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 2021/01/10 19:10:53 UTC

[maven-help-plugin] branch MPH-170 updated (39c89f4 -> 6b7c469)

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

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


 discard 39c89f4  [MPH-170] Maven 3.1.1
 discard 2882c06  [MPH-164] - Effective-pom ignores artifact argument
     new 6b7c469  [MPH-170] Maven 3.1.1

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   (39c89f4)
            \
             N -- N -- N   refs/heads/MPH-170 (6b7c469)

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:
 pom.xml                                            | 11 -----
 .../invoker.properties                             | 18 -------
 .../module/pom.xml                                 | 23 ---------
 src/it/effective-pom-multimodule-artifact/pom.xml  | 41 ----------------
 .../test.properties                                | 19 --------
 .../verify.groovy                                  | 30 ------------
 .../maven/plugins/help/AbstractHelpMojo.java       |  6 +--
 .../apache/maven/plugins/help/DescribeMojo.java    | 16 +++---
 .../maven/plugins/help/EffectivePomMojo.java       |  2 -
 .../apache/maven/plugins/help/EvaluateMojo.java    | 57 ++++++++++------------
 10 files changed, 38 insertions(+), 185 deletions(-)
 delete mode 100644 src/it/effective-pom-multimodule-artifact/invoker.properties
 delete mode 100644 src/it/effective-pom-multimodule-artifact/module/pom.xml
 delete mode 100644 src/it/effective-pom-multimodule-artifact/pom.xml
 delete mode 100644 src/it/effective-pom-multimodule-artifact/test.properties
 delete mode 100644 src/it/effective-pom-multimodule-artifact/verify.groovy


[maven-help-plugin] 01/01: [MPH-170] Maven 3.1.1

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

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

commit 6b7c4698bdbd8cfb503d12ffb0787474d79cc635
Author: Sylwester Lachiewicz <sl...@apache.org>
AuthorDate: Fri Jan 1 23:47:14 2021 +0100

    [MPH-170] Maven 3.1.1
---
 pom.xml                                            | 20 +-----
 .../maven/plugins/help/AbstractHelpMojo.java       | 61 +++++++++++-----
 .../apache/maven/plugins/help/DescribeMojo.java    | 29 ++++----
 .../apache/maven/plugins/help/EvaluateMojo.java    | 81 ++++++++++------------
 4 files changed, 94 insertions(+), 97 deletions(-)

diff --git a/pom.xml b/pom.xml
index 57e53e8..c0593ed 100644
--- a/pom.xml
+++ b/pom.xml
@@ -69,7 +69,7 @@
 
   <properties>
     <javaVersion>7</javaVersion>
-    <mavenVersion>3.0</mavenVersion>
+    <mavenVersion>3.1.1</mavenVersion>
     <surefire.version>2.22.2</surefire.version>
     <project.build.outputTimestamp>2020-04-07T21:04:00Z</project.build.outputTimestamp>
   </properties>
@@ -143,11 +143,6 @@
       <version>3.2.1</version>
     </dependency>
     <dependency>
-      <groupId>org.apache.maven.shared</groupId>
-      <artifactId>maven-artifact-transfer</artifactId>
-      <version>0.10.0</version>
-    </dependency>
-    <dependency>
       <groupId>org.apache.maven.reporting</groupId>
       <artifactId>maven-reporting-api</artifactId>
       <version>3.0</version>
@@ -212,7 +207,7 @@
     <dependency>
       <groupId>org.apache.maven.plugin-testing</groupId>
       <artifactId>maven-plugin-testing-harness</artifactId>
-      <version>2.1</version>
+      <version>3.1.0</version>
       <scope>test</scope>
     </dependency>
     <dependency>
@@ -273,17 +268,6 @@
           </execution>
         </executions>
       </plugin>
