From 136af3e21424fa40013d00f53e0d38611440a05d Mon Sep 17 00:00:00 2001 From: "Edwin L. Punzalan" Date: Fri, 17 Feb 2006 07:19:44 +0000 Subject: [PATCH] PR: MRM-96 Enabled use of proxy and added import of proxy configuration from maven-proxy configuration file. git-svn-id: https://svn.apache.org/repos/asf/maven/repository-manager/trunk@378453 13f79535-47bb-0310-9956-ffa450edef68 --- .../repository/proxy/DefaultProxyManager.java | 4 +- .../configuration/ProxyConfiguration.java | 8 +++ .../proxy/repository/ProxyRepository.java | 51 +++++++++++++++++++ .../configuration/ProxyConfigurationTest.java | 9 ++++ 4 files changed, 70 insertions(+), 2 deletions(-) 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 bfd670179..bd8ceee7d 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 @@ -287,7 +287,7 @@ public class DefaultProxyManager } catch ( ResourceDoesNotExistException e ) { - //@todo usage for cacheFailure + //@todo usage for cacheFailure //do nothing, file not found in this repository } catch ( AuthorizationException e ) @@ -369,7 +369,7 @@ public class DefaultProxyManager boolean connected = false; try { - wagon.connect( repository ); + wagon.connect( repository, repository.getProxy() ); connected = true; } catch ( ConnectionException e ) 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 659381597..d36fa4961 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 @@ -171,6 +171,14 @@ public class ProxyConfiguration repo.setCacheFailures( repoConfig.getCacheFailures() ); repo.setCachePeriod( repoConfig.getCachePeriod() ); + if ( repoConfig instanceof HttpRepoConfiguration ) + { + HttpRepoConfiguration httpRepo = (HttpRepoConfiguration) repoConfig; + MavenProxyConfiguration httpProxy = httpRepo.getProxy(); + repo.setProxy( httpProxy.getHost(), httpProxy.getPort(), + httpProxy.getUsername(), httpProxy.getPassword() ); + } + repoList.add( repo ); } } 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 efbe6b3d4..3cf2e0978 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,6 +18,7 @@ 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 @@ -33,6 +34,8 @@ public class ProxyRepository private boolean cacheFailures = false; + private ProxyInfo proxy; + public ProxyRepository( String id, String url, ArtifactRepositoryLayout layout, boolean cacheFailures, long cachePeriod ) { @@ -67,4 +70,52 @@ public class ProxyRepository { this.cacheFailures = cacheFailures; } + + public boolean isProxied() + { + return ( proxy != null ); + } + + public ProxyInfo getProxy() + { + 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; + } } 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 08b1f086f..0b6aafa78 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 @@ -21,6 +21,7 @@ import org.apache.maven.artifact.repository.layout.ArtifactRepositoryLayout; import org.apache.maven.artifact.repository.layout.DefaultRepositoryLayout; import org.apache.maven.artifact.repository.layout.LegacyRepositoryLayout; import org.apache.maven.repository.proxy.repository.ProxyRepository; +import org.apache.maven.wagon.proxy.ProxyInfo; import org.codehaus.plexus.PlexusTestCase; import org.codehaus.plexus.util.FileUtils; @@ -72,6 +73,7 @@ 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" ); config.addRepository( repo2 ); assertEquals( 2, config.getRepositories().size() ); @@ -89,6 +91,13 @@ public class ProxyConfigurationTest assertFalse( repo.isCacheFailures() ); assertEquals( 3600, repo.getCachePeriod() ); assertEquals( repo2, repo ); + assertTrue( repo.isProxied() ); + ProxyInfo proxyInfo = repo.getProxy(); + assertNotNull( proxyInfo ); + assertEquals( "some.local.proxy", proxyInfo.getHost() ); + assertEquals( 80, proxyInfo.getPort() ); + assertEquals( "username", proxyInfo.getUserName() ); + assertEquals( "password", proxyInfo.getPassword() ); try { -- 2.39.5