From 0831cf00b201fe869d4da7c8992a2bc45afa518b Mon Sep 17 00:00:00 2001 From: Nick Rayburn <52075362+nrayburn-tech@users.noreply.github.com> Date: Fri, 1 Nov 2024 18:47:10 -0500 Subject: [PATCH] IDEA-311825 Support MVNW_PASSWORD, MVNW_REPOURL, and MVNW_USERNAME for downloading Maven wrapper --- .../idea/maven/server/MavenWrapperSupport.kt | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/plugins/maven/src/main/java/org/jetbrains/idea/maven/server/MavenWrapperSupport.kt b/plugins/maven/src/main/java/org/jetbrains/idea/maven/server/MavenWrapperSupport.kt index 2ca53cbb6f5b3..e87d261fa7f8e 100644 --- a/plugins/maven/src/main/java/org/jetbrains/idea/maven/server/MavenWrapperSupport.kt +++ b/plugins/maven/src/main/java/org/jetbrains/idea/maven/server/MavenWrapperSupport.kt @@ -66,6 +66,13 @@ internal class MavenWrapperSupport { indicator?.apply { text = SyncBundle.message("maven.sync.wrapper.downloading.from", urlString) } try { HttpRequests.request(urlString) + .tuner{ + val username = System.getenv("MVNW_USERNAME") + val password = System.getenv("MVNW_PASSWORD") + if (!username.isNullOrBlank() && !password.isNullOrBlank()) { + it.setRequestProperty("Authorization", "Basic " + Base64.getEncoder().encodeToString("$username:$password".toByteArray())) + } + } .forceHttps(false) .connectTimeout(30_000) .readTimeout(30_000) @@ -185,7 +192,14 @@ internal class MavenWrapperSupport { val stream = ByteArrayInputStream(wrapperProperties.contentsToByteArray(true)) properties.load(stream) - return properties.getProperty(DISTRIBUTION_URL_PROPERTY) + val configuredProperty = properties.getProperty(DISTRIBUTION_URL_PROPERTY) + val urlBase = System.getenv("MVNW_REPOURL") + val configuredUrlBaseEnd = configuredProperty?.indexOf("/org/apache/maven") ?: -1 + if (!urlBase.isNullOrBlank() && configuredUrlBaseEnd >= 0) { + return (if (urlBase.endsWith('/')) urlBase.substring(0, urlBase.length - 1) else urlBase) + configuredProperty.substring(configuredUrlBaseEnd) + } + + return configuredProperty } catch (e: IOException) { MavenLog.LOG.warn("exception reading wrapper url", e) @@ -227,4 +241,4 @@ internal class MavenWrapperSupport { fun getWrapperProperties(baseDir: VirtualFile?) = baseDir?.findChild(".mvn")?.findChild("wrapper")?.findChild("maven-wrapper.properties") } -} \ No newline at end of file +}