diff --git a/gradle/error-prone.gradle b/gradle/error-prone.gradle index 1a6feba6f8..8b73fdbe4e 100644 --- a/gradle/error-prone.gradle +++ b/gradle/error-prone.gradle @@ -5,30 +5,88 @@ apply plugin: 'net.ltgt.errorprone' dependencies { errorprone('com.google.errorprone:error_prone_core:2.42.0') errorprone('tech.picnic.error-prone-support:error-prone-contrib:0.25.0') - constraints { - errorprone('com.google.guava:guava') { - version { - require('33.4.8-jre') - } - because('Older versions use deprecated methods in sun.misc.Unsafe') - // https://github.com/junit-team/junit-framework/pull/5039#discussion_r2414490581 - } - } } tasks.withType(JavaCompile).configureEach { options.errorprone { - disableAllChecks = true // consider removal to avoid error prone error“s, following convention over configuration. + disable( // not patchable + 'FormatStringConcatenation', + 'FunctionalInterfaceMethodChanged', + 'JavaxInjectOnAbstractMethod', + 'OverridesJavaxInjectableMethod', + 'ReturnValueIgnored', + 'Slf4jLogStatement', + 'MissingSummary', + // patchable + 'LexicographicalAnnotationAttributeListing', + 'LexicographicalAnnotationListing', + 'NonStaticImport', + 'Slf4jLoggerDeclaration', // logger -> log + 'StaticImport', + // critical, finds lots of bugs... unused configs and stuff. + 'Unused', + 'UnusedMethod', + 'UnusedParameters', + 'UnusedVariable', + ) error( + 'AmbiguousJsonCreator', + 'AssertJNullnessAssertion', + 'AutowiredConstructor', + 'CanonicalAnnotationSyntax', + 'CollectorMutability', 'ConstantNaming', + 'DirectReturn', + 'EmptyMethod', + 'ExplicitArgumentEnumeration', + 'ExplicitEnumOrdering', + 'IdentityConversion', + 'ImmutablesSortedSetComparator', + 'IsInstanceLambdaUsage', + 'MockitoMockClassReference', + 'MockitoStubbing', + 'NestedOptionals', + 'PrimitiveComparison', 'RedundantStringConversion', + 'RedundantStringEscape', + 'SelfAssignment', + 'StringJoin', + 'StringJoining', ) + // fixme bug: this only happens when the file is dirty! + // up2date checking (caching) must consider file changes, as file is currently corrupt! + // fix SelfTest.java:L22 ForbidGradleInternal(import org.gradle.api.internal.project.ProjectInternal;) + errorproneArgs.add('-XepExcludedPaths:.*/SelfTest.java') if (!getenv().containsKey('CI') && getenv('IN_PLACE')?.toBoolean()) { errorproneArgs.addAll( '-XepPatchLocation:IN_PLACE', '-XepPatchChecks:' + + 'AmbiguousJsonCreator,' + + 'ArrayEquals,' + + 'AssertJNullnessAssertion,' + + 'AutowiredConstructor,' + + 'CanonicalAnnotationSyntax,' + + 'CollectorMutability,' + 'ConstantNaming,' + - 'RedundantStringConversion,' + 'DirectReturn,' + + 'EmptyMethod,' + + 'ExplicitArgumentEnumeration,' + + 'ExplicitEnumOrdering,' + + 'FormatStringConcatenation,' + + 'IdentityConversion,' + + 'ImmutablesSortedSetComparator,' + + 'IsInstanceLambdaUsage,' + + 'MockitoMockClassReference,' + + 'MockitoStubbing,' + + 'NestedOptionals,' + + 'PrimitiveComparison,' + + 'RedundantStringConversion,' + + 'RedundantStringEscape,' + + 'SelfAssignment,' + + 'Slf4jLogStatement,' + + 'StringJoin,' + + 'StringJoining,' + + 'TimeZoneUsage,' ) } } diff --git a/gradle/rewrite.gradle b/gradle/rewrite.gradle index 4464ee652c..9f75f75e96 100644 --- a/gradle/rewrite.gradle +++ b/gradle/rewrite.gradle @@ -2,7 +2,6 @@ apply plugin: 'org.openrewrite.rewrite' rewrite { activeRecipe('com.diffplug.spotless.openrewrite.SanityCheck') - activeStyle('com.diffplug.spotless.openrewrite.SpotlessFormat') exclusions.addAll( '**.dirty.java', '**FormatterProperties.java', diff --git a/lib-extra/src/test/java/com/diffplug/spotless/extra/java/EclipseJdtEqualityTest.java b/lib-extra/src/test/java/com/diffplug/spotless/extra/java/EclipseJdtEqualityTest.java index c842337b3e..18349b046e 100644 --- a/lib-extra/src/test/java/com/diffplug/spotless/extra/java/EclipseJdtEqualityTest.java +++ b/lib-extra/src/test/java/com/diffplug/spotless/extra/java/EclipseJdtEqualityTest.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 DiffPlug + * Copyright 2024-2025 DiffPlug * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -20,6 +20,7 @@ import java.io.IOException; import java.io.ObjectOutputStream; import java.io.Serializable; +import java.util.Arrays; import java.util.List; import org.junit.jupiter.api.Assertions; @@ -43,7 +44,7 @@ public void test() throws Exception { var serialized1 = toBytes(step1); var serialized2 = toBytes(step2); - Assertions.assertFalse(serialized1.equals(serialized2)); + Assertions.assertFalse(Arrays.equals(serialized1, serialized2)); } private static FormatterStep withSettingsFile(File settingsFile) { diff --git a/lib/src/compatKtLint0Dot48Dot0/java/com/diffplug/spotless/glue/ktlint/compat/KtLintCompat0Dot48Dot0Adapter.java b/lib/src/compatKtLint0Dot48Dot0/java/com/diffplug/spotless/glue/ktlint/compat/KtLintCompat0Dot48Dot0Adapter.java index 78bd28f86b..ce1a21d69d 100644 --- a/lib/src/compatKtLint0Dot48Dot0/java/com/diffplug/spotless/glue/ktlint/compat/KtLintCompat0Dot48Dot0Adapter.java +++ b/lib/src/compatKtLint0Dot48Dot0/java/com/diffplug/spotless/glue/ktlint/compat/KtLintCompat0Dot48Dot0Adapter.java @@ -1,5 +1,5 @@ /* - * Copyright 2023-2024 DiffPlug + * Copyright 2023-2025 DiffPlug * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -115,7 +115,7 @@ public String format( private static EditorConfigOverride createEditorConfigOverride(final List rules, Map editorConfigOverrideMap) { // Get properties from rules in the rule sets Stream> ruleProperties = rules.stream() - .filter(rule -> rule instanceof UsesEditorConfigProperties) + .filter(UsesEditorConfigProperties.class::isInstance) .flatMap(rule -> ((UsesEditorConfigProperties) rule).getEditorConfigProperties().stream()); // Create a mapping of properties to their names based on rule properties and default properties diff --git a/lib/src/main/java/com/diffplug/spotless/PaddedCell.java b/lib/src/main/java/com/diffplug/spotless/PaddedCell.java index 18fb44acbb..f6973a6daa 100644 --- a/lib/src/main/java/com/diffplug/spotless/PaddedCell.java +++ b/lib/src/main/java/com/diffplug/spotless/PaddedCell.java @@ -153,7 +153,7 @@ public String canonical() { // @formatter:off switch (type) { case CONVERGE: return steps.get(steps.size() - 1); - case CYCLE: return Collections.min(steps, Comparator.comparing(String::length).thenComparing(Function.identity())); + case CYCLE: return Collections.min(steps, Comparator.comparingInt(String::length).thenComparing(Function.identity())); case DIVERGE: throw new IllegalArgumentException("No canonical form for a diverging result"); default: throw new IllegalArgumentException("Unknown type: " + type); } diff --git a/lib/src/main/java/com/diffplug/spotless/biome/BiomeStep.java b/lib/src/main/java/com/diffplug/spotless/biome/BiomeStep.java index 2f80fba8f4..848481e07e 100644 --- a/lib/src/main/java/com/diffplug/spotless/biome/BiomeStep.java +++ b/lib/src/main/java/com/diffplug/spotless/biome/BiomeStep.java @@ -25,7 +25,6 @@ import java.nio.file.attribute.PosixFilePermission; import java.util.ArrayList; import java.util.HashSet; -import java.util.Set; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -299,7 +298,7 @@ private State createState() throws IOException, InterruptedException { validateBiomeExecutable(resolvedPathToExe); validateBiomeConfigPath(configPath, version); LOGGER.debug("Using Biome executable located at '{}'", resolvedPathToExe); - var exeSignature = FileSignature.signAsList(Set.of(new File(resolvedPathToExe))); + var exeSignature = FileSignature.signAsList(new File(resolvedPathToExe)); makeExecutable(resolvedPathToExe); return new State(resolvedPathToExe, exeSignature, configPath, language); } diff --git a/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/GitRatchetGradleTest.java b/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/GitRatchetGradleTest.java index e4c1d31615..0e3cb3f283 100644 --- a/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/GitRatchetGradleTest.java +++ b/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/GitRatchetGradleTest.java @@ -1,5 +1,5 @@ /* - * Copyright 2016-2024 DiffPlug + * Copyright 2016-2025 DiffPlug * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -58,7 +58,7 @@ public GradleRunner gradleRunner() throws IOException { @ParameterizedTest //@ValueSource(ints = {0, 1}) // TODO: this is a flaky configuration cache issue that started with Gradle 8.5 - @ValueSource(ints = {0}) + @ValueSource(ints = 0) void singleProjectExhaustive(int useConfigCache) throws Exception { try (Git git = initRepo()) { if (useConfigCache == 1) { @@ -158,7 +158,7 @@ private BuildResultAssertion assertFail(String... tasks) throws Exception { @ParameterizedTest //@ValueSource(ints = {0, 1}) // TODO: this is a flaky configuration cache issue that started with Gradle 8.5 - @ValueSource(ints = {0}) + @ValueSource(ints = 0) void multiProject(int useConfigCache) throws Exception { try (Git git = initRepo()) { if (useConfigCache == 1) { diff --git a/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/SpotlessTaskImplTest.java b/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/SpotlessTaskImplTest.java index ad2ae7c5aa..1b3a44a109 100644 --- a/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/SpotlessTaskImplTest.java +++ b/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/SpotlessTaskImplTest.java @@ -29,17 +29,17 @@ public class SpotlessTaskImplTest { @Test public void testThrowsMessageContainsFilename() throws Exception { - SpotlessTaskImpl task = Mockito.mock(SpotlessTaskImpl.class, Mockito.CALLS_REAL_METHODS); + SpotlessTaskImpl task = Mockito.mock(Mockito.CALLS_REAL_METHODS); Mockito.when(task.getLogger()).thenReturn(Mockito.mock(Logger.class)); File projectDir = Path.of("unitTests", "projectDir").toFile(); - DirectoryProperty projectDirProperty = Mockito.mock(DirectoryProperty.class, Mockito.RETURNS_DEEP_STUBS); + DirectoryProperty projectDirProperty = Mockito.mock(Mockito.RETURNS_DEEP_STUBS); Mockito.when(projectDirProperty.get().getAsFile()).thenReturn(projectDir); Mockito.when(task.getProjectDir()).thenReturn(projectDirProperty); File input = Path.of("unitTests", "projectDir", "someInput").toFile(); - Formatter formatter = Mockito.mock(Formatter.class); + Formatter formatter = Mockito.mock(); Assertions.assertThatThrownBy(() -> task.processInputFile(null, formatter, input, "someInput")).hasMessageContaining(input.toString()); } diff --git a/plugin-maven/src/test/java/com/diffplug/spotless/maven/FileLocatorTest.java b/plugin-maven/src/test/java/com/diffplug/spotless/maven/FileLocatorTest.java index 1e28359a3b..279ccff887 100644 --- a/plugin-maven/src/test/java/com/diffplug/spotless/maven/FileLocatorTest.java +++ b/plugin-maven/src/test/java/com/diffplug/spotless/maven/FileLocatorTest.java @@ -40,7 +40,7 @@ class FileLocatorTest extends ResourceHarness { @BeforeEach void beforeEach() { - resourceManager = mock(ResourceManager.class); + resourceManager = mock(); fileLocator = new FileLocator(resourceManager, rootFolder(), rootFolder()); } diff --git a/plugin-maven/src/test/java/com/diffplug/spotless/maven/incremental/FileIndexHarness.java b/plugin-maven/src/test/java/com/diffplug/spotless/maven/incremental/FileIndexHarness.java index 8260038efa..087b8717f0 100644 --- a/plugin-maven/src/test/java/com/diffplug/spotless/maven/incremental/FileIndexHarness.java +++ b/plugin-maven/src/test/java/com/diffplug/spotless/maven/incremental/FileIndexHarness.java @@ -1,5 +1,5 @@ /* - * Copyright 2021 DiffPlug + * Copyright 2021-2025 DiffPlug * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -35,8 +35,8 @@ abstract class FileIndexHarness { protected static final PluginFingerprint FINGERPRINT = PluginFingerprint.from("foo"); - protected final FileIndexConfig config = mock(FileIndexConfig.class); - protected final Log log = mock(Log.class); + protected final FileIndexConfig config = mock(); + protected final Log log = mock(); protected Path tempDir; diff --git a/plugin-maven/src/test/java/com/diffplug/spotless/maven/incremental/NoopCheckerTest.java b/plugin-maven/src/test/java/com/diffplug/spotless/maven/incremental/NoopCheckerTest.java index 4025d5b271..ff67fffb57 100644 --- a/plugin-maven/src/test/java/com/diffplug/spotless/maven/incremental/NoopCheckerTest.java +++ b/plugin-maven/src/test/java/com/diffplug/spotless/maven/incremental/NoopCheckerTest.java @@ -1,5 +1,5 @@ /* - * Copyright 2021-2024 DiffPlug + * Copyright 2021-2025 DiffPlug * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -59,7 +59,7 @@ void beforeEach() throws Exception { @Test void deletesExistingIndexFileWhenCreated() { - Log log = mock(Log.class); + Log log = mock(); try (UpToDateChecker realChecker = UpToDateChecker.forProject(project, indexFile, singletonList(dummyFormatter()), log)) { realChecker.setUpToDate(existingSourceFile); } @@ -76,7 +76,7 @@ void deletesExistingIndexFileWhenCreated() { void doesNothingWhenIndexFileDoesNotExist() { assertThat(indexFile).doesNotExist(); - Log log = mock(Log.class); + Log log = mock(); try (UpToDateChecker noopChecker = UpToDateChecker.noop(project, indexFile, log)) { assertThat(noopChecker).isNotNull(); } diff --git a/rewrite.yml b/rewrite.yml index 627b4f2bd5..00f05a6fa4 100644 --- a/rewrite.yml +++ b/rewrite.yml @@ -66,28 +66,3 @@ recipeList: - tech.picnic.errorprone.refasterrules.TimeRulesRecipes # - org.openrewrite.java.migrate.lang.FindVirtualThreadOpportunities # don't want to use: https://github.com/diffplug/spotless/pull/2684#discussion_r2433831887 --- -name: com.diffplug.spotless.openrewrite.SpotlessFormat -styleConfigs: - - org.openrewrite.java.style.ImportLayoutStyle: - classCountToUseStarImport: 999 - nameCountToUseStarImport: 999 - # bug https://github.com/openrewrite/rewrite/issues/6107 - # layout: - # - import java.* - # - - # - import javax.* - # - - # - import org.* - # - - # - import com.* - # - - # - import com.diffplug.* - # - - # - import static all other imports - # - - # - import all other imports - # - - - org.openrewrite.java.style.TabsAndIndentsStyle: - useTabCharacter: true - tabSize: 4 ---- diff --git a/settings.gradle b/settings.gradle index f8e4a141c3..7c6a7f9873 100644 --- a/settings.gradle +++ b/settings.gradle @@ -1,3 +1,5 @@ +import static java.lang.System.getenv + pluginManagement { repositories { mavenCentral() @@ -6,25 +8,17 @@ pluginManagement { } plugins { + id 'com.adarshr.test-logger' version '4.0.0' apply false // https://github.com/radarsh/gradle-test-logger-plugin/blob/develop/CHANGELOG.md id 'com.diffplug.spotless' version '8.0.0' apply false - // https://plugins.gradle.org/plugin/com.gradle.plugin-publish - id 'com.gradle.plugin-publish' version '2.0.0' apply false - // https://github.com/gradle-nexus/publish-plugin/releases - id 'io.github.gradle-nexus.publish-plugin' version '2.0.0' apply false - // https://github.com/spotbugs/spotbugs-gradle-plugin/releases - id 'com.github.spotbugs' version '6.4.4' apply false - // https://github.com/diffplug/spotless-changelog/blob/main/CHANGELOG.md - id 'com.diffplug.spotless-changelog' version '3.1.2' apply false - // https://github.com/radarsh/gradle-test-logger-plugin/blob/develop/CHANGELOG.md - id 'com.adarshr.test-logger' version '4.0.0' apply false - // https://github.com/davidburstrom/version-compatibility-gradle-plugin/tags - id 'io.github.davidburstrom.version-compatibility' version '0.5.0' apply false - // https://plugins.gradle.org/plugin/com.gradle.develocity - id 'com.gradle.develocity' version '4.2.2' - // https://github.com/equodev/equo-ide/blob/main/plugin-gradle/CHANGELOG.md - id 'dev.equo.ide' version '1.7.8' apply false - id 'org.openrewrite.rewrite' version '7.18.0' apply false + id 'com.diffplug.spotless-changelog' version '3.1.2' apply false // https://github.com/diffplug/spotless-changelog/blob/main/CHANGELOG.md + id 'com.github.spotbugs' version '6.4.4' apply false // https://github.com/spotbugs/spotbugs-gradle-plugin/releases + id 'com.gradle.develocity' version '4.2.2' // https://plugins.gradle.org/plugin/com.gradle.develocity + id 'com.gradle.plugin-publish' version '2.0.0' apply false // https://plugins.gradle.org/plugin/com.gradle.plugin-publish + id 'dev.equo.ide' version '1.7.8' apply false // https://github.com/equodev/equo-ide/blob/main/plugin-gradle/CHANGELOG.md + id 'io.github.davidburstrom.version-compatibility' version '0.5.0' apply false // https://github.com/davidburstrom/version-compatibility-gradle-plugin/tags + id 'io.github.gradle-nexus.publish-plugin' version '2.0.0' apply false // https://github.com/gradle-nexus/publish-plugin/releases id 'net.ltgt.errorprone' version '4.3.0' apply false + id 'org.openrewrite.rewrite' version '7.18.0' apply false } dependencyResolutionManagement { @@ -61,14 +55,12 @@ if (System.env['CI'] != null) { } } -def isCI = providers.environmentVariable('CI').present - develocity { buildScan { termsOfUseUrl = "https://gradle.com/terms-of-service" termsOfUseAgree = "yes" publishing { - onlyIf { isCI } + onlyIf { providers.environmentVariable('CI').present } } } } @@ -78,26 +70,25 @@ enableFeaturePreview("TYPESAFE_PROJECT_ACCESSORS") rootProject.name = 'spotless' -include 'lib' // reusable library with no dependencies -include 'testlib' // library for sharing test infrastructure between the projects below - +include 'lib' // reusable library with no dependencies include 'lib-extra' // reusable library with lots of dependencies include 'plugin-gradle' // gradle-specific glue code +include 'testlib' // library for sharing test infrastructure between the projects below -def getStartProperty(java.lang.String name) { +def getStartProperty(String name) { def value = startParameter.getProjectProperties().get(name) if(null != value) { return value } // user properties are not available in the startParameter - def userPropertiesFile = new java.io.File(startParameter.getGradleUserHomeDir(), 'gradle.properties') - def userProperties = new java.util.Properties() + def userPropertiesFile = new File(startParameter.getGradleUserHomeDir(), 'gradle.properties') + def userProperties = new Properties() if (userPropertiesFile.exists()) { userProperties.load(userPropertiesFile.newReader()) } return userProperties.get(name) } -if (System.getenv('SPOTLESS_EXCLUDE_MAVEN') != 'true' && getStartProperty('SPOTLESS_EXCLUDE_MAVEN') != 'true') { - include 'plugin-maven' // maven-specific glue code +if (!getenv('SPOTLESS_EXCLUDE_MAVEN')?.toBoolean() && !Boolean.valueOf(getStartProperty('SPOTLESS_EXCLUDE_MAVEN') as String)) { + include 'plugin-maven' // maven-specific glue code }