You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@maven.apache.org by sl...@apache.org on 2020/05/27 08:36:51 UTC

[maven-site-plugin] branch MSITE-833 created (now 3a3eb6c)

This is an automated email from the ASF dual-hosted git repository.

slachiewicz pushed a change to branch MSITE-833
in repository https://gitbox.apache.org/repos/asf/maven-site-plugin.git.


      at 3a3eb6c  [MSITE-833] Remove dependency to maven-compat

This branch includes the following new commits:

     new 3a3eb6c  [MSITE-833] Remove dependency to maven-compat

The 1 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.



[maven-site-plugin] 01/01: [MSITE-833] Remove dependency to maven-compat

Posted by sl...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

slachiewicz pushed a commit to branch MSITE-833
in repository https://gitbox.apache.org/repos/asf/maven-site-plugin.git

commit 3a3eb6cd9a7d051afd90b59eac6b057857005ba9
Author: Sylwester Lachiewicz <sl...@apache.org>
AuthorDate: Wed May 27 10:36:33 2020 +0200

    [MSITE-833] Remove dependency to maven-compat
---
 pom.xml                                            |   2 +-
 .../plugins/site/deploy/AbstractDeployMojo.java    | 186 ++++++---------------
 .../site/deploy/AbstractSiteDeployWebDavTest.java  |   7 +-
 .../plugins/site/deploy/SiteDeployMojoTest.java    |   7 +-
 4 files changed, 58 insertions(+), 144 deletions(-)

diff --git a/pom.xml b/pom.xml
index 1f6c845..aa883d8 100644
--- a/pom.xml
+++ b/pom.xml
@@ -240,7 +240,7 @@ under the License.
       <groupId>org.apache.maven</groupId>
       <artifactId>maven-compat</artifactId>
       <version>${mavenVersion}</version>
-      <scope>provided</scope>
+      <scope>test</scope>
     </dependency>
     <dependency>
       <groupId>org.apache.maven</groupId>
diff --git a/src/main/java/org/apache/maven/plugins/site/deploy/AbstractDeployMojo.java b/src/main/java/org/apache/maven/plugins/site/deploy/AbstractDeployMojo.java
index 415e59e..0629002 100644
--- a/src/main/java/org/apache/maven/plugins/site/deploy/AbstractDeployMojo.java
+++ b/src/main/java/org/apache/maven/plugins/site/deploy/AbstractDeployMojo.java
@@ -19,7 +19,6 @@ package org.apache.maven.plugins.site.deploy;
  * under the License.
  */
 
-import org.apache.maven.artifact.manager.WagonManager;
 import org.apache.maven.doxia.site.decoration.inheritance.URIPathDescriptor;
 import org.apache.maven.execution.MavenExecutionRequest;
 import org.apache.maven.execution.MavenSession;
@@ -42,7 +41,6 @@ import org.apache.maven.wagon.CommandExecutor;
 import org.apache.maven.wagon.ConnectionException;
 import org.apache.maven.wagon.ResourceDoesNotExistException;
 import org.apache.maven.wagon.TransferFailedException;
-import org.apache.maven.wagon.UnsupportedProtocolException;
 import org.apache.maven.wagon.Wagon;
 import org.apache.maven.wagon.authentication.AuthenticationException;
 import org.apache.maven.wagon.authentication.AuthenticationInfo;
@@ -50,7 +48,6 @@ import org.apache.maven.wagon.authorization.AuthorizationException;
 import org.apache.maven.wagon.observers.Debug;
 import org.apache.maven.wagon.proxy.ProxyInfo;
 import org.apache.maven.wagon.repository.Repository;
-import org.codehaus.plexus.PlexusConstants;
 import org.codehaus.plexus.PlexusContainer;
 import org.codehaus.plexus.component.configurator.ComponentConfigurationException;
 import org.codehaus.plexus.component.configurator.ComponentConfigurator;
@@ -58,9 +55,6 @@ import org.codehaus.plexus.component.repository.exception.ComponentLifecycleExce
 import org.codehaus.plexus.component.repository.exception.ComponentLookupException;
 import org.codehaus.plexus.configuration.PlexusConfiguration;
 import org.codehaus.plexus.configuration.xml.XmlPlexusConfiguration;
