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 22:47:46 UTC

[maven-help-plugin] branch master updated (1d6368d -> c5f14c1)

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

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


    from 1d6368d  Bump plexus-interactivity-api from 1.0-alpha-6 to 1.0
     new 512535b  [MPH-170] Require Maven 3.1.1, drop dependency to maven-artifact-transfer
     new c5f14c1  Bump to 3.3.0-SNAPSHOT

The 2 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                                            | 24 ++-----
 .../maven/plugins/help/AbstractHelpMojo.java       | 62 ++++++++++-------
 .../apache/maven/plugins/help/DescribeMojo.java    | 35 ++++------
 .../apache/maven/plugins/help/EvaluateMojo.java    | 78 ++++++++++------------
 4 files changed, 91 insertions(+), 108 deletions(-)


[maven-help-plugin] 02/02: Bump to 3.3.0-SNAPSHOT

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

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

commit c5f14c178bc26489b0bf722d90f489f98f3225ba
Author: Sylwester Lachiewicz <sl...@apache.org>
AuthorDate: Sun Jan 10 23:38:53 2021 +0100

    Bump to 3.3.0-SNAPSHOT
---
 pom.xml | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/pom.xml b/pom.xml
index c0593ed..a52fcbf 100644
--- a/pom.xml
+++ b/pom.xml
@@ -26,11 +26,11 @@
     <artifactId>maven-plugins</artifactId>
     <groupId>org.apache.maven.plugins</groupId>
     <version>34</version>
-    <relativePath>../../pom/maven/maven-plugins/pom.xml</relativePath>
+    <relativePath />
   </parent>
 
   <artifactId>maven-help-plugin</artifactId>
-  <version>3.2.1-SNAPSHOT</version>
+  <version>3.3.0-SNAPSHOT</version>
   <packaging>maven-plugin</packaging>
 
   <name>Apache Maven Help Plugin</name>


[maven-help-plugin] 01/02: [MPH-170] Require Maven 3.1.1, drop dependency to maven-artifact-transfer

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

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

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

    [MPH-170] Require Maven 3.1.1, drop dependency to maven-artifact-transfer
---
 pom.xml                                            | 20 +-----
 .../maven/plugins/help/AbstractHelpMojo.java       | 62 ++++++++++-------
 .../apache/maven/plugins/help/DescribeMojo.java    | 35 ++++------
 .../apache/maven/plugins/help/EvaluateMojo.java    | 78 ++++++++++------------
 4 files changed, 89 insertions(+), 106 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..1477f1b 100644
--- a/src/main/java/org/apache/maven/plugins/help/AbstractHelpMojo.java
+++ b/src/main/java/org/apache/maven/plugins/help/AbstractHelpMojo.java
@@ -19,11 +19,7 @@ package org.apache.maven.plugins.help;
  * under the License.
  */
 
-import java.io.File;
-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 +32,22 @@ 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.ArtifactDescriptorRequest;
+import org.eclipse.aether.resolution.ArtifactDescriptorResult;
+import org.eclipse.aether.resolution.ArtifactRequest;
+
+import java.io.File;
+import java.io.IOException;
+import java.io.Writer;
+import java.util.List;
 
 /**
  * Base class with some Help Mojo functionalities.
@@ -63,13 +69,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;
-    
+    protected RepositorySystem repositorySystem;
+
     /**
      * Remote repositories used for the project.
      */
@@ -152,7 +158,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 +187,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,15 +203,18 @@ public abstract class AbstractHelpMojo
     protected MavenProject getMavenProject( String artifactString )
         throws MojoExecutionException
     {
-        ArtifactCoordinate coordinate = getArtifactCoordinate( artifactString, "pom" );
         try
         {
             ProjectBuildingRequest pbr = new DefaultProjectBuildingRequest( session.getProjectBuildingRequest() );
             pbr.setRemoteRepositories( remoteRepositories );
+            pbr.setLocalRepository( localRepository );
             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,18 @@ public abstract class AbstractHelpMojo
         }
     }
 
+    protected org.eclipse.aether.resolution.ArtifactResult resolveArtifact(
+            org.eclipse.aether.artifact.Artifact artifact ) throws RepositoryException
+    {
+        List<RemoteRepository> repositories = RepositoryUtils.toRepos( remoteRepositories );
+        RepositorySystemSession repositorySession = session.getProjectBuildingRequest().getRepositorySession();
+
+        // use descriptor to respect relocation
+        ArtifactDescriptorResult artifactDescriptor = repositorySystem.readArtifactDescriptor(
+                repositorySession, new ArtifactDescriptorRequest( artifact, repositories, null ) );
+
+        return repositorySystem.resolveArtifact( repositorySession,
+                new ArtifactRequest( artifactDescriptor.getArtifact(), repositories, null ) );
+    }
+
 }
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..334ede7 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,17 @@ 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 = new DefaultArtifact(
+                    pd.getGroupId(), pd.getArtifactId(), "jar", pd.getVersion() );
             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 +695,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 )
         {
@@ -977,8 +979,10 @@ 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(
+                    new DefaultArtifact( pd.getGroupId(), pd.getArtifactId(), "jar", pd.getVersion() ) ).getArtifact();
+            org.eclipse.aether.artifact.Artifact pom = resolveArtifact(
+                    new DefaultArtifact( pd.getGroupId(), pd.getArtifactId(), "pom", pd.getVersion() ) ).getArtifact();
             MavenProject project = projectBuilder.build( pom.getFile(), pbr ).getProject();
             urls.add( jar.getFile().toURI().toURL() );
             for ( Object artifact : project.getCompileClasspathElements() )
@@ -997,19 +1001,6 @@ public class DescribeMojo
     }
 
     /**
-     * Transforms the given plugin descriptor into an artifact coordinate. It is formed by its GAV information, along
-     * with the given type.
-     *
-     * @param pd Plugin descriptor.
-     * @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 )
-    {
-        return getArtifactCoordinate( pd.getGroupId(), pd.getArtifactId(), pd.getVersion(), type );
-    }
-
-    /**
      * Gets the effective string to use for the plugin/mojo/parameter description.
      *
      * @param description The description of the element, may be <code>null</code>.
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..4710725 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,10 @@ 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
+        throws MojoExecutionException, ProjectBuildingException, RepositoryException
     {
         return getArtifactFile( true );
     }
@@ -589,10 +587,10 @@ 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
+        throws MojoExecutionException, ProjectBuildingException, RepositoryException
     {
         return getArtifactFile( false );
     }
@@ -603,41 +601,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 +642,9 @@ 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
+        throws MojoExecutionException
     {
         String resource = "META-INF/maven/org.apache.maven.plugins/maven-help-plugin/pom.properties";