Skip to content

Commit

Permalink
[MDEP-966] Migrate TreeMojo/CopyMojo/AnalyzeExclusionsMojo/UnpackMojo…
Browse files Browse the repository at this point in the history
…/CopyDependenciesMojo from Plexus to Sisu Guice (#483)

* [MDEP-966] Migrate TreeMojo from Plexus to Sisu Guice
* [MDEP-966] Migrate AnalyzeExclusionMojo from Plexus to Sisu Guice
* [MDEP-966] Migrate CopyMojo from Plexus to Sisu Guice
* [MDEP-966] Migrate UnpackMojo from Plexus to Sisu Guice
* BuildClasspathMojo
* CopyDependenciesMojo
  • Loading branch information
elharo authored Nov 28, 2024
1 parent 0079030 commit 969ed96
Show file tree
Hide file tree
Showing 15 changed files with 101 additions and 70 deletions.
14 changes: 7 additions & 7 deletions src/main/java/org/apache/maven/plugins/dependency/GetMojo.java
Original file line number Diff line number Diff line change
Expand Up @@ -59,25 +59,25 @@
public class GetMojo extends AbstractMojo {
private static final Pattern ALT_REPO_SYNTAX_PATTERN = Pattern.compile("(.+)::(.*)::(.+)");

private MavenSession session;
private final MavenSession session;

private ArtifactResolver artifactResolver;
private final ArtifactResolver artifactResolver;

private DependencyResolver dependencyResolver;
private final DependencyResolver dependencyResolver;

private ArtifactHandlerManager artifactHandlerManager;
private final ArtifactHandlerManager artifactHandlerManager;

/**
* Map that contains the layouts.
*/
private Map<String, ArtifactRepositoryLayout> repositoryLayouts;
private final Map<String, ArtifactRepositoryLayout> repositoryLayouts;

/**
* The repository system.
*/
private RepositorySystem repositorySystem;
private final RepositorySystem repositorySystem;

private DefaultDependableCoordinate coordinate = new DefaultDependableCoordinate();
private final DefaultDependableCoordinate coordinate = new DefaultDependableCoordinate();

/**
* Repositories in the format id::[layout]::url or just url, separated by comma. ie.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@
@Mojo(name = "list-classes", requiresProject = false, threadSafe = true)
public class ListClassesMojo extends AbstractMojo {

private ResolverUtil resolverUtil;
private final ResolverUtil resolverUtil;

private ParamArtifact paramArtifact = new ParamArtifact();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@
@Mojo(name = "list-repositories", threadSafe = true)
public class ListRepositoriesMojo extends AbstractDependencyMojo {

private RepositorySystem repositorySystem;
private final RepositorySystem repositorySystem;

@Inject
public ListRepositoriesMojo(RepositorySystem repositorySystem) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ public class PropertiesMojo extends AbstractMojo {
/**
* The current Maven project
*/
private MavenProject project;
private final MavenProject project;

@Inject
public PropertiesMojo(MavenProject project) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,24 +83,24 @@ public class PurgeLocalRepositoryMojo extends AbstractMojo {
/**
* The current Maven project.
*/
private MavenProject project;
private final MavenProject project;

private MavenSession session;
private final MavenSession session;

/**
* Artifact handler manager.
*/
private ArtifactHandlerManager artifactHandlerManager;
private final ArtifactHandlerManager artifactHandlerManager;

/**
* The dependency resolver
*/
private DependencyResolver dependencyResolver;
private final DependencyResolver dependencyResolver;

/**
* The artifact resolver used to re-resolve dependencies, if that option is enabled.
*/
private ArtifactResolver artifactResolver;
private final ArtifactResolver artifactResolver;

/**
* The Maven projects in the reactor.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@
public class AnalyzeDepMgt extends AbstractMojo {
// fields -----------------------------------------------------------------

private MavenProject project;
private final MavenProject project;

/**
* Fail the build if a problem is detected.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,12 @@ public class AnalyzeReport extends AbstractMavenReport {
/**
* The Maven project dependency analyzer to use.
*/
private ProjectDependencyAnalyzer analyzer;
private final ProjectDependencyAnalyzer analyzer;

/**
* Internationalization component
*/
private final I18N i18n;

/**
* Ignore Runtime/Provided/Test/System scopes for unused dependency analysis
Expand Down Expand Up @@ -84,11 +89,6 @@ public class AnalyzeReport extends AbstractMavenReport {
@Parameter(property = "mdep.analyze.excludedClasses")
private Set<String> excludedClasses;

/**
* Internationalization component
*/
private I18N i18n;

@Inject
public AnalyzeReport(ProjectDependencyAnalyzer analyzer, I18N i18n) {
this.analyzer = analyzer;
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,14 +58,18 @@
@Mojo(name = "analyze-exclusions", requiresDependencyCollection = ResolutionScope.TEST, threadSafe = true)
public class AnalyzeExclusionsMojo extends AbstractMojo {

@Component
private MavenProject project;
private final MavenProject project;

private final ResolverUtil resolverUtil;

@Component
private ResolverUtil resolverUtil;
private final MavenSession session;

@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;
private final 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,12 +18,13 @@
*/
package org.apache.maven.plugins.dependency.fromConfiguration;

import javax.inject.Inject;

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

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 @@ -43,8 +44,7 @@
@Mojo(name = "unpack", defaultPhase = LifecyclePhase.PROCESS_SOURCES, requiresProject = false, threadSafe = true)
public class UnpackMojo extends AbstractFromConfigurationMojo {

@Component
private UnpackUtil unpackUtil;
private final UnpackUtil unpackUtil;

/**
* Directory to store flag files after unpack
Expand Down Expand Up @@ -97,6 +97,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;
private final CopyUtil copyUtil;

/**
*
*/
@Component
private ArtifactInstaller installer;
private final 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,11 +18,12 @@
*/
package org.apache.maven.plugins.dependency.fromDependencies;

import javax.inject.Inject;

import java.io.File;

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 @@ -50,8 +51,12 @@
// CHECKSTYLE_ON: LineLength
public class UnpackDependenciesMojo extends AbstractFromDependenciesMojo {

@Component
private UnpackUtil unpackUtil;
private final UnpackUtil unpackUtil;

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

/**
* A comma separated list of file patterns to include when unpacking the artifact. i.e.
Expand Down
Loading

0 comments on commit 969ed96

Please sign in to comment.