Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Convert reports to Guice #803

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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) {
Expand All @@ -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
Copy link

@Bukama Bukama Dec 25, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you want to use the Java 16 inline return Javadoc here (which automatically adds the period at the end)?
If yes, the correct Javadoc to write this would be

{@return the according string for the section}

Which would be transformed to

Returns the according string for the section.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, per pom.xml we're still using Java 8 here

*/
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");
}
Expand Down Expand Up @@ -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;

Expand Down Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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>
*
Expand Down Expand Up @@ -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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,20 +18,23 @@
*/
package org.apache.maven.plugins.surefire.report;

import javax.inject.Inject;

import java.io.File;

import org.apache.maven.plugins.annotations.Execute;
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.project.MavenProject;
import org.codehaus.plexus.i18n.I18N;

/**
* Creates a nicely formatted Surefire Test Report in html format.
*
* @author <a href="mailto:jruiz@exist.com">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 {
Expand All @@ -43,20 +46,25 @@ 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
*/
@Parameter(defaultValue = "true", property = "alwaysGenerateSurefireReport")
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();
Expand Down
Loading