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-surefire.git
The following commit(s) were added to refs/heads/master by this push:
new d28e294e5 Convert reports to Guice (#803)
d28e294e5 is described below
commit d28e294e59aa88002a0417f67c1d8f52bc1e8351
Author: Elliotte Rusty Harold <[email protected]>
AuthorDate: Sat Feb 15 14:44:49 2025 +0000
Convert reports to Guice (#803)
* Convert reports to Guice
---
.../surefire/report/AbstractSurefireReport.java | 39 +++++++++++++++++-----
.../surefire/report/FailsafeOnlyReport.java | 10 +++++-
.../surefire/report/SurefireOnlyReport.java | 11 +++++-
.../plugins/surefire/report/SurefireReport.java | 14 ++++++--
4 files changed, 61 insertions(+), 13 deletions(-)
diff --git
a/maven-surefire-report-plugin/src/main/java/org/apache/maven/plugins/surefire/report/AbstractSurefireReport.java
b/maven-surefire-report-plugin/src/main/java/org/apache/maven/plugins/surefire/report/AbstractSurefireReport.java
index da3cf1b1c..95ca6b31d 100644
---
a/maven-surefire-report-plugin/src/main/java/org/apache/maven/plugins/surefire/report/AbstractSurefireReport.java
+++
b/maven-surefire-report-plugin/src/main/java/org/apache/maven/plugins/surefire/report/AbstractSurefireReport.java
@@ -32,7 +32,6 @@
import java.util.ResourceBundle;
import org.apache.maven.plugin.surefire.log.api.ConsoleLogger;
-import org.apache.maven.plugins.annotations.Component;
import org.apache.maven.plugins.annotations.Parameter;
import org.apache.maven.project.MavenProject;
import org.apache.maven.reporting.AbstractMavenReport;
@@ -110,13 +109,16 @@ public abstract class AbstractSurefireReport extends
AbstractMavenReport {
@Parameter(defaultValue =
"${basedir}/src/site/custom/surefire-report.properties")
private String customBundle;
+ private List<File> resolvedReportsDirectories;
+
/**
* Internationalization component
*/
- @Component
private I18N i18n;
- private List<File> resolvedReportsDirectories;
+ protected AbstractSurefireReport(I18N i18n) {
+ this.i18n = i18n;
+ }
/**
* Whether the report should be generated or not.
@@ -253,15 +255,16 @@ private List<MavenProject> getProjectsWithoutRoot() {
}
/**
- * @param locale The locale
- * @param key The key to search for
- * @return The text appropriate for the locale.
+ * @param locale the locale
+ * @param key the key to search fo
+ * @return the text appropriate for the locale.
*/
protected String getI18nString(Locale locale, String key) {
return getI18N(locale).getString("surefire-report", locale, "report."
+ getI18Nsection() + '.' + key);
}
+
/**
- * @param locale The local.
+ * @param locale the locale
* @return I18N for the locale
*/
protected I18N getI18N(Locale locale) {
@@ -278,17 +281,20 @@ protected I18N getI18N(Locale locale) {
return i18n;
}
+
/**
- * @return The according string for the section.
+ * @return the according string for the section
*/
protected abstract String getI18Nsection();
/** {@inheritDoc} */
+ @Override
public String getName(Locale locale) {
return getI18nString(locale, "name");
}
/** {@inheritDoc} */
+ @Override
public String getDescription(Locale locale) {
return getI18nString(locale, "description");
}
@@ -353,61 +359,73 @@ private static class CustomI18N implements I18N {
}
/** {@inheritDoc} */
+ @Override
public String getDefaultLanguage() {
return locale.getLanguage();
}
/** {@inheritDoc} */
+ @Override
public String getDefaultCountry() {
return locale.getCountry();
}
/** {@inheritDoc} */
+ @Override
public String getDefaultBundleName() {
return bundleName;
}
/** {@inheritDoc} */
+ @Override
public String[] getBundleNames() {
return new String[] {bundleName};
}
/** {@inheritDoc} */
+ @Override
public ResourceBundle getBundle() {
return bundle;
}
/** {@inheritDoc} */
+ @Override
public ResourceBundle getBundle(String bundleName) {
return bundle;
}
/** {@inheritDoc} */
+ @Override
public ResourceBundle getBundle(String bundleName, String
languageHeader) {
return bundle;
}
/** {@inheritDoc} */
+ @Override
public ResourceBundle getBundle(String bundleName, Locale locale) {
return bundle;
}
/** {@inheritDoc} */
+ @Override
public Locale getLocale(String languageHeader) {
return new Locale(languageHeader);
}
/** {@inheritDoc} */
+ @Override
public String getString(String key) {
return getString(bundleName, locale, key);
}
/** {@inheritDoc} */
+ @Override
public String getString(String key, Locale locale) {
return getString(bundleName, locale, key);
}
/** {@inheritDoc} */
+ @Override
public String getString(String bundleName, Locale locale, String key) {
String value;
@@ -450,26 +468,31 @@ public String getString(String bundleName, Locale locale,
String key) {
}
/** {@inheritDoc} */
+ @Override
public String format(String key, Object arg1) {
return format(bundleName, locale, key, new Object[] {arg1});
}
/** {@inheritDoc} */
+ @Override
public String format(String key, Object arg1, Object arg2) {
return format(bundleName, locale, key, new Object[] {arg1, arg2});
}
/** {@inheritDoc} */
+ @Override
public String format(String bundleName, Locale locale, String key,
Object arg1) {
return format(bundleName, locale, key, new Object[] {arg1});
}
/** {@inheritDoc} */
+ @Override
public String format(String bundleName, Locale locale, String key,
Object arg1, Object arg2) {
return format(bundleName, locale, key, new Object[] {arg1, arg2});
}
/** {@inheritDoc} */
+ @Override
public String format(String bundleName, Locale locale, String key,
Object[] args) {
if (locale == null) {
locale = getLocale(null);
diff --git
a/maven-surefire-report-plugin/src/main/java/org/apache/maven/plugins/surefire/report/FailsafeOnlyReport.java
b/maven-surefire-report-plugin/src/main/java/org/apache/maven/plugins/surefire/report/FailsafeOnlyReport.java
index ae2b62078..3e0aa4030 100644
---
a/maven-surefire-report-plugin/src/main/java/org/apache/maven/plugins/surefire/report/FailsafeOnlyReport.java
+++
b/maven-surefire-report-plugin/src/main/java/org/apache/maven/plugins/surefire/report/FailsafeOnlyReport.java
@@ -18,15 +18,18 @@
*/
package org.apache.maven.plugins.surefire.report;
+import javax.inject.Inject;
+
import java.io.File;
import org.apache.maven.plugins.annotations.Mojo;
import org.apache.maven.plugins.annotations.Parameter;
import org.apache.maven.project.MavenProject;
+import org.codehaus.plexus.i18n.I18N;
/**
* Creates a nicely formatted Failsafe Test Report in html format.
- * This goal does not run the tests, it only builds the reports.
+ * This goal does not run the tests; it only builds the reports.
* See <a href="https://issues.apache.org/jira/browse/SUREFIRE-257">
* https://issues.apache.org/jira/browse/SUREFIRE-257</a>
*
@@ -58,6 +61,11 @@ public class FailsafeOnlyReport extends
AbstractSurefireReport {
@Parameter(defaultValue = "false", property = "skipFailsafeReport")
private boolean skipFailsafeReport;
+ @Inject
+ public FailsafeOnlyReport(I18N i18n) {
+ super(i18n);
+ }
+
@Override
protected File getSurefireReportsDirectory(MavenProject subProject) {
String buildDir = subProject.getBuild().getDirectory();
diff --git
a/maven-surefire-report-plugin/src/main/java/org/apache/maven/plugins/surefire/report/SurefireOnlyReport.java
b/maven-surefire-report-plugin/src/main/java/org/apache/maven/plugins/surefire/report/SurefireOnlyReport.java
index d523e9769..488e7462e 100644
---
a/maven-surefire-report-plugin/src/main/java/org/apache/maven/plugins/surefire/report/SurefireOnlyReport.java
+++
b/maven-surefire-report-plugin/src/main/java/org/apache/maven/plugins/surefire/report/SurefireOnlyReport.java
@@ -18,9 +18,12 @@
*/
package org.apache.maven.plugins.surefire.report;
+import javax.inject.Inject;
+
import org.apache.maven.plugins.annotations.Execute;
import org.apache.maven.plugins.annotations.LifecyclePhase;
import org.apache.maven.plugins.annotations.Mojo;
+import org.codehaus.plexus.i18n.I18N;
/**
* Creates a nicely formatted Surefire Test Report in html format.
@@ -34,4 +37,10 @@
@Mojo(name = "report-only")
@Execute(phase = LifecyclePhase.NONE)
@SuppressWarnings("unused")
-public class SurefireOnlyReport extends SurefireReport {}
+public class SurefireOnlyReport extends SurefireReport {
+
+ @Inject
+ public SurefireOnlyReport(I18N i18n) {
+ super(i18n);
+ }
+}
diff --git
a/maven-surefire-report-plugin/src/main/java/org/apache/maven/plugins/surefire/report/SurefireReport.java
b/maven-surefire-report-plugin/src/main/java/org/apache/maven/plugins/surefire/report/SurefireReport.java
index 1405ba9c9..29bdb0b51 100644
---
a/maven-surefire-report-plugin/src/main/java/org/apache/maven/plugins/surefire/report/SurefireReport.java
+++
b/maven-surefire-report-plugin/src/main/java/org/apache/maven/plugins/surefire/report/SurefireReport.java
@@ -18,6 +18,8 @@
*/
package org.apache.maven.plugins.surefire.report;
+import javax.inject.Inject;
+
import java.io.File;
import org.apache.maven.plugins.annotations.Execute;
@@ -25,13 +27,14 @@
import org.apache.maven.plugins.annotations.Mojo;
import org.apache.maven.plugins.annotations.Parameter;
import org.apache.maven.project.MavenProject;
+import org.codehaus.plexus.i18n.I18N;
/**
* Creates a nicely formatted Surefire Test Report in html format.
*
* @author <a href="mailto:[email protected]">Johnny R. Ruiz III</a>
*/
-@Mojo(name = "report", inheritByDefault = false)
+@Mojo(name = "report")
@Execute(lifecycle = "surefire", phase = LifecyclePhase.TEST)
@SuppressWarnings("unused")
public class SurefireReport extends AbstractSurefireReport {
@@ -43,7 +46,7 @@ public class SurefireReport extends AbstractSurefireReport {
private String outputName;
/**
- * If set to true the surefire report will be generated even when there
are no surefire result files.
+ * If set to true, the surefire report will be generated even when there
are no surefire result files.
* Defaults to {@code true} to preserve legacy behaviour pre 2.10.
* @since 2.11
*/
@@ -51,12 +54,17 @@ public class SurefireReport extends AbstractSurefireReport {
private boolean alwaysGenerateSurefireReport;
/**
- * If set to true the surefire report generation will be skipped.
+ * If set to true, the surefire report generation will be skipped.
* @since 2.11
*/
@Parameter(defaultValue = "false", property = "skipSurefireReport")
private boolean skipSurefireReport;
+ @Inject
+ public SurefireReport(I18N i18n) {
+ super(i18n);
+ }
+
@Override
protected File getSurefireReportsDirectory(MavenProject subProject) {
String buildDir = subProject.getBuild().getDirectory();