You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@maven.apache.org by el...@apache.org on 2024/12/06 15:23:32 UTC
(maven-invoker-plugin) branch guice created (now 94563cb)
This is an automated email from the ASF dual-hosted git repository.
elharo pushed a change to branch guice
in repository https://gitbox.apache.org/repos/asf/maven-invoker-plugin.git
at 94563cb Switch to Guice injection
This branch includes the following new commits:
new 94563cb Switch to Guice injection
The 1 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails. The revisions
listed as "add" were already present in the repository and have only
been added to this reference.
(maven-invoker-plugin) 01/01: Switch to Guice injection
Posted by el...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
elharo pushed a commit to branch guice
in repository https://gitbox.apache.org/repos/asf/maven-invoker-plugin.git
commit 94563cbc48d00c58b3957110b0e622c329160e77
Author: Elliotte Rusty Harold <el...@ibiblio.org>
AuthorDate: Fri Dec 6 10:23:26 2024 -0500
Switch to Guice injection
---
.../maven/plugins/invoker/AbstractInvokerMojo.java | 21 ++++++++++++---------
.../maven/plugins/invoker/IntegrationTestMojo.java | 13 ++++++++++++-
.../apache/maven/plugins/invoker/InvokerMojo.java | 11 +++++++++++
.../apache/maven/plugins/invoker/InvokerReport.java | 11 ++++++++---
.../maven/plugins/invoker/InterpolationTest.java | 3 +--
.../maven/plugins/invoker/InvokerMojoTest.java | 12 ++----------
6 files changed, 46 insertions(+), 25 deletions(-)
diff --git a/src/main/java/org/apache/maven/plugins/invoker/AbstractInvokerMojo.java b/src/main/java/org/apache/maven/plugins/invoker/AbstractInvokerMojo.java
index 2632020..667c193 100644
--- a/src/main/java/org/apache/maven/plugins/invoker/AbstractInvokerMojo.java
+++ b/src/main/java/org/apache/maven/plugins/invoker/AbstractInvokerMojo.java
@@ -56,7 +56,6 @@ import org.apache.maven.plugin.AbstractMojo;
import org.apache.maven.plugin.MojoExecution;
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.Parameter;
import org.apache.maven.plugins.invoker.model.BuildJob;
import org.apache.maven.plugins.invoker.model.io.xpp3.BuildJobXpp3Writer;
@@ -728,20 +727,24 @@ public abstract class AbstractInvokerMojo extends AbstractMojo {
@Parameter(defaultValue = "${settings}", readonly = true, required = true)
private Settings settings;
- @Component
- private Invoker invoker;
+ private final Invoker invoker;
- @Component
- private SettingsBuilder settingsBuilder;
+ private final SettingsBuilder settingsBuilder;
- @Component
- private ToolchainManagerPrivate toolchainManagerPrivate;
+ private final ToolchainManagerPrivate toolchainManagerPrivate;
+
+ public AbstractInvokerMojo(
+ Invoker invoker, SettingsBuilder settingsBuilder, ToolchainManagerPrivate toolchainManagerPrivate) {
+ this.invoker = invoker;
+ this.settingsBuilder = settingsBuilder;
+ this.toolchainManagerPrivate = toolchainManagerPrivate;
+ }
/**
* Invokes Maven on the configured test projects.
*
- * @throws org.apache.maven.plugin.MojoExecutionException If the goal encountered severe errors.
- * @throws org.apache.maven.plugin.MojoFailureException If any of the Maven builds failed.
+ * @throws org.apache.maven.plugin.MojoExecutionException if the goal encountered severe errors
+ * @throws org.apache.maven.plugin.MojoFailureException if any of the Maven builds failed
*/
public void execute() throws MojoExecutionException, MojoFailureException {
if (skipInvocation) {
diff --git a/src/main/java/org/apache/maven/plugins/invoker/IntegrationTestMojo.java b/src/main/java/org/apache/maven/plugins/invoker/IntegrationTestMojo.java
index 8fe675b..aebdc46 100644
--- a/src/main/java/org/apache/maven/plugins/invoker/IntegrationTestMojo.java
+++ b/src/main/java/org/apache/maven/plugins/invoker/IntegrationTestMojo.java
@@ -18,10 +18,15 @@
*/
package org.apache.maven.plugins.invoker;
+import javax.inject.Inject;
+
import org.apache.maven.plugin.MojoFailureException;
import org.apache.maven.plugins.annotations.LifecyclePhase;
import org.apache.maven.plugins.annotations.Mojo;
import org.apache.maven.plugins.annotations.ResolutionScope;
+import org.apache.maven.settings.building.SettingsBuilder;
+import org.apache.maven.shared.invoker.Invoker;
+import org.apache.maven.toolchain.ToolchainManagerPrivate;
/**
* Searches for integration test Maven projects, and executes each, collecting a log in the project directory, will
@@ -36,10 +41,16 @@ import org.apache.maven.plugins.annotations.ResolutionScope;
defaultPhase = LifecyclePhase.INTEGRATION_TEST,
requiresDependencyResolution = ResolutionScope.TEST,
threadSafe = true)
+// CHECKSTYLE_ON: LineLength
public class IntegrationTestMojo extends AbstractInvokerMojo {
+ @Inject
+ public IntegrationTestMojo(
+ Invoker invoker, SettingsBuilder settingsBuilder, ToolchainManagerPrivate toolchainManagerPrivate) {
+ super(invoker, settingsBuilder, toolchainManagerPrivate);
+ }
+
void processResults(InvokerSession invokerSession) throws MojoFailureException {
// do nothing
}
}
-// CHECKSTYLE_ON: LineLength
diff --git a/src/main/java/org/apache/maven/plugins/invoker/InvokerMojo.java b/src/main/java/org/apache/maven/plugins/invoker/InvokerMojo.java
index 361319a..5d07a35 100644
--- a/src/main/java/org/apache/maven/plugins/invoker/InvokerMojo.java
+++ b/src/main/java/org/apache/maven/plugins/invoker/InvokerMojo.java
@@ -18,11 +18,16 @@
*/
package org.apache.maven.plugins.invoker;
+import javax.inject.Inject;
+
import org.apache.maven.plugin.MojoFailureException;
import org.apache.maven.plugins.annotations.LifecyclePhase;
import org.apache.maven.plugins.annotations.Mojo;
import org.apache.maven.plugins.annotations.Parameter;
import org.apache.maven.plugins.annotations.ResolutionScope;
+import org.apache.maven.settings.building.SettingsBuilder;
+import org.apache.maven.shared.invoker.Invoker;
+import org.apache.maven.toolchain.ToolchainManagerPrivate;
/**
* Searches for integration test Maven projects, and executes each, collecting a log in the project directory, and
@@ -66,6 +71,12 @@ public class InvokerMojo extends AbstractInvokerMojo {
@Parameter(property = "invoker.streamLogsOnFailures", defaultValue = "false")
private boolean streamLogsOnFailures;
+ @Inject
+ public InvokerMojo(
+ Invoker invoker, SettingsBuilder settingsBuilder, ToolchainManagerPrivate toolchainManagerPrivate) {
+ super(invoker, settingsBuilder, toolchainManagerPrivate);
+ }
+
void processResults(InvokerSession invokerSession) throws MojoFailureException {
if (streamLogsOnFailures) {
invokerSession.logFailedBuildLog(getLog(), ignoreFailures);
diff --git a/src/main/java/org/apache/maven/plugins/invoker/InvokerReport.java b/src/main/java/org/apache/maven/plugins/invoker/InvokerReport.java
index 339705a..0ca4242 100644
--- a/src/main/java/org/apache/maven/plugins/invoker/InvokerReport.java
+++ b/src/main/java/org/apache/maven/plugins/invoker/InvokerReport.java
@@ -18,13 +18,14 @@
*/
package org.apache.maven.plugins.invoker;
+import javax.inject.Inject;
+
import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import java.util.Locale;
-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.invoker.model.BuildJob;
@@ -56,8 +57,12 @@ public class InvokerReport extends AbstractMavenReport {
/**
* Internationalization component
*/
- @Component
- protected I18N i18n;
+ protected final I18N i18n;
+
+ @Inject
+ public InvokerReport(I18N i18n) {
+ this.i18n = i18n;
+ }
protected void executeReport(Locale locale) throws MavenReportException {
File[] reportFiles = getReportFiles();
diff --git a/src/test/java/org/apache/maven/plugins/invoker/InterpolationTest.java b/src/test/java/org/apache/maven/plugins/invoker/InterpolationTest.java
index 637845d..862e908 100644
--- a/src/test/java/org/apache/maven/plugins/invoker/InterpolationTest.java
+++ b/src/test/java/org/apache/maven/plugins/invoker/InterpolationTest.java
@@ -67,7 +67,7 @@ public class InterpolationTest extends AbstractMojoTestCase {
Reader reader = null;
File interpolatedPomFile;
try {
- InvokerMojo invokerMojo = new InvokerMojo();
+ InvokerMojo invokerMojo = new InvokerMojo(null, null, null);
setVariableValueToObject(invokerMojo, "project", buildMavenProjectStub());
setVariableValueToObject(invokerMojo, "settings", new Settings());
Properties properties = new Properties();
@@ -84,7 +84,6 @@ public class InterpolationTest extends AbstractMojoTestCase {
String content = IOUtil.toString(reader);
assertTrue(content.indexOf("<interpolateValue>bar</interpolateValue>") > 0);
reader.close();
- reader = null;
// recreate it to test delete if exists before creation
invokerMojo.buildInterpolatedFile(new File(dirPath, "pom.xml"), interpolatedPomFile);
reader = ReaderFactory.newXmlReader(interpolatedPomFile);
diff --git a/src/test/java/org/apache/maven/plugins/invoker/InvokerMojoTest.java b/src/test/java/org/apache/maven/plugins/invoker/InvokerMojoTest.java
index 49abbeb..effd2e3 100644
--- a/src/test/java/org/apache/maven/plugins/invoker/InvokerMojoTest.java
+++ b/src/test/java/org/apache/maven/plugins/invoker/InvokerMojoTest.java
@@ -40,6 +40,8 @@ public class InvokerMojoTest extends AbstractMojoTestCase {
private static final String INTERPOLATION_PROJECT = "interpolation" + File.separator + "pom.xml";
private static final String WITHOUT_POM_PROJECT = "without-pom-project-dir";
+ private final InvokerMojo invokerMojo = new InvokerMojo(null, null, null);
+
private MavenProject getMavenProject() {
MavenProject mavenProject = new MavenProject();
mavenProject.setFile(new File("target/foo.txt"));
@@ -47,8 +49,6 @@ public class InvokerMojoTest extends AbstractMojoTestCase {
}
public void testSingleInvokerTest() throws Exception {
- // given
- InvokerMojo invokerMojo = new InvokerMojo();
String dirPath = getBasedir() + "/src/test/resources/unit";
setVariableValueToObject(invokerMojo, "projectsDirectory", new File(dirPath));
setVariableValueToObject(invokerMojo, "invokerPropertiesFile", "invoker.properties");
@@ -64,8 +64,6 @@ public class InvokerMojoTest extends AbstractMojoTestCase {
}
public void testMultiInvokerTest() throws Exception {
- // given
- InvokerMojo invokerMojo = new InvokerMojo();
String dirPath = getBasedir() + "/src/test/resources/unit";
setVariableValueToObject(invokerMojo, "projectsDirectory", new File(dirPath));
setVariableValueToObject(invokerMojo, "invokerPropertiesFile", "invoker.properties");
@@ -82,7 +80,6 @@ public class InvokerMojoTest extends AbstractMojoTestCase {
public void testFullPatternInvokerTest() throws Exception {
// given
- InvokerMojo invokerMojo = new InvokerMojo();
String dirPath = getBasedir() + "/src/test/resources/unit";
setVariableValueToObject(invokerMojo, "projectsDirectory", new File(dirPath));
setVariableValueToObject(invokerMojo, "invokerPropertiesFile", "invoker.properties");
@@ -101,8 +98,6 @@ public class InvokerMojoTest extends AbstractMojoTestCase {
}
public void testSetupInProjectList() throws Exception {
- // given
- InvokerMojo invokerMojo = new InvokerMojo();
String dirPath = getBasedir() + "/src/test/resources/unit";
setVariableValueToObject(invokerMojo, "projectsDirectory", new File(dirPath));
setVariableValueToObject(invokerMojo, "invokerPropertiesFile", "invoker.properties");
@@ -129,7 +124,6 @@ public class InvokerMojoTest extends AbstractMojoTestCase {
public void testSetupProjectIsFiltered() throws Exception {
// given
- InvokerMojo invokerMojo = new InvokerMojo();
String dirPath = getBasedir() + "/src/test/resources/unit";
setVariableValueToObject(invokerMojo, "projectsDirectory", new File(dirPath));
setVariableValueToObject(invokerMojo, "invokerPropertiesFile", "invoker.properties");
@@ -166,8 +160,6 @@ public class InvokerMojoTest extends AbstractMojoTestCase {
{"2.5C", (int) (Double.parseDouble("2.5") * Runtime.getRuntime().availableProcessors())}
};
- InvokerMojo invokerMojo = new InvokerMojo();
-
for (Object[] testValue : testValues) {
String parallelThreads = (String) testValue[0];
int expectedParallelThreads = (Integer) testValue[1];