diff --git a/LICENSE b/LICENSE index a2828e73..1c91f10a 100644 --- a/LICENSE +++ b/LICENSE @@ -6,7 +6,7 @@ http://creativecommons.org/licenses/by/4.0/ MIT License -Copyright (c) 2014-2023 Dr. Ullrich Hafner +Copyright (c) 2014-2026 Dr. Ullrich Hafner Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation diff --git a/LIESMICH.md b/LIESMICH.md index bc195c03..697abf4d 100644 --- a/LIESMICH.md +++ b/LIESMICH.md @@ -25,7 +25,7 @@ entsprechenden IntelliJ Plugins). Zusätzlich sind die [IntelliJ Code Inspections](https://www.jetbrains.com/help/idea/code-inspection.html) gemäß meiner Richtlinien konfiguriert. Aktuell können diese allerdings noch nicht automatisch im Build überprüft werden (siehe [#7](https://github.com/uhafner/codingstyle/issues/7)). Insgesamt ist damit sichergestellt, -dass immer die gleichen Warnungen angezeigt werden - egal wie und wo die Java Dateien weiterverarbeitet werden. +dass immer die gleichen Warnungen angezeigt werden - egal wie und wo die Java-Dateien weiterverarbeitet werden. Für SpotBugs und PMD ist der Umweg über das Build Management Tool [Maven](http://maven.apache.org/) erforderlich (die entsprechenden IntelliJ Plugins sind leider aus meiner Sicht noch nicht ausgereift genug bzw. verwenden eine separate Konfiguration). Die Verwendung von Maven hat zudem den Vorteil, dass die Ergebnisse hinterher leicht in den Continuous Integration Server diff --git a/README.md b/README.md index d86e7504..72041975 100644 --- a/README.md +++ b/README.md @@ -17,7 +17,7 @@ It provides all necessary resources for a Java project to enforce this coding st - [SpotBugs](https://spotbugs.github.io) - [Error Prone](https://errorprone.info) -❗This project requires a JDK version of 17 or higher.❗ +❗This project requires a JDK version of 21 or higher.❗ Moreover, this project provides some sample classes that already use this style guide. These classes can be used as such but are not required in this project. @@ -54,4 +54,4 @@ Source code (snippets, examples, and classes) are using the [MIT license](https: [![License: MIT](https://img.shields.io/badge/license-MIT-yellow.svg)](https://en.wikipedia.org/wiki/MIT_License) [![License: CC BY 4.0](https://img.shields.io/badge/License-CC%20BY%204.0-lightgrey.svg)](https://creativecommons.org/licenses/by/4.0/) -![JDK17](https://img.shields.io/badge/jdk-17-blue.svg) +![JDK21](https://img.shields.io/badge/jdk-21-blue.svg) diff --git a/pom.xml b/pom.xml index c58afad5..6f1b9dfe 100644 --- a/pom.xml +++ b/pom.xml @@ -4,7 +4,7 @@ edu.hm.hafner codingstyle - 5.28.0-SNAPSHOT + 6.0.0-SNAPSHOT jar Java coding style @@ -47,7 +47,7 @@ UTF-8 ${source.encoding} - 17 + 21 21 ${project.groupId}.codingstyle @@ -357,19 +357,19 @@ org.openrewrite.maven.BestPractices org.openrewrite.maven.RemoveRedundantDependencyVersions org.openrewrite.staticanalysis.AddSerialAnnotationToSerialVersionUID - org.openrewrite.staticanalysis.MissingOverrideAnnotation org.openrewrite.staticanalysis.CodeCleanup org.openrewrite.staticanalysis.CommonStaticAnalysis + org.openrewrite.staticanalysis.MissingOverrideAnnotation org.openrewrite.staticanalysis.RemoveExtraSemicolons - org.openrewrite.java.migrate.UpgradeToJava17 + org.openrewrite.java.migrate.UpgradeToJava21 + org.openrewrite.java.migrate.util.JavaUtilAPIs org.openrewrite.java.migrate.util.SequencedCollection + org.openrewrite.java.migrate.lang.StringRulesRecipes org.openrewrite.java.migrate.lang.var.UseVarForObject org.openrewrite.java.migrate.net.JavaNetAPIs - org.openrewrite.java.migrate.util.JavaUtilAPIs - org.openrewrite.java.migrate.lang.StringRulesRecipes - org.openrewrite.java.format.RemoveTrailingWhitespace org.openrewrite.java.format.BlankLines org.openrewrite.java.format.EmptyNewlineAtEndOfFile + org.openrewrite.java.format.RemoveTrailingWhitespace org.openrewrite.java.testing.assertj.SimplifyChainedAssertJAssertions @@ -719,7 +719,8 @@ - ${java.jdk.version} + [21,22),[25,26) + Java LTS 21 or 25 is required to build this project. diff --git a/src/main/java/edu/hm/hafner/util/FilteredLog.java b/src/main/java/edu/hm/hafner/util/FilteredLog.java index f3e730bc..e446025d 100644 --- a/src/main/java/edu/hm/hafner/util/FilteredLog.java +++ b/src/main/java/edu/hm/hafner/util/FilteredLog.java @@ -23,7 +23,7 @@ */ public class FilteredLog implements Serializable { @Serial - private static final long serialVersionUID = -8552323621953159904L; + private static final long serialVersionUID = 6956036398485594488L; private static final int DEFAULT_MAX_LINES = 20; @@ -31,10 +31,10 @@ public class FilteredLog implements Serializable { private final int maxLines; private int lines; - @SuppressWarnings("serial") - private final List infoMessages = new ArrayList<>(); - @SuppressWarnings("serial") - private final List errorMessages = new ArrayList<>(); + @SuppressWarnings("PMD.LooseCoupling") + private final ArrayList infoMessages = new ArrayList<>(); + @SuppressWarnings("PMD.LooseCoupling") + private final ArrayList errorMessages = new ArrayList<>(); private transient ReentrantLock lock = new ReentrantLock(); diff --git a/src/main/java/edu/hm/hafner/util/Generated.java b/src/main/java/edu/hm/hafner/util/Generated.java index 9073ba0b..4f7122f6 100644 --- a/src/main/java/edu/hm/hafner/util/Generated.java +++ b/src/main/java/edu/hm/hafner/util/Generated.java @@ -8,13 +8,11 @@ /** * This annotation is used to mark source code that has been generated or is somehow not relevant for style checking or - * code coverage analysis. It is quite similar to the JSR305 annotation. The - * main difference is that it has class retention, so it is available for tools that work on bytecode (like JaCoCo, - * PIT, or SpotBugs). + * code coverage analysis. It is quite similar to the annotation of the abandoned JSR305 project. The main difference is + * that it has class retention, so it is available for tools that work on bytecode (like JaCoCo, PIT, or SpotBugs). */ @Retention(CLASS) -@Target({PACKAGE, TYPE, ANNOTATION_TYPE, METHOD, CONSTRUCTOR, FIELD, - LOCAL_VARIABLE, PARAMETER}) +@Target({PACKAGE, TYPE, ANNOTATION_TYPE, METHOD, CONSTRUCTOR, FIELD, LOCAL_VARIABLE, PARAMETER}) public @interface Generated { /** * An optional property that identifies the code generator. diff --git a/src/test/java/edu/hm/hafner/util/EnsureTest.java b/src/test/java/edu/hm/hafner/util/EnsureTest.java index fa3b659b..2565be6d 100644 --- a/src/test/java/edu/hm/hafner/util/EnsureTest.java +++ b/src/test/java/edu/hm/hafner/util/EnsureTest.java @@ -29,7 +29,7 @@ void shouldNotThrowExceptionIfContractIsValid() { Ensure.that("").isNotNull(); Ensure.that("", "").isNotNull(); Ensure.that(null, (Object) null).isNull(); - Ensure.that(new String[] {""}).isNotEmpty(); + Ensure.that(new String[]{""}).isNotEmpty(); Ensure.that(SOME_STRING).isNotEmpty(); Ensure.that(SOME_STRING).isNotBlank(); Ensure.that("").isInstanceOf(String.class); @@ -116,7 +116,7 @@ void shouldThrowExceptionIfEmpty() { Ensure.that(Lists.newArrayList("", null, "")).isNotEmpty(ERROR_MESSAGE)).isInstanceOf( AssertionError.class); assertThatThrownBy(() -> - Ensure.that(new String[] {"", null, ""}).isNotEmpty(ERROR_MESSAGE)).isInstanceOf(AssertionError.class); + Ensure.that(new String[]{"", null, ""}).isNotEmpty(ERROR_MESSAGE)).isInstanceOf(AssertionError.class); assertThatThrownBy(() -> Ensure.that("").isNotEmpty(ERROR_MESSAGE)).isInstanceOf(AssertionError.class); assertThatThrownBy(() -> @@ -128,7 +128,7 @@ void shouldThrowExceptionIfEmpty() { assertThatThrownBy(() -> Ensure.that(Lists.newArrayList("", null, "")).isNotEmpty()).isInstanceOf(AssertionError.class); assertThatThrownBy(() -> - Ensure.that(new String[] {"", null, ""}).isNotEmpty()).isInstanceOf(AssertionError.class); + Ensure.that(new String[]{"", null, ""}).isNotEmpty()).isInstanceOf(AssertionError.class); assertThatThrownBy(() -> Ensure.that("").isNotEmpty()).isInstanceOf(AssertionError.class); assertThatThrownBy(() -> diff --git a/src/test/java/edu/hm/hafner/util/LineRangeListTest.java b/src/test/java/edu/hm/hafner/util/LineRangeListTest.java index 4c4ffb32..2257f5ac 100644 --- a/src/test/java/edu/hm/hafner/util/LineRangeListTest.java +++ b/src/test/java/edu/hm/hafner/util/LineRangeListTest.java @@ -1,9 +1,9 @@ package edu.hm.hafner.util; -import java.util.List; - import org.junit.jupiter.api.Test; +import java.util.List; + import static org.assertj.core.api.Assertions.*; /** @@ -43,17 +43,17 @@ void shouldSupportSetOperations() { var range = new LineRange(1, 2); list.add(range); - assertThat(list.get(0)).isEqualTo(range); - assertThat(list.get(0)).isNotSameAs(range); + assertThat(list.getFirst()).isEqualTo(range); + assertThat(list.getFirst()).isNotSameAs(range); assertThat(list).hasSize(1); var other = new LineRange(3, 4); assertThat(list.set(0, other)).isEqualTo(range); - assertThat(list.get(0)).isEqualTo(other); - assertThat(list.get(0)).isNotSameAs(other); + assertThat(list.getFirst()).isEqualTo(other); + assertThat(list.getFirst()).isNotSameAs(other); assertThat(list).hasSize(1); - assertThat(list.remove(0)).isEqualTo(other); + assertThat(list.removeFirst()).isEqualTo(other); assertThat(list).hasSize(0); }