From ebe1744c6434991755fd5d3ed77adcf7f3da57f9 Mon Sep 17 00:00:00 2001 From: Enrico Olivelli Date: Sat, 13 Apr 2019 08:05:12 +0200 Subject: [PATCH] MCHECKSTYLE-366 Upgrade checkstyle to a more recent version and require Java 8 as Checkstyle 7+ requires Java 8 --- Jenkinsfile | 2 +- pom.xml | 6 +- src/it/MCHECKSTYLE-129/pom.xml | 2 +- src/it/MCHECKSTYLE-137/checkstyle.xml | 9 +- .../src/main/java/org/MyClass.java | 17 +- .../com/company/build-tools/checkstyle.xml | 1 - src/it/MCHECKSTYLE-193/checkstyle.xml | 3 - .../plugins/checkstyle/EmptyLoggingCheck.java | 9 +- .../maven/plugins/checkstyle/its/AppTest.java | 4 +- .../multi-modules-aggregate/maven_checks.xml | 205 ++++++++++++++++++ src/it/multi-modules-aggregate/pom.xml | 12 +- src/it/multi-modules-aggregate/verify.groovy | 3 +- .../exec/CheckstyleCheckerListener.java | 16 +- 13 files changed, 245 insertions(+), 44 deletions(-) create mode 100644 src/it/multi-modules-aggregate/maven_checks.xml diff --git a/Jenkinsfile b/Jenkinsfile index e9f05f7d..d472c6f2 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -17,4 +17,4 @@ * under the License. */ -asfMavenTlpPlgnBuild() +asfMavenTlpPlgnBuild(jdk:['8','9','10','11','12']) diff --git a/pom.xml b/pom.xml index ab1627dd..22f43589 100644 --- a/pom.xml +++ b/pom.xml @@ -63,12 +63,12 @@ under the License. - - 7 + + 8 1.${javaVersion} 1.${javaVersion} 3.0 - 6.18 + 8.19 1.4 3.7.1 diff --git a/src/it/MCHECKSTYLE-129/pom.xml b/src/it/MCHECKSTYLE-129/pom.xml index 97cbfdde..81354a7a 100644 --- a/src/it/MCHECKSTYLE-129/pom.xml +++ b/src/it/MCHECKSTYLE-129/pom.xml @@ -57,7 +57,7 @@ under the License. maven-checkstyle-plugin ${checkstyleVersion} - http://svn.apache.org/repos/asf/maven/plugins/tags/maven-checkstyle-plugin-2.15/src/main/resources/config/sun_checks.xml + https://raw.githubusercontent.com/checkstyle/checkstyle/master/src/main/resources/sun_checks.xml diff --git a/src/it/MCHECKSTYLE-137/checkstyle.xml b/src/it/MCHECKSTYLE-137/checkstyle.xml index 4979f119..d4316c3d 100644 --- a/src/it/MCHECKSTYLE-137/checkstyle.xml +++ b/src/it/MCHECKSTYLE-137/checkstyle.xml @@ -20,8 +20,6 @@ under the License. - - @@ -89,7 +87,7 @@ under the License. - + @@ -98,7 +96,6 @@ under the License. - @@ -117,7 +114,6 @@ under the License. - @@ -125,7 +121,7 @@ under the License. - @@ -152,7 +148,6 @@ under the License. - diff --git a/src/it/MCHECKSTYLE-137/src/main/java/org/MyClass.java b/src/it/MCHECKSTYLE-137/src/main/java/org/MyClass.java index cc9677b2..272b913d 100644 --- a/src/it/MCHECKSTYLE-137/src/main/java/org/MyClass.java +++ b/src/it/MCHECKSTYLE-137/src/main/java/org/MyClass.java @@ -18,16 +18,13 @@ * specific language governing permissions and limitations * under the License. */ +public class MyClass { -public class MyClass -{ public static boolean singleCharHiragana(int v1, char v2) { - if (v1 != 12 || c == 'の') - { - return true; - } - else - { - return false; - } + if (v1 != 12 || c == 'の') { + return true; + } else { + return false; + } + } } diff --git a/src/it/MCHECKSTYLE-169/build-tools/src/main/resources/com/company/build-tools/checkstyle.xml b/src/it/MCHECKSTYLE-169/build-tools/src/main/resources/com/company/build-tools/checkstyle.xml index bdfae833..bedb23f9 100644 --- a/src/it/MCHECKSTYLE-169/build-tools/src/main/resources/com/company/build-tools/checkstyle.xml +++ b/src/it/MCHECKSTYLE-169/build-tools/src/main/resources/com/company/build-tools/checkstyle.xml @@ -27,7 +27,6 @@ under the License. - diff --git a/src/it/MCHECKSTYLE-193/checkstyle.xml b/src/it/MCHECKSTYLE-193/checkstyle.xml index 7e0c3e2e..58868092 100644 --- a/src/it/MCHECKSTYLE-193/checkstyle.xml +++ b/src/it/MCHECKSTYLE-193/checkstyle.xml @@ -23,8 +23,6 @@ Checkstyle rules for Basis Technology. --> - - @@ -159,7 +157,6 @@ Checkstyle rules for Basis Technology. - diff --git a/src/it/MCHECKSTYLE-338/empty-logging-check/src/main/java/org/apache/maven/plugins/checkstyle/EmptyLoggingCheck.java b/src/it/MCHECKSTYLE-338/empty-logging-check/src/main/java/org/apache/maven/plugins/checkstyle/EmptyLoggingCheck.java index a17cfd7e..10d3b3ee 100644 --- a/src/it/MCHECKSTYLE-338/empty-logging-check/src/main/java/org/apache/maven/plugins/checkstyle/EmptyLoggingCheck.java +++ b/src/it/MCHECKSTYLE-338/empty-logging-check/src/main/java/org/apache/maven/plugins/checkstyle/EmptyLoggingCheck.java @@ -20,10 +20,13 @@ */ import java.io.File; +import java.util.Collections; import java.util.List; +import java.util.TreeSet; import com.puppycrawl.tools.checkstyle.api.AbstractFileSetCheck; import com.puppycrawl.tools.checkstyle.api.CheckstyleException; +import com.puppycrawl.tools.checkstyle.api.FileText; import com.puppycrawl.tools.checkstyle.api.LocalizedMessage; import com.puppycrawl.tools.checkstyle.api.SeverityLevel; @@ -32,12 +35,12 @@ public class EmptyLoggingCheck { @Override - protected void processFiltered( File file, List lines ) + protected void processFiltered( File file, FileText lines ) throws CheckstyleException { - getMessageCollector().add( new LocalizedMessage( 0, 0, getMessageBundle(), + addMessages( new TreeSet( Collections.singleton( new LocalizedMessage( 0, 0, getMessageBundle(), "EmptyLoggingCheck on file " + file.getName(), new Object[0], - SeverityLevel.ERROR, getId(), getClass(), null ) ); + SeverityLevel.ERROR, getId(), getClass(), null ) ) ) ); } } diff --git a/src/it/multi-modules-aggregate/child-b/src/test/java/org/apache/maven/plugins/checkstyle/its/AppTest.java b/src/it/multi-modules-aggregate/child-b/src/test/java/org/apache/maven/plugins/checkstyle/its/AppTest.java index 677b7200..42f84223 100644 --- a/src/it/multi-modules-aggregate/child-b/src/test/java/org/apache/maven/plugins/checkstyle/its/AppTest.java +++ b/src/it/multi-modules-aggregate/child-b/src/test/java/org/apache/maven/plugins/checkstyle/its/AppTest.java @@ -20,9 +20,7 @@ public AppTest( String testName ) super( testName ); } - /** - * @return the suite of tests being tested - */ + /* missing javadoc */ public static Test suite() { return new TestSuite( AppTest.class ); diff --git a/src/it/multi-modules-aggregate/maven_checks.xml b/src/it/multi-modules-aggregate/maven_checks.xml new file mode 100644 index 00000000..78fb6b3f --- /dev/null +++ b/src/it/multi-modules-aggregate/maven_checks.xml @@ -0,0 +1,205 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/it/multi-modules-aggregate/pom.xml b/src/it/multi-modules-aggregate/pom.xml index 44217633..82ac112d 100644 --- a/src/it/multi-modules-aggregate/pom.xml +++ b/src/it/multi-modules-aggregate/pom.xml @@ -51,13 +51,6 @@ org.apache.maven.plugins maven-checkstyle-plugin @pom.version@ - - - org.apache.maven.shared - maven-shared-resources - 2 - - @@ -70,7 +63,8 @@ maven-checkstyle-plugin @pom.version@ - config/maven_checks.xml + + maven_checks.xml true false @@ -88,4 +82,4 @@ child-a child-b - \ No newline at end of file + diff --git a/src/it/multi-modules-aggregate/verify.groovy b/src/it/multi-modules-aggregate/verify.groovy index 4c70eaa9..1e5b9b1e 100644 --- a/src/it/multi-modules-aggregate/verify.groovy +++ b/src/it/multi-modules-aggregate/verify.groovy @@ -20,7 +20,6 @@ assert new File( basedir, 'target/checkstyle-cachefile' ).exists(); assert new File( basedir, 'target/checkstyle-checker.xml' ).exists(); -assert new File( basedir, 'target/checkstyle-header.txt' ).exists(); assert new File( basedir, 'target/checkstyle-result.xml' ).exists(); assert new File( basedir, 'target/site/checkstyle-aggregate.html' ).exists(); @@ -30,4 +29,4 @@ content = new File( basedir, 'target/site/checkstyle-aggregate.html' ).text; assert content.contains( 'org/apache/maven/plugins/checkstyle/its/App.java' ); assert content.contains( 'org/apache/maven/plugins/checkstyle/its/AppTest.java' ); -return true; \ No newline at end of file +return true; diff --git a/src/main/java/org/apache/maven/plugins/checkstyle/exec/CheckstyleCheckerListener.java b/src/main/java/org/apache/maven/plugins/checkstyle/exec/CheckstyleCheckerListener.java index a1fcc7f3..e6fade58 100644 --- a/src/main/java/org/apache/maven/plugins/checkstyle/exec/CheckstyleCheckerListener.java +++ b/src/main/java/org/apache/maven/plugins/checkstyle/exec/CheckstyleCheckerListener.java @@ -22,6 +22,7 @@ import com.puppycrawl.tools.checkstyle.api.AuditEvent; import com.puppycrawl.tools.checkstyle.api.AuditListener; import com.puppycrawl.tools.checkstyle.api.AutomaticBean; +import com.puppycrawl.tools.checkstyle.api.CheckstyleException; import com.puppycrawl.tools.checkstyle.api.Configuration; import com.puppycrawl.tools.checkstyle.api.SeverityLevel; @@ -42,7 +43,7 @@ public class CheckstyleCheckerListener extends AutomaticBean implements AuditListener { - private List sourceDirectories; + private final List sourceDirectories; private CheckstyleResults results; @@ -109,18 +110,21 @@ public SeverityLevel getSeverityLevelFilter() } /** {@inheritDoc} */ + @Override public void auditStarted( AuditEvent event ) { setResults( new CheckstyleResults() ); } /** {@inheritDoc} */ + @Override public void auditFinished( AuditEvent event ) { //do nothing } /** {@inheritDoc} */ + @Override public void fileStarted( AuditEvent event ) { final String fileName = StringUtils.replace( event.getFileName(), "\\", "/" ); @@ -146,6 +150,7 @@ public void fileStarted( AuditEvent event ) } /** {@inheritDoc} */ + @Override public void fileFinished( AuditEvent event ) { getResults().setFileViolations( currentFile, events ); @@ -153,6 +158,7 @@ public void fileFinished( AuditEvent event ) } /** {@inheritDoc} */ + @Override public void addError( AuditEvent event ) { if ( SeverityLevel.IGNORE.equals( event.getSeverityLevel() ) ) @@ -167,11 +173,19 @@ public void addError( AuditEvent event ) } /** {@inheritDoc} */ + @Override public void addException( AuditEvent event, Throwable throwable ) { //Do Nothing } + /** {@inheritDoc} */ + @Override + protected void finishLocalSetup() throws CheckstyleException + { + //Do Nothing + } + /** * @return The results of Checkstyle invocation. */