You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@maven.apache.org by el...@apache.org on 2020/05/26 12:49:58 UTC

[maven-site-plugin] branch master updated: [MSITE-757] remove Maven 2 support (#24)

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

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


The following commit(s) were added to refs/heads/master by this push:
     new f37789b  [MSITE-757] remove Maven 2 support (#24)
f37789b is described below

commit f37789b984a0e7ea45a118f24d032c6479b4e4d1
Author: Elliotte Rusty Harold <el...@users.noreply.github.com>
AuthorDate: Tue May 26 08:49:51 2020 -0400

    [MSITE-757] remove Maven 2 support (#24)
    
    remove Maven 2 support
    * remove dependency on classworlds
---
 pom.xml                                            |  6 --
 .../plugins/site/deploy/AbstractDeployMojo.java    | 85 ++++++++++++++++++----
 .../site/render/AbstractSiteRenderingMojo.java     | 15 ++--
 .../site/render/ReportDocumentRenderer.java        | 49 +------------
 4 files changed, 81 insertions(+), 74 deletions(-)

diff --git a/pom.xml b/pom.xml
index 08760d5..af2bae6 100644
--- a/pom.xml
+++ b/pom.xml
@@ -323,12 +323,6 @@ under the License.
       <version>3.3.0</version>
     </dependency>
 
-    <dependency>
-      <groupId>org.codehaus.plexus</groupId>
-      <artifactId>plexus-classworlds</artifactId>
-      <version>2.5.2</version>
-    </dependency>
-
     <!-- Doxia -->
     <dependency>
       <groupId>org.apache.maven.doxia</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 4e2c5ec..59b5f25 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
@@ -171,11 +171,11 @@ public abstract class AbstractDeployMojo
     }
 
     /**
-     * Make sure the given url ends with a slash.
+     * Make sure the given URL ends with a slash.
      *
-     * @param url a String.
-     * @return if url already ends with '/' it is returned unchanged,
-     *         otherwise a '/' character is appended.
+     * @param url a String
+     * @return if url already ends with '/' it is returned unchanged.
+     *         Otherwise a '/' character is appended.
      */
     protected static String appendSlash( final String url )
     {
@@ -476,13 +476,75 @@ public abstract class AbstractDeployMojo
     }
 
     /**
-     * Get proxy information for Maven 3.
+     * 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 settingsDecrypter settings password decrypter.
+     * @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
      * @return a ProxyInfo object instantiated or <code>null</code> if no matching proxy is found.
      */
     private ProxyInfo getProxy( Repository repository, SettingsDecrypter settingsDecrypter )
@@ -565,12 +627,6 @@ public abstract class AbstractDeployMojo
     /**
      * Configure the Wagon with the information from serverConfigurationMap ( which comes from settings.xml )
      *
-     * @param wagon
-     * @param repositoryId
-     * @param settings
-     * @param container
-     * @param log
-     * @throws TransferFailedException
      * @todo Remove when {@link WagonManager#getWagon(Repository) is available}. It's available in Maven 2.0.5.
      */
     private static void configureWagon( Wagon wagon, String repositoryId, Settings settings, PlexusContainer container,
@@ -596,7 +652,6 @@ public abstract class AbstractDeployMojo
                 {
                     componentConfigurator =
                         (ComponentConfigurator) container.lookup( ComponentConfigurator.ROLE, "basic" );
-
                     componentConfigurator.configureComponent( wagon, plexusConf, container.getContainerRealm() );
                 }
                 catch ( final ComponentLookupException e )
@@ -732,7 +787,7 @@ public abstract class AbstractDeployMojo
         private static final String MARK = "-_.!~*'()";
         private static final String RESERVED = ";/?:@&=+$,";
 
-        public static String encodeURI( final String uriString )
+        private static String encodeURI( final String uriString )
         {
             final char[] chars = uriString.toCharArray();
             final StringBuilder uri = new StringBuilder( chars.length );
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 49c5e47..f72154f 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,20 +230,19 @@ public abstract class AbstractSiteRenderingMojo
     protected List<MavenReportExecution> getReports()
         throws MojoExecutionException
     {
+        MavenReportExecutorRequest mavenReportExecutorRequest = new MavenReportExecutorRequest();
+        mavenReportExecutorRequest.setLocalRepository( localRepository );
+        mavenReportExecutorRequest.setMavenSession( mavenSession );
+        mavenReportExecutorRequest.setProject( project );
+        mavenReportExecutorRequest.setReportPlugins( getReportingPlugins() );
+
         try
         {
             MavenReportExecutor mavenReportExecutor = container.lookup( MavenReportExecutor.class );
 
-            MavenReportExecutorRequest mavenReportExecutorRequest = new MavenReportExecutorRequest();
-            mavenReportExecutorRequest.setLocalRepository( localRepository );
-            mavenReportExecutorRequest.setMavenSession( mavenSession );
-            mavenReportExecutorRequest.setProject( project );
-            mavenReportExecutorRequest.setReportPlugins( getReportingPlugins() );
-
             List<MavenReportExecution> allReports = mavenReportExecutor.buildMavenReports( mavenReportExecutorRequest );
 
             // filter out reports that can't be generated
-            // todo Lambda Java 1.8
             List<MavenReportExecution> reportExecutions = new ArrayList<>( allReports.size() );
             for ( MavenReportExecution exec : allReports )
             {
@@ -261,7 +260,7 @@ public abstract class AbstractSiteRenderingMojo
     }
 
     /**
-     * Get the report plugins from reporting section, adding if necessary (ni.e. not excluded)
+     * Get the report plugins from reporting section, adding if necessary (i.e. not excluded)
      * default reports (i.e. maven-project-info-reports)
      *
      * @return the effective list of reports
diff --git a/src/main/java/org/apache/maven/plugins/site/render/ReportDocumentRenderer.java b/src/main/java/org/apache/maven/plugins/site/render/ReportDocumentRenderer.java
index dcf6e07..e59a023 100644
--- a/src/main/java/org/apache/maven/plugins/site/render/ReportDocumentRenderer.java
+++ b/src/main/java/org/apache/maven/plugins/site/render/ReportDocumentRenderer.java
@@ -76,57 +76,16 @@ public class ReportDocumentRenderer
 
         this.renderingContext = renderingContext;
 
-        if ( mavenReportExecution.getPlugin() == null )
-        {
-            // Maven 2: report has been prepared in Maven Core, MavenReportExecution contains only the report
-            this.reportMojoInfo = getPluginInfo( report );
-        }
-        else
-        {
-            // Maven 3: full MavenReportExecution prepared by maven-reporting-impl
-            this.reportMojoInfo =
-                mavenReportExecution.getPlugin().getArtifactId() + ':' + mavenReportExecution.getPlugin().getVersion()
-                    + ':' + mavenReportExecution.getGoal();
-        }
+        // full MavenReportExecution prepared by maven-reporting-impl
+        this.reportMojoInfo =
+            mavenReportExecution.getPlugin().getArtifactId() + ':' + mavenReportExecution.getPlugin().getVersion()
+                + ':' + mavenReportExecution.getGoal();
 
         this.classLoader = mavenReportExecution.getClassLoader();
 
         this.log = log;
     }
 
-    /**
-     * Get plugin information from report's Manifest.
-     *
-     * @param report the Maven report
-     * @return plugin information as Specification Title followed by Specification Version if set in Manifest and
-     *         supported by JVM
-     */
-    private String getPluginInfo( MavenReport report )
-    {
-        Package pkg = report.getClass().getPackage();
-
-        if ( pkg != null )
-        {
-            String title = pkg.getSpecificationTitle();
-            String version = pkg.getSpecificationVersion();
-
-            if ( title == null )
-            {
-                return version;
-            }
-            else if ( version == null )
-            {
-                return title;
-            }
-            else
-            {
-                return title + ' ' + version;
-            }
-        }
-
-        return null;
-    }
-
     private static class MultiPageSubSink
         extends SiteRendererSink
     {