diff --git a/CHANGES.md b/CHANGES.md index c86189bad4..cfd8526468 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -12,9 +12,14 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format ( ## [Unreleased] ### Added * Added support for enabling ktlint experimental ruleset. ([#1145](https://github.com/diffplug/spotless/pull/1168)) +### Fixed +* Fixed support for Python Black's new version reporting. ([#1170](https://github.com/diffplug/spotless/issues/1170)) +* Error messages for unexpected file encoding now works on Java 8. (fixes [#1081](https://github.com/diffplug/spotless/issues/1081)) +### Changes +* Bump default `black` version to latest (`19.10b0` -> `22.3.0`). ([#1170](https://github.com/diffplug/spotless/issues/1170)) +* Bump default `ktfmt` version `0.34` -> `0.36`. ([#1159](https://github.com/diffplug/spotless/pull/1159)) ## [2.24.2] - 2022-04-06 - ### Fixed * Git user config and system config also included for defaultEndings configuration. ([#540](https://github.com/diffplug/spotless/issues/540)) diff --git a/lib/build.gradle b/lib/build.gradle index d620a3dd8d..415817b09d 100644 --- a/lib/build.gradle +++ b/lib/build.gradle @@ -35,7 +35,7 @@ dependencies { palantirJavaFormatCompileOnly 'com.palantir.javaformat:palantir-java-format:1.1.0' - String VER_KTFMT = '0.34' + String VER_KTFMT = '0.35' ktfmtCompileOnly "com.facebook:ktfmt:$VER_KTFMT" String VER_KTLINT_GOOGLE_JAVA_FORMAT = '1.7' // for JDK 8 compatibility ktfmtCompileOnly("com.google.googlejavaformat:google-java-format") { diff --git a/lib/src/main/java/com/diffplug/spotless/EncodingErrorMsg.java b/lib/src/main/java/com/diffplug/spotless/EncodingErrorMsg.java index b89400b7c2..168bf9acff 100644 --- a/lib/src/main/java/com/diffplug/spotless/EncodingErrorMsg.java +++ b/lib/src/main/java/com/diffplug/spotless/EncodingErrorMsg.java @@ -1,5 +1,5 @@ /* - * Copyright 2016 DiffPlug + * Copyright 2016-2022 DiffPlug * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -15,6 +15,7 @@ */ package com.diffplug.spotless; +import java.nio.Buffer; import java.nio.ByteBuffer; import java.nio.CharBuffer; import java.nio.charset.Charset; @@ -115,8 +116,8 @@ private static void addIfAvailable(Collection charsets, String name) { } private void appendExample(Charset charset, boolean must) { - byteBuf.clear(); - charBuf.clear(); + java8fix(byteBuf).clear(); + java8fix(charBuf).clear(); CharsetDecoder decoder = charset.newDecoder(); if (!must) { @@ -134,7 +135,7 @@ private void appendExample(Charset charset, boolean must) { .onUnmappableCharacter(CodingErrorAction.REPLACE) .decode(byteBuf, charBuf, true); } - charBuf.flip(); + java8fix(charBuf).flip(); int start = Math.max(unrepresentable - CONTEXT, 0); int end = Math.min(charBuf.limit(), unrepresentable + CONTEXT + 1); @@ -146,4 +147,9 @@ private void appendExample(Charset charset, boolean must) { message.append(" <- "); message.append(charset.name()); } + + /** Fixes https://jira.mongodb.org/browse/JAVA-2559, as reported in https://github.com/diffplug/spotless/issues/1081 */ + private static Buffer java8fix(Buffer b) { + return b; + } } diff --git a/lib/src/main/java/com/diffplug/spotless/kotlin/KtfmtStep.java b/lib/src/main/java/com/diffplug/spotless/kotlin/KtfmtStep.java index d9feef4c91..3cefe7baca 100644 --- a/lib/src/main/java/com/diffplug/spotless/kotlin/KtfmtStep.java +++ b/lib/src/main/java/com/diffplug/spotless/kotlin/KtfmtStep.java @@ -39,7 +39,7 @@ public class KtfmtStep { // prevent direct instantiation private KtfmtStep() {} - private static final String DEFAULT_VERSION = "0.34"; + private static final String DEFAULT_VERSION = "0.35"; static final String NAME = "ktfmt"; static final String PACKAGE = "com.facebook"; static final String MAVEN_COORDINATE = PACKAGE + ":ktfmt:"; diff --git a/lib/src/main/java/com/diffplug/spotless/python/BlackStep.java b/lib/src/main/java/com/diffplug/spotless/python/BlackStep.java index c19d023ffc..3f4a8837b6 100644 --- a/lib/src/main/java/com/diffplug/spotless/python/BlackStep.java +++ b/lib/src/main/java/com/diffplug/spotless/python/BlackStep.java @@ -1,5 +1,5 @@ /* - * Copyright 2020-2021 DiffPlug + * Copyright 2020-2022 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.nio.charset.StandardCharsets; import java.util.Arrays; import java.util.List; +import java.util.regex.Pattern; import javax.annotation.Nullable; @@ -36,7 +37,7 @@ public static String name() { } public static String defaultVersion() { - return "19.10b0"; + return "22.3.0"; } private final String version; @@ -63,6 +64,7 @@ private State createState() throws IOException, InterruptedException { String trackingIssue = "\n github issue to handle this better: https://github.com/diffplug/spotless/issues/674"; String exeAbsPath = ForeignExe.nameAndVersion("black", version) .pathToExe(pathToExe) + .versionRegex(Pattern.compile("(?:black,|version) (\\S*)")) .fixCantFind("Try running {@code pip install black=={version}}, or else tell Spotless where it is with {@code black().pathToExe('path/to/executable')}" + trackingIssue) .fixWrongVersion("Try running {@code pip install --force-reinstall black=={version}}, or else specify {@code black('{versionFound}')} to Spotless" + trackingIssue) .confirmVersionAndGetAbsolutePath(); diff --git a/plugin-gradle/CHANGES.md b/plugin-gradle/CHANGES.md index b986f4b839..b412a58a59 100644 --- a/plugin-gradle/CHANGES.md +++ b/plugin-gradle/CHANGES.md @@ -4,8 +4,18 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format ( ## [Unreleased] ### Added -* Added a runToFixMessage property to customize the run-to-fix message in spotlessCheck task ([#1175](https://github.com/diffplug/spotless/issues/1175)). +* Added a `runToFixMessage` property to customize the run-to-fix message in `spotlessCheck` task. ([#1175](https://github.com/diffplug/spotless/issues/1175)) * Added support for enabling ktlint experimental ruleset. ([#1145](https://github.com/diffplug/spotless/pull/1168)) +### Fixed +* Fixed support for Python Black's new version reporting. ([#1170](https://github.com/diffplug/spotless/issues/1170)) +* All tasks (including helper tasks) are now part of the `verification` group. (fixes [#1050](https://github.com/diffplug/spotless/issues/1050)) +* Error messages for unexpected file encoding now works on Java 8. (fixes [#1081](https://github.com/diffplug/spotless/issues/1081)) +### Changed +* Bump default `black` version to latest (`19.10b0` -> `22.3.0`). ([#1170](https://github.com/diffplug/spotless/issues/1170)) +* Bump default `ktfmt` version to latest (`0.34` -> `0.35`). ([#1159](https://github.com/diffplug/spotless/pull/1159)) +* Spotless now applies the `base` plugin to make sure that Spotless always has a `check` task to hook into. ([#1179](https://github.com/diffplug/spotless/pull/1179), fixes [#1164](https://github.com/diffplug/spotless/pull/1164), reverts [#1014](https://github.com/diffplug/spotless/pull/1014)) + * Spotless used to work this way, we stopped applying base starting with version [`6.0.3` (released Dec 2021)](https://github.com/diffplug/spotless/blob/main/plugin-gradle/CHANGES.md#603---2021-12-06) in order to play nicely with a now-outdated Android template, but not applying `base` causes more problems than it fixes (see [#1164](https://github.com/diffplug/spotless/pull/1164) for a good example). + * If you have anything like `tasks.register("clean"` or `tasks.register("clean", Delete)`, just change the `register` to `named` so that you are configuring the existing `clean` created by `base`, rather than creating a new task. ## [6.4.2] - 2022-04-06 ### Fixed diff --git a/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/FormatExtension.java b/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/FormatExtension.java index 9da66b7929..d8c5525db6 100644 --- a/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/FormatExtension.java +++ b/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/FormatExtension.java @@ -1,5 +1,5 @@ /* - * Copyright 2016-2021 DiffPlug + * Copyright 2016-2022 DiffPlug * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -37,6 +37,7 @@ import org.gradle.api.Project; import org.gradle.api.file.ConfigurableFileTree; import org.gradle.api.file.FileCollection; +import org.gradle.api.plugins.BasePlugin; import com.diffplug.common.base.Preconditions; import com.diffplug.spotless.FormatExceptionPolicyStrict; @@ -788,7 +789,7 @@ public SpotlessApply createIndependentApplyTask(String taskName) { spotlessTask.init(spotless.getRegisterDependenciesTask().getTaskService()); setupTask(spotlessTask); // clean removes the SpotlessCache, so we have to run after clean - SpotlessPlugin.configureCleanTask(spotless.project, spotlessTask::mustRunAfter); + spotlessTask.mustRunAfter(BasePlugin.CLEAN_TASK_NAME); // create the apply task SpotlessApply applyTask = spotless.project.getTasks().create(taskName, SpotlessApply.class); applyTask.init(spotlessTask); diff --git a/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/SpotlessExtension.java b/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/SpotlessExtension.java index e85c26f25e..57aa3b2d83 100644 --- a/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/SpotlessExtension.java +++ b/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/SpotlessExtension.java @@ -29,6 +29,7 @@ import org.gradle.api.Project; import org.gradle.api.tasks.TaskContainer; import org.gradle.api.tasks.TaskProvider; +import org.gradle.language.base.plugins.LifecycleBasePlugin; import com.diffplug.spotless.LineEnding; @@ -36,7 +37,7 @@ public abstract class SpotlessExtension { final Project project; private final RegisterDependenciesTask registerDependenciesTask; - protected static final String TASK_GROUP = "Verification"; + protected static final String TASK_GROUP = LifecycleBasePlugin.VERIFICATION_GROUP; protected static final String CHECK_DESCRIPTION = "Checks that sourcecode satisfies formatting steps."; protected static final String APPLY_DESCRIPTION = "Applies code formatting steps to sourcecode in-place."; diff --git a/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/SpotlessExtensionImpl.java b/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/SpotlessExtensionImpl.java index 24fa7b54b0..96474ffc4b 100644 --- a/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/SpotlessExtensionImpl.java +++ b/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/SpotlessExtensionImpl.java @@ -1,5 +1,5 @@ /* - * Copyright 2016-2021 DiffPlug + * Copyright 2016-2022 DiffPlug * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -17,7 +17,7 @@ import org.gradle.api.Action; import org.gradle.api.Project; -import org.gradle.api.UnknownTaskException; +import org.gradle.api.plugins.BasePlugin; import org.gradle.api.plugins.JavaBasePlugin; import org.gradle.api.tasks.TaskContainer; import org.gradle.api.tasks.TaskProvider; @@ -41,12 +41,7 @@ public SpotlessExtensionImpl(Project project) { project.afterEvaluate(unused -> { if (enforceCheck) { - try { - project.getTasks().named(JavaBasePlugin.CHECK_TASK_NAME) - .configure(task -> task.dependsOn(rootCheckTask)); - } catch (UnknownTaskException e) { - // no action needed, it's okay if there's no `check` task - } + project.getTasks().named(JavaBasePlugin.CHECK_TASK_NAME).configure(task -> task.dependsOn(rootCheckTask)); } }); } @@ -60,9 +55,11 @@ protected void createFormatTasks(String name, FormatExtension formatExtension) { String taskName = EXTENSION + SpotlessPlugin.capitalize(name); TaskProvider spotlessTask = tasks.register(taskName, SpotlessTaskImpl.class, task -> { task.init(getRegisterDependenciesTask().getTaskService()); + task.setGroup(TASK_GROUP); task.setEnabled(!isIdeHook); + // clean removes the SpotlessCache, so we have to run after clean + task.mustRunAfter(BasePlugin.CLEAN_TASK_NAME); }); - SpotlessPlugin.taskMustRunAfterClean(project, spotlessTask); project.afterEvaluate(unused -> { spotlessTask.configure(task -> { // now that the task is being configured, we execute our actions @@ -77,6 +74,7 @@ protected void createFormatTasks(String name, FormatExtension formatExtension) { // create the check and apply control tasks TaskProvider applyTask = tasks.register(taskName + APPLY, SpotlessApply.class, task -> { task.init(spotlessTask.get()); + task.setGroup(TASK_GROUP); task.setEnabled(!isIdeHook); task.dependsOn(spotlessTask); }); @@ -91,6 +89,7 @@ protected void createFormatTasks(String name, FormatExtension formatExtension) { TaskProvider checkTask = tasks.register(taskName + CHECK, SpotlessCheck.class, task -> { SpotlessTaskImpl source = spotlessTask.get(); + task.setGroup(TASK_GROUP); task.init(source); task.setEnabled(!isIdeHook); task.dependsOn(source); @@ -103,8 +102,9 @@ protected void createFormatTasks(String name, FormatExtension formatExtension) { // create the diagnose task TaskProvider diagnoseTask = tasks.register(taskName + DIAGNOSE, SpotlessDiagnoseTask.class, task -> { task.source = spotlessTask.get(); + task.setGroup(TASK_GROUP); + task.mustRunAfter(BasePlugin.CLEAN_TASK_NAME); }); - SpotlessPlugin.taskMustRunAfterClean(project, diagnoseTask); rootDiagnoseTask.configure(task -> task.dependsOn(diagnoseTask)); } } diff --git a/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/SpotlessPlugin.java b/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/SpotlessPlugin.java index 7b9e61eb03..868502d216 100644 --- a/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/SpotlessPlugin.java +++ b/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/SpotlessPlugin.java @@ -15,14 +15,10 @@ */ package com.diffplug.gradle.spotless; -import java.util.function.Consumer; - import org.gradle.api.GradleException; import org.gradle.api.Plugin; import org.gradle.api.Project; import org.gradle.api.plugins.BasePlugin; -import org.gradle.api.tasks.Delete; -import org.gradle.api.tasks.TaskProvider; import com.diffplug.spotless.SpotlessCache; @@ -39,6 +35,8 @@ public void apply(Project project) { if (project.hasProperty(SPOTLESS_MODERN)) { project.getLogger().warn("'spotlessModern' has no effect as of Spotless 5.0, recommend removing it."); } + // make sure there's a `clean` and a `check` + project.getPlugins().apply(BasePlugin.class); // setup the extension project.getExtensions().create(SpotlessExtension.class, SpotlessExtension.EXTENSION, SpotlessExtensionImpl.class, project); @@ -50,26 +48,7 @@ public void apply(Project project) { // // we use System.identityHashCode() to avoid a memory leak by hanging on to the reference directly int cacheKey = System.identityHashCode(project.getRootProject()); - configureCleanTask(project, clean -> clean.doLast(unused -> SpotlessCache.clearOnce(cacheKey))); - } - - static void configureCleanTask(Project project, Consumer onClean) { - project.getTasks().withType(Delete.class).configureEach(clean -> { - if (clean.getName().equals(BasePlugin.CLEAN_TASK_NAME)) { - onClean.accept(clean); - } - }); - } - - /** clean removes the SpotlessCache, so we have to run after clean. */ - static void taskMustRunAfterClean(Project project, TaskProvider task) { - if (project.getPlugins().hasPlugin(BasePlugin.class)) { - // if we know that the clean task is around, then we can configure lazily - task.configure(t -> t.mustRunAfter(BasePlugin.CLEAN_TASK_NAME)); - } else { - // otherwise, we trigger configuration when the clean task gets configured - configureCleanTask(project, clean -> task.get().mustRunAfter(clean)); - } + project.getTasks().named(BasePlugin.CLEAN_TASK_NAME).configure(clean -> clean.doLast(unused -> SpotlessCache.clearOnce(cacheKey))); } static String capitalize(String input) { diff --git a/plugin-maven/CHANGES.md b/plugin-maven/CHANGES.md index 7ffcf0cc81..e4831da6c1 100644 --- a/plugin-maven/CHANGES.md +++ b/plugin-maven/CHANGES.md @@ -3,9 +3,14 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format (starting after version `1.27.0`). ## [Unreleased] +### Fixed +* Fixed support for Python Black's new version reporting. ([#1170](https://github.com/diffplug/spotless/issues/1170)) +* Error messages for unexpected file encoding now works on Java 8. (fixes [#1081](https://github.com/diffplug/spotless/issues/1081)) +### Changes +* Bump default `black` version to latest (`19.10b0` -> `22.3.0`). ([#1170](https://github.com/diffplug/spotless/issues/1170)) +* Bump default `ktfmt` version `0.34` -> `0.35`. ([#1159](https://github.com/diffplug/spotless/pull/1159)) ## [2.22.1] - 2022-04-06 - ### Fixed * Git user config and system config also included for defaultEndings configuration. ([#540](https://github.com/diffplug/spotless/issues/540))