diff --git a/plugins/package-managers/bundler/src/main/kotlin/Bundler.kt b/plugins/package-managers/bundler/src/main/kotlin/Bundler.kt index edda3e5262b14..e8e4f330943c3 100644 --- a/plugins/package-managers/bundler/src/main/kotlin/Bundler.kt +++ b/plugins/package-managers/bundler/src/main/kotlin/Bundler.kt @@ -165,11 +165,11 @@ class Bundler( // [2]: https://github.com/jruby/jruby/discussions/7403 val lockfiles = definitionFiles.map { it.resolveSibling(BUNDLER_LOCKFILE_NAME) }.filter { it.isFile } - val lockFilesBundlerVersion = lockfiles.mapNotNull { + val lockfilesBundlerVersion = lockfiles.mapNotNull { parseBundlerVersionFromLockfile(it) }.sortedWith(AlphaNumericComparator).lastOrNull() - val bundlerVersion = options[OPTION_BUNDLER_VERSION] ?: lockFilesBundlerVersion + val bundlerVersion = options[OPTION_BUNDLER_VERSION] ?: lockfilesBundlerVersion if (bundlerVersion != null) { val duration = measureTime { diff --git a/plugins/package-managers/composer/src/main/kotlin/Composer.kt b/plugins/package-managers/composer/src/main/kotlin/Composer.kt index 09fa129d97b14..d141a49ec5dd0 100644 --- a/plugins/package-managers/composer/src/main/kotlin/Composer.kt +++ b/plugins/package-managers/composer/src/main/kotlin/Composer.kt @@ -128,11 +128,11 @@ class Composer( return listOf(result) } - val lockFile = ensureLockFile(workingDir) + val lockfile = ensureLockFile(workingDir) - logger.info { "Parsing lock file at '$lockFile'..." } + logger.info { "Parsing lock file at '$lockfile'..." } - val json = jsonMapper.readTree(lockFile) + val json = jsonMapper.readTree(lockfile) val packages = parseInstalledPackages(json) // Let's also determine the "virtual" (replaced and provided) packages. These can be declared as @@ -157,18 +157,18 @@ class Composer( private fun parseScope( scopeName: String, manifest: JsonNode, - lockFile: JsonNode, + lockfile: JsonNode, packages: Map, virtualPackages: Set ): Scope { val requiredPackages = manifest[scopeName].fieldNamesOrEmpty().asSequence() - val dependencies = buildDependencyTree(requiredPackages, lockFile, packages, virtualPackages) + val dependencies = buildDependencyTree(requiredPackages, lockfile, packages, virtualPackages) return Scope(scopeName, dependencies) } private fun buildDependencyTree( dependencies: Sequence, - lockFile: JsonNode, + lockfile: JsonNode, packages: Map, virtualPackages: Set, dependencyBranch: List = emptyList() @@ -191,9 +191,9 @@ class Composer( } try { - val runtimeDependencies = getRuntimeDependencies(packageName, lockFile) + val runtimeDependencies = getRuntimeDependencies(packageName, lockfile) val transitiveDependencies = buildDependencyTree( - runtimeDependencies, lockFile, packages, virtualPackages, dependencyBranch + packageName + runtimeDependencies, lockfile, packages, virtualPackages, dependencyBranch + packageName ) packageReferences += packageInfo.toReference(dependencies = transitiveDependencies) } catch (e: IOException) { @@ -278,11 +278,11 @@ class Composer( } private fun ensureLockFile(workingDir: File): File { - val lockFile = workingDir.resolve(COMPOSER_LOCK_FILE) + val lockfile = workingDir.resolve(COMPOSER_LOCK_FILE) - val hasLockFile = lockFile.isFile + val hasLockFile = lockfile.isFile requireLockfile(workingDir) { hasLockFile } - if (hasLockFile) return lockFile + if (hasLockFile) return lockfile val composerVersion = Semver(getVersion(workingDir)) val args = listOfNotNull( @@ -293,7 +293,7 @@ class Composer( run(workingDir, *args.toTypedArray()) - return lockFile + return lockfile } } @@ -307,9 +307,9 @@ private fun String.isPlatformDependency(): Boolean = private val COMPOSER_PLATFORM_TYPES = setOf("composer", "composer-plugin-api", "composer-runtime-api") private val PHP_PLATFORM_TYPES = setOf("php", "php-64bit", "php-ipv6", "php-zts", "php-debug") -private fun getRuntimeDependencies(packageName: String, lockFile: JsonNode): Sequence { +private fun getRuntimeDependencies(packageName: String, lockfile: JsonNode): Sequence { listOf("packages", "packages-dev").forEach { - lockFile[it]?.forEach { packageInfo -> + lockfile[it]?.forEach { packageInfo -> if (packageInfo["name"].textValueOrEmpty() == packageName) { val requiredPackages = packageInfo["require"] if (requiredPackages != null && requiredPackages.isObject) { @@ -355,7 +355,7 @@ private fun parseVcsInfo(packageInfo: JsonNode): VcsInfo = private fun parseVirtualPackageNames( packages: Map, manifest: JsonNode, - lockFile: JsonNode + lockfile: JsonNode ): Set { val replacedNames = mutableSetOf() @@ -364,7 +364,7 @@ private fun parseVirtualPackageNames( replacedNames += parseVirtualNames(manifest) listOf("packages", "packages-dev").forEach { type -> - lockFile[type]?.flatMap { pkgInfo -> + lockfile[type]?.flatMap { pkgInfo -> parseVirtualNames(pkgInfo) }?.let { replacedNames += it diff --git a/plugins/package-managers/node/src/main/kotlin/utils/NpmDetection.kt b/plugins/package-managers/node/src/main/kotlin/utils/NpmDetection.kt index d99cff990d729..9a41b61bff8bc 100644 --- a/plugins/package-managers/node/src/main/kotlin/utils/NpmDetection.kt +++ b/plugins/package-managers/node/src/main/kotlin/utils/NpmDetection.kt @@ -110,7 +110,7 @@ class NpmDetection(private val definitionFiles: Collection) { * An enum of all supported Node package managers. */ enum class NodePackageManager( - val lockFileName: String, + val lockfileName: String, val markerFileName: String? = null, val workspaceFileName: String = NodePackageManager.DEFINITION_FILE ) { @@ -135,27 +135,27 @@ enum class NodePackageManager( }, YARN("yarn.lock") { - private val lockFileMarker = "# yarn lockfile v1" + private val lockfileMarker = "# yarn lockfile v1" override fun hasLockFile(projectDir: File): Boolean { - val lockFile = projectDir.resolve(lockFileName) - if (!lockFile.isFile) return false + val lockfile = projectDir.resolve(lockfileName) + if (!lockfile.isFile) return false - return lockFile.useLines { lines -> - lines.take(2).lastOrNull() == lockFileMarker + return lockfile.useLines { lines -> + lines.take(2).lastOrNull() == lockfileMarker } } }, YARN2("yarn.lock", markerFileName = ".yarnrc.yml") { - private val lockFileMarker = "__metadata:" + private val lockfileMarker = "__metadata:" override fun hasLockFile(projectDir: File): Boolean { - val lockFile = projectDir.resolve(lockFileName) - if (!lockFile.isFile) return false + val lockfile = projectDir.resolve(lockfileName) + if (!lockfile.isFile) return false - return lockFile.useLines { lines -> - lines.take(4).lastOrNull() == lockFileMarker + return lockfile.useLines { lines -> + lines.take(4).lastOrNull() == lockfileMarker } } }; @@ -190,7 +190,7 @@ enum class NodePackageManager( /** * Return true if the [projectDir] contains a lock file for this package manager, or return false otherwise. */ - open fun hasLockFile(projectDir: File): Boolean = hasNonEmptyFile(projectDir, lockFileName) + open fun hasLockFile(projectDir: File): Boolean = hasNonEmptyFile(projectDir, lockfileName) /** * If the [projectDir] contains a workspace file for this package manager, return the list of package patterns, or diff --git a/plugins/package-managers/node/src/test/kotlin/utils/NpmDetectionTest.kt b/plugins/package-managers/node/src/test/kotlin/utils/NpmDetectionTest.kt index 858a244e0d246..47ad5b39aeb11 100644 --- a/plugins/package-managers/node/src/test/kotlin/utils/NpmDetectionTest.kt +++ b/plugins/package-managers/node/src/test/kotlin/utils/NpmDetectionTest.kt @@ -41,11 +41,11 @@ class NpmDetectionTest : WordSpec({ "All Node package manager detections" should { "ignore empty lock files" { NodePackageManager.entries.forAll { - val lockFile = tempdir().resolve(it.lockFileName).apply { + val lockfile = tempdir().resolve(it.lockfileName).apply { writeText("") } - it.hasLockFile(lockFile.parentFile) shouldBe false + it.hasLockFile(lockfile.parentFile) shouldBe false } } @@ -72,8 +72,8 @@ class NpmDetectionTest : WordSpec({ "return only those managers whose lock files are present" { val projectDir = tempdir().apply { resolve("package.json").writeText("{}") - resolve(NPM.lockFileName).writeText("{}") - resolve(PNPM.lockFileName).writeText("#") + resolve(NPM.lockfileName).writeText("{}") + resolve(PNPM.lockfileName).writeText("#") } NodePackageManager.forDirectory(projectDir).shouldContainExactlyInAnyOrder(NPM, PNPM) @@ -82,7 +82,7 @@ class NpmDetectionTest : WordSpec({ "return only NPM if distinguished by lock file" { val projectDir = tempdir().apply { resolve("package.json").writeText("{}") - resolve(NPM.lockFileName).writeText("{}") + resolve(NPM.lockfileName).writeText("{}") } NodePackageManager.forDirectory(projectDir).shouldContainExactlyInAnyOrder(NPM) @@ -100,7 +100,7 @@ class NpmDetectionTest : WordSpec({ "return only PNPM if distinguished by lock file" { val projectDir = tempdir().apply { resolve("package.json").writeText("{}") - resolve(PNPM.lockFileName).writeText("#") + resolve(PNPM.lockfileName).writeText("#") } NodePackageManager.forDirectory(projectDir).shouldContainExactlyInAnyOrder(PNPM) @@ -118,7 +118,7 @@ class NpmDetectionTest : WordSpec({ "return only YARN if distinguished by lock file" { val projectDir = tempdir().apply { resolve("package.json").writeText("{}") - resolve(YARN.lockFileName).writeText(YARN_LOCK_FILE_HEADER) + resolve(YARN.lockfileName).writeText(YARN_LOCK_FILE_HEADER) } NodePackageManager.forDirectory(projectDir).shouldContainExactlyInAnyOrder(YARN) @@ -127,7 +127,7 @@ class NpmDetectionTest : WordSpec({ "return only YARN2 if distinguished by lock file" { val projectDir = tempdir().apply { resolve("package.json").writeText("{}") - resolve(YARN2.lockFileName).writeText(YARN2_LOCK_FILE_HEADER) + resolve(YARN2.lockfileName).writeText(YARN2_LOCK_FILE_HEADER) } NodePackageManager.forDirectory(projectDir).shouldContainExactlyInAnyOrder(YARN2) @@ -136,11 +136,11 @@ class NpmDetectionTest : WordSpec({ "NPM detection" should { "recognize lock files" { - val lockFile = tempdir().resolve(NPM.lockFileName).apply { + val lockfile = tempdir().resolve(NPM.lockfileName).apply { writeText("{}") } - NPM.hasLockFile(lockFile.parentFile) shouldBe true + NPM.hasLockFile(lockfile.parentFile) shouldBe true } "parse workspace files" { @@ -171,11 +171,11 @@ class NpmDetectionTest : WordSpec({ "PNPM detection" should { "recognize lock files" { - val lockFile = tempdir().resolve(PNPM.lockFileName).apply { + val lockfile = tempdir().resolve(PNPM.lockfileName).apply { writeText("lockfileVersion: '6.0'") } - PNPM.hasLockFile(lockFile.parentFile) shouldBe true + PNPM.hasLockFile(lockfile.parentFile) shouldBe true } "parse workspace files" { @@ -204,11 +204,11 @@ class NpmDetectionTest : WordSpec({ "Yarn detection" should { "recognize lock files" { - val lockFile = tempdir().resolve(YARN.lockFileName).apply { + val lockfile = tempdir().resolve(YARN.lockfileName).apply { writeText(YARN_LOCK_FILE_HEADER) } - YARN.hasLockFile(lockFile.parentFile) shouldBe true + YARN.hasLockFile(lockfile.parentFile) shouldBe true } "parse workspace files" { @@ -234,11 +234,11 @@ class NpmDetectionTest : WordSpec({ "Yarn2 detection" should { "recognize lock files" { - val lockFile = tempdir().resolve(YARN2.lockFileName).apply { + val lockfile = tempdir().resolve(YARN2.lockfileName).apply { writeText(YARN2_LOCK_FILE_HEADER) } - YARN2.hasLockFile(lockFile.parentFile) shouldBe true + YARN2.hasLockFile(lockfile.parentFile) shouldBe true } "parse workspace files" { diff --git a/plugins/package-managers/pub/src/funTest/kotlin/PubFunTest.kt b/plugins/package-managers/pub/src/funTest/kotlin/PubFunTest.kt index 3d4d5ad084f3b..641bf33541623 100644 --- a/plugins/package-managers/pub/src/funTest/kotlin/PubFunTest.kt +++ b/plugins/package-managers/pub/src/funTest/kotlin/PubFunTest.kt @@ -43,14 +43,14 @@ class PubFunTest : WordSpec({ "resolve dart http dependencies correctly".config(enabled = false) { val definitionFile = getAssetFile("projects/external/dart-http/pubspec.yaml") val expectedResultFile = getAssetFile("projects/external/dart-http-expected-output.yml") - val lockFile = definitionFile.resolveSibling("pubspec.lock").also { + val lockfile = definitionFile.resolveSibling("pubspec.lock").also { getAssetFile("projects/external/dart-http-pubspec.lock").copyTo(it, overwrite = true) } val result = try { create("Pub", allowDynamicVersions = true).resolveSingleProject(definitionFile) } finally { - lockFile.delete() + lockfile.delete() } result.toYaml() should matchExpectedResult(expectedResultFile, definitionFile) diff --git a/plugins/package-managers/pub/src/main/kotlin/Pub.kt b/plugins/package-managers/pub/src/main/kotlin/Pub.kt index 5ca61ac2f1c78..ba521fcedf17f 100644 --- a/plugins/package-managers/pub/src/main/kotlin/Pub.kt +++ b/plugins/package-managers/pub/src/main/kotlin/Pub.kt @@ -267,11 +267,11 @@ class Pub( logger.info { "Reading $PUB_LOCK_FILE file in $workingDir." } - val lockFile = yamlMapper.readTree(workingDir.resolve(PUB_LOCK_FILE)) + val lockfile = yamlMapper.readTree(workingDir.resolve(PUB_LOCK_FILE)) logger.info { "Successfully read lockfile." } - val parsePackagesResult = parseInstalledPackages(lockFile, labels, workingDir) + val parsePackagesResult = parseInstalledPackages(lockfile, labels, workingDir) if (!pubDependenciesOnly) { if (gradleFactory != null) { @@ -306,9 +306,9 @@ class Pub( logger.info { "Successfully parsed installed packages." } - scopes += parseScope("dependencies", manifest, lockFile, parsePackagesResult.packages, labels, workingDir) + scopes += parseScope("dependencies", manifest, lockfile, parsePackagesResult.packages, labels, workingDir) scopes += parseScope( - "dev_dependencies", manifest, lockFile, parsePackagesResult.packages, labels, workingDir + "dev_dependencies", manifest, lockfile, parsePackagesResult.packages, labels, workingDir ) } @@ -322,7 +322,7 @@ class Pub( private fun parseScope( scopeName: String, manifest: JsonNode, - lockFile: JsonNode, + lockfile: JsonNode, packages: Map, labels: Map, workingDir: File @@ -332,14 +332,14 @@ class Pub( logger.info { "Parsing scope '$scopeName' for package '$packageName'." } val requiredPackages = manifest[scopeName]?.fieldNames()?.asSequence().orEmpty().toList() - val dependencies = buildDependencyTree(requiredPackages, manifest, lockFile, packages, labels, workingDir) + val dependencies = buildDependencyTree(requiredPackages, manifest, lockfile, packages, labels, workingDir) return Scope(scopeName, dependencies) } private fun buildDependencyTree( dependencies: List, manifest: JsonNode, - lockFile: JsonNode, + lockfile: JsonNode, packages: Map, labels: Map, workingDir: File, @@ -357,7 +357,7 @@ class Pub( // dependency tree. if (packageName in processedPackages) return@forEach - val pkgInfoFromLockFile = lockFile["packages"][packageName] + val pkgInfoFromLockFile = lockfile["packages"][packageName] // If the package is marked as SDK (e.g. flutter, flutter_test, dart) we cannot resolve it correctly as // it is not stored in .pub-cache. For now, we just ignore those SDK packages. if (pkgInfoFromLockFile == null || pkgInfoFromLockFile["source"].textValueOrEmpty() == "sdk") return@forEach @@ -379,7 +379,7 @@ class Pub( val transitiveDependencies = buildDependencyTree( dependencies = requiredPackages, manifest = dependencyYamlFile, - lockFile = lockFile, + lockfile = lockfile, packages = packages, labels = labels, workingDir = workingDir, @@ -513,7 +513,7 @@ class Pub( } private fun parseInstalledPackages( - lockFile: JsonNode, + lockfile: JsonNode, labels: Map, workingDir: File ): ParsePackagesResult { @@ -526,7 +526,7 @@ class Pub( var containsFlutter = false listOf("packages"/*, "packages-dev"*/).forEach { - lockFile[it]?.fields()?.forEach { (packageName, pkgInfoFromLockFile) -> + lockfile[it]?.fields()?.forEach { (packageName, pkgInfoFromLockFile) -> try { val version = pkgInfoFromLockFile["version"].textValueOrEmpty() var description = "" @@ -654,7 +654,7 @@ class Pub( // each Pub dependency manually, as the analyzer will only analyze the projectRoot, but not the packages in // the ".pub-cache" directory. if (containsFlutter && !pubDependenciesOnly) { - lockFile["packages"]?.forEach { pkgInfoFromLockFile -> + lockfile["packages"]?.forEach { pkgInfoFromLockFile -> // As this package contains Flutter, trigger Gradle manually for it. scanAndroidPackages(pkgInfoFromLockFile, labels, workingDir).forEach { result -> result.collectPackagesByScope("releaseCompileClasspath").forEach { pkg ->