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/09 22:04:20 UTC

[maven-help-plugin] branch MPH-160 updated (2574ac4 -> 0e2d19e)

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 2574ac4  [MPH-160] use Maven-provided xpp3-extended-writer when available
 discard dafd6ac  [MPH-160] display line number only if meaningful
 discard 9d041fd  [MPH-160] add color for comments
 discard 8d1af38  [MPH-160] update plexus-utils and Modello for XPP3 DOM tracking
 discard 67b0465  [MPH-160] add "verbose" to effective-pom to display POM input location
     new 8502f1b  [MPH-160] add "verbose" to effective-pom to display POM input location
     new fe17779  [MPH-160] add color for comments
     new 9da7ef0  [MPH-160] update plexus-utils and Modello for XPP3 DOM tracking
     new 0e2d19e  [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   (2574ac4)
            \
             N -- N -- N   refs/heads/MPH-160 (0e2d19e)

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 4 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:


[maven-help-plugin] 01/04: [MPH-160] add "verbose" to effective-pom to display POM input location

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 8502f1b9c1824c7ce890a560a38365e97e59bf2d
Author: Hervé Boutemy <hb...@apache.org>
AuthorDate: Fri Feb 15 12:33:01 2019 +0100

    [MPH-160] add "verbose" to effective-pom to display POM input location
---
 pom.xml                                            | 45 ++++++++++++++++++
 src/it/effective-pom-verbose/invoker.properties    | 18 ++++++++
 src/it/effective-pom-verbose/pom.xml               | 37 +++++++++++++++
 .../maven/plugins/help/EffectivePomMojo.java       | 53 ++++++++++++++++++++--
 4 files changed, 150 insertions(+), 3 deletions(-)

diff --git a/pom.xml b/pom.xml
index 3316d04..c8bead1 100644
--- a/pom.xml
+++ b/pom.xml
@@ -277,6 +277,51 @@
           </execution>
         </executions>
       </plugin>
+      <!-- unpack old Maven core sources for maven.mdo model to be able to generate xpp3-extended-writer when not yet provided by Maven core -->
+      <plugin>
+        <groupId>org.apache.maven.plugins</groupId>
+        <artifactId>maven-dependency-plugin</artifactId>
+        <executions>
+          <execution>
+            <phase>generate-sources</phase>
+            <goals>
+              <goal>unpack</goal>
+            </goals>
+            <configuration>
+              <artifactItems>
+                <artifactItem>
+                  <groupId>org.apache.maven</groupId>
+                  <artifactId>apache-maven</artifactId>
+                  <version>${mavenVersion}</version>
+                  <type>tar.gz</type>
+                  <classifier>src</classifier>
+                  <outputDirectory>${project.build.directory}</outputDirectory>
+                </artifactItem>
+              </artifactItems>
+            </configuration>
+          </execution>
+        </executions>
+      </plugin>
+      <plugin>
+        <groupId>org.codehaus.modello</groupId>
+        <artifactId>modello-maven-plugin</artifactId>
+        <version>1.9.2-SNAPSHOT</version>
+        <configuration>
+          <version>4.0.0</version>
+          <models>
+            <model>target/apache-maven-${mavenVersion}/maven-model/src/main/mdo/maven.mdo</model>
+          </models>
+          <extendedClassnameSuffix>ExOldSupport</extendedClassnameSuffix><!-- to avoid conflict with class provided by Maven core -->
+        </configuration>
+        <executions>
+          <execution>
+            <id>modello</id>
+            <goals>
+              <goal>xpp3-extended-writer</goal>
+            </goals>
+          </execution>
+        </executions>
+      </plugin>
     </plugins>
   </build>
 </project>
diff --git a/src/it/effective-pom-verbose/invoker.properties b/src/it/effective-pom-verbose/invoker.properties
new file mode 100644
index 0000000..fd3f2fe
--- /dev/null
+++ b/src/it/effective-pom-verbose/invoker.properties
@@ -0,0 +1,18 @@
+# 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.
+
+invoker.goals = ${project.groupId}:${project.artifactId}:${project.version}:effective-pom -Dverbose
diff --git a/src/it/effective-pom-verbose/pom.xml b/src/it/effective-pom-verbose/pom.xml
new file mode 100644
index 0000000..2138bfe
--- /dev/null
+++ b/src/it/effective-pom-verbose/pom.xml
@@ -0,0 +1,37 @@
+<?xml version="1.0" encoding="UTF-8"?>
+
+<!--
+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.
+-->
+
+<project>
+  <modelVersion>4.0.0</modelVersion>
+  <parent>
+    <artifactId>maven-plugins</artifactId>
+    <groupId>org.apache.maven.plugins</groupId>
+    <version>33</version>
+  </parent>
+
+  <groupId>org.apache.maven.its.help</groupId>
+  <artifactId>test</artifactId>
+  <version>1.0-SNAPSHOT</version>
+
+  <description>
+  </description>
+
+</project>
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 63c9d27..cd481ca 100644
--- a/src/main/java/org/apache/maven/plugins/help/EffectivePomMojo.java
+++ b/src/main/java/org/apache/maven/plugins/help/EffectivePomMojo.java
@@ -24,8 +24,11 @@ import java.io.StringWriter;
 import java.util.List;
 import java.util.Properties;
 
+import org.apache.maven.model.InputLocation;
 import org.apache.maven.model.Model;
+import org.apache.maven.model.InputSource;
 import org.apache.maven.model.io.xpp3.MavenXpp3Writer;
+import org.apache.maven.model.io.xpp3.MavenXpp3WriterExOldSupport;
 import org.apache.maven.plugin.MojoExecution;
 import org.apache.maven.plugin.MojoExecution.Source;
 import org.apache.maven.plugin.MojoExecutionException;
@@ -82,6 +85,14 @@ public class EffectivePomMojo
     @Parameter( property = "artifact" )
     private String artifact;
 
+    /**
+     * Output POM input location as comments.
+     * 
+     * @since 3.2.0
+     */
+    @Parameter( property = "verbose", defaultValue = "false" )
+    private boolean verbose = false;
+
     // ----------------------------------------------------------------------
     // Public methods
     // ----------------------------------------------------------------------
@@ -120,6 +131,11 @@ public class EffectivePomMojo
         }
 
         String effectivePom = prettyFormat( w.toString(), encoding, false );
