You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@maven.apache.org by hb...@apache.org on 2019/03/11 18:25:03 UTC

[maven-help-plugin] branch MPH-160 updated (d523875 -> ddc9eb0)

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

hboutemy pushed a change to branch MPH-160
in repository https://gitbox.apache.org/repos/asf/maven-help-plugin.git.


 discard d523875  [MPH-160] use Maven-provided xpp3-extended-writer when available
     new ddc9eb0  [MPH-160] use Maven-provided xpp3-extended-writer when available

This update added new revisions after undoing existing revisions.
That is to say, some revisions that were in the old version of the
branch are not in the new version.  This situation occurs
when a user --force pushes a change and generates a repository
containing something like this:

 * -- * -- B -- O -- O -- O   (d523875)
            \
             N -- N -- N   refs/heads/MPH-160 (ddc9eb0)

You should already have received notification emails for all of the O
revisions, and so the following emails describe only the N revisions
from the common base, B.

Any revisions marked "omit" are not gone; other references still
refer to them.  Any revisions marked "discard" are gone forever.

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.


Summary of changes:
 src/main/java/org/apache/maven/plugins/help/EvaluateMojo.java | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)


[maven-help-plugin] 01/01: [MPH-160] use Maven-provided xpp3-extended-writer when available

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

hboutemy pushed a commit to branch MPH-160
in repository https://gitbox.apache.org/repos/asf/maven-help-plugin.git

commit ddc9eb0d55cf38bca96808cf466ada42ec11ca72
Author: Hervé Boutemy <hb...@apache.org>
AuthorDate: Sat Feb 23 22:36:13 2019 +0100

    [MPH-160] use Maven-provided xpp3-extended-writer when available
    
    and use refactored InputLocation toString() customization using
    InputLocation.StringFormatter abstract class
---
 pom.xml                                            |   2 +-
 .../maven/plugins/help/EffectivePomMojo.java       | 124 ++++++++++++++++++---
 .../apache/maven/plugins/help/EvaluateMojo.java    |   2 +-
 3 files changed, 112 insertions(+), 16 deletions(-)

diff --git a/pom.xml b/pom.xml
index 017e8a2..485e5b3 100644
--- a/pom.xml
+++ b/pom.xml
@@ -87,7 +87,7 @@
     <dependency>
       <groupId>org.apache.maven</groupId>
       <artifactId>maven-model</artifactId>
-      <version>${mavenVersion}</version>
+      <version>3.6.1-SNAPSHOT</version>
     </dependency>
     <dependency>
       <groupId>org.apache.maven</groupId>
diff --git a/src/main/java/org/apache/maven/plugins/help/EffectivePomMojo.java b/src/main/java/org/apache/maven/plugins/help/EffectivePomMojo.java
index ae9a455..10c383c 100644
--- a/src/main/java/org/apache/maven/plugins/help/EffectivePomMojo.java
+++ b/src/main/java/org/apache/maven/plugins/help/EffectivePomMojo.java
@@ -21,6 +21,9 @@ package org.apache.maven.plugins.help;
 
 import java.io.IOException;
 import java.io.StringWriter;
+import java.io.Writer;
+import java.lang.reflect.InvocationTargetException;
+import java.lang.reflect.Method;
 import java.util.List;
 import java.util.Properties;
 
@@ -40,6 +43,8 @@ import org.codehaus.plexus.util.StringUtils;
 import org.codehaus.plexus.util.xml.PrettyPrintXMLWriter;
 import org.codehaus.plexus.util.xml.XMLWriter;
 import org.codehaus.plexus.util.xml.XmlWriterUtil;
