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/24 14:33:15 UTC

[maven-site-plugin] 01/02: [MSITE-845] Drop Maven 2 support

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

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

commit 511acd85c62f0f5c25367c0cb73e93597603725e
Author: tibordigana <ti...@apache.org>
AuthorDate: Mon Jul 8 14:20:47 2019 +0200

    [MSITE-845] Drop Maven 2 support
    
    Closes #12
---
 src/it/projects/MSITE-265/pom.xml                  |   2 +-
 src/it/projects/MSITE-265/verify.bsh               |   4 +-
 src/it/projects/MSITE-609/pom.xml                  |   2 +-
 src/it/projects/MSITE-609/verify.bsh               |   4 +-
 src/it/projects/it-plugin-test/pom.xml             |   9 +-
 src/it/projects/new-configuration/pom.xml          |   2 +-
 src/it/projects/site-attach-descriptor/pom.xml     |   2 +-
 src/it/projects/site-deploy/pom.xml                |   2 +-
 src/it/projects/site-deploy/verify.bsh             |   4 +-
 src/it/projects/site-jar/pom.xml                   |   2 +-
 .../maven/plugins/site/AbstractSiteMojo.java       |   9 --
 .../plugins/site/deploy/AbstractDeployMojo.java    | 149 +++------------------
 .../site/render/AbstractSiteRenderingMojo.java     |  45 +++----
 13 files changed, 45 insertions(+), 191 deletions(-)

diff --git a/src/it/projects/MSITE-265/pom.xml b/src/it/projects/MSITE-265/pom.xml
index a4e0965..77dbc89 100644
--- a/src/it/projects/MSITE-265/pom.xml
+++ b/src/it/projects/MSITE-265/pom.xml
@@ -32,7 +32,7 @@ under the License.
   <name>MSITE-265 It</name>
 
   <properties>
-    <currentVersion>2.0.7</currentVersion>
+    <currentVersion>3.0.5</currentVersion>
     <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
   </properties>
 
diff --git a/src/it/projects/MSITE-265/verify.bsh b/src/it/projects/MSITE-265/verify.bsh
index e45d763..e460309 100644
--- a/src/it/projects/MSITE-265/verify.bsh
+++ b/src/it/projects/MSITE-265/verify.bsh
@@ -65,10 +65,10 @@ try
         return false;
     }
     String downloadContent = FileUtils.fileRead( download, "UTF-8" );
-    int indexOf = downloadContent.indexOf( "Download Maven 2.0.7" );
+    int indexOf = downloadContent.indexOf( "Download Maven 3.0.5" );
     if ( indexOf < 0 )
     {
-        System.err.println( "download.html doesn't contain Download Maven 2.0.7" );
+        System.err.println( "download.html doesn't contain Download Maven 3.0.5" );
         return false;
     }
     if ( downloadContent.indexOf( "charset=UTF-8" ) < 0 )
diff --git a/src/it/projects/MSITE-609/pom.xml b/src/it/projects/MSITE-609/pom.xml
index 69ad977..214fcc5 100644
--- a/src/it/projects/MSITE-609/pom.xml
+++ b/src/it/projects/MSITE-609/pom.xml
@@ -32,7 +32,7 @@ under the License.
   <name>MSITE-609 IT</name>
 
   <properties>
-    <currentVersion>2.0.7</currentVersion>
+    <currentVersion>3.0.5</currentVersion>
     <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
   </properties>
 
diff --git a/src/it/projects/MSITE-609/verify.bsh b/src/it/projects/MSITE-609/verify.bsh
index 3488815..0b822a8 100644
--- a/src/it/projects/MSITE-609/verify.bsh
+++ b/src/it/projects/MSITE-609/verify.bsh
@@ -65,10 +65,10 @@ try
         return false;
     }
     String downloadContent = FileUtils.fileRead( download, "UTF-8" );
-    int indexOf = downloadContent.indexOf( "Download Maven 2.0.7" );
+    int indexOf = downloadContent.indexOf( "Download Maven 3.0.5" );
     if ( indexOf < 0 )
     {
-        System.err.println( "download.html doesn't contain Download Maven 2.0.7" );
+        System.err.println( "download.html doesn't contain Download Maven 3.0.5" );
         return false;
     }
 }
diff --git a/src/it/projects/it-plugin-test/pom.xml b/src/it/projects/it-plugin-test/pom.xml
index 68c8b98..550019e 100644
--- a/src/it/projects/it-plugin-test/pom.xml
+++ b/src/it/projects/it-plugin-test/pom.xml
@@ -35,7 +35,7 @@ under the License.
     <dependency>
       <groupId>org.apache.maven</groupId>
       <artifactId>maven-plugin-api</artifactId>
