diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 328b293b1b..da398b9e99 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -1,138 +1,126 @@ -name: CI - +name: CI ๐Ÿšฆ on: push: branches: - main - release-* pull_request: - env: build_java_version: 21 - jobs: build: + name: Build ๐Ÿ“ฆ runs-on: ubuntu-latest steps: - - name: Checkout + - name: Checkout ๐Ÿ“ฅ uses: actions/checkout@v6 - - name: Set up Java + - name: Setup Java โ˜•๏ธ uses: actions/setup-java@v5.1.0 with: - distribution: 'zulu' + distribution: zulu java-version: ${{ env.build_java_version }} - - name: Set Up Gradle + - name: Setup Gradle ๐Ÿ˜ uses: gradle/actions/setup-gradle@v5 - - name: Build + - name: Spotless โœจ + run: ./gradlew spotlessCheck + - name: Sanity Check ๐Ÿ•Š + run: ./gradlew rewriteDryRun + - name: Build ๐Ÿ—๏ธ run: ./gradlew build - - name: Check project files unmodified + - name: Verify No Modified Files ๐Ÿ“‹ run: | - directoryState="$(git status --porcelain)" + directoryState="$(git.status --porcelain)" if [ -n "$directoryState" ]; then - echo "Some files were modified during build. Please run the build locally before checking in, as it ensures some source file conventions (like copyright header)." - echo "The following files were modified:" + echo "Some files were modified during build. Please run the build locally before checking in." + echo "Modified files:" echo "$directoryState" exit 1 fi - test: + name: Unit Tests ๐Ÿงช (${{ matrix.os }} - JDK ${{ matrix.test_java_version }}) strategy: fail-fast: false matrix: - os: - - ubuntu-latest - - macos-latest - - windows-latest - test_java_version: - - 8 - - 11 - - 17 - - 21 + os: [ubuntu-latest, macos-latest, windows-latest] + test_java_version: [8, 11, 17, 21] runs-on: ${{ matrix.os }} steps: - - name: Checkout + - name: Checkout ๐Ÿ“ฅ uses: actions/checkout@v6 - - name: Set up Build JDK + - name: Setup Build JDK โ˜• uses: actions/setup-java@v5.1.0 with: - distribution: 'zulu' + distribution: zulu java-version: ${{ env.build_java_version }} - - name: Set up Test JDK + - name: Setup Test JDK โ˜• uses: actions/setup-java@v5.1.0 with: - distribution: 'zulu' + distribution: zulu java-version: ${{ matrix.test_java_version }} - - name: Provide installed JDKs - uses: actions/github-script@v8 + - name: Resolve Installed JDK Paths ๐Ÿ” id: provideJdkPaths + uses: actions/github-script@v8 with: script: | - for ( let envVarName in process.env ) { + for (let envVarName in process.env) { if (/JAVA_HOME_\d.*64/.test(envVarName)) { const version = envVarName.match(/JAVA_HOME_(\d+).*64/)[1]; if (version === "${{ matrix.test_java_version }}") { - core.exportVariable('test_jdk_path', process.env[envVarName]); + core.exportVariable("test_jdk_path", process.env[envVarName]); } else if (version === "${{ env.build_java_version }}") { - core.exportVariable('build_jdk_path', process.env[envVarName]); + core.exportVariable("build_jdk_path", process.env[envVarName]); } } } - - name: Set Up Gradle + - name: Setup Gradle ๐Ÿ˜ uses: gradle/actions/setup-gradle@v5 - - name: Test + - name: Run Tests ๐Ÿงช run: ./gradlew test -PallTests -PtestJavaVersion=${{ matrix.test_java_version }} "-Porg.gradle.java.installations.paths=${{ env.test_jdk_path }}" env: JAVA_HOME: ${{ env.build_jdk_path }} - integration-test: + name: Integration Tests ๐Ÿงฉ (${{ matrix.os }} - JDK ${{ matrix.test_java_version }}) strategy: fail-fast: false matrix: - os: - - ubuntu-latest - - macos-latest - - windows-latest - test_java_version: - - 8 - - 11 - - 17 - - 21 + os: [ubuntu-latest, macos-latest, windows-latest] + test_java_version: [8, 11, 17, 21] runs-on: ${{ matrix.os }} steps: - - name: Checkout + - name: Checkout ๐Ÿ“ฅ uses: actions/checkout@v6 - - name: Set up Build JDK + - name: Setup Build JDK โ˜• uses: actions/setup-java@v5.1.0 with: - distribution: 'zulu' + distribution: zulu java-version: ${{ env.build_java_version }} - - name: Set up Test JDK + - name: Setup Test JDK โ˜• uses: actions/setup-java@v5.1.0 with: - distribution: 'zulu' + distribution: zulu java-version: ${{ matrix.test_java_version }} - - name: Provide installed JDKs - uses: actions/github-script@v8 + - name: Resolve Installed JDK Paths ๐Ÿ” id: provideJdkPaths + uses: actions/github-script@v8 with: script: | - for ( let envVarName in process.env ) { + for (let envVarName in process.env) { if (/JAVA_HOME_\d.*64/.test(envVarName)) { const version = envVarName.match(/JAVA_HOME_(\d+).*64/)[1]; if (version === "${{ matrix.test_java_version }}") { - core.exportVariable('test_jdk_path', process.env[envVarName]); + core.exportVariable("test_jdk_path", process.env[envVarName]); } else if (version === "${{ env.build_java_version }}") { - core.exportVariable('build_jdk_path', process.env[envVarName]); + core.exportVariable("build_jdk_path", process.env[envVarName]); } } } - - name: Set Up Gradle + - name: Setup Gradle ๐Ÿ˜ uses: gradle/actions/setup-gradle@v5 - - name: Publish to Maven Local + - name: Publish to Maven Local ๐Ÿ“ฆ run: ./gradlew build -xtest -xspotbugsMain -xjavadoc publishToMavenLocal env: JAVA_HOME: ${{ env.build_jdk_path }} - - name: Integration test + - name: Run Integration Tests ๐Ÿงฉ run: ./gradlew runMavenTest -PtestJavaVersion=${{ matrix.test_java_version }} "-Porg.gradle.java.installations.paths=${{ env.test_jdk_path }}" env: JAVA_HOME: ${{ env.build_jdk_path }} diff --git a/.gitignore b/.gitignore index bbb461d787..b2729f8acb 100644 --- a/.gitignore +++ b/.gitignore @@ -1,5 +1,6 @@ .gradle .idea +!.idea/icon.png *.iml build out diff --git a/.idea/icon.png b/.idea/icon.png new file mode 100644 index 0000000000..e8d2ce09d0 Binary files /dev/null and b/.idea/icon.png differ diff --git a/archunit-junit/junit5/engine/src/main/java/com/tngtech/archunit/junit/internal/AbstractArchUnitTestDescriptor.java b/archunit-junit/junit5/engine/src/main/java/com/tngtech/archunit/junit/internal/AbstractArchUnitTestDescriptor.java index a5be37f5d4..8a68516433 100644 --- a/archunit-junit/junit5/engine/src/main/java/com/tngtech/archunit/junit/internal/AbstractArchUnitTestDescriptor.java +++ b/archunit-junit/junit5/engine/src/main/java/com/tngtech/archunit/junit/internal/AbstractArchUnitTestDescriptor.java @@ -76,7 +76,7 @@ public Set getTags() { static String formatWithPath(UniqueId uniqueId, String name) { return Stream.concat( uniqueId.getSegments().stream() - .filter(it -> it.getType().equals(ArchUnitTestDescriptor.CLASS_SEGMENT_TYPE)) + .filter(it -> ArchUnitTestDescriptor.CLASS_SEGMENT_TYPE.equals(it.getType())) .skip(1) .map(UniqueId.Segment::getValue) .map(Formatters::ensureSimpleName), diff --git a/archunit/src/jdk9main/java/com/tngtech/archunit/core/importer/ModuleLocationResolver.java b/archunit/src/jdk9main/java/com/tngtech/archunit/core/importer/ModuleLocationResolver.java index b5fec8a8db..052de6ace4 100644 --- a/archunit/src/jdk9main/java/com/tngtech/archunit/core/importer/ModuleLocationResolver.java +++ b/archunit/src/jdk9main/java/com/tngtech/archunit/core/importer/ModuleLocationResolver.java @@ -15,44 +15,46 @@ */ package com.tngtech.archunit.core.importer; -import java.io.File; +import com.google.common.base.Splitter; + import java.lang.module.ModuleFinder; -import java.lang.module.ModuleReference; import java.net.MalformedURLException; import java.net.URI; import java.net.URL; import java.nio.file.Path; import java.nio.file.Paths; -import java.util.List; -import java.util.Set; import java.util.stream.Stream; -import com.google.common.base.Splitter; - import static com.google.common.base.Strings.nullToEmpty; import static com.google.common.collect.Iterables.concat; +import static com.tngtech.archunit.core.importer.UrlSource.From.iterable; +import static java.io.File.pathSeparatorChar; +import static java.lang.System.getProperty; import static java.util.stream.Collectors.toList; class ModuleLocationResolver implements LocationResolver { + private static final String JDK_MODULE_PATH = "jdk.module.path"; private final FromClasspathAndUrlClassLoaders standardResolver = new FromClasspathAndUrlClassLoaders(); @Override public UrlSource resolveClassPath() { - Iterable classpath = standardResolver.resolveClassPath(); - Set systemModuleReferences = ModuleFinder.ofSystem().findAll(); - Set configuredModuleReferences = ModuleFinder.of(modulepath()).findAll(); - Iterable modulepath = Stream.concat(systemModuleReferences.stream(), configuredModuleReferences.stream()) - .flatMap(moduleReference -> moduleReference.location().stream()) - .map(this::toUrl) - .collect(toList()); - - return UrlSource.From.iterable(concat(classpath, modulepath)); + return iterable(concat( + standardResolver.resolveClassPath(), + Stream.concat(ModuleFinder.ofSystem().findAll().stream(), + ModuleFinder.of(modulepath()).findAll().stream()) + .flatMap(moduleReference -> moduleReference.location().stream()) + .map(this::toUrl) + .collect(toList()))); } private Path[] modulepath() { - String modulepathProperty = nullToEmpty(System.getProperty("jdk.module.path")); - List modulepath = Splitter.on(File.pathSeparatorChar).omitEmptyStrings().splitToList(modulepathProperty); - return modulepath.stream().map(Paths::get).toArray(Path[]::new); + return Splitter + .on(pathSeparatorChar) + .omitEmptyStrings() + .splitToList(nullToEmpty(getProperty(JDK_MODULE_PATH))) + .stream() + .map(Paths::get) + .toArray(Path[]::new); } private URL toUrl(URI uri) { diff --git a/archunit/src/main/java/com/tngtech/archunit/core/importer/ClassFileSource.java b/archunit/src/main/java/com/tngtech/archunit/core/importer/ClassFileSource.java index befbdc0718..1ca0e36def 100644 --- a/archunit/src/main/java/com/tngtech/archunit/core/importer/ClassFileSource.java +++ b/archunit/src/main/java/com/tngtech/archunit/core/importer/ClassFileSource.java @@ -207,7 +207,7 @@ public InputStream get() { @Internal class FileToImport { static boolean isRelevant(String simpleFileName) { - return simpleFileName.endsWith(".class") && !simpleFileName.equals("module-info.class"); + return simpleFileName.endsWith(".class") && !"module-info.class".equals(simpleFileName); } } } diff --git a/archunit/src/main/java/com/tngtech/archunit/core/importer/JavaClassDescriptorImporter.java b/archunit/src/main/java/com/tngtech/archunit/core/importer/JavaClassDescriptorImporter.java index 0a6ffa0030..3bd5dfedfe 100644 --- a/archunit/src/main/java/com/tngtech/archunit/core/importer/JavaClassDescriptorImporter.java +++ b/archunit/src/main/java/com/tngtech/archunit/core/importer/JavaClassDescriptorImporter.java @@ -60,7 +60,7 @@ private static boolean isAsmMethodHandle(Handle handle) { } static boolean isLambdaMetafactory(String asmObjectTypeName) { - return asmObjectTypeName.equals(LAMBDA_METAFACTORY_ASM_OBJECT_TYPE_NAME); + return LAMBDA_METAFACTORY_ASM_OBJECT_TYPE_NAME.equals(asmObjectTypeName); } static boolean isLambdaMethod(Handle methodHandle) { diff --git a/archunit/src/main/java/com/tngtech/archunit/core/importer/UrlSource.java b/archunit/src/main/java/com/tngtech/archunit/core/importer/UrlSource.java index 2f593b5d01..914a90d0d6 100644 --- a/archunit/src/main/java/com/tngtech/archunit/core/importer/UrlSource.java +++ b/archunit/src/main/java/com/tngtech/archunit/core/importer/UrlSource.java @@ -98,7 +98,7 @@ private static Iterable readClasspathEntriesFromManifests(List urls) { // Use URI because of better equals / hashcode private static void readClasspathUriEntriesFromManifests(Set result, Set uris) { - uris.stream().filter(url -> url.getScheme().equals("jar")) + uris.stream().filter(url -> "jar".equals(url.getScheme())) .map(From::readClasspathEntriesFromManifest) .map(manifestUris -> ImmutableSet.copyOf(difference(manifestUris, result))) // difference returns a dynamic SetView -> safe-copy .forEach(unknownSoFar -> { diff --git a/archunit/src/test/java/com/tngtech/archunit/core/domain/JavaParameterizedTypeTest.java b/archunit/src/test/java/com/tngtech/archunit/core/domain/JavaParameterizedTypeTest.java index 05b77742a7..47ae37e107 100644 --- a/archunit/src/test/java/com/tngtech/archunit/core/domain/JavaParameterizedTypeTest.java +++ b/archunit/src/test/java/com/tngtech/archunit/core/domain/JavaParameterizedTypeTest.java @@ -48,11 +48,11 @@ class WithWildcards, ? super Map testClass) { Type reflectionType = Arrays.stream(testClass.getTypeParameters()) - .filter(v -> v.getName().equals("TEST")) + .filter(v -> "TEST".equals(v.getName())) .map(v -> v.getBounds()[0]) .findFirst().get(); JavaType javaType = new ClassFileImporter().importClass(testClass).getTypeParameters().stream() - .filter(v -> v.getName().equals("TEST")) + .filter(v -> "TEST".equals(v.getName())) .map(v -> v.getBounds().get(0)) .findFirst().get(); diff --git a/archunit/src/test/java/com/tngtech/archunit/core/importer/ClassFileImporterSlowTest.java b/archunit/src/test/java/com/tngtech/archunit/core/importer/ClassFileImporterSlowTest.java index 3285b03938..9b9c56d8d5 100644 --- a/archunit/src/test/java/com/tngtech/archunit/core/importer/ClassFileImporterSlowTest.java +++ b/archunit/src/test/java/com/tngtech/archunit/core/importer/ClassFileImporterSlowTest.java @@ -183,7 +183,7 @@ private JavaClasses importJavaBase() { // before Java 9 packages like java.lang were in rt.jar; location.contains("rt.jar") || // from Java 9 on those packages were in a JRT with name 'java.base' - (location.asURI().getScheme().equals("jrt") && location.contains("java.base")) + ("jrt".equals(location.asURI().getScheme()) && location.contains("java.base")) )).importClasspath(); } @@ -198,7 +198,7 @@ private ImportOption importJavaBaseOrRtAndJUnitJarAndFilesOnTheClasspath() { if (location.isJar() && (location.contains("junit") || location.contains("/rt.jar"))) { return true; } - return location.asURI().getScheme().equals("jrt") && location.contains("java.base"); + return "jrt".equals(location.asURI().getScheme()) && location.contains("java.base"); }; } diff --git a/archunit/src/test/java/com/tngtech/archunit/core/importer/ClassFileImporterSyntheticPrivateAccessesTest.java b/archunit/src/test/java/com/tngtech/archunit/core/importer/ClassFileImporterSyntheticPrivateAccessesTest.java index 781e53bd7e..6aa035884b 100644 --- a/archunit/src/test/java/com/tngtech/archunit/core/importer/ClassFileImporterSyntheticPrivateAccessesTest.java +++ b/archunit/src/test/java/com/tngtech/archunit/core/importer/ClassFileImporterSyntheticPrivateAccessesTest.java @@ -461,7 +461,7 @@ private void stringConcat() { @SuppressWarnings("OptionalGetWithoutIsPresent") private Set> importRelevantAccesses(Class origin, Class target) { return new ClassFileImporter().importClasses(origin, target).get(origin).getMethods().stream() - .filter(m -> m.getName().equals("access")) + .filter(m -> "access".equals(m.getName())) .findFirst() .get() .getAccessesFromSelf() diff --git a/archunit/src/test/java/com/tngtech/archunit/core/importer/ImportOptionsTest.java b/archunit/src/test/java/com/tngtech/archunit/core/importer/ImportOptionsTest.java index 5fe9cad65b..8c3e466c78 100644 --- a/archunit/src/test/java/com/tngtech/archunit/core/importer/ImportOptionsTest.java +++ b/archunit/src/test/java/com/tngtech/archunit/core/importer/ImportOptionsTest.java @@ -207,7 +207,7 @@ private static Location locationOf(Class clazz) { } private static boolean comesFromJarArchive(Class clazz) { - return LocationTest.urlOfClass(clazz).getProtocol().equals("jar"); + return "jar".equals(LocationTest.urlOfClass(clazz).getProtocol()); } private static class FolderPattern { diff --git a/archunit/src/test/java/com/tngtech/archunit/lang/syntax/elements/GivenMethodsTest.java b/archunit/src/test/java/com/tngtech/archunit/lang/syntax/elements/GivenMethodsTest.java index b14b43206a..4232164e3d 100644 --- a/archunit/src/test/java/com/tngtech/archunit/lang/syntax/elements/GivenMethodsTest.java +++ b/archunit/src/test/java/com/tngtech/archunit/lang/syntax/elements/GivenMethodsTest.java @@ -12,7 +12,9 @@ import static com.tngtech.archunit.core.domain.TestUtils.importClasses; import static com.tngtech.archunit.lang.syntax.ArchRuleDefinition.methods; -import static com.tngtech.archunit.lang.syntax.elements.GivenMembersTest.*; +import static com.tngtech.archunit.lang.syntax.elements.GivenMembersTest.DescribedRuleStart; +import static com.tngtech.archunit.lang.syntax.elements.GivenMembersTest.described; +import static com.tngtech.archunit.lang.syntax.elements.GivenMembersTest.everythingViolationPrintMemberName; import static com.tngtech.java.junit.dataprovider.DataProviders.$; import static com.tngtech.java.junit.dataprovider.DataProviders.$$; import static org.assertj.core.api.Assertions.assertThat; diff --git a/archunit/src/test/java/com/tngtech/archunit/library/modules/RandomModulesSyntaxTest.java b/archunit/src/test/java/com/tngtech/archunit/library/modules/RandomModulesSyntaxTest.java index 4a6265e495..4ce35507ab 100644 --- a/archunit/src/test/java/com/tngtech/archunit/library/modules/RandomModulesSyntaxTest.java +++ b/archunit/src/test/java/com/tngtech/archunit/library/modules/RandomModulesSyntaxTest.java @@ -92,7 +92,7 @@ public Parameter get(String methodName, TypeToken type) { new SingleParameterProvider(String.class) { @Override protected boolean canHandle(String methodName, Class type) { - return methodName.equals("respectTheirAllowedDependenciesDeclaredIn") && super.canHandle(methodName, type); + return "respectTheirAllowedDependenciesDeclaredIn".equals(methodName) && super.canHandle(methodName, type); } @Override @@ -104,7 +104,7 @@ public Parameter get(String methodName, TypeToken type) { @Override protected boolean canHandle(String methodName, Class type) { - return methodName.equals("onlyDependOnEachOtherThroughPackagesDeclaredIn") && super.canHandle(methodName, type); + return "onlyDependOnEachOtherThroughPackagesDeclaredIn".equals(methodName) && super.canHandle(methodName, type); } @Override diff --git a/archunit/src/test/java/com/tngtech/archunit/library/modules/syntax/ModulesShouldTest.java b/archunit/src/test/java/com/tngtech/archunit/library/modules/syntax/ModulesShouldTest.java index 93e6ce1887..ec7b2a5e21 100644 --- a/archunit/src/test/java/com/tngtech/archunit/library/modules/syntax/ModulesShouldTest.java +++ b/archunit/src/test/java/com/tngtech/archunit/library/modules/syntax/ModulesShouldTest.java @@ -79,9 +79,9 @@ public void respectTheirAllowedDependenciesDeclaredIn_takes_allowed_dependencies @Test public void respectTheirAllowedDependenciesDeclaredIn_works_together_with_filtering_by_predicate() { assertThatRule(modules().definedByAnnotation(TestModule.class) - .that(DescribedPredicate.describe("are not Module 1", it -> !it.getName().equals("Module 1"))) - .and(DescribedPredicate.describe("are not Module 2", it -> !it.getName().equals("Module 2"))) - .or(DescribedPredicate.describe("are Module 3", it -> it.getName().equals("Module 3"))) + .that(DescribedPredicate.describe("are not Module 1", it -> !"Module 1".equals(it.getName()))) + .and(DescribedPredicate.describe("are not Module 2", it -> !"Module 2".equals(it.getName()))) + .or(DescribedPredicate.describe("are Module 3", it -> "Module 3".equals(it.getName()))) .should().respectTheirAllowedDependenciesDeclaredIn("allowedDependencies", consideringOnlyDependenciesBetweenModules())) .checking(new ClassFileImporter().importPackagesOf(ClassInModule1.class, InternalClassInModule2.class, ClassInModule3.class)) .hasNoViolation(); diff --git a/archunit/src/test/java/com/tngtech/archunit/testutil/syntax/RandomSyntaxTestBase.java b/archunit/src/test/java/com/tngtech/archunit/testutil/syntax/RandomSyntaxTestBase.java index 7e2626c098..bc395797bd 100644 --- a/archunit/src/test/java/com/tngtech/archunit/testutil/syntax/RandomSyntaxTestBase.java +++ b/archunit/src/test/java/com/tngtech/archunit/testutil/syntax/RandomSyntaxTestBase.java @@ -350,7 +350,7 @@ public Parameter get(String methodName, TypeToken type) { || methodName.toLowerCase().contains("declared") || methodName.toLowerCase().contains("type")) { return new Parameter("some.Type", "some.Type"); - } else if (methodName.equals("be") || methodName.equals("notBe")) { + } else if ("be".equals(methodName) || "notBe".equals(methodName)) { return new Parameter("some.Type", "some.Type"); } else { return new Parameter("string", "'string'"); diff --git a/build.gradle b/build.gradle index 4b7e162f55..cdbf6e4d9b 100644 --- a/build.gradle +++ b/build.gradle @@ -1,10 +1,11 @@ plugins { id 'archunit.base-conventions' - id 'com.gradleup.shadow' version '8.3.9' apply false - id 'com.github.spotbugs' version '6.4.7' apply false - id "io.github.gradle-nexus.publish-plugin" version "2.0.0" apply false - id "com.diffplug.spotless" version "8.1.0" apply false + id 'com.diffplug.spotless' version '8.1.0' apply false id 'com.github.ben-manes.versions' version '0.53.0' apply false + id 'com.github.spotbugs' version '6.4.7' apply false + id 'com.gradleup.shadow' version '8.3.9' apply false + id 'io.github.gradle-nexus.publish-plugin' version '2.0.0' apply false + id 'org.openrewrite.rewrite' version '7.21.0' apply false } def appAndSourceUrl = 'https://github.com/TNG/ArchUnit' diff --git a/buildSrc/src/main/groovy/archunit.java-code-quality-conventions.gradle b/buildSrc/src/main/groovy/archunit.java-code-quality-conventions.gradle index 6fee7b4725..c914f1f896 100644 --- a/buildSrc/src/main/groovy/archunit.java-code-quality-conventions.gradle +++ b/buildSrc/src/main/groovy/archunit.java-code-quality-conventions.gradle @@ -1,23 +1,41 @@ plugins { id 'com.github.spotbugs' id 'com.diffplug.spotless' + id 'org.openrewrite.rewrite' +} +dependencies { + rewrite('org.openrewrite.recipe:rewrite-java-security:3.22.0') + rewrite('org.openrewrite.recipe:rewrite-migrate-java:3.22.0') + rewrite('org.openrewrite.recipe:rewrite-rewrite:0.16.0') + rewrite('org.openrewrite.recipe:rewrite-static-analysis:2.22.0') + rewrite('org.openrewrite.recipe:rewrite-testing-frameworks:3.22.0') + rewrite('org.openrewrite.recipe:rewrite-third-party:0.31.2') +} +rewrite { + activeRecipe('com.tngtech.archunit.openrewrite.SanityCheck') + configFile = project.getRootProject().file('buildSrc/src/main/resources/code_quality/rewrite.yml') + exclusions.addAll( + '**special-tests.gradle', + '**testlib/src/main/resources**' + ) + exportDatatables = true + failOnDryRunResults = true } - spotbugs { excludeFilter = rootProject.file('buildSrc/src/main/resources/code_quality/spotbugs-excludes.xml') } - spotbugsMain { reports { xml.enabled false html.enabled true } } - spotbugsTest.enabled = false - spotless { java { + // palantirJavaFormat() // might consider. + forbidWildcardImports() removeUnusedImports() + trimTrailingWhitespace() } } diff --git a/buildSrc/src/main/resources/code_quality/rewrite.yml b/buildSrc/src/main/resources/code_quality/rewrite.yml new file mode 100644 index 0000000000..c227f18e18 --- /dev/null +++ b/buildSrc/src/main/resources/code_quality/rewrite.yml @@ -0,0 +1,14 @@ +--- +type: specs.openrewrite.org/v1beta/recipe +name: com.tngtech.archunit.openrewrite.SanityCheck +displayName: Apply all common best practices +description: Comprehensive code quality recipe combining modernization, security, and best practices. +recipeList: + - org.openrewrite.staticanalysis.EqualsAvoidsNull + - tech.picnic.errorprone.refasterrules.TimeRulesRecipes +# - org.openrewrite.java.testing.assertj.Assertj +# - org.openrewrite.java.testing.junit.JupiterBestPractices +# - tech.picnic.errorprone.refasterrules.JUnitRulesRecipes +# - tech.picnic.errorprone.refasterrules.JUnitToAssertJRulesRecipes +# - tech.picnic.errorprone.refasterrules.StreamRulesRecipes +--- diff --git a/rewrite.yml b/rewrite.yml new file mode 100644 index 0000000000..371d838682 --- /dev/null +++ b/rewrite.yml @@ -0,0 +1,69 @@ +--- +type: specs.openrewrite.org/v1beta/recipe +name: com.tngtech.archunit.openrewrite.SanityCheck +displayName: Apply all common best practices +description: Comprehensive code quality recipe combining modernization, security, and best practices. +recipeList: + - org.openrewrite.gradle.EnableGradleBuildCache + - org.openrewrite.gradle.EnableGradleParallelExecution + - org.openrewrite.gradle.GradleBestPractices + - org.openrewrite.java.RemoveUnusedImports + - org.openrewrite.java.format.NormalizeFormat + - org.openrewrite.java.format.NormalizeLineBreaks + - org.openrewrite.java.format.RemoveTrailingWhitespace + - org.openrewrite.java.migrate.UpgradeToJava21 + - org.openrewrite.java.migrate.lang.StringRulesRecipes + - org.openrewrite.java.migrate.util.JavaLangAPIs + - org.openrewrite.java.migrate.util.JavaUtilAPIs + - org.openrewrite.java.migrate.util.MigrateInflaterDeflaterToClose + - org.openrewrite.java.migrate.util.ReplaceStreamCollectWithToList + - org.openrewrite.java.migrate.util.SequencedCollection + - org.openrewrite.java.recipes.JavaRecipeBestPractices + - org.openrewrite.java.recipes.RecipeTestingBestPractices + - org.openrewrite.java.security.JavaSecurityBestPractices + - org.openrewrite.java.testing.archunit.ArchUnit0to1Migration + - org.openrewrite.java.testing.assertj.Assertj + - org.openrewrite.java.testing.cleanup.BestPractices + - org.openrewrite.java.testing.junit.JupiterBestPractices + - org.openrewrite.java.testing.junit5.CleanupAssertions + - org.openrewrite.java.testing.junit5.JUnit5BestPractices + - org.openrewrite.staticanalysis.BufferedWriterCreationRecipes + - org.openrewrite.staticanalysis.CodeCleanup + - org.openrewrite.staticanalysis.CommonStaticAnalysis + - org.openrewrite.staticanalysis.EqualsAvoidsNull + - org.openrewrite.staticanalysis.JavaApiBestPractices + - org.openrewrite.staticanalysis.LowercasePackage + - org.openrewrite.staticanalysis.MissingOverrideAnnotation + - org.openrewrite.staticanalysis.ModifierOrder + - org.openrewrite.staticanalysis.NoFinalizer + - org.openrewrite.staticanalysis.NoToStringOnStringType + - org.openrewrite.staticanalysis.NoValueOfOnStringType + - org.openrewrite.staticanalysis.RemoveUnusedLocalVariables + - org.openrewrite.staticanalysis.RemoveUnusedPrivateFields + - org.openrewrite.staticanalysis.RemoveUnusedPrivateMethods + - org.openrewrite.staticanalysis.SimplifyTernaryRecipes + - org.openrewrite.staticanalysis.URLEqualsHashCodeRecipes + - org.openrewrite.staticanalysis.UnnecessaryCloseInTryWithResources + - org.openrewrite.staticanalysis.UnnecessaryExplicitTypeArguments + - org.openrewrite.staticanalysis.UnnecessaryParentheses + - org.openrewrite.staticanalysis.UnnecessaryReturnAsLastStatement + - tech.picnic.errorprone.refasterrules.BigDecimalRulesRecipes + - tech.picnic.errorprone.refasterrules.CharSequenceRulesRecipes + - tech.picnic.errorprone.refasterrules.ClassRulesRecipes + - tech.picnic.errorprone.refasterrules.CollectionRulesRecipes + - tech.picnic.errorprone.refasterrules.ComparatorRulesRecipes + - tech.picnic.errorprone.refasterrules.EqualityRulesRecipes + - tech.picnic.errorprone.refasterrules.FileRulesRecipes + - tech.picnic.errorprone.refasterrules.JUnitRulesRecipes + - tech.picnic.errorprone.refasterrules.MapRulesRecipes + - tech.picnic.errorprone.refasterrules.MicrometerRulesRecipes + - tech.picnic.errorprone.refasterrules.MockitoRulesRecipes + - tech.picnic.errorprone.refasterrules.NullRulesRecipes + - tech.picnic.errorprone.refasterrules.OptionalRulesRecipes + - tech.picnic.errorprone.refasterrules.PatternRulesRecipes + - tech.picnic.errorprone.refasterrules.PreconditionsRulesRecipes + - tech.picnic.errorprone.refasterrules.PrimitiveRulesRecipes + - tech.picnic.errorprone.refasterrules.StreamRulesRecipes + - tech.picnic.errorprone.refasterrules.StringRulesRecipes + - tech.picnic.errorprone.refasterrules.TimeRulesRecipes +---