Skip to content

Commit 89744d0

Browse files
authored
Convert Analyze Mojos to Guice constructor injection (#499)
1 parent 8b07cb3 commit 89744d0

File tree

3 files changed

+38
-18
lines changed

3 files changed

+38
-18
lines changed

src/main/java/org/apache/maven/plugins/dependency/analyze/AbstractAnalyzeMojo.java

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,6 @@
3434
import org.apache.maven.plugin.AbstractMojo;
3535
import org.apache.maven.plugin.MojoExecutionException;
3636
import org.apache.maven.plugin.MojoFailureException;
37-
import org.apache.maven.plugins.annotations.Component;
3837
import org.apache.maven.plugins.annotations.Parameter;
3938
import org.apache.maven.project.MavenProject;
4039
import org.apache.maven.shared.artifact.filter.StrictPatternExcludesArtifactFilter;
@@ -55,19 +54,6 @@
5554
public abstract class AbstractAnalyzeMojo extends AbstractMojo {
5655
// fields -----------------------------------------------------------------
5756

58-
/**
59-
* The plexusContainer to look-up the right {@link ProjectDependencyAnalyzer} implementation depending on the mojo
60-
* configuration.
61-
*/
62-
@Component
63-
private PlexusContainer plexusContainer;
64-
65-
/**
66-
* The Maven project to analyze.
67-
*/
68-
@Component
69-
private MavenProject project;
70-
7157
/**
7258
* Specify the project dependency analyzer to use (plexus component role-hint). By default,
7359
* <a href="/shared/maven-dependency-analyzer/">maven-dependency-analyzer</a> is used. To use this, you must declare
@@ -271,6 +257,22 @@ public abstract class AbstractAnalyzeMojo extends AbstractMojo {
271257
@Parameter(property = "mdep.analyze.excludedClasses")
272258
private Set<String> excludedClasses;
273259

260+
/**
261+
* The plexusContainer to look up the {@link ProjectDependencyAnalyzer} implementation depending on the mojo
262+
* configuration.
263+
*/
264+
private final PlexusContainer plexusContainer;
265+
266+
/**
267+
* The Maven project to analyze.
268+
*/
269+
private final MavenProject project;
270+
271+
protected AbstractAnalyzeMojo(PlexusContainer plexusContainer, MavenProject project) {
272+
this.plexusContainer = plexusContainer;
273+
this.project = project;
274+
}
275+
274276
// Mojo methods -----------------------------------------------------------
275277

276278
/*

src/main/java/org/apache/maven/plugins/dependency/analyze/AnalyzeMojo.java

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,17 +18,21 @@
1818
*/
1919
package org.apache.maven.plugins.dependency.analyze;
2020

21+
import javax.inject.Inject;
22+
2123
import org.apache.maven.plugins.annotations.Execute;
2224
import org.apache.maven.plugins.annotations.LifecyclePhase;
2325
import org.apache.maven.plugins.annotations.Mojo;
2426
import org.apache.maven.plugins.annotations.ResolutionScope;
27+
import org.apache.maven.project.MavenProject;
28+
import org.codehaus.plexus.PlexusContainer;
2529

2630
/**
2731
* Analyzes the dependencies of this project and determines which are: used and declared; used and undeclared; unused
28-
* and declared. This goal is intended to be used standalone, thus it always executes the <code>test-compile</code>
29-
* phase - use the <code>dependency:analyze-only</code> goal instead when participating in the build lifecycle.
32+
* and declared. This goal is intended to be used standalone. Thus, it always executes the <code>test-compile</code>
33+
* phase. Use the <code>dependency:analyze-only</code> goal instead when participating in the build lifecycle.
3034
* <p>
31-
* By default, <a href="http://maven.apache.org/shared/maven-dependency-analyzer/">maven-dependency-analyzer</a> is used
35+
* By default, <a href="https://maven.apache.org/shared/maven-dependency-analyzer/">maven-dependency-analyzer</a> is used
3236
* to perform the analysis, with limitations due to the fact that it works at bytecode level, but any analyzer can be
3337
* plugged in through <code>analyzer</code> parameter.
3438
* </p>
@@ -41,4 +45,9 @@
4145
@Execute(phase = LifecyclePhase.TEST_COMPILE)
4246
public class AnalyzeMojo extends AbstractAnalyzeMojo {
4347
// subclassed to provide annotations
48+
49+
@Inject
50+
public AnalyzeMojo(PlexusContainer plexusContainer, MavenProject project) {
51+
super(plexusContainer, project);
52+
}
4453
}

src/main/java/org/apache/maven/plugins/dependency/analyze/AnalyzeOnlyMojo.java

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,17 +18,21 @@
1818
*/
1919
package org.apache.maven.plugins.dependency.analyze;
2020

21+
import javax.inject.Inject;
22+
2123
import org.apache.maven.plugins.annotations.LifecyclePhase;
2224
import org.apache.maven.plugins.annotations.Mojo;
2325
import org.apache.maven.plugins.annotations.ResolutionScope;
26+
import org.apache.maven.project.MavenProject;
27+
import org.codehaus.plexus.PlexusContainer;
2428

2529
/**
2630
* Analyzes the dependencies of this project and determines which are: used and declared; used and undeclared; unused
2731
* and declared. This goal is intended to be used in the build lifecycle, thus it assumes that the
2832
* <code>test-compile</code> phase has been executed - use the <code>dependency:analyze</code> goal instead when running
2933
* standalone.
3034
* <p>
31-
* By default, <a href="http://maven.apache.org/shared/maven-dependency-analyzer/">maven-dependency-analyzer</a> is used
35+
* By default, <a href="https://maven.apache.org/shared/maven-dependency-analyzer/">maven-dependency-analyzer</a> is used
3236
* to perform the analysis, with limitations due to the fact that it works at bytecode level, but any analyzer can be
3337
* plugged in through <code>analyzer</code> parameter.
3438
* </p>
@@ -46,4 +50,9 @@
4650
// @formatter:on
4751
public class AnalyzeOnlyMojo extends AbstractAnalyzeMojo {
4852
// subclassed to provide annotations
53+
54+
@Inject
55+
public AnalyzeOnlyMojo(PlexusContainer plexusContainer, MavenProject project) {
56+
super(plexusContainer, project);
57+
}
4958
}

0 commit comments

Comments
 (0)