maven-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From denn...@apache.org
Subject svn commit: r636147 - in /maven/plugins/trunk/maven-site-plugin/src: main/java/org/apache/maven/plugins/site/ test/java/org/apache/maven/plugins/site/
Date Tue, 11 Mar 2008 23:25:30 GMT
Author: dennisl
Date: Tue Mar 11 16:25:22 2008
New Revision: 636147

URL: http://svn.apache.org/viewvc?rev=636147&view=rev
Log:
[MSITE-211] Can't deploy site using site:deploy due to a ProxyHTTP error
Submitted by: Cyrille Le Clerc
Reviewed by: Dennis Lundberg

o I modified the handling of wildcards and the associated tests.

Added:
    maven/plugins/trunk/maven-site-plugin/src/test/java/org/apache/maven/plugins/site/SiteDeployMojoTest.java
  (with props)
Modified:
    maven/plugins/trunk/maven-site-plugin/src/main/java/org/apache/maven/plugins/site/SiteDeployMojo.java
    maven/plugins/trunk/maven-site-plugin/src/main/java/org/apache/maven/plugins/site/SiteStageDeployMojo.java

Modified: maven/plugins/trunk/maven-site-plugin/src/main/java/org/apache/maven/plugins/site/SiteDeployMojo.java
URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-site-plugin/src/main/java/org/apache/maven/plugins/site/SiteDeployMojo.java?rev=636147&r1=636146&r2=636147&view=diff
==============================================================================
--- maven/plugins/trunk/maven-site-plugin/src/main/java/org/apache/maven/plugins/site/SiteDeployMojo.java
(original)
+++ maven/plugins/trunk/maven-site-plugin/src/main/java/org/apache/maven/plugins/site/SiteDeployMojo.java
Tue Mar 11 16:25:22 2008
@@ -23,6 +23,7 @@
 import java.util.HashMap;
 import java.util.Map;
 
+import org.apache.commons.lang.StringUtils;
 import org.apache.maven.artifact.manager.WagonConfigurationException;
 import org.apache.maven.artifact.manager.WagonManager;
 import org.apache.maven.model.DistributionManagement;
@@ -30,7 +31,6 @@
 import org.apache.maven.plugin.AbstractMojo;
 import org.apache.maven.plugin.MojoExecutionException;
 import org.apache.maven.project.MavenProject;
-import org.apache.maven.settings.Proxy;
 import org.apache.maven.settings.Settings;
 import org.apache.maven.wagon.CommandExecutionException;
 import org.apache.maven.wagon.CommandExecutor;
@@ -56,11 +56,11 @@
 import org.codehaus.plexus.personality.plexus.lifecycle.phase.Contextualizable;
 
 /**
- * Deploys website using scp/file protocol.
+ * Deploys the site using scp/file protocol.
  * For scp protocol, website files are packaged into zip archive,
- * then archive is transfred to remote host, nextly it is un-archived.
+ * then the archive is transfered to the remote host, next it is un-archived.
  * This method of deployment should normally be much faster
- * then making file by file copy.  For file protocol, the files are copied
+ * then making a file by file copy.  For file protocol, the files are copied
  * directly to the destination directory.
  *
  * @author <a href="mailto:michal@org.codehaus.org">Michal Maczka</a>
@@ -171,7 +171,7 @@
 
             wagon.addTransferListener( debug );
 
-            ProxyInfo proxyInfo = getProxyInfo( settings );
+            ProxyInfo proxyInfo = getProxyInfo( repository, wagonManager );
             if ( proxyInfo != null )
             {
                 wagon.connect( repository, wagonManager.getAuthenticationInfo( id ), proxyInfo
);
@@ -229,27 +229,65 @@
     }
 
     /**
-     * Convenience method to map a <code>Proxy</code> object from the user system
settings to a
-     * <code>ProxyInfo</code> object.
-     *
-     * @return a proxyInfo object instancied or null if no active proxy is define in the
settings.xml
+     * <p>
+     * Get the <code>ProxyInfo</code> of the proxy associated with the <code>host</code>
+     * and the <code>protocol</code> of the given <code>repository</code>

+     * </p>
+     * <p>
+     * Extract from <a href="http://java.sun.com/j2se/1.5.0/docs/guide/net/properties.html">
+     * J2SE Doc : Networking Properties - nonProxyHosts</a> : "The value can be a list
of hosts, 
+     * each separated by a |, and in addition a wildcard character (*) can be used for matching"
+     * </p>
+     * <p>
+     * Defensively support for comma (",") and semi colon (";") in addition to pipe ("|")
as separator.
+     * </p>
+     * 
+     * @return a ProxyInfo object instantiated or <code>null</code> if no matching
proxy is found
      */
