From 744a4d8f94a9a0ce1003ab9800a4008d7daa595d Mon Sep 17 00:00:00 2001 From: Paul Campbell Date: Sat, 20 Jan 2018 22:21:15 +0000 Subject: [PATCH 01/13] Add sourceDirectories to avoid scanning generated sources --- tile/tile.xml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/tile/tile.xml b/tile/tile.xml index f87d3e6..5896d0f 100644 --- a/tile/tile.xml +++ b/tile/tile.xml @@ -32,6 +32,9 @@ ${kemitix.checkstyle.ruleset.location} + + ${build.sourceDirectory} + From 62c81bd0b38ee511c9fe593b664996f2cbbafbe3 Mon Sep 17 00:00:00 2001 From: Paul Campbell Date: Sat, 20 Jan 2018 22:27:25 +0000 Subject: [PATCH 02/13] version set to 4.0.1 --- builder/pom.xml | 2 +- builder/src/main/resources/README-template.md | 2 +- pom.xml | 2 +- regressions/pom.xml | 2 +- ruleset/pom.xml | 2 +- tile/pom.xml | 2 +- tile/tile.xml | 2 +- 7 files changed, 7 insertions(+), 7 deletions(-) diff --git a/builder/pom.xml b/builder/pom.xml index a085803..e9ab8d5 100644 --- a/builder/pom.xml +++ b/builder/pom.xml @@ -14,7 +14,7 @@ net.kemitix.checkstyle builder jar - 4.0.0 + 4.0.1 true diff --git a/builder/src/main/resources/README-template.md b/builder/src/main/resources/README-template.md index 98c3585..5aabff6 100644 --- a/builder/src/main/resources/README-template.md +++ b/builder/src/main/resources/README-template.md @@ -31,7 +31,7 @@ The simplest way to use the ruleset is with the maven-tile: true - net.kemitix.checkstyle:tile:4.0.0 + net.kemitix.checkstyle:tile:4.0.1 diff --git a/pom.xml b/pom.xml index ea633af..4ed6fd9 100644 --- a/pom.xml +++ b/pom.xml @@ -6,7 +6,7 @@ net.kemitix.checkstyle root - 4.0.0 + 4.0.1 pom diff --git a/regressions/pom.xml b/regressions/pom.xml index 059099b..594633e 100644 --- a/regressions/pom.xml +++ b/regressions/pom.xml @@ -12,7 +12,7 @@ net.kemitix.checkstyle regressions - 4.0.0 + 4.0.1 true diff --git a/ruleset/pom.xml b/ruleset/pom.xml index f445b7f..5124525 100644 --- a/ruleset/pom.xml +++ b/ruleset/pom.xml @@ -13,7 +13,7 @@ net.kemitix.checkstyle ruleset - 4.0.0 + 4.0.1 jar Kemitix Checkstyle Ruleset diff --git a/tile/pom.xml b/tile/pom.xml index 016fe39..1b04434 100644 --- a/tile/pom.xml +++ b/tile/pom.xml @@ -12,7 +12,7 @@ net.kemitix.checkstyle tile - 4.0.0 + 4.0.1 tile diff --git a/tile/tile.xml b/tile/tile.xml index 5896d0f..b347e8d 100644 --- a/tile/tile.xml +++ b/tile/tile.xml @@ -3,7 +3,7 @@ 3.0.0 8.6 1.26.0 - 4.0.0 + 4.0.1 5-complexity net/kemitix/checkstyle-${kemitix.checkstyle.ruleset.level}.xml From c5d6af4ffa1bdcb128b7715a232d4e4c19bb1cb0 Mon Sep 17 00:00:00 2001 From: Paul Campbell Date: Wed, 24 Jan 2018 07:04:15 +0000 Subject: [PATCH 03/13] Upgrade lombok to 1.16.20 --- builder/pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/builder/pom.xml b/builder/pom.xml index e9ab8d5..0c6766a 100644 --- a/builder/pom.xml +++ b/builder/pom.xml @@ -24,7 +24,7 @@ 8.6 1.26.0 - 1.16.18 + 1.16.20 Brussels-SR6 1.5.9.RELEASE 2.3.5 From 1529472940eb9f40a1ef88f2e76ddade9b333898 Mon Sep 17 00:00:00 2001 From: Paul Campbell Date: Wed, 24 Jan 2018 07:04:45 +0000 Subject: [PATCH 04/13] Add javax.annotation-api for jdk 9 compatibility --- builder/pom.xml | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/builder/pom.xml b/builder/pom.xml index 0c6766a..1d3fc39 100644 --- a/builder/pom.xml +++ b/builder/pom.xml @@ -36,6 +36,7 @@ ${project.version} 5-complexity net/kemitix/checkstyle-${kemitix.checkstyle.ruleset.level}.xml + 1.2 @@ -76,6 +77,11 @@ + + javax.annotation + javax.annotation-api + ${javax.annotation-api.version} + org.springframework.boot spring-boot-starter-log4j2 From 998399739111ea343a4044e4878370a76b5cb0bb Mon Sep 17 00:00:00 2001 From: Paul Campbell Date: Wed, 24 Jan 2018 07:06:56 +0000 Subject: [PATCH 05/13] Upgrade kemitix-maven-tiles to 0.3.0 --- builder/pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/builder/pom.xml b/builder/pom.xml index 1d3fc39..be01d9f 100644 --- a/builder/pom.xml +++ b/builder/pom.xml @@ -20,7 +20,7 @@ true 1.8 2.10 - 0.2.0 + 0.3.0 8.6 1.26.0 From 3c83b78cea97ce3ed0d483b0d99a8ceab7e59735 Mon Sep 17 00:00:00 2001 From: Paul Campbell Date: Wed, 24 Jan 2018 21:47:17 +0000 Subject: [PATCH 06/13] Test should be using interface --- .../checkstyle/ruleset/builder/DefaultPackageScannerTest.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 e0540f2..240d12c 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,7 +16,7 @@ import static org.assertj.core.api.Assertions.assertThat; */ public class DefaultPackageScannerTest { - private DefaultPackageScanner scanner; + private PackageScanner scanner; @Before public void setUp() throws Exception { From 5e62e745937eeffb210af2b367b8a1a10493b7c9 Mon Sep 17 00:00:00 2001 From: Paul Campbell Date: Wed, 24 Jan 2018 21:55:14 +0000 Subject: [PATCH 07/13] Lombok should be provided --- builder/pom.xml | 1 + 1 file changed, 1 insertion(+) diff --git a/builder/pom.xml b/builder/pom.xml index be01d9f..3015348 100644 --- a/builder/pom.xml +++ b/builder/pom.xml @@ -56,6 +56,7 @@ org.projectlombok lombok ${lombok.version} + provided org.mockito From 9be6ca763aab7448208d5de37dd44231ff032204 Mon Sep 17 00:00:00 2001 From: Paul Campbell Date: Wed, 24 Jan 2018 21:55:27 +0000 Subject: [PATCH 08/13] Update README tile version --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 6e420fa..99c48f1 100644 --- a/README.md +++ b/README.md @@ -31,7 +31,7 @@ The simplest way to use the ruleset is with the maven-tile: true - net.kemitix.checkstyle:tile:4.0.0 + net.kemitix.checkstyle:tile:4.0.1 From d3f86fc3186e879a6328bd7d75a3cab13c013d32 Mon Sep 17 00:00:00 2001 From: Paul Campbell Date: Wed, 24 Jan 2018 21:55:52 +0000 Subject: [PATCH 09/13] Remove use of @PostContruct --- .../ruleset/builder/BuilderConfiguration.java | 37 +++++++++++++++++ .../builder/DefaultRuleClassLocator.java | 40 +++++++------------ .../builder/DefaultRuleClassLocatorTest.java | 33 +++++---------- 3 files changed, 61 insertions(+), 49 deletions(-) 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 index 197c38c..626c729 100644 --- a/builder/src/main/java/net/kemitix/checkstyle/ruleset/builder/BuilderConfiguration.java +++ b/builder/src/main/java/net/kemitix/checkstyle/ruleset/builder/BuilderConfiguration.java @@ -26,6 +26,12 @@ import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import java.io.IOException; +import java.util.AbstractMap; +import java.util.List; +import java.util.Map; +import java.util.function.Function; +import java.util.stream.Collectors; +import java.util.stream.Stream; /** * Configuration for Builder. @@ -46,4 +52,35 @@ public class BuilderConfiguration { public ClassPath classPath() throws IOException { return ClassPath.from(getClass().getClassLoader()); } + + /** + * A Map of rules for each RuleSource. + * + * @param packageScanner the PackageScanner + * + * @return a Map with a list of check classes for each rule source + */ + @Bean + public Map> checkClasses(final PackageScanner packageScanner) { + return Stream.of(RuleSource.values()) + .map(toRuleSourceEntry(packageScanner)) + .collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue)); + } + + private static Function>> toRuleSourceEntry( + final PackageScanner packageScanner + ) { + return source -> new AbstractMap.SimpleEntry<>( + source, + classesInSource(source, packageScanner) + ); + } + + private static List classesInSource( + final RuleSource source, + final PackageScanner packageScanner + ) { + return packageScanner.apply(source) + .collect(Collectors.toList()); + } } 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 index 0df04a6..873de34 100644 --- a/builder/src/main/java/net/kemitix/checkstyle/ruleset/builder/DefaultRuleClassLocator.java +++ b/builder/src/main/java/net/kemitix/checkstyle/ruleset/builder/DefaultRuleClassLocator.java @@ -24,13 +24,9 @@ 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.Objects; -import java.util.stream.Collectors; -import java.util.stream.Stream; /** * Default implementation of {@link RuleClassLocator}. @@ -41,38 +37,30 @@ import java.util.stream.Stream; @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)); - } + private final Map> checkClasses; @Override public final String apply(final Rule rule) { return getCanonicalClassName(rule.getSource(), rule.getName()); } - private String getCanonicalClassName(final RuleSource source, final String name) { + private String getCanonicalClassName( + final RuleSource source, + final String name + ) { Objects.requireNonNull(checkClasses, "init() method not called"); return checkClasses.get(source) - .stream() - .sorted() - .filter(classname -> byRuleName(classname, name)) - .findFirst() - .orElseThrow(() -> new CheckstyleClassNotFoundException(name)); + .stream() + .sorted() + .filter(classname -> byRuleName(classname, name)) + .findFirst() + .orElseThrow(() -> new CheckstyleClassNotFoundException(name)); } - private boolean byRuleName(final String classname, final String 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/test/java/net/kemitix/checkstyle/ruleset/builder/DefaultRuleClassLocatorTest.java b/builder/src/test/java/net/kemitix/checkstyle/ruleset/builder/DefaultRuleClassLocatorTest.java index a342ae6..764dd32 100644 --- a/builder/src/test/java/net/kemitix/checkstyle/ruleset/builder/DefaultRuleClassLocatorTest.java +++ b/builder/src/test/java/net/kemitix/checkstyle/ruleset/builder/DefaultRuleClassLocatorTest.java @@ -4,7 +4,9 @@ import org.junit.Before; import org.junit.Test; import java.util.Collections; +import java.util.HashMap; import java.util.List; +import java.util.Map; import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.assertThatNullPointerException; @@ -19,14 +21,9 @@ import static org.mockito.Mockito.mock; */ public class DefaultRuleClassLocatorTest { - private DefaultRuleClassLocator subject; + private final Map> checkClasses = new HashMap<>(); - private PackageScanner packageScanner = mock(PackageScanner.class); - - @Before - public void setUp() { - subject = new DefaultRuleClassLocator(packageScanner); - } + private final DefaultRuleClassLocator subject = new DefaultRuleClassLocator(checkClasses); @Test public void canLookupRuleWithClassNameEndingInCheck() { @@ -35,9 +32,8 @@ public class DefaultRuleClassLocatorTest { 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(); + checkClasses.put(RuleSource.CHECKSTYLE, checkstyleClasses); + checkClasses.put(RuleSource.SEVNTU, sevntuClasses); final Rule rule = createCheckstyleRule(rulename); //when final String result = subject.apply(rule); @@ -52,9 +48,8 @@ public class DefaultRuleClassLocatorTest { final String expected = "com.puppycrawl.tools.checkstyle.checks.regexp.RegexpOnFilename"; 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(); + checkClasses.put(RuleSource.CHECKSTYLE, checkstyleClasses); + checkClasses.put(RuleSource.SEVNTU, sevntuClasses); final Rule rule = createCheckstyleRule(rulename); //when final String result = subject.apply(rule); @@ -69,9 +64,8 @@ public class DefaultRuleClassLocatorTest { final String expected = "com.puppycrawl.tools.checkstyle.checks.regexp.RegexpOnFilenameNoMatch"; 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(); + checkClasses.put(RuleSource.CHECKSTYLE, checkstyleClasses); + checkClasses.put(RuleSource.SEVNTU, sevntuClasses); final Rule rule = createCheckstyleRule(rulename); //then assertThatThrownBy(() -> subject.apply(rule)) @@ -79,13 +73,6 @@ public class DefaultRuleClassLocatorTest { .hasMessage("No class found to implement RegexpOnFilename"); } - @Test - public void throwsNullPointerExceptionWhenInitNotCalled() { - assertThatNullPointerException() - .isThrownBy(() -> subject.apply(new Rule())) - .withMessage("init() method not called"); - } - private Rule createCheckstyleRule(final String rulename) { final Rule rule = new Rule(); rule.setSource(RuleSource.CHECKSTYLE); From a79cfc1f1f13a2314d009c7f9062d79d6347f0d8 Mon Sep 17 00:00:00 2001 From: Paul Campbell Date: Wed, 24 Jan 2018 21:56:07 +0000 Subject: [PATCH 10/13] Add set-version.sh --- set-version.sh | 15 +++++++++++++++ 1 file changed, 15 insertions(+) create mode 100644 set-version.sh diff --git a/set-version.sh b/set-version.sh new file mode 100644 index 0000000..717be2e --- /dev/null +++ b/set-version.sh @@ -0,0 +1,15 @@ +#!/usr/bin/env bash + +if test $# != 2 +then + echo "current and next version missing" + exit +fi + +CURRENT=$1 +NEXT=$2 + +echo Updating version from $CURRENT to $NEXT + +./mvnw versions:set -DnewVersion=$NEXT +perl -p -i -e "s,$CURRENT Date: Wed, 24 Jan 2018 22:01:31 +0000 Subject: [PATCH 11/13] Update CHANGELOG --- CHANGELOG | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/CHANGELOG b/CHANGELOG index ce62d42..4a2e86b 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -1,6 +1,13 @@ CHANGELOG ========= +4.0.1 +----- + +* Add sourceDirectories to avoid scanning generated sources +* Upgrade lombok to 1.16.20 +* Upgrade kemitix-maven-tiles to 0.3.0 + 4.0.0 ----- From fd63f94a278b2bfc7b1dea565bcfad70a25fc777 Mon Sep 17 00:00:00 2001 From: Paul Campbell Date: Thu, 25 Jan 2018 06:55:18 +0000 Subject: [PATCH 12/13] Add test for checkClasses bean --- .../builder/BuilderConfigurationTest.java | 23 +++++++++++++++++++ 1 file changed, 23 insertions(+) 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 index 294cb87..9279196 100644 --- a/builder/src/test/java/net/kemitix/checkstyle/ruleset/builder/BuilderConfigurationTest.java +++ b/builder/src/test/java/net/kemitix/checkstyle/ruleset/builder/BuilderConfigurationTest.java @@ -4,8 +4,14 @@ import com.google.common.reflect.ClassPath; import org.junit.Test; import java.io.IOException; +import java.util.Collections; +import java.util.List; +import java.util.Map; +import java.util.stream.Stream; import static org.assertj.core.api.Assertions.assertThat; +import static org.mockito.BDDMockito.given; +import static org.mockito.Mockito.mock; /** * Tests for {@link BuilderConfiguration}. @@ -21,4 +27,21 @@ public class BuilderConfigurationTest { //then assertThat(classPath).isNotNull(); } + + @Test + public void canGetCheckClasses() { + //given + final PackageScanner packageScanner = mock(PackageScanner.class); + final String checkstyleClass = "checkstyle class"; + given(packageScanner.apply(RuleSource.CHECKSTYLE)).willReturn(Stream.of(checkstyleClass)); + final String sevntuClass = "sevntu class"; + given(packageScanner.apply(RuleSource.SEVNTU)).willReturn(Stream.of(sevntuClass)); + //when + final Map> checkClasses = new BuilderConfiguration().checkClasses(packageScanner); + //then + assertThat(checkClasses).containsOnlyKeys(RuleSource.values()); + assertThat(checkClasses) + .containsEntry(RuleSource.CHECKSTYLE, Collections.singletonList(checkstyleClass)) + .containsEntry(RuleSource.SEVNTU, Collections.singletonList(sevntuClass)); + } } From ede3db53bf557ad5fae8fb2016f3e71a0bc390be Mon Sep 17 00:00:00 2001 From: Paul Campbell Date: Thu, 25 Jan 2018 06:59:09 +0000 Subject: [PATCH 13/13] Remove unused imports --- .../ruleset/builder/DefaultRuleClassLocatorTest.java | 4 ---- 1 file changed, 4 deletions(-) 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 index 764dd32..3e9dd11 100644 --- a/builder/src/test/java/net/kemitix/checkstyle/ruleset/builder/DefaultRuleClassLocatorTest.java +++ b/builder/src/test/java/net/kemitix/checkstyle/ruleset/builder/DefaultRuleClassLocatorTest.java @@ -1,6 +1,5 @@ package net.kemitix.checkstyle.ruleset.builder; -import org.junit.Before; import org.junit.Test; import java.util.Collections; @@ -9,10 +8,7 @@ import java.util.List; import java.util.Map; import static org.assertj.core.api.Assertions.assertThat; -import static org.assertj.core.api.Assertions.assertThatNullPointerException; import static org.assertj.core.api.Assertions.assertThatThrownBy; -import static org.mockito.BDDMockito.given; -import static org.mockito.Mockito.mock; /** * Tests for {@link DefaultRuleClassLocator}.