-      <version>2.2.1</version>
+      <version>3.0</version>
     </dependency>
     <dependency>
       <groupId>junit</groupId>
@@ -52,13 +52,6 @@ under the License.
           <groupId>org.apache.maven.plugins</groupId>
           <artifactId>maven-site-plugin</artifactId>
           <version>@project.version@</version>
-          <dependencies><!-- TODO remove when prerequisite is Java 7 -->
-            <dependency>
-              <groupId>org.apache.maven.doxia</groupId>
-              <artifactId>doxia-module-markdown</artifactId>
-              <version>1.7</version>
-            </dependency>
-          </dependencies>
         </plugin>
       </plugins>
     </pluginManagement>
diff --git a/src/it/projects/new-configuration/pom.xml b/src/it/projects/new-configuration/pom.xml
index a37af45..5c552a3 100644
--- a/src/it/projects/new-configuration/pom.xml
+++ b/src/it/projects/new-configuration/pom.xml
@@ -35,7 +35,7 @@ under the License.
     <dependency>
       <groupId>org.apache.maven</groupId>
       <artifactId>maven-plugin-api</artifactId>
-      <version>2.2.1</version>
+      <version>3.0</version>
     </dependency>
     <dependency>
       <groupId>junit</groupId>
diff --git a/src/it/projects/site-attach-descriptor/pom.xml b/src/it/projects/site-attach-descriptor/pom.xml
index b0321f1..db1475c 100644
--- a/src/it/projects/site-attach-descriptor/pom.xml
+++ b/src/it/projects/site-attach-descriptor/pom.xml
@@ -37,7 +37,7 @@ under the License.
   </modules>
 
   <properties>
-    <currentVersion>2.0.7</currentVersion>
+    <currentVersion>3.0.5</currentVersion>
     <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
   </properties>
 
diff --git a/src/it/projects/site-deploy/pom.xml b/src/it/projects/site-deploy/pom.xml
index 874ff53..99255c4 100644
--- a/src/it/projects/site-deploy/pom.xml
+++ b/src/it/projects/site-deploy/pom.xml
@@ -32,7 +32,7 @@ under the License.
   <name>site-deploy IT</name>
 
   <properties>
-    <currentVersion>2.0.7</currentVersion>
+    <currentVersion>3.0.5</currentVersion>
     <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
   </properties>
 
diff --git a/src/it/projects/site-deploy/verify.bsh b/src/it/projects/site-deploy/verify.bsh
index 3488815..0b822a8 100644
--- a/src/it/projects/site-deploy/verify.bsh
+++ b/src/it/projects/site-deploy/verify.bsh
@@ -65,10 +65,10 @@ try
         return false;
     }
     String downloadContent = FileUtils.fileRead( download, "UTF-8" );
-    int indexOf = downloadContent.indexOf( "Download Maven 2.0.7" );
+    int indexOf = downloadContent.indexOf( "Download Maven 3.0.5" );
     if ( indexOf < 0 )
     {
-        System.err.println( "download.html doesn't contain Download Maven 2.0.7" );
+        System.err.println( "download.html doesn't contain Download Maven 3.0.5" );
         return false;
     }
 }
diff --git a/src/it/projects/site-jar/pom.xml b/src/it/projects/site-jar/pom.xml
index d76a8ea..d1fa668 100644
--- a/src/it/projects/site-jar/pom.xml
+++ b/src/it/projects/site-jar/pom.xml
@@ -32,7 +32,7 @@ under the License.
   <name>site-jar IT</name>
 
   <properties>
-    <currentVersion>2.0.7</currentVersion>
+    <currentVersion>3.0.5</currentVersion>
     <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
     <project.build.outputTimestamp>2019-11-02T17:48:12Z</project.build.outputTimestamp>
   </properties>
diff --git a/src/main/java/org/apache/maven/plugins/site/AbstractSiteMojo.java b/src/main/java/org/apache/maven/plugins/site/AbstractSiteMojo.java
index 9886634..b759cfd 100644
--- a/src/main/java/org/apache/maven/plugins/site/AbstractSiteMojo.java
+++ b/src/main/java/org/apache/maven/plugins/site/AbstractSiteMojo.java
@@ -20,7 +20,6 @@ package org.apache.maven.plugins.site;
  */
 
 import org.apache.maven.artifact.repository.ArtifactRepository;
