From 61f5b5ff39e42b3660f70c8b94118ad384ab3902 Mon Sep 17 00:00:00 2001 From: Thomas Jensen Date: Thu, 6 Jul 2017 20:17:45 +0200 Subject: [PATCH] Support Checkstyle 8.0 (major breaking change), drop support for Checkstyle <= 6.15 drop support for Java 6 Source code is now Java7 (up from Java6) --- .travis.yml | 12 +++-- build.gradle | 10 ++-- .../addons/build/tasks/TestTask.java | 3 -- project/dependencyConfigs/default.properties | 6 +-- project/dependencyConfigs/java6.properties | 46 ------------------- project/dependencyConfigs/java7.properties | 11 ++--- project/version.properties | 6 +-- .../addons/checks/AbstractAddonsCheck.java | 36 +++++++++------ .../addons/util/CheckstyleApiFixer.java | 8 ++-- 9 files changed, 49 insertions(+), 89 deletions(-) delete mode 100644 project/dependencyConfigs/java6.properties diff --git a/.travis.yml b/.travis.yml index d4562fce..0f26caf8 100644 --- a/.travis.yml +++ b/.travis.yml @@ -11,17 +11,21 @@ before_install: # - sudo update-alternatives --config java - ./gradlew clean +# Update JDK8 to latest version available for Travis +addons: + apt: + packages: + - oracle-java8-installer + env: global: - - checkstyleaddons_jdk6_java=/usr/lib/jvm/java-6-openjdk-amd64/bin/java - - checkstyleaddons_jdk6_javac=/usr/lib/jvm/java-6-openjdk-amd64/bin/javac - - checkstyleaddons_jdk6_javadoc=/usr/lib/jvm/java-6-openjdk-amd64/bin/javadoc - checkstyleaddons_jdk7_java=/usr/lib/jvm/java-7-openjdk-amd64/bin/java - checkstyleaddons_jdk7_javac=/usr/lib/jvm/java-7-openjdk-amd64/bin/javac - checkstyleaddons_jdk7_javadoc=/usr/lib/jvm/java-7-openjdk-amd64/bin/javadoc +install: true script: - - ./gradlew check xtest site + - ./gradlew build site after_success: - ./gradlew jacocoTestReport coveralls diff --git a/build.gradle b/build.gradle index 5abf59d7..cf1b91de 100644 --- a/build.gradle +++ b/build.gradle @@ -48,6 +48,7 @@ import com.thomasjensen.checkstyle.addons.build.tasks.JavadocTask; import com.thomasjensen.checkstyle.addons.build.tasks.SiteTask; import org.ajoberstar.grgit.Grgit; import org.apache.tools.ant.filters.ReplaceTokens; +import org.gradle.internal.jvm.Jvm; // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - @@ -59,7 +60,7 @@ description = 'Additional Checkstyle Checks'; version = new VersionWrapper(project).toString(); ClasspathBuilder.clearConfigCache(); new JavaLevelUtil(project).analyzeJavaLevels(); -sourceCompatibility = JavaVersion.VERSION_1_6; +sourceCompatibility = JavaVersion.VERSION_1_7; ext { // keep these in sync with the ExtProp enum @@ -91,7 +92,7 @@ taskCreator.establishSonarQubeSourceSet(); dependencies { compileOnly group: 'com.google.code.findbugs', name: 'annotations', version: '3.0.1'; compileOnly group: 'com.google.code.findbugs', name: 'jsr305', version: '3.0.1'; - compile group: 'com.puppycrawl.tools', name: 'checkstyle', version: '7.0'; + compile group: 'com.puppycrawl.tools', name: 'checkstyle', version: '8.0'; compile group: 'com.fasterxml.jackson.core', name: 'jackson-databind', version: '2.7.3'; sonarqubeCompileOnly group: 'com.google.code.findbugs', name: 'annotations', version: '3.0.1'; @@ -124,8 +125,9 @@ ext { exceptionFormat 'full'; } onOutput { final TestDescriptor descriptor, final TestOutputEvent event -> - if (descriptor.className != 'com.thomasjensen.checkstyle.addons.checks.misc.MdlJsonConfigValidatorTest' || - event.getDestination() == TestOutputEvent.Destination.StdErr) { + if ((Jvm.current().getJavaVersion() != JavaVersion.VERSION_1_6) && + (descriptor.className != 'com.thomasjensen.checkstyle.addons.checks.misc.MdlJsonConfigValidatorTest' || + event.getDestination() == TestOutputEvent.Destination.StdErr)) { logger.lifecycle(event.message); } } diff --git a/buildSrc/src/main/java/com/thomasjensen/checkstyle/addons/build/tasks/TestTask.java b/buildSrc/src/main/java/com/thomasjensen/checkstyle/addons/build/tasks/TestTask.java index d9500567..ff1e6270 100644 --- a/buildSrc/src/main/java/com/thomasjensen/checkstyle/addons/build/tasks/TestTask.java +++ b/buildSrc/src/main/java/com/thomasjensen/checkstyle/addons/build/tasks/TestTask.java @@ -77,9 +77,6 @@ public void configureFor(@Nonnull final DependencyConfig pDepConfig, @Nonnull fi dependsOn(TaskNames.testClasses.getName(pDepConfig)); configure(buildUtil.getExtraPropertyValue(ExtProp.TestConfigClosure)); - if (JavaVersion.VERSION_1_6.equals(pDepConfig.getJavaLevel())) { - getTestLogging().setShowStandardStreams(false); - } setTestClassesDir(((JavaCompile) buildUtil.getTask(TaskNames.compileTestJava, pDepConfig)).getDestinationDir()); if (baseCsVersion.equals(pCsVersion)) { diff --git a/project/dependencyConfigs/default.properties b/project/dependencyConfigs/default.properties index e31465b5..06be028c 100644 --- a/project/dependencyConfigs/default.properties +++ b/project/dependencyConfigs/default.properties @@ -21,7 +21,7 @@ # Keep in mind that the base version must not be present in the list of compatible versions below. # Checkstyle versions which we expect to be compatible with the base version above -CompatibleWithCheckstyle = 7.1, 7.1.1, 7.1.2, 7.2, 7.3, 7.4, 7.5, 7.5.1, 7.6, 7.6.1, 7.7, 7.8, 7.8.1, 7.8.2 +CompatibleWithCheckstyle = 7.0, 7.1, 7.1.1, 7.1.2, 7.2, 7.3, 7.4, 7.5, 7.5.1, 7.6, 7.6.1, 7.7, 7.8, 7.8.1, 7.8.2 JavaLevel = 1.8 JavadocLinks = http://checkstyle-addons.github.io/jsr305-javadoc/3.0.1/, \ @@ -33,6 +33,6 @@ JavadocLinks = http://checkstyle-addons.github.io/jsr305-javadoc/3.0.1/, \ # The default dependency configuration must support SonarQube. SonarQubeSupport = true -SonarQubeMinPlatformVersion = 4.5.1 +SonarQubeMinPlatformVersion = 4.5.2 SonarQubeMinJavaPlugin = 2.2 -SonarQubeMinCheckstylePlugin = 2.3 +SonarQubeMinCheckstylePlugin = 3.1 diff --git a/project/dependencyConfigs/java6.properties b/project/dependencyConfigs/java6.properties deleted file mode 100644 index 6d9d6d0b..00000000 --- a/project/dependencyConfigs/java6.properties +++ /dev/null @@ -1,46 +0,0 @@ -# Checkstyle-Addons - Additional Checkstyle checks -# Copyright (C) 2015 Thomas Jensen -# -# This program is free software: you can redistribute it and/or modify it under the -# terms of the GNU General Public License, version 3, as published by the Free -# Software Foundation. -# -# This program is distributed in the hope that it will be useful, but WITHOUT ANY -# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A -# PARTICULAR PURPOSE. See the GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License along with this -# program. If not, see . -# _________________________________________________________________________________ - - -# This dependency configuration will build the latest possible version that still runs on Java 6. This has some effect -# on the setup of the runtime environments, but assuming you have a working Java 6 based runtime, then you will be -# able to use Checkstyle Addons, too! Note that the exact Checkstyle version 6.1 (not 6.1.1 or anything else!) is -# required for this to work (rationale: https://github.com/checkstyle/checkstyle/issues/505). For IntelliJ, this means -# using Checkstyle-IDEA 4.10.0 exactly. - -# the Checkstyle base version -dependencyVersion.com.puppycrawl.tools = 6.1 - -# Checkstyle versions which we expect to be compatible with the base version above -CompatibleWithCheckstyle = 6.0, 6.1.1 - -JavaLevel = 1.6 -JavadocLinks = http://checkstyle-addons.github.io/jsr305-javadoc/3.0.1/, \ - http://docs.oracle.com/javase/6/docs/api/, \ - http://jcip.net/annotations/doc/, \ - http://javadocs.sonarsource.org/3.0/apidocs/, \ - http://checkstyle.sourceforge.net/apidocs/ -dependencyVersion.com.google.code.findbugs = 2.0.3 - -SonarQubeSupport = true - -# the SonarQube API version (for compiling the SonarQube plugin) -dependencyVersion.org.codehaus.sonar = 3.0 -# the SLF4J NOP binding required for the SonarQube API version -dependencyVersion.org.slf4j = 1.6.2 - -SonarQubeMinPlatformVersion = 4.2 -SonarQubeMinJavaPlugin = 2.2 -SonarQubeMinCheckstylePlugin = 2.2 diff --git a/project/dependencyConfigs/java7.properties b/project/dependencyConfigs/java7.properties index ec84ba17..814ddef0 100644 --- a/project/dependencyConfigs/java7.properties +++ b/project/dependencyConfigs/java7.properties @@ -20,11 +20,10 @@ # (see Checkstyle issue #2997 - https://github.com/checkstyle/checkstyle/issues/2997). Checkstyle 6.16.1 is OK. # the Checkstyle base version -dependencyVersion.com.puppycrawl.tools = 6.4.1 +dependencyVersion.com.puppycrawl.tools = 6.16.1 # Checkstyle versions which we expect to be compatible with the base version above -CompatibleWithCheckstyle = 6.2, 6.3, 6.4, 6.5, 6.6, 6.7, 6.8, 6.8.1, 6.8.2, 6.9, 6.10, 6.10.1, 6.11, 6.11.1, 6.11.2, \ - 6.12, 6.12.1, 6.13, 6.14, 6.14.1, 6.15, 6.16.1, 6.17, 6.18, 6.19 +CompatibleWithCheckstyle = 6.17, 6.18, 6.19 JavaLevel = 1.7 JavadocLinks = http://checkstyle-addons.github.io/jsr305-javadoc/3.0.1/, \ @@ -34,13 +33,9 @@ JavadocLinks = http://checkstyle-addons.github.io/jsr305-javadoc/3.0.1/, \ http://checkstyle.sourceforge.net/apidocs/ dependencyVersion.com.google.code.findbugs = 3.0.0 -SonarQubeSupport = true +SonarQubeSupport = false # the SonarQube API version (for compiling the SonarQube plugin) dependencyVersion.org.codehaus.sonar = 3.0 # the SLF4J NOP binding required for the SonarQube API version dependencyVersion.org.slf4j = 1.6.2 - -SonarQubeMinPlatformVersion = 4.5.1 -SonarQubeMinJavaPlugin = 2.2 -SonarQubeMinCheckstylePlugin = 2.3 diff --git a/project/version.properties b/project/version.properties index 2a417cae..edf7fee7 100644 --- a/project/version.properties +++ b/project/version.properties @@ -1,9 +1,9 @@ # Checkstyle Addons Version number # Versioning scheme: Semantic - http://semver.org/ -major = 4 -minor = 2 -patch = 1 +major = 5 +minor = 0 +patch = 0 # release or snapshot release = false diff --git a/src/main/java/com/thomasjensen/checkstyle/addons/checks/AbstractAddonsCheck.java b/src/main/java/com/thomasjensen/checkstyle/addons/checks/AbstractAddonsCheck.java index 2e4a61a4..fcd7be4f 100644 --- a/src/main/java/com/thomasjensen/checkstyle/addons/checks/AbstractAddonsCheck.java +++ b/src/main/java/com/thomasjensen/checkstyle/addons/checks/AbstractAddonsCheck.java @@ -30,7 +30,7 @@ import javax.annotation.Nonnull; import javax.annotation.Nullable; -import com.puppycrawl.tools.checkstyle.api.Check; +import com.puppycrawl.tools.checkstyle.api.AbstractCheck; import com.puppycrawl.tools.checkstyle.api.DetailAST; import com.puppycrawl.tools.checkstyle.api.TokenTypes; import com.thomasjensen.checkstyle.addons.util.CheckstyleApiFixer; @@ -43,11 +43,11 @@ */ @SuppressFBWarnings("ACEM_ABSTRACT_CLASS_EMPTY_METHODS") public abstract class AbstractAddonsCheck - extends Check + extends AbstractCheck { - private static final Set TOKENS = Collections.unmodifiableSet(new HashSet(Arrays.asList( - TokenTypes.PACKAGE_DEF, TokenTypes.ENUM_DEF, TokenTypes.CLASS_DEF, TokenTypes.INTERFACE_DEF, - TokenTypes.ANNOTATION_DEF))); + private static final Set TOKENS = Collections.unmodifiableSet(new HashSet(Arrays + .asList(TokenTypes.PACKAGE_DEF, TokenTypes.ENUM_DEF, TokenTypes.CLASS_DEF, TokenTypes.INTERFACE_DEF, + TokenTypes.ANNOTATION_DEF))); /** binary name of the outer (or only) class */ private BinaryName iOuterClassName = null; @@ -83,8 +83,17 @@ protected AbstractAddonsCheck(@Nullable final String pMockfile) + /** + * The tokens which this check is interested in. Will be added to the tokens of the base class. + * + * @return the relevant tokens + */ + public abstract Set getRelevantTokens(); + + + @Override - public final int[] getDefaultTokens() + public final int[] getRequiredTokens() { final Set tokens = new TreeSet(); tokens.addAll(TOKENS); @@ -100,19 +109,18 @@ public final int[] getDefaultTokens() - /** - * The tokens which this check is interested in. Will be added to the tokens of the base class. - * - * @return the relevant tokens - */ - public abstract Set getRelevantTokens(); + @Override + public final int[] getAcceptableTokens() + { + return getRequiredTokens(); + } @Override - public int[] getRequiredTokens() + public final int[] getDefaultTokens() { - return getDefaultTokens(); + return getRequiredTokens(); } diff --git a/src/main/java/com/thomasjensen/checkstyle/addons/util/CheckstyleApiFixer.java b/src/main/java/com/thomasjensen/checkstyle/addons/util/CheckstyleApiFixer.java index ff904e8f..94d87ec1 100644 --- a/src/main/java/com/thomasjensen/checkstyle/addons/util/CheckstyleApiFixer.java +++ b/src/main/java/com/thomasjensen/checkstyle/addons/util/CheckstyleApiFixer.java @@ -22,7 +22,7 @@ import javax.annotation.Nonnull; import javax.annotation.Nullable; -import com.puppycrawl.tools.checkstyle.api.Check; +import com.puppycrawl.tools.checkstyle.api.AbstractCheck; import com.puppycrawl.tools.checkstyle.api.FileContents; import com.puppycrawl.tools.checkstyle.api.TokenTypes; @@ -34,7 +34,7 @@ */ public class CheckstyleApiFixer { - private final Check check; + private final AbstractCheck check; private final File currentFileNameMockFile; @@ -45,7 +45,7 @@ public class CheckstyleApiFixer * * @param pCheck the check for which this instance of the API fixer shall run */ - public CheckstyleApiFixer(@Nonnull final Check pCheck) + public CheckstyleApiFixer(@Nonnull final AbstractCheck pCheck) { this(pCheck, null); } @@ -58,7 +58,7 @@ public CheckstyleApiFixer(@Nonnull final Check pCheck) * @param pCheck the check for which this instance of the API fixer shall run * @param pCurrentFileNameMockFile file to use as result of {@link #getCurrentFileName()} in unit tests */ - public CheckstyleApiFixer(@Nonnull final Check pCheck, @Nullable final String pCurrentFileNameMockFile) + public CheckstyleApiFixer(@Nonnull final AbstractCheck pCheck, @Nullable final String pCurrentFileNameMockFile) { check = pCheck; currentFileNameMockFile = pCurrentFileNameMockFile != null ? new File(pCurrentFileNameMockFile) : null;