use proxy settings for maven aether, see #14

This commit is contained in:
Sebastian Sdorra
2011-05-09 15:08:42 +02:00
parent 3f74473be5
commit d04c898fb8
2 changed files with 43 additions and 7 deletions

View File

@@ -57,7 +57,10 @@ import org.sonatype.aether.impl.VersionRangeResolver;
import org.sonatype.aether.impl.VersionResolver; import org.sonatype.aether.impl.VersionResolver;
import org.sonatype.aether.impl.internal.DefaultServiceLocator; import org.sonatype.aether.impl.internal.DefaultServiceLocator;
import org.sonatype.aether.repository.LocalRepository; import org.sonatype.aether.repository.LocalRepository;
import org.sonatype.aether.repository.Proxy;
import org.sonatype.aether.repository.ProxySelector;
import org.sonatype.aether.repository.RemoteRepository; import org.sonatype.aether.repository.RemoteRepository;
import org.sonatype.aether.resolution.DependencyRequest;
import org.sonatype.aether.spi.connector.RepositoryConnectorFactory; import org.sonatype.aether.spi.connector.RepositoryConnectorFactory;
import org.sonatype.aether.util.artifact.DefaultArtifact; import org.sonatype.aether.util.artifact.DefaultArtifact;
import org.sonatype.aether.util.graph.PreorderNodeListGenerator; import org.sonatype.aether.util.graph.PreorderNodeListGenerator;
@@ -66,6 +69,7 @@ import sonia.scm.ConfigurationException;
import sonia.scm.SCMContextProvider; import sonia.scm.SCMContextProvider;
import sonia.scm.boot.BootstrapListener; import sonia.scm.boot.BootstrapListener;
import sonia.scm.boot.Classpath; import sonia.scm.boot.Classpath;
import sonia.scm.config.ScmConfiguration;
import sonia.scm.util.IOUtil; import sonia.scm.util.IOUtil;
import sonia.scm.util.Util; import sonia.scm.util.Util;
@@ -109,11 +113,14 @@ public class AetherPluginHandler
* *
* @param pluginManager * @param pluginManager
* @param context * @param context
* @param configuration
*/ */
public AetherPluginHandler(PluginManager pluginManager, public AetherPluginHandler(PluginManager pluginManager,
SCMContextProvider context) SCMContextProvider context,
ScmConfiguration configuration)
{ {
this.pluginManager = pluginManager; this.pluginManager = pluginManager;
this.configuration = configuration;
localRepositoryDirectory = new File(context.getBaseDirectory(), localRepositoryDirectory = new File(context.getBaseDirectory(),
BootstrapListener.PLUGIN_DIRECTORY); BootstrapListener.PLUGIN_DIRECTORY);
@@ -208,8 +215,23 @@ public class AetherPluginHandler
for (PluginRepository repository : repositories) for (PluginRepository repository : repositories)
{ {
remoteRepositories.add(new RemoteRepository(repository.getId(), RemoteRepository rr = new RemoteRepository(repository.getId(), "default",
"default", repository.getUrl())); repository.getUrl());
if (configuration.isEnableProxy())
{
Proxy proxy = createProxy();
if (logger.isDebugEnabled())
{
logger.debug("enable proxy {} for {}", repository.getUrl(),
proxy.getHost());
}
rr.setProxy(proxy);
}
remoteRepositories.add(rr);
} }
} }
@@ -236,8 +258,9 @@ public class AetherPluginHandler
{ {
DependencyNode node = repositorySystem.collectDependencies(session, DependencyNode node = repositorySystem.collectDependencies(session,
request).getRoot(); request).getRoot();
DependencyRequest dr = new DependencyRequest(node, FILTER);
repositorySystem.resolveDependencies(session, node, FILTER); repositorySystem.resolveDependencies(session, dr);
synchronized (Classpath.class) synchronized (Classpath.class)
{ {
@@ -295,6 +318,18 @@ public class AetherPluginHandler
return classpathSet; return classpathSet;
} }
/**
* Method description
*
*
* @return
*/
private Proxy createProxy()
{
return new Proxy(Proxy.TYPE_HTTP, configuration.getProxyServer(),
configuration.getProxyPort(), null);
}
/** /**
* Method description * Method description
* *
@@ -381,6 +416,9 @@ public class AetherPluginHandler
/** Field description */ /** Field description */
private File classpathFile; private File classpathFile;
/** Field description */
private ScmConfiguration configuration;
/** Field description */ /** Field description */
private JAXBContext jaxbContext; private JAXBContext jaxbContext;

View File

@@ -61,8 +61,6 @@ import sonia.scm.util.Util;
import java.io.InputStream; import java.io.InputStream;
import java.io.UnsupportedEncodingException; import java.io.UnsupportedEncodingException;
import java.net.URL;
import java.net.URLConnection;
import java.net.URLEncoder; import java.net.URLEncoder;
import java.util.Collection; import java.util.Collection;
@@ -553,7 +551,7 @@ public class DefaultPluginManager implements PluginManager
if (pluginHandler == null) if (pluginHandler == null)
{ {
pluginHandler = new AetherPluginHandler(this, pluginHandler = new AetherPluginHandler(this,
SCMContext.getContext()); SCMContext.getContext(), configuration);
} }
pluginHandler.setPluginRepositories(center.getRepositories()); pluginHandler.setPluginRepositories(center.getRepositories());