Bump version-tracker from 3.1.0 to 3.1.1 (#425)
* Bump version-tracker from 3.1.0 to 3.1.1 Bumps version-tracker from 3.1.0 to 3.1.1. --- updated-dependencies: - dependency-name: net.kemitix.tiles:version-tracker dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] <support@github.com> * Fixes for spotbugs Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> Co-authored-by: Paul Campbell <pcampbell@kemitix.net>
This commit is contained in:
parent
c2e3234dd4
commit
b0663c2164
14 changed files with 118 additions and 60 deletions
|
@ -22,7 +22,7 @@
|
|||
<maven.compiler.source>${java.version}</maven.compiler.source>
|
||||
<maven.compiler.target>${java.version}</maven.compiler.target>
|
||||
<tiles-maven-plugin.version>2.23</tiles-maven-plugin.version>
|
||||
<kemitix-maven-tiles.version>3.1.0</kemitix-maven-tiles.version>
|
||||
<kemitix-maven-tiles.version>3.1.1</kemitix-maven-tiles.version>
|
||||
|
||||
<checkstyle.version>8.44</checkstyle.version>
|
||||
<sevntu.version>1.40.0</sevntu.version>
|
||||
|
|
|
@ -1,6 +1,5 @@
|
|||
package net.kemitix.checkstyle.ruleset.builder;
|
||||
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import net.kemitix.files.FileReaderWriter;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
|
@ -16,10 +15,19 @@ import java.util.stream.Collectors;
|
|||
* @author Paul Campbell (pcampbell@kemitix.net).
|
||||
*/
|
||||
@Configuration
|
||||
@RequiredArgsConstructor
|
||||
public class BuilderConfiguration {
|
||||
|
||||
private final SourcesProperties sourcesProperties;
|
||||
private final transient SourcesProperties sourcesProperties =
|
||||
new SourcesProperties();
|
||||
|
||||
/**
|
||||
* Creates a new instance of the class.
|
||||
*
|
||||
* @param sourcesProperties the source properties
|
||||
*/
|
||||
public BuilderConfiguration(final SourcesProperties sourcesProperties) {
|
||||
this.sourcesProperties.setSources(sourcesProperties.getSources());
|
||||
}
|
||||
|
||||
/**
|
||||
* A Map of rules for each RuleSource.
|
||||
|
|
|
@ -1,8 +1,8 @@
|
|||
package net.kemitix.checkstyle.ruleset.builder;
|
||||
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
import java.util.Map;
|
||||
|
@ -14,11 +14,24 @@ import java.util.Objects;
|
|||
* @author Paul Campbell (pcampbell@kemitix.net).
|
||||
*/
|
||||
@Service
|
||||
@RequiredArgsConstructor
|
||||
public class DefaultRuleClassLocator implements RuleClassLocator {
|
||||
|
||||
private final Map<RuleSource, List<String>> checkClasses;
|
||||
private final SourcesProperties sourcesProperties;
|
||||
private final transient Map<RuleSource, List<String>> checkClasses;
|
||||
private final transient SourcesProperties sourcesProperties = new SourcesProperties();
|
||||
|
||||
/**
|
||||
* Creates a new instance of the class.
|
||||
*
|
||||
* @param checkClasses The list of check classes grouped by their source
|
||||
* @param sourcesProperties the source properties
|
||||
*/
|
||||
public DefaultRuleClassLocator(
|
||||
final Map<RuleSource, List<String>> checkClasses,
|
||||
final SourcesProperties sourcesProperties
|
||||
) {
|
||||
this.checkClasses = new HashMap<>(checkClasses);
|
||||
this.sourcesProperties.setSources(sourcesProperties.getSources());
|
||||
}
|
||||
|
||||
@Override
|
||||
public final String apply(final Rule rule) {
|
||||
|
|
|
@ -4,7 +4,6 @@ import com.speedment.common.mapstream.MapStream;
|
|||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
|
||||
import java.net.URI;
|
||||
import java.util.Comparator;
|
||||
import java.util.HashMap;
|
||||
import java.util.Locale;
|
||||
|
@ -18,8 +17,8 @@ import java.util.stream.Collectors;
|
|||
* @author Paul Campbell (pcampbell@kemitix.net)
|
||||
*/
|
||||
@Setter
|
||||
@Getter
|
||||
public class Rule {
|
||||
@SuppressWarnings("methodcount")
|
||||
public final class Rule {
|
||||
|
||||
private static final Locale LOCALE = Locale.ENGLISH;
|
||||
|
||||
|
@ -31,11 +30,12 @@ public class Rule {
|
|||
* Configuration properties.
|
||||
*/
|
||||
@SuppressWarnings("PMD.UseConcurrentHashMap")
|
||||
private final Map<String, String> properties = new HashMap<>();
|
||||
private Map<String, String> properties = new HashMap<>();
|
||||
|
||||
/**
|
||||
* The name of the rule's Check class.
|
||||
*/
|
||||
@Getter
|
||||
private String name;
|
||||
|
||||
/**
|
||||
|
@ -46,11 +46,13 @@ public class Rule {
|
|||
/**
|
||||
* The first level the rule is enabled on.
|
||||
*/
|
||||
@Getter
|
||||
private RuleLevel level;
|
||||
|
||||
/**
|
||||
* Whether the rule is enabled.
|
||||
*/
|
||||
@Getter
|
||||
private boolean enabled;
|
||||
|
||||
/**
|
||||
|
@ -61,18 +63,29 @@ public class Rule {
|
|||
/**
|
||||
* URI for full official documentation.
|
||||
*/
|
||||
private URI uri;
|
||||
@Getter
|
||||
private String uri;
|
||||
|
||||
/**
|
||||
* Flag to indicate rules that can not be suppressed (via {@code @SuppressWarnings}.
|
||||
*/
|
||||
@Getter
|
||||
private boolean insuppressible;
|
||||
|
||||
/**
|
||||
* The reason a rule has been disabled.
|
||||
*/
|
||||
@Getter
|
||||
private String reason;
|
||||
|
||||
public void setProperties(final Map<String, String> properties) {
|
||||
this.properties = new HashMap<>(properties);
|
||||
}
|
||||
|
||||
public Map<String, String> getProperties() {
|
||||
return new HashMap<>(properties);
|
||||
}
|
||||
|
||||
/**
|
||||
* Compare two Rules lexicographically for sorting by rule name, ignoring case.
|
||||
*
|
||||
|
@ -83,9 +96,9 @@ public class Rule {
|
|||
* the right string; and a value greater than 0 if the left string is lexicographically greater than the right
|
||||
* string.
|
||||
*/
|
||||
protected static int sortByName(final Rule left, final Rule right) {
|
||||
return left.getName().toLowerCase(LOCALE)
|
||||
.compareTo(right.getName().toLowerCase(LOCALE));
|
||||
public static int sortByName(final Rule left, final Rule right) {
|
||||
return left.name.toLowerCase(LOCALE)
|
||||
.compareTo(right.name.toLowerCase(LOCALE));
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -96,7 +109,7 @@ public class Rule {
|
|||
* @return a Predicate to check a Rule
|
||||
*/
|
||||
static Predicate<Rule> hasParent(final RuleParent ruleParent) {
|
||||
return rule -> ruleParent == rule.getParent();
|
||||
return rule -> ruleParent == rule.parent;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -107,7 +120,7 @@ public class Rule {
|
|||
* @return a Predicate to check a Rule
|
||||
*/
|
||||
static Predicate<Rule> isIncludedInLevel(final RuleLevel ruleLevel) {
|
||||
return rule -> ruleLevel.compareTo(rule.getLevel()) >= 0;
|
||||
return rule -> ruleLevel.compareTo(rule.level) >= 0;
|
||||
}
|
||||
|
||||
private static String formatProperties(final Map<String, String> properties) {
|
||||
|
|
|
@ -1,20 +1,36 @@
|
|||
package net.kemitix.checkstyle.ruleset.builder;
|
||||
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.util.function.Predicate;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
@Component
|
||||
@RequiredArgsConstructor
|
||||
public class RuleLoader {
|
||||
|
||||
private static final String NEWLINE = "\n";
|
||||
|
||||
private final RulesProperties rulesProperties;
|
||||
private final RuleReadmeLoader ruleReadmeLoader;
|
||||
private final SourcesProperties sourcesProperties;
|
||||
private final transient RulesProperties rulesProperties;
|
||||
private final transient RuleReadmeLoader ruleReadmeLoader;
|
||||
private final transient SourcesProperties sourcesProperties =
|
||||
new SourcesProperties();
|
||||
|
||||
/**
|
||||
* Creates a new instance of the class.
|
||||
*
|
||||
* @param rulesProperties the rules priorities
|
||||
* @param ruleReadmeLoader the README loader
|
||||
* @param sourcesProperties the source priorities
|
||||
*/
|
||||
public RuleLoader(
|
||||
final RulesProperties rulesProperties,
|
||||
final RuleReadmeLoader ruleReadmeLoader,
|
||||
final SourcesProperties sourcesProperties
|
||||
) {
|
||||
this.rulesProperties = rulesProperties;
|
||||
this.ruleReadmeLoader = ruleReadmeLoader;
|
||||
this.sourcesProperties.setSources(sourcesProperties.getSources());
|
||||
}
|
||||
|
||||
/**
|
||||
* Loads from the source, where the source is enabled, all rules that are
|
||||
|
|
|
@ -1,7 +1,5 @@
|
|||
package net.kemitix.checkstyle.ruleset.builder;
|
||||
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
import org.springframework.boot.context.properties.ConfigurationProperties;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
|
||||
|
@ -14,13 +12,20 @@ import java.util.Optional;
|
|||
*
|
||||
* @author Paul Campbell (pcampbell@kemitix.net)
|
||||
*/
|
||||
@Setter
|
||||
@Getter
|
||||
@Configuration
|
||||
@ConfigurationProperties("")
|
||||
class SourcesProperties {
|
||||
|
||||
private List<RuleSource> sources = new ArrayList<>();
|
||||
private final List<RuleSource> sources = new ArrayList<>();
|
||||
|
||||
public void setSources(final List<RuleSource> sources) {
|
||||
this.sources.clear();
|
||||
this.sources.addAll(sources);
|
||||
}
|
||||
|
||||
public List<RuleSource> getSources() {
|
||||
return new ArrayList<>(sources);
|
||||
}
|
||||
|
||||
/**
|
||||
* Search for a RuleSource by name.
|
||||
|
|
|
@ -165,8 +165,7 @@ public class CheckstyleWriterTest {
|
|||
public void writeRuleWithProperties() throws Exception {
|
||||
//given
|
||||
val rule = enabledRule(RuleLevel.LAYOUT, RuleParent.TREEWALKER);
|
||||
rule.getProperties()
|
||||
.put("key", "value");
|
||||
rule.setProperties(Map.of("key", "value"));
|
||||
rulesProperties.getRules()
|
||||
.add(rule);
|
||||
//when
|
||||
|
|
|
@ -19,21 +19,9 @@ public class DefaultRuleClassLocatorTest {
|
|||
|
||||
private SourcesProperties sourceProperties = new SourcesProperties();
|
||||
|
||||
private final DefaultRuleClassLocator subject =
|
||||
new DefaultRuleClassLocator(
|
||||
checkClasses,
|
||||
sourceProperties);
|
||||
|
||||
private final RuleSource checkstyleRuleSource = RuleSourceMother.checkstyle.get();
|
||||
private final RuleSource sevntuRuleSource = RuleSourceMother.sevntu.get();
|
||||
|
||||
@BeforeEach
|
||||
public void setUp() {
|
||||
sourceProperties.setSources(Arrays.asList(
|
||||
checkstyleRuleSource, sevntuRuleSource
|
||||
));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void canLookupRuleWithClassNameEndingInCheck() {
|
||||
//given
|
||||
|
@ -43,7 +31,14 @@ public class DefaultRuleClassLocatorTest {
|
|||
final List<String> sevntuClasses = Collections.emptyList();
|
||||
checkClasses.put(checkstyleRuleSource, checkstyleClasses);
|
||||
checkClasses.put(sevntuRuleSource, sevntuClasses);
|
||||
sourceProperties.setSources(Arrays.asList(
|
||||
checkstyleRuleSource, sevntuRuleSource
|
||||
));
|
||||
final Rule rule = createCheckstyleRule(rulename);
|
||||
DefaultRuleClassLocator subject =
|
||||
new DefaultRuleClassLocator(
|
||||
checkClasses,
|
||||
sourceProperties);
|
||||
//when
|
||||
final String result = subject.apply(rule);
|
||||
//then
|
||||
|
@ -59,7 +54,14 @@ public class DefaultRuleClassLocatorTest {
|
|||
final List<String> sevntuClasses = Collections.emptyList();
|
||||
checkClasses.put(checkstyleRuleSource, checkstyleClasses);
|
||||
checkClasses.put(sevntuRuleSource, sevntuClasses);
|
||||
sourceProperties.setSources(Arrays.asList(
|
||||
checkstyleRuleSource, sevntuRuleSource
|
||||
));
|
||||
final Rule rule = createCheckstyleRule(rulename);
|
||||
DefaultRuleClassLocator subject =
|
||||
new DefaultRuleClassLocator(
|
||||
checkClasses,
|
||||
sourceProperties);
|
||||
//when
|
||||
final String result = subject.apply(rule);
|
||||
//then
|
||||
|
@ -76,6 +78,10 @@ public class DefaultRuleClassLocatorTest {
|
|||
checkClasses.put(checkstyleRuleSource, checkstyleClasses);
|
||||
checkClasses.put(sevntuRuleSource, sevntuClasses);
|
||||
final Rule rule = createCheckstyleRule(rulename);
|
||||
DefaultRuleClassLocator subject =
|
||||
new DefaultRuleClassLocator(
|
||||
checkClasses,
|
||||
sourceProperties);
|
||||
//then
|
||||
assertThatThrownBy(() -> subject.apply(rule))
|
||||
.isInstanceOf(CheckstyleClassNotFoundException.class)
|
||||
|
|
|
@ -39,7 +39,7 @@ public class DefaultRuleReadmeLoaderTest
|
|||
loader = new DefaultRuleReadmeLoader(templateProperties);
|
||||
rule = new Rule();
|
||||
rule.setName("name");
|
||||
rule.setUri(URI.create("uri"));
|
||||
rule.setUri("uri");
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
|
@ -48,12 +48,6 @@ public class RuleLoaderTest {
|
|||
public void setUp() throws Exception {
|
||||
MockitoAnnotations.openMocks(this).close();
|
||||
|
||||
ruleLoader =
|
||||
new RuleLoader(
|
||||
ruleProperties,
|
||||
ruleReadmeLoader,
|
||||
sourcesProperties);
|
||||
|
||||
enabledRule.setEnabled(true);
|
||||
enabledRule.setName(enabledRuleName);
|
||||
|
||||
|
@ -76,12 +70,18 @@ public class RuleLoaderTest {
|
|||
false,
|
||||
disabledRuleSourcePackage);
|
||||
ruleSources.add(disabledRuleSource);
|
||||
sourcesProperties.setSources(ruleSources);
|
||||
rules.add(disabledRule);
|
||||
disabledRuleLines.add(disabledRuleLineOne);
|
||||
disabledRuleLines.add(disabledRuleLineTwo);
|
||||
given(ruleReadmeLoader.load(disabledRule))
|
||||
.willReturn(disabledRuleLines.stream());
|
||||
}
|
||||
|
||||
ruleLoader =
|
||||
new RuleLoader(
|
||||
ruleProperties,
|
||||
ruleReadmeLoader,
|
||||
sourcesProperties); }
|
||||
|
||||
@Test
|
||||
public void enabledForEnabledSource() {
|
||||
|
|
|
@ -5,7 +5,7 @@ import org.assertj.core.api.SoftAssertions;
|
|||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import java.net.URI;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* Tests for {@link Rule}.
|
||||
|
@ -31,7 +31,7 @@ public class RuleTest {
|
|||
val level = RuleLevel.LAYOUT;
|
||||
val enabled = true;
|
||||
val insuppressible = true;
|
||||
val uri = URI.create("rule://name.md");
|
||||
val uri = "rule://name.md";
|
||||
val reason = "reason";
|
||||
val key = "key";
|
||||
val value = "value";
|
||||
|
@ -44,16 +44,12 @@ public class RuleTest {
|
|||
rule.setInsuppressible(insuppressible);
|
||||
rule.setUri(uri);
|
||||
rule.setReason(reason);
|
||||
rule.getProperties()
|
||||
.put(key, value);
|
||||
rule.setProperties(Map.of(key, value));
|
||||
//then
|
||||
SoftAssertions.assertSoftly(softly -> {
|
||||
softly.assertThat(rule.getName())
|
||||
.as("set/getName()")
|
||||
.isEqualTo(name);
|
||||
softly.assertThat(rule.getParent())
|
||||
.as("set/getParent()")
|
||||
.isEqualTo(parent);
|
||||
softly.assertThat(rule.getLevel())
|
||||
.as("set/getLevel()")
|
||||
.isEqualTo(level);
|
||||
|
|
|
@ -3,6 +3,8 @@ package net.kemitix.checkstyle.ruleset.builder;
|
|||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import java.util.Collections;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
public class SourcesPropertiesTest {
|
||||
|
@ -24,7 +26,7 @@ public class SourcesPropertiesTest {
|
|||
final RuleSource source =
|
||||
RuleSourceMother.create("name", true, "package");
|
||||
//when
|
||||
sourcesProperties.getSources().add(source);
|
||||
sourcesProperties.setSources(Collections.singletonList(source));
|
||||
//then
|
||||
assertThat(sourcesProperties.getSources()).containsExactly(source);
|
||||
}
|
||||
|
|
|
@ -22,7 +22,7 @@
|
|||
|
||||
<properties>
|
||||
<tiles-maven-plugin.version>2.23</tiles-maven-plugin.version>
|
||||
<kemitix-tiles.version>3.1.0</kemitix-tiles.version>
|
||||
<kemitix-tiles.version>3.1.1</kemitix-tiles.version>
|
||||
</properties>
|
||||
|
||||
<licenses>
|
||||
|
|
|
@ -18,7 +18,7 @@
|
|||
|
||||
<properties>
|
||||
<tiles-maven-plugin.version>2.23</tiles-maven-plugin.version>
|
||||
<kemitix-maven-tiles.version>3.1.0</kemitix-maven-tiles.version>
|
||||
<kemitix-maven-tiles.version>3.1.1</kemitix-maven-tiles.version>
|
||||
|
||||
<maven-checkstyle-plugin.version>3.1.2</maven-checkstyle-plugin.version>
|
||||
<checkstyle.version>8.44</checkstyle.version>
|
||||
|
|
Loading…
Reference in a new issue