diff --git a/spring-boot-cli/src/main/java/org/springframework/boot/cli/compiler/grape/CompositeProxySelector.java b/spring-boot-cli/src/main/java/org/springframework/boot/cli/compiler/grape/CompositeProxySelector.java new file mode 100644 index 0000000000..c26f65ec7d --- /dev/null +++ b/spring-boot-cli/src/main/java/org/springframework/boot/cli/compiler/grape/CompositeProxySelector.java @@ -0,0 +1,48 @@ +/* + * Copyright 2012-2013 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.springframework.boot.cli.compiler.grape; + +import java.util.ArrayList; +import java.util.List; + +import org.eclipse.aether.repository.Proxy; +import org.eclipse.aether.repository.ProxySelector; +import org.eclipse.aether.repository.RemoteRepository; + +/** + * @author Dave Syer + */ +public class CompositeProxySelector implements ProxySelector { + + private List selectors = new ArrayList(); + + public CompositeProxySelector(List selectors) { + this.selectors = selectors; + } + + @Override + public Proxy getProxy(RemoteRepository repository) { + for (ProxySelector selector : this.selectors) { + Proxy proxy = selector.getProxy(repository); + if (proxy != null) { + return proxy; + } + } + return null; + } + +} diff --git a/spring-boot-cli/src/main/java/org/springframework/boot/cli/compiler/grape/DefaultRepositorySystemSessionAutoConfiguration.java b/spring-boot-cli/src/main/java/org/springframework/boot/cli/compiler/grape/DefaultRepositorySystemSessionAutoConfiguration.java index 707cc59c33..3fb2c0f36a 100644 --- a/spring-boot-cli/src/main/java/org/springframework/boot/cli/compiler/grape/DefaultRepositorySystemSessionAutoConfiguration.java +++ b/spring-boot-cli/src/main/java/org/springframework/boot/cli/compiler/grape/DefaultRepositorySystemSessionAutoConfiguration.java @@ -17,11 +17,13 @@ package org.springframework.boot.cli.compiler.grape; import java.io.File; +import java.util.Arrays; import org.eclipse.aether.DefaultRepositorySystemSession; import org.eclipse.aether.RepositorySystem; import org.eclipse.aether.repository.LocalRepository; import org.eclipse.aether.repository.LocalRepositoryManager; +import org.eclipse.aether.repository.ProxySelector; import org.springframework.util.StringUtils; /** @@ -44,8 +46,12 @@ public class DefaultRepositorySystemSessionAutoConfiguration implements session.setLocalRepositoryManager(localRepositoryManager); } - if (session.getProxySelector() == null) { - session.setProxySelector(new JreProxySelector()); + ProxySelector existing = session.getProxySelector(); + if (existing == null || !(existing instanceof CompositeProxySelector)) { + JreProxySelector fallback = new JreProxySelector(); + ProxySelector selector = existing == null ? fallback + : new CompositeProxySelector(Arrays.asList(existing, fallback)); + session.setProxySelector(selector); } } diff --git a/spring-boot-cli/src/test/java/org/springframework/boot/cli/compiler/grape/AetherGrapeEngineTests.java b/spring-boot-cli/src/test/java/org/springframework/boot/cli/compiler/grape/AetherGrapeEngineTests.java index d0bb151da3..943960f148 100644 --- a/spring-boot-cli/src/test/java/org/springframework/boot/cli/compiler/grape/AetherGrapeEngineTests.java +++ b/spring-boot-cli/src/test/java/org/springframework/boot/cli/compiler/grape/AetherGrapeEngineTests.java @@ -23,10 +23,13 @@ import java.util.Arrays; import java.util.HashMap; import java.util.Map; +import org.eclipse.aether.DefaultRepositorySystemSession; import org.junit.Test; import org.springframework.boot.cli.compiler.DependencyResolutionContext; +import org.springframework.test.util.ReflectionTestUtils; import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; /** * Tests for {@link AetherGrapeEngine}. @@ -52,6 +55,14 @@ public class AetherGrapeEngineTests { assertEquals(6, this.groovyClassLoader.getURLs().length); } + @Test + public void proxySelector() { + DefaultRepositorySystemSession session = (DefaultRepositorySystemSession) ReflectionTestUtils + .getField(this.grapeEngine, "session"); + assertTrue((session.getProxySelector() instanceof CompositeProxySelector) + || (session.getProxySelector() instanceof JreProxySelector)); + } + @SuppressWarnings("unchecked") @Test public void dependencyResolutionWithExclusions() {