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
9 changes: 7 additions & 2 deletions gradle/error-prone.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,16 @@ dependencies {
tasks.withType(JavaCompile).configureEach {
options.errorprone {
disableAllChecks = true // consider removal to avoid error prone error´s, following convention over configuration.
error('RedundantStringConversion')
error(
'ConstantNaming',
'RedundantStringConversion',
)
if (!getenv().containsKey('CI') && getenv('IN_PLACE')?.toBoolean()) {
errorproneArgs.addAll(
'-XepPatchLocation:IN_PLACE',
'-XepPatchChecks:RedundantStringConversion'
'-XepPatchChecks:' +
'ConstantNaming,' +
'RedundantStringConversion,'
)
}
}
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 @@ -55,7 +55,7 @@

public class KtLintCompat0Dot49Dot0Adapter implements KtLintCompatAdapter {

private static final Logger logger = LoggerFactory.getLogger(KtLintCompat0Dot49Dot0Adapter.class);
private static final Logger LOGGER = LoggerFactory.getLogger(KtLintCompat0Dot49Dot0Adapter.class);

private static final List<EditorConfigProperty<?>> DEFAULT_EDITOR_CONFIG_PROPERTIES;

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 @@ -55,7 +55,7 @@

public class KtLintCompat0Dot50Dot0Adapter implements KtLintCompatAdapter {

private static final Logger logger = LoggerFactory.getLogger(KtLintCompat0Dot50Dot0Adapter.class);
private static final Logger LOGGER = LoggerFactory.getLogger(KtLintCompat0Dot50Dot0Adapter.class);

private static final List<EditorConfigProperty<?>> DEFAULT_EDITOR_CONFIG_PROPERTIES;

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 @@ -54,7 +54,7 @@

public class KtLintCompat1Dot0Dot0Adapter implements KtLintCompatAdapter {

private static final Logger logger = LoggerFactory.getLogger(KtLintCompat1Dot0Dot0Adapter.class);
private static final Logger LOGGER = LoggerFactory.getLogger(KtLintCompat1Dot0Dot0Adapter.class);

private static final List<EditorConfigProperty<?>> DEFAULT_EDITOR_CONFIG_PROPERTIES;

Expand Down
21 changes: 10 additions & 11 deletions lib/src/main/java/com/diffplug/spotless/DirtyState.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2022-2024 DiffPlug
* Copyright 2022-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 @@ -31,19 +31,18 @@
* then you can call {@link #writeCanonicalTo(OutputStream)} to get the canonical form of the given file.
*/
public class DirtyState {
@Nullable
private final byte[] canonicalBytes;
@Nullable private final byte[] canonicalBytes;
Copy link
Contributor Author

Choose a reason for hiding this comment

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

is this the new way of doing so, or a bug?

As applied in general the formatAnnotations looks quite strange, isn´t it?

Copy link
Member

Choose a reason for hiding this comment

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

I don't care where it goes, fine with me


DirtyState(@Nullable byte[] canonicalBytes) {
this.canonicalBytes = canonicalBytes;
}

public boolean isClean() {
return this == isClean;
return this == IS_CLEAN;
}

public boolean didNotConverge() {
return this == didNotConverge;
return this == DID_NOT_CONVERGE;
}

byte[] canonicalBytes() {
Expand All @@ -63,11 +62,11 @@ public void writeCanonicalTo(OutputStream out) throws IOException {

/** Returns the DirtyState which corresponds to {@code isClean()}. */
public static DirtyState clean() {
return isClean;
return IS_CLEAN;
}

static final DirtyState didNotConverge = new DirtyState(null);
static final DirtyState isClean = new DirtyState(null);
static final DirtyState DID_NOT_CONVERGE = new DirtyState(null);
static final DirtyState IS_CLEAN = new DirtyState(null);

public static DirtyState of(Formatter formatter, File file) throws IOException {
return of(formatter, file, Files.readAllBytes(file.toPath()));
Expand Down Expand Up @@ -101,7 +100,7 @@ static DirtyState of(Formatter formatter, File file, byte[] rawBytes, String raw
// if F(input) == input, then the formatter is well-behaving and the input is clean
byte[] formattedBytes = formatted.getBytes(formatter.getEncoding());
if (Arrays.equals(rawBytes, formattedBytes)) {
return isClean;
return IS_CLEAN;
}

// F(input) != input, so we'll do a padded check
Expand All @@ -113,7 +112,7 @@ static DirtyState of(Formatter formatter, File file, byte[] rawBytes, String raw

PaddedCell cell = PaddedCell.check(formatter, file, rawUnix, exceptionPerStep);
if (!cell.isResolvable()) {
return didNotConverge;
return DID_NOT_CONVERGE;
}

// get the canonical bytes
Expand All @@ -124,7 +123,7 @@ static DirtyState of(Formatter formatter, File file, byte[] rawBytes, String raw
// and write them to disk if needed
return new DirtyState(canonicalBytes);
} else {
return isClean;
return IS_CLEAN;
}
}
}
8 changes: 4 additions & 4 deletions lib/src/main/java/com/diffplug/spotless/FileSignature.java
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ private FileSignature(final List<File> files) throws IOException {

int i = 0;
for (File file : this.files) {
signatures[i] = cache.sign(file);
signatures[i] = CACHE.sign(file);
++i;
}
}
Expand Down Expand Up @@ -146,11 +146,11 @@ public File getOnlyFile() {
}
}

private static final boolean machineIsWin = System.getProperty("os.name").toLowerCase(Locale.ROOT).contains("win");
private static final boolean MACHINE_IS_WIN = System.getProperty("os.name").toLowerCase(Locale.ROOT).contains("win");

/** Returns true if this JVM is running on a windows machine. */
public static boolean machineIsWin() {
return machineIsWin;
return MACHINE_IS_WIN;
}

/** Transforms a native path to a unix one. */
Expand Down Expand Up @@ -179,7 +179,7 @@ private static List<File> validateInputFiles(List<File> files) {
* the jars which constitute any given formatter live in a central cache, but will be signed
* over and over. To save this I/O, we maintain a cache, invalidated by lastModified time.
*/
static final Cache cache = new Cache();
static final Cache CACHE = new Cache();

private static final class Cache {
Map<String, Sig> cache = new HashMap<>();
Expand Down
4 changes: 2 additions & 2 deletions lib/src/main/java/com/diffplug/spotless/Formatter.java
Original file line number Diff line number Diff line change
Expand Up @@ -143,13 +143,13 @@ static void legacyErrorBehavior(Formatter formatter, File file, ValuePerStep<Thr
for (int i = 0; i < formatter.getSteps().size(); i++) {
Throwable exception = exceptionPerStep.get(i);
if (exception != null && exception != LintState.formatStepCausedNoChange()) {
logger.error("Step '{}' found problem in '{}':\n{}", formatter.getSteps().get(i).getName(), file.getName(), exception.getMessage(), exception);
LOGGER.error("Step '{}' found problem in '{}':\n{}", formatter.getSteps().get(i).getName(), file.getName(), exception.getMessage(), exception);
throw ThrowingEx.asRuntimeRethrowError(exception);
}
}
}

private static final Logger logger = LoggerFactory.getLogger(Formatter.class);
private static final Logger LOGGER = LoggerFactory.getLogger(Formatter.class);

/**
* Returns the result of calling all of the FormatterSteps, while also
Expand Down
4 changes: 2 additions & 2 deletions lib/src/main/java/com/diffplug/spotless/JarState.java
Original file line number Diff line number Diff line change
Expand Up @@ -45,15 +45,15 @@
*/
public final class JarState implements Serializable {

private static final Logger logger = LoggerFactory.getLogger(JarState.class);
private static final Logger LOGGER = LoggerFactory.getLogger(JarState.class);

// Let the classloader be overridden for tools using different approaches to classloading
@Nullable private static ClassLoader forcedClassLoader;

/** Overrides the classloader used by all JarStates. */
public static void setForcedClassLoader(@Nullable ClassLoader forcedClassLoader) {
if (!Objects.equals(JarState.forcedClassLoader, forcedClassLoader)) {
logger.info("Overriding the forced classloader for JarState from {} to {}", JarState.forcedClassLoader, forcedClassLoader);
LOGGER.info("Overriding the forced classloader for JarState from {} to {}", JarState.forcedClassLoader, forcedClassLoader);
}
JarState.forcedClassLoader = forcedClassLoader;
}
Expand Down
12 changes: 6 additions & 6 deletions lib/src/main/java/com/diffplug/spotless/LineEnding.java
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ public Policy createPolicy(File projectDir, Supplier<Iterable<File>> toFormat) {
/** Should use {@link #createPolicy(File, Supplier)} instead, but this will work iff its a path-independent LineEnding policy. */
public Policy createPolicy() {
switch (this) {
case PLATFORM_NATIVE: return _platformNativePolicy;
case PLATFORM_NATIVE: return _PLATFORM_NATIVE_POLICY;
case WINDOWS: return WINDOWS_POLICY;
case UNIX: return UNIX_POLICY;
case MAC_CLASSIC: return MAC_CLASSIC_POLICY;
Expand Down Expand Up @@ -152,9 +152,9 @@ static String getEndingFor(Reader reader) throws IOException {
private static final Policy UNIX_POLICY = new ConstantLineEndingPolicy(UNIX.str());
private static final Policy MAC_CLASSIC_POLICY = new ConstantLineEndingPolicy(MAC_CLASSIC.str());
private static final Policy PRESERVE_POLICY = new PreserveLineEndingPolicy();
private static final String _platformNative = System.getProperty("line.separator");
private static final Policy _platformNativePolicy = new ConstantLineEndingPolicy(_platformNative);
private static final boolean nativeIsWin = _platformNative.equals(WINDOWS.str());
private static final String _PLATFORM_NATIVE = System.getProperty("line.separator");
private static final Policy _PLATFORM_NATIVE_POLICY = new ConstantLineEndingPolicy(_PLATFORM_NATIVE);
private static final boolean NATIVE_IS_WIN = _PLATFORM_NATIVE.equals(WINDOWS.str());

/**
* @deprecated Using the system-native line endings to detect the windows operating system has turned out
Expand All @@ -164,13 +164,13 @@ static String getEndingFor(Reader reader) throws IOException {
*/
@Deprecated
public static boolean nativeIsWin() {
return nativeIsWin;
return NATIVE_IS_WIN;
}

/** Returns the standard line ending for this policy. */
public String str() {
switch (this) {
case PLATFORM_NATIVE: return _platformNative;
case PLATFORM_NATIVE: return _PLATFORM_NATIVE;
case WINDOWS: return "\r\n";
case UNIX: return "\n";
case MAC_CLASSIC: return "\r";
Expand Down
4 changes: 2 additions & 2 deletions lib/src/main/java/com/diffplug/spotless/LintState.java
Original file line number Diff line number Diff line change
Expand Up @@ -197,10 +197,10 @@ public static LintState of(Formatter formatter, File file, byte[] rawBytes) {

/** Returns the DirtyState which corresponds to {@code isClean()}. */
public static LintState clean() {
return isClean;
return IS_CLEAN;
}

private static final LintState isClean = new LintState(DirtyState.clean(), null);
private static final LintState IS_CLEAN = new LintState(DirtyState.clean(), null);

static Throwable formatStepCausedNoChange() {
return FormatterCausedNoChange.INSTANCE;
Expand Down
12 changes: 6 additions & 6 deletions lib/src/main/java/com/diffplug/spotless/SpotlessCache.java
Original file line number Diff line number Diff line change
Expand Up @@ -76,17 +76,17 @@ synchronized ClassLoader classloader(Serializable key, JarState state) {
}

static SpotlessCache instance() {
return instance;
return INSTANCE;
}

/**
* Closes all cached classloaders.
*/
private static void clear() {
List<URLClassLoader> toDelete;
synchronized (instance) {
toDelete = new ArrayList<>(instance.cache.values());
instance.cache.clear();
synchronized (INSTANCE) {
toDelete = new ArrayList<>(INSTANCE.cache.values());
INSTANCE.cache.clear();
}
for (URLClassLoader classLoader : toDelete) {
try {
Expand All @@ -104,7 +104,7 @@ private static void clear() {
* If {@code key} is null, the clear will always happen (as though null != null).
*/
public static boolean clearOnce(@Nullable Object key) {
synchronized (instance) {
synchronized (INSTANCE) {
if (key == null) {
lastClear = null;
} else if (key.equals(lastClear)) {
Expand All @@ -117,5 +117,5 @@ public static boolean clearOnce(@Nullable Object key) {
return true;
}

private static final SpotlessCache instance = new SpotlessCache();
private static final SpotlessCache INSTANCE = new SpotlessCache();
}
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
* <a href="https://github.com/biomejs/biome">https://github.com/biomejs/biome</a>.
*/
final class BiomeExecutableDownloader {
private static final Logger logger = LoggerFactory.getLogger(BiomeExecutableDownloader.class);
private static final Logger LOGGER = LoggerFactory.getLogger(BiomeExecutableDownloader.class);

/**
* The checksum algorithm to use for checking the integrity of downloaded files.
Expand Down Expand Up @@ -106,7 +106,7 @@ public Path download(String version) throws IOException, InterruptedException {
if (executableDir != null) {
Files.createDirectories(executableDir);
}
logger.info("Attempting to download Biome from '{}' to '{}'", url, executablePath);
LOGGER.info("Attempting to download Biome from '{}' to '{}'", url, executablePath);
var request = HttpRequest.newBuilder(URI.create(url)).GET().build();
var handler = BodyHandlers.ofFile(executablePath, WRITE_OPTIONS);
var response = HttpClient.newBuilder().followRedirects(Redirect.NORMAL).build().send(request, handler);
Expand All @@ -118,7 +118,7 @@ public Path download(String version) throws IOException, InterruptedException {
throw new IOException("Failed to download file from " + url + ", file is empty or does not exist");
}
writeChecksumFile(downloadedFile, checksumPath);
logger.debug("Biome was downloaded successfully to '{}'", downloadedFile);
LOGGER.debug("Biome was downloaded successfully to '{}'", downloadedFile);
return downloadedFile;
}

Expand All @@ -142,13 +142,13 @@ public Path download(String version) throws IOException, InterruptedException {
*/
public Path ensureDownloaded(String version) throws IOException, InterruptedException {
var platform = Platform.guess();
logger.debug("Ensuring that Biome for platform '{}' is downloaded", platform);
LOGGER.debug("Ensuring that Biome for platform '{}' is downloaded", platform);
var existing = findDownloaded(version);
if (existing.isPresent()) {
logger.debug("Biome was already downloaded, using executable at '{}'", existing.orElseThrow());
LOGGER.debug("Biome was already downloaded, using executable at '{}'", existing.orElseThrow());
return existing.orElseThrow();
} else {
logger.debug("Biome was not yet downloaded, attempting to download executable");
LOGGER.debug("Biome was not yet downloaded, attempting to download executable");
return download(version);
}
}
Expand All @@ -169,7 +169,7 @@ public Path ensureDownloaded(String version) throws IOException, InterruptedExce
public Optional<Path> findDownloaded(String version) throws IOException {
var platform = Platform.guess();
var executablePath = getExecutablePath(version, platform);
logger.debug("Checking Biome executable at {}", executablePath);
LOGGER.debug("Checking Biome executable at {}", executablePath);
return checkFileWithChecksum(executablePath) ? Optional.ofNullable(executablePath) : Optional.empty();
}

Expand All @@ -183,26 +183,26 @@ public Optional<Path> findDownloaded(String version) throws IOException {
*/
private boolean checkFileWithChecksum(Path filePath) {
if (!Files.exists(filePath)) {
logger.debug("File '{}' does not exist yet", filePath);
LOGGER.debug("File '{}' does not exist yet", filePath);
return false;
}
if (Files.isDirectory(filePath)) {
logger.debug("File '{}' exists, but is a directory", filePath);
LOGGER.debug("File '{}' exists, but is a directory", filePath);
return false;
}
var checksumPath = getChecksumPath(filePath);
if (!Files.exists(checksumPath)) {
logger.debug("File '{}' exists, but checksum file '{}' does not", filePath, checksumPath);
LOGGER.debug("File '{}' exists, but checksum file '{}' does not", filePath, checksumPath);
return false;
}
if (Files.isDirectory(checksumPath)) {
logger.debug("Checksum file '{}' exists, but is a directory", checksumPath);
LOGGER.debug("Checksum file '{}' exists, but is a directory", checksumPath);
return false;
}
try {
var actualChecksum = computeChecksum(filePath, CHECKSUM_ALGORITHM);
var expectedChecksum = readTextFile(checksumPath, StandardCharsets.ISO_8859_1);
logger.debug("Expected checksum: {}, actual checksum: {}", expectedChecksum, actualChecksum);
LOGGER.debug("Expected checksum: {}, actual checksum: {}", expectedChecksum, actualChecksum);
return Objects.equals(expectedChecksum, actualChecksum);
} catch (final IOException ignored) {
return false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
* Settings and constants for Biome to use.
*/
public final class BiomeSettings {
private static final Logger logger = LoggerFactory.getLogger(BiomeSettings.class);
private static final Logger LOGGER = LoggerFactory.getLogger(BiomeSettings.class);

private static final String CONFIG_NAME = "biome.json";
private static final String DEFAULT_VERSION = "1.2.0";
Expand Down Expand Up @@ -106,7 +106,7 @@ public static boolean versionHigherThanOrEqualTo(String version, int major, int
}
return actualMajor == major && actualMinor == minor && actualPatch == patch;
} catch (final Exception e) {
logger.warn("Failed to parse biome version string '{}'. Expected format is 'major.minor.patch'.", version, e);
LOGGER.warn("Failed to parse biome version string '{}'. Expected format is 'major.minor.patch'.", version, e);
return false;
}
}
Expand Down
Loading
Loading