diff --git a/builder/pom.xml b/builder/pom.xml
index 6a706c2..ba16681 100644
--- a/builder/pom.xml
+++ b/builder/pom.xml
@@ -22,7 +22,7 @@
${java.version}
${java.version}
2.23
- 3.1.0
+ 3.1.1
8.44
1.40.0
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 cdd0b42..f905fe7 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
@@ -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.
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 d457d05..433bc7e 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
@@ -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> checkClasses;
- private final SourcesProperties sourcesProperties;
+ private final transient Map> 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> checkClasses,
+ final SourcesProperties sourcesProperties
+ ) {
+ this.checkClasses = new HashMap<>(checkClasses);
+ this.sourcesProperties.setSources(sourcesProperties.getSources());
+ }
@Override
public final String apply(final Rule rule) {
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 8b9e78f..ccd8baf 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
@@ -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 properties = new HashMap<>();
+ private Map 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 properties) {
+ this.properties = new HashMap<>(properties);
+ }
+
+ public Map 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 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 isIncludedInLevel(final RuleLevel ruleLevel) {
- return rule -> ruleLevel.compareTo(rule.getLevel()) >= 0;
+ return rule -> ruleLevel.compareTo(rule.level) >= 0;
}
private static String formatProperties(final Map properties) {
diff --git a/builder/src/main/java/net/kemitix/checkstyle/ruleset/builder/RuleLoader.java b/builder/src/main/java/net/kemitix/checkstyle/ruleset/builder/RuleLoader.java
index 94141b2..cf85e2d 100644
--- a/builder/src/main/java/net/kemitix/checkstyle/ruleset/builder/RuleLoader.java
+++ b/builder/src/main/java/net/kemitix/checkstyle/ruleset/builder/RuleLoader.java
@@ -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
diff --git a/builder/src/main/java/net/kemitix/checkstyle/ruleset/builder/SourcesProperties.java b/builder/src/main/java/net/kemitix/checkstyle/ruleset/builder/SourcesProperties.java
index d9d7cd7..bd92b97 100644
--- a/builder/src/main/java/net/kemitix/checkstyle/ruleset/builder/SourcesProperties.java
+++ b/builder/src/main/java/net/kemitix/checkstyle/ruleset/builder/SourcesProperties.java
@@ -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 sources = new ArrayList<>();
+ private final List sources = new ArrayList<>();
+
+ public void setSources(final List sources) {
+ this.sources.clear();
+ this.sources.addAll(sources);
+ }
+
+ public List getSources() {
+ return new ArrayList<>(sources);
+ }
/**
* Search for a RuleSource by name.
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 d5a6815..cff958e 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
@@ -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
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 10f6595..680a584 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
@@ -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 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 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)
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 3f1d3e9..37dc8f9 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
@@ -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
diff --git a/builder/src/test/java/net/kemitix/checkstyle/ruleset/builder/RuleLoaderTest.java b/builder/src/test/java/net/kemitix/checkstyle/ruleset/builder/RuleLoaderTest.java
index 951de53..64279f3 100644
--- a/builder/src/test/java/net/kemitix/checkstyle/ruleset/builder/RuleLoaderTest.java
+++ b/builder/src/test/java/net/kemitix/checkstyle/ruleset/builder/RuleLoaderTest.java
@@ -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() {
diff --git a/builder/src/test/java/net/kemitix/checkstyle/ruleset/builder/RuleTest.java b/builder/src/test/java/net/kemitix/checkstyle/ruleset/builder/RuleTest.java
index 04be25c..a7662eb 100644
--- a/builder/src/test/java/net/kemitix/checkstyle/ruleset/builder/RuleTest.java
+++ b/builder/src/test/java/net/kemitix/checkstyle/ruleset/builder/RuleTest.java
@@ -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);
diff --git a/builder/src/test/java/net/kemitix/checkstyle/ruleset/builder/SourcesPropertiesTest.java b/builder/src/test/java/net/kemitix/checkstyle/ruleset/builder/SourcesPropertiesTest.java
index 2eb5873..7604c18 100644
--- a/builder/src/test/java/net/kemitix/checkstyle/ruleset/builder/SourcesPropertiesTest.java
+++ b/builder/src/test/java/net/kemitix/checkstyle/ruleset/builder/SourcesPropertiesTest.java
@@ -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);
}
diff --git a/ruleset/pom.xml b/ruleset/pom.xml
index 645bbe5..d6f2320 100644
--- a/ruleset/pom.xml
+++ b/ruleset/pom.xml
@@ -22,7 +22,7 @@
2.23
- 3.1.0
+ 3.1.1
diff --git a/tile/pom.xml b/tile/pom.xml
index 657181d..4a494e8 100644
--- a/tile/pom.xml
+++ b/tile/pom.xml
@@ -18,7 +18,7 @@
2.23
- 3.1.0
+ 3.1.1
3.1.2
8.44