diff --git a/plugins/package-managers/pub/src/main/kotlin/utils/PubCacheReader.kt b/plugins/package-managers/pub/src/main/kotlin/utils/PubCacheReader.kt index 2123f0e1d1c7..af5ec9460ec0 100644 --- a/plugins/package-managers/pub/src/main/kotlin/utils/PubCacheReader.kt +++ b/plugins/package-managers/pub/src/main/kotlin/utils/PubCacheReader.kt @@ -85,13 +85,13 @@ internal class PubCacheReader(flutterHome: File? = null) { val path = if (type == "hosted" && url.isNotEmpty()) { // Packages with source set to "hosted" and "url" key in description set to "https://pub.dartlang.org". // The path should be resolved to "hosted/pub.dartlang.org/packageName-packageVersion". - "hosted/${url.replace("https://", "")}/$packageName-$packageVersion" + "hosted/${url.replace("https://", "").replace("/", "%47")}/$packageName-$packageVersion" } else if (type == "git" && resolvedRef.isNotEmpty()) { // Packages with source set to "git" and a "resolved-ref" key in description set to a gitHash. // These packages do not define a packageName in the packageInfo, but by definition the path resolves to // the project name as given from the VcsHost and to the resolvedRef. val projectName = VcsHost.getProject(url) ?: return null - if (resolvedPath.isNotEmpty()) { + if (resolvedPath.isNotEmpty() && resolvedPath != ".") { "git/$projectName-$resolvedRef/$resolvedPath" } else { "git/$projectName-$resolvedRef" diff --git a/plugins/package-managers/pub/src/test/kotlin/utils/PubCacheReaderTest.kt b/plugins/package-managers/pub/src/test/kotlin/utils/PubCacheReaderTest.kt index c751589ec21c..58ffe23bd903 100644 --- a/plugins/package-managers/pub/src/test/kotlin/utils/PubCacheReaderTest.kt +++ b/plugins/package-managers/pub/src/test/kotlin/utils/PubCacheReaderTest.kt @@ -40,6 +40,9 @@ class PubCacheReaderTest : WordSpec({ val gitPackageCacheDir = tmpPubCacheDir.resolve("git/$PACKAGE_NAME-$RESOLVED_REF") val gitPackageWithPathCacheDir = tmpPubCacheDir.resolve("git/$PACKAGE_NAME-$RESOLVED_REF/$PACKAGE_NAME") val hostedPackageCacheDir = tmpPubCacheDir.resolve("hosted/oss-review-toolkit.org/$PACKAGE_NAME-$PACKAGE_VERSION") + val customPackageCacheDir = tmpPubCacheDir.resolve( + "hosted/oss-review-toolkit.org%47api%47pub%47repository%47/$PACKAGE_NAME-$PACKAGE_VERSION" + ) val localPackagePathAbsolute = ABSOLUTE_PATH val localPackagePathRelative = ABSOLUTE_PATH.resolve(RELATIVE_PATH) @@ -49,6 +52,7 @@ class PubCacheReaderTest : WordSpec({ gitPackageCacheDir.safeMkdirs() gitPackageWithPathCacheDir.safeMkdirs() hostedPackageCacheDir.safeMkdirs() + customPackageCacheDir.safeMkdirs() } "findProjectRoot" should { @@ -72,6 +76,27 @@ class PubCacheReaderTest : WordSpec({ ) shouldBe gitPackageCacheDir } + "resolve the path of a Git dependency with special path" { + reader.findProjectRoot( + jsonMapper.readTree( + """ + { + "dependency": "direct main", + "description": { + "path": ".", + "ref": "master", + "resolved-ref": "$RESOLVED_REF", + "url": "https://github.com/oss-review-toolkit/$PACKAGE_NAME.git" + }, + "source": "git", + "version": "9.9.9" + } + """.trimIndent() + ), + ABSOLUTE_PATH // not used + ) shouldBe gitPackageCacheDir + } + "resolve the path of a Git dependency with path" { reader.findProjectRoot( jsonMapper.readTree( @@ -112,6 +137,25 @@ class PubCacheReaderTest : WordSpec({ ) shouldBe hostedPackageCacheDir } + "resolve the path of a custom package repository dependency" { + PubCacheReader().findProjectRoot( + jsonMapper.readTree( + """ + { + "dependency": "transitive", + "description": { + "name": "$PACKAGE_NAME", + "url": "https://oss-review-toolkit.org/api/pub/repository/" + }, + "source": "hosted", + "version": "$PACKAGE_VERSION" + } + """.trimIndent() + ), + ABSOLUTE_PATH // not used + ) shouldBe customPackageCacheDir + } + "resolve the relative path of a local dependency" { PubCacheReader().findProjectRoot( jsonMapper.readTree(