Skip to content

Commit

Permalink
fix(pub): Improve support for custom package repositories
Browse files Browse the repository at this point in the history
Signed-off-by: Timo Salmi <[email protected]>
  • Loading branch information
Syyllinen committed Jul 12, 2024
1 parent 2651da9 commit 162853f
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ 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")

Check warning

Code scanning / detekt

Line detected, which is longer than the defined maximum line length in the code style. Warning test

Line detected, which is longer than the defined maximum line length in the code style.
val localPackagePathAbsolute = ABSOLUTE_PATH
val localPackagePathRelative = ABSOLUTE_PATH.resolve(RELATIVE_PATH)

Expand Down Expand Up @@ -72,6 +73,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(
Expand All @@ -93,23 +115,23 @@ class PubCacheReaderTest : WordSpec({
) shouldBe gitPackageWithPathCacheDir
}

"resolve the path of a hosted dependency" {
"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"
"url": "https://oss-review-toolkit.org/api/pub/repository/"
},
"source": "hosted",
"version": "$PACKAGE_VERSION"
}
""".trimIndent()
),
ABSOLUTE_PATH // not used
) shouldBe hostedPackageCacheDir
) shouldBe customPackageCacheDir
}

"resolve the relative path of a local dependency" {
Expand Down

0 comments on commit 162853f

Please sign in to comment.