Skip to content

Commit e2dd087

Browse files
committed
chore: Prefer the / operator to resolve files in simple cases
Do this only in cases where it clearly improves readability. Signed-off-by: Sebastian Schuberth <[email protected]>
1 parent e8bbb85 commit e2dd087

File tree

90 files changed

+304
-221
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

90 files changed

+304
-221
lines changed

analyzer/src/funTest/kotlin/PackageManagerFunTest.kt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ import org.ossreviewtoolkit.model.config.Excludes
3636
import org.ossreviewtoolkit.model.config.PathExclude
3737
import org.ossreviewtoolkit.model.config.PathExcludeReason
3838
import org.ossreviewtoolkit.plugins.api.PluginConfig
39+
import org.ossreviewtoolkit.utils.common.div
3940

4041
class PackageManagerFunTest : WordSpec({
4142
val definitionFiles = listOf(
@@ -197,7 +198,7 @@ class PackageManagerFunTest : WordSpec({
197198

198199
"fail if the provided file is not a directory" {
199200
shouldThrow<IllegalArgumentException> {
200-
PackageManager.findManagedFiles(projectDir.resolve("pom.xml"), packageManagers)
201+
PackageManager.findManagedFiles(projectDir / "pom.xml", packageManagers)
201202
}
202203
}
203204
}

cli/src/funTest/kotlin/OrtMainFunTest.kt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ import org.ossreviewtoolkit.model.config.ProviderPluginConfiguration
4242
import org.ossreviewtoolkit.model.mapper
4343
import org.ossreviewtoolkit.model.readValue
4444
import org.ossreviewtoolkit.utils.common.EnvironmentVariableFilter
45+
import org.ossreviewtoolkit.utils.common.div
4546
import org.ossreviewtoolkit.utils.common.extractResource
4647
import org.ossreviewtoolkit.utils.ort.ORT_REFERENCE_CONFIG_FILENAME
4748

@@ -55,7 +56,7 @@ class OrtMainFunTest : StringSpec() {
5556
override suspend fun beforeSpec(spec: Spec) {
5657
configFile = tempfile(suffix = ".yml")
5758

58-
val curationsFile = tempdir().resolve("gradle-curations.yml")
59+
val curationsFile = tempdir() / "gradle-curations.yml"
5960
extractResource("/gradle-curations.yml", curationsFile)
6061

6162
val writer = configFile.mapper().writerFor(OrtConfiguration::class.java).withRootName("ort")

cli/src/main/kotlin/OrtMain.kt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ import org.ossreviewtoolkit.plugins.commands.api.OrtCommandFactory
5353
import org.ossreviewtoolkit.utils.common.EnvironmentVariableFilter
5454
import org.ossreviewtoolkit.utils.common.MaskedString
5555
import org.ossreviewtoolkit.utils.common.Os
56+
import org.ossreviewtoolkit.utils.common.div
5657
import org.ossreviewtoolkit.utils.common.expandTilde
5758
import org.ossreviewtoolkit.utils.common.mebibytes
5859
import org.ossreviewtoolkit.utils.common.replaceCredentialsInUri
@@ -90,7 +91,7 @@ class OrtMain : CliktCommand(ORT_NAME) {
9091
private val configFile by option("--config", "-c", help = "The path to a configuration file.")
9192
.convert { it.expandTilde() }
9293
.file(mustExist = true, canBeFile = true, canBeDir = false, mustBeWritable = false, mustBeReadable = true)
93-
.default(ortConfigDirectory.resolve(ORT_CONFIG_FILENAME))
94+
.default(ortConfigDirectory / ORT_CONFIG_FILENAME)
9495

9596
private val logLevel by option(help = "Set the verbosity level of log output.").switch(
9697
"--error" to Level.ERROR,

clients/bazel-module-registry/src/main/kotlin/LocalBazelModuleRegistryService.kt

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ import kotlinx.serialization.json.decodeFromStream
2727
import org.apache.logging.log4j.kotlin.logger
2828

2929
import org.ossreviewtoolkit.downloader.VersionControlSystem
30+
import org.ossreviewtoolkit.utils.common.div
3031

3132
private const val BAZEL_MODULES_DIR = "modules"
3233
const val METADATA_JSON = "metadata.json"
@@ -62,7 +63,7 @@ class LocalBazelModuleRegistryService(url: String, directory: File) : BazelModul
6263
private val bazelRegistry: BazelRegistry
6364

6465
init {
65-
val registryFile = directory.resolve("bazel_registry.json")
66+
val registryFile = directory / "bazel_registry.json"
6667

6768
require(registryFile.isFile) {
6869
"The Bazel registry file bazel_registry.json does not exist in '${directory.canonicalPath}'."
@@ -78,15 +79,15 @@ class LocalBazelModuleRegistryService(url: String, directory: File) : BazelModul
7879
override val urls: List<String> = listOf(url)
7980

8081
override suspend fun getModuleMetadata(name: String): ModuleMetadata {
81-
val metadataJson = moduleDirectory.resolve(name).resolve(METADATA_JSON)
82+
val metadataJson = moduleDirectory / name / METADATA_JSON
8283
require(metadataJson.isFile)
8384
return metadataJson.inputStream().use {
8485
JSON.decodeFromStream<ModuleMetadata>(it)
8586
}
8687
}
8788

8889
override suspend fun getModuleSourceInfo(name: String, version: String): ModuleSourceInfo {
89-
val sourceJson = moduleDirectory.resolve(name).resolve(version).resolve(SOURCE_JSON)
90+
val sourceJson = moduleDirectory / name / version / SOURCE_JSON
9091
require(sourceJson.isFile)
9192
val sourceInfo = sourceJson.inputStream().use {
9293
JSON.decodeFromStream<ModuleSourceInfo>(it)
@@ -110,7 +111,7 @@ class LocalBazelModuleRegistryService(url: String, directory: File) : BazelModul
110111
// According to the specification, if path and module_base_path are both relative paths, the path
111112
// to the module source is <registry_path>/<module_base_path>/<path>.
112113
val registryPath = moduleDirectory.parentFile
113-
val modulePath = registryPath.resolve(moduleBasePathAsFile).resolve(pathAsFile)
114+
val modulePath = registryPath / moduleBasePathAsFile / pathAsFile
114115
VersionControlSystem.getPathInfo(modulePath)
115116
sourceInfo.vcs = VersionControlSystem.getPathInfo(modulePath)
116117
}

downloader/src/funTest/kotlin/DownloaderFunTest.kt

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ import org.ossreviewtoolkit.model.VcsInfo
4444
import org.ossreviewtoolkit.model.VcsType
4545
import org.ossreviewtoolkit.model.config.DownloaderConfiguration
4646
import org.ossreviewtoolkit.utils.common.VCS_DIRECTORIES
47+
import org.ossreviewtoolkit.utils.common.div
4748
import org.ossreviewtoolkit.utils.ort.normalizeVcsUrl
4849

4950
class DownloaderFunTest : WordSpec({
@@ -75,7 +76,7 @@ class DownloaderFunTest : WordSpec({
7576
)
7677

7778
val provenance = Downloader(DownloaderConfiguration()).download(pkg, outputDir)
78-
val tslibDir = outputDir.resolve("tslib-1.10.0")
79+
val tslibDir = outputDir / "tslib-1.10.0"
7980

8081
provenance.shouldBeTypeOf<ArtifactProvenance>().apply {
8182
sourceArtifact.url shouldBe pkg.sourceArtifact.url
@@ -107,7 +108,7 @@ class DownloaderFunTest : WordSpec({
107108
)
108109

109110
val provenance = Downloader(DownloaderConfiguration()).download(pkg, outputDir)
110-
val tyrexDir = outputDir.resolve("tyrex-1.0.1")
111+
val tyrexDir = outputDir / "tyrex-1.0.1"
111112

112113
provenance.shouldBeTypeOf<ArtifactProvenance>().apply {
113114
sourceArtifact.url shouldBe pkg.sourceArtifact.url
@@ -138,7 +139,7 @@ class DownloaderFunTest : WordSpec({
138139
)
139140

140141
val provenance = Downloader(DownloaderConfiguration()).download(pkg, outputDir)
141-
val licenseFile = outputDir.resolve("LICENSE-junit.txt")
142+
val licenseFile = outputDir / "LICENSE-junit.txt"
142143

143144
provenance.shouldBeTypeOf<ArtifactProvenance>().apply {
144145
sourceArtifact.url shouldBe pkg.sourceArtifact.url
@@ -214,7 +215,7 @@ class DownloaderFunTest : WordSpec({
214215
)
215216

216217
val provenance = Downloader(downloaderConfiguration).download(pkg, outputDir)
217-
val licenseFile = outputDir.resolve("LICENSE-junit.txt")
218+
val licenseFile = outputDir / "LICENSE-junit.txt"
218219

219220
provenance.shouldBeTypeOf<ArtifactProvenance>().apply {
220221
sourceArtifact.url shouldBe pkg.sourceArtifact.url
@@ -263,7 +264,7 @@ class DownloaderFunTest : WordSpec({
263264

264265
val provenance = Downloader(DownloaderConfiguration()).download(pkg, outputDir)
265266
val workingTree = VersionControlSystem.forDirectory(outputDir)
266-
val babelCliDir = outputDir.resolve("packages/babel-cli")
267+
val babelCliDir = outputDir / "packages" / "babel-cli"
267268

268269
provenance.shouldBeTypeOf<RepositoryProvenance>().apply {
269270
vcsInfo.type shouldBe pkg.vcsProcessed.type
@@ -345,7 +346,7 @@ class DownloaderFunTest : WordSpec({
345346
)
346347

347348
val provenance = Downloader(downloaderConfiguration).download(pkg, outputDir)
348-
val licenseFile = outputDir.resolve("LICENSE-junit.txt")
349+
val licenseFile = outputDir / "LICENSE-junit.txt"
349350

350351
provenance.shouldBeTypeOf<RepositoryProvenance>().apply {
351352
vcsInfo.url shouldBe pkg.vcs.url

downloader/src/main/kotlin/Downloader.kt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ import org.ossreviewtoolkit.model.UnknownProvenance
4040
import org.ossreviewtoolkit.model.VcsType
4141
import org.ossreviewtoolkit.model.config.DownloaderConfiguration
4242
import org.ossreviewtoolkit.utils.common.collectMessages
43+
import org.ossreviewtoolkit.utils.common.div
4344
import org.ossreviewtoolkit.utils.common.replaceCredentialsInUri
4445
import org.ossreviewtoolkit.utils.common.safeDeleteRecursively
4546
import org.ossreviewtoolkit.utils.common.safeMkdirs
@@ -362,7 +363,7 @@ class Downloader(private val config: DownloaderConfiguration) {
362363
if (sourceArchive.extension == "gem") {
363364
// Unpack the nested data archive for Ruby Gems.
364365
val gemDirectory = createOrtTempDir("gem")
365-
val dataFile = gemDirectory.resolve("data.tar.gz")
366+
val dataFile = gemDirectory / "data.tar.gz"
366367

367368
try {
368369
sourceArchive.unpack(gemDirectory)

downloader/src/test/kotlin/VersionControlSystemTest.kt

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ import org.ossreviewtoolkit.model.VcsInfo
3939
import org.ossreviewtoolkit.model.VcsType
4040
import org.ossreviewtoolkit.plugins.api.PluginConfig
4141
import org.ossreviewtoolkit.plugins.versioncontrolsystems.git.GitFactory
42+
import org.ossreviewtoolkit.utils.common.div
4243

4344
class VersionControlSystemTest : WordSpec({
4445
val vcsRoot = File("..").absoluteFile.normalize()
@@ -50,8 +51,8 @@ class VersionControlSystemTest : WordSpec({
5051

5152
"work if given absolute paths" {
5253
absVcsDir.getPathToRoot(vcsRoot) shouldBe ""
53-
absVcsDir.getPathToRoot(vcsRoot.resolve("downloader/src")) shouldBe "downloader/src"
54-
absVcsDir.getPathToRoot(absProjDir.resolve("kotlin")) shouldBe "downloader/src/test/kotlin"
54+
absVcsDir.getPathToRoot(vcsRoot / "downloader" / "src") shouldBe "downloader/src"
55+
absVcsDir.getPathToRoot(absProjDir / "kotlin") shouldBe "downloader/src/test/kotlin"
5556
}
5657

5758
"work if given relative paths" {
@@ -66,8 +67,8 @@ class VersionControlSystemTest : WordSpec({
6667

6768
"work if given absolute paths" {
6869
relVcsDir.getPathToRoot(vcsRoot) shouldBe ""
69-
relVcsDir.getPathToRoot(vcsRoot.resolve("downloader/src")) shouldBe "downloader/src"
70-
relVcsDir.getPathToRoot(absProjDir.resolve("kotlin")) shouldBe "downloader/src/test/kotlin"
70+
relVcsDir.getPathToRoot(vcsRoot / "downloader" / "src") shouldBe "downloader/src"
71+
relVcsDir.getPathToRoot(absProjDir / "kotlin") shouldBe "downloader/src/test/kotlin"
7172
}
7273

7374
"work if given relative paths" {

model/src/main/kotlin/config/FileListStorageConfiguration.kt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ import org.ossreviewtoolkit.model.utils.DatabaseUtils
2525
import org.ossreviewtoolkit.model.utils.FileProvenanceFileStorage
2626
import org.ossreviewtoolkit.model.utils.PostgresProvenanceFileStorage
2727
import org.ossreviewtoolkit.model.utils.ProvenanceFileStorage
28+
import org.ossreviewtoolkit.utils.common.div
2829
import org.ossreviewtoolkit.utils.ort.ortDataDirectory
2930
import org.ossreviewtoolkit.utils.ort.storage.FileStorage
3031
import org.ossreviewtoolkit.utils.ort.storage.XZCompressedLocalFileStorage
@@ -67,7 +68,7 @@ fun FileListStorageConfiguration?.createStorage(): ProvenanceFileStorage =
6768
tableName = TABLE_NAME
6869
)
6970
else -> FileProvenanceFileStorage(
70-
storage = XZCompressedLocalFileStorage(ortDataDirectory.resolve("scanner/file-lists")),
71+
storage = XZCompressedLocalFileStorage(ortDataDirectory / "scanner" / "file-lists"),
7172
filename = FILENAME
7273
)
7374
}

model/src/main/kotlin/utils/FileArchiver.kt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ import org.apache.tika.mime.MimeTypes
3131
import org.ossreviewtoolkit.model.KnownProvenance
3232
import org.ossreviewtoolkit.utils.common.FileMatcher
3333
import org.ossreviewtoolkit.utils.common.collectMessages
34+
import org.ossreviewtoolkit.utils.common.div
3435
import org.ossreviewtoolkit.utils.common.packZip
3536
import org.ossreviewtoolkit.utils.common.safeDeleteRecursively
3637
import org.ossreviewtoolkit.utils.common.unpackZip
@@ -54,7 +55,7 @@ class FileArchiver(
5455
private val storage: ProvenanceFileStorage
5556
) {
5657
companion object {
57-
val DEFAULT_ARCHIVE_DIR by lazy { ortDataDirectory.resolve("scanner/archive") }
58+
val DEFAULT_ARCHIVE_DIR by lazy { ortDataDirectory / "scanner" / "archive" }
5859
}
5960

6061
private val matcher = FileMatcher(

model/src/test/kotlin/licenses/LicenseInfoResolverTest.kt

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ import org.ossreviewtoolkit.model.config.PathExcludeReason
5656
import org.ossreviewtoolkit.model.declaredLicenses
5757
import org.ossreviewtoolkit.model.utils.FileArchiver
5858
import org.ossreviewtoolkit.model.utils.FileProvenanceFileStorage
59+
import org.ossreviewtoolkit.utils.common.div
5960
import org.ossreviewtoolkit.utils.common.extractResource
6061
import org.ossreviewtoolkit.utils.ort.DeclaredLicenseProcessor
6162
import org.ossreviewtoolkit.utils.ort.storage.LocalFileStorage
@@ -656,8 +657,8 @@ class LicenseInfoResolverTest : WordSpec({
656657
)
657658
)
658659

659-
val archiveDir = tempdir().resolve("archive")
660-
extractResource("/archive.zip", archiveDir.resolve("88dce74b694866af2a5e380206b119f5e38aad5f/archive.zip"))
660+
val archiveDir = tempdir() / "archive"
661+
extractResource("/archive.zip", archiveDir / "88dce74b694866af2a5e380206b119f5e38aad5f" / "archive.zip")
661662
val archiver = FileArchiver(
662663
patterns = LicenseFilePatterns.DEFAULT.licenseFilenames,
663664
storage = FileProvenanceFileStorage(

0 commit comments

Comments
 (0)