-import org.codehaus.plexus.context.Context;
-import org.codehaus.plexus.context.ContextException;
-import org.codehaus.plexus.personality.plexus.lifecycle.phase.Contextualizable;
 import org.codehaus.plexus.util.StringUtils;
 import org.codehaus.plexus.util.xml.Xpp3Dom;
 
@@ -69,7 +63,8 @@ import java.net.MalformedURLException;
 import java.net.URL;
 import java.util.List;
 import java.util.Locale;
-import java.util.Set;
+
+import static java.util.Locale.*;
 
 /**
  * Abstract base class for deploy mojos.
@@ -80,7 +75,6 @@ import java.util.Set;
  */
 public abstract class AbstractDeployMojo
     extends AbstractSiteMojo
-    implements Contextualizable
 {
     /**
      * Directory containing the generated project sites and report distributions.
@@ -126,11 +120,6 @@ public abstract class AbstractDeployMojo
     private boolean skipDeploy;
 
     /**
-     */
-    @Component
-    private WagonManager wagonManager; // maven-compat
-
-    /**
      * The current user system settings for use in Maven.
      */
     @Parameter( defaultValue = "${settings}", readonly = true )
@@ -146,8 +135,13 @@ public abstract class AbstractDeployMojo
 
     private Site deploySite;
 
+    @Component
     private PlexusContainer container;
 
+    @Component
+    SettingsDecrypter settingsDecrypter;
+
+
     /**
      * {@inheritDoc}
      */
@@ -298,14 +292,12 @@ public abstract class AbstractDeployMojo
         throws MojoExecutionException
     {
         // TODO: work on moving this into the deployer like the other deploy methods
-        final Wagon wagon = getWagon( repository, wagonManager );
+        final Wagon wagon = getWagon( repository );
 
         try
         {
             configureWagon( wagon, repository.getId(), settings, container, getLog() );
 
-            SettingsDecrypter settingsDecrypter = container.lookup( SettingsDecrypter.class );
-
             ProxyInfo proxyInfo = getProxy( repository, settingsDecrypter );
 
             push( directory, repository, wagon, proxyInfo, getLocales(), getDeployModuleDirectory() );
@@ -315,10 +307,6 @@ public abstract class AbstractDeployMojo
                 chmod( wagon, repository, chmodOptions, chmodMode );
             }
         }
-        catch ( ComponentLookupException cle )
-        {
-            throw new MojoExecutionException( "Unable to lookup SettingsDecrypter: " + cle.getMessage(), cle );
-        }
         catch ( TransferFailedException e )
         {
             throw new MojoExecutionException( "Unable to configure Wagon: '" + repository.getProtocol() + "'", e );
@@ -336,63 +324,67 @@ public abstract class AbstractDeployMojo
         }
     }
 
-    private Wagon getWagon( final Repository repository, final WagonManager manager )
+    private Wagon getWagon( final Repository repository )
         throws MojoExecutionException
     {
-        final Wagon wagon;
-
-        try
+        String protocol = repository.getProtocol();
+        if ( protocol == null )
         {
-            wagon = manager.getWagon( repository );
+            throw new MojoExecutionException( "Unspecified protocol" );
         }
-        catch ( UnsupportedProtocolException e )
-        {
-            String shortMessage = "Unsupported protocol: '" + repository.getProtocol() + "' for site deployment to "
-                + "distributionManagement.site.url=" + repository.getUrl() + ".";
-            String longMessage =
-                "\n" + shortMessage + "\n" + "Currently supported protocols are: " + getSupportedProtocols() + ".\n"
-                    + "    Protocols may be added through wagon providers.\n" + "    For more information, see "
-                    + "https://maven.apache.org/plugins/maven-site-plugin/examples/adding-deploy-protocol.html";
-
-            getLog().error( longMessage );
-
-            throw new MojoExecutionException( shortMessage );
-        }
-        catch ( TransferFailedException e )
+        try
         {
-            throw new MojoExecutionException( "Unable to configure Wagon: '" + repository.getProtocol() + "'", e );
-        }
-
-        if ( !wagon.supportsDirectoryCopy() )
+            Wagon wagon = container.lookup( Wagon.class, protocol.toLowerCase( ENGLISH ) );
+            if ( !wagon.supportsDirectoryCopy() )
+            {
+                throw new MojoExecutionException(
+                        "Wagon protocol '" + repository.getProtocol() + "' doesn't support directory copying" );
+            }
+            return wagon;
+       }
+        catch ( ComponentLookupException e )
         {
-            throw new MojoExecutionException(
-                "Wagon protocol '" + repository.getProtocol() + "' doesn't support directory copying" );
+            throw new MojoExecutionException( "Cannot find wagon which supports the requested protocol: "
+                    + protocol, e );
         }
