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 16:17:18 UTC

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

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 0e2d19e  [MPH-160] use Maven-provided xpp3-extended-writer when available
 discard 9da7ef0  [MPH-160] update plexus-utils and Modello for XPP3 DOM tracking
 discard fe17779  [MPH-160] add color for comments
 discard 8502f1b  [MPH-160] add "verbose" to effective-pom to display POM input location
     new 81ee66f  [MPH-160] add "verbose" to effective-pom to display POM input location
     new 7f5468c  [MPH-160] add color for comments
     new c42e663  [MPH-160] update plexus-utils and Modello for XPP3 DOM tracking
     new d523875  [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   (0e2d19e)
            \
             N -- N -- N   refs/heads/MPH-160 (d523875)

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:
 pom.xml | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)


[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 81ee66f4fc1d663aeae76dc6bbfecd8d55c54684
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                                            | 47 ++++++++++++++++++-
 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, 151 insertions(+), 4 deletions(-)

diff --git a/pom.xml b/pom.xml
index 3316d04..6b77045 100644
--- a/pom.xml
+++ b/pom.xml
@@ -30,7 +30,7 @@
   </parent>
 
   <artifactId>maven-help-plugin</artifactId>
-  <version>3.1.2-SNAPSHOT</version>
+  <version>3.2.0-SNAPSHOT</version>
   <packaging>maven-plugin</packaging>
 
   <name>Apache Maven Help Plugin</name>
@@ -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.10.0</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] 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 d5238750b291b8674e769572a78366a9e4afb5c9
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 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 );
         }
     }
 }


[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 7f5468c17409113584a0fed3a6e49321f39ce43c
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 6b77045..ad54484 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] 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 c42e66339b8623160d283f573e620f78c0d32d75
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 | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/pom.xml b/pom.xml
index ad54484..017e8a2 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</version>
     </dependency>
 
     <!-- misc -->