From 5299d728b925f862be33f5244ca86de625261d6e Mon Sep 17 00:00:00 2001 From: Slawomir Jaranowski Date: Fri, 10 Mar 2023 07:53:51 +0100 Subject: [PATCH] [MPH-195] Get rid of localRepository from mojo parameter --- .../maven/plugins/help/AbstractHelpMojo.java | 37 +++++-------------- .../maven/plugins/help/DescribeMojo.java | 17 ++------- .../maven/plugins/help/EffectivePomMojo.java | 8 ---- .../maven/plugins/help/EvaluateMojo.java | 6 --- .../maven/plugins/help/DescribeMojoTest.java | 2 +- 5 files changed, 15 insertions(+), 55 deletions(-) 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 4e3249a3..d9512f1e 100644 --- a/src/main/java/org/apache/maven/plugins/help/AbstractHelpMojo.java +++ b/src/main/java/org/apache/maven/plugins/help/AbstractHelpMojo.java @@ -21,11 +21,8 @@ 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; import org.apache.maven.model.building.ModelBuildingRequest; import org.apache.maven.plugin.AbstractMojo; @@ -42,7 +39,6 @@ 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; @@ -73,22 +69,10 @@ public abstract class AbstractHelpMojo extends AbstractMojo { protected RepositorySystem repositorySystem; /** - * Remote repositories used for the project. + * Current Maven project. */ - @Parameter(defaultValue = "${project.remoteArtifactRepositories}", required = true, readonly = true) - protected List remoteRepositories; - - /** - * Plugin repositories used for the project. - */ - @Parameter(defaultValue = "${project.pluginArtifactRepositories}", required = true, readonly = true) - protected List pluginArtifactRepositories; - - /** - * Local Repository. - */ - @Parameter(defaultValue = "${localRepository}", required = true, readonly = true) - protected ArtifactRepository localRepository; + @Parameter(defaultValue = "${project}", readonly = true, required = true) + protected MavenProject project; /** * The current build session instance. This is used for @@ -185,9 +169,8 @@ protected org.eclipse.aether.artifact.Artifact getAetherArtifact(String artifact protected MavenProject getMavenProject(String artifactString) throws MojoExecutionException { try { ProjectBuildingRequest pbr = new DefaultProjectBuildingRequest(session.getProjectBuildingRequest()); - pbr.setRemoteRepositories(remoteRepositories); - pbr.setLocalRepository(localRepository); - pbr.setPluginArtifactRepositories(pluginArtifactRepositories); + pbr.setRemoteRepositories(project.getRemoteArtifactRepositories()); + pbr.setPluginArtifactRepositories(project.getPluginArtifactRepositories()); pbr.setProject(null); pbr.setValidationLevel(ModelBuildingRequest.VALIDATION_LEVEL_MINIMAL); pbr.setResolveDependencies(true); @@ -205,15 +188,15 @@ protected MavenProject getMavenProject(String artifactString) throws MojoExecuti protected org.eclipse.aether.resolution.ArtifactResult resolveArtifact( org.eclipse.aether.artifact.Artifact artifact) throws RepositoryException { - List repositories = RepositoryUtils.toRepos(remoteRepositories); - RepositorySystemSession repositorySession = - session.getProjectBuildingRequest().getRepositorySession(); + RepositorySystemSession repositorySession = session.getRepositorySession(); // use descriptor to respect relocation ArtifactDescriptorResult artifactDescriptor = repositorySystem.readArtifactDescriptor( - repositorySession, new ArtifactDescriptorRequest(artifact, repositories, null)); + repositorySession, + new ArtifactDescriptorRequest(artifact, project.getRemoteProjectRepositories(), null)); return repositorySystem.resolveArtifact( - repositorySession, new ArtifactRequest(artifactDescriptor.getArtifact(), repositories, null)); + repositorySession, + new ArtifactRequest(artifactDescriptor.getArtifact(), project.getRemoteProjectRepositories(), 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 fe3613d0..516961e2 100644 --- a/src/main/java/org/apache/maven/plugins/help/DescribeMojo.java +++ b/src/main/java/org/apache/maven/plugins/help/DescribeMojo.java @@ -130,15 +130,6 @@ public class DescribeMojo extends AbstractHelpMojo { // Mojo parameters // ---------------------------------------------------------------------- - /** - * The current project, if there is one. This is listed as optional, since - * the help plugin should be able to function on its own. If this - * parameter is empty at execution time, this Mojo will instead use the - * super-project. - */ - @org.apache.maven.plugins.annotations.Parameter(defaultValue = "${project}", readonly = true, required = true) - private MavenProject project; - /** * The Maven Plugin to describe. This must be specified in one of three ways: *
@@ -389,8 +380,8 @@ private void describePlugin(PluginDescriptor pd, StringBuilder buffer) // Can be null because of MPLUGIN-137 (and descriptors generated with maven-plugin-tools-api <= 2.4.3) Artifact aetherArtifact = new DefaultArtifact(pd.getGroupId(), pd.getArtifactId(), "jar", pd.getVersion()); ProjectBuildingRequest pbr = new DefaultProjectBuildingRequest(session.getProjectBuildingRequest()); - pbr.setRemoteRepositories(remoteRepositories); - pbr.setLocalRepository(localRepository); + pbr.setRemoteRepositories(project.getRemoteArtifactRepositories()); + pbr.setPluginArtifactRepositories(project.getPluginArtifactRepositories()); pbr.setProject(null); pbr.setValidationLevel(ModelBuildingRequest.VALIDATION_LEVEL_MINIMAL); try { @@ -733,7 +724,6 @@ private boolean describeCommand(StringBuilder descriptionBuffer) throws MojoExec * @return The sequence of display lines, never null. * @throws MojoFailureException if any can not invoke the method * @throws MojoExecutionException if no line was found for text - * @see HelpMojo#toLines(String, int, int, int) */ private static List toLines(String text, int indent, int indentSize, int lineLength) throws MojoFailureException, MojoExecutionException { @@ -864,7 +854,8 @@ private boolean isReportGoal(MojoDescriptor md) { PluginDescriptor pd = md.getPluginDescriptor(); List urls = new ArrayList<>(); ProjectBuildingRequest pbr = new DefaultProjectBuildingRequest(session.getProjectBuildingRequest()); - pbr.setRemoteRepositories(remoteRepositories); + pbr.setRemoteRepositories(project.getRemoteArtifactRepositories()); + pbr.setPluginArtifactRepositories(project.getPluginArtifactRepositories()); pbr.setResolveDependencies(true); pbr.setProject(null); pbr.setValidationLevel(ModelBuildingRequest.VALIDATION_LEVEL_MINIMAL); 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 718d59e8..a9b0ce5d 100644 --- a/src/main/java/org/apache/maven/plugins/help/EffectivePomMojo.java +++ b/src/main/java/org/apache/maven/plugins/help/EffectivePomMojo.java @@ -58,14 +58,6 @@ public class EffectivePomMojo extends AbstractEffectiveMojo { // Mojo parameters // ---------------------------------------------------------------------- - /** - * The Maven project. - * - * @since 2.0.2 - */ - @Parameter(defaultValue = "${project}", readonly = true, required = true) - private MavenProject project; - /** * The projects in the current build. The effective-POM for * each of these projects will written. 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 e67cc455..f4dea134 100644 --- a/src/main/java/org/apache/maven/plugins/help/EvaluateMojo.java +++ b/src/main/java/org/apache/maven/plugins/help/EvaluateMojo.java @@ -131,12 +131,6 @@ public class EvaluateMojo extends AbstractHelpMojo { @Parameter(property = "expression") private String expression; - /** - * Maven project built from the given {@link #artifact}. Otherwise, the current Maven project or the super pom. - */ - @Parameter(defaultValue = "${project}", readonly = true, required = true) - private MavenProject project; - /** * The system settings for Maven. */ diff --git a/src/test/java/org/apache/maven/plugins/help/DescribeMojoTest.java b/src/test/java/org/apache/maven/plugins/help/DescribeMojoTest.java index 9250ba79..0d2c140a 100644 --- a/src/test/java/org/apache/maven/plugins/help/DescribeMojoTest.java +++ b/src/test/java/org/apache/maven/plugins/help/DescribeMojoTest.java @@ -241,7 +241,7 @@ public void testLookupPluginDescriptorPrefixWithoutVersion() throws Throwable { writeDeclaredField(mojo, "pluginVersionResolver", pluginVersionResolver, true); writeDeclaredField(mojo, "pluginManager", pluginManager, true); writeField(mojo, "session", session, true); - writeDeclaredField(mojo, "project", new MavenProject(), true); + writeField(mojo, "project", new MavenProject(), true); when(mojoDescriptorCreator.findPluginForPrefix("help", session)).thenReturn(plugin); when(pluginVersionResolver.resolve(any(PluginVersionRequest.class))).thenReturn(versionResult); when(versionResult.getVersion()).thenReturn("1.0");