Skip to content
Draft
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
1 change: 1 addition & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ repositories {
apply from: rootProject.file('gradle/java-publish.gradle')
apply from: rootProject.file('gradle/changelog.gradle')
allprojects {
apply from: rootProject.file('gradle/error-prone.gradle')
apply from: rootProject.file('gradle/rewrite.gradle')
apply from: rootProject.file('gradle/spotless.gradle')
}
Expand Down
30 changes: 30 additions & 0 deletions gradle/error-prone.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import static java.lang.System.getenv

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.
//error('ConstantNaming')
if (!getenv().containsKey('CI') && getenv('IN_PLACE')?.toBoolean()) {
errorproneArgs.addAll(
'-XepPatchLocation:IN_PLACE',
'-XepPatchChecks:ConstantNaming'
)
}
}
}
Original file line number Diff line number Diff line change
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
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
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
4 changes: 2 additions & 2 deletions lib/src/main/java/com/diffplug/spotless/FileSignature.java
Original file line number Diff line number Diff line change
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
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
12 changes: 6 additions & 6 deletions lib/src/main/java/com/diffplug/spotless/biome/BiomeStep.java
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@
* the network when no executable path is provided explicitly.
*/
public final class BiomeStep {
private static final Logger logger = LoggerFactory.getLogger(BiomeStep.class);
private static final Logger LOGGER = LoggerFactory.getLogger(BiomeStep.class);

/**
* Path to the directory with the {@code biome.json} config file, can be
Expand Down Expand Up @@ -136,7 +136,7 @@ private static void attemptToAddPosixPermission(Path file, PosixFilePermission p
newPermissions.add(permission);
Files.setPosixFilePermissions(file, newPermissions);
} catch (final Exception ignore) {
logger.debug("Unable to add POSIX permission '{}' to file '{}'", permission, file);
LOGGER.debug("Unable to add POSIX permission '{}' to file '{}'", permission, file);
}
}

Expand Down Expand Up @@ -298,7 +298,7 @@ private State createState() throws IOException, InterruptedException {
var resolvedPathToExe = resolveExe();
validateBiomeExecutable(resolvedPathToExe);
validateBiomeConfigPath(configPath, version);
logger.debug("Using Biome executable located at '{}'", resolvedPathToExe);
LOGGER.debug("Using Biome executable located at '{}'", resolvedPathToExe);
var exeSignature = FileSignature.signAsList(Set.of(new File(resolvedPathToExe)));
makeExecutable(resolvedPathToExe);
return new State(resolvedPathToExe, exeSignature, configPath, language);
Expand Down Expand Up @@ -421,13 +421,13 @@ private String[] buildBiomeCommand(File file) {
private String format(ProcessRunner runner, String input, File file) throws IOException, InterruptedException {
var stdin = input.getBytes(StandardCharsets.UTF_8);
var args = buildBiomeCommand(file);
if (logger.isDebugEnabled()) {
logger.debug("Running Biome command to format code: '{}'", String.join(", ", args));
if (LOGGER.isDebugEnabled()) {
LOGGER.debug("Running Biome command to format code: '{}'", String.join(", ", args));
}
var runnerResult = runner.exec(stdin, args);
var stdErr = runnerResult.stdErrUtf8();
if (!stdErr.isEmpty()) {
logger.warn("Biome stderr ouptut for file '{}'\n{}", file, stdErr.trim());
LOGGER.warn("Biome stderr ouptut for file '{}'\n{}", file, stdErr.trim());
}
var formatted = runnerResult.assertExitZero(StandardCharsets.UTF_8);
// When biome encounters an ignored file, it does not output any formatted code
Expand Down
Loading