Skip to content

Commit 9e0d485

Browse files
committed
merge master
2 parents e418ac4 + b0ce8f7 commit 9e0d485

14 files changed

+148
-106
lines changed

pom.xml

Lines changed: 5 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -159,9 +159,9 @@ under the License.
159159

160160
<!-- plexus -->
161161
<dependency>
162-
<groupId>org.codehaus.plexus</groupId>
163-
<artifactId>plexus-component-annotations</artifactId>
164-
<version>2.2.0</version>
162+
<groupId>org.eclipse.sisu</groupId>
163+
<artifactId>org.eclipse.sisu.inject</artifactId>
164+
<scope>provided</scope>
165165
</dependency>
166166
<dependency>
167167
<groupId>org.codehaus.plexus</groupId>
@@ -325,16 +325,8 @@ under the License.
325325
</executions>
326326
</plugin>
327327
<plugin>
328-
<groupId>org.codehaus.plexus</groupId>
329-
<artifactId>plexus-component-metadata</artifactId>
330-
<version>2.2.0</version>
331-
<executions>
332-
<execution>
333-
<goals>
334-
<goal>generate-metadata</goal>
335-
</goals>
336-
</execution>
337-
</executions>
328+
<groupId>org.eclipse.sisu</groupId>
329+
<artifactId>sisu-maven-plugin</artifactId>
338330
</plugin>
339331
</plugins>
340332
</build>

src/main/java/org/apache/maven/plugins/checkstyle/AbstractCheckstyleReport.java

Lines changed: 12 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,6 @@
4444
import org.apache.maven.model.PluginManagement;
4545
import org.apache.maven.model.Resource;
4646
import org.apache.maven.plugin.descriptor.PluginDescriptor;
47-
import org.apache.maven.plugins.annotations.Component;
4847
import org.apache.maven.plugins.annotations.Parameter;
4948
import org.apache.maven.plugins.checkstyle.exec.CheckstyleExecutor;
5049
import org.apache.maven.plugins.checkstyle.exec.CheckstyleExecutorException;
@@ -58,12 +57,9 @@
5857
import org.codehaus.plexus.resource.ResourceManager;
5958
import org.codehaus.plexus.resource.loader.FileResourceLoader;
6059
import org.codehaus.plexus.util.FileUtils;
61-
import org.codehaus.plexus.util.PathTool;
6260

