commit
65500d58d8
15 changed files with 127 additions and 64 deletions
|
@ -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
|
||||
-----
|
||||
|
||||
|
|
|
@ -31,7 +31,7 @@ The simplest way to use the ruleset is with the maven-tile:
|
|||
<extensions>true</extensions>
|
||||
<configuration>
|
||||
<tiles>
|
||||
<tile>net.kemitix.checkstyle:tile:4.0.0</tile>
|
||||
<tile>net.kemitix.checkstyle:tile:4.0.1</tile>
|
||||
</tiles>
|
||||
</configuration>
|
||||
</plugin>
|
||||
|
|
|
@ -14,17 +14,17 @@
|
|||
<groupId>net.kemitix.checkstyle</groupId>
|
||||
<artifactId>builder</artifactId>
|
||||
<packaging>jar</packaging>
|
||||
<version>4.0.0</version>
|
||||
<version>4.0.1</version>
|
||||
|
||||
<properties>
|
||||
<maven.install.skip>true</maven.install.skip>
|
||||
<java.version>1.8</java.version>
|
||||
<tiles-maven-plugin.version>2.10</tiles-maven-plugin.version>
|
||||
<kemitix-tiles.version>0.2.0</kemitix-tiles.version>
|
||||
<kemitix-tiles.version>0.3.0</kemitix-tiles.version>
|
||||
|
||||
<checkstyle.version>8.6</checkstyle.version>
|
||||
<sevntu.version>1.26.0</sevntu.version>
|
||||
<lombok.version>1.16.18</lombok.version>
|
||||
<lombok.version>1.16.20</lombok.version>
|
||||
<spring-platform.version>Brussels-SR6</spring-platform.version>
|
||||
<spring-boot.version>1.5.9.RELEASE</spring-boot.version>
|
||||
<mapstream.version>2.3.5</mapstream.version>
|
||||
|
@ -36,6 +36,7 @@
|
|||
<kemitix.checkstyle.ruleset.version>${project.version}</kemitix.checkstyle.ruleset.version>
|
||||
<kemitix.checkstyle.ruleset.level>5-complexity</kemitix.checkstyle.ruleset.level>
|
||||
<kemitix.checkstyle.ruleset.location>net/kemitix/checkstyle-${kemitix.checkstyle.ruleset.level}.xml</kemitix.checkstyle.ruleset.location>
|
||||
<javax.annotation-api.version>1.2</javax.annotation-api.version>
|
||||
</properties>
|
||||
|
||||
<dependencyManagement>
|
||||
|
@ -55,6 +56,7 @@
|
|||
<groupId>org.projectlombok</groupId>
|
||||
<artifactId>lombok</artifactId>
|
||||
<version>${lombok.version}</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.mockito</groupId>
|
||||
|
@ -76,6 +78,11 @@
|
|||
</exclusion>
|
||||
</exclusions>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>javax.annotation</groupId>
|
||||
<artifactId>javax.annotation-api</artifactId>
|
||||
<version>${javax.annotation-api.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-log4j2</artifactId>
|
||||
|
|
|
@ -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<RuleSource, List<String>> checkClasses(final PackageScanner packageScanner) {
|
||||
return Stream.of(RuleSource.values())
|
||||
.map(toRuleSourceEntry(packageScanner))
|
||||
.collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue));
|
||||
}
|
||||
|
||||
private static Function<RuleSource, AbstractMap.SimpleEntry<RuleSource, List<String>>> toRuleSourceEntry(
|
||||
final PackageScanner packageScanner
|
||||
) {
|
||||
return source -> new AbstractMap.SimpleEntry<>(
|
||||
source,
|
||||
classesInSource(source, packageScanner)
|
||||
);
|
||||
}
|
||||
|
||||
private static List<String> classesInSource(
|
||||
final RuleSource source,
|
||||
final PackageScanner packageScanner
|
||||
) {
|
||||
return packageScanner.apply(source)
|
||||
.collect(Collectors.toList());
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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<RuleSource, List<String>> 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<RuleSource, List<String>> 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");
|
||||
}
|
||||
|
|
|
@ -31,7 +31,7 @@ The simplest way to use the ruleset is with the maven-tile:
|
|||
<extensions>true</extensions>
|
||||
<configuration>
|
||||
<tiles>
|
||||
<tile>net.kemitix.checkstyle:tile:4.0.0</tile>
|
||||
<tile>net.kemitix.checkstyle:tile:4.0.1</tile>
|
||||
</tiles>
|
||||
</configuration>
|
||||
</plugin>
|
||||
|
|
|
@ -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<RuleSource, List<String>> 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));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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 {
|
||||
|
|
|
@ -1,16 +1,14 @@
|
|||
package net.kemitix.checkstyle.ruleset.builder;
|
||||
|
||||
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;
|
||||
import static org.assertj.core.api.Assertions.assertThatThrownBy;
|
||||
import static org.mockito.BDDMockito.given;
|
||||
import static org.mockito.Mockito.mock;
|
||||
|
||||
/**
|
||||
* Tests for {@link DefaultRuleClassLocator}.
|
||||
|
@ -19,14 +17,9 @@ import static org.mockito.Mockito.mock;
|
|||
*/
|
||||
public class DefaultRuleClassLocatorTest {
|
||||
|
||||
private DefaultRuleClassLocator subject;
|
||||
private final Map<RuleSource, List<String>> 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 +28,8 @@ public class DefaultRuleClassLocatorTest {
|
|||
final String expected = "com.puppycrawl.tools.checkstyle.checks.regexp.RegexpOnFilenameCheck";
|
||||
final List<String> checkstyleClasses = Collections.singletonList(expected);
|
||||
final List<String> 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 +44,8 @@ public class DefaultRuleClassLocatorTest {
|
|||
final String expected = "com.puppycrawl.tools.checkstyle.checks.regexp.RegexpOnFilename";
|
||||
final List<String> checkstyleClasses = Collections.singletonList(expected);
|
||||
final List<String> 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 +60,8 @@ public class DefaultRuleClassLocatorTest {
|
|||
final String expected = "com.puppycrawl.tools.checkstyle.checks.regexp.RegexpOnFilenameNoMatch";
|
||||
final List<String> checkstyleClasses = Collections.singletonList(expected);
|
||||
final List<String> 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 +69,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);
|
||||
|
|
2
pom.xml
2
pom.xml
|
@ -6,7 +6,7 @@
|
|||
|
||||
<groupId>net.kemitix.checkstyle</groupId>
|
||||
<artifactId>root</artifactId>
|
||||
<version>4.0.0</version>
|
||||
<version>4.0.1</version>
|
||||
<packaging>pom</packaging>
|
||||
|
||||
<properties>
|
||||
|
|
|
@ -12,7 +12,7 @@
|
|||
|
||||
<groupId>net.kemitix.checkstyle</groupId>
|
||||
<artifactId>regressions</artifactId>
|
||||
<version>4.0.0</version>
|
||||
<version>4.0.1</version>
|
||||
|
||||
<properties>
|
||||
<maven.install.skip>true</maven.install.skip>
|
||||
|
|
|
@ -13,7 +13,7 @@
|
|||
|
||||
<groupId>net.kemitix.checkstyle</groupId>
|
||||
<artifactId>ruleset</artifactId>
|
||||
<version>4.0.0</version>
|
||||
<version>4.0.1</version>
|
||||
<packaging>jar</packaging>
|
||||
|
||||
<name>Kemitix Checkstyle Ruleset</name>
|
||||
|
|
15
set-version.sh
Normal file
15
set-version.sh
Normal file
|
@ -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</,$NEXT</," builder/pom.xml builder/src/main/resources/README-template.md regressions/pom.xml ruleset/pom.xml tile/pom.xml tile/tile.xml
|
|
@ -12,7 +12,7 @@
|
|||
|
||||
<groupId>net.kemitix.checkstyle</groupId>
|
||||
<artifactId>tile</artifactId>
|
||||
<version>4.0.0</version>
|
||||
<version>4.0.1</version>
|
||||
|
||||
<packaging>tile</packaging>
|
||||
|
||||
|
|
|
@ -3,7 +3,7 @@
|
|||
<maven-checkstyle-plugin.version>3.0.0</maven-checkstyle-plugin.version>
|
||||
<checkstyle.version>8.6</checkstyle.version>
|
||||
<sevntu.version>1.26.0</sevntu.version>
|
||||
<kemitix.checkstyle.ruleset.version>4.0.0</kemitix.checkstyle.ruleset.version>
|
||||
<kemitix.checkstyle.ruleset.version>4.0.1</kemitix.checkstyle.ruleset.version>
|
||||
<kemitix.checkstyle.ruleset.level>5-complexity</kemitix.checkstyle.ruleset.level>
|
||||
<kemitix.checkstyle.ruleset.location>net/kemitix/checkstyle-${kemitix.checkstyle.ruleset.level}.xml</kemitix.checkstyle.ruleset.location>
|
||||
</properties>
|
||||
|
@ -32,6 +32,9 @@
|
|||
</dependencies>
|
||||
<configuration>
|
||||
<configLocation>${kemitix.checkstyle.ruleset.location}</configLocation>
|
||||
<sourceDirectories>
|
||||
<sourceDirectory>${build.sourceDirectory}</sourceDirectory>
|
||||
</sourceDirectories>
|
||||
</configuration>
|
||||
<executions>
|
||||
<execution>
|
||||
|
|
Loading…
Reference in a new issue