-    public static ProxyInfo getProxyInfo( Settings settings )
+    public static ProxyInfo getProxyInfo( Repository repository, WagonManager wagonManager
)
     {
-        ProxyInfo proxyInfo = null;
-        if ( settings != null && settings.getActiveProxy() != null )
-        {
-            Proxy settingsProxy = settings.getActiveProxy();
+        ProxyInfo proxyInfo = wagonManager.getProxy( repository.getProtocol() );
 
-            proxyInfo = new ProxyInfo();
-            proxyInfo.setHost( settingsProxy.getHost() );
-            proxyInfo.setType( settingsProxy.getProtocol() );
-            proxyInfo.setPort( settingsProxy.getPort() );
-            proxyInfo.setNonProxyHosts( settingsProxy.getNonProxyHosts() );
-            proxyInfo.setUserName( settingsProxy.getUsername() );
-            proxyInfo.setPassword( settingsProxy.getPassword() );
+        if ( proxyInfo == null )
+        {
+            return null;
         }
 
+        String host = repository.getHost();
+        String nonProxyHostsAsString = proxyInfo.getNonProxyHosts();
+        String[] nonProxyHosts = StringUtils.split( nonProxyHostsAsString, ",;|" );
+        for ( int i = 0; i < nonProxyHosts.length; i++ )
+        {
+            String nonProxyHost = nonProxyHosts[i];
+            if ( StringUtils.contains( nonProxyHost, "*" ) )
+            {
+                // Handle wildcard at the end, beginning or middle of the nonProxyHost
+                String nonProxyHostPrefix = StringUtils.substringBefore( nonProxyHost, "*"
);
+                String nonProxyHostSuffix = StringUtils.substringAfter( nonProxyHost, "*"
);
+                // prefix*
+                if ( StringUtils.isNotEmpty(nonProxyHostPrefix) && host.startsWith(
nonProxyHostPrefix )
+                    && StringUtils.isEmpty(nonProxyHostSuffix) )
+                {
+                    return null;
+                }
+                // *suffix
+                if ( StringUtils.isEmpty(nonProxyHostPrefix)
+                    && StringUtils.isNotEmpty(nonProxyHostSuffix) && host.endsWith(
nonProxyHostSuffix ))
+                {
+                    return null;
+                }
+                // prefix*suffix
+                if ( StringUtils.isNotEmpty(nonProxyHostPrefix) && host.startsWith(
nonProxyHostPrefix )
+                    && StringUtils.isNotEmpty(nonProxyHostSuffix) && host.endsWith(
nonProxyHostSuffix ))
+                {
+                    return null;
+                }
+            }
+            else if ( host.equals( nonProxyHost ) )
+            {
+                return null;
+            }
+        }
         return proxyInfo;
     }
 

Modified: maven/plugins/trunk/maven-site-plugin/src/main/java/org/apache/maven/plugins/site/SiteStageDeployMojo.java
URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-site-plugin/src/main/java/org/apache/maven/plugins/site/SiteStageDeployMojo.java?rev=636147&r1=636146&r2=636147&view=diff
==============================================================================
--- maven/plugins/trunk/maven-site-plugin/src/main/java/org/apache/maven/plugins/site/SiteStageDeployMojo.java
(original)
+++ maven/plugins/trunk/maven-site-plugin/src/main/java/org/apache/maven/plugins/site/SiteStageDeployMojo.java
Tue Mar 11 16:25:22 2008
@@ -119,7 +119,7 @@
 
             wagon.addTransferListener( debug );
 
-            ProxyInfo proxyInfo = SiteDeployMojo.getProxyInfo( settings );
+            ProxyInfo proxyInfo = SiteDeployMojo.getProxyInfo( repository, wagonManager );
             if ( proxyInfo != null )
             {
                 wagon.connect( repository, wagonManager.getAuthenticationInfo( id ), proxyInfo
);

Added: maven/plugins/trunk/maven-site-plugin/src/test/java/org/apache/maven/plugins/site/SiteDeployMojoTest.java
URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-site-plugin/src/test/java/org/apache/maven/plugins/site/SiteDeployMojoTest.java?rev=636147&view=auto
==============================================================================
--- maven/plugins/trunk/maven-site-plugin/src/test/java/org/apache/maven/plugins/site/SiteDeployMojoTest.java
(added)
+++ maven/plugins/trunk/maven-site-plugin/src/test/java/org/apache/maven/plugins/site/SiteDeployMojoTest.java
Tue Mar 11 16:25:22 2008
@@ -0,0 +1,123 @@
+package org.apache.maven.plugins.site;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+import junit.framework.TestCase;
+import org.apache.maven.artifact.manager.DefaultWagonManager;
+import org.apache.maven.artifact.manager.WagonManager;
+import org.apache.maven.wagon.proxy.ProxyInfo;
+import org.apache.maven.wagon.repository.Repository;
+
+/**
+ * @author <a href="mailto:cleclerc@xebia.fr">Cyrille Le Clerc</a>
+ */
+public class SiteDeployMojoTest
+    extends TestCase
+{
+    WagonManager wagonManager;
+
+    Repository repository;
+
+    protected void setUp()
+        throws Exception
+    {
+        super.setUp();
+        wagonManager = new DefaultWagonManager();
+        repository = new Repository( "my-repository", "scp://repository-host/var/maven2"
);
+    }
+
+    public void testGetProxyInfoNoProxyForRepositoryProtocol()
+    {
+        wagonManager.addProxy( "http", "proxy-host", 8080, "my-user", "my-password", null
);
+        ProxyInfo proxyInfo = SiteDeployMojo.getProxyInfo( repository, wagonManager );
+        assertNull( "ProxyInfo must be null because http != scp", proxyInfo );
+    }
+
+    public void testGetProxyInfoForRepositoryHostExactlyMatchesNonProxyHosts()
+    {
+        wagonManager.addProxy( "scp", "localhost", 8080, "my-user", "my-password",
+                               "a-host,repository-host;another-host" );
+        ProxyInfo proxyInfo = SiteDeployMojo.getProxyInfo( repository, wagonManager );
+        assertNull( "ProxyInfo must be null because 'repository-host' in nonProxyHosts list",
proxyInfo );
+    }
+
+    public void testGetProxyInfoForRepositoryHostWildcardMatchNonProxyHosts1()
+    {
+        wagonManager.addProxy( "scp", "localhost", 8080, "my-user", "my-password", "a-host|repository*|another-host"
);
+        ProxyInfo proxyInfo = SiteDeployMojo.getProxyInfo( repository, wagonManager );
+        assertNull( "ProxyInfo must be null because 'repository-host' in nonProxyHosts list",
proxyInfo );
+    }
+
+    public void testGetProxyInfoForRepositoryHostWildcardMatchNonProxyHosts2()
+    {
+        wagonManager.addProxy( "scp", "localhost", 8080, "my-user", "my-password", "*host"
);
+        ProxyInfo proxyInfo = SiteDeployMojo.getProxyInfo( repository, wagonManager );
+        assertNull( "ProxyInfo must be null because 'repository-host' in nonProxyHosts list",
proxyInfo );
+    }
+
+    public void testGetProxyInfoForRepositoryHostWildcardMatchNonProxyHosts3()
+    {
+        wagonManager.addProxy( "scp", "localhost", 8080, "my-user", "my-password", "repository*host"
);
+        ProxyInfo proxyInfo = SiteDeployMojo.getProxyInfo( repository, wagonManager );
+        assertNull( "ProxyInfo must be null because 'repository-host' in nonProxyHosts list",
proxyInfo );
+    }
+
+    public void testGetProxyInfoForRepositoryHostWildcardNoMatchNonProxyHosts1()
+    {
+        wagonManager.addProxy( "scp", "localhost", 8080, "my-user", "my-password", "mycompany*"
);
+        ProxyInfo proxyInfo = SiteDeployMojo.getProxyInfo( repository, wagonManager );
+        assertNotNull( "ProxyInfo must be found because 'repository-host' not in nonProxyHosts
list", proxyInfo );
+    }
+
+    public void testGetProxyInfoForRepositoryHostWildcardNoMatchNonProxyHosts2()
+    {
+        wagonManager.addProxy( "scp", "localhost", 8080, "my-user", "my-password", "*mycompany"
);
+        ProxyInfo proxyInfo = SiteDeployMojo.getProxyInfo( repository, wagonManager );
+        assertNotNull( "ProxyInfo must be found because 'repository-host' not in nonProxyHosts
list", proxyInfo );
+    }
+
+    public void testGetProxyInfoForRepositoryHostWildcardNoMatchNonProxyHosts3()
+    {
+        wagonManager.addProxy( "scp", "localhost", 8080, "my-user", "my-password", "repository*mycompany"
);
+        ProxyInfo proxyInfo = SiteDeployMojo.getProxyInfo( repository, wagonManager );
+        assertNotNull( "ProxyInfo must be found because 'repository-host' not in nonProxyHosts
list", proxyInfo );
+    }
+
+    public void testGetProxyInfoForRepositoryHostWildcardNoMatchNonProxyHosts4()
+    {
+        wagonManager.addProxy( "scp", "localhost", 8080, "my-user", "my-password", "mycompany*host"
);
+        ProxyInfo proxyInfo = SiteDeployMojo.getProxyInfo( repository, wagonManager );
+        assertNotNull( "ProxyInfo must be found because 'repository-host' not in nonProxyHosts
list", proxyInfo );
+    }
+
+    public void testGetProxyInfoForRepositoryHostWildcardNoMatchNonProxyHosts5()
+    {
+        wagonManager.addProxy( "scp", "localhost", 8080, "my-user", "my-password", "mycompany*mycompany"
);
+        ProxyInfo proxyInfo = SiteDeployMojo.getProxyInfo( repository, wagonManager );
+        assertNotNull( "ProxyInfo must be found because 'repository-host' not in nonProxyHosts
list", proxyInfo );
+    }
+
+    public void testGetProxyInfoFound()
+    {
+        wagonManager.addProxy( "scp", "localhost", 8080, "my-user", "my-password", "an-host|another-host"
);
+        ProxyInfo proxyInfo = SiteDeployMojo.getProxyInfo( repository, wagonManager );
+        assertNotNull( "ProxyInfo must be found because 'repository-host' not in nonProxyHosts
list", proxyInfo );
+    }
+}

Propchange: maven/plugins/trunk/maven-site-plugin/src/test/java/org/apache/maven/plugins/site/SiteDeployMojoTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: maven/plugins/trunk/maven-site-plugin/src/test/java/org/apache/maven/plugins/site/SiteDeployMojoTest.java
------------------------------------------------------------------------------
    svn:keywords = Date Revision Author Id



Mime
View raw message