-import org.apache.maven.artifact.versioning.ComparableVersion;
 import org.apache.maven.doxia.tools.SiteTool;
 import org.apache.maven.plugin.AbstractMojo;
 import org.apache.maven.plugins.annotations.Component;
@@ -89,14 +88,6 @@ public abstract class AbstractSiteMojo
     @Parameter( defaultValue = "${reactorProjects}", required = true, readonly = true )
     protected List<MavenProject> reactorProjects;
 
-    /**
-     * Check the current Maven version to see if it's Maven 3.0 or newer.
-     */
-    protected static boolean isMaven3OrMore()
-    {
-        return new ComparableVersion( getMavenVersion() ).compareTo( new ComparableVersion( "3.0" ) ) >= 0;
-    }
-
     protected static String getMavenVersion()
     {
         // This relies on the fact that MavenProject is the in core classloader
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 ac262cd..4e2c5ec 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
@@ -51,7 +51,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.classworlds.ClassRealm;
 import org.codehaus.plexus.PlexusConstants;
 import org.codehaus.plexus.PlexusContainer;
 import org.codehaus.plexus.component.configurator.ComponentConfigurationException;
@@ -67,7 +66,6 @@ import org.codehaus.plexus.util.StringUtils;
 import org.codehaus.plexus.util.xml.Xpp3Dom;
 
 import java.io.File;
-import java.lang.reflect.Method;
 import java.net.MalformedURLException;
 import java.net.URL;
 import java.util.List;
@@ -306,36 +304,10 @@ public abstract class AbstractDeployMojo
         try
         {
             configureWagon( wagon, repository.getId(), settings, container, getLog() );
-        }
-        catch ( TransferFailedException e )
-        {
-            throw new MojoExecutionException( "Unable to configure Wagon: '" + repository.getProtocol() + "'", e );
-        }
 
-        try
-        {
-            final ProxyInfo proxyInfo;
-            if ( !isMaven3OrMore() )
-            {
-                proxyInfo = getProxyInfo( repository, wagonManager );
-            }
-            else
-            {
-                try
-                {
-                    // The cast does not make sense, however I get when compiled with maven 3.5.4:
-                    // error: incompatible types: Object cannot be converted to SettingsDecrypter
-                    // The cast is not necessary with maven 3.3.9
-                    SettingsDecrypter settingsDecrypter =
-                            (SettingsDecrypter) container.lookup( SettingsDecrypter.class );
+            SettingsDecrypter settingsDecrypter = container.lookup( SettingsDecrypter.class );
 
-                    proxyInfo = getProxy( repository, settingsDecrypter );
-                }
-                catch ( ComponentLookupException cle )
-                {
-                    throw new MojoExecutionException( "Unable to lookup SettingsDecrypter: " + cle.getMessage(), cle );
-                }
-            }
+            ProxyInfo proxyInfo = getProxy( repository, settingsDecrypter );
 
             push( directory, repository, wagon, proxyInfo, getLocales(), getDeployModuleDirectory() );
 
@@ -344,6 +316,14 @@ 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 );
+        }
         finally
         {
             try
@@ -496,75 +476,14 @@ public abstract class AbstractDeployMojo
     }
 
     /**
+     * Get proxy information for Maven 3.
      * <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>
-     *
-     * @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 for Maven 3.
      *
-     * @param repository
-     * @param settingsDecrypter
-     * @return
+     * @param repository        the Repository to extract the ProxyInfo from.
+     * @param settingsDecrypter settings password decrypter.
+     * @return a ProxyInfo object instantiated or <code>null</code> if no matching proxy is found.
      */
     private ProxyInfo getProxy( Repository repository, SettingsDecrypter settingsDecrypter )
     {
@@ -593,13 +512,13 @@ public abstract class AbstractDeployMojo
                 {
                     getLog().warn( "fail to build URL with " + url );
                 }
-
             }
         }
         else
         {
             getLog().debug( "getProxy 'protocol': " + protocol );
         }
+
         if ( mavenSession != null && protocol != null )
         {
             MavenExecutionRequest request = mavenSession.getRequest();
@@ -677,15 +596,8 @@ public abstract class AbstractDeployMojo
                 {
                     componentConfigurator =
                         (ComponentConfigurator) container.lookup( ComponentConfigurator.ROLE, "basic" );
-                    if ( isMaven3OrMore() )
-                    {
-                        componentConfigurator.configureComponent( wagon, plexusConf,
-                                                                  container.getContainerRealm() );
-                    }
-                    else
-                    {
-                        configureWagonWithMaven2( componentConfigurator, wagon, plexusConf, container );
-                    }
+
+                    componentConfigurator.configureComponent( wagon, plexusConf, container.getContainerRealm() );
                 }
                 catch ( final ComponentLookupException e )
                 {
@@ -716,33 +628,6 @@ public abstract class AbstractDeployMojo
         }
     }
 
