Skip to content

Commit

Permalink
Update Spotless and Ktlint, and appease these robots (#1213)
Browse files Browse the repository at this point in the history
* Update dependency com.diffplug.spotless:spotless-plugin-gradle to v6.14.0

* Update ktlint

* Apply Spotless

---------

Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
  • Loading branch information
squarejesse and renovate[bot] authored Jan 30, 2023
1 parent c4dc980 commit cd31c07
Show file tree
Hide file tree
Showing 142 changed files with 761 additions and 604 deletions.
4 changes: 2 additions & 2 deletions gradle/libs.versions.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[versions]
jmh = "1.36"
ktlint = "0.42.1"
ktlint = "0.48.2"

[libraries]
android-gradle-plugin = { module = "com.android.tools.build:gradle", version = "7.4.0" }
Expand All @@ -20,7 +20,7 @@ animalSniffer-java = { module = "org.codehaus.mojo.signature:java17", version =
japicmp = { module = "me.champeau.gradle:japicmp-gradle-plugin", version = "0.4.1" }
dokka = { module = "org.jetbrains.dokka:dokka-gradle-plugin", version = "1.7.20" }
shadow = { module = "gradle.plugin.com.github.johnrengelman:shadow", version = "7.1.2" }
spotless = { module = "com.diffplug.spotless:spotless-plugin-gradle", version = "6.13.0" }
spotless = { module = "com.diffplug.spotless:spotless-plugin-gradle", version = "6.14.0" }
bnd = { module = "biz.aQute.bnd:biz.aQute.bnd.gradle", version = "6.4.0" }
guava = { module = "com.google.guava:guava", version = "31.1-jre" }
vanniktech-publish-plugin = { module = "com.vanniktech:gradle-maven-publish-plugin", version = "0.23.2" }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ import okio.fakefilesystem.FakeFileSystem.Operation.WRITE
*/
class FakeFileSystem(
@JvmField
val clock: Clock = Clock.System
val clock: Clock = Clock.System,
) : FileSystem() {

/** File system roots. Each element is a Directory and is created on-demand. */
Expand Down Expand Up @@ -168,7 +168,7 @@ class FakeFileSystem(
|expected 0 open files, but found:
| ${openFiles.joinToString(separator = "\n ") { it.canonicalPath.toString() }}
""".trimMargin(),
firstOpenFile.backtrace
firstOpenFile.backtrace,
)
}

Expand Down Expand Up @@ -234,7 +234,7 @@ class FakeFileSystem(
val lookupResult = lookupPath(
canonicalPath = canonicalPath,
createRootOnDemand = canonicalPath.isRoot,
resolveLastSymlink = false
resolveLastSymlink = false,
)
val element = lookupResult?.element ?: throw FileNotFoundException("no such file: $path")
if (value == null) {
Expand All @@ -249,7 +249,7 @@ class FakeFileSystem(
val lookupResult = lookupPath(
canonicalPath = canonicalPath,
createRootOnDemand = canonicalPath.isRoot,
resolveLastSymlink = false
resolveLastSymlink = false,
)
return lookupResult?.element?.metadata
}
Expand Down Expand Up @@ -370,7 +370,7 @@ class FakeFileSystem(
return FakeFileHandle(
readWrite = readWrite,
openFile = openFile,
file = element
file = element,
)
}

Expand All @@ -394,7 +394,7 @@ class FakeFileSystem(

override fun atomicMove(
source: Path,
target: Path
target: Path,
) {
val canonicalSource = canonicalizeInternal(source)
val canonicalTarget = canonicalizeInternal(target)
Expand Down Expand Up @@ -433,7 +433,7 @@ class FakeFileSystem(
val lookupResult = lookupPath(
canonicalPath = canonicalPath,
createRootOnDemand = true,
resolveLastSymlink = false
resolveLastSymlink = false,
)

if (lookupResult?.element == null) {
Expand All @@ -460,7 +460,7 @@ class FakeFileSystem(

override fun createSymlink(
source: Path,
target: Path
target: Path,
) {
val canonicalSource = canonicalizeInternal(source)

Expand Down Expand Up @@ -553,7 +553,7 @@ class FakeFileSystem(
val symlinkLookupResult = lookupPath(
canonicalPath = currentPath,
recurseCount = recurseCount + 1,
createRootOnDemand = createRootOnDemand
createRootOnDemand = createRootOnDemand,
) ?: break
parent = symlinkLookupResult.parent
lastSegment = symlinkLookupResult.segment
Expand All @@ -574,15 +574,15 @@ class FakeFileSystem(
/** Only null if the looked up path is a root. */
val segment: ByteString?,
/** Non-null if this is a root. Also not null if this file exists. */
val element: Element?
val element: Element?,
)

private fun PathLookupResult?.requireParent(): Directory {
return this?.parent ?: throw IOException("parent directory does not exist")
}

private sealed class Element(
val createdAt: Instant
val createdAt: Instant,
) {
var lastModifiedAt: Instant = createdAt
var lastAccessedAt: Instant = createdAt
Expand Down Expand Up @@ -619,7 +619,7 @@ class FakeFileSystem(
class Symlink(
createdAt: Instant,
/** This may be an absolute or relative path. */
val target: Path
val target: Path,
) : Element(createdAt) {
override val metadata: FileMetadata
get() = FileMetadata(
Expand All @@ -633,7 +633,7 @@ class FakeFileSystem(

fun access(
now: Instant,
modified: Boolean = false
modified: Boolean = false,
) {
lastAccessedAt = now
if (modified) {
Expand All @@ -646,7 +646,7 @@ class FakeFileSystem(

private fun findOpenFile(
canonicalPath: Path,
operation: Operation? = null
operation: Operation? = null,
): OpenFile? {
return openFiles.firstOrNull {
it.canonicalPath == canonicalPath && (operation == null || operation == it.operation)
Expand All @@ -656,7 +656,7 @@ class FakeFileSystem(
private fun checkOffsetAndCount(
size: Long,
offset: Long,
byteCount: Long
byteCount: Long,
) {
if (offset or byteCount < 0 || offset > size || size - offset < byteCount) {
throw ArrayIndexOutOfBoundsException("size=$size offset=$offset byteCount=$byteCount")
Expand All @@ -666,18 +666,18 @@ class FakeFileSystem(
private class OpenFile(
val canonicalPath: Path,
val operation: Operation,
val backtrace: Throwable
val backtrace: Throwable,
)

private enum class Operation {
READ,
WRITE
WRITE,
}

private inner class FakeFileHandle(
readWrite: Boolean,
private val openFile: OpenFile,
private val file: File
private val file: File,
) : FileHandle(readWrite) {
private var closed = false

Expand Down Expand Up @@ -706,7 +706,7 @@ class FakeFileSystem(
fileOffset: Long,
array: ByteArray,
arrayOffset: Int,
byteCount: Int
byteCount: Int,
): Int {
check(!closed) { "closed" }
checkOffsetAndCount(array.size.toLong(), arrayOffset.toLong(), byteCount.toLong())
Expand All @@ -724,7 +724,7 @@ class FakeFileSystem(
fileOffset: Long,
array: ByteArray,
arrayOffset: Int,
byteCount: Int
byteCount: Int,
) {
check(!closed) { "closed" }
checkOffsetAndCount(array.size.toLong(), arrayOffset.toLong(), byteCount.toLong())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
* limitations under the License.
*/
@file:JvmName("-Time")

package okio.fakefilesystem

import kotlin.jvm.JvmName
Expand Down
2 changes: 1 addition & 1 deletion okio-nodefilesystem/src/main/kotlin/okio/FileSink.kt
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
package okio

internal class FileSink(
private val fd: Number
private val fd: Number,
) : Sink {
private var closed = false

Expand Down
4 changes: 2 additions & 2 deletions okio-nodefilesystem/src/main/kotlin/okio/FileSource.kt
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
package okio

internal class FileSource(
private val fd: Number
private val fd: Number,
) : Source {
private var position_ = 0L
private var closed = false
Expand All @@ -31,7 +31,7 @@ internal class FileSource(
buffer = data,
length = byteCount.toDouble(),
offset = 0.0,
position = position_.toDouble()
position = position_.toDouble(),
).toInt()

if (readByteCount == 0) return -1L
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@
*/
@file:JsModule("fs")
@file:JsNonModule

package okio

import kotlin.js.Date
Expand Down Expand Up @@ -110,6 +111,7 @@ internal external fun symlinkSync(target: String, path: String)
internal open external class Dir {
open var path: String
open fun closeSync()

// Note that dukat's signature of readSync() returns a non-nullable Dirent; that's incorrect.
open fun readSync(): Dirent?
}
Expand Down
10 changes: 5 additions & 5 deletions okio-nodefilesystem/src/main/kotlin/okio/NodeJsFileHandle.kt
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ package okio

internal class NodeJsFileHandle(
private val fd: Number,
readWrite: Boolean
readWrite: Boolean,
) : FileHandle(readWrite) {
override fun protectedSize(): Long {
val stats = fstatSync(fd)
Expand All @@ -28,14 +28,14 @@ internal class NodeJsFileHandle(
fileOffset: Long,
array: ByteArray,
arrayOffset: Int,
byteCount: Int
byteCount: Int,
): Int {
val readByteCount = readSync(
fd = fd,
buffer = array,
length = byteCount.toDouble(),
offset = arrayOffset.toDouble(),
position = fileOffset.toDouble()
position = fileOffset.toDouble(),
).toInt()

if (readByteCount == 0) return -1
Expand All @@ -47,14 +47,14 @@ internal class NodeJsFileHandle(
fileOffset: Long,
array: ByteArray,
arrayOffset: Int,
byteCount: Int
byteCount: Int,
) {
val writtenByteCount = writeSync(
fd = fd,
buffer = array,
offset = arrayOffset.toDouble(),
length = byteCount.toDouble(),
position = fileOffset.toDouble()
position = fileOffset.toDouble(),
)

if (writtenByteCount.toInt() != byteCount) {
Expand Down
23 changes: 16 additions & 7 deletions okio-nodefilesystem/src/main/kotlin/okio/NodeJsFileSystem.kt
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ object NodeJsFileSystem : FileSystem() {
size = stat.size.toLong(),
createdAtMillis = stat.ctimeMs.toLong(),
lastModifiedAtMillis = stat.mtimeMs.toLong(),
lastAccessedAtMillis = stat.atimeMs.toLong()
lastAccessedAtMillis = stat.atimeMs.toLong(),
)
}

Expand Down Expand Up @@ -98,8 +98,11 @@ object NodeJsFileSystem : FileSystem() {
opendir.closeSync()
}
} catch (e: Throwable) {
if (throwOnFailure) throw e.toIOException()
else return null
if (throwOnFailure) {
throw e.toIOException()
} else {
return null
}
}
}

Expand Down Expand Up @@ -173,8 +176,11 @@ object NodeJsFileSystem : FileSystem() {
} catch (e: Throwable) {
val alreadyExist = metadataOrNull(dir)?.isDirectory == true
if (alreadyExist) {
if (mustCreate) throw IOException("$dir already exist.")
else return
if (mustCreate) {
throw IOException("$dir already exist.")
} else {
return
}
}

throw e.toIOException()
Expand Down Expand Up @@ -205,8 +211,11 @@ object NodeJsFileSystem : FileSystem() {
rmdirSync(path.toString())
} catch (e: Throwable) {
if (e.errorCode == "ENOENT") {
if (mustExist) throw FileNotFoundException("no such file: $path")
else return
if (mustExist) {
throw FileNotFoundException("no such file: $path")
} else {
return
}
}
throw e.toIOException()
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,5 +22,5 @@ class NodeJsFileSystemTest : AbstractFileSystemTest(
fileSystem = NodeJsFileSystem,
windowsLimitations = Path.DIRECTORY_SEPARATOR == "\\",
allowClobberingEmptyDirectories = Path.DIRECTORY_SEPARATOR == "\\",
temporaryDirectory = FileSystem.SYSTEM_TEMPORARY_DIRECTORY
temporaryDirectory = FileSystem.SYSTEM_TEMPORARY_DIRECTORY,
)
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ abstract class AbstractFileSystemTest(
val fileSystem: FileSystem,
val windowsLimitations: Boolean,
val allowClobberingEmptyDirectories: Boolean,
temporaryDirectory: Path
temporaryDirectory: Path,
) {
val base: Path = temporaryDirectory / "${this::class.simpleName}-${randomToken(16)}"
private val isNodeJsFileSystem = fileSystem::class.simpleName?.startsWith("NodeJs") ?: false
Expand Down Expand Up @@ -1049,6 +1049,7 @@ abstract class AbstractFileSystemTest(
assertTrue(path !in fileSystem.list(base))
assertTrue((path / "file.txt") !in fileSystem.list(base))
}

@Test
fun deleteRecursivelyNonEmptyDirectoryMustExist() {
val path = base / "delete-recursively-non-empty-directory"
Expand Down Expand Up @@ -2298,7 +2299,7 @@ abstract class AbstractFileSystemTest(
exceptionType == "IOException" ||
exceptionType == "IllegalStateException" ||
exceptionType == "ClosedChannelException",
"unexpected exception: $exception"
"unexpected exception: $exception",
)
}

Expand All @@ -2308,7 +2309,8 @@ abstract class AbstractFileSystemTest(
"JvmSystemFileSystem",
"NioSystemFileSystem",
"PosixFileSystem",
"NodeJsFileSystem" -> true
"NodeJsFileSystem",
-> true
else -> false
}
}
Expand All @@ -2319,14 +2321,15 @@ abstract class AbstractFileSystemTest(
return when (fileSystem::class.simpleName) {
"NodeJsFileSystem",
"PosixFileSystem",
"NioSystemFileSystem" -> true
"NioSystemFileSystem",
-> true
else -> false
}
}

private fun expectIOExceptionOnWindows(
exceptJs: Boolean = false,
block: () -> Unit
block: () -> Unit,
) {
val expectCrash = windowsLimitations && (!isNodeJsFileSystem || !exceptJs)
try {
Expand Down
Loading

0 comments on commit cd31c07

Please sign in to comment.