Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use Sisu Guice instead of Plexus #127

Merged
merged 6 commits into from
Dec 24, 2024
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,16 @@
<version>${resolverVersion}</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>javax.inject</groupId>
<artifactId>javax.inject</artifactId>
<version>1</version>
</dependency>
<dependency>
<groupId>org.eclipse.sisu</groupId>
<artifactId>org.eclipse.sisu.plexus</artifactId>
<scope>provided</scope>
</dependency>

<!-- maven plugin tools -->
<dependency>
Expand Down
17 changes: 17 additions & 0 deletions src/main/java/org/apache/maven/plugins/help/DescribeMojo.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -126,6 +128,20 @@ public class DescribeMojo extends AbstractHelpMojo {
@Component
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Component annotation should be removed and field can be final

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

private Map<String, LifecycleMapping> lifecycleMappings;

@Inject
public DescribeMojo(
MavenPluginManager pluginManager,
MojoDescriptorCreator mojoDescriptorCreator,
PluginVersionResolver pluginVersionResolver,
DefaultLifecycles defaultLifecycles,
Map<String, LifecycleMapping> lifecycleMappings) {
this.pluginManager = pluginManager;
this.mojoDescriptorCreator = mojoDescriptorCreator;
this.pluginVersionResolver = pluginVersionResolver;
this.defaultLifecycles = defaultLifecycles;
this.lifecycleMappings = lifecycleMappings;
}

// ----------------------------------------------------------------------
// Mojo parameters
// ----------------------------------------------------------------------
Expand Down Expand Up @@ -209,6 +225,7 @@ public class DescribeMojo extends AbstractHelpMojo {
/**
* {@inheritDoc}
*/
@Override
public void execute() throws MojoExecutionException, MojoFailureException {
StringBuilder descriptionBuffer = new StringBuilder();

Expand Down
39 changes: 23 additions & 16 deletions src/main/java/org/apache/maven/plugins/help/EvaluateMojo.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand All @@ -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
Expand Down Expand Up @@ -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()) {

Expand Down
26 changes: 13 additions & 13 deletions src/test/java/org/apache/maven/plugins/help/DescribeMojoTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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");
Expand All @@ -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();
Expand All @@ -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();
Expand All @@ -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();
Expand All @@ -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();
Expand All @@ -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");
Expand Down Expand Up @@ -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");
Expand Down Expand Up @@ -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");
Expand Down Expand Up @@ -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 {
Expand All @@ -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 {
Expand Down