From 0be284494f88b514699a45a948612a19be33461f Mon Sep 17 00:00:00 2001 From: Lorenz Leutgeb Date: Mon, 15 Nov 2021 08:31:38 +0100 Subject: [PATCH 001/757] Upgrade Message: Print current version --- lib/src/main/java/com/diffplug/spotless/Jvm.java | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/lib/src/main/java/com/diffplug/spotless/Jvm.java b/lib/src/main/java/com/diffplug/spotless/Jvm.java index e22e0c6339..858d9d8d6c 100644 --- a/lib/src/main/java/com/diffplug/spotless/Jvm.java +++ b/lib/src/main/java/com/diffplug/spotless/Jvm.java @@ -198,8 +198,9 @@ private String buildUpgradeFormatterMessage(V fmtVersion) { StringBuilder builder = new StringBuilder(); V recommendedFmtVersionOrNull = getRecommendedFormatterVersion(); if (null != recommendedFmtVersionOrNull && (fmtVersionComparator.compare(fmtVersion, recommendedFmtVersionOrNull) < 0)) { - builder.append(String.format("You are not using latest version on JVM %d+.%n", getRequiredJvmVersion(recommendedFmtVersionOrNull))); - builder.append(String.format("Try to upgrade to %s %s, which may have fixed this problem.", fmtName, getRecommendedFormatterVersion())); + builder.append(String.format("%s %s is currently being used, but outdated.%n", fmtName, fmtVersion)); + builder.append(String.format("%s %s is the recommended version, which may have fixed this problem.%n", fmtName, recommendedFmtVersionOrNull)); + builder.append(String.format("%s %s requires JVM %d+.", fmtName, recommendedFmtVersionOrNull, getRequiredJvmVersion(recommendedFmtVersionOrNull))); } else { V higherFormatterVersionOrNull = fmt2jvmVersion.higherKey(fmtVersion); if (null != higherFormatterVersionOrNull) { From daf59fd5a8cb20472ed47c7a2767ca5008cf4f30 Mon Sep 17 00:00:00 2001 From: circleci Date: Tue, 1 Feb 2022 21:19:43 +0000 Subject: [PATCH 002/757] Published gradle/6.2.1 --- plugin-gradle/CHANGES.md | 2 ++ plugin-gradle/README.md | 46 ++++++++++++++++++++-------------------- 2 files changed, 25 insertions(+), 23 deletions(-) diff --git a/plugin-gradle/CHANGES.md b/plugin-gradle/CHANGES.md index dfd3133f2f..bf3d46dbd6 100644 --- a/plugin-gradle/CHANGES.md +++ b/plugin-gradle/CHANGES.md @@ -3,6 +3,8 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format (starting after version `3.27.0`). ## [Unreleased] + +## [6.2.1] - 2022-02-01 ### Changed * Bump default versions of formatters ([#1095](https://github.com/diffplug/spotless/pull/1095)). * google-java-format `1.12.0` -> `1.13.0` diff --git a/plugin-gradle/README.md b/plugin-gradle/README.md index 9515bb0381..df4c67c113 100644 --- a/plugin-gradle/README.md +++ b/plugin-gradle/README.md @@ -18,9 +18,9 @@ output = [ --> [![Gradle plugin](https://img.shields.io/badge/plugins.gradle.org-com.diffplug.spotless-blue.svg)](https://plugins.gradle.org/plugin/com.diffplug.spotless) [![Maven central](https://img.shields.io/badge/mavencentral-yes-blue.svg)](https://search.maven.org/#search%7Cgav%7C1%7Cg%3A%22com.diffplug.spotless%22%20AND%20a%3A%22spotless-plugin-gradle%22) -[![Javadoc](https://img.shields.io/badge/javadoc-yes-blue.svg)](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.2.0/index.html) +[![Javadoc](https://img.shields.io/badge/javadoc-yes-blue.svg)](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.2.1/index.html) [![License Apache](https://img.shields.io/badge/license-apache-blue.svg)](https://tldrlegal.com/license/apache-license-2.0-(apache-2.0)) -[![Changelog](https://img.shields.io/badge/changelog-6.2.0-blue.svg)](CHANGES.md) +[![Changelog](https://img.shields.io/badge/changelog-6.2.1-blue.svg)](CHANGES.md) [![Circle CI](https://circleci.com/gh/diffplug/spotless/tree/main.svg?style=shield)](https://circleci.com/gh/diffplug/spotless/tree/main) [![Live chat](https://img.shields.io/badge/gitter-chat-brightgreen.svg)](https://gitter.im/diffplug/spotless) @@ -126,10 +126,10 @@ spotless { ``` Spotless consists of a list of formats (in the example above, `misc` and `java`), and each format has: -- a `target` (the files to format), which you set with [`target`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.2.0/com/diffplug/gradle/spotless/FormatExtension.html#target-java.lang.Object...-) and [`targetExclude`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.2.0/com/diffplug/gradle/spotless/FormatExtension.html#targetExclude-java.lang.Object...-) -- a list of `FormatterStep`, which are just `String -> String` functions, such as [`replace`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.2.0/com/diffplug/gradle/spotless/FormatExtension.html#replace-java.lang.String-java.lang.CharSequence-java.lang.CharSequence-), [`replaceRegex`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.2.0/com/diffplug/gradle/spotless/FormatExtension.html#replaceRegex-java.lang.String-java.lang.String-java.lang.String-), [`trimTrailingWhitespace`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.2.0/com/diffplug/gradle/spotless/FormatExtension.html#replace-java.lang.String-java.lang.CharSequence-java.lang.CharSequence-), [`custom`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.2.0/com/diffplug/gradle/spotless/FormatExtension.html#custom-java.lang.String-groovy.lang.Closure-), [`prettier`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.2.0/com/diffplug/gradle/spotless/FormatExtension.html#prettier--), [`eclipseWtp`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.2.0/com/diffplug/gradle/spotless/FormatExtension.html#eclipseWtp-com.diffplug.spotless.extra.wtp.EclipseWtpFormatterStep-), [`licenseHeader`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.2.0/com/diffplug/gradle/spotless/FormatExtension.html#licenseHeader-java.lang.String-java.lang.String-) etc. +- a `target` (the files to format), which you set with [`target`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.2.1/com/diffplug/gradle/spotless/FormatExtension.html#target-java.lang.Object...-) and [`targetExclude`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.2.1/com/diffplug/gradle/spotless/FormatExtension.html#targetExclude-java.lang.Object...-) +- a list of `FormatterStep`, which are just `String -> String` functions, such as [`replace`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.2.1/com/diffplug/gradle/spotless/FormatExtension.html#replace-java.lang.String-java.lang.CharSequence-java.lang.CharSequence-), [`replaceRegex`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.2.1/com/diffplug/gradle/spotless/FormatExtension.html#replaceRegex-java.lang.String-java.lang.String-java.lang.String-), [`trimTrailingWhitespace`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.2.1/com/diffplug/gradle/spotless/FormatExtension.html#replace-java.lang.String-java.lang.CharSequence-java.lang.CharSequence-), [`custom`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.2.1/com/diffplug/gradle/spotless/FormatExtension.html#custom-java.lang.String-groovy.lang.Closure-), [`prettier`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.2.1/com/diffplug/gradle/spotless/FormatExtension.html#prettier--), [`eclipseWtp`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.2.1/com/diffplug/gradle/spotless/FormatExtension.html#eclipseWtp-com.diffplug.spotless.extra.wtp.EclipseWtpFormatterStep-), [`licenseHeader`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.2.1/com/diffplug/gradle/spotless/FormatExtension.html#licenseHeader-java.lang.String-java.lang.String-) etc. -All the generic steps live in [`FormatExtension`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.2.0/com/diffplug/gradle/spotless/FormatExtension.html), and there are many language-specific steps which live in its language-specific subclasses, which are described below. +All the generic steps live in [`FormatExtension`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.2.1/com/diffplug/gradle/spotless/FormatExtension.html), and there are many language-specific steps which live in its language-specific subclasses, which are described below. ### Requirements @@ -141,7 +141,7 @@ If you're stuck on an older version of Gradle, `id 'com.diffplug.gradle.spotless ## Java -`com.diffplug.gradle.spotless.JavaExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.2.0/com/diffplug/gradle/spotless/JavaExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/JavaExtension.java) +`com.diffplug.gradle.spotless.JavaExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.2.1/com/diffplug/gradle/spotless/JavaExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/JavaExtension.java) ```gradle spotless { @@ -248,8 +248,8 @@ spotless { ## Groovy -- `com.diffplug.gradle.spotless.GroovyExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.2.0/com/diffplug/gradle/spotless/GroovyExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/GroovyExtension.java) -- `com.diffplug.gradle.spotless.GroovyGradleExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.2.0/com/diffplug/gradle/spotless/GroovyGradleExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/GroovyGradleExtension.java) +- `com.diffplug.gradle.spotless.GroovyExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.2.1/com/diffplug/gradle/spotless/GroovyExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/GroovyExtension.java) +- `com.diffplug.gradle.spotless.GroovyGradleExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.2.1/com/diffplug/gradle/spotless/GroovyGradleExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/GroovyGradleExtension.java) Configuration for Groovy is similar to [Java](#java), in that it also supports `licenseHeader` and `importOrder`. @@ -300,8 +300,8 @@ Groovy-Eclipse formatting errors/warnings lead per default to a build failure. T ## Kotlin -- `com.diffplug.gradle.spotless.KotlinExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.2.0/com/diffplug/gradle/spotless/KotlinExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/KotlinExtension.java) -- `com.diffplug.gradle.spotless.KotlinGradleExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.2.0/com/diffplug/gradle/spotless/KotlinGradleExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/KotlinGradleExtension.java) +- `com.diffplug.gradle.spotless.KotlinExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.2.1/com/diffplug/gradle/spotless/KotlinExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/KotlinExtension.java) +- `com.diffplug.gradle.spotless.KotlinGradleExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.2.1/com/diffplug/gradle/spotless/KotlinGradleExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/KotlinGradleExtension.java) ```gradle spotless { // if you are using build.gradle.kts, instead of 'spotless {' use: @@ -359,7 +359,7 @@ spotless { ## Scala -`com.diffplug.gradle.spotless.ScalaExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.2.0/com/diffplug/gradle/spotless/ScalaExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/ScalaExtension.java) +`com.diffplug.gradle.spotless.ScalaExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.2.1/com/diffplug/gradle/spotless/ScalaExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/ScalaExtension.java) ```gradle spotless { @@ -391,7 +391,7 @@ spotless { ## C/C++ -`com.diffplug.gradle.spotless.CppExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.2.0/com/diffplug/gradle/spotless/CppExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/CppExtension.java) +`com.diffplug.gradle.spotless.CppExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.2.1/com/diffplug/gradle/spotless/CppExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/CppExtension.java) ```gradle spotless { @@ -423,7 +423,7 @@ spotles { ## Python -`com.diffplug.gradle.spotless.PythonExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.2.0/com/diffplug/gradle/spotless/PythonExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/PythonExtension.java) +`com.diffplug.gradle.spotless.PythonExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.2.1/com/diffplug/gradle/spotless/PythonExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/PythonExtension.java) ```gradle spotless { @@ -457,7 +457,7 @@ black().pathToExe('C:/myuser/.pyenv/versions/3.8.0/scripts/black.exe') ## FreshMark -`com.diffplug.gradle.spotless.FreshMarkExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.2.0/com/diffplug/gradle/spotless/FreshMarkExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/FreshMarkExtension.java) +`com.diffplug.gradle.spotless.FreshMarkExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.2.1/com/diffplug/gradle/spotless/FreshMarkExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/FreshMarkExtension.java) [homepage](https://github.com/diffplug/freshmark). [changelog](https://github.com/diffplug/freshmark/blob/master/CHANGES.md). FreshMark lets you generate markdown in the comments of your markdown. This helps to keep badges and links up-to-date (see the source for this file), and can also be helpful for generating complex tables (see the source for [the parent readme](../README.md)). @@ -478,7 +478,7 @@ spotless { ## Antlr4 -`com.diffplug.gradle.spotless.Antlr4Extension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.2.0/com/diffplug/gradle/spotless/Antlr4Extension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/Antlr4Extension.java) +`com.diffplug.gradle.spotless.Antlr4Extension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.2.1/com/diffplug/gradle/spotless/Antlr4Extension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/Antlr4Extension.java) ```gradle spotless { @@ -503,7 +503,7 @@ antlr4formatter('1.2.1') // version is optional ## SQL -`com.diffplug.gradle.spotless.SqlExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.2.0/com/diffplug/gradle/spotless/SqlExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/SqlExtension.java) +`com.diffplug.gradle.spotless.SqlExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.2.1/com/diffplug/gradle/spotless/SqlExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/SqlExtension.java) ```gradle spotless { @@ -543,7 +543,7 @@ sql.formatter.indent.size=4 ## Typescript -- `com.diffplug.gradle.spotless.TypescriptExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.2.0/com/diffplug/gradle/spotless/TypescriptExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/TypescriptExtension.java) +- `com.diffplug.gradle.spotless.TypescriptExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.2.1/com/diffplug/gradle/spotless/TypescriptExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/TypescriptExtension.java) ```gradle spotless { @@ -586,7 +586,7 @@ For details, see the [npm detection](#npm-detection) and [`.npmrc` detection](#n ## JSON -- `com.diffplug.gradle.spotless.JsonExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.2.0/com/diffplug/gradle/spotless/JsonExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/JsonExtension.java) +- `com.diffplug.gradle.spotless.JsonExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.2.1/com/diffplug/gradle/spotless/JsonExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/JsonExtension.java) ```gradle spotless { @@ -786,7 +786,7 @@ Once a file's license header has a valid year, whether it is a year (`2020`) or * `2017` -> `2017-2020` * `2017-2019` -> `2017-2020` -See the [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.2.0/com/diffplug/gradle/spotless/FormatExtension.LicenseHeaderConfig.html) for a complete listing of options. +See the [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.2.1/com/diffplug/gradle/spotless/FormatExtension.LicenseHeaderConfig.html) for a complete listing of options. @@ -853,9 +853,9 @@ spotless { custom 'lowercase', { str -> str.toLowerCase() } ``` -However, custom rules will disable up-to-date checking and caching, unless you read [this javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.2.0/com/diffplug/gradle/spotless/FormatExtension.html#bumpThisNumberIfACustomStepChanges-int-) and follow its instructions carefully. +However, custom rules will disable up-to-date checking and caching, unless you read [this javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.2.1/com/diffplug/gradle/spotless/FormatExtension.html#bumpThisNumberIfACustomStepChanges-int-) and follow its instructions carefully. -Another option is to create proper `FormatterStep` in your `buildSrc`, and then call [`addStep`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.2.0/com/diffplug/gradle/spotless/FormatExtension.html#addStep-com.diffplug.spotless.FormatterStep-). The contributing guide describes [how to do this](https://github.com/diffplug/spotless/blob/main/CONTRIBUTING.md#how-to-add-a-new-formatterstep). If the step is generally-useful, we hope you'll open a PR to share it! +Another option is to create proper `FormatterStep` in your `buildSrc`, and then call [`addStep`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.2.1/com/diffplug/gradle/spotless/FormatExtension.html#addStep-com.diffplug.spotless.FormatterStep-). The contributing guide describes [how to do this](https://github.com/diffplug/spotless/blob/main/CONTRIBUTING.md#how-to-add-a-new-formatterstep). If the step is generally-useful, we hope you'll open a PR to share it! ```gradle @@ -888,11 +888,11 @@ spotless { format 'foo', com.acme.FooLanguageExtension, { ``` -If you'd like to create a one-off Spotless task outside of the `check`/`apply` framework, see [`FormatExtension.createIndependentApplyTask`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.2.0/com/diffplug/gradle/spotless/FormatExtension.html#createIndependentApplyTask-java.lang.String-). +If you'd like to create a one-off Spotless task outside of the `check`/`apply` framework, see [`FormatExtension.createIndependentApplyTask`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.2.1/com/diffplug/gradle/spotless/FormatExtension.html#createIndependentApplyTask-java.lang.String-). ## Inception (languages within languages within...) -In very rare cases, you might want to format e.g. javascript which is written inside JSP templates, or maybe java within a markdown file, or something wacky like that. You can specify hunks within a file using either open/close tags or a regex with a single capturing group, and then specify rules within it, like so. See [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.2.0/com/diffplug/gradle/spotless/FormatExtension.html#withinBlocks-java.lang.String-java.lang.String-java.lang.String-org.gradle.api.Action-) for more details. +In very rare cases, you might want to format e.g. javascript which is written inside JSP templates, or maybe java within a markdown file, or something wacky like that. You can specify hunks within a file using either open/close tags or a regex with a single capturing group, and then specify rules within it, like so. See [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.2.1/com/diffplug/gradle/spotless/FormatExtension.html#withinBlocks-java.lang.String-java.lang.String-java.lang.String-org.gradle.api.Action-) for more details. ```gradle import com.diffplug.gradle.spotless.JavaExtension From 98d6ee9d55fddae4897ffd554b9d84cb2f07d2ac Mon Sep 17 00:00:00 2001 From: circleci Date: Tue, 1 Feb 2022 21:21:03 +0000 Subject: [PATCH 003/757] Published maven/2.20.1 --- plugin-maven/CHANGES.md | 2 ++ plugin-maven/README.md | 4 ++-- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/plugin-maven/CHANGES.md b/plugin-maven/CHANGES.md index 0a0de0dbee..583d5ce426 100644 --- a/plugin-maven/CHANGES.md +++ b/plugin-maven/CHANGES.md @@ -3,6 +3,8 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format (starting after version `1.27.0`). ## [Unreleased] + +## [2.20.1] - 2022-02-01 * Bump default versions of formatters ([#1095](https://github.com/diffplug/spotless/pull/1095)). * google-java-format `1.12.0` -> `1.13.0` * ktfmt `0.29` -> `0.30` diff --git a/plugin-maven/README.md b/plugin-maven/README.md index 0df3254aeb..986fa6c783 100644 --- a/plugin-maven/README.md +++ b/plugin-maven/README.md @@ -12,8 +12,8 @@ output = [ ].join('\n'); --> [![Maven central](https://img.shields.io/badge/mavencentral-com.diffplug.spotless%3Aspotless--maven--plugin-blue.svg)](https://search.maven.org/#search%7Cgav%7C1%7Cg%3A%22com.diffplug.spotless%22%20AND%20a%3A%22spotless-maven-plugin%22) -[![Javadoc](https://img.shields.io/badge/javadoc-yes-blue.svg)](https://javadoc.io/doc/com.diffplug.spotless/spotless-maven-plugin/2.20.0/index.html) -[![Changelog](https://img.shields.io/badge/changelog-2.20.0-brightgreen.svg)](CHANGES.md) +[![Javadoc](https://img.shields.io/badge/javadoc-yes-blue.svg)](https://javadoc.io/doc/com.diffplug.spotless/spotless-maven-plugin/2.20.1/index.html) +[![Changelog](https://img.shields.io/badge/changelog-2.20.1-brightgreen.svg)](CHANGES.md) [![Circle CI](https://circleci.com/gh/diffplug/spotless/tree/main.svg?style=shield)](https://circleci.com/gh/diffplug/spotless/tree/main) [![Live chat](https://img.shields.io/badge/gitter-chat-brightgreen.svg)](https://gitter.im/diffplug/spotless) From 8ec9caacdc3244dbdc49e09a80bfc6125977edb0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Javier=20Segovia=20C=C3=B3rdoba?= Date: Fri, 4 Feb 2022 00:48:03 +0100 Subject: [PATCH 004/757] Bump ktfmt 0.30 -> 0.31. --- .../diffplug/spotless/kotlin/KtfmtStep.java | 34 ++++++++++++++----- plugin-gradle/CHANGES.md | 2 ++ plugin-maven/CHANGES.md | 2 ++ 3 files changed, 30 insertions(+), 8 deletions(-) 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 b3ad0041f6..9f3b62dadb 100644 --- a/lib/src/main/java/com/diffplug/spotless/kotlin/KtfmtStep.java +++ b/lib/src/main/java/com/diffplug/spotless/kotlin/KtfmtStep.java @@ -32,7 +32,7 @@ public class KtfmtStep { // prevent direct instantiation private KtfmtStep() {} - private static final String DEFAULT_VERSION = "0.30"; + private static final String DEFAULT_VERSION = "0.31"; static final String NAME = "ktfmt"; static final String PACKAGE = "com.facebook"; static final String MAVEN_COORDINATE = PACKAGE + ":ktfmt:"; @@ -120,18 +120,16 @@ static final class State implements Serializable { FormatterFunc createFormat() throws Exception { ClassLoader classLoader = jarState.getClassLoader(); - Class formatterClazz = classLoader.loadClass(pkg + ".ktfmt.FormatterKt"); return input -> { try { if (style == DEFAULT) { - Method formatterMethod = formatterClazz.getMethod(FORMATTER_METHOD, String.class); - return (String) formatterMethod.invoke(formatterClazz, input); + Method formatterMethod = getFormatterClazz(classLoader).getMethod(FORMATTER_METHOD, String.class); + return (String) formatterMethod.invoke(getFormatterClazz(classLoader), input); } else { - Class formattingOptionsClazz = classLoader.loadClass(pkg + ".ktfmt.FormattingOptions"); - Method formatterMethod = formatterClazz.getMethod(FORMATTER_METHOD, formattingOptionsClazz, + Method formatterMethod = getFormatterClazz(classLoader).getMethod(FORMATTER_METHOD, getFormattingOptionsClazz(classLoader), String.class); Object formattingOptions = getCustomFormattingOptions(classLoader, style); - return (String) formatterMethod.invoke(formatterClazz, formattingOptions, input); + return (String) formatterMethod.invoke(getFormatterClazz(classLoader), formattingOptions, input); } } catch (InvocationTargetException e) { throw ThrowingEx.unwrapCause(e); @@ -146,7 +144,7 @@ private Object getCustomFormattingOptions(ClassLoader classLoader, Style style) try { // ktfmt v0.19 and later - return classLoader.loadClass(pkg + ".ktfmt.FormatterKt").getField(style.getFormat()).get(null); + return getFormatterClazz(classLoader).getField(style.getFormat()).get(null); } catch (NoSuchFieldException ignored) {} // fallback to old, pre-0.19 ktfmt interface. @@ -159,5 +157,25 @@ private Object getCustomFormattingOptions(ClassLoader classLoader, Style style) throw new IllegalStateException("Versions pre-0.19 can only use Default and Dropbox styles"); } } + + private Class getFormatterClazz(ClassLoader classLoader) throws Exception { + Class formatterClazz; + if (BadSemver.version(version) >= BadSemver.version(0, 31)) { + formatterClazz = classLoader.loadClass(pkg + ".ktfmt.format.Formatter"); + } else { + formatterClazz = classLoader.loadClass(pkg + ".ktfmt.FormatterKt"); + } + return formatterClazz; + } + + private Class getFormattingOptionsClazz(ClassLoader classLoader) throws Exception { + Class formattingOptionsClazz; + if (BadSemver.version(version) >= BadSemver.version(0, 31)) { + formattingOptionsClazz = classLoader.loadClass(pkg + ".ktfmt.format.FormattingOptions"); + } else { + formattingOptionsClazz = classLoader.loadClass(pkg + ".ktfmt.FormattingOptions"); + } + return formattingOptionsClazz; + } } } diff --git a/plugin-gradle/CHANGES.md b/plugin-gradle/CHANGES.md index bf3d46dbd6..69dc1bae1e 100644 --- a/plugin-gradle/CHANGES.md +++ b/plugin-gradle/CHANGES.md @@ -3,6 +3,8 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format (starting after version `3.27.0`). ## [Unreleased] +### Changed +* ktfmt `0.30` -> `0.31` ## [6.2.1] - 2022-02-01 ### Changed diff --git a/plugin-maven/CHANGES.md b/plugin-maven/CHANGES.md index 583d5ce426..61aba5d796 100644 --- a/plugin-maven/CHANGES.md +++ b/plugin-maven/CHANGES.md @@ -3,6 +3,8 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format (starting after version `1.27.0`). ## [Unreleased] +### Changed +* ktfmt `0.30` -> `0.31` ## [2.20.1] - 2022-02-01 * Bump default versions of formatters ([#1095](https://github.com/diffplug/spotless/pull/1095)). From c3a32ee26afa83ff04425b58736a0e4f8812563f Mon Sep 17 00:00:00 2001 From: Anton Klaren Date: Fri, 28 Jan 2022 12:05:28 +0100 Subject: [PATCH 005/757] Add support for worktrees Git supports using the same local repository for multiple checked-out worktrees. JGit does not fully support this, so we have to do some workarounds for it to work. The previous workaround provided by #965 did not take `commondir` into consideration, which is the location of a few files. --- .../extra/GitAttributesLineEndings.java | 40 ++-- .../spotless/extra/GitWorkarounds.java | 172 +++++++++++++++--- .../spotless/extra/GitAttributesTest.java | 51 +++++- .../spotless/extra/GitWorkaroundsTest.java | 124 +++++++++++++ 4 files changed, 330 insertions(+), 57 deletions(-) create mode 100644 lib-extra/src/test/java/com/diffplug/spotless/extra/GitWorkaroundsTest.java diff --git a/lib-extra/src/main/java/com/diffplug/spotless/extra/GitAttributesLineEndings.java b/lib-extra/src/main/java/com/diffplug/spotless/extra/GitAttributesLineEndings.java index 11ed730e6d..4aab23e142 100644 --- a/lib-extra/src/main/java/com/diffplug/spotless/extra/GitAttributesLineEndings.java +++ b/lib-extra/src/main/java/com/diffplug/spotless/extra/GitAttributesLineEndings.java @@ -38,10 +38,10 @@ import org.eclipse.jgit.lib.Config; import org.eclipse.jgit.lib.ConfigConstants; import org.eclipse.jgit.lib.Constants; +import org.eclipse.jgit.lib.CoreConfig; import org.eclipse.jgit.lib.CoreConfig.AutoCRLF; import org.eclipse.jgit.lib.CoreConfig.EOL; import org.eclipse.jgit.storage.file.FileBasedConfig; -import org.eclipse.jgit.storage.file.FileRepositoryBuilder; import org.eclipse.jgit.util.FS; import org.eclipse.jgit.util.SystemReader; @@ -52,6 +52,7 @@ import com.diffplug.spotless.FileSignature; import com.diffplug.spotless.LazyForwardingEquality; import com.diffplug.spotless.LineEnding; +import com.diffplug.spotless.extra.GitWorkarounds.RepositorySpecificResolver; import edu.umd.cs.findbugs.annotations.SuppressFBWarnings; @@ -132,8 +133,11 @@ public String endingFor(File file) { } static class RuntimeInit { - /** /etc/gitconfig (system-global), ~/.gitconfig, project/.git/config (each might-not exist). */ - final FileBasedConfig systemConfig, userConfig, repoConfig; + /** /etc/gitconfig (system-global), ~/.gitconfig (each might-not exist). */ + final FileBasedConfig systemConfig, userConfig; + + /** Repository specific config, can be $GIT_COMMON_DIR/config, project/.git/config or .git/worktrees//config.worktree if enabled by extension */ + final Config repoConfig; /** Global .gitattributes file pointed at by systemConfig or userConfig, and the file in the repo. */ final @Nullable File globalAttributesFile, repoAttributesFile; @@ -142,7 +146,7 @@ static class RuntimeInit { final @Nullable File workTree; @SuppressFBWarnings("SIC_INNER_SHOULD_BE_STATIC_ANON") - RuntimeInit(File projectDir, Iterable toFormat) throws IOException { + RuntimeInit(File projectDir, Iterable toFormat) { requireElementsNonNull(toFormat); ///////////////////////////////// // USER AND SYSTEM-WIDE VALUES // @@ -152,9 +156,8 @@ static class RuntimeInit { userConfig = SystemReader.getInstance().openUserConfig(systemConfig, FS.DETECTED); Errors.log().run(userConfig::load); - // copy-pasted from org.eclipse.jgit.lib.CoreConfig - String globalAttributesPath = userConfig.getString(ConfigConstants.CONFIG_CORE_SECTION, null, ConfigConstants.CONFIG_KEY_ATTRIBUTESFILE); // copy-pasted from org.eclipse.jgit.internal.storage.file.GlobalAttributesNode + String globalAttributesPath = userConfig.get(CoreConfig.KEY).getAttributesFile(); if (globalAttributesPath != null) { FS fs = FS.detect(); if (globalAttributesPath.startsWith("~/")) { //$NON-NLS-1$ @@ -169,29 +172,16 @@ static class RuntimeInit { ////////////////////////// // REPO-SPECIFIC VALUES // ////////////////////////// - FileRepositoryBuilder builder = GitWorkarounds.fileRepositoryBuilderForProject(projectDir); - if (builder.getGitDir() != null) { - workTree = builder.getWorkTree(); - repoConfig = new FileBasedConfig(userConfig, new File(builder.getGitDir(), Constants.CONFIG), FS.DETECTED); - repoAttributesFile = new File(builder.getGitDir(), Constants.INFO_ATTRIBUTES); + RepositorySpecificResolver repositoryResolver = GitWorkarounds.fileRepositoryResolverForProject(projectDir); + if (repositoryResolver.getGitDir() != null) { + workTree = repositoryResolver.getWorkTree(); + repoConfig = repositoryResolver.getRepositoryConfig(); + repoAttributesFile = repositoryResolver.resolveWithCommonDir(Constants.INFO_ATTRIBUTES); } else { workTree = null; - // null would make repoConfig.getFile() bomb below - repoConfig = new FileBasedConfig(userConfig, null, FS.DETECTED) { - @Override - public void load() { - // empty, do not load - } - - @Override - public boolean isOutdated() { - // regular class would bomb here - return false; - } - }; + repoConfig = new Config(); repoAttributesFile = null; } - Errors.log().run(repoConfig::load); } private Runtime atRuntime() { diff --git a/lib-extra/src/main/java/com/diffplug/spotless/extra/GitWorkarounds.java b/lib-extra/src/main/java/com/diffplug/spotless/extra/GitWorkarounds.java index ee13fefc81..123ca64510 100644 --- a/lib-extra/src/main/java/com/diffplug/spotless/extra/GitWorkarounds.java +++ b/lib-extra/src/main/java/com/diffplug/spotless/extra/GitWorkarounds.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. @@ -17,17 +17,25 @@ import java.io.File; import java.io.IOException; -import java.nio.charset.StandardCharsets; -import java.nio.file.Files; import javax.annotation.Nullable; +import org.eclipse.jgit.errors.ConfigInvalidException; +import org.eclipse.jgit.lib.Config; +import org.eclipse.jgit.lib.ConfigConstants; +import org.eclipse.jgit.lib.Constants; +import org.eclipse.jgit.storage.file.FileBasedConfig; import org.eclipse.jgit.storage.file.FileRepositoryBuilder; +import org.eclipse.jgit.util.IO; +import org.eclipse.jgit.util.RawParseUtils; +import org.eclipse.jgit.util.SystemReader; + +import com.diffplug.common.base.Errors; /** * Utility methods for Git workarounds. */ -public class GitWorkarounds { +public final class GitWorkarounds { private GitWorkarounds() {} /** @@ -40,46 +48,154 @@ private GitWorkarounds() {} * @return the path to the .git directory. */ static @Nullable File getDotGitDir(File projectDir) { - return fileRepositoryBuilderForProject(projectDir).getGitDir(); + return fileRepositoryResolverForProject(projectDir).getGitDir(); } /** - * Creates a {@link FileRepositoryBuilder} for the given project directory. + * Creates a {@link RepositorySpecificResolver} for the given project directory. * * This applies a workaround for JGit not supporting worktrees properly. * * @param projectDir the project directory. * @return the builder. */ - static FileRepositoryBuilder fileRepositoryBuilderForProject(File projectDir) { - FileRepositoryBuilder builder = new FileRepositoryBuilder(); - builder.findGitDir(projectDir); - File gitDir = builder.getGitDir(); - if (gitDir != null) { - builder.setGitDir(resolveRealGitDirIfWorktreeDir(gitDir)); + static RepositorySpecificResolver fileRepositoryResolverForProject(File projectDir) { + RepositorySpecificResolver repositoryResolver = new RepositorySpecificResolver(); + repositoryResolver.findGitDir(projectDir); + repositoryResolver.readEnvironment(); + if (repositoryResolver.getGitDir() != null || repositoryResolver.getWorkTree() != null) { + Errors.rethrow().get(repositoryResolver::setup); } - return builder; + return repositoryResolver; } /** - * If the dir is a worktree directory (typically .git/worktrees/something) then - * returns the actual .git directory. + * Piggyback on the {@link FileRepositoryBuilder} mechanics for finding the git directory. * - * @param dir the directory which may be a worktree directory or may be a .git directory. - * @return the .git directory. + * Here we take into account that git repositories can share a common directory. This directory + * will contain ./config ./objects/, ./info/, and ./refs/. */ - private static File resolveRealGitDirIfWorktreeDir(File dir) { - File pointerFile = new File(dir, "gitdir"); - if (pointerFile.isFile()) { - try { - String content = new String(Files.readAllBytes(pointerFile.toPath()), StandardCharsets.UTF_8).trim(); - return new File(content); - } catch (IOException e) { - System.err.println("failed to parse git meta: " + e.getMessage()); - return dir; + static class RepositorySpecificResolver extends FileRepositoryBuilder { + /** + * The common directory file is used to define $GIT_COMMON_DIR if environment variable is not set. + * https://github.com/git/git/blob/b23dac905bde28da47543484320db16312c87551/Documentation/gitrepository-layout.txt#L259 + */ + private static final String COMMON_DIR = "commondir"; + private static final String GIT_COMMON_DIR_ENV_KEY = "GIT_COMMON_DIR"; + + /** + * Using an extension it is possible to have per-worktree config. + * https://github.com/git/git/blob/b23dac905bde28da47543484320db16312c87551/Documentation/git-worktree.txt#L366 + */ + private static final String EXTENSIONS_WORKTREE_CONFIG = "worktreeConfig"; + private static final String EXTENSIONS_WORKTREE_CONFIG_FILENAME = "config.worktree"; + + private File commonDirectory; + + /** @return the repository specific configuration. */ + Config getRepositoryConfig() { + return Errors.rethrow().get(this::getConfig); + } + + /** + * @return the repository's configuration. + * @throws IOException on errors accessing the configuration file. + * @throws IllegalArgumentException on malformed configuration. + */ + @Override + protected Config loadConfig() throws IOException { + if (getGitDir() != null) { + File path = resolveWithCommonDir(Constants.CONFIG); + FileBasedConfig cfg = new FileBasedConfig(path, safeFS()); + try { + cfg.load(); + + // Check for per-worktree config, it should be parsed after the common config + if (cfg.getBoolean(ConfigConstants.CONFIG_EXTENSIONS_SECTION, EXTENSIONS_WORKTREE_CONFIG, false)) { + File worktreeSpecificConfig = safeFS().resolve(getGitDir(), EXTENSIONS_WORKTREE_CONFIG_FILENAME); + if (safeFS().exists(worktreeSpecificConfig) && safeFS().isFile(worktreeSpecificConfig)) { + // It is important to base this on the common config, as both the common config and the per-worktree config should be used + cfg = new FileBasedConfig(cfg, worktreeSpecificConfig, safeFS()); + try { + cfg.load(); + } catch (ConfigInvalidException err) { + throw new IllegalArgumentException("Failed to parse config " + worktreeSpecificConfig.getAbsolutePath(), err); + } + } + } + } catch (ConfigInvalidException err) { + throw new IllegalArgumentException("Failed to parse config " + path.getAbsolutePath(), err); + } + return cfg; + } + return super.loadConfig(); + } + + @Override + protected void setupGitDir() throws IOException { + super.setupGitDir(); + + // Setup common directory + if (commonDirectory == null) { + File commonDirFile = safeFS().resolve(getGitDir(), COMMON_DIR); + if (safeFS().exists(commonDirFile) && safeFS().isFile(commonDirFile)) { + byte[] content = IO.readFully(commonDirFile); + if (content.length < 1) { + throw emptyFile(commonDirFile); + } + + int lineEnd = RawParseUtils.nextLF(content, 0); + while (content[lineEnd - 1] == '\n' || (content[lineEnd - 1] == '\r' && SystemReader.getInstance().isWindows())) { + lineEnd--; + } + if (lineEnd <= 1) { + throw emptyFile(commonDirFile); + } + + String commonPath = RawParseUtils.decode(content, 0, lineEnd); + File common = new File(commonPath); + if (common.isAbsolute()) { + commonDirectory = common; + } else { + commonDirectory = safeFS().resolve(getGitDir(), commonPath).getCanonicalFile(); + } + } + } + + // Setup object directory + if (getObjectDirectory() == null) { + setObjectDirectory(resolveWithCommonDir(Constants.OBJECTS)); + } + } + + private static IOException emptyFile(File commonDir) { + return new IOException("Empty 'commondir' file: " + commonDir.getAbsolutePath()); + } + + @Override + public FileRepositoryBuilder readEnvironment(SystemReader sr) { + super.readEnvironment(sr); + + // Always overwrite, will trump over the common dir file + String val = sr.getenv(GIT_COMMON_DIR_ENV_KEY); + if (val != null) { + commonDirectory = new File(val); + } + + return self(); + } + + /** + * For repository with multiple linked worktrees some data might be shared in a "common" directory. + * + * @param target the file we want to resolve. + * @return a file resolved from the {@link #getGitDir()}, or possibly in the path specified by $GIT_COMMON_DIR or {@code commondir} file. + */ + File resolveWithCommonDir(String target) { + if (commonDirectory != null) { + return safeFS().resolve(commonDirectory, target); } - } else { - return dir; + return safeFS().resolve(getGitDir(), target); } } } diff --git a/lib-extra/src/test/java/com/diffplug/spotless/extra/GitAttributesTest.java b/lib-extra/src/test/java/com/diffplug/spotless/extra/GitAttributesTest.java index 330a432d40..ed657c365a 100644 --- a/lib-extra/src/test/java/com/diffplug/spotless/extra/GitAttributesTest.java +++ b/lib-extra/src/test/java/com/diffplug/spotless/extra/GitAttributesTest.java @@ -32,12 +32,13 @@ import com.diffplug.spotless.ResourceHarness; class GitAttributesTest extends ResourceHarness { - private List testFiles() { + private List testFiles(String prefix) { try { List result = new ArrayList<>(); for (String path : TEST_PATHS) { - setFile(path).toContent(""); - result.add(newFile(path)); + String prefixedPath = prefix + path; + setFile(prefixedPath).toContent(""); + result.add(newFile(prefixedPath)); } return result; } catch (IOException e) { @@ -45,7 +46,11 @@ private List testFiles() { } } - private static List TEST_PATHS = Arrays.asList("someFile", "subfolder/someFile", "MANIFEST.MF", "subfolder/MANIFEST.MF"); + private List testFiles() { + return testFiles(""); + } + + private static final List TEST_PATHS = Arrays.asList("someFile", "subfolder/someFile", "MANIFEST.MF", "subfolder/MANIFEST.MF"); @Test void cacheTest() throws IOException { @@ -101,4 +106,42 @@ void policyDefaultLineEndingTest() throws GitAPIException, IOException { LineEnding.Policy policy = LineEnding.GIT_ATTRIBUTES.createPolicy(rootFolder(), () -> testFiles()); Assertions.assertThat(policy.getEndingFor(newFile("someFile"))).isEqualTo("\r\n"); } + + @Test + void policyTestWithExternalGitDir() throws IOException, GitAPIException { + File projectFolder = newFolder("project"); + File gitDir = newFolder("project.git"); + Git.init().setDirectory(projectFolder).setGitDir(gitDir).call(); + + setFile("project.git/info/attributes").toContent(StringPrinter.buildStringFromLines( + "* eol=lf", + "*.MF eol=crlf")); + LineEnding.Policy policy = LineEnding.GIT_ATTRIBUTES.createPolicy(projectFolder, () -> testFiles("project/")); + Assertions.assertThat(policy.getEndingFor(newFile("project/someFile"))).isEqualTo("\n"); + Assertions.assertThat(policy.getEndingFor(newFile("project/subfolder/someFile"))).isEqualTo("\n"); + Assertions.assertThat(policy.getEndingFor(newFile("project/MANIFEST.MF"))).isEqualTo("\r\n"); + Assertions.assertThat(policy.getEndingFor(newFile("project/subfolder/MANIFEST.MF"))).isEqualTo("\r\n"); + } + + @Test + void policyTestWithCommonDir() throws IOException, GitAPIException { + File projectFolder = newFolder("project"); + File commonGitDir = newFolder("project.git"); + Git.init().setDirectory(projectFolder).setGitDir(commonGitDir).call(); + newFolder("project.git/worktrees/"); + + File projectGitDir = newFolder("project.git/worktrees/project/"); + setFile("project.git/worktrees/project/gitdir").toContent(projectFolder.getAbsolutePath() + "/.git"); + setFile("project.git/worktrees/project/commondir").toContent("../.."); + setFile("project/.git").toContent("gitdir: " + projectGitDir.getAbsolutePath()); + + setFile("project.git/info/attributes").toContent(StringPrinter.buildStringFromLines( + "* eol=lf", + "*.MF eol=crlf")); + LineEnding.Policy policy = LineEnding.GIT_ATTRIBUTES.createPolicy(projectFolder, () -> testFiles("project/")); + Assertions.assertThat(policy.getEndingFor(newFile("project/someFile"))).isEqualTo("\n"); + Assertions.assertThat(policy.getEndingFor(newFile("project/subfolder/someFile"))).isEqualTo("\n"); + Assertions.assertThat(policy.getEndingFor(newFile("project/MANIFEST.MF"))).isEqualTo("\r\n"); + Assertions.assertThat(policy.getEndingFor(newFile("project/subfolder/MANIFEST.MF"))).isEqualTo("\r\n"); + } } diff --git a/lib-extra/src/test/java/com/diffplug/spotless/extra/GitWorkaroundsTest.java b/lib-extra/src/test/java/com/diffplug/spotless/extra/GitWorkaroundsTest.java new file mode 100644 index 0000000000..a90716f5de --- /dev/null +++ b/lib-extra/src/test/java/com/diffplug/spotless/extra/GitWorkaroundsTest.java @@ -0,0 +1,124 @@ +/* + * Copyright 2022 DiffPlug + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.diffplug.spotless.extra; + +import java.io.File; +import java.io.IOException; + +import org.assertj.core.api.Assertions; +import org.eclipse.jgit.api.Git; +import org.eclipse.jgit.api.errors.GitAPIException; +import org.eclipse.jgit.lib.Constants; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.DisplayName; +import org.junit.jupiter.api.Nested; +import org.junit.jupiter.api.Test; + +import com.diffplug.spotless.ResourceHarness; +import com.diffplug.spotless.extra.GitWorkarounds.RepositorySpecificResolver; + +class GitWorkaroundsTest extends ResourceHarness { + @Test + void inline() throws IOException, GitAPIException { + File projectFolder = newFolder("project"); + Git.init().setDirectory(projectFolder).call(); + + RepositorySpecificResolver repositorySpecificResolver = GitWorkarounds.fileRepositoryResolverForProject(projectFolder); + Assertions.assertThat(repositorySpecificResolver.getGitDir()).isEqualTo(new File(projectFolder, ".git")); + } + + @Test + void external() throws IOException, GitAPIException { + File projectFolder = newFolder("project"); + File gitDir = newFolder("project.git"); + Git.init().setDirectory(projectFolder).setGitDir(gitDir).call(); + + RepositorySpecificResolver repositorySpecificResolver = GitWorkarounds.fileRepositoryResolverForProject(projectFolder); + Assertions.assertThat(repositorySpecificResolver.getGitDir()).isEqualTo(gitDir); + } + + @Nested + @DisplayName("Worktrees") + class Worktrees { + private File project1Tree; + private File project1GitDir; + private File project2Tree; + private File project2GitDir; + private File commonGitDir; + + @BeforeEach + void setUp() throws IOException, GitAPIException { + project1Tree = newFolder("project-w1"); + project2Tree = newFolder("project-w2"); + commonGitDir = newFolder("project.git"); + Git.init().setDirectory(project1Tree).setGitDir(commonGitDir).call(); + + // Setup worktrees manually since JGit does not support it + newFolder("project.git/worktrees/"); + + project1GitDir = newFolder("project.git/worktrees/project-w1/"); + setFile("project.git/worktrees/project-w1/gitdir").toContent(project1Tree.getAbsolutePath() + "/.git"); + setFile("project.git/worktrees/project-w1/commondir").toContent("../.."); // Relative path + setFile("project-w1/.git").toContent("gitdir: " + project1GitDir.getAbsolutePath()); + + project2GitDir = newFolder("project.git/worktrees/project-w2/"); + setFile("project.git/worktrees/project-w2/gitdir").toContent(project2Tree.getAbsolutePath() + "/.git"); + setFile("project.git/worktrees/project-w2/commondir").toContent(commonGitDir.getAbsolutePath()); // Absolute path + setFile("project-w2/.git").toContent("gitdir: " + project2GitDir.getAbsolutePath()); + } + + @Test + void resolveGitDir() { + // Test worktree 1 + { + RepositorySpecificResolver repositorySpecificResolver = GitWorkarounds.fileRepositoryResolverForProject(project1Tree); + Assertions.assertThat(repositorySpecificResolver.getGitDir()).isEqualTo(project1GitDir); + Assertions.assertThat(repositorySpecificResolver.resolveWithCommonDir(Constants.CONFIG)).isEqualTo(new File(commonGitDir, Constants.CONFIG)); + } + + // Test worktree 2 + { + RepositorySpecificResolver repositorySpecificResolver = GitWorkarounds.fileRepositoryResolverForProject(project2Tree); + Assertions.assertThat(repositorySpecificResolver.getGitDir()).isEqualTo(project2GitDir); + Assertions.assertThat(repositorySpecificResolver.resolveWithCommonDir(Constants.CONFIG)).isEqualTo(new File(commonGitDir, Constants.CONFIG)); + } + } + + @Test + void perWorktreeConfig() throws IOException { + setFile("project.git/config").toLines("[core]", "mySetting = true"); + + Assertions.assertThat(getMySetting(project1Tree)).isTrue(); + Assertions.assertThat(getMySetting(project2Tree)).isTrue(); + + // Override setting for project 1, but don't enable extension yet + setFile("project.git/worktrees/project-w1/config.worktree").toLines("[core]", "mySetting = false"); + + Assertions.assertThat(getMySetting(project1Tree)).isTrue(); + Assertions.assertThat(getMySetting(project2Tree)).isTrue(); + + // Enable extension + setFile("project.git/config").toLines("[core]", "mySetting = true", "[extensions]", "worktreeConfig = true"); + + Assertions.assertThat(getMySetting(project1Tree)).isFalse(); // Should now be overridden by config.worktree + Assertions.assertThat(getMySetting(project2Tree)).isTrue(); + } + + private boolean getMySetting(File projectDir) { + return GitWorkarounds.fileRepositoryResolverForProject(projectDir).getRepositoryConfig().getBoolean("core", "mySetting", false); + } + } +} From 4b47e1c6d7e3d9d6d9968631c47a843bd18f782f Mon Sep 17 00:00:00 2001 From: Anton Klaren Date: Fri, 4 Feb 2022 13:51:29 +0100 Subject: [PATCH 006/757] Update changelog --- CHANGES.md | 1 + plugin-gradle/CHANGES.md | 1 + plugin-maven/CHANGES.md | 1 + 3 files changed, 3 insertions(+) diff --git a/CHANGES.md b/CHANGES.md index cc19ae2acc..f64b05cb26 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -10,6 +10,7 @@ This document is intended for Spotless developers. We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format (starting after version `1.27.0`). ## [Unreleased] +# Add full support for git worktrees ([#1119](https://github.com/diffplug/spotless/pull/1119)) ## [2.22.1] - 2022-02-01 ### Changed diff --git a/plugin-gradle/CHANGES.md b/plugin-gradle/CHANGES.md index bf3d46dbd6..8a68af888d 100644 --- a/plugin-gradle/CHANGES.md +++ b/plugin-gradle/CHANGES.md @@ -3,6 +3,7 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format (starting after version `3.27.0`). ## [Unreleased] +# Add full support for git worktrees ([#1119](https://github.com/diffplug/spotless/pull/1119)) ## [6.2.1] - 2022-02-01 ### Changed diff --git a/plugin-maven/CHANGES.md b/plugin-maven/CHANGES.md index 583d5ce426..113a6d580c 100644 --- a/plugin-maven/CHANGES.md +++ b/plugin-maven/CHANGES.md @@ -3,6 +3,7 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format (starting after version `1.27.0`). ## [Unreleased] +# Add full support for git worktrees ([#1119](https://github.com/diffplug/spotless/pull/1119)) ## [2.20.1] - 2022-02-01 * Bump default versions of formatters ([#1095](https://github.com/diffplug/spotless/pull/1095)). From 9d3a4bdf7d9ad1aa391496acace9e95eaab33995 Mon Sep 17 00:00:00 2001 From: Ned Twigg Date: Tue, 8 Feb 2022 15:46:02 -0800 Subject: [PATCH 007/757] Update changelogs. --- CHANGES.md | 2 ++ plugin-gradle/CHANGES.md | 2 +- plugin-maven/CHANGES.md | 2 +- 3 files changed, 4 insertions(+), 2 deletions(-) diff --git a/CHANGES.md b/CHANGES.md index cc19ae2acc..a431ee8c18 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -10,6 +10,8 @@ This document is intended for Spotless developers. We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format (starting after version `1.27.0`). ## [Unreleased] +### Changed +* Bump default ktfmt `0.30` -> `0.31` ([#1118](https://github.com/diffplug/spotless/pull/1118)). ## [2.22.1] - 2022-02-01 ### Changed diff --git a/plugin-gradle/CHANGES.md b/plugin-gradle/CHANGES.md index 69dc1bae1e..265b77084f 100644 --- a/plugin-gradle/CHANGES.md +++ b/plugin-gradle/CHANGES.md @@ -4,7 +4,7 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format ( ## [Unreleased] ### Changed -* ktfmt `0.30` -> `0.31` +* Bump default ktfmt `0.30` -> `0.31` ([#1118](https://github.com/diffplug/spotless/pull/1118)). ## [6.2.1] - 2022-02-01 ### Changed diff --git a/plugin-maven/CHANGES.md b/plugin-maven/CHANGES.md index 61aba5d796..a506bf17d1 100644 --- a/plugin-maven/CHANGES.md +++ b/plugin-maven/CHANGES.md @@ -4,7 +4,7 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format ( ## [Unreleased] ### Changed -* ktfmt `0.30` -> `0.31` +* Bump default ktfmt `0.30` -> `0.31` ([#1118](https://github.com/diffplug/spotless/pull/1118)). ## [2.20.1] - 2022-02-01 * Bump default versions of formatters ([#1095](https://github.com/diffplug/spotless/pull/1095)). From 68893214eee8569219e695a26771b15e41305ccc Mon Sep 17 00:00:00 2001 From: Ned Twigg Date: Tue, 8 Feb 2022 16:07:07 -0800 Subject: [PATCH 008/757] Fix spotbugs warning. --- .../main/java/com/diffplug/spotless/extra/GitWorkarounds.java | 3 +++ 1 file changed, 3 insertions(+) diff --git a/lib-extra/src/main/java/com/diffplug/spotless/extra/GitWorkarounds.java b/lib-extra/src/main/java/com/diffplug/spotless/extra/GitWorkarounds.java index 123ca64510..a66650b38f 100644 --- a/lib-extra/src/main/java/com/diffplug/spotless/extra/GitWorkarounds.java +++ b/lib-extra/src/main/java/com/diffplug/spotless/extra/GitWorkarounds.java @@ -32,6 +32,8 @@ import com.diffplug.common.base.Errors; +import edu.umd.cs.findbugs.annotations.SuppressFBWarnings; + /** * Utility methods for Git workarounds. */ @@ -172,6 +174,7 @@ private static IOException emptyFile(File commonDir) { return new IOException("Empty 'commondir' file: " + commonDir.getAbsolutePath()); } + @SuppressFBWarnings(value = "BC_UNCONFIRMED_CAST_OF_RETURN_VALUE") @Override public FileRepositoryBuilder readEnvironment(SystemReader sr) { super.readEnvironment(sr); From 27d16456d0fb32ea7f842ca08e0cddfe0698118f Mon Sep 17 00:00:00 2001 From: Ned Twigg Date: Tue, 8 Feb 2022 16:16:29 -0800 Subject: [PATCH 009/757] Oops, fix the changelog entries. --- CHANGES.md | 2 ++ plugin-gradle/CHANGES.md | 2 ++ plugin-maven/CHANGES.md | 2 ++ 3 files changed, 6 insertions(+) diff --git a/CHANGES.md b/CHANGES.md index a431ee8c18..64f1e42e37 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -12,6 +12,8 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format ( ## [Unreleased] ### Changed * Bump default ktfmt `0.30` -> `0.31` ([#1118](https://github.com/diffplug/spotless/pull/1118)). +### Fixed +* Add full support for git worktrees ([#1119](https://github.com/diffplug/spotless/pull/1119)). ## [2.22.1] - 2022-02-01 ### Changed diff --git a/plugin-gradle/CHANGES.md b/plugin-gradle/CHANGES.md index 265b77084f..ee6a753893 100644 --- a/plugin-gradle/CHANGES.md +++ b/plugin-gradle/CHANGES.md @@ -5,6 +5,8 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format ( ## [Unreleased] ### Changed * Bump default ktfmt `0.30` -> `0.31` ([#1118](https://github.com/diffplug/spotless/pull/1118)). +### Fixed +* Add full support for git worktrees ([#1119](https://github.com/diffplug/spotless/pull/1119)). ## [6.2.1] - 2022-02-01 ### Changed diff --git a/plugin-maven/CHANGES.md b/plugin-maven/CHANGES.md index a506bf17d1..07021c68ef 100644 --- a/plugin-maven/CHANGES.md +++ b/plugin-maven/CHANGES.md @@ -5,6 +5,8 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format ( ## [Unreleased] ### Changed * Bump default ktfmt `0.30` -> `0.31` ([#1118](https://github.com/diffplug/spotless/pull/1118)). +### Fixed +* Add full support for git worktrees ([#1119](https://github.com/diffplug/spotless/pull/1119)). ## [2.20.1] - 2022-02-01 * Bump default versions of formatters ([#1095](https://github.com/diffplug/spotless/pull/1095)). From 6a03212a6fdb8417b41b54c5e1436558e798cb9b Mon Sep 17 00:00:00 2001 From: Ned Twigg Date: Tue, 8 Feb 2022 16:16:44 -0800 Subject: [PATCH 010/757] Double the Gradle metaspace to help with flaky CI. --- gradle.properties | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gradle.properties b/gradle.properties index fcad5c5ed4..032beae95c 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1,5 +1,5 @@ # To fix metaspace errors -org.gradle.jvmargs=-Xmx2g -XX:MaxMetaspaceSize=512m -Dfile.encoding=UTF-8 +org.gradle.jvmargs=-Xmx2g -XX:MaxMetaspaceSize=1024m -Dfile.encoding=UTF-8 name=spotless description=Spotless - keep your code spotless with Gradle org=diffplug From 19d271c641aab4b16af67287ed835d91e5e076e0 Mon Sep 17 00:00:00 2001 From: circleci Date: Wed, 9 Feb 2022 00:59:32 +0000 Subject: [PATCH 011/757] Published lib/2.22.2 --- CHANGES.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/CHANGES.md b/CHANGES.md index 64f1e42e37..29fd6d9375 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -10,6 +10,8 @@ This document is intended for Spotless developers. We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format (starting after version `1.27.0`). ## [Unreleased] + +## [2.22.2] - 2022-02-09 ### Changed * Bump default ktfmt `0.30` -> `0.31` ([#1118](https://github.com/diffplug/spotless/pull/1118)). ### Fixed From 87861ac19be3c206f97332e6a19e3c912620c050 Mon Sep 17 00:00:00 2001 From: circleci Date: Wed, 9 Feb 2022 01:00:29 +0000 Subject: [PATCH 012/757] Published gradle/6.2.2 --- plugin-gradle/CHANGES.md | 2 ++ plugin-gradle/README.md | 46 ++++++++++++++++++++-------------------- 2 files changed, 25 insertions(+), 23 deletions(-) diff --git a/plugin-gradle/CHANGES.md b/plugin-gradle/CHANGES.md index ee6a753893..6c2a6cd4da 100644 --- a/plugin-gradle/CHANGES.md +++ b/plugin-gradle/CHANGES.md @@ -3,6 +3,8 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format (starting after version `3.27.0`). ## [Unreleased] + +## [6.2.2] - 2022-02-09 ### Changed * Bump default ktfmt `0.30` -> `0.31` ([#1118](https://github.com/diffplug/spotless/pull/1118)). ### Fixed diff --git a/plugin-gradle/README.md b/plugin-gradle/README.md index df4c67c113..ffc52bd923 100644 --- a/plugin-gradle/README.md +++ b/plugin-gradle/README.md @@ -18,9 +18,9 @@ output = [ --> [![Gradle plugin](https://img.shields.io/badge/plugins.gradle.org-com.diffplug.spotless-blue.svg)](https://plugins.gradle.org/plugin/com.diffplug.spotless) [![Maven central](https://img.shields.io/badge/mavencentral-yes-blue.svg)](https://search.maven.org/#search%7Cgav%7C1%7Cg%3A%22com.diffplug.spotless%22%20AND%20a%3A%22spotless-plugin-gradle%22) -[![Javadoc](https://img.shields.io/badge/javadoc-yes-blue.svg)](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.2.1/index.html) +[![Javadoc](https://img.shields.io/badge/javadoc-yes-blue.svg)](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.2.2/index.html) [![License Apache](https://img.shields.io/badge/license-apache-blue.svg)](https://tldrlegal.com/license/apache-license-2.0-(apache-2.0)) -[![Changelog](https://img.shields.io/badge/changelog-6.2.1-blue.svg)](CHANGES.md) +[![Changelog](https://img.shields.io/badge/changelog-6.2.2-blue.svg)](CHANGES.md) [![Circle CI](https://circleci.com/gh/diffplug/spotless/tree/main.svg?style=shield)](https://circleci.com/gh/diffplug/spotless/tree/main) [![Live chat](https://img.shields.io/badge/gitter-chat-brightgreen.svg)](https://gitter.im/diffplug/spotless) @@ -126,10 +126,10 @@ spotless { ``` Spotless consists of a list of formats (in the example above, `misc` and `java`), and each format has: -- a `target` (the files to format), which you set with [`target`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.2.1/com/diffplug/gradle/spotless/FormatExtension.html#target-java.lang.Object...-) and [`targetExclude`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.2.1/com/diffplug/gradle/spotless/FormatExtension.html#targetExclude-java.lang.Object...-) -- a list of `FormatterStep`, which are just `String -> String` functions, such as [`replace`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.2.1/com/diffplug/gradle/spotless/FormatExtension.html#replace-java.lang.String-java.lang.CharSequence-java.lang.CharSequence-), [`replaceRegex`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.2.1/com/diffplug/gradle/spotless/FormatExtension.html#replaceRegex-java.lang.String-java.lang.String-java.lang.String-), [`trimTrailingWhitespace`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.2.1/com/diffplug/gradle/spotless/FormatExtension.html#replace-java.lang.String-java.lang.CharSequence-java.lang.CharSequence-), [`custom`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.2.1/com/diffplug/gradle/spotless/FormatExtension.html#custom-java.lang.String-groovy.lang.Closure-), [`prettier`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.2.1/com/diffplug/gradle/spotless/FormatExtension.html#prettier--), [`eclipseWtp`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.2.1/com/diffplug/gradle/spotless/FormatExtension.html#eclipseWtp-com.diffplug.spotless.extra.wtp.EclipseWtpFormatterStep-), [`licenseHeader`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.2.1/com/diffplug/gradle/spotless/FormatExtension.html#licenseHeader-java.lang.String-java.lang.String-) etc. +- a `target` (the files to format), which you set with [`target`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.2.2/com/diffplug/gradle/spotless/FormatExtension.html#target-java.lang.Object...-) and [`targetExclude`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.2.2/com/diffplug/gradle/spotless/FormatExtension.html#targetExclude-java.lang.Object...-) +- a list of `FormatterStep`, which are just `String -> String` functions, such as [`replace`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.2.2/com/diffplug/gradle/spotless/FormatExtension.html#replace-java.lang.String-java.lang.CharSequence-java.lang.CharSequence-), [`replaceRegex`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.2.2/com/diffplug/gradle/spotless/FormatExtension.html#replaceRegex-java.lang.String-java.lang.String-java.lang.String-), [`trimTrailingWhitespace`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.2.2/com/diffplug/gradle/spotless/FormatExtension.html#replace-java.lang.String-java.lang.CharSequence-java.lang.CharSequence-), [`custom`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.2.2/com/diffplug/gradle/spotless/FormatExtension.html#custom-java.lang.String-groovy.lang.Closure-), [`prettier`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.2.2/com/diffplug/gradle/spotless/FormatExtension.html#prettier--), [`eclipseWtp`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.2.2/com/diffplug/gradle/spotless/FormatExtension.html#eclipseWtp-com.diffplug.spotless.extra.wtp.EclipseWtpFormatterStep-), [`licenseHeader`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.2.2/com/diffplug/gradle/spotless/FormatExtension.html#licenseHeader-java.lang.String-java.lang.String-) etc. -All the generic steps live in [`FormatExtension`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.2.1/com/diffplug/gradle/spotless/FormatExtension.html), and there are many language-specific steps which live in its language-specific subclasses, which are described below. +All the generic steps live in [`FormatExtension`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.2.2/com/diffplug/gradle/spotless/FormatExtension.html), and there are many language-specific steps which live in its language-specific subclasses, which are described below. ### Requirements @@ -141,7 +141,7 @@ If you're stuck on an older version of Gradle, `id 'com.diffplug.gradle.spotless ## Java -`com.diffplug.gradle.spotless.JavaExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.2.1/com/diffplug/gradle/spotless/JavaExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/JavaExtension.java) +`com.diffplug.gradle.spotless.JavaExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.2.2/com/diffplug/gradle/spotless/JavaExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/JavaExtension.java) ```gradle spotless { @@ -248,8 +248,8 @@ spotless { ## Groovy -- `com.diffplug.gradle.spotless.GroovyExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.2.1/com/diffplug/gradle/spotless/GroovyExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/GroovyExtension.java) -- `com.diffplug.gradle.spotless.GroovyGradleExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.2.1/com/diffplug/gradle/spotless/GroovyGradleExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/GroovyGradleExtension.java) +- `com.diffplug.gradle.spotless.GroovyExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.2.2/com/diffplug/gradle/spotless/GroovyExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/GroovyExtension.java) +- `com.diffplug.gradle.spotless.GroovyGradleExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.2.2/com/diffplug/gradle/spotless/GroovyGradleExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/GroovyGradleExtension.java) Configuration for Groovy is similar to [Java](#java), in that it also supports `licenseHeader` and `importOrder`. @@ -300,8 +300,8 @@ Groovy-Eclipse formatting errors/warnings lead per default to a build failure. T ## Kotlin -- `com.diffplug.gradle.spotless.KotlinExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.2.1/com/diffplug/gradle/spotless/KotlinExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/KotlinExtension.java) -- `com.diffplug.gradle.spotless.KotlinGradleExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.2.1/com/diffplug/gradle/spotless/KotlinGradleExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/KotlinGradleExtension.java) +- `com.diffplug.gradle.spotless.KotlinExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.2.2/com/diffplug/gradle/spotless/KotlinExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/KotlinExtension.java) +- `com.diffplug.gradle.spotless.KotlinGradleExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.2.2/com/diffplug/gradle/spotless/KotlinGradleExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/KotlinGradleExtension.java) ```gradle spotless { // if you are using build.gradle.kts, instead of 'spotless {' use: @@ -359,7 +359,7 @@ spotless { ## Scala -`com.diffplug.gradle.spotless.ScalaExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.2.1/com/diffplug/gradle/spotless/ScalaExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/ScalaExtension.java) +`com.diffplug.gradle.spotless.ScalaExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.2.2/com/diffplug/gradle/spotless/ScalaExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/ScalaExtension.java) ```gradle spotless { @@ -391,7 +391,7 @@ spotless { ## C/C++ -`com.diffplug.gradle.spotless.CppExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.2.1/com/diffplug/gradle/spotless/CppExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/CppExtension.java) +`com.diffplug.gradle.spotless.CppExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.2.2/com/diffplug/gradle/spotless/CppExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/CppExtension.java) ```gradle spotless { @@ -423,7 +423,7 @@ spotles { ## Python -`com.diffplug.gradle.spotless.PythonExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.2.1/com/diffplug/gradle/spotless/PythonExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/PythonExtension.java) +`com.diffplug.gradle.spotless.PythonExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.2.2/com/diffplug/gradle/spotless/PythonExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/PythonExtension.java) ```gradle spotless { @@ -457,7 +457,7 @@ black().pathToExe('C:/myuser/.pyenv/versions/3.8.0/scripts/black.exe') ## FreshMark -`com.diffplug.gradle.spotless.FreshMarkExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.2.1/com/diffplug/gradle/spotless/FreshMarkExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/FreshMarkExtension.java) +`com.diffplug.gradle.spotless.FreshMarkExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.2.2/com/diffplug/gradle/spotless/FreshMarkExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/FreshMarkExtension.java) [homepage](https://github.com/diffplug/freshmark). [changelog](https://github.com/diffplug/freshmark/blob/master/CHANGES.md). FreshMark lets you generate markdown in the comments of your markdown. This helps to keep badges and links up-to-date (see the source for this file), and can also be helpful for generating complex tables (see the source for [the parent readme](../README.md)). @@ -478,7 +478,7 @@ spotless { ## Antlr4 -`com.diffplug.gradle.spotless.Antlr4Extension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.2.1/com/diffplug/gradle/spotless/Antlr4Extension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/Antlr4Extension.java) +`com.diffplug.gradle.spotless.Antlr4Extension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.2.2/com/diffplug/gradle/spotless/Antlr4Extension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/Antlr4Extension.java) ```gradle spotless { @@ -503,7 +503,7 @@ antlr4formatter('1.2.1') // version is optional ## SQL -`com.diffplug.gradle.spotless.SqlExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.2.1/com/diffplug/gradle/spotless/SqlExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/SqlExtension.java) +`com.diffplug.gradle.spotless.SqlExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.2.2/com/diffplug/gradle/spotless/SqlExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/SqlExtension.java) ```gradle spotless { @@ -543,7 +543,7 @@ sql.formatter.indent.size=4 ## Typescript -- `com.diffplug.gradle.spotless.TypescriptExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.2.1/com/diffplug/gradle/spotless/TypescriptExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/TypescriptExtension.java) +- `com.diffplug.gradle.spotless.TypescriptExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.2.2/com/diffplug/gradle/spotless/TypescriptExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/TypescriptExtension.java) ```gradle spotless { @@ -586,7 +586,7 @@ For details, see the [npm detection](#npm-detection) and [`.npmrc` detection](#n ## JSON -- `com.diffplug.gradle.spotless.JsonExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.2.1/com/diffplug/gradle/spotless/JsonExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/JsonExtension.java) +- `com.diffplug.gradle.spotless.JsonExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.2.2/com/diffplug/gradle/spotless/JsonExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/JsonExtension.java) ```gradle spotless { @@ -786,7 +786,7 @@ Once a file's license header has a valid year, whether it is a year (`2020`) or * `2017` -> `2017-2020` * `2017-2019` -> `2017-2020` -See the [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.2.1/com/diffplug/gradle/spotless/FormatExtension.LicenseHeaderConfig.html) for a complete listing of options. +See the [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.2.2/com/diffplug/gradle/spotless/FormatExtension.LicenseHeaderConfig.html) for a complete listing of options. @@ -853,9 +853,9 @@ spotless { custom 'lowercase', { str -> str.toLowerCase() } ``` -However, custom rules will disable up-to-date checking and caching, unless you read [this javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.2.1/com/diffplug/gradle/spotless/FormatExtension.html#bumpThisNumberIfACustomStepChanges-int-) and follow its instructions carefully. +However, custom rules will disable up-to-date checking and caching, unless you read [this javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.2.2/com/diffplug/gradle/spotless/FormatExtension.html#bumpThisNumberIfACustomStepChanges-int-) and follow its instructions carefully. -Another option is to create proper `FormatterStep` in your `buildSrc`, and then call [`addStep`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.2.1/com/diffplug/gradle/spotless/FormatExtension.html#addStep-com.diffplug.spotless.FormatterStep-). The contributing guide describes [how to do this](https://github.com/diffplug/spotless/blob/main/CONTRIBUTING.md#how-to-add-a-new-formatterstep). If the step is generally-useful, we hope you'll open a PR to share it! +Another option is to create proper `FormatterStep` in your `buildSrc`, and then call [`addStep`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.2.2/com/diffplug/gradle/spotless/FormatExtension.html#addStep-com.diffplug.spotless.FormatterStep-). The contributing guide describes [how to do this](https://github.com/diffplug/spotless/blob/main/CONTRIBUTING.md#how-to-add-a-new-formatterstep). If the step is generally-useful, we hope you'll open a PR to share it! ```gradle @@ -888,11 +888,11 @@ spotless { format 'foo', com.acme.FooLanguageExtension, { ``` -If you'd like to create a one-off Spotless task outside of the `check`/`apply` framework, see [`FormatExtension.createIndependentApplyTask`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.2.1/com/diffplug/gradle/spotless/FormatExtension.html#createIndependentApplyTask-java.lang.String-). +If you'd like to create a one-off Spotless task outside of the `check`/`apply` framework, see [`FormatExtension.createIndependentApplyTask`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.2.2/com/diffplug/gradle/spotless/FormatExtension.html#createIndependentApplyTask-java.lang.String-). ## Inception (languages within languages within...) -In very rare cases, you might want to format e.g. javascript which is written inside JSP templates, or maybe java within a markdown file, or something wacky like that. You can specify hunks within a file using either open/close tags or a regex with a single capturing group, and then specify rules within it, like so. See [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.2.1/com/diffplug/gradle/spotless/FormatExtension.html#withinBlocks-java.lang.String-java.lang.String-java.lang.String-org.gradle.api.Action-) for more details. +In very rare cases, you might want to format e.g. javascript which is written inside JSP templates, or maybe java within a markdown file, or something wacky like that. You can specify hunks within a file using either open/close tags or a regex with a single capturing group, and then specify rules within it, like so. See [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.2.2/com/diffplug/gradle/spotless/FormatExtension.html#withinBlocks-java.lang.String-java.lang.String-java.lang.String-org.gradle.api.Action-) for more details. ```gradle import com.diffplug.gradle.spotless.JavaExtension From b26f0972b185995d7c6a7aefa726c146d24d9a82 Mon Sep 17 00:00:00 2001 From: circleci Date: Wed, 9 Feb 2022 01:01:56 +0000 Subject: [PATCH 013/757] Published maven/2.20.2 --- plugin-maven/CHANGES.md | 2 ++ plugin-maven/README.md | 4 ++-- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/plugin-maven/CHANGES.md b/plugin-maven/CHANGES.md index 07021c68ef..8d277d1703 100644 --- a/plugin-maven/CHANGES.md +++ b/plugin-maven/CHANGES.md @@ -3,6 +3,8 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format (starting after version `1.27.0`). ## [Unreleased] + +## [2.20.2] - 2022-02-09 ### Changed * Bump default ktfmt `0.30` -> `0.31` ([#1118](https://github.com/diffplug/spotless/pull/1118)). ### Fixed diff --git a/plugin-maven/README.md b/plugin-maven/README.md index 986fa6c783..01688eb9b7 100644 --- a/plugin-maven/README.md +++ b/plugin-maven/README.md @@ -12,8 +12,8 @@ output = [ ].join('\n'); --> [![Maven central](https://img.shields.io/badge/mavencentral-com.diffplug.spotless%3Aspotless--maven--plugin-blue.svg)](https://search.maven.org/#search%7Cgav%7C1%7Cg%3A%22com.diffplug.spotless%22%20AND%20a%3A%22spotless-maven-plugin%22) -[![Javadoc](https://img.shields.io/badge/javadoc-yes-blue.svg)](https://javadoc.io/doc/com.diffplug.spotless/spotless-maven-plugin/2.20.1/index.html) -[![Changelog](https://img.shields.io/badge/changelog-2.20.1-brightgreen.svg)](CHANGES.md) +[![Javadoc](https://img.shields.io/badge/javadoc-yes-blue.svg)](https://javadoc.io/doc/com.diffplug.spotless/spotless-maven-plugin/2.20.2/index.html) +[![Changelog](https://img.shields.io/badge/changelog-2.20.2-brightgreen.svg)](CHANGES.md) [![Circle CI](https://circleci.com/gh/diffplug/spotless/tree/main.svg?style=shield)](https://circleci.com/gh/diffplug/spotless/tree/main) [![Live chat](https://img.shields.io/badge/gitter-chat-brightgreen.svg)](https://gitter.im/diffplug/spotless) From cf449b88ab0277ba69e5700faac0e28703d8b0bd Mon Sep 17 00:00:00 2001 From: Abel Keszei Date: Sun, 30 Jan 2022 22:06:11 +0100 Subject: [PATCH 014/757] add gson support to json extension --- .../diffplug/spotless/json/gson/GsonStep.java | 74 +++++++++++++++++++ .../spotless/json/gson/GsonWrapper.java | 33 +++++++++ .../spotless/json/gson/GsonWrapperBase.java | 56 ++++++++++++++ .../json/gson/JsonElementWrapper.java | 27 +++++++ .../spotless/json/gson/JsonObjectWrapper.java | 46 ++++++++++++ .../spotless/json/gson/JsonWriterWrapper.java | 33 +++++++++ .../gradle/spotless/JsonExtension.java | 41 ++++++++++ 7 files changed, 310 insertions(+) create mode 100644 lib/src/main/java/com/diffplug/spotless/json/gson/GsonStep.java create mode 100644 lib/src/main/java/com/diffplug/spotless/json/gson/GsonWrapper.java create mode 100644 lib/src/main/java/com/diffplug/spotless/json/gson/GsonWrapperBase.java create mode 100644 lib/src/main/java/com/diffplug/spotless/json/gson/JsonElementWrapper.java create mode 100644 lib/src/main/java/com/diffplug/spotless/json/gson/JsonObjectWrapper.java create mode 100644 lib/src/main/java/com/diffplug/spotless/json/gson/JsonWriterWrapper.java diff --git a/lib/src/main/java/com/diffplug/spotless/json/gson/GsonStep.java b/lib/src/main/java/com/diffplug/spotless/json/gson/GsonStep.java new file mode 100644 index 0000000000..5035953289 --- /dev/null +++ b/lib/src/main/java/com/diffplug/spotless/json/gson/GsonStep.java @@ -0,0 +1,74 @@ +package com.diffplug.spotless.json.gson; + +import com.diffplug.spotless.FormatterFunc; +import com.diffplug.spotless.FormatterStep; +import com.diffplug.spotless.JarState; +import com.diffplug.spotless.Provisioner; + +import java.io.IOException; +import java.io.Serializable; +import java.io.StringWriter; +import java.util.Collections; +import java.util.Objects; + +public class GsonStep { + private static final String MAVEN_COORDINATES = "com.google.code.gson:gson"; + + public static FormatterStep create(int indentSpaces, boolean sortByKeys, String version, Provisioner provisioner) { + Objects.requireNonNull(provisioner, "provisioner cannot be null"); + return FormatterStep.createLazy("gson", () -> new State(indentSpaces, sortByKeys, version, provisioner), State::toFormatter); + } + + private static final class State implements Serializable { + private static final long serialVersionUID = 6540876150977107116L; + + private final int indentSpaces; + private final boolean sortByKeys; + private final JarState jarState; + + private State(int indentSpaces, boolean sortByKeys, String version, Provisioner provisioner) throws IOException { + this.indentSpaces = indentSpaces; + this.sortByKeys = sortByKeys; + this.jarState = JarState.from(MAVEN_COORDINATES + ":" + version, provisioner); + } + + FormatterFunc toFormatter() { + JsonWriterWrapper jsonWriterWrapper = new JsonWriterWrapper(jarState); + JsonElementWrapper jsonElementWrapper = new JsonElementWrapper(jarState); + JsonObjectWrapper jsonObjectWrapper = new JsonObjectWrapper(jarState, jsonElementWrapper); + GsonWrapper gsonWrapper = new GsonWrapper(jarState, jsonElementWrapper, jsonWriterWrapper); + Object gson = gsonWrapper.createGson(); + + return inputString -> { + Object jsonElement = gsonWrapper.fromJson(gson, inputString, jsonElementWrapper.getWrappedClass()); + if (sortByKeys && jsonElementWrapper.isJsonObject(jsonElement)) { + jsonElement = sortByKeys(jsonObjectWrapper, jsonElementWrapper, jsonElement); + } + try (StringWriter stringWriter = new StringWriter()) { + Object jsonWriter = jsonWriterWrapper.createJsonWriter(stringWriter); + jsonWriterWrapper.setIndent(jsonWriter, generateIndent(indentSpaces)); + gsonWrapper.toJson(gson, jsonElement, jsonWriter); + return stringWriter.toString(); + } + }; + } + + private Object sortByKeys(JsonObjectWrapper jsonObjectWrapper, JsonElementWrapper jsonElementWrapper, Object jsonObject) { + Object result = jsonObjectWrapper.createJsonObject(); + jsonObjectWrapper.keySet(jsonObject).stream().sorted() + .forEach(key -> { + Object element = jsonObjectWrapper.get(jsonObject, key); + if (jsonElementWrapper.isJsonObject(element)) { + element = sortByKeys(jsonObjectWrapper, jsonElementWrapper, element); + } + jsonObjectWrapper.add(result, key, element); + }); + return result; + } + + private String generateIndent(int indentSpaces) { + return String.join("", Collections.nCopies(indentSpaces, " ")); + } + } + +} diff --git a/lib/src/main/java/com/diffplug/spotless/json/gson/GsonWrapper.java b/lib/src/main/java/com/diffplug/spotless/json/gson/GsonWrapper.java new file mode 100644 index 0000000000..53e765fa04 --- /dev/null +++ b/lib/src/main/java/com/diffplug/spotless/json/gson/GsonWrapper.java @@ -0,0 +1,33 @@ +package com.diffplug.spotless.json.gson; + +import com.diffplug.spotless.JarState; + +import java.lang.reflect.Constructor; +import java.lang.reflect.Method; + +public class GsonWrapper extends GsonWrapperBase { + + private final Constructor constructor; + private final Method fromJsonMethod; + private final Method toJsonMethod; + + public GsonWrapper(JarState jarState, JsonElementWrapper jsonElementWrapper, JsonWriterWrapper jsonWriterWrapper) { + Class clazz = loadClass(jarState.getClassLoader(), "com.google.gson.Gson"); + this.constructor = getConstructor(clazz); + this.fromJsonMethod = getMethod(clazz, "fromJson", String.class, Class.class); + this.toJsonMethod = getMethod(clazz, "toJson", jsonElementWrapper.getWrappedClass(), jsonWriterWrapper.getWrappedClass()); + } + + public Object createGson() { + return newInstance(constructor); + } + + public Object fromJson(Object gson, String json, Class type) { + return invoke(fromJsonMethod, gson, json, type); + } + + public void toJson(Object gson, Object jsonElement, Object jsonWriter) { + invoke(toJsonMethod, gson, jsonElement, jsonWriter); + } + +} diff --git a/lib/src/main/java/com/diffplug/spotless/json/gson/GsonWrapperBase.java b/lib/src/main/java/com/diffplug/spotless/json/gson/GsonWrapperBase.java new file mode 100644 index 0000000000..182011c960 --- /dev/null +++ b/lib/src/main/java/com/diffplug/spotless/json/gson/GsonWrapperBase.java @@ -0,0 +1,56 @@ +package com.diffplug.spotless.json.gson; + +import java.lang.reflect.Constructor; +import java.lang.reflect.InvocationTargetException; +import java.lang.reflect.Method; + +public abstract class GsonWrapperBase { + + public static final String INCOMPATIBLE_ERROR_MESSAGE = "There was a problem interacting with Gson; maybe you set an incompatible version?"; + public static final String FAILED_TO_PARSE_ERROR_MESSAGE = "Failed to parse JSON"; + + protected final Class loadClass(ClassLoader classLoader, String className) { + try { + return classLoader.loadClass(className); + } catch (ClassNotFoundException cause) { + throw new IllegalStateException(INCOMPATIBLE_ERROR_MESSAGE, cause); + } + } + + protected final Constructor getConstructor(Class clazz, Class... argumentTypes) { + try { + return clazz.getConstructor(argumentTypes); + } catch (NoSuchMethodException cause) { + throw new IllegalStateException(INCOMPATIBLE_ERROR_MESSAGE, cause); + } + } + + protected final Method getMethod(Class clazz, String name, Class... argumentTypes) { + try { + return clazz.getMethod(name, argumentTypes); + } catch (NoSuchMethodException cause) { + throw new IllegalStateException(INCOMPATIBLE_ERROR_MESSAGE, cause); + } + } + + protected final T newInstance(Constructor constructor, Object... args) { + try { + return constructor.newInstance(args); + } catch (InstantiationException | IllegalAccessException cause) { + throw new IllegalStateException(INCOMPATIBLE_ERROR_MESSAGE, cause); + } catch (InvocationTargetException cause) { + throw new IllegalStateException(FAILED_TO_PARSE_ERROR_MESSAGE, cause.getCause()); + } + } + + protected Object invoke(Method method, Object targetObject, Object... args) { + try { + return method.invoke(targetObject, args); + } catch (IllegalAccessException cause) { + throw new IllegalStateException(INCOMPATIBLE_ERROR_MESSAGE, cause); + } catch (InvocationTargetException cause) { + throw new IllegalStateException(FAILED_TO_PARSE_ERROR_MESSAGE, cause.getCause()); + } + } + +} diff --git a/lib/src/main/java/com/diffplug/spotless/json/gson/JsonElementWrapper.java b/lib/src/main/java/com/diffplug/spotless/json/gson/JsonElementWrapper.java new file mode 100644 index 0000000000..a45225b411 --- /dev/null +++ b/lib/src/main/java/com/diffplug/spotless/json/gson/JsonElementWrapper.java @@ -0,0 +1,27 @@ +package com.diffplug.spotless.json.gson; + +import com.diffplug.spotless.JarState; + +import java.lang.reflect.Constructor; +import java.lang.reflect.Method; +import java.util.Set; + +public class JsonElementWrapper extends GsonWrapperBase { + + private final Class clazz; + private final Method isJsonObjectMethod; + + public JsonElementWrapper(JarState jarState) { + this.clazz = loadClass(jarState.getClassLoader(), "com.google.gson.JsonElement"); + this.isJsonObjectMethod = getMethod(clazz, "isJsonObject"); + } + + public boolean isJsonObject(Object jsonElement) { + return (boolean) invoke(isJsonObjectMethod, jsonElement); + } + + public Class getWrappedClass() { + return clazz; + } + +} diff --git a/lib/src/main/java/com/diffplug/spotless/json/gson/JsonObjectWrapper.java b/lib/src/main/java/com/diffplug/spotless/json/gson/JsonObjectWrapper.java new file mode 100644 index 0000000000..7d3151b489 --- /dev/null +++ b/lib/src/main/java/com/diffplug/spotless/json/gson/JsonObjectWrapper.java @@ -0,0 +1,46 @@ +package com.diffplug.spotless.json.gson; + +import com.diffplug.spotless.JarState; + +import java.lang.reflect.Constructor; +import java.lang.reflect.Method; +import java.util.Set; + +public class JsonObjectWrapper extends GsonWrapperBase { + + private final Class clazz; + private final Constructor constructor; + private final Method keySetMethod; + private final Method getMethod; + private final Method addMethod; + + public JsonObjectWrapper(JarState jarState, JsonElementWrapper jsonElementWrapper) { + this.clazz = loadClass(jarState.getClassLoader(), "com.google.gson.JsonObject"); + this.constructor = getConstructor(clazz); + this.keySetMethod = getMethod(clazz, "keySet"); + this.getMethod = getMethod(clazz, "get", String.class); + this.addMethod = getMethod(clazz, "add", String.class, jsonElementWrapper.getWrappedClass()); + } + + public Object createJsonObject() { + return newInstance(constructor); + } + + @SuppressWarnings("unchecked") + public Set keySet(Object jsonObject) { + return (Set) invoke(keySetMethod, jsonObject); + } + + public Object get(Object jsonObject, String key) { + return invoke(getMethod, jsonObject, key); + } + + public void add(Object jsonObject, String key, Object element) { + invoke(addMethod, jsonObject, key, element); + } + + public Class getWrappedClass() { + return clazz; + } + +} diff --git a/lib/src/main/java/com/diffplug/spotless/json/gson/JsonWriterWrapper.java b/lib/src/main/java/com/diffplug/spotless/json/gson/JsonWriterWrapper.java new file mode 100644 index 0000000000..580e075e77 --- /dev/null +++ b/lib/src/main/java/com/diffplug/spotless/json/gson/JsonWriterWrapper.java @@ -0,0 +1,33 @@ +package com.diffplug.spotless.json.gson; + +import com.diffplug.spotless.JarState; + +import java.io.Writer; +import java.lang.reflect.Constructor; +import java.lang.reflect.Method; + +public class JsonWriterWrapper extends GsonWrapperBase { + + private final Class clazz; + private final Constructor constructor; + private final Method setIndentMethod; + + public JsonWriterWrapper(JarState jarState) { + this.clazz = loadClass(jarState.getClassLoader(), "com.google.gson.stream.JsonWriter"); + this.constructor = getConstructor(clazz, Writer.class); + this.setIndentMethod = getMethod(clazz, "setIndent", String.class); + } + + public Object createJsonWriter(Writer writer) { + return newInstance(constructor, writer); + } + + public void setIndent(Object jsonWriter, String indent) { + invoke(setIndentMethod, jsonWriter, indent); + } + + public Class getWrappedClass() { + return clazz; + } + +} diff --git a/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/JsonExtension.java b/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/JsonExtension.java index e15d395f3b..e3aeaca9d6 100644 --- a/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/JsonExtension.java +++ b/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/JsonExtension.java @@ -19,9 +19,11 @@ import com.diffplug.spotless.FormatterStep; import com.diffplug.spotless.json.JsonSimpleStep; +import com.diffplug.spotless.json.gson.GsonStep; public class JsonExtension extends FormatExtension { private static final int DEFAULT_INDENTATION = 4; + private static final String DEFAULT_GSON_VERSION = "2.8.9"; static final String NAME = "json"; @Inject @@ -41,6 +43,10 @@ public SimpleConfig simple() { return new SimpleConfig(DEFAULT_INDENTATION); } + public GsonConfig gson() { + return new GsonConfig(); + } + public class SimpleConfig { private int indent; @@ -59,4 +65,39 @@ private FormatterStep createStep() { } } + public class GsonConfig { + private int indentSpaces; + private boolean sortByKeys; + private String version; + + public GsonConfig() { + this.indentSpaces = DEFAULT_INDENTATION; + this.sortByKeys = false; + this.version = DEFAULT_GSON_VERSION; + addStep(createStep()); + } + + public GsonConfig indentWithSpaces(int indentSpaces) { + this.indentSpaces = indentSpaces; + replaceStep(createStep()); + return this; + } + + public GsonConfig sortByKeys() { + this.sortByKeys = true; + replaceStep(createStep()); + return this; + } + + public GsonConfig version(String version) { + this.version = version; + replaceStep(createStep()); + return this; + } + + private FormatterStep createStep() { + return GsonStep.create(indentSpaces, sortByKeys, version, provisioner()); + } + } + } From ecbbda3113a7955874d206a39d227a1e927f2a20 Mon Sep 17 00:00:00 2001 From: Abel Keszei Date: Sun, 30 Jan 2022 22:21:27 +0100 Subject: [PATCH 015/757] add gson support to README --- plugin-gradle/README.md | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/plugin-gradle/README.md b/plugin-gradle/README.md index ffc52bd923..b3821d5277 100644 --- a/plugin-gradle/README.md +++ b/plugin-gradle/README.md @@ -595,6 +595,7 @@ spotless { simple() // has its own section below prettier().config(['parser': 'json']) // see Prettier section below eclipseWtp('json') // see Eclipse web tools platform section + gson() // has its own section below } } ``` @@ -614,6 +615,22 @@ spotless { } ``` +### Gson + +Uses Google Gson to also allow sorting by keys besides custom indentation - useful for i18n files. + +```gradle +spotless { + json { + target 'src/**/*.json' + gson() + .indentWithSpaces(6) // optional: specify the number of spaces to use + .sortByKeys() // optional: sort JSON by its keys + .version('2.8.1') // optional: specify version + } +} +``` + ## Prettier From a62ff120995b09ba9f7a018ac01b61ea7466da7c Mon Sep 17 00:00:00 2001 From: Abel Keszei Date: Sat, 12 Feb 2022 18:03:04 +0100 Subject: [PATCH 016/757] update unit tests for gson support --- .../json/gson/GsonBuilderWrapper.java | 39 ++ .../diffplug/spotless/json/gson/GsonStep.java | 45 +- .../spotless/json/gson/GsonWrapperBase.java | 6 +- .../spotless/json/gson/JsonObjectWrapper.java | 7 +- .../gradle/spotless/JsonExtension.java | 10 +- .../json/cucumberJsonSampleGsonAfter.json | 660 ++++++++++++++++++ .../json/cucumberJsonSampleGsonBefore.json | 660 ++++++++++++++++++ .../resources/json/escapeHtmlGsonAfter.json | 4 + .../json/escapeHtmlGsonAfterDisabled.json | 4 + .../resources/json/escapeHtmlGsonBefore.json | 4 + .../json/objectWithNullGsonAfter.json | 4 + .../json/objectWithNullGsonBefore.json | 4 + .../main/resources/json/sortByKeysAfter.json | 19 + .../json/sortByKeysAfterDisabled.json | 19 + .../main/resources/json/sortByKeysBefore.json | 19 + .../diffplug/spotless/json/GsonStepTest.java | 85 +++ .../json/JsonFormatterStepCommonTests.java | 89 +++ .../spotless/json/JsonSimpleStepTest.java | 107 +-- 18 files changed, 1672 insertions(+), 113 deletions(-) create mode 100644 lib/src/main/java/com/diffplug/spotless/json/gson/GsonBuilderWrapper.java create mode 100644 testlib/src/main/resources/json/cucumberJsonSampleGsonAfter.json create mode 100644 testlib/src/main/resources/json/cucumberJsonSampleGsonBefore.json create mode 100644 testlib/src/main/resources/json/escapeHtmlGsonAfter.json create mode 100644 testlib/src/main/resources/json/escapeHtmlGsonAfterDisabled.json create mode 100644 testlib/src/main/resources/json/escapeHtmlGsonBefore.json create mode 100644 testlib/src/main/resources/json/objectWithNullGsonAfter.json create mode 100644 testlib/src/main/resources/json/objectWithNullGsonBefore.json create mode 100644 testlib/src/main/resources/json/sortByKeysAfter.json create mode 100644 testlib/src/main/resources/json/sortByKeysAfterDisabled.json create mode 100644 testlib/src/main/resources/json/sortByKeysBefore.json create mode 100644 testlib/src/test/java/com/diffplug/spotless/json/GsonStepTest.java create mode 100644 testlib/src/test/java/com/diffplug/spotless/json/JsonFormatterStepCommonTests.java diff --git a/lib/src/main/java/com/diffplug/spotless/json/gson/GsonBuilderWrapper.java b/lib/src/main/java/com/diffplug/spotless/json/gson/GsonBuilderWrapper.java new file mode 100644 index 0000000000..1693a5f9da --- /dev/null +++ b/lib/src/main/java/com/diffplug/spotless/json/gson/GsonBuilderWrapper.java @@ -0,0 +1,39 @@ +package com.diffplug.spotless.json.gson; + +import java.lang.reflect.Constructor; +import java.lang.reflect.Method; + +import com.diffplug.spotless.JarState; + +public class GsonBuilderWrapper extends GsonWrapperBase { + + private final Constructor constructor; + private final Method serializeNullsMethod; + private final Method disableHtmlEscapingMethod; + private final Method createMethod; + + public GsonBuilderWrapper(JarState jarState) { + Class clazz = loadClass(jarState.getClassLoader(), "com.google.gson.GsonBuilder"); + this.constructor = getConstructor(clazz); + this.serializeNullsMethod = getMethod(clazz, "serializeNulls"); + this.disableHtmlEscapingMethod = getMethod(clazz, "disableHtmlEscaping"); + this.createMethod = getMethod(clazz, "create"); + } + + public Object createGsonBuilder() { + return newInstance(constructor); + } + + public Object serializeNulls(Object gsonBuilder) { + return invoke(serializeNullsMethod, gsonBuilder); + } + + public Object disableHtmlEscaping(Object gsonBuilder) { + return invoke(disableHtmlEscapingMethod, gsonBuilder); + } + + public Object create(Object gsonBuilder) { + return invoke(createMethod, gsonBuilder); + } + +} diff --git a/lib/src/main/java/com/diffplug/spotless/json/gson/GsonStep.java b/lib/src/main/java/com/diffplug/spotless/json/gson/GsonStep.java index 5035953289..40ca84eeb7 100644 --- a/lib/src/main/java/com/diffplug/spotless/json/gson/GsonStep.java +++ b/lib/src/main/java/com/diffplug/spotless/json/gson/GsonStep.java @@ -14,21 +14,23 @@ public class GsonStep { private static final String MAVEN_COORDINATES = "com.google.code.gson:gson"; - public static FormatterStep create(int indentSpaces, boolean sortByKeys, String version, Provisioner provisioner) { + public static FormatterStep create(int indentSpaces, boolean sortByKeys, boolean escapeHtml, String version, Provisioner provisioner) { Objects.requireNonNull(provisioner, "provisioner cannot be null"); - return FormatterStep.createLazy("gson", () -> new State(indentSpaces, sortByKeys, version, provisioner), State::toFormatter); + return FormatterStep.createLazy("gson", () -> new State(indentSpaces, sortByKeys, escapeHtml, version, provisioner), State::toFormatter); } private static final class State implements Serializable { - private static final long serialVersionUID = 6540876150977107116L; + private static final long serialVersionUID = -1493479043249379485L; private final int indentSpaces; private final boolean sortByKeys; + private final boolean escapeHtml; private final JarState jarState; - private State(int indentSpaces, boolean sortByKeys, String version, Provisioner provisioner) throws IOException { + private State(int indentSpaces, boolean sortByKeys, boolean escapeHtml, String version, Provisioner provisioner) throws IOException { this.indentSpaces = indentSpaces; this.sortByKeys = sortByKeys; + this.escapeHtml = escapeHtml; this.jarState = JarState.from(MAVEN_COORDINATES + ":" + version, provisioner); } @@ -36,20 +38,35 @@ FormatterFunc toFormatter() { JsonWriterWrapper jsonWriterWrapper = new JsonWriterWrapper(jarState); JsonElementWrapper jsonElementWrapper = new JsonElementWrapper(jarState); JsonObjectWrapper jsonObjectWrapper = new JsonObjectWrapper(jarState, jsonElementWrapper); + GsonBuilderWrapper gsonBuilderWrapper = new GsonBuilderWrapper(jarState); GsonWrapper gsonWrapper = new GsonWrapper(jarState, jsonElementWrapper, jsonWriterWrapper); - Object gson = gsonWrapper.createGson(); + + Object gsonBuilder = gsonBuilderWrapper.serializeNulls(gsonBuilderWrapper.createGsonBuilder()); + if (!escapeHtml) { + gsonBuilder = gsonBuilderWrapper.disableHtmlEscaping(gsonBuilder); + } + Object gson = gsonBuilderWrapper.create(gsonBuilder); return inputString -> { - Object jsonElement = gsonWrapper.fromJson(gson, inputString, jsonElementWrapper.getWrappedClass()); - if (sortByKeys && jsonElementWrapper.isJsonObject(jsonElement)) { - jsonElement = sortByKeys(jsonObjectWrapper, jsonElementWrapper, jsonElement); - } - try (StringWriter stringWriter = new StringWriter()) { - Object jsonWriter = jsonWriterWrapper.createJsonWriter(stringWriter); - jsonWriterWrapper.setIndent(jsonWriter, generateIndent(indentSpaces)); - gsonWrapper.toJson(gson, jsonElement, jsonWriter); - return stringWriter.toString(); + String result; + if (inputString.isEmpty()) { + result = ""; + } else { + Object jsonElement = gsonWrapper.fromJson(gson, inputString, jsonElementWrapper.getWrappedClass()); + if (jsonElement == null) { + throw new AssertionError(GsonWrapperBase.FAILED_TO_PARSE_ERROR_MESSAGE); + } + if (sortByKeys && jsonElementWrapper.isJsonObject(jsonElement)) { + jsonElement = sortByKeys(jsonObjectWrapper, jsonElementWrapper, jsonElement); + } + try (StringWriter stringWriter = new StringWriter()) { + Object jsonWriter = jsonWriterWrapper.createJsonWriter(stringWriter); + jsonWriterWrapper.setIndent(jsonWriter, generateIndent(indentSpaces)); + gsonWrapper.toJson(gson, jsonElement, jsonWriter); + result = stringWriter + "\n"; + } } + return result; }; } diff --git a/lib/src/main/java/com/diffplug/spotless/json/gson/GsonWrapperBase.java b/lib/src/main/java/com/diffplug/spotless/json/gson/GsonWrapperBase.java index 182011c960..31e22d53d0 100644 --- a/lib/src/main/java/com/diffplug/spotless/json/gson/GsonWrapperBase.java +++ b/lib/src/main/java/com/diffplug/spotless/json/gson/GsonWrapperBase.java @@ -7,7 +7,7 @@ public abstract class GsonWrapperBase { public static final String INCOMPATIBLE_ERROR_MESSAGE = "There was a problem interacting with Gson; maybe you set an incompatible version?"; - public static final String FAILED_TO_PARSE_ERROR_MESSAGE = "Failed to parse JSON"; + public static final String FAILED_TO_PARSE_ERROR_MESSAGE = "Unable to format JSON"; protected final Class loadClass(ClassLoader classLoader, String className) { try { @@ -39,7 +39,7 @@ protected final T newInstance(Constructor constructor, Object... args) { } catch (InstantiationException | IllegalAccessException cause) { throw new IllegalStateException(INCOMPATIBLE_ERROR_MESSAGE, cause); } catch (InvocationTargetException cause) { - throw new IllegalStateException(FAILED_TO_PARSE_ERROR_MESSAGE, cause.getCause()); + throw new AssertionError(FAILED_TO_PARSE_ERROR_MESSAGE, cause.getCause()); } } @@ -49,7 +49,7 @@ protected Object invoke(Method method, Object targetObject, Object... args) { } catch (IllegalAccessException cause) { throw new IllegalStateException(INCOMPATIBLE_ERROR_MESSAGE, cause); } catch (InvocationTargetException cause) { - throw new IllegalStateException(FAILED_TO_PARSE_ERROR_MESSAGE, cause.getCause()); + throw new AssertionError(FAILED_TO_PARSE_ERROR_MESSAGE, cause.getCause()); } } diff --git a/lib/src/main/java/com/diffplug/spotless/json/gson/JsonObjectWrapper.java b/lib/src/main/java/com/diffplug/spotless/json/gson/JsonObjectWrapper.java index 7d3151b489..5485ce2ffc 100644 --- a/lib/src/main/java/com/diffplug/spotless/json/gson/JsonObjectWrapper.java +++ b/lib/src/main/java/com/diffplug/spotless/json/gson/JsonObjectWrapper.java @@ -8,14 +8,13 @@ public class JsonObjectWrapper extends GsonWrapperBase { - private final Class clazz; private final Constructor constructor; private final Method keySetMethod; private final Method getMethod; private final Method addMethod; public JsonObjectWrapper(JarState jarState, JsonElementWrapper jsonElementWrapper) { - this.clazz = loadClass(jarState.getClassLoader(), "com.google.gson.JsonObject"); + Class clazz = loadClass(jarState.getClassLoader(), "com.google.gson.JsonObject"); this.constructor = getConstructor(clazz); this.keySetMethod = getMethod(clazz, "keySet"); this.getMethod = getMethod(clazz, "get", String.class); @@ -39,8 +38,4 @@ public void add(Object jsonObject, String key, Object element) { invoke(addMethod, jsonObject, key, element); } - public Class getWrappedClass() { - return clazz; - } - } diff --git a/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/JsonExtension.java b/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/JsonExtension.java index e3aeaca9d6..bce3a68060 100644 --- a/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/JsonExtension.java +++ b/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/JsonExtension.java @@ -68,11 +68,13 @@ private FormatterStep createStep() { public class GsonConfig { private int indentSpaces; private boolean sortByKeys; + private boolean escapeHtml; private String version; public GsonConfig() { this.indentSpaces = DEFAULT_INDENTATION; this.sortByKeys = false; + this.escapeHtml = false; this.version = DEFAULT_GSON_VERSION; addStep(createStep()); } @@ -89,6 +91,12 @@ public GsonConfig sortByKeys() { return this; } + public GsonConfig escapeHtml() { + this.escapeHtml = true; + replaceStep(createStep()); + return this; + } + public GsonConfig version(String version) { this.version = version; replaceStep(createStep()); @@ -96,7 +104,7 @@ public GsonConfig version(String version) { } private FormatterStep createStep() { - return GsonStep.create(indentSpaces, sortByKeys, version, provisioner()); + return GsonStep.create(indentSpaces, sortByKeys, escapeHtml, version, provisioner()); } } diff --git a/testlib/src/main/resources/json/cucumberJsonSampleGsonAfter.json b/testlib/src/main/resources/json/cucumberJsonSampleGsonAfter.json new file mode 100644 index 0000000000..07e87bfd38 --- /dev/null +++ b/testlib/src/main/resources/json/cucumberJsonSampleGsonAfter.json @@ -0,0 +1,660 @@ +[ + { + "id": "account-holder-withdraws-cash", + "tags": [ + { + "name": "@featureTag", + "line": 1 + } + ], + "description": "This is description of the feature", + "name": "1st feature", + "keyword": "Feature", + "line": 2, + "elements": [ + { + "description": "Perfect background", + "name": "Activate Credit Card", + "keyword": "Background", + "line": 7, + "steps": [ + { + "result": { + "duration": 99107447000, + "status": "passed" + }, + "name": "I have a new credit card", + "keyword": "Given ", + "line": 8, + "match": { + "location": "ATMScenario.I_have_a_new_credit_card()" + }, + "embeddings": [ + { + "mime_type": "image/url", + "data": "" + }, + { + "data": "", + "media": { + "type": "text/plain" + } + } + ] + }, + { + "result": { + "duration": 9520000, + "status": "passed" + }, + "name": "My credit card is described as follow:", + "keyword": "And ", + "line": 9, + "match": { + "location": "ATMScenario.My_credit_card_is_described_as_follow" + }, + "doc_string": { + "content_type": "", + "line": 10, + "value": "{\n\"issuer\": {\n\"name\": \"Real Bank Inc.\",\n\"isn:\": \"RB55800093842N\"\n},\n\"card_number\": \"4896 0215 8478 6325\",\n\"holder\": \"A guy\"\n}" + } + }, + { + "result": { + "duration": 7040000, + "status": "passed" + }, + "name": "I confirm my pin number", + "keyword": "When ", + "line": 18, + "match": { + "location": "ATMScenario.I_confirm_my_pin_number()" + }, + "rows": [ + { + "cells": [ + "Müller", + "Deutschland" + ], + "line": 2 + }, + { + "cells": [ + "Nováková", + "Česko" + ], + "line": 3 + }, + { + "cells": [ + "Kovačević", + "Hrvatska" + ], + "line": 4 + }, + { + "cells": [ + "Παπαδόπουλος", + "Παπαδόπουλος" + ], + "line": 5 + }, + { + "cells": [ + "罗/羅", + "中國" + ], + "line": 6 + } + ] + }, + { + "result": { + "duration": 111111, + "status": "passed" + }, + "name": "the card should be activated", + "keyword": "Then ", + "line": 19, + "match": { + "location": "ATMScenario.the_card_should_be_activated()" + } + } + ], + "type": "background" + }, + { + "id": "account-holder-withdraws-cash;account-has-'sufficient-funds';;2", + "tags": [ + { + "name": "@fast", + "line": 21 + }, + { + "name": "@featureTag", + "line": 1 + }, + { + "name": "@checkout", + "line": 21 + } + ], + "description": "Account holder withdraws cash", + "name": "Account has ", + "keyword": "Scenario Outline", + "line": 33, + "steps": [ + { + "result": { + "duration": 17007000, + "status": "passed" + }, + "name": "the account balance is 100", + "keyword": "Given ", + "line": 23, + "match": { + "arguments": [ + { + "val": "100", + "offset": 23 + } + ], + "location": "ATMScenario.createAccount(int)" + } + }, + { + "result": { + "duration": 33444444, + "status": "passed" + }, + "name": "the card is valid", + "keyword": "And ", + "line": 24, + "match": { + "arguments": [ + { + "val": "", + "offset": 0 + } + ], + "location": "ATMScenario.createCreditCard()" + } + }, + { + "result": { + "duration": 44333333, + "status": "passed" + }, + "name": "100 is contained in the machine", + "keyword": "And ", + "line": 25, + "match": { + "arguments": [ + { + "val": "100", + "offset": 0 + } + ], + "location": "ATMScenario.createATM(int)" + }, + "matchedColumns": [ + 1 + ] + }, + { + "result": { + "duration": 11000001, + "status": "passed" + }, + "name": "the Account Holder requests 10, entering PIN 1234", + "keyword": "When ", + "line": 26, + "match": { + "arguments": [ + { + "val": "10", + "offset": 28 + }, + { + "val": "1234", + "offset": 45 + } + ], + "location": "ATMScenario.requestMoney(int)" + }, + "matchedColumns": [ + 2 + ] + }, + { + "result": { + "duration": 3220000, + "status": "passed" + }, + "name": "the ATM should dispense 10 monetary units", + "keyword": "Then ", + "line": 27, + "match": { + "arguments": [ + { + "val": "10", + "offset": 24 + }, + { + "val": "", + "offset": 0 + } + ], + "location": "ATMScenario.checkMoney(int)" + }, + "matchedColumns": [ + 3 + ] + }, + { + "result": { + "duration": 30000000, + "status": "passed" + }, + "name": "the account balance should be 90", + "keyword": "And ", + "line": 28, + "arguments": [ + { + "rows": [ + { + "cells": [ + "max", + "min" + ] + }, + { + "cells": [ + "20", + "3" + ] + } + ] + } + ], + "match": { + "location": "ATMScenario.checkBalance(int)" + }, + "matchedColumns": [ + 2 + ] + } + ], + "type": "scenario", + "after": [ + { + "result": { + "duration": 60744700, + "status": "passed", + "error_message": "Completed" + }, + "match": { + "location": "MachineFactory.timeout()" + } + } + ] + } + ], + "uri": "net/masterthought/example(s)/ATM:東京.feature" + }, + { + "id": "account-holder-withdraws-more-cash", + "description": "As an Account Holder\nI want to withdraw cash from an ATM,
so that I can get money when the bank is closed", + "name": "Second feature", + "keyword": "Feature", + "line": 1, + "elements": [ + { + "id": "account-holder-withdraws-more-cash;account-has-sufficient-funds;;2", + "tags": [ + { + "name": "@checkout", + "line": 101 + } + ], + "before": [ + { + "output": [ + "System version: beta3" + ], + "result": { + "duration": 10744700, + "status": "passed" + }, + "match": { + "location": "MachineFactory.findCashMachine()" + } + }, + { + "result": { + "duration": 1000001, + "status": "failed", + "error_message": " \n" + }, + "match": { + "location": "MachineFactory.wait()" + } + } + ], + "description": "Account holder withdraws more cash", + "name": "Account may not have sufficient funds", + "keyword": "Scenario Outline", + "line": 19, + "steps": [ + { + "result": { + "status": "undefined" + }, + "name": "the account balance is 100", + "keyword": "Given ", + "line": 7, + "match": { + "arguments": [ + { + "val": "100", + "offset": 23 + }, + {} + ] + }, + "matchedColumns": [ + 0 + ], + "before": [ + { + "embeddings": [ + { + "mime_type": "text/plain", + "data": "" + } + ], + "result": { + "duration": 410802047, + "status": "failed" + } + } + ] + }, + { + "result": { + "duration": 13000, + "status": "passed" + }, + "name": "the card is valid", + "keyword": "And ", + "line": 8, + "match": { + "arguments": [ + { + "val": "", + "offset": 17 + } + ], + "location": "ATMScenario.createCreditCard()" + }, + "after": [ + { + "result": { + "duration": 410802048, + "status": "passed" + }, + "match": { + "location": "StepHook.afterStep()" + } + } + ] + }, + { + "result": { + "duration": 36000, + "status": "passed" + }, + "name": "the machine contains 100", + "keyword": "And ", + "line": 9, + "match": { + "arguments": [ + { + "val": "100", + "offset": 21 + } + ], + "location": "ATMScenario.createATM(int)" + }, + "matchedColumns": [ + 1 + ] + }, + { + "result": { + "duration": 32000, + "status": "passed" + }, + "name": "the Account Holder requests 20", + "keyword": "When ", + "line": 10, + "match": { + "arguments": [ + { + "val": "20", + "offset": 28 + } + ], + "location": "ATMScenario.requestMoney(int)" + }, + "matchedColumns": [ + 2 + ] + }, + { + "result": { + "duration": 36000, + "status": "passed" + }, + "name": "the ATM should dispense 20", + "keyword": "Then ", + "line": 11, + "match": { + "arguments": [ + { + "val": "20", + "offset": 24 + } + ], + "location": "ATMScenario.checkMoney(int)" + }, + "matchedColumns": [ + 3 + ] + }, + { + "result": { + "duration": 1933000, + "status": "skipped", + "error_message": "java.lang.AssertionError: \nExpected: is <80>\n got: <90>\n\n\tat org.junit.Assert.assertThat(Assert.java:780)\n\tat org.junit.Assert.assertThat(Assert.java:738)\n\tat net.masterthought.example.ATMScenario.checkBalance(ATMScenario.java:69)\n\tat ✽.And the account balance should be 90(net/masterthought/example/ATMK.feature:12)\n" + }, + "name": "the account balance should be 90", + "keyword": "And ", + "line": 12, + "match": { + "arguments": [ + { + "val": "90", + "offset": 30 + } + ], + "location": "ATMScenario.checkBalance(int)" + }, + "matchedColumns": [ + 4 + ], + "embeddings": [ + { + "mime_type": "image/png", + "data": "", + "name": "Some PNG image" + }, + { + "mime_type": "image/jpeg", + "data": "" + }, + { + "mime_type": "text/plain", + "data": "" + }, + { + "mime_type": "text/html", + "data": "", + "name": "Some HTML embedding" + }, + { + "mime_type": "text/xml", + "data": "" + }, + { + "mime_type": "image/svg+xml", + "data": "" + }, + { + "mime_type": "js", + "data": "" + }, + { + "mime_type": "text/plain", + "data": "" + }, + { + "mime_type": "text/csv", + "data": "" + }, + { + "mime_type": "video/mp4", + "data": "" + } + ] + }, + { + "result": { + "status": "pending" + }, + "name": "the card should be returned", + "keyword": "And ", + "line": 13, + "match": { + "location": "ATMScenario.cardShouldBeReturned()" + }, + "embeddings": [ + { + "mime_type": "application/json", + "data": "" + } + ] + }, + { + "result": { + "status": "skipped" + }, + "name": "its not implemented", + "keyword": "And ", + "line": 14, + "match": { + "location": "ATMScenario.its_not_implemented()" + }, + "output": [ + [ + "Could not connect to the server @Rocky@" + ], + [ + "Could not connect to the server @Mike@" + ] + ] + }, + { + "result": { + "status": "failed" + }, + "name": "the card is valid", + "keyword": "And ", + "line": 15, + "match": { + "location": "ATMScenario.createCreditCard()" + }, + "output": [ + "Checkpoints", + 232 + ] + }, + { + "result": { + "duration": 90000000, + "status": "ambiguous" + }, + "name": "the card should be returned", + "keyword": "And ", + "line": 29, + "match": { + "location": "ATMScenario.cardShouldBeReturned()" + } + } + ], + "type": "scenario", + "after": [ + { + "result": { + "duration": 64700000, + "status": "undefined", + "error_message": "Undefined step" + }, + "match": { + "location": "any.error()" + }, + "embeddings": [ + { + "mime_type": "image/png", + "data": "" + } + ] + } + ] + }, + { + "id": "account-holder-withdraws-more-cash;clean-up", + "name": "Clean-up", + "keyword": "Scenario", + "line": 31, + "steps": [ + { + "result": { + "duration": 560000, + "status": "passed" + }, + "name": "Stream closing", + "keyword": "Given ", + "line": 32 + } + ], + "type": "scenario" + }, + { + "id": "undefined-result", + "name": "This step has no result...", + "keyword": "Scenario", + "line": 35, + "steps": [ + { + "name": " - even it should", + "keyword": "Given ", + "line": 36 + } + ], + "type": "scenario" + } + ], + "uri": "net/masterthought/example/ATMK.feature" + } +] diff --git a/testlib/src/main/resources/json/cucumberJsonSampleGsonBefore.json b/testlib/src/main/resources/json/cucumberJsonSampleGsonBefore.json new file mode 100644 index 0000000000..8250630cf7 --- /dev/null +++ b/testlib/src/main/resources/json/cucumberJsonSampleGsonBefore.json @@ -0,0 +1,660 @@ +[ + { + "id": "account-holder-withdraws-cash", + "tags": [ + { + "name": "@featureTag", + "line": 1 + } + ], + "description": "This is description of the feature", + "name": "1st feature", + "keyword": "Feature", + "line": 2, + "elements": [ + { + "description": "Perfect background", + "name": "Activate Credit Card", + "keyword": "Background", + "line": 7, + "steps": [ + { + "result": { + "duration": 99107447000, + "status": "passed" + }, + "name": "I have a new credit card", + "keyword": "Given ", + "line": 8, + "match": { + "location": "ATMScenario.I_have_a_new_credit_card()" + }, + "embeddings": [ + { + "mime_type": "image/url", + "data": "" + }, + { + "data": "", + "media": { + "type": "text/plain" + } + } + ] + }, + { + "result": { + "duration": 9520000, + "status": "passed" + }, + "name": "My credit card is described as follow:", + "keyword": "And ", + "line": 9, + "match": { + "location": "ATMScenario.My_credit_card_is_described_as_follow" + }, + "doc_string": { + "content_type": "", + "line": 10, + "value": "{\n\"issuer\": {\n\"name\": \"Real Bank Inc.\",\n\"isn:\": \"RB55800093842N\"\n},\n\"card_number\": \"4896 0215 8478 6325\",\n\"holder\": \"A guy\"\n}" + } + }, + { + "result": { + "duration": 7040000, + "status": "passed" + }, + "name": "I confirm my pin number", + "keyword": "When ", + "line": 18, + "match": { + "location": "ATMScenario.I_confirm_my_pin_number()" + }, + "rows": [ + { + "cells": [ + "Müller", + "Deutschland" + ], + "line": 2 + }, + { + "cells": [ + "Nováková", + "Česko" + ], + "line": 3 + }, + { + "cells": [ + "Kovačević", + "Hrvatska" + ], + "line": 4 + }, + { + "cells": [ + "Παπαδόπουλος", + "Παπαδόπουλος" + ], + "line": 5 + }, + { + "cells": [ + "罗/羅", + "中國" + ], + "line": 6 + } + ] + }, + { + "result": { + "duration": 111111, + "status": "passed" + }, + "name": "the card should be activated", + "keyword": "Then ", + "line": 19, + "match": { + "location": "ATMScenario.the_card_should_be_activated()" + } + } + ], + "type": "background" + }, + { + "id": "account-holder-withdraws-cash;account-has-\u0027sufficient-funds\u0027;;2", + "tags": [ + { + "name": "@fast", + "line": 21 + }, + { + "name": "@featureTag", + "line": 1 + }, + { + "name": "@checkout", + "line": 21 + } + ], + "description": "Account holder withdraws cash", + "name": "Account has ", + "keyword": "Scenario Outline", + "line": 33, + "steps": [ + { + "result": { + "duration": 17007000, + "status": "passed" + }, + "name": "the account balance is 100", + "keyword": "Given ", + "line": 23, + "match": { + "arguments": [ + { + "val": "100", + "offset": 23 + } + ], + "location": "ATMScenario.createAccount(int)" + } + }, + { + "result": { + "duration": 33444444, + "status": "passed" + }, + "name": "the card is valid", + "keyword": "And ", + "line": 24, + "match": { + "arguments": [ + { + "val": "", + "offset": 0 + } + ], + "location": "ATMScenario.createCreditCard()" + } + }, + { + "result": { + "duration": 44333333, + "status": "passed" + }, + "name": "100 is contained in the machine", + "keyword": "And ", + "line": 25, + "match": { + "arguments": [ + { + "val": "100", + "offset": 0 + } + ], + "location": "ATMScenario.createATM(int)" + }, + "matchedColumns": [ + 1 + ] + }, + { + "result": { + "duration": 11000001, + "status": "passed" + }, + "name": "the Account Holder requests 10, entering PIN 1234", + "keyword": "When ", + "line": 26, + "match": { + "arguments": [ + { + "val": "10", + "offset": 28 + }, + { + "val": "1234", + "offset": 45 + } + ], + "location": "ATMScenario.requestMoney(int)" + }, + "matchedColumns": [ + 2 + ] + }, + { + "result": { + "duration": 3220000, + "status": "passed" + }, + "name": "the ATM should dispense 10 monetary units", + "keyword": "Then ", + "line": 27, + "match": { + "arguments": [ + { + "val": "10", + "offset": 24 + }, + { + "val": "", + "offset": 0 + } + ], + "location": "ATMScenario.checkMoney(int)" + }, + "matchedColumns": [ + 3 + ] + }, + { + "result": { + "duration": 30000000, + "status": "passed" + }, + "name": "the account balance should be 90", + "keyword": "And ", + "line": 28, + "arguments": [ + { + "rows": [ + { + "cells": [ + "max", + "min" + ] + }, + { + "cells": [ + "20", + "3" + ] + } + ] + } + ], + "match": { + "location": "ATMScenario.checkBalance(int)" + }, + "matchedColumns": [ + 2 + ] + } + ], + "type": "scenario", + "after": [ + { + "result": { + "duration": 60744700, + "status": "passed", + "error_message": "Completed" + }, + "match": { + "location": "MachineFactory.timeout()" + } + } + ] + } + ], + "uri": "net/masterthought/example(s)/ATM:東京.feature" + }, + { + "id": "account-holder-withdraws-more-cash", + "description": "As an Account Holder\nI want to withdraw cash from an ATM,
so that I can get money when the bank is closed", + "name": "Second feature", + "keyword": "Feature", + "line": 1, + "elements": [ + { + "id": "account-holder-withdraws-more-cash;account-has-sufficient-funds;;2", + "tags": [ + { + "name": "@checkout", + "line": 101 + } + ], + "before": [ + { + "output": [ + "System version: beta3" + ], + "result": { + "duration": 10744700, + "status": "passed" + }, + "match": { + "location": "MachineFactory.findCashMachine()" + } + }, + { + "result": { + "duration": 1000001, + "status": "failed", + "error_message": " \n" + }, + "match": { + "location": "MachineFactory.wait()" + } + } + ], + "description": "Account holder withdraws more cash", + "name": "Account may not have sufficient funds", + "keyword": "Scenario Outline", + "line": 19, + "steps": [ + { + "result": { + "status": "undefined" + }, + "name": "the account balance is 100", + "keyword": "Given ", + "line": 7, + "match": { + "arguments": [ + { + "val": "100", + "offset": 23 + }, + {} + ] + }, + "matchedColumns": [ + 0 + ], + "before": [ + { + "embeddings": [ + { + "mime_type": "text/plain", + "data": "" + } + ], + "result": { + "duration": 410802047, + "status": "failed" + } + } + ] + }, + { + "result": { + "duration": 13000, + "status": "passed" + }, + "name": "the card is valid", + "keyword": "And ", + "line": 8, + "match": { + "arguments": [ + { + "val": "", + "offset": 17 + } + ], + "location": "ATMScenario.createCreditCard()" + }, + "after": [ + { + "result": { + "duration": 410802048, + "status": "passed" + }, + "match": { + "location": "StepHook.afterStep()" + } + } + ] + }, + { + "result": { + "duration": 36000, + "status": "passed" + }, + "name": "the machine contains 100", + "keyword": "And ", + "line": 9, + "match": { + "arguments": [ + { + "val": "100", + "offset": 21 + } + ], + "location": "ATMScenario.createATM(int)" + }, + "matchedColumns": [ + 1 + ] + }, + { + "result": { + "duration": 32000, + "status": "passed" + }, + "name": "the Account Holder requests 20", + "keyword": "When ", + "line": 10, + "match": { + "arguments": [ + { + "val": "20", + "offset": 28 + } + ], + "location": "ATMScenario.requestMoney(int)" + }, + "matchedColumns": [ + 2 + ] + }, + { + "result": { + "duration": 36000, + "status": "passed" + }, + "name": "the ATM should dispense 20", + "keyword": "Then ", + "line": 11, + "match": { + "arguments": [ + { + "val": "20", + "offset": 24 + } + ], + "location": "ATMScenario.checkMoney(int)" + }, + "matchedColumns": [ + 3 + ] + }, + { + "result": { + "duration": 1933000, + "status": "skipped", + "error_message": "java.lang.AssertionError: \nExpected: is \u003c80\u003e\n got: \u003c90\u003e\n\n\tat org.junit.Assert.assertThat(Assert.java:780)\n\tat org.junit.Assert.assertThat(Assert.java:738)\n\tat net.masterthought.example.ATMScenario.checkBalance(ATMScenario.java:69)\n\tat ✽.And the account balance should be 90(net/masterthought/example/ATMK.feature:12)\n" + }, + "name": "the account balance should be 90", + "keyword": "And ", + "line": 12, + "match": { + "arguments": [ + { + "val": "90", + "offset": 30 + } + ], + "location": "ATMScenario.checkBalance(int)" + }, + "matchedColumns": [ + 4 + ], + "embeddings": [ + { + "mime_type": "image/png", + "data": "", + "name": "Some PNG image" + }, + { + "mime_type": "image/jpeg", + "data": "" + }, + { + "mime_type": "text/plain", + "data": "" + }, + { + "mime_type": "text/html", + "data": "", + "name": "Some HTML embedding" + }, + { + "mime_type": "text/xml", + "data": "" + }, + { + "mime_type": "image/svg+xml", + "data": "" + }, + { + "mime_type": "js", + "data": "" + }, + { + "mime_type": "text/plain", + "data": "" + }, + { + "mime_type": "text/csv", + "data": "" + }, + { + "mime_type": "video/mp4", + "data": "" + } + ] + }, + { + "result": { + "status": "pending" + }, + "name": "the card should be returned", + "keyword": "And ", + "line": 13, + "match": { + "location": "ATMScenario.cardShouldBeReturned()" + }, + "embeddings": [ + { + "mime_type": "application/json", + "data": "" + } + ] + }, + { + "result": { + "status": "skipped" + }, + "name": "its not implemented", + "keyword": "And ", + "line": 14, + "match": { + "location": "ATMScenario.its_not_implemented()" + }, + "output": [ + [ + "Could not connect to the server @Rocky@" + ], + [ + "Could not connect to the server @Mike@" + ] + ] + }, + { + "result": { + "status": "failed" + }, + "name": "the card is valid", + "keyword": "And ", + "line": 15, + "match": { + "location": "ATMScenario.createCreditCard()" + }, + "output": [ + "Checkpoints", + 232 + ] + }, + { + "result": { + "duration": 90000000, + "status": "ambiguous" + }, + "name": "the card should be returned", + "keyword": "And ", + "line": 29, + "match": { + "location": "ATMScenario.cardShouldBeReturned()" + } + } + ], + "type": "scenario", + "after": [ + { + "result": { + "duration": 64700000, + "status": "undefined", + "error_message": "Undefined step" + }, + "match": { + "location": "any.error()" + }, + "embeddings": [ + { + "mime_type": "image/png", + "data": "" + } + ] + } + ] + }, + { + "id": "account-holder-withdraws-more-cash;clean-up", + "name": "Clean-up", + "keyword": "Scenario", + "line": 31, + "steps": [ + { + "result": { + "duration": 560000, + "status": "passed" + }, + "name": "Stream closing", + "keyword": "Given ", + "line": 32 + } + ], + "type": "scenario" + }, + { + "id": "undefined-result", + "name": "This step has no result...", + "keyword": "Scenario", + "line": 35, + "steps": [ + { + "name": " - even it should", + "keyword": "Given ", + "line": 36 + } + ], + "type": "scenario" + } + ], + "uri": "net/masterthought/example/ATMK.feature" + } +] diff --git a/testlib/src/main/resources/json/escapeHtmlGsonAfter.json b/testlib/src/main/resources/json/escapeHtmlGsonAfter.json new file mode 100644 index 0000000000..f83692da2a --- /dev/null +++ b/testlib/src/main/resources/json/escapeHtmlGsonAfter.json @@ -0,0 +1,4 @@ +{ + "escapedHtml": "\u003ca href\u003d\u0027https://www.google.com/search?q\u003ddiffplug-spotless\u0026tbm\u003disch\u0027\u003eSee some pictures!\u003c\\a\u003e", + "rawHtml": "\u003ca href\u003d\u0027https://www.google.com/search?q\u003ddiffplug-spotless\u0026tbm\u003disch\u0027\u003eSee some pictures!\u003c\\a\u003e" +} diff --git a/testlib/src/main/resources/json/escapeHtmlGsonAfterDisabled.json b/testlib/src/main/resources/json/escapeHtmlGsonAfterDisabled.json new file mode 100644 index 0000000000..fe033341f8 --- /dev/null +++ b/testlib/src/main/resources/json/escapeHtmlGsonAfterDisabled.json @@ -0,0 +1,4 @@ +{ + "escapedHtml": "See some pictures!<\\a>", + "rawHtml": "See some pictures!<\\a>" +} diff --git a/testlib/src/main/resources/json/escapeHtmlGsonBefore.json b/testlib/src/main/resources/json/escapeHtmlGsonBefore.json new file mode 100644 index 0000000000..400e862d99 --- /dev/null +++ b/testlib/src/main/resources/json/escapeHtmlGsonBefore.json @@ -0,0 +1,4 @@ +{ + "escapedHtml": "\u003ca href\u003d\u0027https://www.google.com/search?q\u003ddiffplug-spotless\u0026tbm\u003disch\u0027\u003eSee some pictures!\u003c\\a\u003e", + "rawHtml": "See some pictures!<\\a>" +} diff --git a/testlib/src/main/resources/json/objectWithNullGsonAfter.json b/testlib/src/main/resources/json/objectWithNullGsonAfter.json new file mode 100644 index 0000000000..368632dd8a --- /dev/null +++ b/testlib/src/main/resources/json/objectWithNullGsonAfter.json @@ -0,0 +1,4 @@ +{ + "value": null, + "another": 1 +} diff --git a/testlib/src/main/resources/json/objectWithNullGsonBefore.json b/testlib/src/main/resources/json/objectWithNullGsonBefore.json new file mode 100644 index 0000000000..f68567c97c --- /dev/null +++ b/testlib/src/main/resources/json/objectWithNullGsonBefore.json @@ -0,0 +1,4 @@ +{ +"value": null, +"another": 1 +} diff --git a/testlib/src/main/resources/json/sortByKeysAfter.json b/testlib/src/main/resources/json/sortByKeysAfter.json new file mode 100644 index 0000000000..c4a48de2f2 --- /dev/null +++ b/testlib/src/main/resources/json/sortByKeysAfter.json @@ -0,0 +1,19 @@ +{ + "A": 1, + "X": 2, + "_arraysNotSorted": [ + 3, + 2, + 1 + ], + "a": 3, + "c": 4, + "x": 5, + "z": { + "A": 1, + "X": 2, + "a": 3, + "c": 4, + "x": 5 + } +} diff --git a/testlib/src/main/resources/json/sortByKeysAfterDisabled.json b/testlib/src/main/resources/json/sortByKeysAfterDisabled.json new file mode 100644 index 0000000000..de7462bb98 --- /dev/null +++ b/testlib/src/main/resources/json/sortByKeysAfterDisabled.json @@ -0,0 +1,19 @@ +{ + "z": { + "c": 4, + "x": 5, + "X": 2, + "A": 1, + "a": 3 + }, + "c": 4, + "x": 5, + "X": 2, + "A": 1, + "a": 3, + "_arraysNotSorted": [ + 3, + 2, + 1 + ] +} diff --git a/testlib/src/main/resources/json/sortByKeysBefore.json b/testlib/src/main/resources/json/sortByKeysBefore.json new file mode 100644 index 0000000000..de7462bb98 --- /dev/null +++ b/testlib/src/main/resources/json/sortByKeysBefore.json @@ -0,0 +1,19 @@ +{ + "z": { + "c": 4, + "x": 5, + "X": 2, + "A": 1, + "a": 3 + }, + "c": 4, + "x": 5, + "X": 2, + "A": 1, + "a": 3, + "_arraysNotSorted": [ + 3, + 2, + 1 + ] +} diff --git a/testlib/src/test/java/com/diffplug/spotless/json/GsonStepTest.java b/testlib/src/test/java/com/diffplug/spotless/json/GsonStepTest.java new file mode 100644 index 0000000000..80fde970c3 --- /dev/null +++ b/testlib/src/test/java/com/diffplug/spotless/json/GsonStepTest.java @@ -0,0 +1,85 @@ +package com.diffplug.spotless.json; + +import com.diffplug.spotless.FormatterStep; +import com.diffplug.spotless.Provisioner; + +import com.diffplug.spotless.StepHarness; +import com.diffplug.spotless.TestProvisioner; +import com.diffplug.spotless.json.gson.GsonStep; + +import org.junit.jupiter.api.Test; + +import static org.assertj.core.api.Assertions.assertThatThrownBy; + +public class GsonStepTest extends JsonFormatterStepCommonTests { + + private static final String DEFAULT_VERSION = "2.8.9"; + + @Test + void handlesComplexNestedObject() throws Exception { + doWithResource("cucumberJsonSampleGson"); + } + + @Test + void handlesObjectWithNull() throws Exception { + doWithResource("objectWithNullGson"); + } + + @Test + void handlesInvalidJson() { + assertThatThrownBy(() -> doWithResource("invalidJson")) + .isInstanceOf(AssertionError.class) + .hasMessage("Unable to format JSON") + .hasRootCauseMessage("End of input at line 3 column 1 path $.a"); + } + + @Test + void handlesNotJson() { + assertThatThrownBy(() -> doWithResource("notJson")) + .isInstanceOf(AssertionError.class) + .hasMessage("Unable to format JSON") + .hasNoCause(); + } + + @Test + void handlesSortingWhenSortByKeyEnabled() throws Exception { + FormatterStep step = GsonStep.create(INDENT, true, false, DEFAULT_VERSION, TestProvisioner.mavenCentral()); + StepHarness stepHarness = StepHarness.forStep(step); + stepHarness.testResource("json/sortByKeysBefore.json", "json/sortByKeysAfter.json"); + } + + @Test + void doesNoSortingWhenSortByKeyDisabled() throws Exception { + FormatterStep step = GsonStep.create(INDENT, false, false, DEFAULT_VERSION, TestProvisioner.mavenCentral()); + StepHarness.forStep(step) + .testResource("json/sortByKeysBefore.json", "json/sortByKeysAfterDisabled.json"); + } + + @Test + void handlesHtmlEscapeWhenEnabled() throws Exception { + FormatterStep step = GsonStep.create(INDENT, false, true, DEFAULT_VERSION, TestProvisioner.mavenCentral()); + StepHarness.forStep(step) + .testResource("json/escapeHtmlGsonBefore.json", "json/escapeHtmlGsonAfter.json"); + } + + @Test + void writesRawHtmlWhenHtmlEscapeDisabled() throws Exception { + FormatterStep step = GsonStep.create(INDENT, false, false, DEFAULT_VERSION, TestProvisioner.mavenCentral()); + StepHarness.forStep(step) + .testResource("json/escapeHtmlGsonBefore.json", "json/escapeHtmlGsonAfterDisabled.json"); + } + + @Test + void handlesVersionIncompatibility() { + FormatterStep step = GsonStep.create(INDENT, false, false, "1.7", TestProvisioner.mavenCentral()); + StepHarness stepHarness = StepHarness.forStep(step); + assertThatThrownBy(() -> stepHarness.testResource("json/cucumberJsonSampleGsonBefore.json", "json/cucumberJsonSampleGsonAfter.json")) + .isInstanceOf(IllegalStateException.class) + .hasMessage("There was a problem interacting with Gson; maybe you set an incompatible version?"); + } + + @Override + protected FormatterStep createFormatterStep(int indent, Provisioner provisioner) { + return GsonStep.create(indent, false, false, DEFAULT_VERSION, provisioner); + } +} diff --git a/testlib/src/test/java/com/diffplug/spotless/json/JsonFormatterStepCommonTests.java b/testlib/src/test/java/com/diffplug/spotless/json/JsonFormatterStepCommonTests.java new file mode 100644 index 0000000000..dd8d9ba69a --- /dev/null +++ b/testlib/src/test/java/com/diffplug/spotless/json/JsonFormatterStepCommonTests.java @@ -0,0 +1,89 @@ +package com.diffplug.spotless.json; + +import com.diffplug.spotless.*; + +import org.junit.jupiter.api.Test; + +import static org.assertj.core.api.Assertions.assertThatThrownBy; + +public abstract class JsonFormatterStepCommonTests { + + protected static final int INDENT = 4; + + @Test + void cannotProvideNullProvisioner() { + assertThatThrownBy(() -> createFormatterStep(INDENT, null)) + .isInstanceOf(NullPointerException.class) + .hasMessage("provisioner cannot be null"); + } + + @Test + void handlesNestedObject() throws Exception { + doWithResource("nestedObject"); + } + + @Test + void handlesSingletonArray() throws Exception { + doWithResource("singletonArray"); + } + + @Test + void handlesEmptyFile() throws Exception { + doWithResource("empty"); + } + + @Test + void canSetCustomIndentationLevel() throws Exception { + FormatterStep step = createFormatterStep(6, TestProvisioner.mavenCentral()); + StepHarness stepHarness = StepHarness.forStep(step); + + String before = "json/singletonArrayBefore.json"; + String after = "json/singletonArrayAfter6Spaces.json"; + stepHarness.testResource(before, after); + } + + @Test + void canSetIndentationLevelTo0() throws Exception { + FormatterStep step = createFormatterStep(0, TestProvisioner.mavenCentral()); + StepHarness stepHarness = StepHarness.forStep(step); + + String before = "json/singletonArrayBefore.json"; + String after = "json/singletonArrayAfter0Spaces.json"; + stepHarness.testResource(before, after); + } + + @Test + void equality() { + new SerializableEqualityTester() { + int spaces = 0; + + @Override + protected void setupTest(API api) { + // no changes, are the same + api.areDifferentThan(); + + // with different spacing + spaces = 1; + api.areDifferentThan(); + } + + @Override + protected FormatterStep create() { + return createFormatterStep(spaces, TestProvisioner.mavenCentral()); + } + }.testEquals(); + } + + protected abstract FormatterStep createFormatterStep(int indent, Provisioner provisioner); + + protected StepHarness getStepHarness() { + return StepHarness.forStep(createFormatterStep(INDENT, TestProvisioner.mavenCentral())); + } + + protected void doWithResource(String name) throws Exception { + String before = String.format("json/%sBefore.json", name); + String after = String.format("json/%sAfter.json", name); + getStepHarness().testResource(before, after); + } + +} diff --git a/testlib/src/test/java/com/diffplug/spotless/json/JsonSimpleStepTest.java b/testlib/src/test/java/com/diffplug/spotless/json/JsonSimpleStepTest.java index 4085744593..a8b166fa21 100644 --- a/testlib/src/test/java/com/diffplug/spotless/json/JsonSimpleStepTest.java +++ b/testlib/src/test/java/com/diffplug/spotless/json/JsonSimpleStepTest.java @@ -17,121 +17,50 @@ import static org.assertj.core.api.Assertions.assertThatThrownBy; -import org.junit.jupiter.api.Test; - -import com.diffplug.spotless.FormatterStep; -import com.diffplug.spotless.SerializableEqualityTester; -import com.diffplug.spotless.StepHarness; -import com.diffplug.spotless.TestProvisioner; - -class JsonSimpleStepTest { - - private static final int INDENT = 4; +import com.diffplug.spotless.*; - private final FormatterStep step = JsonSimpleStep.create(INDENT, TestProvisioner.mavenCentral()); - private final StepHarness stepHarness = StepHarness.forStep(step); +import org.junit.jupiter.api.Test; - @Test - void cannotProvidedNullProvisioner() { - assertThatThrownBy(() -> JsonSimpleStep.create(INDENT, null)).isInstanceOf(NullPointerException.class).hasMessage("provisioner cannot be null"); - } +class JsonSimpleStepTest extends JsonFormatterStepCommonTests { @Test void handlesSingletonObject() throws Exception { - doWithResource(stepHarness, "singletonObject"); + doWithResource("singletonObject"); } @Test void handlesSingletonObjectWithArray() throws Exception { - doWithResource(stepHarness, "singletonObjectWithArray"); - } - - @Test - void handlesNestedObject() throws Exception { - doWithResource(stepHarness, "nestedObject"); - } - - @Test - void handlesSingletonArray() throws Exception { - doWithResource(stepHarness, "singletonArray"); - } - - @Test - void handlesEmptyFile() throws Exception { - doWithResource(stepHarness, "empty"); + doWithResource("singletonObjectWithArray"); } @Test void handlesComplexNestedObject() throws Exception { - doWithResource(stepHarness, "cucumberJsonSample"); + doWithResource("cucumberJsonSample"); } @Test void handlesObjectWithNull() throws Exception { - doWithResource(stepHarness, "objectWithNull"); + doWithResource("objectWithNull"); } @Test void handlesInvalidJson() { - assertThatThrownBy(() -> doWithResource(stepHarness, "invalidJson")) - .isInstanceOf(AssertionError.class) - .hasMessage("Unable to format JSON") - .hasRootCauseMessage("Expected a ',' or '}' at 9 [character 0 line 3]"); + assertThatThrownBy(() -> doWithResource("invalidJson")) + .isInstanceOf(AssertionError.class) + .hasMessage("Unable to format JSON") + .hasRootCauseMessage("Expected a ',' or '}' at 9 [character 0 line 3]"); } @Test void handlesNotJson() { - assertThatThrownBy(() -> doWithResource(stepHarness, "notJson")) - .isInstanceOf(AssertionError.class) - .hasMessage("Unable to determine JSON type, expected a '{' or '[' but found '#'") - .hasNoCause(); - } - - @Test - void canSetCustomIndentationLevel() throws Exception { - FormatterStep step = JsonSimpleStep.create(6, TestProvisioner.mavenCentral()); - StepHarness stepHarness = StepHarness.forStep(step); - - String before = "json/singletonArrayBefore.json"; - String after = "json/singletonArrayAfter6Spaces.json"; - stepHarness.testResource(before, after); - } - - @Test - void canSetIndentationLevelTo0() throws Exception { - FormatterStep step = JsonSimpleStep.create(0, TestProvisioner.mavenCentral()); - StepHarness stepHarness = StepHarness.forStep(step); - - String before = "json/singletonArrayBefore.json"; - String after = "json/singletonArrayAfter0Spaces.json"; - stepHarness.testResource(before, after); - } - - @Test - void equality() { - new SerializableEqualityTester() { - int spaces = 0; - - @Override - protected void setupTest(API api) { - // no changes, are the same - api.areDifferentThan(); - - // with different spacing - spaces = 1; - api.areDifferentThan(); - } - - @Override - protected FormatterStep create() { - return JsonSimpleStep.create(spaces, TestProvisioner.mavenCentral()); - } - }.testEquals(); + assertThatThrownBy(() -> doWithResource("notJson")) + .isInstanceOf(AssertionError.class) + .hasMessage("Unable to determine JSON type, expected a '{' or '[' but found '#'") + .hasNoCause(); } - private static void doWithResource(StepHarness stepHarness, String name) throws Exception { - String before = String.format("json/%sBefore.json", name); - String after = String.format("json/%sAfter.json", name); - stepHarness.testResource(before, after); + @Override + protected FormatterStep createFormatterStep(int indent, Provisioner provisioner) { + return JsonSimpleStep.create(indent, provisioner); } } From 7f15f16f4c00fdd3eabd4f1e79a9cd99a0f6fb32 Mon Sep 17 00:00:00 2001 From: Abel Keszei Date: Sat, 12 Feb 2022 18:24:11 +0100 Subject: [PATCH 017/757] add escapeHtml to README --- plugin-gradle/README.md | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/plugin-gradle/README.md b/plugin-gradle/README.md index b3821d5277..7a6089850c 100644 --- a/plugin-gradle/README.md +++ b/plugin-gradle/README.md @@ -626,11 +626,19 @@ spotless { gson() .indentWithSpaces(6) // optional: specify the number of spaces to use .sortByKeys() // optional: sort JSON by its keys + .escapeHtml() // optional: escape HTML in values .version('2.8.1') // optional: specify version } } ``` +Notes: +* There's no option in Gson to leave HTML as-is (i.e. escaped HTML would remain escaped, raw would remain raw). Either +all HTML characters are written escaped or none. Set `escapeHtml` if you prefer the former. +* `sortByKeys` will apply lexicographic order on the keys of the input JSON. See the +[javadoc of String](https://docs.oracle.com/en/java/javase/11/docs/api/java.base/java/lang/String.html#compareTo(java.lang.String)) +for details. + ## Prettier From 3835b5d8904c0e88144c1ec8800902df49e8b494 Mon Sep 17 00:00:00 2001 From: Abel Keszei Date: Sat, 12 Feb 2022 18:59:03 +0100 Subject: [PATCH 018/757] update JsonExtension tests --- .../gradle/spotless/JsonExtensionTest.java | 83 ++++++++++++++++++- 1 file changed, 81 insertions(+), 2 deletions(-) diff --git a/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/JsonExtensionTest.java b/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/JsonExtensionTest.java index edcd4b428f..09ff70673f 100644 --- a/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/JsonExtensionTest.java +++ b/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/JsonExtensionTest.java @@ -21,7 +21,7 @@ class JsonExtensionTest extends GradleIntegrationHarness { @Test - void defaultFormatting() throws IOException { + void simpleDefaultFormatting() throws IOException { setFile("build.gradle").toLines( "plugins {", " id 'java'", @@ -42,7 +42,7 @@ void defaultFormatting() throws IOException { } @Test - void formattingWithCustomNumberOfSpaces() throws IOException { + void simpleFormattingWithCustomNumberOfSpaces() throws IOException { setFile("build.gradle").toLines( "plugins {", " id 'java'", @@ -59,4 +59,83 @@ void formattingWithCustomNumberOfSpaces() throws IOException { gradleRunner().withArguments("spotlessApply").build(); assertFile("src/main/resources/example.json").sameAsResource("json/singletonArrayAfter6Spaces.json"); } + + @Test + void gsonDefaultFormatting() throws IOException { + setFile("build.gradle").toLines( + "plugins {", + " id 'java'", + " id 'com.diffplug.spotless'", + "}", + "repositories { mavenCentral() }", + "spotless {", + " json {", + " target 'examples/**/*.json'", + " gson()", + "}", + "}"); + setFile("src/main/resources/example.json").toResource("json/nestedObjectBefore.json"); + setFile("examples/main/resources/example.json").toResource("json/nestedObjectBefore.json"); + gradleRunner().withArguments("spotlessApply").build(); + assertFile("src/main/resources/example.json").sameAsResource("json/nestedObjectBefore.json"); + assertFile("examples/main/resources/example.json").sameAsResource("json/nestedObjectAfter.json"); + } + + @Test + void gsonFormattingWithCustomNumberOfSpaces() throws IOException { + setFile("build.gradle").toLines( + "plugins {", + " id 'java'", + " id 'com.diffplug.spotless'", + "}", + "repositories { mavenCentral() }", + "spotless {", + " json {", + " target 'src/**/*.json'", + " gson().indentWithSpaces(6)", + "}", + "}"); + setFile("src/main/resources/example.json").toResource("json/singletonArrayBefore.json"); + gradleRunner().withArguments("spotlessApply").build(); + assertFile("src/main/resources/example.json").sameAsResource("json/singletonArrayAfter6Spaces.json"); + } + + @Test + void gsonFormattingWithSortingByKeys() throws IOException { + setFile("build.gradle").toLines( + "plugins {", + " id 'java'", + " id 'com.diffplug.spotless'", + "}", + "repositories { mavenCentral() }", + "spotless {", + " json {", + " target 'src/**/*.json'", + " gson().sortByKeys()", + "}", + "}"); + setFile("src/main/resources/example.json").toResource("json/sortByKeysBefore.json"); + gradleRunner().withArguments("spotlessApply").build(); + assertFile("src/main/resources/example.json").sameAsResource("json/sortByKeysAfter.json"); + } + + @Test + void gsonFormattingWithHtmlEscape() throws IOException { + setFile("build.gradle").toLines( + "plugins {", + " id 'java'", + " id 'com.diffplug.spotless'", + "}", + "repositories { mavenCentral() }", + "spotless {", + " json {", + " target 'src/**/*.json'", + " gson().escapeHtml()", + "}", + "}"); + setFile("src/main/resources/example.json").toResource("json/escapeHtmlGsonBefore.json"); + gradleRunner().withArguments("spotlessApply").build(); + assertFile("src/main/resources/example.json").sameAsResource("json/escapeHtmlGsonAfter.json"); + } + } From b42a8cd392d48b823523a6d02acfc30717c5efb7 Mon Sep 17 00:00:00 2001 From: Abel Keszei Date: Sat, 12 Feb 2022 19:00:30 +0100 Subject: [PATCH 019/757] apply format --- .../json/gson/GsonBuilderWrapper.java | 15 ++++ .../diffplug/spotless/json/gson/GsonStep.java | 39 +++++--- .../spotless/json/gson/GsonWrapper.java | 19 +++- .../spotless/json/gson/GsonWrapperBase.java | 15 ++++ .../json/gson/JsonElementWrapper.java | 21 ++++- .../spotless/json/gson/JsonObjectWrapper.java | 19 +++- .../spotless/json/gson/JsonWriterWrapper.java | 19 +++- .../gradle/spotless/JsonExtension.java | 2 +- .../gradle/spotless/JsonExtensionTest.java | 90 +++++++++---------- .../diffplug/spotless/json/GsonStepTest.java | 46 ++++++---- .../json/JsonFormatterStepCommonTests.java | 23 ++++- .../spotless/json/JsonSimpleStepTest.java | 18 ++-- 12 files changed, 229 insertions(+), 97 deletions(-) diff --git a/lib/src/main/java/com/diffplug/spotless/json/gson/GsonBuilderWrapper.java b/lib/src/main/java/com/diffplug/spotless/json/gson/GsonBuilderWrapper.java index 1693a5f9da..365e27fb4c 100644 --- a/lib/src/main/java/com/diffplug/spotless/json/gson/GsonBuilderWrapper.java +++ b/lib/src/main/java/com/diffplug/spotless/json/gson/GsonBuilderWrapper.java @@ -1,3 +1,18 @@ +/* + * Copyright 2022 DiffPlug + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ package com.diffplug.spotless.json.gson; import java.lang.reflect.Constructor; diff --git a/lib/src/main/java/com/diffplug/spotless/json/gson/GsonStep.java b/lib/src/main/java/com/diffplug/spotless/json/gson/GsonStep.java index 40ca84eeb7..06519ae39d 100644 --- a/lib/src/main/java/com/diffplug/spotless/json/gson/GsonStep.java +++ b/lib/src/main/java/com/diffplug/spotless/json/gson/GsonStep.java @@ -1,16 +1,31 @@ +/* + * Copyright 2022 DiffPlug + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ package com.diffplug.spotless.json.gson; -import com.diffplug.spotless.FormatterFunc; -import com.diffplug.spotless.FormatterStep; -import com.diffplug.spotless.JarState; -import com.diffplug.spotless.Provisioner; - import java.io.IOException; import java.io.Serializable; import java.io.StringWriter; import java.util.Collections; import java.util.Objects; +import com.diffplug.spotless.FormatterFunc; +import com.diffplug.spotless.FormatterStep; +import com.diffplug.spotless.JarState; +import com.diffplug.spotless.Provisioner; + public class GsonStep { private static final String MAVEN_COORDINATES = "com.google.code.gson:gson"; @@ -73,13 +88,13 @@ FormatterFunc toFormatter() { private Object sortByKeys(JsonObjectWrapper jsonObjectWrapper, JsonElementWrapper jsonElementWrapper, Object jsonObject) { Object result = jsonObjectWrapper.createJsonObject(); jsonObjectWrapper.keySet(jsonObject).stream().sorted() - .forEach(key -> { - Object element = jsonObjectWrapper.get(jsonObject, key); - if (jsonElementWrapper.isJsonObject(element)) { - element = sortByKeys(jsonObjectWrapper, jsonElementWrapper, element); - } - jsonObjectWrapper.add(result, key, element); - }); + .forEach(key -> { + Object element = jsonObjectWrapper.get(jsonObject, key); + if (jsonElementWrapper.isJsonObject(element)) { + element = sortByKeys(jsonObjectWrapper, jsonElementWrapper, element); + } + jsonObjectWrapper.add(result, key, element); + }); return result; } diff --git a/lib/src/main/java/com/diffplug/spotless/json/gson/GsonWrapper.java b/lib/src/main/java/com/diffplug/spotless/json/gson/GsonWrapper.java index 53e765fa04..fabb257964 100644 --- a/lib/src/main/java/com/diffplug/spotless/json/gson/GsonWrapper.java +++ b/lib/src/main/java/com/diffplug/spotless/json/gson/GsonWrapper.java @@ -1,10 +1,25 @@ +/* + * Copyright 2022 DiffPlug + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ package com.diffplug.spotless.json.gson; -import com.diffplug.spotless.JarState; - import java.lang.reflect.Constructor; import java.lang.reflect.Method; +import com.diffplug.spotless.JarState; + public class GsonWrapper extends GsonWrapperBase { private final Constructor constructor; diff --git a/lib/src/main/java/com/diffplug/spotless/json/gson/GsonWrapperBase.java b/lib/src/main/java/com/diffplug/spotless/json/gson/GsonWrapperBase.java index 31e22d53d0..3438c6062f 100644 --- a/lib/src/main/java/com/diffplug/spotless/json/gson/GsonWrapperBase.java +++ b/lib/src/main/java/com/diffplug/spotless/json/gson/GsonWrapperBase.java @@ -1,3 +1,18 @@ +/* + * Copyright 2022 DiffPlug + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ package com.diffplug.spotless.json.gson; import java.lang.reflect.Constructor; diff --git a/lib/src/main/java/com/diffplug/spotless/json/gson/JsonElementWrapper.java b/lib/src/main/java/com/diffplug/spotless/json/gson/JsonElementWrapper.java index a45225b411..cbb04a411a 100644 --- a/lib/src/main/java/com/diffplug/spotless/json/gson/JsonElementWrapper.java +++ b/lib/src/main/java/com/diffplug/spotless/json/gson/JsonElementWrapper.java @@ -1,10 +1,23 @@ +/* + * Copyright 2022 DiffPlug + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ package com.diffplug.spotless.json.gson; -import com.diffplug.spotless.JarState; - -import java.lang.reflect.Constructor; import java.lang.reflect.Method; -import java.util.Set; + +import com.diffplug.spotless.JarState; public class JsonElementWrapper extends GsonWrapperBase { diff --git a/lib/src/main/java/com/diffplug/spotless/json/gson/JsonObjectWrapper.java b/lib/src/main/java/com/diffplug/spotless/json/gson/JsonObjectWrapper.java index 5485ce2ffc..0e2d48cf71 100644 --- a/lib/src/main/java/com/diffplug/spotless/json/gson/JsonObjectWrapper.java +++ b/lib/src/main/java/com/diffplug/spotless/json/gson/JsonObjectWrapper.java @@ -1,11 +1,26 @@ +/* + * Copyright 2022 DiffPlug + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ package com.diffplug.spotless.json.gson; -import com.diffplug.spotless.JarState; - import java.lang.reflect.Constructor; import java.lang.reflect.Method; import java.util.Set; +import com.diffplug.spotless.JarState; + public class JsonObjectWrapper extends GsonWrapperBase { private final Constructor constructor; diff --git a/lib/src/main/java/com/diffplug/spotless/json/gson/JsonWriterWrapper.java b/lib/src/main/java/com/diffplug/spotless/json/gson/JsonWriterWrapper.java index 580e075e77..55ce4c0955 100644 --- a/lib/src/main/java/com/diffplug/spotless/json/gson/JsonWriterWrapper.java +++ b/lib/src/main/java/com/diffplug/spotless/json/gson/JsonWriterWrapper.java @@ -1,11 +1,26 @@ +/* + * Copyright 2022 DiffPlug + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ package com.diffplug.spotless.json.gson; -import com.diffplug.spotless.JarState; - import java.io.Writer; import java.lang.reflect.Constructor; import java.lang.reflect.Method; +import com.diffplug.spotless.JarState; + public class JsonWriterWrapper extends GsonWrapperBase { private final Class clazz; diff --git a/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/JsonExtension.java b/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/JsonExtension.java index bce3a68060..25182fa4bc 100644 --- a/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/JsonExtension.java +++ b/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/JsonExtension.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. diff --git a/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/JsonExtensionTest.java b/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/JsonExtensionTest.java index 09ff70673f..e2fb9f70aa 100644 --- a/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/JsonExtensionTest.java +++ b/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/JsonExtensionTest.java @@ -1,5 +1,5 @@ /* - * Copyright 2021 DiffPlug + * Copyright 2021-2022 DiffPlug * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -63,17 +63,17 @@ void simpleFormattingWithCustomNumberOfSpaces() throws IOException { @Test void gsonDefaultFormatting() throws IOException { setFile("build.gradle").toLines( - "plugins {", - " id 'java'", - " id 'com.diffplug.spotless'", - "}", - "repositories { mavenCentral() }", - "spotless {", - " json {", - " target 'examples/**/*.json'", - " gson()", - "}", - "}"); + "plugins {", + " id 'java'", + " id 'com.diffplug.spotless'", + "}", + "repositories { mavenCentral() }", + "spotless {", + " json {", + " target 'examples/**/*.json'", + " gson()", + "}", + "}"); setFile("src/main/resources/example.json").toResource("json/nestedObjectBefore.json"); setFile("examples/main/resources/example.json").toResource("json/nestedObjectBefore.json"); gradleRunner().withArguments("spotlessApply").build(); @@ -84,17 +84,17 @@ void gsonDefaultFormatting() throws IOException { @Test void gsonFormattingWithCustomNumberOfSpaces() throws IOException { setFile("build.gradle").toLines( - "plugins {", - " id 'java'", - " id 'com.diffplug.spotless'", - "}", - "repositories { mavenCentral() }", - "spotless {", - " json {", - " target 'src/**/*.json'", - " gson().indentWithSpaces(6)", - "}", - "}"); + "plugins {", + " id 'java'", + " id 'com.diffplug.spotless'", + "}", + "repositories { mavenCentral() }", + "spotless {", + " json {", + " target 'src/**/*.json'", + " gson().indentWithSpaces(6)", + "}", + "}"); setFile("src/main/resources/example.json").toResource("json/singletonArrayBefore.json"); gradleRunner().withArguments("spotlessApply").build(); assertFile("src/main/resources/example.json").sameAsResource("json/singletonArrayAfter6Spaces.json"); @@ -103,17 +103,17 @@ void gsonFormattingWithCustomNumberOfSpaces() throws IOException { @Test void gsonFormattingWithSortingByKeys() throws IOException { setFile("build.gradle").toLines( - "plugins {", - " id 'java'", - " id 'com.diffplug.spotless'", - "}", - "repositories { mavenCentral() }", - "spotless {", - " json {", - " target 'src/**/*.json'", - " gson().sortByKeys()", - "}", - "}"); + "plugins {", + " id 'java'", + " id 'com.diffplug.spotless'", + "}", + "repositories { mavenCentral() }", + "spotless {", + " json {", + " target 'src/**/*.json'", + " gson().sortByKeys()", + "}", + "}"); setFile("src/main/resources/example.json").toResource("json/sortByKeysBefore.json"); gradleRunner().withArguments("spotlessApply").build(); assertFile("src/main/resources/example.json").sameAsResource("json/sortByKeysAfter.json"); @@ -122,17 +122,17 @@ void gsonFormattingWithSortingByKeys() throws IOException { @Test void gsonFormattingWithHtmlEscape() throws IOException { setFile("build.gradle").toLines( - "plugins {", - " id 'java'", - " id 'com.diffplug.spotless'", - "}", - "repositories { mavenCentral() }", - "spotless {", - " json {", - " target 'src/**/*.json'", - " gson().escapeHtml()", - "}", - "}"); + "plugins {", + " id 'java'", + " id 'com.diffplug.spotless'", + "}", + "repositories { mavenCentral() }", + "spotless {", + " json {", + " target 'src/**/*.json'", + " gson().escapeHtml()", + "}", + "}"); setFile("src/main/resources/example.json").toResource("json/escapeHtmlGsonBefore.json"); gradleRunner().withArguments("spotlessApply").build(); assertFile("src/main/resources/example.json").sameAsResource("json/escapeHtmlGsonAfter.json"); diff --git a/testlib/src/test/java/com/diffplug/spotless/json/GsonStepTest.java b/testlib/src/test/java/com/diffplug/spotless/json/GsonStepTest.java index 80fde970c3..a9fdc5383c 100644 --- a/testlib/src/test/java/com/diffplug/spotless/json/GsonStepTest.java +++ b/testlib/src/test/java/com/diffplug/spotless/json/GsonStepTest.java @@ -1,16 +1,30 @@ +/* + * Copyright 2022 DiffPlug + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ package com.diffplug.spotless.json; +import static org.assertj.core.api.Assertions.assertThatThrownBy; + +import org.junit.jupiter.api.Test; + import com.diffplug.spotless.FormatterStep; import com.diffplug.spotless.Provisioner; - import com.diffplug.spotless.StepHarness; import com.diffplug.spotless.TestProvisioner; import com.diffplug.spotless.json.gson.GsonStep; -import org.junit.jupiter.api.Test; - -import static org.assertj.core.api.Assertions.assertThatThrownBy; - public class GsonStepTest extends JsonFormatterStepCommonTests { private static final String DEFAULT_VERSION = "2.8.9"; @@ -28,17 +42,17 @@ void handlesObjectWithNull() throws Exception { @Test void handlesInvalidJson() { assertThatThrownBy(() -> doWithResource("invalidJson")) - .isInstanceOf(AssertionError.class) - .hasMessage("Unable to format JSON") - .hasRootCauseMessage("End of input at line 3 column 1 path $.a"); + .isInstanceOf(AssertionError.class) + .hasMessage("Unable to format JSON") + .hasRootCauseMessage("End of input at line 3 column 1 path $.a"); } @Test void handlesNotJson() { assertThatThrownBy(() -> doWithResource("notJson")) - .isInstanceOf(AssertionError.class) - .hasMessage("Unable to format JSON") - .hasNoCause(); + .isInstanceOf(AssertionError.class) + .hasMessage("Unable to format JSON") + .hasNoCause(); } @Test @@ -52,21 +66,21 @@ void handlesSortingWhenSortByKeyEnabled() throws Exception { void doesNoSortingWhenSortByKeyDisabled() throws Exception { FormatterStep step = GsonStep.create(INDENT, false, false, DEFAULT_VERSION, TestProvisioner.mavenCentral()); StepHarness.forStep(step) - .testResource("json/sortByKeysBefore.json", "json/sortByKeysAfterDisabled.json"); + .testResource("json/sortByKeysBefore.json", "json/sortByKeysAfterDisabled.json"); } @Test void handlesHtmlEscapeWhenEnabled() throws Exception { FormatterStep step = GsonStep.create(INDENT, false, true, DEFAULT_VERSION, TestProvisioner.mavenCentral()); StepHarness.forStep(step) - .testResource("json/escapeHtmlGsonBefore.json", "json/escapeHtmlGsonAfter.json"); + .testResource("json/escapeHtmlGsonBefore.json", "json/escapeHtmlGsonAfter.json"); } @Test void writesRawHtmlWhenHtmlEscapeDisabled() throws Exception { FormatterStep step = GsonStep.create(INDENT, false, false, DEFAULT_VERSION, TestProvisioner.mavenCentral()); StepHarness.forStep(step) - .testResource("json/escapeHtmlGsonBefore.json", "json/escapeHtmlGsonAfterDisabled.json"); + .testResource("json/escapeHtmlGsonBefore.json", "json/escapeHtmlGsonAfterDisabled.json"); } @Test @@ -74,8 +88,8 @@ void handlesVersionIncompatibility() { FormatterStep step = GsonStep.create(INDENT, false, false, "1.7", TestProvisioner.mavenCentral()); StepHarness stepHarness = StepHarness.forStep(step); assertThatThrownBy(() -> stepHarness.testResource("json/cucumberJsonSampleGsonBefore.json", "json/cucumberJsonSampleGsonAfter.json")) - .isInstanceOf(IllegalStateException.class) - .hasMessage("There was a problem interacting with Gson; maybe you set an incompatible version?"); + .isInstanceOf(IllegalStateException.class) + .hasMessage("There was a problem interacting with Gson; maybe you set an incompatible version?"); } @Override diff --git a/testlib/src/test/java/com/diffplug/spotless/json/JsonFormatterStepCommonTests.java b/testlib/src/test/java/com/diffplug/spotless/json/JsonFormatterStepCommonTests.java index dd8d9ba69a..9ee76f994c 100644 --- a/testlib/src/test/java/com/diffplug/spotless/json/JsonFormatterStepCommonTests.java +++ b/testlib/src/test/java/com/diffplug/spotless/json/JsonFormatterStepCommonTests.java @@ -1,10 +1,25 @@ +/* + * Copyright 2022 DiffPlug + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ package com.diffplug.spotless.json; -import com.diffplug.spotless.*; +import static org.assertj.core.api.Assertions.assertThatThrownBy; import org.junit.jupiter.api.Test; -import static org.assertj.core.api.Assertions.assertThatThrownBy; +import com.diffplug.spotless.*; public abstract class JsonFormatterStepCommonTests { @@ -13,8 +28,8 @@ public abstract class JsonFormatterStepCommonTests { @Test void cannotProvideNullProvisioner() { assertThatThrownBy(() -> createFormatterStep(INDENT, null)) - .isInstanceOf(NullPointerException.class) - .hasMessage("provisioner cannot be null"); + .isInstanceOf(NullPointerException.class) + .hasMessage("provisioner cannot be null"); } @Test diff --git a/testlib/src/test/java/com/diffplug/spotless/json/JsonSimpleStepTest.java b/testlib/src/test/java/com/diffplug/spotless/json/JsonSimpleStepTest.java index a8b166fa21..b4f98e69ba 100644 --- a/testlib/src/test/java/com/diffplug/spotless/json/JsonSimpleStepTest.java +++ b/testlib/src/test/java/com/diffplug/spotless/json/JsonSimpleStepTest.java @@ -1,5 +1,5 @@ /* - * Copyright 2021 DiffPlug + * Copyright 2021-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,10 +17,10 @@ import static org.assertj.core.api.Assertions.assertThatThrownBy; -import com.diffplug.spotless.*; - import org.junit.jupiter.api.Test; +import com.diffplug.spotless.*; + class JsonSimpleStepTest extends JsonFormatterStepCommonTests { @Test @@ -46,17 +46,17 @@ void handlesObjectWithNull() throws Exception { @Test void handlesInvalidJson() { assertThatThrownBy(() -> doWithResource("invalidJson")) - .isInstanceOf(AssertionError.class) - .hasMessage("Unable to format JSON") - .hasRootCauseMessage("Expected a ',' or '}' at 9 [character 0 line 3]"); + .isInstanceOf(AssertionError.class) + .hasMessage("Unable to format JSON") + .hasRootCauseMessage("Expected a ',' or '}' at 9 [character 0 line 3]"); } @Test void handlesNotJson() { assertThatThrownBy(() -> doWithResource("notJson")) - .isInstanceOf(AssertionError.class) - .hasMessage("Unable to determine JSON type, expected a '{' or '[' but found '#'") - .hasNoCause(); + .isInstanceOf(AssertionError.class) + .hasMessage("Unable to determine JSON type, expected a '{' or '[' but found '#'") + .hasNoCause(); } @Override From baeed60bb788fa30c8ba4a7fd868fa963345fd61 Mon Sep 17 00:00:00 2001 From: Abel Keszei Date: Sat, 12 Feb 2022 19:40:45 +0100 Subject: [PATCH 020/757] add json steps to feature matrix --- README.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/README.md b/README.md index 6ace09631d..733979b1a1 100644 --- a/README.md +++ b/README.md @@ -102,6 +102,8 @@ extra('wtp.EclipseWtpFormatterStep') +'{{yes}} | {{yes}} | [`java.PalantirJavaFormatStep`](lib/src/main/java/com/diffplug/spotless/java/PalantirJavaFormatStep.java) | :+1: | :+1: | :white_large_square: | :white_large_square: | | [`java.RemoveUnusedImportsStep`](lib/src/main/java/com/diffplug/spotless/java/RemoveUnusedImportsStep.java) | :+1: | :+1: | :+1: | :white_large_square: | | [`java.EclipseJdtFormatterStep`](lib-extra/src/main/java/com/diffplug/spotless/extra/java/EclipseJdtFormatterStep.java) | :+1: | :+1: | :+1: | :white_large_square: | +| [`json.JsonSimpleStep`](lib/src/main/java/com/diffplug/spotless/json/JsonSimpleStep.java) | :+1: | :white_large_square: | :white_large_square: | :white_large_square: | +| [`json.GsonStep`](lib/src/main/java/com/diffplug/spotless/json/gson/GsonStep.java) | :+1: | :white_large_square: | :white_large_square: | :white_large_square: | | [`kotlin.KtLintStep`](lib/src/main/java/com/diffplug/spotless/kotlin/KtLintStep.java) | :+1: | :+1: | :+1: | :white_large_square: | | [`kotlin.KtfmtStep`](lib/src/main/java/com/diffplug/spotless/kotlin/KtfmtStep.java) | :+1: | :+1: | :white_large_square: | :white_large_square: | | [`kotlin.DiktatStep`](lib/src/main/java/com/diffplug/spotless/kotlin/DiktatStep.java) | :+1: | :+1: | :white_large_square: | :white_large_square: | From 14f4e46992898567b8c94d44406acd016721feb0 Mon Sep 17 00:00:00 2001 From: Abel Keszei Date: Sat, 12 Feb 2022 20:16:11 +0100 Subject: [PATCH 021/757] correctly add json steps to readme --- README.md | 6 ++++-- .../com/diffplug/spotless/json/{gson => }/GsonStep.java | 3 ++- .../java/com/diffplug/gradle/spotless/JsonExtension.java | 2 +- .../test/java/com/diffplug/spotless/json/GsonStepTest.java | 1 - 4 files changed, 7 insertions(+), 5 deletions(-) rename lib/src/main/java/com/diffplug/spotless/json/{gson => }/GsonStep.java (98%) diff --git a/README.md b/README.md index 733979b1a1..bf4e7cf0d1 100644 --- a/README.md +++ b/README.md @@ -61,6 +61,8 @@ lib('java.ImportOrderStep') +'{{yes}} | {{yes}} lib('java.PalantirJavaFormatStep') +'{{yes}} | {{yes}} | {{no}} | {{no}} |', lib('java.RemoveUnusedImportsStep') +'{{yes}} | {{yes}} | {{yes}} | {{no}} |', extra('java.EclipseJdtFormatterStep') +'{{yes}} | {{yes}} | {{yes}} | {{no}} |', +lib('json.GsonStep') +'{{yes}} | {{no}} | {{no}} | {{no}} |', +lib('json.JsonSimpleStep') +'{{yes}} | {{no}} | {{no}} | {{no}} |', lib('kotlin.KtLintStep') +'{{yes}} | {{yes}} | {{yes}} | {{no}} |', lib('kotlin.KtfmtStep') +'{{yes}} | {{yes}} | {{no}} | {{no}} |', lib('kotlin.DiktatStep') +'{{yes}} | {{yes}} | {{no}} | {{no}} |', @@ -102,8 +104,8 @@ extra('wtp.EclipseWtpFormatterStep') +'{{yes}} | {{yes}} | [`java.PalantirJavaFormatStep`](lib/src/main/java/com/diffplug/spotless/java/PalantirJavaFormatStep.java) | :+1: | :+1: | :white_large_square: | :white_large_square: | | [`java.RemoveUnusedImportsStep`](lib/src/main/java/com/diffplug/spotless/java/RemoveUnusedImportsStep.java) | :+1: | :+1: | :+1: | :white_large_square: | | [`java.EclipseJdtFormatterStep`](lib-extra/src/main/java/com/diffplug/spotless/extra/java/EclipseJdtFormatterStep.java) | :+1: | :+1: | :+1: | :white_large_square: | -| [`json.JsonSimpleStep`](lib/src/main/java/com/diffplug/spotless/json/JsonSimpleStep.java) | :+1: | :white_large_square: | :white_large_square: | :white_large_square: | -| [`json.GsonStep`](lib/src/main/java/com/diffplug/spotless/json/gson/GsonStep.java) | :+1: | :white_large_square: | :white_large_square: | :white_large_square: | +| [`json.GsonStep`](lib/src/main/java/com/diffplug/spotless/json/GsonStep.java) | :+1: | :white_large_square: | :white_large_square: | :white_large_square: | +| [`json.JsonSimpleStep`](lib/src/main/java/com/diffplug/spotless/json/JsonSimpleStep.java) | :+1: | :white_large_square: | :white_large_square: | :white_large_square: | | [`kotlin.KtLintStep`](lib/src/main/java/com/diffplug/spotless/kotlin/KtLintStep.java) | :+1: | :+1: | :+1: | :white_large_square: | | [`kotlin.KtfmtStep`](lib/src/main/java/com/diffplug/spotless/kotlin/KtfmtStep.java) | :+1: | :+1: | :white_large_square: | :white_large_square: | | [`kotlin.DiktatStep`](lib/src/main/java/com/diffplug/spotless/kotlin/DiktatStep.java) | :+1: | :+1: | :white_large_square: | :white_large_square: | diff --git a/lib/src/main/java/com/diffplug/spotless/json/gson/GsonStep.java b/lib/src/main/java/com/diffplug/spotless/json/GsonStep.java similarity index 98% rename from lib/src/main/java/com/diffplug/spotless/json/gson/GsonStep.java rename to lib/src/main/java/com/diffplug/spotless/json/GsonStep.java index 06519ae39d..81d6ee2f34 100644 --- a/lib/src/main/java/com/diffplug/spotless/json/gson/GsonStep.java +++ b/lib/src/main/java/com/diffplug/spotless/json/GsonStep.java @@ -13,7 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package com.diffplug.spotless.json.gson; +package com.diffplug.spotless.json; import java.io.IOException; import java.io.Serializable; @@ -25,6 +25,7 @@ import com.diffplug.spotless.FormatterStep; import com.diffplug.spotless.JarState; import com.diffplug.spotless.Provisioner; +import com.diffplug.spotless.json.gson.*; public class GsonStep { private static final String MAVEN_COORDINATES = "com.google.code.gson:gson"; diff --git a/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/JsonExtension.java b/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/JsonExtension.java index 25182fa4bc..0c4ea3442a 100644 --- a/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/JsonExtension.java +++ b/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/JsonExtension.java @@ -18,8 +18,8 @@ import javax.inject.Inject; import com.diffplug.spotless.FormatterStep; +import com.diffplug.spotless.json.GsonStep; import com.diffplug.spotless.json.JsonSimpleStep; -import com.diffplug.spotless.json.gson.GsonStep; public class JsonExtension extends FormatExtension { private static final int DEFAULT_INDENTATION = 4; diff --git a/testlib/src/test/java/com/diffplug/spotless/json/GsonStepTest.java b/testlib/src/test/java/com/diffplug/spotless/json/GsonStepTest.java index a9fdc5383c..822d041aae 100644 --- a/testlib/src/test/java/com/diffplug/spotless/json/GsonStepTest.java +++ b/testlib/src/test/java/com/diffplug/spotless/json/GsonStepTest.java @@ -23,7 +23,6 @@ import com.diffplug.spotless.Provisioner; import com.diffplug.spotless.StepHarness; import com.diffplug.spotless.TestProvisioner; -import com.diffplug.spotless.json.gson.GsonStep; public class GsonStepTest extends JsonFormatterStepCommonTests { From bd73171360e592628a706a93188d5921f7a4db4d Mon Sep 17 00:00:00 2001 From: Abel Keszei Date: Sun, 13 Feb 2022 13:36:31 +0100 Subject: [PATCH 022/757] updates CHANGES.md --- CHANGES.md | 2 ++ plugin-gradle/CHANGES.md | 2 ++ 2 files changed, 4 insertions(+) diff --git a/CHANGES.md b/CHANGES.md index 29fd6d9375..e6420824d9 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -10,6 +10,8 @@ This document is intended for Spotless developers. We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format (starting after version `1.27.0`). ## [Unreleased] +### Added +* Added support for JSON formatting based on [Gson](https://github.com/google/gson) ## [2.22.2] - 2022-02-09 ### Changed diff --git a/plugin-gradle/CHANGES.md b/plugin-gradle/CHANGES.md index 6c2a6cd4da..52b2b057e3 100644 --- a/plugin-gradle/CHANGES.md +++ b/plugin-gradle/CHANGES.md @@ -3,6 +3,8 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format (starting after version `3.27.0`). ## [Unreleased] +### Added +* Added support for JSON formatting based on [Gson](https://github.com/google/gson) ## [6.2.2] - 2022-02-09 ### Changed From c8aa57883efd6bfbd177f5ecb7ea39bf5a1f6096 Mon Sep 17 00:00:00 2001 From: Abel Keszei Date: Sun, 13 Feb 2022 13:37:55 +0100 Subject: [PATCH 023/757] add PR links to CHANGES.md changes --- CHANGES.md | 2 +- plugin-gradle/CHANGES.md | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/CHANGES.md b/CHANGES.md index e6420824d9..364fb31beb 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -11,7 +11,7 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format ( ## [Unreleased] ### Added -* Added support for JSON formatting based on [Gson](https://github.com/google/gson) +* Added support for JSON formatting based on [Gson](https://github.com/google/gson) ([#1125](https://github.com/diffplug/spotless/pull/1125)). ## [2.22.2] - 2022-02-09 ### Changed diff --git a/plugin-gradle/CHANGES.md b/plugin-gradle/CHANGES.md index 52b2b057e3..096a40e09a 100644 --- a/plugin-gradle/CHANGES.md +++ b/plugin-gradle/CHANGES.md @@ -4,7 +4,7 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format ( ## [Unreleased] ### Added -* Added support for JSON formatting based on [Gson](https://github.com/google/gson) +* Added support for JSON formatting based on [Gson](https://github.com/google/gson) ([#1125](https://github.com/diffplug/spotless/pull/1125)). ## [6.2.2] - 2022-02-09 ### Changed From 83091071dd55d5f887679e09170e5489425690e7 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 14 Feb 2022 12:05:37 +0000 Subject: [PATCH 024/757] Bump com.diffplug.spotless from 6.2.0 to 6.2.2 Bumps com.diffplug.spotless from 6.2.0 to 6.2.2. --- updated-dependencies: - dependency-name: com.diffplug.spotless dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] --- settings.gradle | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/settings.gradle b/settings.gradle index ca29a527e2..570d9c3d1e 100644 --- a/settings.gradle +++ b/settings.gradle @@ -1,6 +1,6 @@ pluginManagement { plugins { - id 'com.diffplug.spotless' version '6.2.0' + id 'com.diffplug.spotless' version '6.2.2' // https://plugins.gradle.org/plugin/com.gradle.plugin-publish id 'com.gradle.plugin-publish' version '0.20.0' // https://github.com/gradle-nexus/publish-plugin/releases From 4834e22e9ae05ad3da2973675811346be9976a8e Mon Sep 17 00:00:00 2001 From: Ned Twigg Date: Mon, 14 Feb 2022 12:20:42 -0800 Subject: [PATCH 025/757] Advertise the compile-only sourceset feature. --- CONTRIBUTING.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 94bef92f01..f03c500f83 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -99,6 +99,10 @@ Here's a checklist for creating a new step for Spotless: - [ ] Test class has test methods to verify behavior. - [ ] Test class has a test method `equality()` which tests equality using `StepEqualityTester` (see existing methods for examples). +### Third-party dependencies via reflection or compile-only source sets + +Most formatters are going to use some kind of third-party jar. Spotless integrates with many formatters, some of which have incompatible transitive dependencies. To address this, we resolve third-party dependencies using [`JarState`](https://github.com/diffplug/spotless/blob/b26f0972b185995d7c6a7aefa726c146d24d9a82/lib/src/main/java/com/diffplug/spotless/kotlin/KtfmtStep.java#L118). To call methods on the classes in that `JarState`, you can either use reflection or a compile-only source set. See [#524](https://github.com/diffplug/spotless/issues/524) for examples of both approaches. + ### Accessing the underlying File In order for Spotless' model to work, each step needs to look only at the `String` input, otherwise they cannot compose. However, there are some cases where the source `File` is useful, such as to look at the file extension. In this case, you can pass a `FormatterFunc.NeedsFile` instead of a `FormatterFunc`. This should only be used in [rare circumstances](https://github.com/diffplug/spotless/pull/637), be careful that you don't accidentally depend on the bytes inside of the `File`! From 9b1955b555cbdc63a3fc9306a26f62c2e4da997c Mon Sep 17 00:00:00 2001 From: Ned Twigg Date: Mon, 14 Feb 2022 12:28:59 -0800 Subject: [PATCH 026/757] Add missing bullet points. --- CONTRIBUTING.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index f03c500f83..c1ce74bd8f 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -103,6 +103,9 @@ Here's a checklist for creating a new step for Spotless: Most formatters are going to use some kind of third-party jar. Spotless integrates with many formatters, some of which have incompatible transitive dependencies. To address this, we resolve third-party dependencies using [`JarState`](https://github.com/diffplug/spotless/blob/b26f0972b185995d7c6a7aefa726c146d24d9a82/lib/src/main/java/com/diffplug/spotless/kotlin/KtfmtStep.java#L118). To call methods on the classes in that `JarState`, you can either use reflection or a compile-only source set. See [#524](https://github.com/diffplug/spotless/issues/524) for examples of both approaches. +- Adding a compile-only sourceset is easier to read and probably a better approach for most cases. +- Reflection is more flexible, and might be a better approach for a very simple API. + ### Accessing the underlying File In order for Spotless' model to work, each step needs to look only at the `String` input, otherwise they cannot compose. However, there are some cases where the source `File` is useful, such as to look at the file extension. In this case, you can pass a `FormatterFunc.NeedsFile` instead of a `FormatterFunc`. This should only be used in [rare circumstances](https://github.com/diffplug/spotless/pull/637), be careful that you don't accidentally depend on the bytes inside of the `File`! From e6a31deadf0997c80e7a73a1b44ed562f2dcfdb7 Mon Sep 17 00:00:00 2001 From: Abel Keszei Date: Mon, 14 Feb 2022 23:04:36 +0100 Subject: [PATCH 027/757] make classes of com.diffplug.spotless.json.gson package-private --- README.md | 8 ++++---- .../spotless/json/gson/GsonBuilderWrapper.java | 12 ++++++------ .../spotless/json/{ => gson}/GsonStep.java | 3 +-- .../diffplug/spotless/json/gson/GsonWrapper.java | 15 ++++----------- .../spotless/json/gson/GsonWrapperBase.java | 6 +++--- .../spotless/json/gson/JsonElementWrapper.java | 8 ++++---- .../spotless/json/gson/JsonObjectWrapper.java | 12 ++++++------ .../spotless/json/gson/JsonWriterWrapper.java | 10 +++++----- .../diffplug/gradle/spotless/JsonExtension.java | 2 +- .../spotless/json/{ => gson}/GsonStepTest.java | 4 +++- 10 files changed, 37 insertions(+), 43 deletions(-) rename lib/src/main/java/com/diffplug/spotless/json/{ => gson}/GsonStep.java (98%) rename testlib/src/test/java/com/diffplug/spotless/json/{ => gson}/GsonStepTest.java (97%) diff --git a/README.md b/README.md index bf4e7cf0d1..f95ea7a7ca 100644 --- a/README.md +++ b/README.md @@ -30,8 +30,8 @@ It's easy to build such a function, but there are some gotchas and lots of integ ## Current feature matrix [![Gradle plugin](https://img.shields.io/badge/plugins.gradle.org-com.diffplug.spotless-blue.svg)](https://plugins.gradle.org/plugin/com.diffplug.spotless) [![Maven central](https://img.shields.io/badge/mavencentral-yes-blue.svg)](https://search.maven.org/#search%7Cgav%7C1%7Cg%3A%22com.diffplug.spotless%22%20AND%20a%3A%22spotless-plugin-gradle%22) -[![Javadoc](https://img.shields.io/badge/javadoc-yes-blue.svg)](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.2.2/index.html) +[![Javadoc](https://img.shields.io/badge/javadoc-yes-blue.svg)](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.3.0/index.html) [![License Apache](https://img.shields.io/badge/license-apache-blue.svg)](https://tldrlegal.com/license/apache-license-2.0-(apache-2.0)) -[![Changelog](https://img.shields.io/badge/changelog-6.2.2-blue.svg)](CHANGES.md) +[![Changelog](https://img.shields.io/badge/changelog-6.3.0-blue.svg)](CHANGES.md) [![Circle CI](https://circleci.com/gh/diffplug/spotless/tree/main.svg?style=shield)](https://circleci.com/gh/diffplug/spotless/tree/main) [![Live chat](https://img.shields.io/badge/gitter-chat-brightgreen.svg)](https://gitter.im/diffplug/spotless) @@ -126,10 +126,10 @@ spotless { ``` Spotless consists of a list of formats (in the example above, `misc` and `java`), and each format has: -- a `target` (the files to format), which you set with [`target`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.2.2/com/diffplug/gradle/spotless/FormatExtension.html#target-java.lang.Object...-) and [`targetExclude`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.2.2/com/diffplug/gradle/spotless/FormatExtension.html#targetExclude-java.lang.Object...-) -- a list of `FormatterStep`, which are just `String -> String` functions, such as [`replace`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.2.2/com/diffplug/gradle/spotless/FormatExtension.html#replace-java.lang.String-java.lang.CharSequence-java.lang.CharSequence-), [`replaceRegex`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.2.2/com/diffplug/gradle/spotless/FormatExtension.html#replaceRegex-java.lang.String-java.lang.String-java.lang.String-), [`trimTrailingWhitespace`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.2.2/com/diffplug/gradle/spotless/FormatExtension.html#replace-java.lang.String-java.lang.CharSequence-java.lang.CharSequence-), [`custom`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.2.2/com/diffplug/gradle/spotless/FormatExtension.html#custom-java.lang.String-groovy.lang.Closure-), [`prettier`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.2.2/com/diffplug/gradle/spotless/FormatExtension.html#prettier--), [`eclipseWtp`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.2.2/com/diffplug/gradle/spotless/FormatExtension.html#eclipseWtp-com.diffplug.spotless.extra.wtp.EclipseWtpFormatterStep-), [`licenseHeader`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.2.2/com/diffplug/gradle/spotless/FormatExtension.html#licenseHeader-java.lang.String-java.lang.String-) etc. +- a `target` (the files to format), which you set with [`target`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.3.0/com/diffplug/gradle/spotless/FormatExtension.html#target-java.lang.Object...-) and [`targetExclude`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.3.0/com/diffplug/gradle/spotless/FormatExtension.html#targetExclude-java.lang.Object...-) +- a list of `FormatterStep`, which are just `String -> String` functions, such as [`replace`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.3.0/com/diffplug/gradle/spotless/FormatExtension.html#replace-java.lang.String-java.lang.CharSequence-java.lang.CharSequence-), [`replaceRegex`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.3.0/com/diffplug/gradle/spotless/FormatExtension.html#replaceRegex-java.lang.String-java.lang.String-java.lang.String-), [`trimTrailingWhitespace`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.3.0/com/diffplug/gradle/spotless/FormatExtension.html#replace-java.lang.String-java.lang.CharSequence-java.lang.CharSequence-), [`custom`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.3.0/com/diffplug/gradle/spotless/FormatExtension.html#custom-java.lang.String-groovy.lang.Closure-), [`prettier`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.3.0/com/diffplug/gradle/spotless/FormatExtension.html#prettier--), [`eclipseWtp`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.3.0/com/diffplug/gradle/spotless/FormatExtension.html#eclipseWtp-com.diffplug.spotless.extra.wtp.EclipseWtpFormatterStep-), [`licenseHeader`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.3.0/com/diffplug/gradle/spotless/FormatExtension.html#licenseHeader-java.lang.String-java.lang.String-) etc. -All the generic steps live in [`FormatExtension`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.2.2/com/diffplug/gradle/spotless/FormatExtension.html), and there are many language-specific steps which live in its language-specific subclasses, which are described below. +All the generic steps live in [`FormatExtension`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.3.0/com/diffplug/gradle/spotless/FormatExtension.html), and there are many language-specific steps which live in its language-specific subclasses, which are described below. ### Requirements @@ -141,7 +141,7 @@ If you're stuck on an older version of Gradle, `id 'com.diffplug.gradle.spotless ## Java -`com.diffplug.gradle.spotless.JavaExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.2.2/com/diffplug/gradle/spotless/JavaExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/JavaExtension.java) +`com.diffplug.gradle.spotless.JavaExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.3.0/com/diffplug/gradle/spotless/JavaExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/JavaExtension.java) ```gradle spotless { @@ -248,8 +248,8 @@ spotless { ## Groovy -- `com.diffplug.gradle.spotless.GroovyExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.2.2/com/diffplug/gradle/spotless/GroovyExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/GroovyExtension.java) -- `com.diffplug.gradle.spotless.GroovyGradleExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.2.2/com/diffplug/gradle/spotless/GroovyGradleExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/GroovyGradleExtension.java) +- `com.diffplug.gradle.spotless.GroovyExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.3.0/com/diffplug/gradle/spotless/GroovyExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/GroovyExtension.java) +- `com.diffplug.gradle.spotless.GroovyGradleExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.3.0/com/diffplug/gradle/spotless/GroovyGradleExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/GroovyGradleExtension.java) Configuration for Groovy is similar to [Java](#java), in that it also supports `licenseHeader` and `importOrder`. @@ -300,8 +300,8 @@ Groovy-Eclipse formatting errors/warnings lead per default to a build failure. T ## Kotlin -- `com.diffplug.gradle.spotless.KotlinExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.2.2/com/diffplug/gradle/spotless/KotlinExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/KotlinExtension.java) -- `com.diffplug.gradle.spotless.KotlinGradleExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.2.2/com/diffplug/gradle/spotless/KotlinGradleExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/KotlinGradleExtension.java) +- `com.diffplug.gradle.spotless.KotlinExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.3.0/com/diffplug/gradle/spotless/KotlinExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/KotlinExtension.java) +- `com.diffplug.gradle.spotless.KotlinGradleExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.3.0/com/diffplug/gradle/spotless/KotlinGradleExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/KotlinGradleExtension.java) ```gradle spotless { // if you are using build.gradle.kts, instead of 'spotless {' use: @@ -359,7 +359,7 @@ spotless { ## Scala -`com.diffplug.gradle.spotless.ScalaExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.2.2/com/diffplug/gradle/spotless/ScalaExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/ScalaExtension.java) +`com.diffplug.gradle.spotless.ScalaExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.3.0/com/diffplug/gradle/spotless/ScalaExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/ScalaExtension.java) ```gradle spotless { @@ -391,7 +391,7 @@ spotless { ## C/C++ -`com.diffplug.gradle.spotless.CppExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.2.2/com/diffplug/gradle/spotless/CppExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/CppExtension.java) +`com.diffplug.gradle.spotless.CppExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.3.0/com/diffplug/gradle/spotless/CppExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/CppExtension.java) ```gradle spotless { @@ -423,7 +423,7 @@ spotles { ## Python -`com.diffplug.gradle.spotless.PythonExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.2.2/com/diffplug/gradle/spotless/PythonExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/PythonExtension.java) +`com.diffplug.gradle.spotless.PythonExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.3.0/com/diffplug/gradle/spotless/PythonExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/PythonExtension.java) ```gradle spotless { @@ -457,7 +457,7 @@ black().pathToExe('C:/myuser/.pyenv/versions/3.8.0/scripts/black.exe') ## FreshMark -`com.diffplug.gradle.spotless.FreshMarkExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.2.2/com/diffplug/gradle/spotless/FreshMarkExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/FreshMarkExtension.java) +`com.diffplug.gradle.spotless.FreshMarkExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.3.0/com/diffplug/gradle/spotless/FreshMarkExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/FreshMarkExtension.java) [homepage](https://github.com/diffplug/freshmark). [changelog](https://github.com/diffplug/freshmark/blob/master/CHANGES.md). FreshMark lets you generate markdown in the comments of your markdown. This helps to keep badges and links up-to-date (see the source for this file), and can also be helpful for generating complex tables (see the source for [the parent readme](../README.md)). @@ -478,7 +478,7 @@ spotless { ## Antlr4 -`com.diffplug.gradle.spotless.Antlr4Extension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.2.2/com/diffplug/gradle/spotless/Antlr4Extension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/Antlr4Extension.java) +`com.diffplug.gradle.spotless.Antlr4Extension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.3.0/com/diffplug/gradle/spotless/Antlr4Extension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/Antlr4Extension.java) ```gradle spotless { @@ -503,7 +503,7 @@ antlr4formatter('1.2.1') // version is optional ## SQL -`com.diffplug.gradle.spotless.SqlExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.2.2/com/diffplug/gradle/spotless/SqlExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/SqlExtension.java) +`com.diffplug.gradle.spotless.SqlExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.3.0/com/diffplug/gradle/spotless/SqlExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/SqlExtension.java) ```gradle spotless { @@ -543,7 +543,7 @@ sql.formatter.indent.size=4 ## Typescript -- `com.diffplug.gradle.spotless.TypescriptExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.2.2/com/diffplug/gradle/spotless/TypescriptExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/TypescriptExtension.java) +- `com.diffplug.gradle.spotless.TypescriptExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.3.0/com/diffplug/gradle/spotless/TypescriptExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/TypescriptExtension.java) ```gradle spotless { @@ -586,7 +586,7 @@ For details, see the [npm detection](#npm-detection) and [`.npmrc` detection](#n ## JSON -- `com.diffplug.gradle.spotless.JsonExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.2.2/com/diffplug/gradle/spotless/JsonExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/JsonExtension.java) +- `com.diffplug.gradle.spotless.JsonExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.3.0/com/diffplug/gradle/spotless/JsonExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/JsonExtension.java) ```gradle spotless { @@ -811,7 +811,7 @@ Once a file's license header has a valid year, whether it is a year (`2020`) or * `2017` -> `2017-2020` * `2017-2019` -> `2017-2020` -See the [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.2.2/com/diffplug/gradle/spotless/FormatExtension.LicenseHeaderConfig.html) for a complete listing of options. +See the [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.3.0/com/diffplug/gradle/spotless/FormatExtension.LicenseHeaderConfig.html) for a complete listing of options. @@ -878,9 +878,9 @@ spotless { custom 'lowercase', { str -> str.toLowerCase() } ``` -However, custom rules will disable up-to-date checking and caching, unless you read [this javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.2.2/com/diffplug/gradle/spotless/FormatExtension.html#bumpThisNumberIfACustomStepChanges-int-) and follow its instructions carefully. +However, custom rules will disable up-to-date checking and caching, unless you read [this javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.3.0/com/diffplug/gradle/spotless/FormatExtension.html#bumpThisNumberIfACustomStepChanges-int-) and follow its instructions carefully. -Another option is to create proper `FormatterStep` in your `buildSrc`, and then call [`addStep`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.2.2/com/diffplug/gradle/spotless/FormatExtension.html#addStep-com.diffplug.spotless.FormatterStep-). The contributing guide describes [how to do this](https://github.com/diffplug/spotless/blob/main/CONTRIBUTING.md#how-to-add-a-new-formatterstep). If the step is generally-useful, we hope you'll open a PR to share it! +Another option is to create proper `FormatterStep` in your `buildSrc`, and then call [`addStep`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.3.0/com/diffplug/gradle/spotless/FormatExtension.html#addStep-com.diffplug.spotless.FormatterStep-). The contributing guide describes [how to do this](https://github.com/diffplug/spotless/blob/main/CONTRIBUTING.md#how-to-add-a-new-formatterstep). If the step is generally-useful, we hope you'll open a PR to share it! ```gradle @@ -913,11 +913,11 @@ spotless { format 'foo', com.acme.FooLanguageExtension, { ``` -If you'd like to create a one-off Spotless task outside of the `check`/`apply` framework, see [`FormatExtension.createIndependentApplyTask`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.2.2/com/diffplug/gradle/spotless/FormatExtension.html#createIndependentApplyTask-java.lang.String-). +If you'd like to create a one-off Spotless task outside of the `check`/`apply` framework, see [`FormatExtension.createIndependentApplyTask`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.3.0/com/diffplug/gradle/spotless/FormatExtension.html#createIndependentApplyTask-java.lang.String-). ## Inception (languages within languages within...) -In very rare cases, you might want to format e.g. javascript which is written inside JSP templates, or maybe java within a markdown file, or something wacky like that. You can specify hunks within a file using either open/close tags or a regex with a single capturing group, and then specify rules within it, like so. See [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.2.2/com/diffplug/gradle/spotless/FormatExtension.html#withinBlocks-java.lang.String-java.lang.String-java.lang.String-org.gradle.api.Action-) for more details. +In very rare cases, you might want to format e.g. javascript which is written inside JSP templates, or maybe java within a markdown file, or something wacky like that. You can specify hunks within a file using either open/close tags or a regex with a single capturing group, and then specify rules within it, like so. See [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.3.0/com/diffplug/gradle/spotless/FormatExtension.html#withinBlocks-java.lang.String-java.lang.String-java.lang.String-org.gradle.api.Action-) for more details. ```gradle import com.diffplug.gradle.spotless.JavaExtension From 62e2b782a14676ec43647b0726f821da061e10dd Mon Sep 17 00:00:00 2001 From: Jan DHollander Date: Thu, 17 Feb 2022 13:02:11 +0100 Subject: [PATCH 037/757] #1132 - Add magic value to disable ratchetFrom --- .../spotless/maven/AbstractSpotlessMojo.java | 12 +++++++++--- .../spotless/maven/FormatterFactory.java | 19 ++++++++++++++++--- 2 files changed, 25 insertions(+), 6 deletions(-) diff --git a/plugin-maven/src/main/java/com/diffplug/spotless/maven/AbstractSpotlessMojo.java b/plugin-maven/src/main/java/com/diffplug/spotless/maven/AbstractSpotlessMojo.java index 1b5abe9f0c..274b225114 100644 --- a/plugin-maven/src/main/java/com/diffplug/spotless/maven/AbstractSpotlessMojo.java +++ b/plugin-maven/src/main/java/com/diffplug/spotless/maven/AbstractSpotlessMojo.java @@ -15,8 +15,6 @@ */ package com.diffplug.spotless.maven; -import static java.util.stream.Collectors.toList; - import java.io.File; import java.io.IOException; import java.nio.file.Path; @@ -71,10 +69,16 @@ import com.diffplug.spotless.maven.sql.Sql; import com.diffplug.spotless.maven.typescript.Typescript; +import static java.util.stream.Collectors.toList; + public abstract class AbstractSpotlessMojo extends AbstractMojo { private static final String DEFAULT_INDEX_FILE_NAME = "spotless-index"; private static final String DEFAULT_ENCODING = "UTF-8"; private static final String DEFAULT_LINE_ENDINGS = "GIT_ATTRIBUTES"; + + /** Value to allow unsetting the ratchet inherited from parent pom configuration. */ + static final String RATCHETFROM_NONE = "NONE"; + static final String GOAL_CHECK = "check"; static final String GOAL_APPLY = "apply"; @@ -302,7 +306,9 @@ private FormatterConfig getFormatterConfig() { Provisioner provisioner = MavenProvisioner.create(resolver); List formatterStepFactories = getFormatterStepFactories(); FileLocator fileLocator = getFileLocator(); - return new FormatterConfig(baseDir, encoding, lineEndings, Optional.ofNullable(ratchetFrom), provisioner, fileLocator, formatterStepFactories, Optional.ofNullable(setLicenseHeaderYearsFromGitHistory)); + final Optional optionalRatchetFrom = Optional.ofNullable(this.ratchetFrom) + .filter(ratchet -> !RATCHETFROM_NONE.equals(ratchet)); + return new FormatterConfig(baseDir, encoding, lineEndings, optionalRatchetFrom, provisioner, fileLocator, formatterStepFactories, Optional.ofNullable(setLicenseHeaderYearsFromGitHistory)); } private FileLocator getFileLocator() { diff --git a/plugin-maven/src/main/java/com/diffplug/spotless/maven/FormatterFactory.java b/plugin-maven/src/main/java/com/diffplug/spotless/maven/FormatterFactory.java index c06822486c..8e08c3903b 100644 --- a/plugin-maven/src/main/java/com/diffplug/spotless/maven/FormatterFactory.java +++ b/plugin-maven/src/main/java/com/diffplug/spotless/maven/FormatterFactory.java @@ -15,8 +15,6 @@ */ package com.diffplug.spotless.maven; -import static java.util.Collections.emptySet; - import java.io.File; import java.nio.charset.Charset; import java.util.ArrayList; @@ -35,7 +33,20 @@ import com.diffplug.spotless.FormatterStep; import com.diffplug.spotless.LineEnding; import com.diffplug.spotless.generic.PipeStepPair; -import com.diffplug.spotless.maven.generic.*; +import com.diffplug.spotless.maven.generic.EclipseWtp; +import com.diffplug.spotless.maven.generic.EndWithNewline; +import com.diffplug.spotless.maven.generic.Indent; +import com.diffplug.spotless.maven.generic.Jsr223; +import com.diffplug.spotless.maven.generic.LicenseHeader; +import com.diffplug.spotless.maven.generic.NativeCmd; +import com.diffplug.spotless.maven.generic.Prettier; +import com.diffplug.spotless.maven.generic.Replace; +import com.diffplug.spotless.maven.generic.ReplaceRegex; +import com.diffplug.spotless.maven.generic.ToggleOffOn; +import com.diffplug.spotless.maven.generic.TrimTrailingWhitespace; + +import static com.diffplug.spotless.maven.AbstractSpotlessMojo.RATCHETFROM_NONE; +import static java.util.Collections.emptySet; public abstract class FormatterFactory { @Parameter @@ -159,6 +170,8 @@ private LineEnding lineEndings(FormatterConfig config) { Optional ratchetFrom(FormatterConfig config) { if (RATCHETFROM_NOT_SET_AT_FORMAT_LEVEL.equals(ratchetFrom)) { return config.getRatchetFrom(); + } else if (RATCHETFROM_NONE.equals(ratchetFrom)) { + return Optional.empty(); } else { return Optional.ofNullable(ratchetFrom); } From edbad155dd4e0d8da6cd1bc5a21969c020a3462e Mon Sep 17 00:00:00 2001 From: Jan DHollander Date: Fri, 18 Feb 2022 09:07:57 +0100 Subject: [PATCH 038/757] Add info to readme and execute spotlessApply --- plugin-maven/README.md | 8 ++++++++ .../com/diffplug/spotless/maven/AbstractSpotlessMojo.java | 6 +++--- .../com/diffplug/spotless/maven/FormatterFactory.java | 8 ++++---- 3 files changed, 15 insertions(+), 7 deletions(-) diff --git a/plugin-maven/README.md b/plugin-maven/README.md index 01688eb9b7..024b1107fe 100644 --- a/plugin-maven/README.md +++ b/plugin-maven/README.md @@ -999,6 +999,14 @@ However, we strongly recommend that you use a non-local branch, such as a tag or This is especially helpful for injecting accurate copyright dates using the [license step](#license-header). +You can explicitly disable ratchet functionality by providing the value 'NONE': +```xml + + NONE + +``` +This is useful for disabling the ratchet functionality in child projects where the parent defines a ratchetFrom value. + ## `spotless:off` and `spotless:on` Sometimes there is a chunk of code which you have carefully handcrafted, and you would like to exclude just this one little part from getting clobbered by the autoformat. Some formatters have a way to do this, many don't, but who cares. If you setup your spotless like this: diff --git a/plugin-maven/src/main/java/com/diffplug/spotless/maven/AbstractSpotlessMojo.java b/plugin-maven/src/main/java/com/diffplug/spotless/maven/AbstractSpotlessMojo.java index 274b225114..c68733f387 100644 --- a/plugin-maven/src/main/java/com/diffplug/spotless/maven/AbstractSpotlessMojo.java +++ b/plugin-maven/src/main/java/com/diffplug/spotless/maven/AbstractSpotlessMojo.java @@ -15,6 +15,8 @@ */ package com.diffplug.spotless.maven; +import static java.util.stream.Collectors.toList; + import java.io.File; import java.io.IOException; import java.nio.file.Path; @@ -69,8 +71,6 @@ import com.diffplug.spotless.maven.sql.Sql; import com.diffplug.spotless.maven.typescript.Typescript; -import static java.util.stream.Collectors.toList; - public abstract class AbstractSpotlessMojo extends AbstractMojo { private static final String DEFAULT_INDEX_FILE_NAME = "spotless-index"; private static final String DEFAULT_ENCODING = "UTF-8"; @@ -307,7 +307,7 @@ private FormatterConfig getFormatterConfig() { List formatterStepFactories = getFormatterStepFactories(); FileLocator fileLocator = getFileLocator(); final Optional optionalRatchetFrom = Optional.ofNullable(this.ratchetFrom) - .filter(ratchet -> !RATCHETFROM_NONE.equals(ratchet)); + .filter(ratchet -> !RATCHETFROM_NONE.equals(ratchet)); return new FormatterConfig(baseDir, encoding, lineEndings, optionalRatchetFrom, provisioner, fileLocator, formatterStepFactories, Optional.ofNullable(setLicenseHeaderYearsFromGitHistory)); } diff --git a/plugin-maven/src/main/java/com/diffplug/spotless/maven/FormatterFactory.java b/plugin-maven/src/main/java/com/diffplug/spotless/maven/FormatterFactory.java index 8e08c3903b..d5fbe60370 100644 --- a/plugin-maven/src/main/java/com/diffplug/spotless/maven/FormatterFactory.java +++ b/plugin-maven/src/main/java/com/diffplug/spotless/maven/FormatterFactory.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. @@ -15,6 +15,9 @@ */ package com.diffplug.spotless.maven; +import static com.diffplug.spotless.maven.AbstractSpotlessMojo.RATCHETFROM_NONE; +import static java.util.Collections.emptySet; + import java.io.File; import java.nio.charset.Charset; import java.util.ArrayList; @@ -45,9 +48,6 @@ import com.diffplug.spotless.maven.generic.ToggleOffOn; import com.diffplug.spotless.maven.generic.TrimTrailingWhitespace; -import static com.diffplug.spotless.maven.AbstractSpotlessMojo.RATCHETFROM_NONE; -import static java.util.Collections.emptySet; - public abstract class FormatterFactory { @Parameter private String encoding; From bd5548d40a6961c864951fb310b414bfb9f07724 Mon Sep 17 00:00:00 2001 From: Jan DHollander Date: Fri, 18 Feb 2022 09:10:13 +0100 Subject: [PATCH 039/757] Add to changelog --- plugin-maven/CHANGES.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/plugin-maven/CHANGES.md b/plugin-maven/CHANGES.md index 99bf40a44a..ff27aacf48 100644 --- a/plugin-maven/CHANGES.md +++ b/plugin-maven/CHANGES.md @@ -3,6 +3,9 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format (starting after version `1.27.0`). ## [Unreleased] +### Added +* Magic value 'NONE' for disabling ratchet functionality ([#1134](https://github.com/diffplug/spotless/issues/1134)) + ### Changed * Use SLF4J for logging ([#1116](https://github.com/diffplug/spotless/issues/1116)) From 57dabaa48d3626d750218c7726d0c35d706beabe Mon Sep 17 00:00:00 2001 From: circleci Date: Sat, 19 Feb 2022 05:18:00 +0000 Subject: [PATCH 040/757] Published maven/2.21.0 --- plugin-maven/CHANGES.md | 2 ++ plugin-maven/README.md | 4 ++-- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/plugin-maven/CHANGES.md b/plugin-maven/CHANGES.md index ff27aacf48..a41995ef1f 100644 --- a/plugin-maven/CHANGES.md +++ b/plugin-maven/CHANGES.md @@ -3,6 +3,8 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format (starting after version `1.27.0`). ## [Unreleased] + +## [2.21.0] - 2022-02-19 ### Added * Magic value 'NONE' for disabling ratchet functionality ([#1134](https://github.com/diffplug/spotless/issues/1134)) diff --git a/plugin-maven/README.md b/plugin-maven/README.md index 024b1107fe..0a77666e45 100644 --- a/plugin-maven/README.md +++ b/plugin-maven/README.md @@ -12,8 +12,8 @@ output = [ ].join('\n'); --> [![Maven central](https://img.shields.io/badge/mavencentral-com.diffplug.spotless%3Aspotless--maven--plugin-blue.svg)](https://search.maven.org/#search%7Cgav%7C1%7Cg%3A%22com.diffplug.spotless%22%20AND%20a%3A%22spotless-maven-plugin%22) -[![Javadoc](https://img.shields.io/badge/javadoc-yes-blue.svg)](https://javadoc.io/doc/com.diffplug.spotless/spotless-maven-plugin/2.20.2/index.html) -[![Changelog](https://img.shields.io/badge/changelog-2.20.2-brightgreen.svg)](CHANGES.md) +[![Javadoc](https://img.shields.io/badge/javadoc-yes-blue.svg)](https://javadoc.io/doc/com.diffplug.spotless/spotless-maven-plugin/2.21.0/index.html) +[![Changelog](https://img.shields.io/badge/changelog-2.21.0-brightgreen.svg)](CHANGES.md) [![Circle CI](https://circleci.com/gh/diffplug/spotless/tree/main.svg?style=shield)](https://circleci.com/gh/diffplug/spotless/tree/main) [![Live chat](https://img.shields.io/badge/gitter-chat-brightgreen.svg)](https://gitter.im/diffplug/spotless) From 80c4344eda32723a6f2194d7622e41b6633efc79 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 21 Feb 2022 12:04:16 +0000 Subject: [PATCH 041/757] Bump com.github.spotbugs from 5.0.5 to 5.0.6 Bumps com.github.spotbugs from 5.0.5 to 5.0.6. --- updated-dependencies: - dependency-name: com.github.spotbugs dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] --- settings.gradle | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/settings.gradle b/settings.gradle index 570d9c3d1e..0d09df4325 100644 --- a/settings.gradle +++ b/settings.gradle @@ -6,7 +6,7 @@ pluginManagement { // https://github.com/gradle-nexus/publish-plugin/releases id 'io.github.gradle-nexus.publish-plugin' version '1.1.0' // https://github.com/spotbugs/spotbugs-gradle-plugin/releases - id 'com.github.spotbugs' version '5.0.5' + id 'com.github.spotbugs' version '5.0.6' // https://github.com/diffplug/spotless-changelog id 'com.diffplug.spotless-changelog' version '2.3.2' // https://github.com/diffplug/goomph/blob/main/CHANGES.md From aba11e2ba19f4410c4020d053e97370f80511dd8 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 21 Feb 2022 12:04:17 +0000 Subject: [PATCH 042/757] Bump com.diffplug.spotless from 6.2.2 to 6.3.0 Bumps com.diffplug.spotless from 6.2.2 to 6.3.0. --- updated-dependencies: - dependency-name: com.diffplug.spotless dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] --- settings.gradle | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/settings.gradle b/settings.gradle index 570d9c3d1e..72e5cc595e 100644 --- a/settings.gradle +++ b/settings.gradle @@ -1,6 +1,6 @@ pluginManagement { plugins { - id 'com.diffplug.spotless' version '6.2.2' + id 'com.diffplug.spotless' version '6.3.0' // https://plugins.gradle.org/plugin/com.gradle.plugin-publish id 'com.gradle.plugin-publish' version '0.20.0' // https://github.com/gradle-nexus/publish-plugin/releases From c0759b21f964d3e6ec85390b5f4744e7a61a68b2 Mon Sep 17 00:00:00 2001 From: x80486 Date: Tue, 22 Feb 2022 07:40:46 -0500 Subject: [PATCH 043/757] Method encoding should accept java.nio.charset.Charset type --- .../com/diffplug/gradle/spotless/SpotlessExtension.java | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) 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 2fd3033f5f..e85c26f25e 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 @@ -73,6 +73,11 @@ public Charset getEncoding() { return encoding; } + /** Sets encoding to use (defaults to UTF_8). */ + public void setEncoding(Charset charset) { + encoding = requireNonNull(charset); + } + /** Sets encoding to use (defaults to UTF_8). */ public void setEncoding(String name) { requireNonNull(name); @@ -80,8 +85,8 @@ public void setEncoding(String name) { } /** Sets encoding to use (defaults to UTF_8). */ - public void setEncoding(Charset charset) { - encoding = requireNonNull(charset); + public void encoding(Charset charset) { + setEncoding(charset); } /** Sets encoding to use (defaults to UTF_8). */ From 13ef3fbd4e3e9e4b88e18d0c4688c26c1c36ff78 Mon Sep 17 00:00:00 2001 From: x80486 Date: Tue, 22 Feb 2022 07:56:03 -0500 Subject: [PATCH 044/757] Update "Unreleased" section in relevant projects for enhancement described in GitHub's Issue #1128 --- plugin-gradle/CHANGES.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/plugin-gradle/CHANGES.md b/plugin-gradle/CHANGES.md index 02f58ce41a..9f22285976 100644 --- a/plugin-gradle/CHANGES.md +++ b/plugin-gradle/CHANGES.md @@ -3,6 +3,8 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format (starting after version `3.27.0`). ## [Unreleased] +### Added +* Accept `java.nio.charset.Charset` type when setting the character encoding via `encoding` ([#1128](https://github.com/diffplug/spotless/issues/1128)) ## [6.3.0] - 2022-02-15 ### Added From 9eb082e84ca99984b4eb490b08b7f4ded0776456 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 28 Feb 2022 12:03:42 +0000 Subject: [PATCH 045/757] Bump com.adarshr.test-logger from 3.1.0 to 3.2.0 Bumps com.adarshr.test-logger from 3.1.0 to 3.2.0. --- updated-dependencies: - dependency-name: com.adarshr.test-logger dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] --- settings.gradle | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/settings.gradle b/settings.gradle index 4c23fbfcad..cb626e1b3d 100644 --- a/settings.gradle +++ b/settings.gradle @@ -14,7 +14,7 @@ pluginManagement { // https://github.com/gradle/test-retry-gradle-plugin/releases id 'org.gradle.test-retry' version '1.3.1' // https://github.com/radarsh/gradle-test-logger-plugin/blob/develop/CHANGELOG.md - id 'com.adarshr.test-logger' version '3.1.0' + id 'com.adarshr.test-logger' version '3.2.0' } } plugins { From fa0d153b2a2c0af7388e16b589232d396c41076a Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 7 Mar 2022 12:02:57 +0000 Subject: [PATCH 046/757] Bump actions/checkout from 2 to 3 Bumps [actions/checkout](https://github.com/actions/checkout) from 2 to 3. - [Release notes](https://github.com/actions/checkout/releases) - [Changelog](https://github.com/actions/checkout/blob/main/CHANGELOG.md) - [Commits](https://github.com/actions/checkout/compare/v2...v3) --- updated-dependencies: - dependency-name: actions/checkout dependency-type: direct:production update-type: version-update:semver-major ... Signed-off-by: dependabot[bot] --- .github/workflows/codeql-analysis.yml | 2 +- .github/workflows/gradle-wrapper-validation.yml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/codeql-analysis.yml b/.github/workflows/codeql-analysis.yml index 8af7ad4b44..59bac96914 100644 --- a/.github/workflows/codeql-analysis.yml +++ b/.github/workflows/codeql-analysis.yml @@ -30,7 +30,7 @@ jobs: steps: - name: Checkout repository - uses: actions/checkout@v2 + uses: actions/checkout@v3 with: # We must fetch at least the immediate parents so that if this is # a pull request then we can checkout the head. diff --git a/.github/workflows/gradle-wrapper-validation.yml b/.github/workflows/gradle-wrapper-validation.yml index 405a2b3065..8bfd0dcf51 100644 --- a/.github/workflows/gradle-wrapper-validation.yml +++ b/.github/workflows/gradle-wrapper-validation.yml @@ -6,5 +6,5 @@ jobs: name: "Validation" runs-on: ubuntu-latest steps: - - uses: actions/checkout@v2 + - uses: actions/checkout@v3 - uses: gradle/wrapper-validation-action@v1 From af4cd2232dd38c51ec50a3969eb1e1cd53b4843d Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Thu, 10 Mar 2022 19:07:35 +0000 Subject: [PATCH 047/757] Bump slf4j-api from 1.7.35 to 1.7.36 Bumps [slf4j-api](https://github.com/qos-ch/slf4j) from 1.7.35 to 1.7.36. - [Release notes](https://github.com/qos-ch/slf4j/releases) - [Commits](https://github.com/qos-ch/slf4j/compare/v_1.7.35...v_1.7.36) --- updated-dependencies: - dependency-name: org.slf4j:slf4j-api dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] --- lib/build.gradle | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/build.gradle b/lib/build.gradle index b122cb42ee..567e1f786c 100644 --- a/lib/build.gradle +++ b/lib/build.gradle @@ -21,7 +21,7 @@ for (glue in NEEDS_GLUE) { } dependencies { - compileOnly 'org.slf4j:slf4j-api:1.7.35' + compileOnly 'org.slf4j:slf4j-api:1.7.36' // zero runtime reqs is a hard requirements for spotless-lib // if you need a dep, put it in lib-extra testImplementation "org.junit.jupiter:junit-jupiter:$VER_JUNIT" From db9a14f09f3ba708f51e70224aca52a1317045f4 Mon Sep 17 00:00:00 2001 From: DDeg Date: Fri, 11 Mar 2022 10:37:07 +0300 Subject: [PATCH 048/757] Implemented configuration options for Kotlin ktfmt formatter. --- lib/build.gradle | 10 ++ .../glue/ktfmt/KtfmtFormatterFunc.java | 88 +++++++++++++ .../glue/ktfmt/KtfmtFormattingOptions.java | 92 +++++++++++++ .../spotless/glue/ktfmt/KtfmtStyle.java | 20 +++ .../diffplug/spotless/kotlin/KtfmtStep.java | 124 +++++++++++++++--- .../gradle/spotless/KotlinExtension.java | 43 ++++-- .../spotless/KotlinGradleExtension.java | 38 ++++-- .../gradle/spotless/KotlinExtensionTest.java | 46 ++++++- .../diffplug/spotless/maven/kotlin/Ktfmt.java | 20 ++- .../spotless/maven/kotlin/KtfmtTest.java | 20 ++- .../kotlin/ktfmt/max-width-dropbox.clean | 12 ++ .../resources/kotlin/ktfmt/max-width.clean | 12 ++ .../resources/kotlin/ktfmt/max-width.dirty | 12 ++ .../spotless/kotlin/KtfmtStepTest.java | 6 +- 14 files changed, 499 insertions(+), 44 deletions(-) create mode 100644 lib/src/ktfmt/java/com/diffplug/spotless/glue/ktfmt/KtfmtFormatterFunc.java create mode 100644 lib/src/ktfmt/java/com/diffplug/spotless/glue/ktfmt/KtfmtFormattingOptions.java create mode 100644 lib/src/ktfmt/java/com/diffplug/spotless/glue/ktfmt/KtfmtStyle.java create mode 100644 testlib/src/main/resources/kotlin/ktfmt/max-width-dropbox.clean create mode 100644 testlib/src/main/resources/kotlin/ktfmt/max-width.clean create mode 100644 testlib/src/main/resources/kotlin/ktfmt/max-width.dirty diff --git a/lib/build.gradle b/lib/build.gradle index 567e1f786c..a585d8328e 100644 --- a/lib/build.gradle +++ b/lib/build.gradle @@ -9,6 +9,7 @@ apply from: rootProject.file('gradle/java-publish.gradle') def NEEDS_GLUE = [ 'sortPom', 'palantirJavaFormat', + 'ktfmt', 'ktlint', 'flexmark' ] @@ -34,6 +35,15 @@ dependencies { palantirJavaFormatCompileOnly 'com.palantir.javaformat:palantir-java-format:1.1.0' + String VER_KTFMT = '0.34' + 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") { + version { + strictly VER_KTLINT_GOOGLE_JAVA_FORMAT + } + } + String VER_KTLINT='0.43.2' ktlintCompileOnly "com.pinterest:ktlint:$VER_KTLINT" ktlintCompileOnly "com.pinterest.ktlint:ktlint-core:$VER_KTLINT" diff --git a/lib/src/ktfmt/java/com/diffplug/spotless/glue/ktfmt/KtfmtFormatterFunc.java b/lib/src/ktfmt/java/com/diffplug/spotless/glue/ktfmt/KtfmtFormatterFunc.java new file mode 100644 index 0000000000..72e0e50e3c --- /dev/null +++ b/lib/src/ktfmt/java/com/diffplug/spotless/glue/ktfmt/KtfmtFormatterFunc.java @@ -0,0 +1,88 @@ +/* + * Copyright 2022 DiffPlug + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.diffplug.spotless.glue.ktfmt; + +import javax.annotation.Nonnull; +import javax.annotation.Nullable; + +import com.facebook.ktfmt.format.Formatter; +import com.facebook.ktfmt.format.FormattingOptions; + +import com.diffplug.spotless.FormatterFunc; + +public final class KtfmtFormatterFunc implements FormatterFunc { + + @Nonnull + private final KtfmtStyle style; + + @Nullable + private final KtfmtFormattingOptions ktfmtFormattingOptions; + + public KtfmtFormatterFunc() { + this(KtfmtStyle.DEFAULT, null); + } + + public KtfmtFormatterFunc(@Nonnull KtfmtStyle style) { + this(style, null); + } + + public KtfmtFormatterFunc(@Nullable KtfmtFormattingOptions ktfmtFormattingOptions) { + this(KtfmtStyle.DEFAULT, ktfmtFormattingOptions); + } + + public KtfmtFormatterFunc(@Nonnull KtfmtStyle style, @Nullable KtfmtFormattingOptions ktfmtFormattingOptions) { + this.style = style; + this.ktfmtFormattingOptions = ktfmtFormattingOptions; + } + + @Nonnull + @Override + public String apply(@Nonnull String input) throws Exception { + return Formatter.format(createFormattingOptions(), input); + } + + private FormattingOptions createFormattingOptions() { + FormattingOptions formattingOptions; + switch (style) { + case DEFAULT: + formattingOptions = new FormattingOptions(); + break; + case DROPBOX: + formattingOptions = Formatter.DROPBOX_FORMAT; + break; + case GOOGLE: + formattingOptions = Formatter.GOOGLE_FORMAT; + break; + case KOTLIN_LANG: + formattingOptions = Formatter.KOTLINLANG_FORMAT; + break; + default: + throw new IllegalStateException("Unknown formatting option"); + } + + if (ktfmtFormattingOptions != null) { + formattingOptions = formattingOptions.copy( + formattingOptions.getStyle(), + ktfmtFormattingOptions.getMaxWidth().orElse(formattingOptions.getMaxWidth()), + ktfmtFormattingOptions.getBlockIndent().orElse(formattingOptions.getBlockIndent()), + ktfmtFormattingOptions.getContinuationIndent().orElse(formattingOptions.getBlockIndent()), + ktfmtFormattingOptions.getRemoveUnusedImport().orElse(formattingOptions.getRemoveUnusedImports()), + formattingOptions.getDebuggingPrintOpsAfterFormatting()); + } + + return formattingOptions; + } +} diff --git a/lib/src/ktfmt/java/com/diffplug/spotless/glue/ktfmt/KtfmtFormattingOptions.java b/lib/src/ktfmt/java/com/diffplug/spotless/glue/ktfmt/KtfmtFormattingOptions.java new file mode 100644 index 0000000000..ff8e522aae --- /dev/null +++ b/lib/src/ktfmt/java/com/diffplug/spotless/glue/ktfmt/KtfmtFormattingOptions.java @@ -0,0 +1,92 @@ +/* + * Copyright 2022 DiffPlug + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.diffplug.spotless.glue.ktfmt; + +import java.util.Optional; + +import javax.annotation.Nonnull; +import javax.annotation.Nullable; + +public final class KtfmtFormattingOptions { + + @Nullable + private Integer maxWidth; + + @Nullable + private Integer blockIndent; + + @Nullable + private Integer continuationIndent; + + @Nullable + private Boolean removeUnusedImport; + + public KtfmtFormattingOptions( + @Nullable Integer maxWidth, + @Nullable Integer blockIndent, + @Nullable Integer continuationIndent, + @Nullable Boolean removeUnusedImport) { + this.maxWidth = maxWidth; + this.blockIndent = blockIndent; + this.continuationIndent = continuationIndent; + this.removeUnusedImport = removeUnusedImport; + } + + @Nonnull + public Optional getMaxWidth() { + return Optional.ofNullable(maxWidth); + } + + @Nonnull + public Optional getBlockIndent() { + return Optional.ofNullable(blockIndent); + } + + @Nonnull + public Optional getContinuationIndent() { + return Optional.ofNullable(continuationIndent); + } + + @Nonnull + public Optional getRemoveUnusedImport() { + return Optional.ofNullable(removeUnusedImport); + } + + public void setMaxWidth(int maxWidth) { + if (maxWidth <= 0) { + throw new IllegalArgumentException("Max width cannot be negative value or 0"); + } + this.maxWidth = maxWidth; + } + + public void setBlockIndent(int blockIndent) { + if (blockIndent < 0) { + throw new IllegalArgumentException("Block indent cannot be negative value"); + } + this.blockIndent = blockIndent; + } + + public void setContinuationIndent(int continuationIndent) { + if (continuationIndent < 0) { + throw new IllegalArgumentException("Continuation indent cannot be negative value"); + } + this.continuationIndent = continuationIndent; + } + + public void setRemoveUnusedImport(boolean removeUnusedImport) { + this.removeUnusedImport = removeUnusedImport; + } +} diff --git a/lib/src/ktfmt/java/com/diffplug/spotless/glue/ktfmt/KtfmtStyle.java b/lib/src/ktfmt/java/com/diffplug/spotless/glue/ktfmt/KtfmtStyle.java new file mode 100644 index 0000000000..34b81175ec --- /dev/null +++ b/lib/src/ktfmt/java/com/diffplug/spotless/glue/ktfmt/KtfmtStyle.java @@ -0,0 +1,20 @@ +/* + * Copyright 2022 DiffPlug + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.diffplug.spotless.glue.ktfmt; + +public enum KtfmtStyle { + DEFAULT, DROPBOX, GOOGLE, KOTLIN_LANG +} 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 9f3b62dadb..e5e2e57f01 100644 --- a/lib/src/main/java/com/diffplug/spotless/kotlin/KtfmtStep.java +++ b/lib/src/main/java/com/diffplug/spotless/kotlin/KtfmtStep.java @@ -19,11 +19,18 @@ import java.io.IOException; import java.io.Serializable; +import java.lang.reflect.Constructor; import java.lang.reflect.InvocationTargetException; import java.lang.reflect.Method; import java.util.Objects; -import com.diffplug.spotless.*; +import javax.annotation.Nullable; + +import com.diffplug.spotless.FormatterFunc; +import com.diffplug.spotless.FormatterStep; +import com.diffplug.spotless.JarState; +import com.diffplug.spotless.Provisioner; +import com.diffplug.spotless.ThrowingEx; /** * Wraps up ktfmt as a FormatterStep. @@ -32,7 +39,7 @@ public class KtfmtStep { // prevent direct instantiation private KtfmtStep() {} - private static final String DEFAULT_VERSION = "0.31"; + private static final String DEFAULT_VERSION = "0.34"; static final String NAME = "ktfmt"; static final String PACKAGE = "com.facebook"; static final String MAVEN_COORDINATE = PACKAGE + ":ktfmt:"; @@ -62,7 +69,35 @@ String getSince() { } } - private static final String DROPBOX_STYLE_METHOD = "dropboxStyle"; + public static class KtfmtFormattingOptions implements Serializable { + + private static final long serialVersionUID = 1L; + + @Nullable + private Integer maxWidth = null; + + @Nullable + private Integer blockIndent = null; + + @Nullable + private Integer continuationIndent = null; + + @Nullable + private Boolean removeUnusedImport = null; + + public KtfmtFormattingOptions() {} + + public KtfmtFormattingOptions( + @Nullable Integer maxWidth, + @Nullable Integer blockIndent, + @Nullable Integer continuationIndent, + @Nullable Boolean removeUnusedImport) { + this.maxWidth = maxWidth; + this.blockIndent = blockIndent; + this.continuationIndent = continuationIndent; + this.removeUnusedImport = removeUnusedImport; + } + } /** * The format method is available in the link below. @@ -78,26 +113,21 @@ public static FormatterStep create(Provisioner provisioner) { /** Creates a step which formats everything - code, import order, and unused imports. */ public static FormatterStep create(String version, Provisioner provisioner) { - return create(version, provisioner, DEFAULT); + return create(version, provisioner, null, null); } /** Creates a step which formats everything - code, import order, and unused imports. */ - public static FormatterStep create(String version, Provisioner provisioner, Style style) { + public static FormatterStep create(String version, Provisioner provisioner, @Nullable Style style, @Nullable KtfmtFormattingOptions options) { Objects.requireNonNull(version, "version"); Objects.requireNonNull(provisioner, "provisioner"); - Objects.requireNonNull(style, "style"); return FormatterStep.createLazy( - NAME, () -> new State(version, provisioner, style), State::createFormat); + NAME, () -> new State(version, provisioner, style, options), State::createFormat); } public static String defaultVersion() { return DEFAULT_VERSION; } - public static String defaultStyle() { - return Style.DEFAULT.name(); - } - static final class State implements Serializable { private static final long serialVersionUID = 1L; @@ -107,26 +137,90 @@ static final class State implements Serializable { /** * Option that allows to apply formatting options to perform a 4 spaces block and continuation indent. */ + @Nullable private final Style style; + /** + * + */ + @Nullable + private final KtfmtFormattingOptions options; /** The jar that contains the formatter. */ final JarState jarState; - State(String version, Provisioner provisioner, Style style) throws IOException { + State(String version, Provisioner provisioner, @Nullable Style style, @Nullable KtfmtFormattingOptions options) throws IOException { this.version = version; + this.options = options; this.pkg = PACKAGE; this.style = style; this.jarState = JarState.from(MAVEN_COORDINATE + version, provisioner); } FormatterFunc createFormat() throws Exception { - ClassLoader classLoader = jarState.getClassLoader(); + final ClassLoader classLoader = jarState.getClassLoader(); + + if (BadSemver.version(version) < BadSemver.version(0, 32)) { + if (options != null) { + throw new IllegalStateException("Ktfmt formatting options supported for version 0.32 and later"); + } + return getFormatterFuncFallback(style != null ? style : DEFAULT, classLoader); + } + + final Class formatterFuncClass = classLoader.loadClass("com.diffplug.spotless.glue.ktfmt.KtfmtFormatterFunc"); + final Class ktfmtStyleClass = classLoader.loadClass("com.diffplug.spotless.glue.ktfmt.KtfmtStyle"); + final Class ktfmtFormattingOptionsClass = classLoader.loadClass("com.diffplug.spotless.glue.ktfmt.KtfmtFormattingOptions"); + + if (style == null && options == null) { + final Constructor constructor = formatterFuncClass.getConstructor(); + return (FormatterFunc) constructor.newInstance(); + } + + final Object ktfmtStyle = style == null ? null : Enum.valueOf((Class) ktfmtStyleClass, getKtfmtStyleOption(style)); + if (options == null) { + final Constructor constructor = formatterFuncClass.getConstructor(ktfmtStyleClass); + return (FormatterFunc) constructor.newInstance(ktfmtStyle); + } + + final Constructor optionsConstructor = ktfmtFormattingOptionsClass.getConstructor( + Integer.class, Integer.class, Integer.class, Boolean.class); + final Object ktfmtFormattingOptions = optionsConstructor.newInstance( + options.maxWidth, options.blockIndent, options.continuationIndent, options.removeUnusedImport); + if (style == null) { + final Constructor constructor = formatterFuncClass.getConstructor(ktfmtFormattingOptionsClass); + return (FormatterFunc) constructor.newInstance(ktfmtFormattingOptions); + } + + final Constructor constructor = formatterFuncClass.getConstructor(ktfmtStyleClass, ktfmtFormattingOptionsClass); + return (FormatterFunc) constructor.newInstance(ktfmtStyle, ktfmtFormattingOptions); + } + + /** + * @param style + * @return com.diffplug.spotless.glue.ktfmt.KtfmtStyle enum value name + */ + private String getKtfmtStyleOption(Style style) { + switch (style) { + case DEFAULT: + return "DEFAULT"; + case DROPBOX: + return "DROPBOX"; + case GOOGLE: + return "GOOGLE"; + case KOTLINLANG: + return "KOTLIN_LANG"; + default: + throw new IllegalStateException("Unsupported style: " + style); + } + } + + private FormatterFunc getFormatterFuncFallback(Style style, ClassLoader classLoader) { return input -> { try { if (style == DEFAULT) { Method formatterMethod = getFormatterClazz(classLoader).getMethod(FORMATTER_METHOD, String.class); return (String) formatterMethod.invoke(getFormatterClazz(classLoader), input); } else { - Method formatterMethod = getFormatterClazz(classLoader).getMethod(FORMATTER_METHOD, getFormattingOptionsClazz(classLoader), + Method formatterMethod = getFormatterClazz(classLoader).getMethod(FORMATTER_METHOD, + getFormattingOptionsClazz(classLoader), String.class); Object formattingOptions = getCustomFormattingOptions(classLoader, style); return (String) formatterMethod.invoke(getFormatterClazz(classLoader), formattingOptions, input); @@ -151,7 +245,7 @@ private Object getCustomFormattingOptions(ClassLoader classLoader, Style style) if (style == Style.DEFAULT || style == Style.DROPBOX) { Class formattingOptionsCompanionClazz = classLoader.loadClass(pkg + ".ktfmt.FormattingOptions$Companion"); Object companion = formattingOptionsCompanionClazz.getConstructors()[0].newInstance((Object) null); - Method formattingOptionsMethod = formattingOptionsCompanionClazz.getDeclaredMethod(DROPBOX_STYLE_METHOD); + Method formattingOptionsMethod = formattingOptionsCompanionClazz.getDeclaredMethod("dropboxStyle"); return formattingOptionsMethod.invoke(companion); } else { throw new IllegalStateException("Versions pre-0.19 can only use Default and Dropbox styles"); diff --git a/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/KotlinExtension.java b/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/KotlinExtension.java index d88b4aac7f..56d925caa3 100644 --- a/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/KotlinExtension.java +++ b/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/KotlinExtension.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. @@ -21,6 +21,7 @@ import java.util.Collections; import java.util.Map; import java.util.Objects; +import java.util.function.Consumer; import javax.inject.Inject; @@ -34,6 +35,7 @@ import com.diffplug.spotless.kotlin.DiktatStep; import com.diffplug.spotless.kotlin.KtLintStep; import com.diffplug.spotless.kotlin.KtfmtStep; +import com.diffplug.spotless.kotlin.KtfmtStep.KtfmtFormattingOptions; import com.diffplug.spotless.kotlin.KtfmtStep.Style; public class KotlinExtension extends FormatExtension implements HasBuiltinDelimiterForLicense { @@ -104,32 +106,49 @@ public KtfmtConfig ktfmt(String version) { public class KtfmtConfig { final String version; Style style; + KtfmtFormattingOptions options; + + private final ConfigurableStyle configurableStyle = new ConfigurableStyle(); KtfmtConfig(String version) { this.version = Objects.requireNonNull(version); - this.style = Style.DEFAULT; addStep(createStep()); } - public void dropboxStyle() { - style(Style.DROPBOX); + private ConfigurableStyle style(Style style) { + this.style = style; + replaceStep(createStep()); + return configurableStyle; } - public void googleStyle() { - style(Style.GOOGLE); + public ConfigurableStyle dropboxStyle() { + return style(Style.DROPBOX); } - public void kotlinlangStyle() { - style(Style.KOTLINLANG); + public ConfigurableStyle googleStyle() { + return style(Style.GOOGLE); } - public void style(Style style) { - this.style = style; - replaceStep(createStep()); + public ConfigurableStyle kotlinlangStyle() { + return style(Style.KOTLINLANG); + } + + public void configure(Consumer optionsConfiguration) { + this.configurableStyle.configure(optionsConfiguration); } private FormatterStep createStep() { - return KtfmtStep.create(version, provisioner(), style); + return KtfmtStep.create(version, provisioner(), style, options); + } + + class ConfigurableStyle { + + void configure(Consumer optionsConfiguration) { + KtfmtFormattingOptions ktfmtFormattingOptions = new KtfmtFormattingOptions(); + optionsConfiguration.accept(ktfmtFormattingOptions); + options = ktfmtFormattingOptions; + replaceStep(createStep()); + } } } diff --git a/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/KotlinGradleExtension.java b/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/KotlinGradleExtension.java index 5ea3c29594..1ff2b0c332 100644 --- a/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/KotlinGradleExtension.java +++ b/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/KotlinGradleExtension.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. @@ -19,6 +19,7 @@ import java.util.Collections; import java.util.Map; import java.util.Objects; +import java.util.function.Consumer; import javax.inject.Inject; @@ -28,6 +29,7 @@ import com.diffplug.spotless.kotlin.DiktatStep; import com.diffplug.spotless.kotlin.KtLintStep; import com.diffplug.spotless.kotlin.KtfmtStep; +import com.diffplug.spotless.kotlin.KtfmtStep.KtfmtFormattingOptions; import com.diffplug.spotless.kotlin.KtfmtStep.Style; public class KotlinGradleExtension extends FormatExtension { @@ -90,6 +92,9 @@ public KtfmtConfig ktfmt(String version) { public class KtfmtConfig { final String version; Style style; + KtfmtFormattingOptions options; + + private final ConfigurableStyle configurableStyle = new ConfigurableStyle(); KtfmtConfig(String version) { this.version = Objects.requireNonNull(version); @@ -97,25 +102,40 @@ public class KtfmtConfig { addStep(createStep()); } - public void style(Style style) { + private ConfigurableStyle style(Style style) { this.style = style; replaceStep(createStep()); + return configurableStyle; + } + + public ConfigurableStyle dropboxStyle() { + return style(Style.DROPBOX); } - public void dropboxStyle() { - style(Style.DROPBOX); + public ConfigurableStyle googleStyle() { + return style(Style.GOOGLE); } - public void googleStyle() { - style(Style.GOOGLE); + public ConfigurableStyle kotlinlangStyle() { + return style(Style.KOTLINLANG); } - public void kotlinlangStyle() { - style(Style.KOTLINLANG); + public void configure(Consumer optionsConfiguration) { + this.configurableStyle.configure(optionsConfiguration); } private FormatterStep createStep() { - return KtfmtStep.create(version, provisioner(), style); + return KtfmtStep.create(version, provisioner(), style, options); + } + + class ConfigurableStyle { + + void configure(Consumer optionsConfiguration) { + KtfmtFormattingOptions ktfmtFormattingOptions = new KtfmtFormattingOptions(); + optionsConfiguration.accept(ktfmtFormattingOptions); + options = ktfmtFormattingOptions; + replaceStep(createStep()); + } } } diff --git a/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/KotlinExtensionTest.java b/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/KotlinExtensionTest.java index f3d8ad442d..3bbd44d63d 100644 --- a/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/KotlinExtensionTest.java +++ b/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/KotlinExtensionTest.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. @@ -269,4 +269,48 @@ void testWithNonStandardYearSeparatorKtfmt() throws IOException { matcher.startsWith("// License Header 2012, 2014"); }); } + + @Test + @EnabledForJreRange(min = JAVA_11) // ktfmt's dependency, google-java-format 1.8 requires a minimum of JRE 11+. + void testWithCustomMaxWidthDefaultStyleKtfmt() throws IOException { + setFile("build.gradle").toLines( + "plugins {", + " id 'org.jetbrains.kotlin.jvm' version '1.5.31'", + " id 'com.diffplug.spotless'", + "}", + "repositories { mavenCentral() }", + "spotless {", + " kotlin {", + " ktfmt().configure { options ->", + " options.maxWidth = 120", + " }", + " }", + "}"); + + setFile("src/main/kotlin/max-width.kt").toResource("kotlin/ktfmt/max-width.dirty"); + gradleRunner().withArguments("spotlessApply").build(); + assertFile("src/main/kotlin/max-width.kt").sameAsResource("kotlin/ktfmt/max-width.clean"); + } + + @Test + @EnabledForJreRange(min = JAVA_11) // ktfmt's dependency, google-java-format 1.8 requires a minimum of JRE 11+. + void testWithCustomMaxWidthDropboxStyleKtfmt() throws IOException { + setFile("build.gradle").toLines( + "plugins {", + " id 'org.jetbrains.kotlin.jvm' version '1.5.31'", + " id 'com.diffplug.spotless'", + "}", + "repositories { mavenCentral() }", + "spotless {", + " kotlin {", + " ktfmt().dropboxStyle().configure { options ->", + " options.maxWidth = 120", + " }", + " }", + "}"); + + setFile("src/main/kotlin/max-width.kt").toResource("kotlin/ktfmt/max-width.dirty"); + gradleRunner().withArguments("spotlessApply").build(); + assertFile("src/main/kotlin/max-width.kt").sameAsResource("kotlin/ktfmt/max-width-dropbox.clean"); + } } diff --git a/plugin-maven/src/main/java/com/diffplug/spotless/maven/kotlin/Ktfmt.java b/plugin-maven/src/main/java/com/diffplug/spotless/maven/kotlin/Ktfmt.java index c1258a15fe..b917d33a44 100644 --- a/plugin-maven/src/main/java/com/diffplug/spotless/maven/kotlin/Ktfmt.java +++ b/plugin-maven/src/main/java/com/diffplug/spotless/maven/kotlin/Ktfmt.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. @@ -19,6 +19,7 @@ import com.diffplug.spotless.FormatterStep; import com.diffplug.spotless.kotlin.KtfmtStep; +import com.diffplug.spotless.kotlin.KtfmtStep.KtfmtFormattingOptions; import com.diffplug.spotless.kotlin.KtfmtStep.Style; import com.diffplug.spotless.maven.FormatterStepConfig; import com.diffplug.spotless.maven.FormatterStepFactory; @@ -31,10 +32,23 @@ public class Ktfmt implements FormatterStepFactory { @Parameter private String style; + @Parameter + private Integer maxWidth; + + @Parameter + private Integer blockIndent; + + @Parameter + private Integer continuationIndent; + + @Parameter + private Boolean removeUnusedImport; + @Override public FormatterStep newFormatterStep(FormatterStepConfig config) { String version = this.version != null ? this.version : KtfmtStep.defaultVersion(); - String style = this.style != null ? this.style : KtfmtStep.defaultStyle(); - return KtfmtStep.create(version, config.getProvisioner(), Style.valueOf(style)); + Style style = this.style != null ? Style.valueOf(this.style) : null; + KtfmtFormattingOptions options = new KtfmtFormattingOptions(maxWidth, blockIndent, continuationIndent, removeUnusedImport); + return KtfmtStep.create(version, config.getProvisioner(), style, options); } } diff --git a/plugin-maven/src/test/java/com/diffplug/spotless/maven/kotlin/KtfmtTest.java b/plugin-maven/src/test/java/com/diffplug/spotless/maven/kotlin/KtfmtTest.java index 7b0ca069fc..88dcd172e0 100644 --- a/plugin-maven/src/test/java/com/diffplug/spotless/maven/kotlin/KtfmtTest.java +++ b/plugin-maven/src/test/java/com/diffplug/spotless/maven/kotlin/KtfmtTest.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. @@ -48,4 +48,22 @@ void testKtfmtStyle() throws Exception { mavenRunner().withArguments("spotless:apply").runNoError(); assertFile("src/main/kotlin/main.kt").sameAsResource("kotlin/ktfmt/basic-dropboxstyle.clean"); } + + @Test + void testKtfmtWithMaxWidthOption() throws Exception { + writePomWithKotlinSteps("120"); + + setFile("src/main/kotlin/main.kt").toResource("kotlin/ktfmt/max-width.dirty"); + mavenRunner().withArguments("spotless:apply").runNoError(); + assertFile("src/main/kotlin/main.kt").sameAsResource("kotlin/ktfmt/max-width.clean"); + } + + @Test + void testKtfmtStyleWithMaxWidthOption() throws Exception { + writePomWithKotlinSteps("120"); + + setFile("src/main/kotlin/main.kt").toResource("kotlin/ktfmt/max-width.dirty"); + mavenRunner().withArguments("spotless:apply").runNoError(); + assertFile("src/main/kotlin/main.kt").sameAsResource("kotlin/ktfmt/max-width-dropbox.clean"); + } } diff --git a/testlib/src/main/resources/kotlin/ktfmt/max-width-dropbox.clean b/testlib/src/main/resources/kotlin/ktfmt/max-width-dropbox.clean new file mode 100644 index 0000000000..0fce31c7ec --- /dev/null +++ b/testlib/src/main/resources/kotlin/ktfmt/max-width-dropbox.clean @@ -0,0 +1,12 @@ +import a.* +import a.b +import a.b.c.* +import kotlinx.android.synthetic.main.layout_name.* + +fun main() {} + +fun foo(param1: Any, param2: Any, param3: Any, param4: Any, param5: Any, param6: Any, param7: Any, param8: Any) { + a() + functionNameWithAlmost120SymbolsToValidateThatKtfmtNotBreakLineAtDefault100(param1, param2, param3, param4, param5) + return b +} diff --git a/testlib/src/main/resources/kotlin/ktfmt/max-width.clean b/testlib/src/main/resources/kotlin/ktfmt/max-width.clean new file mode 100644 index 0000000000..4592181044 --- /dev/null +++ b/testlib/src/main/resources/kotlin/ktfmt/max-width.clean @@ -0,0 +1,12 @@ +import a.* +import a.b +import a.b.c.* +import kotlinx.android.synthetic.main.layout_name.* + +fun main() {} + +fun foo(param1: Any, param2: Any, param3: Any, param4: Any, param5: Any, param6: Any, param7: Any, param8: Any) { + a() + functionNameWithAlmost120SymbolsToValidateThatKtfmtNotBreakLineAtDefault100(param1, param2, param3, param4, param5) + return b +} diff --git a/testlib/src/main/resources/kotlin/ktfmt/max-width.dirty b/testlib/src/main/resources/kotlin/ktfmt/max-width.dirty new file mode 100644 index 0000000000..ef9504e1c3 --- /dev/null +++ b/testlib/src/main/resources/kotlin/ktfmt/max-width.dirty @@ -0,0 +1,12 @@ +import a.* + +import kotlinx.android.synthetic.main.layout_name.* + +import a.b.c.* +import a.b + +fun main() {} +fun foo(param1: Any, param2: Any, param3: Any, param4: Any, param5: Any, param6: Any, param7: Any, param8: Any) { + a(); functionNameWithAlmost120SymbolsToValidateThatKtfmtNotBreakLineAtDefault100(param1, param2, param3, param4, param5) + return b +} diff --git a/testlib/src/test/java/com/diffplug/spotless/kotlin/KtfmtStepTest.java b/testlib/src/test/java/com/diffplug/spotless/kotlin/KtfmtStepTest.java index 3416e6d297..ddaf1b324b 100644 --- a/testlib/src/test/java/com/diffplug/spotless/kotlin/KtfmtStepTest.java +++ b/testlib/src/test/java/com/diffplug/spotless/kotlin/KtfmtStepTest.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. @@ -35,14 +35,14 @@ void behavior() throws Exception { @Test @EnabledForJreRange(min = JAVA_11) // ktfmt's dependency, google-java-format 1.8 requires a minimum of JRE 11+. void dropboxStyle_0_18() throws Exception { - FormatterStep step = KtfmtStep.create("0.18", TestProvisioner.mavenCentral(), KtfmtStep.Style.DROPBOX); + FormatterStep step = KtfmtStep.create("0.18", TestProvisioner.mavenCentral(), KtfmtStep.Style.DROPBOX, null); StepHarness.forStep(step).testResource("kotlin/ktfmt/basic.dirty", "kotlin/ktfmt/basic-dropboxstyle.clean"); } @Test @EnabledForJreRange(min = JAVA_11) // ktfmt's dependency, google-java-format 1.8 requires a minimum of JRE 11+. void dropboxStyle_0_19() throws Exception { - FormatterStep step = KtfmtStep.create("0.19", TestProvisioner.mavenCentral(), KtfmtStep.Style.DROPBOX); + FormatterStep step = KtfmtStep.create("0.19", TestProvisioner.mavenCentral(), KtfmtStep.Style.DROPBOX, null); StepHarness.forStep(step).testResource("kotlin/ktfmt/basic.dirty", "kotlin/ktfmt/basic-dropboxstyle.clean"); } From fb62f361f1478cef675ceb7df029e26b078bbea8 Mon Sep 17 00:00:00 2001 From: DDeg Date: Fri, 11 Mar 2022 10:47:52 +0300 Subject: [PATCH 049/757] Updated unreleased block in changelog with ktfmt custom parameters. --- CHANGES.md | 1 + plugin-gradle/CHANGES.md | 1 + plugin-maven/CHANGES.md | 1 + 3 files changed, 3 insertions(+) diff --git a/CHANGES.md b/CHANGES.md index 36be0237d7..79c97cb411 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -10,6 +10,7 @@ This document is intended for Spotless developers. We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format (starting after version `1.27.0`). ## [Unreleased] +* Added support for setting custom parameters for Kotlin ktfmt in Gradle and Maven plugins. ([#1145](https://github.com/diffplug/spotless/pull/1145)) ## [2.23.0] - 2022-02-15 ### Added diff --git a/plugin-gradle/CHANGES.md b/plugin-gradle/CHANGES.md index 9f22285976..4eb101c7a0 100644 --- a/plugin-gradle/CHANGES.md +++ b/plugin-gradle/CHANGES.md @@ -5,6 +5,7 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format ( ## [Unreleased] ### Added * Accept `java.nio.charset.Charset` type when setting the character encoding via `encoding` ([#1128](https://github.com/diffplug/spotless/issues/1128)) +* Added support for setting custom parameters for Kotlin ktfmt in Gradle plugin. ([#1145](https://github.com/diffplug/spotless/pull/1145)) ## [6.3.0] - 2022-02-15 ### Added diff --git a/plugin-maven/CHANGES.md b/plugin-maven/CHANGES.md index a41995ef1f..c320da7d31 100644 --- a/plugin-maven/CHANGES.md +++ b/plugin-maven/CHANGES.md @@ -3,6 +3,7 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format (starting after version `1.27.0`). ## [Unreleased] +* Added support for setting custom parameters for Kotlin ktfmt in Maven plugin. ([#1145](https://github.com/diffplug/spotless/pull/1145)) ## [2.21.0] - 2022-02-19 ### Added From de790fcbb942835e0ec5911414a6af0695a2a1ab Mon Sep 17 00:00:00 2001 From: Ned Twigg Date: Mon, 28 Mar 2022 10:58:53 -0700 Subject: [PATCH 050/757] Minor changelog tweaks. --- CHANGES.md | 1 + plugin-maven/CHANGES.md | 1 + 2 files changed, 2 insertions(+) diff --git a/CHANGES.md b/CHANGES.md index 79c97cb411..3010a0f826 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -10,6 +10,7 @@ This document is intended for Spotless developers. We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format (starting after version `1.27.0`). ## [Unreleased] +### Added * Added support for setting custom parameters for Kotlin ktfmt in Gradle and Maven plugins. ([#1145](https://github.com/diffplug/spotless/pull/1145)) ## [2.23.0] - 2022-02-15 diff --git a/plugin-maven/CHANGES.md b/plugin-maven/CHANGES.md index c320da7d31..1976b6b46a 100644 --- a/plugin-maven/CHANGES.md +++ b/plugin-maven/CHANGES.md @@ -3,6 +3,7 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format (starting after version `1.27.0`). ## [Unreleased] +### Added * Added support for setting custom parameters for Kotlin ktfmt in Maven plugin. ([#1145](https://github.com/diffplug/spotless/pull/1145)) ## [2.21.0] - 2022-02-19 From cf04c82e5f983d0774d73a7c67751037d826c757 Mon Sep 17 00:00:00 2001 From: circleci Date: Mon, 28 Mar 2022 18:23:37 +0000 Subject: [PATCH 051/757] Published lib/2.24.0 --- CHANGES.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/CHANGES.md b/CHANGES.md index 3010a0f826..c4f39a815c 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -10,6 +10,8 @@ This document is intended for Spotless developers. We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format (starting after version `1.27.0`). ## [Unreleased] + +## [2.24.0] - 2022-03-28 ### Added * Added support for setting custom parameters for Kotlin ktfmt in Gradle and Maven plugins. ([#1145](https://github.com/diffplug/spotless/pull/1145)) From 795186b3443f1683335e1d91d68b20dbf2978606 Mon Sep 17 00:00:00 2001 From: circleci Date: Mon, 28 Mar 2022 18:24:23 +0000 Subject: [PATCH 052/757] Published gradle/6.4.0 --- plugin-gradle/CHANGES.md | 2 ++ plugin-gradle/README.md | 46 ++++++++++++++++++++-------------------- 2 files changed, 25 insertions(+), 23 deletions(-) diff --git a/plugin-gradle/CHANGES.md b/plugin-gradle/CHANGES.md index 4eb101c7a0..d991b050a4 100644 --- a/plugin-gradle/CHANGES.md +++ b/plugin-gradle/CHANGES.md @@ -3,6 +3,8 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format (starting after version `3.27.0`). ## [Unreleased] + +## [6.4.0] - 2022-03-28 ### Added * Accept `java.nio.charset.Charset` type when setting the character encoding via `encoding` ([#1128](https://github.com/diffplug/spotless/issues/1128)) * Added support for setting custom parameters for Kotlin ktfmt in Gradle plugin. ([#1145](https://github.com/diffplug/spotless/pull/1145)) diff --git a/plugin-gradle/README.md b/plugin-gradle/README.md index 2039ed92d3..9b64f6f38a 100644 --- a/plugin-gradle/README.md +++ b/plugin-gradle/README.md @@ -18,9 +18,9 @@ output = [ --> [![Gradle plugin](https://img.shields.io/badge/plugins.gradle.org-com.diffplug.spotless-blue.svg)](https://plugins.gradle.org/plugin/com.diffplug.spotless) [![Maven central](https://img.shields.io/badge/mavencentral-yes-blue.svg)](https://search.maven.org/#search%7Cgav%7C1%7Cg%3A%22com.diffplug.spotless%22%20AND%20a%3A%22spotless-plugin-gradle%22) -[![Javadoc](https://img.shields.io/badge/javadoc-yes-blue.svg)](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.3.0/index.html) +[![Javadoc](https://img.shields.io/badge/javadoc-yes-blue.svg)](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.4.0/index.html) [![License Apache](https://img.shields.io/badge/license-apache-blue.svg)](https://tldrlegal.com/license/apache-license-2.0-(apache-2.0)) -[![Changelog](https://img.shields.io/badge/changelog-6.3.0-blue.svg)](CHANGES.md) +[![Changelog](https://img.shields.io/badge/changelog-6.4.0-blue.svg)](CHANGES.md) [![Circle CI](https://circleci.com/gh/diffplug/spotless/tree/main.svg?style=shield)](https://circleci.com/gh/diffplug/spotless/tree/main) [![Live chat](https://img.shields.io/badge/gitter-chat-brightgreen.svg)](https://gitter.im/diffplug/spotless) @@ -126,10 +126,10 @@ spotless { ``` Spotless consists of a list of formats (in the example above, `misc` and `java`), and each format has: -- a `target` (the files to format), which you set with [`target`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.3.0/com/diffplug/gradle/spotless/FormatExtension.html#target-java.lang.Object...-) and [`targetExclude`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.3.0/com/diffplug/gradle/spotless/FormatExtension.html#targetExclude-java.lang.Object...-) -- a list of `FormatterStep`, which are just `String -> String` functions, such as [`replace`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.3.0/com/diffplug/gradle/spotless/FormatExtension.html#replace-java.lang.String-java.lang.CharSequence-java.lang.CharSequence-), [`replaceRegex`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.3.0/com/diffplug/gradle/spotless/FormatExtension.html#replaceRegex-java.lang.String-java.lang.String-java.lang.String-), [`trimTrailingWhitespace`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.3.0/com/diffplug/gradle/spotless/FormatExtension.html#replace-java.lang.String-java.lang.CharSequence-java.lang.CharSequence-), [`custom`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.3.0/com/diffplug/gradle/spotless/FormatExtension.html#custom-java.lang.String-groovy.lang.Closure-), [`prettier`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.3.0/com/diffplug/gradle/spotless/FormatExtension.html#prettier--), [`eclipseWtp`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.3.0/com/diffplug/gradle/spotless/FormatExtension.html#eclipseWtp-com.diffplug.spotless.extra.wtp.EclipseWtpFormatterStep-), [`licenseHeader`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.3.0/com/diffplug/gradle/spotless/FormatExtension.html#licenseHeader-java.lang.String-java.lang.String-) etc. +- a `target` (the files to format), which you set with [`target`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.4.0/com/diffplug/gradle/spotless/FormatExtension.html#target-java.lang.Object...-) and [`targetExclude`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.4.0/com/diffplug/gradle/spotless/FormatExtension.html#targetExclude-java.lang.Object...-) +- a list of `FormatterStep`, which are just `String -> String` functions, such as [`replace`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.4.0/com/diffplug/gradle/spotless/FormatExtension.html#replace-java.lang.String-java.lang.CharSequence-java.lang.CharSequence-), [`replaceRegex`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.4.0/com/diffplug/gradle/spotless/FormatExtension.html#replaceRegex-java.lang.String-java.lang.String-java.lang.String-), [`trimTrailingWhitespace`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.4.0/com/diffplug/gradle/spotless/FormatExtension.html#replace-java.lang.String-java.lang.CharSequence-java.lang.CharSequence-), [`custom`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.4.0/com/diffplug/gradle/spotless/FormatExtension.html#custom-java.lang.String-groovy.lang.Closure-), [`prettier`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.4.0/com/diffplug/gradle/spotless/FormatExtension.html#prettier--), [`eclipseWtp`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.4.0/com/diffplug/gradle/spotless/FormatExtension.html#eclipseWtp-com.diffplug.spotless.extra.wtp.EclipseWtpFormatterStep-), [`licenseHeader`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.4.0/com/diffplug/gradle/spotless/FormatExtension.html#licenseHeader-java.lang.String-java.lang.String-) etc. -All the generic steps live in [`FormatExtension`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.3.0/com/diffplug/gradle/spotless/FormatExtension.html), and there are many language-specific steps which live in its language-specific subclasses, which are described below. +All the generic steps live in [`FormatExtension`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.4.0/com/diffplug/gradle/spotless/FormatExtension.html), and there are many language-specific steps which live in its language-specific subclasses, which are described below. ### Requirements @@ -141,7 +141,7 @@ If you're stuck on an older version of Gradle, `id 'com.diffplug.gradle.spotless ## Java -`com.diffplug.gradle.spotless.JavaExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.3.0/com/diffplug/gradle/spotless/JavaExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/JavaExtension.java) +`com.diffplug.gradle.spotless.JavaExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.4.0/com/diffplug/gradle/spotless/JavaExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/JavaExtension.java) ```gradle spotless { @@ -248,8 +248,8 @@ spotless { ## Groovy -- `com.diffplug.gradle.spotless.GroovyExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.3.0/com/diffplug/gradle/spotless/GroovyExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/GroovyExtension.java) -- `com.diffplug.gradle.spotless.GroovyGradleExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.3.0/com/diffplug/gradle/spotless/GroovyGradleExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/GroovyGradleExtension.java) +- `com.diffplug.gradle.spotless.GroovyExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.4.0/com/diffplug/gradle/spotless/GroovyExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/GroovyExtension.java) +- `com.diffplug.gradle.spotless.GroovyGradleExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.4.0/com/diffplug/gradle/spotless/GroovyGradleExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/GroovyGradleExtension.java) Configuration for Groovy is similar to [Java](#java), in that it also supports `licenseHeader` and `importOrder`. @@ -300,8 +300,8 @@ Groovy-Eclipse formatting errors/warnings lead per default to a build failure. T ## Kotlin -- `com.diffplug.gradle.spotless.KotlinExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.3.0/com/diffplug/gradle/spotless/KotlinExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/KotlinExtension.java) -- `com.diffplug.gradle.spotless.KotlinGradleExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.3.0/com/diffplug/gradle/spotless/KotlinGradleExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/KotlinGradleExtension.java) +- `com.diffplug.gradle.spotless.KotlinExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.4.0/com/diffplug/gradle/spotless/KotlinExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/KotlinExtension.java) +- `com.diffplug.gradle.spotless.KotlinGradleExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.4.0/com/diffplug/gradle/spotless/KotlinGradleExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/KotlinGradleExtension.java) ```gradle spotless { // if you are using build.gradle.kts, instead of 'spotless {' use: @@ -359,7 +359,7 @@ spotless { ## Scala -`com.diffplug.gradle.spotless.ScalaExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.3.0/com/diffplug/gradle/spotless/ScalaExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/ScalaExtension.java) +`com.diffplug.gradle.spotless.ScalaExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.4.0/com/diffplug/gradle/spotless/ScalaExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/ScalaExtension.java) ```gradle spotless { @@ -391,7 +391,7 @@ spotless { ## C/C++ -`com.diffplug.gradle.spotless.CppExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.3.0/com/diffplug/gradle/spotless/CppExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/CppExtension.java) +`com.diffplug.gradle.spotless.CppExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.4.0/com/diffplug/gradle/spotless/CppExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/CppExtension.java) ```gradle spotless { @@ -423,7 +423,7 @@ spotles { ## Python -`com.diffplug.gradle.spotless.PythonExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.3.0/com/diffplug/gradle/spotless/PythonExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/PythonExtension.java) +`com.diffplug.gradle.spotless.PythonExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.4.0/com/diffplug/gradle/spotless/PythonExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/PythonExtension.java) ```gradle spotless { @@ -457,7 +457,7 @@ black().pathToExe('C:/myuser/.pyenv/versions/3.8.0/scripts/black.exe') ## FreshMark -`com.diffplug.gradle.spotless.FreshMarkExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.3.0/com/diffplug/gradle/spotless/FreshMarkExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/FreshMarkExtension.java) +`com.diffplug.gradle.spotless.FreshMarkExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.4.0/com/diffplug/gradle/spotless/FreshMarkExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/FreshMarkExtension.java) [homepage](https://github.com/diffplug/freshmark). [changelog](https://github.com/diffplug/freshmark/blob/master/CHANGES.md). FreshMark lets you generate markdown in the comments of your markdown. This helps to keep badges and links up-to-date (see the source for this file), and can also be helpful for generating complex tables (see the source for [the parent readme](../README.md)). @@ -478,7 +478,7 @@ spotless { ## Antlr4 -`com.diffplug.gradle.spotless.Antlr4Extension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.3.0/com/diffplug/gradle/spotless/Antlr4Extension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/Antlr4Extension.java) +`com.diffplug.gradle.spotless.Antlr4Extension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.4.0/com/diffplug/gradle/spotless/Antlr4Extension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/Antlr4Extension.java) ```gradle spotless { @@ -503,7 +503,7 @@ antlr4formatter('1.2.1') // version is optional ## SQL -`com.diffplug.gradle.spotless.SqlExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.3.0/com/diffplug/gradle/spotless/SqlExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/SqlExtension.java) +`com.diffplug.gradle.spotless.SqlExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.4.0/com/diffplug/gradle/spotless/SqlExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/SqlExtension.java) ```gradle spotless { @@ -543,7 +543,7 @@ sql.formatter.indent.size=4 ## Typescript -- `com.diffplug.gradle.spotless.TypescriptExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.3.0/com/diffplug/gradle/spotless/TypescriptExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/TypescriptExtension.java) +- `com.diffplug.gradle.spotless.TypescriptExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.4.0/com/diffplug/gradle/spotless/TypescriptExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/TypescriptExtension.java) ```gradle spotless { @@ -586,7 +586,7 @@ For details, see the [npm detection](#npm-detection) and [`.npmrc` detection](#n ## JSON -- `com.diffplug.gradle.spotless.JsonExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.3.0/com/diffplug/gradle/spotless/JsonExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/JsonExtension.java) +- `com.diffplug.gradle.spotless.JsonExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.4.0/com/diffplug/gradle/spotless/JsonExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/JsonExtension.java) ```gradle spotless { @@ -811,7 +811,7 @@ Once a file's license header has a valid year, whether it is a year (`2020`) or * `2017` -> `2017-2020` * `2017-2019` -> `2017-2020` -See the [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.3.0/com/diffplug/gradle/spotless/FormatExtension.LicenseHeaderConfig.html) for a complete listing of options. +See the [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.4.0/com/diffplug/gradle/spotless/FormatExtension.LicenseHeaderConfig.html) for a complete listing of options. @@ -878,9 +878,9 @@ spotless { custom 'lowercase', { str -> str.toLowerCase() } ``` -However, custom rules will disable up-to-date checking and caching, unless you read [this javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.3.0/com/diffplug/gradle/spotless/FormatExtension.html#bumpThisNumberIfACustomStepChanges-int-) and follow its instructions carefully. +However, custom rules will disable up-to-date checking and caching, unless you read [this javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.4.0/com/diffplug/gradle/spotless/FormatExtension.html#bumpThisNumberIfACustomStepChanges-int-) and follow its instructions carefully. -Another option is to create proper `FormatterStep` in your `buildSrc`, and then call [`addStep`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.3.0/com/diffplug/gradle/spotless/FormatExtension.html#addStep-com.diffplug.spotless.FormatterStep-). The contributing guide describes [how to do this](https://github.com/diffplug/spotless/blob/main/CONTRIBUTING.md#how-to-add-a-new-formatterstep). If the step is generally-useful, we hope you'll open a PR to share it! +Another option is to create proper `FormatterStep` in your `buildSrc`, and then call [`addStep`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.4.0/com/diffplug/gradle/spotless/FormatExtension.html#addStep-com.diffplug.spotless.FormatterStep-). The contributing guide describes [how to do this](https://github.com/diffplug/spotless/blob/main/CONTRIBUTING.md#how-to-add-a-new-formatterstep). If the step is generally-useful, we hope you'll open a PR to share it! ```gradle @@ -913,11 +913,11 @@ spotless { format 'foo', com.acme.FooLanguageExtension, { ``` -If you'd like to create a one-off Spotless task outside of the `check`/`apply` framework, see [`FormatExtension.createIndependentApplyTask`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.3.0/com/diffplug/gradle/spotless/FormatExtension.html#createIndependentApplyTask-java.lang.String-). +If you'd like to create a one-off Spotless task outside of the `check`/`apply` framework, see [`FormatExtension.createIndependentApplyTask`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.4.0/com/diffplug/gradle/spotless/FormatExtension.html#createIndependentApplyTask-java.lang.String-). ## Inception (languages within languages within...) -In very rare cases, you might want to format e.g. javascript which is written inside JSP templates, or maybe java within a markdown file, or something wacky like that. You can specify hunks within a file using either open/close tags or a regex with a single capturing group, and then specify rules within it, like so. See [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.3.0/com/diffplug/gradle/spotless/FormatExtension.html#withinBlocks-java.lang.String-java.lang.String-java.lang.String-org.gradle.api.Action-) for more details. +In very rare cases, you might want to format e.g. javascript which is written inside JSP templates, or maybe java within a markdown file, or something wacky like that. You can specify hunks within a file using either open/close tags or a regex with a single capturing group, and then specify rules within it, like so. See [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.4.0/com/diffplug/gradle/spotless/FormatExtension.html#withinBlocks-java.lang.String-java.lang.String-java.lang.String-org.gradle.api.Action-) for more details. ```gradle import com.diffplug.gradle.spotless.JavaExtension From f1281c9127a6bfe6a4558bf8a201ddf9345df4d8 Mon Sep 17 00:00:00 2001 From: circleci Date: Mon, 28 Mar 2022 18:25:41 +0000 Subject: [PATCH 053/757] Published maven/2.22.0 --- plugin-maven/CHANGES.md | 2 ++ plugin-maven/README.md | 4 ++-- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/plugin-maven/CHANGES.md b/plugin-maven/CHANGES.md index 1976b6b46a..508e7f4997 100644 --- a/plugin-maven/CHANGES.md +++ b/plugin-maven/CHANGES.md @@ -3,6 +3,8 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format (starting after version `1.27.0`). ## [Unreleased] + +## [2.22.0] - 2022-03-28 ### Added * Added support for setting custom parameters for Kotlin ktfmt in Maven plugin. ([#1145](https://github.com/diffplug/spotless/pull/1145)) diff --git a/plugin-maven/README.md b/plugin-maven/README.md index 0a77666e45..d6b4d4d605 100644 --- a/plugin-maven/README.md +++ b/plugin-maven/README.md @@ -12,8 +12,8 @@ output = [ ].join('\n'); --> [![Maven central](https://img.shields.io/badge/mavencentral-com.diffplug.spotless%3Aspotless--maven--plugin-blue.svg)](https://search.maven.org/#search%7Cgav%7C1%7Cg%3A%22com.diffplug.spotless%22%20AND%20a%3A%22spotless-maven-plugin%22) -[![Javadoc](https://img.shields.io/badge/javadoc-yes-blue.svg)](https://javadoc.io/doc/com.diffplug.spotless/spotless-maven-plugin/2.21.0/index.html) -[![Changelog](https://img.shields.io/badge/changelog-2.21.0-brightgreen.svg)](CHANGES.md) +[![Javadoc](https://img.shields.io/badge/javadoc-yes-blue.svg)](https://javadoc.io/doc/com.diffplug.spotless/spotless-maven-plugin/2.22.0/index.html) +[![Changelog](https://img.shields.io/badge/changelog-2.22.0-brightgreen.svg)](CHANGES.md) [![Circle CI](https://circleci.com/gh/diffplug/spotless/tree/main.svg?style=shield)](https://circleci.com/gh/diffplug/spotless/tree/main) [![Live chat](https://img.shields.io/badge/gitter-chat-brightgreen.svg)](https://gitter.im/diffplug/spotless) From 66e1a17c01b9e20b03d858648a927e237201ad30 Mon Sep 17 00:00:00 2001 From: DDeg Date: Tue, 29 Mar 2022 11:08:17 +0300 Subject: [PATCH 054/757] Fixed Ktfmt options usage in Gradle Kotlin (kts) scripts. --- .../diffplug/spotless/kotlin/KtfmtStep.java | 16 +++++++ .../gradle/spotless/KotlinExtension.java | 4 +- .../spotless/KotlinGradleExtension.java | 4 +- .../gradle/spotless/KotlinExtensionTest.java | 44 +++++++++++++++++++ 4 files changed, 64 insertions(+), 4 deletions(-) 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 e5e2e57f01..d9feef4c91 100644 --- a/lib/src/main/java/com/diffplug/spotless/kotlin/KtfmtStep.java +++ b/lib/src/main/java/com/diffplug/spotless/kotlin/KtfmtStep.java @@ -97,6 +97,22 @@ public KtfmtFormattingOptions( this.continuationIndent = continuationIndent; this.removeUnusedImport = removeUnusedImport; } + + public void setMaxWidth(int maxWidth) { + this.maxWidth = maxWidth; + } + + public void setBlockIndent(int blockIndent) { + this.blockIndent = blockIndent; + } + + public void setContinuationIndent(int continuationIndent) { + this.continuationIndent = continuationIndent; + } + + public void setRemoveUnusedImport(boolean removeUnusedImport) { + this.removeUnusedImport = removeUnusedImport; + } } /** diff --git a/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/KotlinExtension.java b/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/KotlinExtension.java index 56d925caa3..c68fd9aeea 100644 --- a/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/KotlinExtension.java +++ b/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/KotlinExtension.java @@ -141,9 +141,9 @@ private FormatterStep createStep() { return KtfmtStep.create(version, provisioner(), style, options); } - class ConfigurableStyle { + public class ConfigurableStyle { - void configure(Consumer optionsConfiguration) { + public void configure(Consumer optionsConfiguration) { KtfmtFormattingOptions ktfmtFormattingOptions = new KtfmtFormattingOptions(); optionsConfiguration.accept(ktfmtFormattingOptions); options = ktfmtFormattingOptions; diff --git a/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/KotlinGradleExtension.java b/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/KotlinGradleExtension.java index 1ff2b0c332..4275cd6efe 100644 --- a/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/KotlinGradleExtension.java +++ b/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/KotlinGradleExtension.java @@ -128,9 +128,9 @@ private FormatterStep createStep() { return KtfmtStep.create(version, provisioner(), style, options); } - class ConfigurableStyle { + public class ConfigurableStyle { - void configure(Consumer optionsConfiguration) { + public void configure(Consumer optionsConfiguration) { KtfmtFormattingOptions ktfmtFormattingOptions = new KtfmtFormattingOptions(); optionsConfiguration.accept(ktfmtFormattingOptions); options = ktfmtFormattingOptions; diff --git a/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/KotlinExtensionTest.java b/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/KotlinExtensionTest.java index 3bbd44d63d..4c48c340d2 100644 --- a/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/KotlinExtensionTest.java +++ b/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/KotlinExtensionTest.java @@ -292,6 +292,28 @@ void testWithCustomMaxWidthDefaultStyleKtfmt() throws IOException { assertFile("src/main/kotlin/max-width.kt").sameAsResource("kotlin/ktfmt/max-width.clean"); } + @Test + @EnabledForJreRange(min = JAVA_11) // ktfmt's dependency, google-java-format 1.8 requires a minimum of JRE 11+. + void testWithCustomMaxWidthDefaultStyleKtfmtGradleKts() throws IOException { + setFile("build.gradle.kts").toLines( + "plugins {", + " id(\"org.jetbrains.kotlin.jvm\") version \"1.5.31\"", + " id(\"com.diffplug.spotless\")", + "}", + "repositories { mavenCentral() }", + "spotless {", + " kotlin {", + " ktfmt().configure { options ->", + " options.setMaxWidth(120)", + " }", + " }", + "}"); + + setFile("src/main/kotlin/max-width.kt").toResource("kotlin/ktfmt/max-width.dirty"); + gradleRunner().withArguments("spotlessApply").build(); + assertFile("src/main/kotlin/max-width.kt").sameAsResource("kotlin/ktfmt/max-width.clean"); + } + @Test @EnabledForJreRange(min = JAVA_11) // ktfmt's dependency, google-java-format 1.8 requires a minimum of JRE 11+. void testWithCustomMaxWidthDropboxStyleKtfmt() throws IOException { @@ -313,4 +335,26 @@ void testWithCustomMaxWidthDropboxStyleKtfmt() throws IOException { gradleRunner().withArguments("spotlessApply").build(); assertFile("src/main/kotlin/max-width.kt").sameAsResource("kotlin/ktfmt/max-width-dropbox.clean"); } + + @Test + @EnabledForJreRange(min = JAVA_11) // ktfmt's dependency, google-java-format 1.8 requires a minimum of JRE 11+. + void testWithCustomMaxWidthDropboxStyleKtfmtGradleKts() throws IOException { + setFile("build.gradle.kts").toLines( + "plugins {", + " id(\"org.jetbrains.kotlin.jvm\") version \"1.5.31\"", + " id(\"com.diffplug.spotless\")", + "}", + "repositories { mavenCentral() }", + "spotless {", + " kotlin {", + " ktfmt().dropboxStyle().configure { options ->", + " options.setMaxWidth(120)", + " }", + " }", + "}"); + + setFile("src/main/kotlin/max-width.kt").toResource("kotlin/ktfmt/max-width.dirty"); + gradleRunner().withArguments("spotlessApply").build(); + assertFile("src/main/kotlin/max-width.kt").sameAsResource("kotlin/ktfmt/max-width-dropbox.clean"); + } } From cacdf56787e4e897bc5555508c0d0f81ddd3c35d Mon Sep 17 00:00:00 2001 From: DDeg Date: Tue, 29 Mar 2022 11:12:31 +0300 Subject: [PATCH 055/757] Updated unreleased block in changelog with Ktfmt configuration in kts scripts. --- CHANGES.md | 1 + plugin-gradle/CHANGES.md | 1 + 2 files changed, 2 insertions(+) diff --git a/CHANGES.md b/CHANGES.md index c4f39a815c..8de69d7d77 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -10,6 +10,7 @@ This document is intended for Spotless developers. We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format (starting after version `1.27.0`). ## [Unreleased] +* Fixed access modifiers for setters in KtfmtStep configuration ## [2.24.0] - 2022-03-28 ### Added diff --git a/plugin-gradle/CHANGES.md b/plugin-gradle/CHANGES.md index d991b050a4..520d2a667e 100644 --- a/plugin-gradle/CHANGES.md +++ b/plugin-gradle/CHANGES.md @@ -3,6 +3,7 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format (starting after version `3.27.0`). ## [Unreleased] +* Fixed ktfmt options configuration in Gradle plugin for Gradle Kotlin scripts (kts). ## [6.4.0] - 2022-03-28 ### Added From c0fbe4bbbdaef0af610eb306748b92c592b4e921 Mon Sep 17 00:00:00 2001 From: David Morris Date: Tue, 29 Mar 2022 19:35:28 +0100 Subject: [PATCH 056/757] Fix copy and paste error still referring to maven --- plugin-gradle/README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/plugin-gradle/README.md b/plugin-gradle/README.md index 9b64f6f38a..88273a6474 100644 --- a/plugin-gradle/README.md +++ b/plugin-gradle/README.md @@ -195,7 +195,7 @@ spotless { Using Java 16+ with Google Java Format 1.10.0 [requires additional flags](https://github.com/google/google-java-format/releases/tag/v1.10.0) to the running JDK. These Flags can be provided using the `gradle.properties` file (See [documentation](https://docs.gradle.org/current/userguide/build_environment.html)). -For example the following file under `gradle.properties` will run maven with the required flags: +For example the following file under `gradle.properties` will run gradle with the required flags: ``` org.gradle.jvmargs=--add-exports jdk.compiler/com.sun.tools.javac.api=ALL-UNNAMED \ --add-exports jdk.compiler/com.sun.tools.javac.file=ALL-UNNAMED \ @@ -221,7 +221,7 @@ spotless { Using Java 16+ with Palantir Java Format [requires additional flags](https://github.com/google/google-java-format/releases/tag/v1.10.0) on the running JDK. These Flags can be provided using the `gradle.properties` file (See [documentation](https://docs.gradle.org/current/userguide/build_environment.html)). -For example the following file under `gradle.properties` will run maven with the required flags: +For example the following file under `gradle.properties` will run gradle with the required flags: ``` org.gradle.jvmargs=--add-exports jdk.compiler/com.sun.tools.javac.api=ALL-UNNAMED \ --add-exports jdk.compiler/com.sun.tools.javac.file=ALL-UNNAMED \ From 07c9ac8280e81f54699f97ca313721bb7295688e Mon Sep 17 00:00:00 2001 From: Ned Twigg Date: Tue, 29 Mar 2022 14:18:54 -0700 Subject: [PATCH 057/757] Add `### Fixed` category to the `CHANGES.md` --- CHANGES.md | 1 + plugin-gradle/CHANGES.md | 1 + 2 files changed, 2 insertions(+) diff --git a/CHANGES.md b/CHANGES.md index 8de69d7d77..b749f7113a 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -10,6 +10,7 @@ This document is intended for Spotless developers. We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format (starting after version `1.27.0`). ## [Unreleased] +### Fixed * Fixed access modifiers for setters in KtfmtStep configuration ## [2.24.0] - 2022-03-28 diff --git a/plugin-gradle/CHANGES.md b/plugin-gradle/CHANGES.md index 520d2a667e..63470e6f8c 100644 --- a/plugin-gradle/CHANGES.md +++ b/plugin-gradle/CHANGES.md @@ -3,6 +3,7 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format (starting after version `3.27.0`). ## [Unreleased] +### Fixed * Fixed ktfmt options configuration in Gradle plugin for Gradle Kotlin scripts (kts). ## [6.4.0] - 2022-03-28 From d2e48e9ec5c469195d2cc596f05b38aebf521ef8 Mon Sep 17 00:00:00 2001 From: circleci Date: Wed, 30 Mar 2022 00:44:59 +0000 Subject: [PATCH 058/757] Published lib/2.24.1 --- CHANGES.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/CHANGES.md b/CHANGES.md index b749f7113a..0b2af47551 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -10,6 +10,8 @@ This document is intended for Spotless developers. We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format (starting after version `1.27.0`). ## [Unreleased] + +## [2.24.1] - 2022-03-30 ### Fixed * Fixed access modifiers for setters in KtfmtStep configuration From 75e925f8ee5636e62b50f1c48c013cd8d11be791 Mon Sep 17 00:00:00 2001 From: circleci Date: Wed, 30 Mar 2022 05:02:02 +0000 Subject: [PATCH 059/757] Published gradle/6.4.1 --- plugin-gradle/CHANGES.md | 2 ++ plugin-gradle/README.md | 46 ++++++++++++++++++++-------------------- 2 files changed, 25 insertions(+), 23 deletions(-) diff --git a/plugin-gradle/CHANGES.md b/plugin-gradle/CHANGES.md index 63470e6f8c..67413e9014 100644 --- a/plugin-gradle/CHANGES.md +++ b/plugin-gradle/CHANGES.md @@ -3,6 +3,8 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format (starting after version `3.27.0`). ## [Unreleased] + +## [6.4.1] - 2022-03-30 ### Fixed * Fixed ktfmt options configuration in Gradle plugin for Gradle Kotlin scripts (kts). diff --git a/plugin-gradle/README.md b/plugin-gradle/README.md index 88273a6474..eba973a514 100644 --- a/plugin-gradle/README.md +++ b/plugin-gradle/README.md @@ -18,9 +18,9 @@ output = [ --> [![Gradle plugin](https://img.shields.io/badge/plugins.gradle.org-com.diffplug.spotless-blue.svg)](https://plugins.gradle.org/plugin/com.diffplug.spotless) [![Maven central](https://img.shields.io/badge/mavencentral-yes-blue.svg)](https://search.maven.org/#search%7Cgav%7C1%7Cg%3A%22com.diffplug.spotless%22%20AND%20a%3A%22spotless-plugin-gradle%22) -[![Javadoc](https://img.shields.io/badge/javadoc-yes-blue.svg)](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.4.0/index.html) +[![Javadoc](https://img.shields.io/badge/javadoc-yes-blue.svg)](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.4.1/index.html) [![License Apache](https://img.shields.io/badge/license-apache-blue.svg)](https://tldrlegal.com/license/apache-license-2.0-(apache-2.0)) -[![Changelog](https://img.shields.io/badge/changelog-6.4.0-blue.svg)](CHANGES.md) +[![Changelog](https://img.shields.io/badge/changelog-6.4.1-blue.svg)](CHANGES.md) [![Circle CI](https://circleci.com/gh/diffplug/spotless/tree/main.svg?style=shield)](https://circleci.com/gh/diffplug/spotless/tree/main) [![Live chat](https://img.shields.io/badge/gitter-chat-brightgreen.svg)](https://gitter.im/diffplug/spotless) @@ -126,10 +126,10 @@ spotless { ``` Spotless consists of a list of formats (in the example above, `misc` and `java`), and each format has: -- a `target` (the files to format), which you set with [`target`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.4.0/com/diffplug/gradle/spotless/FormatExtension.html#target-java.lang.Object...-) and [`targetExclude`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.4.0/com/diffplug/gradle/spotless/FormatExtension.html#targetExclude-java.lang.Object...-) -- a list of `FormatterStep`, which are just `String -> String` functions, such as [`replace`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.4.0/com/diffplug/gradle/spotless/FormatExtension.html#replace-java.lang.String-java.lang.CharSequence-java.lang.CharSequence-), [`replaceRegex`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.4.0/com/diffplug/gradle/spotless/FormatExtension.html#replaceRegex-java.lang.String-java.lang.String-java.lang.String-), [`trimTrailingWhitespace`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.4.0/com/diffplug/gradle/spotless/FormatExtension.html#replace-java.lang.String-java.lang.CharSequence-java.lang.CharSequence-), [`custom`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.4.0/com/diffplug/gradle/spotless/FormatExtension.html#custom-java.lang.String-groovy.lang.Closure-), [`prettier`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.4.0/com/diffplug/gradle/spotless/FormatExtension.html#prettier--), [`eclipseWtp`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.4.0/com/diffplug/gradle/spotless/FormatExtension.html#eclipseWtp-com.diffplug.spotless.extra.wtp.EclipseWtpFormatterStep-), [`licenseHeader`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.4.0/com/diffplug/gradle/spotless/FormatExtension.html#licenseHeader-java.lang.String-java.lang.String-) etc. +- a `target` (the files to format), which you set with [`target`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.4.1/com/diffplug/gradle/spotless/FormatExtension.html#target-java.lang.Object...-) and [`targetExclude`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.4.1/com/diffplug/gradle/spotless/FormatExtension.html#targetExclude-java.lang.Object...-) +- a list of `FormatterStep`, which are just `String -> String` functions, such as [`replace`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.4.1/com/diffplug/gradle/spotless/FormatExtension.html#replace-java.lang.String-java.lang.CharSequence-java.lang.CharSequence-), [`replaceRegex`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.4.1/com/diffplug/gradle/spotless/FormatExtension.html#replaceRegex-java.lang.String-java.lang.String-java.lang.String-), [`trimTrailingWhitespace`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.4.1/com/diffplug/gradle/spotless/FormatExtension.html#replace-java.lang.String-java.lang.CharSequence-java.lang.CharSequence-), [`custom`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.4.1/com/diffplug/gradle/spotless/FormatExtension.html#custom-java.lang.String-groovy.lang.Closure-), [`prettier`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.4.1/com/diffplug/gradle/spotless/FormatExtension.html#prettier--), [`eclipseWtp`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.4.1/com/diffplug/gradle/spotless/FormatExtension.html#eclipseWtp-com.diffplug.spotless.extra.wtp.EclipseWtpFormatterStep-), [`licenseHeader`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.4.1/com/diffplug/gradle/spotless/FormatExtension.html#licenseHeader-java.lang.String-java.lang.String-) etc. -All the generic steps live in [`FormatExtension`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.4.0/com/diffplug/gradle/spotless/FormatExtension.html), and there are many language-specific steps which live in its language-specific subclasses, which are described below. +All the generic steps live in [`FormatExtension`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.4.1/com/diffplug/gradle/spotless/FormatExtension.html), and there are many language-specific steps which live in its language-specific subclasses, which are described below. ### Requirements @@ -141,7 +141,7 @@ If you're stuck on an older version of Gradle, `id 'com.diffplug.gradle.spotless ## Java -`com.diffplug.gradle.spotless.JavaExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.4.0/com/diffplug/gradle/spotless/JavaExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/JavaExtension.java) +`com.diffplug.gradle.spotless.JavaExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.4.1/com/diffplug/gradle/spotless/JavaExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/JavaExtension.java) ```gradle spotless { @@ -248,8 +248,8 @@ spotless { ## Groovy -- `com.diffplug.gradle.spotless.GroovyExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.4.0/com/diffplug/gradle/spotless/GroovyExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/GroovyExtension.java) -- `com.diffplug.gradle.spotless.GroovyGradleExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.4.0/com/diffplug/gradle/spotless/GroovyGradleExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/GroovyGradleExtension.java) +- `com.diffplug.gradle.spotless.GroovyExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.4.1/com/diffplug/gradle/spotless/GroovyExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/GroovyExtension.java) +- `com.diffplug.gradle.spotless.GroovyGradleExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.4.1/com/diffplug/gradle/spotless/GroovyGradleExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/GroovyGradleExtension.java) Configuration for Groovy is similar to [Java](#java), in that it also supports `licenseHeader` and `importOrder`. @@ -300,8 +300,8 @@ Groovy-Eclipse formatting errors/warnings lead per default to a build failure. T ## Kotlin -- `com.diffplug.gradle.spotless.KotlinExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.4.0/com/diffplug/gradle/spotless/KotlinExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/KotlinExtension.java) -- `com.diffplug.gradle.spotless.KotlinGradleExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.4.0/com/diffplug/gradle/spotless/KotlinGradleExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/KotlinGradleExtension.java) +- `com.diffplug.gradle.spotless.KotlinExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.4.1/com/diffplug/gradle/spotless/KotlinExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/KotlinExtension.java) +- `com.diffplug.gradle.spotless.KotlinGradleExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.4.1/com/diffplug/gradle/spotless/KotlinGradleExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/KotlinGradleExtension.java) ```gradle spotless { // if you are using build.gradle.kts, instead of 'spotless {' use: @@ -359,7 +359,7 @@ spotless { ## Scala -`com.diffplug.gradle.spotless.ScalaExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.4.0/com/diffplug/gradle/spotless/ScalaExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/ScalaExtension.java) +`com.diffplug.gradle.spotless.ScalaExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.4.1/com/diffplug/gradle/spotless/ScalaExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/ScalaExtension.java) ```gradle spotless { @@ -391,7 +391,7 @@ spotless { ## C/C++ -`com.diffplug.gradle.spotless.CppExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.4.0/com/diffplug/gradle/spotless/CppExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/CppExtension.java) +`com.diffplug.gradle.spotless.CppExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.4.1/com/diffplug/gradle/spotless/CppExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/CppExtension.java) ```gradle spotless { @@ -423,7 +423,7 @@ spotles { ## Python -`com.diffplug.gradle.spotless.PythonExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.4.0/com/diffplug/gradle/spotless/PythonExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/PythonExtension.java) +`com.diffplug.gradle.spotless.PythonExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.4.1/com/diffplug/gradle/spotless/PythonExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/PythonExtension.java) ```gradle spotless { @@ -457,7 +457,7 @@ black().pathToExe('C:/myuser/.pyenv/versions/3.8.0/scripts/black.exe') ## FreshMark -`com.diffplug.gradle.spotless.FreshMarkExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.4.0/com/diffplug/gradle/spotless/FreshMarkExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/FreshMarkExtension.java) +`com.diffplug.gradle.spotless.FreshMarkExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.4.1/com/diffplug/gradle/spotless/FreshMarkExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/FreshMarkExtension.java) [homepage](https://github.com/diffplug/freshmark). [changelog](https://github.com/diffplug/freshmark/blob/master/CHANGES.md). FreshMark lets you generate markdown in the comments of your markdown. This helps to keep badges and links up-to-date (see the source for this file), and can also be helpful for generating complex tables (see the source for [the parent readme](../README.md)). @@ -478,7 +478,7 @@ spotless { ## Antlr4 -`com.diffplug.gradle.spotless.Antlr4Extension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.4.0/com/diffplug/gradle/spotless/Antlr4Extension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/Antlr4Extension.java) +`com.diffplug.gradle.spotless.Antlr4Extension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.4.1/com/diffplug/gradle/spotless/Antlr4Extension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/Antlr4Extension.java) ```gradle spotless { @@ -503,7 +503,7 @@ antlr4formatter('1.2.1') // version is optional ## SQL -`com.diffplug.gradle.spotless.SqlExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.4.0/com/diffplug/gradle/spotless/SqlExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/SqlExtension.java) +`com.diffplug.gradle.spotless.SqlExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.4.1/com/diffplug/gradle/spotless/SqlExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/SqlExtension.java) ```gradle spotless { @@ -543,7 +543,7 @@ sql.formatter.indent.size=4 ## Typescript -- `com.diffplug.gradle.spotless.TypescriptExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.4.0/com/diffplug/gradle/spotless/TypescriptExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/TypescriptExtension.java) +- `com.diffplug.gradle.spotless.TypescriptExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.4.1/com/diffplug/gradle/spotless/TypescriptExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/TypescriptExtension.java) ```gradle spotless { @@ -586,7 +586,7 @@ For details, see the [npm detection](#npm-detection) and [`.npmrc` detection](#n ## JSON -- `com.diffplug.gradle.spotless.JsonExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.4.0/com/diffplug/gradle/spotless/JsonExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/JsonExtension.java) +- `com.diffplug.gradle.spotless.JsonExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.4.1/com/diffplug/gradle/spotless/JsonExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/JsonExtension.java) ```gradle spotless { @@ -811,7 +811,7 @@ Once a file's license header has a valid year, whether it is a year (`2020`) or * `2017` -> `2017-2020` * `2017-2019` -> `2017-2020` -See the [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.4.0/com/diffplug/gradle/spotless/FormatExtension.LicenseHeaderConfig.html) for a complete listing of options. +See the [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.4.1/com/diffplug/gradle/spotless/FormatExtension.LicenseHeaderConfig.html) for a complete listing of options. @@ -878,9 +878,9 @@ spotless { custom 'lowercase', { str -> str.toLowerCase() } ``` -However, custom rules will disable up-to-date checking and caching, unless you read [this javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.4.0/com/diffplug/gradle/spotless/FormatExtension.html#bumpThisNumberIfACustomStepChanges-int-) and follow its instructions carefully. +However, custom rules will disable up-to-date checking and caching, unless you read [this javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.4.1/com/diffplug/gradle/spotless/FormatExtension.html#bumpThisNumberIfACustomStepChanges-int-) and follow its instructions carefully. -Another option is to create proper `FormatterStep` in your `buildSrc`, and then call [`addStep`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.4.0/com/diffplug/gradle/spotless/FormatExtension.html#addStep-com.diffplug.spotless.FormatterStep-). The contributing guide describes [how to do this](https://github.com/diffplug/spotless/blob/main/CONTRIBUTING.md#how-to-add-a-new-formatterstep). If the step is generally-useful, we hope you'll open a PR to share it! +Another option is to create proper `FormatterStep` in your `buildSrc`, and then call [`addStep`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.4.1/com/diffplug/gradle/spotless/FormatExtension.html#addStep-com.diffplug.spotless.FormatterStep-). The contributing guide describes [how to do this](https://github.com/diffplug/spotless/blob/main/CONTRIBUTING.md#how-to-add-a-new-formatterstep). If the step is generally-useful, we hope you'll open a PR to share it! ```gradle @@ -913,11 +913,11 @@ spotless { format 'foo', com.acme.FooLanguageExtension, { ``` -If you'd like to create a one-off Spotless task outside of the `check`/`apply` framework, see [`FormatExtension.createIndependentApplyTask`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.4.0/com/diffplug/gradle/spotless/FormatExtension.html#createIndependentApplyTask-java.lang.String-). +If you'd like to create a one-off Spotless task outside of the `check`/`apply` framework, see [`FormatExtension.createIndependentApplyTask`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.4.1/com/diffplug/gradle/spotless/FormatExtension.html#createIndependentApplyTask-java.lang.String-). ## Inception (languages within languages within...) -In very rare cases, you might want to format e.g. javascript which is written inside JSP templates, or maybe java within a markdown file, or something wacky like that. You can specify hunks within a file using either open/close tags or a regex with a single capturing group, and then specify rules within it, like so. See [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.4.0/com/diffplug/gradle/spotless/FormatExtension.html#withinBlocks-java.lang.String-java.lang.String-java.lang.String-org.gradle.api.Action-) for more details. +In very rare cases, you might want to format e.g. javascript which is written inside JSP templates, or maybe java within a markdown file, or something wacky like that. You can specify hunks within a file using either open/close tags or a regex with a single capturing group, and then specify rules within it, like so. See [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.4.1/com/diffplug/gradle/spotless/FormatExtension.html#withinBlocks-java.lang.String-java.lang.String-java.lang.String-org.gradle.api.Action-) for more details. ```gradle import com.diffplug.gradle.spotless.JavaExtension From 6dfbc93f67d7554c472a1c0fc0cc13355383d774 Mon Sep 17 00:00:00 2001 From: Arul Date: Sat, 2 Apr 2022 21:31:05 +0530 Subject: [PATCH 060/757] Fix #540 - Take care of system and user config --- .../extra/GitAttributesLineEndings.java | 2 +- .../spotless/extra/GitWorkarounds.java | 23 +++++++++++++++---- 2 files changed, 20 insertions(+), 5 deletions(-) diff --git a/lib-extra/src/main/java/com/diffplug/spotless/extra/GitAttributesLineEndings.java b/lib-extra/src/main/java/com/diffplug/spotless/extra/GitAttributesLineEndings.java index 4aab23e142..ae9f0ceec1 100644 --- a/lib-extra/src/main/java/com/diffplug/spotless/extra/GitAttributesLineEndings.java +++ b/lib-extra/src/main/java/com/diffplug/spotless/extra/GitAttributesLineEndings.java @@ -172,7 +172,7 @@ static class RuntimeInit { ////////////////////////// // REPO-SPECIFIC VALUES // ////////////////////////// - RepositorySpecificResolver repositoryResolver = GitWorkarounds.fileRepositoryResolverForProject(projectDir); + RepositorySpecificResolver repositoryResolver = GitWorkarounds.fileRepositoryResolverForProject(projectDir, userConfig); if (repositoryResolver.getGitDir() != null) { workTree = repositoryResolver.getWorkTree(); repoConfig = repositoryResolver.getRepositoryConfig(); diff --git a/lib-extra/src/main/java/com/diffplug/spotless/extra/GitWorkarounds.java b/lib-extra/src/main/java/com/diffplug/spotless/extra/GitWorkarounds.java index a66650b38f..15e8cdb5b8 100644 --- a/lib-extra/src/main/java/com/diffplug/spotless/extra/GitWorkarounds.java +++ b/lib-extra/src/main/java/com/diffplug/spotless/extra/GitWorkarounds.java @@ -50,7 +50,7 @@ private GitWorkarounds() {} * @return the path to the .git directory. */ static @Nullable File getDotGitDir(File projectDir) { - return fileRepositoryResolverForProject(projectDir).getGitDir(); + return fileRepositoryResolverForProject(projectDir, null).getGitDir(); } /** @@ -61,8 +61,8 @@ private GitWorkarounds() {} * @param projectDir the project directory. * @return the builder. */ - static RepositorySpecificResolver fileRepositoryResolverForProject(File projectDir) { - RepositorySpecificResolver repositoryResolver = new RepositorySpecificResolver(); + static RepositorySpecificResolver fileRepositoryResolverForProject(File projectDir, Config baseConfig) { + RepositorySpecificResolver repositoryResolver = new RepositorySpecificResolver(baseConfig); repositoryResolver.findGitDir(projectDir); repositoryResolver.readEnvironment(); if (repositoryResolver.getGitDir() != null || repositoryResolver.getWorkTree() != null) { @@ -94,6 +94,16 @@ static class RepositorySpecificResolver extends FileRepositoryBuilder { private File commonDirectory; + private Config baseConfig; + + public RepositorySpecificResolver() { + this(null); + } + + public RepositorySpecificResolver(Config baseConfig) { + this.baseConfig = baseConfig; + } + /** @return the repository specific configuration. */ Config getRepositoryConfig() { return Errors.rethrow().get(this::getConfig); @@ -108,7 +118,12 @@ Config getRepositoryConfig() { protected Config loadConfig() throws IOException { if (getGitDir() != null) { File path = resolveWithCommonDir(Constants.CONFIG); - FileBasedConfig cfg = new FileBasedConfig(path, safeFS()); + FileBasedConfig cfg = null; + if (this.baseConfig == null) { + cfg = new FileBasedConfig(path, safeFS()); + } else { + cfg = new FileBasedConfig(baseConfig, path, safeFS()); + } try { cfg.load(); From af6a3b388bcc11ad0984fafd9b4bea81b1dd577c Mon Sep 17 00:00:00 2001 From: Arul Date: Mon, 4 Apr 2022 04:23:40 +0530 Subject: [PATCH 061/757] - fixed test cases - updated changelogs --- CHANGES.md | 3 +++ .../diffplug/spotless/extra/GitWorkarounds.java | 15 ++++++++++++++- plugin-gradle/CHANGES.md | 3 +++ plugin-maven/CHANGES.md | 3 +++ 4 files changed, 23 insertions(+), 1 deletion(-) diff --git a/CHANGES.md b/CHANGES.md index 0b2af47551..ea34ee65b3 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -11,6 +11,9 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format ( ## [Unreleased] +### Fixed +* Git user config and system config also included for defaultEndings configuration. ([#540](https://github.com/diffplug/spotless/issues/540)) + ## [2.24.1] - 2022-03-30 ### Fixed * Fixed access modifiers for setters in KtfmtStep configuration diff --git a/lib-extra/src/main/java/com/diffplug/spotless/extra/GitWorkarounds.java b/lib-extra/src/main/java/com/diffplug/spotless/extra/GitWorkarounds.java index 15e8cdb5b8..993c207218 100644 --- a/lib-extra/src/main/java/com/diffplug/spotless/extra/GitWorkarounds.java +++ b/lib-extra/src/main/java/com/diffplug/spotless/extra/GitWorkarounds.java @@ -50,7 +50,7 @@ private GitWorkarounds() {} * @return the path to the .git directory. */ static @Nullable File getDotGitDir(File projectDir) { - return fileRepositoryResolverForProject(projectDir, null).getGitDir(); + return fileRepositoryResolverForProject(projectDir).getGitDir(); } /** @@ -61,6 +61,19 @@ private GitWorkarounds() {} * @param projectDir the project directory. * @return the builder. */ + static RepositorySpecificResolver fileRepositoryResolverForProject(File projectDir) { + return fileRepositoryResolverForProject(projectDir, null); + } + + /** + * Creates a {@link RepositorySpecificResolver} for the given project directory. + * + * This applies a workaround for JGit not supporting worktrees properly. + * + * @param projectDir the project directory. + * @param baseConfig the user and system level git config. + * @return the builder. + */ static RepositorySpecificResolver fileRepositoryResolverForProject(File projectDir, Config baseConfig) { RepositorySpecificResolver repositoryResolver = new RepositorySpecificResolver(baseConfig); repositoryResolver.findGitDir(projectDir); diff --git a/plugin-gradle/CHANGES.md b/plugin-gradle/CHANGES.md index 67413e9014..f420e83323 100644 --- a/plugin-gradle/CHANGES.md +++ b/plugin-gradle/CHANGES.md @@ -4,6 +4,9 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format ( ## [Unreleased] +### Fixed +* Git user config and system config also included for defaultEndings configuration. ([#540](https://github.com/diffplug/spotless/issues/540)) + ## [6.4.1] - 2022-03-30 ### Fixed * Fixed ktfmt options configuration in Gradle plugin for Gradle Kotlin scripts (kts). diff --git a/plugin-maven/CHANGES.md b/plugin-maven/CHANGES.md index 508e7f4997..8863af1825 100644 --- a/plugin-maven/CHANGES.md +++ b/plugin-maven/CHANGES.md @@ -4,6 +4,9 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format ( ## [Unreleased] +### Fixed +* Git user config and system config also included for defaultEndings configuration. ([#540](https://github.com/diffplug/spotless/issues/540)) + ## [2.22.0] - 2022-03-28 ### Added * Added support for setting custom parameters for Kotlin ktfmt in Maven plugin. ([#1145](https://github.com/diffplug/spotless/pull/1145)) From 43dadf5bf025d84b240656cc056d239f79ba4cbe Mon Sep 17 00:00:00 2001 From: Arul Date: Mon, 4 Apr 2022 06:46:46 +0530 Subject: [PATCH 062/757] spotbugs fixes --- .../main/java/com/diffplug/spotless/extra/GitWorkarounds.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib-extra/src/main/java/com/diffplug/spotless/extra/GitWorkarounds.java b/lib-extra/src/main/java/com/diffplug/spotless/extra/GitWorkarounds.java index 993c207218..70f0b9cb99 100644 --- a/lib-extra/src/main/java/com/diffplug/spotless/extra/GitWorkarounds.java +++ b/lib-extra/src/main/java/com/diffplug/spotless/extra/GitWorkarounds.java @@ -74,7 +74,7 @@ static RepositorySpecificResolver fileRepositoryResolverForProject(File projectD * @param baseConfig the user and system level git config. * @return the builder. */ - static RepositorySpecificResolver fileRepositoryResolverForProject(File projectDir, Config baseConfig) { + static RepositorySpecificResolver fileRepositoryResolverForProject(File projectDir, @Nullable Config baseConfig) { RepositorySpecificResolver repositoryResolver = new RepositorySpecificResolver(baseConfig); repositoryResolver.findGitDir(projectDir); repositoryResolver.readEnvironment(); @@ -113,7 +113,7 @@ public RepositorySpecificResolver() { this(null); } - public RepositorySpecificResolver(Config baseConfig) { + public RepositorySpecificResolver(@Nullable Config baseConfig) { this.baseConfig = baseConfig; } From b588a52435836fe57eb8bff2fc212f0be3f42b38 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 4 Apr 2022 12:02:36 +0000 Subject: [PATCH 063/757] Bump com.diffplug.spotless from 6.3.0 to 6.4.1 Bumps com.diffplug.spotless from 6.3.0 to 6.4.1. --- updated-dependencies: - dependency-name: com.diffplug.spotless dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] --- settings.gradle | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/settings.gradle b/settings.gradle index cb626e1b3d..46368b1a38 100644 --- a/settings.gradle +++ b/settings.gradle @@ -1,6 +1,6 @@ pluginManagement { plugins { - id 'com.diffplug.spotless' version '6.3.0' + id 'com.diffplug.spotless' version '6.4.1' // https://plugins.gradle.org/plugin/com.gradle.plugin-publish id 'com.gradle.plugin-publish' version '0.20.0' // https://github.com/gradle-nexus/publish-plugin/releases From 51df54ecdd325faead75d7f8167ba0e39ec303e5 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 4 Apr 2022 12:02:37 +0000 Subject: [PATCH 064/757] Bump com.gradle.plugin-publish from 0.20.0 to 0.21.0 Bumps com.gradle.plugin-publish from 0.20.0 to 0.21.0. --- updated-dependencies: - dependency-name: com.gradle.plugin-publish dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] --- settings.gradle | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/settings.gradle b/settings.gradle index cb626e1b3d..f31878f8dd 100644 --- a/settings.gradle +++ b/settings.gradle @@ -2,7 +2,7 @@ pluginManagement { plugins { id 'com.diffplug.spotless' version '6.3.0' // https://plugins.gradle.org/plugin/com.gradle.plugin-publish - id 'com.gradle.plugin-publish' version '0.20.0' + id 'com.gradle.plugin-publish' version '0.21.0' // https://github.com/gradle-nexus/publish-plugin/releases id 'io.github.gradle-nexus.publish-plugin' version '1.1.0' // https://github.com/spotbugs/spotbugs-gradle-plugin/releases From f638d272ffe943e8497af7e51171cf272e20d624 Mon Sep 17 00:00:00 2001 From: circleci Date: Wed, 6 Apr 2022 16:49:47 +0000 Subject: [PATCH 065/757] Published lib/2.24.2 --- CHANGES.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/CHANGES.md b/CHANGES.md index ea34ee65b3..93c6ac5d34 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -11,6 +11,8 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format ( ## [Unreleased] +## [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)) From 7fd553c371f5c607e158216b63ddce5ae88f5d18 Mon Sep 17 00:00:00 2001 From: circleci Date: Wed, 6 Apr 2022 16:50:52 +0000 Subject: [PATCH 066/757] Published gradle/6.4.2 --- plugin-gradle/CHANGES.md | 2 ++ plugin-gradle/README.md | 46 ++++++++++++++++++++-------------------- 2 files changed, 25 insertions(+), 23 deletions(-) diff --git a/plugin-gradle/CHANGES.md b/plugin-gradle/CHANGES.md index f420e83323..192741c0d3 100644 --- a/plugin-gradle/CHANGES.md +++ b/plugin-gradle/CHANGES.md @@ -4,6 +4,8 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format ( ## [Unreleased] +## [6.4.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/plugin-gradle/README.md b/plugin-gradle/README.md index eba973a514..429b09d5c2 100644 --- a/plugin-gradle/README.md +++ b/plugin-gradle/README.md @@ -18,9 +18,9 @@ output = [ --> [![Gradle plugin](https://img.shields.io/badge/plugins.gradle.org-com.diffplug.spotless-blue.svg)](https://plugins.gradle.org/plugin/com.diffplug.spotless) [![Maven central](https://img.shields.io/badge/mavencentral-yes-blue.svg)](https://search.maven.org/#search%7Cgav%7C1%7Cg%3A%22com.diffplug.spotless%22%20AND%20a%3A%22spotless-plugin-gradle%22) -[![Javadoc](https://img.shields.io/badge/javadoc-yes-blue.svg)](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.4.1/index.html) +[![Javadoc](https://img.shields.io/badge/javadoc-yes-blue.svg)](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.4.2/index.html) [![License Apache](https://img.shields.io/badge/license-apache-blue.svg)](https://tldrlegal.com/license/apache-license-2.0-(apache-2.0)) -[![Changelog](https://img.shields.io/badge/changelog-6.4.1-blue.svg)](CHANGES.md) +[![Changelog](https://img.shields.io/badge/changelog-6.4.2-blue.svg)](CHANGES.md) [![Circle CI](https://circleci.com/gh/diffplug/spotless/tree/main.svg?style=shield)](https://circleci.com/gh/diffplug/spotless/tree/main) [![Live chat](https://img.shields.io/badge/gitter-chat-brightgreen.svg)](https://gitter.im/diffplug/spotless) @@ -126,10 +126,10 @@ spotless { ``` Spotless consists of a list of formats (in the example above, `misc` and `java`), and each format has: -- a `target` (the files to format), which you set with [`target`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.4.1/com/diffplug/gradle/spotless/FormatExtension.html#target-java.lang.Object...-) and [`targetExclude`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.4.1/com/diffplug/gradle/spotless/FormatExtension.html#targetExclude-java.lang.Object...-) -- a list of `FormatterStep`, which are just `String -> String` functions, such as [`replace`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.4.1/com/diffplug/gradle/spotless/FormatExtension.html#replace-java.lang.String-java.lang.CharSequence-java.lang.CharSequence-), [`replaceRegex`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.4.1/com/diffplug/gradle/spotless/FormatExtension.html#replaceRegex-java.lang.String-java.lang.String-java.lang.String-), [`trimTrailingWhitespace`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.4.1/com/diffplug/gradle/spotless/FormatExtension.html#replace-java.lang.String-java.lang.CharSequence-java.lang.CharSequence-), [`custom`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.4.1/com/diffplug/gradle/spotless/FormatExtension.html#custom-java.lang.String-groovy.lang.Closure-), [`prettier`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.4.1/com/diffplug/gradle/spotless/FormatExtension.html#prettier--), [`eclipseWtp`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.4.1/com/diffplug/gradle/spotless/FormatExtension.html#eclipseWtp-com.diffplug.spotless.extra.wtp.EclipseWtpFormatterStep-), [`licenseHeader`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.4.1/com/diffplug/gradle/spotless/FormatExtension.html#licenseHeader-java.lang.String-java.lang.String-) etc. +- a `target` (the files to format), which you set with [`target`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.4.2/com/diffplug/gradle/spotless/FormatExtension.html#target-java.lang.Object...-) and [`targetExclude`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.4.2/com/diffplug/gradle/spotless/FormatExtension.html#targetExclude-java.lang.Object...-) +- a list of `FormatterStep`, which are just `String -> String` functions, such as [`replace`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.4.2/com/diffplug/gradle/spotless/FormatExtension.html#replace-java.lang.String-java.lang.CharSequence-java.lang.CharSequence-), [`replaceRegex`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.4.2/com/diffplug/gradle/spotless/FormatExtension.html#replaceRegex-java.lang.String-java.lang.String-java.lang.String-), [`trimTrailingWhitespace`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.4.2/com/diffplug/gradle/spotless/FormatExtension.html#replace-java.lang.String-java.lang.CharSequence-java.lang.CharSequence-), [`custom`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.4.2/com/diffplug/gradle/spotless/FormatExtension.html#custom-java.lang.String-groovy.lang.Closure-), [`prettier`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.4.2/com/diffplug/gradle/spotless/FormatExtension.html#prettier--), [`eclipseWtp`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.4.2/com/diffplug/gradle/spotless/FormatExtension.html#eclipseWtp-com.diffplug.spotless.extra.wtp.EclipseWtpFormatterStep-), [`licenseHeader`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.4.2/com/diffplug/gradle/spotless/FormatExtension.html#licenseHeader-java.lang.String-java.lang.String-) etc. -All the generic steps live in [`FormatExtension`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.4.1/com/diffplug/gradle/spotless/FormatExtension.html), and there are many language-specific steps which live in its language-specific subclasses, which are described below. +All the generic steps live in [`FormatExtension`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.4.2/com/diffplug/gradle/spotless/FormatExtension.html), and there are many language-specific steps which live in its language-specific subclasses, which are described below. ### Requirements @@ -141,7 +141,7 @@ If you're stuck on an older version of Gradle, `id 'com.diffplug.gradle.spotless ## Java -`com.diffplug.gradle.spotless.JavaExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.4.1/com/diffplug/gradle/spotless/JavaExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/JavaExtension.java) +`com.diffplug.gradle.spotless.JavaExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.4.2/com/diffplug/gradle/spotless/JavaExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/JavaExtension.java) ```gradle spotless { @@ -248,8 +248,8 @@ spotless { ## Groovy -- `com.diffplug.gradle.spotless.GroovyExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.4.1/com/diffplug/gradle/spotless/GroovyExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/GroovyExtension.java) -- `com.diffplug.gradle.spotless.GroovyGradleExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.4.1/com/diffplug/gradle/spotless/GroovyGradleExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/GroovyGradleExtension.java) +- `com.diffplug.gradle.spotless.GroovyExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.4.2/com/diffplug/gradle/spotless/GroovyExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/GroovyExtension.java) +- `com.diffplug.gradle.spotless.GroovyGradleExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.4.2/com/diffplug/gradle/spotless/GroovyGradleExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/GroovyGradleExtension.java) Configuration for Groovy is similar to [Java](#java), in that it also supports `licenseHeader` and `importOrder`. @@ -300,8 +300,8 @@ Groovy-Eclipse formatting errors/warnings lead per default to a build failure. T ## Kotlin -- `com.diffplug.gradle.spotless.KotlinExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.4.1/com/diffplug/gradle/spotless/KotlinExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/KotlinExtension.java) -- `com.diffplug.gradle.spotless.KotlinGradleExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.4.1/com/diffplug/gradle/spotless/KotlinGradleExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/KotlinGradleExtension.java) +- `com.diffplug.gradle.spotless.KotlinExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.4.2/com/diffplug/gradle/spotless/KotlinExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/KotlinExtension.java) +- `com.diffplug.gradle.spotless.KotlinGradleExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.4.2/com/diffplug/gradle/spotless/KotlinGradleExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/KotlinGradleExtension.java) ```gradle spotless { // if you are using build.gradle.kts, instead of 'spotless {' use: @@ -359,7 +359,7 @@ spotless { ## Scala -`com.diffplug.gradle.spotless.ScalaExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.4.1/com/diffplug/gradle/spotless/ScalaExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/ScalaExtension.java) +`com.diffplug.gradle.spotless.ScalaExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.4.2/com/diffplug/gradle/spotless/ScalaExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/ScalaExtension.java) ```gradle spotless { @@ -391,7 +391,7 @@ spotless { ## C/C++ -`com.diffplug.gradle.spotless.CppExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.4.1/com/diffplug/gradle/spotless/CppExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/CppExtension.java) +`com.diffplug.gradle.spotless.CppExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.4.2/com/diffplug/gradle/spotless/CppExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/CppExtension.java) ```gradle spotless { @@ -423,7 +423,7 @@ spotles { ## Python -`com.diffplug.gradle.spotless.PythonExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.4.1/com/diffplug/gradle/spotless/PythonExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/PythonExtension.java) +`com.diffplug.gradle.spotless.PythonExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.4.2/com/diffplug/gradle/spotless/PythonExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/PythonExtension.java) ```gradle spotless { @@ -457,7 +457,7 @@ black().pathToExe('C:/myuser/.pyenv/versions/3.8.0/scripts/black.exe') ## FreshMark -`com.diffplug.gradle.spotless.FreshMarkExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.4.1/com/diffplug/gradle/spotless/FreshMarkExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/FreshMarkExtension.java) +`com.diffplug.gradle.spotless.FreshMarkExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.4.2/com/diffplug/gradle/spotless/FreshMarkExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/FreshMarkExtension.java) [homepage](https://github.com/diffplug/freshmark). [changelog](https://github.com/diffplug/freshmark/blob/master/CHANGES.md). FreshMark lets you generate markdown in the comments of your markdown. This helps to keep badges and links up-to-date (see the source for this file), and can also be helpful for generating complex tables (see the source for [the parent readme](../README.md)). @@ -478,7 +478,7 @@ spotless { ## Antlr4 -`com.diffplug.gradle.spotless.Antlr4Extension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.4.1/com/diffplug/gradle/spotless/Antlr4Extension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/Antlr4Extension.java) +`com.diffplug.gradle.spotless.Antlr4Extension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.4.2/com/diffplug/gradle/spotless/Antlr4Extension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/Antlr4Extension.java) ```gradle spotless { @@ -503,7 +503,7 @@ antlr4formatter('1.2.1') // version is optional ## SQL -`com.diffplug.gradle.spotless.SqlExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.4.1/com/diffplug/gradle/spotless/SqlExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/SqlExtension.java) +`com.diffplug.gradle.spotless.SqlExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.4.2/com/diffplug/gradle/spotless/SqlExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/SqlExtension.java) ```gradle spotless { @@ -543,7 +543,7 @@ sql.formatter.indent.size=4 ## Typescript -- `com.diffplug.gradle.spotless.TypescriptExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.4.1/com/diffplug/gradle/spotless/TypescriptExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/TypescriptExtension.java) +- `com.diffplug.gradle.spotless.TypescriptExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.4.2/com/diffplug/gradle/spotless/TypescriptExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/TypescriptExtension.java) ```gradle spotless { @@ -586,7 +586,7 @@ For details, see the [npm detection](#npm-detection) and [`.npmrc` detection](#n ## JSON -- `com.diffplug.gradle.spotless.JsonExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.4.1/com/diffplug/gradle/spotless/JsonExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/JsonExtension.java) +- `com.diffplug.gradle.spotless.JsonExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.4.2/com/diffplug/gradle/spotless/JsonExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/JsonExtension.java) ```gradle spotless { @@ -811,7 +811,7 @@ Once a file's license header has a valid year, whether it is a year (`2020`) or * `2017` -> `2017-2020` * `2017-2019` -> `2017-2020` -See the [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.4.1/com/diffplug/gradle/spotless/FormatExtension.LicenseHeaderConfig.html) for a complete listing of options. +See the [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.4.2/com/diffplug/gradle/spotless/FormatExtension.LicenseHeaderConfig.html) for a complete listing of options. @@ -878,9 +878,9 @@ spotless { custom 'lowercase', { str -> str.toLowerCase() } ``` -However, custom rules will disable up-to-date checking and caching, unless you read [this javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.4.1/com/diffplug/gradle/spotless/FormatExtension.html#bumpThisNumberIfACustomStepChanges-int-) and follow its instructions carefully. +However, custom rules will disable up-to-date checking and caching, unless you read [this javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.4.2/com/diffplug/gradle/spotless/FormatExtension.html#bumpThisNumberIfACustomStepChanges-int-) and follow its instructions carefully. -Another option is to create proper `FormatterStep` in your `buildSrc`, and then call [`addStep`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.4.1/com/diffplug/gradle/spotless/FormatExtension.html#addStep-com.diffplug.spotless.FormatterStep-). The contributing guide describes [how to do this](https://github.com/diffplug/spotless/blob/main/CONTRIBUTING.md#how-to-add-a-new-formatterstep). If the step is generally-useful, we hope you'll open a PR to share it! +Another option is to create proper `FormatterStep` in your `buildSrc`, and then call [`addStep`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.4.2/com/diffplug/gradle/spotless/FormatExtension.html#addStep-com.diffplug.spotless.FormatterStep-). The contributing guide describes [how to do this](https://github.com/diffplug/spotless/blob/main/CONTRIBUTING.md#how-to-add-a-new-formatterstep). If the step is generally-useful, we hope you'll open a PR to share it! ```gradle @@ -913,11 +913,11 @@ spotless { format 'foo', com.acme.FooLanguageExtension, { ``` -If you'd like to create a one-off Spotless task outside of the `check`/`apply` framework, see [`FormatExtension.createIndependentApplyTask`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.4.1/com/diffplug/gradle/spotless/FormatExtension.html#createIndependentApplyTask-java.lang.String-). +If you'd like to create a one-off Spotless task outside of the `check`/`apply` framework, see [`FormatExtension.createIndependentApplyTask`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.4.2/com/diffplug/gradle/spotless/FormatExtension.html#createIndependentApplyTask-java.lang.String-). ## Inception (languages within languages within...) -In very rare cases, you might want to format e.g. javascript which is written inside JSP templates, or maybe java within a markdown file, or something wacky like that. You can specify hunks within a file using either open/close tags or a regex with a single capturing group, and then specify rules within it, like so. See [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.4.1/com/diffplug/gradle/spotless/FormatExtension.html#withinBlocks-java.lang.String-java.lang.String-java.lang.String-org.gradle.api.Action-) for more details. +In very rare cases, you might want to format e.g. javascript which is written inside JSP templates, or maybe java within a markdown file, or something wacky like that. You can specify hunks within a file using either open/close tags or a regex with a single capturing group, and then specify rules within it, like so. See [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.4.2/com/diffplug/gradle/spotless/FormatExtension.html#withinBlocks-java.lang.String-java.lang.String-java.lang.String-org.gradle.api.Action-) for more details. ```gradle import com.diffplug.gradle.spotless.JavaExtension From bd0db272bd7a0eba4507e4ab49d297995cb2f2ee Mon Sep 17 00:00:00 2001 From: circleci Date: Wed, 6 Apr 2022 16:52:41 +0000 Subject: [PATCH 067/757] Published maven/2.22.1 --- plugin-maven/CHANGES.md | 2 ++ plugin-maven/README.md | 4 ++-- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/plugin-maven/CHANGES.md b/plugin-maven/CHANGES.md index 8863af1825..7ffcf0cc81 100644 --- a/plugin-maven/CHANGES.md +++ b/plugin-maven/CHANGES.md @@ -4,6 +4,8 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format ( ## [Unreleased] +## [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)) diff --git a/plugin-maven/README.md b/plugin-maven/README.md index d6b4d4d605..e0daabecd9 100644 --- a/plugin-maven/README.md +++ b/plugin-maven/README.md @@ -12,8 +12,8 @@ output = [ ].join('\n'); --> [![Maven central](https://img.shields.io/badge/mavencentral-com.diffplug.spotless%3Aspotless--maven--plugin-blue.svg)](https://search.maven.org/#search%7Cgav%7C1%7Cg%3A%22com.diffplug.spotless%22%20AND%20a%3A%22spotless-maven-plugin%22) -[![Javadoc](https://img.shields.io/badge/javadoc-yes-blue.svg)](https://javadoc.io/doc/com.diffplug.spotless/spotless-maven-plugin/2.22.0/index.html) -[![Changelog](https://img.shields.io/badge/changelog-2.22.0-brightgreen.svg)](CHANGES.md) +[![Javadoc](https://img.shields.io/badge/javadoc-yes-blue.svg)](https://javadoc.io/doc/com.diffplug.spotless/spotless-maven-plugin/2.22.1/index.html) +[![Changelog](https://img.shields.io/badge/changelog-2.22.1-brightgreen.svg)](CHANGES.md) [![Circle CI](https://circleci.com/gh/diffplug/spotless/tree/main.svg?style=shield)](https://circleci.com/gh/diffplug/spotless/tree/main) [![Live chat](https://img.shields.io/badge/gitter-chat-brightgreen.svg)](https://gitter.im/diffplug/spotless) From d5a97920f61f11f02ad058b978402500e9cad17e Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 11 Apr 2022 12:06:37 +0000 Subject: [PATCH 068/757] Bump com.diffplug.spotless from 6.4.1 to 6.4.2 Bumps com.diffplug.spotless from 6.4.1 to 6.4.2. --- updated-dependencies: - dependency-name: com.diffplug.spotless dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] --- settings.gradle | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/settings.gradle b/settings.gradle index bb8e7f77fe..f34dfc742c 100644 --- a/settings.gradle +++ b/settings.gradle @@ -1,6 +1,6 @@ pluginManagement { plugins { - id 'com.diffplug.spotless' version '6.4.1' + id 'com.diffplug.spotless' version '6.4.2' // https://plugins.gradle.org/plugin/com.gradle.plugin-publish id 'com.gradle.plugin-publish' version '0.21.0' // https://github.com/gradle-nexus/publish-plugin/releases From aefad7a939f231956c0743303ca38ff77223f9ab Mon Sep 17 00:00:00 2001 From: Alex Vanyo Date: Sun, 17 Apr 2022 19:23:29 -0700 Subject: [PATCH 069/757] Add option to use ktlint experimental ruleset --- lib/build.gradle | 1 + .../glue/ktlint/KtlintFormatterFunc.java | 12 ++++-- .../diffplug/spotless/kotlin/KtLintStep.java | 38 ++++++++++++------- plugin-gradle/README.md | 6 ++- .../gradle/spotless/KotlinExtension.java | 17 +++++++-- .../spotless/KotlinGradleExtension.java | 17 +++++++-- .../gradle/spotless/KotlinExtensionTest.java | 36 ++++++++++++++++++ .../spotless/KotlinGradleExtensionTest.java | 36 ++++++++++++++++++ .../kotlin/ktlint/experimental.clean | 7 ++++ .../kotlin/ktlint/experimental.dirty | 6 +++ 10 files changed, 150 insertions(+), 26 deletions(-) create mode 100644 testlib/src/main/resources/kotlin/ktlint/experimental.clean create mode 100644 testlib/src/main/resources/kotlin/ktlint/experimental.dirty diff --git a/lib/build.gradle b/lib/build.gradle index a585d8328e..db9473d65e 100644 --- a/lib/build.gradle +++ b/lib/build.gradle @@ -47,6 +47,7 @@ dependencies { String VER_KTLINT='0.43.2' ktlintCompileOnly "com.pinterest:ktlint:$VER_KTLINT" ktlintCompileOnly "com.pinterest.ktlint:ktlint-core:$VER_KTLINT" + ktlintCompileOnly "com.pinterest.ktlint:ktlint-ruleset-experimental:$VER_KTLINT" ktlintCompileOnly "com.pinterest.ktlint:ktlint-ruleset-standard:$VER_KTLINT" // used for markdown formatting diff --git a/lib/src/ktlint/java/com/diffplug/spotless/glue/ktlint/KtlintFormatterFunc.java b/lib/src/ktlint/java/com/diffplug/spotless/glue/ktlint/KtlintFormatterFunc.java index 061224a819..b3ef570180 100644 --- a/lib/src/ktlint/java/com/diffplug/spotless/glue/ktlint/KtlintFormatterFunc.java +++ b/lib/src/ktlint/java/com/diffplug/spotless/glue/ktlint/KtlintFormatterFunc.java @@ -16,7 +16,7 @@ package com.diffplug.spotless.glue.ktlint; import java.io.File; -import java.util.Collections; +import java.util.ArrayList; import java.util.List; import java.util.Map; @@ -24,6 +24,7 @@ import com.pinterest.ktlint.core.KtLint.Params; import com.pinterest.ktlint.core.LintError; import com.pinterest.ktlint.core.RuleSet; +import com.pinterest.ktlint.ruleset.experimental.ExperimentalRuleSetProvider; import com.pinterest.ktlint.ruleset.standard.StandardRuleSetProvider; import com.diffplug.spotless.FormatterFunc; @@ -38,8 +39,13 @@ public class KtlintFormatterFunc implements FormatterFunc.NeedsFile { private final Function2 formatterCallback; private final boolean isScript; - public KtlintFormatterFunc(boolean isScript, Map userData) { - rulesets = Collections.singletonList(new StandardRuleSetProvider().get()); + public KtlintFormatterFunc(boolean isScript, boolean useExperimental, Map userData) { + rulesets = new ArrayList<>(); + rulesets.add(new StandardRuleSetProvider().get()); + + if (useExperimental) { + rulesets.add(new ExperimentalRuleSetProvider().get()); + } this.userData = userData; formatterCallback = new FormatterCallback(); this.isScript = isScript; diff --git a/lib/src/main/java/com/diffplug/spotless/kotlin/KtLintStep.java b/lib/src/main/java/com/diffplug/spotless/kotlin/KtLintStep.java index 1db75a4e1f..711495c409 100644 --- a/lib/src/main/java/com/diffplug/spotless/kotlin/KtLintStep.java +++ b/lib/src/main/java/com/diffplug/spotless/kotlin/KtLintStep.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. @@ -21,6 +21,7 @@ import java.lang.reflect.InvocationTargetException; import java.lang.reflect.Method; import java.lang.reflect.Proxy; +import java.util.ArrayList; import java.util.Collections; import java.util.Map; import java.util.Objects; @@ -49,26 +50,26 @@ public static FormatterStep create(Provisioner provisioner) { } public static FormatterStep create(String version, Provisioner provisioner) { - return create(version, provisioner, Collections.emptyMap()); + return create(version, provisioner, false, Collections.emptyMap()); } - public static FormatterStep create(String version, Provisioner provisioner, Map userData) { - return create(version, provisioner, false, userData); + public static FormatterStep create(String version, Provisioner provisioner, boolean useExperimental, Map userData) { + return create(version, provisioner, false, useExperimental, userData); } public static FormatterStep createForScript(String version, Provisioner provisioner) { - return create(version, provisioner, true, Collections.emptyMap()); + return create(version, provisioner, true, false, Collections.emptyMap()); } - public static FormatterStep createForScript(String version, Provisioner provisioner, Map userData) { - return create(version, provisioner, true, userData); + public static FormatterStep createForScript(String version, Provisioner provisioner, boolean useExperimental, Map userData) { + return create(version, provisioner, true, useExperimental, userData); } - private static FormatterStep create(String version, Provisioner provisioner, boolean isScript, Map userData) { + private static FormatterStep create(String version, Provisioner provisioner, boolean isScript, boolean useExperimental, Map userData) { Objects.requireNonNull(version, "version"); Objects.requireNonNull(provisioner, "provisioner"); return FormatterStep.createLazy(NAME, - () -> new State(version, provisioner, isScript, userData), + () -> new State(version, provisioner, isScript, useExperimental, userData), State::createFormat); } @@ -84,10 +85,12 @@ static final class State implements Serializable { private final String pkg; /** The jar that contains the formatter. */ final JarState jarState; + private final boolean useExperimental; private final TreeMap userData; private final boolean useParams; - State(String version, Provisioner provisioner, boolean isScript, Map userData) throws IOException { + State(String version, Provisioner provisioner, boolean isScript, boolean useExperimental, Map userData) throws IOException { + this.useExperimental = useExperimental; this.userData = new TreeMap<>(userData); String coordinate; if (BadSemver.version(version) < BadSemver.version(0, 32)) { @@ -105,17 +108,26 @@ static final class State implements Serializable { FormatterFunc createFormat() throws Exception { if (useParams) { Class formatterFunc = jarState.getClassLoader().loadClass("com.diffplug.spotless.glue.ktlint.KtlintFormatterFunc"); - Constructor constructor = formatterFunc.getConstructor(boolean.class, Map.class); - return (FormatterFunc.NeedsFile) constructor.newInstance(isScript, userData); + Constructor constructor = formatterFunc.getConstructor(boolean.class, boolean.class, Map.class); + return (FormatterFunc.NeedsFile) constructor.newInstance(isScript, useExperimental, userData); } ClassLoader classLoader = jarState.getClassLoader(); // String KtLint::format(String input, Iterable rules, Function2 errorCallback) + ArrayList ruleSets = new ArrayList<>(); + // first, we get the standard rules Class standardRuleSetProviderClass = classLoader.loadClass(pkg + ".ktlint.ruleset.standard.StandardRuleSetProvider"); Object standardRuleSet = standardRuleSetProviderClass.getMethod("get").invoke(standardRuleSetProviderClass.newInstance()); - Iterable ruleSets = Collections.singletonList(standardRuleSet); + ruleSets.add(standardRuleSet); + + // second, we get the experimental rules if desired + if (useExperimental) { + Class experimentalRuleSetProviderClass = classLoader.loadClass(pkg + ".ktlint.ruleset.experimental.ExperimentalRuleSetProvider"); + Object experimentalRuleSet = experimentalRuleSetProviderClass.getMethod("get").invoke(experimentalRuleSetProviderClass.newInstance()); + ruleSets.add(experimentalRuleSet); + } // next, we create an error callback which throws an assertion error when the format is bad Class function2Interface = classLoader.loadClass("kotlin.jvm.functions.Function2"); diff --git a/plugin-gradle/README.md b/plugin-gradle/README.md index 429b09d5c2..c8de7946bc 100644 --- a/plugin-gradle/README.md +++ b/plugin-gradle/README.md @@ -340,8 +340,10 @@ spotless { ```kotlin spotless { kotlin { - // version and userData are both optional - ktlint('0.43.2').userData(mapOf('indent_size' to '2', 'continuation_indent_size' to '2')) + // version, setUseExperimental and userData are all optional + ktlint('0.43.2') + .setUseExperimental(true) + .userData(mapOf('indent_size' to '2', 'continuation_indent_size' to '2')) ``` ### diktat diff --git a/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/KotlinExtension.java b/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/KotlinExtension.java index c68fd9aeea..f7cb7a20f0 100644 --- a/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/KotlinExtension.java +++ b/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/KotlinExtension.java @@ -59,7 +59,7 @@ public LicenseHeaderConfig licenseHeaderFile(Object licenseHeaderFile) { /** Adds the specified version of ktlint. */ public KotlinFormatExtension ktlint(String version) { Objects.requireNonNull(version); - return new KotlinFormatExtension(version, Collections.emptyMap()); + return new KotlinFormatExtension(version, false, Collections.emptyMap()); } public KotlinFormatExtension ktlint() { @@ -69,23 +69,32 @@ public KotlinFormatExtension ktlint() { public class KotlinFormatExtension { private final String version; + private boolean useExperimental; private Map userData; - KotlinFormatExtension(String version, Map config) { + KotlinFormatExtension(String version, boolean useExperimental, Map config) { this.version = version; + this.useExperimental = useExperimental; this.userData = config; addStep(createStep()); } - public void userData(Map userData) { + public KotlinFormatExtension setUseExperimental(boolean useExperimental) { + this.useExperimental = useExperimental; + replaceStep(createStep()); + return this; + } + + public KotlinFormatExtension userData(Map userData) { // Copy the map to a sorted map because up-to-date checking is based on binary-equals of the serialized // representation. this.userData = userData; replaceStep(createStep()); + return this; } private FormatterStep createStep() { - return KtLintStep.create(version, provisioner(), userData); + return KtLintStep.create(version, provisioner(), useExperimental, userData); } } diff --git a/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/KotlinGradleExtension.java b/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/KotlinGradleExtension.java index 4275cd6efe..7a98c211bc 100644 --- a/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/KotlinGradleExtension.java +++ b/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/KotlinGradleExtension.java @@ -45,7 +45,7 @@ public KotlinGradleExtension(SpotlessExtension spotless) { /** Adds the specified version of ktlint. */ public KotlinFormatExtension ktlint(String version) { Objects.requireNonNull(version, "version"); - return new KotlinFormatExtension(version, Collections.emptyMap()); + return new KotlinFormatExtension(version, false, Collections.emptyMap()); } public KotlinFormatExtension ktlint() { @@ -55,23 +55,32 @@ public KotlinFormatExtension ktlint() { public class KotlinFormatExtension { private final String version; + private boolean useExperimental; private Map userData; - KotlinFormatExtension(String version, Map config) { + KotlinFormatExtension(String version, boolean useExperimental, Map config) { this.version = version; + this.useExperimental = useExperimental; this.userData = config; addStep(createStep()); } - public void userData(Map userData) { + public KotlinFormatExtension setUseExperimental(boolean useExperimental) { + this.useExperimental = useExperimental; + replaceStep(createStep()); + return this; + } + + public KotlinFormatExtension userData(Map userData) { // Copy the map to a sorted map because up-to-date checking is based on binary-equals of the serialized // representation. this.userData = ImmutableSortedMap.copyOf(userData); replaceStep(createStep()); + return this; } private FormatterStep createStep() { - return KtLintStep.createForScript(version, provisioner(), userData); + return KtLintStep.createForScript(version, provisioner(), useExperimental, userData); } } diff --git a/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/KotlinExtensionTest.java b/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/KotlinExtensionTest.java index 4c48c340d2..ff34ff1dc2 100644 --- a/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/KotlinExtensionTest.java +++ b/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/KotlinExtensionTest.java @@ -139,6 +139,42 @@ void testWithIndentation() throws IOException { assertThat(result.getOutput()).contains("Unexpected indentation (4) (it should be 6)"); } + @Test + void withExperimental() throws IOException { + setFile("build.gradle").toLines( + "plugins {", + " id 'org.jetbrains.kotlin.jvm' version '1.5.31'", + " id 'com.diffplug.spotless'", + "}", + "repositories { mavenCentral() }", + "spotless {", + " kotlin {", + " ktlint().setUseExperimental(true)", + " }", + "}"); + setFile("src/main/kotlin/experimental.kt").toResource("kotlin/ktlint/experimental.dirty"); + gradleRunner().withArguments("spotlessApply").build(); + assertFile("src/main/kotlin/experimental.kt").sameAsResource("kotlin/ktlint/experimental.clean"); + } + + @Test + void withExperimental_0_32() throws IOException { + setFile("build.gradle").toLines( + "plugins {", + " id 'org.jetbrains.kotlin.jvm' version '1.5.31'", + " id 'com.diffplug.spotless'", + "}", + "repositories { mavenCentral() }", + "spotless {", + " kotlin {", + " ktlint('0.32.0').setUseExperimental(true)", + " }", + "}"); + setFile("src/main/kotlin/basic.kt").toResource("kotlin/ktlint/basic.dirty"); + gradleRunner().withArguments("spotlessApply").build(); + assertFile("src/main/kotlin/basic.kt").sameAsResource("kotlin/ktlint/basic.clean"); + } + @Test void testWithHeader() throws IOException { setFile("build.gradle").toLines( diff --git a/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/KotlinGradleExtensionTest.java b/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/KotlinGradleExtensionTest.java index c68de0d7e7..4d39a31d1a 100644 --- a/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/KotlinGradleExtensionTest.java +++ b/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/KotlinGradleExtensionTest.java @@ -128,6 +128,42 @@ void indentStep() throws IOException { gradleRunner().withArguments("spotlessCheck").buildAndFail(); } + @Test + void withExperimental() throws IOException { + setFile("build.gradle").toLines( + "plugins {", + " id 'org.jetbrains.kotlin.jvm' version '1.5.31'", + " id 'com.diffplug.spotless'", + "}", + "repositories { mavenCentral() }", + "spotless {", + " kotlin {", + " ktlint().setUseExperimental(true)", + " }", + "}"); + setFile("src/main/kotlin/experimental.kt").toResource("kotlin/ktlint/experimental.dirty"); + gradleRunner().withArguments("spotlessApply").build(); + assertFile("src/main/kotlin/experimental.kt").sameAsResource("kotlin/ktlint/experimental.clean"); + } + + @Test + void withExperimental_0_32() throws IOException { + setFile("build.gradle").toLines( + "plugins {", + " id 'org.jetbrains.kotlin.jvm' version '1.5.31'", + " id 'com.diffplug.spotless'", + "}", + "repositories { mavenCentral() }", + "spotless {", + " kotlin {", + " ktlint('0.32.0').setUseExperimental(true)", + " }", + "}"); + setFile("src/main/kotlin/basic.kt").toResource("kotlin/ktlint/basic.dirty"); + gradleRunner().withArguments("spotlessApply").build(); + assertFile("src/main/kotlin/basic.kt").sameAsResource("kotlin/ktlint/basic.clean"); + } + @Test @EnabledForJreRange(min = JAVA_11) // ktfmt's dependency, google-java-format 1.8 requires a minimum of JRE 11+. void integration_ktfmt() throws IOException { diff --git a/testlib/src/main/resources/kotlin/ktlint/experimental.clean b/testlib/src/main/resources/kotlin/ktlint/experimental.clean new file mode 100644 index 0000000000..50c41243a8 --- /dev/null +++ b/testlib/src/main/resources/kotlin/ktlint/experimental.clean @@ -0,0 +1,7 @@ +fun main() { + if (false) { + println("false") + } else { + println("true") + } +} diff --git a/testlib/src/main/resources/kotlin/ktlint/experimental.dirty b/testlib/src/main/resources/kotlin/ktlint/experimental.dirty new file mode 100644 index 0000000000..cdb6e6bdf5 --- /dev/null +++ b/testlib/src/main/resources/kotlin/ktlint/experimental.dirty @@ -0,0 +1,6 @@ +fun main() { + if (false) + println("false") + else + println("true") +} From a209bc1cadbe08b72fcbc3b3059ee9cbd3d6c75a Mon Sep 17 00:00:00 2001 From: Alex Vanyo Date: Sun, 17 Apr 2022 19:35:32 -0700 Subject: [PATCH 070/757] Update changelogs --- CHANGES.md | 2 ++ plugin-gradle/CHANGES.md | 2 ++ 2 files changed, 4 insertions(+) diff --git a/CHANGES.md b/CHANGES.md index 93c6ac5d34..c86189bad4 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -10,6 +10,8 @@ This document is intended for Spotless developers. We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format (starting after version `1.27.0`). ## [Unreleased] +### Added +* Added support for enabling ktlint experimental ruleset. ([#1145](https://github.com/diffplug/spotless/pull/1168)) ## [2.24.2] - 2022-04-06 diff --git a/plugin-gradle/CHANGES.md b/plugin-gradle/CHANGES.md index 192741c0d3..1862e3ddee 100644 --- a/plugin-gradle/CHANGES.md +++ b/plugin-gradle/CHANGES.md @@ -3,6 +3,8 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format (starting after version `3.27.0`). ## [Unreleased] +### Added +* Added support for enabling ktlint experimental ruleset. ([#1145](https://github.com/diffplug/spotless/pull/1168)) ## [6.4.2] - 2022-04-06 From ad44fc51d5c0b4c7a7369f64e07669263df116b9 Mon Sep 17 00:00:00 2001 From: Alex Vanyo Date: Sun, 17 Apr 2022 20:11:33 -0700 Subject: [PATCH 071/757] Add test for verifying rule under test is still experimental --- .../gradle/spotless/KotlinExtensionTest.java | 25 +++++++++++++++++++ .../spotless/KotlinGradleExtensionTest.java | 25 +++++++++++++++++++ 2 files changed, 50 insertions(+) diff --git a/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/KotlinExtensionTest.java b/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/KotlinExtensionTest.java index ff34ff1dc2..f10be630ef 100644 --- a/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/KotlinExtensionTest.java +++ b/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/KotlinExtensionTest.java @@ -175,6 +175,31 @@ void withExperimental_0_32() throws IOException { assertFile("src/main/kotlin/basic.kt").sameAsResource("kotlin/ktlint/basic.clean"); } + /** + * Check that the sample used to verify the experimental ruleset is untouched by the default ruleset, to verify + * that enabling the experimental ruleset is actually doing something. + * + * If this test fails, it's likely that the experimental rule being used as a test graduated into the standard + * ruleset, and therefore a new experimental rule should be used to verify functionality. + */ + @Test + void experimentalSampleUnchangedWithDefaultRuleset() throws IOException { + setFile("build.gradle").toLines( + "plugins {", + " id 'org.jetbrains.kotlin.jvm' version '1.5.31'", + " id 'com.diffplug.spotless'", + "}", + "repositories { mavenCentral() }", + "spotless {", + " kotlin {", + " ktlint()", + " }", + "}"); + setFile("src/main/kotlin/experimental.kt").toResource("kotlin/ktlint/experimental.dirty"); + gradleRunner().withArguments("spotlessApply").build(); + assertFile("src/main/kotlin/experimental.kt").sameAsResource("kotlin/ktlint/experimental.dirty"); + } + @Test void testWithHeader() throws IOException { setFile("build.gradle").toLines( diff --git a/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/KotlinGradleExtensionTest.java b/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/KotlinGradleExtensionTest.java index 4d39a31d1a..d1ffff0718 100644 --- a/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/KotlinGradleExtensionTest.java +++ b/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/KotlinGradleExtensionTest.java @@ -164,6 +164,31 @@ void withExperimental_0_32() throws IOException { assertFile("src/main/kotlin/basic.kt").sameAsResource("kotlin/ktlint/basic.clean"); } + /** + * Check that the sample used to verify the experimental ruleset is untouched by the default ruleset, to verify + * that enabling the experimental ruleset is actually doing something. + * + * If this test fails, it's likely that the experimental rule being used as a test graduated into the standard + * ruleset, and therefore a new experimental rule should be used to verify functionality. + */ + @Test + void experimentalSampleUnchangedWithDefaultRuleset() throws IOException { + setFile("build.gradle").toLines( + "plugins {", + " id 'org.jetbrains.kotlin.jvm' version '1.5.31'", + " id 'com.diffplug.spotless'", + "}", + "repositories { mavenCentral() }", + "spotless {", + " kotlin {", + " ktlint()", + " }", + "}"); + setFile("src/main/kotlin/experimental.kt").toResource("kotlin/ktlint/experimental.dirty"); + gradleRunner().withArguments("spotlessApply").build(); + assertFile("src/main/kotlin/experimental.kt").sameAsResource("kotlin/ktlint/experimental.dirty"); + } + @Test @EnabledForJreRange(min = JAVA_11) // ktfmt's dependency, google-java-format 1.8 requires a minimum of JRE 11+. void integration_ktfmt() throws IOException { From 0d8816c9fd137ebc8f08aaa0c9bf6a4c814fe6cf Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 18 Apr 2022 12:06:33 +0000 Subject: [PATCH 072/757] Bump org.gradle.test-retry from 1.3.1 to 1.3.2 Bumps org.gradle.test-retry from 1.3.1 to 1.3.2. --- updated-dependencies: - dependency-name: org.gradle.test-retry dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] --- settings.gradle | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/settings.gradle b/settings.gradle index bb8e7f77fe..6af1681cd2 100644 --- a/settings.gradle +++ b/settings.gradle @@ -12,7 +12,7 @@ pluginManagement { // https://github.com/diffplug/goomph/blob/main/CHANGES.md id 'com.diffplug.p2.asmaven' version '3.27.0' // DO NOT UPDATE, see https://github.com/diffplug/spotless/pull/874 // https://github.com/gradle/test-retry-gradle-plugin/releases - id 'org.gradle.test-retry' version '1.3.1' + id 'org.gradle.test-retry' version '1.3.2' // https://github.com/radarsh/gradle-test-logger-plugin/blob/develop/CHANGELOG.md id 'com.adarshr.test-logger' version '3.2.0' } From 1e85ee425454258c1af22ecab3d156fbc8f30808 Mon Sep 17 00:00:00 2001 From: Dawid Weiss Date: Thu, 21 Apr 2022 09:04:46 +0200 Subject: [PATCH 073/757] #1175 Added a runToFixMessage property to customize the run-to-fix message in spotlessCheck task --- plugin-gradle/CHANGES.md | 2 ++ .../diffplug/gradle/spotless/SpotlessCheck.java | 10 ++++++++-- .../gradle/spotless/DiffMessageFormatterTest.java | 15 ++++++++++++++- 3 files changed, 24 insertions(+), 3 deletions(-) diff --git a/plugin-gradle/CHANGES.md b/plugin-gradle/CHANGES.md index 192741c0d3..3a66016979 100644 --- a/plugin-gradle/CHANGES.md +++ b/plugin-gradle/CHANGES.md @@ -3,6 +3,8 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format (starting after version `3.27.0`). ## [Unreleased] +### Added +* Added a runToFixMessage property to customize the run-to-fix message in spotlessCheck task ([#1175](https://github.com/diffplug/spotless/issues/1175)). ## [6.4.2] - 2022-04-06 diff --git a/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/SpotlessCheck.java b/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/SpotlessCheck.java index 55336a00ad..d0e27d60bf 100644 --- a/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/SpotlessCheck.java +++ b/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/SpotlessCheck.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. @@ -29,6 +29,7 @@ import org.gradle.api.file.FileVisitDetails; import org.gradle.api.file.FileVisitor; import org.gradle.api.provider.Property; +import org.gradle.api.tasks.Input; import org.gradle.api.tasks.Internal; import org.gradle.api.tasks.TaskAction; @@ -40,6 +41,9 @@ public abstract class SpotlessCheck extends SpotlessTaskService.ClientTask { @Internal public abstract Property getEncoding(); + @Input + public abstract Property getRunToFixMessage(); + public void performActionTest() throws IOException { performAction(true); } @@ -98,7 +102,7 @@ public void visitFile(FileVisitDetails fileVisitDetails) { if (!problemFiles.isEmpty()) { Collections.sort(problemFiles); throw new GradleException(DiffMessageFormatter.builder() - .runToFix("Run '" + calculateGradleCommand() + " " + getTaskPathPrefix() + "spotlessApply' to fix these violations.") + .runToFix(getRunToFixMessage().get()) .formatterFolder( getProjectDir().get().getAsFile().toPath(), getSpotlessOutDirectory().get().toPath(), @@ -117,6 +121,8 @@ void init(SpotlessTaskImpl impl) { super.init(impl); getProjectPath().set(getProject().getPath()); getEncoding().set(impl.getEncoding()); + getRunToFixMessage().convention( + "Run '" + calculateGradleCommand() + " " + getTaskPathPrefix() + "spotlessApply' to fix these violations."); } private String getTaskPathPrefix() { diff --git a/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/DiffMessageFormatterTest.java b/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/DiffMessageFormatterTest.java index c46d398bf8..ef72043a47 100644 --- a/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/DiffMessageFormatterTest.java +++ b/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/DiffMessageFormatterTest.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. @@ -135,6 +135,19 @@ void lineEndingProblem() throws Exception { " +C\\n"); } + @Test + void customRunToFixMessage() throws Exception { + Bundle task = create(setFile("testFile").toContent("A\r\nB\r\nC\r\n")); + String customMessage = "Formatting issues detected, please read automatic-code-formatting.txt and correct."; + task.check.getRunToFixMessage().set(customMessage); + + String msg = task.checkFailureMsg(); + + String firstLine = "The following files had format violations:\n"; + String lastLine = "\n" + customMessage; + Assertions.assertThat(msg).startsWith(firstLine).endsWith(lastLine); + } + @Test void whitespaceProblem() throws Exception { Bundle spotless = create(setFile("testFile").toContent("A \nB\t\nC \n")); From 247939d28c3576f8cf202833d8321272d75c8ff8 Mon Sep 17 00:00:00 2001 From: Ned Twigg Date: Thu, 21 Apr 2022 17:01:01 -0700 Subject: [PATCH 074/757] Remove unused piece from build.gradle (to trigger CI). --- build.gradle | 4 ---- 1 file changed, 4 deletions(-) diff --git a/build.gradle b/build.gradle index 7c3a3dede9..16136e07ec 100644 --- a/build.gradle +++ b/build.gradle @@ -19,7 +19,3 @@ spotless { endWithNewline() } } - -static Class spotBugsTaskType() { - return com.github.spotbugs.snom.SpotBugsTask -} From 78dc7a6490469ea0d80d748cda2283db69795217 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Fri, 22 Apr 2022 00:58:21 +0000 Subject: [PATCH 075/757] Bump ktfmt from 0.34 to 0.35 Bumps [ktfmt](https://github.com/facebookincubator/ktfmt) from 0.34 to 0.35. - [Release notes](https://github.com/facebookincubator/ktfmt/releases) - [Commits](https://github.com/facebookincubator/ktfmt/compare/v0.34...v0.35) --- updated-dependencies: - dependency-name: com.facebook:ktfmt dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] --- lib/build.gradle | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/build.gradle b/lib/build.gradle index db9473d65e..28cd8e7221 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") { From 533f1888ebdf289afd51fd53af92a04dfcccd7d8 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Fri, 22 Apr 2022 00:58:48 +0000 Subject: [PATCH 076/757] Bump VER_KTLINT from 0.43.2 to 0.45.2 Bumps `VER_KTLINT` from 0.43.2 to 0.45.2. Updates `ktlint` from 0.43.2 to 0.45.2 - [Release notes](https://github.com/pinterest/ktlint/releases) - [Changelog](https://github.com/pinterest/ktlint/blob/master/CHANGELOG.md) - [Commits](https://github.com/pinterest/ktlint/compare/0.43.2...0.45.2) Updates `ktlint-core` from 0.43.2 to 0.45.2 - [Release notes](https://github.com/pinterest/ktlint/releases) - [Changelog](https://github.com/pinterest/ktlint/blob/master/CHANGELOG.md) - [Commits](https://github.com/pinterest/ktlint/compare/0.43.2...0.45.2) Updates `ktlint-ruleset-experimental` from 0.43.2 to 0.45.2 - [Release notes](https://github.com/pinterest/ktlint/releases) - [Changelog](https://github.com/pinterest/ktlint/blob/master/CHANGELOG.md) - [Commits](https://github.com/pinterest/ktlint/compare/0.43.2...0.45.2) Updates `ktlint-ruleset-standard` from 0.43.2 to 0.45.2 - [Release notes](https://github.com/pinterest/ktlint/releases) - [Changelog](https://github.com/pinterest/ktlint/blob/master/CHANGELOG.md) - [Commits](https://github.com/pinterest/ktlint/compare/0.43.2...0.45.2) --- updated-dependencies: - dependency-name: com.pinterest:ktlint dependency-type: direct:production update-type: version-update:semver-minor - dependency-name: com.pinterest.ktlint:ktlint-core dependency-type: direct:production update-type: version-update:semver-minor - dependency-name: com.pinterest.ktlint:ktlint-ruleset-experimental dependency-type: direct:production update-type: version-update:semver-minor - dependency-name: com.pinterest.ktlint:ktlint-ruleset-standard dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] --- lib/build.gradle | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/build.gradle b/lib/build.gradle index db9473d65e..d620a3dd8d 100644 --- a/lib/build.gradle +++ b/lib/build.gradle @@ -44,7 +44,7 @@ dependencies { } } - String VER_KTLINT='0.43.2' + String VER_KTLINT='0.45.2' ktlintCompileOnly "com.pinterest:ktlint:$VER_KTLINT" ktlintCompileOnly "com.pinterest.ktlint:ktlint-core:$VER_KTLINT" ktlintCompileOnly "com.pinterest.ktlint:ktlint-ruleset-experimental:$VER_KTLINT" From 3d0a1032397423c46fb46efe1916f2cbb987cfa5 Mon Sep 17 00:00:00 2001 From: Ned Twigg Date: Thu, 21 Apr 2022 22:20:50 -0700 Subject: [PATCH 077/757] Fix the regex for Python black to work for old and new versions. --- lib/src/main/java/com/diffplug/spotless/python/BlackStep.java | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) 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..bd8095c495 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; @@ -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(); From 800967a6fbecc2888983e64a66f9e3462714e154 Mon Sep 17 00:00:00 2001 From: Ned Twigg Date: Thu, 21 Apr 2022 22:22:49 -0700 Subject: [PATCH 078/757] Bump default black version to latest: `19.10b0` -> `22.3.0` --- lib/src/main/java/com/diffplug/spotless/python/BlackStep.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 bd8095c495..3f4a8837b6 100644 --- a/lib/src/main/java/com/diffplug/spotless/python/BlackStep.java +++ b/lib/src/main/java/com/diffplug/spotless/python/BlackStep.java @@ -37,7 +37,7 @@ public static String name() { } public static String defaultVersion() { - return "19.10b0"; + return "22.3.0"; } private final String version; From f1c7f3968a78174bd04021ed34af3d225c6c3b71 Mon Sep 17 00:00:00 2001 From: Ned Twigg Date: Thu, 21 Apr 2022 22:29:57 -0700 Subject: [PATCH 079/757] Update changelogs. --- CHANGES.md | 3 ++- plugin-gradle/CHANGES.md | 2 ++ plugin-maven/CHANGES.md | 3 ++- 3 files changed, 6 insertions(+), 2 deletions(-) diff --git a/CHANGES.md b/CHANGES.md index c86189bad4..24ee694274 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -12,9 +12,10 @@ 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, and bumped default version to latest (`19.10b0` -> `22.3.0`) ([#1170](https://github.com/diffplug/spotless/issues/1170)) ## [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/plugin-gradle/CHANGES.md b/plugin-gradle/CHANGES.md index b986f4b839..04d1ccf10f 100644 --- a/plugin-gradle/CHANGES.md +++ b/plugin-gradle/CHANGES.md @@ -6,6 +6,8 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format ( ### Added * 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, and bumped default version to latest (`19.10b0` -> `22.3.0`) ([#1170](https://github.com/diffplug/spotless/issues/1170)) ## [6.4.2] - 2022-04-06 ### Fixed diff --git a/plugin-maven/CHANGES.md b/plugin-maven/CHANGES.md index 7ffcf0cc81..fb5dea1c6d 100644 --- a/plugin-maven/CHANGES.md +++ b/plugin-maven/CHANGES.md @@ -3,9 +3,10 @@ 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, and bumped default version to latest (`19.10b0` -> `22.3.0`) ([#1170](https://github.com/diffplug/spotless/issues/1170)) ## [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)) From 297c8f7e2d3e512ce70eb0a44b5acbf1bfe401a3 Mon Sep 17 00:00:00 2001 From: Ned Twigg Date: Thu, 21 Apr 2022 22:57:43 -0700 Subject: [PATCH 080/757] Apply `base` eagerly. --- .../gradle/spotless/FormatExtension.java | 5 ++-- .../spotless/SpotlessExtensionImpl.java | 16 +++++------ .../gradle/spotless/SpotlessPlugin.java | 27 +++---------------- 3 files changed, 12 insertions(+), 36 deletions(-) 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/SpotlessExtensionImpl.java b/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/SpotlessExtensionImpl.java index 24fa7b54b0..8a03d5b2ef 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)); } }); } @@ -61,8 +56,9 @@ protected void createFormatTasks(String name, FormatExtension formatExtension) { TaskProvider spotlessTask = tasks.register(taskName, SpotlessTaskImpl.class, task -> { task.init(getRegisterDependenciesTask().getTaskService()); 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 @@ -103,8 +99,8 @@ 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.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) { From 5856e8a0459001a98c743edcb9bff68ebf6213ab Mon Sep 17 00:00:00 2001 From: Ned Twigg Date: Thu, 21 Apr 2022 23:00:11 -0700 Subject: [PATCH 081/757] Update changelog. --- plugin-gradle/CHANGES.md | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/plugin-gradle/CHANGES.md b/plugin-gradle/CHANGES.md index 04d1ccf10f..97bd49309d 100644 --- a/plugin-gradle/CHANGES.md +++ b/plugin-gradle/CHANGES.md @@ -4,10 +4,14 @@ 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, and bumped default version to latest (`19.10b0` -> `22.3.0`) ([#1170](https://github.com/diffplug/spotless/issues/1170)) +### Changed +- 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 From b6d71e75434f3b5d6199295adc4373cf9168b865 Mon Sep 17 00:00:00 2001 From: Ned Twigg Date: Thu, 21 Apr 2022 23:15:18 -0700 Subject: [PATCH 082/757] All tasks are now part of the `verification` group. --- .../java/com/diffplug/gradle/spotless/SpotlessExtension.java | 3 ++- .../com/diffplug/gradle/spotless/SpotlessExtensionImpl.java | 4 ++++ 2 files changed, 6 insertions(+), 1 deletion(-) 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 8a03d5b2ef..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 @@ -55,6 +55,7 @@ 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); @@ -73,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); }); @@ -87,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); @@ -99,6 +102,7 @@ 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); }); rootDiagnoseTask.configure(task -> task.dependsOn(diagnoseTask)); From c4748d8d1ce86d3e0e3d9d2dbe8c600fe846d10e Mon Sep 17 00:00:00 2001 From: Ned Twigg Date: Thu, 21 Apr 2022 23:17:50 -0700 Subject: [PATCH 083/757] Update changelog. --- plugin-gradle/CHANGES.md | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/plugin-gradle/CHANGES.md b/plugin-gradle/CHANGES.md index 97bd49309d..32e20c8732 100644 --- a/plugin-gradle/CHANGES.md +++ b/plugin-gradle/CHANGES.md @@ -4,12 +4,13 @@ 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, and bumped default version to latest (`19.10b0` -> `22.3.0`) ([#1170](https://github.com/diffplug/spotless/issues/1170)) +* Fixed support for Python Black's new version reporting, and bumped default version to latest (`19.10b0` -> `22.3.0`). ([#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)) ### Changed -- 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 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. From 2bd6d403690b669cc6e7a134c6ba3235eab98c94 Mon Sep 17 00:00:00 2001 From: Ned Twigg Date: Thu, 21 Apr 2022 23:37:15 -0700 Subject: [PATCH 084/757] Fix encoding error messages when generated on Java 8. --- .../com/diffplug/spotless/EncodingErrorMsg.java | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) 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; + } } From 40df41df55564ff19ba2a5c49c72cbf3fb130994 Mon Sep 17 00:00:00 2001 From: Ned Twigg Date: Thu, 21 Apr 2022 23:39:44 -0700 Subject: [PATCH 085/757] Update changelog. --- CHANGES.md | 3 ++- plugin-gradle/CHANGES.md | 1 + plugin-maven/CHANGES.md | 3 ++- 3 files changed, 5 insertions(+), 2 deletions(-) diff --git a/CHANGES.md b/CHANGES.md index 24ee694274..554f1688e4 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -13,7 +13,8 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format ( ### 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, and bumped default version to latest (`19.10b0` -> `22.3.0`) ([#1170](https://github.com/diffplug/spotless/issues/1170)) +* Fixed support for Python Black's new version reporting, and bumped default version to latest (`19.10b0` -> `22.3.0`). ([#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)) ## [2.24.2] - 2022-04-06 ### Fixed diff --git a/plugin-gradle/CHANGES.md b/plugin-gradle/CHANGES.md index 32e20c8732..3e54fe34e1 100644 --- a/plugin-gradle/CHANGES.md +++ b/plugin-gradle/CHANGES.md @@ -9,6 +9,7 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format ( ### Fixed * Fixed support for Python Black's new version reporting, and bumped default version to latest (`19.10b0` -> `22.3.0`). ([#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 - 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). diff --git a/plugin-maven/CHANGES.md b/plugin-maven/CHANGES.md index fb5dea1c6d..8097b5a368 100644 --- a/plugin-maven/CHANGES.md +++ b/plugin-maven/CHANGES.md @@ -4,7 +4,8 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format ( ## [Unreleased] ### Fixed -* Fixed support for Python Black's new version reporting, and bumped default version to latest (`19.10b0` -> `22.3.0`) ([#1170](https://github.com/diffplug/spotless/issues/1170)) +* Fixed support for Python Black's new version reporting, and bumped default version to latest (`19.10b0` -> `22.3.0`). ([#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)) ## [2.22.1] - 2022-04-06 ### Fixed From b0b19360e8e357a4ce84dbe922ad6145e5bd8196 Mon Sep 17 00:00:00 2001 From: Ned Twigg Date: Thu, 21 Apr 2022 23:55:10 -0700 Subject: [PATCH 086/757] Bump our default KtfmtStep version too. --- lib/src/main/java/com/diffplug/spotless/kotlin/KtfmtStep.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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:"; From 6f520e68266499d206bbe27dbc228e45504faecd Mon Sep 17 00:00:00 2001 From: Ned Twigg Date: Fri, 22 Apr 2022 00:11:37 -0700 Subject: [PATCH 087/757] Bump KtLintStep default version `0.43.2` -> `0.45.2`. --- lib/src/main/java/com/diffplug/spotless/kotlin/KtLintStep.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/src/main/java/com/diffplug/spotless/kotlin/KtLintStep.java b/lib/src/main/java/com/diffplug/spotless/kotlin/KtLintStep.java index 711495c409..de099b04d1 100644 --- a/lib/src/main/java/com/diffplug/spotless/kotlin/KtLintStep.java +++ b/lib/src/main/java/com/diffplug/spotless/kotlin/KtLintStep.java @@ -38,7 +38,7 @@ public class KtLintStep { // prevent direct instantiation private KtLintStep() {} - private static final String DEFAULT_VERSION = "0.43.2"; + private static final String DEFAULT_VERSION = "0.45.2"; static final String NAME = "ktlint"; static final String PACKAGE_PRE_0_32 = "com.github.shyiko"; static final String PACKAGE = "com.pinterest"; From cb1a37786e1797f6cc719d1343f4c480f7ca155d Mon Sep 17 00:00:00 2001 From: Ned Twigg Date: Fri, 22 Apr 2022 00:17:07 -0700 Subject: [PATCH 088/757] Bump changelogs. --- CHANGES.md | 5 ++++- plugin-gradle/CHANGES.md | 10 ++++++---- plugin-maven/CHANGES.md | 5 ++++- 3 files changed, 14 insertions(+), 6 deletions(-) diff --git a/CHANGES.md b/CHANGES.md index 554f1688e4..cfd8526468 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -13,8 +13,11 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format ( ### 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, and bumped default version to latest (`19.10b0` -> `22.3.0`). ([#1170](https://github.com/diffplug/spotless/issues/1170)) +* 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 diff --git a/plugin-gradle/CHANGES.md b/plugin-gradle/CHANGES.md index 3e54fe34e1..b412a58a59 100644 --- a/plugin-gradle/CHANGES.md +++ b/plugin-gradle/CHANGES.md @@ -7,13 +7,15 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format ( * 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, and bumped default version to latest (`19.10b0` -> `22.3.0`). ([#1170](https://github.com/diffplug/spotless/issues/1170)) +* 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 -- 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. +* 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-maven/CHANGES.md b/plugin-maven/CHANGES.md index 8097b5a368..e4831da6c1 100644 --- a/plugin-maven/CHANGES.md +++ b/plugin-maven/CHANGES.md @@ -4,8 +4,11 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format ( ## [Unreleased] ### Fixed -* Fixed support for Python Black's new version reporting, and bumped default version to latest (`19.10b0` -> `22.3.0`). ([#1170](https://github.com/diffplug/spotless/issues/1170)) +* 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 From b708850eb0114a91fdb153a96602bcea566373c1 Mon Sep 17 00:00:00 2001 From: Ned Twigg Date: Fri, 22 Apr 2022 00:23:13 -0700 Subject: [PATCH 089/757] Bump changelogs. --- CHANGES.md | 5 +++-- plugin-gradle/CHANGES.md | 5 +++-- plugin-maven/CHANGES.md | 5 +++-- 3 files changed, 9 insertions(+), 6 deletions(-) diff --git a/CHANGES.md b/CHANGES.md index cfd8526468..b36380d4fb 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -16,8 +16,9 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format ( * 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)) +* 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)) +* Bump default `ktlint` version to latest `0.43.2` -> `0.45.2`. ([#1177](https://github.com/diffplug/spotless/pull/1177)) ## [2.24.2] - 2022-04-06 ### Fixed diff --git a/plugin-gradle/CHANGES.md b/plugin-gradle/CHANGES.md index b412a58a59..1685156c8a 100644 --- a/plugin-gradle/CHANGES.md +++ b/plugin-gradle/CHANGES.md @@ -11,11 +11,12 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format ( * 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. +* 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)) +* Bump default `ktlint` version to latest `0.43.2` -> `0.45.2`. ([#1177](https://github.com/diffplug/spotless/pull/1177)) ## [6.4.2] - 2022-04-06 ### Fixed diff --git a/plugin-maven/CHANGES.md b/plugin-maven/CHANGES.md index e4831da6c1..7c7a8b214b 100644 --- a/plugin-maven/CHANGES.md +++ b/plugin-maven/CHANGES.md @@ -7,8 +7,9 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format ( * 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)) +* 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)) +* Bump default `ktlint` version to latest `0.43.2` -> `0.45.2`. ([#1177](https://github.com/diffplug/spotless/pull/1177)) ## [2.22.1] - 2022-04-06 ### Fixed From 9e1bfc8be55f54bb3411ea2aa9bee887a0b96898 Mon Sep 17 00:00:00 2001 From: Ned Twigg Date: Fri, 22 Apr 2022 07:17:34 -0700 Subject: [PATCH 090/757] Fix test assertion. --- .../java/com/diffplug/spotless/kotlin/KtLintStepTest.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/testlib/src/test/java/com/diffplug/spotless/kotlin/KtLintStepTest.java b/testlib/src/test/java/com/diffplug/spotless/kotlin/KtLintStepTest.java index a3548c58b6..ecca9e6cc6 100644 --- a/testlib/src/test/java/com/diffplug/spotless/kotlin/KtLintStepTest.java +++ b/testlib/src/test/java/com/diffplug/spotless/kotlin/KtLintStepTest.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. @@ -36,7 +36,7 @@ void behavior() throws Exception { .testResource("kotlin/ktlint/basic.dirty", "kotlin/ktlint/basic.clean") .testResourceException("kotlin/ktlint/unsolvable.dirty", assertion -> { assertion.isInstanceOf(AssertionError.class); - assertion.hasMessage("Error on line: 1, column: 2\n" + + assertion.hasMessage("Error on line: 1, column: 1\n" + "Wildcard import"); }); } From 1a26b6b55cb49705d5d1c1d7cad045807bfb9394 Mon Sep 17 00:00:00 2001 From: Ned Twigg Date: Fri, 22 Apr 2022 07:38:05 -0700 Subject: [PATCH 091/757] Small change to trigger CI. --- .gitignore | 1 - 1 file changed, 1 deletion(-) diff --git a/.gitignore b/.gitignore index 8b95e1b44f..1a95765d37 100644 --- a/.gitignore +++ b/.gitignore @@ -23,7 +23,6 @@ gradle-app.setting _ext/*/gradle/dependency-locks/*.lockfile ### Eclipse ### -*.pydevproject .metadata .gradle bin/ From 42a6361f78c92beee4ddc9b1871036520ea47747 Mon Sep 17 00:00:00 2001 From: circleci Date: Fri, 22 Apr 2022 23:27:11 +0000 Subject: [PATCH 092/757] Published lib/2.25.0 --- CHANGES.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/CHANGES.md b/CHANGES.md index b36380d4fb..90eccfbd45 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -10,6 +10,8 @@ This document is intended for Spotless developers. We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format (starting after version `1.27.0`). ## [Unreleased] + +## [2.25.0] - 2022-04-22 ### Added * Added support for enabling ktlint experimental ruleset. ([#1145](https://github.com/diffplug/spotless/pull/1168)) ### Fixed From 7df18d26801f7e3fc22c133def6f53e9ac308285 Mon Sep 17 00:00:00 2001 From: circleci Date: Fri, 22 Apr 2022 23:27:56 +0000 Subject: [PATCH 093/757] Published gradle/6.5.0 --- plugin-gradle/CHANGES.md | 2 ++ plugin-gradle/README.md | 46 ++++++++++++++++++++-------------------- 2 files changed, 25 insertions(+), 23 deletions(-) diff --git a/plugin-gradle/CHANGES.md b/plugin-gradle/CHANGES.md index 1685156c8a..a85e28ed75 100644 --- a/plugin-gradle/CHANGES.md +++ b/plugin-gradle/CHANGES.md @@ -3,6 +3,8 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format (starting after version `3.27.0`). ## [Unreleased] + +## [6.5.0] - 2022-04-22 ### Added * 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)) diff --git a/plugin-gradle/README.md b/plugin-gradle/README.md index c8de7946bc..02baa6e654 100644 --- a/plugin-gradle/README.md +++ b/plugin-gradle/README.md @@ -18,9 +18,9 @@ output = [ --> [![Gradle plugin](https://img.shields.io/badge/plugins.gradle.org-com.diffplug.spotless-blue.svg)](https://plugins.gradle.org/plugin/com.diffplug.spotless) [![Maven central](https://img.shields.io/badge/mavencentral-yes-blue.svg)](https://search.maven.org/#search%7Cgav%7C1%7Cg%3A%22com.diffplug.spotless%22%20AND%20a%3A%22spotless-plugin-gradle%22) -[![Javadoc](https://img.shields.io/badge/javadoc-yes-blue.svg)](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.4.2/index.html) +[![Javadoc](https://img.shields.io/badge/javadoc-yes-blue.svg)](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.5.0/index.html) [![License Apache](https://img.shields.io/badge/license-apache-blue.svg)](https://tldrlegal.com/license/apache-license-2.0-(apache-2.0)) -[![Changelog](https://img.shields.io/badge/changelog-6.4.2-blue.svg)](CHANGES.md) +[![Changelog](https://img.shields.io/badge/changelog-6.5.0-blue.svg)](CHANGES.md) [![Circle CI](https://circleci.com/gh/diffplug/spotless/tree/main.svg?style=shield)](https://circleci.com/gh/diffplug/spotless/tree/main) [![Live chat](https://img.shields.io/badge/gitter-chat-brightgreen.svg)](https://gitter.im/diffplug/spotless) @@ -126,10 +126,10 @@ spotless { ``` Spotless consists of a list of formats (in the example above, `misc` and `java`), and each format has: -- a `target` (the files to format), which you set with [`target`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.4.2/com/diffplug/gradle/spotless/FormatExtension.html#target-java.lang.Object...-) and [`targetExclude`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.4.2/com/diffplug/gradle/spotless/FormatExtension.html#targetExclude-java.lang.Object...-) -- a list of `FormatterStep`, which are just `String -> String` functions, such as [`replace`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.4.2/com/diffplug/gradle/spotless/FormatExtension.html#replace-java.lang.String-java.lang.CharSequence-java.lang.CharSequence-), [`replaceRegex`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.4.2/com/diffplug/gradle/spotless/FormatExtension.html#replaceRegex-java.lang.String-java.lang.String-java.lang.String-), [`trimTrailingWhitespace`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.4.2/com/diffplug/gradle/spotless/FormatExtension.html#replace-java.lang.String-java.lang.CharSequence-java.lang.CharSequence-), [`custom`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.4.2/com/diffplug/gradle/spotless/FormatExtension.html#custom-java.lang.String-groovy.lang.Closure-), [`prettier`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.4.2/com/diffplug/gradle/spotless/FormatExtension.html#prettier--), [`eclipseWtp`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.4.2/com/diffplug/gradle/spotless/FormatExtension.html#eclipseWtp-com.diffplug.spotless.extra.wtp.EclipseWtpFormatterStep-), [`licenseHeader`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.4.2/com/diffplug/gradle/spotless/FormatExtension.html#licenseHeader-java.lang.String-java.lang.String-) etc. +- a `target` (the files to format), which you set with [`target`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.5.0/com/diffplug/gradle/spotless/FormatExtension.html#target-java.lang.Object...-) and [`targetExclude`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.5.0/com/diffplug/gradle/spotless/FormatExtension.html#targetExclude-java.lang.Object...-) +- a list of `FormatterStep`, which are just `String -> String` functions, such as [`replace`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.5.0/com/diffplug/gradle/spotless/FormatExtension.html#replace-java.lang.String-java.lang.CharSequence-java.lang.CharSequence-), [`replaceRegex`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.5.0/com/diffplug/gradle/spotless/FormatExtension.html#replaceRegex-java.lang.String-java.lang.String-java.lang.String-), [`trimTrailingWhitespace`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.5.0/com/diffplug/gradle/spotless/FormatExtension.html#replace-java.lang.String-java.lang.CharSequence-java.lang.CharSequence-), [`custom`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.5.0/com/diffplug/gradle/spotless/FormatExtension.html#custom-java.lang.String-groovy.lang.Closure-), [`prettier`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.5.0/com/diffplug/gradle/spotless/FormatExtension.html#prettier--), [`eclipseWtp`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.5.0/com/diffplug/gradle/spotless/FormatExtension.html#eclipseWtp-com.diffplug.spotless.extra.wtp.EclipseWtpFormatterStep-), [`licenseHeader`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.5.0/com/diffplug/gradle/spotless/FormatExtension.html#licenseHeader-java.lang.String-java.lang.String-) etc. -All the generic steps live in [`FormatExtension`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.4.2/com/diffplug/gradle/spotless/FormatExtension.html), and there are many language-specific steps which live in its language-specific subclasses, which are described below. +All the generic steps live in [`FormatExtension`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.5.0/com/diffplug/gradle/spotless/FormatExtension.html), and there are many language-specific steps which live in its language-specific subclasses, which are described below. ### Requirements @@ -141,7 +141,7 @@ If you're stuck on an older version of Gradle, `id 'com.diffplug.gradle.spotless ## Java -`com.diffplug.gradle.spotless.JavaExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.4.2/com/diffplug/gradle/spotless/JavaExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/JavaExtension.java) +`com.diffplug.gradle.spotless.JavaExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.5.0/com/diffplug/gradle/spotless/JavaExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/JavaExtension.java) ```gradle spotless { @@ -248,8 +248,8 @@ spotless { ## Groovy -- `com.diffplug.gradle.spotless.GroovyExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.4.2/com/diffplug/gradle/spotless/GroovyExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/GroovyExtension.java) -- `com.diffplug.gradle.spotless.GroovyGradleExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.4.2/com/diffplug/gradle/spotless/GroovyGradleExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/GroovyGradleExtension.java) +- `com.diffplug.gradle.spotless.GroovyExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.5.0/com/diffplug/gradle/spotless/GroovyExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/GroovyExtension.java) +- `com.diffplug.gradle.spotless.GroovyGradleExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.5.0/com/diffplug/gradle/spotless/GroovyGradleExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/GroovyGradleExtension.java) Configuration for Groovy is similar to [Java](#java), in that it also supports `licenseHeader` and `importOrder`. @@ -300,8 +300,8 @@ Groovy-Eclipse formatting errors/warnings lead per default to a build failure. T ## Kotlin -- `com.diffplug.gradle.spotless.KotlinExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.4.2/com/diffplug/gradle/spotless/KotlinExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/KotlinExtension.java) -- `com.diffplug.gradle.spotless.KotlinGradleExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.4.2/com/diffplug/gradle/spotless/KotlinGradleExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/KotlinGradleExtension.java) +- `com.diffplug.gradle.spotless.KotlinExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.5.0/com/diffplug/gradle/spotless/KotlinExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/KotlinExtension.java) +- `com.diffplug.gradle.spotless.KotlinGradleExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.5.0/com/diffplug/gradle/spotless/KotlinGradleExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/KotlinGradleExtension.java) ```gradle spotless { // if you are using build.gradle.kts, instead of 'spotless {' use: @@ -361,7 +361,7 @@ spotless { ## Scala -`com.diffplug.gradle.spotless.ScalaExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.4.2/com/diffplug/gradle/spotless/ScalaExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/ScalaExtension.java) +`com.diffplug.gradle.spotless.ScalaExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.5.0/com/diffplug/gradle/spotless/ScalaExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/ScalaExtension.java) ```gradle spotless { @@ -393,7 +393,7 @@ spotless { ## C/C++ -`com.diffplug.gradle.spotless.CppExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.4.2/com/diffplug/gradle/spotless/CppExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/CppExtension.java) +`com.diffplug.gradle.spotless.CppExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.5.0/com/diffplug/gradle/spotless/CppExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/CppExtension.java) ```gradle spotless { @@ -425,7 +425,7 @@ spotles { ## Python -`com.diffplug.gradle.spotless.PythonExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.4.2/com/diffplug/gradle/spotless/PythonExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/PythonExtension.java) +`com.diffplug.gradle.spotless.PythonExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.5.0/com/diffplug/gradle/spotless/PythonExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/PythonExtension.java) ```gradle spotless { @@ -459,7 +459,7 @@ black().pathToExe('C:/myuser/.pyenv/versions/3.8.0/scripts/black.exe') ## FreshMark -`com.diffplug.gradle.spotless.FreshMarkExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.4.2/com/diffplug/gradle/spotless/FreshMarkExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/FreshMarkExtension.java) +`com.diffplug.gradle.spotless.FreshMarkExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.5.0/com/diffplug/gradle/spotless/FreshMarkExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/FreshMarkExtension.java) [homepage](https://github.com/diffplug/freshmark). [changelog](https://github.com/diffplug/freshmark/blob/master/CHANGES.md). FreshMark lets you generate markdown in the comments of your markdown. This helps to keep badges and links up-to-date (see the source for this file), and can also be helpful for generating complex tables (see the source for [the parent readme](../README.md)). @@ -480,7 +480,7 @@ spotless { ## Antlr4 -`com.diffplug.gradle.spotless.Antlr4Extension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.4.2/com/diffplug/gradle/spotless/Antlr4Extension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/Antlr4Extension.java) +`com.diffplug.gradle.spotless.Antlr4Extension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.5.0/com/diffplug/gradle/spotless/Antlr4Extension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/Antlr4Extension.java) ```gradle spotless { @@ -505,7 +505,7 @@ antlr4formatter('1.2.1') // version is optional ## SQL -`com.diffplug.gradle.spotless.SqlExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.4.2/com/diffplug/gradle/spotless/SqlExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/SqlExtension.java) +`com.diffplug.gradle.spotless.SqlExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.5.0/com/diffplug/gradle/spotless/SqlExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/SqlExtension.java) ```gradle spotless { @@ -545,7 +545,7 @@ sql.formatter.indent.size=4 ## Typescript -- `com.diffplug.gradle.spotless.TypescriptExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.4.2/com/diffplug/gradle/spotless/TypescriptExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/TypescriptExtension.java) +- `com.diffplug.gradle.spotless.TypescriptExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.5.0/com/diffplug/gradle/spotless/TypescriptExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/TypescriptExtension.java) ```gradle spotless { @@ -588,7 +588,7 @@ For details, see the [npm detection](#npm-detection) and [`.npmrc` detection](#n ## JSON -- `com.diffplug.gradle.spotless.JsonExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.4.2/com/diffplug/gradle/spotless/JsonExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/JsonExtension.java) +- `com.diffplug.gradle.spotless.JsonExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.5.0/com/diffplug/gradle/spotless/JsonExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/JsonExtension.java) ```gradle spotless { @@ -813,7 +813,7 @@ Once a file's license header has a valid year, whether it is a year (`2020`) or * `2017` -> `2017-2020` * `2017-2019` -> `2017-2020` -See the [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.4.2/com/diffplug/gradle/spotless/FormatExtension.LicenseHeaderConfig.html) for a complete listing of options. +See the [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.5.0/com/diffplug/gradle/spotless/FormatExtension.LicenseHeaderConfig.html) for a complete listing of options. @@ -880,9 +880,9 @@ spotless { custom 'lowercase', { str -> str.toLowerCase() } ``` -However, custom rules will disable up-to-date checking and caching, unless you read [this javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.4.2/com/diffplug/gradle/spotless/FormatExtension.html#bumpThisNumberIfACustomStepChanges-int-) and follow its instructions carefully. +However, custom rules will disable up-to-date checking and caching, unless you read [this javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.5.0/com/diffplug/gradle/spotless/FormatExtension.html#bumpThisNumberIfACustomStepChanges-int-) and follow its instructions carefully. -Another option is to create proper `FormatterStep` in your `buildSrc`, and then call [`addStep`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.4.2/com/diffplug/gradle/spotless/FormatExtension.html#addStep-com.diffplug.spotless.FormatterStep-). The contributing guide describes [how to do this](https://github.com/diffplug/spotless/blob/main/CONTRIBUTING.md#how-to-add-a-new-formatterstep). If the step is generally-useful, we hope you'll open a PR to share it! +Another option is to create proper `FormatterStep` in your `buildSrc`, and then call [`addStep`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.5.0/com/diffplug/gradle/spotless/FormatExtension.html#addStep-com.diffplug.spotless.FormatterStep-). The contributing guide describes [how to do this](https://github.com/diffplug/spotless/blob/main/CONTRIBUTING.md#how-to-add-a-new-formatterstep). If the step is generally-useful, we hope you'll open a PR to share it! ```gradle @@ -915,11 +915,11 @@ spotless { format 'foo', com.acme.FooLanguageExtension, { ``` -If you'd like to create a one-off Spotless task outside of the `check`/`apply` framework, see [`FormatExtension.createIndependentApplyTask`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.4.2/com/diffplug/gradle/spotless/FormatExtension.html#createIndependentApplyTask-java.lang.String-). +If you'd like to create a one-off Spotless task outside of the `check`/`apply` framework, see [`FormatExtension.createIndependentApplyTask`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.5.0/com/diffplug/gradle/spotless/FormatExtension.html#createIndependentApplyTask-java.lang.String-). ## Inception (languages within languages within...) -In very rare cases, you might want to format e.g. javascript which is written inside JSP templates, or maybe java within a markdown file, or something wacky like that. You can specify hunks within a file using either open/close tags or a regex with a single capturing group, and then specify rules within it, like so. See [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.4.2/com/diffplug/gradle/spotless/FormatExtension.html#withinBlocks-java.lang.String-java.lang.String-java.lang.String-org.gradle.api.Action-) for more details. +In very rare cases, you might want to format e.g. javascript which is written inside JSP templates, or maybe java within a markdown file, or something wacky like that. You can specify hunks within a file using either open/close tags or a regex with a single capturing group, and then specify rules within it, like so. See [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.5.0/com/diffplug/gradle/spotless/FormatExtension.html#withinBlocks-java.lang.String-java.lang.String-java.lang.String-org.gradle.api.Action-) for more details. ```gradle import com.diffplug.gradle.spotless.JavaExtension From 90f3f997b708bd8526aac2bc4d79db57070ff090 Mon Sep 17 00:00:00 2001 From: circleci Date: Fri, 22 Apr 2022 23:29:07 +0000 Subject: [PATCH 094/757] Published maven/2.22.2 --- plugin-maven/CHANGES.md | 2 ++ plugin-maven/README.md | 4 ++-- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/plugin-maven/CHANGES.md b/plugin-maven/CHANGES.md index 7c7a8b214b..d798cdd3b1 100644 --- a/plugin-maven/CHANGES.md +++ b/plugin-maven/CHANGES.md @@ -3,6 +3,8 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format (starting after version `1.27.0`). ## [Unreleased] + +## [2.22.2] - 2022-04-22 ### 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)) diff --git a/plugin-maven/README.md b/plugin-maven/README.md index e0daabecd9..ef2945c330 100644 --- a/plugin-maven/README.md +++ b/plugin-maven/README.md @@ -12,8 +12,8 @@ output = [ ].join('\n'); --> [![Maven central](https://img.shields.io/badge/mavencentral-com.diffplug.spotless%3Aspotless--maven--plugin-blue.svg)](https://search.maven.org/#search%7Cgav%7C1%7Cg%3A%22com.diffplug.spotless%22%20AND%20a%3A%22spotless-maven-plugin%22) -[![Javadoc](https://img.shields.io/badge/javadoc-yes-blue.svg)](https://javadoc.io/doc/com.diffplug.spotless/spotless-maven-plugin/2.22.1/index.html) -[![Changelog](https://img.shields.io/badge/changelog-2.22.1-brightgreen.svg)](CHANGES.md) +[![Javadoc](https://img.shields.io/badge/javadoc-yes-blue.svg)](https://javadoc.io/doc/com.diffplug.spotless/spotless-maven-plugin/2.22.2/index.html) +[![Changelog](https://img.shields.io/badge/changelog-2.22.2-brightgreen.svg)](CHANGES.md) [![Circle CI](https://circleci.com/gh/diffplug/spotless/tree/main.svg?style=shield)](https://circleci.com/gh/diffplug/spotless/tree/main) [![Live chat](https://img.shields.io/badge/gitter-chat-brightgreen.svg)](https://gitter.im/diffplug/spotless) From 7ba7cb5f1ee29ceb19abd70232d269d2b622acf5 Mon Sep 17 00:00:00 2001 From: naveensrinivasan <172697+naveensrinivasan@users.noreply.github.com> Date: Sat, 23 Apr 2022 21:23:35 -0500 Subject: [PATCH 095/757] chore: Set permissions for GitHub actions MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Restrict the GitHub token permissions only to the required ones; this way, even if the attackers will succeed in compromising your workflow, they won’t be able to do much. - Included permissions for the action. https://github.com/ossf/scorecard/blob/main/docs/checks.md#token-permissions https://docs.github.com/en/actions/using-workflows/workflow-syntax-for-github-actions#permissions https://docs.github.com/en/actions/using-jobs/assigning-permissions-to-jobs [Keeping your GitHub Actions and workflows secure Part 1: Preventing pwn requests](https://securitylab.github.com/research/github-actions-preventing-pwn-requests/) Signed-off-by: naveensrinivasan <172697+naveensrinivasan@users.noreply.github.com> --- .github/workflows/codeql-analysis.yml | 7 +++++++ .github/workflows/gradle-wrapper-validation.yml | 3 +++ 2 files changed, 10 insertions(+) diff --git a/.github/workflows/codeql-analysis.yml b/.github/workflows/codeql-analysis.yml index 59bac96914..5d8365459c 100644 --- a/.github/workflows/codeql-analysis.yml +++ b/.github/workflows/codeql-analysis.yml @@ -14,8 +14,15 @@ on: schedule: - cron: '0 16 * * 3' +permissions: + contents: read + jobs: analyze: + permissions: + actions: read # for github/codeql-action/init to get workflow details + contents: read # for actions/checkout to fetch code + security-events: write # for github/codeql-action/autobuild to send a status report name: Analyze runs-on: ubuntu-latest diff --git a/.github/workflows/gradle-wrapper-validation.yml b/.github/workflows/gradle-wrapper-validation.yml index 8bfd0dcf51..c80a7e5278 100644 --- a/.github/workflows/gradle-wrapper-validation.yml +++ b/.github/workflows/gradle-wrapper-validation.yml @@ -1,6 +1,9 @@ name: "Validate Gradle Wrapper" on: [push, pull_request] +permissions: + contents: read + jobs: validation: name: "Validation" From 82e5db3910cea585c9d25eaea0ee1b7777ecc26d Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 25 Apr 2022 12:04:26 +0000 Subject: [PATCH 096/757] Bump ktfmt from 0.35 to 0.36 Bumps [ktfmt](https://github.com/facebookincubator/ktfmt) from 0.35 to 0.36. - [Release notes](https://github.com/facebookincubator/ktfmt/releases) - [Commits](https://github.com/facebookincubator/ktfmt/compare/v0.35...v0.36) --- updated-dependencies: - dependency-name: com.facebook:ktfmt dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] --- lib/build.gradle | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/build.gradle b/lib/build.gradle index 415817b09d..2df4243110 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.35' + String VER_KTFMT = '0.36' 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") { From 99f81bc9863497a1ca04e31e0a3a8cb351406cd3 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 25 Apr 2022 12:04:29 +0000 Subject: [PATCH 097/757] Bump com.diffplug.spotless from 6.4.2 to 6.5.0 Bumps com.diffplug.spotless from 6.4.2 to 6.5.0. --- updated-dependencies: - dependency-name: com.diffplug.spotless dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] --- settings.gradle | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/settings.gradle b/settings.gradle index 8be69fc46d..4bdbdfc1a8 100644 --- a/settings.gradle +++ b/settings.gradle @@ -1,6 +1,6 @@ pluginManagement { plugins { - id 'com.diffplug.spotless' version '6.4.2' + id 'com.diffplug.spotless' version '6.5.0' // https://plugins.gradle.org/plugin/com.gradle.plugin-publish id 'com.gradle.plugin-publish' version '0.21.0' // https://github.com/gradle-nexus/publish-plugin/releases From c4670ce14afa41aa7074618c23e562326601d9ce Mon Sep 17 00:00:00 2001 From: Ned Twigg Date: Wed, 27 Apr 2022 12:48:55 -0700 Subject: [PATCH 098/757] Bump ktfmt default version to 0.36. --- lib/src/main/java/com/diffplug/spotless/kotlin/KtfmtStep.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 3cefe7baca..86b036db3b 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.35"; + private static final String DEFAULT_VERSION = "0.36"; static final String NAME = "ktfmt"; static final String PACKAGE = "com.facebook"; static final String MAVEN_COORDINATE = PACKAGE + ":ktfmt:"; From 4a7c091082fde94ffd854213957ee27a09643d08 Mon Sep 17 00:00:00 2001 From: Ned Twigg Date: Wed, 27 Apr 2022 12:50:03 -0700 Subject: [PATCH 099/757] Update changelogs. --- CHANGES.md | 2 ++ plugin-gradle/CHANGES.md | 2 ++ plugin-maven/CHANGES.md | 2 ++ 3 files changed, 6 insertions(+) diff --git a/CHANGES.md b/CHANGES.md index 90eccfbd45..763ecfa763 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -10,6 +10,8 @@ This document is intended for Spotless developers. We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format (starting after version `1.27.0`). ## [Unreleased] +### Changes +* Bump default `ktfmt` version to latest `0.35` -> `0.36`. ([#1183](https://github.com/diffplug/spotless/issues/1183)) ## [2.25.0] - 2022-04-22 ### Added diff --git a/plugin-gradle/CHANGES.md b/plugin-gradle/CHANGES.md index a85e28ed75..c9c72348d3 100644 --- a/plugin-gradle/CHANGES.md +++ b/plugin-gradle/CHANGES.md @@ -3,6 +3,8 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format (starting after version `3.27.0`). ## [Unreleased] +### Changes +* Bump default `ktfmt` version to latest `0.35` -> `0.36`. ([#1183](https://github.com/diffplug/spotless/issues/1183)) ## [6.5.0] - 2022-04-22 ### Added diff --git a/plugin-maven/CHANGES.md b/plugin-maven/CHANGES.md index d798cdd3b1..9b85f48e8c 100644 --- a/plugin-maven/CHANGES.md +++ b/plugin-maven/CHANGES.md @@ -3,6 +3,8 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format (starting after version `1.27.0`). ## [Unreleased] +### Changes +* Bump default `ktfmt` version to latest `0.35` -> `0.36`. ([#1183](https://github.com/diffplug/spotless/issues/1183)) ## [2.22.2] - 2022-04-22 ### Fixed From 6e7d35b6fdfec7c7161343ce85280a0c538f49cf Mon Sep 17 00:00:00 2001 From: Ned Twigg Date: Wed, 27 Apr 2022 13:05:40 -0700 Subject: [PATCH 100/757] Bump default GJF to 1.15.0. --- .../java/com/diffplug/spotless/java/GoogleJavaFormatStep.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/src/main/java/com/diffplug/spotless/java/GoogleJavaFormatStep.java b/lib/src/main/java/com/diffplug/spotless/java/GoogleJavaFormatStep.java index c5ef2e576a..6aec20c891 100644 --- a/lib/src/main/java/com/diffplug/spotless/java/GoogleJavaFormatStep.java +++ b/lib/src/main/java/com/diffplug/spotless/java/GoogleJavaFormatStep.java @@ -93,7 +93,7 @@ public static FormatterStep create(String groupArtifact, String version, String State::createFormat); } - static final Jvm.Support JVM_SUPPORT = Jvm. support(NAME).add(8, "1.7").add(11, "1.13.0"); + static final Jvm.Support JVM_SUPPORT = Jvm. support(NAME).add(8, "1.7").add(11, "1.15.0"); public static String defaultGroupArtifact() { return MAVEN_COORDINATE; From b6735ed78f05420666d58ccb77d98b1f0ef3acf2 Mon Sep 17 00:00:00 2001 From: Ned Twigg Date: Wed, 27 Apr 2022 13:09:54 -0700 Subject: [PATCH 101/757] Bump changelogs. --- CHANGES.md | 2 ++ plugin-gradle/CHANGES.md | 2 ++ plugin-maven/CHANGES.md | 2 ++ 3 files changed, 6 insertions(+) diff --git a/CHANGES.md b/CHANGES.md index 763ecfa763..cb69dd746c 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -12,6 +12,8 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format ( ## [Unreleased] ### Changes * Bump default `ktfmt` version to latest `0.35` -> `0.36`. ([#1183](https://github.com/diffplug/spotless/issues/1183)) +* Bump default `google-java-format` version to latest `1.13.0` -> `1.15.0`. + * This means it is no longer necessary to use the `--add-exports` workaround (fixes [#834](https://github.com/diffplug/spotless/issues/834)). ## [2.25.0] - 2022-04-22 ### Added diff --git a/plugin-gradle/CHANGES.md b/plugin-gradle/CHANGES.md index c9c72348d3..eeca3cba82 100644 --- a/plugin-gradle/CHANGES.md +++ b/plugin-gradle/CHANGES.md @@ -5,6 +5,8 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format ( ## [Unreleased] ### Changes * Bump default `ktfmt` version to latest `0.35` -> `0.36`. ([#1183](https://github.com/diffplug/spotless/issues/1183)) +* Bump default `google-java-format` version to latest `1.13.0` -> `1.15.0`. + * This means it is no longer necessary to use the `--add-exports` workaround (fixes [#834](https://github.com/diffplug/spotless/issues/834)). ## [6.5.0] - 2022-04-22 ### Added diff --git a/plugin-maven/CHANGES.md b/plugin-maven/CHANGES.md index 9b85f48e8c..bc42d526b6 100644 --- a/plugin-maven/CHANGES.md +++ b/plugin-maven/CHANGES.md @@ -5,6 +5,8 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format ( ## [Unreleased] ### Changes * Bump default `ktfmt` version to latest `0.35` -> `0.36`. ([#1183](https://github.com/diffplug/spotless/issues/1183)) +* Bump default `google-java-format` version to latest `1.13.0` -> `1.15.0`. + * This means it is no longer necessary to use the `--add-exports` workaround (fixes [#834](https://github.com/diffplug/spotless/issues/834)). ## [2.22.2] - 2022-04-22 ### Fixed From f497ad2b6379b5d9c658dc269a06bebf4f829435 Mon Sep 17 00:00:00 2001 From: circleci Date: Wed, 27 Apr 2022 20:58:19 +0000 Subject: [PATCH 102/757] Published lib/2.25.1 --- CHANGES.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/CHANGES.md b/CHANGES.md index cb69dd746c..c055c88f34 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -10,6 +10,8 @@ This document is intended for Spotless developers. We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format (starting after version `1.27.0`). ## [Unreleased] + +## [2.25.1] - 2022-04-27 ### Changes * Bump default `ktfmt` version to latest `0.35` -> `0.36`. ([#1183](https://github.com/diffplug/spotless/issues/1183)) * Bump default `google-java-format` version to latest `1.13.0` -> `1.15.0`. From e2d9237cb3a4fa469c3b8828c56b5b6283498842 Mon Sep 17 00:00:00 2001 From: circleci Date: Wed, 27 Apr 2022 20:59:11 +0000 Subject: [PATCH 103/757] Published gradle/6.5.1 --- plugin-gradle/CHANGES.md | 2 ++ plugin-gradle/README.md | 46 ++++++++++++++++++++-------------------- 2 files changed, 25 insertions(+), 23 deletions(-) diff --git a/plugin-gradle/CHANGES.md b/plugin-gradle/CHANGES.md index eeca3cba82..0c528b30a7 100644 --- a/plugin-gradle/CHANGES.md +++ b/plugin-gradle/CHANGES.md @@ -3,6 +3,8 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format (starting after version `3.27.0`). ## [Unreleased] + +## [6.5.1] - 2022-04-27 ### Changes * Bump default `ktfmt` version to latest `0.35` -> `0.36`. ([#1183](https://github.com/diffplug/spotless/issues/1183)) * Bump default `google-java-format` version to latest `1.13.0` -> `1.15.0`. diff --git a/plugin-gradle/README.md b/plugin-gradle/README.md index 02baa6e654..ba59a7339b 100644 --- a/plugin-gradle/README.md +++ b/plugin-gradle/README.md @@ -18,9 +18,9 @@ output = [ --> [![Gradle plugin](https://img.shields.io/badge/plugins.gradle.org-com.diffplug.spotless-blue.svg)](https://plugins.gradle.org/plugin/com.diffplug.spotless) [![Maven central](https://img.shields.io/badge/mavencentral-yes-blue.svg)](https://search.maven.org/#search%7Cgav%7C1%7Cg%3A%22com.diffplug.spotless%22%20AND%20a%3A%22spotless-plugin-gradle%22) -[![Javadoc](https://img.shields.io/badge/javadoc-yes-blue.svg)](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.5.0/index.html) +[![Javadoc](https://img.shields.io/badge/javadoc-yes-blue.svg)](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.5.1/index.html) [![License Apache](https://img.shields.io/badge/license-apache-blue.svg)](https://tldrlegal.com/license/apache-license-2.0-(apache-2.0)) -[![Changelog](https://img.shields.io/badge/changelog-6.5.0-blue.svg)](CHANGES.md) +[![Changelog](https://img.shields.io/badge/changelog-6.5.1-blue.svg)](CHANGES.md) [![Circle CI](https://circleci.com/gh/diffplug/spotless/tree/main.svg?style=shield)](https://circleci.com/gh/diffplug/spotless/tree/main) [![Live chat](https://img.shields.io/badge/gitter-chat-brightgreen.svg)](https://gitter.im/diffplug/spotless) @@ -126,10 +126,10 @@ spotless { ``` Spotless consists of a list of formats (in the example above, `misc` and `java`), and each format has: -- a `target` (the files to format), which you set with [`target`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.5.0/com/diffplug/gradle/spotless/FormatExtension.html#target-java.lang.Object...-) and [`targetExclude`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.5.0/com/diffplug/gradle/spotless/FormatExtension.html#targetExclude-java.lang.Object...-) -- a list of `FormatterStep`, which are just `String -> String` functions, such as [`replace`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.5.0/com/diffplug/gradle/spotless/FormatExtension.html#replace-java.lang.String-java.lang.CharSequence-java.lang.CharSequence-), [`replaceRegex`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.5.0/com/diffplug/gradle/spotless/FormatExtension.html#replaceRegex-java.lang.String-java.lang.String-java.lang.String-), [`trimTrailingWhitespace`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.5.0/com/diffplug/gradle/spotless/FormatExtension.html#replace-java.lang.String-java.lang.CharSequence-java.lang.CharSequence-), [`custom`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.5.0/com/diffplug/gradle/spotless/FormatExtension.html#custom-java.lang.String-groovy.lang.Closure-), [`prettier`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.5.0/com/diffplug/gradle/spotless/FormatExtension.html#prettier--), [`eclipseWtp`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.5.0/com/diffplug/gradle/spotless/FormatExtension.html#eclipseWtp-com.diffplug.spotless.extra.wtp.EclipseWtpFormatterStep-), [`licenseHeader`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.5.0/com/diffplug/gradle/spotless/FormatExtension.html#licenseHeader-java.lang.String-java.lang.String-) etc. +- a `target` (the files to format), which you set with [`target`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.5.1/com/diffplug/gradle/spotless/FormatExtension.html#target-java.lang.Object...-) and [`targetExclude`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.5.1/com/diffplug/gradle/spotless/FormatExtension.html#targetExclude-java.lang.Object...-) +- a list of `FormatterStep`, which are just `String -> String` functions, such as [`replace`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.5.1/com/diffplug/gradle/spotless/FormatExtension.html#replace-java.lang.String-java.lang.CharSequence-java.lang.CharSequence-), [`replaceRegex`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.5.1/com/diffplug/gradle/spotless/FormatExtension.html#replaceRegex-java.lang.String-java.lang.String-java.lang.String-), [`trimTrailingWhitespace`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.5.1/com/diffplug/gradle/spotless/FormatExtension.html#replace-java.lang.String-java.lang.CharSequence-java.lang.CharSequence-), [`custom`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.5.1/com/diffplug/gradle/spotless/FormatExtension.html#custom-java.lang.String-groovy.lang.Closure-), [`prettier`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.5.1/com/diffplug/gradle/spotless/FormatExtension.html#prettier--), [`eclipseWtp`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.5.1/com/diffplug/gradle/spotless/FormatExtension.html#eclipseWtp-com.diffplug.spotless.extra.wtp.EclipseWtpFormatterStep-), [`licenseHeader`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.5.1/com/diffplug/gradle/spotless/FormatExtension.html#licenseHeader-java.lang.String-java.lang.String-) etc. -All the generic steps live in [`FormatExtension`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.5.0/com/diffplug/gradle/spotless/FormatExtension.html), and there are many language-specific steps which live in its language-specific subclasses, which are described below. +All the generic steps live in [`FormatExtension`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.5.1/com/diffplug/gradle/spotless/FormatExtension.html), and there are many language-specific steps which live in its language-specific subclasses, which are described below. ### Requirements @@ -141,7 +141,7 @@ If you're stuck on an older version of Gradle, `id 'com.diffplug.gradle.spotless ## Java -`com.diffplug.gradle.spotless.JavaExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.5.0/com/diffplug/gradle/spotless/JavaExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/JavaExtension.java) +`com.diffplug.gradle.spotless.JavaExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.5.1/com/diffplug/gradle/spotless/JavaExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/JavaExtension.java) ```gradle spotless { @@ -248,8 +248,8 @@ spotless { ## Groovy -- `com.diffplug.gradle.spotless.GroovyExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.5.0/com/diffplug/gradle/spotless/GroovyExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/GroovyExtension.java) -- `com.diffplug.gradle.spotless.GroovyGradleExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.5.0/com/diffplug/gradle/spotless/GroovyGradleExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/GroovyGradleExtension.java) +- `com.diffplug.gradle.spotless.GroovyExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.5.1/com/diffplug/gradle/spotless/GroovyExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/GroovyExtension.java) +- `com.diffplug.gradle.spotless.GroovyGradleExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.5.1/com/diffplug/gradle/spotless/GroovyGradleExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/GroovyGradleExtension.java) Configuration for Groovy is similar to [Java](#java), in that it also supports `licenseHeader` and `importOrder`. @@ -300,8 +300,8 @@ Groovy-Eclipse formatting errors/warnings lead per default to a build failure. T ## Kotlin -- `com.diffplug.gradle.spotless.KotlinExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.5.0/com/diffplug/gradle/spotless/KotlinExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/KotlinExtension.java) -- `com.diffplug.gradle.spotless.KotlinGradleExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.5.0/com/diffplug/gradle/spotless/KotlinGradleExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/KotlinGradleExtension.java) +- `com.diffplug.gradle.spotless.KotlinExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.5.1/com/diffplug/gradle/spotless/KotlinExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/KotlinExtension.java) +- `com.diffplug.gradle.spotless.KotlinGradleExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.5.1/com/diffplug/gradle/spotless/KotlinGradleExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/KotlinGradleExtension.java) ```gradle spotless { // if you are using build.gradle.kts, instead of 'spotless {' use: @@ -361,7 +361,7 @@ spotless { ## Scala -`com.diffplug.gradle.spotless.ScalaExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.5.0/com/diffplug/gradle/spotless/ScalaExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/ScalaExtension.java) +`com.diffplug.gradle.spotless.ScalaExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.5.1/com/diffplug/gradle/spotless/ScalaExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/ScalaExtension.java) ```gradle spotless { @@ -393,7 +393,7 @@ spotless { ## C/C++ -`com.diffplug.gradle.spotless.CppExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.5.0/com/diffplug/gradle/spotless/CppExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/CppExtension.java) +`com.diffplug.gradle.spotless.CppExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.5.1/com/diffplug/gradle/spotless/CppExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/CppExtension.java) ```gradle spotless { @@ -425,7 +425,7 @@ spotles { ## Python -`com.diffplug.gradle.spotless.PythonExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.5.0/com/diffplug/gradle/spotless/PythonExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/PythonExtension.java) +`com.diffplug.gradle.spotless.PythonExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.5.1/com/diffplug/gradle/spotless/PythonExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/PythonExtension.java) ```gradle spotless { @@ -459,7 +459,7 @@ black().pathToExe('C:/myuser/.pyenv/versions/3.8.0/scripts/black.exe') ## FreshMark -`com.diffplug.gradle.spotless.FreshMarkExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.5.0/com/diffplug/gradle/spotless/FreshMarkExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/FreshMarkExtension.java) +`com.diffplug.gradle.spotless.FreshMarkExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.5.1/com/diffplug/gradle/spotless/FreshMarkExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/FreshMarkExtension.java) [homepage](https://github.com/diffplug/freshmark). [changelog](https://github.com/diffplug/freshmark/blob/master/CHANGES.md). FreshMark lets you generate markdown in the comments of your markdown. This helps to keep badges and links up-to-date (see the source for this file), and can also be helpful for generating complex tables (see the source for [the parent readme](../README.md)). @@ -480,7 +480,7 @@ spotless { ## Antlr4 -`com.diffplug.gradle.spotless.Antlr4Extension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.5.0/com/diffplug/gradle/spotless/Antlr4Extension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/Antlr4Extension.java) +`com.diffplug.gradle.spotless.Antlr4Extension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.5.1/com/diffplug/gradle/spotless/Antlr4Extension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/Antlr4Extension.java) ```gradle spotless { @@ -505,7 +505,7 @@ antlr4formatter('1.2.1') // version is optional ## SQL -`com.diffplug.gradle.spotless.SqlExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.5.0/com/diffplug/gradle/spotless/SqlExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/SqlExtension.java) +`com.diffplug.gradle.spotless.SqlExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.5.1/com/diffplug/gradle/spotless/SqlExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/SqlExtension.java) ```gradle spotless { @@ -545,7 +545,7 @@ sql.formatter.indent.size=4 ## Typescript -- `com.diffplug.gradle.spotless.TypescriptExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.5.0/com/diffplug/gradle/spotless/TypescriptExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/TypescriptExtension.java) +- `com.diffplug.gradle.spotless.TypescriptExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.5.1/com/diffplug/gradle/spotless/TypescriptExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/TypescriptExtension.java) ```gradle spotless { @@ -588,7 +588,7 @@ For details, see the [npm detection](#npm-detection) and [`.npmrc` detection](#n ## JSON -- `com.diffplug.gradle.spotless.JsonExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.5.0/com/diffplug/gradle/spotless/JsonExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/JsonExtension.java) +- `com.diffplug.gradle.spotless.JsonExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.5.1/com/diffplug/gradle/spotless/JsonExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/JsonExtension.java) ```gradle spotless { @@ -813,7 +813,7 @@ Once a file's license header has a valid year, whether it is a year (`2020`) or * `2017` -> `2017-2020` * `2017-2019` -> `2017-2020` -See the [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.5.0/com/diffplug/gradle/spotless/FormatExtension.LicenseHeaderConfig.html) for a complete listing of options. +See the [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.5.1/com/diffplug/gradle/spotless/FormatExtension.LicenseHeaderConfig.html) for a complete listing of options. @@ -880,9 +880,9 @@ spotless { custom 'lowercase', { str -> str.toLowerCase() } ``` -However, custom rules will disable up-to-date checking and caching, unless you read [this javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.5.0/com/diffplug/gradle/spotless/FormatExtension.html#bumpThisNumberIfACustomStepChanges-int-) and follow its instructions carefully. +However, custom rules will disable up-to-date checking and caching, unless you read [this javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.5.1/com/diffplug/gradle/spotless/FormatExtension.html#bumpThisNumberIfACustomStepChanges-int-) and follow its instructions carefully. -Another option is to create proper `FormatterStep` in your `buildSrc`, and then call [`addStep`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.5.0/com/diffplug/gradle/spotless/FormatExtension.html#addStep-com.diffplug.spotless.FormatterStep-). The contributing guide describes [how to do this](https://github.com/diffplug/spotless/blob/main/CONTRIBUTING.md#how-to-add-a-new-formatterstep). If the step is generally-useful, we hope you'll open a PR to share it! +Another option is to create proper `FormatterStep` in your `buildSrc`, and then call [`addStep`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.5.1/com/diffplug/gradle/spotless/FormatExtension.html#addStep-com.diffplug.spotless.FormatterStep-). The contributing guide describes [how to do this](https://github.com/diffplug/spotless/blob/main/CONTRIBUTING.md#how-to-add-a-new-formatterstep). If the step is generally-useful, we hope you'll open a PR to share it! ```gradle @@ -915,11 +915,11 @@ spotless { format 'foo', com.acme.FooLanguageExtension, { ``` -If you'd like to create a one-off Spotless task outside of the `check`/`apply` framework, see [`FormatExtension.createIndependentApplyTask`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.5.0/com/diffplug/gradle/spotless/FormatExtension.html#createIndependentApplyTask-java.lang.String-). +If you'd like to create a one-off Spotless task outside of the `check`/`apply` framework, see [`FormatExtension.createIndependentApplyTask`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.5.1/com/diffplug/gradle/spotless/FormatExtension.html#createIndependentApplyTask-java.lang.String-). ## Inception (languages within languages within...) -In very rare cases, you might want to format e.g. javascript which is written inside JSP templates, or maybe java within a markdown file, or something wacky like that. You can specify hunks within a file using either open/close tags or a regex with a single capturing group, and then specify rules within it, like so. See [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.5.0/com/diffplug/gradle/spotless/FormatExtension.html#withinBlocks-java.lang.String-java.lang.String-java.lang.String-org.gradle.api.Action-) for more details. +In very rare cases, you might want to format e.g. javascript which is written inside JSP templates, or maybe java within a markdown file, or something wacky like that. You can specify hunks within a file using either open/close tags or a regex with a single capturing group, and then specify rules within it, like so. See [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.5.1/com/diffplug/gradle/spotless/FormatExtension.html#withinBlocks-java.lang.String-java.lang.String-java.lang.String-org.gradle.api.Action-) for more details. ```gradle import com.diffplug.gradle.spotless.JavaExtension From a8f208a99d571502fa960c25530c83d2a8349bbd Mon Sep 17 00:00:00 2001 From: circleci Date: Wed, 27 Apr 2022 21:00:41 +0000 Subject: [PATCH 104/757] Published maven/2.22.3 --- plugin-maven/CHANGES.md | 2 ++ plugin-maven/README.md | 4 ++-- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/plugin-maven/CHANGES.md b/plugin-maven/CHANGES.md index bc42d526b6..db71399c37 100644 --- a/plugin-maven/CHANGES.md +++ b/plugin-maven/CHANGES.md @@ -3,6 +3,8 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format (starting after version `1.27.0`). ## [Unreleased] + +## [2.22.3] - 2022-04-27 ### Changes * Bump default `ktfmt` version to latest `0.35` -> `0.36`. ([#1183](https://github.com/diffplug/spotless/issues/1183)) * Bump default `google-java-format` version to latest `1.13.0` -> `1.15.0`. diff --git a/plugin-maven/README.md b/plugin-maven/README.md index ef2945c330..6958e5d0e2 100644 --- a/plugin-maven/README.md +++ b/plugin-maven/README.md @@ -12,8 +12,8 @@ output = [ ].join('\n'); --> [![Maven central](https://img.shields.io/badge/mavencentral-com.diffplug.spotless%3Aspotless--maven--plugin-blue.svg)](https://search.maven.org/#search%7Cgav%7C1%7Cg%3A%22com.diffplug.spotless%22%20AND%20a%3A%22spotless-maven-plugin%22) -[![Javadoc](https://img.shields.io/badge/javadoc-yes-blue.svg)](https://javadoc.io/doc/com.diffplug.spotless/spotless-maven-plugin/2.22.2/index.html) -[![Changelog](https://img.shields.io/badge/changelog-2.22.2-brightgreen.svg)](CHANGES.md) +[![Javadoc](https://img.shields.io/badge/javadoc-yes-blue.svg)](https://javadoc.io/doc/com.diffplug.spotless/spotless-maven-plugin/2.22.3/index.html) +[![Changelog](https://img.shields.io/badge/changelog-2.22.3-brightgreen.svg)](CHANGES.md) [![Circle CI](https://circleci.com/gh/diffplug/spotless/tree/main.svg?style=shield)](https://circleci.com/gh/diffplug/spotless/tree/main) [![Live chat](https://img.shields.io/badge/gitter-chat-brightgreen.svg)](https://gitter.im/diffplug/spotless) From 4d454723d3ca0eb11d20916793989b188e470e94 Mon Sep 17 00:00:00 2001 From: Ned Twigg Date: Thu, 28 Apr 2022 16:11:34 -0700 Subject: [PATCH 105/757] Update changelog to make it clear that #834 is still broken. --- CHANGES.md | 2 +- plugin-gradle/CHANGES.md | 2 +- plugin-maven/CHANGES.md | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/CHANGES.md b/CHANGES.md index c055c88f34..b2acc6f0b3 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -15,7 +15,7 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format ( ### Changes * Bump default `ktfmt` version to latest `0.35` -> `0.36`. ([#1183](https://github.com/diffplug/spotless/issues/1183)) * Bump default `google-java-format` version to latest `1.13.0` -> `1.15.0`. - * This means it is no longer necessary to use the `--add-exports` workaround (fixes [#834](https://github.com/diffplug/spotless/issues/834)). + * ~~This means it is no longer necessary to use the `--add-exports` workaround (fixes [#834](https://github.com/diffplug/spotless/issues/834)).~~ `--add-exports` workaround is still needed. ## [2.25.0] - 2022-04-22 ### Added diff --git a/plugin-gradle/CHANGES.md b/plugin-gradle/CHANGES.md index 0c528b30a7..7025767e6d 100644 --- a/plugin-gradle/CHANGES.md +++ b/plugin-gradle/CHANGES.md @@ -8,7 +8,7 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format ( ### Changes * Bump default `ktfmt` version to latest `0.35` -> `0.36`. ([#1183](https://github.com/diffplug/spotless/issues/1183)) * Bump default `google-java-format` version to latest `1.13.0` -> `1.15.0`. - * This means it is no longer necessary to use the `--add-exports` workaround (fixes [#834](https://github.com/diffplug/spotless/issues/834)). + * ~~This means it is no longer necessary to use the `--add-exports` workaround (fixes [#834](https://github.com/diffplug/spotless/issues/834)).~~ `--add-exports` workaround is still needed. ## [6.5.0] - 2022-04-22 ### Added diff --git a/plugin-maven/CHANGES.md b/plugin-maven/CHANGES.md index db71399c37..b050ecfed0 100644 --- a/plugin-maven/CHANGES.md +++ b/plugin-maven/CHANGES.md @@ -8,7 +8,7 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format ( ### Changes * Bump default `ktfmt` version to latest `0.35` -> `0.36`. ([#1183](https://github.com/diffplug/spotless/issues/1183)) * Bump default `google-java-format` version to latest `1.13.0` -> `1.15.0`. - * This means it is no longer necessary to use the `--add-exports` workaround (fixes [#834](https://github.com/diffplug/spotless/issues/834)). + * ~~This means it is no longer necessary to use the `--add-exports` workaround (fixes [#834](https://github.com/diffplug/spotless/issues/834)).~~ `--add-exports` workaround is still needed. ## [2.22.2] - 2022-04-22 ### Fixed From 1d945a77b8a4395c244f8b800712bb6592c9e28e Mon Sep 17 00:00:00 2001 From: Peter Trifanov Date: Sat, 30 Apr 2022 12:19:41 +0300 Subject: [PATCH 106/757] Convert diktat integration to use a compile-only sourceset * Convert diktat integration * Pass absolute path into `Params` object to resolve the problem with package name checking --- CHANGES.md | 1 + lib/build.gradle | 6 +- .../glue/diktat/DiktatFormatterFunc.java | 95 +++++++++++++++++++ .../diffplug/spotless/kotlin/DiktatStep.java | 91 +----------------- 4 files changed, 105 insertions(+), 88 deletions(-) create mode 100644 lib/src/diktat/java/com/diffplug/spotless/glue/diktat/DiktatFormatterFunc.java diff --git a/CHANGES.md b/CHANGES.md index b2acc6f0b3..f1379048d1 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -10,6 +10,7 @@ This document is intended for Spotless developers. We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format (starting after version `1.27.0`). ## [Unreleased] +* Converted `diktat` integration to use a compile-only source set. ([#524](https://github.com/diffplug/spotless/issues/524)) ## [2.25.1] - 2022-04-27 ### Changes diff --git a/lib/build.gradle b/lib/build.gradle index 2df4243110..ccfb9b1b79 100644 --- a/lib/build.gradle +++ b/lib/build.gradle @@ -11,7 +11,8 @@ def NEEDS_GLUE = [ 'palantirJavaFormat', 'ktfmt', 'ktlint', - 'flexmark' + 'flexmark', + 'diktat' ] for (glue in NEEDS_GLUE) { sourceSets.register(glue) { @@ -50,6 +51,9 @@ dependencies { ktlintCompileOnly "com.pinterest.ktlint:ktlint-ruleset-experimental:$VER_KTLINT" ktlintCompileOnly "com.pinterest.ktlint:ktlint-ruleset-standard:$VER_KTLINT" + String VER_DIKTAT = "1.1.0" + diktatCompileOnly "org.cqfn.diktat:diktat-rules:$VER_DIKTAT" + // used for markdown formatting flexmarkCompileOnly 'com.vladsch.flexmark:flexmark-all:0.62.2' } diff --git a/lib/src/diktat/java/com/diffplug/spotless/glue/diktat/DiktatFormatterFunc.java b/lib/src/diktat/java/com/diffplug/spotless/glue/diktat/DiktatFormatterFunc.java new file mode 100644 index 0000000000..5960ce2095 --- /dev/null +++ b/lib/src/diktat/java/com/diffplug/spotless/glue/diktat/DiktatFormatterFunc.java @@ -0,0 +1,95 @@ +/* + * Copyright 2021-2022 DiffPlug + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.diffplug.spotless.glue.diktat; + +import java.io.File; +import java.util.*; + +import org.cqfn.diktat.ruleset.rules.DiktatRuleSetProvider; + +import com.pinterest.ktlint.core.KtLint; +import com.pinterest.ktlint.core.KtLint.Params; +import com.pinterest.ktlint.core.LintError; +import com.pinterest.ktlint.core.RuleSet; + +import com.diffplug.spotless.FormatterFunc; + +import kotlin.Unit; +import kotlin.jvm.functions.Function2; + +public class DiktatFormatterFunc implements FormatterFunc.NeedsFile { + + private final List rulesets; + private final Map userData; + private final Function2 formatterCallback; + private final boolean isScript; + + private final ArrayList errors = new ArrayList<>(); + + public DiktatFormatterFunc(boolean isScript, Map userData) { + rulesets = Collections.singletonList(new DiktatRuleSetProvider().get()); + this.userData = userData; + this.formatterCallback = new FormatterCallback(errors); + this.isScript = isScript; + } + + static class FormatterCallback implements Function2 { + private final ArrayList errors; + + FormatterCallback(ArrayList errors) { + this.errors = errors; + } + + @Override + public Unit invoke(LintError lintError, Boolean corrected) { + if (!corrected) { + errors.add(lintError); + } + return null; + } + } + + @Override + public String applyWithFile(String unix, File file) throws Exception { + errors.clear(); + userData.put("file_path", file.getAbsolutePath()); + String result = KtLint.INSTANCE.format(new Params( + file.getName(), + unix, + rulesets, + userData, + formatterCallback, + isScript, + null, + false)); + + if (!errors.isEmpty()) { + StringBuilder error = new StringBuilder(); + error.append("There are ").append(errors.size()).append(" unfixed errors:"); + for (LintError er : errors) { + error.append(System.lineSeparator()) + .append("Error on line: ").append(er.getLine()) + .append(", column: ").append(er.getCol()) + .append(" cannot be fixed automatically") + .append(System.lineSeparator()) + .append(er.getDetail()); + } + throw new AssertionError(error); + } + + return result; + } +} diff --git a/lib/src/main/java/com/diffplug/spotless/kotlin/DiktatStep.java b/lib/src/main/java/com/diffplug/spotless/kotlin/DiktatStep.java index 7f5779cce6..e01748d4b5 100644 --- a/lib/src/main/java/com/diffplug/spotless/kotlin/DiktatStep.java +++ b/lib/src/main/java/com/diffplug/spotless/kotlin/DiktatStep.java @@ -18,9 +18,6 @@ import java.io.IOException; import java.io.Serializable; import java.lang.reflect.Constructor; -import java.lang.reflect.InvocationTargetException; -import java.lang.reflect.Method; -import java.lang.reflect.Proxy; import java.util.*; import javax.annotation.Nullable; @@ -33,10 +30,9 @@ public class DiktatStep { // prevent direct instantiation private DiktatStep() {} - private static final String DEFAULT_VERSION = "1.0.1"; + private static final String DEFAULT_VERSION = "1.1.0"; static final String NAME = "diktat"; static final String PACKAGE_DIKTAT = "org.cqfn.diktat"; - static final String PACKAGE_KTLINT = "com.pinterest.ktlint"; static final String MAVEN_COORDINATE = PACKAGE_DIKTAT + ":diktat-rules:"; public static String defaultVersionDiktat() { @@ -82,8 +78,6 @@ static final class State implements Serializable { /** Are the files being linted Kotlin script files. */ private final boolean isScript; private final @Nullable FileSignature config; - private final String pkg; - private final String pkgKtlint; final JarState jar; private final TreeMap userData; @@ -93,96 +87,19 @@ static final class State implements Serializable { pkgSet.add(MAVEN_COORDINATE + versionDiktat); this.userData = new TreeMap<>(userData); - this.pkg = PACKAGE_DIKTAT; - this.pkgKtlint = PACKAGE_KTLINT; this.jar = JarState.from(pkgSet, provisioner); this.isScript = isScript; this.config = config; } FormatterFunc createFormat() throws Exception { - - ClassLoader classLoader = jar.getClassLoader(); - - // first, we get the diktat rules if (config != null) { System.setProperty("diktat.config.path", config.getOnlyFile().getAbsolutePath()); } - Class ruleSetProviderClass = classLoader.loadClass(pkg + ".ruleset.rules.DiktatRuleSetProvider"); - Object diktatRuleSet = ruleSetProviderClass.getMethod("get").invoke(ruleSetProviderClass.newInstance()); - Iterable ruleSets = Collections.singletonList(diktatRuleSet); - - // next, we create an error callback which throws an assertion error when the format is bad - Class function2Interface = classLoader.loadClass("kotlin.jvm.functions.Function2"); - Class lintErrorClass = classLoader.loadClass(pkgKtlint + ".core.LintError"); - Method detailGetter = lintErrorClass.getMethod("getDetail"); - Method lineGetter = lintErrorClass.getMethod("getLine"); - Method colGetter = lintErrorClass.getMethod("getCol"); - - // grab the KtLint singleton - Class ktlintClass = classLoader.loadClass(pkgKtlint + ".core.KtLint"); - Object ktlint = ktlintClass.getDeclaredField("INSTANCE").get(null); - - Class paramsClass = classLoader.loadClass(pkgKtlint + ".core.KtLint$Params"); - // and its constructor - Constructor constructor = paramsClass.getConstructor( - /* fileName, nullable */ String.class, - /* text */ String.class, - /* ruleSets */ Iterable.class, - /* userData */ Map.class, - /* callback */ function2Interface, - /* script */ boolean.class, - /* editorConfigPath, nullable */ String.class, - /* debug */ boolean.class); - Method formatterMethod = ktlintClass.getMethod("format", paramsClass); - FormatterFunc.NeedsFile formatterFunc = (input, file) -> { - ArrayList errors = new ArrayList<>(); - - Object formatterCallback = Proxy.newProxyInstance(classLoader, new Class[]{function2Interface}, - (proxy, method, args) -> { - Object lintError = args[0]; //ktlint.core.LintError - boolean corrected = (Boolean) args[1]; - if (!corrected) { - errors.add(lintError); - } - return null; - }); - - userData.put("file_path", file.getAbsolutePath()); - try { - Object params = constructor.newInstance( - /* fileName, nullable */ file.getName(), - /* text */ input, - /* ruleSets */ ruleSets, - /* userData */ userData, - /* callback */ formatterCallback, - /* script */ isScript, - /* editorConfigPath, nullable */ null, - /* debug */ false); - String result = (String) formatterMethod.invoke(ktlint, params); - if (!errors.isEmpty()) { - StringBuilder error = new StringBuilder(""); - error.append("There are ").append(errors.size()).append(" unfixed errors:"); - for (Object er : errors) { - String detail = (String) detailGetter.invoke(er); - int line = (Integer) lineGetter.invoke(er); - int col = (Integer) colGetter.invoke(er); - - error.append(System.lineSeparator()).append("Error on line: ").append(line).append(", column: ").append(col).append(" cannot be fixed automatically") - .append(System.lineSeparator()).append(detail); - } - throw new AssertionError(error); - } - return result; - } catch (InvocationTargetException e) { - throw ThrowingEx.unwrapCause(e); - } - }; - - return formatterFunc; + Class formatterFunc = jar.getClassLoader().loadClass("com.diffplug.spotless.glue.diktat.DiktatFormatterFunc"); + Constructor constructor = formatterFunc.getConstructor(boolean.class, Map.class); + return (FormatterFunc.NeedsFile) constructor.newInstance(isScript, userData); } - } - } From ef85dc4a25a3494e633c192d90c68ac6f0277339 Mon Sep 17 00:00:00 2001 From: Ned Twigg Date: Mon, 2 May 2022 13:32:20 -0700 Subject: [PATCH 107/757] Update changelogs. --- CHANGES.md | 4 +++- plugin-gradle/CHANGES.md | 3 +++ plugin-maven/CHANGES.md | 3 +++ 3 files changed, 9 insertions(+), 1 deletion(-) diff --git a/CHANGES.md b/CHANGES.md index f1379048d1..3f34593b1e 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -10,7 +10,9 @@ This document is intended for Spotless developers. We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format (starting after version `1.27.0`). ## [Unreleased] -* Converted `diktat` integration to use a compile-only source set. ([#524](https://github.com/diffplug/spotless/issues/524)) +### Changes +* Bump default `diktat` version to latest `1.0.1` -> `1.0.1`. + * Converted `diktat` integration to use a compile-only source set. ([#524](https://github.com/diffplug/spotless/issues/524)) ## [2.25.1] - 2022-04-27 ### Changes diff --git a/plugin-gradle/CHANGES.md b/plugin-gradle/CHANGES.md index 7025767e6d..1b7e892414 100644 --- a/plugin-gradle/CHANGES.md +++ b/plugin-gradle/CHANGES.md @@ -3,6 +3,9 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format (starting after version `3.27.0`). ## [Unreleased] +### Changes +* Bump default `diktat` version to latest `1.0.1` -> `1.0.1`. + * Converted `diktat` integration to use a compile-only source set. ([#524](https://github.com/diffplug/spotless/issues/524)) ## [6.5.1] - 2022-04-27 ### Changes diff --git a/plugin-maven/CHANGES.md b/plugin-maven/CHANGES.md index b050ecfed0..db2891049b 100644 --- a/plugin-maven/CHANGES.md +++ b/plugin-maven/CHANGES.md @@ -3,6 +3,9 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format (starting after version `1.27.0`). ## [Unreleased] +### Changes +* Bump default `diktat` version to latest `1.0.1` -> `1.0.1`. + * Converted `diktat` integration to use a compile-only source set. ([#524](https://github.com/diffplug/spotless/issues/524)) ## [2.22.3] - 2022-04-27 ### Changes From a49c2b1b7b72d947077fc41c8221dcddd44bf29d Mon Sep 17 00:00:00 2001 From: Peter Trifanov Date: Tue, 3 May 2022 10:42:21 +0300 Subject: [PATCH 108/757] Convert diktat integration to use a compile-only sourceset * Pass absolute path into `Params` object to resolve the problem with package name checking * Update changelogs --- CHANGES.md | 3 ++- .../diffplug/spotless/glue/diktat/DiktatFormatterFunc.java | 4 +++- plugin-gradle/CHANGES.md | 3 ++- plugin-maven/CHANGES.md | 3 ++- 4 files changed, 9 insertions(+), 4 deletions(-) diff --git a/CHANGES.md b/CHANGES.md index 3f34593b1e..56a0040dd4 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -11,8 +11,9 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format ( ## [Unreleased] ### Changes -* Bump default `diktat` version to latest `1.0.1` -> `1.0.1`. +* Bump default `diktat` version to latest `1.0.1` -> `1.1.0`. * Converted `diktat` integration to use a compile-only source set. ([#524](https://github.com/diffplug/spotless/issues/524)) + * Use the full path to a file in `diktat` integration ([#1189](https://github.com/diffplug/spotless/issues/1189)) ## [2.25.1] - 2022-04-27 ### Changes diff --git a/lib/src/diktat/java/com/diffplug/spotless/glue/diktat/DiktatFormatterFunc.java b/lib/src/diktat/java/com/diffplug/spotless/glue/diktat/DiktatFormatterFunc.java index 5960ce2095..1374bebb10 100644 --- a/lib/src/diktat/java/com/diffplug/spotless/glue/diktat/DiktatFormatterFunc.java +++ b/lib/src/diktat/java/com/diffplug/spotless/glue/diktat/DiktatFormatterFunc.java @@ -67,7 +67,9 @@ public String applyWithFile(String unix, File file) throws Exception { errors.clear(); userData.put("file_path", file.getAbsolutePath()); String result = KtLint.INSTANCE.format(new Params( - file.getName(), + // Unlike Ktlint, Diktat requires full path to the file. + // See https://github.com/diffplug/spotless/issues/1189, https://github.com/analysis-dev/diktat/issues/1202 + file.getAbsolutePath(), unix, rulesets, userData, diff --git a/plugin-gradle/CHANGES.md b/plugin-gradle/CHANGES.md index 1b7e892414..3ef22ce327 100644 --- a/plugin-gradle/CHANGES.md +++ b/plugin-gradle/CHANGES.md @@ -4,8 +4,9 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format ( ## [Unreleased] ### Changes -* Bump default `diktat` version to latest `1.0.1` -> `1.0.1`. +* Bump default `diktat` version to latest `1.0.1` -> `1.1.0`. * Converted `diktat` integration to use a compile-only source set. ([#524](https://github.com/diffplug/spotless/issues/524)) + * Use the full path to a file in `diktat` integration ([#1189](https://github.com/diffplug/spotless/issues/1189)) ## [6.5.1] - 2022-04-27 ### Changes diff --git a/plugin-maven/CHANGES.md b/plugin-maven/CHANGES.md index db2891049b..8598ac482e 100644 --- a/plugin-maven/CHANGES.md +++ b/plugin-maven/CHANGES.md @@ -4,8 +4,9 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format ( ## [Unreleased] ### Changes -* Bump default `diktat` version to latest `1.0.1` -> `1.0.1`. +* Bump default `diktat` version to latest `1.0.1` -> `1.1.0`. * Converted `diktat` integration to use a compile-only source set. ([#524](https://github.com/diffplug/spotless/issues/524)) + * Use the full path to a file in `diktat` integration ([#1189](https://github.com/diffplug/spotless/issues/1189)) ## [2.22.3] - 2022-04-27 ### Changes From 417b1b85d68423726ae914fe926c4938deb11d6b Mon Sep 17 00:00:00 2001 From: Ned Twigg Date: Tue, 3 May 2022 14:12:24 -0700 Subject: [PATCH 109/757] Bump changelogs (mostly to trigger CI). --- CHANGES.md | 6 +++--- plugin-gradle/CHANGES.md | 6 +++--- plugin-maven/CHANGES.md | 6 +++--- 3 files changed, 9 insertions(+), 9 deletions(-) diff --git a/CHANGES.md b/CHANGES.md index 56a0040dd4..083b6b31f5 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -11,9 +11,9 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format ( ## [Unreleased] ### Changes -* Bump default `diktat` version to latest `1.0.1` -> `1.1.0`. - * Converted `diktat` integration to use a compile-only source set. ([#524](https://github.com/diffplug/spotless/issues/524)) - * Use the full path to a file in `diktat` integration ([#1189](https://github.com/diffplug/spotless/issues/1189)) +* Bump default `diktat` version to latest `1.0.1` -> `1.1.0`. ([#1190](https://github.com/diffplug/spotless/pull/1190)) + * Converted `diktat` integration to use a compile-only source set. (fixes [#524](https://github.com/diffplug/spotless/issues/524)) + * Use the full path to a file in `diktat` integration. (fixes [#1189](https://github.com/diffplug/spotless/issues/1189)) ## [2.25.1] - 2022-04-27 ### Changes diff --git a/plugin-gradle/CHANGES.md b/plugin-gradle/CHANGES.md index 3ef22ce327..81590a3d86 100644 --- a/plugin-gradle/CHANGES.md +++ b/plugin-gradle/CHANGES.md @@ -4,9 +4,9 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format ( ## [Unreleased] ### Changes -* Bump default `diktat` version to latest `1.0.1` -> `1.1.0`. - * Converted `diktat` integration to use a compile-only source set. ([#524](https://github.com/diffplug/spotless/issues/524)) - * Use the full path to a file in `diktat` integration ([#1189](https://github.com/diffplug/spotless/issues/1189)) +* Bump default `diktat` version to latest `1.0.1` -> `1.1.0`. ([#1190](https://github.com/diffplug/spotless/pull/1190)) + * Converted `diktat` integration to use a compile-only source set. (fixes [#524](https://github.com/diffplug/spotless/issues/524)) + * Use the full path to a file in `diktat` integration. (fixes [#1189](https://github.com/diffplug/spotless/issues/1189)) ## [6.5.1] - 2022-04-27 ### Changes diff --git a/plugin-maven/CHANGES.md b/plugin-maven/CHANGES.md index 8598ac482e..4b7610ebb3 100644 --- a/plugin-maven/CHANGES.md +++ b/plugin-maven/CHANGES.md @@ -4,9 +4,9 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format ( ## [Unreleased] ### Changes -* Bump default `diktat` version to latest `1.0.1` -> `1.1.0`. - * Converted `diktat` integration to use a compile-only source set. ([#524](https://github.com/diffplug/spotless/issues/524)) - * Use the full path to a file in `diktat` integration ([#1189](https://github.com/diffplug/spotless/issues/1189)) +* Bump default `diktat` version to latest `1.0.1` -> `1.1.0`. ([#1190](https://github.com/diffplug/spotless/pull/1190)) + * Converted `diktat` integration to use a compile-only source set. (fixes [#524](https://github.com/diffplug/spotless/issues/524)) + * Use the full path to a file in `diktat` integration. (fixes [#1189](https://github.com/diffplug/spotless/issues/1189)) ## [2.22.3] - 2022-04-27 ### Changes From 335d49524f3d9944d88da2cdadc69ff4f05a4cee Mon Sep 17 00:00:00 2001 From: Ned Twigg Date: Tue, 3 May 2022 15:44:52 -0700 Subject: [PATCH 110/757] Fixup the tests. --- .../java/com/diffplug/spotless/kotlin/DiktatStepTest.java | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/testlib/src/test/java/com/diffplug/spotless/kotlin/DiktatStepTest.java b/testlib/src/test/java/com/diffplug/spotless/kotlin/DiktatStepTest.java index 040a23d0a8..24a79ed61b 100644 --- a/testlib/src/test/java/com/diffplug/spotless/kotlin/DiktatStepTest.java +++ b/testlib/src/test/java/com/diffplug/spotless/kotlin/DiktatStepTest.java @@ -38,9 +38,9 @@ void behavior() throws Exception { assertion.isInstanceOf(AssertionError.class); assertion.hasMessage("There are 2 unfixed errors:" + System.lineSeparator() + "Error on line: 1, column: 1 cannot be fixed automatically" + - System.lineSeparator() + "[FILE_NAME_INCORRECT] file name is incorrect - it should end with .kt extension and be in PascalCase: " + + System.lineSeparator() + "[FILE_NAME_INCORRECT] file name is incorrect - it should end with .kt extension and be in PascalCase: testlib" + System.lineSeparator() + "Error on line: 1, column: 1 cannot be fixed automatically" + - System.lineSeparator() + "[FILE_NAME_MATCH_CLASS] file name is incorrect - it should match with the class described in it if there is the only one class declared: vs Unsolvable"); + System.lineSeparator() + "[FILE_NAME_MATCH_CLASS] file name is incorrect - it should match with the class described in it if there is the only one class declared: testlib vs Unsolvable"); }); } @@ -57,9 +57,9 @@ void behaviorConf() throws Exception { assertion.isInstanceOf(AssertionError.class); assertion.hasMessage("There are 2 unfixed errors:" + System.lineSeparator() + "Error on line: 1, column: 1 cannot be fixed automatically" + - System.lineSeparator() + "[FILE_NAME_INCORRECT] file name is incorrect - it should end with .kt extension and be in PascalCase: " + + System.lineSeparator() + "[FILE_NAME_INCORRECT] file name is incorrect - it should end with .kt extension and be in PascalCase: testlib" + System.lineSeparator() + "Error on line: 1, column: 1 cannot be fixed automatically" + - System.lineSeparator() + "[FILE_NAME_MATCH_CLASS] file name is incorrect - it should match with the class described in it if there is the only one class declared: vs Unsolvable"); + System.lineSeparator() + "[FILE_NAME_MATCH_CLASS] file name is incorrect - it should match with the class described in it if there is the only one class declared: testlib vs Unsolvable"); }); } From acf8a6faca4464d4e9b9662c49bf99b3ede44346 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Tue, 3 May 2022 23:07:36 +0000 Subject: [PATCH 111/757] Bump github/codeql-action from 1 to 2 Bumps [github/codeql-action](https://github.com/github/codeql-action) from 1 to 2. - [Release notes](https://github.com/github/codeql-action/releases) - [Changelog](https://github.com/github/codeql-action/blob/main/CHANGELOG.md) - [Commits](https://github.com/github/codeql-action/compare/v1...v2) --- updated-dependencies: - dependency-name: github/codeql-action dependency-type: direct:production update-type: version-update:semver-major ... Signed-off-by: dependabot[bot] --- .github/workflows/codeql-analysis.yml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/codeql-analysis.yml b/.github/workflows/codeql-analysis.yml index 5d8365459c..b2f2a259c3 100644 --- a/.github/workflows/codeql-analysis.yml +++ b/.github/workflows/codeql-analysis.yml @@ -50,7 +50,7 @@ jobs: # Initializes the CodeQL tools for scanning. - name: Initialize CodeQL - uses: github/codeql-action/init@v1 + uses: github/codeql-action/init@v2 with: languages: ${{ matrix.language }} # If you wish to specify custom queries, you can do so here or in a config file. @@ -61,7 +61,7 @@ jobs: # Autobuild attempts to build any compiled languages (C/C++, C#, or Java). # If this step fails, then you should remove it and run the build manually (see below) - name: Autobuild - uses: github/codeql-action/autobuild@v1 + uses: github/codeql-action/autobuild@v2 # ℹ️ Command-line programs to run using the OS shell. # 📚 https://git.io/JvXDl @@ -75,4 +75,4 @@ jobs: # make release - name: Perform CodeQL Analysis - uses: github/codeql-action/analyze@v1 + uses: github/codeql-action/analyze@v2 From 1346d0868d43a9366c30dac62d3b8c2efedc30e9 Mon Sep 17 00:00:00 2001 From: circleci Date: Tue, 3 May 2022 23:12:35 +0000 Subject: [PATCH 112/757] Published lib/2.25.2 --- CHANGES.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/CHANGES.md b/CHANGES.md index 083b6b31f5..a30549e380 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -10,6 +10,8 @@ This document is intended for Spotless developers. We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format (starting after version `1.27.0`). ## [Unreleased] + +## [2.25.2] - 2022-05-03 ### Changes * Bump default `diktat` version to latest `1.0.1` -> `1.1.0`. ([#1190](https://github.com/diffplug/spotless/pull/1190)) * Converted `diktat` integration to use a compile-only source set. (fixes [#524](https://github.com/diffplug/spotless/issues/524)) From daac96f3eb357c698d4c44dc9ab74fbdc6331e24 Mon Sep 17 00:00:00 2001 From: circleci Date: Tue, 3 May 2022 23:13:31 +0000 Subject: [PATCH 113/757] Published gradle/6.5.2 --- plugin-gradle/CHANGES.md | 2 ++ plugin-gradle/README.md | 46 ++++++++++++++++++++-------------------- 2 files changed, 25 insertions(+), 23 deletions(-) diff --git a/plugin-gradle/CHANGES.md b/plugin-gradle/CHANGES.md index 81590a3d86..9397d1fa5a 100644 --- a/plugin-gradle/CHANGES.md +++ b/plugin-gradle/CHANGES.md @@ -3,6 +3,8 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format (starting after version `3.27.0`). ## [Unreleased] + +## [6.5.2] - 2022-05-03 ### Changes * Bump default `diktat` version to latest `1.0.1` -> `1.1.0`. ([#1190](https://github.com/diffplug/spotless/pull/1190)) * Converted `diktat` integration to use a compile-only source set. (fixes [#524](https://github.com/diffplug/spotless/issues/524)) diff --git a/plugin-gradle/README.md b/plugin-gradle/README.md index ba59a7339b..bc6d28b72c 100644 --- a/plugin-gradle/README.md +++ b/plugin-gradle/README.md @@ -18,9 +18,9 @@ output = [ --> [![Gradle plugin](https://img.shields.io/badge/plugins.gradle.org-com.diffplug.spotless-blue.svg)](https://plugins.gradle.org/plugin/com.diffplug.spotless) [![Maven central](https://img.shields.io/badge/mavencentral-yes-blue.svg)](https://search.maven.org/#search%7Cgav%7C1%7Cg%3A%22com.diffplug.spotless%22%20AND%20a%3A%22spotless-plugin-gradle%22) -[![Javadoc](https://img.shields.io/badge/javadoc-yes-blue.svg)](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.5.1/index.html) +[![Javadoc](https://img.shields.io/badge/javadoc-yes-blue.svg)](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.5.2/index.html) [![License Apache](https://img.shields.io/badge/license-apache-blue.svg)](https://tldrlegal.com/license/apache-license-2.0-(apache-2.0)) -[![Changelog](https://img.shields.io/badge/changelog-6.5.1-blue.svg)](CHANGES.md) +[![Changelog](https://img.shields.io/badge/changelog-6.5.2-blue.svg)](CHANGES.md) [![Circle CI](https://circleci.com/gh/diffplug/spotless/tree/main.svg?style=shield)](https://circleci.com/gh/diffplug/spotless/tree/main) [![Live chat](https://img.shields.io/badge/gitter-chat-brightgreen.svg)](https://gitter.im/diffplug/spotless) @@ -126,10 +126,10 @@ spotless { ``` Spotless consists of a list of formats (in the example above, `misc` and `java`), and each format has: -- a `target` (the files to format), which you set with [`target`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.5.1/com/diffplug/gradle/spotless/FormatExtension.html#target-java.lang.Object...-) and [`targetExclude`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.5.1/com/diffplug/gradle/spotless/FormatExtension.html#targetExclude-java.lang.Object...-) -- a list of `FormatterStep`, which are just `String -> String` functions, such as [`replace`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.5.1/com/diffplug/gradle/spotless/FormatExtension.html#replace-java.lang.String-java.lang.CharSequence-java.lang.CharSequence-), [`replaceRegex`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.5.1/com/diffplug/gradle/spotless/FormatExtension.html#replaceRegex-java.lang.String-java.lang.String-java.lang.String-), [`trimTrailingWhitespace`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.5.1/com/diffplug/gradle/spotless/FormatExtension.html#replace-java.lang.String-java.lang.CharSequence-java.lang.CharSequence-), [`custom`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.5.1/com/diffplug/gradle/spotless/FormatExtension.html#custom-java.lang.String-groovy.lang.Closure-), [`prettier`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.5.1/com/diffplug/gradle/spotless/FormatExtension.html#prettier--), [`eclipseWtp`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.5.1/com/diffplug/gradle/spotless/FormatExtension.html#eclipseWtp-com.diffplug.spotless.extra.wtp.EclipseWtpFormatterStep-), [`licenseHeader`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.5.1/com/diffplug/gradle/spotless/FormatExtension.html#licenseHeader-java.lang.String-java.lang.String-) etc. +- a `target` (the files to format), which you set with [`target`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.5.2/com/diffplug/gradle/spotless/FormatExtension.html#target-java.lang.Object...-) and [`targetExclude`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.5.2/com/diffplug/gradle/spotless/FormatExtension.html#targetExclude-java.lang.Object...-) +- a list of `FormatterStep`, which are just `String -> String` functions, such as [`replace`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.5.2/com/diffplug/gradle/spotless/FormatExtension.html#replace-java.lang.String-java.lang.CharSequence-java.lang.CharSequence-), [`replaceRegex`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.5.2/com/diffplug/gradle/spotless/FormatExtension.html#replaceRegex-java.lang.String-java.lang.String-java.lang.String-), [`trimTrailingWhitespace`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.5.2/com/diffplug/gradle/spotless/FormatExtension.html#replace-java.lang.String-java.lang.CharSequence-java.lang.CharSequence-), [`custom`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.5.2/com/diffplug/gradle/spotless/FormatExtension.html#custom-java.lang.String-groovy.lang.Closure-), [`prettier`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.5.2/com/diffplug/gradle/spotless/FormatExtension.html#prettier--), [`eclipseWtp`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.5.2/com/diffplug/gradle/spotless/FormatExtension.html#eclipseWtp-com.diffplug.spotless.extra.wtp.EclipseWtpFormatterStep-), [`licenseHeader`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.5.2/com/diffplug/gradle/spotless/FormatExtension.html#licenseHeader-java.lang.String-java.lang.String-) etc. -All the generic steps live in [`FormatExtension`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.5.1/com/diffplug/gradle/spotless/FormatExtension.html), and there are many language-specific steps which live in its language-specific subclasses, which are described below. +All the generic steps live in [`FormatExtension`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.5.2/com/diffplug/gradle/spotless/FormatExtension.html), and there are many language-specific steps which live in its language-specific subclasses, which are described below. ### Requirements @@ -141,7 +141,7 @@ If you're stuck on an older version of Gradle, `id 'com.diffplug.gradle.spotless ## Java -`com.diffplug.gradle.spotless.JavaExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.5.1/com/diffplug/gradle/spotless/JavaExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/JavaExtension.java) +`com.diffplug.gradle.spotless.JavaExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.5.2/com/diffplug/gradle/spotless/JavaExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/JavaExtension.java) ```gradle spotless { @@ -248,8 +248,8 @@ spotless { ## Groovy -- `com.diffplug.gradle.spotless.GroovyExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.5.1/com/diffplug/gradle/spotless/GroovyExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/GroovyExtension.java) -- `com.diffplug.gradle.spotless.GroovyGradleExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.5.1/com/diffplug/gradle/spotless/GroovyGradleExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/GroovyGradleExtension.java) +- `com.diffplug.gradle.spotless.GroovyExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.5.2/com/diffplug/gradle/spotless/GroovyExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/GroovyExtension.java) +- `com.diffplug.gradle.spotless.GroovyGradleExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.5.2/com/diffplug/gradle/spotless/GroovyGradleExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/GroovyGradleExtension.java) Configuration for Groovy is similar to [Java](#java), in that it also supports `licenseHeader` and `importOrder`. @@ -300,8 +300,8 @@ Groovy-Eclipse formatting errors/warnings lead per default to a build failure. T ## Kotlin -- `com.diffplug.gradle.spotless.KotlinExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.5.1/com/diffplug/gradle/spotless/KotlinExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/KotlinExtension.java) -- `com.diffplug.gradle.spotless.KotlinGradleExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.5.1/com/diffplug/gradle/spotless/KotlinGradleExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/KotlinGradleExtension.java) +- `com.diffplug.gradle.spotless.KotlinExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.5.2/com/diffplug/gradle/spotless/KotlinExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/KotlinExtension.java) +- `com.diffplug.gradle.spotless.KotlinGradleExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.5.2/com/diffplug/gradle/spotless/KotlinGradleExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/KotlinGradleExtension.java) ```gradle spotless { // if you are using build.gradle.kts, instead of 'spotless {' use: @@ -361,7 +361,7 @@ spotless { ## Scala -`com.diffplug.gradle.spotless.ScalaExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.5.1/com/diffplug/gradle/spotless/ScalaExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/ScalaExtension.java) +`com.diffplug.gradle.spotless.ScalaExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.5.2/com/diffplug/gradle/spotless/ScalaExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/ScalaExtension.java) ```gradle spotless { @@ -393,7 +393,7 @@ spotless { ## C/C++ -`com.diffplug.gradle.spotless.CppExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.5.1/com/diffplug/gradle/spotless/CppExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/CppExtension.java) +`com.diffplug.gradle.spotless.CppExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.5.2/com/diffplug/gradle/spotless/CppExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/CppExtension.java) ```gradle spotless { @@ -425,7 +425,7 @@ spotles { ## Python -`com.diffplug.gradle.spotless.PythonExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.5.1/com/diffplug/gradle/spotless/PythonExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/PythonExtension.java) +`com.diffplug.gradle.spotless.PythonExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.5.2/com/diffplug/gradle/spotless/PythonExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/PythonExtension.java) ```gradle spotless { @@ -459,7 +459,7 @@ black().pathToExe('C:/myuser/.pyenv/versions/3.8.0/scripts/black.exe') ## FreshMark -`com.diffplug.gradle.spotless.FreshMarkExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.5.1/com/diffplug/gradle/spotless/FreshMarkExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/FreshMarkExtension.java) +`com.diffplug.gradle.spotless.FreshMarkExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.5.2/com/diffplug/gradle/spotless/FreshMarkExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/FreshMarkExtension.java) [homepage](https://github.com/diffplug/freshmark). [changelog](https://github.com/diffplug/freshmark/blob/master/CHANGES.md). FreshMark lets you generate markdown in the comments of your markdown. This helps to keep badges and links up-to-date (see the source for this file), and can also be helpful for generating complex tables (see the source for [the parent readme](../README.md)). @@ -480,7 +480,7 @@ spotless { ## Antlr4 -`com.diffplug.gradle.spotless.Antlr4Extension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.5.1/com/diffplug/gradle/spotless/Antlr4Extension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/Antlr4Extension.java) +`com.diffplug.gradle.spotless.Antlr4Extension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.5.2/com/diffplug/gradle/spotless/Antlr4Extension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/Antlr4Extension.java) ```gradle spotless { @@ -505,7 +505,7 @@ antlr4formatter('1.2.1') // version is optional ## SQL -`com.diffplug.gradle.spotless.SqlExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.5.1/com/diffplug/gradle/spotless/SqlExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/SqlExtension.java) +`com.diffplug.gradle.spotless.SqlExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.5.2/com/diffplug/gradle/spotless/SqlExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/SqlExtension.java) ```gradle spotless { @@ -545,7 +545,7 @@ sql.formatter.indent.size=4 ## Typescript -- `com.diffplug.gradle.spotless.TypescriptExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.5.1/com/diffplug/gradle/spotless/TypescriptExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/TypescriptExtension.java) +- `com.diffplug.gradle.spotless.TypescriptExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.5.2/com/diffplug/gradle/spotless/TypescriptExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/TypescriptExtension.java) ```gradle spotless { @@ -588,7 +588,7 @@ For details, see the [npm detection](#npm-detection) and [`.npmrc` detection](#n ## JSON -- `com.diffplug.gradle.spotless.JsonExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.5.1/com/diffplug/gradle/spotless/JsonExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/JsonExtension.java) +- `com.diffplug.gradle.spotless.JsonExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.5.2/com/diffplug/gradle/spotless/JsonExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/JsonExtension.java) ```gradle spotless { @@ -813,7 +813,7 @@ Once a file's license header has a valid year, whether it is a year (`2020`) or * `2017` -> `2017-2020` * `2017-2019` -> `2017-2020` -See the [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.5.1/com/diffplug/gradle/spotless/FormatExtension.LicenseHeaderConfig.html) for a complete listing of options. +See the [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.5.2/com/diffplug/gradle/spotless/FormatExtension.LicenseHeaderConfig.html) for a complete listing of options. @@ -880,9 +880,9 @@ spotless { custom 'lowercase', { str -> str.toLowerCase() } ``` -However, custom rules will disable up-to-date checking and caching, unless you read [this javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.5.1/com/diffplug/gradle/spotless/FormatExtension.html#bumpThisNumberIfACustomStepChanges-int-) and follow its instructions carefully. +However, custom rules will disable up-to-date checking and caching, unless you read [this javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.5.2/com/diffplug/gradle/spotless/FormatExtension.html#bumpThisNumberIfACustomStepChanges-int-) and follow its instructions carefully. -Another option is to create proper `FormatterStep` in your `buildSrc`, and then call [`addStep`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.5.1/com/diffplug/gradle/spotless/FormatExtension.html#addStep-com.diffplug.spotless.FormatterStep-). The contributing guide describes [how to do this](https://github.com/diffplug/spotless/blob/main/CONTRIBUTING.md#how-to-add-a-new-formatterstep). If the step is generally-useful, we hope you'll open a PR to share it! +Another option is to create proper `FormatterStep` in your `buildSrc`, and then call [`addStep`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.5.2/com/diffplug/gradle/spotless/FormatExtension.html#addStep-com.diffplug.spotless.FormatterStep-). The contributing guide describes [how to do this](https://github.com/diffplug/spotless/blob/main/CONTRIBUTING.md#how-to-add-a-new-formatterstep). If the step is generally-useful, we hope you'll open a PR to share it! ```gradle @@ -915,11 +915,11 @@ spotless { format 'foo', com.acme.FooLanguageExtension, { ``` -If you'd like to create a one-off Spotless task outside of the `check`/`apply` framework, see [`FormatExtension.createIndependentApplyTask`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.5.1/com/diffplug/gradle/spotless/FormatExtension.html#createIndependentApplyTask-java.lang.String-). +If you'd like to create a one-off Spotless task outside of the `check`/`apply` framework, see [`FormatExtension.createIndependentApplyTask`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.5.2/com/diffplug/gradle/spotless/FormatExtension.html#createIndependentApplyTask-java.lang.String-). ## Inception (languages within languages within...) -In very rare cases, you might want to format e.g. javascript which is written inside JSP templates, or maybe java within a markdown file, or something wacky like that. You can specify hunks within a file using either open/close tags or a regex with a single capturing group, and then specify rules within it, like so. See [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.5.1/com/diffplug/gradle/spotless/FormatExtension.html#withinBlocks-java.lang.String-java.lang.String-java.lang.String-org.gradle.api.Action-) for more details. +In very rare cases, you might want to format e.g. javascript which is written inside JSP templates, or maybe java within a markdown file, or something wacky like that. You can specify hunks within a file using either open/close tags or a regex with a single capturing group, and then specify rules within it, like so. See [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.5.2/com/diffplug/gradle/spotless/FormatExtension.html#withinBlocks-java.lang.String-java.lang.String-java.lang.String-org.gradle.api.Action-) for more details. ```gradle import com.diffplug.gradle.spotless.JavaExtension From acd8e40d9f983d30ec361bfbea9231db92114148 Mon Sep 17 00:00:00 2001 From: circleci Date: Tue, 3 May 2022 23:15:30 +0000 Subject: [PATCH 114/757] Published maven/2.22.4 --- plugin-maven/CHANGES.md | 2 ++ plugin-maven/README.md | 4 ++-- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/plugin-maven/CHANGES.md b/plugin-maven/CHANGES.md index 4b7610ebb3..fbacbc6c96 100644 --- a/plugin-maven/CHANGES.md +++ b/plugin-maven/CHANGES.md @@ -3,6 +3,8 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format (starting after version `1.27.0`). ## [Unreleased] + +## [2.22.4] - 2022-05-03 ### Changes * Bump default `diktat` version to latest `1.0.1` -> `1.1.0`. ([#1190](https://github.com/diffplug/spotless/pull/1190)) * Converted `diktat` integration to use a compile-only source set. (fixes [#524](https://github.com/diffplug/spotless/issues/524)) diff --git a/plugin-maven/README.md b/plugin-maven/README.md index 6958e5d0e2..b3bab5af71 100644 --- a/plugin-maven/README.md +++ b/plugin-maven/README.md @@ -12,8 +12,8 @@ output = [ ].join('\n'); --> [![Maven central](https://img.shields.io/badge/mavencentral-com.diffplug.spotless%3Aspotless--maven--plugin-blue.svg)](https://search.maven.org/#search%7Cgav%7C1%7Cg%3A%22com.diffplug.spotless%22%20AND%20a%3A%22spotless-maven-plugin%22) -[![Javadoc](https://img.shields.io/badge/javadoc-yes-blue.svg)](https://javadoc.io/doc/com.diffplug.spotless/spotless-maven-plugin/2.22.3/index.html) -[![Changelog](https://img.shields.io/badge/changelog-2.22.3-brightgreen.svg)](CHANGES.md) +[![Javadoc](https://img.shields.io/badge/javadoc-yes-blue.svg)](https://javadoc.io/doc/com.diffplug.spotless/spotless-maven-plugin/2.22.4/index.html) +[![Changelog](https://img.shields.io/badge/changelog-2.22.4-brightgreen.svg)](CHANGES.md) [![Circle CI](https://circleci.com/gh/diffplug/spotless/tree/main.svg?style=shield)](https://circleci.com/gh/diffplug/spotless/tree/main) [![Live chat](https://img.shields.io/badge/gitter-chat-brightgreen.svg)](https://gitter.im/diffplug/spotless) From 408dc68d10609fd8db194001279a34b2fc3876ac Mon Sep 17 00:00:00 2001 From: Ned Twigg Date: Fri, 6 May 2022 10:27:08 -0700 Subject: [PATCH 115/757] Fix the Black regex. --- CHANGES.md | 2 ++ lib/src/main/java/com/diffplug/spotless/python/BlackStep.java | 2 +- plugin-gradle/CHANGES.md | 2 ++ plugin-maven/CHANGES.md | 2 ++ 4 files changed, 7 insertions(+), 1 deletion(-) diff --git a/CHANGES.md b/CHANGES.md index a30549e380..e7427e178d 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -10,6 +10,8 @@ This document is intended for Spotless developers. We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format (starting after version `1.27.0`). ## [Unreleased] +### Fixed +* Update the `black` version regex to fix `19.10b0` and earlier. (fixes [#1195](https://github.com/diffplug/spotless/issues/1195), regression introduced in `2.25.0`) ## [2.25.2] - 2022-05-03 ### Changes 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 3f4a8837b6..6a03d0d808 100644 --- a/lib/src/main/java/com/diffplug/spotless/python/BlackStep.java +++ b/lib/src/main/java/com/diffplug/spotless/python/BlackStep.java @@ -64,7 +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*)")) + .versionRegex(Pattern.compile("(?:black, version|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 9397d1fa5a..963d6d06d7 100644 --- a/plugin-gradle/CHANGES.md +++ b/plugin-gradle/CHANGES.md @@ -3,6 +3,8 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format (starting after version `3.27.0`). ## [Unreleased] +### Fixed +* Update the `black` version regex to fix `19.10b0` and earlier. (fixes [#1195](https://github.com/diffplug/spotless/issues/1195), regression introduced in `6.5.0`) ## [6.5.2] - 2022-05-03 ### Changes diff --git a/plugin-maven/CHANGES.md b/plugin-maven/CHANGES.md index fbacbc6c96..08cad5cfa9 100644 --- a/plugin-maven/CHANGES.md +++ b/plugin-maven/CHANGES.md @@ -3,6 +3,8 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format (starting after version `1.27.0`). ## [Unreleased] +### Fixed +* Update the `black` version regex to fix `19.10b0` and earlier. (fixes [#1195](https://github.com/diffplug/spotless/issues/1195), regression introduced in `2.22.2`) ## [2.22.4] - 2022-05-03 ### Changes From 90778f72b1993aa5a24ede003fdb064044936d59 Mon Sep 17 00:00:00 2001 From: Ned Twigg Date: Fri, 6 May 2022 13:04:23 -0700 Subject: [PATCH 116/757] GradleProvisioner throws `GradleException` instead of just `logger.error`, this way Gradle reports the root cause. --- .../com/diffplug/gradle/spotless/GradleProvisioner.java | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/GradleProvisioner.java b/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/GradleProvisioner.java index 4ef8521412..63697afca2 100644 --- a/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/GradleProvisioner.java +++ b/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/GradleProvisioner.java @@ -127,12 +127,10 @@ private static Provisioner forConfigurationContainer(Project project, Configurat if (!projName.isEmpty()) { projName = projName + "/"; } - logger.error( - "You need to add a repository containing the '{}' artifact in '{}build.gradle'.\n" + + throw new GradleException(String.format( + "You need to add a repository containing the '%s' artifact in '%sbuild.gradle'.\n" + "E.g.: 'repositories { mavenCentral() }'", - mavenCoords, projName, - e); - throw e; + mavenCoords, projName), e); } }; } From f32ebe876259e7b823dc1da7b3f9886391dfc827 Mon Sep 17 00:00:00 2001 From: Ned Twigg Date: Fri, 6 May 2022 10:36:52 -0700 Subject: [PATCH 117/757] Fix caching memory leak in GitAttributesLineEndings. --- .../extra/GitAttributesLineEndings.java | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/lib-extra/src/main/java/com/diffplug/spotless/extra/GitAttributesLineEndings.java b/lib-extra/src/main/java/com/diffplug/spotless/extra/GitAttributesLineEndings.java index ae9f0ceec1..c4ca8edacb 100644 --- a/lib-extra/src/main/java/com/diffplug/spotless/extra/GitAttributesLineEndings.java +++ b/lib-extra/src/main/java/com/diffplug/spotless/extra/GitAttributesLineEndings.java @@ -15,8 +15,6 @@ */ package com.diffplug.spotless.extra; -import static com.diffplug.spotless.extra.LibExtraPreconditions.requireElementsNonNull; - import java.io.File; import java.io.FileInputStream; import java.io.IOException; @@ -78,8 +76,8 @@ public static LineEnding.Policy create(File projectDir, Supplier> static class RelocatablePolicy extends LazyForwardingEquality implements LineEnding.Policy { private static final long serialVersionUID = 5868522122123693015L; - final transient File projectDir; - final transient Supplier> toFormat; + transient File projectDir; + transient Supplier> toFormat; RelocatablePolicy(File projectDir, Supplier> toFormat) { this.projectDir = Objects.requireNonNull(projectDir, "projectDir"); @@ -88,8 +86,13 @@ static class RelocatablePolicy extends LazyForwardingEquality imp @Override protected CachedEndings calculateState() throws Exception { - Runtime runtime = new RuntimeInit(projectDir, toFormat.get()).atRuntime(); - return new CachedEndings(projectDir, runtime, toFormat.get()); + Runtime runtime = new RuntimeInit(projectDir).atRuntime(); + // LazyForwardingEquality guarantees that this will only be called once, and keeping toFormat + // causes a memory leak, see https://github.com/diffplug/spotless/issues/1194 + CachedEndings state = new CachedEndings(projectDir, runtime, toFormat.get()); + projectDir = null; + toFormat = null; + return state; } @Override @@ -146,8 +149,7 @@ static class RuntimeInit { final @Nullable File workTree; @SuppressFBWarnings("SIC_INNER_SHOULD_BE_STATIC_ANON") - RuntimeInit(File projectDir, Iterable toFormat) { - requireElementsNonNull(toFormat); + RuntimeInit(File projectDir) { ///////////////////////////////// // USER AND SYSTEM-WIDE VALUES // ///////////////////////////////// From 986cda366250925537005fe6072561043afa1f4b Mon Sep 17 00:00:00 2001 From: Ned Twigg Date: Fri, 6 May 2022 13:20:00 -0700 Subject: [PATCH 118/757] Added a lazy version of `createIndependentApplyTask`. --- .../gradle/spotless/FormatExtension.java | 28 +++++++++++-------- 1 file changed, 17 insertions(+), 11 deletions(-) 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 d8c5525db6..94ae136429 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 @@ -38,6 +38,7 @@ import org.gradle.api.file.ConfigurableFileTree; import org.gradle.api.file.FileCollection; import org.gradle.api.plugins.BasePlugin; +import org.gradle.api.tasks.TaskProvider; import com.diffplug.common.base.Preconditions; import com.diffplug.spotless.FormatExceptionPolicyStrict; @@ -769,6 +770,11 @@ protected Project getProject() { return spotless.project; } + /** Eager version of {@link #createIndependentApplyTaskLazy(String)} */ + public SpotlessApply createIndependentApplyTask(String taskName) { + return createIndependentApplyTaskLazy(taskName).get(); + } + /** * Creates an independent {@link SpotlessApply} for (very) unusual circumstances. * @@ -782,19 +788,19 @@ protected Project getProject() { * * NOTE: does not respect the rarely-used {@code spotlessFiles} property. */ - public SpotlessApply createIndependentApplyTask(String taskName) { + public TaskProvider createIndependentApplyTaskLazy(String taskName) { Preconditions.checkArgument(!taskName.endsWith(SpotlessExtension.APPLY), "Task name must not end with " + SpotlessExtension.APPLY); - // create and setup the task - SpotlessTaskImpl spotlessTask = spotless.project.getTasks().create(taskName + SpotlessTaskService.INDEPENDENT_HELPER, SpotlessTaskImpl.class); - spotlessTask.init(spotless.getRegisterDependenciesTask().getTaskService()); - setupTask(spotlessTask); - // clean removes the SpotlessCache, so we have to run after clean - spotlessTask.mustRunAfter(BasePlugin.CLEAN_TASK_NAME); + TaskProvider spotlessTask = spotless.project.getTasks().register(taskName + SpotlessTaskService.INDEPENDENT_HELPER, SpotlessTaskImpl.class, task -> { + task.init(spotless.getRegisterDependenciesTask().getTaskService()); + setupTask(task); + // clean removes the SpotlessCache, so we have to run after clean + task.mustRunAfter(BasePlugin.CLEAN_TASK_NAME); + }); // create the apply task - SpotlessApply applyTask = spotless.project.getTasks().create(taskName, SpotlessApply.class); - applyTask.init(spotlessTask); - applyTask.dependsOn(spotlessTask); - + TaskProvider applyTask = spotless.project.getTasks().register(taskName, SpotlessApply.class, task -> { + task.dependsOn(spotlessTask); + task.init(spotlessTask.get()); + }); return applyTask; } From 9b5510af72cf560948d0886c0694cfee2f9a9764 Mon Sep 17 00:00:00 2001 From: Ned Twigg Date: Fri, 6 May 2022 13:49:24 -0700 Subject: [PATCH 119/757] Fix caching memory leak in lazy FormatterSteps. --- .../java/com/diffplug/spotless/FormatterStepImpl.java | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/lib/src/main/java/com/diffplug/spotless/FormatterStepImpl.java b/lib/src/main/java/com/diffplug/spotless/FormatterStepImpl.java index 061aff6af9..7663145f51 100644 --- a/lib/src/main/java/com/diffplug/spotless/FormatterStepImpl.java +++ b/lib/src/main/java/com/diffplug/spotless/FormatterStepImpl.java @@ -1,5 +1,5 @@ /* - * Copyright 2016-2020 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. @@ -39,7 +39,7 @@ abstract class FormatterStepImpl extends Strict stateSupplier; + transient ThrowingEx.Supplier stateSupplier; FormatterStepImpl(String name, ThrowingEx.Supplier stateSupplier) { this.name = Objects.requireNonNull(name); @@ -53,7 +53,11 @@ public String getName() { @Override protected State calculateState() throws Exception { - return stateSupplier.get(); + // LazyForwardingEquality guarantees that this will only be called once, and keeping toFormat + // causes a memory leak, see https://github.com/diffplug/spotless/issues/1194 + State state = stateSupplier.get(); + stateSupplier = null; + return state; } static final class Standard extends FormatterStepImpl { From a0a96e379c31b092085bc9f4cf7591ce4df8b458 Mon Sep 17 00:00:00 2001 From: Ned Twigg Date: Sun, 8 May 2022 18:11:52 -0700 Subject: [PATCH 120/757] Update changelogs. --- CHANGES.md | 1 + plugin-gradle/CHANGES.md | 3 +++ 2 files changed, 4 insertions(+) diff --git a/CHANGES.md b/CHANGES.md index e7427e178d..7eb1c33afe 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -12,6 +12,7 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format ( ## [Unreleased] ### Fixed * Update the `black` version regex to fix `19.10b0` and earlier. (fixes [#1195](https://github.com/diffplug/spotless/issues/1195), regression introduced in `2.25.0`) +* `GitAttributesLineEndings$RelocatablePolicy` and `FormatterStepImpl` now null-out their initialization lambdas after their state has been calculated, which allows GC to collect variables which were incidentally captured but not needed in the calculated state. ([#1198](https://github.com/diffplug/spotless/pull/1198)) ## [2.25.2] - 2022-05-03 ### Changes diff --git a/plugin-gradle/CHANGES.md b/plugin-gradle/CHANGES.md index 963d6d06d7..b8531d3812 100644 --- a/plugin-gradle/CHANGES.md +++ b/plugin-gradle/CHANGES.md @@ -3,8 +3,11 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format (starting after version `3.27.0`). ## [Unreleased] +### Added +* `FormatExtension.createIndependentApplyTaskLazy`, with same functionality as `createIndependentApplyTaskLazy` but returning `TaskProvider` ([#1198](https://github.com/diffplug/spotless/pull/1198)) ### Fixed * Update the `black` version regex to fix `19.10b0` and earlier. (fixes [#1195](https://github.com/diffplug/spotless/issues/1195), regression introduced in `6.5.0`) +* Improved daemon memory consumption ([#1198](https://github.com/diffplug/spotless/pull/1198) fixes [#1194](https://github.com/diffplug/spotless/issues/1194)) ## [6.5.2] - 2022-05-03 ### Changes From d42c78d52177fe55876bef556548da4e39d2d9cc Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 9 May 2022 12:03:38 +0000 Subject: [PATCH 121/757] Bump ktfmt from 0.36 to 0.37 Bumps [ktfmt](https://github.com/facebookincubator/ktfmt) from 0.36 to 0.37. - [Release notes](https://github.com/facebookincubator/ktfmt/releases) - [Commits](https://github.com/facebookincubator/ktfmt/compare/v0.36...v0.37) --- updated-dependencies: - dependency-name: com.facebook:ktfmt dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] --- lib/build.gradle | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/build.gradle b/lib/build.gradle index ccfb9b1b79..2eb0f3e0e5 100644 --- a/lib/build.gradle +++ b/lib/build.gradle @@ -36,7 +36,7 @@ dependencies { palantirJavaFormatCompileOnly 'com.palantir.javaformat:palantir-java-format:1.1.0' - String VER_KTFMT = '0.36' + String VER_KTFMT = '0.37' 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") { From 2be12910f62f2883330e064f44a6cc2f74ac52bf Mon Sep 17 00:00:00 2001 From: Ned Twigg Date: Mon, 9 May 2022 16:51:07 -0700 Subject: [PATCH 122/757] JvmLocalCache should force state evaluation of any LazyForwardingEquality to give it a chance to null-out its initializing lambda. Addresses https://github.com/diffplug/spotless/issues/1194#issuecomment-1120744842 --- .../com/diffplug/spotless/LazyForwardingEquality.java | 7 ++++++- .../java/com/diffplug/gradle/spotless/JvmLocalCache.java | 8 +++++++- 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/lib/src/main/java/com/diffplug/spotless/LazyForwardingEquality.java b/lib/src/main/java/com/diffplug/spotless/LazyForwardingEquality.java index 05e758d586..e29464bd91 100644 --- a/lib/src/main/java/com/diffplug/spotless/LazyForwardingEquality.java +++ b/lib/src/main/java/com/diffplug/spotless/LazyForwardingEquality.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. @@ -111,4 +111,9 @@ static byte[] toBytes(Serializable obj) { } return byteOutput.toByteArray(); } + + /** Ensures that the lazy state has been evaluated. */ + public static void unlazy(LazyForwardingEquality in) { + in.state(); + } } diff --git a/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/JvmLocalCache.java b/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/JvmLocalCache.java index 9478e9e66f..3f03a5852b 100644 --- a/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/JvmLocalCache.java +++ b/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/JvmLocalCache.java @@ -1,5 +1,5 @@ /* - * Copyright 2021 DiffPlug + * Copyright 2021-2022 DiffPlug * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -26,6 +26,7 @@ import org.gradle.api.Task; import com.diffplug.spotless.FileSignature; +import com.diffplug.spotless.LazyForwardingEquality; class JvmLocalCache { private static GradleException cacheIsStale() { @@ -53,6 +54,11 @@ static class LiveCacheKeyImpl implements LiveCache, Serializable { @Override public void set(T value) { + if (value instanceof LazyForwardingEquality) { + // whenever we cache an instance of LazyForwardingEquality, we want to make sure that we give it + // a chance to null-out its initialization lambda (see https://github.com/diffplug/spotless/issues/1194#issuecomment-1120744842) + LazyForwardingEquality.unlazy((LazyForwardingEquality) value); + } daemonState.put(internalKey, value); } From 27271d1552c19e9d8775368306ab433c7a9dff65 Mon Sep 17 00:00:00 2001 From: Ned Twigg Date: Mon, 9 May 2022 17:07:20 -0700 Subject: [PATCH 123/757] Bump default ktfmt to latest 0.36 -> 0.37 --- lib/src/main/java/com/diffplug/spotless/kotlin/KtfmtStep.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 86b036db3b..b7ade56b5f 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.36"; + private static final String DEFAULT_VERSION = "0.37"; static final String NAME = "ktfmt"; static final String PACKAGE = "com.facebook"; static final String MAVEN_COORDINATE = PACKAGE + ":ktfmt:"; From 2a1c3216f75068e77b17bc9851328f75ffdd046a Mon Sep 17 00:00:00 2001 From: Ned Twigg Date: Mon, 9 May 2022 17:07:30 -0700 Subject: [PATCH 124/757] Bump changes to latest. --- CHANGES.md | 2 ++ plugin-gradle/CHANGES.md | 2 ++ plugin-maven/CHANGES.md | 2 ++ 3 files changed, 6 insertions(+) diff --git a/CHANGES.md b/CHANGES.md index 7eb1c33afe..11562e8047 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -13,6 +13,8 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format ( ### Fixed * Update the `black` version regex to fix `19.10b0` and earlier. (fixes [#1195](https://github.com/diffplug/spotless/issues/1195), regression introduced in `2.25.0`) * `GitAttributesLineEndings$RelocatablePolicy` and `FormatterStepImpl` now null-out their initialization lambdas after their state has been calculated, which allows GC to collect variables which were incidentally captured but not needed in the calculated state. ([#1198](https://github.com/diffplug/spotless/pull/1198)) +### Changes +* Bump default `ktfmt` version to latest `0.36` -> `0.37`. ([#1200](https://github.com/diffplug/spotless/pull/1200)) ## [2.25.2] - 2022-05-03 ### Changes diff --git a/plugin-gradle/CHANGES.md b/plugin-gradle/CHANGES.md index b8531d3812..74f75fff75 100644 --- a/plugin-gradle/CHANGES.md +++ b/plugin-gradle/CHANGES.md @@ -8,6 +8,8 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format ( ### Fixed * Update the `black` version regex to fix `19.10b0` and earlier. (fixes [#1195](https://github.com/diffplug/spotless/issues/1195), regression introduced in `6.5.0`) * Improved daemon memory consumption ([#1198](https://github.com/diffplug/spotless/pull/1198) fixes [#1194](https://github.com/diffplug/spotless/issues/1194)) +### Changes +* Bump default `ktfmt` version to latest `0.36` -> `0.37`. ([#1200](https://github.com/diffplug/spotless/pull/1200)) ## [6.5.2] - 2022-05-03 ### Changes diff --git a/plugin-maven/CHANGES.md b/plugin-maven/CHANGES.md index 08cad5cfa9..de8f0c2be0 100644 --- a/plugin-maven/CHANGES.md +++ b/plugin-maven/CHANGES.md @@ -5,6 +5,8 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format ( ## [Unreleased] ### Fixed * Update the `black` version regex to fix `19.10b0` and earlier. (fixes [#1195](https://github.com/diffplug/spotless/issues/1195), regression introduced in `2.22.2`) +### Changes +* Bump default `ktfmt` version to latest `0.36` -> `0.37`. ([#1200](https://github.com/diffplug/spotless/pull/1200)) ## [2.22.4] - 2022-05-03 ### Changes From 424e42aa93c21f0d02efad28882453857abb1dde Mon Sep 17 00:00:00 2001 From: Ned Twigg Date: Tue, 10 May 2022 09:45:41 -0700 Subject: [PATCH 125/757] LazyForwardingEquality can now unlazy a `FormatterStep` which has a delegate field, a well as a `List`. Fixes https://github.com/diffplug/spotless/issues/1194#issuecomment-1122034178 --- .../spotless/DelegateFormatterStep.java | 32 +++++++++++++++++++ .../FilterByContentPatternFormatterStep.java | 14 ++------ .../spotless/FilterByFileFormatterStep.java | 12 ++----- .../spotless/LazyForwardingEquality.java | 13 ++++++-- 4 files changed, 49 insertions(+), 22 deletions(-) create mode 100644 lib/src/main/java/com/diffplug/spotless/DelegateFormatterStep.java diff --git a/lib/src/main/java/com/diffplug/spotless/DelegateFormatterStep.java b/lib/src/main/java/com/diffplug/spotless/DelegateFormatterStep.java new file mode 100644 index 0000000000..829652a5dc --- /dev/null +++ b/lib/src/main/java/com/diffplug/spotless/DelegateFormatterStep.java @@ -0,0 +1,32 @@ +/* + * Copyright 2022 DiffPlug + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.diffplug.spotless; + +import java.util.Objects; + +/** Superclass of all compound FormatterSteps necessary for {@link com.diffplug.spotless.LazyForwardingEquality#unlazy(java.lang.Object)}. */ +abstract class DelegateFormatterStep implements FormatterStep { + protected final FormatterStep delegateStep; + + DelegateFormatterStep(FormatterStep delegateStep) { + this.delegateStep = Objects.requireNonNull(delegateStep); + } + + @Override + public final String getName() { + return delegateStep.getName(); + } +} diff --git a/lib/src/main/java/com/diffplug/spotless/FilterByContentPatternFormatterStep.java b/lib/src/main/java/com/diffplug/spotless/FilterByContentPatternFormatterStep.java index 9b39361719..d9a6fe4093 100644 --- a/lib/src/main/java/com/diffplug/spotless/FilterByContentPatternFormatterStep.java +++ b/lib/src/main/java/com/diffplug/spotless/FilterByContentPatternFormatterStep.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. @@ -22,27 +22,19 @@ import javax.annotation.Nullable; -final class FilterByContentPatternFormatterStep implements FormatterStep { - private final FormatterStep delegateStep; +final class FilterByContentPatternFormatterStep extends DelegateFormatterStep { final Pattern contentPattern; FilterByContentPatternFormatterStep(FormatterStep delegateStep, String contentPattern) { - this.delegateStep = Objects.requireNonNull(delegateStep); + super(delegateStep); this.contentPattern = Pattern.compile(Objects.requireNonNull(contentPattern)); } - @Override - public String getName() { - return delegateStep.getName(); - } - @Override public @Nullable String format(String raw, File file) throws Exception { Objects.requireNonNull(raw, "raw"); Objects.requireNonNull(file, "file"); - Matcher matcher = contentPattern.matcher(raw); - if (matcher.find()) { return delegateStep.format(raw, file); } else { diff --git a/lib/src/main/java/com/diffplug/spotless/FilterByFileFormatterStep.java b/lib/src/main/java/com/diffplug/spotless/FilterByFileFormatterStep.java index 2fd221220c..04a06a4673 100644 --- a/lib/src/main/java/com/diffplug/spotless/FilterByFileFormatterStep.java +++ b/lib/src/main/java/com/diffplug/spotless/FilterByFileFormatterStep.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. @@ -20,20 +20,14 @@ import javax.annotation.Nullable; -final class FilterByFileFormatterStep implements FormatterStep { - private final FormatterStep delegateStep; +final class FilterByFileFormatterStep extends DelegateFormatterStep { private final SerializableFileFilter filter; FilterByFileFormatterStep(FormatterStep delegateStep, SerializableFileFilter filter) { - this.delegateStep = Objects.requireNonNull(delegateStep); + super(delegateStep); this.filter = Objects.requireNonNull(filter); } - @Override - public String getName() { - return delegateStep.getName(); - } - @Override public @Nullable String format(String raw, File file) throws Exception { Objects.requireNonNull(raw, "raw"); diff --git a/lib/src/main/java/com/diffplug/spotless/LazyForwardingEquality.java b/lib/src/main/java/com/diffplug/spotless/LazyForwardingEquality.java index e29464bd91..e2d6ba8988 100644 --- a/lib/src/main/java/com/diffplug/spotless/LazyForwardingEquality.java +++ b/lib/src/main/java/com/diffplug/spotless/LazyForwardingEquality.java @@ -113,7 +113,16 @@ static byte[] toBytes(Serializable obj) { } /** Ensures that the lazy state has been evaluated. */ - public static void unlazy(LazyForwardingEquality in) { - in.state(); + public static void unlazy(Object in) { + if (in instanceof LazyForwardingEquality) { + ((LazyForwardingEquality) in).state(); + } else if (in instanceof DelegateFormatterStep) { + unlazy(((DelegateFormatterStep) in).delegateStep); + } else if (in instanceof Iterable) { + Iterable cast = (Iterable) in; + for (Object c : cast) { + unlazy(c); + } + } } } From 628c5fcbe3e1ed85c895c0d2fe5bf9ebadf47bd6 Mon Sep 17 00:00:00 2001 From: Ned Twigg Date: Tue, 10 May 2022 13:32:28 -0700 Subject: [PATCH 126/757] Fix spotbugs warning about `\n` vs `%n`. --- .../java/com/diffplug/gradle/spotless/GradleProvisioner.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/GradleProvisioner.java b/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/GradleProvisioner.java index 63697afca2..97f051cd86 100644 --- a/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/GradleProvisioner.java +++ b/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/GradleProvisioner.java @@ -128,7 +128,7 @@ private static Provisioner forConfigurationContainer(Project project, Configurat projName = projName + "/"; } throw new GradleException(String.format( - "You need to add a repository containing the '%s' artifact in '%sbuild.gradle'.\n" + + "You need to add a repository containing the '%s' artifact in '%sbuild.gradle'.%n" + "E.g.: 'repositories { mavenCentral() }'", mavenCoords, projName), e); } From 619fdcbf626f6ed929182834317eb5a3d646da09 Mon Sep 17 00:00:00 2001 From: circleci Date: Tue, 10 May 2022 22:50:59 +0000 Subject: [PATCH 127/757] Published lib/2.25.3 --- CHANGES.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/CHANGES.md b/CHANGES.md index 11562e8047..8d2011de17 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -10,6 +10,8 @@ This document is intended for Spotless developers. We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format (starting after version `1.27.0`). ## [Unreleased] + +## [2.25.3] - 2022-05-10 ### Fixed * Update the `black` version regex to fix `19.10b0` and earlier. (fixes [#1195](https://github.com/diffplug/spotless/issues/1195), regression introduced in `2.25.0`) * `GitAttributesLineEndings$RelocatablePolicy` and `FormatterStepImpl` now null-out their initialization lambdas after their state has been calculated, which allows GC to collect variables which were incidentally captured but not needed in the calculated state. ([#1198](https://github.com/diffplug/spotless/pull/1198)) From be2897247ffd28814b83fcdf9b440e5d541052c0 Mon Sep 17 00:00:00 2001 From: circleci Date: Tue, 10 May 2022 22:51:46 +0000 Subject: [PATCH 128/757] Published gradle/6.6.0 --- plugin-gradle/CHANGES.md | 2 ++ plugin-gradle/README.md | 46 ++++++++++++++++++++-------------------- 2 files changed, 25 insertions(+), 23 deletions(-) diff --git a/plugin-gradle/CHANGES.md b/plugin-gradle/CHANGES.md index 74f75fff75..fe7b0f879f 100644 --- a/plugin-gradle/CHANGES.md +++ b/plugin-gradle/CHANGES.md @@ -3,6 +3,8 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format (starting after version `3.27.0`). ## [Unreleased] + +## [6.6.0] - 2022-05-10 ### Added * `FormatExtension.createIndependentApplyTaskLazy`, with same functionality as `createIndependentApplyTaskLazy` but returning `TaskProvider` ([#1198](https://github.com/diffplug/spotless/pull/1198)) ### Fixed diff --git a/plugin-gradle/README.md b/plugin-gradle/README.md index bc6d28b72c..06ba04d45e 100644 --- a/plugin-gradle/README.md +++ b/plugin-gradle/README.md @@ -18,9 +18,9 @@ output = [ --> [![Gradle plugin](https://img.shields.io/badge/plugins.gradle.org-com.diffplug.spotless-blue.svg)](https://plugins.gradle.org/plugin/com.diffplug.spotless) [![Maven central](https://img.shields.io/badge/mavencentral-yes-blue.svg)](https://search.maven.org/#search%7Cgav%7C1%7Cg%3A%22com.diffplug.spotless%22%20AND%20a%3A%22spotless-plugin-gradle%22) -[![Javadoc](https://img.shields.io/badge/javadoc-yes-blue.svg)](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.5.2/index.html) +[![Javadoc](https://img.shields.io/badge/javadoc-yes-blue.svg)](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.6.0/index.html) [![License Apache](https://img.shields.io/badge/license-apache-blue.svg)](https://tldrlegal.com/license/apache-license-2.0-(apache-2.0)) -[![Changelog](https://img.shields.io/badge/changelog-6.5.2-blue.svg)](CHANGES.md) +[![Changelog](https://img.shields.io/badge/changelog-6.6.0-blue.svg)](CHANGES.md) [![Circle CI](https://circleci.com/gh/diffplug/spotless/tree/main.svg?style=shield)](https://circleci.com/gh/diffplug/spotless/tree/main) [![Live chat](https://img.shields.io/badge/gitter-chat-brightgreen.svg)](https://gitter.im/diffplug/spotless) @@ -126,10 +126,10 @@ spotless { ``` Spotless consists of a list of formats (in the example above, `misc` and `java`), and each format has: -- a `target` (the files to format), which you set with [`target`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.5.2/com/diffplug/gradle/spotless/FormatExtension.html#target-java.lang.Object...-) and [`targetExclude`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.5.2/com/diffplug/gradle/spotless/FormatExtension.html#targetExclude-java.lang.Object...-) -- a list of `FormatterStep`, which are just `String -> String` functions, such as [`replace`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.5.2/com/diffplug/gradle/spotless/FormatExtension.html#replace-java.lang.String-java.lang.CharSequence-java.lang.CharSequence-), [`replaceRegex`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.5.2/com/diffplug/gradle/spotless/FormatExtension.html#replaceRegex-java.lang.String-java.lang.String-java.lang.String-), [`trimTrailingWhitespace`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.5.2/com/diffplug/gradle/spotless/FormatExtension.html#replace-java.lang.String-java.lang.CharSequence-java.lang.CharSequence-), [`custom`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.5.2/com/diffplug/gradle/spotless/FormatExtension.html#custom-java.lang.String-groovy.lang.Closure-), [`prettier`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.5.2/com/diffplug/gradle/spotless/FormatExtension.html#prettier--), [`eclipseWtp`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.5.2/com/diffplug/gradle/spotless/FormatExtension.html#eclipseWtp-com.diffplug.spotless.extra.wtp.EclipseWtpFormatterStep-), [`licenseHeader`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.5.2/com/diffplug/gradle/spotless/FormatExtension.html#licenseHeader-java.lang.String-java.lang.String-) etc. +- a `target` (the files to format), which you set with [`target`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.6.0/com/diffplug/gradle/spotless/FormatExtension.html#target-java.lang.Object...-) and [`targetExclude`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.6.0/com/diffplug/gradle/spotless/FormatExtension.html#targetExclude-java.lang.Object...-) +- a list of `FormatterStep`, which are just `String -> String` functions, such as [`replace`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.6.0/com/diffplug/gradle/spotless/FormatExtension.html#replace-java.lang.String-java.lang.CharSequence-java.lang.CharSequence-), [`replaceRegex`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.6.0/com/diffplug/gradle/spotless/FormatExtension.html#replaceRegex-java.lang.String-java.lang.String-java.lang.String-), [`trimTrailingWhitespace`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.6.0/com/diffplug/gradle/spotless/FormatExtension.html#replace-java.lang.String-java.lang.CharSequence-java.lang.CharSequence-), [`custom`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.6.0/com/diffplug/gradle/spotless/FormatExtension.html#custom-java.lang.String-groovy.lang.Closure-), [`prettier`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.6.0/com/diffplug/gradle/spotless/FormatExtension.html#prettier--), [`eclipseWtp`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.6.0/com/diffplug/gradle/spotless/FormatExtension.html#eclipseWtp-com.diffplug.spotless.extra.wtp.EclipseWtpFormatterStep-), [`licenseHeader`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.6.0/com/diffplug/gradle/spotless/FormatExtension.html#licenseHeader-java.lang.String-java.lang.String-) etc. -All the generic steps live in [`FormatExtension`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.5.2/com/diffplug/gradle/spotless/FormatExtension.html), and there are many language-specific steps which live in its language-specific subclasses, which are described below. +All the generic steps live in [`FormatExtension`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.6.0/com/diffplug/gradle/spotless/FormatExtension.html), and there are many language-specific steps which live in its language-specific subclasses, which are described below. ### Requirements @@ -141,7 +141,7 @@ If you're stuck on an older version of Gradle, `id 'com.diffplug.gradle.spotless ## Java -`com.diffplug.gradle.spotless.JavaExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.5.2/com/diffplug/gradle/spotless/JavaExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/JavaExtension.java) +`com.diffplug.gradle.spotless.JavaExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.6.0/com/diffplug/gradle/spotless/JavaExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/JavaExtension.java) ```gradle spotless { @@ -248,8 +248,8 @@ spotless { ## Groovy -- `com.diffplug.gradle.spotless.GroovyExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.5.2/com/diffplug/gradle/spotless/GroovyExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/GroovyExtension.java) -- `com.diffplug.gradle.spotless.GroovyGradleExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.5.2/com/diffplug/gradle/spotless/GroovyGradleExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/GroovyGradleExtension.java) +- `com.diffplug.gradle.spotless.GroovyExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.6.0/com/diffplug/gradle/spotless/GroovyExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/GroovyExtension.java) +- `com.diffplug.gradle.spotless.GroovyGradleExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.6.0/com/diffplug/gradle/spotless/GroovyGradleExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/GroovyGradleExtension.java) Configuration for Groovy is similar to [Java](#java), in that it also supports `licenseHeader` and `importOrder`. @@ -300,8 +300,8 @@ Groovy-Eclipse formatting errors/warnings lead per default to a build failure. T ## Kotlin -- `com.diffplug.gradle.spotless.KotlinExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.5.2/com/diffplug/gradle/spotless/KotlinExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/KotlinExtension.java) -- `com.diffplug.gradle.spotless.KotlinGradleExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.5.2/com/diffplug/gradle/spotless/KotlinGradleExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/KotlinGradleExtension.java) +- `com.diffplug.gradle.spotless.KotlinExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.6.0/com/diffplug/gradle/spotless/KotlinExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/KotlinExtension.java) +- `com.diffplug.gradle.spotless.KotlinGradleExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.6.0/com/diffplug/gradle/spotless/KotlinGradleExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/KotlinGradleExtension.java) ```gradle spotless { // if you are using build.gradle.kts, instead of 'spotless {' use: @@ -361,7 +361,7 @@ spotless { ## Scala -`com.diffplug.gradle.spotless.ScalaExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.5.2/com/diffplug/gradle/spotless/ScalaExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/ScalaExtension.java) +`com.diffplug.gradle.spotless.ScalaExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.6.0/com/diffplug/gradle/spotless/ScalaExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/ScalaExtension.java) ```gradle spotless { @@ -393,7 +393,7 @@ spotless { ## C/C++ -`com.diffplug.gradle.spotless.CppExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.5.2/com/diffplug/gradle/spotless/CppExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/CppExtension.java) +`com.diffplug.gradle.spotless.CppExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.6.0/com/diffplug/gradle/spotless/CppExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/CppExtension.java) ```gradle spotless { @@ -425,7 +425,7 @@ spotles { ## Python -`com.diffplug.gradle.spotless.PythonExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.5.2/com/diffplug/gradle/spotless/PythonExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/PythonExtension.java) +`com.diffplug.gradle.spotless.PythonExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.6.0/com/diffplug/gradle/spotless/PythonExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/PythonExtension.java) ```gradle spotless { @@ -459,7 +459,7 @@ black().pathToExe('C:/myuser/.pyenv/versions/3.8.0/scripts/black.exe') ## FreshMark -`com.diffplug.gradle.spotless.FreshMarkExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.5.2/com/diffplug/gradle/spotless/FreshMarkExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/FreshMarkExtension.java) +`com.diffplug.gradle.spotless.FreshMarkExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.6.0/com/diffplug/gradle/spotless/FreshMarkExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/FreshMarkExtension.java) [homepage](https://github.com/diffplug/freshmark). [changelog](https://github.com/diffplug/freshmark/blob/master/CHANGES.md). FreshMark lets you generate markdown in the comments of your markdown. This helps to keep badges and links up-to-date (see the source for this file), and can also be helpful for generating complex tables (see the source for [the parent readme](../README.md)). @@ -480,7 +480,7 @@ spotless { ## Antlr4 -`com.diffplug.gradle.spotless.Antlr4Extension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.5.2/com/diffplug/gradle/spotless/Antlr4Extension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/Antlr4Extension.java) +`com.diffplug.gradle.spotless.Antlr4Extension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.6.0/com/diffplug/gradle/spotless/Antlr4Extension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/Antlr4Extension.java) ```gradle spotless { @@ -505,7 +505,7 @@ antlr4formatter('1.2.1') // version is optional ## SQL -`com.diffplug.gradle.spotless.SqlExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.5.2/com/diffplug/gradle/spotless/SqlExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/SqlExtension.java) +`com.diffplug.gradle.spotless.SqlExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.6.0/com/diffplug/gradle/spotless/SqlExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/SqlExtension.java) ```gradle spotless { @@ -545,7 +545,7 @@ sql.formatter.indent.size=4 ## Typescript -- `com.diffplug.gradle.spotless.TypescriptExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.5.2/com/diffplug/gradle/spotless/TypescriptExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/TypescriptExtension.java) +- `com.diffplug.gradle.spotless.TypescriptExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.6.0/com/diffplug/gradle/spotless/TypescriptExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/TypescriptExtension.java) ```gradle spotless { @@ -588,7 +588,7 @@ For details, see the [npm detection](#npm-detection) and [`.npmrc` detection](#n ## JSON -- `com.diffplug.gradle.spotless.JsonExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.5.2/com/diffplug/gradle/spotless/JsonExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/JsonExtension.java) +- `com.diffplug.gradle.spotless.JsonExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.6.0/com/diffplug/gradle/spotless/JsonExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/JsonExtension.java) ```gradle spotless { @@ -813,7 +813,7 @@ Once a file's license header has a valid year, whether it is a year (`2020`) or * `2017` -> `2017-2020` * `2017-2019` -> `2017-2020` -See the [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.5.2/com/diffplug/gradle/spotless/FormatExtension.LicenseHeaderConfig.html) for a complete listing of options. +See the [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.6.0/com/diffplug/gradle/spotless/FormatExtension.LicenseHeaderConfig.html) for a complete listing of options. @@ -880,9 +880,9 @@ spotless { custom 'lowercase', { str -> str.toLowerCase() } ``` -However, custom rules will disable up-to-date checking and caching, unless you read [this javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.5.2/com/diffplug/gradle/spotless/FormatExtension.html#bumpThisNumberIfACustomStepChanges-int-) and follow its instructions carefully. +However, custom rules will disable up-to-date checking and caching, unless you read [this javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.6.0/com/diffplug/gradle/spotless/FormatExtension.html#bumpThisNumberIfACustomStepChanges-int-) and follow its instructions carefully. -Another option is to create proper `FormatterStep` in your `buildSrc`, and then call [`addStep`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.5.2/com/diffplug/gradle/spotless/FormatExtension.html#addStep-com.diffplug.spotless.FormatterStep-). The contributing guide describes [how to do this](https://github.com/diffplug/spotless/blob/main/CONTRIBUTING.md#how-to-add-a-new-formatterstep). If the step is generally-useful, we hope you'll open a PR to share it! +Another option is to create proper `FormatterStep` in your `buildSrc`, and then call [`addStep`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.6.0/com/diffplug/gradle/spotless/FormatExtension.html#addStep-com.diffplug.spotless.FormatterStep-). The contributing guide describes [how to do this](https://github.com/diffplug/spotless/blob/main/CONTRIBUTING.md#how-to-add-a-new-formatterstep). If the step is generally-useful, we hope you'll open a PR to share it! ```gradle @@ -915,11 +915,11 @@ spotless { format 'foo', com.acme.FooLanguageExtension, { ``` -If you'd like to create a one-off Spotless task outside of the `check`/`apply` framework, see [`FormatExtension.createIndependentApplyTask`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.5.2/com/diffplug/gradle/spotless/FormatExtension.html#createIndependentApplyTask-java.lang.String-). +If you'd like to create a one-off Spotless task outside of the `check`/`apply` framework, see [`FormatExtension.createIndependentApplyTask`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.6.0/com/diffplug/gradle/spotless/FormatExtension.html#createIndependentApplyTask-java.lang.String-). ## Inception (languages within languages within...) -In very rare cases, you might want to format e.g. javascript which is written inside JSP templates, or maybe java within a markdown file, or something wacky like that. You can specify hunks within a file using either open/close tags or a regex with a single capturing group, and then specify rules within it, like so. See [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.5.2/com/diffplug/gradle/spotless/FormatExtension.html#withinBlocks-java.lang.String-java.lang.String-java.lang.String-org.gradle.api.Action-) for more details. +In very rare cases, you might want to format e.g. javascript which is written inside JSP templates, or maybe java within a markdown file, or something wacky like that. You can specify hunks within a file using either open/close tags or a regex with a single capturing group, and then specify rules within it, like so. See [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.6.0/com/diffplug/gradle/spotless/FormatExtension.html#withinBlocks-java.lang.String-java.lang.String-java.lang.String-org.gradle.api.Action-) for more details. ```gradle import com.diffplug.gradle.spotless.JavaExtension From 8b3e85dbb5a1cb8f0f8be4978f296dd3abf8852d Mon Sep 17 00:00:00 2001 From: circleci Date: Tue, 10 May 2022 22:53:18 +0000 Subject: [PATCH 129/757] Published maven/2.22.5 --- plugin-maven/CHANGES.md | 2 ++ plugin-maven/README.md | 4 ++-- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/plugin-maven/CHANGES.md b/plugin-maven/CHANGES.md index de8f0c2be0..a0dbcc1d97 100644 --- a/plugin-maven/CHANGES.md +++ b/plugin-maven/CHANGES.md @@ -3,6 +3,8 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format (starting after version `1.27.0`). ## [Unreleased] + +## [2.22.5] - 2022-05-10 ### Fixed * Update the `black` version regex to fix `19.10b0` and earlier. (fixes [#1195](https://github.com/diffplug/spotless/issues/1195), regression introduced in `2.22.2`) ### Changes diff --git a/plugin-maven/README.md b/plugin-maven/README.md index b3bab5af71..3486a37255 100644 --- a/plugin-maven/README.md +++ b/plugin-maven/README.md @@ -12,8 +12,8 @@ output = [ ].join('\n'); --> [![Maven central](https://img.shields.io/badge/mavencentral-com.diffplug.spotless%3Aspotless--maven--plugin-blue.svg)](https://search.maven.org/#search%7Cgav%7C1%7Cg%3A%22com.diffplug.spotless%22%20AND%20a%3A%22spotless-maven-plugin%22) -[![Javadoc](https://img.shields.io/badge/javadoc-yes-blue.svg)](https://javadoc.io/doc/com.diffplug.spotless/spotless-maven-plugin/2.22.4/index.html) -[![Changelog](https://img.shields.io/badge/changelog-2.22.4-brightgreen.svg)](CHANGES.md) +[![Javadoc](https://img.shields.io/badge/javadoc-yes-blue.svg)](https://javadoc.io/doc/com.diffplug.spotless/spotless-maven-plugin/2.22.5/index.html) +[![Changelog](https://img.shields.io/badge/changelog-2.22.5-brightgreen.svg)](CHANGES.md) [![Circle CI](https://circleci.com/gh/diffplug/spotless/tree/main.svg?style=shield)](https://circleci.com/gh/diffplug/spotless/tree/main) [![Live chat](https://img.shields.io/badge/gitter-chat-brightgreen.svg)](https://gitter.im/diffplug/spotless) From e8cc5401d450350659f9592a7a5942ad9cea937a Mon Sep 17 00:00:00 2001 From: Per Lundberg Date: Thu, 12 May 2022 10:44:36 +0300 Subject: [PATCH 130/757] Update README.md Remove superfluous backtick --- plugin-gradle/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugin-gradle/README.md b/plugin-gradle/README.md index 06ba04d45e..48572377b8 100644 --- a/plugin-gradle/README.md +++ b/plugin-gradle/README.md @@ -135,7 +135,7 @@ All the generic steps live in [`FormatExtension`](https://javadoc.io/doc/com.dif Spotless requires JRE 8+, and Gradle 6.1.1+. Some steps require JRE 11+, `Unsupported major.minor version` means you're using a step that needs a newer JRE. -If you're stuck on an older version of Gradle, `id 'com.diffplug.gradle.spotless' version '4.5.1'` supports all the way back to Gradle 2.x`. +If you're stuck on an older version of Gradle, `id 'com.diffplug.gradle.spotless' version '4.5.1'` supports all the way back to Gradle 2.x. From ce19481aa71310a8125f6472230232e43958f260 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lars=20K=C3=B6dderitzsch?= Date: Thu, 12 May 2022 11:29:03 +0200 Subject: [PATCH 131/757] unlazy collections/delegates #1194 unlazy collections/delegates --- .../java/com/diffplug/gradle/spotless/JvmLocalCache.java | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/JvmLocalCache.java b/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/JvmLocalCache.java index 3f03a5852b..bcc480b7c6 100644 --- a/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/JvmLocalCache.java +++ b/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/JvmLocalCache.java @@ -54,11 +54,10 @@ static class LiveCacheKeyImpl implements LiveCache, Serializable { @Override public void set(T value) { - if (value instanceof LazyForwardingEquality) { - // whenever we cache an instance of LazyForwardingEquality, we want to make sure that we give it - // a chance to null-out its initialization lambda (see https://github.com/diffplug/spotless/issues/1194#issuecomment-1120744842) - LazyForwardingEquality.unlazy((LazyForwardingEquality) value); - } + + // whenever we cache an instance of LazyForwardingEquality, we want to make sure that we give it + // a chance to null-out its initialization lambda (see https://github.com/diffplug/spotless/issues/1194#issuecomment-1120744842) + LazyForwardingEquality.unlazy(value); daemonState.put(internalKey, value); } From 73264a8dff04a2388eb509f90664ac197e62ccf2 Mon Sep 17 00:00:00 2001 From: Ned Twigg Date: Thu, 12 May 2022 16:29:32 -0700 Subject: [PATCH 132/757] Fix the predeclare case. --- .../gradle/spotless/SpotlessExtensionPredeclare.java | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/SpotlessExtensionPredeclare.java b/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/SpotlessExtensionPredeclare.java index a086f1ca52..ae6243f53a 100644 --- a/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/SpotlessExtensionPredeclare.java +++ b/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/SpotlessExtensionPredeclare.java @@ -1,5 +1,5 @@ /* - * Copyright 2021 DiffPlug + * Copyright 2021-2022 DiffPlug * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -21,6 +21,8 @@ import org.gradle.api.Action; import org.gradle.api.Project; +import com.diffplug.spotless.LazyForwardingEquality; + public class SpotlessExtensionPredeclare extends SpotlessExtension { private final SortedMap toSetup = new TreeMap<>(); @@ -33,6 +35,8 @@ public SpotlessExtensionPredeclare(Project project, GradleProvisioner.Policy pol lazyAction.execute(formatExtension); } getRegisterDependenciesTask().steps.addAll(formatExtension.steps); + // needed to fix Deemon memory leaks (#1194), but this line came from https://github.com/diffplug/spotless/pull/1206 + LazyForwardingEquality.unlazy(getRegisterDependenciesTask().steps); }); }); } From b9e8325033ec7756b1d3f5e2a05551954b679dd1 Mon Sep 17 00:00:00 2001 From: Ned Twigg Date: Thu, 12 May 2022 16:31:01 -0700 Subject: [PATCH 133/757] Update changelog. --- plugin-gradle/CHANGES.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/plugin-gradle/CHANGES.md b/plugin-gradle/CHANGES.md index fe7b0f879f..c535402d9e 100644 --- a/plugin-gradle/CHANGES.md +++ b/plugin-gradle/CHANGES.md @@ -3,6 +3,8 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format (starting after version `3.27.0`). ## [Unreleased] +### Fixed +* More daemon memory consumption fixes ([#1206](https://github.com/diffplug/spotless/pull/1198) fixes [#1194](https://github.com/diffplug/spotless/issues/1194)) ## [6.6.0] - 2022-05-10 ### Added From 63b97621a7be320313be8ee64b4e552400a18e79 Mon Sep 17 00:00:00 2001 From: circleci Date: Fri, 13 May 2022 19:37:15 +0000 Subject: [PATCH 134/757] Published gradle/6.6.1 --- plugin-gradle/CHANGES.md | 2 ++ plugin-gradle/README.md | 46 ++++++++++++++++++++-------------------- 2 files changed, 25 insertions(+), 23 deletions(-) diff --git a/plugin-gradle/CHANGES.md b/plugin-gradle/CHANGES.md index c535402d9e..e67e6546bb 100644 --- a/plugin-gradle/CHANGES.md +++ b/plugin-gradle/CHANGES.md @@ -3,6 +3,8 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format (starting after version `3.27.0`). ## [Unreleased] + +## [6.6.1] - 2022-05-13 ### Fixed * More daemon memory consumption fixes ([#1206](https://github.com/diffplug/spotless/pull/1198) fixes [#1194](https://github.com/diffplug/spotless/issues/1194)) diff --git a/plugin-gradle/README.md b/plugin-gradle/README.md index 48572377b8..72eb58cb2b 100644 --- a/plugin-gradle/README.md +++ b/plugin-gradle/README.md @@ -18,9 +18,9 @@ output = [ --> [![Gradle plugin](https://img.shields.io/badge/plugins.gradle.org-com.diffplug.spotless-blue.svg)](https://plugins.gradle.org/plugin/com.diffplug.spotless) [![Maven central](https://img.shields.io/badge/mavencentral-yes-blue.svg)](https://search.maven.org/#search%7Cgav%7C1%7Cg%3A%22com.diffplug.spotless%22%20AND%20a%3A%22spotless-plugin-gradle%22) -[![Javadoc](https://img.shields.io/badge/javadoc-yes-blue.svg)](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.6.0/index.html) +[![Javadoc](https://img.shields.io/badge/javadoc-yes-blue.svg)](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.6.1/index.html) [![License Apache](https://img.shields.io/badge/license-apache-blue.svg)](https://tldrlegal.com/license/apache-license-2.0-(apache-2.0)) -[![Changelog](https://img.shields.io/badge/changelog-6.6.0-blue.svg)](CHANGES.md) +[![Changelog](https://img.shields.io/badge/changelog-6.6.1-blue.svg)](CHANGES.md) [![Circle CI](https://circleci.com/gh/diffplug/spotless/tree/main.svg?style=shield)](https://circleci.com/gh/diffplug/spotless/tree/main) [![Live chat](https://img.shields.io/badge/gitter-chat-brightgreen.svg)](https://gitter.im/diffplug/spotless) @@ -126,10 +126,10 @@ spotless { ``` Spotless consists of a list of formats (in the example above, `misc` and `java`), and each format has: -- a `target` (the files to format), which you set with [`target`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.6.0/com/diffplug/gradle/spotless/FormatExtension.html#target-java.lang.Object...-) and [`targetExclude`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.6.0/com/diffplug/gradle/spotless/FormatExtension.html#targetExclude-java.lang.Object...-) -- a list of `FormatterStep`, which are just `String -> String` functions, such as [`replace`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.6.0/com/diffplug/gradle/spotless/FormatExtension.html#replace-java.lang.String-java.lang.CharSequence-java.lang.CharSequence-), [`replaceRegex`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.6.0/com/diffplug/gradle/spotless/FormatExtension.html#replaceRegex-java.lang.String-java.lang.String-java.lang.String-), [`trimTrailingWhitespace`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.6.0/com/diffplug/gradle/spotless/FormatExtension.html#replace-java.lang.String-java.lang.CharSequence-java.lang.CharSequence-), [`custom`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.6.0/com/diffplug/gradle/spotless/FormatExtension.html#custom-java.lang.String-groovy.lang.Closure-), [`prettier`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.6.0/com/diffplug/gradle/spotless/FormatExtension.html#prettier--), [`eclipseWtp`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.6.0/com/diffplug/gradle/spotless/FormatExtension.html#eclipseWtp-com.diffplug.spotless.extra.wtp.EclipseWtpFormatterStep-), [`licenseHeader`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.6.0/com/diffplug/gradle/spotless/FormatExtension.html#licenseHeader-java.lang.String-java.lang.String-) etc. +- a `target` (the files to format), which you set with [`target`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.6.1/com/diffplug/gradle/spotless/FormatExtension.html#target-java.lang.Object...-) and [`targetExclude`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.6.1/com/diffplug/gradle/spotless/FormatExtension.html#targetExclude-java.lang.Object...-) +- a list of `FormatterStep`, which are just `String -> String` functions, such as [`replace`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.6.1/com/diffplug/gradle/spotless/FormatExtension.html#replace-java.lang.String-java.lang.CharSequence-java.lang.CharSequence-), [`replaceRegex`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.6.1/com/diffplug/gradle/spotless/FormatExtension.html#replaceRegex-java.lang.String-java.lang.String-java.lang.String-), [`trimTrailingWhitespace`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.6.1/com/diffplug/gradle/spotless/FormatExtension.html#replace-java.lang.String-java.lang.CharSequence-java.lang.CharSequence-), [`custom`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.6.1/com/diffplug/gradle/spotless/FormatExtension.html#custom-java.lang.String-groovy.lang.Closure-), [`prettier`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.6.1/com/diffplug/gradle/spotless/FormatExtension.html#prettier--), [`eclipseWtp`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.6.1/com/diffplug/gradle/spotless/FormatExtension.html#eclipseWtp-com.diffplug.spotless.extra.wtp.EclipseWtpFormatterStep-), [`licenseHeader`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.6.1/com/diffplug/gradle/spotless/FormatExtension.html#licenseHeader-java.lang.String-java.lang.String-) etc. -All the generic steps live in [`FormatExtension`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.6.0/com/diffplug/gradle/spotless/FormatExtension.html), and there are many language-specific steps which live in its language-specific subclasses, which are described below. +All the generic steps live in [`FormatExtension`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.6.1/com/diffplug/gradle/spotless/FormatExtension.html), and there are many language-specific steps which live in its language-specific subclasses, which are described below. ### Requirements @@ -141,7 +141,7 @@ If you're stuck on an older version of Gradle, `id 'com.diffplug.gradle.spotless ## Java -`com.diffplug.gradle.spotless.JavaExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.6.0/com/diffplug/gradle/spotless/JavaExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/JavaExtension.java) +`com.diffplug.gradle.spotless.JavaExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.6.1/com/diffplug/gradle/spotless/JavaExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/JavaExtension.java) ```gradle spotless { @@ -248,8 +248,8 @@ spotless { ## Groovy -- `com.diffplug.gradle.spotless.GroovyExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.6.0/com/diffplug/gradle/spotless/GroovyExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/GroovyExtension.java) -- `com.diffplug.gradle.spotless.GroovyGradleExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.6.0/com/diffplug/gradle/spotless/GroovyGradleExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/GroovyGradleExtension.java) +- `com.diffplug.gradle.spotless.GroovyExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.6.1/com/diffplug/gradle/spotless/GroovyExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/GroovyExtension.java) +- `com.diffplug.gradle.spotless.GroovyGradleExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.6.1/com/diffplug/gradle/spotless/GroovyGradleExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/GroovyGradleExtension.java) Configuration for Groovy is similar to [Java](#java), in that it also supports `licenseHeader` and `importOrder`. @@ -300,8 +300,8 @@ Groovy-Eclipse formatting errors/warnings lead per default to a build failure. T ## Kotlin -- `com.diffplug.gradle.spotless.KotlinExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.6.0/com/diffplug/gradle/spotless/KotlinExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/KotlinExtension.java) -- `com.diffplug.gradle.spotless.KotlinGradleExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.6.0/com/diffplug/gradle/spotless/KotlinGradleExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/KotlinGradleExtension.java) +- `com.diffplug.gradle.spotless.KotlinExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.6.1/com/diffplug/gradle/spotless/KotlinExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/KotlinExtension.java) +- `com.diffplug.gradle.spotless.KotlinGradleExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.6.1/com/diffplug/gradle/spotless/KotlinGradleExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/KotlinGradleExtension.java) ```gradle spotless { // if you are using build.gradle.kts, instead of 'spotless {' use: @@ -361,7 +361,7 @@ spotless { ## Scala -`com.diffplug.gradle.spotless.ScalaExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.6.0/com/diffplug/gradle/spotless/ScalaExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/ScalaExtension.java) +`com.diffplug.gradle.spotless.ScalaExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.6.1/com/diffplug/gradle/spotless/ScalaExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/ScalaExtension.java) ```gradle spotless { @@ -393,7 +393,7 @@ spotless { ## C/C++ -`com.diffplug.gradle.spotless.CppExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.6.0/com/diffplug/gradle/spotless/CppExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/CppExtension.java) +`com.diffplug.gradle.spotless.CppExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.6.1/com/diffplug/gradle/spotless/CppExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/CppExtension.java) ```gradle spotless { @@ -425,7 +425,7 @@ spotles { ## Python -`com.diffplug.gradle.spotless.PythonExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.6.0/com/diffplug/gradle/spotless/PythonExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/PythonExtension.java) +`com.diffplug.gradle.spotless.PythonExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.6.1/com/diffplug/gradle/spotless/PythonExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/PythonExtension.java) ```gradle spotless { @@ -459,7 +459,7 @@ black().pathToExe('C:/myuser/.pyenv/versions/3.8.0/scripts/black.exe') ## FreshMark -`com.diffplug.gradle.spotless.FreshMarkExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.6.0/com/diffplug/gradle/spotless/FreshMarkExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/FreshMarkExtension.java) +`com.diffplug.gradle.spotless.FreshMarkExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.6.1/com/diffplug/gradle/spotless/FreshMarkExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/FreshMarkExtension.java) [homepage](https://github.com/diffplug/freshmark). [changelog](https://github.com/diffplug/freshmark/blob/master/CHANGES.md). FreshMark lets you generate markdown in the comments of your markdown. This helps to keep badges and links up-to-date (see the source for this file), and can also be helpful for generating complex tables (see the source for [the parent readme](../README.md)). @@ -480,7 +480,7 @@ spotless { ## Antlr4 -`com.diffplug.gradle.spotless.Antlr4Extension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.6.0/com/diffplug/gradle/spotless/Antlr4Extension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/Antlr4Extension.java) +`com.diffplug.gradle.spotless.Antlr4Extension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.6.1/com/diffplug/gradle/spotless/Antlr4Extension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/Antlr4Extension.java) ```gradle spotless { @@ -505,7 +505,7 @@ antlr4formatter('1.2.1') // version is optional ## SQL -`com.diffplug.gradle.spotless.SqlExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.6.0/com/diffplug/gradle/spotless/SqlExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/SqlExtension.java) +`com.diffplug.gradle.spotless.SqlExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.6.1/com/diffplug/gradle/spotless/SqlExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/SqlExtension.java) ```gradle spotless { @@ -545,7 +545,7 @@ sql.formatter.indent.size=4 ## Typescript -- `com.diffplug.gradle.spotless.TypescriptExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.6.0/com/diffplug/gradle/spotless/TypescriptExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/TypescriptExtension.java) +- `com.diffplug.gradle.spotless.TypescriptExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.6.1/com/diffplug/gradle/spotless/TypescriptExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/TypescriptExtension.java) ```gradle spotless { @@ -588,7 +588,7 @@ For details, see the [npm detection](#npm-detection) and [`.npmrc` detection](#n ## JSON -- `com.diffplug.gradle.spotless.JsonExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.6.0/com/diffplug/gradle/spotless/JsonExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/JsonExtension.java) +- `com.diffplug.gradle.spotless.JsonExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.6.1/com/diffplug/gradle/spotless/JsonExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/JsonExtension.java) ```gradle spotless { @@ -813,7 +813,7 @@ Once a file's license header has a valid year, whether it is a year (`2020`) or * `2017` -> `2017-2020` * `2017-2019` -> `2017-2020` -See the [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.6.0/com/diffplug/gradle/spotless/FormatExtension.LicenseHeaderConfig.html) for a complete listing of options. +See the [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.6.1/com/diffplug/gradle/spotless/FormatExtension.LicenseHeaderConfig.html) for a complete listing of options. @@ -880,9 +880,9 @@ spotless { custom 'lowercase', { str -> str.toLowerCase() } ``` -However, custom rules will disable up-to-date checking and caching, unless you read [this javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.6.0/com/diffplug/gradle/spotless/FormatExtension.html#bumpThisNumberIfACustomStepChanges-int-) and follow its instructions carefully. +However, custom rules will disable up-to-date checking and caching, unless you read [this javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.6.1/com/diffplug/gradle/spotless/FormatExtension.html#bumpThisNumberIfACustomStepChanges-int-) and follow its instructions carefully. -Another option is to create proper `FormatterStep` in your `buildSrc`, and then call [`addStep`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.6.0/com/diffplug/gradle/spotless/FormatExtension.html#addStep-com.diffplug.spotless.FormatterStep-). The contributing guide describes [how to do this](https://github.com/diffplug/spotless/blob/main/CONTRIBUTING.md#how-to-add-a-new-formatterstep). If the step is generally-useful, we hope you'll open a PR to share it! +Another option is to create proper `FormatterStep` in your `buildSrc`, and then call [`addStep`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.6.1/com/diffplug/gradle/spotless/FormatExtension.html#addStep-com.diffplug.spotless.FormatterStep-). The contributing guide describes [how to do this](https://github.com/diffplug/spotless/blob/main/CONTRIBUTING.md#how-to-add-a-new-formatterstep). If the step is generally-useful, we hope you'll open a PR to share it! ```gradle @@ -915,11 +915,11 @@ spotless { format 'foo', com.acme.FooLanguageExtension, { ``` -If you'd like to create a one-off Spotless task outside of the `check`/`apply` framework, see [`FormatExtension.createIndependentApplyTask`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.6.0/com/diffplug/gradle/spotless/FormatExtension.html#createIndependentApplyTask-java.lang.String-). +If you'd like to create a one-off Spotless task outside of the `check`/`apply` framework, see [`FormatExtension.createIndependentApplyTask`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.6.1/com/diffplug/gradle/spotless/FormatExtension.html#createIndependentApplyTask-java.lang.String-). ## Inception (languages within languages within...) -In very rare cases, you might want to format e.g. javascript which is written inside JSP templates, or maybe java within a markdown file, or something wacky like that. You can specify hunks within a file using either open/close tags or a regex with a single capturing group, and then specify rules within it, like so. See [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.6.0/com/diffplug/gradle/spotless/FormatExtension.html#withinBlocks-java.lang.String-java.lang.String-java.lang.String-org.gradle.api.Action-) for more details. +In very rare cases, you might want to format e.g. javascript which is written inside JSP templates, or maybe java within a markdown file, or something wacky like that. You can specify hunks within a file using either open/close tags or a regex with a single capturing group, and then specify rules within it, like so. See [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.6.1/com/diffplug/gradle/spotless/FormatExtension.html#withinBlocks-java.lang.String-java.lang.String-java.lang.String-org.gradle.api.Action-) for more details. ```gradle import com.diffplug.gradle.spotless.JavaExtension From 3e185d9e7a7996084257a7df0a8a1790cf46e2d5 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 16 May 2022 12:04:01 +0000 Subject: [PATCH 135/757] Bump com.github.spotbugs from 5.0.6 to 5.0.7 Bumps com.github.spotbugs from 5.0.6 to 5.0.7. --- updated-dependencies: - dependency-name: com.github.spotbugs dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] --- settings.gradle | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/settings.gradle b/settings.gradle index 4bdbdfc1a8..07f7e5ec34 100644 --- a/settings.gradle +++ b/settings.gradle @@ -6,7 +6,7 @@ pluginManagement { // https://github.com/gradle-nexus/publish-plugin/releases id 'io.github.gradle-nexus.publish-plugin' version '1.1.0' // https://github.com/spotbugs/spotbugs-gradle-plugin/releases - id 'com.github.spotbugs' version '5.0.6' + id 'com.github.spotbugs' version '5.0.7' // https://github.com/diffplug/spotless-changelog id 'com.diffplug.spotless-changelog' version '2.3.2' // https://github.com/diffplug/goomph/blob/main/CHANGES.md From 8241fe511a029c9c02eb9550c832e827497b921f Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 16 May 2022 12:04:03 +0000 Subject: [PATCH 136/757] Bump org.gradle.test-retry from 1.3.2 to 1.4.0 Bumps org.gradle.test-retry from 1.3.2 to 1.4.0. --- updated-dependencies: - dependency-name: org.gradle.test-retry dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] --- settings.gradle | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/settings.gradle b/settings.gradle index 4bdbdfc1a8..32c136d631 100644 --- a/settings.gradle +++ b/settings.gradle @@ -12,7 +12,7 @@ pluginManagement { // https://github.com/diffplug/goomph/blob/main/CHANGES.md id 'com.diffplug.p2.asmaven' version '3.27.0' // DO NOT UPDATE, see https://github.com/diffplug/spotless/pull/874 // https://github.com/gradle/test-retry-gradle-plugin/releases - id 'org.gradle.test-retry' version '1.3.2' + id 'org.gradle.test-retry' version '1.4.0' // https://github.com/radarsh/gradle-test-logger-plugin/blob/develop/CHANGELOG.md id 'com.adarshr.test-logger' version '3.2.0' } From 9b26e02542733813276aa959fd22afba4c162e12 Mon Sep 17 00:00:00 2001 From: Marek Hlava Date: Sat, 21 May 2022 20:33:56 +0200 Subject: [PATCH 137/757] Add support for KtLint editorConfigOverride --- .editorconfig | 2 + .../glue/ktlint/KtlintFormatterFunc.java | 92 ++++++++++++++++--- .../diffplug/spotless/kotlin/BadSemver.java | 13 ++- .../diffplug/spotless/kotlin/KtLintStep.java | 34 ++++--- plugin-gradle/README.md | 11 ++- .../gradle/spotless/KotlinExtension.java | 20 +++- .../spotless/KotlinGradleExtension.java | 17 +++- .../gradle/spotless/KotlinExtensionTest.java | 45 +++++++++ .../spotless/KotlinGradleExtensionTest.java | 63 +++++++++++-- .../experimentalEditorConfigOverride.clean | 5 + .../experimentalEditorConfigOverride.dirty | 5 + .../spotless/kotlin/KtLintStepTest.java | 7 ++ 12 files changed, 268 insertions(+), 46 deletions(-) create mode 100644 testlib/src/main/resources/kotlin/ktlint/experimentalEditorConfigOverride.clean create mode 100644 testlib/src/main/resources/kotlin/ktlint/experimentalEditorConfigOverride.dirty diff --git a/.editorconfig b/.editorconfig index a8061a0816..6712fd66cc 100644 --- a/.editorconfig +++ b/.editorconfig @@ -16,6 +16,8 @@ indent_size = 2 # Doc: https://youtrack.jetbrains.com/issue/IDEA-170643#focus=streamItem-27-3708697.0-0 ij_java_imports_layout = java.**,|,javax.**,|,org.**,|,com.**,|,com.diffplug.**,|,* ij_java_use_single_class_imports = true +ij_java_class_count_to_use_import_on_demand = 999 +ij_java_names_count_to_use_import_on_demand = 999 [*.xml.mustache] indent_style = space diff --git a/lib/src/ktlint/java/com/diffplug/spotless/glue/ktlint/KtlintFormatterFunc.java b/lib/src/ktlint/java/com/diffplug/spotless/glue/ktlint/KtlintFormatterFunc.java index b3ef570180..1cd79a6ba9 100644 --- a/lib/src/ktlint/java/com/diffplug/spotless/glue/ktlint/KtlintFormatterFunc.java +++ b/lib/src/ktlint/java/com/diffplug/spotless/glue/ktlint/KtlintFormatterFunc.java @@ -17,18 +17,26 @@ import java.io.File; import java.util.ArrayList; +import java.util.Arrays; import java.util.List; import java.util.Map; +import java.util.Objects; +import java.util.stream.Collectors; +import java.util.stream.Stream; import com.pinterest.ktlint.core.KtLint; -import com.pinterest.ktlint.core.KtLint.Params; +import com.pinterest.ktlint.core.KtLint.ExperimentalParams; import com.pinterest.ktlint.core.LintError; import com.pinterest.ktlint.core.RuleSet; +import com.pinterest.ktlint.core.api.DefaultEditorConfigProperties; +import com.pinterest.ktlint.core.api.EditorConfigOverride; +import com.pinterest.ktlint.core.api.UsesEditorConfigProperties; import com.pinterest.ktlint.ruleset.experimental.ExperimentalRuleSetProvider; import com.pinterest.ktlint.ruleset.standard.StandardRuleSetProvider; import com.diffplug.spotless.FormatterFunc; +import kotlin.Pair; import kotlin.Unit; import kotlin.jvm.functions.Function2; @@ -38,8 +46,13 @@ public class KtlintFormatterFunc implements FormatterFunc.NeedsFile { private final Map userData; private final Function2 formatterCallback; private final boolean isScript; + private final EditorConfigOverride editorConfigOverride; - public KtlintFormatterFunc(boolean isScript, boolean useExperimental, Map userData) { + /** + * Non-empty editorConfigOverrideMap requires KtLint 0.45.2. + */ + public KtlintFormatterFunc(boolean isScript, boolean useExperimental, Map userData, + Map editorConfigOverrideMap) { rulesets = new ArrayList<>(); rulesets.add(new StandardRuleSetProvider().get()); @@ -49,6 +62,46 @@ public KtlintFormatterFunc(boolean isScript, boolean useExperimental, Map editorConfigOverrideMap) { + // Get properties from rules in the rule sets + Stream> ruleProperties = rulesets.stream() + .flatMap(ruleSet -> Arrays.stream(ruleSet.getRules())) + .filter(rule -> rule instanceof UsesEditorConfigProperties) + .flatMap(rule -> ((UsesEditorConfigProperties) rule).getEditorConfigProperties().stream()); + + // Create a mapping of properties to their names based on rule properties and default properties + Map> supportedProperties = Stream + .concat(ruleProperties, DefaultEditorConfigProperties.INSTANCE.getDefaultEditorConfigProperties().stream()) + .distinct() + .collect(Collectors.toMap(property -> property.getType().getName(), property -> property)); + + // Create config properties based on provided property names and values + @SuppressWarnings("unchecked") + Pair, ?>[] properties = editorConfigOverrideMap.entrySet().stream() + .map(entry -> { + UsesEditorConfigProperties.EditorConfigProperty property = supportedProperties.get(entry.getKey()); + if (property != null) { + return new Pair<>(property, entry.getValue()); + } else { + return null; + } + }) + .filter(Objects::nonNull) + .toArray(Pair[]::new); + + return EditorConfigOverride.Companion.from(properties); } static class FormatterCallback implements Function2 { @@ -63,14 +116,31 @@ public Unit invoke(LintError lint, Boolean corrected) { @Override public String applyWithFile(String unix, File file) throws Exception { - return KtLint.INSTANCE.format(new Params( - file.getName(), - unix, - rulesets, - userData, - formatterCallback, - isScript, - null, - false)); + + if (editorConfigOverride != null) { + // Use ExperimentalParams with EditorConfigOverride which requires KtLint 0.45.2 + return KtLint.INSTANCE.format(new ExperimentalParams( + file.getName(), + unix, + rulesets, + userData, + formatterCallback, + isScript, + null, + false, + editorConfigOverride, + false)); + } else { + // Use Params for backward compatibility + return KtLint.INSTANCE.format(new KtLint.Params( + file.getName(), + unix, + rulesets, + userData, + formatterCallback, + isScript, + null, + false)); + } } } diff --git a/lib/src/main/java/com/diffplug/spotless/kotlin/BadSemver.java b/lib/src/main/java/com/diffplug/spotless/kotlin/BadSemver.java index ae500e55b4..771c27eb3e 100644 --- a/lib/src/main/java/com/diffplug/spotless/kotlin/BadSemver.java +++ b/lib/src/main/java/com/diffplug/spotless/kotlin/BadSemver.java @@ -1,5 +1,5 @@ /* - * Copyright 2021 DiffPlug + * Copyright 2021-2022 DiffPlug * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -26,13 +26,18 @@ protected static int version(String input) { } String major = matcher.group(1); String minor = matcher.group(2); - return version(Integer.parseInt(major), Integer.parseInt(minor)); + String patch = matcher.group(3); + return version(Integer.parseInt(major), Integer.parseInt(minor), patch != null ? Integer.parseInt(patch) : 0); } /** Ambiguous after 2147.483647.blah-blah */ + protected static int version(int major, int minor, int patch) { + return major * 1_000_000 + minor * 1_000 + patch; + } + protected static int version(int major, int minor) { - return major * 1_000_000 + minor; + return version(major, minor, 0); } - private static final Pattern BAD_SEMVER = Pattern.compile("(\\d+)\\.(\\d+)"); + private static final Pattern BAD_SEMVER = Pattern.compile("(\\d+)\\.(\\d+)\\.*(\\d+)*"); } diff --git a/lib/src/main/java/com/diffplug/spotless/kotlin/KtLintStep.java b/lib/src/main/java/com/diffplug/spotless/kotlin/KtLintStep.java index de099b04d1..d58331ec1b 100644 --- a/lib/src/main/java/com/diffplug/spotless/kotlin/KtLintStep.java +++ b/lib/src/main/java/com/diffplug/spotless/kotlin/KtLintStep.java @@ -50,26 +50,29 @@ public static FormatterStep create(Provisioner provisioner) { } public static FormatterStep create(String version, Provisioner provisioner) { - return create(version, provisioner, false, Collections.emptyMap()); + return create(version, provisioner, false, Collections.emptyMap(), Collections.emptyMap()); } - public static FormatterStep create(String version, Provisioner provisioner, boolean useExperimental, Map userData) { - return create(version, provisioner, false, useExperimental, userData); + public static FormatterStep create(String version, Provisioner provisioner, boolean useExperimental, + Map userData, Map editorConfigOverride) { + return create(version, provisioner, false, useExperimental, userData, editorConfigOverride); } public static FormatterStep createForScript(String version, Provisioner provisioner) { - return create(version, provisioner, true, false, Collections.emptyMap()); + return create(version, provisioner, true, false, Collections.emptyMap(), Collections.emptyMap()); } - public static FormatterStep createForScript(String version, Provisioner provisioner, boolean useExperimental, Map userData) { - return create(version, provisioner, true, useExperimental, userData); + public static FormatterStep createForScript(String version, Provisioner provisioner, boolean useExperimental, + Map userData, Map editorConfigOverride) { + return create(version, provisioner, true, useExperimental, userData, editorConfigOverride); } - private static FormatterStep create(String version, Provisioner provisioner, boolean isScript, boolean useExperimental, Map userData) { + private static FormatterStep create(String version, Provisioner provisioner, boolean isScript, boolean useExperimental, + Map userData, Map editorConfigOverride) { Objects.requireNonNull(version, "version"); Objects.requireNonNull(provisioner, "provisioner"); return FormatterStep.createLazy(NAME, - () -> new State(version, provisioner, isScript, useExperimental, userData), + () -> new State(version, provisioner, isScript, useExperimental, userData, editorConfigOverride), State::createFormat); } @@ -87,11 +90,20 @@ static final class State implements Serializable { final JarState jarState; private final boolean useExperimental; private final TreeMap userData; + private final TreeMap editorConfigOverride; private final boolean useParams; - State(String version, Provisioner provisioner, boolean isScript, boolean useExperimental, Map userData) throws IOException { + State(String version, Provisioner provisioner, boolean isScript, boolean useExperimental, + Map userData, Map editorConfigOverride) throws IOException { + + if (!editorConfigOverride.isEmpty() && + BadSemver.version(version) < BadSemver.version(0, 45, 2)) { + throw new IllegalStateException("KtLint editorConfigOverride supported for version 0.45.2 and later"); + } + this.useExperimental = useExperimental; this.userData = new TreeMap<>(userData); + this.editorConfigOverride = new TreeMap<>(editorConfigOverride); String coordinate; if (BadSemver.version(version) < BadSemver.version(0, 32)) { coordinate = MAVEN_COORDINATE_PRE_0_32; @@ -108,8 +120,8 @@ static final class State implements Serializable { FormatterFunc createFormat() throws Exception { if (useParams) { Class formatterFunc = jarState.getClassLoader().loadClass("com.diffplug.spotless.glue.ktlint.KtlintFormatterFunc"); - Constructor constructor = formatterFunc.getConstructor(boolean.class, boolean.class, Map.class); - return (FormatterFunc.NeedsFile) constructor.newInstance(isScript, useExperimental, userData); + Constructor constructor = formatterFunc.getConstructor(boolean.class, boolean.class, Map.class, Map.class); + return (FormatterFunc.NeedsFile) constructor.newInstance(isScript, useExperimental, userData, editorConfigOverride); } ClassLoader classLoader = jarState.getClassLoader(); diff --git a/plugin-gradle/README.md b/plugin-gradle/README.md index 72eb58cb2b..e7f1f92107 100644 --- a/plugin-gradle/README.md +++ b/plugin-gradle/README.md @@ -335,15 +335,18 @@ spotless { ### ktlint -[homepage](https://github.com/pinterest/ktlint). [changelog](https://github.com/pinterest/ktlint/releases). Spotless does not ([yet](https://github.com/diffplug/spotless/issues/142)) respect the `.editorconfig` settings ([ktlint docs](https://github.com/pinterest/ktlint#editorconfig)), but you can provide them manually as `userData`. +[homepage](https://github.com/pinterest/ktlint). [changelog](https://github.com/pinterest/ktlint/releases). Spotless does not ([yet](https://github.com/diffplug/spotless/issues/142)) respect the `.editorconfig` settings ([ktlint docs](https://github.com/pinterest/ktlint#editorconfig)), but you can provide them manually as `editorConfigOverride`. ```kotlin spotless { kotlin { - // version, setUseExperimental and userData are all optional - ktlint('0.43.2') + // version, setUseExperimental, userData and editorConfigOverride are all optional + ktlint("0.45.2") .setUseExperimental(true) - .userData(mapOf('indent_size' to '2', 'continuation_indent_size' to '2')) + .userData(mapOf("android" to "true")) + .editorConfigOverride(mapOf("indent_size" to 2)) + } +} ``` ### diktat diff --git a/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/KotlinExtension.java b/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/KotlinExtension.java index f7cb7a20f0..546efab46d 100644 --- a/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/KotlinExtension.java +++ b/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/KotlinExtension.java @@ -30,6 +30,7 @@ import org.gradle.api.plugins.JavaPluginConvention; import org.gradle.api.tasks.SourceSet; +import com.diffplug.common.collect.ImmutableSortedMap; import com.diffplug.spotless.FileSignature; import com.diffplug.spotless.FormatterStep; import com.diffplug.spotless.kotlin.DiktatStep; @@ -59,7 +60,7 @@ public LicenseHeaderConfig licenseHeaderFile(Object licenseHeaderFile) { /** Adds the specified version of ktlint. */ public KotlinFormatExtension ktlint(String version) { Objects.requireNonNull(version); - return new KotlinFormatExtension(version, false, Collections.emptyMap()); + return new KotlinFormatExtension(version, false, Collections.emptyMap(), Collections.emptyMap()); } public KotlinFormatExtension ktlint() { @@ -71,11 +72,14 @@ public class KotlinFormatExtension { private final String version; private boolean useExperimental; private Map userData; + private Map editorConfigOverride; - KotlinFormatExtension(String version, boolean useExperimental, Map config) { + KotlinFormatExtension(String version, boolean useExperimental, Map config, + Map editorConfigOverride) { this.version = version; this.useExperimental = useExperimental; this.userData = config; + this.editorConfigOverride = editorConfigOverride; addStep(createStep()); } @@ -88,13 +92,21 @@ public KotlinFormatExtension setUseExperimental(boolean useExperimental) { public KotlinFormatExtension userData(Map userData) { // Copy the map to a sorted map because up-to-date checking is based on binary-equals of the serialized // representation. - this.userData = userData; + this.userData = ImmutableSortedMap.copyOf(userData); + replaceStep(createStep()); + return this; + } + + public KotlinFormatExtension editorConfigOverride(Map editorConfigOverride) { + // Copy the map to a sorted map because up-to-date checking is based on binary-equals of the serialized + // representation. + this.editorConfigOverride = ImmutableSortedMap.copyOf(editorConfigOverride); replaceStep(createStep()); return this; } private FormatterStep createStep() { - return KtLintStep.create(version, provisioner(), useExperimental, userData); + return KtLintStep.create(version, provisioner(), useExperimental, userData, editorConfigOverride); } } diff --git a/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/KotlinGradleExtension.java b/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/KotlinGradleExtension.java index 7a98c211bc..c1abe62bd1 100644 --- a/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/KotlinGradleExtension.java +++ b/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/KotlinGradleExtension.java @@ -45,7 +45,7 @@ public KotlinGradleExtension(SpotlessExtension spotless) { /** Adds the specified version of ktlint. */ public KotlinFormatExtension ktlint(String version) { Objects.requireNonNull(version, "version"); - return new KotlinFormatExtension(version, false, Collections.emptyMap()); + return new KotlinFormatExtension(version, false, Collections.emptyMap(), Collections.emptyMap()); } public KotlinFormatExtension ktlint() { @@ -57,11 +57,14 @@ public class KotlinFormatExtension { private final String version; private boolean useExperimental; private Map userData; + private Map editorConfigOverride; - KotlinFormatExtension(String version, boolean useExperimental, Map config) { + KotlinFormatExtension(String version, boolean useExperimental, Map config, + Map editorConfigOverride) { this.version = version; this.useExperimental = useExperimental; this.userData = config; + this.editorConfigOverride = editorConfigOverride; addStep(createStep()); } @@ -79,8 +82,16 @@ public KotlinFormatExtension userData(Map userData) { return this; } + public KotlinFormatExtension editorConfigOverride(Map editorConfigOverride) { + // Copy the map to a sorted map because up-to-date checking is based on binary-equals of the serialized + // representation. + this.editorConfigOverride = ImmutableSortedMap.copyOf(editorConfigOverride); + replaceStep(createStep()); + return this; + } + private FormatterStep createStep() { - return KtLintStep.createForScript(version, provisioner(), useExperimental, userData); + return KtLintStep.createForScript(version, provisioner(), useExperimental, userData, editorConfigOverride); } } diff --git a/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/KotlinExtensionTest.java b/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/KotlinExtensionTest.java index f10be630ef..da2a604681 100644 --- a/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/KotlinExtensionTest.java +++ b/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/KotlinExtensionTest.java @@ -16,6 +16,7 @@ package com.diffplug.gradle.spotless; import static org.assertj.core.api.Assertions.assertThat; +import static org.junit.jupiter.api.Assertions.assertThrows; import static org.junit.jupiter.api.condition.JRE.JAVA_11; import java.io.IOException; @@ -175,6 +176,50 @@ void withExperimental_0_32() throws IOException { assertFile("src/main/kotlin/basic.kt").sameAsResource("kotlin/ktlint/basic.clean"); } + @Test + void withExperimentalEditorConfigOverride() throws IOException { + setFile("build.gradle").toLines( + "plugins {", + " id 'org.jetbrains.kotlin.jvm' version '1.5.31'", + " id 'com.diffplug.spotless'", + "}", + "repositories { mavenCentral() }", + "spotless {", + " kotlin {", + " ktlint().setUseExperimental(true)", + " .editorConfigOverride([", + " ij_kotlin_allow_trailing_comma: true,", + " ij_kotlin_allow_trailing_comma_on_call_site: true", + " ])", + " }", + "}"); + setFile("src/main/kotlin/experimental.kt").toResource("kotlin/ktlint/experimentalEditorConfigOverride.dirty"); + gradleRunner().withArguments("spotlessApply").build(); + assertFile("src/main/kotlin/experimental.kt").sameAsResource("kotlin/ktlint/experimentalEditorConfigOverride.clean"); + } + + @Test + void withEditorConfigOverride_0_45_1() throws IOException { + setFile("build.gradle").toLines( + "plugins {", + " id 'org.jetbrains.kotlin.jvm' version '1.5.31'", + " id 'com.diffplug.spotless'", + "}", + "repositories { mavenCentral() }", + "spotless {", + " kotlin {", + " ktlint('0.45.1')", + " .editorConfigOverride([", + " indent_size: 5", + " ])", + " }", + "}"); + setFile("src/main/kotlin/basic.kt").toResource("kotlin/ktlint/basic.dirty"); + Throwable error = assertThrows(Throwable.class, + () -> gradleRunner().withArguments("spotlessApply").build()); + assertThat(error).hasMessageContaining("KtLint editorConfigOverride supported for version 0.45.2 and later"); + } + /** * Check that the sample used to verify the experimental ruleset is untouched by the default ruleset, to verify * that enabling the experimental ruleset is actually doing something. diff --git a/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/KotlinGradleExtensionTest.java b/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/KotlinGradleExtensionTest.java index d1ffff0718..034174cf73 100644 --- a/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/KotlinGradleExtensionTest.java +++ b/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/KotlinGradleExtensionTest.java @@ -16,6 +16,7 @@ package com.diffplug.gradle.spotless; import static org.assertj.core.api.Assertions.assertThat; +import static org.junit.jupiter.api.Assertions.assertThrows; import static org.junit.jupiter.api.condition.JRE.JAVA_11; import java.io.IOException; @@ -137,13 +138,13 @@ void withExperimental() throws IOException { "}", "repositories { mavenCentral() }", "spotless {", - " kotlin {", + " kotlinGradle {", " ktlint().setUseExperimental(true)", " }", "}"); - setFile("src/main/kotlin/experimental.kt").toResource("kotlin/ktlint/experimental.dirty"); + setFile("configuration.gradle.kts").toResource("kotlin/ktlint/experimental.dirty"); gradleRunner().withArguments("spotlessApply").build(); - assertFile("src/main/kotlin/experimental.kt").sameAsResource("kotlin/ktlint/experimental.clean"); + assertFile("configuration.gradle.kts").sameAsResource("kotlin/ktlint/experimental.clean"); } @Test @@ -155,13 +156,57 @@ void withExperimental_0_32() throws IOException { "}", "repositories { mavenCentral() }", "spotless {", - " kotlin {", + " kotlinGradle {", " ktlint('0.32.0').setUseExperimental(true)", " }", "}"); - setFile("src/main/kotlin/basic.kt").toResource("kotlin/ktlint/basic.dirty"); + setFile("configuration.gradle.kts").toResource("kotlin/ktlint/basic.dirty"); + gradleRunner().withArguments("spotlessApply").build(); + assertFile("configuration.gradle.kts").sameAsResource("kotlin/ktlint/basic.clean"); + } + + @Test + void withExperimentalEditorConfigOverride() throws IOException { + setFile("build.gradle").toLines( + "plugins {", + " id 'org.jetbrains.kotlin.jvm' version '1.5.31'", + " id 'com.diffplug.spotless'", + "}", + "repositories { mavenCentral() }", + "spotless {", + " kotlinGradle {", + " ktlint().setUseExperimental(true)", + " .editorConfigOverride([", + " ij_kotlin_allow_trailing_comma: true,", + " ij_kotlin_allow_trailing_comma_on_call_site: true", + " ])", + " }", + "}"); + setFile("configuration.gradle.kts").toResource("kotlin/ktlint/experimentalEditorConfigOverride.dirty"); gradleRunner().withArguments("spotlessApply").build(); - assertFile("src/main/kotlin/basic.kt").sameAsResource("kotlin/ktlint/basic.clean"); + assertFile("configuration.gradle.kts").sameAsResource("kotlin/ktlint/experimentalEditorConfigOverride.clean"); + } + + @Test + void withEditorConfigOverride_0_45_1() throws IOException { + setFile("build.gradle").toLines( + "plugins {", + " id 'org.jetbrains.kotlin.jvm' version '1.5.31'", + " id 'com.diffplug.spotless'", + "}", + "repositories { mavenCentral() }", + "spotless {", + " kotlinGradle {", + " ktlint('0.45.1')", + " .editorConfigOverride([", + " indent_size: 5", + " ])", + " }", + "}"); + setFile("configuration.gradle.kts").toResource("kotlin/ktlint/basic.dirty"); + Throwable error = assertThrows(Throwable.class, + () -> gradleRunner().withArguments("spotlessApply").build()); + assertThat(error).hasMessageContaining("KtLint editorConfigOverride supported for version 0.45.2 and later"); } /** @@ -180,13 +225,13 @@ void experimentalSampleUnchangedWithDefaultRuleset() throws IOException { "}", "repositories { mavenCentral() }", "spotless {", - " kotlin {", + " kotlinGradle {", " ktlint()", " }", "}"); - setFile("src/main/kotlin/experimental.kt").toResource("kotlin/ktlint/experimental.dirty"); + setFile("configuration.gradle.kts").toResource("kotlin/ktlint/experimental.dirty"); gradleRunner().withArguments("spotlessApply").build(); - assertFile("src/main/kotlin/experimental.kt").sameAsResource("kotlin/ktlint/experimental.dirty"); + assertFile("configuration.gradle.kts").sameAsResource("kotlin/ktlint/experimental.dirty"); } @Test diff --git a/testlib/src/main/resources/kotlin/ktlint/experimentalEditorConfigOverride.clean b/testlib/src/main/resources/kotlin/ktlint/experimentalEditorConfigOverride.clean new file mode 100644 index 0000000000..532177d038 --- /dev/null +++ b/testlib/src/main/resources/kotlin/ktlint/experimentalEditorConfigOverride.clean @@ -0,0 +1,5 @@ +fun main() { + val list = listOf( + "hello", + ) +} diff --git a/testlib/src/main/resources/kotlin/ktlint/experimentalEditorConfigOverride.dirty b/testlib/src/main/resources/kotlin/ktlint/experimentalEditorConfigOverride.dirty new file mode 100644 index 0000000000..1610d6ba6d --- /dev/null +++ b/testlib/src/main/resources/kotlin/ktlint/experimentalEditorConfigOverride.dirty @@ -0,0 +1,5 @@ +fun main() { + val list = listOf( + "hello" + ) +} diff --git a/testlib/src/test/java/com/diffplug/spotless/kotlin/KtLintStepTest.java b/testlib/src/test/java/com/diffplug/spotless/kotlin/KtLintStepTest.java index ecca9e6cc6..af61ac4cd0 100644 --- a/testlib/src/test/java/com/diffplug/spotless/kotlin/KtLintStepTest.java +++ b/testlib/src/test/java/com/diffplug/spotless/kotlin/KtLintStepTest.java @@ -77,6 +77,13 @@ void worksAlpha1() throws Exception { .testResource("kotlin/ktlint/basic.dirty", "kotlin/ktlint/basic.clean"); } + @Test + void worksPre0_45_2() throws Exception { + FormatterStep step = KtLintStep.create("0.45.1", TestProvisioner.mavenCentral()); + StepHarness.forStep(step) + .testResource("kotlin/ktlint/basic.dirty", "kotlin/ktlint/basic.clean"); + } + @Test void equality() throws Exception { new SerializableEqualityTester() { From 1978504080cf3362a4544709d86e4b7674388846 Mon Sep 17 00:00:00 2001 From: Marek Hlava Date: Sat, 21 May 2022 20:54:19 +0200 Subject: [PATCH 138/757] Update changelog --- CHANGES.md | 2 ++ plugin-gradle/CHANGES.md | 2 ++ 2 files changed, 4 insertions(+) diff --git a/CHANGES.md b/CHANGES.md index 8d2011de17..9b0f9ae0ea 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -11,6 +11,8 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format ( ## [Unreleased] +* Add support for `editorConfigOverride` in `ktlint`. ([#1218](https://github.com/diffplug/spotless/pull/1218) fixes [#1193](https://github.com/diffplug/spotless/issues/1193)) + ## [2.25.3] - 2022-05-10 ### Fixed * Update the `black` version regex to fix `19.10b0` and earlier. (fixes [#1195](https://github.com/diffplug/spotless/issues/1195), regression introduced in `2.25.0`) diff --git a/plugin-gradle/CHANGES.md b/plugin-gradle/CHANGES.md index e67e6546bb..06c8988425 100644 --- a/plugin-gradle/CHANGES.md +++ b/plugin-gradle/CHANGES.md @@ -4,6 +4,8 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format ( ## [Unreleased] +* Add support for `editorConfigOverride` in `ktlint`. ([#1218](https://github.com/diffplug/spotless/pull/1218) fixes [#1193](https://github.com/diffplug/spotless/issues/1193)) + ## [6.6.1] - 2022-05-13 ### Fixed * More daemon memory consumption fixes ([#1206](https://github.com/diffplug/spotless/pull/1198) fixes [#1194](https://github.com/diffplug/spotless/issues/1194)) From aa9e37a4a35e96348ae079e923e837adcfa27a8b Mon Sep 17 00:00:00 2001 From: tison Date: Wed, 1 Jun 2022 23:45:16 +0800 Subject: [PATCH 139/757] Open com.sun.tools.javac modules on JDK 16+ Signed-off-by: tison --- .../main/java/com/diffplug/spotless/Jvm.java | 3 + .../com/diffplug/spotless/ModuleHelper.java | 136 ++++++++++++++++++ 2 files changed, 139 insertions(+) create mode 100644 lib/src/main/java/com/diffplug/spotless/ModuleHelper.java diff --git a/lib/src/main/java/com/diffplug/spotless/Jvm.java b/lib/src/main/java/com/diffplug/spotless/Jvm.java index e22e0c6339..8d7482cb61 100644 --- a/lib/src/main/java/com/diffplug/spotless/Jvm.java +++ b/lib/src/main/java/com/diffplug/spotless/Jvm.java @@ -48,6 +48,9 @@ public final class Jvm { if (VERSION <= 8) { throw new IllegalArgumentException("Expected " + jre + " to start with an integer greater than 8"); } + if (VERSION >= 16) { + ModuleHelper.doOpenInternalPackagesIfRequired(); + } } } diff --git a/lib/src/main/java/com/diffplug/spotless/ModuleHelper.java b/lib/src/main/java/com/diffplug/spotless/ModuleHelper.java new file mode 100644 index 0000000000..d4895afd20 --- /dev/null +++ b/lib/src/main/java/com/diffplug/spotless/ModuleHelper.java @@ -0,0 +1,136 @@ +/* + * 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. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.diffplug.spotless; + +import java.lang.invoke.MethodHandle; +import java.lang.invoke.MethodHandles; +import java.lang.reflect.Field; +import java.lang.reflect.Method; +import java.lang.reflect.Modifier; +import java.util.ArrayList; +import java.util.Collection; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +import javax.annotation.Nullable; + +import sun.misc.Unsafe; + +public final class ModuleHelper { + private static final Map REQUIRED_PACKAGES_TO_TEST_CLASSES = new HashMap<>(); + + static { + REQUIRED_PACKAGES_TO_TEST_CLASSES.putIfAbsent("com.sun.tools.javac.util", "Context"); + REQUIRED_PACKAGES_TO_TEST_CLASSES.putIfAbsent("com.sun.tools.javac.file", "CacheFSInfo"); + REQUIRED_PACKAGES_TO_TEST_CLASSES.putIfAbsent("com.sun.tools.javac.tree", "TreeTranslator"); + REQUIRED_PACKAGES_TO_TEST_CLASSES.putIfAbsent("com.sun.tools.javac.main", "CommandLine"); + REQUIRED_PACKAGES_TO_TEST_CLASSES.putIfAbsent("com.sun.tools.javac.jvm", "ClassFile"); + REQUIRED_PACKAGES_TO_TEST_CLASSES.putIfAbsent("com.sun.tools.javac.parser", "Tokens$TokenKind"); + REQUIRED_PACKAGES_TO_TEST_CLASSES.putIfAbsent("com.sun.tools.javac.code", "Source"); + REQUIRED_PACKAGES_TO_TEST_CLASSES.putIfAbsent("com.sun.tools.javac.processing", "PrintingProcessor"); + REQUIRED_PACKAGES_TO_TEST_CLASSES.putIfAbsent("com.sun.tools.javac.comp", "AttrContext"); + REQUIRED_PACKAGES_TO_TEST_CLASSES.putIfAbsent("com.sun.tools.javac.api", "DiagnosticFormatter$PositionKind"); + } + + private static boolean checkDone = false; + + public static synchronized void doOpenInternalPackagesIfRequired() { + if (checkDone) { + return; + } + try { + checkDone = true; + final List unavailableRequiredPackages = unavailableRequiredPackages(); + if (!unavailableRequiredPackages.isEmpty()) { + openPackages(unavailableRequiredPackages); + final List failedToOpen = unavailableRequiredPackages(); + if (!failedToOpen.isEmpty()) { + final StringBuilder message = new StringBuilder(); + message.append("WARNING: Some required internal classes are unavailable. Please consider adding the following JVM arguments\n"); + message.append("WARNING: "); + for (String name: failedToOpen) { + message.append(String.format("--add-opens jdk.compiler/%s=ALL-UNNAMED", name)); + } + System.err.println(message); + } + } + } catch (Throwable e) { + System.err.println("WARNING: Failed to check for unavailable JDK packages. Reason: " + e.getMessage()); + } + } + + private static List unavailableRequiredPackages() { + final List packages = new ArrayList<>(); + for (Map.Entry e : REQUIRED_PACKAGES_TO_TEST_CLASSES.entrySet()) { + final String key = e.getKey(); + final String value = e.getValue(); + try { + final Class clazz = Class.forName(key + "." + value); + if (clazz.isEnum()) { + clazz.getMethod("values").invoke(null); + } else { + clazz.getDeclaredConstructor().newInstance(); + } + } catch (IllegalAccessException ex) { + packages.add(key); + } catch (Exception ignore) { + // in old versions of JDK some classes could be unavailable + } + } + return packages; + } + + @SuppressWarnings("unchecked") + private static void openPackages(Collection packagesToOpen) throws Throwable { + final Collection modules = allModules(); + if (modules == null) { + return; + } + final Unsafe unsafe = Unsafe.getUnsafe(); + final Field implLookupField = MethodHandles.Lookup.class.getDeclaredField("IMPL_LOOKUP"); + final MethodHandles.Lookup lookup = (MethodHandles.Lookup) unsafe.getObject( + unsafe.staticFieldBase(implLookupField), + unsafe.staticFieldOffset(implLookupField)); + final MethodHandle modifiers = lookup.findSetter(Method.class, "modifiers", Integer.TYPE); + final Method exportMethod = Class.forName("java.lang.Module").getDeclaredMethod("implAddOpens", String.class); + modifiers.invokeExact(exportMethod, Modifier.PUBLIC); + for (Object module : modules) { + final Collection packages = (Collection) module.getClass().getMethod("getPackages").invoke(module); + for (String name : packages) { + if (packagesToOpen.contains(name)) { + exportMethod.invoke(module, name); + } + } + } + } + + @Nullable + // calling ModuleLayer.boot().modules() by reflection + private static Collection allModules() { + try { + final Object boot = Class.forName("java.lang.ModuleLayer").getMethod("boot").invoke(null); + if (boot == null) { + return null; + } + final Object modules = boot.getClass().getMethod("modules").invoke(boot); + return (Collection) modules; + } catch (Exception ignore) { + return null; + } + } +} From 81ce19b2841f74f9c31ce4b68e2aef42eba4a27f Mon Sep 17 00:00:00 2001 From: tison Date: Wed, 1 Jun 2022 23:46:27 +0800 Subject: [PATCH 140/757] remove unrelated modules Signed-off-by: tison --- lib/src/main/java/com/diffplug/spotless/ModuleHelper.java | 5 ----- 1 file changed, 5 deletions(-) diff --git a/lib/src/main/java/com/diffplug/spotless/ModuleHelper.java b/lib/src/main/java/com/diffplug/spotless/ModuleHelper.java index d4895afd20..a81be46442 100644 --- a/lib/src/main/java/com/diffplug/spotless/ModuleHelper.java +++ b/lib/src/main/java/com/diffplug/spotless/ModuleHelper.java @@ -38,12 +38,7 @@ public final class ModuleHelper { REQUIRED_PACKAGES_TO_TEST_CLASSES.putIfAbsent("com.sun.tools.javac.util", "Context"); REQUIRED_PACKAGES_TO_TEST_CLASSES.putIfAbsent("com.sun.tools.javac.file", "CacheFSInfo"); REQUIRED_PACKAGES_TO_TEST_CLASSES.putIfAbsent("com.sun.tools.javac.tree", "TreeTranslator"); - REQUIRED_PACKAGES_TO_TEST_CLASSES.putIfAbsent("com.sun.tools.javac.main", "CommandLine"); - REQUIRED_PACKAGES_TO_TEST_CLASSES.putIfAbsent("com.sun.tools.javac.jvm", "ClassFile"); REQUIRED_PACKAGES_TO_TEST_CLASSES.putIfAbsent("com.sun.tools.javac.parser", "Tokens$TokenKind"); - REQUIRED_PACKAGES_TO_TEST_CLASSES.putIfAbsent("com.sun.tools.javac.code", "Source"); - REQUIRED_PACKAGES_TO_TEST_CLASSES.putIfAbsent("com.sun.tools.javac.processing", "PrintingProcessor"); - REQUIRED_PACKAGES_TO_TEST_CLASSES.putIfAbsent("com.sun.tools.javac.comp", "AttrContext"); REQUIRED_PACKAGES_TO_TEST_CLASSES.putIfAbsent("com.sun.tools.javac.api", "DiagnosticFormatter$PositionKind"); } From 31d5791aac07f282064776b064666e1355de0a61 Mon Sep 17 00:00:00 2001 From: tison Date: Thu, 2 Jun 2022 00:39:47 +0800 Subject: [PATCH 141/757] run spotlessApply Signed-off-by: tison --- lib/src/main/java/com/diffplug/spotless/Jvm.java | 2 +- lib/src/main/java/com/diffplug/spotless/ModuleHelper.java | 7 +++---- 2 files changed, 4 insertions(+), 5 deletions(-) diff --git a/lib/src/main/java/com/diffplug/spotless/Jvm.java b/lib/src/main/java/com/diffplug/spotless/Jvm.java index 8d7482cb61..7756ffa917 100644 --- a/lib/src/main/java/com/diffplug/spotless/Jvm.java +++ b/lib/src/main/java/com/diffplug/spotless/Jvm.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. diff --git a/lib/src/main/java/com/diffplug/spotless/ModuleHelper.java b/lib/src/main/java/com/diffplug/spotless/ModuleHelper.java index a81be46442..0ccd3c8c15 100644 --- a/lib/src/main/java/com/diffplug/spotless/ModuleHelper.java +++ b/lib/src/main/java/com/diffplug/spotless/ModuleHelper.java @@ -13,7 +13,6 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package com.diffplug.spotless; import java.lang.invoke.MethodHandle; @@ -58,7 +57,7 @@ public static synchronized void doOpenInternalPackagesIfRequired() { final StringBuilder message = new StringBuilder(); message.append("WARNING: Some required internal classes are unavailable. Please consider adding the following JVM arguments\n"); message.append("WARNING: "); - for (String name: failedToOpen) { + for (String name : failedToOpen) { message.append(String.format("--add-opens jdk.compiler/%s=ALL-UNNAMED", name)); } System.err.println(message); @@ -99,8 +98,8 @@ private static void openPackages(Collection packagesToOpen) throws Throw final Unsafe unsafe = Unsafe.getUnsafe(); final Field implLookupField = MethodHandles.Lookup.class.getDeclaredField("IMPL_LOOKUP"); final MethodHandles.Lookup lookup = (MethodHandles.Lookup) unsafe.getObject( - unsafe.staticFieldBase(implLookupField), - unsafe.staticFieldOffset(implLookupField)); + unsafe.staticFieldBase(implLookupField), + unsafe.staticFieldOffset(implLookupField)); final MethodHandle modifiers = lookup.findSetter(Method.class, "modifiers", Integer.TYPE); final Method exportMethod = Class.forName("java.lang.Module").getDeclaredMethod("implAddOpens", String.class); modifiers.invokeExact(exportMethod, Modifier.PUBLIC); From 2033c6ab7cc570f7fedcb83af4647eac31dfee60 Mon Sep 17 00:00:00 2001 From: tison Date: Thu, 2 Jun 2022 07:31:39 +0800 Subject: [PATCH 142/757] SuppressFBWarnings REC_CATCH_EXCEPTION Signed-off-by: tison --- lib/src/main/java/com/diffplug/spotless/ModuleHelper.java | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/lib/src/main/java/com/diffplug/spotless/ModuleHelper.java b/lib/src/main/java/com/diffplug/spotless/ModuleHelper.java index 0ccd3c8c15..0ab4f95540 100644 --- a/lib/src/main/java/com/diffplug/spotless/ModuleHelper.java +++ b/lib/src/main/java/com/diffplug/spotless/ModuleHelper.java @@ -28,6 +28,7 @@ import javax.annotation.Nullable; +import edu.umd.cs.findbugs.annotations.SuppressFBWarnings; import sun.misc.Unsafe; public final class ModuleHelper { @@ -68,6 +69,7 @@ public static synchronized void doOpenInternalPackagesIfRequired() { } } + @SuppressFBWarnings("REC_CATCH_EXCEPTION") // workaround JDK11 private static List unavailableRequiredPackages() { final List packages = new ArrayList<>(); for (Map.Entry e : REQUIRED_PACKAGES_TO_TEST_CLASSES.entrySet()) { @@ -114,8 +116,9 @@ private static void openPackages(Collection packagesToOpen) throws Throw } @Nullable - // calling ModuleLayer.boot().modules() by reflection + @SuppressFBWarnings("REC_CATCH_EXCEPTION") // workaround JDK11 private static Collection allModules() { + // calling ModuleLayer.boot().modules() by reflection try { final Object boot = Class.forName("java.lang.ModuleLayer").getMethod("boot").invoke(null); if (boot == null) { From 7474c2544849ebc3c1a15a49548122de0da776ca Mon Sep 17 00:00:00 2001 From: tison Date: Thu, 2 Jun 2022 23:20:18 +0800 Subject: [PATCH 143/757] Update CHANGES files Signed-off-by: tison --- CHANGES.md | 2 ++ plugin-gradle/CHANGES.md | 2 ++ plugin-maven/CHANGES.md | 2 ++ 3 files changed, 6 insertions(+) diff --git a/CHANGES.md b/CHANGES.md index 8d2011de17..a5b391e794 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -10,6 +10,8 @@ This document is intended for Spotless developers. We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format (starting after version `1.27.0`). ## [Unreleased] +### Fixed +* google-java-format works on JDK16+ without jvm args workaround. ([#1224](https://github.com/diffplug/spotless/pull/1224)) ## [2.25.3] - 2022-05-10 ### Fixed diff --git a/plugin-gradle/CHANGES.md b/plugin-gradle/CHANGES.md index e67e6546bb..ad048e0a52 100644 --- a/plugin-gradle/CHANGES.md +++ b/plugin-gradle/CHANGES.md @@ -3,6 +3,8 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format (starting after version `3.27.0`). ## [Unreleased] +### Fixed +* google-java-format works on JDK16+ without jvm args workaround. ([#1224](https://github.com/diffplug/spotless/pull/1224)) ## [6.6.1] - 2022-05-13 ### Fixed diff --git a/plugin-maven/CHANGES.md b/plugin-maven/CHANGES.md index a0dbcc1d97..85094381e2 100644 --- a/plugin-maven/CHANGES.md +++ b/plugin-maven/CHANGES.md @@ -3,6 +3,8 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format (starting after version `1.27.0`). ## [Unreleased] +### Fixed +* google-java-format works on JDK16+ without jvm args workaround. ([#1224](https://github.com/diffplug/spotless/pull/1224)) ## [2.22.5] - 2022-05-10 ### Fixed From 2631a3f276b0350c360ea92eec553e1a8780f5ea Mon Sep 17 00:00:00 2001 From: tison Date: Thu, 2 Jun 2022 23:34:18 +0800 Subject: [PATCH 144/757] only doOpenInternalPackagesIfRequired when GoogleJavaFormatStep is relevant Signed-off-by: tison --- lib/src/main/java/com/diffplug/spotless/Jvm.java | 3 --- .../com/diffplug/spotless/java/GoogleJavaFormatStep.java | 1 + .../com/diffplug/spotless/{ => java}/ModuleHelper.java | 7 +++++-- 3 files changed, 6 insertions(+), 5 deletions(-) rename lib/src/main/java/com/diffplug/spotless/{ => java}/ModuleHelper.java (97%) diff --git a/lib/src/main/java/com/diffplug/spotless/Jvm.java b/lib/src/main/java/com/diffplug/spotless/Jvm.java index 7756ffa917..14686c1e4c 100644 --- a/lib/src/main/java/com/diffplug/spotless/Jvm.java +++ b/lib/src/main/java/com/diffplug/spotless/Jvm.java @@ -48,9 +48,6 @@ public final class Jvm { if (VERSION <= 8) { throw new IllegalArgumentException("Expected " + jre + " to start with an integer greater than 8"); } - if (VERSION >= 16) { - ModuleHelper.doOpenInternalPackagesIfRequired(); - } } } diff --git a/lib/src/main/java/com/diffplug/spotless/java/GoogleJavaFormatStep.java b/lib/src/main/java/com/diffplug/spotless/java/GoogleJavaFormatStep.java index 6aec20c891..6390c619a9 100644 --- a/lib/src/main/java/com/diffplug/spotless/java/GoogleJavaFormatStep.java +++ b/lib/src/main/java/com/diffplug/spotless/java/GoogleJavaFormatStep.java @@ -136,6 +136,7 @@ static final class State implements Serializable { State(String stepName, String groupArtifact, String version, String style, Provisioner provisioner, boolean reflowLongStrings) throws Exception { JVM_SUPPORT.assertFormatterSupported(version); + ModuleHelper.doOpenInternalPackagesIfRequired(); this.jarState = JarState.from(groupArtifact + ":" + version, provisioner); this.stepName = stepName; this.version = version; diff --git a/lib/src/main/java/com/diffplug/spotless/ModuleHelper.java b/lib/src/main/java/com/diffplug/spotless/java/ModuleHelper.java similarity index 97% rename from lib/src/main/java/com/diffplug/spotless/ModuleHelper.java rename to lib/src/main/java/com/diffplug/spotless/java/ModuleHelper.java index 0ab4f95540..274b33d09f 100644 --- a/lib/src/main/java/com/diffplug/spotless/ModuleHelper.java +++ b/lib/src/main/java/com/diffplug/spotless/java/ModuleHelper.java @@ -13,7 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package com.diffplug.spotless; +package com.diffplug.spotless.java; import java.lang.invoke.MethodHandle; import java.lang.invoke.MethodHandles; @@ -31,7 +31,10 @@ import edu.umd.cs.findbugs.annotations.SuppressFBWarnings; import sun.misc.Unsafe; -public final class ModuleHelper { +final class ModuleHelper { + // prevent direct instantiation + private ModuleHelper() {} + private static final Map REQUIRED_PACKAGES_TO_TEST_CLASSES = new HashMap<>(); static { From 75616a06dc75c1bce8683d299cb0bce181ef08d8 Mon Sep 17 00:00:00 2001 From: Ned Twigg Date: Sat, 4 Jun 2022 17:05:28 -0700 Subject: [PATCH 145/757] Update changelog. --- CHANGES.md | 4 ++-- plugin-gradle/CHANGES.md | 5 +++-- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/CHANGES.md b/CHANGES.md index 9b0f9ae0ea..0a3351fe91 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -10,8 +10,8 @@ This document is intended for Spotless developers. We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format (starting after version `1.27.0`). ## [Unreleased] - -* Add support for `editorConfigOverride` in `ktlint`. ([#1218](https://github.com/diffplug/spotless/pull/1218) fixes [#1193](https://github.com/diffplug/spotless/issues/1193)) +### Added +* Support for `editorConfigOverride` in `ktlint`. ([#1218](https://github.com/diffplug/spotless/pull/1218) fixes [#1193](https://github.com/diffplug/spotless/issues/1193)) ## [2.25.3] - 2022-05-10 ### Fixed diff --git a/plugin-gradle/CHANGES.md b/plugin-gradle/CHANGES.md index 06c8988425..0732a18cee 100644 --- a/plugin-gradle/CHANGES.md +++ b/plugin-gradle/CHANGES.md @@ -3,8 +3,9 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format (starting after version `3.27.0`). ## [Unreleased] - -* Add support for `editorConfigOverride` in `ktlint`. ([#1218](https://github.com/diffplug/spotless/pull/1218) fixes [#1193](https://github.com/diffplug/spotless/issues/1193)) +### Added +* Support for `editorConfigOverride` in `ktlint`. ([#1218](https://github.com/diffplug/spotless/pull/1218) fixes [#1193](https://github.com/diffplug/spotless/issues/1193)) + * If you are using properties like `indent_size`, you should pass now pass them as `editorConfigOverride` and not as `userData`. ## [6.6.1] - 2022-05-13 ### Fixed From b3fc6bc069f39cda48ff4d2144981acdb5358e8c Mon Sep 17 00:00:00 2001 From: Ned Twigg Date: Sat, 4 Jun 2022 18:56:54 -0700 Subject: [PATCH 146/757] Only run ModuleHelper for JVM >= 16. --- .../main/java/com/diffplug/spotless/java/ModuleHelper.java | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/lib/src/main/java/com/diffplug/spotless/java/ModuleHelper.java b/lib/src/main/java/com/diffplug/spotless/java/ModuleHelper.java index 274b33d09f..68a2a181d0 100644 --- a/lib/src/main/java/com/diffplug/spotless/java/ModuleHelper.java +++ b/lib/src/main/java/com/diffplug/spotless/java/ModuleHelper.java @@ -28,6 +28,8 @@ import javax.annotation.Nullable; +import com.diffplug.spotless.Jvm; + import edu.umd.cs.findbugs.annotations.SuppressFBWarnings; import sun.misc.Unsafe; @@ -48,7 +50,7 @@ private ModuleHelper() {} private static boolean checkDone = false; public static synchronized void doOpenInternalPackagesIfRequired() { - if (checkDone) { + if (Jvm.version() < 16 || checkDone) { return; } try { From bd8341772ad31305538de09458d51517a278c310 Mon Sep 17 00:00:00 2001 From: Ned Twigg Date: Sat, 4 Jun 2022 18:57:45 -0700 Subject: [PATCH 147/757] Improve the maven changelog entry. --- plugin-maven/CHANGES.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/plugin-maven/CHANGES.md b/plugin-maven/CHANGES.md index 85094381e2..01cf26bcbd 100644 --- a/plugin-maven/CHANGES.md +++ b/plugin-maven/CHANGES.md @@ -4,7 +4,8 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format ( ## [Unreleased] ### Fixed -* google-java-format works on JDK16+ without jvm args workaround. ([#1224](https://github.com/diffplug/spotless/pull/1224)) +* `googleJavaFormat` and `removeUnusedImports` works on JDK16+ without jvm args workaround. ([#1224](https://github.com/diffplug/spotless/pull/1224)) + * If you have a bunch of `--add-exports` calls in `MAVEN_OPTS` or `.mvn/jvm.config`, you should be able to remove them. (fixes [#834](https://github.com/diffplug/spotless/issues/834#issuecomment-817524058)) ## [2.22.5] - 2022-05-10 ### Fixed From be40828864870b75aca974dd890e188a04dc2f8b Mon Sep 17 00:00:00 2001 From: circleci Date: Sun, 5 Jun 2022 16:03:45 +0000 Subject: [PATCH 148/757] Published lib/2.26.0 --- CHANGES.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/CHANGES.md b/CHANGES.md index df4135c4bd..1837866009 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -10,6 +10,8 @@ This document is intended for Spotless developers. We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format (starting after version `1.27.0`). ## [Unreleased] + +## [2.26.0] - 2022-06-05 ### Added * Support for `editorConfigOverride` in `ktlint`. ([#1218](https://github.com/diffplug/spotless/pull/1218) fixes [#1193](https://github.com/diffplug/spotless/issues/1193)) ### Fixed From 9ca9917405961933a934a175c39501dba6652f63 Mon Sep 17 00:00:00 2001 From: circleci Date: Sun, 5 Jun 2022 16:04:33 +0000 Subject: [PATCH 149/757] Published gradle/6.7.0 --- plugin-gradle/CHANGES.md | 2 ++ plugin-gradle/README.md | 46 ++++++++++++++++++++-------------------- 2 files changed, 25 insertions(+), 23 deletions(-) diff --git a/plugin-gradle/CHANGES.md b/plugin-gradle/CHANGES.md index edbbf11915..0e7d6d6267 100644 --- a/plugin-gradle/CHANGES.md +++ b/plugin-gradle/CHANGES.md @@ -3,6 +3,8 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format (starting after version `3.27.0`). ## [Unreleased] + +## [6.7.0] - 2022-06-05 ### Added * Support for `editorConfigOverride` in `ktlint`. ([#1218](https://github.com/diffplug/spotless/pull/1218) fixes [#1193](https://github.com/diffplug/spotless/issues/1193)) * If you are using properties like `indent_size`, you should pass now pass them as `editorConfigOverride` and not as `userData`. diff --git a/plugin-gradle/README.md b/plugin-gradle/README.md index e7f1f92107..ab5204d99f 100644 --- a/plugin-gradle/README.md +++ b/plugin-gradle/README.md @@ -18,9 +18,9 @@ output = [ --> [![Gradle plugin](https://img.shields.io/badge/plugins.gradle.org-com.diffplug.spotless-blue.svg)](https://plugins.gradle.org/plugin/com.diffplug.spotless) [![Maven central](https://img.shields.io/badge/mavencentral-yes-blue.svg)](https://search.maven.org/#search%7Cgav%7C1%7Cg%3A%22com.diffplug.spotless%22%20AND%20a%3A%22spotless-plugin-gradle%22) -[![Javadoc](https://img.shields.io/badge/javadoc-yes-blue.svg)](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.6.1/index.html) +[![Javadoc](https://img.shields.io/badge/javadoc-yes-blue.svg)](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.7.0/index.html) [![License Apache](https://img.shields.io/badge/license-apache-blue.svg)](https://tldrlegal.com/license/apache-license-2.0-(apache-2.0)) -[![Changelog](https://img.shields.io/badge/changelog-6.6.1-blue.svg)](CHANGES.md) +[![Changelog](https://img.shields.io/badge/changelog-6.7.0-blue.svg)](CHANGES.md) [![Circle CI](https://circleci.com/gh/diffplug/spotless/tree/main.svg?style=shield)](https://circleci.com/gh/diffplug/spotless/tree/main) [![Live chat](https://img.shields.io/badge/gitter-chat-brightgreen.svg)](https://gitter.im/diffplug/spotless) @@ -126,10 +126,10 @@ spotless { ``` Spotless consists of a list of formats (in the example above, `misc` and `java`), and each format has: -- a `target` (the files to format), which you set with [`target`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.6.1/com/diffplug/gradle/spotless/FormatExtension.html#target-java.lang.Object...-) and [`targetExclude`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.6.1/com/diffplug/gradle/spotless/FormatExtension.html#targetExclude-java.lang.Object...-) -- a list of `FormatterStep`, which are just `String -> String` functions, such as [`replace`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.6.1/com/diffplug/gradle/spotless/FormatExtension.html#replace-java.lang.String-java.lang.CharSequence-java.lang.CharSequence-), [`replaceRegex`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.6.1/com/diffplug/gradle/spotless/FormatExtension.html#replaceRegex-java.lang.String-java.lang.String-java.lang.String-), [`trimTrailingWhitespace`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.6.1/com/diffplug/gradle/spotless/FormatExtension.html#replace-java.lang.String-java.lang.CharSequence-java.lang.CharSequence-), [`custom`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.6.1/com/diffplug/gradle/spotless/FormatExtension.html#custom-java.lang.String-groovy.lang.Closure-), [`prettier`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.6.1/com/diffplug/gradle/spotless/FormatExtension.html#prettier--), [`eclipseWtp`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.6.1/com/diffplug/gradle/spotless/FormatExtension.html#eclipseWtp-com.diffplug.spotless.extra.wtp.EclipseWtpFormatterStep-), [`licenseHeader`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.6.1/com/diffplug/gradle/spotless/FormatExtension.html#licenseHeader-java.lang.String-java.lang.String-) etc. +- a `target` (the files to format), which you set with [`target`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.7.0/com/diffplug/gradle/spotless/FormatExtension.html#target-java.lang.Object...-) and [`targetExclude`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.7.0/com/diffplug/gradle/spotless/FormatExtension.html#targetExclude-java.lang.Object...-) +- a list of `FormatterStep`, which are just `String -> String` functions, such as [`replace`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.7.0/com/diffplug/gradle/spotless/FormatExtension.html#replace-java.lang.String-java.lang.CharSequence-java.lang.CharSequence-), [`replaceRegex`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.7.0/com/diffplug/gradle/spotless/FormatExtension.html#replaceRegex-java.lang.String-java.lang.String-java.lang.String-), [`trimTrailingWhitespace`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.7.0/com/diffplug/gradle/spotless/FormatExtension.html#replace-java.lang.String-java.lang.CharSequence-java.lang.CharSequence-), [`custom`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.7.0/com/diffplug/gradle/spotless/FormatExtension.html#custom-java.lang.String-groovy.lang.Closure-), [`prettier`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.7.0/com/diffplug/gradle/spotless/FormatExtension.html#prettier--), [`eclipseWtp`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.7.0/com/diffplug/gradle/spotless/FormatExtension.html#eclipseWtp-com.diffplug.spotless.extra.wtp.EclipseWtpFormatterStep-), [`licenseHeader`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.7.0/com/diffplug/gradle/spotless/FormatExtension.html#licenseHeader-java.lang.String-java.lang.String-) etc. -All the generic steps live in [`FormatExtension`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.6.1/com/diffplug/gradle/spotless/FormatExtension.html), and there are many language-specific steps which live in its language-specific subclasses, which are described below. +All the generic steps live in [`FormatExtension`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.7.0/com/diffplug/gradle/spotless/FormatExtension.html), and there are many language-specific steps which live in its language-specific subclasses, which are described below. ### Requirements @@ -141,7 +141,7 @@ If you're stuck on an older version of Gradle, `id 'com.diffplug.gradle.spotless ## Java -`com.diffplug.gradle.spotless.JavaExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.6.1/com/diffplug/gradle/spotless/JavaExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/JavaExtension.java) +`com.diffplug.gradle.spotless.JavaExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.7.0/com/diffplug/gradle/spotless/JavaExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/JavaExtension.java) ```gradle spotless { @@ -248,8 +248,8 @@ spotless { ## Groovy -- `com.diffplug.gradle.spotless.GroovyExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.6.1/com/diffplug/gradle/spotless/GroovyExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/GroovyExtension.java) -- `com.diffplug.gradle.spotless.GroovyGradleExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.6.1/com/diffplug/gradle/spotless/GroovyGradleExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/GroovyGradleExtension.java) +- `com.diffplug.gradle.spotless.GroovyExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.7.0/com/diffplug/gradle/spotless/GroovyExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/GroovyExtension.java) +- `com.diffplug.gradle.spotless.GroovyGradleExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.7.0/com/diffplug/gradle/spotless/GroovyGradleExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/GroovyGradleExtension.java) Configuration for Groovy is similar to [Java](#java), in that it also supports `licenseHeader` and `importOrder`. @@ -300,8 +300,8 @@ Groovy-Eclipse formatting errors/warnings lead per default to a build failure. T ## Kotlin -- `com.diffplug.gradle.spotless.KotlinExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.6.1/com/diffplug/gradle/spotless/KotlinExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/KotlinExtension.java) -- `com.diffplug.gradle.spotless.KotlinGradleExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.6.1/com/diffplug/gradle/spotless/KotlinGradleExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/KotlinGradleExtension.java) +- `com.diffplug.gradle.spotless.KotlinExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.7.0/com/diffplug/gradle/spotless/KotlinExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/KotlinExtension.java) +- `com.diffplug.gradle.spotless.KotlinGradleExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.7.0/com/diffplug/gradle/spotless/KotlinGradleExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/KotlinGradleExtension.java) ```gradle spotless { // if you are using build.gradle.kts, instead of 'spotless {' use: @@ -364,7 +364,7 @@ spotless { ## Scala -`com.diffplug.gradle.spotless.ScalaExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.6.1/com/diffplug/gradle/spotless/ScalaExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/ScalaExtension.java) +`com.diffplug.gradle.spotless.ScalaExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.7.0/com/diffplug/gradle/spotless/ScalaExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/ScalaExtension.java) ```gradle spotless { @@ -396,7 +396,7 @@ spotless { ## C/C++ -`com.diffplug.gradle.spotless.CppExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.6.1/com/diffplug/gradle/spotless/CppExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/CppExtension.java) +`com.diffplug.gradle.spotless.CppExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.7.0/com/diffplug/gradle/spotless/CppExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/CppExtension.java) ```gradle spotless { @@ -428,7 +428,7 @@ spotles { ## Python -`com.diffplug.gradle.spotless.PythonExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.6.1/com/diffplug/gradle/spotless/PythonExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/PythonExtension.java) +`com.diffplug.gradle.spotless.PythonExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.7.0/com/diffplug/gradle/spotless/PythonExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/PythonExtension.java) ```gradle spotless { @@ -462,7 +462,7 @@ black().pathToExe('C:/myuser/.pyenv/versions/3.8.0/scripts/black.exe') ## FreshMark -`com.diffplug.gradle.spotless.FreshMarkExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.6.1/com/diffplug/gradle/spotless/FreshMarkExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/FreshMarkExtension.java) +`com.diffplug.gradle.spotless.FreshMarkExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.7.0/com/diffplug/gradle/spotless/FreshMarkExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/FreshMarkExtension.java) [homepage](https://github.com/diffplug/freshmark). [changelog](https://github.com/diffplug/freshmark/blob/master/CHANGES.md). FreshMark lets you generate markdown in the comments of your markdown. This helps to keep badges and links up-to-date (see the source for this file), and can also be helpful for generating complex tables (see the source for [the parent readme](../README.md)). @@ -483,7 +483,7 @@ spotless { ## Antlr4 -`com.diffplug.gradle.spotless.Antlr4Extension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.6.1/com/diffplug/gradle/spotless/Antlr4Extension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/Antlr4Extension.java) +`com.diffplug.gradle.spotless.Antlr4Extension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.7.0/com/diffplug/gradle/spotless/Antlr4Extension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/Antlr4Extension.java) ```gradle spotless { @@ -508,7 +508,7 @@ antlr4formatter('1.2.1') // version is optional ## SQL -`com.diffplug.gradle.spotless.SqlExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.6.1/com/diffplug/gradle/spotless/SqlExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/SqlExtension.java) +`com.diffplug.gradle.spotless.SqlExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.7.0/com/diffplug/gradle/spotless/SqlExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/SqlExtension.java) ```gradle spotless { @@ -548,7 +548,7 @@ sql.formatter.indent.size=4 ## Typescript -- `com.diffplug.gradle.spotless.TypescriptExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.6.1/com/diffplug/gradle/spotless/TypescriptExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/TypescriptExtension.java) +- `com.diffplug.gradle.spotless.TypescriptExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.7.0/com/diffplug/gradle/spotless/TypescriptExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/TypescriptExtension.java) ```gradle spotless { @@ -591,7 +591,7 @@ For details, see the [npm detection](#npm-detection) and [`.npmrc` detection](#n ## JSON -- `com.diffplug.gradle.spotless.JsonExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.6.1/com/diffplug/gradle/spotless/JsonExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/JsonExtension.java) +- `com.diffplug.gradle.spotless.JsonExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.7.0/com/diffplug/gradle/spotless/JsonExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/JsonExtension.java) ```gradle spotless { @@ -816,7 +816,7 @@ Once a file's license header has a valid year, whether it is a year (`2020`) or * `2017` -> `2017-2020` * `2017-2019` -> `2017-2020` -See the [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.6.1/com/diffplug/gradle/spotless/FormatExtension.LicenseHeaderConfig.html) for a complete listing of options. +See the [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.7.0/com/diffplug/gradle/spotless/FormatExtension.LicenseHeaderConfig.html) for a complete listing of options. @@ -883,9 +883,9 @@ spotless { custom 'lowercase', { str -> str.toLowerCase() } ``` -However, custom rules will disable up-to-date checking and caching, unless you read [this javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.6.1/com/diffplug/gradle/spotless/FormatExtension.html#bumpThisNumberIfACustomStepChanges-int-) and follow its instructions carefully. +However, custom rules will disable up-to-date checking and caching, unless you read [this javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.7.0/com/diffplug/gradle/spotless/FormatExtension.html#bumpThisNumberIfACustomStepChanges-int-) and follow its instructions carefully. -Another option is to create proper `FormatterStep` in your `buildSrc`, and then call [`addStep`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.6.1/com/diffplug/gradle/spotless/FormatExtension.html#addStep-com.diffplug.spotless.FormatterStep-). The contributing guide describes [how to do this](https://github.com/diffplug/spotless/blob/main/CONTRIBUTING.md#how-to-add-a-new-formatterstep). If the step is generally-useful, we hope you'll open a PR to share it! +Another option is to create proper `FormatterStep` in your `buildSrc`, and then call [`addStep`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.7.0/com/diffplug/gradle/spotless/FormatExtension.html#addStep-com.diffplug.spotless.FormatterStep-). The contributing guide describes [how to do this](https://github.com/diffplug/spotless/blob/main/CONTRIBUTING.md#how-to-add-a-new-formatterstep). If the step is generally-useful, we hope you'll open a PR to share it! ```gradle @@ -918,11 +918,11 @@ spotless { format 'foo', com.acme.FooLanguageExtension, { ``` -If you'd like to create a one-off Spotless task outside of the `check`/`apply` framework, see [`FormatExtension.createIndependentApplyTask`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.6.1/com/diffplug/gradle/spotless/FormatExtension.html#createIndependentApplyTask-java.lang.String-). +If you'd like to create a one-off Spotless task outside of the `check`/`apply` framework, see [`FormatExtension.createIndependentApplyTask`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.7.0/com/diffplug/gradle/spotless/FormatExtension.html#createIndependentApplyTask-java.lang.String-). ## Inception (languages within languages within...) -In very rare cases, you might want to format e.g. javascript which is written inside JSP templates, or maybe java within a markdown file, or something wacky like that. You can specify hunks within a file using either open/close tags or a regex with a single capturing group, and then specify rules within it, like so. See [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.6.1/com/diffplug/gradle/spotless/FormatExtension.html#withinBlocks-java.lang.String-java.lang.String-java.lang.String-org.gradle.api.Action-) for more details. +In very rare cases, you might want to format e.g. javascript which is written inside JSP templates, or maybe java within a markdown file, or something wacky like that. You can specify hunks within a file using either open/close tags or a regex with a single capturing group, and then specify rules within it, like so. See [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.7.0/com/diffplug/gradle/spotless/FormatExtension.html#withinBlocks-java.lang.String-java.lang.String-java.lang.String-org.gradle.api.Action-) for more details. ```gradle import com.diffplug.gradle.spotless.JavaExtension From 2a0f65add24c25239bc526a6ccf1496a4c3f8ba1 Mon Sep 17 00:00:00 2001 From: circleci Date: Sun, 5 Jun 2022 16:06:20 +0000 Subject: [PATCH 150/757] Published maven/2.22.6 --- plugin-maven/CHANGES.md | 2 ++ plugin-maven/README.md | 4 ++-- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/plugin-maven/CHANGES.md b/plugin-maven/CHANGES.md index 01cf26bcbd..e5fcb0e6d2 100644 --- a/plugin-maven/CHANGES.md +++ b/plugin-maven/CHANGES.md @@ -3,6 +3,8 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format (starting after version `1.27.0`). ## [Unreleased] + +## [2.22.6] - 2022-06-05 ### Fixed * `googleJavaFormat` and `removeUnusedImports` works on JDK16+ without jvm args workaround. ([#1224](https://github.com/diffplug/spotless/pull/1224)) * If you have a bunch of `--add-exports` calls in `MAVEN_OPTS` or `.mvn/jvm.config`, you should be able to remove them. (fixes [#834](https://github.com/diffplug/spotless/issues/834#issuecomment-817524058)) diff --git a/plugin-maven/README.md b/plugin-maven/README.md index 3486a37255..50e0a5ed99 100644 --- a/plugin-maven/README.md +++ b/plugin-maven/README.md @@ -12,8 +12,8 @@ output = [ ].join('\n'); --> [![Maven central](https://img.shields.io/badge/mavencentral-com.diffplug.spotless%3Aspotless--maven--plugin-blue.svg)](https://search.maven.org/#search%7Cgav%7C1%7Cg%3A%22com.diffplug.spotless%22%20AND%20a%3A%22spotless-maven-plugin%22) -[![Javadoc](https://img.shields.io/badge/javadoc-yes-blue.svg)](https://javadoc.io/doc/com.diffplug.spotless/spotless-maven-plugin/2.22.5/index.html) -[![Changelog](https://img.shields.io/badge/changelog-2.22.5-brightgreen.svg)](CHANGES.md) +[![Javadoc](https://img.shields.io/badge/javadoc-yes-blue.svg)](https://javadoc.io/doc/com.diffplug.spotless/spotless-maven-plugin/2.22.6/index.html) +[![Changelog](https://img.shields.io/badge/changelog-2.22.6-brightgreen.svg)](CHANGES.md) [![Circle CI](https://circleci.com/gh/diffplug/spotless/tree/main.svg?style=shield)](https://circleci.com/gh/diffplug/spotless/tree/main) [![Live chat](https://img.shields.io/badge/gitter-chat-brightgreen.svg)](https://gitter.im/diffplug/spotless) From 3cc562682d7ab810672fce6d222cf5cf2bbabd5f Mon Sep 17 00:00:00 2001 From: tison Date: Fri, 3 Jun 2022 00:14:13 +0800 Subject: [PATCH 151/757] get theUnsafe by reflection Signed-off-by: tison --- .../main/java/com/diffplug/spotless/java/ModuleHelper.java | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/lib/src/main/java/com/diffplug/spotless/java/ModuleHelper.java b/lib/src/main/java/com/diffplug/spotless/java/ModuleHelper.java index 68a2a181d0..415c58d69b 100644 --- a/lib/src/main/java/com/diffplug/spotless/java/ModuleHelper.java +++ b/lib/src/main/java/com/diffplug/spotless/java/ModuleHelper.java @@ -102,7 +102,9 @@ private static void openPackages(Collection packagesToOpen) throws Throw if (modules == null) { return; } - final Unsafe unsafe = Unsafe.getUnsafe(); + final Field unsafeField = Unsafe.class.getDeclaredField("theUnsafe"); + unsafeField.setAccessible(true); + final Unsafe unsafe = (Unsafe) unsafeField.get(null); final Field implLookupField = MethodHandles.Lookup.class.getDeclaredField("IMPL_LOOKUP"); final MethodHandles.Lookup lookup = (MethodHandles.Lookup) unsafe.getObject( unsafe.staticFieldBase(implLookupField), From 6f98128680b715e7210e58faa11ba4b95bbc6f88 Mon Sep 17 00:00:00 2001 From: Ned Twigg Date: Thu, 9 Jun 2022 17:01:19 -0700 Subject: [PATCH 152/757] Update changelogs. --- CHANGES.md | 2 ++ plugin-gradle/CHANGES.md | 3 +++ plugin-maven/CHANGES.md | 3 +++ 3 files changed, 8 insertions(+) diff --git a/CHANGES.md b/CHANGES.md index 1837866009..d8090f8079 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -10,6 +10,8 @@ This document is intended for Spotless developers. We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format (starting after version `1.27.0`). ## [Unreleased] +### Fixed +* (Second try) `googleJavaFormat` and `removeUnusedImports` works on JDK16+ without jvm args workaround. ([#1228](https://github.com/diffplug/spotless/pull/1228)) ## [2.26.0] - 2022-06-05 ### Added diff --git a/plugin-gradle/CHANGES.md b/plugin-gradle/CHANGES.md index 0e7d6d6267..392633e7c8 100644 --- a/plugin-gradle/CHANGES.md +++ b/plugin-gradle/CHANGES.md @@ -3,6 +3,9 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format (starting after version `3.27.0`). ## [Unreleased] +### Fixed +* (Second try) `googleJavaFormat` and `removeUnusedImports` works on JDK16+ without jvm args workaround. ([#1228](https://github.com/diffplug/spotless/pull/1228)) + * If you have a bunch of `--add-exports` calls in your `org.gradle.jvmargs` property in `gradle.properties`, you should be able to remove them. (fixes [#834](https://github.com/diffplug/spotless/issues/834#issuecomment-819118761)) ## [6.7.0] - 2022-06-05 ### Added diff --git a/plugin-maven/CHANGES.md b/plugin-maven/CHANGES.md index e5fcb0e6d2..2fa38baba8 100644 --- a/plugin-maven/CHANGES.md +++ b/plugin-maven/CHANGES.md @@ -3,6 +3,9 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format (starting after version `1.27.0`). ## [Unreleased] +### Fixed +* (Second try) `googleJavaFormat` and `removeUnusedImports` works on JDK16+ without jvm args workaround. ([#1228](https://github.com/diffplug/spotless/pull/1228)) + * If you have a bunch of `--add-exports` calls in `MAVEN_OPTS` or `.mvn/jvm.config`, you should be able to remove them. (fixes [#834](https://github.com/diffplug/spotless/issues/834#issuecomment-817524058)) ## [2.22.6] - 2022-06-05 ### Fixed From 78281ed89a7d1c3c596f9e06eea3b301ccb86530 Mon Sep 17 00:00:00 2001 From: circleci Date: Fri, 10 Jun 2022 17:50:07 +0000 Subject: [PATCH 153/757] Published lib/2.26.1 --- CHANGES.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/CHANGES.md b/CHANGES.md index d8090f8079..ea675ade27 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -10,6 +10,8 @@ This document is intended for Spotless developers. We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format (starting after version `1.27.0`). ## [Unreleased] + +## [2.26.1] - 2022-06-10 ### Fixed * (Second try) `googleJavaFormat` and `removeUnusedImports` works on JDK16+ without jvm args workaround. ([#1228](https://github.com/diffplug/spotless/pull/1228)) From b6a18ffa8c5089ba5eabc5e0898f1cdd103de49a Mon Sep 17 00:00:00 2001 From: circleci Date: Fri, 10 Jun 2022 17:51:06 +0000 Subject: [PATCH 154/757] Published gradle/6.7.1 --- plugin-gradle/CHANGES.md | 2 ++ plugin-gradle/README.md | 46 ++++++++++++++++++++-------------------- 2 files changed, 25 insertions(+), 23 deletions(-) diff --git a/plugin-gradle/CHANGES.md b/plugin-gradle/CHANGES.md index 392633e7c8..a13fedf837 100644 --- a/plugin-gradle/CHANGES.md +++ b/plugin-gradle/CHANGES.md @@ -3,6 +3,8 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format (starting after version `3.27.0`). ## [Unreleased] + +## [6.7.1] - 2022-06-10 ### Fixed * (Second try) `googleJavaFormat` and `removeUnusedImports` works on JDK16+ without jvm args workaround. ([#1228](https://github.com/diffplug/spotless/pull/1228)) * If you have a bunch of `--add-exports` calls in your `org.gradle.jvmargs` property in `gradle.properties`, you should be able to remove them. (fixes [#834](https://github.com/diffplug/spotless/issues/834#issuecomment-819118761)) diff --git a/plugin-gradle/README.md b/plugin-gradle/README.md index ab5204d99f..291d0cf027 100644 --- a/plugin-gradle/README.md +++ b/plugin-gradle/README.md @@ -18,9 +18,9 @@ output = [ --> [![Gradle plugin](https://img.shields.io/badge/plugins.gradle.org-com.diffplug.spotless-blue.svg)](https://plugins.gradle.org/plugin/com.diffplug.spotless) [![Maven central](https://img.shields.io/badge/mavencentral-yes-blue.svg)](https://search.maven.org/#search%7Cgav%7C1%7Cg%3A%22com.diffplug.spotless%22%20AND%20a%3A%22spotless-plugin-gradle%22) -[![Javadoc](https://img.shields.io/badge/javadoc-yes-blue.svg)](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.7.0/index.html) +[![Javadoc](https://img.shields.io/badge/javadoc-yes-blue.svg)](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.7.1/index.html) [![License Apache](https://img.shields.io/badge/license-apache-blue.svg)](https://tldrlegal.com/license/apache-license-2.0-(apache-2.0)) -[![Changelog](https://img.shields.io/badge/changelog-6.7.0-blue.svg)](CHANGES.md) +[![Changelog](https://img.shields.io/badge/changelog-6.7.1-blue.svg)](CHANGES.md) [![Circle CI](https://circleci.com/gh/diffplug/spotless/tree/main.svg?style=shield)](https://circleci.com/gh/diffplug/spotless/tree/main) [![Live chat](https://img.shields.io/badge/gitter-chat-brightgreen.svg)](https://gitter.im/diffplug/spotless) @@ -126,10 +126,10 @@ spotless { ``` Spotless consists of a list of formats (in the example above, `misc` and `java`), and each format has: -- a `target` (the files to format), which you set with [`target`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.7.0/com/diffplug/gradle/spotless/FormatExtension.html#target-java.lang.Object...-) and [`targetExclude`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.7.0/com/diffplug/gradle/spotless/FormatExtension.html#targetExclude-java.lang.Object...-) -- a list of `FormatterStep`, which are just `String -> String` functions, such as [`replace`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.7.0/com/diffplug/gradle/spotless/FormatExtension.html#replace-java.lang.String-java.lang.CharSequence-java.lang.CharSequence-), [`replaceRegex`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.7.0/com/diffplug/gradle/spotless/FormatExtension.html#replaceRegex-java.lang.String-java.lang.String-java.lang.String-), [`trimTrailingWhitespace`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.7.0/com/diffplug/gradle/spotless/FormatExtension.html#replace-java.lang.String-java.lang.CharSequence-java.lang.CharSequence-), [`custom`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.7.0/com/diffplug/gradle/spotless/FormatExtension.html#custom-java.lang.String-groovy.lang.Closure-), [`prettier`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.7.0/com/diffplug/gradle/spotless/FormatExtension.html#prettier--), [`eclipseWtp`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.7.0/com/diffplug/gradle/spotless/FormatExtension.html#eclipseWtp-com.diffplug.spotless.extra.wtp.EclipseWtpFormatterStep-), [`licenseHeader`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.7.0/com/diffplug/gradle/spotless/FormatExtension.html#licenseHeader-java.lang.String-java.lang.String-) etc. +- a `target` (the files to format), which you set with [`target`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.7.1/com/diffplug/gradle/spotless/FormatExtension.html#target-java.lang.Object...-) and [`targetExclude`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.7.1/com/diffplug/gradle/spotless/FormatExtension.html#targetExclude-java.lang.Object...-) +- a list of `FormatterStep`, which are just `String -> String` functions, such as [`replace`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.7.1/com/diffplug/gradle/spotless/FormatExtension.html#replace-java.lang.String-java.lang.CharSequence-java.lang.CharSequence-), [`replaceRegex`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.7.1/com/diffplug/gradle/spotless/FormatExtension.html#replaceRegex-java.lang.String-java.lang.String-java.lang.String-), [`trimTrailingWhitespace`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.7.1/com/diffplug/gradle/spotless/FormatExtension.html#replace-java.lang.String-java.lang.CharSequence-java.lang.CharSequence-), [`custom`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.7.1/com/diffplug/gradle/spotless/FormatExtension.html#custom-java.lang.String-groovy.lang.Closure-), [`prettier`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.7.1/com/diffplug/gradle/spotless/FormatExtension.html#prettier--), [`eclipseWtp`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.7.1/com/diffplug/gradle/spotless/FormatExtension.html#eclipseWtp-com.diffplug.spotless.extra.wtp.EclipseWtpFormatterStep-), [`licenseHeader`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.7.1/com/diffplug/gradle/spotless/FormatExtension.html#licenseHeader-java.lang.String-java.lang.String-) etc. -All the generic steps live in [`FormatExtension`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.7.0/com/diffplug/gradle/spotless/FormatExtension.html), and there are many language-specific steps which live in its language-specific subclasses, which are described below. +All the generic steps live in [`FormatExtension`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.7.1/com/diffplug/gradle/spotless/FormatExtension.html), and there are many language-specific steps which live in its language-specific subclasses, which are described below. ### Requirements @@ -141,7 +141,7 @@ If you're stuck on an older version of Gradle, `id 'com.diffplug.gradle.spotless ## Java -`com.diffplug.gradle.spotless.JavaExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.7.0/com/diffplug/gradle/spotless/JavaExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/JavaExtension.java) +`com.diffplug.gradle.spotless.JavaExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.7.1/com/diffplug/gradle/spotless/JavaExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/JavaExtension.java) ```gradle spotless { @@ -248,8 +248,8 @@ spotless { ## Groovy -- `com.diffplug.gradle.spotless.GroovyExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.7.0/com/diffplug/gradle/spotless/GroovyExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/GroovyExtension.java) -- `com.diffplug.gradle.spotless.GroovyGradleExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.7.0/com/diffplug/gradle/spotless/GroovyGradleExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/GroovyGradleExtension.java) +- `com.diffplug.gradle.spotless.GroovyExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.7.1/com/diffplug/gradle/spotless/GroovyExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/GroovyExtension.java) +- `com.diffplug.gradle.spotless.GroovyGradleExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.7.1/com/diffplug/gradle/spotless/GroovyGradleExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/GroovyGradleExtension.java) Configuration for Groovy is similar to [Java](#java), in that it also supports `licenseHeader` and `importOrder`. @@ -300,8 +300,8 @@ Groovy-Eclipse formatting errors/warnings lead per default to a build failure. T ## Kotlin -- `com.diffplug.gradle.spotless.KotlinExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.7.0/com/diffplug/gradle/spotless/KotlinExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/KotlinExtension.java) -- `com.diffplug.gradle.spotless.KotlinGradleExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.7.0/com/diffplug/gradle/spotless/KotlinGradleExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/KotlinGradleExtension.java) +- `com.diffplug.gradle.spotless.KotlinExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.7.1/com/diffplug/gradle/spotless/KotlinExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/KotlinExtension.java) +- `com.diffplug.gradle.spotless.KotlinGradleExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.7.1/com/diffplug/gradle/spotless/KotlinGradleExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/KotlinGradleExtension.java) ```gradle spotless { // if you are using build.gradle.kts, instead of 'spotless {' use: @@ -364,7 +364,7 @@ spotless { ## Scala -`com.diffplug.gradle.spotless.ScalaExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.7.0/com/diffplug/gradle/spotless/ScalaExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/ScalaExtension.java) +`com.diffplug.gradle.spotless.ScalaExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.7.1/com/diffplug/gradle/spotless/ScalaExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/ScalaExtension.java) ```gradle spotless { @@ -396,7 +396,7 @@ spotless { ## C/C++ -`com.diffplug.gradle.spotless.CppExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.7.0/com/diffplug/gradle/spotless/CppExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/CppExtension.java) +`com.diffplug.gradle.spotless.CppExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.7.1/com/diffplug/gradle/spotless/CppExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/CppExtension.java) ```gradle spotless { @@ -428,7 +428,7 @@ spotles { ## Python -`com.diffplug.gradle.spotless.PythonExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.7.0/com/diffplug/gradle/spotless/PythonExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/PythonExtension.java) +`com.diffplug.gradle.spotless.PythonExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.7.1/com/diffplug/gradle/spotless/PythonExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/PythonExtension.java) ```gradle spotless { @@ -462,7 +462,7 @@ black().pathToExe('C:/myuser/.pyenv/versions/3.8.0/scripts/black.exe') ## FreshMark -`com.diffplug.gradle.spotless.FreshMarkExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.7.0/com/diffplug/gradle/spotless/FreshMarkExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/FreshMarkExtension.java) +`com.diffplug.gradle.spotless.FreshMarkExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.7.1/com/diffplug/gradle/spotless/FreshMarkExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/FreshMarkExtension.java) [homepage](https://github.com/diffplug/freshmark). [changelog](https://github.com/diffplug/freshmark/blob/master/CHANGES.md). FreshMark lets you generate markdown in the comments of your markdown. This helps to keep badges and links up-to-date (see the source for this file), and can also be helpful for generating complex tables (see the source for [the parent readme](../README.md)). @@ -483,7 +483,7 @@ spotless { ## Antlr4 -`com.diffplug.gradle.spotless.Antlr4Extension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.7.0/com/diffplug/gradle/spotless/Antlr4Extension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/Antlr4Extension.java) +`com.diffplug.gradle.spotless.Antlr4Extension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.7.1/com/diffplug/gradle/spotless/Antlr4Extension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/Antlr4Extension.java) ```gradle spotless { @@ -508,7 +508,7 @@ antlr4formatter('1.2.1') // version is optional ## SQL -`com.diffplug.gradle.spotless.SqlExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.7.0/com/diffplug/gradle/spotless/SqlExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/SqlExtension.java) +`com.diffplug.gradle.spotless.SqlExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.7.1/com/diffplug/gradle/spotless/SqlExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/SqlExtension.java) ```gradle spotless { @@ -548,7 +548,7 @@ sql.formatter.indent.size=4 ## Typescript -- `com.diffplug.gradle.spotless.TypescriptExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.7.0/com/diffplug/gradle/spotless/TypescriptExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/TypescriptExtension.java) +- `com.diffplug.gradle.spotless.TypescriptExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.7.1/com/diffplug/gradle/spotless/TypescriptExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/TypescriptExtension.java) ```gradle spotless { @@ -591,7 +591,7 @@ For details, see the [npm detection](#npm-detection) and [`.npmrc` detection](#n ## JSON -- `com.diffplug.gradle.spotless.JsonExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.7.0/com/diffplug/gradle/spotless/JsonExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/JsonExtension.java) +- `com.diffplug.gradle.spotless.JsonExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.7.1/com/diffplug/gradle/spotless/JsonExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/JsonExtension.java) ```gradle spotless { @@ -816,7 +816,7 @@ Once a file's license header has a valid year, whether it is a year (`2020`) or * `2017` -> `2017-2020` * `2017-2019` -> `2017-2020` -See the [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.7.0/com/diffplug/gradle/spotless/FormatExtension.LicenseHeaderConfig.html) for a complete listing of options. +See the [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.7.1/com/diffplug/gradle/spotless/FormatExtension.LicenseHeaderConfig.html) for a complete listing of options. @@ -883,9 +883,9 @@ spotless { custom 'lowercase', { str -> str.toLowerCase() } ``` -However, custom rules will disable up-to-date checking and caching, unless you read [this javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.7.0/com/diffplug/gradle/spotless/FormatExtension.html#bumpThisNumberIfACustomStepChanges-int-) and follow its instructions carefully. +However, custom rules will disable up-to-date checking and caching, unless you read [this javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.7.1/com/diffplug/gradle/spotless/FormatExtension.html#bumpThisNumberIfACustomStepChanges-int-) and follow its instructions carefully. -Another option is to create proper `FormatterStep` in your `buildSrc`, and then call [`addStep`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.7.0/com/diffplug/gradle/spotless/FormatExtension.html#addStep-com.diffplug.spotless.FormatterStep-). The contributing guide describes [how to do this](https://github.com/diffplug/spotless/blob/main/CONTRIBUTING.md#how-to-add-a-new-formatterstep). If the step is generally-useful, we hope you'll open a PR to share it! +Another option is to create proper `FormatterStep` in your `buildSrc`, and then call [`addStep`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.7.1/com/diffplug/gradle/spotless/FormatExtension.html#addStep-com.diffplug.spotless.FormatterStep-). The contributing guide describes [how to do this](https://github.com/diffplug/spotless/blob/main/CONTRIBUTING.md#how-to-add-a-new-formatterstep). If the step is generally-useful, we hope you'll open a PR to share it! ```gradle @@ -918,11 +918,11 @@ spotless { format 'foo', com.acme.FooLanguageExtension, { ``` -If you'd like to create a one-off Spotless task outside of the `check`/`apply` framework, see [`FormatExtension.createIndependentApplyTask`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.7.0/com/diffplug/gradle/spotless/FormatExtension.html#createIndependentApplyTask-java.lang.String-). +If you'd like to create a one-off Spotless task outside of the `check`/`apply` framework, see [`FormatExtension.createIndependentApplyTask`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.7.1/com/diffplug/gradle/spotless/FormatExtension.html#createIndependentApplyTask-java.lang.String-). ## Inception (languages within languages within...) -In very rare cases, you might want to format e.g. javascript which is written inside JSP templates, or maybe java within a markdown file, or something wacky like that. You can specify hunks within a file using either open/close tags or a regex with a single capturing group, and then specify rules within it, like so. See [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.7.0/com/diffplug/gradle/spotless/FormatExtension.html#withinBlocks-java.lang.String-java.lang.String-java.lang.String-org.gradle.api.Action-) for more details. +In very rare cases, you might want to format e.g. javascript which is written inside JSP templates, or maybe java within a markdown file, or something wacky like that. You can specify hunks within a file using either open/close tags or a regex with a single capturing group, and then specify rules within it, like so. See [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.7.1/com/diffplug/gradle/spotless/FormatExtension.html#withinBlocks-java.lang.String-java.lang.String-java.lang.String-org.gradle.api.Action-) for more details. ```gradle import com.diffplug.gradle.spotless.JavaExtension From 000aab1ec90bbfc6363e15ba45b6beb702d8c18a Mon Sep 17 00:00:00 2001 From: circleci Date: Fri, 10 Jun 2022 17:52:36 +0000 Subject: [PATCH 155/757] Published maven/2.22.7 --- plugin-maven/CHANGES.md | 2 ++ plugin-maven/README.md | 4 ++-- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/plugin-maven/CHANGES.md b/plugin-maven/CHANGES.md index 2fa38baba8..0f32859cab 100644 --- a/plugin-maven/CHANGES.md +++ b/plugin-maven/CHANGES.md @@ -3,6 +3,8 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format (starting after version `1.27.0`). ## [Unreleased] + +## [2.22.7] - 2022-06-10 ### Fixed * (Second try) `googleJavaFormat` and `removeUnusedImports` works on JDK16+ without jvm args workaround. ([#1228](https://github.com/diffplug/spotless/pull/1228)) * If you have a bunch of `--add-exports` calls in `MAVEN_OPTS` or `.mvn/jvm.config`, you should be able to remove them. (fixes [#834](https://github.com/diffplug/spotless/issues/834#issuecomment-817524058)) diff --git a/plugin-maven/README.md b/plugin-maven/README.md index 50e0a5ed99..2795cc1629 100644 --- a/plugin-maven/README.md +++ b/plugin-maven/README.md @@ -12,8 +12,8 @@ output = [ ].join('\n'); --> [![Maven central](https://img.shields.io/badge/mavencentral-com.diffplug.spotless%3Aspotless--maven--plugin-blue.svg)](https://search.maven.org/#search%7Cgav%7C1%7Cg%3A%22com.diffplug.spotless%22%20AND%20a%3A%22spotless-maven-plugin%22) -[![Javadoc](https://img.shields.io/badge/javadoc-yes-blue.svg)](https://javadoc.io/doc/com.diffplug.spotless/spotless-maven-plugin/2.22.6/index.html) -[![Changelog](https://img.shields.io/badge/changelog-2.22.6-brightgreen.svg)](CHANGES.md) +[![Javadoc](https://img.shields.io/badge/javadoc-yes-blue.svg)](https://javadoc.io/doc/com.diffplug.spotless/spotless-maven-plugin/2.22.7/index.html) +[![Changelog](https://img.shields.io/badge/changelog-2.22.7-brightgreen.svg)](CHANGES.md) [![Circle CI](https://circleci.com/gh/diffplug/spotless/tree/main.svg?style=shield)](https://circleci.com/gh/diffplug/spotless/tree/main) [![Live chat](https://img.shields.io/badge/gitter-chat-brightgreen.svg)](https://gitter.im/diffplug/spotless) From be18ed0274766d4ca45de42eaec30384ceed8272 Mon Sep 17 00:00:00 2001 From: Ned Twigg Date: Sat, 11 Jun 2022 15:57:45 -0700 Subject: [PATCH 156/757] Apply the fix from #1224 to PalantirJavaFormatStep. --- .../java/com/diffplug/spotless/java/PalantirJavaFormatStep.java | 1 + 1 file changed, 1 insertion(+) diff --git a/lib/src/main/java/com/diffplug/spotless/java/PalantirJavaFormatStep.java b/lib/src/main/java/com/diffplug/spotless/java/PalantirJavaFormatStep.java index a5474d549b..89673787d6 100644 --- a/lib/src/main/java/com/diffplug/spotless/java/PalantirJavaFormatStep.java +++ b/lib/src/main/java/com/diffplug/spotless/java/PalantirJavaFormatStep.java @@ -60,6 +60,7 @@ private static final class State implements Serializable { private final String formatterVersion; State(JarState jarState, String formatterVersion) { + ModuleHelper.doOpenInternalPackagesIfRequired(); this.jarState = jarState; this.formatterVersion = formatterVersion; } From ba2c979bad568b4fc7e924472a9caf4cdd138ba5 Mon Sep 17 00:00:00 2001 From: Ned Twigg Date: Sat, 11 Jun 2022 16:01:28 -0700 Subject: [PATCH 157/757] Update changelogs. --- CHANGES.md | 2 ++ plugin-gradle/CHANGES.md | 2 ++ plugin-maven/CHANGES.md | 2 ++ 3 files changed, 6 insertions(+) diff --git a/CHANGES.md b/CHANGES.md index ea675ade27..03d5ceec2e 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -10,6 +10,8 @@ This document is intended for Spotless developers. We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format (starting after version `1.27.0`). ## [Unreleased] +### Fixed +* `PalantirJavaFormatStep` no longer needs the `--add-exports` calls in the `org.gradle.jvmargs` property in `gradle.properties`. ([#1233](https://github.com/diffplug/spotless/pull/1233)) ## [2.26.1] - 2022-06-10 ### Fixed diff --git a/plugin-gradle/CHANGES.md b/plugin-gradle/CHANGES.md index a13fedf837..890eb66e64 100644 --- a/plugin-gradle/CHANGES.md +++ b/plugin-gradle/CHANGES.md @@ -3,6 +3,8 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format (starting after version `3.27.0`). ## [Unreleased] +### Fixed +* `PalantirJavaFormatStep` no longer needs the `--add-exports` calls in the `org.gradle.jvmargs` property in `gradle.properties`. ([#1233](https://github.com/diffplug/spotless/pull/1233)) ## [6.7.1] - 2022-06-10 ### Fixed diff --git a/plugin-maven/CHANGES.md b/plugin-maven/CHANGES.md index 0f32859cab..7583181456 100644 --- a/plugin-maven/CHANGES.md +++ b/plugin-maven/CHANGES.md @@ -3,6 +3,8 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format (starting after version `1.27.0`). ## [Unreleased] +### Fixed +* `PalantirJavaFormatStep` no longer needs the `--add-exports` calls in `MAVEN_OPTS` or `.mvn/jvm.config`. ([#1233](https://github.com/diffplug/spotless/pull/1233)) ## [2.22.7] - 2022-06-10 ### Fixed From b737f4c9b044a898ebeb93556c6c649019c7ccd4 Mon Sep 17 00:00:00 2001 From: circleci Date: Sat, 11 Jun 2022 23:50:10 +0000 Subject: [PATCH 158/757] Published lib/2.26.2 --- CHANGES.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/CHANGES.md b/CHANGES.md index 03d5ceec2e..3803d08fd9 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -10,6 +10,8 @@ This document is intended for Spotless developers. We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format (starting after version `1.27.0`). ## [Unreleased] + +## [2.26.2] - 2022-06-11 ### Fixed * `PalantirJavaFormatStep` no longer needs the `--add-exports` calls in the `org.gradle.jvmargs` property in `gradle.properties`. ([#1233](https://github.com/diffplug/spotless/pull/1233)) From 56912f5983c33d1803d56162d211a699fc2d5f00 Mon Sep 17 00:00:00 2001 From: circleci Date: Sat, 11 Jun 2022 23:51:09 +0000 Subject: [PATCH 159/757] Published gradle/6.7.2 --- plugin-gradle/CHANGES.md | 2 ++ plugin-gradle/README.md | 46 ++++++++++++++++++++-------------------- 2 files changed, 25 insertions(+), 23 deletions(-) diff --git a/plugin-gradle/CHANGES.md b/plugin-gradle/CHANGES.md index 890eb66e64..6eac3102e0 100644 --- a/plugin-gradle/CHANGES.md +++ b/plugin-gradle/CHANGES.md @@ -3,6 +3,8 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format (starting after version `3.27.0`). ## [Unreleased] + +## [6.7.2] - 2022-06-11 ### Fixed * `PalantirJavaFormatStep` no longer needs the `--add-exports` calls in the `org.gradle.jvmargs` property in `gradle.properties`. ([#1233](https://github.com/diffplug/spotless/pull/1233)) diff --git a/plugin-gradle/README.md b/plugin-gradle/README.md index 291d0cf027..99d86026d6 100644 --- a/plugin-gradle/README.md +++ b/plugin-gradle/README.md @@ -18,9 +18,9 @@ output = [ --> [![Gradle plugin](https://img.shields.io/badge/plugins.gradle.org-com.diffplug.spotless-blue.svg)](https://plugins.gradle.org/plugin/com.diffplug.spotless) [![Maven central](https://img.shields.io/badge/mavencentral-yes-blue.svg)](https://search.maven.org/#search%7Cgav%7C1%7Cg%3A%22com.diffplug.spotless%22%20AND%20a%3A%22spotless-plugin-gradle%22) -[![Javadoc](https://img.shields.io/badge/javadoc-yes-blue.svg)](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.7.1/index.html) +[![Javadoc](https://img.shields.io/badge/javadoc-yes-blue.svg)](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.7.2/index.html) [![License Apache](https://img.shields.io/badge/license-apache-blue.svg)](https://tldrlegal.com/license/apache-license-2.0-(apache-2.0)) -[![Changelog](https://img.shields.io/badge/changelog-6.7.1-blue.svg)](CHANGES.md) +[![Changelog](https://img.shields.io/badge/changelog-6.7.2-blue.svg)](CHANGES.md) [![Circle CI](https://circleci.com/gh/diffplug/spotless/tree/main.svg?style=shield)](https://circleci.com/gh/diffplug/spotless/tree/main) [![Live chat](https://img.shields.io/badge/gitter-chat-brightgreen.svg)](https://gitter.im/diffplug/spotless) @@ -126,10 +126,10 @@ spotless { ``` Spotless consists of a list of formats (in the example above, `misc` and `java`), and each format has: -- a `target` (the files to format), which you set with [`target`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.7.1/com/diffplug/gradle/spotless/FormatExtension.html#target-java.lang.Object...-) and [`targetExclude`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.7.1/com/diffplug/gradle/spotless/FormatExtension.html#targetExclude-java.lang.Object...-) -- a list of `FormatterStep`, which are just `String -> String` functions, such as [`replace`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.7.1/com/diffplug/gradle/spotless/FormatExtension.html#replace-java.lang.String-java.lang.CharSequence-java.lang.CharSequence-), [`replaceRegex`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.7.1/com/diffplug/gradle/spotless/FormatExtension.html#replaceRegex-java.lang.String-java.lang.String-java.lang.String-), [`trimTrailingWhitespace`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.7.1/com/diffplug/gradle/spotless/FormatExtension.html#replace-java.lang.String-java.lang.CharSequence-java.lang.CharSequence-), [`custom`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.7.1/com/diffplug/gradle/spotless/FormatExtension.html#custom-java.lang.String-groovy.lang.Closure-), [`prettier`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.7.1/com/diffplug/gradle/spotless/FormatExtension.html#prettier--), [`eclipseWtp`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.7.1/com/diffplug/gradle/spotless/FormatExtension.html#eclipseWtp-com.diffplug.spotless.extra.wtp.EclipseWtpFormatterStep-), [`licenseHeader`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.7.1/com/diffplug/gradle/spotless/FormatExtension.html#licenseHeader-java.lang.String-java.lang.String-) etc. +- a `target` (the files to format), which you set with [`target`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.7.2/com/diffplug/gradle/spotless/FormatExtension.html#target-java.lang.Object...-) and [`targetExclude`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.7.2/com/diffplug/gradle/spotless/FormatExtension.html#targetExclude-java.lang.Object...-) +- a list of `FormatterStep`, which are just `String -> String` functions, such as [`replace`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.7.2/com/diffplug/gradle/spotless/FormatExtension.html#replace-java.lang.String-java.lang.CharSequence-java.lang.CharSequence-), [`replaceRegex`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.7.2/com/diffplug/gradle/spotless/FormatExtension.html#replaceRegex-java.lang.String-java.lang.String-java.lang.String-), [`trimTrailingWhitespace`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.7.2/com/diffplug/gradle/spotless/FormatExtension.html#replace-java.lang.String-java.lang.CharSequence-java.lang.CharSequence-), [`custom`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.7.2/com/diffplug/gradle/spotless/FormatExtension.html#custom-java.lang.String-groovy.lang.Closure-), [`prettier`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.7.2/com/diffplug/gradle/spotless/FormatExtension.html#prettier--), [`eclipseWtp`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.7.2/com/diffplug/gradle/spotless/FormatExtension.html#eclipseWtp-com.diffplug.spotless.extra.wtp.EclipseWtpFormatterStep-), [`licenseHeader`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.7.2/com/diffplug/gradle/spotless/FormatExtension.html#licenseHeader-java.lang.String-java.lang.String-) etc. -All the generic steps live in [`FormatExtension`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.7.1/com/diffplug/gradle/spotless/FormatExtension.html), and there are many language-specific steps which live in its language-specific subclasses, which are described below. +All the generic steps live in [`FormatExtension`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.7.2/com/diffplug/gradle/spotless/FormatExtension.html), and there are many language-specific steps which live in its language-specific subclasses, which are described below. ### Requirements @@ -141,7 +141,7 @@ If you're stuck on an older version of Gradle, `id 'com.diffplug.gradle.spotless ## Java -`com.diffplug.gradle.spotless.JavaExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.7.1/com/diffplug/gradle/spotless/JavaExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/JavaExtension.java) +`com.diffplug.gradle.spotless.JavaExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.7.2/com/diffplug/gradle/spotless/JavaExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/JavaExtension.java) ```gradle spotless { @@ -248,8 +248,8 @@ spotless { ## Groovy -- `com.diffplug.gradle.spotless.GroovyExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.7.1/com/diffplug/gradle/spotless/GroovyExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/GroovyExtension.java) -- `com.diffplug.gradle.spotless.GroovyGradleExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.7.1/com/diffplug/gradle/spotless/GroovyGradleExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/GroovyGradleExtension.java) +- `com.diffplug.gradle.spotless.GroovyExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.7.2/com/diffplug/gradle/spotless/GroovyExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/GroovyExtension.java) +- `com.diffplug.gradle.spotless.GroovyGradleExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.7.2/com/diffplug/gradle/spotless/GroovyGradleExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/GroovyGradleExtension.java) Configuration for Groovy is similar to [Java](#java), in that it also supports `licenseHeader` and `importOrder`. @@ -300,8 +300,8 @@ Groovy-Eclipse formatting errors/warnings lead per default to a build failure. T ## Kotlin -- `com.diffplug.gradle.spotless.KotlinExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.7.1/com/diffplug/gradle/spotless/KotlinExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/KotlinExtension.java) -- `com.diffplug.gradle.spotless.KotlinGradleExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.7.1/com/diffplug/gradle/spotless/KotlinGradleExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/KotlinGradleExtension.java) +- `com.diffplug.gradle.spotless.KotlinExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.7.2/com/diffplug/gradle/spotless/KotlinExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/KotlinExtension.java) +- `com.diffplug.gradle.spotless.KotlinGradleExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.7.2/com/diffplug/gradle/spotless/KotlinGradleExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/KotlinGradleExtension.java) ```gradle spotless { // if you are using build.gradle.kts, instead of 'spotless {' use: @@ -364,7 +364,7 @@ spotless { ## Scala -`com.diffplug.gradle.spotless.ScalaExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.7.1/com/diffplug/gradle/spotless/ScalaExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/ScalaExtension.java) +`com.diffplug.gradle.spotless.ScalaExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.7.2/com/diffplug/gradle/spotless/ScalaExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/ScalaExtension.java) ```gradle spotless { @@ -396,7 +396,7 @@ spotless { ## C/C++ -`com.diffplug.gradle.spotless.CppExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.7.1/com/diffplug/gradle/spotless/CppExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/CppExtension.java) +`com.diffplug.gradle.spotless.CppExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.7.2/com/diffplug/gradle/spotless/CppExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/CppExtension.java) ```gradle spotless { @@ -428,7 +428,7 @@ spotles { ## Python -`com.diffplug.gradle.spotless.PythonExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.7.1/com/diffplug/gradle/spotless/PythonExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/PythonExtension.java) +`com.diffplug.gradle.spotless.PythonExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.7.2/com/diffplug/gradle/spotless/PythonExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/PythonExtension.java) ```gradle spotless { @@ -462,7 +462,7 @@ black().pathToExe('C:/myuser/.pyenv/versions/3.8.0/scripts/black.exe') ## FreshMark -`com.diffplug.gradle.spotless.FreshMarkExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.7.1/com/diffplug/gradle/spotless/FreshMarkExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/FreshMarkExtension.java) +`com.diffplug.gradle.spotless.FreshMarkExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.7.2/com/diffplug/gradle/spotless/FreshMarkExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/FreshMarkExtension.java) [homepage](https://github.com/diffplug/freshmark). [changelog](https://github.com/diffplug/freshmark/blob/master/CHANGES.md). FreshMark lets you generate markdown in the comments of your markdown. This helps to keep badges and links up-to-date (see the source for this file), and can also be helpful for generating complex tables (see the source for [the parent readme](../README.md)). @@ -483,7 +483,7 @@ spotless { ## Antlr4 -`com.diffplug.gradle.spotless.Antlr4Extension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.7.1/com/diffplug/gradle/spotless/Antlr4Extension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/Antlr4Extension.java) +`com.diffplug.gradle.spotless.Antlr4Extension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.7.2/com/diffplug/gradle/spotless/Antlr4Extension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/Antlr4Extension.java) ```gradle spotless { @@ -508,7 +508,7 @@ antlr4formatter('1.2.1') // version is optional ## SQL -`com.diffplug.gradle.spotless.SqlExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.7.1/com/diffplug/gradle/spotless/SqlExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/SqlExtension.java) +`com.diffplug.gradle.spotless.SqlExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.7.2/com/diffplug/gradle/spotless/SqlExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/SqlExtension.java) ```gradle spotless { @@ -548,7 +548,7 @@ sql.formatter.indent.size=4 ## Typescript -- `com.diffplug.gradle.spotless.TypescriptExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.7.1/com/diffplug/gradle/spotless/TypescriptExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/TypescriptExtension.java) +- `com.diffplug.gradle.spotless.TypescriptExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.7.2/com/diffplug/gradle/spotless/TypescriptExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/TypescriptExtension.java) ```gradle spotless { @@ -591,7 +591,7 @@ For details, see the [npm detection](#npm-detection) and [`.npmrc` detection](#n ## JSON -- `com.diffplug.gradle.spotless.JsonExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.7.1/com/diffplug/gradle/spotless/JsonExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/JsonExtension.java) +- `com.diffplug.gradle.spotless.JsonExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.7.2/com/diffplug/gradle/spotless/JsonExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/JsonExtension.java) ```gradle spotless { @@ -816,7 +816,7 @@ Once a file's license header has a valid year, whether it is a year (`2020`) or * `2017` -> `2017-2020` * `2017-2019` -> `2017-2020` -See the [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.7.1/com/diffplug/gradle/spotless/FormatExtension.LicenseHeaderConfig.html) for a complete listing of options. +See the [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.7.2/com/diffplug/gradle/spotless/FormatExtension.LicenseHeaderConfig.html) for a complete listing of options. @@ -883,9 +883,9 @@ spotless { custom 'lowercase', { str -> str.toLowerCase() } ``` -However, custom rules will disable up-to-date checking and caching, unless you read [this javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.7.1/com/diffplug/gradle/spotless/FormatExtension.html#bumpThisNumberIfACustomStepChanges-int-) and follow its instructions carefully. +However, custom rules will disable up-to-date checking and caching, unless you read [this javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.7.2/com/diffplug/gradle/spotless/FormatExtension.html#bumpThisNumberIfACustomStepChanges-int-) and follow its instructions carefully. -Another option is to create proper `FormatterStep` in your `buildSrc`, and then call [`addStep`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.7.1/com/diffplug/gradle/spotless/FormatExtension.html#addStep-com.diffplug.spotless.FormatterStep-). The contributing guide describes [how to do this](https://github.com/diffplug/spotless/blob/main/CONTRIBUTING.md#how-to-add-a-new-formatterstep). If the step is generally-useful, we hope you'll open a PR to share it! +Another option is to create proper `FormatterStep` in your `buildSrc`, and then call [`addStep`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.7.2/com/diffplug/gradle/spotless/FormatExtension.html#addStep-com.diffplug.spotless.FormatterStep-). The contributing guide describes [how to do this](https://github.com/diffplug/spotless/blob/main/CONTRIBUTING.md#how-to-add-a-new-formatterstep). If the step is generally-useful, we hope you'll open a PR to share it! ```gradle @@ -918,11 +918,11 @@ spotless { format 'foo', com.acme.FooLanguageExtension, { ``` -If you'd like to create a one-off Spotless task outside of the `check`/`apply` framework, see [`FormatExtension.createIndependentApplyTask`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.7.1/com/diffplug/gradle/spotless/FormatExtension.html#createIndependentApplyTask-java.lang.String-). +If you'd like to create a one-off Spotless task outside of the `check`/`apply` framework, see [`FormatExtension.createIndependentApplyTask`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.7.2/com/diffplug/gradle/spotless/FormatExtension.html#createIndependentApplyTask-java.lang.String-). ## Inception (languages within languages within...) -In very rare cases, you might want to format e.g. javascript which is written inside JSP templates, or maybe java within a markdown file, or something wacky like that. You can specify hunks within a file using either open/close tags or a regex with a single capturing group, and then specify rules within it, like so. See [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.7.1/com/diffplug/gradle/spotless/FormatExtension.html#withinBlocks-java.lang.String-java.lang.String-java.lang.String-org.gradle.api.Action-) for more details. +In very rare cases, you might want to format e.g. javascript which is written inside JSP templates, or maybe java within a markdown file, or something wacky like that. You can specify hunks within a file using either open/close tags or a regex with a single capturing group, and then specify rules within it, like so. See [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.7.2/com/diffplug/gradle/spotless/FormatExtension.html#withinBlocks-java.lang.String-java.lang.String-java.lang.String-org.gradle.api.Action-) for more details. ```gradle import com.diffplug.gradle.spotless.JavaExtension From 97784730e21574b859f013ba00825502ce040929 Mon Sep 17 00:00:00 2001 From: circleci Date: Sat, 11 Jun 2022 23:52:42 +0000 Subject: [PATCH 160/757] Published maven/2.22.8 --- plugin-maven/CHANGES.md | 2 ++ plugin-maven/README.md | 4 ++-- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/plugin-maven/CHANGES.md b/plugin-maven/CHANGES.md index 7583181456..672dfb1150 100644 --- a/plugin-maven/CHANGES.md +++ b/plugin-maven/CHANGES.md @@ -3,6 +3,8 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format (starting after version `1.27.0`). ## [Unreleased] + +## [2.22.8] - 2022-06-11 ### Fixed * `PalantirJavaFormatStep` no longer needs the `--add-exports` calls in `MAVEN_OPTS` or `.mvn/jvm.config`. ([#1233](https://github.com/diffplug/spotless/pull/1233)) diff --git a/plugin-maven/README.md b/plugin-maven/README.md index 2795cc1629..e6b9ee8e29 100644 --- a/plugin-maven/README.md +++ b/plugin-maven/README.md @@ -12,8 +12,8 @@ output = [ ].join('\n'); --> [![Maven central](https://img.shields.io/badge/mavencentral-com.diffplug.spotless%3Aspotless--maven--plugin-blue.svg)](https://search.maven.org/#search%7Cgav%7C1%7Cg%3A%22com.diffplug.spotless%22%20AND%20a%3A%22spotless-maven-plugin%22) -[![Javadoc](https://img.shields.io/badge/javadoc-yes-blue.svg)](https://javadoc.io/doc/com.diffplug.spotless/spotless-maven-plugin/2.22.7/index.html) -[![Changelog](https://img.shields.io/badge/changelog-2.22.7-brightgreen.svg)](CHANGES.md) +[![Javadoc](https://img.shields.io/badge/javadoc-yes-blue.svg)](https://javadoc.io/doc/com.diffplug.spotless/spotless-maven-plugin/2.22.8/index.html) +[![Changelog](https://img.shields.io/badge/changelog-2.22.8-brightgreen.svg)](CHANGES.md) [![Circle CI](https://circleci.com/gh/diffplug/spotless/tree/main.svg?style=shield)](https://circleci.com/gh/diffplug/spotless/tree/main) [![Live chat](https://img.shields.io/badge/gitter-chat-brightgreen.svg)](https://gitter.im/diffplug/spotless) From e19c3ad4a79d458c5520005bb785524de3356722 Mon Sep 17 00:00:00 2001 From: Iurii Ignatko Date: Mon, 13 Jun 2022 15:44:15 +0300 Subject: [PATCH 161/757] Specify additional task outputs --- gradle/java-setup.gradle | 10 +++++++++- plugin-maven/build.gradle | 15 ++++++++------- 2 files changed, 17 insertions(+), 8 deletions(-) diff --git a/gradle/java-setup.gradle b/gradle/java-setup.gradle index 5d9d756414..707584bccf 100644 --- a/gradle/java-setup.gradle +++ b/gradle/java-setup.gradle @@ -17,7 +17,6 @@ apply plugin: 'com.github.spotbugs' spotbugs { toolVersion = VER_SPOTBUGS ignoreFailures = false // bug free or it doesn't ship! - reportsDir = file('build/spotbugs') reportLevel = 'medium' // low|medium|high (low = sensitive to even minor mistakes) omitVisitors = [ 'FindReturnRef'] // https://spotbugs.readthedocs.io/en/latest/detectors.html#findreturnref @@ -25,6 +24,15 @@ spotbugs { tasks.named('spotbugsTest') { enabled = false } + +tasks.withType(com.github.spotbugs.snom.SpotBugsTask).configureEach { + outputs.file("$buildDir/reports/spotbugs/${it.name}.html") + outputs.file("$buildDir/spotbugs/auxclasspath/${it.name}") + reports { + html.enabled = true + } +} + tasks.named('spotbugsMain') { // only run on Java 8 (no benefit to running twice) enabled = org.gradle.api.JavaVersion.current() == org.gradle.api.JavaVersion.VERSION_11 diff --git a/plugin-maven/build.gradle b/plugin-maven/build.gradle index 0905f58c24..d3da756bcc 100644 --- a/plugin-maven/build.gradle +++ b/plugin-maven/build.gradle @@ -27,7 +27,7 @@ import java.nio.file.Files import java.nio.file.Paths import static java.nio.charset.StandardCharsets.UTF_8 -import static java.nio.file.StandardOpenOption.CREATE_NEW +import static java.nio.file.StandardOpenOption.CREATE import static java.nio.file.StandardOpenOption.TRUNCATE_EXISTING ext.artifactId = project.artifactIdMaven @@ -91,9 +91,7 @@ dependencies { testImplementation "org.apache.maven:maven-core:${VER_MAVEN_API}" } -task cleanMavenProjectDir(type: Delete) { delete MAVEN_PROJECT_DIR } - -task copySourceFiles(type: Sync, dependsOn: cleanMavenProjectDir) { +task copySourceFiles(type: Sync) { from "src/main/java" into "${MAVEN_PROJECT_DIR}/src/main/java" } @@ -137,6 +135,9 @@ libs.each { } task createPomXml(dependsOn: installLocalDependencies) { + def newPomXml = Paths.get(MAVEN_PROJECT_DIR, "pom.xml") + + outputs.file(newPomXml) doLast { def additionalDependencies = project.configurations.runtimeClasspath.resolvedConfiguration.resolvedArtifacts.findAll { return !libs.contains(it.moduleVersion.id.name) @@ -158,10 +159,9 @@ task createPomXml(dependsOn: installLocalDependencies) { ] def pomXmlTemplate = Paths.get(PROJECT_DIR, "src/test/resources/pom-build.xml.mustache") - def newPomXml = Paths.get(MAVEN_PROJECT_DIR, "pom.xml") Files.newBufferedReader(pomXmlTemplate).withCloseable { reader -> - Files.newBufferedWriter(newPomXml, UTF_8, CREATE_NEW, TRUNCATE_EXISTING).withCloseable { writer -> + Files.newBufferedWriter(newPomXml, UTF_8, CREATE, TRUNCATE_EXISTING).withCloseable { writer -> def mustache = new DefaultMustacheFactory().compile(reader, "pom") mustache.execute(writer, versions) } @@ -170,11 +170,12 @@ task createPomXml(dependsOn: installLocalDependencies) { } task runMavenBuild(type: Exec, dependsOn: [ - cleanMavenProjectDir, copySourceFiles, copyMvnw, createPomXml ]) { + outputs.dir(LOCAL_MAVEN_REPO_DIR) + workingDir MAVEN_PROJECT_DIR // -B batch mode to make dependency download logging less verbose commandLine mvnw("clean install -B -Dmaven.repo.local=${LOCAL_MAVEN_REPO_DIR}") From 9940d740802f62554e1b4032b404210bd41a1356 Mon Sep 17 00:00:00 2001 From: Iurii Ignatko Date: Tue, 14 Jun 2022 16:31:21 +0300 Subject: [PATCH 162/757] Use project.layout instead of buildDir and static strings --- gradle/java-setup.gradle | 4 ++-- plugin-maven/build.gradle | 19 ++++++++----------- 2 files changed, 10 insertions(+), 13 deletions(-) diff --git a/gradle/java-setup.gradle b/gradle/java-setup.gradle index 707584bccf..9c9f394405 100644 --- a/gradle/java-setup.gradle +++ b/gradle/java-setup.gradle @@ -26,8 +26,8 @@ tasks.named('spotbugsTest') { } tasks.withType(com.github.spotbugs.snom.SpotBugsTask).configureEach { - outputs.file("$buildDir/reports/spotbugs/${it.name}.html") - outputs.file("$buildDir/spotbugs/auxclasspath/${it.name}") + outputs.file(project.layout.buildDirectory.file("reports/spotbugs/${it.name}.html")) + outputs.file(project.layout.buildDirectory.file("spotbugs/auxclasspath/${it.name}")) reports { html.enabled = true } diff --git a/plugin-maven/build.gradle b/plugin-maven/build.gradle index d3da756bcc..174f10ef6a 100644 --- a/plugin-maven/build.gradle +++ b/plugin-maven/build.gradle @@ -24,7 +24,6 @@ visteg { import com.github.mustachejava.DefaultMustacheFactory import java.nio.file.Files -import java.nio.file.Paths import static java.nio.charset.StandardCharsets.UTF_8 import static java.nio.file.StandardOpenOption.CREATE @@ -35,10 +34,8 @@ version = spotlessChangelog.versionNext apply from: rootProject.file("gradle/java-setup.gradle") apply from: rootProject.file("gradle/java-publish.gradle") -final PROJECT_DIR = project.projectDir.toString() -final BUILD_DIR = project.buildDir.toString() -final MAVEN_PROJECT_DIR = "${BUILD_DIR}/mavenProject" -final LOCAL_MAVEN_REPO_DIR = "${BUILD_DIR}/localMavenRepository" +final MAVEN_PROJECT_DIR = project.layout.buildDirectory.dir("mavenProject").get() +final LOCAL_MAVEN_REPO_DIR = project.layout.buildDirectory.dir("localMavenRepository").get() def mvnw(String args) { boolean isWin = System.getProperty('os.name').toLowerCase().contains('win') @@ -93,7 +90,7 @@ dependencies { task copySourceFiles(type: Sync) { from "src/main/java" - into "${MAVEN_PROJECT_DIR}/src/main/java" + into MAVEN_PROJECT_DIR.dir("src/main/java") } task copyMvnw(type: Copy, dependsOn: copySourceFiles) { @@ -120,7 +117,7 @@ libs.each { workingDir MAVEN_PROJECT_DIR inputs.file(file) - outputs.dir(project.file("${LOCAL_MAVEN_REPO_DIR}/${groupId.replace('.', '/')}/${artifactId}/${version}")) + outputs.dir(LOCAL_MAVEN_REPO_DIR.file(groupId.replace('.', '/') + "/" + artifactId + "/" + version)) commandLine mvnw("org.apache.maven.plugins:maven-install-plugin:2.3.1:install-file " + "-Dfile=${file} " + "-DgroupId=${groupId} " + @@ -135,7 +132,7 @@ libs.each { } task createPomXml(dependsOn: installLocalDependencies) { - def newPomXml = Paths.get(MAVEN_PROJECT_DIR, "pom.xml") + def newPomXml = MAVEN_PROJECT_DIR.file("pom.xml").asFile.toPath() outputs.file(newPomXml) doLast { @@ -158,7 +155,7 @@ task createPomXml(dependsOn: installLocalDependencies) { additionalDependencies : additionalDependencies ] - def pomXmlTemplate = Paths.get(PROJECT_DIR, "src/test/resources/pom-build.xml.mustache") + def pomXmlTemplate = project.layout.projectDirectory.file("src/test/resources/pom-build.xml.mustache").asFile.toPath() Files.newBufferedReader(pomXmlTemplate).withCloseable { reader -> Files.newBufferedWriter(newPomXml, UTF_8, CREATE, TRUNCATE_EXISTING).withCloseable { writer -> @@ -183,7 +180,7 @@ task runMavenBuild(type: Exec, dependsOn: [ jar.setActions Arrays.asList() jar.dependsOn(runMavenBuild) -File jarIn = file("${MAVEN_PROJECT_DIR}/target/spotless-maven-plugin-${version}.jar") +File jarIn = MAVEN_PROJECT_DIR.file("target/spotless-maven-plugin-${version}.jar").asFile File jarOut = jar.archivePath jar.inputs.file(jarIn) jar.outputs.file(jarOut) @@ -196,7 +193,7 @@ test { useJUnitPlatform() } apply from: rootProject.file('gradle/special-tests.gradle') tasks.withType(Test) { - systemProperty "localMavenRepositoryDir", LOCAL_MAVEN_REPO_DIR + systemProperty "localMavenRepositoryDir", LOCAL_MAVEN_REPO_DIR.asFile systemProperty "spotlessMavenPluginVersion", project.version dependsOn(jar) } From 57dad351859909dba226c51eb06292b308360468 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Tue, 14 Jun 2022 23:38:46 +0000 Subject: [PATCH 163/757] Bump com.github.spotbugs from 5.0.7 to 5.0.8 Bumps com.github.spotbugs from 5.0.7 to 5.0.8. --- updated-dependencies: - dependency-name: com.github.spotbugs dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] --- settings.gradle | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/settings.gradle b/settings.gradle index 83a40d3061..13792d7260 100644 --- a/settings.gradle +++ b/settings.gradle @@ -6,7 +6,7 @@ pluginManagement { // https://github.com/gradle-nexus/publish-plugin/releases id 'io.github.gradle-nexus.publish-plugin' version '1.1.0' // https://github.com/spotbugs/spotbugs-gradle-plugin/releases - id 'com.github.spotbugs' version '5.0.7' + id 'com.github.spotbugs' version '5.0.8' // https://github.com/diffplug/spotless-changelog id 'com.diffplug.spotless-changelog' version '2.3.2' // https://github.com/diffplug/goomph/blob/main/CHANGES.md From 34c5fe7192b34da4b24718235e296d6807728054 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=8C=83=E4=BF=8A=E7=BF=94?= Date: Mon, 20 Jun 2022 10:13:16 +0800 Subject: [PATCH 164/757] add support for MAC_CLASSIC (\r only) --- .../com/diffplug/spotless/LineEnding.java | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/lib/src/main/java/com/diffplug/spotless/LineEnding.java b/lib/src/main/java/com/diffplug/spotless/LineEnding.java index 6ea5372807..4dd4344835 100644 --- a/lib/src/main/java/com/diffplug/spotless/LineEnding.java +++ b/lib/src/main/java/com/diffplug/spotless/LineEnding.java @@ -41,8 +41,10 @@ public Policy createPolicy() { PLATFORM_NATIVE, /** {@code \r\n} */ WINDOWS, - /** {@code \n} */ - UNIX; + /** {@code \n} */ + UNIX, + /** {@code \r} */ + MAC_CLASSIC; // @formatter:on /** Returns a {@link Policy} appropriate for files which are contained within the given rootFolder. */ @@ -75,6 +77,7 @@ public Policy createPolicy() { case PLATFORM_NATIVE: return _platformNativePolicy; case WINDOWS: return WINDOWS_POLICY; case UNIX: return UNIX_POLICY; + case MAC_CLASSIC: return MAC_CLASSIC_POLICY; default: throw new UnsupportedOperationException(this + " is a path-specific line ending."); } } @@ -96,6 +99,7 @@ public String getEndingFor(File file) { private static final Policy WINDOWS_POLICY = new ConstantLineEndingPolicy(WINDOWS.str()); 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 String _platformNative = System.getProperty("line.separator"); private static final Policy _platformNativePolicy = new ConstantLineEndingPolicy(_platformNative); private static final boolean nativeIsWin = _platformNative.equals(WINDOWS.str()); @@ -117,6 +121,7 @@ public String str() { case PLATFORM_NATIVE: return _platformNative; case WINDOWS: return "\r\n"; case UNIX: return "\n"; + case MAC_CLASSIC: return "\r"; default: throw new UnsupportedOperationException(this + " is a path-specific line ending."); } } @@ -137,12 +142,14 @@ public default boolean isUnix(File file) { /** Returns a string with exclusively unix line endings. */ public static String toUnix(String input) { - int firstNewline = input.lastIndexOf('\n'); - if (firstNewline == -1) { + if (input.lastIndexOf(WINDOWS.str()) > -1) { + return input.replace("\r", ""); + } else if (input.lastIndexOf(MAC_CLASSIC.str()) > -1) { + // replace mac classic '\r' with unix line endings '\n' + return input.replace(MAC_CLASSIC.str(), UNIX.str()); + } else { // fastest way to detect if a string is already unix-only return input; - } else { - return input.replace("\r", ""); } } } From 1cd8553e37f3d9fad546683ca71a04f0826d5b8c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=8C=83=E4=BF=8A=E7=BF=94?= Date: Tue, 21 Jun 2022 14:51:30 +0800 Subject: [PATCH 165/757] apply code style --- lib/src/main/java/com/diffplug/spotless/LineEnding.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/src/main/java/com/diffplug/spotless/LineEnding.java b/lib/src/main/java/com/diffplug/spotless/LineEnding.java index 4dd4344835..c5c5c45125 100644 --- a/lib/src/main/java/com/diffplug/spotless/LineEnding.java +++ b/lib/src/main/java/com/diffplug/spotless/LineEnding.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. From 585d0a524acd6580dd04961255838a856e40329f Mon Sep 17 00:00:00 2001 From: Ned Twigg Date: Fri, 24 Jun 2022 21:53:47 -0700 Subject: [PATCH 166/757] Speedup LineEnding.toUnix, and add a test. --- .../java/com/diffplug/spotless/LineEnding.java | 17 ++++++++++------- .../com/diffplug/spotless/FormatterTest.java | 10 +++++++++- 2 files changed, 19 insertions(+), 8 deletions(-) diff --git a/lib/src/main/java/com/diffplug/spotless/LineEnding.java b/lib/src/main/java/com/diffplug/spotless/LineEnding.java index c5c5c45125..72b2532f2a 100644 --- a/lib/src/main/java/com/diffplug/spotless/LineEnding.java +++ b/lib/src/main/java/com/diffplug/spotless/LineEnding.java @@ -142,14 +142,17 @@ public default boolean isUnix(File file) { /** Returns a string with exclusively unix line endings. */ public static String toUnix(String input) { - if (input.lastIndexOf(WINDOWS.str()) > -1) { - return input.replace("\r", ""); - } else if (input.lastIndexOf(MAC_CLASSIC.str()) > -1) { - // replace mac classic '\r' with unix line endings '\n' - return input.replace(MAC_CLASSIC.str(), UNIX.str()); - } else { - // fastest way to detect if a string is already unix-only + int lastCarriageReturn = input.lastIndexOf('\r'); + if (lastCarriageReturn == -1) { return input; + } else { + if (input.lastIndexOf("\r\n") == -1) { + // it is MAC_CLASSIC \r + return input.replace('\r', '\n'); + } else { + // it is WINDOWS \r\n + return input.replace("\r", ""); + } } } } diff --git a/testlib/src/test/java/com/diffplug/spotless/FormatterTest.java b/testlib/src/test/java/com/diffplug/spotless/FormatterTest.java index fc56332b2b..06b8e64d31 100644 --- a/testlib/src/test/java/com/diffplug/spotless/FormatterTest.java +++ b/testlib/src/test/java/com/diffplug/spotless/FormatterTest.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. @@ -22,12 +22,20 @@ import java.util.ArrayList; import java.util.List; +import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Test; import com.diffplug.common.base.StandardSystemProperty; import com.diffplug.spotless.generic.EndWithNewlineStep; class FormatterTest { + @Test + void toUnix() { + Assertions.assertEquals("1\n2\n3", LineEnding.toUnix("1\n2\n3")); + Assertions.assertEquals("1\n2\n3", LineEnding.toUnix("1\r2\r3")); + Assertions.assertEquals("1\n2\n3", LineEnding.toUnix("1\r\n2\r\n3")); + } + // Formatter normally needs to be closed, but no resources will be leaked in this special case @Test void equality() { From e4b0e0b402f0d25055c49ba27aa6fffabdc7d2e1 Mon Sep 17 00:00:00 2001 From: Ned Twigg Date: Fri, 24 Jun 2022 21:53:53 -0700 Subject: [PATCH 167/757] Update docs. --- plugin-gradle/README.md | 2 +- plugin-maven/README.md | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/plugin-gradle/README.md b/plugin-gradle/README.md index 99d86026d6..52c1d4edac 100644 --- a/plugin-gradle/README.md +++ b/plugin-gradle/README.md @@ -866,7 +866,7 @@ spotless { encoding 'Cp1252' // except java, which will be Cp1252 ``` -Line endings can also be set globally or per-format using the `lineEndings` property. Spotless supports four line ending modes: `UNIX`, `WINDOWS`, `PLATFORM_NATIVE`, and `GIT_ATTRIBUTES`. The default value is `GIT_ATTRIBUTES`, and *we highly recommend that you* ***do not change*** *this value*. Git has opinions about line endings, and if Spotless and git disagree, then you're going to have a bad time. +Line endings can also be set globally or per-format using the `lineEndings` property. Spotless supports four line ending modes: `UNIX`, `WINDOWS`, `MAC_CLASSIC`, `PLATFORM_NATIVE`, and `GIT_ATTRIBUTES`. The default value is `GIT_ATTRIBUTES`, and *we highly recommend that you* ***do not change*** *this value*. Git has opinions about line endings, and if Spotless and git disagree, then you're going to have a bad time. You can easily set the line endings of different files using [a `.gitattributes` file](https://help.github.com/articles/dealing-with-line-endings/). Here's an example `.gitattributes` which sets all files to unix newlines: `* text eol=lf`. diff --git a/plugin-maven/README.md b/plugin-maven/README.md index e6b9ee8e29..c4aefd4289 100644 --- a/plugin-maven/README.md +++ b/plugin-maven/README.md @@ -1034,7 +1034,7 @@ Spotless uses UTF-8 by default, but you can use [any encoding which Java support ``` -Line endings can also be set globally or per-format using the `lineEndings` property. Spotless supports four line ending modes: `UNIX`, `WINDOWS`, `PLATFORM_NATIVE`, and `GIT_ATTRIBUTES`. The default value is `GIT_ATTRIBUTES`, and *we highly recommend that you* ***do not change*** *this value*. Git has opinions about line endings, and if Spotless and git disagree, then you're going to have a bad time. +Line endings can also be set globally or per-format using the `lineEndings` property. Spotless supports four line ending modes: `UNIX`, `WINDOWS`, `MAC_CLASSIC`, `PLATFORM_NATIVE`, and `GIT_ATTRIBUTES`. The default value is `GIT_ATTRIBUTES`, and *we highly recommend that you* ***do not change*** *this value*. Git has opinions about line endings, and if Spotless and git disagree, then you're going to have a bad time. You can easily set the line endings of different files using [a `.gitattributes` file](https://help.github.com/articles/dealing-with-line-endings/). Here's an example `.gitattributes` which sets all files to unix newlines: `* text eol=lf`. From ab0321734d6fb8eae897c69b14efe5b22ebd6ca8 Mon Sep 17 00:00:00 2001 From: Ned Twigg Date: Fri, 24 Jun 2022 21:58:16 -0700 Subject: [PATCH 168/757] Update changelogs. --- CHANGES.md | 2 ++ plugin-gradle/CHANGES.md | 2 ++ plugin-maven/CHANGES.md | 2 ++ 3 files changed, 6 insertions(+) diff --git a/CHANGES.md b/CHANGES.md index 3803d08fd9..8e0d2c74d5 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -10,6 +10,8 @@ This document is intended for Spotless developers. We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format (starting after version `1.27.0`). ## [Unreleased] +### Added +* Support for `MAC_CLASSIC` (`\r`) line ending ([#1243](https://github.com/diffplug/spotless/pull/1243) fixes [#1196](https://github.com/diffplug/spotless/issues/1196)) ## [2.26.2] - 2022-06-11 ### Fixed diff --git a/plugin-gradle/CHANGES.md b/plugin-gradle/CHANGES.md index 6eac3102e0..178b8ec39b 100644 --- a/plugin-gradle/CHANGES.md +++ b/plugin-gradle/CHANGES.md @@ -3,6 +3,8 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format (starting after version `3.27.0`). ## [Unreleased] +### Added +* Support for `MAC_CLASSIC` (`\r`) line ending ([#1243](https://github.com/diffplug/spotless/pull/1243) fixes [#1196](https://github.com/diffplug/spotless/issues/1196)) ## [6.7.2] - 2022-06-11 ### Fixed diff --git a/plugin-maven/CHANGES.md b/plugin-maven/CHANGES.md index 672dfb1150..f6c5bcc84e 100644 --- a/plugin-maven/CHANGES.md +++ b/plugin-maven/CHANGES.md @@ -3,6 +3,8 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format (starting after version `1.27.0`). ## [Unreleased] +### Added +* Support for `MAC_CLASSIC` (`\r`) line ending ([#1243](https://github.com/diffplug/spotless/pull/1243) fixes [#1196](https://github.com/diffplug/spotless/issues/1196)) ## [2.22.8] - 2022-06-11 ### Fixed From 83ad9774a18f20621e09307f6fca30d1e20aed78 Mon Sep 17 00:00:00 2001 From: Nariman Abdullin Date: Fri, 24 Jun 2022 17:24:04 +0300 Subject: [PATCH 169/757] Upgrade diktat to 1.2.0 --- lib/build.gradle | 2 +- .../glue/diktat/DiktatFormatterFunc.java | 13 ++++----- .../diffplug/spotless/kotlin/DiktatStep.java | 28 ++++++------------- 3 files changed, 16 insertions(+), 27 deletions(-) diff --git a/lib/build.gradle b/lib/build.gradle index 2eb0f3e0e5..97897b68bb 100644 --- a/lib/build.gradle +++ b/lib/build.gradle @@ -51,7 +51,7 @@ dependencies { ktlintCompileOnly "com.pinterest.ktlint:ktlint-ruleset-experimental:$VER_KTLINT" ktlintCompileOnly "com.pinterest.ktlint:ktlint-ruleset-standard:$VER_KTLINT" - String VER_DIKTAT = "1.1.0" + String VER_DIKTAT = "1.2.0" diktatCompileOnly "org.cqfn.diktat:diktat-rules:$VER_DIKTAT" // used for markdown formatting diff --git a/lib/src/diktat/java/com/diffplug/spotless/glue/diktat/DiktatFormatterFunc.java b/lib/src/diktat/java/com/diffplug/spotless/glue/diktat/DiktatFormatterFunc.java index 1374bebb10..5a5762f4b6 100644 --- a/lib/src/diktat/java/com/diffplug/spotless/glue/diktat/DiktatFormatterFunc.java +++ b/lib/src/diktat/java/com/diffplug/spotless/glue/diktat/DiktatFormatterFunc.java @@ -20,8 +20,8 @@ import org.cqfn.diktat.ruleset.rules.DiktatRuleSetProvider; +import com.pinterest.ktlint.core.api.EditorConfigOverride; import com.pinterest.ktlint.core.KtLint; -import com.pinterest.ktlint.core.KtLint.Params; import com.pinterest.ktlint.core.LintError; import com.pinterest.ktlint.core.RuleSet; @@ -33,15 +33,13 @@ public class DiktatFormatterFunc implements FormatterFunc.NeedsFile { private final List rulesets; - private final Map userData; private final Function2 formatterCallback; private final boolean isScript; private final ArrayList errors = new ArrayList<>(); - public DiktatFormatterFunc(boolean isScript, Map userData) { + public DiktatFormatterFunc(boolean isScript) { rulesets = Collections.singletonList(new DiktatRuleSetProvider().get()); - this.userData = userData; this.formatterCallback = new FormatterCallback(errors); this.isScript = isScript; } @@ -65,17 +63,18 @@ public Unit invoke(LintError lintError, Boolean corrected) { @Override public String applyWithFile(String unix, File file) throws Exception { errors.clear(); - userData.put("file_path", file.getAbsolutePath()); - String result = KtLint.INSTANCE.format(new Params( + String result = KtLint.INSTANCE.format(new KtLint.ExperimentalParams( // Unlike Ktlint, Diktat requires full path to the file. // See https://github.com/diffplug/spotless/issues/1189, https://github.com/analysis-dev/diktat/issues/1202 file.getAbsolutePath(), unix, rulesets, - userData, + Collections.emptyMap(), formatterCallback, isScript, null, + false, + new EditorConfigOverride(), false)); if (!errors.isEmpty()) { diff --git a/lib/src/main/java/com/diffplug/spotless/kotlin/DiktatStep.java b/lib/src/main/java/com/diffplug/spotless/kotlin/DiktatStep.java index e01748d4b5..7533652243 100644 --- a/lib/src/main/java/com/diffplug/spotless/kotlin/DiktatStep.java +++ b/lib/src/main/java/com/diffplug/spotless/kotlin/DiktatStep.java @@ -30,7 +30,7 @@ public class DiktatStep { // prevent direct instantiation private DiktatStep() {} - private static final String DEFAULT_VERSION = "1.1.0"; + private static final String DEFAULT_VERSION = "1.2.0"; static final String NAME = "diktat"; static final String PACKAGE_DIKTAT = "org.cqfn.diktat"; static final String MAVEN_COORDINATE = PACKAGE_DIKTAT + ":diktat-rules:"; @@ -44,30 +44,22 @@ public static FormatterStep create(Provisioner provisioner) { } public static FormatterStep create(String versionDiktat, Provisioner provisioner) { - return create(versionDiktat, provisioner, Collections.emptyMap(), null); + return create(versionDiktat, provisioner, null); } public static FormatterStep create(String versionDiktat, Provisioner provisioner, @Nullable FileSignature config) { - return create(versionDiktat, provisioner, Collections.emptyMap(), config); - } - - public static FormatterStep create(String versionDiktat, Provisioner provisioner, Map userData, @Nullable FileSignature config) { - return create(versionDiktat, provisioner, false, userData, config); + return create(versionDiktat, provisioner, false, config); } public static FormatterStep createForScript(String versionDiktat, Provisioner provisioner, @Nullable FileSignature config) { - return createForScript(versionDiktat, provisioner, Collections.emptyMap(), config); - } - - public static FormatterStep createForScript(String versionDiktat, Provisioner provisioner, Map userData, @Nullable FileSignature config) { - return create(versionDiktat, provisioner, true, userData, config); + return create(versionDiktat, provisioner, true, config); } - public static FormatterStep create(String versionDiktat, Provisioner provisioner, boolean isScript, Map userData, @Nullable FileSignature config) { + public static FormatterStep create(String versionDiktat, Provisioner provisioner, boolean isScript, @Nullable FileSignature config) { Objects.requireNonNull(versionDiktat, "versionDiktat"); Objects.requireNonNull(provisioner, "provisioner"); return FormatterStep.createLazy(NAME, - () -> new DiktatStep.State(versionDiktat, provisioner, isScript, userData, config), + () -> new DiktatStep.State(versionDiktat, provisioner, isScript, config), DiktatStep.State::createFormat); } @@ -79,14 +71,12 @@ static final class State implements Serializable { private final boolean isScript; private final @Nullable FileSignature config; final JarState jar; - private final TreeMap userData; - State(String versionDiktat, Provisioner provisioner, boolean isScript, Map userData, @Nullable FileSignature config) throws IOException { + State(String versionDiktat, Provisioner provisioner, boolean isScript, @Nullable FileSignature config) throws IOException { HashSet pkgSet = new HashSet<>(); pkgSet.add(MAVEN_COORDINATE + versionDiktat); - this.userData = new TreeMap<>(userData); this.jar = JarState.from(pkgSet, provisioner); this.isScript = isScript; this.config = config; @@ -98,8 +88,8 @@ FormatterFunc createFormat() throws Exception { } Class formatterFunc = jar.getClassLoader().loadClass("com.diffplug.spotless.glue.diktat.DiktatFormatterFunc"); - Constructor constructor = formatterFunc.getConstructor(boolean.class, Map.class); - return (FormatterFunc.NeedsFile) constructor.newInstance(isScript, userData); + Constructor constructor = formatterFunc.getConstructor(boolean.class); + return (FormatterFunc.NeedsFile) constructor.newInstance(isScript); } } } From e9a9b9e31c1ec26cb6dbefde579826ec21c2272c Mon Sep 17 00:00:00 2001 From: Nariman Abdullin Date: Fri, 24 Jun 2022 17:32:18 +0300 Subject: [PATCH 170/757] Update CHANGES.md --- CHANGES.md | 2 ++ plugin-gradle/CHANGES.md | 2 ++ plugin-maven/CHANGES.md | 2 ++ 3 files changed, 6 insertions(+) diff --git a/CHANGES.md b/CHANGES.md index 8e0d2c74d5..c9b2a9fa70 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -12,6 +12,8 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format ( ## [Unreleased] ### Added * Support for `MAC_CLASSIC` (`\r`) line ending ([#1243](https://github.com/diffplug/spotless/pull/1243) fixes [#1196](https://github.com/diffplug/spotless/issues/1196)) +### Fixed +* Bump default `diktat` version to latest `1.1.0` -> `1.2.0`. ([saveourtool/diktat#1399](https://github.com/saveourtool/diktat/issues/1399)) ## [2.26.2] - 2022-06-11 ### Fixed diff --git a/plugin-gradle/CHANGES.md b/plugin-gradle/CHANGES.md index 178b8ec39b..2244b0dfad 100644 --- a/plugin-gradle/CHANGES.md +++ b/plugin-gradle/CHANGES.md @@ -5,6 +5,8 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format ( ## [Unreleased] ### Added * Support for `MAC_CLASSIC` (`\r`) line ending ([#1243](https://github.com/diffplug/spotless/pull/1243) fixes [#1196](https://github.com/diffplug/spotless/issues/1196)) +### Fixed +* Bump default `diktat` version to latest `1.1.0` -> `1.2.0`. ([saveourtool/diktat#1399](https://github.com/saveourtool/diktat/issues/1399)) ## [6.7.2] - 2022-06-11 ### Fixed diff --git a/plugin-maven/CHANGES.md b/plugin-maven/CHANGES.md index f6c5bcc84e..4d75eae40b 100644 --- a/plugin-maven/CHANGES.md +++ b/plugin-maven/CHANGES.md @@ -5,6 +5,8 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format ( ## [Unreleased] ### Added * Support for `MAC_CLASSIC` (`\r`) line ending ([#1243](https://github.com/diffplug/spotless/pull/1243) fixes [#1196](https://github.com/diffplug/spotless/issues/1196)) +### Fixed +* Bump default `diktat` version to latest `1.1.0` -> `1.2.0`. ([saveourtool/diktat#1399](https://github.com/saveourtool/diktat/issues/1399)) ## [2.22.8] - 2022-06-11 ### Fixed From f65b13691c9142f151f8ff4a96fa09a160e8b673 Mon Sep 17 00:00:00 2001 From: Nariman Abdullin Date: Fri, 24 Jun 2022 18:01:41 +0300 Subject: [PATCH 171/757] fixed compile and static issue --- .../com/diffplug/spotless/glue/diktat/DiktatFormatterFunc.java | 2 +- .../main/java/com/diffplug/spotless/maven/kotlin/Diktat.java | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/src/diktat/java/com/diffplug/spotless/glue/diktat/DiktatFormatterFunc.java b/lib/src/diktat/java/com/diffplug/spotless/glue/diktat/DiktatFormatterFunc.java index 5a5762f4b6..0b9d115c2b 100644 --- a/lib/src/diktat/java/com/diffplug/spotless/glue/diktat/DiktatFormatterFunc.java +++ b/lib/src/diktat/java/com/diffplug/spotless/glue/diktat/DiktatFormatterFunc.java @@ -20,10 +20,10 @@ import org.cqfn.diktat.ruleset.rules.DiktatRuleSetProvider; -import com.pinterest.ktlint.core.api.EditorConfigOverride; import com.pinterest.ktlint.core.KtLint; import com.pinterest.ktlint.core.LintError; import com.pinterest.ktlint.core.RuleSet; +import com.pinterest.ktlint.core.api.EditorConfigOverride; import com.diffplug.spotless.FormatterFunc; diff --git a/plugin-maven/src/main/java/com/diffplug/spotless/maven/kotlin/Diktat.java b/plugin-maven/src/main/java/com/diffplug/spotless/maven/kotlin/Diktat.java index 97cbec07b2..13d600e11f 100644 --- a/plugin-maven/src/main/java/com/diffplug/spotless/maven/kotlin/Diktat.java +++ b/plugin-maven/src/main/java/com/diffplug/spotless/maven/kotlin/Diktat.java @@ -41,6 +41,6 @@ public FormatterStep newFormatterStep(FormatterStepConfig stepConfig) { config = ThrowingEx.get(() -> FileSignature.signAsList(stepConfig.getFileLocator().locateFile(configFile))); } String diktatVersion = version != null ? version : DiktatStep.defaultVersionDiktat(); - return DiktatStep.create(diktatVersion, stepConfig.getProvisioner(), Collections.emptyMap(), config); + return DiktatStep.create(diktatVersion, stepConfig.getProvisioner(), config); } } From 5c42c00f67f44057f04bf90afbe62fc8a9bf9e43 Mon Sep 17 00:00:00 2001 From: Nariman Abdullin Date: Fri, 24 Jun 2022 18:45:35 +0300 Subject: [PATCH 172/757] fixed integration tests --- .../main/resources/kotlin/diktat/main.clean | 6 +++--- .../main/resources/kotlin/diktat/main.dirty | 6 +++--- .../spotless/kotlin/DiktatStepTest.java | 18 +++++++++++++----- 3 files changed, 19 insertions(+), 11 deletions(-) diff --git a/testlib/src/main/resources/kotlin/diktat/main.clean b/testlib/src/main/resources/kotlin/diktat/main.clean index 4405165ed5..c46b4542b0 100644 --- a/testlib/src/main/resources/kotlin/diktat/main.clean +++ b/testlib/src/main/resources/kotlin/diktat/main.clean @@ -1,7 +1,7 @@ package org.cqfn.diktat.example.gradle.multiproject /** - * @return print. + * @return something */ class Main { /** @@ -9,7 +9,7 @@ class Main { * */ fun foo() { - println(";") - println() + bar(";") + bar() } } diff --git a/testlib/src/main/resources/kotlin/diktat/main.dirty b/testlib/src/main/resources/kotlin/diktat/main.dirty index 5f7be993aa..a5c225cc4f 100644 --- a/testlib/src/main/resources/kotlin/diktat/main.dirty +++ b/testlib/src/main/resources/kotlin/diktat/main.dirty @@ -1,6 +1,6 @@ package org.cqfn.diktat.example.gradle.multiproject /** - * @return print. + * @return something */ class Main { /** @@ -8,7 +8,7 @@ class Main { * */ fun foo() { - println(";") - println(); + bar(";") + bar(); } } diff --git a/testlib/src/test/java/com/diffplug/spotless/kotlin/DiktatStepTest.java b/testlib/src/test/java/com/diffplug/spotless/kotlin/DiktatStepTest.java index 24a79ed61b..c19f1dc45a 100644 --- a/testlib/src/test/java/com/diffplug/spotless/kotlin/DiktatStepTest.java +++ b/testlib/src/test/java/com/diffplug/spotless/kotlin/DiktatStepTest.java @@ -36,11 +36,15 @@ void behavior() throws Exception { StepHarness.forStep(step) .testResourceException("kotlin/diktat/Unsolvable.kt", assertion -> { assertion.isInstanceOf(AssertionError.class); - assertion.hasMessage("There are 2 unfixed errors:" + + assertion.hasMessage("There are 4 unfixed errors:" + System.lineSeparator() + "Error on line: 1, column: 1 cannot be fixed automatically" + System.lineSeparator() + "[FILE_NAME_INCORRECT] file name is incorrect - it should end with .kt extension and be in PascalCase: testlib" + System.lineSeparator() + "Error on line: 1, column: 1 cannot be fixed automatically" + - System.lineSeparator() + "[FILE_NAME_MATCH_CLASS] file name is incorrect - it should match with the class described in it if there is the only one class declared: testlib vs Unsolvable"); + System.lineSeparator() + "[FILE_NAME_MATCH_CLASS] file name is incorrect - it should match with the class described in it if there is the only one class declared: testlib vs Unsolvable" + + System.lineSeparator() + "Error on line: 1, column: 1 cannot be fixed automatically" + + System.lineSeparator() + "[DEBUG_PRINT] use a dedicated logging library: found println()" + + System.lineSeparator() + "Error on line: 13, column: 9 cannot be fixed automatically" + + System.lineSeparator() + "[DEBUG_PRINT] use a dedicated logging library: found println()"); }); } @@ -51,15 +55,19 @@ void behaviorConf() throws Exception { File conf = setFile(configPath).toResource("kotlin/diktat/diktat-analysis.yml"); FileSignature config = signAsList(conf); - FormatterStep step = DiktatStep.create("1.0.1", TestProvisioner.mavenCentral(), Collections.emptyMap(), config); + FormatterStep step = DiktatStep.create("1.2.0", TestProvisioner.mavenCentral(), config); StepHarness.forStep(step) .testResourceException("kotlin/diktat/Unsolvable.kt", assertion -> { assertion.isInstanceOf(AssertionError.class); - assertion.hasMessage("There are 2 unfixed errors:" + + assertion.hasMessage("There are 4 unfixed errors:" + System.lineSeparator() + "Error on line: 1, column: 1 cannot be fixed automatically" + System.lineSeparator() + "[FILE_NAME_INCORRECT] file name is incorrect - it should end with .kt extension and be in PascalCase: testlib" + System.lineSeparator() + "Error on line: 1, column: 1 cannot be fixed automatically" + - System.lineSeparator() + "[FILE_NAME_MATCH_CLASS] file name is incorrect - it should match with the class described in it if there is the only one class declared: testlib vs Unsolvable"); + System.lineSeparator() + "[FILE_NAME_MATCH_CLASS] file name is incorrect - it should match with the class described in it if there is the only one class declared: testlib vs Unsolvable" + + System.lineSeparator() + "Error on line: 1, column: 1 cannot be fixed automatically" + + System.lineSeparator() + "[DEBUG_PRINT] use a dedicated logging library: found println()" + + System.lineSeparator() + "Error on line: 13, column: 9 cannot be fixed automatically" + + System.lineSeparator() + "[DEBUG_PRINT] use a dedicated logging library: found println()"); }); } From f6de4bb1ab49b4f948f37d186cd04032b16e2a00 Mon Sep 17 00:00:00 2001 From: Nariman Abdullin Date: Fri, 24 Jun 2022 19:38:51 +0300 Subject: [PATCH 173/757] fixed year in javadoc --- .../main/java/com/diffplug/spotless/maven/kotlin/Diktat.java | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/plugin-maven/src/main/java/com/diffplug/spotless/maven/kotlin/Diktat.java b/plugin-maven/src/main/java/com/diffplug/spotless/maven/kotlin/Diktat.java index 13d600e11f..e47345d45d 100644 --- a/plugin-maven/src/main/java/com/diffplug/spotless/maven/kotlin/Diktat.java +++ b/plugin-maven/src/main/java/com/diffplug/spotless/maven/kotlin/Diktat.java @@ -1,5 +1,5 @@ /* - * Copyright 2021 DiffPlug + * Copyright 2021-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,8 +15,6 @@ */ package com.diffplug.spotless.maven.kotlin; -import java.util.Collections; - import org.apache.maven.plugins.annotations.Parameter; import com.diffplug.spotless.FileSignature; From 6d1e35db09f50aebbedc4bcdf8d0dc9234d06e27 Mon Sep 17 00:00:00 2001 From: Nariman Abdullin Date: Tue, 28 Jun 2022 20:51:08 +0300 Subject: [PATCH 174/757] bump diktat to 1.2.1 and add validation of min version --- CHANGES.md | 4 +++- .../com/diffplug/spotless/kotlin/DiktatStep.java | 7 ++++++- plugin-gradle/CHANGES.md | 4 +++- plugin-maven/CHANGES.md | 4 +++- .../diffplug/spotless/kotlin/DiktatStepTest.java | 16 +++++++++++++--- 5 files changed, 28 insertions(+), 7 deletions(-) diff --git a/CHANGES.md b/CHANGES.md index c9b2a9fa70..760595e88c 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -13,7 +13,9 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format ( ### Added * Support for `MAC_CLASSIC` (`\r`) line ending ([#1243](https://github.com/diffplug/spotless/pull/1243) fixes [#1196](https://github.com/diffplug/spotless/issues/1196)) ### Fixed -* Bump default `diktat` version to latest `1.1.0` -> `1.2.0`. ([saveourtool/diktat#1399](https://github.com/saveourtool/diktat/issues/1399)) +* Bump default `diktat` version to latest `1.1.0` -> `1.2.1`. ([saveourtool/diktat#1399](https://github.com/saveourtool/diktat/issues/1399)) + * Note that support `diktat` version `1.2.1` is or higher + * The property `userData` is removed ## [2.26.2] - 2022-06-11 ### Fixed diff --git a/lib/src/main/java/com/diffplug/spotless/kotlin/DiktatStep.java b/lib/src/main/java/com/diffplug/spotless/kotlin/DiktatStep.java index 7533652243..94921a99bd 100644 --- a/lib/src/main/java/com/diffplug/spotless/kotlin/DiktatStep.java +++ b/lib/src/main/java/com/diffplug/spotless/kotlin/DiktatStep.java @@ -30,7 +30,9 @@ public class DiktatStep { // prevent direct instantiation private DiktatStep() {} - private static final String DEFAULT_VERSION = "1.2.0"; + private static final String MIN_SUPPORTED_VERSION = "1.2.1"; + + private static final String DEFAULT_VERSION = "1.2.1"; static final String NAME = "diktat"; static final String PACKAGE_DIKTAT = "org.cqfn.diktat"; static final String MAVEN_COORDINATE = PACKAGE_DIKTAT + ":diktat-rules:"; @@ -56,6 +58,9 @@ public static FormatterStep createForScript(String versionDiktat, Provisioner pr } public static FormatterStep create(String versionDiktat, Provisioner provisioner, boolean isScript, @Nullable FileSignature config) { + if (BadSemver.version(versionDiktat) < BadSemver.version(MIN_SUPPORTED_VERSION)) { + throw new IllegalStateException("Diktat supported for version " + MIN_SUPPORTED_VERSION + " and later"); + } Objects.requireNonNull(versionDiktat, "versionDiktat"); Objects.requireNonNull(provisioner, "provisioner"); return FormatterStep.createLazy(NAME, diff --git a/plugin-gradle/CHANGES.md b/plugin-gradle/CHANGES.md index 2244b0dfad..05bd5f7ce6 100644 --- a/plugin-gradle/CHANGES.md +++ b/plugin-gradle/CHANGES.md @@ -6,7 +6,9 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format ( ### Added * Support for `MAC_CLASSIC` (`\r`) line ending ([#1243](https://github.com/diffplug/spotless/pull/1243) fixes [#1196](https://github.com/diffplug/spotless/issues/1196)) ### Fixed -* Bump default `diktat` version to latest `1.1.0` -> `1.2.0`. ([saveourtool/diktat#1399](https://github.com/saveourtool/diktat/issues/1399)) +* Bump default `diktat` version to latest `1.1.0` -> `1.2.1`. ([saveourtool/diktat#1399](https://github.com/saveourtool/diktat/issues/1399)) + * Note that support `diktat` version `1.2.1` is or higher + * The property `userData` is removed ## [6.7.2] - 2022-06-11 ### Fixed diff --git a/plugin-maven/CHANGES.md b/plugin-maven/CHANGES.md index 4d75eae40b..259cab1017 100644 --- a/plugin-maven/CHANGES.md +++ b/plugin-maven/CHANGES.md @@ -6,7 +6,9 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format ( ### Added * Support for `MAC_CLASSIC` (`\r`) line ending ([#1243](https://github.com/diffplug/spotless/pull/1243) fixes [#1196](https://github.com/diffplug/spotless/issues/1196)) ### Fixed -* Bump default `diktat` version to latest `1.1.0` -> `1.2.0`. ([saveourtool/diktat#1399](https://github.com/saveourtool/diktat/issues/1399)) +* Bump default `diktat` version to latest `1.1.0` -> `1.2.1`. ([saveourtool/diktat#1399](https://github.com/saveourtool/diktat/issues/1399)) + * Note that support `diktat` version `1.2.1` is or higher + * The property `userData` is removed ## [2.22.8] - 2022-06-11 ### Fixed diff --git a/testlib/src/test/java/com/diffplug/spotless/kotlin/DiktatStepTest.java b/testlib/src/test/java/com/diffplug/spotless/kotlin/DiktatStepTest.java index c19f1dc45a..c37289c6e6 100644 --- a/testlib/src/test/java/com/diffplug/spotless/kotlin/DiktatStepTest.java +++ b/testlib/src/test/java/com/diffplug/spotless/kotlin/DiktatStepTest.java @@ -18,8 +18,8 @@ import static com.diffplug.spotless.FileSignature.signAsList; import java.io.File; -import java.util.Collections; +import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Test; import com.diffplug.spotless.FileSignature; @@ -50,12 +50,11 @@ void behavior() throws Exception { @Test void behaviorConf() throws Exception { - String configPath = "src/main/kotlin/diktat-analysis.yml"; File conf = setFile(configPath).toResource("kotlin/diktat/diktat-analysis.yml"); FileSignature config = signAsList(conf); - FormatterStep step = DiktatStep.create("1.2.0", TestProvisioner.mavenCentral(), config); + FormatterStep step = DiktatStep.create("1.2.1", TestProvisioner.mavenCentral(), config); StepHarness.forStep(step) .testResourceException("kotlin/diktat/Unsolvable.kt", assertion -> { assertion.isInstanceOf(AssertionError.class); @@ -71,4 +70,15 @@ void behaviorConf() throws Exception { }); } + @Test + void notSupportedVersion() { + final IllegalStateException notSupportedException = Assertions.assertThrows(IllegalStateException.class, + () -> DiktatStep.create("1.2.0", TestProvisioner.mavenCentral())); + Assertions.assertTrue( + notSupportedException.getMessage().contains("Diktat supported for version 1.2.1 and later") + ); + + Assertions.assertDoesNotThrow(() -> DiktatStep.create("1.2.1", TestProvisioner.mavenCentral())); + Assertions.assertDoesNotThrow(() -> DiktatStep.create("2.0.0", TestProvisioner.mavenCentral())); + } } From 67978ab1cbe345e71e4cea30ea3aa04c0f0330af Mon Sep 17 00:00:00 2001 From: Mitchell Skaggs Date: Tue, 28 Jun 2022 21:44:32 -0500 Subject: [PATCH 175/757] Update KtLint min version to 0.46.0 and default version to 0.46.1 Closes #1239 --- CHANGES.md | 3 + lib/build.gradle | 2 +- .../glue/ktlint/KtlintFormatterFunc.java | 44 ++++------ .../diffplug/spotless/kotlin/KtLintStep.java | 86 ++----------------- plugin-gradle/CHANGES.md | 3 + plugin-maven/CHANGES.md | 3 + .../spotless/kotlin/KtLintStepTest.java | 39 +-------- 7 files changed, 37 insertions(+), 143 deletions(-) diff --git a/CHANGES.md b/CHANGES.md index 8e0d2c74d5..830d57d1a4 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -12,6 +12,9 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format ( ## [Unreleased] ### Added * Support for `MAC_CLASSIC` (`\r`) line ending ([#1243](https://github.com/diffplug/spotless/pull/1243) fixes [#1196](https://github.com/diffplug/spotless/issues/1196)) +### Changes +* Bump default `ktlint` version to latest `0.45.2` -> `0.46.1` [#1239](https://github.com/diffplug/spotless/issues/1239) + * Note that we now require `ktlint >= 0.46.0` due to frequent compatibility breakages ## [2.26.2] - 2022-06-11 ### Fixed diff --git a/lib/build.gradle b/lib/build.gradle index 2eb0f3e0e5..34b25d94a7 100644 --- a/lib/build.gradle +++ b/lib/build.gradle @@ -45,7 +45,7 @@ dependencies { } } - String VER_KTLINT='0.45.2' + String VER_KTLINT='0.46.1' ktlintCompileOnly "com.pinterest:ktlint:$VER_KTLINT" ktlintCompileOnly "com.pinterest.ktlint:ktlint-core:$VER_KTLINT" ktlintCompileOnly "com.pinterest.ktlint:ktlint-ruleset-experimental:$VER_KTLINT" diff --git a/lib/src/ktlint/java/com/diffplug/spotless/glue/ktlint/KtlintFormatterFunc.java b/lib/src/ktlint/java/com/diffplug/spotless/glue/ktlint/KtlintFormatterFunc.java index 1cd79a6ba9..da3e3ae475 100644 --- a/lib/src/ktlint/java/com/diffplug/spotless/glue/ktlint/KtlintFormatterFunc.java +++ b/lib/src/ktlint/java/com/diffplug/spotless/glue/ktlint/KtlintFormatterFunc.java @@ -24,6 +24,8 @@ import java.util.stream.Collectors; import java.util.stream.Stream; +import org.jetbrains.annotations.NotNull; + import com.pinterest.ktlint.core.KtLint; import com.pinterest.ktlint.core.KtLint.ExperimentalParams; import com.pinterest.ktlint.core.LintError; @@ -46,6 +48,7 @@ public class KtlintFormatterFunc implements FormatterFunc.NeedsFile { private final Map userData; private final Function2 formatterCallback; private final boolean isScript; + @NotNull private final EditorConfigOverride editorConfigOverride; /** @@ -64,7 +67,7 @@ public KtlintFormatterFunc(boolean isScript, boolean useExperimental, Map edit // Create a mapping of properties to their names based on rule properties and default properties Map> supportedProperties = Stream - .concat(ruleProperties, DefaultEditorConfigProperties.INSTANCE.getDefaultEditorConfigProperties().stream()) + .concat(ruleProperties, DefaultEditorConfigProperties.INSTANCE.getEditorConfigProperties().stream()) .distinct() .collect(Collectors.toMap(property -> property.getType().getName(), property -> property)); @@ -116,31 +119,16 @@ public Unit invoke(LintError lint, Boolean corrected) { @Override public String applyWithFile(String unix, File file) throws Exception { - - if (editorConfigOverride != null) { - // Use ExperimentalParams with EditorConfigOverride which requires KtLint 0.45.2 - return KtLint.INSTANCE.format(new ExperimentalParams( - file.getName(), - unix, - rulesets, - userData, - formatterCallback, - isScript, - null, - false, - editorConfigOverride, - false)); - } else { - // Use Params for backward compatibility - return KtLint.INSTANCE.format(new KtLint.Params( - file.getName(), - unix, - rulesets, - userData, - formatterCallback, - isScript, - null, - false)); - } + return KtLint.INSTANCE.format(new ExperimentalParams( + file.getName(), + unix, + rulesets, + userData, + formatterCallback, + isScript, + null, + false, + editorConfigOverride, + false)); } } diff --git a/lib/src/main/java/com/diffplug/spotless/kotlin/KtLintStep.java b/lib/src/main/java/com/diffplug/spotless/kotlin/KtLintStep.java index d58331ec1b..f57ef1e997 100644 --- a/lib/src/main/java/com/diffplug/spotless/kotlin/KtLintStep.java +++ b/lib/src/main/java/com/diffplug/spotless/kotlin/KtLintStep.java @@ -18,10 +18,6 @@ import java.io.IOException; import java.io.Serializable; import java.lang.reflect.Constructor; -import java.lang.reflect.InvocationTargetException; -import java.lang.reflect.Method; -import java.lang.reflect.Proxy; -import java.util.ArrayList; import java.util.Collections; import java.util.Map; import java.util.Objects; @@ -31,18 +27,15 @@ import com.diffplug.spotless.FormatterStep; import com.diffplug.spotless.JarState; import com.diffplug.spotless.Provisioner; -import com.diffplug.spotless.ThrowingEx; /** Wraps up ktlint as a FormatterStep. */ public class KtLintStep { // prevent direct instantiation private KtLintStep() {} - private static final String DEFAULT_VERSION = "0.45.2"; + private static final String DEFAULT_VERSION = "0.46.1"; static final String NAME = "ktlint"; - static final String PACKAGE_PRE_0_32 = "com.github.shyiko"; static final String PACKAGE = "com.pinterest"; - static final String MAVEN_COORDINATE_PRE_0_32 = PACKAGE_PRE_0_32 + ":ktlint:"; static final String MAVEN_COORDINATE = PACKAGE + ":ktlint:"; public static FormatterStep create(Provisioner provisioner) { @@ -85,95 +78,30 @@ static final class State implements Serializable { /** Are the files being linted Kotlin script files. */ private final boolean isScript; - private final String pkg; /** The jar that contains the formatter. */ final JarState jarState; private final boolean useExperimental; private final TreeMap userData; private final TreeMap editorConfigOverride; - private final boolean useParams; State(String version, Provisioner provisioner, boolean isScript, boolean useExperimental, Map userData, Map editorConfigOverride) throws IOException { - if (!editorConfigOverride.isEmpty() && - BadSemver.version(version) < BadSemver.version(0, 45, 2)) { - throw new IllegalStateException("KtLint editorConfigOverride supported for version 0.45.2 and later"); + if (BadSemver.version(version) < BadSemver.version(0, 46, 0)) { + throw new IllegalStateException("KtLint versions < 0.46.0 not supported!"); } this.useExperimental = useExperimental; this.userData = new TreeMap<>(userData); this.editorConfigOverride = new TreeMap<>(editorConfigOverride); - String coordinate; - if (BadSemver.version(version) < BadSemver.version(0, 32)) { - coordinate = MAVEN_COORDINATE_PRE_0_32; - this.pkg = PACKAGE_PRE_0_32; - } else { - coordinate = MAVEN_COORDINATE; - this.pkg = PACKAGE; - } - this.useParams = BadSemver.version(version) >= BadSemver.version(0, 34); - this.jarState = JarState.from(coordinate + version, provisioner); + this.jarState = JarState.from(MAVEN_COORDINATE + version, provisioner); this.isScript = isScript; } FormatterFunc createFormat() throws Exception { - if (useParams) { - Class formatterFunc = jarState.getClassLoader().loadClass("com.diffplug.spotless.glue.ktlint.KtlintFormatterFunc"); - Constructor constructor = formatterFunc.getConstructor(boolean.class, boolean.class, Map.class, Map.class); - return (FormatterFunc.NeedsFile) constructor.newInstance(isScript, useExperimental, userData, editorConfigOverride); - } - - ClassLoader classLoader = jarState.getClassLoader(); - // String KtLint::format(String input, Iterable rules, Function2 errorCallback) - - ArrayList ruleSets = new ArrayList<>(); - - // first, we get the standard rules - Class standardRuleSetProviderClass = classLoader.loadClass(pkg + ".ktlint.ruleset.standard.StandardRuleSetProvider"); - Object standardRuleSet = standardRuleSetProviderClass.getMethod("get").invoke(standardRuleSetProviderClass.newInstance()); - ruleSets.add(standardRuleSet); - - // second, we get the experimental rules if desired - if (useExperimental) { - Class experimentalRuleSetProviderClass = classLoader.loadClass(pkg + ".ktlint.ruleset.experimental.ExperimentalRuleSetProvider"); - Object experimentalRuleSet = experimentalRuleSetProviderClass.getMethod("get").invoke(experimentalRuleSetProviderClass.newInstance()); - ruleSets.add(experimentalRuleSet); - } - - // next, we create an error callback which throws an assertion error when the format is bad - Class function2Interface = classLoader.loadClass("kotlin.jvm.functions.Function2"); - Class lintErrorClass = classLoader.loadClass(pkg + ".ktlint.core.LintError"); - Method detailGetter = lintErrorClass.getMethod("getDetail"); - Method lineGetter = lintErrorClass.getMethod("getLine"); - Method colGetter = lintErrorClass.getMethod("getCol"); - Object formatterCallback = Proxy.newProxyInstance(classLoader, new Class[]{function2Interface}, - (proxy, method, args) -> { - Object lintError = args[0]; //ktlint.core.LintError - boolean corrected = (Boolean) args[1]; - if (!corrected) { - String detail = (String) detailGetter.invoke(lintError); - int line = (Integer) lineGetter.invoke(lintError); - int col = (Integer) colGetter.invoke(lintError); - throw new AssertionError("Error on line: " + line + ", column: " + col + "\n" + detail); - } - return null; - }); - - // grab the KtLint singleton - Class ktlintClass = classLoader.loadClass(pkg + ".ktlint.core.KtLint"); - Object ktlint = ktlintClass.getDeclaredField("INSTANCE").get(null); - - // and its format method - String formatterMethodName = isScript ? "formatScript" : "format"; - Method formatterMethod = ktlintClass.getMethod(formatterMethodName, String.class, Iterable.class, Map.class, function2Interface); - return input -> { - try { - return (String) formatterMethod.invoke(ktlint, input, ruleSets, userData, formatterCallback); - } catch (InvocationTargetException e) { - throw ThrowingEx.unwrapCause(e); - } - }; + Class formatterFunc = jarState.getClassLoader().loadClass("com.diffplug.spotless.glue.ktlint.KtlintFormatterFunc"); + Constructor constructor = formatterFunc.getConstructor(boolean.class, boolean.class, Map.class, Map.class); + return (FormatterFunc.NeedsFile) constructor.newInstance(isScript, useExperimental, userData, editorConfigOverride); } } } diff --git a/plugin-gradle/CHANGES.md b/plugin-gradle/CHANGES.md index 178b8ec39b..77d94486bb 100644 --- a/plugin-gradle/CHANGES.md +++ b/plugin-gradle/CHANGES.md @@ -5,6 +5,9 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format ( ## [Unreleased] ### Added * Support for `MAC_CLASSIC` (`\r`) line ending ([#1243](https://github.com/diffplug/spotless/pull/1243) fixes [#1196](https://github.com/diffplug/spotless/issues/1196)) +### Changes +* Bump default `ktlint` version to latest `0.45.2` -> `0.46.1` [#1239](https://github.com/diffplug/spotless/issues/1239) + * Note that we now require `ktlint >= 0.46.0` due to frequent compatibility breakages ## [6.7.2] - 2022-06-11 ### Fixed diff --git a/plugin-maven/CHANGES.md b/plugin-maven/CHANGES.md index f6c5bcc84e..adefaacb5e 100644 --- a/plugin-maven/CHANGES.md +++ b/plugin-maven/CHANGES.md @@ -5,6 +5,9 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format ( ## [Unreleased] ### Added * Support for `MAC_CLASSIC` (`\r`) line ending ([#1243](https://github.com/diffplug/spotless/pull/1243) fixes [#1196](https://github.com/diffplug/spotless/issues/1196)) +### Changes +* Bump default `ktlint` version to latest `0.45.2` -> `0.46.1` [#1239](https://github.com/diffplug/spotless/issues/1239) + * Note that we now require `ktlint >= 0.46.0` due to frequent compatibility breakages ## [2.22.8] - 2022-06-11 ### Fixed diff --git a/testlib/src/test/java/com/diffplug/spotless/kotlin/KtLintStepTest.java b/testlib/src/test/java/com/diffplug/spotless/kotlin/KtLintStepTest.java index af61ac4cd0..388fa57e74 100644 --- a/testlib/src/test/java/com/diffplug/spotless/kotlin/KtLintStepTest.java +++ b/testlib/src/test/java/com/diffplug/spotless/kotlin/KtLintStepTest.java @@ -42,8 +42,8 @@ void behavior() throws Exception { } @Test - void worksShyiko() throws Exception { - FormatterStep step = KtLintStep.create("0.31.0", TestProvisioner.mavenCentral()); + void worksPre0_46_1() throws Exception { + FormatterStep step = KtLintStep.create("0.46.0", TestProvisioner.mavenCentral()); StepHarness.forStep(step) .testResource("kotlin/ktlint/basic.dirty", "kotlin/ktlint/basic.clean") .testResourceException("kotlin/ktlint/unsolvable.dirty", assertion -> { @@ -53,48 +53,17 @@ void worksShyiko() throws Exception { }); } - // Regression test to ensure it works on the version it switched to Pinterest (version 0.32.0) - // but before 0.34. - // https://github.com/diffplug/spotless/issues/419 - @Test - void worksPinterestAndPre034() throws Exception { - FormatterStep step = KtLintStep.create("0.32.0", TestProvisioner.mavenCentral()); - StepHarness.forStep(step) - .testResource("kotlin/ktlint/basic.dirty", "kotlin/ktlint/basic.clean") - .testResourceException("kotlin/ktlint/unsolvable.dirty", assertion -> { - assertion.isInstanceOf(AssertionError.class); - assertion.hasMessage("Error on line: 1, column: 1\n" + - "Wildcard import"); - }); - } - - // Regression test to handle alpha and 1.x version numbers - // https://github.com/diffplug/spotless/issues/668 - @Test - void worksAlpha1() throws Exception { - FormatterStep step = KtLintStep.create("0.38.0-alpha01", TestProvisioner.mavenCentral()); - StepHarness.forStep(step) - .testResource("kotlin/ktlint/basic.dirty", "kotlin/ktlint/basic.clean"); - } - - @Test - void worksPre0_45_2() throws Exception { - FormatterStep step = KtLintStep.create("0.45.1", TestProvisioner.mavenCentral()); - StepHarness.forStep(step) - .testResource("kotlin/ktlint/basic.dirty", "kotlin/ktlint/basic.clean"); - } - @Test void equality() throws Exception { new SerializableEqualityTester() { - String version = "0.32.0"; + String version = "0.46.0"; @Override protected void setupTest(API api) { // same version == same api.areDifferentThan(); // change the version, and it's different - version = "0.38.0-alpha01"; + version = "0.46.1"; api.areDifferentThan(); } From 652e1f0786a1721b8b5c15f4063e422739a42789 Mon Sep 17 00:00:00 2001 From: Mitchell Skaggs Date: Tue, 28 Jun 2022 21:45:47 -0500 Subject: [PATCH 176/757] Remove outdated test comment --- .../java/com/diffplug/spotless/kotlin/KtLintStepTest.java | 5 ----- 1 file changed, 5 deletions(-) diff --git a/testlib/src/test/java/com/diffplug/spotless/kotlin/KtLintStepTest.java b/testlib/src/test/java/com/diffplug/spotless/kotlin/KtLintStepTest.java index 388fa57e74..a4a43ef44e 100644 --- a/testlib/src/test/java/com/diffplug/spotless/kotlin/KtLintStepTest.java +++ b/testlib/src/test/java/com/diffplug/spotless/kotlin/KtLintStepTest.java @@ -23,11 +23,6 @@ import com.diffplug.spotless.StepHarness; import com.diffplug.spotless.TestProvisioner; -/** - * This class is the only one that uses jcenter, and it seems to be the only one that - * causes these problems. The root is still a gradle bug, but in the meantime we don't - * need to hold up *every* PR with this: https://github.com/gradle/gradle/issues/11752 - */ class KtLintStepTest extends ResourceHarness { @Test void behavior() throws Exception { From cfe2cf41af4062d4d374539e8aa68850fadf7619 Mon Sep 17 00:00:00 2001 From: Ned Twigg Date: Wed, 29 Jun 2022 16:10:56 -0700 Subject: [PATCH 177/757] Change the verbiage around minimum required version. --- CHANGES.md | 7 +++---- .../main/java/com/diffplug/spotless/kotlin/DiktatStep.java | 2 +- plugin-gradle/CHANGES.md | 7 +++---- plugin-maven/CHANGES.md | 7 +++---- 4 files changed, 10 insertions(+), 13 deletions(-) diff --git a/CHANGES.md b/CHANGES.md index 760595e88c..3a415d83ca 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -12,10 +12,9 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format ( ## [Unreleased] ### Added * Support for `MAC_CLASSIC` (`\r`) line ending ([#1243](https://github.com/diffplug/spotless/pull/1243) fixes [#1196](https://github.com/diffplug/spotless/issues/1196)) -### Fixed -* Bump default `diktat` version to latest `1.1.0` -> `1.2.1`. ([saveourtool/diktat#1399](https://github.com/saveourtool/diktat/issues/1399)) - * Note that support `diktat` version `1.2.1` is or higher - * The property `userData` is removed +### Changed +* Minimum required `diktat` version bumped to `1.2.1` ([#1246](https://github.com/diffplug/spotless/pull/1246)) + * Default bumped from `1.1.0` -> `1.2.1` ## [2.26.2] - 2022-06-11 ### Fixed diff --git a/lib/src/main/java/com/diffplug/spotless/kotlin/DiktatStep.java b/lib/src/main/java/com/diffplug/spotless/kotlin/DiktatStep.java index 94921a99bd..ff3e3240cf 100644 --- a/lib/src/main/java/com/diffplug/spotless/kotlin/DiktatStep.java +++ b/lib/src/main/java/com/diffplug/spotless/kotlin/DiktatStep.java @@ -59,7 +59,7 @@ public static FormatterStep createForScript(String versionDiktat, Provisioner pr public static FormatterStep create(String versionDiktat, Provisioner provisioner, boolean isScript, @Nullable FileSignature config) { if (BadSemver.version(versionDiktat) < BadSemver.version(MIN_SUPPORTED_VERSION)) { - throw new IllegalStateException("Diktat supported for version " + MIN_SUPPORTED_VERSION + " and later"); + throw new IllegalStateException("Minimum required Diktat version is " + MIN_SUPPORTED_VERSION + ", you tried " + versionDiktat + " which is too old"); } Objects.requireNonNull(versionDiktat, "versionDiktat"); Objects.requireNonNull(provisioner, "provisioner"); diff --git a/plugin-gradle/CHANGES.md b/plugin-gradle/CHANGES.md index 05bd5f7ce6..266c0ac151 100644 --- a/plugin-gradle/CHANGES.md +++ b/plugin-gradle/CHANGES.md @@ -5,10 +5,9 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format ( ## [Unreleased] ### Added * Support for `MAC_CLASSIC` (`\r`) line ending ([#1243](https://github.com/diffplug/spotless/pull/1243) fixes [#1196](https://github.com/diffplug/spotless/issues/1196)) -### Fixed -* Bump default `diktat` version to latest `1.1.0` -> `1.2.1`. ([saveourtool/diktat#1399](https://github.com/saveourtool/diktat/issues/1399)) - * Note that support `diktat` version `1.2.1` is or higher - * The property `userData` is removed +### Changed +* Minimum required `diktat` version bumped to `1.2.1` ([#1246](https://github.com/diffplug/spotless/pull/1246)) + * Default bumped from `1.1.0` -> `1.2.1` ## [6.7.2] - 2022-06-11 ### Fixed diff --git a/plugin-maven/CHANGES.md b/plugin-maven/CHANGES.md index 259cab1017..25aec044fc 100644 --- a/plugin-maven/CHANGES.md +++ b/plugin-maven/CHANGES.md @@ -5,10 +5,9 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format ( ## [Unreleased] ### Added * Support for `MAC_CLASSIC` (`\r`) line ending ([#1243](https://github.com/diffplug/spotless/pull/1243) fixes [#1196](https://github.com/diffplug/spotless/issues/1196)) -### Fixed -* Bump default `diktat` version to latest `1.1.0` -> `1.2.1`. ([saveourtool/diktat#1399](https://github.com/saveourtool/diktat/issues/1399)) - * Note that support `diktat` version `1.2.1` is or higher - * The property `userData` is removed +### Changed +* Minimum required `diktat` version bumped to `1.2.1` ([#1246](https://github.com/diffplug/spotless/pull/1246)) + * Default bumped from `1.1.0` -> `1.2.1` ## [2.22.8] - 2022-06-11 ### Fixed From e3e0beb4661e491b6935e44ed1f19e97c29cad09 Mon Sep 17 00:00:00 2001 From: Ned Twigg Date: Wed, 29 Jun 2022 16:11:08 -0700 Subject: [PATCH 178/757] spotlessApply --- .../java/com/diffplug/spotless/kotlin/DiktatStepTest.java | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/testlib/src/test/java/com/diffplug/spotless/kotlin/DiktatStepTest.java b/testlib/src/test/java/com/diffplug/spotless/kotlin/DiktatStepTest.java index c37289c6e6..0075aed162 100644 --- a/testlib/src/test/java/com/diffplug/spotless/kotlin/DiktatStepTest.java +++ b/testlib/src/test/java/com/diffplug/spotless/kotlin/DiktatStepTest.java @@ -73,10 +73,9 @@ void behaviorConf() throws Exception { @Test void notSupportedVersion() { final IllegalStateException notSupportedException = Assertions.assertThrows(IllegalStateException.class, - () -> DiktatStep.create("1.2.0", TestProvisioner.mavenCentral())); + () -> DiktatStep.create("1.2.0", TestProvisioner.mavenCentral())); Assertions.assertTrue( - notSupportedException.getMessage().contains("Diktat supported for version 1.2.1 and later") - ); + notSupportedException.getMessage().contains("Diktat supported for version 1.2.1 and later")); Assertions.assertDoesNotThrow(() -> DiktatStep.create("1.2.1", TestProvisioner.mavenCentral())); Assertions.assertDoesNotThrow(() -> DiktatStep.create("2.0.0", TestProvisioner.mavenCentral())); From 3022df74439315487e60149d72ee3f4e1ab9cc55 Mon Sep 17 00:00:00 2001 From: Ned Twigg Date: Wed, 29 Jun 2022 16:35:11 -0700 Subject: [PATCH 179/757] Bump diktat down to latest published version, 1.2.0 --- CHANGES.md | 4 ++-- .../main/java/com/diffplug/spotless/kotlin/DiktatStep.java | 4 ++-- plugin-gradle/CHANGES.md | 4 ++-- plugin-maven/CHANGES.md | 4 ++-- .../java/com/diffplug/spotless/kotlin/DiktatStepTest.java | 6 +++--- 5 files changed, 11 insertions(+), 11 deletions(-) diff --git a/CHANGES.md b/CHANGES.md index 3a415d83ca..0512418d94 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -13,8 +13,8 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format ( ### Added * Support for `MAC_CLASSIC` (`\r`) line ending ([#1243](https://github.com/diffplug/spotless/pull/1243) fixes [#1196](https://github.com/diffplug/spotless/issues/1196)) ### Changed -* Minimum required `diktat` version bumped to `1.2.1` ([#1246](https://github.com/diffplug/spotless/pull/1246)) - * Default bumped from `1.1.0` -> `1.2.1` +* Minimum required `diktat` version bumped to `1.2.0` ([#1246](https://github.com/diffplug/spotless/pull/1246)) + * Default bumped from `1.1.0` -> `1.2.0` ## [2.26.2] - 2022-06-11 ### Fixed diff --git a/lib/src/main/java/com/diffplug/spotless/kotlin/DiktatStep.java b/lib/src/main/java/com/diffplug/spotless/kotlin/DiktatStep.java index ff3e3240cf..92dcd8f51c 100644 --- a/lib/src/main/java/com/diffplug/spotless/kotlin/DiktatStep.java +++ b/lib/src/main/java/com/diffplug/spotless/kotlin/DiktatStep.java @@ -30,9 +30,9 @@ public class DiktatStep { // prevent direct instantiation private DiktatStep() {} - private static final String MIN_SUPPORTED_VERSION = "1.2.1"; + private static final String MIN_SUPPORTED_VERSION = "1.2.0"; - private static final String DEFAULT_VERSION = "1.2.1"; + private static final String DEFAULT_VERSION = "1.2.0"; static final String NAME = "diktat"; static final String PACKAGE_DIKTAT = "org.cqfn.diktat"; static final String MAVEN_COORDINATE = PACKAGE_DIKTAT + ":diktat-rules:"; diff --git a/plugin-gradle/CHANGES.md b/plugin-gradle/CHANGES.md index 266c0ac151..69844c1daa 100644 --- a/plugin-gradle/CHANGES.md +++ b/plugin-gradle/CHANGES.md @@ -6,8 +6,8 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format ( ### Added * Support for `MAC_CLASSIC` (`\r`) line ending ([#1243](https://github.com/diffplug/spotless/pull/1243) fixes [#1196](https://github.com/diffplug/spotless/issues/1196)) ### Changed -* Minimum required `diktat` version bumped to `1.2.1` ([#1246](https://github.com/diffplug/spotless/pull/1246)) - * Default bumped from `1.1.0` -> `1.2.1` +* Minimum required `diktat` version bumped to `1.2.0` ([#1246](https://github.com/diffplug/spotless/pull/1246)) + * Default bumped from `1.1.0` -> `1.2.0` ## [6.7.2] - 2022-06-11 ### Fixed diff --git a/plugin-maven/CHANGES.md b/plugin-maven/CHANGES.md index 25aec044fc..63c121a007 100644 --- a/plugin-maven/CHANGES.md +++ b/plugin-maven/CHANGES.md @@ -6,8 +6,8 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format ( ### Added * Support for `MAC_CLASSIC` (`\r`) line ending ([#1243](https://github.com/diffplug/spotless/pull/1243) fixes [#1196](https://github.com/diffplug/spotless/issues/1196)) ### Changed -* Minimum required `diktat` version bumped to `1.2.1` ([#1246](https://github.com/diffplug/spotless/pull/1246)) - * Default bumped from `1.1.0` -> `1.2.1` +* Minimum required `diktat` version bumped to `1.2.0` ([#1246](https://github.com/diffplug/spotless/pull/1246)) + * Default bumped from `1.1.0` -> `1.2.0` ## [2.22.8] - 2022-06-11 ### Fixed diff --git a/testlib/src/test/java/com/diffplug/spotless/kotlin/DiktatStepTest.java b/testlib/src/test/java/com/diffplug/spotless/kotlin/DiktatStepTest.java index 0075aed162..2a955f16cb 100644 --- a/testlib/src/test/java/com/diffplug/spotless/kotlin/DiktatStepTest.java +++ b/testlib/src/test/java/com/diffplug/spotless/kotlin/DiktatStepTest.java @@ -54,7 +54,7 @@ void behaviorConf() throws Exception { File conf = setFile(configPath).toResource("kotlin/diktat/diktat-analysis.yml"); FileSignature config = signAsList(conf); - FormatterStep step = DiktatStep.create("1.2.1", TestProvisioner.mavenCentral(), config); + FormatterStep step = DiktatStep.create("1.2.0", TestProvisioner.mavenCentral(), config); StepHarness.forStep(step) .testResourceException("kotlin/diktat/Unsolvable.kt", assertion -> { assertion.isInstanceOf(AssertionError.class); @@ -73,9 +73,9 @@ void behaviorConf() throws Exception { @Test void notSupportedVersion() { final IllegalStateException notSupportedException = Assertions.assertThrows(IllegalStateException.class, - () -> DiktatStep.create("1.2.0", TestProvisioner.mavenCentral())); + () -> DiktatStep.create("1.1.0", TestProvisioner.mavenCentral())); Assertions.assertTrue( - notSupportedException.getMessage().contains("Diktat supported for version 1.2.1 and later")); + notSupportedException.getMessage().contains("Minimum required Diktat version is 1.2.0, you tried 1.1.0 which is too old")); Assertions.assertDoesNotThrow(() -> DiktatStep.create("1.2.1", TestProvisioner.mavenCentral())); Assertions.assertDoesNotThrow(() -> DiktatStep.create("2.0.0", TestProvisioner.mavenCentral())); From 9b0cf08d2ea69a1d32e4f5bcd0e910a623e2f779 Mon Sep 17 00:00:00 2001 From: Ned Twigg Date: Wed, 29 Jun 2022 18:45:56 -0700 Subject: [PATCH 180/757] Update the maven tests for Diktat. --- .../java/com/diffplug/spotless/maven/kotlin/DiktatTest.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/plugin-maven/src/test/java/com/diffplug/spotless/maven/kotlin/DiktatTest.java b/plugin-maven/src/test/java/com/diffplug/spotless/maven/kotlin/DiktatTest.java index bd37c5c82e..eccaa7ac2e 100644 --- a/plugin-maven/src/test/java/com/diffplug/spotless/maven/kotlin/DiktatTest.java +++ b/plugin-maven/src/test/java/com/diffplug/spotless/maven/kotlin/DiktatTest.java @@ -40,7 +40,7 @@ void testDiktatWithVersion() throws Exception { writePomWithKotlinSteps( "", - " 1.0.1", + " 1.2.0", ""); String path = "src/main/kotlin/Main.kt"; @@ -56,7 +56,7 @@ void testDiktatConfig() throws Exception { File conf = setFile(configPath).toResource("kotlin/diktat/diktat-analysis.yml"); writePomWithKotlinSteps( "", - " 1.0.1", + " 1.2.0", " " + conf.getAbsolutePath() + "", ""); From 1d9d686d99332f70e3d8d2d42c7a57a0e89ac8f4 Mon Sep 17 00:00:00 2001 From: Ned Twigg Date: Thu, 30 Jun 2022 09:10:22 -0700 Subject: [PATCH 181/757] Fixup a bunch of ktlint tests. --- .../gradle/spotless/KotlinExtensionTest.java | 67 ++++--------------- .../kotlin/ktlint/basic.clean-indent6 | 5 ++ .../KotlinCodeWithMultiYearHeader.test | 1 + .../KotlinCodeWithMultiYearHeader2.test | 1 + .../KotlinCodeWithoutHeader.test | 3 +- 5 files changed, 21 insertions(+), 56 deletions(-) create mode 100644 testlib/src/main/resources/kotlin/ktlint/basic.clean-indent6 diff --git a/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/KotlinExtensionTest.java b/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/KotlinExtensionTest.java index da2a604681..b2952f18b3 100644 --- a/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/KotlinExtensionTest.java +++ b/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/KotlinExtensionTest.java @@ -15,13 +15,10 @@ */ package com.diffplug.gradle.spotless; -import static org.assertj.core.api.Assertions.assertThat; -import static org.junit.jupiter.api.Assertions.assertThrows; import static org.junit.jupiter.api.condition.JRE.JAVA_11; import java.io.IOException; -import org.gradle.testkit.runner.BuildResult; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.condition.EnabledForJreRange; @@ -42,9 +39,9 @@ void integration() throws IOException { " ktlint()", " }", "}"); - setFile("src/main/kotlin/basic.kt").toResource("kotlin/ktlint/basic.dirty"); + setFile("src/main/kotlin/Main.kt").toResource("kotlin/ktlint/basic.dirty"); gradleRunner().withArguments("spotlessApply").build(); - assertFile("src/main/kotlin/basic.kt").sameAsResource("kotlin/ktlint/basic.clean"); + assertFile("src/main/kotlin/Main.kt").sameAsResource("kotlin/ktlint/basic.clean"); } @Test @@ -132,12 +129,12 @@ void testWithIndentation() throws IOException { "repositories { mavenCentral() }", "spotless {", " kotlin {", - " ktlint('0.32.0').userData(['indent_size': '6'])", + " ktlint().editorConfigOverride(['indent_size': '6'])", " }", "}"); - setFile("src/main/kotlin/basic.kt").toResource("kotlin/ktlint/basic.dirty"); - BuildResult result = gradleRunner().withArguments("spotlessApply").buildAndFail(); - assertThat(result.getOutput()).contains("Unexpected indentation (4) (it should be 6)"); + setFile("src/main/kotlin/Main.kt").toResource("kotlin/ktlint/basic.dirty"); + gradleRunner().withArguments("spotlessApply").build(); + assertFile("src/main/kotlin/Main.kt").sameAsResource("kotlin/ktlint/basic.clean-indent6"); } @Test @@ -153,27 +150,9 @@ void withExperimental() throws IOException { " ktlint().setUseExperimental(true)", " }", "}"); - setFile("src/main/kotlin/experimental.kt").toResource("kotlin/ktlint/experimental.dirty"); - gradleRunner().withArguments("spotlessApply").build(); - assertFile("src/main/kotlin/experimental.kt").sameAsResource("kotlin/ktlint/experimental.clean"); - } - - @Test - void withExperimental_0_32() throws IOException { - setFile("build.gradle").toLines( - "plugins {", - " id 'org.jetbrains.kotlin.jvm' version '1.5.31'", - " id 'com.diffplug.spotless'", - "}", - "repositories { mavenCentral() }", - "spotless {", - " kotlin {", - " ktlint('0.32.0').setUseExperimental(true)", - " }", - "}"); - setFile("src/main/kotlin/basic.kt").toResource("kotlin/ktlint/basic.dirty"); + setFile("src/main/kotlin/Main.kt").toResource("kotlin/ktlint/experimental.dirty"); gradleRunner().withArguments("spotlessApply").build(); - assertFile("src/main/kotlin/basic.kt").sameAsResource("kotlin/ktlint/basic.clean"); + assertFile("src/main/kotlin/Main.kt").sameAsResource("kotlin/ktlint/experimental.clean"); } @Test @@ -193,31 +172,9 @@ void withExperimentalEditorConfigOverride() throws IOException { " ])", " }", "}"); - setFile("src/main/kotlin/experimental.kt").toResource("kotlin/ktlint/experimentalEditorConfigOverride.dirty"); + setFile("src/main/kotlin/Main.kt").toResource("kotlin/ktlint/experimentalEditorConfigOverride.dirty"); gradleRunner().withArguments("spotlessApply").build(); - assertFile("src/main/kotlin/experimental.kt").sameAsResource("kotlin/ktlint/experimentalEditorConfigOverride.clean"); - } - - @Test - void withEditorConfigOverride_0_45_1() throws IOException { - setFile("build.gradle").toLines( - "plugins {", - " id 'org.jetbrains.kotlin.jvm' version '1.5.31'", - " id 'com.diffplug.spotless'", - "}", - "repositories { mavenCentral() }", - "spotless {", - " kotlin {", - " ktlint('0.45.1')", - " .editorConfigOverride([", - " indent_size: 5", - " ])", - " }", - "}"); - setFile("src/main/kotlin/basic.kt").toResource("kotlin/ktlint/basic.dirty"); - Throwable error = assertThrows(Throwable.class, - () -> gradleRunner().withArguments("spotlessApply").build()); - assertThat(error).hasMessageContaining("KtLint editorConfigOverride supported for version 0.45.2 and later"); + assertFile("src/main/kotlin/Main.kt").sameAsResource("kotlin/ktlint/experimentalEditorConfigOverride.clean"); } /** @@ -240,9 +197,9 @@ void experimentalSampleUnchangedWithDefaultRuleset() throws IOException { " ktlint()", " }", "}"); - setFile("src/main/kotlin/experimental.kt").toResource("kotlin/ktlint/experimental.dirty"); + setFile("src/main/kotlin/Main.kt").toResource("kotlin/ktlint/experimental.dirty"); gradleRunner().withArguments("spotlessApply").build(); - assertFile("src/main/kotlin/experimental.kt").sameAsResource("kotlin/ktlint/experimental.dirty"); + assertFile("src/main/kotlin/Main.kt").sameAsResource("kotlin/ktlint/experimental.dirty"); } @Test diff --git a/testlib/src/main/resources/kotlin/ktlint/basic.clean-indent6 b/testlib/src/main/resources/kotlin/ktlint/basic.clean-indent6 new file mode 100644 index 0000000000..cbfbfa8712 --- /dev/null +++ b/testlib/src/main/resources/kotlin/ktlint/basic.clean-indent6 @@ -0,0 +1,5 @@ +fun main() { + fun name() { a(); return b } + println(";") + println() +} diff --git a/testlib/src/main/resources/kotlin/licenseheader/KotlinCodeWithMultiYearHeader.test b/testlib/src/main/resources/kotlin/licenseheader/KotlinCodeWithMultiYearHeader.test index c8890b5f34..c78a2f8264 100644 --- a/testlib/src/main/resources/kotlin/licenseheader/KotlinCodeWithMultiYearHeader.test +++ b/testlib/src/main/resources/kotlin/licenseheader/KotlinCodeWithMultiYearHeader.test @@ -1,5 +1,6 @@ // License Header 2012, 2014 @file:JvmName("SomeFileName") + package my.test object AnObject diff --git a/testlib/src/main/resources/kotlin/licenseheader/KotlinCodeWithMultiYearHeader2.test b/testlib/src/main/resources/kotlin/licenseheader/KotlinCodeWithMultiYearHeader2.test index 005124dec9..82c38dec74 100644 --- a/testlib/src/main/resources/kotlin/licenseheader/KotlinCodeWithMultiYearHeader2.test +++ b/testlib/src/main/resources/kotlin/licenseheader/KotlinCodeWithMultiYearHeader2.test @@ -1,5 +1,6 @@ // License Header 2012-2014 @file:JvmName("SomeFileName") + package my.test object AnObject2 diff --git a/testlib/src/main/resources/kotlin/licenseheader/KotlinCodeWithoutHeader.test b/testlib/src/main/resources/kotlin/licenseheader/KotlinCodeWithoutHeader.test index 666ba3a652..16ba57b2d4 100644 --- a/testlib/src/main/resources/kotlin/licenseheader/KotlinCodeWithoutHeader.test +++ b/testlib/src/main/resources/kotlin/licenseheader/KotlinCodeWithoutHeader.test @@ -1,4 +1,5 @@ @file:JvmName("SomeFileName") + package my.test -object AnObject \ No newline at end of file +object AnObject From 1474d990dd3482e4039ebbfd1061f2df4887703f Mon Sep 17 00:00:00 2001 From: Ned Twigg Date: Thu, 30 Jun 2022 10:57:54 -0700 Subject: [PATCH 182/757] Fix the rest of the ktlint tests. --- .../gradle/spotless/KotlinExtensionTest.java | 25 ------ .../spotless/KotlinGradleExtensionTest.java | 83 ------------------- .../spotless/maven/kotlin/KtlintTest.java | 28 +------ 3 files changed, 3 insertions(+), 133 deletions(-) diff --git a/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/KotlinExtensionTest.java b/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/KotlinExtensionTest.java index b2952f18b3..5da722ea44 100644 --- a/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/KotlinExtensionTest.java +++ b/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/KotlinExtensionTest.java @@ -177,31 +177,6 @@ void withExperimentalEditorConfigOverride() throws IOException { assertFile("src/main/kotlin/Main.kt").sameAsResource("kotlin/ktlint/experimentalEditorConfigOverride.clean"); } - /** - * Check that the sample used to verify the experimental ruleset is untouched by the default ruleset, to verify - * that enabling the experimental ruleset is actually doing something. - * - * If this test fails, it's likely that the experimental rule being used as a test graduated into the standard - * ruleset, and therefore a new experimental rule should be used to verify functionality. - */ - @Test - void experimentalSampleUnchangedWithDefaultRuleset() throws IOException { - setFile("build.gradle").toLines( - "plugins {", - " id 'org.jetbrains.kotlin.jvm' version '1.5.31'", - " id 'com.diffplug.spotless'", - "}", - "repositories { mavenCentral() }", - "spotless {", - " kotlin {", - " ktlint()", - " }", - "}"); - setFile("src/main/kotlin/Main.kt").toResource("kotlin/ktlint/experimental.dirty"); - gradleRunner().withArguments("spotlessApply").build(); - assertFile("src/main/kotlin/Main.kt").sameAsResource("kotlin/ktlint/experimental.dirty"); - } - @Test void testWithHeader() throws IOException { setFile("build.gradle").toLines( diff --git a/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/KotlinGradleExtensionTest.java b/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/KotlinGradleExtensionTest.java index 034174cf73..ef42e89198 100644 --- a/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/KotlinGradleExtensionTest.java +++ b/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/KotlinGradleExtensionTest.java @@ -94,24 +94,6 @@ void integration_default_diktat() throws IOException { assertThat(result.getOutput()).contains("[AVOID_NESTED_FUNCTIONS] try to avoid using nested functions"); } - @Test - void integration_pinterest() throws IOException { - setFile("build.gradle").toLines( - "plugins {", - " id 'org.jetbrains.kotlin.jvm' version '1.5.31'", - " id 'com.diffplug.spotless'", - "}", - "repositories { mavenCentral() }", - "spotless {", - " kotlinGradle {", - " ktlint('0.32.0')", - " }", - "}"); - setFile("configuration.gradle.kts").toResource("kotlin/ktlint/basic.dirty"); - gradleRunner().withArguments("spotlessApply").build(); - assertFile("configuration.gradle.kts").sameAsResource("kotlin/ktlint/basic.clean"); - } - @Test void indentStep() throws IOException { setFile("build.gradle").toLines( @@ -147,24 +129,6 @@ void withExperimental() throws IOException { assertFile("configuration.gradle.kts").sameAsResource("kotlin/ktlint/experimental.clean"); } - @Test - void withExperimental_0_32() throws IOException { - setFile("build.gradle").toLines( - "plugins {", - " id 'org.jetbrains.kotlin.jvm' version '1.5.31'", - " id 'com.diffplug.spotless'", - "}", - "repositories { mavenCentral() }", - "spotless {", - " kotlinGradle {", - " ktlint('0.32.0').setUseExperimental(true)", - " }", - "}"); - setFile("configuration.gradle.kts").toResource("kotlin/ktlint/basic.dirty"); - gradleRunner().withArguments("spotlessApply").build(); - assertFile("configuration.gradle.kts").sameAsResource("kotlin/ktlint/basic.clean"); - } - @Test void withExperimentalEditorConfigOverride() throws IOException { setFile("build.gradle").toLines( @@ -187,53 +151,6 @@ void withExperimentalEditorConfigOverride() throws IOException { assertFile("configuration.gradle.kts").sameAsResource("kotlin/ktlint/experimentalEditorConfigOverride.clean"); } - @Test - void withEditorConfigOverride_0_45_1() throws IOException { - setFile("build.gradle").toLines( - "plugins {", - " id 'org.jetbrains.kotlin.jvm' version '1.5.31'", - " id 'com.diffplug.spotless'", - "}", - "repositories { mavenCentral() }", - "spotless {", - " kotlinGradle {", - " ktlint('0.45.1')", - " .editorConfigOverride([", - " indent_size: 5", - " ])", - " }", - "}"); - setFile("configuration.gradle.kts").toResource("kotlin/ktlint/basic.dirty"); - Throwable error = assertThrows(Throwable.class, - () -> gradleRunner().withArguments("spotlessApply").build()); - assertThat(error).hasMessageContaining("KtLint editorConfigOverride supported for version 0.45.2 and later"); - } - - /** - * Check that the sample used to verify the experimental ruleset is untouched by the default ruleset, to verify - * that enabling the experimental ruleset is actually doing something. - * - * If this test fails, it's likely that the experimental rule being used as a test graduated into the standard - * ruleset, and therefore a new experimental rule should be used to verify functionality. - */ - @Test - void experimentalSampleUnchangedWithDefaultRuleset() throws IOException { - setFile("build.gradle").toLines( - "plugins {", - " id 'org.jetbrains.kotlin.jvm' version '1.5.31'", - " id 'com.diffplug.spotless'", - "}", - "repositories { mavenCentral() }", - "spotless {", - " kotlinGradle {", - " ktlint()", - " }", - "}"); - setFile("configuration.gradle.kts").toResource("kotlin/ktlint/experimental.dirty"); - gradleRunner().withArguments("spotlessApply").build(); - assertFile("configuration.gradle.kts").sameAsResource("kotlin/ktlint/experimental.dirty"); - } - @Test @EnabledForJreRange(min = JAVA_11) // ktfmt's dependency, google-java-format 1.8 requires a minimum of JRE 11+. void integration_ktfmt() throws IOException { diff --git a/plugin-maven/src/test/java/com/diffplug/spotless/maven/kotlin/KtlintTest.java b/plugin-maven/src/test/java/com/diffplug/spotless/maven/kotlin/KtlintTest.java index 4e75008829..18e3002328 100644 --- a/plugin-maven/src/test/java/com/diffplug/spotless/maven/kotlin/KtlintTest.java +++ b/plugin-maven/src/test/java/com/diffplug/spotless/maven/kotlin/KtlintTest.java @@ -24,31 +24,9 @@ class KtlintTest extends MavenIntegrationHarness { void testKtlint() throws Exception { writePomWithKotlinSteps(""); - String path1 = "src/main/kotlin/main1.kt"; - String path2 = "src/main/kotlin/main2.kt"; - - setFile(path1).toResource("kotlin/ktlint/basic.dirty"); - setFile(path2).toResource("kotlin/ktlint/basic.dirty"); - + String path = "src/main/kotlin/Main.kt"; + setFile(path).toResource("kotlin/ktlint/basic.dirty"); mavenRunner().withArguments("spotless:apply").runNoError(); - - assertFile(path1).sameAsResource("kotlin/ktlint/basic.clean"); - assertFile(path2).sameAsResource("kotlin/ktlint/basic.clean"); - } - - @Test - void testKtlintShyiko() throws Exception { - writePomWithKotlinSteps("0.21.0"); - - String path1 = "src/main/kotlin/main1.kt"; - String path2 = "src/main/kotlin/main2.kt"; - - setFile(path1).toResource("kotlin/ktlint/basic.dirty"); - setFile(path2).toResource("kotlin/ktlint/basic.dirty"); - - mavenRunner().withArguments("spotless:apply").runNoError(); - - assertFile(path1).sameAsResource("kotlin/ktlint/basic.clean"); - assertFile(path2).sameAsResource("kotlin/ktlint/basic.clean"); + assertFile(path).sameAsResource("kotlin/ktlint/basic.clean"); } } From 4befeaf5b4d2d25541108beb5a6512f5d9b67ac6 Mon Sep 17 00:00:00 2001 From: Ned Twigg Date: Thu, 30 Jun 2022 12:30:57 -0700 Subject: [PATCH 183/757] spotlessApply --- .../com/diffplug/gradle/spotless/KotlinGradleExtensionTest.java | 1 - .../java/com/diffplug/spotless/maven/kotlin/KtlintTest.java | 2 +- 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/KotlinGradleExtensionTest.java b/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/KotlinGradleExtensionTest.java index ef42e89198..0f3438ffff 100644 --- a/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/KotlinGradleExtensionTest.java +++ b/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/KotlinGradleExtensionTest.java @@ -16,7 +16,6 @@ package com.diffplug.gradle.spotless; import static org.assertj.core.api.Assertions.assertThat; -import static org.junit.jupiter.api.Assertions.assertThrows; import static org.junit.jupiter.api.condition.JRE.JAVA_11; import java.io.IOException; diff --git a/plugin-maven/src/test/java/com/diffplug/spotless/maven/kotlin/KtlintTest.java b/plugin-maven/src/test/java/com/diffplug/spotless/maven/kotlin/KtlintTest.java index 18e3002328..887f7a3f50 100644 --- a/plugin-maven/src/test/java/com/diffplug/spotless/maven/kotlin/KtlintTest.java +++ b/plugin-maven/src/test/java/com/diffplug/spotless/maven/kotlin/KtlintTest.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. From 502a8f0c1bc4a1e9f299f60584d80add7236ad9d Mon Sep 17 00:00:00 2001 From: Andrey Kuleshov Date: Thu, 30 Jun 2022 22:44:10 +0300 Subject: [PATCH 184/757] Updated diktat version to 1.2.1 --- lib/build.gradle | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/build.gradle b/lib/build.gradle index 97897b68bb..9491be4a03 100644 --- a/lib/build.gradle +++ b/lib/build.gradle @@ -51,7 +51,7 @@ dependencies { ktlintCompileOnly "com.pinterest.ktlint:ktlint-ruleset-experimental:$VER_KTLINT" ktlintCompileOnly "com.pinterest.ktlint:ktlint-ruleset-standard:$VER_KTLINT" - String VER_DIKTAT = "1.2.0" + String VER_DIKTAT = "1.2.1" diktatCompileOnly "org.cqfn.diktat:diktat-rules:$VER_DIKTAT" // used for markdown formatting From e0286ee22dae7e47a76c94eb476b19b3bfd5dd3b Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Thu, 30 Jun 2022 19:48:03 +0000 Subject: [PATCH 185/757] Bump ktfmt from 0.37 to 0.39 Bumps [ktfmt](https://github.com/facebookincubator/ktfmt) from 0.37 to 0.39. - [Release notes](https://github.com/facebookincubator/ktfmt/releases) - [Commits](https://github.com/facebookincubator/ktfmt/compare/v0.37...v0.39) --- updated-dependencies: - dependency-name: com.facebook:ktfmt dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] --- lib/build.gradle | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/build.gradle b/lib/build.gradle index f819a3c2fe..68f92c69f0 100644 --- a/lib/build.gradle +++ b/lib/build.gradle @@ -36,7 +36,7 @@ dependencies { palantirJavaFormatCompileOnly 'com.palantir.javaformat:palantir-java-format:1.1.0' - String VER_KTFMT = '0.37' + String VER_KTFMT = '0.39' 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") { From 2b93b1b19c38c62288e0976c6d2d134ce0588ca2 Mon Sep 17 00:00:00 2001 From: Andrey Kuleshov Date: Thu, 30 Jun 2022 23:02:56 +0300 Subject: [PATCH 186/757] Updated all version of diktat (including tests) --- .../main/java/com/diffplug/spotless/kotlin/DiktatStep.java | 4 ++-- .../java/com/diffplug/spotless/maven/kotlin/DiktatTest.java | 4 ++-- .../java/com/diffplug/spotless/kotlin/DiktatStepTest.java | 2 +- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/lib/src/main/java/com/diffplug/spotless/kotlin/DiktatStep.java b/lib/src/main/java/com/diffplug/spotless/kotlin/DiktatStep.java index 92dcd8f51c..ff3e3240cf 100644 --- a/lib/src/main/java/com/diffplug/spotless/kotlin/DiktatStep.java +++ b/lib/src/main/java/com/diffplug/spotless/kotlin/DiktatStep.java @@ -30,9 +30,9 @@ public class DiktatStep { // prevent direct instantiation private DiktatStep() {} - private static final String MIN_SUPPORTED_VERSION = "1.2.0"; + private static final String MIN_SUPPORTED_VERSION = "1.2.1"; - private static final String DEFAULT_VERSION = "1.2.0"; + private static final String DEFAULT_VERSION = "1.2.1"; static final String NAME = "diktat"; static final String PACKAGE_DIKTAT = "org.cqfn.diktat"; static final String MAVEN_COORDINATE = PACKAGE_DIKTAT + ":diktat-rules:"; diff --git a/plugin-maven/src/test/java/com/diffplug/spotless/maven/kotlin/DiktatTest.java b/plugin-maven/src/test/java/com/diffplug/spotless/maven/kotlin/DiktatTest.java index eccaa7ac2e..dc6e59fef0 100644 --- a/plugin-maven/src/test/java/com/diffplug/spotless/maven/kotlin/DiktatTest.java +++ b/plugin-maven/src/test/java/com/diffplug/spotless/maven/kotlin/DiktatTest.java @@ -40,7 +40,7 @@ void testDiktatWithVersion() throws Exception { writePomWithKotlinSteps( "", - " 1.2.0", + " 1.2.1", ""); String path = "src/main/kotlin/Main.kt"; @@ -56,7 +56,7 @@ void testDiktatConfig() throws Exception { File conf = setFile(configPath).toResource("kotlin/diktat/diktat-analysis.yml"); writePomWithKotlinSteps( "", - " 1.2.0", + " 1.2.1", " " + conf.getAbsolutePath() + "", ""); diff --git a/testlib/src/test/java/com/diffplug/spotless/kotlin/DiktatStepTest.java b/testlib/src/test/java/com/diffplug/spotless/kotlin/DiktatStepTest.java index 2a955f16cb..39f939ddf4 100644 --- a/testlib/src/test/java/com/diffplug/spotless/kotlin/DiktatStepTest.java +++ b/testlib/src/test/java/com/diffplug/spotless/kotlin/DiktatStepTest.java @@ -54,7 +54,7 @@ void behaviorConf() throws Exception { File conf = setFile(configPath).toResource("kotlin/diktat/diktat-analysis.yml"); FileSignature config = signAsList(conf); - FormatterStep step = DiktatStep.create("1.2.0", TestProvisioner.mavenCentral(), config); + FormatterStep step = DiktatStep.create("1.2.1", TestProvisioner.mavenCentral(), config); StepHarness.forStep(step) .testResourceException("kotlin/diktat/Unsolvable.kt", assertion -> { assertion.isInstanceOf(AssertionError.class); From ad3c18bad8e01149e6df62d264d2af69cc5f416c Mon Sep 17 00:00:00 2001 From: Ned Twigg Date: Thu, 30 Jun 2022 13:11:43 -0700 Subject: [PATCH 187/757] Bump ktfmt programmatically to 0.39 also. --- CHANGES.md | 3 ++- lib/src/main/java/com/diffplug/spotless/kotlin/KtfmtStep.java | 2 +- plugin-gradle/CHANGES.md | 3 ++- plugin-maven/CHANGES.md | 3 ++- 4 files changed, 7 insertions(+), 4 deletions(-) diff --git a/CHANGES.md b/CHANGES.md index 45511490d6..47f9542dc3 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -15,8 +15,9 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format ( ### Changes * Bump default `ktlint` version to latest `0.45.2` -> `0.46.1` ([#1239](https://github.com/diffplug/spotless/issues/1239)) * Minimum supported version also bumped to `0.46.0` (we have abandoned strong backward compatibility for `ktlint`, from here on out Spotless will only support the most-recent breaking change). -* Bump default `diktat` version to latest `1.1.0` -> `1.2.0` ([#1246](https://github.com/diffplug/spotless/pull/1246)) +* Bump default `diktat` version to latest `1.1.0` -> `1.2.1` ([#1246](https://github.com/diffplug/spotless/pull/1246)) * Minimum supported version also bumped to `1.2.0` (diktat is based on ktlint and has the same backward compatibility issues). +* Bump default `ktfmt` version to latest `0.37` -> `0.39` ([#1240](https://github.com/diffplug/spotless/pull/1240)) ## [2.26.2] - 2022-06-11 ### Fixed 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 b7ade56b5f..37bbf786c6 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.37"; + private static final String DEFAULT_VERSION = "0.39"; static final String NAME = "ktfmt"; static final String PACKAGE = "com.facebook"; static final String MAVEN_COORDINATE = PACKAGE + ":ktfmt:"; diff --git a/plugin-gradle/CHANGES.md b/plugin-gradle/CHANGES.md index 71924d68c0..c3be5003da 100644 --- a/plugin-gradle/CHANGES.md +++ b/plugin-gradle/CHANGES.md @@ -8,8 +8,9 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format ( ### Changes * Bump default `ktlint` version to latest `0.45.2` -> `0.46.1` ([#1239](https://github.com/diffplug/spotless/issues/1239)) * Minimum supported version also bumped to `0.46.0` (we have abandoned strong backward compatibility for `ktlint`, from here on out Spotless will only support the most-recent breaking change). -* Bump default `diktat` version to latest `1.1.0` -> `1.2.0` ([#1246](https://github.com/diffplug/spotless/pull/1246)) +* Bump default `diktat` version to latest `1.1.0` -> `1.2.1` ([#1246](https://github.com/diffplug/spotless/pull/1246)) * Minimum supported version also bumped to `1.2.0` (diktat is based on ktlint and has the same backward compatibility issues). +* Bump default `ktfmt` version to latest `0.37` -> `0.39` ([#1240](https://github.com/diffplug/spotless/pull/1240)) ## [6.7.2] - 2022-06-11 ### Fixed diff --git a/plugin-maven/CHANGES.md b/plugin-maven/CHANGES.md index 5012b9f077..e7165b03d0 100644 --- a/plugin-maven/CHANGES.md +++ b/plugin-maven/CHANGES.md @@ -8,8 +8,9 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format ( ### Changes * Bump default `ktlint` version to latest `0.45.2` -> `0.46.1` ([#1239](https://github.com/diffplug/spotless/issues/1239)) * Minimum supported version also bumped to `0.46.0` (we have abandoned strong backward compatibility for `ktlint`, from here on out Spotless will only support the most-recent breaking change). -* Bump default `diktat` version to latest `1.1.0` -> `1.2.0` ([#1246](https://github.com/diffplug/spotless/pull/1246)) +* Bump default `diktat` version to latest `1.1.0` -> `1.2.1` ([#1246](https://github.com/diffplug/spotless/pull/1246)) * Minimum supported version also bumped to `1.2.0` (diktat is based on ktlint and has the same backward compatibility issues). +* Bump default `ktfmt` version to latest `0.37` -> `0.39` ([#1240](https://github.com/diffplug/spotless/pull/1240)) ## [2.22.8] - 2022-06-11 ### Fixed From 9dde3da38949e385fa1bc035508c4511f058a0e9 Mon Sep 17 00:00:00 2001 From: Ned Twigg Date: Thu, 30 Jun 2022 13:38:54 -0700 Subject: [PATCH 188/757] Update changes and a test. --- CHANGES.md | 2 +- plugin-gradle/CHANGES.md | 2 +- plugin-maven/CHANGES.md | 2 +- .../test/java/com/diffplug/spotless/kotlin/DiktatStepTest.java | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/CHANGES.md b/CHANGES.md index 47f9542dc3..5871c0d822 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -16,7 +16,7 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format ( * Bump default `ktlint` version to latest `0.45.2` -> `0.46.1` ([#1239](https://github.com/diffplug/spotless/issues/1239)) * Minimum supported version also bumped to `0.46.0` (we have abandoned strong backward compatibility for `ktlint`, from here on out Spotless will only support the most-recent breaking change). * Bump default `diktat` version to latest `1.1.0` -> `1.2.1` ([#1246](https://github.com/diffplug/spotless/pull/1246)) - * Minimum supported version also bumped to `1.2.0` (diktat is based on ktlint and has the same backward compatibility issues). + * Minimum supported version also bumped to `1.2.1` (diktat is based on ktlint and has the same backward compatibility issues). * Bump default `ktfmt` version to latest `0.37` -> `0.39` ([#1240](https://github.com/diffplug/spotless/pull/1240)) ## [2.26.2] - 2022-06-11 diff --git a/plugin-gradle/CHANGES.md b/plugin-gradle/CHANGES.md index c3be5003da..45c09688a6 100644 --- a/plugin-gradle/CHANGES.md +++ b/plugin-gradle/CHANGES.md @@ -9,7 +9,7 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format ( * Bump default `ktlint` version to latest `0.45.2` -> `0.46.1` ([#1239](https://github.com/diffplug/spotless/issues/1239)) * Minimum supported version also bumped to `0.46.0` (we have abandoned strong backward compatibility for `ktlint`, from here on out Spotless will only support the most-recent breaking change). * Bump default `diktat` version to latest `1.1.0` -> `1.2.1` ([#1246](https://github.com/diffplug/spotless/pull/1246)) - * Minimum supported version also bumped to `1.2.0` (diktat is based on ktlint and has the same backward compatibility issues). + * Minimum supported version also bumped to `1.2.1` (diktat is based on ktlint and has the same backward compatibility issues). * Bump default `ktfmt` version to latest `0.37` -> `0.39` ([#1240](https://github.com/diffplug/spotless/pull/1240)) ## [6.7.2] - 2022-06-11 diff --git a/plugin-maven/CHANGES.md b/plugin-maven/CHANGES.md index e7165b03d0..25ffe9f9e7 100644 --- a/plugin-maven/CHANGES.md +++ b/plugin-maven/CHANGES.md @@ -9,7 +9,7 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format ( * Bump default `ktlint` version to latest `0.45.2` -> `0.46.1` ([#1239](https://github.com/diffplug/spotless/issues/1239)) * Minimum supported version also bumped to `0.46.0` (we have abandoned strong backward compatibility for `ktlint`, from here on out Spotless will only support the most-recent breaking change). * Bump default `diktat` version to latest `1.1.0` -> `1.2.1` ([#1246](https://github.com/diffplug/spotless/pull/1246)) - * Minimum supported version also bumped to `1.2.0` (diktat is based on ktlint and has the same backward compatibility issues). + * Minimum supported version also bumped to `1.2.1` (diktat is based on ktlint and has the same backward compatibility issues). * Bump default `ktfmt` version to latest `0.37` -> `0.39` ([#1240](https://github.com/diffplug/spotless/pull/1240)) ## [2.22.8] - 2022-06-11 diff --git a/testlib/src/test/java/com/diffplug/spotless/kotlin/DiktatStepTest.java b/testlib/src/test/java/com/diffplug/spotless/kotlin/DiktatStepTest.java index 39f939ddf4..45bf6524f1 100644 --- a/testlib/src/test/java/com/diffplug/spotless/kotlin/DiktatStepTest.java +++ b/testlib/src/test/java/com/diffplug/spotless/kotlin/DiktatStepTest.java @@ -75,7 +75,7 @@ void notSupportedVersion() { final IllegalStateException notSupportedException = Assertions.assertThrows(IllegalStateException.class, () -> DiktatStep.create("1.1.0", TestProvisioner.mavenCentral())); Assertions.assertTrue( - notSupportedException.getMessage().contains("Minimum required Diktat version is 1.2.0, you tried 1.1.0 which is too old")); + notSupportedException.getMessage().contains("Minimum required Diktat version is 1.2.1, you tried 1.1.0 which is too old")); Assertions.assertDoesNotThrow(() -> DiktatStep.create("1.2.1", TestProvisioner.mavenCentral())); Assertions.assertDoesNotThrow(() -> DiktatStep.create("2.0.0", TestProvisioner.mavenCentral())); From 795f74f4651124d4d53be44ff6f48952852a2263 Mon Sep 17 00:00:00 2001 From: circleci Date: Thu, 30 Jun 2022 21:05:27 +0000 Subject: [PATCH 189/757] Published lib/2.27.0 --- CHANGES.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/CHANGES.md b/CHANGES.md index 5871c0d822..7f6160b600 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -10,6 +10,8 @@ This document is intended for Spotless developers. We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format (starting after version `1.27.0`). ## [Unreleased] + +## [2.27.0] - 2022-06-30 ### Added * Support for `MAC_CLASSIC` (`\r`) line ending ([#1243](https://github.com/diffplug/spotless/pull/1243) fixes [#1196](https://github.com/diffplug/spotless/issues/1196)) ### Changes From d71bc1812f9fbcabb5cda3e82dac11d7da45e1d5 Mon Sep 17 00:00:00 2001 From: circleci Date: Thu, 30 Jun 2022 21:06:25 +0000 Subject: [PATCH 190/757] Published gradle/6.8.0 --- plugin-gradle/CHANGES.md | 2 ++ plugin-gradle/README.md | 46 ++++++++++++++++++++-------------------- 2 files changed, 25 insertions(+), 23 deletions(-) diff --git a/plugin-gradle/CHANGES.md b/plugin-gradle/CHANGES.md index 45c09688a6..02d8da736d 100644 --- a/plugin-gradle/CHANGES.md +++ b/plugin-gradle/CHANGES.md @@ -3,6 +3,8 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format (starting after version `3.27.0`). ## [Unreleased] + +## [6.8.0] - 2022-06-30 ### Added * Support for `MAC_CLASSIC` (`\r`) line ending ([#1243](https://github.com/diffplug/spotless/pull/1243) fixes [#1196](https://github.com/diffplug/spotless/issues/1196)) ### Changes diff --git a/plugin-gradle/README.md b/plugin-gradle/README.md index 52c1d4edac..5301b4287c 100644 --- a/plugin-gradle/README.md +++ b/plugin-gradle/README.md @@ -18,9 +18,9 @@ output = [ --> [![Gradle plugin](https://img.shields.io/badge/plugins.gradle.org-com.diffplug.spotless-blue.svg)](https://plugins.gradle.org/plugin/com.diffplug.spotless) [![Maven central](https://img.shields.io/badge/mavencentral-yes-blue.svg)](https://search.maven.org/#search%7Cgav%7C1%7Cg%3A%22com.diffplug.spotless%22%20AND%20a%3A%22spotless-plugin-gradle%22) -[![Javadoc](https://img.shields.io/badge/javadoc-yes-blue.svg)](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.7.2/index.html) +[![Javadoc](https://img.shields.io/badge/javadoc-yes-blue.svg)](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.8.0/index.html) [![License Apache](https://img.shields.io/badge/license-apache-blue.svg)](https://tldrlegal.com/license/apache-license-2.0-(apache-2.0)) -[![Changelog](https://img.shields.io/badge/changelog-6.7.2-blue.svg)](CHANGES.md) +[![Changelog](https://img.shields.io/badge/changelog-6.8.0-blue.svg)](CHANGES.md) [![Circle CI](https://circleci.com/gh/diffplug/spotless/tree/main.svg?style=shield)](https://circleci.com/gh/diffplug/spotless/tree/main) [![Live chat](https://img.shields.io/badge/gitter-chat-brightgreen.svg)](https://gitter.im/diffplug/spotless) @@ -126,10 +126,10 @@ spotless { ``` Spotless consists of a list of formats (in the example above, `misc` and `java`), and each format has: -- a `target` (the files to format), which you set with [`target`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.7.2/com/diffplug/gradle/spotless/FormatExtension.html#target-java.lang.Object...-) and [`targetExclude`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.7.2/com/diffplug/gradle/spotless/FormatExtension.html#targetExclude-java.lang.Object...-) -- a list of `FormatterStep`, which are just `String -> String` functions, such as [`replace`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.7.2/com/diffplug/gradle/spotless/FormatExtension.html#replace-java.lang.String-java.lang.CharSequence-java.lang.CharSequence-), [`replaceRegex`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.7.2/com/diffplug/gradle/spotless/FormatExtension.html#replaceRegex-java.lang.String-java.lang.String-java.lang.String-), [`trimTrailingWhitespace`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.7.2/com/diffplug/gradle/spotless/FormatExtension.html#replace-java.lang.String-java.lang.CharSequence-java.lang.CharSequence-), [`custom`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.7.2/com/diffplug/gradle/spotless/FormatExtension.html#custom-java.lang.String-groovy.lang.Closure-), [`prettier`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.7.2/com/diffplug/gradle/spotless/FormatExtension.html#prettier--), [`eclipseWtp`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.7.2/com/diffplug/gradle/spotless/FormatExtension.html#eclipseWtp-com.diffplug.spotless.extra.wtp.EclipseWtpFormatterStep-), [`licenseHeader`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.7.2/com/diffplug/gradle/spotless/FormatExtension.html#licenseHeader-java.lang.String-java.lang.String-) etc. +- a `target` (the files to format), which you set with [`target`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.8.0/com/diffplug/gradle/spotless/FormatExtension.html#target-java.lang.Object...-) and [`targetExclude`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.8.0/com/diffplug/gradle/spotless/FormatExtension.html#targetExclude-java.lang.Object...-) +- a list of `FormatterStep`, which are just `String -> String` functions, such as [`replace`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.8.0/com/diffplug/gradle/spotless/FormatExtension.html#replace-java.lang.String-java.lang.CharSequence-java.lang.CharSequence-), [`replaceRegex`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.8.0/com/diffplug/gradle/spotless/FormatExtension.html#replaceRegex-java.lang.String-java.lang.String-java.lang.String-), [`trimTrailingWhitespace`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.8.0/com/diffplug/gradle/spotless/FormatExtension.html#replace-java.lang.String-java.lang.CharSequence-java.lang.CharSequence-), [`custom`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.8.0/com/diffplug/gradle/spotless/FormatExtension.html#custom-java.lang.String-groovy.lang.Closure-), [`prettier`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.8.0/com/diffplug/gradle/spotless/FormatExtension.html#prettier--), [`eclipseWtp`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.8.0/com/diffplug/gradle/spotless/FormatExtension.html#eclipseWtp-com.diffplug.spotless.extra.wtp.EclipseWtpFormatterStep-), [`licenseHeader`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.8.0/com/diffplug/gradle/spotless/FormatExtension.html#licenseHeader-java.lang.String-java.lang.String-) etc. -All the generic steps live in [`FormatExtension`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.7.2/com/diffplug/gradle/spotless/FormatExtension.html), and there are many language-specific steps which live in its language-specific subclasses, which are described below. +All the generic steps live in [`FormatExtension`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.8.0/com/diffplug/gradle/spotless/FormatExtension.html), and there are many language-specific steps which live in its language-specific subclasses, which are described below. ### Requirements @@ -141,7 +141,7 @@ If you're stuck on an older version of Gradle, `id 'com.diffplug.gradle.spotless ## Java -`com.diffplug.gradle.spotless.JavaExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.7.2/com/diffplug/gradle/spotless/JavaExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/JavaExtension.java) +`com.diffplug.gradle.spotless.JavaExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.8.0/com/diffplug/gradle/spotless/JavaExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/JavaExtension.java) ```gradle spotless { @@ -248,8 +248,8 @@ spotless { ## Groovy -- `com.diffplug.gradle.spotless.GroovyExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.7.2/com/diffplug/gradle/spotless/GroovyExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/GroovyExtension.java) -- `com.diffplug.gradle.spotless.GroovyGradleExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.7.2/com/diffplug/gradle/spotless/GroovyGradleExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/GroovyGradleExtension.java) +- `com.diffplug.gradle.spotless.GroovyExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.8.0/com/diffplug/gradle/spotless/GroovyExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/GroovyExtension.java) +- `com.diffplug.gradle.spotless.GroovyGradleExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.8.0/com/diffplug/gradle/spotless/GroovyGradleExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/GroovyGradleExtension.java) Configuration for Groovy is similar to [Java](#java), in that it also supports `licenseHeader` and `importOrder`. @@ -300,8 +300,8 @@ Groovy-Eclipse formatting errors/warnings lead per default to a build failure. T ## Kotlin -- `com.diffplug.gradle.spotless.KotlinExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.7.2/com/diffplug/gradle/spotless/KotlinExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/KotlinExtension.java) -- `com.diffplug.gradle.spotless.KotlinGradleExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.7.2/com/diffplug/gradle/spotless/KotlinGradleExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/KotlinGradleExtension.java) +- `com.diffplug.gradle.spotless.KotlinExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.8.0/com/diffplug/gradle/spotless/KotlinExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/KotlinExtension.java) +- `com.diffplug.gradle.spotless.KotlinGradleExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.8.0/com/diffplug/gradle/spotless/KotlinGradleExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/KotlinGradleExtension.java) ```gradle spotless { // if you are using build.gradle.kts, instead of 'spotless {' use: @@ -364,7 +364,7 @@ spotless { ## Scala -`com.diffplug.gradle.spotless.ScalaExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.7.2/com/diffplug/gradle/spotless/ScalaExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/ScalaExtension.java) +`com.diffplug.gradle.spotless.ScalaExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.8.0/com/diffplug/gradle/spotless/ScalaExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/ScalaExtension.java) ```gradle spotless { @@ -396,7 +396,7 @@ spotless { ## C/C++ -`com.diffplug.gradle.spotless.CppExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.7.2/com/diffplug/gradle/spotless/CppExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/CppExtension.java) +`com.diffplug.gradle.spotless.CppExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.8.0/com/diffplug/gradle/spotless/CppExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/CppExtension.java) ```gradle spotless { @@ -428,7 +428,7 @@ spotles { ## Python -`com.diffplug.gradle.spotless.PythonExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.7.2/com/diffplug/gradle/spotless/PythonExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/PythonExtension.java) +`com.diffplug.gradle.spotless.PythonExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.8.0/com/diffplug/gradle/spotless/PythonExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/PythonExtension.java) ```gradle spotless { @@ -462,7 +462,7 @@ black().pathToExe('C:/myuser/.pyenv/versions/3.8.0/scripts/black.exe') ## FreshMark -`com.diffplug.gradle.spotless.FreshMarkExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.7.2/com/diffplug/gradle/spotless/FreshMarkExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/FreshMarkExtension.java) +`com.diffplug.gradle.spotless.FreshMarkExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.8.0/com/diffplug/gradle/spotless/FreshMarkExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/FreshMarkExtension.java) [homepage](https://github.com/diffplug/freshmark). [changelog](https://github.com/diffplug/freshmark/blob/master/CHANGES.md). FreshMark lets you generate markdown in the comments of your markdown. This helps to keep badges and links up-to-date (see the source for this file), and can also be helpful for generating complex tables (see the source for [the parent readme](../README.md)). @@ -483,7 +483,7 @@ spotless { ## Antlr4 -`com.diffplug.gradle.spotless.Antlr4Extension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.7.2/com/diffplug/gradle/spotless/Antlr4Extension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/Antlr4Extension.java) +`com.diffplug.gradle.spotless.Antlr4Extension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.8.0/com/diffplug/gradle/spotless/Antlr4Extension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/Antlr4Extension.java) ```gradle spotless { @@ -508,7 +508,7 @@ antlr4formatter('1.2.1') // version is optional ## SQL -`com.diffplug.gradle.spotless.SqlExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.7.2/com/diffplug/gradle/spotless/SqlExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/SqlExtension.java) +`com.diffplug.gradle.spotless.SqlExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.8.0/com/diffplug/gradle/spotless/SqlExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/SqlExtension.java) ```gradle spotless { @@ -548,7 +548,7 @@ sql.formatter.indent.size=4 ## Typescript -- `com.diffplug.gradle.spotless.TypescriptExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.7.2/com/diffplug/gradle/spotless/TypescriptExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/TypescriptExtension.java) +- `com.diffplug.gradle.spotless.TypescriptExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.8.0/com/diffplug/gradle/spotless/TypescriptExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/TypescriptExtension.java) ```gradle spotless { @@ -591,7 +591,7 @@ For details, see the [npm detection](#npm-detection) and [`.npmrc` detection](#n ## JSON -- `com.diffplug.gradle.spotless.JsonExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.7.2/com/diffplug/gradle/spotless/JsonExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/JsonExtension.java) +- `com.diffplug.gradle.spotless.JsonExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.8.0/com/diffplug/gradle/spotless/JsonExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/JsonExtension.java) ```gradle spotless { @@ -816,7 +816,7 @@ Once a file's license header has a valid year, whether it is a year (`2020`) or * `2017` -> `2017-2020` * `2017-2019` -> `2017-2020` -See the [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.7.2/com/diffplug/gradle/spotless/FormatExtension.LicenseHeaderConfig.html) for a complete listing of options. +See the [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.8.0/com/diffplug/gradle/spotless/FormatExtension.LicenseHeaderConfig.html) for a complete listing of options. @@ -883,9 +883,9 @@ spotless { custom 'lowercase', { str -> str.toLowerCase() } ``` -However, custom rules will disable up-to-date checking and caching, unless you read [this javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.7.2/com/diffplug/gradle/spotless/FormatExtension.html#bumpThisNumberIfACustomStepChanges-int-) and follow its instructions carefully. +However, custom rules will disable up-to-date checking and caching, unless you read [this javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.8.0/com/diffplug/gradle/spotless/FormatExtension.html#bumpThisNumberIfACustomStepChanges-int-) and follow its instructions carefully. -Another option is to create proper `FormatterStep` in your `buildSrc`, and then call [`addStep`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.7.2/com/diffplug/gradle/spotless/FormatExtension.html#addStep-com.diffplug.spotless.FormatterStep-). The contributing guide describes [how to do this](https://github.com/diffplug/spotless/blob/main/CONTRIBUTING.md#how-to-add-a-new-formatterstep). If the step is generally-useful, we hope you'll open a PR to share it! +Another option is to create proper `FormatterStep` in your `buildSrc`, and then call [`addStep`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.8.0/com/diffplug/gradle/spotless/FormatExtension.html#addStep-com.diffplug.spotless.FormatterStep-). The contributing guide describes [how to do this](https://github.com/diffplug/spotless/blob/main/CONTRIBUTING.md#how-to-add-a-new-formatterstep). If the step is generally-useful, we hope you'll open a PR to share it! ```gradle @@ -918,11 +918,11 @@ spotless { format 'foo', com.acme.FooLanguageExtension, { ``` -If you'd like to create a one-off Spotless task outside of the `check`/`apply` framework, see [`FormatExtension.createIndependentApplyTask`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.7.2/com/diffplug/gradle/spotless/FormatExtension.html#createIndependentApplyTask-java.lang.String-). +If you'd like to create a one-off Spotless task outside of the `check`/`apply` framework, see [`FormatExtension.createIndependentApplyTask`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.8.0/com/diffplug/gradle/spotless/FormatExtension.html#createIndependentApplyTask-java.lang.String-). ## Inception (languages within languages within...) -In very rare cases, you might want to format e.g. javascript which is written inside JSP templates, or maybe java within a markdown file, or something wacky like that. You can specify hunks within a file using either open/close tags or a regex with a single capturing group, and then specify rules within it, like so. See [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.7.2/com/diffplug/gradle/spotless/FormatExtension.html#withinBlocks-java.lang.String-java.lang.String-java.lang.String-org.gradle.api.Action-) for more details. +In very rare cases, you might want to format e.g. javascript which is written inside JSP templates, or maybe java within a markdown file, or something wacky like that. You can specify hunks within a file using either open/close tags or a regex with a single capturing group, and then specify rules within it, like so. See [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.8.0/com/diffplug/gradle/spotless/FormatExtension.html#withinBlocks-java.lang.String-java.lang.String-java.lang.String-org.gradle.api.Action-) for more details. ```gradle import com.diffplug.gradle.spotless.JavaExtension From 8797048124a00aacd9359ff941cc4ddd7ba7b30f Mon Sep 17 00:00:00 2001 From: circleci Date: Thu, 30 Jun 2022 21:08:45 +0000 Subject: [PATCH 191/757] Published maven/2.23.0 --- plugin-maven/CHANGES.md | 2 ++ plugin-maven/README.md | 4 ++-- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/plugin-maven/CHANGES.md b/plugin-maven/CHANGES.md index 25ffe9f9e7..2cc389b7d3 100644 --- a/plugin-maven/CHANGES.md +++ b/plugin-maven/CHANGES.md @@ -3,6 +3,8 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format (starting after version `1.27.0`). ## [Unreleased] + +## [2.23.0] - 2022-06-30 ### Added * Support for `MAC_CLASSIC` (`\r`) line ending ([#1243](https://github.com/diffplug/spotless/pull/1243) fixes [#1196](https://github.com/diffplug/spotless/issues/1196)) ### Changes diff --git a/plugin-maven/README.md b/plugin-maven/README.md index c4aefd4289..e52d1ee540 100644 --- a/plugin-maven/README.md +++ b/plugin-maven/README.md @@ -12,8 +12,8 @@ output = [ ].join('\n'); --> [![Maven central](https://img.shields.io/badge/mavencentral-com.diffplug.spotless%3Aspotless--maven--plugin-blue.svg)](https://search.maven.org/#search%7Cgav%7C1%7Cg%3A%22com.diffplug.spotless%22%20AND%20a%3A%22spotless-maven-plugin%22) -[![Javadoc](https://img.shields.io/badge/javadoc-yes-blue.svg)](https://javadoc.io/doc/com.diffplug.spotless/spotless-maven-plugin/2.22.8/index.html) -[![Changelog](https://img.shields.io/badge/changelog-2.22.8-brightgreen.svg)](CHANGES.md) +[![Javadoc](https://img.shields.io/badge/javadoc-yes-blue.svg)](https://javadoc.io/doc/com.diffplug.spotless/spotless-maven-plugin/2.23.0/index.html) +[![Changelog](https://img.shields.io/badge/changelog-2.23.0-brightgreen.svg)](CHANGES.md) [![Circle CI](https://circleci.com/gh/diffplug/spotless/tree/main.svg?style=shield)](https://circleci.com/gh/diffplug/spotless/tree/main) [![Live chat](https://img.shields.io/badge/gitter-chat-brightgreen.svg)](https://gitter.im/diffplug/spotless) From a8037c3c5bdf773e88646b627aaac28ec1f864c8 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 4 Jul 2022 12:06:17 +0000 Subject: [PATCH 192/757] Bump com.github.spotbugs from 5.0.8 to 5.0.9 Bumps com.github.spotbugs from 5.0.8 to 5.0.9. --- updated-dependencies: - dependency-name: com.github.spotbugs dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] --- settings.gradle | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/settings.gradle b/settings.gradle index 13792d7260..2733fccd84 100644 --- a/settings.gradle +++ b/settings.gradle @@ -6,7 +6,7 @@ pluginManagement { // https://github.com/gradle-nexus/publish-plugin/releases id 'io.github.gradle-nexus.publish-plugin' version '1.1.0' // https://github.com/spotbugs/spotbugs-gradle-plugin/releases - id 'com.github.spotbugs' version '5.0.8' + id 'com.github.spotbugs' version '5.0.9' // https://github.com/diffplug/spotless-changelog id 'com.diffplug.spotless-changelog' version '2.3.2' // https://github.com/diffplug/goomph/blob/main/CHANGES.md From 8a42ae3028dcd6d5cb649bbaa0b04388f38d7f1f Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 4 Jul 2022 12:06:20 +0000 Subject: [PATCH 193/757] Bump com.gradle.plugin-publish from 0.21.0 to 1.0.0 Bumps com.gradle.plugin-publish from 0.21.0 to 1.0.0. --- updated-dependencies: - dependency-name: com.gradle.plugin-publish dependency-type: direct:production update-type: version-update:semver-major ... Signed-off-by: dependabot[bot] --- settings.gradle | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/settings.gradle b/settings.gradle index 13792d7260..d87a187b71 100644 --- a/settings.gradle +++ b/settings.gradle @@ -2,7 +2,7 @@ pluginManagement { plugins { id 'com.diffplug.spotless' version '6.5.0' // https://plugins.gradle.org/plugin/com.gradle.plugin-publish - id 'com.gradle.plugin-publish' version '0.21.0' + id 'com.gradle.plugin-publish' version '1.0.0' // https://github.com/gradle-nexus/publish-plugin/releases id 'io.github.gradle-nexus.publish-plugin' version '1.1.0' // https://github.com/spotbugs/spotbugs-gradle-plugin/releases From 1cbe523dba200baedf98f676ab3d9ead1950e276 Mon Sep 17 00:00:00 2001 From: bh-tt Date: Mon, 11 Jul 2022 16:44:24 +0200 Subject: [PATCH 194/757] Lazily check for foreign exes which may not be necessary for the current build --- .../spotless/cpp/ClangFormatStep.java | 56 ++++++++++--------- .../diffplug/spotless/python/BlackStep.java | 18 +++--- 2 files changed, 40 insertions(+), 34 deletions(-) diff --git a/lib/src/main/java/com/diffplug/spotless/cpp/ClangFormatStep.java b/lib/src/main/java/com/diffplug/spotless/cpp/ClangFormatStep.java index 5256739004..e038aaec90 100644 --- a/lib/src/main/java/com/diffplug/spotless/cpp/ClangFormatStep.java +++ b/lib/src/main/java/com/diffplug/spotless/cpp/ClangFormatStep.java @@ -21,6 +21,7 @@ import java.nio.charset.StandardCharsets; import java.util.ArrayList; import java.util.List; +import java.util.Objects; import javax.annotation.Nullable; @@ -68,21 +69,20 @@ public FormatterStep create() { private State createState() throws IOException, InterruptedException { String howToInstall = "" + - "You can download clang-format from https://releases.llvm.org and " + - "then point Spotless to it with {@code pathToExe('/path/to/clang-format')} " + - "or you can use your platform's package manager:" + - "\n win: choco install llvm --version {version} (try dropping version if it fails)" + - "\n mac: brew install clang-format (TODO: how to specify version?)" + - "\n linux: apt install clang-format (try clang-format-{version} with dropped minor versions)" + - "\n github issue to handle this better: https://github.com/diffplug/spotless/issues/673"; - String exeAbsPath = ForeignExe.nameAndVersion("clang-format", version) - .pathToExe(pathToExe) - .fixCantFind(howToInstall) - .fixWrongVersion( - "You can tell Spotless to use the version you already have with {@code clangFormat('{versionFound}')}" + - "or you can download the currently specified version, {version}.\n" + howToInstall) - .confirmVersionAndGetAbsolutePath(); - return new State(this, exeAbsPath); + "You can download clang-format from https://releases.llvm.org and " + + "then point Spotless to it with {@code pathToExe('/path/to/clang-format')} " + + "or you can use your platform's package manager:" + + "\n win: choco install llvm --version {version} (try dropping version if it fails)" + + "\n mac: brew install clang-format (TODO: how to specify version?)" + + "\n linux: apt install clang-format (try clang-format-{version} with dropped minor versions)" + + "\n github issue to handle this better: https://github.com/diffplug/spotless/issues/673"; + final ForeignExe exe = ForeignExe.nameAndVersion("clang-format", version) + .pathToExe(pathToExe) + .fixCantFind(howToInstall) + .fixWrongVersion( + "You can tell Spotless to use the version you already have with {@code clangFormat('{versionFound}')}" + + "or you can download the currently specified version, {version}.\n" + howToInstall); + return new State(this, exe); } @SuppressFBWarnings("SE_TRANSIENT_FIELD_NOT_RESTORED") @@ -91,24 +91,28 @@ static class State implements Serializable { // used for up-to-date checks and caching final String version; final @Nullable String style; + final ForeignExe exe; // used for executing - final transient List args; + private @Nullable List args; - State(ClangFormatStep step, String exeAbsPath) { + State(ClangFormatStep step, ForeignExe pathToExe) { this.version = step.version; this.style = step.style; - args = new ArrayList<>(2); - args.add(exeAbsPath); - if (style != null) { - args.add("--style=" + style); - } + this.exe = Objects.requireNonNull(pathToExe); } String format(ProcessRunner runner, String input, File file) throws IOException, InterruptedException { - String[] processArgs = args.toArray(new String[args.size() + 1]); - // add an argument to the end - processArgs[args.size()] = "--assume-filename=" + file.getName(); - return runner.exec(input.getBytes(StandardCharsets.UTF_8), processArgs).assertExitZero(StandardCharsets.UTF_8); + if (args == null) { + final List tmpArgs = new ArrayList<>(); + tmpArgs.add(exe.confirmVersionAndGetAbsolutePath()); + if (style != null) { + tmpArgs.add("--style="+ style); + } + args = tmpArgs; + } + final String[] processArgs = args.toArray(new String[args.size() + 1]); + processArgs[processArgs.length - 1] = "--assume-filename=" + file.getName(); + return runner.exec(input.getBytes(StandardCharsets.UTF_8), args).assertExitZero(StandardCharsets.UTF_8); } FormatterFunc.Closeable toFunc() { 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 6a03d0d808..b3f0c434f3 100644 --- a/lib/src/main/java/com/diffplug/spotless/python/BlackStep.java +++ b/lib/src/main/java/com/diffplug/spotless/python/BlackStep.java @@ -18,8 +18,7 @@ import java.io.IOException; import java.io.Serializable; import java.nio.charset.StandardCharsets; -import java.util.Arrays; -import java.util.List; +import java.util.Objects; import java.util.regex.Pattern; import javax.annotation.Nullable; @@ -62,12 +61,11 @@ public FormatterStep create() { 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) + ForeignExe exeAbsPath = ForeignExe.nameAndVersion("black", version) .pathToExe(pathToExe) .versionRegex(Pattern.compile("(?:black, version|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(); + .fixWrongVersion("Try running {@code pip install --force-reinstall black=={version}}, or else specify {@code black('{versionFound}')} to Spotless" + trackingIssue); return new State(this, exeAbsPath); } @@ -76,15 +74,19 @@ static class State implements Serializable { private static final long serialVersionUID = -1825662356883926318L; // used for up-to-date checks and caching final String version; + final ForeignExe exe; // used for executing - final transient List args; + private @Nullable String[] args; - State(BlackStep step, String exeAbsPath) { + State(BlackStep step, ForeignExe exeAbsPath) { this.version = step.version; - this.args = Arrays.asList(exeAbsPath, "-"); + this.exe = Objects.requireNonNull(exeAbsPath); } String format(ProcessRunner runner, String input) throws IOException, InterruptedException { + if (args == null) { + args = new String[] {exe.confirmVersionAndGetAbsolutePath(), "-"}; + } return runner.exec(input.getBytes(StandardCharsets.UTF_8), args).assertExitZero(StandardCharsets.UTF_8); } From 387b14db43054b4c2b2d2b01e1b0c9cccaff9394 Mon Sep 17 00:00:00 2001 From: bh-tt Date: Mon, 11 Jul 2022 16:50:14 +0200 Subject: [PATCH 195/757] Add to CHANGES.md --- CHANGES.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGES.md b/CHANGES.md index 7f6160b600..90b9ed95b3 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -20,6 +20,7 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format ( * Bump default `diktat` version to latest `1.1.0` -> `1.2.1` ([#1246](https://github.com/diffplug/spotless/pull/1246)) * Minimum supported version also bumped to `1.2.1` (diktat is based on ktlint and has the same backward compatibility issues). * Bump default `ktfmt` version to latest `0.37` -> `0.39` ([#1240](https://github.com/diffplug/spotless/pull/1240)) +* Clang and Black no longer break the build when the binary is unavailable, if they will not be run during that build ([#1257](https://github.com/diffplug/spotless/pull/1257)) ## [2.26.2] - 2022-06-11 ### Fixed From 2338473edf8086c4d54b5053ffd89208c923d88c Mon Sep 17 00:00:00 2001 From: bh-tt Date: Wed, 13 Jul 2022 08:54:00 +0200 Subject: [PATCH 196/757] Transient State fields, fix CHANGES --- CHANGES.md | 4 ++-- .../main/java/com/diffplug/spotless/cpp/ClangFormatStep.java | 4 ++-- lib/src/main/java/com/diffplug/spotless/python/BlackStep.java | 4 ++-- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/CHANGES.md b/CHANGES.md index 90b9ed95b3..4b0b1b0e2f 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -10,7 +10,8 @@ This document is intended for Spotless developers. We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format (starting after version `1.27.0`). ## [Unreleased] - +### Added +* Clang and Black no longer break the build when the binary is unavailable, if they will not be run during that build ([#1257](https://github.com/diffplug/spotless/pull/1257)) ## [2.27.0] - 2022-06-30 ### Added * Support for `MAC_CLASSIC` (`\r`) line ending ([#1243](https://github.com/diffplug/spotless/pull/1243) fixes [#1196](https://github.com/diffplug/spotless/issues/1196)) @@ -20,7 +21,6 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format ( * Bump default `diktat` version to latest `1.1.0` -> `1.2.1` ([#1246](https://github.com/diffplug/spotless/pull/1246)) * Minimum supported version also bumped to `1.2.1` (diktat is based on ktlint and has the same backward compatibility issues). * Bump default `ktfmt` version to latest `0.37` -> `0.39` ([#1240](https://github.com/diffplug/spotless/pull/1240)) -* Clang and Black no longer break the build when the binary is unavailable, if they will not be run during that build ([#1257](https://github.com/diffplug/spotless/pull/1257)) ## [2.26.2] - 2022-06-11 ### Fixed diff --git a/lib/src/main/java/com/diffplug/spotless/cpp/ClangFormatStep.java b/lib/src/main/java/com/diffplug/spotless/cpp/ClangFormatStep.java index e038aaec90..aced507ee5 100644 --- a/lib/src/main/java/com/diffplug/spotless/cpp/ClangFormatStep.java +++ b/lib/src/main/java/com/diffplug/spotless/cpp/ClangFormatStep.java @@ -91,9 +91,9 @@ static class State implements Serializable { // used for up-to-date checks and caching final String version; final @Nullable String style; - final ForeignExe exe; + final transient ForeignExe exe; // used for executing - private @Nullable List args; + private transient @Nullable List args; State(ClangFormatStep step, ForeignExe pathToExe) { this.version = step.version; 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 b3f0c434f3..bf98a3a091 100644 --- a/lib/src/main/java/com/diffplug/spotless/python/BlackStep.java +++ b/lib/src/main/java/com/diffplug/spotless/python/BlackStep.java @@ -74,9 +74,9 @@ static class State implements Serializable { private static final long serialVersionUID = -1825662356883926318L; // used for up-to-date checks and caching final String version; - final ForeignExe exe; + final transient ForeignExe exe; // used for executing - private @Nullable String[] args; + private transient @Nullable String[] args; State(BlackStep step, ForeignExe exeAbsPath) { this.version = step.version; From 82353fd251ccce18c2eb5f2cf900775270513d16 Mon Sep 17 00:00:00 2001 From: Ned Twigg Date: Tue, 26 Jul 2022 16:17:59 -0700 Subject: [PATCH 197/757] spotlessApply --- .../spotless/cpp/ClangFormatStep.java | 30 +++++++++---------- .../diffplug/spotless/python/BlackStep.java | 2 +- 2 files changed, 16 insertions(+), 16 deletions(-) diff --git a/lib/src/main/java/com/diffplug/spotless/cpp/ClangFormatStep.java b/lib/src/main/java/com/diffplug/spotless/cpp/ClangFormatStep.java index aced507ee5..2bff28e64e 100644 --- a/lib/src/main/java/com/diffplug/spotless/cpp/ClangFormatStep.java +++ b/lib/src/main/java/com/diffplug/spotless/cpp/ClangFormatStep.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. @@ -69,19 +69,19 @@ public FormatterStep create() { private State createState() throws IOException, InterruptedException { String howToInstall = "" + - "You can download clang-format from https://releases.llvm.org and " + - "then point Spotless to it with {@code pathToExe('/path/to/clang-format')} " + - "or you can use your platform's package manager:" + - "\n win: choco install llvm --version {version} (try dropping version if it fails)" + - "\n mac: brew install clang-format (TODO: how to specify version?)" + - "\n linux: apt install clang-format (try clang-format-{version} with dropped minor versions)" + - "\n github issue to handle this better: https://github.com/diffplug/spotless/issues/673"; - final ForeignExe exe = ForeignExe.nameAndVersion("clang-format", version) - .pathToExe(pathToExe) - .fixCantFind(howToInstall) - .fixWrongVersion( - "You can tell Spotless to use the version you already have with {@code clangFormat('{versionFound}')}" + - "or you can download the currently specified version, {version}.\n" + howToInstall); + "You can download clang-format from https://releases.llvm.org and " + + "then point Spotless to it with {@code pathToExe('/path/to/clang-format')} " + + "or you can use your platform's package manager:" + + "\n win: choco install llvm --version {version} (try dropping version if it fails)" + + "\n mac: brew install clang-format (TODO: how to specify version?)" + + "\n linux: apt install clang-format (try clang-format-{version} with dropped minor versions)" + + "\n github issue to handle this better: https://github.com/diffplug/spotless/issues/673"; + final ForeignExe exe = ForeignExe.nameAndVersion("clang-format", version) + .pathToExe(pathToExe) + .fixCantFind(howToInstall) + .fixWrongVersion( + "You can tell Spotless to use the version you already have with {@code clangFormat('{versionFound}')}" + + "or you can download the currently specified version, {version}.\n" + howToInstall); return new State(this, exe); } @@ -106,7 +106,7 @@ String format(ProcessRunner runner, String input, File file) throws IOException, final List tmpArgs = new ArrayList<>(); tmpArgs.add(exe.confirmVersionAndGetAbsolutePath()); if (style != null) { - tmpArgs.add("--style="+ style); + tmpArgs.add("--style=" + style); } args = tmpArgs; } 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 bf98a3a091..9bce2241dd 100644 --- a/lib/src/main/java/com/diffplug/spotless/python/BlackStep.java +++ b/lib/src/main/java/com/diffplug/spotless/python/BlackStep.java @@ -85,7 +85,7 @@ static class State implements Serializable { String format(ProcessRunner runner, String input) throws IOException, InterruptedException { if (args == null) { - args = new String[] {exe.confirmVersionAndGetAbsolutePath(), "-"}; + args = new String[]{exe.confirmVersionAndGetAbsolutePath(), "-"}; } return runner.exec(input.getBytes(StandardCharsets.UTF_8), args).assertExitZero(StandardCharsets.UTF_8); } From 1ab9b311c8a308dc79cff3fa72069708c21e92a4 Mon Sep 17 00:00:00 2001 From: Ned Twigg Date: Tue, 26 Jul 2022 16:22:54 -0700 Subject: [PATCH 198/757] Update changelogs. --- CHANGES.md | 3 ++- plugin-gradle/CHANGES.md | 2 ++ plugin-maven/CHANGES.md | 2 ++ 3 files changed, 6 insertions(+), 1 deletion(-) diff --git a/CHANGES.md b/CHANGES.md index 4b0b1b0e2f..bed2af6281 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -11,7 +11,8 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format ( ## [Unreleased] ### Added -* Clang and Black no longer break the build when the binary is unavailable, if they will not be run during that build ([#1257](https://github.com/diffplug/spotless/pull/1257)) +* Clang and Black no longer break the build when the binary is unavailable, if they will not be run during that build ([#1257](https://github.com/diffplug/spotless/pull/1257)). + ## [2.27.0] - 2022-06-30 ### Added * Support for `MAC_CLASSIC` (`\r`) line ending ([#1243](https://github.com/diffplug/spotless/pull/1243) fixes [#1196](https://github.com/diffplug/spotless/issues/1196)) diff --git a/plugin-gradle/CHANGES.md b/plugin-gradle/CHANGES.md index 02d8da736d..43a1fb1d24 100644 --- a/plugin-gradle/CHANGES.md +++ b/plugin-gradle/CHANGES.md @@ -3,6 +3,8 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format (starting after version `3.27.0`). ## [Unreleased] +### Added +* Clang and Black no longer break the build when the binary is unavailable, if they will not be run during that build ([#1257](https://github.com/diffplug/spotless/pull/1257)). ## [6.8.0] - 2022-06-30 ### Added diff --git a/plugin-maven/CHANGES.md b/plugin-maven/CHANGES.md index 2cc389b7d3..3499aeab36 100644 --- a/plugin-maven/CHANGES.md +++ b/plugin-maven/CHANGES.md @@ -3,6 +3,8 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format (starting after version `1.27.0`). ## [Unreleased] +### Added +* Clang and Black no longer break the build when the binary is unavailable, if they will not be run during that build ([#1257](https://github.com/diffplug/spotless/pull/1257)). ## [2.23.0] - 2022-06-30 ### Added From aafd5fd1bb38ed88170394b5d21b3307fb1d0590 Mon Sep 17 00:00:00 2001 From: Stian Steinbakken Date: Wed, 27 Jul 2022 01:26:48 +0200 Subject: [PATCH 199/757] docs: update ktfmt comment with all available options (#1252) --- plugin-maven/README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/plugin-maven/README.md b/plugin-maven/README.md index e52d1ee540..1552c98537 100644 --- a/plugin-maven/README.md +++ b/plugin-maven/README.md @@ -329,8 +329,8 @@ Groovy-Eclipse formatting errors/warnings lead per default to a build failure. T ```xml - 0.30 - + 0.39 + ``` From 5ac80236c8d20b5ac68c00565a7261e53cb49294 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Necati=20S=C3=B6zer?= <32370872+necatisozer@users.noreply.github.com> Date: Wed, 27 Jul 2022 02:27:48 +0300 Subject: [PATCH 200/757] Fix XML config typo in plugin-gradle README (#1259) --- plugin-gradle/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugin-gradle/README.md b/plugin-gradle/README.md index 5301b4287c..1e103a0a81 100644 --- a/plugin-gradle/README.md +++ b/plugin-gradle/README.md @@ -758,7 +758,7 @@ spotless { ```gradle spotless { format 'xml', { - target 'src/**/*/xml' // must specify target + target 'src/**/*.xml' // must specify target eclipseWtp('xml') // must specify a type (table below) eclipseWtp('xml', '4.13.0') // optional version // you can also specify an arbitrary number of config files From 018cb6619babf4af6d608f6683d228df804eeadb Mon Sep 17 00:00:00 2001 From: Ned Twigg Date: Tue, 26 Jul 2022 16:52:56 -0700 Subject: [PATCH 201/757] Bump from Gradle 7.3 -> 7.5 --- gradle/wrapper/gradle-wrapper.jar | Bin 59203 -> 59536 bytes gradle/wrapper/gradle-wrapper.properties | 2 +- gradlew | 257 ++++++++++++++--------- 3 files changed, 154 insertions(+), 105 deletions(-) diff --git a/gradle/wrapper/gradle-wrapper.jar b/gradle/wrapper/gradle-wrapper.jar index e708b1c023ec8b20f512888fe07c5bd3ff77bb8f..7454180f2ae8848c63b8b4dea2cb829da983f2fa 100755 GIT binary patch delta 18435 zcmY&<19zBR)MXm8v2EM7ZQHi-#I|kQZfv7Tn#Q)%81v4zX3d)U4d4 zYYc!v@NU%|U;_sM`2z(4BAilWijmR>4U^KdN)D8%@2KLcqkTDW%^3U(Wg>{qkAF z&RcYr;D1I5aD(N-PnqoEeBN~JyXiT(+@b`4Pv`;KmkBXYN48@0;iXuq6!ytn`vGp$ z6X4DQHMx^WlOek^bde&~cvEO@K$oJ}i`T`N;M|lX0mhmEH zuRpo!rS~#&rg}ajBdma$$}+vEhz?JAFUW|iZEcL%amAg_pzqul-B7Itq6Y_BGmOCC zX*Bw3rFz3R)DXpCVBkI!SoOHtYstv*e-May|+?b80ZRh$MZ$FerlC`)ZKt} zTd0Arf9N2dimjs>mg5&@sfTPsRXKXI;0L~&t+GH zkB<>wxI9D+k5VHHcB7Rku{Z>i3$&hgd9Mt_hS_GaGg0#2EHzyV=j=u5xSyV~F0*qs zW{k9}lFZ?H%@4hII_!bzao!S(J^^ZZVmG_;^qXkpJb7OyR*sPL>))Jx{K4xtO2xTr@St!@CJ=y3q2wY5F`77Tqwz8!&Q{f7Dp zifvzVV1!Dj*dxG%BsQyRP6${X+Tc$+XOG zzvq5xcC#&-iXlp$)L=9t{oD~bT~v^ZxQG;FRz|HcZj|^L#_(VNG)k{=_6|6Bs-tRNCn-XuaZ^*^hpZ@qwi`m|BxcF6IWc?_bhtK_cDZRTw#*bZ2`1@1HcB`mLUmo_>@2R&nj7&CiH zF&laHkG~7#U>c}rn#H)q^|sk+lc!?6wg0xy`VPn!{4P=u@cs%-V{VisOxVqAR{XX+ zw}R;{Ux@6A_QPka=48|tph^^ZFjSHS1BV3xfrbY84^=?&gX=bmz(7C({=*oy|BEp+ zYgj;<`j)GzINJA>{HeSHC)bvp6ucoE`c+6#2KzY9)TClmtEB1^^Mk)(mXWYvup02e%Ghm9qyjz#fO3bNGBX} zFiB>dvc1+If!>I10;qZk`?6pEd*(?bI&G*3YLt;MWw&!?=Mf7%^Op?qnyXWur- zwX|S^P>jF?{m9c&mmK-epCRg#WB+-VDe!2d2~YVoi%7_q(dyC{(}zB${!ElKB2D}P z7QNFM!*O^?FrPMGZ}wQ0TrQAVqZy!weLhu_Zq&`rlD39r*9&2sJHE(JT0EY5<}~x@ z1>P0!L2IFDqAB!($H9s2fI`&J_c+5QT|b#%99HA3@zUWOuYh(~7q7!Pf_U3u!ij5R zjFzeZta^~RvAmd_TY+RU@e}wQaB_PNZI26zmtzT4iGJg9U(Wrgrl>J%Z3MKHOWV(? zj>~Ph$<~8Q_sI+)$DOP^9FE6WhO09EZJ?1W|KidtEjzBX3RCLUwmj9qH1CM=^}MaK z59kGxRRfH(n|0*lkE?`Rpn6d^u5J6wPfi0WF(rucTv(I;`aW)3;nY=J=igkjsn?ED ztH&ji>}TW8)o!Jg@9Z}=i2-;o4#xUksQHu}XT~yRny|kg-$Pqeq!^78xAz2mYP9+4 z9gwAoti2ICvUWxE&RZ~}E)#M8*zy1iwz zHqN%q;u+f6Ti|SzILm0s-)=4)>eb5o-0K zbMW8ecB4p^6OuIX@u`f{>Yn~m9PINEl#+t*jqalwxIx=TeGB9(b6jA}9VOHnE$9sC zH`;epyH!k-3kNk2XWXW!K`L_G!%xOqk0ljPCMjK&VweAxEaZ==cT#;!7)X&C|X{dY^IY(e4D#!tx^vV3NZqK~--JW~wtXJ8X19adXim?PdN(|@o(OdgH3AiHts~?#QkolO?*=U_buYC&tQ3sc(O5HGHN~=6wB@dgIAVT$ z_OJWJ^&*40Pw&%y^t8-Wn4@l9gOl`uU z{Uda_uk9!Iix?KBu9CYwW9Rs=yt_lE11A+k$+)pkY5pXpocxIEJe|pTxwFgB%Kpr&tH;PzgOQ&m|(#Otm?@H^r`v)9yiR8v&Uy>d#TNdRfyN4Jk;`g zp+jr5@L2A7TS4=G-#O<`A9o;{En5!I8lVUG?!PMsv~{E_yP%QqqTxxG%8%KxZ{uwS zOT+EA5`*moN8wwV`Z=wp<3?~f#frmID^K?t7YL`G^(X43gWbo!6(q*u%HxWh$$^2EOq`Hj zp=-fS#Av+s9r-M)wGIggQ)b<@-BR`R8l1G@2+KODmn<_$Tzb7k35?e8;!V0G>`(!~ zY~qZz!6*&|TupOcnvsQYPbcMiJ!J{RyfezB^;fceBk znpA1XS)~KcC%0^_;ihibczSxwBuy;^ksH7lwfq7*GU;TLt*WmUEVQxt{ zKSfJf;lk$0XO8~48Xn2dnh8tMC9WHu`%DZj&a`2!tNB`5%;Md zBs|#T0Ktf?vkWQ)Y+q!At1qgL`C|nbzvgc(+28Q|4N6Geq)Il%+I5c@t02{9^=QJ?=h2BTe`~BEu=_u3xX2&?^zwcQWL+)7dI>JK0g8_`W1n~ zMaEP97X>Ok#=G*nkPmY`VoP8_{~+Rp7DtdSyWxI~?TZHxJ&=6KffcO2Qx1?j7=LZA z?GQt`oD9QpXw+s7`t+eeLO$cpQpl9(6h3_l9a6OUpbwBasCeCw^UB6we!&h9Ik@1zvJ`j4i=tvG9X8o34+N|y(ay~ho$f=l z514~mP>Z>#6+UxM<6@4z*|hFJ?KnkQBs_9{H(-v!_#Vm6Z4(xV5WgWMd3mB9A(>@XE292#k(HdI7P zJkQ2)`bQXTKlr}{VrhSF5rK9TsjtGs0Rs&nUMcH@$ZX_`Hh$Uje*)(Wd&oLW($hZQ z_tPt`{O@f8hZ<}?aQc6~|9iHt>=!%We3=F9yIfiqhXqp=QUVa!@UY@IF5^dr5H8$R zIh{=%S{$BHG+>~a=vQ={!B9B=<-ID=nyjfA0V8->gN{jRL>Qc4Rc<86;~aY+R!~Vs zV7MI~gVzGIY`B*Tt@rZk#Lg}H8sL39OE31wr_Bm%mn}8n773R&N)8B;l+-eOD@N$l zh&~Wz`m1qavVdxwtZLACS(U{rAa0;}KzPq9r76xL?c{&GaG5hX_NK!?)iq`t7q*F# zFoKI{h{*8lb>&sOeHXoAiqm*vV6?C~5U%tXR8^XQ9Y|(XQvcz*>a?%HQ(Vy<2UhNf zVmGeOO#v159KV@1g`m%gJ)XGPLa`a|?9HSzSSX{j;)xg>G(Ncc7+C>AyAWYa(k}5B3mtzg4tsA=C^Wfezb1&LlyrBE1~kNfeiubLls{C)!<%#m@f}v^o+7<VZ6!FZ;JeiAG@5vw7Li{flC8q1%jD_WP2ApBI{fQ}kN zhvhmdZ0bb5(qK@VS5-)G+@GK(tuF6eJuuV5>)Odgmt?i_`tB69DWpC~e8gqh!>jr_ zL1~L0xw@CbMSTmQflpRyjif*Y*O-IVQ_OFhUw-zhPrXXW>6X}+73IoMsu2?uuK3lT>;W#38#qG5tDl66A7Y{mYh=jK8Se!+f=N7%nv zYSHr6a~Nxd`jqov9VgII{%EpC_jFCEc>>SND0;}*Ja8Kv;G)MK7?T~h((c&FEBcQq zvUU1hW2^TX(dDCeU@~a1LF-(+#lz3997A@pipD53&Dr@III2tlw>=!iGabjXzbyUJ z4Hi~M1KCT-5!NR#I%!2Q*A>mqI{dpmUa_mW)%SDs{Iw1LG}0y=wbj@0ba-`q=0!`5 zr(9q1p{#;Rv2CY!L#uTbs(UHVR5+hB@m*zEf4jNu3(Kj$WwW|v?YL*F_0x)GtQC~! zzrnZRmBmwt+i@uXnk05>uR5&1Ddsx1*WwMrIbPD3yU*2By`71pk@gt{|H0D<#B7&8 z2dVmXp*;B)SWY)U1VSNs4ds!yBAj;P=xtatUx^7_gC5tHsF#vvdV;NmKwmNa1GNWZ zi_Jn-B4GnJ%xcYWD5h$*z^haku#_Irh818x^KB)3-;ufjf)D0TE#6>|zFf@~pU;Rs zNw+}c9S+6aPzxkEA6R%s*xhJ37wmgc)-{Zd1&mD5QT}4BQvczWr-Xim>(P^)52`@R z9+Z}44203T5}`AM_G^Snp<_KKc!OrA(5h7{MT^$ZeDsSr(R@^kI?O;}QF)OU zQ9-`t^ys=6DzgLcWt0U{Q(FBs22=r zKD%fLQ^5ZF24c-Z)J{xv?x$&4VhO^mswyb4QTIofCvzq+27*WlYm;h@;Bq%i;{hZA zM97mHI6pP}XFo|^pRTuWQzQs3B-8kY@ajLV!Fb?OYAO3jFv*W-_;AXd;G!CbpZt04iW`Ie^_+cQZGY_Zd@P<*J9EdRsc>c=edf$K|;voXRJ zk*aC@@=MKwR120(%I_HX`3pJ+8GMeO>%30t?~uXT0O-Tu-S{JA;zHoSyXs?Z;fy58 zi>sFtI7hoxNAdOt#3#AWFDW)4EPr4kDYq^`s%JkuO7^efX+u#-qZ56aoRM!tC^P6O zP(cFuBnQGjhX(^LJ(^rVe4-_Vk*3PkBCj!?SsULdmVr0cGJM^=?8b0^DuOFq>0*yA zk1g|C7n%pMS0A8@Aintd$fvRbH?SNdRaFrfoAJ=NoX)G5Gr}3-$^IGF+eI&t{I-GT zp=1fj)2|*ur1Td)+s&w%p#E6tDXX3YYOC{HGHLiCvv?!%%3DO$B$>A}aC;8D0Ef#b z{7NNqC8j+%1n95zq8|hFY`afAB4E)w_&7?oqG0IPJZv)lr{MT}>9p?}Y`=n+^CZ6E zKkjIXPub5!82(B-O2xQojW^P(#Q*;ETpEr^+Wa=qDJ9_k=Wm@fZB6?b(u?LUzX(}+ zE6OyapdG$HC& z&;oa*ALoyIxVvB2cm_N&h&{3ZTuU|aBrJlGOLtZc3KDx)<{ z27@)~GtQF@%6B@w3emrGe?Cv_{iC@a#YO8~OyGRIvp@%RRKC?fclXMP*6GzBFO z5U4QK?~>AR>?KF@I;|(rx(rKxdT9-k-anYS+#S#e1SzKPslK!Z&r8iomPsWG#>`Ld zJ<#+8GFHE!^wsXt(s=CGfVz5K+FHYP5T0E*?0A-z*lNBf)${Y`>Gwc@?j5{Q|6;Bl zkHG1%r$r&O!N^><8AEL+=y(P$7E6hd=>BZ4ZZ9ukJ2*~HR4KGvUR~MUOe$d>E5UK3 z*~O2LK4AnED}4t1Fs$JgvPa*O+WeCji_cn1@Tv7XQ6l@($F1K%{E$!naeX)`bfCG> z8iD<%_M6aeD?a-(Qqu61&fzQqC(E8ksa%CulMnPvR35d{<`VsmaHyzF+B zF6a@1$CT0xGVjofcct4SyxA40uQ`b#9kI)& z?B67-12X-$v#Im4CVUGZHXvPWwuspJ610ITG*A4xMoRVXJl5xbk;OL(;}=+$9?H`b z>u2~yd~gFZ*V}-Q0K6E@p}mtsri&%Zep?ZrPJmv`Qo1>94Lo||Yl)nqwHXEbe)!g( zo`w|LU@H14VvmBjjkl~=(?b{w^G$~q_G(HL`>|aQR%}A64mv0xGHa`S8!*Wb*eB}` zZh)&rkjLK!Rqar)UH)fM<&h&@v*YyOr!Xk2OOMV%$S2mCRdJxKO1RL7xP_Assw)bb z9$sQ30bapFfYTS`i1PihJZYA#0AWNmp>x(;C!?}kZG7Aq?zp!B+gGyJ^FrXQ0E<>2 zCjqZ(wDs-$#pVYP3NGA=en<@_uz!FjFvn1&w1_Igvqs_sL>ExMbcGx4X5f%`Wrri@ z{&vDs)V!rd=pS?G(ricfwPSg(w<8P_6=Qj`qBC7_XNE}1_5>+GBjpURPmvTNE7)~r)Y>ZZecMS7Ro2` z0}nC_GYo3O7j|Wux?6-LFZs%1IV0H`f`l9or-8y0=5VGzjPqO2cd$RRHJIY06Cnh- ztg@Pn1OeY=W`1Mv3`Ti6!@QIT{qcC*&vptnX4Pt1O|dWv8u2s|(CkV`)vBjAC_U5` zCw1f&c4o;LbBSp0=*q z3Y^horBAnR)u=3t?!}e}14%K>^562K!)Vy6r~v({5{t#iRh8WIL|U9H6H97qX09xp zjb0IJ^9Lqxop<-P*VA0By@In*5dq8Pr3bTPu|ArID*4tWM7w+mjit0PgmwLV4&2PW z3MnIzbdR`3tPqtUICEuAH^MR$K_u8~-U2=N1)R=l>zhygus44>6V^6nJFbW-`^)f} zI&h$FK)Mo*x?2`0npTD~jRd}5G~-h8=wL#Y-G+a^C?d>OzsVl7BFAaM==(H zR;ARWa^C3J)`p~_&FRsxt|@e+M&!84`eq)@aO9yBj8iifJv0xVW4F&N-(#E=k`AwJ z3EFXWcpsRlB%l_0Vdu`0G(11F7( zsl~*@XP{jS@?M#ec~%Pr~h z2`M*lIQaolzWN&;hkR2*<=!ORL(>YUMxOzj(60rQfr#wTrkLO!t{h~qg% zv$R}0IqVIg1v|YRu9w7RN&Uh7z$ijV=3U_M(sa`ZF=SIg$uY|=NdC-@%HtkUSEqJv zg|c}mKTCM=Z8YmsFQu7k{VrXtL^!Cts-eb@*v0B3M#3A7JE*)MeW1cfFqz~^S6OXFOIP&iL;Vpy z4dWKsw_1Wn%Y;eW1YOfeP_r1s4*p1C(iDG_hrr~-I%kA>ErxnMWRYu{IcG{sAW;*t z9T|i4bI*g)FXPpKM@~!@a7LDVVGqF}C@mePD$ai|I>73B+9!Ks7W$pw;$W1B%-rb; zJ*-q&ljb=&41dJ^*A0)7>Wa@khGZ;q1fL(2qW=|38j43mTl_;`PEEw07VKY%71l6p z@F|jp88XEnm1p~<5c*cVXvKlj0{THF=n3sU7g>Ki&(ErR;!KSmfH=?49R5(|c_*xw z4$jhCJ1gWT6-g5EV)Ahg?Nw=}`iCyQ6@0DqUb%AZEM^C#?B-@Hmw?LhJ^^VU>&phJ zlB!n5&>I>@sndh~v$2I2Ue23F?0!0}+9H~jg7E`?CS_ERu75^jSwm%!FTAegT`6s7 z^$|%sj2?8wtPQR>@D3sA0-M-g-vL@47YCnxdvd|1mPymvk!j5W1jHnVB&F-0R5e-vs`@u8a5GKdv`LF7uCfKncI4+??Z4iG@AxuX7 z6+@nP^TZ5HX#*z(!y+-KJ3+Ku0M90BTY{SC^{ z&y2#RZPjfX_PE<<>XwGp;g4&wcXsQ0T&XTi(^f+}4qSFH1%^GYi+!rJo~t#ChTeAX zmR0w(iODzQOL+b&{1OqTh*psAb;wT*drr^LKdN?c?HJ*gJl+%kEH&48&S{s28P=%p z7*?(xFW_RYxJxxILS!kdLIJYu@p#mnQ(?moGD1)AxQd66X6b*KN?o&e`u9#N4wu8% z^Gw#G!@|>c740RXziOR=tdbkqf(v~wS_N^CS^1hN-N4{Dww1lvSWcBTX*&9}Cz|s@ z*{O@jZ4RVHq19(HC9xSBZI0M)E;daza+Q*zayrX~N5H4xJ33BD4gn5Ka^Hj{995z4 zzm#Eo?ntC$q1a?)dD$qaC_M{NW!5R!vVZ(XQqS67xR3KP?rA1^+s3M$60WRTVHeTH z6BJO$_jVx0EGPXy}XK_&x597 zt(o6ArN8vZX0?~(lFGHRtHP{gO0y^$iU6Xt2e&v&ugLxfsl;GD)nf~3R^ACqSFLQ< zV7`cXgry((wDMJB55a6D4J;13$z6pupC{-F+wpToW%k1qKjUS^$Mo zN3@}T!ZdpiV7rkNvqP3KbpEn|9aB;@V;gMS1iSb@ zwyD7!5mfj)q+4jE1dq3H`sEKgrVqk|y8{_vmn8bMOi873!rmnu5S=1=-DFx+Oj)Hi zx?~ToiJqOrvSou?RVALltvMADodC7BOg7pOyc4m&6yd(qIuV5?dYUpYzpTe!BuWKi zpTg(JHBYzO&X1e{5o|ZVU-X5e?<}mh=|eMY{ldm>V3NsOGwyxO2h)l#)rH@BI*TN; z`yW26bMSp=k6C4Ja{xB}s`dNp zE+41IwEwo>7*PA|7v-F#jLN>h#a`Er9_86!fwPl{6yWR|fh?c%qc44uP~Ocm2V*(* zICMpS*&aJjxutxKC0Tm8+FBz;3;R^=ajXQUB*nTN*Lb;mruQHUE<&=I7pZ@F-O*VMkJbI#FOrBM8`QEL5Uy=q5e2 z_BwVH%c0^uIWO0*_qD;0jlPoA@sI7BPwOr-mrp7y`|EF)j;$GYdOtEPFRAKyUuUZS z(N4)*6R*ux8s@pMdC*TP?Hx`Zh{{Ser;clg&}CXriXZCr2A!wIoh;j=_eq3_%n7V} za?{KhXg2cXPpKHc90t6=`>s@QF-DNcTJRvLTS)E2FTb+og(wTV7?$kI?QZYgVBn)& zdpJf@tZ{j>B;<MVHiPl_U&KlqBT)$ic+M0uUQWK|N1 zCMl~@o|}!!7yyT%7p#G4?T^Azxt=D(KP{tyx^lD_(q&|zNFgO%!i%7T`>mUuU^FeR zHP&uClWgXm6iXgI8*DEA!O&X#X(zdrNctF{T#pyax16EZ5Lt5Z=RtAja!x+0Z31U8 zjfaky?W)wzd+66$L>o`n;DISQNs09g{GAv%8q2k>2n8q)O^M}=5r#^WR^=se#WSCt zQ`7E1w4qdChz4r@v6hgR?nsaE7pg2B6~+i5 zcTTbBQ2ghUbC-PV(@xvIR(a>Kh?{%YAsMV#4gt1nxBF?$FZ2~nFLKMS!aK=(`WllA zHS<_7ugqKw!#0aUtQwd#A$8|kPN3Af?Tkn)dHF?_?r#X68Wj;|$aw)Wj2Dkw{6)*^ zZfy!TWwh=%g~ECDCy1s8tTgWCi}F1BvTJ9p3H6IFq&zn#3FjZoecA_L_bxGWgeQup zAAs~1IPCnI@H>g|6Lp^Bk)mjrA3_qD4(D(65}l=2RzF-8@h>|Aq!2K-qxt(Q9w7c^ z;gtx`I+=gKOl;h=#fzSgw-V*YT~2_nnSz|!9hIxFb{~dKB!{H zSi??dnmr@%(1w^Be=*Jz5bZeofEKKN&@@uHUMFr-DHS!pb1I&;x9*${bmg6=2I4Zt zHb5LSvojY7ubCNGhp)=95jQ00sMAC{IZdAFsN!lAVQDeiec^HAu=8);2AKqNTT!&E zo+FAR`!A1#T6w@0A+o%&*yzkvxsrqbrfVTG+@z8l4+mRi@j<&)U9n6L>uZoezW>qS zA4YfO;_9dQSyEYpkWnsk0IY}Nr2m(ql@KuQjLgY-@g z4=$uai6^)A5+~^TvLdvhgfd+y?@+tRE^AJabamheJFnpA#O*5_B%s=t8<;?I;qJ}j z&g-9?hbwWEez-!GIhqpB>nFvyi{>Yv>dPU=)qXnr;3v-cd`l}BV?6!v{|cHDOx@IG z;TSiQQ(8=vlH^rCEaZ@Yw}?4#a_Qvx=}BJuxACxm(E7tP4hki^jU@8A zUS|4tTLd)gr@T|F$1eQXPY%fXb7u}(>&9gsd3It^B{W#6F2_g40cgo1^)@-xO&R5X z>qKon+Nvp!4v?-rGQu#M_J2v+3e+?N-WbgPQWf`ZL{Xd9KO^s{uIHTJ6~@d=mc7i z+##ya1p+ZHELmi%3C>g5V#yZt*jMv( zc{m*Y;7v*sjVZ-3mBuaT{$g+^sbs8Rp7BU%Ypi+c%JxtC4O}|9pkF-p-}F{Z7-+45 zDaJQx&CNR)8x~0Yf&M|-1rw%KW3ScjWmKH%J1fBxUp(;F%E+w!U470e_3%+U_q7~P zJm9VSWmZ->K`NfswW(|~fGdMQ!K2z%k-XS?Bh`zrjZDyBMu74Fb4q^A=j6+Vg@{Wc zPRd5Vy*-RS4p1OE-&8f^Fo}^yDj$rb+^>``iDy%t)^pHSV=En5B5~*|32#VkH6S%9 zxgIbsG+|{-$v7mhOww#v-ejaS>u(9KV9_*X!AY#N*LXIxor9hDv%aie@+??X6@Et=xz>6ev9U>6Pn$g4^!}w2Z%Kpqpp+M%mk~?GE-jL&0xLC zy(`*|&gm#mLeoRU8IU?Ujsv=;ab*URmsCl+r?%xcS1BVF*rP}XRR%MO_C!a9J^fOe>U;Y&3aj3 zX`3?i12*^W_|D@VEYR;h&b^s#Kd;JMNbZ#*x8*ZXm(jgw3!jyeHo14Zq!@_Q`V;Dv zKik~!-&%xx`F|l^z2A92aCt4x*I|_oMH9oeqsQgQDgI0j2p!W@BOtCTK8Jp#txi}7 z9kz);EX-2~XmxF5kyAa@n_$YYP^Hd4UPQ>O0-U^-pw1*n{*kdX`Jhz6{!W=V8a$0S z9mYboj#o)!d$gs6vf8I$OVOdZu7L5%)Vo0NhN`SwrQFhP3y4iXe2uV@(G{N{yjNG( zKvcN{k@pXkxyB~9ucR(uPSZ7{~sC=lQtz&V(^A^HppuN!@B4 zS>B=kb14>M-sR>{`teApuHlca6YXs6&sRvRV;9G!XI08CHS~M$=%T~g5Xt~$exVk` zWP^*0h{W%`>K{BktGr@+?ZP}2t0&smjKEVw@3=!rSjw5$gzlx`{dEajg$A58m|Okx zG8@BTPODSk@iqLbS*6>FdVqk}KKHuAHb0UJNnPm!(XO{zg--&@#!niF4T!dGVdNif z3_&r^3+rfQuV^8}2U?bkI5Ng*;&G>(O4&M<86GNxZK{IgKNbRfpg>+32I>(h`T&uv zUN{PRP&onFj$tn1+Yh|0AF330en{b~R+#i9^QIbl9fBv>pN|k&IL2W~j7xbkPyTL^ z*TFONZUS2f33w3)fdzr?)Yg;(s|||=aWZV(nkDaACGSxNCF>XLJSZ=W@?$*` z#sUftY&KqTV+l@2AP5$P-k^N`Bme-xcWPS|5O~arUq~%(z8z87JFB|llS&h>a>Som zC34(_uDViE!H2jI3<@d+F)LYhY)hoW6)i=9u~lM*WH?hI(yA$X#ip}yYld3RAv#1+sBt<)V_9c4(SN9Fn#$}_F}A-}P>N+8io}I3mh!}> z*~*N}ZF4Zergb;`R_g49>ZtTCaEsCHiFb(V{9c@X0`YV2O^@c6~LXg2AE zhA=a~!ALnP6aO9XOC^X15(1T)3!1lNXBEVj5s*G|Wm4YBPV`EOhU&)tTI9-KoLI-U zFI@adu6{w$dvT(zu*#aW*4F=i=!7`P!?hZy(9iL;Z^De3?AW`-gYTPALhrZ*K2|3_ zfz;6xQN9?|;#_U=4t^uS2VkQ8$|?Ub5CgKOj#Ni5j|(zX>x#K(h7LgDP-QHwok~-I zOu9rn%y97qrtKdG=ep)4MKF=TY9^n6CugQ3#G2yx;{))hvlxZGE~rzZ$qEHy-8?pU#G;bwufgSN6?*BeA!7N3RZEh{xS>>-G1!C(e1^ zzd#;39~PE_wFX3Tv;zo>5cc=md{Q}(Rb?37{;YPtAUGZo7j*yHfGH|TOVR#4ACaM2 z;1R0hO(Gl}+0gm9Bo}e@lW)J2OU4nukOTVKshHy7u)tLH^9@QI-jAnDBp(|J8&{fKu=_97$v&F67Z zq+QsJ=gUx3_h_%=+q47msQ*Ub=gMzoSa@S2>`Y9Cj*@Op4plTc!jDhu51nSGI z^sfZ(4=yzlR}kP2rcHRzAY9@T7f`z>fdCU0zibx^gVg&fMkcl)-0bRyWe12bT0}<@ z^h(RgGqS|1y#M;mER;8!CVmX!j=rfNa6>#_^j{^C+SxGhbSJ_a0O|ae!ZxiQCN2qA zKs_Z#Zy|9BOw6x{0*APNm$6tYVG2F$K~JNZ!6>}gJ_NLRYhcIsxY1z~)mt#Yl0pvC zO8#Nod;iow5{B*rUn(0WnN_~~M4|guwfkT(xv;z)olmj=f=aH#Y|#f_*d1H!o( z!EXNxKxth9w1oRr0+1laQceWfgi8z`YS#uzg#s9-QlTT7y2O^^M1PZx z3YS7iegfp6Cs0-ixlG93(JW4wuE7)mfihw}G~Uue{Xb+#F!BkDWs#*cHX^%(We}3% zT%^;m&Juw{hLp^6eyM}J({luCL_$7iRFA6^8B!v|B9P{$42F>|M`4Z_yA{kK()WcM zu#xAZWG%QtiANfX?@+QQOtbU;Avr*_>Yu0C2>=u}zhH9VLp6M>fS&yp*-7}yo8ZWB z{h>ce@HgV?^HgwRThCYnHt{Py0MS=Ja{nIj5%z;0S@?nGQ`z`*EVs&WWNwbzlk`(t zxDSc)$dD+4G6N(p?K>iEKXIk>GlGKTH{08WvrehnHhh%tgpp&8db4*FLN zETA@<$V=I7S^_KxvYv$Em4S{gO>(J#(Wf;Y%(NeECoG3n+o;d~Bjme-4dldKukd`S zRVAnKxOGjWc;L#OL{*BDEA8T=zL8^`J=2N)d&E#?OMUqk&9j_`GX*A9?V-G zdA5QQ#(_Eb^+wDkDiZ6RXL`fck|rVy%)BVv;dvY#`msZ}{x5fmd! zInmWSxvRgXbJ{unxAi*7=Lt&7_e0B#8M5a=Ad0yX#0rvMacnKnXgh>4iiRq<&wit93n!&p zeq~-o37qf)L{KJo3!{l9l9AQb;&>)^-QO4RhG>j`rBlJ09~cbfNMR_~pJD1$UzcGp zOEGTzz01j$=-kLC+O$r8B|VzBotz}sj(rUGOa7PDYwX~9Tum^sW^xjjoncxSz;kqz z$Pz$Ze|sBCTjk7oM&`b5g2mFtuTx>xl{dj*U$L%y-xeQL~|i>KzdUHeep-Yd@}p&L*ig< zgg__3l9T=nbM3bw0Sq&Z2*FA)P~sx0h634BXz0AxV69cED7QGTbK3?P?MENkiy-mV zZ1xV5ry3zIpy>xmThBL0Q!g+Wz@#?6fYvzmEczs(rcujrfCN=^!iWQ6$EM zaCnRThqt~gI-&6v@KZ78unqgv9j6-%TOxpbV`tK{KaoBbhc}$h+rK)5h|bT6wY*t6st-4$e99+Egb#3ip+ERbve08G@Ref&hP)qB&?>B94?eq5i3k;dOuU#!y-@+&5>~!FZik=z4&4|YHy=~!F254 zQAOTZr26}Nc7jzgJ;V~+9ry#?7Z0o*;|Q)k+@a^87lC}}1C)S))f5tk+lMNqw>vh( z`A9E~5m#b9!ZDBltf7QIuMh+VheCoD7nCFhuzThlhA?|8NCt3w?oWW|NDin&&eDU6 zwH`aY=))lpWG?{fda=-auXYp1WIPu&3 zwK|t(Qiqvc@<;1_W#ALDJ}bR;3&v4$9rP)eAg`-~iCte`O^MY+SaP!w%~+{{1tMo` zbp?T%ENs|mHP)Lsxno=nWL&qizR+!Ib=9i%4=B@(Umf$|7!WVxkD%hfRjvxV`Co<; zG*g4QG_>;RE{3V_DOblu$GYm&!+}%>G*yO{-|V9GYG|bH2JIU2iO}ZvY>}Fl%1!OE zZFsirH^$G>BDIy`8;R?lZl|uu@qWj2T5}((RG``6*05AWsVVa2Iu>!F5U>~7_Tlv{ zt=Dpgm~0QVa5mxta+fUt)I0gToeEm9eJX{yYZ~3sLR&nCuyuFWuiDIVJ+-lwViO(E zH+@Rg$&GLueMR$*K8kOl>+aF84Hss5p+dZ8hbW$=bWNIk0paB!qEK$xIm5{*^ad&( zgtA&gb&6FwaaR2G&+L+Pp>t^LrG*-B&Hv;-s(h0QTuYWdnUObu8LRSZoAVd7SJ;%$ zh%V?58mD~3G2X<$H7I)@x?lmbeeSY7X~QiE`dfQ5&K^FB#9e!6!@d9vrSt!);@ZQZ zO#84N5yH$kjm9X4iY#f+U`FKhg=x*FiDoUeu1O5LcC2w&$~5hKB9ZnH+8BpbTGh5T zi_nfmyQY$vQh%ildbR7T;7TKPxSs#vhKR|uup`qi1PufMa(tNCjRbllakshQgn1)a8OO-j8W&aBc_#q1hKDF5-X$h`!CeT z+c#Ial~fDsGAenv7~f@!icm(~)a3OKi((=^zcOb^qH$#DVciGXslUwTd$gt{7)&#a`&Lp ze%AnL0#U?lAl8vUkv$n>bxH*`qOujO0HZkPWZnE0;}0DSEu1O!hg-d9#{&#B1Dm)L zvN%r^hdEt1vR<4zwshg*0_BNrDWjo65be1&_82SW8#iKWs7>TCjUT;-K~*NxpG2P% zovXUo@S|fMGudVSRQrP}J3-Wxq;4xIxJJC|Y#TQBr>pwfy*%=`EUNE*dr-Y?9y9xK zmh1zS@z{^|UL}v**LNYY!?1qIRPTvr!gNXzE{%=-`oKclPrfMKwn` zUwPeIvLcxkIV>(SZ-SeBo-yw~{p!<&_}eELG?wxp zee-V59%@BtB+Z&Xs=O(@P$}v_qy1m=+`!~r^aT> zY+l?+6(L-=P%m4ScfAYR8;f9dyVw)@(;v{|nO#lAPI1xDHXMYt~-BGiP&9y2OQsYdh7-Q1(vL<$u6W0nxVn-qh=nwuRk}{d!uACozccRGx6~xZQ;=#JCE?OuA@;4 zadp$sm}jfgW4?La(pb!3f0B=HUI{5A4b$2rsB|ZGb?3@CTA{|zBf07pYpQ$NM({C6Srv6%_{rVkCndT=1nS}qyEf}Wjtg$e{ng7Wgz$7itYy0sWW_$qld);iUm85GBH)fk3b=2|5mvflm?~inoVo zDH_%e;y`DzoNj|NgZ`U%a9(N*=~8!qqy0Etkxo#`r!!{|(NyT0;5= z8nVZ6AiM+SjMG8J@6c4_f-KXd_}{My?Se1GWP|@wROFpD^5_lu?I%CBzpwi(`x~xh B8dv}T delta 17845 zcmV)CK*GO}(F4QI1F(Jx4W$DjNjn4p0N4ir06~)x5+0MO2`GQvQyWzj|J`gh3(E#l zNGO!HfVMRRN~%`0q^)g%XlN*vP!O#;m*h5VyX@j-1N|HN;8S1vqEAj=eCdn`)tUB9 zXZjcT^`bL6qvL}gvXj%9vrOD+x!Gc_0{$Zg+6lTXG$bmoEBV z*%y^c-mV0~Rjzv%e6eVI)yl>h;TMG)Ft8lqpR`>&IL&`>KDi5l$AavcVh9g;CF0tY zw_S0eIzKD?Nj~e4raA8wxiiImTRzv6;b6|LFmw)!E4=CiJ4I%&axSey4zE-MIh@*! z*P;K2Mx{xVYPLeagKA}Hj=N=1VrWU`ukuBnc14iBG?B}Uj>?=2UMk4|42=()8KOnc zrJzAxxaEIfjw(CKV6F$35u=1qyf(%cY8fXaS9iS?yetY{mQ#Xyat*7sSoM9fJlZqq zyasQ3>D>6p^`ck^Y|kYYZB*G})uAbQ#7)Jeb~glGz@2rPu}zBWDzo5K$tP<|meKV% z{Swf^eq6NBioF)v&~9NLIxHMTKe6gJ@QQ^A6fA!n#u1C&n`aG7TDXKM1Jly-DwTB` z+6?=Y)}hj;C#r5>&x;MCM4U13nuXVK*}@yRY~W3X%>U>*CB2C^K6_OZsXD!nG2RSX zQg*0)$G3%Es$otA@p_1N!hIPT(iSE=8OPZG+t)oFyD~{nevj0gZen$p>U<7}uRE`t5Mk1f4M0K*5 zbn@3IG5I2mk;8K>*RZ zPV6iL006)S001s%0eYj)9hu1 z9o)iQT9(v*sAuZ|ot){RrZ0Qw4{E0A+!Yx_M~#Pj&OPUM&i$RU=Uxu}e*6Sr2ror= z&?lmvFCO$)BY+^+21E>ENWe`I0{02H<-lz&?})gIVFyMWxX0B|0b?S6?qghp3lDgz z2?0|ALJU=7s-~Lb3>9AA5`#UYCl!Xeh^i@bxs5f&SdiD!WN}CIgq&WI4VCW;M!UJL zX2};d^sVj5oVl)OrkapV-C&SrG)*x=X*ru!2s04TjZ`pY$jP)4+%)7&MlpiZ`lgoF zo_p>^4qGz^(Y*uB10dY2kcIbt=$FIdYNqk;~47wf@)6|nJp z1cocL3zDR9N2Pxkw)dpi&_rvMW&Dh0@T*_}(1JFSc0S~Ph2Sr=vy)u*=TY$i_IHSo zR+&dtWFNxHE*!miRJ%o5@~GK^G~4$LzEYR-(B-b(L*3jyTq}M3d0g6sdx!X3-m&O% zK5g`P179KHJKXpIAAX`A2MFUA;`nXx^b?mboVbQgigIHTU8FI>`q53AjWaD&aowtj z{XyIX>c)*nLO~-WZG~>I)4S1d2q@&?nwL)CVSWqWi&m1&#K1!gt`g%O4s$u^->Dwq ziKc&0O9KQ7000OG0000%03-m(e&Y`S09YWC4iYDSty&3q8^?8ij|8zxaCt!zCFq1@ z9TX4Hl68`nY>}cQNW4Ullqp$~SHO~l1!CdFLKK}ij_t^a?I?C^CvlvnZkwiVn>dl2 z2$V(JN{`5`-8ShF_ek6HNRPBlPuIPYu>TAeAV5O2)35r3*_k(Q-h1+h5pb(Zu%oJ__pBsW0n5ILw`!&QR&YV`g0Fe z(qDM!FX_7;`U3rxX#QHT{f%h;)Eursw=*#qvV)~y%^Uo^% zi-%sMe^uz;#Pe;@{JUu05zT*i=u7mU9{MkT`ft(vPdQZoK&2mg=tnf8FsaNQ+QcPg zB>vP8Rd6Z0JoH5_Q`zldg;hx4azQCq*rRZThqlqTRMzn1O3_rQTrHk8LQ<{5UYN~` zM6*~lOGHyAnx&#yCK{i@%N1Us@=6cw=UQxpSE;<(LnnES%6^q^QhBYQ-VCSmIu8wh z@_LmwcFDfAhIn>`%h7L{)iGBzu`Md4dj-m3C8mA9+BL*<>q z#$7^ttIBOE-=^|zmG`K8yUKT{yjLu2SGYsreN0*~9yhFxn4U};Nv1XXj1fH*v-g=3 z@tCPc`YdzQGLp%zXwo*o$m9j-+~nSWls#s|?PyrHO%SUGdk**X9_=|b)Y%^j_V$3S z>mL2A-V)Q}qb(uZipEFVm?}HWc+%G6_K+S+87g-&RkRQ8-{0APDil115eG|&>WQhU zufO*|e`hFks^cJJmx_qNx{ltSp3aT|XgD5-VxGGXb7gkiOG$w^qMVBDjR8%!Sbh72niHRDV* ziFy8LE+*$j?t^6aZP9qt-ow;hzkmhvy*Hn-X^6?yVMbtNbyqZQ^rXg58`gk+I%Wv} zn_)dRq+3xjc8D%}EQ%nnTF7L7m}o9&*^jf`_qvUhVKY7w9Zgxr-0YHWFRd3$l_6UX zpXt^U&TiC*qZWx#pOG6k?3Tg)pra*fw(O6_45>lUBN1U5Qmc>^DHt)5b~Ntjsw!NI z1n4{$HWFeIi)*qvgK^ui;(81VQc1(wJ8C#tjR>Dkjf{xYC^_B^#qrdCc)uZxtgua6 zk98UGQF|;;k`c+0_z)tQ&9DwLB~&12@D1!*mTz_!3Mp=cg;B7Oq4cKN>5v&dW7q@H zal=g6Ipe`siZN4NZiBrkJCU*x216gmbV(FymgHuG@%%|8sgD?gR&0*{y4n=pukZnd z4=Nl~_>jVfbIehu)pG)WvuUpLR}~OKlW|)=S738Wh^a&L+Vx~KJU25o6%G7+Cy5mB zgmYsgkBC|@K4Jm_PwPoz`_|5QSk}^p`XV`649#jr4Lh^Q>Ne~#6Cqxn$7dNMF=%Va z%z9Ef6QmfoXAlQ3)PF8#3Y% zadcE<1`fd1&Q9fMZZnyI;&L;YPuy#TQ8b>AnXr*SGY&xUb>2678A+Y z8K%HOdgq_4LRFu_M>Ou|kj4W%sPPaV)#zDzN~25klE!!PFz_>5wCxglj7WZI13U5| zEq_YLKPH;v8sEhyG`dV_jozR);a6dBvkauhC;1dk%mr+J*Z6MMH9jqxFk@)&h{mHl zrf^i_d-#mTF=6-T8Rk?(1+rPGgl$9=j%#dkf@x6>czSc`jk7$f!9SrV{do%m!t8{? z_iAi$Qe&GDR#Nz^#uJ>-_?(E$ns)(3)X3cYY)?gFvU+N>nnCoBSmwB2<4L|xH19+4 z`$u#*Gt%mRw=*&|em}h_Y`Pzno?k^8e*hEwfM`A_yz-#vJtUfkGb=s>-!6cHfR$Mz z`*A8jVcz7T{n8M>ZTb_sl{EZ9Ctau4naX7TX?&g^VLE?wZ+}m)=YW4ODRy*lV4%-0 zG1XrPs($mVVfpnqoSihnIFkLdxG9um&n-U|`47l{bnr(|8dmglO7H~yeK7-wDwZXq zaHT($Qy2=MMuj@lir(iyxI1HnMlaJwpX86je}e=2n|Esb6hB?SmtDH3 z2qH6o`33b{;M{mDa5@@~1or8+Zcio*97pi1Jkx6v5MXCaYsb~Ynq)eWpKnF{n)FXZ z?Xd;o7ESu&rtMFr5(yJ(B7V>&0gnDdL*4MZH&eO+r*t!TR98ssbMRaw`7;`SLI8mT z=)hSAt~F=mz;JbDI6g~J%w!;QI(X14AnOu;uve^4wyaP3>(?jSLp+LQ7uU(iib%IyB(d&g@+hg;78M>h7yAeq$ALRoHGkKXA+E z$Sk-hd$Fs2nL4w9p@O*Y$c;U)W#d~)&8Js;i^Dp^* z0*7*zEGj~VehF4sRqSGny*K_CxeF=T^8;^lb}HF125G{kMRV?+hYktZWfNA^Mp7y8 zK~Q?ycf%rr+wgLaHQ|_<6z^eTG7izr@99SG9Q{$PCjJabSz`6L_QJJe7{LzTc$P&pwTy<&3RRUlSHmK;?}=QAhQaDW3#VWcNAH3 zeBPRTDf3?3mfdI$&WOg(nr9Gyzg`&u^o!f2rKJ57D_>p z6|?Vg?h(@(*X=o071{g^le>*>qSbVam`o}sAK8>b|11%e&;%`~b2OP7--q%0^2YDS z`2M`{2QYr1VC)sIW9WOu8<~7Q>^$*Og{KF+kI;wFegvaIDkB%3*%PWtWKSq7l`1YcDxQQ2@nv{J!xWV?G+w6C zhUUxUYVf%(Q(40_xrZB@rbxL=Dj3RV^{*yHd>4n-TOoHVRnazDOxxkS9kiZyN}IN3 zB^5N=* zRSTO+rA<{*P8-$GZdyUNOB=MzddG$*@q>mM;pUIiQ_z)hbE#Ze-IS)9G}Rt$5PSB{ zZZ;#h9nS7Rf1ecW&n(Gpu9}{vXQZ-f`UHIvD?cTbF`YvH*{rgE(zE22pLAQfhg-`U zuh612EpByB(~{w7svCylrBk%5$LCIyuhrGi=yOfca`=8ltKxHcSNfDRt@62QH^R_0 z&eQL6rRk>Dvf6rjMQv5ZXzg}S`HqV69hJT^pPHtdhqsrPJWs|IT9>BvpQa@*(FX6v zG}TYjreQCnH(slMt5{NgUf)qsS1F&Bb(M>$X}tWI&yt2I&-rJbqveuj?5J$`Dyfa2 z)m6Mq0XH@K)Y2v8X=-_4=4niodT&Y7W?$KLQhjA<+R}WTdYjX9>kD+SRS^oOY1{A= zZTId-(@wF^UEWso($wZtrs%e7t<}YaC_;#@`r0LUzKY&|qPJz*y~RHG`E6bypP5AX zN!p0^AUu8uDR>xM-ALFzBxXM~Q3z=}fHWCIG>0&I6x2Iu7&U)49j7qeMI&?qb$=4I zdMmhAJrO%@0f%YW! z^gLByEGSk+R0v4*d4w*N$Ju6z#j%HBI}6y$2en=-@S3=6+yZX94m&1j@s- z7T6|#0$c~dYq9IkA!P)AGkp~S$zYJ1SXZ#RM0|E~Q0PSm?DsT4N3f^)b#h(u9%_V5 zX*&EIX|gD~P!vtx?ra71pl%v)F!W~X2hcE!h8cu@6uKURdmo1-7icN4)ej4H1N~-C zjXgOK+mi#aJv4;`DZ%QUbVVZclkx;9`2kgbAhL^d{@etnm+5N8pB#fyH)bxtZGCAv z(%t0kPgBS{Q2HtjrfI0B$$M0c?{r~2T=zeXo7V&&aprCzww=i*}Atu7g^(*ivauMz~kkB%Vt{Wydlz%%2c26%>0PAbZO zVHx%tK(uzDl#ZZK`cW8TD2)eD77wB@gum{B2bO_jnqGl~01EF_^jx4Uqu1yfA~*&g zXJ`-N?D-n~5_QNF_5+Un-4&l$1b zVlHFqtluoN85b^C{A==lp#hS9J(npJ#6P4aY41r) zzCmv~c77X5L}H%sj>5t&@0heUDy;S1gSOS>JtH1v-k5l}z2h~i3^4NF6&iMb;ZYVE zMw*0%-9GdbpF1?HHim|4+)Zed=Fk<2Uz~GKc^P(Ig@x0&XuX0<-K(gA*KkN&lY2Xu zG054Q8wbK~$jE32#Ba*Id2vkqmfV{U$Nx9vJ;jeI`X+j1kh7hB8$CBTe@ANmT^tI8 z%U>zrTKuECin-M|B*gy(SPd`(_xvxjUL?s137KOyH>U{z01cBcFFt=Fp%d+BK4U;9 zQG_W5i)JASNpK)Q0wQpL<+Ml#cei41kCHe&P9?>p+KJN>I~`I^vK1h`IKB7k^xi`f z$H_mtr_+@M>C5+_xt%v}{#WO{86J83;VS@Ei3JLtp<*+hsY1oGzo z0?$?OJO$79;{|@aP!fO6t9TJ!?8i&|c&UPWRMbkwT3nEeFH`Yyyh6b%Rm^nBuTt@9 z+$&-4lf!G|@LCo3<8=yN@5dYbc%uq|Hz|0tiiLQKiUoM9g14zyECKGv0}3AWv2WJ zUAXGUhvkNk`0-H%ACsRSmy4fJ@kxBD3ZKSj6g(n1KPw?g{v19phcBr3BEF>J%lL|d zud3LNuL;cR*xS+;X+N^Br+x2{&hDMhb-$6_fKU(Pt0FQUXgNrZvzsVCnsFqv?#L z4-FYsQ-?D>;LdjHu_TT1CHN~aGkmDjWJkJg4G^!+V_APd%_48tErDv6BW5;ji^UDD zRu5Sw7wwplk`w{OGEKWJM&61c-AWn!SeUP8G#+beH4_Ov*)NUV?eGw&GHNDI6G(1Y zTfCv?T*@{QyK|!Q09wbk5koPD>=@(cA<~i4pSO?f(^5sSbdhUc+K$DW#_7^d7i%At z?KBg#vm$?P4h%?T=XymU;w*AsO_tJr)`+HUll+Uk_zx6vNw>G3jT){w3ck+Z=>7f0 zZVkM*!k^Z_E@_pZK6uH#|vzoL{-j1VFlUHP&5~q?j=UvJJNQG ztQdiCF$8_EaN_Pu8+afN6n8?m5UeR_p_6Log$5V(n9^W)-_vS~Ws`RJhQNPb1$C?| zd9D_ePe*`aI9AZ~Ltbg)DZ;JUo@-tu*O7CJ=T)ZI1&tn%#cisS85EaSvpS~c#CN9B z#Bx$vw|E@gm{;cJOuDi3F1#fxWZ9+5JCqVRCz5o`EDW890NUfNCuBn)3!&vFQE{E$L`Cf7FMSSX%ppLH+Z}#=p zSow$)$z3IL7frW#M>Z4|^9T!=Z8}B0h*MrWXXiVschEA=$a|yX9T~o!=%C?T+l^Cc zJx&MB$me(a*@lLLWZ=>PhKs!}#!ICa0! zq%jNgnF$>zrBZ3z%)Y*yOqHbKzEe_P=@<5$u^!~9G2OAzi#}oP&UL9JljG!zf{JIK z++G*8j)K=$#57N)hj_gSA8golO7xZP|KM?elUq)qLS)i(?&lk{oGMJh{^*FgklBY@Xfl<_Q zXP~(}ST6V01$~VfOmD6j!Hi}lsE}GQikW1YmBH)`f_+)KI!t#~B7=V;{F*`umxy#2Wt8(EbQ~ks9wZS(KV5#5Tn3Ia90r{}fI%pfbqBAG zhZ)E7)ZzqA672%@izC5sBpo>dCcpXi$VNFztSQnmI&u`@zQ#bqFd9d&ls?RomgbSh z9a2rjfNiKl2bR!$Y1B*?3Ko@s^L5lQN|i6ZtiZL|w5oq%{Fb@@E*2%%j=bcma{K~9 z*g1%nEZ;0g;S84ZZ$+Rfurh;Nhq0;{t~(EIRt}D@(Jb7fbe+_@H=t&)I)gPCtj*xI z9S>k?WEAWBmJZ|gs}#{3*pR`-`!HJ)1Dkx8vAM6Tv1bHZhH=MLI;iC#Y!$c|$*R>h zjP{ETat(izXB{@tTOAC4nWNhh1_%7AVaf!kVI5D=Jf5I1!?}stbx_Yv23hLf$iUTb z-)WrTtd2X+;vBW_q*Z6}B!10fs=2FA=3gy*dljsE43!G*3Uw(Is>(-a*5E!T4}b-Y zfvOC)-HYjNfcpi`=kG%(X3XcP?;p&=pz+F^6LKqRom~pA}O* zitR+Np{QZ(D2~p_Jh-k|dL!LPmexLM?tEqI^qRDq9Mg z5XBftj3z}dFir4oScbB&{m5>s{v&U=&_trq#7i&yQN}Z~OIu0}G)>RU*`4<}@7bB% zKYxGx0#L#u199YKSWZwV$nZd>D>{mDTs4qDNyi$4QT6z~D_%Bgf?>3L#NTtvX;?2D zS3IT*2i$Snp4fjDzR#<)A``4|dA(}wv^=L?rB!;kiotwU_gma`w+@AUtkSyhwp{M} z!e`jbUR3AG4XvnBVcyIZht6Vi~?pCC!$XF2 z*V~)DBVm8H7$*OZQJYl3482hadhsI2NCz~_NINtpC?|KI6H3`SG@1d%PsDdw{u}hq zN;OU~F7L1jT&KAitilb&Fl3X12zfSuFm;X)xQWOHL&7d)Q5wgn{78QJ6k5J;is+XP zCPO8_rlGMJB-kuQ*_=Yo1TswG4xnZd&eTjc8=-$6J^8TAa~kEnRQ@Zp-_W&B(4r@F zA==}0vBzsF1mB~743XqBmL9=0RSkGn$cvHf*hyc{<2{@hW+jKjbC|y%CNupHY_NC% zivz^btBLP-cDyV8j>u)=loBs>HoI5ME)xg)oK-Q0wAy|8WD$fm>K{-`0|W{H00;;G z000j`0OWQ8aHA9e04^;603eeQIvtaXMG=2tcr1y8Fl-J;AS+=<0%DU8Bp3oEEDhA^ zOY)M8%o5+cF$rC?trfMcty*f)R;^v=f~}||Xe!#;T3eTDZELN&-50xk+J1heP5AQ>h5O#S_uO;O@;~REd*_G$x$hVeE#bchX)otXQy|S5(oB)2a2%Sc(iDHm z=d>V|a!BLp9^#)o7^EQ2kg=K4%nI^sK2w@-kmvB+ARXYdq?xC2age6)e4$^UaY=wn zgLD^{X0A+{ySY+&7RpldwpC6=E zSPq?y(rl8ZN%(A*sapd4PU+dIakIwT0=zxIJEUW0kZSo|(zFEWdETY*ZjIk9uNMUA ze11=mHu8lUUlgRx!hItf0dAF#HfdIB+#aOuY--#QN9Ry zbx|XkG?PrBb@l6Owl{9Oa9w{x^R}%GwcEEfY;L-6OU8|9RXvu`-ECS`jcO1x1MP{P zcr;Bw##*Dod9K@pEx9z9G~MiNi>8v1OU-}vk*HbI)@CM? zn~b=jWUF%HP=CS+VCP>GiAU_UOz$aq3%%Z2laq^Gx`WAEmuNScCN)OlW>YHGYFgV2 z42lO5ZANs5VMXLS-RZTvBJkWy*OeV#L;7HwWg51*E|RpFR=H}h(|N+79g)tIW!RBK ze08bg^hlygY$C2`%N>7bDm`UZ(5M~DTanh3d~dg+OcNdUanr8azO?})g}EfnUB;5- zE1FX=ru?X=zAk4_6@__o1fE+ml1r&u^f1Kb24Jf-)zKla%-dbd>UZ1 zrj3!RR!Jg`ZnllKJ)4Yfg)@z>(fFepeOcp=F-^VHv?3jSxfa}-NB~*qkJ5Uq(yn+( z<8)qbZh{C!xnO@-XC~XMNVnr-Z+paowv!$H7>`ypMwA(X4(knx7z{UcWWe-wXM!d? zYT}xaVy|7T@yCbNOoy)$D=E%hUNTm(lPZqL)?$v+-~^-1P8m@Jm2t^L%4#!JK#Vtg zyUjM+Y*!$);1<)0MUqL00L0*EZcsE&usAK-?|{l|-)b7|PBKl}?TM6~#j9F+eZq25_L&oSl}DOMv^-tacpDI)l*Ws3u+~jO@;t(T)P=HCEZ#s_5q=m zOsVY!QsOJn)&+Ge6Tm)Ww_Bd@0PY(78ZJ)7_eP-cnXYk`>j9q`x2?Xc6O@55wF+6R zUPdIX!2{VGA;FSivN@+;GNZ7H2(pTDnAOKqF*ARg+C54vZ@Ve`i?%nDDvQRh?m&`1 zq46gH)wV=;UrwfCT3F(m!Q5qYpa!#f6qr0wF=5b9rk%HF(ITc!*R3wIFaCcftGwPt z(kzx{$*>g5L<;u}HzS4XD%ml zmdStbJcY@pn`!fUmkzJ8N>*8Y+DOO^r}1f4ix-`?x|khoRvF%jiA)8)P{?$8j2_qN zcl3Lm9-s$xdYN9)>3j6BPFK)Jbovl|Sf_p((CHe!4hx@F)hd&&*Xb&{TBj>%pT;-n z{3+hA^QZYnjXxtF2XwxPZ`S#J8h>5qLwtwM-{5abbEnRS z`9_`Zq8FJiI#0syE_V_3M&trw$P=ezkHosV$8&I5c0(*-9KBE5DJOC-Xv zw}1bq~AD0_Xerm`%ryiG9_$S z5G|btfiAUNdV09SO2l9v+e#(H6HYOdQs=^ z@xwZQU)~;p1L*~ciC}9ao{nQ-@B>rpUzKBxv=cUusOP5Trs3QnvHxGh9e>s7AM{V1|HfYe z3QwH;nHHR49fYzuGc3W3l5xrDAI392SFXx>lWE3V9Ds9il3PyZaN5>oC3>9W-^7vC z3~KZ-@iD?tIkhg+6t{m;RGk2%>@I0&kf)o$+-^ls0(YABNbM(=l#ad@nKp_j=b~Xs ziR;xu_+)lxy6|+af!@}gO2H_x)p;nZ-tYxW5Omq=l`GzMp*GTLr>vZN1?e}^C$t*Z zvzEdIc2|HA2RFN_4#EkzMqKnbbw!?!?%B@M0^^5Z;K?x-%lg?Z>}wMV8zEqHZ$cr~Y#Wv>9+)KMUZatUqbRU8 z8t9qrek(H^C0Tuzq|cP2$WL7tzj+Dj5y^2SF1D154CnsB$xbz`$wV||n-cG%rsT$p z+3RHdadK(3-noj(2L#8c5lODg)V8pv(GEnNb@F>dEHQr>!qge@L>#qg)RAUtiOYqF ziiV_ETExwD)bQ<))?-9$)E(FiRBYyC@}issHS!j9n)~I1tarxnQ2LfjdIJ)*jp{0E z&1oTd%!Qbw$W58s!6ms>F z=p0!~_Mv~8jyaicOS*t(ntw`5uFi0Bc4*mH8kSkk$>!f0;FM zX_t14I55!ZVsg0O$D2iuEDb7(J>5|NKW^Z~kzm@dax z9(|As$U7^}LF%#`6r&UPB*6`!Rf74h~*C=ami6xUxYCwiJxdr$+`z zKSC4A%8!s%R&j*2si(OEc*fy!q)?%=TjDZJ2}O zxT6o>jlKXz_7_Y$N})}IG`*#KfMzs#R(SI#)3*ZEzCv%_tu(VTZ5J| zw2$5kK)xTa>xGFgS0?X(NecjzFVKG%VVn?neu=&eQ+DJ1APlY1E?Q1s!Kk=yf7Uho z>8mg_!U{cKqpvI3ucSkC2V`!d^XMDk;>GG~>6>&X_z75-kv0UjevS5ORHV^e8r{tr z-9z*y&0eq3k-&c_AKw~<`8dtjsP0XgFv6AnG?0eo5P14T{xW#b*Hn2gEnt5-KvN1z zy!TUSi>IRbD3u+h@;fn7fy{F&hAKx7dG4i!c?5_GnvYV|_d&F16p;)pzEjB{zL-zr z(0&AZUkQ!(A>ghC5U-)t7(EXb-3)tNgb=z`>8m8n+N?vtl-1i&*ftMbE~0zsKG^I$ zSbh+rUiucsb!Ax@yB}j>yGeiKIZk1Xj!i#K^I*LZW_bWQIA-}FmJ~^}>p=K$bX9F{}z{s^KWc~OK(zl_X57aB^J9v}yQ5h#BE$+C)WOglV)nd0WWtaF{7`_Ur`my>4*NleQG#xae4fIo(b zW(&|g*#YHZNvDtE|6}yHvu(hDekJ-t*f!2RK;FZHRMb*l@Qwkh*~CqQRNLaepXypX z1?%ATf_nHIu3z6gK<7Dmd;{`0a!|toT0ck|TL$U;7Wr-*piO@R)KrbUz8SXO0vr1K z>76arfrqImq!ny+VkH!4?x*IR$d6*;ZA}Mhro(mzUa?agrFZpHi*)P~4~4N;XoIvH z9N%4VK|j4mV2DRQUD!_-9fmfA2(YVYyL#S$B;vqu7fnTbAFMqH``wS7^B5=|1O&fL z)qq(oV6_u4x(I(**#mD}MnAy(C&B4a1n6V%$&=vrIDq^F_KhE5Uw8_@{V`_#M0vCu zaNUXB=n0HT@D+ppDXi8-vp{tj)?7+k>1j}VvEKRgQ~DWva}8*pp`W8~KRo*kJ*&X} zP!~2fxQr@dM*q0dI|)Fux=pZWBk==RI7i{^BQf`kWlD2%|@R9!JA7& zLbM$uJ12y}_62$|T|{)@OJZtzfpL^t@1nMTYHutrF#D+^?~CN~9`YQ@#&&@c_Zf)( zbC~y8!2LO8jHwQXv>G~1q?c68ipT*%dY&c{8wd_!Y#~tMJ7yk!F8| zt?m_CLVw6cU@@p(#h4cY&Qsfz2Xp3w^4Cg%m03Tmq~9n%hyoMH^KY7{(QkRyn_!YB zzZa!Tgr~5$MAG$x)Fs71#6j}Kvcv3=9VUX8CH< zbP3|fY8f#$K*<5JQ7whM(v=GN2k26Xsh)#0!HKS(koLgAp-;)8z0w&_Z=nG4v6n8u z&Tm0Fi){4_!Y5Kp?!zv$FKfUifQ{%c82uYfrvE{%ejUd72aNYmI*0z3-a-EYr+bB->oH3#t(AY3 zV{Z=(SJr;D#0(`u*dc*~9T7D8Pudw894%!>c4wU&V1m<~0InidR6fbi?yPl(z+sKa zdF*kS>_4^1UO>y4T%Ar>epSr5&vp`$KdY7B(F%P0@VyHk@1fJ=6X0=aGjD-)BrOJD zW}IU@hg~^2r>a1fQvjTtvL*mKJ7q;pfP*U2=URL`VB_Y_JojbZ+MS=vaVN0C6L_MV zG1#5=35-E`KsD%r>-Q_ndvJ2tOYcMMP9f*t0iJ`(Z`^+YP)h>@lR(@Wvrt-`0tHG+ zuP2R@@mx=T@fPoQ1s`e^1I0H*kQPBGDky@!ZQG@8jY-+2ihreG5q$6i{3vmDTg0j$ zzRb*-nKN@{_wD`V6+i*YS)?$XfrA-sW?js?SYU8#vXxxQCc|*K!EbpWfu)3~jwq6_@KC0m;3A%jH^18_a0;ksC2DEwa@2{9@{ z9@T??<4QwR69zk{UvcHHX;`ICOwrF;@U;etd@YE)4MzI1WCsadP=`%^B>xPS-{`=~ zZ+2im8meb#4p~XIL9}ZOBg7D8R=PC8V}ObDcxEEK(4yGKcyCQWUe{9jCs+@k!_y|I z%s{W(&>P4w@hjQ>PQL$zY+=&aDU6cWr#hG)BVCyfP)h>@3IG5I2mk;8K>)Ppba*!h z005B=001VF5fT=Y4_ytCUk`sv8hJckqSy&Gc2Jx^WJ$J~08N{il-M$fz_ML$)Cpil z(nOv_nlZB^c4s&&O3h=OLiCz&(|f0 zxWU_-JZy>hxP*gvR>CLnNeQ1~g;6{g#-}AbkIzWR;j=8=6!AHpKQCbjFYxf9h%bov zVi;eNa1>t-<14KERUW>^KwoF+8zNo`Y*WiQwq}3m0_2RYtL9Wmu`JaRaQMQ)`Si^6+VbM`!rH~T?DX2=(n4nT zf`G`(Rpq*pDk*v~wMYPZ@vMNZDMPnxMYmU!lA{Xfo?n=Ibb4y3eyY1@Dut4|Y^ml& zqs$r}jAo=B(Ml>ogeEjyv(E`=kBzPf2uv9TQtO$~bamD#=Tv`lNy(K|w$J2O6jS51 zzZtOCHDWz7W0=L1XDW5WR5mtLGc~W+>*vX5{e~U@rE~?7e>vKU-v8bj;F4#abtcV(3ZtwXo9ia93HiETyQXwW4a-0){;$OU*l` zW^bjkyZTJ6_DL^0}`*)#EZ|2nvKRzMLH9-~@Z6$v#t8Dm%(qpP+DgzNe6d)1q zBqhyF$jJTyYFvl_=a>#I8jhJ)d6SBNPg#xg2^kZ3NX8kQ74ah(Y5Z8mlXyzTD&}Q8 ziY(pj-N-V2f>&hZQJ`Di%wp2fN(I%F@l)3M8GcSdNy+#HuO{$I8NXubRlFkL)cY@b z#`v{}-^hRXEq*8B_cG=%PZvI$eo(|8Wc(2o8L#0_GX9L$1@yV>%7mGk)QTD1R*OvS z4OW;ym1)%k9Bfem0tOqq3yyAUWp&q|LsN!RDnxa|j;>R|Mm2rIv7=tej5GFaa+`#| z;7u9Z_^XV+vD@2hF8Xe63+Qd`oig6S9jX(*DbjzPb*K-H7c^7E-(~!R6E%TrgW;RvG;WS{Ziv*W*a*`9Bb;$Er3?MyF~5GcXv`k>U)n}lwv$Sp+H@IKA5$mKk0g*4Ln{!tfvITeY zzr%8JJ5BdcEYsR9eGzJ4B&$}4FMmbRU6{8{_w7Kl77@PNe7|Bc#c?5(C5&Z=kJ#(oM90D4`rh2S!|^L!P#e#1hkD5@~-- z`63GV0~*rOZSqw7k^#-Y$Q4z3Oa2SPRURqEahB1B^h{7~+p03SwzqL9QU#$3-X zdYtQ?-K5xDAdfomEd6(yPtZ!yY_<35bMedeq`z2JWorljz5-f9<^93HM-$#+acw%9r!JOM%O<|BR`W& zd-%j_?b^q7Kl6{q^N{cg2u;11rFB5EP+oqG9&pHD#_Mo@aNMj;LUvsl&nK(ca(hT( zzFc2oHC6WQv8g7jo+3ZSwK+9G$cvfRnql)?g=XeQ3+LTh3)79nhEle8OqS3T$qn(> z(=5Bg?EWq-ldEywgzXW965%H(9^ik*rH(8dNdkbcS9|ow&_r`X~R^R?B+(oTiMzzlx8KnHqUi z8Rh-)VAnS-CO+3}yxqm8)X+N+uzieFVm-F#syP#M1p5&$wX3MJ8 z+R@grZ*5G^Uh4I@VT=>C4RJNc^~3mx$kS1F{L?3)BzdduD2MZKdu#jNno&f2&d{?` zW(>$oktzY@GO{|Ln~Bt^A4)(%?l-&(Dm!iL#$K_xOyhwAf=K2<+Bom zw7|hl6E5}B$d%n0sfZvfQRy9Fyz2~ z83#=#LaHnf1th^k*p|ux8!!8pfHE!)x*%=_hAddl)P%4h4%&8!5-W#xqqb}c=H(i|wqcIS&oDQ{ zhI7N-$f$ra3=RjPmMh?-IEkJYQ<}R9Z!}wmp$#~Uc%u1oh#TP}wF*kJJmQX2#27kL z_dz(yKufo<=m71bZfLp^Ll#t3(IHkrgMcvx@~om%Ib(h(<$Da7urTI`x|%`wD--sN zJEEa>4DGSEG?0ulkosfj8IMNN4)B=ZtvGG{|4Fp=Xhg!wPNgYzS>{Bp%%Qa+624X@ X49Luk)baa85H9$5YCsTPT`SVRWMtMW diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index e750102e09..8049c684f0 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -1,5 +1,5 @@ distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-7.3-bin.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-7.5-bin.zip zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists diff --git a/gradlew b/gradlew index 4f906e0c81..1b6c787337 100755 --- a/gradlew +++ b/gradlew @@ -1,7 +1,7 @@ -#!/usr/bin/env sh +#!/bin/sh # -# Copyright 2015 the original author or authors. +# Copyright © 2015-2021 the original authors. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -17,67 +17,101 @@ # ############################################################################## -## -## Gradle start up script for UN*X -## +# +# Gradle start up script for POSIX generated by Gradle. +# +# Important for running: +# +# (1) You need a POSIX-compliant shell to run this script. If your /bin/sh is +# noncompliant, but you have some other compliant shell such as ksh or +# bash, then to run this script, type that shell name before the whole +# command line, like: +# +# ksh Gradle +# +# Busybox and similar reduced shells will NOT work, because this script +# requires all of these POSIX shell features: +# * functions; +# * expansions «$var», «${var}», «${var:-default}», «${var+SET}», +# «${var#prefix}», «${var%suffix}», and «$( cmd )»; +# * compound commands having a testable exit status, especially «case»; +# * various built-in commands including «command», «set», and «ulimit». +# +# Important for patching: +# +# (2) This script targets any POSIX shell, so it avoids extensions provided +# by Bash, Ksh, etc; in particular arrays are avoided. +# +# The "traditional" practice of packing multiple parameters into a +# space-separated string is a well documented source of bugs and security +# problems, so this is (mostly) avoided, by progressively accumulating +# options in "$@", and eventually passing that to Java. +# +# Where the inherited environment variables (DEFAULT_JVM_OPTS, JAVA_OPTS, +# and GRADLE_OPTS) rely on word-splitting, this is performed explicitly; +# see the in-line comments for details. +# +# There are tweaks for specific operating systems such as AIX, CygWin, +# Darwin, MinGW, and NonStop. +# +# (3) This script is generated from the Groovy template +# https://github.com/gradle/gradle/blob/master/subprojects/plugins/src/main/resources/org/gradle/api/internal/plugins/unixStartScript.txt +# within the Gradle project. +# +# You can find Gradle at https://github.com/gradle/gradle/. +# ############################################################################## # Attempt to set APP_HOME + # Resolve links: $0 may be a link -PRG="$0" -# Need this for relative symlinks. -while [ -h "$PRG" ] ; do - ls=`ls -ld "$PRG"` - link=`expr "$ls" : '.*-> \(.*\)$'` - if expr "$link" : '/.*' > /dev/null; then - PRG="$link" - else - PRG=`dirname "$PRG"`"/$link" - fi +app_path=$0 + +# Need this for daisy-chained symlinks. +while + APP_HOME=${app_path%"${app_path##*/}"} # leaves a trailing /; empty if no leading path + [ -h "$app_path" ] +do + ls=$( ls -ld "$app_path" ) + link=${ls#*' -> '} + case $link in #( + /*) app_path=$link ;; #( + *) app_path=$APP_HOME$link ;; + esac done -SAVED="`pwd`" -cd "`dirname \"$PRG\"`/" >/dev/null -APP_HOME="`pwd -P`" -cd "$SAVED" >/dev/null + +APP_HOME=$( cd "${APP_HOME:-./}" && pwd -P ) || exit APP_NAME="Gradle" -APP_BASE_NAME=`basename "$0"` +APP_BASE_NAME=${0##*/} # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"' # Use the maximum available, or set MAX_FD != -1 to use that value. -MAX_FD="maximum" +MAX_FD=maximum warn () { echo "$*" -} +} >&2 die () { echo echo "$*" echo exit 1 -} +} >&2 # OS specific support (must be 'true' or 'false'). cygwin=false msys=false darwin=false nonstop=false -case "`uname`" in - CYGWIN* ) - cygwin=true - ;; - Darwin* ) - darwin=true - ;; - MINGW* ) - msys=true - ;; - NONSTOP* ) - nonstop=true - ;; +case "$( uname )" in #( + CYGWIN* ) cygwin=true ;; #( + Darwin* ) darwin=true ;; #( + MSYS* | MINGW* ) msys=true ;; #( + NONSTOP* ) nonstop=true ;; esac CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar @@ -87,9 +121,9 @@ CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar if [ -n "$JAVA_HOME" ] ; then if [ -x "$JAVA_HOME/jre/sh/java" ] ; then # IBM's JDK on AIX uses strange locations for the executables - JAVACMD="$JAVA_HOME/jre/sh/java" + JAVACMD=$JAVA_HOME/jre/sh/java else - JAVACMD="$JAVA_HOME/bin/java" + JAVACMD=$JAVA_HOME/bin/java fi if [ ! -x "$JAVACMD" ] ; then die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME @@ -98,7 +132,7 @@ Please set the JAVA_HOME variable in your environment to match the location of your Java installation." fi else - JAVACMD="java" + JAVACMD=java which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. Please set the JAVA_HOME variable in your environment to match the @@ -106,80 +140,95 @@ location of your Java installation." fi # Increase the maximum file descriptors if we can. -if [ "$cygwin" = "false" -a "$darwin" = "false" -a "$nonstop" = "false" ] ; then - MAX_FD_LIMIT=`ulimit -H -n` - if [ $? -eq 0 ] ; then - if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then - MAX_FD="$MAX_FD_LIMIT" - fi - ulimit -n $MAX_FD - if [ $? -ne 0 ] ; then - warn "Could not set maximum file descriptor limit: $MAX_FD" - fi - else - warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT" - fi +if ! "$cygwin" && ! "$darwin" && ! "$nonstop" ; then + case $MAX_FD in #( + max*) + MAX_FD=$( ulimit -H -n ) || + warn "Could not query maximum file descriptor limit" + esac + case $MAX_FD in #( + '' | soft) :;; #( + *) + ulimit -n "$MAX_FD" || + warn "Could not set maximum file descriptor limit to $MAX_FD" + esac fi -# For Darwin, add options to specify how the application appears in the dock -if $darwin; then - GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\"" -fi +# Collect all arguments for the java command, stacking in reverse order: +# * args from the command line +# * the main class name +# * -classpath +# * -D...appname settings +# * --module-path (only if needed) +# * DEFAULT_JVM_OPTS, JAVA_OPTS, and GRADLE_OPTS environment variables. # For Cygwin or MSYS, switch paths to Windows format before running java -if [ "$cygwin" = "true" -o "$msys" = "true" ] ; then - APP_HOME=`cygpath --path --mixed "$APP_HOME"` - CLASSPATH=`cygpath --path --mixed "$CLASSPATH"` - - JAVACMD=`cygpath --unix "$JAVACMD"` - - # We build the pattern for arguments to be converted via cygpath - ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null` - SEP="" - for dir in $ROOTDIRSRAW ; do - ROOTDIRS="$ROOTDIRS$SEP$dir" - SEP="|" - done - OURCYGPATTERN="(^($ROOTDIRS))" - # Add a user-defined pattern to the cygpath arguments - if [ "$GRADLE_CYGPATTERN" != "" ] ; then - OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)" - fi +if "$cygwin" || "$msys" ; then + APP_HOME=$( cygpath --path --mixed "$APP_HOME" ) + CLASSPATH=$( cygpath --path --mixed "$CLASSPATH" ) + + JAVACMD=$( cygpath --unix "$JAVACMD" ) + # Now convert the arguments - kludge to limit ourselves to /bin/sh - i=0 - for arg in "$@" ; do - CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -` - CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option - - if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition - eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"` - else - eval `echo args$i`="\"$arg\"" + for arg do + if + case $arg in #( + -*) false ;; # don't mess with options #( + /?*) t=${arg#/} t=/${t%%/*} # looks like a POSIX filepath + [ -e "$t" ] ;; #( + *) false ;; + esac + then + arg=$( cygpath --path --ignore --mixed "$arg" ) fi - i=`expr $i + 1` + # Roll the args list around exactly as many times as the number of + # args, so each arg winds up back in the position where it started, but + # possibly modified. + # + # NB: a `for` loop captures its iteration list before it begins, so + # changing the positional parameters here affects neither the number of + # iterations, nor the values presented in `arg`. + shift # remove old arg + set -- "$@" "$arg" # push replacement arg done - case $i in - 0) set -- ;; - 1) set -- "$args0" ;; - 2) set -- "$args0" "$args1" ;; - 3) set -- "$args0" "$args1" "$args2" ;; - 4) set -- "$args0" "$args1" "$args2" "$args3" ;; - 5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;; - 6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;; - 7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;; - 8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;; - 9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;; - esac fi -# Escape application args -save () { - for i do printf %s\\n "$i" | sed "s/'/'\\\\''/g;1s/^/'/;\$s/\$/' \\\\/" ; done - echo " " -} -APP_ARGS=`save "$@"` +# Collect all arguments for the java command; +# * $DEFAULT_JVM_OPTS, $JAVA_OPTS, and $GRADLE_OPTS can contain fragments of +# shell script including quotes and variable substitutions, so put them in +# double quotes to make sure that they get re-expanded; and +# * put everything else in single quotes, so that it's not re-expanded. + +set -- \ + "-Dorg.gradle.appname=$APP_BASE_NAME" \ + -classpath "$CLASSPATH" \ + org.gradle.wrapper.GradleWrapperMain \ + "$@" + +# Use "xargs" to parse quoted args. +# +# With -n1 it outputs one arg per line, with the quotes and backslashes removed. +# +# In Bash we could simply go: +# +# readarray ARGS < <( xargs -n1 <<<"$var" ) && +# set -- "${ARGS[@]}" "$@" +# +# but POSIX shell has neither arrays nor command substitution, so instead we +# post-process each arg (as a line of input to sed) to backslash-escape any +# character that might be a shell metacharacter, then use eval to reverse +# that process (while maintaining the separation between arguments), and wrap +# the whole thing up as a single "set" statement. +# +# This will of course break if any of these variables contains a newline or +# an unmatched quote. +# -# Collect all arguments for the java command, following the shell quoting and substitution rules -eval set -- $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS "\"-Dorg.gradle.appname=$APP_BASE_NAME\"" -classpath "\"$CLASSPATH\"" org.gradle.wrapper.GradleWrapperMain "$APP_ARGS" +eval "set -- $( + printf '%s\n' "$DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS" | + xargs -n1 | + sed ' s~[^-[:alnum:]+,./:=@_]~\\&~g; ' | + tr '\n' ' ' + )" '"$@"' exec "$JAVACMD" "$@" From 7867f96901d04048fa22a13306f2b606bf5aad17 Mon Sep 17 00:00:00 2001 From: Ned Twigg Date: Wed, 27 Jul 2022 15:32:22 -0700 Subject: [PATCH 202/757] Add a test that triggers the StableConfigurationCache bug. --- .../com/diffplug/gradle/spotless/ConfigurationCacheTest.java | 5 +++-- .../diffplug/gradle/spotless/GradleIntegrationHarness.java | 4 +++- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/ConfigurationCacheTest.java b/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/ConfigurationCacheTest.java index 14b6de7702..4006752af2 100644 --- a/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/ConfigurationCacheTest.java +++ b/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/ConfigurationCacheTest.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. @@ -25,7 +25,8 @@ public class ConfigurationCacheTest extends GradleIntegrationHarness { @Override protected GradleRunner gradleRunner() throws IOException { setFile("gradle.properties").toContent("org.gradle.unsafe.configuration-cache=true"); - return super.gradleRunner().withGradleVersion(GradleVersionSupport.CONFIGURATION_CACHE.version); + setFile("settings.gradle").toContent("enableFeaturePreview(\"STABLE_CONFIGURATION_CACHE\")"); + return super.gradleRunner().withGradleVersion(GradleVersionSupport.STABLE_CONFIGURATION_CACHE.version); } @Test diff --git a/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/GradleIntegrationHarness.java b/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/GradleIntegrationHarness.java index 98b1e1cbf9..d9a81d2629 100644 --- a/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/GradleIntegrationHarness.java +++ b/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/GradleIntegrationHarness.java @@ -43,7 +43,9 @@ public class GradleIntegrationHarness extends ResourceHarness { public enum GradleVersionSupport { JRE_11("5.0"), MINIMUM(SpotlessPlugin.MINIMUM_GRADLE), // technically, this API exists in 6.5, but the flags for it change in 6.6, so we build to that - CONFIGURATION_CACHE("6.6"); + CONFIGURATION_CACHE("6.6"), + // https://docs.gradle.org/7.5/userguide/configuration_cache.html#config_cache:stable + STABLE_CONFIGURATION_CACHE("7.5"); final String version; From 9ab5fe78f11d1763a6813df1787cdbc791e6b600 Mon Sep 17 00:00:00 2001 From: Ned Twigg Date: Wed, 27 Jul 2022 15:33:51 -0700 Subject: [PATCH 203/757] Call Task.usesService wherever the service is used. --- .../com/diffplug/gradle/spotless/RegisterDependenciesTask.java | 3 ++- .../java/com/diffplug/gradle/spotless/SpotlessTaskImpl.java | 3 ++- .../java/com/diffplug/gradle/spotless/SpotlessTaskService.java | 3 ++- 3 files changed, 6 insertions(+), 3 deletions(-) diff --git a/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/RegisterDependenciesTask.java b/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/RegisterDependenciesTask.java index a3fbdf4a81..69d3ee7525 100644 --- a/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/RegisterDependenciesTask.java +++ b/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/RegisterDependenciesTask.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. @@ -64,6 +64,7 @@ void setup() { String compositeBuildSuffix = getName().substring(TASK_NAME.length()); // see https://github.com/diffplug/spotless/pull/1001 BuildServiceRegistry buildServices = getProject().getGradle().getSharedServices(); getTaskService().set(buildServices.registerIfAbsent("SpotlessTaskService" + compositeBuildSuffix, SpotlessTaskService.class, spec -> {})); + usesService(getTaskService()); getBuildEventsListenerRegistry().onTaskCompletion(getTaskService()); unitOutput = new File(getProject().getBuildDir(), "tmp/spotless-register-dependencies"); } diff --git a/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/SpotlessTaskImpl.java b/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/SpotlessTaskImpl.java index 1b9cda204c..f776603fcc 100644 --- a/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/SpotlessTaskImpl.java +++ b/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/SpotlessTaskImpl.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. @@ -46,6 +46,7 @@ public abstract class SpotlessTaskImpl extends SpotlessTask { abstract DirectoryProperty getProjectDir(); void init(Provider service) { + usesService(service); getTaskService().set(service); getProjectDir().set(getProject().getProjectDir()); } diff --git a/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/SpotlessTaskService.java b/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/SpotlessTaskService.java index 7fc0ea3775..c6b6c261bc 100644 --- a/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/SpotlessTaskService.java +++ b/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/SpotlessTaskService.java @@ -1,5 +1,5 @@ /* - * Copyright 2021 DiffPlug + * Copyright 2021-2022 DiffPlug * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -105,6 +105,7 @@ static abstract class ClientTask extends DefaultTask { protected abstract ObjectFactory getConfigCacheWorkaround(); void init(SpotlessTaskImpl impl) { + usesService(impl.getTaskService()); getSpotlessOutDirectory().set(impl.getOutputDirectory()); getTaskService().set(impl.getTaskService()); getProjectDir().set(impl.getProjectDir()); From 3d12cb04068f586c16bfe61a88c72e14a1a68bb3 Mon Sep 17 00:00:00 2001 From: Ned Twigg Date: Wed, 27 Jul 2022 15:52:41 -0700 Subject: [PATCH 204/757] Workaround to preserve `instanceof BuildServiceProvider` (blech, see #1260 for my complaint). --- .../gradle/spotless/RegisterDependenciesTask.java | 15 ++++++++++----- .../gradle/spotless/SpotlessTaskImpl.java | 9 +++++++++ .../gradle/spotless/SpotlessTaskService.java | 2 +- 3 files changed, 20 insertions(+), 6 deletions(-) diff --git a/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/RegisterDependenciesTask.java b/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/RegisterDependenciesTask.java index 69d3ee7525..75bd06406b 100644 --- a/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/RegisterDependenciesTask.java +++ b/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/RegisterDependenciesTask.java @@ -24,7 +24,7 @@ import javax.inject.Inject; import org.gradle.api.DefaultTask; -import org.gradle.api.provider.Property; +import org.gradle.api.provider.Provider; import org.gradle.api.services.BuildServiceRegistry; import org.gradle.api.tasks.Input; import org.gradle.api.tasks.Internal; @@ -63,9 +63,9 @@ void setup() { Preconditions.checkArgument(getProject().getRootProject() == getProject(), "Can only be used on the root project"); String compositeBuildSuffix = getName().substring(TASK_NAME.length()); // see https://github.com/diffplug/spotless/pull/1001 BuildServiceRegistry buildServices = getProject().getGradle().getSharedServices(); - getTaskService().set(buildServices.registerIfAbsent("SpotlessTaskService" + compositeBuildSuffix, SpotlessTaskService.class, spec -> {})); - usesService(getTaskService()); - getBuildEventsListenerRegistry().onTaskCompletion(getTaskService()); + taskService = buildServices.registerIfAbsent("SpotlessTaskService" + compositeBuildSuffix, SpotlessTaskService.class, spec -> {}); + usesService(taskService); + getBuildEventsListenerRegistry().onTaskCompletion(taskService); unitOutput = new File(getProject().getBuildDir(), "tmp/spotless-register-dependencies"); } @@ -89,8 +89,13 @@ public void trivialFunction() throws IOException { Files.write(Integer.toString(1), unitOutput, StandardCharsets.UTF_8); } + // this field is stupid, but we need it, see https://github.com/diffplug/spotless/issues/1260 + private Provider taskService; + @Internal - abstract Property getTaskService(); + public Provider getTaskService() { + return taskService; + } @Inject protected abstract BuildEventsListenerRegistry getBuildEventsListenerRegistry(); diff --git a/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/SpotlessTaskImpl.java b/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/SpotlessTaskImpl.java index f776603fcc..b37e9f283a 100644 --- a/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/SpotlessTaskImpl.java +++ b/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/SpotlessTaskImpl.java @@ -46,11 +46,20 @@ public abstract class SpotlessTaskImpl extends SpotlessTask { abstract DirectoryProperty getProjectDir(); void init(Provider service) { + taskServiceProvider = service; usesService(service); getTaskService().set(service); getProjectDir().set(getProject().getProjectDir()); } + // this field is stupid, but we need it, see https://github.com/diffplug/spotless/issues/1260 + private transient Provider taskServiceProvider; + + @Internal + Provider getTaskServiceProvider() { + return taskServiceProvider; + } + @Inject protected abstract FileSystemOperations getFs(); diff --git a/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/SpotlessTaskService.java b/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/SpotlessTaskService.java index c6b6c261bc..67de4b946c 100644 --- a/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/SpotlessTaskService.java +++ b/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/SpotlessTaskService.java @@ -105,7 +105,7 @@ static abstract class ClientTask extends DefaultTask { protected abstract ObjectFactory getConfigCacheWorkaround(); void init(SpotlessTaskImpl impl) { - usesService(impl.getTaskService()); + usesService(impl.getTaskServiceProvider()); getSpotlessOutDirectory().set(impl.getOutputDirectory()); getTaskService().set(impl.getTaskService()); getProjectDir().set(impl.getProjectDir()); From 06a09fce2b72e8c267d0d08f683ae53b2d546402 Mon Sep 17 00:00:00 2001 From: Ned Twigg Date: Wed, 27 Jul 2022 16:05:15 -0700 Subject: [PATCH 205/757] Update changelog. --- plugin-gradle/CHANGES.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/plugin-gradle/CHANGES.md b/plugin-gradle/CHANGES.md index 43a1fb1d24..d38d6ee70a 100644 --- a/plugin-gradle/CHANGES.md +++ b/plugin-gradle/CHANGES.md @@ -5,6 +5,8 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format ( ## [Unreleased] ### Added * Clang and Black no longer break the build when the binary is unavailable, if they will not be run during that build ([#1257](https://github.com/diffplug/spotless/pull/1257)). +### Fixed +* Warnings about missing `Task#usesService` for Gradle 8.0 ([#1262](https://github.com/diffplug/spotless/pull/1262) fixes [#1260](https://github.com/diffplug/spotless/issues/1260)) ## [6.8.0] - 2022-06-30 ### Added From 640f6a23cafa3dc06f17bba623ef7c9d435be36c Mon Sep 17 00:00:00 2001 From: Ned Twigg Date: Wed, 27 Jul 2022 16:13:04 -0700 Subject: [PATCH 206/757] Change groovy-xml to match Gradle 7.5 (very worried this is going to break older releases). --- lib-extra/build.gradle | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib-extra/build.gradle b/lib-extra/build.gradle index 1f6fdd8962..4fe7f7c250 100644 --- a/lib-extra/build.gradle +++ b/lib-extra/build.gradle @@ -15,7 +15,7 @@ dependencies { implementation "org.eclipse.jgit:org.eclipse.jgit:${VER_JGIT}" implementation "com.googlecode.concurrent-trees:concurrent-trees:2.6.1" // used for xml parsing in EclipseFormatter - implementation "org.codehaus.groovy:groovy-xml:3.0.9" + implementation "org.codehaus.groovy:groovy-xml:3.0.10" // testing testImplementation project(':testlib') From e386e9313afd523f44113464a679d7999ff7e05e Mon Sep 17 00:00:00 2001 From: Ned Twigg Date: Wed, 27 Jul 2022 22:41:28 -0700 Subject: [PATCH 207/757] Fix test on Java 17 for new groovy. --- lib-extra/build.gradle | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/lib-extra/build.gradle b/lib-extra/build.gradle index 4fe7f7c250..3757dbc91d 100644 --- a/lib-extra/build.gradle +++ b/lib-extra/build.gradle @@ -27,4 +27,10 @@ dependencies { // we'll hold the core lib to a high standard spotbugs { reportLevel = 'low' } // low|medium|high (low = sensitive to even minor mistakes) -test { useJUnitPlatform() } +test { + useJUnitPlatform() + if (JavaVersion.current().isCompatibleWith(JavaVersion.VERSION_17)) { + // needed for EclipseCdtFormatterStepTest + jvmArgs '--add-opens=java.base/java.lang=ALL-UNNAMED' + } +} From 6a786a2d46f562f84eb313919efe77494a453a6d Mon Sep 17 00:00:00 2001 From: Ned Twigg Date: Wed, 27 Jul 2022 23:11:03 -0700 Subject: [PATCH 208/757] Fix GradleVersion forced-upgrade for minimum required JRE. --- .../spotless/GradleIntegrationHarness.java | 21 +++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) diff --git a/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/GradleIntegrationHarness.java b/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/GradleIntegrationHarness.java index d9a81d2629..6cc35290db 100644 --- a/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/GradleIntegrationHarness.java +++ b/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/GradleIntegrationHarness.java @@ -29,6 +29,7 @@ import org.gradle.testkit.runner.BuildTask; import org.gradle.testkit.runner.GradleRunner; import org.gradle.testkit.runner.TaskOutcome; +import org.gradle.util.GradleVersion; import org.junit.jupiter.api.BeforeEach; import com.diffplug.common.base.Errors; @@ -50,27 +51,35 @@ public enum GradleVersionSupport { final String version; GradleVersionSupport(String version) { + String minVersionForRunningJRE; switch (Jvm.version()) { case 20: case 19: - case 18: // TODO: https://docs.gradle.org/current/userguide/compatibility.html + case 18: + minVersionForRunningJRE = "7.5"; + break; case 17: - this.version = "7.3"; + minVersionForRunningJRE = "7.3"; break; case 16: - this.version = "7.0"; + minVersionForRunningJRE = "7.0"; break; case 15: - this.version = "6.7"; + minVersionForRunningJRE = "6.7"; break; case 14: - this.version = "6.3"; + minVersionForRunningJRE = "6.3"; break; default: - this.version = version; + minVersionForRunningJRE = null; break; } + if (minVersionForRunningJRE != null && GradleVersion.version(minVersionForRunningJRE).compareTo(GradleVersion.version(version)) > 0) { + this.version = minVersionForRunningJRE; + } else { + this.version = version; + } } } From 9831c5962a91a7d9eae08a9fea305c632c06bb3f Mon Sep 17 00:00:00 2001 From: Omico Date: Wed, 27 Jul 2022 23:13:36 -0700 Subject: [PATCH 209/757] Support adding license header for classes without package name --- .../main/java/com/diffplug/spotless/kotlin/KotlinConstants.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/src/main/java/com/diffplug/spotless/kotlin/KotlinConstants.java b/lib/src/main/java/com/diffplug/spotless/kotlin/KotlinConstants.java index 5df0231b8d..a7fc413f94 100644 --- a/lib/src/main/java/com/diffplug/spotless/kotlin/KotlinConstants.java +++ b/lib/src/main/java/com/diffplug/spotless/kotlin/KotlinConstants.java @@ -18,7 +18,7 @@ public final class KotlinConstants { // '^' is prepended to the regex in LICENSE_HEADER_DELIMITER later in FormatExtension.licenseHeader(String, String) - public static final String LICENSE_HEADER_DELIMITER = "(package |@file)"; + public static final String LICENSE_HEADER_DELIMITER = "(package |@file|import )"; private KotlinConstants() {} } From f6b85902308e46c0836c30df848526bf4ff0e57d Mon Sep 17 00:00:00 2001 From: Ned Twigg Date: Wed, 27 Jul 2022 23:30:25 -0700 Subject: [PATCH 210/757] The standard tests need the fix for the new Groovy too. --- lib-extra/build.gradle | 2 +- testlib/build.gradle | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/lib-extra/build.gradle b/lib-extra/build.gradle index 3757dbc91d..38e7c37403 100644 --- a/lib-extra/build.gradle +++ b/lib-extra/build.gradle @@ -29,7 +29,7 @@ spotbugs { reportLevel = 'low' } // low|medium|high (low = sensitive to even min test { useJUnitPlatform() - if (JavaVersion.current().isCompatibleWith(JavaVersion.VERSION_17)) { + if (JavaVersion.current().isCompatibleWith(JavaVersion.VERSION_16)) { // needed for EclipseCdtFormatterStepTest jvmArgs '--add-opens=java.base/java.lang=ALL-UNNAMED' } diff --git a/testlib/build.gradle b/testlib/build.gradle index 8e0a012882..30c44ece23 100644 --- a/testlib/build.gradle +++ b/testlib/build.gradle @@ -30,7 +30,8 @@ test { '--add-exports=jdk.compiler/com.sun.tools.javac.file=ALL-UNNAMED', '--add-exports=jdk.compiler/com.sun.tools.javac.parser=ALL-UNNAMED', '--add-exports=jdk.compiler/com.sun.tools.javac.tree=ALL-UNNAMED', - '--add-exports=jdk.compiler/com.sun.tools.javac.util=ALL-UNNAMED' + '--add-exports=jdk.compiler/com.sun.tools.javac.util=ALL-UNNAMED', + '--add-opens=java.base/java.lang=ALL-UNNAMED' ] jvmArgs args } From 8715f50537479e629df371679b2b1049ee66c9ea Mon Sep 17 00:00:00 2001 From: Ned Twigg Date: Thu, 28 Jul 2022 00:13:04 -0700 Subject: [PATCH 211/757] Update changelogs. --- CHANGES.md | 1 + plugin-gradle/CHANGES.md | 1 + plugin-maven/CHANGES.md | 1 + 3 files changed, 3 insertions(+) diff --git a/CHANGES.md b/CHANGES.md index bed2af6281..8c079e0c4d 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -12,6 +12,7 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format ( ## [Unreleased] ### Added * Clang and Black no longer break the build when the binary is unavailable, if they will not be run during that build ([#1257](https://github.com/diffplug/spotless/pull/1257)). +* License header support for Kotlin files without `package` or `@file` but do at least have `import` ([#1263](https://github.com/diffplug/spotless/pull/1263)). ## [2.27.0] - 2022-06-30 ### Added diff --git a/plugin-gradle/CHANGES.md b/plugin-gradle/CHANGES.md index d38d6ee70a..1653838a3a 100644 --- a/plugin-gradle/CHANGES.md +++ b/plugin-gradle/CHANGES.md @@ -5,6 +5,7 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format ( ## [Unreleased] ### Added * Clang and Black no longer break the build when the binary is unavailable, if they will not be run during that build ([#1257](https://github.com/diffplug/spotless/pull/1257)). +* License header support for Kotlin files without `package` or `@file` but do at least have `import` ([#1263](https://github.com/diffplug/spotless/pull/1263)). ### Fixed * Warnings about missing `Task#usesService` for Gradle 8.0 ([#1262](https://github.com/diffplug/spotless/pull/1262) fixes [#1260](https://github.com/diffplug/spotless/issues/1260)) diff --git a/plugin-maven/CHANGES.md b/plugin-maven/CHANGES.md index 3499aeab36..732489f81f 100644 --- a/plugin-maven/CHANGES.md +++ b/plugin-maven/CHANGES.md @@ -5,6 +5,7 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format ( ## [Unreleased] ### Added * Clang and Black no longer break the build when the binary is unavailable, if they will not be run during that build ([#1257](https://github.com/diffplug/spotless/pull/1257)). +* License header support for Kotlin files without `package` or `@file` but do at least have `import` ([#1263](https://github.com/diffplug/spotless/pull/1263)). ## [2.23.0] - 2022-06-30 ### Added From 6d6b09d2d3217e0d59aa5327035a4db5eb338e61 Mon Sep 17 00:00:00 2001 From: Ned Twigg Date: Thu, 28 Jul 2022 00:13:14 -0700 Subject: [PATCH 212/757] spotlessApply --- .../main/java/com/diffplug/spotless/kotlin/KotlinConstants.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/src/main/java/com/diffplug/spotless/kotlin/KotlinConstants.java b/lib/src/main/java/com/diffplug/spotless/kotlin/KotlinConstants.java index a7fc413f94..da2240f16c 100644 --- a/lib/src/main/java/com/diffplug/spotless/kotlin/KotlinConstants.java +++ b/lib/src/main/java/com/diffplug/spotless/kotlin/KotlinConstants.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. From d6e767a2dfa91a0c24464a093d2827d7d1dd9ec0 Mon Sep 17 00:00:00 2001 From: Ned Twigg Date: Thu, 28 Jul 2022 00:45:46 -0700 Subject: [PATCH 213/757] Adapt gradle plugin publishing for the new 1.0 plugin-publish plugin. --- plugin-gradle/build.gradle | 13 ------------- 1 file changed, 13 deletions(-) diff --git a/plugin-gradle/build.gradle b/plugin-gradle/build.gradle index 3a5afd2ba8..8fec4beb92 100644 --- a/plugin-gradle/build.gradle +++ b/plugin-gradle/build.gradle @@ -77,19 +77,6 @@ if (version.endsWith('-SNAPSHOT')) { 'black', 'clang-format' ] - plugins { - spotlessPlugin { - id = 'com.diffplug.spotless' - } - spotlessPluginLegacy { - id = 'com.diffplug.gradle.spotless' - } - } - mavenCoordinates { - groupId = project.group - artifactId = project.artifactIdGradle - version = project.version - } } } From a474435ae70036140d446644d641a682ae20672d Mon Sep 17 00:00:00 2001 From: circleci Date: Thu, 28 Jul 2022 07:50:49 +0000 Subject: [PATCH 214/757] Published lib/2.28.0 --- CHANGES.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/CHANGES.md b/CHANGES.md index 8c079e0c4d..d57135685f 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -10,6 +10,8 @@ This document is intended for Spotless developers. We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format (starting after version `1.27.0`). ## [Unreleased] + +## [2.28.0] - 2022-07-28 ### Added * Clang and Black no longer break the build when the binary is unavailable, if they will not be run during that build ([#1257](https://github.com/diffplug/spotless/pull/1257)). * License header support for Kotlin files without `package` or `@file` but do at least have `import` ([#1263](https://github.com/diffplug/spotless/pull/1263)). From 4085c79c0fdced5bfa80d4347c096f6cecb16e36 Mon Sep 17 00:00:00 2001 From: circleci Date: Thu, 28 Jul 2022 07:52:01 +0000 Subject: [PATCH 215/757] Published gradle/6.9.0 --- plugin-gradle/CHANGES.md | 2 ++ plugin-gradle/README.md | 46 ++++++++++++++++++++-------------------- 2 files changed, 25 insertions(+), 23 deletions(-) diff --git a/plugin-gradle/CHANGES.md b/plugin-gradle/CHANGES.md index 1653838a3a..d7d434a90d 100644 --- a/plugin-gradle/CHANGES.md +++ b/plugin-gradle/CHANGES.md @@ -3,6 +3,8 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format (starting after version `3.27.0`). ## [Unreleased] + +## [6.9.0] - 2022-07-28 ### Added * Clang and Black no longer break the build when the binary is unavailable, if they will not be run during that build ([#1257](https://github.com/diffplug/spotless/pull/1257)). * License header support for Kotlin files without `package` or `@file` but do at least have `import` ([#1263](https://github.com/diffplug/spotless/pull/1263)). diff --git a/plugin-gradle/README.md b/plugin-gradle/README.md index 1e103a0a81..8b8e5372e6 100644 --- a/plugin-gradle/README.md +++ b/plugin-gradle/README.md @@ -18,9 +18,9 @@ output = [ --> [![Gradle plugin](https://img.shields.io/badge/plugins.gradle.org-com.diffplug.spotless-blue.svg)](https://plugins.gradle.org/plugin/com.diffplug.spotless) [![Maven central](https://img.shields.io/badge/mavencentral-yes-blue.svg)](https://search.maven.org/#search%7Cgav%7C1%7Cg%3A%22com.diffplug.spotless%22%20AND%20a%3A%22spotless-plugin-gradle%22) -[![Javadoc](https://img.shields.io/badge/javadoc-yes-blue.svg)](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.8.0/index.html) +[![Javadoc](https://img.shields.io/badge/javadoc-yes-blue.svg)](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.9.0/index.html) [![License Apache](https://img.shields.io/badge/license-apache-blue.svg)](https://tldrlegal.com/license/apache-license-2.0-(apache-2.0)) -[![Changelog](https://img.shields.io/badge/changelog-6.8.0-blue.svg)](CHANGES.md) +[![Changelog](https://img.shields.io/badge/changelog-6.9.0-blue.svg)](CHANGES.md) [![Circle CI](https://circleci.com/gh/diffplug/spotless/tree/main.svg?style=shield)](https://circleci.com/gh/diffplug/spotless/tree/main) [![Live chat](https://img.shields.io/badge/gitter-chat-brightgreen.svg)](https://gitter.im/diffplug/spotless) @@ -126,10 +126,10 @@ spotless { ``` Spotless consists of a list of formats (in the example above, `misc` and `java`), and each format has: -- a `target` (the files to format), which you set with [`target`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.8.0/com/diffplug/gradle/spotless/FormatExtension.html#target-java.lang.Object...-) and [`targetExclude`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.8.0/com/diffplug/gradle/spotless/FormatExtension.html#targetExclude-java.lang.Object...-) -- a list of `FormatterStep`, which are just `String -> String` functions, such as [`replace`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.8.0/com/diffplug/gradle/spotless/FormatExtension.html#replace-java.lang.String-java.lang.CharSequence-java.lang.CharSequence-), [`replaceRegex`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.8.0/com/diffplug/gradle/spotless/FormatExtension.html#replaceRegex-java.lang.String-java.lang.String-java.lang.String-), [`trimTrailingWhitespace`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.8.0/com/diffplug/gradle/spotless/FormatExtension.html#replace-java.lang.String-java.lang.CharSequence-java.lang.CharSequence-), [`custom`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.8.0/com/diffplug/gradle/spotless/FormatExtension.html#custom-java.lang.String-groovy.lang.Closure-), [`prettier`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.8.0/com/diffplug/gradle/spotless/FormatExtension.html#prettier--), [`eclipseWtp`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.8.0/com/diffplug/gradle/spotless/FormatExtension.html#eclipseWtp-com.diffplug.spotless.extra.wtp.EclipseWtpFormatterStep-), [`licenseHeader`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.8.0/com/diffplug/gradle/spotless/FormatExtension.html#licenseHeader-java.lang.String-java.lang.String-) etc. +- a `target` (the files to format), which you set with [`target`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.9.0/com/diffplug/gradle/spotless/FormatExtension.html#target-java.lang.Object...-) and [`targetExclude`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.9.0/com/diffplug/gradle/spotless/FormatExtension.html#targetExclude-java.lang.Object...-) +- a list of `FormatterStep`, which are just `String -> String` functions, such as [`replace`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.9.0/com/diffplug/gradle/spotless/FormatExtension.html#replace-java.lang.String-java.lang.CharSequence-java.lang.CharSequence-), [`replaceRegex`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.9.0/com/diffplug/gradle/spotless/FormatExtension.html#replaceRegex-java.lang.String-java.lang.String-java.lang.String-), [`trimTrailingWhitespace`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.9.0/com/diffplug/gradle/spotless/FormatExtension.html#replace-java.lang.String-java.lang.CharSequence-java.lang.CharSequence-), [`custom`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.9.0/com/diffplug/gradle/spotless/FormatExtension.html#custom-java.lang.String-groovy.lang.Closure-), [`prettier`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.9.0/com/diffplug/gradle/spotless/FormatExtension.html#prettier--), [`eclipseWtp`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.9.0/com/diffplug/gradle/spotless/FormatExtension.html#eclipseWtp-com.diffplug.spotless.extra.wtp.EclipseWtpFormatterStep-), [`licenseHeader`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.9.0/com/diffplug/gradle/spotless/FormatExtension.html#licenseHeader-java.lang.String-java.lang.String-) etc. -All the generic steps live in [`FormatExtension`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.8.0/com/diffplug/gradle/spotless/FormatExtension.html), and there are many language-specific steps which live in its language-specific subclasses, which are described below. +All the generic steps live in [`FormatExtension`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.9.0/com/diffplug/gradle/spotless/FormatExtension.html), and there are many language-specific steps which live in its language-specific subclasses, which are described below. ### Requirements @@ -141,7 +141,7 @@ If you're stuck on an older version of Gradle, `id 'com.diffplug.gradle.spotless ## Java -`com.diffplug.gradle.spotless.JavaExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.8.0/com/diffplug/gradle/spotless/JavaExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/JavaExtension.java) +`com.diffplug.gradle.spotless.JavaExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.9.0/com/diffplug/gradle/spotless/JavaExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/JavaExtension.java) ```gradle spotless { @@ -248,8 +248,8 @@ spotless { ## Groovy -- `com.diffplug.gradle.spotless.GroovyExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.8.0/com/diffplug/gradle/spotless/GroovyExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/GroovyExtension.java) -- `com.diffplug.gradle.spotless.GroovyGradleExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.8.0/com/diffplug/gradle/spotless/GroovyGradleExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/GroovyGradleExtension.java) +- `com.diffplug.gradle.spotless.GroovyExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.9.0/com/diffplug/gradle/spotless/GroovyExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/GroovyExtension.java) +- `com.diffplug.gradle.spotless.GroovyGradleExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.9.0/com/diffplug/gradle/spotless/GroovyGradleExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/GroovyGradleExtension.java) Configuration for Groovy is similar to [Java](#java), in that it also supports `licenseHeader` and `importOrder`. @@ -300,8 +300,8 @@ Groovy-Eclipse formatting errors/warnings lead per default to a build failure. T ## Kotlin -- `com.diffplug.gradle.spotless.KotlinExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.8.0/com/diffplug/gradle/spotless/KotlinExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/KotlinExtension.java) -- `com.diffplug.gradle.spotless.KotlinGradleExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.8.0/com/diffplug/gradle/spotless/KotlinGradleExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/KotlinGradleExtension.java) +- `com.diffplug.gradle.spotless.KotlinExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.9.0/com/diffplug/gradle/spotless/KotlinExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/KotlinExtension.java) +- `com.diffplug.gradle.spotless.KotlinGradleExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.9.0/com/diffplug/gradle/spotless/KotlinGradleExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/KotlinGradleExtension.java) ```gradle spotless { // if you are using build.gradle.kts, instead of 'spotless {' use: @@ -364,7 +364,7 @@ spotless { ## Scala -`com.diffplug.gradle.spotless.ScalaExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.8.0/com/diffplug/gradle/spotless/ScalaExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/ScalaExtension.java) +`com.diffplug.gradle.spotless.ScalaExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.9.0/com/diffplug/gradle/spotless/ScalaExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/ScalaExtension.java) ```gradle spotless { @@ -396,7 +396,7 @@ spotless { ## C/C++ -`com.diffplug.gradle.spotless.CppExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.8.0/com/diffplug/gradle/spotless/CppExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/CppExtension.java) +`com.diffplug.gradle.spotless.CppExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.9.0/com/diffplug/gradle/spotless/CppExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/CppExtension.java) ```gradle spotless { @@ -428,7 +428,7 @@ spotles { ## Python -`com.diffplug.gradle.spotless.PythonExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.8.0/com/diffplug/gradle/spotless/PythonExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/PythonExtension.java) +`com.diffplug.gradle.spotless.PythonExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.9.0/com/diffplug/gradle/spotless/PythonExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/PythonExtension.java) ```gradle spotless { @@ -462,7 +462,7 @@ black().pathToExe('C:/myuser/.pyenv/versions/3.8.0/scripts/black.exe') ## FreshMark -`com.diffplug.gradle.spotless.FreshMarkExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.8.0/com/diffplug/gradle/spotless/FreshMarkExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/FreshMarkExtension.java) +`com.diffplug.gradle.spotless.FreshMarkExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.9.0/com/diffplug/gradle/spotless/FreshMarkExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/FreshMarkExtension.java) [homepage](https://github.com/diffplug/freshmark). [changelog](https://github.com/diffplug/freshmark/blob/master/CHANGES.md). FreshMark lets you generate markdown in the comments of your markdown. This helps to keep badges and links up-to-date (see the source for this file), and can also be helpful for generating complex tables (see the source for [the parent readme](../README.md)). @@ -483,7 +483,7 @@ spotless { ## Antlr4 -`com.diffplug.gradle.spotless.Antlr4Extension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.8.0/com/diffplug/gradle/spotless/Antlr4Extension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/Antlr4Extension.java) +`com.diffplug.gradle.spotless.Antlr4Extension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.9.0/com/diffplug/gradle/spotless/Antlr4Extension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/Antlr4Extension.java) ```gradle spotless { @@ -508,7 +508,7 @@ antlr4formatter('1.2.1') // version is optional ## SQL -`com.diffplug.gradle.spotless.SqlExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.8.0/com/diffplug/gradle/spotless/SqlExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/SqlExtension.java) +`com.diffplug.gradle.spotless.SqlExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.9.0/com/diffplug/gradle/spotless/SqlExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/SqlExtension.java) ```gradle spotless { @@ -548,7 +548,7 @@ sql.formatter.indent.size=4 ## Typescript -- `com.diffplug.gradle.spotless.TypescriptExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.8.0/com/diffplug/gradle/spotless/TypescriptExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/TypescriptExtension.java) +- `com.diffplug.gradle.spotless.TypescriptExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.9.0/com/diffplug/gradle/spotless/TypescriptExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/TypescriptExtension.java) ```gradle spotless { @@ -591,7 +591,7 @@ For details, see the [npm detection](#npm-detection) and [`.npmrc` detection](#n ## JSON -- `com.diffplug.gradle.spotless.JsonExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.8.0/com/diffplug/gradle/spotless/JsonExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/JsonExtension.java) +- `com.diffplug.gradle.spotless.JsonExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.9.0/com/diffplug/gradle/spotless/JsonExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/JsonExtension.java) ```gradle spotless { @@ -816,7 +816,7 @@ Once a file's license header has a valid year, whether it is a year (`2020`) or * `2017` -> `2017-2020` * `2017-2019` -> `2017-2020` -See the [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.8.0/com/diffplug/gradle/spotless/FormatExtension.LicenseHeaderConfig.html) for a complete listing of options. +See the [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.9.0/com/diffplug/gradle/spotless/FormatExtension.LicenseHeaderConfig.html) for a complete listing of options. @@ -883,9 +883,9 @@ spotless { custom 'lowercase', { str -> str.toLowerCase() } ``` -However, custom rules will disable up-to-date checking and caching, unless you read [this javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.8.0/com/diffplug/gradle/spotless/FormatExtension.html#bumpThisNumberIfACustomStepChanges-int-) and follow its instructions carefully. +However, custom rules will disable up-to-date checking and caching, unless you read [this javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.9.0/com/diffplug/gradle/spotless/FormatExtension.html#bumpThisNumberIfACustomStepChanges-int-) and follow its instructions carefully. -Another option is to create proper `FormatterStep` in your `buildSrc`, and then call [`addStep`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.8.0/com/diffplug/gradle/spotless/FormatExtension.html#addStep-com.diffplug.spotless.FormatterStep-). The contributing guide describes [how to do this](https://github.com/diffplug/spotless/blob/main/CONTRIBUTING.md#how-to-add-a-new-formatterstep). If the step is generally-useful, we hope you'll open a PR to share it! +Another option is to create proper `FormatterStep` in your `buildSrc`, and then call [`addStep`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.9.0/com/diffplug/gradle/spotless/FormatExtension.html#addStep-com.diffplug.spotless.FormatterStep-). The contributing guide describes [how to do this](https://github.com/diffplug/spotless/blob/main/CONTRIBUTING.md#how-to-add-a-new-formatterstep). If the step is generally-useful, we hope you'll open a PR to share it! ```gradle @@ -918,11 +918,11 @@ spotless { format 'foo', com.acme.FooLanguageExtension, { ``` -If you'd like to create a one-off Spotless task outside of the `check`/`apply` framework, see [`FormatExtension.createIndependentApplyTask`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.8.0/com/diffplug/gradle/spotless/FormatExtension.html#createIndependentApplyTask-java.lang.String-). +If you'd like to create a one-off Spotless task outside of the `check`/`apply` framework, see [`FormatExtension.createIndependentApplyTask`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.9.0/com/diffplug/gradle/spotless/FormatExtension.html#createIndependentApplyTask-java.lang.String-). ## Inception (languages within languages within...) -In very rare cases, you might want to format e.g. javascript which is written inside JSP templates, or maybe java within a markdown file, or something wacky like that. You can specify hunks within a file using either open/close tags or a regex with a single capturing group, and then specify rules within it, like so. See [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.8.0/com/diffplug/gradle/spotless/FormatExtension.html#withinBlocks-java.lang.String-java.lang.String-java.lang.String-org.gradle.api.Action-) for more details. +In very rare cases, you might want to format e.g. javascript which is written inside JSP templates, or maybe java within a markdown file, or something wacky like that. You can specify hunks within a file using either open/close tags or a regex with a single capturing group, and then specify rules within it, like so. See [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.9.0/com/diffplug/gradle/spotless/FormatExtension.html#withinBlocks-java.lang.String-java.lang.String-java.lang.String-org.gradle.api.Action-) for more details. ```gradle import com.diffplug.gradle.spotless.JavaExtension From 3878d363c9e28f121784362a659c72b1fbdcb6d8 Mon Sep 17 00:00:00 2001 From: circleci Date: Thu, 28 Jul 2022 07:53:27 +0000 Subject: [PATCH 216/757] Published maven/2.24.0 --- plugin-maven/CHANGES.md | 2 ++ plugin-maven/README.md | 4 ++-- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/plugin-maven/CHANGES.md b/plugin-maven/CHANGES.md index 732489f81f..c4ac990753 100644 --- a/plugin-maven/CHANGES.md +++ b/plugin-maven/CHANGES.md @@ -3,6 +3,8 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format (starting after version `1.27.0`). ## [Unreleased] + +## [2.24.0] - 2022-07-28 ### Added * Clang and Black no longer break the build when the binary is unavailable, if they will not be run during that build ([#1257](https://github.com/diffplug/spotless/pull/1257)). * License header support for Kotlin files without `package` or `@file` but do at least have `import` ([#1263](https://github.com/diffplug/spotless/pull/1263)). diff --git a/plugin-maven/README.md b/plugin-maven/README.md index 1552c98537..d4798ba87e 100644 --- a/plugin-maven/README.md +++ b/plugin-maven/README.md @@ -12,8 +12,8 @@ output = [ ].join('\n'); --> [![Maven central](https://img.shields.io/badge/mavencentral-com.diffplug.spotless%3Aspotless--maven--plugin-blue.svg)](https://search.maven.org/#search%7Cgav%7C1%7Cg%3A%22com.diffplug.spotless%22%20AND%20a%3A%22spotless-maven-plugin%22) -[![Javadoc](https://img.shields.io/badge/javadoc-yes-blue.svg)](https://javadoc.io/doc/com.diffplug.spotless/spotless-maven-plugin/2.23.0/index.html) -[![Changelog](https://img.shields.io/badge/changelog-2.23.0-brightgreen.svg)](CHANGES.md) +[![Javadoc](https://img.shields.io/badge/javadoc-yes-blue.svg)](https://javadoc.io/doc/com.diffplug.spotless/spotless-maven-plugin/2.24.0/index.html) +[![Changelog](https://img.shields.io/badge/changelog-2.24.0-brightgreen.svg)](CHANGES.md) [![Circle CI](https://circleci.com/gh/diffplug/spotless/tree/main.svg?style=shield)](https://circleci.com/gh/diffplug/spotless/tree/main) [![Live chat](https://img.shields.io/badge/gitter-chat-brightgreen.svg)](https://gitter.im/diffplug/spotless) From 74d0accc62f470699bbaab83aadbdd3b982e3df3 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 1 Aug 2022 12:04:24 +0000 Subject: [PATCH 217/757] Bump diktat-rules from 1.2.1 to 1.2.3 Bumps [diktat-rules](https://github.com/saveourtool/diktat) from 1.2.1 to 1.2.3. - [Release notes](https://github.com/saveourtool/diktat/releases) - [Commits](https://github.com/saveourtool/diktat/compare/v1.2.1...v1.2.3) --- updated-dependencies: - dependency-name: org.cqfn.diktat:diktat-rules dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] --- lib/build.gradle | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/build.gradle b/lib/build.gradle index 4aba993334..e14e5c6438 100644 --- a/lib/build.gradle +++ b/lib/build.gradle @@ -51,7 +51,7 @@ dependencies { ktlintCompileOnly "com.pinterest.ktlint:ktlint-ruleset-experimental:$VER_KTLINT" ktlintCompileOnly "com.pinterest.ktlint:ktlint-ruleset-standard:$VER_KTLINT" - String VER_DIKTAT = "1.2.1" + String VER_DIKTAT = "1.2.3" diktatCompileOnly "org.cqfn.diktat:diktat-rules:$VER_DIKTAT" // used for markdown formatting From 30bb58a693fe3a6be9737110209180ffad3538f2 Mon Sep 17 00:00:00 2001 From: bh-tt Date: Tue, 2 Aug 2022 11:41:37 +0200 Subject: [PATCH 218/757] Use the correct args --- .../main/java/com/diffplug/spotless/cpp/ClangFormatStep.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/lib/src/main/java/com/diffplug/spotless/cpp/ClangFormatStep.java b/lib/src/main/java/com/diffplug/spotless/cpp/ClangFormatStep.java index aced507ee5..dba55b1931 100644 --- a/lib/src/main/java/com/diffplug/spotless/cpp/ClangFormatStep.java +++ b/lib/src/main/java/com/diffplug/spotless/cpp/ClangFormatStep.java @@ -20,6 +20,7 @@ import java.io.Serializable; import java.nio.charset.StandardCharsets; import java.util.ArrayList; +import java.util.Arrays; import java.util.List; import java.util.Objects; @@ -112,7 +113,7 @@ String format(ProcessRunner runner, String input, File file) throws IOException, } final String[] processArgs = args.toArray(new String[args.size() + 1]); processArgs[processArgs.length - 1] = "--assume-filename=" + file.getName(); - return runner.exec(input.getBytes(StandardCharsets.UTF_8), args).assertExitZero(StandardCharsets.UTF_8); + return runner.exec(input.getBytes(StandardCharsets.UTF_8), processArgs).assertExitZero(StandardCharsets.UTF_8); } FormatterFunc.Closeable toFunc() { From 4cc323f58e0b65e2cafae4738d0f1aa1d079e16c Mon Sep 17 00:00:00 2001 From: bh-tt Date: Tue, 2 Aug 2022 11:46:52 +0200 Subject: [PATCH 219/757] Add to changes --- CHANGES.md | 2 +- plugin-gradle/CHANGES.md | 2 +- plugin-maven/CHANGES.md | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/CHANGES.md b/CHANGES.md index d57135685f..75cf4d7cb0 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -10,7 +10,7 @@ This document is intended for Spotless developers. We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format (starting after version `1.27.0`). ## [Unreleased] - +* Fix Clang not knowing the filename and changing the format ([#1267](https://github.com/diffplug/spotless/pull/1268)) ## [2.28.0] - 2022-07-28 ### Added * Clang and Black no longer break the build when the binary is unavailable, if they will not be run during that build ([#1257](https://github.com/diffplug/spotless/pull/1257)). diff --git a/plugin-gradle/CHANGES.md b/plugin-gradle/CHANGES.md index d7d434a90d..ff4559f19b 100644 --- a/plugin-gradle/CHANGES.md +++ b/plugin-gradle/CHANGES.md @@ -3,7 +3,7 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format (starting after version `3.27.0`). ## [Unreleased] - +* Fix Clang not knowing the filename and changing the format ([#1267](https://github.com/diffplug/spotless/pull/1268)) ## [6.9.0] - 2022-07-28 ### Added * Clang and Black no longer break the build when the binary is unavailable, if they will not be run during that build ([#1257](https://github.com/diffplug/spotless/pull/1257)). diff --git a/plugin-maven/CHANGES.md b/plugin-maven/CHANGES.md index c4ac990753..4a63f89e15 100644 --- a/plugin-maven/CHANGES.md +++ b/plugin-maven/CHANGES.md @@ -3,7 +3,7 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format (starting after version `1.27.0`). ## [Unreleased] - +* Fix Clang not knowing the filename and changing the format ([#1267](https://github.com/diffplug/spotless/pull/1268)) ## [2.24.0] - 2022-07-28 ### Added * Clang and Black no longer break the build when the binary is unavailable, if they will not be run during that build ([#1257](https://github.com/diffplug/spotless/pull/1257)). From b71da45312aff3cd18d63d1bea1a6edd78fc5530 Mon Sep 17 00:00:00 2001 From: bh-tt Date: Tue, 2 Aug 2022 11:52:37 +0200 Subject: [PATCH 220/757] Remove unused import --- lib/src/main/java/com/diffplug/spotless/cpp/ClangFormatStep.java | 1 - 1 file changed, 1 deletion(-) diff --git a/lib/src/main/java/com/diffplug/spotless/cpp/ClangFormatStep.java b/lib/src/main/java/com/diffplug/spotless/cpp/ClangFormatStep.java index 599863ccc1..5591045505 100644 --- a/lib/src/main/java/com/diffplug/spotless/cpp/ClangFormatStep.java +++ b/lib/src/main/java/com/diffplug/spotless/cpp/ClangFormatStep.java @@ -20,7 +20,6 @@ import java.io.Serializable; import java.nio.charset.StandardCharsets; import java.util.ArrayList; -import java.util.Arrays; import java.util.List; import java.util.Objects; From 5d975ba19799992d514659533d661a70ec675940 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Timur=20Sa=C4=9Flam?= Date: Tue, 2 Aug 2022 15:05:39 +0200 Subject: [PATCH 221/757] Fix ANTLR 4 formatter maven configuration. --- plugin-maven/README.md | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/plugin-maven/README.md b/plugin-maven/README.md index d4798ba87e..ee08e91ae3 100644 --- a/plugin-maven/README.md +++ b/plugin-maven/README.md @@ -481,7 +481,7 @@ Groovy-Eclipse formatting errors/warnings lead per default to a build failure. T src/*/antlr4/**/*.g4 - + /* (C)$YEAR */ @@ -490,14 +490,14 @@ Groovy-Eclipse formatting errors/warnings lead per default to a build failure. T ``` -### antlr4formatter +### antlr4Formatter [homepage](https://github.com/antlr/Antlr4Formatter). [available versions](https://search.maven.org/artifact/com.khubla.antlr4formatter/antlr4-formatter). [code](https://github.com/diffplug/spotless/blob/main/plugin-maven/src/main/java/com/diffplug/spotless/maven/antlr4/Antlr4Formatter.java). ```xml - + 1.2.1 - + ``` ## SQL From 05c43364a5ba6adb10f40de8bb88eca705092916 Mon Sep 17 00:00:00 2001 From: Ned Twigg Date: Tue, 9 Aug 2022 10:21:46 -0700 Subject: [PATCH 222/757] Fix changelog categories. --- CHANGES.md | 2 ++ plugin-gradle/CHANGES.md | 2 ++ plugin-maven/CHANGES.md | 2 ++ 3 files changed, 6 insertions(+) diff --git a/CHANGES.md b/CHANGES.md index 75cf4d7cb0..349025fd65 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -10,7 +10,9 @@ This document is intended for Spotless developers. We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format (starting after version `1.27.0`). ## [Unreleased] +### Fixed * Fix Clang not knowing the filename and changing the format ([#1267](https://github.com/diffplug/spotless/pull/1268)) + ## [2.28.0] - 2022-07-28 ### Added * Clang and Black no longer break the build when the binary is unavailable, if they will not be run during that build ([#1257](https://github.com/diffplug/spotless/pull/1257)). diff --git a/plugin-gradle/CHANGES.md b/plugin-gradle/CHANGES.md index ff4559f19b..a550a4f94e 100644 --- a/plugin-gradle/CHANGES.md +++ b/plugin-gradle/CHANGES.md @@ -3,7 +3,9 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format (starting after version `3.27.0`). ## [Unreleased] +### Fixed * Fix Clang not knowing the filename and changing the format ([#1267](https://github.com/diffplug/spotless/pull/1268)) + ## [6.9.0] - 2022-07-28 ### Added * Clang and Black no longer break the build when the binary is unavailable, if they will not be run during that build ([#1257](https://github.com/diffplug/spotless/pull/1257)). diff --git a/plugin-maven/CHANGES.md b/plugin-maven/CHANGES.md index 4a63f89e15..8e26b79353 100644 --- a/plugin-maven/CHANGES.md +++ b/plugin-maven/CHANGES.md @@ -3,7 +3,9 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format (starting after version `1.27.0`). ## [Unreleased] +### Fixed * Fix Clang not knowing the filename and changing the format ([#1267](https://github.com/diffplug/spotless/pull/1268)) + ## [2.24.0] - 2022-07-28 ### Added * Clang and Black no longer break the build when the binary is unavailable, if they will not be run during that build ([#1257](https://github.com/diffplug/spotless/pull/1257)). From 89b46921ebde4ce4a4e9651f0b448ce340e5e4b0 Mon Sep 17 00:00:00 2001 From: Ned Twigg Date: Tue, 9 Aug 2022 10:25:00 -0700 Subject: [PATCH 223/757] Fix changelog links. --- CHANGES.md | 2 +- plugin-gradle/CHANGES.md | 2 +- plugin-maven/CHANGES.md | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/CHANGES.md b/CHANGES.md index 349025fd65..d884759825 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -11,7 +11,7 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format ( ## [Unreleased] ### Fixed -* Fix Clang not knowing the filename and changing the format ([#1267](https://github.com/diffplug/spotless/pull/1268)) +* Fix Clang not knowing the filename and changing the format ([#1268](https://github.com/diffplug/spotless/pull/1268) fixes [#1267](https://github.com/diffplug/spotless/issues/1267)). ## [2.28.0] - 2022-07-28 ### Added diff --git a/plugin-gradle/CHANGES.md b/plugin-gradle/CHANGES.md index a550a4f94e..ebfa7d978e 100644 --- a/plugin-gradle/CHANGES.md +++ b/plugin-gradle/CHANGES.md @@ -4,7 +4,7 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format ( ## [Unreleased] ### Fixed -* Fix Clang not knowing the filename and changing the format ([#1267](https://github.com/diffplug/spotless/pull/1268)) +* Fix Clang not knowing the filename and changing the format ([#1268](https://github.com/diffplug/spotless/pull/1268) fixes [#1267](https://github.com/diffplug/spotless/issues/1267)). ## [6.9.0] - 2022-07-28 ### Added diff --git a/plugin-maven/CHANGES.md b/plugin-maven/CHANGES.md index 8e26b79353..073b77ca27 100644 --- a/plugin-maven/CHANGES.md +++ b/plugin-maven/CHANGES.md @@ -4,7 +4,7 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format ( ## [Unreleased] ### Fixed -* Fix Clang not knowing the filename and changing the format ([#1267](https://github.com/diffplug/spotless/pull/1268)) +* Fix Clang not knowing the filename and changing the format ([#1268](https://github.com/diffplug/spotless/pull/1268) fixes [#1267](https://github.com/diffplug/spotless/issues/1267)). ## [2.24.0] - 2022-07-28 ### Added From dbb207a2425cf5de37dc72ab737e1ba26e6a6a99 Mon Sep 17 00:00:00 2001 From: Ned Twigg Date: Tue, 9 Aug 2022 16:21:20 -0700 Subject: [PATCH 224/757] Bump changelogs. --- CHANGES.md | 2 ++ plugin-gradle/CHANGES.md | 2 ++ plugin-maven/CHANGES.md | 2 ++ 3 files changed, 6 insertions(+) diff --git a/CHANGES.md b/CHANGES.md index d884759825..53976671ba 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -12,6 +12,8 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format ( ## [Unreleased] ### Fixed * Fix Clang not knowing the filename and changing the format ([#1268](https://github.com/diffplug/spotless/pull/1268) fixes [#1267](https://github.com/diffplug/spotless/issues/1267)). +### Changes +* Bump default `diktat` version to latest `1.2.1` -> `1.2.3` ([#1266](https://github.com/diffplug/spotless/pull/1266)) ## [2.28.0] - 2022-07-28 ### Added diff --git a/plugin-gradle/CHANGES.md b/plugin-gradle/CHANGES.md index ebfa7d978e..2c9e995b6f 100644 --- a/plugin-gradle/CHANGES.md +++ b/plugin-gradle/CHANGES.md @@ -5,6 +5,8 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format ( ## [Unreleased] ### Fixed * Fix Clang not knowing the filename and changing the format ([#1268](https://github.com/diffplug/spotless/pull/1268) fixes [#1267](https://github.com/diffplug/spotless/issues/1267)). +### Changes +* Bump default `diktat` version to latest `1.2.1` -> `1.2.3` ([#1266](https://github.com/diffplug/spotless/pull/1266)) ## [6.9.0] - 2022-07-28 ### Added diff --git a/plugin-maven/CHANGES.md b/plugin-maven/CHANGES.md index 073b77ca27..4b5cc3e7b3 100644 --- a/plugin-maven/CHANGES.md +++ b/plugin-maven/CHANGES.md @@ -5,6 +5,8 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format ( ## [Unreleased] ### Fixed * Fix Clang not knowing the filename and changing the format ([#1268](https://github.com/diffplug/spotless/pull/1268) fixes [#1267](https://github.com/diffplug/spotless/issues/1267)). +### Changes +* Bump default `diktat` version to latest `1.2.1` -> `1.2.3` ([#1266](https://github.com/diffplug/spotless/pull/1266)) ## [2.24.0] - 2022-07-28 ### Added From ba7d618407a845c03798facb19218408f4098a2e Mon Sep 17 00:00:00 2001 From: Ned Twigg Date: Tue, 9 Aug 2022 16:21:37 -0700 Subject: [PATCH 225/757] Bump default diktat version 1.2.1 -> 1.2.3 --- lib/src/main/java/com/diffplug/spotless/kotlin/DiktatStep.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/src/main/java/com/diffplug/spotless/kotlin/DiktatStep.java b/lib/src/main/java/com/diffplug/spotless/kotlin/DiktatStep.java index ff3e3240cf..f1cd3103d9 100644 --- a/lib/src/main/java/com/diffplug/spotless/kotlin/DiktatStep.java +++ b/lib/src/main/java/com/diffplug/spotless/kotlin/DiktatStep.java @@ -32,7 +32,7 @@ private DiktatStep() {} private static final String MIN_SUPPORTED_VERSION = "1.2.1"; - private static final String DEFAULT_VERSION = "1.2.1"; + private static final String DEFAULT_VERSION = "1.2.3"; static final String NAME = "diktat"; static final String PACKAGE_DIKTAT = "org.cqfn.diktat"; static final String MAVEN_COORDINATE = PACKAGE_DIKTAT + ":diktat-rules:"; From bde7eb3fff3784716fa706ab8b4fa4d3933a0b7d Mon Sep 17 00:00:00 2001 From: circleci Date: Wed, 10 Aug 2022 01:25:50 +0000 Subject: [PATCH 226/757] Published lib/2.28.1 --- CHANGES.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/CHANGES.md b/CHANGES.md index 53976671ba..751749585f 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -10,6 +10,8 @@ This document is intended for Spotless developers. We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format (starting after version `1.27.0`). ## [Unreleased] + +## [2.28.1] - 2022-08-10 ### Fixed * Fix Clang not knowing the filename and changing the format ([#1268](https://github.com/diffplug/spotless/pull/1268) fixes [#1267](https://github.com/diffplug/spotless/issues/1267)). ### Changes From ece76dde507aee383796e0ccad94a91e6bac5819 Mon Sep 17 00:00:00 2001 From: circleci Date: Wed, 10 Aug 2022 01:27:19 +0000 Subject: [PATCH 227/757] Published gradle/6.9.1 --- plugin-gradle/CHANGES.md | 2 ++ plugin-gradle/README.md | 46 ++++++++++++++++++++-------------------- 2 files changed, 25 insertions(+), 23 deletions(-) diff --git a/plugin-gradle/CHANGES.md b/plugin-gradle/CHANGES.md index 2c9e995b6f..3cf249b893 100644 --- a/plugin-gradle/CHANGES.md +++ b/plugin-gradle/CHANGES.md @@ -3,6 +3,8 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format (starting after version `3.27.0`). ## [Unreleased] + +## [6.9.1] - 2022-08-10 ### Fixed * Fix Clang not knowing the filename and changing the format ([#1268](https://github.com/diffplug/spotless/pull/1268) fixes [#1267](https://github.com/diffplug/spotless/issues/1267)). ### Changes diff --git a/plugin-gradle/README.md b/plugin-gradle/README.md index 8b8e5372e6..bb71d8ab5b 100644 --- a/plugin-gradle/README.md +++ b/plugin-gradle/README.md @@ -18,9 +18,9 @@ output = [ --> [![Gradle plugin](https://img.shields.io/badge/plugins.gradle.org-com.diffplug.spotless-blue.svg)](https://plugins.gradle.org/plugin/com.diffplug.spotless) [![Maven central](https://img.shields.io/badge/mavencentral-yes-blue.svg)](https://search.maven.org/#search%7Cgav%7C1%7Cg%3A%22com.diffplug.spotless%22%20AND%20a%3A%22spotless-plugin-gradle%22) -[![Javadoc](https://img.shields.io/badge/javadoc-yes-blue.svg)](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.9.0/index.html) +[![Javadoc](https://img.shields.io/badge/javadoc-yes-blue.svg)](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.9.1/index.html) [![License Apache](https://img.shields.io/badge/license-apache-blue.svg)](https://tldrlegal.com/license/apache-license-2.0-(apache-2.0)) -[![Changelog](https://img.shields.io/badge/changelog-6.9.0-blue.svg)](CHANGES.md) +[![Changelog](https://img.shields.io/badge/changelog-6.9.1-blue.svg)](CHANGES.md) [![Circle CI](https://circleci.com/gh/diffplug/spotless/tree/main.svg?style=shield)](https://circleci.com/gh/diffplug/spotless/tree/main) [![Live chat](https://img.shields.io/badge/gitter-chat-brightgreen.svg)](https://gitter.im/diffplug/spotless) @@ -126,10 +126,10 @@ spotless { ``` Spotless consists of a list of formats (in the example above, `misc` and `java`), and each format has: -- a `target` (the files to format), which you set with [`target`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.9.0/com/diffplug/gradle/spotless/FormatExtension.html#target-java.lang.Object...-) and [`targetExclude`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.9.0/com/diffplug/gradle/spotless/FormatExtension.html#targetExclude-java.lang.Object...-) -- a list of `FormatterStep`, which are just `String -> String` functions, such as [`replace`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.9.0/com/diffplug/gradle/spotless/FormatExtension.html#replace-java.lang.String-java.lang.CharSequence-java.lang.CharSequence-), [`replaceRegex`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.9.0/com/diffplug/gradle/spotless/FormatExtension.html#replaceRegex-java.lang.String-java.lang.String-java.lang.String-), [`trimTrailingWhitespace`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.9.0/com/diffplug/gradle/spotless/FormatExtension.html#replace-java.lang.String-java.lang.CharSequence-java.lang.CharSequence-), [`custom`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.9.0/com/diffplug/gradle/spotless/FormatExtension.html#custom-java.lang.String-groovy.lang.Closure-), [`prettier`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.9.0/com/diffplug/gradle/spotless/FormatExtension.html#prettier--), [`eclipseWtp`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.9.0/com/diffplug/gradle/spotless/FormatExtension.html#eclipseWtp-com.diffplug.spotless.extra.wtp.EclipseWtpFormatterStep-), [`licenseHeader`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.9.0/com/diffplug/gradle/spotless/FormatExtension.html#licenseHeader-java.lang.String-java.lang.String-) etc. +- a `target` (the files to format), which you set with [`target`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.9.1/com/diffplug/gradle/spotless/FormatExtension.html#target-java.lang.Object...-) and [`targetExclude`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.9.1/com/diffplug/gradle/spotless/FormatExtension.html#targetExclude-java.lang.Object...-) +- a list of `FormatterStep`, which are just `String -> String` functions, such as [`replace`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.9.1/com/diffplug/gradle/spotless/FormatExtension.html#replace-java.lang.String-java.lang.CharSequence-java.lang.CharSequence-), [`replaceRegex`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.9.1/com/diffplug/gradle/spotless/FormatExtension.html#replaceRegex-java.lang.String-java.lang.String-java.lang.String-), [`trimTrailingWhitespace`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.9.1/com/diffplug/gradle/spotless/FormatExtension.html#replace-java.lang.String-java.lang.CharSequence-java.lang.CharSequence-), [`custom`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.9.1/com/diffplug/gradle/spotless/FormatExtension.html#custom-java.lang.String-groovy.lang.Closure-), [`prettier`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.9.1/com/diffplug/gradle/spotless/FormatExtension.html#prettier--), [`eclipseWtp`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.9.1/com/diffplug/gradle/spotless/FormatExtension.html#eclipseWtp-com.diffplug.spotless.extra.wtp.EclipseWtpFormatterStep-), [`licenseHeader`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.9.1/com/diffplug/gradle/spotless/FormatExtension.html#licenseHeader-java.lang.String-java.lang.String-) etc. -All the generic steps live in [`FormatExtension`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.9.0/com/diffplug/gradle/spotless/FormatExtension.html), and there are many language-specific steps which live in its language-specific subclasses, which are described below. +All the generic steps live in [`FormatExtension`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.9.1/com/diffplug/gradle/spotless/FormatExtension.html), and there are many language-specific steps which live in its language-specific subclasses, which are described below. ### Requirements @@ -141,7 +141,7 @@ If you're stuck on an older version of Gradle, `id 'com.diffplug.gradle.spotless ## Java -`com.diffplug.gradle.spotless.JavaExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.9.0/com/diffplug/gradle/spotless/JavaExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/JavaExtension.java) +`com.diffplug.gradle.spotless.JavaExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.9.1/com/diffplug/gradle/spotless/JavaExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/JavaExtension.java) ```gradle spotless { @@ -248,8 +248,8 @@ spotless { ## Groovy -- `com.diffplug.gradle.spotless.GroovyExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.9.0/com/diffplug/gradle/spotless/GroovyExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/GroovyExtension.java) -- `com.diffplug.gradle.spotless.GroovyGradleExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.9.0/com/diffplug/gradle/spotless/GroovyGradleExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/GroovyGradleExtension.java) +- `com.diffplug.gradle.spotless.GroovyExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.9.1/com/diffplug/gradle/spotless/GroovyExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/GroovyExtension.java) +- `com.diffplug.gradle.spotless.GroovyGradleExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.9.1/com/diffplug/gradle/spotless/GroovyGradleExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/GroovyGradleExtension.java) Configuration for Groovy is similar to [Java](#java), in that it also supports `licenseHeader` and `importOrder`. @@ -300,8 +300,8 @@ Groovy-Eclipse formatting errors/warnings lead per default to a build failure. T ## Kotlin -- `com.diffplug.gradle.spotless.KotlinExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.9.0/com/diffplug/gradle/spotless/KotlinExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/KotlinExtension.java) -- `com.diffplug.gradle.spotless.KotlinGradleExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.9.0/com/diffplug/gradle/spotless/KotlinGradleExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/KotlinGradleExtension.java) +- `com.diffplug.gradle.spotless.KotlinExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.9.1/com/diffplug/gradle/spotless/KotlinExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/KotlinExtension.java) +- `com.diffplug.gradle.spotless.KotlinGradleExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.9.1/com/diffplug/gradle/spotless/KotlinGradleExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/KotlinGradleExtension.java) ```gradle spotless { // if you are using build.gradle.kts, instead of 'spotless {' use: @@ -364,7 +364,7 @@ spotless { ## Scala -`com.diffplug.gradle.spotless.ScalaExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.9.0/com/diffplug/gradle/spotless/ScalaExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/ScalaExtension.java) +`com.diffplug.gradle.spotless.ScalaExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.9.1/com/diffplug/gradle/spotless/ScalaExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/ScalaExtension.java) ```gradle spotless { @@ -396,7 +396,7 @@ spotless { ## C/C++ -`com.diffplug.gradle.spotless.CppExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.9.0/com/diffplug/gradle/spotless/CppExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/CppExtension.java) +`com.diffplug.gradle.spotless.CppExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.9.1/com/diffplug/gradle/spotless/CppExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/CppExtension.java) ```gradle spotless { @@ -428,7 +428,7 @@ spotles { ## Python -`com.diffplug.gradle.spotless.PythonExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.9.0/com/diffplug/gradle/spotless/PythonExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/PythonExtension.java) +`com.diffplug.gradle.spotless.PythonExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.9.1/com/diffplug/gradle/spotless/PythonExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/PythonExtension.java) ```gradle spotless { @@ -462,7 +462,7 @@ black().pathToExe('C:/myuser/.pyenv/versions/3.8.0/scripts/black.exe') ## FreshMark -`com.diffplug.gradle.spotless.FreshMarkExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.9.0/com/diffplug/gradle/spotless/FreshMarkExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/FreshMarkExtension.java) +`com.diffplug.gradle.spotless.FreshMarkExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.9.1/com/diffplug/gradle/spotless/FreshMarkExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/FreshMarkExtension.java) [homepage](https://github.com/diffplug/freshmark). [changelog](https://github.com/diffplug/freshmark/blob/master/CHANGES.md). FreshMark lets you generate markdown in the comments of your markdown. This helps to keep badges and links up-to-date (see the source for this file), and can also be helpful for generating complex tables (see the source for [the parent readme](../README.md)). @@ -483,7 +483,7 @@ spotless { ## Antlr4 -`com.diffplug.gradle.spotless.Antlr4Extension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.9.0/com/diffplug/gradle/spotless/Antlr4Extension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/Antlr4Extension.java) +`com.diffplug.gradle.spotless.Antlr4Extension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.9.1/com/diffplug/gradle/spotless/Antlr4Extension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/Antlr4Extension.java) ```gradle spotless { @@ -508,7 +508,7 @@ antlr4formatter('1.2.1') // version is optional ## SQL -`com.diffplug.gradle.spotless.SqlExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.9.0/com/diffplug/gradle/spotless/SqlExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/SqlExtension.java) +`com.diffplug.gradle.spotless.SqlExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.9.1/com/diffplug/gradle/spotless/SqlExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/SqlExtension.java) ```gradle spotless { @@ -548,7 +548,7 @@ sql.formatter.indent.size=4 ## Typescript -- `com.diffplug.gradle.spotless.TypescriptExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.9.0/com/diffplug/gradle/spotless/TypescriptExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/TypescriptExtension.java) +- `com.diffplug.gradle.spotless.TypescriptExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.9.1/com/diffplug/gradle/spotless/TypescriptExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/TypescriptExtension.java) ```gradle spotless { @@ -591,7 +591,7 @@ For details, see the [npm detection](#npm-detection) and [`.npmrc` detection](#n ## JSON -- `com.diffplug.gradle.spotless.JsonExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.9.0/com/diffplug/gradle/spotless/JsonExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/JsonExtension.java) +- `com.diffplug.gradle.spotless.JsonExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.9.1/com/diffplug/gradle/spotless/JsonExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/JsonExtension.java) ```gradle spotless { @@ -816,7 +816,7 @@ Once a file's license header has a valid year, whether it is a year (`2020`) or * `2017` -> `2017-2020` * `2017-2019` -> `2017-2020` -See the [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.9.0/com/diffplug/gradle/spotless/FormatExtension.LicenseHeaderConfig.html) for a complete listing of options. +See the [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.9.1/com/diffplug/gradle/spotless/FormatExtension.LicenseHeaderConfig.html) for a complete listing of options. @@ -883,9 +883,9 @@ spotless { custom 'lowercase', { str -> str.toLowerCase() } ``` -However, custom rules will disable up-to-date checking and caching, unless you read [this javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.9.0/com/diffplug/gradle/spotless/FormatExtension.html#bumpThisNumberIfACustomStepChanges-int-) and follow its instructions carefully. +However, custom rules will disable up-to-date checking and caching, unless you read [this javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.9.1/com/diffplug/gradle/spotless/FormatExtension.html#bumpThisNumberIfACustomStepChanges-int-) and follow its instructions carefully. -Another option is to create proper `FormatterStep` in your `buildSrc`, and then call [`addStep`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.9.0/com/diffplug/gradle/spotless/FormatExtension.html#addStep-com.diffplug.spotless.FormatterStep-). The contributing guide describes [how to do this](https://github.com/diffplug/spotless/blob/main/CONTRIBUTING.md#how-to-add-a-new-formatterstep). If the step is generally-useful, we hope you'll open a PR to share it! +Another option is to create proper `FormatterStep` in your `buildSrc`, and then call [`addStep`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.9.1/com/diffplug/gradle/spotless/FormatExtension.html#addStep-com.diffplug.spotless.FormatterStep-). The contributing guide describes [how to do this](https://github.com/diffplug/spotless/blob/main/CONTRIBUTING.md#how-to-add-a-new-formatterstep). If the step is generally-useful, we hope you'll open a PR to share it! ```gradle @@ -918,11 +918,11 @@ spotless { format 'foo', com.acme.FooLanguageExtension, { ``` -If you'd like to create a one-off Spotless task outside of the `check`/`apply` framework, see [`FormatExtension.createIndependentApplyTask`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.9.0/com/diffplug/gradle/spotless/FormatExtension.html#createIndependentApplyTask-java.lang.String-). +If you'd like to create a one-off Spotless task outside of the `check`/`apply` framework, see [`FormatExtension.createIndependentApplyTask`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.9.1/com/diffplug/gradle/spotless/FormatExtension.html#createIndependentApplyTask-java.lang.String-). ## Inception (languages within languages within...) -In very rare cases, you might want to format e.g. javascript which is written inside JSP templates, or maybe java within a markdown file, or something wacky like that. You can specify hunks within a file using either open/close tags or a regex with a single capturing group, and then specify rules within it, like so. See [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.9.0/com/diffplug/gradle/spotless/FormatExtension.html#withinBlocks-java.lang.String-java.lang.String-java.lang.String-org.gradle.api.Action-) for more details. +In very rare cases, you might want to format e.g. javascript which is written inside JSP templates, or maybe java within a markdown file, or something wacky like that. You can specify hunks within a file using either open/close tags or a regex with a single capturing group, and then specify rules within it, like so. See [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.9.1/com/diffplug/gradle/spotless/FormatExtension.html#withinBlocks-java.lang.String-java.lang.String-java.lang.String-org.gradle.api.Action-) for more details. ```gradle import com.diffplug.gradle.spotless.JavaExtension From ce98b688cb4724a95e0abb05f4bbaf398097c1b8 Mon Sep 17 00:00:00 2001 From: circleci Date: Wed, 10 Aug 2022 01:29:45 +0000 Subject: [PATCH 228/757] Published maven/2.24.1 --- plugin-maven/CHANGES.md | 2 ++ plugin-maven/README.md | 4 ++-- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/plugin-maven/CHANGES.md b/plugin-maven/CHANGES.md index 4b5cc3e7b3..59bf722522 100644 --- a/plugin-maven/CHANGES.md +++ b/plugin-maven/CHANGES.md @@ -3,6 +3,8 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format (starting after version `1.27.0`). ## [Unreleased] + +## [2.24.1] - 2022-08-10 ### Fixed * Fix Clang not knowing the filename and changing the format ([#1268](https://github.com/diffplug/spotless/pull/1268) fixes [#1267](https://github.com/diffplug/spotless/issues/1267)). ### Changes diff --git a/plugin-maven/README.md b/plugin-maven/README.md index ee08e91ae3..f0c1874993 100644 --- a/plugin-maven/README.md +++ b/plugin-maven/README.md @@ -12,8 +12,8 @@ output = [ ].join('\n'); --> [![Maven central](https://img.shields.io/badge/mavencentral-com.diffplug.spotless%3Aspotless--maven--plugin-blue.svg)](https://search.maven.org/#search%7Cgav%7C1%7Cg%3A%22com.diffplug.spotless%22%20AND%20a%3A%22spotless-maven-plugin%22) -[![Javadoc](https://img.shields.io/badge/javadoc-yes-blue.svg)](https://javadoc.io/doc/com.diffplug.spotless/spotless-maven-plugin/2.24.0/index.html) -[![Changelog](https://img.shields.io/badge/changelog-2.24.0-brightgreen.svg)](CHANGES.md) +[![Javadoc](https://img.shields.io/badge/javadoc-yes-blue.svg)](https://javadoc.io/doc/com.diffplug.spotless/spotless-maven-plugin/2.24.1/index.html) +[![Changelog](https://img.shields.io/badge/changelog-2.24.1-brightgreen.svg)](CHANGES.md) [![Circle CI](https://circleci.com/gh/diffplug/spotless/tree/main.svg?style=shield)](https://circleci.com/gh/diffplug/spotless/tree/main) [![Live chat](https://img.shields.io/badge/gitter-chat-brightgreen.svg)](https://gitter.im/diffplug/spotless) From 1c6082674943b72b0f4a46c1c4c4212924ab9884 Mon Sep 17 00:00:00 2001 From: Michael Ernst Date: Fri, 12 Aug 2022 06:44:24 -0700 Subject: [PATCH 229/757] `typeAnnotations()` removes line breaks between type annotations and types --- .../spotless/java/TypeAnnotationsStep.java | 450 ++++++++++++++++++ .../gradle/spotless/JavaExtension.java | 6 + .../TypeAnnotationsInCommentsInput.test | 31 ++ .../TypeAnnotationsInCommentsOutput.test | 25 + .../TypeAnnotationsTestInput.test | 68 +++ .../TypeAnnotationsTestOutput.test | 43 ++ .../java/TypeAnnotationsStepTest.java | 57 +++ 7 files changed, 680 insertions(+) create mode 100644 lib/src/main/java/com/diffplug/spotless/java/TypeAnnotationsStep.java create mode 100644 testlib/src/main/resources/java/typeannotations/TypeAnnotationsInCommentsInput.test create mode 100644 testlib/src/main/resources/java/typeannotations/TypeAnnotationsInCommentsOutput.test create mode 100644 testlib/src/main/resources/java/typeannotations/TypeAnnotationsTestInput.test create mode 100644 testlib/src/main/resources/java/typeannotations/TypeAnnotationsTestOutput.test create mode 100644 testlib/src/test/java/com/diffplug/spotless/java/TypeAnnotationsStepTest.java diff --git a/lib/src/main/java/com/diffplug/spotless/java/TypeAnnotationsStep.java b/lib/src/main/java/com/diffplug/spotless/java/TypeAnnotationsStep.java new file mode 100644 index 0000000000..d2fdc7cd1b --- /dev/null +++ b/lib/src/main/java/com/diffplug/spotless/java/TypeAnnotationsStep.java @@ -0,0 +1,450 @@ +/* + * Copyright 2022 DiffPlug + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.diffplug.spotless.java; + +import java.io.Serializable; +import java.util.Arrays; +import java.util.HashSet; +import java.util.Set; +import java.util.regex.Matcher; +import java.util.regex.Pattern; + +import com.diffplug.spotless.FormatterFunc; +import com.diffplug.spotless.FormatterStep; + +/** + * Some formatters put every annotation on its own line + * -- even type annotations, which should be on the same line as the type they qualify. + * This class corrects the formatting. + * This is useful as a postprocessing step after a Java formatter that is not cognizant of type annotations. + */ +public final class TypeAnnotationsStep { + private TypeAnnotationsStep() {} + + static final String NAME = "No line break between type annotation and type"; + + public static FormatterStep create() { + return FormatterStep.create(NAME, new State(), State::toFormatter); + } + + // TODO: Enable users to specify more type annotations in `typeAnnotations` in build.gradle. + // TODO: Read from a local .type-annotations file. + private static final class State implements Serializable { + private static final long serialVersionUID = 1L; + + /** + * These are type annotations, which should NOT go on their own line. + * A type annotation's {@code @Target} annotation contains {@code TYPE_USE}. + */ + private static final Set typeAnnotations = new HashSet<>( + Arrays.asList( + // Type annotations from the Checker Framework. + "A", + "ACCBottom", + "Acceleration", + "ACCTop", + "AinferBottom", + "AlwaysSafe", + "Angle", + "AnnoWithStringArg", + "Area", + "ArrayLen", + "ArrayLenRange", + "ArrayWithoutPackage", + "AwtAlphaCompositingRule", + "AwtColorSpace", + "AwtCursorType", + "AwtFlowLayout", + "B", + "BinaryName", + "BinaryNameInUnnamedPackage", + "BinaryNameOrPrimitiveType", + "BinaryNameWithoutPackage", + "BoolVal", + "Bottom", + "BottomQualifier", + "BottomThis", + "BottomVal", + "C", + "CalledMethods", + "CalledMethodsBottom", + "CalledMethodsPredicate", + "CalledMethodsTop", + "CanonicalName", + "CanonicalNameAndBinaryName", + "CanonicalNameOrEmpty", + "CanonicalNameOrPrimitiveType", + "CCBottom", + "CCTop", + "cd", + "ClassBound", + "ClassGetName", + "ClassGetSimpleName", + "ClassVal", + "ClassValBottom", + "CompilerMessageKey", + "CompilerMessageKeyBottom", + "Constant", + "Critical", + "Current", + "D", + "DefaultType", + "degrees", + "Det", + "DotSeparatedIdentifiers", + "DotSeparatedIdentifiersOrPrimitiveType", + "DoubleVal", + "E", + "Encrypted", + "EnhancedRegex", + "EnumVal", + "Even", + "F", + "FBCBottom", + "FEBottom", + "FEBot", + "Fenum", + "FenumBottom", + "FenumTop", + "FETop", + "FieldDescriptor", + "FieldDescriptorForPrimitive", + "FieldDescriptorForPrimitiveOrArrayInUnnamedPackage", + "FieldDescriptorWithoutPackage", + "FlowExp", + "Force", + "Format", + "FormatBottom", + "FqBinaryName", + "Frequency", + "FullyQualifiedName", + "g", + "GTENegativeOne", + "GuardedBy", + "GuardedByBottom", + "GuardedByUnknown", + "GuardSatisfied", + "h", + "H1Bot", + "H1Invalid", + "H1Poly", + "H1S1", + "H1S2", + "H1Top", + "H2Bot", + "H2Poly", + "H2S1", + "H2S2", + "H2Top", + "Hz", + "I18nFormat", + "I18nFormatBottom", + "I18nFormatFor", + "I18nInvalidFormat", + "I18nUnknownFormat", + "Identifier", + "IdentifierOrArray", + "IdentifierOrPrimitiveType", + "ImplicitAnno", + "IndexFor", + "IndexOrHigh", + "IndexOrLow", + "Initialized", + "InitializedFields", + "InitializedFieldsBottom", + "InitializedFieldsPredicate", + "InternalForm", + "Interned", + "InternedDistinct", + "IntRange", + "IntVal", + "InvalidFormat", + "K", + "KeyFor", + "KeyForBottom", + "KeyForType", + "kg", + "kHz", + "km", + "km2", + "km3", + "kmPERh", + "kN", + "LbTop", + "LB_TOP", + "LeakedToResult", + "Length", + "LengthOf", + "LessThan", + "LessThanBottom", + "LessThanUnknown", + "LocalizableKey", + "LocalizableKeyBottom", + "Localized", + "LowerBoundBottom", + "LowerBoundUnknown", + "LTEqLengthOf", + "LTLengthOf", + "LTOMLengthOf", + "Luminance", + "m", + "m2", + "m3", + "Mass", + "MatchesRegex", + "MaybeAliased", + "MaybeDerivedFromConstant", + "MaybePresent", + "MaybeThis", + "MethodDescriptor", + "MethodVal", + "MethodValBottom", + "min", + "MinLen", + "mm", + "mm2", + "mm3", + "mol", + "MonotonicNonNull", + "MonotonicNonNullType", + "MonotonicOdd", + "mPERs", + "mPERs2", + "MustCall", + "MustCallAlias", + "MustCallUnknown", + "N", + "NegativeIndexFor", + "NewObject", + "NonConstant", + "NonDet", + "NonLeaked", + "NonNegative", + "NonNull", + "NonNullType", + "NonRaw", + "NotCalledMethods", + "NotNull", + "NotQualifier", + "NTDBottom", + "NTDMiddle", + "NTDSide", + "NTDTop", + "Nullable", + "NullableType", + "Odd", + "OptionalBottom", + "OrderNonDet", + "Parent", + "PatternA", + "PatternAB", + "PatternAC", + "PatternB", + "PatternBC", + "PatternBottomFull", + "PatternBottomPartial", + "PatternC", + "PatternUnknown", + "Poly", + "PolyAll", + "PolyConstant", + "PolyDet", + "PolyEncrypted", + "PolyFenum", + "PolyIndex", + "PolyInitializedFields", + "PolyInterned", + "PolyKeyFor", + "PolyLength", + "PolyLowerBound", + "PolyMustCall", + "PolyNull", + "PolyNullType", + "PolyPresent", + "PolyRaw", + "PolyReflection", + "PolyRegex", + "PolySameLen", + "PolySignature", + "PolySigned", + "PolyTainted", + "PolyTestAccumulation", + "PolyTypeDeclDefault", + "PolyUI", + "PolyUnit", + "PolyUpperBound", + "PolyValue", + "PolyVariableNameDefault", + "Positive", + "Present", + "PrimitiveType", + "PropertyKey", + "PropertyKeyBottom", + "PurityUnqualified", + "Qualifier", + "radians", + "Raw", + "ReflectBottom", + "Regex", + "RegexBottom", + "RegexNNGroups", + "ReportUnqualified", + "s", + "SameLen", + "SameLenBottom", + "SameLenUnknown", + "SearchIndexBottom", + "SearchIndexFor", + "SearchIndexUnknown", + "Sibling1", + "Sibling2", + "SiblingWithFields", + "SignatureBottom", + "Signed", + "SignednessBottom", + "SignednessGlb", + "SignedPositive", + "SignedPositiveFromUnsigned", + "Speed", + "StringVal", + "SubQual", + "Substance", + "SubstringIndexBottom", + "SubstringIndexFor", + "SubstringIndexUnknown", + "SuperQual", + "SwingBoxOrientation", + "SwingCompassDirection", + "SwingElementOrientation", + "SwingHorizontalOrientation", + "SwingSplitPaneOrientation", + "SwingTextOrientation", + "SwingTitleJustification", + "SwingTitlePosition", + "SwingVerticalOrientation", + "t", + "Tainted", + "Temperature", + "TestAccumulation", + "TestAccumulationBottom", + "TestAccumulationPredicate", + "This", + "Time", + "Top", + "TypeDeclDefaultBottom", + "TypeDeclDefaultMiddle", + "TypeDeclDefaultTop", + "UbTop", + "UB_TOP", + "UI", + "UnderInitialization", + "Unique", + "UnitsBottom", + "UnknownClass", + "UnknownCompilerMessageKey", + "UnknownFormat", + "UnknownInitialization", + "UnknownInterned", + "UnknownKeyFor", + "UnknownLocalizableKey", + "UnknownLocalized", + "UnknownMethod", + "UnknownPropertyKey", + "UnknownRegex", + "UnknownSignedness", + "UnknownThis", + "UnknownUnits", + "UnknownVal", + "Unsigned", + "Untainted", + "UpperBoundBottom", + "UpperBoundLiteral", + "UpperBoundUnknown", + "Value", + "VariableNameDefaultBottom", + "VariableNameDefaultMiddle", + "VariableNameDefaultTop", + "Volume", + "WholeProgramInferenceBottom" + // Add type annotations from other tools here. + + )); + + // group 1 is the basename of the annotation. + private static final String annoNoArgRegex = "@(?:[A-Za-z_][A-Za-z0-9_.]*\\.)?([A-Za-z_][A-Za-z0-9_]*)"; + private static final Pattern annoNoArgPattern = Pattern.compile(annoNoArgRegex); + // 3 non-empty cases: () (".*") (.*) + private static final String annoArgRegex = "(?:\\(\\)|\\(\"[^\"]*\"\\)|\\([^\")][^)]*\\))?"; + // group 1 is the basename of the annotation. + private static final String annoRegex = annoNoArgRegex + annoArgRegex; + private static final String trailingAnnoRegex = annoRegex + "$"; + private static final Pattern trailingAnnoPattern = Pattern.compile(trailingAnnoRegex); + + // Heuristic: matches if the line might be within a //, /*, or Javadoc comment. + private static final Pattern withinCommentPattern = Pattern.compile("//|/\\*(?!.*/*/)|^[ \t]*\\*[ \t]"); + // Don't move an annotation to the start of a comment line. + private static final Pattern startsWithCommentPattern = Pattern.compile("^[ \t]*(//|/\\*$|/\\*|void\\b)"); + + State() {} + + FormatterFunc toFormatter() { + return unixStr -> fixupTypeAnnotations(unixStr); + } + + /** + * Removes line break between type annotations and the following type. + * + * @param the text of a Java file + * @return corrected text of the Java file + */ + String fixupTypeAnnotations(String unixStr) { + // Each element of `lines` ends with a newline. + String[] lines = unixStr.split("((?<=\n))"); + for (int i = 0; i < lines.length - 1; i++) { + String line = lines[i]; + if (endsWithTypeAnnotation(line)) { + String nextLine = lines[i + 1]; + if (startsWithCommentPattern.matcher(nextLine).find()) { + continue; + } + lines[i] = ""; + lines[i + 1] = line.stripTrailing() + " " + nextLine.stripLeading(); + } + } + return String.join("", lines); + } + + /** + * Returns true if the line ends with a type annotation. We need to fix such formatting. + */ + boolean endsWithTypeAnnotation(String unixLine) { + // Remove trailing newline. + String line = unixLine.stripTrailing(); + Matcher m = trailingAnnoPattern.matcher(line); + if (!m.find()) { + return false; + } + String preceding = line.substring(0, m.start()); + String basename = m.group(1); + + if (withinCommentPattern.matcher(preceding).find()) { + return false; + } + + return typeAnnotations.contains(basename); + } + } +} diff --git a/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/JavaExtension.java b/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/JavaExtension.java index 479d2ffd12..d882ac472b 100644 --- a/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/JavaExtension.java +++ b/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/JavaExtension.java @@ -36,6 +36,7 @@ import com.diffplug.spotless.java.ImportOrderStep; import com.diffplug.spotless.java.PalantirJavaFormatStep; import com.diffplug.spotless.java.RemoveUnusedImportsStep; +import com.diffplug.spotless.java.TypeAnnotationsStep; public class JavaExtension extends FormatExtension implements HasBuiltinDelimiterForLicense { static final String NAME = "java"; @@ -231,6 +232,11 @@ public void configFile(Object... configFiles) { } + /** Removes newlines between type annotations and types. */ + public void typeAnnotations() { + addStep(TypeAnnotationsStep.create()); + } + /** If the user hasn't specified the files yet, we'll assume he/she means all of the java files. */ @Override protected void setupTask(SpotlessTask task) { diff --git a/testlib/src/main/resources/java/typeannotations/TypeAnnotationsInCommentsInput.test b/testlib/src/main/resources/java/typeannotations/TypeAnnotationsInCommentsInput.test new file mode 100644 index 0000000000..d49799c0c3 --- /dev/null +++ b/testlib/src/main/resources/java/typeannotations/TypeAnnotationsInCommentsInput.test @@ -0,0 +1,31 @@ +class TypeAnnotationsInComments { + + // Here is a comment relating to the annotation @Nullable + @Interned + String m1() {} + + // Here is another comment relating to the annotation @Nullable + String m2() {} + + /** + * Here is a misformatted type annotation within a Javadoc comment. + * + * @Nullable + * String s; + */ + + @Nullable + @Interned + String m3(/* Don't get confused by other comments on the line with the type */) {} + + @Nullable + @Interned + String m3() {} // Still not confused + + /* + code snippets in regular comments do get re-formatted + + @Nullable + String s; + */ +} diff --git a/testlib/src/main/resources/java/typeannotations/TypeAnnotationsInCommentsOutput.test b/testlib/src/main/resources/java/typeannotations/TypeAnnotationsInCommentsOutput.test new file mode 100644 index 0000000000..491ce5b2aa --- /dev/null +++ b/testlib/src/main/resources/java/typeannotations/TypeAnnotationsInCommentsOutput.test @@ -0,0 +1,25 @@ +class TypeAnnotationsInComments { + + // Here is a comment relating to the annotation @Nullable + @Interned String m1() {} + + // Here is another comment relating to the annotation @Nullable + String m2() {} + + /** + * Here is a misformatted type annotation within a Javadoc comment. + * + * @Nullable + * String s; + */ + + @Nullable @Interned String m3(/* Don't get confused by other comments on the line with the type */) {} + + @Nullable @Interned String m3() {} // Still not confused + + /* + code snippets in regular comments do get re-formatted + + @Nullable String s; + */ +} diff --git a/testlib/src/main/resources/java/typeannotations/TypeAnnotationsTestInput.test b/testlib/src/main/resources/java/typeannotations/TypeAnnotationsTestInput.test new file mode 100644 index 0000000000..8a870a34cc --- /dev/null +++ b/testlib/src/main/resources/java/typeannotations/TypeAnnotationsTestInput.test @@ -0,0 +1,68 @@ +class TypeAnnotationsTest { + + public @Nullable + String s0 = null; + + @Deprecated + public @Nullable + String m0() {} + + @Nullable + String s1 = null; + + @Deprecated + @Nullable + String m1() {} + + @Nullable + @Deprecated + String m2() {} + + @Nullable + @Regex(2) + @Interned + String s2 = null; + + @Deprecated + @Nullable + @Regex(2) + @Interned + String m3() {} + + @Nullable + @Deprecated + @Regex(2) + @Interned + String m4() {} + + @Nullable + // a comment + @Regex(2) + @Interned + String s3 = null; + + @Nullable // a comment + @Regex(2) + @Interned + String s4 = null; + + @Nullable + @Regex(2) + @Interned + // a comment + String s5 = null; + + @Deprecated + // a comment + @Nullable + @Regex(2) + @Interned + String m5() {} + + @Deprecated + @Nullable + // a comment + @Regex(2) + @Interned + String m6() {} +} diff --git a/testlib/src/main/resources/java/typeannotations/TypeAnnotationsTestOutput.test b/testlib/src/main/resources/java/typeannotations/TypeAnnotationsTestOutput.test new file mode 100644 index 0000000000..81fd049609 --- /dev/null +++ b/testlib/src/main/resources/java/typeannotations/TypeAnnotationsTestOutput.test @@ -0,0 +1,43 @@ +class TypeAnnotationsTest { + + public @Nullable String s0 = null; + + @Deprecated + public @Nullable String m0() {} + + @Nullable String s1 = null; + + @Deprecated + @Nullable String m1() {} + + @Nullable @Deprecated + String m2() {} + + @Nullable @Regex(2) @Interned String s2 = null; + + @Deprecated + @Nullable @Regex(2) @Interned String m3() {} + + @Nullable @Deprecated + @Regex(2) @Interned String m4() {} + + @Nullable + // a comment + @Regex(2) @Interned String s3 = null; + + @Nullable // a comment + @Regex(2) @Interned String s4 = null; + + @Nullable @Regex(2) @Interned + // a comment + String s5 = null; + + @Deprecated + // a comment + @Nullable @Regex(2) @Interned String m5() {} + + @Deprecated + @Nullable + // a comment + @Regex(2) @Interned String m6() {} +} diff --git a/testlib/src/test/java/com/diffplug/spotless/java/TypeAnnotationsStepTest.java b/testlib/src/test/java/com/diffplug/spotless/java/TypeAnnotationsStepTest.java new file mode 100644 index 0000000000..3724cac09f --- /dev/null +++ b/testlib/src/test/java/com/diffplug/spotless/java/TypeAnnotationsStepTest.java @@ -0,0 +1,57 @@ +/* + * Copyright 2022 DiffPlug + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.diffplug.spotless.java; + +import org.junit.jupiter.api.Test; + +import com.diffplug.spotless.FormatterStep; +import com.diffplug.spotless.ResourceHarness; +import com.diffplug.spotless.SerializableEqualityTester; + +class TypeAnnotationsStepTest extends ResourceHarness { + @Test + void typeAnnotations() throws Throwable { + FormatterStep step = TypeAnnotationsStep.create(); + assertOnResources(step, "java/typeannotations/TypeAnnotationsTestInput.test", "java/typeannotations/TypeAnnotationsTestOutput.test"); + } + + @Test + void typeAnnotationsInComments() throws Throwable { + FormatterStep step = TypeAnnotationsStep.create(); + assertOnResources(step, "java/typeannotations/TypeAnnotationsInCommentsInput.test", "java/typeannotations/TypeAnnotationsInCommentsOutput.test"); + } + + @Test + void doesntThrowIfTypeAnnotationsIsntSerializable() { + TypeAnnotationsStep.create(); + } + + @Test + void equality() throws Exception { + new SerializableEqualityTester() { + @Override + protected void setupTest(API api) { + api.areDifferentThan(); + } + + @Override + protected FormatterStep create() { + return TypeAnnotationsStep.create(); + } + }.testEquals(); + } + +} From 105eb878c91586fce323b2d6cb023b92bcd4cb94 Mon Sep 17 00:00:00 2001 From: Michael Ernst Date: Fri, 12 Aug 2022 06:50:36 -0700 Subject: [PATCH 230/757] Add changelog entry --- CHANGES.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/CHANGES.md b/CHANGES.md index 751749585f..2b293772ee 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -10,6 +10,8 @@ This document is intended for Spotless developers. We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format (starting after version `1.27.0`). ## [Unreleased] +### Added +* `typeAnnotations()` step to correct formatting of type annotations. It puts type annotations on the same line as the type that they qualify. Run it after a Java formattng step, such as `googleJavaFormat()`. ([#1275](https://github.com/diffplug/spotless/pull/1275)) ## [2.28.1] - 2022-08-10 ### Fixed From 6d76fc97f30320748a6e10cca7a052d6638b6529 Mon Sep 17 00:00:00 2001 From: Michael Ernst Date: Fri, 12 Aug 2022 06:52:13 -0700 Subject: [PATCH 231/757] Changelog in `plugin-gradle`, too --- plugin-gradle/CHANGES.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/plugin-gradle/CHANGES.md b/plugin-gradle/CHANGES.md index 3cf249b893..ec0dd4e951 100644 --- a/plugin-gradle/CHANGES.md +++ b/plugin-gradle/CHANGES.md @@ -3,6 +3,8 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format (starting after version `3.27.0`). ## [Unreleased] +### Added +* `typeAnnotations()` step to correct formatting of type annotations. It puts type annotations on the same line as the type that they qualify. Run it after a Java formattng step, such as `googleJavaFormat()`. ([#1275](https://github.com/diffplug/spotless/pull/1275)) ## [6.9.1] - 2022-08-10 ### Fixed From 0c5d1b65b2ec344cd06f310a716a7ad03bd71fc7 Mon Sep 17 00:00:00 2001 From: Michael Ernst Date: Sat, 13 Aug 2022 08:55:20 -0700 Subject: [PATCH 232/757] Don't use Java 11 APIs --- .../java/com/diffplug/spotless/java/TypeAnnotationsStep.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/src/main/java/com/diffplug/spotless/java/TypeAnnotationsStep.java b/lib/src/main/java/com/diffplug/spotless/java/TypeAnnotationsStep.java index d2fdc7cd1b..dd0b86eeb4 100644 --- a/lib/src/main/java/com/diffplug/spotless/java/TypeAnnotationsStep.java +++ b/lib/src/main/java/com/diffplug/spotless/java/TypeAnnotationsStep.java @@ -421,7 +421,7 @@ String fixupTypeAnnotations(String unixStr) { continue; } lines[i] = ""; - lines[i + 1] = line.stripTrailing() + " " + nextLine.stripLeading(); + lines[i + 1] = line.replaceAll("\\s+$", "") + " " + nextLine.replaceAll("^\\s+", ""); } } return String.join("", lines); @@ -432,7 +432,7 @@ String fixupTypeAnnotations(String unixStr) { */ boolean endsWithTypeAnnotation(String unixLine) { // Remove trailing newline. - String line = unixLine.stripTrailing(); + String line = unixLine.replaceAll("\\s+$", ""); Matcher m = trailingAnnoPattern.matcher(line); if (!m.find()) { return false; From 097ecfabdc0bd55ce5bca4f1ccee1a134773b578 Mon Sep 17 00:00:00 2001 From: EricGao888 Date: Tue, 16 Aug 2022 12:02:17 +0800 Subject: [PATCH 233/757] Fix minor bugs related of Spotless SQL config extension docs (#1256) --- plugin-gradle/README.md | 2 +- plugin-maven/README.md | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/plugin-gradle/README.md b/plugin-gradle/README.md index bb71d8ab5b..53e77a9ced 100644 --- a/plugin-gradle/README.md +++ b/plugin-gradle/README.md @@ -528,7 +528,7 @@ spotless { ```gradle spotless { sql { - dbeaver().configFile('dbeaver.props') // configFile is optional + dbeaver().configFile('dbeaver.properties') // configFile is optional ``` Default configuration file, other options [available here](https://github.com/diffplug/spotless/blob/main/lib/src/main/java/com/diffplug/spotless/sql/dbeaver/DBeaverSQLFormatterConfiguration.java). diff --git a/plugin-maven/README.md b/plugin-maven/README.md index f0c1874993..fa4cf55c74 100644 --- a/plugin-maven/README.md +++ b/plugin-maven/README.md @@ -524,7 +524,7 @@ Groovy-Eclipse formatting errors/warnings lead per default to a build failure. T ```xml - dbeaver.props + dbeaver.properties ``` From a9607fc97eef82bd39d869ee3a296cdfda0d471b Mon Sep 17 00:00:00 2001 From: Stephen Panaro Date: Thu, 18 Aug 2022 20:17:53 -0400 Subject: [PATCH 234/757] Add ktlint rule ID in formatter callback --- .../com/diffplug/spotless/glue/ktlint/KtlintFormatterFunc.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/src/ktlint/java/com/diffplug/spotless/glue/ktlint/KtlintFormatterFunc.java b/lib/src/ktlint/java/com/diffplug/spotless/glue/ktlint/KtlintFormatterFunc.java index da3e3ae475..b9b225f35d 100644 --- a/lib/src/ktlint/java/com/diffplug/spotless/glue/ktlint/KtlintFormatterFunc.java +++ b/lib/src/ktlint/java/com/diffplug/spotless/glue/ktlint/KtlintFormatterFunc.java @@ -111,7 +111,7 @@ static class FormatterCallback implements Function2 { @Override public Unit invoke(LintError lint, Boolean corrected) { if (!corrected) { - throw new AssertionError("Error on line: " + lint.getLine() + ", column: " + lint.getCol() + "\n" + lint.getDetail()); + throw new AssertionError("Error on line: " + lint.getLine() + ", column: " + lint.getCol() + "\n" + lint.getRuleId() + "\n" + lint.getDetail()); } return null; } From 83411a88e88237d15efb0fd22186875fe57bac83 Mon Sep 17 00:00:00 2001 From: Stephen Panaro Date: Thu, 18 Aug 2022 20:51:20 -0400 Subject: [PATCH 235/757] update changes --- CHANGES.md | 1 + plugin-gradle/CHANGES.md | 3 +++ plugin-maven/CHANGES.md | 1 + 3 files changed, 5 insertions(+) diff --git a/CHANGES.md b/CHANGES.md index 751749585f..6e3ac85da7 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -10,6 +10,7 @@ This document is intended for Spotless developers. We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format (starting after version `1.27.0`). ## [Unreleased] +* Add the `ktlint` rule in error messages when `ktlint` fails to apply a fix ([#1279](https://github.com/diffplug/spotless/pull/1279)) ## [2.28.1] - 2022-08-10 ### Fixed diff --git a/plugin-gradle/CHANGES.md b/plugin-gradle/CHANGES.md index 3cf249b893..cdb11f83da 100644 --- a/plugin-gradle/CHANGES.md +++ b/plugin-gradle/CHANGES.md @@ -4,6 +4,9 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format ( ## [Unreleased] +### Changes +* Add the `ktlint` rule in error messages when `ktlint` fails to apply a fix ([#1279](https://github.com/diffplug/spotless/pull/1279)) + ## [6.9.1] - 2022-08-10 ### Fixed * Fix Clang not knowing the filename and changing the format ([#1268](https://github.com/diffplug/spotless/pull/1268) fixes [#1267](https://github.com/diffplug/spotless/issues/1267)). diff --git a/plugin-maven/CHANGES.md b/plugin-maven/CHANGES.md index 59bf722522..b4cb262abd 100644 --- a/plugin-maven/CHANGES.md +++ b/plugin-maven/CHANGES.md @@ -3,6 +3,7 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format (starting after version `1.27.0`). ## [Unreleased] +* Add the `ktlint` rule in error messages when `ktlint` fails to apply a fix ([#1279](https://github.com/diffplug/spotless/pull/1279)) ## [2.24.1] - 2022-08-10 ### Fixed From 0f296cba1479591dd75749fe234babe900a909b5 Mon Sep 17 00:00:00 2001 From: Ned Twigg Date: Thu, 18 Aug 2022 22:01:26 -0700 Subject: [PATCH 236/757] Added missing `### Changes` where necessary. --- CHANGES.md | 1 + plugin-gradle/CHANGES.md | 1 - plugin-maven/CHANGES.md | 1 + 3 files changed, 2 insertions(+), 1 deletion(-) diff --git a/CHANGES.md b/CHANGES.md index 6e3ac85da7..9e00263a93 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -10,6 +10,7 @@ This document is intended for Spotless developers. We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format (starting after version `1.27.0`). ## [Unreleased] +### Changes * Add the `ktlint` rule in error messages when `ktlint` fails to apply a fix ([#1279](https://github.com/diffplug/spotless/pull/1279)) ## [2.28.1] - 2022-08-10 diff --git a/plugin-gradle/CHANGES.md b/plugin-gradle/CHANGES.md index cdb11f83da..72d600688c 100644 --- a/plugin-gradle/CHANGES.md +++ b/plugin-gradle/CHANGES.md @@ -3,7 +3,6 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format (starting after version `3.27.0`). ## [Unreleased] - ### Changes * Add the `ktlint` rule in error messages when `ktlint` fails to apply a fix ([#1279](https://github.com/diffplug/spotless/pull/1279)) diff --git a/plugin-maven/CHANGES.md b/plugin-maven/CHANGES.md index b4cb262abd..7366c3b731 100644 --- a/plugin-maven/CHANGES.md +++ b/plugin-maven/CHANGES.md @@ -3,6 +3,7 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format (starting after version `1.27.0`). ## [Unreleased] +### Changes * Add the `ktlint` rule in error messages when `ktlint` fails to apply a fix ([#1279](https://github.com/diffplug/spotless/pull/1279)) ## [2.24.1] - 2022-08-10 From 640d8e7f77ec32f2c9fa8f2f7da6f5844ec2e658 Mon Sep 17 00:00:00 2001 From: Stephen Panaro Date: Fri, 19 Aug 2022 10:22:44 -0400 Subject: [PATCH 237/757] Add rule prefix to message --- .../com/diffplug/spotless/glue/ktlint/KtlintFormatterFunc.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/src/ktlint/java/com/diffplug/spotless/glue/ktlint/KtlintFormatterFunc.java b/lib/src/ktlint/java/com/diffplug/spotless/glue/ktlint/KtlintFormatterFunc.java index b9b225f35d..e7af558fb5 100644 --- a/lib/src/ktlint/java/com/diffplug/spotless/glue/ktlint/KtlintFormatterFunc.java +++ b/lib/src/ktlint/java/com/diffplug/spotless/glue/ktlint/KtlintFormatterFunc.java @@ -111,7 +111,7 @@ static class FormatterCallback implements Function2 { @Override public Unit invoke(LintError lint, Boolean corrected) { if (!corrected) { - throw new AssertionError("Error on line: " + lint.getLine() + ", column: " + lint.getCol() + "\n" + lint.getRuleId() + "\n" + lint.getDetail()); + throw new AssertionError("Error on line: " + lint.getLine() + ", column: " + lint.getCol() + "\nrule: " + lint.getRuleId() + "\n" + lint.getDetail()); } return null; } From fc1da8d3fbf8a9095419cf1a66bf473516e85c3f Mon Sep 17 00:00:00 2001 From: Stephen Panaro Date: Fri, 19 Aug 2022 10:22:50 -0400 Subject: [PATCH 238/757] Fix tests --- .../test/java/com/diffplug/spotless/kotlin/KtLintStepTest.java | 2 ++ 1 file changed, 2 insertions(+) diff --git a/testlib/src/test/java/com/diffplug/spotless/kotlin/KtLintStepTest.java b/testlib/src/test/java/com/diffplug/spotless/kotlin/KtLintStepTest.java index a4a43ef44e..d9e6042c23 100644 --- a/testlib/src/test/java/com/diffplug/spotless/kotlin/KtLintStepTest.java +++ b/testlib/src/test/java/com/diffplug/spotless/kotlin/KtLintStepTest.java @@ -32,6 +32,7 @@ void behavior() throws Exception { .testResourceException("kotlin/ktlint/unsolvable.dirty", assertion -> { assertion.isInstanceOf(AssertionError.class); assertion.hasMessage("Error on line: 1, column: 1\n" + + "rule: no-wildcard-imports\n" + "Wildcard import"); }); } @@ -44,6 +45,7 @@ void worksPre0_46_1() throws Exception { .testResourceException("kotlin/ktlint/unsolvable.dirty", assertion -> { assertion.isInstanceOf(AssertionError.class); assertion.hasMessage("Error on line: 1, column: 1\n" + + "rule: no-wildcard-imports\n" + "Wildcard import"); }); } From 781eb684315319f278a74c84aa6f4cfab415bf84 Mon Sep 17 00:00:00 2001 From: Matthew de Detrich Date: Mon, 22 Aug 2022 13:18:50 +0200 Subject: [PATCH 239/757] Convert scalafmt integration to use a compile-only sourceset --- CHANGES.md | 1 + lib/build.gradle | 6 +- .../diffplug/spotless/scala/ScalaFmtStep.java | 93 ++----------------- .../glue/scalafmt/ScalafmtFormatterFunc.java | 56 +++++++++++ .../scalafmt/basic.cleanWithCustomConf_1.1.0 | 24 ----- .../scalafmt/basic.cleanWithCustomConf_2.0.1 | 25 ----- .../scala/scalafmt/basic.clean_1.1.0 | 16 ---- .../scala/scalafmt/basic.clean_2.0.1 | 18 ---- .../scala/scalafmt/basicPost2.0.0.clean | 18 ---- .../basicPost2.0.0.cleanWithCustomConf | 25 ----- .../resources/scala/scalafmt/scalafmt.conf | 2 + .../spotless/scala/ScalaFmtStepTest.java | 44 ++------- 12 files changed, 81 insertions(+), 247 deletions(-) create mode 100644 lib/src/scalafmt/java/com/diffplug/spotless/glue/scalafmt/ScalafmtFormatterFunc.java delete mode 100644 testlib/src/main/resources/scala/scalafmt/basic.cleanWithCustomConf_1.1.0 delete mode 100644 testlib/src/main/resources/scala/scalafmt/basic.cleanWithCustomConf_2.0.1 delete mode 100644 testlib/src/main/resources/scala/scalafmt/basic.clean_1.1.0 delete mode 100644 testlib/src/main/resources/scala/scalafmt/basic.clean_2.0.1 delete mode 100644 testlib/src/main/resources/scala/scalafmt/basicPost2.0.0.clean delete mode 100644 testlib/src/main/resources/scala/scalafmt/basicPost2.0.0.cleanWithCustomConf diff --git a/CHANGES.md b/CHANGES.md index 751749585f..446698d7ed 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -10,6 +10,7 @@ This document is intended for Spotless developers. We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format (starting after version `1.27.0`). ## [Unreleased] +* Converted `scalafmt` integration to use a compile-only source set. (fixes [#524](https://github.com/diffplug/spotless/issues/524)) ## [2.28.1] - 2022-08-10 ### Fixed diff --git a/lib/build.gradle b/lib/build.gradle index e14e5c6438..0b3f4555b2 100644 --- a/lib/build.gradle +++ b/lib/build.gradle @@ -12,7 +12,8 @@ def NEEDS_GLUE = [ 'ktfmt', 'ktlint', 'flexmark', - 'diktat' + 'diktat', + 'scalafmt' ] for (glue in NEEDS_GLUE) { sourceSets.register(glue) { @@ -51,6 +52,9 @@ dependencies { ktlintCompileOnly "com.pinterest.ktlint:ktlint-ruleset-experimental:$VER_KTLINT" ktlintCompileOnly "com.pinterest.ktlint:ktlint-ruleset-standard:$VER_KTLINT" + String VER_SCALAFMT="3.5.9" + scalafmtCompileOnly "org.scalameta:scalafmt-core_2.13:$VER_SCALAFMT" + String VER_DIKTAT = "1.2.3" diktatCompileOnly "org.cqfn.diktat:diktat-rules:$VER_DIKTAT" diff --git a/lib/src/main/java/com/diffplug/spotless/scala/ScalaFmtStep.java b/lib/src/main/java/com/diffplug/spotless/scala/ScalaFmtStep.java index 8c8e4ccb2d..34c951cf06 100644 --- a/lib/src/main/java/com/diffplug/spotless/scala/ScalaFmtStep.java +++ b/lib/src/main/java/com/diffplug/spotless/scala/ScalaFmtStep.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. @@ -18,13 +18,8 @@ import java.io.File; import java.io.IOException; import java.io.Serializable; -import java.lang.reflect.Method; -import java.nio.charset.StandardCharsets; -import java.nio.file.Files; +import java.lang.reflect.Constructor; import java.util.Collections; -import java.util.Objects; -import java.util.regex.Matcher; -import java.util.regex.Pattern; import javax.annotation.Nullable; @@ -39,12 +34,8 @@ public class ScalaFmtStep { // prevent direct instantiation private ScalaFmtStep() {} - private static final Pattern VERSION_PRE_2_0 = Pattern.compile("[10]\\.(\\d+)\\.\\d+"); - private static final Pattern VERSION_PRE_3_0 = Pattern.compile("2\\.(\\d+)\\.\\d+"); - private static final String DEFAULT_VERSION = "3.0.8"; + private static final String DEFAULT_VERSION = "3.5.9"; static final String NAME = "scalafmt"; - static final String MAVEN_COORDINATE_PRE_2_0 = "com.geirsson:scalafmt-core_2.11:"; - static final String MAVEN_COORDINATE_PRE_3_0 = "org.scalameta:scalafmt-core_2.11:"; static final String MAVEN_COORDINATE = "org.scalameta:scalafmt-core_2.13:"; public static FormatterStep create(Provisioner provisioner) { @@ -52,10 +43,8 @@ public static FormatterStep create(Provisioner provisioner) { } public static FormatterStep create(String version, Provisioner provisioner, @Nullable File configFile) { - Objects.requireNonNull(version, "version"); - Objects.requireNonNull(provisioner, "provisioner"); return FormatterStep.createLazy(NAME, - () -> new State(version, provisioner, configFile), + () -> new State(JarState.from(MAVEN_COORDINATE + version, provisioner), configFile), State::createFormat); } @@ -69,78 +58,16 @@ static final class State implements Serializable { final JarState jarState; final FileSignature configSignature; - State(String version, Provisioner provisioner, @Nullable File configFile) throws IOException { - String mavenCoordinate; - Matcher versionMatcher; - if ((versionMatcher = VERSION_PRE_2_0.matcher(version)).matches()) { - mavenCoordinate = MAVEN_COORDINATE_PRE_2_0; - } else if ((versionMatcher = VERSION_PRE_3_0.matcher(version)).matches()) { - mavenCoordinate = MAVEN_COORDINATE_PRE_3_0; - } else { - mavenCoordinate = MAVEN_COORDINATE; - } - - this.jarState = JarState.from(mavenCoordinate + version, provisioner); + State(JarState jarState, @Nullable File configFile) throws IOException { + this.jarState = jarState; this.configSignature = FileSignature.signAsList(configFile == null ? Collections.emptySet() : Collections.singleton(configFile)); } FormatterFunc createFormat() throws Exception { - ClassLoader classLoader = jarState.getClassLoader(); - - // scalafmt returns instances of formatted, we get result by calling get() - Class formatted = classLoader.loadClass("org.scalafmt.Formatted"); - Method formattedGet = formatted.getMethod("get"); - - // this is how we actually do a format - Class scalafmt = classLoader.loadClass("org.scalafmt.Scalafmt"); - Class scalaSet = classLoader.loadClass("scala.collection.immutable.Set"); - - Object defaultScalaFmtConfig = scalafmt.getMethod("format$default$2").invoke(null); - Object emptyRange = scalafmt.getMethod("format$default$3").invoke(null); - Method formatMethod = scalafmt.getMethod("format", String.class, defaultScalaFmtConfig.getClass(), scalaSet); - - // now we just need to parse the config, if any - Object config; - if (configSignature.files().isEmpty()) { - config = defaultScalaFmtConfig; - } else { - File file = configSignature.getOnlyFile(); - - Class optionCls = classLoader.loadClass("scala.Option"); - Class configCls = classLoader.loadClass("org.scalafmt.config.Config"); - Class scalafmtCls = classLoader.loadClass("org.scalafmt.Scalafmt"); - - Object configured; - - try { - // scalafmt >= 1.6.0 - Method parseHoconConfig = scalafmtCls.getMethod("parseHoconConfig", String.class); - - String configStr = new String(Files.readAllBytes(file.toPath()), StandardCharsets.UTF_8); - - configured = parseHoconConfig.invoke(null, configStr); - } catch (NoSuchMethodException e) { - // scalafmt >= v0.7.0-RC1 && scalafmt < 1.6.0 - Method fromHocon = configCls.getMethod("fromHoconString", String.class, optionCls); - Object fromHoconEmptyPath = configCls.getMethod("fromHoconString$default$2").invoke(null); - - String configStr = new String(Files.readAllBytes(file.toPath()), StandardCharsets.UTF_8); - - configured = fromHocon.invoke(null, configStr, fromHoconEmptyPath); - } - - config = invokeNoArg(configured, "get"); - } - return input -> { - Object resultInsideFormatted = formatMethod.invoke(null, input, config, emptyRange); - return (String) formattedGet.invoke(resultInsideFormatted); - }; + final ClassLoader classLoader = jarState.getClassLoader(); + final Class formatterFunc = classLoader.loadClass("com.diffplug.spotless.glue.scalafmt.ScalafmtFormatterFunc"); + final Constructor constructor = formatterFunc.getConstructor(FileSignature.class); + return (FormatterFunc) constructor.newInstance(this.configSignature); } } - - private static Object invokeNoArg(Object obj, String toInvoke) throws Exception { - Class clazz = obj.getClass(); - Method method = clazz.getMethod(toInvoke); - return method.invoke(obj); - } } diff --git a/lib/src/scalafmt/java/com/diffplug/spotless/glue/scalafmt/ScalafmtFormatterFunc.java b/lib/src/scalafmt/java/com/diffplug/spotless/glue/scalafmt/ScalafmtFormatterFunc.java new file mode 100644 index 0000000000..b5924b2bac --- /dev/null +++ b/lib/src/scalafmt/java/com/diffplug/spotless/glue/scalafmt/ScalafmtFormatterFunc.java @@ -0,0 +1,56 @@ +/* + * Copyright 2022 DiffPlug + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.diffplug.spotless.glue.scalafmt; + +import java.io.File; +import java.lang.reflect.Method; +import java.nio.charset.StandardCharsets; +import java.nio.file.Files; + +import org.scalafmt.Scalafmt; +import org.scalafmt.config.ScalafmtConfig; +import org.scalafmt.config.ScalafmtConfig$; + +import com.diffplug.spotless.FileSignature; +import com.diffplug.spotless.FormatterFunc; + +import scala.collection.immutable.Set$; + +public class ScalafmtFormatterFunc implements FormatterFunc { + private final FileSignature configSignature; + + public ScalafmtFormatterFunc(FileSignature configSignature) { + this.configSignature = configSignature; + } + + @Override + public String apply(String input) throws Exception { + ScalafmtConfig config; + if (configSignature.files().isEmpty()) { + // Note that reflection is used here only because Scalafmt has a method called + // default which happens to be a reserved Java keyword. The only way to call + // such methods is by reflection, see + // https://vlkan.com/blog/post/2015/11/20/scala-method-with-java-reserved-keyword/ + Method method = ScalafmtConfig$.MODULE$.getClass().getDeclaredMethod("default"); + config = (ScalafmtConfig) method.invoke(ScalafmtConfig$.MODULE$); + } else { + File file = configSignature.getOnlyFile(); + String configStr = new String(Files.readAllBytes(file.toPath()), StandardCharsets.UTF_8); + config = Scalafmt.parseHoconConfig(configStr).get(); + } + return Scalafmt.format(input, config, Set$.MODULE$.empty()).get(); + } +} diff --git a/testlib/src/main/resources/scala/scalafmt/basic.cleanWithCustomConf_1.1.0 b/testlib/src/main/resources/scala/scalafmt/basic.cleanWithCustomConf_1.1.0 deleted file mode 100644 index 98bf69b7af..0000000000 --- a/testlib/src/main/resources/scala/scalafmt/basic.cleanWithCustomConf_1.1.0 +++ /dev/null @@ -1,24 +0,0 @@ -@foobar("annot", { - val x = 2 - val y = 2 // y=2 - x + y -}) -object a - extends b - with c { - def foo[ - T: Int#Double#Triple, - R <% String]( - @annot1 - x: Int @annot2 = - 2, - y: Int = 3) - : Int = { - "match" match { - case 1 | 2 => - 3 - case 2 => - 2 - } - } -} diff --git a/testlib/src/main/resources/scala/scalafmt/basic.cleanWithCustomConf_2.0.1 b/testlib/src/main/resources/scala/scalafmt/basic.cleanWithCustomConf_2.0.1 deleted file mode 100644 index fc8267fb75..0000000000 --- a/testlib/src/main/resources/scala/scalafmt/basic.cleanWithCustomConf_2.0.1 +++ /dev/null @@ -1,25 +0,0 @@ -@foobar("annot", { - val x = 2 - val y = 2 // y=2 - x + y -}) -object a - extends b - with c { - def foo[ - T: Int#Double#Triple, - R <% String - ]( - @annot1 - x: Int @annot2 = - 2, - y: Int = 3 - ): Int = { - "match" match { - case 1 | 2 => - 3 - case 2 => - 2 - } - } -} diff --git a/testlib/src/main/resources/scala/scalafmt/basic.clean_1.1.0 b/testlib/src/main/resources/scala/scalafmt/basic.clean_1.1.0 deleted file mode 100644 index 922a2ccbb9..0000000000 --- a/testlib/src/main/resources/scala/scalafmt/basic.clean_1.1.0 +++ /dev/null @@ -1,16 +0,0 @@ -@foobar("annot", { - val x = 2 - val y = 2 // y=2 - x + y -}) -object a extends b with c { - def foo[T: Int#Double#Triple, R <% String](@annot1 - x: Int @annot2 = 2, - y: Int = 3): Int = { - "match" match { - case 1 | 2 => - 3 - case 2 => 2 - } - } -} diff --git a/testlib/src/main/resources/scala/scalafmt/basic.clean_2.0.1 b/testlib/src/main/resources/scala/scalafmt/basic.clean_2.0.1 deleted file mode 100644 index b838dfea65..0000000000 --- a/testlib/src/main/resources/scala/scalafmt/basic.clean_2.0.1 +++ /dev/null @@ -1,18 +0,0 @@ -@foobar("annot", { - val x = 2 - val y = 2 // y=2 - x + y -}) -object a extends b with c { - def foo[T: Int#Double#Triple, R <% String]( - @annot1 - x: Int @annot2 = 2, - y: Int = 3 - ): Int = { - "match" match { - case 1 | 2 => - 3 - case 2 => 2 - } - } -} diff --git a/testlib/src/main/resources/scala/scalafmt/basicPost2.0.0.clean b/testlib/src/main/resources/scala/scalafmt/basicPost2.0.0.clean deleted file mode 100644 index b838dfea65..0000000000 --- a/testlib/src/main/resources/scala/scalafmt/basicPost2.0.0.clean +++ /dev/null @@ -1,18 +0,0 @@ -@foobar("annot", { - val x = 2 - val y = 2 // y=2 - x + y -}) -object a extends b with c { - def foo[T: Int#Double#Triple, R <% String]( - @annot1 - x: Int @annot2 = 2, - y: Int = 3 - ): Int = { - "match" match { - case 1 | 2 => - 3 - case 2 => 2 - } - } -} diff --git a/testlib/src/main/resources/scala/scalafmt/basicPost2.0.0.cleanWithCustomConf b/testlib/src/main/resources/scala/scalafmt/basicPost2.0.0.cleanWithCustomConf deleted file mode 100644 index fc8267fb75..0000000000 --- a/testlib/src/main/resources/scala/scalafmt/basicPost2.0.0.cleanWithCustomConf +++ /dev/null @@ -1,25 +0,0 @@ -@foobar("annot", { - val x = 2 - val y = 2 // y=2 - x + y -}) -object a - extends b - with c { - def foo[ - T: Int#Double#Triple, - R <% String - ]( - @annot1 - x: Int @annot2 = - 2, - y: Int = 3 - ): Int = { - "match" match { - case 1 | 2 => - 3 - case 2 => - 2 - } - } -} diff --git a/testlib/src/main/resources/scala/scalafmt/scalafmt.conf b/testlib/src/main/resources/scala/scalafmt/scalafmt.conf index 5007f5e8ff..bcfec161f4 100644 --- a/testlib/src/main/resources/scala/scalafmt/scalafmt.conf +++ b/testlib/src/main/resources/scala/scalafmt/scalafmt.conf @@ -1,2 +1,4 @@ +version = 3.5.9 +runner.dialect = scala213 style = defaultWithAlign # For pretty alignment. maxColumn = 20 # For my teensy narrow display diff --git a/testlib/src/test/java/com/diffplug/spotless/scala/ScalaFmtStepTest.java b/testlib/src/test/java/com/diffplug/spotless/scala/ScalaFmtStepTest.java index 0f42252d36..8003607962 100644 --- a/testlib/src/test/java/com/diffplug/spotless/scala/ScalaFmtStepTest.java +++ b/testlib/src/test/java/com/diffplug/spotless/scala/ScalaFmtStepTest.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. @@ -20,7 +20,7 @@ import java.io.File; import java.io.IOException; -import java.lang.reflect.InvocationTargetException; +import java.util.NoSuchElementException; import org.junit.jupiter.api.Test; @@ -34,38 +34,16 @@ class ScalaFmtStepTest extends ResourceHarness { @Test void behaviorDefaultConfig() throws Exception { - StepHarness.forStep(ScalaFmtStep.create("1.1.0", TestProvisioner.mavenCentral(), null)) - .testResource("scala/scalafmt/basic.dirty", "scala/scalafmt/basic.clean_1.1.0"); - StepHarness.forStep(ScalaFmtStep.create("2.0.1", TestProvisioner.mavenCentral(), null)) - .testResource("scala/scalafmt/basic.dirty", "scala/scalafmt/basic.clean_2.0.1"); StepHarness.forStep(ScalaFmtStep.create("3.0.0", TestProvisioner.mavenCentral(), null)) .testResource("scala/scalafmt/basic.dirty", "scala/scalafmt/basic.clean_3.0.0"); } @Test void behaviorCustomConfig() throws Exception { - StepHarness.forStep(ScalaFmtStep.create("1.1.0", TestProvisioner.mavenCentral(), createTestFile("scala/scalafmt/scalafmt.conf"))) - .testResource("scala/scalafmt/basic.dirty", "scala/scalafmt/basic.cleanWithCustomConf_1.1.0"); - StepHarness.forStep(ScalaFmtStep.create("2.0.1", TestProvisioner.mavenCentral(), createTestFile("scala/scalafmt/scalafmt.conf"))) - .testResource("scala/scalafmt/basic.dirty", "scala/scalafmt/basic.cleanWithCustomConf_2.0.1"); StepHarness.forStep(ScalaFmtStep.create("3.0.0", TestProvisioner.mavenCentral(), createTestFile("scala/scalafmt/scalafmt.conf"))) .testResource("scala/scalafmt/basic.dirty", "scala/scalafmt/basic.cleanWithCustomConf_3.0.0"); } - @Test - void behaviorDefaultConfigVersion_2_0_0() throws Exception { - FormatterStep step = ScalaFmtStep.create("2.0.0", TestProvisioner.mavenCentral(), null); - StepHarness.forStep(step) - .testResource("scala/scalafmt/basic.dirty", "scala/scalafmt/basicPost2.0.0.clean"); - } - - @Test - void behaviorCustomConfigVersion_2_0_0() throws Exception { - FormatterStep step = ScalaFmtStep.create("2.0.0", TestProvisioner.mavenCentral(), createTestFile("scala/scalafmt/scalafmt.conf")); - StepHarness.forStep(step) - .testResource("scala/scalafmt/basic.dirty", "scala/scalafmt/basicPost2.0.0.cleanWithCustomConf"); - } - @Test void behaviorDefaultConfigVersion_3_0_0() throws Exception { FormatterStep step = ScalaFmtStep.create("3.0.0", TestProvisioner.mavenCentral(), null); @@ -83,7 +61,7 @@ void behaviorCustomConfigVersion_3_0_0() throws Exception { @Test void equality() throws Exception { new SerializableEqualityTester() { - String version = "0.5.1"; + String version = "3.5.9"; File configFile = null; @Override @@ -91,7 +69,7 @@ protected void setupTest(API api) throws IOException { // same version == same api.areDifferentThan(); // change the version, and it's different - version = "0.5.0"; + version = "3.5.8"; api.areDifferentThan(); // add a config file, and its different configFile = createTestFile("scala/scalafmt/scalafmt.conf"); @@ -113,18 +91,10 @@ void invalidConfiguration() throws Exception { File invalidConfFile = createTestFile("scala/scalafmt/scalafmt.invalid.conf"); Provisioner provisioner = TestProvisioner.mavenCentral(); - InvocationTargetException exception; - - exception = assertThrows(InvocationTargetException.class, - () -> StepHarness.forStep(ScalaFmtStep.create("1.1.0", provisioner, invalidConfFile)).test("", "")); - assertThat(exception.getTargetException().getMessage()).contains("Invalid fields: invalidScalaFmtConfigField"); - - exception = assertThrows(InvocationTargetException.class, - () -> StepHarness.forStep(ScalaFmtStep.create("2.0.1", provisioner, invalidConfFile)).test("", "")); - assertThat(exception.getTargetException().getMessage()).contains("Invalid field: invalidScalaFmtConfigField"); + NoSuchElementException exception; - exception = assertThrows(InvocationTargetException.class, + exception = assertThrows(NoSuchElementException.class, () -> StepHarness.forStep(ScalaFmtStep.create("3.0.0", provisioner, invalidConfFile)).test("", "")); - assertThat(exception.getTargetException().getMessage()).contains("found option 'invalidScalaFmtConfigField' which wasn't expected"); + assertThat(exception.getMessage()).contains("found option 'invalidScalaFmtConfigField' which wasn't expected"); } } From fa9ad004babe8841bf51f6503fe223619186ac36 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 22 Aug 2022 12:02:49 +0000 Subject: [PATCH 240/757] Bump com.github.spotbugs from 5.0.9 to 5.0.10 Bumps com.github.spotbugs from 5.0.9 to 5.0.10. --- updated-dependencies: - dependency-name: com.github.spotbugs dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] --- settings.gradle | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/settings.gradle b/settings.gradle index 77f17be106..83ed4aa59d 100644 --- a/settings.gradle +++ b/settings.gradle @@ -6,7 +6,7 @@ pluginManagement { // https://github.com/gradle-nexus/publish-plugin/releases id 'io.github.gradle-nexus.publish-plugin' version '1.1.0' // https://github.com/spotbugs/spotbugs-gradle-plugin/releases - id 'com.github.spotbugs' version '5.0.9' + id 'com.github.spotbugs' version '5.0.10' // https://github.com/diffplug/spotless-changelog id 'com.diffplug.spotless-changelog' version '2.3.2' // https://github.com/diffplug/goomph/blob/main/CHANGES.md From 137392f5fe38deaddebce6114d7e06ea8b517396 Mon Sep 17 00:00:00 2001 From: Matthew de Detrich Date: Tue, 23 Aug 2022 01:06:12 +0200 Subject: [PATCH 241/757] Allow configuration of scalaMajorVersion --- .../diffplug/spotless/scala/ScalaFmtStep.java | 18 +++++++++++++++--- .../gradle/spotless/ScalaExtension.java | 14 +++++++++++--- .../spotless/maven/scala/Scalafmt.java | 6 +++++- 3 files changed, 31 insertions(+), 7 deletions(-) diff --git a/lib/src/main/java/com/diffplug/spotless/scala/ScalaFmtStep.java b/lib/src/main/java/com/diffplug/spotless/scala/ScalaFmtStep.java index 34c951cf06..6ef9fcd5a7 100644 --- a/lib/src/main/java/com/diffplug/spotless/scala/ScalaFmtStep.java +++ b/lib/src/main/java/com/diffplug/spotless/scala/ScalaFmtStep.java @@ -35,16 +35,24 @@ public class ScalaFmtStep { private ScalaFmtStep() {} private static final String DEFAULT_VERSION = "3.5.9"; + + private static final String DEFAULT_SCALA_MAJOR_VERSION = "2.13"; static final String NAME = "scalafmt"; - static final String MAVEN_COORDINATE = "org.scalameta:scalafmt-core_2.13:"; + static final String MAVEN_COORDINATE = "org.scalameta:scalafmt-core_"; public static FormatterStep create(Provisioner provisioner) { - return create(defaultVersion(), provisioner, null); + return create(defaultVersion(), defaultScalaMajorVersion(), provisioner, null); } public static FormatterStep create(String version, Provisioner provisioner, @Nullable File configFile) { + return create(version, defaultScalaMajorVersion(), provisioner, configFile); + } + + public static FormatterStep create(String version, @Nullable String scalaMajorVersion, Provisioner provisioner, @Nullable File configFile) { + String finalScalaMajorVersion = scalaMajorVersion == null ? DEFAULT_SCALA_MAJOR_VERSION : scalaMajorVersion; + return FormatterStep.createLazy(NAME, - () -> new State(JarState.from(MAVEN_COORDINATE + version, provisioner), configFile), + () -> new State(JarState.from(MAVEN_COORDINATE + finalScalaMajorVersion + ":" + version, provisioner), configFile), State::createFormat); } @@ -52,6 +60,10 @@ public static String defaultVersion() { return DEFAULT_VERSION; } + public static String defaultScalaMajorVersion() { + return DEFAULT_SCALA_MAJOR_VERSION; + } + static final class State implements Serializable { private static final long serialVersionUID = 1L; diff --git a/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/ScalaExtension.java b/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/ScalaExtension.java index f6db64348d..06fddc38e3 100644 --- a/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/ScalaExtension.java +++ b/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/ScalaExtension.java @@ -48,21 +48,29 @@ public ScalaFmtConfig scalafmt(String version) { public class ScalaFmtConfig { final String version; @Nullable + String scalaMajorVersion; + @Nullable Object configFile; ScalaFmtConfig(String version) { this.version = Objects.requireNonNull(version); - addStep(createStep()); } - public void configFile(Object configFile) { + public ScalaFmtConfig configFile(Object configFile) { this.configFile = Objects.requireNonNull(configFile); replaceStep(createStep()); + return this; + } + + public ScalaFmtConfig scalaMajorVersion(String scalaMajorVersion) { + this.scalaMajorVersion = Objects.requireNonNull(scalaMajorVersion); + replaceStep(createStep()); + return this; } private FormatterStep createStep() { File resolvedConfigFile = configFile == null ? null : getProject().file(configFile); - return ScalaFmtStep.create(version, provisioner(), resolvedConfigFile); + return ScalaFmtStep.create(version, scalaMajorVersion, provisioner(), resolvedConfigFile); } } diff --git a/plugin-maven/src/main/java/com/diffplug/spotless/maven/scala/Scalafmt.java b/plugin-maven/src/main/java/com/diffplug/spotless/maven/scala/Scalafmt.java index 470a5ddb72..0de90c4a7f 100644 --- a/plugin-maven/src/main/java/com/diffplug/spotless/maven/scala/Scalafmt.java +++ b/plugin-maven/src/main/java/com/diffplug/spotless/maven/scala/Scalafmt.java @@ -32,10 +32,14 @@ public class Scalafmt implements FormatterStepFactory { @Parameter private String version; + @Parameter + private String scalaMajorVersion; + @Override public FormatterStep newFormatterStep(FormatterStepConfig config) { String scalafmtVersion = version != null ? version : ScalaFmtStep.defaultVersion(); + String scalafmtScalaMajorVersion = scalaMajorVersion != null ? scalaMajorVersion : ScalaFmtStep.defaultScalaMajorVersion(); File configFile = config.getFileLocator().locateFile(file); - return ScalaFmtStep.create(scalafmtVersion, config.getProvisioner(), configFile); + return ScalaFmtStep.create(scalafmtVersion, scalafmtScalaMajorVersion, config.getProvisioner(), configFile); } } From abe0be95ee0a819fa165464405d2da4038e48d10 Mon Sep 17 00:00:00 2001 From: Matthew de Detrich Date: Tue, 23 Aug 2022 01:16:40 +0200 Subject: [PATCH 242/757] Resolve formatting issues --- .../main/java/com/diffplug/gradle/spotless/ScalaExtension.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/ScalaExtension.java b/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/ScalaExtension.java index 06fddc38e3..841c35e6d6 100644 --- a/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/ScalaExtension.java +++ b/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/ScalaExtension.java @@ -1,5 +1,5 @@ /* - * Copyright 2016-2020 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. From df59712817490eb87451770b8a32f461160622ea Mon Sep 17 00:00:00 2001 From: Matthew de Detrich Date: Tue, 23 Aug 2022 01:20:35 +0200 Subject: [PATCH 243/757] More formatting issues --- .../main/java/com/diffplug/spotless/maven/scala/Scalafmt.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugin-maven/src/main/java/com/diffplug/spotless/maven/scala/Scalafmt.java b/plugin-maven/src/main/java/com/diffplug/spotless/maven/scala/Scalafmt.java index 0de90c4a7f..e0dc44bef5 100644 --- a/plugin-maven/src/main/java/com/diffplug/spotless/maven/scala/Scalafmt.java +++ b/plugin-maven/src/main/java/com/diffplug/spotless/maven/scala/Scalafmt.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. From 677415e9c197e81a46d1f1f7d8d7d00b13840007 Mon Sep 17 00:00:00 2001 From: Matthew de Detrich Date: Tue, 23 Aug 2022 01:38:57 +0200 Subject: [PATCH 244/757] Fix accidental removal of addStep --- .../main/java/com/diffplug/gradle/spotless/ScalaExtension.java | 1 + 1 file changed, 1 insertion(+) diff --git a/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/ScalaExtension.java b/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/ScalaExtension.java index 841c35e6d6..8a8765b539 100644 --- a/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/ScalaExtension.java +++ b/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/ScalaExtension.java @@ -54,6 +54,7 @@ public class ScalaFmtConfig { ScalaFmtConfig(String version) { this.version = Objects.requireNonNull(version); + addStep(createStep()); } public ScalaFmtConfig configFile(Object configFile) { From 30d72d82f9183274bfcffced5fc7f4525ed80946 Mon Sep 17 00:00:00 2001 From: Matthew de Detrich Date: Tue, 23 Aug 2022 11:40:06 +0200 Subject: [PATCH 245/757] Add documentation for majorScalaVersion --- CHANGES.md | 1 + plugin-gradle/README.md | 4 ++-- plugin-maven/README.md | 1 + 3 files changed, 4 insertions(+), 2 deletions(-) diff --git a/CHANGES.md b/CHANGES.md index 46524605ac..185ca636ee 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -12,6 +12,7 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format ( ## [Unreleased] ### Changes * Converted `scalafmt` integration to use a compile-only source set. (fixes [#524](https://github.com/diffplug/spotless/issues/524)) +* `scalafmt` integration now has a configuration option `majorScalaVersion` that allows you to configure the Scala version that gets resolved from the maven artifact. [#1283](https://github.com/diffplug/spotless/pull/1283) * Add the `ktlint` rule in error messages when `ktlint` fails to apply a fix ([#1279](https://github.com/diffplug/spotless/pull/1279)) ## [2.28.1] - 2022-08-10 diff --git a/plugin-gradle/README.md b/plugin-gradle/README.md index 53e77a9ced..d107dc7f98 100644 --- a/plugin-gradle/README.md +++ b/plugin-gradle/README.md @@ -388,8 +388,8 @@ spotless { ```gradle spotless { scala { - // version and configFile are both optional - scalafmt('2.6.1').configFile('scalafmt.conf') + // version and configFile, majorScalaVersion are all optional + scalafmt('2.6.1').configFile('scalafmt.conf').majorScalaVersion('2.13') ``` diff --git a/plugin-maven/README.md b/plugin-maven/README.md index fa4cf55c74..0b75c59434 100644 --- a/plugin-maven/README.md +++ b/plugin-maven/README.md @@ -395,6 +395,7 @@ Groovy-Eclipse formatting errors/warnings lead per default to a build failure. T 2.0.1 ${project.basedir}/scalafmt.conf + 2.13 ``` From 872424a816b8f1068dfa3b7ae82c447ac342baba Mon Sep 17 00:00:00 2001 From: Matthew de Detrich Date: Tue, 23 Aug 2022 11:40:59 +0200 Subject: [PATCH 246/757] Update scalafmt versions in documentation --- plugin-gradle/README.md | 2 +- plugin-maven/README.md | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/plugin-gradle/README.md b/plugin-gradle/README.md index d107dc7f98..7e0a39ab0e 100644 --- a/plugin-gradle/README.md +++ b/plugin-gradle/README.md @@ -389,7 +389,7 @@ spotless { spotless { scala { // version and configFile, majorScalaVersion are all optional - scalafmt('2.6.1').configFile('scalafmt.conf').majorScalaVersion('2.13') + scalafmt('3.5.9').configFile('scalafmt.conf').majorScalaVersion('2.13') ``` diff --git a/plugin-maven/README.md b/plugin-maven/README.md index 0b75c59434..f29d34f5bd 100644 --- a/plugin-maven/README.md +++ b/plugin-maven/README.md @@ -393,7 +393,7 @@ Groovy-Eclipse formatting errors/warnings lead per default to a build failure. T ```xml - 2.0.1 + 3.5.9 ${project.basedir}/scalafmt.conf 2.13 From 24ca9ec83ed01917bb13827c2f2a26a421610f82 Mon Sep 17 00:00:00 2001 From: Ned Twigg Date: Tue, 23 Aug 2022 12:32:51 -0700 Subject: [PATCH 247/757] Add info about changes to scalafmt default version. --- CHANGES.md | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/CHANGES.md b/CHANGES.md index 185ca636ee..0fc7f14021 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -10,10 +10,12 @@ This document is intended for Spotless developers. We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format (starting after version `1.27.0`). ## [Unreleased] +### Added +* `scalafmt` integration now has a configuration option `majorScalaVersion` that allows you to configure the Scala version that gets resolved from the maven artifact ([#1283](https://github.com/diffplug/spotless/pull/1283)) + * Converted `scalafmt` integration to use a compile-only source set (fixes [#524](https://github.com/diffplug/spotless/issues/524)) ### Changes -* Converted `scalafmt` integration to use a compile-only source set. (fixes [#524](https://github.com/diffplug/spotless/issues/524)) -* `scalafmt` integration now has a configuration option `majorScalaVersion` that allows you to configure the Scala version that gets resolved from the maven artifact. [#1283](https://github.com/diffplug/spotless/pull/1283) * Add the `ktlint` rule in error messages when `ktlint` fails to apply a fix ([#1279](https://github.com/diffplug/spotless/pull/1279)) +* Bump default `scalafmt` to latest `3.0.8` -> `3.5.9` (removed support for pre-`3.0.0`) ([#1283](https://github.com/diffplug/spotless/pull/1283)) ## [2.28.1] - 2022-08-10 ### Fixed From 735c7b5228a46a5d292b0aecfdc2d459932ac414 Mon Sep 17 00:00:00 2001 From: Ned Twigg Date: Tue, 23 Aug 2022 12:33:02 -0700 Subject: [PATCH 248/757] Update the tool-specific changelogs. --- plugin-gradle/CHANGES.md | 3 +++ plugin-maven/CHANGES.md | 3 +++ 2 files changed, 6 insertions(+) diff --git a/plugin-gradle/CHANGES.md b/plugin-gradle/CHANGES.md index 72d600688c..30235660d5 100644 --- a/plugin-gradle/CHANGES.md +++ b/plugin-gradle/CHANGES.md @@ -3,8 +3,11 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format (starting after version `3.27.0`). ## [Unreleased] +### Added +* `scalafmt` integration now has a configuration option `majorScalaVersion` that allows you to configure the Scala version that gets resolved from the maven artifact ([#1283](https://github.com/diffplug/spotless/pull/1283)) ### Changes * Add the `ktlint` rule in error messages when `ktlint` fails to apply a fix ([#1279](https://github.com/diffplug/spotless/pull/1279)) +* Bump default `scalafmt` to latest `3.0.8` -> `3.5.9` (removed support for pre-`3.0.0`) ([#1283](https://github.com/diffplug/spotless/pull/1283)) ## [6.9.1] - 2022-08-10 ### Fixed diff --git a/plugin-maven/CHANGES.md b/plugin-maven/CHANGES.md index 7366c3b731..ced0a0baba 100644 --- a/plugin-maven/CHANGES.md +++ b/plugin-maven/CHANGES.md @@ -3,8 +3,11 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format (starting after version `1.27.0`). ## [Unreleased] +### Added +* `scalafmt` integration now has a configuration option `majorScalaVersion` that allows you to configure the Scala version that gets resolved from the maven artifact ([#1283](https://github.com/diffplug/spotless/pull/1283)) ### Changes * Add the `ktlint` rule in error messages when `ktlint` fails to apply a fix ([#1279](https://github.com/diffplug/spotless/pull/1279)) +* Bump default `scalafmt` to latest `3.0.8` -> `3.5.9` (removed support for pre-`3.0.0`) ([#1283](https://github.com/diffplug/spotless/pull/1283)) ## [2.24.1] - 2022-08-10 ### Fixed From a75877c085b283a8eafb9397008cb7d6ce208217 Mon Sep 17 00:00:00 2001 From: Ned Twigg Date: Tue, 23 Aug 2022 12:37:36 -0700 Subject: [PATCH 249/757] Massive speedup. FormatterFunc is instantiated lazily and is not involved in serialization/equality, so good to eagerly initialize in the constructor. --- .../glue/scalafmt/ScalafmtFormatterFunc.java | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/lib/src/scalafmt/java/com/diffplug/spotless/glue/scalafmt/ScalafmtFormatterFunc.java b/lib/src/scalafmt/java/com/diffplug/spotless/glue/scalafmt/ScalafmtFormatterFunc.java index b5924b2bac..49e1b6a1be 100644 --- a/lib/src/scalafmt/java/com/diffplug/spotless/glue/scalafmt/ScalafmtFormatterFunc.java +++ b/lib/src/scalafmt/java/com/diffplug/spotless/glue/scalafmt/ScalafmtFormatterFunc.java @@ -30,15 +30,9 @@ import scala.collection.immutable.Set$; public class ScalafmtFormatterFunc implements FormatterFunc { - private final FileSignature configSignature; + private final ScalafmtConfig config; - public ScalafmtFormatterFunc(FileSignature configSignature) { - this.configSignature = configSignature; - } - - @Override - public String apply(String input) throws Exception { - ScalafmtConfig config; + public ScalafmtFormatterFunc(FileSignature configSignature) throws Exception { if (configSignature.files().isEmpty()) { // Note that reflection is used here only because Scalafmt has a method called // default which happens to be a reserved Java keyword. The only way to call @@ -51,6 +45,10 @@ public String apply(String input) throws Exception { String configStr = new String(Files.readAllBytes(file.toPath()), StandardCharsets.UTF_8); config = Scalafmt.parseHoconConfig(configStr).get(); } + } + + @Override + public String apply(String input) { return Scalafmt.format(input, config, Set$.MODULE$.empty()).get(); } } From e9d31502b710b56b57bbcc46be02f11313dfbfe0 Mon Sep 17 00:00:00 2001 From: Ned Twigg Date: Tue, 23 Aug 2022 13:02:51 -0700 Subject: [PATCH 250/757] Fix test. --- .../com/diffplug/spotless/scala/ScalaFmtStepTest.java | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/testlib/src/test/java/com/diffplug/spotless/scala/ScalaFmtStepTest.java b/testlib/src/test/java/com/diffplug/spotless/scala/ScalaFmtStepTest.java index 8003607962..bad573e985 100644 --- a/testlib/src/test/java/com/diffplug/spotless/scala/ScalaFmtStepTest.java +++ b/testlib/src/test/java/com/diffplug/spotless/scala/ScalaFmtStepTest.java @@ -20,7 +20,7 @@ import java.io.File; import java.io.IOException; -import java.util.NoSuchElementException; +import java.lang.reflect.InvocationTargetException; import org.junit.jupiter.api.Test; @@ -91,10 +91,8 @@ void invalidConfiguration() throws Exception { File invalidConfFile = createTestFile("scala/scalafmt/scalafmt.invalid.conf"); Provisioner provisioner = TestProvisioner.mavenCentral(); - NoSuchElementException exception; - - exception = assertThrows(NoSuchElementException.class, + InvocationTargetException exception = assertThrows(InvocationTargetException.class, () -> StepHarness.forStep(ScalaFmtStep.create("3.0.0", provisioner, invalidConfFile)).test("", "")); - assertThat(exception.getMessage()).contains("found option 'invalidScalaFmtConfigField' which wasn't expected"); + assertThat(exception.getCause().getMessage()).contains("found option 'invalidScalaFmtConfigField' which wasn't expected"); } } From a5332a6df3166cd1085092419b4f341a4dab3fa9 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Tue, 23 Aug 2022 20:21:26 +0000 Subject: [PATCH 251/757] Bump slf4j-api from 1.7.36 to 2.0.0 Bumps [slf4j-api](https://github.com/qos-ch/slf4j) from 1.7.36 to 2.0.0. - [Release notes](https://github.com/qos-ch/slf4j/releases) - [Commits](https://github.com/qos-ch/slf4j/compare/v_1.7.36...v_2.0.0) --- updated-dependencies: - dependency-name: org.slf4j:slf4j-api dependency-type: direct:production update-type: version-update:semver-major ... Signed-off-by: dependabot[bot] --- lib/build.gradle | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/build.gradle b/lib/build.gradle index 0b3f4555b2..fae8b5b875 100644 --- a/lib/build.gradle +++ b/lib/build.gradle @@ -24,7 +24,7 @@ for (glue in NEEDS_GLUE) { } dependencies { - compileOnly 'org.slf4j:slf4j-api:1.7.36' + compileOnly 'org.slf4j:slf4j-api:2.0.0' // zero runtime reqs is a hard requirements for spotless-lib // if you need a dep, put it in lib-extra testImplementation "org.junit.jupiter:junit-jupiter:$VER_JUNIT" @@ -33,7 +33,7 @@ dependencies { // used for pom sorting sortPomCompileOnly 'com.github.ekryd.sortpom:sortpom-sorter:3.0.0' - sortPomCompileOnly 'org.slf4j:slf4j-api:1.7.35' + sortPomCompileOnly 'org.slf4j:slf4j-api:2.0.0' palantirJavaFormatCompileOnly 'com.palantir.javaformat:palantir-java-format:1.1.0' From 1dfd0ee20868f9ca1b76817ae143712b3df8d729 Mon Sep 17 00:00:00 2001 From: circleci Date: Tue, 23 Aug 2022 21:54:46 +0000 Subject: [PATCH 252/757] Published lib/2.29.0 --- CHANGES.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/CHANGES.md b/CHANGES.md index 0fc7f14021..580b23b9fb 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -10,6 +10,8 @@ This document is intended for Spotless developers. We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format (starting after version `1.27.0`). ## [Unreleased] + +## [2.29.0] - 2022-08-23 ### Added * `scalafmt` integration now has a configuration option `majorScalaVersion` that allows you to configure the Scala version that gets resolved from the maven artifact ([#1283](https://github.com/diffplug/spotless/pull/1283)) * Converted `scalafmt` integration to use a compile-only source set (fixes [#524](https://github.com/diffplug/spotless/issues/524)) From f0ad997adb617fb76afbfa09909294b8aff642b9 Mon Sep 17 00:00:00 2001 From: circleci Date: Tue, 23 Aug 2022 21:55:49 +0000 Subject: [PATCH 253/757] Published gradle/6.10.0 --- plugin-gradle/CHANGES.md | 2 ++ plugin-gradle/README.md | 46 ++++++++++++++++++++-------------------- 2 files changed, 25 insertions(+), 23 deletions(-) diff --git a/plugin-gradle/CHANGES.md b/plugin-gradle/CHANGES.md index 30235660d5..ee1ab8bee8 100644 --- a/plugin-gradle/CHANGES.md +++ b/plugin-gradle/CHANGES.md @@ -3,6 +3,8 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format (starting after version `3.27.0`). ## [Unreleased] + +## [6.10.0] - 2022-08-23 ### Added * `scalafmt` integration now has a configuration option `majorScalaVersion` that allows you to configure the Scala version that gets resolved from the maven artifact ([#1283](https://github.com/diffplug/spotless/pull/1283)) ### Changes diff --git a/plugin-gradle/README.md b/plugin-gradle/README.md index 7e0a39ab0e..a9fcfbfcf6 100644 --- a/plugin-gradle/README.md +++ b/plugin-gradle/README.md @@ -18,9 +18,9 @@ output = [ --> [![Gradle plugin](https://img.shields.io/badge/plugins.gradle.org-com.diffplug.spotless-blue.svg)](https://plugins.gradle.org/plugin/com.diffplug.spotless) [![Maven central](https://img.shields.io/badge/mavencentral-yes-blue.svg)](https://search.maven.org/#search%7Cgav%7C1%7Cg%3A%22com.diffplug.spotless%22%20AND%20a%3A%22spotless-plugin-gradle%22) -[![Javadoc](https://img.shields.io/badge/javadoc-yes-blue.svg)](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.9.1/index.html) +[![Javadoc](https://img.shields.io/badge/javadoc-yes-blue.svg)](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.10.0/index.html) [![License Apache](https://img.shields.io/badge/license-apache-blue.svg)](https://tldrlegal.com/license/apache-license-2.0-(apache-2.0)) -[![Changelog](https://img.shields.io/badge/changelog-6.9.1-blue.svg)](CHANGES.md) +[![Changelog](https://img.shields.io/badge/changelog-6.10.0-blue.svg)](CHANGES.md) [![Circle CI](https://circleci.com/gh/diffplug/spotless/tree/main.svg?style=shield)](https://circleci.com/gh/diffplug/spotless/tree/main) [![Live chat](https://img.shields.io/badge/gitter-chat-brightgreen.svg)](https://gitter.im/diffplug/spotless) @@ -126,10 +126,10 @@ spotless { ``` Spotless consists of a list of formats (in the example above, `misc` and `java`), and each format has: -- a `target` (the files to format), which you set with [`target`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.9.1/com/diffplug/gradle/spotless/FormatExtension.html#target-java.lang.Object...-) and [`targetExclude`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.9.1/com/diffplug/gradle/spotless/FormatExtension.html#targetExclude-java.lang.Object...-) -- a list of `FormatterStep`, which are just `String -> String` functions, such as [`replace`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.9.1/com/diffplug/gradle/spotless/FormatExtension.html#replace-java.lang.String-java.lang.CharSequence-java.lang.CharSequence-), [`replaceRegex`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.9.1/com/diffplug/gradle/spotless/FormatExtension.html#replaceRegex-java.lang.String-java.lang.String-java.lang.String-), [`trimTrailingWhitespace`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.9.1/com/diffplug/gradle/spotless/FormatExtension.html#replace-java.lang.String-java.lang.CharSequence-java.lang.CharSequence-), [`custom`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.9.1/com/diffplug/gradle/spotless/FormatExtension.html#custom-java.lang.String-groovy.lang.Closure-), [`prettier`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.9.1/com/diffplug/gradle/spotless/FormatExtension.html#prettier--), [`eclipseWtp`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.9.1/com/diffplug/gradle/spotless/FormatExtension.html#eclipseWtp-com.diffplug.spotless.extra.wtp.EclipseWtpFormatterStep-), [`licenseHeader`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.9.1/com/diffplug/gradle/spotless/FormatExtension.html#licenseHeader-java.lang.String-java.lang.String-) etc. +- a `target` (the files to format), which you set with [`target`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.10.0/com/diffplug/gradle/spotless/FormatExtension.html#target-java.lang.Object...-) and [`targetExclude`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.10.0/com/diffplug/gradle/spotless/FormatExtension.html#targetExclude-java.lang.Object...-) +- a list of `FormatterStep`, which are just `String -> String` functions, such as [`replace`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.10.0/com/diffplug/gradle/spotless/FormatExtension.html#replace-java.lang.String-java.lang.CharSequence-java.lang.CharSequence-), [`replaceRegex`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.10.0/com/diffplug/gradle/spotless/FormatExtension.html#replaceRegex-java.lang.String-java.lang.String-java.lang.String-), [`trimTrailingWhitespace`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.10.0/com/diffplug/gradle/spotless/FormatExtension.html#replace-java.lang.String-java.lang.CharSequence-java.lang.CharSequence-), [`custom`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.10.0/com/diffplug/gradle/spotless/FormatExtension.html#custom-java.lang.String-groovy.lang.Closure-), [`prettier`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.10.0/com/diffplug/gradle/spotless/FormatExtension.html#prettier--), [`eclipseWtp`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.10.0/com/diffplug/gradle/spotless/FormatExtension.html#eclipseWtp-com.diffplug.spotless.extra.wtp.EclipseWtpFormatterStep-), [`licenseHeader`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.10.0/com/diffplug/gradle/spotless/FormatExtension.html#licenseHeader-java.lang.String-java.lang.String-) etc. -All the generic steps live in [`FormatExtension`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.9.1/com/diffplug/gradle/spotless/FormatExtension.html), and there are many language-specific steps which live in its language-specific subclasses, which are described below. +All the generic steps live in [`FormatExtension`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.10.0/com/diffplug/gradle/spotless/FormatExtension.html), and there are many language-specific steps which live in its language-specific subclasses, which are described below. ### Requirements @@ -141,7 +141,7 @@ If you're stuck on an older version of Gradle, `id 'com.diffplug.gradle.spotless ## Java -`com.diffplug.gradle.spotless.JavaExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.9.1/com/diffplug/gradle/spotless/JavaExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/JavaExtension.java) +`com.diffplug.gradle.spotless.JavaExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.10.0/com/diffplug/gradle/spotless/JavaExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/JavaExtension.java) ```gradle spotless { @@ -248,8 +248,8 @@ spotless { ## Groovy -- `com.diffplug.gradle.spotless.GroovyExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.9.1/com/diffplug/gradle/spotless/GroovyExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/GroovyExtension.java) -- `com.diffplug.gradle.spotless.GroovyGradleExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.9.1/com/diffplug/gradle/spotless/GroovyGradleExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/GroovyGradleExtension.java) +- `com.diffplug.gradle.spotless.GroovyExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.10.0/com/diffplug/gradle/spotless/GroovyExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/GroovyExtension.java) +- `com.diffplug.gradle.spotless.GroovyGradleExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.10.0/com/diffplug/gradle/spotless/GroovyGradleExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/GroovyGradleExtension.java) Configuration for Groovy is similar to [Java](#java), in that it also supports `licenseHeader` and `importOrder`. @@ -300,8 +300,8 @@ Groovy-Eclipse formatting errors/warnings lead per default to a build failure. T ## Kotlin -- `com.diffplug.gradle.spotless.KotlinExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.9.1/com/diffplug/gradle/spotless/KotlinExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/KotlinExtension.java) -- `com.diffplug.gradle.spotless.KotlinGradleExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.9.1/com/diffplug/gradle/spotless/KotlinGradleExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/KotlinGradleExtension.java) +- `com.diffplug.gradle.spotless.KotlinExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.10.0/com/diffplug/gradle/spotless/KotlinExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/KotlinExtension.java) +- `com.diffplug.gradle.spotless.KotlinGradleExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.10.0/com/diffplug/gradle/spotless/KotlinGradleExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/KotlinGradleExtension.java) ```gradle spotless { // if you are using build.gradle.kts, instead of 'spotless {' use: @@ -364,7 +364,7 @@ spotless { ## Scala -`com.diffplug.gradle.spotless.ScalaExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.9.1/com/diffplug/gradle/spotless/ScalaExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/ScalaExtension.java) +`com.diffplug.gradle.spotless.ScalaExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.10.0/com/diffplug/gradle/spotless/ScalaExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/ScalaExtension.java) ```gradle spotless { @@ -396,7 +396,7 @@ spotless { ## C/C++ -`com.diffplug.gradle.spotless.CppExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.9.1/com/diffplug/gradle/spotless/CppExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/CppExtension.java) +`com.diffplug.gradle.spotless.CppExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.10.0/com/diffplug/gradle/spotless/CppExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/CppExtension.java) ```gradle spotless { @@ -428,7 +428,7 @@ spotles { ## Python -`com.diffplug.gradle.spotless.PythonExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.9.1/com/diffplug/gradle/spotless/PythonExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/PythonExtension.java) +`com.diffplug.gradle.spotless.PythonExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.10.0/com/diffplug/gradle/spotless/PythonExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/PythonExtension.java) ```gradle spotless { @@ -462,7 +462,7 @@ black().pathToExe('C:/myuser/.pyenv/versions/3.8.0/scripts/black.exe') ## FreshMark -`com.diffplug.gradle.spotless.FreshMarkExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.9.1/com/diffplug/gradle/spotless/FreshMarkExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/FreshMarkExtension.java) +`com.diffplug.gradle.spotless.FreshMarkExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.10.0/com/diffplug/gradle/spotless/FreshMarkExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/FreshMarkExtension.java) [homepage](https://github.com/diffplug/freshmark). [changelog](https://github.com/diffplug/freshmark/blob/master/CHANGES.md). FreshMark lets you generate markdown in the comments of your markdown. This helps to keep badges and links up-to-date (see the source for this file), and can also be helpful for generating complex tables (see the source for [the parent readme](../README.md)). @@ -483,7 +483,7 @@ spotless { ## Antlr4 -`com.diffplug.gradle.spotless.Antlr4Extension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.9.1/com/diffplug/gradle/spotless/Antlr4Extension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/Antlr4Extension.java) +`com.diffplug.gradle.spotless.Antlr4Extension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.10.0/com/diffplug/gradle/spotless/Antlr4Extension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/Antlr4Extension.java) ```gradle spotless { @@ -508,7 +508,7 @@ antlr4formatter('1.2.1') // version is optional ## SQL -`com.diffplug.gradle.spotless.SqlExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.9.1/com/diffplug/gradle/spotless/SqlExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/SqlExtension.java) +`com.diffplug.gradle.spotless.SqlExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.10.0/com/diffplug/gradle/spotless/SqlExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/SqlExtension.java) ```gradle spotless { @@ -548,7 +548,7 @@ sql.formatter.indent.size=4 ## Typescript -- `com.diffplug.gradle.spotless.TypescriptExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.9.1/com/diffplug/gradle/spotless/TypescriptExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/TypescriptExtension.java) +- `com.diffplug.gradle.spotless.TypescriptExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.10.0/com/diffplug/gradle/spotless/TypescriptExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/TypescriptExtension.java) ```gradle spotless { @@ -591,7 +591,7 @@ For details, see the [npm detection](#npm-detection) and [`.npmrc` detection](#n ## JSON -- `com.diffplug.gradle.spotless.JsonExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.9.1/com/diffplug/gradle/spotless/JsonExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/JsonExtension.java) +- `com.diffplug.gradle.spotless.JsonExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.10.0/com/diffplug/gradle/spotless/JsonExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/JsonExtension.java) ```gradle spotless { @@ -816,7 +816,7 @@ Once a file's license header has a valid year, whether it is a year (`2020`) or * `2017` -> `2017-2020` * `2017-2019` -> `2017-2020` -See the [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.9.1/com/diffplug/gradle/spotless/FormatExtension.LicenseHeaderConfig.html) for a complete listing of options. +See the [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.10.0/com/diffplug/gradle/spotless/FormatExtension.LicenseHeaderConfig.html) for a complete listing of options. @@ -883,9 +883,9 @@ spotless { custom 'lowercase', { str -> str.toLowerCase() } ``` -However, custom rules will disable up-to-date checking and caching, unless you read [this javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.9.1/com/diffplug/gradle/spotless/FormatExtension.html#bumpThisNumberIfACustomStepChanges-int-) and follow its instructions carefully. +However, custom rules will disable up-to-date checking and caching, unless you read [this javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.10.0/com/diffplug/gradle/spotless/FormatExtension.html#bumpThisNumberIfACustomStepChanges-int-) and follow its instructions carefully. -Another option is to create proper `FormatterStep` in your `buildSrc`, and then call [`addStep`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.9.1/com/diffplug/gradle/spotless/FormatExtension.html#addStep-com.diffplug.spotless.FormatterStep-). The contributing guide describes [how to do this](https://github.com/diffplug/spotless/blob/main/CONTRIBUTING.md#how-to-add-a-new-formatterstep). If the step is generally-useful, we hope you'll open a PR to share it! +Another option is to create proper `FormatterStep` in your `buildSrc`, and then call [`addStep`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.10.0/com/diffplug/gradle/spotless/FormatExtension.html#addStep-com.diffplug.spotless.FormatterStep-). The contributing guide describes [how to do this](https://github.com/diffplug/spotless/blob/main/CONTRIBUTING.md#how-to-add-a-new-formatterstep). If the step is generally-useful, we hope you'll open a PR to share it! ```gradle @@ -918,11 +918,11 @@ spotless { format 'foo', com.acme.FooLanguageExtension, { ``` -If you'd like to create a one-off Spotless task outside of the `check`/`apply` framework, see [`FormatExtension.createIndependentApplyTask`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.9.1/com/diffplug/gradle/spotless/FormatExtension.html#createIndependentApplyTask-java.lang.String-). +If you'd like to create a one-off Spotless task outside of the `check`/`apply` framework, see [`FormatExtension.createIndependentApplyTask`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.10.0/com/diffplug/gradle/spotless/FormatExtension.html#createIndependentApplyTask-java.lang.String-). ## Inception (languages within languages within...) -In very rare cases, you might want to format e.g. javascript which is written inside JSP templates, or maybe java within a markdown file, or something wacky like that. You can specify hunks within a file using either open/close tags or a regex with a single capturing group, and then specify rules within it, like so. See [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.9.1/com/diffplug/gradle/spotless/FormatExtension.html#withinBlocks-java.lang.String-java.lang.String-java.lang.String-org.gradle.api.Action-) for more details. +In very rare cases, you might want to format e.g. javascript which is written inside JSP templates, or maybe java within a markdown file, or something wacky like that. You can specify hunks within a file using either open/close tags or a regex with a single capturing group, and then specify rules within it, like so. See [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.10.0/com/diffplug/gradle/spotless/FormatExtension.html#withinBlocks-java.lang.String-java.lang.String-java.lang.String-org.gradle.api.Action-) for more details. ```gradle import com.diffplug.gradle.spotless.JavaExtension From 753f8f76078c81e841eeb9ae50aa108abf64b4f7 Mon Sep 17 00:00:00 2001 From: circleci Date: Tue, 23 Aug 2022 21:57:47 +0000 Subject: [PATCH 254/757] Published maven/2.25.0 --- plugin-maven/CHANGES.md | 2 ++ plugin-maven/README.md | 4 ++-- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/plugin-maven/CHANGES.md b/plugin-maven/CHANGES.md index ced0a0baba..3b6986c5db 100644 --- a/plugin-maven/CHANGES.md +++ b/plugin-maven/CHANGES.md @@ -3,6 +3,8 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format (starting after version `1.27.0`). ## [Unreleased] + +## [2.25.0] - 2022-08-23 ### Added * `scalafmt` integration now has a configuration option `majorScalaVersion` that allows you to configure the Scala version that gets resolved from the maven artifact ([#1283](https://github.com/diffplug/spotless/pull/1283)) ### Changes diff --git a/plugin-maven/README.md b/plugin-maven/README.md index f29d34f5bd..f59d00d47a 100644 --- a/plugin-maven/README.md +++ b/plugin-maven/README.md @@ -12,8 +12,8 @@ output = [ ].join('\n'); --> [![Maven central](https://img.shields.io/badge/mavencentral-com.diffplug.spotless%3Aspotless--maven--plugin-blue.svg)](https://search.maven.org/#search%7Cgav%7C1%7Cg%3A%22com.diffplug.spotless%22%20AND%20a%3A%22spotless-maven-plugin%22) -[![Javadoc](https://img.shields.io/badge/javadoc-yes-blue.svg)](https://javadoc.io/doc/com.diffplug.spotless/spotless-maven-plugin/2.24.1/index.html) -[![Changelog](https://img.shields.io/badge/changelog-2.24.1-brightgreen.svg)](CHANGES.md) +[![Javadoc](https://img.shields.io/badge/javadoc-yes-blue.svg)](https://javadoc.io/doc/com.diffplug.spotless/spotless-maven-plugin/2.25.0/index.html) +[![Changelog](https://img.shields.io/badge/changelog-2.25.0-brightgreen.svg)](CHANGES.md) [![Circle CI](https://circleci.com/gh/diffplug/spotless/tree/main.svg?style=shield)](https://circleci.com/gh/diffplug/spotless/tree/main) [![Live chat](https://img.shields.io/badge/gitter-chat-brightgreen.svg)](https://gitter.im/diffplug/spotless) From 42edcb1c094732c6efb52bc57bb61cc10bb17f88 Mon Sep 17 00:00:00 2001 From: Michael Ernst Date: Thu, 25 Aug 2022 09:28:16 -0700 Subject: [PATCH 255/757] Add documentation in `README.md` --- plugin-gradle/README.md | 42 ++++++++++++++++++++++++++++++++++++++++- 1 file changed, 41 insertions(+), 1 deletion(-) diff --git a/plugin-gradle/README.md b/plugin-gradle/README.md index bb71d8ab5b..aee7d43eef 100644 --- a/plugin-gradle/README.md +++ b/plugin-gradle/README.md @@ -60,7 +60,7 @@ Spotless supports all of Gradle's built-in performance features (incremental bui - [**Quickstart**](#quickstart) - [Requirements](#requirements) - **Languages** - - [Java](#java) ([google-java-format](#google-java-format), [eclipse jdt](#eclipse-jdt), [clang-format](#clang-format), [prettier](#prettier), [palantir-java-format](#palantir-java-format)) + - [Java](#java) ([google-java-format](#google-java-format), [eclipse jdt](#eclipse-jdt), [clang-format](#clang-format), [prettier](#prettier), [palantir-java-format](#palantir-java-format), [type annotations](#Type annotations)) - [Groovy](#groovy) ([eclipse groovy](#eclipse-groovy)) - [Kotlin](#kotlin) ([ktfmt](#ktfmt), [ktlint](#ktlint), [diktat](#diktat), [prettier](#prettier)) - [Scala](#scala) ([scalafmt](#scalafmt)) @@ -117,6 +117,8 @@ spotless { // apply a specific flavor of google-java-format googleJavaFormat('1.8').aosp().reflowLongStrings() + // fix formatting of type annotations + typeAnnotations() // make sure every file has the following copyright header. // optionally, Spotless can set copyright years by digging // through git history (see "license" section below) @@ -162,6 +164,8 @@ spotless { prettier() // has its own section below clangFormat() // has its own section below + typeAnnotations() // has its own section below + licenseHeader '/* (C) $YEAR */' // or licenseHeaderFile } } @@ -188,6 +192,8 @@ spotless { // and/or reflow long strings (requires at least 1.8) // and/or use custom group artifact (you probably don't need this) googleJavaFormat('1.8').aosp().reflowLongStrings().groupArtifact('com.google.googlejavaformat:google-java-format') + // optional: fix formatting of type annotations + typeAnnotations() ``` **⚠️ Note on using Google Java Format with Java 16+** @@ -214,6 +220,8 @@ spotless { palantirJavaFormat() // optional: you can specify a specific version palantirJavaFormat('2.9.0') + // optional: fix formatting of type annotations + typeAnnotations() ``` **⚠️ Note on using Palantir Java Format with Java 16+** @@ -244,6 +252,38 @@ spotless { ``` +### Type annotations + +Type annotations should be on the same line as the type that they qualify. + +```java + @Override + @Deprecated + @Nullable @Interned String s; +``` + +However, some tools format them incorrectly, like this: + +```java + @Override + @Deprecated + @Nullable + @Interned + String s; +``` + +To fix the incorrect formatting, add the `typeAnnotations()` rule after a Java formatter. For example: + +```gradle +spotless { + java { + googleJavaFormat() + typeAnnotations() + } +} +``` + + ## Groovy From 4ad48a95a02261c34a5aa74c225d95289a3ecd56 Mon Sep 17 00:00:00 2001 From: Michael Ernst Date: Thu, 25 Aug 2022 09:31:52 -0700 Subject: [PATCH 256/757] Fix indentation --- .../diffplug/spotless/java/TypeAnnotationsStep.java | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/lib/src/main/java/com/diffplug/spotless/java/TypeAnnotationsStep.java b/lib/src/main/java/com/diffplug/spotless/java/TypeAnnotationsStep.java index dd0b86eeb4..673807a08e 100644 --- a/lib/src/main/java/com/diffplug/spotless/java/TypeAnnotationsStep.java +++ b/lib/src/main/java/com/diffplug/spotless/java/TypeAnnotationsStep.java @@ -405,10 +405,10 @@ FormatterFunc toFormatter() { } /** - * Removes line break between type annotations and the following type. - * - * @param the text of a Java file - * @return corrected text of the Java file + * Removes line break between type annotations and the following type. + * + * @param the text of a Java file + * @return corrected text of the Java file */ String fixupTypeAnnotations(String unixStr) { // Each element of `lines` ends with a newline. @@ -428,7 +428,8 @@ String fixupTypeAnnotations(String unixStr) { } /** - * Returns true if the line ends with a type annotation. We need to fix such formatting. + * Returns true if the line ends with a type annotation. + * TypeAnnotationStep fixes such formatting. */ boolean endsWithTypeAnnotation(String unixLine) { // Remove trailing newline. From e886d24500cf32fff6a417f1dc08bf93b6e15c0b Mon Sep 17 00:00:00 2001 From: Michael Ernst Date: Thu, 25 Aug 2022 10:17:40 -0700 Subject: [PATCH 257/757] The Checker Framework supports most known type annotations. --- .../java/com/diffplug/spotless/java/TypeAnnotationsStep.java | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/lib/src/main/java/com/diffplug/spotless/java/TypeAnnotationsStep.java b/lib/src/main/java/com/diffplug/spotless/java/TypeAnnotationsStep.java index 673807a08e..2a46f0f40c 100644 --- a/lib/src/main/java/com/diffplug/spotless/java/TypeAnnotationsStep.java +++ b/lib/src/main/java/com/diffplug/spotless/java/TypeAnnotationsStep.java @@ -51,7 +51,9 @@ private static final class State implements Serializable { */ private static final Set typeAnnotations = new HashSet<>( Arrays.asList( - // Type annotations from the Checker Framework. + // Type annotations from the Checker Framework and all the tools it + // supports, including FindBugs, JetBrains (IntelliJ), Eclipse, NetBeans, + // Spring, JML, Android, etc. "A", "ACCBottom", "Acceleration", From 8666f98590976ccffb2e81fabbd3a348eed4066d Mon Sep 17 00:00:00 2001 From: Michael Ernst Date: Thu, 25 Aug 2022 11:23:38 -0700 Subject: [PATCH 258/757] Add line to table --- README.md | 2 ++ gradle/spotless.gradle | 1 + plugin-gradle/README.md | 2 +- 3 files changed, 4 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index f95ea7a7ca..7680062a6c 100644 --- a/README.md +++ b/README.md @@ -61,6 +61,7 @@ lib('java.ImportOrderStep') +'{{yes}} | {{yes}} lib('java.PalantirJavaFormatStep') +'{{yes}} | {{yes}} | {{no}} | {{no}} |', lib('java.RemoveUnusedImportsStep') +'{{yes}} | {{yes}} | {{yes}} | {{no}} |', extra('java.EclipseJdtFormatterStep') +'{{yes}} | {{yes}} | {{yes}} | {{no}} |', +lib('java.TypeAnnotationsStep') +'{{yes}} | {{no}} | {{no}} | {{no}} |', lib('json.gson.GsonStep') +'{{yes}} | {{no}} | {{no}} | {{no}} |', lib('json.JsonSimpleStep') +'{{yes}} | {{no}} | {{no}} | {{no}} |', lib('kotlin.KtLintStep') +'{{yes}} | {{yes}} | {{yes}} | {{no}} |', @@ -104,6 +105,7 @@ extra('wtp.EclipseWtpFormatterStep') +'{{yes}} | {{yes}} | [`java.PalantirJavaFormatStep`](lib/src/main/java/com/diffplug/spotless/java/PalantirJavaFormatStep.java) | :+1: | :+1: | :white_large_square: | :white_large_square: | | [`java.RemoveUnusedImportsStep`](lib/src/main/java/com/diffplug/spotless/java/RemoveUnusedImportsStep.java) | :+1: | :+1: | :+1: | :white_large_square: | | [`java.EclipseJdtFormatterStep`](lib-extra/src/main/java/com/diffplug/spotless/extra/java/EclipseJdtFormatterStep.java) | :+1: | :+1: | :+1: | :white_large_square: | +| [`java.TypeAnnotationsStep`](lib/src/main/java/com/diffplug/spotless/java/TypeAnnotationsStep.java) | :+1: | :+1: | :white_large_square: | :white_large_square: | | [`json.gson.GsonStep`](lib/src/main/java/com/diffplug/spotless/json/gson/GsonStep.java) | :+1: | :white_large_square: | :white_large_square: | :white_large_square: | | [`json.JsonSimpleStep`](lib/src/main/java/com/diffplug/spotless/json/JsonSimpleStep.java) | :+1: | :white_large_square: | :white_large_square: | :white_large_square: | | [`kotlin.KtLintStep`](lib/src/main/java/com/diffplug/spotless/kotlin/KtLintStep.java) | :+1: | :+1: | :+1: | :white_large_square: | diff --git a/gradle/spotless.gradle b/gradle/spotless.gradle index 96037b21a3..8ab9516bcc 100644 --- a/gradle/spotless.gradle +++ b/gradle/spotless.gradle @@ -22,6 +22,7 @@ spotless { eclipse().configFile rootProject.file('gradle/spotless.eclipseformat.xml') trimTrailingWhitespace() removeUnusedImports() + // TODO: typeAnnotations() custom 'noInternalDeps', noInternalDepsClosure } } diff --git a/plugin-gradle/README.md b/plugin-gradle/README.md index c96e8a1157..35133d4570 100644 --- a/plugin-gradle/README.md +++ b/plugin-gradle/README.md @@ -60,7 +60,7 @@ Spotless supports all of Gradle's built-in performance features (incremental bui - [**Quickstart**](#quickstart) - [Requirements](#requirements) - **Languages** - - [Java](#java) ([google-java-format](#google-java-format), [eclipse jdt](#eclipse-jdt), [clang-format](#clang-format), [prettier](#prettier), [palantir-java-format](#palantir-java-format), [type annotations](#Type annotations)) + - [Java](#java) ([google-java-format](#google-java-format), [eclipse jdt](#eclipse-jdt), [clang-format](#clang-format), [prettier](#prettier), [palantir-java-format](#palantir-java-format), [type annotations](#type-annotations)) - [Groovy](#groovy) ([eclipse groovy](#eclipse-groovy)) - [Kotlin](#kotlin) ([ktfmt](#ktfmt), [ktlint](#ktlint), [diktat](#diktat), [prettier](#prettier)) - [Scala](#scala) ([scalafmt](#scalafmt)) From 68e421770140f29b2c083ee478447bd1e7932358 Mon Sep 17 00:00:00 2001 From: Michael Ernst Date: Thu, 25 Aug 2022 11:44:54 -0700 Subject: [PATCH 259/757] Tweak comment --- plugin-gradle/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugin-gradle/README.md b/plugin-gradle/README.md index 35133d4570..894d8747bf 100644 --- a/plugin-gradle/README.md +++ b/plugin-gradle/README.md @@ -164,7 +164,7 @@ spotless { prettier() // has its own section below clangFormat() // has its own section below - typeAnnotations() // has its own section below + typeAnnotations() // fixes formatting of type annotations, see below licenseHeader '/* (C) $YEAR */' // or licenseHeaderFile } From e69ab4b0266c39f89f61d0c19dd2e5afe98835b3 Mon Sep 17 00:00:00 2001 From: Michael Ernst Date: Thu, 25 Aug 2022 11:52:07 -0700 Subject: [PATCH 260/757] Add Maven support --- README.md | 2 +- plugin-maven/CHANGES.md | 2 ++ plugin-maven/README.md | 33 +++++++++++++++++-- .../diffplug/spotless/maven/java/Java.java | 4 +++ .../spotless/maven/java/TypeAnnotations.java | 29 ++++++++++++++++ .../maven/java/TypeAnnotationsStepTest.java | 33 +++++++++++++++++++ 6 files changed, 100 insertions(+), 3 deletions(-) create mode 100644 plugin-maven/src/main/java/com/diffplug/spotless/maven/java/TypeAnnotations.java create mode 100644 plugin-maven/src/test/java/com/diffplug/spotless/maven/java/TypeAnnotationsStepTest.java diff --git a/README.md b/README.md index 7680062a6c..049e8728fa 100644 --- a/README.md +++ b/README.md @@ -61,7 +61,7 @@ lib('java.ImportOrderStep') +'{{yes}} | {{yes}} lib('java.PalantirJavaFormatStep') +'{{yes}} | {{yes}} | {{no}} | {{no}} |', lib('java.RemoveUnusedImportsStep') +'{{yes}} | {{yes}} | {{yes}} | {{no}} |', extra('java.EclipseJdtFormatterStep') +'{{yes}} | {{yes}} | {{yes}} | {{no}} |', -lib('java.TypeAnnotationsStep') +'{{yes}} | {{no}} | {{no}} | {{no}} |', +lib('java.TypeAnnotationsStep') +'{{yes}} | {{yes}} | {{no}} | {{no}} |', lib('json.gson.GsonStep') +'{{yes}} | {{no}} | {{no}} | {{no}} |', lib('json.JsonSimpleStep') +'{{yes}} | {{no}} | {{no}} | {{no}} |', lib('kotlin.KtLintStep') +'{{yes}} | {{yes}} | {{yes}} | {{no}} |', diff --git a/plugin-maven/CHANGES.md b/plugin-maven/CHANGES.md index 3b6986c5db..c5c322ff55 100644 --- a/plugin-maven/CHANGES.md +++ b/plugin-maven/CHANGES.md @@ -3,6 +3,8 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format (starting after version `1.27.0`). ## [Unreleased] +### Added +* `typeAnnotations` step to correct formatting of type annotations. It puts type annotations on the same line as the type that they qualify. Run it after a Java formattng step, such as `googleJavaFormat`. ([#1275](https://github.com/diffplug/spotless/pull/1275)) ## [2.25.0] - 2022-08-23 ### Added diff --git a/plugin-maven/README.md b/plugin-maven/README.md index f59d00d47a..eaee799db7 100644 --- a/plugin-maven/README.md +++ b/plugin-maven/README.md @@ -24,7 +24,7 @@ output = [ output = prefixDelimiterReplace(input, 'https://{{org}}.github.io/{{name}}/javadoc/spotless-plugin-maven/', '/', versionLast) --> -Spotless is a general-purpose formatting plugin. It is completely à la carte, but also includes powerful "batteries-included" if you opt-in. Plugin requires a version of Maven higher or equal to 3.1.0. +Spotless is a general-purpose formatting plugin used by [4,000 projects on GitHub (August 2020)](https://github.com/search?l=gradle&q=spotless&type=Code). It is completely à la carte, but also includes powerful "batteries-included" if you opt-in. Plugin requires a version of Maven higher or equal to 3.1.0. To people who use your build, it looks like this: @@ -47,7 +47,7 @@ user@machine repo % mvn spotless:check - [Requirements](#requirements) - [Binding to maven phase](#binding-to-maven-phase) - **Languages** - - [Java](#java) ([google-java-format](#google-java-format), [eclipse jdt](#eclipse-jdt), [prettier](#prettier), [palantir-java-format](#palantir-java-format)) + - [Java](#java) ([google-java-format](#google-java-format), [eclipse jdt](#eclipse-jdt), [prettier](#prettier), [palantir-java-format](#palantir-java-format), [type annotations](#type-annotations)) - [Groovy](#groovy) ([eclipse groovy](#eclipse-groovy)) - [Kotlin](#kotlin) ([ktfmt](#ktfmt), [ktlint](#ktlint), [diktat](#diktat), [prettier](#prettier)) - [Scala](#scala) ([scalafmt](#scalafmt)) @@ -191,6 +191,8 @@ any other maven phase (i.e. compile) then it can be configured as below; + + /* (C)$YEAR */ @@ -255,6 +257,33 @@ This is a workaround to a [pending issue](https://github.com/diffplug/spotless/i ``` +### Type annotations + +Type annotations should be on the same line as the type that they qualify. + +```java + @Override + @Deprecated + @Nullable @Interned String s; +``` + +However, some tools format them incorrectly, like this: + +```java + @Override + @Deprecated + @Nullable + @Interned + String s; +``` + +To fix the incorrect formatting, add the `typeAnnotations()` rule after a Java formatter. For example: + +```XML + + +``` + ## Groovy [code](https://github.com/diffplug/spotless/blob/main/plugin-maven/src/main/java/com/diffplug/spotless/maven/groovy/Groovy.java). [available steps](https://github.com/diffplug/spotless/tree/main/plugin-maven/src/main/java/com/diffplug/spotless/maven/groovy). diff --git a/plugin-maven/src/main/java/com/diffplug/spotless/maven/java/Java.java b/plugin-maven/src/main/java/com/diffplug/spotless/maven/java/Java.java index 819179ebba..66b6b8b1c7 100644 --- a/plugin-maven/src/main/java/com/diffplug/spotless/maven/java/Java.java +++ b/plugin-maven/src/main/java/com/diffplug/spotless/maven/java/Java.java @@ -61,4 +61,8 @@ public void addPalantirJavaFormat(PalantirJavaFormat palantirJavaFormat) { public void addRemoveUnusedImports(RemoveUnusedImports removeUnusedImports) { addStepFactory(removeUnusedImports); } + + public void addTypeAnnotations(TypeAnnotations typeAnnotations) { + addStepFactory(typeAnnotations); + } } diff --git a/plugin-maven/src/main/java/com/diffplug/spotless/maven/java/TypeAnnotations.java b/plugin-maven/src/main/java/com/diffplug/spotless/maven/java/TypeAnnotations.java new file mode 100644 index 0000000000..8a555c6c72 --- /dev/null +++ b/plugin-maven/src/main/java/com/diffplug/spotless/maven/java/TypeAnnotations.java @@ -0,0 +1,29 @@ +/* + * Copyright 2022 DiffPlug + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.diffplug.spotless.maven.java; + +import com.diffplug.spotless.FormatterStep; +import com.diffplug.spotless.java.TypeAnnotationsStep; +import com.diffplug.spotless.maven.FormatterStepConfig; +import com.diffplug.spotless.maven.FormatterStepFactory; + +public class TypeAnnotations implements FormatterStepFactory { + + @Override + public FormatterStep newFormatterStep(FormatterStepConfig config) { + return TypeAnnotationsStep.create(); + } +} diff --git a/plugin-maven/src/test/java/com/diffplug/spotless/maven/java/TypeAnnotationsStepTest.java b/plugin-maven/src/test/java/com/diffplug/spotless/maven/java/TypeAnnotationsStepTest.java new file mode 100644 index 0000000000..9ceebafb5e --- /dev/null +++ b/plugin-maven/src/test/java/com/diffplug/spotless/maven/java/TypeAnnotationsStepTest.java @@ -0,0 +1,33 @@ +/* + * Copyright 2022 DiffPlug + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.diffplug.spotless.maven.java; + +import org.junit.jupiter.api.Test; + +import com.diffplug.spotless.maven.MavenIntegrationHarness; + +class TypeAnnotationsStepTest extends MavenIntegrationHarness { + + @Test + void testRemoveUnusedInports() throws Exception { + writePomWithJavaSteps(""); + + String path = "src/main/java/test.java"; + setFile(path).toResource("java/typeannotations/TypeAnnotationsTestInput.test"); + mavenRunner().withArguments("spotless:apply").runNoError(); + assertFile(path).sameAsResource("java/typeannotations/TypeAnnotationsTestOutput.test"); + } +} From 61da1b2357656f31e23e04ccdf20803ff6ad649c Mon Sep 17 00:00:00 2001 From: Michael Ernst Date: Thu, 25 Aug 2022 12:02:38 -0700 Subject: [PATCH 261/757] Fix test name --- .../diffplug/spotless/maven/java/TypeAnnotationsStepTest.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugin-maven/src/test/java/com/diffplug/spotless/maven/java/TypeAnnotationsStepTest.java b/plugin-maven/src/test/java/com/diffplug/spotless/maven/java/TypeAnnotationsStepTest.java index 9ceebafb5e..c2281bf8fd 100644 --- a/plugin-maven/src/test/java/com/diffplug/spotless/maven/java/TypeAnnotationsStepTest.java +++ b/plugin-maven/src/test/java/com/diffplug/spotless/maven/java/TypeAnnotationsStepTest.java @@ -22,7 +22,7 @@ class TypeAnnotationsStepTest extends MavenIntegrationHarness { @Test - void testRemoveUnusedInports() throws Exception { + void testTypeAnnotations() throws Exception { writePomWithJavaSteps(""); String path = "src/main/java/test.java"; From 9553e60bc2ed8dc32a5e96a58fbf25ca6d07e69c Mon Sep 17 00:00:00 2001 From: Michael Ernst Date: Thu, 25 Aug 2022 12:02:47 -0700 Subject: [PATCH 262/757] Define "type annotation" --- .../java/com/diffplug/spotless/java/TypeAnnotationsStep.java | 4 ++++ plugin-gradle/README.md | 2 ++ plugin-maven/README.md | 2 ++ 3 files changed, 8 insertions(+) diff --git a/lib/src/main/java/com/diffplug/spotless/java/TypeAnnotationsStep.java b/lib/src/main/java/com/diffplug/spotless/java/TypeAnnotationsStep.java index 2a46f0f40c..36a988aa23 100644 --- a/lib/src/main/java/com/diffplug/spotless/java/TypeAnnotationsStep.java +++ b/lib/src/main/java/com/diffplug/spotless/java/TypeAnnotationsStep.java @@ -30,6 +30,9 @@ * -- even type annotations, which should be on the same line as the type they qualify. * This class corrects the formatting. * This is useful as a postprocessing step after a Java formatter that is not cognizant of type annotations. + + *

+ * Note: A type annotation is an annotation that is meta-annotated with {@code @Target({ElementType.TYPE_USE})}. */ public final class TypeAnnotationsStep { private TypeAnnotationsStep() {} @@ -54,6 +57,7 @@ private static final class State implements Serializable { // Type annotations from the Checker Framework and all the tools it // supports, including FindBugs, JetBrains (IntelliJ), Eclipse, NetBeans, // Spring, JML, Android, etc. + // A type annotation is an annotation that is meta-annotated with @Target({ElementType.TYPE_USE}). "A", "ACCBottom", "Acceleration", diff --git a/plugin-gradle/README.md b/plugin-gradle/README.md index 894d8747bf..71ccaf939c 100644 --- a/plugin-gradle/README.md +++ b/plugin-gradle/README.md @@ -262,6 +262,8 @@ Type annotations should be on the same line as the type that they qualify. @Nullable @Interned String s; ``` +(A type annotation is an annotation that is meta-annotated with `@Target({ElementType.TYPE_USE})`.) + However, some tools format them incorrectly, like this: ```java diff --git a/plugin-maven/README.md b/plugin-maven/README.md index eaee799db7..9968bc3217 100644 --- a/plugin-maven/README.md +++ b/plugin-maven/README.md @@ -267,6 +267,8 @@ Type annotations should be on the same line as the type that they qualify. @Nullable @Interned String s; ``` +(A type annotation is an annotation that is meta-annotated with `@Target({ElementType.TYPE_USE})`.) + However, some tools format them incorrectly, like this: ```java From d7cd9fdaebc278b7605a65b174d1cffd19b1df0c Mon Sep 17 00:00:00 2001 From: Michael Ernst Date: Thu, 25 Aug 2022 12:17:15 -0700 Subject: [PATCH 263/757] No reordering --- plugin-gradle/README.md | 2 ++ plugin-maven/README.md | 2 ++ 2 files changed, 4 insertions(+) diff --git a/plugin-gradle/README.md b/plugin-gradle/README.md index 71ccaf939c..3bb5ad4b9a 100644 --- a/plugin-gradle/README.md +++ b/plugin-gradle/README.md @@ -285,6 +285,8 @@ spotless { } ``` +This does not re-order annotations, it just removes incorrect newlines. + diff --git a/plugin-maven/README.md b/plugin-maven/README.md index 9968bc3217..449e6f617f 100644 --- a/plugin-maven/README.md +++ b/plugin-maven/README.md @@ -286,6 +286,8 @@ To fix the incorrect formatting, add the `typeAnnotations()` rule after a Java f ``` +This does not re-order annotations, it just removes incorrect newlines. + ## Groovy [code](https://github.com/diffplug/spotless/blob/main/plugin-maven/src/main/java/com/diffplug/spotless/maven/groovy/Groovy.java). [available steps](https://github.com/diffplug/spotless/tree/main/plugin-maven/src/main/java/com/diffplug/spotless/maven/groovy). From d8f047ee2d20fb6394aff5bb2847a3917f819147 Mon Sep 17 00:00:00 2001 From: Michael Ernst Date: Thu, 25 Aug 2022 12:17:37 -0700 Subject: [PATCH 264/757] Whitespace --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 049e8728fa..94e093ce4f 100644 --- a/README.md +++ b/README.md @@ -105,7 +105,7 @@ extra('wtp.EclipseWtpFormatterStep') +'{{yes}} | {{yes}} | [`java.PalantirJavaFormatStep`](lib/src/main/java/com/diffplug/spotless/java/PalantirJavaFormatStep.java) | :+1: | :+1: | :white_large_square: | :white_large_square: | | [`java.RemoveUnusedImportsStep`](lib/src/main/java/com/diffplug/spotless/java/RemoveUnusedImportsStep.java) | :+1: | :+1: | :+1: | :white_large_square: | | [`java.EclipseJdtFormatterStep`](lib-extra/src/main/java/com/diffplug/spotless/extra/java/EclipseJdtFormatterStep.java) | :+1: | :+1: | :+1: | :white_large_square: | -| [`java.TypeAnnotationsStep`](lib/src/main/java/com/diffplug/spotless/java/TypeAnnotationsStep.java) | :+1: | :+1: | :white_large_square: | :white_large_square: | +| [`java.TypeAnnotationsStep`](lib/src/main/java/com/diffplug/spotless/java/TypeAnnotationsStep.java) | :+1: | :+1: | :white_large_square: | :white_large_square: | | [`json.gson.GsonStep`](lib/src/main/java/com/diffplug/spotless/json/gson/GsonStep.java) | :+1: | :white_large_square: | :white_large_square: | :white_large_square: | | [`json.JsonSimpleStep`](lib/src/main/java/com/diffplug/spotless/json/JsonSimpleStep.java) | :+1: | :white_large_square: | :white_large_square: | :white_large_square: | | [`kotlin.KtLintStep`](lib/src/main/java/com/diffplug/spotless/kotlin/KtLintStep.java) | :+1: | :+1: | :+1: | :white_large_square: | From 437636b3c49430ad8cf692f029ca6e11197ffea2 Mon Sep 17 00:00:00 2001 From: Michael Ernst Date: Thu, 25 Aug 2022 14:10:36 -0700 Subject: [PATCH 265/757] List of type annotations is hard-coded --- CHANGES.md | 2 +- plugin-gradle/CHANGES.md | 2 +- plugin-gradle/README.md | 7 +++++-- plugin-maven/CHANGES.md | 2 +- plugin-maven/README.md | 8 ++++++-- 5 files changed, 14 insertions(+), 7 deletions(-) diff --git a/CHANGES.md b/CHANGES.md index cc2296c166..613df41623 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -11,7 +11,7 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format ( ## [Unreleased] ### Added -* `typeAnnotations()` step to correct formatting of type annotations. It puts type annotations on the same line as the type that they qualify. Run it after a Java formattng step, such as `googleJavaFormat()`. ([#1275](https://github.com/diffplug/spotless/pull/1275)) +* `typeAnnotations()` step to correct formatting of type annotations. It puts type annotations on the same line as the type that they qualify. Run it after a Java formatting step, such as `googleJavaFormat()`. ([#1275](https://github.com/diffplug/spotless/pull/1275)) ## [2.29.0] - 2022-08-23 ### Added diff --git a/plugin-gradle/CHANGES.md b/plugin-gradle/CHANGES.md index 2c3f483356..bd12048a49 100644 --- a/plugin-gradle/CHANGES.md +++ b/plugin-gradle/CHANGES.md @@ -4,7 +4,7 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format ( ## [Unreleased] ### Added -* `typeAnnotations()` step to correct formatting of type annotations. It puts type annotations on the same line as the type that they qualify. Run it after a Java formattng step, such as `googleJavaFormat()`. ([#1275](https://github.com/diffplug/spotless/pull/1275)) +* `typeAnnotations()` step to correct formatting of type annotations. It puts type annotations on the same line as the type that they qualify. Run it after a Java formatting step, such as `googleJavaFormat()`. ([#1275](https://github.com/diffplug/spotless/pull/1275)) ## [6.10.0] - 2022-08-23 ### Added diff --git a/plugin-gradle/README.md b/plugin-gradle/README.md index 3bb5ad4b9a..121917b7c9 100644 --- a/plugin-gradle/README.md +++ b/plugin-gradle/README.md @@ -262,8 +262,6 @@ Type annotations should be on the same line as the type that they qualify. @Nullable @Interned String s; ``` -(A type annotation is an annotation that is meta-annotated with `@Target({ElementType.TYPE_USE})`.) - However, some tools format them incorrectly, like this: ```java @@ -287,6 +285,11 @@ spotless { This does not re-order annotations, it just removes incorrect newlines. +A type annotation is an annotation that is meta-annotated with `@Target({ElementType.TYPE_USE})`. +Because Spotless cannot necessarily examine the annotation definition, it uses a hard-coded +list of well-known type annotations. You can make a pull request to add new ones. +In the future there will be mechanisms to add/remove annotations from the list. + diff --git a/plugin-maven/CHANGES.md b/plugin-maven/CHANGES.md index c5c322ff55..33e3bc7774 100644 --- a/plugin-maven/CHANGES.md +++ b/plugin-maven/CHANGES.md @@ -4,7 +4,7 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format ( ## [Unreleased] ### Added -* `typeAnnotations` step to correct formatting of type annotations. It puts type annotations on the same line as the type that they qualify. Run it after a Java formattng step, such as `googleJavaFormat`. ([#1275](https://github.com/diffplug/spotless/pull/1275)) +* `typeAnnotations` step to correct formatting of type annotations. It puts type annotations on the same line as the type that they qualify. Run it after a Java formatting step, such as `googleJavaFormat`. ([#1275](https://github.com/diffplug/spotless/pull/1275)) ## [2.25.0] - 2022-08-23 ### Added diff --git a/plugin-maven/README.md b/plugin-maven/README.md index 449e6f617f..42372387be 100644 --- a/plugin-maven/README.md +++ b/plugin-maven/README.md @@ -267,8 +267,6 @@ Type annotations should be on the same line as the type that they qualify. @Nullable @Interned String s; ``` -(A type annotation is an annotation that is meta-annotated with `@Target({ElementType.TYPE_USE})`.) - However, some tools format them incorrectly, like this: ```java @@ -288,6 +286,12 @@ To fix the incorrect formatting, add the `typeAnnotations()` rule after a Java f This does not re-order annotations, it just removes incorrect newlines. +A type annotation is an annotation that is meta-annotated with `@Target({ElementType.TYPE_USE})`. +Because Spotless cannot necessarily examine the annotation definition, it uses a hard-coded +list of well-known type annotations. You can make a pull request to add new ones. +In the future there will be mechanisms to add/remove annotations from the list. + + ## Groovy [code](https://github.com/diffplug/spotless/blob/main/plugin-maven/src/main/java/com/diffplug/spotless/maven/groovy/Groovy.java). [available steps](https://github.com/diffplug/spotless/tree/main/plugin-maven/src/main/java/com/diffplug/spotless/maven/groovy). From 2e8991134e8327a6c1fa519e75601418ab9adbda Mon Sep 17 00:00:00 2001 From: "renovate[bot]" <29139614+renovate[bot]@users.noreply.github.com> Date: Thu, 25 Aug 2022 22:29:59 +0000 Subject: [PATCH 266/757] Add renovate.json --- renovate.json | 6 ++++++ 1 file changed, 6 insertions(+) create mode 100644 renovate.json diff --git a/renovate.json b/renovate.json new file mode 100644 index 0000000000..7bd954555f --- /dev/null +++ b/renovate.json @@ -0,0 +1,6 @@ +{ + "$schema": "https://docs.renovatebot.com/renovate-schema.json", + "extends": [ + "config:base" + ] +} From 08aeffd9905c3fa4d095a366d834d009158fb999 Mon Sep 17 00:00:00 2001 From: Ned Twigg Date: Thu, 25 Aug 2022 15:36:02 -0700 Subject: [PATCH 267/757] Remove dependabot, as per #1288 --- .github/dependabot.yml | 10 ---------- 1 file changed, 10 deletions(-) delete mode 100644 .github/dependabot.yml diff --git a/.github/dependabot.yml b/.github/dependabot.yml deleted file mode 100644 index 10ef831183..0000000000 --- a/.github/dependabot.yml +++ /dev/null @@ -1,10 +0,0 @@ -version: 2 -updates: - - package-ecosystem: "gradle" - directory: "/" - schedule: - interval: "weekly" - - package-ecosystem: "github-actions" - directory: "/" - schedule: - interval: "weekly" From 6f2c4f6f0d12e1e9b6722b881b3365afc3ad0aca Mon Sep 17 00:00:00 2001 From: "renovate[bot]" <29139614+renovate[bot]@users.noreply.github.com> Date: Thu, 25 Aug 2022 22:37:50 +0000 Subject: [PATCH 268/757] Update dependency com.github.spullara.mustache.java:compiler to v0.9.10 --- gradle.properties | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gradle.properties b/gradle.properties index 032beae95c..918ff28ab3 100644 --- a/gradle.properties +++ b/gradle.properties @@ -33,5 +33,5 @@ VER_MOCKITO=3.3.3 # Used for Maven Plugin VER_MAVEN_API=3.0 VER_ECLIPSE_AETHER=0.9.0.M2 -VER_MUSTACHE=0.9.6 +VER_MUSTACHE=0.9.10 VER_PLEXUS_RESOURCES=1.2.0 From 8b1ea2d313608b219ff1f39af63f9002a4325778 Mon Sep 17 00:00:00 2001 From: Michael Ernst Date: Thu, 25 Aug 2022 17:19:03 -0700 Subject: [PATCH 269/757] Fix typos --- CONTRIBUTING.md | 2 +- .../spotless/extra/eclipse/base/SpotlessEclipseFramework.java | 2 +- .../spotless/extra/eclipse/base/osgi/BundleController.java | 2 +- _ext/eclipse-groovy/README.md | 2 +- _ext/eclipse-jdt/README.md | 2 +- _ext/eclipse-wtp/README.md | 2 +- .../spotless/extra/eclipse/wtp/sse/PluginPreferences.java | 2 +- gradle/spotless-freshmark.gradle | 2 +- lib/src/main/java/com/diffplug/spotless/FeatureClassLoader.java | 2 +- lib/src/main/java/com/diffplug/spotless/PaddedCell.java | 2 +- plugin-gradle/CHANGES.md | 2 +- 11 files changed, 11 insertions(+), 11 deletions(-) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index c1ce74bd8f..bf1996778d 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -129,7 +129,7 @@ The `_ext` projects are disabled per default, since: The `_ext` can be activated via the root project property `com.diffplug.spotless.include.ext`. -Activate the the property via command line, like for example: +Activate the property via command line, like for example: ``` gradlew -Pcom.diffplug.spotless.include.ext=true build diff --git a/_ext/eclipse-base/src/main/java/com/diffplug/spotless/extra/eclipse/base/SpotlessEclipseFramework.java b/_ext/eclipse-base/src/main/java/com/diffplug/spotless/extra/eclipse/base/SpotlessEclipseFramework.java index 44be5f6805..2eaf9e568e 100644 --- a/_ext/eclipse-base/src/main/java/com/diffplug/spotless/extra/eclipse/base/SpotlessEclipseFramework.java +++ b/_ext/eclipse-base/src/main/java/com/diffplug/spotless/extra/eclipse/base/SpotlessEclipseFramework.java @@ -61,7 +61,7 @@ public enum DefaultBundles { REGISTRY(org.eclipse.core.internal.registry.osgi.Activator.class), /** Eclipse preferences always check whether this bundle has been activated before preference are set.*/ PREFERENCES(org.eclipse.core.internal.preferences.Activator.class), - /** The common runtime provides provides common services, like log and service adapters registry. */ + /** The common runtime provides common services, like log and service adapters registry. */ COMMON(org.eclipse.core.internal.runtime.Activator.class); private final Class activatorClass; diff --git a/_ext/eclipse-base/src/main/java/com/diffplug/spotless/extra/eclipse/base/osgi/BundleController.java b/_ext/eclipse-base/src/main/java/com/diffplug/spotless/extra/eclipse/base/osgi/BundleController.java index 7c5311126e..3589bd7082 100644 --- a/_ext/eclipse-base/src/main/java/com/diffplug/spotless/extra/eclipse/base/osgi/BundleController.java +++ b/_ext/eclipse-base/src/main/java/com/diffplug/spotless/extra/eclipse/base/osgi/BundleController.java @@ -76,7 +76,7 @@ public BundleController() throws BundleException { services.add(org.osgi.service.packageadmin.PackageAdmin.class, bundleLookup); services.add(FrameworkWiring.class, bundleLookup); - //Redirect framework activator requests to the the org.eclipse.osgi bundle to this instance. + //Redirect framework activator requests to the org.eclipse.osgi bundle to this instance. bundles.add(new SimpleBundle(systemBundle, ECLIPSE_LAUNCHER_SYMBOLIC_NAME, Bundle.ACTIVE)); FrameworkBundleRegistry.initialize(this); } diff --git a/_ext/eclipse-groovy/README.md b/_ext/eclipse-groovy/README.md index c565d04cf2..687ed7a132 100644 --- a/_ext/eclipse-groovy/README.md +++ b/_ext/eclipse-groovy/README.md @@ -5,7 +5,7 @@ To fix this, we publish Groovy-Eclipse's formatter and all its dependencies, alo ## Build -To publish a new version, update the `_ext/eclipse-groovy/gradle.properties` appropriately and and see [CONTRIBUTING.md](../../CONTRIBUTING.md) how to enable +To publish a new version, update the `_ext/eclipse-groovy/gradle.properties` appropriately and see [CONTRIBUTING.md](../../CONTRIBUTING.md) how to enable `_ext` projects. ## License diff --git a/_ext/eclipse-jdt/README.md b/_ext/eclipse-jdt/README.md index 014b58e732..624e577e0d 100644 --- a/_ext/eclipse-jdt/README.md +++ b/_ext/eclipse-jdt/README.md @@ -4,7 +4,7 @@ Eclipse JDT and its dependencies require a large amount of byte code. Hence they should not be directly be required by the Spotless, but only be requested in case they are configured by the Spotless configuration. Hence we publish Eclipse's formatter and all its dependencies, along with a small amount of glue code, into the `com.diffplug.gradle.spotless:spotless-eclipse-jdt` artifact. -To publish a new version, update the `_ext/eclipse-jdt/gradle.properties` appropriately and and see [CONTRIBUTING.md](../../CONTRIBUTING.md) how to enable +To publish a new version, update the `_ext/eclipse-jdt/gradle.properties` appropriately and see [CONTRIBUTING.md](../../CONTRIBUTING.md) how to enable `_ext` projects. ## License diff --git a/_ext/eclipse-wtp/README.md b/_ext/eclipse-wtp/README.md index 879f299377..41dd58ff9b 100644 --- a/_ext/eclipse-wtp/README.md +++ b/_ext/eclipse-wtp/README.md @@ -2,7 +2,7 @@ Eclipse WTP is not available in a form which can be easily consumed by maven or gradle. To fix this, we publish Eclipse's WTP formatters, along with a small amount of glue code, into the `com.diffplug.spotless.extra:spotless-eclipse-wtp` artifact. -To publish a new version, update the `_ext/eclipse-wtp/gradle.properties` appropriately and and see [CONTRIBUTING.md](../../CONTRIBUTING.md) how to enable +To publish a new version, update the `_ext/eclipse-wtp/gradle.properties` appropriately and see [CONTRIBUTING.md](../../CONTRIBUTING.md) how to enable `_ext` projects. ## License diff --git a/_ext/eclipse-wtp/src/main/java/com/diffplug/spotless/extra/eclipse/wtp/sse/PluginPreferences.java b/_ext/eclipse-wtp/src/main/java/com/diffplug/spotless/extra/eclipse/wtp/sse/PluginPreferences.java index 8e101ec87c..81aa772617 100644 --- a/_ext/eclipse-wtp/src/main/java/com/diffplug/spotless/extra/eclipse/wtp/sse/PluginPreferences.java +++ b/_ext/eclipse-wtp/src/main/java/com/diffplug/spotless/extra/eclipse/wtp/sse/PluginPreferences.java @@ -33,7 +33,7 @@ import org.eclipse.wst.xml.core.internal.catalog.provisional.ICatalog; /** - * The plugin preference configuration of most WTP formatters is accomplished via the the + * The plugin preference configuration of most WTP formatters is accomplished via the * globabl Eclipse preference lookup. * Spotless allows different formatter configurations per sub-projects. * Fortunately most formatters only perform a lookup on instantiation and not afterwards. diff --git a/gradle/spotless-freshmark.gradle b/gradle/spotless-freshmark.gradle index 6df47581d4..30c5ab6306 100644 --- a/gradle/spotless-freshmark.gradle +++ b/gradle/spotless-freshmark.gradle @@ -75,7 +75,7 @@ if (tasks.names.contains('changelogCheck')) { changelogBumpFreshmark.dependsOn tasks.named('changelogBump') def changelogBumpFreshmarkGitAdd = tasks.register('changelogBumpFreshmarkGitAdd') { - // this git add add should run after the freshmark + // this git add should run after the freshmark dependsOn(changelogBumpFreshmark) // do the git add doLast { diff --git a/lib/src/main/java/com/diffplug/spotless/FeatureClassLoader.java b/lib/src/main/java/com/diffplug/spotless/FeatureClassLoader.java index 506e29f49c..2672fa9475 100644 --- a/lib/src/main/java/com/diffplug/spotless/FeatureClassLoader.java +++ b/lib/src/main/java/com/diffplug/spotless/FeatureClassLoader.java @@ -30,7 +30,7 @@ * This class loader is used to load classes of Spotless features from a search * path of URLs.
* Features shall be independent from build tools. Hence the class loader of the - * underlying build tool is e.g. skipped during the the search for classes.
+ * underlying build tool is e.g. skipped during the search for classes.
* * For `com.diffplug.spotless.glue.`, classes are redefined from within the lib jar * but linked against the `Url[]`. This allows us to ship classfiles which function as glue diff --git a/lib/src/main/java/com/diffplug/spotless/PaddedCell.java b/lib/src/main/java/com/diffplug/spotless/PaddedCell.java index 59ef242f6c..ebc9538860 100644 --- a/lib/src/main/java/com/diffplug/spotless/PaddedCell.java +++ b/lib/src/main/java/com/diffplug/spotless/PaddedCell.java @@ -236,7 +236,7 @@ public static DirtyState calculateDirtyState(Formatter formatter, File file, byt /** * The clean/dirty state of a single file. Intended use: - * - {@link #isClean()} means that the file is is clean, and there's nothing else to say + * - {@link #isClean()} means that the file is clean, and there's nothing else to say * - {@link #didNotConverge()} means that we were unable to determine a clean state * - once you've tested the above conditions and you know that it's a dirty file with a converged state, * then you can call {@link #writeCanonicalTo(OutputStream)} to get the canonical form of the given file. diff --git a/plugin-gradle/CHANGES.md b/plugin-gradle/CHANGES.md index 3cf249b893..9f7ba3d0a6 100644 --- a/plugin-gradle/CHANGES.md +++ b/plugin-gradle/CHANGES.md @@ -786,7 +786,7 @@ spotless { ## [3.4.0] - 2017-05-21 * `ImportOrderStep` can now handle multi-line comments and misplaced imports. * Groovy extension now checks for the `groovy` plugin to be applied. -* Deprecated the old syntax for the the eclipse formatter: +* Deprecated the old syntax for the eclipse formatter: + New syntax better separates the version from the other configuration options, and is more consistent with the other + `eclipseFormatFile('format.xml')` -> `eclipse().configFile('format.xml')` + `eclipseFormatFile('4.4.0', 'format.xml')` -> `eclipse('4.4.0').configFile('format.xml')` From 01ce6c8ec8112b7ac24f9332701dc60741b55dd4 Mon Sep 17 00:00:00 2001 From: Michael Ernst Date: Thu, 25 Aug 2022 17:50:26 -0700 Subject: [PATCH 270/757] Update copyright dates --- lib/src/main/java/com/diffplug/spotless/FeatureClassLoader.java | 2 +- lib/src/main/java/com/diffplug/spotless/PaddedCell.java | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/src/main/java/com/diffplug/spotless/FeatureClassLoader.java b/lib/src/main/java/com/diffplug/spotless/FeatureClassLoader.java index 2672fa9475..b4a69bef11 100644 --- a/lib/src/main/java/com/diffplug/spotless/FeatureClassLoader.java +++ b/lib/src/main/java/com/diffplug/spotless/FeatureClassLoader.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. diff --git a/lib/src/main/java/com/diffplug/spotless/PaddedCell.java b/lib/src/main/java/com/diffplug/spotless/PaddedCell.java index ebc9538860..91914b7908 100644 --- a/lib/src/main/java/com/diffplug/spotless/PaddedCell.java +++ b/lib/src/main/java/com/diffplug/spotless/PaddedCell.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. From 03c37feb05d1ecc3c6a3fe0ee32440e412fb4c1e Mon Sep 17 00:00:00 2001 From: "renovate[bot]" <29139614+renovate[bot]@users.noreply.github.com> Date: Fri, 26 Aug 2022 03:34:13 +0000 Subject: [PATCH 271/757] Update dependency org.eclipse.jgit:org.eclipse.jgit to v5.13.1.202206130422-r --- gradle.properties | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gradle.properties b/gradle.properties index 918ff28ab3..e0d2bd2911 100644 --- a/gradle.properties +++ b/gradle.properties @@ -25,7 +25,7 @@ VER_SLF4J=[1.6,2.0[ # Used in multiple places VER_DURIAN=1.2.0 -VER_JGIT=5.13.0.202109080827-r +VER_JGIT=5.13.1.202206130422-r VER_JUNIT=5.8.0 VER_ASSERTJ=3.15.0 VER_MOCKITO=3.3.3 From 71b141311b2be41930bf1572e3a51494288c8e6b Mon Sep 17 00:00:00 2001 From: "renovate[bot]" <29139614+renovate[bot]@users.noreply.github.com> Date: Fri, 26 Aug 2022 03:34:18 +0000 Subject: [PATCH 272/757] Update win orb to v2.4.1 --- .circleci/config.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index 8afdc61345..a5ca735442 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -1,6 +1,6 @@ version: 2.1 orbs: - win: circleci/windows@2.4.0 + win: circleci/windows@2.4.1 anchors: env_gradle: &env_gradle From e0b6134a4edcf7bfbf9c27a90514b4dc8803018a Mon Sep 17 00:00:00 2001 From: Michael Ernst Date: Sun, 28 Aug 2022 10:02:28 -0700 Subject: [PATCH 273/757] Fix another typo --- .../main/java/com/diffplug/gradle/spotless/JavaExtension.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/JavaExtension.java b/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/JavaExtension.java index 479d2ffd12..ee7590da88 100644 --- a/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/JavaExtension.java +++ b/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/JavaExtension.java @@ -120,7 +120,7 @@ public GoogleJavaFormatConfig googleJavaFormat() { * Uses the given version of google-java-format to format source code. * * Limited to published versions. See issue #33 - * for an workaround for using snapshot versions. + * for a workaround for using snapshot versions. */ public GoogleJavaFormatConfig googleJavaFormat(String version) { Objects.requireNonNull(version); @@ -185,7 +185,7 @@ public PalantirJavaFormatConfig palantirJavaFormat() { * Uses the given version of palantir-java-format to format source code. * * Limited to published versions. See issue #33 - * for an workaround for using snapshot versions. + * for a workaround for using snapshot versions. */ public PalantirJavaFormatConfig palantirJavaFormat(String version) { Objects.requireNonNull(version); From d8b8a863872b7132dbae03b7d18a0cffcfbc5946 Mon Sep 17 00:00:00 2001 From: Michael Ernst Date: Sun, 28 Aug 2022 11:09:25 -1000 Subject: [PATCH 274/757] Support `addTypeAnnotation()` and `removeTypeAnnotation()` --- .github/dependabot.yml | 10 - CHANGES.md | 2 +- README.md | 4 +- gradle.properties | 2 +- gradle/spotless.gradle | 2 +- .../spotless/java/FormatAnnotationsStep.java | 471 ++++++++++++++++++ .../spotless/java/TypeAnnotationsStep.java | 457 ----------------- plugin-gradle/CHANGES.md | 2 +- plugin-gradle/README.md | 32 +- .../gradle/spotless/FormatExtension.java | 1 + .../gradle/spotless/JavaExtension.java | 37 +- plugin-maven/CHANGES.md | 2 +- plugin-maven/README.md | 6 +- ...nnotations.java => FormatAnnotations.java} | 9 +- .../diffplug/spotless/maven/java/Java.java | 4 +- ...st.java => FormatAnnotationsStepTest.java} | 10 +- renovate.json | 6 + .../FormatAnnotationsAddRemoveInput.test | 11 + .../FormatAnnotationsAddRemoveOutput.test | 9 + .../FormatAnnotationsInCommentsInput.test} | 2 +- .../FormatAnnotationsInCommentsOutput.test} | 2 +- .../FormatAnnotationsTestInput.test} | 11 +- .../FormatAnnotationsTestOutput.test} | 10 +- ...st.java => FormatAnnotationsStepTest.java} | 28 +- 24 files changed, 613 insertions(+), 517 deletions(-) delete mode 100644 .github/dependabot.yml create mode 100644 lib/src/main/java/com/diffplug/spotless/java/FormatAnnotationsStep.java delete mode 100644 lib/src/main/java/com/diffplug/spotless/java/TypeAnnotationsStep.java rename plugin-maven/src/main/java/com/diffplug/spotless/maven/java/{TypeAnnotations.java => FormatAnnotations.java} (75%) rename plugin-maven/src/test/java/com/diffplug/spotless/maven/java/{TypeAnnotationsStepTest.java => FormatAnnotationsStepTest.java} (71%) create mode 100644 renovate.json create mode 100644 testlib/src/main/resources/java/formatannotations/FormatAnnotationsAddRemoveInput.test create mode 100644 testlib/src/main/resources/java/formatannotations/FormatAnnotationsAddRemoveOutput.test rename testlib/src/main/resources/java/{typeannotations/TypeAnnotationsInCommentsInput.test => formatannotations/FormatAnnotationsInCommentsInput.test} (94%) rename testlib/src/main/resources/java/{typeannotations/TypeAnnotationsInCommentsOutput.test => formatannotations/FormatAnnotationsInCommentsOutput.test} (93%) rename testlib/src/main/resources/java/{typeannotations/TypeAnnotationsTestInput.test => formatannotations/FormatAnnotationsTestInput.test} (87%) rename testlib/src/main/resources/java/{typeannotations/TypeAnnotationsTestOutput.test => formatannotations/FormatAnnotationsTestOutput.test} (87%) rename testlib/src/test/java/com/diffplug/spotless/java/{TypeAnnotationsStepTest.java => FormatAnnotationsStepTest.java} (50%) diff --git a/.github/dependabot.yml b/.github/dependabot.yml deleted file mode 100644 index 10ef831183..0000000000 --- a/.github/dependabot.yml +++ /dev/null @@ -1,10 +0,0 @@ -version: 2 -updates: - - package-ecosystem: "gradle" - directory: "/" - schedule: - interval: "weekly" - - package-ecosystem: "github-actions" - directory: "/" - schedule: - interval: "weekly" diff --git a/CHANGES.md b/CHANGES.md index 613df41623..cec949f59d 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -11,7 +11,7 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format ( ## [Unreleased] ### Added -* `typeAnnotations()` step to correct formatting of type annotations. It puts type annotations on the same line as the type that they qualify. Run it after a Java formatting step, such as `googleJavaFormat()`. ([#1275](https://github.com/diffplug/spotless/pull/1275)) +* `formatAnnotations()` step to correct formatting of type annotations. It puts type annotations on the same line as the type that they qualify. Run it after a Java formatting step, such as `googleJavaFormat()`. ([#1275](https://github.com/diffplug/spotless/pull/1275)) ## [2.29.0] - 2022-08-23 ### Added diff --git a/README.md b/README.md index 94e093ce4f..fb1a3670e6 100644 --- a/README.md +++ b/README.md @@ -61,7 +61,7 @@ lib('java.ImportOrderStep') +'{{yes}} | {{yes}} lib('java.PalantirJavaFormatStep') +'{{yes}} | {{yes}} | {{no}} | {{no}} |', lib('java.RemoveUnusedImportsStep') +'{{yes}} | {{yes}} | {{yes}} | {{no}} |', extra('java.EclipseJdtFormatterStep') +'{{yes}} | {{yes}} | {{yes}} | {{no}} |', -lib('java.TypeAnnotationsStep') +'{{yes}} | {{yes}} | {{no}} | {{no}} |', +lib('java.FormatAnnotationsStep') +'{{yes}} | {{yes}} | {{no}} | {{no}} |', lib('json.gson.GsonStep') +'{{yes}} | {{no}} | {{no}} | {{no}} |', lib('json.JsonSimpleStep') +'{{yes}} | {{no}} | {{no}} | {{no}} |', lib('kotlin.KtLintStep') +'{{yes}} | {{yes}} | {{yes}} | {{no}} |', @@ -105,7 +105,7 @@ extra('wtp.EclipseWtpFormatterStep') +'{{yes}} | {{yes}} | [`java.PalantirJavaFormatStep`](lib/src/main/java/com/diffplug/spotless/java/PalantirJavaFormatStep.java) | :+1: | :+1: | :white_large_square: | :white_large_square: | | [`java.RemoveUnusedImportsStep`](lib/src/main/java/com/diffplug/spotless/java/RemoveUnusedImportsStep.java) | :+1: | :+1: | :+1: | :white_large_square: | | [`java.EclipseJdtFormatterStep`](lib-extra/src/main/java/com/diffplug/spotless/extra/java/EclipseJdtFormatterStep.java) | :+1: | :+1: | :+1: | :white_large_square: | -| [`java.TypeAnnotationsStep`](lib/src/main/java/com/diffplug/spotless/java/TypeAnnotationsStep.java) | :+1: | :+1: | :white_large_square: | :white_large_square: | +| [`java.FormatAnnotationsStep`](lib/src/main/java/com/diffplug/spotless/java/FormatAnnotationsStep.java) | :+1: | :+1: | :white_large_square: | :white_large_square: | | [`json.gson.GsonStep`](lib/src/main/java/com/diffplug/spotless/json/gson/GsonStep.java) | :+1: | :white_large_square: | :white_large_square: | :white_large_square: | | [`json.JsonSimpleStep`](lib/src/main/java/com/diffplug/spotless/json/JsonSimpleStep.java) | :+1: | :white_large_square: | :white_large_square: | :white_large_square: | | [`kotlin.KtLintStep`](lib/src/main/java/com/diffplug/spotless/kotlin/KtLintStep.java) | :+1: | :+1: | :+1: | :white_large_square: | diff --git a/gradle.properties b/gradle.properties index 032beae95c..918ff28ab3 100644 --- a/gradle.properties +++ b/gradle.properties @@ -33,5 +33,5 @@ VER_MOCKITO=3.3.3 # Used for Maven Plugin VER_MAVEN_API=3.0 VER_ECLIPSE_AETHER=0.9.0.M2 -VER_MUSTACHE=0.9.6 +VER_MUSTACHE=0.9.10 VER_PLEXUS_RESOURCES=1.2.0 diff --git a/gradle/spotless.gradle b/gradle/spotless.gradle index 8ab9516bcc..677630ac69 100644 --- a/gradle/spotless.gradle +++ b/gradle/spotless.gradle @@ -22,7 +22,7 @@ spotless { eclipse().configFile rootProject.file('gradle/spotless.eclipseformat.xml') trimTrailingWhitespace() removeUnusedImports() - // TODO: typeAnnotations() + // TODO: formatAnnotations() custom 'noInternalDeps', noInternalDepsClosure } } diff --git a/lib/src/main/java/com/diffplug/spotless/java/FormatAnnotationsStep.java b/lib/src/main/java/com/diffplug/spotless/java/FormatAnnotationsStep.java new file mode 100644 index 0000000000..28691ccf91 --- /dev/null +++ b/lib/src/main/java/com/diffplug/spotless/java/FormatAnnotationsStep.java @@ -0,0 +1,471 @@ +/* + * Copyright 2022 DiffPlug + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.diffplug.spotless.java; + +import java.io.Serializable; +import java.util.Arrays; +import java.util.Collections; +import java.util.HashSet; +import java.util.List; +import java.util.Set; +import java.util.regex.Matcher; +import java.util.regex.Pattern; + +import com.diffplug.spotless.FormatterFunc; +import com.diffplug.spotless.FormatterStep; + +/** + * Some formatters put every annotation on its own line + * -- even type annotations, which should be on the same line as the type they qualify. + * This class corrects the formatting. + * This is useful as a postprocessing step after a Java formatter that is not cognizant of type annotations. + + *

+ * Note: A type annotation is an annotation that is meta-annotated with {@code @Target({ElementType.TYPE_USE})}. + */ +public final class FormatAnnotationsStep { + + /** + * Simple names of type annotations. + * A type annotation is an annotation that is meta-annotated with @Target({ElementType.TYPE_USE}). + * A type annotation should be formatted on the same line as the type it qualifies. + */ + private static final List defaultTypeAnnotations = + // Use simple names because Spotless has no access to the + // fully-qualified names or the definitions of the type qualifiers. + Arrays.asList( + // Type annotations from the Checker Framework and all + // the tools it supports: FindBugs, JetBrains (IntelliJ), + // Eclipse, NetBeans, Spring, JML, Android, etc. + "A", + "ACCBottom", + "Acceleration", + "ACCTop", + "AinferBottom", + "AlwaysSafe", + "Angle", + "AnnoWithStringArg", + "Area", + "ArrayLen", + "ArrayLenRange", + "ArrayWithoutPackage", + "AwtAlphaCompositingRule", + "AwtColorSpace", + "AwtCursorType", + "AwtFlowLayout", + "B", + "BinaryName", + "BinaryNameInUnnamedPackage", + "BinaryNameOrPrimitiveType", + "BinaryNameWithoutPackage", + "BoolVal", + "Bottom", + "BottomQualifier", + "BottomThis", + "BottomVal", + "C", + "CalledMethods", + "CalledMethodsBottom", + "CalledMethodsPredicate", + "CalledMethodsTop", + "CanonicalName", + "CanonicalNameAndBinaryName", + "CanonicalNameOrEmpty", + "CanonicalNameOrPrimitiveType", + "CCBottom", + "CCTop", + "cd", + "ClassBound", + "ClassGetName", + "ClassGetSimpleName", + "ClassVal", + "ClassValBottom", + "CompilerMessageKey", + "CompilerMessageKeyBottom", + "Constant", + "Critical", + "Current", + "D", + "DefaultType", + "degrees", + "Det", + "DotSeparatedIdentifiers", + "DotSeparatedIdentifiersOrPrimitiveType", + "DoubleVal", + "E", + "Encrypted", + "EnhancedRegex", + "EnumVal", + "Even", + "F", + "FBCBottom", + "FEBottom", + "FEBot", + "Fenum", + "FenumBottom", + "FenumTop", + "FETop", + "FieldDescriptor", + "FieldDescriptorForPrimitive", + "FieldDescriptorForPrimitiveOrArrayInUnnamedPackage", + "FieldDescriptorWithoutPackage", + "FlowExp", + "Force", + "Format", + "FormatBottom", + "FqBinaryName", + "Frequency", + "FullyQualifiedName", + "g", + "GTENegativeOne", + "GuardedBy", + "GuardedByBottom", + "GuardedByUnknown", + "GuardSatisfied", + "h", + "H1Bot", + "H1Invalid", + "H1Poly", + "H1S1", + "H1S2", + "H1Top", + "H2Bot", + "H2Poly", + "H2S1", + "H2S2", + "H2Top", + "Hz", + "I18nFormat", + "I18nFormatBottom", + "I18nFormatFor", + "I18nInvalidFormat", + "I18nUnknownFormat", + "Identifier", + "IdentifierOrArray", + "IdentifierOrPrimitiveType", + "ImplicitAnno", + "IndexFor", + "IndexOrHigh", + "IndexOrLow", + "Initialized", + "InitializedFields", + "InitializedFieldsBottom", + "InitializedFieldsPredicate", + "InternalForm", + "Interned", + "InternedDistinct", + "IntRange", + "IntVal", + "InvalidFormat", + "K", + "KeyFor", + "KeyForBottom", + "KeyForType", + "kg", + "kHz", + "km", + "km2", + "km3", + "kmPERh", + "kN", + "LbTop", + "LB_TOP", + "LeakedToResult", + "Length", + "LengthOf", + "LessThan", + "LessThanBottom", + "LessThanUnknown", + "LocalizableKey", + "LocalizableKeyBottom", + "Localized", + "LowerBoundBottom", + "LowerBoundUnknown", + "LTEqLengthOf", + "LTLengthOf", + "LTOMLengthOf", + "Luminance", + "m", + "m2", + "m3", + "Mass", + "MatchesRegex", + "MaybeAliased", + "MaybeDerivedFromConstant", + "MaybePresent", + "MaybeThis", + "MethodDescriptor", + "MethodVal", + "MethodValBottom", + "min", + "MinLen", + "mm", + "mm2", + "mm3", + "mol", + "MonotonicNonNull", + "MonotonicNonNullType", + "MonotonicOdd", + "mPERs", + "mPERs2", + "MustCall", + "MustCallAlias", + "MustCallUnknown", + "N", + "NegativeIndexFor", + "NewObject", + "NonConstant", + "NonDet", + "NonLeaked", + "NonNegative", + "NonNull", + "NonNullType", + "NonRaw", + "NotCalledMethods", + "NotNull", + "NotQualifier", + "NTDBottom", + "NTDMiddle", + "NTDSide", + "NTDTop", + "Nullable", + "NullableType", + "Odd", + "OptionalBottom", + "OrderNonDet", + "Parent", + "PatternA", + "PatternAB", + "PatternAC", + "PatternB", + "PatternBC", + "PatternBottomFull", + "PatternBottomPartial", + "PatternC", + "PatternUnknown", + "Poly", + "PolyAll", + "PolyConstant", + "PolyDet", + "PolyEncrypted", + "PolyFenum", + "PolyIndex", + "PolyInitializedFields", + "PolyInterned", + "PolyKeyFor", + "PolyLength", + "PolyLowerBound", + "PolyMustCall", + "PolyNull", + "PolyNullType", + "PolyPresent", + "PolyRaw", + "PolyReflection", + "PolyRegex", + "PolySameLen", + "PolySignature", + "PolySigned", + "PolyTainted", + "PolyTestAccumulation", + "PolyTypeDeclDefault", + "PolyUI", + "PolyUnit", + "PolyUpperBound", + "PolyValue", + "PolyVariableNameDefault", + "Positive", + "Present", + "PrimitiveType", + "PropertyKey", + "PropertyKeyBottom", + "PurityUnqualified", + "Qualifier", + "radians", + "Raw", + "ReflectBottom", + "Regex", + "RegexBottom", + "RegexNNGroups", + "ReportUnqualified", + "s", + "SameLen", + "SameLenBottom", + "SameLenUnknown", + "SearchIndexBottom", + "SearchIndexFor", + "SearchIndexUnknown", + "Sibling1", + "Sibling2", + "SiblingWithFields", + "SignatureBottom", + "Signed", + "SignednessBottom", + "SignednessGlb", + "SignedPositive", + "SignedPositiveFromUnsigned", + "Speed", + "StringVal", + "SubQual", + "Substance", + "SubstringIndexBottom", + "SubstringIndexFor", + "SubstringIndexUnknown", + "SuperQual", + "SwingBoxOrientation", + "SwingCompassDirection", + "SwingElementOrientation", + "SwingHorizontalOrientation", + "SwingSplitPaneOrientation", + "SwingTextOrientation", + "SwingTitleJustification", + "SwingTitlePosition", + "SwingVerticalOrientation", + "t", + "Tainted", + "Temperature", + "TestAccumulation", + "TestAccumulationBottom", + "TestAccumulationPredicate", + "This", + "Time", + "Top", + "TypeDeclDefaultBottom", + "TypeDeclDefaultMiddle", + "TypeDeclDefaultTop", + "UbTop", + "UB_TOP", + "UI", + "UnderInitialization", + "Unique", + "UnitsBottom", + "UnknownClass", + "UnknownCompilerMessageKey", + "UnknownFormat", + "UnknownInitialization", + "UnknownInterned", + "UnknownKeyFor", + "UnknownLocalizableKey", + "UnknownLocalized", + "UnknownMethod", + "UnknownPropertyKey", + "UnknownRegex", + "UnknownSignedness", + "UnknownThis", + "UnknownUnits", + "UnknownVal", + "Unsigned", + "Untainted", + "UpperBoundBottom", + "UpperBoundLiteral", + "UpperBoundUnknown", + "Value", + "VariableNameDefaultBottom", + "VariableNameDefaultMiddle", + "VariableNameDefaultTop", + "Volume", + "WholeProgramInferenceBottom" + // TODO: Add type annotations from other tools here. + + ); + + static final String NAME = "No line break between type annotation and type"; + + public static FormatterStep create() { + return create(Collections.emptyList(), Collections.emptyList()); + } + + public static FormatterStep create(List addedTypeAnnotations, List removedTypeAnnotations) { + return FormatterStep.create(NAME, new State(addedTypeAnnotations, removedTypeAnnotations), State::toFormatter); + } + + private FormatAnnotationsStep() {} + + // TODO: Enable users to specify more type annotations in `formatAnnotations` in build.gradle. + // TODO: Read from a local .type-annotations file. + private static final class State implements Serializable { + private static final long serialVersionUID = 1L; + + private final Set typeAnnotations = new HashSet<>(defaultTypeAnnotations); + + // group 1 is the basename of the annotation. + private static final String annoNoArgRegex = "@(?:[A-Za-z_][A-Za-z0-9_.]*\\.)?([A-Za-z_][A-Za-z0-9_]*)"; + private static final Pattern annoNoArgPattern = Pattern.compile(annoNoArgRegex); + // 3 non-empty cases: () (".*") (.*) + private static final String annoArgRegex = "(?:\\(\\)|\\(\"[^\"]*\"\\)|\\([^\")][^)]*\\))?"; + // group 1 is the basename of the annotation. + private static final String annoRegex = annoNoArgRegex + annoArgRegex; + private static final String trailingAnnoRegex = annoRegex + "$"; + private static final Pattern trailingAnnoPattern = Pattern.compile(trailingAnnoRegex); + + // Heuristic: matches if the line might be within a //, /*, or Javadoc comment. + private static final Pattern withinCommentPattern = Pattern.compile("//|/\\*(?!.*/*/)|^[ \t]*\\*[ \t]"); + // Don't move an annotation to the start of a comment line. + private static final Pattern startsWithCommentPattern = Pattern.compile("^[ \t]*(//|/\\*$|/\\*|void\\b)"); + + State(List addedTypeAnnotations, List removedTypeAnnotations) { + typeAnnotations.addAll(addedTypeAnnotations); + typeAnnotations.removeAll(removedTypeAnnotations); + } + + FormatterFunc toFormatter() { + return unixStr -> fixupFormatAnnotations(unixStr); + } + + /** + * Removes line break between type annotations and the following type. + * + * @param the text of a Java file + * @return corrected text of the Java file + */ + String fixupFormatAnnotations(String unixStr) { + // Each element of `lines` ends with a newline. + String[] lines = unixStr.split("((?<=\n))"); + for (int i = 0; i < lines.length - 1; i++) { + String line = lines[i]; + if (endsWithTypeAnnotation(line)) { + String nextLine = lines[i + 1]; + if (startsWithCommentPattern.matcher(nextLine).find()) { + continue; + } + lines[i] = ""; + lines[i + 1] = line.replaceAll("\\s+$", "") + " " + nextLine.replaceAll("^\\s+", ""); + } + } + return String.join("", lines); + } + + /** + * Returns true if the line ends with a type annotation. + * FormatAnnotationsStep fixes such formatting. + */ + boolean endsWithTypeAnnotation(String unixLine) { + // Remove trailing newline. + String line = unixLine.replaceAll("\\s+$", ""); + Matcher m = trailingAnnoPattern.matcher(line); + if (!m.find()) { + return false; + } + String preceding = line.substring(0, m.start()); + String basename = m.group(1); + + if (withinCommentPattern.matcher(preceding).find()) { + return false; + } + + return typeAnnotations.contains(basename); + } + } +} diff --git a/lib/src/main/java/com/diffplug/spotless/java/TypeAnnotationsStep.java b/lib/src/main/java/com/diffplug/spotless/java/TypeAnnotationsStep.java deleted file mode 100644 index 36a988aa23..0000000000 --- a/lib/src/main/java/com/diffplug/spotless/java/TypeAnnotationsStep.java +++ /dev/null @@ -1,457 +0,0 @@ -/* - * Copyright 2022 DiffPlug - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package com.diffplug.spotless.java; - -import java.io.Serializable; -import java.util.Arrays; -import java.util.HashSet; -import java.util.Set; -import java.util.regex.Matcher; -import java.util.regex.Pattern; - -import com.diffplug.spotless.FormatterFunc; -import com.diffplug.spotless.FormatterStep; - -/** - * Some formatters put every annotation on its own line - * -- even type annotations, which should be on the same line as the type they qualify. - * This class corrects the formatting. - * This is useful as a postprocessing step after a Java formatter that is not cognizant of type annotations. - - *

- * Note: A type annotation is an annotation that is meta-annotated with {@code @Target({ElementType.TYPE_USE})}. - */ -public final class TypeAnnotationsStep { - private TypeAnnotationsStep() {} - - static final String NAME = "No line break between type annotation and type"; - - public static FormatterStep create() { - return FormatterStep.create(NAME, new State(), State::toFormatter); - } - - // TODO: Enable users to specify more type annotations in `typeAnnotations` in build.gradle. - // TODO: Read from a local .type-annotations file. - private static final class State implements Serializable { - private static final long serialVersionUID = 1L; - - /** - * These are type annotations, which should NOT go on their own line. - * A type annotation's {@code @Target} annotation contains {@code TYPE_USE}. - */ - private static final Set typeAnnotations = new HashSet<>( - Arrays.asList( - // Type annotations from the Checker Framework and all the tools it - // supports, including FindBugs, JetBrains (IntelliJ), Eclipse, NetBeans, - // Spring, JML, Android, etc. - // A type annotation is an annotation that is meta-annotated with @Target({ElementType.TYPE_USE}). - "A", - "ACCBottom", - "Acceleration", - "ACCTop", - "AinferBottom", - "AlwaysSafe", - "Angle", - "AnnoWithStringArg", - "Area", - "ArrayLen", - "ArrayLenRange", - "ArrayWithoutPackage", - "AwtAlphaCompositingRule", - "AwtColorSpace", - "AwtCursorType", - "AwtFlowLayout", - "B", - "BinaryName", - "BinaryNameInUnnamedPackage", - "BinaryNameOrPrimitiveType", - "BinaryNameWithoutPackage", - "BoolVal", - "Bottom", - "BottomQualifier", - "BottomThis", - "BottomVal", - "C", - "CalledMethods", - "CalledMethodsBottom", - "CalledMethodsPredicate", - "CalledMethodsTop", - "CanonicalName", - "CanonicalNameAndBinaryName", - "CanonicalNameOrEmpty", - "CanonicalNameOrPrimitiveType", - "CCBottom", - "CCTop", - "cd", - "ClassBound", - "ClassGetName", - "ClassGetSimpleName", - "ClassVal", - "ClassValBottom", - "CompilerMessageKey", - "CompilerMessageKeyBottom", - "Constant", - "Critical", - "Current", - "D", - "DefaultType", - "degrees", - "Det", - "DotSeparatedIdentifiers", - "DotSeparatedIdentifiersOrPrimitiveType", - "DoubleVal", - "E", - "Encrypted", - "EnhancedRegex", - "EnumVal", - "Even", - "F", - "FBCBottom", - "FEBottom", - "FEBot", - "Fenum", - "FenumBottom", - "FenumTop", - "FETop", - "FieldDescriptor", - "FieldDescriptorForPrimitive", - "FieldDescriptorForPrimitiveOrArrayInUnnamedPackage", - "FieldDescriptorWithoutPackage", - "FlowExp", - "Force", - "Format", - "FormatBottom", - "FqBinaryName", - "Frequency", - "FullyQualifiedName", - "g", - "GTENegativeOne", - "GuardedBy", - "GuardedByBottom", - "GuardedByUnknown", - "GuardSatisfied", - "h", - "H1Bot", - "H1Invalid", - "H1Poly", - "H1S1", - "H1S2", - "H1Top", - "H2Bot", - "H2Poly", - "H2S1", - "H2S2", - "H2Top", - "Hz", - "I18nFormat", - "I18nFormatBottom", - "I18nFormatFor", - "I18nInvalidFormat", - "I18nUnknownFormat", - "Identifier", - "IdentifierOrArray", - "IdentifierOrPrimitiveType", - "ImplicitAnno", - "IndexFor", - "IndexOrHigh", - "IndexOrLow", - "Initialized", - "InitializedFields", - "InitializedFieldsBottom", - "InitializedFieldsPredicate", - "InternalForm", - "Interned", - "InternedDistinct", - "IntRange", - "IntVal", - "InvalidFormat", - "K", - "KeyFor", - "KeyForBottom", - "KeyForType", - "kg", - "kHz", - "km", - "km2", - "km3", - "kmPERh", - "kN", - "LbTop", - "LB_TOP", - "LeakedToResult", - "Length", - "LengthOf", - "LessThan", - "LessThanBottom", - "LessThanUnknown", - "LocalizableKey", - "LocalizableKeyBottom", - "Localized", - "LowerBoundBottom", - "LowerBoundUnknown", - "LTEqLengthOf", - "LTLengthOf", - "LTOMLengthOf", - "Luminance", - "m", - "m2", - "m3", - "Mass", - "MatchesRegex", - "MaybeAliased", - "MaybeDerivedFromConstant", - "MaybePresent", - "MaybeThis", - "MethodDescriptor", - "MethodVal", - "MethodValBottom", - "min", - "MinLen", - "mm", - "mm2", - "mm3", - "mol", - "MonotonicNonNull", - "MonotonicNonNullType", - "MonotonicOdd", - "mPERs", - "mPERs2", - "MustCall", - "MustCallAlias", - "MustCallUnknown", - "N", - "NegativeIndexFor", - "NewObject", - "NonConstant", - "NonDet", - "NonLeaked", - "NonNegative", - "NonNull", - "NonNullType", - "NonRaw", - "NotCalledMethods", - "NotNull", - "NotQualifier", - "NTDBottom", - "NTDMiddle", - "NTDSide", - "NTDTop", - "Nullable", - "NullableType", - "Odd", - "OptionalBottom", - "OrderNonDet", - "Parent", - "PatternA", - "PatternAB", - "PatternAC", - "PatternB", - "PatternBC", - "PatternBottomFull", - "PatternBottomPartial", - "PatternC", - "PatternUnknown", - "Poly", - "PolyAll", - "PolyConstant", - "PolyDet", - "PolyEncrypted", - "PolyFenum", - "PolyIndex", - "PolyInitializedFields", - "PolyInterned", - "PolyKeyFor", - "PolyLength", - "PolyLowerBound", - "PolyMustCall", - "PolyNull", - "PolyNullType", - "PolyPresent", - "PolyRaw", - "PolyReflection", - "PolyRegex", - "PolySameLen", - "PolySignature", - "PolySigned", - "PolyTainted", - "PolyTestAccumulation", - "PolyTypeDeclDefault", - "PolyUI", - "PolyUnit", - "PolyUpperBound", - "PolyValue", - "PolyVariableNameDefault", - "Positive", - "Present", - "PrimitiveType", - "PropertyKey", - "PropertyKeyBottom", - "PurityUnqualified", - "Qualifier", - "radians", - "Raw", - "ReflectBottom", - "Regex", - "RegexBottom", - "RegexNNGroups", - "ReportUnqualified", - "s", - "SameLen", - "SameLenBottom", - "SameLenUnknown", - "SearchIndexBottom", - "SearchIndexFor", - "SearchIndexUnknown", - "Sibling1", - "Sibling2", - "SiblingWithFields", - "SignatureBottom", - "Signed", - "SignednessBottom", - "SignednessGlb", - "SignedPositive", - "SignedPositiveFromUnsigned", - "Speed", - "StringVal", - "SubQual", - "Substance", - "SubstringIndexBottom", - "SubstringIndexFor", - "SubstringIndexUnknown", - "SuperQual", - "SwingBoxOrientation", - "SwingCompassDirection", - "SwingElementOrientation", - "SwingHorizontalOrientation", - "SwingSplitPaneOrientation", - "SwingTextOrientation", - "SwingTitleJustification", - "SwingTitlePosition", - "SwingVerticalOrientation", - "t", - "Tainted", - "Temperature", - "TestAccumulation", - "TestAccumulationBottom", - "TestAccumulationPredicate", - "This", - "Time", - "Top", - "TypeDeclDefaultBottom", - "TypeDeclDefaultMiddle", - "TypeDeclDefaultTop", - "UbTop", - "UB_TOP", - "UI", - "UnderInitialization", - "Unique", - "UnitsBottom", - "UnknownClass", - "UnknownCompilerMessageKey", - "UnknownFormat", - "UnknownInitialization", - "UnknownInterned", - "UnknownKeyFor", - "UnknownLocalizableKey", - "UnknownLocalized", - "UnknownMethod", - "UnknownPropertyKey", - "UnknownRegex", - "UnknownSignedness", - "UnknownThis", - "UnknownUnits", - "UnknownVal", - "Unsigned", - "Untainted", - "UpperBoundBottom", - "UpperBoundLiteral", - "UpperBoundUnknown", - "Value", - "VariableNameDefaultBottom", - "VariableNameDefaultMiddle", - "VariableNameDefaultTop", - "Volume", - "WholeProgramInferenceBottom" - // Add type annotations from other tools here. - - )); - - // group 1 is the basename of the annotation. - private static final String annoNoArgRegex = "@(?:[A-Za-z_][A-Za-z0-9_.]*\\.)?([A-Za-z_][A-Za-z0-9_]*)"; - private static final Pattern annoNoArgPattern = Pattern.compile(annoNoArgRegex); - // 3 non-empty cases: () (".*") (.*) - private static final String annoArgRegex = "(?:\\(\\)|\\(\"[^\"]*\"\\)|\\([^\")][^)]*\\))?"; - // group 1 is the basename of the annotation. - private static final String annoRegex = annoNoArgRegex + annoArgRegex; - private static final String trailingAnnoRegex = annoRegex + "$"; - private static final Pattern trailingAnnoPattern = Pattern.compile(trailingAnnoRegex); - - // Heuristic: matches if the line might be within a //, /*, or Javadoc comment. - private static final Pattern withinCommentPattern = Pattern.compile("//|/\\*(?!.*/*/)|^[ \t]*\\*[ \t]"); - // Don't move an annotation to the start of a comment line. - private static final Pattern startsWithCommentPattern = Pattern.compile("^[ \t]*(//|/\\*$|/\\*|void\\b)"); - - State() {} - - FormatterFunc toFormatter() { - return unixStr -> fixupTypeAnnotations(unixStr); - } - - /** - * Removes line break between type annotations and the following type. - * - * @param the text of a Java file - * @return corrected text of the Java file - */ - String fixupTypeAnnotations(String unixStr) { - // Each element of `lines` ends with a newline. - String[] lines = unixStr.split("((?<=\n))"); - for (int i = 0; i < lines.length - 1; i++) { - String line = lines[i]; - if (endsWithTypeAnnotation(line)) { - String nextLine = lines[i + 1]; - if (startsWithCommentPattern.matcher(nextLine).find()) { - continue; - } - lines[i] = ""; - lines[i + 1] = line.replaceAll("\\s+$", "") + " " + nextLine.replaceAll("^\\s+", ""); - } - } - return String.join("", lines); - } - - /** - * Returns true if the line ends with a type annotation. - * TypeAnnotationStep fixes such formatting. - */ - boolean endsWithTypeAnnotation(String unixLine) { - // Remove trailing newline. - String line = unixLine.replaceAll("\\s+$", ""); - Matcher m = trailingAnnoPattern.matcher(line); - if (!m.find()) { - return false; - } - String preceding = line.substring(0, m.start()); - String basename = m.group(1); - - if (withinCommentPattern.matcher(preceding).find()) { - return false; - } - - return typeAnnotations.contains(basename); - } - } -} diff --git a/plugin-gradle/CHANGES.md b/plugin-gradle/CHANGES.md index bd12048a49..513f36346d 100644 --- a/plugin-gradle/CHANGES.md +++ b/plugin-gradle/CHANGES.md @@ -4,7 +4,7 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format ( ## [Unreleased] ### Added -* `typeAnnotations()` step to correct formatting of type annotations. It puts type annotations on the same line as the type that they qualify. Run it after a Java formatting step, such as `googleJavaFormat()`. ([#1275](https://github.com/diffplug/spotless/pull/1275)) +* `formatAnnotations()` step to correct formatting of type annotations. It puts type annotations on the same line as the type that they qualify. Run it after a Java formatting step, such as `googleJavaFormat()`. ([#1275](https://github.com/diffplug/spotless/pull/1275)) ## [6.10.0] - 2022-08-23 ### Added diff --git a/plugin-gradle/README.md b/plugin-gradle/README.md index 121917b7c9..c1a41c2ef0 100644 --- a/plugin-gradle/README.md +++ b/plugin-gradle/README.md @@ -118,7 +118,7 @@ spotless { // apply a specific flavor of google-java-format googleJavaFormat('1.8').aosp().reflowLongStrings() // fix formatting of type annotations - typeAnnotations() + formatAnnotations() // make sure every file has the following copyright header. // optionally, Spotless can set copyright years by digging // through git history (see "license" section below) @@ -159,12 +159,13 @@ spotless { removeUnusedImports() - googleJavaFormat() // has its own section below - eclipse() // has its own section below - prettier() // has its own section below - clangFormat() // has its own section below + // Choose one of these formatters. + googleJavaFormat() // has its own section below + eclipse() // has its own section below + prettier() // has its own section below + clangFormat() // has its own section below - typeAnnotations() // fixes formatting of type annotations, see below + formatAnnotations() // fixes formatting of type annotations, see below licenseHeader '/* (C) $YEAR */' // or licenseHeaderFile } @@ -193,7 +194,7 @@ spotless { // and/or use custom group artifact (you probably don't need this) googleJavaFormat('1.8').aosp().reflowLongStrings().groupArtifact('com.google.googlejavaformat:google-java-format') // optional: fix formatting of type annotations - typeAnnotations() + formatAnnotations() ``` **⚠️ Note on using Google Java Format with Java 16+** @@ -221,7 +222,7 @@ spotless { // optional: you can specify a specific version palantirJavaFormat('2.9.0') // optional: fix formatting of type annotations - typeAnnotations() + formatAnnotations() ``` **⚠️ Note on using Palantir Java Format with Java 16+** @@ -272,13 +273,13 @@ However, some tools format them incorrectly, like this: String s; ``` -To fix the incorrect formatting, add the `typeAnnotations()` rule after a Java formatter. For example: +To fix the incorrect formatting, add the `formatAnnotations()` rule after a Java formatter. For example: ```gradle spotless { java { googleJavaFormat() - typeAnnotations() + formatAnnotations() } } ``` @@ -286,9 +287,14 @@ spotless { This does not re-order annotations, it just removes incorrect newlines. A type annotation is an annotation that is meta-annotated with `@Target({ElementType.TYPE_USE})`. -Because Spotless cannot necessarily examine the annotation definition, it uses a hard-coded -list of well-known type annotations. You can make a pull request to add new ones. -In the future there will be mechanisms to add/remove annotations from the list. +Spotless has a default list of well-known type annotations. +You can use `addTypeAnnotation()` and `removeTypeAnnotation()` to override its defaults: + +```gradle + formatAnnotations().addTypeAnnotation("Empty").addTypeAnnotation("NonEmpty").removeTypeAnnotation("Localized") +``` + +You can make a pull request to add new annotations to Spotless's default list. 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 94ae136429..de0313eab4 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 @@ -691,6 +691,7 @@ public void withinBlocks(String name, String open, String close, Action diff --git a/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/JavaExtension.java b/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/JavaExtension.java index d882ac472b..1329ce1ad9 100644 --- a/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/JavaExtension.java +++ b/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/JavaExtension.java @@ -18,6 +18,8 @@ import static com.diffplug.gradle.spotless.PluginGradlePreconditions.requireElementsNonNull; import java.io.File; +import java.util.ArrayList; +import java.util.List; import java.util.Objects; import javax.inject.Inject; @@ -32,11 +34,11 @@ import com.diffplug.spotless.extra.EclipseBasedStepBuilder; import com.diffplug.spotless.extra.java.EclipseJdtFormatterStep; import com.diffplug.spotless.generic.LicenseHeaderStep; +import com.diffplug.spotless.java.FormatAnnotationsStep; import com.diffplug.spotless.java.GoogleJavaFormatStep; import com.diffplug.spotless.java.ImportOrderStep; import com.diffplug.spotless.java.PalantirJavaFormatStep; import com.diffplug.spotless.java.RemoveUnusedImportsStep; -import com.diffplug.spotless.java.TypeAnnotationsStep; public class JavaExtension extends FormatExtension implements HasBuiltinDelimiterForLicense { static final String NAME = "java"; @@ -233,8 +235,37 @@ public void configFile(Object... configFiles) { } /** Removes newlines between type annotations and types. */ - public void typeAnnotations() { - addStep(TypeAnnotationsStep.create()); + public FormatAnnotationsConfig formatAnnotations() { + return new FormatAnnotationsConfig(); + } + + public class FormatAnnotationsConfig { + final List addedTypeAnnotations = new ArrayList<>(); + final List removedTypeAnnotations = new ArrayList<>(); + + FormatAnnotationsConfig() { + addStep(createStep()); + } + + public FormatAnnotationsConfig addTypeAnnotation(String simpleName) { + Objects.requireNonNull(simpleName); + addedTypeAnnotations.add(simpleName); + replaceStep(createStep()); + return this; + } + + public FormatAnnotationsConfig removeTypeAnnotation(String simpleName) { + Objects.requireNonNull(simpleName); + removedTypeAnnotations.add(simpleName); + replaceStep(createStep()); + return this; + } + + private FormatterStep createStep() { + return FormatAnnotationsStep.create( + addedTypeAnnotations, + removedTypeAnnotations); + } } /** If the user hasn't specified the files yet, we'll assume he/she means all of the java files. */ diff --git a/plugin-maven/CHANGES.md b/plugin-maven/CHANGES.md index 33e3bc7774..30842b1b06 100644 --- a/plugin-maven/CHANGES.md +++ b/plugin-maven/CHANGES.md @@ -4,7 +4,7 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format ( ## [Unreleased] ### Added -* `typeAnnotations` step to correct formatting of type annotations. It puts type annotations on the same line as the type that they qualify. Run it after a Java formatting step, such as `googleJavaFormat`. ([#1275](https://github.com/diffplug/spotless/pull/1275)) +* `formatAnnotations` step to correct formatting of type annotations. It puts type annotations on the same line as the type that they qualify. Run it after a Java formatting step, such as `googleJavaFormat`. ([#1275](https://github.com/diffplug/spotless/pull/1275)) ## [2.25.0] - 2022-08-23 ### Added diff --git a/plugin-maven/README.md b/plugin-maven/README.md index 42372387be..b7e93f41ca 100644 --- a/plugin-maven/README.md +++ b/plugin-maven/README.md @@ -191,7 +191,7 @@ any other maven phase (i.e. compile) then it can be configured as below; - + /* (C)$YEAR */ @@ -277,11 +277,11 @@ However, some tools format them incorrectly, like this: String s; ``` -To fix the incorrect formatting, add the `typeAnnotations()` rule after a Java formatter. For example: +To fix the incorrect formatting, add the `formatAnnotations()` rule after a Java formatter. For example: ```XML - + ``` This does not re-order annotations, it just removes incorrect newlines. diff --git a/plugin-maven/src/main/java/com/diffplug/spotless/maven/java/TypeAnnotations.java b/plugin-maven/src/main/java/com/diffplug/spotless/maven/java/FormatAnnotations.java similarity index 75% rename from plugin-maven/src/main/java/com/diffplug/spotless/maven/java/TypeAnnotations.java rename to plugin-maven/src/main/java/com/diffplug/spotless/maven/java/FormatAnnotations.java index 8a555c6c72..5ce820921a 100644 --- a/plugin-maven/src/main/java/com/diffplug/spotless/maven/java/TypeAnnotations.java +++ b/plugin-maven/src/main/java/com/diffplug/spotless/maven/java/FormatAnnotations.java @@ -15,15 +15,18 @@ */ package com.diffplug.spotless.maven.java; +import java.util.Collections; + import com.diffplug.spotless.FormatterStep; -import com.diffplug.spotless.java.TypeAnnotationsStep; +import com.diffplug.spotless.java.FormatAnnotationsStep; import com.diffplug.spotless.maven.FormatterStepConfig; import com.diffplug.spotless.maven.FormatterStepFactory; -public class TypeAnnotations implements FormatterStepFactory { +public class FormatAnnotations implements FormatterStepFactory { @Override public FormatterStep newFormatterStep(FormatterStepConfig config) { - return TypeAnnotationsStep.create(); + // TODO: Permit customization in Maven. + return FormatAnnotationsStep.create(Collections.emptyList(), Collections.emptyList()); } } diff --git a/plugin-maven/src/main/java/com/diffplug/spotless/maven/java/Java.java b/plugin-maven/src/main/java/com/diffplug/spotless/maven/java/Java.java index 66b6b8b1c7..4bd018d53c 100644 --- a/plugin-maven/src/main/java/com/diffplug/spotless/maven/java/Java.java +++ b/plugin-maven/src/main/java/com/diffplug/spotless/maven/java/Java.java @@ -62,7 +62,7 @@ public void addRemoveUnusedImports(RemoveUnusedImports removeUnusedImports) { addStepFactory(removeUnusedImports); } - public void addTypeAnnotations(TypeAnnotations typeAnnotations) { - addStepFactory(typeAnnotations); + public void addFormatAnnotations(FormatAnnotations formatAnnotations) { + addStepFactory(formatAnnotations); } } diff --git a/plugin-maven/src/test/java/com/diffplug/spotless/maven/java/TypeAnnotationsStepTest.java b/plugin-maven/src/test/java/com/diffplug/spotless/maven/java/FormatAnnotationsStepTest.java similarity index 71% rename from plugin-maven/src/test/java/com/diffplug/spotless/maven/java/TypeAnnotationsStepTest.java rename to plugin-maven/src/test/java/com/diffplug/spotless/maven/java/FormatAnnotationsStepTest.java index c2281bf8fd..8560b73fd4 100644 --- a/plugin-maven/src/test/java/com/diffplug/spotless/maven/java/TypeAnnotationsStepTest.java +++ b/plugin-maven/src/test/java/com/diffplug/spotless/maven/java/FormatAnnotationsStepTest.java @@ -19,15 +19,15 @@ import com.diffplug.spotless.maven.MavenIntegrationHarness; -class TypeAnnotationsStepTest extends MavenIntegrationHarness { +class FormatAnnotationsStepTest extends MavenIntegrationHarness { @Test - void testTypeAnnotations() throws Exception { - writePomWithJavaSteps(""); + void testFormatAnnotations() throws Exception { + writePomWithJavaSteps(""); String path = "src/main/java/test.java"; - setFile(path).toResource("java/typeannotations/TypeAnnotationsTestInput.test"); + setFile(path).toResource("java/formatannotations/FormatAnnotationsTestInput.test"); mavenRunner().withArguments("spotless:apply").runNoError(); - assertFile(path).sameAsResource("java/typeannotations/TypeAnnotationsTestOutput.test"); + assertFile(path).sameAsResource("java/formatannotations/FormatAnnotationsTestOutput.test"); } } diff --git a/renovate.json b/renovate.json new file mode 100644 index 0000000000..7bd954555f --- /dev/null +++ b/renovate.json @@ -0,0 +1,6 @@ +{ + "$schema": "https://docs.renovatebot.com/renovate-schema.json", + "extends": [ + "config:base" + ] +} diff --git a/testlib/src/main/resources/java/formatannotations/FormatAnnotationsAddRemoveInput.test b/testlib/src/main/resources/java/formatannotations/FormatAnnotationsAddRemoveInput.test new file mode 100644 index 0000000000..e822a8cc41 --- /dev/null +++ b/testlib/src/main/resources/java/formatannotations/FormatAnnotationsAddRemoveInput.test @@ -0,0 +1,11 @@ +class FormatAnnotationsAddRemove { + + @Empty + String e; + + @NonEmpty + String ne; + + @Localized + String localized; +} diff --git a/testlib/src/main/resources/java/formatannotations/FormatAnnotationsAddRemoveOutput.test b/testlib/src/main/resources/java/formatannotations/FormatAnnotationsAddRemoveOutput.test new file mode 100644 index 0000000000..355528bd88 --- /dev/null +++ b/testlib/src/main/resources/java/formatannotations/FormatAnnotationsAddRemoveOutput.test @@ -0,0 +1,9 @@ +class FormatAnnotationsAddRemove { + + @Empty String e; + + @NonEmpty String ne; + + @Localized + String localized; +} diff --git a/testlib/src/main/resources/java/typeannotations/TypeAnnotationsInCommentsInput.test b/testlib/src/main/resources/java/formatannotations/FormatAnnotationsInCommentsInput.test similarity index 94% rename from testlib/src/main/resources/java/typeannotations/TypeAnnotationsInCommentsInput.test rename to testlib/src/main/resources/java/formatannotations/FormatAnnotationsInCommentsInput.test index d49799c0c3..1095de0fd6 100644 --- a/testlib/src/main/resources/java/typeannotations/TypeAnnotationsInCommentsInput.test +++ b/testlib/src/main/resources/java/formatannotations/FormatAnnotationsInCommentsInput.test @@ -1,4 +1,4 @@ -class TypeAnnotationsInComments { +class FormatAnnotationsInComments { // Here is a comment relating to the annotation @Nullable @Interned diff --git a/testlib/src/main/resources/java/typeannotations/TypeAnnotationsInCommentsOutput.test b/testlib/src/main/resources/java/formatannotations/FormatAnnotationsInCommentsOutput.test similarity index 93% rename from testlib/src/main/resources/java/typeannotations/TypeAnnotationsInCommentsOutput.test rename to testlib/src/main/resources/java/formatannotations/FormatAnnotationsInCommentsOutput.test index 491ce5b2aa..91a352347b 100644 --- a/testlib/src/main/resources/java/typeannotations/TypeAnnotationsInCommentsOutput.test +++ b/testlib/src/main/resources/java/formatannotations/FormatAnnotationsInCommentsOutput.test @@ -1,4 +1,4 @@ -class TypeAnnotationsInComments { +class FormatAnnotationsInComments { // Here is a comment relating to the annotation @Nullable @Interned String m1() {} diff --git a/testlib/src/main/resources/java/typeannotations/TypeAnnotationsTestInput.test b/testlib/src/main/resources/java/formatannotations/FormatAnnotationsTestInput.test similarity index 87% rename from testlib/src/main/resources/java/typeannotations/TypeAnnotationsTestInput.test rename to testlib/src/main/resources/java/formatannotations/FormatAnnotationsTestInput.test index 8a870a34cc..fb711451d1 100644 --- a/testlib/src/main/resources/java/typeannotations/TypeAnnotationsTestInput.test +++ b/testlib/src/main/resources/java/formatannotations/FormatAnnotationsTestInput.test @@ -1,4 +1,4 @@ -class TypeAnnotationsTest { +class FormatAnnotationsTest { public @Nullable String s0 = null; @@ -65,4 +65,13 @@ class TypeAnnotationsTest { @Regex(2) @Interned String m6() {} + + @Empty + String e; + + @NonEmpty + String ne; + + @Localized + String localized; } diff --git a/testlib/src/main/resources/java/typeannotations/TypeAnnotationsTestOutput.test b/testlib/src/main/resources/java/formatannotations/FormatAnnotationsTestOutput.test similarity index 87% rename from testlib/src/main/resources/java/typeannotations/TypeAnnotationsTestOutput.test rename to testlib/src/main/resources/java/formatannotations/FormatAnnotationsTestOutput.test index 81fd049609..ca37e66d86 100644 --- a/testlib/src/main/resources/java/typeannotations/TypeAnnotationsTestOutput.test +++ b/testlib/src/main/resources/java/formatannotations/FormatAnnotationsTestOutput.test @@ -1,4 +1,4 @@ -class TypeAnnotationsTest { +class FormatAnnotationsTest { public @Nullable String s0 = null; @@ -40,4 +40,12 @@ class TypeAnnotationsTest { @Nullable // a comment @Regex(2) @Interned String m6() {} + + @Empty + String e; + + @NonEmpty + String ne; + + @Localized String localized; } diff --git a/testlib/src/test/java/com/diffplug/spotless/java/TypeAnnotationsStepTest.java b/testlib/src/test/java/com/diffplug/spotless/java/FormatAnnotationsStepTest.java similarity index 50% rename from testlib/src/test/java/com/diffplug/spotless/java/TypeAnnotationsStepTest.java rename to testlib/src/test/java/com/diffplug/spotless/java/FormatAnnotationsStepTest.java index 3724cac09f..84d347e490 100644 --- a/testlib/src/test/java/com/diffplug/spotless/java/TypeAnnotationsStepTest.java +++ b/testlib/src/test/java/com/diffplug/spotless/java/FormatAnnotationsStepTest.java @@ -15,28 +15,36 @@ */ package com.diffplug.spotless.java; +import java.util.Arrays; + import org.junit.jupiter.api.Test; import com.diffplug.spotless.FormatterStep; import com.diffplug.spotless.ResourceHarness; import com.diffplug.spotless.SerializableEqualityTester; -class TypeAnnotationsStepTest extends ResourceHarness { +class FormatAnnotationsStepTest extends ResourceHarness { + @Test + void formatAnnotations() throws Throwable { + FormatterStep step = FormatAnnotationsStep.create(); + assertOnResources(step, "java/formatannotations/FormatAnnotationsTestInput.test", "java/formatannotations/FormatAnnotationsTestOutput.test"); + } + @Test - void typeAnnotations() throws Throwable { - FormatterStep step = TypeAnnotationsStep.create(); - assertOnResources(step, "java/typeannotations/TypeAnnotationsTestInput.test", "java/typeannotations/TypeAnnotationsTestOutput.test"); + void formatAnnotationsInComments() throws Throwable { + FormatterStep step = FormatAnnotationsStep.create(); + assertOnResources(step, "java/formatannotations/FormatAnnotationsInCommentsInput.test", "java/formatannotations/FormatAnnotationsInCommentsOutput.test"); } @Test - void typeAnnotationsInComments() throws Throwable { - FormatterStep step = TypeAnnotationsStep.create(); - assertOnResources(step, "java/typeannotations/TypeAnnotationsInCommentsInput.test", "java/typeannotations/TypeAnnotationsInCommentsOutput.test"); + void formatAnnotationsAddRemove() throws Throwable { + FormatterStep step = FormatAnnotationsStep.create(Arrays.asList("Empty", "NonEmpty"), Arrays.asList("Localized")); + assertOnResources(step, "java/formatannotations/FormatAnnotationsAddRemoveInput.test", "java/formatannotations/FormatAnnotationsAddRemoveOutput.test"); } @Test - void doesntThrowIfTypeAnnotationsIsntSerializable() { - TypeAnnotationsStep.create(); + void doesntThrowIfFormatAnnotationsIsntSerializable() { + FormatAnnotationsStep.create(); } @Test @@ -49,7 +57,7 @@ protected void setupTest(API api) { @Override protected FormatterStep create() { - return TypeAnnotationsStep.create(); + return FormatAnnotationsStep.create(); } }.testEquals(); } From 263da38e4ef5ef33b2f5ea45b43d972ffdc78abd Mon Sep 17 00:00:00 2001 From: Michael Ernst Date: Sun, 28 Aug 2022 14:21:43 -0700 Subject: [PATCH 275/757] Tweaks --- .../diffplug/spotless/java/FormatAnnotationsStep.java | 9 ++++++--- .../java/com/diffplug/gradle/spotless/JavaExtension.java | 2 ++ plugin-maven/README.md | 1 + .../diffplug/spotless/maven/java/FormatAnnotations.java | 2 +- .../FormatAnnotationsInCommentsInput.test | 4 ++-- .../FormatAnnotationsInCommentsOutput.test | 4 ++-- 6 files changed, 14 insertions(+), 8 deletions(-) diff --git a/lib/src/main/java/com/diffplug/spotless/java/FormatAnnotationsStep.java b/lib/src/main/java/com/diffplug/spotless/java/FormatAnnotationsStep.java index 28691ccf91..1345182acf 100644 --- a/lib/src/main/java/com/diffplug/spotless/java/FormatAnnotationsStep.java +++ b/lib/src/main/java/com/diffplug/spotless/java/FormatAnnotationsStep.java @@ -393,7 +393,6 @@ public static FormatterStep create(List addedTypeAnnotations, List addedTypeAnnotations, List removedTypeAnnotations) { typeAnnotations.addAll(addedTypeAnnotations); typeAnnotations.removeAll(removedTypeAnnotations); } FormatterFunc toFormatter() { - return unixStr -> fixupFormatAnnotations(unixStr); + return unixStr -> fixupTypeAnnotations(unixStr); } /** @@ -430,7 +433,7 @@ FormatterFunc toFormatter() { * @param the text of a Java file * @return corrected text of the Java file */ - String fixupFormatAnnotations(String unixStr) { + String fixupTypeAnnotations(String unixStr) { // Each element of `lines` ends with a newline. String[] lines = unixStr.split("((?<=\n))"); for (int i = 0; i < lines.length - 1; i++) { diff --git a/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/JavaExtension.java b/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/JavaExtension.java index 1329ce1ad9..25e464b0da 100644 --- a/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/JavaExtension.java +++ b/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/JavaExtension.java @@ -240,7 +240,9 @@ public FormatAnnotationsConfig formatAnnotations() { } public class FormatAnnotationsConfig { + /** Annotations in addition to those in the default list. */ final List addedTypeAnnotations = new ArrayList<>(); + /** Annotations that the user doesn't want treated as type annotations. */ final List removedTypeAnnotations = new ArrayList<>(); FormatAnnotationsConfig() { diff --git a/plugin-maven/README.md b/plugin-maven/README.md index b7e93f41ca..3a112cd3b1 100644 --- a/plugin-maven/README.md +++ b/plugin-maven/README.md @@ -290,6 +290,7 @@ A type annotation is an annotation that is meta-annotated with `@Target({Element Because Spotless cannot necessarily examine the annotation definition, it uses a hard-coded list of well-known type annotations. You can make a pull request to add new ones. In the future there will be mechanisms to add/remove annotations from the list. +These mechanisms already exist for the Gradle plugin. ## Groovy diff --git a/plugin-maven/src/main/java/com/diffplug/spotless/maven/java/FormatAnnotations.java b/plugin-maven/src/main/java/com/diffplug/spotless/maven/java/FormatAnnotations.java index 5ce820921a..ac60af0a62 100644 --- a/plugin-maven/src/main/java/com/diffplug/spotless/maven/java/FormatAnnotations.java +++ b/plugin-maven/src/main/java/com/diffplug/spotless/maven/java/FormatAnnotations.java @@ -26,7 +26,7 @@ public class FormatAnnotations implements FormatterStepFactory { @Override public FormatterStep newFormatterStep(FormatterStepConfig config) { - // TODO: Permit customization in Maven. + // TODO: Permit customization in Maven build files. return FormatAnnotationsStep.create(Collections.emptyList(), Collections.emptyList()); } } diff --git a/testlib/src/main/resources/java/formatannotations/FormatAnnotationsInCommentsInput.test b/testlib/src/main/resources/java/formatannotations/FormatAnnotationsInCommentsInput.test index 1095de0fd6..a744b072a1 100644 --- a/testlib/src/main/resources/java/formatannotations/FormatAnnotationsInCommentsInput.test +++ b/testlib/src/main/resources/java/formatannotations/FormatAnnotationsInCommentsInput.test @@ -1,10 +1,10 @@ class FormatAnnotationsInComments { - // Here is a comment relating to the annotation @Nullable + // Here is a comment @Interned String m1() {} - // Here is another comment relating to the annotation @Nullable + // Here is another comment String m2() {} /** diff --git a/testlib/src/main/resources/java/formatannotations/FormatAnnotationsInCommentsOutput.test b/testlib/src/main/resources/java/formatannotations/FormatAnnotationsInCommentsOutput.test index 91a352347b..be65af24be 100644 --- a/testlib/src/main/resources/java/formatannotations/FormatAnnotationsInCommentsOutput.test +++ b/testlib/src/main/resources/java/formatannotations/FormatAnnotationsInCommentsOutput.test @@ -1,9 +1,9 @@ class FormatAnnotationsInComments { - // Here is a comment relating to the annotation @Nullable + // Here is a comment @Interned String m1() {} - // Here is another comment relating to the annotation @Nullable + // Here is another comment String m2() {} /** From 04040622bed59ebcd87a32a2b1f56a9917587c00 Mon Sep 17 00:00:00 2001 From: Michael Ernst Date: Sun, 28 Aug 2022 14:23:32 -0700 Subject: [PATCH 276/757] Tabify --- .../com/diffplug/spotless/java/FormatAnnotationsStep.java | 8 ++++---- .../java/com/diffplug/gradle/spotless/JavaExtension.java | 4 ++-- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/lib/src/main/java/com/diffplug/spotless/java/FormatAnnotationsStep.java b/lib/src/main/java/com/diffplug/spotless/java/FormatAnnotationsStep.java index 1345182acf..2d01e305a0 100644 --- a/lib/src/main/java/com/diffplug/spotless/java/FormatAnnotationsStep.java +++ b/lib/src/main/java/com/diffplug/spotless/java/FormatAnnotationsStep.java @@ -414,10 +414,10 @@ private static final class State implements Serializable { // Don't move an annotation to the start of a comment line. private static final Pattern startsWithCommentPattern = Pattern.compile("^[ \t]*(//|/\\*$|/\\*|void\\b)"); - /** - * @param addedTypeAnnotations simple names to add to Spotless's default list - * @param removedTypeAnnotations simple names to remove from Spotless's default list - */ + /** + * @param addedTypeAnnotations simple names to add to Spotless's default list + * @param removedTypeAnnotations simple names to remove from Spotless's default list + */ State(List addedTypeAnnotations, List removedTypeAnnotations) { typeAnnotations.addAll(addedTypeAnnotations); typeAnnotations.removeAll(removedTypeAnnotations); diff --git a/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/JavaExtension.java b/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/JavaExtension.java index 25e464b0da..3976c154aa 100644 --- a/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/JavaExtension.java +++ b/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/JavaExtension.java @@ -240,9 +240,9 @@ public FormatAnnotationsConfig formatAnnotations() { } public class FormatAnnotationsConfig { - /** Annotations in addition to those in the default list. */ + /** Annotations in addition to those in the default list. */ final List addedTypeAnnotations = new ArrayList<>(); - /** Annotations that the user doesn't want treated as type annotations. */ + /** Annotations that the user doesn't want treated as type annotations. */ final List removedTypeAnnotations = new ArrayList<>(); FormatAnnotationsConfig() { From 8c59a0637265f9357918caabcc2df459a3025cfb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?David=20Burstr=C3=B6m?= Date: Mon, 29 Aug 2022 13:41:05 +0200 Subject: [PATCH 277/757] Reinstate support for KtLint down to 0.31.0 The io.github.davidburstrom.version-compatibility plugin provides sourcesets that make it possible to write adapters against specific versions of KtLint, and the correct adapter will be selected during runtime. --- CHANGES.md | 3 + lib/build.gradle | 35 +++++ .../compat/KtLintCompat0Dot31Dot0Adapter.java | 63 +++++++++ .../compat/KtLintCompat0Dot32Dot0Adapter.java | 63 +++++++++ .../compat/KtLintCompat0Dot34Dot2Adapter.java | 67 ++++++++++ .../compat/KtLintCompat0Dot45Dot2Adapter.java | 118 +++++++++++++++++ .../compat/KtLintCompat0Dot46Dot0Adapter.java | 118 +++++++++++++++++ .../ktlint/compat/KtLintCompatAdapter.java | 24 ++++ .../ktlint/compat/KtLintCompatReporting.java | 25 ++++ .../glue/ktlint/KtlintFormatterFunc.java | 121 ++++-------------- .../diffplug/spotless/kotlin/KtLintStep.java | 25 +++- plugin-gradle/CHANGES.md | 3 + plugin-maven/CHANGES.md | 3 + settings.gradle | 3 + .../spotless/kotlin/KtLintStepTest.java | 74 ++++++++++- 15 files changed, 641 insertions(+), 104 deletions(-) create mode 100644 lib/src/compatKtLint0Dot31Dot0/java/com/diffplug/spotless/glue/ktlint/compat/KtLintCompat0Dot31Dot0Adapter.java create mode 100644 lib/src/compatKtLint0Dot32Dot0/java/com/diffplug/spotless/glue/ktlint/compat/KtLintCompat0Dot32Dot0Adapter.java create mode 100644 lib/src/compatKtLint0Dot34Dot2/java/com/diffplug/spotless/glue/ktlint/compat/KtLintCompat0Dot34Dot2Adapter.java create mode 100644 lib/src/compatKtLint0Dot45Dot2/java/com/diffplug/spotless/glue/ktlint/compat/KtLintCompat0Dot45Dot2Adapter.java create mode 100644 lib/src/compatKtLint0Dot46Dot0/java/com/diffplug/spotless/glue/ktlint/compat/KtLintCompat0Dot46Dot0Adapter.java create mode 100644 lib/src/compatKtLintApi/java/com/diffplug/spotless/glue/ktlint/compat/KtLintCompatAdapter.java create mode 100644 lib/src/compatKtLintApi/java/com/diffplug/spotless/glue/ktlint/compat/KtLintCompatReporting.java diff --git a/CHANGES.md b/CHANGES.md index 580b23b9fb..01e68f430c 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -11,6 +11,9 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format ( ## [Unreleased] +### Changes +* Extend minimum supported version for `ktlint` to `0.31.0` ([#1303](https://github.com/diffplug/spotless/pull/1303)). + ## [2.29.0] - 2022-08-23 ### Added * `scalafmt` integration now has a configuration option `majorScalaVersion` that allows you to configure the Scala version that gets resolved from the maven artifact ([#1283](https://github.com/diffplug/spotless/pull/1283)) diff --git a/lib/build.gradle b/lib/build.gradle index fae8b5b875..1a5fbf9c64 100644 --- a/lib/build.gradle +++ b/lib/build.gradle @@ -1,5 +1,6 @@ plugins { id 'java-library' + id 'io.github.davidburstrom.version-compatibility' } ext.artifactId = project.artifactIdLib version = rootProject.spotlessChangelog.versionNext @@ -23,6 +24,21 @@ for (glue in NEEDS_GLUE) { } } +versionCompatibility { + adapters { + namespaces.register('KtLint') { + versions = [ + '0.31.0', + '0.32.0', + '0.34.2', + '0.45.2', + '0.46.0', + ] + targetSourceSetName = 'ktlint' + } + } +} + dependencies { compileOnly 'org.slf4j:slf4j-api:2.0.0' // zero runtime reqs is a hard requirements for spotless-lib @@ -52,6 +68,25 @@ dependencies { ktlintCompileOnly "com.pinterest.ktlint:ktlint-ruleset-experimental:$VER_KTLINT" ktlintCompileOnly "com.pinterest.ktlint:ktlint-ruleset-standard:$VER_KTLINT" + compatKtLint0Dot31Dot0CompileOnly 'org.jetbrains.kotlin:kotlin-stdlib-jdk8:1.5.20' + compatKtLint0Dot31Dot0CompileOnly 'com.github.shyiko.ktlint:ktlint-core:0.31.0' + compatKtLint0Dot31Dot0CompileOnly 'com.github.shyiko.ktlint:ktlint-ruleset-experimental:0.31.0' + compatKtLint0Dot31Dot0CompileOnly 'com.github.shyiko.ktlint:ktlint-ruleset-standard:0.31.0' + compatKtLint0Dot32Dot0CompileOnly 'org.jetbrains.kotlin:kotlin-stdlib-jdk8:1.5.20' + compatKtLint0Dot32Dot0CompileOnly 'com.pinterest.ktlint:ktlint-core:0.32.0' + compatKtLint0Dot32Dot0CompileOnly 'com.pinterest.ktlint:ktlint-ruleset-experimental:0.32.0' + compatKtLint0Dot32Dot0CompileOnly 'com.pinterest.ktlint:ktlint-ruleset-standard:0.32.0' + compatKtLint0Dot34Dot2CompileOnly 'org.jetbrains.kotlin:kotlin-stdlib-jdk8:1.5.20' + compatKtLint0Dot34Dot2CompileOnly 'com.pinterest.ktlint:ktlint-core:0.34.2' + compatKtLint0Dot34Dot2CompileOnly 'com.pinterest.ktlint:ktlint-ruleset-experimental:0.34.2' + compatKtLint0Dot34Dot2CompileOnly 'com.pinterest.ktlint:ktlint-ruleset-standard:0.34.2' + compatKtLint0Dot45Dot2CompileOnly 'com.pinterest.ktlint:ktlint-core:0.45.2' + compatKtLint0Dot45Dot2CompileOnly 'com.pinterest.ktlint:ktlint-ruleset-experimental:0.45.2' + compatKtLint0Dot45Dot2CompileOnly 'com.pinterest.ktlint:ktlint-ruleset-standard:0.45.2' + compatKtLint0Dot46Dot0CompileOnly 'com.pinterest.ktlint:ktlint-core:0.46.0' + compatKtLint0Dot46Dot0CompileOnly 'com.pinterest.ktlint:ktlint-ruleset-experimental:0.46.0' + compatKtLint0Dot46Dot0CompileOnly 'com.pinterest.ktlint:ktlint-ruleset-standard:0.46.0' + String VER_SCALAFMT="3.5.9" scalafmtCompileOnly "org.scalameta:scalafmt-core_2.13:$VER_SCALAFMT" diff --git a/lib/src/compatKtLint0Dot31Dot0/java/com/diffplug/spotless/glue/ktlint/compat/KtLintCompat0Dot31Dot0Adapter.java b/lib/src/compatKtLint0Dot31Dot0/java/com/diffplug/spotless/glue/ktlint/compat/KtLintCompat0Dot31Dot0Adapter.java new file mode 100644 index 0000000000..56b8da2d20 --- /dev/null +++ b/lib/src/compatKtLint0Dot31Dot0/java/com/diffplug/spotless/glue/ktlint/compat/KtLintCompat0Dot31Dot0Adapter.java @@ -0,0 +1,63 @@ +/* + * Copyright 2022 DiffPlug + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.diffplug.spotless.glue.ktlint.compat; + +import java.util.ArrayList; +import java.util.List; +import java.util.Map; + +import com.github.shyiko.ktlint.core.KtLint; +import com.github.shyiko.ktlint.core.LintError; +import com.github.shyiko.ktlint.core.RuleSet; +import com.github.shyiko.ktlint.ruleset.experimental.ExperimentalRuleSetProvider; +import com.github.shyiko.ktlint.ruleset.standard.StandardRuleSetProvider; + +import kotlin.Unit; +import kotlin.jvm.functions.Function2; + +public class KtLintCompat0Dot31Dot0Adapter implements KtLintCompatAdapter { + + static class FormatterCallback implements Function2 { + @Override + public Unit invoke(LintError lint, Boolean corrected) { + if (!corrected) { + KtLintCompatReporting.report(lint.getLine(), lint.getCol(), lint.getRuleId(), lint.getDetail()); + } + return null; + } + } + + @Override + public String format(final String text, final String name, final boolean isScript, + final boolean useExperimental, + final Map userData, + final Map editorConfigOverrideMap) { + final FormatterCallback formatterCallback = new FormatterCallback(); + + final List rulesets = new ArrayList<>(); + rulesets.add(new StandardRuleSetProvider().get()); + + if (useExperimental) { + rulesets.add(new ExperimentalRuleSetProvider().get()); + } + + return KtLint.INSTANCE.format( + text, + rulesets, + userData, + formatterCallback); + } +} diff --git a/lib/src/compatKtLint0Dot32Dot0/java/com/diffplug/spotless/glue/ktlint/compat/KtLintCompat0Dot32Dot0Adapter.java b/lib/src/compatKtLint0Dot32Dot0/java/com/diffplug/spotless/glue/ktlint/compat/KtLintCompat0Dot32Dot0Adapter.java new file mode 100644 index 0000000000..6f69fcc7ce --- /dev/null +++ b/lib/src/compatKtLint0Dot32Dot0/java/com/diffplug/spotless/glue/ktlint/compat/KtLintCompat0Dot32Dot0Adapter.java @@ -0,0 +1,63 @@ +/* + * Copyright 2022 DiffPlug + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.diffplug.spotless.glue.ktlint.compat; + +import java.util.ArrayList; +import java.util.List; +import java.util.Map; + +import com.pinterest.ktlint.core.KtLint; +import com.pinterest.ktlint.core.LintError; +import com.pinterest.ktlint.core.RuleSet; +import com.pinterest.ktlint.ruleset.experimental.ExperimentalRuleSetProvider; +import com.pinterest.ktlint.ruleset.standard.StandardRuleSetProvider; + +import kotlin.Unit; +import kotlin.jvm.functions.Function2; + +public class KtLintCompat0Dot32Dot0Adapter implements KtLintCompatAdapter { + + static class FormatterCallback implements Function2 { + @Override + public Unit invoke(LintError lint, Boolean corrected) { + if (!corrected) { + KtLintCompatReporting.report(lint.getLine(), lint.getCol(), lint.getRuleId(), lint.getDetail()); + } + return null; + } + } + + @Override + public String format(final String text, final String name, final boolean isScript, + final boolean useExperimental, + final Map userData, + final Map editorConfigOverrideMap) { + final FormatterCallback formatterCallback = new FormatterCallback(); + + final List rulesets = new ArrayList<>(); + rulesets.add(new StandardRuleSetProvider().get()); + + if (useExperimental) { + rulesets.add(new ExperimentalRuleSetProvider().get()); + } + + return KtLint.INSTANCE.format( + text, + rulesets, + userData, + formatterCallback); + } +} diff --git a/lib/src/compatKtLint0Dot34Dot2/java/com/diffplug/spotless/glue/ktlint/compat/KtLintCompat0Dot34Dot2Adapter.java b/lib/src/compatKtLint0Dot34Dot2/java/com/diffplug/spotless/glue/ktlint/compat/KtLintCompat0Dot34Dot2Adapter.java new file mode 100644 index 0000000000..a3c8c8df3b --- /dev/null +++ b/lib/src/compatKtLint0Dot34Dot2/java/com/diffplug/spotless/glue/ktlint/compat/KtLintCompat0Dot34Dot2Adapter.java @@ -0,0 +1,67 @@ +/* + * Copyright 2022 DiffPlug + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.diffplug.spotless.glue.ktlint.compat; + +import java.util.ArrayList; +import java.util.List; +import java.util.Map; + +import com.pinterest.ktlint.core.KtLint; +import com.pinterest.ktlint.core.LintError; +import com.pinterest.ktlint.core.RuleSet; +import com.pinterest.ktlint.ruleset.experimental.ExperimentalRuleSetProvider; +import com.pinterest.ktlint.ruleset.standard.StandardRuleSetProvider; + +import kotlin.Unit; +import kotlin.jvm.functions.Function2; + +public class KtLintCompat0Dot34Dot2Adapter implements KtLintCompatAdapter { + + static class FormatterCallback implements Function2 { + @Override + public Unit invoke(LintError lint, Boolean corrected) { + if (!corrected) { + KtLintCompatReporting.report(lint.getLine(), lint.getCol(), lint.getRuleId(), lint.getDetail()); + } + return null; + } + } + + @Override + public String format(final String text, final String name, final boolean isScript, + final boolean useExperimental, + final Map userData, + final Map editorConfigOverrideMap) { + final FormatterCallback formatterCallback = new FormatterCallback(); + + final List rulesets = new ArrayList<>(); + rulesets.add(new StandardRuleSetProvider().get()); + + if (useExperimental) { + rulesets.add(new ExperimentalRuleSetProvider().get()); + } + + return KtLint.INSTANCE.format(new KtLint.Params( + name, + text, + rulesets, + userData, + formatterCallback, + isScript, + null, + false)); + } +} diff --git a/lib/src/compatKtLint0Dot45Dot2/java/com/diffplug/spotless/glue/ktlint/compat/KtLintCompat0Dot45Dot2Adapter.java b/lib/src/compatKtLint0Dot45Dot2/java/com/diffplug/spotless/glue/ktlint/compat/KtLintCompat0Dot45Dot2Adapter.java new file mode 100644 index 0000000000..f7eadada3d --- /dev/null +++ b/lib/src/compatKtLint0Dot45Dot2/java/com/diffplug/spotless/glue/ktlint/compat/KtLintCompat0Dot45Dot2Adapter.java @@ -0,0 +1,118 @@ +/* + * Copyright 2022 DiffPlug + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.diffplug.spotless.glue.ktlint.compat; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; +import java.util.Map; +import java.util.Objects; +import java.util.stream.Collectors; +import java.util.stream.Stream; + +import com.pinterest.ktlint.core.KtLint; +import com.pinterest.ktlint.core.LintError; +import com.pinterest.ktlint.core.RuleSet; +import com.pinterest.ktlint.core.api.DefaultEditorConfigProperties; +import com.pinterest.ktlint.core.api.EditorConfigOverride; +import com.pinterest.ktlint.core.api.UsesEditorConfigProperties; +import com.pinterest.ktlint.ruleset.experimental.ExperimentalRuleSetProvider; +import com.pinterest.ktlint.ruleset.standard.StandardRuleSetProvider; + +import kotlin.Pair; +import kotlin.Unit; +import kotlin.jvm.functions.Function2; + +public class KtLintCompat0Dot45Dot2Adapter implements KtLintCompatAdapter { + + static class FormatterCallback implements Function2 { + @Override + public Unit invoke(LintError lint, Boolean corrected) { + if (!corrected) { + KtLintCompatReporting.report(lint.getLine(), lint.getCol(), lint.getRuleId(), lint.getDetail()); + } + return null; + } + } + + @Override + public String format(final String text, final String name, final boolean isScript, + final boolean useExperimental, + final Map userData, + final Map editorConfigOverrideMap) { + final FormatterCallback formatterCallback = new FormatterCallback(); + + final List rulesets = new ArrayList<>(); + rulesets.add(new StandardRuleSetProvider().get()); + + if (useExperimental) { + rulesets.add(new ExperimentalRuleSetProvider().get()); + } + + EditorConfigOverride editorConfigOverride; + if (editorConfigOverrideMap.isEmpty()) { + editorConfigOverride = EditorConfigOverride.Companion.getEmptyEditorConfigOverride(); + } else { + editorConfigOverride = createEditorConfigOverride(rulesets, editorConfigOverrideMap); + } + + return KtLint.INSTANCE.format(new KtLint.ExperimentalParams( + name, + text, + rulesets, + userData, + formatterCallback, + isScript, + null, + false, + editorConfigOverride, + false)); + } + + /** + * Create EditorConfigOverride from user provided parameters. + * Calling this method requires KtLint 0.45.2. + */ + private static EditorConfigOverride createEditorConfigOverride(final List rulesets, Map editorConfigOverrideMap) { + // Get properties from rules in the rule sets + Stream> ruleProperties = rulesets.stream() + .flatMap(ruleSet -> Arrays.stream(ruleSet.getRules())) + .filter(rule -> rule instanceof UsesEditorConfigProperties) + .flatMap(rule -> ((UsesEditorConfigProperties) rule).getEditorConfigProperties().stream()); + + // Create a mapping of properties to their names based on rule properties and default properties + Map> supportedProperties = Stream + .concat(ruleProperties, DefaultEditorConfigProperties.INSTANCE.getDefaultEditorConfigProperties().stream()) + .distinct() + .collect(Collectors.toMap(property -> property.getType().getName(), property -> property)); + + // Create config properties based on provided property names and values + @SuppressWarnings("unchecked") + Pair, ?>[] properties = editorConfigOverrideMap.entrySet().stream() + .map(entry -> { + UsesEditorConfigProperties.EditorConfigProperty property = supportedProperties.get(entry.getKey()); + if (property != null) { + return new Pair<>(property, entry.getValue()); + } else { + return null; + } + }) + .filter(Objects::nonNull) + .toArray(Pair[]::new); + + return EditorConfigOverride.Companion.from(properties); + } +} diff --git a/lib/src/compatKtLint0Dot46Dot0/java/com/diffplug/spotless/glue/ktlint/compat/KtLintCompat0Dot46Dot0Adapter.java b/lib/src/compatKtLint0Dot46Dot0/java/com/diffplug/spotless/glue/ktlint/compat/KtLintCompat0Dot46Dot0Adapter.java new file mode 100644 index 0000000000..873b91af80 --- /dev/null +++ b/lib/src/compatKtLint0Dot46Dot0/java/com/diffplug/spotless/glue/ktlint/compat/KtLintCompat0Dot46Dot0Adapter.java @@ -0,0 +1,118 @@ +/* + * Copyright 2022 DiffPlug + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.diffplug.spotless.glue.ktlint.compat; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; +import java.util.Map; +import java.util.Objects; +import java.util.stream.Collectors; +import java.util.stream.Stream; + +import com.pinterest.ktlint.core.KtLint; +import com.pinterest.ktlint.core.LintError; +import com.pinterest.ktlint.core.RuleSet; +import com.pinterest.ktlint.core.api.DefaultEditorConfigProperties; +import com.pinterest.ktlint.core.api.EditorConfigOverride; +import com.pinterest.ktlint.core.api.UsesEditorConfigProperties; +import com.pinterest.ktlint.ruleset.experimental.ExperimentalRuleSetProvider; +import com.pinterest.ktlint.ruleset.standard.StandardRuleSetProvider; + +import kotlin.Pair; +import kotlin.Unit; +import kotlin.jvm.functions.Function2; + +public class KtLintCompat0Dot46Dot0Adapter implements KtLintCompatAdapter { + + static class FormatterCallback implements Function2 { + @Override + public Unit invoke(LintError lint, Boolean corrected) { + if (!corrected) { + KtLintCompatReporting.report(lint.getLine(), lint.getCol(), lint.getRuleId(), lint.getDetail()); + } + return null; + } + } + + @Override + public String format(final String text, final String name, final boolean isScript, + final boolean useExperimental, + final Map userData, + final Map editorConfigOverrideMap) { + final FormatterCallback formatterCallback = new FormatterCallback(); + + final List rulesets = new ArrayList<>(); + rulesets.add(new StandardRuleSetProvider().get()); + + if (useExperimental) { + rulesets.add(new ExperimentalRuleSetProvider().get()); + } + + EditorConfigOverride editorConfigOverride; + if (editorConfigOverrideMap.isEmpty()) { + editorConfigOverride = EditorConfigOverride.Companion.getEmptyEditorConfigOverride(); + } else { + editorConfigOverride = createEditorConfigOverride(rulesets, editorConfigOverrideMap); + } + + return KtLint.INSTANCE.format(new KtLint.ExperimentalParams( + name, + text, + rulesets, + userData, + formatterCallback, + isScript, + null, + false, + editorConfigOverride, + false)); + } + + /** + * Create EditorConfigOverride from user provided parameters. + * Calling this method requires KtLint 0.45.2. + */ + private static EditorConfigOverride createEditorConfigOverride(final List rulesets, Map editorConfigOverrideMap) { + // Get properties from rules in the rule sets + Stream> ruleProperties = rulesets.stream() + .flatMap(ruleSet -> Arrays.stream(ruleSet.getRules())) + .filter(rule -> rule instanceof UsesEditorConfigProperties) + .flatMap(rule -> ((UsesEditorConfigProperties) rule).getEditorConfigProperties().stream()); + + // Create a mapping of properties to their names based on rule properties and default properties + Map> supportedProperties = Stream + .concat(ruleProperties, DefaultEditorConfigProperties.INSTANCE.getEditorConfigProperties().stream()) + .distinct() + .collect(Collectors.toMap(property -> property.getType().getName(), property -> property)); + + // Create config properties based on provided property names and values + @SuppressWarnings("unchecked") + Pair, ?>[] properties = editorConfigOverrideMap.entrySet().stream() + .map(entry -> { + UsesEditorConfigProperties.EditorConfigProperty property = supportedProperties.get(entry.getKey()); + if (property != null) { + return new Pair<>(property, entry.getValue()); + } else { + return null; + } + }) + .filter(Objects::nonNull) + .toArray(Pair[]::new); + + return EditorConfigOverride.Companion.from(properties); + } +} diff --git a/lib/src/compatKtLintApi/java/com/diffplug/spotless/glue/ktlint/compat/KtLintCompatAdapter.java b/lib/src/compatKtLintApi/java/com/diffplug/spotless/glue/ktlint/compat/KtLintCompatAdapter.java new file mode 100644 index 0000000000..5097cac135 --- /dev/null +++ b/lib/src/compatKtLintApi/java/com/diffplug/spotless/glue/ktlint/compat/KtLintCompatAdapter.java @@ -0,0 +1,24 @@ +/* + * Copyright 2022 DiffPlug + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.diffplug.spotless.glue.ktlint.compat; + +import java.util.Map; + +public interface KtLintCompatAdapter { + + String format(String text, String name, boolean isScript, boolean useExperimental, Map userData, + Map editorConfigOverrideMap); +} diff --git a/lib/src/compatKtLintApi/java/com/diffplug/spotless/glue/ktlint/compat/KtLintCompatReporting.java b/lib/src/compatKtLintApi/java/com/diffplug/spotless/glue/ktlint/compat/KtLintCompatReporting.java new file mode 100644 index 0000000000..7c1e0f6dd8 --- /dev/null +++ b/lib/src/compatKtLintApi/java/com/diffplug/spotless/glue/ktlint/compat/KtLintCompatReporting.java @@ -0,0 +1,25 @@ +/* + * Copyright 2022 DiffPlug + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.diffplug.spotless.glue.ktlint.compat; + +final class KtLintCompatReporting { + + private KtLintCompatReporting() {} + + static void report(int line, int column, String ruleId, String detail) { + throw new AssertionError("Error on line: " + line + ", column: " + column + "\nrule: " + ruleId + "\n" + detail); + } +} diff --git a/lib/src/ktlint/java/com/diffplug/spotless/glue/ktlint/KtlintFormatterFunc.java b/lib/src/ktlint/java/com/diffplug/spotless/glue/ktlint/KtlintFormatterFunc.java index e7af558fb5..96ad244593 100644 --- a/lib/src/ktlint/java/com/diffplug/spotless/glue/ktlint/KtlintFormatterFunc.java +++ b/lib/src/ktlint/java/com/diffplug/spotless/glue/ktlint/KtlintFormatterFunc.java @@ -16,119 +16,52 @@ package com.diffplug.spotless.glue.ktlint; import java.io.File; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.List; import java.util.Map; -import java.util.Objects; -import java.util.stream.Collectors; -import java.util.stream.Stream; import org.jetbrains.annotations.NotNull; -import com.pinterest.ktlint.core.KtLint; -import com.pinterest.ktlint.core.KtLint.ExperimentalParams; -import com.pinterest.ktlint.core.LintError; -import com.pinterest.ktlint.core.RuleSet; -import com.pinterest.ktlint.core.api.DefaultEditorConfigProperties; -import com.pinterest.ktlint.core.api.EditorConfigOverride; -import com.pinterest.ktlint.core.api.UsesEditorConfigProperties; -import com.pinterest.ktlint.ruleset.experimental.ExperimentalRuleSetProvider; -import com.pinterest.ktlint.ruleset.standard.StandardRuleSetProvider; - import com.diffplug.spotless.FormatterFunc; - -import kotlin.Pair; -import kotlin.Unit; -import kotlin.jvm.functions.Function2; +import com.diffplug.spotless.glue.ktlint.compat.KtLintCompat0Dot31Dot0Adapter; +import com.diffplug.spotless.glue.ktlint.compat.KtLintCompat0Dot32Dot0Adapter; +import com.diffplug.spotless.glue.ktlint.compat.KtLintCompat0Dot34Dot2Adapter; +import com.diffplug.spotless.glue.ktlint.compat.KtLintCompat0Dot45Dot2Adapter; +import com.diffplug.spotless.glue.ktlint.compat.KtLintCompat0Dot46Dot0Adapter; +import com.diffplug.spotless.glue.ktlint.compat.KtLintCompat0Dot47Dot0Adapter; +import com.diffplug.spotless.glue.ktlint.compat.KtLintCompatAdapter; public class KtlintFormatterFunc implements FormatterFunc.NeedsFile { - private final List rulesets; private final Map userData; - private final Function2 formatterCallback; private final boolean isScript; @NotNull - private final EditorConfigOverride editorConfigOverride; + private final KtLintCompatAdapter adapter; + private final boolean useExperimental; + private final Map editorConfigOverrideMap; - /** - * Non-empty editorConfigOverrideMap requires KtLint 0.45.2. - */ - public KtlintFormatterFunc(boolean isScript, boolean useExperimental, Map userData, + public KtlintFormatterFunc(String version, boolean isScript, boolean useExperimental, Map userData, Map editorConfigOverrideMap) { - rulesets = new ArrayList<>(); - rulesets.add(new StandardRuleSetProvider().get()); - - if (useExperimental) { - rulesets.add(new ExperimentalRuleSetProvider().get()); + int minorVersion = Integer.parseInt(version.split("\\.")[1]); + if (version.equals("0.45.2")) { + this.adapter = new KtLintCompat0Dot45Dot2Adapter(); + } else if (minorVersion >= 47) { + this.adapter = new KtLintCompat0Dot47Dot0Adapter(); + } else if (minorVersion >= 46) { + this.adapter = new KtLintCompat0Dot46Dot0Adapter(); + } else if (minorVersion >= 34) { + this.adapter = new KtLintCompat0Dot34Dot2Adapter(); + } else if (minorVersion >= 32) { + this.adapter = new KtLintCompat0Dot32Dot0Adapter(); + } else { + this.adapter = new KtLintCompat0Dot31Dot0Adapter(); } + this.useExperimental = useExperimental; + this.editorConfigOverrideMap = editorConfigOverrideMap; this.userData = userData; - formatterCallback = new FormatterCallback(); this.isScript = isScript; - - if (editorConfigOverrideMap.isEmpty()) { - this.editorConfigOverride = EditorConfigOverride.Companion.getEmptyEditorConfigOverride(); - } else { - this.editorConfigOverride = createEditorConfigOverride(editorConfigOverrideMap); - } - } - - /** - * Create EditorConfigOverride from user provided parameters. - * Calling this method requires KtLint 0.45.2. - */ - private EditorConfigOverride createEditorConfigOverride(Map editorConfigOverrideMap) { - // Get properties from rules in the rule sets - Stream> ruleProperties = rulesets.stream() - .flatMap(ruleSet -> Arrays.stream(ruleSet.getRules())) - .filter(rule -> rule instanceof UsesEditorConfigProperties) - .flatMap(rule -> ((UsesEditorConfigProperties) rule).getEditorConfigProperties().stream()); - - // Create a mapping of properties to their names based on rule properties and default properties - Map> supportedProperties = Stream - .concat(ruleProperties, DefaultEditorConfigProperties.INSTANCE.getEditorConfigProperties().stream()) - .distinct() - .collect(Collectors.toMap(property -> property.getType().getName(), property -> property)); - - // Create config properties based on provided property names and values - @SuppressWarnings("unchecked") - Pair, ?>[] properties = editorConfigOverrideMap.entrySet().stream() - .map(entry -> { - UsesEditorConfigProperties.EditorConfigProperty property = supportedProperties.get(entry.getKey()); - if (property != null) { - return new Pair<>(property, entry.getValue()); - } else { - return null; - } - }) - .filter(Objects::nonNull) - .toArray(Pair[]::new); - - return EditorConfigOverride.Companion.from(properties); - } - - static class FormatterCallback implements Function2 { - @Override - public Unit invoke(LintError lint, Boolean corrected) { - if (!corrected) { - throw new AssertionError("Error on line: " + lint.getLine() + ", column: " + lint.getCol() + "\nrule: " + lint.getRuleId() + "\n" + lint.getDetail()); - } - return null; - } } @Override public String applyWithFile(String unix, File file) throws Exception { - return KtLint.INSTANCE.format(new ExperimentalParams( - file.getName(), - unix, - rulesets, - userData, - formatterCallback, - isScript, - null, - false, - editorConfigOverride, - false)); + return adapter.format(unix, file.getName(), isScript, useExperimental, userData, editorConfigOverrideMap); } } diff --git a/lib/src/main/java/com/diffplug/spotless/kotlin/KtLintStep.java b/lib/src/main/java/com/diffplug/spotless/kotlin/KtLintStep.java index f57ef1e997..6b886c2186 100644 --- a/lib/src/main/java/com/diffplug/spotless/kotlin/KtLintStep.java +++ b/lib/src/main/java/com/diffplug/spotless/kotlin/KtLintStep.java @@ -35,7 +35,9 @@ private KtLintStep() {} private static final String DEFAULT_VERSION = "0.46.1"; static final String NAME = "ktlint"; + static final String PACKAGE_PRE_0_32 = "com.github.shyiko"; static final String PACKAGE = "com.pinterest"; + static final String MAVEN_COORDINATE_PRE_0_32 = PACKAGE_PRE_0_32 + ":ktlint:"; static final String MAVEN_COORDINATE = PACKAGE + ":ktlint:"; public static FormatterStep create(Provisioner provisioner) { @@ -83,25 +85,34 @@ static final class State implements Serializable { private final boolean useExperimental; private final TreeMap userData; private final TreeMap editorConfigOverride; + private final String version; State(String version, Provisioner provisioner, boolean isScript, boolean useExperimental, Map userData, Map editorConfigOverride) throws IOException { + this.version = version; - if (BadSemver.version(version) < BadSemver.version(0, 46, 0)) { - throw new IllegalStateException("KtLint versions < 0.46.0 not supported!"); + String coordinate; + if (BadSemver.version(version) < BadSemver.version(0, 32)) { + coordinate = MAVEN_COORDINATE_PRE_0_32; + } else { + coordinate = MAVEN_COORDINATE; + } + if (BadSemver.version(version) < BadSemver.version(0, 31, 0)) { + throw new IllegalStateException("KtLint versions < 0.31.0 not supported!"); } - this.useExperimental = useExperimental; this.userData = new TreeMap<>(userData); this.editorConfigOverride = new TreeMap<>(editorConfigOverride); - this.jarState = JarState.from(MAVEN_COORDINATE + version, provisioner); + this.jarState = JarState.from(coordinate + version, provisioner); this.isScript = isScript; } FormatterFunc createFormat() throws Exception { - Class formatterFunc = jarState.getClassLoader().loadClass("com.diffplug.spotless.glue.ktlint.KtlintFormatterFunc"); - Constructor constructor = formatterFunc.getConstructor(boolean.class, boolean.class, Map.class, Map.class); - return (FormatterFunc.NeedsFile) constructor.newInstance(isScript, useExperimental, userData, editorConfigOverride); + final ClassLoader classLoader = jarState.getClassLoader(); + Class formatterFunc = classLoader.loadClass("com.diffplug.spotless.glue.ktlint.KtlintFormatterFunc"); + Constructor constructor = formatterFunc.getConstructor( + String.class, boolean.class, boolean.class, Map.class, Map.class); + return (FormatterFunc.NeedsFile) constructor.newInstance(version, isScript, useExperimental, userData, editorConfigOverride); } } } diff --git a/plugin-gradle/CHANGES.md b/plugin-gradle/CHANGES.md index ee1ab8bee8..f1f1fd69e1 100644 --- a/plugin-gradle/CHANGES.md +++ b/plugin-gradle/CHANGES.md @@ -4,6 +4,9 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format ( ## [Unreleased] +### Changes +* Extend minimum supported version for `ktlint` to `0.31.0` ([#1303](https://github.com/diffplug/spotless/pull/1303)). + ## [6.10.0] - 2022-08-23 ### Added * `scalafmt` integration now has a configuration option `majorScalaVersion` that allows you to configure the Scala version that gets resolved from the maven artifact ([#1283](https://github.com/diffplug/spotless/pull/1283)) diff --git a/plugin-maven/CHANGES.md b/plugin-maven/CHANGES.md index 3b6986c5db..f69b4a058e 100644 --- a/plugin-maven/CHANGES.md +++ b/plugin-maven/CHANGES.md @@ -4,6 +4,9 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format ( ## [Unreleased] +### Changes +* Extend minimum supported version for `ktlint` to `0.31.0` ([#1303](https://github.com/diffplug/spotless/pull/1303)). + ## [2.25.0] - 2022-08-23 ### Added * `scalafmt` integration now has a configuration option `majorScalaVersion` that allows you to configure the Scala version that gets resolved from the maven artifact ([#1283](https://github.com/diffplug/spotless/pull/1283)) diff --git a/settings.gradle b/settings.gradle index 83ed4aa59d..7909da6da8 100644 --- a/settings.gradle +++ b/settings.gradle @@ -15,6 +15,8 @@ pluginManagement { id 'org.gradle.test-retry' version '1.4.0' // https://github.com/radarsh/gradle-test-logger-plugin/blob/develop/CHANGELOG.md id 'com.adarshr.test-logger' version '3.2.0' + // https://github.com/davidburstrom/version-compatibility-gradle-plugin/tags + id 'io.github.davidburstrom.version-compatibility' version '0.1.0' } } plugins { @@ -26,6 +28,7 @@ plugins { id 'com.diffplug.p2.asmaven' apply false id 'org.gradle.test-retry' apply false id 'com.adarshr.test-logger' apply false + id 'io.github.davidburstrom.version-compatibility' apply false } if (System.env['CI'] != null) { // use the remote buildcache on all CI builds diff --git a/testlib/src/test/java/com/diffplug/spotless/kotlin/KtLintStepTest.java b/testlib/src/test/java/com/diffplug/spotless/kotlin/KtLintStepTest.java index d9e6042c23..96c2ab885a 100644 --- a/testlib/src/test/java/com/diffplug/spotless/kotlin/KtLintStepTest.java +++ b/testlib/src/test/java/com/diffplug/spotless/kotlin/KtLintStepTest.java @@ -15,6 +15,7 @@ */ package com.diffplug.spotless.kotlin; +import org.junit.jupiter.api.Disabled; import org.junit.jupiter.api.Test; import com.diffplug.spotless.FormatterStep; @@ -38,7 +39,74 @@ void behavior() throws Exception { } @Test - void worksPre0_46_1() throws Exception { + void worksShyiko() throws Exception { + FormatterStep step = KtLintStep.create("0.31.0", TestProvisioner.mavenCentral()); + StepHarness.forStep(step) + .testResource("kotlin/ktlint/basic.dirty", "kotlin/ktlint/basic.clean") + .testResourceException("kotlin/ktlint/unsolvable.dirty", assertion -> { + assertion.isInstanceOf(AssertionError.class); + assertion.hasMessage("Error on line: 1, column: 1\n" + + "rule: no-wildcard-imports\n" + + "Wildcard import"); + }); + } + + // Regression test to ensure it works on the version it switched to Pinterest (version 0.32.0) + // but before 0.34. + // https://github.com/diffplug/spotless/issues/419 + @Test + void worksPinterestAndPre034() throws Exception { + FormatterStep step = KtLintStep.create("0.32.0", TestProvisioner.mavenCentral()); + StepHarness.forStep(step) + .testResource("kotlin/ktlint/basic.dirty", "kotlin/ktlint/basic.clean") + .testResourceException("kotlin/ktlint/unsolvable.dirty", assertion -> { + assertion.isInstanceOf(AssertionError.class); + assertion.hasMessage("Error on line: 1, column: 1\n" + + "rule: no-wildcard-imports\n" + + "Wildcard import"); + }); + } + + // Regression test to handle alpha and 1.x version numbers + // https://github.com/diffplug/spotless/issues/668 + @Test + void worksAlpha1() throws Exception { + FormatterStep step = KtLintStep.create("0.38.0-alpha01", TestProvisioner.mavenCentral()); + StepHarness.forStep(step) + .testResource("kotlin/ktlint/basic.dirty", "kotlin/ktlint/basic.clean"); + } + + @Test + void works0_44_0() throws Exception { + FormatterStep step = KtLintStep.create("0.44.0", TestProvisioner.mavenCentral()); + StepHarness.forStep(step) + .testResource("kotlin/ktlint/basic.dirty", "kotlin/ktlint/basic.clean"); + } + + @Disabled("https://github.com/pinterest/ktlint/issues/1421") + @Test + void works0_45_0() throws Exception { + FormatterStep step = KtLintStep.create("0.45.0", TestProvisioner.mavenCentral()); + StepHarness.forStep(step) + .testResource("kotlin/ktlint/basic.dirty", "kotlin/ktlint/basic.clean"); + } + + @Test + void works0_45_1() throws Exception { + FormatterStep step = KtLintStep.create("0.45.1", TestProvisioner.mavenCentral()); + StepHarness.forStep(step) + .testResource("kotlin/ktlint/basic.dirty", "kotlin/ktlint/basic.clean"); + } + + @Test + void works0_45_2() throws Exception { + FormatterStep step = KtLintStep.create("0.45.2", TestProvisioner.mavenCentral()); + StepHarness.forStep(step) + .testResource("kotlin/ktlint/basic.dirty", "kotlin/ktlint/basic.clean"); + } + + @Test + void works0_46_0() throws Exception { FormatterStep step = KtLintStep.create("0.46.0", TestProvisioner.mavenCentral()); StepHarness.forStep(step) .testResource("kotlin/ktlint/basic.dirty", "kotlin/ktlint/basic.clean") @@ -53,14 +121,14 @@ void worksPre0_46_1() throws Exception { @Test void equality() throws Exception { new SerializableEqualityTester() { - String version = "0.46.0"; + String version = "0.32.0"; @Override protected void setupTest(API api) { // same version == same api.areDifferentThan(); // change the version, and it's different - version = "0.46.1"; + version = "0.38.0-alpha01"; api.areDifferentThan(); } From 225d992fcf8fee26b7a3ca820f3fc82bc2bf064d Mon Sep 17 00:00:00 2001 From: "benjamin.gentner" Date: Fri, 2 Sep 2022 16:34:35 +0200 Subject: [PATCH 278/757] Fix Freshmark compatibility with JDK 15+ (fixes #803) --- .../spotless/markdown/FreshMarkStep.java | 16 +++++++++++++++- .../spotless/markdown/FreshMarkStepTest.java | 6 +----- 2 files changed, 16 insertions(+), 6 deletions(-) diff --git a/lib/src/main/java/com/diffplug/spotless/markdown/FreshMarkStep.java b/lib/src/main/java/com/diffplug/spotless/markdown/FreshMarkStep.java index 2591cac7a5..fd03e95046 100644 --- a/lib/src/main/java/com/diffplug/spotless/markdown/FreshMarkStep.java +++ b/lib/src/main/java/com/diffplug/spotless/markdown/FreshMarkStep.java @@ -19,6 +19,8 @@ import java.io.Serializable; import java.lang.reflect.Method; +import java.util.ArrayList; +import java.util.List; import java.util.Map; import java.util.NavigableMap; import java.util.Objects; @@ -31,6 +33,7 @@ import com.diffplug.spotless.FormatterFunc; import com.diffplug.spotless.FormatterStep; import com.diffplug.spotless.JarState; +import com.diffplug.spotless.Jvm; import com.diffplug.spotless.Provisioner; import com.diffplug.spotless.ThrowingEx.Supplier; @@ -42,6 +45,10 @@ private FreshMarkStep() {} private static final String DEFAULT_VERSION = "1.3.1"; private static final String NAME = "freshmark"; private static final String MAVEN_COORDINATE = "com.diffplug.freshmark:freshmark:"; + + private static final String NASHORN_MAVEN_COORDINATE = "org.openjdk.nashorn:nashorn-core:"; + + private static final String NASHORN_VERSION = "15.4"; private static final String FORMATTER_CLASS = "com.diffplug.freshmark.FreshMark"; private static final String FORMATTER_METHOD = "compile"; @@ -55,8 +62,15 @@ public static FormatterStep create(String version, Supplier> prop Objects.requireNonNull(version, "version"); Objects.requireNonNull(properties, "properties"); Objects.requireNonNull(provisioner, "provisioner"); + + List mavenCoordinates = new ArrayList<>(); + mavenCoordinates.add(MAVEN_COORDINATE + version); + if (Jvm.version() >= 15) { + mavenCoordinates.add(NASHORN_MAVEN_COORDINATE + NASHORN_VERSION); + } + return FormatterStep.createLazy(NAME, - () -> new State(JarState.from(MAVEN_COORDINATE + version, provisioner), properties.get()), + () -> new State(JarState.from(mavenCoordinates, provisioner), properties.get()), State::createFormat); } diff --git a/testlib/src/test/java/com/diffplug/spotless/markdown/FreshMarkStepTest.java b/testlib/src/test/java/com/diffplug/spotless/markdown/FreshMarkStepTest.java index 477642e247..a5fede28bc 100644 --- a/testlib/src/test/java/com/diffplug/spotless/markdown/FreshMarkStepTest.java +++ b/testlib/src/test/java/com/diffplug/spotless/markdown/FreshMarkStepTest.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. @@ -15,20 +15,16 @@ */ package com.diffplug.spotless.markdown; -import static org.junit.jupiter.api.condition.JRE.JAVA_14; - import java.util.HashMap; import java.util.Map; import org.junit.jupiter.api.Test; -import org.junit.jupiter.api.condition.EnabledForJreRange; import com.diffplug.spotless.FormatterStep; import com.diffplug.spotless.SerializableEqualityTester; import com.diffplug.spotless.StepHarness; import com.diffplug.spotless.TestProvisioner; -@EnabledForJreRange(max = JAVA_14) class FreshMarkStepTest { @Test void behavior() throws Exception { From 6abbc8adf4bd4644260fab7e9436619ab19e408b Mon Sep 17 00:00:00 2001 From: "renovate[bot]" <29139614+renovate[bot]@users.noreply.github.com> Date: Sun, 11 Sep 2022 01:37:09 +0000 Subject: [PATCH 279/757] Update dependency gradle to v7.5.1 --- gradle/wrapper/gradle-wrapper.jar | Bin 59536 -> 60756 bytes gradle/wrapper/gradle-wrapper.properties | 2 +- gradlew | 6 ++++++ gradlew.bat | 14 ++++++++------ 4 files changed, 15 insertions(+), 7 deletions(-) diff --git a/gradle/wrapper/gradle-wrapper.jar b/gradle/wrapper/gradle-wrapper.jar index 7454180f2ae8848c63b8b4dea2cb829da983f2fa..249e5832f090a2944b7473328c07c9755baa3196 100755 GIT binary patch delta 10158 zcmaKSbyOWsmn~e}-QC?axCPf>!2<-jxI0|j{UX8L-QC?axDz};a7}ppGBe+Nv*x{5 zy?WI?=j^WT(_Md5*V*xNP>X9&wM>xUvNiMuKDK=Xg!N%oM>Yru2rh7#yD-sW0Ov#$ zCKBSOD3>TM%&1T5t&#FK@|@1f)Ze+EE6(7`}J(Ek4})CD@I+W;L{ zO>K;wokKMA)EC6C|D@nz%D2L3U=Nm(qc>e4GM3WsHGu-T?l^PV6m-T-(igun?PZ8U z{qbiLDMcGSF1`FiKhlsV@qPMRm~h9@z3DZmWp;Suh%5BdP6jqHn}$-gu`_xNg|j{PSJ0n$ zbE;Azwq8z6IBlgKIEKc4V?*##hGW#t*rh=f<;~RFWotXS$vr;Mqz>A99PMH3N5BMi zWLNRjc57*z`2)gBV0o4rcGM(u*EG8_H5(|kThAnp|}u2xz>>X6tN zv)$|P2Nr1D*fk4wvqf(7;NmdRV3eL{!>DO-B98(s*-4$g{)EnRYAw+DP-C`=k)B!* zHU7!ejcbavGCYuz9k@$aZQaU%#K%6`D}=N_m?~^)IcmQZun+K)fSIoS>Ws zwvZ%Rfmw>%c!kCd~Pmf$E%LCj2r>+FzKGDm+%u88|hHprot{*OIVpi`Vd^^aumtx2L}h} zPu$v~zdHaWPF<`LVQX4i7bk82h#RwRyORx*z3I}o&>>eBDCif%s7&*vF6kU%1` zf(bvILch^~>cQ{=Y#?nx(8C-Uuv7!2_YeCfo?zkP;FK zX+KdjKS;HQ+7 zj>MCBI=d$~9KDJ1I2sb_3=T6D+Mu9{O&vcTnDA(I#<=L8csjEqsOe=&`=QBc7~>u2 zfdcO44PUOST%PcN+8PzKFYoR0;KJ$-Nwu#MgSM{_!?r&%rVM}acp>53if|vpH)q=O z;6uAi__am8g$EjZ33?PmCrg@(M!V_@(^+#wAWNu&e3*pGlfhF2<3NobAC zlusz>wMV--3ytd@S047g)-J@eOD;DMnC~@zvS=Gnw3=LnRzkeV`LH4#JGPklE4!Q3 zq&;|yGR0FiuE-|&1p2g{MG!Z3)oO9Jf4@0h*3!+RHv=SiEf*oGQCSRQf=LqT5~sajcJ8XjE>E*@q$n z!4|Rz%Lv8TgI23JV6%)N&`Otk6&RBdS|lCe7+#yAfdyEWNTfFb&*S6-;Q}d`de!}*3vM(z71&3 z37B%@GWjeQ_$lr%`m-8B&Zl4Gv^X{+N{GCsQGr!LLU4SHmLt3{B*z-HP{73G8u>nK zHxNQ4eduv>lARQfULUtIlLx#7ea+O;w?LH}FF28c9pg#*M`pB~{jQmPB*gA;Hik#e zZpz&X#O}}r#O_#oSr4f`zN^wedt>ST791bAZ5(=g<Oj)m9X8J^>Th}fznPY0T zsD9ayM7Hrlb6?jHXL<{kdA*Q#UPCYce0p`fHxoZ7_P`cF-$1YY9Pi;0QFt{CCf%C# zuF60A_NTstTQeFR3)O*ThlWKk08}7Nshh}J-sGY=gzE!?(_ZI4ovF6oZ$)&Zt~WZi z_0@Bk!~R4+<&b6CjI{nGj+P{*+9}6;{RwZ7^?H)xjhiRi;?A|wb0UxjPr?L@$^v|0= z@6d3+eU|&re3+G*XgFS}tih3;>2-R1x>`2hmUb5+Z~eM4P|$ zAxvE$l@sIhf_#YLnF|Wcfp(Gh@@dJ-yh|FhKqsyQp_>7j1)w|~5OKETx2P$~`}5huK;{gw_~HXP6=RsG)FKSZ=VYkt+0z&D zr?`R3bqVV?Zmqj&PQ`G3b^PIrd{_K|Hhqt zAUS#|*WpEOeZ{@h*j6%wYsrL`oHNV=z*^}yT1NCTgk1-Gl(&+TqZhODTKb9|0$3;| z;{UUq7X9Oz`*gwbi|?&USWH?Fr;6=@Be4w=8zu>DLUsrwf+7A`)lpdGykP`^SA8{ok{KE3sM$N@l}kB2GDe7MEN? zWcQ2I0fJ1ZK%s-YKk?QbEBO6`C{bg$%le0FTgfmSan-Kih0A7)rGy|2gd)_gRH7qp z*bNlP0u|S^5<)kFcd&wQg*6QP5;y(3ZgI%vUgWk#`g!sMf`02>@xz{Ie9_-fXllyw zh>P%cK+-HkQ;D$Jh=ig(ASN^zJ7|q*#m;}2M*T#s0a^nF_>jI(L(|*}#|$O&B^t!W zv-^-vP)kuu+b%(o3j)B@do)n*Y0x%YNy`sYj*-z2ncYoggD6l z6{1LndTQUh+GCX;7rCrT z@=vy&^1zyl{#7vRPv;R^PZPaIks8okq)To8!Cks0&`Y^Xy5iOWC+MmCg0Jl?1ufXO zaK8Q5IO~J&E|<;MnF_oXLc=LU#m{6yeomA^Ood;)fEqGPeD|fJiz(`OHF_f*{oWJq z1_$NF&Mo7@GKae#f4AD|KIkGVi~ubOj1C>>WCpQq>MeDTR_2xL01^+K1+ zr$}J>d=fW{65hi2bz&zqRKs8zpDln z*7+Gtfz6rkgfj~#{MB=49FRP;ge*e0=x#czw5N{@T1{EAl;G&@tpS!+&2&Stf<%<+55R18u2%+}`?PZo8xg|Y9Xli(fSQyC7 z+O5{;ZyW$!eYR~gy>;l6cA+e`oXN6a6t(&kUkWus*Kf<m$W7L)w5uXYF)->OeWMSUVXi;N#sY zvz4c?GkBU{D;FaQ)9|HU7$?BX8DFH%hC11a@6s4lI}y{XrB~jd{w1x&6bD?gemdlV z-+ZnCcldFanu`P=S0S7XzwXO(7N9KV?AkgZzm|J&f{l-Dp<)|-S7?*@HBIfRxmo1% zcB4`;Al{w-OFD08g=Qochf9=gb56_FPc{C9N5UAjTcJ(`$>)wVhW=A<8i#!bmKD#6~wMBak^2(p56d2vs&O6s4>#NB0UVr24K z%cw|-Yv}g5`_zcEqrZBaRSoBm;BuXJM^+W$yUVS9?u(`87t)IokPgC_bQ3g_#@0Yg zywb?u{Di7zd3XQ$y!m^c`6~t-7@g-hwnTppbOXckS-^N?w1`kRMpC!mfMY?K#^Ldm zYL>771%d{+iqh4a&4RdLNt3_(^^*{U2!A>u^b{7e@}Azd_PiZ>d~(@(Q@EYElLAx3LgQ5(ZUf*I%EbGiBTG!g#=t zXbmPhWH`*B;aZI)$+PWX+W)z?3kTOi{2UY9*b9bpSU!GWcVu+)!^b4MJhf=U9c?jj z%V)EOF8X3qC5~+!Pmmmd@gXzbycd5Jdn!N#i^50a$4u}8^O}DG2$w-U|8QkR-WU1mk4pF z#_imS#~c2~Z{>!oE?wfYc+T+g=eJL`{bL6=Gf_lat2s=|RxgP!e#L|6XA8w{#(Po(xk1~rNQ4UiG``U`eKy7`ot;xv4 zdv54BHMXIq;#^B%W(b8xt%JRueW5PZsB2eW=s3k^Pe1C$-NN8~UA~)=Oy->22yJ%e zu=(XD^5s{MkmWB)AF_qCFf&SDH%ytqpt-jgs35XK8Ez5FUj?uD3++@2%*9+-65LGQ zvu1eopeQoFW98@kzU{+He9$Yj#`vaQkqu%?1wCoBd%G=)TROYl2trZa{AZ@#^LARR zdzg-?EUnt9dK2;W=zCcVj18RTj-%w^#pREbgpD0aL@_v-XV2&Cd@JB^(}GRBU}9gV z6sWmVZmFZ9qrBN%4b?seOcOdOZ+6cx8-#R(+LYKJu~Y%pF5#85aF9$MnP7r^Bu%D? zT{b-KBujiy>7_*9{8u0|mTJ(atnnnS%qBDM_Gx5>3V+2~Wt=EeT4cXOdud$+weM(>wdBg+cV$}6%(ccP;`!~CzW{0O2aLY z?rQtBB6`ZztPP@_&`kzDzxc==?a{PUPUbbX31Vy?_(;c+>3q*!df!K(LQYZNrZ>$A*8<4M%e8vj1`%(x9)d~);ym4p zoo518$>9Pe| zZaFGj);h?khh*kgUI-Xvj+Dr#r&~FhU=eQ--$ZcOY9;x%&3U(&)q}eJs=)K5kUgi5 zNaI-m&4?wlwFO^`5l-B?17w4RFk(IKy5fpS0K%txp0qOj$e=+1EUJbLd-u>TYNna~ z+m?gU0~xlcnP>J>%m_y_*7hVMj3d&)2xV8>F%J;6ncm)ILGzF2sPAV|uYk5!-F%jL(53^51BKr zc3g7+v^w<4WIhk7a#{N6Ku_u{F`eo;X+u!C(lIaiY#*V5!sMed39%-AgV*`(nI)Im zemHE^2foBMPyIP<*yuD21{6I?Co?_{pqp-*#N6sZRQAzEBV4HQheOyZT5UBd)>G85 zw^xHvCEP4AJk<{v2kQQ;g;C)rCY=X!c8rNpNJ4mHETN}t1rwSe7=s8u&LzW-+6AEB z)LX0o7`EqC94HM{4p}d2wOwj2EB|O;?&^FeG9ZrT%c!J&x`Z3D2!cm(UZbFBb`+h ztfhjq75yuSn2~|Pc)p$Ul6=)}7cfXtBsvc15f&(K{jnEsw5Gh0GM^O=JC+X-~@r1kI$=FH=yBzsO#PxR1xU9+T{KuPx7sMe~GX zSP>AT3%(Xs@Ez**e@GAn{-GvB^oa6}5^2s+Mg~Gw?#$u&ZP;u~mP|FXsVtr>3k9O?%v>`Ha-3QsOG<7KdXlqKrsN25R|K<<;- z8kFY!&J&Yrqx3ptevOHiqPxKo_wwAPD)$DWMz{0>{T5qM%>rMqGZ!dJdK(&tP1#89 zVcu}I1I-&3%nMyF62m%MDpl~p)PM(%YoR zD)=W)E7kjwzAr!?^P*`?=fMHd1q4yjLGTTRUidem^Ocjrfgk2Jp|6SabEVHKC3c>RX@tNx=&Z7gC z0ztZoZx+#o36xH8mv6;^e{vU;G{JW17kn(RO&0L%q^fpWSYSkr1Cb92@bV->VO5P z;=V{hS5wcROQfbah6ND{2a$zFnj>@yuOcw}X~E20g7)5=Z#(y)RC878{_rObmGQ;9 zUy>&`YT^2R@jqR1z9Fx&x)WBstIE#*UhAa>WrMm<10={@$UN@Cog+#pxq{W@l0DOf zJGs^Jv?t8HgIXk(;NFHXun$J{{p})cJ^BWn4BeQo6dMNp%JO@$9z{(}qqEHuZOUQP zZiwo70Oa@lMYL(W*R4(!oj`)9kRggJns-A|w+XL=P07>QBMTEbG^gPS)H zu^@MFTFZtsKGFHgj|hupbK({r>PX3_kc@|4Jdqr@gyyKrHw8Tu<#0&32Hh?S zsVm_kQ2K`4+=gjw1mVhdOz7dI7V!Iu8J1LgI+_rF`Wgx5-XwU~$h>b$%#$U3wWC-ea0P(At2SjPAm57kd;!W5k{do1}X681o}`!c*(w!kCjtGTh7`=!M)$9 zWjTns{<-WX+Xi;&d!lyV&1KT9dKL??8)fu2(?Ox<^?EAzt_(#5bp4wAfgIADYgLU` z;J7f8g%-tfmTI1ZHjgufKcAT4SO(vx?xSo4pdWh`3#Yk;DqPGQE0GD?!_CfXb(E8WoJt6*Yutnkvmb?7H9B zVICAYowwxK;VM4(#~|}~Ooyzm*1ddU_Yg%Ax*_FcZm^AzYc$<+9bv;Eucr(SSF}*JsjTfb*DY>qmmkt z;dRkB#~SylP~Jcmr&Bl9TxHf^DcGUelG%rA{&s)5*$|-ww}Kwx-lWnNeghVm@z zqi3@-oJnN%r2O4t9`5I5Zfc;^ROHmY6C9 z1VRRX*1+aBlbO_p>B+50f1p&%?_A*16R0n+l}HKWI$yIH3oq2`k4O?tEVd~a4~>iI zo{d}b8tr+$q<%%K%Ett*i|RAJEMnk9hU7LtL!lxOB45xO1g)ycDBd=NbpaE3j?Gw& z0M&xx13EkCgNHu%Z8rBLo93XH-zQUfF3{Iy>65-KSPniqIzF+?x$3>`L?oBOBeEsv zs_y7@7>IbS&w2Vju^#vBpPWQuUv=dDRGm(-MH|l+8T?vfgD;{nE_*-h?@D;GN>4hA z9{!G@ANfHZOxMq5kkoh4h*p3+zE7z$13ocDJR$XA*7uKtG5Cn_-ibn%2h{ z;J0m5aCjg(@_!G>i2FDAvcn5-Aby8b;J0u%u)!`PK#%0FS-C3(cq9J{V`DJEbbE|| zYpTDd+ulcjEd5`&v!?=hVgz&S0|C^We?2|>9|2T6?~nn^_CpLn&kuI|VG7_E{Ofu9 zAqe0Reuq5Zunlx@zyTqEL+ssT15X|Z0LUfZAr-i$1_SJ{j}BHmBm}s8{OgK3lm%4F zzC%jz!y!8WUJo2FLkU(mVh7-uzC+gcbkV^bM}&Y6=HTTca{!7ZSoB!)l|v<(3ly!jq&P5A2q(U5~h)))aj-`-6&aM~LBySnAy zA0{Z{FHiUb8rW|Yo%kQwi`Kh>EEE$0g7UxeeeVkcY%~87yCmSjYyxoqq(%Jib*lH; zz`t5y094U`k_o{-*U^dFH~+1I@GsgwqmGsQC9-Vr0X94TLhlV;Kt#`9h-N?oKHqpx zzVAOxltd%gzb_Qu{NHnE8vPp=G$#S)Y%&6drobF_#NeY%VLzeod delta 9041 zcmY*t@kVBCBP!g$Qih>$!M(|j-I?-C8+=cK0w!?cVWy9LXH zd%I}(h%K_>9Qvap&`U=={XcolW-VA%#t9ljo~WmY8+Eb|zcKX3eyx7qiuU|a)zU5cYm5{k5IAa3ibZf_B&=YT!-XyLap%QRdebT+PIcg$KjM3HqA3uZ5|yBj2vv8$L{#$>P=xi+J&zLILkooDarGpiupEiuy`9uy&>yEr95d)64m+~`y*NClGrY|5MLlv!)d5$QEtqW)BeBhrd)W5g1{S@J-t8_J1 zthp@?CJY}$LmSecnf3aicXde(pXfeCei4=~ZN=7VoeU|rEEIW^!UBtxGc6W$x6;0fjRs7Nn)*b9JW5*9uVAwi) zj&N7W;i<Qy80(5gsyEIEQm>_+4@4Ol)F?0{YzD(6V~e=zXmc2+R~P~< zuz5pju;(akH2+w5w!vnpoikD5_{L<6T`uCCi@_Uorr`L(8zh~x!yEK*!LN02Q1Iri z>v*dEX<(+_;6ZAOIzxm@PbfY4a>ws4D82&_{9UHCfll!x`6o8*i0ZB+B#Ziv%RgtG z*S}<4!&COp)*ZMmXzl0A8mWA$)fCEzk$Wex*YdB}_-v|k9>jKy^Y>3me;{{|Ab~AL zQC(naNU=JtU3aP6P>Fm-!_k1XbhdS0t~?uJ$ZvLbvow10>nh*%_Kh>7AD#IflU8SL zMRF1fmMX#v8m=MGGb7y5r!Qf~Y}vBW}fsG<{1CHX7Yz z=w*V9(vOs6eO>CDuhurDTf3DVVF^j~rqP*7S-$MLSW7Ab>8H-80ly;9Q0BWoNV zz8Wr2CdK!rW0`sMD&y{Ue{`mEkXm0%S2k;J^iMe|sV5xQbt$ojzfQE+6aM9LWH`t& z8B;Ig7S<1Dwq`3W*w59L(opjq)ll4E-c?MivCh!4>$0^*=DKI&T2&j?;Z82_iZV$H zKmK7tEs7;MI-Vo(9wc1b)kc(t(Yk? z#Hgo8PG_jlF1^|6ge%;(MG~6fuKDFFd&}>BlhBTh&mmuKsn>2buYS=<5BWw^`ncCb zrCRWR5`IwKC@URU8^aOJjSrhvO>s}O&RBD8&V=Fk2@~zYY?$qO&!9%s>YecVY0zhK zBxKGTTyJ(uF`p27CqwPU1y7*)r}y;{|0FUO)-8dKT^>=LUoU_6P^^utg|* zuj}LBA*gS?4EeEdy$bn#FGex)`#y|vg77NVEjTUn8%t z@l|7T({SM!y$PZy9lb2N;BaF}MfGM%rZk10aqvUF`CDaC)&Av|eED$x_;qSoAka*2 z2rR+OTZTAPBx`vQ{;Z{B4Ad}}qOBqg>P4xf%ta|}9kJ2$od>@gyC6Bf&DUE>sqqBT zYA>(sA=Scl2C_EF8)9d8xwdBSnH5uL=I4hch6KCHj-{99IywUD{HR`d(vk@Kvl)WD zXC(v{ZTsyLy{rio*6Wi6Lck%L(7T~Is-F_`2R}q z!H1ylg_)Mv&_|b1{tVl!t{;PDa!0v6^Zqs_`RdxI%@vR)n|`i`7O<>CIMzqI00y{;` zhoMyy>1}>?kAk~ND6}`qlUR=B+a&bvA)BWf%`@N)gt@@Ji2`p1GzRGC$r1<2KBO3N z++YMLD9c|bxC;za_UVJ*r6&Ea;_YC>-Ebe-H=VAgDmx+?Q=DxCE4=yQXrn z7(0X#oIjyfZUd}fv2$;4?8y|0!L^ep_rMz|1gU-hcgVYIlI~o>o$K&)$rwo(KJO~R zDcGKo-@im7C<&2$6+q-xtxlR`I4vL|wFd<`a|T}*Nt;(~Vwx&2QG_j$r0DktR+6I4W)gUx*cDVBwGe00aa803ZYiwy;d{1p)y0?*IT8ddPS`E~MiS z1d%Vm0Hb4LN2*f8FZ|6xRQev@ZK-?(oPs+mT*{%NqhGL_0dJ$?rAxA{2 z`r3MBv&)xblcd>@hArncJpL~C(_HTo&D&CS!_J5Giz$^2EfR_)xjgPg`Bq^u%1C*+ z7W*HGp|{B?dOM}|E)Cs$61y8>&-rHBw;A8 zgkWw}r$nT%t(1^GLeAVyj1l@)6UkHdM!%LJg|0%BO74M593&LlrksrgoO{iEz$}HK z4V>WXgk|7Ya!Vgm#WO^ZLtVjxwZ&k5wT6RteViH3ds{VO+2xMJZ`hToOz~_+hRfY{ z%M;ZDKRNTsK5#h6goUF(h#VXSB|7byWWle*d0$IHP+FA`y)Q^5W!|&N$ndaHexdTn z{vf?T$(9b&tI&O`^+IqpCheAFth;KY(kSl2su_9|Y1B{o9`mm)z^E`Bqw!n+JCRO) zGbIpJ@spvz=*Jki{wufWm|m`)XmDsxvbJR5dLF=kuf_C>dl}{nGO(g4I$8 zSSW#5$?vqUDZHe_%`Zm?Amd^>I4SkBvy+i}wiQYBxj0F1a$*%T+6}Yz?lX&iQ}zaU zI@%8cwVGtF3!Ke3De$dL5^j-$Bh3+By zrSR3c2a>XtaE#TB}^#hq@!vnZ1(An#bk_eKR{?;Z&0cgh4$cMNU2HL=m=YjMTI zT$BRltXs4T=im;Ao+$Bk3Dz(3!C;rTqelJ?RF)d~dP9>$_6dbz=_8#MQFMMX0S$waWxY#mtDn}1U{4PGeRH5?a>{>TU@1UlucMAmzrd@PCwr|il)m1fooO7Z{Vyr z6wn=2A5z(9g9-OU10X_ei50@~)$}w4u)b+mt)z-sz0X32m}NKTt4>!O{^4wA(|3A8 zkr(DxtMnl$Hol>~XNUE?h9;*pGG&kl*q_pb z&*$lH70zI=D^s)fU~A7cg4^tUF6*Oa+3W0=7FFB*bf$Kbqw1&amO50YeZM)SDScqy zTw$-M$NA<_We!@4!|-?V3CEPnfN4t}AeM9W$iSWYz8f;5H)V$pRjMhRV@Z&jDz#FF zXyWh7UiIc7=0U9L35=$G54RjAupR&4j`(O3i?qjOk6gb!WjNtl1Fj-VmltDTos-Bl z*OLfOleS~o3`?l!jTYIG!V7?c<;Xu(&#~xf-f(-jwow-0Hv7JZG>}YKvB=rRbdMyv zmao*-!L?)##-S#V^}oRm7^Db zT5C2RFY4>ov~?w!3l_H}t=#X=vY-*LQy(w>u%r`zQ`_RukSqIv@WyGXa-ppbk-X=g zyn?TH(`-m*in(w=Ny$%dHNSVxsL|_+X=+kM+v_w{ZC(okof9k1RP5qDvcA-d&u{5U z?)a9LXht1f6|Tdy5FgXo;sqR|CKxDKruU9RjK~P6xN+4;0eAc|^x%UO^&NM4!nK_! z6X14Zkk=5tqpl&d6FYuMmlLGQZep0UE3`fT>xzgH>C*hQ2VzCQlO`^kThU6q%3&K^ zf^kfQm|7SeU#c%f8e?A<9mALLJ-;)p_bv6$pp~49_o;>Y=GyUQ)*prjFbkU;z%HkOW_*a#j^0b@GF|`6c}7>=W{Ef!#dz5lpkN>@IH+(sx~QMEFe4 z1GeKK67;&P%ExtO>}^JxBeHii)ykX8W@aWhJO!H(w)DH4sPatQ$F-Phiqx_clj`9m zK;z7X6gD2)8kG^aTr|oY>vmgOPQ4`_W+xj2j!$YT9x(DH6pF~ zd_C#8c>Gfb)k2Ku4~t=Xb>T^8KW;2HPN#%}@@hC1lNf~Xk)~oj=w-Y11a@DtIyYk8 z9^|_RIAA(1qUSs3rowxr&OuRVFL8(zSqU_rGlqHpkeYT4z7DGdS0q4V-b!3fsv$Yb zPq4UP^3XFd(G%JAN|0y>?&sLzNir30K(lyzNYvCtE2gDyy-nthPlrXXU75fhoS7kA zg%GYyBEFQ(xgdjtv+>?>Q!G!8& z3+F>)4|N+F1a^T?XC8 zxRRx7-{DV%uUYt&*$z2uQTbZDbUn)PozID*(i^{JDjNq`v?;&OW^&~{ZPE_e+?RMk z!7O5CUKJSnGZvjTbLX2$zwYRZs_$f{T!hvVHuTg77|O;zBHlA|GIUu_bh4`Bl?7KE zYB~a`b?O;0SfD?0EZiPYpVf=P4=|zr(u_w}oP0S`YOZziX9cuwpll&%QMv4bBC_JdP#rT3>MliqySv0& zh)r=vw?no&;5T}QVTkHKY%t`%{#*#J;aw!wPs}?q2$(e0Y#cdBG1T09ypI@#-y24+fzhJem1NSZ$TCAjU2|ebYG&&6p(0f>wQoNqVa#6J^W!3$gIWEw7d<^k!U~O5v=8goq$jC`p8CS zrox#Jw3w`k&Ty7UVbm35nZ}FYT5`fN)TO6R`tEUFotxr^BTXZGt|n(Ymqmr^pCu^^w?uX!ONbm?q{y9FehdmcJuV8V%A-ma zgl=n9+op{wkj-}N;6t;(JA1A#VF3S9AFh6EXRa0~7qop~3^~t1>hc6rdS_4!+D?Xh z5y?j}*p@*-pmlTb#7C0x{E(E@%eepK_YycNkhrYH^0m)YR&gRuQi4ZqJNv6Rih0zQ zqjMuSng>Ps;?M0YVyh<;D3~;60;>exDe)Vq3x@GRf!$wgFY5w4=Jo=g*E{76%~jqr zxTtb_L4Cz_E4RTfm@0eXfr1%ho?zP(>dsRarS>!^uAh~bd0lEhe2x7AEZQmBc%rU; z&FUrs&mIt8DL`L4JpiFp3NNyk3N>iL6;Nohp*XbZZn%BDhF_y{&{X3UtX(7aAyG63P zELC;>2L`jnFS#vC->A(hZ!tGi7N7^YtW7-LB6!SVdEM&7N?g}r4rW2wLn{Ni*I~$Y z@#;KwJIl0^?eX{JWiHQxDvccnNKBhHW0h6`j=)OH1`)7)69B$XNT@)l1s25M+~o2_ zpa&X<_vHxN_oR|B#ir2p*VNB~o6Z1OE&~a+_|AxS)(@Dgznq(b(|K8BN_nQ7+>N`= zXOx_@AhcmmcRvp6eX#4z6sn=V0%KonKFVY@+m&)Rx!Z5U@WdyHMCF4_qzJNpzc9Fw z7Bdzx54(e7>wcEqHKqH-Paiut;~ZVJpS6_q>ub)zD#TQ4j*i(I8DvS$BfyX~A%<#} z*=g2$8s;YYjEHl`7cKw!a9PFRt8tVR zM&X|bs?B1#ycjl>AzgbdRkr-@NmBc^ys)aoT75F(yweV&Y-3hNNXj-valA&=)G{NL zX?smr5sQWi3n;GGPW{%vW)xw-#D0QY%zjXxYj?($b4JzpW0sWY!fkwC5bJMkhTp$J z6CNVLd=-Ktt7D<^-f|=wjNjf0l%@iu2dR+zdQ&9NLa(B_okKdRy^!Q!F$Ro=hF$-r z!3@ocUs^7?cvdTMPbn*8S-o!PsF;>FcBkBkg&ET`W`lp?j`Z}4>DF|}9407lK9y~^No&pT7J|rVQ9Dh>qg|%=gxxg=! z>WX$!;7s~gDPmPF<--(?CvEnvV*E1KdXpr>XVv!DN~PyISE7d+K_9+W^pnR6cX&?E ziLr{0`JIs@NcA|;8L|p!3H~9y8mga2Dsm4I?rBS7$3wcT!_l*$^8U3hKUri|_I3N2 zz$xY`)IWA7P*Y1BJtyBEh?8EEvs8Oyl^{(+`gi{9hwpcN#I%Z0j$^yBp?z<;Ny!G$ zra3J_^i0(~LiKuITs%v)qE+YrJr?~w+)`Rcte^O=nwmPg@&!Q7FGTtjpTdI6wH&ZV z)2}VZY6(MbP`tgoew++(pt$jVj- zvPK)pSJ)U(XfUqBqZNo|za#Xx+IVEb?HGQ^wUVH&wTdWgP(z#ijyvXjwk>tFBUn*2 zuj5ENQjT{2&T`k;q54*Z>O~djuUBNwc6l(BzY?Ed4SIt9QA&8+>qaRIck?WdD0rh@ zh`VTZPwSNNCcLH3J}(q zdEtu@HfxDTpEqWruG=86m;QVO{}E&q8qYWhmA>(FjW`V&rg!CEL1oZCZcAX@yX(2tg8`>m1psG0ZpO+Rnph@Bhjj!~|+S=@+U{*ukwGrBj{5xfIHHP7|} z^7@g2;d%FMO8f(MS&6c##mrX2i(5uiX1o(=Vw89IQcHw)n{ZTS@``xT$Af@CQTP#w zl3kn6+MJP+l(;K-rWgjpdBU|CB4>W%cObZBH^Am~EvRO%D>uU^HVRXi$1 zb?Pr~ZlopLfT5l%03SjI7>YiGZZs=n(A!c;N9%%aByY~5(-hS4z_i2wgKYsG%OhhxH#^5i%&9ESb(@# zV_f5${Gf=$BK)1VY=NX#f+M}6f`OWmpC*OU3&+P@n>$Xvco*Nm$c<=`S|lY6S}Ut- z80}ztIpkV>W%^Ox`enpk<25_i7`RPiDugxHfUDBD8$bp9XR15>a?r^#&!1Ne6n{MI z){H`!jwrx}8b-w@@E8H0v)l!5!W8En=u67v+`iNoz<_h4{V*qQK+@)JP^JqsKAedZ zNh4toE+I7;^}7kkj|hzNVFWkZ$N9rxPl9|_@2kbW*4}&o%(L`WpQCN2M?gz>cyWHk zulMwRxpdpx+~P(({@%UY20LwM7sA&1M|`bEoq)Id zyUHt>@vfu**UOL9wiW*C75cc&qBX37qLd`<;$gS+mvL^v3Z8i4p6(@Wv`N|U6Exn< zd`@WxqU^8u^Aw+uw#vuDEIByaD)vucU2{4xRseczf_TJXUwaUK+E_IoItXJq88${0 z=K5jGehPa2)CnH&Lcxv&1jQ=T8>*vgp1^%)c&C2TL69;vSN)Q)e#Hj7!oS0 zlrEmJ=w4N9pID5KEY5qz;?2Q}0|4ESEio&cLrp221LTt~j3KjUB`LU?tP=p;B=WSXo;C?8(pnF6@?-ZD0m3DYZ* z#SzaXh|)hmTC|zQOG>aEMw%4&2XU?prlk5(M3ay-YC^QLRMN+TIB*;TB=wL_atpeD zh-!sS%A`3 z=^?niQx+^za_wQd2hRR=hsR0uzUoyOcrY!z7W)G2|C-_gqc`wrG5qCuU!Z?g*GL^H z?j^<_-A6BC^Dp`p(i0!1&?U{YlF@!|W{E@h=qQ&5*|U~V8wS;m!RK(Q6aX~oH9ToE zZYKXZoRV~!?P1ADJ74J-PFk2A{e&gh2o)@yZOZuBi^0+Hkp`dX;cZs9CRM+##;P!*BlA%M48TuR zWUgfD1DLsLs+-4XC>o>wbv-B)!t*47ON5wgoMX%llnmXG%L8209Vi;yZ`+N2v2Ox+ zMe7JHunQE$ckHHhEYRA+e`A3=XO5L%fMau71`XL7v)b{f1rkTY+WWSIkH#sG=pLqe zA(xZIp>_=4$zKq0t_G7q9@L zZ5D-0{8o%7f>0szA#c;rjL;4Y%hl}wYrx1R`Viq|Pz}c-{{LJY070ym@E~mt*pTyG z79bfcWTGGEje;PLD;N-XHw=`wS^howfzb$%oP8n)lN$o$ZWjZx|6iSsi2piI_7s7z zX#b$@z6kIJ^9{-Y^~wJ!s0V^Td5V7#4&pyU#NHw#9)N&qbpNFDR1jqC00W}91OnnS z{$J@GBz%bka`xsz;rb_iJ|rgmpUVyEZ)Xi*SO5U&|NFkTHb3y@e@%{WrvE&Jp#Lw^ zcj13CbsW+V>i@rj@SEfFf0@yjS@nbPB0)6D`lA;e%61nh`-qhydO!uS7jXGQd%i7opEnOL;| zDn!3EUm(V796;f?fA+RDF<@%qKlo)`0VtL74`!~516_aogYP%QfG#<2kQ!pijthz2 zpaFX3|D$%C7!bL242U?-e@2QZ`q$~lgZbvgfLLyVfT1OC5<8@6lLi=A{stK#zJmWd zlx+(HbgX)l$RGwH|2rV@P3o@xCrxch0$*z1ASpy(n+d4d2XWd~2AYjQm`xZU3af8F p+x$Nxf1895@0bJirXkdpJh+N7@Nb7x007(DEB&^Lm}dWn{T~m64-^0Z diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index 8049c684f0..ae04661ee7 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -1,5 +1,5 @@ distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-7.5-bin.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-7.5.1-bin.zip zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists diff --git a/gradlew b/gradlew index 1b6c787337..a69d9cb6c2 100755 --- a/gradlew +++ b/gradlew @@ -205,6 +205,12 @@ set -- \ org.gradle.wrapper.GradleWrapperMain \ "$@" +# Stop when "xargs" is not available. +if ! command -v xargs >/dev/null 2>&1 +then + die "xargs is not available" +fi + # Use "xargs" to parse quoted args. # # With -n1 it outputs one arg per line, with the quotes and backslashes removed. diff --git a/gradlew.bat b/gradlew.bat index 107acd32c4..f127cfd49d 100644 --- a/gradlew.bat +++ b/gradlew.bat @@ -14,7 +14,7 @@ @rem limitations under the License. @rem -@if "%DEBUG%" == "" @echo off +@if "%DEBUG%"=="" @echo off @rem ########################################################################## @rem @rem Gradle startup script for Windows @@ -25,7 +25,7 @@ if "%OS%"=="Windows_NT" setlocal set DIRNAME=%~dp0 -if "%DIRNAME%" == "" set DIRNAME=. +if "%DIRNAME%"=="" set DIRNAME=. set APP_BASE_NAME=%~n0 set APP_HOME=%DIRNAME% @@ -40,7 +40,7 @@ if defined JAVA_HOME goto findJavaFromJavaHome set JAVA_EXE=java.exe %JAVA_EXE% -version >NUL 2>&1 -if "%ERRORLEVEL%" == "0" goto execute +if %ERRORLEVEL% equ 0 goto execute echo. echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. @@ -75,13 +75,15 @@ set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar :end @rem End local scope for the variables with windows NT shell -if "%ERRORLEVEL%"=="0" goto mainEnd +if %ERRORLEVEL% equ 0 goto mainEnd :fail rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of rem the _cmd.exe /c_ return code! -if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1 -exit /b 1 +set EXIT_CODE=%ERRORLEVEL% +if %EXIT_CODE% equ 0 set EXIT_CODE=1 +if not ""=="%GRADLE_EXIT_CONSOLE%" exit %EXIT_CODE% +exit /b %EXIT_CODE% :mainEnd if "%OS%"=="Windows_NT" endlocal From 3dfb10e8cd78e823695dd298b7e6981d921c2b84 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?David=20Burstr=C3=B6m?= Date: Mon, 29 Aug 2022 13:48:05 +0200 Subject: [PATCH 280/757] Add support for KtLint 0.47.x --- CHANGES.md | 1 + lib/build.gradle | 4 + .../compat/KtLintCompat0Dot47Dot0Adapter.java | 125 ++++++++++++++++++ plugin-gradle/CHANGES.md | 1 + plugin-maven/CHANGES.md | 1 + .../spotless/kotlin/KtLintStepTest.java | 26 ++++ 6 files changed, 158 insertions(+) create mode 100644 lib/src/compatKtLint0Dot47Dot0/java/com/diffplug/spotless/glue/ktlint/compat/KtLintCompat0Dot47Dot0Adapter.java diff --git a/CHANGES.md b/CHANGES.md index 01e68f430c..66679453dd 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -13,6 +13,7 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format ( ### Changes * Extend minimum supported version for `ktlint` to `0.31.0` ([#1303](https://github.com/diffplug/spotless/pull/1303)). +* Support `ktlint` version 0.47.x ([#1303](https://github.com/diffplug/spotless/pull/1303)) fixes [#1281](https://github.com/diffplug/spotless/issues/1281). ## [2.29.0] - 2022-08-23 ### Added diff --git a/lib/build.gradle b/lib/build.gradle index 1a5fbf9c64..5983e4479a 100644 --- a/lib/build.gradle +++ b/lib/build.gradle @@ -33,6 +33,7 @@ versionCompatibility { '0.34.2', '0.45.2', '0.46.0', + '0.47.0', ] targetSourceSetName = 'ktlint' } @@ -86,6 +87,9 @@ dependencies { compatKtLint0Dot46Dot0CompileOnly 'com.pinterest.ktlint:ktlint-core:0.46.0' compatKtLint0Dot46Dot0CompileOnly 'com.pinterest.ktlint:ktlint-ruleset-experimental:0.46.0' compatKtLint0Dot46Dot0CompileOnly 'com.pinterest.ktlint:ktlint-ruleset-standard:0.46.0' + compatKtLint0Dot47Dot0CompileOnly 'com.pinterest.ktlint:ktlint-core:0.47.0' + compatKtLint0Dot47Dot0CompileOnly 'com.pinterest.ktlint:ktlint-ruleset-experimental:0.47.0' + compatKtLint0Dot47Dot0CompileOnly 'com.pinterest.ktlint:ktlint-ruleset-standard:0.47.0' String VER_SCALAFMT="3.5.9" scalafmtCompileOnly "org.scalameta:scalafmt-core_2.13:$VER_SCALAFMT" diff --git a/lib/src/compatKtLint0Dot47Dot0/java/com/diffplug/spotless/glue/ktlint/compat/KtLintCompat0Dot47Dot0Adapter.java b/lib/src/compatKtLint0Dot47Dot0/java/com/diffplug/spotless/glue/ktlint/compat/KtLintCompat0Dot47Dot0Adapter.java new file mode 100644 index 0000000000..842294a5cc --- /dev/null +++ b/lib/src/compatKtLint0Dot47Dot0/java/com/diffplug/spotless/glue/ktlint/compat/KtLintCompat0Dot47Dot0Adapter.java @@ -0,0 +1,125 @@ +/* + * Copyright 2022 DiffPlug + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.diffplug.spotless.glue.ktlint.compat; + +import static java.util.Collections.emptySet; + +import java.util.LinkedHashSet; +import java.util.List; +import java.util.Map; +import java.util.Objects; +import java.util.Set; +import java.util.stream.Collectors; +import java.util.stream.Stream; + +import com.pinterest.ktlint.core.KtLint; +import com.pinterest.ktlint.core.LintError; +import com.pinterest.ktlint.core.Rule; +import com.pinterest.ktlint.core.RuleProvider; +import com.pinterest.ktlint.core.api.DefaultEditorConfigProperties; +import com.pinterest.ktlint.core.api.EditorConfigDefaults; +import com.pinterest.ktlint.core.api.EditorConfigOverride; +import com.pinterest.ktlint.core.api.UsesEditorConfigProperties; +import com.pinterest.ktlint.ruleset.experimental.ExperimentalRuleSetProvider; +import com.pinterest.ktlint.ruleset.standard.StandardRuleSetProvider; + +import kotlin.Pair; +import kotlin.Unit; +import kotlin.jvm.functions.Function2; + +public class KtLintCompat0Dot47Dot0Adapter implements KtLintCompatAdapter { + + static class FormatterCallback implements Function2 { + @Override + public Unit invoke(LintError lint, Boolean corrected) { + if (!corrected) { + KtLintCompatReporting.report(lint.getLine(), lint.getCol(), lint.getRuleId(), lint.getDetail()); + } + return null; + } + } + + @Override + public String format(final String text, final String name, final boolean isScript, + final boolean useExperimental, + final Map userData, + final Map editorConfigOverrideMap) { + final FormatterCallback formatterCallback = new FormatterCallback(); + + Set allRuleProviders = new LinkedHashSet<>( + new StandardRuleSetProvider().getRuleProviders()); + if (useExperimental) { + allRuleProviders.addAll(new ExperimentalRuleSetProvider().getRuleProviders()); + } + + EditorConfigOverride editorConfigOverride; + if (editorConfigOverrideMap.isEmpty()) { + editorConfigOverride = EditorConfigOverride.Companion.getEmptyEditorConfigOverride(); + } else { + editorConfigOverride = createEditorConfigOverride(allRuleProviders.stream().map( + RuleProvider::createNewRuleInstance).collect( + Collectors.toList()), + editorConfigOverrideMap); + } + + return KtLint.INSTANCE.format(new KtLint.ExperimentalParams( + name, + text, + emptySet(), + allRuleProviders, + userData, + formatterCallback, + isScript, + null, + false, + EditorConfigDefaults.Companion.getEmptyEditorConfigDefaults(), + editorConfigOverride, + false)); + } + + /** + * Create EditorConfigOverride from user provided parameters. + * Calling this method requires KtLint 0.45.2. + */ + private static EditorConfigOverride createEditorConfigOverride(final List rules, Map editorConfigOverrideMap) { + // Get properties from rules in the rule sets + Stream> ruleProperties = rules.stream() + .filter(rule -> rule instanceof UsesEditorConfigProperties) + .flatMap(rule -> ((UsesEditorConfigProperties) rule).getEditorConfigProperties().stream()); + + // Create a mapping of properties to their names based on rule properties and default properties + Map> supportedProperties = Stream + .concat(ruleProperties, DefaultEditorConfigProperties.INSTANCE.getEditorConfigProperties().stream()) + .distinct() + .collect(Collectors.toMap(property -> property.getType().getName(), property -> property)); + + // Create config properties based on provided property names and values + @SuppressWarnings("unchecked") + Pair, ?>[] properties = editorConfigOverrideMap.entrySet().stream() + .map(entry -> { + UsesEditorConfigProperties.EditorConfigProperty property = supportedProperties.get(entry.getKey()); + if (property != null) { + return new Pair<>(property, entry.getValue()); + } else { + return null; + } + }) + .filter(Objects::nonNull) + .toArray(Pair[]::new); + + return EditorConfigOverride.Companion.from(properties); + } +} diff --git a/plugin-gradle/CHANGES.md b/plugin-gradle/CHANGES.md index f1f1fd69e1..ef6a9c8988 100644 --- a/plugin-gradle/CHANGES.md +++ b/plugin-gradle/CHANGES.md @@ -6,6 +6,7 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format ( ### Changes * Extend minimum supported version for `ktlint` to `0.31.0` ([#1303](https://github.com/diffplug/spotless/pull/1303)). +* Support `ktlint` version 0.47.x ([#1303](https://github.com/diffplug/spotless/pull/1303)) fixes [#1281](https://github.com/diffplug/spotless/issues/1281). ## [6.10.0] - 2022-08-23 ### Added diff --git a/plugin-maven/CHANGES.md b/plugin-maven/CHANGES.md index f69b4a058e..d6b6a51bcb 100644 --- a/plugin-maven/CHANGES.md +++ b/plugin-maven/CHANGES.md @@ -6,6 +6,7 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format ( ### Changes * Extend minimum supported version for `ktlint` to `0.31.0` ([#1303](https://github.com/diffplug/spotless/pull/1303)). +* Support `ktlint` version 0.47.x ([#1303](https://github.com/diffplug/spotless/pull/1303)) fixes [#1281](https://github.com/diffplug/spotless/issues/1281). ## [2.25.0] - 2022-08-23 ### Added diff --git a/testlib/src/test/java/com/diffplug/spotless/kotlin/KtLintStepTest.java b/testlib/src/test/java/com/diffplug/spotless/kotlin/KtLintStepTest.java index 96c2ab885a..71a0979422 100644 --- a/testlib/src/test/java/com/diffplug/spotless/kotlin/KtLintStepTest.java +++ b/testlib/src/test/java/com/diffplug/spotless/kotlin/KtLintStepTest.java @@ -118,6 +118,32 @@ void works0_46_0() throws Exception { }); } + @Test + void works0_47_0() throws Exception { + FormatterStep step = KtLintStep.create("0.47.0", TestProvisioner.mavenCentral()); + StepHarness.forStep(step) + .testResource("kotlin/ktlint/basic.dirty", "kotlin/ktlint/basic.clean") + .testResourceException("kotlin/ktlint/unsolvable.dirty", assertion -> { + assertion.isInstanceOf(AssertionError.class); + assertion.hasMessage("Error on line: 1, column: 1\n" + + "rule: no-wildcard-imports\n" + + "Wildcard import"); + }); + } + + @Test + void works0_47_1() throws Exception { + FormatterStep step = KtLintStep.create("0.47.1", TestProvisioner.mavenCentral()); + StepHarness.forStep(step) + .testResource("kotlin/ktlint/basic.dirty", "kotlin/ktlint/basic.clean") + .testResourceException("kotlin/ktlint/unsolvable.dirty", assertion -> { + assertion.isInstanceOf(AssertionError.class); + assertion.hasMessage("Error on line: 1, column: 1\n" + + "rule: no-wildcard-imports\n" + + "Wildcard import"); + }); + } + @Test void equality() throws Exception { new SerializableEqualityTester() { From e63edb9e1b46e488e78468d700b1b48a193a9d79 Mon Sep 17 00:00:00 2001 From: "renovate[bot]" <29139614+renovate[bot]@users.noreply.github.com> Date: Tue, 13 Sep 2022 18:34:26 +0000 Subject: [PATCH 281/757] Update plugin com.github.spotbugs to v5.0.12 --- settings.gradle | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/settings.gradle b/settings.gradle index 83ed4aa59d..af76e2f368 100644 --- a/settings.gradle +++ b/settings.gradle @@ -6,7 +6,7 @@ pluginManagement { // https://github.com/gradle-nexus/publish-plugin/releases id 'io.github.gradle-nexus.publish-plugin' version '1.1.0' // https://github.com/spotbugs/spotbugs-gradle-plugin/releases - id 'com.github.spotbugs' version '5.0.10' + id 'com.github.spotbugs' version '5.0.12' // https://github.com/diffplug/spotless-changelog id 'com.diffplug.spotless-changelog' version '2.3.2' // https://github.com/diffplug/goomph/blob/main/CHANGES.md From 164b95fda2b9158676ac5b243037ee8ea79f77b4 Mon Sep 17 00:00:00 2001 From: "renovate[bot]" <29139614+renovate[bot]@users.noreply.github.com> Date: Tue, 13 Sep 2022 18:34:30 +0000 Subject: [PATCH 282/757] Update plugin org.gradle.test-retry to v1.4.1 --- settings.gradle | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/settings.gradle b/settings.gradle index 83ed4aa59d..40769b1f4d 100644 --- a/settings.gradle +++ b/settings.gradle @@ -12,7 +12,7 @@ pluginManagement { // https://github.com/diffplug/goomph/blob/main/CHANGES.md id 'com.diffplug.p2.asmaven' version '3.27.0' // DO NOT UPDATE, see https://github.com/diffplug/spotless/pull/874 // https://github.com/gradle/test-retry-gradle-plugin/releases - id 'org.gradle.test-retry' version '1.4.0' + id 'org.gradle.test-retry' version '1.4.1' // https://github.com/radarsh/gradle-test-logger-plugin/blob/develop/CHANGELOG.md id 'com.adarshr.test-logger' version '3.2.0' } From ef219c09a1d3a9119d393c9cd383892086aef83a Mon Sep 17 00:00:00 2001 From: Ned Twigg Date: Tue, 13 Sep 2022 17:10:27 -0700 Subject: [PATCH 283/757] Remove workarounds to #834 because they are no longer needed thanks to #1224 and #1228. --- plugin-gradle/README.md | 30 ------------------------------ plugin-maven/README.md | 22 ---------------------- 2 files changed, 52 deletions(-) diff --git a/plugin-gradle/README.md b/plugin-gradle/README.md index c1a41c2ef0..dc49c21a88 100644 --- a/plugin-gradle/README.md +++ b/plugin-gradle/README.md @@ -197,21 +197,6 @@ spotless { formatAnnotations() ``` -**⚠️ Note on using Google Java Format with Java 16+** - -Using Java 16+ with Google Java Format 1.10.0 [requires additional flags](https://github.com/google/google-java-format/releases/tag/v1.10.0) to the running JDK. -These Flags can be provided using the `gradle.properties` file (See [documentation](https://docs.gradle.org/current/userguide/build_environment.html)). - -For example the following file under `gradle.properties` will run gradle with the required flags: -``` -org.gradle.jvmargs=--add-exports jdk.compiler/com.sun.tools.javac.api=ALL-UNNAMED \ - --add-exports jdk.compiler/com.sun.tools.javac.file=ALL-UNNAMED \ - --add-exports jdk.compiler/com.sun.tools.javac.parser=ALL-UNNAMED \ - --add-exports jdk.compiler/com.sun.tools.javac.tree=ALL-UNNAMED \ - --add-exports jdk.compiler/com.sun.tools.javac.util=ALL-UNNAMED -``` -This is a workaround to a [pending issue](https://github.com/diffplug/spotless/issues/834). - ### palantir-java-format [homepage](https://github.com/palantir/palantir-java-format). [changelog](https://github.com/palantir/palantir-java-format/releases). @@ -225,21 +210,6 @@ spotless { formatAnnotations() ``` -**⚠️ Note on using Palantir Java Format with Java 16+** - -Using Java 16+ with Palantir Java Format [requires additional flags](https://github.com/google/google-java-format/releases/tag/v1.10.0) on the running JDK. -These Flags can be provided using the `gradle.properties` file (See [documentation](https://docs.gradle.org/current/userguide/build_environment.html)). - -For example the following file under `gradle.properties` will run gradle with the required flags: -``` -org.gradle.jvmargs=--add-exports jdk.compiler/com.sun.tools.javac.api=ALL-UNNAMED \ - --add-exports jdk.compiler/com.sun.tools.javac.file=ALL-UNNAMED \ - --add-exports jdk.compiler/com.sun.tools.javac.parser=ALL-UNNAMED \ - --add-exports jdk.compiler/com.sun.tools.javac.tree=ALL-UNNAMED \ - --add-exports jdk.compiler/com.sun.tools.javac.util=ALL-UNNAMED -``` -This is a workaround to a [pending issue](https://github.com/diffplug/spotless/issues/834). - ### eclipse jdt [homepage](https://www.eclipse.org/downloads/packages/). [compatible versions](https://github.com/diffplug/spotless/tree/main/lib-extra/src/main/resources/com/diffplug/spotless/extra/eclipse_jdt_formatter). See [here](../ECLIPSE_SCREENSHOTS.md) for screenshots that demonstrate how to get and install the config file mentioned below. diff --git a/plugin-maven/README.md b/plugin-maven/README.md index 3a112cd3b1..93175b9ed8 100644 --- a/plugin-maven/README.md +++ b/plugin-maven/README.md @@ -214,17 +214,6 @@ any other maven phase (i.e. compile) then it can be configured as below; ``` -**⚠️ Note on using Google Java Format with Java 16+** - -Using Java 16+ with Google Java Format 1.10.0 [requires additional flags](https://github.com/google/google-java-format/releases/tag/v1.10.0) to the running JDK. -These Flags can be provided using `MAVEN_OPTS` environment variable or using the `./mvn/jvm.config` file (See [documentation](https://maven.apache.org/configure.html#mvn-jvm-config-file)). - -For example the following file under `.mvn/jvm.config` will run maven with the required flags: -``` ---add-exports jdk.compiler/com.sun.tools.javac.api=ALL-UNNAMED --add-exports jdk.compiler/com.sun.tools.javac.file=ALL-UNNAMED --add-exports jdk.compiler/com.sun.tools.javac.parser=ALL-UNNAMED --add-exports jdk.compiler/com.sun.tools.javac.tree=ALL-UNNAMED --add-exports jdk.compiler/com.sun.tools.javac.util=ALL-UNNAMED -``` -This is a workaround to a [pending issue](https://github.com/diffplug/spotless/issues/834). - ### palantir-java-format [homepage](https://github.com/palantir/palantir-java-format). [changelog](https://github.com/palantir/palantir-java-format/releases). [code](https://github.com/diffplug/spotless/blob/main/plugin-maven/src/main/java/com/diffplug/spotless/maven/java/PalantirJavaFormat.java). @@ -235,17 +224,6 @@ This is a workaround to a [pending issue](https://github.com/diffplug/spotless/i ``` -**⚠️ Note on using Palantir Java Format with Java 16+** - -Using Java 16+ with Palantir Java Format [requires additional flags](https://github.com/google/google-java-format/releases/tag/v1.10.0) on the running JDK. -These Flags can be provided using `MAVEN_OPTS` environment variable or using the `./mvn/jvm.config` file (See [documentation](https://maven.apache.org/configure.html#mvn-jvm-config-file)). - -For example the following file under `.mvn/jvm.config` will run maven with the required flags: -``` ---add-exports jdk.compiler/com.sun.tools.javac.api=ALL-UNNAMED --add-exports jdk.compiler/com.sun.tools.javac.file=ALL-UNNAMED --add-exports jdk.compiler/com.sun.tools.javac.parser=ALL-UNNAMED --add-exports jdk.compiler/com.sun.tools.javac.tree=ALL-UNNAMED --add-exports jdk.compiler/com.sun.tools.javac.util=ALL-UNNAMED -``` -This is a workaround to a [pending issue](https://github.com/diffplug/spotless/issues/834). - ### eclipse jdt [homepage](https://www.eclipse.org/downloads/packages/). [compatible versions](https://github.com/diffplug/spotless/tree/main/lib-extra/src/main/resources/com/diffplug/spotless/extra/eclipse_jdt_formatter). [code](https://github.com/diffplug/spotless/blob/main/plugin-maven/src/main/java/com/diffplug/spotless/maven/java/Eclipse.java). See [here](../ECLIPSE_SCREENSHOTS.md) for screenshots that demonstrate how to get and install the config file mentioned below. From 61d362bf03f7e8e47d5fccf8602ddef253c9a314 Mon Sep 17 00:00:00 2001 From: Ned Twigg Date: Tue, 13 Sep 2022 17:14:06 -0700 Subject: [PATCH 284/757] Keep the step-specific sections specific to their section. --- plugin-gradle/README.md | 4 ---- 1 file changed, 4 deletions(-) diff --git a/plugin-gradle/README.md b/plugin-gradle/README.md index dc49c21a88..f5b7bbf1cc 100644 --- a/plugin-gradle/README.md +++ b/plugin-gradle/README.md @@ -193,8 +193,6 @@ spotless { // and/or reflow long strings (requires at least 1.8) // and/or use custom group artifact (you probably don't need this) googleJavaFormat('1.8').aosp().reflowLongStrings().groupArtifact('com.google.googlejavaformat:google-java-format') - // optional: fix formatting of type annotations - formatAnnotations() ``` ### palantir-java-format @@ -206,8 +204,6 @@ spotless { palantirJavaFormat() // optional: you can specify a specific version palantirJavaFormat('2.9.0') - // optional: fix formatting of type annotations - formatAnnotations() ``` ### eclipse jdt From 7a434ce732b50927a5690bb9b3e822407a462fa1 Mon Sep 17 00:00:00 2001 From: Ned Twigg Date: Tue, 13 Sep 2022 17:15:51 -0700 Subject: [PATCH 285/757] Fix TOC entry to match the new formatAnnotations name. --- plugin-gradle/README.md | 4 ++-- plugin-maven/README.md | 6 +++--- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/plugin-gradle/README.md b/plugin-gradle/README.md index f5b7bbf1cc..a6d05daa9d 100644 --- a/plugin-gradle/README.md +++ b/plugin-gradle/README.md @@ -60,7 +60,7 @@ Spotless supports all of Gradle's built-in performance features (incremental bui - [**Quickstart**](#quickstart) - [Requirements](#requirements) - **Languages** - - [Java](#java) ([google-java-format](#google-java-format), [eclipse jdt](#eclipse-jdt), [clang-format](#clang-format), [prettier](#prettier), [palantir-java-format](#palantir-java-format), [type annotations](#type-annotations)) + - [Java](#java) ([google-java-format](#google-java-format), [eclipse jdt](#eclipse-jdt), [clang-format](#clang-format), [prettier](#prettier), [palantir-java-format](#palantir-java-format), [formatAnnotations](#formatAnnotations)) - [Groovy](#groovy) ([eclipse groovy](#eclipse-groovy)) - [Kotlin](#kotlin) ([ktfmt](#ktfmt), [ktlint](#ktlint), [diktat](#diktat), [prettier](#prettier)) - [Scala](#scala) ([scalafmt](#scalafmt)) @@ -219,7 +219,7 @@ spotless { ``` -### Type annotations +### formatAnnotations Type annotations should be on the same line as the type that they qualify. diff --git a/plugin-maven/README.md b/plugin-maven/README.md index 93175b9ed8..d80773f3f1 100644 --- a/plugin-maven/README.md +++ b/plugin-maven/README.md @@ -47,7 +47,7 @@ user@machine repo % mvn spotless:check - [Requirements](#requirements) - [Binding to maven phase](#binding-to-maven-phase) - **Languages** - - [Java](#java) ([google-java-format](#google-java-format), [eclipse jdt](#eclipse-jdt), [prettier](#prettier), [palantir-java-format](#palantir-java-format), [type annotations](#type-annotations)) + - [Java](#java) ([google-java-format](#google-java-format), [eclipse jdt](#eclipse-jdt), [prettier](#prettier), [palantir-java-format](#palantir-java-format), [formatAnnotations](#formatAnnotations)) - [Groovy](#groovy) ([eclipse groovy](#eclipse-groovy)) - [Kotlin](#kotlin) ([ktfmt](#ktfmt), [ktlint](#ktlint), [diktat](#diktat), [prettier](#prettier)) - [Scala](#scala) ([scalafmt](#scalafmt)) @@ -235,7 +235,7 @@ any other maven phase (i.e. compile) then it can be configured as below; ``` -### Type annotations +### formatAnnotations Type annotations should be on the same line as the type that they qualify. @@ -255,7 +255,7 @@ However, some tools format them incorrectly, like this: String s; ``` -To fix the incorrect formatting, add the `formatAnnotations()` rule after a Java formatter. For example: +To fix the incorrect formatting, add the `formatAnnotations` rule after a Java formatter. For example: ```XML From 78cd2ef7448260c6640b8acc3ac158ed73b7f50c Mon Sep 17 00:00:00 2001 From: Ned Twigg Date: Tue, 13 Sep 2022 17:17:16 -0700 Subject: [PATCH 286/757] Minor tweak to changelog. --- CHANGES.md | 2 +- plugin-gradle/CHANGES.md | 2 +- plugin-maven/CHANGES.md | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/CHANGES.md b/CHANGES.md index cec949f59d..f61bebaa50 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -11,7 +11,7 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format ( ## [Unreleased] ### Added -* `formatAnnotations()` step to correct formatting of type annotations. It puts type annotations on the same line as the type that they qualify. Run it after a Java formatting step, such as `googleJavaFormat()`. ([#1275](https://github.com/diffplug/spotless/pull/1275)) +* `formatAnnotations()` step to correct formatting of Java type annotations. It puts type annotations on the same line as the type that they qualify. Run it after a Java formatting step, such as `googleJavaFormat()`. ([#1275](https://github.com/diffplug/spotless/pull/1275)) ## [2.29.0] - 2022-08-23 ### Added diff --git a/plugin-gradle/CHANGES.md b/plugin-gradle/CHANGES.md index 0efb87334d..5003de1aba 100644 --- a/plugin-gradle/CHANGES.md +++ b/plugin-gradle/CHANGES.md @@ -4,7 +4,7 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format ( ## [Unreleased] ### Added -* `formatAnnotations()` step to correct formatting of type annotations. It puts type annotations on the same line as the type that they qualify. Run it after a Java formatting step, such as `googleJavaFormat()`. ([#1275](https://github.com/diffplug/spotless/pull/1275)) +* `formatAnnotations()` step to correct formatting of Java type annotations. It puts type annotations on the same line as the type that they qualify. Run it after a Java formatting step, such as `googleJavaFormat()`. ([#1275](https://github.com/diffplug/spotless/pull/1275)) ## [6.10.0] - 2022-08-23 ### Added diff --git a/plugin-maven/CHANGES.md b/plugin-maven/CHANGES.md index 30842b1b06..fd371233f2 100644 --- a/plugin-maven/CHANGES.md +++ b/plugin-maven/CHANGES.md @@ -4,7 +4,7 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format ( ## [Unreleased] ### Added -* `formatAnnotations` step to correct formatting of type annotations. It puts type annotations on the same line as the type that they qualify. Run it after a Java formatting step, such as `googleJavaFormat`. ([#1275](https://github.com/diffplug/spotless/pull/1275)) +* `formatAnnotations` step to correct formatting of Java type annotations. It puts type annotations on the same line as the type that they qualify. Run it after a Java formatting step, such as `googleJavaFormat`. ([#1275](https://github.com/diffplug/spotless/pull/1275)) ## [2.25.0] - 2022-08-23 ### Added From b3212da39b9a8ccb1c80aba9ebeab5164c8b7fdf Mon Sep 17 00:00:00 2001 From: "renovate[bot]" <29139614+renovate[bot]@users.noreply.github.com> Date: Wed, 14 Sep 2022 02:19:01 +0000 Subject: [PATCH 287/757] Update dependency org.junit.jupiter:junit-jupiter to v5.9.0 --- gradle.properties | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gradle.properties b/gradle.properties index e0d2bd2911..87f667956f 100644 --- a/gradle.properties +++ b/gradle.properties @@ -26,7 +26,7 @@ VER_SLF4J=[1.6,2.0[ # Used in multiple places VER_DURIAN=1.2.0 VER_JGIT=5.13.1.202206130422-r -VER_JUNIT=5.8.0 +VER_JUNIT=5.9.0 VER_ASSERTJ=3.15.0 VER_MOCKITO=3.3.3 From 90c802de6b306b563f3d61412e3ae59022c82b80 Mon Sep 17 00:00:00 2001 From: "renovate[bot]" <29139614+renovate[bot]@users.noreply.github.com> Date: Wed, 14 Sep 2022 04:43:01 +0000 Subject: [PATCH 288/757] Update dependency com.facebook:ktfmt to v0.40 --- lib/build.gradle | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/build.gradle b/lib/build.gradle index fae8b5b875..3988a03bef 100644 --- a/lib/build.gradle +++ b/lib/build.gradle @@ -37,7 +37,7 @@ dependencies { palantirJavaFormatCompileOnly 'com.palantir.javaformat:palantir-java-format:1.1.0' - String VER_KTFMT = '0.39' + String VER_KTFMT = '0.40' 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") { From b5c5cb11b76dd389b7dc0761dd7982517202ad7b Mon Sep 17 00:00:00 2001 From: "renovate[bot]" <29139614+renovate[bot]@users.noreply.github.com> Date: Wed, 14 Sep 2022 04:43:23 +0000 Subject: [PATCH 289/757] Update dependency org.assertj:assertj-core to v3.23.1 --- gradle.properties | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gradle.properties b/gradle.properties index 87f667956f..a9808ceb00 100644 --- a/gradle.properties +++ b/gradle.properties @@ -27,7 +27,7 @@ VER_SLF4J=[1.6,2.0[ VER_DURIAN=1.2.0 VER_JGIT=5.13.1.202206130422-r VER_JUNIT=5.9.0 -VER_ASSERTJ=3.15.0 +VER_ASSERTJ=3.23.1 VER_MOCKITO=3.3.3 # Used for Maven Plugin From b722fc9a258863f003fd72b998c3f138f639e793 Mon Sep 17 00:00:00 2001 From: Ned Twigg Date: Tue, 13 Sep 2022 21:48:28 -0700 Subject: [PATCH 290/757] Update changelogs. --- CHANGES.md | 2 ++ plugin-gradle/CHANGES.md | 2 ++ plugin-maven/CHANGES.md | 2 ++ 3 files changed, 6 insertions(+) diff --git a/CHANGES.md b/CHANGES.md index f61bebaa50..df7f0380b5 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -12,6 +12,8 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format ( ## [Unreleased] ### Added * `formatAnnotations()` step to correct formatting of Java type annotations. It puts type annotations on the same line as the type that they qualify. Run it after a Java formatting step, such as `googleJavaFormat()`. ([#1275](https://github.com/diffplug/spotless/pull/1275)) +### Changes +* Bump default `ktfmt` version to latest `0.39` -> `0.40` ([#1312](https://github.com/diffplug/spotless/pull/1312)) ## [2.29.0] - 2022-08-23 ### Added diff --git a/plugin-gradle/CHANGES.md b/plugin-gradle/CHANGES.md index 5003de1aba..aed5f04ec5 100644 --- a/plugin-gradle/CHANGES.md +++ b/plugin-gradle/CHANGES.md @@ -5,6 +5,8 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format ( ## [Unreleased] ### Added * `formatAnnotations()` step to correct formatting of Java type annotations. It puts type annotations on the same line as the type that they qualify. Run it after a Java formatting step, such as `googleJavaFormat()`. ([#1275](https://github.com/diffplug/spotless/pull/1275)) +### Changes +* Bump default `ktfmt` version to latest `0.39` -> `0.40` ([#1312](https://github.com/diffplug/spotless/pull/1312)) ## [6.10.0] - 2022-08-23 ### Added diff --git a/plugin-maven/CHANGES.md b/plugin-maven/CHANGES.md index fd371233f2..aa54842d27 100644 --- a/plugin-maven/CHANGES.md +++ b/plugin-maven/CHANGES.md @@ -5,6 +5,8 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format ( ## [Unreleased] ### Added * `formatAnnotations` step to correct formatting of Java type annotations. It puts type annotations on the same line as the type that they qualify. Run it after a Java formatting step, such as `googleJavaFormat`. ([#1275](https://github.com/diffplug/spotless/pull/1275)) +### Changes +* Bump default `ktfmt` version to latest `0.39` -> `0.40` ([#1312](https://github.com/diffplug/spotless/pull/1312)) ## [2.25.0] - 2022-08-23 ### Added From f2e2f71979efade036dbec53d27d66fcd00e3264 Mon Sep 17 00:00:00 2001 From: Ned Twigg Date: Tue, 13 Sep 2022 21:48:39 -0700 Subject: [PATCH 291/757] Udpate KtFmtStep to the new latest version. --- lib/src/main/java/com/diffplug/spotless/kotlin/KtfmtStep.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 37bbf786c6..9e52bd0435 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.39"; + private static final String DEFAULT_VERSION = "0.40"; static final String NAME = "ktfmt"; static final String PACKAGE = "com.facebook"; static final String MAVEN_COORDINATE = PACKAGE + ":ktfmt:"; From 6e481449c4ed8f552846f1356f8422a5c1518fab Mon Sep 17 00:00:00 2001 From: "renovate[bot]" <29139614+renovate[bot]@users.noreply.github.com> Date: Wed, 14 Sep 2022 05:02:53 +0000 Subject: [PATCH 292/757] Update dependency org.mockito:mockito-core to v3.12.4 --- gradle.properties | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gradle.properties b/gradle.properties index a9808ceb00..8c0e3015b4 100644 --- a/gradle.properties +++ b/gradle.properties @@ -28,7 +28,7 @@ VER_DURIAN=1.2.0 VER_JGIT=5.13.1.202206130422-r VER_JUNIT=5.9.0 VER_ASSERTJ=3.23.1 -VER_MOCKITO=3.3.3 +VER_MOCKITO=3.12.4 # Used for Maven Plugin VER_MAVEN_API=3.0 From 9ec6f63323bb351483fffdea346a8504146cb071 Mon Sep 17 00:00:00 2001 From: Ned Twigg Date: Tue, 13 Sep 2022 22:15:13 -0700 Subject: [PATCH 293/757] Add comments for what the differences are in each version of the adapter function. --- .../spotless/glue/ktlint/KtlintFormatterFunc.java | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/lib/src/ktlint/java/com/diffplug/spotless/glue/ktlint/KtlintFormatterFunc.java b/lib/src/ktlint/java/com/diffplug/spotless/glue/ktlint/KtlintFormatterFunc.java index 96ad244593..cc64eb9d66 100644 --- a/lib/src/ktlint/java/com/diffplug/spotless/glue/ktlint/KtlintFormatterFunc.java +++ b/lib/src/ktlint/java/com/diffplug/spotless/glue/ktlint/KtlintFormatterFunc.java @@ -41,17 +41,23 @@ public class KtlintFormatterFunc implements FormatterFunc.NeedsFile { public KtlintFormatterFunc(String version, boolean isScript, boolean useExperimental, Map userData, Map editorConfigOverrideMap) { int minorVersion = Integer.parseInt(version.split("\\.")[1]); - if (version.equals("0.45.2")) { - this.adapter = new KtLintCompat0Dot45Dot2Adapter(); - } else if (minorVersion >= 47) { + if (minorVersion >= 47) { + // rename RuleSet to RuleProvider this.adapter = new KtLintCompat0Dot47Dot0Adapter(); } else if (minorVersion >= 46) { + // DefaultEditorConfigProperties.INSTANCE.getDefaultEditorConfigProperties() renamed to .getEditorConfigProperties() this.adapter = new KtLintCompat0Dot46Dot0Adapter(); + } else if (version.equals("0.45.2")) { + // add editorConfigOverride + this.adapter = new KtLintCompat0Dot45Dot2Adapter(); } else if (minorVersion >= 34) { + // KtLint.INSTANCE.format() now needs more parameters this.adapter = new KtLintCompat0Dot34Dot2Adapter(); } else if (minorVersion >= 32) { + // rename packages from `com.github.shyiko` to `com.pinterest` this.adapter = new KtLintCompat0Dot32Dot0Adapter(); } else { + // the OG this.adapter = new KtLintCompat0Dot31Dot0Adapter(); } this.useExperimental = useExperimental; From 864eb7a8fa2ec80728d7f8c6a6cc8ce6575c137e Mon Sep 17 00:00:00 2001 From: Ned Twigg Date: Tue, 13 Sep 2022 22:19:18 -0700 Subject: [PATCH 294/757] Bump ktlint default version from `0.46.1` to `0.47.1` --- lib/src/main/java/com/diffplug/spotless/kotlin/KtLintStep.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/src/main/java/com/diffplug/spotless/kotlin/KtLintStep.java b/lib/src/main/java/com/diffplug/spotless/kotlin/KtLintStep.java index 6b886c2186..5627913e4a 100644 --- a/lib/src/main/java/com/diffplug/spotless/kotlin/KtLintStep.java +++ b/lib/src/main/java/com/diffplug/spotless/kotlin/KtLintStep.java @@ -33,7 +33,7 @@ public class KtLintStep { // prevent direct instantiation private KtLintStep() {} - private static final String DEFAULT_VERSION = "0.46.1"; + private static final String DEFAULT_VERSION = "0.47.1"; static final String NAME = "ktlint"; static final String PACKAGE_PRE_0_32 = "com.github.shyiko"; static final String PACKAGE = "com.pinterest"; From d80f076f1119153dc5865652eb6684fe101d5077 Mon Sep 17 00:00:00 2001 From: Ned Twigg Date: Tue, 13 Sep 2022 22:22:04 -0700 Subject: [PATCH 295/757] Resolve changelog merge. --- CHANGES.md | 6 ++---- plugin-gradle/CHANGES.md | 6 ++---- plugin-maven/CHANGES.md | 6 ++---- 3 files changed, 6 insertions(+), 12 deletions(-) diff --git a/CHANGES.md b/CHANGES.md index 4242daf40f..d845cc0b99 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -14,10 +14,8 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format ( * `formatAnnotations()` step to correct formatting of Java type annotations. It puts type annotations on the same line as the type that they qualify. Run it after a Java formatting step, such as `googleJavaFormat()`. ([#1275](https://github.com/diffplug/spotless/pull/1275)) ### Changes * Bump default `ktfmt` version to latest `0.39` -> `0.40` ([#1312](https://github.com/diffplug/spotless/pull/1312)) - -### Changes -* Extend minimum supported version for `ktlint` to `0.31.0` ([#1303](https://github.com/diffplug/spotless/pull/1303)). -* Support `ktlint` version 0.47.x ([#1303](https://github.com/diffplug/spotless/pull/1303)) fixes [#1281](https://github.com/diffplug/spotless/issues/1281). +* Bump default `ktlint` version to latest `0.46.1` -> `0.47.1` ([#1303](https://github.com/diffplug/spotless/pull/1303)) + * Also restored support for older versions of ktlint back to `0.31.0` ## [2.29.0] - 2022-08-23 ### Added diff --git a/plugin-gradle/CHANGES.md b/plugin-gradle/CHANGES.md index 0a2f400635..78a9b46693 100644 --- a/plugin-gradle/CHANGES.md +++ b/plugin-gradle/CHANGES.md @@ -7,10 +7,8 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format ( * `formatAnnotations()` step to correct formatting of Java type annotations. It puts type annotations on the same line as the type that they qualify. Run it after a Java formatting step, such as `googleJavaFormat()`. ([#1275](https://github.com/diffplug/spotless/pull/1275)) ### Changes * Bump default `ktfmt` version to latest `0.39` -> `0.40` ([#1312](https://github.com/diffplug/spotless/pull/1312)) - -### Changes -* Extend minimum supported version for `ktlint` to `0.31.0` ([#1303](https://github.com/diffplug/spotless/pull/1303)). -* Support `ktlint` version 0.47.x ([#1303](https://github.com/diffplug/spotless/pull/1303)) fixes [#1281](https://github.com/diffplug/spotless/issues/1281). +* Bump default `ktlint` version to latest `0.46.1` -> `0.47.1` ([#1303](https://github.com/diffplug/spotless/pull/1303)) + * Also restored support for older versions of ktlint back to `0.31.0` ## [6.10.0] - 2022-08-23 ### Added diff --git a/plugin-maven/CHANGES.md b/plugin-maven/CHANGES.md index 6536aa074a..5d47dc4f4f 100644 --- a/plugin-maven/CHANGES.md +++ b/plugin-maven/CHANGES.md @@ -7,10 +7,8 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format ( * `formatAnnotations` step to correct formatting of Java type annotations. It puts type annotations on the same line as the type that they qualify. Run it after a Java formatting step, such as `googleJavaFormat`. ([#1275](https://github.com/diffplug/spotless/pull/1275)) ### Changes * Bump default `ktfmt` version to latest `0.39` -> `0.40` ([#1312](https://github.com/diffplug/spotless/pull/1312)) - -### Changes -* Extend minimum supported version for `ktlint` to `0.31.0` ([#1303](https://github.com/diffplug/spotless/pull/1303)). -* Support `ktlint` version 0.47.x ([#1303](https://github.com/diffplug/spotless/pull/1303)) fixes [#1281](https://github.com/diffplug/spotless/issues/1281). +* Bump default `ktlint` version to latest `0.46.1` -> `0.47.1` ([#1303](https://github.com/diffplug/spotless/pull/1303)) + * Also restored support for older versions of ktlint back to `0.31.0` ## [2.25.0] - 2022-08-23 ### Added From 670c0ab54b97c0208df43dc5093c8c11c3e68aba Mon Sep 17 00:00:00 2001 From: "renovate[bot]" <29139614+renovate[bot]@users.noreply.github.com> Date: Wed, 14 Sep 2022 05:24:21 +0000 Subject: [PATCH 296/757] Update dependency org.eclipse.aether:aether-api to v0.9.1.v20140329 --- gradle.properties | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gradle.properties b/gradle.properties index 8c0e3015b4..09d152d886 100644 --- a/gradle.properties +++ b/gradle.properties @@ -32,6 +32,6 @@ VER_MOCKITO=3.12.4 # Used for Maven Plugin VER_MAVEN_API=3.0 -VER_ECLIPSE_AETHER=0.9.0.M2 +VER_ECLIPSE_AETHER=0.9.1.v20140329 VER_MUSTACHE=0.9.10 VER_PLEXUS_RESOURCES=1.2.0 From f634a23b88a0271da4fab9de840c86c86592eea9 Mon Sep 17 00:00:00 2001 From: "renovate[bot]" <29139614+renovate[bot]@users.noreply.github.com> Date: Wed, 14 Sep 2022 05:46:52 +0000 Subject: [PATCH 297/757] Update dependency com.github.spotbugs:spotbugs-annotations to v4.7.2 --- gradle.properties | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gradle.properties b/gradle.properties index 09d152d886..9b90d05ee8 100644 --- a/gradle.properties +++ b/gradle.properties @@ -17,7 +17,7 @@ artifactIdGradle=spotless-plugin-gradle # Build requirements VER_JAVA=1.8 -VER_SPOTBUGS=4.5.0 +VER_SPOTBUGS=4.7.2 VER_JSR_305=3.0.2 # Dependencies provided by Spotless plugin From 58a50f648168979fb2478db9b2781ac1764550b3 Mon Sep 17 00:00:00 2001 From: "renovate[bot]" <29139614+renovate[bot]@users.noreply.github.com> Date: Wed, 14 Sep 2022 05:47:06 +0000 Subject: [PATCH 298/757] Update plugin com.diffplug.spotless-changelog to v2.4.0 --- settings.gradle | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/settings.gradle b/settings.gradle index 1706b5fa7f..8e9c3a2d35 100644 --- a/settings.gradle +++ b/settings.gradle @@ -8,7 +8,7 @@ pluginManagement { // https://github.com/spotbugs/spotbugs-gradle-plugin/releases id 'com.github.spotbugs' version '5.0.12' // https://github.com/diffplug/spotless-changelog - id 'com.diffplug.spotless-changelog' version '2.3.2' + id 'com.diffplug.spotless-changelog' version '2.4.0' // https://github.com/diffplug/goomph/blob/main/CHANGES.md id 'com.diffplug.p2.asmaven' version '3.27.0' // DO NOT UPDATE, see https://github.com/diffplug/spotless/pull/874 // https://github.com/gradle/test-retry-gradle-plugin/releases From 6cee33d6f035b462be5800c154d86ecad63cdd57 Mon Sep 17 00:00:00 2001 From: circleci Date: Wed, 14 Sep 2022 05:54:42 +0000 Subject: [PATCH 299/757] Published lib/2.30.0 --- CHANGES.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/CHANGES.md b/CHANGES.md index d845cc0b99..23c20dc957 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -10,6 +10,8 @@ This document is intended for Spotless developers. We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format (starting after version `1.27.0`). ## [Unreleased] + +## [2.30.0] - 2022-09-14 ### Added * `formatAnnotations()` step to correct formatting of Java type annotations. It puts type annotations on the same line as the type that they qualify. Run it after a Java formatting step, such as `googleJavaFormat()`. ([#1275](https://github.com/diffplug/spotless/pull/1275)) ### Changes From 36e5cc6d61a8b728cf21e5b42b03fccdc66a872e Mon Sep 17 00:00:00 2001 From: circleci Date: Wed, 14 Sep 2022 05:56:03 +0000 Subject: [PATCH 300/757] Published gradle/6.11.0 --- plugin-gradle/CHANGES.md | 2 ++ plugin-gradle/README.md | 46 ++++++++++++++++++++-------------------- 2 files changed, 25 insertions(+), 23 deletions(-) diff --git a/plugin-gradle/CHANGES.md b/plugin-gradle/CHANGES.md index 78a9b46693..f7c15244d5 100644 --- a/plugin-gradle/CHANGES.md +++ b/plugin-gradle/CHANGES.md @@ -3,6 +3,8 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format (starting after version `3.27.0`). ## [Unreleased] + +## [6.11.0] - 2022-09-14 ### Added * `formatAnnotations()` step to correct formatting of Java type annotations. It puts type annotations on the same line as the type that they qualify. Run it after a Java formatting step, such as `googleJavaFormat()`. ([#1275](https://github.com/diffplug/spotless/pull/1275)) ### Changes diff --git a/plugin-gradle/README.md b/plugin-gradle/README.md index a6d05daa9d..29e748295e 100644 --- a/plugin-gradle/README.md +++ b/plugin-gradle/README.md @@ -18,9 +18,9 @@ output = [ --> [![Gradle plugin](https://img.shields.io/badge/plugins.gradle.org-com.diffplug.spotless-blue.svg)](https://plugins.gradle.org/plugin/com.diffplug.spotless) [![Maven central](https://img.shields.io/badge/mavencentral-yes-blue.svg)](https://search.maven.org/#search%7Cgav%7C1%7Cg%3A%22com.diffplug.spotless%22%20AND%20a%3A%22spotless-plugin-gradle%22) -[![Javadoc](https://img.shields.io/badge/javadoc-yes-blue.svg)](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.10.0/index.html) +[![Javadoc](https://img.shields.io/badge/javadoc-yes-blue.svg)](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.11.0/index.html) [![License Apache](https://img.shields.io/badge/license-apache-blue.svg)](https://tldrlegal.com/license/apache-license-2.0-(apache-2.0)) -[![Changelog](https://img.shields.io/badge/changelog-6.10.0-blue.svg)](CHANGES.md) +[![Changelog](https://img.shields.io/badge/changelog-6.11.0-blue.svg)](CHANGES.md) [![Circle CI](https://circleci.com/gh/diffplug/spotless/tree/main.svg?style=shield)](https://circleci.com/gh/diffplug/spotless/tree/main) [![Live chat](https://img.shields.io/badge/gitter-chat-brightgreen.svg)](https://gitter.im/diffplug/spotless) @@ -128,10 +128,10 @@ spotless { ``` Spotless consists of a list of formats (in the example above, `misc` and `java`), and each format has: -- a `target` (the files to format), which you set with [`target`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.10.0/com/diffplug/gradle/spotless/FormatExtension.html#target-java.lang.Object...-) and [`targetExclude`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.10.0/com/diffplug/gradle/spotless/FormatExtension.html#targetExclude-java.lang.Object...-) -- a list of `FormatterStep`, which are just `String -> String` functions, such as [`replace`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.10.0/com/diffplug/gradle/spotless/FormatExtension.html#replace-java.lang.String-java.lang.CharSequence-java.lang.CharSequence-), [`replaceRegex`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.10.0/com/diffplug/gradle/spotless/FormatExtension.html#replaceRegex-java.lang.String-java.lang.String-java.lang.String-), [`trimTrailingWhitespace`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.10.0/com/diffplug/gradle/spotless/FormatExtension.html#replace-java.lang.String-java.lang.CharSequence-java.lang.CharSequence-), [`custom`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.10.0/com/diffplug/gradle/spotless/FormatExtension.html#custom-java.lang.String-groovy.lang.Closure-), [`prettier`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.10.0/com/diffplug/gradle/spotless/FormatExtension.html#prettier--), [`eclipseWtp`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.10.0/com/diffplug/gradle/spotless/FormatExtension.html#eclipseWtp-com.diffplug.spotless.extra.wtp.EclipseWtpFormatterStep-), [`licenseHeader`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.10.0/com/diffplug/gradle/spotless/FormatExtension.html#licenseHeader-java.lang.String-java.lang.String-) etc. +- a `target` (the files to format), which you set with [`target`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.11.0/com/diffplug/gradle/spotless/FormatExtension.html#target-java.lang.Object...-) and [`targetExclude`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.11.0/com/diffplug/gradle/spotless/FormatExtension.html#targetExclude-java.lang.Object...-) +- a list of `FormatterStep`, which are just `String -> String` functions, such as [`replace`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.11.0/com/diffplug/gradle/spotless/FormatExtension.html#replace-java.lang.String-java.lang.CharSequence-java.lang.CharSequence-), [`replaceRegex`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.11.0/com/diffplug/gradle/spotless/FormatExtension.html#replaceRegex-java.lang.String-java.lang.String-java.lang.String-), [`trimTrailingWhitespace`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.11.0/com/diffplug/gradle/spotless/FormatExtension.html#replace-java.lang.String-java.lang.CharSequence-java.lang.CharSequence-), [`custom`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.11.0/com/diffplug/gradle/spotless/FormatExtension.html#custom-java.lang.String-groovy.lang.Closure-), [`prettier`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.11.0/com/diffplug/gradle/spotless/FormatExtension.html#prettier--), [`eclipseWtp`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.11.0/com/diffplug/gradle/spotless/FormatExtension.html#eclipseWtp-com.diffplug.spotless.extra.wtp.EclipseWtpFormatterStep-), [`licenseHeader`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.11.0/com/diffplug/gradle/spotless/FormatExtension.html#licenseHeader-java.lang.String-java.lang.String-) etc. -All the generic steps live in [`FormatExtension`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.10.0/com/diffplug/gradle/spotless/FormatExtension.html), and there are many language-specific steps which live in its language-specific subclasses, which are described below. +All the generic steps live in [`FormatExtension`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.11.0/com/diffplug/gradle/spotless/FormatExtension.html), and there are many language-specific steps which live in its language-specific subclasses, which are described below. ### Requirements @@ -143,7 +143,7 @@ If you're stuck on an older version of Gradle, `id 'com.diffplug.gradle.spotless ## Java -`com.diffplug.gradle.spotless.JavaExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.10.0/com/diffplug/gradle/spotless/JavaExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/JavaExtension.java) +`com.diffplug.gradle.spotless.JavaExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.11.0/com/diffplug/gradle/spotless/JavaExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/JavaExtension.java) ```gradle spotless { @@ -267,8 +267,8 @@ You can make a pull request to add new annotations to Spotless's default list. ## Groovy -- `com.diffplug.gradle.spotless.GroovyExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.10.0/com/diffplug/gradle/spotless/GroovyExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/GroovyExtension.java) -- `com.diffplug.gradle.spotless.GroovyGradleExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.10.0/com/diffplug/gradle/spotless/GroovyGradleExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/GroovyGradleExtension.java) +- `com.diffplug.gradle.spotless.GroovyExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.11.0/com/diffplug/gradle/spotless/GroovyExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/GroovyExtension.java) +- `com.diffplug.gradle.spotless.GroovyGradleExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.11.0/com/diffplug/gradle/spotless/GroovyGradleExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/GroovyGradleExtension.java) Configuration for Groovy is similar to [Java](#java), in that it also supports `licenseHeader` and `importOrder`. @@ -319,8 +319,8 @@ Groovy-Eclipse formatting errors/warnings lead per default to a build failure. T ## Kotlin -- `com.diffplug.gradle.spotless.KotlinExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.10.0/com/diffplug/gradle/spotless/KotlinExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/KotlinExtension.java) -- `com.diffplug.gradle.spotless.KotlinGradleExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.10.0/com/diffplug/gradle/spotless/KotlinGradleExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/KotlinGradleExtension.java) +- `com.diffplug.gradle.spotless.KotlinExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.11.0/com/diffplug/gradle/spotless/KotlinExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/KotlinExtension.java) +- `com.diffplug.gradle.spotless.KotlinGradleExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.11.0/com/diffplug/gradle/spotless/KotlinGradleExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/KotlinGradleExtension.java) ```gradle spotless { // if you are using build.gradle.kts, instead of 'spotless {' use: @@ -383,7 +383,7 @@ spotless { ## Scala -`com.diffplug.gradle.spotless.ScalaExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.10.0/com/diffplug/gradle/spotless/ScalaExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/ScalaExtension.java) +`com.diffplug.gradle.spotless.ScalaExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.11.0/com/diffplug/gradle/spotless/ScalaExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/ScalaExtension.java) ```gradle spotless { @@ -415,7 +415,7 @@ spotless { ## C/C++ -`com.diffplug.gradle.spotless.CppExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.10.0/com/diffplug/gradle/spotless/CppExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/CppExtension.java) +`com.diffplug.gradle.spotless.CppExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.11.0/com/diffplug/gradle/spotless/CppExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/CppExtension.java) ```gradle spotless { @@ -447,7 +447,7 @@ spotles { ## Python -`com.diffplug.gradle.spotless.PythonExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.10.0/com/diffplug/gradle/spotless/PythonExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/PythonExtension.java) +`com.diffplug.gradle.spotless.PythonExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.11.0/com/diffplug/gradle/spotless/PythonExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/PythonExtension.java) ```gradle spotless { @@ -481,7 +481,7 @@ black().pathToExe('C:/myuser/.pyenv/versions/3.8.0/scripts/black.exe') ## FreshMark -`com.diffplug.gradle.spotless.FreshMarkExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.10.0/com/diffplug/gradle/spotless/FreshMarkExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/FreshMarkExtension.java) +`com.diffplug.gradle.spotless.FreshMarkExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.11.0/com/diffplug/gradle/spotless/FreshMarkExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/FreshMarkExtension.java) [homepage](https://github.com/diffplug/freshmark). [changelog](https://github.com/diffplug/freshmark/blob/master/CHANGES.md). FreshMark lets you generate markdown in the comments of your markdown. This helps to keep badges and links up-to-date (see the source for this file), and can also be helpful for generating complex tables (see the source for [the parent readme](../README.md)). @@ -502,7 +502,7 @@ spotless { ## Antlr4 -`com.diffplug.gradle.spotless.Antlr4Extension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.10.0/com/diffplug/gradle/spotless/Antlr4Extension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/Antlr4Extension.java) +`com.diffplug.gradle.spotless.Antlr4Extension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.11.0/com/diffplug/gradle/spotless/Antlr4Extension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/Antlr4Extension.java) ```gradle spotless { @@ -527,7 +527,7 @@ antlr4formatter('1.2.1') // version is optional ## SQL -`com.diffplug.gradle.spotless.SqlExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.10.0/com/diffplug/gradle/spotless/SqlExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/SqlExtension.java) +`com.diffplug.gradle.spotless.SqlExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.11.0/com/diffplug/gradle/spotless/SqlExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/SqlExtension.java) ```gradle spotless { @@ -567,7 +567,7 @@ sql.formatter.indent.size=4 ## Typescript -- `com.diffplug.gradle.spotless.TypescriptExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.10.0/com/diffplug/gradle/spotless/TypescriptExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/TypescriptExtension.java) +- `com.diffplug.gradle.spotless.TypescriptExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.11.0/com/diffplug/gradle/spotless/TypescriptExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/TypescriptExtension.java) ```gradle spotless { @@ -610,7 +610,7 @@ For details, see the [npm detection](#npm-detection) and [`.npmrc` detection](#n ## JSON -- `com.diffplug.gradle.spotless.JsonExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.10.0/com/diffplug/gradle/spotless/JsonExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/JsonExtension.java) +- `com.diffplug.gradle.spotless.JsonExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.11.0/com/diffplug/gradle/spotless/JsonExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/JsonExtension.java) ```gradle spotless { @@ -835,7 +835,7 @@ Once a file's license header has a valid year, whether it is a year (`2020`) or * `2017` -> `2017-2020` * `2017-2019` -> `2017-2020` -See the [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.10.0/com/diffplug/gradle/spotless/FormatExtension.LicenseHeaderConfig.html) for a complete listing of options. +See the [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.11.0/com/diffplug/gradle/spotless/FormatExtension.LicenseHeaderConfig.html) for a complete listing of options. @@ -902,9 +902,9 @@ spotless { custom 'lowercase', { str -> str.toLowerCase() } ``` -However, custom rules will disable up-to-date checking and caching, unless you read [this javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.10.0/com/diffplug/gradle/spotless/FormatExtension.html#bumpThisNumberIfACustomStepChanges-int-) and follow its instructions carefully. +However, custom rules will disable up-to-date checking and caching, unless you read [this javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.11.0/com/diffplug/gradle/spotless/FormatExtension.html#bumpThisNumberIfACustomStepChanges-int-) and follow its instructions carefully. -Another option is to create proper `FormatterStep` in your `buildSrc`, and then call [`addStep`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.10.0/com/diffplug/gradle/spotless/FormatExtension.html#addStep-com.diffplug.spotless.FormatterStep-). The contributing guide describes [how to do this](https://github.com/diffplug/spotless/blob/main/CONTRIBUTING.md#how-to-add-a-new-formatterstep). If the step is generally-useful, we hope you'll open a PR to share it! +Another option is to create proper `FormatterStep` in your `buildSrc`, and then call [`addStep`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.11.0/com/diffplug/gradle/spotless/FormatExtension.html#addStep-com.diffplug.spotless.FormatterStep-). The contributing guide describes [how to do this](https://github.com/diffplug/spotless/blob/main/CONTRIBUTING.md#how-to-add-a-new-formatterstep). If the step is generally-useful, we hope you'll open a PR to share it! ```gradle @@ -937,11 +937,11 @@ spotless { format 'foo', com.acme.FooLanguageExtension, { ``` -If you'd like to create a one-off Spotless task outside of the `check`/`apply` framework, see [`FormatExtension.createIndependentApplyTask`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.10.0/com/diffplug/gradle/spotless/FormatExtension.html#createIndependentApplyTask-java.lang.String-). +If you'd like to create a one-off Spotless task outside of the `check`/`apply` framework, see [`FormatExtension.createIndependentApplyTask`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.11.0/com/diffplug/gradle/spotless/FormatExtension.html#createIndependentApplyTask-java.lang.String-). ## Inception (languages within languages within...) -In very rare cases, you might want to format e.g. javascript which is written inside JSP templates, or maybe java within a markdown file, or something wacky like that. You can specify hunks within a file using either open/close tags or a regex with a single capturing group, and then specify rules within it, like so. See [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.10.0/com/diffplug/gradle/spotless/FormatExtension.html#withinBlocks-java.lang.String-java.lang.String-java.lang.String-org.gradle.api.Action-) for more details. +In very rare cases, you might want to format e.g. javascript which is written inside JSP templates, or maybe java within a markdown file, or something wacky like that. You can specify hunks within a file using either open/close tags or a regex with a single capturing group, and then specify rules within it, like so. See [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.11.0/com/diffplug/gradle/spotless/FormatExtension.html#withinBlocks-java.lang.String-java.lang.String-java.lang.String-org.gradle.api.Action-) for more details. ```gradle import com.diffplug.gradle.spotless.JavaExtension From 0b186ab5217a53bf33f047dc00952cb0889e9121 Mon Sep 17 00:00:00 2001 From: circleci Date: Wed, 14 Sep 2022 05:57:45 +0000 Subject: [PATCH 301/757] Published maven/2.26.0 --- plugin-maven/CHANGES.md | 2 ++ plugin-maven/README.md | 4 ++-- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/plugin-maven/CHANGES.md b/plugin-maven/CHANGES.md index 5d47dc4f4f..1ce37116a1 100644 --- a/plugin-maven/CHANGES.md +++ b/plugin-maven/CHANGES.md @@ -3,6 +3,8 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format (starting after version `1.27.0`). ## [Unreleased] + +## [2.26.0] - 2022-09-14 ### Added * `formatAnnotations` step to correct formatting of Java type annotations. It puts type annotations on the same line as the type that they qualify. Run it after a Java formatting step, such as `googleJavaFormat`. ([#1275](https://github.com/diffplug/spotless/pull/1275)) ### Changes diff --git a/plugin-maven/README.md b/plugin-maven/README.md index d80773f3f1..19796770ef 100644 --- a/plugin-maven/README.md +++ b/plugin-maven/README.md @@ -12,8 +12,8 @@ output = [ ].join('\n'); --> [![Maven central](https://img.shields.io/badge/mavencentral-com.diffplug.spotless%3Aspotless--maven--plugin-blue.svg)](https://search.maven.org/#search%7Cgav%7C1%7Cg%3A%22com.diffplug.spotless%22%20AND%20a%3A%22spotless-maven-plugin%22) -[![Javadoc](https://img.shields.io/badge/javadoc-yes-blue.svg)](https://javadoc.io/doc/com.diffplug.spotless/spotless-maven-plugin/2.25.0/index.html) -[![Changelog](https://img.shields.io/badge/changelog-2.25.0-brightgreen.svg)](CHANGES.md) +[![Javadoc](https://img.shields.io/badge/javadoc-yes-blue.svg)](https://javadoc.io/doc/com.diffplug.spotless/spotless-maven-plugin/2.26.0/index.html) +[![Changelog](https://img.shields.io/badge/changelog-2.26.0-brightgreen.svg)](CHANGES.md) [![Circle CI](https://circleci.com/gh/diffplug/spotless/tree/main.svg?style=shield)](https://circleci.com/gh/diffplug/spotless/tree/main) [![Live chat](https://img.shields.io/badge/gitter-chat-brightgreen.svg)](https://gitter.im/diffplug/spotless) From cdf7c015ad6f5ebb5b7efbc2b9d75f1e3dfbced4 Mon Sep 17 00:00:00 2001 From: "renovate[bot]" <29139614+renovate[bot]@users.noreply.github.com> Date: Wed, 14 Sep 2022 11:09:59 +0000 Subject: [PATCH 302/757] Update plugin com.diffplug.spotless to v6.11.0 --- settings.gradle | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/settings.gradle b/settings.gradle index 91de4f9e48..fb37734f5f 100644 --- a/settings.gradle +++ b/settings.gradle @@ -1,6 +1,6 @@ pluginManagement { plugins { - id 'com.diffplug.spotless' version '6.5.0' + id 'com.diffplug.spotless' version '6.11.0' // https://plugins.gradle.org/plugin/com.gradle.plugin-publish id 'com.gradle.plugin-publish' version '1.0.0' // https://github.com/gradle-nexus/publish-plugin/releases From 556bb22349d3328c1824431d27798b815a92dfa4 Mon Sep 17 00:00:00 2001 From: "renovate[bot]" <29139614+renovate[bot]@users.noreply.github.com> Date: Thu, 15 Sep 2022 21:10:36 +0000 Subject: [PATCH 303/757] Update dependency org.eclipse.aether:aether-api to v1 --- gradle.properties | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gradle.properties b/gradle.properties index 9b90d05ee8..d37961f958 100644 --- a/gradle.properties +++ b/gradle.properties @@ -32,6 +32,6 @@ VER_MOCKITO=3.12.4 # Used for Maven Plugin VER_MAVEN_API=3.0 -VER_ECLIPSE_AETHER=0.9.1.v20140329 +VER_ECLIPSE_AETHER=1.1.0 VER_MUSTACHE=0.9.10 VER_PLEXUS_RESOURCES=1.2.0 From 80111ddeb4e5f877dccf6ba9fcd2ca67d89ea600 Mon Sep 17 00:00:00 2001 From: "renovate[bot]" <29139614+renovate[bot]@users.noreply.github.com> Date: Fri, 16 Sep 2022 00:10:49 +0000 Subject: [PATCH 304/757] Update dependency org.mockito:mockito-core to v4 --- gradle.properties | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gradle.properties b/gradle.properties index 9b90d05ee8..4ac4b94fa5 100644 --- a/gradle.properties +++ b/gradle.properties @@ -28,7 +28,7 @@ VER_DURIAN=1.2.0 VER_JGIT=5.13.1.202206130422-r VER_JUNIT=5.9.0 VER_ASSERTJ=3.23.1 -VER_MOCKITO=3.12.4 +VER_MOCKITO=4.8.0 # Used for Maven Plugin VER_MAVEN_API=3.0 From f87bd70b6cd34392898da055f3d7507491b36368 Mon Sep 17 00:00:00 2001 From: "renovate[bot]" <29139614+renovate[bot]@users.noreply.github.com> Date: Fri, 16 Sep 2022 00:10:56 +0000 Subject: [PATCH 305/757] Update win orb to v5 --- .circleci/config.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index a5ca735442..83e434bcec 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -1,6 +1,6 @@ version: 2.1 orbs: - win: circleci/windows@2.4.1 + win: circleci/windows@5.0.0 anchors: env_gradle: &env_gradle From 57788b87e745f9b1f01682aaa36565faada5e6c1 Mon Sep 17 00:00:00 2001 From: Tormod Alf Try Tufteland Date: Fri, 16 Sep 2022 15:33:48 +0200 Subject: [PATCH 306/757] feat: ktlint editorConfigOverrides for plugin-maven --- plugin-maven/README.md | 4 ++++ .../com/diffplug/spotless/maven/kotlin/Ktlint.java | 14 +++++++++++++- .../diffplug/spotless/maven/kotlin/KtlintTest.java | 10 ++++++++++ 3 files changed, 27 insertions(+), 1 deletion(-) diff --git a/plugin-maven/README.md b/plugin-maven/README.md index 19796770ef..a6a8491784 100644 --- a/plugin-maven/README.md +++ b/plugin-maven/README.md @@ -359,6 +359,10 @@ Groovy-Eclipse formatting errors/warnings lead per default to a build failure. T ```xml 0.43.2 + + true + true + ``` diff --git a/plugin-maven/src/main/java/com/diffplug/spotless/maven/kotlin/Ktlint.java b/plugin-maven/src/main/java/com/diffplug/spotless/maven/kotlin/Ktlint.java index 796523d315..5792ee0611 100644 --- a/plugin-maven/src/main/java/com/diffplug/spotless/maven/kotlin/Ktlint.java +++ b/plugin-maven/src/main/java/com/diffplug/spotless/maven/kotlin/Ktlint.java @@ -22,14 +22,26 @@ import com.diffplug.spotless.maven.FormatterStepConfig; import com.diffplug.spotless.maven.FormatterStepFactory; +import java.util.Collections; +import java.util.HashMap; +import java.util.Map; + public class Ktlint implements FormatterStepFactory { @Parameter private String version; + @Parameter + private Map editorConfigOverride; + @Override public FormatterStep newFormatterStep(FormatterStepConfig config) { String ktlintVersion = version != null ? version : KtLintStep.defaultVersion(); - return KtLintStep.create(ktlintVersion, config.getProvisioner()); + + if (editorConfigOverride == null) { + editorConfigOverride = new HashMap<>(); + } + + return KtLintStep.create(ktlintVersion, config.getProvisioner(), false, Collections.emptyMap(), editorConfigOverride); } } diff --git a/plugin-maven/src/test/java/com/diffplug/spotless/maven/kotlin/KtlintTest.java b/plugin-maven/src/test/java/com/diffplug/spotless/maven/kotlin/KtlintTest.java index 887f7a3f50..ba6f1d8e2c 100644 --- a/plugin-maven/src/test/java/com/diffplug/spotless/maven/kotlin/KtlintTest.java +++ b/plugin-maven/src/test/java/com/diffplug/spotless/maven/kotlin/KtlintTest.java @@ -29,4 +29,14 @@ void testKtlint() throws Exception { mavenRunner().withArguments("spotless:apply").runNoError(); assertFile(path).sameAsResource("kotlin/ktlint/basic.clean"); } + + @Test + void testKtlintEditorConfigOverride() throws Exception { + writePomWithKotlinSteps("truetrue"); + + String path = "src/main/kotlin/Main.kt"; + setFile(path).toResource("kotlin/ktlint/experimentalEditorConfigOverride.dirty"); + mavenRunner().withArguments("spotless:apply").runNoError(); + assertFile(path).sameAsResource("kotlin/ktlint/experimentalEditorConfigOverride.clean"); + } } From e4f1fc92a1c280c6b370530e6f64a69b8daa8296 Mon Sep 17 00:00:00 2001 From: Tormod Alf Try Tufteland Date: Fri, 16 Sep 2022 16:43:53 +0200 Subject: [PATCH 307/757] doc: add changes --- CHANGES.md | 2 ++ plugin-maven/CHANGES.md | 2 ++ 2 files changed, 4 insertions(+) diff --git a/CHANGES.md b/CHANGES.md index 23c20dc957..b0117a4bd5 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -10,6 +10,8 @@ This document is intended for Spotless developers. We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format (starting after version `1.27.0`). ## [Unreleased] +### Added +* Support for `editorConfigOverride` in `ktlint`, `plugin-maven`. ([#1335](https://github.com/diffplug/spotless/pull/1335) fixes [#1334](https://github.com/diffplug/spotless/issues/1334)) ## [2.30.0] - 2022-09-14 ### Added diff --git a/plugin-maven/CHANGES.md b/plugin-maven/CHANGES.md index 1ce37116a1..6046e7aed1 100644 --- a/plugin-maven/CHANGES.md +++ b/plugin-maven/CHANGES.md @@ -3,6 +3,8 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format (starting after version `1.27.0`). ## [Unreleased] +### Added +* Support for `editorConfigOverride` in `ktlint`, `plugin-maven`. ([#1335](https://github.com/diffplug/spotless/pull/1335) fixes [#1334](https://github.com/diffplug/spotless/issues/1334)) ## [2.26.0] - 2022-09-14 ### Added From 96803ae88ff4d0d4de554dc4a5f00fb1d4b47cdf Mon Sep 17 00:00:00 2001 From: Tormod Alf Try Tufteland Date: Sat, 17 Sep 2022 10:57:17 +0200 Subject: [PATCH 308/757] fix: linting --- .../com/diffplug/spotless/maven/kotlin/Ktlint.java | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/plugin-maven/src/main/java/com/diffplug/spotless/maven/kotlin/Ktlint.java b/plugin-maven/src/main/java/com/diffplug/spotless/maven/kotlin/Ktlint.java index 5792ee0611..45bda05065 100644 --- a/plugin-maven/src/main/java/com/diffplug/spotless/maven/kotlin/Ktlint.java +++ b/plugin-maven/src/main/java/com/diffplug/spotless/maven/kotlin/Ktlint.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,10 @@ */ package com.diffplug.spotless.maven.kotlin; +import java.util.Collections; +import java.util.HashMap; +import java.util.Map; + import org.apache.maven.plugins.annotations.Parameter; import com.diffplug.spotless.FormatterStep; @@ -22,10 +26,6 @@ import com.diffplug.spotless.maven.FormatterStepConfig; import com.diffplug.spotless.maven.FormatterStepFactory; -import java.util.Collections; -import java.util.HashMap; -import java.util.Map; - public class Ktlint implements FormatterStepFactory { @Parameter From 59c166a369e77867d28b453b94787111f36a96a7 Mon Sep 17 00:00:00 2001 From: Ned Twigg Date: Mon, 19 Sep 2022 13:02:20 -0700 Subject: [PATCH 309/757] Only changes are in plugin-maven, so that's the only changelog that should change. --- CHANGES.md | 2 -- 1 file changed, 2 deletions(-) diff --git a/CHANGES.md b/CHANGES.md index b0117a4bd5..23c20dc957 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -10,8 +10,6 @@ This document is intended for Spotless developers. We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format (starting after version `1.27.0`). ## [Unreleased] -### Added -* Support for `editorConfigOverride` in `ktlint`, `plugin-maven`. ([#1335](https://github.com/diffplug/spotless/pull/1335) fixes [#1334](https://github.com/diffplug/spotless/issues/1334)) ## [2.30.0] - 2022-09-14 ### Added From de9bb1f757bf2502551cd98dd8f371abf2d1a3fb Mon Sep 17 00:00:00 2001 From: circleci Date: Mon, 19 Sep 2022 20:09:52 +0000 Subject: [PATCH 310/757] Published maven/2.27.0 --- plugin-maven/CHANGES.md | 2 ++ plugin-maven/README.md | 4 ++-- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/plugin-maven/CHANGES.md b/plugin-maven/CHANGES.md index 6046e7aed1..6c3ff896a9 100644 --- a/plugin-maven/CHANGES.md +++ b/plugin-maven/CHANGES.md @@ -3,6 +3,8 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format (starting after version `1.27.0`). ## [Unreleased] + +## [2.27.0] - 2022-09-19 ### Added * Support for `editorConfigOverride` in `ktlint`, `plugin-maven`. ([#1335](https://github.com/diffplug/spotless/pull/1335) fixes [#1334](https://github.com/diffplug/spotless/issues/1334)) diff --git a/plugin-maven/README.md b/plugin-maven/README.md index a6a8491784..a7ab01cfa0 100644 --- a/plugin-maven/README.md +++ b/plugin-maven/README.md @@ -12,8 +12,8 @@ output = [ ].join('\n'); --> [![Maven central](https://img.shields.io/badge/mavencentral-com.diffplug.spotless%3Aspotless--maven--plugin-blue.svg)](https://search.maven.org/#search%7Cgav%7C1%7Cg%3A%22com.diffplug.spotless%22%20AND%20a%3A%22spotless-maven-plugin%22) -[![Javadoc](https://img.shields.io/badge/javadoc-yes-blue.svg)](https://javadoc.io/doc/com.diffplug.spotless/spotless-maven-plugin/2.26.0/index.html) -[![Changelog](https://img.shields.io/badge/changelog-2.26.0-brightgreen.svg)](CHANGES.md) +[![Javadoc](https://img.shields.io/badge/javadoc-yes-blue.svg)](https://javadoc.io/doc/com.diffplug.spotless/spotless-maven-plugin/2.27.0/index.html) +[![Changelog](https://img.shields.io/badge/changelog-2.27.0-brightgreen.svg)](CHANGES.md) [![Circle CI](https://circleci.com/gh/diffplug/spotless/tree/main.svg?style=shield)](https://circleci.com/gh/diffplug/spotless/tree/main) [![Live chat](https://img.shields.io/badge/gitter-chat-brightgreen.svg)](https://gitter.im/diffplug/spotless) From 92e21d9a64f6aa753695b83114e5ed6db022f6d9 Mon Sep 17 00:00:00 2001 From: "renovate[bot]" <29139614+renovate[bot]@users.noreply.github.com> Date: Tue, 20 Sep 2022 22:09:47 +0000 Subject: [PATCH 311/757] Update dependency org.junit.jupiter:junit-jupiter to v5.9.1 --- gradle.properties | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gradle.properties b/gradle.properties index 155ac981bc..b7bbe3ea6a 100644 --- a/gradle.properties +++ b/gradle.properties @@ -26,7 +26,7 @@ VER_SLF4J=[1.6,2.0[ # Used in multiple places VER_DURIAN=1.2.0 VER_JGIT=5.13.1.202206130422-r -VER_JUNIT=5.9.0 +VER_JUNIT=5.9.1 VER_ASSERTJ=3.23.1 VER_MOCKITO=4.8.0 From d99ee528b065046b153d208a718ee57734d84469 Mon Sep 17 00:00:00 2001 From: "renovate[bot]" <29139614+renovate[bot]@users.noreply.github.com> Date: Fri, 23 Sep 2022 22:03:23 +0000 Subject: [PATCH 312/757] Update dependency com.facebook:ktfmt to v0.41 --- lib/build.gradle | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/build.gradle b/lib/build.gradle index dfb2a38d73..dfd67e59ed 100644 --- a/lib/build.gradle +++ b/lib/build.gradle @@ -54,7 +54,7 @@ dependencies { palantirJavaFormatCompileOnly 'com.palantir.javaformat:palantir-java-format:1.1.0' - String VER_KTFMT = '0.40' + String VER_KTFMT = '0.41' 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") { From b0bb294147cd30966b88335391b6becb880526de Mon Sep 17 00:00:00 2001 From: "renovate[bot]" <29139614+renovate[bot]@users.noreply.github.com> Date: Mon, 26 Sep 2022 13:37:54 +0000 Subject: [PATCH 313/757] Update dependency com.palantir.javaformat:palantir-java-format to v2 --- lib/build.gradle | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/build.gradle b/lib/build.gradle index dfb2a38d73..ef10376f18 100644 --- a/lib/build.gradle +++ b/lib/build.gradle @@ -52,7 +52,7 @@ dependencies { sortPomCompileOnly 'com.github.ekryd.sortpom:sortpom-sorter:3.0.0' sortPomCompileOnly 'org.slf4j:slf4j-api:2.0.0' - palantirJavaFormatCompileOnly 'com.palantir.javaformat:palantir-java-format:1.1.0' + palantirJavaFormatCompileOnly 'com.palantir.javaformat:palantir-java-format:2.27.0' String VER_KTFMT = '0.40' ktfmtCompileOnly "com.facebook:ktfmt:$VER_KTFMT" From dc9f4291f80bcb15dd63721abbba70f4ab0c371a Mon Sep 17 00:00:00 2001 From: tison Date: Wed, 28 Sep 2022 21:18:52 +0800 Subject: [PATCH 314/757] fix: maven plugin should identify skip config key Signed-off-by: tison --- .../com/diffplug/spotless/maven/AbstractSpotlessMojo.java | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/plugin-maven/src/main/java/com/diffplug/spotless/maven/AbstractSpotlessMojo.java b/plugin-maven/src/main/java/com/diffplug/spotless/maven/AbstractSpotlessMojo.java index c68733f387..f163fa2802 100644 --- a/plugin-maven/src/main/java/com/diffplug/spotless/maven/AbstractSpotlessMojo.java +++ b/plugin-maven/src/main/java/com/diffplug/spotless/maven/AbstractSpotlessMojo.java @@ -91,6 +91,9 @@ public abstract class AbstractSpotlessMojo extends AbstractMojo { @Parameter(defaultValue = "${mojoExecution.goal}", required = true, readonly = true) private String goal; + @Parameter(defaultValue = "false") + private boolean skip; + @Parameter(property = "spotless.apply.skip", defaultValue = "false") private boolean applySkip; @@ -200,6 +203,10 @@ public final void execute() throws MojoExecutionException { } private boolean shouldSkip() { + if (skip) { + return true; + } + switch (goal) { case GOAL_CHECK: return checkSkip; @@ -208,6 +215,7 @@ private boolean shouldSkip() { default: break; } + return false; } From 622f3a0c0bdb679a9f3a9123ba598dd2e6201be7 Mon Sep 17 00:00:00 2001 From: tison Date: Wed, 28 Sep 2022 22:48:37 +0800 Subject: [PATCH 315/757] update CHANGES Signed-off-by: tison --- plugin-maven/CHANGES.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/plugin-maven/CHANGES.md b/plugin-maven/CHANGES.md index 6c3ff896a9..d46447ea38 100644 --- a/plugin-maven/CHANGES.md +++ b/plugin-maven/CHANGES.md @@ -3,6 +3,8 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format (starting after version `1.27.0`). ## [Unreleased] +### Fixed +* `skip` config key should work again now. ([#1353](https://github.com/diffplug/spotless/pull/1353) fixes [#1227](https://github.com/diffplug/spotless/issues/1227) and [#491](https://github.com/diffplug/spotless/issues/491)) ## [2.27.0] - 2022-09-19 ### Added From 7667a849d377b546d45350b77b65e0793e3d17dc Mon Sep 17 00:00:00 2001 From: circleci Date: Wed, 28 Sep 2022 17:29:42 +0000 Subject: [PATCH 316/757] Published maven/2.27.1 --- plugin-maven/CHANGES.md | 2 ++ plugin-maven/README.md | 4 ++-- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/plugin-maven/CHANGES.md b/plugin-maven/CHANGES.md index d46447ea38..33b8f2b03a 100644 --- a/plugin-maven/CHANGES.md +++ b/plugin-maven/CHANGES.md @@ -3,6 +3,8 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format (starting after version `1.27.0`). ## [Unreleased] + +## [2.27.1] - 2022-09-28 ### Fixed * `skip` config key should work again now. ([#1353](https://github.com/diffplug/spotless/pull/1353) fixes [#1227](https://github.com/diffplug/spotless/issues/1227) and [#491](https://github.com/diffplug/spotless/issues/491)) diff --git a/plugin-maven/README.md b/plugin-maven/README.md index a7ab01cfa0..b60cfa1a38 100644 --- a/plugin-maven/README.md +++ b/plugin-maven/README.md @@ -12,8 +12,8 @@ output = [ ].join('\n'); --> [![Maven central](https://img.shields.io/badge/mavencentral-com.diffplug.spotless%3Aspotless--maven--plugin-blue.svg)](https://search.maven.org/#search%7Cgav%7C1%7Cg%3A%22com.diffplug.spotless%22%20AND%20a%3A%22spotless-maven-plugin%22) -[![Javadoc](https://img.shields.io/badge/javadoc-yes-blue.svg)](https://javadoc.io/doc/com.diffplug.spotless/spotless-maven-plugin/2.27.0/index.html) -[![Changelog](https://img.shields.io/badge/changelog-2.27.0-brightgreen.svg)](CHANGES.md) +[![Javadoc](https://img.shields.io/badge/javadoc-yes-blue.svg)](https://javadoc.io/doc/com.diffplug.spotless/spotless-maven-plugin/2.27.1/index.html) +[![Changelog](https://img.shields.io/badge/changelog-2.27.1-brightgreen.svg)](CHANGES.md) [![Circle CI](https://circleci.com/gh/diffplug/spotless/tree/main.svg?style=shield)](https://circleci.com/gh/diffplug/spotless/tree/main) [![Live chat](https://img.shields.io/badge/gitter-chat-brightgreen.svg)](https://gitter.im/diffplug/spotless) From aa48b8d9f1b4b0785d33dbecd4acb96e5c39b1e1 Mon Sep 17 00:00:00 2001 From: Duo Zhang Date: Tue, 4 Oct 2022 00:58:47 +0800 Subject: [PATCH 317/757] Allow replacement to be null for ReplaceRegex of plugin maven --- .../com/diffplug/spotless/maven/generic/Replace.java | 12 +++++++----- .../spotless/maven/generic/ReplaceRegex.java | 12 +++++++----- 2 files changed, 14 insertions(+), 10 deletions(-) diff --git a/plugin-maven/src/main/java/com/diffplug/spotless/maven/generic/Replace.java b/plugin-maven/src/main/java/com/diffplug/spotless/maven/generic/Replace.java index 947ceee8e2..53967fd7d7 100644 --- a/plugin-maven/src/main/java/com/diffplug/spotless/maven/generic/Replace.java +++ b/plugin-maven/src/main/java/com/diffplug/spotless/maven/generic/Replace.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. @@ -35,10 +35,12 @@ public class Replace implements FormatterStepFactory { @Override public FormatterStep newFormatterStep(FormatterStepConfig config) { - if (name == null || search == null || replacement == null) { - throw new IllegalArgumentException("Must specify 'name', 'search' and 'replacement'."); + if (name == null || search == null) { + throw new IllegalArgumentException("Must specify 'name' and 'search'."); } - - return ReplaceStep.create(name, search, replacement); + // Use empty string if replacement is not provided. In pom.xml there is no way to specify + // an empty string as a property value as maven will always trim the value and if it is + // empty, maven will consider the property as not provided. + return ReplaceStep.create(name, search, replacement != null ? replacement : ""); } } diff --git a/plugin-maven/src/main/java/com/diffplug/spotless/maven/generic/ReplaceRegex.java b/plugin-maven/src/main/java/com/diffplug/spotless/maven/generic/ReplaceRegex.java index 243f14220e..9983aa8475 100644 --- a/plugin-maven/src/main/java/com/diffplug/spotless/maven/generic/ReplaceRegex.java +++ b/plugin-maven/src/main/java/com/diffplug/spotless/maven/generic/ReplaceRegex.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. @@ -35,10 +35,12 @@ public class ReplaceRegex implements FormatterStepFactory { @Override public FormatterStep newFormatterStep(FormatterStepConfig config) { - if (name == null || searchRegex == null || replacement == null) { - throw new IllegalArgumentException("Must specify 'name', 'searchRegex' and 'replacement'."); + if (name == null || searchRegex == null) { + throw new IllegalArgumentException("Must specify 'name' and 'searchRegex'."); } - - return ReplaceRegexStep.create(name, searchRegex, replacement); + // Use empty string if replacement is not provided. In pom.xml there is no way to specify + // an empty string as a property value as maven will always trim the value and if it is + // empty, maven will consider the property as not provided. + return ReplaceRegexStep.create(name, searchRegex, replacement != null ? replacement : ""); } } From 49892456496c283d23b47b6d4f0bc5f6a44c885e Mon Sep 17 00:00:00 2001 From: Ned Twigg Date: Mon, 10 Oct 2022 16:26:53 +0200 Subject: [PATCH 318/757] Update changelog. --- plugin-maven/CHANGES.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/plugin-maven/CHANGES.md b/plugin-maven/CHANGES.md index 33b8f2b03a..e42fd89add 100644 --- a/plugin-maven/CHANGES.md +++ b/plugin-maven/CHANGES.md @@ -3,6 +3,8 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format (starting after version `1.27.0`). ## [Unreleased] +### Fixed +* `replace` and `replaceRegex` steps now allow you to replace something with an empty string, previously this would generate a null pointer exception. (fixes [#1359](https://github.com/diffplug/spotless/issues/1359)) ## [2.27.1] - 2022-09-28 ### Fixed From 23784ba9e1774c91218a77e2b60ba12343b33c8c Mon Sep 17 00:00:00 2001 From: circleci Date: Mon, 10 Oct 2022 14:50:07 +0000 Subject: [PATCH 319/757] Published maven/2.27.2 --- plugin-maven/CHANGES.md | 2 ++ plugin-maven/README.md | 4 ++-- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/plugin-maven/CHANGES.md b/plugin-maven/CHANGES.md index e42fd89add..7da89e6712 100644 --- a/plugin-maven/CHANGES.md +++ b/plugin-maven/CHANGES.md @@ -3,6 +3,8 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format (starting after version `1.27.0`). ## [Unreleased] + +## [2.27.2] - 2022-10-10 ### Fixed * `replace` and `replaceRegex` steps now allow you to replace something with an empty string, previously this would generate a null pointer exception. (fixes [#1359](https://github.com/diffplug/spotless/issues/1359)) diff --git a/plugin-maven/README.md b/plugin-maven/README.md index b60cfa1a38..2a249357a6 100644 --- a/plugin-maven/README.md +++ b/plugin-maven/README.md @@ -12,8 +12,8 @@ output = [ ].join('\n'); --> [![Maven central](https://img.shields.io/badge/mavencentral-com.diffplug.spotless%3Aspotless--maven--plugin-blue.svg)](https://search.maven.org/#search%7Cgav%7C1%7Cg%3A%22com.diffplug.spotless%22%20AND%20a%3A%22spotless-maven-plugin%22) -[![Javadoc](https://img.shields.io/badge/javadoc-yes-blue.svg)](https://javadoc.io/doc/com.diffplug.spotless/spotless-maven-plugin/2.27.1/index.html) -[![Changelog](https://img.shields.io/badge/changelog-2.27.1-brightgreen.svg)](CHANGES.md) +[![Javadoc](https://img.shields.io/badge/javadoc-yes-blue.svg)](https://javadoc.io/doc/com.diffplug.spotless/spotless-maven-plugin/2.27.2/index.html) +[![Changelog](https://img.shields.io/badge/changelog-2.27.2-brightgreen.svg)](CHANGES.md) [![Circle CI](https://circleci.com/gh/diffplug/spotless/tree/main.svg?style=shield)](https://circleci.com/gh/diffplug/spotless/tree/main) [![Live chat](https://img.shields.io/badge/gitter-chat-brightgreen.svg)](https://gitter.im/diffplug/spotless) From 3d6da4b821e70c3b451e7234c5b6d053ab89cef4 Mon Sep 17 00:00:00 2001 From: Ned Twigg Date: Mon, 10 Oct 2022 17:58:50 +0200 Subject: [PATCH 320/757] Move the repositories block higher. --- build.gradle | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/build.gradle b/build.gradle index 16136e07ec..5766e6b85e 100644 --- a/build.gradle +++ b/build.gradle @@ -1,3 +1,6 @@ +repositories { + mavenCentral() +} apply from: rootProject.file('gradle/java-publish.gradle') apply from: rootProject.file('gradle/changelog.gradle') allprojects { @@ -5,9 +8,6 @@ allprojects { } apply from: rootProject.file('gradle/spotless-freshmark.gradle') -repositories { - mavenCentral() -} spotless { groovyGradle { target '*.gradle', 'gradle/*.gradle' From 744a2d9fdcaac0d8d3b45a03e30b32322c2e0ae2 Mon Sep 17 00:00:00 2001 From: Ned Twigg Date: Mon, 10 Oct 2022 18:14:13 +0200 Subject: [PATCH 321/757] Fixes. --- plugin-gradle/build.gradle | 2 +- plugin-maven/build.gradle | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/plugin-gradle/build.gradle b/plugin-gradle/build.gradle index 8fec4beb92..f1b3320b50 100644 --- a/plugin-gradle/build.gradle +++ b/plugin-gradle/build.gradle @@ -1,10 +1,10 @@ apply from: rootProject.file('gradle/changelog.gradle') ext.artifactId = project.artifactIdGradle version = spotlessChangelog.versionNext +apply plugin: 'java-library' apply from: rootProject.file('gradle/java-setup.gradle') apply from: rootProject.file('gradle/spotless-freshmark.gradle') -apply plugin: 'java-library' apply plugin: 'com.gradle.plugin-publish' apply plugin: 'java-gradle-plugin' diff --git a/plugin-maven/build.gradle b/plugin-maven/build.gradle index 174f10ef6a..b7ac8a36c8 100644 --- a/plugin-maven/build.gradle +++ b/plugin-maven/build.gradle @@ -5,6 +5,7 @@ buildscript { plugins { id 'cz.malohlava.visteg' version '1.0.5' // https://github.com/mmalohlava/gradle-visteg } +repositories { mavenCentral() } apply from: rootProject.file('gradle/changelog.gradle') apply from: rootProject.file('gradle/spotless-freshmark.gradle') From bd12e20cbb58ad4b51d63bb47b24911f364357ae Mon Sep 17 00:00:00 2001 From: Michael Ernst Date: Tue, 11 Oct 2022 10:36:42 -0700 Subject: [PATCH 322/757] Don't treat `@Value` as a type annotation --- .../java/com/diffplug/spotless/java/FormatAnnotationsStep.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/src/main/java/com/diffplug/spotless/java/FormatAnnotationsStep.java b/lib/src/main/java/com/diffplug/spotless/java/FormatAnnotationsStep.java index 2d01e305a0..d05a53ee1b 100644 --- a/lib/src/main/java/com/diffplug/spotless/java/FormatAnnotationsStep.java +++ b/lib/src/main/java/com/diffplug/spotless/java/FormatAnnotationsStep.java @@ -371,7 +371,7 @@ public final class FormatAnnotationsStep { "UpperBoundBottom", "UpperBoundLiteral", "UpperBoundUnknown", - "Value", + "ValueTypeAnno", "VariableNameDefaultBottom", "VariableNameDefaultMiddle", "VariableNameDefaultTop", From 26f8f59966c02ee2a1d238a5ffa34b6016018285 Mon Sep 17 00:00:00 2001 From: Michael Ernst Date: Tue, 11 Oct 2022 10:42:38 -0700 Subject: [PATCH 323/757] Add test cases for type annotations on classes --- ...FormatAnnotationsAccessModifiersInput.test | 57 +++++++++++++++++++ ...ormatAnnotationsAccessModifiersOutput.test | 57 +++++++++++++++++++ .../FormatAnnotationsTestInput.test | 9 +++ .../FormatAnnotationsTestOutput.test | 7 +++ 4 files changed, 130 insertions(+) create mode 100644 testlib/src/main/resources/java/formatannotations/FormatAnnotationsAccessModifiersInput.test create mode 100644 testlib/src/main/resources/java/formatannotations/FormatAnnotationsAccessModifiersOutput.test diff --git a/testlib/src/main/resources/java/formatannotations/FormatAnnotationsAccessModifiersInput.test b/testlib/src/main/resources/java/formatannotations/FormatAnnotationsAccessModifiersInput.test new file mode 100644 index 0000000000..6ac5519cc9 --- /dev/null +++ b/testlib/src/main/resources/java/formatannotations/FormatAnnotationsAccessModifiersInput.test @@ -0,0 +1,57 @@ +// Annotations in the wrong order. The preferred order is: +// * declaration annotations +// * access modifiers such as `public` +// * type annotations +// * type + +class FormatAnnotationsAccessModifiers { + + @Nullable public Object myMethod1() { + return null; + } + + @Nullable + public Object myMethod2() { + return null; + } + + @Nullable + public + Object myMethod3() { + return null; + } + + @Nullable + @Deprecated + public Object myMethod4() { + return null; + } + + @Override + @Nullable + @Deprecated + public Object myMethod5() { + return null; + } + + @Nullable @Deprecated public Object myMethod6() { + return null; + } +} + +@Deprecated +@Interned +@MustCall("close") +@SuppressWarnings +public class MyClass3 { + // No body +} + +public +@Deprecated +@SuppressWarnings +@Interned +@MustCall("close") +class MyClass4 { + // No body +} diff --git a/testlib/src/main/resources/java/formatannotations/FormatAnnotationsAccessModifiersOutput.test b/testlib/src/main/resources/java/formatannotations/FormatAnnotationsAccessModifiersOutput.test new file mode 100644 index 0000000000..6ac5519cc9 --- /dev/null +++ b/testlib/src/main/resources/java/formatannotations/FormatAnnotationsAccessModifiersOutput.test @@ -0,0 +1,57 @@ +// Annotations in the wrong order. The preferred order is: +// * declaration annotations +// * access modifiers such as `public` +// * type annotations +// * type + +class FormatAnnotationsAccessModifiers { + + @Nullable public Object myMethod1() { + return null; + } + + @Nullable + public Object myMethod2() { + return null; + } + + @Nullable + public + Object myMethod3() { + return null; + } + + @Nullable + @Deprecated + public Object myMethod4() { + return null; + } + + @Override + @Nullable + @Deprecated + public Object myMethod5() { + return null; + } + + @Nullable @Deprecated public Object myMethod6() { + return null; + } +} + +@Deprecated +@Interned +@MustCall("close") +@SuppressWarnings +public class MyClass3 { + // No body +} + +public +@Deprecated +@SuppressWarnings +@Interned +@MustCall("close") +class MyClass4 { + // No body +} diff --git a/testlib/src/main/resources/java/formatannotations/FormatAnnotationsTestInput.test b/testlib/src/main/resources/java/formatannotations/FormatAnnotationsTestInput.test index fb711451d1..b93631db5a 100644 --- a/testlib/src/main/resources/java/formatannotations/FormatAnnotationsTestInput.test +++ b/testlib/src/main/resources/java/formatannotations/FormatAnnotationsTestInput.test @@ -75,3 +75,12 @@ class FormatAnnotationsTest { @Localized String localized; } + +@Deprecated +@SuppressWarnings +public +@Interned +@MustCall("close") +class MyClass1 { + // No body +} diff --git a/testlib/src/main/resources/java/formatannotations/FormatAnnotationsTestOutput.test b/testlib/src/main/resources/java/formatannotations/FormatAnnotationsTestOutput.test index ca37e66d86..6daabf198c 100644 --- a/testlib/src/main/resources/java/formatannotations/FormatAnnotationsTestOutput.test +++ b/testlib/src/main/resources/java/formatannotations/FormatAnnotationsTestOutput.test @@ -49,3 +49,10 @@ class FormatAnnotationsTest { @Localized String localized; } + +@Deprecated +@SuppressWarnings +public +@Interned @MustCall("close") class MyClass1 { + // No body +} From 4b13e329e25a872c125d8f4c8eb8b05a0ca60d90 Mon Sep 17 00:00:00 2001 From: Michael Ernst Date: Thu, 13 Oct 2022 10:25:39 -0700 Subject: [PATCH 324/757] Add changelog --- CHANGES.md | 2 ++ plugin-gradle/CHANGES.md | 2 ++ plugin-maven/CHANGES.md | 2 ++ 3 files changed, 6 insertions(+) diff --git a/CHANGES.md b/CHANGES.md index 23c20dc957..dc0bd38c60 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -10,6 +10,8 @@ This document is intended for Spotless developers. We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format (starting after version `1.27.0`). ## [Unreleased] +### Fixed +* Don't treat `@Value` as a type annotation [#1367](https://github.com/diffplug/spotless/pull/1367) ## [2.30.0] - 2022-09-14 ### Added diff --git a/plugin-gradle/CHANGES.md b/plugin-gradle/CHANGES.md index f7c15244d5..a8adac938d 100644 --- a/plugin-gradle/CHANGES.md +++ b/plugin-gradle/CHANGES.md @@ -3,6 +3,8 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format (starting after version `3.27.0`). ## [Unreleased] +### Fixed +* Don't treat `@Value` as a type annotation [#1367](https://github.com/diffplug/spotless/pull/1367) ## [6.11.0] - 2022-09-14 ### Added diff --git a/plugin-maven/CHANGES.md b/plugin-maven/CHANGES.md index 1ce37116a1..268cf97322 100644 --- a/plugin-maven/CHANGES.md +++ b/plugin-maven/CHANGES.md @@ -3,6 +3,8 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format (starting after version `1.27.0`). ## [Unreleased] +### Fixed +* Don't treat `@Value` as a type annotation [#1367](https://github.com/diffplug/spotless/pull/1367) ## [2.26.0] - 2022-09-14 ### Added From e79625731bdef4bdb0a58557975231c52f1339ff Mon Sep 17 00:00:00 2001 From: Michael Ernst Date: Thu, 13 Oct 2022 10:47:02 -0700 Subject: [PATCH 325/757] Add invocation of test --- .../spotless/maven/java/FormatAnnotationsStepTest.java | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/plugin-maven/src/test/java/com/diffplug/spotless/maven/java/FormatAnnotationsStepTest.java b/plugin-maven/src/test/java/com/diffplug/spotless/maven/java/FormatAnnotationsStepTest.java index 8560b73fd4..972a4b4f7f 100644 --- a/plugin-maven/src/test/java/com/diffplug/spotless/maven/java/FormatAnnotationsStepTest.java +++ b/plugin-maven/src/test/java/com/diffplug/spotless/maven/java/FormatAnnotationsStepTest.java @@ -30,4 +30,14 @@ void testFormatAnnotations() throws Exception { mavenRunner().withArguments("spotless:apply").runNoError(); assertFile(path).sameAsResource("java/formatannotations/FormatAnnotationsTestOutput.test"); } + + @Test + void testFormatAnnotationsAccessModifiers() throws Exception { + writePomWithJavaSteps(""); + + String path = "src/main/java/test.java"; + setFile(path).toResource("java/formatannotations/FormatAnnotationsAccessModifiersInput.test"); + mavenRunner().withArguments("spotless:apply").runNoError(); + assertFile(path).sameAsResource("java/formatannotations/FormatAnnotationsAccessModifiersOutput.test"); + } } From 276810c5109831dcd04bfc9932a1e84b2afb67d1 Mon Sep 17 00:00:00 2001 From: Michael Ernst Date: Thu, 13 Oct 2022 14:37:50 -0700 Subject: [PATCH 326/757] Add tests, fix expected output --- ...FormatAnnotationsAccessModifiersInput.test | 6 +++++ ...ormatAnnotationsAccessModifiersOutput.test | 25 ++++++++----------- 2 files changed, 17 insertions(+), 14 deletions(-) diff --git a/testlib/src/main/resources/java/formatannotations/FormatAnnotationsAccessModifiersInput.test b/testlib/src/main/resources/java/formatannotations/FormatAnnotationsAccessModifiersInput.test index 6ac5519cc9..13546f9a84 100644 --- a/testlib/src/main/resources/java/formatannotations/FormatAnnotationsAccessModifiersInput.test +++ b/testlib/src/main/resources/java/formatannotations/FormatAnnotationsAccessModifiersInput.test @@ -27,6 +27,12 @@ class FormatAnnotationsAccessModifiers { return null; } + @Deprecated + @Nullable + public Object myMethod4a() { + return null; + } + @Override @Nullable @Deprecated diff --git a/testlib/src/main/resources/java/formatannotations/FormatAnnotationsAccessModifiersOutput.test b/testlib/src/main/resources/java/formatannotations/FormatAnnotationsAccessModifiersOutput.test index 6ac5519cc9..ffc6169c4c 100644 --- a/testlib/src/main/resources/java/formatannotations/FormatAnnotationsAccessModifiersOutput.test +++ b/testlib/src/main/resources/java/formatannotations/FormatAnnotationsAccessModifiersOutput.test @@ -10,26 +10,27 @@ class FormatAnnotationsAccessModifiers { return null; } - @Nullable - public Object myMethod2() { + @Nullable public Object myMethod2() { return null; } - @Nullable - public + @Nullable public Object myMethod3() { return null; } - @Nullable - @Deprecated + @Nullable @Deprecated public Object myMethod4() { return null; } - @Override - @Nullable @Deprecated + @Nullable public Object myMethod4a() { + return null; + } + + @Override + @Nullable @Deprecated public Object myMethod5() { return null; } @@ -40,9 +41,7 @@ class FormatAnnotationsAccessModifiers { } @Deprecated -@Interned -@MustCall("close") -@SuppressWarnings +@Interned @MustCall("close") @SuppressWarnings public class MyClass3 { // No body } @@ -50,8 +49,6 @@ public class MyClass3 { public @Deprecated @SuppressWarnings -@Interned -@MustCall("close") -class MyClass4 { +@Interned @MustCall("close") class MyClass4 { // No body } From 650374d4be3aa9489f4f2580d3bc96957c40257f Mon Sep 17 00:00:00 2001 From: "renovate[bot]" <29139614+renovate[bot]@users.noreply.github.com> Date: Mon, 17 Oct 2022 07:07:09 +0000 Subject: [PATCH 327/757] fix(deps): update dependency com.github.spotbugs:spotbugs-annotations to v4.7.3 --- gradle.properties | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gradle.properties b/gradle.properties index b7bbe3ea6a..31a94db7df 100644 --- a/gradle.properties +++ b/gradle.properties @@ -17,7 +17,7 @@ artifactIdGradle=spotless-plugin-gradle # Build requirements VER_JAVA=1.8 -VER_SPOTBUGS=4.7.2 +VER_SPOTBUGS=4.7.3 VER_JSR_305=3.0.2 # Dependencies provided by Spotless plugin From 28ca68cc4552dc530132161934fa54260494fbc4 Mon Sep 17 00:00:00 2001 From: "renovate[bot]" <29139614+renovate[bot]@users.noreply.github.com> Date: Wed, 19 Oct 2022 00:55:20 +0000 Subject: [PATCH 328/757] chore(deps): update plugin com.github.spotbugs to v5.0.13 --- settings.gradle | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/settings.gradle b/settings.gradle index 47699727c4..0ce22a9a8c 100644 --- a/settings.gradle +++ b/settings.gradle @@ -6,7 +6,7 @@ pluginManagement { // https://github.com/gradle-nexus/publish-plugin/releases id 'io.github.gradle-nexus.publish-plugin' version '1.1.0' // https://github.com/spotbugs/spotbugs-gradle-plugin/releases - id 'com.github.spotbugs' version '5.0.12' + id 'com.github.spotbugs' version '5.0.13' // https://github.com/diffplug/spotless-changelog id 'com.diffplug.spotless-changelog' version '2.4.0' // https://github.com/diffplug/goomph/blob/main/CHANGES.md From 707e50edb0a5d54d9634d28acfa403b209d57740 Mon Sep 17 00:00:00 2001 From: Bruno Medeiros Date: Wed, 19 Oct 2022 23:12:34 +0800 Subject: [PATCH 329/757] fix(ktlint): support ktlint_disabled_rules in 0.47+ --- .../glue/ktlint/compat/KtLintCompat0Dot47Dot0Adapter.java | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/lib/src/compatKtLint0Dot47Dot0/java/com/diffplug/spotless/glue/ktlint/compat/KtLintCompat0Dot47Dot0Adapter.java b/lib/src/compatKtLint0Dot47Dot0/java/com/diffplug/spotless/glue/ktlint/compat/KtLintCompat0Dot47Dot0Adapter.java index 842294a5cc..66274fd0ef 100644 --- a/lib/src/compatKtLint0Dot47Dot0/java/com/diffplug/spotless/glue/ktlint/compat/KtLintCompat0Dot47Dot0Adapter.java +++ b/lib/src/compatKtLint0Dot47Dot0/java/com/diffplug/spotless/glue/ktlint/compat/KtLintCompat0Dot47Dot0Adapter.java @@ -100,9 +100,13 @@ private static EditorConfigOverride createEditorConfigOverride(final List .filter(rule -> rule instanceof UsesEditorConfigProperties) .flatMap(rule -> ((UsesEditorConfigProperties) rule).getEditorConfigProperties().stream()); + // get complete list of supported properties in DefaultEditorConfigProperties.INSTANCE + List> editorConfigProperties = DefaultEditorConfigProperties.INSTANCE.getEditorConfigProperties(); + editorConfigProperties.add(DefaultEditorConfigProperties.INSTANCE.getKtlintDisabledRulesProperty()); + // Create a mapping of properties to their names based on rule properties and default properties Map> supportedProperties = Stream - .concat(ruleProperties, DefaultEditorConfigProperties.INSTANCE.getEditorConfigProperties().stream()) + .concat(ruleProperties, editorConfigProperties.stream()) .distinct() .collect(Collectors.toMap(property -> property.getType().getName(), property -> property)); From 6824821bcd072a0a35370a2dc4604d8635fe35c9 Mon Sep 17 00:00:00 2001 From: Bruno Medeiros Date: Fri, 21 Oct 2022 10:14:38 +0800 Subject: [PATCH 330/757] user mutable list implementation before adding element --- .../glue/ktlint/compat/KtLintCompat0Dot47Dot0Adapter.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/lib/src/compatKtLint0Dot47Dot0/java/com/diffplug/spotless/glue/ktlint/compat/KtLintCompat0Dot47Dot0Adapter.java b/lib/src/compatKtLint0Dot47Dot0/java/com/diffplug/spotless/glue/ktlint/compat/KtLintCompat0Dot47Dot0Adapter.java index 66274fd0ef..757ffc922b 100644 --- a/lib/src/compatKtLint0Dot47Dot0/java/com/diffplug/spotless/glue/ktlint/compat/KtLintCompat0Dot47Dot0Adapter.java +++ b/lib/src/compatKtLint0Dot47Dot0/java/com/diffplug/spotless/glue/ktlint/compat/KtLintCompat0Dot47Dot0Adapter.java @@ -17,6 +17,7 @@ import static java.util.Collections.emptySet; +import java.util.ArrayList; import java.util.LinkedHashSet; import java.util.List; import java.util.Map; @@ -101,7 +102,7 @@ private static EditorConfigOverride createEditorConfigOverride(final List .flatMap(rule -> ((UsesEditorConfigProperties) rule).getEditorConfigProperties().stream()); // get complete list of supported properties in DefaultEditorConfigProperties.INSTANCE - List> editorConfigProperties = DefaultEditorConfigProperties.INSTANCE.getEditorConfigProperties(); + List> editorConfigProperties = new ArrayList<>(DefaultEditorConfigProperties.INSTANCE.getEditorConfigProperties()); editorConfigProperties.add(DefaultEditorConfigProperties.INSTANCE.getKtlintDisabledRulesProperty()); // Create a mapping of properties to their names based on rule properties and default properties From fb3f658631df27bd98cf5bb0a54dae13be4b9818 Mon Sep 17 00:00:00 2001 From: Bruno Medeiros Date: Fri, 21 Oct 2022 10:15:04 +0800 Subject: [PATCH 331/757] add change log entries --- CHANGES.md | 1 + plugin-gradle/CHANGES.md | 1 + plugin-maven/CHANGES.md | 1 + 3 files changed, 3 insertions(+) diff --git a/CHANGES.md b/CHANGES.md index dc0bd38c60..f6671d2191 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -12,6 +12,7 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format ( ## [Unreleased] ### Fixed * Don't treat `@Value` as a type annotation [#1367](https://github.com/diffplug/spotless/pull/1367) +* Support `ktlint_disabled_rules` in `ktlint` 0.47.x [#1378](https://github.com/diffplug/spotless/pull/1378) ## [2.30.0] - 2022-09-14 ### Added diff --git a/plugin-gradle/CHANGES.md b/plugin-gradle/CHANGES.md index a8adac938d..5acd85ddc8 100644 --- a/plugin-gradle/CHANGES.md +++ b/plugin-gradle/CHANGES.md @@ -5,6 +5,7 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format ( ## [Unreleased] ### Fixed * Don't treat `@Value` as a type annotation [#1367](https://github.com/diffplug/spotless/pull/1367) +* Support `ktlint_disabled_rules` in `ktlint` 0.47.x [#1378](https://github.com/diffplug/spotless/pull/1378) ## [6.11.0] - 2022-09-14 ### Added diff --git a/plugin-maven/CHANGES.md b/plugin-maven/CHANGES.md index 75659026d4..b08a2366fd 100644 --- a/plugin-maven/CHANGES.md +++ b/plugin-maven/CHANGES.md @@ -5,6 +5,7 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format ( ## [Unreleased] ### Fixed * Don't treat `@Value` as a type annotation [#1367](https://github.com/diffplug/spotless/pull/1367) +* Support `ktlint_disabled_rules` in `ktlint` 0.47.x [#1378](https://github.com/diffplug/spotless/pull/1378) ## [2.27.2] - 2022-10-10 ### Fixed From ec2e1b2aa274476a1c7a52741b98c7905fd7ebbc Mon Sep 17 00:00:00 2001 From: "renovate[bot]" <29139614+renovate[bot]@users.noreply.github.com> Date: Fri, 21 Oct 2022 19:58:11 +0000 Subject: [PATCH 332/757] fix(deps): update dependency org.mockito:mockito-core to v4.8.1 --- gradle.properties | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gradle.properties b/gradle.properties index 31a94db7df..5df7719934 100644 --- a/gradle.properties +++ b/gradle.properties @@ -28,7 +28,7 @@ VER_DURIAN=1.2.0 VER_JGIT=5.13.1.202206130422-r VER_JUNIT=5.9.1 VER_ASSERTJ=3.23.1 -VER_MOCKITO=4.8.0 +VER_MOCKITO=4.8.1 # Used for Maven Plugin VER_MAVEN_API=3.0 From bff7c23af18d9a65f0f1baedcd190edd2e832807 Mon Sep 17 00:00:00 2001 From: Jasper Vandemalle Date: Wed, 26 Oct 2022 11:55:07 +0200 Subject: [PATCH 333/757] Fix SortPomStepStep typo --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index fb1a3670e6..605305bd29 100644 --- a/README.md +++ b/README.md @@ -71,7 +71,7 @@ lib('markdown.FreshMarkStep') +'{{yes}} | {{no}} lib('markdown.FlexmarkStep') +'{{no}} | {{yes}} | {{no}} | {{no}} |', lib('npm.PrettierFormatterStep') +'{{yes}} | {{yes}} | {{no}} | {{no}} |', lib('npm.TsFmtFormatterStep') +'{{yes}} | {{yes}} | {{no}} | {{no}} |', -lib('pom.SortPomStepStep') +'{{no}} | {{yes}} | {{no}} | {{no}} |', +lib('pom.SortPomStep') +'{{no}} | {{yes}} | {{no}} | {{no}} |', lib('python.BlackStep') +'{{yes}} | {{no}} | {{no}} | {{no}} |', lib('scala.ScalaFmtStep') +'{{yes}} | {{yes}} | {{yes}} | {{no}} |', lib('sql.DBeaverSQLFormatterStep') +'{{yes}} | {{yes}} | {{yes}} | {{no}} |', @@ -115,7 +115,7 @@ extra('wtp.EclipseWtpFormatterStep') +'{{yes}} | {{yes}} | [`markdown.FlexmarkStep`](lib/src/main/java/com/diffplug/spotless/markdown/FlexmarkStep.java) | :white_large_square: | :+1: | :white_large_square: | :white_large_square: | | [`npm.PrettierFormatterStep`](lib/src/main/java/com/diffplug/spotless/npm/PrettierFormatterStep.java) | :+1: | :+1: | :white_large_square: | :white_large_square: | | [`npm.TsFmtFormatterStep`](lib/src/main/java/com/diffplug/spotless/npm/TsFmtFormatterStep.java) | :+1: | :+1: | :white_large_square: | :white_large_square: | -| [`pom.SortPomStepStep`](lib/src/main/java/com/diffplug/spotless/pom/SortPomStepStep.java) | :white_large_square: | :+1: | :white_large_square: | :white_large_square: | +| [`pom.SortPomStep`](lib/src/main/java/com/diffplug/spotless/pom/SortPomStep.java) | :white_large_square: | :+1: | :white_large_square: | :white_large_square: | | [`python.BlackStep`](lib/src/main/java/com/diffplug/spotless/python/BlackStep.java) | :+1: | :white_large_square: | :white_large_square: | :white_large_square: | | [`scala.ScalaFmtStep`](lib/src/main/java/com/diffplug/spotless/scala/ScalaFmtStep.java) | :+1: | :+1: | :+1: | :white_large_square: | | [`sql.DBeaverSQLFormatterStep`](lib/src/main/java/com/diffplug/spotless/sql/DBeaverSQLFormatterStep.java) | :+1: | :+1: | :+1: | :white_large_square: | From be4892f9d300d507225e65169c6f2a0e84afcb53 Mon Sep 17 00:00:00 2001 From: "renovate[bot]" <29139614+renovate[bot]@users.noreply.github.com> Date: Tue, 1 Nov 2022 01:32:49 +0000 Subject: [PATCH 334/757] fix(deps): update dependency org.scalameta:scalafmt-core_2.13 to v3.6.1 --- lib/build.gradle | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/build.gradle b/lib/build.gradle index dfb2a38d73..34f04371d6 100644 --- a/lib/build.gradle +++ b/lib/build.gradle @@ -91,7 +91,7 @@ dependencies { compatKtLint0Dot47Dot0CompileOnly 'com.pinterest.ktlint:ktlint-ruleset-experimental:0.47.0' compatKtLint0Dot47Dot0CompileOnly 'com.pinterest.ktlint:ktlint-ruleset-standard:0.47.0' - String VER_SCALAFMT="3.5.9" + String VER_SCALAFMT="3.6.1" scalafmtCompileOnly "org.scalameta:scalafmt-core_2.13:$VER_SCALAFMT" String VER_DIKTAT = "1.2.3" From 3785b1be4ab93a906fa933a317a6877968239201 Mon Sep 17 00:00:00 2001 From: jochenberger Date: Thu, 3 Nov 2022 14:56:07 +0100 Subject: [PATCH 335/757] Fix link --- plugin-gradle/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugin-gradle/README.md b/plugin-gradle/README.md index 29e748295e..7f5590da21 100644 --- a/plugin-gradle/README.md +++ b/plugin-gradle/README.md @@ -303,7 +303,7 @@ spotless { ### eclipse groovy -[homepage](https://github.com/groovy/groovy-eclipse/wiki). [changelog](https://github.com/groovy/groovy-eclipse/releases). [compatible versions](https://github.com/diffplug/spotless/tree/main/lib-extra/src/main/resources/com/diffplug/spotless/extra/groovy_eclipse_formatter). The Groovy formatter uses some of the [eclipse jdt](#eclipse-jdt) configuration parameters in addition to groovy-specific ones. All parameters can be configured within a single file, like the Java properties file [greclipse.properties](../testlib/src/main/resources/groovy/greclipse/format/greclipse.properties) in the previous example. The formatter step can also load the [exported Eclipse properties](../ECLIPSE_SCREENSHOTS.md) and augment it with the `.metadata/.plugins/org.eclipse.core.runtime/.settings/org.codehaus.groovy.eclipse.ui.prefs` from your Eclipse workspace as shown below. +[homepage](https://github.com/groovy/groovy-eclipse/wiki). [changelog](https://github.com/groovy/groovy-eclipse/releases). [compatible versions](https://github.com/diffplug/spotless/tree/main/lib-extra/src/main/resources/com/diffplug/spotless/extra/eclipse_groovy_formatter). The Groovy formatter uses some of the [eclipse jdt](#eclipse-jdt) configuration parameters in addition to groovy-specific ones. All parameters can be configured within a single file, like the Java properties file [greclipse.properties](../testlib/src/main/resources/groovy/greclipse/format/greclipse.properties) in the previous example. The formatter step can also load the [exported Eclipse properties](../ECLIPSE_SCREENSHOTS.md) and augment it with the `.metadata/.plugins/org.eclipse.core.runtime/.settings/org.codehaus.groovy.eclipse.ui.prefs` from your Eclipse workspace as shown below. ```gradle spotless { From 8d4d944eaff35a7e372e79517b0b67f91dde9400 Mon Sep 17 00:00:00 2001 From: "renovate[bot]" <29139614+renovate[bot]@users.noreply.github.com> Date: Fri, 11 Nov 2022 12:04:59 +0000 Subject: [PATCH 336/757] chore(deps): update plugin com.gradle.plugin-publish to v1.1.0 --- settings.gradle | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/settings.gradle b/settings.gradle index 0ce22a9a8c..6184ab802f 100644 --- a/settings.gradle +++ b/settings.gradle @@ -2,7 +2,7 @@ pluginManagement { plugins { id 'com.diffplug.spotless' version '6.11.0' // https://plugins.gradle.org/plugin/com.gradle.plugin-publish - id 'com.gradle.plugin-publish' version '1.0.0' + id 'com.gradle.plugin-publish' version '1.1.0' // https://github.com/gradle-nexus/publish-plugin/releases id 'io.github.gradle-nexus.publish-plugin' version '1.1.0' // https://github.com/spotbugs/spotbugs-gradle-plugin/releases From e8133131e12e3ba1a95257770376f59b64903ebf Mon Sep 17 00:00:00 2001 From: "renovate[bot]" <29139614+renovate[bot]@users.noreply.github.com> Date: Mon, 14 Nov 2022 20:13:44 +0000 Subject: [PATCH 337/757] fix(deps): update dependency org.mockito:mockito-core to v4.9.0 --- gradle.properties | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gradle.properties b/gradle.properties index 5df7719934..fc2b2b43da 100644 --- a/gradle.properties +++ b/gradle.properties @@ -28,7 +28,7 @@ VER_DURIAN=1.2.0 VER_JGIT=5.13.1.202206130422-r VER_JUNIT=5.9.1 VER_ASSERTJ=3.23.1 -VER_MOCKITO=4.8.1 +VER_MOCKITO=4.9.0 # Used for Maven Plugin VER_MAVEN_API=3.0 From 9773159231029cb23212d7a2b4656d508dc8525c Mon Sep 17 00:00:00 2001 From: "renovate[bot]" <29139614+renovate[bot]@users.noreply.github.com> Date: Tue, 15 Nov 2022 17:15:34 +0000 Subject: [PATCH 338/757] fix(deps): update dependency org.cqfn.diktat:diktat-rules to v1.2.4.2 --- lib/build.gradle | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/build.gradle b/lib/build.gradle index dfb2a38d73..cf3216ade6 100644 --- a/lib/build.gradle +++ b/lib/build.gradle @@ -94,7 +94,7 @@ dependencies { String VER_SCALAFMT="3.5.9" scalafmtCompileOnly "org.scalameta:scalafmt-core_2.13:$VER_SCALAFMT" - String VER_DIKTAT = "1.2.3" + String VER_DIKTAT = "1.2.4.2" diktatCompileOnly "org.cqfn.diktat:diktat-rules:$VER_DIKTAT" // used for markdown formatting From 35a56eaed731ea5d43786fd7c5a2ab4fc8d3dff4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Aur=C3=A9lien=20Mino?= Date: Sun, 20 Nov 2022 00:37:49 +0100 Subject: [PATCH 339/757] Support for group of imports without blank lines between groups To keep compatibility with existing configuration, a special delimiter `|` is introduced to separate subgroup of imports inside a group. For example "java|javax" will not generate a blank line between the java group and the javax group. The notion of ImportsGroup has been introduced for clarification, allowing code has been simplification. Fixes #1375 --- CHANGES.md | 1 + .../spotless/java/ImportSorterImpl.java | 174 ++++++++---------- plugin-gradle/README.md | 4 +- plugin-maven/README.md | 8 +- .../JavaCodeSortedImportsSubgroups.test | 16 ++ .../JavaCodeUnsortedImportsSubgroups.test | 15 ++ .../spotless/java/ImportOrderStepTest.java | 6 + 7 files changed, 119 insertions(+), 105 deletions(-) create mode 100644 testlib/src/main/resources/java/importsorter/JavaCodeSortedImportsSubgroups.test create mode 100644 testlib/src/main/resources/java/importsorter/JavaCodeUnsortedImportsSubgroups.test diff --git a/CHANGES.md b/CHANGES.md index f6671d2191..4bd52e1aa0 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -13,6 +13,7 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format ( ### Fixed * Don't treat `@Value` as a type annotation [#1367](https://github.com/diffplug/spotless/pull/1367) * Support `ktlint_disabled_rules` in `ktlint` 0.47.x [#1378](https://github.com/diffplug/spotless/pull/1378) +* ImportOrder: support groups of imports without blank lines [#1401](https://github.com/diffplug/spotless/pull/1401) ## [2.30.0] - 2022-09-14 ### Added diff --git a/lib/src/main/java/com/diffplug/spotless/java/ImportSorterImpl.java b/lib/src/main/java/com/diffplug/spotless/java/ImportSorterImpl.java index ec075ffedd..6dd8d58ba4 100644 --- a/lib/src/main/java/com/diffplug/spotless/java/ImportSorterImpl.java +++ b/lib/src/main/java/com/diffplug/spotless/java/ImportSorterImpl.java @@ -17,6 +17,8 @@ import java.io.Serializable; import java.util.*; +import java.util.stream.Collectors; +import java.util.stream.Stream; import javax.annotation.Nullable; @@ -25,12 +27,41 @@ // which itself is licensed under the Apache 2.0 license. final class ImportSorterImpl { - private final List template = new ArrayList<>(); + private static final String CATCH_ALL_SUBGROUP = ""; + private static final String STATIC_KEYWORD = "static "; + private static final String STATIC_SYMBOL = "\\#"; + private static final String SUBGROUP_SEPARATOR = "|"; + + private final List importsGroups; private final Map> matchingImports = new HashMap<>(); private final List notMatching = new ArrayList<>(); private final Set allImportOrderItems = new HashSet<>(); private final Comparator ordering; + // An ImportsGroup is a group of imports ; each group is separated by blank lines. + // A group is composed of subgroups : imports are sorted by subgroup. + private static class ImportsGroup { + + private final List subGroups; + + public ImportsGroup(String importOrder) { + this.subGroups = Stream.of(importOrder.split("\\" + SUBGROUP_SEPARATOR)) + .map(this::normalizeStatic) + .collect(Collectors.toList()); + } + + private String normalizeStatic(String subgroup) { + if (subgroup.startsWith(STATIC_SYMBOL)) { + return subgroup.replace(STATIC_SYMBOL, STATIC_KEYWORD); + } + return subgroup; + } + + public List getSubGroups() { + return subGroups; + } + } + static List sort(List imports, List importsOrder, boolean wildcardsLast, String lineFormat) { ImportSorterImpl importsSorter = new ImportSorterImpl(importsOrder, wildcardsLast); return importsSorter.sort(imports, lineFormat); @@ -40,43 +71,42 @@ private List sort(List imports, String lineFormat) { filterMatchingImports(imports); mergeNotMatchingItems(false); mergeNotMatchingItems(true); - mergeMatchingItems(); + List sortedImported = mergeMatchingItems(); - return getResult(lineFormat); + return getResult(sortedImported, lineFormat); } private ImportSorterImpl(List importOrder, boolean wildcardsLast) { - List importOrderCopy = new ArrayList<>(importOrder); - normalizeStaticOrderItems(importOrderCopy); - putStaticItemIfNotExists(importOrderCopy); - template.addAll(importOrderCopy); + importsGroups = importOrder.stream().filter(Objects::nonNull).map(ImportsGroup::new).collect(Collectors.toList()); + putStaticItemIfNotExists(importsGroups); + putCatchAllGroupIfNotExists(importsGroups); + ordering = new OrderingComparator(wildcardsLast); - this.allImportOrderItems.addAll(importOrderCopy); + + List subgroups = importsGroups.stream().map(ImportsGroup::getSubGroups).flatMap(Collection::stream).collect(Collectors.toList()); + this.allImportOrderItems.addAll(subgroups); } - private static void putStaticItemIfNotExists(List allImportOrderItems) { - boolean contains = false; + private void putStaticItemIfNotExists(List importsGroups) { + boolean catchAllSubGroupExist = importsGroups.stream().anyMatch(group -> group.getSubGroups().contains(STATIC_KEYWORD)); + if (catchAllSubGroupExist) { + return; + } + int indexOfFirstStatic = 0; - for (int i = 0; i < allImportOrderItems.size(); i++) { - String allImportOrderItem = allImportOrderItems.get(i); - if (allImportOrderItem.equals("static ")) { - contains = true; - } - if (allImportOrderItem.startsWith("static ")) { + for (int i = 0; i < importsGroups.size(); i++) { + boolean subgroupMatch = importsGroups.get(i).getSubGroups().stream().anyMatch(subgroup -> subgroup.startsWith(STATIC_KEYWORD)); + if (subgroupMatch) { indexOfFirstStatic = i; } } - if (!contains) { - allImportOrderItems.add(indexOfFirstStatic, "static "); - } + importsGroups.add(indexOfFirstStatic, new ImportsGroup(STATIC_KEYWORD)); } - private static void normalizeStaticOrderItems(List allImportOrderItems) { - for (int i = 0; i < allImportOrderItems.size(); i++) { - String s = allImportOrderItems.get(i); - if (s.startsWith("\\#")) { - allImportOrderItems.set(i, s.replace("\\#", "static ")); - } + private void putCatchAllGroupIfNotExists(List importsGroups) { + boolean catchAllSubGroupExist = importsGroups.stream().anyMatch(group -> group.getSubGroups().contains(CATCH_ALL_SUBGROUP)); + if (!catchAllSubGroupExist) { + importsGroups.add(new ImportsGroup(CATCH_ALL_SUBGROUP)); } } @@ -87,9 +117,7 @@ private void filterMatchingImports(List imports) { for (String anImport : imports) { String orderItem = getBestMatchingImportOrderItem(anImport); if (orderItem != null) { - if (!matchingImports.containsKey(orderItem)) { - matchingImports.put(orderItem, new ArrayList<>()); - } + matchingImports.computeIfAbsent(orderItem, key -> new ArrayList<>()); matchingImports.get(orderItem).add(anImport); } else { notMatching.add(anImport); @@ -116,34 +144,14 @@ private void filterMatchingImports(List imports) { * not matching means it does not match any order item, so it will be appended before or after order items */ private void mergeNotMatchingItems(boolean staticItems) { - sort(notMatching); - - int firstIndexOfOrderItem = getFirstIndexOfOrderItem(notMatching, staticItems); - int indexOfOrderItem = 0; for (String notMatchingItem : notMatching) { if (!matchesStatic(staticItems, notMatchingItem)) { continue; } boolean isOrderItem = isOrderItem(notMatchingItem, staticItems); - if (isOrderItem) { - indexOfOrderItem = template.indexOf(notMatchingItem); - } else { - if (indexOfOrderItem == 0 && firstIndexOfOrderItem != 0) { - // insert before alphabetically first order item - template.add(firstIndexOfOrderItem, notMatchingItem); - firstIndexOfOrderItem++; - } else if (firstIndexOfOrderItem == 0) { - // no order is specified - if (template.size() > 0 && (template.get(template.size() - 1).startsWith("static"))) { - // insert N after last static import - template.add(ImportSorter.N); - } - template.add(notMatchingItem); - } else { - // insert after the previous order item - template.add(indexOfOrderItem + 1, notMatchingItem); - indexOfOrderItem++; - } + if (!isOrderItem) { + matchingImports.computeIfAbsent(CATCH_ALL_SUBGROUP, key -> new ArrayList<>()); + matchingImports.get(CATCH_ALL_SUBGROUP).add(notMatchingItem); } } } @@ -153,76 +161,44 @@ private boolean isOrderItem(String notMatchingItem, boolean staticItems) { return contains && matchesStatic(staticItems, notMatchingItem); } - /** - * gets first order item from sorted input list, and finds out it's index in template. - */ - private int getFirstIndexOfOrderItem(List notMatching, boolean staticItems) { - int firstIndexOfOrderItem = 0; - for (String notMatchingItem : notMatching) { - if (!matchesStatic(staticItems, notMatchingItem)) { - continue; - } - boolean isOrderItem = isOrderItem(notMatchingItem, staticItems); - if (isOrderItem) { - firstIndexOfOrderItem = template.indexOf(notMatchingItem); - break; - } - } - return firstIndexOfOrderItem; - } - private static boolean matchesStatic(boolean staticItems, String notMatchingItem) { - boolean isStatic = notMatchingItem.startsWith("static "); + boolean isStatic = notMatchingItem.startsWith(STATIC_KEYWORD); return (isStatic && staticItems) || (!isStatic && !staticItems); } - private void mergeMatchingItems() { - for (int i = 0; i < template.size(); i++) { - String item = template.get(i); - if (allImportOrderItems.contains(item)) { - // find matching items for order item - List strings = matchingImports.get(item); + private List mergeMatchingItems() { + List template = new ArrayList<>(); + for (ImportsGroup group : importsGroups) { + boolean groupIsNotEmpty = false; + for (String subgroup : group.getSubGroups()) { + List strings = matchingImports.get(subgroup); if (strings == null || strings.isEmpty()) { - // if there is none, just remove order item - template.remove(i); - i--; continue; } + groupIsNotEmpty = true; List matchingItems = new ArrayList<>(strings); sort(matchingItems); - - // replace order item by matching import statements - // this is a mess and it is only a luck that it works :-] - template.remove(i); - if (i != 0 && !template.get(i - 1).equals(ImportSorter.N)) { - template.add(i, ImportSorter.N); - i++; - } - if (i + 1 < template.size() && !template.get(i + 1).equals(ImportSorter.N) - && !template.get(i).equals(ImportSorter.N)) { - template.add(i, ImportSorter.N); - } - template.addAll(i, matchingItems); - if (i != 0 && !template.get(i - 1).equals(ImportSorter.N)) { - template.add(i, ImportSorter.N); - } - + template.addAll(matchingItems); + } + if (groupIsNotEmpty) { + template.add(ImportSorter.N); } } // if there is \n on the end, remove it - if (template.size() > 0 && template.get(template.size() - 1).equals(ImportSorter.N)) { + if (!template.isEmpty() && template.get(template.size() - 1).equals(ImportSorter.N)) { template.remove(template.size() - 1); } + return template; } private void sort(List items) { items.sort(ordering); } - private List getResult(String lineFormat) { + private List getResult(List sortedImported, String lineFormat) { List strings = new ArrayList<>(); - for (String s : template) { + for (String s : sortedImported) { if (s.equals(ImportSorter.N)) { strings.add(s); } else { diff --git a/plugin-gradle/README.md b/plugin-gradle/README.md index 7f5590da21..03d933aea2 100644 --- a/plugin-gradle/README.md +++ b/plugin-gradle/README.md @@ -151,8 +151,8 @@ spotless { // Use the default importOrder configuration importOrder() // optional: you can specify import groups directly - // note: you can use an empty string for all the imports you didn't specify explicitly, and '\\#` prefix for static imports - importOrder('java', 'javax', 'com.acme', '', '\\#com.acme', '\\#') + // note: you can use an empty string for all the imports you didn't specify explicitly, '|' to join group without blank line, and '\\#` prefix for static imports + importOrder('java|javax', 'com.acme', '', '\\#com.acme', '\\#') // optional: instead of specifying import groups directly you can specify a config file // export config file: https://github.com/diffplug/spotless/blob/main/ECLIPSE_SCREENSHOTS.md#creating-spotlessimportorder importOrderFile('eclipse-import-order.txt') // import order file as exported from eclipse diff --git a/plugin-maven/README.md b/plugin-maven/README.md index 2a249357a6..d596af229b 100644 --- a/plugin-maven/README.md +++ b/plugin-maven/README.md @@ -181,8 +181,8 @@ any other maven phase (i.e. compile) then it can be configured as below; false - java,javax,org,com,com.diffplug,,\\#com.diffplug,\\# - + java|javax,org,com,com.diffplug,,\\#com.diffplug,\\# + @@ -286,8 +286,8 @@ These mechanisms already exist for the Gradle plugin. - java,javax,org,com,com.diffplug,,\\#com.diffplug,\\# - + java|javax,org,com,com.diffplug,,\\#com.diffplug,\\# + diff --git a/testlib/src/main/resources/java/importsorter/JavaCodeSortedImportsSubgroups.test b/testlib/src/main/resources/java/importsorter/JavaCodeSortedImportsSubgroups.test new file mode 100644 index 0000000000..b2346bb19c --- /dev/null +++ b/testlib/src/main/resources/java/importsorter/JavaCodeSortedImportsSubgroups.test @@ -0,0 +1,16 @@ +import java.awt.*; +import java.lang.Runnable; +import java.lang.Thread; +import java.util.*; +import java.util.List; +import javax.annotation.Nullable; +import javax.inject.Inject; + +import org.dooda.Didoo; +import static com.foo.Bar; +import static com.github.tomakehurst.wiremock.client.WireMock.*; +import static com.github.tomakehurst.wiremock.client.WireMock.equalTo; + +import static java.lang.Exception.*; +import static java.lang.Runnable.*; +import static org.hamcrest.Matchers.*; diff --git a/testlib/src/main/resources/java/importsorter/JavaCodeUnsortedImportsSubgroups.test b/testlib/src/main/resources/java/importsorter/JavaCodeUnsortedImportsSubgroups.test new file mode 100644 index 0000000000..35d8c465e4 --- /dev/null +++ b/testlib/src/main/resources/java/importsorter/JavaCodeUnsortedImportsSubgroups.test @@ -0,0 +1,15 @@ +import static java.lang.Exception.*; +import static com.github.tomakehurst.wiremock.client.WireMock.*; +import org.dooda.Didoo; +import java.util.List; +import javax.inject.Inject; +import java.lang.Thread; +import java.util.*; +import java.lang.Runnable; +import static org.hamcrest.Matchers.*; +import javax.annotation.Nullable; + +import static java.lang.Runnable.*; +import static com.github.tomakehurst.wiremock.client.WireMock.equalTo; +import static com.foo.Bar +import java.awt.*; diff --git a/testlib/src/test/java/com/diffplug/spotless/java/ImportOrderStepTest.java b/testlib/src/test/java/com/diffplug/spotless/java/ImportOrderStepTest.java index 332b5bc979..2db3651e02 100644 --- a/testlib/src/test/java/com/diffplug/spotless/java/ImportOrderStepTest.java +++ b/testlib/src/test/java/com/diffplug/spotless/java/ImportOrderStepTest.java @@ -34,6 +34,12 @@ void sortImportsFromArray() throws Throwable { assertOnResources(step, "java/importsorter/JavaCodeUnsortedImports.test", "java/importsorter/JavaCodeSortedImports.test"); } + @Test + void sortImportsFromArrayWithSubgroups() throws Throwable { + FormatterStep step = ImportOrderStep.forJava().createFrom("java|javax", "org|\\#com", "\\#"); + assertOnResources(step, "java/importsorter/JavaCodeUnsortedImportsSubgroups.test", "java/importsorter/JavaCodeSortedImportsSubgroups.test"); + } + @Test void sortImportsFromFile() throws Throwable { FormatterStep step = ImportOrderStep.forJava().createFrom(createTestFile("java/importsorter/import.properties")); From a1314e93e2274da1a29bfdec6c8056fcfd0d5293 Mon Sep 17 00:00:00 2001 From: Ned Twigg Date: Wed, 23 Nov 2022 16:52:08 -0800 Subject: [PATCH 340/757] Update changelogs. --- CHANGES.md | 3 ++- plugin-gradle/CHANGES.md | 2 ++ plugin-maven/CHANGES.md | 2 ++ 3 files changed, 6 insertions(+), 1 deletion(-) diff --git a/CHANGES.md b/CHANGES.md index 4bd52e1aa0..634542e6af 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -10,10 +10,11 @@ This document is intended for Spotless developers. We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format (starting after version `1.27.0`). ## [Unreleased] +### Added +* `importOrder` now support groups of imports without blank lines ([#1401](https://github.com/diffplug/spotless/pull/1401)) ### Fixed * Don't treat `@Value` as a type annotation [#1367](https://github.com/diffplug/spotless/pull/1367) * Support `ktlint_disabled_rules` in `ktlint` 0.47.x [#1378](https://github.com/diffplug/spotless/pull/1378) -* ImportOrder: support groups of imports without blank lines [#1401](https://github.com/diffplug/spotless/pull/1401) ## [2.30.0] - 2022-09-14 ### Added diff --git a/plugin-gradle/CHANGES.md b/plugin-gradle/CHANGES.md index 5acd85ddc8..b002c5bd74 100644 --- a/plugin-gradle/CHANGES.md +++ b/plugin-gradle/CHANGES.md @@ -3,6 +3,8 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format (starting after version `3.27.0`). ## [Unreleased] +### Added +* `importOrder` now support groups of imports without blank lines ([#1401](https://github.com/diffplug/spotless/pull/1401)) ### Fixed * Don't treat `@Value` as a type annotation [#1367](https://github.com/diffplug/spotless/pull/1367) * Support `ktlint_disabled_rules` in `ktlint` 0.47.x [#1378](https://github.com/diffplug/spotless/pull/1378) diff --git a/plugin-maven/CHANGES.md b/plugin-maven/CHANGES.md index b08a2366fd..cd42f0e8d8 100644 --- a/plugin-maven/CHANGES.md +++ b/plugin-maven/CHANGES.md @@ -3,6 +3,8 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format (starting after version `1.27.0`). ## [Unreleased] +### Added +* `importOrder` now support groups of imports without blank lines ([#1401](https://github.com/diffplug/spotless/pull/1401)) ### Fixed * Don't treat `@Value` as a type annotation [#1367](https://github.com/diffplug/spotless/pull/1367) * Support `ktlint_disabled_rules` in `ktlint` 0.47.x [#1378](https://github.com/diffplug/spotless/pull/1378) From 997a4b5f9699cfbd5309bd81d6ef8a5d77f5403b Mon Sep 17 00:00:00 2001 From: Ned Twigg Date: Wed, 23 Nov 2022 22:14:59 -0800 Subject: [PATCH 341/757] spotlessApply --- .../java/com/diffplug/spotless/java/ImportSorterImpl.java | 6 +++--- .../com/diffplug/spotless/java/ImportOrderStepTest.java | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/lib/src/main/java/com/diffplug/spotless/java/ImportSorterImpl.java b/lib/src/main/java/com/diffplug/spotless/java/ImportSorterImpl.java index 6dd8d58ba4..0390d99c1b 100644 --- a/lib/src/main/java/com/diffplug/spotless/java/ImportSorterImpl.java +++ b/lib/src/main/java/com/diffplug/spotless/java/ImportSorterImpl.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. @@ -46,8 +46,8 @@ private static class ImportsGroup { public ImportsGroup(String importOrder) { this.subGroups = Stream.of(importOrder.split("\\" + SUBGROUP_SEPARATOR)) - .map(this::normalizeStatic) - .collect(Collectors.toList()); + .map(this::normalizeStatic) + .collect(Collectors.toList()); } private String normalizeStatic(String subgroup) { diff --git a/testlib/src/test/java/com/diffplug/spotless/java/ImportOrderStepTest.java b/testlib/src/test/java/com/diffplug/spotless/java/ImportOrderStepTest.java index 2db3651e02..32cf0a97c0 100644 --- a/testlib/src/test/java/com/diffplug/spotless/java/ImportOrderStepTest.java +++ b/testlib/src/test/java/com/diffplug/spotless/java/ImportOrderStepTest.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. From c280c4081a96d0ed3fea74ba4c0780d1431b389e Mon Sep 17 00:00:00 2001 From: Ned Twigg Date: Wed, 23 Nov 2022 23:12:29 -0800 Subject: [PATCH 342/757] Bump ktfmt to latest. --- lib/src/main/java/com/diffplug/spotless/kotlin/KtfmtStep.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 9e52bd0435..4f84d991bc 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.40"; + private static final String DEFAULT_VERSION = "0.41"; static final String NAME = "ktfmt"; static final String PACKAGE = "com.facebook"; static final String MAVEN_COORDINATE = PACKAGE + ":ktfmt:"; From 2ac1c46a6e161a44c0960fd1bb3ef042810799f2 Mon Sep 17 00:00:00 2001 From: Ned Twigg Date: Wed, 23 Nov 2022 23:13:58 -0800 Subject: [PATCH 343/757] Update changelogs. --- CHANGES.md | 2 ++ plugin-gradle/CHANGES.md | 2 ++ plugin-maven/CHANGES.md | 2 ++ 3 files changed, 6 insertions(+) diff --git a/CHANGES.md b/CHANGES.md index 634542e6af..2b8dbcbb97 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -15,6 +15,8 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format ( ### Fixed * Don't treat `@Value` as a type annotation [#1367](https://github.com/diffplug/spotless/pull/1367) * Support `ktlint_disabled_rules` in `ktlint` 0.47.x [#1378](https://github.com/diffplug/spotless/pull/1378) +### Changes +* Bump default `ktfmt` version to latest `0.40` -> `0.41` ([#1340](https://github.com/diffplug/spotless/pull/1340)) ## [2.30.0] - 2022-09-14 ### Added diff --git a/plugin-gradle/CHANGES.md b/plugin-gradle/CHANGES.md index b002c5bd74..faf63fc28f 100644 --- a/plugin-gradle/CHANGES.md +++ b/plugin-gradle/CHANGES.md @@ -8,6 +8,8 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format ( ### Fixed * Don't treat `@Value` as a type annotation [#1367](https://github.com/diffplug/spotless/pull/1367) * Support `ktlint_disabled_rules` in `ktlint` 0.47.x [#1378](https://github.com/diffplug/spotless/pull/1378) +### Changes +* Bump default `ktfmt` version to latest `0.40` -> `0.41` ([#1340](https://github.com/diffplug/spotless/pull/1340)) ## [6.11.0] - 2022-09-14 ### Added diff --git a/plugin-maven/CHANGES.md b/plugin-maven/CHANGES.md index cd42f0e8d8..a12b42b761 100644 --- a/plugin-maven/CHANGES.md +++ b/plugin-maven/CHANGES.md @@ -8,6 +8,8 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format ( ### Fixed * Don't treat `@Value` as a type annotation [#1367](https://github.com/diffplug/spotless/pull/1367) * Support `ktlint_disabled_rules` in `ktlint` 0.47.x [#1378](https://github.com/diffplug/spotless/pull/1378) +### Changes +* Bump default `ktfmt` version to latest `0.40` -> `0.41` ([#1340](https://github.com/diffplug/spotless/pull/1340)) ## [2.27.2] - 2022-10-10 ### Fixed From 91534af62b65b0c66ef14d87000e67a9f7e044b9 Mon Sep 17 00:00:00 2001 From: Ned Twigg Date: Wed, 23 Nov 2022 23:17:19 -0800 Subject: [PATCH 344/757] Bump the default ScalaFmtStep version. --- lib/src/main/java/com/diffplug/spotless/scala/ScalaFmtStep.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/src/main/java/com/diffplug/spotless/scala/ScalaFmtStep.java b/lib/src/main/java/com/diffplug/spotless/scala/ScalaFmtStep.java index 6ef9fcd5a7..bff0d9b215 100644 --- a/lib/src/main/java/com/diffplug/spotless/scala/ScalaFmtStep.java +++ b/lib/src/main/java/com/diffplug/spotless/scala/ScalaFmtStep.java @@ -34,7 +34,7 @@ public class ScalaFmtStep { // prevent direct instantiation private ScalaFmtStep() {} - private static final String DEFAULT_VERSION = "3.5.9"; + private static final String DEFAULT_VERSION = "3.6.1"; private static final String DEFAULT_SCALA_MAJOR_VERSION = "2.13"; static final String NAME = "scalafmt"; From 4f20754c0930d26646110e86c71f03d5d0a0bbe0 Mon Sep 17 00:00:00 2001 From: Ned Twigg Date: Wed, 23 Nov 2022 23:19:05 -0800 Subject: [PATCH 345/757] Update changelogs. --- CHANGES.md | 1 + plugin-gradle/CHANGES.md | 1 + plugin-maven/CHANGES.md | 1 + 3 files changed, 3 insertions(+) diff --git a/CHANGES.md b/CHANGES.md index 2b8dbcbb97..04dedc886f 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -17,6 +17,7 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format ( * Support `ktlint_disabled_rules` in `ktlint` 0.47.x [#1378](https://github.com/diffplug/spotless/pull/1378) ### Changes * Bump default `ktfmt` version to latest `0.40` -> `0.41` ([#1340](https://github.com/diffplug/spotless/pull/1340)) +* Bump default `scalafmt` version to latest `3.5.9` -> `3.6.1` ([#1373](https://github.com/diffplug/spotless/pull/1373)) ## [2.30.0] - 2022-09-14 ### Added diff --git a/plugin-gradle/CHANGES.md b/plugin-gradle/CHANGES.md index faf63fc28f..fdc40ef58b 100644 --- a/plugin-gradle/CHANGES.md +++ b/plugin-gradle/CHANGES.md @@ -10,6 +10,7 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format ( * Support `ktlint_disabled_rules` in `ktlint` 0.47.x [#1378](https://github.com/diffplug/spotless/pull/1378) ### Changes * Bump default `ktfmt` version to latest `0.40` -> `0.41` ([#1340](https://github.com/diffplug/spotless/pull/1340)) +* Bump default `scalafmt` version to latest `3.5.9` -> `3.6.1` ([#1373](https://github.com/diffplug/spotless/pull/1373)) ## [6.11.0] - 2022-09-14 ### Added diff --git a/plugin-maven/CHANGES.md b/plugin-maven/CHANGES.md index a12b42b761..9d728c41e8 100644 --- a/plugin-maven/CHANGES.md +++ b/plugin-maven/CHANGES.md @@ -10,6 +10,7 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format ( * Support `ktlint_disabled_rules` in `ktlint` 0.47.x [#1378](https://github.com/diffplug/spotless/pull/1378) ### Changes * Bump default `ktfmt` version to latest `0.40` -> `0.41` ([#1340](https://github.com/diffplug/spotless/pull/1340)) +* Bump default `scalafmt` version to latest `3.5.9` -> `3.6.1` ([#1373](https://github.com/diffplug/spotless/pull/1373)) ## [2.27.2] - 2022-10-10 ### Fixed From aa8cd409b298ba801815ac759aa22deb1712c532 Mon Sep 17 00:00:00 2001 From: Ned Twigg Date: Wed, 23 Nov 2022 23:22:31 -0800 Subject: [PATCH 346/757] Bump diktat 1.2.3 -> 1.2.4.2 --- CHANGES.md | 1 + lib/src/main/java/com/diffplug/spotless/kotlin/DiktatStep.java | 2 +- plugin-gradle/CHANGES.md | 1 + plugin-maven/CHANGES.md | 1 + 4 files changed, 4 insertions(+), 1 deletion(-) diff --git a/CHANGES.md b/CHANGES.md index 04dedc886f..0522c24fcd 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -18,6 +18,7 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format ( ### Changes * Bump default `ktfmt` version to latest `0.40` -> `0.41` ([#1340](https://github.com/diffplug/spotless/pull/1340)) * Bump default `scalafmt` version to latest `3.5.9` -> `3.6.1` ([#1373](https://github.com/diffplug/spotless/pull/1373)) +* Bump default `diktat` version to latest `1.2.3` -> `1.2.4.2` ([#1393](https://github.com/diffplug/spotless/pull/1393)) ## [2.30.0] - 2022-09-14 ### Added diff --git a/lib/src/main/java/com/diffplug/spotless/kotlin/DiktatStep.java b/lib/src/main/java/com/diffplug/spotless/kotlin/DiktatStep.java index f1cd3103d9..9fb5bd634f 100644 --- a/lib/src/main/java/com/diffplug/spotless/kotlin/DiktatStep.java +++ b/lib/src/main/java/com/diffplug/spotless/kotlin/DiktatStep.java @@ -32,7 +32,7 @@ private DiktatStep() {} private static final String MIN_SUPPORTED_VERSION = "1.2.1"; - private static final String DEFAULT_VERSION = "1.2.3"; + private static final String DEFAULT_VERSION = "1.2.4.2"; static final String NAME = "diktat"; static final String PACKAGE_DIKTAT = "org.cqfn.diktat"; static final String MAVEN_COORDINATE = PACKAGE_DIKTAT + ":diktat-rules:"; diff --git a/plugin-gradle/CHANGES.md b/plugin-gradle/CHANGES.md index fdc40ef58b..7a297ba536 100644 --- a/plugin-gradle/CHANGES.md +++ b/plugin-gradle/CHANGES.md @@ -11,6 +11,7 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format ( ### Changes * Bump default `ktfmt` version to latest `0.40` -> `0.41` ([#1340](https://github.com/diffplug/spotless/pull/1340)) * Bump default `scalafmt` version to latest `3.5.9` -> `3.6.1` ([#1373](https://github.com/diffplug/spotless/pull/1373)) +* Bump default `diktat` version to latest `1.2.3` -> `1.2.4.2` ([#1393](https://github.com/diffplug/spotless/pull/1393)) ## [6.11.0] - 2022-09-14 ### Added diff --git a/plugin-maven/CHANGES.md b/plugin-maven/CHANGES.md index 9d728c41e8..3348adbb77 100644 --- a/plugin-maven/CHANGES.md +++ b/plugin-maven/CHANGES.md @@ -11,6 +11,7 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format ( ### Changes * Bump default `ktfmt` version to latest `0.40` -> `0.41` ([#1340](https://github.com/diffplug/spotless/pull/1340)) * Bump default `scalafmt` version to latest `3.5.9` -> `3.6.1` ([#1373](https://github.com/diffplug/spotless/pull/1373)) +* Bump default `diktat` version to latest `1.2.3` -> `1.2.4.2` ([#1393](https://github.com/diffplug/spotless/pull/1393)) ## [2.27.2] - 2022-10-10 ### Fixed From 284dfaf0fc1b92a583f74bc3298f15295aa6a7f8 Mon Sep 17 00:00:00 2001 From: Ned Twigg Date: Thu, 24 Nov 2022 00:05:06 -0800 Subject: [PATCH 347/757] Fix the scalafmt tests. --- testlib/src/main/resources/scala/scalafmt/scalafmt.conf | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/testlib/src/main/resources/scala/scalafmt/scalafmt.conf b/testlib/src/main/resources/scala/scalafmt/scalafmt.conf index bcfec161f4..e15d7318fa 100644 --- a/testlib/src/main/resources/scala/scalafmt/scalafmt.conf +++ b/testlib/src/main/resources/scala/scalafmt/scalafmt.conf @@ -1,4 +1,4 @@ -version = 3.5.9 +version = 3.6.1 runner.dialect = scala213 style = defaultWithAlign # For pretty alignment. maxColumn = 20 # For my teensy narrow display From 933ad2a8b56f78cb47fcb43738b8bb2ed668c2f7 Mon Sep 17 00:00:00 2001 From: Ned Twigg Date: Thu, 24 Nov 2022 00:20:17 -0800 Subject: [PATCH 348/757] Bump default `palantir-java-format` version to latest `2.10` -> `2.28` --- .../java/com/diffplug/spotless/java/PalantirJavaFormatStep.java | 2 +- .../com/diffplug/spotless/java/PalantirJavaFormatStepTest.java | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/src/main/java/com/diffplug/spotless/java/PalantirJavaFormatStep.java b/lib/src/main/java/com/diffplug/spotless/java/PalantirJavaFormatStep.java index 89673787d6..67c55c2e86 100644 --- a/lib/src/main/java/com/diffplug/spotless/java/PalantirJavaFormatStep.java +++ b/lib/src/main/java/com/diffplug/spotless/java/PalantirJavaFormatStep.java @@ -29,7 +29,7 @@ private PalantirJavaFormatStep() {} private static final String NAME = "palantir-java-format"; private static final String MAVEN_COORDINATE = "com.palantir.javaformat:palantir-java-format:"; - private static final Jvm.Support JVM_SUPPORT = Jvm. support(NAME).add(8, "1.1.0").add(11, "2.10.0"); + private static final Jvm.Support JVM_SUPPORT = Jvm. support(NAME).add(8, "1.1.0").add(11, "2.28.0"); /** Creates a step which formats everything - code, import order, and unused imports. */ public static FormatterStep create(Provisioner provisioner) { diff --git a/testlib/src/test/java/com/diffplug/spotless/java/PalantirJavaFormatStepTest.java b/testlib/src/test/java/com/diffplug/spotless/java/PalantirJavaFormatStepTest.java index a589992567..ad358cafc6 100644 --- a/testlib/src/test/java/com/diffplug/spotless/java/PalantirJavaFormatStepTest.java +++ b/testlib/src/test/java/com/diffplug/spotless/java/PalantirJavaFormatStepTest.java @@ -40,7 +40,7 @@ void jvm13Features() throws Exception { @Test @EnabledForJreRange(min = JAVA_11) void behavior2() throws Exception { - FormatterStep step = PalantirJavaFormatStep.create("2.10.0", TestProvisioner.mavenCentral()); + FormatterStep step = PalantirJavaFormatStep.create("2.28.0", TestProvisioner.mavenCentral()); StepHarness.forStep(step) .testResource("java/palantirjavaformat/JavaCodeUnformatted.test", "java/palantirjavaformat/JavaCodeFormatted.test") .testResource("java/palantirjavaformat/JavaCodeWithLicenseUnformatted.test", "java/palantirjavaformat/JavaCodeWithLicenseFormatted.test") From d30fc64f1cf1a51289c9d34c61c6ec134aa6274f Mon Sep 17 00:00:00 2001 From: Ned Twigg Date: Thu, 24 Nov 2022 00:20:23 -0800 Subject: [PATCH 349/757] Bump changelogs. --- CHANGES.md | 1 + plugin-gradle/CHANGES.md | 1 + plugin-maven/CHANGES.md | 1 + 3 files changed, 3 insertions(+) diff --git a/CHANGES.md b/CHANGES.md index 0522c24fcd..fdd4925141 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -19,6 +19,7 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format ( * Bump default `ktfmt` version to latest `0.40` -> `0.41` ([#1340](https://github.com/diffplug/spotless/pull/1340)) * Bump default `scalafmt` version to latest `3.5.9` -> `3.6.1` ([#1373](https://github.com/diffplug/spotless/pull/1373)) * Bump default `diktat` version to latest `1.2.3` -> `1.2.4.2` ([#1393](https://github.com/diffplug/spotless/pull/1393)) +* Bump default `palantir-java-format` version to latest `2.10` -> `2.28` ([#1393](https://github.com/diffplug/spotless/pull/1393)) ## [2.30.0] - 2022-09-14 ### Added diff --git a/plugin-gradle/CHANGES.md b/plugin-gradle/CHANGES.md index 7a297ba536..cdc2be9766 100644 --- a/plugin-gradle/CHANGES.md +++ b/plugin-gradle/CHANGES.md @@ -12,6 +12,7 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format ( * Bump default `ktfmt` version to latest `0.40` -> `0.41` ([#1340](https://github.com/diffplug/spotless/pull/1340)) * Bump default `scalafmt` version to latest `3.5.9` -> `3.6.1` ([#1373](https://github.com/diffplug/spotless/pull/1373)) * Bump default `diktat` version to latest `1.2.3` -> `1.2.4.2` ([#1393](https://github.com/diffplug/spotless/pull/1393)) +* Bump default `palantir-java-format` version to latest `2.10` -> `2.28` ([#1393](https://github.com/diffplug/spotless/pull/1393)) ## [6.11.0] - 2022-09-14 ### Added diff --git a/plugin-maven/CHANGES.md b/plugin-maven/CHANGES.md index 3348adbb77..dccbe089d5 100644 --- a/plugin-maven/CHANGES.md +++ b/plugin-maven/CHANGES.md @@ -12,6 +12,7 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format ( * Bump default `ktfmt` version to latest `0.40` -> `0.41` ([#1340](https://github.com/diffplug/spotless/pull/1340)) * Bump default `scalafmt` version to latest `3.5.9` -> `3.6.1` ([#1373](https://github.com/diffplug/spotless/pull/1373)) * Bump default `diktat` version to latest `1.2.3` -> `1.2.4.2` ([#1393](https://github.com/diffplug/spotless/pull/1393)) +* Bump default `palantir-java-format` version to latest `2.10` -> `2.28` ([#1393](https://github.com/diffplug/spotless/pull/1393)) ## [2.27.2] - 2022-10-10 ### Fixed From 075d6375bb35ad8bb66e21beefdd2ce90a6339f3 Mon Sep 17 00:00:00 2001 From: Ned Twigg Date: Thu, 24 Nov 2022 00:21:33 -0800 Subject: [PATCH 350/757] Bump lib to latest. --- lib/build.gradle | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/build.gradle b/lib/build.gradle index 472da94a61..9fd9981370 100644 --- a/lib/build.gradle +++ b/lib/build.gradle @@ -52,7 +52,7 @@ dependencies { sortPomCompileOnly 'com.github.ekryd.sortpom:sortpom-sorter:3.0.0' sortPomCompileOnly 'org.slf4j:slf4j-api:2.0.0' - palantirJavaFormatCompileOnly 'com.palantir.javaformat:palantir-java-format:2.27.0' + palantirJavaFormatCompileOnly 'com.palantir.javaformat:palantir-java-format:2.28.0' String VER_KTFMT = '0.41' ktfmtCompileOnly "com.facebook:ktfmt:$VER_KTFMT" From 050009fb378caadca16c062b741f81366ea5e4ac Mon Sep 17 00:00:00 2001 From: Ned Twigg Date: Thu, 24 Nov 2022 00:29:24 -0800 Subject: [PATCH 351/757] Stop testing node on windows because it's too slow and we test it anyway with test_npm_8. --- .circleci/config.yml | 7 ------- 1 file changed, 7 deletions(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index 83e434bcec..dd9adf4c00 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -140,13 +140,6 @@ jobs: path: lib-extra/build/test-results/test - store_test_results: path: plugin-gradle/build/test-results/test - - run: - name: gradlew testNpm - command: gradlew testNpm --build-cache -PSPOTLESS_EXCLUDE_MAVEN=true - - store_test_results: - path: testlib/build/test-results/testNpm - - store_test_results: - path: plugin-gradle/build/test-results/testNpm changelog_print: << : *env_gradle steps: From fd70d743f4832303e468f549b4f8b8d17398b73d Mon Sep 17 00:00:00 2001 From: Ned Twigg Date: Thu, 24 Nov 2022 01:05:29 -0800 Subject: [PATCH 352/757] Fix CI --- lib/build.gradle | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/build.gradle b/lib/build.gradle index 9fd9981370..e398e80d23 100644 --- a/lib/build.gradle +++ b/lib/build.gradle @@ -52,7 +52,7 @@ dependencies { sortPomCompileOnly 'com.github.ekryd.sortpom:sortpom-sorter:3.0.0' sortPomCompileOnly 'org.slf4j:slf4j-api:2.0.0' - palantirJavaFormatCompileOnly 'com.palantir.javaformat:palantir-java-format:2.28.0' + palantirJavaFormatCompileOnly 'com.palantir.javaformat:palantir-java-format:1.1.0' // this version needs to stay compilable against Java 8 for CI Job testNpm String VER_KTFMT = '0.41' ktfmtCompileOnly "com.facebook:ktfmt:$VER_KTFMT" From d7d7ecce6d10b45739e49abed74162538cec62f6 Mon Sep 17 00:00:00 2001 From: Ned Twigg Date: Thu, 24 Nov 2022 13:33:20 -0800 Subject: [PATCH 353/757] Fix publishing by bumping spotless-changelog to latest. --- settings.gradle | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/settings.gradle b/settings.gradle index 6184ab802f..591901cab5 100644 --- a/settings.gradle +++ b/settings.gradle @@ -8,7 +8,7 @@ pluginManagement { // https://github.com/spotbugs/spotbugs-gradle-plugin/releases id 'com.github.spotbugs' version '5.0.13' // https://github.com/diffplug/spotless-changelog - id 'com.diffplug.spotless-changelog' version '2.4.0' + id 'com.diffplug.spotless-changelog' version '2.4.1' // https://github.com/diffplug/goomph/blob/main/CHANGES.md id 'com.diffplug.p2.asmaven' version '3.27.0' // DO NOT UPDATE, see https://github.com/diffplug/spotless/pull/874 // https://github.com/gradle/test-retry-gradle-plugin/releases From f2f8b08dd855d79973fa29048d654b1e12cb35cb Mon Sep 17 00:00:00 2001 From: circleci Date: Thu, 24 Nov 2022 22:19:00 +0000 Subject: [PATCH 354/757] Published lib/2.31.0 --- CHANGES.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/CHANGES.md b/CHANGES.md index fdd4925141..b4bdc4479e 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -10,6 +10,8 @@ This document is intended for Spotless developers. We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format (starting after version `1.27.0`). ## [Unreleased] + +## [2.31.0] - 2022-11-24 ### Added * `importOrder` now support groups of imports without blank lines ([#1401](https://github.com/diffplug/spotless/pull/1401)) ### Fixed From a31bba3e5a623f2dbb4eb98d1946961b8dbd23e3 Mon Sep 17 00:00:00 2001 From: circleci Date: Thu, 24 Nov 2022 22:20:03 +0000 Subject: [PATCH 355/757] Published gradle/6.12.0 --- plugin-gradle/CHANGES.md | 2 ++ plugin-gradle/README.md | 46 ++++++++++++++++++++-------------------- 2 files changed, 25 insertions(+), 23 deletions(-) diff --git a/plugin-gradle/CHANGES.md b/plugin-gradle/CHANGES.md index cdc2be9766..2060e5e90c 100644 --- a/plugin-gradle/CHANGES.md +++ b/plugin-gradle/CHANGES.md @@ -3,6 +3,8 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format (starting after version `3.27.0`). ## [Unreleased] + +## [6.12.0] - 2022-11-24 ### Added * `importOrder` now support groups of imports without blank lines ([#1401](https://github.com/diffplug/spotless/pull/1401)) ### Fixed diff --git a/plugin-gradle/README.md b/plugin-gradle/README.md index 03d933aea2..fcc0336cbb 100644 --- a/plugin-gradle/README.md +++ b/plugin-gradle/README.md @@ -18,9 +18,9 @@ output = [ --> [![Gradle plugin](https://img.shields.io/badge/plugins.gradle.org-com.diffplug.spotless-blue.svg)](https://plugins.gradle.org/plugin/com.diffplug.spotless) [![Maven central](https://img.shields.io/badge/mavencentral-yes-blue.svg)](https://search.maven.org/#search%7Cgav%7C1%7Cg%3A%22com.diffplug.spotless%22%20AND%20a%3A%22spotless-plugin-gradle%22) -[![Javadoc](https://img.shields.io/badge/javadoc-yes-blue.svg)](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.11.0/index.html) +[![Javadoc](https://img.shields.io/badge/javadoc-yes-blue.svg)](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.12.0/index.html) [![License Apache](https://img.shields.io/badge/license-apache-blue.svg)](https://tldrlegal.com/license/apache-license-2.0-(apache-2.0)) -[![Changelog](https://img.shields.io/badge/changelog-6.11.0-blue.svg)](CHANGES.md) +[![Changelog](https://img.shields.io/badge/changelog-6.12.0-blue.svg)](CHANGES.md) [![Circle CI](https://circleci.com/gh/diffplug/spotless/tree/main.svg?style=shield)](https://circleci.com/gh/diffplug/spotless/tree/main) [![Live chat](https://img.shields.io/badge/gitter-chat-brightgreen.svg)](https://gitter.im/diffplug/spotless) @@ -128,10 +128,10 @@ spotless { ``` Spotless consists of a list of formats (in the example above, `misc` and `java`), and each format has: -- a `target` (the files to format), which you set with [`target`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.11.0/com/diffplug/gradle/spotless/FormatExtension.html#target-java.lang.Object...-) and [`targetExclude`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.11.0/com/diffplug/gradle/spotless/FormatExtension.html#targetExclude-java.lang.Object...-) -- a list of `FormatterStep`, which are just `String -> String` functions, such as [`replace`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.11.0/com/diffplug/gradle/spotless/FormatExtension.html#replace-java.lang.String-java.lang.CharSequence-java.lang.CharSequence-), [`replaceRegex`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.11.0/com/diffplug/gradle/spotless/FormatExtension.html#replaceRegex-java.lang.String-java.lang.String-java.lang.String-), [`trimTrailingWhitespace`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.11.0/com/diffplug/gradle/spotless/FormatExtension.html#replace-java.lang.String-java.lang.CharSequence-java.lang.CharSequence-), [`custom`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.11.0/com/diffplug/gradle/spotless/FormatExtension.html#custom-java.lang.String-groovy.lang.Closure-), [`prettier`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.11.0/com/diffplug/gradle/spotless/FormatExtension.html#prettier--), [`eclipseWtp`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.11.0/com/diffplug/gradle/spotless/FormatExtension.html#eclipseWtp-com.diffplug.spotless.extra.wtp.EclipseWtpFormatterStep-), [`licenseHeader`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.11.0/com/diffplug/gradle/spotless/FormatExtension.html#licenseHeader-java.lang.String-java.lang.String-) etc. +- a `target` (the files to format), which you set with [`target`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.12.0/com/diffplug/gradle/spotless/FormatExtension.html#target-java.lang.Object...-) and [`targetExclude`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.12.0/com/diffplug/gradle/spotless/FormatExtension.html#targetExclude-java.lang.Object...-) +- a list of `FormatterStep`, which are just `String -> String` functions, such as [`replace`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.12.0/com/diffplug/gradle/spotless/FormatExtension.html#replace-java.lang.String-java.lang.CharSequence-java.lang.CharSequence-), [`replaceRegex`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.12.0/com/diffplug/gradle/spotless/FormatExtension.html#replaceRegex-java.lang.String-java.lang.String-java.lang.String-), [`trimTrailingWhitespace`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.12.0/com/diffplug/gradle/spotless/FormatExtension.html#replace-java.lang.String-java.lang.CharSequence-java.lang.CharSequence-), [`custom`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.12.0/com/diffplug/gradle/spotless/FormatExtension.html#custom-java.lang.String-groovy.lang.Closure-), [`prettier`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.12.0/com/diffplug/gradle/spotless/FormatExtension.html#prettier--), [`eclipseWtp`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.12.0/com/diffplug/gradle/spotless/FormatExtension.html#eclipseWtp-com.diffplug.spotless.extra.wtp.EclipseWtpFormatterStep-), [`licenseHeader`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.12.0/com/diffplug/gradle/spotless/FormatExtension.html#licenseHeader-java.lang.String-java.lang.String-) etc. -All the generic steps live in [`FormatExtension`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.11.0/com/diffplug/gradle/spotless/FormatExtension.html), and there are many language-specific steps which live in its language-specific subclasses, which are described below. +All the generic steps live in [`FormatExtension`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.12.0/com/diffplug/gradle/spotless/FormatExtension.html), and there are many language-specific steps which live in its language-specific subclasses, which are described below. ### Requirements @@ -143,7 +143,7 @@ If you're stuck on an older version of Gradle, `id 'com.diffplug.gradle.spotless ## Java -`com.diffplug.gradle.spotless.JavaExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.11.0/com/diffplug/gradle/spotless/JavaExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/JavaExtension.java) +`com.diffplug.gradle.spotless.JavaExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.12.0/com/diffplug/gradle/spotless/JavaExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/JavaExtension.java) ```gradle spotless { @@ -267,8 +267,8 @@ You can make a pull request to add new annotations to Spotless's default list. ## Groovy -- `com.diffplug.gradle.spotless.GroovyExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.11.0/com/diffplug/gradle/spotless/GroovyExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/GroovyExtension.java) -- `com.diffplug.gradle.spotless.GroovyGradleExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.11.0/com/diffplug/gradle/spotless/GroovyGradleExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/GroovyGradleExtension.java) +- `com.diffplug.gradle.spotless.GroovyExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.12.0/com/diffplug/gradle/spotless/GroovyExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/GroovyExtension.java) +- `com.diffplug.gradle.spotless.GroovyGradleExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.12.0/com/diffplug/gradle/spotless/GroovyGradleExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/GroovyGradleExtension.java) Configuration for Groovy is similar to [Java](#java), in that it also supports `licenseHeader` and `importOrder`. @@ -319,8 +319,8 @@ Groovy-Eclipse formatting errors/warnings lead per default to a build failure. T ## Kotlin -- `com.diffplug.gradle.spotless.KotlinExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.11.0/com/diffplug/gradle/spotless/KotlinExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/KotlinExtension.java) -- `com.diffplug.gradle.spotless.KotlinGradleExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.11.0/com/diffplug/gradle/spotless/KotlinGradleExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/KotlinGradleExtension.java) +- `com.diffplug.gradle.spotless.KotlinExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.12.0/com/diffplug/gradle/spotless/KotlinExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/KotlinExtension.java) +- `com.diffplug.gradle.spotless.KotlinGradleExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.12.0/com/diffplug/gradle/spotless/KotlinGradleExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/KotlinGradleExtension.java) ```gradle spotless { // if you are using build.gradle.kts, instead of 'spotless {' use: @@ -383,7 +383,7 @@ spotless { ## Scala -`com.diffplug.gradle.spotless.ScalaExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.11.0/com/diffplug/gradle/spotless/ScalaExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/ScalaExtension.java) +`com.diffplug.gradle.spotless.ScalaExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.12.0/com/diffplug/gradle/spotless/ScalaExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/ScalaExtension.java) ```gradle spotless { @@ -415,7 +415,7 @@ spotless { ## C/C++ -`com.diffplug.gradle.spotless.CppExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.11.0/com/diffplug/gradle/spotless/CppExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/CppExtension.java) +`com.diffplug.gradle.spotless.CppExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.12.0/com/diffplug/gradle/spotless/CppExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/CppExtension.java) ```gradle spotless { @@ -447,7 +447,7 @@ spotles { ## Python -`com.diffplug.gradle.spotless.PythonExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.11.0/com/diffplug/gradle/spotless/PythonExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/PythonExtension.java) +`com.diffplug.gradle.spotless.PythonExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.12.0/com/diffplug/gradle/spotless/PythonExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/PythonExtension.java) ```gradle spotless { @@ -481,7 +481,7 @@ black().pathToExe('C:/myuser/.pyenv/versions/3.8.0/scripts/black.exe') ## FreshMark -`com.diffplug.gradle.spotless.FreshMarkExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.11.0/com/diffplug/gradle/spotless/FreshMarkExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/FreshMarkExtension.java) +`com.diffplug.gradle.spotless.FreshMarkExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.12.0/com/diffplug/gradle/spotless/FreshMarkExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/FreshMarkExtension.java) [homepage](https://github.com/diffplug/freshmark). [changelog](https://github.com/diffplug/freshmark/blob/master/CHANGES.md). FreshMark lets you generate markdown in the comments of your markdown. This helps to keep badges and links up-to-date (see the source for this file), and can also be helpful for generating complex tables (see the source for [the parent readme](../README.md)). @@ -502,7 +502,7 @@ spotless { ## Antlr4 -`com.diffplug.gradle.spotless.Antlr4Extension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.11.0/com/diffplug/gradle/spotless/Antlr4Extension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/Antlr4Extension.java) +`com.diffplug.gradle.spotless.Antlr4Extension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.12.0/com/diffplug/gradle/spotless/Antlr4Extension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/Antlr4Extension.java) ```gradle spotless { @@ -527,7 +527,7 @@ antlr4formatter('1.2.1') // version is optional ## SQL -`com.diffplug.gradle.spotless.SqlExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.11.0/com/diffplug/gradle/spotless/SqlExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/SqlExtension.java) +`com.diffplug.gradle.spotless.SqlExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.12.0/com/diffplug/gradle/spotless/SqlExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/SqlExtension.java) ```gradle spotless { @@ -567,7 +567,7 @@ sql.formatter.indent.size=4 ## Typescript -- `com.diffplug.gradle.spotless.TypescriptExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.11.0/com/diffplug/gradle/spotless/TypescriptExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/TypescriptExtension.java) +- `com.diffplug.gradle.spotless.TypescriptExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.12.0/com/diffplug/gradle/spotless/TypescriptExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/TypescriptExtension.java) ```gradle spotless { @@ -610,7 +610,7 @@ For details, see the [npm detection](#npm-detection) and [`.npmrc` detection](#n ## JSON -- `com.diffplug.gradle.spotless.JsonExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.11.0/com/diffplug/gradle/spotless/JsonExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/JsonExtension.java) +- `com.diffplug.gradle.spotless.JsonExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.12.0/com/diffplug/gradle/spotless/JsonExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/JsonExtension.java) ```gradle spotless { @@ -835,7 +835,7 @@ Once a file's license header has a valid year, whether it is a year (`2020`) or * `2017` -> `2017-2020` * `2017-2019` -> `2017-2020` -See the [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.11.0/com/diffplug/gradle/spotless/FormatExtension.LicenseHeaderConfig.html) for a complete listing of options. +See the [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.12.0/com/diffplug/gradle/spotless/FormatExtension.LicenseHeaderConfig.html) for a complete listing of options. @@ -902,9 +902,9 @@ spotless { custom 'lowercase', { str -> str.toLowerCase() } ``` -However, custom rules will disable up-to-date checking and caching, unless you read [this javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.11.0/com/diffplug/gradle/spotless/FormatExtension.html#bumpThisNumberIfACustomStepChanges-int-) and follow its instructions carefully. +However, custom rules will disable up-to-date checking and caching, unless you read [this javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.12.0/com/diffplug/gradle/spotless/FormatExtension.html#bumpThisNumberIfACustomStepChanges-int-) and follow its instructions carefully. -Another option is to create proper `FormatterStep` in your `buildSrc`, and then call [`addStep`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.11.0/com/diffplug/gradle/spotless/FormatExtension.html#addStep-com.diffplug.spotless.FormatterStep-). The contributing guide describes [how to do this](https://github.com/diffplug/spotless/blob/main/CONTRIBUTING.md#how-to-add-a-new-formatterstep). If the step is generally-useful, we hope you'll open a PR to share it! +Another option is to create proper `FormatterStep` in your `buildSrc`, and then call [`addStep`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.12.0/com/diffplug/gradle/spotless/FormatExtension.html#addStep-com.diffplug.spotless.FormatterStep-). The contributing guide describes [how to do this](https://github.com/diffplug/spotless/blob/main/CONTRIBUTING.md#how-to-add-a-new-formatterstep). If the step is generally-useful, we hope you'll open a PR to share it! ```gradle @@ -937,11 +937,11 @@ spotless { format 'foo', com.acme.FooLanguageExtension, { ``` -If you'd like to create a one-off Spotless task outside of the `check`/`apply` framework, see [`FormatExtension.createIndependentApplyTask`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.11.0/com/diffplug/gradle/spotless/FormatExtension.html#createIndependentApplyTask-java.lang.String-). +If you'd like to create a one-off Spotless task outside of the `check`/`apply` framework, see [`FormatExtension.createIndependentApplyTask`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.12.0/com/diffplug/gradle/spotless/FormatExtension.html#createIndependentApplyTask-java.lang.String-). ## Inception (languages within languages within...) -In very rare cases, you might want to format e.g. javascript which is written inside JSP templates, or maybe java within a markdown file, or something wacky like that. You can specify hunks within a file using either open/close tags or a regex with a single capturing group, and then specify rules within it, like so. See [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.11.0/com/diffplug/gradle/spotless/FormatExtension.html#withinBlocks-java.lang.String-java.lang.String-java.lang.String-org.gradle.api.Action-) for more details. +In very rare cases, you might want to format e.g. javascript which is written inside JSP templates, or maybe java within a markdown file, or something wacky like that. You can specify hunks within a file using either open/close tags or a regex with a single capturing group, and then specify rules within it, like so. See [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.12.0/com/diffplug/gradle/spotless/FormatExtension.html#withinBlocks-java.lang.String-java.lang.String-java.lang.String-org.gradle.api.Action-) for more details. ```gradle import com.diffplug.gradle.spotless.JavaExtension From 4d34ad4dda4161df018863b22c9eb1162651da1d Mon Sep 17 00:00:00 2001 From: circleci Date: Thu, 24 Nov 2022 22:21:45 +0000 Subject: [PATCH 356/757] Published maven/2.28.0 --- plugin-maven/CHANGES.md | 2 ++ plugin-maven/README.md | 4 ++-- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/plugin-maven/CHANGES.md b/plugin-maven/CHANGES.md index dccbe089d5..9baefc2ec8 100644 --- a/plugin-maven/CHANGES.md +++ b/plugin-maven/CHANGES.md @@ -3,6 +3,8 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format (starting after version `1.27.0`). ## [Unreleased] + +## [2.28.0] - 2022-11-24 ### Added * `importOrder` now support groups of imports without blank lines ([#1401](https://github.com/diffplug/spotless/pull/1401)) ### Fixed diff --git a/plugin-maven/README.md b/plugin-maven/README.md index d596af229b..e6a2c47aae 100644 --- a/plugin-maven/README.md +++ b/plugin-maven/README.md @@ -12,8 +12,8 @@ output = [ ].join('\n'); --> [![Maven central](https://img.shields.io/badge/mavencentral-com.diffplug.spotless%3Aspotless--maven--plugin-blue.svg)](https://search.maven.org/#search%7Cgav%7C1%7Cg%3A%22com.diffplug.spotless%22%20AND%20a%3A%22spotless-maven-plugin%22) -[![Javadoc](https://img.shields.io/badge/javadoc-yes-blue.svg)](https://javadoc.io/doc/com.diffplug.spotless/spotless-maven-plugin/2.27.2/index.html) -[![Changelog](https://img.shields.io/badge/changelog-2.27.2-brightgreen.svg)](CHANGES.md) +[![Javadoc](https://img.shields.io/badge/javadoc-yes-blue.svg)](https://javadoc.io/doc/com.diffplug.spotless/spotless-maven-plugin/2.28.0/index.html) +[![Changelog](https://img.shields.io/badge/changelog-2.28.0-brightgreen.svg)](CHANGES.md) [![Circle CI](https://circleci.com/gh/diffplug/spotless/tree/main.svg?style=shield)](https://circleci.com/gh/diffplug/spotless/tree/main) [![Live chat](https://img.shields.io/badge/gitter-chat-brightgreen.svg)](https://gitter.im/diffplug/spotless) From aac6de4e80171e5a8dc6aaf5682bbc1069d956ad Mon Sep 17 00:00:00 2001 From: "renovate[bot]" <29139614+renovate[bot]@users.noreply.github.com> Date: Thu, 24 Nov 2022 23:26:23 +0000 Subject: [PATCH 357/757] chore(deps): update plugin com.diffplug.spotless to v6.12.0 --- settings.gradle | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/settings.gradle b/settings.gradle index 591901cab5..e0f3291da5 100644 --- a/settings.gradle +++ b/settings.gradle @@ -1,6 +1,6 @@ pluginManagement { plugins { - id 'com.diffplug.spotless' version '6.11.0' + id 'com.diffplug.spotless' version '6.12.0' // https://plugins.gradle.org/plugin/com.gradle.plugin-publish id 'com.gradle.plugin-publish' version '1.1.0' // https://github.com/gradle-nexus/publish-plugin/releases From ad9159e266647a422ec3d6b3f89e794f36515733 Mon Sep 17 00:00:00 2001 From: "renovate[bot]" <29139614+renovate[bot]@users.noreply.github.com> Date: Fri, 25 Nov 2022 15:18:54 +0000 Subject: [PATCH 358/757] chore(deps): update dependency gradle to v7.6 --- gradle/wrapper/gradle-wrapper.jar | Bin 60756 -> 61574 bytes gradle/wrapper/gradle-wrapper.properties | 3 ++- gradlew | 12 ++++++++---- gradlew.bat | 1 + 4 files changed, 11 insertions(+), 5 deletions(-) diff --git a/gradle/wrapper/gradle-wrapper.jar b/gradle/wrapper/gradle-wrapper.jar index 249e5832f090a2944b7473328c07c9755baa3196..943f0cbfa754578e88a3dae77fce6e3dea56edbf 100755 GIT binary patch delta 36524 zcmZ6yQ*&aJ*i+pKn$=zKxk7ICNNX(G9gnUwow3iT2Ov?s|4Q$^qH|&1~>6K_f6Q@z)!W6o~05E1}7HS1}Bv=ef%?3Rc##Sb1)XzucCDxr#(Nfxotv ze%V_W`66|_=BK{+dN$WOZ#V$@kI(=7e7*Y3BMEum`h#%BJi{7P9=hz5ij2k_KbUm( zhz-iBt4RTzAPma)PhcHhjxYjxR6q^N4p+V6h&tZxbs!p4m8noJ?|i)9ATc@)IUzb~ zw2p)KDi7toTFgE%JA2d_9aWv7{xD{EzTGPb{V6+C=+O-u@I~*@9Q;(P9sE>h-v@&g ztSnY;?gI0q;XWPTrOm!4!5|uwJYJVPNluyu5}^SCc1ns-U#GrGqZ1B#qCcJbqoMAc zF$xB#F!(F?RcUqZtueR`*#i7DQ2CF?hhYV&goK!o`U?+H{F-15he}`xQ!)+H>0!QM z`)D&7s@{0}iVkz$(t{mqBKP?~W4b@KcuDglktFy&<2_z)F8Q~73;QcP`+pO=L}4yjlzNuLzuvnVAO``skBd=rV%VWQTd0x6_%ddY*G(AJt06`GHq zJVxl`G*RiYAeT=`Cf(SUN$kUEju!>SqwEd8RWUIk$|8A& zAvW|Uo<=TWC~u}V?SNFv`Fq9OeF_VpfyXHPIIay@Pu5J6$$pg{;xE9D7CROVYV>5c zv^IYXPo_Z4)bg5h?JSUX!K`q_u{>F%FzrG>*!Db_^7*7(F@f%i34Ps`JBAH6{s=ygSr^CVO)voP`v=SO z7v;4cFM_D>iVl{&X*N7pe4_^YKV%`5J774`5!DC}g;D@50h?VA!;fU1?Hf%%`N8R1 zSg@hZ8%Dq^eYV1!g8;`6vCSJoK+V1Q6N8ImtfE3iXs!s~B>js)sLHB9w$r+6Q>Oh#Ig&awvm%OBLg!7alaf}9Cuf;M4%Ig9 zx4K}IQfPr&u?k8xWp!wI4{CP#GTs#qR0b+G{&+=vL}I{b-Pha43^%8=K3997~* z>A|oxYE%Vo4~DiOih`87u|{8!Ql5|9Y+(ZY2nRP+oLdGErjV&YeVKw>A$JyPPAL+C zA36S!dNVf z;xJ)YR;^VPE1?`h-5>{~gwY2pY8RqhrsiIBmJ}n3G@Zs!!fD6y&KWPq&i8HEm*ZAx`G} zjq2CD5U==ID^we8k?=geue4Y>_+%u3$-TzVS6QMlb4NoS%_V>;E2hQ)+1Q@v(reC5 zLeK*f%%{PNO-mtrBVl|-!WaiKAkZv-?wnOwmZ=Tv57k=4PX=C?=I4V*THRFRE8a_{ zb>5YwDf4o>>$o{XYlLN{PZ^Ff?0FJl4>A9C-q9A$$&44l122Qsc|6Fd6aTam{=JO3 zBFfFe9seUPSUeyXQc*RA>2{WoKIYVltA&@5spdIW;rzOOqoQo`CN;~UNgU{{m9^c1 zTrN|8w_7+Nws4}Z-4eS9WMpF3h<@81a)oK9njh;-TB74vR;u{vE?>6FDG7<%GVXFL zUR9l{z*eEND6pp)+hpNT$VVM^Pw*S;#NrbCmH{dhBm?%6D|k)0C@Z9H>T|kby1^)# zOPmJ8Hq`8waoEK(9}IfP_q4yr(s?ME+T%UV-ikxW!XFb^6w02t30j$n_VSwevg;{9 zx0OXK_uGBFej=gbG>G^pEv^`I8&_a@t9>Nr;#r?XNKquD&Ho|`)qK6C^-7SCdo=S& z)vUi;m5*qIePEIbL=wJ|WCBNY;zCm2F-+@N2i{I^uR9UVZm$o`I|@<&2}w)C`h)vV zW{)yGJ3?GCZNtFe53Kb#uzrC7v-{JygKZUiXDV5mR z5la_vAFOvoh#yn)B`$^ZN*Dxp5Uo~_k8G9skn2)Tb>Kw#Vgxi`bti)^(z--X9F~oR zZ6=^_x@mDT~=h_@GGVcgBtLzssB1|Xy(xc(lUYJ#_ zgwc&ajE%^cCYW7d;xAxi{#LN*1}s>{K79MZrq!tYMpRA{T!#^tgXP=J5FvkbZ@gx~ ztq-E&c$`|KX8GS2a_voZHf=y8C{6~f~`DpC- zjQfrt2OGi-WGx}Y4>vM`8<4frU*!bq*NJ*Tyn0cqk=zpDdYth-PJIfz5>pLF@qnai zzj2FEhuOa-7$JR=U!L{UWWJBA%~SW-6Nh&3;<}iQO)DvOI&VKi1L8rmICePWqoY^F z-dC8X8~1T}=C9m&yb1kZzbKd2;29_Pm*Cs=y{Z06QZDlT7Poci>1@hFa%t0<`1()UTxcQ}e`fAh6K`<5C_SG`dw$IqzwEYNKvIH3VWlhz z_#^(T53W}jeWF#WIhj^U7AdIB~3feC--5iUiiT4Qyu81 z;Xa^8#~M@p%6B`LCKWWTa7I+35BLP=EOa&Gp2pbTWw5HOIjrx;2J(KI$$HT|w8}R-8fbp9sot&LiLs7ILlyZc8 zWbss7=*Ah|X$LEt1O|T?ABkIn-0NN`I8+ipfoBZcW>(WiaASG_khBtKM{hfkm5VBS zy0Q`4*G6HRRa#9G)10Ik3$C3|nQbFzmU-dA`LjKQY8icnx?2OE40%z852{OJH=?mbvwr9 zhlx0RDo^D;p*xKx?yT(`s7wj7BHA~rHF2yxnL<1PcU7FM57;?g^ z&CyPh9W4KvZ;T8w;AuNMn|nQ-xJ~CvVT7gAPAGi7w8udw_LOp+p4eZiI`JEC@Mq9F z#dA2AM_};CnL=y0#tZALdB(P~Rz*KqGqjwec%Fy?K(PGoO0tfskWw-aGhd7$ zTi~x1G>4h5q>ek=tIoT(VBQxrq)&#`_0UHC(j*ZO%%}%C)|EzTWEpvYDqCYXLexR9 zlww1ESB+IiO}=oq)8WZj%cY_FTQcEJ`JdABa=_S;O|kLhX*|5|D>0c{12DoC?K95f ztNxm(sTU6cWWd$tv`5X(=x?yAo)IYQ3G*2+o#|EfXko6erF;M4Pc;G0)pUDY)t`H9 z76Z8V9HqbWA@!`BelAT&ErrGTz7}%M*605PEY@3{gv+`yEhr{=EVp_tU%`b54Pn4a zz8nN7`eNx=*`f1t#^7>7G07IEnbnn&`RWZ}4Cp8W_DFDs-5)GU`bw}uBmOQfKmi2@ z(cWWmvHFTUNInRH!0y_ZtuI9Eh@O3+64wy-_2DF~E@KF3abM`0gC%|kHi@&hP_#B$ zLN{Z?$V_;+h?%2zEC{2ITyWOup*w*K?~vpwB(DX1i6oY+F)??;nyHpzaPLIt6G$4; z6>iAsB+&&NN0;ObWVOL+-^ZwD?nHgY>0k>0I3iA7o)f# zN&aX$lM@r_Iu|nSdPjoF{#QD9M6>|JSNPLxX^T2!jCKjS5mwNaO+SmBfOY z;6ZdwfzhO6Vs|9u81f4e%7*mU%8K>A7QWO0;QcX7W@|NSUVl)_>7VEf#&N6E~ zn9Wv88@Suo9P+M_G2(f+JFf#Q^GV#7QQ`qH#$N1y{A*_t^`5H1=V^u?Ec|EF6W+6B z(@Q8ChIUyq;+I5CmjEa1*v%d5{WHyhcHSjQuwzQq?;^BmfV#okq3v8bp7dBdk z54B+%D3=JWd-2w$)puXxZyZH>-$O-?tbSIlGc{em9xHN!44iaCr}6uZ^FpN7IvNh8 zbp!%4xR9np`>AOEd1e2_y}xW#v@@h3wYc?WiwL6Q>fxPQA81V^J)XtGs|Z&er6w~M z!1Ph~85TMG>R&ixNUnevc(w>fgb%+X#Wds6Yl+wH29aE%;RuDeZz5dEt%#p&2VK1n zKkqgl&*_YwnO%9`0<6MVP=O3{02EcR7PvvZPbL2KMuoRsU|Y%zw38qeOL#!YFp#_~+rtNJVl>lJSh_*B0A6n3XkE5po z9RpE_h=pnmDJFX*n6wmsWJ9GLu2=L8y!_R;;Aa2Jl|)I}Qff&`Fy@iOhop8>Y2{F} zbVk3rNMi$XX(q1JrgcIhC08@d5Zc>wLUL3wYm}hzS^!5d&Mec$Sp^$DUS1lD1>KAt z|Efof3nJ4^k(WKL_t-u8ud4L(t>q#9ECj?v#W~W#2zTt>|MCh&*H8Wh1_I&^2Li&M zq9j0`(zk~P7}dB`+15b*j%VPGr$;@4MBQ5AT>-y?0Fxfr2nC1kM2D(y7qMN+p-0yo zOlND}ImY;a_K$HZCrD=P{byToyC7*@;Y$v6wL!c*DfeH#$QS6|3)pJe68d>R#{zNn zB0r*Es<6^ZWeH`M)Cdoyz`@Z&Fu_^pu8*089j{gbbd!jV@s7`eI5_X5J3|poVGlq` zDo9}G;CsjW!hgN2O9=1|GpE;RpQvrBc+&dF)L>V&>9kd6^YIL?+*WDmcQlvwnq`Lf z&N$gF>3+E*NcJojXXI^}B(B-;@ebpVY}l#EcDWles7s;Ft+KZ@m+6FWaD^oYPBXVw z3sq|aKIDh1x5Ff=tW$(LO|!e&G?Xvh^H!GfiA(emluL!LmD=EV@|u|8S7w6ibUePJ z>{sOC6L27R+b&}e?VH;KvV3a;O3G=gwG}YzrkSTV6(&=;o)EV~2OD(Eh4mu@K0G)i z3#44IZhqN6+Hb2h#3R8YwJW7LesDA9=n)75u#46_ZmSh@6Q-4oHvGxFPY8x;Q+)d@ z*-SDqhVeyPGkoD)iq;z0r*M)IhY5I>gMA@RS&EIYPq}Z{$Q4Jbfd76EVhSF-sR^TO z!=o?>V(^bx!pG$26J~Z>Tvu&Uu+0;>m+pg(fmbu(97^(OHBH4;J8WIfv-f5}VP#VS z$Y$}SHKdphDUHlbdIVW!k$L6T{LY)|H}MT=l$22kIl>|46FK9dt$?3Fjk2RA-~AX7 z1|Xe`n)%h~e-O_qLpoFXJ$%gmocq`v0%hRw1k_6nh|+3pvJDy}m)V|xjL&!Z6?%pU z+m)r2*pWjEl!etAYxdzWb0{mGc;#$>rE%)b z@Rnj78P;$lrzY!XCa0&x+8a^YF*G|Q|C}bGeczz(5m_gq08wJHIH`WqHH?A}!~_3{ zQEvMXmL<*nThl^pL58nbHgQ1n9cYmN{C8J^6AKS%?~>1DCt70Q2Vp0;E@`GF%Tzkc zSUt&LJ=wHI6@#8_%=2s=j^4VBd1-h_)3 zeozYua!|{x(qk#z;tavf28rj_5Oen-cYG%;R6I}Hz$yMXeg^)_$OUUXx1r^qrl!DG zYXkAXKBMrVM-rJwAo<5J{NW1XJhW;Nh*&`nFV-Z;Vd({KSkMxV#cn|bXJ z50GtvFE##sqGhV#lv2s6?^yeBShlhR%XaPIo)iXOue}jwZ;Zq#dgDn8H?74Y+$Z?C z2Y5mCC66>dp%sVMecUzCirWq99Ea(TDwClZxtEB~4N-2JmlH#>Z2jOcaNaw4tn?P->BBGNHxUHez7>C@TZNT5Z zHerlG0a4~06L%>tn!~$s^L5`~{ueLZ5?`$46nHvwKxM0V9VQ(k{A40xDVw{+Qt)RV zQ)T2Df)cp0nv!lUFt3D=i~k!V|7dUjpz?K2ZiynO)$d{2*YT$N^CQ{t=luZ>WcE!> zg25p}If9RTho%G@PZp;5zBwv`n+e9iO=6dx1V^|4Ty%`oE=f7O&QC^s!4MJ+lMG>^ za!mgpz*^SHT+M_zm;{H#E~SaU^Kn*y)nTAF*2@t5mF+l)bte+a+goaA*zXJ4P)H|y z{4OwbJnIPtMp4E~=64gM-Y{#o{x)+8YCg$C7Yy=;9hdyBgRFIY2_L9DL3*B@%$5#m z8P}+)glf*}UPD$C;_yntx}9VPmSSnY9`Thd09nfoR;3`kar*FRfS)`+as*t2l*USWgmaZ!qFubr1DegTGZspyYMgic{inI0dSt+rJR z((jjMrdq^?VSZ8FCO;0NW@>O_b67gDHP%W*^O?J z91NQ7ZFODMSvHj3cvT#6RJUF7x=-BJFQ^6<&mOd15Z&M!?b+3Tg!UcgldD9tOAt5K z3X>MlE-a=sj;K&}sSng48jQ7sp|&u3;@e>V4Cuf(!s@9lZ0Cg^DKWmki%>$<85tOG zU;e{%zHU~KREBUg?FbcseK{lmK-`*S1p9j_4hF=F$y)NB;HsHwuf_A0Zhy395eU7o8^A zi2t7Ch|KVprUn03N0T2XshT!g$HTErcQBBG=TWaHkYtaI2CJY7ajI%yr&9 zVC^zJ3WW03bjwGNx{l}#+D&Ml_uI4PQhV}qZPXOP7ffSv(O;hX{Ff1|HoA~v)V!4y{CdALyi2YPjrRVmRYilRv z5PSkj*Z_8Fa*sCqGN?7YTnkr9=i9X`qcw7nqz#{bj?B7NiV9fWF+%~Rb1X@MuS^Mw zC)d#K{(-9!?xStM2K5x%x~ogWxgIK>s5r_RT1jU_lxdTtIEFWvi4eJSAiGec&HXQ( z5t7!J1b#SL|8s4)u147PWQUq_e33!5Z#f$Ja&az)(Htl`Z0@Ez)0d74BzNHHfH|<-8q*ZMf?%eJzoGS!0S6Y zSU7y^1+;V$Je9F027>1eN#_tz+2t}Y^N zYfi9}J!N^SU1CYoNBDbD39@84xLroY@0f%%c^(5CE+}!b5-Mt3oXe2nBdyicgGIL+rzTTKv`}Pp%fG1f^s?sgNH8=Q}s4Z>0ZCZ8ZYF z4og8nK%OA~zZMJX01uFtrmwhcgg*XbiMP9kfkPYFASbp7*Bk^5ZBzV)dL)JhPwDkM zkgdHeKw)orJcj4^)a^wQC2|->G=OBzuc-SskRrrf+H-E%HQ==Ex}d*504#GbIUXIB zcZs@Oo0i61MG}&0bu%@2N?MMJMRXyTVb8@3wF5eY3G6-1NdT~{{~YFs8f&SNebdaq zKmP>XqCQ@iaamuvY2m%xJ~gdSLSj~DBhB`NCj_c}NbSjB{r(E`_-+6a#vx*|S>-GU zHsw^dxxu`e)q1HbH==rLFap?cebKumnTo=iJQ zJD1#=o>0%Y@&jP?^)Q5bTV!pzrf=FoHq2c_59pq@my{D4AW8VU*7LVp;LF-qESV;L zClRfyQ6CcD$sd84K@e@p_ALH%j(Pz@Em@QFyY`AG&(|!(cG8!oV#ejr`y(LolX}Iu zL$)G)8^y4sUAYCWprzVR?`#OJ%NU)9U^B!OGSj>Ly;<)<(nNh`?z*GvJ|ZBKfZ`0 z=q_yGHWPp~R+J+{{@APVwmp8`=%N!L7AT^l^oaM|JrCFu7J#@frf=z(vGq2>sQ^@u zk=^d#gDf}ME!~9PaLfw44~rsG!)T7h8~dY^VcZQa+ueWPGG$mWXB|H2$$0BT(QAIu|=DJXPQDNes3Q>-|Mh=Ih zy{WR)QmhL5rQbBYPBa+e7)8Vo;_aKrg`}izmN>#ATuSDu!QUFA zsgM|Kv@W(S}Ag^6e8)9pQc@JLj_2ZIkO=8)#ARm#mU=NncWbmd-SbO;ad=y|k`shy3b z*8o0@EJo3b$#zSgmnlT7KAp)U!qI2M`hiC@Gp0)pNGHYMe1$MBNE}Hd{Sv^`wI7>MzNwgVv1ZzL zttmyv!=TKuPH$b>r7$lgP5?vho;#Ks4+zLzaz-1b{p-Fn6dWy1Agg7O2{&VQ5@s3A zAqzC9QokRD59!@ex#k>xy61kq6h~O$lb;lB;Q|chv&wzR+N zgXdIo%?q1Y$TzsdCo+n$^NODN7yd}cAv+rkG|u-(wTp?zUSUxaA-W3dwqikdrokwz) z68)Gn$Nwc1zB$F9`#(af|C3v;|2$bo7fU8f7h^NK6h&@xi2m`)g4mW$?l@5JEc*VV z6d67@Fl2w6mO;MYUl2U>R996gQUX$d>$D>)TNGq*arz}f21yh^uvIM!3u$H{_CH5! zrjt9L^&J8UqEV_lLn&}nc|Q=MDei6t=vL_>X-i8B%f5FDi)|qQ;2V-T!qOi*uqq{U zElET6#2cb>Z_6p_vw44&mN!;T&~ubi&p`XGepCNAfa0-T zC84V@VN^R6%z({m=$%iXrbiggxvMiBpww~ktD&=9-JPK3kPCOGCJNQj8+l9k#!QeS zv3h$Ej>@j<-zBW0Qr`5tNQVRfYK_$3>nWUzf&c*tCpl@aYwa%b;JNeTX10OevcxY7 zqnLgKU-X9G8~&?Dr)`*7GryqhN#;9v`D_c=_xBcD{j-cLop~pSnM?&7HggX6gb++ftBq$idM1|>5t+68sWf{ixREbMkZesmpjJsAFPQ#2+8Uek z$BPbu3cQuNDQq+^M}&ZuSHjxUgxOjF<^%4 z*8lc$CgA<$n=DYg_DsrHB7zYM0Ro|gS8ZnUq$u3GQ+{owv9RdB$wG%d-;R+I>?i?b z+r_mu{IL6WTYftdz?0#pbHkmQP31LvXcMK6;mAP+;q^L@q}v~TD}Ni>f7@QYcbM!T zX5kShHv3X1U=>B!2*si9=AEJCBt~GIH7DL4^+gHj+q}tk0F_?Q-=z{JY%77nkw>$F zG}6ROaL_)3t$jX=ZtFG{Q=LZfNjNb2LK=m9l|7iaB++N|S$vAr1 z_gf3JpIB|?dptfQ{sOZGlhyj~D;T#hjaNh0X5(o&7)87^t@@Hteh{0DOM{tCu$l#& z&NhA&V4VR}nzZP{7i(5bGB17<7bu+RJ1}k}=ffSg%=+213Oy@Aj1vv2U>U>8tRhKM z=*e<21)u6SSb{CC&We%#6X@duqLWGJ>O)Ls`uM98``34g11;D}*7>c3+^c|Os&;t}`(BWMD zfbyr~$j%{6%DZ`kR-}s~p?0#&-5a}b?6tDqwtqY%ep0ypSRIB54G@|0J5E#LkxQk# z_&xE=d(U}q?*Rh7L7f8AM5{qdGpC<&t~9YI!%j2G@nUPoLPSiWHjCVP{JAe?cBjQ zTqI=R{nv5c@|R)8Oi3cTL{&6%XdTgDP4CNYT}q2f5|Xf_hID#;83kd+v0RRyNKYn} zyPahwd=4ncDORLvatBc~KzT+jiiD{tzd3d*T(f7ayS;J&I1X!xaL2~POrw2ST=Pr5 zu*c}fb@)0P6jv))kNl38C7gmnWGmlL@{PWOVYt9se*cS0w#@W=N+dY#V08ci=Zmg9 z+${f#Qfs5)hOPxC;q{(J{Kx4HF)2QMzlVtXz0-O&h2$VxtT;ROvZ13nN{IG>Asv{% zHuDqgZ{R2(X*hkO+!HYHHWvRYrvN9fl-1?x6b)oseZY)@dQ6O>9Y#8*23~%bzN~Nf zpHGMdS-G|%F^v3Gnlsc$s4Wl=ZEu+J6y~*Ih2tpmHfO56JXKjldm$BxDvW6ZH>JrU zdRo}=^466lAq6!qY_@nQ}5ETUEoF;`>7b8W910_Z17!r`D?QNvC z+WF%@IkPi43n4;0Ks`M{x*0-^GK7oCAp?pFK1`~RoMSe@jAlV8vQruCUNyQ_7wk?` zSKe*|!4ar@VSA}!ThlIB*Qa5){pu&HS!a)-{lWL2@o1486ZK_!!}FSZ>vyUPIOX#+ z5d3~J24Op?!f!oNytub~egnkB`}h?eh!QyX6&^LbNuA#9vH#N_7IL|#6kIDhLL=be zEg3Cwmw{A(cm{&T zPg>XIWX24$Mj_#^k2I91C@h;b$8WNVr&MLjEwgAUtSeJ2W0)6Fit}PF!K&1j=*+6g zL{XOUrqhNyPLemIF4C&hThR8fie9^fYg$yl$m!1|YgcPlO>TB-(X{lkN~X}R=GA!Q zou<9ZJV6*}SN_4WRsqzRGI&p$;9DxDFTlyPw6Q9rlo@E3tMN&Wo4eFs{1=RCUij$V z`8)kmh0fhTTiEyvRl90B%q2(Moh$jg7{NeQiy> ze!H{zbG7<3BcK}XE&V_1kFfGA7D^ODxn*@nqlp!{LhYb47zIUlV^m+7kZh^a7L1^D zvI?m^9PECMnnN$0hi^Ur0b-~QgEORanrv|`dd;ek$4rAgEEof3HyvuYoZ)H*;+TgO z8CJY~4YDI^7RD7O)m&2h2K`-4e-I$1zcZ*K>Cd7~sSxEXc{d7-;f z5Ykr56Nkie%=z4_LIA}H>c81e$%ey=2hjqzTxoO0MDe!J&PE@EmX49jQJJg?HNw;B zHRHr)3do7CGDa3lPAZ4LAnpT)spnk8(ZiFz$|F$1m*A@!qCPug>Isp|MPI24i>jp~ z((9EQ9W#Rz)0AYT&ZWOWKBNtdNYYm2QytK$o-_|W5j7Abr&73(MG+Ar4K!Ij=nKu# z;SNkveY?Oc!I|Vta2{rb@c50#p_byn|_tu>Pv}6YDydl|}X#4oZW2 zvq)Y@8iG5@6c3?uu4vdLSBq23P&qUSvtGcu_qgH*?KfaT)@QueLx6apA97FI7sXP=foe zmrEu7;%Z=yTTGUsHsjR(wU54xNPI$hLFZUOwh=uhZ&rLammOQ?w*)}?Ah#%&K~OZc zl#Owj1OCEeXt!ALV7LgJ=MVbCo}<%92WX$wCS~Ins}%5+sb*C{WoOT5*2%sgjya;~ z|A#;k?j~J9qB)Tku1BGX=MrZ}<%Z4}i$OvCHv_3vtH_NZoK zjJljjt(~Yh%aI@gFnM*e*@_*N190p^@w5?SjRMb66N_^3EZ#Yoh<8FM>Yx$+mTbp$ zjQQS7(rs2j^54CJXdkH|$1&$wPOGDvm^@1o1pl9~!5&B+I=U-f_M-M&r3zfp2%TH%Ib3lz-^t)+Z9E+>W1Bt1`B}rZ$hZ3{0n|nZKM9O z$?_1+y}fB2$zEzE$zC#46=0E_4x7-VXY5}<+d!g2+Kg$gvU-Xm-A9DBZz+bZ*zDTx z$Wfb93))oLQf;wKi5JBJ%$yq}m42lacy`bC9PjFg*}pCnqn@dv{k9WiwCC07;6n#e zJ499v3YGQ^WyYY=x*s`q*;@R_ai1NKNA}<6=F8IvJArr{-YbdY#{l1K{(4l$7^7We zo~>}l=+L8IJ`BhgR&b$J3hW!ljy5F`+4NA06g$&4oC-`oGb@e5aw-1dSDL}GOnUuy z)z1W)8W9t(7w%OCn_~#0;^F)xic6It5)3h);vuLAKFS4b)G;Z$n-R&{b6h@yGxGo> zT-cq0W7~n+qN10;1OS+*c>H$(GoKq4hGG% zL&XJG$PDQ6K^BD#s_MsnlGPE+$W^B`&a+Z+4;`*nyKil99^E(wW?t>#V_xYWHLl2} zIV`uiR-__g+<&m#Z*4E|wjKY1R2mCm%k2ayMSDw`Rz_KA!3P$uIbB`dl`3&A zmT@gMT@ZpAxBys8zRtgoH+ebSaVA)maP?G1=G4x^Nw3mV0?qehWL35vMI~p$y0hGL z6@vHf-50P~uoe6yY&*D)Ekmi06LF!Jqz9#7kMvWexYMbAn{}`{3ZBsd6$5jBCujDp z<0N?b*1%T<-_Nxh`lKtla|FFqs7RZMtjHAwZ0Ck&s{x`#^S?36BNQN1JU^0f&TRoC z$}c)LW7)-n$CmAg&n(96AycC4!4_*D(~HvXyLW>HORuI0;ny$f9h{!Ud0=X0x%{l6NH$ z?lttWn}DQL521;-r~Kf$N_YPo)7H>3gI@Ivt}GnR=8W~Nn7_PE_3{sRNn`R~bs`g1 zoTh`7o4H*TRp7VBp=%>&t&Cd*Ny~@;{C)P;62d^dipuJYUV3-Dh<#a&AIxtrmX42( zYEH-8F3|^nY-=yw(?^d!hTojNxr~A!n$Ao+2mq*kZ&>Zm+BDC*sul=~!LUtWiokIB zxc(dNwyk&5o;>WRt)Q-Wj;fvuvJO&DLPe%mt@t!Oq^VsoIN0iTh%fh#`-{Ha?a8gf zj^yA3`=_NEONO0Z?}YVP*dL{T}v|A&cE7$_0G=g;1s*WDQuRcq>cJ?z=8b5&i<)=3ELSW%Kff zs=my9Q%8?aMxZeDq=RBHg*&HnIeQ_}X@oh=f#?C^HSg?1dwLn#wu(o^uANrRZD;H; zYbOec$#wJB(u?w22{gV+zb~pv|Ag!q$N@^|6n+FV5-X=lR$jajjeRh$1tjht$URz1 zhw)(ksAr2;QBXH9T#A$6V4PsR7K)){JQb?79o6&*IwDPZknNqySIa6pwcs)~xN81I zKc-GmzZ$i(8RaU==$Dx{tD@4nph-V*=W{Ln97*VEN^F+u0!F<%$l=K`ikIp#<^Yt} z{rx1gk>;rVccPIo6hD=xPQ$PxVwl6Cl;YI6iLf3!aevhsyXXZovK#TOv0|*T+^ii5 z+YO`u(SO3@ybv-DG)w)E;@+ULoj_+<;mc#iW8{9Y!99vE`HdAK=Utac&Eq1uy!TLgOS-C1E90Am)B{Tiw z$>$Er{s{snLEaO5@u&zqxE@v;p6D&?u@40t{#VNA&7SZael};kGEwnHgD4V5RNM@g z(EL~B=A8&?pPPW-fTja0Oi6SVtI_(3ME!qWLg-uK2afWhBn(C2PAmUyu^2h?Y402i z9P03g5$1#etGdUUo?#skjQ|$*()ybRGMXM`-2?jjThnTcPV==7sg$k{GxYdF+S*zz z%dtBo(R9!7SW6Utq|wFpsKMSAH-x{WB|Cz62A8!p8!kHz1tM=9I=M&xqQG zz17xBW7t?Q?C%@4YC`p*za(>hOrK&ELyDQu{5ACOg9noZS1SGh{-FcLy_W;nf$N`N zGYxdIzy7mL3K@Kw65DmvPH0@&;T{y&jP^AsaYENi}q|A z3}l}5V?z_VvpHf%CkpN@IK`czOuLPY=yBUf8Q3b9$X|kEiYROV$`T8T7ZjFPvKhbK zDYxzz99JRNzsx0f1Y>IrIQq9o+W(TsB(ZtN@4*)DMGr3?4~Jt|37IBI|7oQknQI3X zAWs`45xiCHga9;8+W{|!Yy>tic?%SNq=3EX@z2Mk!P0dKG0NCHNz0*F-a z`7K?6d*D4ri*=>wyQyQt{_t=t95*gB1|tdTg45fR{KmKD|3ZuM$QlkX{-tUkq@3Qd z-6X|jEyZa@tuxB}qrdlJdc0{8``%3M$xl8$9pUzkFa$Ww{Jocp9>;5~oNC8o`3GK& zy7_X8YoQDCO1TU_a%#Q+rC?Rr`r)W8CdpEe=>uMYDx6^46V_1DthgX`6CnF*E+%bY z=GYih(DizXEVFDuQRPQY&dc2p;Pwo7L{I2r3;QV8IEPg1McP{PchEUDf} zbtSAoBMPt?&Q@{fG_3a7gzHl58O7e(h_F6^rKgU=a&(^WpgH3U%`tpj3CMVRA-uol z(hA)(VF{4@`k@PREUQJ_8w6CcMW4Pm06{fw^*>aMH%#ik6lD{{j~nT}Vw=wZ(;Ct& zi1nt}RmOGrVHP++5;Z@eE*lkdw~?>AJL_Yg!~p*adS_s1`_oT1B26S zt&1-4twO45pMl<5B9T;SLH9Q?E>dBXcy@5k-{YQ5K!A`=YMYMlLOYc(+LdC<@@UIZ zxq%vI<;6P)=W4nRb7nxQ9KGzXsOjWs_3V-2*V+r}?dAZA7{7f*>^PxEw|6+WS0wAs zen2zj2cFKIr`~Ai`YU|OR4%DQw8uM=|g2B{;1Ho`mx@??e)rX!p$MSlA70pKVcvZ@|fYLpEV~s7G z>#?88yv{ekJpeJL<-?FY7wf10XpS{B4}jy{uc)7esm&J1)ZYt5LI_{)0BkN8Nc}ep zg%SYD0Cub3?KXLY*-dYntrghE|}%?RY5i3yVcPFlheiJUMLIr=Xp=U-^siywr8MF^JAEwl2uQ$VIfuDFPisd}4W2ZxY$C`2`tBTA~ zG2P62@*~(9gYmO6#Ya<1TG#3rQd0BwVyNP@Ayt7B(h%z<@N>Iz;|2VkT8T3`anW@3 z03^F>TCLS9Y*sY)#=BX5!LYD9Z;z4QSOL2^Zw~0e;OutRfp)Xu83Yz~srLh8rR}fp z=#yHH{&=!mHgDg!b;9K@Ux99VmQ*K2Xn%gV6YWHHw(<_uA&($p}$2U2TIs7y+ zM7X5Yk#^wpDE4kQZmN3&VC{!nno7wD2`bEeAwS;W6>$oUt#~E57Imre?b54{c$`tHdB6GMC`IZWLL(%j20Bh zW@}9_@4EsYT$u1Q3ZPWkvYxUX{6AcsV{;{1w60^@wv!dJW7}rOw!LE8wrwXJr(>&Q z+xFe(e7mP=RLy@dYSfEoS{pC8KXH4kGf zd``z`=z(*mSdLiXj&Y{>&akI{IMzo@tD>a^<(r*Ssf6Nz;ZsaLra9mcD`MN8$2`!w zj#+BZCrV}b_c=qEqt7{oF$>wI5*0B0kP{DNQ5_-V9dZ<9u;vm!(L2I_#p*nprX%tU z!{;Gb7IuVBg7pdB2!{X!ZgHqp5+?drImJ(UE6~P2|C?+`E9th5QSv!}?=L}=tvcFMQuyE`=pek1zbRxBAFdgqqB#0~EkA_CpTe0`e$i(eyMD!C!D0SjSaixQMIl zQ>-Dj?K($9qMGwhRqIt28n$`*FH_6v*JjZRnIMxz-qVe_KzSGY5Ph0$(^e$r-hLD4T4m@eV#69bG7_fQ>o`!yu97p=$)>fb; z&!>)wS*Fj!ag#iKWRWiC735;`@XxXFT)nniSe~^1r0v?bQ6_Fokmx~(-O5D{7$d>R z#Us$PxL8^}t1rpnJ@#E}+O?`@a4wB;n{#!lX6WlOwo}C3TgP%?N=BT*FrxR=JR(g$ zJn3EhTI~xj_mVxhFImqt22JE`CI;B~Pb~*cFE>{uL*2mnfeKb_aYO6sDC{Khp%ba`v>+M4WqY2KK4@w{=P~Tzx42!1yHniJT#~*CHF5|TVC_n_ z&;r3b9d!f0;?+iQ8rT1N>MM-D(HQrU-WWU9=w|>nbeG#luD0;ayPj`4=&7Ik$Z{Z3~ z!oob~d$cMHx9;vjAfJ{XC6R@pzkLW4q1ak{?IimWUVBKithq`vKQD14&60gGKCCale{X}Ft0By269l*P6r zuTm0E33lN!&zezRh=5l@mQP_RAR5sr^}&4j;(eFAj2@K*7>|(4IdGb4yB%g88|TKZ z^M@nOtS|f?{!z}s#}S=w{R0`LbVP{k5xhlw?;F>N1tIByWsnp`Bg)hb4sZR>Y12=3 z!#Anh?EEZFm==f$1I@Zw1Y6-%6aE;!l&t#!4vB-%4AfB{X;!sT(jBKx*-5qZn|89Z zK%Is6JLf#w>eauBET9VUE&>aD*^+~!ilaiM?p&mM&kqY3D1*5QUGBbUOI)=eY1dMv zJ=ybPA_VaWPE1+MDhiYq4$DfAeVIv!IP-*#v53?V-c^a) zG6p$+O#_1{V`nNcS`{^%iBn8Oi4fO$#Q7x-$tp2dRs-etYmui-mt@P{hh?ldJJP!? z`!i88d>h`9rIRd6=^pZVuo5}3zUbAX>~uzA4C%servKlplCW0(Ta+B&Eey1CQ5DDV zf2Mk*YRAVjE>){hi_9poOCsx=BU4gQV)kovP|^v!npW_>^LFUzYHx;MKo!BEj7Xy9Xg-A6>kWs*$)aMAWh^_0Fnx;eR|2;L0ZjLl*+F1Moh4?D&8h6H6jJQ+OxgwJV51#)zSmqvRnQ5 zz~62JXPCCiwK9W;yo9-%7Xka%OtQeVDK5SGr51}$q@i)OE>BHgfOFiV%SZ5E(VC*q zYujoHFnnF^qs^WhZG}uBRIs4{4xGP&Tbtr=RJ?=4?;IaVA9Yzp!}H z9QDT#L{7Y?)r=m^ucWOjUuJh*FSmqL?!<1x{iOcP?l7BCorp91#(gUNGIQf@1)d1lXx(RAI zhm*TFNYgXZn_A}FPfh;WMHE%oCs8d+1emobQCt@YTjxcWoK81LeXY~+9)^+UOmeCk z)#LMg9G1`jWr;WZrrR$Gwve9&X+lKpB~*OkxAEnRpO&^BwsOm&TDeQBlvTv^nuju5 zyB8jH2{_Xtz=1n}8hD4nhhZvyxynbGz%2iKM-8|$N`wX8O-Toi=&@x087+joKHd4@ zsx+@?mPB(R?mMWCIeejm^dhs63ARzdm}jsA(O)QqT|m}QRWm-(Hzh#M1)wVV%1iJL zg(a=;b~-ZkGDk#mk1~G*z!7zGrRGL-8}=VILi|%;0knSAjJX1jZXYa@^cU6K|NAIP zkrpm_?r8?!`$D^>c>@hwX{b1l4f&cY;wwU&Q2vPM9oGB`Uj2&haf>bY84LFfn>4P} zUwt~VVTwui2oj$uGt#`OH>|MYjm8`R#n z{C%^u?$@fW&NV}iCuMF`&DU3gT0TNA(vM@&mV$M7yWD^p3 zN996Z8he29k4NFCg+9PbnZ$<&>5-W0fbtK7!ePTkfP37tvtUFQiW$|1%XoEZO`#0Q z2^XjxY40!DruxCn-p%m|j1RfInIaROco}Cf&3zhkkBHj&Rt=WZ_VkNJdliOb-H{>p z4n>c+XW~q#1M6<*boFS%=vdUE3ndU*iM+EFUvAM1=)%}A49e~^iF9Tr^(nqF(J^n~ z49*I<-WXCZ`1EG0hYOd%nsoM{LT8_q$a&QSBz;#S3YCwj?)0mjn_saa@O3c^sMqwF z!ZcWHQHCT~S|SVe5eVTt=z64&T=nI)wG<+4e2@}Gp9#uWEM+p-{L1PUC zM9N-bN73qWRRpT*YCLuK_D+uRgFcwsV}^odrD$A zI~cJDK#5qb8UPL(A_=P(=)Z0U`Aq`WLGuPhE^-isi?g-0`OZ?4kK^MyAsY+mxqt5G z-B14#h=^(sGv*CF8}cd}Xwl*_z1KEt!uP`_(wPBT8=FmK<+VOOk}fZ4Gj*{W-MSmu zygps+?d@%?tx#Fn|0(KF86C^QEgcz^1&!sUz|u||p8_`(gR(h#GELI8FrjSjfNCc zYJ9BHx9555<@$3ttNMYtIMa?NQe?V&_luijx2?!gBJ8tg}l4R@z5x73q4 zfZVtX0lZOzVV%@yTg!w5oMcYuMfGrD!RFwqChHhY`G22|vNLn!6a7VRi4gD!@Ae2K zT6A|%SwkYp{k$!ki4db&5nZ!Hg{8dj)h57Z<$r$9=s?;uzmx54DcKt)m0_ow(XjO@ z{}vbrW9)Fk2;8-9>tkzX!IEOW7lMb$gf~wwZgu2{whBB$YvW7BQSPQZQDy~)5Wh@8*P!VrB-YNi~zFb27ia7UtoAd`4C|JS~iU%&Qw1UMjN zC(CRqwMFj@{DT5Q%Z!g{RpCq?CpzVQqdKjxHQ1xa=u_EKr1ec5)TH;7hvWIn?hs@&K~48_$RK3+ zdu{2({Eh&7HD%B{)|+9CYaV^V1<$`JDFoj0UB!kwzCp*vlO(9kJe-Iv4aj7J^fJER zTEQS`H@RGhfs9w?M)S`;LliZ`Qvu3g2?r)nr?wT^cRJy(wBCr0MDqtRFHm$E%-!6g zMLRw$2+YPDN~0`{Vm}H&to@Nr&fF{~L0>m}Ghn>Vj81s`EIQnE@l@Jse`#}N0!!DL zkzs?x4I;fLH-LS+=E9Vl88}Td=@l&5&xyb1KaYf^1>c=cC+$#bcr7(`-gQsjD7Tws zxszZy^8Sv(2%nbY|4UVV<}>Y_l1lTjrKy;Y5${ej*V%OT0+D~Ec3-9;X zs?8%af6+X@s}jQO+NREG?W&1rhl(x1!Yfpt@?JLkH~UV_9l*DG6qvuakx_O+bAq=s z({A;t{jPMtJAA3|O@KE~J3M!)@g5`5KHrMBrNC_Vh4B|&pimlm=+i4!K-R<3m20bD zzS$Ki+QfH%hnUo)1S~{GWomug`!{WD(v+ zuvqIy(f7nrv3AgZ=8rf6?es-84@=OK6qbY0wJ-G zL(2?kPhb zZ{|(D3#69jUn8s@S7FY>F%&HMCc-%c24`6k2TkwB}T>7a66k$Rk>2x3dp&D-EP;6vCr%iE>GKFx;(izH3Le$SQsp0A%5 zm-Se9<@jb?{00JSx_;^KuDtmei!?oLZDoJ59(**b_6Y`2ZP$kvK4#2^Lk;B5oCirY zRlPg?{iEPr_J_ES2=O`sJ_qloEFsXBDQ+Z4sZubH45vc)72Y|~@)oVTzXL$U?w#*n zclYx8f%j*|f#eOo&_;}Am3`vA@XpB}-9L>H4kiQkO%r&~{%W@YWSeD_%B5+F67d*j z?Utu*W~cd#8x`Co76I~a0hZ}GzEOX;;hDT#z2m$G4zcHYIefxJIe3HizO!1pDziPE z*|lfM&rHZW`dhSY#7rpieqo!w>m&7!e)!(++5So5!vv0pL0Wxlkw z;_!rN(U5yR9=>CNO_J%S#)QEl@X^i< z$-v~-byW{BRXav4GT1VHt3jrFK9-@DZunt&iHnR->YIe?0!h%8oHlN&$VawG{+?<< zoY3lysffn`42Anr(od87p_%kBvtEl~1Jq51oU>0Cs?E%&n0t{t#)ExsgW$H{YuO*? z(`4X_deFhMU*%36&*Y&?o78sAOZl$&98gl@b9zEa>Ul`Eht&~4&@b1AzPD7{!Ati$ zwXVr7)>u0Sv&p#{4{|Qcx56H> zF?_X1-NV9Zi{jD!EQY!op(nLS=XU(DmJtXhf;wDL&4dvd`O>zAaBzN(?%law3sn1p z_#_Z!M+Gw0@Qk>REY&5+l&ECBG20Y4{6#618u0a_FxP38r-^@-!(PFvJl*UdjdBDn z11S4BYW3AgDE#Gc`TX_x<1XiTCER)+z?$_X z7n&6Ev$hKOggBsrg&CpBUpqPE1~%I*WKQW)@&B^`ZW5)SBHYAX27S#;6vo)8c5BcH z!iREPvmG%-xk%IahqAZVSke7KH%Rm!>V_tpH`>bSS4Y|tT-m!g!=Ni9VbK>Rx}WE8 z1ss1w(!|#dy?b|&w)Q0+&&lInD4O`WjJ{*tN3GHw8{8SD?rdB!ZRgxa1F<=81)1({ z2JvQ>m?i8VI<$}9MmtE)MyKN(H%%Ec)=3jmP)K#QS&7qL0o;%>!jhlVO3 z&jsJtdo5DnGgt&A^6{Y8a8ne9+lmC2B)oq7mWC?KoKbd`r)Uj|vMQx$o%)qPrk?b_ zW1Nh}Mw*Y_&LN|blw(R7 zFqMcuihIjBcSQDyLEoxd@%w52JEp%6+H?S#HPt_I1T@F@jW@935OmoG zE^SH~5V5=!n&E+yvOEFgM<8j%Fift}(j53d3V%1r9NT`}I%2p0$%QVx!#G2{NyO0x+|GF&XFcta601En$nx7I1 zQqAX}hG!*oND@sdrvXZQ=WU5MOE7QtKbgX45%?B?waqj`sNjDd- zUTH|{!iKvo{j~L-X=^?Us9D+2O!SG>$w%in^7zGGy+BMpnFr)#L4Zc0>7HJeEGS(u z(RiPD!>0L<(^-m_3%r!)MMdobk+T+6rOX^H>@PRjP^E3Fvx;U$0pz%a=(m-W6LZ}U zX2QnW7lPQm!-pgsRh$Rxq+tS|LfE_T9hZ*a3%%5EE8!rlmCi9s zC%T&Q39zQ(krY&I&{y3pYWA%5nHIL{j;9dmcaU{*@}l1i1fbF-HD&(6I+spEHr?l5 z6XUR+=CRY)I%wupKQI4-`6@A*Z2p1C5}Q+EOD4Yb@LB`10Ghl=YqM}RO`lWgijdXcY?-_PlpTe z5*pPp$8~kOI0r-}EJwDCeZBX!`~Vja_Xl`%VEZe$l0N#Q`pQFV5Kk9_nkJD}iNtEl z0C^Kr-ATPgZ(oeg!%ExcVXg|I_d=BoM=ZHAT`5PDZJr04Ur3RdN~zCSJui+P?cOm? zZ_4uvSbO6q9^3ohA?X&NT{--uRs)j1^n_QP0Q$3&rxFIzTz7O`nX?jRXhg1DeB#5) z(GfV1DF?0?JQ|Qk@MriD8NQBaWeKv2Q%Q{4hBkh-u_vne>zF%J~@`u;J25*=?$ zdhu8F1#*^Vel)g8@`n!4w}b9O5MZ9mGr6l(IoOWq9%{A1u0kLk75}< z&VTouJCQe<1WILdAsGA2MManwFz@+UBd8q0t~Z?>7i9wlMSc4rIngyRBL7^uYc7hA zBHUFVhg$Uoyx@ss=>vt^E5y7o;$7KRvv{t|CpAnB&qk`W5$c_mfC9N(b79uh8{1b@ z`%f{Lmb-*Z{$${zz}Myib@*kI7yMEizc6;Irq>h1)$KEnLBTf!E}{B15VVoV)p+aT z76}rh#zlkeIT-ez_6b@mR`!5_WT}T{kciOQ8yX_<@OT6_PmxrmJyWnWqxT>-Aho3b*pIl1(z(06k|pbILiK8h1e<%dkjsXB~8Vf{m4 z;ClZn{kzSkl4$w-j^Qx`(3BIce`g>_bgmJy8*cgJ=8Ty6LZs*o(tJ?TUi$1Et5WlE zPm1hE>IZ@-G>o3sf#8sEAr@8W4+aYgQTPkDDhUV$hNQpvpEmwC*qRWQY}4A92_0DZ zmPs>)&dZ8l5)X-zicS159QB4{Zwz=3=NVHv+vF*NB9 z1yz|msvE4PVio9vx4?D z{ZQdbB!aR@k>T3)149tjYac!k9CIDV$2WZDZLI0o-b>X4G9HSuePIX}6fDMrw_{k4w^WTJKctikHje-7u zn7gF^^f9vkrII_IBPZA9zyVn%O~I^a3h^!RY1?E;v_(46klc%M2I=TV%+aGbx1n_|{GwNit$QzspH)ZRKc+9Ky0a-Mj~~W; z9=1QW{@mQWZ0CL4h$4e)g#u@U;Tecj_=E}U`TnGM7>o{0dU4MT*|8>hhQ`?UB!zFB>>~9<{V@O>aC9U~Une3IWIR5R z_5_;sDvxI0ns0l_QeF?}X5QNM`1(*9drDI7dr~8llWtCKyo`HdZv%?+Yo+%2`Fb=5 zKSVr%FvKu>!KA)Y5&sPD zuJbS|=5`k){vruC`iTofuv9tp)kTGFd-$o@dfQ&XgVVImF;1#Xx#`I3vul#F$qWYb z%LOU(SbQDVH4RnT>9}Wa7hO`?yKvd%M<7B)^-9gvI0d9NpIMkS zRT00KAyowFDZ=SlDLo`s`r?978R0T>hJCU9`HXoWFBuyu7Ifhz-OU9hFUQuonGfWr zokmWPK)otgYn@!v?`Dtcubl8K1%*k2j$mrp>~SkW z=^_So$+T1|P2fC#QyVCNlVUHq?y@pBngYPoosbeTuE5F>N&Y)$kL=WDpkyH~cO!1J zMU8RHS*10ceS^H7l>?Ax-ySAEq;fFak>8M}foyYCs-;Rmzg$T;k1$Bi^ZQD=+=cv~ zbPGjC8@KD2%G>R7`kXxj(wO;v?YYy^+8h$cQIphb3NS8{p_AkYO+3 z@r-QEvcg|3shClf+$g=3b_M|nrQ|lu+E$yX&=MQ;_k3cF{6!0wx6Dg;;-oBc9EN>k zD#NH0R)&||qCZOZwIv9erOFWBUabK&8^iW^&#Oat0LxZ=F3cTrBau=&v4cK^>5k@gj#zWtyXj%YL_X!h>bYx@JNuVPpBwJE56w;HXl zZ1;k@d>8+2?a%T+rZv`KSlm|ckXJH62?JJAR z7ldHyEgPiZ7!yX$7!&3vTs-Y7hkx;Id(DrB6cEMyABU(*M((X7YWt-L#i`S$!5}fl zC#oXNEBbfMF4HSLYC0$tY1Q-u&Ykz7^Eumbt#?%(T*Y>yC7L`~p}oAkt~tH*7e4Q& z$EWB(at2C8c9em~sOw`1CvA#}IOF9Z2~%FBmb4G8IYeC!Dm&P!zH#Jna-NO;Qd{(7 zATVoYNg}*h`Jn02H$^WRu1L+psWjwYMr~!BZZ{afjMr|Rh^JQYjck*m8ZE0?)~vqw zSAykMDOKwNT}~IGR-3e435!bEmBPlvKn{**+>sru9y;ynv+RdQX`cNo_%uiQyM~gY zkNXTcZ~J38fc(I+Tg@T>ta#K|CyTKv73iu?Y3>J!+07C?lcTyZWvw|?(w33jJN{5- zynWxvFsqw231<32Aj^xVe zS{qBm^{P2re~|C%4rPHF|F>PqE#D4Gqy(PQqW(YSb36aV+ngr7;Z^rsa`1CFOVGl|5mBdB0*q*?%XBXPjPm^A~cwh}`D~ z?6gO&d^<6m>+l5?;>v6BSph|=1uthK(GEITC3RddQQ6I%I8e=$ZwLj#N5a1>8ivCg zc9PxY9k%zK80_2>^XcdCV4!Dqbplas_v^F62wKZCbfyb7Wbkyg+t5R?jVp_p=87)rAsVG;p?@}0DhfjF2KY=ur_sDRN5Z@ zBoczZ8+*l`4CNsWF7`5M9V-hSSKJz^0xO62%BvUldB37t{XX4Ba8~4nB7(_iRUV7C zZ;UVO848`?$wGFpL>#F1+QXS!7Eecu#h!577tuSg z6^-(>A_N+VK1MVMP=Fhb(cBTDWU#U9m4gz0I*3`Ekeu#d_-kiPg!qv3`67kym=Gc@ z4AmeEJ6{D5GT9l)0Nt?D)UZ!J6$_sfK%VCX&4dy{lH3oNgOFQ2La|}=(_+;?BPZhJ zbklwJ?_h@!#;1t8lY{2DbWMd63lRBe~A zUI018Hx{L;2 zP!4pmu_b}ynHxga0}8?m18nj=$kLnve9s^Ie^-H@{|7@7h%5N$^Is(t_dm!303><- zFJ^N8IbO0tDI&&}NbSz6da0ByoGx4z$_S2h1eJKQLn#puSq70^es*d-_l4(XJ#*_n zK*J}P(truL6NXuaq7uz`1IeN|p&1V&u2eyhN#=m1r|%dhlWusBQB&9Kj?1K#Hhvs^ z-dw2ubqArME!@rtqD~^LMn}(jgSFkP6{lq?QJpdKZ;mfckF6(uBjSn{+8(#`kG@;n zm3xcjQ0qycjaDG+MetaBT!=+z$|gzdx#dMIAswr_Th_kYiKDKk!&_UmUaRf(O6SR6 zzMcwVclitdu{K&Gt?B%0$DH%Ka)m`JL6Z#Jpcu<41@jFbBz1!FpuJbOJ)Z8kHKT}Q z_!}IRR?c>0&Nt&Qj;h!jwPEdQD`+lYT-#aWIWB5Cq~_MoaCWl~Jf%0pW3b z-Ku(nGC90fjj`rXh7Cc(Xf)$}yt?d+VM=r=6)FS@`OQ&6LV5%jY**8LDEo=q2-2;W zXLFz5Yj$C0KPF35%Za62bizyq5V&Un=D1ejqYy`jNUkEZx`7gG{jZU)SoHqE-`bUo zsxgy5URx|pOM9qlM|Bp2^+Otw#8?sx1ynFD)OACtwIT+Y1B}#snwfkd`ZNWUuZ1Dg z3J5J&JYAt6fN_#GTqdGv#wb8&nj)t%)0R_2(EHvf6Pta)r*dD@@=u{net~%WnTTt@ zjak199mId#cZ9@4m$bZo{wloNngnd}jm87j!n|hi9Gq)eq)1}J2NY6a=#-LWMACKc?Fn0eJgkvFVwzHPJSCda^P{jTCuDdIo7gYl<=sY)}+_Q3T%^*<8y46+?f*t zH^<~z8%7i-y{g&sZx`Wx(?%_9eB=1?F3Q=~ZWpcXS2{)%Z9?Cz?VlQHnd}xq*zI2y zC9dbVFHaskv)NGv?a~q}@_}vlro>|<@v`XmF4Xxq2O;^%wnr{e?a?y4zMGVO?J%x^ zqr6{Bq#9Sdib%!nZ>kG=6?f%d7)P_OZ)Dq)iWU>+(HwnZ2ea?AwD@Sgm6u&|?0uVx zHxW#~O1#4B=U!!E>x~yKjHM?d#H@c!rP-Zxm{VDkNw8W`WrERLYXUVKYIYoFqPj*A zFD}v?HkI1j_Hx{o@ika5m+~!ax#-9xYI>XIWkO7@)a8b3_C=V??O4fZ7soW&yvXmK z-Ps1%D+Tf_>unWrYEhe=B?nJ0+0j#f@%V`N7WrAJ=nVTZJE zu||VpNVe*I9}B7xo>6jqrpD3elbe=GMt4c$PzD=N*o1C^{TEqP{ol-`R~MW*V!kQ% zn+%OSPE%}dn?Wye?nKP0-xm5TJ80J_9&2daEWBpADhIPefDBt{al>tbKt)<2snTIu zZ=8K+!iMD>YoHCf*0G)b%;7n6H#1R~!v@As4^5D1lst)5TM3#`b+OnbI8 ze2bnPSnwdjYL}M91Q_*VgiH&E$IwTZ8S_za4*+yAgj5BfnG{is4=6UmO(6JZKUR5SgyC~B8+P%s38NFVIE@Q6rfXPzmilun?o|)VM7f+` zBdcF#M3FbOR$Q@j4_G#;NQenj3gRkK>d0ZD3{BN3G>@?AF2^t#o1j%e<=&-KcS+6# zm6Eq30rjfpO$--s?Bj7Y=s=H~<(V?^04ns*QVD^CIxlO0hb~rThyP*JH%;Os3o-J4%j@DjkQ* zLeNu35%fvejsqOEvSa^M)%+~Sb>V1HspK+y1Fw_zI1{Y*=POV}KhLx<6ibQ~4s47T z9GzXb!%Psmx}s#;glavT22gg7+Otqq7wiTH1hgtBRnI*GQ#>D9U4?Q(U=8Ef&r_)N z0=gyY`$sC*AdM`2lT31sy!%Z?Ys5TOU?=+5bRrov=-JL8B#s+Yvyd!I7ej~T!?yqB z0G*_hL^v2o@bg96In$!D)){V8(7HmoIrS38vkt=Hk`(G)a-;#YyjiDcdB0a)e+l(c zZm;JipJkXo>r!!n|Drb)#WeSzW$q%|2m4c~$7Z)uqb+w8Cuw%9_w^&^?xo*ck_nj3 z@uxkG#F&A0mw=OGT>nKcYT1XP=j~}ze zn><9CpZC;te(7Psr&pm%h}d%@$tGvUmk74-*flv?d+qOAVh6;i))(ag1T^!K6{7w~ue z!|EGUtV7CwfxW&=hxs>+K1hz!@B+U!ly3QxjW>KHQcY2c$WirWOqv|mZz>>sCYc8( zb%Zcz*FDj9+sw}1&G{$)chro>?Mq@q&LmDOu;2mtO(FN?UjNt5^ovxp;t5fo@QHzU z;@Re6YR|x?3ORQ%4G;Mm9#`^!7H|`;Xumbak->7ftC1n_fQOOC(Y%4vPXoHvvjLG> zc8D~=@;n6U(W)GDu&xX|!V_A-YIzVVtZDOu0=ci9mBwRhz zFqbia8@GeR7L*&w&8f2`d^!*4v5n9uA^pY1j~onD8Uz=Xti(&Y5Vt=jP7-gF6G4=5qf>o$TuBF<{bDQW z0b?DoR%bxUoO?s<1AS5!>{}@}*5I}_zrca*l2lfIwAeWp8$3sC3 ztEe~-=&EHrxI++EdY}cv7fZKqiMa;iYSBl>2Oym1mZ4f5e0y;F2GSZMs^!hUS$x*a z2x9lgyVN0Mf+2;s^Orv`y{3ztYA$?w2dJ!1D4*;^h;JGzMmFu3ry}jIu)6VTR`}{ypXCA07t@KT>O#Gs%@vd7>me@^RA7eN=#Q>CzXb-L%&MZzWdOV}12D8!Qm# z!NxL)Cak9k8f)TR!7r3e|{Z$-S|MS9FN8DrR3$qkh}! z<`ucgSNcmAQP!FnVJ+dIMQmR>##46@b&ruT(WY`9yt%YXg3x?K^J#|)6Kj>n_;2)0 zm3y_Qk*;Ud)nT%?iqrJm(>i>`eX-3+%cjK$o3rJfDbTKEad5T1T|O7#9NrqHu~rmt zN#ozS^(SDrA zsv(RB8@C1~R?f8Zekms{TPVD5IM3Z5td7{^#dnE0>oo=gjzot0pc|W2-CS6Sq_xY2 zKMDYyz&m62bzH&UjDIx#Y3dY%4v<=hB-68UFkV`UdO2n=$ z#L&BUcq-2)V8}*ybjF?kFjFJjt1T<@KGe!$-^(q=N1LgKCHaX=4v=|7;o~<0rzSEhRMu+*`oOKW z5?SX<;N?sF@l6-Kc}=7kTvS>_d~#^UkwD#!5W!16`VLA}O#fomaSk+2EKlne)J(XWzpHxYn7?p-1nR=c# zTBjb)7n*)FYNEN|o3!YkmYQ&hI$^e|!bc*!!0>rekNz!DNYZ#$6A^S^LvoH_P$Rlp7@a zv#OyyvAiwaMX5Am9pv?V@u_5A0mA!KU|3&r8 zpROC7?dY#2mr0fJZOR46^c1;}+FVaQ9q~Ysb}-iX@Fj05!hZBw3NZdz=k&|W(w7ht zbW%mADXI^t)}f#^V80V&k3;4+rO}GH9b8#W9#VgsSAjF*maJdH`dPzgJo81_2Xj6B zJ?M*!zA#+fIE5N^f$!-N9dpW~a%ubr zd_d2GxJYsVk4Ts)vAZiCi+n{SDW=MO5zSQ=ui$AD&S~!p9(aku@VF^KE&Dp%D0f|I?$O6l|8FC5g+$-iz8m9mo|L&C8{W5`2ds*u}tmk?Njg-NH$ zuYOT^Z6+X4k3hP4;z6TETdvNR=lR#Nrl9yIl_xy=)8Zrf?T?DGarFi;1Ez}5*}eDF z*k0GJ++IymAM%H#tFlzTmafY98Ox-XcLSY8SwvFPht`ItUu$z4q86N?zTuX>LiAb= zlK=f#yCxc&orpOyjF0y`XPSLU#kcRfrbv8KNQJvbMg)Z051D(nq^I#O+N~k_rE3^b z7d~@V=<*_xEmBf5X;pk)FMi%&)Db#b=!dc5kMQgRc5;-gb;nNfstPyH)^Ix8@L!5{ zlF1VP3$6U7zVU~d<_qiWn#c2qxq?4l>5EY05pwrj9OV5a;9Pd1I5*(JJPX!(wjzNZ ztk+_oHW*koHw&sj%v}q8^&1R8`YYHU@|{TOdBLH70I};=UY@EUkS01XT#dOHO5)we zAg~vu^3FrMVKr&i1H#u2m-wJuqWB1}w_x5H(JExSxDp4Qq{9U}k>OtiWp+5U@H6vL zBilZ%XL1Ifs^Mk%ad$;&xX#5S+!T>@H@Oek$1*TUQ21Cg<@w+eVAbh%`sIUJ;&s28 z&b|j-P)*TP#fmBIGS^y9D=0=;SE@SUw34e=<)|rOh7_X)eQ7I@l7#=2=zL~?Q_zyY-NH*)p__8 zXl=T?l&$Mk;T~zeH{2`IHP5}e<7FBv*>4~b*qco{T4Fe{QmTwndm8vgt**DfC7CYj^x4(3e#4BnUZyCm>k zsypku(lIZ7|KRtdLkDg0(`D|@fP#}ehZPFpUFrPB%_3QBQU4Pv^DH7{W{U;8ceoPy zV~^F5{ZZp<93x z9h#!%4@8_||RJ`FEIb~EFW}a)A)E--&5iii? z%}-rwtJHPYM=>hb??##Q1)hIGlDOZ+-FDeHJ%>og3OCN~H?Z~H=Cn>dYeGTf&^G!HJ;=j{ObHef}gi_Ld zJJ5hmjNqRtez^0*hgfd>{R0Zxyw&rJ0*4)#u8s9yzg-C?d25;-n4+(`D1;FQ>!(sUC3!(_REC? zbP^_^zyPg9hK;2vAV8PR6|A__<*1qLq6$Eq8l4S6miweXq5?a-nHN^HdIY!f_-o@u zp>Y<5g14Q{Vq)T-cj+<(iSIn49(9+qkL2C3?9iuc1&4aE89IqL*f&6a^^zfQ!1XvI zfXQM>34_t9t82$vL;XRil9PbsK+TGPzDy#&S3cjbOdEm~NI6t9>84uAq4u_*#>l9q z>VI>bQwUr-2dEYXydv#&S)X**ktfYGV57CIm05Omhc}Jl(!cnjYr1cFV7GftkGncB z&Hn2ZS{d3RwD9IFW43<+gepDlSxb;sKMd4%92<=IMHrjqXOhMtmgBT~)AzY1_Q_Nj zw@j(JDHekRvv=jqG7SP@l9|N~)7YfFU*pUw<#ReCAH21<$J61cB~wM-4wnZuf?!x8 z&@&FDqPxuKW1#{Qs|nwITE(P<^g=KYP1JZt=8t1#dyQx~P)ChKLSV$ir527yem+}C z&!-)ct4_`<5j}3Z5e_5){UC0`%OIs5&V!TEOyxa5zGJiDegY_wdbk620d=Q*!#?^i z2(l5VjooD9Z%&w*U%NHIDy}RGVS6`mlYp4y-LVW1;yhH5ADCa|jvjb^77b)wd5-wz zEa)Y94>QRui~kZH!G|4I!~88=%0&5G0eO<-nmHrap#K1XR^grjSe|Z|icAjz75nrP zACVIcUvi7-|NNp!+-;Hwr2EQhS0&}q%-04`%he-MLZ%u)DE3(ue zxb}WfOasYLv|TI5YXcSpqy`fNgeG}+nlPF93JI91>1BvY--xvJTv2LSv#U(gM20pcy6m*!qT-REi98kj;igw`RKd( zC~Lj(W4oNOhm!qSdy9MN+v(nUxk~==dUOJzzjMH4O1xV@F(@m5V@h|b4a{J?WriGBkzCCt>v1AD;OO~ud zS+hiL*0B>p#vMeuS<-!EH+B=*GRP8IgoH@h#@K0WF;|rG%kOEr_vJO6f6jBx^PclP zbLRXpXXg8SK7qpH#M2sM(~zwCG;wtNyn?vMWGJEWiqBj0IAtfzk9VBXz_y~AHU6~9 zecjKYtN>+acdRx@uVVO?`NcJ&LhT1VM{@&HtRG3?=|2^Z60B~K*p@boc23}r-TbaD z!>XBP(u5m`S#SH_8J3gct?H5V^cvy_&#begx)Yl6h2xK*oRO@Z_Bk#4%g%EXE^a;b zkdlQ0F~ST`@j9*Ukp#&{yF1LU&!?+q4-voEIiw6U1cY^&#p3_)YP{yLY(Agqbw4*} z8(ZHtUQ70I_%0rD;mz}WmdC+0xKo3QFeYCmLt{d-lfmT;q-hFyBwF=F%k9>_`t!PruazqK8B3CmUW_dDa zB)FO$wiBn55}KS%KJ)C|1^w#z0|)Q6S9)z{ffONO7hcJN5)R|W9vdu zoyY?Fc{jh}d(4(E0)-LvT6x;Xw+t|wZ!NgmE6k&T#;PUpagBt@kH>C#&)1QC7t?o_ zAGL6{))=~`ebD+i!0lx%G|ZSqFsmA;M>fkEdtL1C89?>1IG+_kb(Cs5{gGC1!-(ON zM}(4=p|PQTfWwU^_usPnyyi7ADZw^bJ=~J+bw8SzTDySd=E@>hxg8&3{L`~}(y3Z% zTbEOv62Z1^`_1$_4C`-6(Z~G7_vh=SAG#x|65B2UCPq!?^i5{&D_Tm_eSWw1uIHig zn@TUk&u!KYG7rm4?ApX8yR0$1&ey!0O9w)5rKNLOWZR)+LC!X^mE!XjZypOQMFo== zmvnO_yf}T-26K4YI!MOfmLivK-8F#=<~6fxyZh< zDenbKj-#aen^9$u0nf~#{nX>NLw5e4-uETs@zK<|UKD6Yl2Ed0Icys!G>* z`dZe_AfCIqLx1P1+N6?X{7YMGtt7VEB{zz~#I=XoGkH}LvBRHap207-`iz$gn{&4{ zh&b+cohV1@otped*^G;Fg|p-3hRt5gX+$C`FV>nOxo6+yY`w>cwW2^NMP27@_Lw}y zeaVVqMbe^?%#osXsOgU-hFW-hvZ9_)GLOA;>wpBC`+#W8jq)h_D@5#SkY(|uF!^Be zvpDxpLH;k;0&3`IV|#nk1OM7EvmXh2`2Dis?iDd54f*uw}jI5THWNIpIqj#NNJ0^2-^Wl*XFz;=xU8n9fv&FLCRIMSj7Q{ZWQ@hZc50(s; z3m6Qr;uqSO66T^?IXs83+G)5t6Sk}PG{2s=Wk-sPcMR5+`7w%`ajV|Oy3(43TSu+C zM~-Zmxa(}^%;=3m237SDD%R~xy8}xO5~CNQrV)Ltrk&z;N6jZt9)3}| z@p0saOnkL#elg?UO_@Ig`wP$CW^}0K&8wf#eIy++_>C90jd2LruH+s%w`}ihw92os zil}cNBDANCIN?G$uC+&?1()6!CWQzL*!D=s5W4p6HKG=QYwh{gCf&{3AST zrcNN5Ph~ju9%GXq_H!sthKqWX%||#6QQ)I!eFR95MgKL%q5H-4IkR`d3zHeeKHiFy z(u>-81|;aIADIjbIk)%244uctVlG#1_LwwztihjJ%A5%KqOMyC2rvu|l#eN|91lN5 z=Nt%}c-$Ej=SrDJCxNO7n}28o!M0qw?(~+_vJ6vZYt6Tye z6T%7!VXP5SO7V$#{fL1jMC{}K@z(d_t)^>op*uwbQ*~aco^uJ0YYm$`n&-3CT0M4^ zFXv+7eDBVP03x6O-dE>vRE;nbk$iI7r0?Z}g>Ni#E!lJJj2W&fiz6x=Nh+D04r|@# zfX;@vAkD%`Z1>BilpnVOI0lkfdtaiv2ozv;#fqmZm`>4^9_7-NWrc7gB~{=VO0r|6 zi%rTpc9bR18A3{*7gMjq+3UOVpKWMM)QH+;&%Km}>K;^!mqB|X7TOYb9#>(mT>XWq4gBjFX0woPN(1n^o!XP zq~rFHG`l8OKHGr&=M^G~PMXO+(xsUFhg$FK8?}<)`m7;V2eyLo#pS zkX&aXT3)!$R%e?x&V7=z5>efncx|Ql+l*CJ5z3#j#p$}#Gqc4tP0QJgNXW1p`S}VFsL_g(d*5kcnN{R|e&8PrW zKTs&SOM>;#Ax#=6M1~6G&d35Z&T2GJkrEZ6pOpa)9IJjGsXzsSkdS{BB;hyeOv! zKFJJDEwaGMyunY48gwI|%#ti{pmXrs)Mit$ZQHhO+qP}J;Tzko*tRRSU9oMal2ljs=<)aX`hJabHP3$5o@<>0 z+y`6!4c0*S13}rfE2|m?1cU(-1cWwa-VZZH@dqxz8+{Dp8!E4*e5J^>D2lW|f-j0x zo<(~QnFNO1pI8`Gd=Dh1B^mL?ab$;(Lh-=8JXtcDpd5?J1y(UPr2%wU(aZOC<-9lL zfcxF*)xE2UIN)87z5VfIhVHN5;|_d+;QhP>h}{S&#GHB~#GGp3!G^1MJbr%lo)4`o zc_%nvPRltX1nccyRLGDVhDq}twP!iOEwD#^U`j(>W|X!^l(A2Bq}thVpjupbJb$tJs_GSbRy=NhT>;2vm1Jp_7P7}k!J11JV$6$a@ojwipW`qx8>vXJJ zJ?zdA<96Wd;j-7&y8wUZb`0vX<7W{%()c?7O2Z!-sp^ecl~$6a?0}R|mAP(@jFxjh zIhxOTBZ1C!Nb1X5dw}fW(aiP!kXA5QDScnJ7E8 zW{-~6^Pn2k&Fjj}2Ckjx{MvEXtEAXY>rYahfIyx>Hw5VZ;Rj7GOVwBeZnpy+Dv>P! zGjqds6s?W0{q=I8gany>eP?xNX%WZKX==PuvH9xy+WvMz8S6wDjx)_Zewge9Gq_0k zEAWR=HIJ|Z#=i8{dR{C6TMglt_Hv?R_Lr}FzoWzvzrxeTP*T{hrUn}X4n&;~;bm)n zhjTJA;7Z3(7NN6M_mgz4;=Ac5MkX47SN*K1*q|LqUH{umM_55_r&15}m{Drjev2>) zSD%5XQJ(QP3Kf{R!Uun#|9FREeI%^-Jz|lJy~g+~DJU z@}jhnz%n*4U3{jH#O4aLo;oZ~;-*?!?e`q^m&_*lUsR@Vuugr{mlw7#;AMPBJq!28 zFJVD=aoQsXXU9xeE7pV7LVn#q{p!VZ3%Y7}jE47Oc_kZjN{$2I_Ih`Hid_gb!z77k zLEPp?R;<|(jHShvV>3q;6{-VZbkCCwhse5}9x5_xyKM(xnjv^V-XBsASA(EHumh^r zu4uRPY+C7=BU8QW{OGSZAfm^B!Ait0-jY>*sG>$R-+;7@n-8id2AU2mHkJf0=Ox7L z3wA>N`?)k>o~;OBOg*l9-c&2Ax>sd#(g1YY--PWe-tT@R^ihOGFOUaF!s{7t|8@Ch z_a_pXzZ3hE9!TK$1W#azp-gEOQ-WuU#0`utpn2;A8trA^l6q$YQF51^@s+gh=n(ox zoxo50I#y^dUD+qqZWwdRChW+6_RmN-hX4{Bk=n^oC1Z8WWcqd|_FqA#1Txzjttspk z$qnVX*9wL95^mN zFaghCQlK}=ONlTTi^uzFqhx1MtD@5q52vJ+NFxQ!u7FgleEERVM{9Q0KxyV+k(#!U zjP{AHSQz$~(Idp)Q>buZc_HZTh*;6r2LVj?1C+I;u46gWXMuJCdyY<=&+h zm4(^0&>UeXB@WOkTUHnuLdRJ}V^~#YwH&^#l%E<;i*sXUO>N1{m4ma@FJx=_#Nw;< z>DuvrnXPe9bTKX@WWBobWN|7oK=)Lm*uH{jQz)jjk}-j>shi7zn|@FwV-hX@U0v25h!EE-T`2>;fbnoybY~s9BLR+`KF%Q zDzbQ>Qv(mtg1L{<#PeylU~f84G=c~OVgw9kph^bB%mbG$j0Gi*<7%^`biLCi$6A3Ua2o<@&WZB%x_Qab`4f8RYu2zo&RGMRxDj1!RG($dfM3s(BZguTy zLQ~Oa_37Ex6x&lHa@^$nGLNS@^H2-MXqXBgn+7g$+NPHtFwcLI4Xtep*>ku19Ga^p zp#I$0_;mELs}quj#0<%t{k44%{7sS|V3?G1-3ZXqJ$R|-W>adjIc-=-Eg~5@2km53 z@Xnl(UkDbZjcc2EDxRKDmzlg3g;+`NXn<32Cs&Gr8M9>iNKNBkYED;3NV$c>%@2(7 zGuZSz;-4HW^C9IKoKie9{tDcJelMU3LgIin!vgno;{>zF^|F}Zn0+;$q2u1o;iwNQ z*ah^oyIql#CiRE(k02Ch-UkgWPBjjbKsFW>pRn$MumX$j zqFLTNU8r{i;*{D$hD+hOUa3_r7*l8 zv!m^zk9RI`jl^J^vt>t_yJad>q#1C=@BvNJ3MPiI931*tyGN(dfE8@a@$)+PFz%6ktHtd^7EFEspL&_D^Xzo&X6_DQ78wf zz1psXF}CZ($`6(2F%C09Pw5W0$pQWGyoi+#B$=AsBzZ;_@JF(*yWu_ba8?#NS)qv3 zq)8|X$tO8<*Cm-6pLzt=@HH~~Whyl@SnX7DTU)W*f~rdggk(W%Z<}b!YT6ltALyJV z&W{eSCYIj#IUky_2kCU`3+UF0CXWJ{R8hft0T~UY^%aGF@Oo1BC3Im`#{kkc7=7sS z8CyJwKM+!`5Ng(Bjw7C=YqBjR4pZ2q^G&dX1t1Bk9B9@gNUD)hE_4oC1LkMMj*Bml z!1|Cs$=oA49A5dB(J*y(pS)A`;qu&G&y}CmAx;G$aS6rh0|Wz#;j$XWiYE!A`t z-nl(heIYdB4%$A?#G8lH%12=MhxWT30nM>+I;h~}7?yr1=LE_C8i57|Wo6{sNQ^>; z76_DvAknlKbXXCYyWKW}OVJIAO$mR9f1kA z`gr)*`~ttfA25CqYm&2*ElP{2i^7qjnqohhLcekYd2ZllD!}7e;-T;lQF}5|iT6py z$l_@r6W(PRz>DAk+cMkZ60X498M-8S!#MJ%S_YjdN(}{_^tcey;R#>;6?L~{leV>u zPbWCJT!zM&*IJeiG+#{cHEvY+ z+Lzy+60#``hEJ4SM{BO+Om>~)RW=p6jE0QoZkC2X1^f$hGAhP8_=LV(#|^Z~1k`J`5Y4{&kph&!7&$xsda&#_|163LJY#sev-!dySjv~soVP|ZwnwS8hqE7eW=?jZIr zi|q0V2R4CbUK!WWlN?7FFNm=IV8vl((EGk<62$xUXcUio))$cnA|RzW;>9U(Bnp6*3SvPm@L)RUplH%j@jDW74248VZ*?j*TrNov+S$c>Dg~fOE1Sik8ABjAeJthLGdbJHnAQl>~+P~ z#8EO}Y7Or4mzgHx>OH=BF}4#ZoI}bJDIC?5J}a%Y(U;mvo%ZW1r2&8f2;ee-6!*6Q zFsae|^`2GCb)p)TzZ{-!^I1Vp@Gyr_M=`Yr)@w?iR~9Kw1~6sAY<}DOF4BFc>oH<+*sWy5S1`mn zF_U-HR381t#PQ`v5doZKTAbNU&Q!FVsUhGIj1!oSU@eSlp5BJPTk$s@L7bUstn`sLU5{#Kyg$T}jmaPaIaQUY)z>ik7Gtj+=Nj;AU=gg&6F~`6+*>>bh zaKRIBVV{_t+a0vt?L;AJae1#NN3)b4T4J^{&oTSdK$>TA&jL2srV0Bw&K~20G=K|j zcmh{_ur7h{M7$gy0P9R^qHnt{2bc55gi`-njR>CF3==d!!^0k-~D{^(9K>;EN-H(QO zcZVNtB+4?UGKW*dGw=#54>WJ8zmpFY%WPBA)rS~ zPf*sTprcOzJg7evUSu! zamXo{%o5}g-xEvC$qkF|h4Yc;6zl5`G@*CeNRuDYY_Il}tj5jasMb`Qx$ZH!@Y3k6 z+vHg^XC|{@Ma$u!yS5RwTtFrB_OZi>IH14e>hHj(Hr+h7{XhjbX zmagNjzDdLH2|so87G^T9=ht^OPok%n@-B7JZd+EBohHA~h|rvTnJWJ-cH5wU9a3e0 zvh1;5>}1vXA)efRhiI*5y=m#|(c|RZ5MCv^G^Vm~bPhcT-P#6llM1*B)Q=|}n#G%- z`-^P3y#>dghcZ-yeS&?^yJeObqdBxnZ6z*>=yfI!cY~2T5*cEWyWcUED2Q2p@DKoz z^OkzZ20>xZGW_|beg{&(M*r^H<#dy|iqOg^qS$Jzp;gQ?*iK&xyqwoSNqVV9;-wY>Bspr8Ti;34;h$o4MC1^b+y{g*55ZzjeWc6f)u8Ng9YEkK>jNC-{Gs}VJgcq(_Z-0ggT3-5t0G)sPE93~qXib;- z5LBi{NKsUJY%s)ymtC2A6uR|VkQQsmlZ8kUrOP}~K7(I=^oSkGxQw1GjA0^MV%;%L z0MBEeSY!ch`*juR$+7!jxlX!YaQFf2)qaVx6X=@~yOIY|;Q7Tu&urcxOemAGWQ(_% z&%;!GQtn8uG%}mcAx~*me%RC!O0xY2>NJ^*f>P#Kp-eBx45d;fTDndGZeXa&yJQ*0 za^P$+D(OSmdXmuwlJN$mZO$v0QWU^gG(CY-0dir%z;;(1zsS?Q1AKQj86wg$o7 ztaYCK?g)FeF_ehxGfp3bBUXIuApba`PhLixgH}sI7BA?5T!650fhsDPJussQVzT~L zP5z4y@!x}?g|=E(0Tcw}790dbGQ|XgAO(pKDn<8@0#K@EpoAuZF5va2QMp}pDk7RR zQo~vV)0?F%tU^IPdpV&b?6r{KV$U;U+A#_+^7mH^Q|6no{|gb${o(8lWT=GQf!OKn z7SHRJpQ4oz;O`yEFG^0h1{E6PX?mV5jwt~=Im%x9VoS4;QCgDzQhy8wG}fsV1JO1V zcM6lDQh@)v|NL%>uhf-KE=_w#{GDgG=1DGP^8y_P>Ioics)A5zUA;TspE3o<7$qF=&{j!*nQi@J1H*qy&fRj5}9W1>v(;&Vb7tAwk0(9 zX1sh-ItRzL-7*><-FadFS0C!q8K!i%5?|hQ67tW-8Q|}R+f@|t;Ic$CbWHI!seIY3 zIe^OgvEl}gt)2MvJ z;gtLYk>PVo4kG_^Iw>~XrqR+p-OR`089eK{vweJqASd7@vpFlX(jNH;^z~{Ws{A6+fmmO=-OL;THV; zus@QT@>O?g;0>5_oN7s6A7PvE~9pb-ae#N05e%sWJJtWYNI&ELSq4mldQ2=9# z`vU(jc>Y(av-6N3Ae1N|AOimb-s~ZM${Za5pr%El7L$$7&vy&yFYxq@%bWY6mo25l0o3OGDC2c!%j@--0`U3x+zz69A0F$wMN$02 zORhsol7=%CP5jV;jLF3iwdX9hOGcD6I_cCYPwEqhIezA^T%Q<77F`*0GiNr`~`L^B*Mo>e6ZO63)@J@Fqo>rU@%4g zBQ>m?f}iZCwpg7>R&Sj{rVPv+iupA-bbx1enWI+;``7|Oa603ZVjH;wL(-z&0Znn~ z5H9}mw0MTe1(!`*@n#Iwq7e=93k5VifES@sNo*bC9=`!3ii(saI8k~MU(3w{W)7{j zUX%$8JUix+_eX&S!K$iFTT_!=GiOa}i2>Qlq6IhOcG@ehjGEgLCyOEfv2W?$yv1pA zIb$!pW<8rs;3lQ>&p@Cd-A&~|d{)*yLI7wXBAv);-Uzk8`9NG(Ky@37L}C>qfUd6e zgMD-F76jWB3f@)Y8FvYnC7_nl=kLP-EIK8{+(i0@Bh^x9*Ey`dUcv1SFbl|8Wbv+X z+>Dkf5qZzB{ae|1+de+rvRmLoGeaFkTUW>|t2w31FZASyo~G8RV~8!DIzpA#uX0+B zXHtKPVE(#Qq>@_9kejW*=R5@qa7|1{-a~8>5rzd3_~-AbzRQ(`p<%kc!Q>RHp{|e4 z>=bO>kc~5O#H+3iU!9SYvvKvKb2bkFx_(qz&lP%RPW6rF=4zWu)Z>aAEaQj;Y>~C* zd`Ky5dZEUEtA5d*WDQDWo^GBzYRzxlwa^Miq`Dkc_xcY5)mpuSg>3PXOZ9jr@1l63yCA+^HtdWt8pJ@|jO!LFGFVy}u}e z`9~i8`sn_Hh=0)wWZv|J88rD}5%(K@m0GQ%LFkt2%%nt~pa*fxR4_oZ&z6)y*p{zV zRUn*J)hw+z%(U9$zKy`?{&d8xow>zdcD6xKtAXOU=+D5)B){w~17M;fWPpO18Wz$F zPpfrhxkK^mad29hK&^B(9#oyT-bQm*N)ngJ+l_Z0NGuDw{ zp-TM`@@k|JAodN{0HDOHmUqiSZjMZv*}sq(&f21cTnsw7^9vEr-tqJd5DV08SVD{1 zDi$GWtahLiXqnw(&tZ%5tDgmLru-2(yb4vjZ(qv5W3bNpeGw|#&y9OFCXZ9)J-kpE zU7p*%^z+d(+ha%34Ov~uopAsIdP(*$g;)#4oa*b1rnr}r77$-V?h9Y~C56Hp(qw%F zJ-9GRmRO`9g&Z|YW&CcEAca>8NAkmzX>yoQJ$j8rsV5k>5eX~uOPh3OcqOcP@HE!W znPD$aTWvp2dkyt=_;I>RMQkU?8!MSxIJ-YV*9F<(K+HWl zfgi3a;9LjJw*hu7#j*MvUvvTj?%W@Y7tDdn`!|@JbUr(@HCM^e?U%fAWYDIa&pXU9bBOn4OH)GDN@ z!C859;_}Q9pQ>Btil0}X`c44zc{qF2d0_zX_hEycusnBiKQCvX`r0HMy7gwSAF$ZS zf4Z#M1i(MwK8bchM%z_W2mBH^kcy2gXpsAiRk?@jO%5D#x#tT+1?*|L3_fb5`ZvWq zwB;P=M;{(_5>Bem&Y=Y(Z8m_}xu_*Vz#+%y9Z{{#P^mEPr}wM4p+l^Ba! z^ZK?EMLCCHGQ9UQ=|*cl&?WM3mGivfZtrv-tEkKkF~T?3@IW)kyU>5Lj(oVUsPtcx z_4F_A`2Q#Cc#iM@d1($xOUmeDf4%UwS21vCBNODsH^7<@l1M6GW+SkvvW=Msw6IpE zvu`k+_=@i1oSv56L{YwJaQt!9grhmvmP9@*uZn_1YHeMI>_XmPyjwHu}yYeQF zQ_0X$d+18Ra;isQFq1C8Dugvb=j^7A;-)T z8Kw>?m8MpJmwyhH10(K;hEnpTs$(9>q=neA*AeB=PclT})o$W0;XjvwlPGlY>qu$5 z%)3zAuD1jy#z8G)yz+!myes)LwIeKJcV+cauP-!z^ibZFRWn$Jj$HJypESxTxMs%E ze>(K3yoRkWh{Z1(r;RdLwaI*MJ@*htv`fr3Y+B?*Tk zPDkcp8W}1Y(Fcpzh&?}(5E+Ov{KJUC0zOyyw!#U|cpQBM6$~RJmDIz_zt>A?e1Af~ z|6Cl#{$l=BDx%hbDN2}Z!EU`yxISBGo=t!u;mK*g=+u*3cL+3ENWIM}%?^ecw&te5 zW_gC7GXcN&qcMoFNQF+E_xAt!FLiJ^!K!~m5C0?j|8;M>92CSQE(aatshs+g6eTnY z+j75!X?mS$FeESvi6JCto$$s|$T=AR!@b<75zp6Sfx(qnco*g)2L$0em0$*S%hbZ z`hR{Vo>@$__3*(XJr3L%zu&`(nXgo;G|8N=TXR&Gd5=~jJiw>ohjP*CYcIY4@=&rE z#Xct5tax4~5wZGoHx3C$T0J&7M{Gm8>ts5@f6=@3W}O+RDSWrtCR6kTzz-?+Jw^AQ zghRGphBr~sclWV>=aNiI7*K9ul%#XN0L_Sy$>YiW`mqe0N2Qjo%HtZJGoAims7@)$ zVV`7E#JR7X+f-JNM5O|kGMDB732L~GrrHBNKs{~ch6)pyDR{TwteT!X`9@2aHM;hy zz)X{d485vt%S>Lv)4<+}VBK;W9_yDArFAvn1fa4uq#NFBz%4(=Va{dR6{#y12G{=r zw|<4N=N`QNPIBsV%3PzXvTM0=e~VduZDwX>o`Fzcv^N#4``PH`*2NCcyi@AwT4&G9 zm|QqlDoM1640-GiR+*aX{SbyyNP-J8gwrG&2ECNMNaZ=;{(?ag;EJ`c^sO_m6WvU& z&KW{JWfJLc6TN_=I|p{1w+xMP3IYFTI>ua1UA^EfWIRHwk9uU_fq;KOET5Y30Cfb1 zk?ipC>Sui%?L`3!WtAX6cY{lOm!ucULQR)dG;3^!tTW=R%&CfK(}|8lW8zmCve^`iz7gS6@&q+I{Bt&^)2la;H9xqXTQ2Fm}r=k9Vqrd)7KLHr%9Fp6vDyI_5UvX;1dCZ4Zv>} z$ryCl=d0hZ1NyKUXwe#Ps)wBY*-M@Z=iYd)UZvQHuDZ1>wM;%h{+pgbM z)wWWm6In6A*7gjrvMBF64|94eJB^eNp6T@<>=JdtS@E8V!;aO+YJd^DfZO#Nj2wE6RN-CJ?_k8a;F8f z02oeQBD8u)&aFG<5~D*;8i7#oOmpg9UV#=Hc*jdM$QC3g*sfMlW@m?O*WxO5{6cd3 zX`ejZ3ysbJ4C^osr=4^_<}DyInJB!z@Tf3ms3<=>a}YcWQyM(IagxaqV5^+3PRm0S zETO@Ck9QOso5yG%6F3H6>UM8A{s|Z|+TQZKdP_YYw=42PI*Tz6EO+ZmT3cr0cyVA^y%#9?eYNQ2o-rbVekn1#E|tto40;x zKcvM&tt1g8<&8v4kVLh!d^QxbXF|0dDGpU)vO-C0#it~lciKZ0=teFhq38x5LHsW3 zmVFmKm-vu)H3_ccBrwtdF@;CkT(u*-lG9TC+)?U`%n}V%SHy4%WbPm557IYD&Mb8X(*P4x^A(SGZECio_ z*s4!Y947&NIu%xz8-5lJC+fEw@NF3@KZF}VwjNyT!HaQhw&u6R177I=cCNcov*|zL z4sKxdF&uJN0--#AC2sH_I?UBZ^j&k(?JP9jNu0gIORjh@^dCeLH$b;*K7N*MJdO03 zWg(1l!uXMI1#Dbp-GNQb85mVg|Kuo&%$_~6i#QO^jCanlgwna0MXz!njj2i_|HJs} z_=PkI8Q(iln)~HJ3Lw0pE`T1Vr8Mlqf1NhU=NF+#M(tAP-M(s9~Q+LW5xZ)iOJ z1(#je@5p6<(pG|a2{2uPbr}1k+3|h7!c&*6_haZcaoBWik=N?>@fi;aP7S7@xAUHE z*hn#x0M}eWpyz53`!jsehk_=6+;mtHtYVJ6*#Bs${WS;Y4k*=@q6a2jE}Ldvd@0RS zxX`!b5Q@(M9e0b9np0*xXq zOmUzs5|0}@2Q>f4|3$1sI>jOXD0tKvk4p3lRY@W&oln6`bg?^p6J>&7izET9lOlGX zab=n`!tbc^C|HpyPT>Uu^0LO)H)a$kVN8djN0gI8?-Sf1KJfI+?yp3OdW5L%Xo^b` zM-xA0ssWRA8Cb_r!LI=Mg}x9d6v2pyq`XmuCbQIADUu&UM+(y3T?u70KO-A&|4XT{ zLZAkCO1+p6VAp9;8U0(41|7~VXmgnd1BDA4Z>1L}mJ(G#e%vx-V`ztQzJc+0b<0!o zFO`x1!Z6fdkiXQ2oeVkK#3I=(r&9fodAGTn-`|gqSV3Sd4(2M&Nn#8MW1JV>rY2*e zp^1L`GEBZQfJHdqpb+Nd(mlJ4WVxXMC9@+r12TU!qw#5sgwj-wc}Q4jdCPPT{ETF?@Uj>Nt8%IAvk(o0faQv<++d z^?{2ephHKDBrzhm2lOkIhqLVJ^fhW2TD{@?xA_z1IGCgR-Mf!ATb5BBTW z<>EuEG9#_MtNM2?NFkdi`!x|invBmdf}BIi01*t0GdJHs_i+SZoI-BAG8E|ROq3vP z)j<=o%JEUO_Grn7S~%HV8Wa8z@6Wh1y7J9Q!l>En-QgU_Xmy8*^8Q#kxl~)->TA(v zef4ykvNXkEO(it9N^k|u9A#!R=ozZMO&PvT-a!#AIvk@yg9>dq<99g@HJO}R_J^FC zBn${l$A3ZpONaA}Hp2G5WVV9>0TKG2WM-Dsf=RQmWE$xFjS!((M_MX8>^?*%zX2k@Xy$a~*t`>n;%zt)IZVEq<~ z$RxOMPxD>j_Q8hmw|rme{S85It?&?zz~@bM$b^9G{?s3TV8Q=tjAaFXEeu^N=8ZyX z40~c_xY(@6`|CihpJU|>Ln1%kpy&^U(F}GKPNAjbhXuMv5@>(yYKiigyZ>OGMJ%P6 zN9rD0KLEWk!=(zRo}03Q@+Ww1$x(hyc9g7A%x$VaKU2#3UIk@}$Fg)IW%)%Wof>;q z)dV}iqeWM|E{}rB?0kv%n5nObtjBU?8ZOOJiT;=?#hpXeQ3kB91nr7!no-pXBb$a> z7i04gJV$ozM6Q2LI&Ob%<%B**Zh2eH^OS$-D*&{gUcDd7rb%0h4Ppuv|5*CM8+@|H z5~qGbwVz(ilVPn-I!lIP%bdt88T^TJug8iaNclGU|UAFJt|9q z96;UBx%57ZCC@F?B!Ie&(}=YOZsx+anhH%RudwPi=BCupCc^yN;saDfMU0y8boIs7 zpk`aQh{3}FhRt$rl*0xyw$*YLcH|(c?8af)PKtR^_J`a|oAvZ`_L{lbdYNPFr*2X%M5x^>k$K`6R_9iuS%>}$6YR!#e*x(9F^Y)fT zFJ8NQ5QCBlJJ?pKkf;nIXHUd&=BF(MGOOXAI9`0fqW_X z;!=^x<^JJaZOxT6?Q(J8R_XS*_D(i!;4!rv3WyX(?eL!^JdCE1GIXA;nG^FHq?vlj zk{WZ5s?kVJd_$`1_cg{ZiIR$V=z!DI12(eSSO-FRfl%V?SoULOtY-@HdHbTJ2|SON zSp-@bvu$}3baxB7TUSy?$P3Kk6b}utoD7@wj_IJYb6LpnoG}AYeTX|~Si6l`^agE? zPUQyM^{XM?;R!Gr(MV@dYC|j>=}a4nQ1H(1dPf-DnNK@BNBHh2obBYi34l?apkiBj zQ3xy+A}Y!pcrGQI2#}4{3KJemmHleLygC|QHAH2zN-TxjXuigz$H+A2C3G?ygw13v>_}Q)=jIGy(J;k;GZ)u$c9OXKm!Zk4L{=it zOtz-}!cADTgcd@Ua}TknHh?>i=Ah>2U!GV}D;)Qje1rwu#P2Z_|vpx0h50+0zWP@{TNcP;s0?A5KD4E$zWB(1)gq8MCVzJTr2npH)Wk9bQYzkJ0{|s zfSgN(g&S=+JF@WcLr9q_Raf|}Xg&C?AUuSv8p+*(Yw?O;hFO?VzK%Fb24G9H&7NO} zk}^N~6=L#03rmRt;CE-Jdj+sveP_3Vq$BS;uyy=h{ocMJ=^Ot%dEH;=h@gb8IW-IB*TzqHV`{AfTZAvjsWQMAAOx zrK8>Xt0X!Oi*?q+V4B^hE@UY}2NQvxD%I{*c_t6IMd3vi=ib29v~BMJnxMlYzrT@y zE!Ic%YM!YIz>0zJLuX|pr;SGF2?a2lx9c+nk@y`MiuEzQTDukma~(qgw+cq`LG8o{ zmG@7w2nz@&B6;zCAiNjq+mDAnAirig5-cQOOWYrrju?**(TNszhb!$iEKz`Z;n+LWu zM3sRu6IuFr$w7e;h6QO->}chMx_INTlVMSY5e5SOMoge~?tSG;Q&%lpRUfPI_0Zap zi`WZ*PJ%Ms-q8R3q;BeBFx79QY`MbqGQCMvEI*Oze3`^7isChyBns#+IESY?9A&sT z6y^2m)n>f92FQbl3RAk1EMViOCwMX^aul=@+Je9^I`v`2ZWlVuCYzn}(n4CvyE+on+*XzbWTn({Mq&|Lh!8xIr6BWqd4Y`+e(;ED! z8}OY%YYdEKpz)y7h4TdWYpcv~rcd%u#YpQ&4aHmW`#!ia=FXQ$k<}R8A9V=i7a-r@I|I}1Cc2k z$Hr64_0FCw9RBM@Yp*q6;_q^1fy4P z(bpznR@&%Kclg7aE87k#9EDJzM=(NYXL?PS6m%!s!P8 zt=)MxPIKMf7}{!W6SJd~s_shuy$C;q9?PW)AF(x#TrcHdIgSkro4 zahz;Q+4qLXxHZRNVdh4*uK=JD{PrYdb?~euzuzcniLv0(g_gGwGYE^SvMQq(|5*~a zM``!z@O|HDALpbIFaZACba;zWvX7U2?e%Vl;>vU2y79w%@?+mY5M-Ba+-LBhC$x5! zFcS>veT<7Aqj-Lc%i2_M#QP&@Z40Tl^UCJviNwemWb{X@_1W0?NfRtjkV@Qf z0QDZ+AlluNNsDoNPn~3VNdI7_u9L;D&6vjSB*~}X_~?M1gFOf zyGLns1g)gx_sIJxX9|0&nusXS)pfO3V_YTlcVb{ylxhIaP@laOTXBOyLN<&V z0}8fXRSSA4TB+swnqR~xi?rXWo)~KvS)?9PCHbg2E8Y(ISA5?Gg7jsK$#r$jeMn0Y zi*hLEt4TBVTVD2-7EFru>rN7p(dASs126pY#;EcVXcrBLbS{FM&(Nk|ZHJ&wKXJ57 z$(D@K%pBMVM==5Xad7u*>(NGsq&;$zuMG$V#Smi)v}DGU-YpX}))}Vm(lors^7a{& zVHRkf(o{u@;f$T2SW^m-6NbabD&K*Se8)Ub<5L~#JHuQ@V)`_IUmOoObtyuJzC1uY zH`mN`+83e`>x<(dBxj+`Zf2Z+YoYi8u_~*%k~8prXrVh``3XKSVW@?^J@^79zF=4l5r1YsRur~&`VroB>cy&XzE=IajU9avpDm28 zj?_Fcl8^d85er3&g)_fVA~K`RE_bu$?gYe=Bb7^&urdPA|y#{y*qP-Bnd!Gf@yZk>oc?|SUZ1E4fJcD>O|q7 za>m?fsDnGse3uJ6-GJS`hbSXZY5s#`Mw*4V53xznIp@qb*zj3J_g=+I`L|{AQdrWAXd}y3 zXs4q$<%((|qq6JC8WPVXH5ta?+pl4KsQVHAN)6gY$o+7}48I;a3O+6xm>PS9{0z4u z8s^ywr(LFNWFp&5?uF9bmsRuz_4(0@bP713{r52%w8v15Dkt5wKP@i(HDzT|ah~Rp z#xKnPWCRYw(Fju;{OQFsQ=QtL`3Mfo?$-ASjPO&R{ITCB`mOWi))ynZxa{?$HgoUn zrIFU1ea@i{sa&Bw8;8;@I0?Jc+&z0y>hOk>9VBK1CRdIG zzr2tP`Yw)=jVb&)7os6i>9}tF$P7SKXg2JsxuNruT+gWTYzo#rmv^2Ha$@;C-NUJA z`c@2=Hm^^`{iAn^&S`6t(}Cj-mO&i*a8)zq2N#G9Y5n#CFdwhw-*qGxZZ zNnM(8zlmYGE%88jxU7}B9R>4}Pb%bmOYjSKHY&Il~N#SFlVf}YJQ zEPU+9AOPD9{rANMT9aCS!066cpoLI24l5oWf6Sy&aJ}G;prH5R4ct54 zv;}C%13Kdhn%DLscVV*2`d8L}HwNH#CotTsmd~xeqwHd>;uu#x?lu{^uA_34rE%FR zynUIf6dY*pz}Pb`BjB_o0*+*i7sCp{#4z!^di6|YLhID}TojNXwggC0aI1~*8j1U= zu+dz3_z{LnOTRAH&r7LMCOm9*eq1SSI_Ia!k!t7D50ntNBN;s)+o2?CR{kp>@Csx1 zQ)vMxbl_TN5GTYkC1@275IK5J_VMHPfHhk%*`_tDi*I<4-lmOEZJ#7L)$B~Os(fJZ ziLf5qYiEontFR1G6a>Up8vXJ^m(XNqBQM8%yT5%yI<>5`tVdMrZ?Ma18!WMXUbM(oKC z;dZB286@@4LBTktO`7{TPx=n60%s?MqGVF3J!YkkRp5-(oFLp-Fef-GIMA1Kz-ZE+ z^2PWfK$zE)*Ad%4*4&@_g>ls{GC{UsH1VBtRsV2w*TUz5a9(c#AUM}VqcOZc{t{}Q z)l))30Q)YS{P-uKsQ!(IC{ylj@l$@CBLKqH_0*Px(ZAC%QDr+I)X|44h>=_GVQDL< z4_ZUmo>_k~$>~g*W-pu59pngseFrfKRv?X^Ros44k2M#HuFPge2y~ym1e`8@zrDZX z1+it${6rbTxf+Q4u{P`iM#ahuniH>J0GIE^&45qp9n{#r-B^*?(iTG^2_GN|*gYBPo&T~Vlmu#} z*|gG|0m(Xlf9)vPgRI#p;iaZG3%9(OdnP7<3dU73W$IDw?eD<2KgJ zgs$dS;DxRo#X3Co78@wp8O1S^s%D;SGmJHnA*{?c`?z&>9W-!U%;UfK;Q&jx83Jb3 zb3lHt80xjzvpFLl&juOp9VuGlG$B>*4XVP8auhtDuO8 zkdxIMcVp72m|D}oJ`=-EkpdQN+6j_vQy9uRIr%4Vuhim#wc9F~vFf6&qsKVtbT8G) zx$(=4bjY4EAeZb!t&n>8lVi<`|G-><8Q?Y)%$A97go3&2ZX%vZ5KUO(ivu{k5hYD8 zz1rs+;`5oLXEx5CwAg1$w>~km1qa@4`lu4rlUw7+t%=~_RqG0~uK-`%;1Ngr!x_&g z@D45*CkRQ4ie@*I(+Iil*Cz_*oXmT_874~CT5Aw@rquZ|{(`3OhTiU%FWrJ(XI|Icw^M z(FAMEe#t9+)LvXHG-_UOG=WC&Y0>+|{%_lO{hyx|`S-&Cq7>rGf7`|yyJ~nE=--Z< zIpG#)s?yZxy26{dpcEQ(ur_vj#JIS!6zJmBvlN{On~dEZ8^V8qf^W+ieP=04SVp{L zq8?=dOIhD!-@Xetc?&L*0q^L4>Q`fa2m6*Z6}RwJ85h* zww-*jZQE93+qTWdR&%;9&c)vUVLi`WbBr0WJ$0(TxqLxS^PB(X3S47h2m_CvjB zB7?Uy=zA>A7`#0RX!R2 z;o7Nr!cluI)=i!ozV4x|SQ56Da&V@1u$d0BagE$bBP#08#J&lWbU)&!rc7e3I~{2p zv>JsLOVU5L%K0_>gq*5Ae$T{uIB)?>`=$!3b6 zTBrT0a5kLQ{}wuon7oC4YIu}NA+T$WH1WB9m@J^_w9R9wH!9dFjqL{|-}QX`l~Cqh zn3l`wDa!&IM_uY*vogsvuKP^?d#mjpm=4Dc@jtCVC0q1*SB`!Yjhs9C?}@n`Bt1Fp zV*T}kFyfM_3%2|Uu2jB~*Q?mAgIp_l{N=_`YnkiB@F>4nE!Io3cK)#Tp1hpwR^E8& zT?YWh!J(*VRBJrQ#MaIz|88r^64~8Sf%j9(dW31rMA=;Cqxnz1x874+v$66THzFs? z!>mmj$Zc>4#u}6J=kL*yd?vE@kl`P%9rj6onBH0hFL0v6AGkHz0fhXAUYw?;=8zjO z^d-4w1n#wK>L)1HeTl&vRN_xr_q^N)2}U5M@`63zK0QO~5NWEMsa;7=N$n)3-j=$*Wn9dn+^T7noK(ucN@W9% z47Md5UMq809N9y}eC0a>Qbri^=ec`jhgpjp1}K*=;i2ZRh78$@XK2@j9-?26bFbfh z@asnq(O!^{o6ec_1i{t-BvJ{?!ebL+_4Fhe>?3E%7gxBrt9P`#0#IO-(?Y&j{5p?zJ- zoyysAuntO>Ym}of{o_W6edLMd73CSc8TRBgfo^1GKkPqlyF2|l6F6ky&M27V3#Ts@2vRIH*{iygOb~`f|oexMToOL4dkot;ZCLlfShXg?hY3*`P zTPqH5L{fWfRTDiz{0lCUolF#xtkXAcM2ktfHj6s;R%@uDQE#%2H2!*o^r=V~dxjJ1 z*vlm3mzr}qwm%(ZJYWoF$kB!uSiyQpxu?wIMjE1nUQT&lbxnl>89fa6JIuk?p70+P z2a>f0k(R0`6gy|9hk8(GZh+=nqjC41XK@MNgbS8@$^1~qzE!+aQSJtzD1j0Bk(-$| zIr8diKlRD6&y3?Zcm&d@o7{?N805=PMbXQz`|ck-X(-7=>iD_LI;WHRBk&Snp1-|3 z*rJ%TI6{JcYq$S+T?WWqsw-Zc81u)EL(2|Qe zE*ENq>O|eRvg$TDIrS~W6eq@WWJy@}de}C{sV=?BxxQjmts0_MjZPrh&%mFq+Db0j z*{`b?#d`s44Rzg7b12!*45f?JVHY3XgBpKIG8)Eh@9}$9YVy|DB1;jQpZ`>%?2%u` zo@dR7o}5LTW!8rFk;w@8hSLEJ#ygD5dMC(k4{A4urO9-M_Op%TXtJ zULnG0+8z1?5+54IVAqFLQOMJ0QAYYi`rYaUf=?M3=rOV;)aXQK=exsgN0BHYB&p}+ z{W(IbecGka*X=1FDGA{f(M{ERjkb^a=EqxXH_MVWM5r;8+Zxzouy3bwqYx(>0;(s* zxJ^-slyA3(pMbR%MJkp+QnW0|Cif+g#}`^&X!ib0=#DqIrx@rj#SBf|%`BpA@P5zH z8g0(csXG5dH4tJRx1cRVzR>=Rks$x(?T1hO*ZpJPMb zKvq;rmqeaa;-vxGL|5#bA5=U$i^A0>m`4xeb!P4Sbk>wj%`(~TYJTzextmh6Az11p z^E%V}*5^6L>#FS}=RViz>bL&aloKP$9L--P>Lp+fa6c6|>)}29Y%%vOpZ#(l6(e*% zb$Clo^_A#I(ZJque1c6pR9G~+y#=BW<@0c__ zx(vWc^}G8i0>8rE{m?V$93Ar1&pEpL+04$(fu&AiRyNp`3Z0YuC7o-M+uDG@mVm^Gfm67L>0tdcME^L5M z9;aNzjLZbb!1&JJd3U$HiOXnkax~9&ScvZWdV6uJvD#~8`Dt6Rt`yfg+v~x{^Os62 z0!PTCF&X>jq{=czY_Tk#sqIpsg*k@VUGtOO>g;w0E!yVx^q>%w5*yRh`sRj{s+|{A zQ)M++1AhOn*_!Ioj*hNsM4mtAaIV1b=ZELZb68hbNRi7lO~U^DBXrrn+fObRk<35Z z3UBue9b$sBZx8Jc?0+IkL=S&T@x}j0h|YFI$)Lee_5jU5^sQ?RWrBlNO2JOS3IWRNUR~Uz;ewb>#+%A(%H) z#f*>}gUf$=h7{&RH=%2%XW87=5vxQGMqNFe+LEr7UdQ0{&)o{~wW}(K53W*hPsKxj zcb%4P_K&!SJgE1n6E@F~N>M+__H-=p7-Cg!0~t6J^4_Sv-V}}@Pk`rFAW`sEbvXNh z(+Tkc7ZdOcU)DHwSx45lTiFwEy=H=(IzB_&OKONKN4y&1rk2|a>R+LS$8yQu@}F6M z=a@Nt*nwy;Ydk=!h3@6O`zq_z)RHP|gGR!OfG3?VIcCGYiLvY}3bEOW3$PX#f^V$v z;V_?w9>nDkEeJ^}JKd|BC6ua)Lmy+XE}E2_OyR4vrzcwXHJFtQlcED^Mz64=(#4re zBnG-HT5O@I4>W&2w5fYf>KjuTj^$+H?#7Pes4$85vIQ523WC{t$(+TdR!d#gX z>-!e<5Cs^`etP%!OIM=fG2glrVR4w*`Rp9I(FixK(tP5TNORc#=_E7$4h-Y=y*W+k zl9@j`^J9(L$xtRBXiR~?`VT4cVnpoEu~W2nmxA3AGe{9FXooD*^SyXgoG8In2vd zwy_A~#_d(@k~Q>d9JC<_3tCBkm?z^obvlV+87<(&>a`2mpnQR;xJgaDAsh<0%7*M@ z15=@nR?4*+%0lEmHjY@@9pMBA8-haZ0@!R1586ZB0%iGLlhM&+$)dosGFzNaE}1O- zP3_>3l$6LZnkot+XMi_+;RSYZ%-$eFSyv@MVzwElzOJ>%z1m-QoR+fGk=2dY1pRZ~ zohG-Hfs2#G78D2!gia-=W$cVA&o}p+SZY3VsW=2t^ANsucAQ1JjnRrbvPJ5|*%H%N ze1VJ>80N5iF!7Wu^g5H$R+9M{nuFud%5>W_%yByfyHjvW+^u>LdvAjS1R(xf(0}H# z{v{(^eo=nN8P3J%nz=D!d&Be5D~}~ z46>pkz{LOCYFPjB5(-TtFD{Z{yJlG|oT*Va6{vwiTo3rR;sK<~^omr5wp?OsMEhAS?(=bMc_|KrgcSOILA8 zal2i)CmrS5n){rG?08?f=u$>bE)8nzRS zR-At7_(`6UW1gH6x&I;!gFBtPfoR=zgHE7E-#}R2iNMPO<^9rraRAwDXbvg1Xq==uFW(SZ8Z|vW8mc9X6 zWX&%j|2~>q!a_GRuh~-5CidJIch{5EuLZaYx!fq2H4^_^XYBC*Vf|F^ zZ4%GMQ&K&a%6$3C_cd^A5G84?@6Gt(W`X?cPZ~B)8#o>Ovgd44&nTU%@a;sN*pdy) zo_wCs9orQ_1f_(FQv{$U_WdhA%(mpdEC$}F-JkccRQnX^tp!C1#wQD7*5)C6^X12I z?j$Y%d!TR|3i-8_@I^2`+mqTI_9T<{hlqpg zmcF+9sQnF9#W4Wy*P*vK^G@h;Amf}EYoyx3=joEhp9c^=sxLrGg`vf44HY(NG)J+| z|F?U2U_kV$f4xSVN0tuQufwaVu{g&Bm6DqFM3r%*Zb*E@1)0OknrZfV29iRO0Y;K6h1VcKwT!0*Za171EDtI+fsc@_|X>g|s zNk=>k9ZiZ0E6-{Lz%bU&j#34iXzzv_W z2D_9C?6=D=)@M#tf14cpSP_CZZ%J}Xf0&xQpY15NS`vU$89J3k;ZakLWw|a+-q1Sf zNppMF#yOe1wDEPAbLJ@w6t{^&-U#_r;o65=9~Hwp-A@0E@GGYUMy)A2`cmpuC`d$*xH`Q(~S z)I#_{A-VTwlQ$upw&Un*STJ3R3SNO8*A%K2k*2wUtpq|}{&)nn0b`9yM^+?Z1=mk+ zO0_MZYB0qslkYW?8q|d4XFKz1B7EPGyaoaeW=>7tV37Vg8P7eR5q*+wfymh&iaDd^ zN^smWa}TmP({jw(bfT=O865K){6a@r$6BUd<&vX>eueAMk(u!?Mavj8$KykMSd*Dq zfD8K~Hh(7ZG~pb<<_I*)x@IPgFAbF0CNnd; z(AwglQw8@c1&g4g+(vo)r^eALl*>f&SI|6l^EuEwmGfJSL19sOkmpcAzGQXi+8D|* z{O+Wc_>+=gvg!>I{!pu(M$`%0DGK?7GHTj zQvM5soNUybecue#S5)q-U*Q?+5f8Y)E2RhP-d<;d%}&V27sTGyiLYMIM_Ih#lyo*G8-5Tx!Q7JQc&3id{kCsLB(^v-K>GYyTAh6-=qBd9_d;JZ> zf|;n9nCRSF-K@|Igh^RhKzyTmRfs!n(k~K%ND*t3YMS8BZm`-tNGyn;8y9eXYW!$3 zMqZPmvu~L%04^w9_lELDnm!!7{bRXy6mDjEY|V)+ZM&FI`{|I19X)vuda{{RWW{;u z)z$P=YlmS3&RI9);fj05mWjaGhjL{;JR~GT$G3DRSn5}=(gp7HEHqY# zUco3+)h4Z)IGp-hwoX*X7&WlPM#D_;p-Qswh{4%|nePeLof2(nfGsRpS@+jFDH~EH zKqfw?rT2RmbS5(RG(G2ewd8ug-byd%ec$cK17+N-U+=r}Lss6T1j>t(yFEC2vw2Iw z_6Ni#xo4LoD-fL1I~t!=9V^+f9}+IJu5enLUsz{PpDb(O6&l0@dJ2@1Kt9QW@J-{v zfJ+S}3LwCUT&l7%`BDvy^JvapD zziav5dg)nrpE`uWB6jd`6s<(S(66{zrF~Ap@p)5d-_=;V0v58xzu-S^X$nr+&V?D) zrR*dloi#@4=zqp6e!9&MM81h=aa6S51#7|hzeg<};xhTy+7Tt*a=$F?L`3lPE z5H1EvfO`Cmu-Y(5j{>RS&4gCgYomh#AQ?AxwrA{VM=5(SdRmGQ^{@XdSD81*w>!Ao zE^Iu#f9$gk8367-I&tF11y18ZLNXl87dg^F33_)NFZ86ZA1}T`Sgeh4zuZK0>;FEvO*+*?-w{r=VKv zy7I4~fa>CoovB-6hvrWs{@hNE>#m*8_rJc^mup|V4?p}|UPefo`uBPiQ&|kcp#H2B)??6YgN!qdayMyd(4{)tV2>`Tya0;=&-t@O8~@_9dy#jKm0ZU&?FpfQpZ56ReK>*O==^LBb3jF>gc#o7LY<_t-5SNGmbo;#^< z0hOu}01(w}@f87R7!)t5SyWgst|&oS#Nof0i7M1+($=*nr7*CZm4);ytB1u;_bn7)KJ5|?g(C%K>6`(zmZ?%^{mh2B?bZO%s^QyQxX+2dmPhU)yY0WbPh@r!f=_dzI7$TRK=V)q~n=*Jbhb1Z;Z^k}pL; zKq3kOk(E;kC3zM~D=V%nM{Y^chcv==$Jj}_i}rEcmIc@uiubpmdqeG@Q`yOvH5cxB zz3^ivLx7ys7zPW(-H1R47}XFSP@?!&?3%r_1vtF~2k7rJLBt-Y!}?CW0fAVCK#4L7 zYv>vbfaWm4FCCE6Ye)Ve-*ydPG*7GdYk?XF8T#5@o`qrrGLmFj_(1N!tfB;7_4`@D*F!R7SYcyAU~V9b#XjE=5$ z#UzF>JWxE1bTbD z-*lGJM!zNQiL&BcMOAj91x@fRywj@hG2 zmB&N?8>X<41q^;r5qK?p|9!(x$$W6Af=xxL^h)Wn+^$-(?#icC?yce9!H7Za`z=b# z)fc%;dBskfHbX`X8gRWpcALR5nA>SUKNV^SdM292pk1e}FpZV4O zctIFCXlNo*(R!)pj?LUeLmAyYar<8S6oXODyF2uG+i*)K`xoy9Qn)ydQexLS^0|%g zLUse>W-lZw{h(j|{AGuV+ryjGUoWa_DGp3M+_jWU#{LxVL48?ZVuHrp1S0eAwOJEw z1l~EZrezdtl~J=4J!^!wguA+YE&H@~S-w8E4beMNS;c-SlHmRFq%0zdTM0)z&qCv9 z_Su$b53XnfD{{7um;S{+(3PN+@U|^rC{0 zryteC4KEJZAmTjm;Ej{IKp-W^;rZ=3l5H+9AQ#+O+|#=yKkG4R%nS*y3P3WkpyLMf zu!lw8mX<1P@MJ=;pi3`sW4wHuZ#4$R#how95rngW-hTL=B7ZQSGi*VZDHvCBM5$m1 zF_l`3O!AftmNR?)PV^c(aJ?aH^~I|8Sd-Jc+DTD0ojwa3Bfhc}46-uJ#Hr~Efy-Iw zNQqi3x`(RQzr=m9<{XKPUQ2a&5?S4{E;qH6&S03+A|~e!vw@q zZh0_Cp@#rq?^l=W#fom)@r25FtwLk>=LBI4Pd1aPoU4nkj}}^U?&^Jeb+dQ_5duG4 z*3fLz{E?tUb;wRfI(LQ^w^}2HT^CVowPAj51#S5D&+`jk{K%&g=Q%j-W9nbZ4yre;4{s(izp^_8u3ncj-&05|+T-Qp7?0}(k3(Z$P zV<^h|O_w)Z=~f{s{QifoEMb7`x>|h5R?seL&;y@}u5ZGYU)KXVk<`1?4u3yeK6l`! z)-5OGnTmnVrp)i(x$d#yUiNURMTiRFmYWe^WJh>7x?@MJ(XD6&&(q(3lBuj)_$s7r~F>yb<2`0!y$wYI-N6LbZfxQ%fR90m+Y)T>EyXtRccO$(u;y)?G zWg!cz?hVF|Gz3D!fmv8M5;~svg;%_g1ALLnL7u0T8Bbb!pO1640*7DU{@b6PJ5oCL z`WFqu{zoOC|9>h$B26h9U=6oy_W@EYOS(tP1zGHc5t_dX|k?eqS5gb{?CmmNt$KBO2txD$SYnf{b& z+~J?uOpad(FFtkPRpY+Ki2+|;E%G-JX49;f}=MDE2}}s>+49uOIu{@ zX`v!P%kfk;x|pJjS*tzL(eE|krh8Oj=+rXKCvm(d_StHq^{m}22Q%Q=+%w=%F_O#e zQu-QY=nKMJR8Er)*bs24IAp2ybozReiLTcesMW>cex`M z6@z6I7vtlgCMELB!W3I0;7oxWQ10{4JtMrC6}QVWF?L%^KX1yJlj&U2>L2i@GQrQolHhqp* z6Wce)ZKPo^(z@jLX@C~SeMJ1Pmk9~dzU9ZdoVZ&~2WY`~>!>aXP_m?RczA5hmz>Q8 zf6HLETIh2A8DWtzpTtTphq*9*m(WQD);O5XVFOB|7_X~@9Pfi%O+o{a(F9Hv)&P4I zLA4uz3%VbYH{|{0v@>a(&^f=nv!d^L?d8VxO!w8;naO*<14T$&5d2Xik9mV;5mB5@ zBNxuP0Km?I7jen!m0qY!v#{oz5&yj{kFE5mne~+S9q0GmaxRO|` z$sku2_ua8NSKZt@Lbi7CjMTdV-nVzgWxjU44aiY{Zxb?IhJG#`>;KK2Y+snWA_cS$ z%W=~mJmPR%G~taH+6S`Y7ITT5S|?P~`)<>bYO`)v+_DP*voqDqb-Jahogx{CXAda3 z<+qwRx%9Cor_S7&+|>u{(Hk!7M2jm9p}F)PXGs)A4yp3mt=b25(Q&UFxd$W#C@sbH4~!y6E2<-)^qezJl?^>>XzQ!xHscWi#=mg@adE8sVxNK{Lpu4^}x1GZ91rp#(>t=Brs9hOq2qH!~3wl!Kj=#`Zg z+K%NLDU62OEw%oLaxSY*u-5Q1JQzKxu_QEnc(WxkqFkRhpvW#{?uXZ8)C8>|*IT-h zPv#KNDlHUI)GzEH@1RExPJJ)Yw1vY}FFiR*B3QVp0gIe#4pZcxvl$rPWLtI40+u!i zq{s(&s@e9!R9Cib$rCT8(#qW{9SUddR}qL#w2@oA=t5vQY`)}5cXVbE!4B1bpLKtrBWKasWkkb>ukCNS0V7NwsdXoRD*a=bgYCz)8R zn+)Oh_G*>b&X?I8Jdd}LiWY!qG-%*M_xE(d;;*+ROLpYAHmsY7?p4#S02-AI(p!F^ zCzfuU54mGCU#dVIi|vuI;Dbt4@+CuW_^@60%L_WWv`$E`=N+A)VWF8R*hD=RS!Wri zE8R9X^K0xh$(4Y{xp5j~u!mHtMxZh|N7^*!wru}V;#_#ai594yBZw9lV09@?hIV^8 zvb0y`{cfDiFMVDw+_6s{4J@p+)x*#w9R?WwPPSGE^1{RQ;^~Kxeppj zkSDi)`5>LeDMSDvw^&2y>dm2t-83gJ*fajg3&PKtfdf8;N+&-N!;{y*&8}%0iYlAv z`cKn0yRC@PLsbx!+fak+La69{Ytk8pYO+&u-k+ z%x(qzE@TQJMJ*?w0{GmF@T_Vxu zShGX8L*T0oCfH}%&mm%1jwMMm?xNWJeXxMG!k;pqSRX^X&`!&ziICf%BVW#E zN_N=(%P?ax;B|zK!S#ZkMx@Axt;;rtj^&igb30F9&I*!GIu`rE>MdGGVKx!cCxC(N z^uRe>2&`!*ukz)d^Chi9Z_T+&NPRXLQdd0H>H{Ls4%o#-=nl7Ae!=i)TiV@taSgoQ z-B1ebMqI~)uIEAcOR@uj>_{#eXRfKO9^F5-%XpiLOzmjql!b*xM0>qgi}j(}y|G(+ zdxFp%+7sh3U>noVy1NnSE1&KIID|?bv@`7-jg45SlJl571 z)0zxF4D7oiq1W1k{1ReW4mE)(I%ys3_2>(6uKB)xYe2~?G%dUm{=8Y}rP!$7zW{)SaWc@brYM+LuuJn_wlShyIMFH=dU?=Xw z8dWP-o`xTzwZ<);bw#a$J}}q95dY)f=Nk8ewae&+<)f-^C%N>*K+sduTi6b6WZst! zJVyfEp%vB|yq!fK{q=Hdj#HXqrh!}r9{5Y(jiAzPcZ2v63i%}oBCyoOYz*5PgP33zGw zs2J{Hd3pYT3j7)c`X3ldyIEh@{x9CD-T*yD+-mP?U+2o&)bhJ{*4=qw!-R&+TjnvS+{zEIL#HRMsiBfk5~* zI~}7`ysPbIRp6YZS)F1+E7{`h9q^Vs*(YzQn#^x%<3Zjz@)nOF)LhD2{wJc4!lx*2 zG0Qp7N-d=ZC0(0DN6&XqPhPr06x*ko#3uO~X}+FbBwG|>9O-DtQag1OKodw^%bF2R zxXgb!b11V$*gWbcquad{h>x`YVVffVa_VFMX(d6Q^N@aYPHSE?z_KSw z-6064WZJ)w^a^UJ(y1w?h>l7*$N4=QQ;Xj%N5f#{JQRnxqpIuL(%+m#-JYm$erEFc zYsHK)ui`sn_J(5*{>)8&Fp!8aM}Vu}(=DHjy@j~=^W|Elp;gs4itPO3|YQrda-r3bnTmHw)5e;1RfLe0<&*@yO<-5|h!^0EhR~E?i@s82|vL{{~05FxrMq-Bec&b>9o|g|7 z<}4-$VUX2a90_e6I&btO`U z^Y5WwAG)J*7}>okw%FGzpP#yqIJ3A?J*R6RH4&Zn!V=vYwcF z;V0QP11JO|@V15yrlQCs>1n03N9Jki7v;lRQ{YHwfv);Ks;<-(JAAE5=?#17a46CN z!eeC)OAn41X^uf(l4uU28<-9oO5u~iFH)2fM5(6GubShD(#?zYNv9i$yk{zKR+O)= zxu$@+T$sM9a|;qZGEfx9v3prspxEu4D8e5V3-?fYiDQ6+Ek zM9d@-A2=%3K-AKjb7u=v&X-5b{GPVZQ-{Q{Ji~WsZ7DQ9#UbB~iS)YFRpiDX zdO%UHatl%h-SNrz40ZcG$MabHCBuPrkMxP;Z_bs6xA<0_D}T2wAMF1Te*bRq)GXKy zpKRMPIN}wOlX`Hx2}eOG$WL)5z(i81CaK%wR;jDR^iosp`D z5e{`n=1*>|x-hZj>BE6>476?-Y_q2|Lk(Yo9Wp?!*7UBj<&csb7aEnevR1z4bLv%%gGXA~-ZcCgw8 zQA2@9jVOf(vgp6m`a#@hRwB;oKoXRoC3_H-+^H$3PWV==DkMJ}mB8Mfv&*W+=G@`s zd3b<_!Dc)wPbF%w0*fT+8uqpOLe@+`DD12+hNC`QxPXKZNF(TMRWUB{qg>OsI9{lX zHu14a&dKvC<-Vk)g>R?qh$_?hP!>qsJO~*8bfcap)_ur))g)g4*W4EP9bQ46I8-c; zXk$JfN;jd*`xy(T2Cqmcn%A!Ft1 zB12n8V-#`+Wua+B1pK>=Y~_gLmYC=1o6}W+epmR$3|e=Nr{RqJme{vKgLRE_RL0+V z@j#E>3u}SR7efid{iu0%akfG8V?2@5BFFPB#_{-F<@E5&&!DC)H;-}w<$FHnj4p@d z#GVx~jQDSkSy*S<4C2QEOQt=5R0bcDZn`H?9_d;8v~`=BBTfl@_WSHOucOY@QNAYn*^DNHBd8VsGU8pPc7{+H83=K&a?n5R(xmos6g zoFmTdnkczR4a3L4?|j+mo~YXLkx%xqI;UW%&Ql4@`ujqy1$N#-)@c{U9BzE+Eukf#nUC?)*PiJwf(J%01@TLN}m{9N!`p?A%1SKVv&NdIk zDf>~|A=0}6-!}t+-{ZZ2YrP^8wlHoHe%?!d0n7Utoj-BAFLy`o^ctK+1ab{SDSbr` zM*e{Ro@++Lla%>8_31VC;e=WJK9}H)2khK)-rV)COT=9|fr9&gc!q9)p}(nuXAp-g zxdSwe{_By@8a;kqe^FXJu?>776hD7Am?Q4CM<4soKPOKl2P`834q6;j;6su2$0Y0E z?E>Glgq^v|zTlhNP^|PpTo_Mr+&z{2KX2(E3Dl>faImKD;2@rif`;`?`?dvrzmTRM z&8(wxJ)_ku9umYaSc8zcMH_!m2;LkskZ3kR$TUa81^k&n8VV09J&^OZbc}DyUB4=P z@;x`Nplf(5zt6D-AeWaC)cfwQlOB|_=`FeuMn7qfiahQ%Qd##Th%3Px)}@c6;O1Pa zYdr(T`Do45h*z=|^X=8yoQVB61og%;IevDZ@u*U0! zHg@^%pUGkEF|ra~%bZ*O-36wpm(kmdbd%7bDl~Co{4L~b)+lP+O)i-X1pJC(*$RVprFj3^ys{3g5 zpJ<`(#JQahL^)v!-dLxAX&j1uwy{+&hu{-Pv9MNf1)(cs)3Ro|W zvs2HkRZ0^;)Snj|7RkA**MoAXR~hvRKa^01?^-V)X5`&*r zN<>(F)cvW-lOmXx1-;|BD?^?n z#+Hw0h4=-!FfXN-CBMmz%^=knvAO`oVnaZO=6w+vJt8=-5ghD091i>ym2Tjgl7#F-V`!H}0^6wx zgFa{tkI;bTF4Ew!_fwno6aJQI^yk@BzB4#*SDrEH(}HU6t*Pl9Lzk!A+m4HW%{L-h zilpdx>98I9tIjVgF$@K zN#OW1nrh^bD2TG3Q8%gYstK_We*Az$b0+cZ7wj28;%1#`8){$geLPsTqFO3`-MfVNZOMVoK8(fk}W*P-c zBg=j6=jGMo%#MD~w>;1Z?xNoLT|?001Oq{_KnWOk**)HL2xf&*Uh>AWz68h_EG(!P zLU;K>R8E`JK0xs@3^-1)f?9rBhFoUZdStuWfNxMzi0qK7jA3h`e(pNyBMuaHtMDDA zy@z|8W&*pcbV89UpgNCcv=>*M-B4<&~!k%d}nZdn-;flQwz% zW1(-0!=QUbyqv{K!>#q#dh^I?{I%j(_{_4_(%D)4E{ckWeWpOSe|_x%pzL zx@#rV4yc4QHc0DB6K>yo`)2nWt7w|}A^8>3*l^X4Hyt#cSQ0m`kXrfcRh4LDh}4=r z=FcYx#Z7HO|Cc)6n>mTNPY}ji)eYC)eLtpfE~xm41W!Pv?j*|t$5d|br1jUo>I>@+ zw5A{OK@N9bRD@#MLEoA@!VHTJ;^0jqe}o7K<^lFdI-$6y*y1gN6d0Zr2x$U>U#|Rg z4B(ji{!X_xSeX0hf36B`o!-zM;L!Lc<@1i^IrFhx!eP+nx@Lz_R~^vFC<0|^gs%Ge z&?RLdsSAhyd=o|#!BwCUV#PKVhjG+LC>SGhDl2~g8H0_ZCLhg%XRZaOE*F9{i4$9- zdsGA&gNbWEAtMgtRS!tBj0=Kqh{*U&K;-d_xf)z*oJf^?6pT&sC*+#oR3-rt#5ZPC zOVj_gqa;4c5YhkjzvH2SfKdIX|2^RbD$#fW33vujPq4po=wA;HG?*c+;gN^^;;iAp zp=pa&)ApA|ep`nTS98gjy$dc=m!j^XWz5Yx7tz{e#9cYhrl(<8<8b7ot~+0My_+2_ zJb7&M6eV&}eF|NB<~+auIpOQNyT;Uqtb_PUxDAVv5OJ3kLf@u2uz?NWEEVkEcs+E$ z2Ckv^vYEGwcj33I^Dq>s(n6h>w+ju3r9=A>MwV<$9;7 zD}>&_&zyL;vj@fAd?-->QR;+;F@@1qpv-`$d;GALTJiuTP*3egpeBU+%_EXt(rjH1 z4;Sa`78C30)(!_V>nuwG)~SLs0{nLw=x4kYdCN;|dYQ0+9x0ACU; zC%IWV*H!}pAERM;p=TdE^JVxxS9wp~piA#)++R36`2p(_K8MAk$vQ{hFX*t48OJ`fLxBf(AZ2x9Rs{ zxE}q7hUE}7q)^z$@W85ZQLZVWQJ7up3S8QrMi*U1(AoPTJ-@c5)tKbmh zs3i&|>=+mXifkF0WrtIj4Kvu!N{>9*nq?ZTw@@5l&6hbfwNFR`lYZby!pOCtQW=hw zA^xQw?^j2MjT>;C%_7S@i3i^QVX1AZBDbqHAq9L?TZ~HISjE@&oUY~L=ik!QMmJA& zc&?$(!WdOX=LzW)^GnOAVkDt+j3u$vscWg~*DA@xFnE5q78Q`NH$cNo zeRa5w!rIkKhpFB0Y_Pj^)GuDC!0%`NUsqQi4rTX-^V+vDVaE0*W*TWi6Jabxk;qa+ ziI6QMvX+!4Ava#W*!veJZ|DFrqm=YzLK^wAE`r^z!=>U~OV3Vv_FfD>7J8*YHm%~! z{i2$(ys;3Q^6zJ3svhgcPcu)kzU!`Qa=1Y|cNDv)#f3atToQJP{ONW=!LxkU$Mcld ztLW?k?N7SYmd#;_m4=1Os%ApHx^Ba8;NHH+fy$_A^FXcpJylG%!WgOJf=U^g?f>xJ zXqy#?(DU%4a$^l-_A&!L?_MkfS(|DMT}8TY-Hu{hU4LxZJBW~e)tV{BJt}ZZU8(2q zut_g)!eT95b;k+g?hh01YAv;vLQUutuWJj;O*@3h|bZ*~>T+4tI=&sxe|5=m9Q4zZ8i6EnieuRfWb5(|$n zPd$}$I}g)N;`a$d+11?-_^bj23!vKak6}MnT$rSGxE_h+NiGf+Jc(|vlvajPC`Qn^o zxxQ26T3fy=U-IksLSv<7*>^);AEfAbolc9zY1mK0T6(d*Jno6X54&_6H@@z2F?7!j zsN-u84LoJkqvCdGOZtzs`Y~SU&~@#RySMq{e7o9L7_aPitz^iJi+S?&DBtRd4-#WU z@Xs_@S-45bGyH4l*U^jp`ZEk+$(85;*9(j0fda8H=G2LLlET3$Q?pXCQ86Xj{CYmi zfXBwN7FZKH=?60lLYis%$;h3ERO0QgIL0{JSaA29&Pio2wLE`5zmNxML0){*o%1%P zbvX5$=<4;$f*lqgB~py*gFXuls_9?QPIoS~6nInOeXVImyF<;8ihmhVdb^2xPz1*_ zFn3Gl#4{8D+qW%IHFhlE%RP#{e-7heb1RF0`MQ6P&=qyx%94v&hePEvgec?H>bXid z#|J^Ep4cYtFAMdKUiYHT>uoWd7F`D44mX+wBX+zp@-Y z(uK!`I8GcR)5xTx3Z4SfGe)*;iU>uIX>i;^W`2$PLctdPDpXZ_YgY^<+xCOq;f4l% zd4Wgrmq}c8Pnk1)VjsUZw+!8EsT~{{A`g5e8u9V!EZ$97=zR?N&GR)UZI?+|jnv3YA|K-``Z|OL|#yprTm(2Gyx`%v(yb(pbhK zru@vIzZ3&RHAN#Qx_kv5TG8}VyX~{Z!ySl(Kn>SOlB9+8>99CNnN)?GI1+XvePV6C z!RWlZx%KsH`D&_VYELq8Jd5u5J_|3dG!LO-m)-XD8AnwEb5z4Mb`pGAt1^x8kG03O z9t^B`_aphC^T73n?ehLa)|+7#Zb0?o%D@T)w)Vm0KD{zrLi>YiGD?tplqwb^^?5^R zVQ^cR0OXiN=z=hi7TJuLFi2sdpeA8(lc@(S34_Zb8UWQ#grZQ0DFe2NZ9rT!i0zk! zwn=~iWf;)=cS6mQY*T(f2O?tGW*=4r$j+g`R~RjV6cDkW!pHy^3F1NffE2tc{%(%w zm(Y>*=>0|@ZDFM2IyNYEkQZzoB*3dO*7?XAjS|Aeqrm}OQTPSK!EEhdBwMI3qF%)T z`iN(P<_0(OvUNm(!Vm^BMgFiTn*z!Z8s^Y=qOh!OD>@{%cx%@^TZDAx?4|M410{SqTm#yXk zaz`+b=5}`aRS}nw5iBoT5F>pQ18p_@)vqMSmLEVitr{UQQs>C103t_s%W)9UbHqcy zz^Dz(!8^|pFEd3p00#ocNRWUdU^yy-mN6oPaYsxXkQvwF(gFL&y&zFP&x%v8 z2tZGupne~qFrm+d22K+yavbDi921x!@l`4^Z79|cbezQi6w3rkKKaX(1QZqt`Vs=} zvov82nkJ4U-Ju9x9${_LgxOpx$k8~DoS$tRAir=BIB5d^p>tTXMv((>^gNPf9hjRW zL5-KeK)MDvjhubYDOspG4Ma}4K=d2zWm$0{aynBxpr|aiYcstb{1^|PEdhwm5+T3ZU#=){oFze(jcj+Sc^#n7qTxTE3w{>*{h6KdY89A1M}#@vzJ3Fc VwlMN}`%er%aGR6olj~j${vQ;P=LY}) diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index ae04661ee7..f398c33c4b 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -1,5 +1,6 @@ distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-7.5.1-bin.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-7.6-bin.zip +networkTimeout=10000 zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists diff --git a/gradlew b/gradlew index a69d9cb6c2..65dcd68d65 100755 --- a/gradlew +++ b/gradlew @@ -55,7 +55,7 @@ # Darwin, MinGW, and NonStop. # # (3) This script is generated from the Groovy template -# https://github.com/gradle/gradle/blob/master/subprojects/plugins/src/main/resources/org/gradle/api/internal/plugins/unixStartScript.txt +# https://github.com/gradle/gradle/blob/HEAD/subprojects/plugins/src/main/resources/org/gradle/api/internal/plugins/unixStartScript.txt # within the Gradle project. # # You can find Gradle at https://github.com/gradle/gradle/. @@ -80,10 +80,10 @@ do esac done -APP_HOME=$( cd "${APP_HOME:-./}" && pwd -P ) || exit - -APP_NAME="Gradle" +# This is normally unused +# shellcheck disable=SC2034 APP_BASE_NAME=${0##*/} +APP_HOME=$( cd "${APP_HOME:-./}" && pwd -P ) || exit # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"' @@ -143,12 +143,16 @@ fi if ! "$cygwin" && ! "$darwin" && ! "$nonstop" ; then case $MAX_FD in #( max*) + # In POSIX sh, ulimit -H is undefined. That's why the result is checked to see if it worked. + # shellcheck disable=SC3045 MAX_FD=$( ulimit -H -n ) || warn "Could not query maximum file descriptor limit" esac case $MAX_FD in #( '' | soft) :;; #( *) + # In POSIX sh, ulimit -n is undefined. That's why the result is checked to see if it worked. + # shellcheck disable=SC3045 ulimit -n "$MAX_FD" || warn "Could not set maximum file descriptor limit to $MAX_FD" esac diff --git a/gradlew.bat b/gradlew.bat index f127cfd49d..93e3f59f13 100644 --- a/gradlew.bat +++ b/gradlew.bat @@ -26,6 +26,7 @@ if "%OS%"=="Windows_NT" setlocal set DIRNAME=%~dp0 if "%DIRNAME%"=="" set DIRNAME=. +@rem This is normally unused set APP_BASE_NAME=%~n0 set APP_HOME=%DIRNAME% From 4816da628f08453210e0cbf503988f321cae6686 Mon Sep 17 00:00:00 2001 From: "renovate[bot]" <29139614+renovate[bot]@users.noreply.github.com> Date: Wed, 30 Nov 2022 16:14:47 +0000 Subject: [PATCH 359/757] chore(deps): update plugin org.gradle.test-retry to v1.5.0 --- settings.gradle | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/settings.gradle b/settings.gradle index e0f3291da5..eb818a2c0e 100644 --- a/settings.gradle +++ b/settings.gradle @@ -12,7 +12,7 @@ pluginManagement { // https://github.com/diffplug/goomph/blob/main/CHANGES.md id 'com.diffplug.p2.asmaven' version '3.27.0' // DO NOT UPDATE, see https://github.com/diffplug/spotless/pull/874 // https://github.com/gradle/test-retry-gradle-plugin/releases - id 'org.gradle.test-retry' version '1.4.1' + id 'org.gradle.test-retry' version '1.5.0' // https://github.com/radarsh/gradle-test-logger-plugin/blob/develop/CHANGELOG.md id 'com.adarshr.test-logger' version '3.2.0' // https://github.com/davidburstrom/version-compatibility-gradle-plugin/tags From 1f0397c6976d02ffa034441900145ac526e651d8 Mon Sep 17 00:00:00 2001 From: Konrad Windszus Date: Thu, 1 Dec 2022 12:30:05 +0100 Subject: [PATCH 360/757] Add m2e support This closes #1413 --- plugin-maven/build.gradle | 1 + .../spotless/maven/AbstractSpotlessMojo.java | 10 ++++-- .../spotless/maven/SpotlessApplyMojo.java | 1 + .../maven/incremental/UpToDateChecker.java | 22 +++++++++++++ .../m2e/lifecycle-mapping-metadata.xml | 32 +++++++++++++++++++ 5 files changed, 64 insertions(+), 2 deletions(-) create mode 100644 plugin-maven/src/main/resources/META-INF/m2e/lifecycle-mapping-metadata.xml diff --git a/plugin-maven/build.gradle b/plugin-maven/build.gradle index b7ac8a36c8..3ea73e6101 100644 --- a/plugin-maven/build.gradle +++ b/plugin-maven/build.gradle @@ -76,6 +76,7 @@ dependencies { implementation "com.diffplug.durian:durian-collect:${VER_DURIAN}" implementation("org.codehaus.plexus:plexus-resources:${VER_PLEXUS_RESOURCES}") implementation "org.eclipse.jgit:org.eclipse.jgit:${VER_JGIT}" + implementation 'org.sonatype.plexus:plexus-build-api:0.0.7' testImplementation project(":testlib") testImplementation "org.junit.jupiter:junit-jupiter:${VER_JUNIT}" diff --git a/plugin-maven/src/main/java/com/diffplug/spotless/maven/AbstractSpotlessMojo.java b/plugin-maven/src/main/java/com/diffplug/spotless/maven/AbstractSpotlessMojo.java index f163fa2802..a0180e6d75 100644 --- a/plugin-maven/src/main/java/com/diffplug/spotless/maven/AbstractSpotlessMojo.java +++ b/plugin-maven/src/main/java/com/diffplug/spotless/maven/AbstractSpotlessMojo.java @@ -88,6 +88,9 @@ public abstract class AbstractSpotlessMojo extends AbstractMojo { @Component private ResourceManager resourceManager; + @Component + protected BuildContext buildContext; + @Parameter(defaultValue = "${mojoExecution.goal}", required = true, readonly = true) private String goal; @@ -344,10 +347,13 @@ private UpToDateChecker createUpToDateChecker(Iterable formatters) { Path targetDir = project.getBasedir().toPath().resolve(project.getBuild().getDirectory()); indexFile = targetDir.resolve(DEFAULT_INDEX_FILE_NAME); } + final UpToDateChecker checker; if (upToDateChecking != null && upToDateChecking.isEnabled()) { getLog().info("Up-to-date checking enabled"); - return UpToDateChecker.forProject(project, indexFile, formatters, getLog()); + checker = UpToDateChecker.forProject(project, indexFile, formatters, getLog()); + } else { + checker = UpToDateChecker.noop(project, indexFile, getLog()); } - return UpToDateChecker.noop(project, indexFile, getLog()); + return UpToDateChecker.wrapWithBuildContext(checker, buildContext); } } diff --git a/plugin-maven/src/main/java/com/diffplug/spotless/maven/SpotlessApplyMojo.java b/plugin-maven/src/main/java/com/diffplug/spotless/maven/SpotlessApplyMojo.java index 6ea67240ee..4f3fb64f5a 100644 --- a/plugin-maven/src/main/java/com/diffplug/spotless/maven/SpotlessApplyMojo.java +++ b/plugin-maven/src/main/java/com/diffplug/spotless/maven/SpotlessApplyMojo.java @@ -45,6 +45,7 @@ protected void process(Iterable files, Formatter formatter, UpToDateChecke PaddedCell.DirtyState dirtyState = PaddedCell.calculateDirtyState(formatter, file); if (!dirtyState.isClean() && !dirtyState.didNotConverge()) { dirtyState.writeCanonicalTo(file); + buildContext.refresh(file); } } catch (IOException e) { throw new MojoExecutionException("Unable to format file " + file, e); diff --git a/plugin-maven/src/main/java/com/diffplug/spotless/maven/incremental/UpToDateChecker.java b/plugin-maven/src/main/java/com/diffplug/spotless/maven/incremental/UpToDateChecker.java index 2fd2f3a1ea..6dd21728e3 100644 --- a/plugin-maven/src/main/java/com/diffplug/spotless/maven/incremental/UpToDateChecker.java +++ b/plugin-maven/src/main/java/com/diffplug/spotless/maven/incremental/UpToDateChecker.java @@ -19,6 +19,7 @@ import org.apache.maven.plugin.logging.Log; import org.apache.maven.project.MavenProject; +import org.sonatype.plexus.build.incremental.BuildContext; import com.diffplug.spotless.Formatter; @@ -37,4 +38,25 @@ static UpToDateChecker noop(MavenProject project, Path indexFile, Log log) { static UpToDateChecker forProject(MavenProject project, Path indexFile, Iterable formatters, Log log) { return IndexBasedChecker.create(project, indexFile, formatters, log); } + + static UpToDateChecker wrapWithBuildContext(UpToDateChecker delegate, BuildContext buildContext) { + return new UpToDateChecker() { + + @Override + public void setUpToDate(Path file) { + delegate.setUpToDate(file); + } + + @Override + public boolean isUpToDate(Path file) { + return !buildContext.hasDelta(file.toFile()) || delegate.isUpToDate(file); + } + + @Override + public void close() { + delegate.close(); + } + }; + } + } diff --git a/plugin-maven/src/main/resources/META-INF/m2e/lifecycle-mapping-metadata.xml b/plugin-maven/src/main/resources/META-INF/m2e/lifecycle-mapping-metadata.xml new file mode 100644 index 0000000000..9000b83704 --- /dev/null +++ b/plugin-maven/src/main/resources/META-INF/m2e/lifecycle-mapping-metadata.xml @@ -0,0 +1,32 @@ + + + + + + + + apply + check + + + + + true + false + + + + + \ No newline at end of file From a7c0f67a76da52d80f575fdf43ac481906210999 Mon Sep 17 00:00:00 2001 From: Konrad Windszus Date: Thu, 1 Dec 2022 12:41:37 +0100 Subject: [PATCH 361/757] fix formatting --- .../java/com/diffplug/spotless/maven/SpotlessApplyMojo.java | 2 +- .../spotless/maven/incremental/UpToDateChecker.java | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/plugin-maven/src/main/java/com/diffplug/spotless/maven/SpotlessApplyMojo.java b/plugin-maven/src/main/java/com/diffplug/spotless/maven/SpotlessApplyMojo.java index 4f3fb64f5a..7a15d01b17 100644 --- a/plugin-maven/src/main/java/com/diffplug/spotless/maven/SpotlessApplyMojo.java +++ b/plugin-maven/src/main/java/com/diffplug/spotless/maven/SpotlessApplyMojo.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. diff --git a/plugin-maven/src/main/java/com/diffplug/spotless/maven/incremental/UpToDateChecker.java b/plugin-maven/src/main/java/com/diffplug/spotless/maven/incremental/UpToDateChecker.java index 6dd21728e3..f63b8b4dfc 100644 --- a/plugin-maven/src/main/java/com/diffplug/spotless/maven/incremental/UpToDateChecker.java +++ b/plugin-maven/src/main/java/com/diffplug/spotless/maven/incremental/UpToDateChecker.java @@ -38,10 +38,10 @@ static UpToDateChecker noop(MavenProject project, Path indexFile, Log log) { static UpToDateChecker forProject(MavenProject project, Path indexFile, Iterable formatters, Log log) { return IndexBasedChecker.create(project, indexFile, formatters, log); } - + static UpToDateChecker wrapWithBuildContext(UpToDateChecker delegate, BuildContext buildContext) { return new UpToDateChecker() { - + @Override public void setUpToDate(Path file) { delegate.setUpToDate(file); @@ -58,5 +58,5 @@ public void close() { } }; } - + } From fa232426a5ea26cee7a8e483b3a81c3677a1c1d1 Mon Sep 17 00:00:00 2001 From: Konrad Windszus Date: Thu, 1 Dec 2022 12:45:57 +0100 Subject: [PATCH 362/757] add missing import --- .../java/com/diffplug/spotless/maven/AbstractSpotlessMojo.java | 1 + 1 file changed, 1 insertion(+) diff --git a/plugin-maven/src/main/java/com/diffplug/spotless/maven/AbstractSpotlessMojo.java b/plugin-maven/src/main/java/com/diffplug/spotless/maven/AbstractSpotlessMojo.java index a0180e6d75..e4fdc7dcd0 100644 --- a/plugin-maven/src/main/java/com/diffplug/spotless/maven/AbstractSpotlessMojo.java +++ b/plugin-maven/src/main/java/com/diffplug/spotless/maven/AbstractSpotlessMojo.java @@ -50,6 +50,7 @@ import org.eclipse.aether.RepositorySystem; import org.eclipse.aether.RepositorySystemSession; import org.eclipse.aether.repository.RemoteRepository; +import org.sonatype.plexus.build.incremental.BuildContext; import com.diffplug.spotless.Formatter; import com.diffplug.spotless.LineEnding; From b7b17a9831095685622934f34133585c55517c4e Mon Sep 17 00:00:00 2001 From: Konrad Windszus Date: Sat, 3 Dec 2022 09:37:48 +0100 Subject: [PATCH 363/757] replace OR by AND --- .../diffplug/spotless/maven/incremental/UpToDateChecker.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugin-maven/src/main/java/com/diffplug/spotless/maven/incremental/UpToDateChecker.java b/plugin-maven/src/main/java/com/diffplug/spotless/maven/incremental/UpToDateChecker.java index f63b8b4dfc..be971cb374 100644 --- a/plugin-maven/src/main/java/com/diffplug/spotless/maven/incremental/UpToDateChecker.java +++ b/plugin-maven/src/main/java/com/diffplug/spotless/maven/incremental/UpToDateChecker.java @@ -49,7 +49,7 @@ public void setUpToDate(Path file) { @Override public boolean isUpToDate(Path file) { - return !buildContext.hasDelta(file.toFile()) || delegate.isUpToDate(file); + return !buildContext.hasDelta(file.toFile()) && delegate.isUpToDate(file); } @Override From b22f54fe8367051e3a3bd969e1c7155713beb1e3 Mon Sep 17 00:00:00 2001 From: Konrad Windszus Date: Sat, 3 Dec 2022 09:48:00 +0100 Subject: [PATCH 364/757] fix condition to only evaluate IndexBasedChecker when necessary --- .../diffplug/spotless/maven/incremental/UpToDateChecker.java | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/plugin-maven/src/main/java/com/diffplug/spotless/maven/incremental/UpToDateChecker.java b/plugin-maven/src/main/java/com/diffplug/spotless/maven/incremental/UpToDateChecker.java index be971cb374..bda325d992 100644 --- a/plugin-maven/src/main/java/com/diffplug/spotless/maven/incremental/UpToDateChecker.java +++ b/plugin-maven/src/main/java/com/diffplug/spotless/maven/incremental/UpToDateChecker.java @@ -49,7 +49,10 @@ public void setUpToDate(Path file) { @Override public boolean isUpToDate(Path file) { - return !buildContext.hasDelta(file.toFile()) && delegate.isUpToDate(file); + if (buildContext.hasDelta(file)) { + return delegate.isUpToDate(file); + } + return true; } @Override From fc02156bdc8c265a20eb475e48438e93af783412 Mon Sep 17 00:00:00 2001 From: Konrad Windszus Date: Mon, 5 Dec 2022 09:53:10 +0100 Subject: [PATCH 365/757] fix compilation error and make field private --- .../java/com/diffplug/spotless/maven/AbstractSpotlessMojo.java | 2 +- .../diffplug/spotless/maven/incremental/UpToDateChecker.java | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/plugin-maven/src/main/java/com/diffplug/spotless/maven/AbstractSpotlessMojo.java b/plugin-maven/src/main/java/com/diffplug/spotless/maven/AbstractSpotlessMojo.java index e4fdc7dcd0..2f3f0e4ab2 100644 --- a/plugin-maven/src/main/java/com/diffplug/spotless/maven/AbstractSpotlessMojo.java +++ b/plugin-maven/src/main/java/com/diffplug/spotless/maven/AbstractSpotlessMojo.java @@ -90,7 +90,7 @@ public abstract class AbstractSpotlessMojo extends AbstractMojo { private ResourceManager resourceManager; @Component - protected BuildContext buildContext; + private BuildContext buildContext; @Parameter(defaultValue = "${mojoExecution.goal}", required = true, readonly = true) private String goal; diff --git a/plugin-maven/src/main/java/com/diffplug/spotless/maven/incremental/UpToDateChecker.java b/plugin-maven/src/main/java/com/diffplug/spotless/maven/incremental/UpToDateChecker.java index bda325d992..40dc84c8c6 100644 --- a/plugin-maven/src/main/java/com/diffplug/spotless/maven/incremental/UpToDateChecker.java +++ b/plugin-maven/src/main/java/com/diffplug/spotless/maven/incremental/UpToDateChecker.java @@ -49,7 +49,7 @@ public void setUpToDate(Path file) { @Override public boolean isUpToDate(Path file) { - if (buildContext.hasDelta(file)) { + if (buildContext.hasDelta(file.toFile())) { return delegate.isUpToDate(file); } return true; From 52ea9fb8e1694245ce74f1c03b3e3ffbdcddbdb1 Mon Sep 17 00:00:00 2001 From: Konrad Windszus Date: Mon, 5 Dec 2022 09:56:08 +0100 Subject: [PATCH 366/757] revert making field private, as accessed in subclasses --- .../java/com/diffplug/spotless/maven/AbstractSpotlessMojo.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugin-maven/src/main/java/com/diffplug/spotless/maven/AbstractSpotlessMojo.java b/plugin-maven/src/main/java/com/diffplug/spotless/maven/AbstractSpotlessMojo.java index 2f3f0e4ab2..e4fdc7dcd0 100644 --- a/plugin-maven/src/main/java/com/diffplug/spotless/maven/AbstractSpotlessMojo.java +++ b/plugin-maven/src/main/java/com/diffplug/spotless/maven/AbstractSpotlessMojo.java @@ -90,7 +90,7 @@ public abstract class AbstractSpotlessMojo extends AbstractMojo { private ResourceManager resourceManager; @Component - private BuildContext buildContext; + protected BuildContext buildContext; @Parameter(defaultValue = "${mojoExecution.goal}", required = true, readonly = true) private String goal; From 99272b229158ef0116c53ed9e8a7f69008638f93 Mon Sep 17 00:00:00 2001 From: "renovate[bot]" <29139614+renovate[bot]@users.noreply.github.com> Date: Fri, 9 Dec 2022 13:59:44 +0000 Subject: [PATCH 367/757] fix(deps): update dependency com.facebook:ktfmt to v0.42 --- lib/build.gradle | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/build.gradle b/lib/build.gradle index e398e80d23..18935800fa 100644 --- a/lib/build.gradle +++ b/lib/build.gradle @@ -54,7 +54,7 @@ dependencies { palantirJavaFormatCompileOnly 'com.palantir.javaformat:palantir-java-format:1.1.0' // this version needs to stay compilable against Java 8 for CI Job testNpm - String VER_KTFMT = '0.41' + String VER_KTFMT = '0.42' 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") { From 2e4197ec7a99482a090d3f5a7da70f040e497e98 Mon Sep 17 00:00:00 2001 From: Laurent Goujon Date: Thu, 15 Dec 2022 14:55:19 -0800 Subject: [PATCH 368/757] Fix typo in gradle properties Fix typo in constant used by gradle scripts: ECLISPE -> ECLIPSE --- _ext/eclipse-cdt/build.gradle | 4 ++-- _ext/eclipse-cdt/gradle.properties | 4 ++-- _ext/eclipse-groovy/build.gradle | 2 +- _ext/eclipse-groovy/gradle.properties | 2 +- _ext/eclipse-wtp/build.gradle | 10 +++++----- _ext/eclipse-wtp/gradle.properties | 8 ++++---- 6 files changed, 15 insertions(+), 15 deletions(-) diff --git a/_ext/eclipse-cdt/build.gradle b/_ext/eclipse-cdt/build.gradle index 17819f4a2e..93ccac3b24 100644 --- a/_ext/eclipse-cdt/build.gradle +++ b/_ext/eclipse-cdt/build.gradle @@ -19,13 +19,13 @@ apply from: rootProject.file('gradle/java-publish.gradle') dependencies { implementation "com.diffplug.spotless:spotless-eclipse-base:${VER_SPOTLESS_ECLISPE_BASE}" // Provides text partitioners for formatters - implementation ("org.eclipse.platform:org.eclipse.jface.text:${VER_ECLISPE_JFACE}") { + implementation ("org.eclipse.platform:org.eclipse.jface.text:${VER_ECLIPSE_JFACE}") { exclude group: 'org.eclipse.platform', module: 'org.eclipse.swt' } // Required to by CCorePlugin calling CDTLogWriter implementation "com.ibm.icu:icu4j:${VER_IBM_ICU}" // Required to by CCorePlugin calling PositionTrackerManager - implementation "org.eclipse.platform:org.eclipse.core.filebuffers:${VER_ECLISPE_EFS}" + implementation "org.eclipse.platform:org.eclipse.core.filebuffers:${VER_ECLIPSE_EFS}" testImplementation("org.slf4j:slf4j-simple:${VER_SLF4J}") } diff --git a/_ext/eclipse-cdt/gradle.properties b/_ext/eclipse-cdt/gradle.properties index 9c1c8a7ee6..10166b51d0 100644 --- a/_ext/eclipse-cdt/gradle.properties +++ b/_ext/eclipse-cdt/gradle.properties @@ -7,6 +7,6 @@ VER_JAVA=11 # Compile dependencies VER_ECLIPSE_CDT=10.5 VER_SPOTLESS_ECLISPE_BASE=[3.5.0,4.0.0[ -VER_ECLISPE_JFACE=[3.18.0,4.0.0[ -VER_ECLISPE_EFS=[3.7.0,4.0.0[ +VER_ECLIPSE_JFACE=[3.18.0,4.0.0[ +VER_ECLIPSE_EFS=[3.7.0,4.0.0[ VER_IBM_ICU=[67.1,68[ diff --git a/_ext/eclipse-groovy/build.gradle b/_ext/eclipse-groovy/build.gradle index e1382acd76..00a7fed489 100644 --- a/_ext/eclipse-groovy/build.gradle +++ b/_ext/eclipse-groovy/build.gradle @@ -41,7 +41,7 @@ apply from: rootProject.file('gradle/java-publish.gradle') dependencies { implementation "com.diffplug.spotless:spotless-eclipse-base:${VER_SPOTLESS_ECLISPE_BASE}" // Provides text partitioners for formatters - implementation ("org.eclipse.platform:org.eclipse.jface.text:${VER_ECLISPE_JFACE}") { + implementation ("org.eclipse.platform:org.eclipse.jface.text:${VER_ECLIPSE_JFACE}") { exclude group: 'org.eclipse.platform', module: 'org.eclipse.swt' } testImplementation("org.slf4j:slf4j-simple:${VER_SLF4J}") diff --git a/_ext/eclipse-groovy/gradle.properties b/_ext/eclipse-groovy/gradle.properties index b8a21001fd..9569e765bc 100644 --- a/_ext/eclipse-groovy/gradle.properties +++ b/_ext/eclipse-groovy/gradle.properties @@ -7,7 +7,7 @@ VER_JAVA=11 # Compile VER_ECLIPSE=4.21 VER_SPOTLESS_ECLISPE_BASE=[3.4.2,4.0.0[ -VER_ECLISPE_JFACE=[3.15.300,4.0.0[ +VER_ECLIPSE_JFACE=[3.15.300,4.0.0[ VER_GRECLIPSE=4.3.0 VER_GROOVY=4.0.0 # Use org.eclipse.jdt.core patched for Groovy-Eclipse diff --git a/_ext/eclipse-wtp/build.gradle b/_ext/eclipse-wtp/build.gradle index 4001e100c2..ba32385a1b 100644 --- a/_ext/eclipse-wtp/build.gradle +++ b/_ext/eclipse-wtp/build.gradle @@ -64,20 +64,20 @@ dependencies { // Required by most WPT formatters implementation "com.ibm.icu:icu4j:${VER_IBM_ICU}" // The XSD/DTD and other models are defined with EMF. - implementation "org.eclipse.emf:org.eclipse.emf.common:${VER_ECLISPE_EMF}" - implementation "org.eclipse.emf:org.eclipse.emf.ecore:${VER_ECLISPE_EMF}" + implementation "org.eclipse.emf:org.eclipse.emf.common:${VER_ECLIPSE_EMF}" + implementation "org.eclipse.emf:org.eclipse.emf.ecore:${VER_ECLIPSE_EMF}" // Some WPT plugins requires OSGI bundle interfaces (but not effectively used) implementation "org.eclipse.platform:org.eclipse.osgi.services:${VER_ECLIPSE_OSGI_SERVICES}" // Provides document data structure and file buffers for formatters implementation "org.eclipse.platform:org.eclipse.core.filebuffers:${VER_ECLIPSE_FILE_BUFFERS}" // Provides text partitioners for formatters - implementation ("org.eclipse.platform:org.eclipse.jface.text:${VER_ECLISPE_JFACE}") { + implementation ("org.eclipse.platform:org.eclipse.jface.text:${VER_ECLIPSE_JFACE}") { exclude group: 'org.eclipse.platform', module: 'org.eclipse.swt' } // Some WPT plugins use the EFS for storing temporary worspace data - implementation "org.eclipse.platform:org.eclipse.core.filesystem:${VER_ECLISPE_EFS}" + implementation "org.eclipse.platform:org.eclipse.core.filesystem:${VER_ECLIPSE_EFS}" // Required by org.eclipse.wst.xsd.core - implementation "org.eclipse.emf:org.eclipse.xsd:${VER_ECLISPE_XSD}" + implementation "org.eclipse.emf:org.eclipse.xsd:${VER_ECLIPSE_XSD}" testImplementation("org.slf4j:slf4j-simple:${VER_SLF4J}") } diff --git a/_ext/eclipse-wtp/gradle.properties b/_ext/eclipse-wtp/gradle.properties index 743748d1ba..f6cedd63e3 100644 --- a/_ext/eclipse-wtp/gradle.properties +++ b/_ext/eclipse-wtp/gradle.properties @@ -8,9 +8,9 @@ VER_JAVA=11 VER_ECLIPSE_WTP=2021-09 VER_SPOTLESS_ECLISPE_BASE=[3.5.0,4.0.0[ VER_IBM_ICU=[67.1,68[ -VER_ECLISPE_EMF=[2.22.0,3.0.0[ +VER_ECLIPSE_EMF=[2.22.0,3.0.0[ VER_ECLIPSE_OSGI_SERVICES=[3.10.0,4.0.0[ VER_ECLIPSE_FILE_BUFFERS=[3.7.0,4.0.0[ -VER_ECLISPE_JFACE=[3.18.0,4.0.0[ -VER_ECLISPE_EFS=[1.9.0,2.0.0[ -VER_ECLISPE_XSD=[2.18.0,3.0.0[ +VER_ECLIPSE_JFACE=[3.18.0,4.0.0[ +VER_ECLIPSE_EFS=[1.9.0,2.0.0[ +VER_ECLIPSE_XSD=[2.18.0,3.0.0[ From 697236562f7ce20025c619d30fe5756b1404bd0c Mon Sep 17 00:00:00 2001 From: Laurent Goujon Date: Thu, 15 Dec 2022 14:56:28 -0800 Subject: [PATCH 369/757] Reduce ratchet memory usage for multi-module projects Ratchet creates a cache of Git repository per project but each Git repository is a new FileRepository instance even if two projects share the same repository on disk. Since FileRepository is thread-safe, change GitRatchet to cache FileRepository instances per git repository --- .../com/diffplug/spotless/extra/GitRatchet.java | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/lib-extra/src/main/java/com/diffplug/spotless/extra/GitRatchet.java b/lib-extra/src/main/java/com/diffplug/spotless/extra/GitRatchet.java index 6b8d5a9f41..3b0e3c06ed 100644 --- a/lib-extra/src/main/java/com/diffplug/spotless/extra/GitRatchet.java +++ b/lib-extra/src/main/java/com/diffplug/spotless/extra/GitRatchet.java @@ -138,6 +138,7 @@ private static boolean worktreeIsCleanCheckout(TreeWalk treeWalk) { private final static int WORKDIR = 2; Map gitRoots = new HashMap<>(); + Map gitRepositories = new HashMap<>(); Table rootTreeShaCache = HashBasedTable.create(); Map subtreeShaCache = new HashMap<>(); @@ -174,7 +175,7 @@ protected Repository repositoryFor(Project project) throws IOException { protected abstract @Nullable Project getParent(Project project); - private static @Nullable Repository traverseParentsUntil(File startWith, @Nullable File file) throws IOException { + private @Nullable Repository traverseParentsUntil(File startWith, @Nullable File file) throws IOException { while (startWith != null && !Objects.equals(startWith, file)) { if (isGitRoot(startWith)) { return createRepo(startWith); @@ -190,8 +191,14 @@ private static boolean isGitRoot(File dir) { return dotGit != null && RepositoryCache.FileKey.isGitRepository(dotGit, FS.DETECTED); } - static Repository createRepo(File dir) throws IOException { - return FileRepositoryBuilder.create(GitWorkarounds.getDotGitDir(dir)); + Repository createRepo(File dir) throws IOException { + File dotGitDir = GitWorkarounds.getDotGitDir(dir); + Repository repo = gitRepositories.get(dotGitDir); + if (repo == null) { + repo = FileRepositoryBuilder.create(dotGitDir); + gitRepositories.put(dotGitDir, repo); + } + return repo; } /** From f6f37f4d9e4cad9e1732afbfee4615a7fbbd1345 Mon Sep 17 00:00:00 2001 From: Laurent Goujon Date: Thu, 15 Dec 2022 15:07:57 -0800 Subject: [PATCH 370/757] Update CHANGES.md --- CHANGES.md | 1 + plugin-gradle/CHANGES.md | 1 + plugin-maven/CHANGES.md | 1 + 3 files changed, 3 insertions(+) diff --git a/CHANGES.md b/CHANGES.md index b4bdc4479e..b781dacb6d 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -17,6 +17,7 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format ( ### Fixed * Don't treat `@Value` as a type annotation [#1367](https://github.com/diffplug/spotless/pull/1367) * Support `ktlint_disabled_rules` in `ktlint` 0.47.x [#1378](https://github.com/diffplug/spotless/pull/1378) +* Share git repositories across projects when using ratchet ([#1426](https://github.com/diffplug/spotless/pull/1426)) ### Changes * Bump default `ktfmt` version to latest `0.40` -> `0.41` ([#1340](https://github.com/diffplug/spotless/pull/1340)) * Bump default `scalafmt` version to latest `3.5.9` -> `3.6.1` ([#1373](https://github.com/diffplug/spotless/pull/1373)) diff --git a/plugin-gradle/CHANGES.md b/plugin-gradle/CHANGES.md index 2060e5e90c..a4aa656c3f 100644 --- a/plugin-gradle/CHANGES.md +++ b/plugin-gradle/CHANGES.md @@ -10,6 +10,7 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format ( ### Fixed * Don't treat `@Value` as a type annotation [#1367](https://github.com/diffplug/spotless/pull/1367) * Support `ktlint_disabled_rules` in `ktlint` 0.47.x [#1378](https://github.com/diffplug/spotless/pull/1378) +* Share git repositories across projects when using ratchet ([#1426](https://github.com/diffplug/spotless/pull/1426)) ### Changes * Bump default `ktfmt` version to latest `0.40` -> `0.41` ([#1340](https://github.com/diffplug/spotless/pull/1340)) * Bump default `scalafmt` version to latest `3.5.9` -> `3.6.1` ([#1373](https://github.com/diffplug/spotless/pull/1373)) diff --git a/plugin-maven/CHANGES.md b/plugin-maven/CHANGES.md index 9baefc2ec8..6b7d3e40d2 100644 --- a/plugin-maven/CHANGES.md +++ b/plugin-maven/CHANGES.md @@ -10,6 +10,7 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format ( ### Fixed * Don't treat `@Value` as a type annotation [#1367](https://github.com/diffplug/spotless/pull/1367) * Support `ktlint_disabled_rules` in `ktlint` 0.47.x [#1378](https://github.com/diffplug/spotless/pull/1378) +* Share git repositories across projects when using ratchet ([#1426](https://github.com/diffplug/spotless/pull/1426)) ### Changes * Bump default `ktfmt` version to latest `0.40` -> `0.41` ([#1340](https://github.com/diffplug/spotless/pull/1340)) * Bump default `scalafmt` version to latest `3.5.9` -> `3.6.1` ([#1373](https://github.com/diffplug/spotless/pull/1373)) From fd6cd9a36ef70f68a128169e93d3430604101b94 Mon Sep 17 00:00:00 2001 From: Laurent Goujon Date: Thu, 15 Dec 2022 15:14:31 -0800 Subject: [PATCH 371/757] Add missing typo --- _ext/eclipse-cdt/build.gradle | 2 +- _ext/eclipse-cdt/gradle.properties | 2 +- _ext/eclipse-groovy/build.gradle | 2 +- _ext/eclipse-groovy/gradle.properties | 2 +- _ext/eclipse-jdt/build.gradle | 2 +- _ext/eclipse-jdt/gradle.properties | 2 +- _ext/eclipse-wtp/build.gradle | 2 +- _ext/eclipse-wtp/gradle.properties | 2 +- 8 files changed, 8 insertions(+), 8 deletions(-) diff --git a/_ext/eclipse-cdt/build.gradle b/_ext/eclipse-cdt/build.gradle index 93ccac3b24..0982b7d555 100644 --- a/_ext/eclipse-cdt/build.gradle +++ b/_ext/eclipse-cdt/build.gradle @@ -17,7 +17,7 @@ apply from: rootProject.file('gradle/java-publish.gradle') dependencies { - implementation "com.diffplug.spotless:spotless-eclipse-base:${VER_SPOTLESS_ECLISPE_BASE}" + implementation "com.diffplug.spotless:spotless-eclipse-base:${VER_SPOTLESS_ECLIPSE_BASE}" // Provides text partitioners for formatters implementation ("org.eclipse.platform:org.eclipse.jface.text:${VER_ECLIPSE_JFACE}") { exclude group: 'org.eclipse.platform', module: 'org.eclipse.swt' diff --git a/_ext/eclipse-cdt/gradle.properties b/_ext/eclipse-cdt/gradle.properties index 10166b51d0..821ceea4d1 100644 --- a/_ext/eclipse-cdt/gradle.properties +++ b/_ext/eclipse-cdt/gradle.properties @@ -6,7 +6,7 @@ VER_JAVA=11 # Compile dependencies VER_ECLIPSE_CDT=10.5 -VER_SPOTLESS_ECLISPE_BASE=[3.5.0,4.0.0[ +VER_SPOTLESS_ECLIPSE_BASE=[3.5.0,4.0.0[ VER_ECLIPSE_JFACE=[3.18.0,4.0.0[ VER_ECLIPSE_EFS=[3.7.0,4.0.0[ VER_IBM_ICU=[67.1,68[ diff --git a/_ext/eclipse-groovy/build.gradle b/_ext/eclipse-groovy/build.gradle index 00a7fed489..a45590fada 100644 --- a/_ext/eclipse-groovy/build.gradle +++ b/_ext/eclipse-groovy/build.gradle @@ -39,7 +39,7 @@ apply from: rootProject.file('_ext/gradle/p2-fat-jar-setup.gradle') apply from: rootProject.file('gradle/java-publish.gradle') dependencies { - implementation "com.diffplug.spotless:spotless-eclipse-base:${VER_SPOTLESS_ECLISPE_BASE}" + implementation "com.diffplug.spotless:spotless-eclipse-base:${VER_SPOTLESS_ECLIPSE_BASE}" // Provides text partitioners for formatters implementation ("org.eclipse.platform:org.eclipse.jface.text:${VER_ECLIPSE_JFACE}") { exclude group: 'org.eclipse.platform', module: 'org.eclipse.swt' diff --git a/_ext/eclipse-groovy/gradle.properties b/_ext/eclipse-groovy/gradle.properties index 9569e765bc..c1c6101caa 100644 --- a/_ext/eclipse-groovy/gradle.properties +++ b/_ext/eclipse-groovy/gradle.properties @@ -6,7 +6,7 @@ VER_JAVA=11 # Compile VER_ECLIPSE=4.21 -VER_SPOTLESS_ECLISPE_BASE=[3.4.2,4.0.0[ +VER_SPOTLESS_ECLIPSE_BASE=[3.4.2,4.0.0[ VER_ECLIPSE_JFACE=[3.15.300,4.0.0[ VER_GRECLIPSE=4.3.0 VER_GROOVY=4.0.0 diff --git a/_ext/eclipse-jdt/build.gradle b/_ext/eclipse-jdt/build.gradle index b0967822a9..283e52f86d 100644 --- a/_ext/eclipse-jdt/build.gradle +++ b/_ext/eclipse-jdt/build.gradle @@ -10,7 +10,7 @@ ext { } dependencies { - implementation "com.diffplug.spotless:spotless-eclipse-base:${VER_SPOTLESS_ECLISPE_BASE}" + implementation "com.diffplug.spotless:spotless-eclipse-base:${VER_SPOTLESS_ECLIPSE_BASE}" implementation("org.eclipse.jdt:org.eclipse.jdt.core:${VER_ECLIPSE_JDT_CORE}") { exclude group: 'org.eclipse.platform', module: 'org.eclipse.ant.core' exclude group: 'org.eclipse.platform', module: 'org.eclipse.core.expressions' diff --git a/_ext/eclipse-jdt/gradle.properties b/_ext/eclipse-jdt/gradle.properties index 82a4423140..51d5f41014 100644 --- a/_ext/eclipse-jdt/gradle.properties +++ b/_ext/eclipse-jdt/gradle.properties @@ -6,4 +6,4 @@ VER_JAVA=11 # Compile VER_ECLIPSE_JDT_CORE=[3.13.0,4.0.0[ -VER_SPOTLESS_ECLISPE_BASE=[3.5.0,4.0.0[ +VER_SPOTLESS_ECLIPSE_BASE=[3.5.0,4.0.0[ diff --git a/_ext/eclipse-wtp/build.gradle b/_ext/eclipse-wtp/build.gradle index ba32385a1b..92a78578f6 100644 --- a/_ext/eclipse-wtp/build.gradle +++ b/_ext/eclipse-wtp/build.gradle @@ -60,7 +60,7 @@ apply from: rootProject.file('_ext/gradle/p2-fat-jar-setup.gradle') apply from: rootProject.file('gradle/java-publish.gradle') dependencies { - implementation "com.diffplug.spotless:spotless-eclipse-base:${VER_SPOTLESS_ECLISPE_BASE}" + implementation "com.diffplug.spotless:spotless-eclipse-base:${VER_SPOTLESS_ECLIPSE_BASE}" // Required by most WPT formatters implementation "com.ibm.icu:icu4j:${VER_IBM_ICU}" // The XSD/DTD and other models are defined with EMF. diff --git a/_ext/eclipse-wtp/gradle.properties b/_ext/eclipse-wtp/gradle.properties index f6cedd63e3..a341c0fb49 100644 --- a/_ext/eclipse-wtp/gradle.properties +++ b/_ext/eclipse-wtp/gradle.properties @@ -6,7 +6,7 @@ VER_JAVA=11 # Compile VER_ECLIPSE_WTP=2021-09 -VER_SPOTLESS_ECLISPE_BASE=[3.5.0,4.0.0[ +VER_SPOTLESS_ECLIPSE_BASE=[3.5.0,4.0.0[ VER_IBM_ICU=[67.1,68[ VER_ECLIPSE_EMF=[2.22.0,3.0.0[ VER_ECLIPSE_OSGI_SERVICES=[3.10.0,4.0.0[ From 7949f87aced31c56b6fbc86d9370dd7163816c90 Mon Sep 17 00:00:00 2001 From: Laurent Goujon Date: Thu, 15 Dec 2022 15:11:01 -0800 Subject: [PATCH 372/757] Update CHANGES.md --- _ext/eclipse-cdt/CHANGES.md | 2 ++ _ext/eclipse-groovy/CHANGES.md | 2 ++ _ext/eclipse-wtp/CHANGES.md | 2 ++ 3 files changed, 6 insertions(+) diff --git a/_ext/eclipse-cdt/CHANGES.md b/_ext/eclipse-cdt/CHANGES.md index bdc7d99ea9..cda212bd3d 100644 --- a/_ext/eclipse-cdt/CHANGES.md +++ b/_ext/eclipse-cdt/CHANGES.md @@ -3,6 +3,8 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format (starting after version `9.9.0`). ## [Unreleased] +### Fixed +* Fix typo in gradle variable names ([#1425](https://github.com/diffplug/spotless/pull/1425)) ## [10.5.0] - 2021-12-13 ### Added diff --git a/_ext/eclipse-groovy/CHANGES.md b/_ext/eclipse-groovy/CHANGES.md index c80ce061d5..b0f909ccb2 100644 --- a/_ext/eclipse-groovy/CHANGES.md +++ b/_ext/eclipse-groovy/CHANGES.md @@ -3,6 +3,8 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format (starting after version `3.5.0`). ## [Unreleased] +### Fixed +* Fix typo in gradle variable names ([#1425](https://github.com/diffplug/spotless/pull/1425)) ## [4.3.0] - 2021-10-13 ### Added diff --git a/_ext/eclipse-wtp/CHANGES.md b/_ext/eclipse-wtp/CHANGES.md index 6fc919aa0e..0001618b1f 100644 --- a/_ext/eclipse-wtp/CHANGES.md +++ b/_ext/eclipse-wtp/CHANGES.md @@ -3,6 +3,8 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format (starting after version `3.15.1`). ## [Unreleased] +### Fixed +* Fix typo in gradle variable names ([#1425](https://github.com/diffplug/spotless/pull/1425)) ## [3.23.0] - 2021-09-22 ### Added From 38ca03bd1613bbfb368f45dabbe21b109aba0162 Mon Sep 17 00:00:00 2001 From: Ned Twigg Date: Sun, 18 Dec 2022 10:20:11 -0800 Subject: [PATCH 373/757] spotlessApply --- build.gradle | 2 +- .../diffplug/spotless/extra/GitRatchet.java | 18 +++++++++--------- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/build.gradle b/build.gradle index 5766e6b85e..f9e3d0de21 100644 --- a/build.gradle +++ b/build.gradle @@ -18,4 +18,4 @@ spotless { trimTrailingWhitespace() endWithNewline() } -} +} \ No newline at end of file diff --git a/lib-extra/src/main/java/com/diffplug/spotless/extra/GitRatchet.java b/lib-extra/src/main/java/com/diffplug/spotless/extra/GitRatchet.java index 3b0e3c06ed..4ba59e6aa5 100644 --- a/lib-extra/src/main/java/com/diffplug/spotless/extra/GitRatchet.java +++ b/lib-extra/src/main/java/com/diffplug/spotless/extra/GitRatchet.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. @@ -138,7 +138,7 @@ private static boolean worktreeIsCleanCheckout(TreeWalk treeWalk) { private final static int WORKDIR = 2; Map gitRoots = new HashMap<>(); - Map gitRepositories = new HashMap<>(); + Map gitRepositories = new HashMap<>(); Table rootTreeShaCache = HashBasedTable.create(); Map subtreeShaCache = new HashMap<>(); @@ -192,13 +192,13 @@ private static boolean isGitRoot(File dir) { } Repository createRepo(File dir) throws IOException { - File dotGitDir = GitWorkarounds.getDotGitDir(dir); - Repository repo = gitRepositories.get(dotGitDir); - if (repo == null) { - repo = FileRepositoryBuilder.create(dotGitDir); - gitRepositories.put(dotGitDir, repo); - } - return repo; + File dotGitDir = GitWorkarounds.getDotGitDir(dir); + Repository repo = gitRepositories.get(dotGitDir); + if (repo == null) { + repo = FileRepositoryBuilder.create(dotGitDir); + gitRepositories.put(dotGitDir, repo); + } + return repo; } /** From a4d552625952b62dd28e2e59fa6f76d179426091 Mon Sep 17 00:00:00 2001 From: Laurent Goujon Date: Mon, 19 Dec 2022 10:47:37 -0800 Subject: [PATCH 374/757] Simplify GitRatchet cache logic Change GitRatchet cache logic to use git root instead of projects as a caching key for FileRepository. --- .../diffplug/spotless/extra/GitRatchet.java | 55 +++---------------- 1 file changed, 8 insertions(+), 47 deletions(-) diff --git a/lib-extra/src/main/java/com/diffplug/spotless/extra/GitRatchet.java b/lib-extra/src/main/java/com/diffplug/spotless/extra/GitRatchet.java index 4ba59e6aa5..31f2f597f9 100644 --- a/lib-extra/src/main/java/com/diffplug/spotless/extra/GitRatchet.java +++ b/lib-extra/src/main/java/com/diffplug/spotless/extra/GitRatchet.java @@ -19,7 +19,6 @@ import java.io.IOException; import java.util.HashMap; import java.util.Map; -import java.util.Objects; import java.util.Optional; import javax.annotation.Nullable; @@ -137,8 +136,7 @@ private static boolean worktreeIsCleanCheckout(TreeWalk treeWalk) { private final static int INDEX = 1; private final static int WORKDIR = 2; - Map gitRoots = new HashMap<>(); - Map gitRepositories = new HashMap<>(); + Map gitRoots = new HashMap<>(); Table rootTreeShaCache = HashBasedTable.create(); Map subtreeShaCache = new HashMap<>(); @@ -148,25 +146,14 @@ private static boolean worktreeIsCleanCheckout(TreeWalk treeWalk) { * We cache the Repository for every Project in {@code gitRoots}, and use dynamic programming to populate it. */ protected Repository repositoryFor(Project project) throws IOException { - Repository repo = gitRoots.get(project); + File projectGitDir = GitWorkarounds.getDotGitDir(getDir(project)); + if (projectGitDir == null || !RepositoryCache.FileKey.isGitRepository(projectGitDir, FS.DETECTED)) { + throw new IllegalArgumentException("Cannot find git repository in any parent directory"); + } + Repository repo = gitRoots.get(projectGitDir); if (repo == null) { - if (isGitRoot(getDir(project))) { - repo = createRepo(getDir(project)); - } else { - Project parentProj = getParent(project); - if (parentProj == null) { - repo = traverseParentsUntil(getDir(project).getParentFile(), null); - if (repo == null) { - throw new IllegalArgumentException("Cannot find git repository in any parent directory"); - } - } else { - repo = traverseParentsUntil(getDir(project).getParentFile(), getDir(parentProj)); - if (repo == null) { - repo = repositoryFor(parentProj); - } - } - } - gitRoots.put(project, repo); + repo = FileRepositoryBuilder.create(projectGitDir); + gitRoots.put(projectGitDir, repo); } return repo; } @@ -175,32 +162,6 @@ protected Repository repositoryFor(Project project) throws IOException { protected abstract @Nullable Project getParent(Project project); - private @Nullable Repository traverseParentsUntil(File startWith, @Nullable File file) throws IOException { - while (startWith != null && !Objects.equals(startWith, file)) { - if (isGitRoot(startWith)) { - return createRepo(startWith); - } else { - startWith = startWith.getParentFile(); - } - } - return null; - } - - private static boolean isGitRoot(File dir) { - File dotGit = GitWorkarounds.getDotGitDir(dir); - return dotGit != null && RepositoryCache.FileKey.isGitRepository(dotGit, FS.DETECTED); - } - - Repository createRepo(File dir) throws IOException { - File dotGitDir = GitWorkarounds.getDotGitDir(dir); - Repository repo = gitRepositories.get(dotGitDir); - if (repo == null) { - repo = FileRepositoryBuilder.create(dotGitDir); - gitRepositories.put(dotGitDir, repo); - } - return repo; - } - /** * Fast way to return treeSha of the given ref against the git repository which stores the given project. * Because of parallel project evaluation, there may be races here, so we synchronize on ourselves. However, this method From 079257aa340e5ace264eb63cddda6260ddc7ee79 Mon Sep 17 00:00:00 2001 From: "renovate[bot]" <29139614+renovate[bot]@users.noreply.github.com> Date: Wed, 28 Dec 2022 16:25:37 +0000 Subject: [PATCH 375/757] fix(deps): update dependency org.mockito:mockito-core to v4.11.0 --- gradle.properties | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gradle.properties b/gradle.properties index fc2b2b43da..577ed87535 100644 --- a/gradle.properties +++ b/gradle.properties @@ -28,7 +28,7 @@ VER_DURIAN=1.2.0 VER_JGIT=5.13.1.202206130422-r VER_JUNIT=5.9.1 VER_ASSERTJ=3.23.1 -VER_MOCKITO=4.9.0 +VER_MOCKITO=4.11.0 # Used for Maven Plugin VER_MAVEN_API=3.0 From e19bc6739c12c440e1b850bfba8e8b0876f6148d Mon Sep 17 00:00:00 2001 From: Abel Keszei Date: Fri, 30 Dec 2022 11:44:58 +0100 Subject: [PATCH 376/757] add support for skipping first few lines matching a pattern --- .../spotless/generic/LicenseHeaderStep.java | 69 ++++++++++++++----- .../gradle/spotless/FormatExtension.java | 6 ++ 2 files changed, 57 insertions(+), 18 deletions(-) diff --git a/lib/src/main/java/com/diffplug/spotless/generic/LicenseHeaderStep.java b/lib/src/main/java/com/diffplug/spotless/generic/LicenseHeaderStep.java index 6a34c08828..5345adc150 100644 --- a/lib/src/main/java/com/diffplug/spotless/generic/LicenseHeaderStep.java +++ b/lib/src/main/java/com/diffplug/spotless/generic/LicenseHeaderStep.java @@ -51,7 +51,7 @@ public static LicenseHeaderStep headerDelimiter(String header, String delimiter) } public static LicenseHeaderStep headerDelimiter(ThrowingEx.Supplier headerLazy, String delimiter) { - return new LicenseHeaderStep(null, null, headerLazy, delimiter, DEFAULT_YEAR_DELIMITER, () -> YearMode.PRESERVE); + return new LicenseHeaderStep(null, null, headerLazy, delimiter, DEFAULT_YEAR_DELIMITER, () -> YearMode.PRESERVE, null); } final String name; @@ -60,14 +60,16 @@ public static LicenseHeaderStep headerDelimiter(ThrowingEx.Supplier head final String delimiter; final String yearSeparator; final Supplier yearMode; + final @Nullable String skipLinesPattern; - private LicenseHeaderStep(@Nullable String name, @Nullable String contentPattern, ThrowingEx.Supplier headerLazy, String delimiter, String yearSeparator, Supplier yearMode) { + private LicenseHeaderStep(@Nullable String name, @Nullable String contentPattern, ThrowingEx.Supplier headerLazy, String delimiter, String yearSeparator, Supplier yearMode, @Nullable String skipLinesPattern) { this.name = sanitizeName(name); - this.contentPattern = sanitizeContentPattern(contentPattern); + this.contentPattern = sanitizePattern(contentPattern); this.headerLazy = Objects.requireNonNull(headerLazy); this.delimiter = Objects.requireNonNull(delimiter); this.yearSeparator = Objects.requireNonNull(yearSeparator); this.yearMode = Objects.requireNonNull(yearMode); + this.skipLinesPattern = sanitizePattern(skipLinesPattern); } public String getName() { @@ -75,11 +77,11 @@ public String getName() { } public LicenseHeaderStep withName(String name) { - return new LicenseHeaderStep(name, contentPattern, headerLazy, delimiter, yearSeparator, yearMode); + return new LicenseHeaderStep(name, contentPattern, headerLazy, delimiter, yearSeparator, yearMode, skipLinesPattern); } public LicenseHeaderStep withContentPattern(String contentPattern) { - return new LicenseHeaderStep(name, contentPattern, headerLazy, delimiter, yearSeparator, yearMode); + return new LicenseHeaderStep(name, contentPattern, headerLazy, delimiter, yearSeparator, yearMode, skipLinesPattern); } public LicenseHeaderStep withHeaderString(String header) { @@ -87,15 +89,15 @@ public LicenseHeaderStep withHeaderString(String header) { } public LicenseHeaderStep withHeaderLazy(ThrowingEx.Supplier headerLazy) { - return new LicenseHeaderStep(name, contentPattern, headerLazy, delimiter, yearSeparator, yearMode); + return new LicenseHeaderStep(name, contentPattern, headerLazy, delimiter, yearSeparator, yearMode, skipLinesPattern); } public LicenseHeaderStep withDelimiter(String delimiter) { - return new LicenseHeaderStep(name, contentPattern, headerLazy, delimiter, yearSeparator, yearMode); + return new LicenseHeaderStep(name, contentPattern, headerLazy, delimiter, yearSeparator, yearMode, skipLinesPattern); } public LicenseHeaderStep withYearSeparator(String yearSeparator) { - return new LicenseHeaderStep(name, contentPattern, headerLazy, delimiter, yearSeparator, yearMode); + return new LicenseHeaderStep(name, contentPattern, headerLazy, delimiter, yearSeparator, yearMode, skipLinesPattern); } public LicenseHeaderStep withYearMode(YearMode yearMode) { @@ -103,7 +105,11 @@ public LicenseHeaderStep withYearMode(YearMode yearMode) { } public LicenseHeaderStep withYearModeLazy(Supplier yearMode) { - return new LicenseHeaderStep(name, contentPattern, headerLazy, delimiter, yearSeparator, yearMode); + return new LicenseHeaderStep(name, contentPattern, headerLazy, delimiter, yearSeparator, yearMode, skipLinesPattern); + } + + public LicenseHeaderStep withSkipLinesPattern(String skipLinesPattern) { + return new LicenseHeaderStep(name, contentPattern, headerLazy, delimiter, yearSeparator, yearMode, skipLinesPattern); } public FormatterStep build() { @@ -112,7 +118,7 @@ public FormatterStep build() { if (yearMode.get() == YearMode.SET_FROM_GIT) { formatterStep = FormatterStep.createNeverUpToDateLazy(name, () -> { boolean updateYear = false; // doesn't matter - Runtime runtime = new Runtime(headerLazy.get(), delimiter, yearSeparator, updateYear); + Runtime runtime = new Runtime(headerLazy.get(), delimiter, yearSeparator, updateYear, skipLinesPattern); return FormatterFunc.needsFile(runtime::setLicenseHeaderYearsFromGitHistory); }); } else { @@ -130,7 +136,7 @@ public FormatterStep build() { default: throw new IllegalStateException(yearMode.toString()); } - return new Runtime(headerLazy.get(), delimiter, yearSeparator, updateYear); + return new Runtime(headerLazy.get(), delimiter, yearSeparator, updateYear, skipLinesPattern); }, step -> step::format); } @@ -156,18 +162,18 @@ private String sanitizeName(@Nullable String name) { } @Nullable - private String sanitizeContentPattern(@Nullable String contentPattern) { - if (contentPattern == null) { - return contentPattern; + private String sanitizePattern(@Nullable String pattern) { + if (pattern == null) { + return pattern; } - contentPattern = contentPattern.trim(); + pattern = pattern.trim(); - if (contentPattern.isEmpty()) { + if (pattern.isEmpty()) { return null; } - return contentPattern; + return pattern; } private static final String DEFAULT_NAME_PREFIX = LicenseHeaderStep.class.getName(); @@ -195,6 +201,7 @@ private static class Runtime implements Serializable { private static final long serialVersionUID = 1475199492829130965L; private final Pattern delimiterPattern; + private final @Nullable Pattern skipLinesPattern; private final String yearSepOrFull; private final @Nullable String yearToday; private final @Nullable String beforeYear; @@ -203,7 +210,7 @@ private static class Runtime implements Serializable { private final boolean licenseHeaderWithRange; /** The license that we'd like enforced. */ - private Runtime(String licenseHeader, String delimiter, String yearSeparator, boolean updateYearWithLatest) { + private Runtime(String licenseHeader, String delimiter, String yearSeparator, boolean updateYearWithLatest, @Nullable String skipLinesPattern) { if (delimiter.contains("\n")) { throw new IllegalArgumentException("The delimiter must not contain any newlines."); } @@ -213,6 +220,7 @@ private Runtime(String licenseHeader, String delimiter, String yearSeparator, bo licenseHeader = licenseHeader + "\n"; } this.delimiterPattern = Pattern.compile('^' + delimiter, Pattern.UNIX_LINES | Pattern.MULTILINE); + this.skipLinesPattern = skipLinesPattern == null ? null : Pattern.compile(skipLinesPattern); Optional yearToken = getYearToken(licenseHeader); if (yearToken.isPresent()) { @@ -254,6 +262,31 @@ private static Optional getYearToken(String licenseHeader) { /** Formats the given string. */ private String format(String raw) { + if (skipLinesPattern == null) { + return addOrUpdateLicenseHeader(raw); + } else { + String[] lines = raw.split("\n"); + StringBuilder skippedLinesBuilder = new StringBuilder(); + StringBuilder remainingLinesBuilder = new StringBuilder(); + boolean lastMatched = true; + for (String line : lines) { + if (lastMatched) { + Matcher matcher = skipLinesPattern.matcher(line); + if (matcher.find()) { + skippedLinesBuilder.append(line).append('\n'); + } else { + remainingLinesBuilder.append(line).append('\n'); + lastMatched = false; + } + } else { + remainingLinesBuilder.append(line).append('\n'); + } + } + return skippedLinesBuilder + addOrUpdateLicenseHeader(remainingLinesBuilder.toString()); + } + } + + private String addOrUpdateLicenseHeader(String raw) { Matcher contentMatcher = delimiterPattern.matcher(raw); if (!contentMatcher.find()) { throw new IllegalArgumentException("Unable to find delimiter regex " + delimiterPattern); 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 de0313eab4..84690bf063 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 @@ -462,6 +462,12 @@ public LicenseHeaderConfig yearSeparator(String yearSeparator) { return this; } + public LicenseHeaderConfig skipLinesPattern(String skipLinesPattern) { + builder = builder.withSkipLinesPattern(skipLinesPattern); + replaceStep(createStep()); + return this; + } + /** * @param updateYearWithLatest * Will turn {@code 2004} into {@code 2004-2020}, and {@code 2004-2019} into {@code 2004-2020} From e46b9a1a3b4581085d50d6002a2a78e3790b96e2 Mon Sep 17 00:00:00 2001 From: Ned Twigg Date: Sat, 31 Dec 2022 01:09:30 -0800 Subject: [PATCH 377/757] Fix changelogs. --- CHANGES.md | 2 ++ plugin-gradle/CHANGES.md | 3 ++- plugin-maven/CHANGES.md | 2 ++ 3 files changed, 6 insertions(+), 1 deletion(-) diff --git a/CHANGES.md b/CHANGES.md index b781dacb6d..a59f0c8570 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -10,6 +10,8 @@ This document is intended for Spotless developers. We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format (starting after version `1.27.0`). ## [Unreleased] +### Fixed +* Improve memory usage when using git ratchet ([#1426](https://github.com/diffplug/spotless/pull/1426)) ## [2.31.0] - 2022-11-24 ### Added diff --git a/plugin-gradle/CHANGES.md b/plugin-gradle/CHANGES.md index a4aa656c3f..ebe7d0ceea 100644 --- a/plugin-gradle/CHANGES.md +++ b/plugin-gradle/CHANGES.md @@ -3,6 +3,8 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format (starting after version `3.27.0`). ## [Unreleased] +### Fixed +* Improve memory usage when using git ratchet ([#1426](https://github.com/diffplug/spotless/pull/1426)) ## [6.12.0] - 2022-11-24 ### Added @@ -10,7 +12,6 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format ( ### Fixed * Don't treat `@Value` as a type annotation [#1367](https://github.com/diffplug/spotless/pull/1367) * Support `ktlint_disabled_rules` in `ktlint` 0.47.x [#1378](https://github.com/diffplug/spotless/pull/1378) -* Share git repositories across projects when using ratchet ([#1426](https://github.com/diffplug/spotless/pull/1426)) ### Changes * Bump default `ktfmt` version to latest `0.40` -> `0.41` ([#1340](https://github.com/diffplug/spotless/pull/1340)) * Bump default `scalafmt` version to latest `3.5.9` -> `3.6.1` ([#1373](https://github.com/diffplug/spotless/pull/1373)) diff --git a/plugin-maven/CHANGES.md b/plugin-maven/CHANGES.md index 6b7d3e40d2..07903bfae1 100644 --- a/plugin-maven/CHANGES.md +++ b/plugin-maven/CHANGES.md @@ -3,6 +3,8 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format (starting after version `1.27.0`). ## [Unreleased] +### Fixed +* Improve memory usage when using git ratchet ([#1426](https://github.com/diffplug/spotless/pull/1426)) ## [2.28.0] - 2022-11-24 ### Added From 9580038f011220a9a1047ac77f33649709d04c12 Mon Sep 17 00:00:00 2001 From: "renovate[bot]" <29139614+renovate[bot]@users.noreply.github.com> Date: Sat, 31 Dec 2022 09:27:29 +0000 Subject: [PATCH 378/757] chore(deps): update plugin io.github.davidburstrom.version-compatibility to v0.3.0 --- settings.gradle | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/settings.gradle b/settings.gradle index eb818a2c0e..828a3629c7 100644 --- a/settings.gradle +++ b/settings.gradle @@ -16,7 +16,7 @@ pluginManagement { // https://github.com/radarsh/gradle-test-logger-plugin/blob/develop/CHANGELOG.md id 'com.adarshr.test-logger' version '3.2.0' // https://github.com/davidburstrom/version-compatibility-gradle-plugin/tags - id 'io.github.davidburstrom.version-compatibility' version '0.1.0' + id 'io.github.davidburstrom.version-compatibility' version '0.3.0' } } plugins { From 46e8db412f261542f696db895430ef7edcd16039 Mon Sep 17 00:00:00 2001 From: Ned Twigg Date: Sat, 31 Dec 2022 01:52:24 -0800 Subject: [PATCH 379/757] Add missing changelog entry for #1414 and #1413 --- plugin-maven/CHANGES.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/plugin-maven/CHANGES.md b/plugin-maven/CHANGES.md index 07903bfae1..e1c6b8ce48 100644 --- a/plugin-maven/CHANGES.md +++ b/plugin-maven/CHANGES.md @@ -3,6 +3,8 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format (starting after version `1.27.0`). ## [Unreleased] +### Added +* Added support for M2E's incremental compilation ([#1414](https://github.com/diffplug/spotless/pull/1414) fixes [#1413](https://github.com/diffplug/spotless/issues/1413)) ### Fixed * Improve memory usage when using git ratchet ([#1426](https://github.com/diffplug/spotless/pull/1426)) From 18fd936aac915cbcb6bb7aa1e110ce6504d9a306 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?David=20Burstr=C3=B6m?= Date: Sun, 1 Jan 2023 13:01:31 +0100 Subject: [PATCH 380/757] Fix the documentation so that it looks sane in Vim too --- CONTRIBUTING.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index bf1996778d..782e377d58 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -36,7 +36,7 @@ For the folders below in monospace text, they are published on maven central at | `lib-extra` | Contains the optional parts of Spotless which require external dependencies. `LineEnding.GIT_ATTRIBUTES` won't work unless `lib-extra` is available. | | `plugin-gradle` | Integrates spotless and all of its formatters into Gradle. | | `plugin-maven` | Integrates spotless and all of its formatters into Maven. | -| _ext | Folder for generating glue jars (specifically packaging Eclipse jars from p2 for consumption using maven). +| `_ext` | Folder for generating glue jars (specifically packaging Eclipse jars from p2 for consumption using maven). ## How to add a new FormatterStep @@ -119,7 +119,7 @@ There are many great formatters (prettier, clang-format, black, etc.) which live Because of Spotless' up-to-date checking and [git ratcheting](https://github.com/diffplug/spotless/tree/main/plugin-gradle#ratchet), Spotless actually doesn't have to call formatters very often, so even an expensive shell call for every single invocation isn't that bad. Anything that works is better than nothing, and we can always speed things up later if it feels too slow (but it probably won't). -## How to enable the _ext projects +## How to enable the `_ext` projects The `_ext` projects are disabled per default, since: From 918547f92cc6f1140f5f1bd889b6062440861199 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?David=20Burstr=C3=B6m?= Date: Tue, 20 Dec 2022 22:27:14 +0100 Subject: [PATCH 381/757] Add support for KtLint 0.48.0 (fixes #1430) --- CHANGES.md | 3 + lib/build.gradle | 4 + .../compat/KtLintCompat0Dot48Dot0Adapter.java | 121 ++++++++++++++++++ .../glue/ktlint/KtlintFormatterFunc.java | 6 +- .../diffplug/spotless/kotlin/KtLintStep.java | 2 +- plugin-gradle/CHANGES.md | 2 + plugin-maven/CHANGES.md | 3 + .../spotless/kotlin/KtLintStepTest.java | 13 ++ 8 files changed, 152 insertions(+), 2 deletions(-) create mode 100644 lib/src/compatKtLint0Dot48Dot0/java/com/diffplug/spotless/glue/ktlint/compat/KtLintCompat0Dot48Dot0Adapter.java diff --git a/CHANGES.md b/CHANGES.md index a59f0c8570..171924a35f 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -12,6 +12,9 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format ( ## [Unreleased] ### Fixed * Improve memory usage when using git ratchet ([#1426](https://github.com/diffplug/spotless/pull/1426)) +* Support `ktlint` 0.48+ ([#1432](https://github.com/diffplug/spotless/pull/1432)) fixes ([#1430](https://github.com/diffplug/spotless/issues/1430)) +### Changes +* Bump default `ktlint` version to latest `0.47.1` -> `0.48.0` ([#1432](https://github.com/diffplug/spotless/pull/1432)) ## [2.31.0] - 2022-11-24 ### Added diff --git a/lib/build.gradle b/lib/build.gradle index e398e80d23..8a816c61aa 100644 --- a/lib/build.gradle +++ b/lib/build.gradle @@ -34,6 +34,7 @@ versionCompatibility { '0.45.2', '0.46.0', '0.47.0', + '0.48.0', ] targetSourceSetName = 'ktlint' } @@ -90,6 +91,9 @@ dependencies { compatKtLint0Dot47Dot0CompileOnly 'com.pinterest.ktlint:ktlint-core:0.47.0' compatKtLint0Dot47Dot0CompileOnly 'com.pinterest.ktlint:ktlint-ruleset-experimental:0.47.0' compatKtLint0Dot47Dot0CompileOnly 'com.pinterest.ktlint:ktlint-ruleset-standard:0.47.0' + compatKtLint0Dot48Dot0CompileOnly 'com.pinterest.ktlint:ktlint-core:0.48.0' + compatKtLint0Dot48Dot0CompileOnly 'com.pinterest.ktlint:ktlint-ruleset-experimental:0.48.0' + compatKtLint0Dot48Dot0CompileOnly 'com.pinterest.ktlint:ktlint-ruleset-standard:0.48.0' String VER_SCALAFMT="3.6.1" scalafmtCompileOnly "org.scalameta:scalafmt-core_2.13:$VER_SCALAFMT" diff --git a/lib/src/compatKtLint0Dot48Dot0/java/com/diffplug/spotless/glue/ktlint/compat/KtLintCompat0Dot48Dot0Adapter.java b/lib/src/compatKtLint0Dot48Dot0/java/com/diffplug/spotless/glue/ktlint/compat/KtLintCompat0Dot48Dot0Adapter.java new file mode 100644 index 0000000000..8235c535a5 --- /dev/null +++ b/lib/src/compatKtLint0Dot48Dot0/java/com/diffplug/spotless/glue/ktlint/compat/KtLintCompat0Dot48Dot0Adapter.java @@ -0,0 +1,121 @@ +/* + * Copyright 2023 DiffPlug + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.diffplug.spotless.glue.ktlint.compat; + +import java.util.LinkedHashSet; +import java.util.List; +import java.util.Map; +import java.util.Objects; +import java.util.Set; +import java.util.stream.Collectors; +import java.util.stream.Stream; + +import com.pinterest.ktlint.core.KtLint; +import com.pinterest.ktlint.core.LintError; +import com.pinterest.ktlint.core.Rule; +import com.pinterest.ktlint.core.RuleProvider; +import com.pinterest.ktlint.core.api.DefaultEditorConfigProperties; +import com.pinterest.ktlint.core.api.EditorConfigDefaults; +import com.pinterest.ktlint.core.api.EditorConfigOverride; +import com.pinterest.ktlint.core.api.UsesEditorConfigProperties; +import com.pinterest.ktlint.core.api.editorconfig.EditorConfigProperty; +import com.pinterest.ktlint.ruleset.experimental.ExperimentalRuleSetProvider; +import com.pinterest.ktlint.ruleset.standard.StandardRuleSetProvider; + +import kotlin.Pair; +import kotlin.Unit; +import kotlin.jvm.functions.Function2; + +public class KtLintCompat0Dot48Dot0Adapter implements KtLintCompatAdapter { + + static class FormatterCallback implements Function2 { + @Override + public Unit invoke(LintError lint, Boolean corrected) { + if (!corrected) { + KtLintCompatReporting.report(lint.getLine(), lint.getCol(), lint.getRuleId(), lint.getDetail()); + } + return null; + } + } + + @Override + public String format(final String text, final String name, final boolean isScript, + final boolean useExperimental, + final Map userData, + final Map editorConfigOverrideMap) { + final FormatterCallback formatterCallback = new FormatterCallback(); + + Set allRuleProviders = new LinkedHashSet<>( + new StandardRuleSetProvider().getRuleProviders()); + if (useExperimental) { + allRuleProviders.addAll(new ExperimentalRuleSetProvider().getRuleProviders()); + } + + EditorConfigOverride editorConfigOverride; + if (editorConfigOverrideMap.isEmpty()) { + editorConfigOverride = EditorConfigOverride.Companion.getEmptyEditorConfigOverride(); + } else { + editorConfigOverride = createEditorConfigOverride(allRuleProviders.stream().map( + RuleProvider::createNewRuleInstance).collect( + Collectors.toList()), + editorConfigOverrideMap); + } + + return KtLint.INSTANCE.format(new KtLint.ExperimentalParams( + name, + text, + allRuleProviders, + userData, + formatterCallback, + isScript, + false, + EditorConfigDefaults.Companion.getEmptyEditorConfigDefaults(), + editorConfigOverride, + false)); + } + + /** + * Create EditorConfigOverride from user provided parameters. + */ + private static EditorConfigOverride createEditorConfigOverride(final List rules, Map editorConfigOverrideMap) { + // Get properties from rules in the rule sets + Stream> ruleProperties = rules.stream() + .filter(rule -> rule instanceof UsesEditorConfigProperties) + .flatMap(rule -> ((UsesEditorConfigProperties) rule).getEditorConfigProperties().stream()); + + // Create a mapping of properties to their names based on rule properties and default properties + Map> supportedProperties = Stream + .concat(ruleProperties, DefaultEditorConfigProperties.INSTANCE.getEditorConfigProperties().stream()) + .distinct() + .collect(Collectors.toMap(EditorConfigProperty::getName, property -> property)); + + // Create config properties based on provided property names and values + @SuppressWarnings("unchecked") + Pair, ?>[] properties = editorConfigOverrideMap.entrySet().stream() + .map(entry -> { + EditorConfigProperty property = supportedProperties.get(entry.getKey()); + if (property != null) { + return new Pair<>(property, entry.getValue()); + } else { + return null; + } + }) + .filter(Objects::nonNull) + .toArray(Pair[]::new); + + return EditorConfigOverride.Companion.from(properties); + } +} diff --git a/lib/src/ktlint/java/com/diffplug/spotless/glue/ktlint/KtlintFormatterFunc.java b/lib/src/ktlint/java/com/diffplug/spotless/glue/ktlint/KtlintFormatterFunc.java index cc64eb9d66..45c5c5e4cf 100644 --- a/lib/src/ktlint/java/com/diffplug/spotless/glue/ktlint/KtlintFormatterFunc.java +++ b/lib/src/ktlint/java/com/diffplug/spotless/glue/ktlint/KtlintFormatterFunc.java @@ -27,6 +27,7 @@ import com.diffplug.spotless.glue.ktlint.compat.KtLintCompat0Dot45Dot2Adapter; import com.diffplug.spotless.glue.ktlint.compat.KtLintCompat0Dot46Dot0Adapter; import com.diffplug.spotless.glue.ktlint.compat.KtLintCompat0Dot47Dot0Adapter; +import com.diffplug.spotless.glue.ktlint.compat.KtLintCompat0Dot48Dot0Adapter; import com.diffplug.spotless.glue.ktlint.compat.KtLintCompatAdapter; public class KtlintFormatterFunc implements FormatterFunc.NeedsFile { @@ -41,7 +42,10 @@ public class KtlintFormatterFunc implements FormatterFunc.NeedsFile { public KtlintFormatterFunc(String version, boolean isScript, boolean useExperimental, Map userData, Map editorConfigOverrideMap) { int minorVersion = Integer.parseInt(version.split("\\.")[1]); - if (minorVersion >= 47) { + if (minorVersion >= 48) { + // ExperimentalParams lost two constructor arguments, EditorConfigProperty moved to its own class + this.adapter = new KtLintCompat0Dot48Dot0Adapter(); + } else if (minorVersion == 47) { // rename RuleSet to RuleProvider this.adapter = new KtLintCompat0Dot47Dot0Adapter(); } else if (minorVersion >= 46) { diff --git a/lib/src/main/java/com/diffplug/spotless/kotlin/KtLintStep.java b/lib/src/main/java/com/diffplug/spotless/kotlin/KtLintStep.java index 5627913e4a..f62c62b05b 100644 --- a/lib/src/main/java/com/diffplug/spotless/kotlin/KtLintStep.java +++ b/lib/src/main/java/com/diffplug/spotless/kotlin/KtLintStep.java @@ -33,7 +33,7 @@ public class KtLintStep { // prevent direct instantiation private KtLintStep() {} - private static final String DEFAULT_VERSION = "0.47.1"; + private static final String DEFAULT_VERSION = "0.48.0"; static final String NAME = "ktlint"; static final String PACKAGE_PRE_0_32 = "com.github.shyiko"; static final String PACKAGE = "com.pinterest"; diff --git a/plugin-gradle/CHANGES.md b/plugin-gradle/CHANGES.md index ebe7d0ceea..ec06599d20 100644 --- a/plugin-gradle/CHANGES.md +++ b/plugin-gradle/CHANGES.md @@ -12,11 +12,13 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format ( ### Fixed * Don't treat `@Value` as a type annotation [#1367](https://github.com/diffplug/spotless/pull/1367) * Support `ktlint_disabled_rules` in `ktlint` 0.47.x [#1378](https://github.com/diffplug/spotless/pull/1378) +* Support `ktlint` 0.48+ ([#1432](https://github.com/diffplug/spotless/pull/1432)) fixes ([#1430](https://github.com/diffplug/spotless/issues/1430)) ### Changes * Bump default `ktfmt` version to latest `0.40` -> `0.41` ([#1340](https://github.com/diffplug/spotless/pull/1340)) * Bump default `scalafmt` version to latest `3.5.9` -> `3.6.1` ([#1373](https://github.com/diffplug/spotless/pull/1373)) * Bump default `diktat` version to latest `1.2.3` -> `1.2.4.2` ([#1393](https://github.com/diffplug/spotless/pull/1393)) * Bump default `palantir-java-format` version to latest `2.10` -> `2.28` ([#1393](https://github.com/diffplug/spotless/pull/1393)) +* Bump default `ktlint` version to latest `0.47.1` -> `0.48.0` ([#1432](https://github.com/diffplug/spotless/pull/1432)) ## [6.11.0] - 2022-09-14 ### Added diff --git a/plugin-maven/CHANGES.md b/plugin-maven/CHANGES.md index e1c6b8ce48..f401908166 100644 --- a/plugin-maven/CHANGES.md +++ b/plugin-maven/CHANGES.md @@ -7,6 +7,9 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format ( * Added support for M2E's incremental compilation ([#1414](https://github.com/diffplug/spotless/pull/1414) fixes [#1413](https://github.com/diffplug/spotless/issues/1413)) ### Fixed * Improve memory usage when using git ratchet ([#1426](https://github.com/diffplug/spotless/pull/1426)) +* Support `ktlint` 0.48+ ([#1432](https://github.com/diffplug/spotless/pull/1432)) fixes ([#1430](https://github.com/diffplug/spotless/issues/1430)) +### Changes +* Bump default `ktlint` version to latest `0.47.1` -> `0.48.0` ([#1432](https://github.com/diffplug/spotless/pull/1432)) ## [2.28.0] - 2022-11-24 ### Added diff --git a/testlib/src/test/java/com/diffplug/spotless/kotlin/KtLintStepTest.java b/testlib/src/test/java/com/diffplug/spotless/kotlin/KtLintStepTest.java index 71a0979422..3a55a19e92 100644 --- a/testlib/src/test/java/com/diffplug/spotless/kotlin/KtLintStepTest.java +++ b/testlib/src/test/java/com/diffplug/spotless/kotlin/KtLintStepTest.java @@ -144,6 +144,19 @@ void works0_47_1() throws Exception { }); } + @Test + void works0_48_0() throws Exception { + FormatterStep step = KtLintStep.create("0.48.0", TestProvisioner.mavenCentral()); + StepHarness.forStep(step) + .testResource("kotlin/ktlint/basic.dirty", "kotlin/ktlint/basic.clean") + .testResourceException("kotlin/ktlint/unsolvable.dirty", assertion -> { + assertion.isInstanceOf(AssertionError.class); + assertion.hasMessage("Error on line: 1, column: 1\n" + + "rule: no-wildcard-imports\n" + + "Wildcard import"); + }); + } + @Test void equality() throws Exception { new SerializableEqualityTester() { From b3d8e89002c21324f03e896c0d786df3be09839d Mon Sep 17 00:00:00 2001 From: Ned Twigg Date: Sun, 1 Jan 2023 20:13:05 -0800 Subject: [PATCH 382/757] spotlessApply for 2023 --- .../com/diffplug/spotless/glue/ktlint/KtlintFormatterFunc.java | 2 +- lib/src/main/java/com/diffplug/spotless/kotlin/KtLintStep.java | 2 +- .../test/java/com/diffplug/spotless/kotlin/KtLintStepTest.java | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/src/ktlint/java/com/diffplug/spotless/glue/ktlint/KtlintFormatterFunc.java b/lib/src/ktlint/java/com/diffplug/spotless/glue/ktlint/KtlintFormatterFunc.java index 45c5c5e4cf..fc64cdb23e 100644 --- a/lib/src/ktlint/java/com/diffplug/spotless/glue/ktlint/KtlintFormatterFunc.java +++ b/lib/src/ktlint/java/com/diffplug/spotless/glue/ktlint/KtlintFormatterFunc.java @@ -1,5 +1,5 @@ /* - * Copyright 2021-2022 DiffPlug + * Copyright 2021-2023 DiffPlug * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/lib/src/main/java/com/diffplug/spotless/kotlin/KtLintStep.java b/lib/src/main/java/com/diffplug/spotless/kotlin/KtLintStep.java index f62c62b05b..b444f0f1a7 100644 --- a/lib/src/main/java/com/diffplug/spotless/kotlin/KtLintStep.java +++ b/lib/src/main/java/com/diffplug/spotless/kotlin/KtLintStep.java @@ -1,5 +1,5 @@ /* - * Copyright 2016-2022 DiffPlug + * Copyright 2016-2023 DiffPlug * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/testlib/src/test/java/com/diffplug/spotless/kotlin/KtLintStepTest.java b/testlib/src/test/java/com/diffplug/spotless/kotlin/KtLintStepTest.java index 3a55a19e92..42e377fde5 100644 --- a/testlib/src/test/java/com/diffplug/spotless/kotlin/KtLintStepTest.java +++ b/testlib/src/test/java/com/diffplug/spotless/kotlin/KtLintStepTest.java @@ -1,5 +1,5 @@ /* - * Copyright 2016-2022 DiffPlug + * Copyright 2016-2023 DiffPlug * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. From b44d70d00add006427f3cb8ef2387da543addfa3 Mon Sep 17 00:00:00 2001 From: Ned Twigg Date: Sun, 1 Jan 2023 20:14:22 -0800 Subject: [PATCH 383/757] Move changelog entries to the correct release. --- plugin-gradle/CHANGES.md | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/plugin-gradle/CHANGES.md b/plugin-gradle/CHANGES.md index ec06599d20..3e78920abe 100644 --- a/plugin-gradle/CHANGES.md +++ b/plugin-gradle/CHANGES.md @@ -5,6 +5,9 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format ( ## [Unreleased] ### Fixed * Improve memory usage when using git ratchet ([#1426](https://github.com/diffplug/spotless/pull/1426)) +* Support `ktlint` 0.48+ ([#1432](https://github.com/diffplug/spotless/pull/1432)) fixes ([#1430](https://github.com/diffplug/spotless/issues/1430)) +### Changes +* Bump default `ktlint` version to latest `0.47.1` -> `0.48.0` ([#1432](https://github.com/diffplug/spotless/pull/1432)) ## [6.12.0] - 2022-11-24 ### Added @@ -12,13 +15,11 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format ( ### Fixed * Don't treat `@Value` as a type annotation [#1367](https://github.com/diffplug/spotless/pull/1367) * Support `ktlint_disabled_rules` in `ktlint` 0.47.x [#1378](https://github.com/diffplug/spotless/pull/1378) -* Support `ktlint` 0.48+ ([#1432](https://github.com/diffplug/spotless/pull/1432)) fixes ([#1430](https://github.com/diffplug/spotless/issues/1430)) ### Changes * Bump default `ktfmt` version to latest `0.40` -> `0.41` ([#1340](https://github.com/diffplug/spotless/pull/1340)) * Bump default `scalafmt` version to latest `3.5.9` -> `3.6.1` ([#1373](https://github.com/diffplug/spotless/pull/1373)) * Bump default `diktat` version to latest `1.2.3` -> `1.2.4.2` ([#1393](https://github.com/diffplug/spotless/pull/1393)) * Bump default `palantir-java-format` version to latest `2.10` -> `2.28` ([#1393](https://github.com/diffplug/spotless/pull/1393)) -* Bump default `ktlint` version to latest `0.47.1` -> `0.48.0` ([#1432](https://github.com/diffplug/spotless/pull/1432)) ## [6.11.0] - 2022-09-14 ### Added From 9a8ccae9ec04ff5e6f37da07cc445242ef69c516 Mon Sep 17 00:00:00 2001 From: Ned Twigg Date: Sun, 1 Jan 2023 20:19:21 -0800 Subject: [PATCH 384/757] Bump default ktfmt 0.41 -> 0.42 --- lib/src/main/java/com/diffplug/spotless/kotlin/KtfmtStep.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 4f84d991bc..242c9c9173 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.41"; + private static final String DEFAULT_VERSION = "0.42"; static final String NAME = "ktfmt"; static final String PACKAGE = "com.facebook"; static final String MAVEN_COORDINATE = PACKAGE + ":ktfmt:"; From 8f7e00594de49856e2c14edf09d89352e0eddd60 Mon Sep 17 00:00:00 2001 From: Ned Twigg Date: Sun, 1 Jan 2023 20:21:01 -0800 Subject: [PATCH 385/757] spotlessApply --- lib/src/main/java/com/diffplug/spotless/kotlin/KtfmtStep.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 242c9c9173..b6f7a533eb 100644 --- a/lib/src/main/java/com/diffplug/spotless/kotlin/KtfmtStep.java +++ b/lib/src/main/java/com/diffplug/spotless/kotlin/KtfmtStep.java @@ -1,5 +1,5 @@ /* - * Copyright 2016-2022 DiffPlug + * Copyright 2016-2023 DiffPlug * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. From 062e83584650be1dd47f5c8485426e8438b05600 Mon Sep 17 00:00:00 2001 From: Ned Twigg Date: Sun, 1 Jan 2023 20:21:13 -0800 Subject: [PATCH 386/757] Bump changelogs. --- CHANGES.md | 1 + plugin-gradle/CHANGES.md | 1 + plugin-maven/CHANGES.md | 1 + 3 files changed, 3 insertions(+) diff --git a/CHANGES.md b/CHANGES.md index 171924a35f..fe37d3e845 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -15,6 +15,7 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format ( * Support `ktlint` 0.48+ ([#1432](https://github.com/diffplug/spotless/pull/1432)) fixes ([#1430](https://github.com/diffplug/spotless/issues/1430)) ### Changes * Bump default `ktlint` version to latest `0.47.1` -> `0.48.0` ([#1432](https://github.com/diffplug/spotless/pull/1432)) +* Bump default `ktfmt` version to latest `0.41` -> `0.42` ([#1421](https://github.com/diffplug/spotless/pull/1421)) ## [2.31.0] - 2022-11-24 ### Added diff --git a/plugin-gradle/CHANGES.md b/plugin-gradle/CHANGES.md index 3e78920abe..6b98d25dc2 100644 --- a/plugin-gradle/CHANGES.md +++ b/plugin-gradle/CHANGES.md @@ -8,6 +8,7 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format ( * Support `ktlint` 0.48+ ([#1432](https://github.com/diffplug/spotless/pull/1432)) fixes ([#1430](https://github.com/diffplug/spotless/issues/1430)) ### Changes * Bump default `ktlint` version to latest `0.47.1` -> `0.48.0` ([#1432](https://github.com/diffplug/spotless/pull/1432)) +* Bump default `ktfmt` version to latest `0.41` -> `0.42` ([#1421](https://github.com/diffplug/spotless/pull/1421)) ## [6.12.0] - 2022-11-24 ### Added diff --git a/plugin-maven/CHANGES.md b/plugin-maven/CHANGES.md index f401908166..e8fc8d3d49 100644 --- a/plugin-maven/CHANGES.md +++ b/plugin-maven/CHANGES.md @@ -10,6 +10,7 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format ( * Support `ktlint` 0.48+ ([#1432](https://github.com/diffplug/spotless/pull/1432)) fixes ([#1430](https://github.com/diffplug/spotless/issues/1430)) ### Changes * Bump default `ktlint` version to latest `0.47.1` -> `0.48.0` ([#1432](https://github.com/diffplug/spotless/pull/1432)) +* Bump default `ktfmt` version to latest `0.41` -> `0.42` ([#1421](https://github.com/diffplug/spotless/pull/1421)) ## [2.28.0] - 2022-11-24 ### Added From 45a3c8a2b13cd223f4ca9cfd0831b7639f12fffd Mon Sep 17 00:00:00 2001 From: Ned Twigg Date: Sun, 1 Jan 2023 20:37:08 -0800 Subject: [PATCH 387/757] Reorder plugin application to keep Gradle 7.6 happy. --- plugin-gradle/build.gradle | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/plugin-gradle/build.gradle b/plugin-gradle/build.gradle index f1b3320b50..ba60eb450f 100644 --- a/plugin-gradle/build.gradle +++ b/plugin-gradle/build.gradle @@ -2,11 +2,11 @@ apply from: rootProject.file('gradle/changelog.gradle') ext.artifactId = project.artifactIdGradle version = spotlessChangelog.versionNext apply plugin: 'java-library' +apply plugin: 'com.gradle.plugin-publish' +apply plugin: 'java-gradle-plugin' apply from: rootProject.file('gradle/java-setup.gradle') apply from: rootProject.file('gradle/spotless-freshmark.gradle') -apply plugin: 'com.gradle.plugin-publish' -apply plugin: 'java-gradle-plugin' dependencies { if (version.endsWith('-SNAPSHOT') || (rootProject.spotlessChangelog.versionNext == rootProject.spotlessChangelog.versionLast)) { From c13acee2130be0b730a14fbadade6e7f597001b7 Mon Sep 17 00:00:00 2001 From: circleci Date: Mon, 2 Jan 2023 04:44:42 +0000 Subject: [PATCH 388/757] Published lib/2.31.1 --- CHANGES.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/CHANGES.md b/CHANGES.md index fe37d3e845..e3493f7c09 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -10,6 +10,8 @@ This document is intended for Spotless developers. We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format (starting after version `1.27.0`). ## [Unreleased] + +## [2.31.1] - 2023-01-02 ### Fixed * Improve memory usage when using git ratchet ([#1426](https://github.com/diffplug/spotless/pull/1426)) * Support `ktlint` 0.48+ ([#1432](https://github.com/diffplug/spotless/pull/1432)) fixes ([#1430](https://github.com/diffplug/spotless/issues/1430)) From 718a504c123de899e75300e7f2f6c55d7a40da42 Mon Sep 17 00:00:00 2001 From: circleci Date: Mon, 2 Jan 2023 04:45:56 +0000 Subject: [PATCH 389/757] Published gradle/6.12.1 --- plugin-gradle/CHANGES.md | 2 ++ plugin-gradle/README.md | 46 ++++++++++++++++++++-------------------- 2 files changed, 25 insertions(+), 23 deletions(-) diff --git a/plugin-gradle/CHANGES.md b/plugin-gradle/CHANGES.md index 6b98d25dc2..cac4f56567 100644 --- a/plugin-gradle/CHANGES.md +++ b/plugin-gradle/CHANGES.md @@ -3,6 +3,8 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format (starting after version `3.27.0`). ## [Unreleased] + +## [6.12.1] - 2023-01-02 ### Fixed * Improve memory usage when using git ratchet ([#1426](https://github.com/diffplug/spotless/pull/1426)) * Support `ktlint` 0.48+ ([#1432](https://github.com/diffplug/spotless/pull/1432)) fixes ([#1430](https://github.com/diffplug/spotless/issues/1430)) diff --git a/plugin-gradle/README.md b/plugin-gradle/README.md index fcc0336cbb..755d21d056 100644 --- a/plugin-gradle/README.md +++ b/plugin-gradle/README.md @@ -18,9 +18,9 @@ output = [ --> [![Gradle plugin](https://img.shields.io/badge/plugins.gradle.org-com.diffplug.spotless-blue.svg)](https://plugins.gradle.org/plugin/com.diffplug.spotless) [![Maven central](https://img.shields.io/badge/mavencentral-yes-blue.svg)](https://search.maven.org/#search%7Cgav%7C1%7Cg%3A%22com.diffplug.spotless%22%20AND%20a%3A%22spotless-plugin-gradle%22) -[![Javadoc](https://img.shields.io/badge/javadoc-yes-blue.svg)](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.12.0/index.html) +[![Javadoc](https://img.shields.io/badge/javadoc-yes-blue.svg)](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.12.1/index.html) [![License Apache](https://img.shields.io/badge/license-apache-blue.svg)](https://tldrlegal.com/license/apache-license-2.0-(apache-2.0)) -[![Changelog](https://img.shields.io/badge/changelog-6.12.0-blue.svg)](CHANGES.md) +[![Changelog](https://img.shields.io/badge/changelog-6.12.1-blue.svg)](CHANGES.md) [![Circle CI](https://circleci.com/gh/diffplug/spotless/tree/main.svg?style=shield)](https://circleci.com/gh/diffplug/spotless/tree/main) [![Live chat](https://img.shields.io/badge/gitter-chat-brightgreen.svg)](https://gitter.im/diffplug/spotless) @@ -128,10 +128,10 @@ spotless { ``` Spotless consists of a list of formats (in the example above, `misc` and `java`), and each format has: -- a `target` (the files to format), which you set with [`target`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.12.0/com/diffplug/gradle/spotless/FormatExtension.html#target-java.lang.Object...-) and [`targetExclude`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.12.0/com/diffplug/gradle/spotless/FormatExtension.html#targetExclude-java.lang.Object...-) -- a list of `FormatterStep`, which are just `String -> String` functions, such as [`replace`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.12.0/com/diffplug/gradle/spotless/FormatExtension.html#replace-java.lang.String-java.lang.CharSequence-java.lang.CharSequence-), [`replaceRegex`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.12.0/com/diffplug/gradle/spotless/FormatExtension.html#replaceRegex-java.lang.String-java.lang.String-java.lang.String-), [`trimTrailingWhitespace`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.12.0/com/diffplug/gradle/spotless/FormatExtension.html#replace-java.lang.String-java.lang.CharSequence-java.lang.CharSequence-), [`custom`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.12.0/com/diffplug/gradle/spotless/FormatExtension.html#custom-java.lang.String-groovy.lang.Closure-), [`prettier`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.12.0/com/diffplug/gradle/spotless/FormatExtension.html#prettier--), [`eclipseWtp`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.12.0/com/diffplug/gradle/spotless/FormatExtension.html#eclipseWtp-com.diffplug.spotless.extra.wtp.EclipseWtpFormatterStep-), [`licenseHeader`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.12.0/com/diffplug/gradle/spotless/FormatExtension.html#licenseHeader-java.lang.String-java.lang.String-) etc. +- a `target` (the files to format), which you set with [`target`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.12.1/com/diffplug/gradle/spotless/FormatExtension.html#target-java.lang.Object...-) and [`targetExclude`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.12.1/com/diffplug/gradle/spotless/FormatExtension.html#targetExclude-java.lang.Object...-) +- a list of `FormatterStep`, which are just `String -> String` functions, such as [`replace`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.12.1/com/diffplug/gradle/spotless/FormatExtension.html#replace-java.lang.String-java.lang.CharSequence-java.lang.CharSequence-), [`replaceRegex`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.12.1/com/diffplug/gradle/spotless/FormatExtension.html#replaceRegex-java.lang.String-java.lang.String-java.lang.String-), [`trimTrailingWhitespace`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.12.1/com/diffplug/gradle/spotless/FormatExtension.html#replace-java.lang.String-java.lang.CharSequence-java.lang.CharSequence-), [`custom`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.12.1/com/diffplug/gradle/spotless/FormatExtension.html#custom-java.lang.String-groovy.lang.Closure-), [`prettier`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.12.1/com/diffplug/gradle/spotless/FormatExtension.html#prettier--), [`eclipseWtp`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.12.1/com/diffplug/gradle/spotless/FormatExtension.html#eclipseWtp-com.diffplug.spotless.extra.wtp.EclipseWtpFormatterStep-), [`licenseHeader`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.12.1/com/diffplug/gradle/spotless/FormatExtension.html#licenseHeader-java.lang.String-java.lang.String-) etc. -All the generic steps live in [`FormatExtension`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.12.0/com/diffplug/gradle/spotless/FormatExtension.html), and there are many language-specific steps which live in its language-specific subclasses, which are described below. +All the generic steps live in [`FormatExtension`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.12.1/com/diffplug/gradle/spotless/FormatExtension.html), and there are many language-specific steps which live in its language-specific subclasses, which are described below. ### Requirements @@ -143,7 +143,7 @@ If you're stuck on an older version of Gradle, `id 'com.diffplug.gradle.spotless ## Java -`com.diffplug.gradle.spotless.JavaExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.12.0/com/diffplug/gradle/spotless/JavaExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/JavaExtension.java) +`com.diffplug.gradle.spotless.JavaExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.12.1/com/diffplug/gradle/spotless/JavaExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/JavaExtension.java) ```gradle spotless { @@ -267,8 +267,8 @@ You can make a pull request to add new annotations to Spotless's default list. ## Groovy -- `com.diffplug.gradle.spotless.GroovyExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.12.0/com/diffplug/gradle/spotless/GroovyExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/GroovyExtension.java) -- `com.diffplug.gradle.spotless.GroovyGradleExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.12.0/com/diffplug/gradle/spotless/GroovyGradleExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/GroovyGradleExtension.java) +- `com.diffplug.gradle.spotless.GroovyExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.12.1/com/diffplug/gradle/spotless/GroovyExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/GroovyExtension.java) +- `com.diffplug.gradle.spotless.GroovyGradleExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.12.1/com/diffplug/gradle/spotless/GroovyGradleExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/GroovyGradleExtension.java) Configuration for Groovy is similar to [Java](#java), in that it also supports `licenseHeader` and `importOrder`. @@ -319,8 +319,8 @@ Groovy-Eclipse formatting errors/warnings lead per default to a build failure. T ## Kotlin -- `com.diffplug.gradle.spotless.KotlinExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.12.0/com/diffplug/gradle/spotless/KotlinExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/KotlinExtension.java) -- `com.diffplug.gradle.spotless.KotlinGradleExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.12.0/com/diffplug/gradle/spotless/KotlinGradleExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/KotlinGradleExtension.java) +- `com.diffplug.gradle.spotless.KotlinExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.12.1/com/diffplug/gradle/spotless/KotlinExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/KotlinExtension.java) +- `com.diffplug.gradle.spotless.KotlinGradleExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.12.1/com/diffplug/gradle/spotless/KotlinGradleExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/KotlinGradleExtension.java) ```gradle spotless { // if you are using build.gradle.kts, instead of 'spotless {' use: @@ -383,7 +383,7 @@ spotless { ## Scala -`com.diffplug.gradle.spotless.ScalaExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.12.0/com/diffplug/gradle/spotless/ScalaExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/ScalaExtension.java) +`com.diffplug.gradle.spotless.ScalaExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.12.1/com/diffplug/gradle/spotless/ScalaExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/ScalaExtension.java) ```gradle spotless { @@ -415,7 +415,7 @@ spotless { ## C/C++ -`com.diffplug.gradle.spotless.CppExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.12.0/com/diffplug/gradle/spotless/CppExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/CppExtension.java) +`com.diffplug.gradle.spotless.CppExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.12.1/com/diffplug/gradle/spotless/CppExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/CppExtension.java) ```gradle spotless { @@ -447,7 +447,7 @@ spotles { ## Python -`com.diffplug.gradle.spotless.PythonExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.12.0/com/diffplug/gradle/spotless/PythonExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/PythonExtension.java) +`com.diffplug.gradle.spotless.PythonExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.12.1/com/diffplug/gradle/spotless/PythonExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/PythonExtension.java) ```gradle spotless { @@ -481,7 +481,7 @@ black().pathToExe('C:/myuser/.pyenv/versions/3.8.0/scripts/black.exe') ## FreshMark -`com.diffplug.gradle.spotless.FreshMarkExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.12.0/com/diffplug/gradle/spotless/FreshMarkExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/FreshMarkExtension.java) +`com.diffplug.gradle.spotless.FreshMarkExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.12.1/com/diffplug/gradle/spotless/FreshMarkExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/FreshMarkExtension.java) [homepage](https://github.com/diffplug/freshmark). [changelog](https://github.com/diffplug/freshmark/blob/master/CHANGES.md). FreshMark lets you generate markdown in the comments of your markdown. This helps to keep badges and links up-to-date (see the source for this file), and can also be helpful for generating complex tables (see the source for [the parent readme](../README.md)). @@ -502,7 +502,7 @@ spotless { ## Antlr4 -`com.diffplug.gradle.spotless.Antlr4Extension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.12.0/com/diffplug/gradle/spotless/Antlr4Extension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/Antlr4Extension.java) +`com.diffplug.gradle.spotless.Antlr4Extension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.12.1/com/diffplug/gradle/spotless/Antlr4Extension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/Antlr4Extension.java) ```gradle spotless { @@ -527,7 +527,7 @@ antlr4formatter('1.2.1') // version is optional ## SQL -`com.diffplug.gradle.spotless.SqlExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.12.0/com/diffplug/gradle/spotless/SqlExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/SqlExtension.java) +`com.diffplug.gradle.spotless.SqlExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.12.1/com/diffplug/gradle/spotless/SqlExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/SqlExtension.java) ```gradle spotless { @@ -567,7 +567,7 @@ sql.formatter.indent.size=4 ## Typescript -- `com.diffplug.gradle.spotless.TypescriptExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.12.0/com/diffplug/gradle/spotless/TypescriptExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/TypescriptExtension.java) +- `com.diffplug.gradle.spotless.TypescriptExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.12.1/com/diffplug/gradle/spotless/TypescriptExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/TypescriptExtension.java) ```gradle spotless { @@ -610,7 +610,7 @@ For details, see the [npm detection](#npm-detection) and [`.npmrc` detection](#n ## JSON -- `com.diffplug.gradle.spotless.JsonExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.12.0/com/diffplug/gradle/spotless/JsonExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/JsonExtension.java) +- `com.diffplug.gradle.spotless.JsonExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.12.1/com/diffplug/gradle/spotless/JsonExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/JsonExtension.java) ```gradle spotless { @@ -835,7 +835,7 @@ Once a file's license header has a valid year, whether it is a year (`2020`) or * `2017` -> `2017-2020` * `2017-2019` -> `2017-2020` -See the [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.12.0/com/diffplug/gradle/spotless/FormatExtension.LicenseHeaderConfig.html) for a complete listing of options. +See the [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.12.1/com/diffplug/gradle/spotless/FormatExtension.LicenseHeaderConfig.html) for a complete listing of options. @@ -902,9 +902,9 @@ spotless { custom 'lowercase', { str -> str.toLowerCase() } ``` -However, custom rules will disable up-to-date checking and caching, unless you read [this javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.12.0/com/diffplug/gradle/spotless/FormatExtension.html#bumpThisNumberIfACustomStepChanges-int-) and follow its instructions carefully. +However, custom rules will disable up-to-date checking and caching, unless you read [this javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.12.1/com/diffplug/gradle/spotless/FormatExtension.html#bumpThisNumberIfACustomStepChanges-int-) and follow its instructions carefully. -Another option is to create proper `FormatterStep` in your `buildSrc`, and then call [`addStep`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.12.0/com/diffplug/gradle/spotless/FormatExtension.html#addStep-com.diffplug.spotless.FormatterStep-). The contributing guide describes [how to do this](https://github.com/diffplug/spotless/blob/main/CONTRIBUTING.md#how-to-add-a-new-formatterstep). If the step is generally-useful, we hope you'll open a PR to share it! +Another option is to create proper `FormatterStep` in your `buildSrc`, and then call [`addStep`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.12.1/com/diffplug/gradle/spotless/FormatExtension.html#addStep-com.diffplug.spotless.FormatterStep-). The contributing guide describes [how to do this](https://github.com/diffplug/spotless/blob/main/CONTRIBUTING.md#how-to-add-a-new-formatterstep). If the step is generally-useful, we hope you'll open a PR to share it! ```gradle @@ -937,11 +937,11 @@ spotless { format 'foo', com.acme.FooLanguageExtension, { ``` -If you'd like to create a one-off Spotless task outside of the `check`/`apply` framework, see [`FormatExtension.createIndependentApplyTask`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.12.0/com/diffplug/gradle/spotless/FormatExtension.html#createIndependentApplyTask-java.lang.String-). +If you'd like to create a one-off Spotless task outside of the `check`/`apply` framework, see [`FormatExtension.createIndependentApplyTask`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.12.1/com/diffplug/gradle/spotless/FormatExtension.html#createIndependentApplyTask-java.lang.String-). ## Inception (languages within languages within...) -In very rare cases, you might want to format e.g. javascript which is written inside JSP templates, or maybe java within a markdown file, or something wacky like that. You can specify hunks within a file using either open/close tags or a regex with a single capturing group, and then specify rules within it, like so. See [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.12.0/com/diffplug/gradle/spotless/FormatExtension.html#withinBlocks-java.lang.String-java.lang.String-java.lang.String-org.gradle.api.Action-) for more details. +In very rare cases, you might want to format e.g. javascript which is written inside JSP templates, or maybe java within a markdown file, or something wacky like that. You can specify hunks within a file using either open/close tags or a regex with a single capturing group, and then specify rules within it, like so. See [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.12.1/com/diffplug/gradle/spotless/FormatExtension.html#withinBlocks-java.lang.String-java.lang.String-java.lang.String-org.gradle.api.Action-) for more details. ```gradle import com.diffplug.gradle.spotless.JavaExtension From 8146bf72d33c7ce443c21a748595eeea1087a5e1 Mon Sep 17 00:00:00 2001 From: circleci Date: Mon, 2 Jan 2023 04:47:36 +0000 Subject: [PATCH 390/757] Published maven/2.29.0 --- plugin-maven/CHANGES.md | 2 ++ plugin-maven/README.md | 4 ++-- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/plugin-maven/CHANGES.md b/plugin-maven/CHANGES.md index e8fc8d3d49..84e06aa847 100644 --- a/plugin-maven/CHANGES.md +++ b/plugin-maven/CHANGES.md @@ -3,6 +3,8 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format (starting after version `1.27.0`). ## [Unreleased] + +## [2.29.0] - 2023-01-02 ### Added * Added support for M2E's incremental compilation ([#1414](https://github.com/diffplug/spotless/pull/1414) fixes [#1413](https://github.com/diffplug/spotless/issues/1413)) ### Fixed diff --git a/plugin-maven/README.md b/plugin-maven/README.md index e6a2c47aae..80be3dbc37 100644 --- a/plugin-maven/README.md +++ b/plugin-maven/README.md @@ -12,8 +12,8 @@ output = [ ].join('\n'); --> [![Maven central](https://img.shields.io/badge/mavencentral-com.diffplug.spotless%3Aspotless--maven--plugin-blue.svg)](https://search.maven.org/#search%7Cgav%7C1%7Cg%3A%22com.diffplug.spotless%22%20AND%20a%3A%22spotless-maven-plugin%22) -[![Javadoc](https://img.shields.io/badge/javadoc-yes-blue.svg)](https://javadoc.io/doc/com.diffplug.spotless/spotless-maven-plugin/2.28.0/index.html) -[![Changelog](https://img.shields.io/badge/changelog-2.28.0-brightgreen.svg)](CHANGES.md) +[![Javadoc](https://img.shields.io/badge/javadoc-yes-blue.svg)](https://javadoc.io/doc/com.diffplug.spotless/spotless-maven-plugin/2.29.0/index.html) +[![Changelog](https://img.shields.io/badge/changelog-2.29.0-brightgreen.svg)](CHANGES.md) [![Circle CI](https://circleci.com/gh/diffplug/spotless/tree/main.svg?style=shield)](https://circleci.com/gh/diffplug/spotless/tree/main) [![Live chat](https://img.shields.io/badge/gitter-chat-brightgreen.svg)](https://gitter.im/diffplug/spotless) From 2c03111edf22f9506520a31aff476017258d24b9 Mon Sep 17 00:00:00 2001 From: Ned Twigg Date: Sun, 1 Jan 2023 21:04:36 -0800 Subject: [PATCH 391/757] Update GradleIntegrationHarness' JVM compatibility matrix. --- .../diffplug/gradle/spotless/GradleIntegrationHarness.java | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/GradleIntegrationHarness.java b/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/GradleIntegrationHarness.java index 6cc35290db..9e2f490429 100644 --- a/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/GradleIntegrationHarness.java +++ b/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/GradleIntegrationHarness.java @@ -1,5 +1,5 @@ /* - * Copyright 2016-2022 DiffPlug + * Copyright 2016-2023 DiffPlug * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -53,9 +53,12 @@ public enum GradleVersionSupport { GradleVersionSupport(String version) { String minVersionForRunningJRE; switch (Jvm.version()) { + case 21: case 20: - case 19: // TODO: https://docs.gradle.org/current/userguide/compatibility.html + case 19: + minVersionForRunningJRE = "7.6"; + break; case 18: minVersionForRunningJRE = "7.5"; break; From 923d87561af4f914d0221d9145d50adcd003a36e Mon Sep 17 00:00:00 2001 From: Ned Twigg Date: Sun, 1 Jan 2023 21:05:02 -0800 Subject: [PATCH 392/757] Update groovy-xml to a version that Gradle 7.6 can tolerate. --- lib-extra/build.gradle | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/lib-extra/build.gradle b/lib-extra/build.gradle index 38e7c37403..6dd195cde9 100644 --- a/lib-extra/build.gradle +++ b/lib-extra/build.gradle @@ -15,7 +15,9 @@ dependencies { implementation "org.eclipse.jgit:org.eclipse.jgit:${VER_JGIT}" implementation "com.googlecode.concurrent-trees:concurrent-trees:2.6.1" // used for xml parsing in EclipseFormatter - implementation "org.codehaus.groovy:groovy-xml:3.0.10" + // TODO: Gradle barfs if this doesn't match its built-in version, + // would be great to drop this for something less sensitive if possible + implementation "org.codehaus.groovy:groovy-xml:3.0.13" // testing testImplementation project(':testlib') From 1f7bab70bff03a047e081c2d019be508810d3371 Mon Sep 17 00:00:00 2001 From: Ned Twigg Date: Sun, 1 Jan 2023 21:12:33 -0800 Subject: [PATCH 393/757] Turns out we don't need groovy-xml at all anymore. Lol. --- lib-extra/build.gradle | 4 ---- 1 file changed, 4 deletions(-) diff --git a/lib-extra/build.gradle b/lib-extra/build.gradle index 6dd195cde9..d94992f8d3 100644 --- a/lib-extra/build.gradle +++ b/lib-extra/build.gradle @@ -14,10 +14,6 @@ dependencies { // needed by GitAttributesLineEndings implementation "org.eclipse.jgit:org.eclipse.jgit:${VER_JGIT}" implementation "com.googlecode.concurrent-trees:concurrent-trees:2.6.1" - // used for xml parsing in EclipseFormatter - // TODO: Gradle barfs if this doesn't match its built-in version, - // would be great to drop this for something less sensitive if possible - implementation "org.codehaus.groovy:groovy-xml:3.0.13" // testing testImplementation project(':testlib') From d7ac1fe76f1fffe611af89b3535d1e44352e0433 Mon Sep 17 00:00:00 2001 From: Ned Twigg Date: Sun, 1 Jan 2023 21:14:48 -0800 Subject: [PATCH 394/757] Update changelog. --- CHANGES.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/CHANGES.md b/CHANGES.md index e3493f7c09..40a2ae3e07 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -10,6 +10,8 @@ This document is intended for Spotless developers. We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format (starting after version `1.27.0`). ## [Unreleased] +### Changes +* Bump the dev version of Gradle from `7.5.1` to `7.6` ([#1409](https://github.com/diffplug/spotless/pull/1409)) ## [2.31.1] - 2023-01-02 ### Fixed From 6e19b7edc7e5e6b4bf62214c18ff1b2b84e72c8c Mon Sep 17 00:00:00 2001 From: Ned Twigg Date: Sun, 1 Jan 2023 21:23:38 -0800 Subject: [PATCH 395/757] Another needed update for the changelog. --- CHANGES.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGES.md b/CHANGES.md index 40a2ae3e07..cf43b4eb22 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -12,6 +12,7 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format ( ## [Unreleased] ### Changes * Bump the dev version of Gradle from `7.5.1` to `7.6` ([#1409](https://github.com/diffplug/spotless/pull/1409)) + * We also removed the no-longer-required dependency `org.codehaus.groovy:groovy-xml` ## [2.31.1] - 2023-01-02 ### Fixed From ade6c0d48138af938aaa7039a22ef784e92036b0 Mon Sep 17 00:00:00 2001 From: "renovate[bot]" <29139614+renovate[bot]@users.noreply.github.com> Date: Mon, 2 Jan 2023 06:21:18 +0000 Subject: [PATCH 396/757] chore(deps): update plugin com.diffplug.spotless to v6.12.1 --- settings.gradle | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/settings.gradle b/settings.gradle index 828a3629c7..786baa1eba 100644 --- a/settings.gradle +++ b/settings.gradle @@ -1,6 +1,6 @@ pluginManagement { plugins { - id 'com.diffplug.spotless' version '6.12.0' + id 'com.diffplug.spotless' version '6.12.1' // https://plugins.gradle.org/plugin/com.gradle.plugin-publish id 'com.gradle.plugin-publish' version '1.1.0' // https://github.com/gradle-nexus/publish-plugin/releases From 50e7cb01e05019c671e1411fb7c56f8bd7314f52 Mon Sep 17 00:00:00 2001 From: Abel Keszei Date: Mon, 2 Jan 2023 19:34:54 +0100 Subject: [PATCH 397/757] apply license header updates --- .../java/com/diffplug/spotless/generic/LicenseHeaderStep.java | 2 +- .../main/java/com/diffplug/gradle/spotless/FormatExtension.java | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/src/main/java/com/diffplug/spotless/generic/LicenseHeaderStep.java b/lib/src/main/java/com/diffplug/spotless/generic/LicenseHeaderStep.java index 5345adc150..d1fdf86e3e 100644 --- a/lib/src/main/java/com/diffplug/spotless/generic/LicenseHeaderStep.java +++ b/lib/src/main/java/com/diffplug/spotless/generic/LicenseHeaderStep.java @@ -1,5 +1,5 @@ /* - * Copyright 2016-2021 DiffPlug + * Copyright 2016-2023 DiffPlug * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. 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 84690bf063..9c1e239d39 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-2022 DiffPlug + * Copyright 2016-2023 DiffPlug * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. From 9df255ed3c1a56aeec24e6e92190e6382cf45dcd Mon Sep 17 00:00:00 2001 From: Eir Nym <485399+eirnym@users.noreply.github.com> Date: Tue, 3 Jan 2023 00:06:41 +0100 Subject: [PATCH 398/757] Add editor config file option to maven and gradle --- .../compat/KtLintCompat0Dot31Dot0Adapter.java | 4 ++-- .../compat/KtLintCompat0Dot32Dot0Adapter.java | 4 ++-- .../compat/KtLintCompat0Dot34Dot2Adapter.java | 6 +++--- .../compat/KtLintCompat0Dot45Dot2Adapter.java | 6 +++--- .../compat/KtLintCompat0Dot46Dot0Adapter.java | 6 +++--- .../compat/KtLintCompat0Dot47Dot0Adapter.java | 17 ++++++++++++----- .../compat/KtLintCompat0Dot48Dot0Adapter.java | 15 +++++++++++---- .../glue/ktlint/compat/KtLintCompatAdapter.java | 4 ++-- .../glue/ktlint/KtlintFormatterFunc.java | 6 ++++-- .../diffplug/spotless/kotlin/KtLintStep.java | 15 +++++++++++---- .../gradle/spotless/KotlinExtension.java | 10 ++++++---- .../gradle/spotless/KotlinGradleExtension.java | 14 +++++++++++--- .../diffplug/spotless/maven/kotlin/Ktlint.java | 7 ++++--- 13 files changed, 74 insertions(+), 40 deletions(-) diff --git a/lib/src/compatKtLint0Dot31Dot0/java/com/diffplug/spotless/glue/ktlint/compat/KtLintCompat0Dot31Dot0Adapter.java b/lib/src/compatKtLint0Dot31Dot0/java/com/diffplug/spotless/glue/ktlint/compat/KtLintCompat0Dot31Dot0Adapter.java index 56b8da2d20..a10bf9be0e 100644 --- a/lib/src/compatKtLint0Dot31Dot0/java/com/diffplug/spotless/glue/ktlint/compat/KtLintCompat0Dot31Dot0Adapter.java +++ b/lib/src/compatKtLint0Dot31Dot0/java/com/diffplug/spotless/glue/ktlint/compat/KtLintCompat0Dot31Dot0Adapter.java @@ -1,5 +1,5 @@ /* - * Copyright 2022 DiffPlug + * Copyright 2022-2023 DiffPlug * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -43,7 +43,7 @@ public Unit invoke(LintError lint, Boolean corrected) { @Override public String format(final String text, final String name, final boolean isScript, final boolean useExperimental, - final Map userData, + String editorConfigPath, final Map userData, final Map editorConfigOverrideMap) { final FormatterCallback formatterCallback = new FormatterCallback(); diff --git a/lib/src/compatKtLint0Dot32Dot0/java/com/diffplug/spotless/glue/ktlint/compat/KtLintCompat0Dot32Dot0Adapter.java b/lib/src/compatKtLint0Dot32Dot0/java/com/diffplug/spotless/glue/ktlint/compat/KtLintCompat0Dot32Dot0Adapter.java index 6f69fcc7ce..3f98abe3b3 100644 --- a/lib/src/compatKtLint0Dot32Dot0/java/com/diffplug/spotless/glue/ktlint/compat/KtLintCompat0Dot32Dot0Adapter.java +++ b/lib/src/compatKtLint0Dot32Dot0/java/com/diffplug/spotless/glue/ktlint/compat/KtLintCompat0Dot32Dot0Adapter.java @@ -1,5 +1,5 @@ /* - * Copyright 2022 DiffPlug + * Copyright 2022-2023 DiffPlug * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -43,7 +43,7 @@ public Unit invoke(LintError lint, Boolean corrected) { @Override public String format(final String text, final String name, final boolean isScript, final boolean useExperimental, - final Map userData, + String editorConfigPath, final Map userData, final Map editorConfigOverrideMap) { final FormatterCallback formatterCallback = new FormatterCallback(); diff --git a/lib/src/compatKtLint0Dot34Dot2/java/com/diffplug/spotless/glue/ktlint/compat/KtLintCompat0Dot34Dot2Adapter.java b/lib/src/compatKtLint0Dot34Dot2/java/com/diffplug/spotless/glue/ktlint/compat/KtLintCompat0Dot34Dot2Adapter.java index a3c8c8df3b..0352a8e1f0 100644 --- a/lib/src/compatKtLint0Dot34Dot2/java/com/diffplug/spotless/glue/ktlint/compat/KtLintCompat0Dot34Dot2Adapter.java +++ b/lib/src/compatKtLint0Dot34Dot2/java/com/diffplug/spotless/glue/ktlint/compat/KtLintCompat0Dot34Dot2Adapter.java @@ -1,5 +1,5 @@ /* - * Copyright 2022 DiffPlug + * Copyright 2022-2023 DiffPlug * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -43,7 +43,7 @@ public Unit invoke(LintError lint, Boolean corrected) { @Override public String format(final String text, final String name, final boolean isScript, final boolean useExperimental, - final Map userData, + String editorConfigPath, final Map userData, final Map editorConfigOverrideMap) { final FormatterCallback formatterCallback = new FormatterCallback(); @@ -61,7 +61,7 @@ public String format(final String text, final String name, final boolean isScrip userData, formatterCallback, isScript, - null, + editorConfigPath, false)); } } diff --git a/lib/src/compatKtLint0Dot45Dot2/java/com/diffplug/spotless/glue/ktlint/compat/KtLintCompat0Dot45Dot2Adapter.java b/lib/src/compatKtLint0Dot45Dot2/java/com/diffplug/spotless/glue/ktlint/compat/KtLintCompat0Dot45Dot2Adapter.java index f7eadada3d..15c2238d5d 100644 --- a/lib/src/compatKtLint0Dot45Dot2/java/com/diffplug/spotless/glue/ktlint/compat/KtLintCompat0Dot45Dot2Adapter.java +++ b/lib/src/compatKtLint0Dot45Dot2/java/com/diffplug/spotless/glue/ktlint/compat/KtLintCompat0Dot45Dot2Adapter.java @@ -1,5 +1,5 @@ /* - * Copyright 2022 DiffPlug + * Copyright 2022-2023 DiffPlug * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -51,7 +51,7 @@ public Unit invoke(LintError lint, Boolean corrected) { @Override public String format(final String text, final String name, final boolean isScript, final boolean useExperimental, - final Map userData, + String editorConfigPath, final Map userData, final Map editorConfigOverrideMap) { final FormatterCallback formatterCallback = new FormatterCallback(); @@ -76,7 +76,7 @@ public String format(final String text, final String name, final boolean isScrip userData, formatterCallback, isScript, - null, + editorConfigPath, false, editorConfigOverride, false)); diff --git a/lib/src/compatKtLint0Dot46Dot0/java/com/diffplug/spotless/glue/ktlint/compat/KtLintCompat0Dot46Dot0Adapter.java b/lib/src/compatKtLint0Dot46Dot0/java/com/diffplug/spotless/glue/ktlint/compat/KtLintCompat0Dot46Dot0Adapter.java index 873b91af80..28eba672a0 100644 --- a/lib/src/compatKtLint0Dot46Dot0/java/com/diffplug/spotless/glue/ktlint/compat/KtLintCompat0Dot46Dot0Adapter.java +++ b/lib/src/compatKtLint0Dot46Dot0/java/com/diffplug/spotless/glue/ktlint/compat/KtLintCompat0Dot46Dot0Adapter.java @@ -1,5 +1,5 @@ /* - * Copyright 2022 DiffPlug + * Copyright 2022-2023 DiffPlug * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -51,7 +51,7 @@ public Unit invoke(LintError lint, Boolean corrected) { @Override public String format(final String text, final String name, final boolean isScript, final boolean useExperimental, - final Map userData, + String editorConfigPath, final Map userData, final Map editorConfigOverrideMap) { final FormatterCallback formatterCallback = new FormatterCallback(); @@ -76,7 +76,7 @@ public String format(final String text, final String name, final boolean isScrip userData, formatterCallback, isScript, - null, + editorConfigPath, false, editorConfigOverride, false)); diff --git a/lib/src/compatKtLint0Dot47Dot0/java/com/diffplug/spotless/glue/ktlint/compat/KtLintCompat0Dot47Dot0Adapter.java b/lib/src/compatKtLint0Dot47Dot0/java/com/diffplug/spotless/glue/ktlint/compat/KtLintCompat0Dot47Dot0Adapter.java index 757ffc922b..3445a688b1 100644 --- a/lib/src/compatKtLint0Dot47Dot0/java/com/diffplug/spotless/glue/ktlint/compat/KtLintCompat0Dot47Dot0Adapter.java +++ b/lib/src/compatKtLint0Dot47Dot0/java/com/diffplug/spotless/glue/ktlint/compat/KtLintCompat0Dot47Dot0Adapter.java @@ -1,5 +1,5 @@ /* - * Copyright 2022 DiffPlug + * Copyright 2022-2023 DiffPlug * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -17,6 +17,8 @@ import static java.util.Collections.emptySet; +import java.io.File; +import java.nio.file.Path; import java.util.ArrayList; import java.util.LinkedHashSet; import java.util.List; @@ -56,7 +58,7 @@ public Unit invoke(LintError lint, Boolean corrected) { @Override public String format(final String text, final String name, final boolean isScript, final boolean useExperimental, - final Map userData, + String editorConfigPath, final Map userData, final Map editorConfigOverrideMap) { final FormatterCallback formatterCallback = new FormatterCallback(); @@ -68,14 +70,19 @@ public String format(final String text, final String name, final boolean isScrip EditorConfigOverride editorConfigOverride; if (editorConfigOverrideMap.isEmpty()) { - editorConfigOverride = EditorConfigOverride.Companion.getEmptyEditorConfigOverride(); + editorConfigOverride = new EditorConfigOverride(); } else { editorConfigOverride = createEditorConfigOverride(allRuleProviders.stream().map( RuleProvider::createNewRuleInstance).collect( Collectors.toList()), editorConfigOverrideMap); } - + Path editorConfigFilePath; + if (editorConfigPath == null) { + editorConfigFilePath = null; + } else { + editorConfigFilePath = new File(editorConfigPath).toPath(); + } return KtLint.INSTANCE.format(new KtLint.ExperimentalParams( name, text, @@ -86,7 +93,7 @@ public String format(final String text, final String name, final boolean isScrip isScript, null, false, - EditorConfigDefaults.Companion.getEmptyEditorConfigDefaults(), + EditorConfigDefaults.Companion.load(editorConfigFilePath), editorConfigOverride, false)); } diff --git a/lib/src/compatKtLint0Dot48Dot0/java/com/diffplug/spotless/glue/ktlint/compat/KtLintCompat0Dot48Dot0Adapter.java b/lib/src/compatKtLint0Dot48Dot0/java/com/diffplug/spotless/glue/ktlint/compat/KtLintCompat0Dot48Dot0Adapter.java index 8235c535a5..3efc8c085d 100644 --- a/lib/src/compatKtLint0Dot48Dot0/java/com/diffplug/spotless/glue/ktlint/compat/KtLintCompat0Dot48Dot0Adapter.java +++ b/lib/src/compatKtLint0Dot48Dot0/java/com/diffplug/spotless/glue/ktlint/compat/KtLintCompat0Dot48Dot0Adapter.java @@ -15,6 +15,8 @@ */ package com.diffplug.spotless.glue.ktlint.compat; +import java.io.File; +import java.nio.file.Path; import java.util.LinkedHashSet; import java.util.List; import java.util.Map; @@ -54,7 +56,7 @@ public Unit invoke(LintError lint, Boolean corrected) { @Override public String format(final String text, final String name, final boolean isScript, final boolean useExperimental, - final Map userData, + String editorConfigPath, final Map userData, final Map editorConfigOverrideMap) { final FormatterCallback formatterCallback = new FormatterCallback(); @@ -66,14 +68,19 @@ public String format(final String text, final String name, final boolean isScrip EditorConfigOverride editorConfigOverride; if (editorConfigOverrideMap.isEmpty()) { - editorConfigOverride = EditorConfigOverride.Companion.getEmptyEditorConfigOverride(); + editorConfigOverride = new EditorConfigOverride(); } else { editorConfigOverride = createEditorConfigOverride(allRuleProviders.stream().map( RuleProvider::createNewRuleInstance).collect( Collectors.toList()), editorConfigOverrideMap); } - + Path editorConfigFilePath; + if (editorConfigPath == null) { + editorConfigFilePath = null; + } else { + editorConfigFilePath = new File(editorConfigPath).toPath(); + } return KtLint.INSTANCE.format(new KtLint.ExperimentalParams( name, text, @@ -82,7 +89,7 @@ public String format(final String text, final String name, final boolean isScrip formatterCallback, isScript, false, - EditorConfigDefaults.Companion.getEmptyEditorConfigDefaults(), + EditorConfigDefaults.Companion.load(editorConfigFilePath), editorConfigOverride, false)); } diff --git a/lib/src/compatKtLintApi/java/com/diffplug/spotless/glue/ktlint/compat/KtLintCompatAdapter.java b/lib/src/compatKtLintApi/java/com/diffplug/spotless/glue/ktlint/compat/KtLintCompatAdapter.java index 5097cac135..b3e5d1817a 100644 --- a/lib/src/compatKtLintApi/java/com/diffplug/spotless/glue/ktlint/compat/KtLintCompatAdapter.java +++ b/lib/src/compatKtLintApi/java/com/diffplug/spotless/glue/ktlint/compat/KtLintCompatAdapter.java @@ -1,5 +1,5 @@ /* - * Copyright 2022 DiffPlug + * Copyright 2022-2023 DiffPlug * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -19,6 +19,6 @@ public interface KtLintCompatAdapter { - String format(String text, String name, boolean isScript, boolean useExperimental, Map userData, + String format(String text, String name, boolean isScript, boolean useExperimental, String editorConfigPath, Map userData, Map editorConfigOverrideMap); } diff --git a/lib/src/ktlint/java/com/diffplug/spotless/glue/ktlint/KtlintFormatterFunc.java b/lib/src/ktlint/java/com/diffplug/spotless/glue/ktlint/KtlintFormatterFunc.java index fc64cdb23e..5b43bf5e14 100644 --- a/lib/src/ktlint/java/com/diffplug/spotless/glue/ktlint/KtlintFormatterFunc.java +++ b/lib/src/ktlint/java/com/diffplug/spotless/glue/ktlint/KtlintFormatterFunc.java @@ -37,9 +37,10 @@ public class KtlintFormatterFunc implements FormatterFunc.NeedsFile { @NotNull private final KtLintCompatAdapter adapter; private final boolean useExperimental; + private final String editorConfigPath; private final Map editorConfigOverrideMap; - public KtlintFormatterFunc(String version, boolean isScript, boolean useExperimental, Map userData, + public KtlintFormatterFunc(String version, boolean isScript, boolean useExperimental, String editorConfigPath, Map userData, Map editorConfigOverrideMap) { int minorVersion = Integer.parseInt(version.split("\\.")[1]); if (minorVersion >= 48) { @@ -64,6 +65,7 @@ public KtlintFormatterFunc(String version, boolean isScript, boolean useExperime // the OG this.adapter = new KtLintCompat0Dot31Dot0Adapter(); } + this.editorConfigPath = editorConfigPath; this.useExperimental = useExperimental; this.editorConfigOverrideMap = editorConfigOverrideMap; this.userData = userData; @@ -72,6 +74,6 @@ public KtlintFormatterFunc(String version, boolean isScript, boolean useExperime @Override public String applyWithFile(String unix, File file) throws Exception { - return adapter.format(unix, file.getName(), isScript, useExperimental, userData, editorConfigOverrideMap); + return adapter.format(unix, file.getName(), isScript, useExperimental, editorConfigPath, userData, editorConfigOverrideMap); } } diff --git a/lib/src/main/java/com/diffplug/spotless/kotlin/KtLintStep.java b/lib/src/main/java/com/diffplug/spotless/kotlin/KtLintStep.java index b444f0f1a7..9291e69fde 100644 --- a/lib/src/main/java/com/diffplug/spotless/kotlin/KtLintStep.java +++ b/lib/src/main/java/com/diffplug/spotless/kotlin/KtLintStep.java @@ -64,10 +64,15 @@ public static FormatterStep createForScript(String version, Provisioner provisio private static FormatterStep create(String version, Provisioner provisioner, boolean isScript, boolean useExperimental, Map userData, Map editorConfigOverride) { + return create(version, provisioner, useExperimental, userData, editorConfigOverride); + } + + public static FormatterStep create(String version, Provisioner provisioner, boolean isScript, boolean useExperimental, + String editorConfig, Map userData, Map editorConfigOverride) { Objects.requireNonNull(version, "version"); Objects.requireNonNull(provisioner, "provisioner"); return FormatterStep.createLazy(NAME, - () -> new State(version, provisioner, isScript, useExperimental, userData, editorConfigOverride), + () -> new State(version, provisioner, isScript, useExperimental, editorConfig, userData, editorConfigOverride), State::createFormat); } @@ -86,9 +91,10 @@ static final class State implements Serializable { private final TreeMap userData; private final TreeMap editorConfigOverride; private final String version; + private final String editorConfigPath; State(String version, Provisioner provisioner, boolean isScript, boolean useExperimental, - Map userData, Map editorConfigOverride) throws IOException { + String editorConfigPath, Map userData, Map editorConfigOverride) throws IOException { this.version = version; String coordinate; @@ -104,6 +110,7 @@ static final class State implements Serializable { this.userData = new TreeMap<>(userData); this.editorConfigOverride = new TreeMap<>(editorConfigOverride); this.jarState = JarState.from(coordinate + version, provisioner); + this.editorConfigPath = editorConfigPath; this.isScript = isScript; } @@ -111,8 +118,8 @@ FormatterFunc createFormat() throws Exception { final ClassLoader classLoader = jarState.getClassLoader(); Class formatterFunc = classLoader.loadClass("com.diffplug.spotless.glue.ktlint.KtlintFormatterFunc"); Constructor constructor = formatterFunc.getConstructor( - String.class, boolean.class, boolean.class, Map.class, Map.class); - return (FormatterFunc.NeedsFile) constructor.newInstance(version, isScript, useExperimental, userData, editorConfigOverride); + String.class, boolean.class, boolean.class, String.class, Map.class, Map.class); + return (FormatterFunc.NeedsFile) constructor.newInstance(version, isScript, useExperimental, editorConfigPath, userData, editorConfigOverride); } } } diff --git a/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/KotlinExtension.java b/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/KotlinExtension.java index 546efab46d..eddeef36d6 100644 --- a/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/KotlinExtension.java +++ b/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/KotlinExtension.java @@ -1,5 +1,5 @@ /* - * Copyright 2016-2022 DiffPlug + * Copyright 2016-2023 DiffPlug * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -60,7 +60,7 @@ public LicenseHeaderConfig licenseHeaderFile(Object licenseHeaderFile) { /** Adds the specified version of ktlint. */ public KotlinFormatExtension ktlint(String version) { Objects.requireNonNull(version); - return new KotlinFormatExtension(version, false, Collections.emptyMap(), Collections.emptyMap()); + return new KotlinFormatExtension(version, false, null, Collections.emptyMap(), Collections.emptyMap()); } public KotlinFormatExtension ktlint() { @@ -71,13 +71,15 @@ public class KotlinFormatExtension { private final String version; private boolean useExperimental; + private String editorConfigPath; private Map userData; private Map editorConfigOverride; - KotlinFormatExtension(String version, boolean useExperimental, Map config, + KotlinFormatExtension(String version, boolean useExperimental, String editorConfigPath, Map config, Map editorConfigOverride) { this.version = version; this.useExperimental = useExperimental; + this.editorConfigPath = editorConfigPath; this.userData = config; this.editorConfigOverride = editorConfigOverride; addStep(createStep()); @@ -106,7 +108,7 @@ public KotlinFormatExtension editorConfigOverride(Map editorConf } private FormatterStep createStep() { - return KtLintStep.create(version, provisioner(), useExperimental, userData, editorConfigOverride); + return KtLintStep.create(version, provisioner(), useExperimental, false, editorConfigPath, userData, editorConfigOverride); } } diff --git a/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/KotlinGradleExtension.java b/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/KotlinGradleExtension.java index c1abe62bd1..5120d88754 100644 --- a/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/KotlinGradleExtension.java +++ b/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/KotlinGradleExtension.java @@ -1,5 +1,5 @@ /* - * Copyright 2016-2022 DiffPlug + * Copyright 2016-2023 DiffPlug * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -45,7 +45,7 @@ public KotlinGradleExtension(SpotlessExtension spotless) { /** Adds the specified version of ktlint. */ public KotlinFormatExtension ktlint(String version) { Objects.requireNonNull(version, "version"); - return new KotlinFormatExtension(version, false, Collections.emptyMap(), Collections.emptyMap()); + return new KotlinFormatExtension(version, false, null, Collections.emptyMap(), Collections.emptyMap()); } public KotlinFormatExtension ktlint() { @@ -56,18 +56,26 @@ public class KotlinFormatExtension { private final String version; private boolean useExperimental; + private String editorConfigPath; private Map userData; private Map editorConfigOverride; - KotlinFormatExtension(String version, boolean useExperimental, Map config, + KotlinFormatExtension(String version, boolean useExperimental, String editorConfigPath, Map config, Map editorConfigOverride) { this.version = version; this.useExperimental = useExperimental; + this.editorConfigPath = editorConfigPath; this.userData = config; this.editorConfigOverride = editorConfigOverride; addStep(createStep()); } + public KotlinFormatExtension setEditorConfigPath(String editorConfigPath) { + this.editorConfigPath = editorConfigPath; + replaceStep(createStep()); + return this; + } + public KotlinFormatExtension setUseExperimental(boolean useExperimental) { this.useExperimental = useExperimental; replaceStep(createStep()); diff --git a/plugin-maven/src/main/java/com/diffplug/spotless/maven/kotlin/Ktlint.java b/plugin-maven/src/main/java/com/diffplug/spotless/maven/kotlin/Ktlint.java index 45bda05065..ad57c47976 100644 --- a/plugin-maven/src/main/java/com/diffplug/spotless/maven/kotlin/Ktlint.java +++ b/plugin-maven/src/main/java/com/diffplug/spotless/maven/kotlin/Ktlint.java @@ -1,5 +1,5 @@ /* - * Copyright 2016-2022 DiffPlug + * Copyright 2016-2023 DiffPlug * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -30,7 +30,8 @@ public class Ktlint implements FormatterStepFactory { @Parameter private String version; - + @Parameter + private String editorConfigPath; @Parameter private Map editorConfigOverride; @@ -42,6 +43,6 @@ public FormatterStep newFormatterStep(FormatterStepConfig config) { editorConfigOverride = new HashMap<>(); } - return KtLintStep.create(ktlintVersion, config.getProvisioner(), false, Collections.emptyMap(), editorConfigOverride); + return KtLintStep.create(ktlintVersion, config.getProvisioner(), false, false, editorConfigPath, Collections.emptyMap(), editorConfigOverride); } } From 132ecc94a2380da4afcea336bdad5fcbf652fe93 Mon Sep 17 00:00:00 2001 From: Ned Twigg Date: Mon, 2 Jan 2023 14:39:02 -0800 Subject: [PATCH 399/757] Breaking changes to Spotless' internal testing infrastructure `testlib` * `StepHarness` now operates on `Formatter` rather than a `FormatterStep`. * `StepHarnessWithFile` now takes a `ResourceHarness` in its constructor. * Standardized that we test exception *messages*, not types, which will ease the transition to linting later on. --- .../spotless/extra/GitAttributesTest.java | 25 ++-- .../diffplug/spotless/ResourceHarness.java | 55 ++++----- .../com/diffplug/spotless/StepHarness.java | 69 ++++++----- .../spotless/StepHarnessWithFile.java | 105 ++++++++++------- .../antlr4/Antlr4FormatterStepTest.java | 10 +- .../spotless/cpp/ClangFormatStepTest.java | 14 +-- .../spotless/generic/IndentStepTest.java | 28 ++--- .../spotless/generic/PipeStepPairTest.java | 16 ++- .../java/FormatAnnotationsStepTest.java | 18 +-- .../spotless/java/ImportOrderStepTest.java | 47 ++++---- .../json/JsonFormatterStepCommonTests.java | 5 +- .../spotless/json/JsonSimpleStepTest.java | 111 ++++++++++++++---- .../spotless/json/gson/GsonStepTest.java | 33 ++---- .../spotless/kotlin/DiktatStepTest.java | 42 ++----- .../spotless/kotlin/KtLintStepTest.java | 106 +++++++---------- .../npm/PrettierFormatterStepTest.java | 17 ++- .../spotless/scala/ScalaFmtStepTest.java | 33 +++--- 17 files changed, 373 insertions(+), 361 deletions(-) diff --git a/lib-extra/src/test/java/com/diffplug/spotless/extra/GitAttributesTest.java b/lib-extra/src/test/java/com/diffplug/spotless/extra/GitAttributesTest.java index ed657c365a..a7cde9e58f 100644 --- a/lib-extra/src/test/java/com/diffplug/spotless/extra/GitAttributesTest.java +++ b/lib-extra/src/test/java/com/diffplug/spotless/extra/GitAttributesTest.java @@ -1,5 +1,5 @@ /* - * Copyright 2016-2022 DiffPlug + * Copyright 2016-2023 DiffPlug * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -26,24 +26,19 @@ import org.eclipse.jgit.api.errors.GitAPIException; import org.junit.jupiter.api.Test; -import com.diffplug.common.base.Errors; import com.diffplug.common.base.StringPrinter; import com.diffplug.spotless.LineEnding; import com.diffplug.spotless.ResourceHarness; class GitAttributesTest extends ResourceHarness { private List testFiles(String prefix) { - try { - List result = new ArrayList<>(); - for (String path : TEST_PATHS) { - String prefixedPath = prefix + path; - setFile(prefixedPath).toContent(""); - result.add(newFile(prefixedPath)); - } - return result; - } catch (IOException e) { - throw Errors.asRuntime(e); + List result = new ArrayList<>(); + for (String path : TEST_PATHS) { + String prefixedPath = prefix + path; + setFile(prefixedPath).toContent(""); + result.add(newFile(prefixedPath)); } + return result; } private List testFiles() { @@ -53,7 +48,7 @@ private List testFiles() { private static final List TEST_PATHS = Arrays.asList("someFile", "subfolder/someFile", "MANIFEST.MF", "subfolder/MANIFEST.MF"); @Test - void cacheTest() throws IOException { + void cacheTest() { setFile(".gitattributes").toContent(StringPrinter.buildStringFromLines( "* eol=lf", "*.MF eol=crlf")); @@ -84,7 +79,7 @@ void cacheTest() throws IOException { } @Test - void policyTest() throws IOException { + void policyTest() { setFile(".gitattributes").toContent(StringPrinter.buildStringFromLines( "* eol=lf", "*.MF eol=crlf")); @@ -96,7 +91,7 @@ void policyTest() throws IOException { } @Test - void policyDefaultLineEndingTest() throws GitAPIException, IOException { + void policyDefaultLineEndingTest() throws GitAPIException { Git git = Git.init().setDirectory(rootFolder()).call(); git.close(); setFile(".git/config").toContent(StringPrinter.buildStringFromLines( diff --git a/testlib/src/main/java/com/diffplug/spotless/ResourceHarness.java b/testlib/src/main/java/com/diffplug/spotless/ResourceHarness.java index b4a8bbae24..d4a79fe417 100644 --- a/testlib/src/main/java/com/diffplug/spotless/ResourceHarness.java +++ b/testlib/src/main/java/com/diffplug/spotless/ResourceHarness.java @@ -1,5 +1,5 @@ /* - * Copyright 2016-2021 DiffPlug + * Copyright 2016-2023 DiffPlug * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -54,7 +54,7 @@ protected File rootFolder() { } /** Returns a new child of the root folder. */ - protected File newFile(String subpath) throws IOException { + protected File newFile(String subpath) { return new File(rootFolder(), subpath); } @@ -85,16 +85,16 @@ protected void replace(String path, String toReplace, String replaceWith) throws } /** Returns the contents of the given file from the src/test/resources directory. */ - protected static String getTestResource(String filename) throws IOException { + protected static String getTestResource(String filename) { URL url = ResourceHarness.class.getResource("/" + filename); if (url == null) { throw new IllegalArgumentException("No such resource " + filename); } - return Resources.toString(url, StandardCharsets.UTF_8); + return ThrowingEx.get(() -> LineEnding.toUnix(Resources.toString(url, StandardCharsets.UTF_8))); } /** Returns Files (in a temporary folder) which has the contents of the given file from the src/test/resources directory. */ - protected List createTestFiles(String... filenames) throws IOException { + protected List createTestFiles(String... filenames) { List files = new ArrayList<>(filenames.length); for (String filename : filenames) { files.add(createTestFile(filename)); @@ -103,7 +103,7 @@ protected List createTestFiles(String... filenames) throws IOException { } /** Returns a File (in a temporary folder) which has the contents of the given file from the src/test/resources directory. */ - protected File createTestFile(String filename) throws IOException { + protected File createTestFile(String filename) { return createTestFile(filename, UnaryOperator.identity()); } @@ -111,39 +111,22 @@ protected File createTestFile(String filename) throws IOException { * Returns a File (in a temporary folder) which has the contents, possibly processed, of the given file from the * src/test/resources directory. */ - protected File createTestFile(String filename, UnaryOperator fileContentsProcessor) throws IOException { + protected File createTestFile(String filename, UnaryOperator fileContentsProcessor) { int lastSlash = filename.lastIndexOf('/'); String name = lastSlash >= 0 ? filename.substring(lastSlash) : filename; File file = newFile(name); file.getParentFile().mkdirs(); - Files.write(file.toPath(), fileContentsProcessor.apply(getTestResource(filename)).getBytes(StandardCharsets.UTF_8)); + ThrowingEx.run(() -> Files.write(file.toPath(), fileContentsProcessor.apply(getTestResource(filename)).getBytes(StandardCharsets.UTF_8))); return file; } - /** Reads the given resource from "before", applies the step, and makes sure the result is "after". */ - protected void assertOnResources(FormatterStep step, String unformattedPath, String expectedPath) throws Throwable { - assertOnResources(rawUnix -> step.format(rawUnix, new File("")), unformattedPath, expectedPath); - } - - /** Reads the given resource from "before", applies the step, and makes sure the result is "after". */ - protected void assertOnResources(FormatterFunc step, String unformattedPath, String expectedPath) throws Throwable { - String unformatted = LineEnding.toUnix(getTestResource(unformattedPath)); // unix-ified input - String formatted = step.apply(unformatted); - // no windows newlines - assertThat(formatted).doesNotContain("\r"); - - // unix-ify the test resource output in case git screwed it up - String expected = LineEnding.toUnix(getTestResource(expectedPath)); // unix-ified output - assertThat(formatted).isEqualTo(expected); - } - @CheckReturnValue - protected ReadAsserter assertFile(String path) throws IOException { + protected ReadAsserter assertFile(String path) { return new ReadAsserter(newFile(path)); } @CheckReturnValue - protected ReadAsserter assertFile(File file) throws IOException { + protected ReadAsserter assertFile(File file) { return new ReadAsserter(file); } @@ -176,7 +159,7 @@ public void matches(Consumer> conditions) } } - protected WriteAsserter setFile(String path) throws IOException { + protected WriteAsserter setFile(String path) { return new WriteAsserter(newFile(path)); } @@ -188,21 +171,25 @@ private WriteAsserter(File file) { this.file = file; } - public File toLines(String... lines) throws IOException { + public File toLines(String... lines) { return toContent(String.join("\n", Arrays.asList(lines))); } - public File toContent(String content) throws IOException { + public File toContent(String content) { return toContent(content, StandardCharsets.UTF_8); } - public File toContent(String content, Charset charset) throws IOException { - Files.write(file.toPath(), content.getBytes(charset)); + public File toContent(String content, Charset charset) { + ThrowingEx.run(() -> { + Files.write(file.toPath(), content.getBytes(charset)); + }); return file; } - public File toResource(String path) throws IOException { - Files.write(file.toPath(), getTestResource(path).getBytes(StandardCharsets.UTF_8)); + public File toResource(String path) { + ThrowingEx.run(() -> { + Files.write(file.toPath(), getTestResource(path).getBytes(StandardCharsets.UTF_8)); + }); return file; } diff --git a/testlib/src/main/java/com/diffplug/spotless/StepHarness.java b/testlib/src/main/java/com/diffplug/spotless/StepHarness.java index 8755f852d6..976a80df29 100644 --- a/testlib/src/main/java/com/diffplug/spotless/StepHarness.java +++ b/testlib/src/main/java/com/diffplug/spotless/StepHarness.java @@ -1,5 +1,5 @@ /* - * Copyright 2016-2021 DiffPlug + * Copyright 2016-2023 DiffPlug * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -22,31 +22,21 @@ import java.nio.file.Paths; import java.util.Arrays; import java.util.Objects; -import java.util.function.Consumer; -import org.assertj.core.api.AbstractThrowableAssert; +import org.assertj.core.api.AbstractStringAssert; import org.assertj.core.api.Assertions; /** An api for testing a {@code FormatterStep} that doesn't depend on the File path. DO NOT ADD FILE SUPPORT TO THIS, use {@link StepHarnessWithFile} if you need that. */ public class StepHarness implements AutoCloseable { - private final FormatterFunc formatter; + private final Formatter formatter; - private StepHarness(FormatterFunc formatter) { + private StepHarness(Formatter formatter) { this.formatter = Objects.requireNonNull(formatter); } /** Creates a harness for testing steps which don't depend on the file. */ public static StepHarness forStep(FormatterStep step) { - // We don't care if an individual FormatterStep is misbehaving on line-endings, because - // Formatter fixes that. No reason to care in tests either. It's likely to pop up when - // running tests on Windows from time-to-time - return new StepHarness(FormatterFunc.Closeable.ofDangerous( - () -> { - if (step instanceof FormatterStepImpl.Standard) { - ((FormatterStepImpl.Standard) step).cleanupFormatterFunc(); - } - }, - input -> LineEnding.toUnix(step.format(input, new File(""))))); + return forSteps(step); } /** Creates a harness for testing steps which don't depend on the file. */ @@ -61,55 +51,62 @@ public static StepHarness forSteps(FormatterStep... steps) { /** Creates a harness for testing a formatter whose steps don't depend on the file. */ public static StepHarness forFormatter(Formatter formatter) { - return new StepHarness(FormatterFunc.Closeable.ofDangerous( - formatter::close, - input -> formatter.compute(input, new File("")))); + return new StepHarness(formatter); } /** Asserts that the given element is transformed as expected, and that the result is idempotent. */ - public StepHarness test(String before, String after) throws Exception { - String actual = formatter.apply(before); + public StepHarness test(String before, String after) { + String actual = formatter.compute(LineEnding.toUnix(before), new File("")); assertEquals(after, actual, "Step application failed"); return testUnaffected(after); } /** Asserts that the given element is idempotent w.r.t the step under test. */ - public StepHarness testUnaffected(String idempotentElement) throws Exception { - String actual = formatter.apply(idempotentElement); + public StepHarness testUnaffected(String idempotentElement) { + String actual = formatter.compute(LineEnding.toUnix(idempotentElement), new File("")); assertEquals(idempotentElement, actual, "Step is not idempotent"); return this; } /** Asserts that the given elements in the resources directory are transformed as expected. */ - public StepHarness testResource(String resourceBefore, String resourceAfter) throws Exception { + public StepHarness testResource(String resourceBefore, String resourceAfter) { String before = ResourceHarness.getTestResource(resourceBefore); String after = ResourceHarness.getTestResource(resourceAfter); return test(before, after); } /** Asserts that the given elements in the resources directory are transformed as expected. */ - public StepHarness testResourceUnaffected(String resourceIdempotent) throws Exception { + public StepHarness testResourceUnaffected(String resourceIdempotent) { String idempotentElement = ResourceHarness.getTestResource(resourceIdempotent); return testUnaffected(idempotentElement); } - /** Asserts that the given elements in the resources directory are transformed as expected. */ - public StepHarness testResourceException(String resourceBefore, Consumer> exceptionAssertion) throws Exception { - return testException(ResourceHarness.getTestResource(resourceBefore), exceptionAssertion); + public AbstractStringAssert testResourceExceptionMsg(String resourceBefore) { + return testExceptionMsg(ResourceHarness.getTestResource(resourceBefore)); } - /** Asserts that the given elements in the resources directory are transformed as expected. */ - public StepHarness testException(String before, Consumer> exceptionAssertion) throws Exception { - Throwable t = assertThrows(Throwable.class, () -> formatter.apply(before)); - AbstractThrowableAssert abstractAssert = Assertions.assertThat(t); - exceptionAssertion.accept(abstractAssert); - return this; + public AbstractStringAssert testExceptionMsg(String before) { + try { + formatter.compute(LineEnding.toUnix(before), FormatterStepImpl.SENTINEL); + throw new SecurityException("Expected exception"); + } catch (Throwable e) { + if (e instanceof SecurityException) { + throw new AssertionError(e.getMessage()); + } else { + Throwable rootCause = e; + while (rootCause.getCause() != null) { + if (rootCause instanceof IllegalStateException) { + break; + } + rootCause = rootCause.getCause(); + } + return Assertions.assertThat(rootCause.getMessage()); + } + } } @Override public void close() { - if (formatter instanceof FormatterFunc.Closeable) { - ((FormatterFunc.Closeable) formatter).close(); - } + formatter.close(); } } diff --git a/testlib/src/main/java/com/diffplug/spotless/StepHarnessWithFile.java b/testlib/src/main/java/com/diffplug/spotless/StepHarnessWithFile.java index 89be961d04..3d01a6bd44 100644 --- a/testlib/src/main/java/com/diffplug/spotless/StepHarnessWithFile.java +++ b/testlib/src/main/java/com/diffplug/spotless/StepHarnessWithFile.java @@ -1,5 +1,5 @@ /* - * Copyright 2016-2021 DiffPlug + * Copyright 2016-2023 DiffPlug * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -18,78 +18,99 @@ import static org.junit.jupiter.api.Assertions.*; import java.io.File; +import java.nio.charset.StandardCharsets; +import java.util.Collections; import java.util.Objects; +import org.assertj.core.api.AbstractStringAssert; +import org.assertj.core.api.Assertions; + /** An api for testing a {@code FormatterStep} that depends on the File path. */ public class StepHarnessWithFile implements AutoCloseable { - private final FormatterFunc formatter; + private final Formatter formatter; + private final ResourceHarness harness; - private StepHarnessWithFile(FormatterFunc formatter) { + private StepHarnessWithFile(ResourceHarness harness, Formatter formatter) { + this.harness = Objects.requireNonNull(harness); this.formatter = Objects.requireNonNull(formatter); } /** Creates a harness for testing steps which do depend on the file. */ - public static StepHarnessWithFile forStep(FormatterStep step) { - // We don't care if an individual FormatterStep is misbehaving on line-endings, because - // Formatter fixes that. No reason to care in tests either. It's likely to pop up when - // running tests on Windows from time-to-time - return new StepHarnessWithFile(FormatterFunc.Closeable.ofDangerous( - () -> { - if (step instanceof FormatterStepImpl.Standard) { - ((FormatterStepImpl.Standard) step).cleanupFormatterFunc(); - } - }, - new FormatterFunc() { - @Override - public String apply(String unix) throws Exception { - return apply(unix, new File("")); - } - - @Override - public String apply(String unix, File file) throws Exception { - return LineEnding.toUnix(step.format(unix, file)); - } - })); + public static StepHarnessWithFile forStep(ResourceHarness harness, FormatterStep step) { + return new StepHarnessWithFile(harness, Formatter.builder() + .encoding(StandardCharsets.UTF_8) + .lineEndingsPolicy(LineEnding.UNIX.createPolicy()) + .steps(Collections.singletonList(step)) + .rootDir(harness.rootFolder().toPath()) + .build()); } /** Creates a harness for testing a formatter whose steps do depend on the file. */ - public static StepHarnessWithFile forFormatter(Formatter formatter) { - return new StepHarnessWithFile(FormatterFunc.Closeable.ofDangerous( - formatter::close, - input -> formatter.compute(input, new File("")))); + public static StepHarnessWithFile forFormatter(ResourceHarness harness, Formatter formatter) { + return new StepHarnessWithFile(harness, formatter); } /** Asserts that the given element is transformed as expected, and that the result is idempotent. */ - public StepHarnessWithFile test(File file, String before, String after) throws Exception { - String actual = formatter.apply(before, file); + public StepHarnessWithFile test(File file, String before, String after) { + String actual = formatter.compute(LineEnding.toUnix(before), file); assertEquals(after, actual, "Step application failed"); return testUnaffected(file, after); } /** Asserts that the given element is idempotent w.r.t the step under test. */ - public StepHarnessWithFile testUnaffected(File file, String idempotentElement) throws Exception { - String actual = formatter.apply(idempotentElement, file); + public StepHarnessWithFile testUnaffected(File file, String idempotentElement) { + String actual = formatter.compute(LineEnding.toUnix(idempotentElement), file); assertEquals(idempotentElement, actual, "Step is not idempotent"); return this; } /** Asserts that the given elements in the resources directory are transformed as expected. */ - public StepHarnessWithFile testResource(File file, String resourceBefore, String resourceAfter) throws Exception { - String before = ResourceHarness.getTestResource(resourceBefore); - String after = ResourceHarness.getTestResource(resourceAfter); - return test(file, before, after); + public StepHarnessWithFile testResource(String resourceBefore, String resourceAfter) { + return testResource(resourceBefore, resourceBefore, resourceAfter); + } + + public StepHarnessWithFile testResource(String filename, String resourceBefore, String resourceAfter) { + String contentBefore = ResourceHarness.getTestResource(resourceBefore); + File file = harness.setFile(filename).toContent(contentBefore); + return test(file, contentBefore, ResourceHarness.getTestResource(resourceAfter)); } /** Asserts that the given elements in the resources directory are transformed as expected. */ - public StepHarnessWithFile testResourceUnaffected(File file, String resourceIdempotent) throws Exception { - String idempotentElement = ResourceHarness.getTestResource(resourceIdempotent); - return testUnaffected(file, idempotentElement); + public StepHarnessWithFile testResourceUnaffected(String resourceIdempotent) { + String contentBefore = ResourceHarness.getTestResource(resourceIdempotent); + File file = harness.setFile(resourceIdempotent).toContent(contentBefore); + return testUnaffected(file, contentBefore); + } + + public AbstractStringAssert testResourceExceptionMsg(String resourceBefore) { + return testResourceExceptionMsg(resourceBefore, resourceBefore); + } + + public AbstractStringAssert testResourceExceptionMsg(String filename, String resourceBefore) { + String contentBefore = ResourceHarness.getTestResource(resourceBefore); + File file = harness.setFile(filename).toContent(contentBefore); + return testExceptionMsg(file, contentBefore); + } + + public AbstractStringAssert testExceptionMsg(File file, String before) { + try { + formatter.compute(LineEnding.toUnix(before), file); + throw new SecurityException("Expected exception"); + } catch (Throwable e) { + if (e instanceof SecurityException) { + throw new AssertionError(e.getMessage()); + } else { + Throwable rootCause = e; + while (rootCause.getCause() != null) { + rootCause = rootCause.getCause(); + } + return Assertions.assertThat(rootCause.getMessage()); + } + } } @Override public void close() { - if (formatter instanceof FormatterFunc.Closeable) { - ((FormatterFunc.Closeable) formatter).close(); - } + formatter.close(); } } diff --git a/testlib/src/test/java/com/diffplug/spotless/antlr4/Antlr4FormatterStepTest.java b/testlib/src/test/java/com/diffplug/spotless/antlr4/Antlr4FormatterStepTest.java index a26cbd4425..0f5b1b0bb7 100644 --- a/testlib/src/test/java/com/diffplug/spotless/antlr4/Antlr4FormatterStepTest.java +++ b/testlib/src/test/java/com/diffplug/spotless/antlr4/Antlr4FormatterStepTest.java @@ -1,5 +1,5 @@ /* - * Copyright 2016-2021 DiffPlug + * Copyright 2016-2023 DiffPlug * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -18,15 +18,13 @@ import org.junit.jupiter.api.Test; import com.diffplug.spotless.FormatterStep; -import com.diffplug.spotless.ResourceHarness; +import com.diffplug.spotless.StepHarness; import com.diffplug.spotless.TestProvisioner; -class Antlr4FormatterStepTest extends ResourceHarness { - +class Antlr4FormatterStepTest { @Test void formatGrammar() throws Throwable { FormatterStep step = Antlr4FormatterStep.create(TestProvisioner.mavenCentral()); - assertOnResources(step, "antlr4/Hello.unformatted.g4", "antlr4/Hello.formatted.g4"); + StepHarness.forStep(step).testResource("antlr4/Hello.unformatted.g4", "antlr4/Hello.formatted.g4"); } - } diff --git a/testlib/src/test/java/com/diffplug/spotless/cpp/ClangFormatStepTest.java b/testlib/src/test/java/com/diffplug/spotless/cpp/ClangFormatStepTest.java index cf0f551485..7e76b4eea1 100644 --- a/testlib/src/test/java/com/diffplug/spotless/cpp/ClangFormatStepTest.java +++ b/testlib/src/test/java/com/diffplug/spotless/cpp/ClangFormatStepTest.java @@ -1,5 +1,5 @@ /* - * Copyright 2020-2021 DiffPlug + * Copyright 2020-2023 DiffPlug * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -15,26 +15,26 @@ */ package com.diffplug.spotless.cpp; -import java.io.File; import java.util.Arrays; import org.junit.jupiter.api.Test; +import com.diffplug.spotless.ResourceHarness; import com.diffplug.spotless.StepHarnessWithFile; import com.diffplug.spotless.tag.ClangTest; @ClangTest -class ClangFormatStepTest { +class ClangFormatStepTest extends ResourceHarness { @Test - void test() throws Exception { - try (StepHarnessWithFile harness = StepHarnessWithFile.forStep(ClangFormatStep.withVersion(ClangFormatStep.defaultVersion()).create())) { + void test() { + try (StepHarnessWithFile harness = StepHarnessWithFile.forStep(this, ClangFormatStep.withVersion(ClangFormatStep.defaultVersion()).create())) { // can't be named java or it gets compiled into .class file - harness.testResource(new File("example.java"), "clang/example.java.dirty", "clang/example.java.clean"); + harness.testResource("example.java", "clang/example.java.dirty", "clang/example.java.clean"); // test every other language clang supports for (String ext : Arrays.asList("c", "cs", "js", "m", "proto")) { String filename = "example." + ext; String root = "clang/" + filename; - harness.testResource(new File(filename), root, root + ".clean"); + harness.testResource(filename, root, root + ".clean"); } } } diff --git a/testlib/src/test/java/com/diffplug/spotless/generic/IndentStepTest.java b/testlib/src/test/java/com/diffplug/spotless/generic/IndentStepTest.java index c7df4639e3..38503d7182 100644 --- a/testlib/src/test/java/com/diffplug/spotless/generic/IndentStepTest.java +++ b/testlib/src/test/java/com/diffplug/spotless/generic/IndentStepTest.java @@ -1,5 +1,5 @@ /* - * Copyright 2016-2022 DiffPlug + * Copyright 2016-2023 DiffPlug * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -15,46 +15,42 @@ */ package com.diffplug.spotless.generic; -import java.io.File; - -import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Test; import com.diffplug.spotless.FormatterStep; -import com.diffplug.spotless.ResourceHarness; import com.diffplug.spotless.SerializableEqualityTester; import com.diffplug.spotless.StepHarness; -class IndentStepTest extends ResourceHarness { +class IndentStepTest { @Test - void tabToTab() throws Throwable { + void tabToTab() { FormatterStep indent = IndentStep.Type.TAB.create(4); - assertOnResources(indent, "indent/IndentedWithTab.test", "indent/IndentedWithTab.test"); + StepHarness.forStep(indent).testResource("indent/IndentedWithTab.test", "indent/IndentedWithTab.test"); } @Test - void spaceToSpace() throws Throwable { + void spaceToSpace() { FormatterStep indent = IndentStep.Type.SPACE.create(4); - assertOnResources(indent, "indent/IndentedWithSpace.test", "indent/IndentedWithSpace.test"); + StepHarness.forStep(indent).testResource("indent/IndentedWithSpace.test", "indent/IndentedWithSpace.test"); } @Test - void spaceToTab() throws Throwable { + void spaceToTab() { FormatterStep indent = IndentStep.Type.TAB.create(4); - assertOnResources(indent, "indent/IndentedWithSpace.test", "indent/IndentedWithTab.test"); + StepHarness.forStep(indent).testResource("indent/IndentedWithSpace.test", "indent/IndentedWithTab.test"); } @Test - void tabToSpace() throws Throwable { + void tabToSpace() { FormatterStep indent = IndentStep.Type.SPACE.create(4); - assertOnResources(indent, "indent/IndentedWithTab.test", "indent/IndentedWithSpace.test"); + StepHarness.forStep(indent).testResource("indent/IndentedWithTab.test", "indent/IndentedWithSpace.test"); } @Test - void doesntClipNewlines() throws Throwable { + void doesntClipNewlines() { FormatterStep indent = IndentStep.Type.SPACE.create(4); String blankNewlines = "\n\n\n\n"; - Assertions.assertEquals(blankNewlines, indent.format(blankNewlines, new File(""))); + StepHarness.forStep(indent).testUnaffected(blankNewlines); } @Test diff --git a/testlib/src/test/java/com/diffplug/spotless/generic/PipeStepPairTest.java b/testlib/src/test/java/com/diffplug/spotless/generic/PipeStepPairTest.java index 6bb144e6b4..b648432b92 100644 --- a/testlib/src/test/java/com/diffplug/spotless/generic/PipeStepPairTest.java +++ b/testlib/src/test/java/com/diffplug/spotless/generic/PipeStepPairTest.java @@ -1,5 +1,5 @@ /* - * Copyright 2020-2021 DiffPlug + * Copyright 2020-2023 DiffPlug * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -27,7 +27,7 @@ class PipeStepPairTest { @Test - void single() throws Exception { + void single() { PipeStepPair pair = PipeStepPair.named("underTest").openClose("spotless:off", "spotless:on").buildPair(); FormatterStep lowercase = FormatterStep.createNeverUpToDate("lowercase", str -> str.toLowerCase(Locale.ROOT)); StepHarness harness = StepHarness.forSteps(pair.in(), lowercase, pair.out()); @@ -47,7 +47,7 @@ void single() throws Exception { } @Test - void multiple() throws Exception { + void multiple() { PipeStepPair pair = PipeStepPair.named("underTest").openClose("spotless:off", "spotless:on").buildPair(); FormatterStep lowercase = FormatterStep.createNeverUpToDate("lowercase", str -> str.toLowerCase(Locale.ROOT)); StepHarness harness = StepHarness.forSteps(pair.in(), lowercase, pair.out()); @@ -81,23 +81,21 @@ void multiple() throws Exception { } @Test - void broken() throws Exception { + void broken() { PipeStepPair pair = PipeStepPair.named("underTest").openClose("spotless:off", "spotless:on").buildPair(); FormatterStep uppercase = FormatterStep.createNeverUpToDate("uppercase", str -> str.toUpperCase(Locale.ROOT)); StepHarness harness = StepHarness.forSteps(pair.in(), uppercase, pair.out()); // this fails because uppercase turns spotless:off into SPOTLESS:OFF, etc - harness.testException(StringPrinter.buildStringFromLines( + harness.testExceptionMsg(StringPrinter.buildStringFromLines( "A B C", "spotless:off", "D E F", "spotless:on", - "G H I"), exception -> { - exception.hasMessage("An intermediate step removed a match of spotless:off spotless:on"); - }); + "G H I")).isEqualTo("An intermediate step removed a match of spotless:off spotless:on"); } @Test - void andApply() throws Exception { + void andApply() { FormatterStep lowercase = FormatterStep.createNeverUpToDate("lowercase", str -> str.toLowerCase(Locale.ROOT)); FormatterStep lowercaseSometimes = PipeStepPair.named("lowercaseSometimes").openClose("", "") .buildStepWhichAppliesSubSteps(Paths.get(""), Arrays.asList(lowercase)); diff --git a/testlib/src/test/java/com/diffplug/spotless/java/FormatAnnotationsStepTest.java b/testlib/src/test/java/com/diffplug/spotless/java/FormatAnnotationsStepTest.java index 84d347e490..7aa0b64c00 100644 --- a/testlib/src/test/java/com/diffplug/spotless/java/FormatAnnotationsStepTest.java +++ b/testlib/src/test/java/com/diffplug/spotless/java/FormatAnnotationsStepTest.java @@ -1,5 +1,5 @@ /* - * Copyright 2022 DiffPlug + * Copyright 2022-2023 DiffPlug * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -20,26 +20,26 @@ import org.junit.jupiter.api.Test; import com.diffplug.spotless.FormatterStep; -import com.diffplug.spotless.ResourceHarness; import com.diffplug.spotless.SerializableEqualityTester; +import com.diffplug.spotless.StepHarness; -class FormatAnnotationsStepTest extends ResourceHarness { +class FormatAnnotationsStepTest { @Test - void formatAnnotations() throws Throwable { + void formatAnnotations() { FormatterStep step = FormatAnnotationsStep.create(); - assertOnResources(step, "java/formatannotations/FormatAnnotationsTestInput.test", "java/formatannotations/FormatAnnotationsTestOutput.test"); + StepHarness.forStep(step).testResource("java/formatannotations/FormatAnnotationsTestInput.test", "java/formatannotations/FormatAnnotationsTestOutput.test"); } @Test - void formatAnnotationsInComments() throws Throwable { + void formatAnnotationsInComments() { FormatterStep step = FormatAnnotationsStep.create(); - assertOnResources(step, "java/formatannotations/FormatAnnotationsInCommentsInput.test", "java/formatannotations/FormatAnnotationsInCommentsOutput.test"); + StepHarness.forStep(step).testResource("java/formatannotations/FormatAnnotationsInCommentsInput.test", "java/formatannotations/FormatAnnotationsInCommentsOutput.test"); } @Test - void formatAnnotationsAddRemove() throws Throwable { + void formatAnnotationsAddRemove() { FormatterStep step = FormatAnnotationsStep.create(Arrays.asList("Empty", "NonEmpty"), Arrays.asList("Localized")); - assertOnResources(step, "java/formatannotations/FormatAnnotationsAddRemoveInput.test", "java/formatannotations/FormatAnnotationsAddRemoveOutput.test"); + StepHarness.forStep(step).testResource("java/formatannotations/FormatAnnotationsAddRemoveInput.test", "java/formatannotations/FormatAnnotationsAddRemoveOutput.test"); } @Test diff --git a/testlib/src/test/java/com/diffplug/spotless/java/ImportOrderStepTest.java b/testlib/src/test/java/com/diffplug/spotless/java/ImportOrderStepTest.java index 32cf0a97c0..8f3bd799bc 100644 --- a/testlib/src/test/java/com/diffplug/spotless/java/ImportOrderStepTest.java +++ b/testlib/src/test/java/com/diffplug/spotless/java/ImportOrderStepTest.java @@ -1,5 +1,5 @@ /* - * Copyright 2016-2022 DiffPlug + * Copyright 2016-2023 DiffPlug * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -20,72 +20,73 @@ import com.diffplug.spotless.FormatterStep; import com.diffplug.spotless.ResourceHarness; import com.diffplug.spotless.SerializableEqualityTester; +import com.diffplug.spotless.StepHarness; class ImportOrderStepTest extends ResourceHarness { @Test - void sortImportsDefault() throws Throwable { + void sortImportsDefault() { FormatterStep step = ImportOrderStep.forJava().createFrom(); - assertOnResources(step, "java/importsorter/JavaCodeUnsortedImports.test", "java/importsorter/JavaCodeSortedImportsDefault.test"); + StepHarness.forStep(step).testResource("java/importsorter/JavaCodeUnsortedImports.test", "java/importsorter/JavaCodeSortedImportsDefault.test"); } @Test - void sortImportsFromArray() throws Throwable { + void sortImportsFromArray() { FormatterStep step = ImportOrderStep.forJava().createFrom("java", "javax", "org", "\\#com"); - assertOnResources(step, "java/importsorter/JavaCodeUnsortedImports.test", "java/importsorter/JavaCodeSortedImports.test"); + StepHarness.forStep(step).testResource("java/importsorter/JavaCodeUnsortedImports.test", "java/importsorter/JavaCodeSortedImports.test"); } @Test - void sortImportsFromArrayWithSubgroups() throws Throwable { + void sortImportsFromArrayWithSubgroups() { FormatterStep step = ImportOrderStep.forJava().createFrom("java|javax", "org|\\#com", "\\#"); - assertOnResources(step, "java/importsorter/JavaCodeUnsortedImportsSubgroups.test", "java/importsorter/JavaCodeSortedImportsSubgroups.test"); + StepHarness.forStep(step).testResource("java/importsorter/JavaCodeUnsortedImportsSubgroups.test", "java/importsorter/JavaCodeSortedImportsSubgroups.test"); } @Test - void sortImportsFromFile() throws Throwable { + void sortImportsFromFile() { FormatterStep step = ImportOrderStep.forJava().createFrom(createTestFile("java/importsorter/import.properties")); - assertOnResources(step, "java/importsorter/JavaCodeUnsortedImports.test", "java/importsorter/JavaCodeSortedImports.test"); + StepHarness.forStep(step).testResource("java/importsorter/JavaCodeUnsortedImports.test", "java/importsorter/JavaCodeSortedImports.test"); } @Test - void sortImportsUnmatched() throws Throwable { + void sortImportsUnmatched() { FormatterStep step = ImportOrderStep.forJava().createFrom(createTestFile("java/importsorter/import_unmatched.properties")); - assertOnResources(step, "java/importsorter/JavaCodeUnsortedImportsUnmatched.test", "java/importsorter/JavaCodeSortedImportsUnmatched.test"); + StepHarness.forStep(step).testResource("java/importsorter/JavaCodeUnsortedImportsUnmatched.test", "java/importsorter/JavaCodeSortedImportsUnmatched.test"); } @Test - void sortImportsWildcardsLast() throws Throwable { + void sortImportsWildcardsLast() { FormatterStep step = ImportOrderStep.forJava().createFrom(true); - assertOnResources(step, "java/importsorter/JavaCodeUnsortedImports.test", "java/importsorter/JavaCodeSortedImportsWildcardsLast.test"); + StepHarness.forStep(step).testResource("java/importsorter/JavaCodeUnsortedImports.test", "java/importsorter/JavaCodeSortedImportsWildcardsLast.test"); } @Test - void removeDuplicates() throws Throwable { + void removeDuplicates() { FormatterStep step = ImportOrderStep.forJava().createFrom(createTestFile("java/importsorter/import_unmatched.properties")); - assertOnResources(step, "java/importsorter/JavaCodeSortedDuplicateImportsUnmatched.test", "java/importsorter/JavaCodeSortedImportsUnmatched.test"); + StepHarness.forStep(step).testResource("java/importsorter/JavaCodeSortedDuplicateImportsUnmatched.test", "java/importsorter/JavaCodeSortedImportsUnmatched.test"); } @Test - void removeComments() throws Throwable { + void removeComments() { FormatterStep step = ImportOrderStep.forJava().createFrom(createTestFile("java/importsorter/import.properties")); - assertOnResources(step, "java/importsorter/JavaCodeImportComments.test", "java/importsorter/JavaCodeSortedImports.test"); + StepHarness.forStep(step).testResource("java/importsorter/JavaCodeImportComments.test", "java/importsorter/JavaCodeSortedImports.test"); } @Test - void misplacedImports() throws Throwable { + void misplacedImports() { FormatterStep step = ImportOrderStep.forJava().createFrom(createTestFile("java/importsorter/import.properties")); - assertOnResources(step, "java/importsorter/JavaCodeUnsortedMisplacedImports.test", "java/importsorter/JavaCodeSortedMisplacedImports.test"); + StepHarness.forStep(step).testResource("java/importsorter/JavaCodeUnsortedMisplacedImports.test", "java/importsorter/JavaCodeSortedMisplacedImports.test"); } @Test - void empty() throws Throwable { + void empty() { FormatterStep step = ImportOrderStep.forJava().createFrom(createTestFile("java/importsorter/import.properties")); - assertOnResources(step, "java/importsorter/JavaCodeEmptyFile.test", "java/importsorter/JavaCodeEmptyFile.test"); + StepHarness.forStep(step).testResource("java/importsorter/JavaCodeEmptyFile.test", "java/importsorter/JavaCodeEmptyFile.test"); } @Test - void groovyImports() throws Throwable { + void groovyImports() { FormatterStep step = ImportOrderStep.forGroovy().createFrom(createTestFile("java/importsorter/import.properties")); - assertOnResources(step, "java/importsorter/GroovyCodeUnsortedMisplacedImports.test", "java/importsorter/GroovyCodeSortedMisplacedImports.test"); + StepHarness.forStep(step).testResource("java/importsorter/GroovyCodeUnsortedMisplacedImports.test", "java/importsorter/GroovyCodeSortedMisplacedImports.test"); } @Test diff --git a/testlib/src/test/java/com/diffplug/spotless/json/JsonFormatterStepCommonTests.java b/testlib/src/test/java/com/diffplug/spotless/json/JsonFormatterStepCommonTests.java index 9ee76f994c..fbdb6e9a4e 100644 --- a/testlib/src/test/java/com/diffplug/spotless/json/JsonFormatterStepCommonTests.java +++ b/testlib/src/test/java/com/diffplug/spotless/json/JsonFormatterStepCommonTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2022 DiffPlug + * Copyright 2022-2023 DiffPlug * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -95,10 +95,9 @@ protected StepHarness getStepHarness() { return StepHarness.forStep(createFormatterStep(INDENT, TestProvisioner.mavenCentral())); } - protected void doWithResource(String name) throws Exception { + protected void doWithResource(String name) { String before = String.format("json/%sBefore.json", name); String after = String.format("json/%sAfter.json", name); getStepHarness().testResource(before, after); } - } diff --git a/testlib/src/test/java/com/diffplug/spotless/json/JsonSimpleStepTest.java b/testlib/src/test/java/com/diffplug/spotless/json/JsonSimpleStepTest.java index b4f98e69ba..19edc1a8e8 100644 --- a/testlib/src/test/java/com/diffplug/spotless/json/JsonSimpleStepTest.java +++ b/testlib/src/test/java/com/diffplug/spotless/json/JsonSimpleStepTest.java @@ -1,5 +1,5 @@ /* - * Copyright 2021-2022 DiffPlug + * Copyright 2021-2023 DiffPlug * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -19,48 +19,115 @@ import org.junit.jupiter.api.Test; -import com.diffplug.spotless.*; +import com.diffplug.spotless.FormatterStep; +import com.diffplug.spotless.SerializableEqualityTester; +import com.diffplug.spotless.StepHarness; +import com.diffplug.spotless.TestProvisioner; -class JsonSimpleStepTest extends JsonFormatterStepCommonTests { +class JsonSimpleStepTest { + + private static final int INDENT = 4; + + private final FormatterStep step = JsonSimpleStep.create(INDENT, TestProvisioner.mavenCentral()); + private final StepHarness stepHarness = StepHarness.forStep(step); + + @Test + void cannotProvidedNullProvisioner() { + assertThatThrownBy(() -> JsonSimpleStep.create(INDENT, null)).isInstanceOf(NullPointerException.class).hasMessage("provisioner cannot be null"); + } + + @Test + void handlesSingletonObject() { + doWithResource(stepHarness, "singletonObject"); + } + + @Test + void handlesSingletonObjectWithArray() { + doWithResource(stepHarness, "singletonObjectWithArray"); + } + + @Test + void handlesNestedObject() { + doWithResource(stepHarness, "nestedObject"); + } @Test - void handlesSingletonObject() throws Exception { - doWithResource("singletonObject"); + void handlesSingletonArray() { + doWithResource(stepHarness, "singletonArray"); } @Test - void handlesSingletonObjectWithArray() throws Exception { - doWithResource("singletonObjectWithArray"); + void handlesEmptyFile() { + doWithResource(stepHarness, "empty"); } @Test - void handlesComplexNestedObject() throws Exception { - doWithResource("cucumberJsonSample"); + void handlesComplexNestedObject() { + doWithResource(stepHarness, "cucumberJsonSample"); } @Test - void handlesObjectWithNull() throws Exception { - doWithResource("objectWithNull"); + void handlesObjectWithNull() { + doWithResource(stepHarness, "objectWithNull"); } @Test void handlesInvalidJson() { - assertThatThrownBy(() -> doWithResource("invalidJson")) - .isInstanceOf(AssertionError.class) - .hasMessage("Unable to format JSON") - .hasRootCauseMessage("Expected a ',' or '}' at 9 [character 0 line 3]"); + stepHarness.testResourceExceptionMsg("json/invalidJsonBefore.json") + .contains("Expected a ',' or '}' at 9 [character 0 line 3]"); } @Test void handlesNotJson() { - assertThatThrownBy(() -> doWithResource("notJson")) - .isInstanceOf(AssertionError.class) - .hasMessage("Unable to determine JSON type, expected a '{' or '[' but found '#'") - .hasNoCause(); + stepHarness.testResourceExceptionMsg("json/notJsonBefore.json") + .contains("Unable to determine JSON type, expected a '{' or '[' but found '#'"); + } + + @Test + void canSetCustomIndentationLevel() { + FormatterStep step = JsonSimpleStep.create(6, TestProvisioner.mavenCentral()); + StepHarness stepHarness = StepHarness.forStep(step); + + String before = "json/singletonArrayBefore.json"; + String after = "json/singletonArrayAfter6Spaces.json"; + stepHarness.testResource(before, after); + } + + @Test + void canSetIndentationLevelTo0() { + FormatterStep step = JsonSimpleStep.create(0, TestProvisioner.mavenCentral()); + StepHarness stepHarness = StepHarness.forStep(step); + + String before = "json/singletonArrayBefore.json"; + String after = "json/singletonArrayAfter0Spaces.json"; + stepHarness.testResource(before, after); + } + + @Test + void equality() { + new SerializableEqualityTester() { + int spaces = 0; + + @Override + protected void setupTest(API api) { + // no changes, are the same + api.areDifferentThan(); + + // with different spacing + spaces = 1; + api.areDifferentThan(); + } + + @Override + protected FormatterStep create() { + return JsonSimpleStep.create(spaces, TestProvisioner.mavenCentral()); + } + }.testEquals(); } - @Override - protected FormatterStep createFormatterStep(int indent, Provisioner provisioner) { - return JsonSimpleStep.create(indent, provisioner); + private static void doWithResource(StepHarness stepHarness, String name) { + String before = String.format("json/%sBefore.json", name); + String after = String.format("json/%sAfter.json", name); + stepHarness.testResource(before, after); } } diff --git a/testlib/src/test/java/com/diffplug/spotless/json/gson/GsonStepTest.java b/testlib/src/test/java/com/diffplug/spotless/json/gson/GsonStepTest.java index cf1fd10752..8f1d758836 100644 --- a/testlib/src/test/java/com/diffplug/spotless/json/gson/GsonStepTest.java +++ b/testlib/src/test/java/com/diffplug/spotless/json/gson/GsonStepTest.java @@ -1,5 +1,5 @@ /* - * Copyright 2022 DiffPlug + * Copyright 2022-2023 DiffPlug * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -15,8 +15,9 @@ */ package com.diffplug.spotless.json.gson; -import static org.assertj.core.api.Assertions.assertThatThrownBy; +import java.io.File; +import org.assertj.core.api.Assertions; import org.junit.jupiter.api.Test; import com.diffplug.spotless.FormatterStep; @@ -30,54 +31,47 @@ public class GsonStepTest extends JsonFormatterStepCommonTests { private static final String DEFAULT_VERSION = "2.8.9"; @Test - void handlesComplexNestedObject() throws Exception { + void handlesComplexNestedObject() { doWithResource("cucumberJsonSampleGson"); } @Test - void handlesObjectWithNull() throws Exception { + void handlesObjectWithNull() { doWithResource("objectWithNullGson"); } @Test void handlesInvalidJson() { - assertThatThrownBy(() -> doWithResource("invalidJson")) - .isInstanceOf(AssertionError.class) - .hasMessage("Unable to format JSON") - .hasRootCauseMessage("End of input at line 3 column 1 path $.a"); + getStepHarness().testResourceExceptionMsg("json/invalidJsonBefore.json").isEqualTo("End of input at line 3 column 1 path $.a"); } @Test void handlesNotJson() { - assertThatThrownBy(() -> doWithResource("notJson")) - .isInstanceOf(AssertionError.class) - .hasMessage("Unable to format JSON") - .hasNoCause(); + getStepHarness().testResourceExceptionMsg("json/notJsonBefore.json").isEqualTo("Unable to format JSON"); } @Test - void handlesSortingWhenSortByKeyEnabled() throws Exception { + void handlesSortingWhenSortByKeyEnabled() { FormatterStep step = GsonStep.create(INDENT, true, false, DEFAULT_VERSION, TestProvisioner.mavenCentral()); - StepHarness stepHarness = StepHarness.forStep(step); - stepHarness.testResource("json/sortByKeysBefore.json", "json/sortByKeysAfter.json"); + StepHarness.forStep(step).testResource("json/sortByKeysBefore.json", "json/sortByKeysAfter.json"); } @Test - void doesNoSortingWhenSortByKeyDisabled() throws Exception { + void doesNoSortingWhenSortByKeyDisabled() { FormatterStep step = GsonStep.create(INDENT, false, false, DEFAULT_VERSION, TestProvisioner.mavenCentral()); StepHarness.forStep(step) .testResource("json/sortByKeysBefore.json", "json/sortByKeysAfterDisabled.json"); } @Test - void handlesHtmlEscapeWhenEnabled() throws Exception { + void handlesHtmlEscapeWhenEnabled() { FormatterStep step = GsonStep.create(INDENT, false, true, DEFAULT_VERSION, TestProvisioner.mavenCentral()); StepHarness.forStep(step) .testResource("json/escapeHtmlGsonBefore.json", "json/escapeHtmlGsonAfter.json"); } @Test - void writesRawHtmlWhenHtmlEscapeDisabled() throws Exception { + void writesRawHtmlWhenHtmlEscapeDisabled() { FormatterStep step = GsonStep.create(INDENT, false, false, DEFAULT_VERSION, TestProvisioner.mavenCentral()); StepHarness.forStep(step) .testResource("json/escapeHtmlGsonBefore.json", "json/escapeHtmlGsonAfterDisabled.json"); @@ -86,8 +80,7 @@ void writesRawHtmlWhenHtmlEscapeDisabled() throws Exception { @Test void handlesVersionIncompatibility() { FormatterStep step = GsonStep.create(INDENT, false, false, "1.7", TestProvisioner.mavenCentral()); - StepHarness stepHarness = StepHarness.forStep(step); - assertThatThrownBy(() -> stepHarness.testResource("json/cucumberJsonSampleGsonBefore.json", "json/cucumberJsonSampleGsonAfter.json")) + Assertions.assertThatThrownBy(() -> step.format("", new File(""))) .isInstanceOf(IllegalStateException.class) .hasMessage("There was a problem interacting with Gson; maybe you set an incompatible version?"); } diff --git a/testlib/src/test/java/com/diffplug/spotless/kotlin/DiktatStepTest.java b/testlib/src/test/java/com/diffplug/spotless/kotlin/DiktatStepTest.java index 45bf6524f1..5055f47e8d 100644 --- a/testlib/src/test/java/com/diffplug/spotless/kotlin/DiktatStepTest.java +++ b/testlib/src/test/java/com/diffplug/spotless/kotlin/DiktatStepTest.java @@ -1,5 +1,5 @@ /* - * Copyright 2021-2022 DiffPlug + * Copyright 2021-2023 DiffPlug * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -25,27 +25,19 @@ import com.diffplug.spotless.FileSignature; import com.diffplug.spotless.FormatterStep; import com.diffplug.spotless.ResourceHarness; -import com.diffplug.spotless.StepHarness; +import com.diffplug.spotless.StepHarnessWithFile; import com.diffplug.spotless.TestProvisioner; class DiktatStepTest extends ResourceHarness { @Test - void behavior() throws Exception { + void behavior() { FormatterStep step = DiktatStep.create(TestProvisioner.mavenCentral()); - StepHarness.forStep(step) - .testResourceException("kotlin/diktat/Unsolvable.kt", assertion -> { - assertion.isInstanceOf(AssertionError.class); - assertion.hasMessage("There are 4 unfixed errors:" + - System.lineSeparator() + "Error on line: 1, column: 1 cannot be fixed automatically" + - System.lineSeparator() + "[FILE_NAME_INCORRECT] file name is incorrect - it should end with .kt extension and be in PascalCase: testlib" + - System.lineSeparator() + "Error on line: 1, column: 1 cannot be fixed automatically" + - System.lineSeparator() + "[FILE_NAME_MATCH_CLASS] file name is incorrect - it should match with the class described in it if there is the only one class declared: testlib vs Unsolvable" + - System.lineSeparator() + "Error on line: 1, column: 1 cannot be fixed automatically" + - System.lineSeparator() + "[DEBUG_PRINT] use a dedicated logging library: found println()" + - System.lineSeparator() + "Error on line: 13, column: 9 cannot be fixed automatically" + - System.lineSeparator() + "[DEBUG_PRINT] use a dedicated logging library: found println()"); - }); + StepHarnessWithFile.forStep(this, step).testResourceExceptionMsg("kotlin/diktat/Unsolvable.kt").isEqualTo("There are 2 unfixed errors:" + + System.lineSeparator() + "Error on line: 1, column: 1 cannot be fixed automatically" + + System.lineSeparator() + "[DEBUG_PRINT] use a dedicated logging library: found println()" + + System.lineSeparator() + "Error on line: 13, column: 9 cannot be fixed automatically" + + System.lineSeparator() + "[DEBUG_PRINT] use a dedicated logging library: found println()"); } @Test @@ -55,19 +47,11 @@ void behaviorConf() throws Exception { FileSignature config = signAsList(conf); FormatterStep step = DiktatStep.create("1.2.1", TestProvisioner.mavenCentral(), config); - StepHarness.forStep(step) - .testResourceException("kotlin/diktat/Unsolvable.kt", assertion -> { - assertion.isInstanceOf(AssertionError.class); - assertion.hasMessage("There are 4 unfixed errors:" + - System.lineSeparator() + "Error on line: 1, column: 1 cannot be fixed automatically" + - System.lineSeparator() + "[FILE_NAME_INCORRECT] file name is incorrect - it should end with .kt extension and be in PascalCase: testlib" + - System.lineSeparator() + "Error on line: 1, column: 1 cannot be fixed automatically" + - System.lineSeparator() + "[FILE_NAME_MATCH_CLASS] file name is incorrect - it should match with the class described in it if there is the only one class declared: testlib vs Unsolvable" + - System.lineSeparator() + "Error on line: 1, column: 1 cannot be fixed automatically" + - System.lineSeparator() + "[DEBUG_PRINT] use a dedicated logging library: found println()" + - System.lineSeparator() + "Error on line: 13, column: 9 cannot be fixed automatically" + - System.lineSeparator() + "[DEBUG_PRINT] use a dedicated logging library: found println()"); - }); + StepHarnessWithFile.forStep(this, step).testResourceExceptionMsg("kotlin/diktat/Unsolvable.kt").isEqualTo("There are 2 unfixed errors:" + + System.lineSeparator() + "Error on line: 1, column: 1 cannot be fixed automatically" + + System.lineSeparator() + "[DEBUG_PRINT] use a dedicated logging library: found println()" + + System.lineSeparator() + "Error on line: 13, column: 9 cannot be fixed automatically" + + System.lineSeparator() + "[DEBUG_PRINT] use a dedicated logging library: found println()"); } @Test diff --git a/testlib/src/test/java/com/diffplug/spotless/kotlin/KtLintStepTest.java b/testlib/src/test/java/com/diffplug/spotless/kotlin/KtLintStepTest.java index 42e377fde5..94de314e0b 100644 --- a/testlib/src/test/java/com/diffplug/spotless/kotlin/KtLintStepTest.java +++ b/testlib/src/test/java/com/diffplug/spotless/kotlin/KtLintStepTest.java @@ -22,62 +22,56 @@ import com.diffplug.spotless.ResourceHarness; import com.diffplug.spotless.SerializableEqualityTester; import com.diffplug.spotless.StepHarness; +import com.diffplug.spotless.StepHarnessWithFile; import com.diffplug.spotless.TestProvisioner; class KtLintStepTest extends ResourceHarness { @Test - void behavior() throws Exception { + void behavior() { FormatterStep step = KtLintStep.create(TestProvisioner.mavenCentral()); - StepHarness.forStep(step) + StepHarnessWithFile.forStep(this, step) .testResource("kotlin/ktlint/basic.dirty", "kotlin/ktlint/basic.clean") - .testResourceException("kotlin/ktlint/unsolvable.dirty", assertion -> { - assertion.isInstanceOf(AssertionError.class); - assertion.hasMessage("Error on line: 1, column: 1\n" + - "rule: no-wildcard-imports\n" + - "Wildcard import"); - }); + .testResourceExceptionMsg("kotlin/ktlint/unsolvable.dirty").isEqualTo( + "Error on line: 1, column: 1\n" + + "rule: no-wildcard-imports\n" + + "Wildcard import"); } @Test - void worksShyiko() throws Exception { + void worksShyiko() { FormatterStep step = KtLintStep.create("0.31.0", TestProvisioner.mavenCentral()); - StepHarness.forStep(step) + StepHarnessWithFile.forStep(this, step) .testResource("kotlin/ktlint/basic.dirty", "kotlin/ktlint/basic.clean") - .testResourceException("kotlin/ktlint/unsolvable.dirty", assertion -> { - assertion.isInstanceOf(AssertionError.class); - assertion.hasMessage("Error on line: 1, column: 1\n" + - "rule: no-wildcard-imports\n" + - "Wildcard import"); - }); + .testResourceExceptionMsg("kotlin/ktlint/unsolvable.dirty").isEqualTo( + "Error on line: 1, column: 1\n" + + "rule: no-wildcard-imports\n" + + "Wildcard import"); } // Regression test to ensure it works on the version it switched to Pinterest (version 0.32.0) // but before 0.34. // https://github.com/diffplug/spotless/issues/419 @Test - void worksPinterestAndPre034() throws Exception { + void worksPinterestAndPre034() { FormatterStep step = KtLintStep.create("0.32.0", TestProvisioner.mavenCentral()); - StepHarness.forStep(step) + StepHarnessWithFile.forStep(this, step) .testResource("kotlin/ktlint/basic.dirty", "kotlin/ktlint/basic.clean") - .testResourceException("kotlin/ktlint/unsolvable.dirty", assertion -> { - assertion.isInstanceOf(AssertionError.class); - assertion.hasMessage("Error on line: 1, column: 1\n" + - "rule: no-wildcard-imports\n" + - "Wildcard import"); - }); + .testResourceExceptionMsg("kotlin/ktlint/unsolvable.dirty").isEqualTo("Error on line: 1, column: 1\n" + + "rule: no-wildcard-imports\n" + + "Wildcard import"); } // Regression test to handle alpha and 1.x version numbers // https://github.com/diffplug/spotless/issues/668 @Test - void worksAlpha1() throws Exception { + void worksAlpha1() { FormatterStep step = KtLintStep.create("0.38.0-alpha01", TestProvisioner.mavenCentral()); StepHarness.forStep(step) .testResource("kotlin/ktlint/basic.dirty", "kotlin/ktlint/basic.clean"); } @Test - void works0_44_0() throws Exception { + void works0_44_0() { FormatterStep step = KtLintStep.create("0.44.0", TestProvisioner.mavenCentral()); StepHarness.forStep(step) .testResource("kotlin/ktlint/basic.dirty", "kotlin/ktlint/basic.clean"); @@ -85,80 +79,68 @@ void works0_44_0() throws Exception { @Disabled("https://github.com/pinterest/ktlint/issues/1421") @Test - void works0_45_0() throws Exception { + void works0_45_0() { FormatterStep step = KtLintStep.create("0.45.0", TestProvisioner.mavenCentral()); StepHarness.forStep(step) .testResource("kotlin/ktlint/basic.dirty", "kotlin/ktlint/basic.clean"); } @Test - void works0_45_1() throws Exception { + void works0_45_1() { FormatterStep step = KtLintStep.create("0.45.1", TestProvisioner.mavenCentral()); StepHarness.forStep(step) .testResource("kotlin/ktlint/basic.dirty", "kotlin/ktlint/basic.clean"); } @Test - void works0_45_2() throws Exception { + void works0_45_2() { FormatterStep step = KtLintStep.create("0.45.2", TestProvisioner.mavenCentral()); StepHarness.forStep(step) .testResource("kotlin/ktlint/basic.dirty", "kotlin/ktlint/basic.clean"); } @Test - void works0_46_0() throws Exception { + void works0_46_0() { FormatterStep step = KtLintStep.create("0.46.0", TestProvisioner.mavenCentral()); - StepHarness.forStep(step) + StepHarnessWithFile.forStep(this, step) .testResource("kotlin/ktlint/basic.dirty", "kotlin/ktlint/basic.clean") - .testResourceException("kotlin/ktlint/unsolvable.dirty", assertion -> { - assertion.isInstanceOf(AssertionError.class); - assertion.hasMessage("Error on line: 1, column: 1\n" + - "rule: no-wildcard-imports\n" + - "Wildcard import"); - }); + .testResourceExceptionMsg("kotlin/ktlint/unsolvable.dirty").isEqualTo("Error on line: 1, column: 1\n" + + "rule: no-wildcard-imports\n" + + "Wildcard import"); } @Test - void works0_47_0() throws Exception { + void works0_47_0() { FormatterStep step = KtLintStep.create("0.47.0", TestProvisioner.mavenCentral()); - StepHarness.forStep(step) + StepHarnessWithFile.forStep(this, step) .testResource("kotlin/ktlint/basic.dirty", "kotlin/ktlint/basic.clean") - .testResourceException("kotlin/ktlint/unsolvable.dirty", assertion -> { - assertion.isInstanceOf(AssertionError.class); - assertion.hasMessage("Error on line: 1, column: 1\n" + - "rule: no-wildcard-imports\n" + - "Wildcard import"); - }); + .testResourceExceptionMsg("kotlin/ktlint/unsolvable.dirty").isEqualTo("Error on line: 1, column: 1\n" + + "rule: no-wildcard-imports\n" + + "Wildcard import"); } @Test - void works0_47_1() throws Exception { + void works0_47_1() { FormatterStep step = KtLintStep.create("0.47.1", TestProvisioner.mavenCentral()); - StepHarness.forStep(step) + StepHarnessWithFile.forStep(this, step) .testResource("kotlin/ktlint/basic.dirty", "kotlin/ktlint/basic.clean") - .testResourceException("kotlin/ktlint/unsolvable.dirty", assertion -> { - assertion.isInstanceOf(AssertionError.class); - assertion.hasMessage("Error on line: 1, column: 1\n" + - "rule: no-wildcard-imports\n" + - "Wildcard import"); - }); + .testResourceExceptionMsg("kotlin/ktlint/unsolvable.dirty").isEqualTo("Error on line: 1, column: 1\n" + + "rule: no-wildcard-imports\n" + + "Wildcard import"); } @Test - void works0_48_0() throws Exception { + void works0_48_0() { FormatterStep step = KtLintStep.create("0.48.0", TestProvisioner.mavenCentral()); - StepHarness.forStep(step) + StepHarnessWithFile.forStep(this, step) .testResource("kotlin/ktlint/basic.dirty", "kotlin/ktlint/basic.clean") - .testResourceException("kotlin/ktlint/unsolvable.dirty", assertion -> { - assertion.isInstanceOf(AssertionError.class); - assertion.hasMessage("Error on line: 1, column: 1\n" + - "rule: no-wildcard-imports\n" + - "Wildcard import"); - }); + .testResourceExceptionMsg("kotlin/ktlint/unsolvable.dirty").isEqualTo("Error on line: 1, column: 1\n" + + "rule: no-wildcard-imports\n" + + "Wildcard import"); } @Test - void equality() throws Exception { + void equality() { new SerializableEqualityTester() { String version = "0.32.0"; diff --git a/testlib/src/test/java/com/diffplug/spotless/npm/PrettierFormatterStepTest.java b/testlib/src/test/java/com/diffplug/spotless/npm/PrettierFormatterStepTest.java index d2d866e97d..9de75fda32 100644 --- a/testlib/src/test/java/com/diffplug/spotless/npm/PrettierFormatterStepTest.java +++ b/testlib/src/test/java/com/diffplug/spotless/npm/PrettierFormatterStepTest.java @@ -1,5 +1,5 @@ /* - * Copyright 2016-2021 DiffPlug + * Copyright 2016-2023 DiffPlug * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -25,13 +25,14 @@ import com.diffplug.common.collect.ImmutableMap; import com.diffplug.spotless.FormatterStep; +import com.diffplug.spotless.ResourceHarness; import com.diffplug.spotless.StepHarness; import com.diffplug.spotless.StepHarnessWithFile; import com.diffplug.spotless.TestProvisioner; import com.diffplug.spotless.tag.NpmTest; @NpmTest -class PrettierFormatterStepTest { +class PrettierFormatterStepTest extends ResourceHarness { @NpmTest @Nested @@ -96,8 +97,8 @@ void parserInferenceBasedOnFilenameIsWorking() throws Exception { npmPathResolver(), new PrettierConfig(null, Collections.emptyMap())); - try (StepHarnessWithFile stepHarness = StepHarnessWithFile.forStep(formatterStep)) { - stepHarness.testResource(new File("test.json"), dirtyFile, cleanFile); + try (StepHarnessWithFile stepHarness = StepHarnessWithFile.forStep(this, formatterStep)) { + stepHarness.testResource("test.json", dirtyFile, cleanFile); } } @@ -109,11 +110,9 @@ void verifyPrettierErrorMessageIsRelayed() throws Exception { buildDir(), npmPathResolver(), new PrettierConfig(null, ImmutableMap.of("parser", "postcss"))); - try (StepHarness stepHarness = StepHarness.forStep(formatterStep)) { - stepHarness.testResourceException("npm/prettier/filetypes/scss/scss.dirty", exception -> { - exception.hasMessageContaining("HTTP 501"); - exception.hasMessageContaining("Couldn't resolve parser \"postcss\""); - }); + try (StepHarnessWithFile stepHarness = StepHarnessWithFile.forStep(this, formatterStep)) { + stepHarness.testResourceExceptionMsg("npm/prettier/filetypes/scss/scss.dirty").startsWith( + "com.diffplug.spotless.npm.SimpleRestClient$SimpleRestResponseException: Unexpected response status code at /prettier/format [HTTP 501] -- (Error while formatting: Error: Couldn't resolve parser \"postcss\")"); } } } diff --git a/testlib/src/test/java/com/diffplug/spotless/scala/ScalaFmtStepTest.java b/testlib/src/test/java/com/diffplug/spotless/scala/ScalaFmtStepTest.java index bad573e985..1714dd9e29 100644 --- a/testlib/src/test/java/com/diffplug/spotless/scala/ScalaFmtStepTest.java +++ b/testlib/src/test/java/com/diffplug/spotless/scala/ScalaFmtStepTest.java @@ -1,5 +1,5 @@ /* - * Copyright 2016-2022 DiffPlug + * Copyright 2016-2023 DiffPlug * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -15,13 +15,9 @@ */ package com.diffplug.spotless.scala; -import static org.assertj.core.api.Assertions.assertThat; -import static org.junit.jupiter.api.Assertions.assertThrows; - import java.io.File; -import java.io.IOException; -import java.lang.reflect.InvocationTargetException; +import org.assertj.core.api.Assertions; import org.junit.jupiter.api.Test; import com.diffplug.spotless.FormatterStep; @@ -33,43 +29,43 @@ class ScalaFmtStepTest extends ResourceHarness { @Test - void behaviorDefaultConfig() throws Exception { + void behaviorDefaultConfig() { StepHarness.forStep(ScalaFmtStep.create("3.0.0", TestProvisioner.mavenCentral(), null)) .testResource("scala/scalafmt/basic.dirty", "scala/scalafmt/basic.clean_3.0.0"); } @Test - void behaviorCustomConfig() throws Exception { + void behaviorCustomConfig() { StepHarness.forStep(ScalaFmtStep.create("3.0.0", TestProvisioner.mavenCentral(), createTestFile("scala/scalafmt/scalafmt.conf"))) .testResource("scala/scalafmt/basic.dirty", "scala/scalafmt/basic.cleanWithCustomConf_3.0.0"); } @Test - void behaviorDefaultConfigVersion_3_0_0() throws Exception { + void behaviorDefaultConfigVersion_3_0_0() { FormatterStep step = ScalaFmtStep.create("3.0.0", TestProvisioner.mavenCentral(), null); StepHarness.forStep(step) .testResource("scala/scalafmt/basic.dirty", "scala/scalafmt/basicPost3.0.0.clean"); } @Test - void behaviorCustomConfigVersion_3_0_0() throws Exception { + void behaviorCustomConfigVersion_3_0_0() { FormatterStep step = ScalaFmtStep.create("3.0.0", TestProvisioner.mavenCentral(), createTestFile("scala/scalafmt/scalafmt.conf")); StepHarness.forStep(step) .testResource("scala/scalafmt/basic.dirty", "scala/scalafmt/basicPost3.0.0.cleanWithCustomConf"); } @Test - void equality() throws Exception { + void equality() { new SerializableEqualityTester() { - String version = "3.5.9"; + String version = "3.6.1"; File configFile = null; @Override - protected void setupTest(API api) throws IOException { + protected void setupTest(API api) { // same version == same api.areDifferentThan(); // change the version, and it's different - version = "3.5.8"; + version = "3.0.0"; api.areDifferentThan(); // add a config file, and its different configFile = createTestFile("scala/scalafmt/scalafmt.conf"); @@ -87,12 +83,11 @@ protected FormatterStep create() { } @Test - void invalidConfiguration() throws Exception { + void invalidConfiguration() { File invalidConfFile = createTestFile("scala/scalafmt/scalafmt.invalid.conf"); Provisioner provisioner = TestProvisioner.mavenCentral(); - - InvocationTargetException exception = assertThrows(InvocationTargetException.class, - () -> StepHarness.forStep(ScalaFmtStep.create("3.0.0", provisioner, invalidConfFile)).test("", "")); - assertThat(exception.getCause().getMessage()).contains("found option 'invalidScalaFmtConfigField' which wasn't expected"); + Assertions.assertThatThrownBy(() -> { + ScalaFmtStep.create("3.0.0", provisioner, invalidConfFile).format("", new File("")); + }).cause().message().contains("found option 'invalidScalaFmtConfigField' which wasn't expected"); } } From 748fd3040b286edf521c65cb67ad8cadc0e7c96f Mon Sep 17 00:00:00 2001 From: Ned Twigg Date: Mon, 2 Jan 2023 18:17:11 -0800 Subject: [PATCH 400/757] Update changelog. --- CHANGES.md | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/CHANGES.md b/CHANGES.md index cf43b4eb22..a7e3516607 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -13,6 +13,11 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format ( ### Changes * Bump the dev version of Gradle from `7.5.1` to `7.6` ([#1409](https://github.com/diffplug/spotless/pull/1409)) * We also removed the no-longer-required dependency `org.codehaus.groovy:groovy-xml` +* Breaking changes to Spotless' internal testing infrastructure `testlib` ([#1443](https://github.com/diffplug/spotless/pull/1443)) + * `ResourceHarness` no longer has any duplicated functionality which was also present in `StepHarness` + * `StepHarness` now operates on `Formatter` rather than a `FormatterStep` + * `StepHarnessWithFile` now takes a `ResourceHarness` in its constructor to handle the file manipulation parts + * Standardized that we test exception *messages*, not types, which will ease the transition to linting later on ## [2.31.1] - 2023-01-02 ### Fixed From 6cd1eb49e54fd4a58e78f8fc1db2e0a1998043a5 Mon Sep 17 00:00:00 2001 From: Ned Twigg Date: Mon, 2 Jan 2023 18:45:08 -0800 Subject: [PATCH 401/757] Try to fix the failing Prettier test. --- .../com/diffplug/spotless/npm/PrettierFormatterStepTest.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/testlib/src/test/java/com/diffplug/spotless/npm/PrettierFormatterStepTest.java b/testlib/src/test/java/com/diffplug/spotless/npm/PrettierFormatterStepTest.java index 9de75fda32..5f14022ad8 100644 --- a/testlib/src/test/java/com/diffplug/spotless/npm/PrettierFormatterStepTest.java +++ b/testlib/src/test/java/com/diffplug/spotless/npm/PrettierFormatterStepTest.java @@ -111,8 +111,8 @@ void verifyPrettierErrorMessageIsRelayed() throws Exception { npmPathResolver(), new PrettierConfig(null, ImmutableMap.of("parser", "postcss"))); try (StepHarnessWithFile stepHarness = StepHarnessWithFile.forStep(this, formatterStep)) { - stepHarness.testResourceExceptionMsg("npm/prettier/filetypes/scss/scss.dirty").startsWith( - "com.diffplug.spotless.npm.SimpleRestClient$SimpleRestResponseException: Unexpected response status code at /prettier/format [HTTP 501] -- (Error while formatting: Error: Couldn't resolve parser \"postcss\")"); + stepHarness.testResourceExceptionMsg("npm/prettier/filetypes/scss/scss.dirty").isEqualTo( + "Unexpected response status code at /prettier/format [HTTP 501] -- (Error while formatting: Error: Couldn't resolve parser \"postcss\")"); } } } From f0b74d8a8494a4dd188ae773882fe2faa49e425c Mon Sep 17 00:00:00 2001 From: Ned Twigg Date: Mon, 2 Jan 2023 20:20:41 -0800 Subject: [PATCH 402/757] StepHarness needs a strict error policy for it to exercise what we want in the tests. --- testlib/src/main/java/com/diffplug/spotless/StepHarness.java | 1 + .../src/main/java/com/diffplug/spotless/StepHarnessWithFile.java | 1 + 2 files changed, 2 insertions(+) diff --git a/testlib/src/main/java/com/diffplug/spotless/StepHarness.java b/testlib/src/main/java/com/diffplug/spotless/StepHarness.java index 976a80df29..71e2a663b5 100644 --- a/testlib/src/main/java/com/diffplug/spotless/StepHarness.java +++ b/testlib/src/main/java/com/diffplug/spotless/StepHarness.java @@ -46,6 +46,7 @@ public static StepHarness forSteps(FormatterStep... steps) { .lineEndingsPolicy(LineEnding.UNIX.createPolicy()) .encoding(StandardCharsets.UTF_8) .rootDir(Paths.get("")) + .exceptionPolicy(new FormatExceptionPolicyStrict()) .build()); } diff --git a/testlib/src/main/java/com/diffplug/spotless/StepHarnessWithFile.java b/testlib/src/main/java/com/diffplug/spotless/StepHarnessWithFile.java index 3d01a6bd44..98a709c59f 100644 --- a/testlib/src/main/java/com/diffplug/spotless/StepHarnessWithFile.java +++ b/testlib/src/main/java/com/diffplug/spotless/StepHarnessWithFile.java @@ -42,6 +42,7 @@ public static StepHarnessWithFile forStep(ResourceHarness harness, FormatterStep .lineEndingsPolicy(LineEnding.UNIX.createPolicy()) .steps(Collections.singletonList(step)) .rootDir(harness.rootFolder().toPath()) + .exceptionPolicy(new FormatExceptionPolicyStrict()) .build()); } From 5e728be5dbad1a66f04b19f62b4483c186bb727a Mon Sep 17 00:00:00 2001 From: Benoit Lacelle Date: Tue, 3 Jan 2023 22:33:12 +0400 Subject: [PATCH 403/757] Initial iteration --- plugin-maven/README.md | 50 ++++++++++++++++++- .../diffplug/spotless/maven/json/Gson.java | 45 +++++++++++++++++ .../diffplug/spotless/maven/json/Json.java | 47 +++++++++++++++++ .../diffplug/spotless/maven/json/Simple.java | 35 +++++++++++++ 4 files changed, 176 insertions(+), 1 deletion(-) create mode 100644 plugin-maven/src/main/java/com/diffplug/spotless/maven/json/Gson.java create mode 100644 plugin-maven/src/main/java/com/diffplug/spotless/maven/json/Json.java create mode 100644 plugin-maven/src/main/java/com/diffplug/spotless/maven/json/Simple.java diff --git a/plugin-maven/README.md b/plugin-maven/README.md index 80be3dbc37..8be4149705 100644 --- a/plugin-maven/README.md +++ b/plugin-maven/README.md @@ -58,6 +58,7 @@ user@machine repo % mvn spotless:check - [Maven Pom](#maven-pom) ([sortPom](#sortpom)) - [Markdown](#markdown) ([flexmark](#flexmark)) - [Typescript](#typescript) ([tsfmt](#tsfmt), [prettier](#prettier)) + - [JSON](#json) - Multiple languages - [Prettier](#prettier) ([plugins](#prettier-plugins), [npm detection](#npm-detection), [`.npmrc` detection](#npmrc-detection)) - [eclipse web tools platform](#eclipse-web-tools-platform) @@ -431,7 +432,7 @@ Groovy-Eclipse formatting errors/warnings lead per default to a build failure. T - src/native/** + src/native/** @@ -700,6 +701,53 @@ The auto-discovery of config files (up the file tree) will not work when using t For details, see the [npm detection](#npm-detection) and [`.npmrc` detection](#npmrc-detection) sections of prettier, which apply also to tsfmt. +## JSON + +- `com.diffplug.spotless.maven.json.Json` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.12.1/com/diffplug/gradle/spotless/JsonExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-maven/src/main/java/com/diffplug/spotless/maven/json/Json.java) + +```xml + + + + src/**/*.json + + + + + + +``` + +### simple + +Uses a JSON pretty-printer that optionally allows configuring the number of spaces that are used to pretty print objects: + +```xml + + 4 + +``` + +### Gson + +Uses Google Gson to also allow sorting by keys besides custom indentation - useful for i18n files. + +```xml + + 4 + false + false + 2.8.1 + +``` + +Notes: +* There's no option in Gson to leave HTML as-is (i.e. escaped HTML would remain escaped, raw would remain raw). Either +all HTML characters are written escaped or none. Set `escapeHtml` if you prefer the former. +* `sortByKeys` will apply lexicographic order on the keys of the input JSON. See the +[javadoc of String](https://docs.oracle.com/en/java/javase/11/docs/api/java.base/java/lang/String.html#compareTo(java.lang.String)) +for details. + ## Prettier diff --git a/plugin-maven/src/main/java/com/diffplug/spotless/maven/json/Gson.java b/plugin-maven/src/main/java/com/diffplug/spotless/maven/json/Gson.java new file mode 100644 index 0000000000..9091157637 --- /dev/null +++ b/plugin-maven/src/main/java/com/diffplug/spotless/maven/json/Gson.java @@ -0,0 +1,45 @@ +/* + * Copyright 2021 DiffPlug + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.diffplug.spotless.maven.json; + +import org.apache.maven.plugins.annotations.Parameter; + +import com.diffplug.spotless.FormatterStep; +import com.diffplug.spotless.json.gson.GsonStep; +import com.diffplug.spotless.maven.FormatterStepConfig; +import com.diffplug.spotless.maven.FormatterStepFactory; + +public class Gson implements FormatterStepFactory { + private static final String DEFAULT_GSON_VERSION = "2.8.9"; + + @Parameter + int indentSpaces = Json.DEFAULT_INDENTATION; + + @Parameter + boolean sortByKeys = false; + + @Parameter + boolean escapeHtml = false; + + @Parameter + String version = DEFAULT_GSON_VERSION; + + @Override + public FormatterStep newFormatterStep(FormatterStepConfig stepConfig) { + int indentSpaces = this.indentSpaces; + return GsonStep.create(indentSpaces, sortByKeys, escapeHtml, version, stepConfig.getProvisioner()); + } +} diff --git a/plugin-maven/src/main/java/com/diffplug/spotless/maven/json/Json.java b/plugin-maven/src/main/java/com/diffplug/spotless/maven/json/Json.java new file mode 100644 index 0000000000..4cd4e88a7d --- /dev/null +++ b/plugin-maven/src/main/java/com/diffplug/spotless/maven/json/Json.java @@ -0,0 +1,47 @@ +/* + * Copyright 2021 DiffPlug + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.diffplug.spotless.maven.json; + +import java.util.Collections; +import java.util.Set; + +import com.diffplug.spotless.maven.FormatterFactory; + +/** + * A {@link FormatterFactory} implementation that corresponds to {@code ...} configuration element. + */ +public class Json extends FormatterFactory { + public static final int DEFAULT_INDENTATION = 4; + + @Override + public Set defaultIncludes() { + return Collections.emptySet(); + } + + @Override + public String licenseHeaderDelimiter() { + return null; + } + + public void addSimple(Simple simple) { + addStepFactory(simple); + } + + public void addGson(Gson gson) { + addStepFactory(gson); + } + +} diff --git a/plugin-maven/src/main/java/com/diffplug/spotless/maven/json/Simple.java b/plugin-maven/src/main/java/com/diffplug/spotless/maven/json/Simple.java new file mode 100644 index 0000000000..5926d22282 --- /dev/null +++ b/plugin-maven/src/main/java/com/diffplug/spotless/maven/json/Simple.java @@ -0,0 +1,35 @@ +/* + * Copyright 2021 DiffPlug + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.diffplug.spotless.maven.json; + +import org.apache.maven.plugins.annotations.Parameter; + +import com.diffplug.spotless.FormatterStep; +import com.diffplug.spotless.json.JsonSimpleStep; +import com.diffplug.spotless.maven.FormatterStepConfig; +import com.diffplug.spotless.maven.FormatterStepFactory; + +public class Simple implements FormatterStepFactory { + + @Parameter + int indentSpaces = Json.DEFAULT_INDENTATION; + + @Override + public FormatterStep newFormatterStep(FormatterStepConfig stepConfig) { + int indentSpaces = this.indentSpaces; + return JsonSimpleStep.create(indentSpaces, stepConfig.getProvisioner()); + } +} From a7f969c8a950b33fd609b93a77b9032fb191cf30 Mon Sep 17 00:00:00 2001 From: Benoit Lacelle Date: Tue, 3 Jan 2023 22:34:34 +0400 Subject: [PATCH 404/757] Fix copyright --- .../src/main/java/com/diffplug/spotless/maven/json/Gson.java | 2 +- .../src/main/java/com/diffplug/spotless/maven/json/Json.java | 2 +- .../src/main/java/com/diffplug/spotless/maven/json/Simple.java | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/plugin-maven/src/main/java/com/diffplug/spotless/maven/json/Gson.java b/plugin-maven/src/main/java/com/diffplug/spotless/maven/json/Gson.java index 9091157637..7962ecb1f7 100644 --- a/plugin-maven/src/main/java/com/diffplug/spotless/maven/json/Gson.java +++ b/plugin-maven/src/main/java/com/diffplug/spotless/maven/json/Gson.java @@ -1,5 +1,5 @@ /* - * Copyright 2021 DiffPlug + * Copyright 2023 DiffPlug * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/plugin-maven/src/main/java/com/diffplug/spotless/maven/json/Json.java b/plugin-maven/src/main/java/com/diffplug/spotless/maven/json/Json.java index 4cd4e88a7d..27f9a0b82a 100644 --- a/plugin-maven/src/main/java/com/diffplug/spotless/maven/json/Json.java +++ b/plugin-maven/src/main/java/com/diffplug/spotless/maven/json/Json.java @@ -1,5 +1,5 @@ /* - * Copyright 2021 DiffPlug + * Copyright 2023 DiffPlug * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/plugin-maven/src/main/java/com/diffplug/spotless/maven/json/Simple.java b/plugin-maven/src/main/java/com/diffplug/spotless/maven/json/Simple.java index 5926d22282..f1cc114da2 100644 --- a/plugin-maven/src/main/java/com/diffplug/spotless/maven/json/Simple.java +++ b/plugin-maven/src/main/java/com/diffplug/spotless/maven/json/Simple.java @@ -1,5 +1,5 @@ /* - * Copyright 2021 DiffPlug + * Copyright 2023 DiffPlug * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. From 338dd161ed45c853f4b63772ee2da1d867c06521 Mon Sep 17 00:00:00 2001 From: Jake Wharton Date: Tue, 3 Jan 2023 14:00:09 -0500 Subject: [PATCH 405/757] Prevent tool configurations from being resolved outside project When exposed they can create ambiguities when downstream projects try to automatically choose a configuration based on its attributes. --- .../java/com/diffplug/gradle/spotless/GradleProvisioner.java | 1 + 1 file changed, 1 insertion(+) diff --git a/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/GradleProvisioner.java b/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/GradleProvisioner.java index 97f051cd86..65e41da42c 100644 --- a/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/GradleProvisioner.java +++ b/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/GradleProvisioner.java @@ -118,6 +118,7 @@ private static Provisioner forConfigurationContainer(Project project, Configurat .forEach(config.getDependencies()::add); config.setDescription(mavenCoords.toString()); config.setTransitive(withTransitives); + config.setCanBeConsumed(false); config.attributes(attr -> { attr.attribute(Bundling.BUNDLING_ATTRIBUTE, project.getObjects().named(Bundling.class, Bundling.EXTERNAL)); }); From f9a70adede09876fb0b770209d89f1f11dd7108e Mon Sep 17 00:00:00 2001 From: Jake Wharton Date: Tue, 3 Jan 2023 14:05:48 -0500 Subject: [PATCH 406/757] Update CHANGES.md --- plugin-gradle/CHANGES.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/plugin-gradle/CHANGES.md b/plugin-gradle/CHANGES.md index cac4f56567..b9e3096980 100644 --- a/plugin-gradle/CHANGES.md +++ b/plugin-gradle/CHANGES.md @@ -3,6 +3,8 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format (starting after version `3.27.0`). ## [Unreleased] +### Fixed +* Prevent tool configurations from being resolved outside project ([#1447](https://github.com/diffplug/spotless/pull/1447)) ## [6.12.1] - 2023-01-02 ### Fixed From 163fb6e347a2a45fceb5189fd8d8b47882eadd1d Mon Sep 17 00:00:00 2001 From: Jake Wharton Date: Tue, 3 Jan 2023 14:16:47 -0500 Subject: [PATCH 407/757] Update GradleProvisioner.java --- .../java/com/diffplug/gradle/spotless/GradleProvisioner.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/GradleProvisioner.java b/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/GradleProvisioner.java index 65e41da42c..bd5d8db8ca 100644 --- a/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/GradleProvisioner.java +++ b/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/GradleProvisioner.java @@ -1,5 +1,5 @@ /* - * Copyright 2016-2022 DiffPlug + * Copyright 2016-2023 DiffPlug * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. From 773d59c45412a349437334a2429d675236e35396 Mon Sep 17 00:00:00 2001 From: Eir Nym <485399+eirnym@users.noreply.github.com> Date: Tue, 3 Jan 2023 00:12:32 +0100 Subject: [PATCH 408/757] Add changes --- CHANGES.md | 2 ++ plugin-gradle/CHANGES.md | 2 ++ plugin-maven/CHANGES.md | 2 ++ 3 files changed, 6 insertions(+) diff --git a/CHANGES.md b/CHANGES.md index cf43b4eb22..440ea59f80 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -10,6 +10,8 @@ This document is intended for Spotless developers. We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format (starting after version `1.27.0`). ## [Unreleased] +### Added +* Add option `editorConfigFile` for `ktLint` [#142](https://github.com/diffplug/spotless/issues/142) ### Changes * Bump the dev version of Gradle from `7.5.1` to `7.6` ([#1409](https://github.com/diffplug/spotless/pull/1409)) * We also removed the no-longer-required dependency `org.codehaus.groovy:groovy-xml` diff --git a/plugin-gradle/CHANGES.md b/plugin-gradle/CHANGES.md index cac4f56567..3c9b51bd5a 100644 --- a/plugin-gradle/CHANGES.md +++ b/plugin-gradle/CHANGES.md @@ -3,6 +3,8 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format (starting after version `3.27.0`). ## [Unreleased] +### Added +* Add option `editorConfigFile` for `ktLint` [#142](https://github.com/diffplug/spotless/issues/142) ## [6.12.1] - 2023-01-02 ### Fixed diff --git a/plugin-maven/CHANGES.md b/plugin-maven/CHANGES.md index 84e06aa847..ae8ac7e4dd 100644 --- a/plugin-maven/CHANGES.md +++ b/plugin-maven/CHANGES.md @@ -3,6 +3,8 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format (starting after version `1.27.0`). ## [Unreleased] +### Added +* Add option `editorConfigFile` for `ktLint` [#142](https://github.com/diffplug/spotless/issues/142) ## [2.29.0] - 2023-01-02 ### Added From 57be84fb8283e62ae971f25c5b3467ee5906db8a Mon Sep 17 00:00:00 2001 From: Eir Nym <485399+eirnym@users.noreply.github.com> Date: Tue, 3 Jan 2023 21:19:47 +0100 Subject: [PATCH 409/757] Use FileSignature to cache changes --- .../glue/ktlint/KtlintFormatterFunc.java | 26 +++++++------------ .../diffplug/spotless/kotlin/KtLintStep.java | 7 ++--- .../gradle/spotless/KotlinExtension.java | 14 ++++++++-- .../spotless/KotlinGradleExtension.java | 13 +++++++--- .../spotless/maven/kotlin/Ktlint.java | 11 +++++--- 5 files changed, 43 insertions(+), 28 deletions(-) diff --git a/lib/src/ktlint/java/com/diffplug/spotless/glue/ktlint/KtlintFormatterFunc.java b/lib/src/ktlint/java/com/diffplug/spotless/glue/ktlint/KtlintFormatterFunc.java index 5b43bf5e14..df98b6d691 100644 --- a/lib/src/ktlint/java/com/diffplug/spotless/glue/ktlint/KtlintFormatterFunc.java +++ b/lib/src/ktlint/java/com/diffplug/spotless/glue/ktlint/KtlintFormatterFunc.java @@ -15,20 +15,14 @@ */ package com.diffplug.spotless.glue.ktlint; -import java.io.File; -import java.util.Map; +import com.diffplug.spotless.FileSignature; +import com.diffplug.spotless.FormatterFunc; +import com.diffplug.spotless.glue.ktlint.compat.*; import org.jetbrains.annotations.NotNull; -import com.diffplug.spotless.FormatterFunc; -import com.diffplug.spotless.glue.ktlint.compat.KtLintCompat0Dot31Dot0Adapter; -import com.diffplug.spotless.glue.ktlint.compat.KtLintCompat0Dot32Dot0Adapter; -import com.diffplug.spotless.glue.ktlint.compat.KtLintCompat0Dot34Dot2Adapter; -import com.diffplug.spotless.glue.ktlint.compat.KtLintCompat0Dot45Dot2Adapter; -import com.diffplug.spotless.glue.ktlint.compat.KtLintCompat0Dot46Dot0Adapter; -import com.diffplug.spotless.glue.ktlint.compat.KtLintCompat0Dot47Dot0Adapter; -import com.diffplug.spotless.glue.ktlint.compat.KtLintCompat0Dot48Dot0Adapter; -import com.diffplug.spotless.glue.ktlint.compat.KtLintCompatAdapter; +import java.io.File; +import java.util.Map; public class KtlintFormatterFunc implements FormatterFunc.NeedsFile { @@ -37,11 +31,11 @@ public class KtlintFormatterFunc implements FormatterFunc.NeedsFile { @NotNull private final KtLintCompatAdapter adapter; private final boolean useExperimental; - private final String editorConfigPath; + private final FileSignature editorConfigPath; private final Map editorConfigOverrideMap; - public KtlintFormatterFunc(String version, boolean isScript, boolean useExperimental, String editorConfigPath, Map userData, - Map editorConfigOverrideMap) { + public KtlintFormatterFunc(String version, boolean isScript, boolean useExperimental, FileSignature editorConfigPath, Map userData, + Map editorConfigOverrideMap) { int minorVersion = Integer.parseInt(version.split("\\.")[1]); if (minorVersion >= 48) { // ExperimentalParams lost two constructor arguments, EditorConfigProperty moved to its own class @@ -73,7 +67,7 @@ public KtlintFormatterFunc(String version, boolean isScript, boolean useExperime } @Override - public String applyWithFile(String unix, File file) throws Exception { - return adapter.format(unix, file.getName(), isScript, useExperimental, editorConfigPath, userData, editorConfigOverrideMap); + public String applyWithFile(String unix, File file) { + return adapter.format(unix, file.getName(), isScript, useExperimental, editorConfigPath.getOnlyFile().getAbsolutePath(), userData, editorConfigOverrideMap); } } diff --git a/lib/src/main/java/com/diffplug/spotless/kotlin/KtLintStep.java b/lib/src/main/java/com/diffplug/spotless/kotlin/KtLintStep.java index 9291e69fde..6d4d8b07ed 100644 --- a/lib/src/main/java/com/diffplug/spotless/kotlin/KtLintStep.java +++ b/lib/src/main/java/com/diffplug/spotless/kotlin/KtLintStep.java @@ -23,6 +23,7 @@ import java.util.Objects; import java.util.TreeMap; +import com.diffplug.spotless.FileSignature; import com.diffplug.spotless.FormatterFunc; import com.diffplug.spotless.FormatterStep; import com.diffplug.spotless.JarState; @@ -68,7 +69,7 @@ private static FormatterStep create(String version, Provisioner provisioner, boo } public static FormatterStep create(String version, Provisioner provisioner, boolean isScript, boolean useExperimental, - String editorConfig, Map userData, Map editorConfigOverride) { + FileSignature editorConfig, Map userData, Map editorConfigOverride) { Objects.requireNonNull(version, "version"); Objects.requireNonNull(provisioner, "provisioner"); return FormatterStep.createLazy(NAME, @@ -91,10 +92,10 @@ static final class State implements Serializable { private final TreeMap userData; private final TreeMap editorConfigOverride; private final String version; - private final String editorConfigPath; + private final FileSignature editorConfigPath; State(String version, Provisioner provisioner, boolean isScript, boolean useExperimental, - String editorConfigPath, Map userData, Map editorConfigOverride) throws IOException { + FileSignature editorConfigPath, Map userData, Map editorConfigOverride) throws IOException { this.version = version; String coordinate; diff --git a/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/KotlinExtension.java b/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/KotlinExtension.java index eddeef36d6..8af03aaefd 100644 --- a/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/KotlinExtension.java +++ b/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/KotlinExtension.java @@ -71,11 +71,11 @@ public class KotlinFormatExtension { private final String version; private boolean useExperimental; - private String editorConfigPath; + private FileSignature editorConfigPath; private Map userData; private Map editorConfigOverride; - KotlinFormatExtension(String version, boolean useExperimental, String editorConfigPath, Map config, + KotlinFormatExtension(String version, boolean useExperimental, FileSignature editorConfigPath, Map config, Map editorConfigOverride) { this.version = version; this.useExperimental = useExperimental; @@ -91,6 +91,16 @@ public KotlinFormatExtension setUseExperimental(boolean useExperimental) { return this; } + public KotlinFormatExtension setEditorConfigPath(Object editorConfigFile) throws IOException { + if (editorConfigFile == null) { + this.editorConfigPath = null; + } else { + this.editorConfigPath = FileSignature.signAsList(getProject().file(editorConfigFile)); + } + replaceStep(createStep()); + return this; + } + public KotlinFormatExtension userData(Map userData) { // Copy the map to a sorted map because up-to-date checking is based on binary-equals of the serialized // representation. diff --git a/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/KotlinGradleExtension.java b/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/KotlinGradleExtension.java index 5120d88754..ca4ecc9bde 100644 --- a/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/KotlinGradleExtension.java +++ b/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/KotlinGradleExtension.java @@ -56,11 +56,11 @@ public class KotlinFormatExtension { private final String version; private boolean useExperimental; - private String editorConfigPath; + private FileSignature editorConfigPath; private Map userData; private Map editorConfigOverride; - KotlinFormatExtension(String version, boolean useExperimental, String editorConfigPath, Map config, + KotlinFormatExtension(String version, boolean useExperimental, FileSignature editorConfigPath, Map config, Map editorConfigOverride) { this.version = version; this.useExperimental = useExperimental; @@ -70,8 +70,13 @@ public class KotlinFormatExtension { addStep(createStep()); } - public KotlinFormatExtension setEditorConfigPath(String editorConfigPath) { - this.editorConfigPath = editorConfigPath; + public KotlinFormatExtension setEditorConfigPath(Object editorConfigPath) throws IOException { + + if (editorConfigPath == null) { + this.editorConfigPath = null; + } else { + this.editorConfigPath = FileSignature.signAsList(getProject().file(editorConfigPath)); + } replaceStep(createStep()); return this; } diff --git a/plugin-maven/src/main/java/com/diffplug/spotless/maven/kotlin/Ktlint.java b/plugin-maven/src/main/java/com/diffplug/spotless/maven/kotlin/Ktlint.java index ad57c47976..2825980733 100644 --- a/plugin-maven/src/main/java/com/diffplug/spotless/maven/kotlin/Ktlint.java +++ b/plugin-maven/src/main/java/com/diffplug/spotless/maven/kotlin/Ktlint.java @@ -21,7 +21,9 @@ import org.apache.maven.plugins.annotations.Parameter; +import com.diffplug.spotless.FileSignature; import com.diffplug.spotless.FormatterStep; +import com.diffplug.spotless.ThrowingEx; import com.diffplug.spotless.kotlin.KtLintStep; import com.diffplug.spotless.maven.FormatterStepConfig; import com.diffplug.spotless.maven.FormatterStepFactory; @@ -36,13 +38,16 @@ public class Ktlint implements FormatterStepFactory { private Map editorConfigOverride; @Override - public FormatterStep newFormatterStep(FormatterStepConfig config) { + public FormatterStep newFormatterStep(final FormatterStepConfig stepConfig) { String ktlintVersion = version != null ? version : KtLintStep.defaultVersion(); - + FileSignature configPath = null; + if (editorConfigPath != null) { + configPath = ThrowingEx.get(() -> FileSignature.signAsList(stepConfig.getFileLocator().locateFile(editorConfigPath))); + } if (editorConfigOverride == null) { editorConfigOverride = new HashMap<>(); } - return KtLintStep.create(ktlintVersion, config.getProvisioner(), false, false, editorConfigPath, Collections.emptyMap(), editorConfigOverride); + return KtLintStep.create(ktlintVersion, stepConfig.getProvisioner(), false, false, configPath, Collections.emptyMap(), editorConfigOverride); } } From bd93e17a69613f04d4eab32629862c7229a2176f Mon Sep 17 00:00:00 2001 From: Eir Nym <485399+eirnym@users.noreply.github.com> Date: Tue, 3 Jan 2023 22:03:22 +0100 Subject: [PATCH 410/757] Fix NPE and contract to pass the variable --- .../glue/ktlint/KtlintFormatterFunc.java | 19 ++++++++++++------- .../diffplug/spotless/kotlin/KtLintStep.java | 4 ++-- 2 files changed, 14 insertions(+), 9 deletions(-) diff --git a/lib/src/ktlint/java/com/diffplug/spotless/glue/ktlint/KtlintFormatterFunc.java b/lib/src/ktlint/java/com/diffplug/spotless/glue/ktlint/KtlintFormatterFunc.java index df98b6d691..cfd6ab859c 100644 --- a/lib/src/ktlint/java/com/diffplug/spotless/glue/ktlint/KtlintFormatterFunc.java +++ b/lib/src/ktlint/java/com/diffplug/spotless/glue/ktlint/KtlintFormatterFunc.java @@ -15,14 +15,14 @@ */ package com.diffplug.spotless.glue.ktlint; -import com.diffplug.spotless.FileSignature; -import com.diffplug.spotless.FormatterFunc; -import com.diffplug.spotless.glue.ktlint.compat.*; +import java.io.File; +import java.util.Map; import org.jetbrains.annotations.NotNull; -import java.io.File; -import java.util.Map; +import com.diffplug.spotless.FileSignature; +import com.diffplug.spotless.FormatterFunc; +import com.diffplug.spotless.glue.ktlint.compat.*; public class KtlintFormatterFunc implements FormatterFunc.NeedsFile { @@ -35,7 +35,7 @@ public class KtlintFormatterFunc implements FormatterFunc.NeedsFile { private final Map editorConfigOverrideMap; public KtlintFormatterFunc(String version, boolean isScript, boolean useExperimental, FileSignature editorConfigPath, Map userData, - Map editorConfigOverrideMap) { + Map editorConfigOverrideMap) { int minorVersion = Integer.parseInt(version.split("\\.")[1]); if (minorVersion >= 48) { // ExperimentalParams lost two constructor arguments, EditorConfigProperty moved to its own class @@ -68,6 +68,11 @@ public KtlintFormatterFunc(String version, boolean isScript, boolean useExperime @Override public String applyWithFile(String unix, File file) { - return adapter.format(unix, file.getName(), isScript, useExperimental, editorConfigPath.getOnlyFile().getAbsolutePath(), userData, editorConfigOverrideMap); + + String absoluteEditorConfigPath = null; + if (editorConfigPath != null) { + absoluteEditorConfigPath = editorConfigPath.getOnlyFile().getAbsolutePath(); + } + return adapter.format(unix, file.getName(), isScript, useExperimental, absoluteEditorConfigPath, userData, editorConfigOverrideMap); } } diff --git a/lib/src/main/java/com/diffplug/spotless/kotlin/KtLintStep.java b/lib/src/main/java/com/diffplug/spotless/kotlin/KtLintStep.java index 6d4d8b07ed..4d29a01394 100644 --- a/lib/src/main/java/com/diffplug/spotless/kotlin/KtLintStep.java +++ b/lib/src/main/java/com/diffplug/spotless/kotlin/KtLintStep.java @@ -59,7 +59,7 @@ public static FormatterStep createForScript(String version, Provisioner provisio } public static FormatterStep createForScript(String version, Provisioner provisioner, boolean useExperimental, - Map userData, Map editorConfigOverride) { + FileSignature editorConfigPath, Map userData, Map editorConfigOverride) { return create(version, provisioner, true, useExperimental, userData, editorConfigOverride); } @@ -119,7 +119,7 @@ FormatterFunc createFormat() throws Exception { final ClassLoader classLoader = jarState.getClassLoader(); Class formatterFunc = classLoader.loadClass("com.diffplug.spotless.glue.ktlint.KtlintFormatterFunc"); Constructor constructor = formatterFunc.getConstructor( - String.class, boolean.class, boolean.class, String.class, Map.class, Map.class); + String.class, boolean.class, boolean.class, FileSignature.class, Map.class, Map.class); return (FormatterFunc.NeedsFile) constructor.newInstance(version, isScript, useExperimental, editorConfigPath, userData, editorConfigOverride); } } From b18da45e4a88f5900c80bd6dd6f2422b194127f2 Mon Sep 17 00:00:00 2001 From: Eir Nym <485399+eirnym@users.noreply.github.com> Date: Tue, 3 Jan 2023 22:04:00 +0100 Subject: [PATCH 411/757] EditorConfig: Set sane default for Gradle --- .../gradle/spotless/KotlinGradleExtension.java | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/KotlinGradleExtension.java b/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/KotlinGradleExtension.java index ca4ecc9bde..a06c640060 100644 --- a/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/KotlinGradleExtension.java +++ b/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/KotlinGradleExtension.java @@ -15,6 +15,7 @@ */ package com.diffplug.gradle.spotless; +import java.io.File; import java.io.IOException; import java.util.Collections; import java.util.Map; @@ -43,12 +44,17 @@ public KotlinGradleExtension(SpotlessExtension spotless) { } /** Adds the specified version of ktlint. */ - public KotlinFormatExtension ktlint(String version) { + public KotlinFormatExtension ktlint(String version) throws IOException { Objects.requireNonNull(version, "version"); - return new KotlinFormatExtension(version, false, null, Collections.emptyMap(), Collections.emptyMap()); + FileSignature editorConfigPath = null; + File defaultEditorConfig = getProject().getRootProject().file(".editorConfig"); + if (defaultEditorConfig.exists() && defaultEditorConfig.isFile()) { + editorConfigPath = FileSignature.signAsList(defaultEditorConfig); + } + return new KotlinFormatExtension(version, false, editorConfigPath, Collections.emptyMap(), Collections.emptyMap()); } - public KotlinFormatExtension ktlint() { + public KotlinFormatExtension ktlint() throws IOException { return ktlint(KtLintStep.defaultVersion()); } @@ -104,7 +110,7 @@ public KotlinFormatExtension editorConfigOverride(Map editorConf } private FormatterStep createStep() { - return KtLintStep.createForScript(version, provisioner(), useExperimental, userData, editorConfigOverride); + return KtLintStep.createForScript(version, provisioner(), useExperimental, editorConfigPath, userData, editorConfigOverride); } } From 79e35c1dfe3c18aca8e216749d825752cd539d3d Mon Sep 17 00:00:00 2001 From: Eir Nym <485399+eirnym@users.noreply.github.com> Date: Tue, 3 Jan 2023 22:07:05 +0100 Subject: [PATCH 412/757] EditorConfig: add documentation --- plugin-gradle/README.md | 10 +++++++++- plugin-maven/README.md | 8 +++++++- 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/plugin-gradle/README.md b/plugin-gradle/README.md index 755d21d056..84c4e626a0 100644 --- a/plugin-gradle/README.md +++ b/plugin-gradle/README.md @@ -354,7 +354,14 @@ spotless { ### ktlint -[homepage](https://github.com/pinterest/ktlint). [changelog](https://github.com/pinterest/ktlint/releases). Spotless does not ([yet](https://github.com/diffplug/spotless/issues/142)) respect the `.editorconfig` settings ([ktlint docs](https://github.com/pinterest/ktlint#editorconfig)), but you can provide them manually as `editorConfigOverride`. +[homepage](https://github.com/pinterest/ktlint). [changelog](https://github.com/pinterest/ktlint/releases). + +Spotless respects the `.editorconfig` settings by providing `editorConfigPath` option. +([ktlint docs](https://github.com/pinterest/ktlint#editorconfig)). +Default value is the `.editorconfig` file located in the top project. +Passing `null` will clear the option. + +Additionally, `editorConfigOverride` options will override what's supplied in `.editorconfig` file. ```kotlin spotless { @@ -363,6 +370,7 @@ spotless { ktlint("0.45.2") .setUseExperimental(true) .userData(mapOf("android" to "true")) + .editorConfigPath("$projectDir/config/.editorconfig") // sample unusual placement .editorConfigOverride(mapOf("indent_size" to 2)) } } diff --git a/plugin-maven/README.md b/plugin-maven/README.md index 80be3dbc37..1ae8e3a195 100644 --- a/plugin-maven/README.md +++ b/plugin-maven/README.md @@ -354,7 +354,13 @@ Groovy-Eclipse formatting errors/warnings lead per default to a build failure. T ### ktlint -[homepage](https://github.com/pinterest/ktlint). [changelog](https://github.com/pinterest/ktlint/releases). [code](https://github.com/diffplug/spotless/blob/main/plugin-maven/src/main/java/com/diffplug/spotless/maven/kotlin/Ktlint.java). Spotless does not ([yet](https://github.com/diffplug/spotless/issues/142)) respect the `.editorconfig` settings. +[homepage](https://github.com/pinterest/ktlint). [changelog](https://github.com/pinterest/ktlint/releases). +[code](https://github.com/diffplug/spotless/blob/main/plugin-maven/src/main/java/com/diffplug/spotless/maven/kotlin/Ktlint.java). + +Spotless respects the `.editorconfig` settings by providing `editorConfigPath` option. +([ktlint docs](https://github.com/pinterest/ktlint#editorconfig)). + +Additionally, `editorConfigOverride` options will override what's supplied in `.editorconfig` file. ```xml From 696d50c8b49db16a27ba9222683ece55dbfc91d5 Mon Sep 17 00:00:00 2001 From: Jake Wharton Date: Tue, 3 Jan 2023 16:58:31 -0500 Subject: [PATCH 413/757] Update GradleProvisioner.java --- .../java/com/diffplug/gradle/spotless/GradleProvisioner.java | 1 + 1 file changed, 1 insertion(+) diff --git a/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/GradleProvisioner.java b/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/GradleProvisioner.java index bd5d8db8ca..e1129b3b0b 100644 --- a/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/GradleProvisioner.java +++ b/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/GradleProvisioner.java @@ -119,6 +119,7 @@ private static Provisioner forConfigurationContainer(Project project, Configurat config.setDescription(mavenCoords.toString()); config.setTransitive(withTransitives); config.setCanBeConsumed(false); + config.setVisible(false); config.attributes(attr -> { attr.attribute(Bundling.BUNDLING_ATTRIBUTE, project.getObjects().named(Bundling.class, Bundling.EXTERNAL)); }); From 5e442db1cd30bbc299cf904939af1174e6d44361 Mon Sep 17 00:00:00 2001 From: Ned Twigg Date: Tue, 3 Jan 2023 14:30:02 -0800 Subject: [PATCH 414/757] Tweak changelog. --- plugin-gradle/CHANGES.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugin-gradle/CHANGES.md b/plugin-gradle/CHANGES.md index b9e3096980..c5f464069f 100644 --- a/plugin-gradle/CHANGES.md +++ b/plugin-gradle/CHANGES.md @@ -4,7 +4,7 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format ( ## [Unreleased] ### Fixed -* Prevent tool configurations from being resolved outside project ([#1447](https://github.com/diffplug/spotless/pull/1447)) +* Prevent tool configurations from being resolved outside project ([#1447](https://github.com/diffplug/spotless/pull/1447) fixes [#1215](https://github.com/diffplug/spotless/issues/1215)) ## [6.12.1] - 2023-01-02 ### Fixed From fc938dfdd8d800ea37ac79d456e66f6a51250189 Mon Sep 17 00:00:00 2001 From: Benoit Lacelle Date: Wed, 4 Jan 2023 11:27:01 +0400 Subject: [PATCH 415/757] Add changes note, Fix style --- plugin-maven/CHANGES.md | 1 + plugin-maven/README.md | 12 +++--- .../diffplug/spotless/maven/json/Json.java | 2 +- .../spotless/maven/json/JsonTest.java | 40 +++++++++++++++++++ 4 files changed, 48 insertions(+), 7 deletions(-) create mode 100644 plugin-maven/src/test/java/com/diffplug/spotless/maven/json/JsonTest.java diff --git a/plugin-maven/CHANGES.md b/plugin-maven/CHANGES.md index 84e06aa847..b15e005a9b 100644 --- a/plugin-maven/CHANGES.md +++ b/plugin-maven/CHANGES.md @@ -7,6 +7,7 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format ( ## [2.29.0] - 2023-01-02 ### Added * Added support for M2E's incremental compilation ([#1414](https://github.com/diffplug/spotless/pull/1414) fixes [#1413](https://github.com/diffplug/spotless/issues/1413)) +* Add JSON support ([#1446](https://github.com/diffplug/spotless/pull/1446)) ### Fixed * Improve memory usage when using git ratchet ([#1426](https://github.com/diffplug/spotless/pull/1426)) * Support `ktlint` 0.48+ ([#1432](https://github.com/diffplug/spotless/pull/1432)) fixes ([#1430](https://github.com/diffplug/spotless/issues/1430)) diff --git a/plugin-maven/README.md b/plugin-maven/README.md index 8be4149705..70f3dfe1dc 100644 --- a/plugin-maven/README.md +++ b/plugin-maven/README.md @@ -724,8 +724,8 @@ Uses a JSON pretty-printer that optionally allows configuring the number of spac ```xml - 4 - + 4 + ``` ### Gson @@ -734,10 +734,10 @@ Uses Google Gson to also allow sorting by keys besides custom indentation - usef ```xml - 4 - false - false - 2.8.1 + 4 + false + false + 2.8.1 ``` diff --git a/plugin-maven/src/main/java/com/diffplug/spotless/maven/json/Json.java b/plugin-maven/src/main/java/com/diffplug/spotless/maven/json/Json.java index 27f9a0b82a..c326525d0c 100644 --- a/plugin-maven/src/main/java/com/diffplug/spotless/maven/json/Json.java +++ b/plugin-maven/src/main/java/com/diffplug/spotless/maven/json/Json.java @@ -25,7 +25,7 @@ */ public class Json extends FormatterFactory { public static final int DEFAULT_INDENTATION = 4; - + @Override public Set defaultIncludes() { return Collections.emptySet(); diff --git a/plugin-maven/src/test/java/com/diffplug/spotless/maven/json/JsonTest.java b/plugin-maven/src/test/java/com/diffplug/spotless/maven/json/JsonTest.java new file mode 100644 index 0000000000..b7e666190a --- /dev/null +++ b/plugin-maven/src/test/java/com/diffplug/spotless/maven/json/JsonTest.java @@ -0,0 +1,40 @@ +/* + * Copyright 2023 DiffPlug + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.diffplug.spotless.maven.json; + +import org.junit.jupiter.api.Test; + +import com.diffplug.spotless.maven.MavenIntegrationHarness; + +public class JsonTest extends MavenIntegrationHarness { + @Test + public void testFormatJson_WithSimple_defaultConfig() throws Exception { + writePomWithPomSteps(""); + + setFile("json_test.json").toResource("json/json_dirty.json"); + mavenRunner().withArguments("spotless:apply").runNoError().error(); + assertFile("json_test.json").sameAsResource("json/json_clean_default.json"); + } + + @Test + public void testFormatJson_WithGson_defaultConfig() throws Exception { + writePomWithPomSteps(""); + + setFile("json_test.json").toResource("json/json_dirty.json"); + mavenRunner().withArguments("spotless:apply").runNoError().error(); + assertFile("json_test.json").sameAsResource("json/json_clean_default.json"); + } +} From 49592279ad462949fb68c3643ee85be0a062d839 Mon Sep 17 00:00:00 2001 From: Simon Gamma Date: Mon, 28 Nov 2022 19:55:57 +0100 Subject: [PATCH 416/757] extract base serve code --- .../spotless/npm/NpmResourceHelper.java | 10 +++++- .../spotless/npm/PrettierFormatterStep.java | 4 ++- .../spotless/npm/TsFmtFormatterStep.java | 4 ++- .../com/diffplug/spotless/npm/common-serve.js | 32 +++++++++++++++++++ .../diffplug/spotless/npm/prettier-serve.js | 30 ----------------- .../com/diffplug/spotless/npm/tsfmt-serve.js | 31 ------------------ 6 files changed, 47 insertions(+), 64 deletions(-) create mode 100644 lib/src/main/resources/com/diffplug/spotless/npm/common-serve.js diff --git a/lib/src/main/java/com/diffplug/spotless/npm/NpmResourceHelper.java b/lib/src/main/java/com/diffplug/spotless/npm/NpmResourceHelper.java index ad1211d717..cb6fff3290 100644 --- a/lib/src/main/java/com/diffplug/spotless/npm/NpmResourceHelper.java +++ b/lib/src/main/java/com/diffplug/spotless/npm/NpmResourceHelper.java @@ -1,5 +1,5 @@ /* - * Copyright 2016-2020 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. @@ -19,7 +19,9 @@ import java.nio.charset.StandardCharsets; import java.nio.file.Files; import java.time.Duration; +import java.util.Arrays; import java.util.concurrent.TimeoutException; +import java.util.stream.Collectors; import com.diffplug.spotless.ThrowingEx; @@ -45,6 +47,12 @@ static void deleteFileIfExists(File file) throws IOException { } } + static String readUtf8StringFromClasspath(Class clazz, String... resourceNames) { + return Arrays.stream(resourceNames) + .map(resourceName -> readUtf8StringFromClasspath(clazz, resourceName)) + .collect(Collectors.joining("\n")); + } + static String readUtf8StringFromClasspath(Class clazz, String resourceName) { try (InputStream input = clazz.getResourceAsStream(resourceName)) { return readUtf8StringFromInputStream(input); diff --git a/lib/src/main/java/com/diffplug/spotless/npm/PrettierFormatterStep.java b/lib/src/main/java/com/diffplug/spotless/npm/PrettierFormatterStep.java index 49d692d62c..5a5662eee4 100644 --- a/lib/src/main/java/com/diffplug/spotless/npm/PrettierFormatterStep.java +++ b/lib/src/main/java/com/diffplug/spotless/npm/PrettierFormatterStep.java @@ -70,7 +70,9 @@ private static class State extends NpmFormatterStepStateBase implements Serializ NpmResourceHelper.readUtf8StringFromClasspath(PrettierFormatterStep.class, "/com/diffplug/spotless/npm/prettier-package.json"), new TreeMap<>(devDependencies)), "prettier", - NpmResourceHelper.readUtf8StringFromClasspath(PrettierFormatterStep.class, "/com/diffplug/spotless/npm/prettier-serve.js"), + NpmResourceHelper.readUtf8StringFromClasspath(PrettierFormatterStep.class, + "/com/diffplug/spotless/npm/common-serve.js", + "/com/diffplug/spotless/npm/prettier-serve.js"), npmPathResolver.resolveNpmrcContent()), buildDir, npmPathResolver.resolveNpmExecutable()); diff --git a/lib/src/main/java/com/diffplug/spotless/npm/TsFmtFormatterStep.java b/lib/src/main/java/com/diffplug/spotless/npm/TsFmtFormatterStep.java index 14080ecf56..e9c098d709 100644 --- a/lib/src/main/java/com/diffplug/spotless/npm/TsFmtFormatterStep.java +++ b/lib/src/main/java/com/diffplug/spotless/npm/TsFmtFormatterStep.java @@ -76,7 +76,9 @@ public State(String stepName, Map versions, File buildDir, NpmPa new NpmConfig( replaceDevDependencies(NpmResourceHelper.readUtf8StringFromClasspath(TsFmtFormatterStep.class, "/com/diffplug/spotless/npm/tsfmt-package.json"), new TreeMap<>(versions)), "typescript-formatter", - NpmResourceHelper.readUtf8StringFromClasspath(PrettierFormatterStep.class, "/com/diffplug/spotless/npm/tsfmt-serve.js"), + NpmResourceHelper.readUtf8StringFromClasspath(PrettierFormatterStep.class, + "/com/diffplug/spotless/npm/common-serve.js", + "/com/diffplug/spotless/npm/tsfmt-serve.js"), npmPathResolver.resolveNpmrcContent()), buildDir, npmPathResolver.resolveNpmExecutable()); diff --git a/lib/src/main/resources/com/diffplug/spotless/npm/common-serve.js b/lib/src/main/resources/com/diffplug/spotless/npm/common-serve.js new file mode 100644 index 0000000000..3e031cedea --- /dev/null +++ b/lib/src/main/resources/com/diffplug/spotless/npm/common-serve.js @@ -0,0 +1,32 @@ +// this file will be glued to the top of the specific xy-server.js file +const GracefulShutdownManager = require("@moebius/http-graceful-shutdown").GracefulShutdownManager; +const express = require("express"); +const app = express(); + +app.use(express.json({ limit: "50mb" })); + +const fs = require("fs"); + +var listener = app.listen(0, "127.0.0.1", () => { + console.log("Server running on port " + listener.address().port); + fs.writeFile("server.port.tmp", "" + listener.address().port, function(err) { + if (err) { + return console.log(err); + } else { + fs.rename("server.port.tmp", "server.port", function(err) { + if (err) { + return console.log(err); + } + }); // try to be as atomic as possible + } + }); +}); +const shutdownManager = new GracefulShutdownManager(listener); + +app.post("/shutdown", (req, res) => { + res.status(200).send("Shutting down"); + setTimeout(function() { + shutdownManager.terminate(() => console.log("graceful shutdown finished.")); + }, 200); +}); + diff --git a/lib/src/main/resources/com/diffplug/spotless/npm/prettier-serve.js b/lib/src/main/resources/com/diffplug/spotless/npm/prettier-serve.js index 351ef73f9a..d4ce13bbbc 100644 --- a/lib/src/main/resources/com/diffplug/spotless/npm/prettier-serve.js +++ b/lib/src/main/resources/com/diffplug/spotless/npm/prettier-serve.js @@ -1,35 +1,5 @@ -const GracefulShutdownManager = require("@moebius/http-graceful-shutdown").GracefulShutdownManager; -const express = require("express"); -const app = express(); - -app.use(express.json({ limit: "50mb" })); const prettier = require("prettier"); -const fs = require("fs"); - -var listener = app.listen(0, "127.0.0.1", () => { - console.log("Server running on port " + listener.address().port); - fs.writeFile("server.port.tmp", "" + listener.address().port, function(err) { - if (err) { - return console.log(err); - } else { - fs.rename("server.port.tmp", "server.port", function(err) { - if (err) { - return console.log(err); - } - }); // try to be as atomic as possible - } - }); -}); -const shutdownManager = new GracefulShutdownManager(listener); - -app.post("/shutdown", (req, res) => { - res.status(200).send("Shutting down"); - setTimeout(function() { - shutdownManager.terminate(() => console.log("graceful shutdown finished.")); - }, 200); -}); - app.post("/prettier/config-options", (req, res) => { var config_data = req.body; var prettier_config_path = config_data.prettier_config_path; diff --git a/lib/src/main/resources/com/diffplug/spotless/npm/tsfmt-serve.js b/lib/src/main/resources/com/diffplug/spotless/npm/tsfmt-serve.js index b25048d410..8ec25565ff 100644 --- a/lib/src/main/resources/com/diffplug/spotless/npm/tsfmt-serve.js +++ b/lib/src/main/resources/com/diffplug/spotless/npm/tsfmt-serve.js @@ -1,36 +1,5 @@ -const GracefulShutdownManager = require("@moebius/http-graceful-shutdown").GracefulShutdownManager; -const express = require("express"); -const app = express(); -app.use(express.json({ limit: "50mb" })); - const tsfmt = require("typescript-formatter"); -const fs = require("fs"); - -var listener = app.listen(0, "127.0.0.1", () => { - console.log("Server running on port " + listener.address().port); - fs.writeFile("server.port.tmp", "" + listener.address().port, function(err) { - if (err) { - return console.log(err); - } else { - fs.rename("server.port.tmp", "server.port", function(err) { - if (err) { - return console.log(err); - } - }); // try to be as atomic as possible - } - }); -}); - -const shutdownManager = new GracefulShutdownManager(listener); - -app.post("/shutdown", (req, res) => { - res.status(200).send("Shutting down"); - setTimeout(function() { - shutdownManager.terminate(() => console.log("graceful shutdown finished.")); - }, 200); -}); - app.post("/tsfmt/format", (req, res) => { var format_data = req.body; tsfmt.processString("spotless-format-string.ts", format_data.file_content, format_data.config_options).then(resultMap => { From c70bd347f4b855035ddc466b0d7d5361ee77f415 Mon Sep 17 00:00:00 2001 From: Simon Gamma Date: Mon, 28 Nov 2022 19:56:11 +0100 Subject: [PATCH 417/757] upgrade express to latest --- .../resources/com/diffplug/spotless/npm/prettier-package.json | 2 +- .../main/resources/com/diffplug/spotless/npm/tsfmt-package.json | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/src/main/resources/com/diffplug/spotless/npm/prettier-package.json b/lib/src/main/resources/com/diffplug/spotless/npm/prettier-package.json index 113f20bc3f..7bda08db8a 100644 --- a/lib/src/main/resources/com/diffplug/spotless/npm/prettier-package.json +++ b/lib/src/main/resources/com/diffplug/spotless/npm/prettier-package.json @@ -9,7 +9,7 @@ }, "devDependencies": { ${devDependencies}, - "express": "4.17.1", + "express": "4.18.2", "@moebius/http-graceful-shutdown": "1.1.0" }, "dependencies": {}, diff --git a/lib/src/main/resources/com/diffplug/spotless/npm/tsfmt-package.json b/lib/src/main/resources/com/diffplug/spotless/npm/tsfmt-package.json index d6e5eff3b2..7037bd2ec1 100644 --- a/lib/src/main/resources/com/diffplug/spotless/npm/tsfmt-package.json +++ b/lib/src/main/resources/com/diffplug/spotless/npm/tsfmt-package.json @@ -9,7 +9,7 @@ }, "devDependencies": { ${devDependencies}, - "express": "4.17.1", + "express": "4.18.2", "@moebius/http-graceful-shutdown": "1.1.0" }, "dependencies": {}, From 3884e14d7ffd9a3c4fbfbe9bdeeb1172810d0b17 Mon Sep 17 00:00:00 2001 From: Simon Gamma Date: Sat, 3 Dec 2022 19:50:03 +0100 Subject: [PATCH 418/757] extract common rest code on client side --- .../spotless/npm/BaseNpmRestService.java | 30 +++++++++++++++++++ .../spotless/npm/PrettierRestService.java | 13 ++------ .../spotless/npm/TsFmtRestService.java | 13 ++------ 3 files changed, 36 insertions(+), 20 deletions(-) create mode 100644 lib/src/main/java/com/diffplug/spotless/npm/BaseNpmRestService.java diff --git a/lib/src/main/java/com/diffplug/spotless/npm/BaseNpmRestService.java b/lib/src/main/java/com/diffplug/spotless/npm/BaseNpmRestService.java new file mode 100644 index 0000000000..e8582c15ec --- /dev/null +++ b/lib/src/main/java/com/diffplug/spotless/npm/BaseNpmRestService.java @@ -0,0 +1,30 @@ +/* + * 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. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.diffplug.spotless.npm; + +abstract class BaseNpmRestService { + + protected final SimpleRestClient restClient; + + BaseNpmRestService(String baseUrl) { + this.restClient = SimpleRestClient.forBaseUrl(baseUrl); + } + + public String shutdown() { + return restClient.post("/shutdown"); + } + +} diff --git a/lib/src/main/java/com/diffplug/spotless/npm/PrettierRestService.java b/lib/src/main/java/com/diffplug/spotless/npm/PrettierRestService.java index ced08b013f..2a62823aa0 100644 --- a/lib/src/main/java/com/diffplug/spotless/npm/PrettierRestService.java +++ b/lib/src/main/java/com/diffplug/spotless/npm/PrettierRestService.java @@ -1,5 +1,5 @@ /* - * Copyright 2016-2020 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. @@ -19,12 +19,10 @@ import java.util.LinkedHashMap; import java.util.Map; -public class PrettierRestService { - - private final SimpleRestClient restClient; +public class PrettierRestService extends BaseNpmRestService { PrettierRestService(String baseUrl) { - this.restClient = SimpleRestClient.forBaseUrl(baseUrl); + super(baseUrl); } public String resolveConfig(File prettierConfigPath, Map prettierConfigOptions) { @@ -48,9 +46,4 @@ public String format(String fileContent, String configOptionsJsonString) { return restClient.postJson("/prettier/format", jsonProperties); } - - public String shutdown() { - return restClient.post("/shutdown"); - } - } diff --git a/lib/src/main/java/com/diffplug/spotless/npm/TsFmtRestService.java b/lib/src/main/java/com/diffplug/spotless/npm/TsFmtRestService.java index a47b608c36..f77510c3b6 100644 --- a/lib/src/main/java/com/diffplug/spotless/npm/TsFmtRestService.java +++ b/lib/src/main/java/com/diffplug/spotless/npm/TsFmtRestService.java @@ -1,5 +1,5 @@ /* - * Copyright 2016-2020 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. @@ -18,12 +18,10 @@ import java.util.LinkedHashMap; import java.util.Map; -public class TsFmtRestService { - - private final SimpleRestClient restClient; +public class TsFmtRestService extends BaseNpmRestService { TsFmtRestService(String baseUrl) { - this.restClient = SimpleRestClient.forBaseUrl(baseUrl); + super(baseUrl); } public String format(String fileContent, Map configOptions) { @@ -35,9 +33,4 @@ public String format(String fileContent, Map configOptions) { return restClient.postJson("/tsfmt/format", jsonProperties); } - - public String shutdown() { - return restClient.post("/shutdown"); - } - } From c20d3bb14adae3b90654b0531ac12a06d468185a Mon Sep 17 00:00:00 2001 From: Simon Gamma Date: Sat, 3 Dec 2022 19:53:24 +0100 Subject: [PATCH 419/757] add "eslint --fix" as formatter --- .../diffplug/spotless/npm/EslintConfig.java | 61 +++++ .../spotless/npm/EslintFormatterStep.java | 219 ++++++++++++++++++ .../spotless/npm/EslintRestService.java | 46 ++++ .../spotless/npm/NpmResourceHelper.java | 11 + .../diffplug/spotless/npm/eslint-package.json | 19 ++ .../com/diffplug/spotless/npm/eslint-serve.js | 66 ++++++ .../gradle/spotless/FormatExtension.java | 87 ++++++- .../gradle/spotless/TypescriptExtension.java | 56 ++++- .../spotless/TypescriptExtensionTest.java | 21 +- .../resources/npm/eslint/config/.eslintrc.js | 38 +++ .../eslint/config/typescript.configfile.clean | 15 ++ .../eslint/config/typescript.defaults.clean | 11 + .../npm/eslint/config/typescript.dirty | 10 + .../eslint/config/typescript.override.clean | 9 + .../eslint/filetypes/typescript/.eslintrc.js | 59 +++++ .../filetypes/typescript/typescript.clean | 11 + .../filetypes/typescript/typescript.dirty | 11 + 17 files changed, 737 insertions(+), 13 deletions(-) create mode 100644 lib/src/main/java/com/diffplug/spotless/npm/EslintConfig.java create mode 100644 lib/src/main/java/com/diffplug/spotless/npm/EslintFormatterStep.java create mode 100644 lib/src/main/java/com/diffplug/spotless/npm/EslintRestService.java create mode 100644 lib/src/main/resources/com/diffplug/spotless/npm/eslint-package.json create mode 100644 lib/src/main/resources/com/diffplug/spotless/npm/eslint-serve.js create mode 100644 testlib/src/main/resources/npm/eslint/config/.eslintrc.js create mode 100644 testlib/src/main/resources/npm/eslint/config/typescript.configfile.clean create mode 100644 testlib/src/main/resources/npm/eslint/config/typescript.defaults.clean create mode 100644 testlib/src/main/resources/npm/eslint/config/typescript.dirty create mode 100644 testlib/src/main/resources/npm/eslint/config/typescript.override.clean create mode 100644 testlib/src/main/resources/npm/eslint/filetypes/typescript/.eslintrc.js create mode 100644 testlib/src/main/resources/npm/eslint/filetypes/typescript/typescript.clean create mode 100644 testlib/src/main/resources/npm/eslint/filetypes/typescript/typescript.dirty diff --git a/lib/src/main/java/com/diffplug/spotless/npm/EslintConfig.java b/lib/src/main/java/com/diffplug/spotless/npm/EslintConfig.java new file mode 100644 index 0000000000..a6d41f9bc0 --- /dev/null +++ b/lib/src/main/java/com/diffplug/spotless/npm/EslintConfig.java @@ -0,0 +1,61 @@ +/* + * 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. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.diffplug.spotless.npm; + +import java.io.File; +import java.io.IOException; +import java.io.Serializable; + +import javax.annotation.Nullable; + +import com.diffplug.spotless.FileSignature; +import com.diffplug.spotless.ThrowingEx; + +import edu.umd.cs.findbugs.annotations.SuppressFBWarnings; + +public class EslintConfig implements Serializable { + + private static final long serialVersionUID = -6196834313082791248L; + + @SuppressFBWarnings("SE_TRANSIENT_FIELD_NOT_RESTORED") + @Nullable + private final transient File eslintConfigPath; + + @SuppressWarnings("unused") + private final FileSignature eslintConfigPathSignature; + + private final String eslintConfigJs; + + public EslintConfig(@Nullable File eslintConfigPath, @Nullable String eslintConfigJs) { + try { + this.eslintConfigPath = eslintConfigPath; + this.eslintConfigPathSignature = eslintConfigPath != null ? FileSignature.signAsList(this.eslintConfigPath) : FileSignature.signAsList(); + this.eslintConfigJs = eslintConfigJs; + } catch (IOException e) { + throw ThrowingEx.asRuntime(e); + } + } + + @Nullable + public File getEslintConfigPath() { + return eslintConfigPath; + } + + @Nullable + public String getEslintConfigJs() { + return eslintConfigJs; + } +} diff --git a/lib/src/main/java/com/diffplug/spotless/npm/EslintFormatterStep.java b/lib/src/main/java/com/diffplug/spotless/npm/EslintFormatterStep.java new file mode 100644 index 0000000000..83d60a72c1 --- /dev/null +++ b/lib/src/main/java/com/diffplug/spotless/npm/EslintFormatterStep.java @@ -0,0 +1,219 @@ +/* + * 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. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.diffplug.spotless.npm; + +import static java.util.Objects.requireNonNull; + +import java.io.File; +import java.io.IOException; +import java.io.Serializable; +import java.util.Collections; +import java.util.HashMap; +import java.util.LinkedHashMap; +import java.util.Map; +import java.util.Objects; +import java.util.TreeMap; + +import javax.annotation.Nonnull; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import com.diffplug.spotless.FormatterFunc; +import com.diffplug.spotless.FormatterFunc.Closeable; +import com.diffplug.spotless.FormatterStep; +import com.diffplug.spotless.Provisioner; +import com.diffplug.spotless.ThrowingEx; +import com.diffplug.spotless.npm.EslintRestService.FormatOption; + +public class EslintFormatterStep { + + private static final Logger logger = LoggerFactory.getLogger(EslintFormatterStep.class); + + public static final String NAME = "eslint-format"; + + public static final String DEFAULT_ESLINT_VERSION = "8.28.0"; + + public enum PopularStyleGuide { + STANDARD_WITH_TYPESCRIPT("standard-with-typescript") { + @Override + public Map devDependencies() { + Map dependencies = new LinkedHashMap<>(); + dependencies.put("eslint-config-standard-with-typescript", "23.0.0"); + dependencies.put("eslint-plugin-import", "2.26.0"); + dependencies.put("eslint-plugin-n", "15.5.1"); + dependencies.put("eslint-plugin-promise", "6.1.1"); + dependencies.put("typescript", "4.9.3"); + return dependencies; + } + }, + XO_TYPESCRIPT("xo-typescript") { + @Override + public Map devDependencies() { + Map dependencies = new LinkedHashMap<>(); + dependencies.put("eslint-config-xo", "0.43.1"); + dependencies.put("eslint-config-xo-typescript", "0.55.1"); + dependencies.put("typescript", "4.9.3"); + return dependencies; + } + }; + + private final String popularStyleGuideName; + + PopularStyleGuide(String popularStyleGuideName) { + this.popularStyleGuideName = popularStyleGuideName; + } + + public String getPopularStyleGuideName() { + return popularStyleGuideName; + } + + public abstract Map devDependencies(); + + public static PopularStyleGuide fromNameOrNull(String popularStyleGuideName) { + for (PopularStyleGuide popularStyleGuide : PopularStyleGuide.values()) { + if (popularStyleGuide.popularStyleGuideName.equals(popularStyleGuideName)) { + return popularStyleGuide; + } + } + return null; + } + } + + public static Map defaultDevDependenciesForTypescript() { + return defaultDevDependenciesTypescriptWithEslint(DEFAULT_ESLINT_VERSION); + } + + public static Map defaultDevDependenciesTypescriptWithEslint(String eslintVersion) { + Map dependencies = new LinkedHashMap<>(); + dependencies.put("@typescript-eslint/eslint-plugin", "5.45.0"); + dependencies.put("@typescript-eslint/parser", "5.45.0"); + dependencies.put("eslint", Objects.requireNonNull(eslintVersion)); + return dependencies; + } + + public static Map defaultDevDependencies() { + return defaultDevDependenciesWithEslint(DEFAULT_ESLINT_VERSION); + } + + public static Map defaultDevDependenciesWithEslint(String version) { + return Collections.singletonMap("eslint", version); + } + + public static FormatterStep create(Map devDependencies, Provisioner provisioner, File buildDir, NpmPathResolver npmPathResolver, EslintConfig eslintConfig) { + requireNonNull(devDependencies); + requireNonNull(provisioner); + requireNonNull(buildDir); + return FormatterStep.createLazy(NAME, + () -> new State(NAME, devDependencies, buildDir, npmPathResolver, eslintConfig), + State::createFormatterFunc); + } + + private static class State extends NpmFormatterStepStateBase implements Serializable { + + private static final long serialVersionUID = -539537027004745812L; + private final EslintConfig eslintConfig; + + State(String stepName, Map devDependencies, File buildDir, NpmPathResolver npmPathResolver, EslintConfig eslintConfig) throws IOException { + super(stepName, + new NpmConfig( + replaceDevDependencies( + NpmResourceHelper.readUtf8StringFromClasspath(EslintFormatterStep.class, "/com/diffplug/spotless/npm/eslint-package.json"), + new TreeMap<>(devDependencies)), + "eslint", + NpmResourceHelper.readUtf8StringFromClasspath(EslintFormatterStep.class, + "/com/diffplug/spotless/npm/common-serve.js", + "/com/diffplug/spotless/npm/eslint-serve.js"), + npmPathResolver.resolveNpmrcContent()), + buildDir, + npmPathResolver.resolveNpmExecutable()); + this.eslintConfig = localCopyFiles(requireNonNull(eslintConfig)); + } + + private EslintConfig localCopyFiles(EslintConfig orig) { + if (orig.getEslintConfigPath() == null) { + return orig; + } + // If a config file is provided, we need to make sure it is at the same location as the node modules + // as eslint will try to resolve plugin/config names relatively to the config file location + FormattedPrinter.SYSOUT.print("Copying config file <%s> to <%s> and using the copy", orig.getEslintConfigPath(), nodeModulesDir); + File configFileCopy = NpmResourceHelper.copyFileToDir(orig.getEslintConfigPath(), nodeModulesDir); + return new EslintConfig(configFileCopy, orig.getEslintConfigJs()); + } + + @Override + @Nonnull + public FormatterFunc createFormatterFunc() { + try { + FormattedPrinter.SYSOUT.print("creating formatter function (starting server)"); + ServerProcessInfo eslintRestServer = npmRunServer(); + EslintRestService restService = new EslintRestService(eslintRestServer.getBaseUrl()); + + // String prettierConfigOptions = restService.resolveConfig(this.prettierConfig.getPrettierConfigPath(), this.prettierConfig.getOptions()); + return Closeable.ofDangerous(() -> endServer(restService, eslintRestServer), new EslintFilePathPassingFormatterFunc(nodeModulesDir, eslintConfig, restService)); + } catch (IOException e) { + throw ThrowingEx.asRuntime(e); + } + } + + private void endServer(BaseNpmRestService restService, ServerProcessInfo restServer) throws Exception { + FormattedPrinter.SYSOUT.print("Closing formatting function (ending server)."); + try { + restService.shutdown(); + } catch (Throwable t) { + logger.info("Failed to request shutdown of rest service via api. Trying via process.", t); + } + restServer.close(); + } + + } + + private static class EslintFilePathPassingFormatterFunc implements FormatterFunc.NeedsFile { + private final File nodeModulesDir; + private final EslintConfig eslintConfig; + private final EslintRestService restService; + + public EslintFilePathPassingFormatterFunc(File nodeModulesDir, EslintConfig eslintConfig, EslintRestService restService) { + this.nodeModulesDir = nodeModulesDir; + this.eslintConfig = requireNonNull(eslintConfig); + this.restService = requireNonNull(restService); + } + + @Override + public String applyWithFile(String unix, File file) throws Exception { + FormattedPrinter.SYSOUT.print("formatting String '" + unix.substring(0, Math.min(50, unix.length())) + "[...]' in file '" + file + "'"); + + Map eslintCallOptions = new HashMap<>(); + setConfigToCallOptions(eslintCallOptions); + setFilePathToCallOptions(eslintCallOptions, file); + return restService.format(unix, eslintCallOptions); + } + + private void setFilePathToCallOptions(Map eslintCallOptions, File fileToBeFormatted) { + eslintCallOptions.put(FormatOption.FILE_PATH, fileToBeFormatted.getAbsolutePath()); + } + + private void setConfigToCallOptions(Map eslintCallOptions) { + if (eslintConfig.getEslintConfigPath() != null) { + eslintCallOptions.put(FormatOption.ESLINT_OVERRIDE_CONFIG_FILE, eslintConfig.getEslintConfigPath().getAbsolutePath()); + } + if (eslintConfig.getEslintConfigJs() != null) { + eslintCallOptions.put(FormatOption.ESLINT_OVERRIDE_CONFIG, eslintConfig.getEslintConfigJs()); + } + eslintCallOptions.put(FormatOption.NODE_MODULES_DIR, nodeModulesDir.getAbsolutePath()); + } + } +} diff --git a/lib/src/main/java/com/diffplug/spotless/npm/EslintRestService.java b/lib/src/main/java/com/diffplug/spotless/npm/EslintRestService.java new file mode 100644 index 0000000000..541b77bab8 --- /dev/null +++ b/lib/src/main/java/com/diffplug/spotless/npm/EslintRestService.java @@ -0,0 +1,46 @@ +/* + * 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. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.diffplug.spotless.npm; + +import java.util.LinkedHashMap; +import java.util.Map; +import java.util.Map.Entry; + +public class EslintRestService extends BaseNpmRestService { + + EslintRestService(String baseUrl) { + super(baseUrl); + } + + public String format(String fileContent, Map formatOptions) { + Map jsonProperties = new LinkedHashMap<>(); + jsonProperties.put("file_content", fileContent); + for (Entry option : formatOptions.entrySet()) { + jsonProperties.put(option.getKey().backendName, option.getValue()); + } + return restClient.postJson("/eslint/format", jsonProperties); + } + + enum FormatOption { + ESLINT_OVERRIDE_CONFIG("eslint_override_config"), ESLINT_OVERRIDE_CONFIG_FILE("eslint_override_config_file"), FILE_PATH("file_path"), NODE_MODULES_DIR("node_modules_dir"); + + private final String backendName; + + FormatOption(String backendName) { + this.backendName = backendName; + } + } +} diff --git a/lib/src/main/java/com/diffplug/spotless/npm/NpmResourceHelper.java b/lib/src/main/java/com/diffplug/spotless/npm/NpmResourceHelper.java index cb6fff3290..4f97e7e732 100644 --- a/lib/src/main/java/com/diffplug/spotless/npm/NpmResourceHelper.java +++ b/lib/src/main/java/com/diffplug/spotless/npm/NpmResourceHelper.java @@ -18,6 +18,7 @@ import java.io.*; import java.nio.charset.StandardCharsets; import java.nio.file.Files; +import java.nio.file.StandardCopyOption; import java.time.Duration; import java.util.Arrays; import java.util.concurrent.TimeoutException; @@ -100,4 +101,14 @@ static void awaitReadableFile(File file, Duration maxWaitTime) throws TimeoutExc } } } + + static File copyFileToDir(File file, File targetDir) { + try { + File copiedFile = new File(targetDir, file.getName()); + Files.copy(file.toPath(), copiedFile.toPath(), StandardCopyOption.REPLACE_EXISTING); + return copiedFile; + } catch (IOException e) { + throw ThrowingEx.asRuntime(e); + } + } } diff --git a/lib/src/main/resources/com/diffplug/spotless/npm/eslint-package.json b/lib/src/main/resources/com/diffplug/spotless/npm/eslint-package.json new file mode 100644 index 0000000000..dcd91e729d --- /dev/null +++ b/lib/src/main/resources/com/diffplug/spotless/npm/eslint-package.json @@ -0,0 +1,19 @@ +{ + "name": "spotless-eslint-formatter-step", + "version": "2.0.0", + "description": "Spotless formatter step for running eslint as a rest service.", + "repository": "https://github.com/diffplug/spotless", + "license": "Apache-2.0", + "scripts": { + "start": "node serve.js" + }, + "devDependencies": { +${devDependencies}, + "express": "4.18.2", + "@moebius/http-graceful-shutdown": "1.1.0" + }, + "dependencies": {}, + "engines": { + "node": ">=6" + } +} diff --git a/lib/src/main/resources/com/diffplug/spotless/npm/eslint-serve.js b/lib/src/main/resources/com/diffplug/spotless/npm/eslint-serve.js new file mode 100644 index 0000000000..8c56b8ef08 --- /dev/null +++ b/lib/src/main/resources/com/diffplug/spotless/npm/eslint-serve.js @@ -0,0 +1,66 @@ +const {ESLint} = require("eslint"); + +app.post("/eslint/format", async (req, res) => { + + const format_data = req.body; + + const ESLintOverrideConfig = format_data.eslint_override_config; + + const ESLintOverrideConfigFile = format_data.eslint_override_config_file; + + if (!ESLintOverrideConfig && !ESLintOverrideConfigFile) { + res.status(501).send("Error while formatting: No config provided"); + return; + } + + const filePath = format_data.file_path; + + if (!filePath) { + res.status(501).send("Error while formatting: No file path provided"); + return; + } + + const ESLintOptions = { + fix: true, + useEslintrc: false, // would result in (gradle) cache issues + resolvePluginsRelativeTo: format_data.node_modules_dir + }; + + + if (ESLintOverrideConfigFile) { + ESLintOptions.overrideConfigFile = ESLintOverrideConfigFile; + } + if (ESLintOverrideConfig) { + ESLintOptions.overrideConfig = ESLintOverrideConfig; + } + + const eslint = new ESLint(ESLintOptions); + + + try { + console.log("using options: " + JSON.stringify(ESLintOptions)); + console.log("format input", format_data.file_content); + const lintTextOptions = { + filePath: filePath, + } + console.log("lintTextOptions", lintTextOptions); + // LintResult[] // https://eslint.org/docs/latest/developer-guide/nodejs-api#-lintresult-type + const results = await eslint.lintText(format_data.file_content, lintTextOptions); + if (results.length !== 1) { + res.status(501).send("Error while formatting: Unexpected number of results"); + return; + } + const result = results[0]; + console.log("result: " + JSON.stringify(result)); + if (result.fatalErrorCount && result.fatalErrorCount > 0) { + res.status(501).send("Fatal error while formatting: " + JSON.stringify(result.messages)); + return; + } + const formatted = result.output || result.source || format_data.file_content; + res.set("Content-Type", "text/plain"); + res.send(formatted); + } catch (err) { + console.log("error", err); + res.status(501).send("Error while formatting: " + err); + } +}); 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 de0313eab4..99e21bd8c8 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 @@ -16,6 +16,7 @@ package com.diffplug.gradle.spotless; import static com.diffplug.gradle.spotless.PluginGradlePreconditions.requireElementsNonNull; +import static java.util.Objects.requireNonNull; import java.io.File; import java.io.Serializable; @@ -23,9 +24,9 @@ import java.nio.file.Files; import java.util.ArrayList; import java.util.Collection; +import java.util.LinkedHashMap; import java.util.List; import java.util.Map; -import java.util.Objects; import java.util.Random; import java.util.TreeMap; @@ -59,6 +60,8 @@ import com.diffplug.spotless.generic.ReplaceRegexStep; import com.diffplug.spotless.generic.ReplaceStep; import com.diffplug.spotless.generic.TrimTrailingWhitespaceStep; +import com.diffplug.spotless.npm.EslintConfig; +import com.diffplug.spotless.npm.EslintFormatterStep; import com.diffplug.spotless.npm.NpmPathResolver; import com.diffplug.spotless.npm.PrettierFormatterStep; @@ -71,7 +74,7 @@ public class FormatExtension { @Inject public FormatExtension(SpotlessExtension spotless) { - this.spotless = Objects.requireNonNull(spotless); + this.spotless = requireNonNull(spotless); } protected final Provisioner provisioner() { @@ -96,7 +99,7 @@ public LineEnding getLineEndings() { /** Sets the line endings to use (defaults to {@link SpotlessExtensionImpl#getLineEndings()}. */ public void setLineEndings(LineEnding lineEndings) { - this.lineEndings = Objects.requireNonNull(lineEndings); + this.lineEndings = requireNonNull(lineEndings); } Charset encoding; @@ -108,7 +111,7 @@ public Charset getEncoding() { /** Sets the encoding to use (defaults to {@link SpotlessExtensionImpl#getEncoding()}. */ public void setEncoding(String name) { - setEncoding(Charset.forName(Objects.requireNonNull(name))); + setEncoding(Charset.forName(requireNonNull(name))); } /** Sentinel to distinguish between "don't ratchet this format" and "use spotless parent format". */ @@ -136,19 +139,19 @@ public void ratchetFrom(String ratchetFrom) { /** Sets the encoding to use (defaults to {@link SpotlessExtensionImpl#getEncoding()}. */ public void setEncoding(Charset charset) { - encoding = Objects.requireNonNull(charset); + encoding = requireNonNull(charset); } final FormatExceptionPolicyStrict exceptionPolicy = new FormatExceptionPolicyStrict(); /** Ignores errors in the given step. */ public void ignoreErrorForStep(String stepName) { - exceptionPolicy.excludeStep(Objects.requireNonNull(stepName)); + exceptionPolicy.excludeStep(requireNonNull(stepName)); } /** Ignores errors for the given relative path. */ public void ignoreErrorForPath(String relativePath) { - exceptionPolicy.excludePath(Objects.requireNonNull(relativePath)); + exceptionPolicy.excludePath(requireNonNull(relativePath)); } /** Sets encoding to use (defaults to {@link SpotlessExtensionImpl#getEncoding()}). */ @@ -290,7 +293,7 @@ private static void relativizeIfSubdir(List relativePaths, File root, Fi /** Adds a new step. */ public void addStep(FormatterStep newStep) { - Objects.requireNonNull(newStep); + requireNonNull(newStep); int existingIdx = getExistingStepIdx(newStep.getName()); if (existingIdx != -1) { throw new GradleException("Multiple steps with name '" + newStep.getName() + "' for spotless format '" + formatName() + "'"); @@ -356,13 +359,13 @@ protected Integer calculateState() throws Exception { /** Adds a custom step. Receives a string with unix-newlines, must return a string with unix newlines. */ public void custom(String name, Closure formatter) { - Objects.requireNonNull(formatter, "formatter"); + requireNonNull(formatter, "formatter"); custom(name, formatter::call); } /** Adds a custom step. Receives a string with unix-newlines, must return a string with unix newlines. */ public void custom(String name, FormatterFunc formatter) { - Objects.requireNonNull(formatter, "formatter"); + requireNonNull(formatter, "formatter"); addStep(FormatterStep.createLazy(name, () -> globalState, unusedState -> formatter)); } @@ -560,7 +563,7 @@ public class PrettierConfig extends NpmStepConfig { final Map devDependencies; PrettierConfig(Map devDependencies) { - this.devDependencies = Objects.requireNonNull(devDependencies); + this.devDependencies = requireNonNull(devDependencies); } public PrettierConfig configFile(final Object prettierConfigFile) { @@ -605,6 +608,68 @@ public PrettierConfig prettier(Map devDependencies) { return prettierConfig; } + public class EslintFormatExtension extends NpmStepConfig { + + Map devDependencies = new LinkedHashMap<>(); + + @Nullable + Object configFilePath = null; + + @Nullable + String configJs = null; + + public EslintFormatExtension(Map devDependencies) { + this.devDependencies.putAll(requireNonNull(devDependencies)); + } + + public EslintFormatExtension devDependencies(Map devDependencies) { + this.devDependencies.putAll(devDependencies); + replaceStep(createStep()); + return this; + } + + public EslintFormatExtension configJs(String configJs) { + this.configJs = requireNonNull(configJs); + replaceStep(createStep()); + return this; + } + + public EslintFormatExtension configFile(Object configFilePath) { + this.configFilePath = requireNonNull(configFilePath); + replaceStep(createStep()); + return this; + } + + public FormatterStep createStep() { + final Project project = getProject(); + + return EslintFormatterStep.create( + devDependencies, + provisioner(), + project.getBuildDir(), + new NpmPathResolver(npmFileOrNull(), npmrcFileOrNull(), project.getProjectDir(), project.getRootDir()), + eslintConfig()); + } + + private EslintConfig eslintConfig() { + return new EslintConfig(configFilePath != null ? getProject().file(configFilePath) : null, configJs); + } + } + + public EslintFormatExtension eslint() { + return eslint(EslintFormatterStep.defaultDevDependencies()); + } + + public EslintFormatExtension eslint(String version) { + return eslint(EslintFormatterStep.defaultDevDependenciesWithEslint(version)); + } + + public EslintFormatExtension eslint(Map devDependencies) { + EslintFormatExtension eslint = new EslintFormatExtension(devDependencies); + addStep(eslint.createStep()); + return eslint; + } + /** Uses the default version of clang-format. */ public ClangFormatConfig clangFormat() { return clangFormat(ClangFormatStep.defaultVersion()); diff --git a/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/TypescriptExtension.java b/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/TypescriptExtension.java index 58b9d4acbb..e80730d5ed 100644 --- a/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/TypescriptExtension.java +++ b/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/TypescriptExtension.java @@ -1,5 +1,5 @@ /* - * Copyright 2016-2020 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,10 +17,12 @@ import static java.util.Objects.requireNonNull; +import java.util.Arrays; import java.util.Collections; import java.util.Map; import java.util.Objects; import java.util.TreeMap; +import java.util.stream.Collectors; import javax.annotation.Nullable; import javax.inject.Inject; @@ -28,6 +30,8 @@ import org.gradle.api.Project; import com.diffplug.spotless.FormatterStep; +import com.diffplug.spotless.npm.EslintFormatterStep; +import com.diffplug.spotless.npm.EslintFormatterStep.PopularStyleGuide; import com.diffplug.spotless.npm.NpmPathResolver; import com.diffplug.spotless.npm.PrettierFormatterStep; import com.diffplug.spotless.npm.TsConfigFileType; @@ -169,6 +173,56 @@ private void fixParserToTypescript() { } } + @Override + public TypescriptEslintFormatExtension eslint() { + return eslint(EslintFormatterStep.defaultDevDependenciesForTypescript()); + } + + @Override + public TypescriptEslintFormatExtension eslint(String version) { + return eslint(EslintFormatterStep.defaultDevDependenciesTypescriptWithEslint(version)); + } + + @Override + public TypescriptEslintFormatExtension eslint(Map devDependencies) { + TypescriptEslintFormatExtension eslint = new TypescriptEslintFormatExtension(devDependencies); + addStep(eslint.createStep()); + return eslint; + } + + public class TypescriptEslintFormatExtension extends EslintFormatExtension { + + public TypescriptEslintFormatExtension(Map devDependencies) { + super(devDependencies); + } + + @Override + public TypescriptEslintFormatExtension devDependencies(Map devDependencies) { + return (TypescriptEslintFormatExtension) super.devDependencies(devDependencies); + } + + @Override + public TypescriptEslintFormatExtension configJs(String configJs) { + return (TypescriptEslintFormatExtension) super.configJs(configJs); + } + + @Override + public TypescriptEslintFormatExtension configFile(Object configFilePath) { + return (TypescriptEslintFormatExtension) super.configFile(configFilePath); + } + + public TypescriptEslintFormatExtension styleGuide(String styleGuide) { + PopularStyleGuide popularStyleGuide = PopularStyleGuide.fromNameOrNull(styleGuide); + if (popularStyleGuide == null) { + throw new IllegalArgumentException("Unknown style guide: " + styleGuide + ". Known style guides: " + + Arrays.stream(PopularStyleGuide.values()).map(PopularStyleGuide::getPopularStyleGuideName).collect(Collectors.joining(", "))); + } + devDependencies(popularStyleGuide.devDependencies()); + replaceStep(createStep()); + return this; + } + } + @Override protected void setupTask(SpotlessTask task) { // defaults to all typescript files diff --git a/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/TypescriptExtensionTest.java b/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/TypescriptExtensionTest.java index 100c4eb3b0..40da7e3536 100644 --- a/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/TypescriptExtensionTest.java +++ b/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/TypescriptExtensionTest.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. @@ -141,4 +141,23 @@ void usePrettier() throws IOException { gradleRunner().withArguments("--stacktrace", "spotlessApply").build(); assertFile("test.ts").sameAsResource("npm/prettier/filetypes/typescript/typescript.clean"); } + + @Test + void useEslint() throws IOException { + setFile(".eslintrc.js").toResource("npm/eslint/filetypes/typescript/.eslintrc.js"); + setFile("build.gradle").toLines( + "plugins {", + " id 'com.diffplug.spotless'", + "}", + "repositories { mavenCentral() }", + "spotless {", + " typescript {", + " target 'test.ts'", + " eslint().configFile('.eslintrc.js')", + " }", + "}"); + setFile("test.ts").toResource("npm/eslint/filetypes/typescript/typescript.dirty"); + gradleRunner().withArguments("--stacktrace", "spotlessApply").build(); + assertFile("test.ts").sameAsResource("npm/eslint/filetypes/typescript/typescript.clean"); + } } diff --git a/testlib/src/main/resources/npm/eslint/config/.eslintrc.js b/testlib/src/main/resources/npm/eslint/config/.eslintrc.js new file mode 100644 index 0000000000..6cb3070512 --- /dev/null +++ b/testlib/src/main/resources/npm/eslint/config/.eslintrc.js @@ -0,0 +1,38 @@ +module.exports = { + "env": { + "browser": true, + "es2021": true + }, + "extends": [ + "eslint:recommended", + "plugin:@typescript-eslint/recommended" + ], + "overrides": [ + ], + "parser": "@typescript-eslint/parser", + "parserOptions": { + "ecmaVersion": "latest", + "sourceType": "module" + }, + "plugins": [ + "@typescript-eslint" + ], + "rules": { + "indent": [ + "error", + 4 + ], + "linebreak-style": [ + "error", + "unix" + ], + "quotes": [ + "error", + "double" + ], + "semi": [ + "error", + "always" + ] + } +}; diff --git a/testlib/src/main/resources/npm/eslint/config/typescript.configfile.clean b/testlib/src/main/resources/npm/eslint/config/typescript.configfile.clean new file mode 100644 index 0000000000..0ec76369be --- /dev/null +++ b/testlib/src/main/resources/npm/eslint/config/typescript.configfile.clean @@ -0,0 +1,15 @@ +export class MyVeryOwnControllerWithARatherLongNameThatIsNotReallyNecessary + extends AbstractController + implements DisposeAware, CallbackAware { + public myValue: string[]; + + constructor( + private myService: Service, + name: string, + private field: any + ) { + super(name); + } + + //... +} diff --git a/testlib/src/main/resources/npm/eslint/config/typescript.defaults.clean b/testlib/src/main/resources/npm/eslint/config/typescript.defaults.clean new file mode 100644 index 0000000000..0155b905bd --- /dev/null +++ b/testlib/src/main/resources/npm/eslint/config/typescript.defaults.clean @@ -0,0 +1,11 @@ +export class MyVeryOwnControllerWithARatherLongNameThatIsNotReallyNecessary + extends AbstractController + implements DisposeAware, CallbackAware { + public myValue: string[]; + + constructor(private myService: Service, name: string, private field: any) { + super(name); + } + + //... +} diff --git a/testlib/src/main/resources/npm/eslint/config/typescript.dirty b/testlib/src/main/resources/npm/eslint/config/typescript.dirty new file mode 100644 index 0000000000..a3a30bf49a --- /dev/null +++ b/testlib/src/main/resources/npm/eslint/config/typescript.dirty @@ -0,0 +1,10 @@ +export class MyVeryOwnControllerWithARatherLongNameThatIsNotReallyNecessary extends AbstractController implements DisposeAware, CallbackAware { + + +public myValue:string[]; + +constructor(private myService:Service,name:string,private field:any){ super(name) ;} + + +//... +} diff --git a/testlib/src/main/resources/npm/eslint/config/typescript.override.clean b/testlib/src/main/resources/npm/eslint/config/typescript.override.clean new file mode 100644 index 0000000000..3f3a8c30af --- /dev/null +++ b/testlib/src/main/resources/npm/eslint/config/typescript.override.clean @@ -0,0 +1,9 @@ +export class MyVeryOwnControllerWithARatherLongNameThatIsNotReallyNecessary extends AbstractController implements DisposeAware, CallbackAware { + public myValue: string[]; + + constructor(private myService: Service, name: string, private field: any) { + super(name); + } + + //... +} diff --git a/testlib/src/main/resources/npm/eslint/filetypes/typescript/.eslintrc.js b/testlib/src/main/resources/npm/eslint/filetypes/typescript/.eslintrc.js new file mode 100644 index 0000000000..e6ddff7d4c --- /dev/null +++ b/testlib/src/main/resources/npm/eslint/filetypes/typescript/.eslintrc.js @@ -0,0 +1,59 @@ +module.exports = { + "env": { + "browser": true, + "es2021": true + }, + "extends": [ + "eslint:recommended", + "plugin:@typescript-eslint/recommended" + ], + "overrides": [ + ], + "parser": "@typescript-eslint/parser", + "parserOptions": { + "ecmaVersion": "latest", + "sourceType": "module" + }, + "plugins": [ + "@typescript-eslint" + ], + "rules": { + "indent": [ + "error", + 4 + ], + "linebreak-style": [ + "error", + "unix" + ], + "quotes": [ + "error", + "double" + ], + "semi": [ + "error", + "always" + ], + "curly": [ + "error" + ], + "max-statements-per-line": [ + "error", + { "max": 1 } + ], + "object-curly-newline": [ + "error", + "always" + ], + "comma-spacing": [ + "error", + { "before": false, "after": true } + ], + "object-property-newline": [ + "error", + ], + "no-trailing-spaces": [ + "error" + ], + } +}; diff --git a/testlib/src/main/resources/npm/eslint/filetypes/typescript/typescript.clean b/testlib/src/main/resources/npm/eslint/filetypes/typescript/typescript.clean new file mode 100644 index 0000000000..526519cae9 --- /dev/null +++ b/testlib/src/main/resources/npm/eslint/filetypes/typescript/typescript.clean @@ -0,0 +1,11 @@ +export class MyController extends AbstractController implements DisposeAware, CallbackAware { + + + public myValue:string[]; + + constructor(private myService:Service, name:string, private field:any){ super(name) ;} + + + //... + +} diff --git a/testlib/src/main/resources/npm/eslint/filetypes/typescript/typescript.dirty b/testlib/src/main/resources/npm/eslint/filetypes/typescript/typescript.dirty new file mode 100644 index 0000000000..0a9201c2e7 --- /dev/null +++ b/testlib/src/main/resources/npm/eslint/filetypes/typescript/typescript.dirty @@ -0,0 +1,11 @@ +export class MyController extends AbstractController implements DisposeAware, CallbackAware { + + +public myValue:string[]; + +constructor(private myService:Service,name:string,private field:any){ super(name) ;} + + +//... + +} From 4f5e4d343d08831104abd7faec86d8ff820b3125 Mon Sep 17 00:00:00 2001 From: Simon Gamma Date: Wed, 7 Dec 2022 20:01:32 +0100 Subject: [PATCH 420/757] eslint: add support for xo standard typescript ruleset --- .../diffplug/spotless/npm/EslintConfig.java | 19 ++++++++- .../spotless/npm/EslintFormatterStep.java | 42 ++++++++++++------- .../spotless/npm/EslintRestService.java | 2 +- .../npm/NpmFormatterStepStateBase.java | 6 ++- .../spotless/npm/NpmResourceHelper.java | 17 ++++++-- .../spotless/npm/PrettierFormatterStep.java | 7 ++-- .../spotless/npm/TsFmtFormatterStep.java | 7 ++-- .../com/diffplug/spotless/npm/eslint-serve.js | 14 +++++++ .../gradle/spotless/FormatExtension.java | 32 +++++++++++++- .../gradle/spotless/TypescriptExtension.java | 11 +++++ .../spotless/TypescriptExtensionTest.java | 26 ++++++++++-- .../custom_rules}/.eslintrc.js | 0 .../custom_rules}/typescript.clean | 0 .../custom_rules}/typescript.dirty | 0 .../typescript/standard_rules_xo/.eslintrc.js | 26 ++++++++++++ .../standard_rules_xo/tsconfig.json | 18 ++++++++ .../standard_rules_xo/typescript.clean | 9 ++++ .../standard_rules_xo/typescript.dirty | 10 +++++ 18 files changed, 216 insertions(+), 30 deletions(-) rename testlib/src/main/resources/npm/eslint/{filetypes/typescript => typescript/custom_rules}/.eslintrc.js (100%) rename testlib/src/main/resources/npm/eslint/{filetypes/typescript => typescript/custom_rules}/typescript.clean (100%) rename testlib/src/main/resources/npm/eslint/{filetypes/typescript => typescript/custom_rules}/typescript.dirty (100%) create mode 100644 testlib/src/main/resources/npm/eslint/typescript/standard_rules_xo/.eslintrc.js create mode 100644 testlib/src/main/resources/npm/eslint/typescript/standard_rules_xo/tsconfig.json create mode 100644 testlib/src/main/resources/npm/eslint/typescript/standard_rules_xo/typescript.clean create mode 100644 testlib/src/main/resources/npm/eslint/typescript/standard_rules_xo/typescript.dirty diff --git a/lib/src/main/java/com/diffplug/spotless/npm/EslintConfig.java b/lib/src/main/java/com/diffplug/spotless/npm/EslintConfig.java index a6d41f9bc0..83f5ab1a73 100644 --- a/lib/src/main/java/com/diffplug/spotless/npm/EslintConfig.java +++ b/lib/src/main/java/com/diffplug/spotless/npm/EslintConfig.java @@ -18,7 +18,12 @@ import java.io.File; import java.io.IOException; import java.io.Serializable; +import java.util.Collections; +import java.util.Map; +import java.util.Optional; +import java.util.TreeMap; +import javax.annotation.Nonnull; import javax.annotation.Nullable; import com.diffplug.spotless.FileSignature; @@ -39,11 +44,18 @@ public class EslintConfig implements Serializable { private final String eslintConfigJs; - public EslintConfig(@Nullable File eslintConfigPath, @Nullable String eslintConfigJs) { + @SuppressFBWarnings("SE_TRANSIENT_FIELD_NOT_RESTORED") + private final transient Map> additionalConfigFiles; // key: source-file, value: target-remapping path relative to package.json (if needed) + + private final FileSignature additionalConfigFilesSignature; + + public EslintConfig(@Nullable File eslintConfigPath, @Nullable String eslintConfigJs, Map> additionalConfigFiles) { try { this.eslintConfigPath = eslintConfigPath; this.eslintConfigPathSignature = eslintConfigPath != null ? FileSignature.signAsList(this.eslintConfigPath) : FileSignature.signAsList(); this.eslintConfigJs = eslintConfigJs; + this.additionalConfigFiles = additionalConfigFiles != null ? new TreeMap<>(additionalConfigFiles) : Collections.emptyMap(); + this.additionalConfigFilesSignature = FileSignature.signAsList(this.additionalConfigFiles.keySet().toArray(new File[0])); } catch (IOException e) { throw ThrowingEx.asRuntime(e); } @@ -58,4 +70,9 @@ public File getEslintConfigPath() { public String getEslintConfigJs() { return eslintConfigJs; } + + @Nonnull + public Map> getAdditionalConfigFiles() { + return additionalConfigFiles; + } } diff --git a/lib/src/main/java/com/diffplug/spotless/npm/EslintFormatterStep.java b/lib/src/main/java/com/diffplug/spotless/npm/EslintFormatterStep.java index 83d60a72c1..492cf0da90 100644 --- a/lib/src/main/java/com/diffplug/spotless/npm/EslintFormatterStep.java +++ b/lib/src/main/java/com/diffplug/spotless/npm/EslintFormatterStep.java @@ -25,6 +25,7 @@ import java.util.LinkedHashMap; import java.util.Map; import java.util.Objects; +import java.util.Optional; import java.util.TreeMap; import javax.annotation.Nonnull; @@ -113,12 +114,13 @@ public static Map defaultDevDependenciesWithEslint(String versio return Collections.singletonMap("eslint", version); } - public static FormatterStep create(Map devDependencies, Provisioner provisioner, File buildDir, NpmPathResolver npmPathResolver, EslintConfig eslintConfig) { + public static FormatterStep create(Map devDependencies, Provisioner provisioner, File projectDir, File buildDir, NpmPathResolver npmPathResolver, EslintConfig eslintConfig) { requireNonNull(devDependencies); requireNonNull(provisioner); + requireNonNull(projectDir); requireNonNull(buildDir); return FormatterStep.createLazy(NAME, - () -> new State(NAME, devDependencies, buildDir, npmPathResolver, eslintConfig), + () -> new State(NAME, devDependencies, projectDir, buildDir, npmPathResolver, eslintConfig), State::createFormatterFunc); } @@ -127,7 +129,7 @@ private static class State extends NpmFormatterStepStateBase implements Serializ private static final long serialVersionUID = -539537027004745812L; private final EslintConfig eslintConfig; - State(String stepName, Map devDependencies, File buildDir, NpmPathResolver npmPathResolver, EslintConfig eslintConfig) throws IOException { + State(String stepName, Map devDependencies, File projectDir, File buildDir, NpmPathResolver npmPathResolver, EslintConfig eslintConfig) throws IOException { super(stepName, new NpmConfig( replaceDevDependencies( @@ -138,20 +140,29 @@ private static class State extends NpmFormatterStepStateBase implements Serializ "/com/diffplug/spotless/npm/common-serve.js", "/com/diffplug/spotless/npm/eslint-serve.js"), npmPathResolver.resolveNpmrcContent()), + projectDir, buildDir, npmPathResolver.resolveNpmExecutable()); this.eslintConfig = localCopyFiles(requireNonNull(eslintConfig)); } private EslintConfig localCopyFiles(EslintConfig orig) { - if (orig.getEslintConfigPath() == null) { - return orig; - } - // If a config file is provided, we need to make sure it is at the same location as the node modules - // as eslint will try to resolve plugin/config names relatively to the config file location + // If any config files are provided, we need to make sure they are at the same location as the node modules + // as eslint will try to resolve plugin/config names relatively to the config file location and some + // eslint configs contain relative paths to additional config files (such as tsconfig.json e.g.) FormattedPrinter.SYSOUT.print("Copying config file <%s> to <%s> and using the copy", orig.getEslintConfigPath(), nodeModulesDir); File configFileCopy = NpmResourceHelper.copyFileToDir(orig.getEslintConfigPath(), nodeModulesDir); - return new EslintConfig(configFileCopy, orig.getEslintConfigJs()); + + for (Map.Entry> additionalConfigFile : orig.getAdditionalConfigFiles().entrySet()) { + FormattedPrinter.SYSOUT.print("Copying additional config file <%s> to <%s> at subpath <%s> and using the copy", additionalConfigFile.getKey(), nodeModulesDir, additionalConfigFile.getValue()); + + if (additionalConfigFile.getValue().isPresent()) { + NpmResourceHelper.copyFileToDirAtSubpath(additionalConfigFile.getKey(), nodeModulesDir, additionalConfigFile.getValue().get()); + } else { + NpmResourceHelper.copyFileToDir(additionalConfigFile.getKey(), nodeModulesDir); + } + } + return new EslintConfig(configFileCopy, orig.getEslintConfigJs(), orig.getAdditionalConfigFiles()); } @Override @@ -161,9 +172,7 @@ public FormatterFunc createFormatterFunc() { FormattedPrinter.SYSOUT.print("creating formatter function (starting server)"); ServerProcessInfo eslintRestServer = npmRunServer(); EslintRestService restService = new EslintRestService(eslintRestServer.getBaseUrl()); - - // String prettierConfigOptions = restService.resolveConfig(this.prettierConfig.getPrettierConfigPath(), this.prettierConfig.getOptions()); - return Closeable.ofDangerous(() -> endServer(restService, eslintRestServer), new EslintFilePathPassingFormatterFunc(nodeModulesDir, eslintConfig, restService)); + return Closeable.ofDangerous(() -> endServer(restService, eslintRestServer), new EslintFilePathPassingFormatterFunc(projectDir, nodeModulesDir, eslintConfig, restService)); } catch (IOException e) { throw ThrowingEx.asRuntime(e); } @@ -182,12 +191,14 @@ private void endServer(BaseNpmRestService restService, ServerProcessInfo restSer } private static class EslintFilePathPassingFormatterFunc implements FormatterFunc.NeedsFile { + private final File projectDir; private final File nodeModulesDir; private final EslintConfig eslintConfig; private final EslintRestService restService; - public EslintFilePathPassingFormatterFunc(File nodeModulesDir, EslintConfig eslintConfig, EslintRestService restService) { - this.nodeModulesDir = nodeModulesDir; + public EslintFilePathPassingFormatterFunc(File projectDir, File nodeModulesDir, EslintConfig eslintConfig, EslintRestService restService) { + this.projectDir = requireNonNull(projectDir); + this.nodeModulesDir = requireNonNull(nodeModulesDir); this.eslintConfig = requireNonNull(eslintConfig); this.restService = requireNonNull(restService); } @@ -214,6 +225,9 @@ private void setConfigToCallOptions(Map eslintCallOptions) eslintCallOptions.put(FormatOption.ESLINT_OVERRIDE_CONFIG, eslintConfig.getEslintConfigJs()); } eslintCallOptions.put(FormatOption.NODE_MODULES_DIR, nodeModulesDir.getAbsolutePath()); + + // TODO (simschla, 09.12.22): maybe only add this if there is a typescript config active? (TBD: how to detect) + eslintCallOptions.put(FormatOption.TS_CONFIG_ROOT_DIR, nodeModulesDir.toPath().relativize(projectDir.toPath()).toString()); } } } diff --git a/lib/src/main/java/com/diffplug/spotless/npm/EslintRestService.java b/lib/src/main/java/com/diffplug/spotless/npm/EslintRestService.java index 541b77bab8..d3a01621f1 100644 --- a/lib/src/main/java/com/diffplug/spotless/npm/EslintRestService.java +++ b/lib/src/main/java/com/diffplug/spotless/npm/EslintRestService.java @@ -35,7 +35,7 @@ public String format(String fileContent, Map formatOptions } enum FormatOption { - ESLINT_OVERRIDE_CONFIG("eslint_override_config"), ESLINT_OVERRIDE_CONFIG_FILE("eslint_override_config_file"), FILE_PATH("file_path"), NODE_MODULES_DIR("node_modules_dir"); + ESLINT_OVERRIDE_CONFIG("eslint_override_config"), ESLINT_OVERRIDE_CONFIG_FILE("eslint_override_config_file"), FILE_PATH("file_path"), NODE_MODULES_DIR("node_modules_dir"), TS_CONFIG_ROOT_DIR("ts_config_root_dir"); private final String backendName; diff --git a/lib/src/main/java/com/diffplug/spotless/npm/NpmFormatterStepStateBase.java b/lib/src/main/java/com/diffplug/spotless/npm/NpmFormatterStepStateBase.java index 2e8d80e471..fc1543fd61 100644 --- a/lib/src/main/java/com/diffplug/spotless/npm/NpmFormatterStepStateBase.java +++ b/lib/src/main/java/com/diffplug/spotless/npm/NpmFormatterStepStateBase.java @@ -51,13 +51,17 @@ abstract class NpmFormatterStepStateBase implements Serializable { @SuppressFBWarnings("SE_TRANSIENT_FIELD_NOT_RESTORED") private final transient File npmExecutable; + @SuppressFBWarnings("SE_TRANSIENT_FIELD_NOT_RESTORED") + public final transient File projectDir; + private final NpmConfig npmConfig; private final String stepName; - protected NpmFormatterStepStateBase(String stepName, NpmConfig npmConfig, File buildDir, File npm) throws IOException { + protected NpmFormatterStepStateBase(String stepName, NpmConfig npmConfig, File projectDir, File buildDir, File npm) throws IOException { this.stepName = requireNonNull(stepName); this.npmConfig = requireNonNull(npmConfig); + this.projectDir = requireNonNull(projectDir); this.npmExecutable = npm; NodeServerLayout layout = prepareNodeServer(buildDir); diff --git a/lib/src/main/java/com/diffplug/spotless/npm/NpmResourceHelper.java b/lib/src/main/java/com/diffplug/spotless/npm/NpmResourceHelper.java index 4f97e7e732..48e974eec6 100644 --- a/lib/src/main/java/com/diffplug/spotless/npm/NpmResourceHelper.java +++ b/lib/src/main/java/com/diffplug/spotless/npm/NpmResourceHelper.java @@ -18,9 +18,12 @@ import java.io.*; import java.nio.charset.StandardCharsets; import java.nio.file.Files; +import java.nio.file.Path; +import java.nio.file.Paths; import java.nio.file.StandardCopyOption; import java.time.Duration; import java.util.Arrays; +import java.util.Objects; import java.util.concurrent.TimeoutException; import java.util.stream.Collectors; @@ -103,10 +106,18 @@ static void awaitReadableFile(File file, Duration maxWaitTime) throws TimeoutExc } static File copyFileToDir(File file, File targetDir) { + return copyFileToDirAtSubpath(file, targetDir, file.getName()); + } + + static File copyFileToDirAtSubpath(File file, File targetDir, String relativePath) { + Objects.requireNonNull(relativePath); try { - File copiedFile = new File(targetDir, file.getName()); - Files.copy(file.toPath(), copiedFile.toPath(), StandardCopyOption.REPLACE_EXISTING); - return copiedFile; + // create file pointing to relativePath in targetDir + final Path relativeTargetFile = Paths.get(targetDir.getAbsolutePath(), relativePath); + assertDirectoryExists(relativeTargetFile.getParent().toFile()); + + Files.copy(file.toPath(), relativeTargetFile, StandardCopyOption.REPLACE_EXISTING); + return relativeTargetFile.toFile(); } catch (IOException e) { throw ThrowingEx.asRuntime(e); } diff --git a/lib/src/main/java/com/diffplug/spotless/npm/PrettierFormatterStep.java b/lib/src/main/java/com/diffplug/spotless/npm/PrettierFormatterStep.java index 5a5662eee4..8489644c36 100644 --- a/lib/src/main/java/com/diffplug/spotless/npm/PrettierFormatterStep.java +++ b/lib/src/main/java/com/diffplug/spotless/npm/PrettierFormatterStep.java @@ -49,12 +49,12 @@ public static final Map defaultDevDependenciesWithPrettier(Strin return Collections.singletonMap("prettier", version); } - public static FormatterStep create(Map devDependencies, Provisioner provisioner, File buildDir, NpmPathResolver npmPathResolver, PrettierConfig prettierConfig) { + public static FormatterStep create(Map devDependencies, Provisioner provisioner, File projectDir, File buildDir, NpmPathResolver npmPathResolver, PrettierConfig prettierConfig) { requireNonNull(devDependencies); requireNonNull(provisioner); requireNonNull(buildDir); return FormatterStep.createLazy(NAME, - () -> new State(NAME, devDependencies, buildDir, npmPathResolver, prettierConfig), + () -> new State(NAME, devDependencies, projectDir, buildDir, npmPathResolver, prettierConfig), State::createFormatterFunc); } @@ -63,7 +63,7 @@ private static class State extends NpmFormatterStepStateBase implements Serializ private static final long serialVersionUID = -539537027004745812L; private final PrettierConfig prettierConfig; - State(String stepName, Map devDependencies, File buildDir, NpmPathResolver npmPathResolver, PrettierConfig prettierConfig) throws IOException { + State(String stepName, Map devDependencies, File projectDir, File buildDir, NpmPathResolver npmPathResolver, PrettierConfig prettierConfig) throws IOException { super(stepName, new NpmConfig( replaceDevDependencies( @@ -74,6 +74,7 @@ private static class State extends NpmFormatterStepStateBase implements Serializ "/com/diffplug/spotless/npm/common-serve.js", "/com/diffplug/spotless/npm/prettier-serve.js"), npmPathResolver.resolveNpmrcContent()), + projectDir, buildDir, npmPathResolver.resolveNpmExecutable()); this.prettierConfig = requireNonNull(prettierConfig); diff --git a/lib/src/main/java/com/diffplug/spotless/npm/TsFmtFormatterStep.java b/lib/src/main/java/com/diffplug/spotless/npm/TsFmtFormatterStep.java index e9c098d709..027af89e23 100644 --- a/lib/src/main/java/com/diffplug/spotless/npm/TsFmtFormatterStep.java +++ b/lib/src/main/java/com/diffplug/spotless/npm/TsFmtFormatterStep.java @@ -40,11 +40,11 @@ public class TsFmtFormatterStep { public static final String NAME = "tsfmt-format"; - public static FormatterStep create(Map versions, Provisioner provisioner, File buildDir, NpmPathResolver npmPathResolver, @Nullable TypedTsFmtConfigFile configFile, @Nullable Map inlineTsFmtSettings) { + public static FormatterStep create(Map versions, Provisioner provisioner, File projectDir, File buildDir, NpmPathResolver npmPathResolver, @Nullable TypedTsFmtConfigFile configFile, @Nullable Map inlineTsFmtSettings) { requireNonNull(provisioner); requireNonNull(buildDir); return FormatterStep.createLazy(NAME, - () -> new State(NAME, versions, buildDir, npmPathResolver, configFile, inlineTsFmtSettings), + () -> new State(NAME, versions, projectDir, buildDir, npmPathResolver, configFile, inlineTsFmtSettings), State::createFormatterFunc); } @@ -71,7 +71,7 @@ public static class State extends NpmFormatterStepStateBase implements Serializa @Nullable private final TypedTsFmtConfigFile configFile; - public State(String stepName, Map versions, File buildDir, NpmPathResolver npmPathResolver, @Nullable TypedTsFmtConfigFile configFile, @Nullable Map inlineTsFmtSettings) throws IOException { + public State(String stepName, Map versions, File projectDir, File buildDir, NpmPathResolver npmPathResolver, @Nullable TypedTsFmtConfigFile configFile, @Nullable Map inlineTsFmtSettings) throws IOException { super(stepName, new NpmConfig( replaceDevDependencies(NpmResourceHelper.readUtf8StringFromClasspath(TsFmtFormatterStep.class, "/com/diffplug/spotless/npm/tsfmt-package.json"), new TreeMap<>(versions)), @@ -80,6 +80,7 @@ public State(String stepName, Map versions, File buildDir, NpmPa "/com/diffplug/spotless/npm/common-serve.js", "/com/diffplug/spotless/npm/tsfmt-serve.js"), npmPathResolver.resolveNpmrcContent()), + projectDir, buildDir, npmPathResolver.resolveNpmExecutable()); this.buildDir = requireNonNull(buildDir); diff --git a/lib/src/main/resources/com/diffplug/spotless/npm/eslint-serve.js b/lib/src/main/resources/com/diffplug/spotless/npm/eslint-serve.js index 8c56b8ef08..15018e6cb0 100644 --- a/lib/src/main/resources/com/diffplug/spotless/npm/eslint-serve.js +++ b/lib/src/main/resources/com/diffplug/spotless/npm/eslint-serve.js @@ -24,8 +24,22 @@ app.post("/eslint/format", async (req, res) => { fix: true, useEslintrc: false, // would result in (gradle) cache issues resolvePluginsRelativeTo: format_data.node_modules_dir + // baseConfig: { + // parserOptions: { + // tsconfigRootDir: '../../', + // } + // } }; + if (format_data.ts_config_root_dir) { + ESLintOptions.baseConfig = { + parserOptions: { + tsconfigRootDir: format_data.ts_config_root_dir + } + }; + // res.status(501).send("Resolved ts config root dir: " + format_data.ts_config_root_dir); + } + if (ESLintOverrideConfigFile) { ESLintOptions.overrideConfigFile = ESLintOverrideConfigFile; 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 99e21bd8c8..3f433afa92 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 @@ -27,8 +27,10 @@ import java.util.LinkedHashMap; import java.util.List; import java.util.Map; +import java.util.Optional; import java.util.Random; import java.util.TreeMap; +import java.util.stream.Collectors; import javax.annotation.Nullable; import javax.inject.Inject; @@ -583,6 +585,7 @@ FormatterStep createStep() { return PrettierFormatterStep.create( devDependencies, provisioner(), + project.getProjectDir(), project.getBuildDir(), new NpmPathResolver(npmFileOrNull(), npmrcFileOrNull(), project.getProjectDir(), project.getRootDir()), new com.diffplug.spotless.npm.PrettierConfig( @@ -618,6 +621,8 @@ public class EslintFormatExtension extends NpmStepConfig @Nullable String configJs = null; + List additionalConfigs = new ArrayList<>(); + public EslintFormatExtension(Map devDependencies) { this.devDependencies.putAll(requireNonNull(devDependencies)); } @@ -640,19 +645,44 @@ public EslintFormatExtension configFile(Object configFilePath) { return this; } + protected void additionalConfigFilePath(Object sourceFile, String relativeTargetPath) { + this.additionalConfigs.add(new AdditionalEslintConfig(sourceFile, relativeTargetPath)); + } + public FormatterStep createStep() { final Project project = getProject(); return EslintFormatterStep.create( devDependencies, provisioner(), + project.getProjectDir(), project.getBuildDir(), new NpmPathResolver(npmFileOrNull(), npmrcFileOrNull(), project.getProjectDir(), project.getRootDir()), eslintConfig()); } private EslintConfig eslintConfig() { - return new EslintConfig(configFilePath != null ? getProject().file(configFilePath) : null, configJs); + return new EslintConfig(configFilePath != null ? getProject().file(configFilePath) : null, configJs, additionalConfigs()); + } + + private Map> additionalConfigs() { + // convert additionalConfigs to a map explicitly allowing null values + + return additionalConfigs.stream() + .collect(Collectors.toMap( + config -> getProject().file(config.configFilePath), + config -> Optional.ofNullable(config.relativeTargetPath))); + } + } + + private static class AdditionalEslintConfig { + final Object configFilePath; + + final String relativeTargetPath; + + AdditionalEslintConfig(Object configFilePath, String relativeTargetPath) { + this.configFilePath = configFilePath; + this.relativeTargetPath = relativeTargetPath; } } diff --git a/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/TypescriptExtension.java b/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/TypescriptExtension.java index e80730d5ed..b126cc76c6 100644 --- a/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/TypescriptExtension.java +++ b/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/TypescriptExtension.java @@ -113,6 +113,7 @@ public FormatterStep createStep() { return TsFmtFormatterStep.create( devDependencies, provisioner(), + project.getProjectDir(), project.getBuildDir(), new NpmPathResolver(npmFileOrNull(), npmrcFileOrNull(), project.getProjectDir(), project.getRootDir()), typedConfigFile(), @@ -221,6 +222,16 @@ public TypescriptEslintFormatExtension styleGuide(String styleGuide) { replaceStep(createStep()); return this; } + + public TypescriptEslintFormatExtension tsconfigFile(Object path) { + return tsconfigFile(path, null); + } + + public TypescriptEslintFormatExtension tsconfigFile(Object path, String remapping) { + additionalConfigFilePath(path, remapping); + replaceStep(createStep()); + return this; + } } @Override diff --git a/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/TypescriptExtensionTest.java b/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/TypescriptExtensionTest.java index 40da7e3536..e7086e0c91 100644 --- a/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/TypescriptExtensionTest.java +++ b/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/TypescriptExtensionTest.java @@ -144,7 +144,7 @@ void usePrettier() throws IOException { @Test void useEslint() throws IOException { - setFile(".eslintrc.js").toResource("npm/eslint/filetypes/typescript/.eslintrc.js"); + setFile(".eslintrc.js").toResource("npm/eslint/typescript/custom_rules/.eslintrc.js"); setFile("build.gradle").toLines( "plugins {", " id 'com.diffplug.spotless'", @@ -156,8 +156,28 @@ void useEslint() throws IOException { " eslint().configFile('.eslintrc.js')", " }", "}"); - setFile("test.ts").toResource("npm/eslint/filetypes/typescript/typescript.dirty"); + setFile("test.ts").toResource("npm/eslint/typescript/custom_rules/typescript.dirty"); gradleRunner().withArguments("--stacktrace", "spotlessApply").build(); - assertFile("test.ts").sameAsResource("npm/eslint/filetypes/typescript/typescript.clean"); + assertFile("test.ts").sameAsResource("npm/eslint/typescript/custom_rules/typescript.clean"); + } + + @Test + void useXoStandardRules() throws IOException { + setFile(".eslintrc.js").toResource("npm/eslint/typescript/standard_rules_xo/.eslintrc.js"); + setFile("tsconfig.json").toResource("npm/eslint/typescript/standard_rules_xo/tsconfig.json"); // needs to be copied to! + setFile("build.gradle").toLines( + "plugins {", + " id 'com.diffplug.spotless'", + "}", + "repositories { mavenCentral() }", + "spotless {", + " typescript {", + " target 'test.ts'", + " eslint().styleGuide('xo-typescript').configFile('.eslintrc.js')//.tsconfigFile('tsconfig.json')", // TODO TODO maybe can skip the additional config files alltogether, instead provide tsConfigRootDir to eslint-serve.js via call + " }", + "}"); + setFile("test.ts").toResource("npm/eslint/typescript/standard_rules_xo/typescript.dirty"); + gradleRunner().withArguments("--stacktrace", "spotlessApply").build(); + assertFile("test.ts").sameAsResource("npm/eslint/typescript/standard_rules_xo/typescript.clean"); } } diff --git a/testlib/src/main/resources/npm/eslint/filetypes/typescript/.eslintrc.js b/testlib/src/main/resources/npm/eslint/typescript/custom_rules/.eslintrc.js similarity index 100% rename from testlib/src/main/resources/npm/eslint/filetypes/typescript/.eslintrc.js rename to testlib/src/main/resources/npm/eslint/typescript/custom_rules/.eslintrc.js diff --git a/testlib/src/main/resources/npm/eslint/filetypes/typescript/typescript.clean b/testlib/src/main/resources/npm/eslint/typescript/custom_rules/typescript.clean similarity index 100% rename from testlib/src/main/resources/npm/eslint/filetypes/typescript/typescript.clean rename to testlib/src/main/resources/npm/eslint/typescript/custom_rules/typescript.clean diff --git a/testlib/src/main/resources/npm/eslint/filetypes/typescript/typescript.dirty b/testlib/src/main/resources/npm/eslint/typescript/custom_rules/typescript.dirty similarity index 100% rename from testlib/src/main/resources/npm/eslint/filetypes/typescript/typescript.dirty rename to testlib/src/main/resources/npm/eslint/typescript/custom_rules/typescript.dirty diff --git a/testlib/src/main/resources/npm/eslint/typescript/standard_rules_xo/.eslintrc.js b/testlib/src/main/resources/npm/eslint/typescript/standard_rules_xo/.eslintrc.js new file mode 100644 index 0000000000..e1ca03f732 --- /dev/null +++ b/testlib/src/main/resources/npm/eslint/typescript/standard_rules_xo/.eslintrc.js @@ -0,0 +1,26 @@ +module.exports = { + env: { + browser: true, + es2021: true, + }, + extends: 'xo/browser', + overrides: [ + { + extends: [ + 'xo-typescript', + ], + files: [ + '*.ts', + '*.tsx', + ], + }, + ], + parser: "@typescript-eslint/parser", + parserOptions: { + ecmaVersion: 'latest', + sourceType: 'module', + project: './tsconfig.json', + }, + rules: { + }, +}; diff --git a/testlib/src/main/resources/npm/eslint/typescript/standard_rules_xo/tsconfig.json b/testlib/src/main/resources/npm/eslint/typescript/standard_rules_xo/tsconfig.json new file mode 100644 index 0000000000..629f834eb5 --- /dev/null +++ b/testlib/src/main/resources/npm/eslint/typescript/standard_rules_xo/tsconfig.json @@ -0,0 +1,18 @@ +{ + "compileOnSave": true, + "compilerOptions": { + "module": "ES6", + "noImplicitAny": true, + "outDir": "build/ide/", + "sourceMap": true, + "skipLibCheck": true, + "target": "ES6", + "baseUrl": "./", + "paths": { + }, + "lib": ["es7", "dom", "es2017"] + }, + "include": [ + "**/*" + ] +} diff --git a/testlib/src/main/resources/npm/eslint/typescript/standard_rules_xo/typescript.clean b/testlib/src/main/resources/npm/eslint/typescript/standard_rules_xo/typescript.clean new file mode 100644 index 0000000000..5c43d7a746 --- /dev/null +++ b/testlib/src/main/resources/npm/eslint/typescript/standard_rules_xo/typescript.clean @@ -0,0 +1,9 @@ +export class MyController extends AbstractController implements DisposeAware, CallbackAware { + public myValue: string[]; + + constructor(private readonly myService: Service, name: string, private readonly field: any) { + super(name); + } + + // ... +} diff --git a/testlib/src/main/resources/npm/eslint/typescript/standard_rules_xo/typescript.dirty b/testlib/src/main/resources/npm/eslint/typescript/standard_rules_xo/typescript.dirty new file mode 100644 index 0000000000..a8f7447af1 --- /dev/null +++ b/testlib/src/main/resources/npm/eslint/typescript/standard_rules_xo/typescript.dirty @@ -0,0 +1,10 @@ +export class MyController extends AbstractController implements DisposeAware, CallbackAware { + +public myValue:string[]; + +constructor(private myService:Service,name:string,private field:any){ super(name) ;} + + +//... + +} From 96339675402e79f0737f70733b2224cba4345c2e Mon Sep 17 00:00:00 2001 From: Simon Gamma Date: Fri, 9 Dec 2022 21:10:40 +0100 Subject: [PATCH 421/757] eslint: add support for standard-with-typescript ruleset --- .../com/diffplug/spotless/npm/eslint-serve.js | 71 +++++++++---------- .../spotless/TypescriptExtensionTest.java | 24 ++++++- .../.eslintrc.js | 16 +++++ .../tsconfig.json | 18 +++++ .../typescript.clean | 7 ++ .../typescript.dirty | 10 +++ 6 files changed, 105 insertions(+), 41 deletions(-) create mode 100644 testlib/src/main/resources/npm/eslint/typescript/standard_rules_standard_with_typescript/.eslintrc.js create mode 100644 testlib/src/main/resources/npm/eslint/typescript/standard_rules_standard_with_typescript/tsconfig.json create mode 100644 testlib/src/main/resources/npm/eslint/typescript/standard_rules_standard_with_typescript/typescript.clean create mode 100644 testlib/src/main/resources/npm/eslint/typescript/standard_rules_standard_with_typescript/typescript.dirty diff --git a/lib/src/main/resources/com/diffplug/spotless/npm/eslint-serve.js b/lib/src/main/resources/com/diffplug/spotless/npm/eslint-serve.js index 15018e6cb0..2804eb86dd 100644 --- a/lib/src/main/resources/com/diffplug/spotless/npm/eslint-serve.js +++ b/lib/src/main/resources/com/diffplug/spotless/npm/eslint-serve.js @@ -1,57 +1,50 @@ const {ESLint} = require("eslint"); app.post("/eslint/format", async (req, res) => { + try { + const format_data = req.body; - const format_data = req.body; - - const ESLintOverrideConfig = format_data.eslint_override_config; + const ESLintOverrideConfig = format_data.eslint_override_config; - const ESLintOverrideConfigFile = format_data.eslint_override_config_file; + const ESLintOverrideConfigFile = format_data.eslint_override_config_file; - if (!ESLintOverrideConfig && !ESLintOverrideConfigFile) { - res.status(501).send("Error while formatting: No config provided"); - return; - } - - const filePath = format_data.file_path; + if (!ESLintOverrideConfig && !ESLintOverrideConfigFile) { + res.status(501).send("Error while formatting: No config provided"); + return; + } - if (!filePath) { - res.status(501).send("Error while formatting: No file path provided"); - return; - } + const filePath = format_data.file_path; - const ESLintOptions = { - fix: true, - useEslintrc: false, // would result in (gradle) cache issues - resolvePluginsRelativeTo: format_data.node_modules_dir - // baseConfig: { - // parserOptions: { - // tsconfigRootDir: '../../', - // } - // } - }; + if (!filePath) { + res.status(501).send("Error while formatting: No file path provided"); + return; + } - if (format_data.ts_config_root_dir) { - ESLintOptions.baseConfig = { - parserOptions: { - tsconfigRootDir: format_data.ts_config_root_dir - } + const ESLintOptions = { + fix: true, + useEslintrc: false, // would result in (gradle) cache issues + resolvePluginsRelativeTo: format_data.node_modules_dir }; - // res.status(501).send("Resolved ts config root dir: " + format_data.ts_config_root_dir); - } + if (format_data.ts_config_root_dir) { + ESLintOptions.baseConfig = { + parserOptions: { + tsconfigRootDir: format_data.ts_config_root_dir + } + }; + } - if (ESLintOverrideConfigFile) { - ESLintOptions.overrideConfigFile = ESLintOverrideConfigFile; - } - if (ESLintOverrideConfig) { - ESLintOptions.overrideConfig = ESLintOverrideConfig; - } - const eslint = new ESLint(ESLintOptions); + if (ESLintOverrideConfigFile) { + ESLintOptions.overrideConfigFile = ESLintOverrideConfigFile; + } + if (ESLintOverrideConfig) { + ESLintOptions.overrideConfig = ESLintOverrideConfig; + } + + const eslint = new ESLint(ESLintOptions); - try { console.log("using options: " + JSON.stringify(ESLintOptions)); console.log("format input", format_data.file_content); const lintTextOptions = { diff --git a/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/TypescriptExtensionTest.java b/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/TypescriptExtensionTest.java index e7086e0c91..0c3d10c89f 100644 --- a/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/TypescriptExtensionTest.java +++ b/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/TypescriptExtensionTest.java @@ -164,7 +164,7 @@ void useEslint() throws IOException { @Test void useXoStandardRules() throws IOException { setFile(".eslintrc.js").toResource("npm/eslint/typescript/standard_rules_xo/.eslintrc.js"); - setFile("tsconfig.json").toResource("npm/eslint/typescript/standard_rules_xo/tsconfig.json"); // needs to be copied to! + setFile("tsconfig.json").toResource("npm/eslint/typescript/standard_rules_xo/tsconfig.json"); setFile("build.gradle").toLines( "plugins {", " id 'com.diffplug.spotless'", @@ -173,11 +173,31 @@ void useXoStandardRules() throws IOException { "spotless {", " typescript {", " target 'test.ts'", - " eslint().styleGuide('xo-typescript').configFile('.eslintrc.js')//.tsconfigFile('tsconfig.json')", // TODO TODO maybe can skip the additional config files alltogether, instead provide tsConfigRootDir to eslint-serve.js via call + " eslint().styleGuide('xo-typescript').configFile('.eslintrc.js')", " }", "}"); setFile("test.ts").toResource("npm/eslint/typescript/standard_rules_xo/typescript.dirty"); gradleRunner().withArguments("--stacktrace", "spotlessApply").build(); assertFile("test.ts").sameAsResource("npm/eslint/typescript/standard_rules_xo/typescript.clean"); } + + @Test + void useStandardWithTypescriptRules() throws IOException { + setFile(".eslintrc.js").toResource("npm/eslint/typescript/standard_rules_standard_with_typescript/.eslintrc.js"); + setFile("tsconfig.json").toResource("npm/eslint/typescript/standard_rules_standard_with_typescript/tsconfig.json"); + setFile("build.gradle").toLines( + "plugins {", + " id 'com.diffplug.spotless'", + "}", + "repositories { mavenCentral() }", + "spotless {", + " typescript {", + " target 'test.ts'", + " eslint().styleGuide('standard-with-typescript').configFile('.eslintrc.js')", + " }", + "}"); + setFile("test.ts").toResource("npm/eslint/typescript/standard_rules_standard_with_typescript/typescript.dirty"); + gradleRunner().withArguments("--stacktrace", "spotlessApply").build(); + assertFile("test.ts").sameAsResource("npm/eslint/typescript/standard_rules_standard_with_typescript/typescript.clean"); + } } diff --git a/testlib/src/main/resources/npm/eslint/typescript/standard_rules_standard_with_typescript/.eslintrc.js b/testlib/src/main/resources/npm/eslint/typescript/standard_rules_standard_with_typescript/.eslintrc.js new file mode 100644 index 0000000000..0a86d5db86 --- /dev/null +++ b/testlib/src/main/resources/npm/eslint/typescript/standard_rules_standard_with_typescript/.eslintrc.js @@ -0,0 +1,16 @@ +module.exports = { + env: { + browser: true, + es2021: true + }, + extends: 'standard-with-typescript', + overrides: [ + ], + parserOptions: { + ecmaVersion: 'latest', + sourceType: 'module', + project: './tsconfig.json', + }, + rules: { + } +} diff --git a/testlib/src/main/resources/npm/eslint/typescript/standard_rules_standard_with_typescript/tsconfig.json b/testlib/src/main/resources/npm/eslint/typescript/standard_rules_standard_with_typescript/tsconfig.json new file mode 100644 index 0000000000..629f834eb5 --- /dev/null +++ b/testlib/src/main/resources/npm/eslint/typescript/standard_rules_standard_with_typescript/tsconfig.json @@ -0,0 +1,18 @@ +{ + "compileOnSave": true, + "compilerOptions": { + "module": "ES6", + "noImplicitAny": true, + "outDir": "build/ide/", + "sourceMap": true, + "skipLibCheck": true, + "target": "ES6", + "baseUrl": "./", + "paths": { + }, + "lib": ["es7", "dom", "es2017"] + }, + "include": [ + "**/*" + ] +} diff --git a/testlib/src/main/resources/npm/eslint/typescript/standard_rules_standard_with_typescript/typescript.clean b/testlib/src/main/resources/npm/eslint/typescript/standard_rules_standard_with_typescript/typescript.clean new file mode 100644 index 0000000000..cbe609b1bb --- /dev/null +++ b/testlib/src/main/resources/npm/eslint/typescript/standard_rules_standard_with_typescript/typescript.clean @@ -0,0 +1,7 @@ +export class MyController extends AbstractController implements DisposeAware, CallbackAware { + public myValue: string[] + + constructor (private readonly myService: Service, name: string, private readonly field: any) { super(name) } + + // ... +} diff --git a/testlib/src/main/resources/npm/eslint/typescript/standard_rules_standard_with_typescript/typescript.dirty b/testlib/src/main/resources/npm/eslint/typescript/standard_rules_standard_with_typescript/typescript.dirty new file mode 100644 index 0000000000..a8f7447af1 --- /dev/null +++ b/testlib/src/main/resources/npm/eslint/typescript/standard_rules_standard_with_typescript/typescript.dirty @@ -0,0 +1,10 @@ +export class MyController extends AbstractController implements DisposeAware, CallbackAware { + +public myValue:string[]; + +constructor(private myService:Service,name:string,private field:any){ super(name) ;} + + +//... + +} From 7022b7fa3b9337474951defff106746c280f4a58 Mon Sep 17 00:00:00 2001 From: Simon Gamma Date: Thu, 15 Dec 2022 19:53:59 +0100 Subject: [PATCH 422/757] eslint: add unit tests, cleanup code --- .../diffplug/spotless/npm/EslintConfig.java | 23 +- .../spotless/npm/EslintFormatterStep.java | 21 +- .../spotless/npm/EslintTypescriptConfig.java | 41 ++++ .../gradle/spotless/FormatExtension.java | 30 +-- .../gradle/spotless/TypescriptExtension.java | 19 +- .../diffplug/spotless/ResourceHarness.java | 18 +- .../spotless/npm/EslintFormatterStepTest.java | 210 ++++++++++++++++++ .../npm/NpmFormatterStepCommonTests.java | 9 + .../npm/PrettierFormatterStepTest.java | 5 + .../spotless/npm/TsFmtFormatterStepTest.java | 2 + 10 files changed, 309 insertions(+), 69 deletions(-) create mode 100644 lib/src/main/java/com/diffplug/spotless/npm/EslintTypescriptConfig.java create mode 100644 testlib/src/test/java/com/diffplug/spotless/npm/EslintFormatterStepTest.java diff --git a/lib/src/main/java/com/diffplug/spotless/npm/EslintConfig.java b/lib/src/main/java/com/diffplug/spotless/npm/EslintConfig.java index 83f5ab1a73..732111cc71 100644 --- a/lib/src/main/java/com/diffplug/spotless/npm/EslintConfig.java +++ b/lib/src/main/java/com/diffplug/spotless/npm/EslintConfig.java @@ -18,12 +18,7 @@ import java.io.File; import java.io.IOException; import java.io.Serializable; -import java.util.Collections; -import java.util.Map; -import java.util.Optional; -import java.util.TreeMap; -import javax.annotation.Nonnull; import javax.annotation.Nullable; import com.diffplug.spotless.FileSignature; @@ -44,23 +39,20 @@ public class EslintConfig implements Serializable { private final String eslintConfigJs; - @SuppressFBWarnings("SE_TRANSIENT_FIELD_NOT_RESTORED") - private final transient Map> additionalConfigFiles; // key: source-file, value: target-remapping path relative to package.json (if needed) - - private final FileSignature additionalConfigFilesSignature; - - public EslintConfig(@Nullable File eslintConfigPath, @Nullable String eslintConfigJs, Map> additionalConfigFiles) { + public EslintConfig(@Nullable File eslintConfigPath, @Nullable String eslintConfigJs) { try { this.eslintConfigPath = eslintConfigPath; this.eslintConfigPathSignature = eslintConfigPath != null ? FileSignature.signAsList(this.eslintConfigPath) : FileSignature.signAsList(); this.eslintConfigJs = eslintConfigJs; - this.additionalConfigFiles = additionalConfigFiles != null ? new TreeMap<>(additionalConfigFiles) : Collections.emptyMap(); - this.additionalConfigFilesSignature = FileSignature.signAsList(this.additionalConfigFiles.keySet().toArray(new File[0])); } catch (IOException e) { throw ThrowingEx.asRuntime(e); } } + public EslintConfig withEslintConfigPath(@Nullable File eslintConfigPath) { + return new EslintConfig(eslintConfigPath, this.eslintConfigJs); + } + @Nullable public File getEslintConfigPath() { return eslintConfigPath; @@ -70,9 +62,4 @@ public File getEslintConfigPath() { public String getEslintConfigJs() { return eslintConfigJs; } - - @Nonnull - public Map> getAdditionalConfigFiles() { - return additionalConfigFiles; - } } diff --git a/lib/src/main/java/com/diffplug/spotless/npm/EslintFormatterStep.java b/lib/src/main/java/com/diffplug/spotless/npm/EslintFormatterStep.java index 492cf0da90..49bde50945 100644 --- a/lib/src/main/java/com/diffplug/spotless/npm/EslintFormatterStep.java +++ b/lib/src/main/java/com/diffplug/spotless/npm/EslintFormatterStep.java @@ -25,7 +25,6 @@ import java.util.LinkedHashMap; import java.util.Map; import java.util.Objects; -import java.util.Optional; import java.util.TreeMap; import javax.annotation.Nonnull; @@ -152,17 +151,7 @@ private EslintConfig localCopyFiles(EslintConfig orig) { // eslint configs contain relative paths to additional config files (such as tsconfig.json e.g.) FormattedPrinter.SYSOUT.print("Copying config file <%s> to <%s> and using the copy", orig.getEslintConfigPath(), nodeModulesDir); File configFileCopy = NpmResourceHelper.copyFileToDir(orig.getEslintConfigPath(), nodeModulesDir); - - for (Map.Entry> additionalConfigFile : orig.getAdditionalConfigFiles().entrySet()) { - FormattedPrinter.SYSOUT.print("Copying additional config file <%s> to <%s> at subpath <%s> and using the copy", additionalConfigFile.getKey(), nodeModulesDir, additionalConfigFile.getValue()); - - if (additionalConfigFile.getValue().isPresent()) { - NpmResourceHelper.copyFileToDirAtSubpath(additionalConfigFile.getKey(), nodeModulesDir, additionalConfigFile.getValue().get()); - } else { - NpmResourceHelper.copyFileToDir(additionalConfigFile.getKey(), nodeModulesDir); - } - } - return new EslintConfig(configFileCopy, orig.getEslintConfigJs(), orig.getAdditionalConfigFiles()); + return orig.withEslintConfigPath(configFileCopy); } @Override @@ -226,8 +215,12 @@ private void setConfigToCallOptions(Map eslintCallOptions) } eslintCallOptions.put(FormatOption.NODE_MODULES_DIR, nodeModulesDir.getAbsolutePath()); - // TODO (simschla, 09.12.22): maybe only add this if there is a typescript config active? (TBD: how to detect) - eslintCallOptions.put(FormatOption.TS_CONFIG_ROOT_DIR, nodeModulesDir.toPath().relativize(projectDir.toPath()).toString()); + if (eslintConfig instanceof EslintTypescriptConfig) { + // if we are a ts config, see if we need to use specific paths or use default projectDir + File tsConfigFilePath = ((EslintTypescriptConfig) eslintConfig).getTypescriptConfigPath(); + File tsConfigRootDir = tsConfigFilePath != null ? tsConfigFilePath.getParentFile() : projectDir; + eslintCallOptions.put(FormatOption.TS_CONFIG_ROOT_DIR, nodeModulesDir.getAbsoluteFile().toPath().relativize(tsConfigRootDir.getAbsoluteFile().toPath()).toString()); + } } } } diff --git a/lib/src/main/java/com/diffplug/spotless/npm/EslintTypescriptConfig.java b/lib/src/main/java/com/diffplug/spotless/npm/EslintTypescriptConfig.java new file mode 100644 index 0000000000..05c8209837 --- /dev/null +++ b/lib/src/main/java/com/diffplug/spotless/npm/EslintTypescriptConfig.java @@ -0,0 +1,41 @@ +package com.diffplug.spotless.npm; + +import com.diffplug.spotless.FileSignature; +import com.diffplug.spotless.ThrowingEx; + +import edu.umd.cs.findbugs.annotations.SuppressFBWarnings; + +import javax.annotation.Nullable; + +import java.io.File; +import java.io.IOException; + +public class EslintTypescriptConfig extends EslintConfig { + + @SuppressFBWarnings("SE_TRANSIENT_FIELD_NOT_RESTORED") + @Nullable + private final transient File typescriptConfigPath; + + @SuppressWarnings("unused") + private final FileSignature typescriptConfigPathSignature; + + public EslintTypescriptConfig(@Nullable File eslintConfigPath, @Nullable String eslintConfigJs, @Nullable File typescriptConfigPath) { + super(eslintConfigPath, eslintConfigJs); + try { + this.typescriptConfigPath = typescriptConfigPath; + this.typescriptConfigPathSignature = typescriptConfigPath != null ? FileSignature.signAsList(this.typescriptConfigPath) : FileSignature.signAsList(); + } catch (IOException e) { + throw ThrowingEx.asRuntime(e); + } + } + + @Override + public EslintConfig withEslintConfigPath(@Nullable File eslintConfigPath) { + return new EslintTypescriptConfig(eslintConfigPath, this.getEslintConfigJs(), this.typescriptConfigPath); + } + + @Nullable + public File getTypescriptConfigPath() { + return typescriptConfigPath; + } +} 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 3f433afa92..6152f9009d 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 @@ -621,8 +621,6 @@ public class EslintFormatExtension extends NpmStepConfig @Nullable String configJs = null; - List additionalConfigs = new ArrayList<>(); - public EslintFormatExtension(Map devDependencies) { this.devDependencies.putAll(requireNonNull(devDependencies)); } @@ -645,10 +643,6 @@ public EslintFormatExtension configFile(Object configFilePath) { return this; } - protected void additionalConfigFilePath(Object sourceFile, String relativeTargetPath) { - this.additionalConfigs.add(new AdditionalEslintConfig(sourceFile, relativeTargetPath)); - } - public FormatterStep createStep() { final Project project = getProject(); @@ -661,28 +655,8 @@ public FormatterStep createStep() { eslintConfig()); } - private EslintConfig eslintConfig() { - return new EslintConfig(configFilePath != null ? getProject().file(configFilePath) : null, configJs, additionalConfigs()); - } - - private Map> additionalConfigs() { - // convert additionalConfigs to a map explicitly allowing null values - - return additionalConfigs.stream() - .collect(Collectors.toMap( - config -> getProject().file(config.configFilePath), - config -> Optional.ofNullable(config.relativeTargetPath))); - } - } - - private static class AdditionalEslintConfig { - final Object configFilePath; - - final String relativeTargetPath; - - AdditionalEslintConfig(Object configFilePath, String relativeTargetPath) { - this.configFilePath = configFilePath; - this.relativeTargetPath = relativeTargetPath; + protected EslintConfig eslintConfig() { + return new EslintConfig(configFilePath != null ? getProject().file(configFilePath) : null, configJs); } } diff --git a/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/TypescriptExtension.java b/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/TypescriptExtension.java index b126cc76c6..d4dedc32eb 100644 --- a/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/TypescriptExtension.java +++ b/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/TypescriptExtension.java @@ -27,6 +27,10 @@ import javax.annotation.Nullable; import javax.inject.Inject; +import com.diffplug.spotless.npm.EslintConfig; + +import com.diffplug.spotless.npm.EslintTypescriptConfig; + import org.gradle.api.Project; import com.diffplug.spotless.FormatterStep; @@ -193,6 +197,9 @@ public TypescriptEslintFormatExtension eslint(Map devDependencie public class TypescriptEslintFormatExtension extends EslintFormatExtension { + @Nullable + Object typescriptConfigFilePath = null; + public TypescriptEslintFormatExtension(Map devDependencies) { super(devDependencies); } @@ -224,14 +231,16 @@ public TypescriptEslintFormatExtension styleGuide(String styleGuide) { } public TypescriptEslintFormatExtension tsconfigFile(Object path) { - return tsconfigFile(path, null); - } - - public TypescriptEslintFormatExtension tsconfigFile(Object path, String remapping) { - additionalConfigFilePath(path, remapping); + this.typescriptConfigFilePath = requireNonNull(path); replaceStep(createStep()); return this; } + + @Override + protected EslintConfig eslintConfig() { + EslintConfig config = super.eslintConfig(); + return new EslintTypescriptConfig(config.getEslintConfigPath(), config.getEslintConfigJs(), typescriptConfigFilePath != null ? getProject().file(typescriptConfigFilePath) : null); + } } @Override diff --git a/testlib/src/main/java/com/diffplug/spotless/ResourceHarness.java b/testlib/src/main/java/com/diffplug/spotless/ResourceHarness.java index d4a79fe417..0304889e1f 100644 --- a/testlib/src/main/java/com/diffplug/spotless/ResourceHarness.java +++ b/testlib/src/main/java/com/diffplug/spotless/ResourceHarness.java @@ -27,6 +27,7 @@ import java.util.ArrayList; import java.util.Arrays; import java.util.List; +import java.util.Optional; import java.util.function.Consumer; import java.util.function.UnaryOperator; @@ -86,11 +87,20 @@ protected void replace(String path, String toReplace, String replaceWith) throws /** Returns the contents of the given file from the src/test/resources directory. */ protected static String getTestResource(String filename) { - URL url = ResourceHarness.class.getResource("/" + filename); - if (url == null) { - throw new IllegalArgumentException("No such resource " + filename); + Optional resourceUrl = getTestResourceUrl(filename); + if (resourceUrl.isPresent()) { + return ThrowingEx.get(() -> LineEnding.toUnix(Resources.toString(resourceUrl.get(), StandardCharsets.UTF_8))); } - return ThrowingEx.get(() -> LineEnding.toUnix(Resources.toString(url, StandardCharsets.UTF_8))); + throw new IllegalArgumentException("No such resource " + filename); + } + + protected static boolean existsTestResource(String filename) { + return getTestResourceUrl(filename).isPresent(); + } + + private static Optional getTestResourceUrl(String filename) { + URL url = ResourceHarness.class.getResource("/" + filename); + return Optional.ofNullable(url); } /** Returns Files (in a temporary folder) which has the contents of the given file from the src/test/resources directory. */ diff --git a/testlib/src/test/java/com/diffplug/spotless/npm/EslintFormatterStepTest.java b/testlib/src/test/java/com/diffplug/spotless/npm/EslintFormatterStepTest.java new file mode 100644 index 0000000000..afe463c1aa --- /dev/null +++ b/testlib/src/test/java/com/diffplug/spotless/npm/EslintFormatterStepTest.java @@ -0,0 +1,210 @@ +/* + * Copyright 2016-2021 DiffPlug + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.diffplug.spotless.npm; + +import com.diffplug.common.collect.ImmutableMap; +import com.diffplug.spotless.FormatterStep; +import com.diffplug.spotless.StepHarness; +import com.diffplug.spotless.StepHarnessWithFile; +import com.diffplug.spotless.TestProvisioner; +import com.diffplug.spotless.tag.NpmTest; + +import org.junit.jupiter.api.Nested; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.ValueSource; + +import java.io.File; +import java.util.Map; +import java.util.TreeMap; + +@NpmTest +class EslintFormatterStepTest { + + @NpmTest + @Nested + class EslintTypescriptFormattingStepTest extends NpmFormatterStepCommonTests { + + private final Map> devDependenciesForRuleset = ImmutableMap.of( + "custom_rules", EslintFormatterStep.defaultDevDependenciesForTypescript(), + "standard_rules_standard_with_typescript", combine(EslintFormatterStep.defaultDevDependenciesForTypescript(), EslintFormatterStep.PopularStyleGuide.STANDARD_WITH_TYPESCRIPT.devDependencies()), + "standard_rules_xo", combine(EslintFormatterStep.defaultDevDependenciesForTypescript(), EslintFormatterStep.PopularStyleGuide.XO_TYPESCRIPT.devDependencies()) + ); + + private final Map combine(Map m1, Map m2) { + Map combined = new TreeMap<>(m1); + combined.putAll(m2); + return combined; + } + + @ParameterizedTest(name = "{index}: eslint can be applied using ruleset {0}") + @ValueSource(strings = {"custom_rules", "standard_rules_standard_with_typescript", "standard_rules_xo"}) + void formattingUsingRulesetsFile(String ruleSetName) throws Exception { + String filedir = "npm/eslint/typescript/" + ruleSetName + "/"; + + String testDir = "formatting_ruleset_" + ruleSetName + "/"; +// File testDirFile = newFolder(testDir); + + final File eslintRc = createTestFile(filedir + ".eslintrc.js"); +// final File eslintRc = setFile(buildDir().getPath() + "/.eslintrc.js").toResource(filedir + ".eslintrc.js"); + + //setFile(testDir + "/test.ts").toResource(filedir + "typescript.dirty"); + File tsconfigFile = null; + if (existsTestResource(filedir + "tsconfig.json")) { + tsconfigFile = setFile(testDir + "tsconfig.json").toResource(filedir + "tsconfig.json"); + } + final String dirtyFile = filedir + "typescript.dirty"; + File dirtyFileFile = setFile(testDir + "test.ts").toResource(dirtyFile); + final String cleanFile = filedir + "typescript.clean"; + + final FormatterStep formatterStep = EslintFormatterStep.create( + devDependenciesForRuleset.get(ruleSetName), + TestProvisioner.mavenCentral(), + projectDir(), + buildDir(), + npmPathResolver(), + new EslintTypescriptConfig(eslintRc, null, tsconfigFile)); + + try (StepHarnessWithFile stepHarness = StepHarnessWithFile.forStep(formatterStep)) { + stepHarness.testResource(dirtyFileFile, dirtyFile, cleanFile); + } + } + } +/* + @NpmTest + @Nested + class PrettierFormattingOfFileTypesIsWorking extends NpmFormatterStepCommonTests { + + @ParameterizedTest(name = "{index}: prettier can be applied to {0}") + @ValueSource(strings = {"html", "typescript", "json", "javascript-es5", "javascript-es6", "css", "scss", "markdown", "yaml"}) + void formattingUsingConfigFile(String fileType) throws Exception { + String filedir = "npm/prettier/filetypes/" + fileType + "/"; + + final File prettierRc = createTestFile(filedir + ".prettierrc.yml"); + final String dirtyFile = filedir + fileType + ".dirty"; + final String cleanFile = filedir + fileType + ".clean"; + + final FormatterStep formatterStep = PrettierFormatterStep.create( + PrettierFormatterStep.defaultDevDependencies(), + TestProvisioner.mavenCentral(), + buildDir(), + npmPathResolver(), + new PrettierConfig(prettierRc, null)); + + try (StepHarness stepHarness = StepHarness.forStep(formatterStep)) { + stepHarness.testResource(dirtyFile, cleanFile); + } + } + } + + @NpmTest + @Nested + class SpecificPrettierFormatterStepTests extends NpmFormatterStepCommonTests { + + @Test + void parserInferenceBasedOnExplicitFilepathIsWorking() throws Exception { + String filedir = "npm/prettier/filetypes/json/"; + + final String dirtyFile = filedir + "json.dirty"; + final String cleanFile = filedir + "json.clean"; + + final FormatterStep formatterStep = PrettierFormatterStep.create( + PrettierFormatterStep.defaultDevDependencies(), + TestProvisioner.mavenCentral(), + buildDir(), + npmPathResolver(), + new PrettierConfig(null, ImmutableMap.of("filepath", "anyname.json"))); // should select parser based on this name + + try (StepHarness stepHarness = StepHarness.forStep(formatterStep)) { + stepHarness.testResource(dirtyFile, cleanFile); + } + } + + @Test + void parserInferenceBasedOnFilenameIsWorking() throws Exception { + String filedir = "npm/prettier/filename/"; + + final String dirtyFile = filedir + "dirty.json"; + final String cleanFile = filedir + "clean.json"; + + final FormatterStep formatterStep = PrettierFormatterStep.create( + PrettierFormatterStep.defaultDevDependencies(), + TestProvisioner.mavenCentral(), + buildDir(), + npmPathResolver(), + new PrettierConfig(null, Collections.emptyMap())); + + try (StepHarnessWithFile stepHarness = StepHarnessWithFile.forStep(formatterStep)) { + stepHarness.testResource(new File("test.json"), dirtyFile, cleanFile); + } + } + + @Test + void verifyPrettierErrorMessageIsRelayed() throws Exception { + FormatterStep formatterStep = PrettierFormatterStep.create( + PrettierFormatterStep.defaultDevDependenciesWithPrettier("2.0.5"), + TestProvisioner.mavenCentral(), + buildDir(), + npmPathResolver(), + new PrettierConfig(null, ImmutableMap.of("parser", "postcss"))); + try (StepHarness stepHarness = StepHarness.forStep(formatterStep)) { + stepHarness.testResourceException("npm/prettier/filetypes/scss/scss.dirty", exception -> { + exception.hasMessageContaining("HTTP 501"); + exception.hasMessageContaining("Couldn't resolve parser \"postcss\""); + }); + } + } + } + + @NpmTest + @Nested + class PrettierFormattingOptionsAreWorking extends NpmFormatterStepCommonTests { + + private static final String FILEDIR = "npm/prettier/config/"; + + void runFormatTest(PrettierConfig config, String cleanFileNameSuffix) throws Exception { + + final String dirtyFile = FILEDIR + "typescript.dirty"; + final String cleanFile = FILEDIR + "typescript." + cleanFileNameSuffix + ".clean"; + + final FormatterStep formatterStep = PrettierFormatterStep.create( + PrettierFormatterStep.defaultDevDependencies(), + TestProvisioner.mavenCentral(), + buildDir(), + npmPathResolver(), + config); // should select parser based on this name + + try (StepHarness stepHarness = StepHarness.forStep(formatterStep)) { + stepHarness.testResource(dirtyFile, cleanFile); + } + } + + @Test + void defaultsAreApplied() throws Exception { + runFormatTest(new PrettierConfig(null, ImmutableMap.of("parser", "typescript")), "defaults"); + } + + @Test + void configFileOptionsAreApplied() throws Exception { + runFormatTest(new PrettierConfig(createTestFile(FILEDIR + ".prettierrc.yml"), null), "configfile"); + } + + @Test + void configFileOptionsCanBeOverriden() throws Exception { + runFormatTest(new PrettierConfig(createTestFile(FILEDIR + ".prettierrc.yml"), ImmutableMap.of("printWidth", 300)), "override"); + } + + }*/ +} diff --git a/testlib/src/test/java/com/diffplug/spotless/npm/NpmFormatterStepCommonTests.java b/testlib/src/test/java/com/diffplug/spotless/npm/NpmFormatterStepCommonTests.java index 4da65cadc6..f1b5da59ff 100644 --- a/testlib/src/test/java/com/diffplug/spotless/npm/NpmFormatterStepCommonTests.java +++ b/testlib/src/test/java/com/diffplug/spotless/npm/NpmFormatterStepCommonTests.java @@ -42,4 +42,13 @@ protected File buildDir() throws IOException { } return this.buildDir; } + + private File projectDir = null; + + protected File projectDir() throws IOException { + if (this.projectDir == null) { + this.projectDir = newFolder("project-dir"); + } + return this.projectDir; + } } diff --git a/testlib/src/test/java/com/diffplug/spotless/npm/PrettierFormatterStepTest.java b/testlib/src/test/java/com/diffplug/spotless/npm/PrettierFormatterStepTest.java index 5f14022ad8..9db218efb5 100644 --- a/testlib/src/test/java/com/diffplug/spotless/npm/PrettierFormatterStepTest.java +++ b/testlib/src/test/java/com/diffplug/spotless/npm/PrettierFormatterStepTest.java @@ -50,6 +50,7 @@ void formattingUsingConfigFile(String fileType) throws Exception { final FormatterStep formatterStep = PrettierFormatterStep.create( PrettierFormatterStep.defaultDevDependencies(), TestProvisioner.mavenCentral(), + projectDir(), buildDir(), npmPathResolver(), new PrettierConfig(prettierRc, null)); @@ -74,6 +75,7 @@ void parserInferenceBasedOnExplicitFilepathIsWorking() throws Exception { final FormatterStep formatterStep = PrettierFormatterStep.create( PrettierFormatterStep.defaultDevDependencies(), TestProvisioner.mavenCentral(), + projectDir(), buildDir(), npmPathResolver(), new PrettierConfig(null, ImmutableMap.of("filepath", "anyname.json"))); // should select parser based on this name @@ -93,6 +95,7 @@ void parserInferenceBasedOnFilenameIsWorking() throws Exception { final FormatterStep formatterStep = PrettierFormatterStep.create( PrettierFormatterStep.defaultDevDependencies(), TestProvisioner.mavenCentral(), + projectDir(), buildDir(), npmPathResolver(), new PrettierConfig(null, Collections.emptyMap())); @@ -107,6 +110,7 @@ void verifyPrettierErrorMessageIsRelayed() throws Exception { FormatterStep formatterStep = PrettierFormatterStep.create( PrettierFormatterStep.defaultDevDependenciesWithPrettier("2.0.5"), TestProvisioner.mavenCentral(), + projectDir(), buildDir(), npmPathResolver(), new PrettierConfig(null, ImmutableMap.of("parser", "postcss"))); @@ -131,6 +135,7 @@ void runFormatTest(PrettierConfig config, String cleanFileNameSuffix) throws Exc final FormatterStep formatterStep = PrettierFormatterStep.create( PrettierFormatterStep.defaultDevDependencies(), TestProvisioner.mavenCentral(), + projectDir(), buildDir(), npmPathResolver(), config); // should select parser based on this name diff --git a/testlib/src/test/java/com/diffplug/spotless/npm/TsFmtFormatterStepTest.java b/testlib/src/test/java/com/diffplug/spotless/npm/TsFmtFormatterStepTest.java index 2812601726..d06b902b83 100644 --- a/testlib/src/test/java/com/diffplug/spotless/npm/TsFmtFormatterStepTest.java +++ b/testlib/src/test/java/com/diffplug/spotless/npm/TsFmtFormatterStepTest.java @@ -57,6 +57,7 @@ void formattingUsingConfigFile(String formattingConfigFile) throws Exception { final FormatterStep formatterStep = TsFmtFormatterStep.create( TsFmtFormatterStep.defaultDevDependencies(), TestProvisioner.mavenCentral(), + projectDir(), buildDir(), npmPathResolver(), TypedTsFmtConfigFile.named(configFileNameWithoutExtension, configFile), @@ -79,6 +80,7 @@ void formattingUsingInlineConfigWorks() throws Exception { final FormatterStep formatterStep = TsFmtFormatterStep.create( TsFmtFormatterStep.defaultDevDependencies(), TestProvisioner.mavenCentral(), + projectDir(), buildDir(), npmPathResolver(), null, From a2a5502b2ea696968c036dc89e21dedc95dd8633 Mon Sep 17 00:00:00 2001 From: Simon Gamma Date: Thu, 15 Dec 2022 20:11:33 +0100 Subject: [PATCH 423/757] eslint: reduce required options --- .../resources/com/diffplug/spotless/npm/eslint-serve.js | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/lib/src/main/resources/com/diffplug/spotless/npm/eslint-serve.js b/lib/src/main/resources/com/diffplug/spotless/npm/eslint-serve.js index 2804eb86dd..3c10b048c1 100644 --- a/lib/src/main/resources/com/diffplug/spotless/npm/eslint-serve.js +++ b/lib/src/main/resources/com/diffplug/spotless/npm/eslint-serve.js @@ -23,7 +23,6 @@ app.post("/eslint/format", async (req, res) => { const ESLintOptions = { fix: true, useEslintrc: false, // would result in (gradle) cache issues - resolvePluginsRelativeTo: format_data.node_modules_dir }; if (format_data.ts_config_root_dir) { @@ -42,15 +41,17 @@ app.post("/eslint/format", async (req, res) => { ESLintOptions.overrideConfig = ESLintOverrideConfig; } + console.log("using options: " + JSON.stringify(ESLintOptions)); + console.log("format input: ", format_data.file_content); + const eslint = new ESLint(ESLintOptions); - console.log("using options: " + JSON.stringify(ESLintOptions)); - console.log("format input", format_data.file_content); const lintTextOptions = { filePath: filePath, } console.log("lintTextOptions", lintTextOptions); + // LintResult[] // https://eslint.org/docs/latest/developer-guide/nodejs-api#-lintresult-type const results = await eslint.lintText(format_data.file_content, lintTextOptions); if (results.length !== 1) { From 35b2b7ced394c1bb5c512b47edd34604e451726d Mon Sep 17 00:00:00 2001 From: Simon Gamma Date: Fri, 16 Dec 2022 06:06:07 +0100 Subject: [PATCH 424/757] eslint: remove unneeded configuration --- .../diffplug/spotless/npm/EslintFormatterStep.java | 2 -- .../diffplug/spotless/npm/EslintRestService.java | 2 +- .../spotless/npm/EslintFormatterStepTest.java | 13 ++++++++----- 3 files changed, 9 insertions(+), 8 deletions(-) diff --git a/lib/src/main/java/com/diffplug/spotless/npm/EslintFormatterStep.java b/lib/src/main/java/com/diffplug/spotless/npm/EslintFormatterStep.java index 49bde50945..55261350b3 100644 --- a/lib/src/main/java/com/diffplug/spotless/npm/EslintFormatterStep.java +++ b/lib/src/main/java/com/diffplug/spotless/npm/EslintFormatterStep.java @@ -213,8 +213,6 @@ private void setConfigToCallOptions(Map eslintCallOptions) if (eslintConfig.getEslintConfigJs() != null) { eslintCallOptions.put(FormatOption.ESLINT_OVERRIDE_CONFIG, eslintConfig.getEslintConfigJs()); } - eslintCallOptions.put(FormatOption.NODE_MODULES_DIR, nodeModulesDir.getAbsolutePath()); - if (eslintConfig instanceof EslintTypescriptConfig) { // if we are a ts config, see if we need to use specific paths or use default projectDir File tsConfigFilePath = ((EslintTypescriptConfig) eslintConfig).getTypescriptConfigPath(); diff --git a/lib/src/main/java/com/diffplug/spotless/npm/EslintRestService.java b/lib/src/main/java/com/diffplug/spotless/npm/EslintRestService.java index d3a01621f1..198ee5389c 100644 --- a/lib/src/main/java/com/diffplug/spotless/npm/EslintRestService.java +++ b/lib/src/main/java/com/diffplug/spotless/npm/EslintRestService.java @@ -35,7 +35,7 @@ public String format(String fileContent, Map formatOptions } enum FormatOption { - ESLINT_OVERRIDE_CONFIG("eslint_override_config"), ESLINT_OVERRIDE_CONFIG_FILE("eslint_override_config_file"), FILE_PATH("file_path"), NODE_MODULES_DIR("node_modules_dir"), TS_CONFIG_ROOT_DIR("ts_config_root_dir"); + ESLINT_OVERRIDE_CONFIG("eslint_override_config"), ESLINT_OVERRIDE_CONFIG_FILE("eslint_override_config_file"), FILE_PATH("file_path"), TS_CONFIG_ROOT_DIR("ts_config_root_dir"); private final String backendName; diff --git a/testlib/src/test/java/com/diffplug/spotless/npm/EslintFormatterStepTest.java b/testlib/src/test/java/com/diffplug/spotless/npm/EslintFormatterStepTest.java index afe463c1aa..45787e4217 100644 --- a/testlib/src/test/java/com/diffplug/spotless/npm/EslintFormatterStepTest.java +++ b/testlib/src/test/java/com/diffplug/spotless/npm/EslintFormatterStepTest.java @@ -23,6 +23,7 @@ import com.diffplug.spotless.tag.NpmTest; import org.junit.jupiter.api.Nested; +import org.junit.jupiter.api.Test; import org.junit.jupiter.params.ParameterizedTest; import org.junit.jupiter.params.provider.ValueSource; @@ -33,6 +34,12 @@ @NpmTest class EslintFormatterStepTest { + private final Map combine(Map m1, Map m2) { + Map combined = new TreeMap<>(m1); + combined.putAll(m2); + return combined; + } + @NpmTest @Nested class EslintTypescriptFormattingStepTest extends NpmFormatterStepCommonTests { @@ -43,11 +50,7 @@ class EslintTypescriptFormattingStepTest extends NpmFormatterStepCommonTests { "standard_rules_xo", combine(EslintFormatterStep.defaultDevDependenciesForTypescript(), EslintFormatterStep.PopularStyleGuide.XO_TYPESCRIPT.devDependencies()) ); - private final Map combine(Map m1, Map m2) { - Map combined = new TreeMap<>(m1); - combined.putAll(m2); - return combined; - } + @ParameterizedTest(name = "{index}: eslint can be applied using ruleset {0}") @ValueSource(strings = {"custom_rules", "standard_rules_standard_with_typescript", "standard_rules_xo"}) From 016dd3adc08cfb92ef37bccf2ea59d7c48c4edcd Mon Sep 17 00:00:00 2001 From: Simon Gamma Date: Fri, 16 Dec 2022 06:06:51 +0100 Subject: [PATCH 425/757] eslint: test supplying inline config --- .../spotless/npm/EslintFormatterStep.java | 3 + .../com/diffplug/spotless/npm/eslint-serve.js | 2 +- .../spotless/npm/EslintFormatterStepTest.java | 161 ++++++------------ 3 files changed, 52 insertions(+), 114 deletions(-) diff --git a/lib/src/main/java/com/diffplug/spotless/npm/EslintFormatterStep.java b/lib/src/main/java/com/diffplug/spotless/npm/EslintFormatterStep.java index 55261350b3..91d8ef62a5 100644 --- a/lib/src/main/java/com/diffplug/spotless/npm/EslintFormatterStep.java +++ b/lib/src/main/java/com/diffplug/spotless/npm/EslintFormatterStep.java @@ -146,6 +146,9 @@ private static class State extends NpmFormatterStepStateBase implements Serializ } private EslintConfig localCopyFiles(EslintConfig orig) { + if (orig.getEslintConfigPath() == null) { + return orig; + } // If any config files are provided, we need to make sure they are at the same location as the node modules // as eslint will try to resolve plugin/config names relatively to the config file location and some // eslint configs contain relative paths to additional config files (such as tsconfig.json e.g.) diff --git a/lib/src/main/resources/com/diffplug/spotless/npm/eslint-serve.js b/lib/src/main/resources/com/diffplug/spotless/npm/eslint-serve.js index 3c10b048c1..b9f3207d5f 100644 --- a/lib/src/main/resources/com/diffplug/spotless/npm/eslint-serve.js +++ b/lib/src/main/resources/com/diffplug/spotless/npm/eslint-serve.js @@ -38,7 +38,7 @@ app.post("/eslint/format", async (req, res) => { ESLintOptions.overrideConfigFile = ESLintOverrideConfigFile; } if (ESLintOverrideConfig) { - ESLintOptions.overrideConfig = ESLintOverrideConfig; + eval("ESLintOptions.overrideConfig = " + ESLintOverrideConfig); } console.log("using options: " + JSON.stringify(ESLintOptions)); diff --git a/testlib/src/test/java/com/diffplug/spotless/npm/EslintFormatterStepTest.java b/testlib/src/test/java/com/diffplug/spotless/npm/EslintFormatterStepTest.java index 45787e4217..fdf17caae7 100644 --- a/testlib/src/test/java/com/diffplug/spotless/npm/EslintFormatterStepTest.java +++ b/testlib/src/test/java/com/diffplug/spotless/npm/EslintFormatterStepTest.java @@ -85,129 +85,64 @@ void formattingUsingRulesetsFile(String ruleSetName) throws Exception { } } } -/* - @NpmTest - @Nested - class PrettierFormattingOfFileTypesIsWorking extends NpmFormatterStepCommonTests { - - @ParameterizedTest(name = "{index}: prettier can be applied to {0}") - @ValueSource(strings = {"html", "typescript", "json", "javascript-es5", "javascript-es6", "css", "scss", "markdown", "yaml"}) - void formattingUsingConfigFile(String fileType) throws Exception { - String filedir = "npm/prettier/filetypes/" + fileType + "/"; - - final File prettierRc = createTestFile(filedir + ".prettierrc.yml"); - final String dirtyFile = filedir + fileType + ".dirty"; - final String cleanFile = filedir + fileType + ".clean"; - - final FormatterStep formatterStep = PrettierFormatterStep.create( - PrettierFormatterStep.defaultDevDependencies(), - TestProvisioner.mavenCentral(), - buildDir(), - npmPathResolver(), - new PrettierConfig(prettierRc, null)); - - try (StepHarness stepHarness = StepHarness.forStep(formatterStep)) { - stepHarness.testResource(dirtyFile, cleanFile); - } - } - } @NpmTest @Nested - class SpecificPrettierFormatterStepTests extends NpmFormatterStepCommonTests { + class EslintInlineConfigFormattingStepTest extends NpmFormatterStepCommonTests { - @Test - void parserInferenceBasedOnExplicitFilepathIsWorking() throws Exception { - String filedir = "npm/prettier/filetypes/json/"; - - final String dirtyFile = filedir + "json.dirty"; - final String cleanFile = filedir + "json.clean"; - - final FormatterStep formatterStep = PrettierFormatterStep.create( - PrettierFormatterStep.defaultDevDependencies(), - TestProvisioner.mavenCentral(), - buildDir(), - npmPathResolver(), - new PrettierConfig(null, ImmutableMap.of("filepath", "anyname.json"))); // should select parser based on this name - - try (StepHarness stepHarness = StepHarness.forStep(formatterStep)) { - stepHarness.testResource(dirtyFile, cleanFile); - } - } @Test - void parserInferenceBasedOnFilenameIsWorking() throws Exception { - String filedir = "npm/prettier/filename/"; - - final String dirtyFile = filedir + "dirty.json"; - final String cleanFile = filedir + "clean.json"; + void formattingUsingInlineXoConfig() throws Exception { + String filedir = "npm/eslint/typescript/standard_rules_xo/"; + + String testDir = "formatting_ruleset_xo_inline_config/"; + + + final String esLintConfig = String.join("\n", + "{", + " env: {", + " browser: true,", + " es2021: true,", + " },", + " extends: 'xo/browser',", + " overrides: [", + " {", + " extends: [", + " 'xo-typescript',", + " ],", + " files: [", + " '*.ts',", + " '*.tsx',", + " ],", + " },", + " ],", + " parser: '@typescript-eslint/parser',", + " parserOptions: {", + " ecmaVersion: 'latest',", + " sourceType: 'module',", + " project: './tsconfig.json',", + " },", + " rules: {", + " },", + "}" + ); + + File tsconfigFile = setFile(testDir + "tsconfig.json").toResource(filedir + "tsconfig.json"); + final String dirtyFile = filedir + "typescript.dirty"; + File dirtyFileFile = setFile(testDir + "test.ts").toResource(dirtyFile); + final String cleanFile = filedir + "typescript.clean"; - final FormatterStep formatterStep = PrettierFormatterStep.create( - PrettierFormatterStep.defaultDevDependencies(), - TestProvisioner.mavenCentral(), - buildDir(), - npmPathResolver(), - new PrettierConfig(null, Collections.emptyMap())); + final FormatterStep formatterStep = EslintFormatterStep.create( + combine(EslintFormatterStep.PopularStyleGuide.XO_TYPESCRIPT.devDependencies(), EslintFormatterStep.defaultDevDependenciesForTypescript()), + TestProvisioner.mavenCentral(), + projectDir(), + buildDir(), + npmPathResolver(), + new EslintTypescriptConfig(null, esLintConfig, tsconfigFile)); try (StepHarnessWithFile stepHarness = StepHarnessWithFile.forStep(formatterStep)) { - stepHarness.testResource(new File("test.json"), dirtyFile, cleanFile); - } - } - - @Test - void verifyPrettierErrorMessageIsRelayed() throws Exception { - FormatterStep formatterStep = PrettierFormatterStep.create( - PrettierFormatterStep.defaultDevDependenciesWithPrettier("2.0.5"), - TestProvisioner.mavenCentral(), - buildDir(), - npmPathResolver(), - new PrettierConfig(null, ImmutableMap.of("parser", "postcss"))); - try (StepHarness stepHarness = StepHarness.forStep(formatterStep)) { - stepHarness.testResourceException("npm/prettier/filetypes/scss/scss.dirty", exception -> { - exception.hasMessageContaining("HTTP 501"); - exception.hasMessageContaining("Couldn't resolve parser \"postcss\""); - }); + stepHarness.testResource(dirtyFileFile, dirtyFile, cleanFile); } } } - - @NpmTest - @Nested - class PrettierFormattingOptionsAreWorking extends NpmFormatterStepCommonTests { - - private static final String FILEDIR = "npm/prettier/config/"; - - void runFormatTest(PrettierConfig config, String cleanFileNameSuffix) throws Exception { - - final String dirtyFile = FILEDIR + "typescript.dirty"; - final String cleanFile = FILEDIR + "typescript." + cleanFileNameSuffix + ".clean"; - - final FormatterStep formatterStep = PrettierFormatterStep.create( - PrettierFormatterStep.defaultDevDependencies(), - TestProvisioner.mavenCentral(), - buildDir(), - npmPathResolver(), - config); // should select parser based on this name - - try (StepHarness stepHarness = StepHarness.forStep(formatterStep)) { - stepHarness.testResource(dirtyFile, cleanFile); - } - } - - @Test - void defaultsAreApplied() throws Exception { - runFormatTest(new PrettierConfig(null, ImmutableMap.of("parser", "typescript")), "defaults"); - } - - @Test - void configFileOptionsAreApplied() throws Exception { - runFormatTest(new PrettierConfig(createTestFile(FILEDIR + ".prettierrc.yml"), null), "configfile"); - } - - @Test - void configFileOptionsCanBeOverriden() throws Exception { - runFormatTest(new PrettierConfig(createTestFile(FILEDIR + ".prettierrc.yml"), ImmutableMap.of("printWidth", 300)), "override"); - } - - }*/ } From a9f89d8e51e8c969a40f1bf78b668852ffa69ddc Mon Sep 17 00:00:00 2001 From: Simon Gamma Date: Fri, 16 Dec 2022 19:57:48 +0100 Subject: [PATCH 426/757] eslint: adding javascript formatting (part 1) --- .../spotless/npm/EslintFormatterStep.java | 40 ++++++++++++- .../spotless/TypescriptExtensionTest.java | 16 +++--- .../javascript/custom_rules/.eslintrc.js | 31 ++++++++++ .../custom_rules/javascript-es6.clean | 21 +++++++ .../custom_rules/javascript-es6.dirty | 21 +++++++ .../javascript/styleguide/airbnb/.eslintrc.js | 15 +++++ .../styleguide/airbnb/javascript-es6.clean | 17 ++++++ .../styleguide/airbnb/javascript-es6.dirty | 21 +++++++ .../javascript/styleguide/google/.eslintrc.js | 15 +++++ .../styleguide/google/javascript-es6.clean | 25 +++++++++ .../styleguide/google/javascript-es6.dirty | 21 +++++++ .../styleguide/standard/.eslintrc.js | 15 +++++ .../styleguide/standard/javascript-es6.clean | 19 +++++++ .../styleguide/standard/javascript-es6.dirty | 21 +++++++ .../javascript/styleguide/xo/.eslintrc.js | 15 +++++ .../styleguide/xo/javascript-es6.clean | 20 +++++++ .../styleguide/xo/javascript-es6.dirty | 21 +++++++ .../standard_with_typescript}/.eslintrc.js | 0 .../standard_with_typescript}/tsconfig.json | 0 .../typescript.clean | 0 .../typescript.dirty | 0 .../xo}/.eslintrc.js | 0 .../xo}/tsconfig.json | 0 .../xo}/typescript.clean | 0 .../xo}/typescript.dirty | 0 .../spotless/npm/EslintFormatterStepTest.java | 56 ++++++++++++++++--- 26 files changed, 393 insertions(+), 17 deletions(-) create mode 100644 testlib/src/main/resources/npm/eslint/javascript/custom_rules/.eslintrc.js create mode 100644 testlib/src/main/resources/npm/eslint/javascript/custom_rules/javascript-es6.clean create mode 100644 testlib/src/main/resources/npm/eslint/javascript/custom_rules/javascript-es6.dirty create mode 100644 testlib/src/main/resources/npm/eslint/javascript/styleguide/airbnb/.eslintrc.js create mode 100644 testlib/src/main/resources/npm/eslint/javascript/styleguide/airbnb/javascript-es6.clean create mode 100644 testlib/src/main/resources/npm/eslint/javascript/styleguide/airbnb/javascript-es6.dirty create mode 100644 testlib/src/main/resources/npm/eslint/javascript/styleguide/google/.eslintrc.js create mode 100644 testlib/src/main/resources/npm/eslint/javascript/styleguide/google/javascript-es6.clean create mode 100644 testlib/src/main/resources/npm/eslint/javascript/styleguide/google/javascript-es6.dirty create mode 100644 testlib/src/main/resources/npm/eslint/javascript/styleguide/standard/.eslintrc.js create mode 100644 testlib/src/main/resources/npm/eslint/javascript/styleguide/standard/javascript-es6.clean create mode 100644 testlib/src/main/resources/npm/eslint/javascript/styleguide/standard/javascript-es6.dirty create mode 100644 testlib/src/main/resources/npm/eslint/javascript/styleguide/xo/.eslintrc.js create mode 100644 testlib/src/main/resources/npm/eslint/javascript/styleguide/xo/javascript-es6.clean create mode 100644 testlib/src/main/resources/npm/eslint/javascript/styleguide/xo/javascript-es6.dirty rename testlib/src/main/resources/npm/eslint/typescript/{standard_rules_standard_with_typescript => styleguide/standard_with_typescript}/.eslintrc.js (100%) rename testlib/src/main/resources/npm/eslint/typescript/{standard_rules_standard_with_typescript => styleguide/standard_with_typescript}/tsconfig.json (100%) rename testlib/src/main/resources/npm/eslint/typescript/{standard_rules_standard_with_typescript => styleguide/standard_with_typescript}/typescript.clean (100%) rename testlib/src/main/resources/npm/eslint/typescript/{standard_rules_standard_with_typescript => styleguide/standard_with_typescript}/typescript.dirty (100%) rename testlib/src/main/resources/npm/eslint/typescript/{standard_rules_xo => styleguide/xo}/.eslintrc.js (100%) rename testlib/src/main/resources/npm/eslint/typescript/{standard_rules_xo => styleguide/xo}/tsconfig.json (100%) rename testlib/src/main/resources/npm/eslint/typescript/{standard_rules_xo => styleguide/xo}/typescript.clean (100%) rename testlib/src/main/resources/npm/eslint/typescript/{standard_rules_xo => styleguide/xo}/typescript.dirty (100%) diff --git a/lib/src/main/java/com/diffplug/spotless/npm/EslintFormatterStep.java b/lib/src/main/java/com/diffplug/spotless/npm/EslintFormatterStep.java index 91d8ef62a5..14bc99a243 100644 --- a/lib/src/main/java/com/diffplug/spotless/npm/EslintFormatterStep.java +++ b/lib/src/main/java/com/diffplug/spotless/npm/EslintFormatterStep.java @@ -48,7 +48,7 @@ public class EslintFormatterStep { public static final String DEFAULT_ESLINT_VERSION = "8.28.0"; public enum PopularStyleGuide { - STANDARD_WITH_TYPESCRIPT("standard-with-typescript") { + TS_STANDARD_WITH_TYPESCRIPT("standard-with-typescript") { @Override public Map devDependencies() { Map dependencies = new LinkedHashMap<>(); @@ -60,7 +60,7 @@ public Map devDependencies() { return dependencies; } }, - XO_TYPESCRIPT("xo-typescript") { + TS_XO_TYPESCRIPT("xo-typescript") { @Override public Map devDependencies() { Map dependencies = new LinkedHashMap<>(); @@ -69,6 +69,42 @@ public Map devDependencies() { dependencies.put("typescript", "4.9.3"); return dependencies; } + }, + JS_AIRBNB("airbnb") { + @Override + public Map devDependencies() { + Map dependencies = new LinkedHashMap<>(); + dependencies.put("eslint-config-airbnb-base", "15.0.0"); + dependencies.put("eslint-plugin-import", "2.26.0"); + return dependencies; + } + }, + JS_GOOGLE("google") { + @Override + public Map devDependencies() { + Map dependencies = new LinkedHashMap<>(); + dependencies.put("eslint-config-google", "0.14.0"); + return dependencies; + } + }, + JS_STANDARD("standard") { + @Override + public Map devDependencies() { + Map dependencies = new LinkedHashMap<>(); + dependencies.put("eslint-config-standard", "17.0.0"); + dependencies.put("eslint-plugin-import", "2.26.0"); + dependencies.put("eslint-plugin-n", "15.6.0"); + dependencies.put("eslint-plugin-promise", "6.1.1"); + return dependencies; + } + }, + JS_XO("xo") { + @Override + public Map devDependencies() { + Map dependencies = new LinkedHashMap<>(); + dependencies.put("eslint-config-xo", "0.43.1"); + return dependencies; + } }; private final String popularStyleGuideName; diff --git a/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/TypescriptExtensionTest.java b/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/TypescriptExtensionTest.java index 0c3d10c89f..7d715998f6 100644 --- a/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/TypescriptExtensionTest.java +++ b/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/TypescriptExtensionTest.java @@ -163,8 +163,8 @@ void useEslint() throws IOException { @Test void useXoStandardRules() throws IOException { - setFile(".eslintrc.js").toResource("npm/eslint/typescript/standard_rules_xo/.eslintrc.js"); - setFile("tsconfig.json").toResource("npm/eslint/typescript/standard_rules_xo/tsconfig.json"); + setFile(".eslintrc.js").toResource("npm/eslint/typescript/styleguide/xo/.eslintrc.js"); + setFile("tsconfig.json").toResource("npm/eslint/typescript/styleguide/xo/tsconfig.json"); setFile("build.gradle").toLines( "plugins {", " id 'com.diffplug.spotless'", @@ -176,15 +176,15 @@ void useXoStandardRules() throws IOException { " eslint().styleGuide('xo-typescript').configFile('.eslintrc.js')", " }", "}"); - setFile("test.ts").toResource("npm/eslint/typescript/standard_rules_xo/typescript.dirty"); + setFile("test.ts").toResource("npm/eslint/typescript/styleguide/xo/typescript.dirty"); gradleRunner().withArguments("--stacktrace", "spotlessApply").build(); - assertFile("test.ts").sameAsResource("npm/eslint/typescript/standard_rules_xo/typescript.clean"); + assertFile("test.ts").sameAsResource("npm/eslint/typescript/styleguide/xo/typescript.clean"); } @Test void useStandardWithTypescriptRules() throws IOException { - setFile(".eslintrc.js").toResource("npm/eslint/typescript/standard_rules_standard_with_typescript/.eslintrc.js"); - setFile("tsconfig.json").toResource("npm/eslint/typescript/standard_rules_standard_with_typescript/tsconfig.json"); + setFile(".eslintrc.js").toResource("npm/eslint/typescript/styleguide/standard_with_typescript/.eslintrc.js"); + setFile("tsconfig.json").toResource("npm/eslint/typescript/styleguide/standard_with_typescript/tsconfig.json"); setFile("build.gradle").toLines( "plugins {", " id 'com.diffplug.spotless'", @@ -196,8 +196,8 @@ void useStandardWithTypescriptRules() throws IOException { " eslint().styleGuide('standard-with-typescript').configFile('.eslintrc.js')", " }", "}"); - setFile("test.ts").toResource("npm/eslint/typescript/standard_rules_standard_with_typescript/typescript.dirty"); + setFile("test.ts").toResource("npm/eslint/typescript/styleguide/standard_with_typescript/typescript.dirty"); gradleRunner().withArguments("--stacktrace", "spotlessApply").build(); - assertFile("test.ts").sameAsResource("npm/eslint/typescript/standard_rules_standard_with_typescript/typescript.clean"); + assertFile("test.ts").sameAsResource("npm/eslint/typescript/styleguide/standard_with_typescript/typescript.clean"); } } diff --git a/testlib/src/main/resources/npm/eslint/javascript/custom_rules/.eslintrc.js b/testlib/src/main/resources/npm/eslint/javascript/custom_rules/.eslintrc.js new file mode 100644 index 0000000000..60c5c19f5b --- /dev/null +++ b/testlib/src/main/resources/npm/eslint/javascript/custom_rules/.eslintrc.js @@ -0,0 +1,31 @@ +module.exports = { + "env": { + "browser": true, + "es2021": true + }, + "extends": "eslint:recommended", + "overrides": [ + ], + "parserOptions": { + "ecmaVersion": "latest", + "sourceType": "module" + }, + "rules": { + "indent": [ + "error", + 2 + ], + "linebreak-style": [ + "error", + "unix" + ], + "quotes": [ + "error", + "double" + ], + "semi": [ + "error", + "always" + ] + } +}; diff --git a/testlib/src/main/resources/npm/eslint/javascript/custom_rules/javascript-es6.clean b/testlib/src/main/resources/npm/eslint/javascript/custom_rules/javascript-es6.clean new file mode 100644 index 0000000000..8bbeb50cf3 --- /dev/null +++ b/testlib/src/main/resources/npm/eslint/javascript/custom_rules/javascript-es6.clean @@ -0,0 +1,21 @@ +var numbers=[1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20, +]; + +const p = { + first: "Peter", + last : "Pan", + get fullName() { return this.first + " " + this.last; } +}; + +const str = "Hello, world!" +; + +var str2=str.charAt(3)+str[0]; + +var multilinestr = "Hello \ +World" +; + +function test (a, b = "world") { let combined =a+ b; return combined;} + +test ("Hello"); diff --git a/testlib/src/main/resources/npm/eslint/javascript/custom_rules/javascript-es6.dirty b/testlib/src/main/resources/npm/eslint/javascript/custom_rules/javascript-es6.dirty new file mode 100644 index 0000000000..36a514cc30 --- /dev/null +++ b/testlib/src/main/resources/npm/eslint/javascript/custom_rules/javascript-es6.dirty @@ -0,0 +1,21 @@ +var numbers=[1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20, +]; + +const p = { + first: 'Peter', + last : 'Pan', + get fullName() { return this.first + ' ' + this.last; } +}; + +const str = 'Hello, world!' +; + +var str2=str.charAt(3)+str[0]; + +var multilinestr = 'Hello \ +World' +; + +function test (a, b = 'world') { let combined =a+ b; return combined}; + +test ('Hello'); diff --git a/testlib/src/main/resources/npm/eslint/javascript/styleguide/airbnb/.eslintrc.js b/testlib/src/main/resources/npm/eslint/javascript/styleguide/airbnb/.eslintrc.js new file mode 100644 index 0000000000..d93248ee88 --- /dev/null +++ b/testlib/src/main/resources/npm/eslint/javascript/styleguide/airbnb/.eslintrc.js @@ -0,0 +1,15 @@ +module.exports = { + env: { + browser: true, + es2021: true, + }, + extends: 'airbnb-base', + overrides: [ + ], + parserOptions: { + ecmaVersion: 'latest', + sourceType: 'module', + }, + rules: { + }, +}; diff --git a/testlib/src/main/resources/npm/eslint/javascript/styleguide/airbnb/javascript-es6.clean b/testlib/src/main/resources/npm/eslint/javascript/styleguide/airbnb/javascript-es6.clean new file mode 100644 index 0000000000..c8dda3d33f --- /dev/null +++ b/testlib/src/main/resources/npm/eslint/javascript/styleguide/airbnb/javascript-es6.clean @@ -0,0 +1,17 @@ +const numbers = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, +]; + +const p = { + first: 'Peter', + last: 'Pan', + get fullName() { return `${this.first} ${this.last}`; }, +}; + +const str = 'Hello, world!'; +const str2 = str.charAt(3) + str[0]; + +const multilinestr = 'Hello \ +World'; +function test(a, b = 'world') { const combined = a + b; return combined; } + +test('Hello'); diff --git a/testlib/src/main/resources/npm/eslint/javascript/styleguide/airbnb/javascript-es6.dirty b/testlib/src/main/resources/npm/eslint/javascript/styleguide/airbnb/javascript-es6.dirty new file mode 100644 index 0000000000..08ebafc1a2 --- /dev/null +++ b/testlib/src/main/resources/npm/eslint/javascript/styleguide/airbnb/javascript-es6.dirty @@ -0,0 +1,21 @@ +var numbers=[1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20, +]; + +const p = { + first: "Peter", + last : "Pan", + get fullName() { return this.first + " " + this.last; } +}; + +const str = "Hello, world!" +; + +var str2=str.charAt(3)+str[0]; + +var multilinestr = "Hello \ +World" +; + +function test (a, b = "world") { let combined =a+ b; return combined}; + +test ("Hello"); diff --git a/testlib/src/main/resources/npm/eslint/javascript/styleguide/google/.eslintrc.js b/testlib/src/main/resources/npm/eslint/javascript/styleguide/google/.eslintrc.js new file mode 100644 index 0000000000..71b0c47016 --- /dev/null +++ b/testlib/src/main/resources/npm/eslint/javascript/styleguide/google/.eslintrc.js @@ -0,0 +1,15 @@ +module.exports = { + 'env': { + 'browser': true, + 'es2021': true, + }, + 'extends': 'google', + 'overrides': [ + ], + 'parserOptions': { + 'ecmaVersion': 'latest', + 'sourceType': 'module', + }, + 'rules': { + }, +}; diff --git a/testlib/src/main/resources/npm/eslint/javascript/styleguide/google/javascript-es6.clean b/testlib/src/main/resources/npm/eslint/javascript/styleguide/google/javascript-es6.clean new file mode 100644 index 0000000000..f960a984c2 --- /dev/null +++ b/testlib/src/main/resources/npm/eslint/javascript/styleguide/google/javascript-es6.clean @@ -0,0 +1,25 @@ +const numbers=[1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, +]; + +const p = { + first: 'Peter', + last: 'Pan', + get fullName() { + return this.first + ' ' + this.last; + }, +}; + +const str = 'Hello, world!' +; + +const str2=str.charAt(3)+str[0]; + +const multilinestr = 'Hello \ +World' +; + +function test(a, b = 'world') { + const combined =a+ b; return combined; +}; + +test('Hello'); diff --git a/testlib/src/main/resources/npm/eslint/javascript/styleguide/google/javascript-es6.dirty b/testlib/src/main/resources/npm/eslint/javascript/styleguide/google/javascript-es6.dirty new file mode 100644 index 0000000000..08ebafc1a2 --- /dev/null +++ b/testlib/src/main/resources/npm/eslint/javascript/styleguide/google/javascript-es6.dirty @@ -0,0 +1,21 @@ +var numbers=[1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20, +]; + +const p = { + first: "Peter", + last : "Pan", + get fullName() { return this.first + " " + this.last; } +}; + +const str = "Hello, world!" +; + +var str2=str.charAt(3)+str[0]; + +var multilinestr = "Hello \ +World" +; + +function test (a, b = "world") { let combined =a+ b; return combined}; + +test ("Hello"); diff --git a/testlib/src/main/resources/npm/eslint/javascript/styleguide/standard/.eslintrc.js b/testlib/src/main/resources/npm/eslint/javascript/styleguide/standard/.eslintrc.js new file mode 100644 index 0000000000..cbed25aab9 --- /dev/null +++ b/testlib/src/main/resources/npm/eslint/javascript/styleguide/standard/.eslintrc.js @@ -0,0 +1,15 @@ +module.exports = { + env: { + browser: true, + es2021: true + }, + extends: 'standard', + overrides: [ + ], + parserOptions: { + ecmaVersion: 'latest', + sourceType: 'module' + }, + rules: { + } +} diff --git a/testlib/src/main/resources/npm/eslint/javascript/styleguide/standard/javascript-es6.clean b/testlib/src/main/resources/npm/eslint/javascript/styleguide/standard/javascript-es6.clean new file mode 100644 index 0000000000..757d330a7f --- /dev/null +++ b/testlib/src/main/resources/npm/eslint/javascript/styleguide/standard/javascript-es6.clean @@ -0,0 +1,19 @@ +const numbers = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20 +] + +const p = { + first: 'Peter', + last: 'Pan', + get fullName () { return this.first + ' ' + this.last } +} + +const str = 'Hello, world!' + +const str2 = str.charAt(3) + str[0] + +const multilinestr = 'Hello \ +World' + +function test (a, b = 'world') { const combined = a + b; return combined }; + +test('Hello') diff --git a/testlib/src/main/resources/npm/eslint/javascript/styleguide/standard/javascript-es6.dirty b/testlib/src/main/resources/npm/eslint/javascript/styleguide/standard/javascript-es6.dirty new file mode 100644 index 0000000000..08ebafc1a2 --- /dev/null +++ b/testlib/src/main/resources/npm/eslint/javascript/styleguide/standard/javascript-es6.dirty @@ -0,0 +1,21 @@ +var numbers=[1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20, +]; + +const p = { + first: "Peter", + last : "Pan", + get fullName() { return this.first + " " + this.last; } +}; + +const str = "Hello, world!" +; + +var str2=str.charAt(3)+str[0]; + +var multilinestr = "Hello \ +World" +; + +function test (a, b = "world") { let combined =a+ b; return combined}; + +test ("Hello"); diff --git a/testlib/src/main/resources/npm/eslint/javascript/styleguide/xo/.eslintrc.js b/testlib/src/main/resources/npm/eslint/javascript/styleguide/xo/.eslintrc.js new file mode 100644 index 0000000000..844e843c41 --- /dev/null +++ b/testlib/src/main/resources/npm/eslint/javascript/styleguide/xo/.eslintrc.js @@ -0,0 +1,15 @@ +module.exports = { + env: { + browser: true, + es2021: true, + }, + extends: 'xo', + overrides: [ + ], + parserOptions: { + ecmaVersion: 'latest', + sourceType: 'module', + }, + rules: { + }, +}; diff --git a/testlib/src/main/resources/npm/eslint/javascript/styleguide/xo/javascript-es6.clean b/testlib/src/main/resources/npm/eslint/javascript/styleguide/xo/javascript-es6.clean new file mode 100644 index 0000000000..3cd1bd0865 --- /dev/null +++ b/testlib/src/main/resources/npm/eslint/javascript/styleguide/xo/javascript-es6.clean @@ -0,0 +1,20 @@ +const numbers = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20]; + +const p = { + first: 'Peter', + last: 'Pan', + get fullName() { + return this.first + ' ' + this.last; + }, +}; + +const str = 'Hello, world!'; +const str2 = str.charAt(3) + str[0]; + +const multilinestr = 'Hello \ +World'; +function test(a, b = 'world') { + const combined = a + b; return combined; +} + +test('Hello'); diff --git a/testlib/src/main/resources/npm/eslint/javascript/styleguide/xo/javascript-es6.dirty b/testlib/src/main/resources/npm/eslint/javascript/styleguide/xo/javascript-es6.dirty new file mode 100644 index 0000000000..08ebafc1a2 --- /dev/null +++ b/testlib/src/main/resources/npm/eslint/javascript/styleguide/xo/javascript-es6.dirty @@ -0,0 +1,21 @@ +var numbers=[1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20, +]; + +const p = { + first: "Peter", + last : "Pan", + get fullName() { return this.first + " " + this.last; } +}; + +const str = "Hello, world!" +; + +var str2=str.charAt(3)+str[0]; + +var multilinestr = "Hello \ +World" +; + +function test (a, b = "world") { let combined =a+ b; return combined}; + +test ("Hello"); diff --git a/testlib/src/main/resources/npm/eslint/typescript/standard_rules_standard_with_typescript/.eslintrc.js b/testlib/src/main/resources/npm/eslint/typescript/styleguide/standard_with_typescript/.eslintrc.js similarity index 100% rename from testlib/src/main/resources/npm/eslint/typescript/standard_rules_standard_with_typescript/.eslintrc.js rename to testlib/src/main/resources/npm/eslint/typescript/styleguide/standard_with_typescript/.eslintrc.js diff --git a/testlib/src/main/resources/npm/eslint/typescript/standard_rules_standard_with_typescript/tsconfig.json b/testlib/src/main/resources/npm/eslint/typescript/styleguide/standard_with_typescript/tsconfig.json similarity index 100% rename from testlib/src/main/resources/npm/eslint/typescript/standard_rules_standard_with_typescript/tsconfig.json rename to testlib/src/main/resources/npm/eslint/typescript/styleguide/standard_with_typescript/tsconfig.json diff --git a/testlib/src/main/resources/npm/eslint/typescript/standard_rules_standard_with_typescript/typescript.clean b/testlib/src/main/resources/npm/eslint/typescript/styleguide/standard_with_typescript/typescript.clean similarity index 100% rename from testlib/src/main/resources/npm/eslint/typescript/standard_rules_standard_with_typescript/typescript.clean rename to testlib/src/main/resources/npm/eslint/typescript/styleguide/standard_with_typescript/typescript.clean diff --git a/testlib/src/main/resources/npm/eslint/typescript/standard_rules_standard_with_typescript/typescript.dirty b/testlib/src/main/resources/npm/eslint/typescript/styleguide/standard_with_typescript/typescript.dirty similarity index 100% rename from testlib/src/main/resources/npm/eslint/typescript/standard_rules_standard_with_typescript/typescript.dirty rename to testlib/src/main/resources/npm/eslint/typescript/styleguide/standard_with_typescript/typescript.dirty diff --git a/testlib/src/main/resources/npm/eslint/typescript/standard_rules_xo/.eslintrc.js b/testlib/src/main/resources/npm/eslint/typescript/styleguide/xo/.eslintrc.js similarity index 100% rename from testlib/src/main/resources/npm/eslint/typescript/standard_rules_xo/.eslintrc.js rename to testlib/src/main/resources/npm/eslint/typescript/styleguide/xo/.eslintrc.js diff --git a/testlib/src/main/resources/npm/eslint/typescript/standard_rules_xo/tsconfig.json b/testlib/src/main/resources/npm/eslint/typescript/styleguide/xo/tsconfig.json similarity index 100% rename from testlib/src/main/resources/npm/eslint/typescript/standard_rules_xo/tsconfig.json rename to testlib/src/main/resources/npm/eslint/typescript/styleguide/xo/tsconfig.json diff --git a/testlib/src/main/resources/npm/eslint/typescript/standard_rules_xo/typescript.clean b/testlib/src/main/resources/npm/eslint/typescript/styleguide/xo/typescript.clean similarity index 100% rename from testlib/src/main/resources/npm/eslint/typescript/standard_rules_xo/typescript.clean rename to testlib/src/main/resources/npm/eslint/typescript/styleguide/xo/typescript.clean diff --git a/testlib/src/main/resources/npm/eslint/typescript/standard_rules_xo/typescript.dirty b/testlib/src/main/resources/npm/eslint/typescript/styleguide/xo/typescript.dirty similarity index 100% rename from testlib/src/main/resources/npm/eslint/typescript/standard_rules_xo/typescript.dirty rename to testlib/src/main/resources/npm/eslint/typescript/styleguide/xo/typescript.dirty diff --git a/testlib/src/test/java/com/diffplug/spotless/npm/EslintFormatterStepTest.java b/testlib/src/test/java/com/diffplug/spotless/npm/EslintFormatterStepTest.java index fdf17caae7..3a8bfc7fd6 100644 --- a/testlib/src/test/java/com/diffplug/spotless/npm/EslintFormatterStepTest.java +++ b/testlib/src/test/java/com/diffplug/spotless/npm/EslintFormatterStepTest.java @@ -17,7 +17,6 @@ import com.diffplug.common.collect.ImmutableMap; import com.diffplug.spotless.FormatterStep; -import com.diffplug.spotless.StepHarness; import com.diffplug.spotless.StepHarnessWithFile; import com.diffplug.spotless.TestProvisioner; import com.diffplug.spotless.tag.NpmTest; @@ -40,24 +39,67 @@ private final Map combine(Map m1, Map> devDependenciesForRuleset = ImmutableMap.of( + "custom_rules", EslintFormatterStep.defaultDevDependenciesForTypescript(), + "styleguide/airbnb", combine(EslintFormatterStep.defaultDevDependencies(), EslintFormatterStep.PopularStyleGuide.JS_AIRBNB.devDependencies()), + "styleguide/google", combine(EslintFormatterStep.defaultDevDependencies(), EslintFormatterStep.PopularStyleGuide.JS_GOOGLE.devDependencies()), + "styleguide/standard", combine(EslintFormatterStep.defaultDevDependencies(), EslintFormatterStep.PopularStyleGuide.JS_STANDARD.devDependencies()), + "styleguide/xo", combine(EslintFormatterStep.defaultDevDependencies(), EslintFormatterStep.PopularStyleGuide.JS_XO.devDependencies()) + ); + + @ParameterizedTest(name = "{index}: eslint can be applied using ruleset {0}") + @ValueSource(strings = {"custom_rules", "styleguide/airbnb", "styleguide/google", "styleguide/standard", "styleguide/xo"}) + void formattingUsingRulesetsFile(String ruleSetName) throws Exception { + String filedir = "npm/eslint/javascript/" + ruleSetName + "/"; + + String testDir = "formatting_ruleset_" + ruleSetName.replace('/', '_') + "/"; +// File testDirFile = newFolder(testDir); + + final File eslintRc = createTestFile(filedir + ".eslintrc.js"); +// final File eslintRc = setFile(buildDir().getPath() + "/.eslintrc.js").toResource(filedir + ".eslintrc.js"); + + final String dirtyFile = filedir + "javascript-es6.dirty"; + File dirtyFileFile = setFile(testDir + "test.js").toResource(dirtyFile); + final String cleanFile = filedir + "javascript-es6.clean"; + + final FormatterStep formatterStep = EslintFormatterStep.create( + devDependenciesForRuleset.get(ruleSetName), + TestProvisioner.mavenCentral(), + projectDir(), + buildDir(), + npmPathResolver(), + new EslintConfig(eslintRc, null)); + + try (StepHarnessWithFile stepHarness = StepHarnessWithFile.forStep(formatterStep)) { + stepHarness.testResource(dirtyFileFile, dirtyFile, cleanFile); + } + } + } + + + @NpmTest @Nested class EslintTypescriptFormattingStepTest extends NpmFormatterStepCommonTests { private final Map> devDependenciesForRuleset = ImmutableMap.of( "custom_rules", EslintFormatterStep.defaultDevDependenciesForTypescript(), - "standard_rules_standard_with_typescript", combine(EslintFormatterStep.defaultDevDependenciesForTypescript(), EslintFormatterStep.PopularStyleGuide.STANDARD_WITH_TYPESCRIPT.devDependencies()), - "standard_rules_xo", combine(EslintFormatterStep.defaultDevDependenciesForTypescript(), EslintFormatterStep.PopularStyleGuide.XO_TYPESCRIPT.devDependencies()) + "styleguide/standard_with_typescript", combine(EslintFormatterStep.defaultDevDependenciesForTypescript(), EslintFormatterStep.PopularStyleGuide.TS_STANDARD_WITH_TYPESCRIPT.devDependencies()), + "styleguide/xo", combine(EslintFormatterStep.defaultDevDependenciesForTypescript(), EslintFormatterStep.PopularStyleGuide.TS_XO_TYPESCRIPT.devDependencies()) ); @ParameterizedTest(name = "{index}: eslint can be applied using ruleset {0}") - @ValueSource(strings = {"custom_rules", "standard_rules_standard_with_typescript", "standard_rules_xo"}) + @ValueSource(strings = {"custom_rules", "styleguide/standard_with_typescript", "styleguide/xo"}) void formattingUsingRulesetsFile(String ruleSetName) throws Exception { String filedir = "npm/eslint/typescript/" + ruleSetName + "/"; - String testDir = "formatting_ruleset_" + ruleSetName + "/"; + String testDir = "formatting_ruleset_" + ruleSetName.replace('/', '_') + "/"; // File testDirFile = newFolder(testDir); final File eslintRc = createTestFile(filedir + ".eslintrc.js"); @@ -88,7 +130,7 @@ void formattingUsingRulesetsFile(String ruleSetName) throws Exception { @NpmTest @Nested - class EslintInlineConfigFormattingStepTest extends NpmFormatterStepCommonTests { + class EslintInlineConfigTypescriptFormattingStepTest extends NpmFormatterStepCommonTests { @Test @@ -133,7 +175,7 @@ void formattingUsingInlineXoConfig() throws Exception { final String cleanFile = filedir + "typescript.clean"; final FormatterStep formatterStep = EslintFormatterStep.create( - combine(EslintFormatterStep.PopularStyleGuide.XO_TYPESCRIPT.devDependencies(), EslintFormatterStep.defaultDevDependenciesForTypescript()), + combine(EslintFormatterStep.PopularStyleGuide.TS_XO_TYPESCRIPT.devDependencies(), EslintFormatterStep.defaultDevDependenciesForTypescript()), TestProvisioner.mavenCentral(), projectDir(), buildDir(), From 4efc19b200face1697512e18ed906524df444177 Mon Sep 17 00:00:00 2001 From: Simon Gamma Date: Sun, 18 Dec 2022 20:43:16 +0100 Subject: [PATCH 427/757] eslint: introduce separate javascript extension --- .../spotless/npm/EslintTypescriptConfig.java | 25 ++- .../gradle/spotless/FormatExtension.java | 100 +++-------- .../gradle/spotless/JavascriptExtension.java | 156 ++++++++++++++++++ .../gradle/spotless/SpotlessExtension.java | 5 + .../gradle/spotless/TypescriptExtension.java | 84 +++++----- .../spotless/npm/EslintFormatterStepTest.java | 139 ++++++++-------- .../npm/NpmFormatterStepCommonTests.java | 2 +- .../spotless/npm/TsFmtFormatterStepTest.java | 2 +- 8 files changed, 313 insertions(+), 200 deletions(-) create mode 100644 plugin-gradle/src/main/java/com/diffplug/gradle/spotless/JavascriptExtension.java diff --git a/lib/src/main/java/com/diffplug/spotless/npm/EslintTypescriptConfig.java b/lib/src/main/java/com/diffplug/spotless/npm/EslintTypescriptConfig.java index 05c8209837..f8c213a0a9 100644 --- a/lib/src/main/java/com/diffplug/spotless/npm/EslintTypescriptConfig.java +++ b/lib/src/main/java/com/diffplug/spotless/npm/EslintTypescriptConfig.java @@ -1,15 +1,30 @@ +/* + * Copyright 2022 DiffPlug + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ package com.diffplug.spotless.npm; +import java.io.File; +import java.io.IOException; + +import javax.annotation.Nullable; + import com.diffplug.spotless.FileSignature; import com.diffplug.spotless.ThrowingEx; import edu.umd.cs.findbugs.annotations.SuppressFBWarnings; -import javax.annotation.Nullable; - -import java.io.File; -import java.io.IOException; - public class EslintTypescriptConfig extends EslintConfig { @SuppressFBWarnings("SE_TRANSIENT_FIELD_NOT_RESTORED") 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 6152f9009d..08e713a921 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 @@ -24,13 +24,11 @@ import java.nio.file.Files; import java.util.ArrayList; import java.util.Collection; -import java.util.LinkedHashMap; import java.util.List; import java.util.Map; -import java.util.Optional; import java.util.Random; import java.util.TreeMap; -import java.util.stream.Collectors; +import java.util.function.Consumer; import javax.annotation.Nullable; import javax.inject.Inject; @@ -62,8 +60,6 @@ import com.diffplug.spotless.generic.ReplaceRegexStep; import com.diffplug.spotless.generic.ReplaceStep; import com.diffplug.spotless.generic.TrimTrailingWhitespaceStep; -import com.diffplug.spotless.npm.EslintConfig; -import com.diffplug.spotless.npm.EslintFormatterStep; import com.diffplug.spotless.npm.NpmPathResolver; import com.diffplug.spotless.npm.PrettierFormatterStep; @@ -518,23 +514,32 @@ public LicenseHeaderConfig licenseHeaderFile(Object licenseHeaderFile, String de return config; } - public abstract class NpmStepConfig> { + public abstract static class NpmStepConfig> { @Nullable protected Object npmFile; @Nullable protected Object npmrcFile; + protected Project project; + + private Consumer replaceStep; + + public NpmStepConfig(Project project, Consumer replaceStep) { + this.project = requireNonNull(project); + this.replaceStep = requireNonNull(replaceStep); + } + @SuppressWarnings("unchecked") public T npmExecutable(final Object npmFile) { this.npmFile = npmFile; - replaceStep(createStep()); + replaceStep(); return (T) this; } public T npmrc(final Object npmrcFile) { this.npmrcFile = npmrcFile; - replaceStep(createStep()); + replaceStep(); return (T) this; } @@ -547,10 +552,14 @@ File npmrcFileOrNull() { } private File fileOrNull(Object npmFile) { - return npmFile != null ? getProject().file(npmFile) : null; + return npmFile != null ? project.file(npmFile) : null; } - abstract FormatterStep createStep(); + protected void replaceStep() { + replaceStep.accept(createStep()); + } + + abstract protected FormatterStep createStep(); } @@ -565,22 +574,24 @@ public class PrettierConfig extends NpmStepConfig { final Map devDependencies; PrettierConfig(Map devDependencies) { + super(getProject(), FormatExtension.this::replaceStep); this.devDependencies = requireNonNull(devDependencies); } public PrettierConfig configFile(final Object prettierConfigFile) { this.prettierConfigFile = prettierConfigFile; - replaceStep(createStep()); + replaceStep(); return this; } public PrettierConfig config(final Map prettierConfig) { this.prettierConfig = new TreeMap<>(prettierConfig); - replaceStep(createStep()); + replaceStep(); return this; } - FormatterStep createStep() { + @Override + protected FormatterStep createStep() { final Project project = getProject(); return PrettierFormatterStep.create( devDependencies, @@ -611,69 +622,6 @@ public PrettierConfig prettier(Map devDependencies) { return prettierConfig; } - public class EslintFormatExtension extends NpmStepConfig { - - Map devDependencies = new LinkedHashMap<>(); - - @Nullable - Object configFilePath = null; - - @Nullable - String configJs = null; - - public EslintFormatExtension(Map devDependencies) { - this.devDependencies.putAll(requireNonNull(devDependencies)); - } - - public EslintFormatExtension devDependencies(Map devDependencies) { - this.devDependencies.putAll(devDependencies); - replaceStep(createStep()); - return this; - } - - public EslintFormatExtension configJs(String configJs) { - this.configJs = requireNonNull(configJs); - replaceStep(createStep()); - return this; - } - - public EslintFormatExtension configFile(Object configFilePath) { - this.configFilePath = requireNonNull(configFilePath); - replaceStep(createStep()); - return this; - } - - public FormatterStep createStep() { - final Project project = getProject(); - - return EslintFormatterStep.create( - devDependencies, - provisioner(), - project.getProjectDir(), - project.getBuildDir(), - new NpmPathResolver(npmFileOrNull(), npmrcFileOrNull(), project.getProjectDir(), project.getRootDir()), - eslintConfig()); - } - - protected EslintConfig eslintConfig() { - return new EslintConfig(configFilePath != null ? getProject().file(configFilePath) : null, configJs); - } - } - - public EslintFormatExtension eslint() { - return eslint(EslintFormatterStep.defaultDevDependencies()); - } - - public EslintFormatExtension eslint(String version) { - return eslint(EslintFormatterStep.defaultDevDependenciesWithEslint(version)); - } - - public EslintFormatExtension eslint(Map devDependencies) { - EslintFormatExtension eslint = new EslintFormatExtension(devDependencies); - addStep(eslint.createStep()); - return eslint; - } - /** Uses the default version of clang-format. */ public ClangFormatConfig clangFormat() { return clangFormat(ClangFormatStep.defaultVersion()); diff --git a/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/JavascriptExtension.java b/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/JavascriptExtension.java new file mode 100644 index 0000000000..348ed5f37e --- /dev/null +++ b/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/JavascriptExtension.java @@ -0,0 +1,156 @@ +/* + * 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. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.diffplug.gradle.spotless; + +import static java.util.Objects.requireNonNull; + +import java.util.Arrays; +import java.util.LinkedHashMap; +import java.util.Map; +import java.util.function.Consumer; +import java.util.stream.Collectors; + +import javax.annotation.Nullable; +import javax.inject.Inject; + +import org.gradle.api.Project; + +import com.diffplug.spotless.FormatterStep; +import com.diffplug.spotless.npm.EslintConfig; +import com.diffplug.spotless.npm.EslintFormatterStep; +import com.diffplug.spotless.npm.EslintFormatterStep.PopularStyleGuide; +import com.diffplug.spotless.npm.NpmPathResolver; + +public class JavascriptExtension extends FormatExtension { + + static final String NAME = "javascript"; + + @Inject + public JavascriptExtension(SpotlessExtension spotless) { + super(spotless); + } + + public JavascriptEslintConfig eslint() { + return eslint(EslintFormatterStep.defaultDevDependenciesForTypescript()); + } + + public JavascriptEslintConfig eslint(String version) { + return eslint(EslintFormatterStep.defaultDevDependenciesTypescriptWithEslint(version)); + } + + public JavascriptEslintConfig eslint(Map devDependencies) { + JavascriptEslintConfig eslint = new JavascriptEslintConfig(devDependencies); + addStep(eslint.createStep()); + return eslint; + } + + // TODO: make the configs static so that they do not need to have a hierarchy symmetric to the extensions + + public static abstract class EslintBaseConfig> extends NpmStepConfig> { + Map devDependencies = new LinkedHashMap<>(); + + @Nullable + Object configFilePath = null; + + @Nullable + String configJs = null; + + public EslintBaseConfig(Project project, Consumer replaceStep, Map devDependencies) { + super(project, replaceStep); + this.devDependencies.putAll(requireNonNull(devDependencies)); + } + + @SuppressWarnings("unchecked") + public T devDependencies(Map devDependencies) { + this.devDependencies.putAll(devDependencies); + replaceStep(); + return (T) this; + } + + @SuppressWarnings("unchecked") + public T configJs(String configJs) { + this.configJs = requireNonNull(configJs); + replaceStep(); + return (T) this; + } + + @SuppressWarnings("unchecked") + public T configFile(Object configFilePath) { + this.configFilePath = requireNonNull(configFilePath); + replaceStep(); + return (T) this; + } + + @SuppressWarnings("unchecked") + public T styleGuide(String styleGuide) { + PopularStyleGuide popularStyleGuide = PopularStyleGuide.fromNameOrNull(styleGuide); + + verifyStyleGuideIsSupported(styleGuide, popularStyleGuide); + devDependencies(popularStyleGuide.devDependencies()); + replaceStep(); + return (T) this; + } + + protected abstract void verifyStyleGuideIsSupported(String styleGuideName, PopularStyleGuide popularStyleGuide); + } + + public class JavascriptEslintConfig extends EslintBaseConfig { + + public JavascriptEslintConfig(Map devDependencies) { + super(getProject(), JavascriptExtension.this::replaceStep, devDependencies); + } + + public FormatterStep createStep() { + final Project project = getProject(); + + return EslintFormatterStep.create( + devDependencies, + provisioner(), + project.getProjectDir(), + project.getBuildDir(), + new NpmPathResolver(npmFileOrNull(), npmrcFileOrNull(), project.getProjectDir(), project.getRootDir()), + eslintConfig()); + } + + @Override + protected void verifyStyleGuideIsSupported(String styleGuideName, PopularStyleGuide popularStyleGuide) { + if (!isJsStyleGuide(popularStyleGuide)) { + throw new IllegalArgumentException("Unknown style guide: " + styleGuideName + ". Known javascript style guides: " + + Arrays.stream(PopularStyleGuide.values()) + .filter(this::isJsStyleGuide) + .map(PopularStyleGuide::getPopularStyleGuideName) + .sorted() + .collect(Collectors.joining(", "))); + } + } + + private boolean isJsStyleGuide(PopularStyleGuide popularStyleGuide) { + return popularStyleGuide != null && popularStyleGuide.name().startsWith("JS_"); + } + + protected EslintConfig eslintConfig() { + return new EslintConfig(configFilePath != null ? getProject().file(configFilePath) : null, configJs); + } + } + + @Override + protected void setupTask(SpotlessTask task) { + if (target == null) { + throw noDefaultTargetException(); + } + super.setupTask(task); + } +} 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 57aa3b2d83..3fe5721b5d 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 @@ -167,6 +167,11 @@ public void cpp(Action closure) { format(CppExtension.NAME, CppExtension.class, closure); } + /** Configures the special javascript-specific extension for javascript files. */ + public void javascript(Action closure) { + format(JavascriptExtension.NAME, JavascriptExtension.class, closure); + } + /** Configures the special typescript-specific extension for typescript files. */ public void typescript(Action closure) { format(TypescriptExtension.NAME, TypescriptExtension.class, closure); diff --git a/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/TypescriptExtension.java b/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/TypescriptExtension.java index d4dedc32eb..f318dd89c8 100644 --- a/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/TypescriptExtension.java +++ b/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/TypescriptExtension.java @@ -27,15 +27,13 @@ import javax.annotation.Nullable; import javax.inject.Inject; -import com.diffplug.spotless.npm.EslintConfig; - -import com.diffplug.spotless.npm.EslintTypescriptConfig; - import org.gradle.api.Project; import com.diffplug.spotless.FormatterStep; +import com.diffplug.spotless.npm.EslintConfig; import com.diffplug.spotless.npm.EslintFormatterStep; import com.diffplug.spotless.npm.EslintFormatterStep.PopularStyleGuide; +import com.diffplug.spotless.npm.EslintTypescriptConfig; import com.diffplug.spotless.npm.NpmPathResolver; import com.diffplug.spotless.npm.PrettierFormatterStep; import com.diffplug.spotless.npm.TsConfigFileType; @@ -81,12 +79,13 @@ public class TypescriptFormatExtension extends NpmStepConfig devDependencies; TypescriptFormatExtension(Map devDependencies) { + super(getProject(), TypescriptExtension.this::replaceStep); this.devDependencies = Objects.requireNonNull(devDependencies); } public void config(final Map config) { this.config = new TreeMap<>(requireNonNull(config)); - replaceStep(createStep()); + replaceStep(); } public void tsconfigFile(final Object path) { @@ -108,7 +107,7 @@ public void tsfmtFile(final Object path) { private void configFile(TsConfigFileType filetype, Object path) { this.configFileType = requireNonNull(filetype); this.configFilePath = requireNonNull(path); - replaceStep(createStep()); + replaceStep(); } public FormatterStep createStep() { @@ -161,7 +160,7 @@ public class TypescriptPrettierConfig extends PrettierConfig { } @Override - FormatterStep createStep() { + protected FormatterStep createStep() { fixParserToTypescript(); return super.createStep(); } @@ -178,74 +177,73 @@ private void fixParserToTypescript() { } } - @Override - public TypescriptEslintFormatExtension eslint() { + public TypescriptEslintConfig eslint() { return eslint(EslintFormatterStep.defaultDevDependenciesForTypescript()); } - @Override - public TypescriptEslintFormatExtension eslint(String version) { + public TypescriptEslintConfig eslint(String version) { return eslint(EslintFormatterStep.defaultDevDependenciesTypescriptWithEslint(version)); } - @Override - public TypescriptEslintFormatExtension eslint(Map devDependencies) { - TypescriptEslintFormatExtension eslint = new TypescriptEslintFormatExtension(devDependencies); + public TypescriptEslintConfig eslint(Map devDependencies) { + TypescriptEslintConfig eslint = new TypescriptEslintConfig(devDependencies); addStep(eslint.createStep()); return eslint; } - public class TypescriptEslintFormatExtension extends EslintFormatExtension { + public class TypescriptEslintConfig extends JavascriptExtension.EslintBaseConfig { @Nullable Object typescriptConfigFilePath = null; - public TypescriptEslintFormatExtension(Map devDependencies) { - super(devDependencies); + public TypescriptEslintConfig(Map devDependencies) { + super(getProject(), TypescriptExtension.this::replaceStep, devDependencies); } - @Override - public TypescriptEslintFormatExtension devDependencies(Map devDependencies) { - return (TypescriptEslintFormatExtension) super.devDependencies(devDependencies); + public TypescriptEslintConfig tsconfigFile(Object path) { + this.typescriptConfigFilePath = requireNonNull(path); + replaceStep(); + return this; } @Override - public TypescriptEslintFormatExtension configJs(String configJs) { - return (TypescriptEslintFormatExtension) super.configJs(configJs); + protected void verifyStyleGuideIsSupported(String styleGuideName, PopularStyleGuide popularStyleGuide) { + if (!isTsStyleGuide(popularStyleGuide)) { + throw new IllegalArgumentException("Unknown style guide: " + styleGuideName + ". Known typescript style guides: " + + Arrays.stream(EslintFormatterStep.PopularStyleGuide.values()) + .filter(this::isTsStyleGuide) + .map(PopularStyleGuide::getPopularStyleGuideName) + .sorted() + .collect(Collectors.joining(", "))); + } } - @Override - public TypescriptEslintFormatExtension configFile(Object configFilePath) { - return (TypescriptEslintFormatExtension) super.configFile(configFilePath); + private boolean isTsStyleGuide(PopularStyleGuide popularStyleGuide) { + return popularStyleGuide != null && popularStyleGuide.name().startsWith("TS_"); } - public TypescriptEslintFormatExtension styleGuide(String styleGuide) { - PopularStyleGuide popularStyleGuide = PopularStyleGuide.fromNameOrNull(styleGuide); - if (popularStyleGuide == null) { - throw new IllegalArgumentException("Unknown style guide: " + styleGuide + ". Known style guides: " - + Arrays.stream(PopularStyleGuide.values()).map(PopularStyleGuide::getPopularStyleGuideName).collect(Collectors.joining(", "))); - } - devDependencies(popularStyleGuide.devDependencies()); - replaceStep(createStep()); - return this; - } + public FormatterStep createStep() { + final Project project = getProject(); - public TypescriptEslintFormatExtension tsconfigFile(Object path) { - this.typescriptConfigFilePath = requireNonNull(path); - replaceStep(createStep()); - return this; + return EslintFormatterStep.create( + devDependencies, + provisioner(), + project.getProjectDir(), + project.getBuildDir(), + new NpmPathResolver(npmFileOrNull(), npmrcFileOrNull(), project.getProjectDir(), project.getRootDir()), + eslintConfig()); } - @Override protected EslintConfig eslintConfig() { - EslintConfig config = super.eslintConfig(); - return new EslintTypescriptConfig(config.getEslintConfigPath(), config.getEslintConfigJs(), typescriptConfigFilePath != null ? getProject().file(typescriptConfigFilePath) : null); + return new EslintTypescriptConfig( + configFilePath != null ? getProject().file(configFilePath) : null, + configJs, + typescriptConfigFilePath != null ? getProject().file(typescriptConfigFilePath) : null); } } @Override protected void setupTask(SpotlessTask task) { - // defaults to all typescript files if (target == null) { throw noDefaultTargetException(); } diff --git a/testlib/src/test/java/com/diffplug/spotless/npm/EslintFormatterStepTest.java b/testlib/src/test/java/com/diffplug/spotless/npm/EslintFormatterStepTest.java index 3a8bfc7fd6..95298db0ea 100644 --- a/testlib/src/test/java/com/diffplug/spotless/npm/EslintFormatterStepTest.java +++ b/testlib/src/test/java/com/diffplug/spotless/npm/EslintFormatterStepTest.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. @@ -15,20 +15,20 @@ */ package com.diffplug.spotless.npm; -import com.diffplug.common.collect.ImmutableMap; -import com.diffplug.spotless.FormatterStep; -import com.diffplug.spotless.StepHarnessWithFile; -import com.diffplug.spotless.TestProvisioner; -import com.diffplug.spotless.tag.NpmTest; +import java.io.File; +import java.util.Map; +import java.util.TreeMap; import org.junit.jupiter.api.Nested; import org.junit.jupiter.api.Test; import org.junit.jupiter.params.ParameterizedTest; import org.junit.jupiter.params.provider.ValueSource; -import java.io.File; -import java.util.Map; -import java.util.TreeMap; +import com.diffplug.common.collect.ImmutableMap; +import com.diffplug.spotless.FormatterStep; +import com.diffplug.spotless.StepHarnessWithFile; +import com.diffplug.spotless.TestProvisioner; +import com.diffplug.spotless.tag.NpmTest; @NpmTest class EslintFormatterStepTest { @@ -44,12 +44,11 @@ private final Map combine(Map m1, Map> devDependenciesForRuleset = ImmutableMap.of( - "custom_rules", EslintFormatterStep.defaultDevDependenciesForTypescript(), - "styleguide/airbnb", combine(EslintFormatterStep.defaultDevDependencies(), EslintFormatterStep.PopularStyleGuide.JS_AIRBNB.devDependencies()), - "styleguide/google", combine(EslintFormatterStep.defaultDevDependencies(), EslintFormatterStep.PopularStyleGuide.JS_GOOGLE.devDependencies()), - "styleguide/standard", combine(EslintFormatterStep.defaultDevDependencies(), EslintFormatterStep.PopularStyleGuide.JS_STANDARD.devDependencies()), - "styleguide/xo", combine(EslintFormatterStep.defaultDevDependencies(), EslintFormatterStep.PopularStyleGuide.JS_XO.devDependencies()) - ); + "custom_rules", EslintFormatterStep.defaultDevDependenciesForTypescript(), + "styleguide/airbnb", combine(EslintFormatterStep.defaultDevDependencies(), EslintFormatterStep.PopularStyleGuide.JS_AIRBNB.devDependencies()), + "styleguide/google", combine(EslintFormatterStep.defaultDevDependencies(), EslintFormatterStep.PopularStyleGuide.JS_GOOGLE.devDependencies()), + "styleguide/standard", combine(EslintFormatterStep.defaultDevDependencies(), EslintFormatterStep.PopularStyleGuide.JS_STANDARD.devDependencies()), + "styleguide/xo", combine(EslintFormatterStep.defaultDevDependencies(), EslintFormatterStep.PopularStyleGuide.JS_XO.devDependencies())); @ParameterizedTest(name = "{index}: eslint can be applied using ruleset {0}") @ValueSource(strings = {"custom_rules", "styleguide/airbnb", "styleguide/google", "styleguide/standard", "styleguide/xo"}) @@ -57,22 +56,22 @@ void formattingUsingRulesetsFile(String ruleSetName) throws Exception { String filedir = "npm/eslint/javascript/" + ruleSetName + "/"; String testDir = "formatting_ruleset_" + ruleSetName.replace('/', '_') + "/"; -// File testDirFile = newFolder(testDir); + // File testDirFile = newFolder(testDir); final File eslintRc = createTestFile(filedir + ".eslintrc.js"); -// final File eslintRc = setFile(buildDir().getPath() + "/.eslintrc.js").toResource(filedir + ".eslintrc.js"); + // final File eslintRc = setFile(buildDir().getPath() + "/.eslintrc.js").toResource(filedir + ".eslintrc.js"); final String dirtyFile = filedir + "javascript-es6.dirty"; File dirtyFileFile = setFile(testDir + "test.js").toResource(dirtyFile); final String cleanFile = filedir + "javascript-es6.clean"; final FormatterStep formatterStep = EslintFormatterStep.create( - devDependenciesForRuleset.get(ruleSetName), - TestProvisioner.mavenCentral(), - projectDir(), - buildDir(), - npmPathResolver(), - new EslintConfig(eslintRc, null)); + devDependenciesForRuleset.get(ruleSetName), + TestProvisioner.mavenCentral(), + projectDir(), + buildDir(), + npmPathResolver(), + new EslintConfig(eslintRc, null)); try (StepHarnessWithFile stepHarness = StepHarnessWithFile.forStep(formatterStep)) { stepHarness.testResource(dirtyFileFile, dirtyFile, cleanFile); @@ -80,19 +79,14 @@ void formattingUsingRulesetsFile(String ruleSetName) throws Exception { } } - - @NpmTest @Nested class EslintTypescriptFormattingStepTest extends NpmFormatterStepCommonTests { private final Map> devDependenciesForRuleset = ImmutableMap.of( - "custom_rules", EslintFormatterStep.defaultDevDependenciesForTypescript(), - "styleguide/standard_with_typescript", combine(EslintFormatterStep.defaultDevDependenciesForTypescript(), EslintFormatterStep.PopularStyleGuide.TS_STANDARD_WITH_TYPESCRIPT.devDependencies()), - "styleguide/xo", combine(EslintFormatterStep.defaultDevDependenciesForTypescript(), EslintFormatterStep.PopularStyleGuide.TS_XO_TYPESCRIPT.devDependencies()) - ); - - + "custom_rules", EslintFormatterStep.defaultDevDependenciesForTypescript(), + "styleguide/standard_with_typescript", combine(EslintFormatterStep.defaultDevDependenciesForTypescript(), EslintFormatterStep.PopularStyleGuide.TS_STANDARD_WITH_TYPESCRIPT.devDependencies()), + "styleguide/xo", combine(EslintFormatterStep.defaultDevDependenciesForTypescript(), EslintFormatterStep.PopularStyleGuide.TS_XO_TYPESCRIPT.devDependencies())); @ParameterizedTest(name = "{index}: eslint can be applied using ruleset {0}") @ValueSource(strings = {"custom_rules", "styleguide/standard_with_typescript", "styleguide/xo"}) @@ -100,10 +94,10 @@ void formattingUsingRulesetsFile(String ruleSetName) throws Exception { String filedir = "npm/eslint/typescript/" + ruleSetName + "/"; String testDir = "formatting_ruleset_" + ruleSetName.replace('/', '_') + "/"; -// File testDirFile = newFolder(testDir); + // File testDirFile = newFolder(testDir); final File eslintRc = createTestFile(filedir + ".eslintrc.js"); -// final File eslintRc = setFile(buildDir().getPath() + "/.eslintrc.js").toResource(filedir + ".eslintrc.js"); + // final File eslintRc = setFile(buildDir().getPath() + "/.eslintrc.js").toResource(filedir + ".eslintrc.js"); //setFile(testDir + "/test.ts").toResource(filedir + "typescript.dirty"); File tsconfigFile = null; @@ -115,12 +109,12 @@ void formattingUsingRulesetsFile(String ruleSetName) throws Exception { final String cleanFile = filedir + "typescript.clean"; final FormatterStep formatterStep = EslintFormatterStep.create( - devDependenciesForRuleset.get(ruleSetName), - TestProvisioner.mavenCentral(), - projectDir(), - buildDir(), - npmPathResolver(), - new EslintTypescriptConfig(eslintRc, null, tsconfigFile)); + devDependenciesForRuleset.get(ruleSetName), + TestProvisioner.mavenCentral(), + projectDir(), + buildDir(), + npmPathResolver(), + new EslintTypescriptConfig(eslintRc, null, tsconfigFile)); try (StepHarnessWithFile stepHarness = StepHarnessWithFile.forStep(formatterStep)) { stepHarness.testResource(dirtyFileFile, dirtyFile, cleanFile); @@ -132,42 +126,39 @@ void formattingUsingRulesetsFile(String ruleSetName) throws Exception { @Nested class EslintInlineConfigTypescriptFormattingStepTest extends NpmFormatterStepCommonTests { - @Test void formattingUsingInlineXoConfig() throws Exception { String filedir = "npm/eslint/typescript/standard_rules_xo/"; String testDir = "formatting_ruleset_xo_inline_config/"; - final String esLintConfig = String.join("\n", - "{", - " env: {", - " browser: true,", - " es2021: true,", - " },", - " extends: 'xo/browser',", - " overrides: [", - " {", - " extends: [", - " 'xo-typescript',", - " ],", - " files: [", - " '*.ts',", - " '*.tsx',", - " ],", - " },", - " ],", - " parser: '@typescript-eslint/parser',", - " parserOptions: {", - " ecmaVersion: 'latest',", - " sourceType: 'module',", - " project: './tsconfig.json',", - " },", - " rules: {", - " },", - "}" - ); + "{", + " env: {", + " browser: true,", + " es2021: true,", + " },", + " extends: 'xo/browser',", + " overrides: [", + " {", + " extends: [", + " 'xo-typescript',", + " ],", + " files: [", + " '*.ts',", + " '*.tsx',", + " ],", + " },", + " ],", + " parser: '@typescript-eslint/parser',", + " parserOptions: {", + " ecmaVersion: 'latest',", + " sourceType: 'module',", + " project: './tsconfig.json',", + " },", + " rules: {", + " },", + "}"); File tsconfigFile = setFile(testDir + "tsconfig.json").toResource(filedir + "tsconfig.json"); final String dirtyFile = filedir + "typescript.dirty"; @@ -175,12 +166,12 @@ void formattingUsingInlineXoConfig() throws Exception { final String cleanFile = filedir + "typescript.clean"; final FormatterStep formatterStep = EslintFormatterStep.create( - combine(EslintFormatterStep.PopularStyleGuide.TS_XO_TYPESCRIPT.devDependencies(), EslintFormatterStep.defaultDevDependenciesForTypescript()), - TestProvisioner.mavenCentral(), - projectDir(), - buildDir(), - npmPathResolver(), - new EslintTypescriptConfig(null, esLintConfig, tsconfigFile)); + combine(EslintFormatterStep.PopularStyleGuide.TS_XO_TYPESCRIPT.devDependencies(), EslintFormatterStep.defaultDevDependenciesForTypescript()), + TestProvisioner.mavenCentral(), + projectDir(), + buildDir(), + npmPathResolver(), + new EslintTypescriptConfig(null, esLintConfig, tsconfigFile)); try (StepHarnessWithFile stepHarness = StepHarnessWithFile.forStep(formatterStep)) { stepHarness.testResource(dirtyFileFile, dirtyFile, cleanFile); diff --git a/testlib/src/test/java/com/diffplug/spotless/npm/NpmFormatterStepCommonTests.java b/testlib/src/test/java/com/diffplug/spotless/npm/NpmFormatterStepCommonTests.java index f1b5da59ff..1ed6e9bbe8 100644 --- a/testlib/src/test/java/com/diffplug/spotless/npm/NpmFormatterStepCommonTests.java +++ b/testlib/src/test/java/com/diffplug/spotless/npm/NpmFormatterStepCommonTests.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. diff --git a/testlib/src/test/java/com/diffplug/spotless/npm/TsFmtFormatterStepTest.java b/testlib/src/test/java/com/diffplug/spotless/npm/TsFmtFormatterStepTest.java index d06b902b83..474c664486 100644 --- a/testlib/src/test/java/com/diffplug/spotless/npm/TsFmtFormatterStepTest.java +++ b/testlib/src/test/java/com/diffplug/spotless/npm/TsFmtFormatterStepTest.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. From 0206246cee0de58aac3b3477da69f98d8b1c2426 Mon Sep 17 00:00:00 2001 From: Simon Gamma Date: Tue, 20 Dec 2022 19:38:34 +0100 Subject: [PATCH 428/757] eslint: adding tests for js --- .../diffplug/spotless/npm/EslintConfig.java | 7 + .../spotless/npm/EslintFormatterStep.java | 4 +- .../gradle/spotless/JavascriptExtension.java | 61 ++++- .../spotless/JavascriptExtensionTest.java | 221 ++++++++++++++++++ .../spotless/TypescriptExtensionTest.java | 25 +- 5 files changed, 312 insertions(+), 6 deletions(-) create mode 100644 plugin-gradle/src/test/java/com/diffplug/gradle/spotless/JavascriptExtensionTest.java diff --git a/lib/src/main/java/com/diffplug/spotless/npm/EslintConfig.java b/lib/src/main/java/com/diffplug/spotless/npm/EslintConfig.java index 732111cc71..4e1848856a 100644 --- a/lib/src/main/java/com/diffplug/spotless/npm/EslintConfig.java +++ b/lib/src/main/java/com/diffplug/spotless/npm/EslintConfig.java @@ -62,4 +62,11 @@ public File getEslintConfigPath() { public String getEslintConfigJs() { return eslintConfigJs; } + + public EslintConfig verify() { + if (eslintConfigPath == null && eslintConfigJs == null) { + throw new IllegalArgumentException("ESLint must be configured using either a configFile or a configJs - but both are null."); + } + return this; + } } diff --git a/lib/src/main/java/com/diffplug/spotless/npm/EslintFormatterStep.java b/lib/src/main/java/com/diffplug/spotless/npm/EslintFormatterStep.java index 14bc99a243..0e5e618e1e 100644 --- a/lib/src/main/java/com/diffplug/spotless/npm/EslintFormatterStep.java +++ b/lib/src/main/java/com/diffplug/spotless/npm/EslintFormatterStep.java @@ -183,14 +183,14 @@ private static class State extends NpmFormatterStepStateBase implements Serializ private EslintConfig localCopyFiles(EslintConfig orig) { if (orig.getEslintConfigPath() == null) { - return orig; + return orig.verify(); } // If any config files are provided, we need to make sure they are at the same location as the node modules // as eslint will try to resolve plugin/config names relatively to the config file location and some // eslint configs contain relative paths to additional config files (such as tsconfig.json e.g.) FormattedPrinter.SYSOUT.print("Copying config file <%s> to <%s> and using the copy", orig.getEslintConfigPath(), nodeModulesDir); File configFileCopy = NpmResourceHelper.copyFileToDir(orig.getEslintConfigPath(), nodeModulesDir); - return orig.withEslintConfigPath(configFileCopy); + return orig.withEslintConfigPath(configFileCopy).verify(); } @Override diff --git a/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/JavascriptExtension.java b/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/JavascriptExtension.java index 348ed5f37e..fb05387f49 100644 --- a/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/JavascriptExtension.java +++ b/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/JavascriptExtension.java @@ -18,6 +18,7 @@ import static java.util.Objects.requireNonNull; import java.util.Arrays; +import java.util.Collections; import java.util.LinkedHashMap; import java.util.Map; import java.util.function.Consumer; @@ -28,11 +29,13 @@ import org.gradle.api.Project; +import com.diffplug.common.collect.ImmutableList; import com.diffplug.spotless.FormatterStep; import com.diffplug.spotless.npm.EslintConfig; import com.diffplug.spotless.npm.EslintFormatterStep; import com.diffplug.spotless.npm.EslintFormatterStep.PopularStyleGuide; import com.diffplug.spotless.npm.NpmPathResolver; +import com.diffplug.spotless.npm.PrettierFormatterStep; public class JavascriptExtension extends FormatExtension { @@ -57,8 +60,6 @@ public JavascriptEslintConfig eslint(Map devDependencies) { return eslint; } - // TODO: make the configs static so that they do not need to have a hierarchy symmetric to the extensions - public static abstract class EslintBaseConfig> extends NpmStepConfig> { Map devDependencies = new LinkedHashMap<>(); @@ -146,6 +147,62 @@ protected EslintConfig eslintConfig() { } } + /** Uses the default version of prettier. */ + @Override + public PrettierConfig prettier() { + return prettier(PrettierFormatterStep.defaultDevDependencies()); + } + + /** Uses the specified version of prettier. */ + @Override + public PrettierConfig prettier(String version) { + return prettier(PrettierFormatterStep.defaultDevDependenciesWithPrettier(version)); + } + + /** Uses exactly the npm packages specified in the map. */ + @Override + public PrettierConfig prettier(Map devDependencies) { + PrettierConfig prettierConfig = new JavascriptPrettierConfig(devDependencies); + addStep(prettierConfig.createStep()); + return prettierConfig; + } + + private static final String DEFAULT_PRETTIER_JS_PARSER = "babel"; + private static final ImmutableList PRETTIER_JS_PARSERS = ImmutableList.of(DEFAULT_PRETTIER_JS_PARSER, "babel-flow", "flow"); + + /** + * Overrides the parser to be set to a js parser. + */ + public class JavascriptPrettierConfig extends PrettierConfig { + + JavascriptPrettierConfig(Map devDependencies) { + super(devDependencies); + } + + @Override + protected FormatterStep createStep() { + fixParserToJavascript(); + return super.createStep(); + } + + private void fixParserToJavascript() { + if (this.prettierConfig == null) { + this.prettierConfig = Collections.singletonMap("parser", DEFAULT_PRETTIER_JS_PARSER); + } else { + final Object currentParser = this.prettierConfig.get("parser"); + if (PRETTIER_JS_PARSERS.contains(String.valueOf(currentParser))) { + getProject().getLogger().debug("Already javascript parser set, not overriding."); + } else { + this.prettierConfig.put("parser", DEFAULT_PRETTIER_JS_PARSER); + if (currentParser != null) { + getProject().getLogger().warn("Overriding parser option to '{}'. (Was set to '{}'.) Set it to another js parser if you have problems with '{}'.", DEFAULT_PRETTIER_JS_PARSER, currentParser, DEFAULT_PRETTIER_JS_PARSER); + } + } + + } + } + } + @Override protected void setupTask(SpotlessTask task) { if (target == null) { diff --git a/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/JavascriptExtensionTest.java b/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/JavascriptExtensionTest.java new file mode 100644 index 0000000000..af203936f3 --- /dev/null +++ b/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/JavascriptExtensionTest.java @@ -0,0 +1,221 @@ +/* + * 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. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.diffplug.gradle.spotless; + +import java.io.IOException; + +import org.assertj.core.api.Assertions; +import org.gradle.testkit.runner.BuildResult; +import org.junit.jupiter.api.Nested; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.ValueSource; + +import com.diffplug.spotless.tag.NpmTest; + +@NpmTest +class JavascriptExtensionTest extends GradleIntegrationHarness { + + @NpmTest + @Nested + class EslintGeneralJavascriptTests extends GradleIntegrationHarness { + @Test + void supportsEslintFormattingForJavascript() throws IOException { + setFile(".eslintrc.js").toResource("npm/eslint/javascript/styleguide/standard/.eslintrc.js"); + setFile("build.gradle").toLines( + "plugins {", + " id 'com.diffplug.spotless'", + "}", + "repositories { mavenCentral() }", + "spotless {", + " javascript {", + " target 'test.js'", + " eslint().configFile('.eslintrc.js').styleGuide('standard')", + " }", + "}"); + setFile("test.js").toResource("npm/eslint/javascript/styleguide/standard/javascript-es6.dirty"); + gradleRunner().withArguments("--stacktrace", "spotlessApply").build(); + assertFile("test.js").sameAsResource("npm/eslint/javascript/styleguide/standard/javascript-es6.clean"); + } + + @Test + void eslintDoesNotAllowToUseTsStyleGuideForJavascript() throws IOException { + setFile(".eslintrc.js").toResource("npm/eslint/javascript/styleguide/standard/.eslintrc.js"); + setFile("build.gradle").toLines( + "plugins {", + " id 'com.diffplug.spotless'", + "}", + "repositories { mavenCentral() }", + "spotless {", + " javascript {", + " target 'test.js'", + " eslint().configFile('.eslintrc.js').styleGuide('xo-typescript')", + " }", + "}"); + setFile("test.js").toResource("npm/eslint/javascript/styleguide/standard/javascript-es6.dirty"); + final BuildResult spotlessApply = gradleRunner().withArguments("--stacktrace", "spotlessApply").buildAndFail(); + Assertions.assertThat(spotlessApply.getOutput()).contains("Unknown style guide: xo-typescript"); + } + + @Test + void eslintAllowsToSpecifyEslintVersionForJavascript() throws IOException { + setFile(".eslintrc.js").toResource("npm/eslint/javascript/styleguide/standard/.eslintrc.js"); + setFile("build.gradle").toLines( + "plugins {", + " id 'com.diffplug.spotless'", + "}", + "repositories { mavenCentral() }", + "spotless {", + " javascript {", + " target 'test.js'", + " eslint('8.28.0').configFile('.eslintrc.js').styleGuide('standard')", + " }", + "}"); + setFile("test.js").toResource("npm/eslint/javascript/styleguide/standard/javascript-es6.dirty"); + gradleRunner().withArguments("--stacktrace", "spotlessApply").build(); + assertFile("test.js").sameAsResource("npm/eslint/javascript/styleguide/standard/javascript-es6.clean"); + } + + @Test + void esllintAllowsToSpecifyInlineConfig() throws IOException { + final String eslintConfigJs = String.join("\n", + "{", + " env: {", + " browser: true,", + " es2021: true", + " },", + " extends: 'standard',", + " overrides: [", + " ],", + " parserOptions: {", + " ecmaVersion: 'latest',", + " sourceType: 'module'", + " },", + " rules: {", + " }", + "}"); + setFile("build.gradle").toLines( + "plugins {", + " id 'com.diffplug.spotless'", + "}", + "repositories { mavenCentral() }", + "spotless {", + " javascript {", + " target 'test.js'", + " eslint().configJs('''" + eslintConfigJs + "''').styleGuide('standard')", + " }", + "}"); + setFile("test.js").toResource("npm/eslint/javascript/styleguide/standard/javascript-es6.dirty"); + gradleRunner().withArguments("--stacktrace", "spotlessApply").build(); + assertFile("test.js").sameAsResource("npm/eslint/javascript/styleguide/standard/javascript-es6.clean"); + } + + @Test + void eslintRequiresAnExplicitEslintConfig() throws IOException { + setFile(".eslintrc.js").toResource("npm/eslint/javascript/styleguide/standard/.eslintrc.js"); + setFile("build.gradle").toLines( + "plugins {", + " id 'com.diffplug.spotless'", + "}", + "repositories { mavenCentral() }", + "spotless {", + " javascript {", + " target 'test.js'", + " eslint().styleGuide('standard')", + " }", + "}"); + setFile("test.js").toResource("npm/eslint/javascript/styleguide/standard/javascript-es6.dirty"); + BuildResult spotlessApply = gradleRunner().withArguments("--stacktrace", "spotlessApply").buildAndFail(); + Assertions.assertThat(spotlessApply.getOutput()).contains("ESLint must be configured"); + } + + @Test + void eslintAllowsSpecifyingCustomLibraryVersions() throws IOException { + setFile(".eslintrc.js").toResource("npm/eslint/javascript/styleguide/standard/.eslintrc.js"); + setFile("build.gradle").toLines( + "plugins {", + " id 'com.diffplug.spotless'", + "}", + "repositories { mavenCentral() }", + "spotless {", + " javascript {", + " target 'test.js'", + " eslint([", + " 'eslint': '8.28.0',", + " 'eslint-config-standard': '17.0.0',", + " 'eslint-plugin-import': '2.26.0',", + " 'eslint-plugin-n': '15.6.0',", + " 'eslint-plugin-promise': '6.1.1'", + " ]).configFile('.eslintrc.js')", + " }", + "}"); + setFile("test.js").toResource("npm/eslint/javascript/styleguide/standard/javascript-es6.dirty"); + gradleRunner().withArguments("--stacktrace", "spotlessApply").build(); + assertFile("test.js").sameAsResource("npm/eslint/javascript/styleguide/standard/javascript-es6.clean"); + } + + } + + @NpmTest + @Nested + class EslintPopularJsStyleGuideTests extends GradleIntegrationHarness { + @ParameterizedTest(name = "{index}: eslint can be applied using styleguide {0}") + @ValueSource(strings = {"airbnb", "google", "standard", "xo"}) + void formattingUsingStyleguide(String styleguide) throws Exception { + + final String styleguidePath = "npm/eslint/javascript/styleguide/" + styleguide + "/"; + + setFile(".eslintrc.js").toResource(styleguidePath + ".eslintrc.js"); + setFile("build.gradle").toLines( + "plugins {", + " id 'com.diffplug.spotless'", + "}", + "repositories { mavenCentral() }", + "spotless {", + " javascript {", + " target 'test.js'", + " eslint().configFile('.eslintrc.js').styleGuide('" + styleguide + "')", + " }", + "}"); + setFile("test.js").toResource(styleguidePath + "javascript-es6.dirty"); + gradleRunner().withArguments("--stacktrace", "spotlessApply").build(); + assertFile("test.js").sameAsResource(styleguidePath + "javascript-es6.clean"); + } + } + + @NpmTest + @Nested + class JavascriptPrettierTests extends GradleIntegrationHarness { + @Test + void supportsPrettierFormattingForJavascript() throws IOException { + setFile("build.gradle").toLines( + "plugins {", + " id 'com.diffplug.spotless'", + "}", + "repositories { mavenCentral() }", + "spotless {", + " javascript {", + " target 'test.js'", + " prettier()", + " }", + "}"); + setFile("test.js").toResource("npm/prettier/filetypes/javascript-es6/javascript-es6.dirty"); + gradleRunner().withArguments("--stacktrace", "spotlessApply").build(); + assertFile("test.js").sameAsResource("npm/prettier/filetypes/javascript-es6/javascript-es6.clean"); + } + } + +} diff --git a/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/TypescriptExtensionTest.java b/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/TypescriptExtensionTest.java index 7d715998f6..da9fa03905 100644 --- a/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/TypescriptExtensionTest.java +++ b/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/TypescriptExtensionTest.java @@ -17,6 +17,8 @@ import java.io.IOException; +import org.assertj.core.api.Assertions; +import org.gradle.testkit.runner.BuildResult; import org.junit.jupiter.api.Test; import com.diffplug.spotless.tag.NpmTest; @@ -162,7 +164,7 @@ void useEslint() throws IOException { } @Test - void useXoStandardRules() throws IOException { + void useEslintXoStandardRules() throws IOException { setFile(".eslintrc.js").toResource("npm/eslint/typescript/styleguide/xo/.eslintrc.js"); setFile("tsconfig.json").toResource("npm/eslint/typescript/styleguide/xo/tsconfig.json"); setFile("build.gradle").toLines( @@ -182,7 +184,7 @@ void useXoStandardRules() throws IOException { } @Test - void useStandardWithTypescriptRules() throws IOException { + void useEslintStandardWithTypescriptRules() throws IOException { setFile(".eslintrc.js").toResource("npm/eslint/typescript/styleguide/standard_with_typescript/.eslintrc.js"); setFile("tsconfig.json").toResource("npm/eslint/typescript/styleguide/standard_with_typescript/tsconfig.json"); setFile("build.gradle").toLines( @@ -200,4 +202,23 @@ void useStandardWithTypescriptRules() throws IOException { gradleRunner().withArguments("--stacktrace", "spotlessApply").build(); assertFile("test.ts").sameAsResource("npm/eslint/typescript/styleguide/standard_with_typescript/typescript.clean"); } + + @Test + void useEslintForTypescriptDoesNotAllowUsingJsStyleguide() throws IOException { + setFile(".eslintrc.js").toResource("npm/eslint/javascript/styleguide/airbnb/.eslintrc.js"); + setFile("build.gradle").toLines( + "plugins {", + " id 'com.diffplug.spotless'", + "}", + "repositories { mavenCentral() }", + "spotless {", + " typescript {", + " target 'test.ts'", + " eslint().styleGuide('airbnb').configFile('.eslintrc.js')", + " }", + "}"); + setFile("test.js").toResource("npm/eslint/javascript/styleguide/airbnb/javascript-es6.dirty"); + BuildResult spotlessApply = gradleRunner().withArguments("--stacktrace", "spotlessApply").buildAndFail(); + Assertions.assertThat(spotlessApply.getOutput()).contains("Unknown style guide: airbnb"); + } } From 393a4c4424e66466cf1a698ab8716c331ec7e493 Mon Sep 17 00:00:00 2001 From: Simon Gamma Date: Tue, 20 Dec 2022 19:37:54 +0100 Subject: [PATCH 429/757] eslint: bumping version numbers --- .../spotless/npm/EslintFormatterStep.java | 37 +++++++++---------- 1 file changed, 18 insertions(+), 19 deletions(-) diff --git a/lib/src/main/java/com/diffplug/spotless/npm/EslintFormatterStep.java b/lib/src/main/java/com/diffplug/spotless/npm/EslintFormatterStep.java index 0e5e618e1e..8589819540 100644 --- a/lib/src/main/java/com/diffplug/spotless/npm/EslintFormatterStep.java +++ b/lib/src/main/java/com/diffplug/spotless/npm/EslintFormatterStep.java @@ -45,18 +45,17 @@ public class EslintFormatterStep { public static final String NAME = "eslint-format"; - public static final String DEFAULT_ESLINT_VERSION = "8.28.0"; + public static final String DEFAULT_ESLINT_VERSION = "^8.30.0"; public enum PopularStyleGuide { TS_STANDARD_WITH_TYPESCRIPT("standard-with-typescript") { @Override public Map devDependencies() { Map dependencies = new LinkedHashMap<>(); - dependencies.put("eslint-config-standard-with-typescript", "23.0.0"); - dependencies.put("eslint-plugin-import", "2.26.0"); - dependencies.put("eslint-plugin-n", "15.5.1"); - dependencies.put("eslint-plugin-promise", "6.1.1"); - dependencies.put("typescript", "4.9.3"); + dependencies.put("eslint-config-standard-with-typescript", "^24.0.0"); + dependencies.put("eslint-plugin-import", "^2.26.0"); + dependencies.put("eslint-plugin-n", "^15.6.0"); + dependencies.put("eslint-plugin-promise", "^6.1.1"); return dependencies; } }, @@ -64,9 +63,8 @@ public Map devDependencies() { @Override public Map devDependencies() { Map dependencies = new LinkedHashMap<>(); - dependencies.put("eslint-config-xo", "0.43.1"); - dependencies.put("eslint-config-xo-typescript", "0.55.1"); - dependencies.put("typescript", "4.9.3"); + dependencies.put("eslint-config-xo", "^0.43.1"); + dependencies.put("eslint-config-xo-typescript", "^0.55.1"); return dependencies; } }, @@ -74,8 +72,8 @@ public Map devDependencies() { @Override public Map devDependencies() { Map dependencies = new LinkedHashMap<>(); - dependencies.put("eslint-config-airbnb-base", "15.0.0"); - dependencies.put("eslint-plugin-import", "2.26.0"); + dependencies.put("eslint-config-airbnb-base", "^15.0.0"); + dependencies.put("eslint-plugin-import", "^2.26.0"); return dependencies; } }, @@ -83,7 +81,7 @@ public Map devDependencies() { @Override public Map devDependencies() { Map dependencies = new LinkedHashMap<>(); - dependencies.put("eslint-config-google", "0.14.0"); + dependencies.put("eslint-config-google", "^0.14.0"); return dependencies; } }, @@ -91,10 +89,10 @@ public Map devDependencies() { @Override public Map devDependencies() { Map dependencies = new LinkedHashMap<>(); - dependencies.put("eslint-config-standard", "17.0.0"); - dependencies.put("eslint-plugin-import", "2.26.0"); - dependencies.put("eslint-plugin-n", "15.6.0"); - dependencies.put("eslint-plugin-promise", "6.1.1"); + dependencies.put("eslint-config-standard", "^17.0.0"); + dependencies.put("eslint-plugin-import", "^2.26.0"); + dependencies.put("eslint-plugin-n", "^15.6.0"); + dependencies.put("eslint-plugin-promise", "^6.1.1"); return dependencies; } }, @@ -102,7 +100,7 @@ public Map devDependencies() { @Override public Map devDependencies() { Map dependencies = new LinkedHashMap<>(); - dependencies.put("eslint-config-xo", "0.43.1"); + dependencies.put("eslint-config-xo", "^0.43.1"); return dependencies; } }; @@ -135,8 +133,9 @@ public static Map defaultDevDependenciesForTypescript() { public static Map defaultDevDependenciesTypescriptWithEslint(String eslintVersion) { Map dependencies = new LinkedHashMap<>(); - dependencies.put("@typescript-eslint/eslint-plugin", "5.45.0"); - dependencies.put("@typescript-eslint/parser", "5.45.0"); + dependencies.put("@typescript-eslint/eslint-plugin", "^5.47.0"); + dependencies.put("@typescript-eslint/parser", "^5.47.0"); + dependencies.put("typescript", "^4.9.4"); dependencies.put("eslint", Objects.requireNonNull(eslintVersion)); return dependencies; } From 8dc740ef3723d38687222c2dfcd9b68bae3edce0 Mon Sep 17 00:00:00 2001 From: Simon Gamma Date: Tue, 20 Dec 2022 19:53:57 +0100 Subject: [PATCH 430/757] eslint: adapt to extended api on maven side --- .../java/com/diffplug/spotless/maven/generic/Prettier.java | 7 ++++--- .../java/com/diffplug/spotless/maven/typescript/Tsfmt.java | 7 ++++--- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/plugin-maven/src/main/java/com/diffplug/spotless/maven/generic/Prettier.java b/plugin-maven/src/main/java/com/diffplug/spotless/maven/generic/Prettier.java index 85684e85cd..5bdce32c47 100644 --- a/plugin-maven/src/main/java/com/diffplug/spotless/maven/generic/Prettier.java +++ b/plugin-maven/src/main/java/com/diffplug/spotless/maven/generic/Prettier.java @@ -1,5 +1,5 @@ /* - * Copyright 2016-2020 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. @@ -105,8 +105,9 @@ public FormatterStep newFormatterStep(FormatterStepConfig stepConfig) { // create the format step PrettierConfig prettierConfig = new PrettierConfig(configFileHandler, configInline); File buildDir = stepConfig.getFileLocator().getBuildDir(); - NpmPathResolver npmPathResolver = new NpmPathResolver(npm, npmrcFile, stepConfig.getFileLocator().getBaseDir()); - return PrettierFormatterStep.create(devDependencies, stepConfig.getProvisioner(), buildDir, npmPathResolver, prettierConfig); + File baseDir = stepConfig.getFileLocator().getBaseDir(); + NpmPathResolver npmPathResolver = new NpmPathResolver(npm, npmrcFile, baseDir); + return PrettierFormatterStep.create(devDependencies, stepConfig.getProvisioner(), baseDir, buildDir, npmPathResolver, prettierConfig); } private boolean moreThanOneNonNull(Object... objects) { diff --git a/plugin-maven/src/main/java/com/diffplug/spotless/maven/typescript/Tsfmt.java b/plugin-maven/src/main/java/com/diffplug/spotless/maven/typescript/Tsfmt.java index 9ebb9ac503..e41231818c 100644 --- a/plugin-maven/src/main/java/com/diffplug/spotless/maven/typescript/Tsfmt.java +++ b/plugin-maven/src/main/java/com/diffplug/spotless/maven/typescript/Tsfmt.java @@ -1,5 +1,5 @@ /* - * Copyright 2016-2020 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. @@ -120,8 +120,9 @@ public FormatterStep newFormatterStep(FormatterStepConfig stepConfig) { } File buildDir = stepConfig.getFileLocator().getBuildDir(); - NpmPathResolver npmPathResolver = new NpmPathResolver(npm, npmrcFile, stepConfig.getFileLocator().getBaseDir()); - return TsFmtFormatterStep.create(devDependencies, stepConfig.getProvisioner(), buildDir, npmPathResolver, configFile, configInline); + File baseDir = stepConfig.getFileLocator().getBaseDir(); + NpmPathResolver npmPathResolver = new NpmPathResolver(npm, npmrcFile, baseDir); + return TsFmtFormatterStep.create(devDependencies, stepConfig.getProvisioner(), baseDir, buildDir, npmPathResolver, configFile, configInline); } private static IllegalArgumentException onlyOneConfig() { From cb3dd5536febc8fccb0b71ee1103225d6fd9eafb Mon Sep 17 00:00:00 2001 From: Simon Gamma Date: Wed, 21 Dec 2022 16:28:32 +0100 Subject: [PATCH 431/757] eslint: speedup npm install --- lib/src/main/java/com/diffplug/spotless/npm/NpmProcess.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/src/main/java/com/diffplug/spotless/npm/NpmProcess.java b/lib/src/main/java/com/diffplug/spotless/npm/NpmProcess.java index e1bf8c8673..28db79b726 100644 --- a/lib/src/main/java/com/diffplug/spotless/npm/NpmProcess.java +++ b/lib/src/main/java/com/diffplug/spotless/npm/NpmProcess.java @@ -1,5 +1,5 @@ /* - * Copyright 2016-2020 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. @@ -34,7 +34,7 @@ class NpmProcess { } void install() { - npmAwait("install", "--no-audit", "--no-package-lock"); + npmAwait("install", "--no-audit", "--no-package-lock", "--prefer-offline"); } Process start() { From e12c5efb5f64b4133228e7d102baebd67191da32 Mon Sep 17 00:00:00 2001 From: Simon Gamma Date: Wed, 21 Dec 2022 16:31:18 +0100 Subject: [PATCH 432/757] eslint: speedup npmrc tests we intend them to timeout, but please fail quicker. --- .../gradle/spotless/PrettierIntegrationTest.java | 12 +++++++++--- .../maven/prettier/PrettierFormatStepTest.java | 14 +++++++++++--- .../maven/typescript/TypescriptFormatStepTest.java | 14 +++++++++++--- 3 files changed, 31 insertions(+), 9 deletions(-) diff --git a/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/PrettierIntegrationTest.java b/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/PrettierIntegrationTest.java index 404ccf88c8..6f55312bd5 100644 --- a/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/PrettierIntegrationTest.java +++ b/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/PrettierIntegrationTest.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. @@ -163,7 +163,10 @@ void usePhpCommunityPlugin() throws IOException { @Test void autodetectNpmrcFileConfig() throws IOException { setFile(".npmrc").toLines( - "registry=https://i.do.no.exist.com"); + "registry=https://i.do.not.exist.com", + "fetch-timeout=250", + "fetch-retry-mintimeout=250", + "fetch-retry-maxtimeout=250"); setFile("build.gradle").toLines( "plugins {", " id 'com.diffplug.spotless'", @@ -186,7 +189,10 @@ void autodetectNpmrcFileConfig() throws IOException { @Test void pickupNpmrcFileConfig() throws IOException { setFile(".custom_npmrc").toLines( - "registry=https://i.do.no.exist.com"); + "registry=https://i.do.not.exist.com", + "fetch-timeout=250", + "fetch-retry-mintimeout=250", + "fetch-retry-maxtimeout=250"); setFile("build.gradle").toLines( "plugins {", " id 'com.diffplug.spotless'", diff --git a/plugin-maven/src/test/java/com/diffplug/spotless/maven/prettier/PrettierFormatStepTest.java b/plugin-maven/src/test/java/com/diffplug/spotless/maven/prettier/PrettierFormatStepTest.java index 130bbde600..8fce61b5d8 100644 --- a/plugin-maven/src/test/java/com/diffplug/spotless/maven/prettier/PrettierFormatStepTest.java +++ b/plugin-maven/src/test/java/com/diffplug/spotless/maven/prettier/PrettierFormatStepTest.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. @@ -145,7 +145,11 @@ void autodetect_parser_based_on_filename() throws Exception { @Test void autodetect_npmrc_file() throws Exception { - setFile(".npmrc").toLines("registry=https://i.do.no.exist.com"); + setFile(".npmrc").toLines( + "registry=https://i.do.not.exist.com", + "fetch-timeout=250", + "fetch-retry-mintimeout=250", + "fetch-retry-maxtimeout=250"); String suffix = "ts"; writePomWithPrettierSteps("**/*." + suffix, "", @@ -158,7 +162,11 @@ void autodetect_npmrc_file() throws Exception { @Test void select_configured_npmrc_file() throws Exception { - setFile(".custom_npmrc").toLines("registry=https://i.do.no.exist.com"); + setFile(".custom_npmrc").toLines( + "registry=https://i.do.not.exist.com", + "fetch-timeout=250", + "fetch-retry-mintimeout=250", + "fetch-retry-maxtimeout=250"); String suffix = "ts"; writePomWithPrettierSteps("**/*." + suffix, "", diff --git a/plugin-maven/src/test/java/com/diffplug/spotless/maven/typescript/TypescriptFormatStepTest.java b/plugin-maven/src/test/java/com/diffplug/spotless/maven/typescript/TypescriptFormatStepTest.java index 600f9818d1..3b21f972ed 100644 --- a/plugin-maven/src/test/java/com/diffplug/spotless/maven/typescript/TypescriptFormatStepTest.java +++ b/plugin-maven/src/test/java/com/diffplug/spotless/maven/typescript/TypescriptFormatStepTest.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. @@ -114,7 +114,11 @@ void testTypescript_2_Configs() throws Exception { @Test void testNpmrcIsAutoPickedUp() throws Exception { - setFile(".npmrc").toLines("registry=https://i.do.no.exist.com"); + setFile(".npmrc").toLines( + "registry=https://i.do.not.exist.com", + "fetch-timeout=250", + "fetch-retry-mintimeout=250", + "fetch-retry-maxtimeout=250"); writePomWithTypescriptSteps( "", " ${basedir}/tslint.json", @@ -126,7 +130,11 @@ void testNpmrcIsAutoPickedUp() throws Exception { @Test void testNpmrcIsConfigurativelyPickedUp() throws Exception { - setFile(".custom_npmrc").toLines("registry=https://i.do.no.exist.com"); + setFile(".custom_npmrc").toLines( + "registry=https://i.do.not.exist.com", + "fetch-timeout=250", + "fetch-retry-mintimeout=250", + "fetch-retry-maxtimeout=250"); writePomWithTypescriptSteps( "", " ${basedir}/tslint.json", From 218db79b6ff8d0a1ea8c00a83cf38e21b8a19689 Mon Sep 17 00:00:00 2001 From: Simon Gamma Date: Wed, 21 Dec 2022 16:31:51 +0100 Subject: [PATCH 433/757] eslint: extract base properties to a common base class --- .../spotless/maven/generic/Prettier.java | 20 ++----- .../npm/AbstractNpmFormatterStepFactory.java | 55 +++++++++++++++++++ .../spotless/maven/typescript/Tsfmt.java | 20 ++----- 3 files changed, 65 insertions(+), 30 deletions(-) create mode 100644 plugin-maven/src/main/java/com/diffplug/spotless/maven/npm/AbstractNpmFormatterStepFactory.java diff --git a/plugin-maven/src/main/java/com/diffplug/spotless/maven/generic/Prettier.java b/plugin-maven/src/main/java/com/diffplug/spotless/maven/generic/Prettier.java index 5bdce32c47..b45f802653 100644 --- a/plugin-maven/src/main/java/com/diffplug/spotless/maven/generic/Prettier.java +++ b/plugin-maven/src/main/java/com/diffplug/spotless/maven/generic/Prettier.java @@ -23,12 +23,12 @@ import com.diffplug.spotless.FormatterStep; import com.diffplug.spotless.maven.FormatterStepConfig; -import com.diffplug.spotless.maven.FormatterStepFactory; +import com.diffplug.spotless.maven.npm.AbstractNpmFormatterStepFactory; import com.diffplug.spotless.npm.NpmPathResolver; import com.diffplug.spotless.npm.PrettierConfig; import com.diffplug.spotless.npm.PrettierFormatterStep; -public class Prettier implements FormatterStepFactory { +public class Prettier extends AbstractNpmFormatterStepFactory { public static final String ERROR_MESSAGE_ONLY_ONE_CONFIG = "must specify exactly one prettierVersion, devDependencies or devDependencyProperties"; @@ -47,12 +47,6 @@ public class Prettier implements FormatterStepFactory { @Parameter private String configFile; - @Parameter - private String npmExecutable; - - @Parameter - private String npmrc; - @Override public FormatterStep newFormatterStep(FormatterStepConfig stepConfig) { @@ -70,10 +64,6 @@ public FormatterStep newFormatterStep(FormatterStepConfig stepConfig) { this.devDependencies = dependencyPropertiesAsMap(); } - File npm = npmExecutable != null ? stepConfig.getFileLocator().locateFile(npmExecutable) : null; - - File npmrcFile = npmrc != null ? stepConfig.getFileLocator().locateFile(npmrc) : null; - // process config file or inline config File configFileHandler; if (this.configFile != null) { @@ -103,10 +93,10 @@ public FormatterStep newFormatterStep(FormatterStepConfig stepConfig) { } // create the format step + File baseDir = baseDir(stepConfig); + File buildDir = buildDir(stepConfig); PrettierConfig prettierConfig = new PrettierConfig(configFileHandler, configInline); - File buildDir = stepConfig.getFileLocator().getBuildDir(); - File baseDir = stepConfig.getFileLocator().getBaseDir(); - NpmPathResolver npmPathResolver = new NpmPathResolver(npm, npmrcFile, baseDir); + NpmPathResolver npmPathResolver = npmPathResolver(stepConfig); return PrettierFormatterStep.create(devDependencies, stepConfig.getProvisioner(), baseDir, buildDir, npmPathResolver, prettierConfig); } diff --git a/plugin-maven/src/main/java/com/diffplug/spotless/maven/npm/AbstractNpmFormatterStepFactory.java b/plugin-maven/src/main/java/com/diffplug/spotless/maven/npm/AbstractNpmFormatterStepFactory.java new file mode 100644 index 0000000000..8bc0f8f715 --- /dev/null +++ b/plugin-maven/src/main/java/com/diffplug/spotless/maven/npm/AbstractNpmFormatterStepFactory.java @@ -0,0 +1,55 @@ +/* + * 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. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.diffplug.spotless.maven.npm; + +import java.io.File; + +import org.apache.maven.plugins.annotations.Parameter; + +import com.diffplug.spotless.maven.FormatterStepConfig; +import com.diffplug.spotless.maven.FormatterStepFactory; +import com.diffplug.spotless.npm.NpmPathResolver; + +public abstract class AbstractNpmFormatterStepFactory implements FormatterStepFactory { + + @Parameter + private String npmExecutable; + + @Parameter + private String npmrc; + + protected File npm(FormatterStepConfig stepConfig) { + File npm = npmExecutable != null ? stepConfig.getFileLocator().locateFile(npmExecutable) : null; + return npm; + } + + protected File npmrc(FormatterStepConfig stepConfig) { + File npmrc = this.npmrc != null ? stepConfig.getFileLocator().locateFile(this.npmrc) : null; + return npmrc; + } + + protected File buildDir(FormatterStepConfig stepConfig) { + return stepConfig.getFileLocator().getBuildDir(); + } + + protected File baseDir(FormatterStepConfig stepConfig) { + return stepConfig.getFileLocator().getBaseDir(); + } + + protected NpmPathResolver npmPathResolver(FormatterStepConfig stepConfig) { + return new NpmPathResolver(npm(stepConfig), npmrc(stepConfig), baseDir(stepConfig)); + } +} diff --git a/plugin-maven/src/main/java/com/diffplug/spotless/maven/typescript/Tsfmt.java b/plugin-maven/src/main/java/com/diffplug/spotless/maven/typescript/Tsfmt.java index e41231818c..6c60c02cc6 100644 --- a/plugin-maven/src/main/java/com/diffplug/spotless/maven/typescript/Tsfmt.java +++ b/plugin-maven/src/main/java/com/diffplug/spotless/maven/typescript/Tsfmt.java @@ -23,13 +23,13 @@ import com.diffplug.spotless.FormatterStep; import com.diffplug.spotless.maven.FormatterStepConfig; -import com.diffplug.spotless.maven.FormatterStepFactory; +import com.diffplug.spotless.maven.npm.AbstractNpmFormatterStepFactory; import com.diffplug.spotless.npm.NpmPathResolver; import com.diffplug.spotless.npm.TsConfigFileType; import com.diffplug.spotless.npm.TsFmtFormatterStep; import com.diffplug.spotless.npm.TypedTsFmtConfigFile; -public class Tsfmt implements FormatterStepFactory { +public class Tsfmt extends AbstractNpmFormatterStepFactory { @Parameter private String tslintFile; @@ -52,12 +52,6 @@ public class Tsfmt implements FormatterStepFactory { @Parameter private String tslintVersion; - @Parameter - private String npmExecutable; - - @Parameter - private String npmrc; - @Parameter private Map config; @@ -74,10 +68,6 @@ public FormatterStep newFormatterStep(FormatterStepConfig stepConfig) { devDependencies.put("tslint", tslintVersion); } - File npm = npmExecutable != null ? stepConfig.getFileLocator().locateFile(npmExecutable) : null; - - File npmrcFile = npmrc != null ? stepConfig.getFileLocator().locateFile(npmrc) : null; - TypedTsFmtConfigFile configFile; Map configInline; // check that there is only 1 config file or inline config @@ -119,9 +109,9 @@ public FormatterStep newFormatterStep(FormatterStepConfig stepConfig) { throw onlyOneConfig(); } - File buildDir = stepConfig.getFileLocator().getBuildDir(); - File baseDir = stepConfig.getFileLocator().getBaseDir(); - NpmPathResolver npmPathResolver = new NpmPathResolver(npm, npmrcFile, baseDir); + File buildDir = buildDir(stepConfig); + File baseDir = baseDir(stepConfig); + NpmPathResolver npmPathResolver = npmPathResolver(stepConfig); return TsFmtFormatterStep.create(devDependencies, stepConfig.getProvisioner(), baseDir, buildDir, npmPathResolver, configFile, configInline); } From 31462a224d9b54c21ce75366e5d40ce5ea59f540 Mon Sep 17 00:00:00 2001 From: Simon Gamma Date: Thu, 22 Dec 2022 07:52:03 +0100 Subject: [PATCH 434/757] eslint: initial maven support --- .../spotless/npm/EslintFormatterStep.java | 25 +++-- .../gradle/spotless/JavascriptExtension.java | 14 +-- .../gradle/spotless/TypescriptExtension.java | 9 +- .../spotless/maven/AbstractSpotlessMojo.java | 4 + .../spotless/maven/javascript/EslintJs.java | 98 +++++++++++++++++++ .../spotless/maven/javascript/Javascript.java | 42 ++++++++ .../spotless/maven/typescript/EslintTs.java | 48 +++++++++ .../spotless/maven/typescript/Typescript.java | 8 +- .../spotless/npm/EslintFormatterStepTest.java | 2 +- 9 files changed, 221 insertions(+), 29 deletions(-) create mode 100644 plugin-maven/src/main/java/com/diffplug/spotless/maven/javascript/EslintJs.java create mode 100644 plugin-maven/src/main/java/com/diffplug/spotless/maven/javascript/Javascript.java create mode 100644 plugin-maven/src/main/java/com/diffplug/spotless/maven/typescript/EslintTs.java diff --git a/lib/src/main/java/com/diffplug/spotless/npm/EslintFormatterStep.java b/lib/src/main/java/com/diffplug/spotless/npm/EslintFormatterStep.java index 8589819540..820283aae4 100644 --- a/lib/src/main/java/com/diffplug/spotless/npm/EslintFormatterStep.java +++ b/lib/src/main/java/com/diffplug/spotless/npm/EslintFormatterStep.java @@ -20,12 +20,14 @@ import java.io.File; import java.io.IOException; import java.io.Serializable; +import java.util.Arrays; import java.util.Collections; import java.util.HashMap; import java.util.LinkedHashMap; import java.util.Map; import java.util.Objects; import java.util.TreeMap; +import java.util.function.Predicate; import javax.annotation.Nonnull; @@ -50,7 +52,7 @@ public class EslintFormatterStep { public enum PopularStyleGuide { TS_STANDARD_WITH_TYPESCRIPT("standard-with-typescript") { @Override - public Map devDependencies() { + public @Nonnull Map devDependencies() { Map dependencies = new LinkedHashMap<>(); dependencies.put("eslint-config-standard-with-typescript", "^24.0.0"); dependencies.put("eslint-plugin-import", "^2.26.0"); @@ -61,7 +63,7 @@ public Map devDependencies() { }, TS_XO_TYPESCRIPT("xo-typescript") { @Override - public Map devDependencies() { + public @Nonnull Map devDependencies() { Map dependencies = new LinkedHashMap<>(); dependencies.put("eslint-config-xo", "^0.43.1"); dependencies.put("eslint-config-xo-typescript", "^0.55.1"); @@ -70,7 +72,7 @@ public Map devDependencies() { }, JS_AIRBNB("airbnb") { @Override - public Map devDependencies() { + public @Nonnull Map devDependencies() { Map dependencies = new LinkedHashMap<>(); dependencies.put("eslint-config-airbnb-base", "^15.0.0"); dependencies.put("eslint-plugin-import", "^2.26.0"); @@ -79,7 +81,7 @@ public Map devDependencies() { }, JS_GOOGLE("google") { @Override - public Map devDependencies() { + public @Nonnull Map devDependencies() { Map dependencies = new LinkedHashMap<>(); dependencies.put("eslint-config-google", "^0.14.0"); return dependencies; @@ -87,7 +89,7 @@ public Map devDependencies() { }, JS_STANDARD("standard") { @Override - public Map devDependencies() { + public @Nonnull Map devDependencies() { Map dependencies = new LinkedHashMap<>(); dependencies.put("eslint-config-standard", "^17.0.0"); dependencies.put("eslint-plugin-import", "^2.26.0"); @@ -98,7 +100,7 @@ public Map devDependencies() { }, JS_XO("xo") { @Override - public Map devDependencies() { + public @Nonnull Map devDependencies() { Map dependencies = new LinkedHashMap<>(); dependencies.put("eslint-config-xo", "^0.43.1"); return dependencies; @@ -115,7 +117,7 @@ public String getPopularStyleGuideName() { return popularStyleGuideName; } - public abstract Map devDependencies(); + public abstract @Nonnull Map devDependencies(); public static PopularStyleGuide fromNameOrNull(String popularStyleGuideName) { for (PopularStyleGuide popularStyleGuide : PopularStyleGuide.values()) { @@ -125,6 +127,15 @@ public static PopularStyleGuide fromNameOrNull(String popularStyleGuideName) { } return null; } + + public static String getPopularStyleGuideNames(Predicate filter) { + // collect matching style guide names using stream + return Arrays.stream(PopularStyleGuide.values()) + .filter(filter) + .map(PopularStyleGuide::getPopularStyleGuideName) + .sorted() + .collect(java.util.stream.Collectors.joining(", ")); + } } public static Map defaultDevDependenciesForTypescript() { diff --git a/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/JavascriptExtension.java b/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/JavascriptExtension.java index fb05387f49..cbe0040a83 100644 --- a/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/JavascriptExtension.java +++ b/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/JavascriptExtension.java @@ -17,12 +17,10 @@ import static java.util.Objects.requireNonNull; -import java.util.Arrays; import java.util.Collections; import java.util.LinkedHashMap; import java.util.Map; import java.util.function.Consumer; -import java.util.stream.Collectors; import javax.annotation.Nullable; import javax.inject.Inject; @@ -100,9 +98,8 @@ public T styleGuide(String styleGuide) { PopularStyleGuide popularStyleGuide = PopularStyleGuide.fromNameOrNull(styleGuide); verifyStyleGuideIsSupported(styleGuide, popularStyleGuide); - devDependencies(popularStyleGuide.devDependencies()); - replaceStep(); - return (T) this; + assert popularStyleGuide != null; + return devDependencies(popularStyleGuide.devDependencies()); } protected abstract void verifyStyleGuideIsSupported(String styleGuideName, PopularStyleGuide popularStyleGuide); @@ -129,12 +126,7 @@ public FormatterStep createStep() { @Override protected void verifyStyleGuideIsSupported(String styleGuideName, PopularStyleGuide popularStyleGuide) { if (!isJsStyleGuide(popularStyleGuide)) { - throw new IllegalArgumentException("Unknown style guide: " + styleGuideName + ". Known javascript style guides: " - + Arrays.stream(PopularStyleGuide.values()) - .filter(this::isJsStyleGuide) - .map(PopularStyleGuide::getPopularStyleGuideName) - .sorted() - .collect(Collectors.joining(", "))); + throw new IllegalArgumentException("Unknown style guide: " + styleGuideName + ". Known javascript style guides: " + PopularStyleGuide.getPopularStyleGuideNames(this::isJsStyleGuide)); } } diff --git a/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/TypescriptExtension.java b/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/TypescriptExtension.java index f318dd89c8..79ae056bdc 100644 --- a/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/TypescriptExtension.java +++ b/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/TypescriptExtension.java @@ -17,12 +17,10 @@ import static java.util.Objects.requireNonNull; -import java.util.Arrays; import java.util.Collections; import java.util.Map; import java.util.Objects; import java.util.TreeMap; -import java.util.stream.Collectors; import javax.annotation.Nullable; import javax.inject.Inject; @@ -209,12 +207,7 @@ public TypescriptEslintConfig tsconfigFile(Object path) { @Override protected void verifyStyleGuideIsSupported(String styleGuideName, PopularStyleGuide popularStyleGuide) { if (!isTsStyleGuide(popularStyleGuide)) { - throw new IllegalArgumentException("Unknown style guide: " + styleGuideName + ". Known typescript style guides: " - + Arrays.stream(EslintFormatterStep.PopularStyleGuide.values()) - .filter(this::isTsStyleGuide) - .map(PopularStyleGuide::getPopularStyleGuideName) - .sorted() - .collect(Collectors.joining(", "))); + throw new IllegalArgumentException("Unknown style guide: " + styleGuideName + ". Known typescript style guides: " + PopularStyleGuide.getPopularStyleGuideNames(this::isTsStyleGuide)); } } diff --git a/plugin-maven/src/main/java/com/diffplug/spotless/maven/AbstractSpotlessMojo.java b/plugin-maven/src/main/java/com/diffplug/spotless/maven/AbstractSpotlessMojo.java index e4fdc7dcd0..f13f9b200d 100644 --- a/plugin-maven/src/main/java/com/diffplug/spotless/maven/AbstractSpotlessMojo.java +++ b/plugin-maven/src/main/java/com/diffplug/spotless/maven/AbstractSpotlessMojo.java @@ -64,6 +64,7 @@ import com.diffplug.spotless.maven.incremental.UpToDateChecker; import com.diffplug.spotless.maven.incremental.UpToDateChecking; import com.diffplug.spotless.maven.java.Java; +import com.diffplug.spotless.maven.javascript.Javascript; import com.diffplug.spotless.maven.kotlin.Kotlin; import com.diffplug.spotless.maven.markdown.Markdown; import com.diffplug.spotless.maven.pom.Pom; @@ -152,6 +153,9 @@ public abstract class AbstractSpotlessMojo extends AbstractMojo { @Parameter private Typescript typescript; + @Parameter + private Javascript javascript; + @Parameter private Antlr4 antlr4; diff --git a/plugin-maven/src/main/java/com/diffplug/spotless/maven/javascript/EslintJs.java b/plugin-maven/src/main/java/com/diffplug/spotless/maven/javascript/EslintJs.java new file mode 100644 index 0000000000..91de2136a1 --- /dev/null +++ b/plugin-maven/src/main/java/com/diffplug/spotless/maven/javascript/EslintJs.java @@ -0,0 +1,98 @@ +/* + * 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. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.diffplug.spotless.maven.javascript; + +import java.io.File; +import java.util.Map; +import java.util.TreeMap; + +import org.apache.maven.plugins.annotations.Parameter; + +import com.diffplug.spotless.FormatterStep; +import com.diffplug.spotless.maven.FormatterStepConfig; +import com.diffplug.spotless.maven.npm.AbstractNpmFormatterStepFactory; +import com.diffplug.spotless.npm.EslintConfig; +import com.diffplug.spotless.npm.EslintFormatterStep; +import com.diffplug.spotless.npm.NpmPathResolver; + +public class EslintJs extends AbstractNpmFormatterStepFactory { + + @Parameter + private String configFile; + + @Parameter + private String configJs; + + @Parameter + private String styleGuide; + + @Parameter + protected String eslintVersion; + + @Parameter + private Map devDependencies; + + @Override + public FormatterStep newFormatterStep(FormatterStepConfig stepConfig) { + Map devDependencies = new TreeMap<>(); + if (this.devDependencies != null) { + devDependencies.putAll(this.devDependencies); + } else { + Map defaultDependencies = createDefaultDependencies(); + devDependencies.putAll(defaultDependencies); + } + + addStyleGuideDevDependencies(devDependencies); + + File buildDir = buildDir(stepConfig); + File baseDir = baseDir(stepConfig); + NpmPathResolver npmPathResolver = npmPathResolver(stepConfig); + return EslintFormatterStep.create(devDependencies, stepConfig.getProvisioner(), baseDir, buildDir, npmPathResolver, eslintConfig(stepConfig)); + } + + protected EslintConfig eslintConfig(FormatterStepConfig stepConfig) { + return new EslintConfig(this.configFile != null ? stepConfig.getFileLocator().locateFile(this.configFile) : null, this.configJs); + } + + private void addStyleGuideDevDependencies(Map devDependencies) { + if (this.styleGuide != null) { + EslintFormatterStep.PopularStyleGuide styleGuide = EslintFormatterStep.PopularStyleGuide.valueOf(this.styleGuide); + validateStyleGuide(styleGuide); + devDependencies.putAll(styleGuide.devDependencies()); + } + } + + private void validateStyleGuide(EslintFormatterStep.PopularStyleGuide styleGuide) { + if (styleGuide == null) { + throw new IllegalArgumentException("StyleGuide '" + this.styleGuide + "' is not supported. Supported style guides: " + supportedStyleGuides()); + } + if (!isValidStyleGuide(styleGuide)) { + throw new IllegalArgumentException("StyleGuide must be of correct type but is: " + styleGuide + ". Use one of the following: " + supportedStyleGuides()); + } + } + + private String supportedStyleGuides() { + return EslintFormatterStep.PopularStyleGuide.getPopularStyleGuideNames(this::isValidStyleGuide); + } + + protected boolean isValidStyleGuide(EslintFormatterStep.PopularStyleGuide styleGuide) { + return styleGuide.name().startsWith("JS_"); + } + + protected Map createDefaultDependencies() { + return eslintVersion == null ? EslintFormatterStep.defaultDevDependencies() : EslintFormatterStep.defaultDevDependenciesWithEslint(eslintVersion); + } +} diff --git a/plugin-maven/src/main/java/com/diffplug/spotless/maven/javascript/Javascript.java b/plugin-maven/src/main/java/com/diffplug/spotless/maven/javascript/Javascript.java new file mode 100644 index 0000000000..db7049ff0d --- /dev/null +++ b/plugin-maven/src/main/java/com/diffplug/spotless/maven/javascript/Javascript.java @@ -0,0 +1,42 @@ +/* + * 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. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.diffplug.spotless.maven.javascript; + +import java.util.Collections; +import java.util.Set; + +import com.diffplug.spotless.maven.FormatterFactory; + +/** + * A {@link FormatterFactory} implementation that corresponds to {@code ...} configuration element. + *

+ * It defines a formatter for typescript source files. + */ +public class Javascript extends FormatterFactory { + @Override + public Set defaultIncludes() { + return Collections.emptySet(); + } + + @Override + public String licenseHeaderDelimiter() { + return null; + } + + public void addEslint(EslintJs eslint) { + addStepFactory(eslint); + } +} diff --git a/plugin-maven/src/main/java/com/diffplug/spotless/maven/typescript/EslintTs.java b/plugin-maven/src/main/java/com/diffplug/spotless/maven/typescript/EslintTs.java new file mode 100644 index 0000000000..0fe834ffde --- /dev/null +++ b/plugin-maven/src/main/java/com/diffplug/spotless/maven/typescript/EslintTs.java @@ -0,0 +1,48 @@ +/* + * Copyright 2022 DiffPlug + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.diffplug.spotless.maven.typescript; + +import java.util.Map; + +import org.apache.maven.plugins.annotations.Parameter; + +import com.diffplug.spotless.maven.FormatterStepConfig; +import com.diffplug.spotless.maven.javascript.EslintJs; +import com.diffplug.spotless.npm.EslintConfig; +import com.diffplug.spotless.npm.EslintFormatterStep; +import com.diffplug.spotless.npm.EslintTypescriptConfig; + +public class EslintTs extends EslintJs { + + @Parameter + private String tsconfigFile; + + @Override + protected EslintConfig eslintConfig(FormatterStepConfig stepConfig) { + EslintConfig jsConfig = super.eslintConfig(stepConfig); + return new EslintTypescriptConfig(jsConfig.getEslintConfigPath(), jsConfig.getEslintConfigJs(), tsconfigFile != null ? stepConfig.getFileLocator().locateFile(tsconfigFile) : null); + } + + @Override + protected boolean isValidStyleGuide(EslintFormatterStep.PopularStyleGuide styleGuide) { + return styleGuide.name().startsWith("TS_"); + } + + @Override + protected Map createDefaultDependencies() { + return this.eslintVersion == null ? EslintFormatterStep.defaultDevDependenciesForTypescript() : EslintFormatterStep.defaultDevDependenciesTypescriptWithEslint(this.eslintVersion); + } +} diff --git a/plugin-maven/src/main/java/com/diffplug/spotless/maven/typescript/Typescript.java b/plugin-maven/src/main/java/com/diffplug/spotless/maven/typescript/Typescript.java index da6e6ddd91..1320cac2d8 100644 --- a/plugin-maven/src/main/java/com/diffplug/spotless/maven/typescript/Typescript.java +++ b/plugin-maven/src/main/java/com/diffplug/spotless/maven/typescript/Typescript.java @@ -1,5 +1,5 @@ /* - * Copyright 2016-2020 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. @@ -23,7 +23,7 @@ /** * A {@link FormatterFactory} implementation that corresponds to {@code ...} configuration element. *

- * It defines a formatter for typescript source files. + * It defines formatters for typescript source files. */ public class Typescript extends FormatterFactory { @Override @@ -39,4 +39,8 @@ public String licenseHeaderDelimiter() { public void addTsfmt(Tsfmt tsfmt) { addStepFactory(tsfmt); } + + public void addEslint(EslintTs eslint) { + addStepFactory(eslint); + } } diff --git a/testlib/src/test/java/com/diffplug/spotless/npm/EslintFormatterStepTest.java b/testlib/src/test/java/com/diffplug/spotless/npm/EslintFormatterStepTest.java index 95298db0ea..15ebb0cc0d 100644 --- a/testlib/src/test/java/com/diffplug/spotless/npm/EslintFormatterStepTest.java +++ b/testlib/src/test/java/com/diffplug/spotless/npm/EslintFormatterStepTest.java @@ -128,7 +128,7 @@ class EslintInlineConfigTypescriptFormattingStepTest extends NpmFormatterStepCom @Test void formattingUsingInlineXoConfig() throws Exception { - String filedir = "npm/eslint/typescript/standard_rules_xo/"; + String filedir = "npm/eslint/typescript/styleguide/xo/"; String testDir = "formatting_ruleset_xo_inline_config/"; From dd5ae78fcd05300f64a6a85a1823402fe1891045 Mon Sep 17 00:00:00 2001 From: Simon Gamma Date: Thu, 22 Dec 2022 20:04:16 +0100 Subject: [PATCH 435/757] eslint: tests for maven integration into typescript --- .../com/diffplug/spotless/npm/eslint-serve.js | 2 +- .../spotless/maven/javascript/EslintJs.java | 4 +- .../maven/MavenIntegrationHarness.java | 4 +- .../typescript/TypescriptFormatStepTest.java | 107 +++++++++++++++--- 4 files changed, 96 insertions(+), 21 deletions(-) diff --git a/lib/src/main/resources/com/diffplug/spotless/npm/eslint-serve.js b/lib/src/main/resources/com/diffplug/spotless/npm/eslint-serve.js index b9f3207d5f..1f1b1fab5a 100644 --- a/lib/src/main/resources/com/diffplug/spotless/npm/eslint-serve.js +++ b/lib/src/main/resources/com/diffplug/spotless/npm/eslint-serve.js @@ -55,7 +55,7 @@ app.post("/eslint/format", async (req, res) => { // LintResult[] // https://eslint.org/docs/latest/developer-guide/nodejs-api#-lintresult-type const results = await eslint.lintText(format_data.file_content, lintTextOptions); if (results.length !== 1) { - res.status(501).send("Error while formatting: Unexpected number of results"); + res.status(501).send("Error while formatting: Unexpected number of results: " + JSON.stringify(results)); return; } const result = results[0]; diff --git a/plugin-maven/src/main/java/com/diffplug/spotless/maven/javascript/EslintJs.java b/plugin-maven/src/main/java/com/diffplug/spotless/maven/javascript/EslintJs.java index 91de2136a1..589e2f3f0c 100644 --- a/plugin-maven/src/main/java/com/diffplug/spotless/maven/javascript/EslintJs.java +++ b/plugin-maven/src/main/java/com/diffplug/spotless/maven/javascript/EslintJs.java @@ -69,7 +69,7 @@ protected EslintConfig eslintConfig(FormatterStepConfig stepConfig) { private void addStyleGuideDevDependencies(Map devDependencies) { if (this.styleGuide != null) { - EslintFormatterStep.PopularStyleGuide styleGuide = EslintFormatterStep.PopularStyleGuide.valueOf(this.styleGuide); + EslintFormatterStep.PopularStyleGuide styleGuide = EslintFormatterStep.PopularStyleGuide.fromNameOrNull(this.styleGuide); validateStyleGuide(styleGuide); devDependencies.putAll(styleGuide.devDependencies()); } @@ -80,7 +80,7 @@ private void validateStyleGuide(EslintFormatterStep.PopularStyleGuide styleGuide throw new IllegalArgumentException("StyleGuide '" + this.styleGuide + "' is not supported. Supported style guides: " + supportedStyleGuides()); } if (!isValidStyleGuide(styleGuide)) { - throw new IllegalArgumentException("StyleGuide must be of correct type but is: " + styleGuide + ". Use one of the following: " + supportedStyleGuides()); + throw new IllegalArgumentException("StyleGuide must be of correct type but is: " + styleGuide.getPopularStyleGuideName() + ". Use one of the following: " + supportedStyleGuides()); } } diff --git a/plugin-maven/src/test/java/com/diffplug/spotless/maven/MavenIntegrationHarness.java b/plugin-maven/src/test/java/com/diffplug/spotless/maven/MavenIntegrationHarness.java index 939940a315..61d9c80a37 100644 --- a/plugin-maven/src/test/java/com/diffplug/spotless/maven/MavenIntegrationHarness.java +++ b/plugin-maven/src/test/java/com/diffplug/spotless/maven/MavenIntegrationHarness.java @@ -136,8 +136,8 @@ protected void writePomWithCppSteps(String... steps) throws IOException { writePom(groupWithSteps("cpp", steps)); } - protected void writePomWithTypescriptSteps(String... steps) throws IOException { - writePom(groupWithSteps("typescript", including("**/*.ts"), steps)); + protected void writePomWithTypescriptSteps(String includes, String... steps) throws IOException { + writePom(groupWithSteps("typescript", including(includes), steps)); } protected void writePomWithSqlSteps(String... steps) throws IOException { diff --git a/plugin-maven/src/test/java/com/diffplug/spotless/maven/typescript/TypescriptFormatStepTest.java b/plugin-maven/src/test/java/com/diffplug/spotless/maven/typescript/TypescriptFormatStepTest.java index 3b21f972ed..b57a2a97a6 100644 --- a/plugin-maven/src/test/java/com/diffplug/spotless/maven/typescript/TypescriptFormatStepTest.java +++ b/plugin-maven/src/test/java/com/diffplug/spotless/maven/typescript/TypescriptFormatStepTest.java @@ -21,84 +21,95 @@ import org.junit.jupiter.api.Test; +import com.diffplug.spotless.ResourceHarness; import com.diffplug.spotless.maven.MavenIntegrationHarness; import com.diffplug.spotless.maven.MavenRunner.Result; import com.diffplug.spotless.tag.NpmTest; @NpmTest class TypescriptFormatStepTest extends MavenIntegrationHarness { - private void run(String kind) throws IOException, InterruptedException { - String path = prepareRun(kind); + + private static final String TEST_FILE_PATH = "src/main/typescript/test.ts"; + + private void runTsfmt(String kind) throws IOException, InterruptedException { + String path = prepareRunTsfmt(kind); mavenRunner().withArguments("spotless:apply").runNoError(); assertFile(path).sameAsResource("npm/tsfmt/" + kind + "/" + kind + ".clean"); } - private String prepareRun(String kind) throws IOException { - String path = "src/main/typescript/test.ts"; - setFile(path).toResource("npm/tsfmt/" + kind + "/" + kind + ".dirty"); - return path; + private String prepareRunTsfmt(String kind) throws IOException { + setFile(TEST_FILE_PATH).toResource("npm/tsfmt/" + kind + "/" + kind + ".dirty"); + return TEST_FILE_PATH; } - private Result runExpectingError(String kind) throws IOException, InterruptedException { - prepareRun(kind); + private Result runExpectingErrorTsfmt(String kind) throws IOException, InterruptedException { + prepareRunTsfmt(kind); return mavenRunner().withArguments("spotless:apply").runHasError(); } @Test void tslint() throws Exception { writePomWithTypescriptSteps( + TEST_FILE_PATH, "", " ${basedir}/tslint.json", ""); setFile("tslint.json").toResource("npm/tsfmt/tslint/tslint.json"); - run("tslint"); + runTsfmt("tslint"); } @Test void vscode() throws Exception { writePomWithTypescriptSteps( + TEST_FILE_PATH, "", " ${basedir}/vscode.json", ""); setFile("vscode.json").toResource("npm/tsfmt/vscode/vscode.json"); - run("vscode"); + runTsfmt("vscode"); } @Test void tsfmt() throws Exception { writePomWithTypescriptSteps( + TEST_FILE_PATH, "", " ${basedir}/tsfmt.json", ""); setFile("tsfmt.json").toResource("npm/tsfmt/tsfmt/tsfmt.json"); - run("tsfmt"); + runTsfmt("tsfmt"); } @Test void tsfmtInline() throws Exception { writePomWithTypescriptSteps( + TEST_FILE_PATH, "", " ", " 1", " true", " ", ""); - run("tsfmt"); + runTsfmt("tsfmt"); } @Test void tsconfig() throws Exception { writePomWithTypescriptSteps( + TEST_FILE_PATH, "", " ${project.basedir}/tsconfig.json", ""); setFile("tsconfig.json").toResource("npm/tsfmt/tsconfig/tsconfig.json"); - run("tsconfig"); + runTsfmt("tsconfig"); } @Test void testTypescript_2_Configs() throws Exception { + String path = "src/main/typescript/test.ts"; + writePomWithTypescriptSteps( + path, "", " ${basedir}/tslint.json", " ${basedir}/tslint.json", @@ -106,7 +117,6 @@ void testTypescript_2_Configs() throws Exception { setFile("vscode.json").toResource("npm/tsfmt/vscode/vscode.json"); setFile("tsfmt.json").toResource("npm/tsfmt/tsfmt/tsfmt.json"); - String path = "src/main/typescript/test.ts"; setFile(path).toResource("npm/tsfmt/tsfmt/tsfmt.dirty"); Result result = mavenRunner().withArguments("spotless:apply").runHasError(); assertThat(result.output()).contains("must specify exactly one configFile or config"); @@ -120,11 +130,12 @@ void testNpmrcIsAutoPickedUp() throws Exception { "fetch-retry-mintimeout=250", "fetch-retry-maxtimeout=250"); writePomWithTypescriptSteps( + TEST_FILE_PATH, "", " ${basedir}/tslint.json", ""); setFile("tslint.json").toResource("npm/tsfmt/tslint/tslint.json"); - Result result = runExpectingError("tslint"); + Result result = runExpectingErrorTsfmt("tslint"); assertThat(result.output()).containsPattern("Running npm command.*npm install.* failed with exit code: 1"); } @@ -136,12 +147,76 @@ void testNpmrcIsConfigurativelyPickedUp() throws Exception { "fetch-retry-mintimeout=250", "fetch-retry-maxtimeout=250"); writePomWithTypescriptSteps( + TEST_FILE_PATH, "", " ${basedir}/tslint.json", " ${basedir}/.custom_npmrc", ""); setFile("tslint.json").toResource("npm/tsfmt/tslint/tslint.json"); - Result result = runExpectingError("tslint"); + Result result = runExpectingErrorTsfmt("tslint"); assertThat(result.output()).containsPattern("Running npm command.*npm install.* failed with exit code: 1"); } + + @Test + void eslintConfigFile() throws Exception { + writePomWithTypescriptSteps( + TEST_FILE_PATH, + "", + " .eslintrc.js", + ""); + setFile(".eslintrc.js").toResource("npm/eslint/typescript/custom_rules/.eslintrc.js"); + setFile(TEST_FILE_PATH).toResource("npm/eslint/typescript/custom_rules/typescript.dirty"); + + mavenRunner().withArguments("spotless:apply").runNoError(); + assertFile(TEST_FILE_PATH).sameAsResource("npm/eslint/typescript/custom_rules/typescript.clean"); + } + + @Test + void eslintConfigJs() throws Exception { + final String configJs = ResourceHarness.getTestResource("npm/eslint/typescript/custom_rules/.eslintrc.js") + .replace("module.exports = ", ""); + writePomWithTypescriptSteps( + TEST_FILE_PATH, + "", + " " + configJs + "", + ""); + setFile(TEST_FILE_PATH).toResource("npm/eslint/typescript/custom_rules/typescript.dirty"); + + mavenRunner().withArguments("spotless:apply").runNoError(); + assertFile(TEST_FILE_PATH).sameAsResource("npm/eslint/typescript/custom_rules/typescript.clean"); + } + + @Test + void eslintStyleguideStandardWithTypescript() throws Exception { + writePomWithTypescriptSteps( + TEST_FILE_PATH, + "", + " .eslintrc.js", + " standard-with-typescript", + " ${basedir}/tsconfig.json", + ""); + setFile(".eslintrc.js").toResource("npm/eslint/typescript/styleguide/standard_with_typescript/.eslintrc.js"); + setFile("tsconfig.json").toResource("npm/eslint/typescript/styleguide/standard_with_typescript/tsconfig.json"); + setFile(TEST_FILE_PATH).toResource("npm/eslint/typescript/styleguide/standard_with_typescript/typescript.dirty"); + + mavenRunner().withArguments("spotless:apply").runNoError(); + assertFile(TEST_FILE_PATH).sameAsResource("npm/eslint/typescript/styleguide/standard_with_typescript/typescript.clean"); + } + + @Test + void eslintStyleguideXo() throws Exception { + writePomWithTypescriptSteps( + TEST_FILE_PATH, + "", + " .eslintrc.js", + " xo-typescript", + " ${basedir}/tsconfig.json", + ""); + setFile(".eslintrc.js").toResource("npm/eslint/typescript/styleguide/xo/.eslintrc.js"); + setFile("tsconfig.json").toResource("npm/eslint/typescript/styleguide/xo/tsconfig.json"); + setFile(TEST_FILE_PATH).toResource("npm/eslint/typescript/styleguide/xo/typescript.dirty"); + + mavenRunner().withArguments("spotless:apply").runNoError(); + assertFile(TEST_FILE_PATH).sameAsResource("npm/eslint/typescript/styleguide/xo/typescript.clean"); + } } From 7d2e5adc131e6458bb71e8e9cb694dffce1ae502 Mon Sep 17 00:00:00 2001 From: Simon Gamma Date: Fri, 23 Dec 2022 07:53:57 +0100 Subject: [PATCH 436/757] eslint: adding maven javascript tests --- .../spotless/maven/AbstractSpotlessMojo.java | 2 +- .../maven/javascript/AbstractEslint.java | 92 +++++++++++++++ .../spotless/maven/javascript/EslintJs.java | 65 +--------- .../spotless/maven/typescript/EslintTs.java | 10 +- .../maven/MavenIntegrationHarness.java | 4 + .../javascript/JavascriptFormatStepTest.java | 111 ++++++++++++++++++ 6 files changed, 216 insertions(+), 68 deletions(-) create mode 100644 plugin-maven/src/main/java/com/diffplug/spotless/maven/javascript/AbstractEslint.java create mode 100644 plugin-maven/src/test/java/com/diffplug/spotless/maven/javascript/JavascriptFormatStepTest.java diff --git a/plugin-maven/src/main/java/com/diffplug/spotless/maven/AbstractSpotlessMojo.java b/plugin-maven/src/main/java/com/diffplug/spotless/maven/AbstractSpotlessMojo.java index f13f9b200d..647535a590 100644 --- a/plugin-maven/src/main/java/com/diffplug/spotless/maven/AbstractSpotlessMojo.java +++ b/plugin-maven/src/main/java/com/diffplug/spotless/maven/AbstractSpotlessMojo.java @@ -335,7 +335,7 @@ private FileLocator getFileLocator() { } private List getFormatterFactories() { - return Stream.concat(formats.stream(), Stream.of(groovy, java, scala, kotlin, cpp, typescript, antlr4, pom, sql, python, markdown)) + return Stream.concat(formats.stream(), Stream.of(groovy, java, scala, kotlin, cpp, typescript, javascript, antlr4, pom, sql, python, markdown)) .filter(Objects::nonNull) .collect(toList()); } diff --git a/plugin-maven/src/main/java/com/diffplug/spotless/maven/javascript/AbstractEslint.java b/plugin-maven/src/main/java/com/diffplug/spotless/maven/javascript/AbstractEslint.java new file mode 100644 index 0000000000..735a25c0c5 --- /dev/null +++ b/plugin-maven/src/main/java/com/diffplug/spotless/maven/javascript/AbstractEslint.java @@ -0,0 +1,92 @@ +/* + * 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. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.diffplug.spotless.maven.javascript; + +import java.io.File; +import java.util.Map; +import java.util.TreeMap; + +import org.apache.maven.plugins.annotations.Parameter; + +import com.diffplug.spotless.FormatterStep; +import com.diffplug.spotless.maven.FormatterStepConfig; +import com.diffplug.spotless.maven.npm.AbstractNpmFormatterStepFactory; +import com.diffplug.spotless.npm.EslintConfig; +import com.diffplug.spotless.npm.EslintFormatterStep; +import com.diffplug.spotless.npm.NpmPathResolver; + +public abstract class AbstractEslint extends AbstractNpmFormatterStepFactory { + + @Parameter + protected String configFile; + + @Parameter + protected String configJs; + + @Parameter + protected String styleGuide; + + @Parameter + protected String eslintVersion; + + @Parameter + protected Map devDependencies; + + @Override + public FormatterStep newFormatterStep(FormatterStepConfig stepConfig) { + Map devDependencies = new TreeMap<>(); + if (this.devDependencies != null) { + devDependencies.putAll(this.devDependencies); + } else { + Map defaultDependencies = createDefaultDependencies(); + devDependencies.putAll(defaultDependencies); + } + + addStyleGuideDevDependencies(devDependencies); + + File buildDir = buildDir(stepConfig); + File baseDir = baseDir(stepConfig); + NpmPathResolver npmPathResolver = npmPathResolver(stepConfig); + return EslintFormatterStep.create(devDependencies, stepConfig.getProvisioner(), baseDir, buildDir, npmPathResolver, eslintConfig(stepConfig)); + } + + protected abstract EslintConfig eslintConfig(FormatterStepConfig stepConfig); + + private void addStyleGuideDevDependencies(Map devDependencies) { + if (this.styleGuide != null) { + EslintFormatterStep.PopularStyleGuide styleGuide = EslintFormatterStep.PopularStyleGuide.fromNameOrNull(this.styleGuide); + validateStyleGuide(styleGuide); + devDependencies.putAll(styleGuide.devDependencies()); + } + } + + private void validateStyleGuide(EslintFormatterStep.PopularStyleGuide styleGuide) { + if (styleGuide == null) { + throw new IllegalArgumentException("StyleGuide '" + this.styleGuide + "' is not supported. Supported style guides: " + supportedStyleGuides()); + } + if (!isValidStyleGuide(styleGuide)) { + throw new IllegalArgumentException("StyleGuide must be of correct type but is: " + styleGuide.getPopularStyleGuideName() + ". Use one of the following: " + supportedStyleGuides()); + } + } + + private String supportedStyleGuides() { + return EslintFormatterStep.PopularStyleGuide.getPopularStyleGuideNames(this::isValidStyleGuide); + } + + protected abstract boolean isValidStyleGuide(EslintFormatterStep.PopularStyleGuide styleGuide); + + protected abstract Map createDefaultDependencies(); +} diff --git a/plugin-maven/src/main/java/com/diffplug/spotless/maven/javascript/EslintJs.java b/plugin-maven/src/main/java/com/diffplug/spotless/maven/javascript/EslintJs.java index 589e2f3f0c..f6c7beaff4 100644 --- a/plugin-maven/src/main/java/com/diffplug/spotless/maven/javascript/EslintJs.java +++ b/plugin-maven/src/main/java/com/diffplug/spotless/maven/javascript/EslintJs.java @@ -15,84 +15,23 @@ */ package com.diffplug.spotless.maven.javascript; -import java.io.File; import java.util.Map; -import java.util.TreeMap; -import org.apache.maven.plugins.annotations.Parameter; - -import com.diffplug.spotless.FormatterStep; import com.diffplug.spotless.maven.FormatterStepConfig; -import com.diffplug.spotless.maven.npm.AbstractNpmFormatterStepFactory; import com.diffplug.spotless.npm.EslintConfig; import com.diffplug.spotless.npm.EslintFormatterStep; -import com.diffplug.spotless.npm.NpmPathResolver; - -public class EslintJs extends AbstractNpmFormatterStepFactory { - - @Parameter - private String configFile; - - @Parameter - private String configJs; - - @Parameter - private String styleGuide; - - @Parameter - protected String eslintVersion; - - @Parameter - private Map devDependencies; - - @Override - public FormatterStep newFormatterStep(FormatterStepConfig stepConfig) { - Map devDependencies = new TreeMap<>(); - if (this.devDependencies != null) { - devDependencies.putAll(this.devDependencies); - } else { - Map defaultDependencies = createDefaultDependencies(); - devDependencies.putAll(defaultDependencies); - } - addStyleGuideDevDependencies(devDependencies); - - File buildDir = buildDir(stepConfig); - File baseDir = baseDir(stepConfig); - NpmPathResolver npmPathResolver = npmPathResolver(stepConfig); - return EslintFormatterStep.create(devDependencies, stepConfig.getProvisioner(), baseDir, buildDir, npmPathResolver, eslintConfig(stepConfig)); - } +public class EslintJs extends AbstractEslint { protected EslintConfig eslintConfig(FormatterStepConfig stepConfig) { return new EslintConfig(this.configFile != null ? stepConfig.getFileLocator().locateFile(this.configFile) : null, this.configJs); } - private void addStyleGuideDevDependencies(Map devDependencies) { - if (this.styleGuide != null) { - EslintFormatterStep.PopularStyleGuide styleGuide = EslintFormatterStep.PopularStyleGuide.fromNameOrNull(this.styleGuide); - validateStyleGuide(styleGuide); - devDependencies.putAll(styleGuide.devDependencies()); - } - } - - private void validateStyleGuide(EslintFormatterStep.PopularStyleGuide styleGuide) { - if (styleGuide == null) { - throw new IllegalArgumentException("StyleGuide '" + this.styleGuide + "' is not supported. Supported style guides: " + supportedStyleGuides()); - } - if (!isValidStyleGuide(styleGuide)) { - throw new IllegalArgumentException("StyleGuide must be of correct type but is: " + styleGuide.getPopularStyleGuideName() + ". Use one of the following: " + supportedStyleGuides()); - } - } - - private String supportedStyleGuides() { - return EslintFormatterStep.PopularStyleGuide.getPopularStyleGuideNames(this::isValidStyleGuide); - } - protected boolean isValidStyleGuide(EslintFormatterStep.PopularStyleGuide styleGuide) { return styleGuide.name().startsWith("JS_"); } protected Map createDefaultDependencies() { - return eslintVersion == null ? EslintFormatterStep.defaultDevDependencies() : EslintFormatterStep.defaultDevDependenciesWithEslint(eslintVersion); + return this.eslintVersion == null ? EslintFormatterStep.defaultDevDependencies() : EslintFormatterStep.defaultDevDependenciesWithEslint(this.eslintVersion); } } diff --git a/plugin-maven/src/main/java/com/diffplug/spotless/maven/typescript/EslintTs.java b/plugin-maven/src/main/java/com/diffplug/spotless/maven/typescript/EslintTs.java index 0fe834ffde..f69f17f41e 100644 --- a/plugin-maven/src/main/java/com/diffplug/spotless/maven/typescript/EslintTs.java +++ b/plugin-maven/src/main/java/com/diffplug/spotless/maven/typescript/EslintTs.java @@ -20,20 +20,22 @@ import org.apache.maven.plugins.annotations.Parameter; import com.diffplug.spotless.maven.FormatterStepConfig; -import com.diffplug.spotless.maven.javascript.EslintJs; +import com.diffplug.spotless.maven.javascript.AbstractEslint; import com.diffplug.spotless.npm.EslintConfig; import com.diffplug.spotless.npm.EslintFormatterStep; import com.diffplug.spotless.npm.EslintTypescriptConfig; -public class EslintTs extends EslintJs { +public class EslintTs extends AbstractEslint { @Parameter private String tsconfigFile; @Override protected EslintConfig eslintConfig(FormatterStepConfig stepConfig) { - EslintConfig jsConfig = super.eslintConfig(stepConfig); - return new EslintTypescriptConfig(jsConfig.getEslintConfigPath(), jsConfig.getEslintConfigJs(), tsconfigFile != null ? stepConfig.getFileLocator().locateFile(tsconfigFile) : null); + return new EslintTypescriptConfig( + configFile != null ? stepConfig.getFileLocator().locateFile(configFile) : null, + configJs, + tsconfigFile != null ? stepConfig.getFileLocator().locateFile(tsconfigFile) : null); } @Override diff --git a/plugin-maven/src/test/java/com/diffplug/spotless/maven/MavenIntegrationHarness.java b/plugin-maven/src/test/java/com/diffplug/spotless/maven/MavenIntegrationHarness.java index 61d9c80a37..7a8073925d 100644 --- a/plugin-maven/src/test/java/com/diffplug/spotless/maven/MavenIntegrationHarness.java +++ b/plugin-maven/src/test/java/com/diffplug/spotless/maven/MavenIntegrationHarness.java @@ -136,6 +136,10 @@ protected void writePomWithCppSteps(String... steps) throws IOException { writePom(groupWithSteps("cpp", steps)); } + protected void writePomWithJavascriptSteps(String includes, String... steps) throws IOException { + writePom(groupWithSteps("javascript", including(includes), steps)); + } + protected void writePomWithTypescriptSteps(String includes, String... steps) throws IOException { writePom(groupWithSteps("typescript", including(includes), steps)); } diff --git a/plugin-maven/src/test/java/com/diffplug/spotless/maven/javascript/JavascriptFormatStepTest.java b/plugin-maven/src/test/java/com/diffplug/spotless/maven/javascript/JavascriptFormatStepTest.java new file mode 100644 index 0000000000..0f6d0d275f --- /dev/null +++ b/plugin-maven/src/test/java/com/diffplug/spotless/maven/javascript/JavascriptFormatStepTest.java @@ -0,0 +1,111 @@ +/* + * 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. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.diffplug.spotless.maven.javascript; + +import org.junit.jupiter.api.Nested; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.ValueSource; + +import com.diffplug.spotless.ResourceHarness; +import com.diffplug.spotless.maven.MavenIntegrationHarness; +import com.diffplug.spotless.maven.MavenRunner.Result; +import com.diffplug.spotless.tag.NpmTest; + +@NpmTest +class JavascriptFormatStepTest extends MavenIntegrationHarness { + + private static final String TEST_FILE_PATH = "src/main/javascript/test.js"; + + @NpmTest + @Nested + class EslintCustomRulesTest extends MavenIntegrationHarness { + + @Test + void eslintConfigFile() throws Exception { + writePomWithJavascriptSteps( + TEST_FILE_PATH, + "", + " .eslintrc.js", + ""); + setFile(".eslintrc.js").toResource("npm/eslint/javascript/custom_rules/.eslintrc.js"); + setFile(TEST_FILE_PATH).toResource("npm/eslint/javascript/custom_rules/javascript-es6.dirty"); + + Result result = mavenRunner().withArguments("spotless:apply").runNoError(); + System.out.println(result.output()); + assertFile(TEST_FILE_PATH).sameAsResource("npm/eslint/javascript/custom_rules/javascript-es6.clean"); + } + + @Test + void eslintConfigJs() throws Exception { + final String configJs = ResourceHarness.getTestResource("npm/eslint/javascript/custom_rules/.eslintrc.js") + .replace("module.exports = ", ""); + writePomWithJavascriptSteps( + TEST_FILE_PATH, + "", + " " + configJs + "", + ""); + setFile(TEST_FILE_PATH).toResource("npm/eslint/javascript/custom_rules/javascript-es6.dirty"); + + mavenRunner().withArguments("spotless:apply").runNoError(); + assertFile(TEST_FILE_PATH).sameAsResource("npm/eslint/javascript/custom_rules/javascript-es6.clean"); + } + + } + + @NpmTest + @Nested + class EslintStyleguidesTest extends MavenIntegrationHarness { + + @ParameterizedTest(name = "{index}: eslint js formatting with configFile using styleguide {0}") + @ValueSource(strings = {"airbnb", "google", "standard", "xo"}) + void eslintJsStyleguideUsingConfigFile(String styleGuide) throws Exception { + final String styleGuidePath = "npm/eslint/javascript/styleguide/" + styleGuide; + + writePomWithJavascriptSteps( + TEST_FILE_PATH, + "", + " .eslintrc.js", + " " + styleGuide + "", + ""); + setFile(".eslintrc.js").toResource(styleGuidePath + "/.eslintrc.js"); + setFile(TEST_FILE_PATH).toResource(styleGuidePath + "/javascript-es6.dirty"); + + mavenRunner().withArguments("spotless:apply").runNoError(); + assertFile(TEST_FILE_PATH).sameAsResource(styleGuidePath + "/javascript-es6.clean"); + } + + @ParameterizedTest(name = "{index}: eslint js formatting with inline config using styleguide {0}") + @ValueSource(strings = {"airbnb", "google", "standard", "xo"}) + void eslintJsStyleguideUsingInlineConfig(String styleGuide) throws Exception { + final String styleGuidePath = "npm/eslint/javascript/styleguide/" + styleGuide; + + final String escapedInlineConfig = ResourceHarness.getTestResource(styleGuidePath + "/.eslintrc.js") + .replace("<", "<") + .replace(">", ">"); + writePomWithJavascriptSteps( + TEST_FILE_PATH, + "", + " " + escapedInlineConfig + "", + " " + styleGuide + "", + ""); + setFile(TEST_FILE_PATH).toResource(styleGuidePath + "/javascript-es6.dirty"); + + mavenRunner().withArguments("spotless:apply").runNoError(); + assertFile(TEST_FILE_PATH).sameAsResource(styleGuidePath + "/javascript-es6.clean"); + } + } +} From 1d164d3528c8b9763217637665e9a84587a85002 Mon Sep 17 00:00:00 2001 From: Simon Gamma Date: Fri, 23 Dec 2022 08:22:07 +0100 Subject: [PATCH 437/757] eslint: also test custom devDependencies case --- .../javascript/JavascriptFormatStepTest.java | 24 +++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/plugin-maven/src/test/java/com/diffplug/spotless/maven/javascript/JavascriptFormatStepTest.java b/plugin-maven/src/test/java/com/diffplug/spotless/maven/javascript/JavascriptFormatStepTest.java index 0f6d0d275f..379208b9e4 100644 --- a/plugin-maven/src/test/java/com/diffplug/spotless/maven/javascript/JavascriptFormatStepTest.java +++ b/plugin-maven/src/test/java/com/diffplug/spotless/maven/javascript/JavascriptFormatStepTest.java @@ -107,5 +107,29 @@ void eslintJsStyleguideUsingInlineConfig(String styleGuide) throws Exception { mavenRunner().withArguments("spotless:apply").runNoError(); assertFile(TEST_FILE_PATH).sameAsResource(styleGuidePath + "/javascript-es6.clean"); } + + @Test + void provideCustomDependenciesForStyleguideStandard() throws Exception { + final String styleGuidePath = "npm/eslint/javascript/styleguide/standard"; + + writePomWithJavascriptSteps( + TEST_FILE_PATH, + "", + " .eslintrc.js", + " ", + " 8.28.0", + " 17.0.0", + " 2.26.0", + " 15.6.0", + " 6.1.1", + " ", + ""); + setFile(".eslintrc.js").toResource(styleGuidePath + "/.eslintrc.js"); + + setFile(TEST_FILE_PATH).toResource(styleGuidePath + "/javascript-es6.dirty"); + + mavenRunner().withArguments("spotless:apply").runNoError(); + assertFile(TEST_FILE_PATH).sameAsResource(styleGuidePath + "/javascript-es6.clean"); + } } } From 3f3705395fac64a7f083facd13896e5d26243e38 Mon Sep 17 00:00:00 2001 From: Simon Gamma Date: Wed, 4 Jan 2023 09:55:35 +0100 Subject: [PATCH 438/757] eslint: adding readme (common and plugin-gradle) --- CHANGES.md | 3 + README.md | 2 + plugin-gradle/CHANGES.md | 2 + plugin-gradle/README.md | 120 ++++++++++++++++++++++++++++++++++++++- 4 files changed, 126 insertions(+), 1 deletion(-) diff --git a/CHANGES.md b/CHANGES.md index a7e3516607..3efdec3b67 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -10,6 +10,9 @@ This document is intended for Spotless developers. We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format (starting after version `1.27.0`). ## [Unreleased] +### Added +* Added support for npm-based [ESLint](https://eslint.org/)-formatter for javascript and typescript ([#1433](https://github.com/diffplug/spotless/pull/1433)) + ### Changes * Bump the dev version of Gradle from `7.5.1` to `7.6` ([#1409](https://github.com/diffplug/spotless/pull/1409)) * We also removed the no-longer-required dependency `org.codehaus.groovy:groovy-xml` diff --git a/README.md b/README.md index 605305bd29..ddc3c2391c 100644 --- a/README.md +++ b/README.md @@ -69,6 +69,7 @@ lib('kotlin.KtfmtStep') +'{{yes}} | {{yes}} lib('kotlin.DiktatStep') +'{{yes}} | {{yes}} | {{no}} | {{no}} |', lib('markdown.FreshMarkStep') +'{{yes}} | {{no}} | {{no}} | {{no}} |', lib('markdown.FlexmarkStep') +'{{no}} | {{yes}} | {{no}} | {{no}} |', +lib('npm.EslintFormatterStep') +'{{yes}} | {{yes}} | {{no}} | {{no}} |', lib('npm.PrettierFormatterStep') +'{{yes}} | {{yes}} | {{no}} | {{no}} |', lib('npm.TsFmtFormatterStep') +'{{yes}} | {{yes}} | {{no}} | {{no}} |', lib('pom.SortPomStep') +'{{no}} | {{yes}} | {{no}} | {{no}} |', @@ -113,6 +114,7 @@ extra('wtp.EclipseWtpFormatterStep') +'{{yes}} | {{yes}} | [`kotlin.DiktatStep`](lib/src/main/java/com/diffplug/spotless/kotlin/DiktatStep.java) | :+1: | :+1: | :white_large_square: | :white_large_square: | | [`markdown.FreshMarkStep`](lib/src/main/java/com/diffplug/spotless/markdown/FreshMarkStep.java) | :+1: | :white_large_square: | :white_large_square: | :white_large_square: | | [`markdown.FlexmarkStep`](lib/src/main/java/com/diffplug/spotless/markdown/FlexmarkStep.java) | :white_large_square: | :+1: | :white_large_square: | :white_large_square: | +| [`npm.EslintFormatterStep`](lib/src/main/java/com/diffplug/spotless/npm/EslintFormatterStep.java) | :+1: | :+1: | :white_large_square: | :white_large_square: | | [`npm.PrettierFormatterStep`](lib/src/main/java/com/diffplug/spotless/npm/PrettierFormatterStep.java) | :+1: | :+1: | :white_large_square: | :white_large_square: | | [`npm.TsFmtFormatterStep`](lib/src/main/java/com/diffplug/spotless/npm/TsFmtFormatterStep.java) | :+1: | :+1: | :white_large_square: | :white_large_square: | | [`pom.SortPomStep`](lib/src/main/java/com/diffplug/spotless/pom/SortPomStep.java) | :white_large_square: | :+1: | :white_large_square: | :white_large_square: | diff --git a/plugin-gradle/CHANGES.md b/plugin-gradle/CHANGES.md index c5f464069f..d668f69483 100644 --- a/plugin-gradle/CHANGES.md +++ b/plugin-gradle/CHANGES.md @@ -3,6 +3,8 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format (starting after version `3.27.0`). ## [Unreleased] +### Added +* Added support for npm-based [ESLint](https://eslint.org/) formatter for javascript and typescript ([#1433](https://github.com/diffplug/spotless/pull/1433)) ### Fixed * Prevent tool configurations from being resolved outside project ([#1447](https://github.com/diffplug/spotless/pull/1447) fixes [#1215](https://github.com/diffplug/spotless/issues/1215)) diff --git a/plugin-gradle/README.md b/plugin-gradle/README.md index 755d21d056..6f498059b9 100644 --- a/plugin-gradle/README.md +++ b/plugin-gradle/README.md @@ -69,7 +69,8 @@ Spotless supports all of Gradle's built-in performance features (incremental bui - [FreshMark](#freshmark) aka markdown - [Antlr4](#antlr4) ([antlr4formatter](#antlr4formatter)) - [SQL](#sql) ([dbeaver](#dbeaver), [prettier](#prettier)) - - [Typescript](#typescript) ([tsfmt](#tsfmt), [prettier](#prettier)) + - [Typescript](#typescript) ([tsfmt](#tsfmt), [prettier](#prettier), [eslint](#eslint--typescript-)) + - [Javascript](#javascript) ([prettier](#prettier), [eslint](#eslint--javascript-)) - [JSON](#json) - Multiple languages - [Prettier](#prettier) ([plugins](#prettier-plugins), [npm detection](#npm-detection), [`.npmrc` detection](#npmrc-detection)) @@ -576,6 +577,7 @@ spotless { tsfmt() // has its own section below prettier() // has its own section below + eslint() // has its own section below licenseHeader '/* (C) $YEAR */', '(import|const|declare|export|var) ' // or licenseHeaderFile // note the '(import|const|...' argument - this is a regex which identifies the top @@ -608,6 +610,122 @@ spotless { For details, see the [npm detection](#npm-detection) and [`.npmrc` detection](#npmrc-detection) sections of prettier, which apply also to tsfmt. +### eslint (Typescript) + +[npm](https://www.npmjs.com/package/eslint). [changelog](https://github.com/eslint/eslint/blob/main/CHANGELOG.md). *Please note:* +The auto-discovery of config files (up the file tree) will not work when using eslint within spotless, +hence you are required to provide resolvable file paths for config files, or alternatively provide the configuration inline. + +The configuration is very similar to the [eslint (Javascript)](#eslint--javascript-) configuration. It differs in supported +styleguides and the requirement for a tsconfigFile. + +```gradle +spotless { + typescript { + eslint('8.30.0') // version is optional + eslint(['my-eslint-fork': '1.2.3', 'my-eslint-plugin': '1.2.1']) // can specify exactly which npm packages to use + + eslint() + // optional: use a popular eslint styleguide for typescript + .styleGuide('standard-with-typescript') // or 'xo-typescript' + // configuration is mandatory. Provide inline config or a config file. + // a) inline-configuration + .configJs(''' + { + env: { + browser: true, + es2021: true + }, + extends: 'standard-with-typescript', + overrides: [ + ], + parserOptions: { + ecmaVersion: 'latest', + sourceType: 'module', + project: './tsconfig.json', + }, + rules: { + } + } + ''') + // b) config file + .configFile('.eslintrc.js') + // recommended: provide a tsconfig.json - especially when using the styleguides + .tsconfigFile('tsconfig.json') + } +} +``` + +**Prerequisite: eslint requires a working NodeJS version** + +For details, see the [npm detection](#npm-detection) and [`.npmrc` detection](#npmrc-detection) sections of prettier, which apply also to eslint. + +## Javascript + +- `com.diffplug.gradle.spotless.JavascriptExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.12.0/com/diffplug/gradle/spotless/JavascriptExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/JavascriptExtension.java) + +```gradle +spotless { + javascript { + target 'src/**/*.js' // you have to set the target manually + + prettier() // has its own section below + eslint() // has its own section below + + licenseHeader '/* (C) $YEAR */', 'REGEX_TO_DEFINE_TOP_OF_FILE' // or licenseHeaderFile + } +} +``` + +### eslint (Javascript) + +[npm](https://www.npmjs.com/package/eslint). [changelog](https://github.com/eslint/eslint/blob/main/CHANGELOG.md). *Please note:* +The auto-discovery of config files (up the file tree) will not work when using eslint within spotless, +hence you are required to provide resolvable file paths for config files, or alternatively provide the configuration inline. + +The configuration is very similar to the [eslint (Typescript)](#eslint--typescript-) configuration. It differs in supported +styleguides and no requirement for a tsconfig (of course). + +```gradle + +```gradle +spotless { + javascript { + eslint('8.30.0') // version is optional + eslint(['my-eslint-fork': '1.2.3', 'my-eslint-plugin': '1.2.1']) // can specify exactly which npm packages to use + + eslint() + // optional: use a popular eslint styleguide for javascript + .styleGuide('standard') // or 'airbnb', 'google', 'xo' + // configuration is mandatory. Provide inline config or a config file. + // a) inline-configuration + .configJs(''' + { + env: { + browser: true, + es2021: true + }, + extends: 'standard', + overrides: [ + ], + parserOptions: { + ecmaVersion: 'latest', + sourceType: 'module' + }, + rules: { + } + } + ''') + // b) config file + .configFile('.eslintrc.js') + } +} +``` + +**Prerequisite: eslint requires a working NodeJS version** + +For details, see the [npm detection](#npm-detection) and [`.npmrc` detection](#npmrc-detection) sections of prettier, which apply also to eslint. + ## JSON - `com.diffplug.gradle.spotless.JsonExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.12.1/com/diffplug/gradle/spotless/JsonExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/JsonExtension.java) From bb843ce0cf741b809ea8cf022ae5556464789ac5 Mon Sep 17 00:00:00 2001 From: Simon Gamma Date: Wed, 4 Jan 2023 09:56:22 +0100 Subject: [PATCH 439/757] eslint: apply spotless --- .../spotless/npm/BaseNpmRestService.java | 2 +- .../diffplug/spotless/npm/EslintConfig.java | 2 +- .../spotless/npm/EslintFormatterStep.java | 2 +- .../spotless/npm/EslintRestService.java | 2 +- .../spotless/npm/EslintTypescriptConfig.java | 2 +- .../npm/NpmFormatterStepStateBase.java | 2 +- .../com/diffplug/spotless/npm/NpmProcess.java | 2 +- .../spotless/npm/NpmResourceHelper.java | 2 +- .../spotless/npm/PrettierFormatterStep.java | 2 +- .../spotless/npm/PrettierRestService.java | 2 +- .../spotless/npm/TsFmtFormatterStep.java | 2 +- .../spotless/npm/TsFmtRestService.java | 2 +- .../gradle/spotless/FormatExtension.java | 2 +- .../gradle/spotless/JavascriptExtension.java | 2 +- .../gradle/spotless/SpotlessExtension.java | 2 +- .../gradle/spotless/TypescriptExtension.java | 2 +- .../spotless/JavascriptExtensionTest.java | 2 +- .../spotless/PrettierIntegrationTest.java | 2 +- .../spotless/TypescriptExtensionTest.java | 2 +- .../spotless/maven/AbstractSpotlessMojo.java | 2 +- .../spotless/maven/generic/Prettier.java | 2 +- .../maven/javascript/AbstractEslint.java | 2 +- .../spotless/maven/javascript/EslintJs.java | 2 +- .../spotless/maven/javascript/Javascript.java | 2 +- .../npm/AbstractNpmFormatterStepFactory.java | 2 +- .../spotless/maven/typescript/EslintTs.java | 2 +- .../spotless/maven/typescript/Tsfmt.java | 2 +- .../spotless/maven/typescript/Typescript.java | 2 +- .../maven/MavenIntegrationHarness.java | 2 +- .../javascript/JavascriptFormatStepTest.java | 24 +++++++++---------- .../prettier/PrettierFormatStepTest.java | 2 +- .../typescript/TypescriptFormatStepTest.java | 2 +- .../spotless/npm/EslintFormatterStepTest.java | 2 +- .../npm/NpmFormatterStepCommonTests.java | 2 +- .../spotless/npm/TsFmtFormatterStepTest.java | 2 +- 35 files changed, 46 insertions(+), 46 deletions(-) diff --git a/lib/src/main/java/com/diffplug/spotless/npm/BaseNpmRestService.java b/lib/src/main/java/com/diffplug/spotless/npm/BaseNpmRestService.java index e8582c15ec..a6d93182a1 100644 --- a/lib/src/main/java/com/diffplug/spotless/npm/BaseNpmRestService.java +++ b/lib/src/main/java/com/diffplug/spotless/npm/BaseNpmRestService.java @@ -1,5 +1,5 @@ /* - * Copyright 2016-2022 DiffPlug + * Copyright 2016-2023 DiffPlug * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/lib/src/main/java/com/diffplug/spotless/npm/EslintConfig.java b/lib/src/main/java/com/diffplug/spotless/npm/EslintConfig.java index 4e1848856a..3499b3face 100644 --- a/lib/src/main/java/com/diffplug/spotless/npm/EslintConfig.java +++ b/lib/src/main/java/com/diffplug/spotless/npm/EslintConfig.java @@ -1,5 +1,5 @@ /* - * Copyright 2016-2022 DiffPlug + * Copyright 2016-2023 DiffPlug * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/lib/src/main/java/com/diffplug/spotless/npm/EslintFormatterStep.java b/lib/src/main/java/com/diffplug/spotless/npm/EslintFormatterStep.java index 820283aae4..ac3ee05345 100644 --- a/lib/src/main/java/com/diffplug/spotless/npm/EslintFormatterStep.java +++ b/lib/src/main/java/com/diffplug/spotless/npm/EslintFormatterStep.java @@ -1,5 +1,5 @@ /* - * Copyright 2016-2022 DiffPlug + * Copyright 2016-2023 DiffPlug * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/lib/src/main/java/com/diffplug/spotless/npm/EslintRestService.java b/lib/src/main/java/com/diffplug/spotless/npm/EslintRestService.java index 198ee5389c..e17237ecbf 100644 --- a/lib/src/main/java/com/diffplug/spotless/npm/EslintRestService.java +++ b/lib/src/main/java/com/diffplug/spotless/npm/EslintRestService.java @@ -1,5 +1,5 @@ /* - * Copyright 2016-2022 DiffPlug + * Copyright 2016-2023 DiffPlug * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/lib/src/main/java/com/diffplug/spotless/npm/EslintTypescriptConfig.java b/lib/src/main/java/com/diffplug/spotless/npm/EslintTypescriptConfig.java index f8c213a0a9..fc45f8bd7b 100644 --- a/lib/src/main/java/com/diffplug/spotless/npm/EslintTypescriptConfig.java +++ b/lib/src/main/java/com/diffplug/spotless/npm/EslintTypescriptConfig.java @@ -1,5 +1,5 @@ /* - * Copyright 2022 DiffPlug + * Copyright 2022-2023 DiffPlug * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/lib/src/main/java/com/diffplug/spotless/npm/NpmFormatterStepStateBase.java b/lib/src/main/java/com/diffplug/spotless/npm/NpmFormatterStepStateBase.java index fc1543fd61..49a166e45c 100644 --- a/lib/src/main/java/com/diffplug/spotless/npm/NpmFormatterStepStateBase.java +++ b/lib/src/main/java/com/diffplug/spotless/npm/NpmFormatterStepStateBase.java @@ -1,5 +1,5 @@ /* - * Copyright 2016-2022 DiffPlug + * Copyright 2016-2023 DiffPlug * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/lib/src/main/java/com/diffplug/spotless/npm/NpmProcess.java b/lib/src/main/java/com/diffplug/spotless/npm/NpmProcess.java index 28db79b726..e2fd07682c 100644 --- a/lib/src/main/java/com/diffplug/spotless/npm/NpmProcess.java +++ b/lib/src/main/java/com/diffplug/spotless/npm/NpmProcess.java @@ -1,5 +1,5 @@ /* - * Copyright 2016-2022 DiffPlug + * Copyright 2016-2023 DiffPlug * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/lib/src/main/java/com/diffplug/spotless/npm/NpmResourceHelper.java b/lib/src/main/java/com/diffplug/spotless/npm/NpmResourceHelper.java index 48e974eec6..2acf3a180d 100644 --- a/lib/src/main/java/com/diffplug/spotless/npm/NpmResourceHelper.java +++ b/lib/src/main/java/com/diffplug/spotless/npm/NpmResourceHelper.java @@ -1,5 +1,5 @@ /* - * Copyright 2016-2022 DiffPlug + * Copyright 2016-2023 DiffPlug * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/lib/src/main/java/com/diffplug/spotless/npm/PrettierFormatterStep.java b/lib/src/main/java/com/diffplug/spotless/npm/PrettierFormatterStep.java index 8489644c36..a83fc07674 100644 --- a/lib/src/main/java/com/diffplug/spotless/npm/PrettierFormatterStep.java +++ b/lib/src/main/java/com/diffplug/spotless/npm/PrettierFormatterStep.java @@ -1,5 +1,5 @@ /* - * Copyright 2016-2022 DiffPlug + * Copyright 2016-2023 DiffPlug * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/lib/src/main/java/com/diffplug/spotless/npm/PrettierRestService.java b/lib/src/main/java/com/diffplug/spotless/npm/PrettierRestService.java index 2a62823aa0..ccdc189d27 100644 --- a/lib/src/main/java/com/diffplug/spotless/npm/PrettierRestService.java +++ b/lib/src/main/java/com/diffplug/spotless/npm/PrettierRestService.java @@ -1,5 +1,5 @@ /* - * Copyright 2016-2022 DiffPlug + * Copyright 2016-2023 DiffPlug * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/lib/src/main/java/com/diffplug/spotless/npm/TsFmtFormatterStep.java b/lib/src/main/java/com/diffplug/spotless/npm/TsFmtFormatterStep.java index 027af89e23..98d694ec33 100644 --- a/lib/src/main/java/com/diffplug/spotless/npm/TsFmtFormatterStep.java +++ b/lib/src/main/java/com/diffplug/spotless/npm/TsFmtFormatterStep.java @@ -1,5 +1,5 @@ /* - * Copyright 2016-2022 DiffPlug + * Copyright 2016-2023 DiffPlug * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/lib/src/main/java/com/diffplug/spotless/npm/TsFmtRestService.java b/lib/src/main/java/com/diffplug/spotless/npm/TsFmtRestService.java index f77510c3b6..704d2b47af 100644 --- a/lib/src/main/java/com/diffplug/spotless/npm/TsFmtRestService.java +++ b/lib/src/main/java/com/diffplug/spotless/npm/TsFmtRestService.java @@ -1,5 +1,5 @@ /* - * Copyright 2016-2022 DiffPlug + * Copyright 2016-2023 DiffPlug * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. 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 08e713a921..c72c9339a0 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-2022 DiffPlug + * Copyright 2016-2023 DiffPlug * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/JavascriptExtension.java b/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/JavascriptExtension.java index cbe0040a83..862c7566ee 100644 --- a/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/JavascriptExtension.java +++ b/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/JavascriptExtension.java @@ -1,5 +1,5 @@ /* - * Copyright 2016-2022 DiffPlug + * Copyright 2016-2023 DiffPlug * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. 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 3fe5721b5d..1c65fad310 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 @@ -1,5 +1,5 @@ /* - * Copyright 2016-2022 DiffPlug + * Copyright 2016-2023 DiffPlug * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/TypescriptExtension.java b/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/TypescriptExtension.java index 79ae056bdc..5de1bb1ac3 100644 --- a/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/TypescriptExtension.java +++ b/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/TypescriptExtension.java @@ -1,5 +1,5 @@ /* - * Copyright 2016-2022 DiffPlug + * Copyright 2016-2023 DiffPlug * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/JavascriptExtensionTest.java b/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/JavascriptExtensionTest.java index af203936f3..331e17f28e 100644 --- a/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/JavascriptExtensionTest.java +++ b/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/JavascriptExtensionTest.java @@ -1,5 +1,5 @@ /* - * Copyright 2016-2022 DiffPlug + * Copyright 2016-2023 DiffPlug * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/PrettierIntegrationTest.java b/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/PrettierIntegrationTest.java index 6f55312bd5..bc8ad1148e 100644 --- a/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/PrettierIntegrationTest.java +++ b/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/PrettierIntegrationTest.java @@ -1,5 +1,5 @@ /* - * Copyright 2016-2022 DiffPlug + * Copyright 2016-2023 DiffPlug * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/TypescriptExtensionTest.java b/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/TypescriptExtensionTest.java index da9fa03905..598ff7dc14 100644 --- a/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/TypescriptExtensionTest.java +++ b/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/TypescriptExtensionTest.java @@ -1,5 +1,5 @@ /* - * Copyright 2016-2022 DiffPlug + * Copyright 2016-2023 DiffPlug * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/plugin-maven/src/main/java/com/diffplug/spotless/maven/AbstractSpotlessMojo.java b/plugin-maven/src/main/java/com/diffplug/spotless/maven/AbstractSpotlessMojo.java index 647535a590..5ad96ece46 100644 --- a/plugin-maven/src/main/java/com/diffplug/spotless/maven/AbstractSpotlessMojo.java +++ b/plugin-maven/src/main/java/com/diffplug/spotless/maven/AbstractSpotlessMojo.java @@ -1,5 +1,5 @@ /* - * Copyright 2016-2022 DiffPlug + * Copyright 2016-2023 DiffPlug * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/plugin-maven/src/main/java/com/diffplug/spotless/maven/generic/Prettier.java b/plugin-maven/src/main/java/com/diffplug/spotless/maven/generic/Prettier.java index b45f802653..ffe384b4d9 100644 --- a/plugin-maven/src/main/java/com/diffplug/spotless/maven/generic/Prettier.java +++ b/plugin-maven/src/main/java/com/diffplug/spotless/maven/generic/Prettier.java @@ -1,5 +1,5 @@ /* - * Copyright 2016-2022 DiffPlug + * Copyright 2016-2023 DiffPlug * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/plugin-maven/src/main/java/com/diffplug/spotless/maven/javascript/AbstractEslint.java b/plugin-maven/src/main/java/com/diffplug/spotless/maven/javascript/AbstractEslint.java index 735a25c0c5..b5fc156a57 100644 --- a/plugin-maven/src/main/java/com/diffplug/spotless/maven/javascript/AbstractEslint.java +++ b/plugin-maven/src/main/java/com/diffplug/spotless/maven/javascript/AbstractEslint.java @@ -1,5 +1,5 @@ /* - * Copyright 2016-2022 DiffPlug + * Copyright 2016-2023 DiffPlug * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/plugin-maven/src/main/java/com/diffplug/spotless/maven/javascript/EslintJs.java b/plugin-maven/src/main/java/com/diffplug/spotless/maven/javascript/EslintJs.java index f6c7beaff4..f9954ab0c8 100644 --- a/plugin-maven/src/main/java/com/diffplug/spotless/maven/javascript/EslintJs.java +++ b/plugin-maven/src/main/java/com/diffplug/spotless/maven/javascript/EslintJs.java @@ -1,5 +1,5 @@ /* - * Copyright 2016-2022 DiffPlug + * Copyright 2016-2023 DiffPlug * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/plugin-maven/src/main/java/com/diffplug/spotless/maven/javascript/Javascript.java b/plugin-maven/src/main/java/com/diffplug/spotless/maven/javascript/Javascript.java index db7049ff0d..7ca35dd258 100644 --- a/plugin-maven/src/main/java/com/diffplug/spotless/maven/javascript/Javascript.java +++ b/plugin-maven/src/main/java/com/diffplug/spotless/maven/javascript/Javascript.java @@ -1,5 +1,5 @@ /* - * Copyright 2016-2022 DiffPlug + * Copyright 2016-2023 DiffPlug * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/plugin-maven/src/main/java/com/diffplug/spotless/maven/npm/AbstractNpmFormatterStepFactory.java b/plugin-maven/src/main/java/com/diffplug/spotless/maven/npm/AbstractNpmFormatterStepFactory.java index 8bc0f8f715..22ee5e0dba 100644 --- a/plugin-maven/src/main/java/com/diffplug/spotless/maven/npm/AbstractNpmFormatterStepFactory.java +++ b/plugin-maven/src/main/java/com/diffplug/spotless/maven/npm/AbstractNpmFormatterStepFactory.java @@ -1,5 +1,5 @@ /* - * Copyright 2016-2022 DiffPlug + * Copyright 2016-2023 DiffPlug * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/plugin-maven/src/main/java/com/diffplug/spotless/maven/typescript/EslintTs.java b/plugin-maven/src/main/java/com/diffplug/spotless/maven/typescript/EslintTs.java index f69f17f41e..72f3735d97 100644 --- a/plugin-maven/src/main/java/com/diffplug/spotless/maven/typescript/EslintTs.java +++ b/plugin-maven/src/main/java/com/diffplug/spotless/maven/typescript/EslintTs.java @@ -1,5 +1,5 @@ /* - * Copyright 2022 DiffPlug + * Copyright 2022-2023 DiffPlug * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/plugin-maven/src/main/java/com/diffplug/spotless/maven/typescript/Tsfmt.java b/plugin-maven/src/main/java/com/diffplug/spotless/maven/typescript/Tsfmt.java index 6c60c02cc6..685d473072 100644 --- a/plugin-maven/src/main/java/com/diffplug/spotless/maven/typescript/Tsfmt.java +++ b/plugin-maven/src/main/java/com/diffplug/spotless/maven/typescript/Tsfmt.java @@ -1,5 +1,5 @@ /* - * Copyright 2016-2022 DiffPlug + * Copyright 2016-2023 DiffPlug * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/plugin-maven/src/main/java/com/diffplug/spotless/maven/typescript/Typescript.java b/plugin-maven/src/main/java/com/diffplug/spotless/maven/typescript/Typescript.java index 1320cac2d8..6f0d7f91b2 100644 --- a/plugin-maven/src/main/java/com/diffplug/spotless/maven/typescript/Typescript.java +++ b/plugin-maven/src/main/java/com/diffplug/spotless/maven/typescript/Typescript.java @@ -1,5 +1,5 @@ /* - * Copyright 2016-2022 DiffPlug + * Copyright 2016-2023 DiffPlug * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/plugin-maven/src/test/java/com/diffplug/spotless/maven/MavenIntegrationHarness.java b/plugin-maven/src/test/java/com/diffplug/spotless/maven/MavenIntegrationHarness.java index 7a8073925d..d9a23cdb74 100644 --- a/plugin-maven/src/test/java/com/diffplug/spotless/maven/MavenIntegrationHarness.java +++ b/plugin-maven/src/test/java/com/diffplug/spotless/maven/MavenIntegrationHarness.java @@ -1,5 +1,5 @@ /* - * Copyright 2016-2022 DiffPlug + * Copyright 2016-2023 DiffPlug * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/plugin-maven/src/test/java/com/diffplug/spotless/maven/javascript/JavascriptFormatStepTest.java b/plugin-maven/src/test/java/com/diffplug/spotless/maven/javascript/JavascriptFormatStepTest.java index 379208b9e4..7ebc592add 100644 --- a/plugin-maven/src/test/java/com/diffplug/spotless/maven/javascript/JavascriptFormatStepTest.java +++ b/plugin-maven/src/test/java/com/diffplug/spotless/maven/javascript/JavascriptFormatStepTest.java @@ -1,5 +1,5 @@ /* - * Copyright 2016-2022 DiffPlug + * Copyright 2016-2023 DiffPlug * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -113,17 +113,17 @@ void provideCustomDependenciesForStyleguideStandard() throws Exception { final String styleGuidePath = "npm/eslint/javascript/styleguide/standard"; writePomWithJavascriptSteps( - TEST_FILE_PATH, - "", - " .eslintrc.js", - " ", - " 8.28.0", - " 17.0.0", - " 2.26.0", - " 15.6.0", - " 6.1.1", - " ", - ""); + TEST_FILE_PATH, + "", + " .eslintrc.js", + " ", + " 8.28.0", + " 17.0.0", + " 2.26.0", + " 15.6.0", + " 6.1.1", + " ", + ""); setFile(".eslintrc.js").toResource(styleGuidePath + "/.eslintrc.js"); setFile(TEST_FILE_PATH).toResource(styleGuidePath + "/javascript-es6.dirty"); diff --git a/plugin-maven/src/test/java/com/diffplug/spotless/maven/prettier/PrettierFormatStepTest.java b/plugin-maven/src/test/java/com/diffplug/spotless/maven/prettier/PrettierFormatStepTest.java index 8fce61b5d8..c0a9267b93 100644 --- a/plugin-maven/src/test/java/com/diffplug/spotless/maven/prettier/PrettierFormatStepTest.java +++ b/plugin-maven/src/test/java/com/diffplug/spotless/maven/prettier/PrettierFormatStepTest.java @@ -1,5 +1,5 @@ /* - * Copyright 2016-2022 DiffPlug + * Copyright 2016-2023 DiffPlug * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/plugin-maven/src/test/java/com/diffplug/spotless/maven/typescript/TypescriptFormatStepTest.java b/plugin-maven/src/test/java/com/diffplug/spotless/maven/typescript/TypescriptFormatStepTest.java index b57a2a97a6..ac925cc9b6 100644 --- a/plugin-maven/src/test/java/com/diffplug/spotless/maven/typescript/TypescriptFormatStepTest.java +++ b/plugin-maven/src/test/java/com/diffplug/spotless/maven/typescript/TypescriptFormatStepTest.java @@ -1,5 +1,5 @@ /* - * Copyright 2016-2022 DiffPlug + * Copyright 2016-2023 DiffPlug * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/testlib/src/test/java/com/diffplug/spotless/npm/EslintFormatterStepTest.java b/testlib/src/test/java/com/diffplug/spotless/npm/EslintFormatterStepTest.java index 15ebb0cc0d..5f53c9effa 100644 --- a/testlib/src/test/java/com/diffplug/spotless/npm/EslintFormatterStepTest.java +++ b/testlib/src/test/java/com/diffplug/spotless/npm/EslintFormatterStepTest.java @@ -1,5 +1,5 @@ /* - * Copyright 2016-2022 DiffPlug + * Copyright 2016-2023 DiffPlug * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/testlib/src/test/java/com/diffplug/spotless/npm/NpmFormatterStepCommonTests.java b/testlib/src/test/java/com/diffplug/spotless/npm/NpmFormatterStepCommonTests.java index 1ed6e9bbe8..dff105108a 100644 --- a/testlib/src/test/java/com/diffplug/spotless/npm/NpmFormatterStepCommonTests.java +++ b/testlib/src/test/java/com/diffplug/spotless/npm/NpmFormatterStepCommonTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2016-2022 DiffPlug + * Copyright 2016-2023 DiffPlug * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/testlib/src/test/java/com/diffplug/spotless/npm/TsFmtFormatterStepTest.java b/testlib/src/test/java/com/diffplug/spotless/npm/TsFmtFormatterStepTest.java index 474c664486..a774c7c1ee 100644 --- a/testlib/src/test/java/com/diffplug/spotless/npm/TsFmtFormatterStepTest.java +++ b/testlib/src/test/java/com/diffplug/spotless/npm/TsFmtFormatterStepTest.java @@ -1,5 +1,5 @@ /* - * Copyright 2016-2022 DiffPlug + * Copyright 2016-2023 DiffPlug * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. From 508dd69b8c328cf537809025ca0134e65c7587b0 Mon Sep 17 00:00:00 2001 From: Simon Gamma Date: Wed, 4 Jan 2023 10:02:13 +0100 Subject: [PATCH 440/757] bumping default prettier version --- CHANGES.md | 3 ++- .../spotless/npm/PrettierFormatterStep.java | 2 +- .../config/typescript.configfile.clean | 3 ++- .../prettier/config/typescript.defaults.clean | 3 ++- .../javascript-es5/javascript-es5.clean | 24 +++---------------- .../javascript-es6/javascript-es6.clean | 24 +++---------------- 6 files changed, 13 insertions(+), 46 deletions(-) diff --git a/CHANGES.md b/CHANGES.md index 3efdec3b67..bf1798d7c2 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -12,8 +12,8 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format ( ## [Unreleased] ### Added * Added support for npm-based [ESLint](https://eslint.org/)-formatter for javascript and typescript ([#1433](https://github.com/diffplug/spotless/pull/1433)) - ### Changes +* Bump default Version for `prettier` from `2.0.5` to `2.8.1` * Bump the dev version of Gradle from `7.5.1` to `7.6` ([#1409](https://github.com/diffplug/spotless/pull/1409)) * We also removed the no-longer-required dependency `org.codehaus.groovy:groovy-xml` * Breaking changes to Spotless' internal testing infrastructure `testlib` ([#1443](https://github.com/diffplug/spotless/pull/1443)) @@ -22,6 +22,7 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format ( * `StepHarnessWithFile` now takes a `ResourceHarness` in its constructor to handle the file manipulation parts * Standardized that we test exception *messages*, not types, which will ease the transition to linting later on + ## [2.31.1] - 2023-01-02 ### Fixed * Improve memory usage when using git ratchet ([#1426](https://github.com/diffplug/spotless/pull/1426)) diff --git a/lib/src/main/java/com/diffplug/spotless/npm/PrettierFormatterStep.java b/lib/src/main/java/com/diffplug/spotless/npm/PrettierFormatterStep.java index a83fc07674..22a162eb0b 100644 --- a/lib/src/main/java/com/diffplug/spotless/npm/PrettierFormatterStep.java +++ b/lib/src/main/java/com/diffplug/spotless/npm/PrettierFormatterStep.java @@ -42,7 +42,7 @@ public class PrettierFormatterStep { public static final String NAME = "prettier-format"; public static final Map defaultDevDependencies() { - return defaultDevDependenciesWithPrettier("2.0.5"); + return defaultDevDependenciesWithPrettier("2.8.1"); } public static final Map defaultDevDependenciesWithPrettier(String version) { diff --git a/testlib/src/main/resources/npm/prettier/config/typescript.configfile.clean b/testlib/src/main/resources/npm/prettier/config/typescript.configfile.clean index 0ec76369be..dfe71bf0a9 100644 --- a/testlib/src/main/resources/npm/prettier/config/typescript.configfile.clean +++ b/testlib/src/main/resources/npm/prettier/config/typescript.configfile.clean @@ -1,6 +1,7 @@ export class MyVeryOwnControllerWithARatherLongNameThatIsNotReallyNecessary extends AbstractController - implements DisposeAware, CallbackAware { + implements DisposeAware, CallbackAware +{ public myValue: string[]; constructor( diff --git a/testlib/src/main/resources/npm/prettier/config/typescript.defaults.clean b/testlib/src/main/resources/npm/prettier/config/typescript.defaults.clean index 0155b905bd..61d8e020d6 100644 --- a/testlib/src/main/resources/npm/prettier/config/typescript.defaults.clean +++ b/testlib/src/main/resources/npm/prettier/config/typescript.defaults.clean @@ -1,6 +1,7 @@ export class MyVeryOwnControllerWithARatherLongNameThatIsNotReallyNecessary extends AbstractController - implements DisposeAware, CallbackAware { + implements DisposeAware, CallbackAware +{ public myValue: string[]; constructor(private myService: Service, name: string, private field: any) { diff --git a/testlib/src/main/resources/npm/prettier/filetypes/javascript-es5/javascript-es5.clean b/testlib/src/main/resources/npm/prettier/filetypes/javascript-es5/javascript-es5.clean index 29002f6b05..0cfac613f1 100644 --- a/testlib/src/main/resources/npm/prettier/filetypes/javascript-es5/javascript-es5.clean +++ b/testlib/src/main/resources/npm/prettier/filetypes/javascript-es5/javascript-es5.clean @@ -1,24 +1,5 @@ var numbers = [ - 1, - 2, - 3, - 4, - 5, - 6, - 7, - 8, - 9, - 10, - 11, - 12, - 13, - 14, - 15, - 16, - 17, - 18, - 19, - 20, + 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, ]; var p = { @@ -32,7 +13,8 @@ var p = { var str = "Hello, world!"; var str2 = str.charAt(3) + str[0]; -var multilinestr = "Hello \ +var multilinestr = + "Hello \ World"; function test(a, b) { return a + b; diff --git a/testlib/src/main/resources/npm/prettier/filetypes/javascript-es6/javascript-es6.clean b/testlib/src/main/resources/npm/prettier/filetypes/javascript-es6/javascript-es6.clean index d4e982d69f..1935faa03c 100644 --- a/testlib/src/main/resources/npm/prettier/filetypes/javascript-es6/javascript-es6.clean +++ b/testlib/src/main/resources/npm/prettier/filetypes/javascript-es6/javascript-es6.clean @@ -1,24 +1,5 @@ var numbers = [ - 1, - 2, - 3, - 4, - 5, - 6, - 7, - 8, - 9, - 10, - 11, - 12, - 13, - 14, - 15, - 16, - 17, - 18, - 19, - 20, + 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, ]; const p = { @@ -32,7 +13,8 @@ const p = { const str = "Hello, world!"; var str2 = str.charAt(3) + str[0]; -var multilinestr = "Hello \ +var multilinestr = + "Hello \ World"; function test(a, b = "world") { let combined = a + b; From 67a0a0510e9f55c911c4bc7f519756c49767d88d Mon Sep 17 00:00:00 2001 From: Simon Gamma Date: Wed, 4 Jan 2023 12:56:45 +0100 Subject: [PATCH 441/757] eslint: update readme for maven --- plugin-maven/CHANGES.md | 2 + plugin-maven/README.md | 140 +++++++++++++++++++++++++++++++++++++++- 2 files changed, 141 insertions(+), 1 deletion(-) diff --git a/plugin-maven/CHANGES.md b/plugin-maven/CHANGES.md index 84e06aa847..f57a8dbbd4 100644 --- a/plugin-maven/CHANGES.md +++ b/plugin-maven/CHANGES.md @@ -3,6 +3,8 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format (starting after version `1.27.0`). ## [Unreleased] +### Added +* Added support for npm-based [ESLint](https://eslint.org/)-formatter for javascript and typescript ([#1433](https://github.com/diffplug/spotless/pull/1433)) ## [2.29.0] - 2023-01-02 ### Added diff --git a/plugin-maven/README.md b/plugin-maven/README.md index 80be3dbc37..b246bcb035 100644 --- a/plugin-maven/README.md +++ b/plugin-maven/README.md @@ -57,7 +57,8 @@ user@machine repo % mvn spotless:check - [Sql](#sql) ([dbeaver](#dbeaver)) - [Maven Pom](#maven-pom) ([sortPom](#sortpom)) - [Markdown](#markdown) ([flexmark](#flexmark)) - - [Typescript](#typescript) ([tsfmt](#tsfmt), [prettier](#prettier)) + - [Typescript](#typescript) ([tsfmt](#tsfmt), [prettier](#prettier), [ESLint](#eslint--typescript-)) + - [Javascript](#javascript) ([prettier](#prettier), [ESLint](#eslint--javascript-)) - Multiple languages - [Prettier](#prettier) ([plugins](#prettier-plugins), [npm detection](#npm-detection), [`.npmrc` detection](#npmrc-detection)) - [eclipse web tools platform](#eclipse-web-tools-platform) @@ -660,6 +661,7 @@ Currently, none of the available options can be configured yet. It uses only the + /* (C)$YEAR */ @@ -700,8 +702,144 @@ The auto-discovery of config files (up the file tree) will not work when using t For details, see the [npm detection](#npm-detection) and [`.npmrc` detection](#npmrc-detection) sections of prettier, which apply also to tsfmt. +### ESLint (typescript) + +[npm](https://www.npmjs.com/package/eslint). [changelog](https://github.com/eslint/eslint/blob/main/CHANGELOG.md). *Please note:* +The auto-discovery of config files (up the file tree) will not work when using ESLint within spotless, +hence you are required to provide resolvable file paths for config files, or alternatively provide the configuration inline. + +The configuration is very similar to the [ESLint (Javascript)](#eslint--javascript-) configuration. It differs in supported +styleguides and the requirement for a tsconfigFile. + +```xml + + + 8.30.0 + + 8.30.0 + 1.2.1 + + + + eslint + 8.30.0 + + + @eslint/my-plugin-typescript + 0.14.2 + + + + standard-with-typescript + + ${project.basedir}/.eslintrc.js + + { + env: { + browser: true, + es2021: true + }, + extends: 'standard-with-typescript', + overrides: [ + ], + parserOptions: { + ecmaVersion: 'latest', + sourceType: 'module', + project: './tsconfig.json', + }, + rules: { + } + } + + + ${project.basedir}/tsconfig.json + +``` + +**Prerequisite: ESLint requires a working NodeJS version** + +For details, see the [npm detection](#npm-detection) and [`.npmrc` detection](#npmrc-detection) sections of prettier, which apply also to ESLint. + +## Javascript + +[code](https://github.com/diffplug/spotless/blob/main/plugin-maven/src/main/java/com/diffplug/spotless/maven/javascript/Javascript.java). [available steps](https://github.com/diffplug/spotless/tree/main/plugin-maven/src/main/java/com/diffplug/spotless/maven/javascript). + +```xml + + + + src/**/*.js + + + + + + + /* (C)$YEAR */ + REGEX_TO_DEFINE_TOP_OF_FILE + + + +``` + + +### ESLint (Javascript) + +[npm](https://www.npmjs.com/package/eslint). [changelog](https://github.com/eslint/eslint/blob/main/CHANGELOG.md). *Please note:* +The auto-discovery of config files (up the file tree) will not work when using ESLint within spotless, +hence you are required to provide resolvable file paths for config files, or alternatively provide the configuration inline. + +The configuration is very similar to the [ESLint (Typescript)](#eslint--typescript-) configuration. It differs in supported +styleguides and no requirement for a tsconfig (of course). + +```xml + + + 8.30.0 + + 8.30.0 + 1.2.1 + + + + eslint + 8.30.0 + + + @eslint/my-plugin-javascript + 0.14.2 + + + + standard + + ${project.basedir}/.eslintrc.js + + { + env: { + browser: true, + es2021: true + }, + extends: 'standard', + overrides: [ + ], + parserOptions: { + ecmaVersion: 'latest', + sourceType: 'module' + }, + rules: { + } + } + + +``` + +**Prerequisite: ESLint requires a working NodeJS version** + +For details, see the [npm detection](#npm-detection) and [`.npmrc` detection](#npmrc-detection) sections of prettier, which apply also to ESLint. + ## Prettier [homepage](https://prettier.io/). [changelog](https://github.com/prettier/prettier/blob/master/CHANGELOG.md). [official plugins](https://prettier.io/docs/en/plugins.html#official-plugins). [community plugins](https://prettier.io/docs/en/plugins.html#community-plugins). Prettier is a formatter that can format almost every anything - JavaScript, JSX, Angular, Vue, Flow, TypeScript, CSS, Less, SCSS, HTML, JSON, GraphQL, Markdown (including GFM and MDX), and YAML. It can format even more [using plugins](https://prettier.io/docs/en/plugins.html) (PHP, Ruby, Swift, XML, Apex, Elm, Java (!!), Kotlin, pgSQL, .properties, solidity, svelte, toml, shellscript, ...). From e07082a5526e370b5355606d90298d70b8d8d32f Mon Sep 17 00:00:00 2001 From: Simon Gamma Date: Wed, 4 Jan 2023 12:56:56 +0100 Subject: [PATCH 442/757] eslint: unify naming in documentation --- plugin-gradle/README.md | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/plugin-gradle/README.md b/plugin-gradle/README.md index 6f498059b9..edd6c43bb6 100644 --- a/plugin-gradle/README.md +++ b/plugin-gradle/README.md @@ -69,8 +69,8 @@ Spotless supports all of Gradle's built-in performance features (incremental bui - [FreshMark](#freshmark) aka markdown - [Antlr4](#antlr4) ([antlr4formatter](#antlr4formatter)) - [SQL](#sql) ([dbeaver](#dbeaver), [prettier](#prettier)) - - [Typescript](#typescript) ([tsfmt](#tsfmt), [prettier](#prettier), [eslint](#eslint--typescript-)) - - [Javascript](#javascript) ([prettier](#prettier), [eslint](#eslint--javascript-)) + - [Typescript](#typescript) ([tsfmt](#tsfmt), [prettier](#prettier), [ESLint](#eslint--typescript-)) + - [Javascript](#javascript) ([prettier](#prettier), [ESLint](#eslint--javascript-)) - [JSON](#json) - Multiple languages - [Prettier](#prettier) ([plugins](#prettier-plugins), [npm detection](#npm-detection), [`.npmrc` detection](#npmrc-detection)) @@ -610,13 +610,13 @@ spotless { For details, see the [npm detection](#npm-detection) and [`.npmrc` detection](#npmrc-detection) sections of prettier, which apply also to tsfmt. -### eslint (Typescript) +### ESLint (Typescript) [npm](https://www.npmjs.com/package/eslint). [changelog](https://github.com/eslint/eslint/blob/main/CHANGELOG.md). *Please note:* -The auto-discovery of config files (up the file tree) will not work when using eslint within spotless, +The auto-discovery of config files (up the file tree) will not work when using ESLint within spotless, hence you are required to provide resolvable file paths for config files, or alternatively provide the configuration inline. -The configuration is very similar to the [eslint (Javascript)](#eslint--javascript-) configuration. It differs in supported +The configuration is very similar to the [ESLint (Javascript)](#eslint--javascript-) configuration. It differs in supported styleguides and the requirement for a tsconfigFile. ```gradle @@ -656,9 +656,9 @@ spotless { } ``` -**Prerequisite: eslint requires a working NodeJS version** +**Prerequisite: ESLint requires a working NodeJS version** -For details, see the [npm detection](#npm-detection) and [`.npmrc` detection](#npmrc-detection) sections of prettier, which apply also to eslint. +For details, see the [npm detection](#npm-detection) and [`.npmrc` detection](#npmrc-detection) sections of prettier, which apply also to ESLint. ## Javascript @@ -677,13 +677,13 @@ spotless { } ``` -### eslint (Javascript) +### ESLint (Javascript) [npm](https://www.npmjs.com/package/eslint). [changelog](https://github.com/eslint/eslint/blob/main/CHANGELOG.md). *Please note:* -The auto-discovery of config files (up the file tree) will not work when using eslint within spotless, +The auto-discovery of config files (up the file tree) will not work when using ESLint within spotless, hence you are required to provide resolvable file paths for config files, or alternatively provide the configuration inline. -The configuration is very similar to the [eslint (Typescript)](#eslint--typescript-) configuration. It differs in supported +The configuration is very similar to the [ESLint (Typescript)](#eslint--typescript-) configuration. It differs in supported styleguides and no requirement for a tsconfig (of course). ```gradle @@ -722,9 +722,9 @@ spotless { } ``` -**Prerequisite: eslint requires a working NodeJS version** +**Prerequisite: ESLint requires a working NodeJS version** -For details, see the [npm detection](#npm-detection) and [`.npmrc` detection](#npmrc-detection) sections of prettier, which apply also to eslint. +For details, see the [npm detection](#npm-detection) and [`.npmrc` detection](#npmrc-detection) sections of prettier, which apply also to ESLint. ## JSON From 2943c661623dddfd34c8a532fbdad8f1fdf32469 Mon Sep 17 00:00:00 2001 From: Simon Gamma Date: Wed, 4 Jan 2023 13:41:44 +0100 Subject: [PATCH 443/757] eslint: adapt to api changes in TestResource --- .../spotless/npm/EslintFormatterStepTest.java | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/testlib/src/test/java/com/diffplug/spotless/npm/EslintFormatterStepTest.java b/testlib/src/test/java/com/diffplug/spotless/npm/EslintFormatterStepTest.java index 5f53c9effa..a993f43090 100644 --- a/testlib/src/test/java/com/diffplug/spotless/npm/EslintFormatterStepTest.java +++ b/testlib/src/test/java/com/diffplug/spotless/npm/EslintFormatterStepTest.java @@ -19,6 +19,8 @@ import java.util.Map; import java.util.TreeMap; +import com.diffplug.spotless.ResourceHarness; + import org.junit.jupiter.api.Nested; import org.junit.jupiter.api.Test; import org.junit.jupiter.params.ParameterizedTest; @@ -73,8 +75,8 @@ void formattingUsingRulesetsFile(String ruleSetName) throws Exception { npmPathResolver(), new EslintConfig(eslintRc, null)); - try (StepHarnessWithFile stepHarness = StepHarnessWithFile.forStep(formatterStep)) { - stepHarness.testResource(dirtyFileFile, dirtyFile, cleanFile); + try (StepHarnessWithFile stepHarness = StepHarnessWithFile.forStep(this, formatterStep)) { + stepHarness.test(dirtyFileFile, ResourceHarness.getTestResource(dirtyFile), ResourceHarness.getTestResource(cleanFile)); } } } @@ -116,8 +118,8 @@ void formattingUsingRulesetsFile(String ruleSetName) throws Exception { npmPathResolver(), new EslintTypescriptConfig(eslintRc, null, tsconfigFile)); - try (StepHarnessWithFile stepHarness = StepHarnessWithFile.forStep(formatterStep)) { - stepHarness.testResource(dirtyFileFile, dirtyFile, cleanFile); + try (StepHarnessWithFile stepHarness = StepHarnessWithFile.forStep(this, formatterStep)) { + stepHarness.test(dirtyFileFile, ResourceHarness.getTestResource(dirtyFile), ResourceHarness.getTestResource(cleanFile)); } } } @@ -173,8 +175,8 @@ void formattingUsingInlineXoConfig() throws Exception { npmPathResolver(), new EslintTypescriptConfig(null, esLintConfig, tsconfigFile)); - try (StepHarnessWithFile stepHarness = StepHarnessWithFile.forStep(formatterStep)) { - stepHarness.testResource(dirtyFileFile, dirtyFile, cleanFile); + try (StepHarnessWithFile stepHarness = StepHarnessWithFile.forStep(this, formatterStep)) { + stepHarness.test(dirtyFileFile, ResourceHarness.getTestResource(dirtyFile), ResourceHarness.getTestResource(cleanFile)); } } } From ce21de7bbe2108a04b8b9b1c02a43cf01d889faf Mon Sep 17 00:00:00 2001 From: Simon Gamma Date: Wed, 4 Jan 2023 13:44:21 +0100 Subject: [PATCH 444/757] eslint: adapt PR number --- CHANGES.md | 2 +- plugin-gradle/CHANGES.md | 2 +- plugin-maven/CHANGES.md | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/CHANGES.md b/CHANGES.md index bf1798d7c2..95a657e334 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -11,7 +11,7 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format ( ## [Unreleased] ### Added -* Added support for npm-based [ESLint](https://eslint.org/)-formatter for javascript and typescript ([#1433](https://github.com/diffplug/spotless/pull/1433)) +* Added support for npm-based [ESLint](https://eslint.org/)-formatter for javascript and typescript ([#1453](https://github.com/diffplug/spotless/pull/1453)) ### Changes * Bump default Version for `prettier` from `2.0.5` to `2.8.1` * Bump the dev version of Gradle from `7.5.1` to `7.6` ([#1409](https://github.com/diffplug/spotless/pull/1409)) diff --git a/plugin-gradle/CHANGES.md b/plugin-gradle/CHANGES.md index d668f69483..7ed1bc7a20 100644 --- a/plugin-gradle/CHANGES.md +++ b/plugin-gradle/CHANGES.md @@ -4,7 +4,7 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format ( ## [Unreleased] ### Added -* Added support for npm-based [ESLint](https://eslint.org/) formatter for javascript and typescript ([#1433](https://github.com/diffplug/spotless/pull/1433)) +* Added support for npm-based [ESLint](https://eslint.org/) formatter for javascript and typescript ([#1453](https://github.com/diffplug/spotless/pull/1453)) ### Fixed * Prevent tool configurations from being resolved outside project ([#1447](https://github.com/diffplug/spotless/pull/1447) fixes [#1215](https://github.com/diffplug/spotless/issues/1215)) diff --git a/plugin-maven/CHANGES.md b/plugin-maven/CHANGES.md index f57a8dbbd4..a58bb2a30f 100644 --- a/plugin-maven/CHANGES.md +++ b/plugin-maven/CHANGES.md @@ -4,7 +4,7 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format ( ## [Unreleased] ### Added -* Added support for npm-based [ESLint](https://eslint.org/)-formatter for javascript and typescript ([#1433](https://github.com/diffplug/spotless/pull/1433)) +* Added support for npm-based [ESLint](https://eslint.org/)-formatter for javascript and typescript ([#1453](https://github.com/diffplug/spotless/pull/1453)) ## [2.29.0] - 2023-01-02 ### Added From 3a1d43bca5274dd83fe5f7667d85afe14c8d4400 Mon Sep 17 00:00:00 2001 From: Simon Gamma Date: Wed, 4 Jan 2023 13:53:53 +0100 Subject: [PATCH 445/757] eslint: add default version bump to CHANGES --- plugin-gradle/CHANGES.md | 2 ++ plugin-maven/CHANGES.md | 2 ++ 2 files changed, 4 insertions(+) diff --git a/plugin-gradle/CHANGES.md b/plugin-gradle/CHANGES.md index 7ed1bc7a20..bb05d07554 100644 --- a/plugin-gradle/CHANGES.md +++ b/plugin-gradle/CHANGES.md @@ -7,6 +7,8 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format ( * Added support for npm-based [ESLint](https://eslint.org/) formatter for javascript and typescript ([#1453](https://github.com/diffplug/spotless/pull/1453)) ### Fixed * Prevent tool configurations from being resolved outside project ([#1447](https://github.com/diffplug/spotless/pull/1447) fixes [#1215](https://github.com/diffplug/spotless/issues/1215)) +### Changes +* Bump default Version for `prettier` from `2.0.5` to `2.8.1` ## [6.12.1] - 2023-01-02 ### Fixed diff --git a/plugin-maven/CHANGES.md b/plugin-maven/CHANGES.md index a58bb2a30f..4f5d30cb74 100644 --- a/plugin-maven/CHANGES.md +++ b/plugin-maven/CHANGES.md @@ -5,6 +5,8 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format ( ## [Unreleased] ### Added * Added support for npm-based [ESLint](https://eslint.org/)-formatter for javascript and typescript ([#1453](https://github.com/diffplug/spotless/pull/1453)) +### Changes +* Bump default Version for `prettier` from `2.0.5` to `2.8.1` ## [2.29.0] - 2023-01-02 ### Added From b4f76b4f8cca59803ef720b651c39d00e88e0617 Mon Sep 17 00:00:00 2001 From: Simon Gamma Date: Wed, 4 Jan 2023 14:04:21 +0100 Subject: [PATCH 446/757] eslint: adapt maven code to match documentation --- .../spotless/maven/generic/Prettier.java | 16 +-------------- .../maven/javascript/AbstractEslint.java | 17 ++++++++++++++++ .../npm/AbstractNpmFormatterStepFactory.java | 20 +++++++++++++++++++ .../spotless/npm/EslintFormatterStepTest.java | 3 +-- 4 files changed, 39 insertions(+), 17 deletions(-) diff --git a/plugin-maven/src/main/java/com/diffplug/spotless/maven/generic/Prettier.java b/plugin-maven/src/main/java/com/diffplug/spotless/maven/generic/Prettier.java index ffe384b4d9..01ce2a5394 100644 --- a/plugin-maven/src/main/java/com/diffplug/spotless/maven/generic/Prettier.java +++ b/plugin-maven/src/main/java/com/diffplug/spotless/maven/generic/Prettier.java @@ -61,7 +61,7 @@ public FormatterStep newFormatterStep(FormatterStepConfig stepConfig) { if (prettierVersion != null && !prettierVersion.isEmpty()) { this.devDependencies = PrettierFormatterStep.defaultDevDependenciesWithPrettier(prettierVersion); } else if (devDependencyProperties != null) { - this.devDependencies = dependencyPropertiesAsMap(); + this.devDependencies = propertiesAsMap(this.devDependencyProperties); } // process config file or inline config @@ -100,20 +100,6 @@ public FormatterStep newFormatterStep(FormatterStepConfig stepConfig) { return PrettierFormatterStep.create(devDependencies, stepConfig.getProvisioner(), baseDir, buildDir, npmPathResolver, prettierConfig); } - private boolean moreThanOneNonNull(Object... objects) { - return Arrays.stream(objects) - .filter(Objects::nonNull) - .filter(o -> !(o instanceof String) || !((String) o).isEmpty()) // if it is a string, it should not be empty - .count() > 1; - } - - private Map dependencyPropertiesAsMap() { - return this.devDependencyProperties.stringPropertyNames() - .stream() - .map(name -> new AbstractMap.SimpleEntry<>(name, this.devDependencyProperties.getProperty(name))) - .collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue)); - } - private static IllegalArgumentException onlyOneConfig() { return new IllegalArgumentException(ERROR_MESSAGE_ONLY_ONE_CONFIG); } diff --git a/plugin-maven/src/main/java/com/diffplug/spotless/maven/javascript/AbstractEslint.java b/plugin-maven/src/main/java/com/diffplug/spotless/maven/javascript/AbstractEslint.java index b5fc156a57..1829f91b4e 100644 --- a/plugin-maven/src/main/java/com/diffplug/spotless/maven/javascript/AbstractEslint.java +++ b/plugin-maven/src/main/java/com/diffplug/spotless/maven/javascript/AbstractEslint.java @@ -17,6 +17,7 @@ import java.io.File; import java.util.Map; +import java.util.Properties; import java.util.TreeMap; import org.apache.maven.plugins.annotations.Parameter; @@ -30,6 +31,8 @@ public abstract class AbstractEslint extends AbstractNpmFormatterStepFactory { + public static final String ERROR_MESSAGE_ONLY_ONE_CONFIG = "must specify exactly one eslintVersion, devDependencies or devDependencyProperties"; + @Parameter protected String configFile; @@ -45,11 +48,21 @@ public abstract class AbstractEslint extends AbstractNpmFormatterStepFactory { @Parameter protected Map devDependencies; + @Parameter + protected Properties devDependencyProperties; + @Override public FormatterStep newFormatterStep(FormatterStepConfig stepConfig) { + // check if config is only setup in one way + if (moreThanOneNonNull(this.eslintVersion, this.devDependencies, this.devDependencyProperties)) { + throw onlyOneConfig(); + } + Map devDependencies = new TreeMap<>(); if (this.devDependencies != null) { devDependencies.putAll(this.devDependencies); + } else if (this.devDependencyProperties != null) { + devDependencies.putAll(propertiesAsMap(this.devDependencyProperties)); } else { Map defaultDependencies = createDefaultDependencies(); devDependencies.putAll(defaultDependencies); @@ -63,6 +76,10 @@ public FormatterStep newFormatterStep(FormatterStepConfig stepConfig) { return EslintFormatterStep.create(devDependencies, stepConfig.getProvisioner(), baseDir, buildDir, npmPathResolver, eslintConfig(stepConfig)); } + private static IllegalArgumentException onlyOneConfig() { + return new IllegalArgumentException(ERROR_MESSAGE_ONLY_ONE_CONFIG); + } + protected abstract EslintConfig eslintConfig(FormatterStepConfig stepConfig); private void addStyleGuideDevDependencies(Map devDependencies) { diff --git a/plugin-maven/src/main/java/com/diffplug/spotless/maven/npm/AbstractNpmFormatterStepFactory.java b/plugin-maven/src/main/java/com/diffplug/spotless/maven/npm/AbstractNpmFormatterStepFactory.java index 22ee5e0dba..5467f4c3bc 100644 --- a/plugin-maven/src/main/java/com/diffplug/spotless/maven/npm/AbstractNpmFormatterStepFactory.java +++ b/plugin-maven/src/main/java/com/diffplug/spotless/maven/npm/AbstractNpmFormatterStepFactory.java @@ -16,6 +16,12 @@ package com.diffplug.spotless.maven.npm; import java.io.File; +import java.util.AbstractMap; +import java.util.Arrays; +import java.util.Map; +import java.util.Objects; +import java.util.Properties; +import java.util.stream.Collectors; import org.apache.maven.plugins.annotations.Parameter; @@ -52,4 +58,18 @@ protected File baseDir(FormatterStepConfig stepConfig) { protected NpmPathResolver npmPathResolver(FormatterStepConfig stepConfig) { return new NpmPathResolver(npm(stepConfig), npmrc(stepConfig), baseDir(stepConfig)); } + + protected boolean moreThanOneNonNull(Object... objects) { + return Arrays.stream(objects) + .filter(Objects::nonNull) + .filter(o -> !(o instanceof String) || !((String) o).isEmpty()) // if it is a string, it should not be empty + .count() > 1; + } + + protected Map propertiesAsMap(Properties devDependencyProperties) { + return devDependencyProperties.stringPropertyNames() + .stream() + .map(name -> new AbstractMap.SimpleEntry<>(name, devDependencyProperties.getProperty(name))) + .collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue)); + } } diff --git a/testlib/src/test/java/com/diffplug/spotless/npm/EslintFormatterStepTest.java b/testlib/src/test/java/com/diffplug/spotless/npm/EslintFormatterStepTest.java index a993f43090..19f6e8c223 100644 --- a/testlib/src/test/java/com/diffplug/spotless/npm/EslintFormatterStepTest.java +++ b/testlib/src/test/java/com/diffplug/spotless/npm/EslintFormatterStepTest.java @@ -19,8 +19,6 @@ import java.util.Map; import java.util.TreeMap; -import com.diffplug.spotless.ResourceHarness; - import org.junit.jupiter.api.Nested; import org.junit.jupiter.api.Test; import org.junit.jupiter.params.ParameterizedTest; @@ -28,6 +26,7 @@ import com.diffplug.common.collect.ImmutableMap; import com.diffplug.spotless.FormatterStep; +import com.diffplug.spotless.ResourceHarness; import com.diffplug.spotless.StepHarnessWithFile; import com.diffplug.spotless.TestProvisioner; import com.diffplug.spotless.tag.NpmTest; From 45983197c3098f163dc6abf5c751684b21cbc6cc Mon Sep 17 00:00:00 2001 From: Simon Gamma Date: Wed, 4 Jan 2023 14:04:31 +0100 Subject: [PATCH 447/757] eslint: spotlessApply --- .../src/main/java/com/diffplug/spotless/extra/GitRatchet.java | 2 +- plugin-gradle/README.md | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/lib-extra/src/main/java/com/diffplug/spotless/extra/GitRatchet.java b/lib-extra/src/main/java/com/diffplug/spotless/extra/GitRatchet.java index 31f2f597f9..037d4d847b 100644 --- a/lib-extra/src/main/java/com/diffplug/spotless/extra/GitRatchet.java +++ b/lib-extra/src/main/java/com/diffplug/spotless/extra/GitRatchet.java @@ -1,5 +1,5 @@ /* - * Copyright 2020-2022 DiffPlug + * Copyright 2020-2023 DiffPlug * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/plugin-gradle/README.md b/plugin-gradle/README.md index edd6c43bb6..1e34cdc88a 100644 --- a/plugin-gradle/README.md +++ b/plugin-gradle/README.md @@ -662,7 +662,7 @@ For details, see the [npm detection](#npm-detection) and [`.npmrc` detection](#n ## Javascript -- `com.diffplug.gradle.spotless.JavascriptExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.12.0/com/diffplug/gradle/spotless/JavascriptExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/JavascriptExtension.java) +- `com.diffplug.gradle.spotless.JavascriptExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.12.1/com/diffplug/gradle/spotless/JavascriptExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/JavascriptExtension.java) ```gradle spotless { From f01b03891d980e06f215ae2706c39a5f2d20753e Mon Sep 17 00:00:00 2001 From: Benoit Lacelle Date: Wed, 4 Jan 2023 18:24:17 +0400 Subject: [PATCH 448/757] Fix tests --- .../spotless/maven/MavenIntegrationHarness.java | 4 ++++ .../com/diffplug/spotless/maven/json/JsonTest.java | 12 ++++++------ 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/plugin-maven/src/test/java/com/diffplug/spotless/maven/MavenIntegrationHarness.java b/plugin-maven/src/test/java/com/diffplug/spotless/maven/MavenIntegrationHarness.java index 939940a315..1976d577bb 100644 --- a/plugin-maven/src/test/java/com/diffplug/spotless/maven/MavenIntegrationHarness.java +++ b/plugin-maven/src/test/java/com/diffplug/spotless/maven/MavenIntegrationHarness.java @@ -156,6 +156,10 @@ protected void writePomWithMarkdownSteps(String... steps) throws IOException { writePom(groupWithSteps("markdown", including("**/*.md"), steps)); } + protected void writePomWithJsonSteps(String... steps) throws IOException { + writePom(groupWithSteps("json", including("**/*.json"), steps)); + } + protected void writePom(String... configuration) throws IOException { writePom(null, configuration, null); } diff --git a/plugin-maven/src/test/java/com/diffplug/spotless/maven/json/JsonTest.java b/plugin-maven/src/test/java/com/diffplug/spotless/maven/json/JsonTest.java index b7e666190a..fe6560cbec 100644 --- a/plugin-maven/src/test/java/com/diffplug/spotless/maven/json/JsonTest.java +++ b/plugin-maven/src/test/java/com/diffplug/spotless/maven/json/JsonTest.java @@ -22,19 +22,19 @@ public class JsonTest extends MavenIntegrationHarness { @Test public void testFormatJson_WithSimple_defaultConfig() throws Exception { - writePomWithPomSteps(""); + writePomWithJsonSteps(""); - setFile("json_test.json").toResource("json/json_dirty.json"); + setFile("json_test.json").toResource("json/sortByKeysBefore.json"); mavenRunner().withArguments("spotless:apply").runNoError().error(); - assertFile("json_test.json").sameAsResource("json/json_clean_default.json"); + assertFile("json_test.json").sameAsResource("json/sortByKeysAfterDisabled.json"); } @Test public void testFormatJson_WithGson_defaultConfig() throws Exception { - writePomWithPomSteps(""); + writePomWithJsonSteps(""); - setFile("json_test.json").toResource("json/json_dirty.json"); + setFile("json_test.json").toResource("json/sortByKeysBefore.json"); mavenRunner().withArguments("spotless:apply").runNoError().error(); - assertFile("json_test.json").sameAsResource("json/json_clean_default.json"); + assertFile("json_test.json").sameAsResource("json/sortByKeysAfterDisabled.json"); } } From 1d2290d61e019edc01f86c2ee838a00107935ac4 Mon Sep 17 00:00:00 2001 From: Benoit Lacelle Date: Wed, 4 Jan 2023 18:29:05 +0400 Subject: [PATCH 449/757] Fix README --- plugin-maven/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugin-maven/README.md b/plugin-maven/README.md index 70f3dfe1dc..dcc18a5dd6 100644 --- a/plugin-maven/README.md +++ b/plugin-maven/README.md @@ -703,7 +703,7 @@ For details, see the [npm detection](#npm-detection) and [`.npmrc` detection](#n ## JSON -- `com.diffplug.spotless.maven.json.Json` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.12.1/com/diffplug/gradle/spotless/JsonExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-maven/src/main/java/com/diffplug/spotless/maven/json/Json.java) +- `com.diffplug.spotless.maven.json.Json` [code](https://github.com/diffplug/spotless/blob/main/plugin-maven/src/main/java/com/diffplug/spotless/maven/json/json.java) ```xml From a4899012b2cc08c176264567e829979de1d33095 Mon Sep 17 00:00:00 2001 From: Benoit Lacelle Date: Wed, 4 Jan 2023 18:47:39 +0400 Subject: [PATCH 450/757] Fix style --- .../com/diffplug/spotless/maven/MavenIntegrationHarness.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugin-maven/src/test/java/com/diffplug/spotless/maven/MavenIntegrationHarness.java b/plugin-maven/src/test/java/com/diffplug/spotless/maven/MavenIntegrationHarness.java index 1976d577bb..9e9495da65 100644 --- a/plugin-maven/src/test/java/com/diffplug/spotless/maven/MavenIntegrationHarness.java +++ b/plugin-maven/src/test/java/com/diffplug/spotless/maven/MavenIntegrationHarness.java @@ -1,5 +1,5 @@ /* - * Copyright 2016-2022 DiffPlug + * Copyright 2016-2023 DiffPlug * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. From cf8bc0853f7cfa1364a12d076368bc099f9a9ef2 Mon Sep 17 00:00:00 2001 From: Abel Keszei Date: Wed, 4 Jan 2023 21:15:57 +0100 Subject: [PATCH 451/757] =?UTF-8?q?rename=20skipLinesPattern=20to=20skip?= =?UTF-8?q?=C3=85LinesMatching?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../spotless/generic/LicenseHeaderStep.java | 36 +++++++++---------- .../gradle/spotless/FormatExtension.java | 4 +-- 2 files changed, 20 insertions(+), 20 deletions(-) diff --git a/lib/src/main/java/com/diffplug/spotless/generic/LicenseHeaderStep.java b/lib/src/main/java/com/diffplug/spotless/generic/LicenseHeaderStep.java index d1fdf86e3e..8a46e08bda 100644 --- a/lib/src/main/java/com/diffplug/spotless/generic/LicenseHeaderStep.java +++ b/lib/src/main/java/com/diffplug/spotless/generic/LicenseHeaderStep.java @@ -60,16 +60,16 @@ public static LicenseHeaderStep headerDelimiter(ThrowingEx.Supplier head final String delimiter; final String yearSeparator; final Supplier yearMode; - final @Nullable String skipLinesPattern; + final @Nullable String skipLinesMatching; - private LicenseHeaderStep(@Nullable String name, @Nullable String contentPattern, ThrowingEx.Supplier headerLazy, String delimiter, String yearSeparator, Supplier yearMode, @Nullable String skipLinesPattern) { + private LicenseHeaderStep(@Nullable String name, @Nullable String contentPattern, ThrowingEx.Supplier headerLazy, String delimiter, String yearSeparator, Supplier yearMode, @Nullable String skipLinesMatching) { this.name = sanitizeName(name); this.contentPattern = sanitizePattern(contentPattern); this.headerLazy = Objects.requireNonNull(headerLazy); this.delimiter = Objects.requireNonNull(delimiter); this.yearSeparator = Objects.requireNonNull(yearSeparator); this.yearMode = Objects.requireNonNull(yearMode); - this.skipLinesPattern = sanitizePattern(skipLinesPattern); + this.skipLinesMatching = sanitizePattern(skipLinesMatching); } public String getName() { @@ -77,11 +77,11 @@ public String getName() { } public LicenseHeaderStep withName(String name) { - return new LicenseHeaderStep(name, contentPattern, headerLazy, delimiter, yearSeparator, yearMode, skipLinesPattern); + return new LicenseHeaderStep(name, contentPattern, headerLazy, delimiter, yearSeparator, yearMode, skipLinesMatching); } public LicenseHeaderStep withContentPattern(String contentPattern) { - return new LicenseHeaderStep(name, contentPattern, headerLazy, delimiter, yearSeparator, yearMode, skipLinesPattern); + return new LicenseHeaderStep(name, contentPattern, headerLazy, delimiter, yearSeparator, yearMode, skipLinesMatching); } public LicenseHeaderStep withHeaderString(String header) { @@ -89,15 +89,15 @@ public LicenseHeaderStep withHeaderString(String header) { } public LicenseHeaderStep withHeaderLazy(ThrowingEx.Supplier headerLazy) { - return new LicenseHeaderStep(name, contentPattern, headerLazy, delimiter, yearSeparator, yearMode, skipLinesPattern); + return new LicenseHeaderStep(name, contentPattern, headerLazy, delimiter, yearSeparator, yearMode, skipLinesMatching); } public LicenseHeaderStep withDelimiter(String delimiter) { - return new LicenseHeaderStep(name, contentPattern, headerLazy, delimiter, yearSeparator, yearMode, skipLinesPattern); + return new LicenseHeaderStep(name, contentPattern, headerLazy, delimiter, yearSeparator, yearMode, skipLinesMatching); } public LicenseHeaderStep withYearSeparator(String yearSeparator) { - return new LicenseHeaderStep(name, contentPattern, headerLazy, delimiter, yearSeparator, yearMode, skipLinesPattern); + return new LicenseHeaderStep(name, contentPattern, headerLazy, delimiter, yearSeparator, yearMode, skipLinesMatching); } public LicenseHeaderStep withYearMode(YearMode yearMode) { @@ -105,11 +105,11 @@ public LicenseHeaderStep withYearMode(YearMode yearMode) { } public LicenseHeaderStep withYearModeLazy(Supplier yearMode) { - return new LicenseHeaderStep(name, contentPattern, headerLazy, delimiter, yearSeparator, yearMode, skipLinesPattern); + return new LicenseHeaderStep(name, contentPattern, headerLazy, delimiter, yearSeparator, yearMode, skipLinesMatching); } - public LicenseHeaderStep withSkipLinesPattern(String skipLinesPattern) { - return new LicenseHeaderStep(name, contentPattern, headerLazy, delimiter, yearSeparator, yearMode, skipLinesPattern); + public LicenseHeaderStep withSkipLinesMatching(String skipLinesMatching) { + return new LicenseHeaderStep(name, contentPattern, headerLazy, delimiter, yearSeparator, yearMode, skipLinesMatching); } public FormatterStep build() { @@ -118,7 +118,7 @@ public FormatterStep build() { if (yearMode.get() == YearMode.SET_FROM_GIT) { formatterStep = FormatterStep.createNeverUpToDateLazy(name, () -> { boolean updateYear = false; // doesn't matter - Runtime runtime = new Runtime(headerLazy.get(), delimiter, yearSeparator, updateYear, skipLinesPattern); + Runtime runtime = new Runtime(headerLazy.get(), delimiter, yearSeparator, updateYear, skipLinesMatching); return FormatterFunc.needsFile(runtime::setLicenseHeaderYearsFromGitHistory); }); } else { @@ -136,7 +136,7 @@ public FormatterStep build() { default: throw new IllegalStateException(yearMode.toString()); } - return new Runtime(headerLazy.get(), delimiter, yearSeparator, updateYear, skipLinesPattern); + return new Runtime(headerLazy.get(), delimiter, yearSeparator, updateYear, skipLinesMatching); }, step -> step::format); } @@ -201,7 +201,7 @@ private static class Runtime implements Serializable { private static final long serialVersionUID = 1475199492829130965L; private final Pattern delimiterPattern; - private final @Nullable Pattern skipLinesPattern; + private final @Nullable Pattern skipLinesMatching; private final String yearSepOrFull; private final @Nullable String yearToday; private final @Nullable String beforeYear; @@ -210,7 +210,7 @@ private static class Runtime implements Serializable { private final boolean licenseHeaderWithRange; /** The license that we'd like enforced. */ - private Runtime(String licenseHeader, String delimiter, String yearSeparator, boolean updateYearWithLatest, @Nullable String skipLinesPattern) { + private Runtime(String licenseHeader, String delimiter, String yearSeparator, boolean updateYearWithLatest, @Nullable String skipLinesMatching) { if (delimiter.contains("\n")) { throw new IllegalArgumentException("The delimiter must not contain any newlines."); } @@ -220,7 +220,7 @@ private Runtime(String licenseHeader, String delimiter, String yearSeparator, bo licenseHeader = licenseHeader + "\n"; } this.delimiterPattern = Pattern.compile('^' + delimiter, Pattern.UNIX_LINES | Pattern.MULTILINE); - this.skipLinesPattern = skipLinesPattern == null ? null : Pattern.compile(skipLinesPattern); + this.skipLinesMatching = skipLinesMatching == null ? null : Pattern.compile(skipLinesMatching); Optional yearToken = getYearToken(licenseHeader); if (yearToken.isPresent()) { @@ -262,7 +262,7 @@ private static Optional getYearToken(String licenseHeader) { /** Formats the given string. */ private String format(String raw) { - if (skipLinesPattern == null) { + if (skipLinesMatching == null) { return addOrUpdateLicenseHeader(raw); } else { String[] lines = raw.split("\n"); @@ -271,7 +271,7 @@ private String format(String raw) { boolean lastMatched = true; for (String line : lines) { if (lastMatched) { - Matcher matcher = skipLinesPattern.matcher(line); + Matcher matcher = skipLinesMatching.matcher(line); if (matcher.find()) { skippedLinesBuilder.append(line).append('\n'); } else { 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 9c1e239d39..b8344c385f 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 @@ -462,8 +462,8 @@ public LicenseHeaderConfig yearSeparator(String yearSeparator) { return this; } - public LicenseHeaderConfig skipLinesPattern(String skipLinesPattern) { - builder = builder.withSkipLinesPattern(skipLinesPattern); + public LicenseHeaderConfig skipLinesMatching(String skipLinesMatching) { + builder = builder.withSkipLinesMatching(skipLinesMatching); replaceStep(createStep()); return this; } From 6dc01fa90418ca7eb995bfa42f7ef2eb207643fc Mon Sep 17 00:00:00 2001 From: Clayton Walker Date: Wed, 4 Jan 2023 14:06:51 -0700 Subject: [PATCH 452/757] Fix ktlint 0.48 --- gradle.properties | 2 + lib/build.gradle | 16 +++-- .../KtLintCompat0Dot48Dot1Adapter.java} | 64 ++++++++++++++----- .../glue/ktlint/KtlintFormatterFunc.java | 4 +- .../diffplug/spotless/kotlin/KtLintStep.java | 2 +- .../KtLintCompat0Dot48Dot1AdapterTest.java | 48 ++++++++++++++ .../resources/empty_class_body.kt | 3 + .../resources/fails_no_semicolons.kt | 3 + .../spotless/kotlin/KtLintStepTest.java | 4 +- 9 files changed, 119 insertions(+), 27 deletions(-) rename lib/src/{compatKtLint0Dot48Dot0/java/com/diffplug/spotless/glue/ktlint/compat/KtLintCompat0Dot48Dot0Adapter.java => compatKtLint0Dot48Dot1/java/com/diffplug/spotless/glue/ktlint/compat/KtLintCompat0Dot48Dot1Adapter.java} (57%) create mode 100644 lib/src/testCompatKtLint0Dot48Dot1/java/com/diffplug/spotless/glue/ktlint/compat/KtLintCompat0Dot48Dot1AdapterTest.java create mode 100644 lib/src/testCompatKtLint0Dot48Dot1/resources/empty_class_body.kt create mode 100644 lib/src/testCompatKtLint0Dot48Dot1/resources/fails_no_semicolons.kt diff --git a/gradle.properties b/gradle.properties index 577ed87535..001197ff4c 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1,5 +1,7 @@ # To fix metaspace errors org.gradle.jvmargs=-Xmx2g -XX:MaxMetaspaceSize=1024m -Dfile.encoding=UTF-8 +org.gradle.parallel=true +org.gradle.caching=true name=spotless description=Spotless - keep your code spotless with Gradle org=diffplug diff --git a/lib/build.gradle b/lib/build.gradle index 0cc258afca..826abf70a7 100644 --- a/lib/build.gradle +++ b/lib/build.gradle @@ -34,7 +34,7 @@ versionCompatibility { '0.45.2', '0.46.0', '0.47.0', - '0.48.0', + '0.48.1', ] targetSourceSetName = 'ktlint' } @@ -91,9 +91,9 @@ dependencies { compatKtLint0Dot47Dot0CompileOnly 'com.pinterest.ktlint:ktlint-core:0.47.0' compatKtLint0Dot47Dot0CompileOnly 'com.pinterest.ktlint:ktlint-ruleset-experimental:0.47.0' compatKtLint0Dot47Dot0CompileOnly 'com.pinterest.ktlint:ktlint-ruleset-standard:0.47.0' - compatKtLint0Dot48Dot0CompileOnly 'com.pinterest.ktlint:ktlint-core:0.48.0' - compatKtLint0Dot48Dot0CompileOnly 'com.pinterest.ktlint:ktlint-ruleset-experimental:0.48.0' - compatKtLint0Dot48Dot0CompileOnly 'com.pinterest.ktlint:ktlint-ruleset-standard:0.48.0' + compatKtLint0Dot48Dot1CompileOnly 'com.pinterest.ktlint:ktlint-core:0.48.1' + compatKtLint0Dot48Dot1CompileOnly 'com.pinterest.ktlint:ktlint-ruleset-experimental:0.48.1' + compatKtLint0Dot48Dot1CompileOnly 'com.pinterest.ktlint:ktlint-ruleset-standard:0.48.1' String VER_SCALAFMT="3.6.1" scalafmtCompileOnly "org.scalameta:scalafmt-core_2.13:$VER_SCALAFMT" @@ -105,10 +105,16 @@ dependencies { flexmarkCompileOnly 'com.vladsch.flexmark:flexmark-all:0.62.2' } +configurations.named('testCompatKtLint0Dot48Dot1Implementation').configure { + extendsFrom(configurations.testImplementation, configurations.compatKtLint0Dot48Dot1CompileOnly) +} + // we'll hold the core lib to a high standard spotbugs { reportLevel = 'low' } // low|medium|high (low = sensitive to even minor mistakes) -test { useJUnitPlatform() } +tasks.withType(Test).configureEach { + useJUnitPlatform() +} jar { for (glue in NEEDS_GLUE) { diff --git a/lib/src/compatKtLint0Dot48Dot0/java/com/diffplug/spotless/glue/ktlint/compat/KtLintCompat0Dot48Dot0Adapter.java b/lib/src/compatKtLint0Dot48Dot1/java/com/diffplug/spotless/glue/ktlint/compat/KtLintCompat0Dot48Dot1Adapter.java similarity index 57% rename from lib/src/compatKtLint0Dot48Dot0/java/com/diffplug/spotless/glue/ktlint/compat/KtLintCompat0Dot48Dot0Adapter.java rename to lib/src/compatKtLint0Dot48Dot1/java/com/diffplug/spotless/glue/ktlint/compat/KtLintCompat0Dot48Dot1Adapter.java index 8235c535a5..e47f950a1b 100644 --- a/lib/src/compatKtLint0Dot48Dot0/java/com/diffplug/spotless/glue/ktlint/compat/KtLintCompat0Dot48Dot0Adapter.java +++ b/lib/src/compatKtLint0Dot48Dot1/java/com/diffplug/spotless/glue/ktlint/compat/KtLintCompat0Dot48Dot1Adapter.java @@ -15,6 +15,9 @@ */ package com.diffplug.spotless.glue.ktlint.compat; +import java.nio.file.Paths; +import java.util.ArrayList; +import java.util.Collections; import java.util.LinkedHashSet; import java.util.List; import java.util.Map; @@ -23,15 +26,21 @@ import java.util.stream.Collectors; import java.util.stream.Stream; -import com.pinterest.ktlint.core.KtLint; +import com.pinterest.ktlint.core.KtLintRuleEngine; import com.pinterest.ktlint.core.LintError; import com.pinterest.ktlint.core.Rule; import com.pinterest.ktlint.core.RuleProvider; -import com.pinterest.ktlint.core.api.DefaultEditorConfigProperties; import com.pinterest.ktlint.core.api.EditorConfigDefaults; import com.pinterest.ktlint.core.api.EditorConfigOverride; import com.pinterest.ktlint.core.api.UsesEditorConfigProperties; +import com.pinterest.ktlint.core.api.editorconfig.CodeStyleEditorConfigPropertyKt; +import com.pinterest.ktlint.core.api.editorconfig.DisabledRulesEditorConfigPropertyKt; import com.pinterest.ktlint.core.api.editorconfig.EditorConfigProperty; +import com.pinterest.ktlint.core.api.editorconfig.IndentSizeEditorConfigPropertyKt; +import com.pinterest.ktlint.core.api.editorconfig.IndentStyleEditorConfigPropertyKt; +import com.pinterest.ktlint.core.api.editorconfig.InsertFinalNewLineEditorConfigPropertyKt; +import com.pinterest.ktlint.core.api.editorconfig.MaxLineLengthEditorConfigPropertyKt; +import com.pinterest.ktlint.core.api.editorconfig.RuleExecutionEditorConfigPropertyKt; import com.pinterest.ktlint.ruleset.experimental.ExperimentalRuleSetProvider; import com.pinterest.ktlint.ruleset.standard.StandardRuleSetProvider; @@ -39,7 +48,23 @@ import kotlin.Unit; import kotlin.jvm.functions.Function2; -public class KtLintCompat0Dot48Dot0Adapter implements KtLintCompatAdapter { +public class KtLintCompat0Dot48Dot1Adapter implements KtLintCompatAdapter { + + private static final List> DEFAULT_EDITOR_CONFIG_PROPERTIES; + + static { + List> list = new ArrayList<>(); + list.add(CodeStyleEditorConfigPropertyKt.getCODE_STYLE_PROPERTY()); + //noinspection deprecation + list.add(DisabledRulesEditorConfigPropertyKt.getDISABLED_RULES_PROPERTY()); + //noinspection KotlinInternalInJava,deprecation + list.add(DisabledRulesEditorConfigPropertyKt.getKTLINT_DISABLED_RULES_PROPERTY()); + list.add(IndentStyleEditorConfigPropertyKt.getINDENT_STYLE_PROPERTY()); + list.add(IndentSizeEditorConfigPropertyKt.getINDENT_SIZE_PROPERTY()); + list.add(InsertFinalNewLineEditorConfigPropertyKt.getINSERT_FINAL_NEWLINE_PROPERTY()); + list.add(MaxLineLengthEditorConfigPropertyKt.getMAX_LINE_LENGTH_PROPERTY()); + DEFAULT_EDITOR_CONFIG_PROPERTIES = Collections.unmodifiableList(list); + } static class FormatterCallback implements Function2 { @Override @@ -47,7 +72,7 @@ public Unit invoke(LintError lint, Boolean corrected) { if (!corrected) { KtLintCompatReporting.report(lint.getLine(), lint.getCol(), lint.getRuleId(), lint.getDetail()); } - return null; + return Unit.INSTANCE; } } @@ -66,7 +91,7 @@ public String format(final String text, final String name, final boolean isScrip EditorConfigOverride editorConfigOverride; if (editorConfigOverrideMap.isEmpty()) { - editorConfigOverride = EditorConfigOverride.Companion.getEmptyEditorConfigOverride(); + editorConfigOverride = EditorConfigOverride.Companion.getEMPTY_EDITOR_CONFIG_OVERRIDE(); } else { editorConfigOverride = createEditorConfigOverride(allRuleProviders.stream().map( RuleProvider::createNewRuleInstance).collect( @@ -74,17 +99,10 @@ public String format(final String text, final String name, final boolean isScrip editorConfigOverrideMap); } - return KtLint.INSTANCE.format(new KtLint.ExperimentalParams( - name, - text, - allRuleProviders, - userData, - formatterCallback, - isScript, - false, - EditorConfigDefaults.Companion.getEmptyEditorConfigDefaults(), - editorConfigOverride, - false)); + EditorConfigDefaults editorConfigDefaults = EditorConfigDefaults.Companion.getEMPTY_EDITOR_CONFIG_DEFAULTS(); + boolean isInvokedFromCli = false; + KtLintRuleEngine ktLintRuleEngine = new KtLintRuleEngine(allRuleProviders, editorConfigDefaults, editorConfigOverride, isInvokedFromCli); + return ktLintRuleEngine.format(text, Paths.get(name), formatterCallback); } /** @@ -98,7 +116,7 @@ private static EditorConfigOverride createEditorConfigOverride(final List // Create a mapping of properties to their names based on rule properties and default properties Map> supportedProperties = Stream - .concat(ruleProperties, DefaultEditorConfigProperties.INSTANCE.getEditorConfigProperties().stream()) + .concat(ruleProperties, DEFAULT_EDITOR_CONFIG_PROPERTIES.stream()) .distinct() .collect(Collectors.toMap(EditorConfigProperty::getName, property -> property)); @@ -109,6 +127,18 @@ private static EditorConfigOverride createEditorConfigOverride(final List EditorConfigProperty property = supportedProperties.get(entry.getKey()); if (property != null) { return new Pair<>(property, entry.getValue()); + } else if (entry.getKey().startsWith("ktlint_")) { + String[] parts = entry.getKey().substring(7).split("_", 2); + if (parts.length == 1) { + // convert ktlint_{ruleset} to {ruleset} + String qualifiedRuleId = parts[0]; + property = RuleExecutionEditorConfigPropertyKt.createRuleSetExecutionEditorConfigProperty(qualifiedRuleId); + } else { + // convert ktlint_{ruleset}_{rulename} to {ruleset}:{rulename} + String qualifiedRuleId = parts[0] + ":" + parts[1]; + property = RuleExecutionEditorConfigPropertyKt.createRuleExecutionEditorConfigProperty(qualifiedRuleId); + } + return new Pair<>(property, entry.getValue()); } else { return null; } diff --git a/lib/src/ktlint/java/com/diffplug/spotless/glue/ktlint/KtlintFormatterFunc.java b/lib/src/ktlint/java/com/diffplug/spotless/glue/ktlint/KtlintFormatterFunc.java index fc64cdb23e..5be69e819c 100644 --- a/lib/src/ktlint/java/com/diffplug/spotless/glue/ktlint/KtlintFormatterFunc.java +++ b/lib/src/ktlint/java/com/diffplug/spotless/glue/ktlint/KtlintFormatterFunc.java @@ -27,7 +27,7 @@ import com.diffplug.spotless.glue.ktlint.compat.KtLintCompat0Dot45Dot2Adapter; import com.diffplug.spotless.glue.ktlint.compat.KtLintCompat0Dot46Dot0Adapter; import com.diffplug.spotless.glue.ktlint.compat.KtLintCompat0Dot47Dot0Adapter; -import com.diffplug.spotless.glue.ktlint.compat.KtLintCompat0Dot48Dot0Adapter; +import com.diffplug.spotless.glue.ktlint.compat.KtLintCompat0Dot48Dot1Adapter; import com.diffplug.spotless.glue.ktlint.compat.KtLintCompatAdapter; public class KtlintFormatterFunc implements FormatterFunc.NeedsFile { @@ -44,7 +44,7 @@ public KtlintFormatterFunc(String version, boolean isScript, boolean useExperime int minorVersion = Integer.parseInt(version.split("\\.")[1]); if (minorVersion >= 48) { // ExperimentalParams lost two constructor arguments, EditorConfigProperty moved to its own class - this.adapter = new KtLintCompat0Dot48Dot0Adapter(); + this.adapter = new KtLintCompat0Dot48Dot1Adapter(); } else if (minorVersion == 47) { // rename RuleSet to RuleProvider this.adapter = new KtLintCompat0Dot47Dot0Adapter(); diff --git a/lib/src/main/java/com/diffplug/spotless/kotlin/KtLintStep.java b/lib/src/main/java/com/diffplug/spotless/kotlin/KtLintStep.java index b444f0f1a7..7efbb911e3 100644 --- a/lib/src/main/java/com/diffplug/spotless/kotlin/KtLintStep.java +++ b/lib/src/main/java/com/diffplug/spotless/kotlin/KtLintStep.java @@ -33,7 +33,7 @@ public class KtLintStep { // prevent direct instantiation private KtLintStep() {} - private static final String DEFAULT_VERSION = "0.48.0"; + private static final String DEFAULT_VERSION = "0.48.1"; static final String NAME = "ktlint"; static final String PACKAGE_PRE_0_32 = "com.github.shyiko"; static final String PACKAGE = "com.pinterest"; diff --git a/lib/src/testCompatKtLint0Dot48Dot1/java/com/diffplug/spotless/glue/ktlint/compat/KtLintCompat0Dot48Dot1AdapterTest.java b/lib/src/testCompatKtLint0Dot48Dot1/java/com/diffplug/spotless/glue/ktlint/compat/KtLintCompat0Dot48Dot1AdapterTest.java new file mode 100644 index 0000000000..d4416d83f3 --- /dev/null +++ b/lib/src/testCompatKtLint0Dot48Dot1/java/com/diffplug/spotless/glue/ktlint/compat/KtLintCompat0Dot48Dot1AdapterTest.java @@ -0,0 +1,48 @@ +package com.diffplug.spotless.glue.ktlint.compat; + +import java.io.IOException; +import java.io.InputStream; +import java.nio.file.Files; +import java.nio.file.Path; +import java.util.HashMap; +import java.util.Map; + +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.io.TempDir; + +import static org.junit.jupiter.api.Assertions.assertEquals; + +public class KtLintCompat0Dot48Dot1AdapterTest { + @Test + public void testDefaults(@TempDir Path path) throws IOException { + KtLintCompat0Dot48Dot1Adapter KtLintCompat0Dot48Dot1Adapter = new KtLintCompat0Dot48Dot1Adapter(); + try (InputStream is = KtLintCompat0Dot48Dot1AdapterTest.class.getResourceAsStream("/empty_class_body.kt")) { + Files.copy(is, path.resolve("empty_class_body.kt")); + } + String text = new String(Files.readAllBytes(path.resolve("empty_class_body.kt"))); + + Map userData = new HashMap<>(); + + Map editorConfigOverrideMap = new HashMap<>(); + + String formatted = KtLintCompat0Dot48Dot1Adapter.format(text, "empty_class_body.kt", false, false, userData, editorConfigOverrideMap); + assertEquals("class empty_class_body\n", formatted); + } + + @Test + public void testEditorConfigCanDisable(@TempDir Path path) throws IOException { + KtLintCompat0Dot48Dot1Adapter KtLintCompat0Dot48Dot1Adapter = new KtLintCompat0Dot48Dot1Adapter(); + try (InputStream is = KtLintCompat0Dot48Dot1AdapterTest.class.getResourceAsStream("/fails_no_semicolons.kt")) { + Files.copy(is, path.resolve("fails_no_semicolons.kt")); + } + String text = new String(Files.readAllBytes(path.resolve("fails_no_semicolons.kt"))); + + Map userData = new HashMap<>(); + + Map editorConfigOverrideMap = new HashMap<>(); + editorConfigOverrideMap.put("ktlint_standard_no-semi", "disabled"); + + String formatted = KtLintCompat0Dot48Dot1Adapter.format(text, "fails_no_semicolons.kt", false, false, userData, editorConfigOverrideMap); + assertEquals("class fails_no_semicolons {\n\tval i = 0;\n}\n", formatted); + } +} diff --git a/lib/src/testCompatKtLint0Dot48Dot1/resources/empty_class_body.kt b/lib/src/testCompatKtLint0Dot48Dot1/resources/empty_class_body.kt new file mode 100644 index 0000000000..b84774d572 --- /dev/null +++ b/lib/src/testCompatKtLint0Dot48Dot1/resources/empty_class_body.kt @@ -0,0 +1,3 @@ +class empty_class_body { + +} diff --git a/lib/src/testCompatKtLint0Dot48Dot1/resources/fails_no_semicolons.kt b/lib/src/testCompatKtLint0Dot48Dot1/resources/fails_no_semicolons.kt new file mode 100644 index 0000000000..20ab460913 --- /dev/null +++ b/lib/src/testCompatKtLint0Dot48Dot1/resources/fails_no_semicolons.kt @@ -0,0 +1,3 @@ +class fails_no_semicolons { + val i = 0; +} diff --git a/testlib/src/test/java/com/diffplug/spotless/kotlin/KtLintStepTest.java b/testlib/src/test/java/com/diffplug/spotless/kotlin/KtLintStepTest.java index 94de314e0b..4ad9620d48 100644 --- a/testlib/src/test/java/com/diffplug/spotless/kotlin/KtLintStepTest.java +++ b/testlib/src/test/java/com/diffplug/spotless/kotlin/KtLintStepTest.java @@ -130,8 +130,8 @@ void works0_47_1() { } @Test - void works0_48_0() { - FormatterStep step = KtLintStep.create("0.48.0", TestProvisioner.mavenCentral()); + void works0_48_1() { + FormatterStep step = KtLintStep.create("0.48.1", TestProvisioner.mavenCentral()); StepHarnessWithFile.forStep(this, step) .testResource("kotlin/ktlint/basic.dirty", "kotlin/ktlint/basic.clean") .testResourceExceptionMsg("kotlin/ktlint/unsolvable.dirty").isEqualTo("Error on line: 1, column: 1\n" + From 4550b66e70910b4733500a6fa4534197fbaa0dd6 Mon Sep 17 00:00:00 2001 From: Clayton Walker Date: Wed, 4 Jan 2023 14:13:36 -0700 Subject: [PATCH 453/757] Add change to changelog --- CHANGES.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGES.md b/CHANGES.md index a7e3516607..d595ff8df6 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -11,6 +11,7 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format ( ## [Unreleased] ### Changes +* Fix ktlint 0.48.x and bump to ktlint 0.48.1 * Bump the dev version of Gradle from `7.5.1` to `7.6` ([#1409](https://github.com/diffplug/spotless/pull/1409)) * We also removed the no-longer-required dependency `org.codehaus.groovy:groovy-xml` * Breaking changes to Spotless' internal testing infrastructure `testlib` ([#1443](https://github.com/diffplug/spotless/pull/1443)) From 2936d3cbd6493cab8a2fd27d797b6f8fd2d920eb Mon Sep 17 00:00:00 2001 From: Clayton Walker Date: Wed, 4 Jan 2023 14:14:54 -0700 Subject: [PATCH 454/757] Add link to issue in changelog --- CHANGES.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGES.md b/CHANGES.md index d595ff8df6..ee73f019a5 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -11,7 +11,7 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format ( ## [Unreleased] ### Changes -* Fix ktlint 0.48.x and bump to ktlint 0.48.1 +* Fix ktlint 0.48.x and bump to ktlint 0.48.1 ([#1444](https://github.com/diffplug/spotless/issues/1444)) * Bump the dev version of Gradle from `7.5.1` to `7.6` ([#1409](https://github.com/diffplug/spotless/pull/1409)) * We also removed the no-longer-required dependency `org.codehaus.groovy:groovy-xml` * Breaking changes to Spotless' internal testing infrastructure `testlib` ([#1443](https://github.com/diffplug/spotless/pull/1443)) From 3a3583b836815c6b431fdce0ddd9a9ea3af03a81 Mon Sep 17 00:00:00 2001 From: Abel Keszei Date: Wed, 4 Jan 2023 22:16:49 +0100 Subject: [PATCH 455/757] add maven support --- .../java/com/diffplug/spotless/generic/LicenseHeaderStep.java | 2 +- .../com/diffplug/spotless/maven/generic/LicenseHeader.java | 4 ++++ 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/lib/src/main/java/com/diffplug/spotless/generic/LicenseHeaderStep.java b/lib/src/main/java/com/diffplug/spotless/generic/LicenseHeaderStep.java index 8a46e08bda..46312ca07a 100644 --- a/lib/src/main/java/com/diffplug/spotless/generic/LicenseHeaderStep.java +++ b/lib/src/main/java/com/diffplug/spotless/generic/LicenseHeaderStep.java @@ -108,7 +108,7 @@ public LicenseHeaderStep withYearModeLazy(Supplier yearMode) { return new LicenseHeaderStep(name, contentPattern, headerLazy, delimiter, yearSeparator, yearMode, skipLinesMatching); } - public LicenseHeaderStep withSkipLinesMatching(String skipLinesMatching) { + public LicenseHeaderStep withSkipLinesMatching(@Nullable String skipLinesMatching) { return new LicenseHeaderStep(name, contentPattern, headerLazy, delimiter, yearSeparator, yearMode, skipLinesMatching); } diff --git a/plugin-maven/src/main/java/com/diffplug/spotless/maven/generic/LicenseHeader.java b/plugin-maven/src/main/java/com/diffplug/spotless/maven/generic/LicenseHeader.java index ee2ae4fda0..22386c6892 100644 --- a/plugin-maven/src/main/java/com/diffplug/spotless/maven/generic/LicenseHeader.java +++ b/plugin-maven/src/main/java/com/diffplug/spotless/maven/generic/LicenseHeader.java @@ -37,6 +37,9 @@ public class LicenseHeader implements FormatterStepFactory { @Parameter private String delimiter; + @Parameter + private String skipLinesMatching; + @Override public final FormatterStep newFormatterStep(FormatterStepConfig config) { String delimiterString = delimiter != null ? delimiter : config.getLicenseHeaderDelimiter(); @@ -53,6 +56,7 @@ public final FormatterStep newFormatterStep(FormatterStepConfig config) { } return LicenseHeaderStep.headerDelimiter(() -> readFileOrContent(config), delimiterString) .withYearMode(yearMode) + .withSkipLinesMatching(skipLinesMatching) .build() .filterByFile(LicenseHeaderStep.unsupportedJvmFilesFilter()); } else { From 41c3fe9f07ddfa7145e1e582de923537393e0c67 Mon Sep 17 00:00:00 2001 From: Clayton Walker Date: Wed, 4 Jan 2023 14:21:19 -0700 Subject: [PATCH 456/757] Update all change logs --- CHANGES.md | 4 +++- plugin-gradle/CHANGES.md | 3 +++ plugin-maven/CHANGES.md | 4 ++++ 3 files changed, 10 insertions(+), 1 deletion(-) diff --git a/CHANGES.md b/CHANGES.md index ee73f019a5..50e4d83141 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -10,8 +10,9 @@ This document is intended for Spotless developers. We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format (starting after version `1.27.0`). ## [Unreleased] +### Fixed +* Support `ktlint` 0.48+ new rule disabling syntax ([#1456](https://github.com/diffplug/spotless/pull/1456)) fixes ([#1444](https://github.com/diffplug/spotless/issues/1444)) ### Changes -* Fix ktlint 0.48.x and bump to ktlint 0.48.1 ([#1444](https://github.com/diffplug/spotless/issues/1444)) * Bump the dev version of Gradle from `7.5.1` to `7.6` ([#1409](https://github.com/diffplug/spotless/pull/1409)) * We also removed the no-longer-required dependency `org.codehaus.groovy:groovy-xml` * Breaking changes to Spotless' internal testing infrastructure `testlib` ([#1443](https://github.com/diffplug/spotless/pull/1443)) @@ -19,6 +20,7 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format ( * `StepHarness` now operates on `Formatter` rather than a `FormatterStep` * `StepHarnessWithFile` now takes a `ResourceHarness` in its constructor to handle the file manipulation parts * Standardized that we test exception *messages*, not types, which will ease the transition to linting later on + * Bump default `ktlint` version to latest `0.47.1` -> `0.48.1` ([#1456](https://github.com/diffplug/spotless/pull/1456)) ## [2.31.1] - 2023-01-02 ### Fixed diff --git a/plugin-gradle/CHANGES.md b/plugin-gradle/CHANGES.md index c5f464069f..56ed8d6c1e 100644 --- a/plugin-gradle/CHANGES.md +++ b/plugin-gradle/CHANGES.md @@ -5,6 +5,9 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format ( ## [Unreleased] ### Fixed * Prevent tool configurations from being resolved outside project ([#1447](https://github.com/diffplug/spotless/pull/1447) fixes [#1215](https://github.com/diffplug/spotless/issues/1215)) +* Support `ktlint` 0.48+ new rule disabling syntax ([#1456](https://github.com/diffplug/spotless/pull/1456)) fixes ([#1444](https://github.com/diffplug/spotless/issues/1444)) +### Changes +* Bump default `ktlint` version to latest `0.47.1` -> `0.48.1` ([#1456](https://github.com/diffplug/spotless/pull/1456)) ## [6.12.1] - 2023-01-02 ### Fixed diff --git a/plugin-maven/CHANGES.md b/plugin-maven/CHANGES.md index 84e06aa847..bc706437fd 100644 --- a/plugin-maven/CHANGES.md +++ b/plugin-maven/CHANGES.md @@ -3,6 +3,10 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format (starting after version `1.27.0`). ## [Unreleased] +### Fixed +* Support `ktlint` 0.48+ new rule disabling syntax ([#1456](https://github.com/diffplug/spotless/pull/1456)) fixes ([#1444](https://github.com/diffplug/spotless/issues/1444)) +### Changes +* Bump default `ktlint` version to latest `0.47.1` -> `0.48.1` ([#1456](https://github.com/diffplug/spotless/pull/1456)) ## [2.29.0] - 2023-01-02 ### Added From 954e6b58b5c02bbab86b0998cc1232717cba0c7f Mon Sep 17 00:00:00 2001 From: Clayton Walker Date: Wed, 4 Jan 2023 14:33:30 -0700 Subject: [PATCH 457/757] Run spotless --- .../KtLintCompat0Dot48Dot1AdapterTest.java | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/lib/src/testCompatKtLint0Dot48Dot1/java/com/diffplug/spotless/glue/ktlint/compat/KtLintCompat0Dot48Dot1AdapterTest.java b/lib/src/testCompatKtLint0Dot48Dot1/java/com/diffplug/spotless/glue/ktlint/compat/KtLintCompat0Dot48Dot1AdapterTest.java index d4416d83f3..a49de57a97 100644 --- a/lib/src/testCompatKtLint0Dot48Dot1/java/com/diffplug/spotless/glue/ktlint/compat/KtLintCompat0Dot48Dot1AdapterTest.java +++ b/lib/src/testCompatKtLint0Dot48Dot1/java/com/diffplug/spotless/glue/ktlint/compat/KtLintCompat0Dot48Dot1AdapterTest.java @@ -1,5 +1,22 @@ +/* + * Copyright 2023 DiffPlug + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ package com.diffplug.spotless.glue.ktlint.compat; +import static org.junit.jupiter.api.Assertions.assertEquals; + import java.io.IOException; import java.io.InputStream; import java.nio.file.Files; @@ -10,8 +27,6 @@ import org.junit.jupiter.api.Test; import org.junit.jupiter.api.io.TempDir; -import static org.junit.jupiter.api.Assertions.assertEquals; - public class KtLintCompat0Dot48Dot1AdapterTest { @Test public void testDefaults(@TempDir Path path) throws IOException { From 1a19da11f18dcdf60d821abda4ebd77a0a4e4648 Mon Sep 17 00:00:00 2001 From: Clayton Walker Date: Wed, 4 Jan 2023 15:34:22 -0700 Subject: [PATCH 458/757] Use older format function that doesn't load .editorconfig --- .../compat/KtLintCompat0Dot48Dot1Adapter.java | 18 ++++++++++++------ .../KtLintCompat0Dot48Dot1AdapterTest.java | 1 + .../spotless/kotlin/KtLintStepTest.java | 10 ++++++++++ 3 files changed, 23 insertions(+), 6 deletions(-) diff --git a/lib/src/compatKtLint0Dot48Dot1/java/com/diffplug/spotless/glue/ktlint/compat/KtLintCompat0Dot48Dot1Adapter.java b/lib/src/compatKtLint0Dot48Dot1/java/com/diffplug/spotless/glue/ktlint/compat/KtLintCompat0Dot48Dot1Adapter.java index e47f950a1b..4329c18db9 100644 --- a/lib/src/compatKtLint0Dot48Dot1/java/com/diffplug/spotless/glue/ktlint/compat/KtLintCompat0Dot48Dot1Adapter.java +++ b/lib/src/compatKtLint0Dot48Dot1/java/com/diffplug/spotless/glue/ktlint/compat/KtLintCompat0Dot48Dot1Adapter.java @@ -15,7 +15,6 @@ */ package com.diffplug.spotless.glue.ktlint.compat; -import java.nio.file.Paths; import java.util.ArrayList; import java.util.Collections; import java.util.LinkedHashSet; @@ -26,7 +25,7 @@ import java.util.stream.Collectors; import java.util.stream.Stream; -import com.pinterest.ktlint.core.KtLintRuleEngine; +import com.pinterest.ktlint.core.KtLint; import com.pinterest.ktlint.core.LintError; import com.pinterest.ktlint.core.Rule; import com.pinterest.ktlint.core.RuleProvider; @@ -99,10 +98,17 @@ public String format(final String text, final String name, final boolean isScrip editorConfigOverrideMap); } - EditorConfigDefaults editorConfigDefaults = EditorConfigDefaults.Companion.getEMPTY_EDITOR_CONFIG_DEFAULTS(); - boolean isInvokedFromCli = false; - KtLintRuleEngine ktLintRuleEngine = new KtLintRuleEngine(allRuleProviders, editorConfigDefaults, editorConfigOverride, isInvokedFromCli); - return ktLintRuleEngine.format(text, Paths.get(name), formatterCallback); + return KtLint.INSTANCE.format(new KtLint.ExperimentalParams( + name, + text, + allRuleProviders, + userData, + formatterCallback, + isScript, + false, + EditorConfigDefaults.Companion.getEMPTY_EDITOR_CONFIG_DEFAULTS(), + editorConfigOverride, + false)); } /** diff --git a/lib/src/testCompatKtLint0Dot48Dot1/java/com/diffplug/spotless/glue/ktlint/compat/KtLintCompat0Dot48Dot1AdapterTest.java b/lib/src/testCompatKtLint0Dot48Dot1/java/com/diffplug/spotless/glue/ktlint/compat/KtLintCompat0Dot48Dot1AdapterTest.java index a49de57a97..31e6caf824 100644 --- a/lib/src/testCompatKtLint0Dot48Dot1/java/com/diffplug/spotless/glue/ktlint/compat/KtLintCompat0Dot48Dot1AdapterTest.java +++ b/lib/src/testCompatKtLint0Dot48Dot1/java/com/diffplug/spotless/glue/ktlint/compat/KtLintCompat0Dot48Dot1AdapterTest.java @@ -55,6 +55,7 @@ public void testEditorConfigCanDisable(@TempDir Path path) throws IOException { Map userData = new HashMap<>(); Map editorConfigOverrideMap = new HashMap<>(); + editorConfigOverrideMap.put("indent_style", "tab"); editorConfigOverrideMap.put("ktlint_standard_no-semi", "disabled"); String formatted = KtLintCompat0Dot48Dot1Adapter.format(text, "fails_no_semicolons.kt", false, false, userData, editorConfigOverrideMap); diff --git a/testlib/src/test/java/com/diffplug/spotless/kotlin/KtLintStepTest.java b/testlib/src/test/java/com/diffplug/spotless/kotlin/KtLintStepTest.java index 4ad9620d48..1be0c7b72f 100644 --- a/testlib/src/test/java/com/diffplug/spotless/kotlin/KtLintStepTest.java +++ b/testlib/src/test/java/com/diffplug/spotless/kotlin/KtLintStepTest.java @@ -129,6 +129,16 @@ void works0_47_1() { "Wildcard import"); } + @Test + void works0_48_0() { + FormatterStep step = KtLintStep.create("0.48.0", TestProvisioner.mavenCentral()); + StepHarnessWithFile.forStep(this, step) + .testResource("kotlin/ktlint/basic.dirty", "kotlin/ktlint/basic.clean") + .testResourceExceptionMsg("kotlin/ktlint/unsolvable.dirty").isEqualTo("Error on line: 1, column: 1\n" + + "rule: no-wildcard-imports\n" + + "Wildcard import"); + } + @Test void works0_48_1() { FormatterStep step = KtLintStep.create("0.48.1", TestProvisioner.mavenCentral()); From 11971ab599ee730d3c1fc6b995198a31f7525f6a Mon Sep 17 00:00:00 2001 From: Clayton Walker Date: Wed, 4 Jan 2023 15:43:03 -0700 Subject: [PATCH 459/757] Fix UTF-8 encoder errors --- .../ktlint/compat/KtLintCompat0Dot48Dot1AdapterTest.java | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/lib/src/testCompatKtLint0Dot48Dot1/java/com/diffplug/spotless/glue/ktlint/compat/KtLintCompat0Dot48Dot1AdapterTest.java b/lib/src/testCompatKtLint0Dot48Dot1/java/com/diffplug/spotless/glue/ktlint/compat/KtLintCompat0Dot48Dot1AdapterTest.java index 31e6caf824..ca9d603e5c 100644 --- a/lib/src/testCompatKtLint0Dot48Dot1/java/com/diffplug/spotless/glue/ktlint/compat/KtLintCompat0Dot48Dot1AdapterTest.java +++ b/lib/src/testCompatKtLint0Dot48Dot1/java/com/diffplug/spotless/glue/ktlint/compat/KtLintCompat0Dot48Dot1AdapterTest.java @@ -19,6 +19,7 @@ import java.io.IOException; import java.io.InputStream; +import java.nio.charset.StandardCharsets; import java.nio.file.Files; import java.nio.file.Path; import java.util.HashMap; @@ -34,7 +35,7 @@ public void testDefaults(@TempDir Path path) throws IOException { try (InputStream is = KtLintCompat0Dot48Dot1AdapterTest.class.getResourceAsStream("/empty_class_body.kt")) { Files.copy(is, path.resolve("empty_class_body.kt")); } - String text = new String(Files.readAllBytes(path.resolve("empty_class_body.kt"))); + String text = new String(Files.readAllBytes(path.resolve("empty_class_body.kt")), StandardCharsets.UTF_8); Map userData = new HashMap<>(); @@ -50,7 +51,7 @@ public void testEditorConfigCanDisable(@TempDir Path path) throws IOException { try (InputStream is = KtLintCompat0Dot48Dot1AdapterTest.class.getResourceAsStream("/fails_no_semicolons.kt")) { Files.copy(is, path.resolve("fails_no_semicolons.kt")); } - String text = new String(Files.readAllBytes(path.resolve("fails_no_semicolons.kt"))); + String text = new String(Files.readAllBytes(path.resolve("fails_no_semicolons.kt")), StandardCharsets.UTF_8); Map userData = new HashMap<>(); From b853169fb7650db131b6cc8efa9b538c4613cde2 Mon Sep 17 00:00:00 2001 From: Clayton Walker Date: Wed, 4 Jan 2023 15:56:42 -0700 Subject: [PATCH 460/757] Remove org.gradle settings --- gradle.properties | 2 -- 1 file changed, 2 deletions(-) diff --git a/gradle.properties b/gradle.properties index 001197ff4c..577ed87535 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1,7 +1,5 @@ # To fix metaspace errors org.gradle.jvmargs=-Xmx2g -XX:MaxMetaspaceSize=1024m -Dfile.encoding=UTF-8 -org.gradle.parallel=true -org.gradle.caching=true name=spotless description=Spotless - keep your code spotless with Gradle org=diffplug From 3540242e98591391c2e766656d5e9ed53f6ca746 Mon Sep 17 00:00:00 2001 From: Simon Gamma Date: Thu, 5 Jan 2023 07:00:51 +0100 Subject: [PATCH 461/757] eslint: reduce log-noise, cleanup error codes --- .../com/diffplug/spotless/npm/NpmProcess.java | 6 +++++- .../com/diffplug/spotless/npm/common-serve.js | 13 ++++++++++--- .../com/diffplug/spotless/npm/eslint-serve.js | 18 +++++++++--------- .../diffplug/spotless/npm/prettier-serve.js | 2 +- .../com/diffplug/spotless/npm/tsfmt-serve.js | 2 +- .../npm/PrettierFormatterStepTest.java | 2 +- 6 files changed, 27 insertions(+), 16 deletions(-) diff --git a/lib/src/main/java/com/diffplug/spotless/npm/NpmProcess.java b/lib/src/main/java/com/diffplug/spotless/npm/NpmProcess.java index e2fd07682c..8be94a9ea3 100644 --- a/lib/src/main/java/com/diffplug/spotless/npm/NpmProcess.java +++ b/lib/src/main/java/com/diffplug/spotless/npm/NpmProcess.java @@ -34,7 +34,11 @@ class NpmProcess { } void install() { - npmAwait("install", "--no-audit", "--no-package-lock", "--prefer-offline"); + npmAwait("install", + "--no-audit", + "--no-package-lock", + "--no-fund", + "--prefer-offline"); } Process start() { diff --git a/lib/src/main/resources/com/diffplug/spotless/npm/common-serve.js b/lib/src/main/resources/com/diffplug/spotless/npm/common-serve.js index 3e031cedea..c1c9d62757 100644 --- a/lib/src/main/resources/com/diffplug/spotless/npm/common-serve.js +++ b/lib/src/main/resources/com/diffplug/spotless/npm/common-serve.js @@ -1,4 +1,5 @@ -// this file will be glued to the top of the specific xy-server.js file +// this file will be glued to the top of the specific xy-serve.js file +const debug_serve = false; // set to true for debug log output in node process const GracefulShutdownManager = require("@moebius/http-graceful-shutdown").GracefulShutdownManager; const express = require("express"); const app = express(); @@ -7,8 +8,14 @@ app.use(express.json({ limit: "50mb" })); const fs = require("fs"); +function debugLog() { + if (debug_serve) { + console.log.apply(this, arguments) + } +} + var listener = app.listen(0, "127.0.0.1", () => { - console.log("Server running on port " + listener.address().port); + debugLog("Server running on port " + listener.address().port); fs.writeFile("server.port.tmp", "" + listener.address().port, function(err) { if (err) { return console.log(err); @@ -26,7 +33,7 @@ const shutdownManager = new GracefulShutdownManager(listener); app.post("/shutdown", (req, res) => { res.status(200).send("Shutting down"); setTimeout(function() { - shutdownManager.terminate(() => console.log("graceful shutdown finished.")); + shutdownManager.terminate(() => debugLog("graceful shutdown finished.")); }, 200); }); diff --git a/lib/src/main/resources/com/diffplug/spotless/npm/eslint-serve.js b/lib/src/main/resources/com/diffplug/spotless/npm/eslint-serve.js index 1f1b1fab5a..8b60e56dc8 100644 --- a/lib/src/main/resources/com/diffplug/spotless/npm/eslint-serve.js +++ b/lib/src/main/resources/com/diffplug/spotless/npm/eslint-serve.js @@ -9,14 +9,14 @@ app.post("/eslint/format", async (req, res) => { const ESLintOverrideConfigFile = format_data.eslint_override_config_file; if (!ESLintOverrideConfig && !ESLintOverrideConfigFile) { - res.status(501).send("Error while formatting: No config provided"); + res.status(400).send("Error while formatting: No config provided"); return; } const filePath = format_data.file_path; if (!filePath) { - res.status(501).send("Error while formatting: No file path provided"); + res.status(400).send("Error while formatting: No file path provided"); return; } @@ -41,8 +41,8 @@ app.post("/eslint/format", async (req, res) => { eval("ESLintOptions.overrideConfig = " + ESLintOverrideConfig); } - console.log("using options: " + JSON.stringify(ESLintOptions)); - console.log("format input: ", format_data.file_content); + debugLog("using options: " + JSON.stringify(ESLintOptions)); + debugLog("format input: ", format_data.file_content); const eslint = new ESLint(ESLintOptions); @@ -50,18 +50,18 @@ app.post("/eslint/format", async (req, res) => { const lintTextOptions = { filePath: filePath, } - console.log("lintTextOptions", lintTextOptions); + debugLog("lintTextOptions", lintTextOptions); // LintResult[] // https://eslint.org/docs/latest/developer-guide/nodejs-api#-lintresult-type const results = await eslint.lintText(format_data.file_content, lintTextOptions); if (results.length !== 1) { - res.status(501).send("Error while formatting: Unexpected number of results: " + JSON.stringify(results)); + res.status(500).send("Error while formatting: Unexpected number of results: " + JSON.stringify(results)); return; } const result = results[0]; - console.log("result: " + JSON.stringify(result)); + debugLog("result: " + JSON.stringify(result)); if (result.fatalErrorCount && result.fatalErrorCount > 0) { - res.status(501).send("Fatal error while formatting: " + JSON.stringify(result.messages)); + res.status(500).send("Fatal error while formatting: " + JSON.stringify(result.messages)); return; } const formatted = result.output || result.source || format_data.file_content; @@ -69,6 +69,6 @@ app.post("/eslint/format", async (req, res) => { res.send(formatted); } catch (err) { console.log("error", err); - res.status(501).send("Error while formatting: " + err); + res.status(500).send("Error while formatting: " + err); } }); diff --git a/lib/src/main/resources/com/diffplug/spotless/npm/prettier-serve.js b/lib/src/main/resources/com/diffplug/spotless/npm/prettier-serve.js index d4ce13bbbc..b60daaaa77 100644 --- a/lib/src/main/resources/com/diffplug/spotless/npm/prettier-serve.js +++ b/lib/src/main/resources/com/diffplug/spotless/npm/prettier-serve.js @@ -27,7 +27,7 @@ app.post("/prettier/format", (req, res) => { try { formatted_file_content = prettier.format(format_data.file_content, format_data.config_options); } catch(err) { - res.status(501).send("Error while formatting: " + err); + res.status(500).send("Error while formatting: " + err); return; } res.set("Content-Type", "text/plain"); diff --git a/lib/src/main/resources/com/diffplug/spotless/npm/tsfmt-serve.js b/lib/src/main/resources/com/diffplug/spotless/npm/tsfmt-serve.js index 8ec25565ff..b9f20a1472 100644 --- a/lib/src/main/resources/com/diffplug/spotless/npm/tsfmt-serve.js +++ b/lib/src/main/resources/com/diffplug/spotless/npm/tsfmt-serve.js @@ -25,6 +25,6 @@ app.post("/tsfmt/format", (req, res) => { res.set("Content-Type", "text/plain"); res.send(resultMap.dest); }).catch(reason => { - res.status(501).send(reason); + res.status(500).send(reason); }); }); diff --git a/testlib/src/test/java/com/diffplug/spotless/npm/PrettierFormatterStepTest.java b/testlib/src/test/java/com/diffplug/spotless/npm/PrettierFormatterStepTest.java index 9db218efb5..acc756fa31 100644 --- a/testlib/src/test/java/com/diffplug/spotless/npm/PrettierFormatterStepTest.java +++ b/testlib/src/test/java/com/diffplug/spotless/npm/PrettierFormatterStepTest.java @@ -116,7 +116,7 @@ void verifyPrettierErrorMessageIsRelayed() throws Exception { new PrettierConfig(null, ImmutableMap.of("parser", "postcss"))); try (StepHarnessWithFile stepHarness = StepHarnessWithFile.forStep(this, formatterStep)) { stepHarness.testResourceExceptionMsg("npm/prettier/filetypes/scss/scss.dirty").isEqualTo( - "Unexpected response status code at /prettier/format [HTTP 501] -- (Error while formatting: Error: Couldn't resolve parser \"postcss\")"); + "Unexpected response status code at /prettier/format [HTTP 500] -- (Error while formatting: Error: Couldn't resolve parser \"postcss\")"); } } } From 98c023b8f972ac37574f0bdae5d407bc502b50f0 Mon Sep 17 00:00:00 2001 From: Simon Gamma Date: Thu, 5 Jan 2023 09:35:10 +0100 Subject: [PATCH 462/757] eslint: spotbugs fix --- .../java/com/diffplug/spotless/npm/EslintTypescriptConfig.java | 2 ++ 1 file changed, 2 insertions(+) diff --git a/lib/src/main/java/com/diffplug/spotless/npm/EslintTypescriptConfig.java b/lib/src/main/java/com/diffplug/spotless/npm/EslintTypescriptConfig.java index fc45f8bd7b..ea3e2046b3 100644 --- a/lib/src/main/java/com/diffplug/spotless/npm/EslintTypescriptConfig.java +++ b/lib/src/main/java/com/diffplug/spotless/npm/EslintTypescriptConfig.java @@ -27,6 +27,8 @@ public class EslintTypescriptConfig extends EslintConfig { + private static final long serialVersionUID = -126864670181617006L; + @SuppressFBWarnings("SE_TRANSIENT_FIELD_NOT_RESTORED") @Nullable private final transient File typescriptConfigPath; From 667eef943c0f89ca2415e913cf6d8206ff8c5585 Mon Sep 17 00:00:00 2001 From: Eir Nym <485399+eirnym@users.noreply.github.com> Date: Thu, 5 Jan 2023 13:14:32 +0100 Subject: [PATCH 463/757] Pass editor config and filenames correctly --- .../glue/ktlint/KtlintFormatterFunc.java | 2 +- .../diffplug/spotless/kotlin/KtLintStep.java | 57 +++++++++++++++---- .../gradle/spotless/KotlinExtension.java | 16 ++++-- .../spotless/KotlinGradleExtension.java | 12 +++- 4 files changed, 68 insertions(+), 19 deletions(-) diff --git a/lib/src/ktlint/java/com/diffplug/spotless/glue/ktlint/KtlintFormatterFunc.java b/lib/src/ktlint/java/com/diffplug/spotless/glue/ktlint/KtlintFormatterFunc.java index cfd6ab859c..034a782be6 100644 --- a/lib/src/ktlint/java/com/diffplug/spotless/glue/ktlint/KtlintFormatterFunc.java +++ b/lib/src/ktlint/java/com/diffplug/spotless/glue/ktlint/KtlintFormatterFunc.java @@ -73,6 +73,6 @@ public String applyWithFile(String unix, File file) { if (editorConfigPath != null) { absoluteEditorConfigPath = editorConfigPath.getOnlyFile().getAbsolutePath(); } - return adapter.format(unix, file.getName(), isScript, useExperimental, absoluteEditorConfigPath, userData, editorConfigOverrideMap); + return adapter.format(unix, file.getAbsolutePath(), isScript, useExperimental, absoluteEditorConfigPath, userData, editorConfigOverrideMap); } } diff --git a/lib/src/main/java/com/diffplug/spotless/kotlin/KtLintStep.java b/lib/src/main/java/com/diffplug/spotless/kotlin/KtLintStep.java index 4d29a01394..20e7d885e1 100644 --- a/lib/src/main/java/com/diffplug/spotless/kotlin/KtLintStep.java +++ b/lib/src/main/java/com/diffplug/spotless/kotlin/KtLintStep.java @@ -23,6 +23,8 @@ import java.util.Objects; import java.util.TreeMap; +import javax.annotation.Nullable; + import com.diffplug.spotless.FileSignature; import com.diffplug.spotless.FormatterFunc; import com.diffplug.spotless.FormatterStep; @@ -51,25 +53,50 @@ public static FormatterStep create(String version, Provisioner provisioner) { public static FormatterStep create(String version, Provisioner provisioner, boolean useExperimental, Map userData, Map editorConfigOverride) { - return create(version, provisioner, false, useExperimental, userData, editorConfigOverride); + return create(version, provisioner, false, useExperimental, null, userData, editorConfigOverride); } public static FormatterStep createForScript(String version, Provisioner provisioner) { - return create(version, provisioner, true, false, Collections.emptyMap(), Collections.emptyMap()); + return create(version, provisioner, true, false, null, Collections.emptyMap(), Collections.emptyMap()); } - public static FormatterStep createForScript(String version, Provisioner provisioner, boolean useExperimental, - FileSignature editorConfigPath, Map userData, Map editorConfigOverride) { - return create(version, provisioner, true, useExperimental, userData, editorConfigOverride); + public static FormatterStep createForScript(String version, + Provisioner provisioner, + boolean useExperimental, + @Nullable FileSignature editorConfigPath, + Map userData, + Map editorConfigOverride) { + return create(version, + provisioner, + true, + useExperimental, + editorConfigPath, + userData, + editorConfigOverride); } - private static FormatterStep create(String version, Provisioner provisioner, boolean isScript, boolean useExperimental, - Map userData, Map editorConfigOverride) { - return create(version, provisioner, useExperimental, userData, editorConfigOverride); + private static FormatterStep create(String version, + Provisioner provisioner, + boolean isScript, + boolean useExperimental, + Map userData, + Map editorConfigOverride) { + return create(version, + provisioner, + useExperimental, + isScript, + null, + userData, + editorConfigOverride); } - public static FormatterStep create(String version, Provisioner provisioner, boolean isScript, boolean useExperimental, - FileSignature editorConfig, Map userData, Map editorConfigOverride) { + public static FormatterStep create(String version, + Provisioner provisioner, + boolean isScript, + boolean useExperimental, + @Nullable FileSignature editorConfig, + Map userData, + Map editorConfigOverride) { Objects.requireNonNull(version, "version"); Objects.requireNonNull(provisioner, "provisioner"); return FormatterStep.createLazy(NAME, @@ -92,10 +119,16 @@ static final class State implements Serializable { private final TreeMap userData; private final TreeMap editorConfigOverride; private final String version; + @Nullable private final FileSignature editorConfigPath; - State(String version, Provisioner provisioner, boolean isScript, boolean useExperimental, - FileSignature editorConfigPath, Map userData, Map editorConfigOverride) throws IOException { + State(String version, + Provisioner provisioner, + boolean isScript, + boolean useExperimental, + @Nullable FileSignature editorConfigPath, + Map userData, + Map editorConfigOverride) throws IOException { this.version = version; String coordinate; diff --git a/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/KotlinExtension.java b/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/KotlinExtension.java index 8af03aaefd..9ebc290219 100644 --- a/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/KotlinExtension.java +++ b/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/KotlinExtension.java @@ -17,12 +17,14 @@ import static com.diffplug.spotless.kotlin.KotlinConstants.LICENSE_HEADER_DELIMITER; +import java.io.File; import java.io.IOException; import java.util.Collections; import java.util.Map; import java.util.Objects; import java.util.function.Consumer; +import javax.annotation.Nullable; import javax.inject.Inject; import org.gradle.api.GradleException; @@ -58,12 +60,17 @@ public LicenseHeaderConfig licenseHeaderFile(Object licenseHeaderFile) { } /** Adds the specified version of ktlint. */ - public KotlinFormatExtension ktlint(String version) { + public KotlinFormatExtension ktlint(String version) throws IOException { Objects.requireNonNull(version); - return new KotlinFormatExtension(version, false, null, Collections.emptyMap(), Collections.emptyMap()); + FileSignature editorConfigPath = null; + File defaultEditorConfig = getProject().getRootProject().file(".editorconfig"); + if (defaultEditorConfig.exists() && defaultEditorConfig.isFile()) { + editorConfigPath = FileSignature.signAsList(defaultEditorConfig); + } + return new KotlinFormatExtension(version, false, editorConfigPath, Collections.emptyMap(), Collections.emptyMap()); } - public KotlinFormatExtension ktlint() { + public KotlinFormatExtension ktlint() throws IOException { return ktlint(KtLintStep.defaultVersion()); } @@ -71,11 +78,12 @@ public class KotlinFormatExtension { private final String version; private boolean useExperimental; + @Nullable private FileSignature editorConfigPath; private Map userData; private Map editorConfigOverride; - KotlinFormatExtension(String version, boolean useExperimental, FileSignature editorConfigPath, Map config, + KotlinFormatExtension(String version, boolean useExperimental, @Nullable FileSignature editorConfigPath, Map config, Map editorConfigOverride) { this.version = version; this.useExperimental = useExperimental; diff --git a/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/KotlinGradleExtension.java b/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/KotlinGradleExtension.java index a06c640060..ec645a8972 100644 --- a/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/KotlinGradleExtension.java +++ b/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/KotlinGradleExtension.java @@ -22,6 +22,7 @@ import java.util.Objects; import java.util.function.Consumer; +import javax.annotation.Nullable; import javax.inject.Inject; import com.diffplug.common.collect.ImmutableSortedMap; @@ -47,7 +48,7 @@ public KotlinGradleExtension(SpotlessExtension spotless) { public KotlinFormatExtension ktlint(String version) throws IOException { Objects.requireNonNull(version, "version"); FileSignature editorConfigPath = null; - File defaultEditorConfig = getProject().getRootProject().file(".editorConfig"); + File defaultEditorConfig = getProject().getRootProject().file(".editorconfig"); if (defaultEditorConfig.exists() && defaultEditorConfig.isFile()) { editorConfigPath = FileSignature.signAsList(defaultEditorConfig); } @@ -62,6 +63,7 @@ public class KotlinFormatExtension { private final String version; private boolean useExperimental; + @Nullable private FileSignature editorConfigPath; private Map userData; private Map editorConfigOverride; @@ -110,7 +112,13 @@ public KotlinFormatExtension editorConfigOverride(Map editorConf } private FormatterStep createStep() { - return KtLintStep.createForScript(version, provisioner(), useExperimental, editorConfigPath, userData, editorConfigOverride); + return KtLintStep.createForScript( + version, + provisioner(), + useExperimental, + editorConfigPath, + userData, + editorConfigOverride); } } From 03eae65e91b89d8ccc3ff71c6a5b2a4b4d243748 Mon Sep 17 00:00:00 2001 From: Eir Nym <485399+eirnym@users.noreply.github.com> Date: Thu, 5 Jan 2023 13:17:23 +0100 Subject: [PATCH 464/757] EditorConfig: Use Path for files for KtLint --- .../ktlint/compat/KtLintCompat0Dot31Dot0Adapter.java | 9 +++++---- .../ktlint/compat/KtLintCompat0Dot32Dot0Adapter.java | 9 +++++---- .../ktlint/compat/KtLintCompat0Dot34Dot2Adapter.java | 11 ++++++----- .../ktlint/compat/KtLintCompat0Dot45Dot2Adapter.java | 11 ++++++----- .../ktlint/compat/KtLintCompat0Dot46Dot0Adapter.java | 11 ++++++----- .../ktlint/compat/KtLintCompat0Dot47Dot0Adapter.java | 10 +++++----- .../ktlint/compat/KtLintCompat0Dot48Dot0Adapter.java | 10 +++++----- .../glue/ktlint/compat/KtLintCompatAdapter.java | 5 +++-- .../spotless/glue/ktlint/KtlintFormatterFunc.java | 2 +- 9 files changed, 42 insertions(+), 36 deletions(-) diff --git a/lib/src/compatKtLint0Dot31Dot0/java/com/diffplug/spotless/glue/ktlint/compat/KtLintCompat0Dot31Dot0Adapter.java b/lib/src/compatKtLint0Dot31Dot0/java/com/diffplug/spotless/glue/ktlint/compat/KtLintCompat0Dot31Dot0Adapter.java index a10bf9be0e..42d6e0c5bd 100644 --- a/lib/src/compatKtLint0Dot31Dot0/java/com/diffplug/spotless/glue/ktlint/compat/KtLintCompat0Dot31Dot0Adapter.java +++ b/lib/src/compatKtLint0Dot31Dot0/java/com/diffplug/spotless/glue/ktlint/compat/KtLintCompat0Dot31Dot0Adapter.java @@ -15,6 +15,7 @@ */ package com.diffplug.spotless.glue.ktlint.compat; +import java.nio.file.Path; import java.util.ArrayList; import java.util.List; import java.util.Map; @@ -41,10 +42,10 @@ public Unit invoke(LintError lint, Boolean corrected) { } @Override - public String format(final String text, final String name, final boolean isScript, - final boolean useExperimental, - String editorConfigPath, final Map userData, - final Map editorConfigOverrideMap) { + public String format(final String text, Path path, final boolean isScript, + final boolean useExperimental, + String editorConfigPath, final Map userData, + final Map editorConfigOverrideMap) { final FormatterCallback formatterCallback = new FormatterCallback(); final List rulesets = new ArrayList<>(); diff --git a/lib/src/compatKtLint0Dot32Dot0/java/com/diffplug/spotless/glue/ktlint/compat/KtLintCompat0Dot32Dot0Adapter.java b/lib/src/compatKtLint0Dot32Dot0/java/com/diffplug/spotless/glue/ktlint/compat/KtLintCompat0Dot32Dot0Adapter.java index 3f98abe3b3..11d3c0d8e5 100644 --- a/lib/src/compatKtLint0Dot32Dot0/java/com/diffplug/spotless/glue/ktlint/compat/KtLintCompat0Dot32Dot0Adapter.java +++ b/lib/src/compatKtLint0Dot32Dot0/java/com/diffplug/spotless/glue/ktlint/compat/KtLintCompat0Dot32Dot0Adapter.java @@ -15,6 +15,7 @@ */ package com.diffplug.spotless.glue.ktlint.compat; +import java.nio.file.Path; import java.util.ArrayList; import java.util.List; import java.util.Map; @@ -41,10 +42,10 @@ public Unit invoke(LintError lint, Boolean corrected) { } @Override - public String format(final String text, final String name, final boolean isScript, - final boolean useExperimental, - String editorConfigPath, final Map userData, - final Map editorConfigOverrideMap) { + public String format(final String text, Path path, final boolean isScript, + final boolean useExperimental, + String editorConfigPath, final Map userData, + final Map editorConfigOverrideMap) { final FormatterCallback formatterCallback = new FormatterCallback(); final List rulesets = new ArrayList<>(); diff --git a/lib/src/compatKtLint0Dot34Dot2/java/com/diffplug/spotless/glue/ktlint/compat/KtLintCompat0Dot34Dot2Adapter.java b/lib/src/compatKtLint0Dot34Dot2/java/com/diffplug/spotless/glue/ktlint/compat/KtLintCompat0Dot34Dot2Adapter.java index 0352a8e1f0..63d59ff74e 100644 --- a/lib/src/compatKtLint0Dot34Dot2/java/com/diffplug/spotless/glue/ktlint/compat/KtLintCompat0Dot34Dot2Adapter.java +++ b/lib/src/compatKtLint0Dot34Dot2/java/com/diffplug/spotless/glue/ktlint/compat/KtLintCompat0Dot34Dot2Adapter.java @@ -15,6 +15,7 @@ */ package com.diffplug.spotless.glue.ktlint.compat; +import java.nio.file.Path; import java.util.ArrayList; import java.util.List; import java.util.Map; @@ -41,10 +42,10 @@ public Unit invoke(LintError lint, Boolean corrected) { } @Override - public String format(final String text, final String name, final boolean isScript, - final boolean useExperimental, - String editorConfigPath, final Map userData, - final Map editorConfigOverrideMap) { + public String format(final String text, Path path, final boolean isScript, + final boolean useExperimental, + String editorConfigPath, final Map userData, + final Map editorConfigOverrideMap) { final FormatterCallback formatterCallback = new FormatterCallback(); final List rulesets = new ArrayList<>(); @@ -55,7 +56,7 @@ public String format(final String text, final String name, final boolean isScrip } return KtLint.INSTANCE.format(new KtLint.Params( - name, + path.toFile().getAbsolutePath(), text, rulesets, userData, diff --git a/lib/src/compatKtLint0Dot45Dot2/java/com/diffplug/spotless/glue/ktlint/compat/KtLintCompat0Dot45Dot2Adapter.java b/lib/src/compatKtLint0Dot45Dot2/java/com/diffplug/spotless/glue/ktlint/compat/KtLintCompat0Dot45Dot2Adapter.java index 15c2238d5d..b7b2435d93 100644 --- a/lib/src/compatKtLint0Dot45Dot2/java/com/diffplug/spotless/glue/ktlint/compat/KtLintCompat0Dot45Dot2Adapter.java +++ b/lib/src/compatKtLint0Dot45Dot2/java/com/diffplug/spotless/glue/ktlint/compat/KtLintCompat0Dot45Dot2Adapter.java @@ -15,6 +15,7 @@ */ package com.diffplug.spotless.glue.ktlint.compat; +import java.nio.file.Path; import java.util.ArrayList; import java.util.Arrays; import java.util.List; @@ -49,10 +50,10 @@ public Unit invoke(LintError lint, Boolean corrected) { } @Override - public String format(final String text, final String name, final boolean isScript, - final boolean useExperimental, - String editorConfigPath, final Map userData, - final Map editorConfigOverrideMap) { + public String format(final String text, Path path, final boolean isScript, + final boolean useExperimental, + String editorConfigPath, final Map userData, + final Map editorConfigOverrideMap) { final FormatterCallback formatterCallback = new FormatterCallback(); final List rulesets = new ArrayList<>(); @@ -70,7 +71,7 @@ public String format(final String text, final String name, final boolean isScrip } return KtLint.INSTANCE.format(new KtLint.ExperimentalParams( - name, + path.toFile().getAbsolutePath(), text, rulesets, userData, diff --git a/lib/src/compatKtLint0Dot46Dot0/java/com/diffplug/spotless/glue/ktlint/compat/KtLintCompat0Dot46Dot0Adapter.java b/lib/src/compatKtLint0Dot46Dot0/java/com/diffplug/spotless/glue/ktlint/compat/KtLintCompat0Dot46Dot0Adapter.java index 28eba672a0..198ce7ef9c 100644 --- a/lib/src/compatKtLint0Dot46Dot0/java/com/diffplug/spotless/glue/ktlint/compat/KtLintCompat0Dot46Dot0Adapter.java +++ b/lib/src/compatKtLint0Dot46Dot0/java/com/diffplug/spotless/glue/ktlint/compat/KtLintCompat0Dot46Dot0Adapter.java @@ -15,6 +15,7 @@ */ package com.diffplug.spotless.glue.ktlint.compat; +import java.nio.file.Path; import java.util.ArrayList; import java.util.Arrays; import java.util.List; @@ -49,10 +50,10 @@ public Unit invoke(LintError lint, Boolean corrected) { } @Override - public String format(final String text, final String name, final boolean isScript, - final boolean useExperimental, - String editorConfigPath, final Map userData, - final Map editorConfigOverrideMap) { + public String format(final String text, Path path, final boolean isScript, + final boolean useExperimental, + String editorConfigPath, final Map userData, + final Map editorConfigOverrideMap) { final FormatterCallback formatterCallback = new FormatterCallback(); final List rulesets = new ArrayList<>(); @@ -70,7 +71,7 @@ public String format(final String text, final String name, final boolean isScrip } return KtLint.INSTANCE.format(new KtLint.ExperimentalParams( - name, + path.toFile().getAbsolutePath(), text, rulesets, userData, diff --git a/lib/src/compatKtLint0Dot47Dot0/java/com/diffplug/spotless/glue/ktlint/compat/KtLintCompat0Dot47Dot0Adapter.java b/lib/src/compatKtLint0Dot47Dot0/java/com/diffplug/spotless/glue/ktlint/compat/KtLintCompat0Dot47Dot0Adapter.java index 3445a688b1..0d4f65936a 100644 --- a/lib/src/compatKtLint0Dot47Dot0/java/com/diffplug/spotless/glue/ktlint/compat/KtLintCompat0Dot47Dot0Adapter.java +++ b/lib/src/compatKtLint0Dot47Dot0/java/com/diffplug/spotless/glue/ktlint/compat/KtLintCompat0Dot47Dot0Adapter.java @@ -56,10 +56,10 @@ public Unit invoke(LintError lint, Boolean corrected) { } @Override - public String format(final String text, final String name, final boolean isScript, - final boolean useExperimental, - String editorConfigPath, final Map userData, - final Map editorConfigOverrideMap) { + public String format(final String text, Path path, final boolean isScript, + final boolean useExperimental, + String editorConfigPath, final Map userData, + final Map editorConfigOverrideMap) { final FormatterCallback formatterCallback = new FormatterCallback(); Set allRuleProviders = new LinkedHashSet<>( @@ -84,7 +84,7 @@ public String format(final String text, final String name, final boolean isScrip editorConfigFilePath = new File(editorConfigPath).toPath(); } return KtLint.INSTANCE.format(new KtLint.ExperimentalParams( - name, + path.toFile().getAbsolutePath(), text, emptySet(), allRuleProviders, diff --git a/lib/src/compatKtLint0Dot48Dot0/java/com/diffplug/spotless/glue/ktlint/compat/KtLintCompat0Dot48Dot0Adapter.java b/lib/src/compatKtLint0Dot48Dot0/java/com/diffplug/spotless/glue/ktlint/compat/KtLintCompat0Dot48Dot0Adapter.java index 3efc8c085d..2cc580ea6a 100644 --- a/lib/src/compatKtLint0Dot48Dot0/java/com/diffplug/spotless/glue/ktlint/compat/KtLintCompat0Dot48Dot0Adapter.java +++ b/lib/src/compatKtLint0Dot48Dot0/java/com/diffplug/spotless/glue/ktlint/compat/KtLintCompat0Dot48Dot0Adapter.java @@ -54,10 +54,10 @@ public Unit invoke(LintError lint, Boolean corrected) { } @Override - public String format(final String text, final String name, final boolean isScript, - final boolean useExperimental, - String editorConfigPath, final Map userData, - final Map editorConfigOverrideMap) { + public String format(final String text, Path path, final boolean isScript, + final boolean useExperimental, + String editorConfigPath, final Map userData, + final Map editorConfigOverrideMap) { final FormatterCallback formatterCallback = new FormatterCallback(); Set allRuleProviders = new LinkedHashSet<>( @@ -82,7 +82,7 @@ public String format(final String text, final String name, final boolean isScrip editorConfigFilePath = new File(editorConfigPath).toPath(); } return KtLint.INSTANCE.format(new KtLint.ExperimentalParams( - name, + path.toFile().getAbsolutePath(), text, allRuleProviders, userData, diff --git a/lib/src/compatKtLintApi/java/com/diffplug/spotless/glue/ktlint/compat/KtLintCompatAdapter.java b/lib/src/compatKtLintApi/java/com/diffplug/spotless/glue/ktlint/compat/KtLintCompatAdapter.java index b3e5d1817a..1693025688 100644 --- a/lib/src/compatKtLintApi/java/com/diffplug/spotless/glue/ktlint/compat/KtLintCompatAdapter.java +++ b/lib/src/compatKtLintApi/java/com/diffplug/spotless/glue/ktlint/compat/KtLintCompatAdapter.java @@ -15,10 +15,11 @@ */ package com.diffplug.spotless.glue.ktlint.compat; +import java.nio.file.Path; import java.util.Map; public interface KtLintCompatAdapter { - String format(String text, String name, boolean isScript, boolean useExperimental, String editorConfigPath, Map userData, - Map editorConfigOverrideMap); + String format(String text, Path path, boolean isScript, boolean useExperimental, String editorConfigPath, Map userData, + Map editorConfigOverrideMap); } diff --git a/lib/src/ktlint/java/com/diffplug/spotless/glue/ktlint/KtlintFormatterFunc.java b/lib/src/ktlint/java/com/diffplug/spotless/glue/ktlint/KtlintFormatterFunc.java index 034a782be6..1fe296143c 100644 --- a/lib/src/ktlint/java/com/diffplug/spotless/glue/ktlint/KtlintFormatterFunc.java +++ b/lib/src/ktlint/java/com/diffplug/spotless/glue/ktlint/KtlintFormatterFunc.java @@ -73,6 +73,6 @@ public String applyWithFile(String unix, File file) { if (editorConfigPath != null) { absoluteEditorConfigPath = editorConfigPath.getOnlyFile().getAbsolutePath(); } - return adapter.format(unix, file.getAbsolutePath(), isScript, useExperimental, absoluteEditorConfigPath, userData, editorConfigOverrideMap); + return adapter.format(unix, file.toPath(), isScript, useExperimental, absoluteEditorConfigPath, userData, editorConfigOverrideMap); } } From 5f4417ede83573d9d91e48b2ad0a136617d65f1b Mon Sep 17 00:00:00 2001 From: Eir Nym <485399+eirnym@users.noreply.github.com> Date: Thu, 5 Jan 2023 13:58:00 +0100 Subject: [PATCH 465/757] EditorConfig: Using KtLintRuleEngine for KtLint 0.48.x --- .../compat/KtLintCompat0Dot31Dot0Adapter.java | 6 +++--- .../compat/KtLintCompat0Dot32Dot0Adapter.java | 6 +++--- .../compat/KtLintCompat0Dot34Dot2Adapter.java | 6 +++--- .../compat/KtLintCompat0Dot45Dot2Adapter.java | 6 +++--- .../compat/KtLintCompat0Dot46Dot0Adapter.java | 6 +++--- .../compat/KtLintCompat0Dot47Dot0Adapter.java | 6 +++--- .../compat/KtLintCompat0Dot48Dot0Adapter.java | 19 +++++++------------ .../ktlint/compat/KtLintCompatAdapter.java | 2 +- 8 files changed, 26 insertions(+), 31 deletions(-) diff --git a/lib/src/compatKtLint0Dot31Dot0/java/com/diffplug/spotless/glue/ktlint/compat/KtLintCompat0Dot31Dot0Adapter.java b/lib/src/compatKtLint0Dot31Dot0/java/com/diffplug/spotless/glue/ktlint/compat/KtLintCompat0Dot31Dot0Adapter.java index 42d6e0c5bd..b9147345e2 100644 --- a/lib/src/compatKtLint0Dot31Dot0/java/com/diffplug/spotless/glue/ktlint/compat/KtLintCompat0Dot31Dot0Adapter.java +++ b/lib/src/compatKtLint0Dot31Dot0/java/com/diffplug/spotless/glue/ktlint/compat/KtLintCompat0Dot31Dot0Adapter.java @@ -43,9 +43,9 @@ public Unit invoke(LintError lint, Boolean corrected) { @Override public String format(final String text, Path path, final boolean isScript, - final boolean useExperimental, - String editorConfigPath, final Map userData, - final Map editorConfigOverrideMap) { + final boolean useExperimental, + String editorConfigPath, final Map userData, + final Map editorConfigOverrideMap) { final FormatterCallback formatterCallback = new FormatterCallback(); final List rulesets = new ArrayList<>(); diff --git a/lib/src/compatKtLint0Dot32Dot0/java/com/diffplug/spotless/glue/ktlint/compat/KtLintCompat0Dot32Dot0Adapter.java b/lib/src/compatKtLint0Dot32Dot0/java/com/diffplug/spotless/glue/ktlint/compat/KtLintCompat0Dot32Dot0Adapter.java index 11d3c0d8e5..de77d027f6 100644 --- a/lib/src/compatKtLint0Dot32Dot0/java/com/diffplug/spotless/glue/ktlint/compat/KtLintCompat0Dot32Dot0Adapter.java +++ b/lib/src/compatKtLint0Dot32Dot0/java/com/diffplug/spotless/glue/ktlint/compat/KtLintCompat0Dot32Dot0Adapter.java @@ -43,9 +43,9 @@ public Unit invoke(LintError lint, Boolean corrected) { @Override public String format(final String text, Path path, final boolean isScript, - final boolean useExperimental, - String editorConfigPath, final Map userData, - final Map editorConfigOverrideMap) { + final boolean useExperimental, + String editorConfigPath, final Map userData, + final Map editorConfigOverrideMap) { final FormatterCallback formatterCallback = new FormatterCallback(); final List rulesets = new ArrayList<>(); diff --git a/lib/src/compatKtLint0Dot34Dot2/java/com/diffplug/spotless/glue/ktlint/compat/KtLintCompat0Dot34Dot2Adapter.java b/lib/src/compatKtLint0Dot34Dot2/java/com/diffplug/spotless/glue/ktlint/compat/KtLintCompat0Dot34Dot2Adapter.java index 63d59ff74e..ae86e55e40 100644 --- a/lib/src/compatKtLint0Dot34Dot2/java/com/diffplug/spotless/glue/ktlint/compat/KtLintCompat0Dot34Dot2Adapter.java +++ b/lib/src/compatKtLint0Dot34Dot2/java/com/diffplug/spotless/glue/ktlint/compat/KtLintCompat0Dot34Dot2Adapter.java @@ -43,9 +43,9 @@ public Unit invoke(LintError lint, Boolean corrected) { @Override public String format(final String text, Path path, final boolean isScript, - final boolean useExperimental, - String editorConfigPath, final Map userData, - final Map editorConfigOverrideMap) { + final boolean useExperimental, + String editorConfigPath, final Map userData, + final Map editorConfigOverrideMap) { final FormatterCallback formatterCallback = new FormatterCallback(); final List rulesets = new ArrayList<>(); diff --git a/lib/src/compatKtLint0Dot45Dot2/java/com/diffplug/spotless/glue/ktlint/compat/KtLintCompat0Dot45Dot2Adapter.java b/lib/src/compatKtLint0Dot45Dot2/java/com/diffplug/spotless/glue/ktlint/compat/KtLintCompat0Dot45Dot2Adapter.java index b7b2435d93..06fbf8cdbd 100644 --- a/lib/src/compatKtLint0Dot45Dot2/java/com/diffplug/spotless/glue/ktlint/compat/KtLintCompat0Dot45Dot2Adapter.java +++ b/lib/src/compatKtLint0Dot45Dot2/java/com/diffplug/spotless/glue/ktlint/compat/KtLintCompat0Dot45Dot2Adapter.java @@ -51,9 +51,9 @@ public Unit invoke(LintError lint, Boolean corrected) { @Override public String format(final String text, Path path, final boolean isScript, - final boolean useExperimental, - String editorConfigPath, final Map userData, - final Map editorConfigOverrideMap) { + final boolean useExperimental, + String editorConfigPath, final Map userData, + final Map editorConfigOverrideMap) { final FormatterCallback formatterCallback = new FormatterCallback(); final List rulesets = new ArrayList<>(); diff --git a/lib/src/compatKtLint0Dot46Dot0/java/com/diffplug/spotless/glue/ktlint/compat/KtLintCompat0Dot46Dot0Adapter.java b/lib/src/compatKtLint0Dot46Dot0/java/com/diffplug/spotless/glue/ktlint/compat/KtLintCompat0Dot46Dot0Adapter.java index 198ce7ef9c..8c41157946 100644 --- a/lib/src/compatKtLint0Dot46Dot0/java/com/diffplug/spotless/glue/ktlint/compat/KtLintCompat0Dot46Dot0Adapter.java +++ b/lib/src/compatKtLint0Dot46Dot0/java/com/diffplug/spotless/glue/ktlint/compat/KtLintCompat0Dot46Dot0Adapter.java @@ -51,9 +51,9 @@ public Unit invoke(LintError lint, Boolean corrected) { @Override public String format(final String text, Path path, final boolean isScript, - final boolean useExperimental, - String editorConfigPath, final Map userData, - final Map editorConfigOverrideMap) { + final boolean useExperimental, + String editorConfigPath, final Map userData, + final Map editorConfigOverrideMap) { final FormatterCallback formatterCallback = new FormatterCallback(); final List rulesets = new ArrayList<>(); diff --git a/lib/src/compatKtLint0Dot47Dot0/java/com/diffplug/spotless/glue/ktlint/compat/KtLintCompat0Dot47Dot0Adapter.java b/lib/src/compatKtLint0Dot47Dot0/java/com/diffplug/spotless/glue/ktlint/compat/KtLintCompat0Dot47Dot0Adapter.java index 0d4f65936a..441f4636fa 100644 --- a/lib/src/compatKtLint0Dot47Dot0/java/com/diffplug/spotless/glue/ktlint/compat/KtLintCompat0Dot47Dot0Adapter.java +++ b/lib/src/compatKtLint0Dot47Dot0/java/com/diffplug/spotless/glue/ktlint/compat/KtLintCompat0Dot47Dot0Adapter.java @@ -57,9 +57,9 @@ public Unit invoke(LintError lint, Boolean corrected) { @Override public String format(final String text, Path path, final boolean isScript, - final boolean useExperimental, - String editorConfigPath, final Map userData, - final Map editorConfigOverrideMap) { + final boolean useExperimental, + String editorConfigPath, final Map userData, + final Map editorConfigOverrideMap) { final FormatterCallback formatterCallback = new FormatterCallback(); Set allRuleProviders = new LinkedHashSet<>( diff --git a/lib/src/compatKtLint0Dot48Dot0/java/com/diffplug/spotless/glue/ktlint/compat/KtLintCompat0Dot48Dot0Adapter.java b/lib/src/compatKtLint0Dot48Dot0/java/com/diffplug/spotless/glue/ktlint/compat/KtLintCompat0Dot48Dot0Adapter.java index 2cc580ea6a..51a1b283c6 100644 --- a/lib/src/compatKtLint0Dot48Dot0/java/com/diffplug/spotless/glue/ktlint/compat/KtLintCompat0Dot48Dot0Adapter.java +++ b/lib/src/compatKtLint0Dot48Dot0/java/com/diffplug/spotless/glue/ktlint/compat/KtLintCompat0Dot48Dot0Adapter.java @@ -25,7 +25,7 @@ import java.util.stream.Collectors; import java.util.stream.Stream; -import com.pinterest.ktlint.core.KtLint; +import com.pinterest.ktlint.core.KtLintRuleEngine; import com.pinterest.ktlint.core.LintError; import com.pinterest.ktlint.core.Rule; import com.pinterest.ktlint.core.RuleProvider; @@ -55,9 +55,9 @@ public Unit invoke(LintError lint, Boolean corrected) { @Override public String format(final String text, Path path, final boolean isScript, - final boolean useExperimental, - String editorConfigPath, final Map userData, - final Map editorConfigOverrideMap) { + final boolean useExperimental, + String editorConfigPath, final Map userData, + final Map editorConfigOverrideMap) { final FormatterCallback formatterCallback = new FormatterCallback(); Set allRuleProviders = new LinkedHashSet<>( @@ -81,17 +81,12 @@ public String format(final String text, Path path, final boolean isScript, } else { editorConfigFilePath = new File(editorConfigPath).toPath(); } - return KtLint.INSTANCE.format(new KtLint.ExperimentalParams( - path.toFile().getAbsolutePath(), - text, + return new KtLintRuleEngine( allRuleProviders, - userData, - formatterCallback, - isScript, - false, EditorConfigDefaults.Companion.load(editorConfigFilePath), editorConfigOverride, - false)); + false) + .format(path, formatterCallback); } /** diff --git a/lib/src/compatKtLintApi/java/com/diffplug/spotless/glue/ktlint/compat/KtLintCompatAdapter.java b/lib/src/compatKtLintApi/java/com/diffplug/spotless/glue/ktlint/compat/KtLintCompatAdapter.java index 1693025688..9d5cc8b06e 100644 --- a/lib/src/compatKtLintApi/java/com/diffplug/spotless/glue/ktlint/compat/KtLintCompatAdapter.java +++ b/lib/src/compatKtLintApi/java/com/diffplug/spotless/glue/ktlint/compat/KtLintCompatAdapter.java @@ -21,5 +21,5 @@ public interface KtLintCompatAdapter { String format(String text, Path path, boolean isScript, boolean useExperimental, String editorConfigPath, Map userData, - Map editorConfigOverrideMap); + Map editorConfigOverrideMap); } From 5cd53a9bb9fa709af695ef61272bb3f9977d5571 Mon Sep 17 00:00:00 2001 From: Eir Nym <485399+eirnym@users.noreply.github.com> Date: Thu, 5 Jan 2023 14:02:05 +0100 Subject: [PATCH 466/757] EditorConfig: pass Path to an implementation --- .../ktlint/compat/KtLintCompat0Dot31Dot0Adapter.java | 2 +- .../ktlint/compat/KtLintCompat0Dot32Dot0Adapter.java | 2 +- .../ktlint/compat/KtLintCompat0Dot34Dot2Adapter.java | 4 ++-- .../ktlint/compat/KtLintCompat0Dot45Dot2Adapter.java | 4 ++-- .../ktlint/compat/KtLintCompat0Dot46Dot0Adapter.java | 4 ++-- .../ktlint/compat/KtLintCompat0Dot47Dot0Adapter.java | 12 +++--------- .../ktlint/compat/KtLintCompat0Dot48Dot0Adapter.java | 12 +++--------- .../glue/ktlint/compat/KtLintCompatAdapter.java | 2 +- .../spotless/glue/ktlint/KtlintFormatterFunc.java | 5 +++-- 9 files changed, 18 insertions(+), 29 deletions(-) diff --git a/lib/src/compatKtLint0Dot31Dot0/java/com/diffplug/spotless/glue/ktlint/compat/KtLintCompat0Dot31Dot0Adapter.java b/lib/src/compatKtLint0Dot31Dot0/java/com/diffplug/spotless/glue/ktlint/compat/KtLintCompat0Dot31Dot0Adapter.java index b9147345e2..7a956de86a 100644 --- a/lib/src/compatKtLint0Dot31Dot0/java/com/diffplug/spotless/glue/ktlint/compat/KtLintCompat0Dot31Dot0Adapter.java +++ b/lib/src/compatKtLint0Dot31Dot0/java/com/diffplug/spotless/glue/ktlint/compat/KtLintCompat0Dot31Dot0Adapter.java @@ -44,7 +44,7 @@ public Unit invoke(LintError lint, Boolean corrected) { @Override public String format(final String text, Path path, final boolean isScript, final boolean useExperimental, - String editorConfigPath, final Map userData, + Path editorConfigPath, final Map userData, final Map editorConfigOverrideMap) { final FormatterCallback formatterCallback = new FormatterCallback(); diff --git a/lib/src/compatKtLint0Dot32Dot0/java/com/diffplug/spotless/glue/ktlint/compat/KtLintCompat0Dot32Dot0Adapter.java b/lib/src/compatKtLint0Dot32Dot0/java/com/diffplug/spotless/glue/ktlint/compat/KtLintCompat0Dot32Dot0Adapter.java index de77d027f6..94c41c3716 100644 --- a/lib/src/compatKtLint0Dot32Dot0/java/com/diffplug/spotless/glue/ktlint/compat/KtLintCompat0Dot32Dot0Adapter.java +++ b/lib/src/compatKtLint0Dot32Dot0/java/com/diffplug/spotless/glue/ktlint/compat/KtLintCompat0Dot32Dot0Adapter.java @@ -44,7 +44,7 @@ public Unit invoke(LintError lint, Boolean corrected) { @Override public String format(final String text, Path path, final boolean isScript, final boolean useExperimental, - String editorConfigPath, final Map userData, + Path editorConfigPath, final Map userData, final Map editorConfigOverrideMap) { final FormatterCallback formatterCallback = new FormatterCallback(); diff --git a/lib/src/compatKtLint0Dot34Dot2/java/com/diffplug/spotless/glue/ktlint/compat/KtLintCompat0Dot34Dot2Adapter.java b/lib/src/compatKtLint0Dot34Dot2/java/com/diffplug/spotless/glue/ktlint/compat/KtLintCompat0Dot34Dot2Adapter.java index ae86e55e40..8926a8e21f 100644 --- a/lib/src/compatKtLint0Dot34Dot2/java/com/diffplug/spotless/glue/ktlint/compat/KtLintCompat0Dot34Dot2Adapter.java +++ b/lib/src/compatKtLint0Dot34Dot2/java/com/diffplug/spotless/glue/ktlint/compat/KtLintCompat0Dot34Dot2Adapter.java @@ -44,7 +44,7 @@ public Unit invoke(LintError lint, Boolean corrected) { @Override public String format(final String text, Path path, final boolean isScript, final boolean useExperimental, - String editorConfigPath, final Map userData, + Path editorConfigPath, final Map userData, final Map editorConfigOverrideMap) { final FormatterCallback formatterCallback = new FormatterCallback(); @@ -62,7 +62,7 @@ public String format(final String text, Path path, final boolean isScript, userData, formatterCallback, isScript, - editorConfigPath, + editorConfigPath.toFile().getAbsolutePath(), false)); } } diff --git a/lib/src/compatKtLint0Dot45Dot2/java/com/diffplug/spotless/glue/ktlint/compat/KtLintCompat0Dot45Dot2Adapter.java b/lib/src/compatKtLint0Dot45Dot2/java/com/diffplug/spotless/glue/ktlint/compat/KtLintCompat0Dot45Dot2Adapter.java index 06fbf8cdbd..c90cf59d2b 100644 --- a/lib/src/compatKtLint0Dot45Dot2/java/com/diffplug/spotless/glue/ktlint/compat/KtLintCompat0Dot45Dot2Adapter.java +++ b/lib/src/compatKtLint0Dot45Dot2/java/com/diffplug/spotless/glue/ktlint/compat/KtLintCompat0Dot45Dot2Adapter.java @@ -52,7 +52,7 @@ public Unit invoke(LintError lint, Boolean corrected) { @Override public String format(final String text, Path path, final boolean isScript, final boolean useExperimental, - String editorConfigPath, final Map userData, + Path editorConfigPath, final Map userData, final Map editorConfigOverrideMap) { final FormatterCallback formatterCallback = new FormatterCallback(); @@ -77,7 +77,7 @@ public String format(final String text, Path path, final boolean isScript, userData, formatterCallback, isScript, - editorConfigPath, + editorConfigPath.toFile().getAbsolutePath(), false, editorConfigOverride, false)); diff --git a/lib/src/compatKtLint0Dot46Dot0/java/com/diffplug/spotless/glue/ktlint/compat/KtLintCompat0Dot46Dot0Adapter.java b/lib/src/compatKtLint0Dot46Dot0/java/com/diffplug/spotless/glue/ktlint/compat/KtLintCompat0Dot46Dot0Adapter.java index 8c41157946..54b34296a4 100644 --- a/lib/src/compatKtLint0Dot46Dot0/java/com/diffplug/spotless/glue/ktlint/compat/KtLintCompat0Dot46Dot0Adapter.java +++ b/lib/src/compatKtLint0Dot46Dot0/java/com/diffplug/spotless/glue/ktlint/compat/KtLintCompat0Dot46Dot0Adapter.java @@ -52,7 +52,7 @@ public Unit invoke(LintError lint, Boolean corrected) { @Override public String format(final String text, Path path, final boolean isScript, final boolean useExperimental, - String editorConfigPath, final Map userData, + Path editorConfigPath, final Map userData, final Map editorConfigOverrideMap) { final FormatterCallback formatterCallback = new FormatterCallback(); @@ -77,7 +77,7 @@ public String format(final String text, Path path, final boolean isScript, userData, formatterCallback, isScript, - editorConfigPath, + editorConfigPath.toFile().getAbsolutePath(), false, editorConfigOverride, false)); diff --git a/lib/src/compatKtLint0Dot47Dot0/java/com/diffplug/spotless/glue/ktlint/compat/KtLintCompat0Dot47Dot0Adapter.java b/lib/src/compatKtLint0Dot47Dot0/java/com/diffplug/spotless/glue/ktlint/compat/KtLintCompat0Dot47Dot0Adapter.java index 441f4636fa..20b87eeb17 100644 --- a/lib/src/compatKtLint0Dot47Dot0/java/com/diffplug/spotless/glue/ktlint/compat/KtLintCompat0Dot47Dot0Adapter.java +++ b/lib/src/compatKtLint0Dot47Dot0/java/com/diffplug/spotless/glue/ktlint/compat/KtLintCompat0Dot47Dot0Adapter.java @@ -17,7 +17,6 @@ import static java.util.Collections.emptySet; -import java.io.File; import java.nio.file.Path; import java.util.ArrayList; import java.util.LinkedHashSet; @@ -58,7 +57,7 @@ public Unit invoke(LintError lint, Boolean corrected) { @Override public String format(final String text, Path path, final boolean isScript, final boolean useExperimental, - String editorConfigPath, final Map userData, + Path editorConfigPath, final Map userData, final Map editorConfigOverrideMap) { final FormatterCallback formatterCallback = new FormatterCallback(); @@ -77,12 +76,7 @@ public String format(final String text, Path path, final boolean isScript, Collectors.toList()), editorConfigOverrideMap); } - Path editorConfigFilePath; - if (editorConfigPath == null) { - editorConfigFilePath = null; - } else { - editorConfigFilePath = new File(editorConfigPath).toPath(); - } + return KtLint.INSTANCE.format(new KtLint.ExperimentalParams( path.toFile().getAbsolutePath(), text, @@ -93,7 +87,7 @@ public String format(final String text, Path path, final boolean isScript, isScript, null, false, - EditorConfigDefaults.Companion.load(editorConfigFilePath), + EditorConfigDefaults.Companion.load(editorConfigPath), editorConfigOverride, false)); } diff --git a/lib/src/compatKtLint0Dot48Dot0/java/com/diffplug/spotless/glue/ktlint/compat/KtLintCompat0Dot48Dot0Adapter.java b/lib/src/compatKtLint0Dot48Dot0/java/com/diffplug/spotless/glue/ktlint/compat/KtLintCompat0Dot48Dot0Adapter.java index 51a1b283c6..be7f161251 100644 --- a/lib/src/compatKtLint0Dot48Dot0/java/com/diffplug/spotless/glue/ktlint/compat/KtLintCompat0Dot48Dot0Adapter.java +++ b/lib/src/compatKtLint0Dot48Dot0/java/com/diffplug/spotless/glue/ktlint/compat/KtLintCompat0Dot48Dot0Adapter.java @@ -15,7 +15,6 @@ */ package com.diffplug.spotless.glue.ktlint.compat; -import java.io.File; import java.nio.file.Path; import java.util.LinkedHashSet; import java.util.List; @@ -56,7 +55,7 @@ public Unit invoke(LintError lint, Boolean corrected) { @Override public String format(final String text, Path path, final boolean isScript, final boolean useExperimental, - String editorConfigPath, final Map userData, + Path editorConfigPath, final Map userData, final Map editorConfigOverrideMap) { final FormatterCallback formatterCallback = new FormatterCallback(); @@ -75,15 +74,10 @@ public String format(final String text, Path path, final boolean isScript, Collectors.toList()), editorConfigOverrideMap); } - Path editorConfigFilePath; - if (editorConfigPath == null) { - editorConfigFilePath = null; - } else { - editorConfigFilePath = new File(editorConfigPath).toPath(); - } + return new KtLintRuleEngine( allRuleProviders, - EditorConfigDefaults.Companion.load(editorConfigFilePath), + EditorConfigDefaults.Companion.load(editorConfigPath), editorConfigOverride, false) .format(path, formatterCallback); diff --git a/lib/src/compatKtLintApi/java/com/diffplug/spotless/glue/ktlint/compat/KtLintCompatAdapter.java b/lib/src/compatKtLintApi/java/com/diffplug/spotless/glue/ktlint/compat/KtLintCompatAdapter.java index 9d5cc8b06e..68a65eb6c8 100644 --- a/lib/src/compatKtLintApi/java/com/diffplug/spotless/glue/ktlint/compat/KtLintCompatAdapter.java +++ b/lib/src/compatKtLintApi/java/com/diffplug/spotless/glue/ktlint/compat/KtLintCompatAdapter.java @@ -20,6 +20,6 @@ public interface KtLintCompatAdapter { - String format(String text, Path path, boolean isScript, boolean useExperimental, String editorConfigPath, Map userData, + String format(String text, Path path, boolean isScript, boolean useExperimental, Path editorConfigPath, Map userData, Map editorConfigOverrideMap); } diff --git a/lib/src/ktlint/java/com/diffplug/spotless/glue/ktlint/KtlintFormatterFunc.java b/lib/src/ktlint/java/com/diffplug/spotless/glue/ktlint/KtlintFormatterFunc.java index 1fe296143c..e6f3715d25 100644 --- a/lib/src/ktlint/java/com/diffplug/spotless/glue/ktlint/KtlintFormatterFunc.java +++ b/lib/src/ktlint/java/com/diffplug/spotless/glue/ktlint/KtlintFormatterFunc.java @@ -16,6 +16,7 @@ package com.diffplug.spotless.glue.ktlint; import java.io.File; +import java.nio.file.Path; import java.util.Map; import org.jetbrains.annotations.NotNull; @@ -69,9 +70,9 @@ public KtlintFormatterFunc(String version, boolean isScript, boolean useExperime @Override public String applyWithFile(String unix, File file) { - String absoluteEditorConfigPath = null; + Path absoluteEditorConfigPath = null; if (editorConfigPath != null) { - absoluteEditorConfigPath = editorConfigPath.getOnlyFile().getAbsolutePath(); + absoluteEditorConfigPath = editorConfigPath.getOnlyFile().toPath(); } return adapter.format(unix, file.toPath(), isScript, useExperimental, absoluteEditorConfigPath, userData, editorConfigOverrideMap); } From f4c2a1d84e2cb82aa36415ae514a93cc60b59ace Mon Sep 17 00:00:00 2001 From: Eir Nym <485399+eirnym@users.noreply.github.com> Date: Thu, 5 Jan 2023 16:28:35 +0100 Subject: [PATCH 467/757] EditorConfig: Use default path without checking (KtLint will check them anyway) --- .../java/com/diffplug/gradle/spotless/KotlinExtension.java | 5 +---- .../com/diffplug/gradle/spotless/KotlinGradleExtension.java | 5 +---- 2 files changed, 2 insertions(+), 8 deletions(-) diff --git a/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/KotlinExtension.java b/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/KotlinExtension.java index 9ebc290219..5d1c484521 100644 --- a/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/KotlinExtension.java +++ b/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/KotlinExtension.java @@ -62,11 +62,8 @@ public LicenseHeaderConfig licenseHeaderFile(Object licenseHeaderFile) { /** Adds the specified version of ktlint. */ public KotlinFormatExtension ktlint(String version) throws IOException { Objects.requireNonNull(version); - FileSignature editorConfigPath = null; File defaultEditorConfig = getProject().getRootProject().file(".editorconfig"); - if (defaultEditorConfig.exists() && defaultEditorConfig.isFile()) { - editorConfigPath = FileSignature.signAsList(defaultEditorConfig); - } + FileSignature editorConfigPath = FileSignature.signAsList(defaultEditorConfig); return new KotlinFormatExtension(version, false, editorConfigPath, Collections.emptyMap(), Collections.emptyMap()); } diff --git a/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/KotlinGradleExtension.java b/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/KotlinGradleExtension.java index ec645a8972..82a8edd9a5 100644 --- a/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/KotlinGradleExtension.java +++ b/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/KotlinGradleExtension.java @@ -47,11 +47,8 @@ public KotlinGradleExtension(SpotlessExtension spotless) { /** Adds the specified version of ktlint. */ public KotlinFormatExtension ktlint(String version) throws IOException { Objects.requireNonNull(version, "version"); - FileSignature editorConfigPath = null; File defaultEditorConfig = getProject().getRootProject().file(".editorconfig"); - if (defaultEditorConfig.exists() && defaultEditorConfig.isFile()) { - editorConfigPath = FileSignature.signAsList(defaultEditorConfig); - } + FileSignature editorConfigPath = FileSignature.signAsList(defaultEditorConfig); return new KotlinFormatExtension(version, false, editorConfigPath, Collections.emptyMap(), Collections.emptyMap()); } From b6e90739d5deac7b356eaad74307b3c2dc061a0c Mon Sep 17 00:00:00 2001 From: Clayton Walker Date: Fri, 6 Jan 2023 10:45:59 -0700 Subject: [PATCH 468/757] Change back to 0.48.0 --- lib/build.gradle | 12 ++++++------ .../compat/KtLintCompat0Dot48Dot0Adapter.java} | 2 +- .../spotless/glue/ktlint/KtlintFormatterFunc.java | 4 ++-- .../compat/KtLintCompat0Dot48Dot0AdapterTest.java} | 14 +++++++------- .../resources/empty_class_body.kt | 0 .../resources/fails_no_semicolons.kt | 0 6 files changed, 16 insertions(+), 16 deletions(-) rename lib/src/{compatKtLint0Dot48Dot1/java/com/diffplug/spotless/glue/ktlint/compat/KtLintCompat0Dot48Dot1Adapter.java => compatKtLint0Dot48Dot0/java/com/diffplug/spotless/glue/ktlint/compat/KtLintCompat0Dot48Dot0Adapter.java} (99%) rename lib/src/{testCompatKtLint0Dot48Dot1/java/com/diffplug/spotless/glue/ktlint/compat/KtLintCompat0Dot48Dot1AdapterTest.java => testCompatKtLint0Dot48Dot0/java/com/diffplug/spotless/glue/ktlint/compat/KtLintCompat0Dot48Dot0AdapterTest.java} (81%) rename lib/src/{testCompatKtLint0Dot48Dot1 => testCompatKtLint0Dot48Dot0}/resources/empty_class_body.kt (100%) rename lib/src/{testCompatKtLint0Dot48Dot1 => testCompatKtLint0Dot48Dot0}/resources/fails_no_semicolons.kt (100%) diff --git a/lib/build.gradle b/lib/build.gradle index 826abf70a7..4cf4c66332 100644 --- a/lib/build.gradle +++ b/lib/build.gradle @@ -34,7 +34,7 @@ versionCompatibility { '0.45.2', '0.46.0', '0.47.0', - '0.48.1', + '0.48.0', ] targetSourceSetName = 'ktlint' } @@ -91,9 +91,9 @@ dependencies { compatKtLint0Dot47Dot0CompileOnly 'com.pinterest.ktlint:ktlint-core:0.47.0' compatKtLint0Dot47Dot0CompileOnly 'com.pinterest.ktlint:ktlint-ruleset-experimental:0.47.0' compatKtLint0Dot47Dot0CompileOnly 'com.pinterest.ktlint:ktlint-ruleset-standard:0.47.0' - compatKtLint0Dot48Dot1CompileOnly 'com.pinterest.ktlint:ktlint-core:0.48.1' - compatKtLint0Dot48Dot1CompileOnly 'com.pinterest.ktlint:ktlint-ruleset-experimental:0.48.1' - compatKtLint0Dot48Dot1CompileOnly 'com.pinterest.ktlint:ktlint-ruleset-standard:0.48.1' + compatKtLint0Dot48Dot0CompileOnly 'com.pinterest.ktlint:ktlint-core:0.48.0' + compatKtLint0Dot48Dot0CompileOnly 'com.pinterest.ktlint:ktlint-ruleset-experimental:0.48.0' + compatKtLint0Dot48Dot0CompileOnly 'com.pinterest.ktlint:ktlint-ruleset-standard:0.48.0' String VER_SCALAFMT="3.6.1" scalafmtCompileOnly "org.scalameta:scalafmt-core_2.13:$VER_SCALAFMT" @@ -105,8 +105,8 @@ dependencies { flexmarkCompileOnly 'com.vladsch.flexmark:flexmark-all:0.62.2' } -configurations.named('testCompatKtLint0Dot48Dot1Implementation').configure { - extendsFrom(configurations.testImplementation, configurations.compatKtLint0Dot48Dot1CompileOnly) +configurations.named('testCompatKtLint0Dot48Dot0Implementation').configure { + extendsFrom(configurations.testImplementation, configurations.compatKtLint0Dot48Dot0CompileOnly) } // we'll hold the core lib to a high standard diff --git a/lib/src/compatKtLint0Dot48Dot1/java/com/diffplug/spotless/glue/ktlint/compat/KtLintCompat0Dot48Dot1Adapter.java b/lib/src/compatKtLint0Dot48Dot0/java/com/diffplug/spotless/glue/ktlint/compat/KtLintCompat0Dot48Dot0Adapter.java similarity index 99% rename from lib/src/compatKtLint0Dot48Dot1/java/com/diffplug/spotless/glue/ktlint/compat/KtLintCompat0Dot48Dot1Adapter.java rename to lib/src/compatKtLint0Dot48Dot0/java/com/diffplug/spotless/glue/ktlint/compat/KtLintCompat0Dot48Dot0Adapter.java index 4329c18db9..f910576971 100644 --- a/lib/src/compatKtLint0Dot48Dot1/java/com/diffplug/spotless/glue/ktlint/compat/KtLintCompat0Dot48Dot1Adapter.java +++ b/lib/src/compatKtLint0Dot48Dot0/java/com/diffplug/spotless/glue/ktlint/compat/KtLintCompat0Dot48Dot0Adapter.java @@ -47,7 +47,7 @@ import kotlin.Unit; import kotlin.jvm.functions.Function2; -public class KtLintCompat0Dot48Dot1Adapter implements KtLintCompatAdapter { +public class KtLintCompat0Dot48Dot0Adapter implements KtLintCompatAdapter { private static final List> DEFAULT_EDITOR_CONFIG_PROPERTIES; diff --git a/lib/src/ktlint/java/com/diffplug/spotless/glue/ktlint/KtlintFormatterFunc.java b/lib/src/ktlint/java/com/diffplug/spotless/glue/ktlint/KtlintFormatterFunc.java index 5be69e819c..fc64cdb23e 100644 --- a/lib/src/ktlint/java/com/diffplug/spotless/glue/ktlint/KtlintFormatterFunc.java +++ b/lib/src/ktlint/java/com/diffplug/spotless/glue/ktlint/KtlintFormatterFunc.java @@ -27,7 +27,7 @@ import com.diffplug.spotless.glue.ktlint.compat.KtLintCompat0Dot45Dot2Adapter; import com.diffplug.spotless.glue.ktlint.compat.KtLintCompat0Dot46Dot0Adapter; import com.diffplug.spotless.glue.ktlint.compat.KtLintCompat0Dot47Dot0Adapter; -import com.diffplug.spotless.glue.ktlint.compat.KtLintCompat0Dot48Dot1Adapter; +import com.diffplug.spotless.glue.ktlint.compat.KtLintCompat0Dot48Dot0Adapter; import com.diffplug.spotless.glue.ktlint.compat.KtLintCompatAdapter; public class KtlintFormatterFunc implements FormatterFunc.NeedsFile { @@ -44,7 +44,7 @@ public KtlintFormatterFunc(String version, boolean isScript, boolean useExperime int minorVersion = Integer.parseInt(version.split("\\.")[1]); if (minorVersion >= 48) { // ExperimentalParams lost two constructor arguments, EditorConfigProperty moved to its own class - this.adapter = new KtLintCompat0Dot48Dot1Adapter(); + this.adapter = new KtLintCompat0Dot48Dot0Adapter(); } else if (minorVersion == 47) { // rename RuleSet to RuleProvider this.adapter = new KtLintCompat0Dot47Dot0Adapter(); diff --git a/lib/src/testCompatKtLint0Dot48Dot1/java/com/diffplug/spotless/glue/ktlint/compat/KtLintCompat0Dot48Dot1AdapterTest.java b/lib/src/testCompatKtLint0Dot48Dot0/java/com/diffplug/spotless/glue/ktlint/compat/KtLintCompat0Dot48Dot0AdapterTest.java similarity index 81% rename from lib/src/testCompatKtLint0Dot48Dot1/java/com/diffplug/spotless/glue/ktlint/compat/KtLintCompat0Dot48Dot1AdapterTest.java rename to lib/src/testCompatKtLint0Dot48Dot0/java/com/diffplug/spotless/glue/ktlint/compat/KtLintCompat0Dot48Dot0AdapterTest.java index ca9d603e5c..cccf71da12 100644 --- a/lib/src/testCompatKtLint0Dot48Dot1/java/com/diffplug/spotless/glue/ktlint/compat/KtLintCompat0Dot48Dot1AdapterTest.java +++ b/lib/src/testCompatKtLint0Dot48Dot0/java/com/diffplug/spotless/glue/ktlint/compat/KtLintCompat0Dot48Dot0AdapterTest.java @@ -28,11 +28,11 @@ import org.junit.jupiter.api.Test; import org.junit.jupiter.api.io.TempDir; -public class KtLintCompat0Dot48Dot1AdapterTest { +public class KtLintCompat0Dot48Dot0AdapterTest { @Test public void testDefaults(@TempDir Path path) throws IOException { - KtLintCompat0Dot48Dot1Adapter KtLintCompat0Dot48Dot1Adapter = new KtLintCompat0Dot48Dot1Adapter(); - try (InputStream is = KtLintCompat0Dot48Dot1AdapterTest.class.getResourceAsStream("/empty_class_body.kt")) { + KtLintCompat0Dot48Dot0Adapter ktLintCompat0Dot48Dot0Adapter = new KtLintCompat0Dot48Dot0Adapter(); + try (InputStream is = KtLintCompat0Dot48Dot0AdapterTest.class.getResourceAsStream("/empty_class_body.kt")) { Files.copy(is, path.resolve("empty_class_body.kt")); } String text = new String(Files.readAllBytes(path.resolve("empty_class_body.kt")), StandardCharsets.UTF_8); @@ -41,14 +41,14 @@ public void testDefaults(@TempDir Path path) throws IOException { Map editorConfigOverrideMap = new HashMap<>(); - String formatted = KtLintCompat0Dot48Dot1Adapter.format(text, "empty_class_body.kt", false, false, userData, editorConfigOverrideMap); + String formatted = ktLintCompat0Dot48Dot0Adapter.format(text, "empty_class_body.kt", false, false, userData, editorConfigOverrideMap); assertEquals("class empty_class_body\n", formatted); } @Test public void testEditorConfigCanDisable(@TempDir Path path) throws IOException { - KtLintCompat0Dot48Dot1Adapter KtLintCompat0Dot48Dot1Adapter = new KtLintCompat0Dot48Dot1Adapter(); - try (InputStream is = KtLintCompat0Dot48Dot1AdapterTest.class.getResourceAsStream("/fails_no_semicolons.kt")) { + KtLintCompat0Dot48Dot0Adapter ktLintCompat0Dot48Dot0Adapter = new KtLintCompat0Dot48Dot0Adapter(); + try (InputStream is = KtLintCompat0Dot48Dot0AdapterTest.class.getResourceAsStream("/fails_no_semicolons.kt")) { Files.copy(is, path.resolve("fails_no_semicolons.kt")); } String text = new String(Files.readAllBytes(path.resolve("fails_no_semicolons.kt")), StandardCharsets.UTF_8); @@ -59,7 +59,7 @@ public void testEditorConfigCanDisable(@TempDir Path path) throws IOException { editorConfigOverrideMap.put("indent_style", "tab"); editorConfigOverrideMap.put("ktlint_standard_no-semi", "disabled"); - String formatted = KtLintCompat0Dot48Dot1Adapter.format(text, "fails_no_semicolons.kt", false, false, userData, editorConfigOverrideMap); + String formatted = ktLintCompat0Dot48Dot0Adapter.format(text, "fails_no_semicolons.kt", false, false, userData, editorConfigOverrideMap); assertEquals("class fails_no_semicolons {\n\tval i = 0;\n}\n", formatted); } } diff --git a/lib/src/testCompatKtLint0Dot48Dot1/resources/empty_class_body.kt b/lib/src/testCompatKtLint0Dot48Dot0/resources/empty_class_body.kt similarity index 100% rename from lib/src/testCompatKtLint0Dot48Dot1/resources/empty_class_body.kt rename to lib/src/testCompatKtLint0Dot48Dot0/resources/empty_class_body.kt diff --git a/lib/src/testCompatKtLint0Dot48Dot1/resources/fails_no_semicolons.kt b/lib/src/testCompatKtLint0Dot48Dot0/resources/fails_no_semicolons.kt similarity index 100% rename from lib/src/testCompatKtLint0Dot48Dot1/resources/fails_no_semicolons.kt rename to lib/src/testCompatKtLint0Dot48Dot0/resources/fails_no_semicolons.kt From 8d52fb28f73c7a772b9097a05e00e73df967c69d Mon Sep 17 00:00:00 2001 From: "renovate[bot]" <29139614+renovate[bot]@users.noreply.github.com> Date: Fri, 6 Jan 2023 17:56:29 +0000 Subject: [PATCH 469/757] fix(deps): update dependency org.assertj:assertj-core to v3.24.1 --- gradle.properties | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gradle.properties b/gradle.properties index 577ed87535..e966c09437 100644 --- a/gradle.properties +++ b/gradle.properties @@ -27,7 +27,7 @@ VER_SLF4J=[1.6,2.0[ VER_DURIAN=1.2.0 VER_JGIT=5.13.1.202206130422-r VER_JUNIT=5.9.1 -VER_ASSERTJ=3.23.1 +VER_ASSERTJ=3.24.1 VER_MOCKITO=4.11.0 # Used for Maven Plugin From 6b2e2c397f4405ff9c1ed264dcd78138d2e8bb87 Mon Sep 17 00:00:00 2001 From: Clayton Walker Date: Fri, 6 Jan 2023 11:10:29 -0700 Subject: [PATCH 470/757] Use testCommonImplementation configuration --- lib/build.gradle | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/lib/build.gradle b/lib/build.gradle index 4cf4c66332..e8c22d28b6 100644 --- a/lib/build.gradle +++ b/lib/build.gradle @@ -45,9 +45,9 @@ dependencies { compileOnly 'org.slf4j:slf4j-api:2.0.0' // zero runtime reqs is a hard requirements for spotless-lib // if you need a dep, put it in lib-extra - testImplementation "org.junit.jupiter:junit-jupiter:$VER_JUNIT" - testImplementation "org.assertj:assertj-core:$VER_ASSERTJ" - testImplementation "com.diffplug.durian:durian-testlib:$VER_DURIAN" + testCommonImplementation "org.junit.jupiter:junit-jupiter:$VER_JUNIT" + testCommonImplementation "org.assertj:assertj-core:$VER_ASSERTJ" + testCommonImplementation "com.diffplug.durian:durian-testlib:$VER_DURIAN" // used for pom sorting sortPomCompileOnly 'com.github.ekryd.sortpom:sortpom-sorter:3.0.0' @@ -106,7 +106,7 @@ dependencies { } configurations.named('testCompatKtLint0Dot48Dot0Implementation').configure { - extendsFrom(configurations.testImplementation, configurations.compatKtLint0Dot48Dot0CompileOnly) + extendsFrom(configurations.compatKtLint0Dot48Dot0CompileOnly) } // we'll hold the core lib to a high standard From 3125f972f1b9883a9452c0ef8abb65cdea43ebac Mon Sep 17 00:00:00 2001 From: Ned Twigg Date: Sat, 7 Jan 2023 08:56:44 -0800 Subject: [PATCH 471/757] Our java example was ordered such that the import order would get wiped out by gjf, leading to confusion in #1417. --- plugin-maven/README.md | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/plugin-maven/README.md b/plugin-maven/README.md index dcc18a5dd6..da39543cc4 100644 --- a/plugin-maven/README.md +++ b/plugin-maven/README.md @@ -179,6 +179,10 @@ any other maven phase (i.e. compile) then it can be configured as below; src/test/java/**/*.java + + + + false @@ -188,10 +192,6 @@ any other maven phase (i.e. compile) then it can be configured as below; - - - - From bd562c1365e1b603d7202d66d1d34657ae9baebb Mon Sep 17 00:00:00 2001 From: Ned Twigg Date: Sat, 7 Jan 2023 09:06:34 -0800 Subject: [PATCH 472/757] Emphasize that order matters to the Maven users. --- plugin-maven/README.md | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/plugin-maven/README.md b/plugin-maven/README.md index da39543cc4..8440a4368e 100644 --- a/plugin-maven/README.md +++ b/plugin-maven/README.md @@ -129,7 +129,16 @@ To use it in your pom, just [add the Spotless dependency](https://search.maven.o Spotless consists of a list of formats (in the example above, `misc` and `java`), and each format has: - a `target` (the files to format), which you set with [`includes` and `excludes`](https://github.com/diffplug/spotless/blob/989abbecff4d8373c6111c1a98f359eadc532429/plugin-maven/src/main/java/com/diffplug/spotless/maven/FormatterFactory.java#L51-L55) - a list of `FormatterStep`, which are just `String -> String` functions, such as [`replace`](https://github.com/diffplug/spotless/blob/main/plugin-maven/src/main/java/com/diffplug/spotless/maven/generic/Replace.java), [`replaceRegex`](https://github.com/diffplug/spotless/blob/main/plugin-maven/src/main/java/com/diffplug/spotless/maven/generic/ReplaceRegex.java), [`trimTrailingWhitespace`](https://github.com/diffplug/spotless/blob/main/plugin-maven/src/main/java/com/diffplug/spotless/maven/generic/TrimTrailingWhitespace.java), [`indent`](https://github.com/diffplug/spotless/blob/main/plugin-maven/src/main/java/com/diffplug/spotless/maven/generic/Indent.java), [`prettier`](https://github.com/diffplug/spotless/blob/main/plugin-maven/src/main/java/com/diffplug/spotless/maven/generic/Prettier.java), [`eclipseWtp`](https://github.com/diffplug/spotless/blob/main/plugin-maven/src/main/java/com/diffplug/spotless/maven/generic/EclipseWtp.java), and [`licenseHeader`](https://github.com/diffplug/spotless/blob/main/plugin-maven/src/main/java/com/diffplug/spotless/maven/generic/LicenseHeader.java). - +- **order matters**, and this is good! (More info [here](https://github.com/diffplug/spotless/blob/main/PADDEDCELL.md) and [here](https://github.com/diffplug/spotless/blob/main/CONTRIBUTING.md#how-spotless-works)) + - For example, `googleJavaFormat` always indents with spaces, but some wish it had a tab mode + - ```xml + // this works + true2 + ``` + - ```xml + true2 + // the tab indentation gets overwritten + ``` ### Requirements From 8e1fb53059778d37e67d8814c3eb4e7f8fabbc2f Mon Sep 17 00:00:00 2001 From: Abel Keszei Date: Sat, 7 Jan 2023 21:50:46 +0100 Subject: [PATCH 473/757] add test for skipLinesMatching setting of license header step --- testlib/src/main/resources/license/SkipLines.test | 9 +++++++++ .../main/resources/license/SkipLinesHasLicense.test | 13 +++++++++++++ .../spotless/generic/LicenseHeaderStepTest.java | 7 +++++++ 3 files changed, 29 insertions(+) create mode 100644 testlib/src/main/resources/license/SkipLines.test create mode 100644 testlib/src/main/resources/license/SkipLinesHasLicense.test diff --git a/testlib/src/main/resources/license/SkipLines.test b/testlib/src/main/resources/license/SkipLines.test new file mode 100644 index 0000000000..4048868ac6 --- /dev/null +++ b/testlib/src/main/resources/license/SkipLines.test @@ -0,0 +1,9 @@ + + + + + + + + + diff --git a/testlib/src/main/resources/license/SkipLinesHasLicense.test b/testlib/src/main/resources/license/SkipLinesHasLicense.test new file mode 100644 index 0000000000..f645c5b2e2 --- /dev/null +++ b/testlib/src/main/resources/license/SkipLinesHasLicense.test @@ -0,0 +1,13 @@ + + + + + + + + + + diff --git a/testlib/src/test/java/com/diffplug/spotless/generic/LicenseHeaderStepTest.java b/testlib/src/test/java/com/diffplug/spotless/generic/LicenseHeaderStepTest.java index 137937beb9..785c1c528a 100644 --- a/testlib/src/test/java/com/diffplug/spotless/generic/LicenseHeaderStepTest.java +++ b/testlib/src/test/java/com/diffplug/spotless/generic/LicenseHeaderStepTest.java @@ -122,6 +122,13 @@ void should_remove_header_when_empty() throws Throwable { .test(getTestResource("license/HasLicense.test"), getTestResource("license/MissingLicense.test")); } + @Test + void should_skip_lines_matching_predefined_pattern() throws Throwable { + StepHarness.forStep(LicenseHeaderStep.headerDelimiter("", "^(?!", "^(?! + **/*.yaml + **/*.yml + + + + + +``` + +### jackson + +Uses Jackson and YAMLFactory to pretty print objects: + +```xml + + 2.13.4 + + INDENT_OUTPUT + + + DEFAULT_HAS_TO_DISABLED_FEATURE + + +``` + + + ## Prettier [homepage](https://prettier.io/). [changelog](https://github.com/prettier/prettier/blob/master/CHANGELOG.md). [official plugins](https://prettier.io/docs/en/plugins.html#official-plugins). [community plugins](https://prettier.io/docs/en/plugins.html#community-plugins). Prettier is a formatter that can format almost every anything - JavaScript, JSX, Angular, Vue, Flow, TypeScript, CSS, Less, SCSS, HTML, JSON, GraphQL, Markdown (including GFM and MDX), and YAML. It can format even more [using plugins](https://prettier.io/docs/en/plugins.html) (PHP, Ruby, Swift, XML, Apex, Elm, Java (!!), Kotlin, pgSQL, .properties, solidity, svelte, toml, shellscript, ...). diff --git a/plugin-maven/src/main/java/com/diffplug/spotless/maven/yaml/JacksonYaml.java b/plugin-maven/src/main/java/com/diffplug/spotless/maven/yaml/JacksonYaml.java index 90892f969a..86b52aac7d 100644 --- a/plugin-maven/src/main/java/com/diffplug/spotless/maven/yaml/JacksonYaml.java +++ b/plugin-maven/src/main/java/com/diffplug/spotless/maven/yaml/JacksonYaml.java @@ -31,7 +31,7 @@ public class JacksonYaml implements FormatterStepFactory { private String version = YamlJacksonStep.defaultVersion(); @Parameter - private String[] enabledFeatures = new String[] { "INDENT_OUTPUT" }; + private String[] enabledFeatures = new String[]{"INDENT_OUTPUT"}; @Parameter private String[] disabledFeatures = new String[0]; diff --git a/plugin-maven/src/main/java/com/diffplug/spotless/maven/yaml/Yaml.java b/plugin-maven/src/main/java/com/diffplug/spotless/maven/yaml/Yaml.java index a6ceaaa592..20e609ceb4 100644 --- a/plugin-maven/src/main/java/com/diffplug/spotless/maven/yaml/Yaml.java +++ b/plugin-maven/src/main/java/com/diffplug/spotless/maven/yaml/Yaml.java @@ -15,9 +15,9 @@ */ package com.diffplug.spotless.maven.yaml; -import java.util.Collections; import java.util.Set; +import com.diffplug.common.collect.Sets; import com.diffplug.spotless.maven.FormatterFactory; /** @@ -26,7 +26,7 @@ public class Yaml extends FormatterFactory { @Override public Set defaultIncludes() { - return Collections.emptySet(); + return Sets.newHashSet("**/*.yaml", "**/*.yml"); } @Override diff --git a/plugin-maven/src/test/java/com/diffplug/spotless/maven/MavenIntegrationHarness.java b/plugin-maven/src/test/java/com/diffplug/spotless/maven/MavenIntegrationHarness.java index 9e9495da65..5dbd3e0075 100644 --- a/plugin-maven/src/test/java/com/diffplug/spotless/maven/MavenIntegrationHarness.java +++ b/plugin-maven/src/test/java/com/diffplug/spotless/maven/MavenIntegrationHarness.java @@ -160,6 +160,10 @@ protected void writePomWithJsonSteps(String... steps) throws IOException { writePom(groupWithSteps("json", including("**/*.json"), steps)); } + protected void writePomWithYamlSteps(String... steps) throws IOException { + writePom(groupWithSteps("yaml", steps)); + } + protected void writePom(String... configuration) throws IOException { writePom(null, configuration, null); } diff --git a/plugin-maven/src/test/java/com/diffplug/spotless/maven/yaml/YamlTest.java b/plugin-maven/src/test/java/com/diffplug/spotless/maven/yaml/YamlTest.java new file mode 100644 index 0000000000..8b9bab6cbb --- /dev/null +++ b/plugin-maven/src/test/java/com/diffplug/spotless/maven/yaml/YamlTest.java @@ -0,0 +1,31 @@ +/* + * Copyright 2023 DiffPlug + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.diffplug.spotless.maven.yaml; + +import org.junit.jupiter.api.Test; + +import com.diffplug.spotless.maven.MavenIntegrationHarness; + +public class YamlTest extends MavenIntegrationHarness { + @Test + public void testFormatJson_WithSimple_defaultConfig() throws Exception { + writePomWithJsonSteps(""); + + setFile("yaml_test.json").toResource("yaml/separator_comments.yaml"); + mavenRunner().withArguments("spotless:apply").runNoError().error(); + assertFile("yaml_test.json").sameAsResource("yaml/separator_comments.clean.yaml"); + } +} From 3244f2defe92773733c7d600c0c9f4440506de65 Mon Sep 17 00:00:00 2001 From: Benoit Lacelle Date: Tue, 10 Jan 2023 10:05:31 +0400 Subject: [PATCH 506/757] Add unit-tests --- .../spotless/maven/yaml/YamlTest.java | 20 ++++++++++++++++++- .../yaml/array_with_bracket.clean.yaml | 8 ++++++++ .../resources/yaml/array_with_bracket.yaml | 5 +++++ .../yaml/multiple_document.clean.yaml | 8 ++++++++ .../resources/yaml/multiple_document.yaml | 10 ++++++++++ .../resources/yaml/separator_comments.yaml | 1 + 6 files changed, 51 insertions(+), 1 deletion(-) create mode 100644 testlib/src/main/resources/yaml/array_with_bracket.clean.yaml create mode 100644 testlib/src/main/resources/yaml/array_with_bracket.yaml create mode 100644 testlib/src/main/resources/yaml/multiple_document.clean.yaml create mode 100644 testlib/src/main/resources/yaml/multiple_document.yaml diff --git a/plugin-maven/src/test/java/com/diffplug/spotless/maven/yaml/YamlTest.java b/plugin-maven/src/test/java/com/diffplug/spotless/maven/yaml/YamlTest.java index 8b9bab6cbb..b2168ff05f 100644 --- a/plugin-maven/src/test/java/com/diffplug/spotless/maven/yaml/YamlTest.java +++ b/plugin-maven/src/test/java/com/diffplug/spotless/maven/yaml/YamlTest.java @@ -21,11 +21,29 @@ public class YamlTest extends MavenIntegrationHarness { @Test - public void testFormatJson_WithSimple_defaultConfig() throws Exception { + public void testFormatYaml_WithJackson_defaultConfig_separatorComments() throws Exception { writePomWithJsonSteps(""); setFile("yaml_test.json").toResource("yaml/separator_comments.yaml"); mavenRunner().withArguments("spotless:apply").runNoError().error(); assertFile("yaml_test.json").sameAsResource("yaml/separator_comments.clean.yaml"); } + + @Test + public void testFormatYaml_WithJackson_defaultConfig_arrayBrackets() throws Exception { + writePomWithJsonSteps(""); + + setFile("yaml_test.json").toResource("yaml/array_with_bracket.yaml"); + mavenRunner().withArguments("spotless:apply").runNoError().error(); + assertFile("yaml_test.json").sameAsResource("yaml/array_with_bracket.clean.yaml"); + } + + @Test + public void testFormatYaml_WithJackson_defaultConfig_multipleComments() throws Exception { + writePomWithJsonSteps(""); + + setFile("yaml_test.json").toResource("yaml/multiple_documents.yaml"); + mavenRunner().withArguments("spotless:apply").runNoError().error(); + assertFile("yaml_test.json").sameAsResource("yaml/multiple_documents.clean.yaml"); + } } diff --git a/testlib/src/main/resources/yaml/array_with_bracket.clean.yaml b/testlib/src/main/resources/yaml/array_with_bracket.clean.yaml new file mode 100644 index 0000000000..bf46f753c0 --- /dev/null +++ b/testlib/src/main/resources/yaml/array_with_bracket.clean.yaml @@ -0,0 +1,8 @@ +--- +hr: + - Mark McGwire + # Following node labeled SS + - &SS Sammy Sosa +rbi: + - *SS # Subsequent occurrence + - Ken Griffey \ No newline at end of file diff --git a/testlib/src/main/resources/yaml/array_with_bracket.yaml b/testlib/src/main/resources/yaml/array_with_bracket.yaml new file mode 100644 index 0000000000..c83e381e6b --- /dev/null +++ b/testlib/src/main/resources/yaml/array_with_bracket.yaml @@ -0,0 +1,5 @@ +hr: [Mark McGwire, Sammy Sosa] + + + +rbi: [Sammy Sosa, Ken Griffey] \ No newline at end of file diff --git a/testlib/src/main/resources/yaml/multiple_document.clean.yaml b/testlib/src/main/resources/yaml/multiple_document.clean.yaml new file mode 100644 index 0000000000..bf46f753c0 --- /dev/null +++ b/testlib/src/main/resources/yaml/multiple_document.clean.yaml @@ -0,0 +1,8 @@ +--- +hr: + - Mark McGwire + # Following node labeled SS + - &SS Sammy Sosa +rbi: + - *SS # Subsequent occurrence + - Ken Griffey \ No newline at end of file diff --git a/testlib/src/main/resources/yaml/multiple_document.yaml b/testlib/src/main/resources/yaml/multiple_document.yaml new file mode 100644 index 0000000000..51f14a5862 --- /dev/null +++ b/testlib/src/main/resources/yaml/multiple_document.yaml @@ -0,0 +1,10 @@ +document: this is document 1 +--- + +document: this is document 2 + + +--- + + +document: this is document 3 \ No newline at end of file diff --git a/testlib/src/main/resources/yaml/separator_comments.yaml b/testlib/src/main/resources/yaml/separator_comments.yaml index bf46f753c0..0213e66406 100644 --- a/testlib/src/main/resources/yaml/separator_comments.yaml +++ b/testlib/src/main/resources/yaml/separator_comments.yaml @@ -1,3 +1,4 @@ + --- hr: - Mark McGwire From 43078663dbf2b7cf1fcdf55f1c25b41d272684ad Mon Sep 17 00:00:00 2001 From: Benoit Lacelle Date: Tue, 10 Jan 2023 10:06:36 +0400 Subject: [PATCH 507/757] Improve testcases --- .../main/resources/yaml/array_with_bracket.clean.yaml | 10 ++-------- .../src/main/resources/yaml/array_with_bracket.yaml | 4 ++-- 2 files changed, 4 insertions(+), 10 deletions(-) diff --git a/testlib/src/main/resources/yaml/array_with_bracket.clean.yaml b/testlib/src/main/resources/yaml/array_with_bracket.clean.yaml index bf46f753c0..8e9d80065e 100644 --- a/testlib/src/main/resources/yaml/array_with_bracket.clean.yaml +++ b/testlib/src/main/resources/yaml/array_with_bracket.clean.yaml @@ -1,8 +1,2 @@ ---- -hr: - - Mark McGwire - # Following node labeled SS - - &SS Sammy Sosa -rbi: - - *SS # Subsequent occurrence - - Ken Griffey \ No newline at end of file +episodes: [1, 2, 3, 4, 5, 6, 7] +best-jedi: {name: Obi-Wan, side: light} \ No newline at end of file diff --git a/testlib/src/main/resources/yaml/array_with_bracket.yaml b/testlib/src/main/resources/yaml/array_with_bracket.yaml index c83e381e6b..e28373163d 100644 --- a/testlib/src/main/resources/yaml/array_with_bracket.yaml +++ b/testlib/src/main/resources/yaml/array_with_bracket.yaml @@ -1,5 +1,5 @@ -hr: [Mark McGwire, Sammy Sosa] +episodes: [1, 2, 3, 4, 5, 6, 7] -rbi: [Sammy Sosa, Ken Griffey] \ No newline at end of file +best-jedi: {name: Obi-Wan, side: light} \ No newline at end of file From d4d91cb97975a8a29e7a067a3c64af15460b7bef Mon Sep 17 00:00:00 2001 From: Simon Gamma Date: Tue, 10 Jan 2023 08:35:14 +0100 Subject: [PATCH 508/757] eslint: remove direct api support for styleguides --- .../spotless/npm/EslintFormatterStep.java | 93 +------------- plugin-gradle/README.md | 4 - .../gradle/spotless/JavascriptExtension.java | 25 +--- .../gradle/spotless/TypescriptExtension.java | 15 +-- .../spotless/JavascriptExtensionTest.java | 41 ++---- .../spotless/TypescriptExtensionTest.java | 32 ++--- plugin-maven/README.md | 4 - .../maven/javascript/AbstractEslint.java | 28 ---- .../spotless/maven/javascript/EslintJs.java | 4 - .../spotless/maven/typescript/EslintTs.java | 5 - .../javascript/JavascriptFormatStepTest.java | 10 +- .../typescript/TypescriptFormatStepTest.java | 10 +- .../spotless/npm/EslintStyleGuide.java | 120 ++++++++++++++++++ .../spotless/npm/EslintFormatterStepTest.java | 21 +-- 14 files changed, 170 insertions(+), 242 deletions(-) create mode 100644 testlib/src/main/java/com/diffplug/spotless/npm/EslintStyleGuide.java diff --git a/lib/src/main/java/com/diffplug/spotless/npm/EslintFormatterStep.java b/lib/src/main/java/com/diffplug/spotless/npm/EslintFormatterStep.java index ac3ee05345..81c5b6ce78 100644 --- a/lib/src/main/java/com/diffplug/spotless/npm/EslintFormatterStep.java +++ b/lib/src/main/java/com/diffplug/spotless/npm/EslintFormatterStep.java @@ -20,14 +20,12 @@ import java.io.File; import java.io.IOException; import java.io.Serializable; -import java.util.Arrays; import java.util.Collections; import java.util.HashMap; import java.util.LinkedHashMap; import java.util.Map; import java.util.Objects; import java.util.TreeMap; -import java.util.function.Predicate; import javax.annotation.Nonnull; @@ -47,96 +45,7 @@ public class EslintFormatterStep { public static final String NAME = "eslint-format"; - public static final String DEFAULT_ESLINT_VERSION = "^8.30.0"; - - public enum PopularStyleGuide { - TS_STANDARD_WITH_TYPESCRIPT("standard-with-typescript") { - @Override - public @Nonnull Map devDependencies() { - Map dependencies = new LinkedHashMap<>(); - dependencies.put("eslint-config-standard-with-typescript", "^24.0.0"); - dependencies.put("eslint-plugin-import", "^2.26.0"); - dependencies.put("eslint-plugin-n", "^15.6.0"); - dependencies.put("eslint-plugin-promise", "^6.1.1"); - return dependencies; - } - }, - TS_XO_TYPESCRIPT("xo-typescript") { - @Override - public @Nonnull Map devDependencies() { - Map dependencies = new LinkedHashMap<>(); - dependencies.put("eslint-config-xo", "^0.43.1"); - dependencies.put("eslint-config-xo-typescript", "^0.55.1"); - return dependencies; - } - }, - JS_AIRBNB("airbnb") { - @Override - public @Nonnull Map devDependencies() { - Map dependencies = new LinkedHashMap<>(); - dependencies.put("eslint-config-airbnb-base", "^15.0.0"); - dependencies.put("eslint-plugin-import", "^2.26.0"); - return dependencies; - } - }, - JS_GOOGLE("google") { - @Override - public @Nonnull Map devDependencies() { - Map dependencies = new LinkedHashMap<>(); - dependencies.put("eslint-config-google", "^0.14.0"); - return dependencies; - } - }, - JS_STANDARD("standard") { - @Override - public @Nonnull Map devDependencies() { - Map dependencies = new LinkedHashMap<>(); - dependencies.put("eslint-config-standard", "^17.0.0"); - dependencies.put("eslint-plugin-import", "^2.26.0"); - dependencies.put("eslint-plugin-n", "^15.6.0"); - dependencies.put("eslint-plugin-promise", "^6.1.1"); - return dependencies; - } - }, - JS_XO("xo") { - @Override - public @Nonnull Map devDependencies() { - Map dependencies = new LinkedHashMap<>(); - dependencies.put("eslint-config-xo", "^0.43.1"); - return dependencies; - } - }; - - private final String popularStyleGuideName; - - PopularStyleGuide(String popularStyleGuideName) { - this.popularStyleGuideName = popularStyleGuideName; - } - - public String getPopularStyleGuideName() { - return popularStyleGuideName; - } - - public abstract @Nonnull Map devDependencies(); - - public static PopularStyleGuide fromNameOrNull(String popularStyleGuideName) { - for (PopularStyleGuide popularStyleGuide : PopularStyleGuide.values()) { - if (popularStyleGuide.popularStyleGuideName.equals(popularStyleGuideName)) { - return popularStyleGuide; - } - } - return null; - } - - public static String getPopularStyleGuideNames(Predicate filter) { - // collect matching style guide names using stream - return Arrays.stream(PopularStyleGuide.values()) - .filter(filter) - .map(PopularStyleGuide::getPopularStyleGuideName) - .sorted() - .collect(java.util.stream.Collectors.joining(", ")); - } - } + public static final String DEFAULT_ESLINT_VERSION = "^8.31.0"; public static Map defaultDevDependenciesForTypescript() { return defaultDevDependenciesTypescriptWithEslint(DEFAULT_ESLINT_VERSION); diff --git a/plugin-gradle/README.md b/plugin-gradle/README.md index 1ed2b942b5..8a06351bed 100644 --- a/plugin-gradle/README.md +++ b/plugin-gradle/README.md @@ -634,8 +634,6 @@ spotless { eslint(['my-eslint-fork': '1.2.3', 'my-eslint-plugin': '1.2.1']) // can specify exactly which npm packages to use eslint() - // optional: use a popular eslint styleguide for typescript - .styleGuide('standard-with-typescript') // or 'xo-typescript' // configuration is mandatory. Provide inline config or a config file. // a) inline-configuration .configJs(''' @@ -703,8 +701,6 @@ spotless { eslint(['my-eslint-fork': '1.2.3', 'my-eslint-plugin': '1.2.1']) // can specify exactly which npm packages to use eslint() - // optional: use a popular eslint styleguide for javascript - .styleGuide('standard') // or 'airbnb', 'google', 'xo' // configuration is mandatory. Provide inline config or a config file. // a) inline-configuration .configJs(''' diff --git a/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/JavascriptExtension.java b/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/JavascriptExtension.java index 862c7566ee..dd476b6a69 100644 --- a/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/JavascriptExtension.java +++ b/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/JavascriptExtension.java @@ -31,7 +31,6 @@ import com.diffplug.spotless.FormatterStep; import com.diffplug.spotless.npm.EslintConfig; import com.diffplug.spotless.npm.EslintFormatterStep; -import com.diffplug.spotless.npm.EslintFormatterStep.PopularStyleGuide; import com.diffplug.spotless.npm.NpmPathResolver; import com.diffplug.spotless.npm.PrettierFormatterStep; @@ -73,7 +72,7 @@ public EslintBaseConfig(Project project, Consumer replaceStep, Ma } @SuppressWarnings("unchecked") - public T devDependencies(Map devDependencies) { + protected T devDependencies(Map devDependencies) { this.devDependencies.putAll(devDependencies); replaceStep(); return (T) this; @@ -92,17 +91,6 @@ public T configFile(Object configFilePath) { replaceStep(); return (T) this; } - - @SuppressWarnings("unchecked") - public T styleGuide(String styleGuide) { - PopularStyleGuide popularStyleGuide = PopularStyleGuide.fromNameOrNull(styleGuide); - - verifyStyleGuideIsSupported(styleGuide, popularStyleGuide); - assert popularStyleGuide != null; - return devDependencies(popularStyleGuide.devDependencies()); - } - - protected abstract void verifyStyleGuideIsSupported(String styleGuideName, PopularStyleGuide popularStyleGuide); } public class JavascriptEslintConfig extends EslintBaseConfig { @@ -123,17 +111,6 @@ public FormatterStep createStep() { eslintConfig()); } - @Override - protected void verifyStyleGuideIsSupported(String styleGuideName, PopularStyleGuide popularStyleGuide) { - if (!isJsStyleGuide(popularStyleGuide)) { - throw new IllegalArgumentException("Unknown style guide: " + styleGuideName + ". Known javascript style guides: " + PopularStyleGuide.getPopularStyleGuideNames(this::isJsStyleGuide)); - } - } - - private boolean isJsStyleGuide(PopularStyleGuide popularStyleGuide) { - return popularStyleGuide != null && popularStyleGuide.name().startsWith("JS_"); - } - protected EslintConfig eslintConfig() { return new EslintConfig(configFilePath != null ? getProject().file(configFilePath) : null, configJs); } diff --git a/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/TypescriptExtension.java b/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/TypescriptExtension.java index 5de1bb1ac3..0824caa769 100644 --- a/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/TypescriptExtension.java +++ b/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/TypescriptExtension.java @@ -27,10 +27,10 @@ import org.gradle.api.Project; +import com.diffplug.gradle.spotless.JavascriptExtension.EslintBaseConfig; import com.diffplug.spotless.FormatterStep; import com.diffplug.spotless.npm.EslintConfig; import com.diffplug.spotless.npm.EslintFormatterStep; -import com.diffplug.spotless.npm.EslintFormatterStep.PopularStyleGuide; import com.diffplug.spotless.npm.EslintTypescriptConfig; import com.diffplug.spotless.npm.NpmPathResolver; import com.diffplug.spotless.npm.PrettierFormatterStep; @@ -189,7 +189,7 @@ public TypescriptEslintConfig eslint(Map devDependencies) { return eslint; } - public class TypescriptEslintConfig extends JavascriptExtension.EslintBaseConfig { + public class TypescriptEslintConfig extends EslintBaseConfig { @Nullable Object typescriptConfigFilePath = null; @@ -204,17 +204,6 @@ public TypescriptEslintConfig tsconfigFile(Object path) { return this; } - @Override - protected void verifyStyleGuideIsSupported(String styleGuideName, PopularStyleGuide popularStyleGuide) { - if (!isTsStyleGuide(popularStyleGuide)) { - throw new IllegalArgumentException("Unknown style guide: " + styleGuideName + ". Known typescript style guides: " + PopularStyleGuide.getPopularStyleGuideNames(this::isTsStyleGuide)); - } - } - - private boolean isTsStyleGuide(PopularStyleGuide popularStyleGuide) { - return popularStyleGuide != null && popularStyleGuide.name().startsWith("TS_"); - } - public FormatterStep createStep() { final Project project = getProject(); diff --git a/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/JavascriptExtensionTest.java b/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/JavascriptExtensionTest.java index 331e17f28e..26354b93be 100644 --- a/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/JavascriptExtensionTest.java +++ b/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/JavascriptExtensionTest.java @@ -24,11 +24,17 @@ import org.junit.jupiter.params.ParameterizedTest; import org.junit.jupiter.params.provider.ValueSource; +import com.diffplug.spotless.npm.EslintFormatterStep; +import com.diffplug.spotless.npm.EslintStyleGuide; import com.diffplug.spotless.tag.NpmTest; @NpmTest class JavascriptExtensionTest extends GradleIntegrationHarness { + private static String styleGuideMapString(String styleGuideName) { + return EslintStyleGuide.fromNameOrNull(styleGuideName).asGradleMapStringMergedWith(EslintFormatterStep.defaultDevDependencies()); + } + @NpmTest @Nested class EslintGeneralJavascriptTests extends GradleIntegrationHarness { @@ -43,7 +49,7 @@ void supportsEslintFormattingForJavascript() throws IOException { "spotless {", " javascript {", " target 'test.js'", - " eslint().configFile('.eslintrc.js').styleGuide('standard')", + " eslint(" + styleGuideMapString("standard") + ").configFile('.eslintrc.js')", " }", "}"); setFile("test.js").toResource("npm/eslint/javascript/styleguide/standard/javascript-es6.dirty"); @@ -51,28 +57,9 @@ void supportsEslintFormattingForJavascript() throws IOException { assertFile("test.js").sameAsResource("npm/eslint/javascript/styleguide/standard/javascript-es6.clean"); } - @Test - void eslintDoesNotAllowToUseTsStyleGuideForJavascript() throws IOException { - setFile(".eslintrc.js").toResource("npm/eslint/javascript/styleguide/standard/.eslintrc.js"); - setFile("build.gradle").toLines( - "plugins {", - " id 'com.diffplug.spotless'", - "}", - "repositories { mavenCentral() }", - "spotless {", - " javascript {", - " target 'test.js'", - " eslint().configFile('.eslintrc.js').styleGuide('xo-typescript')", - " }", - "}"); - setFile("test.js").toResource("npm/eslint/javascript/styleguide/standard/javascript-es6.dirty"); - final BuildResult spotlessApply = gradleRunner().withArguments("--stacktrace", "spotlessApply").buildAndFail(); - Assertions.assertThat(spotlessApply.getOutput()).contains("Unknown style guide: xo-typescript"); - } - @Test void eslintAllowsToSpecifyEslintVersionForJavascript() throws IOException { - setFile(".eslintrc.js").toResource("npm/eslint/javascript/styleguide/standard/.eslintrc.js"); + setFile(".eslintrc.js").toResource("npm/eslint/javascript/custom_rules/.eslintrc.js"); setFile("build.gradle").toLines( "plugins {", " id 'com.diffplug.spotless'", @@ -81,12 +68,12 @@ void eslintAllowsToSpecifyEslintVersionForJavascript() throws IOException { "spotless {", " javascript {", " target 'test.js'", - " eslint('8.28.0').configFile('.eslintrc.js').styleGuide('standard')", + " eslint('8.28.0').configFile('.eslintrc.js')", " }", "}"); - setFile("test.js").toResource("npm/eslint/javascript/styleguide/standard/javascript-es6.dirty"); + setFile("test.js").toResource("npm/eslint/javascript/custom_rules/javascript-es6.dirty"); gradleRunner().withArguments("--stacktrace", "spotlessApply").build(); - assertFile("test.js").sameAsResource("npm/eslint/javascript/styleguide/standard/javascript-es6.clean"); + assertFile("test.js").sameAsResource("npm/eslint/javascript/custom_rules/javascript-es6.clean"); } @Test @@ -115,7 +102,7 @@ void esllintAllowsToSpecifyInlineConfig() throws IOException { "spotless {", " javascript {", " target 'test.js'", - " eslint().configJs('''" + eslintConfigJs + "''').styleGuide('standard')", + " eslint(" + styleGuideMapString("standard") + ").configJs('''" + eslintConfigJs + "''')", " }", "}"); setFile("test.js").toResource("npm/eslint/javascript/styleguide/standard/javascript-es6.dirty"); @@ -134,7 +121,7 @@ void eslintRequiresAnExplicitEslintConfig() throws IOException { "spotless {", " javascript {", " target 'test.js'", - " eslint().styleGuide('standard')", + " eslint(" + styleGuideMapString("standard") + ")", " }", "}"); setFile("test.js").toResource("npm/eslint/javascript/styleguide/standard/javascript-es6.dirty"); @@ -187,7 +174,7 @@ void formattingUsingStyleguide(String styleguide) throws Exception { "spotless {", " javascript {", " target 'test.js'", - " eslint().configFile('.eslintrc.js').styleGuide('" + styleguide + "')", + " eslint(" + styleGuideMapString(styleguide) + ").configFile('.eslintrc.js')", " }", "}"); setFile("test.js").toResource(styleguidePath + "javascript-es6.dirty"); diff --git a/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/TypescriptExtensionTest.java b/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/TypescriptExtensionTest.java index 598ff7dc14..9b4ec8372e 100644 --- a/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/TypescriptExtensionTest.java +++ b/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/TypescriptExtensionTest.java @@ -17,14 +17,19 @@ import java.io.IOException; -import org.assertj.core.api.Assertions; -import org.gradle.testkit.runner.BuildResult; import org.junit.jupiter.api.Test; +import com.diffplug.spotless.npm.EslintFormatterStep; +import com.diffplug.spotless.npm.EslintStyleGuide; import com.diffplug.spotless.tag.NpmTest; @NpmTest class TypescriptExtensionTest extends GradleIntegrationHarness { + + private static String styleGuideMapString(String styleGuideName) { + return EslintStyleGuide.fromNameOrNull(styleGuideName).asGradleMapStringMergedWith(EslintFormatterStep.defaultDevDependencies()); + } + @Test void allowToSpecifyFormatterVersion() throws IOException { setFile("build.gradle").toLines( @@ -175,7 +180,7 @@ void useEslintXoStandardRules() throws IOException { "spotless {", " typescript {", " target 'test.ts'", - " eslint().styleGuide('xo-typescript').configFile('.eslintrc.js')", + " eslint(" + styleGuideMapString("xo-typescript") + ").configFile('.eslintrc.js')", " }", "}"); setFile("test.ts").toResource("npm/eslint/typescript/styleguide/xo/typescript.dirty"); @@ -195,30 +200,11 @@ void useEslintStandardWithTypescriptRules() throws IOException { "spotless {", " typescript {", " target 'test.ts'", - " eslint().styleGuide('standard-with-typescript').configFile('.eslintrc.js')", + " eslint(" + styleGuideMapString("standard-with-typescript") + ").configFile('.eslintrc.js')", " }", "}"); setFile("test.ts").toResource("npm/eslint/typescript/styleguide/standard_with_typescript/typescript.dirty"); gradleRunner().withArguments("--stacktrace", "spotlessApply").build(); assertFile("test.ts").sameAsResource("npm/eslint/typescript/styleguide/standard_with_typescript/typescript.clean"); } - - @Test - void useEslintForTypescriptDoesNotAllowUsingJsStyleguide() throws IOException { - setFile(".eslintrc.js").toResource("npm/eslint/javascript/styleguide/airbnb/.eslintrc.js"); - setFile("build.gradle").toLines( - "plugins {", - " id 'com.diffplug.spotless'", - "}", - "repositories { mavenCentral() }", - "spotless {", - " typescript {", - " target 'test.ts'", - " eslint().styleGuide('airbnb').configFile('.eslintrc.js')", - " }", - "}"); - setFile("test.js").toResource("npm/eslint/javascript/styleguide/airbnb/javascript-es6.dirty"); - BuildResult spotlessApply = gradleRunner().withArguments("--stacktrace", "spotlessApply").buildAndFail(); - Assertions.assertThat(spotlessApply.getOutput()).contains("Unknown style guide: airbnb"); - } } diff --git a/plugin-maven/README.md b/plugin-maven/README.md index dcf9df45d9..2a2aa31010 100644 --- a/plugin-maven/README.md +++ b/plugin-maven/README.md @@ -745,8 +745,6 @@ styleguides and the requirement for a tsconfigFile. 0.14.2 - - standard-with-typescript ${project.basedir}/.eslintrc.js @@ -826,8 +824,6 @@ styleguides and no requirement for a tsconfig (of course). 0.14.2 - - standard ${project.basedir}/.eslintrc.js diff --git a/plugin-maven/src/main/java/com/diffplug/spotless/maven/javascript/AbstractEslint.java b/plugin-maven/src/main/java/com/diffplug/spotless/maven/javascript/AbstractEslint.java index 1829f91b4e..b06d3079e7 100644 --- a/plugin-maven/src/main/java/com/diffplug/spotless/maven/javascript/AbstractEslint.java +++ b/plugin-maven/src/main/java/com/diffplug/spotless/maven/javascript/AbstractEslint.java @@ -39,9 +39,6 @@ public abstract class AbstractEslint extends AbstractNpmFormatterStepFactory { @Parameter protected String configJs; - @Parameter - protected String styleGuide; - @Parameter protected String eslintVersion; @@ -68,8 +65,6 @@ public FormatterStep newFormatterStep(FormatterStepConfig stepConfig) { devDependencies.putAll(defaultDependencies); } - addStyleGuideDevDependencies(devDependencies); - File buildDir = buildDir(stepConfig); File baseDir = baseDir(stepConfig); NpmPathResolver npmPathResolver = npmPathResolver(stepConfig); @@ -82,28 +77,5 @@ private static IllegalArgumentException onlyOneConfig() { protected abstract EslintConfig eslintConfig(FormatterStepConfig stepConfig); - private void addStyleGuideDevDependencies(Map devDependencies) { - if (this.styleGuide != null) { - EslintFormatterStep.PopularStyleGuide styleGuide = EslintFormatterStep.PopularStyleGuide.fromNameOrNull(this.styleGuide); - validateStyleGuide(styleGuide); - devDependencies.putAll(styleGuide.devDependencies()); - } - } - - private void validateStyleGuide(EslintFormatterStep.PopularStyleGuide styleGuide) { - if (styleGuide == null) { - throw new IllegalArgumentException("StyleGuide '" + this.styleGuide + "' is not supported. Supported style guides: " + supportedStyleGuides()); - } - if (!isValidStyleGuide(styleGuide)) { - throw new IllegalArgumentException("StyleGuide must be of correct type but is: " + styleGuide.getPopularStyleGuideName() + ". Use one of the following: " + supportedStyleGuides()); - } - } - - private String supportedStyleGuides() { - return EslintFormatterStep.PopularStyleGuide.getPopularStyleGuideNames(this::isValidStyleGuide); - } - - protected abstract boolean isValidStyleGuide(EslintFormatterStep.PopularStyleGuide styleGuide); - protected abstract Map createDefaultDependencies(); } diff --git a/plugin-maven/src/main/java/com/diffplug/spotless/maven/javascript/EslintJs.java b/plugin-maven/src/main/java/com/diffplug/spotless/maven/javascript/EslintJs.java index f9954ab0c8..483d38ae1e 100644 --- a/plugin-maven/src/main/java/com/diffplug/spotless/maven/javascript/EslintJs.java +++ b/plugin-maven/src/main/java/com/diffplug/spotless/maven/javascript/EslintJs.java @@ -27,10 +27,6 @@ protected EslintConfig eslintConfig(FormatterStepConfig stepConfig) { return new EslintConfig(this.configFile != null ? stepConfig.getFileLocator().locateFile(this.configFile) : null, this.configJs); } - protected boolean isValidStyleGuide(EslintFormatterStep.PopularStyleGuide styleGuide) { - return styleGuide.name().startsWith("JS_"); - } - protected Map createDefaultDependencies() { return this.eslintVersion == null ? EslintFormatterStep.defaultDevDependencies() : EslintFormatterStep.defaultDevDependenciesWithEslint(this.eslintVersion); } diff --git a/plugin-maven/src/main/java/com/diffplug/spotless/maven/typescript/EslintTs.java b/plugin-maven/src/main/java/com/diffplug/spotless/maven/typescript/EslintTs.java index 72f3735d97..dc43185dcd 100644 --- a/plugin-maven/src/main/java/com/diffplug/spotless/maven/typescript/EslintTs.java +++ b/plugin-maven/src/main/java/com/diffplug/spotless/maven/typescript/EslintTs.java @@ -38,11 +38,6 @@ protected EslintConfig eslintConfig(FormatterStepConfig stepConfig) { tsconfigFile != null ? stepConfig.getFileLocator().locateFile(tsconfigFile) : null); } - @Override - protected boolean isValidStyleGuide(EslintFormatterStep.PopularStyleGuide styleGuide) { - return styleGuide.name().startsWith("TS_"); - } - @Override protected Map createDefaultDependencies() { return this.eslintVersion == null ? EslintFormatterStep.defaultDevDependenciesForTypescript() : EslintFormatterStep.defaultDevDependenciesTypescriptWithEslint(this.eslintVersion); diff --git a/plugin-maven/src/test/java/com/diffplug/spotless/maven/javascript/JavascriptFormatStepTest.java b/plugin-maven/src/test/java/com/diffplug/spotless/maven/javascript/JavascriptFormatStepTest.java index 7ebc592add..5c8a5f04b3 100644 --- a/plugin-maven/src/test/java/com/diffplug/spotless/maven/javascript/JavascriptFormatStepTest.java +++ b/plugin-maven/src/test/java/com/diffplug/spotless/maven/javascript/JavascriptFormatStepTest.java @@ -23,6 +23,8 @@ import com.diffplug.spotless.ResourceHarness; import com.diffplug.spotless.maven.MavenIntegrationHarness; import com.diffplug.spotless.maven.MavenRunner.Result; +import com.diffplug.spotless.npm.EslintFormatterStep; +import com.diffplug.spotless.npm.EslintStyleGuide; import com.diffplug.spotless.tag.NpmTest; @NpmTest @@ -30,6 +32,10 @@ class JavascriptFormatStepTest extends MavenIntegrationHarness { private static final String TEST_FILE_PATH = "src/main/javascript/test.js"; + private static String styleGuideDevDependenciesString(String styleGuideName) { + return EslintStyleGuide.fromNameOrNull(styleGuideName).asMavenXmlStringMergedWith(EslintFormatterStep.defaultDevDependencies()); + } + @NpmTest @Nested class EslintCustomRulesTest extends MavenIntegrationHarness { @@ -79,7 +85,7 @@ void eslintJsStyleguideUsingConfigFile(String styleGuide) throws Exception { TEST_FILE_PATH, "", " .eslintrc.js", - " " + styleGuide + "", + " " + styleGuideDevDependenciesString(styleGuide), ""); setFile(".eslintrc.js").toResource(styleGuidePath + "/.eslintrc.js"); setFile(TEST_FILE_PATH).toResource(styleGuidePath + "/javascript-es6.dirty"); @@ -100,7 +106,7 @@ void eslintJsStyleguideUsingInlineConfig(String styleGuide) throws Exception { TEST_FILE_PATH, "", " " + escapedInlineConfig + "", - " " + styleGuide + "", + " " + styleGuideDevDependenciesString(styleGuide), ""); setFile(TEST_FILE_PATH).toResource(styleGuidePath + "/javascript-es6.dirty"); diff --git a/plugin-maven/src/test/java/com/diffplug/spotless/maven/typescript/TypescriptFormatStepTest.java b/plugin-maven/src/test/java/com/diffplug/spotless/maven/typescript/TypescriptFormatStepTest.java index ac925cc9b6..95097fe467 100644 --- a/plugin-maven/src/test/java/com/diffplug/spotless/maven/typescript/TypescriptFormatStepTest.java +++ b/plugin-maven/src/test/java/com/diffplug/spotless/maven/typescript/TypescriptFormatStepTest.java @@ -24,6 +24,8 @@ import com.diffplug.spotless.ResourceHarness; import com.diffplug.spotless.maven.MavenIntegrationHarness; import com.diffplug.spotless.maven.MavenRunner.Result; +import com.diffplug.spotless.npm.EslintFormatterStep; +import com.diffplug.spotless.npm.EslintStyleGuide; import com.diffplug.spotless.tag.NpmTest; @NpmTest @@ -31,6 +33,10 @@ class TypescriptFormatStepTest extends MavenIntegrationHarness { private static final String TEST_FILE_PATH = "src/main/typescript/test.ts"; + private static String styleGuideDevDependenciesString(String styleGuideName) { + return EslintStyleGuide.fromNameOrNull(styleGuideName).asMavenXmlStringMergedWith(EslintFormatterStep.defaultDevDependencies()); + } + private void runTsfmt(String kind) throws IOException, InterruptedException { String path = prepareRunTsfmt(kind); mavenRunner().withArguments("spotless:apply").runNoError(); @@ -192,7 +198,7 @@ void eslintStyleguideStandardWithTypescript() throws Exception { TEST_FILE_PATH, "", " .eslintrc.js", - " standard-with-typescript", + " " + styleGuideDevDependenciesString("standard-with-typescript"), " ${basedir}/tsconfig.json", ""); setFile(".eslintrc.js").toResource("npm/eslint/typescript/styleguide/standard_with_typescript/.eslintrc.js"); @@ -209,7 +215,7 @@ void eslintStyleguideXo() throws Exception { TEST_FILE_PATH, "", " .eslintrc.js", - " xo-typescript", + " " + styleGuideDevDependenciesString("xo-typescript"), " ${basedir}/tsconfig.json", ""); setFile(".eslintrc.js").toResource("npm/eslint/typescript/styleguide/xo/.eslintrc.js"); diff --git a/testlib/src/main/java/com/diffplug/spotless/npm/EslintStyleGuide.java b/testlib/src/main/java/com/diffplug/spotless/npm/EslintStyleGuide.java new file mode 100644 index 0000000000..62d0b0aa00 --- /dev/null +++ b/testlib/src/main/java/com/diffplug/spotless/npm/EslintStyleGuide.java @@ -0,0 +1,120 @@ +/* + * Copyright 2023 DiffPlug + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.diffplug.spotless.npm; + +import java.util.LinkedHashMap; +import java.util.Map; +import java.util.stream.Collectors; + +import javax.annotation.Nonnull; + +/** + * A helper class to create dev dependencies for eslint when using one of the popular styleguides in testing. + */ +public enum EslintStyleGuide { + TS_STANDARD_WITH_TYPESCRIPT("standard-with-typescript") { + @Override + public @Nonnull Map devDependencies() { + Map dependencies = new LinkedHashMap<>(); + dependencies.put("eslint-config-standard-with-typescript", "^24.0.0"); + dependencies.put("eslint-plugin-import", "^2.26.0"); + dependencies.put("eslint-plugin-n", "^15.6.0"); + dependencies.put("eslint-plugin-promise", "^6.1.1"); + return dependencies; + } + }, + TS_XO_TYPESCRIPT("xo-typescript") { + @Override + public @Nonnull Map devDependencies() { + Map dependencies = new LinkedHashMap<>(); + dependencies.put("eslint-config-xo", "^0.43.1"); + dependencies.put("eslint-config-xo-typescript", "^0.55.1"); + return dependencies; + } + }, + JS_AIRBNB("airbnb") { + @Override + public @Nonnull Map devDependencies() { + Map dependencies = new LinkedHashMap<>(); + dependencies.put("eslint-config-airbnb-base", "^15.0.0"); + dependencies.put("eslint-plugin-import", "^2.26.0"); + return dependencies; + } + }, + JS_GOOGLE("google") { + @Override + public @Nonnull Map devDependencies() { + Map dependencies = new LinkedHashMap<>(); + dependencies.put("eslint-config-google", "^0.14.0"); + return dependencies; + } + }, + JS_STANDARD("standard") { + @Override + public @Nonnull Map devDependencies() { + Map dependencies = new LinkedHashMap<>(); + dependencies.put("eslint-config-standard", "^17.0.0"); + dependencies.put("eslint-plugin-import", "^2.26.0"); + dependencies.put("eslint-plugin-n", "^15.6.0"); + dependencies.put("eslint-plugin-promise", "^6.1.1"); + return dependencies; + } + }, + JS_XO("xo") { + @Override + public @Nonnull Map devDependencies() { + Map dependencies = new LinkedHashMap<>(); + dependencies.put("eslint-config-xo", "^0.43.1"); + return dependencies; + } + }; + + private final String popularStyleGuideName; + + EslintStyleGuide(String popularStyleGuideName) { + this.popularStyleGuideName = popularStyleGuideName; + } + + public abstract @Nonnull Map devDependencies(); + + public static EslintStyleGuide fromNameOrNull(String popularStyleGuideName) { + for (EslintStyleGuide popularStyleGuide : EslintStyleGuide.values()) { + if (popularStyleGuide.popularStyleGuideName.equals(popularStyleGuideName)) { + return popularStyleGuide; + } + } + return null; + } + + public Map mergedWith(Map devDependencies) { + Map merged = new LinkedHashMap<>(devDependencies); + merged.putAll(devDependencies()); + return merged; + } + + public String asGradleMapStringMergedWith(Map devDependencies) { + return mergedWith(devDependencies).entrySet().stream() + .map(entry -> "'" + entry.getKey() + "': '" + entry.getValue() + "'") + .collect(Collectors.joining(", ", "[", "]")); + } + + public String asMavenXmlStringMergedWith(Map devDependencies) { + return mergedWith(devDependencies).entrySet().stream() + .map(entry -> "<" + entry.getKey() + ">" + entry.getValue() + "") + .collect(Collectors.joining("", "", "")); + } + +} diff --git a/testlib/src/test/java/com/diffplug/spotless/npm/EslintFormatterStepTest.java b/testlib/src/test/java/com/diffplug/spotless/npm/EslintFormatterStepTest.java index 19f6e8c223..1bc0915ed3 100644 --- a/testlib/src/test/java/com/diffplug/spotless/npm/EslintFormatterStepTest.java +++ b/testlib/src/test/java/com/diffplug/spotless/npm/EslintFormatterStepTest.java @@ -17,7 +17,6 @@ import java.io.File; import java.util.Map; -import java.util.TreeMap; import org.junit.jupiter.api.Nested; import org.junit.jupiter.api.Test; @@ -34,22 +33,16 @@ @NpmTest class EslintFormatterStepTest { - private final Map combine(Map m1, Map m2) { - Map combined = new TreeMap<>(m1); - combined.putAll(m2); - return combined; - } - @NpmTest @Nested class EslintJavascriptFormattingStepTest extends NpmFormatterStepCommonTests { private final Map> devDependenciesForRuleset = ImmutableMap.of( "custom_rules", EslintFormatterStep.defaultDevDependenciesForTypescript(), - "styleguide/airbnb", combine(EslintFormatterStep.defaultDevDependencies(), EslintFormatterStep.PopularStyleGuide.JS_AIRBNB.devDependencies()), - "styleguide/google", combine(EslintFormatterStep.defaultDevDependencies(), EslintFormatterStep.PopularStyleGuide.JS_GOOGLE.devDependencies()), - "styleguide/standard", combine(EslintFormatterStep.defaultDevDependencies(), EslintFormatterStep.PopularStyleGuide.JS_STANDARD.devDependencies()), - "styleguide/xo", combine(EslintFormatterStep.defaultDevDependencies(), EslintFormatterStep.PopularStyleGuide.JS_XO.devDependencies())); + "styleguide/airbnb", EslintStyleGuide.JS_AIRBNB.mergedWith(EslintFormatterStep.defaultDevDependencies()), + "styleguide/google", EslintStyleGuide.JS_GOOGLE.mergedWith(EslintFormatterStep.defaultDevDependencies()), + "styleguide/standard", EslintStyleGuide.JS_STANDARD.mergedWith(EslintFormatterStep.defaultDevDependencies()), + "styleguide/xo", EslintStyleGuide.JS_XO.mergedWith(EslintFormatterStep.defaultDevDependencies())); @ParameterizedTest(name = "{index}: eslint can be applied using ruleset {0}") @ValueSource(strings = {"custom_rules", "styleguide/airbnb", "styleguide/google", "styleguide/standard", "styleguide/xo"}) @@ -86,8 +79,8 @@ class EslintTypescriptFormattingStepTest extends NpmFormatterStepCommonTests { private final Map> devDependenciesForRuleset = ImmutableMap.of( "custom_rules", EslintFormatterStep.defaultDevDependenciesForTypescript(), - "styleguide/standard_with_typescript", combine(EslintFormatterStep.defaultDevDependenciesForTypescript(), EslintFormatterStep.PopularStyleGuide.TS_STANDARD_WITH_TYPESCRIPT.devDependencies()), - "styleguide/xo", combine(EslintFormatterStep.defaultDevDependenciesForTypescript(), EslintFormatterStep.PopularStyleGuide.TS_XO_TYPESCRIPT.devDependencies())); + "styleguide/standard_with_typescript", EslintStyleGuide.TS_STANDARD_WITH_TYPESCRIPT.mergedWith(EslintFormatterStep.defaultDevDependenciesForTypescript()), + "styleguide/xo", EslintStyleGuide.TS_XO_TYPESCRIPT.mergedWith(EslintFormatterStep.defaultDevDependenciesForTypescript())); @ParameterizedTest(name = "{index}: eslint can be applied using ruleset {0}") @ValueSource(strings = {"custom_rules", "styleguide/standard_with_typescript", "styleguide/xo"}) @@ -167,7 +160,7 @@ void formattingUsingInlineXoConfig() throws Exception { final String cleanFile = filedir + "typescript.clean"; final FormatterStep formatterStep = EslintFormatterStep.create( - combine(EslintFormatterStep.PopularStyleGuide.TS_XO_TYPESCRIPT.devDependencies(), EslintFormatterStep.defaultDevDependenciesForTypescript()), + EslintStyleGuide.TS_XO_TYPESCRIPT.mergedWith(EslintFormatterStep.defaultDevDependenciesForTypescript()), TestProvisioner.mavenCentral(), projectDir(), buildDir(), From 6577e29cdbd735b310143057372b1a0709c5219f Mon Sep 17 00:00:00 2001 From: Simon Gamma Date: Tue, 10 Jan 2023 09:43:04 +0100 Subject: [PATCH 509/757] eslint: fix anchor navigation --- plugin-gradle/README.md | 8 ++++---- plugin-maven/README.md | 8 ++++---- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/plugin-gradle/README.md b/plugin-gradle/README.md index 8a06351bed..878885f645 100644 --- a/plugin-gradle/README.md +++ b/plugin-gradle/README.md @@ -69,8 +69,8 @@ Spotless supports all of Gradle's built-in performance features (incremental bui - [FreshMark](#freshmark) aka markdown - [Antlr4](#antlr4) ([antlr4formatter](#antlr4formatter)) - [SQL](#sql) ([dbeaver](#dbeaver), [prettier](#prettier)) - - [Typescript](#typescript) ([tsfmt](#tsfmt), [prettier](#prettier), [ESLint](#eslint--typescript-)) - - [Javascript](#javascript) ([prettier](#prettier), [ESLint](#eslint--javascript-)) + - [Typescript](#typescript) ([tsfmt](#tsfmt), [prettier](#prettier), [ESLint](#eslint-typescript)) + - [Javascript](#javascript) ([prettier](#prettier), [ESLint](#eslint-javascript)) - [JSON](#json) - Multiple languages - [Prettier](#prettier) ([plugins](#prettier-plugins), [npm detection](#npm-detection), [`.npmrc` detection](#npmrc-detection)) @@ -624,7 +624,7 @@ For details, see the [npm detection](#npm-detection) and [`.npmrc` detection](#n The auto-discovery of config files (up the file tree) will not work when using ESLint within spotless, hence you are required to provide resolvable file paths for config files, or alternatively provide the configuration inline. -The configuration is very similar to the [ESLint (Javascript)](#eslint--javascript-) configuration. It differs in supported +The configuration is very similar to the [ESLint (Javascript)](#eslint-javascript) configuration. It differs in supported styleguides and the requirement for a tsconfigFile. ```gradle @@ -689,7 +689,7 @@ spotless { The auto-discovery of config files (up the file tree) will not work when using ESLint within spotless, hence you are required to provide resolvable file paths for config files, or alternatively provide the configuration inline. -The configuration is very similar to the [ESLint (Typescript)](#eslint--typescript-) configuration. It differs in supported +The configuration is very similar to the [ESLint (Typescript)](#eslint-typescript) configuration. It differs in supported styleguides and no requirement for a tsconfig (of course). ```gradle diff --git a/plugin-maven/README.md b/plugin-maven/README.md index 2a2aa31010..e74e1b27cf 100644 --- a/plugin-maven/README.md +++ b/plugin-maven/README.md @@ -57,8 +57,8 @@ user@machine repo % mvn spotless:check - [Sql](#sql) ([dbeaver](#dbeaver)) - [Maven Pom](#maven-pom) ([sortPom](#sortpom)) - [Markdown](#markdown) ([flexmark](#flexmark)) - - [Typescript](#typescript) ([tsfmt](#tsfmt), [prettier](#prettier), [ESLint](#eslint--typescript-)) - - [Javascript](#javascript) ([prettier](#prettier), [ESLint](#eslint--javascript-)) + - [Typescript](#typescript) ([tsfmt](#tsfmt), [prettier](#prettier), [ESLint](#eslint-typescript)) + - [Javascript](#javascript) ([prettier](#prettier), [ESLint](#eslint-javascript)) - [JSON](#json) - Multiple languages - [Prettier](#prettier) ([plugins](#prettier-plugins), [npm detection](#npm-detection), [`.npmrc` detection](#npmrc-detection)) @@ -724,7 +724,7 @@ For details, see the [npm detection](#npm-detection) and [`.npmrc` detection](#n The auto-discovery of config files (up the file tree) will not work when using ESLint within spotless, hence you are required to provide resolvable file paths for config files, or alternatively provide the configuration inline. -The configuration is very similar to the [ESLint (Javascript)](#eslint--javascript-) configuration. It differs in supported +The configuration is very similar to the [ESLint (Javascript)](#eslint-javascript) configuration. It differs in supported styleguides and the requirement for a tsconfigFile. ```xml @@ -803,7 +803,7 @@ For details, see the [npm detection](#npm-detection) and [`.npmrc` detection](#n The auto-discovery of config files (up the file tree) will not work when using ESLint within spotless, hence you are required to provide resolvable file paths for config files, or alternatively provide the configuration inline. -The configuration is very similar to the [ESLint (Typescript)](#eslint--typescript-) configuration. It differs in supported +The configuration is very similar to the [ESLint (Typescript)](#eslint-typescript) configuration. It differs in supported styleguides and no requirement for a tsconfig (of course). ```xml From 04a6bcbf46bca245bf5e6bead7218b38ae6a3845 Mon Sep 17 00:00:00 2001 From: "renovate[bot]" <29139614+renovate[bot]@users.noreply.github.com> Date: Tue, 10 Jan 2023 13:06:39 +0000 Subject: [PATCH 510/757] Update dependency org.junit.jupiter:junit-jupiter to v5.9.2 --- gradle.properties | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gradle.properties b/gradle.properties index e966c09437..71f755522f 100644 --- a/gradle.properties +++ b/gradle.properties @@ -26,7 +26,7 @@ VER_SLF4J=[1.6,2.0[ # Used in multiple places VER_DURIAN=1.2.0 VER_JGIT=5.13.1.202206130422-r -VER_JUNIT=5.9.1 +VER_JUNIT=5.9.2 VER_ASSERTJ=3.24.1 VER_MOCKITO=4.11.0 From 0227e89d641ab85dc8f2e48f715867c0992add06 Mon Sep 17 00:00:00 2001 From: Simon Gamma Date: Tue, 10 Jan 2023 15:09:03 +0100 Subject: [PATCH 511/757] eslint: cleanup doc --- plugin-gradle/README.md | 8 ++++---- plugin-maven/README.md | 8 ++++---- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/plugin-gradle/README.md b/plugin-gradle/README.md index 878885f645..b44d79ef3d 100644 --- a/plugin-gradle/README.md +++ b/plugin-gradle/README.md @@ -624,8 +624,8 @@ For details, see the [npm detection](#npm-detection) and [`.npmrc` detection](#n The auto-discovery of config files (up the file tree) will not work when using ESLint within spotless, hence you are required to provide resolvable file paths for config files, or alternatively provide the configuration inline. -The configuration is very similar to the [ESLint (Javascript)](#eslint-javascript) configuration. It differs in supported -styleguides and the requirement for a tsconfigFile. +The configuration is very similar to the [ESLint (Javascript)](#eslint-javascript) configuration. In typescript, a +reference to a `tsconfig.json` is required. ```gradle spotless { @@ -689,8 +689,8 @@ spotless { The auto-discovery of config files (up the file tree) will not work when using ESLint within spotless, hence you are required to provide resolvable file paths for config files, or alternatively provide the configuration inline. -The configuration is very similar to the [ESLint (Typescript)](#eslint-typescript) configuration. It differs in supported -styleguides and no requirement for a tsconfig (of course). +The configuration is very similar to the [ESLint (Typescript)](#eslint-typescript) configuration. In javascript, *no* +`tsconfig.json` is supported. ```gradle diff --git a/plugin-maven/README.md b/plugin-maven/README.md index e74e1b27cf..3ec338bf10 100644 --- a/plugin-maven/README.md +++ b/plugin-maven/README.md @@ -724,8 +724,8 @@ For details, see the [npm detection](#npm-detection) and [`.npmrc` detection](#n The auto-discovery of config files (up the file tree) will not work when using ESLint within spotless, hence you are required to provide resolvable file paths for config files, or alternatively provide the configuration inline. -The configuration is very similar to the [ESLint (Javascript)](#eslint-javascript) configuration. It differs in supported -styleguides and the requirement for a tsconfigFile. +The configuration is very similar to the [ESLint (Javascript)](#eslint-javascript) configuration. In typescript, a +reference to a `tsconfig.json` is required. ```xml @@ -803,8 +803,8 @@ For details, see the [npm detection](#npm-detection) and [`.npmrc` detection](#n The auto-discovery of config files (up the file tree) will not work when using ESLint within spotless, hence you are required to provide resolvable file paths for config files, or alternatively provide the configuration inline. -The configuration is very similar to the [ESLint (Typescript)](#eslint-typescript) configuration. It differs in supported -styleguides and no requirement for a tsconfig (of course). +The configuration is very similar to the [ESLint (Typescript)](#eslint-typescript) configuration. In javascript, *no* +`tsconfig.json` is supported. ```xml From 4438d1845f94cfa25f01576f1f9f60850de4690e Mon Sep 17 00:00:00 2001 From: Benoit Lacelle Date: Tue, 10 Jan 2023 21:43:13 +0400 Subject: [PATCH 512/757] Small fixes --- plugin-maven/README.md | 11 +++++----- .../spotless/maven/AbstractSpotlessMojo.java | 12 +++++++++-- .../yaml/{JacksonYaml.java => Jackson.java} | 2 +- .../diffplug/spotless/maven/yaml/Yaml.java | 6 +++--- .../maven/MavenIntegrationHarness.java | 2 +- .../spotless/maven/json/JsonTest.java | 4 ++-- .../spotless/maven/yaml/YamlTest.java | 20 +++++++++---------- .../yaml/multiple_document.clean.yaml | 8 -------- .../yaml/multiple_documents.clean.yaml | 8 ++++++++ ..._document.yaml => multiple_documents.yaml} | 0 .../yaml/separator_comments.clean.yaml | 1 + 11 files changed, 41 insertions(+), 33 deletions(-) rename plugin-maven/src/main/java/com/diffplug/spotless/maven/yaml/{JacksonYaml.java => Jackson.java} (96%) delete mode 100644 testlib/src/main/resources/yaml/multiple_document.clean.yaml create mode 100644 testlib/src/main/resources/yaml/multiple_documents.clean.yaml rename testlib/src/main/resources/yaml/{multiple_document.yaml => multiple_documents.yaml} (100%) diff --git a/plugin-maven/README.md b/plugin-maven/README.md index 9255594375..0fe8bb52b4 100644 --- a/plugin-maven/README.md +++ b/plugin-maven/README.md @@ -768,9 +768,8 @@ for details. ```xml - - **/*.yaml - **/*.yml + + src/**/*.yaml @@ -785,11 +784,11 @@ Uses Jackson and YAMLFactory to pretty print objects: ```xml 2.13.4 - + INDENT_OUTPUT - - DEFAULT_HAS_TO_DISABLED_FEATURE + + DEFAULT_HAS_NO_DISABLED_FEATURE ``` diff --git a/plugin-maven/src/main/java/com/diffplug/spotless/maven/AbstractSpotlessMojo.java b/plugin-maven/src/main/java/com/diffplug/spotless/maven/AbstractSpotlessMojo.java index e4fdc7dcd0..31fd5fd5e3 100644 --- a/plugin-maven/src/main/java/com/diffplug/spotless/maven/AbstractSpotlessMojo.java +++ b/plugin-maven/src/main/java/com/diffplug/spotless/maven/AbstractSpotlessMojo.java @@ -1,5 +1,5 @@ /* - * Copyright 2016-2022 DiffPlug + * Copyright 2016-2023 DiffPlug * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -64,6 +64,7 @@ import com.diffplug.spotless.maven.incremental.UpToDateChecker; import com.diffplug.spotless.maven.incremental.UpToDateChecking; import com.diffplug.spotless.maven.java.Java; +import com.diffplug.spotless.maven.json.Json; import com.diffplug.spotless.maven.kotlin.Kotlin; import com.diffplug.spotless.maven.markdown.Markdown; import com.diffplug.spotless.maven.pom.Pom; @@ -71,6 +72,7 @@ import com.diffplug.spotless.maven.scala.Scala; import com.diffplug.spotless.maven.sql.Sql; import com.diffplug.spotless.maven.typescript.Typescript; +import com.diffplug.spotless.maven.yaml.Yaml; public abstract class AbstractSpotlessMojo extends AbstractMojo { private static final String DEFAULT_INDEX_FILE_NAME = "spotless-index"; @@ -167,6 +169,12 @@ public abstract class AbstractSpotlessMojo extends AbstractMojo { @Parameter private Markdown markdown; + @Parameter + private Json json; + + @Parameter + private Yaml yaml; + @Parameter(property = "spotlessFiles") private String filePatterns; @@ -331,7 +339,7 @@ private FileLocator getFileLocator() { } private List getFormatterFactories() { - return Stream.concat(formats.stream(), Stream.of(groovy, java, scala, kotlin, cpp, typescript, antlr4, pom, sql, python, markdown)) + return Stream.concat(formats.stream(), Stream.of(groovy, java, scala, kotlin, cpp, typescript, antlr4, pom, sql, python, markdown, json, yaml)) .filter(Objects::nonNull) .collect(toList()); } diff --git a/plugin-maven/src/main/java/com/diffplug/spotless/maven/yaml/JacksonYaml.java b/plugin-maven/src/main/java/com/diffplug/spotless/maven/yaml/Jackson.java similarity index 96% rename from plugin-maven/src/main/java/com/diffplug/spotless/maven/yaml/JacksonYaml.java rename to plugin-maven/src/main/java/com/diffplug/spotless/maven/yaml/Jackson.java index 86b52aac7d..2bc7617a38 100644 --- a/plugin-maven/src/main/java/com/diffplug/spotless/maven/yaml/JacksonYaml.java +++ b/plugin-maven/src/main/java/com/diffplug/spotless/maven/yaml/Jackson.java @@ -25,7 +25,7 @@ import com.diffplug.spotless.maven.FormatterStepFactory; import com.diffplug.spotless.yaml.YamlJacksonStep; -public class JacksonYaml implements FormatterStepFactory { +public class Jackson implements FormatterStepFactory { @Parameter private String version = YamlJacksonStep.defaultVersion(); diff --git a/plugin-maven/src/main/java/com/diffplug/spotless/maven/yaml/Yaml.java b/plugin-maven/src/main/java/com/diffplug/spotless/maven/yaml/Yaml.java index 20e609ceb4..6cba1b2ebd 100644 --- a/plugin-maven/src/main/java/com/diffplug/spotless/maven/yaml/Yaml.java +++ b/plugin-maven/src/main/java/com/diffplug/spotless/maven/yaml/Yaml.java @@ -15,9 +15,9 @@ */ package com.diffplug.spotless.maven.yaml; +import java.util.Collections; import java.util.Set; -import com.diffplug.common.collect.Sets; import com.diffplug.spotless.maven.FormatterFactory; /** @@ -26,7 +26,7 @@ public class Yaml extends FormatterFactory { @Override public Set defaultIncludes() { - return Sets.newHashSet("**/*.yaml", "**/*.yml"); + return Collections.emptySet(); } @Override @@ -34,7 +34,7 @@ public String licenseHeaderDelimiter() { return null; } - public void addJackson(JacksonYaml jackson) { + public void addJackson(Jackson jackson) { addStepFactory(jackson); } diff --git a/plugin-maven/src/test/java/com/diffplug/spotless/maven/MavenIntegrationHarness.java b/plugin-maven/src/test/java/com/diffplug/spotless/maven/MavenIntegrationHarness.java index 5dbd3e0075..a008a8bf4f 100644 --- a/plugin-maven/src/test/java/com/diffplug/spotless/maven/MavenIntegrationHarness.java +++ b/plugin-maven/src/test/java/com/diffplug/spotless/maven/MavenIntegrationHarness.java @@ -161,7 +161,7 @@ protected void writePomWithJsonSteps(String... steps) throws IOException { } protected void writePomWithYamlSteps(String... steps) throws IOException { - writePom(groupWithSteps("yaml", steps)); + writePom(groupWithSteps("yaml", including("**/*.yaml"), steps)); } protected void writePom(String... configuration) throws IOException { diff --git a/plugin-maven/src/test/java/com/diffplug/spotless/maven/json/JsonTest.java b/plugin-maven/src/test/java/com/diffplug/spotless/maven/json/JsonTest.java index fe6560cbec..f63dc708e9 100644 --- a/plugin-maven/src/test/java/com/diffplug/spotless/maven/json/JsonTest.java +++ b/plugin-maven/src/test/java/com/diffplug/spotless/maven/json/JsonTest.java @@ -22,7 +22,7 @@ public class JsonTest extends MavenIntegrationHarness { @Test public void testFormatJson_WithSimple_defaultConfig() throws Exception { - writePomWithJsonSteps(""); + writePomWithJsonSteps(""); setFile("json_test.json").toResource("json/sortByKeysBefore.json"); mavenRunner().withArguments("spotless:apply").runNoError().error(); @@ -31,7 +31,7 @@ public void testFormatJson_WithSimple_defaultConfig() throws Exception { @Test public void testFormatJson_WithGson_defaultConfig() throws Exception { - writePomWithJsonSteps(""); + writePomWithJsonSteps(""); setFile("json_test.json").toResource("json/sortByKeysBefore.json"); mavenRunner().withArguments("spotless:apply").runNoError().error(); diff --git a/plugin-maven/src/test/java/com/diffplug/spotless/maven/yaml/YamlTest.java b/plugin-maven/src/test/java/com/diffplug/spotless/maven/yaml/YamlTest.java index b2168ff05f..4614b42f22 100644 --- a/plugin-maven/src/test/java/com/diffplug/spotless/maven/yaml/YamlTest.java +++ b/plugin-maven/src/test/java/com/diffplug/spotless/maven/yaml/YamlTest.java @@ -22,28 +22,28 @@ public class YamlTest extends MavenIntegrationHarness { @Test public void testFormatYaml_WithJackson_defaultConfig_separatorComments() throws Exception { - writePomWithJsonSteps(""); + writePomWithYamlSteps(""); - setFile("yaml_test.json").toResource("yaml/separator_comments.yaml"); + setFile("yaml_test.yaml").toResource("yaml/separator_comments.yaml"); mavenRunner().withArguments("spotless:apply").runNoError().error(); - assertFile("yaml_test.json").sameAsResource("yaml/separator_comments.clean.yaml"); + assertFile("yaml_test.yaml").sameAsResource("yaml/separator_comments.clean.yaml"); } @Test public void testFormatYaml_WithJackson_defaultConfig_arrayBrackets() throws Exception { - writePomWithJsonSteps(""); + writePomWithYamlSteps(""); - setFile("yaml_test.json").toResource("yaml/array_with_bracket.yaml"); + setFile("yaml_test.yaml").toResource("yaml/array_with_bracket.yaml"); mavenRunner().withArguments("spotless:apply").runNoError().error(); - assertFile("yaml_test.json").sameAsResource("yaml/array_with_bracket.clean.yaml"); + assertFile("yaml_test.yaml").sameAsResource("yaml/array_with_bracket.clean.yaml"); } @Test - public void testFormatYaml_WithJackson_defaultConfig_multipleComments() throws Exception { - writePomWithJsonSteps(""); + public void testFormatYaml_WithJackson_defaultConfig_multipleDocuments() throws Exception { + writePomWithYamlSteps(""); - setFile("yaml_test.json").toResource("yaml/multiple_documents.yaml"); + setFile("yaml_test.yaml").toResource("yaml/multiple_documents.yaml"); mavenRunner().withArguments("spotless:apply").runNoError().error(); - assertFile("yaml_test.json").sameAsResource("yaml/multiple_documents.clean.yaml"); + assertFile("yaml_test.yaml").sameAsResource("yaml/multiple_documents.clean.yaml"); } } diff --git a/testlib/src/main/resources/yaml/multiple_document.clean.yaml b/testlib/src/main/resources/yaml/multiple_document.clean.yaml deleted file mode 100644 index bf46f753c0..0000000000 --- a/testlib/src/main/resources/yaml/multiple_document.clean.yaml +++ /dev/null @@ -1,8 +0,0 @@ ---- -hr: - - Mark McGwire - # Following node labeled SS - - &SS Sammy Sosa -rbi: - - *SS # Subsequent occurrence - - Ken Griffey \ No newline at end of file diff --git a/testlib/src/main/resources/yaml/multiple_documents.clean.yaml b/testlib/src/main/resources/yaml/multiple_documents.clean.yaml new file mode 100644 index 0000000000..612497c0ab --- /dev/null +++ b/testlib/src/main/resources/yaml/multiple_documents.clean.yaml @@ -0,0 +1,8 @@ +document: this is document 1 +--- + +document: this is document 2 + +--- + +document: this is document 3 \ No newline at end of file diff --git a/testlib/src/main/resources/yaml/multiple_document.yaml b/testlib/src/main/resources/yaml/multiple_documents.yaml similarity index 100% rename from testlib/src/main/resources/yaml/multiple_document.yaml rename to testlib/src/main/resources/yaml/multiple_documents.yaml diff --git a/testlib/src/main/resources/yaml/separator_comments.clean.yaml b/testlib/src/main/resources/yaml/separator_comments.clean.yaml index bf46f753c0..98160e910f 100644 --- a/testlib/src/main/resources/yaml/separator_comments.clean.yaml +++ b/testlib/src/main/resources/yaml/separator_comments.clean.yaml @@ -1,4 +1,5 @@ --- + hr: - Mark McGwire # Following node labeled SS From dcf727c4ceb1c1c1cff88d3dc4e5c38a1f6ab99e Mon Sep 17 00:00:00 2001 From: Benoit Lacelle Date: Wed, 11 Jan 2023 08:46:12 +0400 Subject: [PATCH 513/757] Add not trivial json tests --- .../spotless/maven/json/JsonTest.java | 23 +++++++++++++++++-- 1 file changed, 21 insertions(+), 2 deletions(-) diff --git a/plugin-maven/src/test/java/com/diffplug/spotless/maven/json/JsonTest.java b/plugin-maven/src/test/java/com/diffplug/spotless/maven/json/JsonTest.java index f63dc708e9..45607807b1 100644 --- a/plugin-maven/src/test/java/com/diffplug/spotless/maven/json/JsonTest.java +++ b/plugin-maven/src/test/java/com/diffplug/spotless/maven/json/JsonTest.java @@ -21,7 +21,7 @@ public class JsonTest extends MavenIntegrationHarness { @Test - public void testFormatJson_WithSimple_defaultConfig() throws Exception { + public void testFormatJson_WithSimple_defaultConfig_sortByKeys() throws Exception { writePomWithJsonSteps(""); setFile("json_test.json").toResource("json/sortByKeysBefore.json"); @@ -30,11 +30,30 @@ public void testFormatJson_WithSimple_defaultConfig() throws Exception { } @Test - public void testFormatJson_WithGson_defaultConfig() throws Exception { + public void testFormatJson_WithSimple_defaultConfig_nestedObject() throws Exception { + writePomWithJsonSteps(""); + + setFile("json_test.json").toResource("json/nestedObjectBefore.json"); + mavenRunner().withArguments("spotless:apply").runNoError().error(); + assertFile("json_test.json").sameAsResource("json/nestedObjectAfter.json"); + } + + @Test + public void testFormatJson_WithGson_defaultConfig_sortByKeys() throws Exception { writePomWithJsonSteps(""); setFile("json_test.json").toResource("json/sortByKeysBefore.json"); mavenRunner().withArguments("spotless:apply").runNoError().error(); assertFile("json_test.json").sameAsResource("json/sortByKeysAfterDisabled.json"); } + + @Test + public void testFormatJson_WithGson_sortByKeys() throws Exception { + writePomWithJsonSteps("true"); + + setFile("json_test.json").toResource("json/sortByKeysBefore.json"); + mavenRunner().withArguments("spotless:apply").runNoError().error(); + assertFile("json_test.json").sameAsResource("json/sortByKeysAfter.json"); + } + } From 0d6e8ea33bd4f77c60acfafe8c4b7c3c0df9b701 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Emil=20Sier=C5=BC=C4=99ga?= Date: Wed, 11 Jan 2023 09:20:52 +0100 Subject: [PATCH 514/757] Docs: additional info about Eclipse formatter version --- plugin-maven/README.md | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/plugin-maven/README.md b/plugin-maven/README.md index 3ec338bf10..5197f92255 100644 --- a/plugin-maven/README.md +++ b/plugin-maven/README.md @@ -241,7 +241,7 @@ any other maven phase (i.e. compile) then it can be configured as below; ```xml - 4.13.0 + 4.13.0 ${project.basedir}/eclipse-formatter.xml ``` @@ -316,7 +316,7 @@ These mechanisms already exist for the Gradle plugin. ```xml - 4.13.0 + 4.13.0 ${project.basedir}/greclipse.properties ``` @@ -466,7 +466,7 @@ Additionally, `editorConfigOverride` options will override what's supplied in `. ```xml - 4.13.0 + 4.13.0 ${project.basedir}/eclipse-cdt.xml ``` @@ -1052,7 +1052,7 @@ Alternatively you can supply spotless with a location of the `.npmrc` file to us ${project.basedir}/xml.prefs ${project.basedir}/additional.properties - 4.13.0 + 4.13.0 From e9c840f9b15bffa7a377c35df07a489f6744e9d9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Emil=20Sier=C5=BC=C4=99ga?= Date: Wed, 11 Jan 2023 09:22:09 +0100 Subject: [PATCH 515/757] Docs: update version of Eclipse formatter (4.13.0 -> 4.21.0) 4.21.0 is the latest supported version. --- plugin-maven/README.md | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/plugin-maven/README.md b/plugin-maven/README.md index 5197f92255..0e2c2982b5 100644 --- a/plugin-maven/README.md +++ b/plugin-maven/README.md @@ -241,7 +241,7 @@ any other maven phase (i.e. compile) then it can be configured as below; ```xml - 4.13.0 + 4.21.0 ${project.basedir}/eclipse-formatter.xml ``` @@ -316,7 +316,7 @@ These mechanisms already exist for the Gradle plugin. ```xml - 4.13.0 + 4.21.0 ${project.basedir}/greclipse.properties ``` @@ -466,7 +466,7 @@ Additionally, `editorConfigOverride` options will override what's supplied in `. ```xml - 4.13.0 + 4.21.0 ${project.basedir}/eclipse-cdt.xml ``` @@ -1052,7 +1052,7 @@ Alternatively you can supply spotless with a location of the `.npmrc` file to us ${project.basedir}/xml.prefs ${project.basedir}/additional.properties - 4.13.0 + 4.21.0 From a43274a225331fa753a5d70980fb33bcaaacdafc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Emil=20Sier=C5=BC=C4=99ga?= Date: Wed, 11 Jan 2023 09:25:27 +0100 Subject: [PATCH 516/757] Docs: fixed broken link to Eclipse WTP compatible versions --- plugin-maven/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugin-maven/README.md b/plugin-maven/README.md index 0e2c2982b5..c159e1ca45 100644 --- a/plugin-maven/README.md +++ b/plugin-maven/README.md @@ -1035,7 +1035,7 @@ Alternatively you can supply spotless with a location of the `.npmrc` file to us ## Eclipse web tools platform -[changelog](https://www.eclipse.org/webtools/). [compatible versions](https://github.com/diffplug/spotless/tree/main/lib-extra/src/main/resources/com/diffplug/spotless/extra/eclipse_wtp_formatters). +[changelog](https://www.eclipse.org/webtools/). [compatible versions](https://github.com/diffplug/spotless/tree/main/lib-extra/src/main/resources/com/diffplug/spotless/extra/eclipse_wtp_formatter). ```xml From 5041562dfa5e24bbc8f6cb9d3d85008d8e8e5ad1 Mon Sep 17 00:00:00 2001 From: Benoit Lacelle Date: Wed, 11 Jan 2023 14:48:22 +0400 Subject: [PATCH 517/757] Fix reflection on stringToObject --- .../main/java/com/diffplug/spotless/yaml/YamlJacksonStep.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/src/main/java/com/diffplug/spotless/yaml/YamlJacksonStep.java b/lib/src/main/java/com/diffplug/spotless/yaml/YamlJacksonStep.java index 4e76bb2941..b29c6ad267 100644 --- a/lib/src/main/java/com/diffplug/spotless/yaml/YamlJacksonStep.java +++ b/lib/src/main/java/com/diffplug/spotless/yaml/YamlJacksonStep.java @@ -132,7 +132,7 @@ FormatterFunc toFormatter() { private String format(Object objectMapper, Method stringToObject, Method objectToString, String s) throws IllegalAccessException, IllegalArgumentException { try { - Object parsed = stringToObject.invoke(s, Object.class); + Object parsed = stringToObject.invoke(objectMapper, s, Object.class); return (String) objectToString.invoke(objectMapper, parsed); } catch (InvocationTargetException ex) { throw new AssertionError("Unable to format YAML", ex.getCause()); From dcb82ae3d82437252cf93d70e3ccb8c7016b467c Mon Sep 17 00:00:00 2001 From: Benoit Lacelle Date: Wed, 11 Jan 2023 15:55:48 +0400 Subject: [PATCH 518/757] Fix cleaned YAML given limitations of Jackson --- .../resources/yaml/array_with_bracket.clean.yaml | 14 ++++++++++++-- .../resources/yaml/multiple_documents.clean.yaml | 4 ++-- .../resources/yaml/separator_comments.clean.yaml | 6 ++---- 3 files changed, 16 insertions(+), 8 deletions(-) diff --git a/testlib/src/main/resources/yaml/array_with_bracket.clean.yaml b/testlib/src/main/resources/yaml/array_with_bracket.clean.yaml index 8e9d80065e..88fc8fd541 100644 --- a/testlib/src/main/resources/yaml/array_with_bracket.clean.yaml +++ b/testlib/src/main/resources/yaml/array_with_bracket.clean.yaml @@ -1,2 +1,12 @@ -episodes: [1, 2, 3, 4, 5, 6, 7] -best-jedi: {name: Obi-Wan, side: light} \ No newline at end of file +--- +episodes: +- 1 +- 2 +- 3 +- 4 +- 5 +- 6 +- 7 +best-jedi: + name: Obi-Wan + side: light \ No newline at end of file diff --git a/testlib/src/main/resources/yaml/multiple_documents.clean.yaml b/testlib/src/main/resources/yaml/multiple_documents.clean.yaml index 612497c0ab..45e0b0916b 100644 --- a/testlib/src/main/resources/yaml/multiple_documents.clean.yaml +++ b/testlib/src/main/resources/yaml/multiple_documents.clean.yaml @@ -1,8 +1,8 @@ -document: this is document 1 --- +document: this is document 1 +--- document: this is document 2 --- - document: this is document 3 \ No newline at end of file diff --git a/testlib/src/main/resources/yaml/separator_comments.clean.yaml b/testlib/src/main/resources/yaml/separator_comments.clean.yaml index 98160e910f..7dac8a279f 100644 --- a/testlib/src/main/resources/yaml/separator_comments.clean.yaml +++ b/testlib/src/main/resources/yaml/separator_comments.clean.yaml @@ -1,9 +1,7 @@ --- - hr: - Mark McGwire - # Following node labeled SS - - &SS Sammy Sosa + - Sammy Sosa rbi: - - *SS # Subsequent occurrence + - Sammy Sosa - Ken Griffey \ No newline at end of file From fb3bb169b6d0df3322b30fa585511bb952a2163b Mon Sep 17 00:00:00 2001 From: Benoit Lacelle Date: Wed, 11 Jan 2023 16:42:03 +0400 Subject: [PATCH 519/757] Fix cleaned YAMLs --- .../src/main/resources/yaml/array_with_bracket.clean.yaml | 4 ++-- .../src/main/resources/yaml/separator_comments.clean.yaml | 8 ++++---- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/testlib/src/main/resources/yaml/array_with_bracket.clean.yaml b/testlib/src/main/resources/yaml/array_with_bracket.clean.yaml index 88fc8fd541..c6f891b9de 100644 --- a/testlib/src/main/resources/yaml/array_with_bracket.clean.yaml +++ b/testlib/src/main/resources/yaml/array_with_bracket.clean.yaml @@ -8,5 +8,5 @@ episodes: - 6 - 7 best-jedi: - name: Obi-Wan - side: light \ No newline at end of file + name: "Obi-Wan" + side: "light" \ No newline at end of file diff --git a/testlib/src/main/resources/yaml/separator_comments.clean.yaml b/testlib/src/main/resources/yaml/separator_comments.clean.yaml index 7dac8a279f..35bb8717dd 100644 --- a/testlib/src/main/resources/yaml/separator_comments.clean.yaml +++ b/testlib/src/main/resources/yaml/separator_comments.clean.yaml @@ -1,7 +1,7 @@ --- hr: - - Mark McGwire - - Sammy Sosa +- "Mark McGwire" +- "Sammy Sosa" rbi: - - Sammy Sosa - - Ken Griffey \ No newline at end of file +- "SS" +- "Ken Griffey" \ No newline at end of file From 13d9d3cd19eaa8812191c44db045aee754df569b Mon Sep 17 00:00:00 2001 From: Benoit Lacelle Date: Thu, 12 Jan 2023 11:06:03 +0400 Subject: [PATCH 520/757] Fix YAML and JSON tests --- .gitignore | 3 + .java-version | 1 - lib/build.gradle | 6 +- .../glue/yaml/YamlJacksonFormatterFunc.java | 99 +++++++++++++++++++ .../spotless/yaml/YamlJacksonStep.java | 31 ++++-- .../spotless/yaml/YamlJacksonV2Step.java | 77 +++++++++++++++ .../diffplug/spotless/maven/yaml/Jackson.java | 3 +- .../spotless/maven/json/JsonTest.java | 26 ++++- .../spotless/maven/yaml/YamlTest.java | 18 +++- .../json/sortByKeysAfterDisabled_Simple.json | 19 ++++ .../multiple_documents.clean.jackson.yaml | 2 + 11 files changed, 263 insertions(+), 22 deletions(-) delete mode 100644 .java-version create mode 100644 lib/src/jackson/java/com/diffplug/spotless/glue/yaml/YamlJacksonFormatterFunc.java create mode 100644 lib/src/main/java/com/diffplug/spotless/yaml/YamlJacksonV2Step.java create mode 100644 testlib/src/main/resources/json/sortByKeysAfterDisabled_Simple.json create mode 100644 testlib/src/main/resources/yaml/multiple_documents.clean.jackson.yaml diff --git a/.gitignore b/.gitignore index 1a95765d37..138bb77159 100644 --- a/.gitignore +++ b/.gitignore @@ -121,3 +121,6 @@ nbdist/ nbactions.xml nb-configuration.xml .nb-gradle/ + +# MacOS jenv +.java-version diff --git a/.java-version b/.java-version deleted file mode 100644 index 2dbc24b32d..0000000000 --- a/.java-version +++ /dev/null @@ -1 +0,0 @@ -11.0 diff --git a/lib/build.gradle b/lib/build.gradle index 115d27195f..0cf07f9531 100644 --- a/lib/build.gradle +++ b/lib/build.gradle @@ -14,7 +14,8 @@ def NEEDS_GLUE = [ 'ktlint', 'flexmark', 'diktat', - 'scalafmt' + 'scalafmt', + 'jackson' ] for (glue in NEEDS_GLUE) { sourceSets.register(glue) { @@ -55,6 +56,9 @@ dependencies { palantirJavaFormatCompileOnly 'com.palantir.javaformat:palantir-java-format:1.1.0' // this version needs to stay compilable against Java 8 for CI Job testNpm + // used jackson-based formatters + jacksonCompileOnly 'com.fasterxml.jackson.dataformat:jackson-dataformat-yaml:2.13.4' + String VER_KTFMT = '0.42' ktfmtCompileOnly "com.facebook:ktfmt:$VER_KTFMT" String VER_KTLINT_GOOGLE_JAVA_FORMAT = '1.7' // for JDK 8 compatibility diff --git a/lib/src/jackson/java/com/diffplug/spotless/glue/yaml/YamlJacksonFormatterFunc.java b/lib/src/jackson/java/com/diffplug/spotless/glue/yaml/YamlJacksonFormatterFunc.java new file mode 100644 index 0000000000..604ad048c8 --- /dev/null +++ b/lib/src/jackson/java/com/diffplug/spotless/glue/yaml/YamlJacksonFormatterFunc.java @@ -0,0 +1,99 @@ +/* + * Copyright 2021-2023 DiffPlug + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.diffplug.spotless.glue.yaml; + +import java.io.IOException; +import java.util.List; + +import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.core.type.TypeReference; +import com.fasterxml.jackson.databind.ObjectMapper; +import com.fasterxml.jackson.databind.SerializationFeature; +import com.fasterxml.jackson.databind.node.ObjectNode; +import com.fasterxml.jackson.dataformat.yaml.YAMLFactory; + +import com.diffplug.spotless.FormatterFunc; + +public class YamlJacksonFormatterFunc implements FormatterFunc { + private List enabledFeatures; + private List disabledFeatures; + + // private static final Logger logger = LoggerFactory.getLogger(YamlJacksonFormatterFunc.class); + + public YamlJacksonFormatterFunc(List enabledFeatures, List disabledFeatures) { + this.enabledFeatures = enabledFeatures; + this.disabledFeatures = disabledFeatures; + } + + @Override + public String apply(String input) throws Exception { + ObjectMapper objectMapper = makeObjectMapper(); + + return format(objectMapper, input); + } + + protected ObjectMapper makeObjectMapper() { + YAMLFactory yamlFactory = new YAMLFactory(); + ObjectMapper objectMapper = new ObjectMapper(yamlFactory); + + // Configure the ObjectMapper + // https://github.com/FasterXML/jackson-databind#commonly-used-features + for (String rawFeature : enabledFeatures) { + // https://stackoverflow.com/questions/3735927/java-instantiating-an-enum-using-reflection + SerializationFeature feature = SerializationFeature.valueOf(rawFeature); + + objectMapper.enable(feature); + } + + for (String rawFeature : disabledFeatures) { + // https://stackoverflow.com/questions/3735927/java-instantiating-an-enum-using-reflection + SerializationFeature feature = SerializationFeature.valueOf(rawFeature); + + objectMapper.disable(feature); + } + return objectMapper; + } + + protected String format(ObjectMapper objectMapper, String input) throws IllegalArgumentException, IOException { + // We may consider adding manually an initial '---' prefix to help management of multiple documents + // if (!input.trim().startsWith("---")) { + // input = "---" + "\n" + input; + // } + + try { + // https://stackoverflow.com/questions/25222327/deserialize-pojos-from-multiple-yaml-documents-in-a-single-file-in-jackson + // https://github.com/FasterXML/jackson-dataformats-text/issues/66#issuecomment-375328648 + // 2023-01: For now, we get 'Cannot deserialize value of type `com.fasterxml.jackson.databind.node.ObjectNode` from Array value' + // JsonParser yamlParser = objectMapper.getFactory().createParser(input); + // List docs = objectMapper.readValues(yamlParser, ObjectNode.class).readAll(); + // return objectMapper.writeValueAsString(docs); + + // 2023-01: This returns JSON instead of YAML + // This will transit with a JsonNode + // A JsonNode may keep the comments from the input node + // JsonNode jsonNode = objectMapper.readTree(input); + //Not 'toPrettyString' as one could require no INDENT_OUTPUT + // return jsonNode.toPrettyString(); + ObjectNode objectNode = objectMapper.readValue(input, ObjectNode.class); + return objectMapper.writeValueAsString(objectNode); + } catch (JsonProcessingException e) { + throw new AssertionError("Unable to format YAML. input='" + input + "'", e); + } + } + + // Spotbugs + private static class ObjectNodeTypeReference extends TypeReference {} +} diff --git a/lib/src/main/java/com/diffplug/spotless/yaml/YamlJacksonStep.java b/lib/src/main/java/com/diffplug/spotless/yaml/YamlJacksonStep.java index b29c6ad267..c0c660694b 100644 --- a/lib/src/main/java/com/diffplug/spotless/yaml/YamlJacksonStep.java +++ b/lib/src/main/java/com/diffplug/spotless/yaml/YamlJacksonStep.java @@ -31,9 +31,10 @@ /** * Simple YAML formatter which reformats the file according to Jackson YAMLFactory. */ +// https://stackoverflow.com/questions/14515994/convert-json-string-to-pretty-print-json-output-using-jackson public final class YamlJacksonStep { - private static final String MAVEN_COORDINATE = "com.fasterxml.jackson.dataformat:jackson-dataformat-yaml:"; - private static final String DEFAULT_VERSION = "2.13.4"; + static final String MAVEN_COORDINATE = "com.fasterxml.jackson.dataformat:jackson-dataformat-yaml:"; + static final String DEFAULT_VERSION = "2.13.4"; public static String defaultVersion() { return DEFAULT_VERSION; @@ -80,8 +81,8 @@ FormatterFunc toFormatter() { Method enableFeature; Method disableFeature; - Method stringToObject; - Method objectToString; + Method stringToNode; + Method nodeToString; try { ClassLoader classLoader = jarState.getClassLoader(); jsonFactoryClass = classLoader.loadClass("com.fasterxml.jackson.core.JsonFactory"); @@ -97,8 +98,18 @@ FormatterFunc toFormatter() { disableFeature = objectMapperClass.getMethod("disable", serializationFeatureClass); } - stringToObject = objectMapperClass.getMethod("readValue", String.class, Class.class); - objectToString = objectMapperClass.getMethod("writeValueAsString", Object.class); + // https://stackoverflow.com/questions/25222327/deserialize-pojos-from-multiple-yaml-documents-in-a-single-file-in-jackson + // List docs = mapper + // .readValues(yamlParser, new TypeReference {}) + // .readAll(); + + Class jsonNodeClass = classLoader.loadClass("com.fasterxml.jackson.databind.JsonNode"); + + // This will transit with a JsonNode + // A JsonNode may keep the comments from the input node + stringToNode = objectMapperClass.getMethod("readTree", String.class); + // Not 'toPrettyString' as one could require no INDENT_OUTPUT + nodeToString = jsonNodeClass.getMethod("toPrettyString"); } catch (ClassNotFoundException | NoSuchMethodException e) { throw new IllegalStateException("There was a problem preparing org.json dependencies", e); } @@ -125,15 +136,15 @@ FormatterFunc toFormatter() { disableFeature.invoke(objectMapper, indentOutput); } - return format(objectMapper, stringToObject, objectToString, s); + return format(objectMapper, stringToNode, nodeToString, s); }; } - private String format(Object objectMapper, Method stringToObject, Method objectToString, String s) + private String format(Object objectMapper, Method stringToNode, Method nodeToString, String s) throws IllegalAccessException, IllegalArgumentException { try { - Object parsed = stringToObject.invoke(objectMapper, s, Object.class); - return (String) objectToString.invoke(objectMapper, parsed); + Object node = stringToNode.invoke(objectMapper, s); + return (String) nodeToString.invoke(node); } catch (InvocationTargetException ex) { throw new AssertionError("Unable to format YAML", ex.getCause()); } diff --git a/lib/src/main/java/com/diffplug/spotless/yaml/YamlJacksonV2Step.java b/lib/src/main/java/com/diffplug/spotless/yaml/YamlJacksonV2Step.java new file mode 100644 index 0000000000..f9b1d6b7dc --- /dev/null +++ b/lib/src/main/java/com/diffplug/spotless/yaml/YamlJacksonV2Step.java @@ -0,0 +1,77 @@ +/* + * Copyright 2021-2023 DiffPlug + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.diffplug.spotless.yaml; + +import java.io.IOException; +import java.io.Serializable; +import java.lang.reflect.Constructor; +import java.lang.reflect.InvocationTargetException; +import java.util.Arrays; +import java.util.List; +import java.util.Objects; + +import com.diffplug.spotless.FormatterFunc; +import com.diffplug.spotless.FormatterStep; +import com.diffplug.spotless.JarState; +import com.diffplug.spotless.Provisioner; + +public class YamlJacksonV2Step { + private YamlJacksonV2Step() {} + + public static String defaultVersion() { + return YamlJacksonStep.DEFAULT_VERSION; + } + + public static FormatterStep create(List enabledFeatures, + List disabledFeatures, + String jacksonVersion, + Provisioner provisioner) { + Objects.requireNonNull(provisioner, "provisioner cannot be null"); + return FormatterStep.createLazy("yaml", + () -> new State(enabledFeatures, disabledFeatures, jacksonVersion, provisioner), + State::toFormatter); + } + + public static FormatterStep create(Provisioner provisioner) { + return create(Arrays.asList("INDENT_OUTPUT"), Arrays.asList(), defaultVersion(), provisioner); + } + + private static final class State implements Serializable { + private static final long serialVersionUID = 1L; + + private final List enabledFeatures; + private final List disabledFeatures; + + private final JarState jarState; + + private State(List enabledFeatures, + List disabledFeatures, + String jacksonVersion, + Provisioner provisioner) throws IOException { + this.enabledFeatures = enabledFeatures; + this.disabledFeatures = disabledFeatures; + + this.jarState = JarState.from(YamlJacksonStep.MAVEN_COORDINATE + jacksonVersion, provisioner); + } + + FormatterFunc toFormatter() throws ClassNotFoundException, NoSuchMethodException, InvocationTargetException, + InstantiationException, IllegalAccessException { + Class formatterFunc = jarState.getClassLoader().loadClass("com.diffplug.spotless.glue.yaml.YamlJacksonFormatterFunc"); + Constructor constructor = formatterFunc.getConstructor(List.class, List.class); + return (FormatterFunc) constructor.newInstance(enabledFeatures, disabledFeatures); + } + } +} diff --git a/plugin-maven/src/main/java/com/diffplug/spotless/maven/yaml/Jackson.java b/plugin-maven/src/main/java/com/diffplug/spotless/maven/yaml/Jackson.java index 2bc7617a38..28fdf5809c 100644 --- a/plugin-maven/src/main/java/com/diffplug/spotless/maven/yaml/Jackson.java +++ b/plugin-maven/src/main/java/com/diffplug/spotless/maven/yaml/Jackson.java @@ -24,6 +24,7 @@ import com.diffplug.spotless.maven.FormatterStepConfig; import com.diffplug.spotless.maven.FormatterStepFactory; import com.diffplug.spotless.yaml.YamlJacksonStep; +import com.diffplug.spotless.yaml.YamlJacksonV2Step; public class Jackson implements FormatterStepFactory { @@ -40,7 +41,7 @@ public class Jackson implements FormatterStepFactory { public FormatterStep newFormatterStep(FormatterStepConfig stepConfig) { List enabledFeaturesAsList = Arrays.asList(enabledFeatures); List disabledFeaturesAsList = Arrays.asList(disabledFeatures); - return YamlJacksonStep + return YamlJacksonV2Step .create(enabledFeaturesAsList, disabledFeaturesAsList, version, stepConfig.getProvisioner()); } } diff --git a/plugin-maven/src/test/java/com/diffplug/spotless/maven/json/JsonTest.java b/plugin-maven/src/test/java/com/diffplug/spotless/maven/json/JsonTest.java index 45607807b1..e492109faa 100644 --- a/plugin-maven/src/test/java/com/diffplug/spotless/maven/json/JsonTest.java +++ b/plugin-maven/src/test/java/com/diffplug/spotless/maven/json/JsonTest.java @@ -16,17 +16,21 @@ package com.diffplug.spotless.maven.json; import org.junit.jupiter.api.Test; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import com.diffplug.spotless.maven.MavenIntegrationHarness; public class JsonTest extends MavenIntegrationHarness { + private static final Logger LOGGER = LoggerFactory.getLogger(JsonTest.class); + @Test public void testFormatJson_WithSimple_defaultConfig_sortByKeys() throws Exception { writePomWithJsonSteps(""); setFile("json_test.json").toResource("json/sortByKeysBefore.json"); - mavenRunner().withArguments("spotless:apply").runNoError().error(); - assertFile("json_test.json").sameAsResource("json/sortByKeysAfterDisabled.json"); + mavenRunner().withArguments("spotless:apply").runNoError(); + assertFile("json_test.json").sameAsResource("json/sortByKeysAfterDisabled_Simple.json"); } @Test @@ -34,7 +38,7 @@ public void testFormatJson_WithSimple_defaultConfig_nestedObject() throws Except writePomWithJsonSteps(""); setFile("json_test.json").toResource("json/nestedObjectBefore.json"); - mavenRunner().withArguments("spotless:apply").runNoError().error(); + mavenRunner().withArguments("spotless:apply").runNoError(); assertFile("json_test.json").sameAsResource("json/nestedObjectAfter.json"); } @@ -43,7 +47,7 @@ public void testFormatJson_WithGson_defaultConfig_sortByKeys() throws Exception writePomWithJsonSteps(""); setFile("json_test.json").toResource("json/sortByKeysBefore.json"); - mavenRunner().withArguments("spotless:apply").runNoError().error(); + mavenRunner().withArguments("spotless:apply").runNoError(); assertFile("json_test.json").sameAsResource("json/sortByKeysAfterDisabled.json"); } @@ -52,8 +56,20 @@ public void testFormatJson_WithGson_sortByKeys() throws Exception { writePomWithJsonSteps("true"); setFile("json_test.json").toResource("json/sortByKeysBefore.json"); - mavenRunner().withArguments("spotless:apply").runNoError().error(); + + String output = mavenRunner().withArguments("spotless:apply").runNoError().output(); + LOGGER.error(output); + System.err.println(output); assertFile("json_test.json").sameAsResource("json/sortByKeysAfter.json"); } + @Test + public void testFormatJson_WithGson_defaultConfig_nestedObject() throws Exception { + writePomWithJsonSteps(""); + + setFile("json_test.json").toResource("json/nestedObjectBefore.json"); + mavenRunner().withArguments("spotless:apply").runNoError(); + assertFile("json_test.json").sameAsResource("json/nestedObjectAfter.json"); + } + } diff --git a/plugin-maven/src/test/java/com/diffplug/spotless/maven/yaml/YamlTest.java b/plugin-maven/src/test/java/com/diffplug/spotless/maven/yaml/YamlTest.java index 4614b42f22..b5a417c536 100644 --- a/plugin-maven/src/test/java/com/diffplug/spotless/maven/yaml/YamlTest.java +++ b/plugin-maven/src/test/java/com/diffplug/spotless/maven/yaml/YamlTest.java @@ -15,17 +15,27 @@ */ package com.diffplug.spotless.maven.yaml; +import static org.assertj.core.api.Assertions.assertThat; + import org.junit.jupiter.api.Test; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import com.diffplug.spotless.maven.MavenIntegrationHarness; +import com.diffplug.spotless.maven.MavenRunner.Result; public class YamlTest extends MavenIntegrationHarness { + private static final Logger LOGGER = LoggerFactory.getLogger(YamlTest.class); + @Test public void testFormatYaml_WithJackson_defaultConfig_separatorComments() throws Exception { writePomWithYamlSteps(""); setFile("yaml_test.yaml").toResource("yaml/separator_comments.yaml"); - mavenRunner().withArguments("spotless:apply").runNoError().error(); + Result runNoError = mavenRunner().withArguments("spotless:apply").runNoError(); + LOGGER.error("result: {}", runNoError); + assertThat(runNoError.exitValue()).as("Run without error %s", runNoError).isEqualTo(0); + LOGGER.error("GOGO"); assertFile("yaml_test.yaml").sameAsResource("yaml/separator_comments.clean.yaml"); } @@ -34,7 +44,7 @@ public void testFormatYaml_WithJackson_defaultConfig_arrayBrackets() throws Exce writePomWithYamlSteps(""); setFile("yaml_test.yaml").toResource("yaml/array_with_bracket.yaml"); - mavenRunner().withArguments("spotless:apply").runNoError().error(); + mavenRunner().withArguments("spotless:apply").runNoError(); assertFile("yaml_test.yaml").sameAsResource("yaml/array_with_bracket.clean.yaml"); } @@ -43,7 +53,7 @@ public void testFormatYaml_WithJackson_defaultConfig_multipleDocuments() throws writePomWithYamlSteps(""); setFile("yaml_test.yaml").toResource("yaml/multiple_documents.yaml"); - mavenRunner().withArguments("spotless:apply").runNoError().error(); - assertFile("yaml_test.yaml").sameAsResource("yaml/multiple_documents.clean.yaml"); + mavenRunner().withArguments("spotless:apply").runNoError(); + assertFile("yaml_test.yaml").sameAsResource("yaml/multiple_documents.clean.jackson.yaml"); } } diff --git a/testlib/src/main/resources/json/sortByKeysAfterDisabled_Simple.json b/testlib/src/main/resources/json/sortByKeysAfterDisabled_Simple.json new file mode 100644 index 0000000000..d2d3612fbd --- /dev/null +++ b/testlib/src/main/resources/json/sortByKeysAfterDisabled_Simple.json @@ -0,0 +1,19 @@ +{ + "A": 1, + "a": 3, + "c": 4, + "x": 5, + "X": 2, + "z": { + "A": 1, + "a": 3, + "c": 4, + "x": 5, + "X": 2 + }, + "_arraysNotSorted": [ + 3, + 2, + 1 + ] +} diff --git a/testlib/src/main/resources/yaml/multiple_documents.clean.jackson.yaml b/testlib/src/main/resources/yaml/multiple_documents.clean.jackson.yaml new file mode 100644 index 0000000000..aa731919b4 --- /dev/null +++ b/testlib/src/main/resources/yaml/multiple_documents.clean.jackson.yaml @@ -0,0 +1,2 @@ +--- +document: "this is document 1" From fa203e4ebb2606383f8c5253e5fa52a6b9ab9099 Mon Sep 17 00:00:00 2001 From: Benoit Lacelle Date: Thu, 12 Jan 2023 11:15:40 +0400 Subject: [PATCH 521/757] Remove reflection impl to rely on glue impl --- lib/build.gradle | 2 +- .../glue/yaml/YamlJacksonFormatterFunc.java | 2 - .../spotless/yaml/YamlJacksonStep.java | 96 +++---------------- .../spotless/yaml/YamlJacksonV2Step.java | 77 --------------- plugin-maven/README.md | 2 +- .../diffplug/spotless/maven/yaml/Jackson.java | 3 +- 6 files changed, 15 insertions(+), 167 deletions(-) delete mode 100644 lib/src/main/java/com/diffplug/spotless/yaml/YamlJacksonV2Step.java diff --git a/lib/build.gradle b/lib/build.gradle index 0cf07f9531..3ef2064765 100644 --- a/lib/build.gradle +++ b/lib/build.gradle @@ -57,7 +57,7 @@ dependencies { palantirJavaFormatCompileOnly 'com.palantir.javaformat:palantir-java-format:1.1.0' // this version needs to stay compilable against Java 8 for CI Job testNpm // used jackson-based formatters - jacksonCompileOnly 'com.fasterxml.jackson.dataformat:jackson-dataformat-yaml:2.13.4' + jacksonCompileOnly 'com.fasterxml.jackson.dataformat:jackson-dataformat-yaml:2.14.1' String VER_KTFMT = '0.42' ktfmtCompileOnly "com.facebook:ktfmt:$VER_KTFMT" diff --git a/lib/src/jackson/java/com/diffplug/spotless/glue/yaml/YamlJacksonFormatterFunc.java b/lib/src/jackson/java/com/diffplug/spotless/glue/yaml/YamlJacksonFormatterFunc.java index 604ad048c8..30cf538159 100644 --- a/lib/src/jackson/java/com/diffplug/spotless/glue/yaml/YamlJacksonFormatterFunc.java +++ b/lib/src/jackson/java/com/diffplug/spotless/glue/yaml/YamlJacksonFormatterFunc.java @@ -31,8 +31,6 @@ public class YamlJacksonFormatterFunc implements FormatterFunc { private List enabledFeatures; private List disabledFeatures; - // private static final Logger logger = LoggerFactory.getLogger(YamlJacksonFormatterFunc.class); - public YamlJacksonFormatterFunc(List enabledFeatures, List disabledFeatures) { this.enabledFeatures = enabledFeatures; this.disabledFeatures = disabledFeatures; diff --git a/lib/src/main/java/com/diffplug/spotless/yaml/YamlJacksonStep.java b/lib/src/main/java/com/diffplug/spotless/yaml/YamlJacksonStep.java index c0c660694b..db2525ab97 100644 --- a/lib/src/main/java/com/diffplug/spotless/yaml/YamlJacksonStep.java +++ b/lib/src/main/java/com/diffplug/spotless/yaml/YamlJacksonStep.java @@ -17,8 +17,8 @@ import java.io.IOException; import java.io.Serializable; +import java.lang.reflect.Constructor; import java.lang.reflect.InvocationTargetException; -import java.lang.reflect.Method; import java.util.Arrays; import java.util.List; import java.util.Objects; @@ -32,9 +32,12 @@ * Simple YAML formatter which reformats the file according to Jackson YAMLFactory. */ // https://stackoverflow.com/questions/14515994/convert-json-string-to-pretty-print-json-output-using-jackson -public final class YamlJacksonStep { +public class YamlJacksonStep { static final String MAVEN_COORDINATE = "com.fasterxml.jackson.dataformat:jackson-dataformat-yaml:"; - static final String DEFAULT_VERSION = "2.13.4"; + // https://mvnrepository.com/artifact/com.fasterxml.jackson.dataformat/jackson-dataformat-yaml + static final String DEFAULT_VERSION = "2.14.1"; + + private YamlJacksonStep() {} public static String defaultVersion() { return DEFAULT_VERSION; @@ -69,89 +72,14 @@ private State(List enabledFeatures, this.enabledFeatures = enabledFeatures; this.disabledFeatures = disabledFeatures; - this.jarState = JarState.from(MAVEN_COORDINATE + jacksonVersion, provisioner); + this.jarState = JarState.from(YamlJacksonStep.MAVEN_COORDINATE + jacksonVersion, provisioner); } - FormatterFunc toFormatter() { - Class jsonFactoryClass; - Class yamlFactoryClass; - Class objectMapperClass; - - Class serializationFeatureClass; - Method enableFeature; - Method disableFeature; - - Method stringToNode; - Method nodeToString; - try { - ClassLoader classLoader = jarState.getClassLoader(); - jsonFactoryClass = classLoader.loadClass("com.fasterxml.jackson.core.JsonFactory"); - yamlFactoryClass = classLoader.loadClass("com.fasterxml.jackson.dataformat.yaml.YAMLFactory"); - - objectMapperClass = classLoader.loadClass("com.fasterxml.jackson.databind.ObjectMapper"); - - // Configure the ObjectMapper - // https://github.com/FasterXML/jackson-databind#commonly-used-features - { - serializationFeatureClass = classLoader.loadClass("com.fasterxml.jackson.databind.SerializationFeature"); - enableFeature = objectMapperClass.getMethod("enable", serializationFeatureClass); - disableFeature = objectMapperClass.getMethod("disable", serializationFeatureClass); - } - - // https://stackoverflow.com/questions/25222327/deserialize-pojos-from-multiple-yaml-documents-in-a-single-file-in-jackson - // List docs = mapper - // .readValues(yamlParser, new TypeReference {}) - // .readAll(); - - Class jsonNodeClass = classLoader.loadClass("com.fasterxml.jackson.databind.JsonNode"); - - // This will transit with a JsonNode - // A JsonNode may keep the comments from the input node - stringToNode = objectMapperClass.getMethod("readTree", String.class); - // Not 'toPrettyString' as one could require no INDENT_OUTPUT - nodeToString = jsonNodeClass.getMethod("toPrettyString"); - } catch (ClassNotFoundException | NoSuchMethodException e) { - throw new IllegalStateException("There was a problem preparing org.json dependencies", e); - } - - return s -> { - if (s.isEmpty()) { - return s; - } - - Object yamlFactory = yamlFactoryClass.getConstructor().newInstance(); - Object objectMapper = objectMapperClass.getConstructor(jsonFactoryClass).newInstance(yamlFactory); - - for (String feature : enabledFeatures) { - // https://stackoverflow.com/questions/3735927/java-instantiating-an-enum-using-reflection - Object indentOutput = Enum.valueOf(serializationFeatureClass.asSubclass(Enum.class), feature); - - enableFeature.invoke(objectMapper, indentOutput); - } - - for (String feature : disabledFeatures) { - // https://stackoverflow.com/questions/3735927/java-instantiating-an-enum-using-reflection - Object indentOutput = Enum.valueOf(serializationFeatureClass.asSubclass(Enum.class), feature); - - disableFeature.invoke(objectMapper, indentOutput); - } - - return format(objectMapper, stringToNode, nodeToString, s); - }; + FormatterFunc toFormatter() throws ClassNotFoundException, NoSuchMethodException, InvocationTargetException, + InstantiationException, IllegalAccessException { + Class formatterFunc = jarState.getClassLoader().loadClass("com.diffplug.spotless.glue.yaml.YamlJacksonFormatterFunc"); + Constructor constructor = formatterFunc.getConstructor(List.class, List.class); + return (FormatterFunc) constructor.newInstance(enabledFeatures, disabledFeatures); } - - private String format(Object objectMapper, Method stringToNode, Method nodeToString, String s) - throws IllegalAccessException, IllegalArgumentException { - try { - Object node = stringToNode.invoke(objectMapper, s); - return (String) nodeToString.invoke(node); - } catch (InvocationTargetException ex) { - throw new AssertionError("Unable to format YAML", ex.getCause()); - } - } - } - - private YamlJacksonStep() { - // cannot be directly instantiated } } diff --git a/lib/src/main/java/com/diffplug/spotless/yaml/YamlJacksonV2Step.java b/lib/src/main/java/com/diffplug/spotless/yaml/YamlJacksonV2Step.java deleted file mode 100644 index f9b1d6b7dc..0000000000 --- a/lib/src/main/java/com/diffplug/spotless/yaml/YamlJacksonV2Step.java +++ /dev/null @@ -1,77 +0,0 @@ -/* - * Copyright 2021-2023 DiffPlug - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package com.diffplug.spotless.yaml; - -import java.io.IOException; -import java.io.Serializable; -import java.lang.reflect.Constructor; -import java.lang.reflect.InvocationTargetException; -import java.util.Arrays; -import java.util.List; -import java.util.Objects; - -import com.diffplug.spotless.FormatterFunc; -import com.diffplug.spotless.FormatterStep; -import com.diffplug.spotless.JarState; -import com.diffplug.spotless.Provisioner; - -public class YamlJacksonV2Step { - private YamlJacksonV2Step() {} - - public static String defaultVersion() { - return YamlJacksonStep.DEFAULT_VERSION; - } - - public static FormatterStep create(List enabledFeatures, - List disabledFeatures, - String jacksonVersion, - Provisioner provisioner) { - Objects.requireNonNull(provisioner, "provisioner cannot be null"); - return FormatterStep.createLazy("yaml", - () -> new State(enabledFeatures, disabledFeatures, jacksonVersion, provisioner), - State::toFormatter); - } - - public static FormatterStep create(Provisioner provisioner) { - return create(Arrays.asList("INDENT_OUTPUT"), Arrays.asList(), defaultVersion(), provisioner); - } - - private static final class State implements Serializable { - private static final long serialVersionUID = 1L; - - private final List enabledFeatures; - private final List disabledFeatures; - - private final JarState jarState; - - private State(List enabledFeatures, - List disabledFeatures, - String jacksonVersion, - Provisioner provisioner) throws IOException { - this.enabledFeatures = enabledFeatures; - this.disabledFeatures = disabledFeatures; - - this.jarState = JarState.from(YamlJacksonStep.MAVEN_COORDINATE + jacksonVersion, provisioner); - } - - FormatterFunc toFormatter() throws ClassNotFoundException, NoSuchMethodException, InvocationTargetException, - InstantiationException, IllegalAccessException { - Class formatterFunc = jarState.getClassLoader().loadClass("com.diffplug.spotless.glue.yaml.YamlJacksonFormatterFunc"); - Constructor constructor = formatterFunc.getConstructor(List.class, List.class); - return (FormatterFunc) constructor.newInstance(enabledFeatures, disabledFeatures); - } - } -} diff --git a/plugin-maven/README.md b/plugin-maven/README.md index 720c9bfee7..c5c5cf0ac3 100644 --- a/plugin-maven/README.md +++ b/plugin-maven/README.md @@ -923,7 +923,7 @@ Uses Jackson and YAMLFactory to pretty print objects: ```xml - 2.13.4 + 2.14.1 INDENT_OUTPUT diff --git a/plugin-maven/src/main/java/com/diffplug/spotless/maven/yaml/Jackson.java b/plugin-maven/src/main/java/com/diffplug/spotless/maven/yaml/Jackson.java index 28fdf5809c..2bc7617a38 100644 --- a/plugin-maven/src/main/java/com/diffplug/spotless/maven/yaml/Jackson.java +++ b/plugin-maven/src/main/java/com/diffplug/spotless/maven/yaml/Jackson.java @@ -24,7 +24,6 @@ import com.diffplug.spotless.maven.FormatterStepConfig; import com.diffplug.spotless.maven.FormatterStepFactory; import com.diffplug.spotless.yaml.YamlJacksonStep; -import com.diffplug.spotless.yaml.YamlJacksonV2Step; public class Jackson implements FormatterStepFactory { @@ -41,7 +40,7 @@ public class Jackson implements FormatterStepFactory { public FormatterStep newFormatterStep(FormatterStepConfig stepConfig) { List enabledFeaturesAsList = Arrays.asList(enabledFeatures); List disabledFeaturesAsList = Arrays.asList(disabledFeatures); - return YamlJacksonV2Step + return YamlJacksonStep .create(enabledFeaturesAsList, disabledFeaturesAsList, version, stepConfig.getProvisioner()); } } From e4dd33a852949b79acc1a59e9352cade6cdb8e02 Mon Sep 17 00:00:00 2001 From: Ned Twigg Date: Thu, 12 Jan 2023 09:29:43 -0800 Subject: [PATCH 522/757] Miinor readme and changelog updates to #1478. --- README.md | 2 ++ plugin-maven/CHANGES.md | 2 +- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 8171886965..637781d894 100644 --- a/README.md +++ b/README.md @@ -77,6 +77,7 @@ lib('python.BlackStep') +'{{yes}} | {{no}} lib('scala.ScalaFmtStep') +'{{yes}} | {{yes}} | {{yes}} | {{no}} |', lib('sql.DBeaverSQLFormatterStep') +'{{yes}} | {{yes}} | {{yes}} | {{no}} |', extra('wtp.EclipseWtpFormatterStep') +'{{yes}} | {{yes}} | {{no}} | {{no}} |', +lib('yaml.YamlJacksonStep') +'{{no}} | {{yes}} | {{no}} | {{no}} |', '| [(Your FormatterStep here)](CONTRIBUTING.md#how-to-add-a-new-formatterstep) | {{no}} | {{no}} | {{no}} | {{no}} |', ].join('\n'); --> @@ -122,6 +123,7 @@ extra('wtp.EclipseWtpFormatterStep') +'{{yes}} | {{yes}} | [`scala.ScalaFmtStep`](lib/src/main/java/com/diffplug/spotless/scala/ScalaFmtStep.java) | :+1: | :+1: | :+1: | :white_large_square: | | [`sql.DBeaverSQLFormatterStep`](lib/src/main/java/com/diffplug/spotless/sql/DBeaverSQLFormatterStep.java) | :+1: | :+1: | :+1: | :white_large_square: | | [`wtp.EclipseWtpFormatterStep`](lib-extra/src/main/java/com/diffplug/spotless/extra/wtp/EclipseWtpFormatterStep.java) | :+1: | :+1: | :white_large_square: | :white_large_square: | +| [`yaml.YamlJacksonStep`](lib/src/main/java/com/diffplug/spotless/yaml/YamlJacksonStep.java) | :white_large_square: | :+1: | :white_large_square: | :white_large_square: | | [(Your FormatterStep here)](CONTRIBUTING.md#how-to-add-a-new-formatterstep) | :white_large_square: | :white_large_square: | :white_large_square: | :white_large_square: | diff --git a/plugin-maven/CHANGES.md b/plugin-maven/CHANGES.md index ed87752a98..15d83725ea 100644 --- a/plugin-maven/CHANGES.md +++ b/plugin-maven/CHANGES.md @@ -5,7 +5,7 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format ( ## [Unreleased] ### Added * Add option `editorConfigFile` for `ktLint` [#142](https://github.com/diffplug/spotless/issues/142) -* **POTENTIALLY BREAKING** `ktlint` step now modifies license headers. Make sure to put `licenseHeader` *after* `ktlint`. + * **POTENTIALLY BREAKING** `ktlint` step now modifies license headers. Make sure to put `licenseHeader` *after* `ktlint`. * Added `skipLinesMatching` option to `licenseHeader` to support formats where license header cannot be immediately added to the top of the file (e.g. xml, sh). ([#1441](https://github.com/diffplug/spotless/pull/1441)) * Add JSON support ([#1446](https://github.com/diffplug/spotless/pull/1446)) * Add YAML support through Jackson ([#1478](https://github.com/diffplug/spotless/pull/1478)) From 2785f17c1b4d8c3f27d675c661f03101d182e5bd Mon Sep 17 00:00:00 2001 From: Ned Twigg Date: Thu, 12 Jan 2023 09:42:45 -0800 Subject: [PATCH 523/757] Fix GPG key name. --- .github/workflows/deploy.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml index 7f93bb01f6..c271788c20 100644 --- a/.github/workflows/deploy.yml +++ b/.github/workflows/deploy.yml @@ -2,7 +2,7 @@ # NEXUS_USER # NEXUS_PASS # GPG_PASSPHRASE -# GPG_KEY (base64) +# GPG_KEY64 (base64) # gpg --export-secret-keys --armor KEY_ID | openssl base64 | pbcopy # GRADLE_PORTAL_KEY # GRADLE_PORTAL_SECRET @@ -31,7 +31,7 @@ jobs: ORG_GRADLE_PROJECT_nexus_user: ${{ secrets.NEXUS_USER }} ORG_GRADLE_PROJECT_nexus_pass: ${{ secrets.NEXUS_PASS }} ORG_GRADLE_PROJECT_gpg_passphrase: ${{ secrets.GPG_PASSPHRASE }} - ORG_GRADLE_PROJECT_gpg_key64: ${{ secrets.GPG_KEY }} + ORG_GRADLE_PROJECT_gpg_key64: ${{ secrets.GPG_KEY64 }} gradle_key steps: From a0a35b2fdbda2f92b394f005ffe69dbacd8f905d Mon Sep 17 00:00:00 2001 From: Ned Twigg Date: Thu, 12 Jan 2023 10:16:04 -0800 Subject: [PATCH 524/757] Fix nonsense characters polluting gpg_key64. --- .github/workflows/deploy.yml | 2 -- 1 file changed, 2 deletions(-) diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml index c271788c20..c7e184e890 100644 --- a/.github/workflows/deploy.yml +++ b/.github/workflows/deploy.yml @@ -32,8 +32,6 @@ jobs: ORG_GRADLE_PROJECT_nexus_pass: ${{ secrets.NEXUS_PASS }} ORG_GRADLE_PROJECT_gpg_passphrase: ${{ secrets.GPG_PASSPHRASE }} ORG_GRADLE_PROJECT_gpg_key64: ${{ secrets.GPG_KEY64 }} - - gradle_key steps: - uses: actions/checkout@v3 - name: jdk 11 From 3d7dde729e835efbec122601890dbd4d5697ff1a Mon Sep 17 00:00:00 2001 From: Simon Gamma Date: Thu, 12 Jan 2023 19:09:57 +0100 Subject: [PATCH 525/757] eslint: move eslint addition to "Added" part --- CHANGES.md | 2 +- plugin-maven/CHANGES.md | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/CHANGES.md b/CHANGES.md index 1c6f0781ef..36911cc6ee 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -15,9 +15,9 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format ( * **POTENTIALLY BREAKING** `ktlint` step now modifies license headers. Make sure to put `licenseHeader` *after* `ktlint`. * Added `skipLinesMatching` option to `licenseHeader` to support formats where license header cannot be immediately added to the top of the file (e.g. xml, sh). ([#1441](https://github.com/diffplug/spotless/pull/1441)). * Add YAML support through Jackson ([#1478](https://github.com/diffplug/spotless/pull/1478)) +* Added support for npm-based [ESLint](https://eslint.org/)-formatter for javascript and typescript ([#1453](https://github.com/diffplug/spotless/pull/1453)) ### Fixed * Support `ktlint` 0.48+ new rule disabling syntax ([#1456](https://github.com/diffplug/spotless/pull/1456)) fixes ([#1444](https://github.com/diffplug/spotless/issues/1444)) -* Added support for npm-based [ESLint](https://eslint.org/)-formatter for javascript and typescript ([#1453](https://github.com/diffplug/spotless/pull/1453)) ### Changes * Bump default version for `prettier` from `2.0.5` to `2.8.1` ([#1453](https://github.com/diffplug/spotless/pull/1453)) diff --git a/plugin-maven/CHANGES.md b/plugin-maven/CHANGES.md index 15d83725ea..2f95b164b9 100644 --- a/plugin-maven/CHANGES.md +++ b/plugin-maven/CHANGES.md @@ -9,9 +9,9 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format ( * Added `skipLinesMatching` option to `licenseHeader` to support formats where license header cannot be immediately added to the top of the file (e.g. xml, sh). ([#1441](https://github.com/diffplug/spotless/pull/1441)) * Add JSON support ([#1446](https://github.com/diffplug/spotless/pull/1446)) * Add YAML support through Jackson ([#1478](https://github.com/diffplug/spotless/pull/1478)) +* Added support for npm-based [ESLint](https://eslint.org/)-formatter for javascript and typescript ([#1453](https://github.com/diffplug/spotless/pull/1453)) ### Fixed * Support `ktlint` 0.48+ new rule disabling syntax ([#1456](https://github.com/diffplug/spotless/pull/1456)) fixes ([#1444](https://github.com/diffplug/spotless/issues/1444)) -* Added support for npm-based [ESLint](https://eslint.org/)-formatter for javascript and typescript ([#1453](https://github.com/diffplug/spotless/pull/1453)) ### Changes * Bump default `ktlint` version to latest `0.47.1` -> `0.48.1` ([#1456](https://github.com/diffplug/spotless/pull/1456)) * Reduce spurious invalidations of the up-to-date index file ([#1461](https://github.com/diffplug/spotless/pull/1461)) From 27686d4402a4b038d2d4a8ddc924c78e6ffa98ac Mon Sep 17 00:00:00 2001 From: Ned Twigg Date: Thu, 12 Jan 2023 10:55:54 -0800 Subject: [PATCH 526/757] Try base64 encoding the nexus password also. --- .github/workflows/deploy.yml | 2 +- gradle/java-publish.gradle | 18 ++++++++++++++++-- 2 files changed, 17 insertions(+), 3 deletions(-) diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml index c7e184e890..67d9449e9b 100644 --- a/.github/workflows/deploy.yml +++ b/.github/workflows/deploy.yml @@ -29,7 +29,7 @@ jobs: env: gh_token: ${{ secrets.GH_TOKEN }} ORG_GRADLE_PROJECT_nexus_user: ${{ secrets.NEXUS_USER }} - ORG_GRADLE_PROJECT_nexus_pass: ${{ secrets.NEXUS_PASS }} + ORG_GRADLE_PROJECT_nexus_pass64: ${{ secrets.NEXUS_PASS64 }} ORG_GRADLE_PROJECT_gpg_passphrase: ${{ secrets.GPG_PASSPHRASE }} ORG_GRADLE_PROJECT_gpg_key64: ${{ secrets.GPG_KEY64 }} steps: diff --git a/gradle/java-publish.gradle b/gradle/java-publish.gradle index 78e73a351f..17819c8da9 100644 --- a/gradle/java-publish.gradle +++ b/gradle/java-publish.gradle @@ -1,6 +1,20 @@ +import java.nio.charset.StandardCharsets + +def decode64(String varNam) { + String envValue = System.env['ORG_GRADLE_PROJECT_nexus_user'] + if (envValue == null) { + return "" + } else { + return new String(envValue.decodeBase64(), "UTF-8") + } +} if (project.parent == null) { group = 'com.diffplug.spotless' + def pass = System.env['ORG_GRADLE_PROJECT_nexus_pass64'] + if (pass != null) { + pass = pass.decodeBase64() + } // it's the root project apply plugin: 'io.github.gradle-nexus.publish-plugin' nexusPublishing { @@ -9,7 +23,7 @@ if (project.parent == null) { nexusUrl.set(uri("https://s01.oss.sonatype.org/service/local/")) snapshotRepositoryUrl.set(uri("https://s01.oss.sonatype.org/content/repositories/snapshots/")) username = System.env['ORG_GRADLE_PROJECT_nexus_user'] - password = System.env['ORG_GRADLE_PROJECT_nexus_pass'] + password = decode64('ORG_GRADLE_PROJECT_nexus_pass64') } } } @@ -158,7 +172,7 @@ model { if (!version.endsWith('-SNAPSHOT')) { signing { - String gpg_key = new String(System.env['ORG_GRADLE_PROJECT_gpg_key64'].decodeBase64()) + String gpg_key = decode64('ORG_GRADLE_PROJECT_gpg_key64') useInMemoryPgpKeys(gpg_key, System.env['ORG_GRADLE_PROJECT_gpg_passphrase']) sign(publishing.publications) } From 8f8951ed6db38e8b117a194f01fb181d8a6ec296 Mon Sep 17 00:00:00 2001 From: Ned Twigg Date: Thu, 12 Jan 2023 11:52:12 -0800 Subject: [PATCH 527/757] Fix stupid mistake in our publishing. --- gradle/java-publish.gradle | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/gradle/java-publish.gradle b/gradle/java-publish.gradle index 17819c8da9..3d1ddd1c4f 100644 --- a/gradle/java-publish.gradle +++ b/gradle/java-publish.gradle @@ -1,7 +1,7 @@ import java.nio.charset.StandardCharsets -def decode64(String varNam) { - String envValue = System.env['ORG_GRADLE_PROJECT_nexus_user'] +def decode64(String varName) { + String envValue = System.env[varName] if (envValue == null) { return "" } else { From fd9b2af6acbcefb36a58c6614decc584da11122c Mon Sep 17 00:00:00 2001 From: Ned Twigg Date: Thu, 12 Jan 2023 11:59:44 -0800 Subject: [PATCH 528/757] Update changelogs. --- CHANGES.md | 2 +- plugin-gradle/CHANGES.md | 1 + plugin-maven/CHANGES.md | 1 + 3 files changed, 3 insertions(+), 1 deletion(-) diff --git a/CHANGES.md b/CHANGES.md index 36911cc6ee..28a857950b 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -16,9 +16,9 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format ( * Added `skipLinesMatching` option to `licenseHeader` to support formats where license header cannot be immediately added to the top of the file (e.g. xml, sh). ([#1441](https://github.com/diffplug/spotless/pull/1441)). * Add YAML support through Jackson ([#1478](https://github.com/diffplug/spotless/pull/1478)) * Added support for npm-based [ESLint](https://eslint.org/)-formatter for javascript and typescript ([#1453](https://github.com/diffplug/spotless/pull/1453)) +* Better suggested messages when user's default is set by JVM limitation. ([#995](https://github.com/diffplug/spotless/pull/995)) ### Fixed * Support `ktlint` 0.48+ new rule disabling syntax ([#1456](https://github.com/diffplug/spotless/pull/1456)) fixes ([#1444](https://github.com/diffplug/spotless/issues/1444)) - ### Changes * Bump default version for `prettier` from `2.0.5` to `2.8.1` ([#1453](https://github.com/diffplug/spotless/pull/1453)) * Bump the dev version of Gradle from `7.5.1` to `7.6` ([#1409](https://github.com/diffplug/spotless/pull/1409)) diff --git a/plugin-gradle/CHANGES.md b/plugin-gradle/CHANGES.md index 7ca75d1b34..d8b9c26275 100644 --- a/plugin-gradle/CHANGES.md +++ b/plugin-gradle/CHANGES.md @@ -8,6 +8,7 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format ( * **POTENTIALLY BREAKING** `ktlint` step now modifies license headers. Make sure to put `licenseHeader` *after* `ktlint`. * Added `skipLinesMatching` option to `licenseHeader` to support formats where license header cannot be immediately added to the top of the file (e.g. xml, sh). ([#1441](https://github.com/diffplug/spotless/pull/1441)) * Added support for npm-based [ESLint](https://eslint.org/) formatter for javascript and typescript ([#1453](https://github.com/diffplug/spotless/pull/1453)) +* Better suggested messages when user's default is set by JVM limitation. ([#995](https://github.com/diffplug/spotless/pull/995)) ### Fixed * Prevent tool configurations from being resolved outside project ([#1447](https://github.com/diffplug/spotless/pull/1447) fixes [#1215](https://github.com/diffplug/spotless/issues/1215)) * Support `ktlint` 0.48+ new rule disabling syntax ([#1456](https://github.com/diffplug/spotless/pull/1456)) fixes ([#1444](https://github.com/diffplug/spotless/issues/1444)) diff --git a/plugin-maven/CHANGES.md b/plugin-maven/CHANGES.md index 2f95b164b9..03a2a0b018 100644 --- a/plugin-maven/CHANGES.md +++ b/plugin-maven/CHANGES.md @@ -10,6 +10,7 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format ( * Add JSON support ([#1446](https://github.com/diffplug/spotless/pull/1446)) * Add YAML support through Jackson ([#1478](https://github.com/diffplug/spotless/pull/1478)) * Added support for npm-based [ESLint](https://eslint.org/)-formatter for javascript and typescript ([#1453](https://github.com/diffplug/spotless/pull/1453)) +* Better suggested messages when user's default is set by JVM limitation. ([#995](https://github.com/diffplug/spotless/pull/995)) ### Fixed * Support `ktlint` 0.48+ new rule disabling syntax ([#1456](https://github.com/diffplug/spotless/pull/1456)) fixes ([#1444](https://github.com/diffplug/spotless/issues/1444)) ### Changes From 445971c68f42aaa0651c08613ba7a74737ed4bd2 Mon Sep 17 00:00:00 2001 From: Ned Twigg Date: Thu, 12 Jan 2023 12:09:53 -0800 Subject: [PATCH 529/757] Fixup test and spotless. --- lib/src/main/java/com/diffplug/spotless/Jvm.java | 2 +- testlib/src/test/java/com/diffplug/spotless/JvmTest.java | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/lib/src/main/java/com/diffplug/spotless/Jvm.java b/lib/src/main/java/com/diffplug/spotless/Jvm.java index 0f7e1ff1a6..c9c71b72df 100644 --- a/lib/src/main/java/com/diffplug/spotless/Jvm.java +++ b/lib/src/main/java/com/diffplug/spotless/Jvm.java @@ -1,5 +1,5 @@ /* - * Copyright 2016-2022 DiffPlug + * Copyright 2016-2023 DiffPlug * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/testlib/src/test/java/com/diffplug/spotless/JvmTest.java b/testlib/src/test/java/com/diffplug/spotless/JvmTest.java index 2bb374d0ed..737c058b37 100644 --- a/testlib/src/test/java/com/diffplug/spotless/JvmTest.java +++ b/testlib/src/test/java/com/diffplug/spotless/JvmTest.java @@ -1,5 +1,5 @@ /* - * Copyright 2021 DiffPlug + * Copyright 2021-2023 DiffPlug * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -140,9 +140,9 @@ void supportProposesFormatterUpgrade() { throw new Exception("Some test exception"); }).apply(""); }).getMessage(); - assertThat(proposal).contains("not using latest version"); - assertThat(proposal).contains(String.format("on JVM %d+", requiredJvm)); - assertThat(proposal).contains(String.format("upgrade to %s %s", TEST_NAME, "2")); + assertThat(proposal).isEqualTo("My Test Formatter " + fmtVersion + " is currently being used, but outdated.\n" + + "My Test Formatter 2 is the recommended version, which may have fixed this problem.\n" + + "My Test Formatter 2 requires JVM 10+."); } } From 8de6dd574a9a85bb160dc9e0c078cd8bec994d4d Mon Sep 17 00:00:00 2001 From: Ned Twigg Date: Thu, 12 Jan 2023 12:24:32 -0800 Subject: [PATCH 530/757] Fix JvmTest on other JVMs. --- testlib/src/test/java/com/diffplug/spotless/JvmTest.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/testlib/src/test/java/com/diffplug/spotless/JvmTest.java b/testlib/src/test/java/com/diffplug/spotless/JvmTest.java index 737c058b37..2f4cf3a806 100644 --- a/testlib/src/test/java/com/diffplug/spotless/JvmTest.java +++ b/testlib/src/test/java/com/diffplug/spotless/JvmTest.java @@ -142,7 +142,7 @@ void supportProposesFormatterUpgrade() { }).getMessage(); assertThat(proposal).isEqualTo("My Test Formatter " + fmtVersion + " is currently being used, but outdated.\n" + "My Test Formatter 2 is the recommended version, which may have fixed this problem.\n" + - "My Test Formatter 2 requires JVM 10+."); + "My Test Formatter 2 requires JVM " + (requiredJvm) + "+."); } } From 66b8dd27c2169cf8dd6a95136183c1568bec2566 Mon Sep 17 00:00:00 2001 From: Ned Twigg Date: Thu, 12 Jan 2023 13:05:59 -0800 Subject: [PATCH 531/757] Fix newlines in JvmTest. --- testlib/src/test/java/com/diffplug/spotless/JvmTest.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/testlib/src/test/java/com/diffplug/spotless/JvmTest.java b/testlib/src/test/java/com/diffplug/spotless/JvmTest.java index 2f4cf3a806..ca7fb71305 100644 --- a/testlib/src/test/java/com/diffplug/spotless/JvmTest.java +++ b/testlib/src/test/java/com/diffplug/spotless/JvmTest.java @@ -140,7 +140,7 @@ void supportProposesFormatterUpgrade() { throw new Exception("Some test exception"); }).apply(""); }).getMessage(); - assertThat(proposal).isEqualTo("My Test Formatter " + fmtVersion + " is currently being used, but outdated.\n" + + assertThat(proposal.replace("\r", "")).isEqualTo("My Test Formatter " + fmtVersion + " is currently being used, but outdated.\n" + "My Test Formatter 2 is the recommended version, which may have fixed this problem.\n" + "My Test Formatter 2 requires JVM " + (requiredJvm) + "+."); } From e2f82c4ec56c422c501957b8e55468a81b815511 Mon Sep 17 00:00:00 2001 From: tison Date: Fri, 13 Jan 2023 13:18:44 +0800 Subject: [PATCH 532/757] Fix subgroups leading catch all matcher Signed-off-by: tison --- .../main/java/com/diffplug/spotless/java/ImportSorterImpl.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/src/main/java/com/diffplug/spotless/java/ImportSorterImpl.java b/lib/src/main/java/com/diffplug/spotless/java/ImportSorterImpl.java index 0390d99c1b..8ed263a780 100644 --- a/lib/src/main/java/com/diffplug/spotless/java/ImportSorterImpl.java +++ b/lib/src/main/java/com/diffplug/spotless/java/ImportSorterImpl.java @@ -45,7 +45,7 @@ private static class ImportsGroup { private final List subGroups; public ImportsGroup(String importOrder) { - this.subGroups = Stream.of(importOrder.split("\\" + SUBGROUP_SEPARATOR)) + this.subGroups = Stream.of(importOrder.split("\\" + SUBGROUP_SEPARATOR, -1)) .map(this::normalizeStatic) .collect(Collectors.toList()); } From c2d60ba1aa2e9076842c8a1cabc963be524a7297 Mon Sep 17 00:00:00 2001 From: tison Date: Fri, 13 Jan 2023 13:23:01 +0800 Subject: [PATCH 533/757] Add sortImportsFromArrayWithSubgroupsLeadingCatchAll test case Signed-off-by: tison --- ...aCodeSortedImportsSubgroupsLeadingCatchAll.test | 14 ++++++++++++++ .../spotless/java/ImportOrderStepTest.java | 6 ++++++ 2 files changed, 20 insertions(+) create mode 100644 testlib/src/main/resources/java/importsorter/JavaCodeSortedImportsSubgroupsLeadingCatchAll.test diff --git a/testlib/src/main/resources/java/importsorter/JavaCodeSortedImportsSubgroupsLeadingCatchAll.test b/testlib/src/main/resources/java/importsorter/JavaCodeSortedImportsSubgroupsLeadingCatchAll.test new file mode 100644 index 0000000000..62efc65e21 --- /dev/null +++ b/testlib/src/main/resources/java/importsorter/JavaCodeSortedImportsSubgroupsLeadingCatchAll.test @@ -0,0 +1,14 @@ +import static com.foo.Bar; +import static com.github.tomakehurst.wiremock.client.WireMock.*; +import static com.github.tomakehurst.wiremock.client.WireMock.equalTo; +import static java.lang.Exception.*; +import static java.lang.Runnable.*; +import static org.hamcrest.Matchers.*; +import java.awt.*; +import java.lang.Runnable; +import java.lang.Thread; +import java.util.*; +import java.util.List; +import javax.annotation.Nullable; +import javax.inject.Inject; +import org.dooda.Didoo; diff --git a/testlib/src/test/java/com/diffplug/spotless/java/ImportOrderStepTest.java b/testlib/src/test/java/com/diffplug/spotless/java/ImportOrderStepTest.java index 8f3bd799bc..ca6bd39825 100644 --- a/testlib/src/test/java/com/diffplug/spotless/java/ImportOrderStepTest.java +++ b/testlib/src/test/java/com/diffplug/spotless/java/ImportOrderStepTest.java @@ -41,6 +41,12 @@ void sortImportsFromArrayWithSubgroups() { StepHarness.forStep(step).testResource("java/importsorter/JavaCodeUnsortedImportsSubgroups.test", "java/importsorter/JavaCodeSortedImportsSubgroups.test"); } + @Test + void sortImportsFromArrayWithSubgroupsLeadingCatchAll() { + FormatterStep step = ImportOrderStep.forJava().createFrom("\\#|"); + StepHarness.forStep(step).testResource("java/importsorter/JavaCodeUnsortedImportsSubgroups.test", "java/importsorter/JavaCodeSortedImportsSubgroupsLeadingCatchAll.test"); + } + @Test void sortImportsFromFile() { FormatterStep step = ImportOrderStep.forJava().createFrom(createTestFile("java/importsorter/import.properties")); From 6688e3f0a9c12b5d6b38c8991af00bc89fa72e27 Mon Sep 17 00:00:00 2001 From: tison Date: Fri, 13 Jan 2023 13:24:57 +0800 Subject: [PATCH 534/757] Update CHANGES files Signed-off-by: tison --- CHANGES.md | 1 + plugin-gradle/CHANGES.md | 1 + plugin-maven/CHANGES.md | 1 + 3 files changed, 3 insertions(+) diff --git a/CHANGES.md b/CHANGES.md index f0db002dc1..035c636e0e 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -16,6 +16,7 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format ( * Added `skipLinesMatching` option to `licenseHeader` to support formats where license header cannot be immediately added to the top of the file (e.g. xml, sh). ([#1441](https://github.com/diffplug/spotless/pull/1441)). ### Fixed * Support `ktlint` 0.48+ new rule disabling syntax ([#1456](https://github.com/diffplug/spotless/pull/1456)) fixes ([#1444](https://github.com/diffplug/spotless/issues/1444)) +* Fix subgroups leading catch all matcher. ### Changes * Bump the dev version of Gradle from `7.5.1` to `7.6` ([#1409](https://github.com/diffplug/spotless/pull/1409)) diff --git a/plugin-gradle/CHANGES.md b/plugin-gradle/CHANGES.md index e8758188b6..39cbb07ad4 100644 --- a/plugin-gradle/CHANGES.md +++ b/plugin-gradle/CHANGES.md @@ -10,6 +10,7 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format ( ### Fixed * Prevent tool configurations from being resolved outside project ([#1447](https://github.com/diffplug/spotless/pull/1447) fixes [#1215](https://github.com/diffplug/spotless/issues/1215)) * Support `ktlint` 0.48+ new rule disabling syntax ([#1456](https://github.com/diffplug/spotless/pull/1456)) fixes ([#1444](https://github.com/diffplug/spotless/issues/1444)) +* Fix subgroups leading catch all matcher. ### Changes * Bump default `ktlint` version to latest `0.47.1` -> `0.48.1` ([#1456](https://github.com/diffplug/spotless/pull/1456)) diff --git a/plugin-maven/CHANGES.md b/plugin-maven/CHANGES.md index cb38f95de1..dfa7a39a45 100644 --- a/plugin-maven/CHANGES.md +++ b/plugin-maven/CHANGES.md @@ -10,6 +10,7 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format ( * Add JSON support ([#1446](https://github.com/diffplug/spotless/pull/1446)) ### Fixed * Support `ktlint` 0.48+ new rule disabling syntax ([#1456](https://github.com/diffplug/spotless/pull/1456)) fixes ([#1444](https://github.com/diffplug/spotless/issues/1444)) +* Fix subgroups leading catch all matcher. ### Changes * Bump default `ktlint` version to latest `0.47.1` -> `0.48.1` ([#1456](https://github.com/diffplug/spotless/pull/1456)) * Reduce spurious invalidations of the up-to-date index file ([#1461](https://github.com/diffplug/spotless/pull/1461)) From 109ffa6b65e71027787e11c8f66187d8c7b888da Mon Sep 17 00:00:00 2001 From: Ned Twigg Date: Fri, 13 Jan 2023 12:08:56 -0800 Subject: [PATCH 535/757] spotlessApply --- .../main/java/com/diffplug/spotless/java/ImportSorterImpl.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/src/main/java/com/diffplug/spotless/java/ImportSorterImpl.java b/lib/src/main/java/com/diffplug/spotless/java/ImportSorterImpl.java index 8ed263a780..1f014ba95e 100644 --- a/lib/src/main/java/com/diffplug/spotless/java/ImportSorterImpl.java +++ b/lib/src/main/java/com/diffplug/spotless/java/ImportSorterImpl.java @@ -1,5 +1,5 @@ /* - * Copyright 2016-2022 DiffPlug + * Copyright 2016-2023 DiffPlug * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. From 49e370b92772c0a6ef9ac1959b60738dd60e9028 Mon Sep 17 00:00:00 2001 From: Ned Twigg Date: Fri, 13 Jan 2023 14:49:39 -0800 Subject: [PATCH 536/757] Published lib/2.32.0 --- CHANGES.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/CHANGES.md b/CHANGES.md index 95c4897c7a..c08ca86796 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -10,6 +10,8 @@ This document is intended for Spotless developers. We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format (starting after version `1.27.0`). ## [Unreleased] + +## [2.32.0] - 2023-01-13 ### Added * Add option `editorConfigFile` for `ktLint` [#142](https://github.com/diffplug/spotless/issues/142) * **POTENTIALLY BREAKING** `ktlint` step now modifies license headers. Make sure to put `licenseHeader` *after* `ktlint`. @@ -33,7 +35,6 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format ( * Switch our publishing infrastructure from CircleCI to GitHub Actions ([#1462](https://github.com/diffplug/spotless/pull/1462)). * Help wanted for moving our tests too ([#1472](https://github.com/diffplug/spotless/issues/1472)) - ## [2.31.1] - 2023-01-02 ### Fixed * Improve memory usage when using git ratchet ([#1426](https://github.com/diffplug/spotless/pull/1426)) From 49505b819ca756e510cc20c9f7f912c62d1fc994 Mon Sep 17 00:00:00 2001 From: Ned Twigg Date: Fri, 13 Jan 2023 14:50:44 -0800 Subject: [PATCH 537/757] Improve deploy.yml docs since we're actually using Base64. --- .github/workflows/deploy.yml | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml index 67d9449e9b..ce7b82f820 100644 --- a/.github/workflows/deploy.yml +++ b/.github/workflows/deploy.yml @@ -1,6 +1,9 @@ # GH_TOKEN # NEXUS_USER -# NEXUS_PASS +# NEXUS_PASS64 (base64 NOTE: `base64` and `openssl base64` failed, had to use Java +# byte[] data = "{{password}}".getBytes(StandardCharsets.UTF_8); +# String encoded = new String(Base64.getEncoder().encode(data), StandardCharsets.UTF_8); +# System.out.println(encoded); # GPG_PASSPHRASE # GPG_KEY64 (base64) # gpg --export-secret-keys --armor KEY_ID | openssl base64 | pbcopy From 84b42b46e850009936359d57a04ee7f25835de96 Mon Sep 17 00:00:00 2001 From: Ned Twigg Date: Fri, 13 Jan 2023 15:10:12 -0800 Subject: [PATCH 538/757] Fix deprecation in how gradle plugins are published. --- plugin-gradle/build.gradle | 42 +++++++++++++++++--------------------- 1 file changed, 19 insertions(+), 23 deletions(-) diff --git a/plugin-gradle/build.gradle b/plugin-gradle/build.gradle index ba60eb450f..6a7f7dca01 100644 --- a/plugin-gradle/build.gradle +++ b/plugin-gradle/build.gradle @@ -38,12 +38,31 @@ apply from: rootProject.file('gradle/special-tests.gradle') // GRADLE PLUGIN PORTAL // ////////////////////////// gradlePlugin { + website = "https://github.com/diffplug/spotless" + vcsUrl = "https://github.com/diffplug/spotless" plugins { spotlessPlugin { id = 'com.diffplug.spotless' implementationClass = 'com.diffplug.gradle.spotless.SpotlessPlugin' displayName = 'Spotless formatting plugin' description = project.description + tags.set([ + 'format', + 'style', + 'license', + 'header', + 'google-java-format', + 'eclipse', + 'ktlint', + 'ktfmt', + 'diktat', + 'tsfmt', + 'prettier', + 'scalafmt', + 'scalafix', + 'black', + 'clang-format' + ]) } spotlessPluginLegacy { id = 'com.diffplug.gradle.spotless' @@ -55,29 +74,6 @@ gradlePlugin { } if (version.endsWith('-SNAPSHOT')) { publishPlugins.enabled = false -} else { - pluginBundle { - // These settings are set for the whole plugin bundle - website = "https://github.com/diffplug/spotless" - vcsUrl = "https://github.com/diffplug/spotless" - tags = [ - 'format', - 'style', - 'license', - 'header', - 'google-java-format', - 'eclipse', - 'ktlint', - 'ktfmt', - 'diktat', - 'tsfmt', - 'prettier', - 'scalafmt', - 'scalafix', - 'black', - 'clang-format' - ] - } } // have to apply java-publish after setting up the pluginBundle From be90ffcf49cb9fce8224ce91b11631fc391c83c6 Mon Sep 17 00:00:00 2001 From: Ned Twigg Date: Fri, 13 Jan 2023 15:13:41 -0800 Subject: [PATCH 539/757] Oops, fix the gradle plugin build. --- .github/workflows/deploy.yml | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml index ce7b82f820..9a1dcdf609 100644 --- a/.github/workflows/deploy.yml +++ b/.github/workflows/deploy.yml @@ -7,8 +7,8 @@ # GPG_PASSPHRASE # GPG_KEY64 (base64) # gpg --export-secret-keys --armor KEY_ID | openssl base64 | pbcopy -# GRADLE_PORTAL_KEY -# GRADLE_PORTAL_SECRET +# GRADLE_KEY +# GRADLE_SECRET name: deploy on: @@ -49,12 +49,12 @@ jobs: if: "${{ github.event.inputs.to_publish == 'all' }}" run: | ./gradlew :changelogPush -Prelease=true --stacktrace --warning-mode all - ./gradlew :plugin-gradle:changelogPush -Prelease=true -Pgradle.publish.key=${{ secrets.GRADLE_PORTAL_KEY }} -Pgradle.publish.secret=${{ secrets.GRADLE_PORTAL_SECRET }} --stacktrace --warning-mode all + ./gradlew :plugin-gradle:changelogPush -Prelease=true -Pgradle.publish.key=${{ secrets.GRADLE_KEY }} -Pgradle.publish.secret=${{ secrets.GRADLE_SECRET }} --stacktrace --warning-mode all ./gradlew :plugin-maven:changelogPush -Prelease=true --stacktrace --warning-mode all - name: publish just plugin-gradle if: "${{ github.event.inputs.to_publish == 'plugin-gradle' }}" run: | - ./gradlew :plugin-gradle:changelogPush -Prelease=true -Pgradle.publish.key=${{ secrets.GRADLE_PORTAL_KEY }} -Pgradle.publish.secret=${{ secrets.GRADLE_PORTAL_SECRET }} --stacktrace --warning-mode all + ./gradlew :plugin-gradle:changelogPush -Prelease=true -Pgradle.publish.key=${{ secrets.GRADLE_KEY }} -Pgradle.publish.secret=${{ secrets.GRADLE_SECRET }} --stacktrace --warning-mode all - name: publish just plugin-maven if: "${{ github.event.inputs.to_publish == 'plugin-maven' }}" run: | From 5c10387fa94d90277bf665bc321e1ad3cdd647a3 Mon Sep 17 00:00:00 2001 From: Ned Twigg Date: Fri, 13 Jan 2023 15:19:40 -0800 Subject: [PATCH 540/757] Bump plugin-maven changelog. --- plugin-maven/CHANGES.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/plugin-maven/CHANGES.md b/plugin-maven/CHANGES.md index 6f59030a8e..05cc349e9f 100644 --- a/plugin-maven/CHANGES.md +++ b/plugin-maven/CHANGES.md @@ -3,6 +3,8 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format (starting after version `1.27.0`). ## [Unreleased] + +## [2.30.0] - 2023-01-13 ### Added * Add option `editorConfigFile` for `ktLint` [#142](https://github.com/diffplug/spotless/issues/142) * **POTENTIALLY BREAKING** `ktlint` step now modifies license headers. Make sure to put `licenseHeader` *after* `ktlint`. From 54bcc6068debe62d87c489532821bd284786d2da Mon Sep 17 00:00:00 2001 From: Ned Twigg Date: Fri, 13 Jan 2023 15:43:36 -0800 Subject: [PATCH 541/757] spotlessApply --- plugin-maven/README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/plugin-maven/README.md b/plugin-maven/README.md index 60975f1e52..4232f76e39 100644 --- a/plugin-maven/README.md +++ b/plugin-maven/README.md @@ -12,8 +12,8 @@ output = [ ].join('\n'); --> [![Maven central](https://img.shields.io/badge/mavencentral-com.diffplug.spotless%3Aspotless--maven--plugin-blue.svg)](https://search.maven.org/#search%7Cgav%7C1%7Cg%3A%22com.diffplug.spotless%22%20AND%20a%3A%22spotless-maven-plugin%22) -[![Javadoc](https://img.shields.io/badge/javadoc-yes-blue.svg)](https://javadoc.io/doc/com.diffplug.spotless/spotless-maven-plugin/2.29.0/index.html) -[![Changelog](https://img.shields.io/badge/changelog-2.29.0-brightgreen.svg)](CHANGES.md) +[![Javadoc](https://img.shields.io/badge/javadoc-yes-blue.svg)](https://javadoc.io/doc/com.diffplug.spotless/spotless-maven-plugin/2.30.0/index.html) +[![Changelog](https://img.shields.io/badge/changelog-2.30.0-brightgreen.svg)](CHANGES.md) [![Circle CI](https://circleci.com/gh/diffplug/spotless/tree/main.svg?style=shield)](https://circleci.com/gh/diffplug/spotless/tree/main) [![Live chat](https://img.shields.io/badge/gitter-chat-brightgreen.svg)](https://gitter.im/diffplug/spotless) From 8734c3b1f27302c504b0c33e817f887deb5e2d44 Mon Sep 17 00:00:00 2001 From: "renovate[bot]" <29139614+renovate[bot]@users.noreply.github.com> Date: Sat, 14 Jan 2023 11:53:17 +0000 Subject: [PATCH 542/757] Update dependency org.mockito:mockito-core to v5 --- gradle.properties | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gradle.properties b/gradle.properties index 71f755522f..23ec1efd7a 100644 --- a/gradle.properties +++ b/gradle.properties @@ -28,7 +28,7 @@ VER_DURIAN=1.2.0 VER_JGIT=5.13.1.202206130422-r VER_JUNIT=5.9.2 VER_ASSERTJ=3.24.1 -VER_MOCKITO=4.11.0 +VER_MOCKITO=5.0.0 # Used for Maven Plugin VER_MAVEN_API=3.0 From 5d73b3ba2313d2d511cc51a18d746031f2ee47d1 Mon Sep 17 00:00:00 2001 From: Ned Twigg Date: Sat, 14 Jan 2023 15:01:55 -0800 Subject: [PATCH 543/757] Fix bug in gradle publishing. --- plugin-gradle/build.gradle | 1 + 1 file changed, 1 insertion(+) diff --git a/plugin-gradle/build.gradle b/plugin-gradle/build.gradle index 6a7f7dca01..e65bda9f70 100644 --- a/plugin-gradle/build.gradle +++ b/plugin-gradle/build.gradle @@ -69,6 +69,7 @@ gradlePlugin { implementationClass = 'com.diffplug.gradle.spotless.SpotlessPluginRedirect' displayName = 'Spotless formatting plugin (legacy)' description = project.description + tags.set(['format']) } } } From fdb58d79c7952e8fcf55ff049fefd84faeb5f01c Mon Sep 17 00:00:00 2001 From: Ned Twigg Date: Sat, 14 Jan 2023 15:04:02 -0800 Subject: [PATCH 544/757] Published plugin-gradle/6.13.0 --- plugin-gradle/CHANGES.md | 2 ++ plugin-gradle/README.md | 48 +++++++++++++++++++------------------- plugin-gradle/build.gradle | 4 +++- 3 files changed, 29 insertions(+), 25 deletions(-) diff --git a/plugin-gradle/CHANGES.md b/plugin-gradle/CHANGES.md index f6210ce8de..e2e32680fe 100644 --- a/plugin-gradle/CHANGES.md +++ b/plugin-gradle/CHANGES.md @@ -3,6 +3,8 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format (starting after version `3.27.0`). ## [Unreleased] + +## [6.13.0] - 2023-01-14 ### Added * **POTENTIALLY BREAKING** `ktlint` step now supports `.editorconfig` ([#1442](https://github.com/diffplug/spotless/pull/1442) implements [#142](https://github.com/diffplug/spotless/issues/142)) * **POTENTIALLY BREAKING** `ktlint` step now modifies license headers. Make sure to put `licenseHeader` *after* `ktlint`. diff --git a/plugin-gradle/README.md b/plugin-gradle/README.md index b44d79ef3d..f2567a5924 100644 --- a/plugin-gradle/README.md +++ b/plugin-gradle/README.md @@ -18,9 +18,9 @@ output = [ --> [![Gradle plugin](https://img.shields.io/badge/plugins.gradle.org-com.diffplug.spotless-blue.svg)](https://plugins.gradle.org/plugin/com.diffplug.spotless) [![Maven central](https://img.shields.io/badge/mavencentral-yes-blue.svg)](https://search.maven.org/#search%7Cgav%7C1%7Cg%3A%22com.diffplug.spotless%22%20AND%20a%3A%22spotless-plugin-gradle%22) -[![Javadoc](https://img.shields.io/badge/javadoc-yes-blue.svg)](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.12.1/index.html) +[![Javadoc](https://img.shields.io/badge/javadoc-yes-blue.svg)](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.13.0/index.html) [![License Apache](https://img.shields.io/badge/license-apache-blue.svg)](https://tldrlegal.com/license/apache-license-2.0-(apache-2.0)) -[![Changelog](https://img.shields.io/badge/changelog-6.12.1-blue.svg)](CHANGES.md) +[![Changelog](https://img.shields.io/badge/changelog-6.13.0-blue.svg)](CHANGES.md) [![Circle CI](https://circleci.com/gh/diffplug/spotless/tree/main.svg?style=shield)](https://circleci.com/gh/diffplug/spotless/tree/main) [![Live chat](https://img.shields.io/badge/gitter-chat-brightgreen.svg)](https://gitter.im/diffplug/spotless) @@ -129,10 +129,10 @@ spotless { ``` Spotless consists of a list of formats (in the example above, `misc` and `java`), and each format has: -- a `target` (the files to format), which you set with [`target`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.12.1/com/diffplug/gradle/spotless/FormatExtension.html#target-java.lang.Object...-) and [`targetExclude`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.12.1/com/diffplug/gradle/spotless/FormatExtension.html#targetExclude-java.lang.Object...-) -- a list of `FormatterStep`, which are just `String -> String` functions, such as [`replace`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.12.1/com/diffplug/gradle/spotless/FormatExtension.html#replace-java.lang.String-java.lang.CharSequence-java.lang.CharSequence-), [`replaceRegex`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.12.1/com/diffplug/gradle/spotless/FormatExtension.html#replaceRegex-java.lang.String-java.lang.String-java.lang.String-), [`trimTrailingWhitespace`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.12.1/com/diffplug/gradle/spotless/FormatExtension.html#replace-java.lang.String-java.lang.CharSequence-java.lang.CharSequence-), [`custom`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.12.1/com/diffplug/gradle/spotless/FormatExtension.html#custom-java.lang.String-groovy.lang.Closure-), [`prettier`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.12.1/com/diffplug/gradle/spotless/FormatExtension.html#prettier--), [`eclipseWtp`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.12.1/com/diffplug/gradle/spotless/FormatExtension.html#eclipseWtp-com.diffplug.spotless.extra.wtp.EclipseWtpFormatterStep-), [`licenseHeader`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.12.1/com/diffplug/gradle/spotless/FormatExtension.html#licenseHeader-java.lang.String-java.lang.String-) etc. +- a `target` (the files to format), which you set with [`target`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.13.0/com/diffplug/gradle/spotless/FormatExtension.html#target-java.lang.Object...-) and [`targetExclude`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.13.0/com/diffplug/gradle/spotless/FormatExtension.html#targetExclude-java.lang.Object...-) +- a list of `FormatterStep`, which are just `String -> String` functions, such as [`replace`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.13.0/com/diffplug/gradle/spotless/FormatExtension.html#replace-java.lang.String-java.lang.CharSequence-java.lang.CharSequence-), [`replaceRegex`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.13.0/com/diffplug/gradle/spotless/FormatExtension.html#replaceRegex-java.lang.String-java.lang.String-java.lang.String-), [`trimTrailingWhitespace`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.13.0/com/diffplug/gradle/spotless/FormatExtension.html#replace-java.lang.String-java.lang.CharSequence-java.lang.CharSequence-), [`custom`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.13.0/com/diffplug/gradle/spotless/FormatExtension.html#custom-java.lang.String-groovy.lang.Closure-), [`prettier`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.13.0/com/diffplug/gradle/spotless/FormatExtension.html#prettier--), [`eclipseWtp`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.13.0/com/diffplug/gradle/spotless/FormatExtension.html#eclipseWtp-com.diffplug.spotless.extra.wtp.EclipseWtpFormatterStep-), [`licenseHeader`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.13.0/com/diffplug/gradle/spotless/FormatExtension.html#licenseHeader-java.lang.String-java.lang.String-) etc. -All the generic steps live in [`FormatExtension`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.12.1/com/diffplug/gradle/spotless/FormatExtension.html), and there are many language-specific steps which live in its language-specific subclasses, which are described below. +All the generic steps live in [`FormatExtension`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.13.0/com/diffplug/gradle/spotless/FormatExtension.html), and there are many language-specific steps which live in its language-specific subclasses, which are described below. ### Requirements @@ -144,7 +144,7 @@ If you're stuck on an older version of Gradle, `id 'com.diffplug.gradle.spotless ## Java -`com.diffplug.gradle.spotless.JavaExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.12.1/com/diffplug/gradle/spotless/JavaExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/JavaExtension.java) +`com.diffplug.gradle.spotless.JavaExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.13.0/com/diffplug/gradle/spotless/JavaExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/JavaExtension.java) ```gradle spotless { @@ -268,8 +268,8 @@ You can make a pull request to add new annotations to Spotless's default list. ## Groovy -- `com.diffplug.gradle.spotless.GroovyExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.12.1/com/diffplug/gradle/spotless/GroovyExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/GroovyExtension.java) -- `com.diffplug.gradle.spotless.GroovyGradleExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.12.1/com/diffplug/gradle/spotless/GroovyGradleExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/GroovyGradleExtension.java) +- `com.diffplug.gradle.spotless.GroovyExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.13.0/com/diffplug/gradle/spotless/GroovyExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/GroovyExtension.java) +- `com.diffplug.gradle.spotless.GroovyGradleExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.13.0/com/diffplug/gradle/spotless/GroovyGradleExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/GroovyGradleExtension.java) Configuration for Groovy is similar to [Java](#java), in that it also supports `licenseHeader` and `importOrder`. @@ -320,8 +320,8 @@ Groovy-Eclipse formatting errors/warnings lead per default to a build failure. T ## Kotlin -- `com.diffplug.gradle.spotless.KotlinExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.12.1/com/diffplug/gradle/spotless/KotlinExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/KotlinExtension.java) -- `com.diffplug.gradle.spotless.KotlinGradleExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.12.1/com/diffplug/gradle/spotless/KotlinGradleExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/KotlinGradleExtension.java) +- `com.diffplug.gradle.spotless.KotlinExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.13.0/com/diffplug/gradle/spotless/KotlinExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/KotlinExtension.java) +- `com.diffplug.gradle.spotless.KotlinGradleExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.13.0/com/diffplug/gradle/spotless/KotlinGradleExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/KotlinGradleExtension.java) ```gradle spotless { // if you are using build.gradle.kts, instead of 'spotless {' use: @@ -392,7 +392,7 @@ spotless { ## Scala -`com.diffplug.gradle.spotless.ScalaExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.12.1/com/diffplug/gradle/spotless/ScalaExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/ScalaExtension.java) +`com.diffplug.gradle.spotless.ScalaExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.13.0/com/diffplug/gradle/spotless/ScalaExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/ScalaExtension.java) ```gradle spotless { @@ -424,7 +424,7 @@ spotless { ## C/C++ -`com.diffplug.gradle.spotless.CppExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.12.1/com/diffplug/gradle/spotless/CppExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/CppExtension.java) +`com.diffplug.gradle.spotless.CppExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.13.0/com/diffplug/gradle/spotless/CppExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/CppExtension.java) ```gradle spotless { @@ -456,7 +456,7 @@ spotles { ## Python -`com.diffplug.gradle.spotless.PythonExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.12.1/com/diffplug/gradle/spotless/PythonExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/PythonExtension.java) +`com.diffplug.gradle.spotless.PythonExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.13.0/com/diffplug/gradle/spotless/PythonExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/PythonExtension.java) ```gradle spotless { @@ -490,7 +490,7 @@ black().pathToExe('C:/myuser/.pyenv/versions/3.8.0/scripts/black.exe') ## FreshMark -`com.diffplug.gradle.spotless.FreshMarkExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.12.1/com/diffplug/gradle/spotless/FreshMarkExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/FreshMarkExtension.java) +`com.diffplug.gradle.spotless.FreshMarkExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.13.0/com/diffplug/gradle/spotless/FreshMarkExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/FreshMarkExtension.java) [homepage](https://github.com/diffplug/freshmark). [changelog](https://github.com/diffplug/freshmark/blob/master/CHANGES.md). FreshMark lets you generate markdown in the comments of your markdown. This helps to keep badges and links up-to-date (see the source for this file), and can also be helpful for generating complex tables (see the source for [the parent readme](../README.md)). @@ -511,7 +511,7 @@ spotless { ## Antlr4 -`com.diffplug.gradle.spotless.Antlr4Extension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.12.1/com/diffplug/gradle/spotless/Antlr4Extension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/Antlr4Extension.java) +`com.diffplug.gradle.spotless.Antlr4Extension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.13.0/com/diffplug/gradle/spotless/Antlr4Extension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/Antlr4Extension.java) ```gradle spotless { @@ -536,7 +536,7 @@ antlr4formatter('1.2.1') // version is optional ## SQL -`com.diffplug.gradle.spotless.SqlExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.12.1/com/diffplug/gradle/spotless/SqlExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/SqlExtension.java) +`com.diffplug.gradle.spotless.SqlExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.13.0/com/diffplug/gradle/spotless/SqlExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/SqlExtension.java) ```gradle spotless { @@ -576,7 +576,7 @@ sql.formatter.indent.size=4 ## Typescript -- `com.diffplug.gradle.spotless.TypescriptExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.12.1/com/diffplug/gradle/spotless/TypescriptExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/TypescriptExtension.java) +- `com.diffplug.gradle.spotless.TypescriptExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.13.0/com/diffplug/gradle/spotless/TypescriptExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/TypescriptExtension.java) ```gradle spotless { @@ -668,7 +668,7 @@ For details, see the [npm detection](#npm-detection) and [`.npmrc` detection](#n ## Javascript -- `com.diffplug.gradle.spotless.JavascriptExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.12.1/com/diffplug/gradle/spotless/JavascriptExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/JavascriptExtension.java) +- `com.diffplug.gradle.spotless.JavascriptExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.13.0/com/diffplug/gradle/spotless/JavascriptExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/JavascriptExtension.java) ```gradle spotless { @@ -732,7 +732,7 @@ For details, see the [npm detection](#npm-detection) and [`.npmrc` detection](#n ## JSON -- `com.diffplug.gradle.spotless.JsonExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.12.1/com/diffplug/gradle/spotless/JsonExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/JsonExtension.java) +- `com.diffplug.gradle.spotless.JsonExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.13.0/com/diffplug/gradle/spotless/JsonExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/JsonExtension.java) ```gradle spotless { @@ -957,7 +957,7 @@ Once a file's license header has a valid year, whether it is a year (`2020`) or * `2017` -> `2017-2020` * `2017-2019` -> `2017-2020` -See the [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.12.1/com/diffplug/gradle/spotless/FormatExtension.LicenseHeaderConfig.html) for a complete listing of options. +See the [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.13.0/com/diffplug/gradle/spotless/FormatExtension.LicenseHeaderConfig.html) for a complete listing of options. @@ -1030,9 +1030,9 @@ spotless { custom 'lowercase', { str -> str.toLowerCase() } ``` -However, custom rules will disable up-to-date checking and caching, unless you read [this javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.12.1/com/diffplug/gradle/spotless/FormatExtension.html#bumpThisNumberIfACustomStepChanges-int-) and follow its instructions carefully. +However, custom rules will disable up-to-date checking and caching, unless you read [this javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.13.0/com/diffplug/gradle/spotless/FormatExtension.html#bumpThisNumberIfACustomStepChanges-int-) and follow its instructions carefully. -Another option is to create proper `FormatterStep` in your `buildSrc`, and then call [`addStep`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.12.1/com/diffplug/gradle/spotless/FormatExtension.html#addStep-com.diffplug.spotless.FormatterStep-). The contributing guide describes [how to do this](https://github.com/diffplug/spotless/blob/main/CONTRIBUTING.md#how-to-add-a-new-formatterstep). If the step is generally-useful, we hope you'll open a PR to share it! +Another option is to create proper `FormatterStep` in your `buildSrc`, and then call [`addStep`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.13.0/com/diffplug/gradle/spotless/FormatExtension.html#addStep-com.diffplug.spotless.FormatterStep-). The contributing guide describes [how to do this](https://github.com/diffplug/spotless/blob/main/CONTRIBUTING.md#how-to-add-a-new-formatterstep). If the step is generally-useful, we hope you'll open a PR to share it! ```gradle @@ -1065,11 +1065,11 @@ spotless { format 'foo', com.acme.FooLanguageExtension, { ``` -If you'd like to create a one-off Spotless task outside of the `check`/`apply` framework, see [`FormatExtension.createIndependentApplyTask`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.12.1/com/diffplug/gradle/spotless/FormatExtension.html#createIndependentApplyTask-java.lang.String-). +If you'd like to create a one-off Spotless task outside of the `check`/`apply` framework, see [`FormatExtension.createIndependentApplyTask`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.13.0/com/diffplug/gradle/spotless/FormatExtension.html#createIndependentApplyTask-java.lang.String-). ## Inception (languages within languages within...) -In very rare cases, you might want to format e.g. javascript which is written inside JSP templates, or maybe java within a markdown file, or something wacky like that. You can specify hunks within a file using either open/close tags or a regex with a single capturing group, and then specify rules within it, like so. See [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.12.1/com/diffplug/gradle/spotless/FormatExtension.html#withinBlocks-java.lang.String-java.lang.String-java.lang.String-org.gradle.api.Action-) for more details. +In very rare cases, you might want to format e.g. javascript which is written inside JSP templates, or maybe java within a markdown file, or something wacky like that. You can specify hunks within a file using either open/close tags or a regex with a single capturing group, and then specify rules within it, like so. See [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.13.0/com/diffplug/gradle/spotless/FormatExtension.html#withinBlocks-java.lang.String-java.lang.String-java.lang.String-org.gradle.api.Action-) for more details. ```gradle import com.diffplug.gradle.spotless.JavaExtension diff --git a/plugin-gradle/build.gradle b/plugin-gradle/build.gradle index e65bda9f70..8a3260d943 100644 --- a/plugin-gradle/build.gradle +++ b/plugin-gradle/build.gradle @@ -69,7 +69,9 @@ gradlePlugin { implementationClass = 'com.diffplug.gradle.spotless.SpotlessPluginRedirect' displayName = 'Spotless formatting plugin (legacy)' description = project.description - tags.set(['format']) + tags.set([ + 'format' + ]) } } } From 67f0db5c53b3877627e018c0b79bd93559cd9277 Mon Sep 17 00:00:00 2001 From: Ned Twigg Date: Sat, 14 Jan 2023 16:06:41 -0800 Subject: [PATCH 545/757] First steps in adapting #1477 to match #1472. --- .github/workflows/build-ci.yml | 67 ---------------------------------- .github/workflows/ci.yml | 43 ++++++++++++++++++++++ 2 files changed, 43 insertions(+), 67 deletions(-) delete mode 100644 .github/workflows/build-ci.yml create mode 100644 .github/workflows/ci.yml diff --git a/.github/workflows/build-ci.yml b/.github/workflows/build-ci.yml deleted file mode 100644 index ea12b03764..0000000000 --- a/.github/workflows/build-ci.yml +++ /dev/null @@ -1,67 +0,0 @@ -on: - push: - branches: - - main - pull_request: - types: [assigned, opened, synchronize, reopened] - -jobs: - buildTest: - name: Build CI - runs-on: ubuntu-latest - strategy: - fail-fast: false - matrix: - java_version: [11, 17] - distribution: ["temurin"] - steps: - - name: Checkout - uses: actions/checkout@v3 - - name: Install JDK ${{ matrix.distribution }} ${{ matrix.java_version }} - uses: actions/setup-java@v3.9.0 - with: - distribution: ${{ matrix.distribution }} - java-version: ${{ matrix.java_version }} - cache: gradle - - name: Build project - run: ./gradlew build -x spotlessCheck -S - spotless: - name: Check Spotless - runs-on: ubuntu-latest - strategy: - fail-fast: false - matrix: - java_version: [11] - distribution: ["temurin"] - steps: - - name: Checkout - uses: actions/checkout@v3 - with: - fetch-depth: 0 - - name: Install JDK ${{ matrix.distribution }} ${{ matrix.java_version }} - uses: actions/setup-java@v3.9.0 - with: - distribution: ${{ matrix.distribution }} - java-version: ${{ matrix.java_version }} - cache: gradle - - name: Check spotless - run: ./gradlew spotlessCheck -S - buildTestOnWindows: - name: Build on Windows CI - runs-on: windows-latest - strategy: - fail-fast: false - matrix: - java_version: [11, 17] - distribution: ["temurin"] - steps: - - name: Checkout - uses: actions/checkout@v3 - - name: Install JDK ${{ matrix.distribution }} ${{ matrix.java_version }} - uses: actions/setup-java@v3.9.0 - with: - distribution: ${{ matrix.distribution }} - java-version: ${{ matrix.java_version }} - cache: gradle - - name: Build project - run: ./gradlew build -x spotlessCheck -S diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml new file mode 100644 index 0000000000..53a1f49cf6 --- /dev/null +++ b/.github/workflows/ci.yml @@ -0,0 +1,43 @@ +# BUILDCACHE_USER +# BUILDCACHE_PASS +# - rw access to buildcache.diffplug.com + +on: [push, pull_request] +jobs: + testClasses: + name: spotlessCheck assemble testClasses + runs-on: ubuntu-latest + env: + buildcacheuser: ${{ secrets.BUILDCACHE_USER }} + buildcachepass: ${{ secrets.BUILDCACHE_PASS }} + steps: + - name: Checkout + uses: actions/checkout@v3 + - name: Install JDK 11 + uses: actions/setup-java@v3 + with: + distribution: "temurin" + java-version: 11 + cache: gradle + - name: Build project + run: ./gradlew spotlessCheck assemble testClasses --build-cache + test_windows: + needs: testClasses + name: test_windows + runs-on: windows-latest + strategy: + fail-fast: false + matrix: + java_version: [17] + distribution: ["temurin"] + steps: + - name: Checkout + uses: actions/checkout@v3 + - name: Install JDK ${{ matrix.distribution }} ${{ matrix.java_version }} + uses: actions/setup-java@v3 + with: + distribution: ${{ matrix.distribution }} + java-version: ${{ matrix.java_version }} + cache: gradle + - name: Build project + run: ./gradlew test --build-cache -PSPOTLESS_EXCLUDE_MAVEN=true From b513d23dbe5839ba65ee04a05f58724f4a9cad1c Mon Sep 17 00:00:00 2001 From: Ned Twigg Date: Sat, 14 Jan 2023 16:09:21 -0800 Subject: [PATCH 546/757] Fix spotless ratchetFrom --- .github/workflows/ci.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 53a1f49cf6..1282ef2a20 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -13,6 +13,8 @@ jobs: steps: - name: Checkout uses: actions/checkout@v3 + with: + fetch-depth: 0 - name: Install JDK 11 uses: actions/setup-java@v3 with: From 8a69785b16cfccde04450a4454b2e9277d61bab5 Mon Sep 17 00:00:00 2001 From: Ned Twigg Date: Sat, 14 Jan 2023 16:26:31 -0800 Subject: [PATCH 547/757] Start running our tests also. --- .github/workflows/ci.yml | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 1282ef2a20..c6974d8de8 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -23,15 +23,13 @@ jobs: cache: gradle - name: Build project run: ./gradlew spotlessCheck assemble testClasses --build-cache - test_windows: + check: needs: testClasses - name: test_windows - runs-on: windows-latest strategy: fail-fast: false - matrix: - java_version: [17] - distribution: ["temurin"] + maven_or_gradle: [maven, gradle] + os: [ubuntu-latest, windows-latest] + jre: [11, 17] steps: - name: Checkout uses: actions/checkout@v3 @@ -41,5 +39,9 @@ jobs: distribution: ${{ matrix.distribution }} java-version: ${{ matrix.java_version }} cache: gradle - - name: Build project - run: ./gradlew test --build-cache -PSPOTLESS_EXCLUDE_MAVEN=true + - name: check maven + if: matrix.maven_or_gradle == 'maven' + run: ./gradlew :plugin-maven:check -x spotlessCheck --build-cache + - name: check everything but maven + if: matrix.maven_or_gradle == 'gradle' + run: export SPOTLESS_EXCLUDE_MAVEN=true && ./gradlew check -x spotlessCheck --build-cache From 0a120eceb177f4a3e78158a42bbc1fea66e250a3 Mon Sep 17 00:00:00 2001 From: Ned Twigg Date: Sat, 14 Jan 2023 16:28:05 -0800 Subject: [PATCH 548/757] Oops. Fix the matrix syntax. --- .github/workflows/ci.yml | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index c6974d8de8..7f0d8d5f7f 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -27,9 +27,10 @@ jobs: needs: testClasses strategy: fail-fast: false - maven_or_gradle: [maven, gradle] - os: [ubuntu-latest, windows-latest] - jre: [11, 17] + matrix: + maven_or_gradle: [maven, gradle] + os: [ubuntu-latest, windows-latest] + jre: [11, 17] steps: - name: Checkout uses: actions/checkout@v3 From 136f96d350529407e860c665fb460d83b61dd4b3 Mon Sep 17 00:00:00 2001 From: Ned Twigg Date: Sat, 14 Jan 2023 16:33:07 -0800 Subject: [PATCH 549/757] Try again. --- .github/workflows/ci.yml | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 7f0d8d5f7f..16952dca28 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -31,14 +31,15 @@ jobs: maven_or_gradle: [maven, gradle] os: [ubuntu-latest, windows-latest] jre: [11, 17] + runs-on: ${{ matrix.os }} steps: - name: Checkout uses: actions/checkout@v3 - name: Install JDK ${{ matrix.distribution }} ${{ matrix.java_version }} uses: actions/setup-java@v3 with: - distribution: ${{ matrix.distribution }} - java-version: ${{ matrix.java_version }} + distribution: "temurin" + java-version: ${{ matrix.jre }} cache: gradle - name: check maven if: matrix.maven_or_gradle == 'maven' From d0af06ef766bb8482c122749027a2f232a2e0cf0 Mon Sep 17 00:00:00 2001 From: Ned Twigg Date: Sat, 14 Jan 2023 16:43:57 -0800 Subject: [PATCH 550/757] Exclude maven from the assemble testClasses because it's not cacheable anyway. --- .github/workflows/ci.yml | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 16952dca28..3bc9de5157 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -21,8 +21,11 @@ jobs: distribution: "temurin" java-version: 11 cache: gradle - - name: Build project - run: ./gradlew spotlessCheck assemble testClasses --build-cache + - name: spotlessCheck + run: ./gradlew spotlessCheck --build-cache + - name: assemble testClasses + run: export SPOTLESS_EXCLUDE_MAVEN=true && ./gradlew assemble testClasses --build-cache + # If this gets resolved, remove the EXCLUDE_MAVEN https://github.com/diffplug/spotless/issues/554 check: needs: testClasses strategy: From 692ad62635ab05b03955dea17406157f92ebb11d Mon Sep 17 00:00:00 2001 From: Ned Twigg Date: Sat, 14 Jan 2023 16:54:41 -0800 Subject: [PATCH 551/757] Add java8 and npm tests. --- .github/workflows/ci.yml | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 3bc9de5157..b14769569b 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -24,16 +24,16 @@ jobs: - name: spotlessCheck run: ./gradlew spotlessCheck --build-cache - name: assemble testClasses - run: export SPOTLESS_EXCLUDE_MAVEN=true && ./gradlew assemble testClasses --build-cache + run: ./gradlew assemble testClasses --build-cache -PSPOTLESS_EXCLUDE_MAVEN=true # If this gets resolved, remove the EXCLUDE_MAVEN https://github.com/diffplug/spotless/issues/554 check: needs: testClasses strategy: fail-fast: false matrix: - maven_or_gradle: [maven, gradle] + kind: [maven, gradle, npm] os: [ubuntu-latest, windows-latest] - jre: [11, 17] + jre: [8, 11, 17] runs-on: ${{ matrix.os }} steps: - name: Checkout @@ -45,8 +45,11 @@ jobs: java-version: ${{ matrix.jre }} cache: gradle - name: check maven - if: matrix.maven_or_gradle == 'maven' + if: matrix.kind == 'maven' run: ./gradlew :plugin-maven:check -x spotlessCheck --build-cache - name: check everything but maven - if: matrix.maven_or_gradle == 'gradle' - run: export SPOTLESS_EXCLUDE_MAVEN=true && ./gradlew check -x spotlessCheck --build-cache + if: matrix.kind == 'gradle' + run: ./gradlew check -x spotlessCheck --build-cache -PSPOTLESS_EXCLUDE_MAVEN=true + - name: check npm + if: matrix.kind == 'npm' + run: ./gradlew testNpm --build-cache From a6c5dd48b902dcd013bed91d15f764ddd783458a Mon Sep 17 00:00:00 2001 From: Ned Twigg Date: Sat, 14 Jan 2023 16:58:38 -0800 Subject: [PATCH 552/757] Change the matrix order a bit. --- .github/workflows/ci.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index b14769569b..ac9d5be617 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -32,8 +32,8 @@ jobs: fail-fast: false matrix: kind: [maven, gradle, npm] - os: [ubuntu-latest, windows-latest] jre: [8, 11, 17] + os: [ubuntu-latest, windows-latest] runs-on: ${{ matrix.os }} steps: - name: Checkout From 35a2dc9640b358f8dd74b3807434310ef76718e5 Mon Sep 17 00:00:00 2001 From: Ned Twigg Date: Sat, 14 Jan 2023 17:01:21 -0800 Subject: [PATCH 553/757] No more double-build by building only pushes to master. --- .github/workflows/ci.yml | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index ac9d5be617..9a34e0d42d 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -2,7 +2,10 @@ # BUILDCACHE_PASS # - rw access to buildcache.diffplug.com -on: [push, pull_request] +on: + pull_request: + push: + branches: [main] jobs: testClasses: name: spotlessCheck assemble testClasses From 71d0e85724beaede77f6c1d116ea2f1e7e13a2c2 Mon Sep 17 00:00:00 2001 From: Ned Twigg Date: Sat, 14 Jan 2023 17:09:08 -0800 Subject: [PATCH 554/757] Cancel in-progress builds that aren't working for us. --- .github/workflows/ci.yml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 9a34e0d42d..ed526a16ca 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -6,6 +6,9 @@ on: pull_request: push: branches: [main] +concurrency: + group: ${{ github.workflow }}-${{ github.ref }} + cancel-in-progress: true jobs: testClasses: name: spotlessCheck assemble testClasses From d0faac2dda2c586e589f2f42e6754ebc7f789240 Mon Sep 17 00:00:00 2001 From: Ned Twigg Date: Sat, 14 Jan 2023 17:22:02 -0800 Subject: [PATCH 555/757] Switch from `check` to `build` --- .github/workflows/ci.yml | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index ed526a16ca..4ce6347755 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -10,7 +10,7 @@ concurrency: group: ${{ github.workflow }}-${{ github.ref }} cancel-in-progress: true jobs: - testClasses: + sanityCheck: name: spotlessCheck assemble testClasses runs-on: ubuntu-latest env: @@ -32,8 +32,8 @@ jobs: - name: assemble testClasses run: ./gradlew assemble testClasses --build-cache -PSPOTLESS_EXCLUDE_MAVEN=true # If this gets resolved, remove the EXCLUDE_MAVEN https://github.com/diffplug/spotless/issues/554 - check: - needs: testClasses + build: + needs: sanityCheck strategy: fail-fast: false matrix: @@ -50,12 +50,12 @@ jobs: distribution: "temurin" java-version: ${{ matrix.jre }} cache: gradle - - name: check maven + - name: build (maven-only) if: matrix.kind == 'maven' - run: ./gradlew :plugin-maven:check -x spotlessCheck --build-cache - - name: check everything but maven + run: ./gradlew :plugin-maven:build -x spotlessCheck --build-cache + - name: build (everything-but-maven) if: matrix.kind == 'gradle' - run: ./gradlew check -x spotlessCheck --build-cache -PSPOTLESS_EXCLUDE_MAVEN=true - - name: check npm + run: ./gradlew build -x spotlessCheck --build-cache -PSPOTLESS_EXCLUDE_MAVEN=true + - name: testNpm if: matrix.kind == 'npm' run: ./gradlew testNpm --build-cache From 707719668fc04fbcd626c725cd35cb4e87fb4745 Mon Sep 17 00:00:00 2001 From: Ned Twigg Date: Sat, 14 Jan 2023 17:26:41 -0800 Subject: [PATCH 556/757] Revert "Update dependency org.mockito:mockito-core to v5" (#1487) b/c it breaks Java 8 --- gradle.properties | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gradle.properties b/gradle.properties index 23ec1efd7a..71f755522f 100644 --- a/gradle.properties +++ b/gradle.properties @@ -28,7 +28,7 @@ VER_DURIAN=1.2.0 VER_JGIT=5.13.1.202206130422-r VER_JUNIT=5.9.2 VER_ASSERTJ=3.24.1 -VER_MOCKITO=5.0.0 +VER_MOCKITO=4.11.0 # Used for Maven Plugin VER_MAVEN_API=3.0 From 549558e05f661aab8ea2f2bf361f7a18af52ce51 Mon Sep 17 00:00:00 2001 From: Ned Twigg Date: Sat, 14 Jan 2023 17:50:06 -0800 Subject: [PATCH 557/757] Grab JUnit reports. --- .github/workflows/ci.yml | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 4ce6347755..63fc565b4a 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -56,6 +56,12 @@ jobs: - name: build (everything-but-maven) if: matrix.kind == 'gradle' run: ./gradlew build -x spotlessCheck --build-cache -PSPOTLESS_EXCLUDE_MAVEN=true - - name: testNpm + - name: test npm if: matrix.kind == 'npm' run: ./gradlew testNpm --build-cache + - name: junit result + uses: mikepenz/action-junit-report@v3 + if: always() # always run even if the previous step fails + with: + check_name: JUnit ${{ matrix.kind }} ${{ matrix.jre }} ${{ matrix.os }} + report_paths: '*/build/test-results/*/TEST-*.xml' From 9cae4966b8b30c976c330c201d64ee6b453227d6 Mon Sep 17 00:00:00 2001 From: Ned Twigg Date: Sat, 14 Jan 2023 18:05:36 -0800 Subject: [PATCH 558/757] Be more efficient with runner minutes. --- .github/workflows/ci.yml | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 63fc565b4a..2e302e6637 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -37,9 +37,21 @@ jobs: strategy: fail-fast: false matrix: - kind: [maven, gradle, npm] + kind: [maven, gradle] jre: [8, 11, 17] - os: [ubuntu-latest, windows-latest] + os: [ubuntu-latest] + include: + # test windows at the diagonals of the above matrix + - kind: maven + jre: 8 + os: windows-latest + - kind: gradle + jre: 17 + os: windows-latest + # npm on linux only (crazy slow on windows) + - kind: npm + jre: 8 + os: ubuntu-latest runs-on: ${{ matrix.os }} steps: - name: Checkout From 6b67bf17b0d7b1887b0df1a3fb6d656b487ba9e8 Mon Sep 17 00:00:00 2001 From: Ned Twigg Date: Sat, 14 Jan 2023 18:06:39 -0800 Subject: [PATCH 559/757] Fully remove CircleCI. --- .circleci/config.yml | 161 ------------------------------------------- 1 file changed, 161 deletions(-) delete mode 100644 .circleci/config.yml diff --git a/.circleci/config.yml b/.circleci/config.yml deleted file mode 100644 index b9f91766c9..0000000000 --- a/.circleci/config.yml +++ /dev/null @@ -1,161 +0,0 @@ -version: 2.1 -orbs: - win: circleci/windows@5.0.0 - -anchors: - env_gradle: &env_gradle - environment: - # we're only allowed to use 2 vCPUs - GRADLE_OPTS: "-Dorg.gradle.workers.max=2" - docker: - - image: cimg/openjdk:11.0 - env_gradle_large: &env_gradle_large - << : *env_gradle - resource_class: large # https://circleci.com/docs/2.0/configuration-reference/#resource_class - environment: - GRADLE_OPTS: "-Dorg.gradle.workers.max=4" - - restore_cache_wrapper: &restore_cache_wrapper - restore_cache: - key: gradle-wrapper2-{{ checksum "gradle/wrapper/gradle-wrapper.properties" }} - restore_cache_deps: &restore_cache_deps - restore_cache: - keys: - - gradle-deps3-{{ checksum "build.gradle" }}-{{ checksum "gradle.properties" }} - - gradle-deps3- - set_git_origin_to_https: &set_git_origin_to_https - run: - name: set git origin to https - command: git remote set-url --push origin https://github.com/diffplug/spotless - - test_nomaven: &test_nomaven - steps: - - checkout - - *restore_cache_wrapper - - *restore_cache_deps - - run: - name: gradlew check -x spotlessCheck - command: export SPOTLESS_EXCLUDE_MAVEN=true && ./gradlew check -x spotlessCheck --build-cache - - store_test_results: - path: testlib/build/test-results/test - - store_test_results: - path: lib-extra/build/test-results/test - - store_test_results: - path: plugin-gradle/build/test-results/test - - store_artifacts: - path: lib/build/spotbugs - - store_artifacts: - path: lib-extra/build/spotbugs - - store_artifacts: - path: testlib/build/spotbugs - - store_artifacts: - path: plugin-gradle/build/spotbugs - -jobs: - # gradlew spotlessCheck assemble testClasses - assemble_testClasses: - <<: *env_gradle_large - steps: - - checkout - - *restore_cache_wrapper - - *restore_cache_deps - - run: - name: gradlew spotlessCheck assemble testClasses - command: ./gradlew spotlessCheck assemble testClasses --build-cache - - save_cache: - paths: - - ~/.gradle/wrapper - key: gradle-wrapper2-{{ checksum "gradle/wrapper/gradle-wrapper.properties" }} - - save_cache: - paths: - - ~/.gradle/caches - - ~/.m2 - key: gradle-deps3-{{ checksum "build.gradle" }}-{{ checksum "gradle.properties" }} - test_nomaven_11: - # latest LTS version - <<: *env_gradle_large - docker: - - image: cimg/openjdk:11.0 - <<: *test_nomaven - test_nomaven_17: - # latest JDK - <<: *env_gradle_large - docker: - - image: cimg/openjdk:17.0 - <<: *test_nomaven - test_justmaven_11: - << : *env_gradle - steps: - - checkout - - *restore_cache_wrapper - - *restore_cache_deps - - run: - name: gradlew :plugin-maven:check - command: ./gradlew :plugin-maven:check --build-cache - - store_test_results: - path: plugin-maven/build/test-results/test - test_npm_8: - << : *env_gradle - environment: - # java doesn't play nice with containers, it tries to hog the entire machine - # https://circleci.com/blog/how-to-handle-java-oom-errors/ - # try the experimental JVM option - _JAVA_OPTIONS: "-XX:+UnlockExperimentalVMOptions -XX:+UseCGroupMemoryLimitForHeap" - docker: - - image: cimg/openjdk:8.0-node - steps: - - checkout - - *restore_cache_wrapper - - *restore_cache_deps - - run: - name: gradlew testNpm - command: export SPOTLESS_EXCLUDE_MAVEN=true && ./gradlew testNpm --build-cache - - store_test_results: - path: testlib/build/test-results/testNpm - - store_test_results: - path: plugin-maven/build/test-results/testNpm - - store_test_results: - path: plugin-gradle/build/test-results/testNpm - - run: - name: gradlew test - command: export SPOTLESS_EXCLUDE_MAVEN=true && ./gradlew test --build-cache - - store_test_results: - path: testlib/build/test-results/test - - store_test_results: - path: lib-extra/build/test-results/test - - store_test_results: - path: plugin-gradle/build/test-results/test - test_windows: - executor: - name: win/default - shell: cmd.exe - steps: - - checkout - - run: - name: gradlew test - command: gradlew test --build-cache -PSPOTLESS_EXCLUDE_MAVEN=true - - store_test_results: - path: testlib/build/test-results/test - - store_test_results: - path: lib-extra/build/test-results/test - - store_test_results: - path: plugin-gradle/build/test-results/test - -workflows: - version: 2 - assemble_and_test: - jobs: - - test_windows - - assemble_testClasses - - test_justmaven_11: - requires: - - assemble_testClasses - - test_nomaven_11: - requires: - - assemble_testClasses - - test_nomaven_17: - requires: - - assemble_testClasses - - test_npm_8: - requires: - - assemble_testClasses From c238f0c672a7d0a5702818b3ac90000ed3f654e0 Mon Sep 17 00:00:00 2001 From: "renovate[bot]" <29139614+renovate[bot]@users.noreply.github.com> Date: Sun, 15 Jan 2023 02:09:45 +0000 Subject: [PATCH 560/757] Update plugin com.diffplug.spotless to v6.13.0 --- settings.gradle | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/settings.gradle b/settings.gradle index 741e4b6ccc..57498bf23f 100644 --- a/settings.gradle +++ b/settings.gradle @@ -1,6 +1,6 @@ pluginManagement { plugins { - id 'com.diffplug.spotless' version '6.12.1' + id 'com.diffplug.spotless' version '6.13.0' // https://plugins.gradle.org/plugin/com.gradle.plugin-publish id 'com.gradle.plugin-publish' version '1.1.0' // https://github.com/gradle-nexus/publish-plugin/releases From 33cafc069ed8b5c5fc6258458ebcf0084639cc16 Mon Sep 17 00:00:00 2001 From: tison Date: Sun, 15 Jan 2023 17:20:23 +0800 Subject: [PATCH 561/757] docs: Correct espace syntax Maven XML can interpret `\#` correctly, `\\#` will mismatch code internal. --- plugin-maven/README.md | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/plugin-maven/README.md b/plugin-maven/README.md index 4232f76e39..2a455dfe07 100644 --- a/plugin-maven/README.md +++ b/plugin-maven/README.md @@ -197,8 +197,8 @@ any other maven phase (i.e. compile) then it can be configured as below; false - java|javax,org,com,com.diffplug,,\\#com.diffplug,\\# - + java|javax,org,com,com.diffplug,,\#com.diffplug,\# + @@ -298,8 +298,8 @@ These mechanisms already exist for the Gradle plugin. - java|javax,org,com,com.diffplug,,\\#com.diffplug,\\# - + java|javax,org,com,com.diffplug,,\#com.diffplug,\# + From eae8ffc0fc20997bda6e540b4da448bf00a0d8d7 Mon Sep 17 00:00:00 2001 From: Benoit Lacelle Date: Sun, 15 Jan 2023 16:52:19 +0400 Subject: [PATCH 562/757] Add JSON jackson step, Refactor with Yaml, enable endWithEol, features are defined in a Map -> boolean --- lib/build.gradle | 1 + .../glue/json/JsonJacksonFormatterFunc.java | 103 ++++++++++++++++++ .../glue/yaml/YamlJacksonFormatterFunc.java | 77 ++----------- .../diffplug/spotless/json/JacksonConfig.java | 71 ++++++++++++ .../spotless/json/JacksonJsonStep.java | 79 ++++++++++++++ ...lJacksonStep.java => JacksonYamlStep.java} | 31 +++--- .../Jackson.java => json/JacksonJson.java} | 34 ++++-- .../diffplug/spotless/maven/json/Json.java | 4 + .../spotless/maven/yaml/JacksonYaml.java | 60 ++++++++++ .../diffplug/spotless/maven/yaml/Yaml.java | 2 +- .../spotless/maven/json/JsonTest.java | 23 +++- .../spotless/maven/yaml/YamlTest.java | 9 ++ .../json/sortByKeysAfter_Jackson.json | 19 ++++ ...fter_Jackson_noSpaceAfterKeySeparator.json | 19 ++++ .../array_with_bracket.clean_with_eol.yaml | 12 ++ 15 files changed, 441 insertions(+), 103 deletions(-) create mode 100644 lib/src/jackson/java/com/diffplug/spotless/glue/json/JsonJacksonFormatterFunc.java create mode 100644 lib/src/main/java/com/diffplug/spotless/json/JacksonConfig.java create mode 100644 lib/src/main/java/com/diffplug/spotless/json/JacksonJsonStep.java rename lib/src/main/java/com/diffplug/spotless/yaml/{YamlJacksonStep.java => JacksonYamlStep.java} (70%) rename plugin-maven/src/main/java/com/diffplug/spotless/maven/{yaml/Jackson.java => json/JacksonJson.java} (51%) create mode 100644 plugin-maven/src/main/java/com/diffplug/spotless/maven/yaml/JacksonYaml.java create mode 100644 testlib/src/main/resources/json/sortByKeysAfter_Jackson.json create mode 100644 testlib/src/main/resources/json/sortByKeysAfter_Jackson_noSpaceAfterKeySeparator.json create mode 100644 testlib/src/main/resources/yaml/array_with_bracket.clean_with_eol.yaml diff --git a/lib/build.gradle b/lib/build.gradle index 3ef2064765..3c36aa0188 100644 --- a/lib/build.gradle +++ b/lib/build.gradle @@ -57,6 +57,7 @@ dependencies { palantirJavaFormatCompileOnly 'com.palantir.javaformat:palantir-java-format:1.1.0' // this version needs to stay compilable against Java 8 for CI Job testNpm // used jackson-based formatters + jacksonCompileOnly 'com.fasterxml.jackson.core:jackson-databind:2.14.1' jacksonCompileOnly 'com.fasterxml.jackson.dataformat:jackson-dataformat-yaml:2.14.1' String VER_KTFMT = '0.42' diff --git a/lib/src/jackson/java/com/diffplug/spotless/glue/json/JsonJacksonFormatterFunc.java b/lib/src/jackson/java/com/diffplug/spotless/glue/json/JsonJacksonFormatterFunc.java new file mode 100644 index 0000000000..0a13ab6626 --- /dev/null +++ b/lib/src/jackson/java/com/diffplug/spotless/glue/json/JsonJacksonFormatterFunc.java @@ -0,0 +1,103 @@ +/* + * Copyright 2021-2023 DiffPlug + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.diffplug.spotless.glue.json; + +import java.io.IOException; + +import com.fasterxml.jackson.core.JsonFactory; +import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.databind.ObjectMapper; +import com.fasterxml.jackson.databind.SerializationFeature; +import com.fasterxml.jackson.databind.node.ObjectNode; + +import com.diffplug.spotless.FormatterFunc; +import com.diffplug.spotless.json.JacksonConfig; + +/** + * A {@link FormatterFunc} based on Jackson library + */ +// https://github.com/FasterXML/jackson-dataformats-text/issues/372 +public class JsonJacksonFormatterFunc implements FormatterFunc { + private JacksonConfig jacksonConfig; + + public JsonJacksonFormatterFunc(JacksonConfig jacksonConfig) { + this.jacksonConfig = jacksonConfig; + } + + @Override + public String apply(String input) throws Exception { + ObjectMapper objectMapper = makeObjectMapper(); + + return format(objectMapper, input); + } + + /** + * @return a {@link JsonFactory}. May be overridden to handle alternative formats. + * @see jackson-dataformats-text + */ + protected JsonFactory makeJsonFactory() { + return new JsonFactory(); + } + + protected ObjectMapper makeObjectMapper() { + JsonFactory jsonFactory = makeJsonFactory(); + ObjectMapper objectMapper = new ObjectMapper(jsonFactory); + + // Configure the ObjectMapper + // https://github.com/FasterXML/jackson-databind#commonly-used-features + jacksonConfig.getFeatureToToggle().forEach((rawFeature, toggle) -> { + // https://stackoverflow.com/questions/3735927/java-instantiating-an-enum-using-reflection + SerializationFeature feature = SerializationFeature.valueOf(rawFeature); + + objectMapper.configure(feature, toggle); + }); + + return objectMapper; + } + + protected String format(ObjectMapper objectMapper, String input) throws IllegalArgumentException, IOException { + // We may consider adding manually an initial '---' prefix to help management of multiple documents + // if (!input.trim().startsWith("---")) { + // input = "---" + "\n" + input; + // } + + try { + // https://stackoverflow.com/questions/25222327/deserialize-pojos-from-multiple-yaml-documents-in-a-single-file-in-jackson + // https://github.com/FasterXML/jackson-dataformats-text/issues/66#issuecomment-375328648 + // 2023-01: For now, we get 'Cannot deserialize value of type `com.fasterxml.jackson.databind.node.ObjectNode` from Array value' + // JsonParser yamlParser = objectMapper.getFactory().createParser(input); + // List docs = objectMapper.readValues(yamlParser, ObjectNode.class).readAll(); + // return objectMapper.writeValueAsString(docs); + + // 2023-01: This returns JSON instead of YAML + // This will transit with a JsonNode + // A JsonNode may keep the comments from the input node + // JsonNode jsonNode = objectMapper.readTree(input); + //Not 'toPrettyString' as one could require no INDENT_OUTPUT + // return jsonNode.toPrettyString(); + ObjectNode objectNode = objectMapper.readValue(input, ObjectNode.class); + String outputFromjackson = objectMapper.writeValueAsString(objectNode); + + if (jacksonConfig.isEndWithEol() && !outputFromjackson.endsWith("\n")) { + outputFromjackson += "\n"; + } + + return outputFromjackson; + } catch (JsonProcessingException e) { + throw new AssertionError("Unable to format. input='" + input + "'", e); + } + } +} diff --git a/lib/src/jackson/java/com/diffplug/spotless/glue/yaml/YamlJacksonFormatterFunc.java b/lib/src/jackson/java/com/diffplug/spotless/glue/yaml/YamlJacksonFormatterFunc.java index 30cf538159..eda2675985 100644 --- a/lib/src/jackson/java/com/diffplug/spotless/glue/yaml/YamlJacksonFormatterFunc.java +++ b/lib/src/jackson/java/com/diffplug/spotless/glue/yaml/YamlJacksonFormatterFunc.java @@ -15,83 +15,20 @@ */ package com.diffplug.spotless.glue.yaml; -import java.io.IOException; -import java.util.List; +import com.diffplug.spotless.glue.json.JsonJacksonFormatterFunc; -import com.fasterxml.jackson.core.JsonProcessingException; -import com.fasterxml.jackson.core.type.TypeReference; -import com.fasterxml.jackson.databind.ObjectMapper; -import com.fasterxml.jackson.databind.SerializationFeature; -import com.fasterxml.jackson.databind.node.ObjectNode; import com.fasterxml.jackson.dataformat.yaml.YAMLFactory; -import com.diffplug.spotless.FormatterFunc; +import com.diffplug.spotless.json.JacksonConfig; -public class YamlJacksonFormatterFunc implements FormatterFunc { - private List enabledFeatures; - private List disabledFeatures; +public class YamlJacksonFormatterFunc extends JsonJacksonFormatterFunc { - public YamlJacksonFormatterFunc(List enabledFeatures, List disabledFeatures) { - this.enabledFeatures = enabledFeatures; - this.disabledFeatures = disabledFeatures; + public YamlJacksonFormatterFunc(JacksonConfig jacksonConfig) { + super(jacksonConfig); } @Override - public String apply(String input) throws Exception { - ObjectMapper objectMapper = makeObjectMapper(); - - return format(objectMapper, input); - } - - protected ObjectMapper makeObjectMapper() { - YAMLFactory yamlFactory = new YAMLFactory(); - ObjectMapper objectMapper = new ObjectMapper(yamlFactory); - - // Configure the ObjectMapper - // https://github.com/FasterXML/jackson-databind#commonly-used-features - for (String rawFeature : enabledFeatures) { - // https://stackoverflow.com/questions/3735927/java-instantiating-an-enum-using-reflection - SerializationFeature feature = SerializationFeature.valueOf(rawFeature); - - objectMapper.enable(feature); - } - - for (String rawFeature : disabledFeatures) { - // https://stackoverflow.com/questions/3735927/java-instantiating-an-enum-using-reflection - SerializationFeature feature = SerializationFeature.valueOf(rawFeature); - - objectMapper.disable(feature); - } - return objectMapper; - } - - protected String format(ObjectMapper objectMapper, String input) throws IllegalArgumentException, IOException { - // We may consider adding manually an initial '---' prefix to help management of multiple documents - // if (!input.trim().startsWith("---")) { - // input = "---" + "\n" + input; - // } - - try { - // https://stackoverflow.com/questions/25222327/deserialize-pojos-from-multiple-yaml-documents-in-a-single-file-in-jackson - // https://github.com/FasterXML/jackson-dataformats-text/issues/66#issuecomment-375328648 - // 2023-01: For now, we get 'Cannot deserialize value of type `com.fasterxml.jackson.databind.node.ObjectNode` from Array value' - // JsonParser yamlParser = objectMapper.getFactory().createParser(input); - // List docs = objectMapper.readValues(yamlParser, ObjectNode.class).readAll(); - // return objectMapper.writeValueAsString(docs); - - // 2023-01: This returns JSON instead of YAML - // This will transit with a JsonNode - // A JsonNode may keep the comments from the input node - // JsonNode jsonNode = objectMapper.readTree(input); - //Not 'toPrettyString' as one could require no INDENT_OUTPUT - // return jsonNode.toPrettyString(); - ObjectNode objectNode = objectMapper.readValue(input, ObjectNode.class); - return objectMapper.writeValueAsString(objectNode); - } catch (JsonProcessingException e) { - throw new AssertionError("Unable to format YAML. input='" + input + "'", e); - } + protected YAMLFactory makeJsonFactory() { + return new YAMLFactory(); } - - // Spotbugs - private static class ObjectNodeTypeReference extends TypeReference {} } diff --git a/lib/src/main/java/com/diffplug/spotless/json/JacksonConfig.java b/lib/src/main/java/com/diffplug/spotless/json/JacksonConfig.java new file mode 100644 index 0000000000..526e235eb7 --- /dev/null +++ b/lib/src/main/java/com/diffplug/spotless/json/JacksonConfig.java @@ -0,0 +1,71 @@ +/* + * Copyright 2023 DiffPlug + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.diffplug.spotless.json; + +import java.util.Collections; +import java.util.LinkedHashMap; +import java.util.Map; + +/** + * A DTO holding the options for Jackson-based formatters + */ +public class JacksonConfig { + + private static final Map DEFAULT_FEATURE_TOGGLES; + + static { + Map defaultFeatureToggles = new LinkedHashMap<>(); + // We activate by default the PrettyPrinter from Jackson + defaultFeatureToggles.put("INDENT_OUTPUT", true); + DEFAULT_FEATURE_TOGGLES = defaultFeatureToggles; + } + + protected Map featureToToggle; + + // https://github.com/revelc/formatter-maven-plugin/pull/405 + protected boolean endWithEol = false; + + // https://github.com/revelc/formatter-maven-plugin/pull/280 + protected boolean spaceBeforeSeparator = false; + + public Map getFeatureToToggle() { + return Collections.unmodifiableMap(featureToToggle); + } + + public void setFeatureToToggle(Map featureToToggle) { + this.featureToToggle = featureToToggle; + } + + public void appendFeatureToToggle(Map features) { + this.featureToToggle.putAll(features); + } + + public boolean isEndWithEol() { + return endWithEol; + } + + public void setEndWithEol(boolean endWithEol) { + this.endWithEol = endWithEol; + } + + public boolean isSpaceBeforeSeparator() { + return spaceBeforeSeparator; + } + + public void setSpaceBeforeSeparator(boolean spaceBeforeSeparator) { + this.spaceBeforeSeparator = spaceBeforeSeparator; + } +} diff --git a/lib/src/main/java/com/diffplug/spotless/json/JacksonJsonStep.java b/lib/src/main/java/com/diffplug/spotless/json/JacksonJsonStep.java new file mode 100644 index 0000000000..0fe1ab057b --- /dev/null +++ b/lib/src/main/java/com/diffplug/spotless/json/JacksonJsonStep.java @@ -0,0 +1,79 @@ +/* + * Copyright 2021-2023 DiffPlug + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.diffplug.spotless.json; + +import java.io.IOException; +import java.io.Serializable; +import java.lang.reflect.Constructor; +import java.lang.reflect.InvocationTargetException; +import java.util.Objects; + +import com.diffplug.spotless.FormatterFunc; +import com.diffplug.spotless.FormatterStep; +import com.diffplug.spotless.JarState; +import com.diffplug.spotless.Provisioner; + +/** + * Simple YAML formatter which reformats the file according to Jackson YAMLFactory. + */ +// https://stackoverflow.com/questions/14515994/convert-json-string-to-pretty-print-json-output-using-jackson +public class JacksonJsonStep { + static final String MAVEN_COORDINATE = "com.fasterxml.jackson.core:jackson-databind:"; + // https://mvnrepository.com/artifact/com.fasterxml.jackson.core/jackson-databind + static final String DEFAULT_VERSION = "2.14.1"; + + private JacksonJsonStep() {} + + public static String defaultVersion() { + return DEFAULT_VERSION; + } + + public static FormatterStep create(JacksonConfig jacksonConfig, + String jacksonVersion, + Provisioner provisioner) { + Objects.requireNonNull(provisioner, "provisioner cannot be null"); + return FormatterStep.createLazy("json", + () -> new State(jacksonConfig, jacksonVersion, provisioner), + State::toFormatter); + } + + public static FormatterStep create(Provisioner provisioner) { + return create(new JacksonConfig(), defaultVersion(), provisioner); + } + + private static final class State implements Serializable { + private static final long serialVersionUID = 1L; + + private final JacksonConfig jacksonConfig; + + private final JarState jarState; + + private State(JacksonConfig jacksonConfig, + String jacksonVersion, + Provisioner provisioner) throws IOException { + this.jacksonConfig = jacksonConfig; + + this.jarState = JarState.from(JacksonJsonStep.MAVEN_COORDINATE + jacksonVersion, provisioner); + } + + FormatterFunc toFormatter() throws ClassNotFoundException, NoSuchMethodException, InvocationTargetException, + InstantiationException, IllegalAccessException { + Class formatterFunc = jarState.getClassLoader().loadClass("com.diffplug.spotless.glue.json.JacksonJsonFormatterFunc"); + Constructor constructor = formatterFunc.getConstructor(JacksonConfig.class); + return (FormatterFunc) constructor.newInstance(jacksonConfig); + } + } +} diff --git a/lib/src/main/java/com/diffplug/spotless/yaml/YamlJacksonStep.java b/lib/src/main/java/com/diffplug/spotless/yaml/JacksonYamlStep.java similarity index 70% rename from lib/src/main/java/com/diffplug/spotless/yaml/YamlJacksonStep.java rename to lib/src/main/java/com/diffplug/spotless/yaml/JacksonYamlStep.java index db2525ab97..944d90e6c9 100644 --- a/lib/src/main/java/com/diffplug/spotless/yaml/YamlJacksonStep.java +++ b/lib/src/main/java/com/diffplug/spotless/yaml/JacksonYamlStep.java @@ -19,67 +19,62 @@ import java.io.Serializable; import java.lang.reflect.Constructor; import java.lang.reflect.InvocationTargetException; -import java.util.Arrays; -import java.util.List; import java.util.Objects; import com.diffplug.spotless.FormatterFunc; import com.diffplug.spotless.FormatterStep; import com.diffplug.spotless.JarState; import com.diffplug.spotless.Provisioner; +import com.diffplug.spotless.json.JacksonConfig; /** * Simple YAML formatter which reformats the file according to Jackson YAMLFactory. */ // https://stackoverflow.com/questions/14515994/convert-json-string-to-pretty-print-json-output-using-jackson -public class YamlJacksonStep { +public class JacksonYamlStep { static final String MAVEN_COORDINATE = "com.fasterxml.jackson.dataformat:jackson-dataformat-yaml:"; // https://mvnrepository.com/artifact/com.fasterxml.jackson.dataformat/jackson-dataformat-yaml static final String DEFAULT_VERSION = "2.14.1"; - private YamlJacksonStep() {} + private JacksonYamlStep() {} public static String defaultVersion() { return DEFAULT_VERSION; } - public static FormatterStep create(List enabledFeatures, - List disabledFeatures, + public static FormatterStep create(JacksonConfig jacksonConfig, String jacksonVersion, Provisioner provisioner) { Objects.requireNonNull(provisioner, "provisioner cannot be null"); return FormatterStep.createLazy("yaml", - () -> new State(enabledFeatures, disabledFeatures, jacksonVersion, provisioner), + () -> new State(jacksonConfig, jacksonVersion, provisioner), State::toFormatter); } public static FormatterStep create(Provisioner provisioner) { - return create(Arrays.asList("INDENT_OUTPUT"), Arrays.asList(), defaultVersion(), provisioner); + return create(new JacksonConfig(), defaultVersion(), provisioner); } private static final class State implements Serializable { private static final long serialVersionUID = 1L; - private final List enabledFeatures; - private final List disabledFeatures; + private final JacksonConfig jacksonConfig; private final JarState jarState; - private State(List enabledFeatures, - List disabledFeatures, + private State(JacksonConfig jacksonConfig, String jacksonVersion, Provisioner provisioner) throws IOException { - this.enabledFeatures = enabledFeatures; - this.disabledFeatures = disabledFeatures; + this.jacksonConfig = jacksonConfig; - this.jarState = JarState.from(YamlJacksonStep.MAVEN_COORDINATE + jacksonVersion, provisioner); + this.jarState = JarState.from(JacksonYamlStep.MAVEN_COORDINATE + jacksonVersion, provisioner); } FormatterFunc toFormatter() throws ClassNotFoundException, NoSuchMethodException, InvocationTargetException, InstantiationException, IllegalAccessException { - Class formatterFunc = jarState.getClassLoader().loadClass("com.diffplug.spotless.glue.yaml.YamlJacksonFormatterFunc"); - Constructor constructor = formatterFunc.getConstructor(List.class, List.class); - return (FormatterFunc) constructor.newInstance(enabledFeatures, disabledFeatures); + Class formatterFunc = jarState.getClassLoader().loadClass("com.diffplug.spotless.glue.yaml.JacksonYamlFormatterFunc"); + Constructor constructor = formatterFunc.getConstructor(JacksonConfig.class); + return (FormatterFunc) constructor.newInstance(jacksonConfig); } } } diff --git a/plugin-maven/src/main/java/com/diffplug/spotless/maven/yaml/Jackson.java b/plugin-maven/src/main/java/com/diffplug/spotless/maven/json/JacksonJson.java similarity index 51% rename from plugin-maven/src/main/java/com/diffplug/spotless/maven/yaml/Jackson.java rename to plugin-maven/src/main/java/com/diffplug/spotless/maven/json/JacksonJson.java index 2bc7617a38..cf03ef21ca 100644 --- a/plugin-maven/src/main/java/com/diffplug/spotless/maven/yaml/Jackson.java +++ b/plugin-maven/src/main/java/com/diffplug/spotless/maven/json/JacksonJson.java @@ -13,34 +13,44 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package com.diffplug.spotless.maven.yaml; +package com.diffplug.spotless.maven.json; -import java.util.Arrays; -import java.util.List; +import java.util.Collections; +import java.util.Map; import org.apache.maven.plugins.annotations.Parameter; import com.diffplug.spotless.FormatterStep; +import com.diffplug.spotless.json.JacksonConfig; +import com.diffplug.spotless.json.JacksonJsonStep; +import com.diffplug.spotless.maven.FormatterFactory; import com.diffplug.spotless.maven.FormatterStepConfig; import com.diffplug.spotless.maven.FormatterStepFactory; -import com.diffplug.spotless.yaml.YamlJacksonStep; -public class Jackson implements FormatterStepFactory { +/** + * A {@link FormatterFactory} implementation that corresponds to {@code ...} configuration element. + */ +public class JacksonJson implements FormatterStepFactory { @Parameter - private String version = YamlJacksonStep.defaultVersion(); + String version = JacksonJsonStep.defaultVersion(); @Parameter - private String[] enabledFeatures = new String[]{"INDENT_OUTPUT"}; + boolean endWithEol = new JacksonConfig().isEndWithEol(); @Parameter - private String[] disabledFeatures = new String[0]; + private Map features = Collections.emptyMap(); @Override public FormatterStep newFormatterStep(FormatterStepConfig stepConfig) { - List enabledFeaturesAsList = Arrays.asList(enabledFeatures); - List disabledFeaturesAsList = Arrays.asList(disabledFeatures); - return YamlJacksonStep - .create(enabledFeaturesAsList, disabledFeaturesAsList, version, stepConfig.getProvisioner()); + JacksonConfig jacksonConfig = new JacksonConfig(); + + if (features != null) { + jacksonConfig.appendFeatureToToggle(features); + } + jacksonConfig.setEndWithEol(endWithEol); + + return JacksonJsonStep + .create(jacksonConfig, version, stepConfig.getProvisioner()); } } diff --git a/plugin-maven/src/main/java/com/diffplug/spotless/maven/json/Json.java b/plugin-maven/src/main/java/com/diffplug/spotless/maven/json/Json.java index c326525d0c..852088278a 100644 --- a/plugin-maven/src/main/java/com/diffplug/spotless/maven/json/Json.java +++ b/plugin-maven/src/main/java/com/diffplug/spotless/maven/json/Json.java @@ -44,4 +44,8 @@ public void addGson(Gson gson) { addStepFactory(gson); } + public void addJackson(JacksonJson jackson) { + addStepFactory(jackson); + } + } diff --git a/plugin-maven/src/main/java/com/diffplug/spotless/maven/yaml/JacksonYaml.java b/plugin-maven/src/main/java/com/diffplug/spotless/maven/yaml/JacksonYaml.java new file mode 100644 index 0000000000..d3d9558cf4 --- /dev/null +++ b/plugin-maven/src/main/java/com/diffplug/spotless/maven/yaml/JacksonYaml.java @@ -0,0 +1,60 @@ +/* + * Copyright 2023 DiffPlug + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.diffplug.spotless.maven.yaml; + +import java.util.Collections; +import java.util.Map; + +import com.diffplug.spotless.maven.FormatterFactory; + +import org.apache.maven.plugins.annotations.Parameter; + +import com.diffplug.spotless.FormatterStep; +import com.diffplug.spotless.json.JacksonConfig; +import com.diffplug.spotless.maven.FormatterStepConfig; +import com.diffplug.spotless.maven.FormatterStepFactory; +import com.diffplug.spotless.yaml.JacksonYamlStep; + +/** + * A {@link FormatterFactory} implementation that corresponds to {@code ...} configuration element. + */ +public class JacksonYaml implements FormatterStepFactory { + + @Parameter + private String version = JacksonYamlStep.defaultVersion(); + + @Parameter + boolean endWithEol = new JacksonConfig().isEndWithEol(); + + @Parameter + boolean spaceBeforeSeparator = new JacksonConfig().isSpaceBeforeSeparator(); + + @Parameter + private Map features = Collections.emptyMap(); + + @Override + public FormatterStep newFormatterStep(FormatterStepConfig stepConfig) { + JacksonConfig jacksonConfig = new JacksonConfig(); + + if (features != null) { + jacksonConfig.appendFeatureToToggle(features); + } + jacksonConfig.setEndWithEol(endWithEol); + + return JacksonYamlStep + .create(jacksonConfig, version, stepConfig.getProvisioner()); + } +} diff --git a/plugin-maven/src/main/java/com/diffplug/spotless/maven/yaml/Yaml.java b/plugin-maven/src/main/java/com/diffplug/spotless/maven/yaml/Yaml.java index 6cba1b2ebd..a6ceaaa592 100644 --- a/plugin-maven/src/main/java/com/diffplug/spotless/maven/yaml/Yaml.java +++ b/plugin-maven/src/main/java/com/diffplug/spotless/maven/yaml/Yaml.java @@ -34,7 +34,7 @@ public String licenseHeaderDelimiter() { return null; } - public void addJackson(Jackson jackson) { + public void addJackson(JacksonYaml jackson) { addStepFactory(jackson); } diff --git a/plugin-maven/src/test/java/com/diffplug/spotless/maven/json/JsonTest.java b/plugin-maven/src/test/java/com/diffplug/spotless/maven/json/JsonTest.java index e492109faa..90b3a2f077 100644 --- a/plugin-maven/src/test/java/com/diffplug/spotless/maven/json/JsonTest.java +++ b/plugin-maven/src/test/java/com/diffplug/spotless/maven/json/JsonTest.java @@ -58,8 +58,6 @@ public void testFormatJson_WithGson_sortByKeys() throws Exception { setFile("json_test.json").toResource("json/sortByKeysBefore.json"); String output = mavenRunner().withArguments("spotless:apply").runNoError().output(); - LOGGER.error(output); - System.err.println(output); assertFile("json_test.json").sameAsResource("json/sortByKeysAfter.json"); } @@ -72,4 +70,25 @@ public void testFormatJson_WithGson_defaultConfig_nestedObject() throws Exceptio assertFile("json_test.json").sameAsResource("json/nestedObjectAfter.json"); } + + @Test + public void testFormatJson_WithJackson_sortByKeys() throws Exception { + writePomWithJsonSteps("true"); + + setFile("json_test.json").toResource("json/sortByKeysBefore.json"); + + String output = mavenRunner().withArguments("spotless:apply").runNoError().output(); + assertFile("json_test.json").sameAsResource("json/sortByKeysAfter.json"); + } + + @Test + public void testFormatJson_WithJackson_sortByKeys_noSpaceAfterKeySeparator() throws Exception { + writePomWithJsonSteps("falsetrue"); + + setFile("json_test.json").toResource("json/sortByKeysBefore.json"); + + String output = mavenRunner().withArguments("spotless:apply").runNoError().output(); + assertFile("json_test.json").sameAsResource("json/sortByKeysAfter.json"); + } + } diff --git a/plugin-maven/src/test/java/com/diffplug/spotless/maven/yaml/YamlTest.java b/plugin-maven/src/test/java/com/diffplug/spotless/maven/yaml/YamlTest.java index b5a417c536..15366ab2e6 100644 --- a/plugin-maven/src/test/java/com/diffplug/spotless/maven/yaml/YamlTest.java +++ b/plugin-maven/src/test/java/com/diffplug/spotless/maven/yaml/YamlTest.java @@ -48,6 +48,15 @@ public void testFormatYaml_WithJackson_defaultConfig_arrayBrackets() throws Exce assertFile("yaml_test.yaml").sameAsResource("yaml/array_with_bracket.clean.yaml"); } + @Test + public void testFormatYaml_WithJackson_defaultConfig_arrayBrackets_withEol() throws Exception { + writePomWithYamlSteps("true"); + + setFile("yaml_test.yaml").toResource("yaml/array_with_bracket.yaml"); + mavenRunner().withArguments("spotless:apply").runNoError(); + assertFile("yaml_test.yaml").sameAsResource("yaml/array_with_bracket.clean_with_eol.yaml"); + } + @Test public void testFormatYaml_WithJackson_defaultConfig_multipleDocuments() throws Exception { writePomWithYamlSteps(""); diff --git a/testlib/src/main/resources/json/sortByKeysAfter_Jackson.json b/testlib/src/main/resources/json/sortByKeysAfter_Jackson.json new file mode 100644 index 0000000000..c4a48de2f2 --- /dev/null +++ b/testlib/src/main/resources/json/sortByKeysAfter_Jackson.json @@ -0,0 +1,19 @@ +{ + "A": 1, + "X": 2, + "_arraysNotSorted": [ + 3, + 2, + 1 + ], + "a": 3, + "c": 4, + "x": 5, + "z": { + "A": 1, + "X": 2, + "a": 3, + "c": 4, + "x": 5 + } +} diff --git a/testlib/src/main/resources/json/sortByKeysAfter_Jackson_noSpaceAfterKeySeparator.json b/testlib/src/main/resources/json/sortByKeysAfter_Jackson_noSpaceAfterKeySeparator.json new file mode 100644 index 0000000000..c4a48de2f2 --- /dev/null +++ b/testlib/src/main/resources/json/sortByKeysAfter_Jackson_noSpaceAfterKeySeparator.json @@ -0,0 +1,19 @@ +{ + "A": 1, + "X": 2, + "_arraysNotSorted": [ + 3, + 2, + 1 + ], + "a": 3, + "c": 4, + "x": 5, + "z": { + "A": 1, + "X": 2, + "a": 3, + "c": 4, + "x": 5 + } +} diff --git a/testlib/src/main/resources/yaml/array_with_bracket.clean_with_eol.yaml b/testlib/src/main/resources/yaml/array_with_bracket.clean_with_eol.yaml new file mode 100644 index 0000000000..6080ba1f82 --- /dev/null +++ b/testlib/src/main/resources/yaml/array_with_bracket.clean_with_eol.yaml @@ -0,0 +1,12 @@ +--- +episodes: +- 1 +- 2 +- 3 +- 4 +- 5 +- 6 +- 7 +best-jedi: + name: "Obi-Wan" + side: "light" From 6c20790c626b05045dc8e53afce004cbac9b8d9c Mon Sep 17 00:00:00 2001 From: Michael Ernst Date: Sun, 15 Jan 2023 16:21:38 -0800 Subject: [PATCH 563/757] Format more type annotations as type annotations --- CHANGES.md | 2 ++ .../com/diffplug/spotless/java/FormatAnnotationsStep.java | 8 ++++++++ 2 files changed, 10 insertions(+) diff --git a/CHANGES.md b/CHANGES.md index c08ca86796..b871fc4be8 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -22,6 +22,8 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format ( ### Fixed * Support `ktlint` 0.48+ new rule disabling syntax ([#1456](https://github.com/diffplug/spotless/pull/1456)) fixes ([#1444](https://github.com/diffplug/spotless/issues/1444)) * Fix subgroups leading catch all matcher. +* Format more type annotations as type annotations [#????](https://github.com/diffplug/spotless/pull/????) + ### Changes * Bump default version for `prettier` from `2.0.5` to `2.8.1` ([#1453](https://github.com/diffplug/spotless/pull/1453)) * Bump the dev version of Gradle from `7.5.1` to `7.6` ([#1409](https://github.com/diffplug/spotless/pull/1409)) diff --git a/lib/src/main/java/com/diffplug/spotless/java/FormatAnnotationsStep.java b/lib/src/main/java/com/diffplug/spotless/java/FormatAnnotationsStep.java index d05a53ee1b..f37502d145 100644 --- a/lib/src/main/java/com/diffplug/spotless/java/FormatAnnotationsStep.java +++ b/lib/src/main/java/com/diffplug/spotless/java/FormatAnnotationsStep.java @@ -55,6 +55,13 @@ public final class FormatAnnotationsStep { "Acceleration", "ACCTop", "AinferBottom", + "AinferDefaultType", + "AinferParent", + "AinferSibling1", + "AinferSibling2", + "AinferTop", + "AinferImplicitAnno", + "AinferSiblingWithFields", "AlwaysSafe", "Angle", "AnnoWithStringArg", @@ -102,6 +109,7 @@ public final class FormatAnnotationsStep { "DefaultType", "degrees", "Det", + "DoesNotMatchRegex", "DotSeparatedIdentifiers", "DotSeparatedIdentifiersOrPrimitiveType", "DoubleVal", From b4c0f1b8abf725ad5adc3dcd6f377613b901d0d4 Mon Sep 17 00:00:00 2001 From: Michael Ernst Date: Sun, 15 Jan 2023 16:24:54 -0800 Subject: [PATCH 564/757] Update `CHANGES.md` files --- CHANGES.md | 3 +-- plugin-gradle/CHANGES.md | 1 + plugin-maven/CHANGES.md | 1 + 3 files changed, 3 insertions(+), 2 deletions(-) diff --git a/CHANGES.md b/CHANGES.md index b871fc4be8..2f8ecc46f5 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -22,8 +22,7 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format ( ### Fixed * Support `ktlint` 0.48+ new rule disabling syntax ([#1456](https://github.com/diffplug/spotless/pull/1456)) fixes ([#1444](https://github.com/diffplug/spotless/issues/1444)) * Fix subgroups leading catch all matcher. -* Format more type annotations as type annotations [#????](https://github.com/diffplug/spotless/pull/????) - +* Format more type annotations as type annotations [#1494](https://github.com/diffplug/spotless/pull/1494) ### Changes * Bump default version for `prettier` from `2.0.5` to `2.8.1` ([#1453](https://github.com/diffplug/spotless/pull/1453)) * Bump the dev version of Gradle from `7.5.1` to `7.6` ([#1409](https://github.com/diffplug/spotless/pull/1409)) diff --git a/plugin-gradle/CHANGES.md b/plugin-gradle/CHANGES.md index f6210ce8de..ef2b7a74c3 100644 --- a/plugin-gradle/CHANGES.md +++ b/plugin-gradle/CHANGES.md @@ -13,6 +13,7 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format ( * Prevent tool configurations from being resolved outside project ([#1447](https://github.com/diffplug/spotless/pull/1447) fixes [#1215](https://github.com/diffplug/spotless/issues/1215)) * Support `ktlint` 0.48+ new rule disabling syntax ([#1456](https://github.com/diffplug/spotless/pull/1456)) fixes ([#1444](https://github.com/diffplug/spotless/issues/1444)) * Fix subgroups leading catch all matcher. +* Format more type annotations as type annotations [#1494](https://github.com/diffplug/spotless/pull/1494) ### Changes * Bump default `ktlint` version to latest `0.47.1` -> `0.48.1` ([#1456](https://github.com/diffplug/spotless/pull/1456)) * Bump default version for `prettier` from `2.0.5` to `2.8.1` ([#1453](https://github.com/diffplug/spotless/pull/1453)) diff --git a/plugin-maven/CHANGES.md b/plugin-maven/CHANGES.md index 6f59030a8e..71d44df464 100644 --- a/plugin-maven/CHANGES.md +++ b/plugin-maven/CHANGES.md @@ -14,6 +14,7 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format ( ### Fixed * Support `ktlint` 0.48+ new rule disabling syntax ([#1456](https://github.com/diffplug/spotless/pull/1456)) fixes ([#1444](https://github.com/diffplug/spotless/issues/1444)) * Fix subgroups leading catch all matcher. +* Format more type annotations as type annotations [#1494](https://github.com/diffplug/spotless/pull/1494) ### Changes * Bump default `ktlint` version to latest `0.47.1` -> `0.48.1` ([#1456](https://github.com/diffplug/spotless/pull/1456)) * Reduce spurious invalidations of the up-to-date index file ([#1461](https://github.com/diffplug/spotless/pull/1461)) From 48245dfa47abf5ce4d87189a5eb8883ec7f3d698 Mon Sep 17 00:00:00 2001 From: Michael Ernst Date: Sun, 15 Jan 2023 16:27:02 -0800 Subject: [PATCH 565/757] Update copyright date --- .../java/com/diffplug/spotless/java/FormatAnnotationsStep.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/src/main/java/com/diffplug/spotless/java/FormatAnnotationsStep.java b/lib/src/main/java/com/diffplug/spotless/java/FormatAnnotationsStep.java index f37502d145..5a2d856850 100644 --- a/lib/src/main/java/com/diffplug/spotless/java/FormatAnnotationsStep.java +++ b/lib/src/main/java/com/diffplug/spotless/java/FormatAnnotationsStep.java @@ -1,5 +1,5 @@ /* - * Copyright 2022 DiffPlug + * Copyright 2022-2023 DiffPlug * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. From 70f38248ba47310e58e58970e0885d437e77c775 Mon Sep 17 00:00:00 2001 From: Michael Ernst Date: Sun, 15 Jan 2023 16:34:20 -0800 Subject: [PATCH 566/757] Move changelog entry --- CHANGES.md | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/CHANGES.md b/CHANGES.md index 2f8ecc46f5..9c0ed23980 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -10,6 +10,10 @@ This document is intended for Spotless developers. We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format (starting after version `1.27.0`). ## [Unreleased] +### Added +### Fixed +* Format more type annotations as type annotations [#1494](https://github.com/diffplug/spotless/pull/1494) +### Changes ## [2.32.0] - 2023-01-13 ### Added @@ -22,7 +26,6 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format ( ### Fixed * Support `ktlint` 0.48+ new rule disabling syntax ([#1456](https://github.com/diffplug/spotless/pull/1456)) fixes ([#1444](https://github.com/diffplug/spotless/issues/1444)) * Fix subgroups leading catch all matcher. -* Format more type annotations as type annotations [#1494](https://github.com/diffplug/spotless/pull/1494) ### Changes * Bump default version for `prettier` from `2.0.5` to `2.8.1` ([#1453](https://github.com/diffplug/spotless/pull/1453)) * Bump the dev version of Gradle from `7.5.1` to `7.6` ([#1409](https://github.com/diffplug/spotless/pull/1409)) From 65e74655e9191d1c891cafb6e3c5683da35bb041 Mon Sep 17 00:00:00 2001 From: Benoit Lacelle Date: Mon, 16 Jan 2023 21:17:46 +0400 Subject: [PATCH 567/757] Add doc, Improve tests --- CHANGES.md | 2 + ...unc.java => JacksonJsonFormatterFunc.java} | 53 +++++++++++++-- .../glue/yaml/JacksonYamlFormatterFunc.java | 66 +++++++++++++++++++ .../glue/yaml/YamlJacksonFormatterFunc.java | 34 ---------- .../diffplug/spotless/json/JacksonConfig.java | 27 ++++---- plugin-maven/CHANGES.md | 5 ++ plugin-maven/README.md | 12 ++-- .../spotless/maven/json/JacksonJson.java | 10 ++- .../spotless/maven/yaml/JacksonYaml.java | 14 ++-- .../spotless/maven/json/JsonTest.java | 9 ++- .../spotless/maven/yaml/YamlTest.java | 6 +- ...After_Jackson_spaceAfterKeySeparator.json} | 0 ...h_bracket.clean.spaceBeforeSeparator.yaml} | 2 +- 13 files changed, 156 insertions(+), 84 deletions(-) rename lib/src/jackson/java/com/diffplug/spotless/glue/json/{JsonJacksonFormatterFunc.java => JacksonJsonFormatterFunc.java} (70%) create mode 100644 lib/src/jackson/java/com/diffplug/spotless/glue/yaml/JacksonYamlFormatterFunc.java delete mode 100644 lib/src/jackson/java/com/diffplug/spotless/glue/yaml/YamlJacksonFormatterFunc.java rename testlib/src/main/resources/json/{sortByKeysAfter_Jackson_noSpaceAfterKeySeparator.json => sortByKeysAfter_Jackson_spaceAfterKeySeparator.json} (100%) rename testlib/src/main/resources/yaml/{array_with_bracket.clean_with_eol.yaml => array_with_bracket.clean.spaceBeforeSeparator.yaml} (81%) diff --git a/CHANGES.md b/CHANGES.md index c08ca86796..fd10d2c14e 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -10,6 +10,8 @@ This document is intended for Spotless developers. We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format (starting after version `1.27.0`). ## [Unreleased] +### Changes +* Rename `YamlJacksonStep` into `JacksonYamlStep` while normalizing Jackson usage ([#1492](https://github.com/diffplug/spotless/pull/1492)) ## [2.32.0] - 2023-01-13 ### Added diff --git a/lib/src/jackson/java/com/diffplug/spotless/glue/json/JsonJacksonFormatterFunc.java b/lib/src/jackson/java/com/diffplug/spotless/glue/json/JacksonJsonFormatterFunc.java similarity index 70% rename from lib/src/jackson/java/com/diffplug/spotless/glue/json/JsonJacksonFormatterFunc.java rename to lib/src/jackson/java/com/diffplug/spotless/glue/json/JacksonJsonFormatterFunc.java index 0a13ab6626..c19e56b549 100644 --- a/lib/src/jackson/java/com/diffplug/spotless/glue/json/JsonJacksonFormatterFunc.java +++ b/lib/src/jackson/java/com/diffplug/spotless/glue/json/JacksonJsonFormatterFunc.java @@ -16,9 +16,14 @@ package com.diffplug.spotless.glue.json; import java.io.IOException; +import java.util.stream.Collectors; +import java.util.stream.IntStream; import com.fasterxml.jackson.core.JsonFactory; import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.core.util.DefaultIndenter; +import com.fasterxml.jackson.core.util.DefaultPrettyPrinter; +import com.fasterxml.jackson.core.util.Separators; import com.fasterxml.jackson.databind.ObjectMapper; import com.fasterxml.jackson.databind.SerializationFeature; import com.fasterxml.jackson.databind.node.ObjectNode; @@ -30,10 +35,10 @@ * A {@link FormatterFunc} based on Jackson library */ // https://github.com/FasterXML/jackson-dataformats-text/issues/372 -public class JsonJacksonFormatterFunc implements FormatterFunc { +public class JacksonJsonFormatterFunc implements FormatterFunc { private JacksonConfig jacksonConfig; - public JsonJacksonFormatterFunc(JacksonConfig jacksonConfig) { + public JacksonJsonFormatterFunc(JacksonConfig jacksonConfig) { this.jacksonConfig = jacksonConfig; } @@ -56,6 +61,8 @@ protected ObjectMapper makeObjectMapper() { JsonFactory jsonFactory = makeJsonFactory(); ObjectMapper objectMapper = new ObjectMapper(jsonFactory); + objectMapper.setDefaultPrettyPrinter(makePrinter()); + // Configure the ObjectMapper // https://github.com/FasterXML/jackson-databind#commonly-used-features jacksonConfig.getFeatureToToggle().forEach((rawFeature, toggle) -> { @@ -68,6 +75,44 @@ protected ObjectMapper makeObjectMapper() { return objectMapper; } + protected DefaultPrettyPrinter makePrinter() { + boolean spaceBeforeSeparator = jacksonConfig.isSpaceBeforeSeparator(); + + DefaultPrettyPrinter.Indenter indenter = new DefaultIndenter(getIndentation(), "\n"); + DefaultPrettyPrinter printer = new DefaultPrettyPrinter() { + private static final long serialVersionUID = 1L; + + @Override + public DefaultPrettyPrinter createInstance() { + return new DefaultPrettyPrinter(this); + } + + @Override + public DefaultPrettyPrinter withSeparators(Separators separators) { + this._separators = separators; + if (spaceBeforeSeparator) { + this._objectFieldValueSeparatorWithSpaces = " " + separators.getObjectFieldValueSeparator() + " "; + } else { + this._objectFieldValueSeparatorWithSpaces = separators.getObjectFieldValueSeparator() + " "; + } + return this; + } + }; + + printer.indentObjectsWith(indenter); + printer.indentArraysWith(indenter); + return printer; + } + + protected String getIndentation() { + int indentSpaces = jacksonConfig.getIndentSpaces(); + if (indentSpaces < 0) { + return "\t"; + } else { + return IntStream.range(0, indentSpaces).mapToObj(i -> "").collect(Collectors.joining()); + } + } + protected String format(ObjectMapper objectMapper, String input) throws IllegalArgumentException, IOException { // We may consider adding manually an initial '---' prefix to help management of multiple documents // if (!input.trim().startsWith("---")) { @@ -91,10 +136,6 @@ protected String format(ObjectMapper objectMapper, String input) throws IllegalA ObjectNode objectNode = objectMapper.readValue(input, ObjectNode.class); String outputFromjackson = objectMapper.writeValueAsString(objectNode); - if (jacksonConfig.isEndWithEol() && !outputFromjackson.endsWith("\n")) { - outputFromjackson += "\n"; - } - return outputFromjackson; } catch (JsonProcessingException e) { throw new AssertionError("Unable to format. input='" + input + "'", e); diff --git a/lib/src/jackson/java/com/diffplug/spotless/glue/yaml/JacksonYamlFormatterFunc.java b/lib/src/jackson/java/com/diffplug/spotless/glue/yaml/JacksonYamlFormatterFunc.java new file mode 100644 index 0000000000..6a471a884c --- /dev/null +++ b/lib/src/jackson/java/com/diffplug/spotless/glue/yaml/JacksonYamlFormatterFunc.java @@ -0,0 +1,66 @@ +/* + * Copyright 2021-2023 DiffPlug + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.diffplug.spotless.glue.yaml; + +import java.io.IOException; + +import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.databind.ObjectMapper; +import com.fasterxml.jackson.databind.node.ObjectNode; +import com.fasterxml.jackson.dataformat.yaml.YAMLFactory; + +import com.diffplug.spotless.glue.json.JacksonJsonFormatterFunc; +import com.diffplug.spotless.json.JacksonConfig; + +public class JacksonYamlFormatterFunc extends JacksonJsonFormatterFunc { + + public JacksonYamlFormatterFunc(JacksonConfig jacksonConfig) { + super(jacksonConfig); + } + + @Override + protected YAMLFactory makeJsonFactory() { + return new YAMLFactory(); + } + + @Override + protected String format(ObjectMapper objectMapper, String input) throws IllegalArgumentException, IOException { + // We may consider adding manually an initial '---' prefix to help management of multiple documents + // if (!input.trim().startsWith("---")) { + // input = "---" + "\n" + input; + // } + + try { + // https://stackoverflow.com/questions/25222327/deserialize-pojos-from-multiple-yaml-documents-in-a-single-file-in-jackson + // https://github.com/FasterXML/jackson-dataformats-text/issues/66#issuecomment-375328648 + // 2023-01: For now, we get 'Cannot deserialize value of type `com.fasterxml.jackson.databind.node.ObjectNode` from Array value' + // JsonParser yamlParser = objectMapper.getFactory().createParser(input); + // List docs = objectMapper.readValues(yamlParser, ObjectNode.class).readAll(); + // return objectMapper.writeValueAsString(docs); + + // A JsonNode may keep the comments from the input node + // JsonNode jsonNode = objectMapper.readTree(input); + //Not 'toPrettyString' as one could require no INDENT_OUTPUT + // return jsonNode.toPrettyString(); + ObjectNode objectNode = objectMapper.readValue(input, ObjectNode.class); + String outputFromjackson = objectMapper.writeValueAsString(objectNode); + + return outputFromjackson; + } catch (JsonProcessingException e) { + throw new AssertionError("Unable to format. input='" + input + "'", e); + } + } +} diff --git a/lib/src/jackson/java/com/diffplug/spotless/glue/yaml/YamlJacksonFormatterFunc.java b/lib/src/jackson/java/com/diffplug/spotless/glue/yaml/YamlJacksonFormatterFunc.java deleted file mode 100644 index eda2675985..0000000000 --- a/lib/src/jackson/java/com/diffplug/spotless/glue/yaml/YamlJacksonFormatterFunc.java +++ /dev/null @@ -1,34 +0,0 @@ -/* - * Copyright 2021-2023 DiffPlug - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package com.diffplug.spotless.glue.yaml; - -import com.diffplug.spotless.glue.json.JsonJacksonFormatterFunc; - -import com.fasterxml.jackson.dataformat.yaml.YAMLFactory; - -import com.diffplug.spotless.json.JacksonConfig; - -public class YamlJacksonFormatterFunc extends JsonJacksonFormatterFunc { - - public YamlJacksonFormatterFunc(JacksonConfig jacksonConfig) { - super(jacksonConfig); - } - - @Override - protected YAMLFactory makeJsonFactory() { - return new YAMLFactory(); - } -} diff --git a/lib/src/main/java/com/diffplug/spotless/json/JacksonConfig.java b/lib/src/main/java/com/diffplug/spotless/json/JacksonConfig.java index 526e235eb7..2fadf31d78 100644 --- a/lib/src/main/java/com/diffplug/spotless/json/JacksonConfig.java +++ b/lib/src/main/java/com/diffplug/spotless/json/JacksonConfig.java @@ -15,6 +15,7 @@ */ package com.diffplug.spotless.json; +import java.io.Serializable; import java.util.Collections; import java.util.LinkedHashMap; import java.util.Map; @@ -22,7 +23,7 @@ /** * A DTO holding the options for Jackson-based formatters */ -public class JacksonConfig { +public class JacksonConfig implements Serializable { private static final Map DEFAULT_FEATURE_TOGGLES; @@ -33,14 +34,14 @@ public class JacksonConfig { DEFAULT_FEATURE_TOGGLES = defaultFeatureToggles; } - protected Map featureToToggle; - - // https://github.com/revelc/formatter-maven-plugin/pull/405 - protected boolean endWithEol = false; + protected Map featureToToggle = new LinkedHashMap<>(); // https://github.com/revelc/formatter-maven-plugin/pull/280 + // By default, Jackson adds a ' ' before separator, which is not standard with most IDE/JSON libraries protected boolean spaceBeforeSeparator = false; + // protected int indentSpaces; + public Map getFeatureToToggle() { return Collections.unmodifiableMap(featureToToggle); } @@ -53,14 +54,6 @@ public void appendFeatureToToggle(Map features) { this.featureToToggle.putAll(features); } - public boolean isEndWithEol() { - return endWithEol; - } - - public void setEndWithEol(boolean endWithEol) { - this.endWithEol = endWithEol; - } - public boolean isSpaceBeforeSeparator() { return spaceBeforeSeparator; } @@ -68,4 +61,12 @@ public boolean isSpaceBeforeSeparator() { public void setSpaceBeforeSeparator(boolean spaceBeforeSeparator) { this.spaceBeforeSeparator = spaceBeforeSeparator; } + + // public int getIndentSpaces() { + // return indentSpaces; + // } + + // public void setIndentSpaces(int indentSpaces) { + // this.indentSpaces = indentSpaces; + // } } diff --git a/plugin-maven/CHANGES.md b/plugin-maven/CHANGES.md index 05cc349e9f..d6326cba12 100644 --- a/plugin-maven/CHANGES.md +++ b/plugin-maven/CHANGES.md @@ -3,6 +3,11 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format (starting after version `1.27.0`). ## [Unreleased] +### Added +* Introduce `` ([#1492](https://github.com/diffplug/spotless/pull/1492)) + * **POTENTIALLY BREAKING** `JacksonYaml` is now configured with a `Map` to configure features +* Jackson (JSON and YAML) has new `spaceBeforeSeparator` option + * **POTENTIALLY BREAKING** `spaceBeforeSeparator` is defaulted to false while the formatter was behaving with `true` ## [2.30.0] - 2023-01-13 ### Added diff --git a/plugin-maven/README.md b/plugin-maven/README.md index 2a455dfe07..6dca992591 100644 --- a/plugin-maven/README.md +++ b/plugin-maven/README.md @@ -924,12 +924,12 @@ Uses Jackson and YAMLFactory to pretty print objects: ```xml 2.14.1 - - INDENT_OUTPUT - - - DEFAULT_HAS_NO_DISABLED_FEATURE - + + true + false + true|false + + false ``` diff --git a/plugin-maven/src/main/java/com/diffplug/spotless/maven/json/JacksonJson.java b/plugin-maven/src/main/java/com/diffplug/spotless/maven/json/JacksonJson.java index cf03ef21ca..31c59a5f81 100644 --- a/plugin-maven/src/main/java/com/diffplug/spotless/maven/json/JacksonJson.java +++ b/plugin-maven/src/main/java/com/diffplug/spotless/maven/json/JacksonJson.java @@ -33,10 +33,10 @@ public class JacksonJson implements FormatterStepFactory { @Parameter - String version = JacksonJsonStep.defaultVersion(); + private String version = JacksonJsonStep.defaultVersion(); @Parameter - boolean endWithEol = new JacksonConfig().isEndWithEol(); + private boolean spaceBeforeSeparator = new JacksonConfig().isSpaceBeforeSeparator(); @Parameter private Map features = Collections.emptyMap(); @@ -45,10 +45,8 @@ public class JacksonJson implements FormatterStepFactory { public FormatterStep newFormatterStep(FormatterStepConfig stepConfig) { JacksonConfig jacksonConfig = new JacksonConfig(); - if (features != null) { - jacksonConfig.appendFeatureToToggle(features); - } - jacksonConfig.setEndWithEol(endWithEol); + jacksonConfig.appendFeatureToToggle(features); + jacksonConfig.setSpaceBeforeSeparator(spaceBeforeSeparator); return JacksonJsonStep .create(jacksonConfig, version, stepConfig.getProvisioner()); diff --git a/plugin-maven/src/main/java/com/diffplug/spotless/maven/yaml/JacksonYaml.java b/plugin-maven/src/main/java/com/diffplug/spotless/maven/yaml/JacksonYaml.java index d3d9558cf4..1cd23bc3cc 100644 --- a/plugin-maven/src/main/java/com/diffplug/spotless/maven/yaml/JacksonYaml.java +++ b/plugin-maven/src/main/java/com/diffplug/spotless/maven/yaml/JacksonYaml.java @@ -18,12 +18,11 @@ import java.util.Collections; import java.util.Map; -import com.diffplug.spotless.maven.FormatterFactory; - import org.apache.maven.plugins.annotations.Parameter; import com.diffplug.spotless.FormatterStep; import com.diffplug.spotless.json.JacksonConfig; +import com.diffplug.spotless.maven.FormatterFactory; import com.diffplug.spotless.maven.FormatterStepConfig; import com.diffplug.spotless.maven.FormatterStepFactory; import com.diffplug.spotless.yaml.JacksonYamlStep; @@ -37,10 +36,7 @@ public class JacksonYaml implements FormatterStepFactory { private String version = JacksonYamlStep.defaultVersion(); @Parameter - boolean endWithEol = new JacksonConfig().isEndWithEol(); - - @Parameter - boolean spaceBeforeSeparator = new JacksonConfig().isSpaceBeforeSeparator(); + private boolean spaceBeforeSeparator = new JacksonConfig().isSpaceBeforeSeparator(); @Parameter private Map features = Collections.emptyMap(); @@ -49,10 +45,8 @@ public class JacksonYaml implements FormatterStepFactory { public FormatterStep newFormatterStep(FormatterStepConfig stepConfig) { JacksonConfig jacksonConfig = new JacksonConfig(); - if (features != null) { - jacksonConfig.appendFeatureToToggle(features); - } - jacksonConfig.setEndWithEol(endWithEol); + jacksonConfig.appendFeatureToToggle(features); + jacksonConfig.setSpaceBeforeSeparator(spaceBeforeSeparator); return JacksonYamlStep .create(jacksonConfig, version, stepConfig.getProvisioner()); diff --git a/plugin-maven/src/test/java/com/diffplug/spotless/maven/json/JsonTest.java b/plugin-maven/src/test/java/com/diffplug/spotless/maven/json/JsonTest.java index 90b3a2f077..b263be8173 100644 --- a/plugin-maven/src/test/java/com/diffplug/spotless/maven/json/JsonTest.java +++ b/plugin-maven/src/test/java/com/diffplug/spotless/maven/json/JsonTest.java @@ -70,7 +70,6 @@ public void testFormatJson_WithGson_defaultConfig_nestedObject() throws Exceptio assertFile("json_test.json").sameAsResource("json/nestedObjectAfter.json"); } - @Test public void testFormatJson_WithJackson_sortByKeys() throws Exception { writePomWithJsonSteps("true"); @@ -78,17 +77,17 @@ public void testFormatJson_WithJackson_sortByKeys() throws Exception { setFile("json_test.json").toResource("json/sortByKeysBefore.json"); String output = mavenRunner().withArguments("spotless:apply").runNoError().output(); - assertFile("json_test.json").sameAsResource("json/sortByKeysAfter.json"); + assertFile("json_test.json").sameAsResource("json/sortByKeysAfter_Jackson.json"); } @Test - public void testFormatJson_WithJackson_sortByKeys_noSpaceAfterKeySeparator() throws Exception { - writePomWithJsonSteps("falsetrue"); + public void testFormatJson_WithJackson_sortByKeys_spaceAfterKeySeparator() throws Exception { + writePomWithJsonSteps("truetrue"); setFile("json_test.json").toResource("json/sortByKeysBefore.json"); String output = mavenRunner().withArguments("spotless:apply").runNoError().output(); - assertFile("json_test.json").sameAsResource("json/sortByKeysAfter.json"); + assertFile("json_test.json").sameAsResource("json/sortByKeysAfter_Jackson_spaceAfterKeySeparator.json"); } } diff --git a/plugin-maven/src/test/java/com/diffplug/spotless/maven/yaml/YamlTest.java b/plugin-maven/src/test/java/com/diffplug/spotless/maven/yaml/YamlTest.java index 15366ab2e6..51f8da99f4 100644 --- a/plugin-maven/src/test/java/com/diffplug/spotless/maven/yaml/YamlTest.java +++ b/plugin-maven/src/test/java/com/diffplug/spotless/maven/yaml/YamlTest.java @@ -49,12 +49,12 @@ public void testFormatYaml_WithJackson_defaultConfig_arrayBrackets() throws Exce } @Test - public void testFormatYaml_WithJackson_defaultConfig_arrayBrackets_withEol() throws Exception { - writePomWithYamlSteps("true"); + public void testFormatYaml_WithJackson_defaultConfig_arrayBrackets_spaceBeforeSeparator() throws Exception { + writePomWithYamlSteps("true"); setFile("yaml_test.yaml").toResource("yaml/array_with_bracket.yaml"); mavenRunner().withArguments("spotless:apply").runNoError(); - assertFile("yaml_test.yaml").sameAsResource("yaml/array_with_bracket.clean_with_eol.yaml"); + assertFile("yaml_test.yaml").sameAsResource("yaml/array_with_bracket.clean.spaceBeforeSeparator.yaml"); } @Test diff --git a/testlib/src/main/resources/json/sortByKeysAfter_Jackson_noSpaceAfterKeySeparator.json b/testlib/src/main/resources/json/sortByKeysAfter_Jackson_spaceAfterKeySeparator.json similarity index 100% rename from testlib/src/main/resources/json/sortByKeysAfter_Jackson_noSpaceAfterKeySeparator.json rename to testlib/src/main/resources/json/sortByKeysAfter_Jackson_spaceAfterKeySeparator.json diff --git a/testlib/src/main/resources/yaml/array_with_bracket.clean_with_eol.yaml b/testlib/src/main/resources/yaml/array_with_bracket.clean.spaceBeforeSeparator.yaml similarity index 81% rename from testlib/src/main/resources/yaml/array_with_bracket.clean_with_eol.yaml rename to testlib/src/main/resources/yaml/array_with_bracket.clean.spaceBeforeSeparator.yaml index 6080ba1f82..c6f891b9de 100644 --- a/testlib/src/main/resources/yaml/array_with_bracket.clean_with_eol.yaml +++ b/testlib/src/main/resources/yaml/array_with_bracket.clean.spaceBeforeSeparator.yaml @@ -9,4 +9,4 @@ episodes: - 7 best-jedi: name: "Obi-Wan" - side: "light" + side: "light" \ No newline at end of file From f05126de68661f584b1b5865b406f35f700ae2e5 Mon Sep 17 00:00:00 2001 From: Benoit Lacelle Date: Mon, 16 Jan 2023 23:02:39 +0400 Subject: [PATCH 568/757] Fix Spotbugs --- .../glue/json/JacksonJsonFormatterFunc.java | 79 ++++++++----------- .../diffplug/spotless/json/JacksonConfig.java | 1 + 2 files changed, 35 insertions(+), 45 deletions(-) diff --git a/lib/src/jackson/java/com/diffplug/spotless/glue/json/JacksonJsonFormatterFunc.java b/lib/src/jackson/java/com/diffplug/spotless/glue/json/JacksonJsonFormatterFunc.java index c19e56b549..c44ff0d0d1 100644 --- a/lib/src/jackson/java/com/diffplug/spotless/glue/json/JacksonJsonFormatterFunc.java +++ b/lib/src/jackson/java/com/diffplug/spotless/glue/json/JacksonJsonFormatterFunc.java @@ -16,8 +16,6 @@ package com.diffplug.spotless.glue.json; import java.io.IOException; -import java.util.stream.Collectors; -import java.util.stream.IntStream; import com.fasterxml.jackson.core.JsonFactory; import com.fasterxml.jackson.core.JsonProcessingException; @@ -79,25 +77,7 @@ protected DefaultPrettyPrinter makePrinter() { boolean spaceBeforeSeparator = jacksonConfig.isSpaceBeforeSeparator(); DefaultPrettyPrinter.Indenter indenter = new DefaultIndenter(getIndentation(), "\n"); - DefaultPrettyPrinter printer = new DefaultPrettyPrinter() { - private static final long serialVersionUID = 1L; - - @Override - public DefaultPrettyPrinter createInstance() { - return new DefaultPrettyPrinter(this); - } - - @Override - public DefaultPrettyPrinter withSeparators(Separators separators) { - this._separators = separators; - if (spaceBeforeSeparator) { - this._objectFieldValueSeparatorWithSpaces = " " + separators.getObjectFieldValueSeparator() + " "; - } else { - this._objectFieldValueSeparatorWithSpaces = separators.getObjectFieldValueSeparator() + " "; - } - return this; - } - }; + DefaultPrettyPrinter printer = new SpotlessDefaultPrettyPrinter(spaceBeforeSeparator); printer.indentObjectsWith(indenter); printer.indentArraysWith(indenter); @@ -105,34 +85,18 @@ public DefaultPrettyPrinter withSeparators(Separators separators) { } protected String getIndentation() { - int indentSpaces = jacksonConfig.getIndentSpaces(); - if (indentSpaces < 0) { - return "\t"; - } else { - return IntStream.range(0, indentSpaces).mapToObj(i -> "").collect(Collectors.joining()); - } + // DefaultIndenter default constructor relies on this + return " "; + // int indentSpaces = jacksonConfig.getIndentSpaces(); + // if (indentSpaces < 0) { + // return "\t"; + // } else { + // return IntStream.range(0, indentSpaces).mapToObj(i -> "").collect(Collectors.joining()); + // } } protected String format(ObjectMapper objectMapper, String input) throws IllegalArgumentException, IOException { - // We may consider adding manually an initial '---' prefix to help management of multiple documents - // if (!input.trim().startsWith("---")) { - // input = "---" + "\n" + input; - // } - try { - // https://stackoverflow.com/questions/25222327/deserialize-pojos-from-multiple-yaml-documents-in-a-single-file-in-jackson - // https://github.com/FasterXML/jackson-dataformats-text/issues/66#issuecomment-375328648 - // 2023-01: For now, we get 'Cannot deserialize value of type `com.fasterxml.jackson.databind.node.ObjectNode` from Array value' - // JsonParser yamlParser = objectMapper.getFactory().createParser(input); - // List docs = objectMapper.readValues(yamlParser, ObjectNode.class).readAll(); - // return objectMapper.writeValueAsString(docs); - - // 2023-01: This returns JSON instead of YAML - // This will transit with a JsonNode - // A JsonNode may keep the comments from the input node - // JsonNode jsonNode = objectMapper.readTree(input); - //Not 'toPrettyString' as one could require no INDENT_OUTPUT - // return jsonNode.toPrettyString(); ObjectNode objectNode = objectMapper.readValue(input, ObjectNode.class); String outputFromjackson = objectMapper.writeValueAsString(objectNode); @@ -141,4 +105,29 @@ protected String format(ObjectMapper objectMapper, String input) throws IllegalA throw new AssertionError("Unable to format. input='" + input + "'", e); } } + + protected static class SpotlessDefaultPrettyPrinter extends DefaultPrettyPrinter { + private static final long serialVersionUID = 1L; + private final boolean spaceBeforeSeparator; + + public SpotlessDefaultPrettyPrinter(boolean spaceBeforeSeparator) { + this.spaceBeforeSeparator = spaceBeforeSeparator; + } + + @Override + public DefaultPrettyPrinter createInstance() { + return new DefaultPrettyPrinter(this); + } + + @Override + public DefaultPrettyPrinter withSeparators(Separators separators) { + this._separators = separators; + if (spaceBeforeSeparator) { + this._objectFieldValueSeparatorWithSpaces = " " + separators.getObjectFieldValueSeparator() + " "; + } else { + this._objectFieldValueSeparatorWithSpaces = separators.getObjectFieldValueSeparator() + " "; + } + return this; + } + } } diff --git a/lib/src/main/java/com/diffplug/spotless/json/JacksonConfig.java b/lib/src/main/java/com/diffplug/spotless/json/JacksonConfig.java index 2fadf31d78..7690913f34 100644 --- a/lib/src/main/java/com/diffplug/spotless/json/JacksonConfig.java +++ b/lib/src/main/java/com/diffplug/spotless/json/JacksonConfig.java @@ -24,6 +24,7 @@ * A DTO holding the options for Jackson-based formatters */ public class JacksonConfig implements Serializable { + private static final long serialVersionUID = 1L; private static final Map DEFAULT_FEATURE_TOGGLES; From beb99af54563b473cd8f209afa78aca35f813d7b Mon Sep 17 00:00:00 2001 From: Ned Twigg Date: Mon, 16 Jan 2023 16:06:43 -0800 Subject: [PATCH 569/757] Adopt `de.benediktritter.maven-plugin-development` --- plugin-maven/build.gradle | 169 +++--------------- .../src/test/resources/pom-build.xml.mustache | 96 ---------- 2 files changed, 21 insertions(+), 244 deletions(-) delete mode 100644 plugin-maven/src/test/resources/pom-build.xml.mustache diff --git a/plugin-maven/build.gradle b/plugin-maven/build.gradle index 3ea73e6101..6cf17dd986 100644 --- a/plugin-maven/build.gradle +++ b/plugin-maven/build.gradle @@ -1,42 +1,15 @@ -buildscript { - repositories { mavenCentral() } - dependencies { classpath "com.github.spullara.mustache.java:compiler:${VER_MUSTACHE}" } -} plugins { - id 'cz.malohlava.visteg' version '1.0.5' // https://github.com/mmalohlava/gradle-visteg + // https://www.benediktritter.de/maven-plugin-development/#release-history + id 'de.benediktritter.maven-plugin-development' version '0.4.0' } + repositories { mavenCentral() } apply from: rootProject.file('gradle/changelog.gradle') -apply from: rootProject.file('gradle/spotless-freshmark.gradle') - -// to generate taskGraph.pdf -// - set enabled (below) to true -// - run: ./gradlew :plugin-maven:test -// - run: rm plugin-maven/output.pdf -// - run: dot -Tpdf plugin-maven/build/reports/visteg.dot > plugin-maven/taskGraph.pdf -visteg { - enabled = false - nodeShape = 'box' - startNodeShape = 'box' - endNodeShape = 'box' - colorscheme = 'pastel24' // https://www.graphviz.org/doc/info/colors.html -} - -import com.github.mustachejava.DefaultMustacheFactory - -import java.nio.file.Files - -import static java.nio.charset.StandardCharsets.UTF_8 -import static java.nio.file.StandardOpenOption.CREATE -import static java.nio.file.StandardOpenOption.TRUNCATE_EXISTING - ext.artifactId = project.artifactIdMaven version = spotlessChangelog.versionNext -apply from: rootProject.file("gradle/java-setup.gradle") -apply from: rootProject.file("gradle/java-publish.gradle") -final MAVEN_PROJECT_DIR = project.layout.buildDirectory.dir("mavenProject").get() -final LOCAL_MAVEN_REPO_DIR = project.layout.buildDirectory.dir("localMavenRepository").get() +apply from: rootProject.file("gradle/java-setup.gradle") +apply from: rootProject.file('gradle/spotless-freshmark.gradle') def mvnw(String args) { boolean isWin = System.getProperty('os.name').toLowerCase().contains('win') @@ -55,17 +28,15 @@ def mvnw(String args) { } } -String libVersion = version.endsWith('-SNAPSHOT') ? - rootProject.spotlessChangelog.versionNext : - rootProject.spotlessChangelog.versionLast +apply plugin: 'de.benediktritter.maven-plugin-development' +mavenPlugin { + name = 'Spotless Maven Plugin' + artifactId = project.artifactIdMaven + description = project.description +} dependencies { - if (version.endsWith('-SNAPSHOT') || (rootProject.spotlessChangelog.versionNext == rootProject.spotlessChangelog.versionLast)) { - implementation project(':lib') - implementation project(':lib-extra') - } else { - implementation "com.diffplug.spotless:spotless-lib:${libVersion}" - implementation "com.diffplug.spotless:spotless-lib-extra:${libVersion}" - } + implementation project(':lib') + implementation project(':lib-extra') compileOnly "org.apache.maven:maven-plugin-api:${VER_MAVEN_API}" compileOnly "org.apache.maven.plugin-tools:maven-plugin-annotations:${VER_MAVEN_API}" @@ -90,112 +61,14 @@ dependencies { testImplementation "org.apache.maven:maven-core:${VER_MAVEN_API}" } -task copySourceFiles(type: Sync) { - from "src/main/java" - into MAVEN_PROJECT_DIR.dir("src/main/java") -} - -task copyMvnw(type: Copy, dependsOn: copySourceFiles) { - from 'src/test/resources' - include 'mvnw' - include 'mvnw.cmd' - include '.mvn/**' - into MAVEN_PROJECT_DIR -} - -task installLocalDependencies -def libs = [ - 'lib', - 'lib-extra', - 'testlib' -] -libs.each { - def groupId = 'com.diffplug.spotless' - def artifactId = "spotless-${it}" - def jarTask = tasks.getByPath(":${it}:jar") - def file = jarTask.archivePath - - def installDependency = task "install_${artifactId}"(type: Exec) { - workingDir MAVEN_PROJECT_DIR - - inputs.file(file) - outputs.dir(LOCAL_MAVEN_REPO_DIR.file(groupId.replace('.', '/') + "/" + artifactId + "/" + version)) - commandLine mvnw("org.apache.maven.plugins:maven-install-plugin:2.3.1:install-file " + - "-Dfile=${file} " + - "-DgroupId=${groupId} " + - "-DartifactId=${artifactId} " + - "-Dversion=${libVersion} " + - "-Dpackaging=jar " + - "-DlocalRepositoryPath=${LOCAL_MAVEN_REPO_DIR}") - } - installDependency.dependsOn(jarTask) - - installLocalDependencies.dependsOn installDependency -} - -task createPomXml(dependsOn: installLocalDependencies) { - def newPomXml = MAVEN_PROJECT_DIR.file("pom.xml").asFile.toPath() - - outputs.file(newPomXml) - doLast { - def additionalDependencies = project.configurations.runtimeClasspath.resolvedConfiguration.resolvedArtifacts.findAll { - return !libs.contains(it.moduleVersion.id.name) - }.collect { - return " \n" + - " ${it.moduleVersion.id.group}\n" + - " ${it.moduleVersion.id.name}\n" + - " ${it.moduleVersion.id.version}\n" + - " \n" - }.join() - - def versions = [ - spotlessMavenPluginVersion: version, - mavenApiVersion : VER_MAVEN_API, - eclipseAetherVersion : VER_ECLIPSE_AETHER, - spotlessLibVersion : libVersion, - jsr305Version : VER_JSR_305, - additionalDependencies : additionalDependencies - ] - - def pomXmlTemplate = project.layout.projectDirectory.file("src/test/resources/pom-build.xml.mustache").asFile.toPath() - - Files.newBufferedReader(pomXmlTemplate).withCloseable { reader -> - Files.newBufferedWriter(newPomXml, UTF_8, CREATE, TRUNCATE_EXISTING).withCloseable { writer -> - def mustache = new DefaultMustacheFactory().compile(reader, "pom") - mustache.execute(writer, versions) - } - } - } -} - -task runMavenBuild(type: Exec, dependsOn: [ - copySourceFiles, - copyMvnw, - createPomXml -]) { - outputs.dir(LOCAL_MAVEN_REPO_DIR) - - workingDir MAVEN_PROJECT_DIR - // -B batch mode to make dependency download logging less verbose - commandLine mvnw("clean install -B -Dmaven.repo.local=${LOCAL_MAVEN_REPO_DIR}") -} - -jar.setActions Arrays.asList() -jar.dependsOn(runMavenBuild) -File jarIn = MAVEN_PROJECT_DIR.file("target/spotless-maven-plugin-${version}.jar").asFile -File jarOut = jar.archivePath -jar.inputs.file(jarIn) -jar.outputs.file(jarOut) -jar.doLast { - Files.copy(jarIn.toPath(), jarOut.toPath(), java.nio.file.StandardCopyOption.REPLACE_EXISTING) -} - -test { useJUnitPlatform() } - apply from: rootProject.file('gradle/special-tests.gradle') -tasks.withType(Test) { - systemProperty "localMavenRepositoryDir", LOCAL_MAVEN_REPO_DIR.asFile - systemProperty "spotlessMavenPluginVersion", project.version - dependsOn(jar) +tasks.withType(Test).configureEach { + useJUnitPlatform() + systemProperty 'spotlessMavenPluginVersion', project.version + dependsOn 'publishToMavenLocal' + dependsOn ':lib:publishToMavenLocal' + dependsOn ':lib-extra:publishToMavenLocal' } + +apply from: rootProject.file("gradle/java-publish.gradle") diff --git a/plugin-maven/src/test/resources/pom-build.xml.mustache b/plugin-maven/src/test/resources/pom-build.xml.mustache deleted file mode 100644 index 3c1d1a7d5b..0000000000 --- a/plugin-maven/src/test/resources/pom-build.xml.mustache +++ /dev/null @@ -1,96 +0,0 @@ - - 4.0.0 - - com.diffplug.spotless - spotless-maven-plugin - {{spotlessMavenPluginVersion}} - maven-plugin - - Spotless Maven Plugin - - - - 3.1.0 - - - - UTF-8 - 1.8 - 1.8 - - - {{mavenApiVersion}} - {{eclipseAetherVersion}} - {{spotlessLibVersion}} - {{jsr305Version}} - - - - - org.apache.maven - maven-core - ${maven.api.version} - provided - - - org.apache.maven - maven-plugin-api - ${maven.api.version} - provided - - - org.apache.maven.plugin-tools - maven-plugin-annotations - ${maven.api.version} - provided - - - org.eclipse.aether - aether-api - ${eclipse.aether.version} - provided - - - org.eclipse.aether - aether-util - ${eclipse.aether.version} - provided - - - com.google.code.findbugs - jsr305 - ${jsr305.version} - provided - - - - com.diffplug.spotless - spotless-lib - ${spotless.lib.version} - - - com.diffplug.spotless - spotless-lib-extra - ${spotless.lib.version} - - -{{{additionalDependencies}}} - - - - - - - - org.apache.maven.plugins - maven-plugin-plugin - 3.5 - - - - - From 48ded12b4812b562065f54db20b4214ddae1f019 Mon Sep 17 00:00:00 2001 From: Ned Twigg Date: Mon, 16 Jan 2023 16:07:18 -0800 Subject: [PATCH 570/757] We now use the default local maven repository. --- .../spotless/maven/MavenIntegrationHarness.java | 6 +----- .../java/com/diffplug/spotless/maven/MavenRunner.java | 10 ++-------- 2 files changed, 3 insertions(+), 13 deletions(-) diff --git a/plugin-maven/src/test/java/com/diffplug/spotless/maven/MavenIntegrationHarness.java b/plugin-maven/src/test/java/com/diffplug/spotless/maven/MavenIntegrationHarness.java index e37bb0f13d..ad19f44624 100644 --- a/plugin-maven/src/test/java/com/diffplug/spotless/maven/MavenIntegrationHarness.java +++ b/plugin-maven/src/test/java/com/diffplug/spotless/maven/MavenIntegrationHarness.java @@ -53,7 +53,6 @@ public class MavenIntegrationHarness extends ResourceHarness { */ private static final String SPOTLESS_MAVEN_VERSION_IDE = null; - private static final String LOCAL_MAVEN_REPOSITORY_DIR = "localMavenRepositoryDir"; private static final String SPOTLESS_MAVEN_PLUGIN_VERSION = "spotlessMavenPluginVersion"; private static final String CONFIGURATION = "configuration"; private static final String EXECUTIONS = "executions"; @@ -179,8 +178,7 @@ protected void writePom(String[] executions, String[] configuration, String[] de protected MavenRunner mavenRunner() throws IOException { return MavenRunner.create() - .withProjectDir(rootFolder()) - .withLocalRepository(new File(getSystemProperty(LOCAL_MAVEN_REPOSITORY_DIR))); + .withProjectDir(rootFolder()); } /** @@ -247,8 +245,6 @@ private static String getSystemProperty(String name) { if (SPOTLESS_MAVEN_VERSION_IDE != null) { if (name.equals("spotlessMavenPluginVersion")) { return SPOTLESS_MAVEN_VERSION_IDE; - } else if (name.equals("localMavenRepositoryDir")) { - return new File("build/localMavenRepository").getAbsolutePath(); } else { throw Unhandled.stringException(name); } diff --git a/plugin-maven/src/test/java/com/diffplug/spotless/maven/MavenRunner.java b/plugin-maven/src/test/java/com/diffplug/spotless/maven/MavenRunner.java index a86e000187..b5e2392a24 100644 --- a/plugin-maven/src/test/java/com/diffplug/spotless/maven/MavenRunner.java +++ b/plugin-maven/src/test/java/com/diffplug/spotless/maven/MavenRunner.java @@ -1,5 +1,5 @@ /* - * Copyright 2016-2021 DiffPlug + * Copyright 2016-2023 DiffPlug * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -46,7 +46,6 @@ private MavenRunner() {} private File projectDir; private String[] args; - private File localRepositoryDir; private Map environment = new HashMap<>(); public MavenRunner withProjectDir(File projectDir) { @@ -59,11 +58,6 @@ public MavenRunner withArguments(String... args) { return this; } - public MavenRunner withLocalRepository(File localRepositoryDir) { - this.localRepositoryDir = localRepositoryDir; - return this; - } - public MavenRunner withRemoteDebug(int port) { String address = (Jvm.version() < 9 ? "" : "*:") + port; environment.put("MAVEN_OPTS", "-agentlib:jdwp=transport=dt_socket,server=y,suspend=y,address=" + address); @@ -75,7 +69,7 @@ private Result run() throws IOException, InterruptedException { Objects.requireNonNull(args, "Need to call withArguments() first"); // run maven with the given args in the given directory String argsString = String.join(" ", Arrays.asList(args)); - List cmds = getPlatformCmds("-e -Dmaven.repo.local=" + localRepositoryDir + ' ' + argsString); + List cmds = getPlatformCmds("-e " + argsString); ProcessBuilder builder = new ProcessBuilder(cmds); builder.directory(projectDir); builder.environment().putAll(environment); From 491da2e1fc0968080c6ad4860873c30d142ed1b3 Mon Sep 17 00:00:00 2001 From: Ned Twigg Date: Mon, 16 Jan 2023 16:07:41 -0800 Subject: [PATCH 571/757] We don't need to exclude maven from the initial assemble anymore. --- .github/workflows/ci.yml | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 2e302e6637..1f08c201f5 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -30,8 +30,7 @@ jobs: - name: spotlessCheck run: ./gradlew spotlessCheck --build-cache - name: assemble testClasses - run: ./gradlew assemble testClasses --build-cache -PSPOTLESS_EXCLUDE_MAVEN=true - # If this gets resolved, remove the EXCLUDE_MAVEN https://github.com/diffplug/spotless/issues/554 + run: ./gradlew assemble testClasses --build-cache build: needs: sanityCheck strategy: From 0f18e245981ad1909aad7bf91cf634446a6d1aab Mon Sep 17 00:00:00 2001 From: Ned Twigg Date: Mon, 16 Jan 2023 16:18:01 -0800 Subject: [PATCH 572/757] Update changelog. --- plugin-maven/CHANGES.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/plugin-maven/CHANGES.md b/plugin-maven/CHANGES.md index 05cc349e9f..6b22962cba 100644 --- a/plugin-maven/CHANGES.md +++ b/plugin-maven/CHANGES.md @@ -3,6 +3,8 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format (starting after version `1.27.0`). ## [Unreleased] +### Changes +* Spotless' custom build was replaced by [`maven-plugin-development`](https://github.com/britter/maven-plugin-development). ([#1496](https://github.com/diffplug/spotless/pull/1496) fixes [#554](https://github.com/diffplug/spotless/issues/554)) ## [2.30.0] - 2023-01-13 ### Added From 8b73372dd286fe43efeb23dcdc8dfa03d85f5fda Mon Sep 17 00:00:00 2001 From: Ned Twigg Date: Mon, 16 Jan 2023 16:20:33 -0800 Subject: [PATCH 573/757] Move maven version constants to the maven buildfile. --- gradle.properties | 8 +------- plugin-maven/build.gradle | 5 +++++ 2 files changed, 6 insertions(+), 7 deletions(-) diff --git a/gradle.properties b/gradle.properties index 71f755522f..c3b71fd92e 100644 --- a/gradle.properties +++ b/gradle.properties @@ -28,10 +28,4 @@ VER_DURIAN=1.2.0 VER_JGIT=5.13.1.202206130422-r VER_JUNIT=5.9.2 VER_ASSERTJ=3.24.1 -VER_MOCKITO=4.11.0 - -# Used for Maven Plugin -VER_MAVEN_API=3.0 -VER_ECLIPSE_AETHER=1.1.0 -VER_MUSTACHE=0.9.10 -VER_PLEXUS_RESOURCES=1.2.0 +VER_MOCKITO=4.11.0 \ No newline at end of file diff --git a/plugin-maven/build.gradle b/plugin-maven/build.gradle index 6cf17dd986..e06fce9ace 100644 --- a/plugin-maven/build.gradle +++ b/plugin-maven/build.gradle @@ -34,6 +34,11 @@ mavenPlugin { artifactId = project.artifactIdMaven description = project.description } + +String VER_MAVEN_API = '3.0' +String VER_ECLIPSE_AETHER = '1.1.0' +String VER_MUSTACHE = '0.9.10' +String VER_PLEXUS_RESOURCES = '1.2.0' dependencies { implementation project(':lib') implementation project(':lib-extra') From 5d7c3b741a4518097bffaacf7e6c30342302c1de Mon Sep 17 00:00:00 2001 From: Ned Twigg Date: Mon, 16 Jan 2023 16:38:18 -0800 Subject: [PATCH 574/757] Move the multimodule harnessing to the only place where it is used. --- .../maven/MavenIntegrationHarness.java | 93 +---------------- .../maven/MultiModuleProjectTest.java | 99 ++++++++++++++++++- 2 files changed, 99 insertions(+), 93 deletions(-) diff --git a/plugin-maven/src/test/java/com/diffplug/spotless/maven/MavenIntegrationHarness.java b/plugin-maven/src/test/java/com/diffplug/spotless/maven/MavenIntegrationHarness.java index ad19f44624..15c504fc72 100644 --- a/plugin-maven/src/test/java/com/diffplug/spotless/maven/MavenIntegrationHarness.java +++ b/plugin-maven/src/test/java/com/diffplug/spotless/maven/MavenIntegrationHarness.java @@ -16,9 +16,7 @@ package com.diffplug.spotless.maven; import static com.diffplug.common.base.Strings.isNullOrEmpty; -import static java.util.Arrays.asList; import static java.util.Arrays.stream; -import static java.util.Collections.emptyMap; import static java.util.Collections.singletonMap; import static java.util.stream.Collectors.toList; import static org.junit.jupiter.api.Assertions.fail; @@ -59,7 +57,6 @@ public class MavenIntegrationHarness extends ResourceHarness { private static final String MODULES = "modules"; private static final String DEPENDENCIES = "dependencies"; private static final String MODULE_NAME = "name"; - private static final String CHILD_ID = "childId"; private static final int REMOTE_DEBUG_PORT = 5005; private final MustacheFactory mustacheFactory = new DefaultMustacheFactory(); @@ -190,10 +187,6 @@ protected MavenRunner mavenRunnerWithRemoteDebug() throws IOException { return mavenRunner().withRemoteDebug(REMOTE_DEBUG_PORT); } - protected MultiModuleProjectCreator multiModuleProject() { - return new MultiModuleProjectCreator(); - } - protected String createPomXmlContent(String pluginVersion, String[] executions, String[] configuration, String[] dependencies) throws IOException { return createPomXmlContent("/pom-test.xml.mustache", pluginVersion, executions, configuration, dependencies); } @@ -207,7 +200,7 @@ protected String createPomXmlContent(String pluginVersion, String[] executions, return createPomXmlContent(pluginVersion, executions, configuration, null); } - private String createPomXmlContent(String pomTemplate, Map params) throws IOException { + protected String createPomXmlContent(String pomTemplate, Map params) throws IOException { URL url = MavenIntegrationHarness.class.getResource(pomTemplate); try (BufferedReader reader = Resources.asCharSource(url, StandardCharsets.UTF_8).openBufferedStream()) { Mustache mustache = mustacheFactory.compile(reader, "pom"); @@ -217,7 +210,7 @@ private String createPomXmlContent(String pomTemplate, Map param } } - private static Map buildPomXmlParams(String pluginVersion, String[] executions, String[] configuration, String[] modules, String[] dependencies) { + protected static Map buildPomXmlParams(String pluginVersion, String[] executions, String[] configuration, String[] modules, String[] dependencies) { Map params = new HashMap<>(); params.put(SPOTLESS_MAVEN_PLUGIN_VERSION, pluginVersion == null ? getSystemProperty(SPOTLESS_MAVEN_PLUGIN_VERSION) : pluginVersion); @@ -276,86 +269,4 @@ private static String[] including(String... includes) { private static String[] formats(String... formats) { return groupWithSteps("formats", formats); } - - protected class MultiModuleProjectCreator { - - private String configSubProject; - private SubProjectFile[] configSubProjectFiles; - private String[] configuration; - private final Map> subProjects = new LinkedHashMap<>(); - - protected MultiModuleProjectCreator withConfigSubProject(String name, SubProjectFile... files) { - configSubProject = name; - configSubProjectFiles = files; - return this; - } - - protected MultiModuleProjectCreator withConfiguration(String... lines) { - configuration = lines; - return this; - } - - protected MultiModuleProjectCreator addSubProject(String name, SubProjectFile... files) { - subProjects.put(name, asList(files)); - return this; - } - - protected void create() throws IOException { - createRootPom(); - createConfigSubProject(); - createSubProjects(); - } - - private void createRootPom() throws IOException { - List modulesList = new ArrayList<>(); - modulesList.add(configSubProject); - modulesList.addAll(subProjects.keySet()); - String[] modules = modulesList.toArray(new String[0]); - - Map rootPomParams = buildPomXmlParams(null, null, configuration, modules, null); - setFile("pom.xml").toContent(createPomXmlContent("/multi-module/pom-parent.xml.mustache", rootPomParams)); - } - - private void createConfigSubProject() throws IOException { - if (configSubProject != null) { - String content = createPomXmlContent("/multi-module/pom-config.xml.mustache", emptyMap()); - setFile(configSubProject + "/pom.xml").toContent(content); - - createSubProjectFiles(configSubProject, asList(configSubProjectFiles)); - } - } - - private void createSubProjects() throws IOException { - for (Map.Entry> entry : subProjects.entrySet()) { - String subProjectName = entry.getKey(); - List subProjectFiles = entry.getValue(); - - String content = createPomXmlContent("/multi-module/pom-child.xml.mustache", singletonMap(CHILD_ID, subProjectName)); - setFile(subProjectName + "/pom.xml").toContent(content); - - createSubProjectFiles(subProjectName, subProjectFiles); - } - } - - private void createSubProjectFiles(String subProjectName, List subProjectFiles) throws IOException { - for (SubProjectFile file : subProjectFiles) { - setFile(subProjectName + '/' + file.to).toResource(file.from); - } - } - } - - protected static class SubProjectFile { - - private final String from; - private final String to; - - private SubProjectFile(String from, String to) { - this.from = from; - this.to = to; - } - - protected static SubProjectFile file(String from, String to) { - return new SubProjectFile(from, to); - } - } } diff --git a/plugin-maven/src/test/java/com/diffplug/spotless/maven/MultiModuleProjectTest.java b/plugin-maven/src/test/java/com/diffplug/spotless/maven/MultiModuleProjectTest.java index e67b1bcad3..ae8378c566 100644 --- a/plugin-maven/src/test/java/com/diffplug/spotless/maven/MultiModuleProjectTest.java +++ b/plugin-maven/src/test/java/com/diffplug/spotless/maven/MultiModuleProjectTest.java @@ -1,5 +1,5 @@ /* - * Copyright 2016-2021 DiffPlug + * Copyright 2016-2023 DiffPlug * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -15,7 +15,15 @@ */ package com.diffplug.spotless.maven; -import static com.diffplug.spotless.maven.MavenIntegrationHarness.SubProjectFile.file; +import static java.util.Arrays.asList; +import static java.util.Collections.emptyMap; +import static java.util.Collections.singletonMap; + +import java.io.IOException; +import java.util.ArrayList; +import java.util.LinkedHashMap; +import java.util.List; +import java.util.Map; import org.junit.jupiter.api.Test; @@ -96,4 +104,91 @@ void testConfigurationDependency() throws Exception { assertFile("three/src/main/scala/test1.scala").sameAsResource("scala/scalafmt/basic.cleanWithCustomConf_3.0.0"); assertFile("three/src/test/scala/test2.scala").sameAsResource("scala/scalafmt/basic.cleanWithCustomConf_3.0.0"); } + + private static final String CHILD_ID = "childId"; + + protected MultiModuleProjectCreator multiModuleProject() { + return new MultiModuleProjectCreator(); + } + + class MultiModuleProjectCreator { + private String configSubProject; + private SubProjectFile[] configSubProjectFiles; + private String[] configuration; + private final Map> subProjects = new LinkedHashMap<>(); + + protected MultiModuleProjectCreator withConfigSubProject(String name, SubProjectFile... files) { + configSubProject = name; + configSubProjectFiles = files; + return this; + } + + protected MultiModuleProjectCreator withConfiguration(String... lines) { + configuration = lines; + return this; + } + + protected MultiModuleProjectCreator addSubProject(String name, SubProjectFile... files) { + subProjects.put(name, asList(files)); + return this; + } + + protected void create() throws IOException { + createRootPom(); + createConfigSubProject(); + createSubProjects(); + } + + private void createRootPom() throws IOException { + List modulesList = new ArrayList<>(); + modulesList.add(configSubProject); + modulesList.addAll(subProjects.keySet()); + String[] modules = modulesList.toArray(new String[0]); + + Map rootPomParams = buildPomXmlParams(null, null, configuration, modules, null); + setFile("pom.xml").toContent(createPomXmlContent("/multi-module/pom-parent.xml.mustache", rootPomParams)); + } + + private void createConfigSubProject() throws IOException { + if (configSubProject != null) { + String content = createPomXmlContent("/multi-module/pom-config.xml.mustache", emptyMap()); + setFile(configSubProject + "/pom.xml").toContent(content); + + createSubProjectFiles(configSubProject, asList(configSubProjectFiles)); + } + } + + private void createSubProjects() throws IOException { + for (Map.Entry> entry : subProjects.entrySet()) { + String subProjectName = entry.getKey(); + List subProjectFiles = entry.getValue(); + + String content = createPomXmlContent("/multi-module/pom-child.xml.mustache", singletonMap(CHILD_ID, subProjectName)); + setFile(subProjectName + "/pom.xml").toContent(content); + + createSubProjectFiles(subProjectName, subProjectFiles); + } + } + + private void createSubProjectFiles(String subProjectName, List subProjectFiles) { + for (SubProjectFile file : subProjectFiles) { + setFile(subProjectName + '/' + file.to).toResource(file.from); + } + } + } + + static class SubProjectFile { + + private final String from; + private final String to; + + private SubProjectFile(String from, String to) { + this.from = from; + this.to = to; + } + } + + static SubProjectFile file(String from, String to) { + return new SubProjectFile(from, to); + } } From 7294dbcfa94778d2f2c25e2e7d34237faac33685 Mon Sep 17 00:00:00 2001 From: Ned Twigg Date: Mon, 16 Jan 2023 17:38:08 -0800 Subject: [PATCH 575/757] MavenRunner now uses a single ProcessRunner across an entire test class. --- .../com/diffplug/spotless/ProcessRunner.java | 34 +++++- .../maven/MavenIntegrationHarness.java | 16 +++ .../diffplug/spotless/maven/MavenRunner.java | 111 +++--------------- 3 files changed, 63 insertions(+), 98 deletions(-) diff --git a/lib/src/main/java/com/diffplug/spotless/ProcessRunner.java b/lib/src/main/java/com/diffplug/spotless/ProcessRunner.java index c798ed6c07..7a1d0ac774 100644 --- a/lib/src/main/java/com/diffplug/spotless/ProcessRunner.java +++ b/lib/src/main/java/com/diffplug/spotless/ProcessRunner.java @@ -1,5 +1,5 @@ /* - * Copyright 2020-2021 DiffPlug + * Copyright 2020-2023 DiffPlug * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -16,10 +16,12 @@ package com.diffplug.spotless; import java.io.ByteArrayOutputStream; +import java.io.File; import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; import java.nio.charset.Charset; +import java.nio.charset.StandardCharsets; import java.util.Arrays; import java.util.List; import java.util.concurrent.ExecutionException; @@ -55,13 +57,18 @@ public Result shell(String cmd) throws IOException, InterruptedException { /** Executes the given shell command (using {@code cmd} on windows and {@code sh} on unix). */ public Result shellWinUnix(String cmdWin, String cmdUnix) throws IOException, InterruptedException { + return shellWinUnix(null, cmdWin, cmdUnix); + } + + /** Executes the given shell command (using {@code cmd} on windows and {@code sh} on unix). */ + public Result shellWinUnix(File cwd, String cmdWin, String cmdUnix) throws IOException, InterruptedException { List args; if (FileSignature.machineIsWin()) { args = Arrays.asList("cmd", "/c", cmdWin); } else { args = Arrays.asList("sh", "-c", cmdUnix); } - return exec(args); + return exec(cwd, args); } /** Creates a process with the given arguments. */ @@ -76,12 +83,25 @@ public Result exec(byte[] stdin, String... args) throws IOException, Interrupted /** Creates a process with the given arguments. */ public Result exec(List args) throws IOException, InterruptedException { - return exec(new byte[0], args); + return exec((File) null, args); + } + + /** Creates a process with the given arguments. */ + public Result exec(File cwd, List args) throws IOException, InterruptedException { + return exec(cwd, new byte[0], args); } /** Creates a process with the given arguments, the given byte array is written to stdin immediately. */ public Result exec(byte[] stdin, List args) throws IOException, InterruptedException { + return exec(null, stdin, args); + } + + /** Creates a process with the given arguments, the given byte array is written to stdin immediately. */ + public Result exec(File cwd, byte[] stdin, List args) throws IOException, InterruptedException { ProcessBuilder builder = new ProcessBuilder(args); + if (cwd != null) { + builder.directory(cwd); + } Process process = builder.start(); Future outputFut = threadStdOut.submit(() -> drainToBytes(process.getInputStream(), bufStdOut)); Future errorFut = threadStdErr.submit(() -> drainToBytes(process.getErrorStream(), bufStdErr)); @@ -147,6 +167,14 @@ public byte[] stdErr() { return stdErr; } + public String stdOutUtf8() { + return new String(stdOut, StandardCharsets.UTF_8); + } + + public String stdErrUtf8() { + return new String(stdErr, StandardCharsets.UTF_8); + } + /** Returns true if the exit code was not zero. */ public boolean exitNotZero() { return exitCode != 0; diff --git a/plugin-maven/src/test/java/com/diffplug/spotless/maven/MavenIntegrationHarness.java b/plugin-maven/src/test/java/com/diffplug/spotless/maven/MavenIntegrationHarness.java index 15c504fc72..1c44eef55e 100644 --- a/plugin-maven/src/test/java/com/diffplug/spotless/maven/MavenIntegrationHarness.java +++ b/plugin-maven/src/test/java/com/diffplug/spotless/maven/MavenIntegrationHarness.java @@ -31,6 +31,8 @@ import java.nio.file.Path; import java.util.*; +import org.junit.jupiter.api.AfterAll; +import org.junit.jupiter.api.BeforeAll; import org.junit.jupiter.api.BeforeEach; import com.github.mustachejava.DefaultMustacheFactory; @@ -40,6 +42,7 @@ import com.diffplug.common.base.Unhandled; import com.diffplug.common.io.Resources; import com.diffplug.spotless.Jvm; +import com.diffplug.spotless.ProcessRunner; import com.diffplug.spotless.ResourceHarness; public class MavenIntegrationHarness extends ResourceHarness { @@ -175,9 +178,22 @@ protected void writePom(String[] executions, String[] configuration, String[] de protected MavenRunner mavenRunner() throws IOException { return MavenRunner.create() + .withRunner(runner) .withProjectDir(rootFolder()); } + private static ProcessRunner runner; + + @BeforeAll + static void setupRunner() throws IOException { + runner = new ProcessRunner(); + } + + @AfterAll + static void closeRunner() throws IOException { + runner.close(); + } + /** * Useful for local development. Allows debugging the Spotless Maven Plugin remotely. * Effectively translates into running {@code mvnDebug} on port 5005. The forked JVM will be diff --git a/plugin-maven/src/test/java/com/diffplug/spotless/maven/MavenRunner.java b/plugin-maven/src/test/java/com/diffplug/spotless/maven/MavenRunner.java index b5e2392a24..4fe454ceba 100644 --- a/plugin-maven/src/test/java/com/diffplug/spotless/maven/MavenRunner.java +++ b/plugin-maven/src/test/java/com/diffplug/spotless/maven/MavenRunner.java @@ -17,21 +17,15 @@ import static org.assertj.core.api.Assertions.assertThat; -import java.io.ByteArrayOutputStream; import java.io.File; import java.io.IOException; -import java.io.InputStream; -import java.nio.charset.Charset; import java.util.Arrays; import java.util.HashMap; -import java.util.List; import java.util.Map; import java.util.Objects; -import com.diffplug.common.base.Throwables; -import com.diffplug.common.io.ByteStreams; -import com.diffplug.spotless.FileSignature; import com.diffplug.spotless.Jvm; +import com.diffplug.spotless.ProcessRunner; /** * Harness for running a maven build, same idea as the @@ -47,6 +41,7 @@ private MavenRunner() {} private File projectDir; private String[] args; private Map environment = new HashMap<>(); + private ProcessRunner runner; public MavenRunner withProjectDir(File projectDir) { this.projectDir = Objects.requireNonNull(projectDir); @@ -58,110 +53,36 @@ public MavenRunner withArguments(String... args) { return this; } + public MavenRunner withRunner(ProcessRunner runner) { + this.runner = runner; + return this; + } + public MavenRunner withRemoteDebug(int port) { String address = (Jvm.version() < 9 ? "" : "*:") + port; environment.put("MAVEN_OPTS", "-agentlib:jdwp=transport=dt_socket,server=y,suspend=y,address=" + address); return this; } - private Result run() throws IOException, InterruptedException { + private ProcessRunner.Result run() throws IOException, InterruptedException { Objects.requireNonNull(projectDir, "Need to call withProjectDir() first"); Objects.requireNonNull(args, "Need to call withArguments() first"); // run maven with the given args in the given directory - String argsString = String.join(" ", Arrays.asList(args)); - List cmds = getPlatformCmds("-e " + argsString); - ProcessBuilder builder = new ProcessBuilder(cmds); - builder.directory(projectDir); - builder.environment().putAll(environment); - Process process = builder.start(); - // slurp and return the stdout, stderr, and exitValue - Slurper output = new Slurper(process.getInputStream()); - Slurper error = new Slurper(process.getErrorStream()); - int exitValue = process.waitFor(); - output.join(); - error.join(); - return new Result(exitValue, output.result(), error.result()); + String argsString = "-e " + String.join(" ", Arrays.asList(args)); + return runner.shellWinUnix(projectDir, "mvnw " + argsString, "./mvnw " + argsString); } /** Runs the command and asserts that exit code is 0. */ - public Result runNoError() throws IOException, InterruptedException { - Result result = run(); - assertThat(result.exitValue()).as("Run without error %s", result).isEqualTo(0); + public ProcessRunner.Result runNoError() throws IOException, InterruptedException { + ProcessRunner.Result result = run(); + assertThat(result.exitCode()).as("Run without error %s", result).isEqualTo(0); return result; } /** Runs the command and asserts that exit code is not 0. */ - public Result runHasError() throws IOException, InterruptedException { - Result result = run(); - assertThat(result.exitValue()).as("Run with error %s", result).isNotEqualTo(0); + public ProcessRunner.Result runHasError() throws IOException, InterruptedException { + ProcessRunner.Result result = run(); + assertThat(result.exitCode()).as("Run with error %s", result).isNotEqualTo(0); return result; } - - public static class Result { - private final int exitValue; - private final String output; - private final String error; - - public Result(int exitValue, String output, String error) { - super(); - this.exitValue = exitValue; - this.output = Objects.requireNonNull(output); - this.error = Objects.requireNonNull(error); - } - - public int exitValue() { - return exitValue; - } - - public String output() { - return output; - } - - public String error() { - return error; - } - - @Override - public String toString() { - return "Result{" + - "exitValue=" + exitValue + - ", output='" + output + '\'' + - ", error='" + error + '\'' + - '}'; - } - } - - /** Prepends any arguments necessary to run a console command. */ - private static List getPlatformCmds(String cmd) { - if (FileSignature.machineIsWin()) { - return Arrays.asList("cmd", "/c", "mvnw " + cmd); - } else { - return Arrays.asList("/bin/sh", "-c", "./mvnw " + cmd); - } - } - - private static class Slurper extends Thread { - private final InputStream input; - private volatile String result; - - Slurper(InputStream input) { - this.input = Objects.requireNonNull(input); - start(); - } - - @Override - public void run() { - try { - ByteArrayOutputStream output = new ByteArrayOutputStream(); - ByteStreams.copy(input, output); - result = output.toString(Charset.defaultCharset().name()); - } catch (Exception e) { - result = Throwables.getStackTraceAsString(e); - } - } - - public String result() { - return result; - } - } } From b314a0126abd90098e1c4d79dacd9ccd551cb35b Mon Sep 17 00:00:00 2001 From: Ned Twigg Date: Mon, 16 Jan 2023 17:38:26 -0800 Subject: [PATCH 576/757] Adapt maven tests to use ProcessRunner. --- .../spotless/maven/SpotlessCheckMojoTest.java | 8 +++++--- .../maven/incremental/UpToDateCheckingTest.java | 8 ++++---- .../javascript/JavascriptFormatStepTest.java | 5 ++--- .../diffplug/spotless/maven/json/JsonTest.java | 2 +- .../maven/markdown/FlexmarkMavenTest.java | 5 ++--- .../spotless/maven/pom/SortPomMavenTest.java | 4 ++-- .../maven/prettier/PrettierFormatStepTest.java | 16 ++++++++-------- .../typescript/TypescriptFormatStepTest.java | 16 ++++++++-------- .../diffplug/spotless/maven/yaml/YamlTest.java | 6 +++--- 9 files changed, 35 insertions(+), 35 deletions(-) diff --git a/plugin-maven/src/test/java/com/diffplug/spotless/maven/SpotlessCheckMojoTest.java b/plugin-maven/src/test/java/com/diffplug/spotless/maven/SpotlessCheckMojoTest.java index cb37e4a4c5..566851c26c 100644 --- a/plugin-maven/src/test/java/com/diffplug/spotless/maven/SpotlessCheckMojoTest.java +++ b/plugin-maven/src/test/java/com/diffplug/spotless/maven/SpotlessCheckMojoTest.java @@ -1,5 +1,5 @@ /* - * Copyright 2016-2022 DiffPlug + * Copyright 2016-2023 DiffPlug * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -21,6 +21,8 @@ import org.junit.jupiter.api.Test; +import com.diffplug.spotless.ProcessRunner; + class SpotlessCheckMojoTest extends MavenIntegrationHarness { private static final String UNFORMATTED_FILE = "license/MissingLicense.test"; @@ -72,8 +74,8 @@ private void testSpotlessCheck(String fileName, String command, boolean expectEr MavenRunner mavenRunner = mavenRunner().withArguments(command); if (expectError) { - MavenRunner.Result result = mavenRunner.runHasError(); - assertThat(result.output()).contains("The following files had format violations"); + ProcessRunner.Result result = mavenRunner.runHasError(); + assertThat(result.stdOutUtf8()).contains("The following files had format violations"); } else { mavenRunner.runNoError(); } diff --git a/plugin-maven/src/test/java/com/diffplug/spotless/maven/incremental/UpToDateCheckingTest.java b/plugin-maven/src/test/java/com/diffplug/spotless/maven/incremental/UpToDateCheckingTest.java index f315c7eefe..6afcba7430 100644 --- a/plugin-maven/src/test/java/com/diffplug/spotless/maven/incremental/UpToDateCheckingTest.java +++ b/plugin-maven/src/test/java/com/diffplug/spotless/maven/incremental/UpToDateCheckingTest.java @@ -1,5 +1,5 @@ /* - * Copyright 2021-2022 DiffPlug + * Copyright 2021-2023 DiffPlug * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -254,15 +254,15 @@ private List writeFiles(String resource, String suffix, int count) throws } private String runSpotlessApply() throws Exception { - return mavenRunnerForGoal("apply").runNoError().output(); + return mavenRunnerForGoal("apply").runNoError().stdOutUtf8(); } private String runSpotlessCheck() throws Exception { - return mavenRunnerForGoal("check").runNoError().output(); + return mavenRunnerForGoal("check").runNoError().stdOutUtf8(); } private String runSpotlessCheckOnUnformattedFiles() throws Exception { - return mavenRunnerForGoal("check").runHasError().output(); + return mavenRunnerForGoal("check").runHasError().stdOutUtf8(); } private MavenRunner mavenRunnerForGoal(String goal) throws IOException { diff --git a/plugin-maven/src/test/java/com/diffplug/spotless/maven/javascript/JavascriptFormatStepTest.java b/plugin-maven/src/test/java/com/diffplug/spotless/maven/javascript/JavascriptFormatStepTest.java index 5c8a5f04b3..d738e17dac 100644 --- a/plugin-maven/src/test/java/com/diffplug/spotless/maven/javascript/JavascriptFormatStepTest.java +++ b/plugin-maven/src/test/java/com/diffplug/spotless/maven/javascript/JavascriptFormatStepTest.java @@ -20,9 +20,9 @@ import org.junit.jupiter.params.ParameterizedTest; import org.junit.jupiter.params.provider.ValueSource; +import com.diffplug.spotless.ProcessRunner; import com.diffplug.spotless.ResourceHarness; import com.diffplug.spotless.maven.MavenIntegrationHarness; -import com.diffplug.spotless.maven.MavenRunner.Result; import com.diffplug.spotless.npm.EslintFormatterStep; import com.diffplug.spotless.npm.EslintStyleGuide; import com.diffplug.spotless.tag.NpmTest; @@ -50,8 +50,7 @@ void eslintConfigFile() throws Exception { setFile(".eslintrc.js").toResource("npm/eslint/javascript/custom_rules/.eslintrc.js"); setFile(TEST_FILE_PATH).toResource("npm/eslint/javascript/custom_rules/javascript-es6.dirty"); - Result result = mavenRunner().withArguments("spotless:apply").runNoError(); - System.out.println(result.output()); + ProcessRunner.Result result = mavenRunner().withArguments("spotless:apply").runNoError(); assertFile(TEST_FILE_PATH).sameAsResource("npm/eslint/javascript/custom_rules/javascript-es6.clean"); } diff --git a/plugin-maven/src/test/java/com/diffplug/spotless/maven/json/JsonTest.java b/plugin-maven/src/test/java/com/diffplug/spotless/maven/json/JsonTest.java index e492109faa..884aba79c7 100644 --- a/plugin-maven/src/test/java/com/diffplug/spotless/maven/json/JsonTest.java +++ b/plugin-maven/src/test/java/com/diffplug/spotless/maven/json/JsonTest.java @@ -57,7 +57,7 @@ public void testFormatJson_WithGson_sortByKeys() throws Exception { setFile("json_test.json").toResource("json/sortByKeysBefore.json"); - String output = mavenRunner().withArguments("spotless:apply").runNoError().output(); + String output = mavenRunner().withArguments("spotless:apply").runNoError().stdOutUtf8(); LOGGER.error(output); System.err.println(output); assertFile("json_test.json").sameAsResource("json/sortByKeysAfter.json"); diff --git a/plugin-maven/src/test/java/com/diffplug/spotless/maven/markdown/FlexmarkMavenTest.java b/plugin-maven/src/test/java/com/diffplug/spotless/maven/markdown/FlexmarkMavenTest.java index a623ca7f3c..eb1c6cc95f 100644 --- a/plugin-maven/src/test/java/com/diffplug/spotless/maven/markdown/FlexmarkMavenTest.java +++ b/plugin-maven/src/test/java/com/diffplug/spotless/maven/markdown/FlexmarkMavenTest.java @@ -1,5 +1,5 @@ /* - * Copyright 2021 DiffPlug + * Copyright 2021-2023 DiffPlug * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -26,8 +26,7 @@ public void testFlexmarkWithDefaultConfig() throws Exception { writePomWithMarkdownSteps(""); setFile("markdown_test.md").toResource("markdown/flexmark/FlexmarkUnformatted.md"); - mavenRunner().withArguments("spotless:apply").runNoError().error(); + mavenRunner().withArguments("spotless:apply").runNoError(); assertFile("markdown_test.md").sameAsResource("markdown/flexmark/FlexmarkFormatted.md"); } - } diff --git a/plugin-maven/src/test/java/com/diffplug/spotless/maven/pom/SortPomMavenTest.java b/plugin-maven/src/test/java/com/diffplug/spotless/maven/pom/SortPomMavenTest.java index ca9d77a6e3..93eb8a9633 100644 --- a/plugin-maven/src/test/java/com/diffplug/spotless/maven/pom/SortPomMavenTest.java +++ b/plugin-maven/src/test/java/com/diffplug/spotless/maven/pom/SortPomMavenTest.java @@ -1,5 +1,5 @@ /* - * Copyright 2021 DiffPlug + * Copyright 2021-2023 DiffPlug * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -25,7 +25,7 @@ public void testSortPomWithDefaultConfig() throws Exception { writePomWithPomSteps(""); setFile("pom_test.xml").toResource("pom/pom_dirty.xml"); - mavenRunner().withArguments("spotless:apply").runNoError().error(); + mavenRunner().withArguments("spotless:apply").runNoError(); assertFile("pom_test.xml").sameAsResource("pom/pom_clean_default.xml"); } } diff --git a/plugin-maven/src/test/java/com/diffplug/spotless/maven/prettier/PrettierFormatStepTest.java b/plugin-maven/src/test/java/com/diffplug/spotless/maven/prettier/PrettierFormatStepTest.java index c0a9267b93..47dab5d152 100644 --- a/plugin-maven/src/test/java/com/diffplug/spotless/maven/prettier/PrettierFormatStepTest.java +++ b/plugin-maven/src/test/java/com/diffplug/spotless/maven/prettier/PrettierFormatStepTest.java @@ -21,8 +21,8 @@ import org.junit.jupiter.api.Test; +import com.diffplug.spotless.ProcessRunner; import com.diffplug.spotless.maven.MavenIntegrationHarness; -import com.diffplug.spotless.maven.MavenRunner.Result; import com.diffplug.spotless.maven.generic.Prettier; import com.diffplug.spotless.tag.NpmTest; @@ -43,7 +43,7 @@ private String prepareRun(String kind, String suffix) throws IOException { return path; } - private Result runExpectingError(String kind, String suffix) throws IOException, InterruptedException { + private ProcessRunner.Result runExpectingError(String kind, String suffix) throws IOException, InterruptedException { String path = prepareRun(kind, suffix); return mavenRunner().withArguments("spotless:apply").runHasError(); } @@ -102,8 +102,8 @@ void unique_dependency_config() throws Exception { " 1.16.4", ""); - Result result = mavenRunner().withArguments("spotless:apply").runHasError(); - assertThat(result.output()).contains(Prettier.ERROR_MESSAGE_ONLY_ONE_CONFIG); + ProcessRunner.Result result = mavenRunner().withArguments("spotless:apply").runHasError(); + assertThat(result.stdOutUtf8()).contains(Prettier.ERROR_MESSAGE_ONLY_ONE_CONFIG); } @Test @@ -156,8 +156,8 @@ void autodetect_npmrc_file() throws Exception { " 1.16.4", " .prettierrc.yml", ""); - Result result = runExpectingError("typescript", suffix); - assertThat(result.output()).containsPattern("Running npm command.*npm install.* failed with exit code: 1"); + ProcessRunner.Result result = runExpectingError("typescript", suffix); + assertThat(result.stdOutUtf8()).containsPattern("Running npm command.*npm install.* failed with exit code: 1"); } @Test @@ -174,7 +174,7 @@ void select_configured_npmrc_file() throws Exception { " .prettierrc.yml", " ${basedir}/.custom_npmrc", ""); - Result result = runExpectingError("typescript", suffix); - assertThat(result.output()).containsPattern("Running npm command.*npm install.* failed with exit code: 1"); + ProcessRunner.Result result = runExpectingError("typescript", suffix); + assertThat(result.stdOutUtf8()).containsPattern("Running npm command.*npm install.* failed with exit code: 1"); } } diff --git a/plugin-maven/src/test/java/com/diffplug/spotless/maven/typescript/TypescriptFormatStepTest.java b/plugin-maven/src/test/java/com/diffplug/spotless/maven/typescript/TypescriptFormatStepTest.java index 95097fe467..a09111d30d 100644 --- a/plugin-maven/src/test/java/com/diffplug/spotless/maven/typescript/TypescriptFormatStepTest.java +++ b/plugin-maven/src/test/java/com/diffplug/spotless/maven/typescript/TypescriptFormatStepTest.java @@ -21,9 +21,9 @@ import org.junit.jupiter.api.Test; +import com.diffplug.spotless.ProcessRunner; import com.diffplug.spotless.ResourceHarness; import com.diffplug.spotless.maven.MavenIntegrationHarness; -import com.diffplug.spotless.maven.MavenRunner.Result; import com.diffplug.spotless.npm.EslintFormatterStep; import com.diffplug.spotless.npm.EslintStyleGuide; import com.diffplug.spotless.tag.NpmTest; @@ -48,7 +48,7 @@ private String prepareRunTsfmt(String kind) throws IOException { return TEST_FILE_PATH; } - private Result runExpectingErrorTsfmt(String kind) throws IOException, InterruptedException { + private ProcessRunner.Result runExpectingErrorTsfmt(String kind) throws IOException, InterruptedException { prepareRunTsfmt(kind); return mavenRunner().withArguments("spotless:apply").runHasError(); } @@ -124,8 +124,8 @@ void testTypescript_2_Configs() throws Exception { setFile("tsfmt.json").toResource("npm/tsfmt/tsfmt/tsfmt.json"); setFile(path).toResource("npm/tsfmt/tsfmt/tsfmt.dirty"); - Result result = mavenRunner().withArguments("spotless:apply").runHasError(); - assertThat(result.output()).contains("must specify exactly one configFile or config"); + ProcessRunner.Result result = mavenRunner().withArguments("spotless:apply").runHasError(); + assertThat(result.stdOutUtf8()).contains("must specify exactly one configFile or config"); } @Test @@ -141,8 +141,8 @@ void testNpmrcIsAutoPickedUp() throws Exception { " ${basedir}/tslint.json", ""); setFile("tslint.json").toResource("npm/tsfmt/tslint/tslint.json"); - Result result = runExpectingErrorTsfmt("tslint"); - assertThat(result.output()).containsPattern("Running npm command.*npm install.* failed with exit code: 1"); + ProcessRunner.Result result = runExpectingErrorTsfmt("tslint"); + assertThat(result.stdOutUtf8()).containsPattern("Running npm command.*npm install.* failed with exit code: 1"); } @Test @@ -159,8 +159,8 @@ void testNpmrcIsConfigurativelyPickedUp() throws Exception { " ${basedir}/.custom_npmrc", ""); setFile("tslint.json").toResource("npm/tsfmt/tslint/tslint.json"); - Result result = runExpectingErrorTsfmt("tslint"); - assertThat(result.output()).containsPattern("Running npm command.*npm install.* failed with exit code: 1"); + ProcessRunner.Result result = runExpectingErrorTsfmt("tslint"); + assertThat(result.stdOutUtf8()).containsPattern("Running npm command.*npm install.* failed with exit code: 1"); } @Test diff --git a/plugin-maven/src/test/java/com/diffplug/spotless/maven/yaml/YamlTest.java b/plugin-maven/src/test/java/com/diffplug/spotless/maven/yaml/YamlTest.java index b5a417c536..f17feeb10a 100644 --- a/plugin-maven/src/test/java/com/diffplug/spotless/maven/yaml/YamlTest.java +++ b/plugin-maven/src/test/java/com/diffplug/spotless/maven/yaml/YamlTest.java @@ -21,8 +21,8 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import com.diffplug.spotless.ProcessRunner; import com.diffplug.spotless.maven.MavenIntegrationHarness; -import com.diffplug.spotless.maven.MavenRunner.Result; public class YamlTest extends MavenIntegrationHarness { private static final Logger LOGGER = LoggerFactory.getLogger(YamlTest.class); @@ -32,9 +32,9 @@ public void testFormatYaml_WithJackson_defaultConfig_separatorComments() throws writePomWithYamlSteps(""); setFile("yaml_test.yaml").toResource("yaml/separator_comments.yaml"); - Result runNoError = mavenRunner().withArguments("spotless:apply").runNoError(); + ProcessRunner.Result runNoError = mavenRunner().withArguments("spotless:apply").runNoError(); LOGGER.error("result: {}", runNoError); - assertThat(runNoError.exitValue()).as("Run without error %s", runNoError).isEqualTo(0); + assertThat(runNoError.exitCode()).as("Run without error %s", runNoError).isEqualTo(0); LOGGER.error("GOGO"); assertFile("yaml_test.yaml").sameAsResource("yaml/separator_comments.clean.yaml"); } From bc4a2684d118b63818803bc1e99417023a229133 Mon Sep 17 00:00:00 2001 From: Ned Twigg Date: Mon, 16 Jan 2023 17:46:43 -0800 Subject: [PATCH 577/757] Add support for environment variables into ProcessRunner so that MavenRunner's support for remote debug works again. --- .../com/diffplug/spotless/ProcessRunner.java | 21 +++++++++---------- .../diffplug/spotless/maven/MavenRunner.java | 2 +- 2 files changed, 11 insertions(+), 12 deletions(-) diff --git a/lib/src/main/java/com/diffplug/spotless/ProcessRunner.java b/lib/src/main/java/com/diffplug/spotless/ProcessRunner.java index 7a1d0ac774..e2149a03d6 100644 --- a/lib/src/main/java/com/diffplug/spotless/ProcessRunner.java +++ b/lib/src/main/java/com/diffplug/spotless/ProcessRunner.java @@ -24,6 +24,7 @@ import java.nio.charset.StandardCharsets; import java.util.Arrays; import java.util.List; +import java.util.Map; import java.util.concurrent.ExecutionException; import java.util.concurrent.ExecutorService; import java.util.concurrent.Executors; @@ -57,18 +58,18 @@ public Result shell(String cmd) throws IOException, InterruptedException { /** Executes the given shell command (using {@code cmd} on windows and {@code sh} on unix). */ public Result shellWinUnix(String cmdWin, String cmdUnix) throws IOException, InterruptedException { - return shellWinUnix(null, cmdWin, cmdUnix); + return shellWinUnix(null, null, cmdWin, cmdUnix); } /** Executes the given shell command (using {@code cmd} on windows and {@code sh} on unix). */ - public Result shellWinUnix(File cwd, String cmdWin, String cmdUnix) throws IOException, InterruptedException { + public Result shellWinUnix(File cwd, Map environment, String cmdWin, String cmdUnix) throws IOException, InterruptedException { List args; if (FileSignature.machineIsWin()) { args = Arrays.asList("cmd", "/c", cmdWin); } else { args = Arrays.asList("sh", "-c", cmdUnix); } - return exec(cwd, args); + return exec(cwd, environment, new byte[0], args); } /** Creates a process with the given arguments. */ @@ -83,25 +84,23 @@ public Result exec(byte[] stdin, String... args) throws IOException, Interrupted /** Creates a process with the given arguments. */ public Result exec(List args) throws IOException, InterruptedException { - return exec((File) null, args); - } - - /** Creates a process with the given arguments. */ - public Result exec(File cwd, List args) throws IOException, InterruptedException { - return exec(cwd, new byte[0], args); + return exec(null, args); } /** Creates a process with the given arguments, the given byte array is written to stdin immediately. */ public Result exec(byte[] stdin, List args) throws IOException, InterruptedException { - return exec(null, stdin, args); + return exec(null, null, stdin, args); } /** Creates a process with the given arguments, the given byte array is written to stdin immediately. */ - public Result exec(File cwd, byte[] stdin, List args) throws IOException, InterruptedException { + public Result exec(File cwd, Map environment, byte[] stdin, List args) throws IOException, InterruptedException { ProcessBuilder builder = new ProcessBuilder(args); if (cwd != null) { builder.directory(cwd); } + if (environment != null) { + builder.environment().putAll(environment); + } Process process = builder.start(); Future outputFut = threadStdOut.submit(() -> drainToBytes(process.getInputStream(), bufStdOut)); Future errorFut = threadStdErr.submit(() -> drainToBytes(process.getErrorStream(), bufStdErr)); diff --git a/plugin-maven/src/test/java/com/diffplug/spotless/maven/MavenRunner.java b/plugin-maven/src/test/java/com/diffplug/spotless/maven/MavenRunner.java index 4fe454ceba..d878b18c5f 100644 --- a/plugin-maven/src/test/java/com/diffplug/spotless/maven/MavenRunner.java +++ b/plugin-maven/src/test/java/com/diffplug/spotless/maven/MavenRunner.java @@ -69,7 +69,7 @@ private ProcessRunner.Result run() throws IOException, InterruptedException { Objects.requireNonNull(args, "Need to call withArguments() first"); // run maven with the given args in the given directory String argsString = "-e " + String.join(" ", Arrays.asList(args)); - return runner.shellWinUnix(projectDir, "mvnw " + argsString, "./mvnw " + argsString); + return runner.shellWinUnix(projectDir, environment, "mvnw " + argsString, "./mvnw " + argsString); } /** Runs the command and asserts that exit code is 0. */ From 7b5f01949713ea90dbc6928346545d15c704a1f2 Mon Sep 17 00:00:00 2001 From: Ned Twigg Date: Mon, 16 Jan 2023 17:49:33 -0800 Subject: [PATCH 578/757] Fix a bug in how ProcessRunner handled null stdin. --- lib/src/main/java/com/diffplug/spotless/ProcessRunner.java | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/lib/src/main/java/com/diffplug/spotless/ProcessRunner.java b/lib/src/main/java/com/diffplug/spotless/ProcessRunner.java index e2149a03d6..1356c0ac0d 100644 --- a/lib/src/main/java/com/diffplug/spotless/ProcessRunner.java +++ b/lib/src/main/java/com/diffplug/spotless/ProcessRunner.java @@ -69,7 +69,7 @@ public Result shellWinUnix(File cwd, Map environment, String cmd } else { args = Arrays.asList("sh", "-c", cmdUnix); } - return exec(cwd, environment, new byte[0], args); + return exec(cwd, environment, null, args); } /** Creates a process with the given arguments. */ @@ -101,6 +101,9 @@ public Result exec(File cwd, Map environment, byte[] stdin, List if (environment != null) { builder.environment().putAll(environment); } + if (stdin == null) { + stdin = new byte[0]; + } Process process = builder.start(); Future outputFut = threadStdOut.submit(() -> drainToBytes(process.getInputStream(), bufStdOut)); Future errorFut = threadStdErr.submit(() -> drainToBytes(process.getErrorStream(), bufStdErr)); From 9d894cd364bcb20bc38d1f22a61e1f37b956f870 Mon Sep 17 00:00:00 2001 From: Ned Twigg Date: Mon, 16 Jan 2023 17:52:02 -0800 Subject: [PATCH 579/757] Update the core changelog since ProcessRunner has gotten a few new methods. --- CHANGES.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/CHANGES.md b/CHANGES.md index c08ca86796..bff243b753 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -10,6 +10,8 @@ This document is intended for Spotless developers. We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format (starting after version `1.27.0`). ## [Unreleased] +### Added +* `ProcessRunner` has added some convenience methods so it can be used for maven testing. ([#1496](https://github.com/diffplug/spotless/pull/1496)) ## [2.32.0] - 2023-01-13 ### Added From 86c613b08be06ff9dab3a59e1dcc7e1227e59d91 Mon Sep 17 00:00:00 2001 From: Ned Twigg Date: Mon, 16 Jan 2023 17:54:36 -0800 Subject: [PATCH 580/757] Small tweak to reduce diff. --- .../com/diffplug/spotless/maven/MavenIntegrationHarness.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/plugin-maven/src/test/java/com/diffplug/spotless/maven/MavenIntegrationHarness.java b/plugin-maven/src/test/java/com/diffplug/spotless/maven/MavenIntegrationHarness.java index 1c44eef55e..5a724408c8 100644 --- a/plugin-maven/src/test/java/com/diffplug/spotless/maven/MavenIntegrationHarness.java +++ b/plugin-maven/src/test/java/com/diffplug/spotless/maven/MavenIntegrationHarness.java @@ -178,8 +178,8 @@ protected void writePom(String[] executions, String[] configuration, String[] de protected MavenRunner mavenRunner() throws IOException { return MavenRunner.create() - .withRunner(runner) - .withProjectDir(rootFolder()); + .withProjectDir(rootFolder()) + .withRunner(runner); } private static ProcessRunner runner; From aa0c878c8817ef0afcc192e1e5257a3e3d7e83f7 Mon Sep 17 00:00:00 2001 From: Ned Twigg Date: Mon, 16 Jan 2023 17:57:18 -0800 Subject: [PATCH 581/757] Fix spotbugs warning. --- .../main/java/com/diffplug/spotless/ProcessRunner.java | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/lib/src/main/java/com/diffplug/spotless/ProcessRunner.java b/lib/src/main/java/com/diffplug/spotless/ProcessRunner.java index 1356c0ac0d..41c664cafe 100644 --- a/lib/src/main/java/com/diffplug/spotless/ProcessRunner.java +++ b/lib/src/main/java/com/diffplug/spotless/ProcessRunner.java @@ -31,6 +31,7 @@ import java.util.concurrent.Future; import java.util.function.BiConsumer; +import edu.umd.cs.findbugs.annotations.Nullable; import edu.umd.cs.findbugs.annotations.SuppressFBWarnings; /** @@ -62,7 +63,7 @@ public Result shellWinUnix(String cmdWin, String cmdUnix) throws IOException, In } /** Executes the given shell command (using {@code cmd} on windows and {@code sh} on unix). */ - public Result shellWinUnix(File cwd, Map environment, String cmdWin, String cmdUnix) throws IOException, InterruptedException { + public Result shellWinUnix(@Nullable File cwd, @Nullable Map environment, String cmdWin, String cmdUnix) throws IOException, InterruptedException { List args; if (FileSignature.machineIsWin()) { args = Arrays.asList("cmd", "/c", cmdWin); @@ -78,7 +79,7 @@ public Result exec(String... args) throws IOException, InterruptedException { } /** Creates a process with the given arguments, the given byte array is written to stdin immediately. */ - public Result exec(byte[] stdin, String... args) throws IOException, InterruptedException { + public Result exec(@Nullable byte[] stdin, String... args) throws IOException, InterruptedException { return exec(stdin, Arrays.asList(args)); } @@ -88,12 +89,12 @@ public Result exec(List args) throws IOException, InterruptedException { } /** Creates a process with the given arguments, the given byte array is written to stdin immediately. */ - public Result exec(byte[] stdin, List args) throws IOException, InterruptedException { + public Result exec(@Nullable byte[] stdin, List args) throws IOException, InterruptedException { return exec(null, null, stdin, args); } /** Creates a process with the given arguments, the given byte array is written to stdin immediately. */ - public Result exec(File cwd, Map environment, byte[] stdin, List args) throws IOException, InterruptedException { + public Result exec(@Nullable File cwd, @Nullable Map environment, @Nullable byte[] stdin, List args) throws IOException, InterruptedException { ProcessBuilder builder = new ProcessBuilder(args); if (cwd != null) { builder.directory(cwd); From e9bea7e369cd2b1bbbda8d5cda958d2f74b1a6a7 Mon Sep 17 00:00:00 2001 From: "renovate[bot]" <29139614+renovate[bot]@users.noreply.github.com> Date: Tue, 17 Jan 2023 03:02:14 +0000 Subject: [PATCH 582/757] fix(deps): update dependency org.assertj:assertj-core to v3.24.2 --- gradle.properties | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gradle.properties b/gradle.properties index 71f755522f..ecf51ea654 100644 --- a/gradle.properties +++ b/gradle.properties @@ -27,7 +27,7 @@ VER_SLF4J=[1.6,2.0[ VER_DURIAN=1.2.0 VER_JGIT=5.13.1.202206130422-r VER_JUNIT=5.9.2 -VER_ASSERTJ=3.24.1 +VER_ASSERTJ=3.24.2 VER_MOCKITO=4.11.0 # Used for Maven Plugin From c51331dc79298ba3a2cdf6356ddcb405dfd65ef1 Mon Sep 17 00:00:00 2001 From: Ned Twigg Date: Mon, 16 Jan 2023 22:47:38 -0800 Subject: [PATCH 583/757] Centralize test configuration into `special-tests` and make sure it doesn't get overwritten. --- lib-extra/build.gradle | 4 ++-- lib/build.gradle | 5 +---- plugin-gradle/build.gradle | 6 ++---- plugin-maven/build.gradle | 2 -- testlib/build.gradle | 16 ---------------- 5 files changed, 5 insertions(+), 28 deletions(-) diff --git a/lib-extra/build.gradle b/lib-extra/build.gradle index d94992f8d3..08bf286d8d 100644 --- a/lib-extra/build.gradle +++ b/lib-extra/build.gradle @@ -25,8 +25,8 @@ dependencies { // we'll hold the core lib to a high standard spotbugs { reportLevel = 'low' } // low|medium|high (low = sensitive to even minor mistakes) -test { - useJUnitPlatform() +apply from: rootProject.file('gradle/special-tests.gradle') +tasks.named('test') { if (JavaVersion.current().isCompatibleWith(JavaVersion.VERSION_16)) { // needed for EclipseCdtFormatterStepTest jvmArgs '--add-opens=java.base/java.lang=ALL-UNNAMED' diff --git a/lib/build.gradle b/lib/build.gradle index 3ef2064765..e7b0298132 100644 --- a/lib/build.gradle +++ b/lib/build.gradle @@ -112,10 +112,7 @@ dependencies { // we'll hold the core lib to a high standard spotbugs { reportLevel = 'low' } // low|medium|high (low = sensitive to even minor mistakes) -tasks.withType(Test).configureEach { - useJUnitPlatform() -} - +apply from: rootProject.file('gradle/special-tests.gradle') jar { for (glue in NEEDS_GLUE) { from sourceSets.getByName(glue).output.classesDirs diff --git a/plugin-gradle/build.gradle b/plugin-gradle/build.gradle index 8a3260d943..11258db0e6 100644 --- a/plugin-gradle/build.gradle +++ b/plugin-gradle/build.gradle @@ -27,13 +27,11 @@ dependencies { testImplementation "com.diffplug.durian:durian-testlib:${VER_DURIAN}" } -test { - useJUnitPlatform() +apply from: rootProject.file('gradle/special-tests.gradle') +tasks.named('test') { testLogging.showStandardStreams = true } -apply from: rootProject.file('gradle/special-tests.gradle') - ////////////////////////// // GRADLE PLUGIN PORTAL // ////////////////////////// diff --git a/plugin-maven/build.gradle b/plugin-maven/build.gradle index e06fce9ace..b46cdda708 100644 --- a/plugin-maven/build.gradle +++ b/plugin-maven/build.gradle @@ -67,9 +67,7 @@ dependencies { } apply from: rootProject.file('gradle/special-tests.gradle') - tasks.withType(Test).configureEach { - useJUnitPlatform() systemProperty 'spotlessMavenPluginVersion', project.version dependsOn 'publishToMavenLocal' dependsOn ':lib:publishToMavenLocal' diff --git a/testlib/build.gradle b/testlib/build.gradle index 30c44ece23..4b16572a8c 100644 --- a/testlib/build.gradle +++ b/testlib/build.gradle @@ -21,22 +21,6 @@ dependencies { // we'll hold the testlib to a low standard (prize brevity) spotbugs { reportLevel = 'high' } // low|medium|high (low = sensitive to even minor mistakes) -test { - useJUnitPlatform() - if (JavaVersion.current().isCompatibleWith(JavaVersion.VERSION_16)) { - // for GJF https://github.com/diffplug/spotless/issues/834 - def args = [ - '--add-exports=jdk.compiler/com.sun.tools.javac.api=ALL-UNNAMED', - '--add-exports=jdk.compiler/com.sun.tools.javac.file=ALL-UNNAMED', - '--add-exports=jdk.compiler/com.sun.tools.javac.parser=ALL-UNNAMED', - '--add-exports=jdk.compiler/com.sun.tools.javac.tree=ALL-UNNAMED', - '--add-exports=jdk.compiler/com.sun.tools.javac.util=ALL-UNNAMED', - '--add-opens=java.base/java.lang=ALL-UNNAMED' - ] - jvmArgs args - } -} - apply from: rootProject.file('gradle/special-tests.gradle') javadoc { From 5e1a0e97ed6d53f3694309e161460b459e9cb802 Mon Sep 17 00:00:00 2001 From: Benoit Lacelle Date: Tue, 17 Jan 2023 12:53:20 +0400 Subject: [PATCH 584/757] Jackson - Yaml starts diverging to enable yanml-specific options --- .../glue/json/JacksonJsonFormatterFunc.java | 40 ++++----- .../glue/yaml/JacksonYamlFormatterFunc.java | 28 +++++-- .../diffplug/spotless/json/JacksonConfig.java | 11 +-- .../spotless/yaml/JacksonYamlConfig.java | 50 ++++++++++++ .../spotless/yaml/JacksonYamlStep.java | 2 +- .../gradle/spotless/JacksonGradleConfig.java | 67 +++++++++++++++ .../gradle/spotless/JsonExtension.java | 23 +++++- .../gradle/spotless/SpotlessExtension.java | 6 ++ .../gradle/spotless/YamlExtension.java | 75 +++++++++++++++++ .../gradle/spotless/YamlExtensionTest.java | 81 +++++++++++++++++++ plugin-maven/CHANGES.md | 7 +- plugin-maven/README.md | 28 +++++-- .../spotless/maven/yaml/JacksonYaml.java | 10 ++- .../spotless/maven/yaml/YamlTest.java | 8 +- ...ay_with_bracket.clean.no_start_marker.yaml | 11 +++ ...th_bracket.clean.spaceBeforeSeparator.yaml | 6 +- 16 files changed, 387 insertions(+), 66 deletions(-) create mode 100644 lib/src/main/java/com/diffplug/spotless/yaml/JacksonYamlConfig.java create mode 100644 plugin-gradle/src/main/java/com/diffplug/gradle/spotless/JacksonGradleConfig.java create mode 100644 plugin-gradle/src/main/java/com/diffplug/gradle/spotless/YamlExtension.java create mode 100644 plugin-gradle/src/test/java/com/diffplug/gradle/spotless/YamlExtensionTest.java create mode 100644 testlib/src/main/resources/yaml/array_with_bracket.clean.no_start_marker.yaml diff --git a/lib/src/jackson/java/com/diffplug/spotless/glue/json/JacksonJsonFormatterFunc.java b/lib/src/jackson/java/com/diffplug/spotless/glue/json/JacksonJsonFormatterFunc.java index c44ff0d0d1..934e60fcd8 100644 --- a/lib/src/jackson/java/com/diffplug/spotless/glue/json/JacksonJsonFormatterFunc.java +++ b/lib/src/jackson/java/com/diffplug/spotless/glue/json/JacksonJsonFormatterFunc.java @@ -18,6 +18,7 @@ import java.io.IOException; import com.fasterxml.jackson.core.JsonFactory; +import com.fasterxml.jackson.core.JsonFactoryBuilder; import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.core.util.DefaultIndenter; import com.fasterxml.jackson.core.util.DefaultPrettyPrinter; @@ -47,12 +48,22 @@ public String apply(String input) throws Exception { return format(objectMapper, input); } + protected String format(ObjectMapper objectMapper, String input) throws IllegalArgumentException, IOException { + try { + ObjectNode objectNode = objectMapper.readValue(input, ObjectNode.class); + return objectMapper.writerWithDefaultPrettyPrinter().writeValueAsString(objectNode); + } catch (JsonProcessingException e) { + throw new AssertionError("Unable to format. input='" + input + "'", e); + } + } + /** * @return a {@link JsonFactory}. May be overridden to handle alternative formats. * @see jackson-dataformats-text */ protected JsonFactory makeJsonFactory() { - return new JsonFactory(); + // We may later accept JsonFactory.Features + return new JsonFactoryBuilder().build(); } protected ObjectMapper makeObjectMapper() { @@ -76,7 +87,9 @@ protected ObjectMapper makeObjectMapper() { protected DefaultPrettyPrinter makePrinter() { boolean spaceBeforeSeparator = jacksonConfig.isSpaceBeforeSeparator(); - DefaultPrettyPrinter.Indenter indenter = new DefaultIndenter(getIndentation(), "\n"); + // DefaultIndenter default constructor relies on 2 whitespaces as default tabulation + // By we want to force '\n' as eol given Spotless provides LF-input (whatever the actual File content/current OS) + DefaultPrettyPrinter.Indenter indenter = new DefaultIndenter(" ", "\n"); DefaultPrettyPrinter printer = new SpotlessDefaultPrettyPrinter(spaceBeforeSeparator); printer.indentObjectsWith(indenter); @@ -84,28 +97,6 @@ protected DefaultPrettyPrinter makePrinter() { return printer; } - protected String getIndentation() { - // DefaultIndenter default constructor relies on this - return " "; - // int indentSpaces = jacksonConfig.getIndentSpaces(); - // if (indentSpaces < 0) { - // return "\t"; - // } else { - // return IntStream.range(0, indentSpaces).mapToObj(i -> "").collect(Collectors.joining()); - // } - } - - protected String format(ObjectMapper objectMapper, String input) throws IllegalArgumentException, IOException { - try { - ObjectNode objectNode = objectMapper.readValue(input, ObjectNode.class); - String outputFromjackson = objectMapper.writeValueAsString(objectNode); - - return outputFromjackson; - } catch (JsonProcessingException e) { - throw new AssertionError("Unable to format. input='" + input + "'", e); - } - } - protected static class SpotlessDefaultPrettyPrinter extends DefaultPrettyPrinter { private static final long serialVersionUID = 1L; private final boolean spaceBeforeSeparator; @@ -123,6 +114,7 @@ public DefaultPrettyPrinter createInstance() { public DefaultPrettyPrinter withSeparators(Separators separators) { this._separators = separators; if (spaceBeforeSeparator) { + // This is Jackson default behavior this._objectFieldValueSeparatorWithSpaces = " " + separators.getObjectFieldValueSeparator() + " "; } else { this._objectFieldValueSeparatorWithSpaces = separators.getObjectFieldValueSeparator() + " "; diff --git a/lib/src/jackson/java/com/diffplug/spotless/glue/yaml/JacksonYamlFormatterFunc.java b/lib/src/jackson/java/com/diffplug/spotless/glue/yaml/JacksonYamlFormatterFunc.java index 6a471a884c..f7686ad503 100644 --- a/lib/src/jackson/java/com/diffplug/spotless/glue/yaml/JacksonYamlFormatterFunc.java +++ b/lib/src/jackson/java/com/diffplug/spotless/glue/yaml/JacksonYamlFormatterFunc.java @@ -17,23 +17,39 @@ import java.io.IOException; +import com.fasterxml.jackson.core.JsonFactory; import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.databind.ObjectMapper; import com.fasterxml.jackson.databind.node.ObjectNode; import com.fasterxml.jackson.dataformat.yaml.YAMLFactory; +import com.fasterxml.jackson.dataformat.yaml.YAMLFactoryBuilder; +import com.fasterxml.jackson.dataformat.yaml.YAMLGenerator; import com.diffplug.spotless.glue.json.JacksonJsonFormatterFunc; -import com.diffplug.spotless.json.JacksonConfig; +import com.diffplug.spotless.yaml.JacksonYamlConfig; public class JacksonYamlFormatterFunc extends JacksonJsonFormatterFunc { + final JacksonYamlConfig yamlConfig; - public JacksonYamlFormatterFunc(JacksonConfig jacksonConfig) { + public JacksonYamlFormatterFunc(JacksonYamlConfig jacksonConfig) { super(jacksonConfig); + this.yamlConfig = jacksonConfig; } - @Override - protected YAMLFactory makeJsonFactory() { - return new YAMLFactory(); + protected JsonFactory makeJsonFactory() { + YAMLFactoryBuilder yamlFactoryBuilder = new YAMLFactoryBuilder(new YAMLFactory()); + + // Configure the ObjectMapper + // https://github.com/FasterXML/jackson-databind#commonly-used-features + yamlConfig.getYamlFeatureToToggle().forEach((rawFeature, toggle) -> { + // https://stackoverflow.com/questions/3735927/java-instantiating-an-enum-using-reflection + // Refers to 'com.fasterxml.jackson.dataformat.yaml.YAMLGenerator.Feature' + YAMLGenerator.Feature feature = YAMLGenerator.Feature.valueOf(rawFeature); + + yamlFactoryBuilder.configure(feature, toggle); + }); + + return yamlFactoryBuilder.build(); } @Override @@ -56,7 +72,7 @@ protected String format(ObjectMapper objectMapper, String input) throws IllegalA //Not 'toPrettyString' as one could require no INDENT_OUTPUT // return jsonNode.toPrettyString(); ObjectNode objectNode = objectMapper.readValue(input, ObjectNode.class); - String outputFromjackson = objectMapper.writeValueAsString(objectNode); + String outputFromjackson = objectMapper.writerWithDefaultPrettyPrinter().writeValueAsString(objectNode); return outputFromjackson; } catch (JsonProcessingException e) { diff --git a/lib/src/main/java/com/diffplug/spotless/json/JacksonConfig.java b/lib/src/main/java/com/diffplug/spotless/json/JacksonConfig.java index 7690913f34..d5ca990b08 100644 --- a/lib/src/main/java/com/diffplug/spotless/json/JacksonConfig.java +++ b/lib/src/main/java/com/diffplug/spotless/json/JacksonConfig.java @@ -31,6 +31,7 @@ public class JacksonConfig implements Serializable { static { Map defaultFeatureToggles = new LinkedHashMap<>(); // We activate by default the PrettyPrinter from Jackson + // @see com.fasterxml.jackson.databind.SerializationFeature.INDENT_OUTPUT defaultFeatureToggles.put("INDENT_OUTPUT", true); DEFAULT_FEATURE_TOGGLES = defaultFeatureToggles; } @@ -41,8 +42,6 @@ public class JacksonConfig implements Serializable { // By default, Jackson adds a ' ' before separator, which is not standard with most IDE/JSON libraries protected boolean spaceBeforeSeparator = false; - // protected int indentSpaces; - public Map getFeatureToToggle() { return Collections.unmodifiableMap(featureToToggle); } @@ -62,12 +61,4 @@ public boolean isSpaceBeforeSeparator() { public void setSpaceBeforeSeparator(boolean spaceBeforeSeparator) { this.spaceBeforeSeparator = spaceBeforeSeparator; } - - // public int getIndentSpaces() { - // return indentSpaces; - // } - - // public void setIndentSpaces(int indentSpaces) { - // this.indentSpaces = indentSpaces; - // } } diff --git a/lib/src/main/java/com/diffplug/spotless/yaml/JacksonYamlConfig.java b/lib/src/main/java/com/diffplug/spotless/yaml/JacksonYamlConfig.java new file mode 100644 index 0000000000..2463b9603f --- /dev/null +++ b/lib/src/main/java/com/diffplug/spotless/yaml/JacksonYamlConfig.java @@ -0,0 +1,50 @@ +/* + * Copyright 2023 DiffPlug + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.diffplug.spotless.yaml; + +import java.util.Collections; +import java.util.LinkedHashMap; +import java.util.Map; + +import com.diffplug.spotless.json.JacksonConfig; + +/** + * Specialization of {@link JacksonConfig} for YAML documents + */ +public class JacksonYamlConfig extends JacksonConfig { + private static final long serialVersionUID = 1L; + + protected Map yamlFeatureToToggle = new LinkedHashMap<>(); + + public Map getYamlFeatureToToggle() { + return Collections.unmodifiableMap(yamlFeatureToToggle); + } + + /** + * @see com.fasterxml.jackson.dataformat.yaml.YAMLGenerator.Feature + */ + public void setYamlFeatureToToggle(Map yamlFeatureToToggle) { + this.yamlFeatureToToggle = yamlFeatureToToggle; + } + + /** + * @see com.fasterxml.jackson.dataformat.yaml.YAMLGenerator.Feature + */ + public void appendYamlFeatureToToggle(Map features) { + this.yamlFeatureToToggle.putAll(features); + } + +} diff --git a/lib/src/main/java/com/diffplug/spotless/yaml/JacksonYamlStep.java b/lib/src/main/java/com/diffplug/spotless/yaml/JacksonYamlStep.java index 944d90e6c9..04d1895fe0 100644 --- a/lib/src/main/java/com/diffplug/spotless/yaml/JacksonYamlStep.java +++ b/lib/src/main/java/com/diffplug/spotless/yaml/JacksonYamlStep.java @@ -73,7 +73,7 @@ private State(JacksonConfig jacksonConfig, FormatterFunc toFormatter() throws ClassNotFoundException, NoSuchMethodException, InvocationTargetException, InstantiationException, IllegalAccessException { Class formatterFunc = jarState.getClassLoader().loadClass("com.diffplug.spotless.glue.yaml.JacksonYamlFormatterFunc"); - Constructor constructor = formatterFunc.getConstructor(JacksonConfig.class); + Constructor constructor = formatterFunc.getConstructor(JacksonYamlConfig.class); return (FormatterFunc) constructor.newInstance(jacksonConfig); } } diff --git a/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/JacksonGradleConfig.java b/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/JacksonGradleConfig.java new file mode 100644 index 0000000000..d388f45d11 --- /dev/null +++ b/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/JacksonGradleConfig.java @@ -0,0 +1,67 @@ +/* + * Copyright 2023 DiffPlug + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.diffplug.gradle.spotless; + +import java.util.Collections; + +import com.diffplug.spotless.FormatterStep; +import com.diffplug.spotless.json.JacksonConfig; +import com.diffplug.spotless.json.JacksonJsonStep; + +public abstract class JacksonGradleConfig { + protected final FormatExtension formatExtension; + + protected JacksonConfig jacksonConfig; + + protected String version = JacksonJsonStep.defaultVersion(); + + public JacksonGradleConfig(JacksonConfig jacksonConfig, FormatExtension formatExtension) { + this.formatExtension = formatExtension; + + this.jacksonConfig = jacksonConfig; + formatExtension.addStep(createStep()); + } + + public JacksonGradleConfig(FormatExtension formatExtension) { + this(new JacksonConfig(), formatExtension); + } + + public JacksonGradleConfig config(JacksonConfig jacksonConfig) { + this.jacksonConfig = jacksonConfig; + formatExtension.replaceStep(createStep()); + return this; + } + + public JacksonGradleConfig feature(String feature, boolean toggle) { + this.jacksonConfig.appendFeatureToToggle(Collections.singletonMap(feature, toggle)); + formatExtension.replaceStep(createStep()); + return this; + } + + public JacksonGradleConfig spaceBeforeSeparator(boolean toggle) { + this.jacksonConfig.setSpaceBeforeSeparator(toggle); + formatExtension.replaceStep(createStep()); + return this; + } + + public JacksonGradleConfig version(String version) { + this.version = version; + formatExtension.replaceStep(createStep()); + return this; + } + + protected abstract FormatterStep createStep(); +} diff --git a/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/JsonExtension.java b/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/JsonExtension.java index 25182fa4bc..542b2d5431 100644 --- a/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/JsonExtension.java +++ b/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/JsonExtension.java @@ -1,5 +1,5 @@ /* - * Copyright 2016-2022 DiffPlug + * Copyright 2016-2023 DiffPlug * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -18,6 +18,8 @@ import javax.inject.Inject; import com.diffplug.spotless.FormatterStep; +import com.diffplug.spotless.json.JacksonConfig; +import com.diffplug.spotless.json.JacksonJsonStep; import com.diffplug.spotless.json.JsonSimpleStep; import com.diffplug.spotless.json.gson.GsonStep; @@ -47,6 +49,10 @@ public GsonConfig gson() { return new GsonConfig(); } + public JacksonJsonGradleConfig jackson() { + return new JacksonJsonGradleConfig(this); + } + public class SimpleConfig { private int indent; @@ -108,4 +114,19 @@ private FormatterStep createStep() { } } + public static class JacksonJsonGradleConfig extends JacksonGradleConfig { + + public JacksonJsonGradleConfig(JacksonConfig jacksonConfig, FormatExtension formatExtension) { + super(jacksonConfig, formatExtension); + } + + public JacksonJsonGradleConfig(FormatExtension formatExtension) { + this(new JacksonConfig(), formatExtension); + } + + @Override + protected FormatterStep createStep() { + return JacksonJsonStep.create(jacksonConfig, version, formatExtension.provisioner()); + } + } } 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 1c65fad310..8c3128e02d 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 @@ -193,6 +193,12 @@ public void json(Action closure) { format(JsonExtension.NAME, JsonExtension.class, closure); } + /** Configures the special YAML-specific extension. */ + public void yaml(Action closure) { + requireNonNull(closure); + format(JsonExtension.NAME, YamlExtension.class, closure); + } + /** Configures a custom extension. */ public void format(String name, Action closure) { requireNonNull(name, "name"); diff --git a/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/YamlExtension.java b/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/YamlExtension.java new file mode 100644 index 0000000000..5907ea985a --- /dev/null +++ b/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/YamlExtension.java @@ -0,0 +1,75 @@ +/* + * Copyright 2016-2023 DiffPlug + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.diffplug.gradle.spotless; + +import java.util.Collections; + +import javax.inject.Inject; + +import com.diffplug.spotless.FormatterStep; +import com.diffplug.spotless.json.JacksonJsonStep; +import com.diffplug.spotless.yaml.JacksonYamlConfig; +import com.diffplug.spotless.yaml.JacksonYamlStep; + +public class YamlExtension extends FormatExtension { + private static final String DEFAULT_GSON_VERSION = JacksonJsonStep.defaultVersion(); + static final String NAME = "yaml"; + + @Inject + public YamlExtension(SpotlessExtension spotless) { + super(spotless); + } + + @Override + protected void setupTask(SpotlessTask task) { + if (target == null) { + throw noDefaultTargetException(); + } + super.setupTask(task); + } + + public JacksonGradleConfig jackson() { + return new JacksonYamlGradleConfig(this); + } + + public class JacksonYamlGradleConfig extends JacksonGradleConfig { + protected JacksonYamlConfig jacksonConfig; + + public JacksonYamlGradleConfig(JacksonYamlConfig jacksonConfig, FormatExtension formatExtension) { + super(jacksonConfig, formatExtension); + + this.jacksonConfig = jacksonConfig; + } + + public JacksonYamlGradleConfig(FormatExtension formatExtension) { + this(new JacksonYamlConfig(), formatExtension); + } + + /** + * @see com.fasterxml.jackson.dataformat.yaml.YAMLGenerator.Feature + */ + public JacksonGradleConfig yamlFeature(String feature, boolean toggle) { + this.jacksonConfig.appendYamlFeatureToToggle(Collections.singletonMap(feature, toggle)); + formatExtension.replaceStep(createStep()); + return this; + } + + @Override + protected FormatterStep createStep() { + return JacksonYamlStep.create(jacksonConfig, version, provisioner()); + } + } +} diff --git a/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/YamlExtensionTest.java b/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/YamlExtensionTest.java new file mode 100644 index 0000000000..c16053a661 --- /dev/null +++ b/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/YamlExtensionTest.java @@ -0,0 +1,81 @@ +/* + * Copyright 2021-2023 DiffPlug + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.diffplug.gradle.spotless; + +import java.io.IOException; + +import org.junit.jupiter.api.Test; + +class YamlExtensionTest extends GradleIntegrationHarness { + @Test + void testFormatYaml_WithJackson_defaultConfig_separatorComments() throws IOException { + setFile("build.gradle").toLines( + "plugins {", + " id 'java'", + " id 'com.diffplug.spotless'", + "}", + "repositories { mavenCentral() }", + "spotless {", + " yaml {", + " target 'src/**/*.yaml'", + " jackson()", + "}", + "}"); + setFile("src/main/resources/example.yaml").toResource("yaml/separator_comments.yaml"); + gradleRunner().withArguments("spotlessApply").build(); + assertFile("src/main/resources/example.yaml").sameAsResource("yaml/separator_comments.clean.yaml"); + } + + @Test + void testFormatYaml_WithJackson_defaultConfig_arrayBrackets_spaceBeforeSeparator() throws IOException { + setFile("build.gradle").toLines( + "plugins {", + " id 'java'", + " id 'com.diffplug.spotless'", + "}", + "repositories { mavenCentral() }", + "spotless {", + " yaml {", + " target 'src/**/*.yaml'", + " jackson().spaceBeforeSeparator(true)", + "}", + "}"); + setFile("src/main/resources/example.yaml").toResource("yaml/array_with_bracket.yaml"); + gradleRunner().withArguments("spotlessApply").build(); + assertFile("src/main/resources/example.yaml").sameAsResource("yaml/array_with_bracket.clean.spaceBeforeSeparator.yaml"); + } + + // see YAMLGenerator.Feature.WRITE_DOC_START_MARKER + @Test + void testFormatYaml_WithJackson_skipDocStartMarker() throws IOException { + setFile("build.gradle").toLines( + "plugins {", + " id 'java'", + " id 'com.diffplug.spotless'", + "}", + "repositories { mavenCentral() }", + "spotless {", + " yaml {", + " target 'src/**/*.yaml'", + " jackson().yamlFeature('WRITE_DOC_START_MARKER', false)", + "}", + "}"); + setFile("src/main/resources/example.yaml").toResource("yaml/array_with_bracket.yaml"); + gradleRunner().withArguments("spotlessApply").build(); + assertFile("src/main/resources/example.yaml").sameAsResource("yaml/array_with_bracket.clean.no_start_marker.yaml"); + } + +} diff --git a/plugin-maven/CHANGES.md b/plugin-maven/CHANGES.md index d6326cba12..5bcc4b24c6 100644 --- a/plugin-maven/CHANGES.md +++ b/plugin-maven/CHANGES.md @@ -3,13 +3,8 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format (starting after version `1.27.0`). ## [Unreleased] -### Added -* Introduce `` ([#1492](https://github.com/diffplug/spotless/pull/1492)) - * **POTENTIALLY BREAKING** `JacksonYaml` is now configured with a `Map` to configure features -* Jackson (JSON and YAML) has new `spaceBeforeSeparator` option - * **POTENTIALLY BREAKING** `spaceBeforeSeparator` is defaulted to false while the formatter was behaving with `true` -## [2.30.0] - 2023-01-13 +# [2.30.0] - 2023-01-13 ### Added * Add option `editorConfigFile` for `ktLint` [#142](https://github.com/diffplug/spotless/issues/142) * **POTENTIALLY BREAKING** `ktlint` step now modifies license headers. Make sure to put `licenseHeader` *after* `ktlint`. diff --git a/plugin-maven/README.md b/plugin-maven/README.md index 6dca992591..e76d424611 100644 --- a/plugin-maven/README.md +++ b/plugin-maven/README.md @@ -12,8 +12,8 @@ output = [ ].join('\n'); --> [![Maven central](https://img.shields.io/badge/mavencentral-com.diffplug.spotless%3Aspotless--maven--plugin-blue.svg)](https://search.maven.org/#search%7Cgav%7C1%7Cg%3A%22com.diffplug.spotless%22%20AND%20a%3A%22spotless-maven-plugin%22) -[![Javadoc](https://img.shields.io/badge/javadoc-yes-blue.svg)](https://javadoc.io/doc/com.diffplug.spotless/spotless-maven-plugin/2.30.0/index.html) -[![Changelog](https://img.shields.io/badge/changelog-2.30.0-brightgreen.svg)](CHANGES.md) +[![Javadoc](https://img.shields.io/badge/javadoc-yes-blue.svg)](https://javadoc.io/doc/com.diffplug.spotless/spotless-maven-plugin/2.29.0/index.html) +[![Changelog](https://img.shields.io/badge/changelog-2.29.0-brightgreen.svg)](CHANGES.md) [![Circle CI](https://circleci.com/gh/diffplug/spotless/tree/main.svg?style=shield)](https://circleci.com/gh/diffplug/spotless/tree/main) [![Live chat](https://img.shields.io/badge/gitter-chat-brightgreen.svg)](https://gitter.im/diffplug/spotless) @@ -864,6 +864,7 @@ For details, see the [npm detection](#npm-detection) and [`.npmrc` detection](#n + ``` @@ -898,6 +899,22 @@ all HTML characters are written escaped or none. Set `escapeHtml` if you prefer [javadoc of String](https://docs.oracle.com/en/java/javase/11/docs/api/java.base/java/lang/String.html#compareTo(java.lang.String)) for details. +### Jackson + +Uses Jackson for formatting. + +```xml + + 2.14.1 + + true + false + true|false + + false + +``` + @@ -924,10 +941,11 @@ Uses Jackson and YAMLFactory to pretty print objects: ```xml 2.14.1 - - true + + true false - true|false + false + true|false false diff --git a/plugin-maven/src/main/java/com/diffplug/spotless/maven/yaml/JacksonYaml.java b/plugin-maven/src/main/java/com/diffplug/spotless/maven/yaml/JacksonYaml.java index 1cd23bc3cc..9741c3f5d0 100644 --- a/plugin-maven/src/main/java/com/diffplug/spotless/maven/yaml/JacksonYaml.java +++ b/plugin-maven/src/main/java/com/diffplug/spotless/maven/yaml/JacksonYaml.java @@ -21,10 +21,10 @@ import org.apache.maven.plugins.annotations.Parameter; import com.diffplug.spotless.FormatterStep; -import com.diffplug.spotless.json.JacksonConfig; import com.diffplug.spotless.maven.FormatterFactory; import com.diffplug.spotless.maven.FormatterStepConfig; import com.diffplug.spotless.maven.FormatterStepFactory; +import com.diffplug.spotless.yaml.JacksonYamlConfig; import com.diffplug.spotless.yaml.JacksonYamlStep; /** @@ -36,16 +36,20 @@ public class JacksonYaml implements FormatterStepFactory { private String version = JacksonYamlStep.defaultVersion(); @Parameter - private boolean spaceBeforeSeparator = new JacksonConfig().isSpaceBeforeSeparator(); + private boolean spaceBeforeSeparator = new JacksonYamlConfig().isSpaceBeforeSeparator(); @Parameter private Map features = Collections.emptyMap(); + @Parameter + private Map yamlFeatures = Collections.emptyMap(); + @Override public FormatterStep newFormatterStep(FormatterStepConfig stepConfig) { - JacksonConfig jacksonConfig = new JacksonConfig(); + JacksonYamlConfig jacksonConfig = new JacksonYamlConfig(); jacksonConfig.appendFeatureToToggle(features); + jacksonConfig.appendYamlFeatureToToggle(yamlFeatures); jacksonConfig.setSpaceBeforeSeparator(spaceBeforeSeparator); return JacksonYamlStep diff --git a/plugin-maven/src/test/java/com/diffplug/spotless/maven/yaml/YamlTest.java b/plugin-maven/src/test/java/com/diffplug/spotless/maven/yaml/YamlTest.java index 51f8da99f4..aaea2c65b1 100644 --- a/plugin-maven/src/test/java/com/diffplug/spotless/maven/yaml/YamlTest.java +++ b/plugin-maven/src/test/java/com/diffplug/spotless/maven/yaml/YamlTest.java @@ -15,14 +15,11 @@ */ package com.diffplug.spotless.maven.yaml; -import static org.assertj.core.api.Assertions.assertThat; - import org.junit.jupiter.api.Test; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import com.diffplug.spotless.maven.MavenIntegrationHarness; -import com.diffplug.spotless.maven.MavenRunner.Result; public class YamlTest extends MavenIntegrationHarness { private static final Logger LOGGER = LoggerFactory.getLogger(YamlTest.class); @@ -32,10 +29,7 @@ public void testFormatYaml_WithJackson_defaultConfig_separatorComments() throws writePomWithYamlSteps(""); setFile("yaml_test.yaml").toResource("yaml/separator_comments.yaml"); - Result runNoError = mavenRunner().withArguments("spotless:apply").runNoError(); - LOGGER.error("result: {}", runNoError); - assertThat(runNoError.exitValue()).as("Run without error %s", runNoError).isEqualTo(0); - LOGGER.error("GOGO"); + mavenRunner().withArguments("spotless:apply").runNoError(); assertFile("yaml_test.yaml").sameAsResource("yaml/separator_comments.clean.yaml"); } diff --git a/testlib/src/main/resources/yaml/array_with_bracket.clean.no_start_marker.yaml b/testlib/src/main/resources/yaml/array_with_bracket.clean.no_start_marker.yaml new file mode 100644 index 0000000000..7f2f5a96cd --- /dev/null +++ b/testlib/src/main/resources/yaml/array_with_bracket.clean.no_start_marker.yaml @@ -0,0 +1,11 @@ +episodes: +- 1 +- 2 +- 3 +- 4 +- 5 +- 6 +- 7 +best-jedi: + name: "Obi-Wan" + side: "light" diff --git a/testlib/src/main/resources/yaml/array_with_bracket.clean.spaceBeforeSeparator.yaml b/testlib/src/main/resources/yaml/array_with_bracket.clean.spaceBeforeSeparator.yaml index c6f891b9de..7dc9255e06 100644 --- a/testlib/src/main/resources/yaml/array_with_bracket.clean.spaceBeforeSeparator.yaml +++ b/testlib/src/main/resources/yaml/array_with_bracket.clean.spaceBeforeSeparator.yaml @@ -7,6 +7,6 @@ episodes: - 5 - 6 - 7 -best-jedi: - name: "Obi-Wan" - side: "light" \ No newline at end of file +best-jedi : + name : "Obi-Wan" + side : "light" From 533dc9999c56ca8dbd381f3ea74b79bcd5774e50 Mon Sep 17 00:00:00 2001 From: Benoit Lacelle Date: Wed, 18 Jan 2023 00:33:53 +0400 Subject: [PATCH 585/757] Progress with gradle and tests --- .../glue/json/AJacksonFormatterFunc.java | 87 +++++++++++++++++++ .../glue/json/JacksonJsonFormatterFunc.java | 59 ++++--------- .../glue/yaml/JacksonYamlFormatterFunc.java | 9 +- .../diffplug/spotless/json/JacksonConfig.java | 14 +-- .../spotless/json/JacksonJsonConfig.java | 59 +++++++++++++ .../spotless/json/JacksonJsonStep.java | 6 +- .../spotless/yaml/JacksonYamlStep.java | 13 +-- .../gradle/spotless/JacksonGradleConfig.java | 6 -- .../gradle/spotless/JsonExtension.java | 28 +++++- .../gradle/spotless/YamlExtension.java | 6 +- .../gradle/spotless/JsonExtensionTest.java | 56 ++++++++---- .../gradle/spotless/YamlExtensionTest.java | 33 ++----- .../spotless/maven/json/JacksonJson.java | 6 +- .../spotless/maven/yaml/JacksonYaml.java | 4 - ...ay_with_bracket.clean.no_start_marker.yaml | 4 +- 15 files changed, 259 insertions(+), 131 deletions(-) create mode 100644 lib/src/jackson/java/com/diffplug/spotless/glue/json/AJacksonFormatterFunc.java create mode 100644 lib/src/main/java/com/diffplug/spotless/json/JacksonJsonConfig.java diff --git a/lib/src/jackson/java/com/diffplug/spotless/glue/json/AJacksonFormatterFunc.java b/lib/src/jackson/java/com/diffplug/spotless/glue/json/AJacksonFormatterFunc.java new file mode 100644 index 0000000000..a835c85f9a --- /dev/null +++ b/lib/src/jackson/java/com/diffplug/spotless/glue/json/AJacksonFormatterFunc.java @@ -0,0 +1,87 @@ +/* + * Copyright 2021-2023 DiffPlug + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.diffplug.spotless.glue.json; + +import java.io.IOException; + +import com.fasterxml.jackson.core.JsonFactory; +import com.fasterxml.jackson.core.JsonGenerator; +import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.core.util.DefaultPrettyPrinter; +import com.fasterxml.jackson.databind.ObjectMapper; +import com.fasterxml.jackson.databind.SerializationFeature; +import com.fasterxml.jackson.databind.node.ObjectNode; + +import com.diffplug.spotless.FormatterFunc; +import com.diffplug.spotless.json.JacksonConfig; + +/** + * A {@link FormatterFunc} based on Jackson library + */ +// https://github.com/FasterXML/jackson-dataformats-text/issues/372 +public abstract class AJacksonFormatterFunc implements FormatterFunc { + private JacksonConfig jacksonConfig; + + public AJacksonFormatterFunc(JacksonConfig jacksonConfig) { + this.jacksonConfig = jacksonConfig; + } + + @Override + public String apply(String input) throws Exception { + ObjectMapper objectMapper = makeObjectMapper(); + + return format(objectMapper, input); + } + + protected String format(ObjectMapper objectMapper, String input) throws IllegalArgumentException, IOException { + try { + ObjectNode objectNode = objectMapper.readValue(input, ObjectNode.class); + return objectMapper.writerWithDefaultPrettyPrinter().writeValueAsString(objectNode); + } catch (JsonProcessingException e) { + throw new AssertionError("Unable to format. input='" + input + "'", e); + } + } + + /** + * @return a {@link JsonFactory}. May be overridden to handle alternative formats. + * @see jackson-dataformats-text + */ + protected abstract JsonFactory makeJsonFactory(); + + protected ObjectMapper makeObjectMapper() { + JsonFactory jsonFactory = makeJsonFactory(); + ObjectMapper objectMapper = new ObjectMapper(jsonFactory); + + objectMapper.setDefaultPrettyPrinter(makePrinter()); + + // Configure the ObjectMapper + // https://github.com/FasterXML/jackson-databind#commonly-used-features + jacksonConfig.getFeatureToToggle().forEach((rawFeature, toggle) -> { + // https://stackoverflow.com/questions/3735927/java-instantiating-an-enum-using-reflection + SerializationFeature feature = SerializationFeature.valueOf(rawFeature); + + objectMapper.configure(feature, toggle); + }); + + new JsonFactory().configure(JsonGenerator.Feature.AUTO_CLOSE_JSON_CONTENT, true); + + return objectMapper; + } + + protected DefaultPrettyPrinter makePrinter() { + return new DefaultPrettyPrinter(); + } +} diff --git a/lib/src/jackson/java/com/diffplug/spotless/glue/json/JacksonJsonFormatterFunc.java b/lib/src/jackson/java/com/diffplug/spotless/glue/json/JacksonJsonFormatterFunc.java index 934e60fcd8..5aadcc568f 100644 --- a/lib/src/jackson/java/com/diffplug/spotless/glue/json/JacksonJsonFormatterFunc.java +++ b/lib/src/jackson/java/com/diffplug/spotless/glue/json/JacksonJsonFormatterFunc.java @@ -15,99 +15,72 @@ */ package com.diffplug.spotless.glue.json; -import java.io.IOException; - import com.fasterxml.jackson.core.JsonFactory; import com.fasterxml.jackson.core.JsonFactoryBuilder; -import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.core.JsonGenerator; import com.fasterxml.jackson.core.util.DefaultIndenter; import com.fasterxml.jackson.core.util.DefaultPrettyPrinter; import com.fasterxml.jackson.core.util.Separators; -import com.fasterxml.jackson.databind.ObjectMapper; -import com.fasterxml.jackson.databind.SerializationFeature; -import com.fasterxml.jackson.databind.node.ObjectNode; import com.diffplug.spotless.FormatterFunc; -import com.diffplug.spotless.json.JacksonConfig; +import com.diffplug.spotless.json.JacksonJsonConfig; /** * A {@link FormatterFunc} based on Jackson library */ // https://github.com/FasterXML/jackson-dataformats-text/issues/372 -public class JacksonJsonFormatterFunc implements FormatterFunc { - private JacksonConfig jacksonConfig; +public class JacksonJsonFormatterFunc extends AJacksonFormatterFunc { + private JacksonJsonConfig jacksonConfig; - public JacksonJsonFormatterFunc(JacksonConfig jacksonConfig) { + public JacksonJsonFormatterFunc(JacksonJsonConfig jacksonConfig) { + super(jacksonConfig); this.jacksonConfig = jacksonConfig; } - @Override - public String apply(String input) throws Exception { - ObjectMapper objectMapper = makeObjectMapper(); - - return format(objectMapper, input); - } - - protected String format(ObjectMapper objectMapper, String input) throws IllegalArgumentException, IOException { - try { - ObjectNode objectNode = objectMapper.readValue(input, ObjectNode.class); - return objectMapper.writerWithDefaultPrettyPrinter().writeValueAsString(objectNode); - } catch (JsonProcessingException e) { - throw new AssertionError("Unable to format. input='" + input + "'", e); - } - } - /** * @return a {@link JsonFactory}. May be overridden to handle alternative formats. * @see jackson-dataformats-text */ protected JsonFactory makeJsonFactory() { - // We may later accept JsonFactory.Features - return new JsonFactoryBuilder().build(); - } - - protected ObjectMapper makeObjectMapper() { - JsonFactory jsonFactory = makeJsonFactory(); - ObjectMapper objectMapper = new ObjectMapper(jsonFactory); - - objectMapper.setDefaultPrettyPrinter(makePrinter()); + JsonFactory jsonFactory = new JsonFactoryBuilder().build(); // Configure the ObjectMapper // https://github.com/FasterXML/jackson-databind#commonly-used-features - jacksonConfig.getFeatureToToggle().forEach((rawFeature, toggle) -> { + jacksonConfig.getJsonFeatureToToggle().forEach((rawFeature, toggle) -> { // https://stackoverflow.com/questions/3735927/java-instantiating-an-enum-using-reflection - SerializationFeature feature = SerializationFeature.valueOf(rawFeature); + JsonGenerator.Feature feature = JsonGenerator.Feature.valueOf(rawFeature); - objectMapper.configure(feature, toggle); + jsonFactory.configure(feature, toggle); }); - return objectMapper; + return jsonFactory; } + @Override protected DefaultPrettyPrinter makePrinter() { boolean spaceBeforeSeparator = jacksonConfig.isSpaceBeforeSeparator(); // DefaultIndenter default constructor relies on 2 whitespaces as default tabulation // By we want to force '\n' as eol given Spotless provides LF-input (whatever the actual File content/current OS) DefaultPrettyPrinter.Indenter indenter = new DefaultIndenter(" ", "\n"); - DefaultPrettyPrinter printer = new SpotlessDefaultPrettyPrinter(spaceBeforeSeparator); + DefaultPrettyPrinter printer = new SpotlessJsonPrettyPrinter(spaceBeforeSeparator); printer.indentObjectsWith(indenter); printer.indentArraysWith(indenter); return printer; } - protected static class SpotlessDefaultPrettyPrinter extends DefaultPrettyPrinter { + protected static class SpotlessJsonPrettyPrinter extends DefaultPrettyPrinter { private static final long serialVersionUID = 1L; private final boolean spaceBeforeSeparator; - public SpotlessDefaultPrettyPrinter(boolean spaceBeforeSeparator) { + public SpotlessJsonPrettyPrinter(boolean spaceBeforeSeparator) { this.spaceBeforeSeparator = spaceBeforeSeparator; } @Override public DefaultPrettyPrinter createInstance() { - return new DefaultPrettyPrinter(this); + return new SpotlessJsonPrettyPrinter(spaceBeforeSeparator); } @Override diff --git a/lib/src/jackson/java/com/diffplug/spotless/glue/yaml/JacksonYamlFormatterFunc.java b/lib/src/jackson/java/com/diffplug/spotless/glue/yaml/JacksonYamlFormatterFunc.java index f7686ad503..3986374c9e 100644 --- a/lib/src/jackson/java/com/diffplug/spotless/glue/yaml/JacksonYamlFormatterFunc.java +++ b/lib/src/jackson/java/com/diffplug/spotless/glue/yaml/JacksonYamlFormatterFunc.java @@ -25,15 +25,19 @@ import com.fasterxml.jackson.dataformat.yaml.YAMLFactoryBuilder; import com.fasterxml.jackson.dataformat.yaml.YAMLGenerator; -import com.diffplug.spotless.glue.json.JacksonJsonFormatterFunc; +import com.diffplug.spotless.glue.json.AJacksonFormatterFunc; import com.diffplug.spotless.yaml.JacksonYamlConfig; -public class JacksonYamlFormatterFunc extends JacksonJsonFormatterFunc { +public class JacksonYamlFormatterFunc extends AJacksonFormatterFunc { final JacksonYamlConfig yamlConfig; public JacksonYamlFormatterFunc(JacksonYamlConfig jacksonConfig) { super(jacksonConfig); this.yamlConfig = jacksonConfig; + + if (jacksonConfig == null) { + throw new IllegalArgumentException("ARG"); + } } protected JsonFactory makeJsonFactory() { @@ -43,7 +47,6 @@ protected JsonFactory makeJsonFactory() { // https://github.com/FasterXML/jackson-databind#commonly-used-features yamlConfig.getYamlFeatureToToggle().forEach((rawFeature, toggle) -> { // https://stackoverflow.com/questions/3735927/java-instantiating-an-enum-using-reflection - // Refers to 'com.fasterxml.jackson.dataformat.yaml.YAMLGenerator.Feature' YAMLGenerator.Feature feature = YAMLGenerator.Feature.valueOf(rawFeature); yamlFactoryBuilder.configure(feature, toggle); diff --git a/lib/src/main/java/com/diffplug/spotless/json/JacksonConfig.java b/lib/src/main/java/com/diffplug/spotless/json/JacksonConfig.java index d5ca990b08..250b77d1f1 100644 --- a/lib/src/main/java/com/diffplug/spotless/json/JacksonConfig.java +++ b/lib/src/main/java/com/diffplug/spotless/json/JacksonConfig.java @@ -21,7 +21,7 @@ import java.util.Map; /** - * A DTO holding the options for Jackson-based formatters + * A DTO holding the basic for Jackson-based formatters */ public class JacksonConfig implements Serializable { private static final long serialVersionUID = 1L; @@ -38,10 +38,6 @@ public class JacksonConfig implements Serializable { protected Map featureToToggle = new LinkedHashMap<>(); - // https://github.com/revelc/formatter-maven-plugin/pull/280 - // By default, Jackson adds a ' ' before separator, which is not standard with most IDE/JSON libraries - protected boolean spaceBeforeSeparator = false; - public Map getFeatureToToggle() { return Collections.unmodifiableMap(featureToToggle); } @@ -53,12 +49,4 @@ public void setFeatureToToggle(Map featureToToggle) { public void appendFeatureToToggle(Map features) { this.featureToToggle.putAll(features); } - - public boolean isSpaceBeforeSeparator() { - return spaceBeforeSeparator; - } - - public void setSpaceBeforeSeparator(boolean spaceBeforeSeparator) { - this.spaceBeforeSeparator = spaceBeforeSeparator; - } } diff --git a/lib/src/main/java/com/diffplug/spotless/json/JacksonJsonConfig.java b/lib/src/main/java/com/diffplug/spotless/json/JacksonJsonConfig.java new file mode 100644 index 0000000000..50b28605d1 --- /dev/null +++ b/lib/src/main/java/com/diffplug/spotless/json/JacksonJsonConfig.java @@ -0,0 +1,59 @@ +/* + * Copyright 2023 DiffPlug + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.diffplug.spotless.json; + +import java.util.Collections; +import java.util.LinkedHashMap; +import java.util.Map; + +/** + * Specialization of {@link JacksonConfig} for JSON documents + */ +public class JacksonJsonConfig extends JacksonConfig { + private static final long serialVersionUID = 1L; + + protected Map jsonFeatureToToggle = new LinkedHashMap<>(); + + // https://github.com/revelc/formatter-maven-plugin/pull/280 + // By default, Jackson adds a ' ' before separator, which is not standard with most IDE/JSON libraries + protected boolean spaceBeforeSeparator = false; + + public Map getJsonFeatureToToggle() { + return Collections.unmodifiableMap(jsonFeatureToToggle); + } + + /** + * @see com.fasterxml.jackson.core.JsonGenerator.Feature + */ + public void setJsonFeatureToToggle(Map jsonFeatureToToggle) { + this.jsonFeatureToToggle = jsonFeatureToToggle; + } + + /** + * @see com.fasterxml.jackson.core.JsonGenerator.Feature + */ + public void appendJsonFeatureToToggle(Map features) { + this.jsonFeatureToToggle.putAll(features); + } + + public boolean isSpaceBeforeSeparator() { + return spaceBeforeSeparator; + } + + public void setSpaceBeforeSeparator(boolean spaceBeforeSeparator) { + this.spaceBeforeSeparator = spaceBeforeSeparator; + } +} diff --git a/lib/src/main/java/com/diffplug/spotless/json/JacksonJsonStep.java b/lib/src/main/java/com/diffplug/spotless/json/JacksonJsonStep.java index 0fe1ab057b..f15edbbd42 100644 --- a/lib/src/main/java/com/diffplug/spotless/json/JacksonJsonStep.java +++ b/lib/src/main/java/com/diffplug/spotless/json/JacksonJsonStep.java @@ -41,7 +41,7 @@ public static String defaultVersion() { return DEFAULT_VERSION; } - public static FormatterStep create(JacksonConfig jacksonConfig, + public static FormatterStep create(JacksonJsonConfig jacksonConfig, String jacksonVersion, Provisioner provisioner) { Objects.requireNonNull(provisioner, "provisioner cannot be null"); @@ -51,7 +51,7 @@ public static FormatterStep create(JacksonConfig jacksonConfig, } public static FormatterStep create(Provisioner provisioner) { - return create(new JacksonConfig(), defaultVersion(), provisioner); + return create(new JacksonJsonConfig(), defaultVersion(), provisioner); } private static final class State implements Serializable { @@ -72,7 +72,7 @@ private State(JacksonConfig jacksonConfig, FormatterFunc toFormatter() throws ClassNotFoundException, NoSuchMethodException, InvocationTargetException, InstantiationException, IllegalAccessException { Class formatterFunc = jarState.getClassLoader().loadClass("com.diffplug.spotless.glue.json.JacksonJsonFormatterFunc"); - Constructor constructor = formatterFunc.getConstructor(JacksonConfig.class); + Constructor constructor = formatterFunc.getConstructor(JacksonJsonConfig.class); return (FormatterFunc) constructor.newInstance(jacksonConfig); } } diff --git a/lib/src/main/java/com/diffplug/spotless/yaml/JacksonYamlStep.java b/lib/src/main/java/com/diffplug/spotless/yaml/JacksonYamlStep.java index 04d1895fe0..201199fe8b 100644 --- a/lib/src/main/java/com/diffplug/spotless/yaml/JacksonYamlStep.java +++ b/lib/src/main/java/com/diffplug/spotless/yaml/JacksonYamlStep.java @@ -25,7 +25,6 @@ import com.diffplug.spotless.FormatterStep; import com.diffplug.spotless.JarState; import com.diffplug.spotless.Provisioner; -import com.diffplug.spotless.json.JacksonConfig; /** * Simple YAML formatter which reformats the file according to Jackson YAMLFactory. @@ -42,7 +41,7 @@ public static String defaultVersion() { return DEFAULT_VERSION; } - public static FormatterStep create(JacksonConfig jacksonConfig, + public static FormatterStep create(JacksonYamlConfig jacksonConfig, String jacksonVersion, Provisioner provisioner) { Objects.requireNonNull(provisioner, "provisioner cannot be null"); @@ -52,21 +51,25 @@ public static FormatterStep create(JacksonConfig jacksonConfig, } public static FormatterStep create(Provisioner provisioner) { - return create(new JacksonConfig(), defaultVersion(), provisioner); + return create(new JacksonYamlConfig(), defaultVersion(), provisioner); } private static final class State implements Serializable { private static final long serialVersionUID = 1L; - private final JacksonConfig jacksonConfig; + private final JacksonYamlConfig jacksonConfig; private final JarState jarState; - private State(JacksonConfig jacksonConfig, + private State(JacksonYamlConfig jacksonConfig, String jacksonVersion, Provisioner provisioner) throws IOException { this.jacksonConfig = jacksonConfig; + if (jacksonConfig == null) { + throw new IllegalArgumentException("ARG"); + } + this.jarState = JarState.from(JacksonYamlStep.MAVEN_COORDINATE + jacksonVersion, provisioner); } diff --git a/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/JacksonGradleConfig.java b/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/JacksonGradleConfig.java index d388f45d11..afc0c36371 100644 --- a/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/JacksonGradleConfig.java +++ b/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/JacksonGradleConfig.java @@ -51,12 +51,6 @@ public JacksonGradleConfig feature(String feature, boolean toggle) { return this; } - public JacksonGradleConfig spaceBeforeSeparator(boolean toggle) { - this.jacksonConfig.setSpaceBeforeSeparator(toggle); - formatExtension.replaceStep(createStep()); - return this; - } - public JacksonGradleConfig version(String version) { this.version = version; formatExtension.replaceStep(createStep()); diff --git a/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/JsonExtension.java b/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/JsonExtension.java index 542b2d5431..31f605809c 100644 --- a/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/JsonExtension.java +++ b/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/JsonExtension.java @@ -15,10 +15,12 @@ */ package com.diffplug.gradle.spotless; +import java.util.Collections; + import javax.inject.Inject; import com.diffplug.spotless.FormatterStep; -import com.diffplug.spotless.json.JacksonConfig; +import com.diffplug.spotless.json.JacksonJsonConfig; import com.diffplug.spotless.json.JacksonJsonStep; import com.diffplug.spotless.json.JsonSimpleStep; import com.diffplug.spotless.json.gson.GsonStep; @@ -49,7 +51,7 @@ public GsonConfig gson() { return new GsonConfig(); } - public JacksonJsonGradleConfig jackson() { + public JacksonJsonGradleConfig jacksonJson() { return new JacksonJsonGradleConfig(this); } @@ -115,17 +117,35 @@ private FormatterStep createStep() { } public static class JacksonJsonGradleConfig extends JacksonGradleConfig { + protected JacksonJsonConfig jacksonConfig; - public JacksonJsonGradleConfig(JacksonConfig jacksonConfig, FormatExtension formatExtension) { + public JacksonJsonGradleConfig(JacksonJsonConfig jacksonConfig, FormatExtension formatExtension) { super(jacksonConfig, formatExtension); + this.jacksonConfig = jacksonConfig; + + if (jacksonConfig == null) { + throw new IllegalArgumentException("ARG2"); + } } public JacksonJsonGradleConfig(FormatExtension formatExtension) { - this(new JacksonConfig(), formatExtension); + this(new JacksonJsonConfig(), formatExtension); + } + + /** + * @see com.fasterxml.jackson.core.JsonGenerator.Feature + */ + public JacksonGradleConfig jsonFeature(String feature, boolean toggle) { + this.jacksonConfig.appendJsonFeatureToToggle(Collections.singletonMap(feature, toggle)); + formatExtension.replaceStep(createStep()); + return this; } @Override protected FormatterStep createStep() { + if (jacksonConfig == null) { + throw new IllegalArgumentException("ARG3"); + } return JacksonJsonStep.create(jacksonConfig, version, formatExtension.provisioner()); } } diff --git a/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/YamlExtension.java b/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/YamlExtension.java index 5907ea985a..3fc12e0495 100644 --- a/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/YamlExtension.java +++ b/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/YamlExtension.java @@ -41,7 +41,7 @@ protected void setupTask(SpotlessTask task) { super.setupTask(task); } - public JacksonGradleConfig jackson() { + public JacksonGradleConfig jacksonYaml() { return new JacksonYamlGradleConfig(this); } @@ -52,6 +52,10 @@ public JacksonYamlGradleConfig(JacksonYamlConfig jacksonConfig, FormatExtension super(jacksonConfig, formatExtension); this.jacksonConfig = jacksonConfig; + + if (jacksonConfig == null) { + throw new IllegalArgumentException("ARG"); + } } public JacksonYamlGradleConfig(FormatExtension formatExtension) { diff --git a/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/JsonExtensionTest.java b/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/JsonExtensionTest.java index e2fb9f70aa..945c72cf75 100644 --- a/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/JsonExtensionTest.java +++ b/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/JsonExtensionTest.java @@ -1,5 +1,5 @@ /* - * Copyright 2021-2022 DiffPlug + * Copyright 2021-2023 DiffPlug * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -30,9 +30,9 @@ void simpleDefaultFormatting() throws IOException { "repositories { mavenCentral() }", "spotless {", " json {", - " target 'examples/**/*.json'", - " simple()", - "}", + " target 'examples/**/*.json'", + " simple()", + " }", "}"); setFile("src/main/resources/example.json").toResource("json/nestedObjectBefore.json"); setFile("examples/main/resources/example.json").toResource("json/nestedObjectBefore.json"); @@ -51,9 +51,9 @@ void simpleFormattingWithCustomNumberOfSpaces() throws IOException { "repositories { mavenCentral() }", "spotless {", " json {", - " target 'src/**/*.json'", - " simple().indentWithSpaces(6)", - "}", + " target 'src/**/*.json'", + " simple().indentWithSpaces(6)", + " }", "}"); setFile("src/main/resources/example.json").toResource("json/singletonArrayBefore.json"); gradleRunner().withArguments("spotlessApply").build(); @@ -70,9 +70,9 @@ void gsonDefaultFormatting() throws IOException { "repositories { mavenCentral() }", "spotless {", " json {", - " target 'examples/**/*.json'", - " gson()", - "}", + " target 'examples/**/*.json'", + " gson()", + " }", "}"); setFile("src/main/resources/example.json").toResource("json/nestedObjectBefore.json"); setFile("examples/main/resources/example.json").toResource("json/nestedObjectBefore.json"); @@ -91,9 +91,9 @@ void gsonFormattingWithCustomNumberOfSpaces() throws IOException { "repositories { mavenCentral() }", "spotless {", " json {", - " target 'src/**/*.json'", - " gson().indentWithSpaces(6)", - "}", + " target 'src/**/*.json'", + " gson().indentWithSpaces(6)", + " }", "}"); setFile("src/main/resources/example.json").toResource("json/singletonArrayBefore.json"); gradleRunner().withArguments("spotlessApply").build(); @@ -110,9 +110,9 @@ void gsonFormattingWithSortingByKeys() throws IOException { "repositories { mavenCentral() }", "spotless {", " json {", - " target 'src/**/*.json'", - " gson().sortByKeys()", - "}", + " target 'src/**/*.json'", + " gson().sortByKeys()", + " }", "}"); setFile("src/main/resources/example.json").toResource("json/sortByKeysBefore.json"); gradleRunner().withArguments("spotlessApply").build(); @@ -129,13 +129,31 @@ void gsonFormattingWithHtmlEscape() throws IOException { "repositories { mavenCentral() }", "spotless {", " json {", - " target 'src/**/*.json'", - " gson().escapeHtml()", - "}", + " target 'src/**/*.json'", + " gson().escapeHtml()", + " }", "}"); setFile("src/main/resources/example.json").toResource("json/escapeHtmlGsonBefore.json"); gradleRunner().withArguments("spotlessApply").build(); assertFile("src/main/resources/example.json").sameAsResource("json/escapeHtmlGsonAfter.json"); } + @Test + void jacksonFormattingWithSortingByKeys() throws IOException { + setFile("build.gradle").toLines( + "plugins {", + " id 'java'", + " id 'com.diffplug.spotless'", + "}", + "repositories { mavenCentral() }", + "spotless {", + " json {", + " target 'src/**/*.json'", + " jacksonJson().feature('ORDER_MAP_ENTRIES_BY_KEYS', true)", + " }", + "}"); + setFile("src/main/resources/example.json").toResource("json/sortByKeysBefore.json"); + gradleRunner().withArguments("spotlessApply").build(); + assertFile("src/main/resources/example.json").sameAsResource("json/sortByKeysAfter_Jackson.json"); + } } diff --git a/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/YamlExtensionTest.java b/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/YamlExtensionTest.java index c16053a661..79e0df0d8d 100644 --- a/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/YamlExtensionTest.java +++ b/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/YamlExtensionTest.java @@ -30,34 +30,15 @@ void testFormatYaml_WithJackson_defaultConfig_separatorComments() throws IOExcep "repositories { mavenCentral() }", "spotless {", " yaml {", - " target 'src/**/*.yaml'", - " jackson()", - "}", + " target 'src/**/*.yaml'", + " jacksonYaml()", + " }", "}"); setFile("src/main/resources/example.yaml").toResource("yaml/separator_comments.yaml"); gradleRunner().withArguments("spotlessApply").build(); assertFile("src/main/resources/example.yaml").sameAsResource("yaml/separator_comments.clean.yaml"); } - @Test - void testFormatYaml_WithJackson_defaultConfig_arrayBrackets_spaceBeforeSeparator() throws IOException { - setFile("build.gradle").toLines( - "plugins {", - " id 'java'", - " id 'com.diffplug.spotless'", - "}", - "repositories { mavenCentral() }", - "spotless {", - " yaml {", - " target 'src/**/*.yaml'", - " jackson().spaceBeforeSeparator(true)", - "}", - "}"); - setFile("src/main/resources/example.yaml").toResource("yaml/array_with_bracket.yaml"); - gradleRunner().withArguments("spotlessApply").build(); - assertFile("src/main/resources/example.yaml").sameAsResource("yaml/array_with_bracket.clean.spaceBeforeSeparator.yaml"); - } - // see YAMLGenerator.Feature.WRITE_DOC_START_MARKER @Test void testFormatYaml_WithJackson_skipDocStartMarker() throws IOException { @@ -69,9 +50,11 @@ void testFormatYaml_WithJackson_skipDocStartMarker() throws IOException { "repositories { mavenCentral() }", "spotless {", " yaml {", - " target 'src/**/*.yaml'", - " jackson().yamlFeature('WRITE_DOC_START_MARKER', false)", - "}", + " target 'src/**/*.yaml'", + " jacksonYaml()" + + " .yamlFeature('WRITE_DOC_START_MARKER', false)" + + " .yamlFeature('MINIMIZE_QUOTES', true)", + " }", "}"); setFile("src/main/resources/example.yaml").toResource("yaml/array_with_bracket.yaml"); gradleRunner().withArguments("spotlessApply").build(); diff --git a/plugin-maven/src/main/java/com/diffplug/spotless/maven/json/JacksonJson.java b/plugin-maven/src/main/java/com/diffplug/spotless/maven/json/JacksonJson.java index 31c59a5f81..9bca852754 100644 --- a/plugin-maven/src/main/java/com/diffplug/spotless/maven/json/JacksonJson.java +++ b/plugin-maven/src/main/java/com/diffplug/spotless/maven/json/JacksonJson.java @@ -21,7 +21,7 @@ import org.apache.maven.plugins.annotations.Parameter; import com.diffplug.spotless.FormatterStep; -import com.diffplug.spotless.json.JacksonConfig; +import com.diffplug.spotless.json.JacksonJsonConfig; import com.diffplug.spotless.json.JacksonJsonStep; import com.diffplug.spotless.maven.FormatterFactory; import com.diffplug.spotless.maven.FormatterStepConfig; @@ -36,14 +36,14 @@ public class JacksonJson implements FormatterStepFactory { private String version = JacksonJsonStep.defaultVersion(); @Parameter - private boolean spaceBeforeSeparator = new JacksonConfig().isSpaceBeforeSeparator(); + private boolean spaceBeforeSeparator = new JacksonJsonConfig().isSpaceBeforeSeparator(); @Parameter private Map features = Collections.emptyMap(); @Override public FormatterStep newFormatterStep(FormatterStepConfig stepConfig) { - JacksonConfig jacksonConfig = new JacksonConfig(); + JacksonJsonConfig jacksonConfig = new JacksonJsonConfig(); jacksonConfig.appendFeatureToToggle(features); jacksonConfig.setSpaceBeforeSeparator(spaceBeforeSeparator); diff --git a/plugin-maven/src/main/java/com/diffplug/spotless/maven/yaml/JacksonYaml.java b/plugin-maven/src/main/java/com/diffplug/spotless/maven/yaml/JacksonYaml.java index 9741c3f5d0..d97cc41647 100644 --- a/plugin-maven/src/main/java/com/diffplug/spotless/maven/yaml/JacksonYaml.java +++ b/plugin-maven/src/main/java/com/diffplug/spotless/maven/yaml/JacksonYaml.java @@ -35,9 +35,6 @@ public class JacksonYaml implements FormatterStepFactory { @Parameter private String version = JacksonYamlStep.defaultVersion(); - @Parameter - private boolean spaceBeforeSeparator = new JacksonYamlConfig().isSpaceBeforeSeparator(); - @Parameter private Map features = Collections.emptyMap(); @@ -50,7 +47,6 @@ public FormatterStep newFormatterStep(FormatterStepConfig stepConfig) { jacksonConfig.appendFeatureToToggle(features); jacksonConfig.appendYamlFeatureToToggle(yamlFeatures); - jacksonConfig.setSpaceBeforeSeparator(spaceBeforeSeparator); return JacksonYamlStep .create(jacksonConfig, version, stepConfig.getProvisioner()); diff --git a/testlib/src/main/resources/yaml/array_with_bracket.clean.no_start_marker.yaml b/testlib/src/main/resources/yaml/array_with_bracket.clean.no_start_marker.yaml index 7f2f5a96cd..0e5571531a 100644 --- a/testlib/src/main/resources/yaml/array_with_bracket.clean.no_start_marker.yaml +++ b/testlib/src/main/resources/yaml/array_with_bracket.clean.no_start_marker.yaml @@ -7,5 +7,5 @@ episodes: - 6 - 7 best-jedi: - name: "Obi-Wan" - side: "light" + name: Obi-Wan + side: light From 4d6f9610e6542dd91029c9031d2a93c5c89319bb Mon Sep 17 00:00:00 2001 From: Benoit Lacelle Date: Wed, 18 Jan 2023 00:50:12 +0400 Subject: [PATCH 586/757] Small fixes --- ...leConfig.java => AJacksonGradleConfig.java} | 18 ++++-------------- .../gradle/spotless/JsonExtension.java | 4 ++-- .../gradle/spotless/YamlExtension.java | 6 +++--- .../gradle/spotless/YamlExtensionTest.java | 4 ++-- 4 files changed, 11 insertions(+), 21 deletions(-) rename plugin-gradle/src/main/java/com/diffplug/gradle/spotless/{JacksonGradleConfig.java => AJacksonGradleConfig.java} (71%) diff --git a/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/JacksonGradleConfig.java b/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/AJacksonGradleConfig.java similarity index 71% rename from plugin-gradle/src/main/java/com/diffplug/gradle/spotless/JacksonGradleConfig.java rename to plugin-gradle/src/main/java/com/diffplug/gradle/spotless/AJacksonGradleConfig.java index afc0c36371..e3d5cee661 100644 --- a/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/JacksonGradleConfig.java +++ b/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/AJacksonGradleConfig.java @@ -21,37 +21,27 @@ import com.diffplug.spotless.json.JacksonConfig; import com.diffplug.spotless.json.JacksonJsonStep; -public abstract class JacksonGradleConfig { +public abstract class AJacksonGradleConfig { protected final FormatExtension formatExtension; protected JacksonConfig jacksonConfig; protected String version = JacksonJsonStep.defaultVersion(); - public JacksonGradleConfig(JacksonConfig jacksonConfig, FormatExtension formatExtension) { + public AJacksonGradleConfig(JacksonConfig jacksonConfig, FormatExtension formatExtension) { this.formatExtension = formatExtension; this.jacksonConfig = jacksonConfig; formatExtension.addStep(createStep()); } - public JacksonGradleConfig(FormatExtension formatExtension) { - this(new JacksonConfig(), formatExtension); - } - - public JacksonGradleConfig config(JacksonConfig jacksonConfig) { - this.jacksonConfig = jacksonConfig; - formatExtension.replaceStep(createStep()); - return this; - } - - public JacksonGradleConfig feature(String feature, boolean toggle) { + public AJacksonGradleConfig feature(String feature, boolean toggle) { this.jacksonConfig.appendFeatureToToggle(Collections.singletonMap(feature, toggle)); formatExtension.replaceStep(createStep()); return this; } - public JacksonGradleConfig version(String version) { + public AJacksonGradleConfig version(String version) { this.version = version; formatExtension.replaceStep(createStep()); return this; diff --git a/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/JsonExtension.java b/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/JsonExtension.java index 31f605809c..94e94c639e 100644 --- a/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/JsonExtension.java +++ b/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/JsonExtension.java @@ -116,7 +116,7 @@ private FormatterStep createStep() { } } - public static class JacksonJsonGradleConfig extends JacksonGradleConfig { + public static class JacksonJsonGradleConfig extends AJacksonGradleConfig { protected JacksonJsonConfig jacksonConfig; public JacksonJsonGradleConfig(JacksonJsonConfig jacksonConfig, FormatExtension formatExtension) { @@ -135,7 +135,7 @@ public JacksonJsonGradleConfig(FormatExtension formatExtension) { /** * @see com.fasterxml.jackson.core.JsonGenerator.Feature */ - public JacksonGradleConfig jsonFeature(String feature, boolean toggle) { + public AJacksonGradleConfig jsonFeature(String feature, boolean toggle) { this.jacksonConfig.appendJsonFeatureToToggle(Collections.singletonMap(feature, toggle)); formatExtension.replaceStep(createStep()); return this; diff --git a/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/YamlExtension.java b/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/YamlExtension.java index 3fc12e0495..e5dc3d79ac 100644 --- a/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/YamlExtension.java +++ b/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/YamlExtension.java @@ -41,11 +41,11 @@ protected void setupTask(SpotlessTask task) { super.setupTask(task); } - public JacksonGradleConfig jacksonYaml() { + public AJacksonGradleConfig jacksonYaml() { return new JacksonYamlGradleConfig(this); } - public class JacksonYamlGradleConfig extends JacksonGradleConfig { + public class JacksonYamlGradleConfig extends AJacksonGradleConfig { protected JacksonYamlConfig jacksonConfig; public JacksonYamlGradleConfig(JacksonYamlConfig jacksonConfig, FormatExtension formatExtension) { @@ -65,7 +65,7 @@ public JacksonYamlGradleConfig(FormatExtension formatExtension) { /** * @see com.fasterxml.jackson.dataformat.yaml.YAMLGenerator.Feature */ - public JacksonGradleConfig yamlFeature(String feature, boolean toggle) { + public AJacksonGradleConfig yamlFeature(String feature, boolean toggle) { this.jacksonConfig.appendYamlFeatureToToggle(Collections.singletonMap(feature, toggle)); formatExtension.replaceStep(createStep()); return this; diff --git a/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/YamlExtensionTest.java b/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/YamlExtensionTest.java index 79e0df0d8d..618b8d17ca 100644 --- a/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/YamlExtensionTest.java +++ b/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/YamlExtensionTest.java @@ -51,8 +51,8 @@ void testFormatYaml_WithJackson_skipDocStartMarker() throws IOException { "spotless {", " yaml {", " target 'src/**/*.yaml'", - " jacksonYaml()" + - " .yamlFeature('WRITE_DOC_START_MARKER', false)" + + " jacksonYaml()" , + " .yamlFeature('WRITE_DOC_START_MARKER', false)" , " .yamlFeature('MINIMIZE_QUOTES', true)", " }", "}"); From 38bc206a73283d0ddff1d10bb1fb45b3493edff3 Mon Sep 17 00:00:00 2001 From: Benoit Lacelle Date: Wed, 18 Jan 2023 00:53:57 +0400 Subject: [PATCH 587/757] Fix style --- .../java/com/diffplug/gradle/spotless/YamlExtensionTest.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/YamlExtensionTest.java b/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/YamlExtensionTest.java index 618b8d17ca..ee5ee33366 100644 --- a/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/YamlExtensionTest.java +++ b/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/YamlExtensionTest.java @@ -51,8 +51,8 @@ void testFormatYaml_WithJackson_skipDocStartMarker() throws IOException { "spotless {", " yaml {", " target 'src/**/*.yaml'", - " jacksonYaml()" , - " .yamlFeature('WRITE_DOC_START_MARKER', false)" , + " jacksonYaml()", + " .yamlFeature('WRITE_DOC_START_MARKER', false)", " .yamlFeature('MINIMIZE_QUOTES', true)", " }", "}"); From b42a1453b385b4320072eaf654da1b6cc4d2297d Mon Sep 17 00:00:00 2001 From: Michael Ernst Date: Tue, 17 Jan 2023 12:54:28 -0800 Subject: [PATCH 588/757] Make changelog entries more informative --- CHANGES.md | 2 +- plugin-gradle/CHANGES.md | 2 +- plugin-maven/CHANGES.md | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/CHANGES.md b/CHANGES.md index 9c0ed23980..3e648d9e0c 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -12,7 +12,7 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format ( ## [Unreleased] ### Added ### Fixed -* Format more type annotations as type annotations [#1494](https://github.com/diffplug/spotless/pull/1494) +* The default list of type annotations used by `formatAnnotations` has had 8 more annotations from the Checker Framework added [#1494](https://github.com/diffplug/spotless/pull/1494) ### Changes ## [2.32.0] - 2023-01-13 diff --git a/plugin-gradle/CHANGES.md b/plugin-gradle/CHANGES.md index d3ee07acad..0ed49a3408 100644 --- a/plugin-gradle/CHANGES.md +++ b/plugin-gradle/CHANGES.md @@ -15,7 +15,7 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format ( * Prevent tool configurations from being resolved outside project ([#1447](https://github.com/diffplug/spotless/pull/1447) fixes [#1215](https://github.com/diffplug/spotless/issues/1215)) * Support `ktlint` 0.48+ new rule disabling syntax ([#1456](https://github.com/diffplug/spotless/pull/1456)) fixes ([#1444](https://github.com/diffplug/spotless/issues/1444)) * Fix subgroups leading catch all matcher. -* Format more type annotations as type annotations [#1494](https://github.com/diffplug/spotless/pull/1494) +* The default list of type annotations used by `formatAnnotations` has had 8 more annotations from the Checker Framework added [#1494](https://github.com/diffplug/spotless/pull/1494) ### Changes * Bump default `ktlint` version to latest `0.47.1` -> `0.48.1` ([#1456](https://github.com/diffplug/spotless/pull/1456)) * Bump default version for `prettier` from `2.0.5` to `2.8.1` ([#1453](https://github.com/diffplug/spotless/pull/1453)) diff --git a/plugin-maven/CHANGES.md b/plugin-maven/CHANGES.md index d7d40f65c7..d0942d2ca8 100644 --- a/plugin-maven/CHANGES.md +++ b/plugin-maven/CHANGES.md @@ -16,7 +16,7 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format ( ### Fixed * Support `ktlint` 0.48+ new rule disabling syntax ([#1456](https://github.com/diffplug/spotless/pull/1456)) fixes ([#1444](https://github.com/diffplug/spotless/issues/1444)) * Fix subgroups leading catch all matcher. -* Format more type annotations as type annotations [#1494](https://github.com/diffplug/spotless/pull/1494) +* The default list of type annotations used by `formatAnnotations` has had 8 more annotations from the Checker Framework added [#1494](https://github.com/diffplug/spotless/pull/1494) ### Changes * Bump default `ktlint` version to latest `0.47.1` -> `0.48.1` ([#1456](https://github.com/diffplug/spotless/pull/1456)) * Reduce spurious invalidations of the up-to-date index file ([#1461](https://github.com/diffplug/spotless/pull/1461)) From 4ff0c33c8055fb661680724db0ddba265d0de6eb Mon Sep 17 00:00:00 2001 From: Michael Ernst Date: Tue, 17 Jan 2023 12:57:39 -0800 Subject: [PATCH 589/757] Put changelog entries in "unreleased" section --- plugin-gradle/CHANGES.md | 5 ++++- plugin-maven/CHANGES.md | 5 ++++- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/plugin-gradle/CHANGES.md b/plugin-gradle/CHANGES.md index 0ed49a3408..63e5b43d74 100644 --- a/plugin-gradle/CHANGES.md +++ b/plugin-gradle/CHANGES.md @@ -3,6 +3,10 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format (starting after version `3.27.0`). ## [Unreleased] +### Added +### Fixed +* The default list of type annotations used by `formatAnnotations` has had 8 more annotations from the Checker Framework added [#1494](https://github.com/diffplug/spotless/pull/1494) +### Changes ## [6.13.0] - 2023-01-14 ### Added @@ -15,7 +19,6 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format ( * Prevent tool configurations from being resolved outside project ([#1447](https://github.com/diffplug/spotless/pull/1447) fixes [#1215](https://github.com/diffplug/spotless/issues/1215)) * Support `ktlint` 0.48+ new rule disabling syntax ([#1456](https://github.com/diffplug/spotless/pull/1456)) fixes ([#1444](https://github.com/diffplug/spotless/issues/1444)) * Fix subgroups leading catch all matcher. -* The default list of type annotations used by `formatAnnotations` has had 8 more annotations from the Checker Framework added [#1494](https://github.com/diffplug/spotless/pull/1494) ### Changes * Bump default `ktlint` version to latest `0.47.1` -> `0.48.1` ([#1456](https://github.com/diffplug/spotless/pull/1456)) * Bump default version for `prettier` from `2.0.5` to `2.8.1` ([#1453](https://github.com/diffplug/spotless/pull/1453)) diff --git a/plugin-maven/CHANGES.md b/plugin-maven/CHANGES.md index d0942d2ca8..e951241a09 100644 --- a/plugin-maven/CHANGES.md +++ b/plugin-maven/CHANGES.md @@ -3,6 +3,10 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format (starting after version `1.27.0`). ## [Unreleased] +### Added +### Fixed +* The default list of type annotations used by `formatAnnotations` has had 8 more annotations from the Checker Framework added [#1494](https://github.com/diffplug/spotless/pull/1494) +### Changes ## [2.30.0] - 2023-01-13 ### Added @@ -16,7 +20,6 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format ( ### Fixed * Support `ktlint` 0.48+ new rule disabling syntax ([#1456](https://github.com/diffplug/spotless/pull/1456)) fixes ([#1444](https://github.com/diffplug/spotless/issues/1444)) * Fix subgroups leading catch all matcher. -* The default list of type annotations used by `formatAnnotations` has had 8 more annotations from the Checker Framework added [#1494](https://github.com/diffplug/spotless/pull/1494) ### Changes * Bump default `ktlint` version to latest `0.47.1` -> `0.48.1` ([#1456](https://github.com/diffplug/spotless/pull/1456)) * Reduce spurious invalidations of the up-to-date index file ([#1461](https://github.com/diffplug/spotless/pull/1461)) From 87c4a2a23fc9a3e74fd7e525d31dc8e41c9c852d Mon Sep 17 00:00:00 2001 From: Ned Twigg Date: Tue, 17 Jan 2023 14:42:24 -0800 Subject: [PATCH 590/757] Remove mvnw beacuse we don't need it here anymore. --- plugin-maven/build.gradle | 17 ----------------- 1 file changed, 17 deletions(-) diff --git a/plugin-maven/build.gradle b/plugin-maven/build.gradle index b46cdda708..1fad11be70 100644 --- a/plugin-maven/build.gradle +++ b/plugin-maven/build.gradle @@ -11,23 +11,6 @@ version = spotlessChangelog.versionNext apply from: rootProject.file("gradle/java-setup.gradle") apply from: rootProject.file('gradle/spotless-freshmark.gradle') -def mvnw(String args) { - boolean isWin = System.getProperty('os.name').toLowerCase().contains('win') - if (isWin) { - return [ - 'cmd', - '/c', - 'mvnw.cmd -e ' + args - ] - } else { - return [ - '/bin/sh', - '-c', - './mvnw -e ' + args - ] - } -} - apply plugin: 'de.benediktritter.maven-plugin-development' mavenPlugin { name = 'Spotless Maven Plugin' From c3a88cb2df3e1ddae20e388f5fbbdffee48e2e05 Mon Sep 17 00:00:00 2001 From: Ned Twigg Date: Tue, 17 Jan 2023 14:43:08 -0800 Subject: [PATCH 591/757] Inline the mustache dependency because it's only used in one place. --- plugin-maven/build.gradle | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/plugin-maven/build.gradle b/plugin-maven/build.gradle index 1fad11be70..ad51318d93 100644 --- a/plugin-maven/build.gradle +++ b/plugin-maven/build.gradle @@ -20,7 +20,6 @@ mavenPlugin { String VER_MAVEN_API = '3.0' String VER_ECLIPSE_AETHER = '1.1.0' -String VER_MUSTACHE = '0.9.10' String VER_PLEXUS_RESOURCES = '1.2.0' dependencies { implementation project(':lib') @@ -42,7 +41,7 @@ dependencies { testImplementation "org.assertj:assertj-core:${VER_ASSERTJ}" testImplementation "org.mockito:mockito-core:${VER_MOCKITO}" testImplementation "com.diffplug.durian:durian-io:${VER_DURIAN}" - testImplementation "com.github.spullara.mustache.java:compiler:${VER_MUSTACHE}" + testImplementation 'com.github.spullara.mustache.java:compiler:0.9.10' testImplementation "org.apache.maven:maven-plugin-api:${VER_MAVEN_API}" testImplementation "org.eclipse.aether:aether-api:${VER_ECLIPSE_AETHER}" testImplementation "org.codehaus.plexus:plexus-resources:${VER_PLEXUS_RESOURCES}" From b256bd48ef418e0f4c04e8409bcca357964c25b3 Mon Sep 17 00:00:00 2001 From: Ned Twigg Date: Tue, 17 Jan 2023 14:48:42 -0800 Subject: [PATCH 592/757] Fix testlib test. --- testlib/build.gradle | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/testlib/build.gradle b/testlib/build.gradle index 4b16572a8c..64d4681805 100644 --- a/testlib/build.gradle +++ b/testlib/build.gradle @@ -22,6 +22,15 @@ dependencies { spotbugs { reportLevel = 'high' } // low|medium|high (low = sensitive to even minor mistakes) apply from: rootProject.file('gradle/special-tests.gradle') +tasks.named('test') { + if (JavaVersion.current().isCompatibleWith(JavaVersion.VERSION_16)) { + // for Antlr4FormatterStepTest and KtLintStepTest + def args = [ + '--add-opens=java.base/java.lang=ALL-UNNAMED' + ] + jvmArgs args + } +} javadoc { options.addStringOption('Xdoclint:none', '-quiet') From 4b2097c3ed3a1ef7ee9550aa20e7a02948106b07 Mon Sep 17 00:00:00 2001 From: Ned Twigg Date: Tue, 17 Jan 2023 15:25:09 -0800 Subject: [PATCH 593/757] Update changelogs. --- CHANGES.md | 6 ++++-- lib/build.gradle | 3 +++ plugin-gradle/CHANGES.md | 6 ++++-- plugin-maven/CHANGES.md | 6 ++++-- 4 files changed, 15 insertions(+), 6 deletions(-) diff --git a/CHANGES.md b/CHANGES.md index 45627807f3..0bdcf657b2 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -15,6 +15,10 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format ( ### Fixed * The default list of type annotations used by `formatAnnotations` has had 8 more annotations from the Checker Framework added [#1494](https://github.com/diffplug/spotless/pull/1494) ### Changes +#### Removed +* Removed support for KtLint 0.3x and 0.45.2 ([#1475](https://github.com/diffplug/spotless/pull/1475)) + * `KtLint` does not maintain a stable API - before this PR, we supported every breaking change in the API since 2019. + * From now on, we will support no more than 2 breaking changes at a time. ## [2.32.0] - 2023-01-13 ### Added @@ -39,8 +43,6 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format ( * Bump default `ktlint` version to latest `0.47.1` -> `0.48.1` ([#1456](https://github.com/diffplug/spotless/pull/1456)) * Switch our publishing infrastructure from CircleCI to GitHub Actions ([#1462](https://github.com/diffplug/spotless/pull/1462)). * Help wanted for moving our tests too ([#1472](https://github.com/diffplug/spotless/issues/1472)) -#### Removed -* Removed support for KtLint 0.3x and 0.45.2 ([#1475](https://github.com/diffplug/spotless/pull/1475)) ## [2.31.1] - 2023-01-02 ### Fixed diff --git a/lib/build.gradle b/lib/build.gradle index 7e2496139c..fc2c1c04a0 100644 --- a/lib/build.gradle +++ b/lib/build.gradle @@ -28,6 +28,9 @@ for (glue in NEEDS_GLUE) { versionCompatibility { adapters { namespaces.register('KtLint') { + // as discussed at https://github.com/diffplug/spotless/pull/1475 + // we will support no more than 2 breaking changes at a time = 3 incompatible versions + // we will try to drop down to only one version if a stable API can be maintained for a full year versions = [ '0.46.0', '0.47.0', diff --git a/plugin-gradle/CHANGES.md b/plugin-gradle/CHANGES.md index 84fc0f4d83..bc4f2bd5e5 100644 --- a/plugin-gradle/CHANGES.md +++ b/plugin-gradle/CHANGES.md @@ -7,6 +7,10 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format ( ### Fixed * The default list of type annotations used by `formatAnnotations` has had 8 more annotations from the Checker Framework added [#1494](https://github.com/diffplug/spotless/pull/1494) ### Changes +#### Removed +* Removed support for KtLint 0.3x and 0.45.2 ([#1475](https://github.com/diffplug/spotless/pull/1475)) + * `KtLint` does not maintain a stable API - before this PR, we supported every breaking change in the API since 2019. + * From now on, we will support no more than 2 breaking changes at a time. ## [6.13.0] - 2023-01-14 ### Added @@ -22,8 +26,6 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format ( ### Changes * Bump default `ktlint` version to latest `0.47.1` -> `0.48.1` ([#1456](https://github.com/diffplug/spotless/pull/1456)) * Bump default version for `prettier` from `2.0.5` to `2.8.1` ([#1453](https://github.com/diffplug/spotless/pull/1453)) -#### Removed -* Removed support for KtLint 0.3x and 0.45.2 ([#1475](https://github.com/diffplug/spotless/pull/1475)) ## [6.12.1] - 2023-01-02 ### Fixed diff --git a/plugin-maven/CHANGES.md b/plugin-maven/CHANGES.md index 7556875183..ce07394b98 100644 --- a/plugin-maven/CHANGES.md +++ b/plugin-maven/CHANGES.md @@ -8,6 +8,10 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format ( * The default list of type annotations used by `formatAnnotations` has had 8 more annotations from the Checker Framework added [#1494](https://github.com/diffplug/spotless/pull/1494) ### Changes * Spotless' custom build was replaced by [`maven-plugin-development`](https://github.com/britter/maven-plugin-development). ([#1496](https://github.com/diffplug/spotless/pull/1496) fixes [#554](https://github.com/diffplug/spotless/issues/554)) +#### Removed +* Removed support for KtLint 0.3x and 0.45.2 ([#1475](https://github.com/diffplug/spotless/pull/1475)) + * `KtLint` does not maintain a stable API - before this PR, we supported every breaking change in the API since 2019. + * From now on, we will support no more than 2 breaking changes at a time. ## [2.30.0] - 2023-01-13 ### Added @@ -25,8 +29,6 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format ( * Bump default `ktlint` version to latest `0.47.1` -> `0.48.1` ([#1456](https://github.com/diffplug/spotless/pull/1456)) * Reduce spurious invalidations of the up-to-date index file ([#1461](https://github.com/diffplug/spotless/pull/1461)) * Bump default version for `prettier` from `2.0.5` to `2.8.1` ([#1453](https://github.com/diffplug/spotless/pull/1453)) -#### Removed -* Removed support for KtLint 0.3x and 0.45.2 ([#1475](https://github.com/diffplug/spotless/pull/1475)) ## [2.29.0] - 2023-01-02 ### Added From 949c0984671a3092219d0e7674d885bbe160f51a Mon Sep 17 00:00:00 2001 From: Benoit Lacelle Date: Wed, 18 Jan 2023 09:35:44 +0400 Subject: [PATCH 594/757] Fix Yaml referring to Json --- .../com/diffplug/gradle/spotless/SpotlessExtension.java | 2 +- plugin-maven/CHANGES.md | 6 +++++- 2 files changed, 6 insertions(+), 2 deletions(-) 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 8c3128e02d..0a31a15764 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 @@ -196,7 +196,7 @@ public void json(Action closure) { /** Configures the special YAML-specific extension. */ public void yaml(Action closure) { requireNonNull(closure); - format(JsonExtension.NAME, YamlExtension.class, closure); + format(YamlExtension.NAME, YamlExtension.class, closure); } /** Configures a custom extension. */ diff --git a/plugin-maven/CHANGES.md b/plugin-maven/CHANGES.md index 97eea5d7c0..cba82652cc 100644 --- a/plugin-maven/CHANGES.md +++ b/plugin-maven/CHANGES.md @@ -4,12 +4,16 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format ( ## [Unreleased] ### Added +* Introduce `` ([#1492](https://github.com/diffplug/spotless/pull/1492)) + * **POTENTIALLY BREAKING** `JacksonYaml` is now configured with a `Map` to configure features +* Jackson (`json` and `yaml`) has new `spaceBeforeSeparator` option + * **POTENTIALLY BREAKING** `spaceBeforeSeparator` is defaulted to false while the formatter was behaving with `true` ### Fixed * The default list of type annotations used by `formatAnnotations` has had 8 more annotations from the Checker Framework added [#1494](https://github.com/diffplug/spotless/pull/1494) ### Changes * Spotless' custom build was replaced by [`maven-plugin-development`](https://github.com/britter/maven-plugin-development). ([#1496](https://github.com/diffplug/spotless/pull/1496) fixes [#554](https://github.com/diffplug/spotless/issues/554)) -# [2.30.0] - 2023-01-13 +## [2.30.0] - 2023-01-13 ### Added * Add option `editorConfigFile` for `ktLint` [#142](https://github.com/diffplug/spotless/issues/142) * **POTENTIALLY BREAKING** `ktlint` step now modifies license headers. Make sure to put `licenseHeader` *after* `ktlint`. From 37875ce62ef876c08a6357a191aa2abf80221f38 Mon Sep 17 00:00:00 2001 From: Benoit Lacelle Date: Wed, 18 Jan 2023 10:28:10 +0400 Subject: [PATCH 595/757] Rename to jackson step for both yaml and json --- .../com/diffplug/spotless/yaml/JacksonYamlStep.java | 6 ++---- .../gradle/spotless/AJacksonGradleConfig.java | 2 +- .../com/diffplug/gradle/spotless/JsonExtension.java | 12 ++++-------- .../com/diffplug/gradle/spotless/YamlExtension.java | 10 +++++----- .../diffplug/gradle/spotless/JsonExtensionTest.java | 2 +- .../diffplug/gradle/spotless/YamlExtensionTest.java | 6 +++--- ...ith_bracket.clean.no_start_marker.no_quotes.yaml} | 0 7 files changed, 16 insertions(+), 22 deletions(-) rename testlib/src/main/resources/yaml/{array_with_bracket.clean.no_start_marker.yaml => array_with_bracket.clean.no_start_marker.no_quotes.yaml} (100%) diff --git a/lib/src/main/java/com/diffplug/spotless/yaml/JacksonYamlStep.java b/lib/src/main/java/com/diffplug/spotless/yaml/JacksonYamlStep.java index 201199fe8b..a87e40f420 100644 --- a/lib/src/main/java/com/diffplug/spotless/yaml/JacksonYamlStep.java +++ b/lib/src/main/java/com/diffplug/spotless/yaml/JacksonYamlStep.java @@ -30,6 +30,7 @@ * Simple YAML formatter which reformats the file according to Jackson YAMLFactory. */ // https://stackoverflow.com/questions/14515994/convert-json-string-to-pretty-print-json-output-using-jackson +// https://stackoverflow.com/questions/60891174/i-want-to-load-a-yaml-file-possibly-edit-the-data-and-then-dump-it-again-how public class JacksonYamlStep { static final String MAVEN_COORDINATE = "com.fasterxml.jackson.dataformat:jackson-dataformat-yaml:"; // https://mvnrepository.com/artifact/com.fasterxml.jackson.dataformat/jackson-dataformat-yaml @@ -44,6 +45,7 @@ public static String defaultVersion() { public static FormatterStep create(JacksonYamlConfig jacksonConfig, String jacksonVersion, Provisioner provisioner) { + Objects.requireNonNull(jacksonConfig, "jacksonConfig cannot be null"); Objects.requireNonNull(provisioner, "provisioner cannot be null"); return FormatterStep.createLazy("yaml", () -> new State(jacksonConfig, jacksonVersion, provisioner), @@ -66,10 +68,6 @@ private State(JacksonYamlConfig jacksonConfig, Provisioner provisioner) throws IOException { this.jacksonConfig = jacksonConfig; - if (jacksonConfig == null) { - throw new IllegalArgumentException("ARG"); - } - this.jarState = JarState.from(JacksonYamlStep.MAVEN_COORDINATE + jacksonVersion, provisioner); } diff --git a/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/AJacksonGradleConfig.java b/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/AJacksonGradleConfig.java index e3d5cee661..c017d41d04 100644 --- a/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/AJacksonGradleConfig.java +++ b/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/AJacksonGradleConfig.java @@ -28,11 +28,11 @@ public abstract class AJacksonGradleConfig { protected String version = JacksonJsonStep.defaultVersion(); + // Make sure to call 'formatExtension.addStep(createStep());' in the extented constructors public AJacksonGradleConfig(JacksonConfig jacksonConfig, FormatExtension formatExtension) { this.formatExtension = formatExtension; this.jacksonConfig = jacksonConfig; - formatExtension.addStep(createStep()); } public AJacksonGradleConfig feature(String feature, boolean toggle) { diff --git a/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/JsonExtension.java b/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/JsonExtension.java index 94e94c639e..b964fcb54d 100644 --- a/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/JsonExtension.java +++ b/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/JsonExtension.java @@ -51,7 +51,7 @@ public GsonConfig gson() { return new GsonConfig(); } - public JacksonJsonGradleConfig jacksonJson() { + public JacksonJsonGradleConfig jackson() { return new JacksonJsonGradleConfig(this); } @@ -123,9 +123,7 @@ public JacksonJsonGradleConfig(JacksonJsonConfig jacksonConfig, FormatExtension super(jacksonConfig, formatExtension); this.jacksonConfig = jacksonConfig; - if (jacksonConfig == null) { - throw new IllegalArgumentException("ARG2"); - } + formatExtension.addStep(createStep()); } public JacksonJsonGradleConfig(FormatExtension formatExtension) { @@ -141,11 +139,9 @@ public AJacksonGradleConfig jsonFeature(String feature, boolean toggle) { return this; } + // 'final' as it is called in the constructor @Override - protected FormatterStep createStep() { - if (jacksonConfig == null) { - throw new IllegalArgumentException("ARG3"); - } + protected final FormatterStep createStep() { return JacksonJsonStep.create(jacksonConfig, version, formatExtension.provisioner()); } } diff --git a/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/YamlExtension.java b/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/YamlExtension.java index e5dc3d79ac..26b742f02a 100644 --- a/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/YamlExtension.java +++ b/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/YamlExtension.java @@ -19,6 +19,7 @@ import javax.inject.Inject; +import com.diffplug.common.base.Throwables; import com.diffplug.spotless.FormatterStep; import com.diffplug.spotless.json.JacksonJsonStep; import com.diffplug.spotless.yaml.JacksonYamlConfig; @@ -41,7 +42,7 @@ protected void setupTask(SpotlessTask task) { super.setupTask(task); } - public AJacksonGradleConfig jacksonYaml() { + public AJacksonGradleConfig jackson() { return new JacksonYamlGradleConfig(this); } @@ -53,9 +54,7 @@ public JacksonYamlGradleConfig(JacksonYamlConfig jacksonConfig, FormatExtension this.jacksonConfig = jacksonConfig; - if (jacksonConfig == null) { - throw new IllegalArgumentException("ARG"); - } + formatExtension.addStep(createStep()); } public JacksonYamlGradleConfig(FormatExtension formatExtension) { @@ -71,8 +70,9 @@ public AJacksonGradleConfig yamlFeature(String feature, boolean toggle) { return this; } + // 'final' as it is called in the constructor @Override - protected FormatterStep createStep() { + protected final FormatterStep createStep() { return JacksonYamlStep.create(jacksonConfig, version, provisioner()); } } diff --git a/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/JsonExtensionTest.java b/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/JsonExtensionTest.java index 945c72cf75..a878615eaa 100644 --- a/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/JsonExtensionTest.java +++ b/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/JsonExtensionTest.java @@ -149,7 +149,7 @@ void jacksonFormattingWithSortingByKeys() throws IOException { "spotless {", " json {", " target 'src/**/*.json'", - " jacksonJson().feature('ORDER_MAP_ENTRIES_BY_KEYS', true)", + " jackson().feature('ORDER_MAP_ENTRIES_BY_KEYS', true)", " }", "}"); setFile("src/main/resources/example.json").toResource("json/sortByKeysBefore.json"); diff --git a/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/YamlExtensionTest.java b/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/YamlExtensionTest.java index ee5ee33366..455dfc6dcf 100644 --- a/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/YamlExtensionTest.java +++ b/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/YamlExtensionTest.java @@ -31,7 +31,7 @@ void testFormatYaml_WithJackson_defaultConfig_separatorComments() throws IOExcep "spotless {", " yaml {", " target 'src/**/*.yaml'", - " jacksonYaml()", + " jackson()", " }", "}"); setFile("src/main/resources/example.yaml").toResource("yaml/separator_comments.yaml"); @@ -51,14 +51,14 @@ void testFormatYaml_WithJackson_skipDocStartMarker() throws IOException { "spotless {", " yaml {", " target 'src/**/*.yaml'", - " jacksonYaml()", + " jackson()", " .yamlFeature('WRITE_DOC_START_MARKER', false)", " .yamlFeature('MINIMIZE_QUOTES', true)", " }", "}"); setFile("src/main/resources/example.yaml").toResource("yaml/array_with_bracket.yaml"); gradleRunner().withArguments("spotlessApply").build(); - assertFile("src/main/resources/example.yaml").sameAsResource("yaml/array_with_bracket.clean.no_start_marker.yaml"); + assertFile("src/main/resources/example.yaml").sameAsResource("yaml/array_with_bracket.clean.no_start_marker.no_quotes.yaml"); } } diff --git a/testlib/src/main/resources/yaml/array_with_bracket.clean.no_start_marker.yaml b/testlib/src/main/resources/yaml/array_with_bracket.clean.no_start_marker.no_quotes.yaml similarity index 100% rename from testlib/src/main/resources/yaml/array_with_bracket.clean.no_start_marker.yaml rename to testlib/src/main/resources/yaml/array_with_bracket.clean.no_start_marker.no_quotes.yaml From a22109e5e4b3e7daf4ae41b308d39bead18a06ef Mon Sep 17 00:00:00 2001 From: Benoit Lacelle Date: Wed, 18 Jan 2023 10:41:53 +0400 Subject: [PATCH 596/757] spotlessApply --- .../spotless/glue/yaml/JacksonYamlFormatterFunc.java | 5 ----- .../java/com/diffplug/gradle/spotless/YamlExtension.java | 1 - .../java/com/diffplug/gradle/spotless/YamlExtensionTest.java | 2 +- plugin-maven/README.md | 4 ++-- .../test/java/com/diffplug/spotless/maven/yaml/YamlTest.java | 1 - 5 files changed, 3 insertions(+), 10 deletions(-) diff --git a/lib/src/jackson/java/com/diffplug/spotless/glue/yaml/JacksonYamlFormatterFunc.java b/lib/src/jackson/java/com/diffplug/spotless/glue/yaml/JacksonYamlFormatterFunc.java index 3986374c9e..0cf4591717 100644 --- a/lib/src/jackson/java/com/diffplug/spotless/glue/yaml/JacksonYamlFormatterFunc.java +++ b/lib/src/jackson/java/com/diffplug/spotless/glue/yaml/JacksonYamlFormatterFunc.java @@ -57,11 +57,6 @@ protected JsonFactory makeJsonFactory() { @Override protected String format(ObjectMapper objectMapper, String input) throws IllegalArgumentException, IOException { - // We may consider adding manually an initial '---' prefix to help management of multiple documents - // if (!input.trim().startsWith("---")) { - // input = "---" + "\n" + input; - // } - try { // https://stackoverflow.com/questions/25222327/deserialize-pojos-from-multiple-yaml-documents-in-a-single-file-in-jackson // https://github.com/FasterXML/jackson-dataformats-text/issues/66#issuecomment-375328648 diff --git a/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/YamlExtension.java b/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/YamlExtension.java index 26b742f02a..bf268914fc 100644 --- a/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/YamlExtension.java +++ b/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/YamlExtension.java @@ -19,7 +19,6 @@ import javax.inject.Inject; -import com.diffplug.common.base.Throwables; import com.diffplug.spotless.FormatterStep; import com.diffplug.spotless.json.JacksonJsonStep; import com.diffplug.spotless.yaml.JacksonYamlConfig; diff --git a/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/YamlExtensionTest.java b/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/YamlExtensionTest.java index 455dfc6dcf..7baddc4177 100644 --- a/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/YamlExtensionTest.java +++ b/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/YamlExtensionTest.java @@ -57,7 +57,7 @@ void testFormatYaml_WithJackson_skipDocStartMarker() throws IOException { " }", "}"); setFile("src/main/resources/example.yaml").toResource("yaml/array_with_bracket.yaml"); - gradleRunner().withArguments("spotlessApply").build(); + gradleRunner().withArguments("spotlessApply", "--stacktrace").build(); assertFile("src/main/resources/example.yaml").sameAsResource("yaml/array_with_bracket.clean.no_start_marker.no_quotes.yaml"); } diff --git a/plugin-maven/README.md b/plugin-maven/README.md index e76d424611..7673a440c6 100644 --- a/plugin-maven/README.md +++ b/plugin-maven/README.md @@ -12,8 +12,8 @@ output = [ ].join('\n'); --> [![Maven central](https://img.shields.io/badge/mavencentral-com.diffplug.spotless%3Aspotless--maven--plugin-blue.svg)](https://search.maven.org/#search%7Cgav%7C1%7Cg%3A%22com.diffplug.spotless%22%20AND%20a%3A%22spotless-maven-plugin%22) -[![Javadoc](https://img.shields.io/badge/javadoc-yes-blue.svg)](https://javadoc.io/doc/com.diffplug.spotless/spotless-maven-plugin/2.29.0/index.html) -[![Changelog](https://img.shields.io/badge/changelog-2.29.0-brightgreen.svg)](CHANGES.md) +[![Javadoc](https://img.shields.io/badge/javadoc-yes-blue.svg)](https://javadoc.io/doc/com.diffplug.spotless/spotless-maven-plugin/2.30.0/index.html) +[![Changelog](https://img.shields.io/badge/changelog-2.30.0-brightgreen.svg)](CHANGES.md) [![Circle CI](https://circleci.com/gh/diffplug/spotless/tree/main.svg?style=shield)](https://circleci.com/gh/diffplug/spotless/tree/main) [![Live chat](https://img.shields.io/badge/gitter-chat-brightgreen.svg)](https://gitter.im/diffplug/spotless) diff --git a/plugin-maven/src/test/java/com/diffplug/spotless/maven/yaml/YamlTest.java b/plugin-maven/src/test/java/com/diffplug/spotless/maven/yaml/YamlTest.java index 084f1495eb..aaea2c65b1 100644 --- a/plugin-maven/src/test/java/com/diffplug/spotless/maven/yaml/YamlTest.java +++ b/plugin-maven/src/test/java/com/diffplug/spotless/maven/yaml/YamlTest.java @@ -19,7 +19,6 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import com.diffplug.spotless.ProcessRunner; import com.diffplug.spotless.maven.MavenIntegrationHarness; public class YamlTest extends MavenIntegrationHarness { From 7bc34f48328a42bdc26a58c2b1d22f2b68892256 Mon Sep 17 00:00:00 2001 From: Benoit Lacelle Date: Wed, 18 Jan 2023 11:46:36 +0400 Subject: [PATCH 597/757] Switch from ObjectNode to Map to enable SerializationFeature.ORDER_MAP_ENTRIES_BY_KEYS --- .../glue/json/AJacksonFormatterFunc.java | 16 ++++++++------ .../glue/json/JacksonJsonFormatterFunc.java | 2 +- .../diffplug/spotless/json/JacksonConfig.java | 2 +- .../spotless/json/JacksonJsonConfig.java | 4 ++-- .../spotless/yaml/JacksonYamlConfig.java | 4 ++-- .../gradle/spotless/JsonExtension.java | 2 +- .../gradle/spotless/YamlExtension.java | 3 +-- .../spotless/maven/json/JsonTest.java | 2 +- .../spotless/maven/yaml/YamlTest.java | 9 -------- .../json/sortByKeysAfter_Jackson.json | 22 ++++++++----------- ...sAfter_Jackson_spaceAfterKeySeparator.json | 22 ++++++++----------- ...th_bracket.clean.spaceBeforeSeparator.yaml | 12 ---------- 12 files changed, 36 insertions(+), 64 deletions(-) delete mode 100644 testlib/src/main/resources/yaml/array_with_bracket.clean.spaceBeforeSeparator.yaml diff --git a/lib/src/jackson/java/com/diffplug/spotless/glue/json/AJacksonFormatterFunc.java b/lib/src/jackson/java/com/diffplug/spotless/glue/json/AJacksonFormatterFunc.java index a835c85f9a..a41ecf90d2 100644 --- a/lib/src/jackson/java/com/diffplug/spotless/glue/json/AJacksonFormatterFunc.java +++ b/lib/src/jackson/java/com/diffplug/spotless/glue/json/AJacksonFormatterFunc.java @@ -16,10 +16,11 @@ package com.diffplug.spotless.glue.json; import java.io.IOException; +import java.util.Map; import com.fasterxml.jackson.core.JsonFactory; -import com.fasterxml.jackson.core.JsonGenerator; import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.core.PrettyPrinter; import com.fasterxml.jackson.core.util.DefaultPrettyPrinter; import com.fasterxml.jackson.databind.ObjectMapper; import com.fasterxml.jackson.databind.SerializationFeature; @@ -48,8 +49,11 @@ public String apply(String input) throws Exception { protected String format(ObjectMapper objectMapper, String input) throws IllegalArgumentException, IOException { try { - ObjectNode objectNode = objectMapper.readValue(input, ObjectNode.class); - return objectMapper.writerWithDefaultPrettyPrinter().writeValueAsString(objectNode); + // ObjectNode is not compatible with SerializationFeature.ORDER_MAP_ENTRIES_BY_KEYS + Map objectNode = objectMapper.readValue(input, Map.class); + String output = objectMapper.writerWithDefaultPrettyPrinter().writeValueAsString(objectNode); + + return output; } catch (JsonProcessingException e) { throw new AssertionError("Unable to format. input='" + input + "'", e); } @@ -65,7 +69,7 @@ protected ObjectMapper makeObjectMapper() { JsonFactory jsonFactory = makeJsonFactory(); ObjectMapper objectMapper = new ObjectMapper(jsonFactory); - objectMapper.setDefaultPrettyPrinter(makePrinter()); + objectMapper.setDefaultPrettyPrinter(makePrettyPrinter()); // Configure the ObjectMapper // https://github.com/FasterXML/jackson-databind#commonly-used-features @@ -76,12 +80,10 @@ protected ObjectMapper makeObjectMapper() { objectMapper.configure(feature, toggle); }); - new JsonFactory().configure(JsonGenerator.Feature.AUTO_CLOSE_JSON_CONTENT, true); - return objectMapper; } - protected DefaultPrettyPrinter makePrinter() { + protected PrettyPrinter makePrettyPrinter() { return new DefaultPrettyPrinter(); } } diff --git a/lib/src/jackson/java/com/diffplug/spotless/glue/json/JacksonJsonFormatterFunc.java b/lib/src/jackson/java/com/diffplug/spotless/glue/json/JacksonJsonFormatterFunc.java index 5aadcc568f..ae455fbbb4 100644 --- a/lib/src/jackson/java/com/diffplug/spotless/glue/json/JacksonJsonFormatterFunc.java +++ b/lib/src/jackson/java/com/diffplug/spotless/glue/json/JacksonJsonFormatterFunc.java @@ -57,7 +57,7 @@ protected JsonFactory makeJsonFactory() { } @Override - protected DefaultPrettyPrinter makePrinter() { + protected DefaultPrettyPrinter makePrettyPrinter() { boolean spaceBeforeSeparator = jacksonConfig.isSpaceBeforeSeparator(); // DefaultIndenter default constructor relies on 2 whitespaces as default tabulation diff --git a/lib/src/main/java/com/diffplug/spotless/json/JacksonConfig.java b/lib/src/main/java/com/diffplug/spotless/json/JacksonConfig.java index 250b77d1f1..f0dba8f072 100644 --- a/lib/src/main/java/com/diffplug/spotless/json/JacksonConfig.java +++ b/lib/src/main/java/com/diffplug/spotless/json/JacksonConfig.java @@ -36,7 +36,7 @@ public class JacksonConfig implements Serializable { DEFAULT_FEATURE_TOGGLES = defaultFeatureToggles; } - protected Map featureToToggle = new LinkedHashMap<>(); + protected Map featureToToggle = new LinkedHashMap<>(DEFAULT_FEATURE_TOGGLES); public Map getFeatureToToggle() { return Collections.unmodifiableMap(featureToToggle); diff --git a/lib/src/main/java/com/diffplug/spotless/json/JacksonJsonConfig.java b/lib/src/main/java/com/diffplug/spotless/json/JacksonJsonConfig.java index 50b28605d1..efff594663 100644 --- a/lib/src/main/java/com/diffplug/spotless/json/JacksonJsonConfig.java +++ b/lib/src/main/java/com/diffplug/spotless/json/JacksonJsonConfig.java @@ -36,14 +36,14 @@ public Map getJsonFeatureToToggle() { } /** - * @see com.fasterxml.jackson.core.JsonGenerator.Feature + * Refers to com.fasterxml.jackson.core.JsonGenerator.Feature */ public void setJsonFeatureToToggle(Map jsonFeatureToToggle) { this.jsonFeatureToToggle = jsonFeatureToToggle; } /** - * @see com.fasterxml.jackson.core.JsonGenerator.Feature + * Refers to com.fasterxml.jackson.core.JsonGenerator.Feature */ public void appendJsonFeatureToToggle(Map features) { this.jsonFeatureToToggle.putAll(features); diff --git a/lib/src/main/java/com/diffplug/spotless/yaml/JacksonYamlConfig.java b/lib/src/main/java/com/diffplug/spotless/yaml/JacksonYamlConfig.java index 2463b9603f..166ee5f307 100644 --- a/lib/src/main/java/com/diffplug/spotless/yaml/JacksonYamlConfig.java +++ b/lib/src/main/java/com/diffplug/spotless/yaml/JacksonYamlConfig.java @@ -34,14 +34,14 @@ public Map getYamlFeatureToToggle() { } /** - * @see com.fasterxml.jackson.dataformat.yaml.YAMLGenerator.Feature + * Refers to com.fasterxml.jackson.dataformat.yaml.YAMLGenerator.Feature */ public void setYamlFeatureToToggle(Map yamlFeatureToToggle) { this.yamlFeatureToToggle = yamlFeatureToToggle; } /** - * @see com.fasterxml.jackson.dataformat.yaml.YAMLGenerator.Feature + * Refers to com.fasterxml.jackson.dataformat.yaml.YAMLGenerator.Feature */ public void appendYamlFeatureToToggle(Map features) { this.yamlFeatureToToggle.putAll(features); diff --git a/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/JsonExtension.java b/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/JsonExtension.java index b964fcb54d..ef0e993d37 100644 --- a/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/JsonExtension.java +++ b/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/JsonExtension.java @@ -131,7 +131,7 @@ public JacksonJsonGradleConfig(FormatExtension formatExtension) { } /** - * @see com.fasterxml.jackson.core.JsonGenerator.Feature + * @Refers to com.fasterxml.jackson.core.JsonGenerator.Feature */ public AJacksonGradleConfig jsonFeature(String feature, boolean toggle) { this.jacksonConfig.appendJsonFeatureToToggle(Collections.singletonMap(feature, toggle)); diff --git a/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/YamlExtension.java b/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/YamlExtension.java index bf268914fc..7be3264102 100644 --- a/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/YamlExtension.java +++ b/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/YamlExtension.java @@ -25,7 +25,6 @@ import com.diffplug.spotless.yaml.JacksonYamlStep; public class YamlExtension extends FormatExtension { - private static final String DEFAULT_GSON_VERSION = JacksonJsonStep.defaultVersion(); static final String NAME = "yaml"; @Inject @@ -61,7 +60,7 @@ public JacksonYamlGradleConfig(FormatExtension formatExtension) { } /** - * @see com.fasterxml.jackson.dataformat.yaml.YAMLGenerator.Feature + * Refers to com.fasterxml.jackson.dataformat.yaml.YAMLGenerator.Feature */ public AJacksonGradleConfig yamlFeature(String feature, boolean toggle) { this.jacksonConfig.appendYamlFeatureToToggle(Collections.singletonMap(feature, toggle)); diff --git a/plugin-maven/src/test/java/com/diffplug/spotless/maven/json/JsonTest.java b/plugin-maven/src/test/java/com/diffplug/spotless/maven/json/JsonTest.java index 47de001a73..1897cc764a 100644 --- a/plugin-maven/src/test/java/com/diffplug/spotless/maven/json/JsonTest.java +++ b/plugin-maven/src/test/java/com/diffplug/spotless/maven/json/JsonTest.java @@ -76,7 +76,7 @@ public void testFormatJson_WithJackson_sortByKeys() throws Exception { setFile("json_test.json").toResource("json/sortByKeysBefore.json"); - mavenRunner().withArguments("spotless:apply").runNoError(); + mavenRunner().withArguments("spotless:apply", "-X").runNoError(); assertFile("json_test.json").sameAsResource("json/sortByKeysAfter_Jackson.json"); } diff --git a/plugin-maven/src/test/java/com/diffplug/spotless/maven/yaml/YamlTest.java b/plugin-maven/src/test/java/com/diffplug/spotless/maven/yaml/YamlTest.java index aaea2c65b1..6af4d09ce9 100644 --- a/plugin-maven/src/test/java/com/diffplug/spotless/maven/yaml/YamlTest.java +++ b/plugin-maven/src/test/java/com/diffplug/spotless/maven/yaml/YamlTest.java @@ -42,15 +42,6 @@ public void testFormatYaml_WithJackson_defaultConfig_arrayBrackets() throws Exce assertFile("yaml_test.yaml").sameAsResource("yaml/array_with_bracket.clean.yaml"); } - @Test - public void testFormatYaml_WithJackson_defaultConfig_arrayBrackets_spaceBeforeSeparator() throws Exception { - writePomWithYamlSteps("true"); - - setFile("yaml_test.yaml").toResource("yaml/array_with_bracket.yaml"); - mavenRunner().withArguments("spotless:apply").runNoError(); - assertFile("yaml_test.yaml").sameAsResource("yaml/array_with_bracket.clean.spaceBeforeSeparator.yaml"); - } - @Test public void testFormatYaml_WithJackson_defaultConfig_multipleDocuments() throws Exception { writePomWithYamlSteps(""); diff --git a/testlib/src/main/resources/json/sortByKeysAfter_Jackson.json b/testlib/src/main/resources/json/sortByKeysAfter_Jackson.json index c4a48de2f2..3af39fd0fb 100644 --- a/testlib/src/main/resources/json/sortByKeysAfter_Jackson.json +++ b/testlib/src/main/resources/json/sortByKeysAfter_Jackson.json @@ -1,19 +1,15 @@ { + "A": 1, + "X": 2, + "_arraysNotSorted": [ 3, 2, 1 ], + "a": 3, + "c": 4, + "x": 5, + "z": { "A": 1, "X": 2, - "_arraysNotSorted": [ - 3, - 2, - 1 - ], "a": 3, "c": 4, - "x": 5, - "z": { - "A": 1, - "X": 2, - "a": 3, - "c": 4, - "x": 5 - } + "x": 5 + } } diff --git a/testlib/src/main/resources/json/sortByKeysAfter_Jackson_spaceAfterKeySeparator.json b/testlib/src/main/resources/json/sortByKeysAfter_Jackson_spaceAfterKeySeparator.json index c4a48de2f2..3af39fd0fb 100644 --- a/testlib/src/main/resources/json/sortByKeysAfter_Jackson_spaceAfterKeySeparator.json +++ b/testlib/src/main/resources/json/sortByKeysAfter_Jackson_spaceAfterKeySeparator.json @@ -1,19 +1,15 @@ { + "A": 1, + "X": 2, + "_arraysNotSorted": [ 3, 2, 1 ], + "a": 3, + "c": 4, + "x": 5, + "z": { "A": 1, "X": 2, - "_arraysNotSorted": [ - 3, - 2, - 1 - ], "a": 3, "c": 4, - "x": 5, - "z": { - "A": 1, - "X": 2, - "a": 3, - "c": 4, - "x": 5 - } + "x": 5 + } } diff --git a/testlib/src/main/resources/yaml/array_with_bracket.clean.spaceBeforeSeparator.yaml b/testlib/src/main/resources/yaml/array_with_bracket.clean.spaceBeforeSeparator.yaml deleted file mode 100644 index 7dc9255e06..0000000000 --- a/testlib/src/main/resources/yaml/array_with_bracket.clean.spaceBeforeSeparator.yaml +++ /dev/null @@ -1,12 +0,0 @@ ---- -episodes: -- 1 -- 2 -- 3 -- 4 -- 5 -- 6 -- 7 -best-jedi : - name : "Obi-Wan" - side : "light" From 8d2cdd3d5c800161fa8149a8c4aa6f9d7d596849 Mon Sep 17 00:00:00 2001 From: Benoit Lacelle Date: Wed, 18 Jan 2023 12:33:38 +0400 Subject: [PATCH 598/757] Fix management of multiple documents YAML --- .../glue/json/AJacksonFormatterFunc.java | 2 +- .../glue/yaml/JacksonYamlFormatterFunc.java | 31 +++++---- .../spotless/json/JsonSimpleStep.java | 6 +- .../gradle/spotless/YamlExtensionTest.java | 67 +++++++++++++++---- .../resources/yaml/array_at_root.clean.yaml | 5 ++ .../main/resources/yaml/array_at_root.yaml | 7 ++ .../yaml/multiple_documents.clean.yaml | 12 ++-- .../resources/yaml/multiple_documents.yaml | 14 ++-- 8 files changed, 99 insertions(+), 45 deletions(-) create mode 100644 testlib/src/main/resources/yaml/array_at_root.clean.yaml create mode 100644 testlib/src/main/resources/yaml/array_at_root.yaml diff --git a/lib/src/jackson/java/com/diffplug/spotless/glue/json/AJacksonFormatterFunc.java b/lib/src/jackson/java/com/diffplug/spotless/glue/json/AJacksonFormatterFunc.java index a41ecf90d2..244ce05a9e 100644 --- a/lib/src/jackson/java/com/diffplug/spotless/glue/json/AJacksonFormatterFunc.java +++ b/lib/src/jackson/java/com/diffplug/spotless/glue/json/AJacksonFormatterFunc.java @@ -55,7 +55,7 @@ protected String format(ObjectMapper objectMapper, String input) throws IllegalA return output; } catch (JsonProcessingException e) { - throw new AssertionError("Unable to format. input='" + input + "'", e); + throw new IllegalArgumentException("Unable to format. input='" + input + "'", e); } } diff --git a/lib/src/jackson/java/com/diffplug/spotless/glue/yaml/JacksonYamlFormatterFunc.java b/lib/src/jackson/java/com/diffplug/spotless/glue/yaml/JacksonYamlFormatterFunc.java index 0cf4591717..96012e1041 100644 --- a/lib/src/jackson/java/com/diffplug/spotless/glue/yaml/JacksonYamlFormatterFunc.java +++ b/lib/src/jackson/java/com/diffplug/spotless/glue/yaml/JacksonYamlFormatterFunc.java @@ -15,12 +15,18 @@ */ package com.diffplug.spotless.glue.yaml; +import java.io.ByteArrayOutputStream; import java.io.IOException; +import java.io.StringWriter; +import java.nio.charset.StandardCharsets; +import java.util.List; import com.fasterxml.jackson.core.JsonFactory; +import com.fasterxml.jackson.core.JsonParser; import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.databind.ObjectMapper; -import com.fasterxml.jackson.databind.node.ObjectNode; +import com.fasterxml.jackson.databind.SequenceWriter; +import com.fasterxml.jackson.databind.node.ContainerNode; import com.fasterxml.jackson.dataformat.yaml.YAMLFactory; import com.fasterxml.jackson.dataformat.yaml.YAMLFactoryBuilder; import com.fasterxml.jackson.dataformat.yaml.YAMLGenerator; @@ -57,24 +63,21 @@ protected JsonFactory makeJsonFactory() { @Override protected String format(ObjectMapper objectMapper, String input) throws IllegalArgumentException, IOException { + //if (true) + // throw new IllegalArgumentException("input = \r\n" + input); try { // https://stackoverflow.com/questions/25222327/deserialize-pojos-from-multiple-yaml-documents-in-a-single-file-in-jackson // https://github.com/FasterXML/jackson-dataformats-text/issues/66#issuecomment-375328648 - // 2023-01: For now, we get 'Cannot deserialize value of type `com.fasterxml.jackson.databind.node.ObjectNode` from Array value' - // JsonParser yamlParser = objectMapper.getFactory().createParser(input); - // List docs = objectMapper.readValues(yamlParser, ObjectNode.class).readAll(); - // return objectMapper.writeValueAsString(docs); + JsonParser yamlParser = objectMapper.getFactory().createParser(input); + List documents = objectMapper.readValues(yamlParser, ContainerNode.class).readAll(); - // A JsonNode may keep the comments from the input node - // JsonNode jsonNode = objectMapper.readTree(input); - //Not 'toPrettyString' as one could require no INDENT_OUTPUT - // return jsonNode.toPrettyString(); - ObjectNode objectNode = objectMapper.readValue(input, ObjectNode.class); - String outputFromjackson = objectMapper.writerWithDefaultPrettyPrinter().writeValueAsString(objectNode); - - return outputFromjackson; + // https://github.com/FasterXML/jackson-dataformats-text/issues/66#issuecomment-554265055 + // https://github.com/FasterXML/jackson-dataformats-text/issues/66#issuecomment-554265055 + StringWriter stringWriter = new StringWriter(); + objectMapper.writer().writeValues(stringWriter).writeAll(documents).close(); + return stringWriter.toString(); } catch (JsonProcessingException e) { - throw new AssertionError("Unable to format. input='" + input + "'", e); + throw new IllegalArgumentException("Unable to format. input='" + input + "'", e); } } } diff --git a/lib/src/main/java/com/diffplug/spotless/json/JsonSimpleStep.java b/lib/src/main/java/com/diffplug/spotless/json/JsonSimpleStep.java index a970149133..1f4db3e059 100644 --- a/lib/src/main/java/com/diffplug/spotless/json/JsonSimpleStep.java +++ b/lib/src/main/java/com/diffplug/spotless/json/JsonSimpleStep.java @@ -81,7 +81,7 @@ FormatterFunc toFormatter() { return format(arrayConstructor, arrayToString, s); } - throw new AssertionError(String.format("Unable to determine JSON type, expected a '{' or '[' but found '%s'", first)); + throw new IllegalArgumentException(String.format("Unable to determine JSON type, expected a '{' or '[' but found '%s'", first)); }; } @@ -89,8 +89,8 @@ private String format(Constructor constructor, Method toString, String input) try { Object parsed = constructor.newInstance(input); return toString.invoke(parsed, indentSpaces) + "\n"; - } catch (InvocationTargetException ex) { - throw new AssertionError("Unable to format JSON", ex.getCause()); + } catch (InvocationTargetException e) { + throw new IllegalArgumentException("Unable to format JSON", e); } } } diff --git a/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/YamlExtensionTest.java b/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/YamlExtensionTest.java index 7baddc4177..295934dd26 100644 --- a/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/YamlExtensionTest.java +++ b/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/YamlExtensionTest.java @@ -43,22 +43,63 @@ void testFormatYaml_WithJackson_defaultConfig_separatorComments() throws IOExcep @Test void testFormatYaml_WithJackson_skipDocStartMarker() throws IOException { setFile("build.gradle").toLines( - "plugins {", - " id 'java'", - " id 'com.diffplug.spotless'", - "}", - "repositories { mavenCentral() }", - "spotless {", - " yaml {", - " target 'src/**/*.yaml'", - " jackson()", - " .yamlFeature('WRITE_DOC_START_MARKER', false)", - " .yamlFeature('MINIMIZE_QUOTES', true)", - " }", - "}"); + "plugins {", + " id 'java'", + " id 'com.diffplug.spotless'", + "}", + "repositories { mavenCentral() }", + "spotless {", + " yaml {", + " target 'src/**/*.yaml'", + " jackson()", + " .yamlFeature('WRITE_DOC_START_MARKER', false)", + " .yamlFeature('MINIMIZE_QUOTES', true)", + " }", + "}"); setFile("src/main/resources/example.yaml").toResource("yaml/array_with_bracket.yaml"); gradleRunner().withArguments("spotlessApply", "--stacktrace").build(); assertFile("src/main/resources/example.yaml").sameAsResource("yaml/array_with_bracket.clean.no_start_marker.no_quotes.yaml"); } + @Test + void testFormatYaml_WithJackson_multipleDocuments() throws IOException { + setFile("build.gradle").toLines( + "plugins {", + " id 'java'", + " id 'com.diffplug.spotless'", + "}", + "repositories { mavenCentral() }", + "spotless {", + " yaml {", + " target 'src/**/*.yaml'", + " jackson()", + " .yamlFeature('MINIMIZE_QUOTES', true)", + " }", + "}"); + setFile("src/main/resources/example.yaml").toResource("yaml/multiple_documents.yaml"); + gradleRunner().withArguments("spotlessApply", "--stacktrace").build(); + assertFile("src/main/resources/example.yaml").sameAsResource("yaml/multiple_documents.clean.jackson.yaml"); + } + + + @Test + void testFormatYaml_WithJackson_arrayAtRoot() throws IOException { + setFile("build.gradle").toLines( + "plugins {", + " id 'java'", + " id 'com.diffplug.spotless'", + "}", + "repositories { mavenCentral() }", + "spotless {", + " yaml {", + " target 'src/**/*.yaml'", + " jackson()", + " }", + "}"); + setFile("src/main/resources/example.yaml").toResource("yaml/array_at_root.yaml"); + gradleRunner().withArguments("spotlessApply", "--stacktrace").build(); + assertFile("src/main/resources/example.yaml").sameAsResource("yaml/array_at_root.clean.yaml"); + } + + } diff --git a/testlib/src/main/resources/yaml/array_at_root.clean.yaml b/testlib/src/main/resources/yaml/array_at_root.clean.yaml new file mode 100644 index 0000000000..f9bae04114 --- /dev/null +++ b/testlib/src/main/resources/yaml/array_at_root.clean.yaml @@ -0,0 +1,5 @@ +--- +- key1: "value1" + key2: "value2" +- key3: "value3" + key4: "value4" diff --git a/testlib/src/main/resources/yaml/array_at_root.yaml b/testlib/src/main/resources/yaml/array_at_root.yaml new file mode 100644 index 0000000000..b26f6bb246 --- /dev/null +++ b/testlib/src/main/resources/yaml/array_at_root.yaml @@ -0,0 +1,7 @@ +- key1: value1 + key2: value2 + + +- key3: value3 + key4: value4 + diff --git a/testlib/src/main/resources/yaml/multiple_documents.clean.yaml b/testlib/src/main/resources/yaml/multiple_documents.clean.yaml index 45e0b0916b..3651473955 100644 --- a/testlib/src/main/resources/yaml/multiple_documents.clean.yaml +++ b/testlib/src/main/resources/yaml/multiple_documents.clean.yaml @@ -1,8 +1,8 @@ ---- -document: this is document 1 - ---- -document: this is document 2 +# Document 1 +key1: value1 +key2: value2 --- -document: this is document 3 \ No newline at end of file +# Document 2 +key3: value3 +key4: value4 diff --git a/testlib/src/main/resources/yaml/multiple_documents.yaml b/testlib/src/main/resources/yaml/multiple_documents.yaml index 51f14a5862..3651473955 100644 --- a/testlib/src/main/resources/yaml/multiple_documents.yaml +++ b/testlib/src/main/resources/yaml/multiple_documents.yaml @@ -1,10 +1,8 @@ -document: this is document 1 ---- - -document: this is document 2 - +# Document 1 +key1: value1 +key2: value2 --- - - -document: this is document 3 \ No newline at end of file +# Document 2 +key3: value3 +key4: value4 From a3693e78c1326a281dac76de9327515243d3f27e Mon Sep 17 00:00:00 2001 From: Benoit Lacelle Date: Wed, 18 Jan 2023 12:36:06 +0400 Subject: [PATCH 599/757] spotlessApply --- .../glue/json/AJacksonFormatterFunc.java | 1 - .../glue/yaml/JacksonYamlFormatterFunc.java | 3 - .../spotless/json/JsonSimpleStep.java | 2 +- .../gradle/spotless/YamlExtension.java | 1 - .../gradle/spotless/YamlExtensionTest.java | 74 +++++++++---------- 5 files changed, 37 insertions(+), 44 deletions(-) diff --git a/lib/src/jackson/java/com/diffplug/spotless/glue/json/AJacksonFormatterFunc.java b/lib/src/jackson/java/com/diffplug/spotless/glue/json/AJacksonFormatterFunc.java index 244ce05a9e..6f363ad1b7 100644 --- a/lib/src/jackson/java/com/diffplug/spotless/glue/json/AJacksonFormatterFunc.java +++ b/lib/src/jackson/java/com/diffplug/spotless/glue/json/AJacksonFormatterFunc.java @@ -24,7 +24,6 @@ import com.fasterxml.jackson.core.util.DefaultPrettyPrinter; import com.fasterxml.jackson.databind.ObjectMapper; import com.fasterxml.jackson.databind.SerializationFeature; -import com.fasterxml.jackson.databind.node.ObjectNode; import com.diffplug.spotless.FormatterFunc; import com.diffplug.spotless.json.JacksonConfig; diff --git a/lib/src/jackson/java/com/diffplug/spotless/glue/yaml/JacksonYamlFormatterFunc.java b/lib/src/jackson/java/com/diffplug/spotless/glue/yaml/JacksonYamlFormatterFunc.java index 96012e1041..edb350c559 100644 --- a/lib/src/jackson/java/com/diffplug/spotless/glue/yaml/JacksonYamlFormatterFunc.java +++ b/lib/src/jackson/java/com/diffplug/spotless/glue/yaml/JacksonYamlFormatterFunc.java @@ -15,17 +15,14 @@ */ package com.diffplug.spotless.glue.yaml; -import java.io.ByteArrayOutputStream; import java.io.IOException; import java.io.StringWriter; -import java.nio.charset.StandardCharsets; import java.util.List; import com.fasterxml.jackson.core.JsonFactory; import com.fasterxml.jackson.core.JsonParser; import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.databind.ObjectMapper; -import com.fasterxml.jackson.databind.SequenceWriter; import com.fasterxml.jackson.databind.node.ContainerNode; import com.fasterxml.jackson.dataformat.yaml.YAMLFactory; import com.fasterxml.jackson.dataformat.yaml.YAMLFactoryBuilder; diff --git a/lib/src/main/java/com/diffplug/spotless/json/JsonSimpleStep.java b/lib/src/main/java/com/diffplug/spotless/json/JsonSimpleStep.java index 1f4db3e059..85ccbfa6e2 100644 --- a/lib/src/main/java/com/diffplug/spotless/json/JsonSimpleStep.java +++ b/lib/src/main/java/com/diffplug/spotless/json/JsonSimpleStep.java @@ -1,5 +1,5 @@ /* - * Copyright 2021 DiffPlug + * Copyright 2021-2023 DiffPlug * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/YamlExtension.java b/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/YamlExtension.java index 7be3264102..abc2dce359 100644 --- a/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/YamlExtension.java +++ b/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/YamlExtension.java @@ -20,7 +20,6 @@ import javax.inject.Inject; import com.diffplug.spotless.FormatterStep; -import com.diffplug.spotless.json.JacksonJsonStep; import com.diffplug.spotless.yaml.JacksonYamlConfig; import com.diffplug.spotless.yaml.JacksonYamlStep; diff --git a/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/YamlExtensionTest.java b/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/YamlExtensionTest.java index 295934dd26..82801eb0fd 100644 --- a/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/YamlExtensionTest.java +++ b/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/YamlExtensionTest.java @@ -43,19 +43,19 @@ void testFormatYaml_WithJackson_defaultConfig_separatorComments() throws IOExcep @Test void testFormatYaml_WithJackson_skipDocStartMarker() throws IOException { setFile("build.gradle").toLines( - "plugins {", - " id 'java'", - " id 'com.diffplug.spotless'", - "}", - "repositories { mavenCentral() }", - "spotless {", - " yaml {", - " target 'src/**/*.yaml'", - " jackson()", - " .yamlFeature('WRITE_DOC_START_MARKER', false)", - " .yamlFeature('MINIMIZE_QUOTES', true)", - " }", - "}"); + "plugins {", + " id 'java'", + " id 'com.diffplug.spotless'", + "}", + "repositories { mavenCentral() }", + "spotless {", + " yaml {", + " target 'src/**/*.yaml'", + " jackson()", + " .yamlFeature('WRITE_DOC_START_MARKER', false)", + " .yamlFeature('MINIMIZE_QUOTES', true)", + " }", + "}"); setFile("src/main/resources/example.yaml").toResource("yaml/array_with_bracket.yaml"); gradleRunner().withArguments("spotlessApply", "--stacktrace").build(); assertFile("src/main/resources/example.yaml").sameAsResource("yaml/array_with_bracket.clean.no_start_marker.no_quotes.yaml"); @@ -64,42 +64,40 @@ void testFormatYaml_WithJackson_skipDocStartMarker() throws IOException { @Test void testFormatYaml_WithJackson_multipleDocuments() throws IOException { setFile("build.gradle").toLines( - "plugins {", - " id 'java'", - " id 'com.diffplug.spotless'", - "}", - "repositories { mavenCentral() }", - "spotless {", - " yaml {", - " target 'src/**/*.yaml'", - " jackson()", - " .yamlFeature('MINIMIZE_QUOTES', true)", - " }", - "}"); + "plugins {", + " id 'java'", + " id 'com.diffplug.spotless'", + "}", + "repositories { mavenCentral() }", + "spotless {", + " yaml {", + " target 'src/**/*.yaml'", + " jackson()", + " .yamlFeature('MINIMIZE_QUOTES', true)", + " }", + "}"); setFile("src/main/resources/example.yaml").toResource("yaml/multiple_documents.yaml"); gradleRunner().withArguments("spotlessApply", "--stacktrace").build(); assertFile("src/main/resources/example.yaml").sameAsResource("yaml/multiple_documents.clean.jackson.yaml"); } - @Test void testFormatYaml_WithJackson_arrayAtRoot() throws IOException { setFile("build.gradle").toLines( - "plugins {", - " id 'java'", - " id 'com.diffplug.spotless'", - "}", - "repositories { mavenCentral() }", - "spotless {", - " yaml {", - " target 'src/**/*.yaml'", - " jackson()", - " }", - "}"); + "plugins {", + " id 'java'", + " id 'com.diffplug.spotless'", + "}", + "repositories { mavenCentral() }", + "spotless {", + " yaml {", + " target 'src/**/*.yaml'", + " jackson()", + " }", + "}"); setFile("src/main/resources/example.yaml").toResource("yaml/array_at_root.yaml"); gradleRunner().withArguments("spotlessApply", "--stacktrace").build(); assertFile("src/main/resources/example.yaml").sameAsResource("yaml/array_at_root.clean.yaml"); } - } From c613302d0b1d4edece0c1d6a9a408aea716cedf4 Mon Sep 17 00:00:00 2001 From: Benoit Lacelle Date: Wed, 18 Jan 2023 13:01:25 +0400 Subject: [PATCH 600/757] Improve documentation, fix tests --- plugin-gradle/CHANGES.md | 2 + plugin-gradle/README.md | 65 +++++++++++++++++-- plugin-maven/README.md | 20 ++++-- .../spotless/maven/json/JacksonJson.java | 4 ++ .../multiple_documents.clean.jackson.yaml | 6 +- 5 files changed, 83 insertions(+), 14 deletions(-) diff --git a/plugin-gradle/CHANGES.md b/plugin-gradle/CHANGES.md index 63e5b43d74..94d7a90409 100644 --- a/plugin-gradle/CHANGES.md +++ b/plugin-gradle/CHANGES.md @@ -4,6 +4,8 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format ( ## [Unreleased] ### Added +* Support `jackson()` for YAML files ([#1492](https://github.com/diffplug/spotless/pull/1492)) +* Support `jackson()` for JSON files ([#1492](https://github.com/diffplug/spotless/pull/1492)) ### Fixed * The default list of type annotations used by `formatAnnotations` has had 8 more annotations from the Checker Framework added [#1494](https://github.com/diffplug/spotless/pull/1494) ### Changes diff --git a/plugin-gradle/README.md b/plugin-gradle/README.md index f2567a5924..e1bd2fe0dd 100644 --- a/plugin-gradle/README.md +++ b/plugin-gradle/README.md @@ -737,11 +737,12 @@ For details, see the [npm detection](#npm-detection) and [`.npmrc` detection](#n ```gradle spotless { json { - target 'src/**/*.json' // you have to set the target manually - simple() // has its own section below + target 'src/**/*.json' // you have to set the target manually + simple() // has its own section below prettier().config(['parser': 'json']) // see Prettier section below - eclipseWtp('json') // see Eclipse web tools platform section - gson() // has its own section below + eclipseWtp('json') // see Eclipse web tools platform section + gson() // has its own section below + jackson() // has its own section below } } ``` @@ -780,10 +781,60 @@ spotless { Notes: * There's no option in Gson to leave HTML as-is (i.e. escaped HTML would remain escaped, raw would remain raw). Either -all HTML characters are written escaped or none. Set `escapeHtml` if you prefer the former. + all HTML characters are written escaped or none. Set `escapeHtml` if you prefer the former. * `sortByKeys` will apply lexicographic order on the keys of the input JSON. See the -[javadoc of String](https://docs.oracle.com/en/java/javase/11/docs/api/java.base/java/lang/String.html#compareTo(java.lang.String)) -for details. + [javadoc of String](https://docs.oracle.com/en/java/javase/11/docs/api/java.base/java/lang/String.html#compareTo(java.lang.String)) + for details. + +### Jackson + +Uses Jackson for json files. + +```gradle +spotless { + json { + target 'src/**/*.json' + jackson() + .spaceBeforeSeparator(false) // optional: add a whitespace before key separator. False by default + .feature('INDENT_OUTPUT', true) // optional: true by default + .feature('ORDER_MAP_ENTRIES_BY_KEYS', true) // optional: false by default + .feature('ANY_OTHER_FEATURE', true|false) // optional: any SerializationFeature can be toggled on or off + .jsonFeature('ANY_OTHER_FEATURE', true|false) // any JsonGenerator.Feature can be toggled on or off + } +} +``` + + +## YAML + +- `com.diffplug.gradle.spotless.YamlExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.13.0/com/diffplug/gradle/spotless/JsonExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/YamlExtension.java) + +```gradle +spotless { + yaml { + target 'src/**/*.yaml' // you have to set the target manually + jackson() // has its own section below + } +} +``` + +### Jackson + +Uses Jackson for `yaml` files. + +```gradle +spotless { + yaml { + target 'src/**/*.yaml' + jackson() + .spaceBeforeSeparator(false) // optional: add a whitespace before key separator. False by default + .feature('INDENT_OUTPUT', true) // optional: true by default + .feature('ORDER_MAP_ENTRIES_BY_KEYS', true) // optional: false by default + .feature('ANY_OTHER_FEATURE', true|false) // optional: any SerializationFeature can be toggled on or off + .yamlFeature('ANY_OTHER_FEATURE', true|false) // any YAMLGenerator.Feature can be toggled on or off + } +} +``` diff --git a/plugin-maven/README.md b/plugin-maven/README.md index 7673a440c6..37d1046b1d 100644 --- a/plugin-maven/README.md +++ b/plugin-maven/README.md @@ -907,11 +907,15 @@ Uses Jackson for formatting. 2.14.1 - true - false - true|false + true + false + true|false - false + + false + true|false + + false ``` @@ -944,9 +948,13 @@ Uses Jackson and YAMLFactory to pretty print objects: true false - false - true|false + true|false + + true + false + true|false + false ``` diff --git a/plugin-maven/src/main/java/com/diffplug/spotless/maven/json/JacksonJson.java b/plugin-maven/src/main/java/com/diffplug/spotless/maven/json/JacksonJson.java index 9bca852754..ecf925ddbe 100644 --- a/plugin-maven/src/main/java/com/diffplug/spotless/maven/json/JacksonJson.java +++ b/plugin-maven/src/main/java/com/diffplug/spotless/maven/json/JacksonJson.java @@ -41,11 +41,15 @@ public class JacksonJson implements FormatterStepFactory { @Parameter private Map features = Collections.emptyMap(); + @Parameter + private Map jsonFeatures = Collections.emptyMap(); + @Override public FormatterStep newFormatterStep(FormatterStepConfig stepConfig) { JacksonJsonConfig jacksonConfig = new JacksonJsonConfig(); jacksonConfig.appendFeatureToToggle(features); + jacksonConfig.appendJsonFeatureToToggle(jsonFeatures); jacksonConfig.setSpaceBeforeSeparator(spaceBeforeSeparator); return JacksonJsonStep diff --git a/testlib/src/main/resources/yaml/multiple_documents.clean.jackson.yaml b/testlib/src/main/resources/yaml/multiple_documents.clean.jackson.yaml index aa731919b4..ff56b4f77a 100644 --- a/testlib/src/main/resources/yaml/multiple_documents.clean.jackson.yaml +++ b/testlib/src/main/resources/yaml/multiple_documents.clean.jackson.yaml @@ -1,2 +1,6 @@ --- -document: "this is document 1" +key1: "value1" +key2: "value2" +--- +key3: "value3" +key4: "value4" From 97ecda34a74bb07e86fa3f4db38e70b9352f49ed Mon Sep 17 00:00:00 2001 From: Benoit Lacelle Date: Wed, 18 Jan 2023 13:27:27 +0400 Subject: [PATCH 601/757] Fix Javadoc --- .../main/java/com/diffplug/gradle/spotless/JsonExtension.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/JsonExtension.java b/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/JsonExtension.java index ef0e993d37..1e9de2e831 100644 --- a/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/JsonExtension.java +++ b/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/JsonExtension.java @@ -131,7 +131,7 @@ public JacksonJsonGradleConfig(FormatExtension formatExtension) { } /** - * @Refers to com.fasterxml.jackson.core.JsonGenerator.Feature + * Refers to com.fasterxml.jackson.core.JsonGenerator.Feature */ public AJacksonGradleConfig jsonFeature(String feature, boolean toggle) { this.jacksonConfig.appendJsonFeatureToToggle(Collections.singletonMap(feature, toggle)); From a80ed394092c9cdd76427f60221136db3795649f Mon Sep 17 00:00:00 2001 From: Benoit Lacelle Date: Wed, 18 Jan 2023 13:51:01 +0400 Subject: [PATCH 602/757] Sync mvn and gradle tests on YAML --- .../java/com/diffplug/gradle/spotless/YamlExtensionTest.java | 1 - 1 file changed, 1 deletion(-) diff --git a/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/YamlExtensionTest.java b/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/YamlExtensionTest.java index 82801eb0fd..067c809846 100644 --- a/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/YamlExtensionTest.java +++ b/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/YamlExtensionTest.java @@ -73,7 +73,6 @@ void testFormatYaml_WithJackson_multipleDocuments() throws IOException { " yaml {", " target 'src/**/*.yaml'", " jackson()", - " .yamlFeature('MINIMIZE_QUOTES', true)", " }", "}"); setFile("src/main/resources/example.yaml").toResource("yaml/multiple_documents.yaml"); From 4b3cb2421996895eef8f871ac47a3089867780ae Mon Sep 17 00:00:00 2001 From: Simon Gamma Date: Mon, 16 Jan 2023 20:45:45 +0100 Subject: [PATCH 603/757] allow supplying node-binary path or look for it as a sibling to npm binary. the path of the npm binary is then prepended to the system PATH before launching the npm process. --- .../spotless/npm/EslintFormatterStep.java | 10 +-- .../spotless/npm/NodeExecutableResolver.java | 45 ++++++++++++++ .../npm/NpmFormatterStepLocations.java | 62 +++++++++++++++++++ .../npm/NpmFormatterStepStateBase.java | 18 ++---- .../spotless/npm/NpmPathResolver.java | 18 ++++-- .../com/diffplug/spotless/npm/NpmProcess.java | 16 +++-- .../spotless/npm/PrettierFormatterStep.java | 8 ++- .../spotless/npm/TsFmtFormatterStep.java | 8 ++- .../gradle/spotless/FormatExtension.java | 17 ++++- .../gradle/spotless/JavascriptExtension.java | 3 +- .../gradle/spotless/TypescriptExtension.java | 5 +- .../NpmTestsWithoutNpmInstallationTest.java | 59 ++++++++++++++++++ .../npm/AbstractNpmFormatterStepFactory.java | 11 +++- .../npm/NpmFormatterStepCommonTests.java | 9 ++- 14 files changed, 252 insertions(+), 37 deletions(-) create mode 100644 lib/src/main/java/com/diffplug/spotless/npm/NodeExecutableResolver.java create mode 100644 lib/src/main/java/com/diffplug/spotless/npm/NpmFormatterStepLocations.java create mode 100644 plugin-gradle/src/test/java/com/diffplug/gradle/spotless/NpmTestsWithoutNpmInstallationTest.java diff --git a/lib/src/main/java/com/diffplug/spotless/npm/EslintFormatterStep.java b/lib/src/main/java/com/diffplug/spotless/npm/EslintFormatterStep.java index 81c5b6ce78..74979d90aa 100644 --- a/lib/src/main/java/com/diffplug/spotless/npm/EslintFormatterStep.java +++ b/lib/src/main/java/com/diffplug/spotless/npm/EslintFormatterStep.java @@ -94,9 +94,11 @@ private static class State extends NpmFormatterStepStateBase implements Serializ "/com/diffplug/spotless/npm/common-serve.js", "/com/diffplug/spotless/npm/eslint-serve.js"), npmPathResolver.resolveNpmrcContent()), - projectDir, - buildDir, - npmPathResolver.resolveNpmExecutable()); + new NpmFormatterStepLocations( + projectDir, + buildDir, + npmPathResolver.resolveNpmExecutable(), + npmPathResolver.resolveNodeExecutable())); this.eslintConfig = localCopyFiles(requireNonNull(eslintConfig)); } @@ -119,7 +121,7 @@ public FormatterFunc createFormatterFunc() { FormattedPrinter.SYSOUT.print("creating formatter function (starting server)"); ServerProcessInfo eslintRestServer = npmRunServer(); EslintRestService restService = new EslintRestService(eslintRestServer.getBaseUrl()); - return Closeable.ofDangerous(() -> endServer(restService, eslintRestServer), new EslintFilePathPassingFormatterFunc(projectDir, nodeModulesDir, eslintConfig, restService)); + return Closeable.ofDangerous(() -> endServer(restService, eslintRestServer), new EslintFilePathPassingFormatterFunc(locations.projectDir(), nodeModulesDir, eslintConfig, restService)); } catch (IOException e) { throw ThrowingEx.asRuntime(e); } diff --git a/lib/src/main/java/com/diffplug/spotless/npm/NodeExecutableResolver.java b/lib/src/main/java/com/diffplug/spotless/npm/NodeExecutableResolver.java new file mode 100644 index 0000000000..c9e04da620 --- /dev/null +++ b/lib/src/main/java/com/diffplug/spotless/npm/NodeExecutableResolver.java @@ -0,0 +1,45 @@ +/* + * Copyright 2023 DiffPlug + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.diffplug.spotless.npm; + +import java.io.File; +import java.util.Optional; + +class NodeExecutableResolver { + + private NodeExecutableResolver() { + // no instance + } + + static String nodeExecutableName() { + String nodeName = "node"; + if (PlatformInfo.normalizedOS() == PlatformInfo.OS.WINDOWS) { + nodeName += ".exe"; + } + return nodeName; + } + + static Optional tryFindNextTo(File npmExecutable) { + if (npmExecutable == null) { + return Optional.empty(); + } + File nodeExecutable = new File(npmExecutable.getParentFile(), nodeExecutableName()); + if (nodeExecutable.exists() && nodeExecutable.isFile() && nodeExecutable.canExecute()) { + return Optional.of(nodeExecutable); + } + return Optional.empty(); + } +} diff --git a/lib/src/main/java/com/diffplug/spotless/npm/NpmFormatterStepLocations.java b/lib/src/main/java/com/diffplug/spotless/npm/NpmFormatterStepLocations.java new file mode 100644 index 0000000000..0c417733e8 --- /dev/null +++ b/lib/src/main/java/com/diffplug/spotless/npm/NpmFormatterStepLocations.java @@ -0,0 +1,62 @@ +/* + * Copyright 2023 DiffPlug + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.diffplug.spotless.npm; + +import static java.util.Objects.requireNonNull; + +import java.io.File; +import java.io.Serializable; + +import edu.umd.cs.findbugs.annotations.SuppressFBWarnings; + +class NpmFormatterStepLocations implements Serializable { + + private static final long serialVersionUID = -1055408537924029969L; + @SuppressFBWarnings("SE_TRANSIENT_FIELD_NOT_RESTORED") + private final transient File projectDir; + + @SuppressFBWarnings("SE_TRANSIENT_FIELD_NOT_RESTORED") + private final transient File buildDir; + + @SuppressFBWarnings("SE_TRANSIENT_FIELD_NOT_RESTORED") + private final transient File npmExecutable; + + @SuppressFBWarnings("SE_TRANSIENT_FIELD_NOT_RESTORED") + private final transient File nodeExecutable; + + public NpmFormatterStepLocations(File projectDir, File buildDir, File npmExecutable, File nodeExecutable) { + this.projectDir = requireNonNull(projectDir); + this.buildDir = requireNonNull(buildDir); + this.npmExecutable = requireNonNull(npmExecutable); + this.nodeExecutable = requireNonNull(nodeExecutable); + } + + public File projectDir() { + return projectDir; + } + + public File buildDir() { + return buildDir; + } + + public File npmExecutable() { + return npmExecutable; + } + + public File nodeExecutable() { + return nodeExecutable; + } +} diff --git a/lib/src/main/java/com/diffplug/spotless/npm/NpmFormatterStepStateBase.java b/lib/src/main/java/com/diffplug/spotless/npm/NpmFormatterStepStateBase.java index 49a166e45c..4f555a177e 100644 --- a/lib/src/main/java/com/diffplug/spotless/npm/NpmFormatterStepStateBase.java +++ b/lib/src/main/java/com/diffplug/spotless/npm/NpmFormatterStepStateBase.java @@ -48,23 +48,17 @@ abstract class NpmFormatterStepStateBase implements Serializable { @SuppressFBWarnings("SE_TRANSIENT_FIELD_NOT_RESTORED") public final transient File nodeModulesDir; - @SuppressFBWarnings("SE_TRANSIENT_FIELD_NOT_RESTORED") - private final transient File npmExecutable; - - @SuppressFBWarnings("SE_TRANSIENT_FIELD_NOT_RESTORED") - public final transient File projectDir; + public final NpmFormatterStepLocations locations; private final NpmConfig npmConfig; private final String stepName; - protected NpmFormatterStepStateBase(String stepName, NpmConfig npmConfig, File projectDir, File buildDir, File npm) throws IOException { + protected NpmFormatterStepStateBase(String stepName, NpmConfig npmConfig, NpmFormatterStepLocations locations) throws IOException { this.stepName = requireNonNull(stepName); this.npmConfig = requireNonNull(npmConfig); - this.projectDir = requireNonNull(projectDir); - this.npmExecutable = npm; - - NodeServerLayout layout = prepareNodeServer(buildDir); + this.locations = locations; + NodeServerLayout layout = prepareNodeServer(locations.buildDir()); this.nodeModulesDir = layout.nodeModulesDir(); this.packageJsonSignature = FileSignature.signAsList(layout.packageJsonFile()); } @@ -88,7 +82,7 @@ private NodeServerLayout prepareNodeServer(File buildDir) throws IOException { } private void runNpmInstall(File npmProjectDir) throws IOException { - new NpmProcess(npmProjectDir, this.npmExecutable).install(); + new NpmProcess(npmProjectDir, this.locations.npmExecutable(), this.locations.nodeExecutable()).install(); } protected ServerProcessInfo npmRunServer() throws ServerStartException, IOException { @@ -102,7 +96,7 @@ protected ServerProcessInfo npmRunServer() throws ServerStartException, IOExcept final File serverPortFile = new File(this.nodeModulesDir, "server.port"); NpmResourceHelper.deleteFileIfExists(serverPortFile); // start the http server in node - Process server = new NpmProcess(this.nodeModulesDir, this.npmExecutable).start(); + Process server = new NpmProcess(this.nodeModulesDir, this.locations.npmExecutable(), this.locations.nodeExecutable()).start(); // await the readiness of the http server - wait for at most 60 seconds try { diff --git a/lib/src/main/java/com/diffplug/spotless/npm/NpmPathResolver.java b/lib/src/main/java/com/diffplug/spotless/npm/NpmPathResolver.java index a9a15bd49d..d18146188d 100644 --- a/lib/src/main/java/com/diffplug/spotless/npm/NpmPathResolver.java +++ b/lib/src/main/java/com/diffplug/spotless/npm/NpmPathResolver.java @@ -1,5 +1,5 @@ /* - * Copyright 2020 DiffPlug + * Copyright 2020-2023 DiffPlug * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -16,7 +16,8 @@ package com.diffplug.spotless.npm; import java.io.File; -import java.util.Arrays; +import java.util.ArrayList; +import java.util.Collections; import java.util.List; import java.util.Optional; @@ -24,14 +25,17 @@ public class NpmPathResolver { private final File explicitNpmExecutable; + private final File explicitNodeExecutable; + private final File explicitNpmrcFile; private final List additionalNpmrcLocations; - public NpmPathResolver(File explicitNpmExecutable, File explicitNpmrcFile, File... additionalNpmrcLocations) { + public NpmPathResolver(File explicitNpmExecutable, File explicitNodeExecutable, File explicitNpmrcFile, List additionalNpmrcLocations) { this.explicitNpmExecutable = explicitNpmExecutable; + this.explicitNodeExecutable = explicitNodeExecutable; this.explicitNpmrcFile = explicitNpmrcFile; - this.additionalNpmrcLocations = Arrays.asList(additionalNpmrcLocations); + this.additionalNpmrcLocations = Collections.unmodifiableList(new ArrayList<>(additionalNpmrcLocations)); } public File resolveNpmExecutable() { @@ -40,6 +44,12 @@ public File resolveNpmExecutable() { .orElseThrow(() -> new IllegalStateException("Can't automatically determine npm executable and none was specifically supplied!\n\n" + NpmExecutableResolver.explainMessage()))); } + public File resolveNodeExecutable() { + return Optional.ofNullable(this.explicitNodeExecutable) + .orElseGet(() -> NodeExecutableResolver.tryFindNextTo(resolveNpmExecutable()) + .orElseThrow(() -> new IllegalStateException("Can't automatically determine node executable and none was specifically supplied!\n\n" + NpmExecutableResolver.explainMessage()))); + } + public String resolveNpmrcContent() { File npmrcFile = Optional.ofNullable(this.explicitNpmrcFile) .orElseGet(() -> new NpmrcResolver(additionalNpmrcLocations).tryFind() diff --git a/lib/src/main/java/com/diffplug/spotless/npm/NpmProcess.java b/lib/src/main/java/com/diffplug/spotless/npm/NpmProcess.java index 8be94a9ea3..1675a4aa4e 100644 --- a/lib/src/main/java/com/diffplug/spotless/npm/NpmProcess.java +++ b/lib/src/main/java/com/diffplug/spotless/npm/NpmProcess.java @@ -28,9 +28,12 @@ class NpmProcess { private final File npmExecutable; - NpmProcess(File workingDir, File npmExecutable) { + private final File nodeExecutable; + + NpmProcess(File workingDir, File npmExecutable, File nodeExecutable) { this.workingDir = workingDir; this.npmExecutable = npmExecutable; + this.nodeExecutable = nodeExecutable; } void install() { @@ -61,11 +64,12 @@ private void npmAwait(String... args) { private Process npm(String... args) { List processCommand = processCommand(args); try { - return new ProcessBuilder() + ProcessBuilder processBuilder = new ProcessBuilder() .inheritIO() .directory(this.workingDir) - .command(processCommand) - .start(); + .command(processCommand); + addEnvironmentVariables(processBuilder); + return processBuilder.start(); } catch (IOException e) { throw new NpmProcessException("Failed to launch npm command '" + commandLine(args) + "'.", e); } @@ -78,6 +82,10 @@ private List processCommand(String... args) { return command; } + private void addEnvironmentVariables(ProcessBuilder processBuilder) { + processBuilder.environment().put("PATH", this.nodeExecutable.getParentFile().getAbsolutePath() + File.pathSeparator + System.getenv("PATH")); + } + private String commandLine(String... args) { return "npm " + Arrays.stream(args).collect(Collectors.joining(" ")); } diff --git a/lib/src/main/java/com/diffplug/spotless/npm/PrettierFormatterStep.java b/lib/src/main/java/com/diffplug/spotless/npm/PrettierFormatterStep.java index 22a162eb0b..20ff71d08e 100644 --- a/lib/src/main/java/com/diffplug/spotless/npm/PrettierFormatterStep.java +++ b/lib/src/main/java/com/diffplug/spotless/npm/PrettierFormatterStep.java @@ -74,9 +74,11 @@ private static class State extends NpmFormatterStepStateBase implements Serializ "/com/diffplug/spotless/npm/common-serve.js", "/com/diffplug/spotless/npm/prettier-serve.js"), npmPathResolver.resolveNpmrcContent()), - projectDir, - buildDir, - npmPathResolver.resolveNpmExecutable()); + new NpmFormatterStepLocations( + projectDir, + buildDir, + npmPathResolver.resolveNpmExecutable(), + npmPathResolver.resolveNodeExecutable())); this.prettierConfig = requireNonNull(prettierConfig); } diff --git a/lib/src/main/java/com/diffplug/spotless/npm/TsFmtFormatterStep.java b/lib/src/main/java/com/diffplug/spotless/npm/TsFmtFormatterStep.java index 98d694ec33..14d6b1bbd0 100644 --- a/lib/src/main/java/com/diffplug/spotless/npm/TsFmtFormatterStep.java +++ b/lib/src/main/java/com/diffplug/spotless/npm/TsFmtFormatterStep.java @@ -80,9 +80,11 @@ public State(String stepName, Map versions, File projectDir, Fil "/com/diffplug/spotless/npm/common-serve.js", "/com/diffplug/spotless/npm/tsfmt-serve.js"), npmPathResolver.resolveNpmrcContent()), - projectDir, - buildDir, - npmPathResolver.resolveNpmExecutable()); + new NpmFormatterStepLocations( + projectDir, + buildDir, + npmPathResolver.resolveNpmExecutable(), + npmPathResolver.resolveNodeExecutable())); this.buildDir = requireNonNull(buildDir); this.configFile = configFile; this.inlineTsFmtSettings = inlineTsFmtSettings == null ? new TreeMap<>() : new TreeMap<>(inlineTsFmtSettings); 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 4e33c45ed0..8012102200 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 @@ -23,6 +23,7 @@ import java.nio.charset.Charset; import java.nio.file.Files; import java.util.ArrayList; +import java.util.Arrays; import java.util.Collection; import java.util.List; import java.util.Map; @@ -524,6 +525,9 @@ public abstract static class NpmStepConfig> { @Nullable protected Object npmFile; + @Nullable + protected Object nodeFile; + @Nullable protected Object npmrcFile; @@ -543,6 +547,13 @@ public T npmExecutable(final Object npmFile) { return (T) this; } + @SuppressWarnings("unchecked") + public T nodeExecutable(final Object nodeFile) { + this.nodeFile = nodeFile; + replaceStep(); + return (T) this; + } + public T npmrc(final Object npmrcFile) { this.npmrcFile = npmrcFile; replaceStep(); @@ -553,6 +564,10 @@ File npmFileOrNull() { return fileOrNull(npmFile); } + File nodeFileOrNull() { + return fileOrNull(nodeFile); + } + File npmrcFileOrNull() { return fileOrNull(npmrcFile); } @@ -604,7 +619,7 @@ protected FormatterStep createStep() { provisioner(), project.getProjectDir(), project.getBuildDir(), - new NpmPathResolver(npmFileOrNull(), npmrcFileOrNull(), project.getProjectDir(), project.getRootDir()), + new NpmPathResolver(npmFileOrNull(), nodeFileOrNull(), npmrcFileOrNull(), Arrays.asList(project.getProjectDir(), project.getRootDir())), new com.diffplug.spotless.npm.PrettierConfig( this.prettierConfigFile != null ? project.file(this.prettierConfigFile) : null, this.prettierConfig)); diff --git a/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/JavascriptExtension.java b/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/JavascriptExtension.java index dd476b6a69..e829c2b53a 100644 --- a/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/JavascriptExtension.java +++ b/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/JavascriptExtension.java @@ -17,6 +17,7 @@ import static java.util.Objects.requireNonNull; +import java.util.Arrays; import java.util.Collections; import java.util.LinkedHashMap; import java.util.Map; @@ -107,7 +108,7 @@ public FormatterStep createStep() { provisioner(), project.getProjectDir(), project.getBuildDir(), - new NpmPathResolver(npmFileOrNull(), npmrcFileOrNull(), project.getProjectDir(), project.getRootDir()), + new NpmPathResolver(npmFileOrNull(), nodeFileOrNull(), npmrcFileOrNull(), Arrays.asList(project.getProjectDir(), project.getRootDir())), eslintConfig()); } diff --git a/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/TypescriptExtension.java b/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/TypescriptExtension.java index 0824caa769..2283afccff 100644 --- a/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/TypescriptExtension.java +++ b/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/TypescriptExtension.java @@ -17,6 +17,7 @@ import static java.util.Objects.requireNonNull; +import java.util.Arrays; import java.util.Collections; import java.util.Map; import java.util.Objects; @@ -116,7 +117,7 @@ public FormatterStep createStep() { provisioner(), project.getProjectDir(), project.getBuildDir(), - new NpmPathResolver(npmFileOrNull(), npmrcFileOrNull(), project.getProjectDir(), project.getRootDir()), + new NpmPathResolver(npmFileOrNull(), nodeFileOrNull(), npmrcFileOrNull(), Arrays.asList(project.getProjectDir(), project.getRootDir())), typedConfigFile(), config); } @@ -212,7 +213,7 @@ public FormatterStep createStep() { provisioner(), project.getProjectDir(), project.getBuildDir(), - new NpmPathResolver(npmFileOrNull(), npmrcFileOrNull(), project.getProjectDir(), project.getRootDir()), + new NpmPathResolver(npmFileOrNull(), nodeFileOrNull(), npmrcFileOrNull(), Arrays.asList(project.getProjectDir(), project.getRootDir())), eslintConfig()); } diff --git a/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/NpmTestsWithoutNpmInstallationTest.java b/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/NpmTestsWithoutNpmInstallationTest.java new file mode 100644 index 0000000000..93bc4b699b --- /dev/null +++ b/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/NpmTestsWithoutNpmInstallationTest.java @@ -0,0 +1,59 @@ +/* + * Copyright 2016-2023 DiffPlug + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.diffplug.gradle.spotless; + +import org.assertj.core.api.Assertions; +import org.gradle.testkit.runner.BuildResult; +import org.junit.jupiter.api.Test; + +class NpmTestsWithoutNpmInstallationTest extends GradleIntegrationHarness { + + @Test + void useNodeFromNodeGradlePlugin() throws Exception { + setFile("build.gradle").toLines( + "plugins {", + " id 'com.diffplug.spotless'", + " id 'com.github.node-gradle.node' version '3.5.1'", + "}", + "repositories { mavenCentral() }", + "node {", + " download = true", + " version = '18.13.0'", + " npmVersion = '8.19.2'", + " workDir = file(\"${buildDir}/nodejs\")", + " npmWorkDir = file(\"${buildDir}/npm\")", + "}", + "def prettierConfig = [:]", + "prettierConfig['printWidth'] = 50", + "prettierConfig['parser'] = 'typescript'", + "spotless {", + " format 'mytypescript', {", + " target 'test.ts'", + " prettier()", + " .npmExecutable(\"${tasks.named('npmSetup').get().npmDir.get()}/bin/npm\")", + " .nodeExecutable(\"${tasks.named('nodeSetup').get().nodeDir.get()}/bin/node\")", + " .config(prettierConfig)", + " }", + "}"); + setFile("test.ts").toResource("npm/prettier/config/typescript.dirty"); + // make sure node binary is there + gradleRunner().withArguments("nodeSetup", "npmSetup").build(); + // then run spotless using that node installation + final BuildResult spotlessApply = gradleRunner().withArguments("--stacktrace", "spotlessApply").build(); + Assertions.assertThat(spotlessApply.getOutput()).contains("BUILD SUCCESSFUL"); + assertFile("test.ts").sameAsResource("npm/prettier/config/typescript.configfile.clean"); + } +} diff --git a/plugin-maven/src/main/java/com/diffplug/spotless/maven/npm/AbstractNpmFormatterStepFactory.java b/plugin-maven/src/main/java/com/diffplug/spotless/maven/npm/AbstractNpmFormatterStepFactory.java index 5467f4c3bc..e4a052106a 100644 --- a/plugin-maven/src/main/java/com/diffplug/spotless/maven/npm/AbstractNpmFormatterStepFactory.java +++ b/plugin-maven/src/main/java/com/diffplug/spotless/maven/npm/AbstractNpmFormatterStepFactory.java @@ -18,6 +18,7 @@ import java.io.File; import java.util.AbstractMap; import java.util.Arrays; +import java.util.Collections; import java.util.Map; import java.util.Objects; import java.util.Properties; @@ -34,6 +35,9 @@ public abstract class AbstractNpmFormatterStepFactory implements FormatterStepFa @Parameter private String npmExecutable; + @Parameter + private String nodeExecutable; + @Parameter private String npmrc; @@ -42,6 +46,11 @@ protected File npm(FormatterStepConfig stepConfig) { return npm; } + protected File node(FormatterStepConfig stepConfig) { + File node = nodeExecutable != null ? stepConfig.getFileLocator().locateFile(nodeExecutable) : null; + return node; + } + protected File npmrc(FormatterStepConfig stepConfig) { File npmrc = this.npmrc != null ? stepConfig.getFileLocator().locateFile(this.npmrc) : null; return npmrc; @@ -56,7 +65,7 @@ protected File baseDir(FormatterStepConfig stepConfig) { } protected NpmPathResolver npmPathResolver(FormatterStepConfig stepConfig) { - return new NpmPathResolver(npm(stepConfig), npmrc(stepConfig), baseDir(stepConfig)); + return new NpmPathResolver(npm(stepConfig), node(stepConfig), npmrc(stepConfig), Collections.singletonList(baseDir(stepConfig))); } protected boolean moreThanOneNonNull(Object... objects) { diff --git a/testlib/src/test/java/com/diffplug/spotless/npm/NpmFormatterStepCommonTests.java b/testlib/src/test/java/com/diffplug/spotless/npm/NpmFormatterStepCommonTests.java index dff105108a..60dd42801a 100644 --- a/testlib/src/test/java/com/diffplug/spotless/npm/NpmFormatterStepCommonTests.java +++ b/testlib/src/test/java/com/diffplug/spotless/npm/NpmFormatterStepCommonTests.java @@ -17,17 +17,22 @@ import java.io.File; import java.io.IOException; +import java.util.Collections; import com.diffplug.spotless.ResourceHarness; public abstract class NpmFormatterStepCommonTests extends ResourceHarness { protected NpmPathResolver npmPathResolver() { - return new NpmPathResolver(npmExecutable(), npmrc()); + return new NpmPathResolver(npmExecutable(), nodeExecutable(), npmrc(), Collections.emptyList()); } private File npmExecutable() { - return NpmExecutableResolver.tryFind().orElseThrow(() -> new IllegalStateException("cannot detect node binary")); + return NpmExecutableResolver.tryFind().orElseThrow(() -> new IllegalStateException("cannot detect npm binary")); + } + + private File nodeExecutable() { + return NodeExecutableResolver.tryFindNextTo(npmExecutable()).orElseThrow(() -> new IllegalStateException("cannot detect node binary")); } private File npmrc() { From f4f8da7a259fbe55fdb66fc97b31f6d55c47a266 Mon Sep 17 00:00:00 2001 From: Simon Gamma Date: Tue, 17 Jan 2023 13:11:59 +0100 Subject: [PATCH 604/757] add test for supplying only npm when binary --- .../NpmTestsWithoutNpmInstallationTest.java | 42 +++++++++++++++++-- 1 file changed, 39 insertions(+), 3 deletions(-) diff --git a/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/NpmTestsWithoutNpmInstallationTest.java b/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/NpmTestsWithoutNpmInstallationTest.java index 93bc4b699b..621d953868 100644 --- a/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/NpmTestsWithoutNpmInstallationTest.java +++ b/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/NpmTestsWithoutNpmInstallationTest.java @@ -22,7 +22,7 @@ class NpmTestsWithoutNpmInstallationTest extends GradleIntegrationHarness { @Test - void useNodeFromNodeGradlePlugin() throws Exception { + void useNodeAndNpmFromNodeGradlePlugin() throws Exception { setFile("build.gradle").toLines( "plugins {", " id 'com.diffplug.spotless'", @@ -39,12 +39,48 @@ void useNodeFromNodeGradlePlugin() throws Exception { "def prettierConfig = [:]", "prettierConfig['printWidth'] = 50", "prettierConfig['parser'] = 'typescript'", + "def npmExecExtension = System.getProperty('os.name').toLowerCase().contains('windows') ? '.cmd' : ''", + "def nodeExecExtension = System.getProperty('os.name').toLowerCase().contains('windows') ? '.exe' : ''", "spotless {", " format 'mytypescript', {", " target 'test.ts'", " prettier()", - " .npmExecutable(\"${tasks.named('npmSetup').get().npmDir.get()}/bin/npm\")", - " .nodeExecutable(\"${tasks.named('nodeSetup').get().nodeDir.get()}/bin/node\")", + " .npmExecutable(\"${tasks.named('npmSetup').get().npmDir.get()}/bin/npm${npmExecExtension}\")", + " .nodeExecutable(\"${tasks.named('nodeSetup').get().nodeDir.get()}/bin/node${nodeExecExtension}\")", + " .config(prettierConfig)", + " }", + "}"); + setFile("test.ts").toResource("npm/prettier/config/typescript.dirty"); + // make sure node binary is there + gradleRunner().withArguments("nodeSetup", "npmSetup").build(); + // then run spotless using that node installation + final BuildResult spotlessApply = gradleRunner().withArguments("--stacktrace", "spotlessApply").build(); + Assertions.assertThat(spotlessApply.getOutput()).contains("BUILD SUCCESSFUL"); + assertFile("test.ts").sameAsResource("npm/prettier/config/typescript.configfile.clean"); + } + + @Test + void useNpmFromNodeGradlePlugin() throws Exception { + setFile("build.gradle").toLines( + "plugins {", + " id 'com.diffplug.spotless'", + " id 'com.github.node-gradle.node' version '3.5.1'", + "}", + "repositories { mavenCentral() }", + "node {", + " download = true", + " version = '18.13.0'", + " workDir = file(\"${buildDir}/nodejs\")", + "}", + "def prettierConfig = [:]", + "prettierConfig['printWidth'] = 50", + "prettierConfig['parser'] = 'typescript'", + "def npmExecExtension = System.getProperty('os.name').toLowerCase().contains('windows') ? '.cmd' : ''", + "spotless {", + " format 'mytypescript', {", + " target 'test.ts'", + " prettier()", + " .npmExecutable(\"${tasks.named('npmSetup').get().npmDir.get()}/bin/npm${npmExecExtension}\")", " .config(prettierConfig)", " }", "}"); From 27f9919da7cc5079cfb2823d6c65484c6e542bb9 Mon Sep 17 00:00:00 2001 From: Simon Gamma Date: Tue, 17 Jan 2023 19:51:54 +0100 Subject: [PATCH 605/757] also allow to configure node executable only --- .../spotless/npm/NodeExecutableResolver.java | 5 +++ .../spotless/npm/NpmPathResolver.java | 41 ++++++++++++++++--- .../NpmTestsWithoutNpmInstallationTest.java | 34 +++++++++++++++ 3 files changed, 74 insertions(+), 6 deletions(-) diff --git a/lib/src/main/java/com/diffplug/spotless/npm/NodeExecutableResolver.java b/lib/src/main/java/com/diffplug/spotless/npm/NodeExecutableResolver.java index c9e04da620..eb30ae78b8 100644 --- a/lib/src/main/java/com/diffplug/spotless/npm/NodeExecutableResolver.java +++ b/lib/src/main/java/com/diffplug/spotless/npm/NodeExecutableResolver.java @@ -42,4 +42,9 @@ static Optional tryFindNextTo(File npmExecutable) { } return Optional.empty(); } + + public static String explainMessage() { + return "Spotless was unable to find a node executable.\n" + + "Either specify the node executable explicitly or make sure it can be found next to the npm executable."; + } } diff --git a/lib/src/main/java/com/diffplug/spotless/npm/NpmPathResolver.java b/lib/src/main/java/com/diffplug/spotless/npm/NpmPathResolver.java index d18146188d..4759d2f914 100644 --- a/lib/src/main/java/com/diffplug/spotless/npm/NpmPathResolver.java +++ b/lib/src/main/java/com/diffplug/spotless/npm/NpmPathResolver.java @@ -38,16 +38,45 @@ public NpmPathResolver(File explicitNpmExecutable, File explicitNodeExecutable, this.additionalNpmrcLocations = Collections.unmodifiableList(new ArrayList<>(additionalNpmrcLocations)); } + /** + * Finds the npm executable to use. + *
+ * Either the explicit npm executable is returned, or - if an explicit node executable is configured - tries to find + * the npm executable relative to the node executable. + * Falls back to looking for npm on the user's system using {@link NpmExecutableResolver} + * + * @return the npm executable to use + * @throws IllegalStateException if no npm executable could be found + */ public File resolveNpmExecutable() { - return Optional.ofNullable(this.explicitNpmExecutable) - .orElseGet(() -> NpmExecutableResolver.tryFind() - .orElseThrow(() -> new IllegalStateException("Can't automatically determine npm executable and none was specifically supplied!\n\n" + NpmExecutableResolver.explainMessage()))); + if (this.explicitNpmExecutable != null) { + return this.explicitNpmExecutable; + } + if (this.explicitNodeExecutable != null) { + File nodeExecutableCandidate = new File(this.explicitNodeExecutable.getParentFile(), NpmExecutableResolver.npmExecutableName()); + if (nodeExecutableCandidate.canExecute()) { + return nodeExecutableCandidate; + } + } + return NpmExecutableResolver.tryFind() + .orElseThrow(() -> new IllegalStateException("Can't automatically determine npm executable and none was specifically supplied!\n\n" + NpmExecutableResolver.explainMessage())); } + /** + * Finds the node executable to use. + *
+ * Either the explicit node executable is returned, or tries to find the node executable relative to the npm executable + * found by {@link #resolveNpmExecutable()}. + * @return the node executable to use + * @throws IllegalStateException if no node executable could be found + */ public File resolveNodeExecutable() { - return Optional.ofNullable(this.explicitNodeExecutable) - .orElseGet(() -> NodeExecutableResolver.tryFindNextTo(resolveNpmExecutable()) - .orElseThrow(() -> new IllegalStateException("Can't automatically determine node executable and none was specifically supplied!\n\n" + NpmExecutableResolver.explainMessage()))); + if (this.explicitNodeExecutable != null) { + return this.explicitNodeExecutable; + } + File npmExecutable = resolveNpmExecutable(); + return NodeExecutableResolver.tryFindNextTo(npmExecutable) + .orElseThrow(() -> new IllegalStateException("Can't automatically determine node executable and none was specifically supplied!\n\n" + NodeExecutableResolver.explainMessage())); } public String resolveNpmrcContent() { diff --git a/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/NpmTestsWithoutNpmInstallationTest.java b/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/NpmTestsWithoutNpmInstallationTest.java index 621d953868..8147c79228 100644 --- a/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/NpmTestsWithoutNpmInstallationTest.java +++ b/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/NpmTestsWithoutNpmInstallationTest.java @@ -92,4 +92,38 @@ void useNpmFromNodeGradlePlugin() throws Exception { Assertions.assertThat(spotlessApply.getOutput()).contains("BUILD SUCCESSFUL"); assertFile("test.ts").sameAsResource("npm/prettier/config/typescript.configfile.clean"); } + + @Test + void useNpmNextToConfiguredNodePluginFromNodeGradlePlugin() throws Exception { + setFile("build.gradle").toLines( + "plugins {", + " id 'com.diffplug.spotless'", + " id 'com.github.node-gradle.node' version '3.5.1'", + "}", + "repositories { mavenCentral() }", + "node {", + " download = true", + " version = '18.13.0'", + " workDir = file(\"${buildDir}/nodejs\")", + "}", + "def prettierConfig = [:]", + "prettierConfig['printWidth'] = 50", + "prettierConfig['parser'] = 'typescript'", + "def nodeExecExtension = System.getProperty('os.name').toLowerCase().contains('windows') ? '.exe' : ''", + "spotless {", + " format 'mytypescript', {", + " target 'test.ts'", + " prettier()", + " .nodeExecutable(\"${tasks.named('nodeSetup').get().nodeDir.get()}/bin/node${nodeExecExtension}\")", + " .config(prettierConfig)", + " }", + "}"); + setFile("test.ts").toResource("npm/prettier/config/typescript.dirty"); + // make sure node binary is there + gradleRunner().withArguments("nodeSetup", "npmSetup").build(); + // then run spotless using that node installation + final BuildResult spotlessApply = gradleRunner().withArguments("--stacktrace", "spotlessApply").build(); + Assertions.assertThat(spotlessApply.getOutput()).contains("BUILD SUCCESSFUL"); + assertFile("test.ts").sameAsResource("npm/prettier/config/typescript.configfile.clean"); + } } From a96d92c0f524f71fc73476ffed6ab8f6b0425308 Mon Sep 17 00:00:00 2001 From: Simon Gamma Date: Tue, 17 Jan 2023 20:46:32 +0100 Subject: [PATCH 606/757] add tests that verifies issue #1499 --- .../NpmTestsWithoutNpmInstallationTest.java | 41 +++++++++++++++++++ 1 file changed, 41 insertions(+) diff --git a/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/NpmTestsWithoutNpmInstallationTest.java b/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/NpmTestsWithoutNpmInstallationTest.java index 8147c79228..d5c4e8f092 100644 --- a/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/NpmTestsWithoutNpmInstallationTest.java +++ b/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/NpmTestsWithoutNpmInstallationTest.java @@ -17,6 +17,7 @@ import org.assertj.core.api.Assertions; import org.gradle.testkit.runner.BuildResult; +import org.junit.jupiter.api.Disabled; import org.junit.jupiter.api.Test; class NpmTestsWithoutNpmInstallationTest extends GradleIntegrationHarness { @@ -59,6 +60,46 @@ void useNodeAndNpmFromNodeGradlePlugin() throws Exception { assertFile("test.ts").sameAsResource("npm/prettier/config/typescript.configfile.clean"); } + @Test + @Disabled("This test is disabled because we currently don't support using npm/node installed by the" + + "node-gradle-plugin as the installation takes place in the *execution* phase, but spotless needs it in the *configuration* phase.") + void useNodeAndNpmFromNodeGradlePluginInOneSweep() throws Exception { + setFile("build.gradle").toLines( + "plugins {", + " id 'com.diffplug.spotless'", + " id 'com.github.node-gradle.node' version '3.5.1'", + "}", + "repositories { mavenCentral() }", + "node {", + " download = true", + " version = '18.13.0'", + " npmVersion = '8.19.2'", + " workDir = file(\"${buildDir}/nodejs\")", + " npmWorkDir = file(\"${buildDir}/npm\")", + "}", + "def prettierConfig = [:]", + "prettierConfig['printWidth'] = 50", + "prettierConfig['parser'] = 'typescript'", + "def npmExecExtension = System.getProperty('os.name').toLowerCase().contains('windows') ? '.cmd' : ''", + "def nodeExecExtension = System.getProperty('os.name').toLowerCase().contains('windows') ? '.exe' : ''", + "spotless {", + " format 'mytypescript', {", + " target 'test.ts'", + " prettier()", + " .npmExecutable(\"${tasks.named('npmSetup').get().npmDir.get()}/bin/npm${npmExecExtension}\")", + " .nodeExecutable(\"${tasks.named('nodeSetup').get().nodeDir.get()}/bin/node${nodeExecExtension}\")", + " .config(prettierConfig)", + " }", + "}", + "tasks.named('spotlessMytypescript').configure {", + " it.dependsOn('nodeSetup', 'npmSetup')", + "}"); + setFile("test.ts").toResource("npm/prettier/config/typescript.dirty"); + final BuildResult spotlessApply = gradleRunner().withArguments("--stacktrace", "spotlessApply").build(); + Assertions.assertThat(spotlessApply.getOutput()).contains("BUILD SUCCESSFUL"); + assertFile("test.ts").sameAsResource("npm/prettier/config/typescript.configfile.clean"); + } + @Test void useNpmFromNodeGradlePlugin() throws Exception { setFile("build.gradle").toLines( From b9437cd78b16d4ef2aeee942bc8d7b6f367068ef Mon Sep 17 00:00:00 2001 From: Simon Gamma Date: Wed, 18 Jan 2023 13:02:15 +0100 Subject: [PATCH 607/757] add maven test to verify dynamically installed npm works --- .../maven/MavenIntegrationHarness.java | 27 +++++--- .../maven/MultiModuleProjectTest.java | 2 +- .../spotless/maven/SpotlessCheckMojoTest.java | 1 + .../incremental/UpToDateCheckingTest.java | 3 +- .../maven/npm/NpmFrontendMavenPlugin.java | 66 +++++++++++++++++++ ...namicallyInstalledNpmInstallationTest.java | 48 ++++++++++++++ .../src/test/resources/pom-test.xml.mustache | 1 + 7 files changed, 137 insertions(+), 11 deletions(-) create mode 100644 plugin-maven/src/test/java/com/diffplug/spotless/maven/npm/NpmFrontendMavenPlugin.java create mode 100644 plugin-maven/src/test/java/com/diffplug/spotless/maven/npm/NpmTestsWithDynamicallyInstalledNpmInstallationTest.java diff --git a/plugin-maven/src/test/java/com/diffplug/spotless/maven/MavenIntegrationHarness.java b/plugin-maven/src/test/java/com/diffplug/spotless/maven/MavenIntegrationHarness.java index 5a724408c8..f4e94e573c 100644 --- a/plugin-maven/src/test/java/com/diffplug/spotless/maven/MavenIntegrationHarness.java +++ b/plugin-maven/src/test/java/com/diffplug/spotless/maven/MavenIntegrationHarness.java @@ -59,6 +59,7 @@ public class MavenIntegrationHarness extends ResourceHarness { private static final String EXECUTIONS = "executions"; private static final String MODULES = "modules"; private static final String DEPENDENCIES = "dependencies"; + private static final String PLUGINS = "plugins"; private static final String MODULE_NAME = "name"; private static final int REMOTE_DEBUG_PORT = 5005; @@ -151,6 +152,10 @@ protected void writePomWithPrettierSteps(String includes, String... steps) throw writePom(formats(groupWithSteps("format", including(includes), steps))); } + protected void writePomWithPrettierSteps(String[] plugins, String includes, String... steps) throws IOException { + writePom(null, formats(groupWithSteps("format", including(includes), steps)), null, plugins); + } + protected void writePomWithPomSteps(String... steps) throws IOException { writePom(groupWithSteps("pom", including("pom_test.xml"), steps)); } @@ -168,11 +173,11 @@ protected void writePomWithYamlSteps(String... steps) throws IOException { } protected void writePom(String... configuration) throws IOException { - writePom(null, configuration, null); + writePom(null, configuration, null, null); } - protected void writePom(String[] executions, String[] configuration, String[] dependencies) throws IOException { - String pomXmlContent = createPomXmlContent(null, executions, configuration, dependencies); + protected void writePom(String[] executions, String[] configuration, String[] dependencies, String[] plugins) throws IOException { + String pomXmlContent = createPomXmlContent(null, executions, configuration, dependencies, plugins); setFile("pom.xml").toContent(pomXmlContent); } @@ -203,17 +208,17 @@ protected MavenRunner mavenRunnerWithRemoteDebug() throws IOException { return mavenRunner().withRemoteDebug(REMOTE_DEBUG_PORT); } - protected String createPomXmlContent(String pluginVersion, String[] executions, String[] configuration, String[] dependencies) throws IOException { - return createPomXmlContent("/pom-test.xml.mustache", pluginVersion, executions, configuration, dependencies); + protected String createPomXmlContent(String pluginVersion, String[] executions, String[] configuration, String[] dependencies, String[] plugins) throws IOException { + return createPomXmlContent("/pom-test.xml.mustache", pluginVersion, executions, configuration, dependencies, plugins); } - protected String createPomXmlContent(String pomTemplate, String pluginVersion, String[] executions, String[] configuration, String[] dependencies) throws IOException { - Map params = buildPomXmlParams(pluginVersion, executions, configuration, null, dependencies); + protected String createPomXmlContent(String pomTemplate, String pluginVersion, String[] executions, String[] configuration, String[] dependencies, String[] plugins) throws IOException { + Map params = buildPomXmlParams(pluginVersion, executions, configuration, null, dependencies, plugins); return createPomXmlContent(pomTemplate, params); } protected String createPomXmlContent(String pluginVersion, String[] executions, String[] configuration) throws IOException { - return createPomXmlContent(pluginVersion, executions, configuration, null); + return createPomXmlContent(pluginVersion, executions, configuration, null, null); } protected String createPomXmlContent(String pomTemplate, Map params) throws IOException { @@ -226,7 +231,7 @@ protected String createPomXmlContent(String pomTemplate, Map par } } - protected static Map buildPomXmlParams(String pluginVersion, String[] executions, String[] configuration, String[] modules, String[] dependencies) { + protected static Map buildPomXmlParams(String pluginVersion, String[] executions, String[] configuration, String[] modules, String[] dependencies, String[] plugins) { Map params = new HashMap<>(); params.put(SPOTLESS_MAVEN_PLUGIN_VERSION, pluginVersion == null ? getSystemProperty(SPOTLESS_MAVEN_PLUGIN_VERSION) : pluginVersion); @@ -247,6 +252,10 @@ protected static Map buildPomXmlParams(String pluginVersion, Str params.put(DEPENDENCIES, String.join("\n", dependencies)); } + if (plugins != null) { + params.put(PLUGINS, String.join("\n", plugins)); + } + return params; } diff --git a/plugin-maven/src/test/java/com/diffplug/spotless/maven/MultiModuleProjectTest.java b/plugin-maven/src/test/java/com/diffplug/spotless/maven/MultiModuleProjectTest.java index ae8378c566..6206affc04 100644 --- a/plugin-maven/src/test/java/com/diffplug/spotless/maven/MultiModuleProjectTest.java +++ b/plugin-maven/src/test/java/com/diffplug/spotless/maven/MultiModuleProjectTest.java @@ -145,7 +145,7 @@ private void createRootPom() throws IOException { modulesList.addAll(subProjects.keySet()); String[] modules = modulesList.toArray(new String[0]); - Map rootPomParams = buildPomXmlParams(null, null, configuration, modules, null); + Map rootPomParams = buildPomXmlParams(null, null, configuration, modules, null, null); setFile("pom.xml").toContent(createPomXmlContent("/multi-module/pom-parent.xml.mustache", rootPomParams)); } diff --git a/plugin-maven/src/test/java/com/diffplug/spotless/maven/SpotlessCheckMojoTest.java b/plugin-maven/src/test/java/com/diffplug/spotless/maven/SpotlessCheckMojoTest.java index 566851c26c..92a78e3923 100644 --- a/plugin-maven/src/test/java/com/diffplug/spotless/maven/SpotlessCheckMojoTest.java +++ b/plugin-maven/src/test/java/com/diffplug/spotless/maven/SpotlessCheckMojoTest.java @@ -62,6 +62,7 @@ void testSpotlessCheckBindingToVerifyPhase() throws Exception { " ${basedir}/license.txt", " ", ""}, + null, null); testSpotlessCheck(UNFORMATTED_FILE, "verify", true); diff --git a/plugin-maven/src/test/java/com/diffplug/spotless/maven/incremental/UpToDateCheckingTest.java b/plugin-maven/src/test/java/com/diffplug/spotless/maven/incremental/UpToDateCheckingTest.java index 6afcba7430..0a9fe8f2d4 100644 --- a/plugin-maven/src/test/java/com/diffplug/spotless/maven/incremental/UpToDateCheckingTest.java +++ b/plugin-maven/src/test/java/com/diffplug/spotless/maven/incremental/UpToDateCheckingTest.java @@ -98,7 +98,8 @@ private void writePomWithPluginManagementAndDependency() throws IOException { " javax.inject", " 1", " ", - ""})); + ""}, + null)); } @Test diff --git a/plugin-maven/src/test/java/com/diffplug/spotless/maven/npm/NpmFrontendMavenPlugin.java b/plugin-maven/src/test/java/com/diffplug/spotless/maven/npm/NpmFrontendMavenPlugin.java new file mode 100644 index 0000000000..3d20170fab --- /dev/null +++ b/plugin-maven/src/test/java/com/diffplug/spotless/maven/npm/NpmFrontendMavenPlugin.java @@ -0,0 +1,66 @@ +/* + * Copyright 2023 DiffPlug + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.diffplug.spotless.maven.npm; + +/** + * Helper class to configure a maven pom to use frontend-maven-plugin. + * @see frontend-maven-plugin on github + */ +public final class NpmFrontendMavenPlugin { + + public static final String GROUP_ID = "com.github.eirslett"; + public static final String ARTIFACT_ID = "frontend-maven-plugin"; + public static final String VERSION = "1.11.3"; // for now, we stick with this version, as it is the last to support maven 3.1 (see pom-test.xml.mustache) + + public static final String GOAL_INSTALL_NODE_AND_NPM = "install-node-and-npm"; + + public static final String INSTALL_DIRECTORY = "target"; + + private NpmFrontendMavenPlugin() { + // prevent instantiation + } + + public static String[] pomPluginLines(String nodeVersion, String npmVersion) { + return new String[]{ + "", + String.format(" %s", GROUP_ID), + String.format(" %s", ARTIFACT_ID), + String.format(" %s", VERSION), + " ", + " ", + " install node and npm", + " ", + String.format(" %s", GOAL_INSTALL_NODE_AND_NPM), + " ", + " ", + " ", + " ", + (nodeVersion != null ? " " + nodeVersion + "" : ""), + (npmVersion != null ? " " + npmVersion + "" : ""), + String.format(" %s", INSTALL_DIRECTORY), + " ", + "" + }; + } + + public static String installNpmMavenGoal() { + return String.format("%s:%s:%s", GROUP_ID, ARTIFACT_ID, GOAL_INSTALL_NODE_AND_NPM); + } + + public static String installedNpmPath() { + return String.format("%s/node/npm", INSTALL_DIRECTORY); + } +} diff --git a/plugin-maven/src/test/java/com/diffplug/spotless/maven/npm/NpmTestsWithDynamicallyInstalledNpmInstallationTest.java b/plugin-maven/src/test/java/com/diffplug/spotless/maven/npm/NpmTestsWithDynamicallyInstalledNpmInstallationTest.java new file mode 100644 index 0000000000..78830bf09d --- /dev/null +++ b/plugin-maven/src/test/java/com/diffplug/spotless/maven/npm/NpmTestsWithDynamicallyInstalledNpmInstallationTest.java @@ -0,0 +1,48 @@ +/* + * Copyright 2023 DiffPlug + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.diffplug.spotless.maven.npm; + +import static com.diffplug.spotless.maven.npm.NpmFrontendMavenPlugin.installNpmMavenGoal; +import static com.diffplug.spotless.maven.npm.NpmFrontendMavenPlugin.installedNpmPath; +import static com.diffplug.spotless.maven.npm.NpmFrontendMavenPlugin.pomPluginLines; + +import org.junit.jupiter.api.Test; + +import com.diffplug.spotless.maven.MavenIntegrationHarness; + +public class NpmTestsWithDynamicallyInstalledNpmInstallationTest extends MavenIntegrationHarness { + + @Test + void useDownloadedNpmInstallation() throws Exception { + writePomWithPrettierSteps( + pomPluginLines("v18.13.0", null), + "src/main/typescript/test.ts", + "", + " " + installedNpmPath() + "", + ""); + + String kind = "typescript"; + String suffix = "ts"; + String configPath = ".prettierrc.yml"; + setFile(configPath).toResource("npm/prettier/filetypes/" + kind + "/" + ".prettierrc.yml"); + String path = "src/main/" + kind + "/test." + suffix; + setFile(path).toResource("npm/prettier/filetypes/" + kind + "/" + kind + ".dirty"); + + mavenRunner().withArguments(installNpmMavenGoal(), "spotless:apply").runNoError(); + assertFile(path).sameAsResource("npm/prettier/filetypes/" + kind + "/" + kind + ".clean"); + } + +} diff --git a/plugin-maven/src/test/resources/pom-test.xml.mustache b/plugin-maven/src/test/resources/pom-test.xml.mustache index 122f5d9218..6db3cb0c15 100644 --- a/plugin-maven/src/test/resources/pom-test.xml.mustache +++ b/plugin-maven/src/test/resources/pom-test.xml.mustache @@ -21,6 +21,7 @@ + {{{plugins}}} com.diffplug.spotless spotless-maven-plugin From 789b9d210a4b1555f0eee41d7e178798ecdd16f1 Mon Sep 17 00:00:00 2001 From: Simon Gamma Date: Wed, 18 Jan 2023 14:22:13 +0100 Subject: [PATCH 608/757] add nodeExecutable configuration to README --- plugin-gradle/README.md | 11 ++++++++--- plugin-maven/README.md | 10 ++++++++-- 2 files changed, 16 insertions(+), 5 deletions(-) diff --git a/plugin-gradle/README.md b/plugin-gradle/README.md index f2567a5924..11f7866644 100644 --- a/plugin-gradle/README.md +++ b/plugin-gradle/README.md @@ -844,18 +844,23 @@ spotless { ### npm detection Prettier is based on NodeJS, so a working NodeJS installation (especially npm) is required on the host running spotless. -Spotless will try to auto-discover an npm installation. If that is not working for you, it is possible to directly configure the npm binary to use. +Spotless will try to auto-discover an npm installation. If that is not working for you, it is possible to directly configure the npm +and/or node binary to use. ```gradle spotless { format 'javascript', { - prettier().npmExecutable('/usr/bin/npm').config(...) + prettier().npmExecutable('/usr/bin/npm').nodeExecutable('/usr/bin/node').config(...) ``` +If you provide both `npmExecutable` and `nodeExecutable`, spotless will use these paths. If you specify only one of the +two, spotless will assume the other one is in the same directory. + ### `.npmrc` detection Spotless picks up npm configuration stored in a `.npmrc` file either in the project directory or in your user home. -Alternatively you can supply spotless with a location of the `.npmrc` file to use. (This can be combined with `npmExecutable`, of course.) +Alternatively you can supply spotless with a location of the `.npmrc` file to use. (This can be combined with +`npmExecutable` and `nodeExecutable`, of course.) ```gradle spotless { diff --git a/plugin-maven/README.md b/plugin-maven/README.md index 2a455dfe07..dc3795927a 100644 --- a/plugin-maven/README.md +++ b/plugin-maven/README.md @@ -1050,17 +1050,23 @@ Since spotless uses the actual npm prettier package behind the scenes, it is pos ### npm detection Prettier is based on NodeJS, so to use it, a working NodeJS installation (especially npm) is required on the host running spotless. -Spotless will try to auto-discover an npm installation. If that is not working for you, it is possible to directly configure the npm binary to use. +Spotless will try to auto-discover an npm installation. If that is not working for you, it is possible to directly configure the npm +and/or node binary to use. ```xml /usr/bin/npm + /usr/bin/node ``` +If you provide both `npmExecutable` and `nodeExecutable`, spotless will use these paths. If you specify only one of the +two, spotless will assume the other one is in the same directory. + ### `.npmrc` detection Spotless picks up npm configuration stored in a `.npmrc` file either in the project directory or in your user home. -Alternatively you can supply spotless with a location of the `.npmrc` file to use. (This can be combined with `npmExecutable`, of course.) +Alternatively you can supply spotless with a location of the `.npmrc` file to use. (This can be combined with +`npmExecutable` and `nodeExecutable`, of course.) ```xml From a9c79aee0929dc15ac1683cf64831d85f589e7d9 Mon Sep 17 00:00:00 2001 From: Simon Gamma Date: Wed, 18 Jan 2023 14:31:57 +0100 Subject: [PATCH 609/757] add `nodeExecutable` to changes.md --- CHANGES.md | 1 + plugin-gradle/CHANGES.md | 1 + plugin-maven/CHANGES.md | 1 + 3 files changed, 3 insertions(+) diff --git a/CHANGES.md b/CHANGES.md index 60c723f62d..dee5bb6175 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -12,6 +12,7 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format ( ## [Unreleased] ### Added * `ProcessRunner` has added some convenience methods so it can be used for maven testing. ([#1496](https://github.com/diffplug/spotless/pull/1496)) +* Allow to specify node executable for node-based formatters using `nodeExecutable` parameter ([#1500](https://github.com/diffplug/spotless/pull/1500)) ### Fixed * The default list of type annotations used by `formatAnnotations` has had 8 more annotations from the Checker Framework added [#1494](https://github.com/diffplug/spotless/pull/1494) ### Changes diff --git a/plugin-gradle/CHANGES.md b/plugin-gradle/CHANGES.md index 63e5b43d74..58142c6755 100644 --- a/plugin-gradle/CHANGES.md +++ b/plugin-gradle/CHANGES.md @@ -4,6 +4,7 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format ( ## [Unreleased] ### Added +* Allow to specify node executable for node-based formatters using `nodeExecutable` parameter ([#1500](https://github.com/diffplug/spotless/pull/1500)) ### Fixed * The default list of type annotations used by `formatAnnotations` has had 8 more annotations from the Checker Framework added [#1494](https://github.com/diffplug/spotless/pull/1494) ### Changes diff --git a/plugin-maven/CHANGES.md b/plugin-maven/CHANGES.md index 1bb49898f1..d93893f35b 100644 --- a/plugin-maven/CHANGES.md +++ b/plugin-maven/CHANGES.md @@ -4,6 +4,7 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format ( ## [Unreleased] ### Added +* Allow to specify node executable for node-based formatters using `nodeExecutable` parameter ([#1500](https://github.com/diffplug/spotless/pull/1500)) ### Fixed * The default list of type annotations used by `formatAnnotations` has had 8 more annotations from the Checker Framework added [#1494](https://github.com/diffplug/spotless/pull/1494) ### Changes From 6b9b870c8754c4af9967ea094b1049f4dc941d25 Mon Sep 17 00:00:00 2001 From: Benoit Lacelle Date: Wed, 18 Jan 2023 23:08:33 +0400 Subject: [PATCH 610/757] Rely on generic JsonNode --- .../spotless/glue/yaml/JacksonYamlFormatterFunc.java | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/lib/src/jackson/java/com/diffplug/spotless/glue/yaml/JacksonYamlFormatterFunc.java b/lib/src/jackson/java/com/diffplug/spotless/glue/yaml/JacksonYamlFormatterFunc.java index edb350c559..ae6b85530b 100644 --- a/lib/src/jackson/java/com/diffplug/spotless/glue/yaml/JacksonYamlFormatterFunc.java +++ b/lib/src/jackson/java/com/diffplug/spotless/glue/yaml/JacksonYamlFormatterFunc.java @@ -22,6 +22,7 @@ import com.fasterxml.jackson.core.JsonFactory; import com.fasterxml.jackson.core.JsonParser; import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.databind.JsonNode; import com.fasterxml.jackson.databind.ObjectMapper; import com.fasterxml.jackson.databind.node.ContainerNode; import com.fasterxml.jackson.dataformat.yaml.YAMLFactory; @@ -60,13 +61,11 @@ protected JsonFactory makeJsonFactory() { @Override protected String format(ObjectMapper objectMapper, String input) throws IllegalArgumentException, IOException { - //if (true) - // throw new IllegalArgumentException("input = \r\n" + input); try { // https://stackoverflow.com/questions/25222327/deserialize-pojos-from-multiple-yaml-documents-in-a-single-file-in-jackson // https://github.com/FasterXML/jackson-dataformats-text/issues/66#issuecomment-375328648 JsonParser yamlParser = objectMapper.getFactory().createParser(input); - List documents = objectMapper.readValues(yamlParser, ContainerNode.class).readAll(); + List documents = objectMapper.readValues(yamlParser, JsonNode.class).readAll(); // https://github.com/FasterXML/jackson-dataformats-text/issues/66#issuecomment-554265055 // https://github.com/FasterXML/jackson-dataformats-text/issues/66#issuecomment-554265055 From 6b6e854e19b0969d23918ae9bd9ec705f25fc46d Mon Sep 17 00:00:00 2001 From: Benoit Lacelle Date: Wed, 18 Jan 2023 23:20:27 +0400 Subject: [PATCH 611/757] Fix style --- .../diffplug/spotless/glue/yaml/JacksonYamlFormatterFunc.java | 1 - 1 file changed, 1 deletion(-) diff --git a/lib/src/jackson/java/com/diffplug/spotless/glue/yaml/JacksonYamlFormatterFunc.java b/lib/src/jackson/java/com/diffplug/spotless/glue/yaml/JacksonYamlFormatterFunc.java index ae6b85530b..89304d8d0a 100644 --- a/lib/src/jackson/java/com/diffplug/spotless/glue/yaml/JacksonYamlFormatterFunc.java +++ b/lib/src/jackson/java/com/diffplug/spotless/glue/yaml/JacksonYamlFormatterFunc.java @@ -24,7 +24,6 @@ import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.databind.JsonNode; import com.fasterxml.jackson.databind.ObjectMapper; -import com.fasterxml.jackson.databind.node.ContainerNode; import com.fasterxml.jackson.dataformat.yaml.YAMLFactory; import com.fasterxml.jackson.dataformat.yaml.YAMLFactoryBuilder; import com.fasterxml.jackson.dataformat.yaml.YAMLGenerator; From e8f0d2d27bb542987b8cc97b7a4c2b5a04880306 Mon Sep 17 00:00:00 2001 From: Simon Gamma Date: Wed, 18 Jan 2023 19:59:56 +0100 Subject: [PATCH 612/757] try fix windows build: set binary name for win --- .../spotless/GradleIntegrationHarness.java | 47 ++- .../NpmTestsWithoutNpmInstallationTest.java | 284 ++++++++++-------- .../maven/npm/NpmFrontendMavenPlugin.java | 2 +- 3 files changed, 193 insertions(+), 140 deletions(-) diff --git a/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/GradleIntegrationHarness.java b/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/GradleIntegrationHarness.java index 9e2f490429..1763fd088f 100644 --- a/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/GradleIntegrationHarness.java +++ b/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/GradleIntegrationHarness.java @@ -21,6 +21,7 @@ import java.io.IOException; import java.util.List; import java.util.ListIterator; +import java.util.function.BiConsumer; import java.util.function.Predicate; import java.util.stream.Collectors; @@ -117,11 +118,34 @@ protected GradleRunner gradleRunner() throws IOException { } /** Dumps the complete file contents of the folder to the console. */ - protected String getContents() throws IOException { + protected String getContents() { return getContents(subPath -> !subPath.startsWith(".gradle")); } - protected String getContents(Predicate subpathsToInclude) throws IOException { + protected String getContents(Predicate subpathsToInclude) { + return StringPrinter.buildString(printer -> Errors.rethrow().run(() -> iterateFiles(subpathsToInclude, (subpath, file) -> { + printer.println("### " + subpath + " ###"); + try { + printer.println(read(subpath)); + } catch (IOException e) { + throw new RuntimeException(e); + } + }))); + } + + /** Dumps the filtered file listing of the folder to the console. */ + protected String listFiles(Predicate subpathsToInclude) { + return StringPrinter.buildString(printer -> iterateFiles(subpathsToInclude, (subPath, file) -> { + printer.println(subPath + " [" + getFileAttributes(file) + "]"); + })); + } + + /** Dumps the file listing of the folder to the console. */ + protected String listFiles() { + return listFiles(subPath -> !subPath.startsWith(".gradle")); + } + + protected void iterateFiles(Predicate subpathsToInclude, BiConsumer consumer) { TreeDef treeDef = TreeDef.forFile(Errors.rethrow()); List files = TreeStream.depthFirst(treeDef, rootFolder()) .filter(File::isFile) @@ -129,16 +153,17 @@ protected String getContents(Predicate subpathsToInclude) throws IOExcep ListIterator iterator = files.listIterator(files.size()); int rootLength = rootFolder().getAbsolutePath().length() + 1; - return StringPrinter.buildString(printer -> Errors.rethrow().run(() -> { - while (iterator.hasPrevious()) { - File file = iterator.previous(); - String subPath = file.getAbsolutePath().substring(rootLength); - if (subpathsToInclude.test(subPath)) { - printer.println("### " + subPath + " ###"); - printer.println(read(subPath)); - } + while (iterator.hasPrevious()) { + File file = iterator.previous(); + String subPath = file.getAbsolutePath().substring(rootLength); + if (subpathsToInclude.test(subPath)) { + consumer.accept(subPath, file); } - })); + } + } + + protected String getFileAttributes(File file) { + return (file.canRead() ? "r" : "-") + (file.canWrite() ? "w" : "-") + (file.canExecute() ? "x" : "-"); } protected void checkRunsThenUpToDate() throws IOException { diff --git a/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/NpmTestsWithoutNpmInstallationTest.java b/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/NpmTestsWithoutNpmInstallationTest.java index d5c4e8f092..916d853920 100644 --- a/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/NpmTestsWithoutNpmInstallationTest.java +++ b/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/NpmTestsWithoutNpmInstallationTest.java @@ -20,151 +20,179 @@ import org.junit.jupiter.api.Disabled; import org.junit.jupiter.api.Test; +import com.diffplug.common.base.Predicates; + class NpmTestsWithoutNpmInstallationTest extends GradleIntegrationHarness { @Test void useNodeAndNpmFromNodeGradlePlugin() throws Exception { - setFile("build.gradle").toLines( - "plugins {", - " id 'com.diffplug.spotless'", - " id 'com.github.node-gradle.node' version '3.5.1'", - "}", - "repositories { mavenCentral() }", - "node {", - " download = true", - " version = '18.13.0'", - " npmVersion = '8.19.2'", - " workDir = file(\"${buildDir}/nodejs\")", - " npmWorkDir = file(\"${buildDir}/npm\")", - "}", - "def prettierConfig = [:]", - "prettierConfig['printWidth'] = 50", - "prettierConfig['parser'] = 'typescript'", - "def npmExecExtension = System.getProperty('os.name').toLowerCase().contains('windows') ? '.cmd' : ''", - "def nodeExecExtension = System.getProperty('os.name').toLowerCase().contains('windows') ? '.exe' : ''", - "spotless {", - " format 'mytypescript', {", - " target 'test.ts'", - " prettier()", - " .npmExecutable(\"${tasks.named('npmSetup').get().npmDir.get()}/bin/npm${npmExecExtension}\")", - " .nodeExecutable(\"${tasks.named('nodeSetup').get().nodeDir.get()}/bin/node${nodeExecExtension}\")", - " .config(prettierConfig)", - " }", - "}"); - setFile("test.ts").toResource("npm/prettier/config/typescript.dirty"); - // make sure node binary is there - gradleRunner().withArguments("nodeSetup", "npmSetup").build(); - // then run spotless using that node installation - final BuildResult spotlessApply = gradleRunner().withArguments("--stacktrace", "spotlessApply").build(); - Assertions.assertThat(spotlessApply.getOutput()).contains("BUILD SUCCESSFUL"); - assertFile("test.ts").sameAsResource("npm/prettier/config/typescript.configfile.clean"); + try { + setFile("build.gradle").toLines( + "plugins {", + " id 'com.diffplug.spotless'", + " id 'com.github.node-gradle.node' version '3.5.1'", + "}", + "repositories { mavenCentral() }", + "node {", + " download = true", + " version = '18.13.0'", + " npmVersion = '8.19.2'", + " workDir = file(\"${buildDir}/nodejs\")", + " npmWorkDir = file(\"${buildDir}/npm\")", + "}", + "def prettierConfig = [:]", + "prettierConfig['printWidth'] = 50", + "prettierConfig['parser'] = 'typescript'", + "def npmExec = System.getProperty('os.name').toLowerCase().contains('windows') ? '/npm.cmd' : '/bin/npm'", + "def nodeExec = System.getProperty('os.name').toLowerCase().contains('windows') ? '/node.exe' : '/bin/node'", + "spotless {", + " format 'mytypescript', {", + " target 'test.ts'", + " prettier()", + " .npmExecutable(\"${tasks.named('npmSetup').get().npmDir.get()}${npmExec}\")", + " .nodeExecutable(\"${tasks.named('nodeSetup').get().nodeDir.get()}${nodeExec}\")", + " .config(prettierConfig)", + " }", + "}"); + setFile("test.ts").toResource("npm/prettier/config/typescript.dirty"); + // make sure node binary is there + gradleRunner().withArguments("nodeSetup", "npmSetup").build(); + // then run spotless using that node installation + final BuildResult spotlessApply = gradleRunner().withArguments("--stacktrace", "spotlessApply").build(); + Assertions.assertThat(spotlessApply.getOutput()).contains("BUILD SUCCESSFUL"); + assertFile("test.ts").sameAsResource("npm/prettier/config/typescript.configfile.clean"); + } catch (Exception e) { + printContents(); + throw e; + } + } + + private void printContents() { + System.out.println("************* Folder contents **************************"); + System.out.println(listFiles(Predicates.and(path -> !path.startsWith(".gradle"), path -> !path.contains("/node_modules/"), path -> !path.contains("/include/")))); + System.out.println("********************************************************"); } @Test @Disabled("This test is disabled because we currently don't support using npm/node installed by the" + "node-gradle-plugin as the installation takes place in the *execution* phase, but spotless needs it in the *configuration* phase.") void useNodeAndNpmFromNodeGradlePluginInOneSweep() throws Exception { - setFile("build.gradle").toLines( - "plugins {", - " id 'com.diffplug.spotless'", - " id 'com.github.node-gradle.node' version '3.5.1'", - "}", - "repositories { mavenCentral() }", - "node {", - " download = true", - " version = '18.13.0'", - " npmVersion = '8.19.2'", - " workDir = file(\"${buildDir}/nodejs\")", - " npmWorkDir = file(\"${buildDir}/npm\")", - "}", - "def prettierConfig = [:]", - "prettierConfig['printWidth'] = 50", - "prettierConfig['parser'] = 'typescript'", - "def npmExecExtension = System.getProperty('os.name').toLowerCase().contains('windows') ? '.cmd' : ''", - "def nodeExecExtension = System.getProperty('os.name').toLowerCase().contains('windows') ? '.exe' : ''", - "spotless {", - " format 'mytypescript', {", - " target 'test.ts'", - " prettier()", - " .npmExecutable(\"${tasks.named('npmSetup').get().npmDir.get()}/bin/npm${npmExecExtension}\")", - " .nodeExecutable(\"${tasks.named('nodeSetup').get().nodeDir.get()}/bin/node${nodeExecExtension}\")", - " .config(prettierConfig)", - " }", - "}", - "tasks.named('spotlessMytypescript').configure {", - " it.dependsOn('nodeSetup', 'npmSetup')", - "}"); - setFile("test.ts").toResource("npm/prettier/config/typescript.dirty"); - final BuildResult spotlessApply = gradleRunner().withArguments("--stacktrace", "spotlessApply").build(); - Assertions.assertThat(spotlessApply.getOutput()).contains("BUILD SUCCESSFUL"); - assertFile("test.ts").sameAsResource("npm/prettier/config/typescript.configfile.clean"); + try { + setFile("build.gradle").toLines( + "plugins {", + " id 'com.diffplug.spotless'", + " id 'com.github.node-gradle.node' version '3.5.1'", + "}", + "repositories { mavenCentral() }", + "node {", + " download = true", + " version = '18.13.0'", + " npmVersion = '8.19.2'", + " workDir = file(\"${buildDir}/nodejs\")", + " npmWorkDir = file(\"${buildDir}/npm\")", + "}", + "def prettierConfig = [:]", + "prettierConfig['printWidth'] = 50", + "prettierConfig['parser'] = 'typescript'", + "def npmExec = System.getProperty('os.name').toLowerCase().contains('windows') ? '/npm.cmd' : '/bin/npm'", + "def nodeExec = System.getProperty('os.name').toLowerCase().contains('windows') ? '/node.exe' : '/bin/node'", + "spotless {", + " format 'mytypescript', {", + " target 'test.ts'", + " prettier()", + " .npmExecutable(\"${tasks.named('npmSetup').get().npmDir.get()}${npmExec}\")", + " .nodeExecutable(\"${tasks.named('nodeSetup').get().nodeDir.get()}${nodeExec}\")", + " .config(prettierConfig)", + " }", + "}", + "tasks.named('spotlessMytypescript').configure {", + " it.dependsOn('nodeSetup', 'npmSetup')", + "}"); + setFile("test.ts").toResource("npm/prettier/config/typescript.dirty"); + final BuildResult spotlessApply = gradleRunner().withArguments("--stacktrace", "spotlessApply").build(); + Assertions.assertThat(spotlessApply.getOutput()).contains("BUILD SUCCESSFUL"); + assertFile("test.ts").sameAsResource("npm/prettier/config/typescript.configfile.clean"); + } catch (Exception e) { + printContents(); + throw e; + } } @Test void useNpmFromNodeGradlePlugin() throws Exception { - setFile("build.gradle").toLines( - "plugins {", - " id 'com.diffplug.spotless'", - " id 'com.github.node-gradle.node' version '3.5.1'", - "}", - "repositories { mavenCentral() }", - "node {", - " download = true", - " version = '18.13.0'", - " workDir = file(\"${buildDir}/nodejs\")", - "}", - "def prettierConfig = [:]", - "prettierConfig['printWidth'] = 50", - "prettierConfig['parser'] = 'typescript'", - "def npmExecExtension = System.getProperty('os.name').toLowerCase().contains('windows') ? '.cmd' : ''", - "spotless {", - " format 'mytypescript', {", - " target 'test.ts'", - " prettier()", - " .npmExecutable(\"${tasks.named('npmSetup').get().npmDir.get()}/bin/npm${npmExecExtension}\")", - " .config(prettierConfig)", - " }", - "}"); - setFile("test.ts").toResource("npm/prettier/config/typescript.dirty"); - // make sure node binary is there - gradleRunner().withArguments("nodeSetup", "npmSetup").build(); - // then run spotless using that node installation - final BuildResult spotlessApply = gradleRunner().withArguments("--stacktrace", "spotlessApply").build(); - Assertions.assertThat(spotlessApply.getOutput()).contains("BUILD SUCCESSFUL"); - assertFile("test.ts").sameAsResource("npm/prettier/config/typescript.configfile.clean"); + try { + setFile("build.gradle").toLines( + "plugins {", + " id 'com.diffplug.spotless'", + " id 'com.github.node-gradle.node' version '3.5.1'", + "}", + "repositories { mavenCentral() }", + "node {", + " download = true", + " version = '18.13.0'", + " workDir = file(\"${buildDir}/nodejs\")", + "}", + "def prettierConfig = [:]", + "prettierConfig['printWidth'] = 50", + "prettierConfig['parser'] = 'typescript'", + "def npmExec = System.getProperty('os.name').toLowerCase().contains('windows') ? '/npm.cmd' : '/bin/npm'", + "spotless {", + " format 'mytypescript', {", + " target 'test.ts'", + " prettier()", + " .npmExecutable(\"${tasks.named('npmSetup').get().npmDir.get()}${npmExec}\")", + " .config(prettierConfig)", + " }", + "}"); + setFile("test.ts").toResource("npm/prettier/config/typescript.dirty"); + // make sure node binary is there + gradleRunner().withArguments("nodeSetup", "npmSetup").build(); + // then run spotless using that node installation + final BuildResult spotlessApply = gradleRunner().withArguments("--stacktrace", "spotlessApply").build(); + Assertions.assertThat(spotlessApply.getOutput()).contains("BUILD SUCCESSFUL"); + assertFile("test.ts").sameAsResource("npm/prettier/config/typescript.configfile.clean"); + } catch (Exception e) { + printContents(); + throw e; + } } @Test void useNpmNextToConfiguredNodePluginFromNodeGradlePlugin() throws Exception { - setFile("build.gradle").toLines( - "plugins {", - " id 'com.diffplug.spotless'", - " id 'com.github.node-gradle.node' version '3.5.1'", - "}", - "repositories { mavenCentral() }", - "node {", - " download = true", - " version = '18.13.0'", - " workDir = file(\"${buildDir}/nodejs\")", - "}", - "def prettierConfig = [:]", - "prettierConfig['printWidth'] = 50", - "prettierConfig['parser'] = 'typescript'", - "def nodeExecExtension = System.getProperty('os.name').toLowerCase().contains('windows') ? '.exe' : ''", - "spotless {", - " format 'mytypescript', {", - " target 'test.ts'", - " prettier()", - " .nodeExecutable(\"${tasks.named('nodeSetup').get().nodeDir.get()}/bin/node${nodeExecExtension}\")", - " .config(prettierConfig)", - " }", - "}"); - setFile("test.ts").toResource("npm/prettier/config/typescript.dirty"); - // make sure node binary is there - gradleRunner().withArguments("nodeSetup", "npmSetup").build(); - // then run spotless using that node installation - final BuildResult spotlessApply = gradleRunner().withArguments("--stacktrace", "spotlessApply").build(); - Assertions.assertThat(spotlessApply.getOutput()).contains("BUILD SUCCESSFUL"); - assertFile("test.ts").sameAsResource("npm/prettier/config/typescript.configfile.clean"); + try { + setFile("build.gradle").toLines( + "plugins {", + " id 'com.diffplug.spotless'", + " id 'com.github.node-gradle.node' version '3.5.1'", + "}", + "repositories { mavenCentral() }", + "node {", + " download = true", + " version = '18.13.0'", + " workDir = file(\"${buildDir}/nodejs\")", + "}", + "def prettierConfig = [:]", + "prettierConfig['printWidth'] = 50", + "prettierConfig['parser'] = 'typescript'", + "def nodeExec = System.getProperty('os.name').toLowerCase().contains('windows') ? '/node.exe' : '/bin/node'", + "spotless {", + " format 'mytypescript', {", + " target 'test.ts'", + " prettier()", + " .nodeExecutable(\"${tasks.named('nodeSetup').get().nodeDir.get()}${nodeExec}\")", + " .config(prettierConfig)", + " }", + "}"); + setFile("test.ts").toResource("npm/prettier/config/typescript.dirty"); + // make sure node binary is there + gradleRunner().withArguments("nodeSetup", "npmSetup").build(); + // then run spotless using that node installation + final BuildResult spotlessApply = gradleRunner().withArguments("--stacktrace", "spotlessApply").build(); + Assertions.assertThat(spotlessApply.getOutput()).contains("BUILD SUCCESSFUL"); + assertFile("test.ts").sameAsResource("npm/prettier/config/typescript.configfile.clean"); + } catch (Exception e) { + printContents(); + throw e; + } } } diff --git a/plugin-maven/src/test/java/com/diffplug/spotless/maven/npm/NpmFrontendMavenPlugin.java b/plugin-maven/src/test/java/com/diffplug/spotless/maven/npm/NpmFrontendMavenPlugin.java index 3d20170fab..de030ab81c 100644 --- a/plugin-maven/src/test/java/com/diffplug/spotless/maven/npm/NpmFrontendMavenPlugin.java +++ b/plugin-maven/src/test/java/com/diffplug/spotless/maven/npm/NpmFrontendMavenPlugin.java @@ -61,6 +61,6 @@ public static String installNpmMavenGoal() { } public static String installedNpmPath() { - return String.format("%s/node/npm", INSTALL_DIRECTORY); + return String.format("%s/node/npm%s", INSTALL_DIRECTORY, System.getProperty("os.name").toLowerCase().contains("win") ? ".cmd" : ""); } } From 5315110b4b42dbc4c105ce06d0cf153965877cc3 Mon Sep 17 00:00:00 2001 From: "renovate[bot]" <29139614+renovate[bot]@users.noreply.github.com> Date: Thu, 19 Jan 2023 14:20:10 +0000 Subject: [PATCH 613/757] chore(deps): update plugin org.gradle.test-retry to v1.5.1 --- settings.gradle | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/settings.gradle b/settings.gradle index 57498bf23f..fb9e7dcf0b 100644 --- a/settings.gradle +++ b/settings.gradle @@ -12,7 +12,7 @@ pluginManagement { // https://github.com/diffplug/goomph/blob/main/CHANGES.md id 'com.diffplug.p2.asmaven' version '3.27.0' // DO NOT UPDATE, see https://github.com/diffplug/spotless/pull/874 // https://github.com/gradle/test-retry-gradle-plugin/releases - id 'org.gradle.test-retry' version '1.5.0' + id 'org.gradle.test-retry' version '1.5.1' // https://github.com/radarsh/gradle-test-logger-plugin/blob/develop/CHANGELOG.md id 'com.adarshr.test-logger' version '3.2.0' // https://github.com/davidburstrom/version-compatibility-gradle-plugin/tags From fed3ffc811da37a30921aa9835627e8ca377c2e2 Mon Sep 17 00:00:00 2001 From: Benoit Lacelle Date: Thu, 19 Jan 2023 19:42:01 +0400 Subject: [PATCH 614/757] First commit to discuss the idea --- .../spotless/maven/ImpactedFilesTracker.java | 24 +++++++++++++++++++ .../spotless/maven/SpotlessApplyMojo.java | 8 +++++++ 2 files changed, 32 insertions(+) create mode 100644 plugin-maven/src/main/java/com/diffplug/spotless/maven/ImpactedFilesTracker.java diff --git a/plugin-maven/src/main/java/com/diffplug/spotless/maven/ImpactedFilesTracker.java b/plugin-maven/src/main/java/com/diffplug/spotless/maven/ImpactedFilesTracker.java new file mode 100644 index 0000000000..6019591e09 --- /dev/null +++ b/plugin-maven/src/main/java/com/diffplug/spotless/maven/ImpactedFilesTracker.java @@ -0,0 +1,24 @@ +package com.diffplug.spotless.maven; + +import java.util.concurrent.atomic.AtomicInteger; + +public class ImpactedFilesTracker { + protected final AtomicInteger nbChecked = new AtomicInteger(); + protected final AtomicInteger nbCleaned = new AtomicInteger(); + + public void checked() { + nbChecked.incrementAndGet(); + } + + public int getChecked() { + return nbChecked.get(); + } + + public void cleaned() { + nbCleaned.incrementAndGet(); + } + + public int getCleaned() { + return nbCleaned.get(); + } +} diff --git a/plugin-maven/src/main/java/com/diffplug/spotless/maven/SpotlessApplyMojo.java b/plugin-maven/src/main/java/com/diffplug/spotless/maven/SpotlessApplyMojo.java index 7a15d01b17..b617505826 100644 --- a/plugin-maven/src/main/java/com/diffplug/spotless/maven/SpotlessApplyMojo.java +++ b/plugin-maven/src/main/java/com/diffplug/spotless/maven/SpotlessApplyMojo.java @@ -33,6 +33,8 @@ public class SpotlessApplyMojo extends AbstractSpotlessMojo { @Override protected void process(Iterable files, Formatter formatter, UpToDateChecker upToDateChecker) throws MojoExecutionException { + ImpactedFilesTracker impactedFilesTracker = new ImpactedFilesTracker(); + for (File file : files) { if (upToDateChecker.isUpToDate(file.toPath())) { if (getLog().isDebugEnabled()) { @@ -42,10 +44,13 @@ protected void process(Iterable files, Formatter formatter, UpToDateChecke } try { + impactedFilesTracker.checked(); PaddedCell.DirtyState dirtyState = PaddedCell.calculateDirtyState(formatter, file); if (!dirtyState.isClean() && !dirtyState.didNotConverge()) { + getLog().info(String.format("Writing clean file: %s", file)); dirtyState.writeCanonicalTo(file); buildContext.refresh(file); + impactedFilesTracker.cleaned(); } } catch (IOException e) { throw new MojoExecutionException("Unable to format file " + file, e); @@ -53,5 +58,8 @@ protected void process(Iterable files, Formatter formatter, UpToDateChecke upToDateChecker.setUpToDate(file.toPath()); } + + // We print the number of considered files which is useful when ratchetFrom is setup + getLog().info(String.format("A formatter with %s steps cleaned: %s files (for %s considered)", formatter.getSteps().size(), impactedFilesTracker.getCleaned(), impactedFilesTracker.getChecked())); } } From 00e6282d2cab0c067614e3b2cd5138c47ee54bb1 Mon Sep 17 00:00:00 2001 From: Ned Twigg Date: Thu, 19 Jan 2023 10:19:25 -0800 Subject: [PATCH 615/757] Add the Jackson steps to the root README.md --- README.md | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 637781d894..0743b69427 100644 --- a/README.md +++ b/README.md @@ -63,6 +63,7 @@ lib('java.RemoveUnusedImportsStep') +'{{yes}} | {{yes}} extra('java.EclipseJdtFormatterStep') +'{{yes}} | {{yes}} | {{yes}} | {{no}} |', lib('java.FormatAnnotationsStep') +'{{yes}} | {{yes}} | {{no}} | {{no}} |', lib('json.gson.GsonStep') +'{{yes}} | {{yes}} | {{no}} | {{no}} |', +lib('json.JacksonJsonStep') +'{{yes}} | {{yes}} | {{no}} | {{no}} |', lib('json.JsonSimpleStep') +'{{yes}} | {{yes}} | {{no}} | {{no}} |', lib('kotlin.KtLintStep') +'{{yes}} | {{yes}} | {{yes}} | {{no}} |', lib('kotlin.KtfmtStep') +'{{yes}} | {{yes}} | {{no}} | {{no}} |', @@ -77,7 +78,7 @@ lib('python.BlackStep') +'{{yes}} | {{no}} lib('scala.ScalaFmtStep') +'{{yes}} | {{yes}} | {{yes}} | {{no}} |', lib('sql.DBeaverSQLFormatterStep') +'{{yes}} | {{yes}} | {{yes}} | {{no}} |', extra('wtp.EclipseWtpFormatterStep') +'{{yes}} | {{yes}} | {{no}} | {{no}} |', -lib('yaml.YamlJacksonStep') +'{{no}} | {{yes}} | {{no}} | {{no}} |', +lib('yaml.JacksonYamlStep') +'{{yes}} | {{yes}} | {{no}} | {{no}} |', '| [(Your FormatterStep here)](CONTRIBUTING.md#how-to-add-a-new-formatterstep) | {{no}} | {{no}} | {{no}} | {{no}} |', ].join('\n'); --> @@ -109,6 +110,7 @@ lib('yaml.YamlJacksonStep') +'{{no}} | {{yes}} | [`java.EclipseJdtFormatterStep`](lib-extra/src/main/java/com/diffplug/spotless/extra/java/EclipseJdtFormatterStep.java) | :+1: | :+1: | :+1: | :white_large_square: | | [`java.FormatAnnotationsStep`](lib/src/main/java/com/diffplug/spotless/java/FormatAnnotationsStep.java) | :+1: | :+1: | :white_large_square: | :white_large_square: | | [`json.gson.GsonStep`](lib/src/main/java/com/diffplug/spotless/json/gson/GsonStep.java) | :+1: | :+1: | :white_large_square: | :white_large_square: | +| [`json.JacksonJsonStep`](lib/src/main/java/com/diffplug/spotless/json/JacksonJsonStep.java) | :+1: | :+1: | :white_large_square: | :white_large_square: | | [`json.JsonSimpleStep`](lib/src/main/java/com/diffplug/spotless/json/JsonSimpleStep.java) | :+1: | :+1: | :white_large_square: | :white_large_square: | | [`kotlin.KtLintStep`](lib/src/main/java/com/diffplug/spotless/kotlin/KtLintStep.java) | :+1: | :+1: | :+1: | :white_large_square: | | [`kotlin.KtfmtStep`](lib/src/main/java/com/diffplug/spotless/kotlin/KtfmtStep.java) | :+1: | :+1: | :white_large_square: | :white_large_square: | @@ -123,7 +125,7 @@ lib('yaml.YamlJacksonStep') +'{{no}} | {{yes}} | [`scala.ScalaFmtStep`](lib/src/main/java/com/diffplug/spotless/scala/ScalaFmtStep.java) | :+1: | :+1: | :+1: | :white_large_square: | | [`sql.DBeaverSQLFormatterStep`](lib/src/main/java/com/diffplug/spotless/sql/DBeaverSQLFormatterStep.java) | :+1: | :+1: | :+1: | :white_large_square: | | [`wtp.EclipseWtpFormatterStep`](lib-extra/src/main/java/com/diffplug/spotless/extra/wtp/EclipseWtpFormatterStep.java) | :+1: | :+1: | :white_large_square: | :white_large_square: | -| [`yaml.YamlJacksonStep`](lib/src/main/java/com/diffplug/spotless/yaml/YamlJacksonStep.java) | :white_large_square: | :+1: | :white_large_square: | :white_large_square: | +| [`yaml.JacksonYamlStep`](lib/src/main/java/com/diffplug/spotless/yaml/JacksonYamlStep.java) | :+1: | :+1: | :white_large_square: | :white_large_square: | | [(Your FormatterStep here)](CONTRIBUTING.md#how-to-add-a-new-formatterstep) | :white_large_square: | :white_large_square: | :white_large_square: | :white_large_square: | From 10f04deb64ca671d8cc448665243dd74337e2ff3 Mon Sep 17 00:00:00 2001 From: Abel Keszei Date: Thu, 19 Jan 2023 22:06:16 +0100 Subject: [PATCH 616/757] move gson formatter to custom compile sourceset --- lib/build.gradle | 5 +- .../spotless/glue/gson/GsonFormatterFunc.java | 77 ++++++++++++++++++ .../json/gson/GsonBuilderWrapper.java | 54 ------------- .../spotless/json/gson/GsonConfig.java | 51 ++++++++++++ .../diffplug/spotless/json/gson/GsonStep.java | 78 ++++--------------- .../spotless/json/gson/GsonWrapper.java | 41 ---------- .../spotless/json/gson/GsonWrapperBase.java | 71 ----------------- .../json/gson/JsonElementWrapper.java | 40 ---------- .../spotless/json/gson/JsonObjectWrapper.java | 56 ------------- .../spotless/json/gson/JsonWriterWrapper.java | 48 ------------ .../gradle/spotless/JsonExtension.java | 21 ++--- .../diffplug/spotless/maven/json/Gson.java | 6 +- 12 files changed, 161 insertions(+), 387 deletions(-) create mode 100644 lib/src/gson/java/com/diffplug/spotless/glue/gson/GsonFormatterFunc.java delete mode 100644 lib/src/main/java/com/diffplug/spotless/json/gson/GsonBuilderWrapper.java create mode 100644 lib/src/main/java/com/diffplug/spotless/json/gson/GsonConfig.java delete mode 100644 lib/src/main/java/com/diffplug/spotless/json/gson/GsonWrapper.java delete mode 100644 lib/src/main/java/com/diffplug/spotless/json/gson/GsonWrapperBase.java delete mode 100644 lib/src/main/java/com/diffplug/spotless/json/gson/JsonElementWrapper.java delete mode 100644 lib/src/main/java/com/diffplug/spotless/json/gson/JsonObjectWrapper.java delete mode 100644 lib/src/main/java/com/diffplug/spotless/json/gson/JsonWriterWrapper.java diff --git a/lib/build.gradle b/lib/build.gradle index 30c8fe8b15..bb1a389993 100644 --- a/lib/build.gradle +++ b/lib/build.gradle @@ -15,7 +15,8 @@ def NEEDS_GLUE = [ 'flexmark', 'diktat', 'scalafmt', - 'jackson' + 'jackson', + 'gson' ] for (glue in NEEDS_GLUE) { sourceSets.register(glue) { @@ -108,6 +109,8 @@ dependencies { // used for markdown formatting flexmarkCompileOnly 'com.vladsch.flexmark:flexmark-all:0.62.2' + + gsonCompileOnly 'com.google.code.gson:gson:2.10.1' } // we'll hold the core lib to a high standard diff --git a/lib/src/gson/java/com/diffplug/spotless/glue/gson/GsonFormatterFunc.java b/lib/src/gson/java/com/diffplug/spotless/glue/gson/GsonFormatterFunc.java new file mode 100644 index 0000000000..33db1faaa6 --- /dev/null +++ b/lib/src/gson/java/com/diffplug/spotless/glue/gson/GsonFormatterFunc.java @@ -0,0 +1,77 @@ +package com.diffplug.spotless.glue.gson; + +import java.io.IOException; +import java.io.StringWriter; +import java.util.Collections; + +import com.diffplug.spotless.FormatterFunc; +import com.diffplug.spotless.ThrowingEx; +import com.diffplug.spotless.json.gson.GsonConfig; + +import com.google.gson.Gson; +import com.google.gson.GsonBuilder; +import com.google.gson.JsonElement; +import com.google.gson.JsonObject; +import com.google.gson.stream.JsonWriter; + +public class GsonFormatterFunc implements FormatterFunc { + + private static final String FAILED_TO_PARSE_ERROR_MESSAGE = "Unable to format JSON"; + + private final Gson gson; + private final GsonConfig gsonConfig; + private final String generatedIndent; + + public GsonFormatterFunc(GsonConfig gsonConfig) { + GsonBuilder gsonBuilder = new GsonBuilder().serializeNulls(); + if (!gsonConfig.isEscapeHtml()) { + gsonBuilder = gsonBuilder.disableHtmlEscaping(); + } + this.gson = gsonBuilder.create(); + this.gsonConfig = gsonConfig; + this.generatedIndent = generateIndent(gsonConfig.getIndentSpaces()); + } + + @Override + public String apply(String inputString) { + String result; + if (inputString.isEmpty()) { + result = ""; + } else { + JsonElement jsonElement = gson.fromJson(inputString, JsonElement.class); + if (jsonElement == null) { + throw new AssertionError(FAILED_TO_PARSE_ERROR_MESSAGE); + } + if (gsonConfig.isSortByKeys() && jsonElement.isJsonObject()) { + jsonElement = sortByKeys(jsonElement.getAsJsonObject()); + } + try (StringWriter stringWriter = new StringWriter()) { + JsonWriter jsonWriter = new JsonWriter(stringWriter); + jsonWriter.setIndent(this.generatedIndent); + gson.toJson(jsonElement, jsonWriter); + result = stringWriter + "\n"; + } catch (IOException ioException) { + throw ThrowingEx.asRuntime(ioException); + } + } + return result; + } + + private JsonElement sortByKeys(JsonObject jsonObject) { + JsonObject result = new JsonObject(); + result.keySet().stream().sorted() + .forEach(key -> { + JsonElement element = jsonObject.get(key); + if (element.isJsonObject()) { + element = sortByKeys(element.getAsJsonObject()); + } + result.add(key, element); + }); + return result; + } + + private String generateIndent(int indentSpaces) { + return String.join("", Collections.nCopies(indentSpaces, " ")); + } + +} diff --git a/lib/src/main/java/com/diffplug/spotless/json/gson/GsonBuilderWrapper.java b/lib/src/main/java/com/diffplug/spotless/json/gson/GsonBuilderWrapper.java deleted file mode 100644 index c2e56f39b8..0000000000 --- a/lib/src/main/java/com/diffplug/spotless/json/gson/GsonBuilderWrapper.java +++ /dev/null @@ -1,54 +0,0 @@ -/* - * Copyright 2022 DiffPlug - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package com.diffplug.spotless.json.gson; - -import java.lang.reflect.Constructor; -import java.lang.reflect.Method; - -import com.diffplug.spotless.JarState; - -class GsonBuilderWrapper extends GsonWrapperBase { - - private final Constructor constructor; - private final Method serializeNullsMethod; - private final Method disableHtmlEscapingMethod; - private final Method createMethod; - - GsonBuilderWrapper(JarState jarState) { - Class clazz = loadClass(jarState.getClassLoader(), "com.google.gson.GsonBuilder"); - this.constructor = getConstructor(clazz); - this.serializeNullsMethod = getMethod(clazz, "serializeNulls"); - this.disableHtmlEscapingMethod = getMethod(clazz, "disableHtmlEscaping"); - this.createMethod = getMethod(clazz, "create"); - } - - Object createGsonBuilder() { - return newInstance(constructor); - } - - Object serializeNulls(Object gsonBuilder) { - return invoke(serializeNullsMethod, gsonBuilder); - } - - Object disableHtmlEscaping(Object gsonBuilder) { - return invoke(disableHtmlEscapingMethod, gsonBuilder); - } - - Object create(Object gsonBuilder) { - return invoke(createMethod, gsonBuilder); - } - -} diff --git a/lib/src/main/java/com/diffplug/spotless/json/gson/GsonConfig.java b/lib/src/main/java/com/diffplug/spotless/json/gson/GsonConfig.java new file mode 100644 index 0000000000..c63ad0aaba --- /dev/null +++ b/lib/src/main/java/com/diffplug/spotless/json/gson/GsonConfig.java @@ -0,0 +1,51 @@ +package com.diffplug.spotless.json.gson; + +import java.io.Serializable; + +public class GsonConfig implements Serializable { + private static final long serialVersionUID = 6039715618937332633L; + + private boolean sortByKeys; + private boolean escapeHtml; + private int indentSpaces; + private String version; + + public GsonConfig(boolean sortByKeys, boolean escapeHtml, int indentSpaces, String version) { + this.sortByKeys = sortByKeys; + this.escapeHtml = escapeHtml; + this.indentSpaces = indentSpaces; + this.version = version; + } + + public boolean isSortByKeys() { + return sortByKeys; + } + + public void setSortByKeys(boolean sortByKeys) { + this.sortByKeys = sortByKeys; + } + + public boolean isEscapeHtml() { + return escapeHtml; + } + + public void setEscapeHtml(boolean escapeHtml) { + this.escapeHtml = escapeHtml; + } + + public int getIndentSpaces() { + return indentSpaces; + } + + public void setIndentSpaces(int indentSpaces) { + this.indentSpaces = indentSpaces; + } + + public String getVersion() { + return version; + } + + public void setVersion(String version) { + this.version = version; + } +} diff --git a/lib/src/main/java/com/diffplug/spotless/json/gson/GsonStep.java b/lib/src/main/java/com/diffplug/spotless/json/gson/GsonStep.java index 06519ae39d..624c4f2533 100644 --- a/lib/src/main/java/com/diffplug/spotless/json/gson/GsonStep.java +++ b/lib/src/main/java/com/diffplug/spotless/json/gson/GsonStep.java @@ -17,8 +17,8 @@ import java.io.IOException; import java.io.Serializable; -import java.io.StringWriter; -import java.util.Collections; +import java.lang.reflect.Constructor; +import java.lang.reflect.InvocationTargetException; import java.util.Objects; import com.diffplug.spotless.FormatterFunc; @@ -29,77 +29,27 @@ public class GsonStep { private static final String MAVEN_COORDINATES = "com.google.code.gson:gson"; - public static FormatterStep create(int indentSpaces, boolean sortByKeys, boolean escapeHtml, String version, Provisioner provisioner) { + public static FormatterStep create(GsonConfig gsonConfig, Provisioner provisioner) { Objects.requireNonNull(provisioner, "provisioner cannot be null"); - return FormatterStep.createLazy("gson", () -> new State(indentSpaces, sortByKeys, escapeHtml, version, provisioner), State::toFormatter); + return FormatterStep.createLazy("gson", () -> new State(gsonConfig, provisioner), State::toFormatter); } private static final class State implements Serializable { - private static final long serialVersionUID = -1493479043249379485L; + private static final long serialVersionUID = -3240568265160440420L; - private final int indentSpaces; - private final boolean sortByKeys; - private final boolean escapeHtml; private final JarState jarState; + private final GsonConfig gsonConfig; - private State(int indentSpaces, boolean sortByKeys, boolean escapeHtml, String version, Provisioner provisioner) throws IOException { - this.indentSpaces = indentSpaces; - this.sortByKeys = sortByKeys; - this.escapeHtml = escapeHtml; - this.jarState = JarState.from(MAVEN_COORDINATES + ":" + version, provisioner); + private State(GsonConfig gsonConfig, Provisioner provisioner) throws IOException { + this.gsonConfig = gsonConfig; + this.jarState = JarState.from(MAVEN_COORDINATES + ":" + gsonConfig.getVersion(), provisioner); } - FormatterFunc toFormatter() { - JsonWriterWrapper jsonWriterWrapper = new JsonWriterWrapper(jarState); - JsonElementWrapper jsonElementWrapper = new JsonElementWrapper(jarState); - JsonObjectWrapper jsonObjectWrapper = new JsonObjectWrapper(jarState, jsonElementWrapper); - GsonBuilderWrapper gsonBuilderWrapper = new GsonBuilderWrapper(jarState); - GsonWrapper gsonWrapper = new GsonWrapper(jarState, jsonElementWrapper, jsonWriterWrapper); - - Object gsonBuilder = gsonBuilderWrapper.serializeNulls(gsonBuilderWrapper.createGsonBuilder()); - if (!escapeHtml) { - gsonBuilder = gsonBuilderWrapper.disableHtmlEscaping(gsonBuilder); - } - Object gson = gsonBuilderWrapper.create(gsonBuilder); - - return inputString -> { - String result; - if (inputString.isEmpty()) { - result = ""; - } else { - Object jsonElement = gsonWrapper.fromJson(gson, inputString, jsonElementWrapper.getWrappedClass()); - if (jsonElement == null) { - throw new AssertionError(GsonWrapperBase.FAILED_TO_PARSE_ERROR_MESSAGE); - } - if (sortByKeys && jsonElementWrapper.isJsonObject(jsonElement)) { - jsonElement = sortByKeys(jsonObjectWrapper, jsonElementWrapper, jsonElement); - } - try (StringWriter stringWriter = new StringWriter()) { - Object jsonWriter = jsonWriterWrapper.createJsonWriter(stringWriter); - jsonWriterWrapper.setIndent(jsonWriter, generateIndent(indentSpaces)); - gsonWrapper.toJson(gson, jsonElement, jsonWriter); - result = stringWriter + "\n"; - } - } - return result; - }; - } - - private Object sortByKeys(JsonObjectWrapper jsonObjectWrapper, JsonElementWrapper jsonElementWrapper, Object jsonObject) { - Object result = jsonObjectWrapper.createJsonObject(); - jsonObjectWrapper.keySet(jsonObject).stream().sorted() - .forEach(key -> { - Object element = jsonObjectWrapper.get(jsonObject, key); - if (jsonElementWrapper.isJsonObject(element)) { - element = sortByKeys(jsonObjectWrapper, jsonElementWrapper, element); - } - jsonObjectWrapper.add(result, key, element); - }); - return result; - } - - private String generateIndent(int indentSpaces) { - return String.join("", Collections.nCopies(indentSpaces, " ")); + FormatterFunc toFormatter() throws ClassNotFoundException, NoSuchMethodException, InvocationTargetException, + InstantiationException, IllegalAccessException { + Class formatterFunc = jarState.getClassLoader().loadClass("com.diffplug.spotless.glue.gson.GsonFormatterFunc"); + Constructor constructor = formatterFunc.getConstructor(GsonConfig.class); + return (FormatterFunc) constructor.newInstance(gsonConfig); } } diff --git a/lib/src/main/java/com/diffplug/spotless/json/gson/GsonWrapper.java b/lib/src/main/java/com/diffplug/spotless/json/gson/GsonWrapper.java deleted file mode 100644 index eaca499eed..0000000000 --- a/lib/src/main/java/com/diffplug/spotless/json/gson/GsonWrapper.java +++ /dev/null @@ -1,41 +0,0 @@ -/* - * Copyright 2022 DiffPlug - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package com.diffplug.spotless.json.gson; - -import java.lang.reflect.Method; - -import com.diffplug.spotless.JarState; - -class GsonWrapper extends GsonWrapperBase { - - private final Method fromJsonMethod; - private final Method toJsonMethod; - - GsonWrapper(JarState jarState, JsonElementWrapper jsonElementWrapper, JsonWriterWrapper jsonWriterWrapper) { - Class clazz = loadClass(jarState.getClassLoader(), "com.google.gson.Gson"); - this.fromJsonMethod = getMethod(clazz, "fromJson", String.class, Class.class); - this.toJsonMethod = getMethod(clazz, "toJson", jsonElementWrapper.getWrappedClass(), jsonWriterWrapper.getWrappedClass()); - } - - Object fromJson(Object gson, String json, Class type) { - return invoke(fromJsonMethod, gson, json, type); - } - - void toJson(Object gson, Object jsonElement, Object jsonWriter) { - invoke(toJsonMethod, gson, jsonElement, jsonWriter); - } - -} diff --git a/lib/src/main/java/com/diffplug/spotless/json/gson/GsonWrapperBase.java b/lib/src/main/java/com/diffplug/spotless/json/gson/GsonWrapperBase.java deleted file mode 100644 index 24d12a5722..0000000000 --- a/lib/src/main/java/com/diffplug/spotless/json/gson/GsonWrapperBase.java +++ /dev/null @@ -1,71 +0,0 @@ -/* - * Copyright 2022 DiffPlug - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package com.diffplug.spotless.json.gson; - -import java.lang.reflect.Constructor; -import java.lang.reflect.InvocationTargetException; -import java.lang.reflect.Method; - -abstract class GsonWrapperBase { - - static final String INCOMPATIBLE_ERROR_MESSAGE = "There was a problem interacting with Gson; maybe you set an incompatible version?"; - static final String FAILED_TO_PARSE_ERROR_MESSAGE = "Unable to format JSON"; - - protected final Class loadClass(ClassLoader classLoader, String className) { - try { - return classLoader.loadClass(className); - } catch (ClassNotFoundException cause) { - throw new IllegalStateException(INCOMPATIBLE_ERROR_MESSAGE, cause); - } - } - - protected final Constructor getConstructor(Class clazz, Class... argumentTypes) { - try { - return clazz.getConstructor(argumentTypes); - } catch (NoSuchMethodException cause) { - throw new IllegalStateException(INCOMPATIBLE_ERROR_MESSAGE, cause); - } - } - - protected final Method getMethod(Class clazz, String name, Class... argumentTypes) { - try { - return clazz.getMethod(name, argumentTypes); - } catch (NoSuchMethodException cause) { - throw new IllegalStateException(INCOMPATIBLE_ERROR_MESSAGE, cause); - } - } - - protected final T newInstance(Constructor constructor, Object... args) { - try { - return constructor.newInstance(args); - } catch (InstantiationException | IllegalAccessException cause) { - throw new IllegalStateException(INCOMPATIBLE_ERROR_MESSAGE, cause); - } catch (InvocationTargetException cause) { - throw new AssertionError(FAILED_TO_PARSE_ERROR_MESSAGE, cause.getCause()); - } - } - - protected Object invoke(Method method, Object targetObject, Object... args) { - try { - return method.invoke(targetObject, args); - } catch (IllegalAccessException cause) { - throw new IllegalStateException(INCOMPATIBLE_ERROR_MESSAGE, cause); - } catch (InvocationTargetException cause) { - throw new AssertionError(FAILED_TO_PARSE_ERROR_MESSAGE, cause.getCause()); - } - } - -} diff --git a/lib/src/main/java/com/diffplug/spotless/json/gson/JsonElementWrapper.java b/lib/src/main/java/com/diffplug/spotless/json/gson/JsonElementWrapper.java deleted file mode 100644 index ffdfa649ce..0000000000 --- a/lib/src/main/java/com/diffplug/spotless/json/gson/JsonElementWrapper.java +++ /dev/null @@ -1,40 +0,0 @@ -/* - * Copyright 2022 DiffPlug - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package com.diffplug.spotless.json.gson; - -import java.lang.reflect.Method; - -import com.diffplug.spotless.JarState; - -class JsonElementWrapper extends GsonWrapperBase { - - private final Class clazz; - private final Method isJsonObjectMethod; - - JsonElementWrapper(JarState jarState) { - this.clazz = loadClass(jarState.getClassLoader(), "com.google.gson.JsonElement"); - this.isJsonObjectMethod = getMethod(clazz, "isJsonObject"); - } - - boolean isJsonObject(Object jsonElement) { - return (boolean) invoke(isJsonObjectMethod, jsonElement); - } - - Class getWrappedClass() { - return clazz; - } - -} diff --git a/lib/src/main/java/com/diffplug/spotless/json/gson/JsonObjectWrapper.java b/lib/src/main/java/com/diffplug/spotless/json/gson/JsonObjectWrapper.java deleted file mode 100644 index 35ec0d876b..0000000000 --- a/lib/src/main/java/com/diffplug/spotless/json/gson/JsonObjectWrapper.java +++ /dev/null @@ -1,56 +0,0 @@ -/* - * Copyright 2022 DiffPlug - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package com.diffplug.spotless.json.gson; - -import java.lang.reflect.Constructor; -import java.lang.reflect.Method; -import java.util.Set; - -import com.diffplug.spotless.JarState; - -class JsonObjectWrapper extends GsonWrapperBase { - - private final Constructor constructor; - private final Method keySetMethod; - private final Method getMethod; - private final Method addMethod; - - JsonObjectWrapper(JarState jarState, JsonElementWrapper jsonElementWrapper) { - Class clazz = loadClass(jarState.getClassLoader(), "com.google.gson.JsonObject"); - this.constructor = getConstructor(clazz); - this.keySetMethod = getMethod(clazz, "keySet"); - this.getMethod = getMethod(clazz, "get", String.class); - this.addMethod = getMethod(clazz, "add", String.class, jsonElementWrapper.getWrappedClass()); - } - - Object createJsonObject() { - return newInstance(constructor); - } - - @SuppressWarnings("unchecked") - Set keySet(Object jsonObject) { - return (Set) invoke(keySetMethod, jsonObject); - } - - Object get(Object jsonObject, String key) { - return invoke(getMethod, jsonObject, key); - } - - void add(Object jsonObject, String key, Object element) { - invoke(addMethod, jsonObject, key, element); - } - -} diff --git a/lib/src/main/java/com/diffplug/spotless/json/gson/JsonWriterWrapper.java b/lib/src/main/java/com/diffplug/spotless/json/gson/JsonWriterWrapper.java deleted file mode 100644 index c9d682e2c2..0000000000 --- a/lib/src/main/java/com/diffplug/spotless/json/gson/JsonWriterWrapper.java +++ /dev/null @@ -1,48 +0,0 @@ -/* - * Copyright 2022 DiffPlug - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package com.diffplug.spotless.json.gson; - -import java.io.Writer; -import java.lang.reflect.Constructor; -import java.lang.reflect.Method; - -import com.diffplug.spotless.JarState; - -class JsonWriterWrapper extends GsonWrapperBase { - - private final Class clazz; - private final Constructor constructor; - private final Method setIndentMethod; - - JsonWriterWrapper(JarState jarState) { - this.clazz = loadClass(jarState.getClassLoader(), "com.google.gson.stream.JsonWriter"); - this.constructor = getConstructor(clazz, Writer.class); - this.setIndentMethod = getMethod(clazz, "setIndent", String.class); - } - - Object createJsonWriter(Writer writer) { - return newInstance(constructor, writer); - } - - void setIndent(Object jsonWriter, String indent) { - invoke(setIndentMethod, jsonWriter, indent); - } - - Class getWrappedClass() { - return clazz; - } - -} diff --git a/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/JsonExtension.java b/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/JsonExtension.java index 1e9de2e831..c684dab291 100644 --- a/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/JsonExtension.java +++ b/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/JsonExtension.java @@ -23,11 +23,12 @@ import com.diffplug.spotless.json.JacksonJsonConfig; import com.diffplug.spotless.json.JacksonJsonStep; import com.diffplug.spotless.json.JsonSimpleStep; +import com.diffplug.spotless.json.gson.GsonConfig; import com.diffplug.spotless.json.gson.GsonStep; public class JsonExtension extends FormatExtension { private static final int DEFAULT_INDENTATION = 4; - private static final String DEFAULT_GSON_VERSION = "2.8.9"; + private static final String DEFAULT_GSON_VERSION = "2.10.1"; static final String NAME = "json"; @Inject @@ -47,8 +48,8 @@ public SimpleConfig simple() { return new SimpleConfig(DEFAULT_INDENTATION); } - public GsonConfig gson() { - return new GsonConfig(); + public GsonGradleConfig gson() { + return new GsonGradleConfig(); } public JacksonJsonGradleConfig jackson() { @@ -73,13 +74,13 @@ private FormatterStep createStep() { } } - public class GsonConfig { + public class GsonGradleConfig { private int indentSpaces; private boolean sortByKeys; private boolean escapeHtml; private String version; - public GsonConfig() { + public GsonGradleConfig() { this.indentSpaces = DEFAULT_INDENTATION; this.sortByKeys = false; this.escapeHtml = false; @@ -87,32 +88,32 @@ public GsonConfig() { addStep(createStep()); } - public GsonConfig indentWithSpaces(int indentSpaces) { + public GsonGradleConfig indentWithSpaces(int indentSpaces) { this.indentSpaces = indentSpaces; replaceStep(createStep()); return this; } - public GsonConfig sortByKeys() { + public GsonGradleConfig sortByKeys() { this.sortByKeys = true; replaceStep(createStep()); return this; } - public GsonConfig escapeHtml() { + public GsonGradleConfig escapeHtml() { this.escapeHtml = true; replaceStep(createStep()); return this; } - public GsonConfig version(String version) { + public GsonGradleConfig version(String version) { this.version = version; replaceStep(createStep()); return this; } private FormatterStep createStep() { - return GsonStep.create(indentSpaces, sortByKeys, escapeHtml, version, provisioner()); + return GsonStep.create(new GsonConfig(sortByKeys, escapeHtml, indentSpaces, version), provisioner()); } } diff --git a/plugin-maven/src/main/java/com/diffplug/spotless/maven/json/Gson.java b/plugin-maven/src/main/java/com/diffplug/spotless/maven/json/Gson.java index 7962ecb1f7..7dda88dcd9 100644 --- a/plugin-maven/src/main/java/com/diffplug/spotless/maven/json/Gson.java +++ b/plugin-maven/src/main/java/com/diffplug/spotless/maven/json/Gson.java @@ -15,6 +15,8 @@ */ package com.diffplug.spotless.maven.json; +import com.diffplug.spotless.json.gson.GsonConfig; + import org.apache.maven.plugins.annotations.Parameter; import com.diffplug.spotless.FormatterStep; @@ -23,7 +25,7 @@ import com.diffplug.spotless.maven.FormatterStepFactory; public class Gson implements FormatterStepFactory { - private static final String DEFAULT_GSON_VERSION = "2.8.9"; + private static final String DEFAULT_GSON_VERSION = "2.10.1"; @Parameter int indentSpaces = Json.DEFAULT_INDENTATION; @@ -40,6 +42,6 @@ public class Gson implements FormatterStepFactory { @Override public FormatterStep newFormatterStep(FormatterStepConfig stepConfig) { int indentSpaces = this.indentSpaces; - return GsonStep.create(indentSpaces, sortByKeys, escapeHtml, version, stepConfig.getProvisioner()); + return GsonStep.create(new GsonConfig(sortByKeys, escapeHtml, indentSpaces, version), stepConfig.getProvisioner()); } } From 0a86bad22192c5453cc08f8eebe3f28b44abd3d5 Mon Sep 17 00:00:00 2001 From: Abel Keszei Date: Thu, 19 Jan 2023 22:07:36 +0100 Subject: [PATCH 617/757] apply format --- .../spotless/glue/gson/GsonFormatterFunc.java | 37 +++++++++++++------ .../spotless/json/gson/GsonConfig.java | 15 ++++++++ .../diffplug/spotless/json/gson/GsonStep.java | 4 +- .../diffplug/spotless/maven/json/Gson.java | 3 +- 4 files changed, 44 insertions(+), 15 deletions(-) diff --git a/lib/src/gson/java/com/diffplug/spotless/glue/gson/GsonFormatterFunc.java b/lib/src/gson/java/com/diffplug/spotless/glue/gson/GsonFormatterFunc.java index 33db1faaa6..c1426a06d1 100644 --- a/lib/src/gson/java/com/diffplug/spotless/glue/gson/GsonFormatterFunc.java +++ b/lib/src/gson/java/com/diffplug/spotless/glue/gson/GsonFormatterFunc.java @@ -1,19 +1,34 @@ +/* + * Copyright 2023 DiffPlug + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ package com.diffplug.spotless.glue.gson; import java.io.IOException; import java.io.StringWriter; import java.util.Collections; -import com.diffplug.spotless.FormatterFunc; -import com.diffplug.spotless.ThrowingEx; -import com.diffplug.spotless.json.gson.GsonConfig; - import com.google.gson.Gson; import com.google.gson.GsonBuilder; import com.google.gson.JsonElement; import com.google.gson.JsonObject; import com.google.gson.stream.JsonWriter; +import com.diffplug.spotless.FormatterFunc; +import com.diffplug.spotless.ThrowingEx; +import com.diffplug.spotless.json.gson.GsonConfig; + public class GsonFormatterFunc implements FormatterFunc { private static final String FAILED_TO_PARSE_ERROR_MESSAGE = "Unable to format JSON"; @@ -60,13 +75,13 @@ public String apply(String inputString) { private JsonElement sortByKeys(JsonObject jsonObject) { JsonObject result = new JsonObject(); result.keySet().stream().sorted() - .forEach(key -> { - JsonElement element = jsonObject.get(key); - if (element.isJsonObject()) { - element = sortByKeys(element.getAsJsonObject()); - } - result.add(key, element); - }); + .forEach(key -> { + JsonElement element = jsonObject.get(key); + if (element.isJsonObject()) { + element = sortByKeys(element.getAsJsonObject()); + } + result.add(key, element); + }); return result; } diff --git a/lib/src/main/java/com/diffplug/spotless/json/gson/GsonConfig.java b/lib/src/main/java/com/diffplug/spotless/json/gson/GsonConfig.java index c63ad0aaba..a11c1ee296 100644 --- a/lib/src/main/java/com/diffplug/spotless/json/gson/GsonConfig.java +++ b/lib/src/main/java/com/diffplug/spotless/json/gson/GsonConfig.java @@ -1,3 +1,18 @@ +/* + * Copyright 2023 DiffPlug + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ package com.diffplug.spotless.json.gson; import java.io.Serializable; diff --git a/lib/src/main/java/com/diffplug/spotless/json/gson/GsonStep.java b/lib/src/main/java/com/diffplug/spotless/json/gson/GsonStep.java index 624c4f2533..1fb0f11d62 100644 --- a/lib/src/main/java/com/diffplug/spotless/json/gson/GsonStep.java +++ b/lib/src/main/java/com/diffplug/spotless/json/gson/GsonStep.java @@ -1,5 +1,5 @@ /* - * Copyright 2022 DiffPlug + * Copyright 2022-2023 DiffPlug * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -46,7 +46,7 @@ private State(GsonConfig gsonConfig, Provisioner provisioner) throws IOException } FormatterFunc toFormatter() throws ClassNotFoundException, NoSuchMethodException, InvocationTargetException, - InstantiationException, IllegalAccessException { + InstantiationException, IllegalAccessException { Class formatterFunc = jarState.getClassLoader().loadClass("com.diffplug.spotless.glue.gson.GsonFormatterFunc"); Constructor constructor = formatterFunc.getConstructor(GsonConfig.class); return (FormatterFunc) constructor.newInstance(gsonConfig); diff --git a/plugin-maven/src/main/java/com/diffplug/spotless/maven/json/Gson.java b/plugin-maven/src/main/java/com/diffplug/spotless/maven/json/Gson.java index 7dda88dcd9..fb5a38e890 100644 --- a/plugin-maven/src/main/java/com/diffplug/spotless/maven/json/Gson.java +++ b/plugin-maven/src/main/java/com/diffplug/spotless/maven/json/Gson.java @@ -15,11 +15,10 @@ */ package com.diffplug.spotless.maven.json; -import com.diffplug.spotless.json.gson.GsonConfig; - import org.apache.maven.plugins.annotations.Parameter; import com.diffplug.spotless.FormatterStep; +import com.diffplug.spotless.json.gson.GsonConfig; import com.diffplug.spotless.json.gson.GsonStep; import com.diffplug.spotless.maven.FormatterStepConfig; import com.diffplug.spotless.maven.FormatterStepFactory; From 290a522e154db4ce10116273b35139e5f64ea8bd Mon Sep 17 00:00:00 2001 From: "renovate[bot]" <29139614+renovate[bot]@users.noreply.github.com> Date: Fri, 20 Jan 2023 21:43:58 +0000 Subject: [PATCH 618/757] Update plugin de.benediktritter.maven-plugin-development to v0.4.1 --- plugin-maven/build.gradle | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugin-maven/build.gradle b/plugin-maven/build.gradle index ad51318d93..664101a0fd 100644 --- a/plugin-maven/build.gradle +++ b/plugin-maven/build.gradle @@ -1,6 +1,6 @@ plugins { // https://www.benediktritter.de/maven-plugin-development/#release-history - id 'de.benediktritter.maven-plugin-development' version '0.4.0' + id 'de.benediktritter.maven-plugin-development' version '0.4.1' } repositories { mavenCentral() } From eea5d5c1d07f23c7381222bd5010b4933008dee9 Mon Sep 17 00:00:00 2001 From: Abel Keszei Date: Sun, 22 Jan 2023 14:36:44 +0100 Subject: [PATCH 619/757] fix tests --- .../spotless/glue/gson/GsonFormatterFunc.java | 2 +- .../com/diffplug/spotless/json/gson/GsonStep.java | 15 ++++++++++----- .../diffplug/spotless/json/gson/GsonStepTest.java | 14 +++++++------- 3 files changed, 18 insertions(+), 13 deletions(-) diff --git a/lib/src/gson/java/com/diffplug/spotless/glue/gson/GsonFormatterFunc.java b/lib/src/gson/java/com/diffplug/spotless/glue/gson/GsonFormatterFunc.java index c1426a06d1..b19476a1a8 100644 --- a/lib/src/gson/java/com/diffplug/spotless/glue/gson/GsonFormatterFunc.java +++ b/lib/src/gson/java/com/diffplug/spotless/glue/gson/GsonFormatterFunc.java @@ -74,7 +74,7 @@ public String apply(String inputString) { private JsonElement sortByKeys(JsonObject jsonObject) { JsonObject result = new JsonObject(); - result.keySet().stream().sorted() + jsonObject.keySet().stream().sorted() .forEach(key -> { JsonElement element = jsonObject.get(key); if (element.isJsonObject()) { diff --git a/lib/src/main/java/com/diffplug/spotless/json/gson/GsonStep.java b/lib/src/main/java/com/diffplug/spotless/json/gson/GsonStep.java index 1fb0f11d62..58993017fa 100644 --- a/lib/src/main/java/com/diffplug/spotless/json/gson/GsonStep.java +++ b/lib/src/main/java/com/diffplug/spotless/json/gson/GsonStep.java @@ -28,6 +28,7 @@ public class GsonStep { private static final String MAVEN_COORDINATES = "com.google.code.gson:gson"; + private static final String INCOMPATIBLE_ERROR_MESSAGE = "There was a problem interacting with Gson; maybe you set an incompatible version?"; public static FormatterStep create(GsonConfig gsonConfig, Provisioner provisioner) { Objects.requireNonNull(provisioner, "provisioner cannot be null"); @@ -45,11 +46,15 @@ private State(GsonConfig gsonConfig, Provisioner provisioner) throws IOException this.jarState = JarState.from(MAVEN_COORDINATES + ":" + gsonConfig.getVersion(), provisioner); } - FormatterFunc toFormatter() throws ClassNotFoundException, NoSuchMethodException, InvocationTargetException, - InstantiationException, IllegalAccessException { - Class formatterFunc = jarState.getClassLoader().loadClass("com.diffplug.spotless.glue.gson.GsonFormatterFunc"); - Constructor constructor = formatterFunc.getConstructor(GsonConfig.class); - return (FormatterFunc) constructor.newInstance(gsonConfig); + FormatterFunc toFormatter() { + try { + Class formatterFunc = jarState.getClassLoader().loadClass("com.diffplug.spotless.glue.gson.GsonFormatterFunc"); + Constructor constructor = formatterFunc.getConstructor(GsonConfig.class); + return (FormatterFunc) constructor.newInstance(gsonConfig); + } catch (ClassNotFoundException | NoSuchMethodException | InvocationTargetException + | InstantiationException | IllegalAccessException | NoClassDefFoundError cause) { + throw new IllegalStateException(INCOMPATIBLE_ERROR_MESSAGE, cause); + } } } diff --git a/testlib/src/test/java/com/diffplug/spotless/json/gson/GsonStepTest.java b/testlib/src/test/java/com/diffplug/spotless/json/gson/GsonStepTest.java index 8f1d758836..3f4d2a84e0 100644 --- a/testlib/src/test/java/com/diffplug/spotless/json/gson/GsonStepTest.java +++ b/testlib/src/test/java/com/diffplug/spotless/json/gson/GsonStepTest.java @@ -28,7 +28,7 @@ public class GsonStepTest extends JsonFormatterStepCommonTests { - private static final String DEFAULT_VERSION = "2.8.9"; + private static final String DEFAULT_VERSION = "2.10.1"; @Test void handlesComplexNestedObject() { @@ -52,34 +52,34 @@ void handlesNotJson() { @Test void handlesSortingWhenSortByKeyEnabled() { - FormatterStep step = GsonStep.create(INDENT, true, false, DEFAULT_VERSION, TestProvisioner.mavenCentral()); + FormatterStep step = GsonStep.create(new GsonConfig(true, false, INDENT, DEFAULT_VERSION), TestProvisioner.mavenCentral()); StepHarness.forStep(step).testResource("json/sortByKeysBefore.json", "json/sortByKeysAfter.json"); } @Test void doesNoSortingWhenSortByKeyDisabled() { - FormatterStep step = GsonStep.create(INDENT, false, false, DEFAULT_VERSION, TestProvisioner.mavenCentral()); + FormatterStep step = GsonStep.create(new GsonConfig(false, false, INDENT, DEFAULT_VERSION), TestProvisioner.mavenCentral()); StepHarness.forStep(step) .testResource("json/sortByKeysBefore.json", "json/sortByKeysAfterDisabled.json"); } @Test void handlesHtmlEscapeWhenEnabled() { - FormatterStep step = GsonStep.create(INDENT, false, true, DEFAULT_VERSION, TestProvisioner.mavenCentral()); + FormatterStep step = GsonStep.create(new GsonConfig(false, true, INDENT, DEFAULT_VERSION), TestProvisioner.mavenCentral()); StepHarness.forStep(step) .testResource("json/escapeHtmlGsonBefore.json", "json/escapeHtmlGsonAfter.json"); } @Test void writesRawHtmlWhenHtmlEscapeDisabled() { - FormatterStep step = GsonStep.create(INDENT, false, false, DEFAULT_VERSION, TestProvisioner.mavenCentral()); + FormatterStep step = GsonStep.create(new GsonConfig(false, false, INDENT, DEFAULT_VERSION), TestProvisioner.mavenCentral()); StepHarness.forStep(step) .testResource("json/escapeHtmlGsonBefore.json", "json/escapeHtmlGsonAfterDisabled.json"); } @Test void handlesVersionIncompatibility() { - FormatterStep step = GsonStep.create(INDENT, false, false, "1.7", TestProvisioner.mavenCentral()); + FormatterStep step = GsonStep.create(new GsonConfig(false, false, INDENT, "1.7"), TestProvisioner.mavenCentral()); Assertions.assertThatThrownBy(() -> step.format("", new File(""))) .isInstanceOf(IllegalStateException.class) .hasMessage("There was a problem interacting with Gson; maybe you set an incompatible version?"); @@ -87,6 +87,6 @@ void handlesVersionIncompatibility() { @Override protected FormatterStep createFormatterStep(int indent, Provisioner provisioner) { - return GsonStep.create(indent, false, false, DEFAULT_VERSION, provisioner); + return GsonStep.create(new GsonConfig(false, false, indent, DEFAULT_VERSION), provisioner); } } From f3481bee7c5f03ad450c2f7a875a204c594ef66f Mon Sep 17 00:00:00 2001 From: Abel Keszei Date: Sun, 22 Jan 2023 14:37:14 +0100 Subject: [PATCH 620/757] apply format --- lib/src/main/java/com/diffplug/spotless/json/gson/GsonStep.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/src/main/java/com/diffplug/spotless/json/gson/GsonStep.java b/lib/src/main/java/com/diffplug/spotless/json/gson/GsonStep.java index 58993017fa..03baec5104 100644 --- a/lib/src/main/java/com/diffplug/spotless/json/gson/GsonStep.java +++ b/lib/src/main/java/com/diffplug/spotless/json/gson/GsonStep.java @@ -52,7 +52,7 @@ FormatterFunc toFormatter() { Constructor constructor = formatterFunc.getConstructor(GsonConfig.class); return (FormatterFunc) constructor.newInstance(gsonConfig); } catch (ClassNotFoundException | NoSuchMethodException | InvocationTargetException - | InstantiationException | IllegalAccessException | NoClassDefFoundError cause) { + | InstantiationException | IllegalAccessException | NoClassDefFoundError cause) { throw new IllegalStateException(INCOMPATIBLE_ERROR_MESSAGE, cause); } } From 85d727e19a149fec2144e40fbe3c656ca83df0e2 Mon Sep 17 00:00:00 2001 From: Abel Keszei Date: Sun, 22 Jan 2023 14:55:19 +0100 Subject: [PATCH 621/757] update CHANGES.md --- CHANGES.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGES.md b/CHANGES.md index 07b81a8fc5..32c7a7f5a5 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -17,6 +17,7 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format ( * The default list of type annotations used by `formatAnnotations` has had 8 more annotations from the Checker Framework added [#1494](https://github.com/diffplug/spotless/pull/1494) ### Changes * Rename `YamlJacksonStep` into `JacksonYamlStep` while normalizing Jackson usage ([#1492](https://github.com/diffplug/spotless/pull/1492)) +* Convert `gson` integration to use a compile-only source set ([#1510](https://github.com/diffplug/spotless/pull/1510)). ## [2.32.0] - 2023-01-13 ### Added From bba246d883a3ad9847d75c4379b7e8b9be1f1907 Mon Sep 17 00:00:00 2001 From: Simon Gamma Date: Fri, 20 Jan 2023 22:00:22 +0100 Subject: [PATCH 622/757] 1416: use process runner to catch output --- .../com/diffplug/spotless/ProcessRunner.java | 146 ++++++++++++++++-- .../com/diffplug/spotless/npm/NpmProcess.java | 34 ++-- 2 files changed, 153 insertions(+), 27 deletions(-) diff --git a/lib/src/main/java/com/diffplug/spotless/ProcessRunner.java b/lib/src/main/java/com/diffplug/spotless/ProcessRunner.java index 41c664cafe..4c076e537c 100644 --- a/lib/src/main/java/com/diffplug/spotless/ProcessRunner.java +++ b/lib/src/main/java/com/diffplug/spotless/ProcessRunner.java @@ -15,6 +15,8 @@ */ package com.diffplug.spotless; +import static java.util.Objects.requireNonNull; + import java.io.ByteArrayOutputStream; import java.io.File; import java.io.IOException; @@ -29,9 +31,12 @@ import java.util.concurrent.ExecutorService; import java.util.concurrent.Executors; import java.util.concurrent.Future; +import java.util.concurrent.TimeUnit; import java.util.function.BiConsumer; -import edu.umd.cs.findbugs.annotations.Nullable; +import javax.annotation.Nonnull; +import javax.annotation.Nullable; + import edu.umd.cs.findbugs.annotations.SuppressFBWarnings; /** @@ -95,6 +100,36 @@ public Result exec(@Nullable byte[] stdin, List args) throws IOException /** Creates a process with the given arguments, the given byte array is written to stdin immediately. */ public Result exec(@Nullable File cwd, @Nullable Map environment, @Nullable byte[] stdin, List args) throws IOException, InterruptedException { + LongRunningProcess process = start(cwd, environment, stdin, args); + try { + // wait for the process to finish + process.waitFor(); + // collect the output + return process.result(); + } catch (ExecutionException e) { + throw ThrowingEx.asRuntime(e); + } + } + + /** + * Creates a process with the given arguments, the given byte array is written to stdin immediately. + *
+ * Delegates to {@link #start(File, Map, byte[], boolean, List)} with {@code false} for {@code redirectErrorStream}. + */ + public LongRunningProcess start(@Nullable File cwd, @Nullable Map environment, @Nullable byte[] stdin, List args) throws IOException { + return start(cwd, environment, stdin, false, args); + } + + /** + * Creates a process with the given arguments, the given byte array is written to stdin immediately. + *
+ * The process is not waited for, so the caller is responsible for calling {@link LongRunningProcess#waitFor()} (if needed). + *
+ * To dispose this {@code ProcessRunner} instance, either call {@link #close()} or {@link LongRunningProcess#close()}. After + * {@link #close()} or {@link LongRunningProcess#close()} has been called, this {@code ProcessRunner} instance must not be used anymore. + */ + public LongRunningProcess start(@Nullable File cwd, @Nullable Map environment, @Nullable byte[] stdin, boolean redirectErrorStream, List args) throws IOException { + checkState(); ProcessBuilder builder = new ProcessBuilder(args); if (cwd != null) { builder.directory(cwd); @@ -105,20 +140,20 @@ public Result exec(@Nullable File cwd, @Nullable Map environment if (stdin == null) { stdin = new byte[0]; } + if (redirectErrorStream) { + builder.redirectErrorStream(true); + } + Process process = builder.start(); Future outputFut = threadStdOut.submit(() -> drainToBytes(process.getInputStream(), bufStdOut)); - Future errorFut = threadStdErr.submit(() -> drainToBytes(process.getErrorStream(), bufStdErr)); + Future errorFut = null; + if (!redirectErrorStream) { + errorFut = threadStdErr.submit(() -> drainToBytes(process.getErrorStream(), bufStdErr)); + } // write stdin process.getOutputStream().write(stdin); process.getOutputStream().close(); - // wait for the process to finish - int exitCode = process.waitFor(); - try { - // collect the output - return new Result(args, exitCode, outputFut.get(), errorFut.get()); - } catch (ExecutionException e) { - throw ThrowingEx.asRuntime(e); - } + return new LongRunningProcess(process, args, outputFut, errorFut); } private static void drain(InputStream input, OutputStream output) throws IOException { @@ -141,17 +176,24 @@ public void close() { threadStdErr.shutdown(); } + /** Checks if this {@code ProcessRunner} instance is still usable. */ + private void checkState() { + if (threadStdOut.isShutdown() || threadStdErr.isShutdown()) { + throw new IllegalStateException("ProcessRunner has been closed and must not be used anymore."); + } + } + @SuppressFBWarnings({"EI_EXPOSE_REP", "EI_EXPOSE_REP2"}) public static class Result { private final List args; private final int exitCode; private final byte[] stdOut, stdErr; - public Result(List args, int exitCode, byte[] stdOut, byte[] stdErr) { + public Result(@Nonnull List args, int exitCode, @Nonnull byte[] stdOut, @Nullable byte[] stdErr) { this.args = args; this.exitCode = exitCode; this.stdOut = stdOut; - this.stdErr = stdErr; + this.stdErr = (stdErr == null ? new byte[0] : stdErr); } public List args() { @@ -222,8 +264,86 @@ public String toString() { } }; perStream.accept(" stdout", stdOut); - perStream.accept(" stderr", stdErr); + if (stdErr.length > 0) { + perStream.accept(" stderr", stdErr); + } return builder.toString(); } } + + /** + * A long-running process that can be waited for. + */ + public class LongRunningProcess extends Process implements AutoCloseable { + + private final Process delegate; + private final List args; + private final Future outputFut; + private final Future errorFut; + + public LongRunningProcess(@Nonnull Process delegate, @Nonnull List args, @Nonnull Future outputFut, @Nullable Future errorFut) { + this.delegate = requireNonNull(delegate); + this.args = args; + this.outputFut = outputFut; + this.errorFut = errorFut; + } + + @Override + public OutputStream getOutputStream() { + return delegate.getOutputStream(); + } + + @Override + public InputStream getInputStream() { + return delegate.getInputStream(); + } + + @Override + public InputStream getErrorStream() { + return delegate.getErrorStream(); + } + + @Override + public int waitFor() throws InterruptedException { + return delegate.waitFor(); + } + + @Override + public boolean waitFor(long timeout, TimeUnit unit) throws InterruptedException { + return delegate.waitFor(timeout, unit); + } + + @Override + public int exitValue() { + return delegate.exitValue(); + } + + @Override + public void destroy() { + delegate.destroy(); + } + + @Override + public Process destroyForcibly() { + return delegate.destroyForcibly(); + } + + @Override + public boolean isAlive() { + return delegate.isAlive(); + } + + public Result result() throws ExecutionException, InterruptedException { + int exitCode = waitFor(); + return new Result(args, exitCode, this.outputFut.get(), (this.errorFut != null ? this.errorFut.get() : null)); + } + + @Override + public void close() { + if (isAlive()) { + destroy(); + } + ProcessRunner.this.close(); + } + } } diff --git a/lib/src/main/java/com/diffplug/spotless/npm/NpmProcess.java b/lib/src/main/java/com/diffplug/spotless/npm/NpmProcess.java index 1675a4aa4e..b622cbd8ba 100644 --- a/lib/src/main/java/com/diffplug/spotless/npm/NpmProcess.java +++ b/lib/src/main/java/com/diffplug/spotless/npm/NpmProcess.java @@ -19,9 +19,15 @@ import java.io.IOException; import java.util.ArrayList; import java.util.Arrays; +import java.util.HashMap; import java.util.List; +import java.util.Map; +import java.util.concurrent.ExecutionException; import java.util.stream.Collectors; +import com.diffplug.spotless.ProcessRunner; +import com.diffplug.spotless.ProcessRunner.LongRunningProcess; + class NpmProcess { private final File workingDir; @@ -30,10 +36,13 @@ class NpmProcess { private final File nodeExecutable; + private final ProcessRunner processRunner; + NpmProcess(File workingDir, File npmExecutable, File nodeExecutable) { this.workingDir = workingDir; this.npmExecutable = npmExecutable; this.nodeExecutable = nodeExecutable; + processRunner = new ProcessRunner(); } void install() { @@ -44,32 +53,27 @@ void install() { "--prefer-offline"); } - Process start() { + LongRunningProcess start() { // adding --scripts-prepend-node-path=true due to https://github.com/diffplug/spotless/issues/619#issuecomment-648018679 return npm("start", "--scripts-prepend-node-path=true"); } private void npmAwait(String... args) { - final Process npmProcess = npm(args); - - try { + try (LongRunningProcess npmProcess = npm(args)) { if (npmProcess.waitFor() != 0) { - throw new NpmProcessException("Running npm command '" + commandLine(args) + "' failed with exit code: " + npmProcess.exitValue()); + throw new NpmProcessException("Running npm command '" + commandLine(args) + "' failed with exit code: " + npmProcess.exitValue() + "\n\n" + npmProcess.result()); } } catch (InterruptedException e) { throw new NpmProcessException("Running npm command '" + commandLine(args) + "' was interrupted.", e); + } catch (ExecutionException e) { + throw new NpmProcessException("Running npm command '" + commandLine(args) + "' failed.", e); } } - private Process npm(String... args) { + private LongRunningProcess npm(String... args) { List processCommand = processCommand(args); try { - ProcessBuilder processBuilder = new ProcessBuilder() - .inheritIO() - .directory(this.workingDir) - .command(processCommand); - addEnvironmentVariables(processBuilder); - return processBuilder.start(); + return processRunner.start(this.workingDir, environmentVariables(), null, true, processCommand); } catch (IOException e) { throw new NpmProcessException("Failed to launch npm command '" + commandLine(args) + "'.", e); } @@ -82,8 +86,10 @@ private List processCommand(String... args) { return command; } - private void addEnvironmentVariables(ProcessBuilder processBuilder) { - processBuilder.environment().put("PATH", this.nodeExecutable.getParentFile().getAbsolutePath() + File.pathSeparator + System.getenv("PATH")); + private Map environmentVariables() { + Map environmentVariables = new HashMap<>(); + environmentVariables.put("PATH", this.nodeExecutable.getParentFile().getAbsolutePath() + File.pathSeparator + System.getenv("PATH")); + return environmentVariables; } private String commandLine(String... args) { From 1c285ecfcd321c0ba37c2ca5d993566e2ce15398 Mon Sep 17 00:00:00 2001 From: Simon Gamma Date: Fri, 20 Jan 2023 23:04:26 +0100 Subject: [PATCH 623/757] 1416: suggest prettier plugins --- .../spotless/npm/PrettierFormatterStep.java | 10 +- .../npm/PrettierMissingParserException.java | 116 ++++++++++++++++++ .../spotless/PrettierIntegrationTest.java | 23 ++++ 3 files changed, 148 insertions(+), 1 deletion(-) create mode 100644 lib/src/main/java/com/diffplug/spotless/npm/PrettierMissingParserException.java diff --git a/lib/src/main/java/com/diffplug/spotless/npm/PrettierFormatterStep.java b/lib/src/main/java/com/diffplug/spotless/npm/PrettierFormatterStep.java index 20ff71d08e..22dd4586ee 100644 --- a/lib/src/main/java/com/diffplug/spotless/npm/PrettierFormatterStep.java +++ b/lib/src/main/java/com/diffplug/spotless/npm/PrettierFormatterStep.java @@ -122,7 +122,14 @@ public String applyWithFile(String unix, File file) throws Exception { FormattedPrinter.SYSOUT.print("formatting String '" + unix.substring(0, Math.min(50, unix.length())) + "[...]' in file '" + file + "'"); final String prettierConfigOptionsWithFilepath = assertFilepathInConfigOptions(file); - return restService.format(unix, prettierConfigOptionsWithFilepath); + try { + return restService.format(unix, prettierConfigOptionsWithFilepath); + } catch (SimpleRestClient.SimpleRestResponseException e) { + if (e.getStatusCode() != 200 && e.getResponseMessage().contains("No parser could be inferred")) { + throw new PrettierMissingParserException(file, e); + } + throw e; + } } private String assertFilepathInConfigOptions(File file) { @@ -141,4 +148,5 @@ private String assertFilepathInConfigOptions(File file) { return "{" + filePathOption + (hasAnyConfigOption ? "," : "") + prettierConfigOptions.substring(startOfConfigOption + 1); } } + } diff --git a/lib/src/main/java/com/diffplug/spotless/npm/PrettierMissingParserException.java b/lib/src/main/java/com/diffplug/spotless/npm/PrettierMissingParserException.java new file mode 100644 index 0000000000..73f81a0e07 --- /dev/null +++ b/lib/src/main/java/com/diffplug/spotless/npm/PrettierMissingParserException.java @@ -0,0 +1,116 @@ +/* + * Copyright 2023 DiffPlug + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.diffplug.spotless.npm; + +import java.io.File; +import java.util.Arrays; +import java.util.Collections; +import java.util.HashMap; +import java.util.Map; +import java.util.Objects; + +import javax.annotation.Nonnull; + +class PrettierMissingParserException extends RuntimeException { + private static final long serialVersionUID = 1L; + + private static final Map EXTENSIONS_TO_PLUGINS; + + static { + Map plugins = new HashMap<>(); + // ---- official plugins + plugins.put(".php", "@prettier/plugin-php"); + plugins.put(".pug", "@prettier/plugin-pug"); + plugins.put(".rb", "@prettier/plugin-ruby"); + plugins.put(".xml", "@prettier/plugin-xml"); + + // ---- community plugins + // default namings: astro, elm, java, jsonata, prisma, properties, sh, sql, svelte, toml + plugins.put(".trigger", "prettier-plugin-apex"); + plugins.put(".cls", "prettier-plugin-apex"); + plugins.put(".html.erb", "prettier-plugin-erb"); + Arrays.asList(".glsl", + ".fp", + ".frag", + ".frg", + ".fs", + ".fsh", + ".fshader", + ".geo", + ".geom", + ".glslf", + ".glslv", + ".gs", + ".gshader", + ".rchit", + ".rmiss", + ".shader", + ".tesc", + ".tese", + ".vert", + ".vrx", + ".vsh", + ".vshader").forEach(ext -> plugins.put(ext, "prettier-plugin-glsl")); + Arrays.asList(".go.html", + ".gohtml", + ".gotmpl", + ".go.tmpl", + ".tmpl", + ".tpl", + ".html.tmpl", + ".html.tpl").forEach(ext -> plugins.put(ext, "prettier-plugin-go-template")); + plugins.put(".kt", "kotlin"); + plugins.put(".mo", "motoko"); + Arrays.asList(".nginx", ".nginxconf").forEach(ext -> plugins.put(ext, "prettier-plugin-nginx")); + plugins.put(".sol", "prettier-plugin-solidity"); + + EXTENSIONS_TO_PLUGINS = Collections.unmodifiableMap(plugins); + } + + private final File file; + + public PrettierMissingParserException(@Nonnull File file, Exception cause) { + super("Prettier could not infer a parser for file '" + file + "'. Maybe you need to include a prettier plugin in devDependencies?\n\n" + recommendPlugin(file), cause); + this.file = Objects.requireNonNull(file); + } + + private static String recommendPlugin(File file) { + String pluginName = guessPlugin(file); + return "A good candidate for file '" + file + "' is '" + pluginName + "\n" + + "See if you can find it on \n" + + "or search on npmjs.com for a plugin matching that name: " + + String.format("\n\n", pluginName) + + "For instructions on how to include plugins for prettier in spotless see our documentation:\n" + + "- for gradle \n" + + "- for maven "; + } + + private static String guessPlugin(File file) { + return EXTENSIONS_TO_PLUGINS.entrySet().stream() + .filter(entry -> file.getName().endsWith(entry.getKey())) + .findFirst() + .map(entry -> entry.getValue()) + .orElse("prettier-plugin-" + extension(file)); + } + + public String fileType() { + return extension(file); + } + + private static String extension(File file) { + return file.getName().substring(file.getName().lastIndexOf('.') + 1); + } +} diff --git a/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/PrettierIntegrationTest.java b/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/PrettierIntegrationTest.java index bc8ad1148e..4c458e3ca7 100644 --- a/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/PrettierIntegrationTest.java +++ b/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/PrettierIntegrationTest.java @@ -135,6 +135,29 @@ void useJavaCommunityPlugin() throws IOException { assertFile("JavaTest.java").sameAsResource("npm/prettier/plugins/java-test.clean"); } + @Test + void suggestsMissingJavaCommunityPlugin() throws IOException { + setFile("build.gradle").toLines( + "plugins {", + " id 'com.diffplug.spotless'", + "}", + "repositories { mavenCentral() }", + "def prettierConfig = [:]", + "prettierConfig['tabWidth'] = 4", + "def prettierPackages = [:]", + "prettierPackages['prettier'] = '2.0.5'", + "spotless {", + " format 'java', {", + " target 'JavaTest.java'", + " prettier(prettierPackages).config(prettierConfig)", + " }", + "}"); + setFile("JavaTest.java").toResource("npm/prettier/plugins/java-test.dirty"); + final BuildResult spotlessApply = gradleRunner().withArguments("--stacktrace", "spotlessApply").buildAndFail(); + Assertions.assertThat(spotlessApply.getOutput()).contains("could not infer a parser"); + Assertions.assertThat(spotlessApply.getOutput()).contains("prettier-plugin-java"); + } + @Test void usePhpCommunityPlugin() throws IOException { setFile("build.gradle").toLines( From 32eee78c9ed3dfc542213f5a72fdfde2503c005c Mon Sep 17 00:00:00 2001 From: Simon Gamma Date: Sun, 22 Jan 2023 21:15:32 +0100 Subject: [PATCH 624/757] 1416: limit output fetched by npm process usually only the last few lines are of interest anyway, so be kind to memory usage. --- ...mitedOverwritingByteArrayOutputStream.java | 132 +++++++++++++ .../com/diffplug/spotless/ProcessRunner.java | 13 +- .../com/diffplug/spotless/npm/NpmProcess.java | 2 +- ...dOverwritingByteArrayOutputStreamTest.java | 179 ++++++++++++++++++ 4 files changed, 322 insertions(+), 4 deletions(-) create mode 100644 lib/src/main/java/com/diffplug/spotless/LimitedOverwritingByteArrayOutputStream.java create mode 100644 lib/src/test/java/com/diffplug/spotless/LimitedOverwritingByteArrayOutputStreamTest.java diff --git a/lib/src/main/java/com/diffplug/spotless/LimitedOverwritingByteArrayOutputStream.java b/lib/src/main/java/com/diffplug/spotless/LimitedOverwritingByteArrayOutputStream.java new file mode 100644 index 0000000000..a76039fccd --- /dev/null +++ b/lib/src/main/java/com/diffplug/spotless/LimitedOverwritingByteArrayOutputStream.java @@ -0,0 +1,132 @@ +/* + * Copyright 2023 DiffPlug + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.diffplug.spotless; + +import java.io.ByteArrayOutputStream; +import java.io.IOException; +import java.io.OutputStream; +import java.io.UnsupportedEncodingException; + +public class LimitedOverwritingByteArrayOutputStream extends ByteArrayOutputStream { + + private final int limit; + + private int zeroIndexPointer = 0; + + private boolean isOverLimit = false; + + public LimitedOverwritingByteArrayOutputStream(int limit) { + this(limit, 32); + } + + public LimitedOverwritingByteArrayOutputStream(int limit, int initialCapacity) { + super(initialCapacity); + if (limit < initialCapacity) { + throw new IllegalArgumentException("Limit must be greater than initial capacity"); + } + if (limit < 0) { + throw new IllegalArgumentException("Limit must be greater than 0"); + } + if (limit % 2 != 0) { + throw new IllegalArgumentException("Limit must be even"); // to fit 16 bit unicode chars + } + this.limit = limit; + } + + // ---- writing + @Override + public synchronized void write(int b) { + if (count < limit) { + super.write(b); + return; + } + isOverLimit = true; + buf[zeroIndexPointer] = (byte) b; + zeroIndexPointer = (zeroIndexPointer + 1) % limit; + } + + @Override + public synchronized void write(byte[] b, int off, int len) { + int remaining = limit - count; + if (remaining >= len) { + super.write(b, off, len); + return; + } + if (remaining > 0) { + // write what we can "normally" + super.write(b, off, remaining); + // rest delegated + write(b, off + remaining, len - remaining); + return; + } + // we are over the limit + isOverLimit = true; + // write till limit is reached + int writeTillLimit = Math.min(len, limit - zeroIndexPointer); + System.arraycopy(b, off, buf, zeroIndexPointer, writeTillLimit); + zeroIndexPointer = (zeroIndexPointer + writeTillLimit) % limit; + if (writeTillLimit < len) { + // write rest + write(b, off + writeTillLimit, len - writeTillLimit); + } + } + + @Override + public synchronized void reset() { + super.reset(); + zeroIndexPointer = 0; + isOverLimit = false; + } + + // ---- output + @Override + public synchronized void writeTo(OutputStream out) throws IOException { + if (!isOverLimit) { + super.writeTo(out); + return; + } + out.write(buf, zeroIndexPointer, limit - zeroIndexPointer); + out.write(buf, 0, zeroIndexPointer); + } + + @Override + public synchronized byte[] toByteArray() { + if (!isOverLimit) { + return super.toByteArray(); + } + byte[] result = new byte[limit]; + System.arraycopy(buf, zeroIndexPointer, result, 0, limit - zeroIndexPointer); + System.arraycopy(buf, 0, result, limit - zeroIndexPointer, zeroIndexPointer); + return result; + } + + @Override + public synchronized String toString() { + if (!isOverLimit) { + return super.toString(); + } + return new String(buf, zeroIndexPointer, limit - zeroIndexPointer) + new String(buf, 0, zeroIndexPointer); + } + + @Override + public synchronized String toString(String charsetName) throws UnsupportedEncodingException { + if (!isOverLimit) { + return super.toString(charsetName); + } + return new String(buf, zeroIndexPointer, limit - zeroIndexPointer, charsetName) + new String(buf, 0, zeroIndexPointer, charsetName); + } + +} diff --git a/lib/src/main/java/com/diffplug/spotless/ProcessRunner.java b/lib/src/main/java/com/diffplug/spotless/ProcessRunner.java index 4c076e537c..0979c4cbd4 100644 --- a/lib/src/main/java/com/diffplug/spotless/ProcessRunner.java +++ b/lib/src/main/java/com/diffplug/spotless/ProcessRunner.java @@ -52,10 +52,17 @@ public class ProcessRunner implements AutoCloseable { private final ExecutorService threadStdOut = Executors.newSingleThreadExecutor(); private final ExecutorService threadStdErr = Executors.newSingleThreadExecutor(); - private final ByteArrayOutputStream bufStdOut = new ByteArrayOutputStream(); - private final ByteArrayOutputStream bufStdErr = new ByteArrayOutputStream(); + private final ByteArrayOutputStream bufStdOut; + private final ByteArrayOutputStream bufStdErr; - public ProcessRunner() {} + public ProcessRunner() { + this(-1); + } + + public ProcessRunner(int limitedBuffers) { + this.bufStdOut = limitedBuffers >= 0 ? new LimitedOverwritingByteArrayOutputStream(limitedBuffers) : new ByteArrayOutputStream(); + this.bufStdErr = limitedBuffers >= 0 ? new LimitedOverwritingByteArrayOutputStream(limitedBuffers) : new ByteArrayOutputStream(); + } /** Executes the given shell command (using {@code cmd} on windows and {@code sh} on unix). */ public Result shell(String cmd) throws IOException, InterruptedException { diff --git a/lib/src/main/java/com/diffplug/spotless/npm/NpmProcess.java b/lib/src/main/java/com/diffplug/spotless/npm/NpmProcess.java index b622cbd8ba..f97193745d 100644 --- a/lib/src/main/java/com/diffplug/spotless/npm/NpmProcess.java +++ b/lib/src/main/java/com/diffplug/spotless/npm/NpmProcess.java @@ -42,7 +42,7 @@ class NpmProcess { this.workingDir = workingDir; this.npmExecutable = npmExecutable; this.nodeExecutable = nodeExecutable; - processRunner = new ProcessRunner(); + processRunner = new ProcessRunner(100 * 1024); // 100kB } void install() { diff --git a/lib/src/test/java/com/diffplug/spotless/LimitedOverwritingByteArrayOutputStreamTest.java b/lib/src/test/java/com/diffplug/spotless/LimitedOverwritingByteArrayOutputStreamTest.java new file mode 100644 index 0000000000..63998a4d75 --- /dev/null +++ b/lib/src/test/java/com/diffplug/spotless/LimitedOverwritingByteArrayOutputStreamTest.java @@ -0,0 +1,179 @@ +/* + * Copyright 2023 DiffPlug + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.diffplug.spotless; + +import java.io.ByteArrayOutputStream; +import java.io.IOException; +import java.util.stream.Stream; + +import org.assertj.core.api.Assertions; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.Arguments; +import org.junit.jupiter.params.provider.MethodSource; + +class LimitedOverwritingByteArrayOutputStreamTest { + + private final byte[] bytes = new byte[]{'0', '1', '2', '3', '4', '5', '6', '7', '8', '9'}; + + @ParameterizedTest(name = "{index} writeStrategy: {0}") + @MethodSource("writeStrategies") + void toStringBehavesNormallyWithinLimit(String name, ByteWriteStrategy writeStrategy) { + LimitedOverwritingByteArrayOutputStream stream = new LimitedOverwritingByteArrayOutputStream(12, 1); + writeStrategy.write(stream, bytes); + Assertions.assertThat(stream.toString()).isEqualTo("0123456789"); + } + + @ParameterizedTest(name = "{index} writeStrategy: {0}") + @MethodSource("writeStrategies") + void toStringBehavesOverwritingOverLimit(String name, ByteWriteStrategy writeStrategy) { + LimitedOverwritingByteArrayOutputStream stream = new LimitedOverwritingByteArrayOutputStream(4, 1); + writeStrategy.write(stream, bytes); + Assertions.assertThat(stream.toString()).hasSize(4); + Assertions.assertThat(stream.toString()).isEqualTo("6789"); + } + + @ParameterizedTest(name = "{index} writeStrategy: {0}") + @MethodSource("writeStrategies") + void toStringBehavesNormallyAtExactlyLimit(String name, ByteWriteStrategy writeStrategy) { + LimitedOverwritingByteArrayOutputStream stream = new LimitedOverwritingByteArrayOutputStream(bytes.length, 1); + writeStrategy.write(stream, bytes); + Assertions.assertThat(stream.toString()).isEqualTo("0123456789"); + } + + @ParameterizedTest(name = "{index} writeStrategy: {0}") + @MethodSource("writeStrategies") + void toByteArrayBehavesNormallyWithinLimit(String name, ByteWriteStrategy writeStrategy) { + LimitedOverwritingByteArrayOutputStream stream = new LimitedOverwritingByteArrayOutputStream(12, 1); + writeStrategy.write(stream, bytes); + Assertions.assertThat(stream.toByteArray()).isEqualTo(bytes); + } + + @ParameterizedTest(name = "{index} writeStrategy: {0}") + @MethodSource("writeStrategies") + void toByteArrayBehavesOverwritingOverLimit(String name, ByteWriteStrategy writeStrategy) { + LimitedOverwritingByteArrayOutputStream stream = new LimitedOverwritingByteArrayOutputStream(4, 1); + writeStrategy.write(stream, bytes); + Assertions.assertThat(stream.toByteArray()).hasSize(4); + Assertions.assertThat(stream.toByteArray()).isEqualTo(new byte[]{'6', '7', '8', '9'}); + } + + @ParameterizedTest(name = "{index} writeStrategy: {0}") + @MethodSource("writeStrategies") + void toByteArrayBehavesOverwritingAtExactlyLimit(String name, ByteWriteStrategy writeStrategy) { + LimitedOverwritingByteArrayOutputStream stream = new LimitedOverwritingByteArrayOutputStream(bytes.length, 1); + writeStrategy.write(stream, bytes); + Assertions.assertThat(stream.toByteArray()).isEqualTo(bytes); + } + + @ParameterizedTest(name = "{index} writeStrategy: {0}") + @MethodSource("writeStrategies") + void writeToBehavesNormallyWithinLimit(String name, ByteWriteStrategy writeStrategy) throws IOException { + LimitedOverwritingByteArrayOutputStream stream = new LimitedOverwritingByteArrayOutputStream(12, 1); + writeStrategy.write(stream, bytes); + ByteArrayOutputStream target = new ByteArrayOutputStream(); + stream.writeTo(target); + Assertions.assertThat(target.toByteArray()).isEqualTo(bytes); + } + + @ParameterizedTest(name = "{index} writeStrategy: {0}") + @MethodSource("writeStrategies") + void writeToBehavesOverwritingOverLimit(String name, ByteWriteStrategy writeStrategy) throws IOException { + LimitedOverwritingByteArrayOutputStream stream = new LimitedOverwritingByteArrayOutputStream(4, 1); + writeStrategy.write(stream, bytes); + ByteArrayOutputStream target = new ByteArrayOutputStream(); + stream.writeTo(target); + Assertions.assertThat(target.toByteArray()).hasSize(4); + Assertions.assertThat(target.toByteArray()).isEqualTo(new byte[]{'6', '7', '8', '9'}); + } + + @ParameterizedTest(name = "{index} writeStrategy: {0}") + @MethodSource("writeStrategies") + void writeToBehavesNormallyAtExactlyLimit(String name, ByteWriteStrategy writeStrategy) throws IOException { + LimitedOverwritingByteArrayOutputStream stream = new LimitedOverwritingByteArrayOutputStream(bytes.length, 1); + writeStrategy.write(stream, bytes); + ByteArrayOutputStream target = new ByteArrayOutputStream(); + stream.writeTo(target); + Assertions.assertThat(target.toByteArray()).isEqualTo(bytes); + } + + @Test + void writeToBehavesCorrectlyWhenOverLimitMultipleCalls() { + // this test explicitly captures a border case where the buffer is not empty but can exactly fit what we are writing + LimitedOverwritingByteArrayOutputStream stream = new LimitedOverwritingByteArrayOutputStream(2, 1); + stream.write('0'); + stream.write(new byte[]{'1', '2'}, 0, 2); + Assertions.assertThat(stream.toString()).hasSize(2); + Assertions.assertThat(stream.toString()).isEqualTo("12"); + } + + private static Stream writeStrategies() { + return Stream.of( + Arguments.of("writeAllAtOnce", allAtOnce()), + Arguments.of("writeOneByteAtATime", oneByteAtATime()), + Arguments.of("writeTwoBytesAtATime", twoBytesAtATime()), + Arguments.of("writeOneAndThenTwoBytesAtATime", oneAndThenTwoBytesAtATime()), + Arguments.of("firstFourBytesAndThenTheRest", firstFourBytesAndThenTheRest())); + } + + private static ByteWriteStrategy allAtOnce() { + return (stream, bytes) -> stream.write(bytes, 0, bytes.length); + } + + private static ByteWriteStrategy oneByteAtATime() { + return (stream, bytes) -> { + for (byte b : bytes) { + stream.write(b); + } + }; + } + + private static ByteWriteStrategy twoBytesAtATime() { + return (stream, bytes) -> { + for (int i = 0; i < bytes.length; i += 2) { + stream.write(bytes, i, 2); + } + }; + } + + private static ByteWriteStrategy oneAndThenTwoBytesAtATime() { + return (stream, bytes) -> { + int written = 0; + for (int i = 0; i + 3 < bytes.length; i += 3) { + stream.write(bytes, i, 1); + stream.write(bytes, i + 1, 2); + written += 3; + } + if (written < bytes.length) { + stream.write(bytes, written, bytes.length - written); + } + + }; + } + + private static ByteWriteStrategy firstFourBytesAndThenTheRest() { + return (stream, bytes) -> { + stream.write(bytes, 0, 4); + stream.write(bytes, 4, bytes.length - 4); + }; + } + + @FunctionalInterface + private interface ByteWriteStrategy { + void write(LimitedOverwritingByteArrayOutputStream stream, byte[] bytes); + } + +} From 8b56d5dafa4af82b6c327121df14ad0612e6494d Mon Sep 17 00:00:00 2001 From: Simon Gamma Date: Sun, 22 Jan 2023 21:24:24 +0100 Subject: [PATCH 625/757] 1416: document changes --- CHANGES.md | 2 ++ plugin-gradle/CHANGES.md | 2 ++ plugin-maven/CHANGES.md | 2 ++ 3 files changed, 6 insertions(+) diff --git a/CHANGES.md b/CHANGES.md index 07b81a8fc5..f5882e5d99 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -12,6 +12,8 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format ( ## [Unreleased] ### Added * `ProcessRunner` has added some convenience methods so it can be used for maven testing. ([#1496](https://github.com/diffplug/spotless/pull/1496)) +* `ProcessRunner` allows to limit captured output to a certain number of bytes. ([#1511](https://github.com/diffplug/spotless/pull/1511)) +* `ProcessRunner` is now capable of handling long-running tasks where waiting for exit is delegated to the caller. ([#1511](https://github.com/diffplug/spotless/pull/1511)) * Allow to specify node executable for node-based formatters using `nodeExecutable` parameter ([#1500](https://github.com/diffplug/spotless/pull/1500)) ### Fixed * The default list of type annotations used by `formatAnnotations` has had 8 more annotations from the Checker Framework added [#1494](https://github.com/diffplug/spotless/pull/1494) diff --git a/plugin-gradle/CHANGES.md b/plugin-gradle/CHANGES.md index cac247a307..f8a6242adf 100644 --- a/plugin-gradle/CHANGES.md +++ b/plugin-gradle/CHANGES.md @@ -10,6 +10,8 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format ( ### Fixed * The default list of type annotations used by `formatAnnotations` has had 8 more annotations from the Checker Framework added [#1494](https://github.com/diffplug/spotless/pull/1494) ### Changes +* Prettier will now suggest to install plugins if a parser cannot be inferred from the file extension ([#1511](https://github.com/diffplug/spotless/pull/1511)) + ## [6.13.0] - 2023-01-14 ### Added diff --git a/plugin-maven/CHANGES.md b/plugin-maven/CHANGES.md index ecb67f231f..f1ab739b62 100644 --- a/plugin-maven/CHANGES.md +++ b/plugin-maven/CHANGES.md @@ -13,6 +13,8 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format ( * The default list of type annotations used by `formatAnnotations` has had 8 more annotations from the Checker Framework added [#1494](https://github.com/diffplug/spotless/pull/1494) ### Changes * Spotless' custom build was replaced by [`maven-plugin-development`](https://github.com/britter/maven-plugin-development). ([#1496](https://github.com/diffplug/spotless/pull/1496) fixes [#554](https://github.com/diffplug/spotless/issues/554)) +* Prettier will now suggest to install plugins if a parser cannot be inferred from the file extension ([#1511](https://github.com/diffplug/spotless/pull/1511)) + ## [2.30.0] - 2023-01-13 ### Added From 2c54ee976245a486572c1b728b5f1dd8db1d06e3 Mon Sep 17 00:00:00 2001 From: Simon Gamma Date: Mon, 23 Jan 2023 08:59:28 +0100 Subject: [PATCH 626/757] 1416: Integrate PR Feedback --- .../com/diffplug/spotless/ProcessRunner.java | 10 +++++--- ...a => RingBufferByteArrayOutputStream.java} | 14 +++++------ .../com/diffplug/spotless/npm/NpmProcess.java | 2 +- ... RingBufferByteArrayOutputStreamTest.java} | 24 +++++++++---------- 4 files changed, 27 insertions(+), 23 deletions(-) rename lib/src/main/java/com/diffplug/spotless/{LimitedOverwritingByteArrayOutputStream.java => RingBufferByteArrayOutputStream.java} (88%) rename lib/src/test/java/com/diffplug/spotless/{LimitedOverwritingByteArrayOutputStreamTest.java => RingBufferByteArrayOutputStreamTest.java} (83%) diff --git a/lib/src/main/java/com/diffplug/spotless/ProcessRunner.java b/lib/src/main/java/com/diffplug/spotless/ProcessRunner.java index 0979c4cbd4..4e48042184 100644 --- a/lib/src/main/java/com/diffplug/spotless/ProcessRunner.java +++ b/lib/src/main/java/com/diffplug/spotless/ProcessRunner.java @@ -59,9 +59,13 @@ public ProcessRunner() { this(-1); } - public ProcessRunner(int limitedBuffers) { - this.bufStdOut = limitedBuffers >= 0 ? new LimitedOverwritingByteArrayOutputStream(limitedBuffers) : new ByteArrayOutputStream(); - this.bufStdErr = limitedBuffers >= 0 ? new LimitedOverwritingByteArrayOutputStream(limitedBuffers) : new ByteArrayOutputStream(); + public static ProcessRunner usingRingBuffersOfCapacity(int limit) { + return new ProcessRunner(limit); + } + + private ProcessRunner(int limitedBuffers) { + this.bufStdOut = limitedBuffers >= 0 ? new RingBufferByteArrayOutputStream(limitedBuffers) : new ByteArrayOutputStream(); + this.bufStdErr = limitedBuffers >= 0 ? new RingBufferByteArrayOutputStream(limitedBuffers) : new ByteArrayOutputStream(); } /** Executes the given shell command (using {@code cmd} on windows and {@code sh} on unix). */ diff --git a/lib/src/main/java/com/diffplug/spotless/LimitedOverwritingByteArrayOutputStream.java b/lib/src/main/java/com/diffplug/spotless/RingBufferByteArrayOutputStream.java similarity index 88% rename from lib/src/main/java/com/diffplug/spotless/LimitedOverwritingByteArrayOutputStream.java rename to lib/src/main/java/com/diffplug/spotless/RingBufferByteArrayOutputStream.java index a76039fccd..0353b50846 100644 --- a/lib/src/main/java/com/diffplug/spotless/LimitedOverwritingByteArrayOutputStream.java +++ b/lib/src/main/java/com/diffplug/spotless/RingBufferByteArrayOutputStream.java @@ -20,7 +20,7 @@ import java.io.OutputStream; import java.io.UnsupportedEncodingException; -public class LimitedOverwritingByteArrayOutputStream extends ByteArrayOutputStream { +class RingBufferByteArrayOutputStream extends ByteArrayOutputStream { private final int limit; @@ -28,20 +28,20 @@ public class LimitedOverwritingByteArrayOutputStream extends ByteArrayOutputStre private boolean isOverLimit = false; - public LimitedOverwritingByteArrayOutputStream(int limit) { + public RingBufferByteArrayOutputStream(int limit) { this(limit, 32); } - public LimitedOverwritingByteArrayOutputStream(int limit, int initialCapacity) { + public RingBufferByteArrayOutputStream(int limit, int initialCapacity) { super(initialCapacity); if (limit < initialCapacity) { - throw new IllegalArgumentException("Limit must be greater than initial capacity"); + throw new IllegalArgumentException("Limit must be greater than initial capacity. Limit: " + limit + ", initial capacity: " + initialCapacity); } - if (limit < 0) { - throw new IllegalArgumentException("Limit must be greater than 0"); + if (limit < 2) { + throw new IllegalArgumentException("Limit must be greater than or equal to 2 but is " + limit); } if (limit % 2 != 0) { - throw new IllegalArgumentException("Limit must be even"); // to fit 16 bit unicode chars + throw new IllegalArgumentException("Limit must be an even number but is " + limit); // to fit 16 bit unicode chars } this.limit = limit; } diff --git a/lib/src/main/java/com/diffplug/spotless/npm/NpmProcess.java b/lib/src/main/java/com/diffplug/spotless/npm/NpmProcess.java index f97193745d..6384900d82 100644 --- a/lib/src/main/java/com/diffplug/spotless/npm/NpmProcess.java +++ b/lib/src/main/java/com/diffplug/spotless/npm/NpmProcess.java @@ -42,7 +42,7 @@ class NpmProcess { this.workingDir = workingDir; this.npmExecutable = npmExecutable; this.nodeExecutable = nodeExecutable; - processRunner = new ProcessRunner(100 * 1024); // 100kB + processRunner = ProcessRunner.usingRingBuffersOfCapacity(100 * 1024); // 100kB } void install() { diff --git a/lib/src/test/java/com/diffplug/spotless/LimitedOverwritingByteArrayOutputStreamTest.java b/lib/src/test/java/com/diffplug/spotless/RingBufferByteArrayOutputStreamTest.java similarity index 83% rename from lib/src/test/java/com/diffplug/spotless/LimitedOverwritingByteArrayOutputStreamTest.java rename to lib/src/test/java/com/diffplug/spotless/RingBufferByteArrayOutputStreamTest.java index 63998a4d75..94fa49dbc1 100644 --- a/lib/src/test/java/com/diffplug/spotless/LimitedOverwritingByteArrayOutputStreamTest.java +++ b/lib/src/test/java/com/diffplug/spotless/RingBufferByteArrayOutputStreamTest.java @@ -25,14 +25,14 @@ import org.junit.jupiter.params.provider.Arguments; import org.junit.jupiter.params.provider.MethodSource; -class LimitedOverwritingByteArrayOutputStreamTest { +class RingBufferByteArrayOutputStreamTest { private final byte[] bytes = new byte[]{'0', '1', '2', '3', '4', '5', '6', '7', '8', '9'}; @ParameterizedTest(name = "{index} writeStrategy: {0}") @MethodSource("writeStrategies") void toStringBehavesNormallyWithinLimit(String name, ByteWriteStrategy writeStrategy) { - LimitedOverwritingByteArrayOutputStream stream = new LimitedOverwritingByteArrayOutputStream(12, 1); + RingBufferByteArrayOutputStream stream = new RingBufferByteArrayOutputStream(12, 1); writeStrategy.write(stream, bytes); Assertions.assertThat(stream.toString()).isEqualTo("0123456789"); } @@ -40,7 +40,7 @@ void toStringBehavesNormallyWithinLimit(String name, ByteWriteStrategy writeStra @ParameterizedTest(name = "{index} writeStrategy: {0}") @MethodSource("writeStrategies") void toStringBehavesOverwritingOverLimit(String name, ByteWriteStrategy writeStrategy) { - LimitedOverwritingByteArrayOutputStream stream = new LimitedOverwritingByteArrayOutputStream(4, 1); + RingBufferByteArrayOutputStream stream = new RingBufferByteArrayOutputStream(4, 1); writeStrategy.write(stream, bytes); Assertions.assertThat(stream.toString()).hasSize(4); Assertions.assertThat(stream.toString()).isEqualTo("6789"); @@ -49,7 +49,7 @@ void toStringBehavesOverwritingOverLimit(String name, ByteWriteStrategy writeStr @ParameterizedTest(name = "{index} writeStrategy: {0}") @MethodSource("writeStrategies") void toStringBehavesNormallyAtExactlyLimit(String name, ByteWriteStrategy writeStrategy) { - LimitedOverwritingByteArrayOutputStream stream = new LimitedOverwritingByteArrayOutputStream(bytes.length, 1); + RingBufferByteArrayOutputStream stream = new RingBufferByteArrayOutputStream(bytes.length, 1); writeStrategy.write(stream, bytes); Assertions.assertThat(stream.toString()).isEqualTo("0123456789"); } @@ -57,7 +57,7 @@ void toStringBehavesNormallyAtExactlyLimit(String name, ByteWriteStrategy writeS @ParameterizedTest(name = "{index} writeStrategy: {0}") @MethodSource("writeStrategies") void toByteArrayBehavesNormallyWithinLimit(String name, ByteWriteStrategy writeStrategy) { - LimitedOverwritingByteArrayOutputStream stream = new LimitedOverwritingByteArrayOutputStream(12, 1); + RingBufferByteArrayOutputStream stream = new RingBufferByteArrayOutputStream(12, 1); writeStrategy.write(stream, bytes); Assertions.assertThat(stream.toByteArray()).isEqualTo(bytes); } @@ -65,7 +65,7 @@ void toByteArrayBehavesNormallyWithinLimit(String name, ByteWriteStrategy writeS @ParameterizedTest(name = "{index} writeStrategy: {0}") @MethodSource("writeStrategies") void toByteArrayBehavesOverwritingOverLimit(String name, ByteWriteStrategy writeStrategy) { - LimitedOverwritingByteArrayOutputStream stream = new LimitedOverwritingByteArrayOutputStream(4, 1); + RingBufferByteArrayOutputStream stream = new RingBufferByteArrayOutputStream(4, 1); writeStrategy.write(stream, bytes); Assertions.assertThat(stream.toByteArray()).hasSize(4); Assertions.assertThat(stream.toByteArray()).isEqualTo(new byte[]{'6', '7', '8', '9'}); @@ -74,7 +74,7 @@ void toByteArrayBehavesOverwritingOverLimit(String name, ByteWriteStrategy write @ParameterizedTest(name = "{index} writeStrategy: {0}") @MethodSource("writeStrategies") void toByteArrayBehavesOverwritingAtExactlyLimit(String name, ByteWriteStrategy writeStrategy) { - LimitedOverwritingByteArrayOutputStream stream = new LimitedOverwritingByteArrayOutputStream(bytes.length, 1); + RingBufferByteArrayOutputStream stream = new RingBufferByteArrayOutputStream(bytes.length, 1); writeStrategy.write(stream, bytes); Assertions.assertThat(stream.toByteArray()).isEqualTo(bytes); } @@ -82,7 +82,7 @@ void toByteArrayBehavesOverwritingAtExactlyLimit(String name, ByteWriteStrategy @ParameterizedTest(name = "{index} writeStrategy: {0}") @MethodSource("writeStrategies") void writeToBehavesNormallyWithinLimit(String name, ByteWriteStrategy writeStrategy) throws IOException { - LimitedOverwritingByteArrayOutputStream stream = new LimitedOverwritingByteArrayOutputStream(12, 1); + RingBufferByteArrayOutputStream stream = new RingBufferByteArrayOutputStream(12, 1); writeStrategy.write(stream, bytes); ByteArrayOutputStream target = new ByteArrayOutputStream(); stream.writeTo(target); @@ -92,7 +92,7 @@ void writeToBehavesNormallyWithinLimit(String name, ByteWriteStrategy writeStrat @ParameterizedTest(name = "{index} writeStrategy: {0}") @MethodSource("writeStrategies") void writeToBehavesOverwritingOverLimit(String name, ByteWriteStrategy writeStrategy) throws IOException { - LimitedOverwritingByteArrayOutputStream stream = new LimitedOverwritingByteArrayOutputStream(4, 1); + RingBufferByteArrayOutputStream stream = new RingBufferByteArrayOutputStream(4, 1); writeStrategy.write(stream, bytes); ByteArrayOutputStream target = new ByteArrayOutputStream(); stream.writeTo(target); @@ -103,7 +103,7 @@ void writeToBehavesOverwritingOverLimit(String name, ByteWriteStrategy writeStra @ParameterizedTest(name = "{index} writeStrategy: {0}") @MethodSource("writeStrategies") void writeToBehavesNormallyAtExactlyLimit(String name, ByteWriteStrategy writeStrategy) throws IOException { - LimitedOverwritingByteArrayOutputStream stream = new LimitedOverwritingByteArrayOutputStream(bytes.length, 1); + RingBufferByteArrayOutputStream stream = new RingBufferByteArrayOutputStream(bytes.length, 1); writeStrategy.write(stream, bytes); ByteArrayOutputStream target = new ByteArrayOutputStream(); stream.writeTo(target); @@ -113,7 +113,7 @@ void writeToBehavesNormallyAtExactlyLimit(String name, ByteWriteStrategy writeSt @Test void writeToBehavesCorrectlyWhenOverLimitMultipleCalls() { // this test explicitly captures a border case where the buffer is not empty but can exactly fit what we are writing - LimitedOverwritingByteArrayOutputStream stream = new LimitedOverwritingByteArrayOutputStream(2, 1); + RingBufferByteArrayOutputStream stream = new RingBufferByteArrayOutputStream(2, 1); stream.write('0'); stream.write(new byte[]{'1', '2'}, 0, 2); Assertions.assertThat(stream.toString()).hasSize(2); @@ -173,7 +173,7 @@ private static ByteWriteStrategy firstFourBytesAndThenTheRest() { @FunctionalInterface private interface ByteWriteStrategy { - void write(LimitedOverwritingByteArrayOutputStream stream, byte[] bytes); + void write(RingBufferByteArrayOutputStream stream, byte[] bytes); } } From c0cd99ddc2cdf630423cc4c38b7a0b97dec225ea Mon Sep 17 00:00:00 2001 From: Simon Gamma Date: Mon, 23 Jan 2023 09:10:30 +0100 Subject: [PATCH 627/757] 1416: spotbugs adaptions --- .../com/diffplug/spotless/RingBufferByteArrayOutputStream.java | 3 +++ .../diffplug/spotless/npm/PrettierMissingParserException.java | 3 ++- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/lib/src/main/java/com/diffplug/spotless/RingBufferByteArrayOutputStream.java b/lib/src/main/java/com/diffplug/spotless/RingBufferByteArrayOutputStream.java index 0353b50846..da4fc6aa04 100644 --- a/lib/src/main/java/com/diffplug/spotless/RingBufferByteArrayOutputStream.java +++ b/lib/src/main/java/com/diffplug/spotless/RingBufferByteArrayOutputStream.java @@ -20,6 +20,8 @@ import java.io.OutputStream; import java.io.UnsupportedEncodingException; +import edu.umd.cs.findbugs.annotations.SuppressFBWarnings; + class RingBufferByteArrayOutputStream extends ByteArrayOutputStream { private final int limit; @@ -113,6 +115,7 @@ public synchronized byte[] toByteArray() { return result; } + @SuppressFBWarnings(value = "DM_DEFAULT_ENCODING", justification = "We want to use the default encoding here since this is contract on ByteArrayOutputStream") @Override public synchronized String toString() { if (!isOverLimit) { diff --git a/lib/src/main/java/com/diffplug/spotless/npm/PrettierMissingParserException.java b/lib/src/main/java/com/diffplug/spotless/npm/PrettierMissingParserException.java index 73f81a0e07..6956545135 100644 --- a/lib/src/main/java/com/diffplug/spotless/npm/PrettierMissingParserException.java +++ b/lib/src/main/java/com/diffplug/spotless/npm/PrettierMissingParserException.java @@ -92,7 +92,8 @@ private static String recommendPlugin(File file) { return "A good candidate for file '" + file + "' is '" + pluginName + "\n" + "See if you can find it on \n" + "or search on npmjs.com for a plugin matching that name: " - + String.format("\n\n", pluginName) + + String.format("", pluginName) + + "\n\n" + "For instructions on how to include plugins for prettier in spotless see our documentation:\n" + "- for gradle \n" + "- for maven "; From 4aa3b7e0f460eaa7a7c329a7868e71060151c95b Mon Sep 17 00:00:00 2001 From: Ned Twigg Date: Mon, 23 Jan 2023 12:13:01 -0800 Subject: [PATCH 628/757] Run spotbugs in all configurations because it's not that slow (17 seconds on my M1) and it's confusing to PR authors to not run. --- gradle/java-setup.gradle | 2 -- 1 file changed, 2 deletions(-) diff --git a/gradle/java-setup.gradle b/gradle/java-setup.gradle index 9c9f394405..f8f2dedf39 100644 --- a/gradle/java-setup.gradle +++ b/gradle/java-setup.gradle @@ -34,8 +34,6 @@ tasks.withType(com.github.spotbugs.snom.SpotBugsTask).configureEach { } tasks.named('spotbugsMain') { - // only run on Java 8 (no benefit to running twice) - enabled = org.gradle.api.JavaVersion.current() == org.gradle.api.JavaVersion.VERSION_11 reports { html.enabled = true } From c849de8a376989005235263e5172fb7141218499 Mon Sep 17 00:00:00 2001 From: Ned Twigg Date: Mon, 23 Jan 2023 15:59:14 -0800 Subject: [PATCH 629/757] Revert previous commit b/c spotbugs gives errant warnings on Java 8. --- gradle/java-setup.gradle | 2 ++ 1 file changed, 2 insertions(+) diff --git a/gradle/java-setup.gradle b/gradle/java-setup.gradle index f8f2dedf39..9c9f394405 100644 --- a/gradle/java-setup.gradle +++ b/gradle/java-setup.gradle @@ -34,6 +34,8 @@ tasks.withType(com.github.spotbugs.snom.SpotBugsTask).configureEach { } tasks.named('spotbugsMain') { + // only run on Java 8 (no benefit to running twice) + enabled = org.gradle.api.JavaVersion.current() == org.gradle.api.JavaVersion.VERSION_11 reports { html.enabled = true } From 0b2a3295487b43d13f2cc6ab5e058c751588cc9b Mon Sep 17 00:00:00 2001 From: Ned Twigg Date: Mon, 23 Jan 2023 16:58:29 -0800 Subject: [PATCH 630/757] Stop running CI on java 8. --- .github/workflows/ci.yml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 1f08c201f5..e78061fc4c 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -37,19 +37,19 @@ jobs: fail-fast: false matrix: kind: [maven, gradle] - jre: [8, 11, 17] + jre: [11, 17] os: [ubuntu-latest] include: # test windows at the diagonals of the above matrix - kind: maven - jre: 8 + jre: 11 os: windows-latest - kind: gradle jre: 17 os: windows-latest # npm on linux only (crazy slow on windows) - kind: npm - jre: 8 + jre: 11 os: ubuntu-latest runs-on: ${{ matrix.os }} steps: From 826760dbad1912590068c5b6ea0c3c7bb9c4250b Mon Sep 17 00:00:00 2001 From: Ned Twigg Date: Mon, 23 Jan 2023 16:58:53 -0800 Subject: [PATCH 631/757] Run spotbugs on all supported JRE because it's not that slow (17 seconds on my M1) and it's confusing to PR authors to not run. --- gradle/java-setup.gradle | 2 -- 1 file changed, 2 deletions(-) diff --git a/gradle/java-setup.gradle b/gradle/java-setup.gradle index 9c9f394405..f8f2dedf39 100644 --- a/gradle/java-setup.gradle +++ b/gradle/java-setup.gradle @@ -34,8 +34,6 @@ tasks.withType(com.github.spotbugs.snom.SpotBugsTask).configureEach { } tasks.named('spotbugsMain') { - // only run on Java 8 (no benefit to running twice) - enabled = org.gradle.api.JavaVersion.current() == org.gradle.api.JavaVersion.VERSION_11 reports { html.enabled = true } From 1c5a3ef960f1e55f72be0c39c5803e69e23c2291 Mon Sep 17 00:00:00 2001 From: Ned Twigg Date: Mon, 23 Jan 2023 16:59:40 -0800 Subject: [PATCH 632/757] Remove `@EnabledForJreRange(min = JAVA_11)` since we don't support < Java 11 anymore anyway. --- .../extra/java/EclipseJdtFormatterStepTest.java | 7 ++----- .../gradle/spotless/KotlinExtensionTest.java | 13 ------------- .../gradle/spotless/KotlinGradleExtensionTest.java | 6 +----- .../spotless/maven/java/GoogleJavaFormatTest.java | 6 +----- .../spotless/maven/java/PalantirJavaFormatTest.java | 6 +----- .../diffplug/spotless/maven/kotlin/KtfmtTest.java | 6 +----- .../spotless/java/GoogleJavaFormatStepTest.java | 6 ++---- .../spotless/java/PalantirJavaFormatStepTest.java | 4 +--- .../com/diffplug/spotless/kotlin/KtfmtStepTest.java | 8 +------- 9 files changed, 10 insertions(+), 52 deletions(-) diff --git a/lib-extra/src/test/java/com/diffplug/spotless/extra/java/EclipseJdtFormatterStepTest.java b/lib-extra/src/test/java/com/diffplug/spotless/extra/java/EclipseJdtFormatterStepTest.java index 3e5e1853c7..2ade78f742 100644 --- a/lib-extra/src/test/java/com/diffplug/spotless/extra/java/EclipseJdtFormatterStepTest.java +++ b/lib-extra/src/test/java/com/diffplug/spotless/extra/java/EclipseJdtFormatterStepTest.java @@ -1,5 +1,5 @@ /* - * Copyright 2016-2021 DiffPlug + * Copyright 2016-2023 DiffPlug * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -15,14 +15,11 @@ */ package com.diffplug.spotless.extra.java; -import static org.junit.jupiter.api.condition.JRE.JAVA_11; - import java.io.File; import java.util.stream.Stream; import org.junit.jupiter.api.Nested; import org.junit.jupiter.api.Test; -import org.junit.jupiter.api.condition.EnabledForJreRange; import org.junit.jupiter.params.ParameterizedTest; import org.junit.jupiter.params.provider.MethodSource; @@ -57,7 +54,7 @@ private static Stream formatWithVersion() { /** New format interface requires source file information to distinguish module-info from compilation unit */ @Nested - @EnabledForJreRange(min = JAVA_11) + class NewFormatInterface extends EclipseResourceHarness { public NewFormatInterface() throws Exception { super(createBuilder(), "module-info.java", getTestResource("java/eclipse/ModuleInfoUnformatted.test"), getTestResource("java/eclipse/ModuleInfoFormatted.test")); diff --git a/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/KotlinExtensionTest.java b/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/KotlinExtensionTest.java index d77b22d0d3..a15a51412e 100644 --- a/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/KotlinExtensionTest.java +++ b/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/KotlinExtensionTest.java @@ -15,12 +15,9 @@ */ package com.diffplug.gradle.spotless; -import static org.junit.jupiter.api.condition.JRE.JAVA_11; - import java.io.IOException; import org.junit.jupiter.api.Test; -import org.junit.jupiter.api.condition.EnabledForJreRange; class KotlinExtensionTest extends GradleIntegrationHarness { private static final String HEADER = "// License Header"; @@ -63,7 +60,6 @@ void integrationDiktat() throws IOException { } @Test - @EnabledForJreRange(min = JAVA_11) // ktfmt's dependency, google-java-format 1.8 requires a minimum of JRE 11+. void integrationKtfmt() throws IOException { setFile("build.gradle").toLines( "plugins {", @@ -82,7 +78,6 @@ void integrationKtfmt() throws IOException { } @Test - @EnabledForJreRange(min = JAVA_11) // ktfmt's dependency, google-java-format 1.8 requires a minimum of JRE 11+. void integrationKtfmt_dropboxStyle_0_18() throws IOException { setFile("build.gradle").toLines( "plugins {", @@ -101,7 +96,6 @@ void integrationKtfmt_dropboxStyle_0_18() throws IOException { } @Test - @EnabledForJreRange(min = JAVA_11) // ktfmt's dependency, google-java-format 1.8 requires a minimum of JRE 11+. void integrationKtfmt_dropboxStyle_0_19() throws IOException { setFile("build.gradle").toLines( "plugins {", @@ -197,7 +191,6 @@ void testWithHeader() throws IOException { } @Test - @EnabledForJreRange(min = JAVA_11) // ktfmt's dependency, google-java-format 1.8 requires a minimum of JRE 11+. void testWithHeaderKtfmt() throws IOException { setFile("build.gradle").toLines( "plugins {", @@ -236,7 +229,6 @@ void testWithCustomHeaderSeparator() throws IOException { } @Test - @EnabledForJreRange(min = JAVA_11) // ktfmt's dependency, google-java-format 1.8 requires a minimum of JRE 11+. void testWithCustomHeaderSeparatorKtfmt() throws IOException { setFile("build.gradle").toLines( "plugins {", @@ -282,7 +274,6 @@ void testWithNonStandardYearSeparator() throws IOException { } @Test - @EnabledForJreRange(min = JAVA_11) // ktfmt's dependency, google-java-format 1.8 requires a minimum of JRE 11+. void testWithNonStandardYearSeparatorKtfmt() throws IOException { setFile("build.gradle").toLines( "plugins {", @@ -309,7 +300,6 @@ void testWithNonStandardYearSeparatorKtfmt() throws IOException { } @Test - @EnabledForJreRange(min = JAVA_11) // ktfmt's dependency, google-java-format 1.8 requires a minimum of JRE 11+. void testWithCustomMaxWidthDefaultStyleKtfmt() throws IOException { setFile("build.gradle").toLines( "plugins {", @@ -331,7 +321,6 @@ void testWithCustomMaxWidthDefaultStyleKtfmt() throws IOException { } @Test - @EnabledForJreRange(min = JAVA_11) // ktfmt's dependency, google-java-format 1.8 requires a minimum of JRE 11+. void testWithCustomMaxWidthDefaultStyleKtfmtGradleKts() throws IOException { setFile("build.gradle.kts").toLines( "plugins {", @@ -353,7 +342,6 @@ void testWithCustomMaxWidthDefaultStyleKtfmtGradleKts() throws IOException { } @Test - @EnabledForJreRange(min = JAVA_11) // ktfmt's dependency, google-java-format 1.8 requires a minimum of JRE 11+. void testWithCustomMaxWidthDropboxStyleKtfmt() throws IOException { setFile("build.gradle").toLines( "plugins {", @@ -375,7 +363,6 @@ void testWithCustomMaxWidthDropboxStyleKtfmt() throws IOException { } @Test - @EnabledForJreRange(min = JAVA_11) // ktfmt's dependency, google-java-format 1.8 requires a minimum of JRE 11+. void testWithCustomMaxWidthDropboxStyleKtfmtGradleKts() throws IOException { setFile("build.gradle.kts").toLines( "plugins {", diff --git a/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/KotlinGradleExtensionTest.java b/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/KotlinGradleExtensionTest.java index 0f3438ffff..015414c331 100644 --- a/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/KotlinGradleExtensionTest.java +++ b/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/KotlinGradleExtensionTest.java @@ -1,5 +1,5 @@ /* - * Copyright 2016-2022 DiffPlug + * Copyright 2016-2023 DiffPlug * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -16,13 +16,11 @@ package com.diffplug.gradle.spotless; import static org.assertj.core.api.Assertions.assertThat; -import static org.junit.jupiter.api.condition.JRE.JAVA_11; import java.io.IOException; import org.gradle.testkit.runner.BuildResult; import org.junit.jupiter.api.Test; -import org.junit.jupiter.api.condition.EnabledForJreRange; class KotlinGradleExtensionTest extends GradleIntegrationHarness { @Test @@ -151,7 +149,6 @@ void withExperimentalEditorConfigOverride() throws IOException { } @Test - @EnabledForJreRange(min = JAVA_11) // ktfmt's dependency, google-java-format 1.8 requires a minimum of JRE 11+. void integration_ktfmt() throws IOException { setFile("build.gradle").toLines( "plugins {", @@ -170,7 +167,6 @@ void integration_ktfmt() throws IOException { } @Test - @EnabledForJreRange(min = JAVA_11) // ktfmt's dependency, google-java-format 1.8 requires a minimum of JRE 11+. void integration_ktfmt_with_dropbox_style() throws IOException { setFile("build.gradle").toLines( "plugins {", diff --git a/plugin-maven/src/test/java/com/diffplug/spotless/maven/java/GoogleJavaFormatTest.java b/plugin-maven/src/test/java/com/diffplug/spotless/maven/java/GoogleJavaFormatTest.java index 6fbff78cc7..98a83d612c 100644 --- a/plugin-maven/src/test/java/com/diffplug/spotless/maven/java/GoogleJavaFormatTest.java +++ b/plugin-maven/src/test/java/com/diffplug/spotless/maven/java/GoogleJavaFormatTest.java @@ -1,5 +1,5 @@ /* - * Copyright 2016-2021 DiffPlug + * Copyright 2016-2023 DiffPlug * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -15,10 +15,7 @@ */ package com.diffplug.spotless.maven.java; -import static org.junit.jupiter.api.condition.JRE.JAVA_11; - import org.junit.jupiter.api.Test; -import org.junit.jupiter.api.condition.EnabledForJreRange; import com.diffplug.spotless.maven.MavenIntegrationHarness; @@ -45,7 +42,6 @@ void specificVersionSpecificStyle() throws Exception { } @Test - @EnabledForJreRange(min = JAVA_11) void specificVersionReflowLongStrings() throws Exception { writePomWithJavaSteps( "", diff --git a/plugin-maven/src/test/java/com/diffplug/spotless/maven/java/PalantirJavaFormatTest.java b/plugin-maven/src/test/java/com/diffplug/spotless/maven/java/PalantirJavaFormatTest.java index 33ec8ea84f..d8d66fa46d 100644 --- a/plugin-maven/src/test/java/com/diffplug/spotless/maven/java/PalantirJavaFormatTest.java +++ b/plugin-maven/src/test/java/com/diffplug/spotless/maven/java/PalantirJavaFormatTest.java @@ -1,5 +1,5 @@ /* - * Copyright 2022 DiffPlug + * Copyright 2022-2023 DiffPlug * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -15,10 +15,7 @@ */ package com.diffplug.spotless.maven.java; -import static org.junit.jupiter.api.condition.JRE.JAVA_11; - import org.junit.jupiter.api.Test; -import org.junit.jupiter.api.condition.EnabledForJreRange; import com.diffplug.spotless.maven.MavenIntegrationHarness; @@ -34,7 +31,6 @@ void specificVersionDefaultStyle() throws Exception { } @Test - @EnabledForJreRange(min = JAVA_11) void specificJava11Version2() throws Exception { writePomWithJavaSteps( "", diff --git a/plugin-maven/src/test/java/com/diffplug/spotless/maven/kotlin/KtfmtTest.java b/plugin-maven/src/test/java/com/diffplug/spotless/maven/kotlin/KtfmtTest.java index 88dcd172e0..4ae266cc23 100644 --- a/plugin-maven/src/test/java/com/diffplug/spotless/maven/kotlin/KtfmtTest.java +++ b/plugin-maven/src/test/java/com/diffplug/spotless/maven/kotlin/KtfmtTest.java @@ -1,5 +1,5 @@ /* - * Copyright 2016-2022 DiffPlug + * Copyright 2016-2023 DiffPlug * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -15,14 +15,10 @@ */ package com.diffplug.spotless.maven.kotlin; -import static org.junit.jupiter.api.condition.JRE.JAVA_11; - import org.junit.jupiter.api.Test; -import org.junit.jupiter.api.condition.EnabledForJreRange; import com.diffplug.spotless.maven.MavenIntegrationHarness; -@EnabledForJreRange(min = JAVA_11) // ktfmt's dependency, google-java-format 1.8 requires a minimum of JRE 11+. class KtfmtTest extends MavenIntegrationHarness { @Test void testKtfmt() throws Exception { diff --git a/testlib/src/test/java/com/diffplug/spotless/java/GoogleJavaFormatStepTest.java b/testlib/src/test/java/com/diffplug/spotless/java/GoogleJavaFormatStepTest.java index cf2a90ad79..ff64b574e1 100644 --- a/testlib/src/test/java/com/diffplug/spotless/java/GoogleJavaFormatStepTest.java +++ b/testlib/src/test/java/com/diffplug/spotless/java/GoogleJavaFormatStepTest.java @@ -1,5 +1,5 @@ /* - * Copyright 2016-2022 DiffPlug + * Copyright 2016-2023 DiffPlug * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -15,7 +15,6 @@ */ package com.diffplug.spotless.java; -import static org.junit.jupiter.api.condition.JRE.JAVA_11; import static org.junit.jupiter.api.condition.JRE.JAVA_13; import static org.junit.jupiter.api.condition.JRE.JAVA_15; @@ -42,7 +41,7 @@ void jvm13Features() throws Exception { } @Test - @EnabledForJreRange(min = JAVA_11, max = JAVA_15) // google-java-format requires JRE 11+ + @EnabledForJreRange(max = JAVA_15) // google-java-format requires JRE 11+ void behavior18() throws Exception { FormatterStep step = GoogleJavaFormatStep.create("1.8", TestProvisioner.mavenCentral()); StepHarness.forStep(step) @@ -125,7 +124,6 @@ protected FormatterStep create() { } @Test - @EnabledForJreRange(min = JAVA_11) // google-java-format requires JRE 11+ void equalityGroupArtifact() throws Exception { new SerializableEqualityTester() { String groupArtifact = GoogleJavaFormatStep.defaultGroupArtifact(); diff --git a/testlib/src/test/java/com/diffplug/spotless/java/PalantirJavaFormatStepTest.java b/testlib/src/test/java/com/diffplug/spotless/java/PalantirJavaFormatStepTest.java index ad358cafc6..dfd59c2655 100644 --- a/testlib/src/test/java/com/diffplug/spotless/java/PalantirJavaFormatStepTest.java +++ b/testlib/src/test/java/com/diffplug/spotless/java/PalantirJavaFormatStepTest.java @@ -1,5 +1,5 @@ /* - * Copyright 2022 DiffPlug + * Copyright 2022-2023 DiffPlug * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -15,7 +15,6 @@ */ package com.diffplug.spotless.java; -import static org.junit.jupiter.api.condition.JRE.JAVA_11; import static org.junit.jupiter.api.condition.JRE.JAVA_13; import org.junit.jupiter.api.Test; @@ -38,7 +37,6 @@ void jvm13Features() throws Exception { } @Test - @EnabledForJreRange(min = JAVA_11) void behavior2() throws Exception { FormatterStep step = PalantirJavaFormatStep.create("2.28.0", TestProvisioner.mavenCentral()); StepHarness.forStep(step) diff --git a/testlib/src/test/java/com/diffplug/spotless/kotlin/KtfmtStepTest.java b/testlib/src/test/java/com/diffplug/spotless/kotlin/KtfmtStepTest.java index ddaf1b324b..bfa971fc40 100644 --- a/testlib/src/test/java/com/diffplug/spotless/kotlin/KtfmtStepTest.java +++ b/testlib/src/test/java/com/diffplug/spotless/kotlin/KtfmtStepTest.java @@ -1,5 +1,5 @@ /* - * Copyright 2016-2022 DiffPlug + * Copyright 2016-2023 DiffPlug * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -15,32 +15,26 @@ */ package com.diffplug.spotless.kotlin; -import static org.junit.jupiter.api.condition.JRE.JAVA_11; - import org.junit.jupiter.api.Disabled; import org.junit.jupiter.api.Test; -import org.junit.jupiter.api.condition.EnabledForJreRange; import com.diffplug.spotless.*; @Disabled class KtfmtStepTest extends ResourceHarness { @Test - @EnabledForJreRange(min = JAVA_11) // ktfmt's dependency, google-java-format 1.8 requires a minimum of JRE 11+. void behavior() throws Exception { FormatterStep step = KtfmtStep.create(TestProvisioner.mavenCentral()); StepHarness.forStep(step).testResource("kotlin/ktfmt/basic.dirty", "kotlin/ktfmt/basic.clean"); } @Test - @EnabledForJreRange(min = JAVA_11) // ktfmt's dependency, google-java-format 1.8 requires a minimum of JRE 11+. void dropboxStyle_0_18() throws Exception { FormatterStep step = KtfmtStep.create("0.18", TestProvisioner.mavenCentral(), KtfmtStep.Style.DROPBOX, null); StepHarness.forStep(step).testResource("kotlin/ktfmt/basic.dirty", "kotlin/ktfmt/basic-dropboxstyle.clean"); } @Test - @EnabledForJreRange(min = JAVA_11) // ktfmt's dependency, google-java-format 1.8 requires a minimum of JRE 11+. void dropboxStyle_0_19() throws Exception { FormatterStep step = KtfmtStep.create("0.19", TestProvisioner.mavenCentral(), KtfmtStep.Style.DROPBOX, null); StepHarness.forStep(step).testResource("kotlin/ktfmt/basic.dirty", "kotlin/ktfmt/basic-dropboxstyle.clean"); From 14e71fb57d313726b0b11f9ece946001540d55cc Mon Sep 17 00:00:00 2001 From: Ned Twigg Date: Mon, 23 Jan 2023 17:02:39 -0800 Subject: [PATCH 633/757] The maven and gradle plugins yell at their users to update to Java 11, and how to update without affecting their users. --- .../com/diffplug/gradle/spotless/SpotlessPlugin.java | 10 +++++++++- .../diffplug/spotless/maven/AbstractSpotlessMojo.java | 11 +++++++++++ 2 files changed, 20 insertions(+), 1 deletion(-) 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 868502d216..91847af0cf 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 @@ -1,5 +1,5 @@ /* - * Copyright 2016-2022 DiffPlug + * Copyright 2016-2023 DiffPlug * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -16,21 +16,29 @@ package com.diffplug.gradle.spotless; import org.gradle.api.GradleException; +import org.gradle.api.JavaVersion; import org.gradle.api.Plugin; import org.gradle.api.Project; import org.gradle.api.plugins.BasePlugin; +import com.diffplug.spotless.Jvm; import com.diffplug.spotless.SpotlessCache; public class SpotlessPlugin implements Plugin { static final String SPOTLESS_MODERN = "spotlessModern"; static final String MINIMUM_GRADLE = "6.1.1"; + private static final int MINIMUM_JRE = 11; @Override public void apply(Project project) { if (SpotlessPluginRedirect.gradleIsTooOld(project)) { throw new GradleException("Spotless requires Gradle " + MINIMUM_GRADLE + " or newer, this was " + project.getGradle().getGradleVersion()); } + if (Jvm.version() < MINIMUM_JRE) { + throw new GradleException("Spotless requires JRE " + MINIMUM_JRE + " or newer, this was " + JavaVersion.current() + ".\n" + + "You can upgrade your build JRE and still compile for older targets, see below\n" + + "https://docs.gradle.org/current/userguide/building_java_projects.html#sec:java_cross_compilation"); + } // if -PspotlessModern=true, then use the modern stuff instead of the legacy stuff if (project.hasProperty(SPOTLESS_MODERN)) { project.getLogger().warn("'spotlessModern' has no effect as of Spotless 5.0, recommend removing it."); diff --git a/plugin-maven/src/main/java/com/diffplug/spotless/maven/AbstractSpotlessMojo.java b/plugin-maven/src/main/java/com/diffplug/spotless/maven/AbstractSpotlessMojo.java index e594c724ef..c4082f52e0 100644 --- a/plugin-maven/src/main/java/com/diffplug/spotless/maven/AbstractSpotlessMojo.java +++ b/plugin-maven/src/main/java/com/diffplug/spotless/maven/AbstractSpotlessMojo.java @@ -53,6 +53,7 @@ import org.sonatype.plexus.build.incremental.BuildContext; import com.diffplug.spotless.Formatter; +import com.diffplug.spotless.Jvm; import com.diffplug.spotless.LineEnding; import com.diffplug.spotless.Provisioner; import com.diffplug.spotless.generic.LicenseHeaderStep; @@ -190,6 +191,16 @@ public abstract class AbstractSpotlessMojo extends AbstractMojo { protected abstract void process(Iterable files, Formatter formatter, UpToDateChecker upToDateChecker) throws MojoExecutionException; + private static final int MINIMUM_JRE = 11; + + protected AbstractSpotlessMojo() { + if (Jvm.version() < MINIMUM_JRE) { + throw new RuntimeException("Spotless requires JRE " + MINIMUM_JRE + " or newer, this was " + Jvm.version() + ".\n" + + "You can upgrade your build JRE and still compile for older targets, see below\n" + + "https://docs.gradle.org/current/userguide/building_java_projects.html#sec:java_cross_compilation"); + } + } + @Override public final void execute() throws MojoExecutionException { if (shouldSkip()) { From b0975be27dab83fb62012650a273662e193f648a Mon Sep 17 00:00:00 2001 From: Ned Twigg Date: Mon, 23 Jan 2023 17:02:48 -0800 Subject: [PATCH 634/757] Update changelogs. --- CHANGES.md | 1 + plugin-gradle/CHANGES.md | 3 ++- plugin-maven/CHANGES.md | 3 ++- 3 files changed, 5 insertions(+), 2 deletions(-) diff --git a/CHANGES.md b/CHANGES.md index f5882e5d99..4c6a1aa0c4 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -18,6 +18,7 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format ( ### Fixed * The default list of type annotations used by `formatAnnotations` has had 8 more annotations from the Checker Framework added [#1494](https://github.com/diffplug/spotless/pull/1494) ### Changes +* **POTENTIALLY BREAKING** Bump minimum JRE from 8 to 11, next release likely to bump bytecode to Java 11 ([#1514](https://github.com/diffplug/spotless/pull/1514) part 1 of [#1337](https://github.com/diffplug/spotless/issues/1337)) * Rename `YamlJacksonStep` into `JacksonYamlStep` while normalizing Jackson usage ([#1492](https://github.com/diffplug/spotless/pull/1492)) ## [2.32.0] - 2023-01-13 diff --git a/plugin-gradle/CHANGES.md b/plugin-gradle/CHANGES.md index f8a6242adf..fa2119f8c5 100644 --- a/plugin-gradle/CHANGES.md +++ b/plugin-gradle/CHANGES.md @@ -10,9 +10,10 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format ( ### Fixed * The default list of type annotations used by `formatAnnotations` has had 8 more annotations from the Checker Framework added [#1494](https://github.com/diffplug/spotless/pull/1494) ### Changes +* **POTENTIALLY BREAKING** Bump minimum JRE from 8 to 11 ([#1514](https://github.com/diffplug/spotless/pull/1514) part 1 of [#1337](https://github.com/diffplug/spotless/issues/1337)) + * You can bump your build JRE without bumping your requirements ([docs](https://docs.gradle.org/current/userguide/building_java_projects.html#sec:java_cross_compilation)). * Prettier will now suggest to install plugins if a parser cannot be inferred from the file extension ([#1511](https://github.com/diffplug/spotless/pull/1511)) - ## [6.13.0] - 2023-01-14 ### Added * **POTENTIALLY BREAKING** `ktlint` step now supports `.editorconfig` ([#1442](https://github.com/diffplug/spotless/pull/1442) implements [#142](https://github.com/diffplug/spotless/issues/142)) diff --git a/plugin-maven/CHANGES.md b/plugin-maven/CHANGES.md index f1ab739b62..66ef83fb6f 100644 --- a/plugin-maven/CHANGES.md +++ b/plugin-maven/CHANGES.md @@ -12,10 +12,11 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format ( ### Fixed * The default list of type annotations used by `formatAnnotations` has had 8 more annotations from the Checker Framework added [#1494](https://github.com/diffplug/spotless/pull/1494) ### Changes +* **POTENTIALLY BREAKING** Bump minimum JRE from 8 to 11 ([#1514](https://github.com/diffplug/spotless/pull/1514) part 1 of [#1337](https://github.com/diffplug/spotless/issues/1337)) + * You can bump your build JRE without bumping your requirements ([docs](https://maven.apache.org/plugins/maven-compiler-plugin/examples/set-compiler-source-and-target.html)). * Spotless' custom build was replaced by [`maven-plugin-development`](https://github.com/britter/maven-plugin-development). ([#1496](https://github.com/diffplug/spotless/pull/1496) fixes [#554](https://github.com/diffplug/spotless/issues/554)) * Prettier will now suggest to install plugins if a parser cannot be inferred from the file extension ([#1511](https://github.com/diffplug/spotless/pull/1511)) - ## [2.30.0] - 2023-01-13 ### Added * Add option `editorConfigFile` for `ktLint` [#142](https://github.com/diffplug/spotless/issues/142) From 5955883bf5fb7bb77f8a970725040a74e8b56205 Mon Sep 17 00:00:00 2001 From: Goooler Date: Tue, 24 Jan 2023 16:12:13 +0800 Subject: [PATCH 635/757] Defer more test configurations --- _ext/eclipse-wtp/build.gradle | 2 +- _ext/gradle/java-setup.gradle | 4 +++- gradle/special-tests.gradle | 2 +- lib-extra/build.gradle | 2 +- plugin-gradle/build.gradle | 2 +- testlib/build.gradle | 2 +- 6 files changed, 8 insertions(+), 6 deletions(-) diff --git a/_ext/eclipse-wtp/build.gradle b/_ext/eclipse-wtp/build.gradle index 92a78578f6..feacfbf4c1 100644 --- a/_ext/eclipse-wtp/build.gradle +++ b/_ext/eclipse-wtp/build.gradle @@ -100,7 +100,7 @@ sourceSets { * All test classes need to run separately since they all instatiate different setups of the * Eclipse framework. */ -test { +tasks.withType(Test).configureEach { //Skip default tests, which would run every test case. exclude '**' } diff --git a/_ext/gradle/java-setup.gradle b/_ext/gradle/java-setup.gradle index 598077d73c..9572fc2955 100644 --- a/_ext/gradle/java-setup.gradle +++ b/_ext/gradle/java-setup.gradle @@ -22,4 +22,6 @@ dependencies { testImplementation project(':testlib') } -test { useJUnitPlatform() } +tasks.withType(Test).configureEach { + useJUnitPlatform() +} diff --git a/gradle/special-tests.gradle b/gradle/special-tests.gradle index c435bc7e81..fd5f602243 100644 --- a/gradle/special-tests.gradle +++ b/gradle/special-tests.gradle @@ -7,7 +7,7 @@ def special = [ ] boolean isCiServer = System.getenv().containsKey("CI") -tasks.named('test') { +tasks.withType(Test).configureEach { // See com.diffplug.spotless.tag package for available JUnit 5 @Tag annotations useJUnitPlatform { excludeTags special as String[] diff --git a/lib-extra/build.gradle b/lib-extra/build.gradle index 08bf286d8d..8381d14041 100644 --- a/lib-extra/build.gradle +++ b/lib-extra/build.gradle @@ -26,7 +26,7 @@ dependencies { spotbugs { reportLevel = 'low' } // low|medium|high (low = sensitive to even minor mistakes) apply from: rootProject.file('gradle/special-tests.gradle') -tasks.named('test') { +tasks.withType(Test).configureEach { if (JavaVersion.current().isCompatibleWith(JavaVersion.VERSION_16)) { // needed for EclipseCdtFormatterStepTest jvmArgs '--add-opens=java.base/java.lang=ALL-UNNAMED' diff --git a/plugin-gradle/build.gradle b/plugin-gradle/build.gradle index 11258db0e6..3e44335276 100644 --- a/plugin-gradle/build.gradle +++ b/plugin-gradle/build.gradle @@ -28,7 +28,7 @@ dependencies { } apply from: rootProject.file('gradle/special-tests.gradle') -tasks.named('test') { +tasks.withType(Test).configureEach { testLogging.showStandardStreams = true } diff --git a/testlib/build.gradle b/testlib/build.gradle index 64d4681805..639df8a2ab 100644 --- a/testlib/build.gradle +++ b/testlib/build.gradle @@ -22,7 +22,7 @@ dependencies { spotbugs { reportLevel = 'high' } // low|medium|high (low = sensitive to even minor mistakes) apply from: rootProject.file('gradle/special-tests.gradle') -tasks.named('test') { +tasks.withType(Test).configureEach { if (JavaVersion.current().isCompatibleWith(JavaVersion.VERSION_16)) { // for Antlr4FormatterStepTest and KtLintStepTest def args = [ From c4df046be318e7a780a7e3b9ba100ceb62d1be3a Mon Sep 17 00:00:00 2001 From: Goooler Date: Tue, 24 Jan 2023 16:43:18 +0800 Subject: [PATCH 636/757] Let check depend on version compatibility tasks https://github.com/davidburstrom/version-compatibility-gradle-plugin#lifecycle-tasks --- lib/build.gradle | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/lib/build.gradle b/lib/build.gradle index 30c8fe8b15..0b42c7bcc1 100644 --- a/lib/build.gradle +++ b/lib/build.gradle @@ -42,6 +42,11 @@ versionCompatibility { } } +tasks.named("check").configure { + dependsOn(tasks.named("testCompatibilityAdapters")) + dependsOn(tasks.named("testCompatibility")) +} + dependencies { compileOnly 'org.slf4j:slf4j-api:2.0.0' // zero runtime reqs is a hard requirements for spotless-lib From 057f6c42a0dbbe61f7a77ec14828a7f233e6b250 Mon Sep 17 00:00:00 2001 From: Goooler Date: Tue, 24 Jan 2023 17:09:22 +0800 Subject: [PATCH 637/757] Make KtLintCompat0Dot48Dot0AdapterTest workable https://github.com/pinterest/ktlint/blob/2642124cfec306050dd0258870a16dc95aaa106c/build-logic/src/main/kotlin/ToolchainForTests.kt#L16-L35 --- lib/build.gradle | 17 +++++++++++++++++ .../KtLintCompat0Dot48Dot0AdapterTest.java | 7 +++++-- 2 files changed, 22 insertions(+), 2 deletions(-) diff --git a/lib/build.gradle b/lib/build.gradle index 0b42c7bcc1..1a112c78cc 100644 --- a/lib/build.gradle +++ b/lib/build.gradle @@ -119,6 +119,23 @@ dependencies { spotbugs { reportLevel = 'low' } // low|medium|high (low = sensitive to even minor mistakes) apply from: rootProject.file('gradle/special-tests.gradle') +tasks.withType(Test).configureEach { + def jdkVersion = JavaVersion.current().majorVersion.toInteger() + def args = [] + if (jdkVersion >= 16) { + // https://docs.gradle.org/7.5/userguide/upgrading_version_7.html#removes_implicit_add_opens_for_test_workers + args += [ + "--add-opens=java.base/java.lang=ALL-UNNAMED", + "--add-opens=java.base/java.util=ALL-UNNAMED", + ] + } + if (jdkVersion >= 18) { + // https://openjdk.org/jeps/411 + args += "-Djava.security.manager=allow" + } + jvmArgs(args) +} + jar { for (glue in NEEDS_GLUE) { from sourceSets.getByName(glue).output.classesDirs diff --git a/lib/src/testCompatKtLint0Dot48Dot0/java/com/diffplug/spotless/glue/ktlint/compat/KtLintCompat0Dot48Dot0AdapterTest.java b/lib/src/testCompatKtLint0Dot48Dot0/java/com/diffplug/spotless/glue/ktlint/compat/KtLintCompat0Dot48Dot0AdapterTest.java index 6825b3d818..8804f86b08 100644 --- a/lib/src/testCompatKtLint0Dot48Dot0/java/com/diffplug/spotless/glue/ktlint/compat/KtLintCompat0Dot48Dot0AdapterTest.java +++ b/lib/src/testCompatKtLint0Dot48Dot0/java/com/diffplug/spotless/glue/ktlint/compat/KtLintCompat0Dot48Dot0AdapterTest.java @@ -22,6 +22,7 @@ import java.nio.charset.StandardCharsets; import java.nio.file.Files; import java.nio.file.Path; +import java.nio.file.Paths; import java.util.HashMap; import java.util.Map; @@ -33,12 +34,13 @@ public class KtLintCompat0Dot48Dot0AdapterTest { public void testDefaults(@TempDir Path path) throws IOException { KtLintCompat0Dot48Dot0Adapter ktLintCompat0Dot48Dot0Adapter = new KtLintCompat0Dot48Dot0Adapter(); String text = loadAndWriteText(path, "empty_class_body.kt"); + final Path filePath = Paths.get(path.toString(), "empty_class_body.kt"); Map userData = new HashMap<>(); Map editorConfigOverrideMap = new HashMap<>(); - String formatted = ktLintCompat0Dot48Dot0Adapter.format(text, path, false, false, null, userData, editorConfigOverrideMap); + String formatted = ktLintCompat0Dot48Dot0Adapter.format(text, filePath, false, false, null, userData, editorConfigOverrideMap); assertEquals("class empty_class_body\n", formatted); } @@ -46,6 +48,7 @@ public void testDefaults(@TempDir Path path) throws IOException { public void testEditorConfigCanDisable(@TempDir Path path) throws IOException { KtLintCompat0Dot48Dot0Adapter ktLintCompat0Dot48Dot0Adapter = new KtLintCompat0Dot48Dot0Adapter(); String text = loadAndWriteText(path, "fails_no_semicolons.kt"); + final Path filePath = Paths.get(path.toString(), "fails_no_semicolons.kt"); Map userData = new HashMap<>(); @@ -53,7 +56,7 @@ public void testEditorConfigCanDisable(@TempDir Path path) throws IOException { editorConfigOverrideMap.put("indent_style", "tab"); editorConfigOverrideMap.put("ktlint_standard_no-semi", "disabled"); - String formatted = ktLintCompat0Dot48Dot0Adapter.format(text, path, false, false, null, userData, editorConfigOverrideMap); + String formatted = ktLintCompat0Dot48Dot0Adapter.format(text, filePath, false, false, null, userData, editorConfigOverrideMap); assertEquals("class fails_no_semicolons {\n\tval i = 0;\n}\n", formatted); } From e6b290084e7b1e40a031ae4c1cf954aeef7b5cc9 Mon Sep 17 00:00:00 2001 From: Goooler Date: Tue, 24 Jan 2023 23:13:36 +0800 Subject: [PATCH 638/757] Cleanup usages of gradle/gradle-build-action - Remove cache from actions/setup-java. - Enable gradle-home-cache-cleanup flag, see https://github.com/gradle/gradle-build-action/blob/main/README.md#removing-unused-files-from-gradle-user-home-before-saving-to-cache. --- .github/workflows/changelog-print.yml | 3 ++- .github/workflows/ci.yml | 10 ++++++++-- .github/workflows/deploy.yml | 3 ++- 3 files changed, 12 insertions(+), 4 deletions(-) diff --git a/.github/workflows/changelog-print.yml b/.github/workflows/changelog-print.yml index 330f78cda0..a3009e3a39 100644 --- a/.github/workflows/changelog-print.yml +++ b/.github/workflows/changelog-print.yml @@ -15,7 +15,8 @@ jobs: with: java-version: 11 distribution: 'temurin' - cache: 'gradle' - name: gradle caching uses: gradle/gradle-build-action@v2 + with: + gradle-home-cache-cleanup: true - run: ./gradlew changelogPrint diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 1f08c201f5..86cf955059 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -26,7 +26,10 @@ jobs: with: distribution: "temurin" java-version: 11 - cache: gradle + - name: gradle caching + uses: gradle/gradle-build-action@v2 + with: + gradle-home-cache-cleanup: true - name: spotlessCheck run: ./gradlew spotlessCheck --build-cache - name: assemble testClasses @@ -60,7 +63,10 @@ jobs: with: distribution: "temurin" java-version: ${{ matrix.jre }} - cache: gradle + - name: gradle caching + uses: gradle/gradle-build-action@v2 + with: + gradle-home-cache-cleanup: true - name: build (maven-only) if: matrix.kind == 'maven' run: ./gradlew :plugin-maven:build -x spotlessCheck --build-cache diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml index 9a1dcdf609..d41dc8fc30 100644 --- a/.github/workflows/deploy.yml +++ b/.github/workflows/deploy.yml @@ -42,9 +42,10 @@ jobs: with: java-version: 11 distribution: 'temurin' - cache: 'gradle' - name: gradle caching uses: gradle/gradle-build-action@v2 + with: + gradle-home-cache-cleanup: true - name: publish all if: "${{ github.event.inputs.to_publish == 'all' }}" run: | From 8be92ffc42d6beb9a62397b9d0d9cccb075e9b90 Mon Sep 17 00:00:00 2001 From: Goooler Date: Tue, 24 Jan 2023 23:17:01 +0800 Subject: [PATCH 639/757] Mark bat files end with CRLF --- .gitattributes | 1 + 1 file changed, 1 insertion(+) diff --git a/.gitattributes b/.gitattributes index e6141d8894..dc4cb6b0bd 100644 --- a/.gitattributes +++ b/.gitattributes @@ -1,3 +1,4 @@ * text eol=lf +*.bat eol=crlf *.png binary *.jar binary From 92b3cf85596384115ea04d41a039b5e3c47bfb7f Mon Sep 17 00:00:00 2001 From: Abel Keszei Date: Tue, 24 Jan 2023 21:17:32 +0100 Subject: [PATCH 640/757] keep old signature of GsonStep.create() and restore GsonConfig classname --- .../diffplug/spotless/json/gson/GsonStep.java | 5 +++++ .../gradle/spotless/JsonExtension.java | 19 +++++++++---------- 2 files changed, 14 insertions(+), 10 deletions(-) diff --git a/lib/src/main/java/com/diffplug/spotless/json/gson/GsonStep.java b/lib/src/main/java/com/diffplug/spotless/json/gson/GsonStep.java index 03baec5104..ec90255b77 100644 --- a/lib/src/main/java/com/diffplug/spotless/json/gson/GsonStep.java +++ b/lib/src/main/java/com/diffplug/spotless/json/gson/GsonStep.java @@ -30,6 +30,11 @@ public class GsonStep { private static final String MAVEN_COORDINATES = "com.google.code.gson:gson"; private static final String INCOMPATIBLE_ERROR_MESSAGE = "There was a problem interacting with Gson; maybe you set an incompatible version?"; + @Deprecated + public static FormatterStep create(int indentSpaces, boolean sortByKeys, boolean escapeHtml, String version, Provisioner provisioner) { + return create(new GsonConfig(sortByKeys, escapeHtml, indentSpaces, version), provisioner); + } + public static FormatterStep create(GsonConfig gsonConfig, Provisioner provisioner) { Objects.requireNonNull(provisioner, "provisioner cannot be null"); return FormatterStep.createLazy("gson", () -> new State(gsonConfig, provisioner), State::toFormatter); diff --git a/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/JsonExtension.java b/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/JsonExtension.java index c684dab291..39b158ce1e 100644 --- a/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/JsonExtension.java +++ b/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/JsonExtension.java @@ -23,7 +23,6 @@ import com.diffplug.spotless.json.JacksonJsonConfig; import com.diffplug.spotless.json.JacksonJsonStep; import com.diffplug.spotless.json.JsonSimpleStep; -import com.diffplug.spotless.json.gson.GsonConfig; import com.diffplug.spotless.json.gson.GsonStep; public class JsonExtension extends FormatExtension { @@ -48,8 +47,8 @@ public SimpleConfig simple() { return new SimpleConfig(DEFAULT_INDENTATION); } - public GsonGradleConfig gson() { - return new GsonGradleConfig(); + public GsonConfig gson() { + return new GsonConfig(); } public JacksonJsonGradleConfig jackson() { @@ -74,13 +73,13 @@ private FormatterStep createStep() { } } - public class GsonGradleConfig { + public class GsonConfig { private int indentSpaces; private boolean sortByKeys; private boolean escapeHtml; private String version; - public GsonGradleConfig() { + public GsonConfig() { this.indentSpaces = DEFAULT_INDENTATION; this.sortByKeys = false; this.escapeHtml = false; @@ -88,32 +87,32 @@ public GsonGradleConfig() { addStep(createStep()); } - public GsonGradleConfig indentWithSpaces(int indentSpaces) { + public GsonConfig indentWithSpaces(int indentSpaces) { this.indentSpaces = indentSpaces; replaceStep(createStep()); return this; } - public GsonGradleConfig sortByKeys() { + public GsonConfig sortByKeys() { this.sortByKeys = true; replaceStep(createStep()); return this; } - public GsonGradleConfig escapeHtml() { + public GsonConfig escapeHtml() { this.escapeHtml = true; replaceStep(createStep()); return this; } - public GsonGradleConfig version(String version) { + public GsonConfig version(String version) { this.version = version; replaceStep(createStep()); return this; } private FormatterStep createStep() { - return GsonStep.create(new GsonConfig(sortByKeys, escapeHtml, indentSpaces, version), provisioner()); + return GsonStep.create(new com.diffplug.spotless.json.gson.GsonConfig(sortByKeys, escapeHtml, indentSpaces, version), provisioner()); } } From 9982c3a7f30cd3a12467f9fb7f18fde6b155a815 Mon Sep 17 00:00:00 2001 From: Eir Nym <485399+eirnym@users.noreply.github.com> Date: Wed, 25 Jan 2023 02:08:01 +0100 Subject: [PATCH 641/757] Drop some old tests --- .../spotless/kotlin/KtLintStepTest.java | 62 ------------------- 1 file changed, 62 deletions(-) diff --git a/testlib/src/test/java/com/diffplug/spotless/kotlin/KtLintStepTest.java b/testlib/src/test/java/com/diffplug/spotless/kotlin/KtLintStepTest.java index 1be0c7b72f..f69d038b6a 100644 --- a/testlib/src/test/java/com/diffplug/spotless/kotlin/KtLintStepTest.java +++ b/testlib/src/test/java/com/diffplug/spotless/kotlin/KtLintStepTest.java @@ -37,68 +37,6 @@ void behavior() { "Wildcard import"); } - @Test - void worksShyiko() { - FormatterStep step = KtLintStep.create("0.31.0", TestProvisioner.mavenCentral()); - StepHarnessWithFile.forStep(this, step) - .testResource("kotlin/ktlint/basic.dirty", "kotlin/ktlint/basic.clean") - .testResourceExceptionMsg("kotlin/ktlint/unsolvable.dirty").isEqualTo( - "Error on line: 1, column: 1\n" + - "rule: no-wildcard-imports\n" + - "Wildcard import"); - } - - // Regression test to ensure it works on the version it switched to Pinterest (version 0.32.0) - // but before 0.34. - // https://github.com/diffplug/spotless/issues/419 - @Test - void worksPinterestAndPre034() { - FormatterStep step = KtLintStep.create("0.32.0", TestProvisioner.mavenCentral()); - StepHarnessWithFile.forStep(this, step) - .testResource("kotlin/ktlint/basic.dirty", "kotlin/ktlint/basic.clean") - .testResourceExceptionMsg("kotlin/ktlint/unsolvable.dirty").isEqualTo("Error on line: 1, column: 1\n" + - "rule: no-wildcard-imports\n" + - "Wildcard import"); - } - - // Regression test to handle alpha and 1.x version numbers - // https://github.com/diffplug/spotless/issues/668 - @Test - void worksAlpha1() { - FormatterStep step = KtLintStep.create("0.38.0-alpha01", TestProvisioner.mavenCentral()); - StepHarness.forStep(step) - .testResource("kotlin/ktlint/basic.dirty", "kotlin/ktlint/basic.clean"); - } - - @Test - void works0_44_0() { - FormatterStep step = KtLintStep.create("0.44.0", TestProvisioner.mavenCentral()); - StepHarness.forStep(step) - .testResource("kotlin/ktlint/basic.dirty", "kotlin/ktlint/basic.clean"); - } - - @Disabled("https://github.com/pinterest/ktlint/issues/1421") - @Test - void works0_45_0() { - FormatterStep step = KtLintStep.create("0.45.0", TestProvisioner.mavenCentral()); - StepHarness.forStep(step) - .testResource("kotlin/ktlint/basic.dirty", "kotlin/ktlint/basic.clean"); - } - - @Test - void works0_45_1() { - FormatterStep step = KtLintStep.create("0.45.1", TestProvisioner.mavenCentral()); - StepHarness.forStep(step) - .testResource("kotlin/ktlint/basic.dirty", "kotlin/ktlint/basic.clean"); - } - - @Test - void works0_45_2() { - FormatterStep step = KtLintStep.create("0.45.2", TestProvisioner.mavenCentral()); - StepHarness.forStep(step) - .testResource("kotlin/ktlint/basic.dirty", "kotlin/ktlint/basic.clean"); - } - @Test void works0_46_0() { FormatterStep step = KtLintStep.create("0.46.0", TestProvisioner.mavenCentral()); From aab121d345486bbc4a9eaf8ac9d4ef3bd1417622 Mon Sep 17 00:00:00 2001 From: Eir Nym <485399+eirnym@users.noreply.github.com> Date: Wed, 25 Jan 2023 02:14:48 +0100 Subject: [PATCH 642/757] Remove stale imports --- .../test/java/com/diffplug/spotless/kotlin/KtLintStepTest.java | 2 -- 1 file changed, 2 deletions(-) diff --git a/testlib/src/test/java/com/diffplug/spotless/kotlin/KtLintStepTest.java b/testlib/src/test/java/com/diffplug/spotless/kotlin/KtLintStepTest.java index f69d038b6a..3047245298 100644 --- a/testlib/src/test/java/com/diffplug/spotless/kotlin/KtLintStepTest.java +++ b/testlib/src/test/java/com/diffplug/spotless/kotlin/KtLintStepTest.java @@ -15,13 +15,11 @@ */ package com.diffplug.spotless.kotlin; -import org.junit.jupiter.api.Disabled; import org.junit.jupiter.api.Test; import com.diffplug.spotless.FormatterStep; import com.diffplug.spotless.ResourceHarness; import com.diffplug.spotless.SerializableEqualityTester; -import com.diffplug.spotless.StepHarness; import com.diffplug.spotless.StepHarnessWithFile; import com.diffplug.spotless.TestProvisioner; From a35e23b400ac05d187b4c144a1d2ff0b2f83c88a Mon Sep 17 00:00:00 2001 From: Goooler Date: Wed, 25 Jan 2023 09:44:15 +0800 Subject: [PATCH 643/757] Enable Gradle's build scan --- settings.gradle | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/settings.gradle b/settings.gradle index fb9e7dcf0b..ca48729297 100644 --- a/settings.gradle +++ b/settings.gradle @@ -29,6 +29,7 @@ plugins { id 'org.gradle.test-retry' apply false id 'com.adarshr.test-logger' apply false id 'io.github.davidburstrom.version-compatibility' apply false + id "com.gradle.enterprise" version "3.12.2" } if (System.env['CI'] != null) { // use the remote buildcache on all CI builds @@ -58,6 +59,14 @@ if (System.env['CI'] != null) { } } +gradleEnterprise { + buildScan { + termsOfServiceUrl = "https://gradle.com/terms-of-service" + termsOfServiceAgree = "yes" + publishAlways() + } +} + rootProject.name = 'spotless' include 'lib' // reusable library with no dependencies From 27629933ab7dcd9d95c008735e789f5a46620b65 Mon Sep 17 00:00:00 2001 From: Goooler Date: Thu, 19 Jan 2023 00:12:18 +0800 Subject: [PATCH 644/757] Generate the correct qualifiedRuleId for Ktlint 0.48.x --- .../glue/ktlint/compat/KtLintCompat0Dot48Dot0Adapter.java | 2 +- .../glue/ktlint/compat/KtLintCompat0Dot48Dot0AdapterTest.java | 2 ++ plugin-gradle/CHANGES.md | 1 + plugin-maven/CHANGES.md | 1 + 4 files changed, 5 insertions(+), 1 deletion(-) diff --git a/lib/src/compatKtLint0Dot48Dot0/java/com/diffplug/spotless/glue/ktlint/compat/KtLintCompat0Dot48Dot0Adapter.java b/lib/src/compatKtLint0Dot48Dot0/java/com/diffplug/spotless/glue/ktlint/compat/KtLintCompat0Dot48Dot0Adapter.java index 5d24603f70..1e54a80859 100644 --- a/lib/src/compatKtLint0Dot48Dot0/java/com/diffplug/spotless/glue/ktlint/compat/KtLintCompat0Dot48Dot0Adapter.java +++ b/lib/src/compatKtLint0Dot48Dot0/java/com/diffplug/spotless/glue/ktlint/compat/KtLintCompat0Dot48Dot0Adapter.java @@ -140,7 +140,7 @@ private static EditorConfigOverride createEditorConfigOverride(final List String[] parts = entry.getKey().substring(7).split("_", 2); if (parts.length == 1) { // convert ktlint_{ruleset} to {ruleset} - String qualifiedRuleId = parts[0]; + String qualifiedRuleId = parts[0] + ":"; property = RuleExecutionEditorConfigPropertyKt.createRuleSetExecutionEditorConfigProperty(qualifiedRuleId); } else { // convert ktlint_{ruleset}_{rulename} to {ruleset}:{rulename} diff --git a/lib/src/testCompatKtLint0Dot48Dot0/java/com/diffplug/spotless/glue/ktlint/compat/KtLintCompat0Dot48Dot0AdapterTest.java b/lib/src/testCompatKtLint0Dot48Dot0/java/com/diffplug/spotless/glue/ktlint/compat/KtLintCompat0Dot48Dot0AdapterTest.java index 8804f86b08..c811b51233 100644 --- a/lib/src/testCompatKtLint0Dot48Dot0/java/com/diffplug/spotless/glue/ktlint/compat/KtLintCompat0Dot48Dot0AdapterTest.java +++ b/lib/src/testCompatKtLint0Dot48Dot0/java/com/diffplug/spotless/glue/ktlint/compat/KtLintCompat0Dot48Dot0AdapterTest.java @@ -55,6 +55,8 @@ public void testEditorConfigCanDisable(@TempDir Path path) throws IOException { Map editorConfigOverrideMap = new HashMap<>(); editorConfigOverrideMap.put("indent_style", "tab"); editorConfigOverrideMap.put("ktlint_standard_no-semi", "disabled"); + // ktlint_filename is an invalid rule in ktlint 0.48.0 + editorConfigOverrideMap.put("ktlint_filename", "disabled"); String formatted = ktLintCompat0Dot48Dot0Adapter.format(text, filePath, false, false, null, userData, editorConfigOverrideMap); assertEquals("class fails_no_semicolons {\n\tval i = 0;\n}\n", formatted); diff --git a/plugin-gradle/CHANGES.md b/plugin-gradle/CHANGES.md index 17bf123b41..37d08f9b75 100644 --- a/plugin-gradle/CHANGES.md +++ b/plugin-gradle/CHANGES.md @@ -10,6 +10,7 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format ( * Prettier will now suggest to install plugins if a parser cannot be inferred from the file extension ([#1511](https://github.com/diffplug/spotless/pull/1511)) ### Fixed * The default list of type annotations used by `formatAnnotations` has had 8 more annotations from the Checker Framework added [#1494](https://github.com/diffplug/spotless/pull/1494) +* **POTENTIALLY BREAKING** Generate the correct qualifiedRuleId for Ktlint 0.48.x [#1495](https://github.com/diffplug/spotless/pull/1495) ### Changes * **POTENTIALLY BREAKING** Removed support for KtLint 0.3x and 0.45.2 ([#1475](https://github.com/diffplug/spotless/pull/1475)) * `KtLint` does not maintain a stable API - before this PR, we supported every breaking change in the API since 2019. diff --git a/plugin-maven/CHANGES.md b/plugin-maven/CHANGES.md index 448011be3c..2a23405d35 100644 --- a/plugin-maven/CHANGES.md +++ b/plugin-maven/CHANGES.md @@ -11,6 +11,7 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format ( * Allow to specify node executable for node-based formatters using `nodeExecutable` parameter ([#1500](https://github.com/diffplug/spotless/pull/1500)) ### Fixed * The default list of type annotations used by `formatAnnotations` has had 8 more annotations from the Checker Framework added [#1494](https://github.com/diffplug/spotless/pull/1494) +* **POTENTIALLY BREAKING** Generate the correct qualifiedRuleId for Ktlint 0.48.x [#1495](https://github.com/diffplug/spotless/pull/1495) ### Changes * Spotless' custom build was replaced by [`maven-plugin-development`](https://github.com/britter/maven-plugin-development). ([#1496](https://github.com/diffplug/spotless/pull/1496) fixes [#554](https://github.com/diffplug/spotless/issues/554)) * Prettier will now suggest to install plugins if a parser cannot be inferred from the file extension ([#1511](https://github.com/diffplug/spotless/pull/1511)) From 70ad96cd566396097e53520f3ebf8b2aa32011b9 Mon Sep 17 00:00:00 2001 From: Simon Gamma Date: Tue, 24 Jan 2023 16:48:14 +0100 Subject: [PATCH 645/757] 1499: delay npmInstall and npmExec resolution to enable interoperability with `node-gradle-plugin` --- .../spotless/npm/EslintFormatterStep.java | 32 +++++++------ .../npm/NpmFormatterStepLocations.java | 11 +++-- .../npm/NpmFormatterStepStateBase.java | 47 ++++++++++--------- .../spotless/npm/PrettierFormatterStep.java | 4 +- .../spotless/npm/TsFmtFormatterStep.java | 4 +- .../NpmTestsWithoutNpmInstallationTest.java | 3 -- 6 files changed, 53 insertions(+), 48 deletions(-) diff --git a/lib/src/main/java/com/diffplug/spotless/npm/EslintFormatterStep.java b/lib/src/main/java/com/diffplug/spotless/npm/EslintFormatterStep.java index 74979d90aa..2a095e9ad7 100644 --- a/lib/src/main/java/com/diffplug/spotless/npm/EslintFormatterStep.java +++ b/lib/src/main/java/com/diffplug/spotless/npm/EslintFormatterStep.java @@ -81,7 +81,9 @@ public static FormatterStep create(Map devDependencies, Provisio private static class State extends NpmFormatterStepStateBase implements Serializable { private static final long serialVersionUID = -539537027004745812L; - private final EslintConfig eslintConfig; + private final EslintConfig origEslintConfig; + + private transient EslintConfig eslintConfigInUse; State(String stepName, Map devDependencies, File projectDir, File buildDir, NpmPathResolver npmPathResolver, EslintConfig eslintConfig) throws IOException { super(stepName, @@ -97,21 +99,23 @@ private static class State extends NpmFormatterStepStateBase implements Serializ new NpmFormatterStepLocations( projectDir, buildDir, - npmPathResolver.resolveNpmExecutable(), - npmPathResolver.resolveNodeExecutable())); - this.eslintConfig = localCopyFiles(requireNonNull(eslintConfig)); + npmPathResolver::resolveNpmExecutable, + npmPathResolver::resolveNodeExecutable)); + this.origEslintConfig = requireNonNull(eslintConfig.verify()); + this.eslintConfigInUse = eslintConfig; } - private EslintConfig localCopyFiles(EslintConfig orig) { - if (orig.getEslintConfigPath() == null) { - return orig.verify(); + @Override + protected void prepareNodeServerLayout() throws IOException { + super.prepareNodeServerLayout(); + if (origEslintConfig.getEslintConfigPath() != null) { + // If any config files are provided, we need to make sure they are at the same location as the node modules + // as eslint will try to resolve plugin/config names relatively to the config file location and some + // eslint configs contain relative paths to additional config files (such as tsconfig.json e.g.) + FormattedPrinter.SYSOUT.print("Copying config file <%s> to <%s> and using the copy", origEslintConfig.getEslintConfigPath(), nodeServerLayout.nodeModulesDir()); + File configFileCopy = NpmResourceHelper.copyFileToDir(origEslintConfig.getEslintConfigPath(), nodeServerLayout.nodeModulesDir()); + this.eslintConfigInUse = this.origEslintConfig.withEslintConfigPath(configFileCopy).verify(); } - // If any config files are provided, we need to make sure they are at the same location as the node modules - // as eslint will try to resolve plugin/config names relatively to the config file location and some - // eslint configs contain relative paths to additional config files (such as tsconfig.json e.g.) - FormattedPrinter.SYSOUT.print("Copying config file <%s> to <%s> and using the copy", orig.getEslintConfigPath(), nodeModulesDir); - File configFileCopy = NpmResourceHelper.copyFileToDir(orig.getEslintConfigPath(), nodeModulesDir); - return orig.withEslintConfigPath(configFileCopy).verify(); } @Override @@ -121,7 +125,7 @@ public FormatterFunc createFormatterFunc() { FormattedPrinter.SYSOUT.print("creating formatter function (starting server)"); ServerProcessInfo eslintRestServer = npmRunServer(); EslintRestService restService = new EslintRestService(eslintRestServer.getBaseUrl()); - return Closeable.ofDangerous(() -> endServer(restService, eslintRestServer), new EslintFilePathPassingFormatterFunc(locations.projectDir(), nodeModulesDir, eslintConfig, restService)); + return Closeable.ofDangerous(() -> endServer(restService, eslintRestServer), new EslintFilePathPassingFormatterFunc(locations.projectDir(), nodeServerLayout.nodeModulesDir(), eslintConfigInUse, restService)); } catch (IOException e) { throw ThrowingEx.asRuntime(e); } diff --git a/lib/src/main/java/com/diffplug/spotless/npm/NpmFormatterStepLocations.java b/lib/src/main/java/com/diffplug/spotless/npm/NpmFormatterStepLocations.java index 0c417733e8..0e99e1afab 100644 --- a/lib/src/main/java/com/diffplug/spotless/npm/NpmFormatterStepLocations.java +++ b/lib/src/main/java/com/diffplug/spotless/npm/NpmFormatterStepLocations.java @@ -19,6 +19,7 @@ import java.io.File; import java.io.Serializable; +import java.util.function.Supplier; import edu.umd.cs.findbugs.annotations.SuppressFBWarnings; @@ -32,12 +33,12 @@ class NpmFormatterStepLocations implements Serializable { private final transient File buildDir; @SuppressFBWarnings("SE_TRANSIENT_FIELD_NOT_RESTORED") - private final transient File npmExecutable; + private final transient Supplier npmExecutable; @SuppressFBWarnings("SE_TRANSIENT_FIELD_NOT_RESTORED") - private final transient File nodeExecutable; + private final transient Supplier nodeExecutable; - public NpmFormatterStepLocations(File projectDir, File buildDir, File npmExecutable, File nodeExecutable) { + public NpmFormatterStepLocations(File projectDir, File buildDir, Supplier npmExecutable, Supplier nodeExecutable) { this.projectDir = requireNonNull(projectDir); this.buildDir = requireNonNull(buildDir); this.npmExecutable = requireNonNull(npmExecutable); @@ -53,10 +54,10 @@ public File buildDir() { } public File npmExecutable() { - return npmExecutable; + return npmExecutable.get(); } public File nodeExecutable() { - return nodeExecutable; + return nodeExecutable.get(); } } diff --git a/lib/src/main/java/com/diffplug/spotless/npm/NpmFormatterStepStateBase.java b/lib/src/main/java/com/diffplug/spotless/npm/NpmFormatterStepStateBase.java index 4f555a177e..996400ce33 100644 --- a/lib/src/main/java/com/diffplug/spotless/npm/NpmFormatterStepStateBase.java +++ b/lib/src/main/java/com/diffplug/spotless/npm/NpmFormatterStepStateBase.java @@ -31,7 +31,6 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import com.diffplug.spotless.FileSignature; import com.diffplug.spotless.FormatterFunc; import edu.umd.cs.findbugs.annotations.SuppressFBWarnings; @@ -42,11 +41,8 @@ abstract class NpmFormatterStepStateBase implements Serializable { private static final long serialVersionUID = 1460749955865959948L; - @SuppressWarnings("unused") - private final FileSignature packageJsonSignature; - @SuppressFBWarnings("SE_TRANSIENT_FIELD_NOT_RESTORED") - public final transient File nodeModulesDir; + protected final transient NodeServerLayout nodeServerLayout; public final NpmFormatterStepLocations locations; @@ -58,45 +54,52 @@ protected NpmFormatterStepStateBase(String stepName, NpmConfig npmConfig, NpmFor this.stepName = requireNonNull(stepName); this.npmConfig = requireNonNull(npmConfig); this.locations = locations; - NodeServerLayout layout = prepareNodeServer(locations.buildDir()); - this.nodeModulesDir = layout.nodeModulesDir(); - this.packageJsonSignature = FileSignature.signAsList(layout.packageJsonFile()); + this.nodeServerLayout = new NodeServerLayout(locations.buildDir(), stepName); } - private NodeServerLayout prepareNodeServer(File buildDir) throws IOException { - NodeServerLayout layout = new NodeServerLayout(buildDir, stepName); - NpmResourceHelper.assertDirectoryExists(layout.nodeModulesDir()); - NpmResourceHelper.writeUtf8StringToFile(layout.packageJsonFile(), + protected void prepareNodeServerLayout() throws IOException { + NpmResourceHelper.assertDirectoryExists(nodeServerLayout.nodeModulesDir()); + NpmResourceHelper.writeUtf8StringToFile(nodeServerLayout.packageJsonFile(), this.npmConfig.getPackageJsonContent()); NpmResourceHelper - .writeUtf8StringToFile(layout.serveJsFile(), this.npmConfig.getServeScriptContent()); + .writeUtf8StringToFile(nodeServerLayout.serveJsFile(), this.npmConfig.getServeScriptContent()); if (this.npmConfig.getNpmrcContent() != null) { - NpmResourceHelper.writeUtf8StringToFile(layout.npmrcFile(), this.npmConfig.getNpmrcContent()); + NpmResourceHelper.writeUtf8StringToFile(nodeServerLayout.npmrcFile(), this.npmConfig.getNpmrcContent()); } else { - NpmResourceHelper.deleteFileIfExists(layout.npmrcFile()); + NpmResourceHelper.deleteFileIfExists(nodeServerLayout.npmrcFile()); } + } + + protected void prepareNodeServer() throws IOException { FormattedPrinter.SYSOUT.print("running npm install"); - runNpmInstall(layout.nodeModulesDir()); + runNpmInstall(nodeServerLayout.nodeModulesDir()); FormattedPrinter.SYSOUT.print("npm install finished"); - return layout; } private void runNpmInstall(File npmProjectDir) throws IOException { new NpmProcess(npmProjectDir, this.locations.npmExecutable(), this.locations.nodeExecutable()).install(); } - protected ServerProcessInfo npmRunServer() throws ServerStartException, IOException { - if (!this.nodeModulesDir.exists()) { - prepareNodeServer(NodeServerLayout.getBuildDirFromNodeModulesDir(this.nodeModulesDir)); + protected void assertNodeServerDirReady() throws IOException { + if (!this.nodeServerLayout.nodeModulesDir().exists() || !this.nodeServerLayout.packageJsonFile().isFile()) { + // reinstall if missing + prepareNodeServerLayout(); } + if (!new File(this.nodeServerLayout.nodeModulesDir(), "node_modules").isDirectory()) { + // run npm install if node_modules is missing + prepareNodeServer(); + } + } + protected ServerProcessInfo npmRunServer() throws ServerStartException, IOException { + assertNodeServerDirReady(); try { // The npm process will output the randomly selected port of the http server process to 'server.port' file // so in order to be safe, remove such a file if it exists before starting. - final File serverPortFile = new File(this.nodeModulesDir, "server.port"); + final File serverPortFile = new File(this.nodeServerLayout.nodeModulesDir(), "server.port"); NpmResourceHelper.deleteFileIfExists(serverPortFile); // start the http server in node - Process server = new NpmProcess(this.nodeModulesDir, this.locations.npmExecutable(), this.locations.nodeExecutable()).start(); + Process server = new NpmProcess(this.nodeServerLayout.nodeModulesDir(), this.locations.npmExecutable(), this.locations.nodeExecutable()).start(); // await the readiness of the http server - wait for at most 60 seconds try { diff --git a/lib/src/main/java/com/diffplug/spotless/npm/PrettierFormatterStep.java b/lib/src/main/java/com/diffplug/spotless/npm/PrettierFormatterStep.java index 22dd4586ee..22f1a69e7c 100644 --- a/lib/src/main/java/com/diffplug/spotless/npm/PrettierFormatterStep.java +++ b/lib/src/main/java/com/diffplug/spotless/npm/PrettierFormatterStep.java @@ -77,8 +77,8 @@ private static class State extends NpmFormatterStepStateBase implements Serializ new NpmFormatterStepLocations( projectDir, buildDir, - npmPathResolver.resolveNpmExecutable(), - npmPathResolver.resolveNodeExecutable())); + npmPathResolver::resolveNpmExecutable, + npmPathResolver::resolveNodeExecutable)); this.prettierConfig = requireNonNull(prettierConfig); } diff --git a/lib/src/main/java/com/diffplug/spotless/npm/TsFmtFormatterStep.java b/lib/src/main/java/com/diffplug/spotless/npm/TsFmtFormatterStep.java index 14d6b1bbd0..4bd665c764 100644 --- a/lib/src/main/java/com/diffplug/spotless/npm/TsFmtFormatterStep.java +++ b/lib/src/main/java/com/diffplug/spotless/npm/TsFmtFormatterStep.java @@ -83,8 +83,8 @@ public State(String stepName, Map versions, File projectDir, Fil new NpmFormatterStepLocations( projectDir, buildDir, - npmPathResolver.resolveNpmExecutable(), - npmPathResolver.resolveNodeExecutable())); + npmPathResolver::resolveNpmExecutable, + npmPathResolver::resolveNodeExecutable)); this.buildDir = requireNonNull(buildDir); this.configFile = configFile; this.inlineTsFmtSettings = inlineTsFmtSettings == null ? new TreeMap<>() : new TreeMap<>(inlineTsFmtSettings); diff --git a/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/NpmTestsWithoutNpmInstallationTest.java b/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/NpmTestsWithoutNpmInstallationTest.java index 916d853920..986e2726cb 100644 --- a/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/NpmTestsWithoutNpmInstallationTest.java +++ b/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/NpmTestsWithoutNpmInstallationTest.java @@ -17,7 +17,6 @@ import org.assertj.core.api.Assertions; import org.gradle.testkit.runner.BuildResult; -import org.junit.jupiter.api.Disabled; import org.junit.jupiter.api.Test; import com.diffplug.common.base.Predicates; @@ -74,8 +73,6 @@ private void printContents() { } @Test - @Disabled("This test is disabled because we currently don't support using npm/node installed by the" + - "node-gradle-plugin as the installation takes place in the *execution* phase, but spotless needs it in the *configuration* phase.") void useNodeAndNpmFromNodeGradlePluginInOneSweep() throws Exception { try { setFile("build.gradle").toLines( From fac7fd1ece0887111e06a2b24def6b24d1cee77c Mon Sep 17 00:00:00 2001 From: Simon Gamma Date: Tue, 24 Jan 2023 19:51:51 +0100 Subject: [PATCH 646/757] 1499: document changes for delaying npm install --- CHANGES.md | 2 ++ plugin-gradle/CHANGES.md | 3 +++ plugin-maven/CHANGES.md | 1 + 3 files changed, 6 insertions(+) diff --git a/CHANGES.md b/CHANGES.md index e8af5aec03..d41f40aaa6 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -23,6 +23,8 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format ( * ** POTENTIALLY BREAKING** Removed support for KtLint 0.3x and 0.45.2 ([#1475](https://github.com/diffplug/spotless/pull/1475)) * `KtLint` does not maintain a stable API - before this PR, we supported every breaking change in the API since 2019. * From now on, we will support no more than 2 breaking changes at a time. +* NpmFormatterStepStateBase delays `npm install` call until the formatter is first used. This enables better integration + with `gradle-node-plugin`. ([#1522](https://github.com/diffplug/spotless/pull/1522)) ## [2.32.0] - 2023-01-13 ### Added diff --git a/plugin-gradle/CHANGES.md b/plugin-gradle/CHANGES.md index 37d08f9b75..cbcd3bd953 100644 --- a/plugin-gradle/CHANGES.md +++ b/plugin-gradle/CHANGES.md @@ -15,6 +15,9 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format ( * **POTENTIALLY BREAKING** Removed support for KtLint 0.3x and 0.45.2 ([#1475](https://github.com/diffplug/spotless/pull/1475)) * `KtLint` does not maintain a stable API - before this PR, we supported every breaking change in the API since 2019. * From now on, we will support no more than 2 breaking changes at a time. +* `npm`-based formatters `ESLint`, `prettier` and `tsfmt` delay their `npm install` call until the formatters are first + used. For gradle this effectively moves the `npm install` call out of the configuration phase and as such enables + better integration with `gradle-node-plugin`. ([#1522](https://github.com/diffplug/spotless/pull/1522)) ## [6.13.0] - 2023-01-14 ### Added diff --git a/plugin-maven/CHANGES.md b/plugin-maven/CHANGES.md index 2a23405d35..93dd005ab6 100644 --- a/plugin-maven/CHANGES.md +++ b/plugin-maven/CHANGES.md @@ -18,6 +18,7 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format ( * **POTENTIALLY BREAKING** Removed support for KtLint 0.3x and 0.45.2 ([#1475](https://github.com/diffplug/spotless/pull/1475)) * `KtLint` does not maintain a stable API - before this PR, we supported every breaking change in the API since 2019. * From now on, we will support no more than 2 breaking changes at a time. +* `npm`-based formatters `ESLint`, `prettier` and `tsfmt` delay their `npm install` call until the formatters are first used. ([#1522](https://github.com/diffplug/spotless/pull/1522) ## [2.30.0] - 2023-01-13 ### Added From 7caf4c08c0daea72d15439bd8cd364e77638158f Mon Sep 17 00:00:00 2001 From: Simon Gamma Date: Tue, 24 Jan 2023 20:52:34 +0100 Subject: [PATCH 647/757] 1499: add documentation and examples showcasing the integration --- plugin-gradle/README.md | 7 +++ .../NpmTestsWithoutNpmInstallationTest.java | 47 +++++++------------ ...onTest_gradle_node_plugin_example_1.gradle | 38 +++++++++++++++ ...onTest_gradle_node_plugin_example_2.gradle | 35 ++++++++++++++ 4 files changed, 96 insertions(+), 31 deletions(-) create mode 100644 plugin-gradle/src/test/resources/com/diffplug/gradle/spotless/NpmTestsWithoutNpmInstallationTest_gradle_node_plugin_example_1.gradle create mode 100644 plugin-gradle/src/test/resources/com/diffplug/gradle/spotless/NpmTestsWithoutNpmInstallationTest_gradle_node_plugin_example_2.gradle diff --git a/plugin-gradle/README.md b/plugin-gradle/README.md index b6e95807d9..7e486719e7 100644 --- a/plugin-gradle/README.md +++ b/plugin-gradle/README.md @@ -907,6 +907,13 @@ spotless { If you provide both `npmExecutable` and `nodeExecutable`, spotless will use these paths. If you specify only one of the two, spotless will assume the other one is in the same directory. +If you use the `gradle-node-plugin` ([github](https://github.com/node-gradle/gradle-node-plugin)), it is possible to use the +node- and npm-binaries dynamically installed by this plugin. See +[this](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/test/resources/com/diffplug/gradle/spotless/NpmTestsWithoutNpmInstallationTest_gradle_node_plugin_example_1.gradle) +or [this](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/test/resources/com/diffplug/gradle/spotless/NpmTestsWithoutNpmInstallationTest_gradle_node_plugin_example_2.gradle) example. + +```gradle + ### `.npmrc` detection Spotless picks up npm configuration stored in a `.npmrc` file either in the project directory or in your user home. diff --git a/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/NpmTestsWithoutNpmInstallationTest.java b/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/NpmTestsWithoutNpmInstallationTest.java index 986e2726cb..03d14292e9 100644 --- a/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/NpmTestsWithoutNpmInstallationTest.java +++ b/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/NpmTestsWithoutNpmInstallationTest.java @@ -73,38 +73,23 @@ private void printContents() { } @Test - void useNodeAndNpmFromNodeGradlePluginInOneSweep() throws Exception { + void useNodeAndNpmFromNodeGradlePlugin_example1() throws Exception { try { - setFile("build.gradle").toLines( - "plugins {", - " id 'com.diffplug.spotless'", - " id 'com.github.node-gradle.node' version '3.5.1'", - "}", - "repositories { mavenCentral() }", - "node {", - " download = true", - " version = '18.13.0'", - " npmVersion = '8.19.2'", - " workDir = file(\"${buildDir}/nodejs\")", - " npmWorkDir = file(\"${buildDir}/npm\")", - "}", - "def prettierConfig = [:]", - "prettierConfig['printWidth'] = 50", - "prettierConfig['parser'] = 'typescript'", - "def npmExec = System.getProperty('os.name').toLowerCase().contains('windows') ? '/npm.cmd' : '/bin/npm'", - "def nodeExec = System.getProperty('os.name').toLowerCase().contains('windows') ? '/node.exe' : '/bin/node'", - "spotless {", - " format 'mytypescript', {", - " target 'test.ts'", - " prettier()", - " .npmExecutable(\"${tasks.named('npmSetup').get().npmDir.get()}${npmExec}\")", - " .nodeExecutable(\"${tasks.named('nodeSetup').get().nodeDir.get()}${nodeExec}\")", - " .config(prettierConfig)", - " }", - "}", - "tasks.named('spotlessMytypescript').configure {", - " it.dependsOn('nodeSetup', 'npmSetup')", - "}"); + setFile("build.gradle").toResource("com/diffplug/gradle/spotless/NpmTestsWithoutNpmInstallationTest_gradle_node_plugin_example_1.gradle"); + setFile("test.ts").toResource("npm/prettier/config/typescript.dirty"); + final BuildResult spotlessApply = gradleRunner().withArguments("--stacktrace", "spotlessApply").build(); + Assertions.assertThat(spotlessApply.getOutput()).contains("BUILD SUCCESSFUL"); + assertFile("test.ts").sameAsResource("npm/prettier/config/typescript.configfile.clean"); + } catch (Exception e) { + printContents(); + throw e; + } + } + + @Test + void useNpmFromNodeGradlePlugin_example2() throws Exception { + try { + setFile("build.gradle").toResource("com/diffplug/gradle/spotless/NpmTestsWithoutNpmInstallationTest_gradle_node_plugin_example_2.gradle"); setFile("test.ts").toResource("npm/prettier/config/typescript.dirty"); final BuildResult spotlessApply = gradleRunner().withArguments("--stacktrace", "spotlessApply").build(); Assertions.assertThat(spotlessApply.getOutput()).contains("BUILD SUCCESSFUL"); diff --git a/plugin-gradle/src/test/resources/com/diffplug/gradle/spotless/NpmTestsWithoutNpmInstallationTest_gradle_node_plugin_example_1.gradle b/plugin-gradle/src/test/resources/com/diffplug/gradle/spotless/NpmTestsWithoutNpmInstallationTest_gradle_node_plugin_example_1.gradle new file mode 100644 index 0000000000..7ec7a2c592 --- /dev/null +++ b/plugin-gradle/src/test/resources/com/diffplug/gradle/spotless/NpmTestsWithoutNpmInstallationTest_gradle_node_plugin_example_1.gradle @@ -0,0 +1,38 @@ +/** + * This example shows how to use the gradle-node-plugin to install node and npm in separate directories + * and use these binaries with the prettier formatter. + */ +plugins { + id 'com.diffplug.spotless' + id 'com.github.node-gradle.node' version '3.5.1' +} +repositories { mavenCentral() } +node { + download = true + version = '18.13.0' + npmVersion = '8.19.2' + // when setting both these directories, npm and node will be in separate directories + workDir = file("${buildDir}/nodejs") + npmWorkDir = file("${buildDir}/npm") +} +def prettierConfig = [:] +prettierConfig['printWidth'] = 50 +prettierConfig['parser'] = 'typescript' + +// the executable names +def npmExec = System.getProperty('os.name').toLowerCase().contains('windows') ? '/npm.cmd' : '/bin/npm' +def nodeExec = System.getProperty('os.name').toLowerCase().contains('windows') ? '/node.exe' : '/bin/node' + +spotless { + format 'mytypescript', { + target 'test.ts' + prettier() + .npmExecutable("${tasks.named('npmSetup').get().npmDir.get()}${npmExec}") // get the npm executable path from gradle-node-plugin + .nodeExecutable("${tasks.named('nodeSetup').get().nodeDir.get()}${nodeExec}") // get the node executable path from gradle-node-plugin + .config(prettierConfig) + } +} + +tasks.named('spotlessMytypescript').configure { + it.dependsOn('nodeSetup', 'npmSetup') +} diff --git a/plugin-gradle/src/test/resources/com/diffplug/gradle/spotless/NpmTestsWithoutNpmInstallationTest_gradle_node_plugin_example_2.gradle b/plugin-gradle/src/test/resources/com/diffplug/gradle/spotless/NpmTestsWithoutNpmInstallationTest_gradle_node_plugin_example_2.gradle new file mode 100644 index 0000000000..eb59b85cf0 --- /dev/null +++ b/plugin-gradle/src/test/resources/com/diffplug/gradle/spotless/NpmTestsWithoutNpmInstallationTest_gradle_node_plugin_example_2.gradle @@ -0,0 +1,35 @@ +/** + * This example shows how to use the gradle-node-plugin to install node and npm together and + * use these binaries with the prettier formatter. + */ +plugins { + id 'com.diffplug.spotless' + id 'com.github.node-gradle.node' version '3.5.1' +} +repositories { mavenCentral() } +node { + download = true + version = '18.13.0' + // when not setting an explicit `npmWorkDir`, the npm binary will be installed next to the node binary + workDir = file("${buildDir}/nodejs") +} +def prettierConfig = [:] +prettierConfig['printWidth'] = 50 +prettierConfig['parser'] = 'typescript' + +// the executable name +def npmExec = System.getProperty('os.name').toLowerCase().contains('windows') ? '/npm.cmd' : '/bin/npm' + +spotless { + typescript { + target 'test.ts' + prettier() + .npmExecutable("${tasks.named('npmSetup').get().npmDir.get()}${npmExec}") // get the npm executable path from gradle-node-plugin + // setting the nodeExecutable is not necessary, since it will be found in the same directory as the npm executable (see above) + .config(prettierConfig) + } +} + +tasks.named('spotlessTypescript').configure { + it.dependsOn('nodeSetup', 'npmSetup') +} From 28ba93b8f3098b5ec104c87ab97d1eecb67b18ff Mon Sep 17 00:00:00 2001 From: Simon Gamma Date: Tue, 24 Jan 2023 20:54:09 +0100 Subject: [PATCH 648/757] 1499: drive-by-bugfix when using singleton map directly, it could occur that we tried to manipulate that map later (combination of using `prettier()` inside `typescript` block while supplying a prettier config via `config([...])` --- .../java/com/diffplug/gradle/spotless/TypescriptExtension.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/TypescriptExtension.java b/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/TypescriptExtension.java index 2283afccff..a11f1b0c39 100644 --- a/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/TypescriptExtension.java +++ b/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/TypescriptExtension.java @@ -166,7 +166,7 @@ protected FormatterStep createStep() { private void fixParserToTypescript() { if (this.prettierConfig == null) { - this.prettierConfig = Collections.singletonMap("parser", "typescript"); + this.prettierConfig = new TreeMap<>(Collections.singletonMap("parser", "typescript")); } else { final Object replaced = this.prettierConfig.put("parser", "typescript"); if (replaced != null) { From 292d7e2bd4fb86f10c05207fc4ff918f3a9dd5df Mon Sep 17 00:00:00 2001 From: Simon Gamma Date: Wed, 25 Jan 2023 11:18:36 +0100 Subject: [PATCH 649/757] 1499: refactor re-install needed detection --- .../spotless/npm/NodeServerLayout.java | 34 ++++++++++++++++++- .../npm/NpmFormatterStepStateBase.java | 12 +++++-- 2 files changed, 43 insertions(+), 3 deletions(-) diff --git a/lib/src/main/java/com/diffplug/spotless/npm/NodeServerLayout.java b/lib/src/main/java/com/diffplug/spotless/npm/NodeServerLayout.java index a175080517..63a6a923da 100644 --- a/lib/src/main/java/com/diffplug/spotless/npm/NodeServerLayout.java +++ b/lib/src/main/java/com/diffplug/spotless/npm/NodeServerLayout.java @@ -1,5 +1,5 @@ /* - * Copyright 2020-2021 DiffPlug + * Copyright 2020-2023 DiffPlug * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -16,6 +16,11 @@ package com.diffplug.spotless.npm; import java.io.File; +import java.nio.file.Files; +import java.nio.file.Path; +import java.util.stream.Stream; + +import com.diffplug.spotless.ThrowingEx; class NodeServerLayout { @@ -50,4 +55,31 @@ public File npmrcFile() { static File getBuildDirFromNodeModulesDir(File nodeModulesDir) { return nodeModulesDir.getParentFile(); } + + public boolean isLayoutPrepared() { + if (!nodeModulesDir().isDirectory()) { + return false; + } + if (!packageJsonFile().isFile()) { + return false; + } + if (!serveJsFile().isFile()) { + return false; + } + // npmrc is optional, so must not be checked here + return true; + } + + public boolean isNodeModulesPrepared() { + Path nodeModulesInstallDirPath = new File(nodeModulesDir(), "node_modules").toPath(); + if (!Files.isDirectory(nodeModulesInstallDirPath)) { + return false; + } + // check if it is NOT empty + return ThrowingEx.get(() -> { + try (Stream entries = Files.list(nodeModulesInstallDirPath)) { + return entries.findFirst().isPresent(); + } + }); + } } diff --git a/lib/src/main/java/com/diffplug/spotless/npm/NpmFormatterStepStateBase.java b/lib/src/main/java/com/diffplug/spotless/npm/NpmFormatterStepStateBase.java index 996400ce33..9cff41e604 100644 --- a/lib/src/main/java/com/diffplug/spotless/npm/NpmFormatterStepStateBase.java +++ b/lib/src/main/java/com/diffplug/spotless/npm/NpmFormatterStepStateBase.java @@ -81,16 +81,24 @@ private void runNpmInstall(File npmProjectDir) throws IOException { } protected void assertNodeServerDirReady() throws IOException { - if (!this.nodeServerLayout.nodeModulesDir().exists() || !this.nodeServerLayout.packageJsonFile().isFile()) { + if (needsPrepareNodeServerLayout()) { // reinstall if missing prepareNodeServerLayout(); } - if (!new File(this.nodeServerLayout.nodeModulesDir(), "node_modules").isDirectory()) { + if (needsPrepareNodeServer()) { // run npm install if node_modules is missing prepareNodeServer(); } } + protected boolean needsPrepareNodeServer() { + return this.nodeServerLayout.isNodeModulesPrepared(); + } + + protected boolean needsPrepareNodeServerLayout() { + return !this.nodeServerLayout.isLayoutPrepared(); + } + protected ServerProcessInfo npmRunServer() throws ServerStartException, IOException { assertNodeServerDirReady(); try { From 7326772bad72c2855fecc62421b4e43031609af6 Mon Sep 17 00:00:00 2001 From: Simon Gamma Date: Wed, 25 Jan 2023 11:27:58 +0100 Subject: [PATCH 650/757] 1499: spotbugs --- .../java/com/diffplug/spotless/npm/EslintFormatterStep.java | 3 +++ 1 file changed, 3 insertions(+) diff --git a/lib/src/main/java/com/diffplug/spotless/npm/EslintFormatterStep.java b/lib/src/main/java/com/diffplug/spotless/npm/EslintFormatterStep.java index 2a095e9ad7..221a745ad7 100644 --- a/lib/src/main/java/com/diffplug/spotless/npm/EslintFormatterStep.java +++ b/lib/src/main/java/com/diffplug/spotless/npm/EslintFormatterStep.java @@ -39,6 +39,8 @@ import com.diffplug.spotless.ThrowingEx; import com.diffplug.spotless.npm.EslintRestService.FormatOption; +import edu.umd.cs.findbugs.annotations.SuppressFBWarnings; + public class EslintFormatterStep { private static final Logger logger = LoggerFactory.getLogger(EslintFormatterStep.class); @@ -83,6 +85,7 @@ private static class State extends NpmFormatterStepStateBase implements Serializ private static final long serialVersionUID = -539537027004745812L; private final EslintConfig origEslintConfig; + @SuppressFBWarnings("SE_TRANSIENT_FIELD_NOT_RESTORED") private transient EslintConfig eslintConfigInUse; State(String stepName, Map devDependencies, File projectDir, File buildDir, NpmPathResolver npmPathResolver, EslintConfig eslintConfig) throws IOException { From 2a8f9890919ef6a73d0112f79415f22addedc897 Mon Sep 17 00:00:00 2001 From: Goooler Date: Wed, 25 Jan 2023 20:49:27 +0800 Subject: [PATCH 651/757] Remove retry plugin https://docs.gradle.com/enterprise/gradle-plugin/#test_retry_migration --- gradle/special-tests.gradle | 1 - settings.gradle | 3 --- 2 files changed, 4 deletions(-) diff --git a/gradle/special-tests.gradle b/gradle/special-tests.gradle index fd5f602243..52f82e4e1b 100644 --- a/gradle/special-tests.gradle +++ b/gradle/special-tests.gradle @@ -1,4 +1,3 @@ -apply plugin: 'org.gradle.test-retry' apply plugin: 'com.adarshr.test-logger' def special = [ 'Npm', diff --git a/settings.gradle b/settings.gradle index ca48729297..8ab9430f00 100644 --- a/settings.gradle +++ b/settings.gradle @@ -11,8 +11,6 @@ pluginManagement { id 'com.diffplug.spotless-changelog' version '2.4.1' // https://github.com/diffplug/goomph/blob/main/CHANGES.md id 'com.diffplug.p2.asmaven' version '3.27.0' // DO NOT UPDATE, see https://github.com/diffplug/spotless/pull/874 - // https://github.com/gradle/test-retry-gradle-plugin/releases - id 'org.gradle.test-retry' version '1.5.1' // https://github.com/radarsh/gradle-test-logger-plugin/blob/develop/CHANGELOG.md id 'com.adarshr.test-logger' version '3.2.0' // https://github.com/davidburstrom/version-compatibility-gradle-plugin/tags @@ -26,7 +24,6 @@ plugins { id 'com.github.spotbugs' apply false id 'com.diffplug.spotless-changelog' apply false id 'com.diffplug.p2.asmaven' apply false - id 'org.gradle.test-retry' apply false id 'com.adarshr.test-logger' apply false id 'io.github.davidburstrom.version-compatibility' apply false id "com.gradle.enterprise" version "3.12.2" From 46d370dd5e5e0ebaadcd4ebca2eef1927d2806f3 Mon Sep 17 00:00:00 2001 From: Simon Gamma Date: Wed, 25 Jan 2023 19:20:05 +0100 Subject: [PATCH 652/757] 1499: provide npm output if server starting fails --- .../diffplug/spotless/npm/NpmFormatterStepStateBase.java | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/lib/src/main/java/com/diffplug/spotless/npm/NpmFormatterStepStateBase.java b/lib/src/main/java/com/diffplug/spotless/npm/NpmFormatterStepStateBase.java index 9cff41e604..3e5fa1ff18 100644 --- a/lib/src/main/java/com/diffplug/spotless/npm/NpmFormatterStepStateBase.java +++ b/lib/src/main/java/com/diffplug/spotless/npm/NpmFormatterStepStateBase.java @@ -32,6 +32,8 @@ import org.slf4j.LoggerFactory; import com.diffplug.spotless.FormatterFunc; +import com.diffplug.spotless.ProcessRunner.LongRunningProcess; +import com.diffplug.spotless.ThrowingEx; import edu.umd.cs.findbugs.annotations.SuppressFBWarnings; @@ -101,13 +103,14 @@ protected boolean needsPrepareNodeServerLayout() { protected ServerProcessInfo npmRunServer() throws ServerStartException, IOException { assertNodeServerDirReady(); + LongRunningProcess server = null; try { // The npm process will output the randomly selected port of the http server process to 'server.port' file // so in order to be safe, remove such a file if it exists before starting. final File serverPortFile = new File(this.nodeServerLayout.nodeModulesDir(), "server.port"); NpmResourceHelper.deleteFileIfExists(serverPortFile); // start the http server in node - Process server = new NpmProcess(this.nodeServerLayout.nodeModulesDir(), this.locations.npmExecutable(), this.locations.nodeExecutable()).start(); + server = new NpmProcess(this.nodeServerLayout.nodeModulesDir(), this.locations.npmExecutable(), this.locations.nodeExecutable()).start(); // await the readiness of the http server - wait for at most 60 seconds try { @@ -128,7 +131,7 @@ protected ServerProcessInfo npmRunServer() throws ServerStartException, IOExcept String serverPort = NpmResourceHelper.readUtf8StringFromFile(serverPortFile).trim(); return new ServerProcessInfo(server, serverPort, serverPortFile); } catch (IOException | TimeoutException e) { - throw new ServerStartException(e); + throw new ServerStartException("Starting server failed." + (server != null ? "\n\nProcess result:\n" + ThrowingEx.get(server::result) : ""), e); } } @@ -197,7 +200,7 @@ public void close() throws Exception { protected static class ServerStartException extends RuntimeException { private static final long serialVersionUID = -8803977379866483002L; - public ServerStartException(Throwable cause) { + public ServerStartException(String message, Throwable cause) { super(cause); } } From 012e4ae55cd0c9c3783ed6130e6edf6e10700277 Mon Sep 17 00:00:00 2001 From: Simon Gamma Date: Wed, 25 Jan 2023 19:21:35 +0100 Subject: [PATCH 653/757] 1499: fix condition --- .../com/diffplug/spotless/npm/NpmFormatterStepStateBase.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/src/main/java/com/diffplug/spotless/npm/NpmFormatterStepStateBase.java b/lib/src/main/java/com/diffplug/spotless/npm/NpmFormatterStepStateBase.java index 3e5fa1ff18..92ac7df6f2 100644 --- a/lib/src/main/java/com/diffplug/spotless/npm/NpmFormatterStepStateBase.java +++ b/lib/src/main/java/com/diffplug/spotless/npm/NpmFormatterStepStateBase.java @@ -94,7 +94,7 @@ protected void assertNodeServerDirReady() throws IOException { } protected boolean needsPrepareNodeServer() { - return this.nodeServerLayout.isNodeModulesPrepared(); + return !this.nodeServerLayout.isNodeModulesPrepared(); } protected boolean needsPrepareNodeServerLayout() { From 76b626cc73ef469c499a3b5fc33f807c0645766f Mon Sep 17 00:00:00 2001 From: Benoit Lacelle Date: Wed, 25 Jan 2023 22:29:12 +0400 Subject: [PATCH 654/757] Handle specifically empty filePath, and not default FS rootDir --- gradle.properties | 2 +- .../java/com/diffplug/spotless/Formatter.java | 12 +++- testlib/build.gradle | 1 + .../com/diffplug/spotless/FormatterTest.java | 66 ++++++++++++++++++- 4 files changed, 76 insertions(+), 5 deletions(-) diff --git a/gradle.properties b/gradle.properties index 5702d21bdd..523440be25 100644 --- a/gradle.properties +++ b/gradle.properties @@ -28,4 +28,4 @@ VER_DURIAN=1.2.0 VER_JGIT=5.13.1.202206130422-r VER_JUNIT=5.9.2 VER_ASSERTJ=3.24.2 -VER_MOCKITO=4.11.0 \ No newline at end of file +VER_MOCKITO=5.0.0 diff --git a/lib/src/main/java/com/diffplug/spotless/Formatter.java b/lib/src/main/java/com/diffplug/spotless/Formatter.java index 038e77fa64..3a38893cd6 100644 --- a/lib/src/main/java/com/diffplug/spotless/Formatter.java +++ b/lib/src/main/java/com/diffplug/spotless/Formatter.java @@ -1,5 +1,5 @@ /* - * Copyright 2016 DiffPlug + * Copyright 2016-2023 DiffPlug * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -237,8 +237,14 @@ public String compute(String unix, File file) { unix = LineEnding.toUnix(formatted); } } catch (Throwable e) { - String relativePath = rootDir.relativize(file.toPath()).toString(); - exceptionPolicy.handleError(e, step, relativePath); + if (file.getPath().isEmpty()) { + // Path.relativize would fail if rootDir is an absolute path + exceptionPolicy.handleError(e, step, ""); + } else { + // Path may be forged from a different FileSystem than Filesystem.default + String relativePath = rootDir.relativize(rootDir.getFileSystem().getPath(file.getPath())).toString(); + exceptionPolicy.handleError(e, step, relativePath); + } } } return unix; diff --git a/testlib/build.gradle b/testlib/build.gradle index 64d4681805..97b17d0dc6 100644 --- a/testlib/build.gradle +++ b/testlib/build.gradle @@ -12,6 +12,7 @@ dependencies { api "com.diffplug.durian:durian-testlib:${VER_DURIAN}" api "org.junit.jupiter:junit-jupiter:${VER_JUNIT}" api "org.assertj:assertj-core:${VER_ASSERTJ}" + api "org.mockito:mockito-core:$VER_MOCKITO" implementation "com.diffplug.durian:durian-io:${VER_DURIAN}" implementation "com.diffplug.durian:durian-collect:${VER_DURIAN}" diff --git a/testlib/src/test/java/com/diffplug/spotless/FormatterTest.java b/testlib/src/test/java/com/diffplug/spotless/FormatterTest.java index 06b8e64d31..0faf40bb95 100644 --- a/testlib/src/test/java/com/diffplug/spotless/FormatterTest.java +++ b/testlib/src/test/java/com/diffplug/spotless/FormatterTest.java @@ -1,5 +1,5 @@ /* - * Copyright 2016-2022 DiffPlug + * Copyright 2016-2023 DiffPlug * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -15,15 +15,19 @@ */ package com.diffplug.spotless; +import java.io.File; import java.nio.charset.Charset; import java.nio.charset.StandardCharsets; +import java.nio.file.FileSystems; import java.nio.file.Path; import java.nio.file.Paths; import java.util.ArrayList; +import java.util.Collections; import java.util.List; import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Test; +import org.mockito.Mockito; import com.diffplug.common.base.StandardSystemProperty; import com.diffplug.spotless.generic.EndWithNewlineStep; @@ -89,4 +93,64 @@ protected Formatter create() { } }.testEquals(); } + + // new File("") can be used if there is no File representing this content. It should not conflict with rootDir.relativize(...) + @Test + public void testExceptionWithEmptyPath() throws Exception { + LineEnding.Policy lineEndingsPolicy = LineEnding.UNIX.createPolicy(); + Charset encoding = StandardCharsets.UTF_8; + FormatExceptionPolicy exceptionPolicy = FormatExceptionPolicy.failOnlyOnError(); + + Path rootDir = Paths.get(StandardSystemProperty.USER_DIR.value()); + + FormatterStep step = Mockito.mock(FormatterStep.class); + Mockito.when(step.getName()).thenReturn("someFailingStep"); + Mockito.when(step.format(Mockito.anyString(), Mockito.any(File.class))).thenThrow(new IllegalArgumentException("someReason")); + List steps = Collections.singletonList(step); + + Formatter formatter = Formatter.builder() + .lineEndingsPolicy(lineEndingsPolicy) + .encoding(encoding) + .rootDir(rootDir) + .steps(steps) + .exceptionPolicy(exceptionPolicy) + .build(); + + formatter.compute("someFileContent", new File("")); + } + + // rootDir may be a path not from the default FileSystem + @Test + public void testExceptionWithRootDirIsNotFileSystem() throws Exception { + LineEnding.Policy lineEndingsPolicy = LineEnding.UNIX.createPolicy(); + Charset encoding = StandardCharsets.UTF_8; + FormatExceptionPolicy exceptionPolicy = FormatExceptionPolicy.failOnlyOnError(); + + Path rootDir = Mockito.mock(Path.class); + Path relativized = Mockito.mock(Path.class); + Mockito.when(rootDir.relativize(Mockito.any(Path.class))).then(invok -> { + Path filePath = invok.getArgument(0); + if (filePath.getFileSystem() == FileSystems.getDefault()) { + throw new IllegalArgumentException("Can not relativize through different FileSystems"); + } + + return relativized; + }); + + FormatterStep step = Mockito.mock(FormatterStep.class); + Mockito.when(step.getName()).thenReturn("someFailingStep"); + Mockito.when(step.format(Mockito.anyString(), Mockito.any(File.class))).thenThrow(new IllegalArgumentException("someReason")); + List steps = Collections.singletonList(step); + + Formatter formatter = Formatter.builder() + .lineEndingsPolicy(lineEndingsPolicy) + .encoding(encoding) + .rootDir(rootDir) + .steps(steps) + .exceptionPolicy(exceptionPolicy) + .build(); + + formatter.compute("someFileContent", new File("")); + } + } From a8c0bb818de07242feeb08f5731af6ce6fd7a0cb Mon Sep 17 00:00:00 2001 From: Benoit Lacelle Date: Wed, 25 Jan 2023 22:53:07 +0400 Subject: [PATCH 655/757] Rollback Mockito to 4.X (as 5.X requires JDK11) --- gradle.properties | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gradle.properties b/gradle.properties index 523440be25..d99bdac6ce 100644 --- a/gradle.properties +++ b/gradle.properties @@ -28,4 +28,4 @@ VER_DURIAN=1.2.0 VER_JGIT=5.13.1.202206130422-r VER_JUNIT=5.9.2 VER_ASSERTJ=3.24.2 -VER_MOCKITO=5.0.0 +VER_MOCKITO=4.11.0 From 469351773f1a6577a8fea6b328a4986581d385bd Mon Sep 17 00:00:00 2001 From: Goooler Date: Wed, 25 Jan 2023 21:18:49 +0800 Subject: [PATCH 656/757] Compare current Java version via isCompatibleWith --- lib/build.gradle | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/lib/build.gradle b/lib/build.gradle index 82595da399..f2ca13ccb1 100644 --- a/lib/build.gradle +++ b/lib/build.gradle @@ -107,16 +107,15 @@ spotbugs { reportLevel = 'low' } // low|medium|high (low = sensitive to even min apply from: rootProject.file('gradle/special-tests.gradle') tasks.withType(Test).configureEach { - def jdkVersion = JavaVersion.current().majorVersion.toInteger() def args = [] - if (jdkVersion >= 16) { + if (JavaVersion.current().isCompatibleWith(JavaVersion.VERSION_16)) { // https://docs.gradle.org/7.5/userguide/upgrading_version_7.html#removes_implicit_add_opens_for_test_workers args += [ "--add-opens=java.base/java.lang=ALL-UNNAMED", "--add-opens=java.base/java.util=ALL-UNNAMED", ] } - if (jdkVersion >= 18) { + if (JavaVersion.current().isCompatibleWith(JavaVersion.VERSION_18)) { // https://openjdk.org/jeps/411 args += "-Djava.security.manager=allow" } From bdf09a4071708af3fd4e10ecc68975c8df89cc56 Mon Sep 17 00:00:00 2001 From: Goooler Date: Wed, 25 Jan 2023 21:23:25 +0800 Subject: [PATCH 657/757] Apply mavenCentral in dependencyResolutionManagement --- build.gradle | 5 +---- gradle/java-setup.gradle | 1 - plugin-maven/build.gradle | 1 - settings.gradle | 8 ++++++++ 4 files changed, 9 insertions(+), 6 deletions(-) diff --git a/build.gradle b/build.gradle index f9e3d0de21..9d43f50135 100644 --- a/build.gradle +++ b/build.gradle @@ -1,6 +1,3 @@ -repositories { - mavenCentral() -} apply from: rootProject.file('gradle/java-publish.gradle') apply from: rootProject.file('gradle/changelog.gradle') allprojects { @@ -18,4 +15,4 @@ spotless { trimTrailingWhitespace() endWithNewline() } -} \ No newline at end of file +} diff --git a/gradle/java-setup.gradle b/gradle/java-setup.gradle index 9c9f394405..0f80c89d81 100644 --- a/gradle/java-setup.gradle +++ b/gradle/java-setup.gradle @@ -1,7 +1,6 @@ ////////// // JAVA // ////////// -repositories { mavenCentral() } // setup java apply plugin: 'java' diff --git a/plugin-maven/build.gradle b/plugin-maven/build.gradle index 664101a0fd..8ab478d6ba 100644 --- a/plugin-maven/build.gradle +++ b/plugin-maven/build.gradle @@ -3,7 +3,6 @@ plugins { id 'de.benediktritter.maven-plugin-development' version '0.4.1' } -repositories { mavenCentral() } apply from: rootProject.file('gradle/changelog.gradle') ext.artifactId = project.artifactIdMaven version = spotlessChangelog.versionNext diff --git a/settings.gradle b/settings.gradle index 8ab9430f00..996d5e6b74 100644 --- a/settings.gradle +++ b/settings.gradle @@ -17,6 +17,7 @@ pluginManagement { id 'io.github.davidburstrom.version-compatibility' version '0.4.0' } } + plugins { id 'com.diffplug.spotless' apply false id 'com.gradle.plugin-publish' apply false @@ -28,6 +29,13 @@ plugins { id 'io.github.davidburstrom.version-compatibility' apply false id "com.gradle.enterprise" version "3.12.2" } + +dependencyResolutionManagement { + repositories { + mavenCentral() + } +} + if (System.env['CI'] != null) { // use the remote buildcache on all CI builds buildCache { From 57edefb327936a8149d730cbc5863707d139db70 Mon Sep 17 00:00:00 2001 From: Goooler Date: Wed, 25 Jan 2023 21:29:54 +0800 Subject: [PATCH 658/757] Apply plugin versions in root plugins block --- settings.gradle | 43 +++++++++++++++++++------------------------ 1 file changed, 19 insertions(+), 24 deletions(-) diff --git a/settings.gradle b/settings.gradle index 996d5e6b74..d925058035 100644 --- a/settings.gradle +++ b/settings.gradle @@ -1,32 +1,27 @@ pluginManagement { - plugins { - id 'com.diffplug.spotless' version '6.13.0' - // https://plugins.gradle.org/plugin/com.gradle.plugin-publish - id 'com.gradle.plugin-publish' version '1.1.0' - // https://github.com/gradle-nexus/publish-plugin/releases - id 'io.github.gradle-nexus.publish-plugin' version '1.1.0' - // https://github.com/spotbugs/spotbugs-gradle-plugin/releases - id 'com.github.spotbugs' version '5.0.13' - // https://github.com/diffplug/spotless-changelog - id 'com.diffplug.spotless-changelog' version '2.4.1' - // https://github.com/diffplug/goomph/blob/main/CHANGES.md - id 'com.diffplug.p2.asmaven' version '3.27.0' // DO NOT UPDATE, see https://github.com/diffplug/spotless/pull/874 - // https://github.com/radarsh/gradle-test-logger-plugin/blob/develop/CHANGELOG.md - id 'com.adarshr.test-logger' version '3.2.0' - // https://github.com/davidburstrom/version-compatibility-gradle-plugin/tags - id 'io.github.davidburstrom.version-compatibility' version '0.4.0' + repositories { + mavenCentral() + gradlePluginPortal() } } plugins { - id 'com.diffplug.spotless' apply false - id 'com.gradle.plugin-publish' apply false - id 'io.github.gradle-nexus.publish-plugin' apply false - id 'com.github.spotbugs' apply false - id 'com.diffplug.spotless-changelog' apply false - id 'com.diffplug.p2.asmaven' apply false - id 'com.adarshr.test-logger' apply false - id 'io.github.davidburstrom.version-compatibility' apply false + id 'com.diffplug.spotless' version '6.13.0' apply false + // https://plugins.gradle.org/plugin/com.gradle.plugin-publish + id 'com.gradle.plugin-publish' version '1.1.0' apply false + // https://github.com/gradle-nexus/publish-plugin/releases + id 'io.github.gradle-nexus.publish-plugin' version '1.1.0' apply false + // https://github.com/spotbugs/spotbugs-gradle-plugin/releases + id 'com.github.spotbugs' version '5.0.13' apply false + // https://github.com/diffplug/spotless-changelog + id 'com.diffplug.spotless-changelog' version '2.4.1' apply false + // https://github.com/diffplug/goomph/blob/main/CHANGES.md + // DO NOT UPDATE, see https://github.com/diffplug/spotless/pull/874 + id 'com.diffplug.p2.asmaven' version '3.27.0' apply false + // https://github.com/radarsh/gradle-test-logger-plugin/blob/develop/CHANGELOG.md + id 'com.adarshr.test-logger' version '3.2.0' apply false + // https://github.com/davidburstrom/version-compatibility-gradle-plugin/tags + id 'io.github.davidburstrom.version-compatibility' version '0.4.0' apply false id "com.gradle.enterprise" version "3.12.2" } From fff6fdf98af32af8ef089c87477177648bb3bd5b Mon Sep 17 00:00:00 2001 From: Goooler Date: Wed, 25 Jan 2023 21:38:07 +0800 Subject: [PATCH 659/757] Defer more task configurations --- _ext/gradle/java-setup.gradle | 2 +- _ext/gradle/update-lockfile.gradle | 4 ++-- gradle/java-setup.gradle | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/_ext/gradle/java-setup.gradle b/_ext/gradle/java-setup.gradle index 9572fc2955..0d620a6519 100644 --- a/_ext/gradle/java-setup.gradle +++ b/_ext/gradle/java-setup.gradle @@ -9,7 +9,7 @@ apply from: rootProject.file('gradle/java-setup.gradle') apply plugin: 'java-library' // Show warning locations, fail on warnings -tasks.withType(JavaCompile) { +tasks.withType(JavaCompile).configureEach { options.compilerArgs << "-Xlint:unchecked" options.compilerArgs << "-Xlint:deprecation" options.compilerArgs << "-Werror" diff --git a/_ext/gradle/update-lockfile.gradle b/_ext/gradle/update-lockfile.gradle index 098d960eff..3c23bb860b 100644 --- a/_ext/gradle/update-lockfile.gradle +++ b/_ext/gradle/update-lockfile.gradle @@ -1,6 +1,6 @@ // Use file locking -configurations.all { +configurations.configureEach { resolutionStrategy { activateDependencyLocking() } -} \ No newline at end of file +} diff --git a/gradle/java-setup.gradle b/gradle/java-setup.gradle index 0f80c89d81..b048229b75 100644 --- a/gradle/java-setup.gradle +++ b/gradle/java-setup.gradle @@ -7,7 +7,7 @@ apply plugin: 'java' sourceCompatibility = VER_JAVA targetCompatibility = VER_JAVA -tasks.withType(JavaCompile) { options.encoding = 'UTF-8' } +tasks.withType(JavaCompile).configureEach { options.encoding = 'UTF-8' } ////////////// // SPOTBUGS // From 05950364f603bc45648660813cc6e7ab692de11d Mon Sep 17 00:00:00 2001 From: Goooler Date: Thu, 26 Jan 2023 13:04:10 +0800 Subject: [PATCH 660/757] Trigger gradle/wrapper-validation-action after related files changed --- .github/workflows/gradle-wrapper-validation.yml | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/.github/workflows/gradle-wrapper-validation.yml b/.github/workflows/gradle-wrapper-validation.yml index c80a7e5278..2c02ce0fc4 100644 --- a/.github/workflows/gradle-wrapper-validation.yml +++ b/.github/workflows/gradle-wrapper-validation.yml @@ -1,5 +1,15 @@ name: "Validate Gradle Wrapper" -on: [push, pull_request] +on: + push: + paths: + - 'gradlew' + - 'gradlew.bat' + - 'gradle/wrapper/' + pull_request: + paths: + - 'gradlew' + - 'gradlew.bat' + - 'gradle/wrapper/' permissions: contents: read From 56a6f7e3d1ccfcdb2fd385a5d06cc3e831c49b22 Mon Sep 17 00:00:00 2001 From: Ned Twigg Date: Wed, 25 Jan 2023 23:03:33 -0800 Subject: [PATCH 661/757] Improved KtLintStepTest.equality to not download so much. --- .../java/com/diffplug/spotless/kotlin/KtLintStepTest.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/testlib/src/test/java/com/diffplug/spotless/kotlin/KtLintStepTest.java b/testlib/src/test/java/com/diffplug/spotless/kotlin/KtLintStepTest.java index 3047245298..6700be168d 100644 --- a/testlib/src/test/java/com/diffplug/spotless/kotlin/KtLintStepTest.java +++ b/testlib/src/test/java/com/diffplug/spotless/kotlin/KtLintStepTest.java @@ -88,14 +88,14 @@ void works0_48_1() { @Test void equality() { new SerializableEqualityTester() { - String version = "0.32.0"; + String version = "0.48.0"; @Override protected void setupTest(API api) { // same version == same api.areDifferentThan(); // change the version, and it's different - version = "0.38.0-alpha01"; + version = "0.48.1"; api.areDifferentThan(); } From fb03922888f9a1e3c3e987249c121df191fe3abd Mon Sep 17 00:00:00 2001 From: Ned Twigg Date: Thu, 26 Jan 2023 10:15:08 -0800 Subject: [PATCH 662/757] The Kotlin gradle integration tests had tested every possible combination. A job for the unit tests, not the integration tests. --- .../gradle/spotless/KotlinExtensionTest.java | 262 ------------------ .../spotless/KotlinGradleExtensionTest.java | 121 -------- 2 files changed, 383 deletions(-) diff --git a/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/KotlinExtensionTest.java b/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/KotlinExtensionTest.java index a15a51412e..947b5bd728 100644 --- a/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/KotlinExtensionTest.java +++ b/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/KotlinExtensionTest.java @@ -23,24 +23,6 @@ class KotlinExtensionTest extends GradleIntegrationHarness { private static final String HEADER = "// License Header"; private static final String HEADER_WITH_YEAR = "// License Header $YEAR"; - @Test - void integration() throws IOException { - setFile("build.gradle").toLines( - "plugins {", - " id 'org.jetbrains.kotlin.jvm' version '1.5.31'", - " id 'com.diffplug.spotless'", - "}", - "repositories { mavenCentral() }", - "spotless {", - " kotlin {", - " ktlint()", - " }", - "}"); - setFile("src/main/kotlin/Main.kt").toResource("kotlin/ktlint/basic.dirty"); - gradleRunner().withArguments("spotlessApply").build(); - assertFile("src/main/kotlin/Main.kt").sameAsResource("kotlin/ktlint/basic.clean"); - } - @Test void integrationDiktat() throws IOException { setFile("build.gradle").toLines( @@ -59,42 +41,6 @@ void integrationDiktat() throws IOException { assertFile("src/main/kotlin/com/example/Main.kt").sameAsResource("kotlin/diktat/main.clean"); } - @Test - void integrationKtfmt() throws IOException { - setFile("build.gradle").toLines( - "plugins {", - " id 'org.jetbrains.kotlin.jvm' version '1.5.31'", - " id 'com.diffplug.spotless'", - "}", - "repositories { mavenCentral() }", - "spotless {", - " kotlin {", - " ktfmt()", - " }", - "}"); - setFile("src/main/kotlin/basic.kt").toResource("kotlin/ktfmt/basic.dirty"); - gradleRunner().withArguments("spotlessApply").build(); - assertFile("src/main/kotlin/basic.kt").sameAsResource("kotlin/ktfmt/basic.clean"); - } - - @Test - void integrationKtfmt_dropboxStyle_0_18() throws IOException { - setFile("build.gradle").toLines( - "plugins {", - " id 'org.jetbrains.kotlin.jvm' version '1.5.31'", - " id 'com.diffplug.spotless'", - "}", - "repositories { mavenCentral() }", - "spotless {", - " kotlin {", - " ktfmt('0.18').dropboxStyle()", - " }", - "}"); - setFile("src/main/kotlin/basic.kt").toResource("kotlin/ktfmt/basic.dirty"); - gradleRunner().withArguments("spotlessApply").build(); - assertFile("src/main/kotlin/basic.kt").sameAsResource("kotlin/ktfmt/basic-dropboxstyle.clean"); - } - @Test void integrationKtfmt_dropboxStyle_0_19() throws IOException { setFile("build.gradle").toLines( @@ -113,42 +59,6 @@ void integrationKtfmt_dropboxStyle_0_19() throws IOException { assertFile("src/main/kotlin/basic.kt").sameAsResource("kotlin/ktfmt/basic-dropboxstyle.clean"); } - @Test - void testWithIndentation() throws IOException { - setFile("build.gradle").toLines( - "plugins {", - " id 'org.jetbrains.kotlin.jvm' version '1.5.31'", - " id 'com.diffplug.spotless'", - "}", - "repositories { mavenCentral() }", - "spotless {", - " kotlin {", - " ktlint().editorConfigOverride(['indent_size': '6'])", - " }", - "}"); - setFile("src/main/kotlin/Main.kt").toResource("kotlin/ktlint/basic.dirty"); - gradleRunner().withArguments("spotlessApply").build(); - assertFile("src/main/kotlin/Main.kt").sameAsResource("kotlin/ktlint/basic.clean-indent6"); - } - - @Test - void withExperimental() throws IOException { - setFile("build.gradle").toLines( - "plugins {", - " id 'org.jetbrains.kotlin.jvm' version '1.5.31'", - " id 'com.diffplug.spotless'", - "}", - "repositories { mavenCentral() }", - "spotless {", - " kotlin {", - " ktlint().setUseExperimental(true)", - " }", - "}"); - setFile("src/main/kotlin/Main.kt").toResource("kotlin/ktlint/experimental.dirty"); - gradleRunner().withArguments("spotlessApply").build(); - assertFile("src/main/kotlin/Main.kt").sameAsResource("kotlin/ktlint/experimental.clean"); - } - @Test void withExperimentalEditorConfigOverride() throws IOException { setFile("build.gradle").toLines( @@ -190,115 +100,6 @@ void testWithHeader() throws IOException { assertFile("src/main/kotlin/AnObject.kt").hasContent(HEADER + "\n" + getTestResource("kotlin/licenseheader/KotlinCodeWithoutHeader.test")); } - @Test - void testWithHeaderKtfmt() throws IOException { - setFile("build.gradle").toLines( - "plugins {", - " id 'org.jetbrains.kotlin.jvm' version '1.5.31'", - " id 'com.diffplug.spotless'", - "}", - "repositories { mavenCentral() }", - "spotless {", - " kotlin {", - " licenseHeader('" + HEADER + "')", - " ktfmt()", - " }", - "}"); - setFile("src/main/kotlin/AnObject.kt").toResource("kotlin/licenseheader/KotlinCodeWithoutHeader.test"); - gradleRunner().withArguments("spotlessApply").build(); - assertFile("src/main/kotlin/AnObject.kt").hasContent(HEADER + "\n" + getTestResource("kotlin/licenseheader/KotlinCodeWithoutHeaderKtfmt.test")); - } - - @Test - void testWithCustomHeaderSeparator() throws IOException { - setFile("build.gradle").toLines( - "plugins {", - " id 'org.jetbrains.kotlin.jvm' version '1.5.31'", - " id 'com.diffplug.spotless'", - "}", - "repositories { mavenCentral() }", - "spotless {", - " kotlin {", - " ktlint()", - " licenseHeader ('" + HEADER + "', '@file')", - " }", - "}"); - setFile("src/main/kotlin/AnObject.kt").toResource("kotlin/licenseheader/KotlinCodeWithoutHeader.test"); - gradleRunner().withArguments("spotlessApply").build(); - assertFile("src/main/kotlin/AnObject.kt").hasContent(HEADER + "\n" + getTestResource("kotlin/licenseheader/KotlinCodeWithoutHeader.test")); - } - - @Test - void testWithCustomHeaderSeparatorKtfmt() throws IOException { - setFile("build.gradle").toLines( - "plugins {", - " id 'org.jetbrains.kotlin.jvm' version '1.5.31'", - " id 'com.diffplug.spotless'", - "}", - "repositories { mavenCentral() }", - "spotless {", - " kotlin {", - " licenseHeader ('" + HEADER + "', '@file')", - " ktfmt()", - " }", - "}"); - setFile("src/main/kotlin/AnObject.kt").toResource("kotlin/licenseheader/KotlinCodeWithoutHeader.test"); - gradleRunner().withArguments("spotlessApply").build(); - assertFile("src/main/kotlin/AnObject.kt").hasContent(HEADER + "\n" + getTestResource("kotlin/licenseheader/KotlinCodeWithoutHeaderKtfmt.test")); - } - - @Test - void testWithNonStandardYearSeparator() throws IOException { - setFile("build.gradle").toLines( - "plugins {", - " id 'org.jetbrains.kotlin.jvm' version '1.5.31'", - " id 'com.diffplug.spotless'", - "}", - "repositories { mavenCentral() }", - "spotless {", - " kotlin {", - " ktlint()", - " licenseHeader('" + HEADER_WITH_YEAR + "').yearSeparator(', ')", - " }", - "}"); - - setFile("src/main/kotlin/AnObject.kt").toResource("kotlin/licenseheader/KotlinCodeWithMultiYearHeader.test"); - setFile("src/main/kotlin/AnObject2.kt").toResource("kotlin/licenseheader/KotlinCodeWithMultiYearHeader2.test"); - gradleRunner().withArguments("spotlessApply").build(); - assertFile("src/main/kotlin/AnObject.kt").matches(matcher -> { - matcher.startsWith("// License Header 2012, 2014"); - }); - assertFile("src/main/kotlin/AnObject2.kt").matches(matcher -> { - matcher.startsWith("// License Header 2012, 2014"); - }); - } - - @Test - void testWithNonStandardYearSeparatorKtfmt() throws IOException { - setFile("build.gradle").toLines( - "plugins {", - " id 'org.jetbrains.kotlin.jvm' version '1.5.31'", - " id 'com.diffplug.spotless'", - "}", - "repositories { mavenCentral() }", - "spotless {", - " kotlin {", - " licenseHeader('" + HEADER_WITH_YEAR + "').yearSeparator(', ')", - " ktfmt()", - " }", - "}"); - - setFile("src/main/kotlin/AnObject.kt").toResource("kotlin/licenseheader/KotlinCodeWithMultiYearHeader.test"); - setFile("src/main/kotlin/AnObject2.kt").toResource("kotlin/licenseheader/KotlinCodeWithMultiYearHeader2.test"); - gradleRunner().withArguments("spotlessApply").build(); - assertFile("src/main/kotlin/AnObject.kt").matches(matcher -> { - matcher.startsWith("// License Header 2012, 2014"); - }); - assertFile("src/main/kotlin/AnObject2.kt").matches(matcher -> { - matcher.startsWith("// License Header 2012, 2014"); - }); - } - @Test void testWithCustomMaxWidthDefaultStyleKtfmt() throws IOException { setFile("build.gradle").toLines( @@ -319,67 +120,4 @@ void testWithCustomMaxWidthDefaultStyleKtfmt() throws IOException { gradleRunner().withArguments("spotlessApply").build(); assertFile("src/main/kotlin/max-width.kt").sameAsResource("kotlin/ktfmt/max-width.clean"); } - - @Test - void testWithCustomMaxWidthDefaultStyleKtfmtGradleKts() throws IOException { - setFile("build.gradle.kts").toLines( - "plugins {", - " id(\"org.jetbrains.kotlin.jvm\") version \"1.5.31\"", - " id(\"com.diffplug.spotless\")", - "}", - "repositories { mavenCentral() }", - "spotless {", - " kotlin {", - " ktfmt().configure { options ->", - " options.setMaxWidth(120)", - " }", - " }", - "}"); - - setFile("src/main/kotlin/max-width.kt").toResource("kotlin/ktfmt/max-width.dirty"); - gradleRunner().withArguments("spotlessApply").build(); - assertFile("src/main/kotlin/max-width.kt").sameAsResource("kotlin/ktfmt/max-width.clean"); - } - - @Test - void testWithCustomMaxWidthDropboxStyleKtfmt() throws IOException { - setFile("build.gradle").toLines( - "plugins {", - " id 'org.jetbrains.kotlin.jvm' version '1.5.31'", - " id 'com.diffplug.spotless'", - "}", - "repositories { mavenCentral() }", - "spotless {", - " kotlin {", - " ktfmt().dropboxStyle().configure { options ->", - " options.maxWidth = 120", - " }", - " }", - "}"); - - setFile("src/main/kotlin/max-width.kt").toResource("kotlin/ktfmt/max-width.dirty"); - gradleRunner().withArguments("spotlessApply").build(); - assertFile("src/main/kotlin/max-width.kt").sameAsResource("kotlin/ktfmt/max-width-dropbox.clean"); - } - - @Test - void testWithCustomMaxWidthDropboxStyleKtfmtGradleKts() throws IOException { - setFile("build.gradle.kts").toLines( - "plugins {", - " id(\"org.jetbrains.kotlin.jvm\") version \"1.5.31\"", - " id(\"com.diffplug.spotless\")", - "}", - "repositories { mavenCentral() }", - "spotless {", - " kotlin {", - " ktfmt().dropboxStyle().configure { options ->", - " options.setMaxWidth(120)", - " }", - " }", - "}"); - - setFile("src/main/kotlin/max-width.kt").toResource("kotlin/ktfmt/max-width.dirty"); - gradleRunner().withArguments("spotlessApply").build(); - assertFile("src/main/kotlin/max-width.kt").sameAsResource("kotlin/ktfmt/max-width-dropbox.clean"); - } } diff --git a/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/KotlinGradleExtensionTest.java b/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/KotlinGradleExtensionTest.java index 015414c331..13a7cd8472 100644 --- a/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/KotlinGradleExtensionTest.java +++ b/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/KotlinGradleExtensionTest.java @@ -23,56 +23,6 @@ import org.junit.jupiter.api.Test; class KotlinGradleExtensionTest extends GradleIntegrationHarness { - @Test - void integration() throws IOException { - testInDirectory(null); - } - - @Test - void integration_script_in_subdir() throws IOException { - testInDirectory("companionScripts"); - } - - private void testInDirectory(final String directory) throws IOException { - setFile("build.gradle").toLines( - "plugins {", - " id 'org.jetbrains.kotlin.jvm' version '1.5.31'", - " id 'com.diffplug.spotless'", - "}", - "repositories { mavenCentral() }", - "spotless {", - " kotlinGradle {", - " ktlint()", - " target '**/*.gradle.kts'", - " }", - "}"); - String filePath = "configuration.gradle.kts"; - if (directory != null) { - filePath = directory + "/" + filePath; - } - setFile(filePath).toResource("kotlin/ktlint/basic.dirty"); - gradleRunner().withArguments("spotlessApply").build(); - assertFile(filePath).sameAsResource("kotlin/ktlint/basic.clean"); - } - - @Test - void integration_default() throws IOException { - setFile("build.gradle").toLines( - "plugins {", - " id 'org.jetbrains.kotlin.jvm' version '1.5.31'", - " id 'com.diffplug.spotless'", - "}", - "repositories { mavenCentral() }", - "spotless {", - " kotlinGradle {", - " ktlint()", - " }", - "}"); - setFile("configuration.gradle.kts").toResource("kotlin/ktlint/basic.dirty"); - gradleRunner().withArguments("spotlessApply").build(); - assertFile("configuration.gradle.kts").sameAsResource("kotlin/ktlint/basic.clean"); - } - @Test void integration_default_diktat() throws IOException { setFile("build.gradle").toLines( @@ -91,41 +41,6 @@ void integration_default_diktat() throws IOException { assertThat(result.getOutput()).contains("[AVOID_NESTED_FUNCTIONS] try to avoid using nested functions"); } - @Test - void indentStep() throws IOException { - setFile("build.gradle").toLines( - "plugins {", - " id 'org.jetbrains.kotlin.jvm' version '1.5.31'", - " id 'com.diffplug.spotless'", - "}", - "repositories { mavenCentral() }", - "spotless {", - " kotlinGradle {", - " ktlint().userData(['indent_size': '6'])", - " }", - "}"); - setFile("configuration.gradle.kts").toResource("kotlin/ktlint/basic.dirty"); - gradleRunner().withArguments("spotlessCheck").buildAndFail(); - } - - @Test - void withExperimental() throws IOException { - setFile("build.gradle").toLines( - "plugins {", - " id 'org.jetbrains.kotlin.jvm' version '1.5.31'", - " id 'com.diffplug.spotless'", - "}", - "repositories { mavenCentral() }", - "spotless {", - " kotlinGradle {", - " ktlint().setUseExperimental(true)", - " }", - "}"); - setFile("configuration.gradle.kts").toResource("kotlin/ktlint/experimental.dirty"); - gradleRunner().withArguments("spotlessApply").build(); - assertFile("configuration.gradle.kts").sameAsResource("kotlin/ktlint/experimental.clean"); - } - @Test void withExperimentalEditorConfigOverride() throws IOException { setFile("build.gradle").toLines( @@ -148,24 +63,6 @@ void withExperimentalEditorConfigOverride() throws IOException { assertFile("configuration.gradle.kts").sameAsResource("kotlin/ktlint/experimentalEditorConfigOverride.clean"); } - @Test - void integration_ktfmt() throws IOException { - setFile("build.gradle").toLines( - "plugins {", - " id 'org.jetbrains.kotlin.jvm' version '1.5.31'", - " id 'com.diffplug.spotless'", - "}", - "repositories { mavenCentral() }", - "spotless {", - " kotlinGradle {", - " ktfmt()", - " }", - "}"); - setFile("configuration.gradle.kts").toResource("kotlin/ktfmt/basic.dirty"); - gradleRunner().withArguments("spotlessApply").build(); - assertFile("configuration.gradle.kts").sameAsResource("kotlin/ktfmt/basic.clean"); - } - @Test void integration_ktfmt_with_dropbox_style() throws IOException { setFile("build.gradle").toLines( @@ -183,22 +80,4 @@ void integration_ktfmt_with_dropbox_style() throws IOException { gradleRunner().withArguments("spotlessApply").build(); assertFile("configuration.gradle.kts").sameAsResource("kotlin/ktfmt/dropboxstyle.clean"); } - - @Test - void integration_lint_script_files_without_top_level_declaration() throws IOException { - setFile("build.gradle").toLines( - "plugins {", - " id 'org.jetbrains.kotlin.jvm' version '1.5.31'", - " id 'com.diffplug.spotless'", - "}", - "repositories { mavenCentral() }", - "spotless {", - " kotlinGradle {", - " ktlint()", - " }", - "}"); - setFile("configuration.gradle.kts").toContent("buildscript {}"); - gradleRunner().withArguments("spotlessApply").build(); - assertFile("configuration.gradle.kts").hasContent("buildscript {}"); - } } From 87a168b877a216dd0c397e58aa37e5c319dd8c7c Mon Sep 17 00:00:00 2001 From: Ned Twigg Date: Thu, 26 Jan 2023 10:36:35 -0800 Subject: [PATCH 663/757] Bump default KtLint `0.48.1` -> `0.48.2` --- .../diffplug/spotless/kotlin/KtLintStep.java | 19 +++++-------------- 1 file changed, 5 insertions(+), 14 deletions(-) diff --git a/lib/src/main/java/com/diffplug/spotless/kotlin/KtLintStep.java b/lib/src/main/java/com/diffplug/spotless/kotlin/KtLintStep.java index 7bcae36fb0..0d75460902 100644 --- a/lib/src/main/java/com/diffplug/spotless/kotlin/KtLintStep.java +++ b/lib/src/main/java/com/diffplug/spotless/kotlin/KtLintStep.java @@ -36,11 +36,9 @@ public class KtLintStep { // prevent direct instantiation private KtLintStep() {} - private static final String DEFAULT_VERSION = "0.48.1"; + private static final String DEFAULT_VERSION = "0.48.2"; static final String NAME = "ktlint"; - static final String PACKAGE_PRE_0_32 = "com.github.shyiko"; static final String PACKAGE = "com.pinterest"; - static final String MAVEN_COORDINATE_PRE_0_32 = PACKAGE_PRE_0_32 + ":ktlint:"; static final String MAVEN_COORDINATE = PACKAGE + ":ktlint:"; public static FormatterStep create(Provisioner provisioner) { @@ -114,21 +112,14 @@ static final class State implements Serializable { @Nullable FileSignature editorConfigPath, Map userData, Map editorConfigOverride) throws IOException { - this.version = version; - - String coordinate; - if (BadSemver.version(version) < BadSemver.version(0, 32)) { - coordinate = MAVEN_COORDINATE_PRE_0_32; - } else { - coordinate = MAVEN_COORDINATE; - } - if (BadSemver.version(version) < BadSemver.version(0, 31, 0)) { - throw new IllegalStateException("KtLint versions < 0.31.0 not supported!"); + if (BadSemver.version(version) < BadSemver.version(0, 46, 0)) { + throw new IllegalStateException("KtLint versions < 0.46.0 not supported!"); } + this.version = version; this.useExperimental = useExperimental; this.userData = new TreeMap<>(userData); this.editorConfigOverride = new TreeMap<>(editorConfigOverride); - this.jarState = JarState.from(coordinate + version, provisioner); + this.jarState = JarState.from(MAVEN_COORDINATE + version, provisioner); this.editorConfigPath = editorConfigPath; this.isScript = isScript; } From 87b6dd8b8bd8a3848d02f612f38b1d547a95bcbe Mon Sep 17 00:00:00 2001 From: Ned Twigg Date: Thu, 26 Jan 2023 10:36:58 -0800 Subject: [PATCH 664/757] Bump default scalafmt `3.6.1` -> `3.7.1` --- .../main/java/com/diffplug/spotless/scala/ScalaFmtStep.java | 4 ++-- testlib/src/main/resources/scala/scalafmt/scalafmt.conf | 2 +- .../java/com/diffplug/spotless/scala/ScalaFmtStepTest.java | 4 ++-- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/lib/src/main/java/com/diffplug/spotless/scala/ScalaFmtStep.java b/lib/src/main/java/com/diffplug/spotless/scala/ScalaFmtStep.java index bff0d9b215..264ca679db 100644 --- a/lib/src/main/java/com/diffplug/spotless/scala/ScalaFmtStep.java +++ b/lib/src/main/java/com/diffplug/spotless/scala/ScalaFmtStep.java @@ -1,5 +1,5 @@ /* - * Copyright 2016-2022 DiffPlug + * Copyright 2016-2023 DiffPlug * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -34,7 +34,7 @@ public class ScalaFmtStep { // prevent direct instantiation private ScalaFmtStep() {} - private static final String DEFAULT_VERSION = "3.6.1"; + static final String DEFAULT_VERSION = "3.7.1"; private static final String DEFAULT_SCALA_MAJOR_VERSION = "2.13"; static final String NAME = "scalafmt"; diff --git a/testlib/src/main/resources/scala/scalafmt/scalafmt.conf b/testlib/src/main/resources/scala/scalafmt/scalafmt.conf index e15d7318fa..f3cfb3a031 100644 --- a/testlib/src/main/resources/scala/scalafmt/scalafmt.conf +++ b/testlib/src/main/resources/scala/scalafmt/scalafmt.conf @@ -1,4 +1,4 @@ -version = 3.6.1 +version = 3.7.1 runner.dialect = scala213 style = defaultWithAlign # For pretty alignment. maxColumn = 20 # For my teensy narrow display diff --git a/testlib/src/test/java/com/diffplug/spotless/scala/ScalaFmtStepTest.java b/testlib/src/test/java/com/diffplug/spotless/scala/ScalaFmtStepTest.java index 1714dd9e29..c28046e148 100644 --- a/testlib/src/test/java/com/diffplug/spotless/scala/ScalaFmtStepTest.java +++ b/testlib/src/test/java/com/diffplug/spotless/scala/ScalaFmtStepTest.java @@ -30,13 +30,13 @@ class ScalaFmtStepTest extends ResourceHarness { @Test void behaviorDefaultConfig() { - StepHarness.forStep(ScalaFmtStep.create("3.0.0", TestProvisioner.mavenCentral(), null)) + StepHarness.forStep(ScalaFmtStep.create(TestProvisioner.mavenCentral())) .testResource("scala/scalafmt/basic.dirty", "scala/scalafmt/basic.clean_3.0.0"); } @Test void behaviorCustomConfig() { - StepHarness.forStep(ScalaFmtStep.create("3.0.0", TestProvisioner.mavenCentral(), createTestFile("scala/scalafmt/scalafmt.conf"))) + StepHarness.forStep(ScalaFmtStep.create(ScalaFmtStep.DEFAULT_VERSION, TestProvisioner.mavenCentral(), createTestFile("scala/scalafmt/scalafmt.conf"))) .testResource("scala/scalafmt/basic.dirty", "scala/scalafmt/basic.cleanWithCustomConf_3.0.0"); } From 5d6714d5666194e3b418a23d3d2379b797fb31fc Mon Sep 17 00:00:00 2001 From: Ned Twigg Date: Thu, 26 Jan 2023 10:41:32 -0800 Subject: [PATCH 665/757] Update changelogs. --- CHANGES.md | 2 ++ plugin-gradle/CHANGES.md | 2 ++ plugin-maven/CHANGES.md | 2 ++ 3 files changed, 6 insertions(+) diff --git a/CHANGES.md b/CHANGES.md index efbf1e5ae0..363dac1758 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -26,6 +26,8 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format ( * From now on, we will support no more than 2 breaking changes at a time. * NpmFormatterStepStateBase delays `npm install` call until the formatter is first used. This enables better integration with `gradle-node-plugin`. ([#1522](https://github.com/diffplug/spotless/pull/1522)) +* Bump default `ktlint` version to latest `0.48.1` -> `0.48.2` ([#1529](https://github.com/diffplug/spotless/pull/1529)) +* Bump default `scalafmt` version to latest `3.6.1` -> `3.7.1` ([#1529](https://github.com/diffplug/spotless/pull/1529)) ## [2.32.0] - 2023-01-13 ### Added diff --git a/plugin-gradle/CHANGES.md b/plugin-gradle/CHANGES.md index 693712cbff..8d01068383 100644 --- a/plugin-gradle/CHANGES.md +++ b/plugin-gradle/CHANGES.md @@ -20,6 +20,8 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format ( * `npm`-based formatters `ESLint`, `prettier` and `tsfmt` delay their `npm install` call until the formatters are first used. For gradle this effectively moves the `npm install` call out of the configuration phase and as such enables better integration with `gradle-node-plugin`. ([#1522](https://github.com/diffplug/spotless/pull/1522)) +* Bump default `ktlint` version to latest `0.48.1` -> `0.48.2` ([#1529](https://github.com/diffplug/spotless/pull/1529)) +* Bump default `scalafmt` version to latest `3.6.1` -> `3.7.1` ([#1529](https://github.com/diffplug/spotless/pull/1529)) ## [6.13.0] - 2023-01-14 ### Added diff --git a/plugin-maven/CHANGES.md b/plugin-maven/CHANGES.md index 9cda0d2785..3967f468fd 100644 --- a/plugin-maven/CHANGES.md +++ b/plugin-maven/CHANGES.md @@ -21,6 +21,8 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format ( * `KtLint` does not maintain a stable API - before this PR, we supported every breaking change in the API since 2019. * From now on, we will support no more than 2 breaking changes at a time. * `npm`-based formatters `ESLint`, `prettier` and `tsfmt` delay their `npm install` call until the formatters are first used. ([#1522](https://github.com/diffplug/spotless/pull/1522) +* Bump default `ktlint` version to latest `0.48.1` -> `0.48.2` ([#1529](https://github.com/diffplug/spotless/pull/1529)) +* Bump default `scalafmt` version to latest `3.6.1` -> `3.7.1` ([#1529](https://github.com/diffplug/spotless/pull/1529)) ## [2.30.0] - 2023-01-13 ### Added From 5c3411d00a120c59f301c6ea57f4e2aff2fb4164 Mon Sep 17 00:00:00 2001 From: Ned Twigg Date: Thu, 26 Jan 2023 11:07:05 -0800 Subject: [PATCH 666/757] Add missing changelog links to root `settings.gradle` --- settings.gradle | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/settings.gradle b/settings.gradle index d925058035..a5bb6c0062 100644 --- a/settings.gradle +++ b/settings.gradle @@ -13,7 +13,7 @@ plugins { id 'io.github.gradle-nexus.publish-plugin' version '1.1.0' apply false // https://github.com/spotbugs/spotbugs-gradle-plugin/releases id 'com.github.spotbugs' version '5.0.13' apply false - // https://github.com/diffplug/spotless-changelog + // https://github.com/diffplug/spotless-changelog/blob/main/CHANGELOG.md id 'com.diffplug.spotless-changelog' version '2.4.1' apply false // https://github.com/diffplug/goomph/blob/main/CHANGES.md // DO NOT UPDATE, see https://github.com/diffplug/spotless/pull/874 @@ -22,7 +22,8 @@ plugins { id 'com.adarshr.test-logger' version '3.2.0' apply false // https://github.com/davidburstrom/version-compatibility-gradle-plugin/tags id 'io.github.davidburstrom.version-compatibility' version '0.4.0' apply false - id "com.gradle.enterprise" version "3.12.2" + // https://plugins.gradle.org/plugin/com.gradle.enterprise + id 'com.gradle.enterprise' version '3.12.2' } dependencyResolutionManagement { From f71b28658bf015b20d7b3a4dc084c8b4fa4f0c19 Mon Sep 17 00:00:00 2001 From: Ned Twigg Date: Thu, 26 Jan 2023 11:07:37 -0800 Subject: [PATCH 667/757] Fix bug in changelog publish setup. --- gradle/java-publish.gradle | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/gradle/java-publish.gradle b/gradle/java-publish.gradle index 3d1ddd1c4f..7d2055d78d 100644 --- a/gradle/java-publish.gradle +++ b/gradle/java-publish.gradle @@ -186,14 +186,12 @@ if (!version.endsWith('-SNAPSHOT')) { } // ensures that changelog bump and push only happens if the publish was successful def thisProj = project - afterEvaluate { - changelogTasks.named('changelogBump').configure { - dependsOn thisProj.tasks.named('publishPluginMavenPublicationToSonatypeRepository') - dependsOn rootProject.tasks.named('closeAndReleaseSonatypeStagingRepository') - // if we have a gradle plugin, we need to push it up to the plugin portal too - if (thisProj.tasks.names.contains('publishPlugins')) { - dependsOn thisProj.tasks.named('publishPlugins') - } + changelogTasks.named('changelogBump').configure { + dependsOn ":${thisProj.path}:publishPluginMavenPublicationToSonatypeRepository" + dependsOn ":closeAndReleaseSonatypeStagingRepository" + // if we have a gradle plugin, we need to push it up to the plugin portal too + if (thisProj.tasks.names.contains('publishPlugins')) { + dependsOn thisProj.tasks.named('publishPlugins') } } } From 0d34fa703536b7f83b35d45f7eea153d724e2cc3 Mon Sep 17 00:00:00 2001 From: Benoit Lacelle Date: Thu, 26 Jan 2023 23:20:30 +0400 Subject: [PATCH 668/757] Switch from new File() to a Sentinel reference --- .../java/com/diffplug/spotless/Formatter.java | 6 ++- .../com/diffplug/spotless/FormatterStep.java | 6 +-- .../diffplug/spotless/FormatterStepImpl.java | 9 ++--- .../com/diffplug/spotless/FormatterTest.java | 38 +++++++++++++++++-- 4 files changed, 45 insertions(+), 14 deletions(-) diff --git a/lib/src/main/java/com/diffplug/spotless/Formatter.java b/lib/src/main/java/com/diffplug/spotless/Formatter.java index 3a38893cd6..be045e7fe1 100644 --- a/lib/src/main/java/com/diffplug/spotless/Formatter.java +++ b/lib/src/main/java/com/diffplug/spotless/Formatter.java @@ -39,6 +39,9 @@ public final class Formatter implements Serializable, AutoCloseable { private static final long serialVersionUID = 1L; + // This Sentinel reference may be used where Formatter requires a File, while there is no actual File to format + public static final File SENTINEL_NO_FILE_ON_DISK = new File("NO_FILE_ON_DISK.sentinel"); + private LineEnding.Policy lineEndingsPolicy; private Charset encoding; private Path rootDir; @@ -237,8 +240,7 @@ public String compute(String unix, File file) { unix = LineEnding.toUnix(formatted); } } catch (Throwable e) { - if (file.getPath().isEmpty()) { - // Path.relativize would fail if rootDir is an absolute path + if (file == SENTINEL_NO_FILE_ON_DISK) { exceptionPolicy.handleError(e, step, ""); } else { // Path may be forged from a different FileSystem than Filesystem.default diff --git a/lib/src/main/java/com/diffplug/spotless/FormatterStep.java b/lib/src/main/java/com/diffplug/spotless/FormatterStep.java index 5729f676b2..79793a403e 100644 --- a/lib/src/main/java/com/diffplug/spotless/FormatterStep.java +++ b/lib/src/main/java/com/diffplug/spotless/FormatterStep.java @@ -1,5 +1,5 @@ /* - * Copyright 2016-2021 DiffPlug + * Copyright 2016-2023 DiffPlug * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -37,8 +37,8 @@ public interface FormatterStep extends Serializable { * @param rawUnix * the content to format, guaranteed to have unix-style newlines ('\n'); never null * @param file - * the file which {@code rawUnix} was obtained from; never null. Pass an empty file using - * {@code new File("")} if and only if no file is actually associated with {@code rawUnix} + * the file which {@code rawUnix} was obtained from; never null. Pass the reference + * {@code Formatter#SENTINEL_NO_FILE_ON_DISK} if and only if no file is actually associated with {@code rawUnix} * @return the formatted content, guaranteed to only have unix-style newlines; may return null * if the formatter step doesn't have any changes to make * @throws Exception if the formatter step experiences a problem diff --git a/lib/src/main/java/com/diffplug/spotless/FormatterStepImpl.java b/lib/src/main/java/com/diffplug/spotless/FormatterStepImpl.java index 7663145f51..fe7cabca49 100644 --- a/lib/src/main/java/com/diffplug/spotless/FormatterStepImpl.java +++ b/lib/src/main/java/com/diffplug/spotless/FormatterStepImpl.java @@ -1,5 +1,5 @@ /* - * Copyright 2016-2022 DiffPlug + * Copyright 2016-2023 DiffPlug * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -109,18 +109,15 @@ protected String format(Integer state, String rawUnix, File file) throws Excepti if (formatter == null) { formatter = formatterSupplier.get(); if (formatter instanceof FormatterFunc.Closeable) { - throw new AssertionError("NeverUpToDate does not support FormatterFunc.Closeable. See https://github.com/diffplug/spotless/pull/284"); + throw new AssertionError("NeverUpToDate does not support FormatterFunc.Closeable. See https://github.com/diffplug/spotless/pull/284"); } } return formatter.apply(rawUnix, file); } } - /** A dummy SENTINEL file. */ - static final File SENTINEL = new File(""); - static void checkNotSentinel(File file) { - if (file == SENTINEL) { + if (file == Formatter.SENTINEL_NO_FILE_ON_DISK) { throw new IllegalArgumentException("This step requires the underlying file. If this is a test, use StepHarnessWithFile"); } } diff --git a/testlib/src/test/java/com/diffplug/spotless/FormatterTest.java b/testlib/src/test/java/com/diffplug/spotless/FormatterTest.java index 0faf40bb95..de96cd2ae3 100644 --- a/testlib/src/test/java/com/diffplug/spotless/FormatterTest.java +++ b/testlib/src/test/java/com/diffplug/spotless/FormatterTest.java @@ -18,6 +18,7 @@ import java.io.File; import java.nio.charset.Charset; import java.nio.charset.StandardCharsets; +import java.nio.file.FileSystem; import java.nio.file.FileSystems; import java.nio.file.Path; import java.nio.file.Paths; @@ -94,7 +95,7 @@ protected Formatter create() { }.testEquals(); } - // new File("") can be used if there is no File representing this content. It should not conflict with rootDir.relativize(...) + // new File("") as filePath is known to fail @Test public void testExceptionWithEmptyPath() throws Exception { LineEnding.Policy lineEndingsPolicy = LineEnding.UNIX.createPolicy(); @@ -116,7 +117,32 @@ public void testExceptionWithEmptyPath() throws Exception { .exceptionPolicy(exceptionPolicy) .build(); - formatter.compute("someFileContent", new File("")); + Assertions.assertThrows(IllegalArgumentException.class, () -> formatter.compute("someFileContent", new File(""))); + } + + // If there is no File actually holding the content, one may rely on Formatter.NO_FILE_ON_DISK + @Test + public void testExceptionWithSentinelNoFileOnDisk() throws Exception { + LineEnding.Policy lineEndingsPolicy = LineEnding.UNIX.createPolicy(); + Charset encoding = StandardCharsets.UTF_8; + FormatExceptionPolicy exceptionPolicy = FormatExceptionPolicy.failOnlyOnError(); + + Path rootDir = Paths.get(StandardSystemProperty.USER_DIR.value()); + + FormatterStep step = Mockito.mock(FormatterStep.class); + Mockito.when(step.getName()).thenReturn("someFailingStep"); + Mockito.when(step.format(Mockito.anyString(), Mockito.any(File.class))).thenThrow(new IllegalArgumentException("someReason")); + List steps = Collections.singletonList(step); + + Formatter formatter = Formatter.builder() + .lineEndingsPolicy(lineEndingsPolicy) + .encoding(encoding) + .rootDir(rootDir) + .steps(steps) + .exceptionPolicy(exceptionPolicy) + .build(); + + formatter.compute("someFileContent", Formatter.SENTINEL_NO_FILE_ON_DISK); } // rootDir may be a path not from the default FileSystem @@ -127,6 +153,12 @@ public void testExceptionWithRootDirIsNotFileSystem() throws Exception { FormatExceptionPolicy exceptionPolicy = FormatExceptionPolicy.failOnlyOnError(); Path rootDir = Mockito.mock(Path.class); + FileSystem customFileSystem = Mockito.mock(FileSystem.class); + Mockito.when(rootDir.getFileSystem()).thenReturn(customFileSystem); + + Path pathFromFile = Mockito.mock(Path.class); + Mockito.when(customFileSystem.getPath(Mockito.anyString())).thenReturn(pathFromFile); + Path relativized = Mockito.mock(Path.class); Mockito.when(rootDir.relativize(Mockito.any(Path.class))).then(invok -> { Path filePath = invok.getArgument(0); @@ -150,7 +182,7 @@ public void testExceptionWithRootDirIsNotFileSystem() throws Exception { .exceptionPolicy(exceptionPolicy) .build(); - formatter.compute("someFileContent", new File("")); + formatter.compute("someFileContent", new File("/some/folder/some.file")); } } From c55e736b620456bfae55e1cac26619bb20c827a4 Mon Sep 17 00:00:00 2001 From: Ned Twigg Date: Thu, 26 Jan 2023 11:29:08 -0800 Subject: [PATCH 669/757] Published lib/2.33.0 --- CHANGES.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/CHANGES.md b/CHANGES.md index 363dac1758..22e568f566 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -10,6 +10,8 @@ This document is intended for Spotless developers. We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format (starting after version `1.27.0`). ## [Unreleased] + +## [2.33.0] - 2023-01-26 ### Added * `ProcessRunner` has added some convenience methods so it can be used for maven testing. ([#1496](https://github.com/diffplug/spotless/pull/1496)) * `ProcessRunner` allows to limit captured output to a certain number of bytes. ([#1511](https://github.com/diffplug/spotless/pull/1511)) From dbea734458f3323cf121f84744838fa865c1a1a6 Mon Sep 17 00:00:00 2001 From: Benoit Lacelle Date: Thu, 26 Jan 2023 23:33:27 +0400 Subject: [PATCH 670/757] Refactor mire usages --- lib/src/main/java/com/diffplug/spotless/FormatterFunc.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/src/main/java/com/diffplug/spotless/FormatterFunc.java b/lib/src/main/java/com/diffplug/spotless/FormatterFunc.java index 48a8e810ee..8a8a15076e 100644 --- a/lib/src/main/java/com/diffplug/spotless/FormatterFunc.java +++ b/lib/src/main/java/com/diffplug/spotless/FormatterFunc.java @@ -127,7 +127,7 @@ public String apply(String unix, File file) throws Exception { @Override public String apply(String unix) throws Exception { - return apply(unix, FormatterStepImpl.SENTINEL); + return apply(unix, Formatter.SENTINEL_NO_FILE_ON_DISK); } }; } @@ -156,7 +156,7 @@ default String apply(String unix, File file) throws Exception { @Override default String apply(String unix) throws Exception { - return apply(unix, FormatterStepImpl.SENTINEL); + return apply(unix, Formatter.SENTINEL_NO_FILE_ON_DISK); } } } From 378a4e8e7f022320b4f0d26844ff390025ee0992 Mon Sep 17 00:00:00 2001 From: Benoit Lacelle Date: Thu, 26 Jan 2023 23:39:00 +0400 Subject: [PATCH 671/757] Fix style --- lib/src/main/java/com/diffplug/spotless/FormatterFunc.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/src/main/java/com/diffplug/spotless/FormatterFunc.java b/lib/src/main/java/com/diffplug/spotless/FormatterFunc.java index 8a8a15076e..90d576e8a0 100644 --- a/lib/src/main/java/com/diffplug/spotless/FormatterFunc.java +++ b/lib/src/main/java/com/diffplug/spotless/FormatterFunc.java @@ -1,5 +1,5 @@ /* - * Copyright 2016-2021 DiffPlug + * Copyright 2016-2023 DiffPlug * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. From 4439934095209a332a8b1cfe1037756cbe878108 Mon Sep 17 00:00:00 2001 From: Benoit Lacelle Date: Thu, 26 Jan 2023 23:48:21 +0400 Subject: [PATCH 672/757] Rely on existing Sentinel --- lib/src/main/java/com/diffplug/spotless/Formatter.java | 5 +---- lib/src/main/java/com/diffplug/spotless/FormatterFunc.java | 6 +++--- lib/src/main/java/com/diffplug/spotless/FormatterStep.java | 2 +- .../main/java/com/diffplug/spotless/FormatterStepImpl.java | 7 +++++-- 4 files changed, 10 insertions(+), 10 deletions(-) diff --git a/lib/src/main/java/com/diffplug/spotless/Formatter.java b/lib/src/main/java/com/diffplug/spotless/Formatter.java index be045e7fe1..035452e29c 100644 --- a/lib/src/main/java/com/diffplug/spotless/Formatter.java +++ b/lib/src/main/java/com/diffplug/spotless/Formatter.java @@ -39,9 +39,6 @@ public final class Formatter implements Serializable, AutoCloseable { private static final long serialVersionUID = 1L; - // This Sentinel reference may be used where Formatter requires a File, while there is no actual File to format - public static final File SENTINEL_NO_FILE_ON_DISK = new File("NO_FILE_ON_DISK.sentinel"); - private LineEnding.Policy lineEndingsPolicy; private Charset encoding; private Path rootDir; @@ -240,7 +237,7 @@ public String compute(String unix, File file) { unix = LineEnding.toUnix(formatted); } } catch (Throwable e) { - if (file == SENTINEL_NO_FILE_ON_DISK) { + if (file == FormatterStepImpl.SENTINEL) { exceptionPolicy.handleError(e, step, ""); } else { // Path may be forged from a different FileSystem than Filesystem.default diff --git a/lib/src/main/java/com/diffplug/spotless/FormatterFunc.java b/lib/src/main/java/com/diffplug/spotless/FormatterFunc.java index 90d576e8a0..48a8e810ee 100644 --- a/lib/src/main/java/com/diffplug/spotless/FormatterFunc.java +++ b/lib/src/main/java/com/diffplug/spotless/FormatterFunc.java @@ -1,5 +1,5 @@ /* - * Copyright 2016-2023 DiffPlug + * Copyright 2016-2021 DiffPlug * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -127,7 +127,7 @@ public String apply(String unix, File file) throws Exception { @Override public String apply(String unix) throws Exception { - return apply(unix, Formatter.SENTINEL_NO_FILE_ON_DISK); + return apply(unix, FormatterStepImpl.SENTINEL); } }; } @@ -156,7 +156,7 @@ default String apply(String unix, File file) throws Exception { @Override default String apply(String unix) throws Exception { - return apply(unix, Formatter.SENTINEL_NO_FILE_ON_DISK); + return apply(unix, FormatterStepImpl.SENTINEL); } } } diff --git a/lib/src/main/java/com/diffplug/spotless/FormatterStep.java b/lib/src/main/java/com/diffplug/spotless/FormatterStep.java index 79793a403e..11a4d5f99e 100644 --- a/lib/src/main/java/com/diffplug/spotless/FormatterStep.java +++ b/lib/src/main/java/com/diffplug/spotless/FormatterStep.java @@ -38,7 +38,7 @@ public interface FormatterStep extends Serializable { * the content to format, guaranteed to have unix-style newlines ('\n'); never null * @param file * the file which {@code rawUnix} was obtained from; never null. Pass the reference - * {@code Formatter#SENTINEL_NO_FILE_ON_DISK} if and only if no file is actually associated with {@code rawUnix} + * {@code FormatterStepImpl#SENTINEL} if and only if no file is actually associated with {@code rawUnix} * @return the formatted content, guaranteed to only have unix-style newlines; may return null * if the formatter step doesn't have any changes to make * @throws Exception if the formatter step experiences a problem diff --git a/lib/src/main/java/com/diffplug/spotless/FormatterStepImpl.java b/lib/src/main/java/com/diffplug/spotless/FormatterStepImpl.java index fe7cabca49..3b1b5cf278 100644 --- a/lib/src/main/java/com/diffplug/spotless/FormatterStepImpl.java +++ b/lib/src/main/java/com/diffplug/spotless/FormatterStepImpl.java @@ -109,15 +109,18 @@ protected String format(Integer state, String rawUnix, File file) throws Excepti if (formatter == null) { formatter = formatterSupplier.get(); if (formatter instanceof FormatterFunc.Closeable) { - throw new AssertionError("NeverUpToDate does not support FormatterFunc.Closeable. See https://github.com/diffplug/spotless/pull/284"); + throw new AssertionError("NeverUpToDate does not support FormatterFunc.Closeable. See https://github.com/diffplug/spotless/pull/284"); } } return formatter.apply(rawUnix, file); } } + /**This Sentinel reference may be used where Formatter requires a File, while there is no actual File to format */ + public static final File SENTINEL = new File(""); + static void checkNotSentinel(File file) { - if (file == Formatter.SENTINEL_NO_FILE_ON_DISK) { + if (file == SENTINEL) { throw new IllegalArgumentException("This step requires the underlying file. If this is a test, use StepHarnessWithFile"); } } From 7f7cc49fed67ea9b8fc5706427dfc16c830570e0 Mon Sep 17 00:00:00 2001 From: Benoit Lacelle Date: Thu, 26 Jan 2023 23:54:13 +0400 Subject: [PATCH 673/757] Fix compilation --- testlib/src/test/java/com/diffplug/spotless/FormatterTest.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/testlib/src/test/java/com/diffplug/spotless/FormatterTest.java b/testlib/src/test/java/com/diffplug/spotless/FormatterTest.java index de96cd2ae3..76f11b3d15 100644 --- a/testlib/src/test/java/com/diffplug/spotless/FormatterTest.java +++ b/testlib/src/test/java/com/diffplug/spotless/FormatterTest.java @@ -142,7 +142,7 @@ public void testExceptionWithSentinelNoFileOnDisk() throws Exception { .exceptionPolicy(exceptionPolicy) .build(); - formatter.compute("someFileContent", Formatter.SENTINEL_NO_FILE_ON_DISK); + formatter.compute("someFileContent", FormatterStepImpl.SENTINEL); } // rootDir may be a path not from the default FileSystem From 27522dc85e2a368cb8e0d60b3f162fc186ea25e0 Mon Sep 17 00:00:00 2001 From: Ned Twigg Date: Thu, 26 Jan 2023 12:00:39 -0800 Subject: [PATCH 674/757] Start publishing against the `release` branch to fix a new issue with GitHub branch protection. It will be a manual process to move `main` towards `release` after a release is complete. --- gradle/changelog.gradle | 1 + 1 file changed, 1 insertion(+) diff --git a/gradle/changelog.gradle b/gradle/changelog.gradle index 316e98a2d7..83c16f474e 100644 --- a/gradle/changelog.gradle +++ b/gradle/changelog.gradle @@ -17,6 +17,7 @@ spotlessChangelog { // need -Prelease=true in order to do a publish appendDashSnapshotUnless_dashPrelease=true + branch 'release' tagPrefix "${kind}/" commitMessage "Published ${kind}/{{version}}" // {{version}} will be replaced } From 2aa7f51bc665e23b685c2a6df9fa930584ad8b3c Mon Sep 17 00:00:00 2001 From: Ned Twigg Date: Thu, 26 Jan 2023 12:06:53 -0800 Subject: [PATCH 675/757] Another shot at fixing our publish workflow. --- .github/workflows/deploy.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml index d41dc8fc30..b2a8f58cf0 100644 --- a/.github/workflows/deploy.yml +++ b/.github/workflows/deploy.yml @@ -46,6 +46,8 @@ jobs: uses: gradle/gradle-build-action@v2 with: gradle-home-cache-cleanup: true + - name: git fetch origin release + run: git fetch origin release - name: publish all if: "${{ github.event.inputs.to_publish == 'all' }}" run: | From 2995371d0baf3707886cc387c91c58b9f7ebbe95 Mon Sep 17 00:00:00 2001 From: Ned Twigg Date: Thu, 26 Jan 2023 12:12:38 -0800 Subject: [PATCH 676/757] So we have to run the workflow on the `release` branch, *and* we need to pull `main` so that git ratchet is happy. --- .github/workflows/deploy.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml index b2a8f58cf0..e692fe8735 100644 --- a/.github/workflows/deploy.yml +++ b/.github/workflows/deploy.yml @@ -46,8 +46,8 @@ jobs: uses: gradle/gradle-build-action@v2 with: gradle-home-cache-cleanup: true - - name: git fetch origin release - run: git fetch origin release + - name: git fetch origin main + run: git fetch origin main - name: publish all if: "${{ github.event.inputs.to_publish == 'all' }}" run: | From f1cfc6189fb0d52d6239348594c6daecb0ce7997 Mon Sep 17 00:00:00 2001 From: runner Date: Thu, 26 Jan 2023 20:16:06 +0000 Subject: [PATCH 677/757] Published gradle/6.14.0 --- plugin-gradle/CHANGES.md | 2 ++ plugin-gradle/README.md | 50 ++++++++++++++++++++-------------------- 2 files changed, 27 insertions(+), 25 deletions(-) diff --git a/plugin-gradle/CHANGES.md b/plugin-gradle/CHANGES.md index 8d01068383..49ef0adbbe 100644 --- a/plugin-gradle/CHANGES.md +++ b/plugin-gradle/CHANGES.md @@ -3,6 +3,8 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format (starting after version `3.27.0`). ## [Unreleased] + +## [6.14.0] - 2023-01-26 ### Added * Support `jackson()` for YAML and JSON files ([#1492](https://github.com/diffplug/spotless/pull/1492)) * Prettier will now suggest to install plugins if a parser cannot be inferred from the file extension ([#1511](https://github.com/diffplug/spotless/pull/1511)) diff --git a/plugin-gradle/README.md b/plugin-gradle/README.md index 7e486719e7..67f3cdd69f 100644 --- a/plugin-gradle/README.md +++ b/plugin-gradle/README.md @@ -18,9 +18,9 @@ output = [ --> [![Gradle plugin](https://img.shields.io/badge/plugins.gradle.org-com.diffplug.spotless-blue.svg)](https://plugins.gradle.org/plugin/com.diffplug.spotless) [![Maven central](https://img.shields.io/badge/mavencentral-yes-blue.svg)](https://search.maven.org/#search%7Cgav%7C1%7Cg%3A%22com.diffplug.spotless%22%20AND%20a%3A%22spotless-plugin-gradle%22) -[![Javadoc](https://img.shields.io/badge/javadoc-yes-blue.svg)](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.13.0/index.html) +[![Javadoc](https://img.shields.io/badge/javadoc-yes-blue.svg)](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.14.0/index.html) [![License Apache](https://img.shields.io/badge/license-apache-blue.svg)](https://tldrlegal.com/license/apache-license-2.0-(apache-2.0)) -[![Changelog](https://img.shields.io/badge/changelog-6.13.0-blue.svg)](CHANGES.md) +[![Changelog](https://img.shields.io/badge/changelog-6.14.0-blue.svg)](CHANGES.md) [![Circle CI](https://circleci.com/gh/diffplug/spotless/tree/main.svg?style=shield)](https://circleci.com/gh/diffplug/spotless/tree/main) [![Live chat](https://img.shields.io/badge/gitter-chat-brightgreen.svg)](https://gitter.im/diffplug/spotless) @@ -129,10 +129,10 @@ spotless { ``` Spotless consists of a list of formats (in the example above, `misc` and `java`), and each format has: -- a `target` (the files to format), which you set with [`target`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.13.0/com/diffplug/gradle/spotless/FormatExtension.html#target-java.lang.Object...-) and [`targetExclude`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.13.0/com/diffplug/gradle/spotless/FormatExtension.html#targetExclude-java.lang.Object...-) -- a list of `FormatterStep`, which are just `String -> String` functions, such as [`replace`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.13.0/com/diffplug/gradle/spotless/FormatExtension.html#replace-java.lang.String-java.lang.CharSequence-java.lang.CharSequence-), [`replaceRegex`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.13.0/com/diffplug/gradle/spotless/FormatExtension.html#replaceRegex-java.lang.String-java.lang.String-java.lang.String-), [`trimTrailingWhitespace`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.13.0/com/diffplug/gradle/spotless/FormatExtension.html#replace-java.lang.String-java.lang.CharSequence-java.lang.CharSequence-), [`custom`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.13.0/com/diffplug/gradle/spotless/FormatExtension.html#custom-java.lang.String-groovy.lang.Closure-), [`prettier`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.13.0/com/diffplug/gradle/spotless/FormatExtension.html#prettier--), [`eclipseWtp`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.13.0/com/diffplug/gradle/spotless/FormatExtension.html#eclipseWtp-com.diffplug.spotless.extra.wtp.EclipseWtpFormatterStep-), [`licenseHeader`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.13.0/com/diffplug/gradle/spotless/FormatExtension.html#licenseHeader-java.lang.String-java.lang.String-) etc. +- a `target` (the files to format), which you set with [`target`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.14.0/com/diffplug/gradle/spotless/FormatExtension.html#target-java.lang.Object...-) and [`targetExclude`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.14.0/com/diffplug/gradle/spotless/FormatExtension.html#targetExclude-java.lang.Object...-) +- a list of `FormatterStep`, which are just `String -> String` functions, such as [`replace`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.14.0/com/diffplug/gradle/spotless/FormatExtension.html#replace-java.lang.String-java.lang.CharSequence-java.lang.CharSequence-), [`replaceRegex`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.14.0/com/diffplug/gradle/spotless/FormatExtension.html#replaceRegex-java.lang.String-java.lang.String-java.lang.String-), [`trimTrailingWhitespace`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.14.0/com/diffplug/gradle/spotless/FormatExtension.html#replace-java.lang.String-java.lang.CharSequence-java.lang.CharSequence-), [`custom`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.14.0/com/diffplug/gradle/spotless/FormatExtension.html#custom-java.lang.String-groovy.lang.Closure-), [`prettier`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.14.0/com/diffplug/gradle/spotless/FormatExtension.html#prettier--), [`eclipseWtp`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.14.0/com/diffplug/gradle/spotless/FormatExtension.html#eclipseWtp-com.diffplug.spotless.extra.wtp.EclipseWtpFormatterStep-), [`licenseHeader`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.14.0/com/diffplug/gradle/spotless/FormatExtension.html#licenseHeader-java.lang.String-java.lang.String-) etc. -All the generic steps live in [`FormatExtension`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.13.0/com/diffplug/gradle/spotless/FormatExtension.html), and there are many language-specific steps which live in its language-specific subclasses, which are described below. +All the generic steps live in [`FormatExtension`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.14.0/com/diffplug/gradle/spotless/FormatExtension.html), and there are many language-specific steps which live in its language-specific subclasses, which are described below. ### Requirements @@ -144,7 +144,7 @@ If you're stuck on an older version of Gradle, `id 'com.diffplug.gradle.spotless ## Java -`com.diffplug.gradle.spotless.JavaExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.13.0/com/diffplug/gradle/spotless/JavaExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/JavaExtension.java) +`com.diffplug.gradle.spotless.JavaExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.14.0/com/diffplug/gradle/spotless/JavaExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/JavaExtension.java) ```gradle spotless { @@ -268,8 +268,8 @@ You can make a pull request to add new annotations to Spotless's default list. ## Groovy -- `com.diffplug.gradle.spotless.GroovyExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.13.0/com/diffplug/gradle/spotless/GroovyExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/GroovyExtension.java) -- `com.diffplug.gradle.spotless.GroovyGradleExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.13.0/com/diffplug/gradle/spotless/GroovyGradleExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/GroovyGradleExtension.java) +- `com.diffplug.gradle.spotless.GroovyExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.14.0/com/diffplug/gradle/spotless/GroovyExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/GroovyExtension.java) +- `com.diffplug.gradle.spotless.GroovyGradleExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.14.0/com/diffplug/gradle/spotless/GroovyGradleExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/GroovyGradleExtension.java) Configuration for Groovy is similar to [Java](#java), in that it also supports `licenseHeader` and `importOrder`. @@ -320,8 +320,8 @@ Groovy-Eclipse formatting errors/warnings lead per default to a build failure. T ## Kotlin -- `com.diffplug.gradle.spotless.KotlinExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.13.0/com/diffplug/gradle/spotless/KotlinExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/KotlinExtension.java) -- `com.diffplug.gradle.spotless.KotlinGradleExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.13.0/com/diffplug/gradle/spotless/KotlinGradleExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/KotlinGradleExtension.java) +- `com.diffplug.gradle.spotless.KotlinExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.14.0/com/diffplug/gradle/spotless/KotlinExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/KotlinExtension.java) +- `com.diffplug.gradle.spotless.KotlinGradleExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.14.0/com/diffplug/gradle/spotless/KotlinGradleExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/KotlinGradleExtension.java) ```gradle spotless { // if you are using build.gradle.kts, instead of 'spotless {' use: @@ -392,7 +392,7 @@ spotless { ## Scala -`com.diffplug.gradle.spotless.ScalaExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.13.0/com/diffplug/gradle/spotless/ScalaExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/ScalaExtension.java) +`com.diffplug.gradle.spotless.ScalaExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.14.0/com/diffplug/gradle/spotless/ScalaExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/ScalaExtension.java) ```gradle spotless { @@ -424,7 +424,7 @@ spotless { ## C/C++ -`com.diffplug.gradle.spotless.CppExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.13.0/com/diffplug/gradle/spotless/CppExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/CppExtension.java) +`com.diffplug.gradle.spotless.CppExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.14.0/com/diffplug/gradle/spotless/CppExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/CppExtension.java) ```gradle spotless { @@ -456,7 +456,7 @@ spotles { ## Python -`com.diffplug.gradle.spotless.PythonExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.13.0/com/diffplug/gradle/spotless/PythonExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/PythonExtension.java) +`com.diffplug.gradle.spotless.PythonExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.14.0/com/diffplug/gradle/spotless/PythonExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/PythonExtension.java) ```gradle spotless { @@ -490,7 +490,7 @@ black().pathToExe('C:/myuser/.pyenv/versions/3.8.0/scripts/black.exe') ## FreshMark -`com.diffplug.gradle.spotless.FreshMarkExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.13.0/com/diffplug/gradle/spotless/FreshMarkExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/FreshMarkExtension.java) +`com.diffplug.gradle.spotless.FreshMarkExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.14.0/com/diffplug/gradle/spotless/FreshMarkExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/FreshMarkExtension.java) [homepage](https://github.com/diffplug/freshmark). [changelog](https://github.com/diffplug/freshmark/blob/master/CHANGES.md). FreshMark lets you generate markdown in the comments of your markdown. This helps to keep badges and links up-to-date (see the source for this file), and can also be helpful for generating complex tables (see the source for [the parent readme](../README.md)). @@ -511,7 +511,7 @@ spotless { ## Antlr4 -`com.diffplug.gradle.spotless.Antlr4Extension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.13.0/com/diffplug/gradle/spotless/Antlr4Extension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/Antlr4Extension.java) +`com.diffplug.gradle.spotless.Antlr4Extension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.14.0/com/diffplug/gradle/spotless/Antlr4Extension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/Antlr4Extension.java) ```gradle spotless { @@ -536,7 +536,7 @@ antlr4formatter('1.2.1') // version is optional ## SQL -`com.diffplug.gradle.spotless.SqlExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.13.0/com/diffplug/gradle/spotless/SqlExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/SqlExtension.java) +`com.diffplug.gradle.spotless.SqlExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.14.0/com/diffplug/gradle/spotless/SqlExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/SqlExtension.java) ```gradle spotless { @@ -576,7 +576,7 @@ sql.formatter.indent.size=4 ## Typescript -- `com.diffplug.gradle.spotless.TypescriptExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.13.0/com/diffplug/gradle/spotless/TypescriptExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/TypescriptExtension.java) +- `com.diffplug.gradle.spotless.TypescriptExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.14.0/com/diffplug/gradle/spotless/TypescriptExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/TypescriptExtension.java) ```gradle spotless { @@ -668,7 +668,7 @@ For details, see the [npm detection](#npm-detection) and [`.npmrc` detection](#n ## Javascript -- `com.diffplug.gradle.spotless.JavascriptExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.13.0/com/diffplug/gradle/spotless/JavascriptExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/JavascriptExtension.java) +- `com.diffplug.gradle.spotless.JavascriptExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.14.0/com/diffplug/gradle/spotless/JavascriptExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/JavascriptExtension.java) ```gradle spotless { @@ -732,7 +732,7 @@ For details, see the [npm detection](#npm-detection) and [`.npmrc` detection](#n ## JSON -- `com.diffplug.gradle.spotless.JsonExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.13.0/com/diffplug/gradle/spotless/JsonExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/JsonExtension.java) +- `com.diffplug.gradle.spotless.JsonExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.14.0/com/diffplug/gradle/spotless/JsonExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/JsonExtension.java) ```gradle spotless { @@ -807,7 +807,7 @@ spotless { ## YAML -- `com.diffplug.gradle.spotless.YamlExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.13.0/com/diffplug/gradle/spotless/JsonExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/YamlExtension.java) +- `com.diffplug.gradle.spotless.YamlExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.14.0/com/diffplug/gradle/spotless/JsonExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/YamlExtension.java) ```gradle spotless { @@ -1020,7 +1020,7 @@ Once a file's license header has a valid year, whether it is a year (`2020`) or * `2017` -> `2017-2020` * `2017-2019` -> `2017-2020` -See the [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.13.0/com/diffplug/gradle/spotless/FormatExtension.LicenseHeaderConfig.html) for a complete listing of options. +See the [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.14.0/com/diffplug/gradle/spotless/FormatExtension.LicenseHeaderConfig.html) for a complete listing of options. @@ -1093,9 +1093,9 @@ spotless { custom 'lowercase', { str -> str.toLowerCase() } ``` -However, custom rules will disable up-to-date checking and caching, unless you read [this javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.13.0/com/diffplug/gradle/spotless/FormatExtension.html#bumpThisNumberIfACustomStepChanges-int-) and follow its instructions carefully. +However, custom rules will disable up-to-date checking and caching, unless you read [this javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.14.0/com/diffplug/gradle/spotless/FormatExtension.html#bumpThisNumberIfACustomStepChanges-int-) and follow its instructions carefully. -Another option is to create proper `FormatterStep` in your `buildSrc`, and then call [`addStep`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.13.0/com/diffplug/gradle/spotless/FormatExtension.html#addStep-com.diffplug.spotless.FormatterStep-). The contributing guide describes [how to do this](https://github.com/diffplug/spotless/blob/main/CONTRIBUTING.md#how-to-add-a-new-formatterstep). If the step is generally-useful, we hope you'll open a PR to share it! +Another option is to create proper `FormatterStep` in your `buildSrc`, and then call [`addStep`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.14.0/com/diffplug/gradle/spotless/FormatExtension.html#addStep-com.diffplug.spotless.FormatterStep-). The contributing guide describes [how to do this](https://github.com/diffplug/spotless/blob/main/CONTRIBUTING.md#how-to-add-a-new-formatterstep). If the step is generally-useful, we hope you'll open a PR to share it! ```gradle @@ -1128,11 +1128,11 @@ spotless { format 'foo', com.acme.FooLanguageExtension, { ``` -If you'd like to create a one-off Spotless task outside of the `check`/`apply` framework, see [`FormatExtension.createIndependentApplyTask`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.13.0/com/diffplug/gradle/spotless/FormatExtension.html#createIndependentApplyTask-java.lang.String-). +If you'd like to create a one-off Spotless task outside of the `check`/`apply` framework, see [`FormatExtension.createIndependentApplyTask`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.14.0/com/diffplug/gradle/spotless/FormatExtension.html#createIndependentApplyTask-java.lang.String-). ## Inception (languages within languages within...) -In very rare cases, you might want to format e.g. javascript which is written inside JSP templates, or maybe java within a markdown file, or something wacky like that. You can specify hunks within a file using either open/close tags or a regex with a single capturing group, and then specify rules within it, like so. See [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.13.0/com/diffplug/gradle/spotless/FormatExtension.html#withinBlocks-java.lang.String-java.lang.String-java.lang.String-org.gradle.api.Action-) for more details. +In very rare cases, you might want to format e.g. javascript which is written inside JSP templates, or maybe java within a markdown file, or something wacky like that. You can specify hunks within a file using either open/close tags or a regex with a single capturing group, and then specify rules within it, like so. See [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.14.0/com/diffplug/gradle/spotless/FormatExtension.html#withinBlocks-java.lang.String-java.lang.String-java.lang.String-org.gradle.api.Action-) for more details. ```gradle import com.diffplug.gradle.spotless.JavaExtension From 07a57ff66f3fa0ffd8abea94e7c0f6ac4f025b5f Mon Sep 17 00:00:00 2001 From: Ned Twigg Date: Thu, 26 Jan 2023 12:18:26 -0800 Subject: [PATCH 678/757] Rename the sentinel and move it to `Formatter`. --- lib/src/main/java/com/diffplug/spotless/Formatter.java | 5 ++++- lib/src/main/java/com/diffplug/spotless/FormatterFunc.java | 6 +++--- .../main/java/com/diffplug/spotless/FormatterStepImpl.java | 5 +---- .../src/main/java/com/diffplug/spotless/StepHarness.java | 2 +- .../src/test/java/com/diffplug/spotless/FormatterTest.java | 2 +- 5 files changed, 10 insertions(+), 10 deletions(-) diff --git a/lib/src/main/java/com/diffplug/spotless/Formatter.java b/lib/src/main/java/com/diffplug/spotless/Formatter.java index 035452e29c..a55e8e6504 100644 --- a/lib/src/main/java/com/diffplug/spotless/Formatter.java +++ b/lib/src/main/java/com/diffplug/spotless/Formatter.java @@ -237,7 +237,7 @@ public String compute(String unix, File file) { unix = LineEnding.toUnix(formatted); } } catch (Throwable e) { - if (file == FormatterStepImpl.SENTINEL) { + if (file == NO_FILE_SENTINEL) { exceptionPolicy.handleError(e, step, ""); } else { // Path may be forged from a different FileSystem than Filesystem.default @@ -289,4 +289,7 @@ public void close() { } } } + + /** This Sentinel reference may be used to Formatter requires a File, while there is no actual File to format */ + public static final File NO_FILE_SENTINEL = new File("NO_FILE_SENTINEL"); } diff --git a/lib/src/main/java/com/diffplug/spotless/FormatterFunc.java b/lib/src/main/java/com/diffplug/spotless/FormatterFunc.java index 48a8e810ee..14b407a2eb 100644 --- a/lib/src/main/java/com/diffplug/spotless/FormatterFunc.java +++ b/lib/src/main/java/com/diffplug/spotless/FormatterFunc.java @@ -1,5 +1,5 @@ /* - * Copyright 2016-2021 DiffPlug + * Copyright 2016-2023 DiffPlug * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -127,7 +127,7 @@ public String apply(String unix, File file) throws Exception { @Override public String apply(String unix) throws Exception { - return apply(unix, FormatterStepImpl.SENTINEL); + return apply(unix, Formatter.NO_FILE_SENTINEL); } }; } @@ -156,7 +156,7 @@ default String apply(String unix, File file) throws Exception { @Override default String apply(String unix) throws Exception { - return apply(unix, FormatterStepImpl.SENTINEL); + return apply(unix, Formatter.NO_FILE_SENTINEL); } } } diff --git a/lib/src/main/java/com/diffplug/spotless/FormatterStepImpl.java b/lib/src/main/java/com/diffplug/spotless/FormatterStepImpl.java index 3b1b5cf278..17b62e75c6 100644 --- a/lib/src/main/java/com/diffplug/spotless/FormatterStepImpl.java +++ b/lib/src/main/java/com/diffplug/spotless/FormatterStepImpl.java @@ -116,11 +116,8 @@ protected String format(Integer state, String rawUnix, File file) throws Excepti } } - /**This Sentinel reference may be used where Formatter requires a File, while there is no actual File to format */ - public static final File SENTINEL = new File(""); - static void checkNotSentinel(File file) { - if (file == SENTINEL) { + if (file == Formatter.NO_FILE_SENTINEL) { throw new IllegalArgumentException("This step requires the underlying file. If this is a test, use StepHarnessWithFile"); } } diff --git a/testlib/src/main/java/com/diffplug/spotless/StepHarness.java b/testlib/src/main/java/com/diffplug/spotless/StepHarness.java index 71e2a663b5..c611cc738a 100644 --- a/testlib/src/main/java/com/diffplug/spotless/StepHarness.java +++ b/testlib/src/main/java/com/diffplug/spotless/StepHarness.java @@ -88,7 +88,7 @@ public AbstractStringAssert testResourceExceptionMsg(String resourceBefore) { public AbstractStringAssert testExceptionMsg(String before) { try { - formatter.compute(LineEnding.toUnix(before), FormatterStepImpl.SENTINEL); + formatter.compute(LineEnding.toUnix(before), Formatter.NO_FILE_SENTINEL); throw new SecurityException("Expected exception"); } catch (Throwable e) { if (e instanceof SecurityException) { diff --git a/testlib/src/test/java/com/diffplug/spotless/FormatterTest.java b/testlib/src/test/java/com/diffplug/spotless/FormatterTest.java index 76f11b3d15..314507bd8d 100644 --- a/testlib/src/test/java/com/diffplug/spotless/FormatterTest.java +++ b/testlib/src/test/java/com/diffplug/spotless/FormatterTest.java @@ -142,7 +142,7 @@ public void testExceptionWithSentinelNoFileOnDisk() throws Exception { .exceptionPolicy(exceptionPolicy) .build(); - formatter.compute("someFileContent", FormatterStepImpl.SENTINEL); + formatter.compute("someFileContent", Formatter.NO_FILE_SENTINEL); } // rootDir may be a path not from the default FileSystem From 5bef415be2d600d4b796301ca694de59b77b1171 Mon Sep 17 00:00:00 2001 From: runner Date: Thu, 26 Jan 2023 20:23:34 +0000 Subject: [PATCH 679/757] Published maven/2.31.0 --- plugin-maven/CHANGES.md | 2 ++ plugin-maven/README.md | 4 ++-- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/plugin-maven/CHANGES.md b/plugin-maven/CHANGES.md index 3967f468fd..ad79193ad8 100644 --- a/plugin-maven/CHANGES.md +++ b/plugin-maven/CHANGES.md @@ -3,6 +3,8 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format (starting after version `1.27.0`). ## [Unreleased] + +## [2.31.0] - 2023-01-26 ### Added * Prettier will now suggest to install plugins if a parser cannot be inferred from the file extension ([#1511](https://github.com/diffplug/spotless/pull/1511)) * Jackson (`json` and `yaml`) has new `spaceBeforeSeparator` option diff --git a/plugin-maven/README.md b/plugin-maven/README.md index f0fc2bb818..2ade34b67b 100644 --- a/plugin-maven/README.md +++ b/plugin-maven/README.md @@ -12,8 +12,8 @@ output = [ ].join('\n'); --> [![Maven central](https://img.shields.io/badge/mavencentral-com.diffplug.spotless%3Aspotless--maven--plugin-blue.svg)](https://search.maven.org/#search%7Cgav%7C1%7Cg%3A%22com.diffplug.spotless%22%20AND%20a%3A%22spotless-maven-plugin%22) -[![Javadoc](https://img.shields.io/badge/javadoc-yes-blue.svg)](https://javadoc.io/doc/com.diffplug.spotless/spotless-maven-plugin/2.30.0/index.html) -[![Changelog](https://img.shields.io/badge/changelog-2.30.0-brightgreen.svg)](CHANGES.md) +[![Javadoc](https://img.shields.io/badge/javadoc-yes-blue.svg)](https://javadoc.io/doc/com.diffplug.spotless/spotless-maven-plugin/2.31.0/index.html) +[![Changelog](https://img.shields.io/badge/changelog-2.31.0-brightgreen.svg)](CHANGES.md) [![Circle CI](https://circleci.com/gh/diffplug/spotless/tree/main.svg?style=shield)](https://circleci.com/gh/diffplug/spotless/tree/main) [![Live chat](https://img.shields.io/badge/gitter-chat-brightgreen.svg)](https://gitter.im/diffplug/spotless) From 9adce647c6dd3e605ddc555c5a972f32d9b192d4 Mon Sep 17 00:00:00 2001 From: Ned Twigg Date: Thu, 26 Jan 2023 12:25:17 -0800 Subject: [PATCH 680/757] Fix javadoc. --- lib/src/main/java/com/diffplug/spotless/Formatter.java | 2 +- lib/src/main/java/com/diffplug/spotless/FormatterStep.java | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/src/main/java/com/diffplug/spotless/Formatter.java b/lib/src/main/java/com/diffplug/spotless/Formatter.java index a55e8e6504..3470a3dc69 100644 --- a/lib/src/main/java/com/diffplug/spotless/Formatter.java +++ b/lib/src/main/java/com/diffplug/spotless/Formatter.java @@ -290,6 +290,6 @@ public void close() { } } - /** This Sentinel reference may be used to Formatter requires a File, while there is no actual File to format */ + /** This Sentinel reference may be used to pass string content to a Formatter or FormatterStep when there is no actual File to format */ public static final File NO_FILE_SENTINEL = new File("NO_FILE_SENTINEL"); } diff --git a/lib/src/main/java/com/diffplug/spotless/FormatterStep.java b/lib/src/main/java/com/diffplug/spotless/FormatterStep.java index 11a4d5f99e..ce09f68450 100644 --- a/lib/src/main/java/com/diffplug/spotless/FormatterStep.java +++ b/lib/src/main/java/com/diffplug/spotless/FormatterStep.java @@ -38,7 +38,7 @@ public interface FormatterStep extends Serializable { * the content to format, guaranteed to have unix-style newlines ('\n'); never null * @param file * the file which {@code rawUnix} was obtained from; never null. Pass the reference - * {@code FormatterStepImpl#SENTINEL} if and only if no file is actually associated with {@code rawUnix} + * {@link Formatter#NO_FILE_SENTINEL} if and only if no file is actually associated with {@code rawUnix} * @return the formatted content, guaranteed to only have unix-style newlines; may return null * if the formatter step doesn't have any changes to make * @throws Exception if the formatter step experiences a problem From 1f78affc868f275b92ad3db7aa9eb7ab3416c16d Mon Sep 17 00:00:00 2001 From: Ned Twigg Date: Thu, 26 Jan 2023 12:28:40 -0800 Subject: [PATCH 681/757] Update changelog. --- CHANGES.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/CHANGES.md b/CHANGES.md index 22e568f566..2af0ab7090 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -10,6 +10,8 @@ This document is intended for Spotless developers. We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format (starting after version `1.27.0`). ## [Unreleased] +### Added +* `Formatter` now has a field `public static final File NO_FILE_SENTINEL` which can be used to pass string content to a Formatter or FormatterStep when there is no actual File to format. ([#1525](https://github.com/diffplug/spotless/pull/1525)) ## [2.33.0] - 2023-01-26 ### Added From 599e1e450183b8492a79b3dd14d37485820f3ce8 Mon Sep 17 00:00:00 2001 From: runner Date: Thu, 26 Jan 2023 20:49:15 +0000 Subject: [PATCH 682/757] Published lib/2.34.0 --- CHANGES.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/CHANGES.md b/CHANGES.md index 2af0ab7090..1f27bbb299 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -10,6 +10,8 @@ This document is intended for Spotless developers. We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format (starting after version `1.27.0`). ## [Unreleased] + +## [2.34.0] - 2023-01-26 ### Added * `Formatter` now has a field `public static final File NO_FILE_SENTINEL` which can be used to pass string content to a Formatter or FormatterStep when there is no actual File to format. ([#1525](https://github.com/diffplug/spotless/pull/1525)) From 5c4fe0a02935cbdbb3f2bcacbea1948494c87190 Mon Sep 17 00:00:00 2001 From: Ned Twigg Date: Thu, 26 Jan 2023 11:12:46 -0800 Subject: [PATCH 683/757] Start compiling as Java 11 bytecode. --- gradle.properties | 2 +- gradle/java-setup.gradle | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/gradle.properties b/gradle.properties index d99bdac6ce..f06bdef37e 100644 --- a/gradle.properties +++ b/gradle.properties @@ -16,7 +16,7 @@ artifactIdMaven=spotless-maven-plugin artifactIdGradle=spotless-plugin-gradle # Build requirements -VER_JAVA=1.8 +VER_JAVA=11 VER_SPOTBUGS=4.7.3 VER_JSR_305=3.0.2 diff --git a/gradle/java-setup.gradle b/gradle/java-setup.gradle index 5de128bda7..10eca7a2d4 100644 --- a/gradle/java-setup.gradle +++ b/gradle/java-setup.gradle @@ -4,10 +4,10 @@ // setup java apply plugin: 'java' - -sourceCompatibility = VER_JAVA -targetCompatibility = VER_JAVA -tasks.withType(JavaCompile).configureEach { options.encoding = 'UTF-8' } +tasks.withType(JavaCompile).configureEach { + options.encoding = 'UTF-8' + options.release = Integer.parseInt(VER_JAVA) +} ////////////// // SPOTBUGS // From 63eb5589fd6e8d20d710124ea559cfee618a2024 Mon Sep 17 00:00:00 2001 From: Ned Twigg Date: Mon, 16 Jan 2023 19:49:23 -0800 Subject: [PATCH 684/757] Remove Java 8 workaround in EncodingErrorMsg. --- .../com/diffplug/spotless/EncodingErrorMsg.java | 14 ++++---------- 1 file changed, 4 insertions(+), 10 deletions(-) diff --git a/lib/src/main/java/com/diffplug/spotless/EncodingErrorMsg.java b/lib/src/main/java/com/diffplug/spotless/EncodingErrorMsg.java index 168bf9acff..3e4bb3423b 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-2022 DiffPlug + * Copyright 2016-2023 DiffPlug * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -15,7 +15,6 @@ */ package com.diffplug.spotless; -import java.nio.Buffer; import java.nio.ByteBuffer; import java.nio.CharBuffer; import java.nio.charset.Charset; @@ -116,8 +115,8 @@ private static void addIfAvailable(Collection charsets, String name) { } private void appendExample(Charset charset, boolean must) { - java8fix(byteBuf).clear(); - java8fix(charBuf).clear(); + byteBuf.clear(); + charBuf.clear(); CharsetDecoder decoder = charset.newDecoder(); if (!must) { @@ -135,7 +134,7 @@ private void appendExample(Charset charset, boolean must) { .onUnmappableCharacter(CodingErrorAction.REPLACE) .decode(byteBuf, charBuf, true); } - java8fix(charBuf).flip(); + charBuf.flip(); int start = Math.max(unrepresentable - CONTEXT, 0); int end = Math.min(charBuf.limit(), unrepresentable + CONTEXT + 1); @@ -147,9 +146,4 @@ 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; - } } From 2fe1bb2030d0690b6c60b26a95bbd9babca77383 Mon Sep 17 00:00:00 2001 From: Ned Twigg Date: Mon, 16 Jan 2023 19:53:45 -0800 Subject: [PATCH 685/757] Remove Java 8 workarounds from FeatureClassLoader. --- .../diffplug/spotless/FeatureClassLoader.java | 24 ++----------------- 1 file changed, 2 insertions(+), 22 deletions(-) diff --git a/lib/src/main/java/com/diffplug/spotless/FeatureClassLoader.java b/lib/src/main/java/com/diffplug/spotless/FeatureClassLoader.java index b4a69bef11..998c2082df 100644 --- a/lib/src/main/java/com/diffplug/spotless/FeatureClassLoader.java +++ b/lib/src/main/java/com/diffplug/spotless/FeatureClassLoader.java @@ -1,5 +1,5 @@ /* - * Copyright 2016-2022 DiffPlug + * Copyright 2016-2023 DiffPlug * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -24,8 +24,6 @@ import java.security.ProtectionDomain; import java.util.Objects; -import javax.annotation.Nullable; - /** * This class loader is used to load classes of Spotless features from a search * path of URLs.
@@ -113,25 +111,7 @@ private static ByteBuffer urlToByteBuffer(URL url) throws IOException { return ByteBuffer.wrap(buffer.toByteArray()); } - /** - * Making spotless Java 9+ compatible. In Java 8 (and minor) the bootstrap - * class loader saw every platform class. In Java 9+ it was changed so the - * bootstrap class loader does not see all classes anymore. This might lead - * to ClassNotFoundException in formatters (e.g. freshmark). - * - * @return null on Java 8 (and minor), otherwise PlatformClassLoader - */ - @Nullable private static ClassLoader getParentClassLoader() { - double version = Double.parseDouble(System.getProperty("java.specification.version")); - if (version > 1.8) { - try { - return (ClassLoader) ClassLoader.class.getMethod("getPlatformClassLoader").invoke(null); - } catch (Exception e) { - throw ThrowingEx.asRuntime(e); - } - } else { - return null; - } + return ThrowingEx.get(() -> (ClassLoader) ClassLoader.class.getMethod("getPlatformClassLoader").invoke(null)); } } From 1f1a53a25990870e2d40d5f953af3c0cf73e87f0 Mon Sep 17 00:00:00 2001 From: Ned Twigg Date: Thu, 26 Jan 2023 12:48:42 -0800 Subject: [PATCH 686/757] Use Java 11 methods to simplify FeatureClassLoader. --- .../java/com/diffplug/spotless/FeatureClassLoader.java | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/lib/src/main/java/com/diffplug/spotless/FeatureClassLoader.java b/lib/src/main/java/com/diffplug/spotless/FeatureClassLoader.java index 998c2082df..0703a91318 100644 --- a/lib/src/main/java/com/diffplug/spotless/FeatureClassLoader.java +++ b/lib/src/main/java/com/diffplug/spotless/FeatureClassLoader.java @@ -101,11 +101,8 @@ public URL findResource(String name) { private static ByteBuffer urlToByteBuffer(URL url) throws IOException { ByteArrayOutputStream buffer = new ByteArrayOutputStream(); - int nRead; - byte[] data = new byte[1024]; - InputStream inputStream = url.openStream(); - while ((nRead = inputStream.read(data, 0, data.length)) != -1) { - buffer.write(data, 0, nRead); + try (InputStream inputStream = url.openStream()) { + inputStream.transferTo(buffer); } buffer.flush(); return ByteBuffer.wrap(buffer.toByteArray()); From 77b24bdd325782e23334ab7ee350e7afb68587b4 Mon Sep 17 00:00:00 2001 From: Ned Twigg Date: Thu, 26 Jan 2023 12:52:20 -0800 Subject: [PATCH 687/757] Bump JGit and Mockito to latest (which required Java 11). --- gradle.properties | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/gradle.properties b/gradle.properties index f06bdef37e..dc4f24a36b 100644 --- a/gradle.properties +++ b/gradle.properties @@ -25,7 +25,7 @@ VER_SLF4J=[1.6,2.0[ # Used in multiple places VER_DURIAN=1.2.0 -VER_JGIT=5.13.1.202206130422-r +VER_JGIT=6.4.0.202211300538-r VER_JUNIT=5.9.2 VER_ASSERTJ=3.24.2 -VER_MOCKITO=4.11.0 +VER_MOCKITO=5.0.0 From a4db1d344b871b81c0b07bf0604a1037f9dbbe7d Mon Sep 17 00:00:00 2001 From: Ned Twigg Date: Thu, 26 Jan 2023 12:52:39 -0800 Subject: [PATCH 688/757] Update a stray old dep. --- lib/build.gradle | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/build.gradle b/lib/build.gradle index f2ca13ccb1..9d95007bc1 100644 --- a/lib/build.gradle +++ b/lib/build.gradle @@ -90,7 +90,7 @@ dependencies { compatKtLint0Dot48Dot0CompileAndTestOnly 'com.pinterest.ktlint:ktlint-ruleset-experimental:0.48.0' compatKtLint0Dot48Dot0CompileAndTestOnly 'com.pinterest.ktlint:ktlint-ruleset-standard:0.48.0' - String VER_SCALAFMT="3.6.1" + String VER_SCALAFMT="3.7.1" scalafmtCompileOnly "org.scalameta:scalafmt-core_2.13:$VER_SCALAFMT" String VER_DIKTAT = "1.2.4.2" From 0ba186ee1a1d99802ab2e0467d838837ef8b64c0 Mon Sep 17 00:00:00 2001 From: Ned Twigg Date: Thu, 26 Jan 2023 13:00:18 -0800 Subject: [PATCH 689/757] Update changelog. --- CHANGES.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/CHANGES.md b/CHANGES.md index 1f27bbb299..401998b233 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -10,6 +10,8 @@ This document is intended for Spotless developers. We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format (starting after version `1.27.0`). ## [Unreleased] +### Changes +* **POTENTIALLY BREAKING** Bump bytecode from Java 8 to 11 ([#1530](https://github.com/diffplug/spotless/pull/1530) part 2 of [#1337](https://github.com/diffplug/spotless/issues/1337)) ## [2.34.0] - 2023-01-26 ### Added From 4222e95f5726f13cb2d3268d149f372f1af12c66 Mon Sep 17 00:00:00 2001 From: "renovate[bot]" <29139614+renovate[bot]@users.noreply.github.com> Date: Thu, 26 Jan 2023 21:08:47 +0000 Subject: [PATCH 690/757] Update plugin com.diffplug.spotless to v6.14.0 --- settings.gradle | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/settings.gradle b/settings.gradle index a5bb6c0062..0ee51448dd 100644 --- a/settings.gradle +++ b/settings.gradle @@ -6,7 +6,7 @@ pluginManagement { } plugins { - id 'com.diffplug.spotless' version '6.13.0' apply false + id 'com.diffplug.spotless' version '6.14.0' apply false // https://plugins.gradle.org/plugin/com.gradle.plugin-publish id 'com.gradle.plugin-publish' version '1.1.0' apply false // https://github.com/gradle-nexus/publish-plugin/releases From 2046daf067bdbb350d078267a2b26a93deca58af Mon Sep 17 00:00:00 2001 From: Ned Twigg Date: Thu, 26 Jan 2023 13:16:49 -0800 Subject: [PATCH 691/757] Looks like spotbugs is stricter now that we're on Java 11. --- .../integration/DiffMessageFormatter.java | 31 ++++++++++--------- 1 file changed, 17 insertions(+), 14 deletions(-) diff --git a/lib-extra/src/main/java/com/diffplug/spotless/extra/integration/DiffMessageFormatter.java b/lib-extra/src/main/java/com/diffplug/spotless/extra/integration/DiffMessageFormatter.java index 15c43c815b..55336e8c04 100644 --- a/lib-extra/src/main/java/com/diffplug/spotless/extra/integration/DiffMessageFormatter.java +++ b/lib-extra/src/main/java/com/diffplug/spotless/extra/integration/DiffMessageFormatter.java @@ -1,5 +1,5 @@ /* - * Copyright 2016-2021 DiffPlug + * Copyright 2016-2023 DiffPlug * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -143,7 +143,7 @@ public String getMessage() { Objects.requireNonNull(runToFix, "runToFix"); Objects.requireNonNull(formatter, "formatter"); Objects.requireNonNull(problemFiles, "problemFiles"); - DiffMessageFormatter diffFormater = new DiffMessageFormatter(this); + DiffMessageFormatter diffFormater = new DiffMessageFormatter(formatter, problemFiles); return "The following files had format violations:\n" + diffFormater.buffer + runToFix; @@ -151,10 +151,6 @@ public String getMessage() { throw Errors.asRuntime(e); } } - - String relativePath(File file) { - return formatter.getRootDir().relativize(file.toPath()).toString(); - } } private static final int MAX_CHECK_MESSAGE_LINES = 50; @@ -163,25 +159,32 @@ String relativePath(File file) { private final StringBuilder buffer = new StringBuilder(MAX_CHECK_MESSAGE_LINES * 64); private int numLines = 0; - private DiffMessageFormatter(Builder builder) throws IOException { - ListIterator problemIter = builder.problemFiles.listIterator(); + private final CleanProvider formatter; + + private DiffMessageFormatter(CleanProvider formatter, List problemFiles) throws IOException { + this.formatter = Objects.requireNonNull(formatter, "formatter"); + ListIterator problemIter = problemFiles.listIterator(); while (problemIter.hasNext() && numLines < MAX_CHECK_MESSAGE_LINES) { File file = problemIter.next(); - addFile(builder.relativePath(file) + "\n" + DiffMessageFormatter.diff(builder, file)); + addFile(relativePath(file) + "\n" + diff(file)); } if (problemIter.hasNext()) { - int remainingFiles = builder.problemFiles.size() - problemIter.nextIndex(); + int remainingFiles = problemFiles.size() - problemIter.nextIndex(); if (remainingFiles >= MAX_FILES_TO_LIST) { buffer.append("Violations also present in ").append(remainingFiles).append(" other files.\n"); } else { buffer.append("Violations also present in:\n"); while (problemIter.hasNext()) { - addIntendedLine(NORMAL_INDENT, builder.relativePath(problemIter.next())); + addIntendedLine(NORMAL_INDENT, relativePath(problemIter.next())); } } } } + private String relativePath(File file) { + return formatter.getRootDir().relativize(file.toPath()).toString(); + } + private static final int MIN_LINES_PER_FILE = 4; private static final Splitter NEWLINE_SPLITTER = Splitter.on('\n'); @@ -230,10 +233,10 @@ private void addIntendedLine(String indent, String line) { * look like if formatted using the given formatter. Does not end with any newline * sequence (\n, \r, \r\n). */ - private static String diff(Builder builder, File file) throws IOException { - String raw = new String(Files.readAllBytes(file.toPath()), builder.formatter.getEncoding()); + private String diff(File file) throws IOException { + String raw = new String(Files.readAllBytes(file.toPath()), formatter.getEncoding()); String rawUnix = LineEnding.toUnix(raw); - String formatted = builder.formatter.getFormatted(file, rawUnix); + String formatted = formatter.getFormatted(file, rawUnix); String formattedUnix = LineEnding.toUnix(formatted); if (rawUnix.equals(formattedUnix)) { From 8e1865052fb0300123a2bed4ca271a945bde0574 Mon Sep 17 00:00:00 2001 From: Ned Twigg Date: Thu, 26 Jan 2023 13:49:53 -0800 Subject: [PATCH 692/757] spotlessApply for 2023 --- .../main/java/com/diffplug/spotless/markdown/FreshMarkStep.java | 2 +- .../java/com/diffplug/spotless/markdown/FreshMarkStepTest.java | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/src/main/java/com/diffplug/spotless/markdown/FreshMarkStep.java b/lib/src/main/java/com/diffplug/spotless/markdown/FreshMarkStep.java index fd03e95046..fca5ac39a4 100644 --- a/lib/src/main/java/com/diffplug/spotless/markdown/FreshMarkStep.java +++ b/lib/src/main/java/com/diffplug/spotless/markdown/FreshMarkStep.java @@ -1,5 +1,5 @@ /* - * Copyright 2016-2022 DiffPlug + * Copyright 2016-2023 DiffPlug * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/testlib/src/test/java/com/diffplug/spotless/markdown/FreshMarkStepTest.java b/testlib/src/test/java/com/diffplug/spotless/markdown/FreshMarkStepTest.java index a5fede28bc..586212383d 100644 --- a/testlib/src/test/java/com/diffplug/spotless/markdown/FreshMarkStepTest.java +++ b/testlib/src/test/java/com/diffplug/spotless/markdown/FreshMarkStepTest.java @@ -1,5 +1,5 @@ /* - * Copyright 2016-2022 DiffPlug + * Copyright 2016-2023 DiffPlug * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. From a610fbf1ae9d64f39e2f9b7b49904e104166f556 Mon Sep 17 00:00:00 2001 From: Ned Twigg Date: Thu, 26 Jan 2023 14:49:05 -0800 Subject: [PATCH 693/757] Minor tweaks to homepage. --- README.md | 46 ++++++++++++++++++++++++++++++++++------------ 1 file changed, 34 insertions(+), 12 deletions(-) diff --git a/README.md b/README.md index 0743b69427..d2527034ca 100644 --- a/README.md +++ b/README.md @@ -1,23 +1,45 @@ # Spotless: Keep your code spotless - -[![Circle CI](https://circleci.com/gh/diffplug/spotless/tree/main.svg?style=shield)](https://circleci.com/gh/diffplug/spotless/tree/main) -[![Live chat](https://img.shields.io/badge/gitter-chat-brightgreen.svg)](https://gitter.im/diffplug/spotless) -[![License Apache](https://img.shields.io/badge/license-apache-brightgreen.svg)](https://tldrlegal.com/license/apache-license-2.0-(apache-2.0)) - +[![Gradle Plugin](https://img.shields.io/gradle-plugin-portal/v/com.diffplug.spotless?color=blue&label=gradle%20plugin)](plugin-gradle) +[![Maven Plugin](https://img.shields.io/maven-central/v/com.diffplug.spotless/spotless-maven-plugin?color=blue&label=maven%20plugin)](plugin-maven) +[![SBT Plugin](https://img.shields.io/badge/sbt%20plugin-0.1.3-blue)](https://github.com/moznion/sbt-spotless) -Spotless can format <antlr | c | c# | c++ | css | flow | graphql | groovy | html | java | javascript | json | jsx | kotlin | less | license headers | markdown | objective-c | protobuf | python | scala | scss | sql | typeScript | vue | yaml | anything> using <gradle | maven | anything>. +Spotless can format <antlr | c | c# | c++ | css | flow | graphql | groovy | html | java | javascript | json | jsx | kotlin | less | license headers | markdown | objective-c | protobuf | python | scala | scss | sql | typeScript | vue | yaml | anything> using <gradle | maven | sbt | anything>. You probably want one of the links below: ## [❇️ Spotless for Gradle](plugin-gradle) (with integrations for [VS Code](https://marketplace.visualstudio.com/items?itemName=richardwillis.vscode-spotless-gradle) and [IntelliJ](https://plugins.jetbrains.com/plugin/18321-spotless-gradle)) + +```console +user@machine repo % ./gradlew build +:spotlessJavaCheck FAILED + The following files had format violations: + src\main\java\com\diffplug\gradle\spotless\FormatExtension.java + -\t\t····if·(targets.length·==·0)·{ + +\t\tif·(targets.length·==·0)·{ + Run './gradlew spotlessApply' to fix these violations. +user@machine repo % ./gradlew spotlessApply +:spotlessApply +BUILD SUCCESSFUL +user@machine repo % ./gradlew build +BUILD SUCCESSFUL +``` + ## [❇️ Spotless for Maven](plugin-maven) + +```console +user@machine repo % mvn spotless:check +[ERROR] > The following files had format violations: +[ERROR] src\main\java\com\diffplug\gradle\spotless\FormatExtension.java +[ERROR] -\t\t····if·(targets.length·==·0)·{ +[ERROR] +\t\tif·(targets.length·==·0)·{ +[ERROR] Run 'mvn spotless:apply' to fix these violations. +user@machine repo % mvn spotless:apply +[INFO] BUILD SUCCESS +user@machine repo % mvn spotless:check +[INFO] BUILD SUCCESS +``` + ## [❇️ Spotless for SBT (external for now)](https://github.com/moznion/sbt-spotless) ## [Other build systems](CONTRIBUTING.md#how-to-add-a-new-plugin-for-a-build-system) From 054ccd12ea39201b39d307d3b1749613f77152a6 Mon Sep 17 00:00:00 2001 From: Ned Twigg Date: Thu, 26 Jan 2023 15:06:57 -0800 Subject: [PATCH 694/757] Update public user counts and remove extra shields (Gitter and CircleCI in particular). --- plugin-gradle/README.md | 16 +++++----------- plugin-maven/README.md | 18 +++++------------- 2 files changed, 10 insertions(+), 24 deletions(-) diff --git a/plugin-gradle/README.md b/plugin-gradle/README.md index 67f3cdd69f..6a56d26e20 100644 --- a/plugin-gradle/README.md +++ b/plugin-gradle/README.md @@ -4,26 +4,20 @@ [![Gradle plugin](https://img.shields.io/badge/plugins.gradle.org-com.diffplug.spotless-blue.svg)](https://plugins.gradle.org/plugin/com.diffplug.spotless) -[![Maven central](https://img.shields.io/badge/mavencentral-yes-blue.svg)](https://search.maven.org/#search%7Cgav%7C1%7Cg%3A%22com.diffplug.spotless%22%20AND%20a%3A%22spotless-plugin-gradle%22) -[![Javadoc](https://img.shields.io/badge/javadoc-yes-blue.svg)](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.14.0/index.html) -[![License Apache](https://img.shields.io/badge/license-apache-blue.svg)](https://tldrlegal.com/license/apache-license-2.0-(apache-2.0)) [![Changelog](https://img.shields.io/badge/changelog-6.14.0-blue.svg)](CHANGES.md) +[![Maven central](https://img.shields.io/badge/mavencentral-here-blue.svg)](https://search.maven.org/#search%7Cgav%7C1%7Cg%3A%22com.diffplug.spotless%22%20AND%20a%3A%22spotless-plugin-gradle%22) +[![Javadoc](https://img.shields.io/badge/javadoc-here-blue.svg)](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.14.0/index.html) -[![Circle CI](https://circleci.com/gh/diffplug/spotless/tree/main.svg?style=shield)](https://circleci.com/gh/diffplug/spotless/tree/main) -[![Live chat](https://img.shields.io/badge/gitter-chat-brightgreen.svg)](https://gitter.im/diffplug/spotless) [![VS Code plugin](https://img.shields.io/badge/IDE-VS_Code-blueviolet.svg)](https://marketplace.visualstudio.com/items?itemName=richardwillis.vscode-spotless-gradle) [![IntelliJ plugin](https://img.shields.io/badge/IDE-IntelliJ-blueviolet.svg)](https://plugins.jetbrains.com/plugin/18321-spotless-gradle) [![Add other IDE](https://img.shields.io/badge/IDE-add_yours-blueviolet.svg)](IDE_HOOK.md) @@ -33,7 +27,7 @@ output = [ output = prefixDelimiterReplace(input, 'https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/', '/', versionLast) --> -Spotless is a general-purpose formatting plugin used by [4,000 projects on GitHub (August 2020)](https://github.com/search?l=gradle&q=spotless&type=Code). It is completely à la carte, but also includes powerful "batteries-included" if you opt-in. +Spotless is a general-purpose formatting plugin used by [15,000 projects on GitHub (Jan 2023)](https://github.com/search?l=gradle&q=spotless&type=Code). It is completely à la carte, but also includes powerful "batteries-included" if you opt-in. To people who use your build, it looks like this ([IDE support also available](IDE_HOOK.md)): diff --git a/plugin-maven/README.md b/plugin-maven/README.md index 2ade34b67b..73402cd929 100644 --- a/plugin-maven/README.md +++ b/plugin-maven/README.md @@ -3,28 +3,20 @@ [![Maven central](https://img.shields.io/badge/mavencentral-com.diffplug.spotless%3Aspotless--maven--plugin-blue.svg)](https://search.maven.org/#search%7Cgav%7C1%7Cg%3A%22com.diffplug.spotless%22%20AND%20a%3A%22spotless-maven-plugin%22) -[![Javadoc](https://img.shields.io/badge/javadoc-yes-blue.svg)](https://javadoc.io/doc/com.diffplug.spotless/spotless-maven-plugin/2.31.0/index.html) -[![Changelog](https://img.shields.io/badge/changelog-2.31.0-brightgreen.svg)](CHANGES.md) - -[![Circle CI](https://circleci.com/gh/diffplug/spotless/tree/main.svg?style=shield)](https://circleci.com/gh/diffplug/spotless/tree/main) -[![Live chat](https://img.shields.io/badge/gitter-chat-brightgreen.svg)](https://gitter.im/diffplug/spotless) -[![License Apache](https://img.shields.io/badge/license-apache-brightgreen.svg)](https://tldrlegal.com/license/apache-license-2.0-(apache-2.0)) +[![Changelog](https://img.shields.io/badge/changelog-2.31.0-blue.svg)](CHANGES.md) +[![Javadoc](https://img.shields.io/badge/javadoc-here-blue.svg)](https://javadoc.io/doc/com.diffplug.spotless/spotless-maven-plugin/2.31.0/index.html) -Spotless is a general-purpose formatting plugin used by [4,000 projects on GitHub (August 2020)](https://github.com/search?l=gradle&q=spotless&type=Code). It is completely à la carte, but also includes powerful "batteries-included" if you opt-in. Plugin requires a version of Maven higher or equal to 3.1.0. +Spotless is a general-purpose formatting plugin used by [6,000 projects on GitHub (Jan 2023)](https://github.com/search?l=Maven+POM&q=spotless&type=Code). It is completely à la carte, but also includes powerful "batteries-included" if you opt-in. Plugin requires a version of Maven higher or equal to 3.1.0. To people who use your build, it looks like this: From b0d16195d45c04a06965217b2bc14bd69d3fe2aa Mon Sep 17 00:00:00 2001 From: Benoit Lacelle Date: Sat, 28 Jan 2023 18:39:41 +0400 Subject: [PATCH 695/757] Introduce Formatter.name, Improve synthesis log --- .../java/com/diffplug/spotless/Formatter.java | 26 +++++++++++++--- .../gradle/spotless/SpotlessTask.java | 3 +- .../spotless/maven/FormatterFactory.java | 4 ++- .../spotless/maven/ImpactedFilesTracker.java | 31 +++++++++++++++++++ .../spotless/maven/SpotlessApplyMojo.java | 10 ++++-- .../spotless/StepHarnessWithFile.java | 1 + 6 files changed, 67 insertions(+), 8 deletions(-) diff --git a/lib/src/main/java/com/diffplug/spotless/Formatter.java b/lib/src/main/java/com/diffplug/spotless/Formatter.java index 038e77fa64..bdfe008a61 100644 --- a/lib/src/main/java/com/diffplug/spotless/Formatter.java +++ b/lib/src/main/java/com/diffplug/spotless/Formatter.java @@ -1,5 +1,5 @@ /* - * Copyright 2016 DiffPlug + * Copyright 2016-2023 DiffPlug * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -39,13 +39,16 @@ public final class Formatter implements Serializable, AutoCloseable { private static final long serialVersionUID = 1L; + // The name is used for logging purpose. It does not convey any applicative purpose + private String name; private LineEnding.Policy lineEndingsPolicy; private Charset encoding; private Path rootDir; private List steps; private FormatExceptionPolicy exceptionPolicy; - private Formatter(LineEnding.Policy lineEndingsPolicy, Charset encoding, Path rootDirectory, List steps, FormatExceptionPolicy exceptionPolicy) { + private Formatter(String name, LineEnding.Policy lineEndingsPolicy, Charset encoding, Path rootDirectory, List steps, FormatExceptionPolicy exceptionPolicy) { + this.name = name; this.lineEndingsPolicy = Objects.requireNonNull(lineEndingsPolicy, "lineEndingsPolicy"); this.encoding = Objects.requireNonNull(encoding, "encoding"); this.rootDir = Objects.requireNonNull(rootDirectory, "rootDir"); @@ -55,6 +58,7 @@ private Formatter(LineEnding.Policy lineEndingsPolicy, Charset encoding, Path ro // override serialize output private void writeObject(ObjectOutputStream out) throws IOException { + out.writeObject(name); out.writeObject(lineEndingsPolicy); out.writeObject(encoding.name()); out.writeObject(rootDir.toString()); @@ -65,6 +69,7 @@ private void writeObject(ObjectOutputStream out) throws IOException { // override serialize input @SuppressWarnings("unchecked") private void readObject(ObjectInputStream in) throws IOException, ClassNotFoundException { + name = (String) in.readObject(); lineEndingsPolicy = (LineEnding.Policy) in.readObject(); encoding = Charset.forName((String) in.readObject()); rootDir = Paths.get((String) in.readObject()); @@ -78,6 +83,10 @@ private void readObjectNoData() throws ObjectStreamException { throw new UnsupportedOperationException(); } + public String getName() { + return name; + } + public LineEnding.Policy getLineEndingsPolicy() { return lineEndingsPolicy; } @@ -103,6 +112,8 @@ public static Formatter.Builder builder() { } public static class Builder { + // optional parameters + private String name = "misc"; // required parameters private LineEnding.Policy lineEndingsPolicy; private Charset encoding; @@ -112,6 +123,11 @@ public static class Builder { private Builder() {} + public Builder name(String name) { + this.name = name; + return this; + } + public Builder lineEndingsPolicy(LineEnding.Policy lineEndingsPolicy) { this.lineEndingsPolicy = lineEndingsPolicy; return this; @@ -138,7 +154,7 @@ public Builder exceptionPolicy(FormatExceptionPolicy exceptionPolicy) { } public Formatter build() { - return new Formatter(lineEndingsPolicy, encoding, rootDir, steps, + return new Formatter(name, lineEndingsPolicy, encoding, rootDir, steps, exceptionPolicy == null ? FormatExceptionPolicy.failOnlyOnError() : exceptionPolicy); } } @@ -248,6 +264,7 @@ public String compute(String unix, File file) { public int hashCode() { final int prime = 31; int result = 1; + result = prime * result + name.hashCode(); result = prime * result + encoding.hashCode(); result = prime * result + lineEndingsPolicy.hashCode(); result = prime * result + rootDir.hashCode(); @@ -268,7 +285,8 @@ public boolean equals(Object obj) { return false; } Formatter other = (Formatter) obj; - return encoding.equals(other.encoding) && + return name.equals(other.name) && + encoding.equals(other.encoding) && lineEndingsPolicy.equals(other.lineEndingsPolicy) && rootDir.equals(other.rootDir) && steps.equals(other.steps) && diff --git a/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/SpotlessTask.java b/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/SpotlessTask.java index 6f2279b2e0..c23cea0845 100644 --- a/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/SpotlessTask.java +++ b/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/SpotlessTask.java @@ -1,5 +1,5 @@ /* - * Copyright 2020-2021 DiffPlug + * Copyright 2020-2023 DiffPlug * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -184,6 +184,7 @@ String formatName() { Formatter buildFormatter() { return Formatter.builder() + .name(formatName()) .lineEndingsPolicy(lineEndingsPolicy.get()) .encoding(Charset.forName(encoding)) .rootDir(getProjectDir().get().getAsFile().toPath()) diff --git a/plugin-maven/src/main/java/com/diffplug/spotless/maven/FormatterFactory.java b/plugin-maven/src/main/java/com/diffplug/spotless/maven/FormatterFactory.java index d5fbe60370..b78e987d34 100644 --- a/plugin-maven/src/main/java/com/diffplug/spotless/maven/FormatterFactory.java +++ b/plugin-maven/src/main/java/com/diffplug/spotless/maven/FormatterFactory.java @@ -1,5 +1,5 @@ /* - * Copyright 2016-2022 DiffPlug + * Copyright 2016-2023 DiffPlug * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -101,7 +101,9 @@ public final Formatter newFormatter(Supplier> filesToFormat, Form formatterSteps.add(pair.out()); } + String formatterName = this.getClass().getSimpleName(); return Formatter.builder() + .name(formatterName) .encoding(formatterEncoding) .lineEndingsPolicy(formatterLineEndingPolicy) .exceptionPolicy(new FormatExceptionPolicyStrict()) diff --git a/plugin-maven/src/main/java/com/diffplug/spotless/maven/ImpactedFilesTracker.java b/plugin-maven/src/main/java/com/diffplug/spotless/maven/ImpactedFilesTracker.java index 6019591e09..7474c109bc 100644 --- a/plugin-maven/src/main/java/com/diffplug/spotless/maven/ImpactedFilesTracker.java +++ b/plugin-maven/src/main/java/com/diffplug/spotless/maven/ImpactedFilesTracker.java @@ -1,11 +1,41 @@ +/* + * Copyright 2023 DiffPlug + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ package com.diffplug.spotless.maven; import java.util.concurrent.atomic.AtomicInteger; +/** + * Tracks the number of processed files, typically by a single Formatter for a whole repository + */ public class ImpactedFilesTracker { + protected final AtomicInteger nbSkipped = new AtomicInteger(); protected final AtomicInteger nbChecked = new AtomicInteger(); protected final AtomicInteger nbCleaned = new AtomicInteger(); + /** + * Some cache mechanism may indicate some content is clean, without having to execute the cleaning process + */ + public void skippedAsCleanCache() { + nbSkipped.incrementAndGet(); + } + + public int getSkipped() { + return nbSkipped.get(); + } + public void checked() { nbChecked.incrementAndGet(); } @@ -21,4 +51,5 @@ public void cleaned() { public int getCleaned() { return nbCleaned.get(); } + } diff --git a/plugin-maven/src/main/java/com/diffplug/spotless/maven/SpotlessApplyMojo.java b/plugin-maven/src/main/java/com/diffplug/spotless/maven/SpotlessApplyMojo.java index b617505826..0f712ecd12 100644 --- a/plugin-maven/src/main/java/com/diffplug/spotless/maven/SpotlessApplyMojo.java +++ b/plugin-maven/src/main/java/com/diffplug/spotless/maven/SpotlessApplyMojo.java @@ -1,5 +1,5 @@ /* - * Copyright 2016-2022 DiffPlug + * Copyright 2016-2023 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 @@ protected void process(Iterable files, Formatter formatter, UpToDateChecke for (File file : files) { if (upToDateChecker.isUpToDate(file.toPath())) { + impactedFilesTracker.skippedAsCleanCache(); if (getLog().isDebugEnabled()) { getLog().debug("Spotless will not format an up-to-date file: " + file); } @@ -60,6 +61,11 @@ protected void process(Iterable files, Formatter formatter, UpToDateChecke } // We print the number of considered files which is useful when ratchetFrom is setup - getLog().info(String.format("A formatter with %s steps cleaned: %s files (for %s considered)", formatter.getSteps().size(), impactedFilesTracker.getCleaned(), impactedFilesTracker.getChecked())); + int nbSkipped = impactedFilesTracker.getSkipped(); + int nbChecked = impactedFilesTracker.getChecked(); + int nbCleaned = impactedFilesTracker.getCleaned(); + int totalProcessed = nbSkipped + nbChecked + nbCleaned; + getLog().info(String.format("Spotless.%s is keeping %s files clean - %s were changed to be clean, %s were already clean, %s were skipped because caching determined they were already clean", + formatter.getName(), totalProcessed, nbCleaned, nbChecked, nbSkipped)); } } diff --git a/testlib/src/main/java/com/diffplug/spotless/StepHarnessWithFile.java b/testlib/src/main/java/com/diffplug/spotless/StepHarnessWithFile.java index 98a709c59f..9a9eb4042b 100644 --- a/testlib/src/main/java/com/diffplug/spotless/StepHarnessWithFile.java +++ b/testlib/src/main/java/com/diffplug/spotless/StepHarnessWithFile.java @@ -38,6 +38,7 @@ private StepHarnessWithFile(ResourceHarness harness, Formatter formatter) { /** Creates a harness for testing steps which do depend on the file. */ public static StepHarnessWithFile forStep(ResourceHarness harness, FormatterStep step) { return new StepHarnessWithFile(harness, Formatter.builder() + .name(step.getName()) .encoding(StandardCharsets.UTF_8) .lineEndingsPolicy(LineEnding.UNIX.createPolicy()) .steps(Collections.singletonList(step)) From 2da48e6f0c1c6a0ae4e7669d43a3756f7df72eb9 Mon Sep 17 00:00:00 2001 From: "renovate[bot]" <29139614+renovate[bot]@users.noreply.github.com> Date: Sun, 29 Jan 2023 04:16:38 +0000 Subject: [PATCH 696/757] Update dependency com.fasterxml.jackson.core:jackson-databind to v2.14.2 --- lib/build.gradle | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/build.gradle b/lib/build.gradle index 9d95007bc1..fa80767047 100644 --- a/lib/build.gradle +++ b/lib/build.gradle @@ -62,7 +62,7 @@ dependencies { palantirJavaFormatCompileOnly 'com.palantir.javaformat:palantir-java-format:1.1.0' // this version needs to stay compilable against Java 8 for CI Job testNpm // used jackson-based formatters - jacksonCompileOnly 'com.fasterxml.jackson.core:jackson-databind:2.14.1' + jacksonCompileOnly 'com.fasterxml.jackson.core:jackson-databind:2.14.2' jacksonCompileOnly 'com.fasterxml.jackson.dataformat:jackson-dataformat-yaml:2.14.1' String VER_KTFMT = '0.42' From 0bb25119d7f96220f4aa5b4072053849a9b06662 Mon Sep 17 00:00:00 2001 From: "renovate[bot]" <29139614+renovate[bot]@users.noreply.github.com> Date: Sun, 29 Jan 2023 13:17:02 +0000 Subject: [PATCH 697/757] Update dependency org.mockito:mockito-core to v5.1.0 --- gradle.properties | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gradle.properties b/gradle.properties index dc4f24a36b..6256e51203 100644 --- a/gradle.properties +++ b/gradle.properties @@ -28,4 +28,4 @@ VER_DURIAN=1.2.0 VER_JGIT=6.4.0.202211300538-r VER_JUNIT=5.9.2 VER_ASSERTJ=3.24.2 -VER_MOCKITO=5.0.0 +VER_MOCKITO=5.1.0 From cc03d541e9e2a8b645e54e535ad0259c959c1ff7 Mon Sep 17 00:00:00 2001 From: "renovate[bot]" <29139614+renovate[bot]@users.noreply.github.com> Date: Mon, 30 Jan 2023 09:08:11 +0000 Subject: [PATCH 698/757] Update plugin com.diffplug.spotless-changelog to v3 --- settings.gradle | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/settings.gradle b/settings.gradle index 0ee51448dd..379daca7bb 100644 --- a/settings.gradle +++ b/settings.gradle @@ -14,7 +14,7 @@ plugins { // https://github.com/spotbugs/spotbugs-gradle-plugin/releases id 'com.github.spotbugs' version '5.0.13' apply false // https://github.com/diffplug/spotless-changelog/blob/main/CHANGELOG.md - id 'com.diffplug.spotless-changelog' version '2.4.1' apply false + id 'com.diffplug.spotless-changelog' version '3.0.1' apply false // https://github.com/diffplug/goomph/blob/main/CHANGES.md // DO NOT UPDATE, see https://github.com/diffplug/spotless/pull/874 id 'com.diffplug.p2.asmaven' version '3.27.0' apply false From cf2a4eb08d002db8b4c51fa4c43ad022361a6013 Mon Sep 17 00:00:00 2001 From: "renovate[bot]" <29139614+renovate[bot]@users.noreply.github.com> Date: Mon, 30 Jan 2023 16:37:03 +0000 Subject: [PATCH 699/757] Update plugin com.gradle.enterprise to v3.12.3 --- settings.gradle | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/settings.gradle b/settings.gradle index 0ee51448dd..e476425c96 100644 --- a/settings.gradle +++ b/settings.gradle @@ -23,7 +23,7 @@ plugins { // https://github.com/davidburstrom/version-compatibility-gradle-plugin/tags id 'io.github.davidburstrom.version-compatibility' version '0.4.0' apply false // https://plugins.gradle.org/plugin/com.gradle.enterprise - id 'com.gradle.enterprise' version '3.12.2' + id 'com.gradle.enterprise' version '3.12.3' } dependencyResolutionManagement { From cf434f2eecf9a9369f22c1c95f56adbb792df30f Mon Sep 17 00:00:00 2001 From: Benoit Lacelle Date: Mon, 30 Jan 2023 23:19:53 +0400 Subject: [PATCH 700/757] Start with Cleanthat Java refactorer --- .../java/JavaCleanthatRefactorerFunc.java | 56 +++++++ .../spotless/java/CleanthatStepFactory.java | 140 ++++++++++++++++++ 2 files changed, 196 insertions(+) create mode 100644 lib/src/cleanthat/java/com/diffplug/spotless/glue/java/JavaCleanthatRefactorerFunc.java create mode 100644 lib/src/main/java/com/diffplug/spotless/java/CleanthatStepFactory.java diff --git a/lib/src/cleanthat/java/com/diffplug/spotless/glue/java/JavaCleanthatRefactorerFunc.java b/lib/src/cleanthat/java/com/diffplug/spotless/glue/java/JavaCleanthatRefactorerFunc.java new file mode 100644 index 0000000000..bc96f0019b --- /dev/null +++ b/lib/src/cleanthat/java/com/diffplug/spotless/glue/java/JavaCleanthatRefactorerFunc.java @@ -0,0 +1,56 @@ +/* + * Copyright 2021-2023 Solven + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.diffplug.spotless.glue.java; + +import com.diffplug.spotless.FormatterFunc; +import eu.solven.cleanthat.config.pojo.CleanthatEngineProperties; +import eu.solven.cleanthat.engine.java.refactorer.JavaRefactorer; +import eu.solven.cleanthat.engine.java.refactorer.JavaRefactorerProperties; +import eu.solven.cleanthat.formatter.LineEnding; +import eu.solven.cleanthat.formatter.PathAndContent; +import java.nio.file.Paths; +import java.util.Arrays; +import java.util.Collections; +import java.util.List; + +public class JavaCleanthatRefactorerFunc implements FormatterFunc { + private List included; + private List excluded; + + public JavaCleanthatRefactorerFunc(List included, List excluded) { + this.included = included == null ? Collections.emptyList() : included; + this.excluded = excluded == null ? Collections.emptyList() : excluded; + } + + public JavaCleanthatRefactorerFunc() { + this(Arrays.asList(JavaRefactorerProperties.WILDCARD), Arrays.asList()); + } + + @Override + public String apply(String input) throws Exception { + JavaRefactorerProperties refactorerProperties = new JavaRefactorerProperties(); + + refactorerProperties.setIncluded(included); + refactorerProperties.setExcluded(excluded); + + JavaRefactorer refactorer = + new JavaRefactorer(CleanthatEngineProperties.builder().build(), refactorerProperties); + + // Spotless calls steps always with LF eol. + return refactorer.doFormat(new PathAndContent(Paths.get("fake"), input), LineEnding.LF); + } + +} diff --git a/lib/src/main/java/com/diffplug/spotless/java/CleanthatStepFactory.java b/lib/src/main/java/com/diffplug/spotless/java/CleanthatStepFactory.java new file mode 100644 index 0000000000..fa9936fb1e --- /dev/null +++ b/lib/src/main/java/com/diffplug/spotless/java/CleanthatStepFactory.java @@ -0,0 +1,140 @@ +/* + * Copyright 2016-2023 Solven + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.diffplug.spotless.java; + +import com.diffplug.spotless.FormatterFunc; +import com.diffplug.spotless.FormatterStep; +import com.diffplug.spotless.JarState; +import com.diffplug.spotless.Jvm; +import com.diffplug.spotless.Provisioner; +import java.io.IOException; +import java.io.Serializable; +import java.lang.reflect.Constructor; +import java.lang.reflect.Method; +import java.util.List; +import java.util.Objects; + +/** + * Enables CleanThat as a SpotLess step. This may be moved to Spotless own repo + * (https://github.com/diffplug/spotless/tree/main/lib) + * + * @author Benoit Lacelle + */ +// https://github.com/diffplug/spotless/blob/main/CONTRIBUTING.md#how-to-add-a-new-formatterstep +public final class CleanthatStepFactory { + + private static final String NAME = "cleanthat"; + private static final String MAVEN_COORDINATE = "io.github.solven-eu.cleanthat:java:"; + + private static final Jvm.Support JVM_SUPPORT = Jvm.support(NAME).add(8, "2.0"); + + // prevent direct instantiation + private CleanthatStepFactory() { + } + + /** Creates a step which formats everything - code, import order, and unused imports. */ + public static FormatterStep create(Provisioner provisioner) { + return create(defaultVersion(), provisioner); + } + + /** Creates a step which formats everything - code, import order, and unused imports. */ + public static FormatterStep create(String version, Provisioner provisioner) { + return create(MAVEN_COORDINATE, version, defaultExcluded(), defaultIncluded(), provisioner); + } + + private static List defaultExcluded() { + return List.of(); + } + + private static List defaultIncluded() { + return List.of("*"); + } + + /** Creates a step which formats everything - groupArtifact, code, import order, and unused imports. */ + public static FormatterStep create(String groupArtifact, + String version, + List excluded, + List included, + Provisioner provisioner) { + Objects.requireNonNull(groupArtifact, "groupArtifact"); + if (groupArtifact.chars().filter(ch -> ch == ':').count() != 1) { + throw new IllegalArgumentException("groupArtifact must be in the form 'groupId:artifactId'"); + } + Objects.requireNonNull(version, "version"); + Objects.requireNonNull(provisioner, "provisioner"); + return FormatterStep.createLazy(NAME, + () -> new JavaRulesState(NAME, groupArtifact, version, excluded, included, provisioner), + JavaRulesState::createFormat); + } + + /** Get default formatter version */ + public static String defaultVersion() { + return JVM_SUPPORT.getRecommendedFormatterVersion(); + } + + static final class JavaRulesState implements Serializable { + private static final long serialVersionUID = 1L; + + final JarState jarState; + final String stepName; + final String version; + + final List included; + final List excluded; + + JavaRulesState(String stepName, String version, Provisioner provisioner) throws IOException { + this(stepName, MAVEN_COORDINATE, version, defaultExcluded(), defaultIncluded(), provisioner); + } + + JavaRulesState(String stepName, + String groupArtifact, + String version, + List included, + List excluded, + Provisioner provisioner) throws IOException { + JVM_SUPPORT.assertFormatterSupported(version); + // ModuleHelper.doOpenInternalPackagesIfRequired(); + this.jarState = JarState.from(groupArtifact + ":" + version, provisioner); + this.stepName = stepName; + this.version = version; + + this.included = included; + this.excluded = excluded; + } + + @SuppressWarnings("PMD.UseProperClassLoader") + FormatterFunc createFormat() { + ClassLoader classLoader = jarState.getClassLoader(); + + Object formatter; + Method formatterMethod; + try { + Class formatterClazz = + classLoader.loadClass("com.diffplug.spotless.glue.java.JavaCleanthatRefactoringFunc"); + Constructor formatterConstructor = formatterClazz.getConstructor(List.class, List.class); + + formatter = formatterConstructor.newInstance(included, excluded); + formatterMethod = formatterClazz.getMethod("apply", String.class); + } catch (ReflectiveOperationException e) { + throw new IllegalStateException("Issue executing the formatter", e); + } + return JVM_SUPPORT.suggestLaterVersionOnError(version, input -> { + return (String) formatterMethod.invoke(formatter, input); + }); + } + + } +} From 8fcce07eee63e064ad1c8e3583dd6c89c32899fa Mon Sep 17 00:00:00 2001 From: Benoit Lacelle Date: Tue, 31 Jan 2023 00:10:27 +0400 Subject: [PATCH 701/757] Apply suggestions --- .../java/com/diffplug/spotless/Formatter.java | 2 +- .../spotless/maven/ImpactedFilesTracker.java | 28 +++++++++---------- .../spotless/maven/SpotlessApplyMojo.java | 13 +++++---- 3 files changed, 21 insertions(+), 22 deletions(-) diff --git a/lib/src/main/java/com/diffplug/spotless/Formatter.java b/lib/src/main/java/com/diffplug/spotless/Formatter.java index bdfe008a61..dede79c1b3 100644 --- a/lib/src/main/java/com/diffplug/spotless/Formatter.java +++ b/lib/src/main/java/com/diffplug/spotless/Formatter.java @@ -113,7 +113,7 @@ public static Formatter.Builder builder() { public static class Builder { // optional parameters - private String name = "misc"; + private String name = "unnamed"; // required parameters private LineEnding.Policy lineEndingsPolicy; private Charset encoding; diff --git a/plugin-maven/src/main/java/com/diffplug/spotless/maven/ImpactedFilesTracker.java b/plugin-maven/src/main/java/com/diffplug/spotless/maven/ImpactedFilesTracker.java index 7474c109bc..f66802475e 100644 --- a/plugin-maven/src/main/java/com/diffplug/spotless/maven/ImpactedFilesTracker.java +++ b/plugin-maven/src/main/java/com/diffplug/spotless/maven/ImpactedFilesTracker.java @@ -15,41 +15,39 @@ */ package com.diffplug.spotless.maven; -import java.util.concurrent.atomic.AtomicInteger; - /** * Tracks the number of processed files, typically by a single Formatter for a whole repository */ -public class ImpactedFilesTracker { - protected final AtomicInteger nbSkipped = new AtomicInteger(); - protected final AtomicInteger nbChecked = new AtomicInteger(); - protected final AtomicInteger nbCleaned = new AtomicInteger(); +class ImpactedFilesTracker { + protected int nbskippedAsCleanCache = 0; + protected int nbCheckedButAlreadyClean = 0; + protected int nbCleaned = 0; /** * Some cache mechanism may indicate some content is clean, without having to execute the cleaning process */ public void skippedAsCleanCache() { - nbSkipped.incrementAndGet(); + nbskippedAsCleanCache++; } - public int getSkipped() { - return nbSkipped.get(); + public int getSkippedAsCleanCache() { + return nbskippedAsCleanCache; } - public void checked() { - nbChecked.incrementAndGet(); + public void checkedButAlreadyClean() { + nbCheckedButAlreadyClean++; } - public int getChecked() { - return nbChecked.get(); + public int getCheckedButAlreadyClean() { + return nbCheckedButAlreadyClean; } public void cleaned() { - nbCleaned.incrementAndGet(); + nbCleaned++; } public int getCleaned() { - return nbCleaned.get(); + return nbCleaned; } } diff --git a/plugin-maven/src/main/java/com/diffplug/spotless/maven/SpotlessApplyMojo.java b/plugin-maven/src/main/java/com/diffplug/spotless/maven/SpotlessApplyMojo.java index 0f712ecd12..0c1cbf8785 100644 --- a/plugin-maven/src/main/java/com/diffplug/spotless/maven/SpotlessApplyMojo.java +++ b/plugin-maven/src/main/java/com/diffplug/spotless/maven/SpotlessApplyMojo.java @@ -45,13 +45,14 @@ protected void process(Iterable files, Formatter formatter, UpToDateChecke } try { - impactedFilesTracker.checked(); PaddedCell.DirtyState dirtyState = PaddedCell.calculateDirtyState(formatter, file); if (!dirtyState.isClean() && !dirtyState.didNotConverge()) { getLog().info(String.format("Writing clean file: %s", file)); dirtyState.writeCanonicalTo(file); buildContext.refresh(file); impactedFilesTracker.cleaned(); + } else { + impactedFilesTracker.checkedButAlreadyClean(); } } catch (IOException e) { throw new MojoExecutionException("Unable to format file " + file, e); @@ -61,11 +62,11 @@ protected void process(Iterable files, Formatter formatter, UpToDateChecke } // We print the number of considered files which is useful when ratchetFrom is setup - int nbSkipped = impactedFilesTracker.getSkipped(); - int nbChecked = impactedFilesTracker.getChecked(); - int nbCleaned = impactedFilesTracker.getCleaned(); - int totalProcessed = nbSkipped + nbChecked + nbCleaned; + int skippedAsCleanCache = impactedFilesTracker.getSkippedAsCleanCache(); + int checkedButAlreadyClean = impactedFilesTracker.getCheckedButAlreadyClean(); + int cleaned = impactedFilesTracker.getCleaned(); + int totalProcessed = skippedAsCleanCache + checkedButAlreadyClean + cleaned; getLog().info(String.format("Spotless.%s is keeping %s files clean - %s were changed to be clean, %s were already clean, %s were skipped because caching determined they were already clean", - formatter.getName(), totalProcessed, nbCleaned, nbChecked, nbSkipped)); + formatter.getName(), totalProcessed, cleaned, checkedButAlreadyClean, skippedAsCleanCache)); } } From ed45e5b57bdd4b62874d8d55aa7f5d93a0d7e138 Mon Sep 17 00:00:00 2001 From: "renovate[bot]" <29139614+renovate[bot]@users.noreply.github.com> Date: Mon, 30 Jan 2023 23:12:28 +0000 Subject: [PATCH 702/757] Update dependency org.mockito:mockito-core to v5.1.1 --- gradle.properties | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gradle.properties b/gradle.properties index 6256e51203..c72fa0429d 100644 --- a/gradle.properties +++ b/gradle.properties @@ -28,4 +28,4 @@ VER_DURIAN=1.2.0 VER_JGIT=6.4.0.202211300538-r VER_JUNIT=5.9.2 VER_ASSERTJ=3.24.2 -VER_MOCKITO=5.1.0 +VER_MOCKITO=5.1.1 From c890b89c7fb4430858bac8277bc5cfffad87ebac Mon Sep 17 00:00:00 2001 From: Benoit Lacelle Date: Tue, 31 Jan 2023 08:39:13 +0400 Subject: [PATCH 703/757] Add a CHANGES entry. Log only if totalProcessed>0 --- plugin-maven/CHANGES.md | 1 + .../java/com/diffplug/spotless/maven/SpotlessApplyMojo.java | 6 ++++-- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/plugin-maven/CHANGES.md b/plugin-maven/CHANGES.md index 1bb49898f1..2ecb7735ff 100644 --- a/plugin-maven/CHANGES.md +++ b/plugin-maven/CHANGES.md @@ -4,6 +4,7 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format ( ## [Unreleased] ### Added +* A synthesis log with the number of considered files is added after each formatter execution [#1507](https://github.com/diffplug/spotless/pull/1507) ### Fixed * The default list of type annotations used by `formatAnnotations` has had 8 more annotations from the Checker Framework added [#1494](https://github.com/diffplug/spotless/pull/1494) ### Changes diff --git a/plugin-maven/src/main/java/com/diffplug/spotless/maven/SpotlessApplyMojo.java b/plugin-maven/src/main/java/com/diffplug/spotless/maven/SpotlessApplyMojo.java index 0c1cbf8785..8dd758e84b 100644 --- a/plugin-maven/src/main/java/com/diffplug/spotless/maven/SpotlessApplyMojo.java +++ b/plugin-maven/src/main/java/com/diffplug/spotless/maven/SpotlessApplyMojo.java @@ -66,7 +66,9 @@ protected void process(Iterable files, Formatter formatter, UpToDateChecke int checkedButAlreadyClean = impactedFilesTracker.getCheckedButAlreadyClean(); int cleaned = impactedFilesTracker.getCleaned(); int totalProcessed = skippedAsCleanCache + checkedButAlreadyClean + cleaned; - getLog().info(String.format("Spotless.%s is keeping %s files clean - %s were changed to be clean, %s were already clean, %s were skipped because caching determined they were already clean", - formatter.getName(), totalProcessed, cleaned, checkedButAlreadyClean, skippedAsCleanCache)); + if (totalProcessed > 0) { + getLog().info(String.format("Spotless.%s is keeping %s files clean - %s were changed to be clean, %s were already clean, %s were skipped because caching determined they were already clean", + formatter.getName(), totalProcessed, cleaned, checkedButAlreadyClean, skippedAsCleanCache)); + } } } From 6f6b34fe35753064fdd35e5fcce8b42ec62660fb Mon Sep 17 00:00:00 2001 From: Benoit Lacelle Date: Tue, 31 Jan 2023 08:45:30 +0400 Subject: [PATCH 704/757] Add debug log if no concerned filers --- .../java/com/diffplug/spotless/maven/SpotlessApplyMojo.java | 3 +++ 1 file changed, 3 insertions(+) diff --git a/plugin-maven/src/main/java/com/diffplug/spotless/maven/SpotlessApplyMojo.java b/plugin-maven/src/main/java/com/diffplug/spotless/maven/SpotlessApplyMojo.java index 8dd758e84b..5f99f6a126 100644 --- a/plugin-maven/src/main/java/com/diffplug/spotless/maven/SpotlessApplyMojo.java +++ b/plugin-maven/src/main/java/com/diffplug/spotless/maven/SpotlessApplyMojo.java @@ -69,6 +69,9 @@ protected void process(Iterable files, Formatter formatter, UpToDateChecke if (totalProcessed > 0) { getLog().info(String.format("Spotless.%s is keeping %s files clean - %s were changed to be clean, %s were already clean, %s were skipped because caching determined they were already clean", formatter.getName(), totalProcessed, cleaned, checkedButAlreadyClean, skippedAsCleanCache)); + } else { + getLog().debug(String.format("Spotless.%s is not considering a single file", + formatter.getName())); } } } From d7ff074095b4bbcbe1acb6a7e4ad1edf6fccb78f Mon Sep 17 00:00:00 2001 From: Ned Twigg Date: Mon, 30 Jan 2023 22:46:21 -0800 Subject: [PATCH 705/757] Treat empty target as a warning (likely a mistake, e.g. #437). --- .../java/com/diffplug/spotless/maven/SpotlessApplyMojo.java | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/plugin-maven/src/main/java/com/diffplug/spotless/maven/SpotlessApplyMojo.java b/plugin-maven/src/main/java/com/diffplug/spotless/maven/SpotlessApplyMojo.java index 5f99f6a126..440b72c21e 100644 --- a/plugin-maven/src/main/java/com/diffplug/spotless/maven/SpotlessApplyMojo.java +++ b/plugin-maven/src/main/java/com/diffplug/spotless/maven/SpotlessApplyMojo.java @@ -70,8 +70,7 @@ protected void process(Iterable files, Formatter formatter, UpToDateChecke getLog().info(String.format("Spotless.%s is keeping %s files clean - %s were changed to be clean, %s were already clean, %s were skipped because caching determined they were already clean", formatter.getName(), totalProcessed, cleaned, checkedButAlreadyClean, skippedAsCleanCache)); } else { - getLog().debug(String.format("Spotless.%s is not considering a single file", - formatter.getName())); + getLog().warn(String.format("Spotless.%s has no target files. Examine your ``: https://github.com/diffplug/spotless/tree/main/plugin-maven#quickstart", formatter.getName())); } } } From eeee68aaa9e605d23b0622af7ff2650237c96fa5 Mon Sep 17 00:00:00 2001 From: Ned Twigg Date: Mon, 30 Jan 2023 22:48:52 -0800 Subject: [PATCH 706/757] Minor renaming to condense SpotlessApplyMojo. --- .../spotless/maven/ImpactedFilesTracker.java | 3 +++ .../spotless/maven/SpotlessApplyMojo.java | 16 ++++++---------- 2 files changed, 9 insertions(+), 10 deletions(-) diff --git a/plugin-maven/src/main/java/com/diffplug/spotless/maven/ImpactedFilesTracker.java b/plugin-maven/src/main/java/com/diffplug/spotless/maven/ImpactedFilesTracker.java index f66802475e..60eb8af762 100644 --- a/plugin-maven/src/main/java/com/diffplug/spotless/maven/ImpactedFilesTracker.java +++ b/plugin-maven/src/main/java/com/diffplug/spotless/maven/ImpactedFilesTracker.java @@ -50,4 +50,7 @@ public int getCleaned() { return nbCleaned; } + public int getTotal() { + return nbskippedAsCleanCache + nbCheckedButAlreadyClean + nbCleaned; + } } diff --git a/plugin-maven/src/main/java/com/diffplug/spotless/maven/SpotlessApplyMojo.java b/plugin-maven/src/main/java/com/diffplug/spotless/maven/SpotlessApplyMojo.java index 440b72c21e..f7f23d6d75 100644 --- a/plugin-maven/src/main/java/com/diffplug/spotless/maven/SpotlessApplyMojo.java +++ b/plugin-maven/src/main/java/com/diffplug/spotless/maven/SpotlessApplyMojo.java @@ -33,11 +33,11 @@ public class SpotlessApplyMojo extends AbstractSpotlessMojo { @Override protected void process(Iterable files, Formatter formatter, UpToDateChecker upToDateChecker) throws MojoExecutionException { - ImpactedFilesTracker impactedFilesTracker = new ImpactedFilesTracker(); + ImpactedFilesTracker counter = new ImpactedFilesTracker(); for (File file : files) { if (upToDateChecker.isUpToDate(file.toPath())) { - impactedFilesTracker.skippedAsCleanCache(); + counter.skippedAsCleanCache(); if (getLog().isDebugEnabled()) { getLog().debug("Spotless will not format an up-to-date file: " + file); } @@ -50,9 +50,9 @@ protected void process(Iterable files, Formatter formatter, UpToDateChecke getLog().info(String.format("Writing clean file: %s", file)); dirtyState.writeCanonicalTo(file); buildContext.refresh(file); - impactedFilesTracker.cleaned(); + counter.cleaned(); } else { - impactedFilesTracker.checkedButAlreadyClean(); + counter.checkedButAlreadyClean(); } } catch (IOException e) { throw new MojoExecutionException("Unable to format file " + file, e); @@ -62,13 +62,9 @@ protected void process(Iterable files, Formatter formatter, UpToDateChecke } // We print the number of considered files which is useful when ratchetFrom is setup - int skippedAsCleanCache = impactedFilesTracker.getSkippedAsCleanCache(); - int checkedButAlreadyClean = impactedFilesTracker.getCheckedButAlreadyClean(); - int cleaned = impactedFilesTracker.getCleaned(); - int totalProcessed = skippedAsCleanCache + checkedButAlreadyClean + cleaned; - if (totalProcessed > 0) { + if (counter.getTotal() > 0) { getLog().info(String.format("Spotless.%s is keeping %s files clean - %s were changed to be clean, %s were already clean, %s were skipped because caching determined they were already clean", - formatter.getName(), totalProcessed, cleaned, checkedButAlreadyClean, skippedAsCleanCache)); + formatter.getName(), counter.getTotal(), counter.getCleaned(), counter.getCheckedButAlreadyClean(), counter.getSkippedAsCleanCache())); } else { getLog().warn(String.format("Spotless.%s has no target files. Examine your ``: https://github.com/diffplug/spotless/tree/main/plugin-maven#quickstart", formatter.getName())); } From 1981d4b2c8f521264e1d3ece408daf4bebf97e49 Mon Sep 17 00:00:00 2001 From: Aleksey Genus Date: Tue, 31 Jan 2023 16:31:50 +0600 Subject: [PATCH 707/757] Sort by keys inside json arrays --- .../spotless/glue/gson/GsonFormatterFunc.java | 32 +++++++++++++++---- 1 file changed, 25 insertions(+), 7 deletions(-) diff --git a/lib/src/gson/java/com/diffplug/spotless/glue/gson/GsonFormatterFunc.java b/lib/src/gson/java/com/diffplug/spotless/glue/gson/GsonFormatterFunc.java index b19476a1a8..0ff5037cba 100644 --- a/lib/src/gson/java/com/diffplug/spotless/glue/gson/GsonFormatterFunc.java +++ b/lib/src/gson/java/com/diffplug/spotless/glue/gson/GsonFormatterFunc.java @@ -21,6 +21,7 @@ import com.google.gson.Gson; import com.google.gson.GsonBuilder; +import com.google.gson.JsonArray; import com.google.gson.JsonElement; import com.google.gson.JsonObject; import com.google.gson.stream.JsonWriter; @@ -57,8 +58,8 @@ public String apply(String inputString) { if (jsonElement == null) { throw new AssertionError(FAILED_TO_PARSE_ERROR_MESSAGE); } - if (gsonConfig.isSortByKeys() && jsonElement.isJsonObject()) { - jsonElement = sortByKeys(jsonElement.getAsJsonObject()); + if (gsonConfig.isSortByKeys()) { + jsonElement = sortByKeys(jsonElement); } try (StringWriter stringWriter = new StringWriter()) { JsonWriter jsonWriter = new JsonWriter(stringWriter); @@ -72,19 +73,36 @@ public String apply(String inputString) { return result; } + private JsonElement sortByKeys(JsonElement jsonElement) { + if (jsonElement.isJsonArray()) { + return sortByKeys(jsonElement.getAsJsonArray()); + } else if (jsonElement.isJsonObject()) { + return sortByKeys(jsonElement.getAsJsonObject()); + } else { + return jsonElement; + } + } + private JsonElement sortByKeys(JsonObject jsonObject) { JsonObject result = new JsonObject(); jsonObject.keySet().stream().sorted() .forEach(key -> { - JsonElement element = jsonObject.get(key); - if (element.isJsonObject()) { - element = sortByKeys(element.getAsJsonObject()); - } - result.add(key, element); + JsonElement sorted = sortByKeys(jsonObject.get(key)); + result.add(key, sorted); }); return result; } + private JsonElement sortByKeys(JsonArray jsonArray) { + var result = new JsonArray(); + for (JsonElement element : jsonArray) { + JsonElement sorted = sortByKeys(element); + result.add(sorted); + } + + return result; + } + private String generateIndent(int indentSpaces) { return String.join("", Collections.nCopies(indentSpaces, " ")); } From d77a3390fd4a378467f2c5b5a790aed2febaa48f Mon Sep 17 00:00:00 2001 From: Aleksey Genus Date: Tue, 31 Jan 2023 17:24:14 +0600 Subject: [PATCH 708/757] Add changes --- CHANGES.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGES.md b/CHANGES.md index 401998b233..72a4b99e93 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -12,6 +12,7 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format ( ## [Unreleased] ### Changes * **POTENTIALLY BREAKING** Bump bytecode from Java 8 to 11 ([#1530](https://github.com/diffplug/spotless/pull/1530) part 2 of [#1337](https://github.com/diffplug/spotless/issues/1337)) +* **POTENTIALLY BREAKING** `sortByKeys` for JSON formatting now takes into account objects inside arrays ([#1546](https://github.com/diffplug/spotless/pull/1546)) ## [2.34.0] - 2023-01-26 ### Added From 6a9dcfd99ccdf5bec5f7330bd4bae9b404d78fc5 Mon Sep 17 00:00:00 2001 From: Ned Twigg Date: Tue, 31 Jan 2023 09:31:49 -0800 Subject: [PATCH 709/757] Stop disabling plugin-maven on JITPACK. --- settings.gradle | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/settings.gradle b/settings.gradle index ac0e81a61b..9573775884 100644 --- a/settings.gradle +++ b/settings.gradle @@ -91,7 +91,7 @@ def getStartProperty(java.lang.String name) { } -if (System.getenv('SPOTLESS_EXCLUDE_MAVEN') != 'true' && getStartProperty('SPOTLESS_EXCLUDE_MAVEN') != 'true' && System.getenv('JITPACK') != 'true') { +if (System.getenv('SPOTLESS_EXCLUDE_MAVEN') != 'true' && getStartProperty('SPOTLESS_EXCLUDE_MAVEN') != 'true') { include 'plugin-maven' // maven-specific glue code } From 4c7b616e510bd83167ff329361ad819fac28ae6e Mon Sep 17 00:00:00 2001 From: Ned Twigg Date: Tue, 31 Jan 2023 09:36:09 -0800 Subject: [PATCH 710/757] Set JitPack build JDK to 11. --- jitpack.yml | 2 ++ 1 file changed, 2 insertions(+) create mode 100644 jitpack.yml diff --git a/jitpack.yml b/jitpack.yml new file mode 100644 index 0000000000..adb3fe10c8 --- /dev/null +++ b/jitpack.yml @@ -0,0 +1,2 @@ +jdk: + - openjdk11 From c77a4a609afa04b4f5969b7eabecd468cf88664e Mon Sep 17 00:00:00 2001 From: Ned Twigg Date: Tue, 31 Jan 2023 09:49:13 -0800 Subject: [PATCH 711/757] Disable signing on JitPack. --- gradle/java-publish.gradle | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gradle/java-publish.gradle b/gradle/java-publish.gradle index 7d2055d78d..4f77a43ac2 100644 --- a/gradle/java-publish.gradle +++ b/gradle/java-publish.gradle @@ -170,7 +170,7 @@ model { } } -if (!version.endsWith('-SNAPSHOT')) { +if (!version.endsWith('-SNAPSHOT') && System.getenv('JITPACK') != 'true') { signing { String gpg_key = decode64('ORG_GRADLE_PROJECT_gpg_key64') useInMemoryPgpKeys(gpg_key, System.env['ORG_GRADLE_PROJECT_gpg_passphrase']) From 1c060830640b39f04b2e16b6ac49da52d7d0d276 Mon Sep 17 00:00:00 2001 From: Ned Twigg Date: Tue, 31 Jan 2023 09:58:13 -0800 Subject: [PATCH 712/757] Another attempt to disable signing on JitPack. --- gradle/java-publish.gradle | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/gradle/java-publish.gradle b/gradle/java-publish.gradle index 4f77a43ac2..3839391d3a 100644 --- a/gradle/java-publish.gradle +++ b/gradle/java-publish.gradle @@ -170,7 +170,11 @@ model { } } -if (!version.endsWith('-SNAPSHOT') && System.getenv('JITPACK') != 'true') { +if (System.getenv('JITPACK') == 'true') { + signing { + setRequired(false) + } +} else if (!version.endsWith('-SNAPSHOT')) { signing { String gpg_key = decode64('ORG_GRADLE_PROJECT_gpg_key64') useInMemoryPgpKeys(gpg_key, System.env['ORG_GRADLE_PROJECT_gpg_passphrase']) From cc43cf1becc90cf964234fa00bd542c0b873d279 Mon Sep 17 00:00:00 2001 From: Ned Twigg Date: Tue, 31 Jan 2023 13:47:59 -0800 Subject: [PATCH 713/757] Another attempt at fixing JitPack. --- gradle/java-publish.gradle | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gradle/java-publish.gradle b/gradle/java-publish.gradle index 3839391d3a..7583bbe344 100644 --- a/gradle/java-publish.gradle +++ b/gradle/java-publish.gradle @@ -170,7 +170,7 @@ model { } } -if (System.getenv('JITPACK') == 'true') { +if (System.env['JITPACK'] == 'true') { signing { setRequired(false) } From e3f1ca4c9cd37356c8940c28814e441e78fe02c5 Mon Sep 17 00:00:00 2001 From: Ned Twigg Date: Tue, 31 Jan 2023 13:59:54 -0800 Subject: [PATCH 714/757] Update contributing guide and changelog. --- CONTRIBUTING.md | 2 +- plugin-maven/CHANGES.md | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 782e377d58..783f58b9af 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -207,7 +207,7 @@ If it doesn't work, you can check the JitPack log at `https://jitpack.io/com/git ### Maven -Run `./gradlew publishToMavenLocal` to publish this to your local repository. The maven plugin is not published to JitPack due to [jitpack/jitpack.io#4112](https://github.com/jitpack/jitpack.io/issues/4112). +Run `./gradlew publishToMavenLocal` to publish this to your local repository. You can also use the JitPack artifacts, using the same principles as Gradle above. ## License diff --git a/plugin-maven/CHANGES.md b/plugin-maven/CHANGES.md index c9e0f420a5..0029814ae9 100644 --- a/plugin-maven/CHANGES.md +++ b/plugin-maven/CHANGES.md @@ -5,6 +5,7 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format ( ## [Unreleased] ### Added * A synthesis log with the number of considered files is added after each formatter execution ([#1507](https://github.com/diffplug/spotless/pull/1507)) +* Any commit of the Spotless maven plugin now available via JitPack ([#1547](https://github.com/diffplug/spotless/pull/1547)) ## [2.31.0] - 2023-01-26 ### Added From a413524f4fc09814c51522897453e6dae453e0d7 Mon Sep 17 00:00:00 2001 From: Aleksey Genus Date: Wed, 1 Feb 2023 11:47:14 +0600 Subject: [PATCH 715/757] Add changes to maven and gradle changelogs Add tests --- plugin-gradle/CHANGES.md | 2 ++ plugin-maven/CHANGES.md | 2 ++ testlib/src/main/resources/json/sortByKeysAfter.json | 6 ++++++ .../src/main/resources/json/sortByKeysAfterDisabled.json | 6 ++++++ testlib/src/main/resources/json/sortByKeysBefore.json | 6 ++++++ 5 files changed, 22 insertions(+) diff --git a/plugin-gradle/CHANGES.md b/plugin-gradle/CHANGES.md index 49ef0adbbe..a81ee7bd93 100644 --- a/plugin-gradle/CHANGES.md +++ b/plugin-gradle/CHANGES.md @@ -3,6 +3,8 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format (starting after version `3.27.0`). ## [Unreleased] +### Changes +* **POTENTIALLY BREAKING** `sortByKeys` for JSON formatting now takes into account objects inside arrays ([#1546](https://github.com/diffplug/spotless/pull/1546)) ## [6.14.0] - 2023-01-26 ### Added diff --git a/plugin-maven/CHANGES.md b/plugin-maven/CHANGES.md index c9e0f420a5..1ffea0faa7 100644 --- a/plugin-maven/CHANGES.md +++ b/plugin-maven/CHANGES.md @@ -5,6 +5,8 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format ( ## [Unreleased] ### Added * A synthesis log with the number of considered files is added after each formatter execution ([#1507](https://github.com/diffplug/spotless/pull/1507)) +### Changes +* **POTENTIALLY BREAKING** `sortByKeys` for JSON formatting now takes into account objects inside arrays ([#1546](https://github.com/diffplug/spotless/pull/1546)) ## [2.31.0] - 2023-01-26 ### Added diff --git a/testlib/src/main/resources/json/sortByKeysAfter.json b/testlib/src/main/resources/json/sortByKeysAfter.json index c4a48de2f2..7a83087f1d 100644 --- a/testlib/src/main/resources/json/sortByKeysAfter.json +++ b/testlib/src/main/resources/json/sortByKeysAfter.json @@ -6,6 +6,12 @@ 2, 1 ], + "_objectsInArraysAreSorted": [ + { + "a": "1", + "b": 2 + } + ], "a": 3, "c": 4, "x": 5, diff --git a/testlib/src/main/resources/json/sortByKeysAfterDisabled.json b/testlib/src/main/resources/json/sortByKeysAfterDisabled.json index de7462bb98..81d81e6891 100644 --- a/testlib/src/main/resources/json/sortByKeysAfterDisabled.json +++ b/testlib/src/main/resources/json/sortByKeysAfterDisabled.json @@ -15,5 +15,11 @@ 3, 2, 1 + ], + "_objectsInArraysAreSorted": [ + { + "b": 2, + "a": "1" + } ] } diff --git a/testlib/src/main/resources/json/sortByKeysBefore.json b/testlib/src/main/resources/json/sortByKeysBefore.json index de7462bb98..81d81e6891 100644 --- a/testlib/src/main/resources/json/sortByKeysBefore.json +++ b/testlib/src/main/resources/json/sortByKeysBefore.json @@ -15,5 +15,11 @@ 3, 2, 1 + ], + "_objectsInArraysAreSorted": [ + { + "b": 2, + "a": "1" + } ] } From c060599aa9c8cb2ee9ad8660cf891ec3e4765f31 Mon Sep 17 00:00:00 2001 From: Aleksey Genus Date: Wed, 1 Feb 2023 11:48:14 +0600 Subject: [PATCH 716/757] Make values consistent --- testlib/src/main/resources/json/sortByKeysAfter.json | 2 +- testlib/src/main/resources/json/sortByKeysAfterDisabled.json | 2 +- testlib/src/main/resources/json/sortByKeysBefore.json | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/testlib/src/main/resources/json/sortByKeysAfter.json b/testlib/src/main/resources/json/sortByKeysAfter.json index 7a83087f1d..070904e872 100644 --- a/testlib/src/main/resources/json/sortByKeysAfter.json +++ b/testlib/src/main/resources/json/sortByKeysAfter.json @@ -8,7 +8,7 @@ ], "_objectsInArraysAreSorted": [ { - "a": "1", + "a": 1, "b": 2 } ], diff --git a/testlib/src/main/resources/json/sortByKeysAfterDisabled.json b/testlib/src/main/resources/json/sortByKeysAfterDisabled.json index 81d81e6891..eb9e38241f 100644 --- a/testlib/src/main/resources/json/sortByKeysAfterDisabled.json +++ b/testlib/src/main/resources/json/sortByKeysAfterDisabled.json @@ -19,7 +19,7 @@ "_objectsInArraysAreSorted": [ { "b": 2, - "a": "1" + "a": 1 } ] } diff --git a/testlib/src/main/resources/json/sortByKeysBefore.json b/testlib/src/main/resources/json/sortByKeysBefore.json index 81d81e6891..eb9e38241f 100644 --- a/testlib/src/main/resources/json/sortByKeysBefore.json +++ b/testlib/src/main/resources/json/sortByKeysBefore.json @@ -19,7 +19,7 @@ "_objectsInArraysAreSorted": [ { "b": 2, - "a": "1" + "a": 1 } ] } From 62ddd9eb084721f963fadd03ef235f0e1f00fa84 Mon Sep 17 00:00:00 2001 From: Benoit Lacelle Date: Wed, 1 Feb 2023 12:30:32 +0400 Subject: [PATCH 717/757] Switch from WARN to DEBUG --- .../java/com/diffplug/spotless/maven/SpotlessApplyMojo.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugin-maven/src/main/java/com/diffplug/spotless/maven/SpotlessApplyMojo.java b/plugin-maven/src/main/java/com/diffplug/spotless/maven/SpotlessApplyMojo.java index f7f23d6d75..028cc3fb9c 100644 --- a/plugin-maven/src/main/java/com/diffplug/spotless/maven/SpotlessApplyMojo.java +++ b/plugin-maven/src/main/java/com/diffplug/spotless/maven/SpotlessApplyMojo.java @@ -66,7 +66,7 @@ protected void process(Iterable files, Formatter formatter, UpToDateChecke getLog().info(String.format("Spotless.%s is keeping %s files clean - %s were changed to be clean, %s were already clean, %s were skipped because caching determined they were already clean", formatter.getName(), counter.getTotal(), counter.getCleaned(), counter.getCheckedButAlreadyClean(), counter.getSkippedAsCleanCache())); } else { - getLog().warn(String.format("Spotless.%s has no target files. Examine your ``: https://github.com/diffplug/spotless/tree/main/plugin-maven#quickstart", formatter.getName())); + getLog().debug(String.format("Spotless.%s has no target files. Examine your ``: https://github.com/diffplug/spotless/tree/main/plugin-maven#quickstart", formatter.getName())); } } } From df8fbf22848a61dd0fff91c19eaff19ca080630a Mon Sep 17 00:00:00 2001 From: Aleksey Genus Date: Wed, 1 Feb 2023 14:36:20 +0600 Subject: [PATCH 718/757] Fix jackson tests --- .../main/resources/json/sortByKeysAfterDisabled_Simple.json | 4 ++++ testlib/src/main/resources/json/sortByKeysAfter_Jackson.json | 4 ++++ .../json/sortByKeysAfter_Jackson_spaceAfterKeySeparator.json | 4 ++++ 3 files changed, 12 insertions(+) diff --git a/testlib/src/main/resources/json/sortByKeysAfterDisabled_Simple.json b/testlib/src/main/resources/json/sortByKeysAfterDisabled_Simple.json index d2d3612fbd..cd7ebc2be1 100644 --- a/testlib/src/main/resources/json/sortByKeysAfterDisabled_Simple.json +++ b/testlib/src/main/resources/json/sortByKeysAfterDisabled_Simple.json @@ -11,6 +11,10 @@ "x": 5, "X": 2 }, + "_objectsInArraysAreSorted": [{ + "a": 1, + "b": 2 + }], "_arraysNotSorted": [ 3, 2, diff --git a/testlib/src/main/resources/json/sortByKeysAfter_Jackson.json b/testlib/src/main/resources/json/sortByKeysAfter_Jackson.json index 3af39fd0fb..003b2ba66f 100644 --- a/testlib/src/main/resources/json/sortByKeysAfter_Jackson.json +++ b/testlib/src/main/resources/json/sortByKeysAfter_Jackson.json @@ -2,6 +2,10 @@ "A": 1, "X": 2, "_arraysNotSorted": [ 3, 2, 1 ], + "_objectsInArraysAreSorted": [ { + "a": 1, + "b": 2 + } ], "a": 3, "c": 4, "x": 5, diff --git a/testlib/src/main/resources/json/sortByKeysAfter_Jackson_spaceAfterKeySeparator.json b/testlib/src/main/resources/json/sortByKeysAfter_Jackson_spaceAfterKeySeparator.json index 3af39fd0fb..003b2ba66f 100644 --- a/testlib/src/main/resources/json/sortByKeysAfter_Jackson_spaceAfterKeySeparator.json +++ b/testlib/src/main/resources/json/sortByKeysAfter_Jackson_spaceAfterKeySeparator.json @@ -2,6 +2,10 @@ "A": 1, "X": 2, "_arraysNotSorted": [ 3, 2, 1 ], + "_objectsInArraysAreSorted": [ { + "a": 1, + "b": 2 + } ], "a": 3, "c": 4, "x": 5, From dc9878b949b7e00058ef69d341e3824135f76640 Mon Sep 17 00:00:00 2001 From: Kostiantyn Liutovych Date: Sat, 4 Feb 2023 14:24:18 +0100 Subject: [PATCH 719/757] Respect sourceDirectory/testSourceDirectory configs for Java formatters --- plugin-maven/CHANGES.md | 2 + .../spotless/maven/AbstractSpotlessMojo.java | 2 +- .../spotless/maven/FormatterFactory.java | 3 +- .../spotless/maven/antlr4/Antlr4.java | 6 +- .../com/diffplug/spotless/maven/cpp/Cpp.java | 6 +- .../spotless/maven/generic/Format.java | 6 +- .../spotless/maven/groovy/Groovy.java | 6 +- .../diffplug/spotless/maven/java/Java.java | 31 +++- .../spotless/maven/javascript/Javascript.java | 4 +- .../diffplug/spotless/maven/json/Json.java | 4 +- .../spotless/maven/kotlin/Kotlin.java | 6 +- .../spotless/maven/markdown/Markdown.java | 6 +- .../com/diffplug/spotless/maven/pom/Pom.java | 6 +- .../spotless/maven/python/Python.java | 6 +- .../diffplug/spotless/maven/scala/Scala.java | 6 +- .../com/diffplug/spotless/maven/sql/Sql.java | 6 +- .../spotless/maven/typescript/Typescript.java | 4 +- .../diffplug/spotless/maven/yaml/Yaml.java | 4 +- .../maven/MavenIntegrationHarness.java | 17 +- .../maven/MultiModuleProjectTest.java | 2 +- .../maven/java/JavaDefaultIncludesTest.java | 151 ++++++++++++++++++ .../src/test/resources/pom-test.xml.mustache | 1 + 22 files changed, 250 insertions(+), 35 deletions(-) create mode 100644 plugin-maven/src/test/java/com/diffplug/spotless/maven/java/JavaDefaultIncludesTest.java diff --git a/plugin-maven/CHANGES.md b/plugin-maven/CHANGES.md index 9c0b237ea3..b924c07fd6 100644 --- a/plugin-maven/CHANGES.md +++ b/plugin-maven/CHANGES.md @@ -5,6 +5,8 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format ( ## [Unreleased] ### Added * A synthesis log with the number of considered files is added after each formatter execution ([#1507](https://github.com/diffplug/spotless/pull/1507)) +### Fixed +* Respect `sourceDirectory` and `testSourceDirectory` POM configurations for Java formatters ([#1553](https://github.com/diffplug/spotless/pull/1553)) ### Changes * **POTENTIALLY BREAKING** `sortByKeys` for JSON formatting now takes into account objects inside arrays ([#1546](https://github.com/diffplug/spotless/pull/1546)) * Any commit of the Spotless maven plugin now available via JitPack ([#1547](https://github.com/diffplug/spotless/pull/1547)) diff --git a/plugin-maven/src/main/java/com/diffplug/spotless/maven/AbstractSpotlessMojo.java b/plugin-maven/src/main/java/com/diffplug/spotless/maven/AbstractSpotlessMojo.java index c4082f52e0..f6aab0eabb 100644 --- a/plugin-maven/src/main/java/com/diffplug/spotless/maven/AbstractSpotlessMojo.java +++ b/plugin-maven/src/main/java/com/diffplug/spotless/maven/AbstractSpotlessMojo.java @@ -320,7 +320,7 @@ private static String withTrailingSeparator(String path) { private Set getIncludes(FormatterFactory formatterFactory) { Set configuredIncludes = formatterFactory.includes(); - Set includes = configuredIncludes.isEmpty() ? formatterFactory.defaultIncludes() : configuredIncludes; + Set includes = configuredIncludes.isEmpty() ? formatterFactory.defaultIncludes(project) : configuredIncludes; if (includes.isEmpty()) { throw new PluginException("You must specify some files to include, such as 'src/**/*.blah'"); } diff --git a/plugin-maven/src/main/java/com/diffplug/spotless/maven/FormatterFactory.java b/plugin-maven/src/main/java/com/diffplug/spotless/maven/FormatterFactory.java index b78e987d34..c4a6663087 100644 --- a/plugin-maven/src/main/java/com/diffplug/spotless/maven/FormatterFactory.java +++ b/plugin-maven/src/main/java/com/diffplug/spotless/maven/FormatterFactory.java @@ -29,6 +29,7 @@ import java.util.stream.Collectors; import org.apache.maven.plugins.annotations.Parameter; +import org.apache.maven.project.MavenProject; import com.diffplug.common.collect.Sets; import com.diffplug.spotless.FormatExceptionPolicyStrict; @@ -71,7 +72,7 @@ public abstract class FormatterFactory { private ToggleOffOn toggle; - public abstract Set defaultIncludes(); + public abstract Set defaultIncludes(MavenProject project); public abstract String licenseHeaderDelimiter(); diff --git a/plugin-maven/src/main/java/com/diffplug/spotless/maven/antlr4/Antlr4.java b/plugin-maven/src/main/java/com/diffplug/spotless/maven/antlr4/Antlr4.java index bc24ebcf16..a43416fb4e 100644 --- a/plugin-maven/src/main/java/com/diffplug/spotless/maven/antlr4/Antlr4.java +++ b/plugin-maven/src/main/java/com/diffplug/spotless/maven/antlr4/Antlr4.java @@ -1,5 +1,5 @@ /* - * Copyright 2016-2020 DiffPlug + * Copyright 2016-2023 DiffPlug * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -17,6 +17,8 @@ import java.util.Set; +import org.apache.maven.project.MavenProject; + import com.diffplug.common.collect.ImmutableSet; import com.diffplug.spotless.antlr4.Antlr4Defaults; import com.diffplug.spotless.maven.FormatterFactory; @@ -30,7 +32,7 @@ */ public class Antlr4 extends FormatterFactory { @Override - public Set defaultIncludes() { + public Set defaultIncludes(MavenProject project) { return ImmutableSet.of(Antlr4Defaults.includes()); } diff --git a/plugin-maven/src/main/java/com/diffplug/spotless/maven/cpp/Cpp.java b/plugin-maven/src/main/java/com/diffplug/spotless/maven/cpp/Cpp.java index f1d07d8552..44940ae4d8 100644 --- a/plugin-maven/src/main/java/com/diffplug/spotless/maven/cpp/Cpp.java +++ b/plugin-maven/src/main/java/com/diffplug/spotless/maven/cpp/Cpp.java @@ -1,5 +1,5 @@ /* - * Copyright 2016-2020 DiffPlug + * Copyright 2016-2023 DiffPlug * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -18,6 +18,8 @@ import java.util.Collections; import java.util.Set; +import org.apache.maven.project.MavenProject; + import com.diffplug.spotless.cpp.CppDefaults; import com.diffplug.spotless.maven.FormatterFactory; import com.diffplug.spotless.maven.generic.LicenseHeader; @@ -30,7 +32,7 @@ */ public class Cpp extends FormatterFactory { @Override - public Set defaultIncludes() { + public Set defaultIncludes(MavenProject project) { return Collections.emptySet(); } diff --git a/plugin-maven/src/main/java/com/diffplug/spotless/maven/generic/Format.java b/plugin-maven/src/main/java/com/diffplug/spotless/maven/generic/Format.java index 465381fb52..a696e13ffb 100644 --- a/plugin-maven/src/main/java/com/diffplug/spotless/maven/generic/Format.java +++ b/plugin-maven/src/main/java/com/diffplug/spotless/maven/generic/Format.java @@ -1,5 +1,5 @@ /* - * Copyright 2016 DiffPlug + * Copyright 2016-2023 DiffPlug * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -18,6 +18,8 @@ import java.util.Collections; import java.util.Set; +import org.apache.maven.project.MavenProject; + import com.diffplug.spotless.maven.FormatterFactory; /** @@ -29,7 +31,7 @@ public class Format extends FormatterFactory { @Override - public Set defaultIncludes() { + public Set defaultIncludes(MavenProject project) { return Collections.emptySet(); } diff --git a/plugin-maven/src/main/java/com/diffplug/spotless/maven/groovy/Groovy.java b/plugin-maven/src/main/java/com/diffplug/spotless/maven/groovy/Groovy.java index e9b3c6c412..8041b812f9 100644 --- a/plugin-maven/src/main/java/com/diffplug/spotless/maven/groovy/Groovy.java +++ b/plugin-maven/src/main/java/com/diffplug/spotless/maven/groovy/Groovy.java @@ -1,5 +1,5 @@ /* - * Copyright 2020-2021 DiffPlug + * Copyright 2020-2023 DiffPlug * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -17,6 +17,8 @@ import java.util.Set; +import org.apache.maven.project.MavenProject; + import com.diffplug.common.collect.ImmutableSet; import com.diffplug.spotless.maven.FormatterFactory; import com.diffplug.spotless.maven.generic.LicenseHeader; @@ -33,7 +35,7 @@ public class Groovy extends FormatterFactory { private static final String LICENSE_HEADER_DELIMITER = "package "; @Override - public Set defaultIncludes() { + public Set defaultIncludes(MavenProject project) { return DEFAULT_INCLUDES; } diff --git a/plugin-maven/src/main/java/com/diffplug/spotless/maven/java/Java.java b/plugin-maven/src/main/java/com/diffplug/spotless/maven/java/Java.java index 4bd018d53c..0921a838b3 100644 --- a/plugin-maven/src/main/java/com/diffplug/spotless/maven/java/Java.java +++ b/plugin-maven/src/main/java/com/diffplug/spotless/maven/java/Java.java @@ -1,5 +1,5 @@ /* - * Copyright 2016-2022 DiffPlug + * Copyright 2016-2023 DiffPlug * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -15,9 +15,17 @@ */ package com.diffplug.spotless.maven.java; +import static java.util.stream.Collectors.toSet; + +import java.io.File; +import java.nio.file.Path; +import java.nio.file.Paths; import java.util.Set; +import java.util.stream.Stream; + +import org.apache.maven.model.Build; +import org.apache.maven.project.MavenProject; -import com.diffplug.common.collect.ImmutableSet; import com.diffplug.spotless.maven.FormatterFactory; import com.diffplug.spotless.maven.generic.LicenseHeader; @@ -29,12 +37,17 @@ */ public class Java extends FormatterFactory { - private static final Set DEFAULT_INCLUDES = ImmutableSet.of("src/main/java/**/*.java", "src/test/java/**/*.java"); private static final String LICENSE_HEADER_DELIMITER = "package "; @Override - public Set defaultIncludes() { - return DEFAULT_INCLUDES; + public Set defaultIncludes(MavenProject project) { + Path projectDir = project.getBasedir().toPath(); + Build build = project.getBuild(); + return Stream.of(build.getSourceDirectory(), build.getTestSourceDirectory()) + .map(Paths::get) + .map(projectDir::relativize) + .map(Java::fileMask) + .collect(toSet()); } @Override @@ -65,4 +78,12 @@ public void addRemoveUnusedImports(RemoveUnusedImports removeUnusedImports) { public void addFormatAnnotations(FormatAnnotations formatAnnotations) { addStepFactory(formatAnnotations); } + + private static String fileMask(Path path) { + String dir = path.toString(); + if (!dir.endsWith(File.separator)) { + dir += File.separator; + } + return dir + "**" + File.separator + "*.java"; + } } diff --git a/plugin-maven/src/main/java/com/diffplug/spotless/maven/javascript/Javascript.java b/plugin-maven/src/main/java/com/diffplug/spotless/maven/javascript/Javascript.java index 7ca35dd258..31a5917e06 100644 --- a/plugin-maven/src/main/java/com/diffplug/spotless/maven/javascript/Javascript.java +++ b/plugin-maven/src/main/java/com/diffplug/spotless/maven/javascript/Javascript.java @@ -18,6 +18,8 @@ import java.util.Collections; import java.util.Set; +import org.apache.maven.project.MavenProject; + import com.diffplug.spotless.maven.FormatterFactory; /** @@ -27,7 +29,7 @@ */ public class Javascript extends FormatterFactory { @Override - public Set defaultIncludes() { + public Set defaultIncludes(MavenProject project) { return Collections.emptySet(); } diff --git a/plugin-maven/src/main/java/com/diffplug/spotless/maven/json/Json.java b/plugin-maven/src/main/java/com/diffplug/spotless/maven/json/Json.java index 852088278a..5bb7c17b3a 100644 --- a/plugin-maven/src/main/java/com/diffplug/spotless/maven/json/Json.java +++ b/plugin-maven/src/main/java/com/diffplug/spotless/maven/json/Json.java @@ -18,6 +18,8 @@ import java.util.Collections; import java.util.Set; +import org.apache.maven.project.MavenProject; + import com.diffplug.spotless.maven.FormatterFactory; /** @@ -27,7 +29,7 @@ public class Json extends FormatterFactory { public static final int DEFAULT_INDENTATION = 4; @Override - public Set defaultIncludes() { + public Set defaultIncludes(MavenProject project) { return Collections.emptySet(); } diff --git a/plugin-maven/src/main/java/com/diffplug/spotless/maven/kotlin/Kotlin.java b/plugin-maven/src/main/java/com/diffplug/spotless/maven/kotlin/Kotlin.java index cfb0aad39e..18eb13773d 100644 --- a/plugin-maven/src/main/java/com/diffplug/spotless/maven/kotlin/Kotlin.java +++ b/plugin-maven/src/main/java/com/diffplug/spotless/maven/kotlin/Kotlin.java @@ -1,5 +1,5 @@ /* - * Copyright 2016-2021 DiffPlug + * Copyright 2016-2023 DiffPlug * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -19,6 +19,8 @@ import java.util.Set; +import org.apache.maven.project.MavenProject; + import com.diffplug.common.collect.ImmutableSet; import com.diffplug.spotless.maven.FormatterFactory; @@ -27,7 +29,7 @@ public class Kotlin extends FormatterFactory { private static final Set DEFAULT_INCLUDES = ImmutableSet.of("src/main/kotlin/**/*.kt", "src/test/kotlin/**/*.kt"); @Override - public Set defaultIncludes() { + public Set defaultIncludes(MavenProject project) { return DEFAULT_INCLUDES; } diff --git a/plugin-maven/src/main/java/com/diffplug/spotless/maven/markdown/Markdown.java b/plugin-maven/src/main/java/com/diffplug/spotless/maven/markdown/Markdown.java index 2ba9b1f58f..0941beb76a 100644 --- a/plugin-maven/src/main/java/com/diffplug/spotless/maven/markdown/Markdown.java +++ b/plugin-maven/src/main/java/com/diffplug/spotless/maven/markdown/Markdown.java @@ -1,5 +1,5 @@ /* - * Copyright 2021 DiffPlug + * Copyright 2021-2023 DiffPlug * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -18,6 +18,8 @@ import java.util.Collections; import java.util.Set; +import org.apache.maven.project.MavenProject; + import com.diffplug.spotless.maven.FormatterFactory; import com.diffplug.spotless.maven.generic.LicenseHeader; @@ -29,7 +31,7 @@ */ public class Markdown extends FormatterFactory { @Override - public Set defaultIncludes() { + public Set defaultIncludes(MavenProject project) { return Collections.emptySet(); } diff --git a/plugin-maven/src/main/java/com/diffplug/spotless/maven/pom/Pom.java b/plugin-maven/src/main/java/com/diffplug/spotless/maven/pom/Pom.java index f083a17c89..9a4d3eea06 100644 --- a/plugin-maven/src/main/java/com/diffplug/spotless/maven/pom/Pom.java +++ b/plugin-maven/src/main/java/com/diffplug/spotless/maven/pom/Pom.java @@ -1,5 +1,5 @@ /* - * Copyright 2021 DiffPlug + * Copyright 2021-2023 DiffPlug * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -17,6 +17,8 @@ import java.util.Set; +import org.apache.maven.project.MavenProject; + import com.diffplug.common.collect.ImmutableSet; import com.diffplug.spotless.maven.FormatterFactory; import com.diffplug.spotless.maven.generic.LicenseHeader; @@ -29,7 +31,7 @@ */ public class Pom extends FormatterFactory { @Override - public Set defaultIncludes() { + public Set defaultIncludes(MavenProject project) { return ImmutableSet.of("pom.xml"); } diff --git a/plugin-maven/src/main/java/com/diffplug/spotless/maven/python/Python.java b/plugin-maven/src/main/java/com/diffplug/spotless/maven/python/Python.java index 09443f070b..df7348c16c 100644 --- a/plugin-maven/src/main/java/com/diffplug/spotless/maven/python/Python.java +++ b/plugin-maven/src/main/java/com/diffplug/spotless/maven/python/Python.java @@ -1,5 +1,5 @@ /* - * Copyright 2021 DiffPlug + * Copyright 2021-2023 DiffPlug * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -18,6 +18,8 @@ import java.util.Collections; import java.util.Set; +import org.apache.maven.project.MavenProject; + import com.diffplug.spotless.maven.FormatterFactory; import com.diffplug.spotless.maven.generic.LicenseHeader; @@ -30,7 +32,7 @@ public class Python extends FormatterFactory { @Override - public Set defaultIncludes() { + public Set defaultIncludes(MavenProject project) { return Collections.emptySet(); } diff --git a/plugin-maven/src/main/java/com/diffplug/spotless/maven/scala/Scala.java b/plugin-maven/src/main/java/com/diffplug/spotless/maven/scala/Scala.java index 423ca71930..7a9e455f5f 100644 --- a/plugin-maven/src/main/java/com/diffplug/spotless/maven/scala/Scala.java +++ b/plugin-maven/src/main/java/com/diffplug/spotless/maven/scala/Scala.java @@ -1,5 +1,5 @@ /* - * Copyright 2016 DiffPlug + * Copyright 2016-2023 DiffPlug * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -17,6 +17,8 @@ import java.util.Set; +import org.apache.maven.project.MavenProject; + import com.diffplug.common.collect.ImmutableSet; import com.diffplug.spotless.maven.FormatterFactory; import com.diffplug.spotless.maven.generic.LicenseHeader; @@ -34,7 +36,7 @@ public class Scala extends FormatterFactory { private static final String LICENSE_HEADER_DELIMITER = "package "; @Override - public Set defaultIncludes() { + public Set defaultIncludes(MavenProject project) { return DEFAULT_INCLUDES; } diff --git a/plugin-maven/src/main/java/com/diffplug/spotless/maven/sql/Sql.java b/plugin-maven/src/main/java/com/diffplug/spotless/maven/sql/Sql.java index c49ac074d9..64ebcb55d7 100644 --- a/plugin-maven/src/main/java/com/diffplug/spotless/maven/sql/Sql.java +++ b/plugin-maven/src/main/java/com/diffplug/spotless/maven/sql/Sql.java @@ -1,5 +1,5 @@ /* - * Copyright 2020 DiffPlug + * Copyright 2020-2023 DiffPlug * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -18,6 +18,8 @@ import java.util.Collections; import java.util.Set; +import org.apache.maven.project.MavenProject; + import com.diffplug.spotless.maven.FormatterFactory; /** @@ -27,7 +29,7 @@ */ public class Sql extends FormatterFactory { @Override - public Set defaultIncludes() { + public Set defaultIncludes(MavenProject project) { return Collections.emptySet(); } diff --git a/plugin-maven/src/main/java/com/diffplug/spotless/maven/typescript/Typescript.java b/plugin-maven/src/main/java/com/diffplug/spotless/maven/typescript/Typescript.java index 6f0d7f91b2..6ba45ab719 100644 --- a/plugin-maven/src/main/java/com/diffplug/spotless/maven/typescript/Typescript.java +++ b/plugin-maven/src/main/java/com/diffplug/spotless/maven/typescript/Typescript.java @@ -18,6 +18,8 @@ import java.util.Collections; import java.util.Set; +import org.apache.maven.project.MavenProject; + import com.diffplug.spotless.maven.FormatterFactory; /** @@ -27,7 +29,7 @@ */ public class Typescript extends FormatterFactory { @Override - public Set defaultIncludes() { + public Set defaultIncludes(MavenProject project) { return Collections.emptySet(); } diff --git a/plugin-maven/src/main/java/com/diffplug/spotless/maven/yaml/Yaml.java b/plugin-maven/src/main/java/com/diffplug/spotless/maven/yaml/Yaml.java index a6ceaaa592..e22f6d40ce 100644 --- a/plugin-maven/src/main/java/com/diffplug/spotless/maven/yaml/Yaml.java +++ b/plugin-maven/src/main/java/com/diffplug/spotless/maven/yaml/Yaml.java @@ -18,6 +18,8 @@ import java.util.Collections; import java.util.Set; +import org.apache.maven.project.MavenProject; + import com.diffplug.spotless.maven.FormatterFactory; /** @@ -25,7 +27,7 @@ */ public class Yaml extends FormatterFactory { @Override - public Set defaultIncludes() { + public Set defaultIncludes(MavenProject project) { return Collections.emptySet(); } diff --git a/plugin-maven/src/test/java/com/diffplug/spotless/maven/MavenIntegrationHarness.java b/plugin-maven/src/test/java/com/diffplug/spotless/maven/MavenIntegrationHarness.java index f4e94e573c..fdc4a745a1 100644 --- a/plugin-maven/src/test/java/com/diffplug/spotless/maven/MavenIntegrationHarness.java +++ b/plugin-maven/src/test/java/com/diffplug/spotless/maven/MavenIntegrationHarness.java @@ -54,7 +54,9 @@ public class MavenIntegrationHarness extends ResourceHarness { */ private static final String SPOTLESS_MAVEN_VERSION_IDE = null; + private static final String POM_TEMPLATE = "/pom-test.xml.mustache"; private static final String SPOTLESS_MAVEN_PLUGIN_VERSION = "spotlessMavenPluginVersion"; + private static final String BUILD = "build"; private static final String CONFIGURATION = "configuration"; private static final String EXECUTIONS = "executions"; private static final String MODULES = "modules"; @@ -209,11 +211,11 @@ protected MavenRunner mavenRunnerWithRemoteDebug() throws IOException { } protected String createPomXmlContent(String pluginVersion, String[] executions, String[] configuration, String[] dependencies, String[] plugins) throws IOException { - return createPomXmlContent("/pom-test.xml.mustache", pluginVersion, executions, configuration, dependencies, plugins); + return createPomXmlContent(POM_TEMPLATE, pluginVersion, executions, configuration, dependencies, plugins); } protected String createPomXmlContent(String pomTemplate, String pluginVersion, String[] executions, String[] configuration, String[] dependencies, String[] plugins) throws IOException { - Map params = buildPomXmlParams(pluginVersion, executions, configuration, null, dependencies, plugins); + Map params = buildPomXmlParams(pluginVersion, null, executions, configuration, null, dependencies, plugins); return createPomXmlContent(pomTemplate, params); } @@ -221,6 +223,11 @@ protected String createPomXmlContent(String pluginVersion, String[] executions, return createPomXmlContent(pluginVersion, executions, configuration, null, null); } + protected String createPomXmlContent(String[] build, String[] configuration) throws IOException { + Map params = buildPomXmlParams(null, build, null, configuration, null, null, null); + return createPomXmlContent(POM_TEMPLATE, params); + } + protected String createPomXmlContent(String pomTemplate, Map params) throws IOException { URL url = MavenIntegrationHarness.class.getResource(pomTemplate); try (BufferedReader reader = Resources.asCharSource(url, StandardCharsets.UTF_8).openBufferedStream()) { @@ -231,10 +238,14 @@ protected String createPomXmlContent(String pomTemplate, Map par } } - protected static Map buildPomXmlParams(String pluginVersion, String[] executions, String[] configuration, String[] modules, String[] dependencies, String[] plugins) { + protected static Map buildPomXmlParams(String pluginVersion, String[] build, String[] executions, String[] configuration, String[] modules, String[] dependencies, String[] plugins) { Map params = new HashMap<>(); params.put(SPOTLESS_MAVEN_PLUGIN_VERSION, pluginVersion == null ? getSystemProperty(SPOTLESS_MAVEN_PLUGIN_VERSION) : pluginVersion); + if (build != null) { + params.put(BUILD, String.join("\n", build)); + } + if (configuration != null) { params.put(CONFIGURATION, String.join("\n", configuration)); } diff --git a/plugin-maven/src/test/java/com/diffplug/spotless/maven/MultiModuleProjectTest.java b/plugin-maven/src/test/java/com/diffplug/spotless/maven/MultiModuleProjectTest.java index 6206affc04..1c9521c402 100644 --- a/plugin-maven/src/test/java/com/diffplug/spotless/maven/MultiModuleProjectTest.java +++ b/plugin-maven/src/test/java/com/diffplug/spotless/maven/MultiModuleProjectTest.java @@ -145,7 +145,7 @@ private void createRootPom() throws IOException { modulesList.addAll(subProjects.keySet()); String[] modules = modulesList.toArray(new String[0]); - Map rootPomParams = buildPomXmlParams(null, null, configuration, modules, null, null); + Map rootPomParams = buildPomXmlParams(null, null, null, configuration, modules, null, null); setFile("pom.xml").toContent(createPomXmlContent("/multi-module/pom-parent.xml.mustache", rootPomParams)); } diff --git a/plugin-maven/src/test/java/com/diffplug/spotless/maven/java/JavaDefaultIncludesTest.java b/plugin-maven/src/test/java/com/diffplug/spotless/maven/java/JavaDefaultIncludesTest.java new file mode 100644 index 0000000000..57f717ad07 --- /dev/null +++ b/plugin-maven/src/test/java/com/diffplug/spotless/maven/java/JavaDefaultIncludesTest.java @@ -0,0 +1,151 @@ +/* + * Copyright 2023 DiffPlug + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.diffplug.spotless.maven.java; + +import java.io.IOException; +import java.util.Arrays; + +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; + +import com.diffplug.spotless.maven.MavenIntegrationHarness; + +public class JavaDefaultIncludesTest extends MavenIntegrationHarness { + + private static final String UNFORMATTED = "java/removeunusedimports/JavaCodeWithPackageUnformatted.test"; + private static final String FORMATTED = "java/removeunusedimports/JavaCodeWithPackageFormatted.test"; + + private static final String FILE_1 = "src/main/java/com/diffplug/spotless/One.java"; + private static final String FILE_2 = "src/test/java/com/diffplug/spotless/Two.java"; + private static final String FILE_3 = "src/com/diffplug/spotless/Three.java"; + private static final String FILE_4 = "test/com/diffplug/spotless/Four.java"; + private static final String FILE_5 = "foo/bar/Five.java"; + + @BeforeEach + void beforeEach() { + for (String file : Arrays.asList(FILE_1, FILE_2, FILE_3, FILE_4, FILE_5)) { + setFile(file).toResource(UNFORMATTED); + } + } + + @Test + void noCustomConfiguration() throws Exception { + writePomWithBuildConfiguration(); + + mavenRunner().withArguments("spotless:apply").runNoError(); + + // Files 1, 2 are formatted because they live under default Maven source & test source dirs + assertFile(FILE_1).sameAsResource(FORMATTED); + assertFile(FILE_2).sameAsResource(FORMATTED); + + // Files 3, 4, 5 are not formatted because they live outside default Maven source & test source dirs + assertFile(FILE_3).sameAsResource(UNFORMATTED); + assertFile(FILE_4).sameAsResource(UNFORMATTED); + assertFile(FILE_5).sameAsResource(UNFORMATTED); + } + + @Test + void customSourceDirConfiguration() throws Exception { + writePomWithBuildConfiguration("src"); + + mavenRunner().withArguments("spotless:apply").runNoError(); + + // Files 1, 2, 3 are formatted because they live under the custom-configured source dir + assertFile(FILE_1).sameAsResource(FORMATTED); + assertFile(FILE_2).sameAsResource(FORMATTED); + assertFile(FILE_3).sameAsResource(FORMATTED); + + // File 4, 5 are not formatted because they live outside the custom-configured source dir and default test source dir + assertFile(FILE_4).sameAsResource(UNFORMATTED); + assertFile(FILE_5).sameAsResource(UNFORMATTED); + } + + @Test + void customTestSourceDirConfiguration() throws Exception { + writePomWithBuildConfiguration("test"); + + mavenRunner().withArguments("spotless:apply").runNoError(); + + // File 1 is formatted because it lives under the default source dir + assertFile(FILE_1).sameAsResource(FORMATTED); + // File 4 is formatted because it lives under the custom-configured test source dir + assertFile(FILE_4).sameAsResource(FORMATTED); + + // Files 2, 3, 5 are not formatted because they live outside the default source dir and custom-configured test source dir + assertFile(FILE_2).sameAsResource(UNFORMATTED); + assertFile(FILE_3).sameAsResource(UNFORMATTED); + assertFile(FILE_5).sameAsResource(UNFORMATTED); + } + + @Test + void customSourceDirAndTestSourceDirConfiguration() throws Exception { + writePomWithBuildConfiguration( + "src", + "test"); + + mavenRunner().withArguments("spotless:apply").runNoError(); + + // Files 1, 2, 3, 4 are formatted because they live under custom-configured source and test source dirs + assertFile(FILE_1).sameAsResource(FORMATTED); + assertFile(FILE_2).sameAsResource(FORMATTED); + assertFile(FILE_3).sameAsResource(FORMATTED); + assertFile(FILE_4).sameAsResource(FORMATTED); + + // File 5 is not formatted because it lives outside custom-configured source and test source dirs + assertFile(FILE_5).sameAsResource(UNFORMATTED); + } + + @Test + void sameCustomSourceDirAndTestSourceDirConfiguration() throws Exception { + writePomWithBuildConfiguration( + "foo/bar", + "foo/bar"); + + mavenRunner().withArguments("spotless:apply").runNoError(); + + // Files 1, 2, 3, 4 are not formatted because they live outside custom-configured source and test source dirs + assertFile(FILE_1).sameAsResource(UNFORMATTED); + assertFile(FILE_2).sameAsResource(UNFORMATTED); + assertFile(FILE_3).sameAsResource(UNFORMATTED); + assertFile(FILE_4).sameAsResource(UNFORMATTED); + + // File 5 is formatted because it lives under the custom-configured source/test source dir + assertFile(FILE_5).sameAsResource(FORMATTED); + } + + @Test + void nestedCustomSourceDirAndTestSourceDirConfiguration() throws Exception { + writePomWithBuildConfiguration( + "foo", + "foo/bar"); + + mavenRunner().withArguments("spotless:apply").runNoError(); + + // Files 1, 2, 3, 4 are not formatted because they live outside custom-configured source and test source dirs + assertFile(FILE_1).sameAsResource(UNFORMATTED); + assertFile(FILE_2).sameAsResource(UNFORMATTED); + assertFile(FILE_3).sameAsResource(UNFORMATTED); + assertFile(FILE_4).sameAsResource(UNFORMATTED); + + // File 5 is formatted because it lives under the custom-configured source/test source dir + assertFile(FILE_5).sameAsResource(FORMATTED); + } + + private void writePomWithBuildConfiguration(String... build) throws IOException { + String xml = createPomXmlContent(build, new String[]{"", "", ""}); + setFile("pom.xml").toContent(xml); + } +} diff --git a/plugin-maven/src/test/resources/pom-test.xml.mustache b/plugin-maven/src/test/resources/pom-test.xml.mustache index 6db3cb0c15..f87e8c1a3e 100644 --- a/plugin-maven/src/test/resources/pom-test.xml.mustache +++ b/plugin-maven/src/test/resources/pom-test.xml.mustache @@ -20,6 +20,7 @@ + {{{build}}} {{{plugins}}} From 6d3862c702dd522fbb5f989a670b03720f8a49d9 Mon Sep 17 00:00:00 2001 From: Ned Twigg Date: Sun, 5 Feb 2023 01:07:51 -0800 Subject: [PATCH 720/757] Use the latest JScriptBox on Java 15+ --- .../main/java/com/diffplug/spotless/markdown/FreshMarkStep.java | 1 + 1 file changed, 1 insertion(+) diff --git a/lib/src/main/java/com/diffplug/spotless/markdown/FreshMarkStep.java b/lib/src/main/java/com/diffplug/spotless/markdown/FreshMarkStep.java index fca5ac39a4..4477c640c7 100644 --- a/lib/src/main/java/com/diffplug/spotless/markdown/FreshMarkStep.java +++ b/lib/src/main/java/com/diffplug/spotless/markdown/FreshMarkStep.java @@ -66,6 +66,7 @@ public static FormatterStep create(String version, Supplier> prop List mavenCoordinates = new ArrayList<>(); mavenCoordinates.add(MAVEN_COORDINATE + version); if (Jvm.version() >= 15) { + mavenCoordinates.add("com.diffplug.jscriptbox:jscriptbox:3.0.1"); mavenCoordinates.add(NASHORN_MAVEN_COORDINATE + NASHORN_VERSION); } From e9d72aa093a70a8ed66d71aa8625394fa4d0f147 Mon Sep 17 00:00:00 2001 From: Ned Twigg Date: Sun, 5 Feb 2023 01:13:31 -0800 Subject: [PATCH 721/757] Update changelogs. --- CHANGES.md | 2 ++ plugin-gradle/CHANGES.md | 3 ++- plugin-maven/CHANGES.md | 1 - 3 files changed, 4 insertions(+), 2 deletions(-) diff --git a/CHANGES.md b/CHANGES.md index 72a4b99e93..c8add05b6a 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -12,7 +12,9 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format ( ## [Unreleased] ### Changes * **POTENTIALLY BREAKING** Bump bytecode from Java 8 to 11 ([#1530](https://github.com/diffplug/spotless/pull/1530) part 2 of [#1337](https://github.com/diffplug/spotless/issues/1337)) +### Fixed * **POTENTIALLY BREAKING** `sortByKeys` for JSON formatting now takes into account objects inside arrays ([#1546](https://github.com/diffplug/spotless/pull/1546)) +* `freshmark` fixed on java 15+ ([#1304](https://github.com/diffplug/spotless/pull/1304) fixes [#803](https://github.com/diffplug/spotless/issues/803)) ## [2.34.0] - 2023-01-26 ### Added diff --git a/plugin-gradle/CHANGES.md b/plugin-gradle/CHANGES.md index a81ee7bd93..fef2c71346 100644 --- a/plugin-gradle/CHANGES.md +++ b/plugin-gradle/CHANGES.md @@ -3,7 +3,8 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format (starting after version `3.27.0`). ## [Unreleased] -### Changes +### Fixed +* `freshmark` fixed on java 15+ ([#1304](https://github.com/diffplug/spotless/pull/1304) fixes [#803](https://github.com/diffplug/spotless/issues/803)) * **POTENTIALLY BREAKING** `sortByKeys` for JSON formatting now takes into account objects inside arrays ([#1546](https://github.com/diffplug/spotless/pull/1546)) ## [6.14.0] - 2023-01-26 diff --git a/plugin-maven/CHANGES.md b/plugin-maven/CHANGES.md index b924c07fd6..d498b868c7 100644 --- a/plugin-maven/CHANGES.md +++ b/plugin-maven/CHANGES.md @@ -7,7 +7,6 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format ( * A synthesis log with the number of considered files is added after each formatter execution ([#1507](https://github.com/diffplug/spotless/pull/1507)) ### Fixed * Respect `sourceDirectory` and `testSourceDirectory` POM configurations for Java formatters ([#1553](https://github.com/diffplug/spotless/pull/1553)) -### Changes * **POTENTIALLY BREAKING** `sortByKeys` for JSON formatting now takes into account objects inside arrays ([#1546](https://github.com/diffplug/spotless/pull/1546)) * Any commit of the Spotless maven plugin now available via JitPack ([#1547](https://github.com/diffplug/spotless/pull/1547)) From 0252904844cbd3a182f9668c49073b809aee97ab Mon Sep 17 00:00:00 2001 From: runner Date: Sun, 5 Feb 2023 16:46:18 +0000 Subject: [PATCH 722/757] Published lib/2.34.1 --- CHANGES.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/CHANGES.md b/CHANGES.md index c8add05b6a..5f1a1ffa9f 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -10,6 +10,8 @@ This document is intended for Spotless developers. We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format (starting after version `1.27.0`). ## [Unreleased] + +## [2.34.1] - 2023-02-05 ### Changes * **POTENTIALLY BREAKING** Bump bytecode from Java 8 to 11 ([#1530](https://github.com/diffplug/spotless/pull/1530) part 2 of [#1337](https://github.com/diffplug/spotless/issues/1337)) ### Fixed From 2fece0442035a72fc3be978d47dca483e8d02b2c Mon Sep 17 00:00:00 2001 From: runner Date: Sun, 5 Feb 2023 16:48:11 +0000 Subject: [PATCH 723/757] Published gradle/6.14.1 --- plugin-gradle/CHANGES.md | 2 ++ plugin-gradle/README.md | 50 ++++++++++++++++++++-------------------- 2 files changed, 27 insertions(+), 25 deletions(-) diff --git a/plugin-gradle/CHANGES.md b/plugin-gradle/CHANGES.md index fef2c71346..e3234584b8 100644 --- a/plugin-gradle/CHANGES.md +++ b/plugin-gradle/CHANGES.md @@ -3,6 +3,8 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format (starting after version `3.27.0`). ## [Unreleased] + +## [6.14.1] - 2023-02-05 ### Fixed * `freshmark` fixed on java 15+ ([#1304](https://github.com/diffplug/spotless/pull/1304) fixes [#803](https://github.com/diffplug/spotless/issues/803)) * **POTENTIALLY BREAKING** `sortByKeys` for JSON formatting now takes into account objects inside arrays ([#1546](https://github.com/diffplug/spotless/pull/1546)) diff --git a/plugin-gradle/README.md b/plugin-gradle/README.md index 6a56d26e20..f61280bc7e 100644 --- a/plugin-gradle/README.md +++ b/plugin-gradle/README.md @@ -14,9 +14,9 @@ output = [ ].join('\n'); --> [![Gradle plugin](https://img.shields.io/badge/plugins.gradle.org-com.diffplug.spotless-blue.svg)](https://plugins.gradle.org/plugin/com.diffplug.spotless) -[![Changelog](https://img.shields.io/badge/changelog-6.14.0-blue.svg)](CHANGES.md) +[![Changelog](https://img.shields.io/badge/changelog-6.14.1-blue.svg)](CHANGES.md) [![Maven central](https://img.shields.io/badge/mavencentral-here-blue.svg)](https://search.maven.org/#search%7Cgav%7C1%7Cg%3A%22com.diffplug.spotless%22%20AND%20a%3A%22spotless-plugin-gradle%22) -[![Javadoc](https://img.shields.io/badge/javadoc-here-blue.svg)](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.14.0/index.html) +[![Javadoc](https://img.shields.io/badge/javadoc-here-blue.svg)](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.14.1/index.html) [![VS Code plugin](https://img.shields.io/badge/IDE-VS_Code-blueviolet.svg)](https://marketplace.visualstudio.com/items?itemName=richardwillis.vscode-spotless-gradle) [![IntelliJ plugin](https://img.shields.io/badge/IDE-IntelliJ-blueviolet.svg)](https://plugins.jetbrains.com/plugin/18321-spotless-gradle) @@ -123,10 +123,10 @@ spotless { ``` Spotless consists of a list of formats (in the example above, `misc` and `java`), and each format has: -- a `target` (the files to format), which you set with [`target`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.14.0/com/diffplug/gradle/spotless/FormatExtension.html#target-java.lang.Object...-) and [`targetExclude`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.14.0/com/diffplug/gradle/spotless/FormatExtension.html#targetExclude-java.lang.Object...-) -- a list of `FormatterStep`, which are just `String -> String` functions, such as [`replace`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.14.0/com/diffplug/gradle/spotless/FormatExtension.html#replace-java.lang.String-java.lang.CharSequence-java.lang.CharSequence-), [`replaceRegex`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.14.0/com/diffplug/gradle/spotless/FormatExtension.html#replaceRegex-java.lang.String-java.lang.String-java.lang.String-), [`trimTrailingWhitespace`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.14.0/com/diffplug/gradle/spotless/FormatExtension.html#replace-java.lang.String-java.lang.CharSequence-java.lang.CharSequence-), [`custom`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.14.0/com/diffplug/gradle/spotless/FormatExtension.html#custom-java.lang.String-groovy.lang.Closure-), [`prettier`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.14.0/com/diffplug/gradle/spotless/FormatExtension.html#prettier--), [`eclipseWtp`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.14.0/com/diffplug/gradle/spotless/FormatExtension.html#eclipseWtp-com.diffplug.spotless.extra.wtp.EclipseWtpFormatterStep-), [`licenseHeader`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.14.0/com/diffplug/gradle/spotless/FormatExtension.html#licenseHeader-java.lang.String-java.lang.String-) etc. +- a `target` (the files to format), which you set with [`target`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.14.1/com/diffplug/gradle/spotless/FormatExtension.html#target-java.lang.Object...-) and [`targetExclude`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.14.1/com/diffplug/gradle/spotless/FormatExtension.html#targetExclude-java.lang.Object...-) +- a list of `FormatterStep`, which are just `String -> String` functions, such as [`replace`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.14.1/com/diffplug/gradle/spotless/FormatExtension.html#replace-java.lang.String-java.lang.CharSequence-java.lang.CharSequence-), [`replaceRegex`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.14.1/com/diffplug/gradle/spotless/FormatExtension.html#replaceRegex-java.lang.String-java.lang.String-java.lang.String-), [`trimTrailingWhitespace`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.14.1/com/diffplug/gradle/spotless/FormatExtension.html#replace-java.lang.String-java.lang.CharSequence-java.lang.CharSequence-), [`custom`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.14.1/com/diffplug/gradle/spotless/FormatExtension.html#custom-java.lang.String-groovy.lang.Closure-), [`prettier`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.14.1/com/diffplug/gradle/spotless/FormatExtension.html#prettier--), [`eclipseWtp`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.14.1/com/diffplug/gradle/spotless/FormatExtension.html#eclipseWtp-com.diffplug.spotless.extra.wtp.EclipseWtpFormatterStep-), [`licenseHeader`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.14.1/com/diffplug/gradle/spotless/FormatExtension.html#licenseHeader-java.lang.String-java.lang.String-) etc. -All the generic steps live in [`FormatExtension`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.14.0/com/diffplug/gradle/spotless/FormatExtension.html), and there are many language-specific steps which live in its language-specific subclasses, which are described below. +All the generic steps live in [`FormatExtension`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.14.1/com/diffplug/gradle/spotless/FormatExtension.html), and there are many language-specific steps which live in its language-specific subclasses, which are described below. ### Requirements @@ -138,7 +138,7 @@ If you're stuck on an older version of Gradle, `id 'com.diffplug.gradle.spotless ## Java -`com.diffplug.gradle.spotless.JavaExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.14.0/com/diffplug/gradle/spotless/JavaExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/JavaExtension.java) +`com.diffplug.gradle.spotless.JavaExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.14.1/com/diffplug/gradle/spotless/JavaExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/JavaExtension.java) ```gradle spotless { @@ -262,8 +262,8 @@ You can make a pull request to add new annotations to Spotless's default list. ## Groovy -- `com.diffplug.gradle.spotless.GroovyExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.14.0/com/diffplug/gradle/spotless/GroovyExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/GroovyExtension.java) -- `com.diffplug.gradle.spotless.GroovyGradleExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.14.0/com/diffplug/gradle/spotless/GroovyGradleExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/GroovyGradleExtension.java) +- `com.diffplug.gradle.spotless.GroovyExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.14.1/com/diffplug/gradle/spotless/GroovyExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/GroovyExtension.java) +- `com.diffplug.gradle.spotless.GroovyGradleExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.14.1/com/diffplug/gradle/spotless/GroovyGradleExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/GroovyGradleExtension.java) Configuration for Groovy is similar to [Java](#java), in that it also supports `licenseHeader` and `importOrder`. @@ -314,8 +314,8 @@ Groovy-Eclipse formatting errors/warnings lead per default to a build failure. T ## Kotlin -- `com.diffplug.gradle.spotless.KotlinExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.14.0/com/diffplug/gradle/spotless/KotlinExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/KotlinExtension.java) -- `com.diffplug.gradle.spotless.KotlinGradleExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.14.0/com/diffplug/gradle/spotless/KotlinGradleExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/KotlinGradleExtension.java) +- `com.diffplug.gradle.spotless.KotlinExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.14.1/com/diffplug/gradle/spotless/KotlinExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/KotlinExtension.java) +- `com.diffplug.gradle.spotless.KotlinGradleExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.14.1/com/diffplug/gradle/spotless/KotlinGradleExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/KotlinGradleExtension.java) ```gradle spotless { // if you are using build.gradle.kts, instead of 'spotless {' use: @@ -386,7 +386,7 @@ spotless { ## Scala -`com.diffplug.gradle.spotless.ScalaExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.14.0/com/diffplug/gradle/spotless/ScalaExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/ScalaExtension.java) +`com.diffplug.gradle.spotless.ScalaExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.14.1/com/diffplug/gradle/spotless/ScalaExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/ScalaExtension.java) ```gradle spotless { @@ -418,7 +418,7 @@ spotless { ## C/C++ -`com.diffplug.gradle.spotless.CppExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.14.0/com/diffplug/gradle/spotless/CppExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/CppExtension.java) +`com.diffplug.gradle.spotless.CppExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.14.1/com/diffplug/gradle/spotless/CppExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/CppExtension.java) ```gradle spotless { @@ -450,7 +450,7 @@ spotles { ## Python -`com.diffplug.gradle.spotless.PythonExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.14.0/com/diffplug/gradle/spotless/PythonExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/PythonExtension.java) +`com.diffplug.gradle.spotless.PythonExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.14.1/com/diffplug/gradle/spotless/PythonExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/PythonExtension.java) ```gradle spotless { @@ -484,7 +484,7 @@ black().pathToExe('C:/myuser/.pyenv/versions/3.8.0/scripts/black.exe') ## FreshMark -`com.diffplug.gradle.spotless.FreshMarkExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.14.0/com/diffplug/gradle/spotless/FreshMarkExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/FreshMarkExtension.java) +`com.diffplug.gradle.spotless.FreshMarkExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.14.1/com/diffplug/gradle/spotless/FreshMarkExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/FreshMarkExtension.java) [homepage](https://github.com/diffplug/freshmark). [changelog](https://github.com/diffplug/freshmark/blob/master/CHANGES.md). FreshMark lets you generate markdown in the comments of your markdown. This helps to keep badges and links up-to-date (see the source for this file), and can also be helpful for generating complex tables (see the source for [the parent readme](../README.md)). @@ -505,7 +505,7 @@ spotless { ## Antlr4 -`com.diffplug.gradle.spotless.Antlr4Extension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.14.0/com/diffplug/gradle/spotless/Antlr4Extension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/Antlr4Extension.java) +`com.diffplug.gradle.spotless.Antlr4Extension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.14.1/com/diffplug/gradle/spotless/Antlr4Extension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/Antlr4Extension.java) ```gradle spotless { @@ -530,7 +530,7 @@ antlr4formatter('1.2.1') // version is optional ## SQL -`com.diffplug.gradle.spotless.SqlExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.14.0/com/diffplug/gradle/spotless/SqlExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/SqlExtension.java) +`com.diffplug.gradle.spotless.SqlExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.14.1/com/diffplug/gradle/spotless/SqlExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/SqlExtension.java) ```gradle spotless { @@ -570,7 +570,7 @@ sql.formatter.indent.size=4 ## Typescript -- `com.diffplug.gradle.spotless.TypescriptExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.14.0/com/diffplug/gradle/spotless/TypescriptExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/TypescriptExtension.java) +- `com.diffplug.gradle.spotless.TypescriptExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.14.1/com/diffplug/gradle/spotless/TypescriptExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/TypescriptExtension.java) ```gradle spotless { @@ -662,7 +662,7 @@ For details, see the [npm detection](#npm-detection) and [`.npmrc` detection](#n ## Javascript -- `com.diffplug.gradle.spotless.JavascriptExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.14.0/com/diffplug/gradle/spotless/JavascriptExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/JavascriptExtension.java) +- `com.diffplug.gradle.spotless.JavascriptExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.14.1/com/diffplug/gradle/spotless/JavascriptExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/JavascriptExtension.java) ```gradle spotless { @@ -726,7 +726,7 @@ For details, see the [npm detection](#npm-detection) and [`.npmrc` detection](#n ## JSON -- `com.diffplug.gradle.spotless.JsonExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.14.0/com/diffplug/gradle/spotless/JsonExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/JsonExtension.java) +- `com.diffplug.gradle.spotless.JsonExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.14.1/com/diffplug/gradle/spotless/JsonExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/JsonExtension.java) ```gradle spotless { @@ -801,7 +801,7 @@ spotless { ## YAML -- `com.diffplug.gradle.spotless.YamlExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.14.0/com/diffplug/gradle/spotless/JsonExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/YamlExtension.java) +- `com.diffplug.gradle.spotless.YamlExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.14.1/com/diffplug/gradle/spotless/JsonExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/YamlExtension.java) ```gradle spotless { @@ -1014,7 +1014,7 @@ Once a file's license header has a valid year, whether it is a year (`2020`) or * `2017` -> `2017-2020` * `2017-2019` -> `2017-2020` -See the [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.14.0/com/diffplug/gradle/spotless/FormatExtension.LicenseHeaderConfig.html) for a complete listing of options. +See the [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.14.1/com/diffplug/gradle/spotless/FormatExtension.LicenseHeaderConfig.html) for a complete listing of options. @@ -1087,9 +1087,9 @@ spotless { custom 'lowercase', { str -> str.toLowerCase() } ``` -However, custom rules will disable up-to-date checking and caching, unless you read [this javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.14.0/com/diffplug/gradle/spotless/FormatExtension.html#bumpThisNumberIfACustomStepChanges-int-) and follow its instructions carefully. +However, custom rules will disable up-to-date checking and caching, unless you read [this javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.14.1/com/diffplug/gradle/spotless/FormatExtension.html#bumpThisNumberIfACustomStepChanges-int-) and follow its instructions carefully. -Another option is to create proper `FormatterStep` in your `buildSrc`, and then call [`addStep`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.14.0/com/diffplug/gradle/spotless/FormatExtension.html#addStep-com.diffplug.spotless.FormatterStep-). The contributing guide describes [how to do this](https://github.com/diffplug/spotless/blob/main/CONTRIBUTING.md#how-to-add-a-new-formatterstep). If the step is generally-useful, we hope you'll open a PR to share it! +Another option is to create proper `FormatterStep` in your `buildSrc`, and then call [`addStep`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.14.1/com/diffplug/gradle/spotless/FormatExtension.html#addStep-com.diffplug.spotless.FormatterStep-). The contributing guide describes [how to do this](https://github.com/diffplug/spotless/blob/main/CONTRIBUTING.md#how-to-add-a-new-formatterstep). If the step is generally-useful, we hope you'll open a PR to share it! ```gradle @@ -1122,11 +1122,11 @@ spotless { format 'foo', com.acme.FooLanguageExtension, { ``` -If you'd like to create a one-off Spotless task outside of the `check`/`apply` framework, see [`FormatExtension.createIndependentApplyTask`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.14.0/com/diffplug/gradle/spotless/FormatExtension.html#createIndependentApplyTask-java.lang.String-). +If you'd like to create a one-off Spotless task outside of the `check`/`apply` framework, see [`FormatExtension.createIndependentApplyTask`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.14.1/com/diffplug/gradle/spotless/FormatExtension.html#createIndependentApplyTask-java.lang.String-). ## Inception (languages within languages within...) -In very rare cases, you might want to format e.g. javascript which is written inside JSP templates, or maybe java within a markdown file, or something wacky like that. You can specify hunks within a file using either open/close tags or a regex with a single capturing group, and then specify rules within it, like so. See [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.14.0/com/diffplug/gradle/spotless/FormatExtension.html#withinBlocks-java.lang.String-java.lang.String-java.lang.String-org.gradle.api.Action-) for more details. +In very rare cases, you might want to format e.g. javascript which is written inside JSP templates, or maybe java within a markdown file, or something wacky like that. You can specify hunks within a file using either open/close tags or a regex with a single capturing group, and then specify rules within it, like so. See [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.14.1/com/diffplug/gradle/spotless/FormatExtension.html#withinBlocks-java.lang.String-java.lang.String-java.lang.String-org.gradle.api.Action-) for more details. ```gradle import com.diffplug.gradle.spotless.JavaExtension From 8d99d7dc44b75fbfbcd25a2550332a11f40219cc Mon Sep 17 00:00:00 2001 From: runner Date: Sun, 5 Feb 2023 16:50:20 +0000 Subject: [PATCH 724/757] Published maven/2.32.0 --- plugin-maven/CHANGES.md | 2 ++ plugin-maven/README.md | 4 ++-- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/plugin-maven/CHANGES.md b/plugin-maven/CHANGES.md index d498b868c7..567d880f4f 100644 --- a/plugin-maven/CHANGES.md +++ b/plugin-maven/CHANGES.md @@ -3,6 +3,8 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format (starting after version `1.27.0`). ## [Unreleased] + +## [2.32.0] - 2023-02-05 ### Added * A synthesis log with the number of considered files is added after each formatter execution ([#1507](https://github.com/diffplug/spotless/pull/1507)) ### Fixed diff --git a/plugin-maven/README.md b/plugin-maven/README.md index 73402cd929..0787150ee1 100644 --- a/plugin-maven/README.md +++ b/plugin-maven/README.md @@ -8,8 +8,8 @@ output = [ ].join('\n'); --> [![Maven central](https://img.shields.io/badge/mavencentral-com.diffplug.spotless%3Aspotless--maven--plugin-blue.svg)](https://search.maven.org/#search%7Cgav%7C1%7Cg%3A%22com.diffplug.spotless%22%20AND%20a%3A%22spotless-maven-plugin%22) -[![Changelog](https://img.shields.io/badge/changelog-2.31.0-blue.svg)](CHANGES.md) -[![Javadoc](https://img.shields.io/badge/javadoc-here-blue.svg)](https://javadoc.io/doc/com.diffplug.spotless/spotless-maven-plugin/2.31.0/index.html) +[![Changelog](https://img.shields.io/badge/changelog-2.32.0-blue.svg)](CHANGES.md) +[![Javadoc](https://img.shields.io/badge/javadoc-here-blue.svg)](https://javadoc.io/doc/com.diffplug.spotless/spotless-maven-plugin/2.32.0/index.html) + @@ -274,6 +276,25 @@ list of well-known type annotations. You can make a pull request to add new one In the future there will be mechanisms to add/remove annotations from the list. These mechanisms already exist for the Gradle plugin. +### Cleanthat + +[homepage](https://github.com/solven-eu/cleanthat). CleanThat enables automatic refactoring of Java code + +```xml + + 2.0 + ${maven.compiler.source} + + * + + + LiteralsFirstInComparisons + + + OptionalNotEmpty + + +``` ## Groovy diff --git a/plugin-maven/src/main/java/com/diffplug/spotless/maven/java/CleanthatJava.java b/plugin-maven/src/main/java/com/diffplug/spotless/maven/java/CleanthatJava.java index 76c130bcdd..7460ab67b9 100644 --- a/plugin-maven/src/main/java/com/diffplug/spotless/maven/java/CleanthatJava.java +++ b/plugin-maven/src/main/java/com/diffplug/spotless/maven/java/CleanthatJava.java @@ -20,7 +20,7 @@ import org.apache.maven.plugins.annotations.Parameter; import com.diffplug.spotless.FormatterStep; -import com.diffplug.spotless.java.CleanthatStepFactory; +import com.diffplug.spotless.java.CleanthatJavaStep; import com.diffplug.spotless.maven.FormatterStepConfig; import com.diffplug.spotless.maven.FormatterStepFactory; @@ -33,19 +33,19 @@ public class CleanthatJava implements FormatterStepFactory { // https://maven.apache.org/plugins/maven-compiler-plugin/compile-mojo.html#source @Parameter(property = "maven.compiler.source") - private String sourceJdk = CleanthatStepFactory.defaultJdkVersion(); + private String sourceJdk = CleanthatJavaStep.defaultJdkVersion(); @Parameter - private List mutators = CleanthatStepFactory.defaultMutators(); + private List mutators = CleanthatJavaStep.defaultMutators(); @Parameter - private List excludedMutators = CleanthatStepFactory.defaultExcludedMutators(); + private List excludedMutators = CleanthatJavaStep.defaultExcludedMutators(); @Override public FormatterStep newFormatterStep(FormatterStepConfig config) { - String groupArtifact = this.groupArtifact != null ? this.groupArtifact : CleanthatStepFactory.defaultGroupArtifact(); - String version = this.version != null ? this.version : CleanthatStepFactory.defaultVersion(); + String groupArtifact = this.groupArtifact != null ? this.groupArtifact : CleanthatJavaStep.defaultGroupArtifact(); + String version = this.version != null ? this.version : CleanthatJavaStep.defaultVersion(); - return CleanthatStepFactory.create(groupArtifact, version, sourceJdk, mutators, excludedMutators, config.getProvisioner()); + return CleanthatJavaStep.create(groupArtifact, version, sourceJdk, mutators, excludedMutators, config.getProvisioner()); } } diff --git a/plugin-maven/src/main/java/com/diffplug/spotless/maven/java/Java.java b/plugin-maven/src/main/java/com/diffplug/spotless/maven/java/Java.java index 0921a838b3..efdf0827db 100644 --- a/plugin-maven/src/main/java/com/diffplug/spotless/maven/java/Java.java +++ b/plugin-maven/src/main/java/com/diffplug/spotless/maven/java/Java.java @@ -79,6 +79,10 @@ public void addFormatAnnotations(FormatAnnotations formatAnnotations) { addStepFactory(formatAnnotations); } + public void addCleanthat(CleanthatJava cleanthat) { + addStepFactory(cleanthat); + } + private static String fileMask(Path path) { String dir = path.toString(); if (!dir.endsWith(File.separator)) { diff --git a/plugin-maven/src/test/java/com/diffplug/spotless/maven/java/CleanthatJavaRefactorerTest.java b/plugin-maven/src/test/java/com/diffplug/spotless/maven/java/CleanthatJavaRefactorerTest.java new file mode 100644 index 0000000000..c72aeb15b2 --- /dev/null +++ b/plugin-maven/src/test/java/com/diffplug/spotless/maven/java/CleanthatJavaRefactorerTest.java @@ -0,0 +1,76 @@ +/* + * Copyright 2022-2023 DiffPlug + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.diffplug.spotless.maven.java; + +import org.assertj.core.api.Assertions; +import org.junit.jupiter.api.Test; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import com.diffplug.spotless.maven.MavenIntegrationHarness; + +class CleanthatJavaRefactorerTest extends MavenIntegrationHarness { + private static final Logger LOGGER = LoggerFactory.getLogger(CleanthatJavaRefactorerTest.class); + + @Test + void testLiteralsFirstInComparisons() throws Exception { + writePomWithJavaSteps( + "", + ""); + + runTest("LiteralsFirstInComparisons.dirty.java", "LiteralsFirstInComparisons.clean.java"); + } + + @Test + void testMultipleMutators() throws Exception { + writePomWithJavaSteps( + "", + ""); + + runTest("MultipleMutators.dirty.java", "MultipleMutators.clean.java"); + } + + @Test + void testExcludeOptionalNotEmpty() throws Exception { + writePomWithJavaSteps( + "", + " ", + " OptionalNotEmpty", + " ", + ""); + + runTest("MultipleMutators.dirty.java", "MultipleMutators.clean.onlyLiteralsFirst.java"); + } + + @Test + void testIncludeOnlyLiteralsFirstInComparisons() throws Exception { + writePomWithJavaSteps( + "", + " ", + " LiteralsFirstInComparisons", + " ", + ""); + + runTest("MultipleMutators.dirty.java", "MultipleMutators.clean.onlyLiteralsFirst.java"); + } + + private void runTest(String dirtyPath, String cleanPath) throws Exception { + String path = "src/main/java/test.java"; + setFile(path).toResource("java/cleanthat/" + dirtyPath); + Assertions.assertThat(mavenRunner().withArguments("spotless:apply -X").runNoError().stdOutUtf8()).isEmpty(); + assertFile(path).sameAsResource("java/cleanthat/" + cleanPath); + } +} diff --git a/testlib/src/main/resources/java/cleanthat/LiteralsFirstInComparisons.clean.java b/testlib/src/main/resources/java/cleanthat/LiteralsFirstInComparisons.clean.java new file mode 100644 index 0000000000..8bacfa58db --- /dev/null +++ b/testlib/src/main/resources/java/cleanthat/LiteralsFirstInComparisons.clean.java @@ -0,0 +1,8 @@ +package eu.solven.cleanthat.engine.java.refactorer.cases.do_not_format_me; + +public class LiteralsFirstInComparisonsCases { + + public boolean isHardcoded(String input) { + return "hardcoded".equals(input); + } +} diff --git a/testlib/src/main/resources/java/cleanthat/LiteralsFirstInComparisons.dirty.java b/testlib/src/main/resources/java/cleanthat/LiteralsFirstInComparisons.dirty.java new file mode 100644 index 0000000000..3a1e074c91 --- /dev/null +++ b/testlib/src/main/resources/java/cleanthat/LiteralsFirstInComparisons.dirty.java @@ -0,0 +1,8 @@ +package eu.solven.cleanthat.engine.java.refactorer.cases.do_not_format_me; + +public class LiteralsFirstInComparisonsCases { + + public boolean isHardcoded(String input) { + return input.equals("hardcoded"); + } +} diff --git a/testlib/src/main/resources/java/cleanthat/MultipleMutators.clean.java b/testlib/src/main/resources/java/cleanthat/MultipleMutators.clean.java new file mode 100644 index 0000000000..0829602dc1 --- /dev/null +++ b/testlib/src/main/resources/java/cleanthat/MultipleMutators.clean.java @@ -0,0 +1,14 @@ +package eu.solven.cleanthat.engine.java.refactorer.cases.do_not_format_me; + +import java.util.Optional; + +public class LiteralsFirstInComparisonsCases { + + public boolean isHardcoded(String input) { + return input.equals("hardcoded"); + } + + public boolean isPresent(Optional optional) { + return optional.isPresent(); + } +} diff --git a/testlib/src/main/resources/java/cleanthat/MultipleMutators.clean.onlyLiteralsFirst.java b/testlib/src/main/resources/java/cleanthat/MultipleMutators.clean.onlyLiteralsFirst.java new file mode 100644 index 0000000000..629d24504b --- /dev/null +++ b/testlib/src/main/resources/java/cleanthat/MultipleMutators.clean.onlyLiteralsFirst.java @@ -0,0 +1,14 @@ +package eu.solven.cleanthat.engine.java.refactorer.cases.do_not_format_me; + +import java.util.Optional; + +public class LiteralsFirstInComparisonsCases { + + public boolean isHardcoded(String input) { + return "hardcoded".equals(input); + } + + public boolean isPresent(Optional optional) { + return !optional.isEmpty(); + } +} diff --git a/testlib/src/main/resources/java/cleanthat/MultipleMutators.dirty.java b/testlib/src/main/resources/java/cleanthat/MultipleMutators.dirty.java new file mode 100644 index 0000000000..8ac230cabc --- /dev/null +++ b/testlib/src/main/resources/java/cleanthat/MultipleMutators.dirty.java @@ -0,0 +1,14 @@ +package eu.solven.cleanthat.engine.java.refactorer.cases.do_not_format_me; + +import java.util.Optional; + +public class LiteralsFirstInComparisonsCases { + + public boolean isHardcoded(String input) { + return input.equals("hardcoded"); + } + + public boolean isPresent(Optional optional) { + return !optional.isEmpty(); + } +} From f80b45f149e3de392a025b3ac8842b6231299fac Mon Sep 17 00:00:00 2001 From: "renovate[bot]" <29139614+renovate[bot]@users.noreply.github.com> Date: Tue, 7 Feb 2023 18:04:35 +0000 Subject: [PATCH 733/757] Update dependency com.facebook:ktfmt to v0.43 --- lib/build.gradle | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/build.gradle b/lib/build.gradle index 9d95007bc1..1fa0e41409 100644 --- a/lib/build.gradle +++ b/lib/build.gradle @@ -65,7 +65,7 @@ dependencies { jacksonCompileOnly 'com.fasterxml.jackson.core:jackson-databind:2.14.1' jacksonCompileOnly 'com.fasterxml.jackson.dataformat:jackson-dataformat-yaml:2.14.1' - String VER_KTFMT = '0.42' + String VER_KTFMT = '0.43' 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") { From 4f62769da7ba656ee47e9596d7f5b0f9c531c650 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lars=20L=C3=B8nne?= Date: Wed, 8 Feb 2023 14:06:17 +0100 Subject: [PATCH 734/757] fixes continuation indent in ktfmt default formatter --- .../spotless/glue/ktfmt/KtfmtFormatterFunc.java | 2 +- .../com/diffplug/spotless/maven/kotlin/KtfmtTest.java | 11 +++++++++++ .../main/resources/kotlin/ktfmt/continuation.clean | 6 ++++++ .../main/resources/kotlin/ktfmt/continuation.dirty | 4 ++++ 4 files changed, 22 insertions(+), 1 deletion(-) create mode 100644 testlib/src/main/resources/kotlin/ktfmt/continuation.clean create mode 100644 testlib/src/main/resources/kotlin/ktfmt/continuation.dirty diff --git a/lib/src/ktfmt/java/com/diffplug/spotless/glue/ktfmt/KtfmtFormatterFunc.java b/lib/src/ktfmt/java/com/diffplug/spotless/glue/ktfmt/KtfmtFormatterFunc.java index 72e0e50e3c..e34f7b4755 100644 --- a/lib/src/ktfmt/java/com/diffplug/spotless/glue/ktfmt/KtfmtFormatterFunc.java +++ b/lib/src/ktfmt/java/com/diffplug/spotless/glue/ktfmt/KtfmtFormatterFunc.java @@ -78,7 +78,7 @@ private FormattingOptions createFormattingOptions() { formattingOptions.getStyle(), ktfmtFormattingOptions.getMaxWidth().orElse(formattingOptions.getMaxWidth()), ktfmtFormattingOptions.getBlockIndent().orElse(formattingOptions.getBlockIndent()), - ktfmtFormattingOptions.getContinuationIndent().orElse(formattingOptions.getBlockIndent()), + ktfmtFormattingOptions.getContinuationIndent().orElse(formattingOptions.getContinuationIndent()), ktfmtFormattingOptions.getRemoveUnusedImport().orElse(formattingOptions.getRemoveUnusedImports()), formattingOptions.getDebuggingPrintOpsAfterFormatting()); } diff --git a/plugin-maven/src/test/java/com/diffplug/spotless/maven/kotlin/KtfmtTest.java b/plugin-maven/src/test/java/com/diffplug/spotless/maven/kotlin/KtfmtTest.java index 4ae266cc23..25ecbc598d 100644 --- a/plugin-maven/src/test/java/com/diffplug/spotless/maven/kotlin/KtfmtTest.java +++ b/plugin-maven/src/test/java/com/diffplug/spotless/maven/kotlin/KtfmtTest.java @@ -19,6 +19,8 @@ import com.diffplug.spotless.maven.MavenIntegrationHarness; +import java.io.IOException; + class KtfmtTest extends MavenIntegrationHarness { @Test void testKtfmt() throws Exception { @@ -36,6 +38,15 @@ void testKtfmt() throws Exception { assertFile(path2).sameAsResource("kotlin/ktfmt/basic.clean"); } + @Test + void testContinuation() throws Exception { + writePomWithKotlinSteps(""); + + setFile("src/main/kotlin/main.kt").toResource("kotlin/ktfmt/continuation.dirty"); + mavenRunner().withArguments("spotless:apply").runNoError(); + assertFile("src/main/kotlin/main.kt").sameAsResource("kotlin/ktfmt/continuation.clean"); + } + @Test void testKtfmtStyle() throws Exception { writePomWithKotlinSteps(""); diff --git a/testlib/src/main/resources/kotlin/ktfmt/continuation.clean b/testlib/src/main/resources/kotlin/ktfmt/continuation.clean new file mode 100644 index 0000000000..11677928fc --- /dev/null +++ b/testlib/src/main/resources/kotlin/ktfmt/continuation.clean @@ -0,0 +1,6 @@ +fun myFunction() { + val location = + restTemplate.postForLocation( + "/v1/my-api", mapOf("name" to "some-name", "url" to "https://www.google.com")) + return location +} diff --git a/testlib/src/main/resources/kotlin/ktfmt/continuation.dirty b/testlib/src/main/resources/kotlin/ktfmt/continuation.dirty new file mode 100644 index 0000000000..3652274d12 --- /dev/null +++ b/testlib/src/main/resources/kotlin/ktfmt/continuation.dirty @@ -0,0 +1,4 @@ +fun myFunction() { + val location = restTemplate.postForLocation("/v1/my-api", mapOf("name" to "some-name", "url" to "https://www.google.com")) + return location +} From 8c74020fd505ecbc46db645b7fa330cbf5fd9514 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lars=20L=C3=B8nne?= Date: Wed, 8 Feb 2023 14:16:52 +0100 Subject: [PATCH 735/757] adds a summary of the change to plugin-maven/CHANGES.md --- plugin-maven/CHANGES.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/plugin-maven/CHANGES.md b/plugin-maven/CHANGES.md index 567d880f4f..0e656e24ec 100644 --- a/plugin-maven/CHANGES.md +++ b/plugin-maven/CHANGES.md @@ -3,6 +3,8 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format (starting after version `1.27.0`). ## [Unreleased] +### Fixed +* Maven plugin with `ktfmt` default style uses correct continuation indent ([#1562](https://github.com/diffplug/spotless/pull/1562)) ## [2.32.0] - 2023-02-05 ### Added From 69e8524c650a53eaae67df350a56bb389b0a8903 Mon Sep 17 00:00:00 2001 From: Benoit Lacelle Date: Wed, 8 Feb 2023 22:28:15 +0400 Subject: [PATCH 736/757] Move to 2.1 to fix issue with class detection --- lib/build.gradle | 5 +- .../spotless/java/CleanthatJavaStep.java | 2 +- .../java/JavaCleanthatRefactorerFuncTest.java | 28 ++++++++ .../java/JavaCleanthatRefactorerFuncTest.java | 72 +++++++++++++++++++ .../java/CleanthatJavaRefactorerTest.java | 2 +- 5 files changed, 106 insertions(+), 3 deletions(-) create mode 100644 lib/src/test/java/com/diffplug/spotless/glue/java/JavaCleanthatRefactorerFuncTest.java create mode 100644 lib/src/testCleanthat/java/com/diffplug/spotless/glue/java/JavaCleanthatRefactorerFuncTest.java diff --git a/lib/build.gradle b/lib/build.gradle index 0e1c2086ea..cd6996a979 100644 --- a/lib/build.gradle +++ b/lib/build.gradle @@ -55,6 +55,7 @@ dependencies { testCommonImplementation "org.junit.jupiter:junit-jupiter:$VER_JUNIT" testCommonImplementation "org.assertj:assertj-core:$VER_ASSERTJ" testCommonImplementation "com.diffplug.durian:durian-testlib:$VER_DURIAN" + testCommonImplementation 'io.github.solven-eu.cleanthat:java:2.1' // used for pom sorting sortPomCompileOnly 'com.github.ekryd.sortpom:sortpom-sorter:3.0.0' @@ -102,7 +103,9 @@ dependencies { gsonCompileOnly 'com.google.code.gson:gson:2.10.1' - cleanthatCompileOnly 'io.github.solven-eu.cleanthat:java:2.0' + // TODO How can one add a test module like 'compatKtLint0Dot48Dot0'? + // cleanthatCompileAndTestOnly 'io.github.solven-eu.cleanthat:java:2.1' + cleanthatCompileOnly 'io.github.solven-eu.cleanthat:java:2.1' } // we'll hold the core lib to a high standard diff --git a/lib/src/main/java/com/diffplug/spotless/java/CleanthatJavaStep.java b/lib/src/main/java/com/diffplug/spotless/java/CleanthatJavaStep.java index 79434cba56..fe4966d873 100644 --- a/lib/src/main/java/com/diffplug/spotless/java/CleanthatJavaStep.java +++ b/lib/src/main/java/com/diffplug/spotless/java/CleanthatJavaStep.java @@ -39,7 +39,7 @@ public final class CleanthatJavaStep { private static final String NAME = "cleanthat"; private static final String MAVEN_COORDINATE = "io.github.solven-eu.cleanthat:java"; - private static final Jvm.Support JVM_SUPPORT = Jvm. support(NAME).add(11, "2.0"); + private static final Jvm.Support JVM_SUPPORT = Jvm. support(NAME).add(11, "2.1"); // prevent direct instantiation private CleanthatJavaStep() {} diff --git a/lib/src/test/java/com/diffplug/spotless/glue/java/JavaCleanthatRefactorerFuncTest.java b/lib/src/test/java/com/diffplug/spotless/glue/java/JavaCleanthatRefactorerFuncTest.java new file mode 100644 index 0000000000..2f3cdc9646 --- /dev/null +++ b/lib/src/test/java/com/diffplug/spotless/glue/java/JavaCleanthatRefactorerFuncTest.java @@ -0,0 +1,28 @@ +/* + * Copyright 2023 DiffPlug + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.diffplug.spotless.glue.java; + +import org.assertj.core.api.Assertions; +import org.junit.jupiter.api.Test; + +import eu.solven.cleanthat.engine.java.refactorer.JavaRefactorer; + +public class JavaCleanthatRefactorerFuncTest { + @Test + public void testMutatorsDetection() { + Assertions.assertThat(JavaRefactorer.getAllIncluded()).isNotEmpty(); + } +} diff --git a/lib/src/testCleanthat/java/com/diffplug/spotless/glue/java/JavaCleanthatRefactorerFuncTest.java b/lib/src/testCleanthat/java/com/diffplug/spotless/glue/java/JavaCleanthatRefactorerFuncTest.java new file mode 100644 index 0000000000..c811b51233 --- /dev/null +++ b/lib/src/testCleanthat/java/com/diffplug/spotless/glue/java/JavaCleanthatRefactorerFuncTest.java @@ -0,0 +1,72 @@ +/* + * Copyright 2023 DiffPlug + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.diffplug.spotless.glue.ktlint.compat; + +import static org.junit.jupiter.api.Assertions.assertEquals; + +import java.io.IOException; +import java.io.InputStream; +import java.nio.charset.StandardCharsets; +import java.nio.file.Files; +import java.nio.file.Path; +import java.nio.file.Paths; +import java.util.HashMap; +import java.util.Map; + +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.io.TempDir; + +public class KtLintCompat0Dot48Dot0AdapterTest { + @Test + public void testDefaults(@TempDir Path path) throws IOException { + KtLintCompat0Dot48Dot0Adapter ktLintCompat0Dot48Dot0Adapter = new KtLintCompat0Dot48Dot0Adapter(); + String text = loadAndWriteText(path, "empty_class_body.kt"); + final Path filePath = Paths.get(path.toString(), "empty_class_body.kt"); + + Map userData = new HashMap<>(); + + Map editorConfigOverrideMap = new HashMap<>(); + + String formatted = ktLintCompat0Dot48Dot0Adapter.format(text, filePath, false, false, null, userData, editorConfigOverrideMap); + assertEquals("class empty_class_body\n", formatted); + } + + @Test + public void testEditorConfigCanDisable(@TempDir Path path) throws IOException { + KtLintCompat0Dot48Dot0Adapter ktLintCompat0Dot48Dot0Adapter = new KtLintCompat0Dot48Dot0Adapter(); + String text = loadAndWriteText(path, "fails_no_semicolons.kt"); + final Path filePath = Paths.get(path.toString(), "fails_no_semicolons.kt"); + + Map userData = new HashMap<>(); + + Map editorConfigOverrideMap = new HashMap<>(); + editorConfigOverrideMap.put("indent_style", "tab"); + editorConfigOverrideMap.put("ktlint_standard_no-semi", "disabled"); + // ktlint_filename is an invalid rule in ktlint 0.48.0 + editorConfigOverrideMap.put("ktlint_filename", "disabled"); + + String formatted = ktLintCompat0Dot48Dot0Adapter.format(text, filePath, false, false, null, userData, editorConfigOverrideMap); + assertEquals("class fails_no_semicolons {\n\tval i = 0;\n}\n", formatted); + } + + private static String loadAndWriteText(Path path, String name) throws IOException { + try (InputStream is = KtLintCompat0Dot48Dot0AdapterTest.class.getResourceAsStream("/" + name)) { + Files.copy(is, path.resolve(name)); + } + return new String(Files.readAllBytes(path.resolve(name)), StandardCharsets.UTF_8); + } + +} diff --git a/plugin-maven/src/test/java/com/diffplug/spotless/maven/java/CleanthatJavaRefactorerTest.java b/plugin-maven/src/test/java/com/diffplug/spotless/maven/java/CleanthatJavaRefactorerTest.java index c72aeb15b2..833b19dda8 100644 --- a/plugin-maven/src/test/java/com/diffplug/spotless/maven/java/CleanthatJavaRefactorerTest.java +++ b/plugin-maven/src/test/java/com/diffplug/spotless/maven/java/CleanthatJavaRefactorerTest.java @@ -70,7 +70,7 @@ void testIncludeOnlyLiteralsFirstInComparisons() throws Exception { private void runTest(String dirtyPath, String cleanPath) throws Exception { String path = "src/main/java/test.java"; setFile(path).toResource("java/cleanthat/" + dirtyPath); - Assertions.assertThat(mavenRunner().withArguments("spotless:apply -X").runNoError().stdOutUtf8()).isEmpty(); + Assertions.assertThat(mavenRunner().withArguments("spotless:apply").withRemoteDebug(21654).runNoError().stdOutUtf8()).doesNotContain("[ERROR]"); assertFile(path).sameAsResource("java/cleanthat/" + cleanPath); } } From bcab5b4abb044d6ba9b730b56b99c74cd4408453 Mon Sep 17 00:00:00 2001 From: Benoit Lacelle Date: Wed, 8 Feb 2023 22:32:23 +0400 Subject: [PATCH 737/757] Improve documentation and changelog ref --- .../spotless/glue/java/JavaCleanthatRefactorerFunc.java | 4 ++++ .../java/com/diffplug/spotless/java/CleanthatJavaStep.java | 1 + plugin-maven/README.md | 2 +- 3 files changed, 6 insertions(+), 1 deletion(-) diff --git a/lib/src/cleanthat/java/com/diffplug/spotless/glue/java/JavaCleanthatRefactorerFunc.java b/lib/src/cleanthat/java/com/diffplug/spotless/glue/java/JavaCleanthatRefactorerFunc.java index 5ec54e69be..7432ebf3f9 100644 --- a/lib/src/cleanthat/java/com/diffplug/spotless/glue/java/JavaCleanthatRefactorerFunc.java +++ b/lib/src/cleanthat/java/com/diffplug/spotless/glue/java/JavaCleanthatRefactorerFunc.java @@ -30,6 +30,10 @@ import eu.solven.cleanthat.engine.java.refactorer.JavaRefactorerProperties; import eu.solven.cleanthat.formatter.LineEnding; +/** + * The glue for CleanThat: it is build over the version in build.gradle, but at runtime it will be executed over + * the version loaded in JarState, which is by default defined in com.diffplug.spotless.java.CleanthatJavaStep#JVM_SUPPORT + */ public class JavaCleanthatRefactorerFunc implements FormatterFunc { private static final Logger LOGGER = LoggerFactory.getLogger(JavaCleanthatRefactorerFunc.class); diff --git a/lib/src/main/java/com/diffplug/spotless/java/CleanthatJavaStep.java b/lib/src/main/java/com/diffplug/spotless/java/CleanthatJavaStep.java index fe4966d873..1cd032a304 100644 --- a/lib/src/main/java/com/diffplug/spotless/java/CleanthatJavaStep.java +++ b/lib/src/main/java/com/diffplug/spotless/java/CleanthatJavaStep.java @@ -39,6 +39,7 @@ public final class CleanthatJavaStep { private static final String NAME = "cleanthat"; private static final String MAVEN_COORDINATE = "io.github.solven-eu.cleanthat:java"; + // CleanThat changelog is available at https://github.com/solven-eu/cleanthat/blob/master/CHANGES.MD private static final Jvm.Support JVM_SUPPORT = Jvm. support(NAME).add(11, "2.1"); // prevent direct instantiation diff --git a/plugin-maven/README.md b/plugin-maven/README.md index 36d46b2386..b1b9098bfe 100644 --- a/plugin-maven/README.md +++ b/plugin-maven/README.md @@ -278,7 +278,7 @@ These mechanisms already exist for the Gradle plugin. ### Cleanthat -[homepage](https://github.com/solven-eu/cleanthat). CleanThat enables automatic refactoring of Java code +[homepage](https://github.com/solven-eu/cleanthat). CleanThat enables automatic refactoring of Java code. [ChangeLog](https://github.com/solven-eu/cleanthat/blob/master/CHANGES.MD) ```xml From a5c8b4da6975b69e5d62ea29246a422a269610e1 Mon Sep 17 00:00:00 2001 From: Benoit Lacelle Date: Wed, 8 Feb 2023 23:06:46 +0400 Subject: [PATCH 738/757] Fix classLoader issue --- .../java/JavaCleanthatRefactorerFunc.java | 19 +++++++++++++++++++ .../java/CleanthatJavaRefactorerTest.java | 15 +++++++++++++-- .../cleanthat/MultipleMutators.clean.java | 2 +- 3 files changed, 33 insertions(+), 3 deletions(-) diff --git a/lib/src/cleanthat/java/com/diffplug/spotless/glue/java/JavaCleanthatRefactorerFunc.java b/lib/src/cleanthat/java/com/diffplug/spotless/glue/java/JavaCleanthatRefactorerFunc.java index 7432ebf3f9..c94fd3c7c4 100644 --- a/lib/src/cleanthat/java/com/diffplug/spotless/glue/java/JavaCleanthatRefactorerFunc.java +++ b/lib/src/cleanthat/java/com/diffplug/spotless/glue/java/JavaCleanthatRefactorerFunc.java @@ -15,6 +15,7 @@ */ package com.diffplug.spotless.glue.java; +import java.io.IOException; import java.util.Arrays; import java.util.Collections; import java.util.List; @@ -25,6 +26,7 @@ import com.diffplug.spotless.FormatterFunc; import eu.solven.cleanthat.config.pojo.CleanthatEngineProperties; +import eu.solven.cleanthat.config.pojo.SourceCodeProperties; import eu.solven.cleanthat.engine.java.IJdkVersionConstants; import eu.solven.cleanthat.engine.java.refactorer.JavaRefactorer; import eu.solven.cleanthat.engine.java.refactorer.JavaRefactorerProperties; @@ -53,8 +55,25 @@ public JavaCleanthatRefactorerFunc() { @Override public String apply(String input) throws Exception { + // https://stackoverflow.com/questions/1771679/difference-between-threads-context-class-loader-and-normal-classloader + ClassLoader originalClassLoader = Thread.currentThread().getContextClassLoader(); + try { + // Ensure CleanThat main Thread has its custom classLoader while executing its refactoring + Thread.currentThread().setContextClassLoader(getClass().getClassLoader()); + return doApply(input); + } finally { + // Restore the originalClassLoader + Thread.currentThread().setContextClassLoader(originalClassLoader); + } + } + + private String doApply(String input) throws InterruptedException, IOException { + // call some API that uses reflection without taking ClassLoader param CleanthatEngineProperties engineProperties = CleanthatEngineProperties.builder().engineVersion(jdkVersion).build(); + // Spotless will push us LF content + engineProperties.setSourceCode(SourceCodeProperties.builder().lineEnding(LineEnding.LF).build()); + JavaRefactorerProperties refactorerProperties = new JavaRefactorerProperties(); refactorerProperties.setIncluded(included); diff --git a/plugin-maven/src/test/java/com/diffplug/spotless/maven/java/CleanthatJavaRefactorerTest.java b/plugin-maven/src/test/java/com/diffplug/spotless/maven/java/CleanthatJavaRefactorerTest.java index 833b19dda8..edb7a69cd5 100644 --- a/plugin-maven/src/test/java/com/diffplug/spotless/maven/java/CleanthatJavaRefactorerTest.java +++ b/plugin-maven/src/test/java/com/diffplug/spotless/maven/java/CleanthatJavaRefactorerTest.java @@ -35,11 +35,21 @@ void testLiteralsFirstInComparisons() throws Exception { } @Test - void testMultipleMutators() throws Exception { + void testMultipleMutators_defaultIsJdk7() throws Exception { writePomWithJavaSteps( "", ""); + runTest("MultipleMutators.dirty.java", "MultipleMutators.clean.onlyLiteralsFirst.java"); + } + + @Test + void testMultipleMutators_Jdk11IntroducedOptionalisPresent() throws Exception { + writePomWithJavaSteps( + "", + "11", + ""); + runTest("MultipleMutators.dirty.java", "MultipleMutators.clean.java"); } @@ -70,7 +80,8 @@ void testIncludeOnlyLiteralsFirstInComparisons() throws Exception { private void runTest(String dirtyPath, String cleanPath) throws Exception { String path = "src/main/java/test.java"; setFile(path).toResource("java/cleanthat/" + dirtyPath); - Assertions.assertThat(mavenRunner().withArguments("spotless:apply").withRemoteDebug(21654).runNoError().stdOutUtf8()).doesNotContain("[ERROR]"); + // .withRemoteDebug(21654) + Assertions.assertThat(mavenRunner().withArguments("spotless:apply").runNoError().stdOutUtf8()).doesNotContain("[ERROR]"); assertFile(path).sameAsResource("java/cleanthat/" + cleanPath); } } diff --git a/testlib/src/main/resources/java/cleanthat/MultipleMutators.clean.java b/testlib/src/main/resources/java/cleanthat/MultipleMutators.clean.java index 0829602dc1..318e1efa15 100644 --- a/testlib/src/main/resources/java/cleanthat/MultipleMutators.clean.java +++ b/testlib/src/main/resources/java/cleanthat/MultipleMutators.clean.java @@ -5,7 +5,7 @@ public class LiteralsFirstInComparisonsCases { public boolean isHardcoded(String input) { - return input.equals("hardcoded"); + return "hardcoded".equals(input); } public boolean isPresent(Optional optional) { From 14122d0f9254c570c4fb894560db91d6b681a528 Mon Sep 17 00:00:00 2001 From: Benoit Lacelle Date: Wed, 8 Feb 2023 23:35:47 +0400 Subject: [PATCH 739/757] Add Gradle compatibility --- .../gradle/spotless/JavaExtension.java | 74 ++++++++++++++++++- .../CleanthatJavaIntegrationTest.java | 42 +++++++++++ 2 files changed, 115 insertions(+), 1 deletion(-) create mode 100644 plugin-gradle/src/test/java/com/diffplug/gradle/spotless/CleanthatJavaIntegrationTest.java diff --git a/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/JavaExtension.java b/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/JavaExtension.java index 0f5926ec66..e65d0601e7 100644 --- a/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/JavaExtension.java +++ b/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/JavaExtension.java @@ -1,5 +1,5 @@ /* - * Copyright 2016-2022 DiffPlug + * Copyright 2016-2023 DiffPlug * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -34,6 +34,7 @@ import com.diffplug.spotless.extra.EclipseBasedStepBuilder; import com.diffplug.spotless.extra.java.EclipseJdtFormatterStep; import com.diffplug.spotless.generic.LicenseHeaderStep; +import com.diffplug.spotless.java.CleanthatJavaStep; import com.diffplug.spotless.java.FormatAnnotationsStep; import com.diffplug.spotless.java.GoogleJavaFormatStep; import com.diffplug.spotless.java.ImportOrderStep; @@ -270,6 +271,77 @@ private FormatterStep createStep() { } } + /** Apply CleanThat refactoring rules. */ + public CleanthatJavaConfig cleanthat() { + return new CleanthatJavaConfig(); + } + + public class CleanthatJavaConfig { + private String groupArtifact = CleanthatJavaStep.defaultGroupArtifact(); + + private String version = CleanthatJavaStep.defaultVersion(); + + private String sourceJdk = CleanthatJavaStep.defaultJdkVersion(); + + private List mutators = CleanthatJavaStep.defaultMutators(); + + private List excludedMutators = CleanthatJavaStep.defaultExcludedMutators(); + + CleanthatJavaConfig() { + addStep(createStep()); + } + + public CleanthatJavaConfig groupArtifact(String groupArtifact) { + Objects.requireNonNull(groupArtifact); + this.groupArtifact = groupArtifact; + replaceStep(createStep()); + return this; + } + + public CleanthatJavaConfig version(String version) { + Objects.requireNonNull(version); + this.version = version; + replaceStep(createStep()); + return this; + } + + public CleanthatJavaConfig sourceJdk(String sourceJdk) { + Objects.requireNonNull(sourceJdk); + this.sourceJdk = sourceJdk; + replaceStep(createStep()); + return this; + } + + // Especially useful to clear default mutators + public CleanthatJavaConfig clearMutators() { + this.mutators.clear(); + replaceStep(createStep()); + return this; + } + + // The fully qualified name of a class implementing eu.solven.cleanthat.engine.java.refactorer.meta.IMutator + // or '*' to include all default mutators + public CleanthatJavaConfig addMutator(String mutator) { + this.mutators.add(mutator); + replaceStep(createStep()); + return this; + } + + // useful to exclude a mutator amongst the default list of mutators + public CleanthatJavaConfig excludeMutator(String mutator) { + this.excludedMutators.add(mutator); + replaceStep(createStep()); + return this; + } + + private FormatterStep createStep() { + return CleanthatJavaStep.create( + groupArtifact, + version, + sourceJdk, mutators, excludedMutators, provisioner()); + } + } + /** If the user hasn't specified the files yet, we'll assume he/she means all of the java files. */ @Override protected void setupTask(SpotlessTask task) { diff --git a/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/CleanthatJavaIntegrationTest.java b/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/CleanthatJavaIntegrationTest.java new file mode 100644 index 0000000000..2b3ede1472 --- /dev/null +++ b/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/CleanthatJavaIntegrationTest.java @@ -0,0 +1,42 @@ +/* + * Copyright 2022-2023 DiffPlug + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.diffplug.gradle.spotless; + +import java.io.IOException; + +import org.junit.jupiter.api.Test; + +class CleanthatJavaIntegrationTest extends GradleIntegrationHarness { + @Test + void integration() throws IOException { + setFile("build.gradle").toLines( + "plugins {", + " id 'com.diffplug.spotless'", + "}", + "repositories { mavenCentral() }", + "", + "spotless {", + " java {", + " target file('test.java')", + " cleanthat().sourceJdk('11')", + " }", + "}"); + + setFile("test.java").toResource("java/cleanthat/MultipleMutators.dirty.java"); + gradleRunner().withArguments("spotlessApply").build(); + assertFile("test.java").sameAsResource("java/cleanthat/MultipleMutators.clean.java"); + } +} From cfd07b06952840df641eea1c59d6f495e86544e6 Mon Sep 17 00:00:00 2001 From: Benoit Lacelle Date: Wed, 8 Feb 2023 23:44:50 +0400 Subject: [PATCH 740/757] Improve Gradle integration --- .../spotless/java/CleanthatJavaStep.java | 6 ++--- plugin-gradle/CHANGES.md | 2 ++ plugin-gradle/README.md | 22 ++++++++++++++++++- .../gradle/spotless/JavaExtension.java | 8 +++---- plugin-maven/CHANGES.md | 2 +- .../spotless/maven/java/CleanthatJava.java | 2 +- 6 files changed, 32 insertions(+), 10 deletions(-) diff --git a/lib/src/main/java/com/diffplug/spotless/java/CleanthatJavaStep.java b/lib/src/main/java/com/diffplug/spotless/java/CleanthatJavaStep.java index 1cd032a304..b5cc5452d1 100644 --- a/lib/src/main/java/com/diffplug/spotless/java/CleanthatJavaStep.java +++ b/lib/src/main/java/com/diffplug/spotless/java/CleanthatJavaStep.java @@ -52,10 +52,10 @@ public static FormatterStep create(Provisioner provisioner) { /** Creates a step which apply default CleanThat mutators. */ public static FormatterStep create(String version, Provisioner provisioner) { - return create(MAVEN_COORDINATE, version, defaultJdkVersion(), defaultExcludedMutators(), defaultMutators(), provisioner); + return create(MAVEN_COORDINATE, version, defaultSourceJdk(), defaultExcludedMutators(), defaultMutators(), provisioner); } - public static String defaultJdkVersion() { + public static String defaultSourceJdk() { // see IJdkVersionConstants.JDK_7 // https://maven.apache.org/plugins/maven-compiler-plugin/compile-mojo.html#source // 1.7 is the default for 'maven-compiler-plugin' since 3.9.0 @@ -114,7 +114,7 @@ static final class JavaRefactorerState implements Serializable { final List excluded; JavaRefactorerState(String stepName, String version, Provisioner provisioner) throws IOException { - this(stepName, MAVEN_COORDINATE, version, defaultJdkVersion(), defaultExcludedMutators(), defaultMutators(), provisioner); + this(stepName, MAVEN_COORDINATE, version, defaultSourceJdk(), defaultExcludedMutators(), defaultMutators(), provisioner); } JavaRefactorerState(String stepName, diff --git a/plugin-gradle/CHANGES.md b/plugin-gradle/CHANGES.md index e3234584b8..1a5458c436 100644 --- a/plugin-gradle/CHANGES.md +++ b/plugin-gradle/CHANGES.md @@ -3,6 +3,8 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format (starting after version `3.27.0`). ## [Unreleased] +### Added +* CleanThat Java Refactorer ([#1560](https://github.com/diffplug/spotless/pull/1560)) ## [6.14.1] - 2023-02-05 ### Fixed diff --git a/plugin-gradle/README.md b/plugin-gradle/README.md index f61280bc7e..c0f8adebfb 100644 --- a/plugin-gradle/README.md +++ b/plugin-gradle/README.md @@ -54,7 +54,7 @@ Spotless supports all of Gradle's built-in performance features (incremental bui - [**Quickstart**](#quickstart) - [Requirements](#requirements) - **Languages** - - [Java](#java) ([google-java-format](#google-java-format), [eclipse jdt](#eclipse-jdt), [clang-format](#clang-format), [prettier](#prettier), [palantir-java-format](#palantir-java-format), [formatAnnotations](#formatAnnotations)) + - [Java](#java) ([google-java-format](#google-java-format), [eclipse jdt](#eclipse-jdt), [clang-format](#clang-format), [prettier](#prettier), [palantir-java-format](#palantir-java-format), [formatAnnotations](#formatAnnotations), [cleanthat](#cleanthat)) - [Groovy](#groovy) ([eclipse groovy](#eclipse-groovy)) - [Kotlin](#kotlin) ([ktfmt](#ktfmt), [ktlint](#ktlint), [diktat](#diktat), [prettier](#prettier)) - [Scala](#scala) ([scalafmt](#scalafmt)) @@ -154,6 +154,9 @@ spotless { removeUnusedImports() + // Cleanthat will refactor your code, but it may break your style: apply it before your formatter + cleanthat() // has its own section below + // Choose one of these formatters. googleJavaFormat() // has its own section below eclipse() // has its own section below @@ -257,6 +260,23 @@ You can use `addTypeAnnotation()` and `removeTypeAnnotation()` to override its d You can make a pull request to add new annotations to Spotless's default list. +### cleanthat + +[homepage](https://github.com/solven-eu/cleanthat). CleanThat enables automatic refactoring of Java code. [ChangeLog](https://github.com/solven-eu/cleanthat/blob/master/CHANGES.MD) + +```gradle +spotless { + java { + cleanthat() + // optional: you can specify a specific version and/or config file + cleanthat() + .groupArtifact('1.7') // default is 'io.github.solven-eu.cleanthat:java' + .version('2.1') // You may force a past of -SNAPSHOT + .sourceCompatibility('1.7') // default is '1.7' + .addMutator('your.custom.MagicMutator') + .excludeMutator('UseCollectionIsEmpty') +``` + diff --git a/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/JavaExtension.java b/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/JavaExtension.java index e65d0601e7..6e9f6de005 100644 --- a/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/JavaExtension.java +++ b/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/JavaExtension.java @@ -281,7 +281,7 @@ public class CleanthatJavaConfig { private String version = CleanthatJavaStep.defaultVersion(); - private String sourceJdk = CleanthatJavaStep.defaultJdkVersion(); + private String sourceJdk = CleanthatJavaStep.defaultSourceJdk(); private List mutators = CleanthatJavaStep.defaultMutators(); @@ -305,9 +305,9 @@ public CleanthatJavaConfig version(String version) { return this; } - public CleanthatJavaConfig sourceJdk(String sourceJdk) { - Objects.requireNonNull(sourceJdk); - this.sourceJdk = sourceJdk; + public CleanthatJavaConfig sourceCompatibility(String jdkVersion) { + Objects.requireNonNull(jdkVersion); + this.sourceJdk = jdkVersion; replaceStep(createStep()); return this; } diff --git a/plugin-maven/CHANGES.md b/plugin-maven/CHANGES.md index fc276f7c8d..a13353e68e 100644 --- a/plugin-maven/CHANGES.md +++ b/plugin-maven/CHANGES.md @@ -4,7 +4,7 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format ( ## [Unreleased] ### Added -* CleanThat Java Refactorer ([#???](https://github.com/diffplug/spotless/pull/???)) +* CleanThat Java Refactorer ([#1560](https://github.com/diffplug/spotless/pull/1560)) ## [2.32.0] - 2023-02-05 ### Added diff --git a/plugin-maven/src/main/java/com/diffplug/spotless/maven/java/CleanthatJava.java b/plugin-maven/src/main/java/com/diffplug/spotless/maven/java/CleanthatJava.java index 7460ab67b9..d7dd1f2530 100644 --- a/plugin-maven/src/main/java/com/diffplug/spotless/maven/java/CleanthatJava.java +++ b/plugin-maven/src/main/java/com/diffplug/spotless/maven/java/CleanthatJava.java @@ -33,7 +33,7 @@ public class CleanthatJava implements FormatterStepFactory { // https://maven.apache.org/plugins/maven-compiler-plugin/compile-mojo.html#source @Parameter(property = "maven.compiler.source") - private String sourceJdk = CleanthatJavaStep.defaultJdkVersion(); + private String sourceJdk = CleanthatJavaStep.defaultSourceJdk(); @Parameter private List mutators = CleanthatJavaStep.defaultMutators(); From 374acb6fec5484f92a1119e05e3a80e9f92a1bc0 Mon Sep 17 00:00:00 2001 From: Benoit Lacelle Date: Thu, 9 Feb 2023 00:01:28 +0400 Subject: [PATCH 741/757] Fix unitTests --- README.md | 2 +- lib/build.gradle | 9 ++- .../java/JavaCleanthatRefactorerFuncTest.java | 72 ------------------- .../glue/java/JavaCleanthatRefactorerFuncTest | 28 ++++++++ .../CleanthatJavaIntegrationTest.java | 2 +- 5 files changed, 37 insertions(+), 76 deletions(-) delete mode 100644 lib/src/testCleanthat/java/com/diffplug/spotless/glue/java/JavaCleanthatRefactorerFuncTest.java create mode 100644 lib/src/testCompatCleanthat2Dot1/java/com/diffplug/spotless/glue/java/JavaCleanthatRefactorerFuncTest diff --git a/README.md b/README.md index 5f59368677..420c13ab53 100644 --- a/README.md +++ b/README.md @@ -84,7 +84,7 @@ lib('java.PalantirJavaFormatStep') +'{{yes}} | {{yes}} lib('java.RemoveUnusedImportsStep') +'{{yes}} | {{yes}} | {{yes}} | {{no}} |', extra('java.EclipseJdtFormatterStep') +'{{yes}} | {{yes}} | {{yes}} | {{no}} |', lib('java.FormatAnnotationsStep') +'{{yes}} | {{yes}} | {{no}} | {{no}} |', -lib('java.CleanthatJavaStep') +'{{no}} | {{yes}} | {{no}} | {{no}} |', +lib('java.CleanthatJavaStep') +'{{yes}} | {{yes}} | {{no}} | {{no}} |', lib('json.gson.GsonStep') +'{{yes}} | {{yes}} | {{no}} | {{no}} |', lib('json.JacksonJsonStep') +'{{yes}} | {{yes}} | {{no}} | {{no}} |', lib('json.JsonSimpleStep') +'{{yes}} | {{yes}} | {{no}} | {{no}} |', diff --git a/lib/build.gradle b/lib/build.gradle index cd6996a979..154b2acd6a 100644 --- a/lib/build.gradle +++ b/lib/build.gradle @@ -40,6 +40,12 @@ versionCompatibility { ] targetSourceSetName = 'ktlint' } + namespaces.register('Cleanthat') { + versions = [ + '2.1', + ] + targetSourceSetName = 'cleanthat' + } } } @@ -103,9 +109,8 @@ dependencies { gsonCompileOnly 'com.google.code.gson:gson:2.10.1' - // TODO How can one add a test module like 'compatKtLint0Dot48Dot0'? - // cleanthatCompileAndTestOnly 'io.github.solven-eu.cleanthat:java:2.1' cleanthatCompileOnly 'io.github.solven-eu.cleanthat:java:2.1' + compatCleanthat2Dot1CompileAndTestOnly 'io.github.solven-eu.cleanthat:java:2.1' } // we'll hold the core lib to a high standard diff --git a/lib/src/testCleanthat/java/com/diffplug/spotless/glue/java/JavaCleanthatRefactorerFuncTest.java b/lib/src/testCleanthat/java/com/diffplug/spotless/glue/java/JavaCleanthatRefactorerFuncTest.java deleted file mode 100644 index c811b51233..0000000000 --- a/lib/src/testCleanthat/java/com/diffplug/spotless/glue/java/JavaCleanthatRefactorerFuncTest.java +++ /dev/null @@ -1,72 +0,0 @@ -/* - * Copyright 2023 DiffPlug - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package com.diffplug.spotless.glue.ktlint.compat; - -import static org.junit.jupiter.api.Assertions.assertEquals; - -import java.io.IOException; -import java.io.InputStream; -import java.nio.charset.StandardCharsets; -import java.nio.file.Files; -import java.nio.file.Path; -import java.nio.file.Paths; -import java.util.HashMap; -import java.util.Map; - -import org.junit.jupiter.api.Test; -import org.junit.jupiter.api.io.TempDir; - -public class KtLintCompat0Dot48Dot0AdapterTest { - @Test - public void testDefaults(@TempDir Path path) throws IOException { - KtLintCompat0Dot48Dot0Adapter ktLintCompat0Dot48Dot0Adapter = new KtLintCompat0Dot48Dot0Adapter(); - String text = loadAndWriteText(path, "empty_class_body.kt"); - final Path filePath = Paths.get(path.toString(), "empty_class_body.kt"); - - Map userData = new HashMap<>(); - - Map editorConfigOverrideMap = new HashMap<>(); - - String formatted = ktLintCompat0Dot48Dot0Adapter.format(text, filePath, false, false, null, userData, editorConfigOverrideMap); - assertEquals("class empty_class_body\n", formatted); - } - - @Test - public void testEditorConfigCanDisable(@TempDir Path path) throws IOException { - KtLintCompat0Dot48Dot0Adapter ktLintCompat0Dot48Dot0Adapter = new KtLintCompat0Dot48Dot0Adapter(); - String text = loadAndWriteText(path, "fails_no_semicolons.kt"); - final Path filePath = Paths.get(path.toString(), "fails_no_semicolons.kt"); - - Map userData = new HashMap<>(); - - Map editorConfigOverrideMap = new HashMap<>(); - editorConfigOverrideMap.put("indent_style", "tab"); - editorConfigOverrideMap.put("ktlint_standard_no-semi", "disabled"); - // ktlint_filename is an invalid rule in ktlint 0.48.0 - editorConfigOverrideMap.put("ktlint_filename", "disabled"); - - String formatted = ktLintCompat0Dot48Dot0Adapter.format(text, filePath, false, false, null, userData, editorConfigOverrideMap); - assertEquals("class fails_no_semicolons {\n\tval i = 0;\n}\n", formatted); - } - - private static String loadAndWriteText(Path path, String name) throws IOException { - try (InputStream is = KtLintCompat0Dot48Dot0AdapterTest.class.getResourceAsStream("/" + name)) { - Files.copy(is, path.resolve(name)); - } - return new String(Files.readAllBytes(path.resolve(name)), StandardCharsets.UTF_8); - } - -} diff --git a/lib/src/testCompatCleanthat2Dot1/java/com/diffplug/spotless/glue/java/JavaCleanthatRefactorerFuncTest b/lib/src/testCompatCleanthat2Dot1/java/com/diffplug/spotless/glue/java/JavaCleanthatRefactorerFuncTest new file mode 100644 index 0000000000..2f3cdc9646 --- /dev/null +++ b/lib/src/testCompatCleanthat2Dot1/java/com/diffplug/spotless/glue/java/JavaCleanthatRefactorerFuncTest @@ -0,0 +1,28 @@ +/* + * Copyright 2023 DiffPlug + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.diffplug.spotless.glue.java; + +import org.assertj.core.api.Assertions; +import org.junit.jupiter.api.Test; + +import eu.solven.cleanthat.engine.java.refactorer.JavaRefactorer; + +public class JavaCleanthatRefactorerFuncTest { + @Test + public void testMutatorsDetection() { + Assertions.assertThat(JavaRefactorer.getAllIncluded()).isNotEmpty(); + } +} diff --git a/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/CleanthatJavaIntegrationTest.java b/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/CleanthatJavaIntegrationTest.java index 2b3ede1472..a754b963f2 100644 --- a/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/CleanthatJavaIntegrationTest.java +++ b/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/CleanthatJavaIntegrationTest.java @@ -31,7 +31,7 @@ void integration() throws IOException { "spotless {", " java {", " target file('test.java')", - " cleanthat().sourceJdk('11')", + " cleanthat().sourceCompatibility('11')", " }", "}"); From 8fbbb7165a840fb8d5435266617a342e8fd21846 Mon Sep 17 00:00:00 2001 From: Benoit Lacelle Date: Thu, 9 Feb 2023 00:02:25 +0400 Subject: [PATCH 742/757] Remove useless dependency --- lib/build.gradle | 1 - 1 file changed, 1 deletion(-) diff --git a/lib/build.gradle b/lib/build.gradle index 154b2acd6a..21181cd54b 100644 --- a/lib/build.gradle +++ b/lib/build.gradle @@ -61,7 +61,6 @@ dependencies { testCommonImplementation "org.junit.jupiter:junit-jupiter:$VER_JUNIT" testCommonImplementation "org.assertj:assertj-core:$VER_ASSERTJ" testCommonImplementation "com.diffplug.durian:durian-testlib:$VER_DURIAN" - testCommonImplementation 'io.github.solven-eu.cleanthat:java:2.1' // used for pom sorting sortPomCompileOnly 'com.github.ekryd.sortpom:sortpom-sorter:3.0.0' From 640a1c20426f1f5ef114a8b15176bf618d6b4d0d Mon Sep 17 00:00:00 2001 From: Benoit Lacelle Date: Thu, 9 Feb 2023 00:08:01 +0400 Subject: [PATCH 743/757] Remove irrelevant test file --- README.md | 2 +- .../java/JavaCleanthatRefactorerFuncTest.java | 28 ------------------- 2 files changed, 1 insertion(+), 29 deletions(-) delete mode 100644 lib/src/test/java/com/diffplug/spotless/glue/java/JavaCleanthatRefactorerFuncTest.java diff --git a/README.md b/README.md index 420c13ab53..662c624bdf 100644 --- a/README.md +++ b/README.md @@ -132,7 +132,7 @@ lib('yaml.JacksonYamlStep') +'{{yes}} | {{yes}} | [`java.RemoveUnusedImportsStep`](lib/src/main/java/com/diffplug/spotless/java/RemoveUnusedImportsStep.java) | :+1: | :+1: | :+1: | :white_large_square: | | [`java.EclipseJdtFormatterStep`](lib-extra/src/main/java/com/diffplug/spotless/extra/java/EclipseJdtFormatterStep.java) | :+1: | :+1: | :+1: | :white_large_square: | | [`java.FormatAnnotationsStep`](lib/src/main/java/com/diffplug/spotless/java/FormatAnnotationsStep.java) | :+1: | :+1: | :white_large_square: | :white_large_square: | -| [`java.CleanthatJavaStep`](lib/src/main/java/com/diffplug/spotless/java/CleanthatJavaStep.java) | :white_large_square: | :+1: | :white_large_square: | :white_large_square: | +| [`java.CleanthatJavaStep`](lib/src/main/java/com/diffplug/spotless/java/CleanthatJavaStep.java) | :+1: | :+1: | :white_large_square: | :white_large_square: | | [`json.gson.GsonStep`](lib/src/main/java/com/diffplug/spotless/json/gson/GsonStep.java) | :+1: | :+1: | :white_large_square: | :white_large_square: | | [`json.JacksonJsonStep`](lib/src/main/java/com/diffplug/spotless/json/JacksonJsonStep.java) | :+1: | :+1: | :white_large_square: | :white_large_square: | | [`json.JsonSimpleStep`](lib/src/main/java/com/diffplug/spotless/json/JsonSimpleStep.java) | :+1: | :+1: | :white_large_square: | :white_large_square: | diff --git a/lib/src/test/java/com/diffplug/spotless/glue/java/JavaCleanthatRefactorerFuncTest.java b/lib/src/test/java/com/diffplug/spotless/glue/java/JavaCleanthatRefactorerFuncTest.java deleted file mode 100644 index 2f3cdc9646..0000000000 --- a/lib/src/test/java/com/diffplug/spotless/glue/java/JavaCleanthatRefactorerFuncTest.java +++ /dev/null @@ -1,28 +0,0 @@ -/* - * Copyright 2023 DiffPlug - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package com.diffplug.spotless.glue.java; - -import org.assertj.core.api.Assertions; -import org.junit.jupiter.api.Test; - -import eu.solven.cleanthat.engine.java.refactorer.JavaRefactorer; - -public class JavaCleanthatRefactorerFuncTest { - @Test - public void testMutatorsDetection() { - Assertions.assertThat(JavaRefactorer.getAllIncluded()).isNotEmpty(); - } -} From fdee03ce774ceff7ef92b3d4db680b0e361ed0fd Mon Sep 17 00:00:00 2001 From: Benoit Lacelle Date: Thu, 9 Feb 2023 00:25:00 +0400 Subject: [PATCH 744/757] Fix extention of unitTest --- ...RefactorerFuncTest => JavaCleanthatRefactorerFuncTest.java} | 0 plugin-maven/README.md | 3 ++- 2 files changed, 2 insertions(+), 1 deletion(-) rename lib/src/testCompatCleanthat2Dot1/java/com/diffplug/spotless/glue/java/{JavaCleanthatRefactorerFuncTest => JavaCleanthatRefactorerFuncTest.java} (100%) diff --git a/lib/src/testCompatCleanthat2Dot1/java/com/diffplug/spotless/glue/java/JavaCleanthatRefactorerFuncTest b/lib/src/testCompatCleanthat2Dot1/java/com/diffplug/spotless/glue/java/JavaCleanthatRefactorerFuncTest.java similarity index 100% rename from lib/src/testCompatCleanthat2Dot1/java/com/diffplug/spotless/glue/java/JavaCleanthatRefactorerFuncTest rename to lib/src/testCompatCleanthat2Dot1/java/com/diffplug/spotless/glue/java/JavaCleanthatRefactorerFuncTest.java diff --git a/plugin-maven/README.md b/plugin-maven/README.md index b1b9098bfe..f59a1d9004 100644 --- a/plugin-maven/README.md +++ b/plugin-maven/README.md @@ -182,6 +182,7 @@ any other maven phase (i.e. compile) then it can be configured as below; src/test/java/**/*.java + @@ -285,7 +286,7 @@ These mechanisms already exist for the Gradle plugin. 2.0 ${maven.compiler.source} - * + * LiteralsFirstInComparisons From ce086ba1382f618a2cb0b93c9f2fac02f19cfdb1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lars=20L=C3=B8nne?= Date: Wed, 8 Feb 2023 21:34:29 +0100 Subject: [PATCH 745/757] adds entry about continuation indent to the other changelogs --- CHANGES.md | 2 ++ plugin-gradle/CHANGES.md | 2 ++ 2 files changed, 4 insertions(+) diff --git a/CHANGES.md b/CHANGES.md index 5f1a1ffa9f..86a9eeabf2 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -10,6 +10,8 @@ This document is intended for Spotless developers. We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format (starting after version `1.27.0`). ## [Unreleased] +### Fixed +* Maven plugin with `ktfmt` default style uses correct continuation indent ([#1562](https://github.com/diffplug/spotless/pull/1562)) ## [2.34.1] - 2023-02-05 ### Changes diff --git a/plugin-gradle/CHANGES.md b/plugin-gradle/CHANGES.md index e3234584b8..9927b56f07 100644 --- a/plugin-gradle/CHANGES.md +++ b/plugin-gradle/CHANGES.md @@ -3,6 +3,8 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format (starting after version `3.27.0`). ## [Unreleased] +### Fixed +* Maven plugin with `ktfmt` default style uses correct continuation indent ([#1562](https://github.com/diffplug/spotless/pull/1562)) ## [6.14.1] - 2023-02-05 ### Fixed From 3e1ea286ca1d203e32f80b557e3fde54c91fa79a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lars=20L=C3=B8nne?= Date: Thu, 9 Feb 2023 12:33:03 +0100 Subject: [PATCH 746/757] updates copyright --- .../com/diffplug/spotless/glue/ktfmt/KtfmtFormatterFunc.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/src/ktfmt/java/com/diffplug/spotless/glue/ktfmt/KtfmtFormatterFunc.java b/lib/src/ktfmt/java/com/diffplug/spotless/glue/ktfmt/KtfmtFormatterFunc.java index e34f7b4755..80f4a42fcd 100644 --- a/lib/src/ktfmt/java/com/diffplug/spotless/glue/ktfmt/KtfmtFormatterFunc.java +++ b/lib/src/ktfmt/java/com/diffplug/spotless/glue/ktfmt/KtfmtFormatterFunc.java @@ -1,5 +1,5 @@ /* - * Copyright 2022 DiffPlug + * Copyright 2022-2023 DiffPlug * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. From 1b990ab98d23561c4433bcab4175356903b2e5c2 Mon Sep 17 00:00:00 2001 From: Simon Gamma Date: Thu, 26 Jan 2023 16:35:21 +0100 Subject: [PATCH 747/757] 1162: adding tests verifying issue results in 'Couldn't resolve parser "php"' on gradle side and 'Couldn't resolve parser "java"' on maven side --- .../spotless/PrettierIntegrationTest.java | 42 +++++++++++++++ .../maven/MavenIntegrationHarness.java | 15 ++++-- .../prettier/PrettierFormatStepTest.java | 52 +++++++++++++++++++ 3 files changed, 105 insertions(+), 4 deletions(-) diff --git a/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/PrettierIntegrationTest.java b/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/PrettierIntegrationTest.java index 4c458e3ca7..8819d5bc07 100644 --- a/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/PrettierIntegrationTest.java +++ b/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/PrettierIntegrationTest.java @@ -183,6 +183,48 @@ void usePhpCommunityPlugin() throws IOException { assertFile("php-example.php").sameAsResource("npm/prettier/plugins/php.clean"); } + /** + * This test is to ensure that we can have multiple prettier instances in one spotless config. + * + * @see Issue #1162 on github + */ + @Test + void usePhpAndJavaCommunityPlugin() throws IOException { + setFile("build.gradle").toLines( + "plugins {", + " id 'com.diffplug.spotless'", + "}", + "repositories { mavenCentral() }", + "def prettierConfigPhp = [:]", + "prettierConfigPhp['tabWidth'] = 3", + "prettierConfigPhp['parser'] = 'php'", + "def prettierPackagesPhp = [:]", + "prettierPackagesPhp['prettier'] = '2.0.5'", + "prettierPackagesPhp['@prettier/plugin-php'] = '0.14.2'", + "def prettierConfigJava = [:]", + "prettierConfigJava['tabWidth'] = 4", + "prettierConfigJava['parser'] = 'java'", + "def prettierPackagesJava = [:]", + "prettierPackagesJava['prettier'] = '2.0.5'", + "prettierPackagesJava['prettier-plugin-java'] = '0.8.0'", + "spotless {", + " format 'php', {", + " target 'php-example.php'", + " prettier(prettierPackagesPhp).config(prettierConfigPhp)", + " }", + " java {", + " target 'JavaTest.java'", + " prettier(prettierPackagesJava).config(prettierConfigJava)", + " }", + "}"); + setFile("php-example.php").toResource("npm/prettier/plugins/php.dirty"); + setFile("JavaTest.java").toResource("npm/prettier/plugins/java-test.dirty"); + final BuildResult spotlessApply = gradleRunner().withArguments("--stacktrace", "spotlessApply").build(); + Assertions.assertThat(spotlessApply.getOutput()).contains("BUILD SUCCESSFUL"); + assertFile("php-example.php").sameAsResource("npm/prettier/plugins/php.clean"); + assertFile("JavaTest.java").sameAsResource("npm/prettier/plugins/java-test.clean"); + } + @Test void autodetectNpmrcFileConfig() throws IOException { setFile(".npmrc").toLines( diff --git a/plugin-maven/src/test/java/com/diffplug/spotless/maven/MavenIntegrationHarness.java b/plugin-maven/src/test/java/com/diffplug/spotless/maven/MavenIntegrationHarness.java index fdc4a745a1..2891ee3b2c 100644 --- a/plugin-maven/src/test/java/com/diffplug/spotless/maven/MavenIntegrationHarness.java +++ b/plugin-maven/src/test/java/com/diffplug/spotless/maven/MavenIntegrationHarness.java @@ -285,7 +285,7 @@ private static String getSystemProperty(String name) { return value; } - private static String[] groupWithSteps(String group, String[] includes, String... steps) { + protected static String[] groupWithSteps(String group, String[] includes, String... steps) { String[] result = new String[steps.length + includes.length + 2]; result[0] = "<" + group + ">"; System.arraycopy(includes, 0, result, 1, includes.length); @@ -294,15 +294,22 @@ private static String[] groupWithSteps(String group, String[] includes, String.. return result; } - private static String[] groupWithSteps(String group, String... steps) { + protected static String[] groupWithSteps(String group, String... steps) { return groupWithSteps(group, new String[]{}, steps); } - private static String[] including(String... includes) { + protected static String[] including(String... includes) { return groupWithSteps("includes", groupWithSteps("include", includes)); } - private static String[] formats(String... formats) { + protected static String[] formats(String... formats) { return groupWithSteps("formats", formats); } + + protected static String[] formats(String[]... formats) { + String[] formatsArray = Arrays.stream(formats) + .flatMap(Arrays::stream) + .toArray(String[]::new); + return formats(formatsArray); + } } diff --git a/plugin-maven/src/test/java/com/diffplug/spotless/maven/prettier/PrettierFormatStepTest.java b/plugin-maven/src/test/java/com/diffplug/spotless/maven/prettier/PrettierFormatStepTest.java index 47dab5d152..78a0fc30ff 100644 --- a/plugin-maven/src/test/java/com/diffplug/spotless/maven/prettier/PrettierFormatStepTest.java +++ b/plugin-maven/src/test/java/com/diffplug/spotless/maven/prettier/PrettierFormatStepTest.java @@ -106,6 +106,58 @@ void unique_dependency_config() throws Exception { assertThat(result.stdOutUtf8()).contains(Prettier.ERROR_MESSAGE_ONLY_ONE_CONFIG); } + /** + * This test is to ensure that we can have multiple prettier instances in one spotless config. + * + * @see Issue #1162 on github + */ + @Test + void multiple_prettier_configs() throws Exception { + writePom( + formats( + groupWithSteps("format", including("php-example.php"), + "", + " ", + " ", + " prettier", + " 2.0.5", + " ", + " ", + " @prettier/plugin-php", + " 0.14.2", + " ", + " ", + " ", + " 3", + " php", + " ", + ""), + groupWithSteps("java", including("JavaTest.java"), + "", + " ", + " ", + " prettier", + " 2.0.5", + " ", + " ", + " prettier-plugin-java", + " 0.8.0", + " ", + " ", + " ", + " 4", + " java", + " ", + ""))); + + setFile("php-example.php").toResource("npm/prettier/plugins/php.dirty"); + setFile("JavaTest.java").toResource("npm/prettier/plugins/java-test.dirty"); + mavenRunner().withArguments("spotless:apply").runNoError(); + assertFile("php-example.php").sameAsResource("npm/prettier/plugins/php.clean"); + assertFile("JavaTest.java").sameAsResource("npm/prettier/plugins/java-test.clean"); + + } + @Test void custom_plugin() throws Exception { writePomWithFormatSteps( From fdbbd024158911d65cb567b04340f875d45dd46b Mon Sep 17 00:00:00 2001 From: Simon Gamma Date: Fri, 27 Jan 2023 20:21:18 +0100 Subject: [PATCH 748/757] 1162: add unique suffix reflecting package.json content --- .../diffplug/spotless/npm/NodeServerLayout.java | 4 ++-- .../spotless/npm/NpmFormatterStepStateBase.java | 9 ++++++++- .../spotless/npm/NpmResourceHelper.java | 17 +++++++++++++++++ 3 files changed, 27 insertions(+), 3 deletions(-) diff --git a/lib/src/main/java/com/diffplug/spotless/npm/NodeServerLayout.java b/lib/src/main/java/com/diffplug/spotless/npm/NodeServerLayout.java index 63a6a923da..60c34bcc8c 100644 --- a/lib/src/main/java/com/diffplug/spotless/npm/NodeServerLayout.java +++ b/lib/src/main/java/com/diffplug/spotless/npm/NodeServerLayout.java @@ -29,8 +29,8 @@ class NodeServerLayout { private final File serveJsFile; private final File npmrcFile; - NodeServerLayout(File buildDir, String stepName) { - this.nodeModulesDir = new File(buildDir, "spotless-node-modules-" + stepName); + NodeServerLayout(File buildDir, String stepName, String stepSuffix) { + this.nodeModulesDir = new File(buildDir, String.format("spotless-node-modules-%s-%s", stepName, stepSuffix)); this.packageJsonFile = new File(nodeModulesDir, "package.json"); this.serveJsFile = new File(nodeModulesDir, "serve.js"); this.npmrcFile = new File(nodeModulesDir, ".npmrc"); diff --git a/lib/src/main/java/com/diffplug/spotless/npm/NpmFormatterStepStateBase.java b/lib/src/main/java/com/diffplug/spotless/npm/NpmFormatterStepStateBase.java index 92ac7df6f2..412a827d9e 100644 --- a/lib/src/main/java/com/diffplug/spotless/npm/NpmFormatterStepStateBase.java +++ b/lib/src/main/java/com/diffplug/spotless/npm/NpmFormatterStepStateBase.java @@ -56,7 +56,14 @@ protected NpmFormatterStepStateBase(String stepName, NpmConfig npmConfig, NpmFor this.stepName = requireNonNull(stepName); this.npmConfig = requireNonNull(npmConfig); this.locations = locations; - this.nodeServerLayout = new NodeServerLayout(locations.buildDir(), stepName); + String stateSuffix = stateSuffix(); + logger.info("Creating {} with name {} and state suffix {}", this.getClass().getSimpleName(), stepName, stateSuffix); + this.nodeServerLayout = new NodeServerLayout(locations.buildDir(), stepName, stateSuffix); + } + + protected String stateSuffix() { + String packageJsonContent = npmConfig.getPackageJsonContent(); + return NpmResourceHelper.md5(packageJsonContent); } protected void prepareNodeServerLayout() throws IOException { diff --git a/lib/src/main/java/com/diffplug/spotless/npm/NpmResourceHelper.java b/lib/src/main/java/com/diffplug/spotless/npm/NpmResourceHelper.java index 2acf3a180d..aa66c54fcf 100644 --- a/lib/src/main/java/com/diffplug/spotless/npm/NpmResourceHelper.java +++ b/lib/src/main/java/com/diffplug/spotless/npm/NpmResourceHelper.java @@ -21,6 +21,7 @@ import java.nio.file.Path; import java.nio.file.Paths; import java.nio.file.StandardCopyOption; +import java.security.MessageDigest; import java.time.Duration; import java.util.Arrays; import java.util.Objects; @@ -122,4 +123,20 @@ static File copyFileToDirAtSubpath(File file, File targetDir, String relativePat throw ThrowingEx.asRuntime(e); } } + + static String md5(File file) { + return md5(readUtf8StringFromFile(file)); + } + + static String md5(String fileContent) { + MessageDigest md = ThrowingEx.get(() -> MessageDigest.getInstance("MD5")); + md.update(fileContent.getBytes(StandardCharsets.UTF_8)); + byte[] digest = md.digest(); + // convert byte array digest to hex string + StringBuilder sb = new StringBuilder(); + for (byte b : digest) { + sb.append(String.format("%02x", b & 0xff)); + } + return sb.toString(); + } } From e0a290a2b784b073eb13bac62f77dff57b9cee11 Mon Sep 17 00:00:00 2001 From: Simon Gamma Date: Wed, 8 Feb 2023 21:09:13 +0100 Subject: [PATCH 749/757] 1162: separate node dirs per package.json --- .../spotless/npm/NodeServerLayout.java | 40 ++++++++++++++++--- .../npm/NpmFormatterStepStateBase.java | 18 ++++----- .../diffplug/spotless/npm/eslint-package.json | 2 +- .../spotless/npm/prettier-package.json | 2 +- .../diffplug/spotless/npm/tsfmt-package.json | 2 +- 5 files changed, 45 insertions(+), 19 deletions(-) diff --git a/lib/src/main/java/com/diffplug/spotless/npm/NodeServerLayout.java b/lib/src/main/java/com/diffplug/spotless/npm/NodeServerLayout.java index 60c34bcc8c..8b39c5e4ab 100644 --- a/lib/src/main/java/com/diffplug/spotless/npm/NodeServerLayout.java +++ b/lib/src/main/java/com/diffplug/spotless/npm/NodeServerLayout.java @@ -18,25 +18,44 @@ import java.io.File; import java.nio.file.Files; import java.nio.file.Path; +import java.util.regex.Matcher; +import java.util.regex.Pattern; import java.util.stream.Stream; import com.diffplug.spotless.ThrowingEx; class NodeServerLayout { + private static final Pattern PACKAGE_JSON_NAME_PATTERN = Pattern.compile("\"name\"\\s*:\\s*\"([^\"]+)\""); + private final File nodeModulesDir; private final File packageJsonFile; + + private final File packageLockJsonFile; + private final File serveJsFile; private final File npmrcFile; - NodeServerLayout(File buildDir, String stepName, String stepSuffix) { - this.nodeModulesDir = new File(buildDir, String.format("spotless-node-modules-%s-%s", stepName, stepSuffix)); + NodeServerLayout(File buildDir, String packageJsonContent) { + this.nodeModulesDir = new File(buildDir, nodeModulesDirName(packageJsonContent)); this.packageJsonFile = new File(nodeModulesDir, "package.json"); + this.packageLockJsonFile = new File(nodeModulesDir, "package-lock.json"); this.serveJsFile = new File(nodeModulesDir, "serve.js"); this.npmrcFile = new File(nodeModulesDir, ".npmrc"); } + private static String nodeModulesDirName(String packageJsonContent) { + String md5Hash = NpmResourceHelper.md5(packageJsonContent); + Matcher matcher = PACKAGE_JSON_NAME_PATTERN.matcher(packageJsonContent); + if (!matcher.find()) { + throw new IllegalArgumentException("package.json must contain a name property"); + } + String packageName = matcher.group(1); + return String.format("%s-node-modules-%s", packageName, md5Hash); + } + File nodeModulesDir() { + return nodeModulesDir; } @@ -52,10 +71,6 @@ public File npmrcFile() { return npmrcFile; } - static File getBuildDirFromNodeModulesDir(File nodeModulesDir) { - return nodeModulesDir.getParentFile(); - } - public boolean isLayoutPrepared() { if (!nodeModulesDir().isDirectory()) { return false; @@ -63,6 +78,9 @@ public boolean isLayoutPrepared() { if (!packageJsonFile().isFile()) { return false; } + if (!packageLockJsonFile.isFile()) { + return false; + } if (!serveJsFile().isFile()) { return false; } @@ -82,4 +100,14 @@ public boolean isNodeModulesPrepared() { } }); } + + @Override + public String toString() { + return String.format( + "NodeServerLayout[nodeModulesDir=%s, packageJsonFile=%s, serveJsFile=%s, npmrcFile=%s]", + this.nodeModulesDir, + this.packageJsonFile, + this.serveJsFile, + this.npmrcFile); + } } diff --git a/lib/src/main/java/com/diffplug/spotless/npm/NpmFormatterStepStateBase.java b/lib/src/main/java/com/diffplug/spotless/npm/NpmFormatterStepStateBase.java index 412a827d9e..f3f8a80fe8 100644 --- a/lib/src/main/java/com/diffplug/spotless/npm/NpmFormatterStepStateBase.java +++ b/lib/src/main/java/com/diffplug/spotless/npm/NpmFormatterStepStateBase.java @@ -56,17 +56,13 @@ protected NpmFormatterStepStateBase(String stepName, NpmConfig npmConfig, NpmFor this.stepName = requireNonNull(stepName); this.npmConfig = requireNonNull(npmConfig); this.locations = locations; - String stateSuffix = stateSuffix(); - logger.info("Creating {} with name {} and state suffix {}", this.getClass().getSimpleName(), stepName, stateSuffix); - this.nodeServerLayout = new NodeServerLayout(locations.buildDir(), stepName, stateSuffix); - } - - protected String stateSuffix() { - String packageJsonContent = npmConfig.getPackageJsonContent(); - return NpmResourceHelper.md5(packageJsonContent); + this.nodeServerLayout = new NodeServerLayout(locations.buildDir(), npmConfig.getPackageJsonContent()); } protected void prepareNodeServerLayout() throws IOException { + final long started = System.currentTimeMillis(); + // maybe introduce trace logger? + logger.info("Preparing {} for npm step {}.", this.nodeServerLayout, getClass().getName()); NpmResourceHelper.assertDirectoryExists(nodeServerLayout.nodeModulesDir()); NpmResourceHelper.writeUtf8StringToFile(nodeServerLayout.packageJsonFile(), this.npmConfig.getPackageJsonContent()); @@ -77,12 +73,14 @@ protected void prepareNodeServerLayout() throws IOException { } else { NpmResourceHelper.deleteFileIfExists(nodeServerLayout.npmrcFile()); } + logger.info("Prepared {} for npm step {} in {} ms.", this.nodeServerLayout, getClass().getName(), System.currentTimeMillis() - started); } protected void prepareNodeServer() throws IOException { - FormattedPrinter.SYSOUT.print("running npm install"); + final long started = System.currentTimeMillis(); + logger.info("running npm install in {} for npm step {}", this.nodeServerLayout.nodeModulesDir(), getClass().getName()); runNpmInstall(nodeServerLayout.nodeModulesDir()); - FormattedPrinter.SYSOUT.print("npm install finished"); + logger.info("npm install finished in {} ms in {} for npm step {}", System.currentTimeMillis() - started, this.nodeServerLayout.nodeModulesDir(), getClass().getName()); } private void runNpmInstall(File npmProjectDir) throws IOException { diff --git a/lib/src/main/resources/com/diffplug/spotless/npm/eslint-package.json b/lib/src/main/resources/com/diffplug/spotless/npm/eslint-package.json index dcd91e729d..0d7ce930f7 100644 --- a/lib/src/main/resources/com/diffplug/spotless/npm/eslint-package.json +++ b/lib/src/main/resources/com/diffplug/spotless/npm/eslint-package.json @@ -1,5 +1,5 @@ { - "name": "spotless-eslint-formatter-step", + "name": "spotless-eslint", "version": "2.0.0", "description": "Spotless formatter step for running eslint as a rest service.", "repository": "https://github.com/diffplug/spotless", diff --git a/lib/src/main/resources/com/diffplug/spotless/npm/prettier-package.json b/lib/src/main/resources/com/diffplug/spotless/npm/prettier-package.json index 7bda08db8a..395a05da67 100644 --- a/lib/src/main/resources/com/diffplug/spotless/npm/prettier-package.json +++ b/lib/src/main/resources/com/diffplug/spotless/npm/prettier-package.json @@ -1,5 +1,5 @@ { - "name": "spotless-prettier-formatter-step", + "name": "spotless-prettier", "version": "2.0.0", "description": "Spotless formatter step for running prettier as a rest service.", "repository": "https://github.com/diffplug/spotless", diff --git a/lib/src/main/resources/com/diffplug/spotless/npm/tsfmt-package.json b/lib/src/main/resources/com/diffplug/spotless/npm/tsfmt-package.json index 7037bd2ec1..483dd0753d 100644 --- a/lib/src/main/resources/com/diffplug/spotless/npm/tsfmt-package.json +++ b/lib/src/main/resources/com/diffplug/spotless/npm/tsfmt-package.json @@ -1,5 +1,5 @@ { - "name": "spotless-tsfmt-formatter-step", + "name": "spotless-tsfmt", "version": "2.0.0", "description": "Spotless formatter step for running tsfmt as a rest service.", "repository": "https://github.com/diffplug/spotless", From 080f2378af86d3fa8e8db5be207a03415dc47fe8 Mon Sep 17 00:00:00 2001 From: Simon Gamma Date: Thu, 9 Feb 2023 20:44:38 +0100 Subject: [PATCH 750/757] 1162: use slf4j for logging --- .../com/diffplug/spotless/LazyArgLogger.java | 40 ++++++++++++++++++ .../spotless/npm/EslintFormatterStep.java | 9 ++-- .../spotless/npm/FormattedPrinter.java | 42 ------------------- .../spotless/npm/PrettierFormatterStep.java | 7 ++-- .../spotless/PrettierIntegrationTest.java | 4 +- 5 files changed, 52 insertions(+), 50 deletions(-) create mode 100644 lib/src/main/java/com/diffplug/spotless/LazyArgLogger.java delete mode 100644 lib/src/main/java/com/diffplug/spotless/npm/FormattedPrinter.java diff --git a/lib/src/main/java/com/diffplug/spotless/LazyArgLogger.java b/lib/src/main/java/com/diffplug/spotless/LazyArgLogger.java new file mode 100644 index 0000000000..e3456a2317 --- /dev/null +++ b/lib/src/main/java/com/diffplug/spotless/LazyArgLogger.java @@ -0,0 +1,40 @@ +/* + * Copyright 2023 DiffPlug + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.diffplug.spotless; + +import java.util.function.Supplier; + +/** + * This is a utility class to allow for lazy evaluation of arguments to be passed to a logger + * and thus avoid unnecessary computation of the arguments if the log level is not enabled. + */ +public final class LazyArgLogger { + + private final Supplier argSupplier; + + private LazyArgLogger(Supplier argSupplier) { + this.argSupplier = argSupplier; + } + + public static LazyArgLogger lazy(Supplier argSupplier) { + return new LazyArgLogger(argSupplier); + } + + @Override + public String toString() { + return String.valueOf(argSupplier.get()); + } +} diff --git a/lib/src/main/java/com/diffplug/spotless/npm/EslintFormatterStep.java b/lib/src/main/java/com/diffplug/spotless/npm/EslintFormatterStep.java index 221a745ad7..b262bb4b98 100644 --- a/lib/src/main/java/com/diffplug/spotless/npm/EslintFormatterStep.java +++ b/lib/src/main/java/com/diffplug/spotless/npm/EslintFormatterStep.java @@ -15,6 +15,7 @@ */ package com.diffplug.spotless.npm; +import static com.diffplug.spotless.LazyArgLogger.lazy; import static java.util.Objects.requireNonNull; import java.io.File; @@ -115,7 +116,7 @@ protected void prepareNodeServerLayout() throws IOException { // If any config files are provided, we need to make sure they are at the same location as the node modules // as eslint will try to resolve plugin/config names relatively to the config file location and some // eslint configs contain relative paths to additional config files (such as tsconfig.json e.g.) - FormattedPrinter.SYSOUT.print("Copying config file <%s> to <%s> and using the copy", origEslintConfig.getEslintConfigPath(), nodeServerLayout.nodeModulesDir()); + logger.info("Copying config file <{}> to <{}> and using the copy", origEslintConfig.getEslintConfigPath(), nodeServerLayout.nodeModulesDir()); File configFileCopy = NpmResourceHelper.copyFileToDir(origEslintConfig.getEslintConfigPath(), nodeServerLayout.nodeModulesDir()); this.eslintConfigInUse = this.origEslintConfig.withEslintConfigPath(configFileCopy).verify(); } @@ -125,7 +126,7 @@ protected void prepareNodeServerLayout() throws IOException { @Nonnull public FormatterFunc createFormatterFunc() { try { - FormattedPrinter.SYSOUT.print("creating formatter function (starting server)"); + logger.info("Creating formatter function (starting server)"); ServerProcessInfo eslintRestServer = npmRunServer(); EslintRestService restService = new EslintRestService(eslintRestServer.getBaseUrl()); return Closeable.ofDangerous(() -> endServer(restService, eslintRestServer), new EslintFilePathPassingFormatterFunc(locations.projectDir(), nodeServerLayout.nodeModulesDir(), eslintConfigInUse, restService)); @@ -135,7 +136,7 @@ public FormatterFunc createFormatterFunc() { } private void endServer(BaseNpmRestService restService, ServerProcessInfo restServer) throws Exception { - FormattedPrinter.SYSOUT.print("Closing formatting function (ending server)."); + logger.info("Closing formatting function (ending server)."); try { restService.shutdown(); } catch (Throwable t) { @@ -161,7 +162,7 @@ public EslintFilePathPassingFormatterFunc(File projectDir, File nodeModulesDir, @Override public String applyWithFile(String unix, File file) throws Exception { - FormattedPrinter.SYSOUT.print("formatting String '" + unix.substring(0, Math.min(50, unix.length())) + "[...]' in file '" + file + "'"); + logger.info("formatting String '{}[...]' in file '{}'", lazy(() -> unix.substring(0, Math.min(50, unix.length()))), file); Map eslintCallOptions = new HashMap<>(); setConfigToCallOptions(eslintCallOptions); diff --git a/lib/src/main/java/com/diffplug/spotless/npm/FormattedPrinter.java b/lib/src/main/java/com/diffplug/spotless/npm/FormattedPrinter.java deleted file mode 100644 index 97d5cdb4c6..0000000000 --- a/lib/src/main/java/com/diffplug/spotless/npm/FormattedPrinter.java +++ /dev/null @@ -1,42 +0,0 @@ -/* - * Copyright 2020 DiffPlug - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package com.diffplug.spotless.npm; - -import static java.util.Objects.requireNonNull; - -import java.io.PrintStream; -import java.time.LocalDateTime; - -enum FormattedPrinter { - SYSOUT(System.out); - - private static final boolean enabled = false; - - private final PrintStream printStream; - - FormattedPrinter(PrintStream printStream) { - this.printStream = requireNonNull(printStream); - } - - public void print(String msg, Object... paramsForStringFormat) { - if (!enabled) { - return; - } - String formatted = String.format(msg, paramsForStringFormat); - String prefixed = String.format("[%s] %s", LocalDateTime.now().toString(), formatted); - this.printStream.println(prefixed); - } -} diff --git a/lib/src/main/java/com/diffplug/spotless/npm/PrettierFormatterStep.java b/lib/src/main/java/com/diffplug/spotless/npm/PrettierFormatterStep.java index 22f1a69e7c..05c61f9bdf 100644 --- a/lib/src/main/java/com/diffplug/spotless/npm/PrettierFormatterStep.java +++ b/lib/src/main/java/com/diffplug/spotless/npm/PrettierFormatterStep.java @@ -15,6 +15,7 @@ */ package com.diffplug.spotless.npm; +import static com.diffplug.spotless.LazyArgLogger.lazy; import static java.util.Objects.requireNonNull; import java.io.File; @@ -86,7 +87,7 @@ private static class State extends NpmFormatterStepStateBase implements Serializ @Nonnull public FormatterFunc createFormatterFunc() { try { - FormattedPrinter.SYSOUT.print("creating formatter function (starting server)"); + logger.info("creating formatter function (starting server)"); ServerProcessInfo prettierRestServer = npmRunServer(); PrettierRestService restService = new PrettierRestService(prettierRestServer.getBaseUrl()); String prettierConfigOptions = restService.resolveConfig(this.prettierConfig.getPrettierConfigPath(), this.prettierConfig.getOptions()); @@ -97,7 +98,7 @@ public FormatterFunc createFormatterFunc() { } private void endServer(PrettierRestService restService, ServerProcessInfo restServer) throws Exception { - FormattedPrinter.SYSOUT.print("Closing formatting function (ending server)."); + logger.info("Closing formatting function (ending server)."); try { restService.shutdown(); } catch (Throwable t) { @@ -119,7 +120,7 @@ public PrettierFilePathPassingFormatterFunc(String prettierConfigOptions, Pretti @Override public String applyWithFile(String unix, File file) throws Exception { - FormattedPrinter.SYSOUT.print("formatting String '" + unix.substring(0, Math.min(50, unix.length())) + "[...]' in file '" + file + "'"); + logger.info("formatting String '{}[...]' in file '{}'", lazy(() -> unix.substring(0, Math.min(50, unix.length()))), file); final String prettierConfigOptionsWithFilepath = assertFilepathInConfigOptions(file); try { diff --git a/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/PrettierIntegrationTest.java b/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/PrettierIntegrationTest.java index 8819d5bc07..a6b2ea9dc8 100644 --- a/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/PrettierIntegrationTest.java +++ b/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/PrettierIntegrationTest.java @@ -219,8 +219,10 @@ void usePhpAndJavaCommunityPlugin() throws IOException { "}"); setFile("php-example.php").toResource("npm/prettier/plugins/php.dirty"); setFile("JavaTest.java").toResource("npm/prettier/plugins/java-test.dirty"); - final BuildResult spotlessApply = gradleRunner().withArguments("--stacktrace", "spotlessApply").build(); + final BuildResult spotlessApply = gradleRunner().forwardOutput().withArguments("--stacktrace", "--info", "spotlessApply").build(); Assertions.assertThat(spotlessApply.getOutput()).contains("BUILD SUCCESSFUL"); + final BuildResult spotlessApply2 = gradleRunner().forwardOutput().withArguments("--stacktrace", "--info", "spotlessApply").build(); + Assertions.assertThat(spotlessApply2.getOutput()).contains("BUILD SUCCESSFUL"); assertFile("php-example.php").sameAsResource("npm/prettier/plugins/php.clean"); assertFile("JavaTest.java").sameAsResource("npm/prettier/plugins/java-test.clean"); } From 92eb869d8a50a86dacc416b0d49052ccd4137ec5 Mon Sep 17 00:00:00 2001 From: Simon Gamma Date: Thu, 9 Feb 2023 20:54:10 +0100 Subject: [PATCH 751/757] 1162: prepare changelog --- CHANGES.md | 5 ++++- plugin-gradle/CHANGES.md | 3 +++ plugin-maven/CHANGES.md | 3 +++ 3 files changed, 10 insertions(+), 1 deletion(-) diff --git a/CHANGES.md b/CHANGES.md index 5f1a1ffa9f..0e2e994a22 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -10,7 +10,10 @@ This document is intended for Spotless developers. We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format (starting after version `1.27.0`). ## [Unreleased] - +### Added +* Introduce `LazyArgLogger` to allow for lazy evaluation of log messages in slf4j logging. ([#1565](https://github.com/diffplug/spotless/pull/1565)) +### Fixed +* Allow multiple instances of the same npm-based formatter to be used by separating their `node_modules` directories. ([#1565](https://github.com/diffplug/spotless/pull/1565)) ## [2.34.1] - 2023-02-05 ### Changes * **POTENTIALLY BREAKING** Bump bytecode from Java 8 to 11 ([#1530](https://github.com/diffplug/spotless/pull/1530) part 2 of [#1337](https://github.com/diffplug/spotless/issues/1337)) diff --git a/plugin-gradle/CHANGES.md b/plugin-gradle/CHANGES.md index e3234584b8..ec5ae54c27 100644 --- a/plugin-gradle/CHANGES.md +++ b/plugin-gradle/CHANGES.md @@ -3,6 +3,9 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format (starting after version `3.27.0`). ## [Unreleased] +### Fixed +* Allow multiple instances of the same npm-based formatter to be used simultaneously. E.g. use prettier for typescript + *and* Java (using the community prettier-plugin-java) without messing up their respective `node_module` dependencies. ([#1565](https://github.com/diffplug/spotless/pull/1565)) ## [6.14.1] - 2023-02-05 ### Fixed diff --git a/plugin-maven/CHANGES.md b/plugin-maven/CHANGES.md index 567d880f4f..cce049488a 100644 --- a/plugin-maven/CHANGES.md +++ b/plugin-maven/CHANGES.md @@ -3,6 +3,9 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format (starting after version `1.27.0`). ## [Unreleased] +### Fixed +* Allow multiple instances of the same npm-based formatter to be used simultaneously. E.g. use prettier for typescript + *and* Java (using the community prettier-plugin-java) without messing up their respective `node_module` dependencies. ([#1565](https://github.com/diffplug/spotless/pull/1565)) ## [2.32.0] - 2023-02-05 ### Added From 4cb02f30d815992dc23ef9dc8f4e20bd9b9c3147 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lars=20L=C3=B8nne?= Date: Fri, 10 Feb 2023 12:59:00 +0100 Subject: [PATCH 752/757] runs spotlessApply and removes an unused import --- .../test/java/com/diffplug/spotless/maven/kotlin/KtfmtTest.java | 2 -- 1 file changed, 2 deletions(-) diff --git a/plugin-maven/src/test/java/com/diffplug/spotless/maven/kotlin/KtfmtTest.java b/plugin-maven/src/test/java/com/diffplug/spotless/maven/kotlin/KtfmtTest.java index 25ecbc598d..e452c5d56b 100644 --- a/plugin-maven/src/test/java/com/diffplug/spotless/maven/kotlin/KtfmtTest.java +++ b/plugin-maven/src/test/java/com/diffplug/spotless/maven/kotlin/KtfmtTest.java @@ -19,8 +19,6 @@ import com.diffplug.spotless.maven.MavenIntegrationHarness; -import java.io.IOException; - class KtfmtTest extends MavenIntegrationHarness { @Test void testKtfmt() throws Exception { From 2204510cec06405430325d7f41a0abb93a90f0f8 Mon Sep 17 00:00:00 2001 From: Ned Twigg Date: Fri, 10 Feb 2023 10:05:05 -0800 Subject: [PATCH 753/757] Update default KtFmtStep version to 0.43 --- lib/src/main/java/com/diffplug/spotless/kotlin/KtfmtStep.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 b6f7a533eb..d6a20bc5b3 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.42"; + private static final String DEFAULT_VERSION = "0.43"; static final String NAME = "ktfmt"; static final String PACKAGE = "com.facebook"; static final String MAVEN_COORDINATE = PACKAGE + ":ktfmt:"; From 4fac2e978c36e1688784cf44541853731aa240b9 Mon Sep 17 00:00:00 2001 From: Ned Twigg Date: Fri, 10 Feb 2023 10:10:13 -0800 Subject: [PATCH 754/757] Bump default version of jackston steps 2.14.1 -> 2.14.2 --- lib/build.gradle | 2 +- .../main/java/com/diffplug/spotless/json/JacksonJsonStep.java | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/build.gradle b/lib/build.gradle index fa80767047..81a6229f35 100644 --- a/lib/build.gradle +++ b/lib/build.gradle @@ -63,7 +63,7 @@ dependencies { // used jackson-based formatters jacksonCompileOnly 'com.fasterxml.jackson.core:jackson-databind:2.14.2' - jacksonCompileOnly 'com.fasterxml.jackson.dataformat:jackson-dataformat-yaml:2.14.1' + jacksonCompileOnly 'com.fasterxml.jackson.dataformat:jackson-dataformat-yaml:2.14.2' String VER_KTFMT = '0.42' ktfmtCompileOnly "com.facebook:ktfmt:$VER_KTFMT" diff --git a/lib/src/main/java/com/diffplug/spotless/json/JacksonJsonStep.java b/lib/src/main/java/com/diffplug/spotless/json/JacksonJsonStep.java index f15edbbd42..94c48e0c5c 100644 --- a/lib/src/main/java/com/diffplug/spotless/json/JacksonJsonStep.java +++ b/lib/src/main/java/com/diffplug/spotless/json/JacksonJsonStep.java @@ -33,7 +33,7 @@ public class JacksonJsonStep { static final String MAVEN_COORDINATE = "com.fasterxml.jackson.core:jackson-databind:"; // https://mvnrepository.com/artifact/com.fasterxml.jackson.core/jackson-databind - static final String DEFAULT_VERSION = "2.14.1"; + static final String DEFAULT_VERSION = "2.14.2"; private JacksonJsonStep() {} From 4f92a676b191aa109fb09d5f29c522e6ddf27810 Mon Sep 17 00:00:00 2001 From: Ned Twigg Date: Fri, 10 Feb 2023 10:22:37 -0800 Subject: [PATCH 755/757] Update changelogs. --- CHANGES.md | 2 ++ plugin-gradle/CHANGES.md | 2 ++ plugin-maven/CHANGES.md | 2 ++ 3 files changed, 6 insertions(+) diff --git a/CHANGES.md b/CHANGES.md index 7c96483595..4909423395 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -16,6 +16,8 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format ( ### Fixed * Allow multiple instances of the same npm-based formatter to be used by separating their `node_modules` directories. ([#1565](https://github.com/diffplug/spotless/pull/1565)) * `ktfmt` default style uses correct continuation indent. ([#1562](https://github.com/diffplug/spotless/pull/1562)) +### Changes +* Bump default `ktfmt` version to latest `0.42` -> `0.43` ([#1561](https://github.com/diffplug/spotless/pull/1561)) ## [2.34.1] - 2023-02-05 ### Changes diff --git a/plugin-gradle/CHANGES.md b/plugin-gradle/CHANGES.md index 5148a11e10..8cba44831d 100644 --- a/plugin-gradle/CHANGES.md +++ b/plugin-gradle/CHANGES.md @@ -9,6 +9,8 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format ( * Allow multiple instances of the same npm-based formatter to be used simultaneously. E.g. use prettier for typescript *and* Java (using the community prettier-plugin-java) without messing up their respective `node_module` dependencies. ([#1565](https://github.com/diffplug/spotless/pull/1565)) * `ktfmt` default style uses correct continuation indent. ([#1562](https://github.com/diffplug/spotless/pull/1562)) +### Changes +* Bump default `ktfmt` version to latest `0.42` -> `0.43` ([#1561](https://github.com/diffplug/spotless/pull/1561)) ## [6.14.1] - 2023-02-05 ### Fixed diff --git a/plugin-maven/CHANGES.md b/plugin-maven/CHANGES.md index 8600825903..035520076d 100644 --- a/plugin-maven/CHANGES.md +++ b/plugin-maven/CHANGES.md @@ -9,6 +9,8 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format ( * Allow multiple instances of the same npm-based formatter to be used simultaneously. E.g. use prettier for typescript *and* Java (using the community prettier-plugin-java) without messing up their respective `node_module` dependencies. ([#1565](https://github.com/diffplug/spotless/pull/1565)) * `ktfmt` default style uses correct continuation indent. ([#1562](https://github.com/diffplug/spotless/pull/1562)) +### Changes +* Bump default `ktfmt` version to latest `0.42` -> `0.43` ([#1561](https://github.com/diffplug/spotless/pull/1561)) ## [2.32.0] - 2023-02-05 ### Added From c2979127467ee7abd976d3503779d9f4a1c2637c Mon Sep 17 00:00:00 2001 From: Ned Twigg Date: Fri, 10 Feb 2023 10:28:58 -0800 Subject: [PATCH 756/757] Bump changelogs. --- CHANGES.md | 1 + plugin-gradle/CHANGES.md | 1 + plugin-maven/CHANGES.md | 1 + 3 files changed, 3 insertions(+) diff --git a/CHANGES.md b/CHANGES.md index 4909423395..b59568d1d4 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -18,6 +18,7 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format ( * `ktfmt` default style uses correct continuation indent. ([#1562](https://github.com/diffplug/spotless/pull/1562)) ### Changes * Bump default `ktfmt` version to latest `0.42` -> `0.43` ([#1561](https://github.com/diffplug/spotless/pull/1561)) +* Bump default `jackson` version to latest `2.14.1` -> `2.14.2` ([#1536](https://github.com/diffplug/spotless/pull/1536)) ## [2.34.1] - 2023-02-05 ### Changes diff --git a/plugin-gradle/CHANGES.md b/plugin-gradle/CHANGES.md index 8cba44831d..10b2adaac7 100644 --- a/plugin-gradle/CHANGES.md +++ b/plugin-gradle/CHANGES.md @@ -11,6 +11,7 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format ( * `ktfmt` default style uses correct continuation indent. ([#1562](https://github.com/diffplug/spotless/pull/1562)) ### Changes * Bump default `ktfmt` version to latest `0.42` -> `0.43` ([#1561](https://github.com/diffplug/spotless/pull/1561)) +* Bump default `jackson` version to latest `2.14.1` -> `2.14.2` ([#1536](https://github.com/diffplug/spotless/pull/1536)) ## [6.14.1] - 2023-02-05 ### Fixed diff --git a/plugin-maven/CHANGES.md b/plugin-maven/CHANGES.md index 035520076d..6de9a15d5e 100644 --- a/plugin-maven/CHANGES.md +++ b/plugin-maven/CHANGES.md @@ -11,6 +11,7 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format ( * `ktfmt` default style uses correct continuation indent. ([#1562](https://github.com/diffplug/spotless/pull/1562)) ### Changes * Bump default `ktfmt` version to latest `0.42` -> `0.43` ([#1561](https://github.com/diffplug/spotless/pull/1561)) +* Bump default `jackson` version to latest `2.14.1` -> `2.14.2` ([#1536](https://github.com/diffplug/spotless/pull/1536)) ## [2.32.0] - 2023-02-05 ### Added From c04253f80b7f8dfa9bdfafde9f7272e88c6db6ad Mon Sep 17 00:00:00 2001 From: runner Date: Fri, 10 Feb 2023 18:43:54 +0000 Subject: [PATCH 757/757] Published lib/2.35.0 --- CHANGES.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/CHANGES.md b/CHANGES.md index b59568d1d4..eec8753271 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -10,6 +10,8 @@ This document is intended for Spotless developers. We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format (starting after version `1.27.0`). ## [Unreleased] + +## [2.35.0] - 2023-02-10 ### Added * CleanThat Java Refactorer. ([#1560](https://github.com/diffplug/spotless/pull/1560)) * Introduce `LazyArgLogger` to allow for lazy evaluation of log messages in slf4j logging. ([#1565](https://github.com/diffplug/spotless/pull/1565)) pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy