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/01 22:47:33 UTC
[maven-help-plugin] 03/03: Maven 3.1.1
This is an automated email from the ASF dual-hosted git repository.
slachiewicz pushed a commit to branch next
in repository https://gitbox.apache.org/repos/asf/maven-help-plugin.git
commit c893bd5e23dac828b1d76003ad9914ed5a1c070d
Author: Sylwester Lachiewicz <sl...@apache.org>
AuthorDate: Fri Jan 1 23:47:14 2021 +0100
Maven 3.1.1
---
pom.xml | 9 +---
.../maven/plugins/help/AbstractHelpMojo.java | 61 +++++++++++++++-------
.../apache/maven/plugins/help/DescribeMojo.java | 29 +++++-----
.../apache/maven/plugins/help/EvaluateMojo.java | 36 ++++++-------
4 files changed, 73 insertions(+), 62 deletions(-)
diff --git a/pom.xml b/pom.xml
index 7847bb4..272322c 100644
--- a/pom.xml
+++ b/pom.xml
@@ -69,7 +69,7 @@
<properties>
<javaVersion>7</javaVersion>
- <mavenVersion>3.0</mavenVersion>
+ <mavenVersion>3.1.1</mavenVersion>
<project.build.outputTimestamp>2020-04-07T21:04:00Z</project.build.outputTimestamp>
</properties>
@@ -142,11 +142,6 @@
<version>3.3.3</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>
@@ -211,7 +206,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>
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..22abe6e 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 getArtifact( 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, null, 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(
+ getArtifact( 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..b3ad4e1 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,15 @@ 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 coordinate = toArtifact( pd, "jar" );
ProjectBuildingRequest pbr = new DefaultProjectBuildingRequest( session.getProjectBuildingRequest() );
pbr.setRemoteRepositories( remoteRepositories );
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 artifact = resolveArtifact( coordinate ).getArtifact();
+ name = projectBuilder.build( RepositoryUtils.toArtifact( artifact ), pbr ).getProject().getName();
}
catch ( Exception e )
{
@@ -692,11 +693,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 +819,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 +976,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( toArtifact( pd, "jar" ) ).getArtifact();
+ org.eclipse.aether.artifact.Artifact pom = resolveArtifact( toArtifact( 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 +1002,10 @@ 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 toArtifact( PluginDescriptor pd, String type )
{
- return getArtifactCoordinate( pd.getGroupId(), pd.getArtifactId(), pd.getVersion(), type );
+ return new DefaultArtifact( pd.getGroupId(), pd.getArtifactId(), null, type, pd.getVersion() );
+// return getArtifactCoordinate( pd.getGroupId(), pd.getArtifactId(), pd.getVersion(), type );
}
/**
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..3b41b68 100644
--- a/src/main/java/org/apache/maven/plugins/help/EvaluateMojo.java
+++ b/src/main/java/org/apache/maven/plugins/help/EvaluateMojo.java
@@ -51,8 +51,6 @@ 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;
@@ -62,6 +60,9 @@ 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.eclipse.aether.RepositoryException;
+import org.eclipse.aether.artifact.Artifact;
+import org.eclipse.aether.artifact.DefaultArtifact;
/**
* Evaluates Maven expressions given by the user in an interactive mode.
@@ -498,11 +499,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 +578,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 +589,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,11 +602,8 @@ 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
+ private File getArtifactFile( boolean isPom ) throws MojoExecutionException, RepositoryException
{
List<Dependency> dependencies = getHelpPluginPom().getDependencies();
for ( Dependency depependency : dependencies )
@@ -632,12 +628,12 @@ public class EvaluateMojo
}
}
- ArtifactCoordinate coordinate =
- getArtifactCoordinate( depependency.getGroupId(), depependency.getArtifactId(),
- depependency.getVersion(), "jar" );
+ Artifact artifact = new DefaultArtifact( depependency.getGroupId(), depependency.getArtifactId(), null,
+ "jar", depependency.getVersion() );
+
ProjectBuildingRequest pbr = new DefaultProjectBuildingRequest( session.getProjectBuildingRequest() );
pbr.setRemoteRepositories( remoteRepositories );
- return artifactResolver.resolveArtifact( pbr, coordinate ).getArtifact().getFile();
+ return resolveArtifact( artifact ).getArtifact().getFile();
}
throw new MojoExecutionException( "Unable to find the 'org.apache.maven:"
@@ -647,10 +643,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";