-      <plugin>
-        <groupId>org.codehaus.plexus</groupId>
-        <artifactId>plexus-component-metadata</artifactId>
-        <executions>
-          <execution>
-            <goals>
-              <goal>generate-metadata</goal>
-            </goals>
-          </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>
diff --git a/src/main/java/org/apache/maven/plugins/help/AbstractHelpMojo.java b/src/main/java/org/apache/maven/plugins/help/AbstractHelpMojo.java
index 4349428..5871f12 100644
--- a/src/main/java/org/apache/maven/plugins/help/AbstractHelpMojo.java
+++ b/src/main/java/org/apache/maven/plugins/help/AbstractHelpMojo.java
@@ -24,6 +24,7 @@ import java.io.IOException;
 import java.io.Writer;
 import java.util.List;
 
+import org.apache.maven.RepositoryUtils;
 import org.apache.maven.artifact.Artifact;
 import org.apache.maven.artifact.repository.ArtifactRepository;
 import org.apache.maven.execution.MavenSession;
@@ -36,12 +37,18 @@ import org.apache.maven.project.DefaultProjectBuildingRequest;
 import org.apache.maven.project.MavenProject;
 import org.apache.maven.project.ProjectBuilder;
 import org.apache.maven.project.ProjectBuildingRequest;
-import org.apache.maven.shared.transfer.artifact.ArtifactCoordinate;
-import org.apache.maven.shared.transfer.artifact.DefaultArtifactCoordinate;
-import org.apache.maven.shared.transfer.artifact.resolve.ArtifactResolver;
 import org.codehaus.plexus.util.IOUtil;
 import org.codehaus.plexus.util.StringUtils;
 import org.codehaus.plexus.util.WriterFactory;
+import org.eclipse.aether.RepositoryException;
+import org.eclipse.aether.RepositorySystem;
+import org.eclipse.aether.RepositorySystemSession;
+import org.eclipse.aether.artifact.DefaultArtifact;
+import org.eclipse.aether.repository.RemoteRepository;
+import org.eclipse.aether.resolution.ArtifactDescriptorException;
+import org.eclipse.aether.resolution.ArtifactDescriptorRequest;
+import org.eclipse.aether.resolution.ArtifactDescriptorResult;
+import org.eclipse.aether.resolution.ArtifactRequest;
 
 /**
  * Base class with some Help Mojo functionalities.
@@ -63,13 +70,13 @@ public abstract class AbstractHelpMojo
      */
     @Component
     protected ProjectBuilder projectBuilder;
-    
+
     /**
      * Component used to resolve artifacts and download their files from remote repositories.
      */
     @Component
-    protected ArtifactResolver artifactResolver;
-    
+    RepositorySystem repositorySystem;
+
     /**
      * Remote repositories used for the project.
      */
@@ -152,7 +159,7 @@ public abstract class AbstractHelpMojo
      * @return the <code>Artifact</code> object for the <code>artifactString</code> parameter.
      * @throws MojoExecutionException if the <code>artifactString</code> doesn't respect the format.
      */
-    protected ArtifactCoordinate getArtifactCoordinate( String artifactString, String type )
+    protected org.eclipse.aether.artifact.Artifact getAetherArtifact( String artifactString, String type )
         throws MojoExecutionException
     {
         if ( StringUtils.isEmpty( artifactString ) )
@@ -181,17 +188,8 @@ public abstract class AbstractHelpMojo
                 throw new MojoExecutionException( "The artifact parameter '" + artifactString
                     + "' should be conform to: " + "'groupId:artifactId[:version]'." );
         }
-        return getArtifactCoordinate( groupId, artifactId, version, type );
-    }
 
