Skip to content

Commit

Permalink
[Scripting] Fix repository ID generation for Maven resolver
Browse files Browse the repository at this point in the history
  • Loading branch information
ileasile authored and teamcityserver committed May 10, 2021
1 parent 7cea639 commit 626c1d3
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -88,11 +88,8 @@ class MavenDependenciesResolver : ExternalDependenciesResolver {
): ResultWithDiagnostics<Boolean> {
val url = repositoryCoordinates.toRepositoryUrlOrNull()
?: return false.asSuccess()
val repo = RemoteRepository.Builder(
repositoryCoordinates.string,
"default",
url.toString()
)
val repoId = repositoryCoordinates.string.replace(FORBIDDEN_CHARS, "_")
val repo = RemoteRepository.Builder(repoId, "default", url.toString())
if (repositoryCoordinates is MavenRepositoryCoordinates) {
val username = repositoryCoordinates.username?.let(::tryResolveEnvironmentVariable)
val password = repositoryCoordinates.password?.let(::tryResolveEnvironmentVariable)
Expand All @@ -109,4 +106,14 @@ class MavenDependenciesResolver : ExternalDependenciesResolver {
repos.add(repo.build())
return true.asSuccess()
}

companion object {
/**
* These characters are forbidden in Windows, Linux or Mac file names.
* As the repository ID is used in metadata filename generation
* (see [org.eclipse.aether.internal.impl.SimpleLocalRepositoryManager.getRepositoryKey]),
* they should be replaced with an allowed character.
*/
private val FORBIDDEN_CHARS = Regex("[/\\\\:<>\"|?*]")
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,18 @@ class MavenResolverTest : ResolversTestBase() {
}
}

// Ignored - tests with custom repos often break the CI due to the caching issues
// TODO: find a way to enable it back
@Ignore
fun ignore_testCustomRepositoryId() {
val resolver = MavenDependenciesResolver()
resolver.addRepository("https://repo.osgeo.org/repository/release/")
val files = runBlocking {
resolver.resolve("org.geotools:gt-shapefile:[23,)")
}.valueOrThrow()
assertTrue(files.any { it.name.startsWith("gt-shapefile") })
}

// Ignored - tests with custom repos often break the CI due to the caching issues
// TODO: find a way to enable it back
@Ignore
Expand Down

0 comments on commit 626c1d3

Please sign in to comment.