Skip to content

Commit

Permalink
Merge branch 'dependabot/gradle/com.facebook-ktfmt-0.35' into dependa…
Browse files Browse the repository at this point in the history
…bot/gradle/VER_KTLINT-0.45.2
  • Loading branch information
nedtwigg committed Apr 22, 2022
2 parents 6f520e6 + cb1a377 commit c4bb9d0
Show file tree
Hide file tree
Showing 11 changed files with 57 additions and 48 deletions.
7 changes: 6 additions & 1 deletion CHANGES.md
Expand Up @@ -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))

Expand Down
2 changes: 1 addition & 1 deletion lib/build.gradle
Expand Up @@ -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") {
Expand Down
14 changes: 10 additions & 4 deletions 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.
Expand All @@ -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;
Expand Down Expand Up @@ -115,8 +116,8 @@ private static void addIfAvailable(Collection<Charset> 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) {
Expand All @@ -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);
Expand All @@ -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;
}
}
Expand Up @@ -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:";
Expand Down
6 changes: 4 additions & 2 deletions 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.
Expand All @@ -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;

Expand All @@ -36,7 +37,7 @@ public static String name() {
}

public static String defaultVersion() {
return "19.10b0";
return "22.3.0";
}

private final String version;
Expand All @@ -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();
Expand Down
12 changes: 11 additions & 1 deletion plugin-gradle/CHANGES.md
Expand Up @@ -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<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.

## [6.4.2] - 2022-04-06
### Fixed
Expand Down
@@ -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.
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand Down
Expand Up @@ -29,14 +29,15 @@
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;

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.";

Expand Down
@@ -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.
Expand All @@ -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;
Expand All @@ -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));
}
});
}
Expand All @@ -60,9 +55,11 @@ protected void createFormatTasks(String name, FormatExtension formatExtension) {
String taskName = EXTENSION + SpotlessPlugin.capitalize(name);
TaskProvider<SpotlessTaskImpl> 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
Expand All @@ -77,6 +74,7 @@ protected void createFormatTasks(String name, FormatExtension formatExtension) {
// create the check and apply control tasks
TaskProvider<SpotlessApply> applyTask = tasks.register(taskName + APPLY, SpotlessApply.class, task -> {
task.init(spotlessTask.get());
task.setGroup(TASK_GROUP);
task.setEnabled(!isIdeHook);
task.dependsOn(spotlessTask);
});
Expand All @@ -91,6 +89,7 @@ protected void createFormatTasks(String name, FormatExtension formatExtension) {

TaskProvider<SpotlessCheck> 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);
Expand All @@ -103,8 +102,9 @@ protected void createFormatTasks(String name, FormatExtension formatExtension) {
// create the diagnose task
TaskProvider<SpotlessDiagnoseTask> 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));
}
}
Expand Up @@ -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;

Expand All @@ -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);
Expand All @@ -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<Delete> 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) {
Expand Down
7 changes: 6 additions & 1 deletion plugin-maven/CHANGES.md
Expand Up @@ -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))

Expand Down

0 comments on commit c4bb9d0

Please sign in to comment.