You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@maven.apache.org by sj...@apache.org on 2023/03/10 07:02:58 UTC

[maven-help-plugin] branch MPH-195 created (now b14c089)

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

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


      at b14c089  [MPH-195] Get rid of localRepository from mojo parameter

This branch includes the following new commits:

     new b14c089  [MPH-195] Get rid of localRepository from mojo parameter

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.



[maven-help-plugin] 01/01: [MPH-195] Get rid of localRepository from mojo parameter

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

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

commit b14c089e664b01ca270898d99bc2c35c6f3a8644
Author: Slawomir Jaranowski <s....@gmail.com>
AuthorDate: Fri Mar 10 07:53:51 2023 +0100

    [MPH-195] Get rid of localRepository from mojo parameter
---
 .../maven/plugins/help/AbstractHelpMojo.java       | 37 ++++++----------------
 .../apache/maven/plugins/help/DescribeMojo.java    | 15 ++-------
 .../maven/plugins/help/EffectivePomMojo.java       |  8 -----
 .../apache/maven/plugins/help/EvaluateMojo.java    |  6 ----
 .../maven/plugins/help/DescribeMojoTest.java       |  2 +-
 5 files changed, 13 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 4e3249a..d9512f1 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 @@ package org.apache.maven.plugins.help;
 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.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;
@@ -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<ArtifactRepository> remoteRepositories;
-
-    /**
-     * Plugin repositories used for the project.
-     */
-    @Parameter(defaultValue = "${project.pluginArtifactRepositories}", required = true, readonly = true)
-    protected List<ArtifactRepository> 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 @@ public abstract class AbstractHelpMojo extends AbstractMojo {
     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 @@ public abstract class AbstractHelpMojo extends AbstractMojo {
 
     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();
+        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 fe3613d..3bf1a65 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:
      * <br/>
@@ -389,8 +380,8 @@ public class DescribeMojo extends AbstractHelpMojo {
             // 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 @@ public class DescribeMojo extends AbstractHelpMojo {
      * @return The sequence of display lines, never <code>null</code>.
      * @throws MojoFailureException   if any can not invoke the method
      * @throws MojoExecutionException if no line was found for <code>text</code>
-     * @see HelpMojo#toLines(String, int, int, int)
      */
     private static List<String> toLines(String text, int indent, int indentSize, int lineLength)
             throws MojoFailureException, MojoExecutionException {
@@ -864,7 +854,6 @@ public class DescribeMojo extends AbstractHelpMojo {
         PluginDescriptor pd = md.getPluginDescriptor();
         List<URL> urls = new ArrayList<>();
         ProjectBuildingRequest pbr = new DefaultProjectBuildingRequest(session.getProjectBuildingRequest());
-        pbr.setRemoteRepositories(remoteRepositories);
         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 718d59e..a9b0ce5 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 e67cc45..f4dea13 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 9250ba7..0d2c140 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 class DescribeMojoTest {
         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");