From 2300dc4b4dd4c888c14260e82b97d9af7ee0a26e Mon Sep 17 00:00:00 2001 From: Paul Campbell Date: Sat, 27 May 2017 20:47:50 +0100 Subject: [PATCH 01/39] version: set to 3.1.0-SNAPSHOT --- builder/pom.xml | 2 +- plugin-sample/pom.xml | 4 ++-- plugin/pom.xml | 2 +- pom.xml | 2 +- regressions/pom.xml | 2 +- ruleset/pom.xml | 4 ++-- sample-parent/pom.xml | 2 +- 7 files changed, 9 insertions(+), 9 deletions(-) diff --git a/builder/pom.xml b/builder/pom.xml index cb1c4a2..0d9d1cd 100644 --- a/builder/pom.xml +++ b/builder/pom.xml @@ -12,7 +12,7 @@ kemitix-checkstyle-ruleset-builder - 3.0.1 + 3.1.0-SNAPSHOT jar Kemitix Checkstyle Ruleset Builder diff --git a/plugin-sample/pom.xml b/plugin-sample/pom.xml index 0b84d0f..8ae0218 100644 --- a/plugin-sample/pom.xml +++ b/plugin-sample/pom.xml @@ -8,12 +8,12 @@ net.kemitix kemitix-checkstyle-ruleset-sample-parent - 3.0.1 + 3.1.0-SNAPSHOT ../sample-parent kemitix-checkstyle-ruleset-plugin-sample - 3.0.1 + 3.1.0-SNAPSHOT Kemitix Checkstyle Ruleset Plugin Sample Sample usage of the Kemitix Checkstyle Ruleset Plugin diff --git a/plugin/pom.xml b/plugin/pom.xml index 6266c91..270b3fd 100644 --- a/plugin/pom.xml +++ b/plugin/pom.xml @@ -7,7 +7,7 @@ net.kemitix kemitix-checkstyle-ruleset-parent - 3.0.1 + 3.1.0-SNAPSHOT kemitix-checkstyle-ruleset-maven-plugin diff --git a/pom.xml b/pom.xml index 6066b6d..8e373c6 100644 --- a/pom.xml +++ b/pom.xml @@ -6,7 +6,7 @@ net.kemitix kemitix-checkstyle-ruleset-parent - 3.0.1 + 3.1.0-SNAPSHOT pom Kemitix Checkstyle Ruleset (Parent) diff --git a/regressions/pom.xml b/regressions/pom.xml index 812b108..9fa775d 100644 --- a/regressions/pom.xml +++ b/regressions/pom.xml @@ -5,7 +5,7 @@ kemitix-checkstyle-ruleset-sample-parent net.kemitix - 3.0.1 + 3.1.0-SNAPSHOT ../sample-parent 4.0.0 diff --git a/ruleset/pom.xml b/ruleset/pom.xml index fbb78a4..1daa208 100644 --- a/ruleset/pom.xml +++ b/ruleset/pom.xml @@ -7,11 +7,11 @@ net.kemitix kemitix-checkstyle-ruleset-parent - 3.0.1 + 3.1.0-SNAPSHOT kemitix-checkstyle-ruleset - 3.0.1 + 3.1.0-SNAPSHOT jar Kemitix Checkstyle Ruleset diff --git a/sample-parent/pom.xml b/sample-parent/pom.xml index aa85c8b..ed2f245 100644 --- a/sample-parent/pom.xml +++ b/sample-parent/pom.xml @@ -8,7 +8,7 @@ kemitix-checkstyle-ruleset-sample-parent pom - 3.0.1 + 3.1.0-SNAPSHOT Kemitix Checkstyle Ruleset Sample Parent Sample parent for modules that use kemitix-checkstyle-ruleset-maven-plugin From 403d4b6504aa9d455c7114a6417b4f1b6fc48fa2 Mon Sep 17 00:00:00 2001 From: Paul Campbell Date: Sun, 28 May 2017 18:18:05 +0100 Subject: [PATCH 02/39] pom.xml: upgrade checkstyle to 7.7 --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index 8e373c6..ea9865f 100644 --- a/pom.xml +++ b/pom.xml @@ -21,8 +21,8 @@ 2.8.2 2.17 - 7.6.1 1.23.1 + 7.7 1.10.19 3.8.0 From 6072613b44f7ac982ad5e4b8918f0774dfd9d230 Mon Sep 17 00:00:00 2001 From: Paul Campbell Date: Sun, 28 May 2017 18:29:46 +0100 Subject: [PATCH 03/39] pom.xml: upgrade sevntu to 1.24.0 * Fixes bug in ForbidWildcardAsReturnType which is now enabled again * Additional pluginRepositories config is no longer required --- README.md | 67 ++++++------------- builder/src/main/resources/README-template.md | 10 +-- builder/src/main/resources/application.yml | 3 +- .../src/main/resources/rules/EnumValueName.md | 39 ++--------- plugin/pom.xml | 7 -- .../plugin/DefaultCheckstyleExecutor.java | 2 +- pom.xml | 2 +- .../net/kemitix/checkstyle-5-complexity.xml | 1 + 8 files changed, 28 insertions(+), 103 deletions(-) diff --git a/README.md b/README.md index e0c3067..9cdfee9 100644 --- a/README.md +++ b/README.md @@ -66,19 +66,11 @@ The level is now specified as a configuration parameter. See the example below. - - - - sevntu-maven - sevntu-maven - http://sevntu-checkstyle.github.io/sevntu.checkstyle/maven2 - - ```` ## All Checks -Rule|Level|Source|Enabled|Suppressable +Rule|Level|Source|Enabled|Suppressible ----|-----|------|-------|------------ [AbbreviationAsWordInName](#abbreviationaswordinname)|naming|checkstyle|Yes| [AbstractClassName](#abstractclassname)|naming|checkstyle|Yes| @@ -143,7 +135,7 @@ Rule|Level|Source|Enabled|Suppressable [ForbidInstantiation](#forbidinstantiation)|unspecified|sevntu|| [ForbidReturnInFinallyBlock](#forbidreturninfinallyblock)|complexity|sevntu|Yes| [ForbidThrowAnonymousExceptions](#forbidthrowanonymousexceptions)|tweaks|sevntu|| -[ForbidWildcardAsReturnType](#forbidwildcardasreturntype)|complexity|sevntu|| +[ForbidWildcardAsReturnType](#forbidwildcardasreturntype)|complexity|sevntu|Yes| [GenericWhitespace](#genericwhitespace)|layout|checkstyle|Yes| [Header](#header)|layout|checkstyle|Yes| [HiddenField](#hiddenfield)|tweaks|checkstyle|Yes| @@ -2264,32 +2256,13 @@ Checks that when an exception is caught, that if it is logged then it is not als Accepts `java.util.logging.Logger` and `org.slf4j.Logger`. #### [EnumValueName](http://sevntu-checkstyle.github.io/sevntu.checkstyle/apidocs/com/github/sevntu/checkstyle/checks/naming/EnumValueNameCheck.html) -Enums are considered to be of two distinct types: 'Class' or 'Value' enumerations. The distinction being that Class Enumerations have methods (other than `toString()`) defined. - -The values defined in the `enum` must match the appropriate pattern: - -* Class: `^[A-Z][a-zA-Z0-9]*$` -* Value: `^[A-Z][A-Z0-9]*(_[A-Z0-9]+)*$` - -The difference being that Class enumerations can't contain underscores but can include lowercase letters (after the first initial capital). Value enumerations can include underscores, but not as the first or second character. +Checks that Enum Values match the pattern: `^[A-Z][A-Z0-9]*(_[A-Z0-9]+)*$` Valid: ```` -enum ValidConstants { +enum Valid { - ALPHA, BETA; -} - -enum ValidClassLike { - - Alpha("a"), - Beta("b"); - - private String name; - - ValidClassLike(String name) { - this.name = name; - } + ALPHA, BETA, GAMMA_RAY; } ```` @@ -2297,19 +2270,7 @@ Invalid: ```` enum InvalidConstants { - alpha, Beta, GAMMA_RAY; -} - -enum InvalidClassLike { - - alpha("a"), - beta("b"); - - private String name; - - InvalidClassLike(String name) { - this.name = name; - } + alpha, Beta; } ```` #### [ForbidCCommentsInMethods](http://sevntu-checkstyle.github.io/sevntu.checkstyle/apidocs/com/github/sevntu/checkstyle/checks/coding/ForbidCCommentsInMethodsCheck.html) @@ -2343,6 +2304,19 @@ try { return true; // invalid } ```` +#### [ForbidWildcardAsReturnType](http://sevntu-checkstyle.github.io/sevntu.checkstyle/apidocs/com/github/sevntu/checkstyle/checks/design/ForbidWildcardAsReturnTypeCheck.html) + +Prevents declaring a method from returning a wildcard type as its return value. + +Valid: +```` + List getList() {} +```` + +Invalid: +```` + List getList() {} +```` #### [LogicConditionNeedOptimization](http://sevntu-checkstyle.github.io/sevntu.checkstyle/apidocs/com/github/sevntu/checkstyle/checks/coding/LogicConditionNeedOptimizationCheck.html) Prevent the placement of variables or fields after methods in an expression. @@ -2703,9 +2677,6 @@ Generic rule; doesn't embody a 'quality' check. #### [ForbidThrowAnonymousExceptions](http://sevntu-checkstyle.github.io/sevntu.checkstyle/apidocs/com/github/sevntu/checkstyle/checks/coding/ForbidThrowAnonymousExceptionsCheck.html) [IllegalThrows](#illegalthrows) performs a similar check. -#### [ForbidWildcardAsReturnType](http://sevntu-checkstyle.github.io/sevntu.checkstyle/apidocs/com/github/sevntu/checkstyle/checks/design/ForbidWildcardAsReturnTypeCheck.html) - -Causes `NullPointerException` when used with `@Value.Immutables` from `org.immutables:value` #### [RequiredParameterForAnnotation](http://sevntu-checkstyle.github.io/sevntu.checkstyle/apidocs/com/github/sevntu/checkstyle/checks/annotation/RequiredParameterForAnnotationCheck.html) Generic rule; doesn't embody a 'quality' check. diff --git a/builder/src/main/resources/README-template.md b/builder/src/main/resources/README-template.md index 93250af..a6f9614 100644 --- a/builder/src/main/resources/README-template.md +++ b/builder/src/main/resources/README-template.md @@ -66,19 +66,11 @@ The level is now specified as a configuration parameter. See the example below. - - - - sevntu-maven - sevntu-maven - http://sevntu-checkstyle.github.io/sevntu.checkstyle/maven2 - - ```` ## All Checks -Rule|Level|Source|Enabled|Suppressable +Rule|Level|Source|Enabled|Suppressible ----|-----|------|-------|------------ %s diff --git a/builder/src/main/resources/application.yml b/builder/src/main/resources/application.yml index 3380f3a..7519e16 100644 --- a/builder/src/main/resources/application.yml +++ b/builder/src/main/resources/application.yml @@ -1056,10 +1056,9 @@ rules: name: ForbidWildcardAsReturnType parent: TREEWALKER level: COMPLEXITY - enabled: false + enabled: true source: SEVNTU uri: http://sevntu-checkstyle.github.io/sevntu.checkstyle/apidocs/com/github/sevntu/checkstyle/checks/design/ForbidWildcardAsReturnTypeCheck.html - reason: Causes `NullPointerException` when used with `@Value.Immutables` from `org.immutables:value` - name: LogicConditionNeedOptimization parent: TREEWALKER diff --git a/builder/src/main/resources/rules/EnumValueName.md b/builder/src/main/resources/rules/EnumValueName.md index c389ed7..07e93b2 100644 --- a/builder/src/main/resources/rules/EnumValueName.md +++ b/builder/src/main/resources/rules/EnumValueName.md @@ -1,30 +1,11 @@ -Enums are considered to be of two distinct types: 'Class' or 'Value' enumerations. The distinction being that Class Enumerations have methods (other than `toString()`) defined. - -The values defined in the `enum` must match the appropriate pattern: - -* Class: `^[A-Z][a-zA-Z0-9]*$` -* Value: `^[A-Z][A-Z0-9]*(_[A-Z0-9]+)*$` - -The difference being that Class enumerations can't contain underscores but can include lowercase letters (after the first initial capital). Value enumerations can include underscores, but not as the first or second character. +Checks that Enum Values match the pattern: `^[A-Z][A-Z0-9]*(_[A-Z0-9]+)*$` Valid: ```` -enum ValidConstants { +enum Valid { - ALPHA, BETA; -} - -enum ValidClassLike { - - Alpha("a"), - Beta("b"); - - private String name; - - ValidClassLike(String name) { - this.name = name; - } + ALPHA, BETA, GAMMA_RAY; } ```` @@ -32,18 +13,6 @@ Invalid: ```` enum InvalidConstants { - alpha, Beta, GAMMA_RAY; -} - -enum InvalidClassLike { - - alpha("a"), - beta("b"); - - private String name; - - InvalidClassLike(String name) { - this.name = name; - } + alpha, Beta; } ```` diff --git a/plugin/pom.xml b/plugin/pom.xml index 270b3fd..db90e76 100644 --- a/plugin/pom.xml +++ b/plugin/pom.xml @@ -151,11 +151,4 @@ - - - sevntu-maven - sevntu-maven - http://sevntu-checkstyle.github.io/sevntu.checkstyle/maven2 - - diff --git a/plugin/src/main/java/net/kemitix/checkstyle/ruleset/plugin/DefaultCheckstyleExecutor.java b/plugin/src/main/java/net/kemitix/checkstyle/ruleset/plugin/DefaultCheckstyleExecutor.java index 24d8e7d..68f03c6 100644 --- a/plugin/src/main/java/net/kemitix/checkstyle/ruleset/plugin/DefaultCheckstyleExecutor.java +++ b/plugin/src/main/java/net/kemitix/checkstyle/ruleset/plugin/DefaultCheckstyleExecutor.java @@ -60,7 +60,7 @@ public class DefaultCheckstyleExecutor implements CheckstyleExecutor { private static final String CHECKSTYLE_ARTIFACTID = "checkstyle"; - private static final String SEVNTU_GROUPID = "com.github.sevntu.checkstyle"; + private static final String SEVNTU_GROUPID = "com.github.sevntu-checkstyle"; private static final String SEVNTU_ARTIFACTID = "sevntu-checkstyle-maven-plugin"; diff --git a/pom.xml b/pom.xml index ea9865f..f5c9d8f 100644 --- a/pom.xml +++ b/pom.xml @@ -21,8 +21,8 @@ 2.8.2 2.17 - 1.23.1 7.7 + 1.24.0 1.10.19 3.8.0 diff --git a/ruleset/src/main/resources/net/kemitix/checkstyle-5-complexity.xml b/ruleset/src/main/resources/net/kemitix/checkstyle-5-complexity.xml index 8c9c3fa..b258137 100644 --- a/ruleset/src/main/resources/net/kemitix/checkstyle-5-complexity.xml +++ b/ruleset/src/main/resources/net/kemitix/checkstyle-5-complexity.xml @@ -210,6 +210,7 @@ + From 4a0ee1de46ae523588f55e6becfeae131fe0b8d4 Mon Sep 17 00:00:00 2001 From: Paul Campbell Date: Sun, 28 May 2017 19:56:43 +0100 Subject: [PATCH 04/39] ruleset: MoveVariableInsideIf: enabled for 4-tweaks and above --- README.md | 24 +++++++ builder/src/main/resources/application.yml | 7 ++ .../rules/MoveVariableInsideIfCheck.md | 22 +++++++ .../regressions/MoveVariableInsideIf.java | 65 +++++++++++++++++++ .../net/kemitix/checkstyle-4-tweaks.xml | 1 + .../net/kemitix/checkstyle-5-complexity.xml | 1 + 6 files changed, 120 insertions(+) create mode 100644 builder/src/main/resources/rules/MoveVariableInsideIfCheck.md create mode 100644 regressions/src/main/java/net/kemitix/checkstyle/regressions/MoveVariableInsideIf.java diff --git a/README.md b/README.md index 9cdfee9..ac39463 100644 --- a/README.md +++ b/README.md @@ -181,6 +181,7 @@ Rule|Level|Source|Enabled|Suppressible [MissingSwitchDefault](#missingswitchdefault)|tweaks|checkstyle|Yes| [ModifiedControlVariable](#modifiedcontrolvariable)|tweaks|checkstyle|Yes| [ModifierOrder](#modifierorder)|naming|checkstyle|Yes| +[MoveVariableInsideIfCheck](#movevariableinsideifcheck)|tweaks|sevntu|Yes| [MultipleStringLiterals](#multiplestringliterals)|naming|checkstyle|Yes| [MultipleVariableDeclarations](#multiplevariabledeclarations)|naming|checkstyle|Yes| [MutableException](#mutableexception)|tweaks|checkstyle|Yes| @@ -2333,6 +2334,29 @@ if (getProperty() && property) {} #### [MapIterationInForEachLoop](http://sevntu-checkstyle.github.io/sevntu.checkstyle/apidocs/com/github/sevntu/checkstyle/checks/coding/MapIterationInForEachLoopCheck.html) Checks for unoptimised iterations over `Map`s. Check use of `map.values()`, `map.keySet()` and `map.entrySet()` against the use of the iterator produced to verify if another could be better. +#### [MoveVariableInsideIfCheck](http://sevntu-checkstyle.github.io/sevntu.checkstyle/apidocs/com/github/sevntu/checkstyle/checks/coding/MoveVariableInsideIfCheck.html) + +Checks if a variable is declared outside an `if` block that is only used within that block. + +Valid: +```` +if (condition) { + String variable = input.substring(1); + return method(variable); +} +return ""; +```` + +Invalid: +```` +String variable = input.substring(1); +if (condition) { + return method(variable); +} +return ""; +```` + +Example: [MoveVariableInsideIf.java](https://github.com/kemitix/kemitix-checkstyle-ruleset/blob/master/regressions/src/main/java/net/kemitix/checkstyle/regressions/MoveVariableInsideIf.java) #### [NameConventionForJunit4TestClasses](http://sevntu-checkstyle.github.io/sevntu.checkstyle/apidocs/com/github/sevntu/checkstyle/checks/coding/NameConventionForJunit4TestClassesCheck.html) Checks the names of JUnit test classes. Classes checked are those that have at least one method annotated with `Test` or `org.junit.Test`. diff --git a/builder/src/main/resources/application.yml b/builder/src/main/resources/application.yml index 7519e16..3b60a5d 100644 --- a/builder/src/main/resources/application.yml +++ b/builder/src/main/resources/application.yml @@ -1498,3 +1498,10 @@ rules: source: SEVNTU uri: http://sevntu-checkstyle.github.io/sevntu.checkstyle/apidocs/com/github/sevntu/checkstyle/checks/coding/WhitespaceBeforeArrayInitializerCheck.html reason: "TODO: enable" + - + name: MoveVariableInsideIfCheck + parent: TREEWALKER + level: TWEAKS + enabled: true + source: SEVNTU + uri: http://sevntu-checkstyle.github.io/sevntu.checkstyle/apidocs/com/github/sevntu/checkstyle/checks/coding/MoveVariableInsideIfCheck.html diff --git a/builder/src/main/resources/rules/MoveVariableInsideIfCheck.md b/builder/src/main/resources/rules/MoveVariableInsideIfCheck.md new file mode 100644 index 0000000..e5304b3 --- /dev/null +++ b/builder/src/main/resources/rules/MoveVariableInsideIfCheck.md @@ -0,0 +1,22 @@ + +Checks if a variable is declared outside an `if` block that is only used within that block. + +Valid: +```` +if (condition) { + String variable = input.substring(1); + return method(variable); +} +return ""; +```` + +Invalid: +```` +String variable = input.substring(1); +if (condition) { + return method(variable); +} +return ""; +```` + +Example: [MoveVariableInsideIf.java](https://github.com/kemitix/kemitix-checkstyle-ruleset/blob/master/regressions/src/main/java/net/kemitix/checkstyle/regressions/MoveVariableInsideIf.java) diff --git a/regressions/src/main/java/net/kemitix/checkstyle/regressions/MoveVariableInsideIf.java b/regressions/src/main/java/net/kemitix/checkstyle/regressions/MoveVariableInsideIf.java new file mode 100644 index 0000000..bfdb49d --- /dev/null +++ b/regressions/src/main/java/net/kemitix/checkstyle/regressions/MoveVariableInsideIf.java @@ -0,0 +1,65 @@ +/** + * The MIT License (MIT) + * + * Copyright (c) 2017 Paul Campbell + * + * Permission is hereby granted, free of charge, to any person obtaining a copy of this software + * and associated documentation files (the "Software"), to deal in the Software without restriction, + * including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, + * subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all copies + * or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, + * INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE + * AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, + * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + */ + +package net.kemitix.checkstyle.regressions; + +/** + * Regression demo for {@code MoveVariableInsideIfCheck}. + * + * @author Paul Campbell (pcampbell@kemitix.net) + */ +class MoveVariableInsideIf { + + private String input = "1"; + + private boolean condition; + + private String method(final String variable) { + return "value"; + } + + /** + * Fails if not suppressed. + * + * @return value + */ + @SuppressWarnings("movevariableinsideif") + String invalid() { + String variable = input.substring(1); + if (condition) { + return method(variable); + } + return ""; + } + + /** + * Rewrite {@link #invalid()} as this to pass. + * + * @return value + */ + String valid() { + if (condition) { + String variable = input.substring(1); + return method(variable); + } + return ""; + } +} diff --git a/ruleset/src/main/resources/net/kemitix/checkstyle-4-tweaks.xml b/ruleset/src/main/resources/net/kemitix/checkstyle-4-tweaks.xml index 50b1a88..2e27c90 100644 --- a/ruleset/src/main/resources/net/kemitix/checkstyle-4-tweaks.xml +++ b/ruleset/src/main/resources/net/kemitix/checkstyle-4-tweaks.xml @@ -175,6 +175,7 @@ + diff --git a/ruleset/src/main/resources/net/kemitix/checkstyle-5-complexity.xml b/ruleset/src/main/resources/net/kemitix/checkstyle-5-complexity.xml index b258137..bc2b68b 100644 --- a/ruleset/src/main/resources/net/kemitix/checkstyle-5-complexity.xml +++ b/ruleset/src/main/resources/net/kemitix/checkstyle-5-complexity.xml @@ -228,6 +228,7 @@ + From 17d82f5885911f8f807a843bc4d26c3594fc4cc4 Mon Sep 17 00:00:00 2001 From: Paul Campbell Date: Mon, 29 May 2017 09:16:17 +0100 Subject: [PATCH 05/39] sample-parent: set level to 5-complexity plugin-sample: overrides level back down to 2-naming --- plugin-sample/pom.xml | 4 +++- sample-parent/pom.xml | 7 ++++--- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/plugin-sample/pom.xml b/plugin-sample/pom.xml index 8ae0218..2c7d70d 100644 --- a/plugin-sample/pom.xml +++ b/plugin-sample/pom.xml @@ -2,7 +2,9 @@ - + + 2-naming + 4.0.0 diff --git a/sample-parent/pom.xml b/sample-parent/pom.xml index ed2f245..f59ce12 100644 --- a/sample-parent/pom.xml +++ b/sample-parent/pom.xml @@ -14,7 +14,8 @@ Sample parent for modules that use kemitix-checkstyle-ruleset-maven-plugin - 2-naming + ${project.version} + 5-complexity UTF-8 UTF-8 @@ -50,9 +51,9 @@ net.kemitix kemitix-checkstyle-ruleset-maven-plugin - ${project.version} + ${kemitix-checkstyle-ruleset.version} - ${kemitix-checkstyle-ruleset-level} + ${kemitix-checkstyle-ruleset.level} From e634dba450e350addf63b05558edb5f3b303e95b Mon Sep 17 00:00:00 2001 From: Paul Campbell Date: Mon, 29 May 2017 09:17:31 +0100 Subject: [PATCH 06/39] regressions: ExplicitInitialization: added Regression added in preparation for checkstyle adding an option in 7.8.x to allow primatives to be initialised to their default values. --- .../regressions/ExplicitInitialization.java | 60 +++++++++++++++++++ 1 file changed, 60 insertions(+) create mode 100644 regressions/src/main/java/net/kemitix/checkstyle/regressions/ExplicitInitialization.java diff --git a/regressions/src/main/java/net/kemitix/checkstyle/regressions/ExplicitInitialization.java b/regressions/src/main/java/net/kemitix/checkstyle/regressions/ExplicitInitialization.java new file mode 100644 index 0000000..322b589 --- /dev/null +++ b/regressions/src/main/java/net/kemitix/checkstyle/regressions/ExplicitInitialization.java @@ -0,0 +1,60 @@ +/** + * The MIT License (MIT) + * + * Copyright (c) 2017 Paul Campbell + * + * Permission is hereby granted, free of charge, to any person obtaining a copy of this software + * and associated documentation files (the "Software"), to deal in the Software without restriction, + * including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, + * subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all copies + * or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, + * INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE + * AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, + * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + */ + +package net.kemitix.checkstyle.regressions; + +/** + * Regression demo for {@code ExplicitInitializationCheck}. + * + * @author Paul Campbell (pcampbell@kemitix.net). + */ +@SuppressWarnings("hideutilityclassconstructor") +class ExplicitInitialization { + + /** + * This will become valid in next release. + */ + @SuppressWarnings("explicitinitialization") + private boolean validBoolean = false; + + /** + * This will become valid in next release. + */ + @SuppressWarnings("explicitinitialization") + private int validInt = 0; + + private String validString = ""; + + private Object validObject = new Object(); + + @SuppressWarnings("explicitinitialization") + private Boolean invalidBoolean = null; + + @SuppressWarnings("explicitinitialization") + private Integer invalidInteger = null; + + @SuppressWarnings("explicitinitialization") + private String invalidString = null; + + @SuppressWarnings("explicitinitialization") + private Object invalidObject = null; + +} From da5461555e31483940f288858d4c94c04969ada4 Mon Sep 17 00:00:00 2001 From: Paul Campbell Date: Mon, 29 May 2017 09:34:18 +0100 Subject: [PATCH 07/39] pom.xml: upgrade checkstyle to 7.8 --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index f5c9d8f..5c317d7 100644 --- a/pom.xml +++ b/pom.xml @@ -21,7 +21,7 @@ 2.8.2 2.17 - 7.7 + 7.8 1.24.0 1.10.19 3.8.0 From 81768ff9f947968ca49971c0c73e79fafacf10fc Mon Sep 17 00:00:00 2001 From: Paul Campbell Date: Mon, 29 May 2017 11:23:48 +0100 Subject: [PATCH 08/39] builder: CheckstyleWriter: avoid throwing raw exception types Instead of throwing RuntimeException or IOException, throw CheckstyleWriterException or TemplateNotFoundException. --- .../ruleset/builder/CheckstyleWriter.java | 4 +- .../builder/CheckstyleWriterException.java | 39 ++++++++++++++++++ .../builder/TemplateNotFoundException.java | 41 +++++++++++++++++++ .../CheckstyleWriterExceptionTest.java | 19 +++++++++ .../ruleset/builder/CheckstyleWriterTest.java | 24 ++++++----- 5 files changed, 114 insertions(+), 13 deletions(-) create mode 100644 builder/src/main/java/net/kemitix/checkstyle/ruleset/builder/CheckstyleWriterException.java create mode 100644 builder/src/main/java/net/kemitix/checkstyle/ruleset/builder/TemplateNotFoundException.java create mode 100644 builder/src/test/java/net/kemitix/checkstyle/ruleset/builder/CheckstyleWriterExceptionTest.java diff --git a/builder/src/main/java/net/kemitix/checkstyle/ruleset/builder/CheckstyleWriter.java b/builder/src/main/java/net/kemitix/checkstyle/ruleset/builder/CheckstyleWriter.java index 0619a7d..3e676e7 100644 --- a/builder/src/main/java/net/kemitix/checkstyle/ruleset/builder/CheckstyleWriter.java +++ b/builder/src/main/java/net/kemitix/checkstyle/ruleset/builder/CheckstyleWriter.java @@ -91,10 +91,10 @@ class CheckstyleWriter implements CommandLineRunner { log.info("Writing xmlFile: {}", xmlFile); Files.write(xmlFile, output, StandardCharsets.UTF_8); } else { - throw new IOException("Missing template: " + checkstyleXmlTemplate.toString()); + throw new TemplateNotFoundException(checkstyleXmlTemplate); } } catch (IOException e) { - throw new RuntimeException(e); + throw new CheckstyleWriterException(e); } } diff --git a/builder/src/main/java/net/kemitix/checkstyle/ruleset/builder/CheckstyleWriterException.java b/builder/src/main/java/net/kemitix/checkstyle/ruleset/builder/CheckstyleWriterException.java new file mode 100644 index 0000000..641d96e --- /dev/null +++ b/builder/src/main/java/net/kemitix/checkstyle/ruleset/builder/CheckstyleWriterException.java @@ -0,0 +1,39 @@ +/** + * The MIT License (MIT) + * + * Copyright (c) 2017 Paul Campbell + * + * Permission is hereby granted, free of charge, to any person obtaining a copy of this software + * and associated documentation files (the "Software"), to deal in the Software without restriction, + * including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, + * subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all copies + * or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, + * INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE + * AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, + * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + */ + +package net.kemitix.checkstyle.ruleset.builder; + +/** + * Raised when there was an error writing a Checkstyle ruleset. + * + * @author Paul Campbell (pcampbell@kemitix.net) + */ +class CheckstyleWriterException extends RuntimeException { + + /** + * Constructor. + * + * @param cause the cause + */ + CheckstyleWriterException(final Throwable cause) { + super(cause); + } +} diff --git a/builder/src/main/java/net/kemitix/checkstyle/ruleset/builder/TemplateNotFoundException.java b/builder/src/main/java/net/kemitix/checkstyle/ruleset/builder/TemplateNotFoundException.java new file mode 100644 index 0000000..08d1521 --- /dev/null +++ b/builder/src/main/java/net/kemitix/checkstyle/ruleset/builder/TemplateNotFoundException.java @@ -0,0 +1,41 @@ +/** + * The MIT License (MIT) + * + * Copyright (c) 2017 Paul Campbell + * + * Permission is hereby granted, free of charge, to any person obtaining a copy of this software + * and associated documentation files (the "Software"), to deal in the Software without restriction, + * including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, + * subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all copies + * or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, + * INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE + * AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, + * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + */ + +package net.kemitix.checkstyle.ruleset.builder; + +import java.nio.file.Path; + +/** + * Raised when a rule template is not found. + * + * @author Paul Campbell (pcampbell@kemitix.net) + */ +class TemplateNotFoundException extends RuntimeException { + + /** + * Constructor. + * + * @param template the missing template + */ + TemplateNotFoundException(final Path template) { + super("Missing template: " + template.toString()); + } +} diff --git a/builder/src/test/java/net/kemitix/checkstyle/ruleset/builder/CheckstyleWriterExceptionTest.java b/builder/src/test/java/net/kemitix/checkstyle/ruleset/builder/CheckstyleWriterExceptionTest.java new file mode 100644 index 0000000..ee44130 --- /dev/null +++ b/builder/src/test/java/net/kemitix/checkstyle/ruleset/builder/CheckstyleWriterExceptionTest.java @@ -0,0 +1,19 @@ +package net.kemitix.checkstyle.ruleset.builder; + +import org.junit.Test; + +/** + * Tests for {@link CheckstyleWriterException}. + * + * @author Paul Campbell (pcampbell@kemitix.net) + */ +public class CheckstyleWriterExceptionTest { + + @Test + public void canCreateException() { + //given + //when + //then + } + +} diff --git a/builder/src/test/java/net/kemitix/checkstyle/ruleset/builder/CheckstyleWriterTest.java b/builder/src/test/java/net/kemitix/checkstyle/ruleset/builder/CheckstyleWriterTest.java index da7d873..733908a 100644 --- a/builder/src/test/java/net/kemitix/checkstyle/ruleset/builder/CheckstyleWriterTest.java +++ b/builder/src/test/java/net/kemitix/checkstyle/ruleset/builder/CheckstyleWriterTest.java @@ -2,9 +2,9 @@ package net.kemitix.checkstyle.ruleset.builder; import lombok.val; import me.andrz.builder.map.MapBuilder; +import org.assertj.core.api.ThrowableAssert; import org.junit.Before; import org.junit.Test; -import org.junit.rules.ExpectedException; import org.junit.rules.TemporaryFolder; import org.mockito.MockitoAnnotations; @@ -20,6 +20,7 @@ import java.util.Map; import java.util.UUID; import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.Assertions.assertThatThrownBy; /** * Tests for {@link CheckstyleWriter}. @@ -48,9 +49,6 @@ public class CheckstyleWriterTest { private Path checkstyleTemplate; - @org.junit.Rule - public ExpectedException exception = ExpectedException.none(); - @org.junit.Rule public TemporaryFolder folder = new TemporaryFolder(); @@ -173,10 +171,11 @@ public class CheckstyleWriterTest { public void throwRteIfTemplateNotFound() throws Exception { //given templateProperties.setCheckstyleXml(Paths.get("garbage")); - exception.expect(RuntimeException.class); - exception.expectMessage("Missing template: garbage"); //when - checkstyleWriter.run(); + final ThrowableAssert.ThrowingCallable action = () -> checkstyleWriter.run(); + //then + assertThatThrownBy(action).isInstanceOf(TemplateNotFoundException.class) + .hasMessage("Missing template: garbage"); } // throw RTE if error writing file @@ -185,11 +184,14 @@ public class CheckstyleWriterTest { //given final String imaginary = String.join(FILE_SEPARATOR, "", "..", "imaginary"); outputProperties.setDirectory(Paths.get(imaginary)); - exception.expect(RuntimeException.class); - exception.expectMessage( - "java.nio.file.NoSuchFileException: " + imaginary + FILE_SEPARATOR + "checkstyle-LAYOUT.xml"); //when - checkstyleWriter.run(); + final ThrowableAssert.ThrowingCallable action = () -> checkstyleWriter.run(); + //then + assertThatThrownBy(action).isInstanceOf(CheckstyleWriterException.class) + .hasMessage( + String.format("java.nio.file.NoSuchFileException: %scheckstyle-LAYOUT.xml", + imaginary + FILE_SEPARATOR + )); } private Map.Entry getOutputFile(final RuleLevel level) throws IOException { From 9ac59206a0c0a85de8e224d88a59078c8b4235c6 Mon Sep 17 00:00:00 2001 From: Paul Campbell Date: Mon, 29 May 2017 11:26:24 +0100 Subject: [PATCH 09/39] KCR28: builder: remove empty test class --- .../CheckstyleWriterExceptionTest.java | 19 ------------------- 1 file changed, 19 deletions(-) delete mode 100644 builder/src/test/java/net/kemitix/checkstyle/ruleset/builder/CheckstyleWriterExceptionTest.java diff --git a/builder/src/test/java/net/kemitix/checkstyle/ruleset/builder/CheckstyleWriterExceptionTest.java b/builder/src/test/java/net/kemitix/checkstyle/ruleset/builder/CheckstyleWriterExceptionTest.java deleted file mode 100644 index ee44130..0000000 --- a/builder/src/test/java/net/kemitix/checkstyle/ruleset/builder/CheckstyleWriterExceptionTest.java +++ /dev/null @@ -1,19 +0,0 @@ -package net.kemitix.checkstyle.ruleset.builder; - -import org.junit.Test; - -/** - * Tests for {@link CheckstyleWriterException}. - * - * @author Paul Campbell (pcampbell@kemitix.net) - */ -public class CheckstyleWriterExceptionTest { - - @Test - public void canCreateException() { - //given - //when - //then - } - -} From 9d2895269d81801385014fba3a85c4bc515c79db Mon Sep 17 00:00:00 2001 From: Paul Campbell Date: Mon, 29 May 2017 11:29:52 +0100 Subject: [PATCH 10/39] KCR29: builder: Rule: sortByName(): use explicit scoping --- .../main/java/net/kemitix/checkstyle/ruleset/builder/Rule.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/builder/src/main/java/net/kemitix/checkstyle/ruleset/builder/Rule.java b/builder/src/main/java/net/kemitix/checkstyle/ruleset/builder/Rule.java index 8e8055b..6e6798e 100644 --- a/builder/src/main/java/net/kemitix/checkstyle/ruleset/builder/Rule.java +++ b/builder/src/main/java/net/kemitix/checkstyle/ruleset/builder/Rule.java @@ -95,7 +95,7 @@ public class Rule { * the right string; and a value greater than 0 if the left string is lexicographically greater than the right * string. */ - static int sortByName(final Rule left, final Rule right) { + protected static int sortByName(final Rule left, final Rule right) { return left.getLowerCaseRuleName() .compareTo(right.getLowerCaseRuleName()); } From 4a4da15d4fde90cf01142bb2e0bf7c238d9ee8cb Mon Sep 17 00:00:00 2001 From: Paul Campbell Date: Mon, 29 May 2017 11:45:55 +0100 Subject: [PATCH 11/39] KCR29: travis-ci: should only submit coverage report from Travis-CI --- travis-ci/travis-coveralls-report.sh | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/travis-ci/travis-coveralls-report.sh b/travis-ci/travis-coveralls-report.sh index aab1704..ae6c472 100755 --- a/travis-ci/travis-coveralls-report.sh +++ b/travis-ci/travis-coveralls-report.sh @@ -1,3 +1,5 @@ #!/usr/bin/env bash -./mvnw --projects builder,plugin test jacoco:report coveralls:report +if [ "$TRAVIS" = "true" ];then + ./mvnw --projects builder,plugin test jacoco:report coveralls:report +fi From dd17826a609fbb67ad6c1824ad199273c0040ca5 Mon Sep 17 00:00:00 2001 From: Paul Campbell Date: Mon, 29 May 2017 11:51:29 +0100 Subject: [PATCH 12/39] KCR29: travis-ci: dump $TRAVIS and other env Trying to detect when running in Travis CI and not Shippable so only Travis-CI submits to coveralls. --- travis-ci/travis-coveralls-report.sh | 2 ++ 1 file changed, 2 insertions(+) diff --git a/travis-ci/travis-coveralls-report.sh b/travis-ci/travis-coveralls-report.sh index ae6c472..8411ecb 100755 --- a/travis-ci/travis-coveralls-report.sh +++ b/travis-ci/travis-coveralls-report.sh @@ -1,5 +1,7 @@ #!/usr/bin/env bash +echo "TRAVIS: $TRAVIS" +set if [ "$TRAVIS" = "true" ];then ./mvnw --projects builder,plugin test jacoco:report coveralls:report fi From 7229c11b30643137d99966e876e766aadd80fae1 Mon Sep 17 00:00:00 2001 From: Paul Campbell Date: Mon, 29 May 2017 12:04:43 +0100 Subject: [PATCH 13/39] KCR29: travis-ci: detect Travis-CI --- travis-ci/travis-coveralls-report.sh | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/travis-ci/travis-coveralls-report.sh b/travis-ci/travis-coveralls-report.sh index 8411ecb..5ef727d 100755 --- a/travis-ci/travis-coveralls-report.sh +++ b/travis-ci/travis-coveralls-report.sh @@ -1,7 +1,7 @@ #!/usr/bin/env bash -echo "TRAVIS: $TRAVIS" -set -if [ "$TRAVIS" = "true" ];then +## Only send coveralls reports from Travis-CI. Some CIs, like Shippable, lie by setting TRAVIS=true. +## Currently, Shippable, does not set TRAVIS_LANGUAGE, but Travis-CI does. +if [ "$TRAVIS_LANGUAGE" = "java" ];then ./mvnw --projects builder,plugin test jacoco:report coveralls:report fi From f7867283ffa7cb8b3c609213649798de8d279393 Mon Sep 17 00:00:00 2001 From: Paul Campbell Date: Mon, 29 May 2017 12:24:51 +0100 Subject: [PATCH 14/39] KCr30: CheckstyleWriterTest: checkstyleTemplate: make field local variable --- .../checkstyle/ruleset/builder/CheckstyleWriterTest.java | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/builder/src/test/java/net/kemitix/checkstyle/ruleset/builder/CheckstyleWriterTest.java b/builder/src/test/java/net/kemitix/checkstyle/ruleset/builder/CheckstyleWriterTest.java index 733908a..f70cbaf 100644 --- a/builder/src/test/java/net/kemitix/checkstyle/ruleset/builder/CheckstyleWriterTest.java +++ b/builder/src/test/java/net/kemitix/checkstyle/ruleset/builder/CheckstyleWriterTest.java @@ -47,8 +47,6 @@ public class CheckstyleWriterTest { private Path outputDirectory; - private Path checkstyleTemplate; - @org.junit.Rule public TemporaryFolder folder = new TemporaryFolder(); @@ -69,8 +67,8 @@ public class CheckstyleWriterTest { .toPath(); outputProperties.setDirectory(outputDirectory); templateProperties = new TemplateProperties(); - checkstyleTemplate = folder.newFile("checkstyle-template.xml") - .toPath(); + val checkstyleTemplate = folder.newFile("checkstyle-template.xml") + .toPath(); Files.write( checkstyleTemplate, TEMPLATE.getBytes(StandardCharsets.UTF_8), StandardOpenOption.TRUNCATE_EXISTING); templateProperties.setCheckstyleXml(checkstyleTemplate); From 27806fb2a2663ca063eab75f94b65b9aa6bd84c4 Mon Sep 17 00:00:00 2001 From: Paul Campbell Date: Mon, 29 May 2017 12:27:40 +0100 Subject: [PATCH 15/39] KCR31: builder: DefaultRuleReadmeLoaderTest: make field local * fragment (Fixes #31) * templateProperties (Fixes #32) --- .../ruleset/builder/DefaultRuleReadmeLoaderTest.java | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/builder/src/test/java/net/kemitix/checkstyle/ruleset/builder/DefaultRuleReadmeLoaderTest.java b/builder/src/test/java/net/kemitix/checkstyle/ruleset/builder/DefaultRuleReadmeLoaderTest.java index 708d4d2..f7a05f2 100644 --- a/builder/src/test/java/net/kemitix/checkstyle/ruleset/builder/DefaultRuleReadmeLoaderTest.java +++ b/builder/src/test/java/net/kemitix/checkstyle/ruleset/builder/DefaultRuleReadmeLoaderTest.java @@ -23,12 +23,8 @@ public class DefaultRuleReadmeLoaderTest { private RuleReadmeLoader loader; - private TemplateProperties templateProperties; - private Rule rule; - private Path fragment; - private Path fragments; @org.junit.Rule @@ -39,7 +35,7 @@ public class DefaultRuleReadmeLoaderTest { @Before public void setUp() throws Exception { - templateProperties = new TemplateProperties(); + final TemplateProperties templateProperties = new TemplateProperties(); fragments = folder.newFolder("fragments") .toPath(); templateProperties.setReadmeFragments(fragments); @@ -53,8 +49,8 @@ public class DefaultRuleReadmeLoaderTest { public void loadEnabledOkay() throws IOException { //given rule.setEnabled(true); - fragment = fragments.resolve("name.md"); - Files.write(fragment, Arrays.asList("", "body")); + final Path fragment1 = fragments.resolve("name.md"); + Files.write(fragment1, Arrays.asList("", "body")); //when val fragment = loader.load(rule); //then From c4f302d9e513c1ecbdcd45157f7c0fa81b663044 Mon Sep 17 00:00:00 2001 From: Paul Campbell Date: Mon, 29 May 2017 13:22:25 +0100 Subject: [PATCH 16/39] KCR33: builder: ReadmeWriterTest: outputProperties: make local Fixes #33 --- .../kemitix/checkstyle/ruleset/builder/ReadmeWriterTest.java | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/builder/src/test/java/net/kemitix/checkstyle/ruleset/builder/ReadmeWriterTest.java b/builder/src/test/java/net/kemitix/checkstyle/ruleset/builder/ReadmeWriterTest.java index bc45598..fa8612f 100644 --- a/builder/src/test/java/net/kemitix/checkstyle/ruleset/builder/ReadmeWriterTest.java +++ b/builder/src/test/java/net/kemitix/checkstyle/ruleset/builder/ReadmeWriterTest.java @@ -27,8 +27,6 @@ public class ReadmeWriterTest { private TemplateProperties templateProperties; - private OutputProperties outputProperties; - private RulesProperties rulesProperties; @Mock @@ -59,7 +57,7 @@ public class ReadmeWriterTest { templateProperties = new TemplateProperties(); templateProperties.setReadmeTemplate(template); templateProperties.setReadmeFragments(fragments); - outputProperties = new OutputProperties(); + final OutputProperties outputProperties = new OutputProperties(); outputProperties.setReadme(readme); rulesProperties = new RulesProperties(); readmeWriter = From d754fdc0a394a7f304dcb40141b7e40631f74d3e Mon Sep 17 00:00:00 2001 From: Paul Campbell Date: Mon, 29 May 2017 13:23:37 +0100 Subject: [PATCH 17/39] KCR34: builder: ReadmeWriterTest: template: make local variable --- .../checkstyle/ruleset/builder/ReadmeWriterTest.java | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/builder/src/test/java/net/kemitix/checkstyle/ruleset/builder/ReadmeWriterTest.java b/builder/src/test/java/net/kemitix/checkstyle/ruleset/builder/ReadmeWriterTest.java index fa8612f..61b584e 100644 --- a/builder/src/test/java/net/kemitix/checkstyle/ruleset/builder/ReadmeWriterTest.java +++ b/builder/src/test/java/net/kemitix/checkstyle/ruleset/builder/ReadmeWriterTest.java @@ -35,8 +35,6 @@ public class ReadmeWriterTest { @Mock private ReadmeIndexBuilder indexBuilder; - private Path template; - private Path fragments; private Path readme; @@ -47,8 +45,8 @@ public class ReadmeWriterTest { @Before public void setUp() throws Exception { MockitoAnnotations.initMocks(this); - template = folder.newFile("README-template.md") - .toPath(); + final Path template = folder.newFile("README-template.md") + .toPath(); Files.write(template, Arrays.asList("i:%s", "ce:%s", "se:%s", "cd:%s", "sd:%s")); fragments = folder.newFolder("fragments") .toPath(); From 74690d8cdfd39356fdb7e8f3516359ea5fd32b74 Mon Sep 17 00:00:00 2001 From: Paul Campbell Date: Mon, 29 May 2017 13:25:50 +0100 Subject: [PATCH 18/39] KCR35: builder: ReadmeWriterTest: fragments: make local variable --- .../checkstyle/ruleset/builder/ReadmeWriterTest.java | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/builder/src/test/java/net/kemitix/checkstyle/ruleset/builder/ReadmeWriterTest.java b/builder/src/test/java/net/kemitix/checkstyle/ruleset/builder/ReadmeWriterTest.java index 61b584e..df3b34f 100644 --- a/builder/src/test/java/net/kemitix/checkstyle/ruleset/builder/ReadmeWriterTest.java +++ b/builder/src/test/java/net/kemitix/checkstyle/ruleset/builder/ReadmeWriterTest.java @@ -35,8 +35,6 @@ public class ReadmeWriterTest { @Mock private ReadmeIndexBuilder indexBuilder; - private Path fragments; - private Path readme; @org.junit.Rule @@ -48,14 +46,14 @@ public class ReadmeWriterTest { final Path template = folder.newFile("README-template.md") .toPath(); Files.write(template, Arrays.asList("i:%s", "ce:%s", "se:%s", "cd:%s", "sd:%s")); - fragments = folder.newFolder("fragments") - .toPath(); - readme = folder.newFile("README.md") - .toPath(); templateProperties = new TemplateProperties(); templateProperties.setReadmeTemplate(template); + final Path fragments = folder.newFolder("fragments") + .toPath(); templateProperties.setReadmeFragments(fragments); final OutputProperties outputProperties = new OutputProperties(); + readme = folder.newFile("README.md") + .toPath(); outputProperties.setReadme(readme); rulesProperties = new RulesProperties(); readmeWriter = From 701b64e2c6eaebd0132bdf4d68872ebeb25e54aa Mon Sep 17 00:00:00 2001 From: Paul Campbell Date: Mon, 29 May 2017 13:27:24 +0100 Subject: [PATCH 19/39] builder: ReadmeWriterTest: templateProperties: make local variable --- .../kemitix/checkstyle/ruleset/builder/ReadmeWriterTest.java | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/builder/src/test/java/net/kemitix/checkstyle/ruleset/builder/ReadmeWriterTest.java b/builder/src/test/java/net/kemitix/checkstyle/ruleset/builder/ReadmeWriterTest.java index df3b34f..51ad769 100644 --- a/builder/src/test/java/net/kemitix/checkstyle/ruleset/builder/ReadmeWriterTest.java +++ b/builder/src/test/java/net/kemitix/checkstyle/ruleset/builder/ReadmeWriterTest.java @@ -25,8 +25,6 @@ public class ReadmeWriterTest { private ReadmeWriter readmeWriter; - private TemplateProperties templateProperties; - private RulesProperties rulesProperties; @Mock @@ -46,7 +44,7 @@ public class ReadmeWriterTest { final Path template = folder.newFile("README-template.md") .toPath(); Files.write(template, Arrays.asList("i:%s", "ce:%s", "se:%s", "cd:%s", "sd:%s")); - templateProperties = new TemplateProperties(); + final TemplateProperties templateProperties = new TemplateProperties(); templateProperties.setReadmeTemplate(template); final Path fragments = folder.newFolder("fragments") .toPath(); From 4cca4286a15ad566d3a4d7e561fad488893c2609 Mon Sep 17 00:00:00 2001 From: Paul Campbell Date: Mon, 29 May 2017 13:31:56 +0100 Subject: [PATCH 20/39] KXR36: plugin: DefaultCheckstyleExecutorTest: artifactFile: make local variable --- .../ruleset/plugin/DefaultCheckstyleExecutorTest.java | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/plugin/src/test/java/net/kemitix/checkstyle/ruleset/plugin/DefaultCheckstyleExecutorTest.java b/plugin/src/test/java/net/kemitix/checkstyle/ruleset/plugin/DefaultCheckstyleExecutorTest.java index b230eeb..8abc7b1 100644 --- a/plugin/src/test/java/net/kemitix/checkstyle/ruleset/plugin/DefaultCheckstyleExecutorTest.java +++ b/plugin/src/test/java/net/kemitix/checkstyle/ruleset/plugin/DefaultCheckstyleExecutorTest.java @@ -72,8 +72,6 @@ public class DefaultCheckstyleExecutorTest { @Mock private Artifact artifact; - private File artifactFile; - @Mock private MavenXpp3Reader mavenXpp3Reader; @@ -122,8 +120,8 @@ public class DefaultCheckstyleExecutorTest { .level(level) .build(); - artifactFile = folder.newFile("pom.xml"); given(artifactRepository.find(any())).willReturn(artifact); + final File artifactFile = folder.newFile("pom.xml"); given(artifact.getFile()).willReturn(artifactFile); given(mavenXpp3Reader.read(any(FileReader.class))).willReturn(pomModel); final Properties properties = new Properties(); From 710cfd151bad6e07bed10c81e9bf373e4214da08 Mon Sep 17 00:00:00 2001 From: Paul Campbell Date: Mon, 29 May 2017 13:34:52 +0100 Subject: [PATCH 21/39] KCR37: regressions: MoveVariableInsideIf: invalid(): use explicit scope --- .../kemitix/checkstyle/regressions/MoveVariableInsideIf.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/regressions/src/main/java/net/kemitix/checkstyle/regressions/MoveVariableInsideIf.java b/regressions/src/main/java/net/kemitix/checkstyle/regressions/MoveVariableInsideIf.java index bfdb49d..33dc9bd 100644 --- a/regressions/src/main/java/net/kemitix/checkstyle/regressions/MoveVariableInsideIf.java +++ b/regressions/src/main/java/net/kemitix/checkstyle/regressions/MoveVariableInsideIf.java @@ -42,7 +42,7 @@ class MoveVariableInsideIf { * @return value */ @SuppressWarnings("movevariableinsideif") - String invalid() { + private String invalid() { String variable = input.substring(1); if (condition) { return method(variable); From b6521b809c937fa6b68ca9245c1d6276fcb5b709 Mon Sep 17 00:00:00 2001 From: Paul Campbell Date: Mon, 29 May 2017 13:35:19 +0100 Subject: [PATCH 22/39] KCR38: regressions: MoveVariableInsideIf: valid(): use explicit scope --- .../kemitix/checkstyle/regressions/MoveVariableInsideIf.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/regressions/src/main/java/net/kemitix/checkstyle/regressions/MoveVariableInsideIf.java b/regressions/src/main/java/net/kemitix/checkstyle/regressions/MoveVariableInsideIf.java index 33dc9bd..bea9d91 100644 --- a/regressions/src/main/java/net/kemitix/checkstyle/regressions/MoveVariableInsideIf.java +++ b/regressions/src/main/java/net/kemitix/checkstyle/regressions/MoveVariableInsideIf.java @@ -55,7 +55,7 @@ class MoveVariableInsideIf { * * @return value */ - String valid() { + private String valid() { if (condition) { String variable = input.substring(1); return method(variable); From 55a28392f8b4126a48115b042586c0688eb93d2a Mon Sep 17 00:00:00 2001 From: Paul Campbell Date: Mon, 29 May 2017 13:39:04 +0100 Subject: [PATCH 23/39] KCR39: regressions: MoveVariableInsideIf: method(): use parameter --- .../kemitix/checkstyle/regressions/MoveVariableInsideIf.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/regressions/src/main/java/net/kemitix/checkstyle/regressions/MoveVariableInsideIf.java b/regressions/src/main/java/net/kemitix/checkstyle/regressions/MoveVariableInsideIf.java index bfdb49d..dd7dda2 100644 --- a/regressions/src/main/java/net/kemitix/checkstyle/regressions/MoveVariableInsideIf.java +++ b/regressions/src/main/java/net/kemitix/checkstyle/regressions/MoveVariableInsideIf.java @@ -33,7 +33,7 @@ class MoveVariableInsideIf { private boolean condition; private String method(final String variable) { - return "value"; + return "value: " + variable; } /** From 1a5ca4ceef1df94a255e8ef7751e23e619fe0010 Mon Sep 17 00:00:00 2001 From: Paul Campbell Date: Mon, 29 May 2017 14:10:04 +0100 Subject: [PATCH 24/39] KCR37+38: MoveVariableInsideIf: avoid unused private methods --- .../kemitix/checkstyle/regressions/MoveVariableInsideIf.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/regressions/src/main/java/net/kemitix/checkstyle/regressions/MoveVariableInsideIf.java b/regressions/src/main/java/net/kemitix/checkstyle/regressions/MoveVariableInsideIf.java index bea9d91..a13ccb3 100644 --- a/regressions/src/main/java/net/kemitix/checkstyle/regressions/MoveVariableInsideIf.java +++ b/regressions/src/main/java/net/kemitix/checkstyle/regressions/MoveVariableInsideIf.java @@ -42,7 +42,7 @@ class MoveVariableInsideIf { * @return value */ @SuppressWarnings("movevariableinsideif") - private String invalid() { + protected String invalid() { String variable = input.substring(1); if (condition) { return method(variable); @@ -55,7 +55,7 @@ class MoveVariableInsideIf { * * @return value */ - private String valid() { + protected String valid() { if (condition) { String variable = input.substring(1); return method(variable); From 9b571a5a582a001bf33a34e15cf3a2044614c213 Mon Sep 17 00:00:00 2001 From: Paul Campbell Date: Mon, 29 May 2017 14:20:16 +0100 Subject: [PATCH 25/39] travis-ci: only deploy from Travis-CI --- travis-ci/travis-deploy.sh | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/travis-ci/travis-deploy.sh b/travis-ci/travis-deploy.sh index 240dd26..cdc921b 100755 --- a/travis-ci/travis-deploy.sh +++ b/travis-ci/travis-deploy.sh @@ -1,6 +1,8 @@ #!/usr/bin/env bash -if [ "$TRAVIS_BRANCH" = 'master' ] && [ "$TRAVIS_PULL_REQUEST" == 'false' ]; then +## Only deploy from Travis-CI. Some CIs, like Shippable, lie by setting TRAVIS=true. +## Currently, Shippable, does not set TRAVIS_LANGUAGE, but Travis-CI does. +if [ "$TRAVIS_LANGUAGE" = "java" ] && [ "$TRAVIS_BRANCH" = 'master' ] && [ "$TRAVIS_PULL_REQUEST" == 'false' ]; then openssl aes-256-cbc -K $encrypted_efec3258f55d_key -iv $encrypted_efec3258f55d_iv \ -in travis-ci/codesigning.asc.enc -out travis-ci/codesigning.asc -d gpg --batch --fast-import travis-ci/codesigning.asc From 02087630c93f1a90346340e58b0a1c725752e1c4 Mon Sep 17 00:00:00 2001 From: Paul Campbell Date: Mon, 29 May 2017 14:40:21 +0100 Subject: [PATCH 26/39] shippable.yml: added --- shippable.yml | 8 ++++++++ 1 file changed, 8 insertions(+) create mode 100644 shippable.yml diff --git a/shippable.yml b/shippable.yml new file mode 100644 index 0000000..3d074c8 --- /dev/null +++ b/shippable.yml @@ -0,0 +1,8 @@ +language: java +jdk: +- oraclejdk8 +cache: + directories: + - "$HOME/.m2" +install: true +script: "./mvnw clean install" From 8c5a6e06fddbbb707730e1efe2563b82f3d8c834 Mon Sep 17 00:00:00 2001 From: Paul Campbell Date: Mon, 29 May 2017 14:46:59 +0100 Subject: [PATCH 27/39] travis-ci: remove defensive checks --- travis-ci/travis-coveralls-report.sh | 6 +----- travis-ci/travis-deploy.sh | 4 +--- 2 files changed, 2 insertions(+), 8 deletions(-) diff --git a/travis-ci/travis-coveralls-report.sh b/travis-ci/travis-coveralls-report.sh index 5ef727d..aab1704 100755 --- a/travis-ci/travis-coveralls-report.sh +++ b/travis-ci/travis-coveralls-report.sh @@ -1,7 +1,3 @@ #!/usr/bin/env bash -## Only send coveralls reports from Travis-CI. Some CIs, like Shippable, lie by setting TRAVIS=true. -## Currently, Shippable, does not set TRAVIS_LANGUAGE, but Travis-CI does. -if [ "$TRAVIS_LANGUAGE" = "java" ];then - ./mvnw --projects builder,plugin test jacoco:report coveralls:report -fi +./mvnw --projects builder,plugin test jacoco:report coveralls:report diff --git a/travis-ci/travis-deploy.sh b/travis-ci/travis-deploy.sh index cdc921b..240dd26 100755 --- a/travis-ci/travis-deploy.sh +++ b/travis-ci/travis-deploy.sh @@ -1,8 +1,6 @@ #!/usr/bin/env bash -## Only deploy from Travis-CI. Some CIs, like Shippable, lie by setting TRAVIS=true. -## Currently, Shippable, does not set TRAVIS_LANGUAGE, but Travis-CI does. -if [ "$TRAVIS_LANGUAGE" = "java" ] && [ "$TRAVIS_BRANCH" = 'master' ] && [ "$TRAVIS_PULL_REQUEST" == 'false' ]; then +if [ "$TRAVIS_BRANCH" = 'master' ] && [ "$TRAVIS_PULL_REQUEST" == 'false' ]; then openssl aes-256-cbc -K $encrypted_efec3258f55d_key -iv $encrypted_efec3258f55d_iv \ -in travis-ci/codesigning.asc.enc -out travis-ci/codesigning.asc -d gpg --batch --fast-import travis-ci/codesigning.asc From da5a14c1cea2e1a38cee58d42800cf05765e8ffe Mon Sep 17 00:00:00 2001 From: Paul Campbell Date: Mon, 29 May 2017 14:52:04 +0100 Subject: [PATCH 28/39] wercker.yml: added --- wercker.yml | 7 +++++++ 1 file changed, 7 insertions(+) create mode 100644 wercker.yml diff --git a/wercker.yml b/wercker.yml new file mode 100644 index 0000000..4c50a59 --- /dev/null +++ b/wercker.yml @@ -0,0 +1,7 @@ +box: maven:3.5.0-jdk-8 + +build: + steps: + - script: + name: maven clean install + code: ./mvnw clean install From 5b9e32d2eb469c5e85482a617dd4d70d4d3d72ca Mon Sep 17 00:00:00 2001 From: Paul Campbell Date: Mon, 29 May 2017 14:56:51 +0100 Subject: [PATCH 29/39] wercker.yml: rewritten --- wercker.yml | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/wercker.yml b/wercker.yml index 4c50a59..b152705 100644 --- a/wercker.yml +++ b/wercker.yml @@ -2,6 +2,5 @@ box: maven:3.5.0-jdk-8 build: steps: - - script: - name: maven clean install - code: ./mvnw clean install + - xenoterracide/maven: + goals: clean install From a0d58fca81d1caa8c95bcde8e09741b45dce608d Mon Sep 17 00:00:00 2001 From: Paul Campbell Date: Mon, 29 May 2017 20:31:22 +0100 Subject: [PATCH 30/39] travis-ci: verbose deploy --- travis-ci/travis-deploy.sh | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/travis-ci/travis-deploy.sh b/travis-ci/travis-deploy.sh index 240dd26..6ff7008 100755 --- a/travis-ci/travis-deploy.sh +++ b/travis-ci/travis-deploy.sh @@ -1,10 +1,18 @@ #!/usr/bin/env bash if [ "$TRAVIS_BRANCH" = 'master' ] && [ "$TRAVIS_PULL_REQUEST" == 'false' ]; then + echo "Preparing to deploy to nexus..." openssl aes-256-cbc -K $encrypted_efec3258f55d_key -iv $encrypted_efec3258f55d_iv \ -in travis-ci/codesigning.asc.enc -out travis-ci/codesigning.asc -d + echo "Signing key decrypted" gpg --batch --fast-import travis-ci/codesigning.asc + echo "Signing key imported" ./mvnw --projects plugin,ruleset --settings travis-ci/travis-settings.xml \ -Dskip-Tests=true -P release -B deploy + echo "Deploy complete" +else + echo "Not deploying" + echo " TRAVIS_BRANCH: $TRAVIS_BRANCH" + echo " TRAVIS_PULL_REQUEST: $TRAVIS_PULL_REQUEST" fi From a0ca4958fc0256608fd5fdc9af389db02241b800 Mon Sep 17 00:00:00 2001 From: Paul Campbell Date: Mon, 29 May 2017 23:55:42 +0100 Subject: [PATCH 31/39] builder: use fully qualified classnames in XML files In Checkstyle 7.8 a new mechanisim is used to lookup rules by name. This new method causes an exception to be thrown is there are more than one classes found that match the rule name. The solution is to use fully qualified class names in the module tag in the XML ruleset files. --- builder/pom.xml | 15 + .../CheckstyleClassNotFoundException.java | 39 +++ .../CheckstyleSourceLoadException.java | 42 +++ .../ruleset/builder/CheckstyleWriter.java | 4 +- .../checkstyle/ruleset/builder/Rule.java | 27 +- .../ruleset/builder/RuleSource.java | 40 ++- .../CheckstyleClassNotFoundExceptionTest.java | 24 ++ .../CheckstyleSourceLoadExceptionTest.java | 28 ++ .../ruleset/builder/CheckstyleWriterTest.java | 16 +- .../net/kemitix/checkstyle-1-layout.xml | 73 ++-- .../net/kemitix/checkstyle-2-naming.xml | 129 +++---- .../net/kemitix/checkstyle-3-javadoc.xml | 157 ++++----- .../net/kemitix/checkstyle-4-tweaks.xml | 249 +++++++------- .../net/kemitix/checkstyle-5-complexity.xml | 315 +++++++++--------- 14 files changed, 683 insertions(+), 475 deletions(-) create mode 100644 builder/src/main/java/net/kemitix/checkstyle/ruleset/builder/CheckstyleClassNotFoundException.java create mode 100644 builder/src/main/java/net/kemitix/checkstyle/ruleset/builder/CheckstyleSourceLoadException.java create mode 100644 builder/src/test/java/net/kemitix/checkstyle/ruleset/builder/CheckstyleClassNotFoundExceptionTest.java create mode 100644 builder/src/test/java/net/kemitix/checkstyle/ruleset/builder/CheckstyleSourceLoadExceptionTest.java diff --git a/builder/pom.xml b/builder/pom.xml index 1d0ffbf..73294ba 100644 --- a/builder/pom.xml +++ b/builder/pom.xml @@ -42,6 +42,8 @@ 2.3.5 1.0.0 4.3.0 + 7.8 + 1.24.0 @@ -92,6 +94,19 @@ ${map-builder.version} test + + + com.puppycrawl.tools + checkstyle + ${checkstyle.version} + compile + + + com.github.sevntu-checkstyle + sevntu-checks + ${sevntu.version} + + diff --git a/builder/src/main/java/net/kemitix/checkstyle/ruleset/builder/CheckstyleClassNotFoundException.java b/builder/src/main/java/net/kemitix/checkstyle/ruleset/builder/CheckstyleClassNotFoundException.java new file mode 100644 index 0000000..ffa297c --- /dev/null +++ b/builder/src/main/java/net/kemitix/checkstyle/ruleset/builder/CheckstyleClassNotFoundException.java @@ -0,0 +1,39 @@ +/** + * The MIT License (MIT) + * + * Copyright (c) 2017 Paul Campbell + * + * Permission is hereby granted, free of charge, to any person obtaining a copy of this software + * and associated documentation files (the "Software"), to deal in the Software without restriction, + * including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, + * subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all copies + * or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, + * INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE + * AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, + * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + */ + +package net.kemitix.checkstyle.ruleset.builder; + +/** + * Raised when a Class to implement a Rule is not found. + * + * @author Paul Campbell (pcampbell@kemitix.net). + */ +public class CheckstyleClassNotFoundException extends RuntimeException { + + /** + * Constructor. + * + * @param name the name of the unimplemented rule + */ + public CheckstyleClassNotFoundException(final String name) { + super("No class found to implement " + name); + } +} diff --git a/builder/src/main/java/net/kemitix/checkstyle/ruleset/builder/CheckstyleSourceLoadException.java b/builder/src/main/java/net/kemitix/checkstyle/ruleset/builder/CheckstyleSourceLoadException.java new file mode 100644 index 0000000..ef9b959 --- /dev/null +++ b/builder/src/main/java/net/kemitix/checkstyle/ruleset/builder/CheckstyleSourceLoadException.java @@ -0,0 +1,42 @@ +/** + * The MIT License (MIT) + * + * Copyright (c) 2017 Paul Campbell + * + * Permission is hereby granted, free of charge, to any person obtaining a copy of this software + * and associated documentation files (the "Software"), to deal in the Software without restriction, + * including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, + * subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all copies + * or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, + * INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE + * AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, + * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + */ + +package net.kemitix.checkstyle.ruleset.builder; + +import java.io.IOException; + +/** + * Raised when there is an error scanning for check classes. + * + * @author Paul Campbell (pcampbell@kemitix.net). + */ +public class CheckstyleSourceLoadException extends RuntimeException { + + /** + * Constructor. + * + * @param basePackage the base package classes were being loaded from + * @param cause the cause + */ + public CheckstyleSourceLoadException(final String basePackage, final IOException cause) { + super("Error loading checkstyle rules from package: " + basePackage, cause); + } +} diff --git a/builder/src/main/java/net/kemitix/checkstyle/ruleset/builder/CheckstyleWriter.java b/builder/src/main/java/net/kemitix/checkstyle/ruleset/builder/CheckstyleWriter.java index 0619a7d..5e3558a 100644 --- a/builder/src/main/java/net/kemitix/checkstyle/ruleset/builder/CheckstyleWriter.java +++ b/builder/src/main/java/net/kemitix/checkstyle/ruleset/builder/CheckstyleWriter.java @@ -101,9 +101,9 @@ class CheckstyleWriter implements CommandLineRunner { private String formatRuleAsModule(final Rule rule) { if (rule.getProperties() .isEmpty()) { - return String.format("", rule.getName()); + return String.format("", rule.getCanonicalClassName()); } - return String.format("%n %s%n", rule.getName(), + return String.format("%n %s%n", rule.getCanonicalClassName(), formatProperties(rule.getProperties()) ); } diff --git a/builder/src/main/java/net/kemitix/checkstyle/ruleset/builder/Rule.java b/builder/src/main/java/net/kemitix/checkstyle/ruleset/builder/Rule.java index 6e6798e..70f9ae7 100644 --- a/builder/src/main/java/net/kemitix/checkstyle/ruleset/builder/Rule.java +++ b/builder/src/main/java/net/kemitix/checkstyle/ruleset/builder/Rule.java @@ -40,6 +40,11 @@ public class Rule { private static final Locale LOCALE = Locale.ENGLISH; + /** + * Configuration properties. + */ + private final Map properties = new HashMap<>(); + /** * The name of the rule's Check class. */ @@ -80,11 +85,6 @@ public class Rule { */ private String reason; - /** - * Configuration properties. - */ - private final Map properties = new HashMap<>(); - /** * Compare two Rules lexicographically for sorting by rule name, ignoring case. * @@ -104,4 +104,21 @@ public class Rule { return getName().toLowerCase(LOCALE); } + /** + * Returns the canonical name of the class that implements this rule. + * + * @return the canonical name of the implementing class + */ + public String getCanonicalClassName() { + return source.getCheckClasses() + .filter(this::byRuleName) + .findFirst() + .orElseThrow(() -> new CheckstyleClassNotFoundException(name)); + } + + private boolean byRuleName(final String classname) { + final String classNameWithDelimiter = "." + name; + return classname.endsWith(classNameWithDelimiter) || classname.endsWith(classNameWithDelimiter + "Check"); + } + } diff --git a/builder/src/main/java/net/kemitix/checkstyle/ruleset/builder/RuleSource.java b/builder/src/main/java/net/kemitix/checkstyle/ruleset/builder/RuleSource.java index d675310..e10cb95 100644 --- a/builder/src/main/java/net/kemitix/checkstyle/ruleset/builder/RuleSource.java +++ b/builder/src/main/java/net/kemitix/checkstyle/ruleset/builder/RuleSource.java @@ -21,6 +21,14 @@ package net.kemitix.checkstyle.ruleset.builder; +import com.google.common.reflect.ClassPath; +import lombok.Getter; + +import java.io.IOException; +import java.util.List; +import java.util.stream.Collectors; +import java.util.stream.Stream; + /** * The origin of the rule. * @@ -28,6 +36,34 @@ package net.kemitix.checkstyle.ruleset.builder; */ public enum RuleSource { - CHECKSTYLE, - SEVNTU, + CHECKSTYLE("com.puppycrawl.tools.checkstyle"), + SEVNTU("com.github.sevntu.checkstyle.checks"); + + @Getter + private final String basePackage; + + private final List checkClasses; + + /** + * Constructor. + * + * @param basePackage the base package that contains all checks from this source + */ + RuleSource(final String basePackage) { + this.basePackage = basePackage; + try { + checkClasses = ClassPath.from(getClass().getClassLoader()) + .getTopLevelClassesRecursive(basePackage) + .stream() + .map(ClassPath.ClassInfo::getName) + .collect(Collectors.toList()); + } catch (IOException e) { + throw new CheckstyleSourceLoadException(basePackage, e); + } + } + + public Stream getCheckClasses() { + return checkClasses.stream() + .sorted(); + } } diff --git a/builder/src/test/java/net/kemitix/checkstyle/ruleset/builder/CheckstyleClassNotFoundExceptionTest.java b/builder/src/test/java/net/kemitix/checkstyle/ruleset/builder/CheckstyleClassNotFoundExceptionTest.java new file mode 100644 index 0000000..eadf0a5 --- /dev/null +++ b/builder/src/test/java/net/kemitix/checkstyle/ruleset/builder/CheckstyleClassNotFoundExceptionTest.java @@ -0,0 +1,24 @@ +package net.kemitix.checkstyle.ruleset.builder; + +import org.junit.Test; + +import static org.assertj.core.api.Assertions.assertThat; + +/** + * Tests for {@link CheckstyleClassNotFoundException}. + * + * @author Paul Campbell (pcampbell@kemitix.net). + */ +public class CheckstyleClassNotFoundExceptionTest { + + @Test + public void canRaiseException() { + //given + final String classname = "class name"; + //when + final CheckstyleClassNotFoundException exception = new CheckstyleClassNotFoundException(classname); + //then + assertThat(exception.getMessage()).startsWith("No class found to implement ") + .endsWith(classname); + } +} diff --git a/builder/src/test/java/net/kemitix/checkstyle/ruleset/builder/CheckstyleSourceLoadExceptionTest.java b/builder/src/test/java/net/kemitix/checkstyle/ruleset/builder/CheckstyleSourceLoadExceptionTest.java new file mode 100644 index 0000000..cb3d1b1 --- /dev/null +++ b/builder/src/test/java/net/kemitix/checkstyle/ruleset/builder/CheckstyleSourceLoadExceptionTest.java @@ -0,0 +1,28 @@ +package net.kemitix.checkstyle.ruleset.builder; + +import org.junit.Test; + +import java.io.IOException; + +import static org.assertj.core.api.AssertionsForClassTypes.assertThat; + +/** + * Tests for {@link CheckstyleSourceLoadException}. + * + * @author Paul Campbell (pcampbell@kemitix.net). + */ +public class CheckstyleSourceLoadExceptionTest { + + @Test + public void canRaiseException() { + //given + final String basePackage = "base package"; + final IOException cause = new IOException(); + //when + final CheckstyleSourceLoadException exception = new CheckstyleSourceLoadException(basePackage, cause); + //then + assertThat(exception).hasCause(cause) + .hasMessageStartingWith("Error loading checkstyle rules from package: ") + .hasMessageEndingWith(basePackage); + } +} diff --git a/builder/src/test/java/net/kemitix/checkstyle/ruleset/builder/CheckstyleWriterTest.java b/builder/src/test/java/net/kemitix/checkstyle/ruleset/builder/CheckstyleWriterTest.java index da7d873..4c7547b 100644 --- a/builder/src/test/java/net/kemitix/checkstyle/ruleset/builder/CheckstyleWriterTest.java +++ b/builder/src/test/java/net/kemitix/checkstyle/ruleset/builder/CheckstyleWriterTest.java @@ -17,7 +17,6 @@ import java.nio.file.StandardOpenOption; import java.util.AbstractMap; import java.util.List; import java.util.Map; -import java.util.UUID; import static org.assertj.core.api.Assertions.assertThat; @@ -42,6 +41,8 @@ public class CheckstyleWriterTest { private String ruleName; + private String ruleClassname; + private Map outputFiles; private Path outputDirectory; @@ -57,8 +58,8 @@ public class CheckstyleWriterTest { @Before public void setUp() throws Exception { MockitoAnnotations.initMocks(this); - ruleName = UUID.randomUUID() - .toString(); + ruleName = "RegexpOnFilename"; + ruleClassname = "com.puppycrawl.tools.checkstyle.checks.regexp.RegexpOnFilenameCheck"; outputProperties = new OutputProperties(); outputFiles = new MapBuilder().put(getOutputFile(RuleLevel.LAYOUT)) .put(getOutputFile(RuleLevel.NAMING)) @@ -91,7 +92,7 @@ public class CheckstyleWriterTest { checkstyleWriter.run(); //then val lines = loadOutputFile(RuleLevel.LAYOUT); - assertThat(lines).containsExactly("C:", String.format("TW:", ruleName)); + assertThat(lines).containsExactly("C:", String.format("TW:", ruleClassname)); } // write rule that is below current level @@ -105,7 +106,7 @@ public class CheckstyleWriterTest { checkstyleWriter.run(); //then val lines = loadOutputFile(RuleLevel.NAMING); - assertThat(lines).containsExactly("C:", String.format("TW:", ruleName)); + assertThat(lines).containsExactly("C:", String.format("TW:", ruleClassname)); } // write rule with checker parent @@ -119,7 +120,7 @@ public class CheckstyleWriterTest { checkstyleWriter.run(); //then val lines = loadOutputFile(RuleLevel.LAYOUT); - assertThat(lines).containsExactly(String.format("C:", ruleName), "TW:"); + assertThat(lines).containsExactly(String.format("C:", ruleClassname), "TW:"); } // write rule with properties @@ -135,7 +136,7 @@ public class CheckstyleWriterTest { checkstyleWriter.run(); //then val lines = loadOutputFile(RuleLevel.LAYOUT); - assertThat(lines).containsExactly("C:", String.format("TW:", ruleName), + assertThat(lines).containsExactly("C:", String.format("TW:", ruleClassname), " ", "" ); } @@ -207,6 +208,7 @@ public class CheckstyleWriterTest { private Rule enabledRule(final RuleLevel level, final RuleParent parent) { val rule = new Rule(); rule.setName(ruleName); + rule.setSource(RuleSource.CHECKSTYLE); rule.setEnabled(true); rule.setLevel(level); rule.setParent(parent); diff --git a/ruleset/src/main/resources/net/kemitix/checkstyle-1-layout.xml b/ruleset/src/main/resources/net/kemitix/checkstyle-1-layout.xml index c7c3f72..7dd6341 100644 --- a/ruleset/src/main/resources/net/kemitix/checkstyle-1-layout.xml +++ b/ruleset/src/main/resources/net/kemitix/checkstyle-1-layout.xml @@ -4,62 +4,63 @@ "http://www.puppycrawl.com/dtds/configuration_1_3.dtd"> - + - - + + - + - - - - - - - - - - - - - + + + + + + + + + + + + + - - - + + + - - - - - - - + + + + + + + - - - - - - - - - + + + + + + + + + + diff --git a/ruleset/src/main/resources/net/kemitix/checkstyle-2-naming.xml b/ruleset/src/main/resources/net/kemitix/checkstyle-2-naming.xml index 040fe94..8388113 100644 --- a/ruleset/src/main/resources/net/kemitix/checkstyle-2-naming.xml +++ b/ruleset/src/main/resources/net/kemitix/checkstyle-2-naming.xml @@ -4,94 +4,95 @@ "http://www.puppycrawl.com/dtds/configuration_1_3.dtd"> - + - - + + - + - + - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + - - - - - - - - - - - - - + + + + + + + + + + + + + - - - - - + + + + + - - - - + + + + - - - + + + - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + diff --git a/ruleset/src/main/resources/net/kemitix/checkstyle-3-javadoc.xml b/ruleset/src/main/resources/net/kemitix/checkstyle-3-javadoc.xml index 811e021..4b469d9 100644 --- a/ruleset/src/main/resources/net/kemitix/checkstyle-3-javadoc.xml +++ b/ruleset/src/main/resources/net/kemitix/checkstyle-3-javadoc.xml @@ -4,120 +4,121 @@ "http://www.puppycrawl.com/dtds/configuration_1_3.dtd"> - + - - + + - - + + - - - + + + - - - - - - + + + + + + - - - - - - - - - - - - - - + + + + + + + + + + + + + + - - - + + + - - + + - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + - - - - - - + + + + + + - - - - + + + + - - - + + + - - + + - - - - + + + + - - - - - - - - - - - + + + + + + + + + + + + diff --git a/ruleset/src/main/resources/net/kemitix/checkstyle-4-tweaks.xml b/ruleset/src/main/resources/net/kemitix/checkstyle-4-tweaks.xml index 2e27c90..a6ad5cc 100644 --- a/ruleset/src/main/resources/net/kemitix/checkstyle-4-tweaks.xml +++ b/ruleset/src/main/resources/net/kemitix/checkstyle-4-tweaks.xml @@ -4,179 +4,180 @@ "http://www.puppycrawl.com/dtds/configuration_1_3.dtd"> - + - - + + - - + + - - - + + + - - - - - - + + + + + + - + - - - - - - - - - + + + + + + + + + - - - - - - - - - - + + + + + + + + + + - - - - - - + + + + + + - - - - + + + + - - - + + + - - + + - - - - - - - - - - + + + + + + + + + + - - - - - - - - - - + + + + + + + + + + - - - - - - - - - + + + + + + + + + - - - - + + + + - - + + - - - - + + + + - - + + - - - - + + + + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/ruleset/src/main/resources/net/kemitix/checkstyle-5-complexity.xml b/ruleset/src/main/resources/net/kemitix/checkstyle-5-complexity.xml index bc2b68b..f486e8c 100644 --- a/ruleset/src/main/resources/net/kemitix/checkstyle-5-complexity.xml +++ b/ruleset/src/main/resources/net/kemitix/checkstyle-5-complexity.xml @@ -4,232 +4,233 @@ "http://www.puppycrawl.com/dtds/configuration_1_3.dtd"> - + - - - + + + - - + + - - - + + + - - - - - - - + + + + + + + - + - - - - + + + + - + - - - - - - - - + + + + + + + + - - - - - + + + + + - - - - - - - - - - - - - + + + + + + + + + + + + + - - - - - - + + + + + + - - - - - + + + + + - - - + + + - + - - + + - - - - - + + + + + - + - - - - - - + + + + + + - - - - - - - - + + + + + + + + - - - - - + + + + + - - + + - - - - - - - - + + + + + + + + - - + + - - - + + + - - - + + + - - - - - - + + + + + + - - - + + + - - - - + + + + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + From 061cc5ff911efa0bbf591a7ae9a9243e8d8098f6 Mon Sep 17 00:00:00 2001 From: Paul Campbell Date: Tue, 30 May 2017 00:02:11 +0100 Subject: [PATCH 32/39] wercker.yml: added --- wercker.yml | 6 ++++++ 1 file changed, 6 insertions(+) create mode 100644 wercker.yml diff --git a/wercker.yml b/wercker.yml new file mode 100644 index 0000000..b152705 --- /dev/null +++ b/wercker.yml @@ -0,0 +1,6 @@ +box: maven:3.5.0-jdk-8 + +build: + steps: + - xenoterracide/maven: + goals: clean install From 2e8e26c3517874ba4a0ff07a3c207de9e6c3c7b1 Mon Sep 17 00:00:00 2001 From: Paul Campbell Date: Tue, 30 May 2017 12:32:29 +0100 Subject: [PATCH 33/39] builder: refactored and improved test coverage --- .../ruleset/builder/BuilderConfiguration.java | 49 ++++++++++++ .../ruleset/builder/CheckstyleWriter.java | 6 +- .../builder/DefaultPackageScanner.java | 47 +++++++++++ .../builder/DefaultRuleClassLocator.java | 77 +++++++++++++++++++ .../ruleset/builder/PackageScanner.java | 34 ++++++++ .../checkstyle/ruleset/builder/Rule.java | 18 ----- .../ruleset/builder/RuleClassLocator.java | 33 ++++++++ .../ruleset/builder/RuleSource.java | 21 ----- .../ruleset/builder/CheckstyleWriterTest.java | 64 ++++++++------- .../builder/DefaultPackageScannerTest.java | 46 +++++++++++ .../builder/DefaultRuleClassLocatorTest.java | 55 +++++++++++++ .../ruleset/builder/RuleSourceTest.java | 12 +++ .../net/kemitix/checkstyle-1-layout.xml | 1 - .../net/kemitix/checkstyle-2-naming.xml | 1 - .../net/kemitix/checkstyle-3-javadoc.xml | 1 - .../net/kemitix/checkstyle-4-tweaks.xml | 1 - .../net/kemitix/checkstyle-5-complexity.xml | 1 - 17 files changed, 393 insertions(+), 74 deletions(-) create mode 100644 builder/src/main/java/net/kemitix/checkstyle/ruleset/builder/BuilderConfiguration.java create mode 100644 builder/src/main/java/net/kemitix/checkstyle/ruleset/builder/DefaultPackageScanner.java create mode 100644 builder/src/main/java/net/kemitix/checkstyle/ruleset/builder/DefaultRuleClassLocator.java create mode 100644 builder/src/main/java/net/kemitix/checkstyle/ruleset/builder/PackageScanner.java create mode 100644 builder/src/main/java/net/kemitix/checkstyle/ruleset/builder/RuleClassLocator.java create mode 100644 builder/src/test/java/net/kemitix/checkstyle/ruleset/builder/DefaultPackageScannerTest.java create mode 100644 builder/src/test/java/net/kemitix/checkstyle/ruleset/builder/DefaultRuleClassLocatorTest.java diff --git a/builder/src/main/java/net/kemitix/checkstyle/ruleset/builder/BuilderConfiguration.java b/builder/src/main/java/net/kemitix/checkstyle/ruleset/builder/BuilderConfiguration.java new file mode 100644 index 0000000..197c38c --- /dev/null +++ b/builder/src/main/java/net/kemitix/checkstyle/ruleset/builder/BuilderConfiguration.java @@ -0,0 +1,49 @@ +/** + * The MIT License (MIT) + * + * Copyright (c) 2017 Paul Campbell + * + * Permission is hereby granted, free of charge, to any person obtaining a copy of this software + * and associated documentation files (the "Software"), to deal in the Software without restriction, + * including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, + * subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all copies + * or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, + * INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE + * AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, + * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + */ + +package net.kemitix.checkstyle.ruleset.builder; + +import com.google.common.reflect.ClassPath; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; + +import java.io.IOException; + +/** + * Configuration for Builder. + * + * @author Paul Campbell (pcampbell@kemitix.net). + */ +@Configuration +public class BuilderConfiguration { + + /** + * Create the ClassPath used to scan packages. + * + * @return the ClassPath + * + * @throws IOException if there is an error + */ + @Bean + public ClassPath classPath() throws IOException { + return ClassPath.from(getClass().getClassLoader()); + } +} diff --git a/builder/src/main/java/net/kemitix/checkstyle/ruleset/builder/CheckstyleWriter.java b/builder/src/main/java/net/kemitix/checkstyle/ruleset/builder/CheckstyleWriter.java index 5e3558a..a9df0cd 100644 --- a/builder/src/main/java/net/kemitix/checkstyle/ruleset/builder/CheckstyleWriter.java +++ b/builder/src/main/java/net/kemitix/checkstyle/ruleset/builder/CheckstyleWriter.java @@ -55,6 +55,8 @@ class CheckstyleWriter implements CommandLineRunner { private final RulesProperties rulesProperties; + private final RuleClassLocator ruleClassLocator; + @Override public void run(final String... args) throws Exception { Stream.of(RuleLevel.values()) @@ -101,9 +103,9 @@ class CheckstyleWriter implements CommandLineRunner { private String formatRuleAsModule(final Rule rule) { if (rule.getProperties() .isEmpty()) { - return String.format("", rule.getCanonicalClassName()); + return String.format("", ruleClassLocator.apply(rule)); } - return String.format("%n %s%n", rule.getCanonicalClassName(), + return String.format("%n %s%n", ruleClassLocator.apply(rule), formatProperties(rule.getProperties()) ); } diff --git a/builder/src/main/java/net/kemitix/checkstyle/ruleset/builder/DefaultPackageScanner.java b/builder/src/main/java/net/kemitix/checkstyle/ruleset/builder/DefaultPackageScanner.java new file mode 100644 index 0000000..aea4769 --- /dev/null +++ b/builder/src/main/java/net/kemitix/checkstyle/ruleset/builder/DefaultPackageScanner.java @@ -0,0 +1,47 @@ +/** + * The MIT License (MIT) + * + * Copyright (c) 2017 Paul Campbell + * + * Permission is hereby granted, free of charge, to any person obtaining a copy of this software + * and associated documentation files (the "Software"), to deal in the Software without restriction, + * including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, + * subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all copies + * or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, + * INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE + * AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, + * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + */ + +package net.kemitix.checkstyle.ruleset.builder; + +import com.google.common.reflect.ClassPath; +import lombok.RequiredArgsConstructor; +import org.springframework.stereotype.Service; + +import java.util.stream.Stream; + +/** + * Default implementation of {@link PackageScanner}. + * + * @author Paul Campbell (pcampbell@kemitix.net). + */ +@Service +@RequiredArgsConstructor +public class DefaultPackageScanner implements PackageScanner { + + private final ClassPath classPath; + + @Override + public final Stream apply(final RuleSource ruleSource) { + return classPath.getTopLevelClassesRecursive(ruleSource.getBasePackage()) + .stream() + .map(ClassPath.ClassInfo::getName); + } +} diff --git a/builder/src/main/java/net/kemitix/checkstyle/ruleset/builder/DefaultRuleClassLocator.java b/builder/src/main/java/net/kemitix/checkstyle/ruleset/builder/DefaultRuleClassLocator.java new file mode 100644 index 0000000..6a91c6b --- /dev/null +++ b/builder/src/main/java/net/kemitix/checkstyle/ruleset/builder/DefaultRuleClassLocator.java @@ -0,0 +1,77 @@ +/** + * The MIT License (MIT) + * + * Copyright (c) 2017 Paul Campbell + * + * Permission is hereby granted, free of charge, to any person obtaining a copy of this software + * and associated documentation files (the "Software"), to deal in the Software without restriction, + * including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, + * subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all copies + * or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, + * INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE + * AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, + * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + */ + +package net.kemitix.checkstyle.ruleset.builder; + +import lombok.RequiredArgsConstructor; +import org.springframework.stereotype.Service; + +import javax.annotation.PostConstruct; +import java.util.AbstractMap; +import java.util.List; +import java.util.Map; +import java.util.stream.Collectors; +import java.util.stream.Stream; + +/** + * Default implementation of {@link RuleClassLocator}. + * + * @author Paul Campbell (pcampbell@kemitix.net). + */ +@Service +@RequiredArgsConstructor +public class DefaultRuleClassLocator implements RuleClassLocator { + + private final PackageScanner packageScanner; + + private Map> checkClasses; + + /** + * Initialise class lists for {@link RuleSource}s. + */ + @PostConstruct + public final void init() { + checkClasses = Stream.of(RuleSource.values()) + .map(source -> new AbstractMap.SimpleEntry<>( + source, packageScanner.apply(source) + .collect(Collectors.toList()))) + .collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue)); + } + + @Override + public final String apply(final Rule rule) { + return getCanonicalClassName(rule.getSource(), rule.getName()); + } + + private String getCanonicalClassName(final RuleSource source, final String name) { + return checkClasses.get(source) + .stream() + .sorted() + .filter(classname -> byRuleName(classname, name)) + .findFirst() + .orElseThrow(() -> new CheckstyleClassNotFoundException(name)); + } + + private boolean byRuleName(final String classname, final String name) { + final String classNameWithDelimiter = "." + name; + return classname.endsWith(classNameWithDelimiter) || classname.endsWith(classNameWithDelimiter + "Check"); + } +} diff --git a/builder/src/main/java/net/kemitix/checkstyle/ruleset/builder/PackageScanner.java b/builder/src/main/java/net/kemitix/checkstyle/ruleset/builder/PackageScanner.java new file mode 100644 index 0000000..7cc8c2b --- /dev/null +++ b/builder/src/main/java/net/kemitix/checkstyle/ruleset/builder/PackageScanner.java @@ -0,0 +1,34 @@ +/** + * The MIT License (MIT) + * + * Copyright (c) 2017 Paul Campbell + * + * Permission is hereby granted, free of charge, to any person obtaining a copy of this software + * and associated documentation files (the "Software"), to deal in the Software without restriction, + * including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, + * subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all copies + * or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, + * INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE + * AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, + * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + */ + +package net.kemitix.checkstyle.ruleset.builder; + +import java.util.function.Function; +import java.util.stream.Stream; + +/** + * Scans a package for all classes. + * + * @author Paul Campbell (pcampbell@kemitix.net). + */ +interface PackageScanner extends Function> { + +} diff --git a/builder/src/main/java/net/kemitix/checkstyle/ruleset/builder/Rule.java b/builder/src/main/java/net/kemitix/checkstyle/ruleset/builder/Rule.java index 70f9ae7..33c5624 100644 --- a/builder/src/main/java/net/kemitix/checkstyle/ruleset/builder/Rule.java +++ b/builder/src/main/java/net/kemitix/checkstyle/ruleset/builder/Rule.java @@ -103,22 +103,4 @@ public class Rule { private String getLowerCaseRuleName() { return getName().toLowerCase(LOCALE); } - - /** - * Returns the canonical name of the class that implements this rule. - * - * @return the canonical name of the implementing class - */ - public String getCanonicalClassName() { - return source.getCheckClasses() - .filter(this::byRuleName) - .findFirst() - .orElseThrow(() -> new CheckstyleClassNotFoundException(name)); - } - - private boolean byRuleName(final String classname) { - final String classNameWithDelimiter = "." + name; - return classname.endsWith(classNameWithDelimiter) || classname.endsWith(classNameWithDelimiter + "Check"); - } - } diff --git a/builder/src/main/java/net/kemitix/checkstyle/ruleset/builder/RuleClassLocator.java b/builder/src/main/java/net/kemitix/checkstyle/ruleset/builder/RuleClassLocator.java new file mode 100644 index 0000000..14b7d50 --- /dev/null +++ b/builder/src/main/java/net/kemitix/checkstyle/ruleset/builder/RuleClassLocator.java @@ -0,0 +1,33 @@ +/** + * The MIT License (MIT) + * + * Copyright (c) 2017 Paul Campbell + * + * Permission is hereby granted, free of charge, to any person obtaining a copy of this software + * and associated documentation files (the "Software"), to deal in the Software without restriction, + * including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, + * subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all copies + * or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, + * INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE + * AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, + * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + */ + +package net.kemitix.checkstyle.ruleset.builder; + +import java.util.function.Function; + +/** + * Returns the canonical name of the class that implements a {@link Rule}. + * + * @author Paul Campbell (pcampbell@kemitix.net). + */ +interface RuleClassLocator extends Function { + +} diff --git a/builder/src/main/java/net/kemitix/checkstyle/ruleset/builder/RuleSource.java b/builder/src/main/java/net/kemitix/checkstyle/ruleset/builder/RuleSource.java index e10cb95..a74871e 100644 --- a/builder/src/main/java/net/kemitix/checkstyle/ruleset/builder/RuleSource.java +++ b/builder/src/main/java/net/kemitix/checkstyle/ruleset/builder/RuleSource.java @@ -21,14 +21,8 @@ package net.kemitix.checkstyle.ruleset.builder; -import com.google.common.reflect.ClassPath; import lombok.Getter; -import java.io.IOException; -import java.util.List; -import java.util.stream.Collectors; -import java.util.stream.Stream; - /** * The origin of the rule. * @@ -42,7 +36,6 @@ public enum RuleSource { @Getter private final String basePackage; - private final List checkClasses; /** * Constructor. @@ -51,19 +44,5 @@ public enum RuleSource { */ RuleSource(final String basePackage) { this.basePackage = basePackage; - try { - checkClasses = ClassPath.from(getClass().getClassLoader()) - .getTopLevelClassesRecursive(basePackage) - .stream() - .map(ClassPath.ClassInfo::getName) - .collect(Collectors.toList()); - } catch (IOException e) { - throw new CheckstyleSourceLoadException(basePackage, e); - } - } - - public Stream getCheckClasses() { - return checkClasses.stream() - .sorted(); } } diff --git a/builder/src/test/java/net/kemitix/checkstyle/ruleset/builder/CheckstyleWriterTest.java b/builder/src/test/java/net/kemitix/checkstyle/ruleset/builder/CheckstyleWriterTest.java index 4c7547b..a409d3d 100644 --- a/builder/src/test/java/net/kemitix/checkstyle/ruleset/builder/CheckstyleWriterTest.java +++ b/builder/src/test/java/net/kemitix/checkstyle/ruleset/builder/CheckstyleWriterTest.java @@ -6,6 +6,7 @@ import org.junit.Before; import org.junit.Test; import org.junit.rules.ExpectedException; import org.junit.rules.TemporaryFolder; +import org.mockito.Mock; import org.mockito.MockitoAnnotations; import java.io.IOException; @@ -19,6 +20,8 @@ import java.util.List; import java.util.Map; import static org.assertj.core.api.Assertions.assertThat; +import static org.mockito.BDDMockito.given; +import static org.mockito.Matchers.any; /** * Tests for {@link CheckstyleWriter}. @@ -31,6 +34,12 @@ public class CheckstyleWriterTest { private static final String FILE_SEPARATOR = System.getProperty("file.separator"); + @org.junit.Rule + public ExpectedException exception = ExpectedException.none(); + + @org.junit.Rule + public TemporaryFolder folder = new TemporaryFolder(); + private CheckstyleWriter checkstyleWriter; private OutputProperties outputProperties; @@ -49,11 +58,8 @@ public class CheckstyleWriterTest { private Path checkstyleTemplate; - @org.junit.Rule - public ExpectedException exception = ExpectedException.none(); - - @org.junit.Rule - public TemporaryFolder folder = new TemporaryFolder(); + @Mock + private RuleClassLocator ruleClassLocator; @Before public void setUp() throws Exception { @@ -78,7 +84,14 @@ public class CheckstyleWriterTest { checkstyleTemplate, TEMPLATE.getBytes(StandardCharsets.UTF_8), StandardOpenOption.TRUNCATE_EXISTING); templateProperties.setCheckstyleXml(checkstyleTemplate); rulesProperties = new RulesProperties(); - checkstyleWriter = new CheckstyleWriter(outputProperties, templateProperties, rulesProperties); + checkstyleWriter = + new CheckstyleWriter(outputProperties, templateProperties, rulesProperties, ruleClassLocator); + given(ruleClassLocator.apply(any())).willReturn(ruleClassname); + } + + private Map.Entry getOutputFile(final RuleLevel level) throws IOException { + final String xmlFile = String.format("checkstyle-%s.xml", level.toString()); + return new AbstractMap.SimpleImmutableEntry<>(level, xmlFile); } // write rule that matches current level @@ -95,6 +108,23 @@ public class CheckstyleWriterTest { assertThat(lines).containsExactly("C:", String.format("TW:", ruleClassname)); } + private List loadOutputFile(final RuleLevel level) throws IOException { + val path = outputDirectory.resolve(outputFiles.get(level)); + assertThat(path).as("Output path exists") + .exists(); + return Files.readAllLines(path, StandardCharsets.UTF_8); + } + + private Rule enabledRule(final RuleLevel level, final RuleParent parent) { + val rule = new Rule(); + rule.setName(ruleName); + rule.setSource(RuleSource.CHECKSTYLE); + rule.setEnabled(true); + rule.setLevel(level); + rule.setParent(parent); + return rule; + } + // write rule that is below current level @Test public void writeRuleThatIsBelowCurrentLevel() throws Exception { @@ -192,26 +222,4 @@ public class CheckstyleWriterTest { //when checkstyleWriter.run(); } - - private Map.Entry getOutputFile(final RuleLevel level) throws IOException { - final String xmlFile = String.format("checkstyle-%s.xml", level.toString()); - return new AbstractMap.SimpleImmutableEntry<>(level, xmlFile); - } - - private List loadOutputFile(final RuleLevel level) throws IOException { - val path = outputDirectory.resolve(outputFiles.get(level)); - assertThat(path).as("Output path exists") - .exists(); - return Files.readAllLines(path, StandardCharsets.UTF_8); - } - - private Rule enabledRule(final RuleLevel level, final RuleParent parent) { - val rule = new Rule(); - rule.setName(ruleName); - rule.setSource(RuleSource.CHECKSTYLE); - rule.setEnabled(true); - rule.setLevel(level); - rule.setParent(parent); - return rule; - } } diff --git a/builder/src/test/java/net/kemitix/checkstyle/ruleset/builder/DefaultPackageScannerTest.java b/builder/src/test/java/net/kemitix/checkstyle/ruleset/builder/DefaultPackageScannerTest.java new file mode 100644 index 0000000..978200e --- /dev/null +++ b/builder/src/test/java/net/kemitix/checkstyle/ruleset/builder/DefaultPackageScannerTest.java @@ -0,0 +1,46 @@ +package net.kemitix.checkstyle.ruleset.builder; + +import com.google.common.reflect.ClassPath; +import org.junit.Before; +import org.junit.Test; + +import java.io.IOException; +import java.util.stream.Stream; + +import static org.assertj.core.api.Assertions.assertThat; + +/** + * Tests for {@link DefaultPackageScanner}. + * + * @author Paul Campbell (pcampbell@kemitix.net) + */ +public class DefaultPackageScannerTest { + + private ClassPath classPath; + + private DefaultPackageScanner scanner; + + @Before + public void setUp() throws Exception { + classPath = ClassPath.from(getClass().getClassLoader()); + scanner = new DefaultPackageScanner(classPath); + } + + @Test + public void canScanCheckstylePackage() throws IOException { + //when + final Stream result = scanner.apply(RuleSource.CHECKSTYLE); + //then + assertThat(result).allMatch(cn -> cn.startsWith(RuleSource.CHECKSTYLE.getBasePackage())) + .contains("com.puppycrawl.tools.checkstyle.checks.sizes.FileLengthCheck"); + } + + @Test + public void canScanSevntuPackage() throws IOException { + //when + final Stream result = scanner.apply(RuleSource.SEVNTU); + //then + assertThat(result).allMatch(cn -> cn.startsWith(RuleSource.SEVNTU.getBasePackage())) + .contains("com.github.sevntu.checkstyle.checks.design.NestedSwitchCheck"); + } +} diff --git a/builder/src/test/java/net/kemitix/checkstyle/ruleset/builder/DefaultRuleClassLocatorTest.java b/builder/src/test/java/net/kemitix/checkstyle/ruleset/builder/DefaultRuleClassLocatorTest.java new file mode 100644 index 0000000..e8ea62a --- /dev/null +++ b/builder/src/test/java/net/kemitix/checkstyle/ruleset/builder/DefaultRuleClassLocatorTest.java @@ -0,0 +1,55 @@ +package net.kemitix.checkstyle.ruleset.builder; + +import org.junit.Before; +import org.junit.Test; +import org.mockito.Mock; +import org.mockito.MockitoAnnotations; + +import java.util.Collections; +import java.util.List; + +import static org.assertj.core.api.Assertions.assertThat; +import static org.mockito.BDDMockito.given; + +/** + * Tests for {@link DefaultRuleClassLocator}. + * + * @author Paul Campbell (pcampbell@kemitix.net) + */ +public class DefaultRuleClassLocatorTest { + + private DefaultRuleClassLocator subject; + + @Mock + private PackageScanner packageScanner; + + @Before + public void setUp() { + MockitoAnnotations.initMocks(this); + subject = new DefaultRuleClassLocator(packageScanner); + } + + @Test + public void canLookupRule() { + //given + final String rulename = "RegexpOnFilename"; + final String expected = "com.puppycrawl.tools.checkstyle.checks.regexp.RegexpOnFilenameCheck"; + final List checkstyleClasses = Collections.singletonList(expected); + final List sevntuClasses = Collections.emptyList(); + given(packageScanner.apply(RuleSource.CHECKSTYLE)).willReturn(checkstyleClasses.stream()); + given(packageScanner.apply(RuleSource.SEVNTU)).willReturn(sevntuClasses.stream()); + subject.init(); + final Rule rule = createCheckstyleRule(rulename); + //when + final String result = subject.apply(rule); + //then + assertThat(result).isEqualTo(expected); + } + + private Rule createCheckstyleRule(final String rulename) { + final Rule rule = new Rule(); + rule.setSource(RuleSource.CHECKSTYLE); + rule.setName(rulename); + return rule; + } +} diff --git a/builder/src/test/java/net/kemitix/checkstyle/ruleset/builder/RuleSourceTest.java b/builder/src/test/java/net/kemitix/checkstyle/ruleset/builder/RuleSourceTest.java index 3cf5562..47397a4 100644 --- a/builder/src/test/java/net/kemitix/checkstyle/ruleset/builder/RuleSourceTest.java +++ b/builder/src/test/java/net/kemitix/checkstyle/ruleset/builder/RuleSourceTest.java @@ -30,4 +30,16 @@ public class RuleSourceTest { //then assertThat(values).containsExactlyElementsOf(expected); } + + @Test + public void basePackages() { + //given + final String puppycrawl = "puppycrawl"; + final String sevntu = "sevntu"; + //then + assertThat(RuleSource.CHECKSTYLE.getBasePackage()).contains(puppycrawl) + .doesNotContain(sevntu); + assertThat(RuleSource.SEVNTU.getBasePackage()).contains(sevntu) + .doesNotContain(puppycrawl); + } } diff --git a/ruleset/src/main/resources/net/kemitix/checkstyle-1-layout.xml b/ruleset/src/main/resources/net/kemitix/checkstyle-1-layout.xml index 7dd6341..dcb2199 100644 --- a/ruleset/src/main/resources/net/kemitix/checkstyle-1-layout.xml +++ b/ruleset/src/main/resources/net/kemitix/checkstyle-1-layout.xml @@ -63,4 +63,3 @@ - diff --git a/ruleset/src/main/resources/net/kemitix/checkstyle-2-naming.xml b/ruleset/src/main/resources/net/kemitix/checkstyle-2-naming.xml index 8388113..a4a70a0 100644 --- a/ruleset/src/main/resources/net/kemitix/checkstyle-2-naming.xml +++ b/ruleset/src/main/resources/net/kemitix/checkstyle-2-naming.xml @@ -95,4 +95,3 @@ - diff --git a/ruleset/src/main/resources/net/kemitix/checkstyle-3-javadoc.xml b/ruleset/src/main/resources/net/kemitix/checkstyle-3-javadoc.xml index 4b469d9..5536268 100644 --- a/ruleset/src/main/resources/net/kemitix/checkstyle-3-javadoc.xml +++ b/ruleset/src/main/resources/net/kemitix/checkstyle-3-javadoc.xml @@ -121,4 +121,3 @@ - diff --git a/ruleset/src/main/resources/net/kemitix/checkstyle-4-tweaks.xml b/ruleset/src/main/resources/net/kemitix/checkstyle-4-tweaks.xml index a6ad5cc..4a5e460 100644 --- a/ruleset/src/main/resources/net/kemitix/checkstyle-4-tweaks.xml +++ b/ruleset/src/main/resources/net/kemitix/checkstyle-4-tweaks.xml @@ -180,4 +180,3 @@ - diff --git a/ruleset/src/main/resources/net/kemitix/checkstyle-5-complexity.xml b/ruleset/src/main/resources/net/kemitix/checkstyle-5-complexity.xml index f486e8c..7181911 100644 --- a/ruleset/src/main/resources/net/kemitix/checkstyle-5-complexity.xml +++ b/ruleset/src/main/resources/net/kemitix/checkstyle-5-complexity.xml @@ -233,4 +233,3 @@ - From 1b318253d2a6e863e271d05da36961235922f84e Mon Sep 17 00:00:00 2001 From: Paul Campbell Date: Tue, 30 May 2017 12:43:34 +0100 Subject: [PATCH 34/39] builder: BuilderConfigurationTest: added --- .../builder/BuilderConfigurationTest.java | 24 +++++++++++++++++++ 1 file changed, 24 insertions(+) create mode 100644 builder/src/test/java/net/kemitix/checkstyle/ruleset/builder/BuilderConfigurationTest.java diff --git a/builder/src/test/java/net/kemitix/checkstyle/ruleset/builder/BuilderConfigurationTest.java b/builder/src/test/java/net/kemitix/checkstyle/ruleset/builder/BuilderConfigurationTest.java new file mode 100644 index 0000000..294cb87 --- /dev/null +++ b/builder/src/test/java/net/kemitix/checkstyle/ruleset/builder/BuilderConfigurationTest.java @@ -0,0 +1,24 @@ +package net.kemitix.checkstyle.ruleset.builder; + +import com.google.common.reflect.ClassPath; +import org.junit.Test; + +import java.io.IOException; + +import static org.assertj.core.api.Assertions.assertThat; + +/** + * Tests for {@link BuilderConfiguration}. + * + * @author Paul Campbell (pcampbell@kemitix.net) + */ +public class BuilderConfigurationTest { + + @Test + public void canGetClassPath() throws IOException { + //when + final ClassPath classPath = new BuilderConfiguration().classPath(); + //then + assertThat(classPath).isNotNull(); + } +} From f189fb3b846e9fcbce265b8ce50501900fcc5ffc Mon Sep 17 00:00:00 2001 From: Paul Campbell Date: Tue, 30 May 2017 12:44:33 +0100 Subject: [PATCH 35/39] builder: DefaultPackageScannerTest: make classPath local variable --- .../checkstyle/ruleset/builder/DefaultPackageScannerTest.java | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/builder/src/test/java/net/kemitix/checkstyle/ruleset/builder/DefaultPackageScannerTest.java b/builder/src/test/java/net/kemitix/checkstyle/ruleset/builder/DefaultPackageScannerTest.java index 978200e..e0540f2 100644 --- a/builder/src/test/java/net/kemitix/checkstyle/ruleset/builder/DefaultPackageScannerTest.java +++ b/builder/src/test/java/net/kemitix/checkstyle/ruleset/builder/DefaultPackageScannerTest.java @@ -16,13 +16,11 @@ import static org.assertj.core.api.Assertions.assertThat; */ public class DefaultPackageScannerTest { - private ClassPath classPath; - private DefaultPackageScanner scanner; @Before public void setUp() throws Exception { - classPath = ClassPath.from(getClass().getClassLoader()); + final ClassPath classPath = ClassPath.from(getClass().getClassLoader()); scanner = new DefaultPackageScanner(classPath); } From 9e657b36eca861769e5732cd888a1bd6f8b8b60e Mon Sep 17 00:00:00 2001 From: Paul Campbell Date: Tue, 30 May 2017 14:36:46 +0100 Subject: [PATCH 36/39] version: set to 3.1.0 --- builder/pom.xml | 2 +- plugin-sample/pom.xml | 4 ++-- plugin/pom.xml | 2 +- pom.xml | 2 +- regressions/pom.xml | 2 +- ruleset/pom.xml | 4 ++-- sample-parent/pom.xml | 2 +- 7 files changed, 9 insertions(+), 9 deletions(-) diff --git a/builder/pom.xml b/builder/pom.xml index 73294ba..aeb0f38 100644 --- a/builder/pom.xml +++ b/builder/pom.xml @@ -12,7 +12,7 @@ kemitix-checkstyle-ruleset-builder - 3.1.0-SNAPSHOT + 3.1.0 jar Kemitix Checkstyle Ruleset Builder diff --git a/plugin-sample/pom.xml b/plugin-sample/pom.xml index 2c7d70d..b49f4a4 100644 --- a/plugin-sample/pom.xml +++ b/plugin-sample/pom.xml @@ -10,12 +10,12 @@ net.kemitix kemitix-checkstyle-ruleset-sample-parent - 3.1.0-SNAPSHOT + 3.1.0 ../sample-parent kemitix-checkstyle-ruleset-plugin-sample - 3.1.0-SNAPSHOT + 3.1.0 Kemitix Checkstyle Ruleset Plugin Sample Sample usage of the Kemitix Checkstyle Ruleset Plugin diff --git a/plugin/pom.xml b/plugin/pom.xml index db90e76..033cd51 100644 --- a/plugin/pom.xml +++ b/plugin/pom.xml @@ -7,7 +7,7 @@ net.kemitix kemitix-checkstyle-ruleset-parent - 3.1.0-SNAPSHOT + 3.1.0 kemitix-checkstyle-ruleset-maven-plugin diff --git a/pom.xml b/pom.xml index 5c317d7..dcecdf7 100644 --- a/pom.xml +++ b/pom.xml @@ -6,7 +6,7 @@ net.kemitix kemitix-checkstyle-ruleset-parent - 3.1.0-SNAPSHOT + 3.1.0 pom Kemitix Checkstyle Ruleset (Parent) diff --git a/regressions/pom.xml b/regressions/pom.xml index 9fa775d..4a694c0 100644 --- a/regressions/pom.xml +++ b/regressions/pom.xml @@ -5,7 +5,7 @@ kemitix-checkstyle-ruleset-sample-parent net.kemitix - 3.1.0-SNAPSHOT + 3.1.0 ../sample-parent 4.0.0 diff --git a/ruleset/pom.xml b/ruleset/pom.xml index 1daa208..0f7726b 100644 --- a/ruleset/pom.xml +++ b/ruleset/pom.xml @@ -7,11 +7,11 @@ net.kemitix kemitix-checkstyle-ruleset-parent - 3.1.0-SNAPSHOT + 3.1.0 kemitix-checkstyle-ruleset - 3.1.0-SNAPSHOT + 3.1.0 jar Kemitix Checkstyle Ruleset diff --git a/sample-parent/pom.xml b/sample-parent/pom.xml index f59ce12..93d794d 100644 --- a/sample-parent/pom.xml +++ b/sample-parent/pom.xml @@ -8,7 +8,7 @@ kemitix-checkstyle-ruleset-sample-parent pom - 3.1.0-SNAPSHOT + 3.1.0 Kemitix Checkstyle Ruleset Sample Parent Sample parent for modules that use kemitix-checkstyle-ruleset-maven-plugin From 96381c9c90c8c9ac5cf8318a7557f506b3d841eb Mon Sep 17 00:00:00 2001 From: Paul Campbell Date: Tue, 30 May 2017 14:42:58 +0100 Subject: [PATCH 37/39] CHANGELOG --- CHANGELOG | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/CHANGELOG b/CHANGELOG index b0f55ad..5f4612a 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -1,6 +1,16 @@ CHANGELOG ========= +3.1.0 +----- + +* Upgrade checkstyle to 7.8 +* Upgrade sevntu to 1.24.0 +* Add Rule: MoveVariableInsideIf +* Add Rule: ForbidWildcardAsReturnType +* Add Wercker CI +* Add Shippable CI + 3.0.1 ----- From 4cc70343bebd8c6748d2e77ba9e60f6cb9f43f5b Mon Sep 17 00:00:00 2001 From: Paul Campbell Date: Tue, 30 May 2017 15:01:05 +0100 Subject: [PATCH 38/39] builder: ExplicitInitilization only applies to object references --- CHANGELOG | 1 + README.md | 8 +++++--- builder/src/main/resources/application.yml | 2 ++ .../src/main/resources/rules/ExplicitInitialization.md | 8 +++++--- .../checkstyle/regressions/ExplicitInitialization.java | 8 -------- .../main/resources/net/kemitix/checkstyle-4-tweaks.xml | 4 +++- .../resources/net/kemitix/checkstyle-5-complexity.xml | 4 +++- 7 files changed, 19 insertions(+), 16 deletions(-) diff --git a/CHANGELOG b/CHANGELOG index 5f4612a..fa87ae3 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -8,6 +8,7 @@ CHANGELOG * Upgrade sevntu to 1.24.0 * Add Rule: MoveVariableInsideIf * Add Rule: ForbidWildcardAsReturnType +* Modify Rule: ExplicitInitialization only applies to objects * Add Wercker CI * Add Shippable CI diff --git a/README.md b/README.md index ac39463..5e53626 100644 --- a/README.md +++ b/README.md @@ -903,13 +903,15 @@ Checks that when a class overrides the `equals()` method, that it also overrides Limits the number of executable statements in a method to 30. #### [ExplicitInitialization](http://checkstyle.sourceforge.net/config_coding.html#ExplicitInitialization) -Checks that fields are not being explicitly initialised to their already default value. +Checks that object fields are not being explicitly initialised to their already default value. + +Does not check primitive field types. Valid: ```` class Valid { - private int foo; + private int foo = 0; private Object bar; } @@ -919,7 +921,7 @@ Invalid: ```` class Invalid { - private int foo = 0; + private Integer foo = 0; private Object bar = null; } diff --git a/builder/src/main/resources/application.yml b/builder/src/main/resources/application.yml index 3b60a5d..ec5e0d0 100644 --- a/builder/src/main/resources/application.yml +++ b/builder/src/main/resources/application.yml @@ -275,6 +275,8 @@ rules: enabled: true source: CHECKSTYLE uri: http://checkstyle.sourceforge.net/config_coding.html#ExplicitInitialization + properties: + onlyObjectReferences: true - name: FallThrough parent: TREEWALKER diff --git a/builder/src/main/resources/rules/ExplicitInitialization.md b/builder/src/main/resources/rules/ExplicitInitialization.md index 62b851c..507d64b 100644 --- a/builder/src/main/resources/rules/ExplicitInitialization.md +++ b/builder/src/main/resources/rules/ExplicitInitialization.md @@ -1,11 +1,13 @@ -Checks that fields are not being explicitly initialised to their already default value. +Checks that object fields are not being explicitly initialised to their already default value. + +Does not check primitive field types. Valid: ```` class Valid { - private int foo; + private int foo = 0; private Object bar; } @@ -15,7 +17,7 @@ Invalid: ```` class Invalid { - private int foo = 0; + private Integer foo = 0; private Object bar = null; } diff --git a/regressions/src/main/java/net/kemitix/checkstyle/regressions/ExplicitInitialization.java b/regressions/src/main/java/net/kemitix/checkstyle/regressions/ExplicitInitialization.java index 322b589..d2987c1 100644 --- a/regressions/src/main/java/net/kemitix/checkstyle/regressions/ExplicitInitialization.java +++ b/regressions/src/main/java/net/kemitix/checkstyle/regressions/ExplicitInitialization.java @@ -29,16 +29,8 @@ package net.kemitix.checkstyle.regressions; @SuppressWarnings("hideutilityclassconstructor") class ExplicitInitialization { - /** - * This will become valid in next release. - */ - @SuppressWarnings("explicitinitialization") private boolean validBoolean = false; - /** - * This will become valid in next release. - */ - @SuppressWarnings("explicitinitialization") private int validInt = 0; private String validString = ""; diff --git a/ruleset/src/main/resources/net/kemitix/checkstyle-4-tweaks.xml b/ruleset/src/main/resources/net/kemitix/checkstyle-4-tweaks.xml index 4a5e460..08ac646 100644 --- a/ruleset/src/main/resources/net/kemitix/checkstyle-4-tweaks.xml +++ b/ruleset/src/main/resources/net/kemitix/checkstyle-4-tweaks.xml @@ -50,7 +50,9 @@ - + + + diff --git a/ruleset/src/main/resources/net/kemitix/checkstyle-5-complexity.xml b/ruleset/src/main/resources/net/kemitix/checkstyle-5-complexity.xml index 7181911..95ead8f 100644 --- a/ruleset/src/main/resources/net/kemitix/checkstyle-5-complexity.xml +++ b/ruleset/src/main/resources/net/kemitix/checkstyle-5-complexity.xml @@ -69,7 +69,9 @@ - + + + From 6b2c5f6e77c36ed3cc5f27040bb77fa552dfb9c6 Mon Sep 17 00:00:00 2001 From: Paul Campbell Date: Tue, 30 May 2017 15:01:28 +0100 Subject: [PATCH 39/39] travis-ci: deploy even when from a pull request --- travis-ci/travis-deploy.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/travis-ci/travis-deploy.sh b/travis-ci/travis-deploy.sh index 6ff7008..5e59a85 100755 --- a/travis-ci/travis-deploy.sh +++ b/travis-ci/travis-deploy.sh @@ -1,6 +1,6 @@ #!/usr/bin/env bash -if [ "$TRAVIS_BRANCH" = 'master' ] && [ "$TRAVIS_PULL_REQUEST" == 'false' ]; then +if [ "$TRAVIS_BRANCH" = 'master' ]; then echo "Preparing to deploy to nexus..." openssl aes-256-cbc -K $encrypted_efec3258f55d_key -iv $encrypted_efec3258f55d_iv \ -in travis-ci/codesigning.asc.enc -out travis-ci/codesigning.asc -d