Ensure a JreProxySelector is applied as a fallback
The issue was that the JreProxySelector was only applied if the existing selector was null, but that hasn't been the case since we added supporty for settings.xml. The strategy now is to fallback to a JreProxySelector if the existing one is null or not already a composite. Fixes gh-914.
This commit is contained in:
parent
bb85a52c38
commit
0e2f9e74db
|
@ -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<ProxySelector> selectors = new ArrayList<ProxySelector>();
|
||||
|
||||
public CompositeProxySelector(List<ProxySelector> 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;
|
||||
}
|
||||
|
||||
}
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -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() {
|
||||
|
|
Loading…
Reference in New Issue