+import org.codehaus.plexus.util.xml.Xpp3Dom;
+import org.codehaus.plexus.util.xml.pull.XmlSerializer;
 
 /**
  * Displays the effective POM as an XML for this build, with the active profiles factored in, or a specified artifact.
@@ -212,9 +217,12 @@ public class EffectivePomMojo
         {
             if ( verbose )
             {
-                // use local xpp3 extended writer when not provided by Maven core
-                new EffectiveWriterExOldSupport().write( sWriter, pom );
-                // TODO detect Maven core-provided xpp3 extended writer and use it instead
+                // try to use Maven core-provided xpp3 extended writer (available since Maven 3.6.1)
+                if ( ! writeMavenXpp3WriterEx( sWriter, pom ) )
+                {
+                    // xpp3 extended writer not provided by Maven core, use local code
+                    new EffectiveWriterExOldSupport().write( sWriter, pom );
+                }
             }
             else
             {
@@ -246,26 +254,114 @@ public class EffectivePomMojo
         pom.setProperties( properties );
     }
 
+    private void warnWriteMavenXpp3WriterEx( Throwable t )
+    {
+        getLog().warn( "Unexpected exception while running Maven Model Extended Writer, "
+            + "falling back to old internal implementation.", t );
+    }
+
+    private boolean writeMavenXpp3WriterEx( Writer writer, Model model )
+        throws IOException
+    {
+        try
+        {
+            Class<?> mavenXpp3WriterExClass = Class.forName( "org.apache.maven.model.io.xpp3.MavenXpp3WriterEx" );
+            Object mavenXpp3WriterEx = mavenXpp3WriterExClass.newInstance();
+
+            Method setStringFormatter =
+                mavenXpp3WriterExClass.getMethod( "setStringFormatter", InputLocation.StringFormatter.class );
+            setStringFormatter.invoke( mavenXpp3WriterEx, new InputLocationStringFormatter() );
+
+            Method write = mavenXpp3WriterExClass.getMethod( "write", Writer.class, Model.class );
+            write.invoke( mavenXpp3WriterEx, writer, model );
+
+            return true;
+        }
+        catch ( ClassNotFoundException e )
+        {
+            // MavenXpp3WriterEx not available in running Maven version
+        }
+        catch ( NoSuchMethodException e )
+        {
+            warnWriteMavenXpp3WriterEx( e );
+        }
+        catch ( SecurityException e )
+        {
+            warnWriteMavenXpp3WriterEx( e );
+        }
+        catch ( InstantiationException e )
+        {
+            warnWriteMavenXpp3WriterEx( e );
+        }
+        catch ( IllegalAccessException e )
+        {
+            warnWriteMavenXpp3WriterEx( e );
+        }
+        catch ( IllegalArgumentException e )
+        {
+            warnWriteMavenXpp3WriterEx( e );
+        }
+        catch ( InvocationTargetException e )
+        {
+            if ( e.getTargetException() instanceof IOException )
+            {
+                throw (IOException) e.getTargetException();
+            }
+            else if ( e.getTargetException() instanceof RuntimeException )
+            {
+                throw (RuntimeException) e.getTargetException();
+            }
+            warnWriteMavenXpp3WriterEx( e );
+        }
+        return false;
+    }
+
+    private static String toString( InputLocation location )
+    {
+        InputSource source = location.getSource();
+
+        String s = source.getModelId(); // by default, display modelId
+
+        if ( StringUtils.isBlank( s ) || s.contains( "[unknown-version]" ) )
+        {
+            // unless it is blank or does not provide version information
+            s = source.toString();
+        }
+
+        return '}' + s + ( ( location.getLineNumber() >= 0 ) ? ", line " + location.getLineNumber() : "" ) + ' ';
+    }
+
+    private static class InputLocationStringFormatter
+        extends InputLocation.StringFormatter
+    {
+
+        public String toString( InputLocation location )
+        {
+            return EffectivePomMojo.toString( location );
+        }
+
+    }
+
     /**
      * Xpp3 extended writer extension to improve default InputSource display
      */
     private static class EffectiveWriterExOldSupport
         extends MavenXpp3WriterExOldSupport
     {
+
         @Override
-        protected String toString( InputLocation location )
+        public String toString( InputLocation location )
         {
-            InputSource source = location.getSource();
-
-            String s = source.getModelId(); // by default, display modelId
-
-            if ( StringUtils.isBlank( s ) || s.contains( "[unknown-version]" ) )
-            {
-                // unless it is blank or does not provide version information
-                s = source.toString();
-            }
+            return EffectivePomMojo.toString( location );
+        }
 
-            return '}' + s + ( ( location.getLineNumber() >= 0 ) ? ", line " + location.getLineNumber() : "" ) + ' ';
+        @Override
+        protected void writeXpp3DomToSerializer( Xpp3Dom dom, XmlSerializer serializer )
+            throws java.io.IOException
+        {
+            // default method uses Xpp3Dom input location tracking, not available in older Maven versions
+            // use old Xpp3Dom serialization, without input location tracking
+            dom.writeToSerializer( null, serializer );
         }
     }
 }
diff --git a/src/main/java/org/apache/maven/plugins/help/EvaluateMojo.java b/src/main/java/org/apache/maven/plugins/help/EvaluateMojo.java
index 6df5570..758973e 100644
--- a/src/main/java/org/apache/maven/plugins/help/EvaluateMojo.java
+++ b/src/main/java/org/apache/maven/plugins/help/EvaluateMojo.java
@@ -535,7 +535,7 @@ public class EvaluateMojo
                     String name = jarEntry.getName().substring( 0, jarEntry.getName().indexOf( "." ) );
                     name = name.replaceAll( "/", "\\." );
 
-                    if ( name.contains( packageFilter ) )
+                    if ( name.contains( packageFilter ) && !name.contains( "$" ) )
                     {
                         try
                         {