diff --git a/spring-boot-cli/src/main/java/org/springframework/boot/cli/compiler/GroovyCompiler.java b/spring-boot-cli/src/main/java/org/springframework/boot/cli/compiler/GroovyCompiler.java index 6564775af6..af75f3e9aa 100644 --- a/spring-boot-cli/src/main/java/org/springframework/boot/cli/compiler/GroovyCompiler.java +++ b/spring-boot-cli/src/main/java/org/springframework/boot/cli/compiler/GroovyCompiler.java @@ -140,7 +140,8 @@ public class GroovyCompiler { RepositoryPolicy.UPDATE_POLICY_NEVER, RepositoryPolicy.CHECKSUM_POLICY_IGNORE)); } - + builder.setProxy(AetherGrapeEngine.defaultProxy(repositoryConfiguration + .getUri().getScheme())); repositories.add(builder.build()); } return repositories; diff --git a/spring-boot-cli/src/main/java/org/springframework/boot/cli/compiler/grape/AetherGrapeEngine.java b/spring-boot-cli/src/main/java/org/springframework/boot/cli/compiler/grape/AetherGrapeEngine.java index 60487a5a99..d9afbd6967 100644 --- a/spring-boot-cli/src/main/java/org/springframework/boot/cli/compiler/grape/AetherGrapeEngine.java +++ b/spring-boot-cli/src/main/java/org/springframework/boot/cli/compiler/grape/AetherGrapeEngine.java @@ -42,6 +42,7 @@ import org.eclipse.aether.impl.DefaultServiceLocator; import org.eclipse.aether.internal.impl.DefaultRepositorySystem; import org.eclipse.aether.repository.LocalRepository; import org.eclipse.aether.repository.LocalRepositoryManager; +import org.eclipse.aether.repository.Proxy; import org.eclipse.aether.repository.RemoteRepository; import org.eclipse.aether.resolution.ArtifactResolutionException; import org.eclipse.aether.resolution.ArtifactResult; @@ -94,6 +95,33 @@ public class AetherGrapeEngine implements GrapeEngine { this.progressReporter = getProgressReporter(session); } + public static Proxy defaultProxy(String protocol) { + // TODO: proxy authentication + if ("http".equals(protocol) || "dav".equals(protocol)) { + String proxyHost = System.getProperty("http.proxyHost"); + if (proxyHost != null) { + // Use defaults from normal JVM proxy handler + return new Proxy("http", proxyHost, new Integer(System.getProperty( + "http.proxyPort", "80"))); + } + } + else if ("https".equals(protocol) || "davs".equals(protocol)) { + String secureProxyHost = System.getProperty("https.proxyHost"); + if (secureProxyHost != null) { + return new Proxy("https", secureProxyHost, new Integer( + System.getProperty("https.proxyPort", "443"))); + } + } + else if ("ftp".equals(protocol)) { + String secureProxyHost = System.getProperty("ftp.proxyHost"); + if (secureProxyHost != null) { + return new Proxy("ftp", secureProxyHost, new Integer(System.getProperty( + "ftp.proxyPort", "443"))); + } + } + return null; + } + private ServiceLocator createServiceLocator() { DefaultServiceLocator locator = MavenRepositorySystemUtils.newServiceLocator(); locator.addService(RepositorySystem.class, DefaultRepositorySystem.class); @@ -245,9 +273,13 @@ public class AetherGrapeEngine implements GrapeEngine { public void addResolver(Map args) { String name = (String) args.get("name"); String root = (String) args.get("root"); + RemoteRepository.Builder builder = new RemoteRepository.Builder(name, "default", + root); + String protocol = root.contains(":") ? root.substring(0, root.indexOf(":")) + : "none"; + builder.setProxy(AetherGrapeEngine.defaultProxy(protocol)); - this.repositories - .add(new RemoteRepository.Builder(name, "default", root).build()); + this.repositories.add(builder.build()); } @Override