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 all 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
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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.
*
Expand Down
28 changes: 15 additions & 13 deletions src/main/java/org/apache/maven/plugins/help/AbstractHelpMojo.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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.
*/
Expand All @@ -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.
*
Expand Down
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.IOException;
import java.util.List;
import java.util.Map;
Expand All @@ -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.
Expand All @@ -44,11 +48,17 @@ public class ActiveProfilesMojo extends AbstractHelpMojo {
@Parameter(defaultValue = "${reactorProjects}", required = true, readonly = true)
private List<MavenProject> projects;

@Inject
public ActiveProfilesMojo(ProjectBuilder projectBuilder, RepositorySystem repositorySystem) {
super(projectBuilder, repositorySystem);
}

// ----------------------------------------------------------------------
// Public methods
// ----------------------------------------------------------------------

/** {@inheritDoc} */
@Override
public void execute() throws MojoExecutionException {
StringBuilder message = new StringBuilder();

Expand Down
10 changes: 10 additions & 0 deletions src/main/java/org/apache/maven/plugins/help/AllProfilesMojo.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.IOException;
import java.util.HashMap;
import java.util.List;
Expand All @@ -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.
Expand Down Expand Up @@ -59,11 +63,17 @@ public class AllProfilesMojo extends AbstractHelpMojo {
@Parameter(defaultValue = "${settings.profiles}", readonly = true, required = true)
private List<org.apache.maven.settings.Profile> 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();

Expand Down
38 changes: 27 additions & 11 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 @@ -50,15 +52,16 @@
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;
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;

Expand Down Expand Up @@ -99,32 +102,45 @@ 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<String, LifecycleMapping> lifecycleMappings;
private final Map<String, LifecycleMapping> lifecycleMappings;

@Inject
public DescribeMojo(
ProjectBuilder projectBuilder,
RepositorySystem repositorySystem,
MavenPluginManager pluginManager,
MojoDescriptorCreator mojoDescriptorCreator,
PluginVersionResolver pluginVersionResolver,
DefaultLifecycles defaultLifecycles,
Map<String, LifecycleMapping> lifecycleMappings) {

super(projectBuilder, repositorySystem);
this.pluginManager = pluginManager;
this.mojoDescriptorCreator = mojoDescriptorCreator;
this.pluginVersionResolver = pluginVersionResolver;
this.defaultLifecycles = defaultLifecycles;
this.lifecycleMappings = lifecycleMappings;
}

// ----------------------------------------------------------------------
// Mojo parameters
Expand Down
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.IOException;
import java.io.StringWriter;
import java.util.Collections;
Expand All @@ -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.
Expand Down Expand Up @@ -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
// ----------------------------------------------------------------------
Expand Down
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.IOException;
import java.io.StringWriter;
import java.net.InetAddress;
Expand All @@ -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;
Expand All @@ -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
Expand Down Expand Up @@ -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) {
Expand Down
Loading
Loading