6361
/**
6462
* Base abstract class for Checkstyle reports.
65-
*
66-
*
6763
*/
6864
public abstract class AbstractCheckstyleReport extends AbstractMavenReport {
6965
protected static final String JAVA_FILES = "**\\/*.java";
@@ -441,31 +437,35 @@ public abstract class AbstractCheckstyleReport extends AbstractMavenReport {
441437
@Parameter(property = "checkstyle.excludeGeneratedSources", defaultValue = "false")
442438
private boolean excludeGeneratedSources;
443439

444-
/**
445-
*/
446-
@Component
447440
protected ResourceManager locator;
448441

449442
/**
450443
* @since 2.5
451444
*/
452-
@Component(role = CheckstyleExecutor.class, hint = "default")
453-
protected CheckstyleExecutor checkstyleExecutor;
445+
protected final CheckstyleExecutor checkstyleExecutor;
454446

455447
/**
456448
* Internationalization component
457449
*/
458-
@Component
459450
private I18N i18n;
460451

461452
protected ByteArrayOutputStream stringOutputStream;
462453

454+
public AbstractCheckstyleReport(
455+
final ResourceManager locator, final CheckstyleExecutor checkstyleExecutor, final I18N i18n) {
456+
this.locator = locator;
457+
this.checkstyleExecutor = checkstyleExecutor;
458+
this.i18n = i18n;
459+
}
460+
463461
/** {@inheritDoc} */
462+
@Override
464463
public String getName(Locale locale) {
465464
return getI18nString(locale, "name");
466465
}
467466

468467
/** {@inheritDoc} */
468+
@Override
469469
public String getDescription(Locale locale) {
470470
return getI18nString(locale, "description");
471471
}
@@ -479,6 +479,7 @@ protected String getI18nString(Locale locale, String key) {
479479
return i18n.getString("checkstyle-report", locale, "report.checkstyle." + key);
480480
}
481481

482+
@Override
482483
protected MavenProject getProject() {
483484
return project;
484485
}
@@ -488,6 +489,7 @@ protected List<MavenProject> getReactorProjects() {
488489
}
489490

490491
/** {@inheritDoc} */
492+
@Override
491493
public void executeReport(Locale locale) throws MavenReportException {
492494
checkDeprecatedParameterUsage(sourceDirectory, "sourceDirectory", "sourceDirectories");
493495
checkDeprecatedParameterUsage(testSourceDirectory, "testSourceDirectory", "testSourceDirectories");
@@ -675,16 +677,6 @@ protected AuditListener getConsoleListener() throws MavenReportException {
675677
return consoleListener;
676678
}
677679

678-
private String determineRelativePath(File location) {
679-
String relativePath =
680-
PathTool.getRelativePath(getReportOutputDirectory().getAbsolutePath(), location.getAbsolutePath());
681-
if (relativePath == null || relativePath.trim().isEmpty()) {
682-
relativePath = ".";
683-
}
684-
685-
return relativePath + "/" + location.getName();
686-
}
687-
688680
protected List<File> getSourceDirectories() {
689681
if (sourceDirectories == null) {
690682
sourceDirectories = filterBuildTarget(project.getCompileSourceRoots());

src/main/java/org/apache/maven/plugins/checkstyle/CheckstyleAggregateReport.java

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,27 +18,39 @@
1818
*/
1919
package org.apache.maven.plugins.checkstyle;
2020

21+
import javax.inject.Inject;
22+
import javax.inject.Named;
23+
2124
import org.apache.maven.plugins.annotations.Mojo;
2225
import org.apache.maven.plugins.annotations.ResolutionScope;
26+
import org.apache.maven.plugins.checkstyle.exec.CheckstyleExecutor;
2327
import org.apache.maven.plugins.checkstyle.exec.CheckstyleExecutorRequest;
2428
import org.apache.maven.reporting.MavenReportException;
29+
import org.codehaus.plexus.i18n.I18N;
30+
import org.codehaus.plexus.resource.ResourceManager;
2531

2632
/**
2733
* A reporting task that performs Checkstyle analysis and generates an aggregate
2834
* HTML report on the violations that Checkstyle finds in a multi-module reactor
2935
* build.
30-
*
31-
*
3236
*/
3337
@Mojo(
3438
name = "checkstyle-aggregate",
3539
aggregator = true,
3640
requiresDependencyResolution = ResolutionScope.COMPILE,
3741
threadSafe = true)
3842
public class CheckstyleAggregateReport extends AbstractCheckstyleReport {
43+
44+
@Inject
45+
public CheckstyleAggregateReport(
46+
ResourceManager locator, @Named("default") CheckstyleExecutor checkstyleExecutor, I18N i18n) {
47+
super(locator, checkstyleExecutor, i18n);
48+
}
49+
3950
/**
4051
* {@inheritDoc}
4152
*/
53+
@Override
4254
protected CheckstyleExecutorRequest createRequest() throws MavenReportException {
4355
CheckstyleExecutorRequest request = new CheckstyleExecutorRequest();
4456
request.setAggregate(true)
@@ -70,11 +82,13 @@ protected CheckstyleExecutorRequest createRequest() throws MavenReportException
7082
}
7183

7284
/** {@inheritDoc} */
85+
@Override
7386
public String getOutputName() {
7487
return "checkstyle-aggregate";
7588
}
7689

7790
/** {@inheritDoc} */
91+
@Override
7892
public boolean canGenerateReport() {
7993
// TODO: would be good to scan the files here
8094
return !skip && project.isExecutionRoot() && reactorProjects.size() > 1;

src/main/java/org/apache/maven/plugins/checkstyle/CheckstyleReport.java

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,14 +18,20 @@
1818
*/
1919
package org.apache.maven.plugins.checkstyle;
2020

21+
import javax.inject.Inject;
22+
import javax.inject.Named;
23+
2124
import java.io.File;
2225
import java.util.List;
2326

2427
import org.apache.maven.model.Resource;
2528
import org.apache.maven.plugins.annotations.Mojo;
2629
import org.apache.maven.plugins.annotations.ResolutionScope;
30+
import org.apache.maven.plugins.checkstyle.exec.CheckstyleExecutor;
2731
import org.apache.maven.plugins.checkstyle.exec.CheckstyleExecutorRequest;
2832
import org.apache.maven.reporting.MavenReportException;
33+
import org.codehaus.plexus.i18n.I18N;
34+
import org.codehaus.plexus.resource.ResourceManager;
2935

3036
/**
3137
* A reporting task that performs Checkstyle analysis and generates an HTML
@@ -38,9 +44,19 @@
3844
*/
3945
@Mojo(name = "checkstyle", requiresDependencyResolution = ResolutionScope.COMPILE, threadSafe = true)
4046
public class CheckstyleReport extends AbstractCheckstyleReport {
47+
48+
@Inject
49+
public CheckstyleReport(
50+
final ResourceManager locator,
51+
final @Named("default") CheckstyleExecutor checkstyleExecutor,
52+
final I18N i18n) {
53+
super(locator, checkstyleExecutor, i18n);
54+
}
55+
4156
/**
4257
* {@inheritDoc}
4358
*/
59+
@Override
4460
protected CheckstyleExecutorRequest createRequest() throws MavenReportException {
4561
CheckstyleExecutorRequest request = new CheckstyleExecutorRequest();
4662
request.setConsoleListener(getConsoleListener())
@@ -70,11 +86,13 @@ protected CheckstyleExecutorRequest createRequest() throws MavenReportException
7086
}
7187

7288
/** {@inheritDoc} */
89+
@Override
7390
public String getOutputName() {
7491
return "checkstyle";
7592
}
7693

7794
/** {@inheritDoc} */
95+
@Override
7896
public boolean canGenerateReport() {
7997
if (skip) {
8098
return false;

src/main/java/org/apache/maven/plugins/checkstyle/CheckstyleReportRenderer.java

Lines changed: 25 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,6 @@
4040

4141
/**
4242
* Generate a report based on CheckstyleResults.
43-
*
44-
*
4543
*/
4644
public class CheckstyleReportRenderer extends AbstractMavenReportRenderer {
4745
private static final int NO_TEXT = 0;
@@ -120,6 +118,7 @@ private String getI18nString(String key) {
120118
return i18n.getString("checkstyle-report", locale, "report.checkstyle." + key);
121119
}
122120

121+
@Override
123122
protected void renderBody() {
124123
startSection(getTitle());
125124

@@ -150,31 +149,31 @@ protected void renderBody() {
150149
}
151150

152151
/**
153-
* Get the value of the specified attribute from the Checkstyle configuration.
152+
* Get the value of the specified property from the Checkstyle configuration.
154153
* If parentConfigurations is non-null and non-empty, the parent
155-
* configurations are searched if the attribute cannot be found in the
156-
* current configuration. If the attribute is still not found, the
154+
* configurations are searched if the property cannot be found in the
155+
* current configuration. If the property is still not found, the
157156
* specified default value will be returned.
158157
*
159-
* @param config The current Checkstyle configuration
160-
* @param parentConfiguration The configuration of the parent of the current configuration
161-
* @param attributeName The name of the attribute
162-
* @param defaultValue The default value to use if the attribute cannot be found in any configuration
163-
* @return The value of the specified attribute
158+
* @param config the current Checkstyle configuration
159+
* @param parentConfiguration the configuration of the parent of the current configuration
160+
* @param propertyName the name of the property
161+
* @param defaultValue the default value to use if the property cannot be found in any configuration
162+
* @return the value of the specified property
164163
*/
165-
private String getConfigAttribute(
164+
private String getConfigProperty(
166165
Configuration config,
167166
ChainedItem<Configuration> parentConfiguration,
168-
String attributeName,
167+
String propertyName,
169168
String defaultValue) {
170169
String ret;
171170
try {
172-
ret = config.getAttribute(attributeName);
171+
ret = config.getProperty(propertyName);
173172
} catch (CheckstyleException e) {
174-
// Try to find the attribute in a parent, if there are any
173+
// Try to find the property in a parent, if there are any
175174
if (parentConfiguration != null) {
176-
ret = getConfigAttribute(
177-
parentConfiguration.value, parentConfiguration.parent, attributeName, defaultValue);
175+
ret = getConfigProperty(
176+
parentConfiguration.value, parentConfiguration.parent, propertyName, defaultValue);
178177
} else {
179178
ret = defaultValue;
180179
}
@@ -185,7 +184,7 @@ private String getConfigAttribute(
185184
/**
186185
* Create the rules summary section of the report.
187186
*
188-
* @param results The results to summarize
187+
* @param results the results to summarize
189188
*/
190189
private void renderRulesSummarySection() {
191190
if (!enableRulesSummary) {
@@ -256,16 +255,16 @@ private void renderRuleRow(ConfReference ref, CheckstyleResults results, String
256255
sink.text(ruleName);
257256
}
258257

259-
List<String> attribnames = new ArrayList<>(Arrays.asList(checkerConfig.getAttributeNames()));
260-
attribnames.remove("severity"); // special value (deserves unique column)
261-
if (!attribnames.isEmpty()) {
258+
List<String> propertyNames = new ArrayList<>(Arrays.asList(checkerConfig.getPropertyNames()));
259+
propertyNames.remove("severity"); // special value (deserves unique column)
260+
if (!propertyNames.isEmpty()) {
262261
sink.list();
263-
for (String name : attribnames) {
262+
for (String name : propertyNames) {
264263
sink.listItem();
265264

266265
sink.text(name);
267266

268-
String value = getConfigAttribute(checkerConfig, null, name, "");
267+
String value = getConfigProperty(checkerConfig, null, name, "");
269268
// special case, Header.header and RegexpHeader.header
270269
if ("header".equals(name) && ("Header".equals(ruleName) || "RegexpHeader".equals(ruleName))) {
271270
String[] lines = StringUtils.split(value, "\\n");
@@ -316,7 +315,7 @@ private void renderRuleRow(ConfReference ref, CheckstyleResults results, String
316315
sink.tableCell();
317316
// Grab the severity from the rule configuration, this time use error as default value
318317
// Also pass along all parent configurations, so that we can try to find the severity there
319-
String severity = getConfigAttribute(checkerConfig, parentConfiguration, "severity", "error");
318+
String severity = getConfigProperty(checkerConfig, parentConfiguration, "severity", "error");
320319
iconSeverity(severity, TEXT_SIMPLE);
321320
sink.tableCell_();
322321

@@ -626,11 +625,11 @@ private void sortConfiguration(
626625
// special sub-case: TreeWalker is the parent of multiple rules, not an effective rule
627626
sortConfiguration(result, childConfig, new ChainedItem<>(config, parent), results);
628627
} else {
629-
String fixedmessage = getConfigAttribute(childConfig, null, "message", null);
628+
String fixedmessage = getConfigProperty(childConfig, null, "message", null);
630629
// Grab the severity from the rule configuration. Do not set default value here as
631630
// it breaks our rule aggregate section entirely. The counts are off but this is
632631
// not appropriate fix location per MCHECKSTYLE-365.
633-
String configSeverity = getConfigAttribute(childConfig, null, "severity", null);
632+
String configSeverity = getConfigProperty(childConfig, null, "severity", null);
634633

635634
// count rule violations
636635
long violations = 0;
@@ -674,6 +673,7 @@ private static class ConfReference implements Comparable<ConfReference> {
674673
this.count = count;
675674
}
676675

676+
@Override
677677
public int compareTo(ConfReference o) {
678678
int compare = category.compareTo(o.category);
679679
if (compare == 0) {

0 commit comments

Comments
 (0)