[Scripting] Fix repository ID generation for Maven resolver

This commit is contained in:
Ilya Muradyan
2021-05-07 22:01:05 +03:00
committed by teamcityserver
parent 7cea639209
commit 626c1d3b48
2 changed files with 24 additions and 5 deletions
@@ -88,11 +88,8 @@ class MavenDependenciesResolver : ExternalDependenciesResolver {
): ResultWithDiagnostics<Boolean> { ): ResultWithDiagnostics<Boolean> {
val url = repositoryCoordinates.toRepositoryUrlOrNull() val url = repositoryCoordinates.toRepositoryUrlOrNull()
?: return false.asSuccess() ?: return false.asSuccess()
val repo = RemoteRepository.Builder( val repoId = repositoryCoordinates.string.replace(FORBIDDEN_CHARS, "_")
repositoryCoordinates.string, val repo = RemoteRepository.Builder(repoId, "default", url.toString())
"default",
url.toString()
)
if (repositoryCoordinates is MavenRepositoryCoordinates) { if (repositoryCoordinates is MavenRepositoryCoordinates) {
val username = repositoryCoordinates.username?.let(::tryResolveEnvironmentVariable) val username = repositoryCoordinates.username?.let(::tryResolveEnvironmentVariable)
val password = repositoryCoordinates.password?.let(::tryResolveEnvironmentVariable) val password = repositoryCoordinates.password?.let(::tryResolveEnvironmentVariable)
@@ -109,4 +106,14 @@ class MavenDependenciesResolver : ExternalDependenciesResolver {
repos.add(repo.build()) repos.add(repo.build())
return true.asSuccess() 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("[/\\\\:<>\"|?*]")
}
} }
@@ -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 // Ignored - tests with custom repos often break the CI due to the caching issues
// TODO: find a way to enable it back // TODO: find a way to enable it back
@Ignore @Ignore