-    protected ArtifactCoordinate getArtifactCoordinate( String groupId, String artifactId, String version, String type )
-    {
-        DefaultArtifactCoordinate coordinate = new DefaultArtifactCoordinate();
-        coordinate.setGroupId( groupId );
-        coordinate.setArtifactId( artifactId );
-        coordinate.setVersion( version );
-        coordinate.setExtension( type );
-        return coordinate;
+        return new DefaultArtifact( groupId, artifactId, type, version );
     }
 
     /**
@@ -206,7 +204,6 @@ public abstract class AbstractHelpMojo
     protected MavenProject getMavenProject( String artifactString )
         throws MojoExecutionException
     {
-        ArtifactCoordinate coordinate = getArtifactCoordinate( artifactString, "pom" );
         try
         {
             ProjectBuildingRequest pbr = new DefaultProjectBuildingRequest( session.getProjectBuildingRequest() );
@@ -214,7 +211,10 @@ public abstract class AbstractHelpMojo
             pbr.setProject( null );
             pbr.setValidationLevel( ModelBuildingRequest.VALIDATION_LEVEL_MINIMAL );
             pbr.setResolveDependencies( true );
-            Artifact artifact = artifactResolver.resolveArtifact( pbr, coordinate ).getArtifact();
+
+            org.eclipse.aether.artifact.Artifact artifact = resolveArtifact(
+                    getAetherArtifact( artifactString, "pom" ) ).getArtifact();
+
             return projectBuilder.build( artifact.getFile(), pbr ).getProject();
         }
         catch ( Exception e )
@@ -224,4 +224,27 @@ public abstract class AbstractHelpMojo
         }
     }
 
+    protected org.eclipse.aether.resolution.ArtifactResult resolveArtifact(
+            org.eclipse.aether.artifact.Artifact aetherArtifact ) throws RepositoryException
+    {
+        try
+        {
+            List<RemoteRepository> remoteRepositories = RepositoryUtils.toRepos( this.remoteRepositories );
+            RepositorySystemSession repositorySession = session.getProjectBuildingRequest().getRepositorySession();
+
+            // use descriptor to respect relocation
+            ArtifactDescriptorRequest descriptorRequest = new ArtifactDescriptorRequest( aetherArtifact,
+                    remoteRepositories, null );
+            ArtifactDescriptorResult descriptorResult = repositorySystem.readArtifactDescriptor( repositorySession,
+                    descriptorRequest );
+            ArtifactRequest request = new ArtifactRequest( descriptorResult.getArtifact(), remoteRepositories, null );
+
+            return repositorySystem.resolveArtifact( repositorySession, request );
+        }
+        catch ( ArtifactDescriptorException  e )
+        {
+            throw new RepositoryException( e.getMessage(), e );
+        }
+    }
+
 }
diff --git a/src/main/java/org/apache/maven/plugins/help/DescribeMojo.java b/src/main/java/org/apache/maven/plugins/help/DescribeMojo.java
index da65624..7d16bcb 100644
--- a/src/main/java/org/apache/maven/plugins/help/DescribeMojo.java
+++ b/src/main/java/org/apache/maven/plugins/help/DescribeMojo.java
@@ -32,7 +32,7 @@ import java.util.StringTokenizer;
 import java.util.regex.Matcher;
 import java.util.regex.Pattern;
 
-import org.apache.maven.artifact.Artifact;
+import org.apache.maven.RepositoryUtils;
 import org.apache.maven.lifecycle.DefaultLifecycles;
 import org.apache.maven.lifecycle.Lifecycle;
 import org.apache.maven.lifecycle.internal.MojoDescriptorCreator;
@@ -56,11 +56,12 @@ import org.apache.maven.project.MavenProject;
 import org.apache.maven.project.ProjectBuildingRequest;
 import org.apache.maven.reporting.MavenReport;
 import org.apache.maven.reporting.exec.MavenPluginManagerHelper;
-import org.apache.maven.shared.transfer.artifact.ArtifactCoordinate;
 import org.apache.maven.shared.utils.logging.MessageUtils;
 import org.apache.maven.tools.plugin.generator.GeneratorUtils;
 import org.apache.maven.tools.plugin.util.PluginUtils;
 import org.codehaus.plexus.util.StringUtils;
+import org.eclipse.aether.artifact.Artifact;
+import org.eclipse.aether.artifact.DefaultArtifact;
 
 /**
  * Displays a list of the attributes for a Maven Plugin and/or goals (aka Mojo - Maven plain Old Java Object).
@@ -431,15 +432,16 @@ public class DescribeMojo
         if ( name == null )
         {
             // Can be null because of MPLUGIN-137 (and descriptors generated with maven-plugin-tools-api <= 2.4.3)
-            ArtifactCoordinate coordinate = toArtifactCoordinate( pd, "jar" );
+            org.eclipse.aether.artifact.Artifact aetherArtifact = toAetherArtifact( pd, "jar" );
             ProjectBuildingRequest pbr = new DefaultProjectBuildingRequest( session.getProjectBuildingRequest() );
             pbr.setRemoteRepositories( remoteRepositories );
+            pbr.setLocalRepository( localRepository );
             pbr.setProject( null );
             pbr.setValidationLevel( ModelBuildingRequest.VALIDATION_LEVEL_MINIMAL );
             try
             {
-                Artifact artifact = artifactResolver.resolveArtifact( pbr, coordinate ).getArtifact();
-                name = projectBuilder.build( artifact, pbr ).getProject().getName();
+                Artifact artifactCopy = resolveArtifact( aetherArtifact ).getArtifact();
+                name = projectBuilder.build( RepositoryUtils.toArtifact( artifactCopy ), pbr ).getProject().getName();
             }
             catch ( Exception e )
             {
@@ -692,11 +694,10 @@ public class DescribeMojo
      *
      * @param descriptionBuffer not null
      * @return <code>true</code> if it implies to describe a plugin, <code>false</code> otherwise.
-     * @throws MojoFailureException   if any reflection exceptions occur or missing components.
      * @throws MojoExecutionException if any
      */
     private boolean describeCommand( StringBuilder descriptionBuffer )