+        if ( verbose )
+        {
+            // tweak location tracking comment, that are put on a separate line by pretty print
+            effectivePom = effectivePom.replaceAll( "(?m)>\\s+<!--}", ">  <!-- " );
+        }
 
         if ( output != null )
         {
@@ -174,17 +190,25 @@ public class EffectivePomMojo
      * @param writer the XML writer , not null, not null.
      * @throws MojoExecutionException if any
      */
-    private static void writeEffectivePom( MavenProject project, XMLWriter writer )
+    private void writeEffectivePom( MavenProject project, XMLWriter writer )
         throws MojoExecutionException
     {
         Model pom = project.getModel();
         cleanModel( pom );
 
         StringWriter sWriter = new StringWriter();
-        MavenXpp3Writer pomWriter = new MavenXpp3Writer();
         try
         {
-            pomWriter.write( sWriter, pom );
+            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
+            }
+            else
+            {
+                new MavenXpp3Writer().write( sWriter, pom );
+            }
         }
         catch ( IOException e )
         {
@@ -210,4 +234,27 @@ public class EffectivePomMojo
         properties.putAll( pom.getProperties() );
         pom.setProperties( properties );
     }
+
+    /**
+     * Xpp3 extended writer extension to improve default InputSource display
+     */
+    private static class EffectiveWriterExOldSupport
+        extends MavenXpp3WriterExOldSupport
+    {
+        @Override
+        protected 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() : "" ) + ' ';
+        }
+    }
 }