-    private static void configureWagonWithMaven2( ComponentConfigurator componentConfigurator, Wagon wagon,
-                                                  PlexusConfiguration plexusConf, PlexusContainer container )
-        throws ComponentConfigurationException
-    {
-        // in Maven 2.x   :
-        // * container.getContainerRealm() -> org.codehaus.classworlds.ClassRealm
-        // * componentConfiguration 3rd param is org.codehaus.classworlds.ClassRealm
-        // so use some reflection see MSITE-609
-        try
-        {
-            Method methodContainerRealm = container.getClass().getMethod( "getContainerRealm" );
-            ClassRealm realm = (ClassRealm) methodContainerRealm.invoke( container );
-
-            Method methodConfigure = componentConfigurator.getClass().getMethod( "configureComponent",
-                                                                                 new Class[]{ Object.class,
-                                                                                     PlexusConfiguration.class,
-                                                                                     ClassRealm.class } );
-
-            methodConfigure.invoke( componentConfigurator, wagon, plexusConf, realm );
-        }
-        catch ( Exception e )
-        {
-            throw new ComponentConfigurationException(
-                "Failed to configure wagon component for a Maven2 use " + e.getMessage(), e );
-        }
-    }
-
     /**
      * {@inheritDoc}
      */
diff --git a/src/main/java/org/apache/maven/plugins/site/render/AbstractSiteRenderingMojo.java b/src/main/java/org/apache/maven/plugins/site/render/AbstractSiteRenderingMojo.java
index 7336d0f..49c5e47 100644
--- a/src/main/java/org/apache/maven/plugins/site/render/AbstractSiteRenderingMojo.java
+++ b/src/main/java/org/apache/maven/plugins/site/render/AbstractSiteRenderingMojo.java
@@ -230,49 +230,34 @@ public abstract class AbstractSiteRenderingMojo
     protected List<MavenReportExecution> getReports()
         throws MojoExecutionException
     {
-        final List<MavenReportExecution> allReports;
-        if ( isMaven3OrMore() )
+        try
         {
-            // Maven 3
+            MavenReportExecutor mavenReportExecutor = container.lookup( MavenReportExecutor.class );
+
             MavenReportExecutorRequest mavenReportExecutorRequest = new MavenReportExecutorRequest();
             mavenReportExecutorRequest.setLocalRepository( localRepository );
             mavenReportExecutorRequest.setMavenSession( mavenSession );
             mavenReportExecutorRequest.setProject( project );
             mavenReportExecutorRequest.setReportPlugins( getReportingPlugins() );
 
-            MavenReportExecutor mavenReportExecutor;
-            try
-            {
-                mavenReportExecutor = container.lookup( MavenReportExecutor.class );
-            }
-            catch ( ComponentLookupException e )
-            {
-                throw new MojoExecutionException( "could not get MavenReportExecutor component", e );
-            }
+            List<MavenReportExecution> allReports = mavenReportExecutor.buildMavenReports( mavenReportExecutorRequest );
 
-            allReports = mavenReportExecutor.buildMavenReports( mavenReportExecutorRequest );
-        }
-        else
-        {
-            // Maven 2
-            allReports = new ArrayList<>( reports.size() );
-            for ( MavenReport report : reports )
+            // filter out reports that can't be generated
+            // todo Lambda Java 1.8
+            List<MavenReportExecution> reportExecutions = new ArrayList<>( allReports.size() );
+            for ( MavenReportExecution exec : allReports )
             {
-                allReports.add( new MavenReportExecution( report ) );
+                if ( exec.canGenerateReport() )
+                {
+                    reportExecutions.add( exec );
+                }
             }
+            return reportExecutions;
         }
-
-        // filter out reports that can't be generated
-        // todo Lambda Java 1.8
-        List<MavenReportExecution> reportExecutions = new ArrayList<>( allReports.size() );
-        for ( MavenReportExecution exec : allReports )
+        catch ( ComponentLookupException e )
         {
-            if ( exec.canGenerateReport() )
-            {
-                reportExecutions.add( exec );
-            }
+            throw new MojoExecutionException( "could not get MavenReportExecutor component", e );
         }
-        return reportExecutions;
     }
 
     /**