-
-        return wagon;
     }
 
-    private String getSupportedProtocols()
+    public AuthenticationInfo getAuthenticationInfo( String id )
     {
-        try
+        if ( id != null )
         {
-            Set<String> protocols = container.lookupMap( Wagon.class ).keySet();
+                List<Server> servers = settings.getServers();
 
-            return StringUtils.join( protocols.iterator(), ", " );
-        }
-        catch ( ComponentLookupException e )
-        {
-            // in the unexpected case there is a problem when instantiating a wagon provider
-            getLog().error( e );
+                if ( servers != null )
+                {
+                    for ( Server server : servers )
+                    {
+                        if ( id.equalsIgnoreCase( server.getId() ) )
+                        {
+                            SettingsDecryptionResult result = settingsDecrypter.decrypt( new DefaultSettingsDecryptionRequest( server ) );
+                            server = result.getServer();
+
+                            AuthenticationInfo authInfo = new AuthenticationInfo();
+                            authInfo.setUserName( server.getUsername() );
+                            authInfo.setPassword( server.getPassword() );
+                            authInfo.setPrivateKey( server.getPrivateKey() );
+                            authInfo.setPassphrase( server.getPassphrase() );
+
+                            return authInfo;
+                        }
+                    }
+            }
         }
-        return "";
+
+        // empty one to prevent NPE
+        return new AuthenticationInfo();
     }
 
     private void push( final File inputDirectory, final Repository repository, final Wagon wagon,
                        final ProxyInfo proxyInfo, final List<Locale> localesList, final String relativeDir )
         throws MojoExecutionException
     {
-        AuthenticationInfo authenticationInfo = wagonManager.getAuthenticationInfo( repository.getId() );
+        AuthenticationInfo authenticationInfo = getAuthenticationInfo( repository.getId() );
         getLog().debug( "authenticationInfo with id '" + repository.getId() + "': "
                             + ( ( authenticationInfo == null ) ? "-" : authenticationInfo.getUserName() ) );
 
@@ -412,7 +404,7 @@ public abstract class AbstractDeployMojo
                 getLog().debug( "connect with proxyInfo" );
                 wagon.connect( repository, authenticationInfo, proxyInfo );
             }
