diff --git a/src/main/java/org/apache/maven/plugins/checkstyle/AbstractCheckstyleReport.java b/src/main/java/org/apache/maven/plugins/checkstyle/AbstractCheckstyleReport.java index 4ab9e052..0c1c8bbc 100644 --- a/src/main/java/org/apache/maven/plugins/checkstyle/AbstractCheckstyleReport.java +++ b/src/main/java/org/apache/maven/plugins/checkstyle/AbstractCheckstyleReport.java @@ -44,7 +44,6 @@ import org.apache.maven.model.PluginManagement; import org.apache.maven.model.Resource; import org.apache.maven.plugin.descriptor.PluginDescriptor; -import org.apache.maven.plugins.annotations.Component; import org.apache.maven.plugins.annotations.Parameter; import org.apache.maven.plugins.checkstyle.exec.CheckstyleExecutor; import org.apache.maven.plugins.checkstyle.exec.CheckstyleExecutorException; @@ -62,8 +61,6 @@ /** * Base abstract class for Checkstyle reports. - * - * */ public abstract class AbstractCheckstyleReport extends AbstractMavenReport { protected static final String JAVA_FILES = "**\\/*.java"; @@ -441,31 +438,34 @@ public abstract class AbstractCheckstyleReport extends AbstractMavenReport { @Parameter(property = "checkstyle.excludeGeneratedSources", defaultValue = "false") private boolean excludeGeneratedSources; - /** - */ - @Component protected ResourceManager locator; /** * @since 2.5 */ - @Component(role = CheckstyleExecutor.class, hint = "default") protected CheckstyleExecutor checkstyleExecutor; /** * Internationalization component */ - @Component private I18N i18n; protected ByteArrayOutputStream stringOutputStream; + public AbstractCheckstyleReport(ResourceManager locator, CheckstyleExecutor checkstyleExecutor, I18N i18n) { + this.locator = locator; + this.checkstyleExecutor = checkstyleExecutor; + this.i18n = i18n; + } + /** {@inheritDoc} */ + @Override public String getName(Locale locale) { return getI18nString(locale, "name"); } /** {@inheritDoc} */ + @Override public String getDescription(Locale locale) { return getI18nString(locale, "description"); } @@ -479,6 +479,7 @@ protected String getI18nString(Locale locale, String key) { return i18n.getString("checkstyle-report", locale, "report.checkstyle." + key); } + @Override protected MavenProject getProject() { return project; } @@ -488,6 +489,7 @@ protected List getReactorProjects() { } /** {@inheritDoc} */ + @Override public void executeReport(Locale locale) throws MavenReportException { checkDeprecatedParameterUsage(sourceDirectory, "sourceDirectory", "sourceDirectories"); checkDeprecatedParameterUsage(testSourceDirectory, "testSourceDirectory", "testSourceDirectories"); diff --git a/src/main/java/org/apache/maven/plugins/checkstyle/CheckstyleAggregateReport.java b/src/main/java/org/apache/maven/plugins/checkstyle/CheckstyleAggregateReport.java index d9144157..d2130d83 100644 --- a/src/main/java/org/apache/maven/plugins/checkstyle/CheckstyleAggregateReport.java +++ b/src/main/java/org/apache/maven/plugins/checkstyle/CheckstyleAggregateReport.java @@ -18,10 +18,15 @@ */ package org.apache.maven.plugins.checkstyle; +import javax.inject.Inject; + import org.apache.maven.plugins.annotations.Mojo; import org.apache.maven.plugins.annotations.ResolutionScope; +import org.apache.maven.plugins.checkstyle.exec.CheckstyleExecutor; import org.apache.maven.plugins.checkstyle.exec.CheckstyleExecutorRequest; import org.apache.maven.reporting.MavenReportException; +import org.codehaus.plexus.i18n.I18N; +import org.codehaus.plexus.resource.ResourceManager; /** * A reporting task that performs Checkstyle analysis and generates an aggregate @@ -36,9 +41,16 @@ requiresDependencyResolution = ResolutionScope.COMPILE, threadSafe = true) public class CheckstyleAggregateReport extends AbstractCheckstyleReport { + + @Inject + public CheckstyleAggregateReport(ResourceManager locator, CheckstyleExecutor checkstyleExecutor, I18N i18n) { + super(locator, checkstyleExecutor, i18n); + } + /** * {@inheritDoc} */ + @Override protected CheckstyleExecutorRequest createRequest() throws MavenReportException { CheckstyleExecutorRequest request = new CheckstyleExecutorRequest(); request.setAggregate(true) @@ -70,11 +82,13 @@ protected CheckstyleExecutorRequest createRequest() throws MavenReportException } /** {@inheritDoc} */ + @Override public String getOutputName() { return "checkstyle-aggregate"; } /** {@inheritDoc} */ + @Override public boolean canGenerateReport() { // TODO: would be good to scan the files here return !skip && project.isExecutionRoot() && reactorProjects.size() > 1; diff --git a/src/main/java/org/apache/maven/plugins/checkstyle/CheckstyleReport.java b/src/main/java/org/apache/maven/plugins/checkstyle/CheckstyleReport.java index b99abf2f..9c68322c 100644 --- a/src/main/java/org/apache/maven/plugins/checkstyle/CheckstyleReport.java +++ b/src/main/java/org/apache/maven/plugins/checkstyle/CheckstyleReport.java @@ -18,14 +18,19 @@ */ package org.apache.maven.plugins.checkstyle; +import javax.inject.Inject; + import java.io.File; import java.util.List; import org.apache.maven.model.Resource; import org.apache.maven.plugins.annotations.Mojo; import org.apache.maven.plugins.annotations.ResolutionScope; +import org.apache.maven.plugins.checkstyle.exec.CheckstyleExecutor; import org.apache.maven.plugins.checkstyle.exec.CheckstyleExecutorRequest; import org.apache.maven.reporting.MavenReportException; +import org.codehaus.plexus.i18n.I18N; +import org.codehaus.plexus.resource.ResourceManager; /** * A reporting task that performs Checkstyle analysis and generates an HTML @@ -38,9 +43,16 @@ */ @Mojo(name = "checkstyle", requiresDependencyResolution = ResolutionScope.COMPILE, threadSafe = true) public class CheckstyleReport extends AbstractCheckstyleReport { + + @Inject + public CheckstyleReport(ResourceManager locator, CheckstyleExecutor checkstyleExecutor, I18N i18n) { + super(locator, checkstyleExecutor, i18n); + } + /** * {@inheritDoc} */ + @Override protected CheckstyleExecutorRequest createRequest() throws MavenReportException { CheckstyleExecutorRequest request = new CheckstyleExecutorRequest(); request.setConsoleListener(getConsoleListener()) @@ -70,11 +82,13 @@ protected CheckstyleExecutorRequest createRequest() throws MavenReportException } /** {@inheritDoc} */ + @Override public String getOutputName() { return "checkstyle"; } /** {@inheritDoc} */ + @Override public boolean canGenerateReport() { if (skip) { return false; diff --git a/src/main/java/org/apache/maven/plugins/checkstyle/CheckstyleViolationCheckMojo.java b/src/main/java/org/apache/maven/plugins/checkstyle/CheckstyleViolationCheckMojo.java index 21a9802d..5c5fcf23 100644 --- a/src/main/java/org/apache/maven/plugins/checkstyle/CheckstyleViolationCheckMojo.java +++ b/src/main/java/org/apache/maven/plugins/checkstyle/CheckstyleViolationCheckMojo.java @@ -18,6 +18,9 @@ */ package org.apache.maven.plugins.checkstyle; +import javax.inject.Inject; +import javax.inject.Named; + import java.io.BufferedReader; import java.io.File; import java.io.FileNotFoundException; @@ -47,7 +50,6 @@ import org.apache.maven.plugin.MojoExecutionException; import org.apache.maven.plugin.MojoFailureException; import org.apache.maven.plugin.descriptor.PluginDescriptor; -import org.apache.maven.plugins.annotations.Component; import org.apache.maven.plugins.annotations.LifecyclePhase; import org.apache.maven.plugins.annotations.Mojo; import org.apache.maven.plugins.annotations.Parameter; @@ -294,12 +296,6 @@ public class CheckstyleViolationCheckMojo extends AbstractMojo { @Parameter(property = "encoding", defaultValue = "${project.build.sourceEncoding}") private String inputEncoding; - /** - * @since 2.5 - */ - @Component(role = CheckstyleExecutor.class, hint = "default") - protected CheckstyleExecutor checkstyleExecutor; - /** * Output errors to console. */ @@ -489,7 +485,18 @@ public class CheckstyleViolationCheckMojo extends AbstractMojo { private File outputXmlFile; + /** + * @since 2.5 + */ + protected CheckstyleExecutor checkstyleExecutor; + + @Inject + public CheckstyleViolationCheckMojo(final @Named("default") CheckstyleExecutor checkstyleExecutor) { + this.checkstyleExecutor = checkstyleExecutor; + } + /** {@inheritDoc} */ + @Override public void execute() throws MojoExecutionException, MojoFailureException { checkDeprecatedParameterUsage(sourceDirectory, "sourceDirectory", "sourceDirectories"); checkDeprecatedParameterUsage(testSourceDirectory, "testSourceDirectory", "testSourceDirectories"); diff --git a/src/main/java/org/apache/maven/plugins/checkstyle/exec/DefaultCheckstyleExecutor.java b/src/main/java/org/apache/maven/plugins/checkstyle/exec/DefaultCheckstyleExecutor.java index 1ad2baca..f5278229 100644 --- a/src/main/java/org/apache/maven/plugins/checkstyle/exec/DefaultCheckstyleExecutor.java +++ b/src/main/java/org/apache/maven/plugins/checkstyle/exec/DefaultCheckstyleExecutor.java @@ -18,6 +18,9 @@ */ package org.apache.maven.plugins.checkstyle.exec; +import javax.inject.Inject; +import javax.inject.Named; + import java.io.ByteArrayInputStream; import java.io.File; import java.io.FileInputStream; @@ -49,8 +52,6 @@ import org.apache.maven.artifact.DependencyResolutionRequiredException; import org.apache.maven.model.Resource; import org.apache.maven.project.MavenProject; -import org.codehaus.plexus.component.annotations.Component; -import org.codehaus.plexus.component.annotations.Requirement; import org.codehaus.plexus.logging.AbstractLogEnabled; import org.codehaus.plexus.resource.ResourceManager; import org.codehaus.plexus.resource.loader.FileResourceCreationException; @@ -61,16 +62,21 @@ /** * @author Olivier Lamy * @since 2.5 - * */ -@Component(role = CheckstyleExecutor.class, hint = "default", instantiationStrategy = "per-lookup") +@Named public class DefaultCheckstyleExecutor extends AbstractLogEnabled implements CheckstyleExecutor { - @Requirement(hint = "default") private ResourceManager locator; - @Requirement(hint = "license") private ResourceManager licenseLocator; + @Inject + public DefaultCheckstyleExecutor( + final @Named("default") ResourceManager locator, final @Named("license") ResourceManager licenseLocator) { + this.locator = locator; + this.licenseLocator = licenseLocator; + } + + @Override public CheckstyleResults executeCheckstyle(CheckstyleExecutorRequest request) throws CheckstyleExecutorException, CheckstyleException { if (getLogger().isDebugEnabled()) { @@ -255,6 +261,7 @@ protected void addSourceDirectory( } } + @Override public Configuration getConfiguration(CheckstyleExecutorRequest request) throws CheckstyleExecutorException { try { // Checkstyle will always use the context classloader in order