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
65 changes: 11 additions & 54 deletions gradle/error-prone.gradle
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import static java.lang.System.getenv

apply plugin: 'net.ltgt.errorprone'

dependencies {
Expand All @@ -9,25 +7,10 @@ dependencies {

tasks.withType(JavaCompile).configureEach {
options.errorprone {
disable( // not patchable
'FormatStringConcatenation',
disable( // consider fix, or reasoning.
'FunctionalInterfaceMethodChanged',
'JavaxInjectOnAbstractMethod',
'OverridesJavaxInjectableMethod',
'ReturnValueIgnored',
'Slf4jLogStatement',
'MissingSummary',
// patchable
'LexicographicalAnnotationAttributeListing',
Copy link
Contributor Author

Choose a reason for hiding this comment

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

now its working as we have enabled convention. the warnings does not break the build somehow.

'LexicographicalAnnotationListing',
'NonStaticImport',
'Slf4jLoggerDeclaration', // logger -> log
'StaticImport',
// critical, finds lots of bugs... unused configs and stuff.
Copy link
Contributor Author

Choose a reason for hiding this comment

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

too much risk and too big. Some extension maven stuff might be unused in code but break on production.

'Unused',
'UnusedMethod',
'UnusedParameters',
'UnusedVariable',
)
error(
'AmbiguousJsonCreator',
Expand All @@ -49,45 +32,19 @@ tasks.withType(JavaCompile).configureEach {
'PrimitiveComparison',
'RedundantStringConversion',
'RedundantStringEscape',
'ReturnValueIgnored',
'SelfAssignment',
'StringJoin',
'StringJoining',
'UnnecessarilyFullyQualified',
'UnnecessaryLambda',
)
// bug: this only happens when the file is dirty.
// might be an up2date (caching) issue, as file is currently in corrupt state.
// ForbidGradleInternal(import org.gradle.api.internal.project.ProjectInternal;)
errorproneArgs.add('-XepExcludedPaths:' +
'.*/SelfTest.java|' +
'.*/GradleIntegrationHarness.java'
)
// 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,' +
'DirectReturn,' +
'EmptyMethod,' +
'ExplicitArgumentEnumeration,' +
'ExplicitEnumOrdering,' +
'FormatStringConcatenation,' +
'IdentityConversion,' +
'ImmutablesSortedSetComparator,' +
'IsInstanceLambdaUsage,' +
'MockitoMockClassReference,' +
'MockitoStubbing,' +
'NestedOptionals,' +
'PrimitiveComparison,' +
'RedundantStringConversion,' +
'RedundantStringEscape,' +
'SelfAssignment,' +
'Slf4jLogStatement,' +
'StringJoin,' +
'StringJoining,' +
'TimeZoneUsage,'
)
}
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2016-2023 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 All @@ -21,6 +21,7 @@
import java.util.stream.Collectors;
import java.util.stream.Stream;

import org.eclipse.cdt.core.ToolFactory;
import org.eclipse.cdt.core.formatter.CodeFormatter;
import org.eclipse.jface.text.Document;
import org.eclipse.jface.text.IDocument;
Expand All @@ -35,7 +36,7 @@ public EclipseCdtFormatterStepImpl(Properties settings) throws Exception {
Map<String, String> settingsMap = stream.collect(Collectors.toMap(
e -> String.valueOf(e.getKey()),
e -> String.valueOf(e.getValue())));
codeFormatter = org.eclipse.cdt.core.ToolFactory.createDefaultCodeFormatter(settingsMap);
codeFormatter = ToolFactory.createDefaultCodeFormatter(settingsMap);
}

/** Formatting C/C++ string */
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 @@ -85,7 +85,7 @@ void policyTest() {
setFile(".gitattributes").toContent(StringPrinter.buildStringFromLines(
"* eol=lf",
"*.MF eol=crlf"));
LineEnding.Policy policy = LineEnding.GIT_ATTRIBUTES.createPolicy(rootFolder(), () -> testFiles());
LineEnding.Policy policy = LineEnding.GIT_ATTRIBUTES.createPolicy(rootFolder(), this::testFiles);
Assertions.assertThat(policy.getEndingFor(newFile("someFile"))).isEqualTo("\n");
Assertions.assertThat(policy.getEndingFor(newFile("subfolder/someFile"))).isEqualTo("\n");
Assertions.assertThat(policy.getEndingFor(newFile("MANIFEST.MF"))).isEqualTo("\r\n");
Expand All @@ -100,7 +100,7 @@ void policyDefaultLineEndingTest() throws GitAPIException {
"[core]",
"autocrlf=true",
"eol=lf"));
LineEnding.Policy policy = LineEnding.GIT_ATTRIBUTES.createPolicy(rootFolder(), () -> testFiles());
LineEnding.Policy policy = LineEnding.GIT_ATTRIBUTES.createPolicy(rootFolder(), this::testFiles);
Assertions.assertThat(policy.getEndingFor(newFile("someFile"))).isEqualTo("\r\n");
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2016-2021 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 All @@ -15,6 +15,8 @@
*/
package com.diffplug.gradle.spotless;

import static org.assertj.core.api.Assertions.assertThat;

import java.nio.charset.Charset;

import org.junit.jupiter.api.Test;
Expand Down Expand Up @@ -51,7 +53,7 @@ void globalIsRespected() throws Exception {
" encoding 'US-ASCII'",
"}");
setFile("test.java").toContent("µ");
gradleRunner().withArguments("spotlessApply").buildAndFail().getOutput().contains("Encoding error!");
Copy link
Contributor Author

Choose a reason for hiding this comment

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

use or loose. Should we check this or adapt the test by removing or inverting this?

Should we extract the ReturnValueIgnored recipe?

Copy link
Member

Choose a reason for hiding this comment

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

I am baffled by this one. The old test was wrong, but the new one looks wrong too. It would be nice to make this test better while we're in here, but I don't want it to hold up the rest.

assertThat(gradleRunner().withArguments("spotlessApply").buildAndFail().getOutput()).doesNotContain("Encoding error!");
assertFile("test.java").hasContent("µ");
}

Expand All @@ -75,7 +77,7 @@ void globalIsRespectedButCanBeOverridden() throws Exception {
"}");
setFile("test.java").toContent("µ");
setFile("utf32.encoded").toContent("µ", Charset.forName("UTF-32"));
gradleRunner().withArguments("spotlessApply").buildAndFail().getOutput().contains("Encoding error!");
assertThat(gradleRunner().withArguments("spotlessApply").buildAndFail().getOutput()).doesNotContain("Encoding error!");
assertFile("test.java").hasContent("µ");
assertFile("utf32.encoded").hasContent("µ", Charset.forName("UTF-32"));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ public Set<File> resolve(boolean withTransitives, Collection<String> mavenCoordi
excludeTransitive.add(EXCLUDE_ALL_TRANSITIVES);
}
List<Dependency> dependencies = mavenCoordinates.stream()
.map(coordinateString -> new DefaultArtifact(coordinateString))
.map(DefaultArtifact::new)
.map(artifact -> new Dependency(artifact, null, null, excludeTransitive))
.collect(toList());
CollectRequest collectRequest = new CollectRequest(dependencies, null, repositories);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -143,19 +143,16 @@ public static Provisioner mavenCentral() {
return MAVEN_CENTRAL.get();
}

private static final Supplier<Provisioner> MAVEN_CENTRAL = Suppliers.memoize(() -> caching("mavenCentral", () -> createWithRepositories(repo -> repo.mavenCentral())));
private static final Supplier<Provisioner> MAVEN_CENTRAL = Suppliers.memoize(() -> caching("mavenCentral", () -> createWithRepositories(RepositoryHandler::mavenCentral)));

/** Creates a Provisioner for the local maven repo for development purpose. */
public static Provisioner mavenLocal() {
return MAVEN_LOCAL.get();
return createWithRepositories(RepositoryHandler::mavenLocal);
}

private static final Supplier<Provisioner> MAVEN_LOCAL = () -> createWithRepositories(repo -> repo.mavenLocal());

/** Creates a Provisioner for the Sonatype snapshots maven repo for development purpose. */
public static Provisioner snapshots() {
return SNAPSHOTS.get();
return createWithRepositories(repo -> repo.maven(setup -> setup.setUrl("https://oss.sonatype.org/content/repositories/snapshots")));
}

private static final Supplier<Provisioner> SNAPSHOTS = () -> createWithRepositories(repo -> repo.maven(setup -> setup.setUrl("https://oss.sonatype.org/content/repositories/snapshots")));
}
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,7 @@ public FormatterSettingsAssert(FormatterProperties actual) {

/** Check that the values form all valid files are part of the settings properties. */
public FormatterSettingsAssert containsSpecificValuesOf(Collection<File> files) {
files.forEach(file -> containsSpecificValuesOf(file));
files.forEach(this::containsSpecificValuesOf);
return this;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import java.io.File;
import java.util.Arrays;

import org.jetbrains.annotations.Nullable;
import org.junit.jupiter.api.Test;

import com.diffplug.common.base.StringPrinter;
Expand Down Expand Up @@ -132,7 +133,7 @@ public String getName() {
return uppercase ? "uppercase" : "lowercase";
}

@org.jetbrains.annotations.Nullable @Override
@Nullable @Override
public String format(String rawUnix, File file) throws Exception {
return uppercase ? rawUnix.toUpperCase() : rawUnix.toLowerCase();
}
Expand Down
Loading