-            else if ( proxyInfo == null && authenticationInfo != null )
+            else if ( authenticationInfo != null )
             {
                 getLog().debug( "connect with authenticationInfo and without proxyInfo" );
                 wagon.connect( repository, authenticationInfo );
@@ -476,71 +468,6 @@ public abstract class AbstractDeployMojo
 
     /**
      * Get proxy information.
-     * <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="https://docs.oracle.com/javase/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 comma (",") and semi colon (";") in addition to pipe ("|") as separator.
-     * </p>
-     *
-     * @param repository   the Repository to extract the ProxyInfo from
-     * @param wagonManager the WagonManager used to connect to the Repository
-     * @return a ProxyInfo object instantiated or <code>null</code> if no matching proxy is found
-     */
-    public static ProxyInfo getProxyInfo( Repository repository, WagonManager wagonManager )
-    {
-        ProxyInfo proxyInfo = wagonManager.getProxy( repository.getProtocol() );
-
-        if ( proxyInfo == null )
-        {
-            return null;
-        }
-
-        String host = repository.getHost();
-        String nonProxyHostsAsString = proxyInfo.getNonProxyHosts();
-        for ( String nonProxyHost : StringUtils.split( nonProxyHostsAsString, ",;|" ) )
-        {
-            if ( StringUtils.contains( nonProxyHost, "*" ) )
-            {
-                // Handle wildcard at the end, beginning or middle of the nonProxyHost
-                final int pos = nonProxyHost.indexOf( '*' );
-                String nonProxyHostPrefix = nonProxyHost.substring( 0, pos );
-                String nonProxyHostSuffix = nonProxyHost.substring( pos + 1 );
-                // 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;
-    }
-
-    /**
-     * Get proxy information.
      *
      * @param repository        the Repository to extract the ProxyInfo from
      * @param settingsDecrypter settings password decrypter
@@ -626,7 +553,7 @@ public abstract class AbstractDeployMojo
     /**
      * Configure the Wagon with the information from serverConfigurationMap ( which comes from settings.xml )
      *
-     * @todo Remove when {@link WagonManager#getWagon(Repository) is available}. It's available in Maven 2.0.5.
+     * @todo Remove when {@link WagonManager#getWagon(String) is available}. It's available in Maven 2.0.5.
      */
     private static void configureWagon( Wagon wagon, String repositoryId, Settings settings, PlexusContainer container,
                                         Log log )
@@ -683,15 +610,6 @@ public abstract class AbstractDeployMojo
     }
 
     /**
-     * {@inheritDoc}
-     */
-    public void contextualize( Context context )
-        throws ContextException
-    {
-        container = (PlexusContainer) context.get( PlexusConstants.PLEXUS_KEY );
-    }
-
-    /**
      * Extract the distributionManagement site from the given MavenProject.
      *
      * @param project the MavenProject. Not null.
diff --git a/src/test/java/org/apache/maven/plugins/site/deploy/AbstractSiteDeployWebDavTest.java b/src/test/java/org/apache/maven/plugins/site/deploy/AbstractSiteDeployWebDavTest.java
index 1af75b1..61333b6 100644
--- a/src/test/java/org/apache/maven/plugins/site/deploy/AbstractSiteDeployWebDavTest.java
+++ b/src/test/java/org/apache/maven/plugins/site/deploy/AbstractSiteDeployWebDavTest.java
@@ -27,7 +27,7 @@ import java.util.List;
 import java.util.Map;
 
 import org.apache.commons.io.FileUtils;
-import org.apache.maven.artifact.repository.ArtifactRepositoryFactory;
+import org.apache.maven.artifact.repository.MavenArtifactRepository;
 import org.apache.maven.doxia.tools.SiteTool;
 import org.apache.maven.execution.DefaultMavenExecutionRequest;
 import org.apache.maven.execution.MavenExecutionRequest;
@@ -226,13 +226,10 @@ public abstract class AbstractSiteDeployWebDavTest
             }
             else
             {
-                ArtifactRepositoryFactory artifactRepositoryFactory = getContainer().lookup( ArtifactRepositoryFactory.class );
-
                 setVariableValueToObject( mojo, "stagingDirectory", inputDirectory );
                 setVariableValueToObject( mojo, "reactorProjects", Collections.emptyList() );
                 setVariableValueToObject( mojo, "localRepository",
-                                          artifactRepositoryFactory.createArtifactRepository( "local", "foo", "default",
-                                                                                              null, null ) );
+                        new MavenArtifactRepository("local", "foo", null, null, null) );
                 setVariableValueToObject( mojo, "siteTool", getContainer().lookup( SiteTool.class ) );
                 setVariableValueToObject( mojo, "siteDirectory", new File("foo") );
                 setVariableValueToObject( mojo, "repositories", Collections.emptyList() );
diff --git a/src/test/java/org/apache/maven/plugins/site/deploy/SiteDeployMojoTest.java b/src/test/java/org/apache/maven/plugins/site/deploy/SiteDeployMojoTest.java
index 59f41b4..623ec3b 100644
--- a/src/test/java/org/apache/maven/plugins/site/deploy/SiteDeployMojoTest.java
+++ b/src/test/java/org/apache/maven/plugins/site/deploy/SiteDeployMojoTest.java
@@ -19,8 +19,7 @@ package org.apache.maven.plugins.site.deploy;
  * under the License.
  */
 
-import org.apache.maven.artifact.manager.WagonManager;
-//import org.apache.maven.wagon.repository.Repository;
+import org.apache.maven.wagon.Wagon;
 import org.codehaus.plexus.PlexusTestCase;
 import org.junit.Before;
 import org.junit.Test;
@@ -34,7 +33,7 @@ import org.junit.runners.JUnit4;
 public class SiteDeployMojoTest
     extends PlexusTestCase
 {
-    private WagonManager wagonManager;
+    private Wagon wagon;
 
     //private Repository repository;
 
@@ -43,7 +42,7 @@ public class SiteDeployMojoTest
         throws Exception
     {
         super.setUp();
-        wagonManager = getContainer().lookup( WagonManager.class );
+        // wagon = getContainer().lookup( Wagon.class, "scp" );
         //repository = new Repository( "my-repository", "scp://repository-host/var/maven2" );
     }