Skip to content
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
80 changes: 69 additions & 11 deletions gradle/error-prone.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

seems like we dont need this to pass prone convention.

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,'
)
}
}
Expand Down
1 change: 0 additions & 1 deletion gradle/rewrite.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down
Original file line number Diff line number Diff line change
@@ -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.
Expand All @@ -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;
Expand All @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
@@ -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.
Expand Down Expand Up @@ -115,7 +115,7 @@ public String format(
private static EditorConfigOverride createEditorConfigOverride(final List<Rule> rules, Map<String, Object> editorConfigOverrideMap) {
// Get properties from rules in the rule sets
Stream<EditorConfigProperty<?>> 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
Expand Down
2 changes: 1 addition & 1 deletion lib/src/main/java/com/diffplug/spotless/PaddedCell.java
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
3 changes: 1 addition & 2 deletions lib/src/main/java/com/diffplug/spotless/biome/BiomeStep.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -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.
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ class FileLocatorTest extends ResourceHarness {

@BeforeEach
void beforeEach() {
resourceManager = mock(ResourceManager.class);
resourceManager = mock();
fileLocator = new FileLocator(resourceManager, rootFolder(), rootFolder());
}

Expand Down
Original file line number Diff line number Diff line change
@@ -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.
Expand Down Expand Up @@ -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;

Expand Down
Original file line number Diff line number Diff line change
@@ -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.
Expand Down Expand Up @@ -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);
}
Expand All @@ -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();
}
Expand Down
25 changes: 0 additions & 25 deletions rewrite.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

imho no recipe uses the style, also this fully covered by spotless so actually no need to keep.

styleConfigs:
- org.openrewrite.java.style.ImportLayoutStyle:
classCountToUseStarImport: 999
nameCountToUseStarImport: 999
# bug https://github.com/openrewrite/rewrite/issues/6107
# layout:
# - import java.*
# - <blank line>
# - import javax.*
# - <blank line>
# - import org.*
# - <blank line>
# - import com.*
# - <blank line>
# - import com.diffplug.*
# - <blank line>
# - import static all other imports
# - <blank line>
# - import all other imports
# - <blank line>
- org.openrewrite.java.style.TabsAndIndentsStyle:
useTabCharacter: true
tabSize: 4
---
47 changes: 19 additions & 28 deletions settings.gradle
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import static java.lang.System.getenv

pluginManagement {
repositories {
mavenCentral()
Expand All @@ -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 {
Expand Down Expand Up @@ -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 }
}
}
}
Expand All @@ -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
}
Loading