You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@maven.apache.org by sl...@apache.org on 2021/04/05 20:19:05 UTC
[maven-checkstyle-plugin] branch MCHECKSTYLE-289 updated (b7fba80
-> 8e3c248)
This is an automated email from the ASF dual-hosted git repository.
slachiewicz pushed a change to branch MCHECKSTYLE-289
in repository https://gitbox.apache.org/repos/asf/maven-checkstyle-plugin.git.
discard b7fba80 [MCHECKSTYLE-289] enableRulesSummary option does not show Rules with default configuration
add 2e93263 [MCHECKSTYLE-358] fix mailing list addres
add a233a05 update maven site plugin
add bd76a6f update maven site plugin
add 1656f61 Merge pull request #31 from apache/dox
add bde7932 (doc) Remove method to simply inherit it (#29)
add 36bde8d (doc) Remove unnecessary casts (#30)
add a2a054d added link to doc
add edaeaf8 added ASF Jira badge
add 1b2f990 fixed typo
add a0c6695 fixed broken links (MPIR 3)
add f4019c9 added README
add 84bb9b4 README improvement
add d16d027 (doc) Remove expression that always evaluates to true
add e138af1 add Reproducible Builds ok badge
add 4f16501 update ASF CI url
add 0f6269d update ASF CI url
add 354fad1 update JUnit
add 1ec4c24 Merge pull request #37 from apache/ver
add d8522d5 remove unused dependency
add 895b91f Merge pull request #38 from apache/ver2
add 4b4101c use try with resources instead of deprecated method
add 04be4e1 Merge pull request #39 from apache/close
add bd635da remove unused imports
add 91b8b16 Merge pull request #40 from apache/ver3
add 7688eb9 [MCHECKSTYLE-387] emit a warning when using an old version of checkstyle.
add b259e84 [MCHECKSTYLE-385] Violation should be a value class
add 102e135 Add Github Actions tests for Java 8, 11, 16-ea and 17-ea
add 358c969 Bump animal-sniffer-maven-plugin from 1.18 to 1.19
add 7b92b74 Update maven-project-info-reports-plugin to 3.1.1
add 29ab795 [MCHECKSTYLE-392] Update historical release notes
add 3af1ab2 [MCHECKSTYLE-400] remove .travis.yml
add 8295569 Bump junit from 4.8.1 to 4.13.1 in /src/it/MCHECKSTYLE-163
add b5bb87f Bump build-helper-maven-plugin from 3.0.0 to 3.2.0
add 6b69179 Upgrade plugins
add a5aeeaf Use maven-checkstyle-plugin 3.1.1
add 27b9ef3 [maven-release-plugin] prepare release maven-checkstyle-plugin-3.1.2
new 8e3c248 [MCHECKSTYLE-289] enableRulesSummary option does not show Rules with default configuration
This update added new revisions after undoing existing revisions.
That is to say, some revisions that were in the old version of the
branch are not in the new version. This situation occurs
when a user --force pushes a change and generates a repository
containing something like this:
* -- * -- B -- O -- O -- O (b7fba80)
\
N -- N -- N refs/heads/MCHECKSTYLE-289 (8e3c248)
You should already have received notification emails for all of the O
revisions, and so the following emails describe only the N revisions
from the common base, B.
Any revisions marked "omit" are not gone; other references still
refer to them. Any revisions marked "discard" are gone forever.
The 1 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails. The revisions
listed as "add" were already present in the repository and have only
been added to this reference.
Summary of changes:
.asf.yaml | 26 +++
.github/workflows/maven.yml | 51 +++++
.travis.yml | 33 ---
CONTRIBUTING.md | 91 --------
README.md | 23 ++-
pom.xml | 50 +++--
src/it/MCHECKSTYLE-163/pom.xml | 2 +-
.../checkstyle/AbstractCheckstyleReport.java | 2 +-
.../maven/plugins/checkstyle/CheckstyleReport.java | 8 -
.../checkstyle/CheckstyleViolationCheckMojo.java | 139 +++++++++----
.../maven/plugins/checkstyle/ReportResource.java | 2 +-
.../apache/maven/plugins/checkstyle/Violation.java | 229 +++++++++++++++++++++
.../checkstyle/exec/DefaultCheckstyleExecutor.java | 21 +-
.../resource/LicenseResourceManager.java | 2 +-
src/site/apt/index.apt.vm | 6 +-
src/site/markdown/history.md.vm | 26 ++-
.../plugins/checkstyle/CheckstyleReportTest.java | 1 -
.../CheckstyleViolationCheckMojoTest.java | 1 -
.../plugins/checkstyle/ReportResourceTest.java | 1 -
.../CheckstyleReportListenerMultiSourceTest.java | 6 -
.../exec/CheckstyleReportListenerTest.java | 3 -
.../checkstyle/exec/CheckstyleResultsTest.java | 3 -
22 files changed, 485 insertions(+), 241 deletions(-)
create mode 100644 .asf.yaml
create mode 100644 .github/workflows/maven.yml
delete mode 100644 .travis.yml
delete mode 100644 CONTRIBUTING.md
create mode 100644 src/main/java/org/apache/maven/plugins/checkstyle/Violation.java
[maven-checkstyle-plugin] 01/01: [MCHECKSTYLE-289]
enableRulesSummary option does not show Rules with default configuration
Posted by sl...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
slachiewicz pushed a commit to branch MCHECKSTYLE-289
in repository https://gitbox.apache.org/repos/asf/maven-checkstyle-plugin.git
commit 8e3c24893f7f8709ed1da1abc880f9bc5cb4760f
Author: Guillaume Boué <gb...@apache.org>
AuthorDate: Sat Apr 7 23:56:18 2018 +0200
[MCHECKSTYLE-289] enableRulesSummary option does not show Rules with
default configuration
Add parameter to explicitly show rules without any violations in the
Rules summary.
---
src/it/MCHECKSTYLE-289/checkstyle.xml | 27 +++++++++
src/it/MCHECKSTYLE-289/pom.xml | 53 ++++++++++++++++++
.../MCHECKSTYLE-289/src/main/java/org/MyClass.java | 26 +++++++++
src/it/MCHECKSTYLE-289/verify.groovy | 22 ++++++++
.../checkstyle/AbstractCheckstyleReport.java | 9 +++
.../checkstyle/CheckstyleReportGenerator.java | 24 ++++++--
.../checkstyle/exec/CheckstyleModuleFactory.java | 64 ++++++++++++++++++++++
.../plugins/checkstyle/exec/CheckstyleResults.java | 11 ++++
.../checkstyle/exec/DefaultCheckstyleExecutor.java | 9 ++-
9 files changed, 237 insertions(+), 8 deletions(-)
diff --git a/src/it/MCHECKSTYLE-289/checkstyle.xml b/src/it/MCHECKSTYLE-289/checkstyle.xml
new file mode 100644
index 0000000..564a7ab
--- /dev/null
+++ b/src/it/MCHECKSTYLE-289/checkstyle.xml
@@ -0,0 +1,27 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ ~ Licensed to the Apache Software Foundation (ASF) under one
+ ~ or more contributor license agreements. See the NOTICE file
+ ~ distributed with this work for additional information
+ ~ regarding copyright ownership. The ASF licenses this file
+ ~ to you under the Apache License, Version 2.0 (the
+ ~ "License"); you may not use this file except in compliance
+ ~ with the License. You may obtain a copy of the License at
+ ~
+ ~ http://www.apache.org/licenses/LICENSE-2.0
+ ~
+ ~ Unless required by applicable law or agreed to in writing,
+ ~ software distributed under the License is distributed on an
+ ~ "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ ~ KIND, either express or implied. See the License for the
+ ~ specific language governing permissions and limitations
+ ~ under the License.
+ -->
+<!DOCTYPE module PUBLIC "-//Puppy Crawl//DTD Check Configuration 1.2//EN" "http://www.puppycrawl.com/dtds/configuration_1_2.dtd">
+<module name="Checker">
+ <module name="TreeWalker">
+ <module name="OuterTypeFilename"/>
+ </module>
+ <!-- add module that is not a check to verify that it does not interfere -->
+ <module name="SuppressionCommentFilter"/>
+</module>
diff --git a/src/it/MCHECKSTYLE-289/pom.xml b/src/it/MCHECKSTYLE-289/pom.xml
new file mode 100644
index 0000000..1ad0dcb
--- /dev/null
+++ b/src/it/MCHECKSTYLE-289/pom.xml
@@ -0,0 +1,53 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ ~ Licensed to the Apache Software Foundation (ASF) under one
+ ~ or more contributor license agreements. See the NOTICE file
+ ~ distributed with this work for additional information
+ ~ regarding copyright ownership. The ASF licenses this file
+ ~ to you under the Apache License, Version 2.0 (the
+ ~ "License"); you may not use this file except in compliance
+ ~ with the License. You may obtain a copy of the License at
+ ~
+ ~ http://www.apache.org/licenses/LICENSE-2.0
+ ~
+ ~ Unless required by applicable law or agreed to in writing,
+ ~ software distributed under the License is distributed on an
+ ~ "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ ~ KIND, either express or implied. See the License for the
+ ~ specific language governing permissions and limitations
+ ~ under the License.
+ -->
+
+<project xmlns="http://maven.apache.org/POM/4.0.0"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
+ <modelVersion>4.0.0</modelVersion>
+ <groupId>org.apache.maven.plugins.checkstyle</groupId>
+ <artifactId>mcheckstytle-289</artifactId>
+ <version>1.0</version>
+ <url>https://issues.apache.org/jira/browse/MCHECKSTYLE-289</url>
+ <description>Tests that setting skipEmptyViolationRules to false correctly shows rules with no violations</description>
+ <properties>
+ <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
+ </properties>
+ <reporting>
+ <plugins>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-checkstyle-plugin</artifactId>
+ <version>@pom.version@</version>
+ <configuration>
+ <configLocation>checkstyle.xml</configLocation>
+ <skipEmptyViolationRules>false</skipEmptyViolationRules>
+ </configuration>
+ <reportSets>
+ <reportSet>
+ <reports>
+ <report>checkstyle</report>
+ </reports>
+ </reportSet>
+ </reportSets>
+ </plugin>
+ </plugins>
+ </reporting>
+</project>
diff --git a/src/it/MCHECKSTYLE-289/src/main/java/org/MyClass.java b/src/it/MCHECKSTYLE-289/src/main/java/org/MyClass.java
new file mode 100644
index 0000000..967d603
--- /dev/null
+++ b/src/it/MCHECKSTYLE-289/src/main/java/org/MyClass.java
@@ -0,0 +1,26 @@
+package org;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+/**
+ * My Class.
+ */
+public class MyClass {
+}
diff --git a/src/it/MCHECKSTYLE-289/verify.groovy b/src/it/MCHECKSTYLE-289/verify.groovy
new file mode 100644
index 0000000..c0f3700
--- /dev/null
+++ b/src/it/MCHECKSTYLE-289/verify.groovy
@@ -0,0 +1,22 @@
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+def html = new File( basedir, 'target/site/checkstyle.html' ).text;
+assert html =~ /(?s)<td>misc<\/td>.*?<td>.*?OuterTypeFilename.*?<\/td>.*?<td>0<\/td>/
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 3b958ff..a6ed116 100644
--- a/src/main/java/org/apache/maven/plugins/checkstyle/AbstractCheckstyleReport.java
+++ b/src/main/java/org/apache/maven/plugins/checkstyle/AbstractCheckstyleReport.java
@@ -360,6 +360,14 @@ public abstract class AbstractCheckstyleReport
private boolean enableRSS;
/**
+ * Specifies if rules with no violations should be skipped from the Rules summary.
+ *
+ * @since 3.0.1
+ */
+ @Parameter( property = "checkstyle.skipEmptyViolationRules", defaultValue = "true" )
+ private boolean skipEmptyViolationRules;
+
+ /**
* SiteTool.
*
* @since 2.2
@@ -740,6 +748,7 @@ public abstract class AbstractCheckstyleReport
generator.setEnableSeveritySummary( enableSeveritySummary );
generator.setEnableFilesSummary( enableFilesSummary );
generator.setEnableRSS( enableRSS );
+ generator.setSkipEmptyViolationRules( skipEmptyViolationRules );
generator.setCheckstyleConfig( results.getConfiguration() );
if ( linkXRef )
{
diff --git a/src/main/java/org/apache/maven/plugins/checkstyle/CheckstyleReportGenerator.java b/src/main/java/org/apache/maven/plugins/checkstyle/CheckstyleReportGenerator.java
index aae277d..d179e81 100644
--- a/src/main/java/org/apache/maven/plugins/checkstyle/CheckstyleReportGenerator.java
+++ b/src/main/java/org/apache/maven/plugins/checkstyle/CheckstyleReportGenerator.java
@@ -65,6 +65,8 @@ public class CheckstyleReportGenerator
private boolean enableFilesSummary;
+ private boolean skipEmptyViolationRules;
+
private boolean enableRSS;
private final SiteTool siteTool;
@@ -740,6 +742,16 @@ public class CheckstyleReportGenerator
this.enableRSS = enableRSS;
}
+ public boolean isSkipEmptyViolationRules()
+ {
+ return skipEmptyViolationRules;
+ }
+
+ public void setSkipEmptyViolationRules( boolean showEmptyViolationRules )
+ {
+ this.skipEmptyViolationRules = showEmptyViolationRules;
+ }
+
public String getXrefLocation()
{
return xrefLocation;
@@ -814,24 +826,24 @@ public class CheckstyleReportGenerator
// count rule violations
long violations = 0;
- AuditEvent lastMatchedEvent = null;
for ( List<AuditEvent> errors : results.getFiles().values() )
{
for ( AuditEvent event : errors )
{
if ( matchRule( event, ruleName, fixedmessage, configSeverity ) )
{
- lastMatchedEvent = event;
violations++;
}
}
}
- if ( violations > 0 ) // forget rules without violations
+ if ( violations > 0 || !skipEmptyViolationRules ) // forget rules without violations when not requested
{
- String category = RuleUtil.getCategory( lastMatchedEvent );
-
- result.add( new ConfReference( category, childConfig, parent, violations, result.size() ) );
+ String category = RuleUtil.getCategory( results.getModuleNameMap().get( ruleName ) );
+ if ( category != null )
+ {
+ result.add( new ConfReference( category, childConfig, parent, violations, result.size() ) );
+ }
}
}
}
diff --git a/src/main/java/org/apache/maven/plugins/checkstyle/exec/CheckstyleModuleFactory.java b/src/main/java/org/apache/maven/plugins/checkstyle/exec/CheckstyleModuleFactory.java
new file mode 100644
index 0000000..a5ba0fd
--- /dev/null
+++ b/src/main/java/org/apache/maven/plugins/checkstyle/exec/CheckstyleModuleFactory.java
@@ -0,0 +1,64 @@
+package org.apache.maven.plugins.checkstyle.exec;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+import java.util.Collections;
+import java.util.Map;
+import java.util.Set;
+import java.util.concurrent.ConcurrentHashMap;
+
+import com.puppycrawl.tools.checkstyle.PackageObjectFactory;
+import com.puppycrawl.tools.checkstyle.api.AbstractViolationReporter;
+import com.puppycrawl.tools.checkstyle.api.CheckstyleException;
+
+/**
+ * Extension of the package object factory, which remembers the check class name from a given name.
+ *
+ * @author gboue
+ */
+public class CheckstyleModuleFactory
+ extends PackageObjectFactory
+{
+
+ private Map<String, String> moduleNameMap = new ConcurrentHashMap<>();
+
+ public CheckstyleModuleFactory( Set<String> packageNames, ClassLoader moduleClassLoader )
+ {
+ super( packageNames, moduleClassLoader );
+ }
+
+ @Override
+ public Object createModule( String name )
+ throws CheckstyleException
+ {
+ Object module = super.createModule( name );
+ if ( module instanceof AbstractViolationReporter )
+ {
+ moduleNameMap.put( name, module.getClass().getName() );
+ }
+ return module;
+ }
+
+ public Map<String, String> getModuleNameMap()
+ {
+ return Collections.unmodifiableMap( moduleNameMap );
+ }
+
+}
diff --git a/src/main/java/org/apache/maven/plugins/checkstyle/exec/CheckstyleResults.java b/src/main/java/org/apache/maven/plugins/checkstyle/exec/CheckstyleResults.java
index a82870f..6a85098 100644
--- a/src/main/java/org/apache/maven/plugins/checkstyle/exec/CheckstyleResults.java
+++ b/src/main/java/org/apache/maven/plugins/checkstyle/exec/CheckstyleResults.java
@@ -38,6 +38,7 @@ import java.util.Map;
public class CheckstyleResults
{
private Map<String, List<AuditEvent>> files;
+ private Map<String, String> moduleNameMap;
private Configuration configuration;
@@ -141,4 +142,14 @@ public class CheckstyleResults
{
this.configuration = configuration;
}
+
+ public Map<String, String> getModuleNameMap()
+ {
+ return moduleNameMap;
+ }
+
+ public void setModuleNameMap( Map<String, String> moduleNameMap )
+ {
+ this.moduleNameMap = moduleNameMap;
+ }
}
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 94a01e0..d7be0a4 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
@@ -157,7 +157,10 @@ public class DefaultCheckstyleExecutor
setUpCheckstyleClassloader( checker, classPathStrings, outputDirectories );
- checker.setModuleClassLoader( Thread.currentThread().getContextClassLoader() );
+ ClassLoader moduleClassLoader = Thread.currentThread().getContextClassLoader();
+ CheckstyleModuleFactory moduleFactory =
+ new CheckstyleModuleFactory( PackageNamesLoader.getPackageNames( moduleClassLoader ), moduleClassLoader );
+ checker.setModuleFactory( moduleFactory );
if ( filterSet != null )
{
@@ -254,7 +257,9 @@ public class DefaultCheckstyleExecutor
}
}
- return checkerListener.getResults();
+ CheckstyleResults results = checkerListener.getResults();
+ results.setModuleNameMap( moduleFactory.getModuleNameMap() );
+ return results;
}
private void setUpCheckstyleClassloader( Checker checker,