Skip to content

Commit c4bb9d0

Browse files
committed
Merge branch 'dependabot/gradle/com.facebook-ktfmt-0.35' into dependabot/gradle/VER_KTLINT-0.45.2
2 parents 6f520e6 + cb1a377 commit c4bb9d0

File tree

11 files changed

+57
-48
lines changed

11 files changed

+57
-48
lines changed

CHANGES.md

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,14 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format (
1212
## [Unreleased]
1313
### Added
1414
* Added support for enabling ktlint experimental ruleset. ([#1145](https://github.com/diffplug/spotless/pull/1168))
15+
### Fixed
16+
* Fixed support for Python Black's new version reporting. ([#1170](https://github.com/diffplug/spotless/issues/1170))
17+
* Error messages for unexpected file encoding now works on Java 8. (fixes [#1081](https://github.com/diffplug/spotless/issues/1081))
18+
### Changes
19+
* Bump default `black` version to latest (`19.10b0` -> `22.3.0`). ([#1170](https://github.com/diffplug/spotless/issues/1170))
20+
* Bump default `ktfmt` version `0.34` -> `0.36`. ([#1159](https://github.com/diffplug/spotless/pull/1159))
1521

1622
## [2.24.2] - 2022-04-06
17-
1823
### Fixed
1924
* Git user config and system config also included for defaultEndings configuration. ([#540](https://github.com/diffplug/spotless/issues/540))
2025

lib/build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ dependencies {
3535

3636
palantirJavaFormatCompileOnly 'com.palantir.javaformat:palantir-java-format:1.1.0'
3737

38-
String VER_KTFMT = '0.34'
38+
String VER_KTFMT = '0.35'
3939
ktfmtCompileOnly "com.facebook:ktfmt:$VER_KTFMT"
4040
String VER_KTLINT_GOOGLE_JAVA_FORMAT = '1.7' // for JDK 8 compatibility
4141
ktfmtCompileOnly("com.google.googlejavaformat:google-java-format") {

lib/src/main/java/com/diffplug/spotless/EncodingErrorMsg.java

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2016 DiffPlug
2+
* Copyright 2016-2022 DiffPlug
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -15,6 +15,7 @@
1515
*/
1616
package com.diffplug.spotless;
1717

18+
import java.nio.Buffer;
1819
import java.nio.ByteBuffer;
1920
import java.nio.CharBuffer;
2021
import java.nio.charset.Charset;
@@ -115,8 +116,8 @@ private static void addIfAvailable(Collection<Charset> charsets, String name) {
115116
}
116117

117118
private void appendExample(Charset charset, boolean must) {
118-
byteBuf.clear();
119-
charBuf.clear();
119+
java8fix(byteBuf).clear();
120+
java8fix(charBuf).clear();
120121

121122
CharsetDecoder decoder = charset.newDecoder();
122123
if (!must) {
@@ -134,7 +135,7 @@ private void appendExample(Charset charset, boolean must) {
134135
.onUnmappableCharacter(CodingErrorAction.REPLACE)
135136
.decode(byteBuf, charBuf, true);
136137
}
137-
charBuf.flip();
138+
java8fix(charBuf).flip();
138139

139140
int start = Math.max(unrepresentable - CONTEXT, 0);
140141
int end = Math.min(charBuf.limit(), unrepresentable + CONTEXT + 1);
@@ -146,4 +147,9 @@ private void appendExample(Charset charset, boolean must) {
146147
message.append(" <- ");
147148
message.append(charset.name());
148149
}
150+
151+
/** Fixes https://jira.mongodb.org/browse/JAVA-2559, as reported in https://github.com/diffplug/spotless/issues/1081 */
152+
private static Buffer java8fix(Buffer b) {
153+
return b;
154+
}
149155
}

lib/src/main/java/com/diffplug/spotless/kotlin/KtfmtStep.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ public class KtfmtStep {
3939
// prevent direct instantiation
4040
private KtfmtStep() {}
4141

42-
private static final String DEFAULT_VERSION = "0.34";
42+
private static final String DEFAULT_VERSION = "0.35";
4343
static final String NAME = "ktfmt";
4444
static final String PACKAGE = "com.facebook";
4545
static final String MAVEN_COORDINATE = PACKAGE + ":ktfmt:";

lib/src/main/java/com/diffplug/spotless/python/BlackStep.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2020-2021 DiffPlug
2+
* Copyright 2020-2022 DiffPlug
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -20,6 +20,7 @@
2020
import java.nio.charset.StandardCharsets;
2121
import java.util.Arrays;
2222
import java.util.List;
23+
import java.util.regex.Pattern;
2324

2425
import javax.annotation.Nullable;
2526

@@ -36,7 +37,7 @@ public static String name() {
3637
}
3738

3839
public static String defaultVersion() {
39-
return "19.10b0";
40+
return "22.3.0";
4041
}
4142

4243
private final String version;
@@ -63,6 +64,7 @@ private State createState() throws IOException, InterruptedException {
6364
String trackingIssue = "\n github issue to handle this better: https://github.com/diffplug/spotless/issues/674";
6465
String exeAbsPath = ForeignExe.nameAndVersion("black", version)
6566
.pathToExe(pathToExe)
67+
.versionRegex(Pattern.compile("(?:black,|version) (\\S*)"))
6668
.fixCantFind("Try running {@code pip install black=={version}}, or else tell Spotless where it is with {@code black().pathToExe('path/to/executable')}" + trackingIssue)
6769
.fixWrongVersion("Try running {@code pip install --force-reinstall black=={version}}, or else specify {@code black('{versionFound}')} to Spotless" + trackingIssue)
6870
.confirmVersionAndGetAbsolutePath();

plugin-gradle/CHANGES.md

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,18 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format (
44

55
## [Unreleased]
66
### Added
7-
* Added a runToFixMessage property to customize the run-to-fix message in spotlessCheck task ([#1175](https://github.com/diffplug/spotless/issues/1175)).
7+
* Added a `runToFixMessage` property to customize the run-to-fix message in `spotlessCheck` task. ([#1175](https://github.com/diffplug/spotless/issues/1175))
88
* Added support for enabling ktlint experimental ruleset. ([#1145](https://github.com/diffplug/spotless/pull/1168))
9+
### Fixed
10+
* Fixed support for Python Black's new version reporting. ([#1170](https://github.com/diffplug/spotless/issues/1170))
11+
* All tasks (including helper tasks) are now part of the `verification` group. (fixes [#1050](https://github.com/diffplug/spotless/issues/1050))
12+
* Error messages for unexpected file encoding now works on Java 8. (fixes [#1081](https://github.com/diffplug/spotless/issues/1081))
13+
### Changed
14+
* Bump default `black` version to latest (`19.10b0` -> `22.3.0`). ([#1170](https://github.com/diffplug/spotless/issues/1170))
15+
* Bump default `ktfmt` version to latest (`0.34` -> `0.35`). ([#1159](https://github.com/diffplug/spotless/pull/1159))
16+
* 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))
17+
* 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).
18+
* If you have anything like `tasks.register<Delete>("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.
919

1020
## [6.4.2] - 2022-04-06
1121
### Fixed

plugin-gradle/src/main/java/com/diffplug/gradle/spotless/FormatExtension.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2016-2021 DiffPlug
2+
* Copyright 2016-2022 DiffPlug
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -37,6 +37,7 @@
3737
import org.gradle.api.Project;
3838
import org.gradle.api.file.ConfigurableFileTree;
3939
import org.gradle.api.file.FileCollection;
40+
import org.gradle.api.plugins.BasePlugin;
4041

4142
import com.diffplug.common.base.Preconditions;
4243
import com.diffplug.spotless.FormatExceptionPolicyStrict;
@@ -788,7 +789,7 @@ public SpotlessApply createIndependentApplyTask(String taskName) {
788789
spotlessTask.init(spotless.getRegisterDependenciesTask().getTaskService());
789790
setupTask(spotlessTask);
790791
// clean removes the SpotlessCache, so we have to run after clean
791-
SpotlessPlugin.configureCleanTask(spotless.project, spotlessTask::mustRunAfter);
792+
spotlessTask.mustRunAfter(BasePlugin.CLEAN_TASK_NAME);
792793
// create the apply task
793794
SpotlessApply applyTask = spotless.project.getTasks().create(taskName, SpotlessApply.class);
794795
applyTask.init(spotlessTask);

plugin-gradle/src/main/java/com/diffplug/gradle/spotless/SpotlessExtension.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,14 +29,15 @@
2929
import org.gradle.api.Project;
3030
import org.gradle.api.tasks.TaskContainer;
3131
import org.gradle.api.tasks.TaskProvider;
32+
import org.gradle.language.base.plugins.LifecycleBasePlugin;
3233

3334
import com.diffplug.spotless.LineEnding;
3435

3536
public abstract class SpotlessExtension {
3637
final Project project;
3738
private final RegisterDependenciesTask registerDependenciesTask;
3839

39-
protected static final String TASK_GROUP = "Verification";
40+
protected static final String TASK_GROUP = LifecycleBasePlugin.VERIFICATION_GROUP;
4041
protected static final String CHECK_DESCRIPTION = "Checks that sourcecode satisfies formatting steps.";
4142
protected static final String APPLY_DESCRIPTION = "Applies code formatting steps to sourcecode in-place.";
4243

plugin-gradle/src/main/java/com/diffplug/gradle/spotless/SpotlessExtensionImpl.java

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2016-2021 DiffPlug
2+
* Copyright 2016-2022 DiffPlug
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -17,7 +17,7 @@
1717

1818
import org.gradle.api.Action;
1919
import org.gradle.api.Project;
20-
import org.gradle.api.UnknownTaskException;
20+
import org.gradle.api.plugins.BasePlugin;
2121
import org.gradle.api.plugins.JavaBasePlugin;
2222
import org.gradle.api.tasks.TaskContainer;
2323
import org.gradle.api.tasks.TaskProvider;
@@ -41,12 +41,7 @@ public SpotlessExtensionImpl(Project project) {
4141

4242
project.afterEvaluate(unused -> {
4343
if (enforceCheck) {
44-
try {
45-
project.getTasks().named(JavaBasePlugin.CHECK_TASK_NAME)
46-
.configure(task -> task.dependsOn(rootCheckTask));
47-
} catch (UnknownTaskException e) {
48-
// no action needed, it's okay if there's no `check` task
49-
}
44+
project.getTasks().named(JavaBasePlugin.CHECK_TASK_NAME).configure(task -> task.dependsOn(rootCheckTask));
5045
}
5146
});
5247
}
@@ -60,9 +55,11 @@ protected void createFormatTasks(String name, FormatExtension formatExtension) {
6055
String taskName = EXTENSION + SpotlessPlugin.capitalize(name);
6156
TaskProvider<SpotlessTaskImpl> spotlessTask = tasks.register(taskName, SpotlessTaskImpl.class, task -> {
6257
task.init(getRegisterDependenciesTask().getTaskService());
58+
task.setGroup(TASK_GROUP);
6359
task.setEnabled(!isIdeHook);
60+
// clean removes the SpotlessCache, so we have to run after clean
61+
task.mustRunAfter(BasePlugin.CLEAN_TASK_NAME);
6462
});
65-
SpotlessPlugin.taskMustRunAfterClean(project, spotlessTask);
6663
project.afterEvaluate(unused -> {
6764
spotlessTask.configure(task -> {
6865
// now that the task is being configured, we execute our actions
@@ -77,6 +74,7 @@ protected void createFormatTasks(String name, FormatExtension formatExtension) {
7774
// create the check and apply control tasks
7875
TaskProvider<SpotlessApply> applyTask = tasks.register(taskName + APPLY, SpotlessApply.class, task -> {
7976
task.init(spotlessTask.get());
77+
task.setGroup(TASK_GROUP);
8078
task.setEnabled(!isIdeHook);
8179
task.dependsOn(spotlessTask);
8280
});
@@ -91,6 +89,7 @@ protected void createFormatTasks(String name, FormatExtension formatExtension) {
9189

9290
TaskProvider<SpotlessCheck> checkTask = tasks.register(taskName + CHECK, SpotlessCheck.class, task -> {
9391
SpotlessTaskImpl source = spotlessTask.get();
92+
task.setGroup(TASK_GROUP);
9493
task.init(source);
9594
task.setEnabled(!isIdeHook);
9695
task.dependsOn(source);
@@ -103,8 +102,9 @@ protected void createFormatTasks(String name, FormatExtension formatExtension) {
103102
// create the diagnose task
104103
TaskProvider<SpotlessDiagnoseTask> diagnoseTask = tasks.register(taskName + DIAGNOSE, SpotlessDiagnoseTask.class, task -> {
105104
task.source = spotlessTask.get();
105+
task.setGroup(TASK_GROUP);
106+
task.mustRunAfter(BasePlugin.CLEAN_TASK_NAME);
106107
});
107-
SpotlessPlugin.taskMustRunAfterClean(project, diagnoseTask);
108108
rootDiagnoseTask.configure(task -> task.dependsOn(diagnoseTask));
109109
}
110110
}

plugin-gradle/src/main/java/com/diffplug/gradle/spotless/SpotlessPlugin.java

Lines changed: 3 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -15,14 +15,10 @@
1515
*/
1616
package com.diffplug.gradle.spotless;
1717

18-
import java.util.function.Consumer;
19-
2018
import org.gradle.api.GradleException;
2119
import org.gradle.api.Plugin;
2220
import org.gradle.api.Project;
2321
import org.gradle.api.plugins.BasePlugin;
24-
import org.gradle.api.tasks.Delete;
25-
import org.gradle.api.tasks.TaskProvider;
2622

2723
import com.diffplug.spotless.SpotlessCache;
2824

@@ -39,6 +35,8 @@ public void apply(Project project) {
3935
if (project.hasProperty(SPOTLESS_MODERN)) {
4036
project.getLogger().warn("'spotlessModern' has no effect as of Spotless 5.0, recommend removing it.");
4137
}
38+
// make sure there's a `clean` and a `check`
39+
project.getPlugins().apply(BasePlugin.class);
4240

4341
// setup the extension
4442
project.getExtensions().create(SpotlessExtension.class, SpotlessExtension.EXTENSION, SpotlessExtensionImpl.class, project);
@@ -50,26 +48,7 @@ public void apply(Project project) {
5048
//
5149
// we use System.identityHashCode() to avoid a memory leak by hanging on to the reference directly
5250
int cacheKey = System.identityHashCode(project.getRootProject());
53-
configureCleanTask(project, clean -> clean.doLast(unused -> SpotlessCache.clearOnce(cacheKey)));
54-
}
55-
56-
static void configureCleanTask(Project project, Consumer<Delete> onClean) {
57-
project.getTasks().withType(Delete.class).configureEach(clean -> {
58-
if (clean.getName().equals(BasePlugin.CLEAN_TASK_NAME)) {
59-
onClean.accept(clean);
60-
}
61-
});
62-
}
63-
64-
/** clean removes the SpotlessCache, so we have to run after clean. */
65-
static void taskMustRunAfterClean(Project project, TaskProvider<?> task) {
66-
if (project.getPlugins().hasPlugin(BasePlugin.class)) {
67-
// if we know that the clean task is around, then we can configure lazily
68-
task.configure(t -> t.mustRunAfter(BasePlugin.CLEAN_TASK_NAME));
69-
} else {
70-
// otherwise, we trigger configuration when the clean task gets configured
71-
configureCleanTask(project, clean -> task.get().mustRunAfter(clean));
72-
}
51+
project.getTasks().named(BasePlugin.CLEAN_TASK_NAME).configure(clean -> clean.doLast(unused -> SpotlessCache.clearOnce(cacheKey)));
7352
}
7453

7554
static String capitalize(String input) {

0 commit comments

Comments
 (0)