From 70e89d7a2fbe93138812a201f4be272b382f0132 Mon Sep 17 00:00:00 2001 From: Elliotte Rusty Harold Date: Thu, 21 Nov 2024 15:07:33 -0500 Subject: [PATCH 1/5] Use Sisu Guice instead of Plexus --- .../maven/plugins/help/DescribeMojo.java | 16 ++++++++ .../maven/plugins/help/EvaluateMojo.java | 39 +++++++++++-------- 2 files changed, 39 insertions(+), 16 deletions(-) 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 19a8118..12f1439 100644 --- a/src/main/java/org/apache/maven/plugins/help/DescribeMojo.java +++ b/src/main/java/org/apache/maven/plugins/help/DescribeMojo.java @@ -32,6 +32,8 @@ import java.util.regex.Pattern; import java.util.stream.Collectors; +import javax.inject.Inject; + import org.apache.maven.RepositoryUtils; import org.apache.maven.lifecycle.DefaultLifecycles; import org.apache.maven.lifecycle.Lifecycle; @@ -126,6 +128,19 @@ public class DescribeMojo extends AbstractHelpMojo { @Component private Map lifecycleMappings; + @Inject + public DescribeMojo(MavenPluginManager pluginManager, + MojoDescriptorCreator mojoDescriptorCreator, + PluginVersionResolver pluginVersionResolver, + DefaultLifecycles defaultLifecycles, + Map lifecycleMappings) { + this.pluginManager = pluginManager; + this.mojoDescriptorCreator = mojoDescriptorCreator; + this.pluginVersionResolver = pluginVersionResolver; + this.defaultLifecycles = defaultLifecycles; + this.lifecycleMappings = lifecycleMappings; + } + // ---------------------------------------------------------------------- // Mojo parameters // ---------------------------------------------------------------------- @@ -209,6 +224,7 @@ public class DescribeMojo extends AbstractHelpMojo { /** * {@inheritDoc} */ + @Override public void execute() throws MojoExecutionException, MojoFailureException { StringBuilder descriptionBuffer = new StringBuilder(); 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 975fd8a..3118f32 100644 --- a/src/main/java/org/apache/maven/plugins/help/EvaluateMojo.java +++ b/src/main/java/org/apache/maven/plugins/help/EvaluateMojo.java @@ -31,6 +31,8 @@ import java.util.jar.JarEntry; import java.util.jar.JarInputStream; +import javax.inject.Inject; + import com.thoughtworks.xstream.XStream; import com.thoughtworks.xstream.converters.MarshallingContext; import com.thoughtworks.xstream.converters.collections.PropertiesConverter; @@ -44,7 +46,6 @@ import org.apache.maven.plugin.MojoFailureException; import org.apache.maven.plugin.PluginParameterExpressionEvaluator; 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.MavenProject; @@ -65,21 +66,6 @@ */ @Mojo(name = "evaluate", requiresProject = false) public class EvaluateMojo extends AbstractHelpMojo { - // ---------------------------------------------------------------------- - // Mojo components - // ---------------------------------------------------------------------- - - /** - * Input handler, needed for command line handling. - */ - @Component - private InputHandler inputHandler; - - /** - * Component used to get mojo descriptors. - */ - @Component - private MojoDescriptorCreator mojoDescriptorCreator; // ---------------------------------------------------------------------- // Mojo parameters @@ -145,11 +131,32 @@ public class EvaluateMojo extends AbstractHelpMojo { /** lazy loading xstream variable */ private XStream xstream; + // ---------------------------------------------------------------------- + // Mojo components + // ---------------------------------------------------------------------- + + /** + * Input handler, needed for command line handling. + */ + private InputHandler inputHandler; + + /** + * Component used to get mojo descriptors. + */ + private MojoDescriptorCreator mojoDescriptorCreator; + + @Inject + public EvaluateMojo(InputHandler inputHandler, MojoDescriptorCreator mojoDescriptorCreator) { + this.inputHandler = inputHandler; + this.mojoDescriptorCreator = mojoDescriptorCreator; + } + // ---------------------------------------------------------------------- // Public methods // ---------------------------------------------------------------------- /** {@inheritDoc} */ + @Override public void execute() throws MojoExecutionException, MojoFailureException { if (expression == null && !settings.isInteractiveMode()) { From cd696b9a2a667a51c3c9f6fa0fbdabebccb58290 Mon Sep 17 00:00:00 2001 From: Elliotte Rusty Harold Date: Thu, 21 Nov 2024 15:08:37 -0500 Subject: [PATCH 2/5] spotless --- .../java/org/apache/maven/plugins/help/DescribeMojo.java | 7 ++++--- .../java/org/apache/maven/plugins/help/EvaluateMojo.java | 4 ++-- 2 files changed, 6 insertions(+), 5 deletions(-) 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 12f1439..3e37b6e 100644 --- a/src/main/java/org/apache/maven/plugins/help/DescribeMojo.java +++ b/src/main/java/org/apache/maven/plugins/help/DescribeMojo.java @@ -18,6 +18,8 @@ */ package org.apache.maven.plugins.help; +import javax.inject.Inject; + import java.io.File; import java.io.IOException; import java.lang.reflect.InvocationTargetException; @@ -32,8 +34,6 @@ import java.util.regex.Pattern; import java.util.stream.Collectors; -import javax.inject.Inject; - import org.apache.maven.RepositoryUtils; import org.apache.maven.lifecycle.DefaultLifecycles; import org.apache.maven.lifecycle.Lifecycle; @@ -129,7 +129,8 @@ public class DescribeMojo extends AbstractHelpMojo { private Map lifecycleMappings; @Inject - public DescribeMojo(MavenPluginManager pluginManager, + public DescribeMojo( + MavenPluginManager pluginManager, MojoDescriptorCreator mojoDescriptorCreator, PluginVersionResolver pluginVersionResolver, DefaultLifecycles defaultLifecycles, 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 3118f32..07a1c51 100644 --- a/src/main/java/org/apache/maven/plugins/help/EvaluateMojo.java +++ b/src/main/java/org/apache/maven/plugins/help/EvaluateMojo.java @@ -18,6 +18,8 @@ */ package org.apache.maven.plugins.help; +import javax.inject.Inject; + import java.io.File; import java.io.FileInputStream; import java.io.IOException; @@ -31,8 +33,6 @@ import java.util.jar.JarEntry; import java.util.jar.JarInputStream; -import javax.inject.Inject; - import com.thoughtworks.xstream.XStream; import com.thoughtworks.xstream.converters.MarshallingContext; import com.thoughtworks.xstream.converters.collections.PropertiesConverter; From e0d7604cd191a0d6035f33b9a44fee9540e35817 Mon Sep 17 00:00:00 2001 From: Elliotte Rusty Harold Date: Thu, 21 Nov 2024 15:16:26 -0500 Subject: [PATCH 3/5] pom --- pom.xml | 10 +++++++ .../maven/plugins/help/DescribeMojoTest.java | 26 +++++++++---------- 2 files changed, 23 insertions(+), 13 deletions(-) diff --git a/pom.xml b/pom.xml index f409b4c..8117275 100644 --- a/pom.xml +++ b/pom.xml @@ -114,6 +114,16 @@ ${resolverVersion} provided + + javax.inject + javax.inject + 1 + + + org.eclipse.sisu + org.eclipse.sisu.plexus + provided + 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 135ad5b..c7f443d 100644 --- a/src/test/java/org/apache/maven/plugins/help/DescribeMojoTest.java +++ b/src/test/java/org/apache/maven/plugins/help/DescribeMojoTest.java @@ -53,7 +53,7 @@ public class DescribeMojoTest { @Test public void testGetExpressionsRoot() { try { - DescribeMojo describeMojo = new DescribeMojo(); + DescribeMojo describeMojo = new DescribeMojo(null, null, null, null, null); Method toLines = describeMojo.getClass().getDeclaredMethod("toLines", String.class, int.class, int.class, int.class); toLines.setAccessible(true); @@ -78,7 +78,7 @@ public void testValidExpression() throws Exception { Method describeMojoParameters = DescribeMojo.class.getDeclaredMethod( "describeMojoParameters", MojoDescriptor.class, StringBuilder.class); describeMojoParameters.setAccessible(true); - describeMojoParameters.invoke(new DescribeMojo(), md, sb); + describeMojoParameters.invoke(new DescribeMojo(null, null, null, null, null), md, sb); assertEquals( " Available parameters:" + ls + ls + " name" + ls + " User property: valid.expression" + ls @@ -104,7 +104,7 @@ public void testInvalidExpression() throws Exception { Method describeMojoParameters = DescribeMojo.class.getDeclaredMethod( "describeMojoParameters", MojoDescriptor.class, StringBuilder.class); describeMojoParameters.setAccessible(true); - describeMojoParameters.invoke(new DescribeMojo(), md, sb); + describeMojoParameters.invoke(new DescribeMojo(null, null, null, null, null), md, sb); assertEquals( " Available parameters:" + ls + ls @@ -120,7 +120,7 @@ public void testInvalidExpression() throws Exception { @Test public void testParsePluginInfoGAV() throws Throwable { - DescribeMojo mojo = new DescribeMojo(); + DescribeMojo mojo = new DescribeMojo(null, null, null, null, null); setFieldWithReflection(mojo, "groupId", "org.test"); setFieldWithReflection(mojo, "artifactId", "test"); setFieldWithReflection(mojo, "version", "1.0"); @@ -136,7 +136,7 @@ public void testParsePluginInfoGAV() throws Throwable { @Test public void testParsePluginInfoPluginPrefix() throws Throwable { - DescribeMojo mojo = new DescribeMojo(); + DescribeMojo mojo = new DescribeMojo(null, null, null, null, null); setFieldWithReflection(mojo, "plugin", "help"); Method parsePluginLookupInfo = setParsePluginLookupInfoAccessibility(); @@ -156,7 +156,7 @@ public void testParsePluginInfoPluginPrefix() throws Throwable { @Test public void testParsePluginInfoPluginGA() throws Throwable { - DescribeMojo mojo = new DescribeMojo(); + DescribeMojo mojo = new DescribeMojo(null, null, null, null, null); setFieldWithReflection(mojo, "plugin", "org.test:test"); Method parsePluginLookupInfo = setParsePluginLookupInfoAccessibility(); @@ -170,7 +170,7 @@ public void testParsePluginInfoPluginGA() throws Throwable { @Test public void testParsePluginInfoPluginGAV() throws Throwable { - DescribeMojo mojo = new DescribeMojo(); + DescribeMojo mojo = new DescribeMojo(null, null, null, null, null); setFieldWithReflection(mojo, "plugin", "org.test:test:1.0"); Method parsePluginLookupInfo = setParsePluginLookupInfoAccessibility(); @@ -184,7 +184,7 @@ public void testParsePluginInfoPluginGAV() throws Throwable { @Test public void testParsePluginInfoPluginIncorrect() throws Throwable { - DescribeMojo mojo = new DescribeMojo(); + DescribeMojo mojo = new DescribeMojo(null, null, null, null, null); setFieldWithReflection(mojo, "plugin", "org.test:test:1.0:invalid"); try { Method parsePluginLookupInfo = setParsePluginLookupInfoAccessibility(); @@ -197,7 +197,7 @@ public void testParsePluginInfoPluginIncorrect() throws Throwable { @Test public void testLookupPluginDescriptorPrefixWithVersion() throws Throwable { - DescribeMojo mojo = new DescribeMojo(); + DescribeMojo mojo = new DescribeMojo(null, null, null, null, null); PluginInfo pi = new PluginInfo(); pi.setPrefix("help"); @@ -239,7 +239,7 @@ public void testLookupPluginDescriptorPrefixWithVersion() throws Throwable { @Test public void testLookupPluginDescriptorPrefixWithoutVersion() throws Throwable { - DescribeMojo mojo = new DescribeMojo(); + DescribeMojo mojo = new DescribeMojo(null, null, null, null, null); PluginInfo pi = new PluginInfo(); pi.setPrefix("help"); @@ -285,7 +285,7 @@ public void testLookupPluginDescriptorPrefixWithoutVersion() throws Throwable { @Test public void testLookupPluginDescriptorGAV() throws Throwable { - DescribeMojo mojo = new DescribeMojo(); + DescribeMojo mojo = new DescribeMojo(null, null, null, null, null); PluginInfo pi = new PluginInfo(); pi.setGroupId("org.test"); @@ -323,7 +323,7 @@ public void testLookupPluginDescriptorGAV() throws Throwable { @Test public void testLookupPluginDescriptorGMissingA() { - DescribeMojo mojo = new DescribeMojo(); + DescribeMojo mojo = new DescribeMojo(null, null, null, null, null); PluginInfo pi = new PluginInfo(); pi.setGroupId("org.test"); try { @@ -339,7 +339,7 @@ public void testLookupPluginDescriptorGMissingA() { @Test public void testLookupPluginDescriptorAMissingG() { - DescribeMojo mojo = new DescribeMojo(); + DescribeMojo mojo = new DescribeMojo(null, null, null, null, null); PluginInfo pi = new PluginInfo(); pi.setArtifactId("test"); try { From 13b94da6f2518152bba911715841d302f82170d1 Mon Sep 17 00:00:00 2001 From: Elliotte Rusty Harold Date: Sat, 7 Dec 2024 06:41:32 -0500 Subject: [PATCH 4/5] inject --- .../apache/maven/plugins/help/DescribeMojo.java | 16 +++++----------- 1 file changed, 5 insertions(+), 11 deletions(-) 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 1fb9891..ecd5f9b 100644 --- a/src/main/java/org/apache/maven/plugins/help/DescribeMojo.java +++ b/src/main/java/org/apache/maven/plugins/help/DescribeMojo.java @@ -52,7 +52,6 @@ import org.apache.maven.plugin.version.PluginVersionResolutionException; import org.apache.maven.plugin.version.PluginVersionResolver; import org.apache.maven.plugin.version.PluginVersionResult; -import org.apache.maven.plugins.annotations.Component; import org.apache.maven.plugins.annotations.Mojo; import org.apache.maven.project.DefaultProjectBuildingRequest; import org.apache.maven.project.MavenProject; @@ -101,32 +100,27 @@ public class DescribeMojo extends AbstractHelpMojo { /** * Component used to get a plugin descriptor from a given plugin. */ - @Component - protected MavenPluginManager pluginManager; + protected final MavenPluginManager pluginManager; /** * Component used to get a plugin by its prefix and get mojo descriptors. */ - @Component - private MojoDescriptorCreator mojoDescriptorCreator; + private final MojoDescriptorCreator mojoDescriptorCreator; /** * Component used to resolve the version for a plugin. */ - @Component - private PluginVersionResolver pluginVersionResolver; + private final PluginVersionResolver pluginVersionResolver; /** * The Maven default built-in lifecycles. */ - @Component - private DefaultLifecycles defaultLifecycles; + private final DefaultLifecycles defaultLifecycles; /** * A map from each packaging to its lifecycle mapping. */ - @Component - private Map lifecycleMappings; + private final Map lifecycleMappings; @Inject public DescribeMojo( From b1aad538c82e0e09e52dc029463f2001358e34b1 Mon Sep 17 00:00:00 2001 From: Elliotte Rusty Harold Date: Sat, 7 Dec 2024 07:06:28 -0500 Subject: [PATCH 5/5] more inject --- .../plugins/help/AbstractEffectiveMojo.java | 7 ++ .../maven/plugins/help/AbstractHelpMojo.java | 28 +++--- .../plugins/help/ActiveProfilesMojo.java | 10 ++ .../maven/plugins/help/AllProfilesMojo.java | 10 ++ .../maven/plugins/help/DescribeMojo.java | 6 ++ .../maven/plugins/help/EffectivePomMojo.java | 9 ++ .../plugins/help/EffectiveSettingsMojo.java | 10 ++ .../maven/plugins/help/EvaluateMojo.java | 9 +- .../apache/maven/plugins/help/SystemMojo.java | 11 +++ .../maven/plugins/help/DescribeMojoTest.java | 93 ++++++++----------- 10 files changed, 126 insertions(+), 67 deletions(-) diff --git a/src/main/java/org/apache/maven/plugins/help/AbstractEffectiveMojo.java b/src/main/java/org/apache/maven/plugins/help/AbstractEffectiveMojo.java index ff4e29e..4bb3099 100644 --- a/src/main/java/org/apache/maven/plugins/help/AbstractEffectiveMojo.java +++ b/src/main/java/org/apache/maven/plugins/help/AbstractEffectiveMojo.java @@ -33,8 +33,10 @@ import java.util.Properties; import java.util.Set; +import org.apache.maven.project.ProjectBuilder; import org.codehaus.plexus.util.xml.XMLWriter; import org.codehaus.plexus.util.xml.XmlWriterUtil; +import org.eclipse.aether.RepositorySystem; import org.jdom2.Document; import org.jdom2.JDOMException; import org.jdom2.input.SAXBuilder; @@ -48,6 +50,11 @@ * @since 2.1 */ public abstract class AbstractEffectiveMojo extends AbstractHelpMojo { + + protected AbstractEffectiveMojo(ProjectBuilder projectBuilder, RepositorySystem repositorySystem) { + super(projectBuilder, repositorySystem); + } + /** * Utility method to write an XML content to a given file. * 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 b0135dd..4217875 100644 --- a/src/main/java/org/apache/maven/plugins/help/AbstractHelpMojo.java +++ b/src/main/java/org/apache/maven/plugins/help/AbstractHelpMojo.java @@ -28,7 +28,6 @@ import org.apache.maven.model.building.ModelBuildingRequest; import org.apache.maven.plugin.AbstractMojo; import org.apache.maven.plugin.MojoExecutionException; -import org.apache.maven.plugins.annotations.Component; import org.apache.maven.plugins.annotations.Parameter; import org.apache.maven.project.DefaultProjectBuildingRequest; import org.apache.maven.project.MavenProject; @@ -55,18 +54,6 @@ public abstract class AbstractHelpMojo extends AbstractMojo { /** The line separator for the current OS. */ protected static final String LS = System.getProperty("line.separator"); - /** - * Maven Project Builder component. - */ - @Component - protected ProjectBuilder projectBuilder; - - /** - * Component used to resolve artifacts and download their files from remote repositories. - */ - @Component - protected RepositorySystem repositorySystem; - /** * Current Maven project. */ @@ -89,6 +76,21 @@ public abstract class AbstractHelpMojo extends AbstractMojo { @Parameter(property = "output") protected File output; + /** + * Maven Project Builder component. + */ + protected final ProjectBuilder projectBuilder; + + /** + * Component used to resolve artifacts and download their files from remote repositories. + */ + protected final RepositorySystem repositorySystem; + + protected AbstractHelpMojo(ProjectBuilder projectBuilder, RepositorySystem repositorySystem) { + this.projectBuilder = projectBuilder; + this.repositorySystem = repositorySystem; + } + /** * Utility method to write a content to a given file. * diff --git a/src/main/java/org/apache/maven/plugins/help/ActiveProfilesMojo.java b/src/main/java/org/apache/maven/plugins/help/ActiveProfilesMojo.java index fdbecab..2f56cc6 100644 --- a/src/main/java/org/apache/maven/plugins/help/ActiveProfilesMojo.java +++ b/src/main/java/org/apache/maven/plugins/help/ActiveProfilesMojo.java @@ -18,6 +18,8 @@ */ package org.apache.maven.plugins.help; +import javax.inject.Inject; + import java.io.IOException; import java.util.List; import java.util.Map; @@ -26,6 +28,8 @@ import org.apache.maven.plugins.annotations.Mojo; import org.apache.maven.plugins.annotations.Parameter; import org.apache.maven.project.MavenProject; +import org.apache.maven.project.ProjectBuilder; +import org.eclipse.aether.RepositorySystem; /** * Displays a list of the profiles which are currently active for this build. @@ -44,11 +48,17 @@ public class ActiveProfilesMojo extends AbstractHelpMojo { @Parameter(defaultValue = "${reactorProjects}", required = true, readonly = true) private List projects; + @Inject + public ActiveProfilesMojo(ProjectBuilder projectBuilder, RepositorySystem repositorySystem) { + super(projectBuilder, repositorySystem); + } + // ---------------------------------------------------------------------- // Public methods // ---------------------------------------------------------------------- /** {@inheritDoc} */ + @Override public void execute() throws MojoExecutionException { StringBuilder message = new StringBuilder(); diff --git a/src/main/java/org/apache/maven/plugins/help/AllProfilesMojo.java b/src/main/java/org/apache/maven/plugins/help/AllProfilesMojo.java index 3d38916..2352bae 100644 --- a/src/main/java/org/apache/maven/plugins/help/AllProfilesMojo.java +++ b/src/main/java/org/apache/maven/plugins/help/AllProfilesMojo.java @@ -18,6 +18,8 @@ */ package org.apache.maven.plugins.help; +import javax.inject.Inject; + import java.io.IOException; import java.util.HashMap; import java.util.List; @@ -29,7 +31,9 @@ import org.apache.maven.plugins.annotations.Mojo; import org.apache.maven.plugins.annotations.Parameter; import org.apache.maven.project.MavenProject; +import org.apache.maven.project.ProjectBuilder; import org.apache.maven.settings.SettingsUtils; +import org.eclipse.aether.RepositorySystem; /** * Displays a list of available profiles under the current project. @@ -59,11 +63,17 @@ public class AllProfilesMojo extends AbstractHelpMojo { @Parameter(defaultValue = "${settings.profiles}", readonly = true, required = true) private List settingsProfiles; + @Inject + public AllProfilesMojo(ProjectBuilder projectBuilder, RepositorySystem repositorySystem) { + super(projectBuilder, repositorySystem); + } + // ---------------------------------------------------------------------- // Public methods // ---------------------------------------------------------------------- /** {@inheritDoc} */ + @Override public void execute() throws MojoExecutionException, MojoFailureException { StringBuilder descriptionBuffer = new StringBuilder(); 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 ecd5f9b..33a0151 100644 --- a/src/main/java/org/apache/maven/plugins/help/DescribeMojo.java +++ b/src/main/java/org/apache/maven/plugins/help/DescribeMojo.java @@ -55,11 +55,13 @@ import org.apache.maven.plugins.annotations.Mojo; 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.reporting.MavenReport; import org.apache.maven.shared.utils.logging.MessageUtils; import org.apache.maven.tools.plugin.generator.HtmlToPlainTextConverter; import org.codehaus.plexus.util.StringUtils; +import org.eclipse.aether.RepositorySystem; import org.eclipse.aether.artifact.Artifact; import org.eclipse.aether.artifact.DefaultArtifact; @@ -124,11 +126,15 @@ public class DescribeMojo extends AbstractHelpMojo { @Inject public DescribeMojo( + ProjectBuilder projectBuilder, + RepositorySystem repositorySystem, MavenPluginManager pluginManager, MojoDescriptorCreator mojoDescriptorCreator, PluginVersionResolver pluginVersionResolver, DefaultLifecycles defaultLifecycles, Map lifecycleMappings) { + + super(projectBuilder, repositorySystem); this.pluginManager = pluginManager; this.mojoDescriptorCreator = mojoDescriptorCreator; this.pluginVersionResolver = pluginVersionResolver; 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 c38e2c5..4fa115c 100644 --- a/src/main/java/org/apache/maven/plugins/help/EffectivePomMojo.java +++ b/src/main/java/org/apache/maven/plugins/help/EffectivePomMojo.java @@ -18,6 +18,8 @@ */ package org.apache.maven.plugins.help; +import javax.inject.Inject; + import java.io.IOException; import java.io.StringWriter; import java.util.Collections; @@ -35,11 +37,13 @@ import org.apache.maven.plugins.annotations.Mojo; import org.apache.maven.plugins.annotations.Parameter; import org.apache.maven.project.MavenProject; +import org.apache.maven.project.ProjectBuilder; import org.apache.maven.shared.utils.logging.MessageUtils; import org.codehaus.plexus.util.StringUtils; import org.codehaus.plexus.util.xml.PrettyPrintXMLWriter; import org.codehaus.plexus.util.xml.XMLWriter; import org.codehaus.plexus.util.xml.XmlWriterUtil; +import org.eclipse.aether.RepositorySystem; /** * Displays the effective POM as an XML for this build, with the active profiles factored in, or a specified artifact. @@ -85,6 +89,11 @@ public class EffectivePomMojo extends AbstractEffectiveMojo { @Parameter(property = "verbose", defaultValue = "false") private boolean verbose = false; + @Inject + public EffectivePomMojo(ProjectBuilder projectBuilder, RepositorySystem repositorySystem) { + super(projectBuilder, repositorySystem); + } + // ---------------------------------------------------------------------- // Public methods // ---------------------------------------------------------------------- diff --git a/src/main/java/org/apache/maven/plugins/help/EffectiveSettingsMojo.java b/src/main/java/org/apache/maven/plugins/help/EffectiveSettingsMojo.java index cf23708..cec9a80 100644 --- a/src/main/java/org/apache/maven/plugins/help/EffectiveSettingsMojo.java +++ b/src/main/java/org/apache/maven/plugins/help/EffectiveSettingsMojo.java @@ -18,6 +18,8 @@ */ package org.apache.maven.plugins.help; +import javax.inject.Inject; + import java.io.IOException; import java.io.StringWriter; import java.net.InetAddress; @@ -29,6 +31,7 @@ import org.apache.maven.plugin.MojoExecutionException; import org.apache.maven.plugins.annotations.Mojo; import org.apache.maven.plugins.annotations.Parameter; +import org.apache.maven.project.ProjectBuilder; import org.apache.maven.settings.Profile; import org.apache.maven.settings.Proxy; import org.apache.maven.settings.Server; @@ -39,6 +42,7 @@ import org.codehaus.plexus.util.xml.PrettyPrintXMLWriter; import org.codehaus.plexus.util.xml.XMLWriter; import org.codehaus.plexus.util.xml.XmlWriterUtil; +import org.eclipse.aether.RepositorySystem; /** * Displays the calculated settings as XML for this project, given any profile enhancement and the inheritance @@ -67,11 +71,17 @@ public class EffectiveSettingsMojo extends AbstractEffectiveMojo { @Parameter(property = "showPasswords", defaultValue = "false") private boolean showPasswords; + @Inject + public EffectiveSettingsMojo(ProjectBuilder projectBuilder, RepositorySystem repositorySystem) { + super(projectBuilder, repositorySystem); + } + // ---------------------------------------------------------------------- // Public methods // ---------------------------------------------------------------------- /** {@inheritDoc} */ + @Override public void execute() throws MojoExecutionException { Settings copySettings; if (showPasswords) { 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 07a1c51..84dd67d 100644 --- a/src/main/java/org/apache/maven/plugins/help/EvaluateMojo.java +++ b/src/main/java/org/apache/maven/plugins/help/EvaluateMojo.java @@ -49,12 +49,14 @@ import org.apache.maven.plugins.annotations.Mojo; import org.apache.maven.plugins.annotations.Parameter; import org.apache.maven.project.MavenProject; +import org.apache.maven.project.ProjectBuilder; import org.apache.maven.settings.Settings; import org.apache.maven.settings.io.xpp3.SettingsXpp3Writer; import org.codehaus.plexus.component.configurator.expression.ExpressionEvaluationException; import org.codehaus.plexus.components.interactivity.InputHandler; import org.codehaus.plexus.util.StringUtils; import org.eclipse.aether.RepositoryException; +import org.eclipse.aether.RepositorySystem; import org.eclipse.aether.artifact.Artifact; import org.eclipse.aether.artifact.DefaultArtifact; @@ -146,7 +148,12 @@ public class EvaluateMojo extends AbstractHelpMojo { private MojoDescriptorCreator mojoDescriptorCreator; @Inject - public EvaluateMojo(InputHandler inputHandler, MojoDescriptorCreator mojoDescriptorCreator) { + public EvaluateMojo( + ProjectBuilder projectBuilder, + RepositorySystem repositorySystem, + InputHandler inputHandler, + MojoDescriptorCreator mojoDescriptorCreator) { + super(projectBuilder, repositorySystem); this.inputHandler = inputHandler; this.mojoDescriptorCreator = mojoDescriptorCreator; } diff --git a/src/main/java/org/apache/maven/plugins/help/SystemMojo.java b/src/main/java/org/apache/maven/plugins/help/SystemMojo.java index d3552d4..d482145 100644 --- a/src/main/java/org/apache/maven/plugins/help/SystemMojo.java +++ b/src/main/java/org/apache/maven/plugins/help/SystemMojo.java @@ -18,13 +18,17 @@ */ package org.apache.maven.plugins.help; +import javax.inject.Inject; + import java.io.IOException; import java.util.Properties; import org.apache.maven.plugin.MojoExecutionException; import org.apache.maven.plugins.annotations.Mojo; +import org.apache.maven.project.ProjectBuilder; import org.codehaus.plexus.util.StringUtils; import org.codehaus.plexus.util.cli.CommandLineUtils; +import org.eclipse.aether.RepositorySystem; /** * Displays a list of the platform details like system properties and environment variables. @@ -34,6 +38,12 @@ */ @Mojo(name = "system", requiresProject = false) public class SystemMojo extends AbstractHelpMojo { + + @Inject + public SystemMojo(ProjectBuilder projectBuilder, RepositorySystem repositorySystem) { + super(projectBuilder, repositorySystem); + } + /** Magic number to beautify the output */ private static final int REPEAT = 25; @@ -42,6 +52,7 @@ public class SystemMojo extends AbstractHelpMojo { // ---------------------------------------------------------------------- /** {@inheritDoc} */ + @Override public void execute() throws MojoExecutionException { StringBuilder message = new StringBuilder(); 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 c7f443d..fe22060 100644 --- a/src/test/java/org/apache/maven/plugins/help/DescribeMojoTest.java +++ b/src/test/java/org/apache/maven/plugins/help/DescribeMojoTest.java @@ -46,21 +46,16 @@ * @author Vincent Siveton */ public class DescribeMojoTest { - /** - * Test method for {@link org.apache.maven.plugins.help.DescribeMojo#toLines(java.lang.String, int, int, int)}. - * - */ + @Test - public void testGetExpressionsRoot() { - try { - DescribeMojo describeMojo = new DescribeMojo(null, null, null, null, null); - Method toLines = - describeMojo.getClass().getDeclaredMethod("toLines", String.class, int.class, int.class, int.class); - toLines.setAccessible(true); - toLines.invoke(null, "", 2, 2, 80); - } catch (Throwable e) { - fail("The API changes"); - } + public void testGetExpressionsRoot() + throws NoSuchMethodException, SecurityException, IllegalAccessException, IllegalArgumentException, + InvocationTargetException { + DescribeMojo describeMojo = new DescribeMojo(null, null, null, null, null, null, null); + Method toLines = + describeMojo.getClass().getDeclaredMethod("toLines", String.class, int.class, int.class, int.class); + toLines.setAccessible(true); + toLines.invoke(null, "", 2, 2, 80); } @Test @@ -74,19 +69,15 @@ public void testValidExpression() throws Exception { String ls = System.getProperty("line.separator"); - try { - Method describeMojoParameters = DescribeMojo.class.getDeclaredMethod( - "describeMojoParameters", MojoDescriptor.class, StringBuilder.class); - describeMojoParameters.setAccessible(true); - describeMojoParameters.invoke(new DescribeMojo(null, null, null, null, null), md, sb); - - assertEquals( - " Available parameters:" + ls + ls + " name" + ls + " User property: valid.expression" + ls - + " (no description available)" + ls, - sb.toString()); - } catch (Throwable e) { - fail(e.getMessage()); - } + Method describeMojoParameters = DescribeMojo.class.getDeclaredMethod( + "describeMojoParameters", MojoDescriptor.class, StringBuilder.class); + describeMojoParameters.setAccessible(true); + describeMojoParameters.invoke(new DescribeMojo(null, null, null, null, null, null, null), md, sb); + + assertEquals( + " Available parameters:" + ls + ls + " name" + ls + " User property: valid.expression" + ls + + " (no description available)" + ls, + sb.toString()); } @Test @@ -100,27 +91,23 @@ public void testInvalidExpression() throws Exception { String ls = System.getProperty("line.separator"); - try { - Method describeMojoParameters = DescribeMojo.class.getDeclaredMethod( - "describeMojoParameters", MojoDescriptor.class, StringBuilder.class); - describeMojoParameters.setAccessible(true); - describeMojoParameters.invoke(new DescribeMojo(null, null, null, null, null), md, sb); - - assertEquals( - " Available parameters:" + ls + ls - + " name" - + ls + " Expression: ${project.build.directory}/generated-sources/foobar" - + ls + " (no description available)" - + ls, - sb.toString()); - } catch (Throwable e) { - fail(e.getMessage()); - } + Method describeMojoParameters = DescribeMojo.class.getDeclaredMethod( + "describeMojoParameters", MojoDescriptor.class, StringBuilder.class); + describeMojoParameters.setAccessible(true); + describeMojoParameters.invoke(new DescribeMojo(null, null, null, null, null, null, null), md, sb); + + assertEquals( + " Available parameters:" + ls + ls + + " name" + + ls + " Expression: ${project.build.directory}/generated-sources/foobar" + + ls + " (no description available)" + + ls, + sb.toString()); } @Test public void testParsePluginInfoGAV() throws Throwable { - DescribeMojo mojo = new DescribeMojo(null, null, null, null, null); + DescribeMojo mojo = new DescribeMojo(null, null, null, null, null, null, null); setFieldWithReflection(mojo, "groupId", "org.test"); setFieldWithReflection(mojo, "artifactId", "test"); setFieldWithReflection(mojo, "version", "1.0"); @@ -136,7 +123,7 @@ public void testParsePluginInfoGAV() throws Throwable { @Test public void testParsePluginInfoPluginPrefix() throws Throwable { - DescribeMojo mojo = new DescribeMojo(null, null, null, null, null); + DescribeMojo mojo = new DescribeMojo(null, null, null, null, null, null, null); setFieldWithReflection(mojo, "plugin", "help"); Method parsePluginLookupInfo = setParsePluginLookupInfoAccessibility(); @@ -156,7 +143,7 @@ public void testParsePluginInfoPluginPrefix() throws Throwable { @Test public void testParsePluginInfoPluginGA() throws Throwable { - DescribeMojo mojo = new DescribeMojo(null, null, null, null, null); + DescribeMojo mojo = new DescribeMojo(null, null, null, null, null, null, null); setFieldWithReflection(mojo, "plugin", "org.test:test"); Method parsePluginLookupInfo = setParsePluginLookupInfoAccessibility(); @@ -170,7 +157,7 @@ public void testParsePluginInfoPluginGA() throws Throwable { @Test public void testParsePluginInfoPluginGAV() throws Throwable { - DescribeMojo mojo = new DescribeMojo(null, null, null, null, null); + DescribeMojo mojo = new DescribeMojo(null, null, null, null, null, null, null); setFieldWithReflection(mojo, "plugin", "org.test:test:1.0"); Method parsePluginLookupInfo = setParsePluginLookupInfoAccessibility(); @@ -184,7 +171,7 @@ public void testParsePluginInfoPluginGAV() throws Throwable { @Test public void testParsePluginInfoPluginIncorrect() throws Throwable { - DescribeMojo mojo = new DescribeMojo(null, null, null, null, null); + DescribeMojo mojo = new DescribeMojo(null, null, null, null, null, null, null); setFieldWithReflection(mojo, "plugin", "org.test:test:1.0:invalid"); try { Method parsePluginLookupInfo = setParsePluginLookupInfoAccessibility(); @@ -197,7 +184,7 @@ public void testParsePluginInfoPluginIncorrect() throws Throwable { @Test public void testLookupPluginDescriptorPrefixWithVersion() throws Throwable { - DescribeMojo mojo = new DescribeMojo(null, null, null, null, null); + DescribeMojo mojo = new DescribeMojo(null, null, null, null, null, null, null); PluginInfo pi = new PluginInfo(); pi.setPrefix("help"); @@ -239,7 +226,7 @@ public void testLookupPluginDescriptorPrefixWithVersion() throws Throwable { @Test public void testLookupPluginDescriptorPrefixWithoutVersion() throws Throwable { - DescribeMojo mojo = new DescribeMojo(null, null, null, null, null); + DescribeMojo mojo = new DescribeMojo(null, null, null, null, null, null, null); PluginInfo pi = new PluginInfo(); pi.setPrefix("help"); @@ -285,7 +272,7 @@ public void testLookupPluginDescriptorPrefixWithoutVersion() throws Throwable { @Test public void testLookupPluginDescriptorGAV() throws Throwable { - DescribeMojo mojo = new DescribeMojo(null, null, null, null, null); + DescribeMojo mojo = new DescribeMojo(null, null, null, null, null, null, null); PluginInfo pi = new PluginInfo(); pi.setGroupId("org.test"); @@ -323,7 +310,7 @@ public void testLookupPluginDescriptorGAV() throws Throwable { @Test public void testLookupPluginDescriptorGMissingA() { - DescribeMojo mojo = new DescribeMojo(null, null, null, null, null); + DescribeMojo mojo = new DescribeMojo(null, null, null, null, null, null, null); PluginInfo pi = new PluginInfo(); pi.setGroupId("org.test"); try { @@ -339,7 +326,7 @@ public void testLookupPluginDescriptorGMissingA() { @Test public void testLookupPluginDescriptorAMissingG() { - DescribeMojo mojo = new DescribeMojo(null, null, null, null, null); + DescribeMojo mojo = new DescribeMojo(null, null, null, null, null, null, null); PluginInfo pi = new PluginInfo(); pi.setArtifactId("test"); try {