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

[MDEP-966] Migrate TreeMojo/CopyMojo/AnalyzeExclusionsMojo/UnpackMojo/CopyDependenciesMojo from Plexus to Sisu Guice #483

Merged
merged 12 commits into from
Nov 28, 2024
7 changes: 0 additions & 7 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -146,13 +146,6 @@ under the License.
<scope>provided</scope>
</dependency>

<dependency>
<groupId>org.eclipse.sisu</groupId>
<artifactId>org.eclipse.sisu.plexus</artifactId>
<version>0.9.0.M3</version>
<scope>provided</scope>
</dependency>

<!-- doxia -->
<dependency>
<groupId>org.apache.maven.doxia</groupId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@
*/
package org.apache.maven.plugins.dependency.exclusion;

import javax.inject.Inject;

import java.util.ArrayList;
import java.util.Collection;
import java.util.HashMap;
Expand All @@ -32,7 +34,6 @@
import org.apache.maven.model.Exclusion;
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.Mojo;
import org.apache.maven.plugins.annotations.Parameter;
import org.apache.maven.plugins.annotations.ResolutionScope;
Expand All @@ -57,15 +58,19 @@
@Mojo(name = "analyze-exclusions", requiresDependencyCollection = ResolutionScope.TEST, threadSafe = true)
public class AnalyzeExclusionsMojo extends AbstractMojo {

@Component
private MavenProject project;
Copy link

Choose a reason for hiding this comment

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

Constructor injected fields should be made 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.

good idea, done


@Component
private ResolverUtil resolverUtil;

@Component
private MavenSession session;

@Inject
public AnalyzeExclusionsMojo(MavenProject project, ResolverUtil resolverUtil, MavenSession session) {
this.project = project;
this.resolverUtil = resolverUtil;
this.session = session;
}

/**
* Whether to fail the build if invalid exclusions is found.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,15 @@
*/
package org.apache.maven.plugins.dependency.fromConfiguration;

import javax.inject.Inject;

import java.io.File;
import java.io.IOException;
import java.util.List;

import org.apache.maven.artifact.Artifact;
import org.apache.maven.plugin.MojoExecutionException;
import org.apache.maven.plugin.MojoFailureException;
import org.apache.maven.plugins.annotations.Component;
import org.apache.maven.plugins.annotations.LifecyclePhase;
import org.apache.maven.plugins.annotations.Mojo;
import org.apache.maven.plugins.annotations.Parameter;
Expand All @@ -42,8 +43,8 @@
@Mojo(name = "copy", defaultPhase = LifecyclePhase.PROCESS_SOURCES, requiresProject = false, threadSafe = true)
public class CopyMojo extends AbstractFromConfigurationMojo {

@Component
private CopyUtil copyUtil;

/**
* Strip artifact version during copy
*/
Expand Down Expand Up @@ -80,6 +81,11 @@ public class CopyMojo extends AbstractFromConfigurationMojo {
@Parameter(property = "artifact")
private String artifact;

@Inject
public CopyMojo(CopyUtil copyUtil) {
this.copyUtil = copyUtil;
}

/**
* Main entry into mojo. This method gets the ArtifactItems and iterates through each one passing it to
* copyArtifact.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,14 @@
*/
package org.apache.maven.plugins.dependency.fromConfiguration;

import javax.inject.Inject;

import java.io.File;
import java.util.List;

import org.apache.commons.lang3.StringUtils;
import org.apache.maven.plugin.MojoExecutionException;
import org.apache.maven.plugin.MojoFailureException;
import org.apache.maven.plugins.annotations.Component;
import org.apache.maven.plugins.annotations.LifecyclePhase;
import org.apache.maven.plugins.annotations.Mojo;
import org.apache.maven.plugins.annotations.Parameter;
Expand All @@ -44,7 +45,6 @@
@Mojo(name = "unpack", defaultPhase = LifecyclePhase.PROCESS_SOURCES, requiresProject = false, threadSafe = true)
public class UnpackMojo extends AbstractFromConfigurationMojo {

@Component
private UnpackUtil unpackUtil;

/**
Expand Down Expand Up @@ -98,6 +98,11 @@ public class UnpackMojo extends AbstractFromConfigurationMojo {
@Parameter(property = "artifact")
private String artifact;

@Inject
public UnpackMojo(UnpackUtil unpackUtil) {
this.unpackUtil = unpackUtil;
}

/**
* Main entry into mojo. This method gets the ArtifactItems and iterates through each one passing it to
* unpackArtifact.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@
*/
package org.apache.maven.plugins.dependency.fromDependencies;

import javax.inject.Inject;

import java.io.File;
import java.io.IOException;
import java.io.Writer;
Expand All @@ -38,7 +40,6 @@
import org.apache.commons.lang3.StringUtils;
import org.apache.maven.artifact.Artifact;
import org.apache.maven.plugin.MojoExecutionException;
import org.apache.maven.plugins.annotations.Component;
import org.apache.maven.plugins.annotations.LifecyclePhase;
import org.apache.maven.plugins.annotations.Mojo;
import org.apache.maven.plugins.annotations.Parameter;
Expand Down Expand Up @@ -162,16 +163,20 @@ public class BuildClasspathMojo extends AbstractDependencyFilterMojo implements
/**
* Maven ProjectHelper
*/
@Component
private MavenProjectHelper projectHelper;

@Component
private RepositoryManager repositoryManager;

@Inject
public BuildClasspathMojo(MavenProjectHelper projectHelper, RepositoryManager repositoryManager) {
this.projectHelper = projectHelper;
this.repositoryManager = repositoryManager;
}

/**
* Main entry into mojo. Gets the list of dependencies and iterates to create a classpath.
*
* @throws MojoExecutionException with a message if an error occurs.
* @throws MojoExecutionException with a message if an error occurs
* @see #getResolvedDependencies(boolean)
*/
@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,17 +18,16 @@
*/
package org.apache.maven.plugins.dependency.fromDependencies;

import javax.inject.Inject;

import java.io.File;
import java.io.IOException;
import java.util.Collections;
import java.util.Map;
import java.util.Set;

import org.apache.maven.RepositoryUtils;
import org.apache.maven.artifact.Artifact;
import org.apache.maven.artifact.repository.layout.ArtifactRepositoryLayout;
import org.apache.maven.plugin.MojoExecutionException;
import org.apache.maven.plugins.annotations.Component;
import org.apache.maven.plugins.annotations.LifecyclePhase;
import org.apache.maven.plugins.annotations.Mojo;
import org.apache.maven.plugins.annotations.Parameter;
Expand Down Expand Up @@ -66,20 +65,15 @@ public class CopyDependenciesMojo extends AbstractFromDependenciesMojo {
@Parameter(property = "mdep.copyPom", defaultValue = "false")
protected boolean copyPom;

@Component
private CopyUtil copyUtil;

/**
*
*/
@Component
private ArtifactInstaller installer;

/**
*
*/
@Component(role = ArtifactRepositoryLayout.class)
private Map<String, ArtifactRepositoryLayout> repositoryLayouts;
@Inject
public CopyDependenciesMojo(CopyUtil copyUtil, ArtifactInstaller installer) {
this.copyUtil = copyUtil;
this.installer = installer;
}

/**
* Either append the artifact's baseVersion or uniqueVersion to the filename. Will only be used if
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@
*/
package org.apache.maven.plugins.dependency.tree;

import javax.inject.Inject;

import java.io.File;
import java.io.IOException;
import java.io.StringWriter;
Expand All @@ -32,7 +34,6 @@
import org.apache.maven.plugin.AbstractMojo;
import org.apache.maven.plugin.MojoExecutionException;
import org.apache.maven.plugin.MojoFailureException;
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.plugins.annotations.ResolutionScope;
Expand Down Expand Up @@ -75,27 +76,23 @@ public class TreeMojo extends AbstractMojo {
/**
* The Maven project.
*/
@Component
private MavenProject project;

@Component
private MavenSession session;

@Parameter(property = "outputEncoding", defaultValue = "${project.reporting.outputEncoding}")
private String outputEncoding;

/**
* The dependency collector builder to use.
*/
@Component(hint = "default")
private DependencyCollectorBuilder dependencyCollectorBuilder;

/**
* The dependency graph builder to use.
*/
@Component(hint = "default")
private DependencyGraphBuilder dependencyGraphBuilder;

@Parameter(property = "outputEncoding", defaultValue = "${project.reporting.outputEncoding}")
private String outputEncoding;

/**
* If specified, this parameter will cause the dependency tree to be written to the path specified, instead of
* writing to the console.
Expand Down Expand Up @@ -205,6 +202,19 @@ public class TreeMojo extends AbstractMojo {
*/
@Parameter(property = "skip", defaultValue = "false")
private boolean skip;

@Inject
public TreeMojo(
MavenProject project,
MavenSession session,
DependencyCollectorBuilder dependencyCollectorBuilder,
DependencyGraphBuilder dependencyGraphBuilder) {
this.project = project;
this.session = session;
this.dependencyCollectorBuilder = dependencyCollectorBuilder;
this.dependencyGraphBuilder = dependencyGraphBuilder;
}

// Mojo methods -----------------------------------------------------------

/*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
public class TestCopyMojo extends AbstractDependencyMojoTestCase {
private CopyMojo mojo;

@Override
protected void setUp() throws Exception {
super.setUp("copy", false, false);
MavenProject project = new DependencyProjectStub();
Expand Down Expand Up @@ -129,7 +130,7 @@ public void assertFileExists(ArtifactItem item, boolean exist) {
}

public void testMojoDefaults() {
CopyMojo themojo = new CopyMojo();
CopyMojo themojo = new CopyMojo(null);

assertFalse(themojo.isStripVersion());
assertFalse(themojo.isSkip());
Expand Down