Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bump version of PMD to PMD-7.0.0-RC4 #939

Merged
merged 9 commits into from
Mar 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions doc/Continuous-Integration.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Continuous Integration des Coding Style

Gemäß des Grundsatzes **eat your own dogfood** ist dieser Coding Style bereits für die Continuous Integration
Gemäß dem Grundsatz **eat your own dogfood** ist dieser Coding Style bereits für die Continuous Integration
in [GitHub Actions](https://github.com/features/actions) und [Jenkins](https://jenkins.io) vorbereitet.

## Maven Konfiguration
Expand All @@ -15,7 +15,7 @@ U.a. sind die folgenden Plugins vorkonfiguriert:
- maven-javadoc-plugin: aktiviert die strikte Prüfung von JavaDoc Kommentaren
- maven-jar-plugin: legt einen Modulnamen fest, falls das Projekt in Java 9 oder höher verwendet wird. Außerdem wird
ein test-jar konfiguriert, sodass alle Tests (und abstrakte Testklassen) auch als Dependencies genutzt werden können.
- maven-pmd-plugin: prüft das Projekt mit PMD, die Regeln liegen in der Datei [pmd-configuration.xml](../etc/pmd-configuration.xml).
- maven-pmd-plugin: prüft das Projekt mit PMD, die Regeln liegen in den Dateien [pmd-java-configuration.xml](../etc/pmd-java-configuration.xml), [pmd-tests-configuration.xml](../etc/pmd-tests-configuration.xml) und [pmd-javascript-configuration.xml](../etc/pmd-javascript-configuration.xml).
- maven-checkstyle-plugin: prüft das Projekt mit CheckStyle, die Regeln liegen in den Dateien [checkstyle-java-configuration.xml](../etc/checkstyle-java-configuration.xml) und [checkstyle-tests-configuration.xml](../etc/checkstyle-tests-configuration.xml).
- spotbugs-maven-plugin: prüft das Projekt mit SpotBugs, alle Regeln werden verwendet mit den Ausnahmen definiert in der Datei [spotbugs-exclusion-filter.xml](../etc/spotbugs-exclusion-filter.xml).
- org.revapi: prüft, ob die aktuelle Versionsnummer die [semantische Versionierung](https://semver.org) berücksichtigt (source and binary). D.h. es gilt:
Expand Down
12 changes: 4 additions & 8 deletions etc/pmd-configuration.xml → etc/pmd-java-configuration.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,14 @@
<ruleset xmlns="http://pmd.sourceforge.net/ruleset/2.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
name="pmd-eclipse"
xsi:schemaLocation="http://pmd.sourceforge.net/ruleset/2.0.0 http://pmd.sourceforge.net/ruleset_2_0_0.xsd">
xsi:schemaLocation="http://pmd.sourceforge.net/ruleset/2.0.0 https://pmd.sourceforge.io/ruleset_2_0_0.xsd">
<description>Ullrich Hafner's PMD rules</description>

<rule ref="category/java/bestpractices.xml">
<exclude name="LiteralsFirstInComparisons"/>
<exclude name="JUnitTestContainsTooManyAsserts"/>
<exclude name="JUnitTestsShouldIncludeAssert"/>
<exclude name="JUnitAssertionsShouldIncludeMessage"/>
<exclude name="UnusedImports"/>
<exclude name="GuardLogStatement"/>
<exclude name="AccessorMethodGeneration"/>
<exclude name="JUnit5TestShouldBePackagePrivate"/>
Expand All @@ -25,7 +24,6 @@
<exclude name="FieldDeclarationsShouldBeAtStartOfClass"/>
<exclude name="CommentDefaultAccessModifier"/>
<exclude name="LocalVariableCouldBeFinal"/>
<exclude name="DefaultPackage"/>
<exclude name="LongVariable"/>
<exclude name="ShortVariable"/>
<exclude name="ShortClassName"/>
Expand Down Expand Up @@ -69,16 +67,14 @@
<exclude name="FinalFieldCouldBeStatic"/>
<exclude name="AvoidUncheckedExceptionsInSignatures"/>
<exclude name="ExcessiveImports"/>
<exclude name="ImmutableField"/>
<exclude name="SimplifyBooleanReturns"/>
</rule>
<rule ref="category/java/design.xml/ImmutableField">
<rule ref="category/java/design.xml/SimplifyBooleanReturns">
<properties>
<property name="ignoredAnnotations" value="org.junit.jupiter.api.io.TempDir|javax.inject.Inject|com.google.inject.Inject"/>
<property name="violationSuppressXPath" value="./ancestor::*[@Name = 'equals'] | ./ancestor::*[@Name = 'hashCode']"/>
</properties>
</rule>

<rule ref="category/java/errorprone.xml">
<exclude name="DataflowAnomalyAnalysis"/>
<exclude name="AvoidDuplicateLiterals"/>
<exclude name="TestClassWithoutTestCases"/>
<exclude name="EmptyCatchBlock"/>
Expand Down
12 changes: 12 additions & 0 deletions etc/pmd-javascript-configuration.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<?xml version="1.0" encoding="UTF-8"?>
<!-- ${project.groupId}:${project.artifactId}:${project.version} -->
<ruleset xmlns="http://pmd.sourceforge.net/ruleset/2.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
name="pmd-eclipse"
xsi:schemaLocation="http://pmd.sourceforge.net/ruleset/2.0.0 https://pmd.sourceforge.io/ruleset_2_0_0.xsd">
<description>Ullrich Hafner's PMD rules</description>

<rule ref="category/ecmascript/bestpractices.xml"/>
<rule ref="category/ecmascript/codestyle.xml"/>
<rule ref="category/ecmascript/errorprone.xml"/>
</ruleset>
109 changes: 109 additions & 0 deletions etc/pmd-tests-configuration.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
<?xml version="1.0" encoding="UTF-8"?>
<!-- ${project.groupId}:${project.artifactId}:${project.version} -->
<ruleset xmlns="http://pmd.sourceforge.net/ruleset/2.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
name="pmd-eclipse"
xsi:schemaLocation="http://pmd.sourceforge.net/ruleset/2.0.0 https://pmd.sourceforge.io/ruleset_2_0_0.xsd">
<description>Ullrich Hafner's PMD rules</description>

<rule ref="category/java/bestpractices.xml">
<exclude name="LiteralsFirstInComparisons"/>
<exclude name="JUnitTestContainsTooManyAsserts"/>
<exclude name="JUnitTestsShouldIncludeAssert"/>
<exclude name="JUnitAssertionsShouldIncludeMessage"/>
<exclude name="GuardLogStatement"/>
<exclude name="AccessorMethodGeneration"/>
<exclude name="JUnit5TestShouldBePackagePrivate"/>
<exclude name="JUnit4TestShouldUseTestAnnotation"/>
<exclude name="UnusedPrivateMethod"/>
<exclude name="LooseCoupling"/>
</rule>
<rule ref="category/java/codestyle.xml">
<exclude name="EmptyControlStatement"/>
<exclude name="AtLeastOneConstructor"/>
<exclude name="UnnecessaryConstructor"/>
<exclude name="FieldDeclarationsShouldBeAtStartOfClass"/>
<exclude name="CommentDefaultAccessModifier"/>
<exclude name="LocalVariableCouldBeFinal"/>
<exclude name="LongVariable"/>
<exclude name="ShortVariable"/>
<exclude name="ShortClassName"/>
<exclude name="OnlyOneReturn"/>
<exclude name="EmptyMethodInAbstractClassShouldBeAbstract"/>
<exclude name="ConfusingTernary"/>
<exclude name="LocalVariableNamingConventions"/>
<exclude name="ClassNamingConventions"/>
</rule>
<rule ref="category/java/codestyle.xml/UnnecessaryConstructor">
<properties>
<property name="ignoredAnnotations" value="org.kohsuke.stapler.DataBoundConstructor"/>
</properties>
</rule>
<rule ref="category/java/codestyle.xml/ClassNamingConventions">
<properties>
<property name="utilityClassPattern" value="[A-Z][a-zA-Z0-9]+"/>
<property name="testClassPattern" value="^[A-Z][a-zA-Z0-9]+Test.*$|^[A-Z][a-zA-Z0-9]+Benchmark.*$|"/>
</properties>
</rule>
<rule ref="category/java/codestyle.xml/LinguisticNaming">
<properties>
<property name="checkSetters" value="false"/>
<property name="booleanMethodPrefixes" value="is|has|can|have|will" />
</properties>
</rule>
<rule ref="category/java/codestyle.xml/ConfusingTernary">
<properties>
<property name="ignoreElseIf" value="true"/>
</properties>
</rule>
<rule ref="category/java/design.xml">
<exclude name="LoosePackageCoupling"/>
<exclude name="LawOfDemeter"/>
<exclude name="TooManyMethods"/>
<exclude name="ClassWithOnlyPrivateConstructorsShouldBeFinal"/>
<exclude name="ExcessiveParameterList"/>
<exclude name="ExcessiveMethodLength"/>
<exclude name="UseObjectForClearerAPI"/>
<exclude name="AvoidCatchingGenericException"/>
<exclude name="FinalFieldCouldBeStatic"/>
<exclude name="AvoidUncheckedExceptionsInSignatures"/>
<exclude name="ExcessiveImports"/>
<exclude name="SimplifyBooleanReturns"/>
<exclude name="DataClass"/>
</rule>
<rule ref="category/java/design.xml/SimplifyBooleanReturns">
<properties>
<property name="violationSuppressXPath" value="./MethodDeclaration[@Image='equals']"/>
</properties>
</rule>
<rule ref="category/java/errorprone.xml">
<exclude name="AvoidDuplicateLiterals"/>
<exclude name="TestClassWithoutTestCases"/>
<exclude name="EmptyCatchBlock"/>
<exclude name="AvoidLiteralsInIfCondition"/>
<exclude name="UseProperClassLoader"/>
</rule>
<rule ref="category/java/errorprone.xml/AvoidLiteralsInIfCondition">
<properties>
<property name="ignoreMagicNumbers" value="-1,0,1"/>
</properties>
</rule>
<rule ref="category/java/errorprone.xml/EmptyCatchBlock">
<properties>
<property name="allowCommentedBlocks" value="true"/>
</properties>
</rule>
<rule ref="category/java/multithreading.xml">
<exclude name="UseConcurrentHashMap"/>
</rule>
<rule ref="category/java/performance.xml">
<exclude name="AppendCharacterWithChar"/>
<exclude name="AvoidInstantiatingObjectsInLoops"/>
<exclude name="RedundantFieldInitializer"/>
<exclude name="ConsecutiveAppendsShouldReuse"/>
<exclude name="UseStringBufferForStringAppends"/>
</rule>
<rule ref="category/java/security.xml">
</rule>

</ruleset>
59 changes: 47 additions & 12 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@
<maven-surefire-plugin.version>3.2.5</maven-surefire-plugin.version>
<maven-jar-plugin.version>3.3.0</maven-jar-plugin.version>
<maven-pmd-plugin.version>3.21.2</maven-pmd-plugin.version>
<pmd.version>6.55.0</pmd.version>
<pmd.version>7.0.0-rc4</pmd.version>
<maven-checkstyle-plugin.version>3.3.1</maven-checkstyle-plugin.version>
<checkstyle.version>10.14.1</checkstyle.version>
<spotbugs-maven-plugin.version>4.8.3.1</spotbugs-maven-plugin.version>
Expand Down Expand Up @@ -490,7 +490,7 @@
<classifier>config</classifier>
<includes>
<include>**/checkstyle-configuration.xml</include>
<include>**/pmd-configuration.xml</include>
<include>**/pmd-*-configuration.xml</include>
<include>**/spotbugs-exclusion-filter.xml</include>
</includes>
</configuration>
Expand Down Expand Up @@ -547,18 +547,14 @@
<configuration>
<linkXRef>false</linkXRef>
<failOnViolation>false</failOnViolation>
<rulesets>
<ruleset>etc/pmd-configuration.xml</ruleset>
</rulesets>
<targetJdk>${java.version}</targetJdk>
<includeTests>true</includeTests>
<minimumTokens>50</minimumTokens>
<excludeRoots>
<excludeRoot>target/generated-test-sources/test-annotations</excludeRoot>
<excludeRoot>target/generated-test-sources/assertj-assertions</excludeRoot>
</excludeRoots>
</configuration>
<dependencies>
<dependency>
<groupId>net.sourceforge.pmd</groupId>
<artifactId>pmd-compat6</artifactId>
<version>${pmd.version}</version>
</dependency>
<dependency>
<groupId>net.sourceforge.pmd</groupId>
<artifactId>pmd-core</artifactId>
Expand All @@ -569,15 +565,54 @@
<artifactId>pmd-java</artifactId>
<version>${pmd.version}</version>
</dependency>
<dependency>
<groupId>net.sourceforge.pmd</groupId>
<artifactId>pmd-javascript</artifactId>
<version>${pmd.version}</version>
</dependency>
<dependency>
<groupId>net.sourceforge.pmd</groupId>
<artifactId>pmd-jsp</artifactId>
<version>${pmd.version}</version>
</dependency>
</dependencies>
<executions>
<execution>
<id>run-pmd</id>
<id>run-pmd-java</id>
<goals>
<goal>pmd</goal>
<goal>cpd</goal>
</goals>
<phase>verify</phase>
<configuration>
<targetDirectory>${project.build.directory}/pmd-java</targetDirectory>
<rulesets>
<ruleset>etc/pmd-java-configuration.xml</ruleset>
</rulesets>
<includeTests>false</includeTests>
<minimumTokens>50</minimumTokens>
</configuration>
</execution>
<execution>
<id>run-pmd-tests</id>
<goals>
<goal>pmd</goal>
<goal>cpd</goal>
</goals>
<phase>verify</phase>
<configuration>
<targetDirectory>${project.build.directory}/pmd-tests</targetDirectory>
<rulesets>
<ruleset>etc/pmd-tests-configuration.xml</ruleset>
</rulesets>
<includeTests>true</includeTests>
<minimumTokens>100</minimumTokens>
<excludeRoots>
<excludeRoot>src/main/java</excludeRoot>
<excludeRoot>${project.build.directory}/generated-test-sources/test-annotations</excludeRoot>
<excludeRoot>${project.build.directory}/generated-test-sources/assertj-assertions</excludeRoot>
</excludeRoots>
</configuration>
</execution>
</executions>
</plugin>
Expand Down
24 changes: 11 additions & 13 deletions src/main/java/edu/hm/hafner/util/Ensure.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;

/**
* Provides several helper methods to validate method arguments and class invariants thus supporting the design by
* Provides several helper methods to validate method arguments and class invariants, thus supporting the design by
* contract concept (DBC).
*
* <p>
Expand All @@ -34,7 +34,6 @@
* @author Ullrich Hafner
* @see <a href="http://se.ethz.ch/~meyer/publications/computer/contract.pdf"> Design by Contract (Meyer, Bertrand)</a>
*/
@SuppressWarnings({"NonBooleanMethodNameMayNotStartWithQuestion", "CyclicClassDependency", "NullAway"})
public final class Ensure {
/**
* Returns a boolean condition.
Expand All @@ -44,7 +43,6 @@ public final class Ensure {
*
* @return a boolean condition
*/
@SuppressWarnings("BooleanParameter")
@CheckReturnValue
public static BooleanCondition that(final boolean value) {
return new BooleanCondition(value);
Expand Down Expand Up @@ -169,7 +167,7 @@ public static void thatStatementIsNeverReached(final String explanation, final O
* always thrown
*/
@FormatMethod
private static void throwException(final String message, final Object... args) {
private static void throwException(final String message, @CheckForNull final Object... args) {
throw new AssertionError(String.format(message, args));
}

Expand Down Expand Up @@ -260,7 +258,6 @@ public static class CollectionCondition extends IterableCondition {
* @param value
* value of the condition
*/
@SuppressWarnings("AssignmentToCollectionOrArrayFieldFromParameter")
public CollectionCondition(@CheckForNull final Collection<?> value) {
super(value);
}
Expand Down Expand Up @@ -503,6 +500,7 @@ private boolean isBlank() {
public static class ObjectCondition<T> {
@CheckForNull
private final T value;
@CheckForNull
private final Object[] additionalValues;

/**
Expand All @@ -524,8 +522,8 @@ public ObjectCondition(@CheckForNull final T value) {
* additional values of the condition
*/
@SuppressFBWarnings("EI2")
@SuppressWarnings({"AssignmentToCollectionOrArrayFieldFromParameter", "PMD.ArrayIsStoredDirectly"})
public ObjectCondition(@CheckForNull final T value, final Object... additionalValues) {
@SuppressWarnings("PMD.ArrayIsStoredDirectly")
public ObjectCondition(@CheckForNull final T value, @CheckForNull final Object... additionalValues) {
this.value = value;
this.additionalValues = additionalValues;
}
Expand Down Expand Up @@ -555,12 +553,14 @@ public void isNotNull() {
*/
@FormatMethod
public void isNotNull(final String explanation, final Object... args) {
if (value == null) {
if (value == null || additionalValues == null) {
throwNullPointerException(explanation, args);
}
for (Object additionalValue : additionalValues) {
if (additionalValue == null) {
throwNullPointerException(explanation, args);
else {
for (Object additionalValue : additionalValues) {
if (additionalValue == null) {
throwNullPointerException(explanation, args);
}
}
}
}
Expand Down Expand Up @@ -597,7 +597,6 @@ public void isNull() {
* @throws AssertionError
* if the object is not {@code null}
*/
@SuppressWarnings("VariableNotUsedInsideIf")
@FormatMethod
public void isNull(final String explanation, final Object... args) {
if (value != null) {
Expand Down Expand Up @@ -669,7 +668,6 @@ public static class BooleanCondition {
* @param value
* value of the condition
*/
@SuppressWarnings("BooleanParameter")
public BooleanCondition(final boolean value) {
this.value = value;
}
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/edu/hm/hafner/util/TreeString.java
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ public final class TreeString implements Serializable {
}

String getLabel() {
return new String(label);
return String.valueOf(label);
}

/**
Expand Down
1 change: 0 additions & 1 deletion src/main/java/edu/hm/hafner/util/TreeStringBuilder.java
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,6 @@ public Child intern(final String string) {
/**
* Makes sure {@link #children} is writable.
*/
@SuppressWarnings("PMD.CompareObjectsWithEquals")
private void makeWritable() {
if (children == NO_CHILDREN) {
children = new HashMap<>();
Expand Down
Loading