-        throws MojoFailureException, MojoExecutionException
+        throws MojoExecutionException
     {
         if ( cmd.indexOf( ':' ) == -1 )
         {
@@ -819,8 +820,7 @@ public class DescribeMojo
         try
         {
             Method m = HelpMojo.class.getDeclaredMethod( "toLines",
-                                                         new Class[]{ String.class, Integer.TYPE, Integer.TYPE,
-                                                             Integer.TYPE } );
+                    String.class, Integer.TYPE, Integer.TYPE, Integer.TYPE );
             m.setAccessible( true );
             @SuppressWarnings( "unchecked" )
             List<String> output = (List<String>) m.invoke( HelpMojo.class, text, indent, indentSize, lineLength );
@@ -977,16 +977,15 @@ public class DescribeMojo
         pbr.setValidationLevel( ModelBuildingRequest.VALIDATION_LEVEL_MINIMAL );
         try
         {
-            Artifact jar = artifactResolver.resolveArtifact( pbr, toArtifactCoordinate( pd, "jar" ) ).getArtifact();
-            Artifact pom = artifactResolver.resolveArtifact( pbr, toArtifactCoordinate( pd, "pom" ) ).getArtifact();
+            org.eclipse.aether.artifact.Artifact jar = resolveArtifact( toAetherArtifact( pd, "jar" ) ).getArtifact();
+            org.eclipse.aether.artifact.Artifact pom = resolveArtifact( toAetherArtifact( pd, "pom" ) ).getArtifact();
             MavenProject project = projectBuilder.build( pom.getFile(), pbr ).getProject();
             urls.add( jar.getFile().toURI().toURL() );
             for ( Object artifact : project.getCompileClasspathElements() )
             {
                 urls.add( new File( (String) artifact ).toURI().toURL() );
             }
-            ClassLoader classLoader =
-                new URLClassLoader( urls.toArray( new URL[urls.size()] ), getClass().getClassLoader() );
+            ClassLoader classLoader = new URLClassLoader( urls.toArray( new URL[0] ), getClass().getClassLoader() );
             return MavenReport.class.isAssignableFrom( Class.forName( md.getImplementation(), false, classLoader ) );
         }
         catch ( Exception e )
@@ -1004,9 +1003,9 @@ public class DescribeMojo
      * @param type Extension for the coordinate.
      * @return Coordinate of an artifact having the same GAV as the given plugin descriptor, with the given type.
      */
-    private ArtifactCoordinate toArtifactCoordinate( PluginDescriptor pd, String type )
+    private org.eclipse.aether.artifact.Artifact toAetherArtifact( PluginDescriptor pd, String type )
     {
-        return getArtifactCoordinate( pd.getGroupId(), pd.getArtifactId(), pd.getVersion(), type );
+        return new DefaultArtifact( pd.getGroupId(), pd.getArtifactId(), type, pd.getVersion() );
     }
 
     /**
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 758973e..bcb5de9 100644
--- a/src/main/java/org/apache/maven/plugins/help/EvaluateMojo.java
+++ b/src/main/java/org/apache/maven/plugins/help/EvaluateMojo.java
@@ -19,19 +19,10 @@ package org.apache.maven.plugins.help;
  * under the License.
  */
 
-import java.io.File;
-import java.io.FileInputStream;
-import java.io.IOException;
-import java.io.InputStream;
-import java.io.StringWriter;
-import java.util.List;
-import java.util.Locale;
-import java.util.Map;
-import java.util.Properties;
-import java.util.TreeMap;
-import java.util.jar.JarEntry;
-import java.util.jar.JarInputStream;
-
+import com.thoughtworks.xstream.XStream;
+import com.thoughtworks.xstream.converters.MarshallingContext;
+import com.thoughtworks.xstream.converters.collections.PropertiesConverter;
+import com.thoughtworks.xstream.io.HierarchicalStreamWriter;
 import org.apache.commons.lang3.ClassUtils;
 import org.apache.maven.lifecycle.internal.MojoDescriptorCreator;
 import org.apache.maven.model.Dependency;
@@ -45,23 +36,30 @@ import org.apache.maven.plugin.descriptor.MojoDescriptor;
 import org.apache.maven.plugins.annotations.Component;
 import org.apache.maven.plugins.annotations.Mojo;
 import org.apache.maven.plugins.annotations.Parameter;
-import org.apache.maven.project.DefaultProjectBuildingRequest;
 import org.apache.maven.project.MavenProject;
 import org.apache.maven.project.ProjectBuildingException;
-import org.apache.maven.project.ProjectBuildingRequest;
 import org.apache.maven.settings.Settings;
 import org.apache.maven.settings.io.xpp3.SettingsXpp3Writer;
-import org.apache.maven.shared.transfer.artifact.ArtifactCoordinate;
-import org.apache.maven.shared.transfer.artifact.resolve.ArtifactResolverException;
 import org.codehaus.plexus.component.configurator.expression.ExpressionEvaluationException;
 import org.codehaus.plexus.components.interactivity.InputHandler;
 import org.codehaus.plexus.util.IOUtil;
 import org.codehaus.plexus.util.StringUtils;
+import org.eclipse.aether.RepositoryException;
+import org.eclipse.aether.artifact.Artifact;
+import org.eclipse.aether.artifact.DefaultArtifact;
 
-import com.thoughtworks.xstream.XStream;
-import com.thoughtworks.xstream.converters.MarshallingContext;
-import com.thoughtworks.xstream.converters.collections.PropertiesConverter;
-import com.thoughtworks.xstream.io.HierarchicalStreamWriter;
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.StringWriter;
+import java.util.List;
+import java.util.Locale;
+import java.util.Map;
+import java.util.Properties;
+import java.util.TreeMap;
+import java.util.jar.JarEntry;
+import java.util.jar.JarInputStream;
 
 /**
  * Evaluates Maven expressions given by the user in an interactive mode.
@@ -498,11 +496,11 @@ public class EvaluateMojo
                 getLog().debug( "MojoExecutionException: " + e.getMessage(), e );
             }
         }
-        catch ( ArtifactResolverException e )
+        catch ( RepositoryException e )
         {
             if ( getLog().isDebugEnabled() )
             {
-                getLog().debug( "ArtifactResolverException: " + e.getMessage(), e );
+                getLog().debug( "RepositoryException: " + e.getMessage(), e );
             }
         }
         catch ( ProjectBuildingException e )
@@ -577,10 +575,9 @@ public class EvaluateMojo
      * @return the <code>org.apache.maven:maven-model</code> artifact jar file in the local repository.
      * @throws MojoExecutionException if any
      * @throws ProjectBuildingException if any
-     * @throws ArtifactResolverException if any
+     * @throws RepositoryException if any
      */
-    private File getMavenModelJarFile()
-        throws MojoExecutionException, ProjectBuildingException, ArtifactResolverException
+    private File getMavenModelJarFile() throws MojoExecutionException, ProjectBuildingException, RepositoryException
     {
         return getArtifactFile( true );
     }
@@ -589,10 +586,9 @@ public class EvaluateMojo
      * @return the <code>org.apache.maven:maven-settings</code> artifact jar file in the local repository.
      * @throws MojoExecutionException if any
      * @throws ProjectBuildingException if any
-     * @throws ArtifactResolverException if any
+     * @throws RepositoryException if any
      */
-    private File getMavenSettingsJarFile()
-        throws MojoExecutionException, ProjectBuildingException, ArtifactResolverException
+    private File getMavenSettingsJarFile() throws MojoExecutionException, ProjectBuildingException, RepositoryException
     {
         return getArtifactFile( false );
     }
@@ -603,41 +599,38 @@ public class EvaluateMojo
      * @return the <code>org.apache.maven:maven-model|maven-settings</code> artifact jar file for this current
      *         HelpPlugin pom.
      * @throws MojoExecutionException if any
-     * @throws ProjectBuildingException if any
-     * @throws ArtifactResolverException if any
      */
     private File getArtifactFile( boolean isPom )
-        throws MojoExecutionException, ProjectBuildingException, ArtifactResolverException
+            throws MojoExecutionException, RepositoryException
     {
         List<Dependency> dependencies = getHelpPluginPom().getDependencies();
-        for ( Dependency depependency : dependencies )
+        for ( Dependency dependency : dependencies )
         {
-            if ( !( depependency.getGroupId().equals( "org.apache.maven" ) ) )
+            if ( !( dependency.getGroupId().equals( "org.apache.maven" ) ) )
             {
                 continue;
             }
 
             if ( isPom )
             {
-                if ( !( depependency.getArtifactId().equals( "maven-model" ) ) )
+                if ( !( dependency.getArtifactId().equals( "maven-model" ) ) )
                 {
                     continue;
                 }
             }
             else
             {
-                if ( !( depependency.getArtifactId().equals( "maven-settings" ) ) )
+                if ( !( dependency.getArtifactId().equals( "maven-settings" ) ) )
                 {
                     continue;
                 }
             }
 
-            ArtifactCoordinate coordinate =
-                getArtifactCoordinate( depependency.getGroupId(), depependency.getArtifactId(),
-                                       depependency.getVersion(), "jar" );
-            ProjectBuildingRequest pbr = new DefaultProjectBuildingRequest( session.getProjectBuildingRequest() );
-            pbr.setRemoteRepositories( remoteRepositories );
-            return artifactResolver.resolveArtifact( pbr, coordinate ).getArtifact().getFile();
+            Artifact mavenArtifact = new DefaultArtifact(
+                    dependency.getGroupId(), dependency.getArtifactId(), "jar",
+                    dependency.getVersion() );
+
+            return resolveArtifact( mavenArtifact ).getArtifact().getFile();
         }
 
         throw new MojoExecutionException( "Unable to find the 'org.apache.maven:"
@@ -647,10 +640,8 @@ public class EvaluateMojo
     /**
      * @return the Maven POM for the current help plugin
      * @throws MojoExecutionException if any
-     * @throws ProjectBuildingException if any
      */
-    private MavenProject getHelpPluginPom()
-        throws MojoExecutionException, ProjectBuildingException
+    private MavenProject getHelpPluginPom() throws MojoExecutionException
     {
         String resource = "META-INF/maven/org.apache.maven.plugins/maven-help-plugin/pom.properties";