diff --git a/maven-repository-proxy/src/main/java/org/apache/maven/repository/proxy/DefaultProxyManager.java b/maven-repository-proxy/src/main/java/org/apache/maven/repository/proxy/DefaultProxyManager.java index cfec8ce46..bad33befb 100644 --- a/maven-repository-proxy/src/main/java/org/apache/maven/repository/proxy/DefaultProxyManager.java +++ b/maven-repository-proxy/src/main/java/org/apache/maven/repository/proxy/DefaultProxyManager.java @@ -445,7 +445,14 @@ public class DefaultProxyManager boolean connected = false; try { - wagon.connect( repository, repository.getProxy() ); + if ( repository.isProxied() ) + { + wagon.connect( repository, config.getHttpProxy() ); + } + else + { + wagon.connect( repository ); + } connected = true; } catch ( ConnectionException e ) diff --git a/maven-repository-proxy/src/main/java/org/apache/maven/repository/proxy/configuration/MavenProxyConfigurationReader.java b/maven-repository-proxy/src/main/java/org/apache/maven/repository/proxy/configuration/MavenProxyConfigurationReader.java index 8b9d447bf..d5831bb68 100644 --- a/maven-repository-proxy/src/main/java/org/apache/maven/repository/proxy/configuration/MavenProxyConfigurationReader.java +++ b/maven-repository-proxy/src/main/java/org/apache/maven/repository/proxy/configuration/MavenProxyConfigurationReader.java @@ -49,8 +49,11 @@ public class MavenProxyConfigurationReader { HttpRepoConfiguration httpRepo = (HttpRepoConfiguration) repoConfig; MavenProxyConfiguration httpProxy = httpRepo.getProxy(); - repo.setProxy( httpProxy.getHost(), httpProxy.getPort(), httpProxy.getUsername(), - httpProxy.getPassword() ); + //todo put into the configuration the proxy + if ( httpProxy != null ) + { + repo.setProxied( true ); + } } repoList.add( repo ); diff --git a/maven-repository-proxy/src/main/java/org/apache/maven/repository/proxy/configuration/ProxyConfiguration.java b/maven-repository-proxy/src/main/java/org/apache/maven/repository/proxy/configuration/ProxyConfiguration.java index 37bc31e6c..3ec4e1c2c 100644 --- a/maven-repository-proxy/src/main/java/org/apache/maven/repository/proxy/configuration/ProxyConfiguration.java +++ b/maven-repository-proxy/src/main/java/org/apache/maven/repository/proxy/configuration/ProxyConfiguration.java @@ -17,7 +17,7 @@ package org.apache.maven.repository.proxy.configuration; */ import org.apache.maven.repository.proxy.repository.ProxyRepository; -import org.codehaus.plexus.PlexusContainer; +import org.apache.maven.wagon.proxy.ProxyInfo; import java.io.File; import java.util.ArrayList; @@ -34,14 +34,14 @@ public class ProxyConfiguration { public static final String ROLE = ProxyConfiguration.class.getName(); - private PlexusContainer container; - private List repositories = new ArrayList(); private String cachePath; private String layout; + private ProxyInfo httpProxy; + /** * Used to set the location where the proxy should cache the configured repositories * @@ -62,6 +62,41 @@ public class ProxyConfiguration return cachePath; } + public void setHttpProxy( ProxyInfo httpProxy ) + { + this.httpProxy = httpProxy; + } + + public void setHttpProxy( String host, int port ) + { + ProxyInfo proxyInfo = new ProxyInfo(); + proxyInfo.setHost( host ); + proxyInfo.setPort( port ); + + setHttpProxy( proxyInfo ); + } + + public void setHttpProxy( String host, int port, String username, String password ) + { + setHttpProxy( host, port ); + httpProxy.setUserName( username ); + httpProxy.setPassword( password ); + } + + public void setHttpProxy( String host, int port, String username, String password, String ntlmHost, String ntlmDomain ) + { + setHttpProxy( host, port ); + httpProxy.setUserName( username ); + httpProxy.setPassword( password ); + httpProxy.setNtlmHost( ntlmHost ); + httpProxy.setNtlmDomain( ntlmDomain ); + } + + public ProxyInfo getHttpProxy() + { + return httpProxy; + } + /** * Used to add proxied repositories. * diff --git a/maven-repository-proxy/src/main/java/org/apache/maven/repository/proxy/repository/ProxyRepository.java b/maven-repository-proxy/src/main/java/org/apache/maven/repository/proxy/repository/ProxyRepository.java index 8e5a2e824..37fd2110c 100644 --- a/maven-repository-proxy/src/main/java/org/apache/maven/repository/proxy/repository/ProxyRepository.java +++ b/maven-repository-proxy/src/main/java/org/apache/maven/repository/proxy/repository/ProxyRepository.java @@ -18,7 +18,6 @@ package org.apache.maven.repository.proxy.repository; import org.apache.maven.artifact.repository.DefaultArtifactRepository; import org.apache.maven.artifact.repository.layout.ArtifactRepositoryLayout; -import org.apache.maven.wagon.proxy.ProxyInfo; /** * Class to represent the Proxy repository. Currently does not provide additional methods from @@ -29,14 +28,14 @@ import org.apache.maven.wagon.proxy.ProxyInfo; public class ProxyRepository extends DefaultArtifactRepository { - // zero does not cache + // zero caches forever private long cachePeriod = 0; private boolean cacheFailures = false; private boolean hardfail = false; - private ProxyInfo proxy; + private boolean proxied = false; public ProxyRepository( String id, String url, ArtifactRepositoryLayout layout, boolean cacheFailures, long cachePeriod ) @@ -75,50 +74,12 @@ public class ProxyRepository public boolean isProxied() { - return ( proxy != null ); + return proxied; } - public ProxyInfo getProxy() + public void setProxied( boolean proxied ) { - return proxy; - } - - public void setProxy( String host, int port ) - { - ProxyInfo proxyInfo = new ProxyInfo(); - proxyInfo.setHost( host ); - proxyInfo.setPort( port ); - - setProxy( proxyInfo ); - } - - public void setProxy( String host, int port, String username, String password ) - { - ProxyInfo proxyInfo = new ProxyInfo(); - proxyInfo.setHost( host ); - proxyInfo.setPort( port ); - proxyInfo.setUserName( username ); - proxyInfo.setPassword( password ); - - setProxy( proxyInfo ); - } - - public void setProxy( String host, int port, String username, String password, String ntlmHost, String ntlmDomain ) - { - ProxyInfo proxyInfo = new ProxyInfo(); - proxyInfo.setHost( host ); - proxyInfo.setPort( port ); - proxyInfo.setUserName( username ); - proxyInfo.setPassword( password ); - proxyInfo.setNtlmHost( ntlmHost ); - proxyInfo.setNtlmDomain( ntlmDomain ); - - setProxy( proxyInfo ); - } - - public void setProxy( ProxyInfo proxy ) - { - this.proxy = proxy; + this.proxied = proxied; } /** diff --git a/maven-repository-proxy/src/test/java/org/apache/maven/repository/proxy/configuration/ProxyConfigurationTest.java b/maven-repository-proxy/src/test/java/org/apache/maven/repository/proxy/configuration/ProxyConfigurationTest.java index dd499ea4f..6fa469369 100644 --- a/maven-repository-proxy/src/test/java/org/apache/maven/repository/proxy/configuration/ProxyConfigurationTest.java +++ b/maven-repository-proxy/src/test/java/org/apache/maven/repository/proxy/configuration/ProxyConfigurationTest.java @@ -61,7 +61,8 @@ public class ProxyConfigurationTest ProxyRepository repo2 = new ProxyRepository( "repo2", "http://www.ibiblio.org/maven", legacyLayout ); repo2.setCacheFailures( false ); repo2.setCachePeriod( 3600 ); - repo2.setProxy( "some.local.proxy", 80, "username", "password" ); + repo2.setProxied( true ); + config.setHttpProxy( "some.local.proxy", 80, "username", "password" ); config.addRepository( repo2 ); assertEquals( 2, config.getRepositories().size() ); @@ -83,7 +84,7 @@ public class ProxyConfigurationTest assertEquals( repo2, repo ); assertTrue( repo.isProxied() ); - ProxyInfo proxyInfo = repo.getProxy(); + ProxyInfo proxyInfo = config.getHttpProxy(); assertNotNull( proxyInfo ); assertEquals( "some.local.proxy", proxyInfo.getHost() ); assertEquals( 80, proxyInfo.getPort() );