Index: maven-core/src/main/java/org/apache/maven/DefaultMaven.java
===================================================================
--- maven-core/src/main/java/org/apache/maven/DefaultMaven.java (r‚vision 480167)
+++ maven-core/src/main/java/org/apache/maven/DefaultMaven.java (copie de travail)
@@ -627,17 +627,24 @@
try
{
- Proxy proxy = settings.getActiveProxy();
+ List proxies = settings.getActiveProxies();
- if ( proxy != null )
+ if ( proxies != null )
{
- if ( proxy.getHost() == null )
+
+ for ( Iterator it = proxies.iterator(); it.hasNext(); )
{
- throw new SettingsConfigurationException( "Proxy in settings.xml has no host" );
+ Proxy proxy = (Proxy) it.next();
+ if ( proxy.getHost() == null )
+ {
+ throw new SettingsConfigurationException( "Proxy in settings.xml has no host, id : "
+ + proxy.getId() );
+ }
+
+ wagonManager.addProxy( proxy.getProtocol(), proxy.getHost(), proxy.getPort(), proxy.getUsername(),
+ proxy.getPassword(), proxy.getNonProxyHosts() );
}
- wagonManager.addProxy( proxy.getProtocol(), proxy.getHost(), proxy.getPort(), proxy.getUsername(),
- proxy.getPassword(), proxy.getNonProxyHosts() );
}
for ( Iterator i = settings.getServers().iterator(); i.hasNext(); )
Index: maven-settings/src/test/java/org/apache/maven/settings/SettingsTest.java
===================================================================
--- maven-settings/src/test/java/org/apache/maven/settings/SettingsTest.java (r‚vision 0)
+++ maven-settings/src/test/java/org/apache/maven/settings/SettingsTest.java (r‚vision 0)
@@ -0,0 +1,141 @@
+package org.apache.maven.settings;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.InputStreamReader;
+import java.io.Reader;
+
+import org.apache.maven.settings.io.xpp3.SettingsXpp3Reader;
+import org.codehaus.plexus.util.xml.pull.XmlPullParserException;
+
+import junit.framework.TestCase;
+
+/**
+ * Test class for the {@link Settings} Class
+ *
+ * @author Thomas Recloux
+ */
+public class SettingsTest extends TestCase
+{
+
+ public void testActiveProxiesFromObjects()
+ {
+
+ Proxy inactiveHttpProxy = new Proxy();
+ inactiveHttpProxy.setActive( false );
+ inactiveHttpProxy.setHost( "host" );
+ inactiveHttpProxy.setPort( 9999 );
+ inactiveHttpProxy.setId( "inactiveHttpProxy" );
+ inactiveHttpProxy.setProtocol( "http" );
+
+ Proxy activeHttpProxy = new Proxy();
+ activeHttpProxy.setActive( true );
+ activeHttpProxy.setHost( "host" );
+ activeHttpProxy.setPort( 9999 );
+ activeHttpProxy.setId( "activeHttpProxy" );
+ activeHttpProxy.setProtocol( "http" );
+
+ Proxy activeHttpsProxy = new Proxy();
+ activeHttpsProxy.setActive( true );
+ activeHttpsProxy.setHost( "host" );
+ activeHttpsProxy.setPort( 9999 );
+ activeHttpsProxy.setId( "activeHttpsProxy" );
+ activeHttpsProxy.setProtocol( "https" );
+
+ // Test with one active proxy
+ Settings settings = new Settings();
+ settings.addProxy( activeHttpProxy );
+ assertEquals( activeHttpProxy, settings.getActiveProxy() );
+ assertNotNull( settings.getActiveProxies() );
+ assertEquals( 1, settings.getActiveProxies().size() );
+ assertEquals( activeHttpProxy, settings.getActiveProxies().get( 0 ) );
+
+ // Test with one inactive proxy
+ settings = new Settings();
+ settings.addProxy( inactiveHttpProxy );
+ assertEquals( inactiveHttpProxy, settings.getActiveProxy() );
+ assertNotNull( settings.getActiveProxies() );
+ assertEquals( 1, settings.getActiveProxies().size() );
+ assertEquals( inactiveHttpProxy, settings.getActiveProxies().get( 0 ) );
+
+ // Test with two proxies, on active, one inactive
+ settings = new Settings();
+ settings.addProxy( inactiveHttpProxy );
+ settings.addProxy( activeHttpProxy );
+ assertEquals( activeHttpProxy, settings.getActiveProxy() );
+ assertNotNull( settings.getActiveProxies() );
+ assertEquals( 1, settings.getActiveProxies().size() );
+ assertEquals( activeHttpProxy, settings.getActiveProxies().get( 0 ) );
+
+ // Test with two active proxies
+ settings = new Settings();
+ settings.addProxy( activeHttpProxy );
+ settings.addProxy( activeHttpsProxy );
+ assertEquals( activeHttpProxy, settings.getActiveProxy() );
+ assertNotNull( settings.getActiveProxies() );
+ assertEquals( 2, settings.getActiveProxies().size() );
+ assertEquals( activeHttpProxy, settings.getActiveProxies().get( 0 ) );
+ assertEquals( activeHttpsProxy, settings.getActiveProxies().get( 1 ) );
+
+ }
+
+ public void testActiveProxiesFromXmlFile() throws IOException, XmlPullParserException
+ {
+ // Test with one active proxy
+ Settings settings = buildSettings( "settings-one-active-proxy.xml" );
+ assertNotNull( settings.getActiveProxy() );
+ assertEquals( "activeHttpProxy", settings.getActiveProxy().getId() );
+ assertEquals( true, settings.getActiveProxy().isActive() );
+ assertNotNull( settings.getActiveProxies() );
+ assertEquals( 1, settings.getActiveProxies().size() );
+ assertEquals( "activeHttpProxy", ((Proxy) settings.getActiveProxies().get( 0 )).getId() );
+
+
+ // Test with one inactive proxy
+ settings = buildSettings( "settings-one-inactive-proxy.xml" );
+ assertNotNull( settings.getActiveProxy() );
+ assertEquals( "inactiveHttpProxy", settings.getActiveProxy().getId() );
+ assertEquals( false, settings.getActiveProxy().isActive() );
+ assertNotNull( settings.getActiveProxies() );
+ assertEquals( 1, settings.getActiveProxies().size() );
+ assertEquals( "inactiveHttpProxy", ((Proxy) settings.getActiveProxies().get( 0 )).getId() );
+
+ // Test with one active unspecified proxy
+ settings = buildSettings( "settings-one-active-unspecified-proxy.xml" );
+ assertNotNull( settings.getActiveProxy() );
+ assertEquals( "unspecifiedHttpProxy", settings.getActiveProxy().getId() );
+ assertEquals( false, settings.getActiveProxy().isActive() );
+ assertNotNull( settings.getActiveProxies() );
+ assertEquals( 1, settings.getActiveProxies().size() );
+ assertEquals( "unspecifiedHttpProxy", ((Proxy) settings.getActiveProxies().get( 0 )).getId() );
+
+ // Test with two active proxies
+ settings = buildSettings( "settings-two-active-proxies.xml" );
+ assertNotNull( settings.getActiveProxy() );
+ assertEquals( "activeHttpProxy", settings.getActiveProxy().getId() );
+ assertNotNull( settings.getActiveProxies() );
+ assertEquals( 2, settings.getActiveProxies().size() );
+ assertEquals( "activeHttpProxy", ((Proxy) settings.getActiveProxies().get( 0 )).getId() );
+ assertEquals( true, ((Proxy) settings.getActiveProxies().get( 0 )).isActive() );
+ assertEquals( "activeHttpsProxy", ((Proxy) settings.getActiveProxies().get( 1 )).getId() );
+ assertEquals( true, ((Proxy) settings.getActiveProxies().get( 1 )).isActive() );
+
+ // Test with one active and one incative proxies
+ settings = buildSettings( "settings-one-active-one-inactive-proxies.xml" );
+ assertNotNull( settings.getActiveProxy() );
+ assertEquals( "activeHttpProxy", settings.getActiveProxy().getId() );
+ assertEquals( true, settings.getActiveProxy().isActive() );
+ assertNotNull( settings.getActiveProxies() );
+ assertEquals( 1, settings.getActiveProxies().size() );
+ assertEquals( "activeHttpProxy", ((Proxy) settings.getActiveProxies().get( 0 )).getId() );
+
+
+ }
+
+ private Settings buildSettings(String confResourceName) throws IOException, XmlPullParserException {
+ InputStream in = Thread.currentThread().getContextClassLoader().getResourceAsStream( confResourceName );
+ Reader reader = new InputStreamReader( in );
+ return new SettingsXpp3Reader().read( reader );
+ }
+
+}
Modification de propri‚t‚s sur maven-settings\src\test\java\org\apache\maven\settings\SettingsTest.java
___________________________________________________________________
Nom : svn:keywords
+ Id
Nom : svn:eol-style
+ native
Index: maven-settings/src/test/resources/settings-one-active-unspecified-proxy.xml
===================================================================
--- maven-settings/src/test/resources/settings-one-active-unspecified-proxy.xml (r‚vision 0)
+++ maven-settings/src/test/resources/settings-one-active-unspecified-proxy.xml (r‚vision 0)
@@ -0,0 +1,11 @@
+
+
+
+
+ unspecifiedHttpProxy
+ http
+ proxy.host.net
+ 80
+
+
+
Modification de propri‚t‚s sur maven-settings\src\test\resources\settings-one-active-unspecified-proxy.xml
___________________________________________________________________
Nom : svn:keywords
+ Id
Nom : svn:eol-style
+ native
Index: maven-settings/src/test/resources/settings-one-active-proxy.xml
===================================================================
--- maven-settings/src/test/resources/settings-one-active-proxy.xml (r‚vision 0)
+++ maven-settings/src/test/resources/settings-one-active-proxy.xml (r‚vision 0)
@@ -0,0 +1,12 @@
+
+
+
+
+ activeHttpProxy
+ true
+ http
+ proxy.host.net
+ 80
+
+
+
Modification de propri‚t‚s sur maven-settings\src\test\resources\settings-one-active-proxy.xml
___________________________________________________________________
Nom : svn:keywords
+ Id
Nom : svn:eol-style
+ native
Index: maven-settings/src/test/resources/settings-two-active-proxies.xml
===================================================================
--- maven-settings/src/test/resources/settings-two-active-proxies.xml (r‚vision 0)
+++ maven-settings/src/test/resources/settings-two-active-proxies.xml (r‚vision 0)
@@ -0,0 +1,19 @@
+
+
+
+
+ activeHttpProxy
+ true
+ http
+ proxy.host.net
+ 80
+
+
+ activeHttpsProxy
+ true
+ https
+ proxy.host.net
+ 80
+
+
+
Modification de propri‚t‚s sur maven-settings\src\test\resources\settings-two-active-proxies.xml
___________________________________________________________________
Nom : svn:keywords
+ Id
Nom : svn:eol-style
+ native
Index: maven-settings/src/test/resources/settings-one-active-one-inactive-proxies.xml
===================================================================
--- maven-settings/src/test/resources/settings-one-active-one-inactive-proxies.xml (r‚vision 0)
+++ maven-settings/src/test/resources/settings-one-active-one-inactive-proxies.xml (r‚vision 0)
@@ -0,0 +1,19 @@
+
+
+
+
+ activeHttpProxy
+ true
+ http
+ proxy.host.net
+ 80
+
+
+ activeHttpsProxy
+ false
+ https
+ proxy.host.net
+ 80
+
+
+
Modification de propri‚t‚s sur maven-settings\src\test\resources\settings-one-active-one-inactive-proxies.xml
___________________________________________________________________
Nom : svn:keywords
+ Id
Nom : svn:eol-style
+ native
Index: maven-settings/src/test/resources/settings-one-inactive-proxy.xml
===================================================================
--- maven-settings/src/test/resources/settings-one-inactive-proxy.xml (r‚vision 0)
+++ maven-settings/src/test/resources/settings-one-inactive-proxy.xml (r‚vision 0)
@@ -0,0 +1,12 @@
+
+
+
+
+ inactiveHttpProxy
+ false
+ http
+ proxy.host.net
+ 80
+
+
+
Modification de propri‚t‚s sur maven-settings\src\test\resources\settings-one-inactive-proxy.xml
___________________________________________________________________
Nom : svn:keywords
+ Id
Nom : svn:eol-style
+ native
Index: maven-settings/settings.mdo
===================================================================
--- maven-settings/settings.mdo (r‚vision 480167)
+++ maven-settings/settings.mdo (copie de travail)
@@ -217,29 +217,62 @@
return Boolean.valueOf( isInteractiveMode() );
}
+ /** First active Proxy */
private Proxy activeProxy;
+ /** List of active Proxies */
+ private java.util.List activeProxies;
public void flushActiveProxy()
{
this.activeProxy = null;
}
+
+ public void flushActiveProxies()
+ {
+ this.activeProxies = null;
+ }
+
- public synchronized Proxy getActiveProxy()
+ /**
+ * @return the first active proxy(@see Proxy)
+ * @deprecated Multiple proxies can be activated, use {@link #getActiveProxies}
+ */
+ public Proxy getActiveProxy()
{
+ initActiveProxies();
+ return activeProxy;
+ }
+
+
+ /**
+ * @return list of active proxies(@see Proxy}
+ */
+ public java.util.List getActiveProxies()
+ {
+ initActiveProxies();
+ return activeProxies;
+ }
+
+ private synchronized void initActiveProxies() {
+
if(activeProxy == null)
{
java.util.List proxies = getProxies();
+ activeProxies = new java.util.ArrayList();
if ( proxies != null && !proxies.isEmpty() )
{
if ( proxies.size() > 1 )
{
+ // return all active proxies
for ( java.util.Iterator it = proxies.iterator(); it.hasNext(); )
{
Proxy proxy = (Proxy) it.next();
if ( proxy.isActive() )
{
- activeProxy = proxy;
- break;
+ if (activeProxy == null) {
+ activeProxy = proxy;
+ }
+ activeProxies.add( proxy );
}
}
}
@@ -247,11 +280,10 @@
{
// If we only have one proxy, use it as the active one.
activeProxy = (Proxy) proxies.get( 0 );
+ activeProxies.add( proxies.get( 0 ) );
}
}
}
-
- return activeProxy;
}
public Server getServer( String serverId )
Index: maven-artifact-manager/src/main/java/org/apache/maven/artifact/manager/DefaultWagonManager.java
===================================================================
--- maven-artifact-manager/src/main/java/org/apache/maven/artifact/manager/DefaultWagonManager.java (r‚vision 480167)
+++ maven-artifact-manager/src/main/java/org/apache/maven/artifact/manager/DefaultWagonManager.java (copie de travail)
@@ -629,9 +629,19 @@
}
}
+ /**
+ * Returns the configured proxy informations for the specified protocol
+ * If no https proxy is configured, fallsback on http protocol
+ */
public ProxyInfo getProxy( String protocol )
{
- return (ProxyInfo) proxies.get( protocol );
+ ProxyInfo proxy = (ProxyInfo) proxies.get(protocol);
+ /* If no proxy is specified for the https protocol,
+ * search a proxy for the http protocol. */
+ if (proxy == null && "https".equals(protocol)) {
+ proxy = (ProxyInfo) proxies.get("http");
+ }
+ return proxy;
}
public AuthenticationInfo getAuthenticationInfo( String id )