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/24 11:31:25 UTC
(maven-invoker-plugin) branch master updated: Switch to Guice constructor injection (#266)
This is an automated email from the ASF dual-hosted git repository.
elharo pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/maven-invoker-plugin.git
The following commit(s) were added to refs/heads/master by this push:
new 7ad7463 Switch to Guice constructor injection (#266)
7ad7463 is described below
commit 7ad7463193ed2b0546b702fe107ef36eda65c328
Author: Elliotte Rusty Harold <el...@users.noreply.github.com>
AuthorDate: Tue Dec 24 11:31:20 2024 +0000
Switch to Guice constructor injection (#266)
* Switch to Guice injection
---
pom.xml | 1 -
.../maven/plugins/invoker/AbstractInvokerMojo.java | 28 +++++++++++++---------
.../maven/plugins/invoker/IntegrationTestMojo.java | 16 ++++++++++++-
.../apache/maven/plugins/invoker/InvokerMojo.java | 14 +++++++++++
.../maven/plugins/invoker/InvokerReport.java | 11 ++++++---
.../maven/plugins/invoker/InterpolationTest.java | 6 ++---
.../maven/plugins/invoker/InvokerMojoTest.java | 11 +++------
7 files changed, 59 insertions(+), 28 deletions(-)
diff --git a/pom.xml b/pom.xml
index 63b5839..7ecaccd 100644
--- a/pom.xml
+++ b/pom.xml
@@ -257,7 +257,6 @@ under the License.
<artifactId>maven-shared-utils</artifactId>
<version>3.4.2</version>
</dependency>
-
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-api</artifactId>
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 2b06cf6..814af54 100644
--- a/src/main/java/org/apache/maven/plugins/invoker/AbstractInvokerMojo.java
+++ b/src/main/java/org/apache/maven/plugins/invoker/AbstractInvokerMojo.java
@@ -57,7 +57,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;
@@ -746,23 +745,30 @@ 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;
- @Component
- private InterpolatorUtils interpolatorUtils;
+ private final InterpolatorUtils interpolatorUtils;
+
+ public AbstractInvokerMojo(
+ Invoker invoker,
+ SettingsBuilder settingsBuilder,
+ ToolchainManagerPrivate toolchainManagerPrivate,
+ InterpolatorUtils interpolatorUtils) {
+ this.invoker = invoker;
+ this.settingsBuilder = settingsBuilder;
+ this.toolchainManagerPrivate = toolchainManagerPrivate;
+ this.interpolatorUtils = interpolatorUtils;
+ }
/**
* 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..58e3386 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,19 @@ 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,
+ InterpolatorUtils interpolatorUtils) {
+ super(invoker, settingsBuilder, toolchainManagerPrivate, interpolatorUtils);
+ }
+
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..1ff0de6 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,15 @@ public class InvokerMojo extends AbstractInvokerMojo {
@Parameter(property = "invoker.streamLogsOnFailures", defaultValue = "false")
private boolean streamLogsOnFailures;
+ @Inject
+ public InvokerMojo(
+ Invoker invoker,
+ SettingsBuilder settingsBuilder,
+ ToolchainManagerPrivate toolchainManagerPrivate,
+ InterpolatorUtils interpolaterUtils) {
+ super(invoker, settingsBuilder, toolchainManagerPrivate, interpolaterUtils);
+ }
+
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 ebc47b3..854c32f 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;
@@ -55,8 +56,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 dd45ae7..6e0be14 100644
--- a/src/test/java/org/apache/maven/plugins/invoker/InterpolationTest.java
+++ b/src/test/java/org/apache/maven/plugins/invoker/InterpolationTest.java
@@ -56,7 +56,6 @@ class InterpolationTest {
@Test
void testCompositeMap() {
-
Map<String, Object> properties = new HashMap<>();
properties.put("foo", "bar");
properties.put("version", "2.0-SNAPSHOT");
@@ -70,8 +69,7 @@ class InterpolationTest {
@Test
void testPomInterpolation() throws Exception {
- File interpolatedPomFile;
- InvokerMojo invokerMojo = new InvokerMojo();
+ InvokerMojo invokerMojo = new InvokerMojo(null, null, null, null);
TestUtil.setVariableValueToObject(invokerMojo, "project", buildMavenProjectStub());
TestUtil.setVariableValueToObject(invokerMojo, "settings", new Settings());
Properties properties = new Properties();
@@ -81,7 +79,7 @@ class InterpolationTest {
String dirPath = TestUtil.getBasedir() + File.separatorChar + "src" + File.separatorChar + "test"
+ File.separatorChar + "resources" + File.separatorChar + "unit" + File.separatorChar + "interpolation";
- interpolatedPomFile = new File(TestUtil.getBasedir(), "target/interpolated-pom.xml");
+ File interpolatedPomFile = new File(TestUtil.getBasedir(), "target/interpolated-pom.xml");
invokerMojo.buildInterpolatedFile(new File(dirPath, "pom.xml"), interpolatedPomFile);
try (Reader reader = new XmlStreamReader(interpolatedPomFile)) {
String content = IOUtil.toString(reader);
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 b8b8f33..529e1f2 100644
--- a/src/test/java/org/apache/maven/plugins/invoker/InvokerMojoTest.java
+++ b/src/test/java/org/apache/maven/plugins/invoker/InvokerMojoTest.java
@@ -42,6 +42,8 @@ class InvokerMojoTest {
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, null);
+
private MavenProject getMavenProject() {
MavenProject mavenProject = new MavenProject();
mavenProject.setFile(new File("target/foo.txt"));
@@ -52,7 +54,6 @@ class InvokerMojoTest {
void testSingleInvokerTest() throws Exception {
// given
MavenProject mavenProject = getMavenProject();
- InvokerMojo invokerMojo = new InvokerMojo();
String dirPath = getBasedir() + "/src/test/resources/unit";
setVariableValueToObject(invokerMojo, "projectsDirectory", new File(dirPath));
setVariableValueToObject(invokerMojo, "invokerPropertiesFile", "invoker.properties");
@@ -72,7 +73,6 @@ class InvokerMojoTest {
void testMultiInvokerTest() throws Exception {
// given
MavenProject mavenProject = getMavenProject();
- InvokerMojo invokerMojo = new InvokerMojo();
String dirPath = getBasedir() + "/src/test/resources/unit";
setVariableValueToObject(invokerMojo, "projectsDirectory", new File(dirPath));
setVariableValueToObject(invokerMojo, "invokerPropertiesFile", "invoker.properties");
@@ -92,7 +92,6 @@ class InvokerMojoTest {
void testFullPatternInvokerTest() throws Exception {
// given
MavenProject mavenProject = getMavenProject();
- InvokerMojo invokerMojo = new InvokerMojo();
String dirPath = getBasedir() + "/src/test/resources/unit";
setVariableValueToObject(invokerMojo, "projectsDirectory", new File(dirPath));
setVariableValueToObject(invokerMojo, "invokerPropertiesFile", "invoker.properties");
@@ -115,7 +114,6 @@ class InvokerMojoTest {
void testSetupInProjectList() throws Exception {
// given
MavenProject mavenProject = getMavenProject();
- InvokerMojo invokerMojo = new InvokerMojo();
String dirPath = getBasedir() + "/src/test/resources/unit";
setVariableValueToObject(invokerMojo, "projectsDirectory", new File(dirPath));
setVariableValueToObject(invokerMojo, "invokerPropertiesFile", "invoker.properties");
@@ -144,11 +142,10 @@ class InvokerMojoTest {
@Test
void testSetupProjectIsFiltered() throws Exception {
// given
- MavenProject mavenProject = getMavenProject();
- InvokerMojo invokerMojo = new InvokerMojo();
String dirPath = getBasedir() + "/src/test/resources/unit";
setVariableValueToObject(invokerMojo, "projectsDirectory", new File(dirPath));
setVariableValueToObject(invokerMojo, "invokerPropertiesFile", "invoker.properties");
+ MavenProject mavenProject = getMavenProject();
setVariableValueToObject(invokerMojo, "project", mavenProject);
setVariableValueToObject(invokerMojo, "interpolatorUtils", new InterpolatorUtils(mavenProject));
setVariableValueToObject(invokerMojo, "settings", new Settings());
@@ -189,8 +186,6 @@ class InvokerMojoTest {
{"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];