Add default proxy settings from System proerties
Aether apparently doesn't use the java.net.* APIs for TCP connections so it doesn't notice when a user sets -Dhttp.Proxy*. To fix it is painful, and leads me to suspect that actually we might want to parse a settings.xml at some point (however unpalatable that is). For now I have added a Proxy to all RemoteRepository instances that we create in the CLI if the user has set -Dhttp.proxyHost (and/or -Dhttps.proxyHost for a secure repository). TODO: authentication. Is there a standard way to specify that globally via system properties. TODO: maybe use per-repository settings if provided (e.g. in settings.xml).
This commit is contained in:
@@ -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;
|
||||
|
||||
@@ -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<String, Object> 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
|
||||
|
||||
Reference in New Issue
Block a user