[maven-help-plugin] 03/04: [MPH-160] update plexus-utils and Modello for XPP3 DOM tracking

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 9da7ef0db1b486e735fef1359aced4da27c04ada
Author: Hervé Boutemy <hb...@apache.org>
AuthorDate: Thu Feb 21 23:45:45 2019 +0100

    [MPH-160] update plexus-utils and Modello for XPP3 DOM tracking
---
 pom.xml | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/pom.xml b/pom.xml
index 7e7fc49..215a592 100644
--- a/pom.xml
+++ b/pom.xml
@@ -180,7 +180,7 @@
     <dependency>
       <groupId>org.codehaus.plexus</groupId>
       <artifactId>plexus-utils</artifactId>
-      <version>3.1.0</version>
+      <version>3.2.0-SNAPSHOT</version>
     </dependency>
 
     <!-- misc -->
@@ -310,7 +310,7 @@
       <plugin>
         <groupId>org.codehaus.modello</groupId>
         <artifactId>modello-maven-plugin</artifactId>
-        <version>1.9.2-SNAPSHOT</version>
+        <version>1.10.0-SNAPSHOT</version>
         <configuration>
           <version>4.0.0</version>
           <models>


[maven-help-plugin] 02/04: [MPH-160] add color for comments

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 fe1777951e75936cefad0970be704cb7c733b3f7
Author: Hervé Boutemy <hb...@apache.org>
AuthorDate: Fri Feb 22 12:22:19 2019 +0100

    [MPH-160] add color for comments
---
 pom.xml                                                       |  5 +++++
 .../java/org/apache/maven/plugins/help/EffectivePomMojo.java  | 11 +++++++++++
 2 files changed, 16 insertions(+)

diff --git a/pom.xml b/pom.xml
index c8bead1..7e7fc49 100644
--- a/pom.xml
+++ b/pom.xml
@@ -137,6 +137,11 @@
     <!-- shared -->
     <dependency>
       <groupId>org.apache.maven.shared</groupId>
+      <artifactId>maven-shared-utils</artifactId>
+      <version>3.2.1</version>
+    </dependency>
+    <dependency>
+      <groupId>org.apache.maven.shared</groupId>
       <artifactId>maven-artifact-transfer</artifactId>
       <version>0.10.0</version>
     </dependency>
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 cd481ca..ae9a455 100644
--- a/src/main/java/org/apache/maven/plugins/help/EffectivePomMojo.java
+++ b/src/main/java/org/apache/maven/plugins/help/EffectivePomMojo.java
@@ -35,6 +35,7 @@ import org.apache.maven.plugin.MojoExecutionException;
 import org.apache.maven.plugins.annotations.Mojo;
 import org.apache.maven.plugins.annotations.Parameter;
 import org.apache.maven.project.MavenProject;
+import org.apache.maven.shared.utils.logging.MessageUtils;
 import org.codehaus.plexus.util.StringUtils;
 import org.codehaus.plexus.util.xml.PrettyPrintXMLWriter;
 import org.codehaus.plexus.util.xml.XMLWriter;
@@ -152,6 +153,16 @@ public class EffectivePomMojo
         }
         else
         {
+            if ( MessageUtils.isColorEnabled() )
+            {
+                // add color to comments
+                String comment = MessageUtils.buffer().project( "<!--.-->" ).toString();
+                int dotIndex = comment.indexOf( "." );
+                String commentStart = comment.substring( 0, dotIndex );
+                String commentEnd = comment.substring( dotIndex + 1 );
+                effectivePom = effectivePom.replaceAll( "<!--", commentStart ).replaceAll( "-->", commentEnd );
+            }
+
             StringBuilder message = new StringBuilder();
 
             message.append( LS );


[maven-help-plugin] 04/04: [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 0e2d19e340a961072b24799233f099cfdd0aba11
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 usinf
    InputLocation.StringFormatter abstract class
---
 pom.xml                                            |   2 +-
 .../maven/plugins/help/EffectivePomMojo.java       | 124 ++++++++++++++++++---
 2 files changed, 111 insertions(+), 15 deletions(-)

diff --git a/pom.xml b/pom.xml
index 215a592..214b757 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 );
         }
     }
 }