Skip to content

Commit 4e04186

Browse files
authored
Merge branch 'main' into flexmark-java
2 parents cc2a628 + 6a9bc8d commit 4e04186

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

41 files changed

+510
-188
lines changed

.circleci/config.yml

+11-10
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,15 @@ anchors:
4242
path: lib-extra/build/test-results/test
4343
- store_test_results:
4444
path: plugin-gradle/build/test-results/test
45+
- store_artifacts:
46+
path: lib/build/spotbugs
47+
- store_artifacts:
48+
path: lib-extra/build/spotbugs
49+
- store_artifacts:
50+
path: testlib/build/spotbugs
51+
- store_artifacts:
52+
path: plugin-gradle/build/spotbugs
53+
4554
jobs:
4655
# gradlew spotlessCheck assemble testClasses
4756
assemble_testClasses:
@@ -108,22 +117,14 @@ jobs:
108117
- store_test_results:
109118
path: plugin-gradle/build/test-results/NpmTest
110119
- run:
111-
name: gradlew check
112-
command: export SPOTLESS_EXCLUDE_MAVEN=true && ./gradlew check --build-cache
120+
name: gradlew test
121+
command: export SPOTLESS_EXCLUDE_MAVEN=true && ./gradlew test --build-cache
113122
- store_test_results:
114123
path: testlib/build/test-results/test
115124
- store_test_results:
116125
path: lib-extra/build/test-results/test
117126
- store_test_results:
118127
path: plugin-gradle/build/test-results/test
119-
- store_artifacts:
120-
path: lib/build/spotbugs
121-
- store_artifacts:
122-
path: lib-extra/build/spotbugs
123-
- store_artifacts:
124-
path: testlib/build/spotbugs
125-
- store_artifacts:
126-
path: plugin-gradle/build/spotbugs
127128
test_windows:
128129
executor:
129130
name: win/default

CHANGES.md

+8
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,15 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format (
1111

1212
## [Unreleased]
1313

14+
## [2.20.2] - 2021-12-05
1415
### Changed
16+
* Bumped default ktlint from `0.43.0` to `0.43.2`.
17+
* Converted `ktlint` integration to use a compile-only source set. ([#524](https://github.com/diffplug/spotless/issues/524))
18+
19+
## [2.20.1] - 2021-12-01
20+
### Changed
21+
* Added `named` option to `licenseHeader` to support alternate license header within same format (like java) ([872](https://github.com/diffplug/spotless/issues/872)).
22+
* Added `onlyIfContentMatches` option to `licenseHeader` to skip license header application based on source file content pattern ([#650](https://github.com/diffplug/spotless/issues/650)).
1523
* Bump jgit version ([#992](https://github.com/diffplug/spotless/pull/992)).
1624
* jgit `5.10.0.202012080955-r` -> `5.13.0.202109080827-r`
1725

CONTRIBUTING.md

+1-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Contributing to Spotless
22

3-
Pull requests are welcome, preferably against `main`. Feel free to develop spotless any way you like, but the easiest way to look at the code is to clone the repo and run `gradlew ide`, which will download, setup, and start an Eclipse IDE for you.
3+
Pull requests are welcome, preferably against `main`. Feel free to develop spotless any way you like.
44

55
## How Spotless works
66

@@ -36,7 +36,6 @@ For the folders below in monospace text, they are published on maven central at
3636
| `lib-extra` | Contains the optional parts of Spotless which require external dependencies. `LineEnding.GIT_ATTRIBUTES` won't work unless `lib-extra` is available. |
3737
| `plugin-gradle` | Integrates spotless and all of its formatters into Gradle. |
3838
| `plugin-maven` | Integrates spotless and all of its formatters into Maven. |
39-
| ide | Generates and launches an IDE for developing spotless. |
4039
| _ext | Folder for generating glue jars (specifically packaging Eclipse jars from p2 for consumption using maven).
4140

4241
## How to add a new FormatterStep

_ext/eclipse-cdt/CHANGES.md

+4
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,10 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format (
44

55
## [Unreleased]
66

7+
## [10.5.0] - 2021-12-10
8+
### Added
9+
* Switch to Eclipse CDT release 10.5 for Eclipse 2021-12.
10+
711
## [10.4.0] - 2021-09-23
812
### Added
913
* Switch to Eclipse CDT release 10.4 for Eclipse 4.21.

_ext/eclipse-cdt/gradle.properties

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ description=Eclipse's CDT C/C++ formatter bundled for Spotless
55
VER_JAVA=11
66

77
# Compile dependencies
8-
VER_ECLIPSE_CDT=10.4
8+
VER_ECLIPSE_CDT=10.5
99
VER_SPOTLESS_ECLISPE_BASE=[3.5.0,4.0.0[
1010
VER_ECLISPE_JFACE=[3.18.0,4.0.0[
1111
VER_ECLISPE_EFS=[3.7.0,4.0.0[

build.gradle

+3-5
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,13 @@
1-
buildscript {
2-
repositories {
3-
mavenCentral()
4-
}
5-
}
61
apply from: rootProject.file('gradle/java-publish.gradle')
72
apply from: rootProject.file('gradle/changelog.gradle')
83
allprojects {
94
apply from: rootProject.file('gradle/spotless.gradle')
105
}
116
apply from: rootProject.file('gradle/spotless-freshmark.gradle')
127

8+
repositories {
9+
mavenCentral()
10+
}
1311
spotless {
1412
groovyGradle {
1513
target '*.gradle', 'gradle/*.gradle'

gradle.properties

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ artifactIdGradle=spotless-plugin-gradle
1515

1616
# Build requirements
1717
VER_JAVA=1.8
18-
VER_SPOTBUGS=4.0.2
18+
VER_SPOTBUGS=4.5.0
1919

2020
# Dependencies provided by Spotless plugin
2121
VER_SLF4J=[1.6,2.0[

gradle/java-publish.gradle

+5
Original file line numberDiff line numberDiff line change
@@ -182,3 +182,8 @@ if (!version.endsWith('-SNAPSHOT')) {
182182
}
183183
}
184184
}
185+
186+
tasks.withType(AbstractArchiveTask).configureEach {
187+
preserveFileTimestamps = false
188+
reproducibleFileOrder = true
189+
}

gradle/java-setup.gradle

+3-2
Original file line numberDiff line numberDiff line change
@@ -19,14 +19,15 @@ spotbugs {
1919
ignoreFailures = false // bug free or it doesn't ship!
2020
reportsDir = file('build/spotbugs')
2121
reportLevel = 'medium' // low|medium|high (low = sensitive to even minor mistakes)
22-
omitVisitors = [] // bugs that we want to ignore
22+
omitVisitors = [
23+
'FindReturnRef'] // https://spotbugs.readthedocs.io/en/latest/detectors.html#findreturnref
2324
}
2425
tasks.named('spotbugsTest') {
2526
enabled = false
2627
}
2728
tasks.named('spotbugsMain') {
2829
// only run on Java 8 (no benefit to running twice)
29-
enabled = org.gradle.api.JavaVersion.current() == org.gradle.api.JavaVersion.VERSION_1_8
30+
enabled = org.gradle.api.JavaVersion.current() == org.gradle.api.JavaVersion.VERSION_11
3031
reports {
3132
html.enabled = true
3233
}

gradle/special-tests.gradle

+2-2
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@ tasks.named('test') {
1414
}
1515
if (isCiServer) {
1616
retry {
17-
maxRetries = 1
18-
maxFailures = 2
17+
maxRetries = 2
18+
maxFailures = 10
1919
}
2020
}
2121
}

gradle/wrapper/gradle-wrapper.jar

509 Bytes
Binary file not shown.
+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
distributionBase=GRADLE_USER_HOME
22
distributionPath=wrapper/dists
3-
distributionUrl=https\://services.gradle.org/distributions/gradle-6.6-bin.zip
3+
distributionUrl=https\://services.gradle.org/distributions/gradle-7.3-bin.zip
44
zipStoreBase=GRADLE_USER_HOME
55
zipStorePath=wrapper/dists

gradlew

+2
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,7 @@ esac
8282

8383
CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
8484

85+
8586
# Determine the Java command to use to start the JVM.
8687
if [ -n "$JAVA_HOME" ] ; then
8788
if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
@@ -129,6 +130,7 @@ fi
129130
if [ "$cygwin" = "true" -o "$msys" = "true" ] ; then
130131
APP_HOME=`cygpath --path --mixed "$APP_HOME"`
131132
CLASSPATH=`cygpath --path --mixed "$CLASSPATH"`
133+
132134
JAVACMD=`cygpath --unix "$JAVACMD"`
133135

134136
# We build the pattern for arguments to be converted via cygpath

gradlew.bat

+4-18
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ if defined JAVA_HOME goto findJavaFromJavaHome
4040

4141
set JAVA_EXE=java.exe
4242
%JAVA_EXE% -version >NUL 2>&1
43-
if "%ERRORLEVEL%" == "0" goto init
43+
if "%ERRORLEVEL%" == "0" goto execute
4444

4545
echo.
4646
echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
@@ -54,7 +54,7 @@ goto fail
5454
set JAVA_HOME=%JAVA_HOME:"=%
5555
set JAVA_EXE=%JAVA_HOME%/bin/java.exe
5656

57-
if exist "%JAVA_EXE%" goto init
57+
if exist "%JAVA_EXE%" goto execute
5858

5959
echo.
6060
echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
@@ -64,28 +64,14 @@ echo location of your Java installation.
6464

6565
goto fail
6666

67-
:init
68-
@rem Get command-line arguments, handling Windows variants
69-
70-
if not "%OS%" == "Windows_NT" goto win9xME_args
71-
72-
:win9xME_args
73-
@rem Slurp the command line arguments.
74-
set CMD_LINE_ARGS=
75-
set _SKIP=2
76-
77-
:win9xME_args_slurp
78-
if "x%~1" == "x" goto execute
79-
80-
set CMD_LINE_ARGS=%*
81-
8267
:execute
8368
@rem Setup the command line
8469

8570
set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
8671

72+
8773
@rem Execute Gradle
88-
"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS%
74+
"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %*
8975

9076
:end
9177
@rem End local scope for the variables with windows NT shell

lib-extra/src/main/java/com/diffplug/spotless/extra/GitRatchet.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,7 @@ protected Repository repositoryFor(Project project) throws IOException {
169169

170170
protected abstract @Nullable Project getParent(Project project);
171171

172-
private static @Nullable Repository traverseParentsUntil(File startWith, File file) throws IOException {
172+
private static @Nullable Repository traverseParentsUntil(File startWith, @Nullable File file) throws IOException {
173173
while (startWith != null && !Objects.equals(startWith, file)) {
174174
if (isGitRoot(startWith)) {
175175
return createRepo(startWith);

lib/build.gradle

+11-5
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@ apply from: rootProject.file('gradle/java-publish.gradle')
88

99
def NEEDS_GLUE = [
1010
'sortPom',
11-
'flexmark'
11+
'ktlint',
12+
'flexmark'
1213
]
1314
for (glue in NEEDS_GLUE) {
1415
sourceSets.register(glue) {
@@ -21,14 +22,19 @@ for (glue in NEEDS_GLUE) {
2122
dependencies {
2223
// zero runtime reqs is a hard requirements for spotless-lib
2324
// if you need a dep, put it in lib-extra
24-
testImplementation "org.junit.jupiter:junit-jupiter:${VER_JUNIT}"
25-
testImplementation "org.assertj:assertj-core:${VER_ASSERTJ}"
26-
testImplementation "com.diffplug.durian:durian-testlib:${VER_DURIAN}"
25+
testImplementation "org.junit.jupiter:junit-jupiter:$VER_JUNIT"
26+
testImplementation "org.assertj:assertj-core:$VER_ASSERTJ"
27+
testImplementation "com.diffplug.durian:durian-testlib:$VER_DURIAN"
2728

2829
// used for pom sorting
2930
sortPomCompileOnly 'com.github.ekryd.sortpom:sortpom-sorter:3.0.0'
3031

31-
// used for markdown formatting
32+
String VER_KTLINT='0.43.2'
33+
ktlintCompileOnly "com.pinterest:ktlint:$VER_KTLINT"
34+
ktlintCompileOnly "com.pinterest.ktlint:ktlint-core:$VER_KTLINT"
35+
ktlintCompileOnly "com.pinterest.ktlint:ktlint-ruleset-standard:$VER_KTLINT"
36+
37+
// used for markdown formatting
3238
flexmarkCompileOnly 'com.vladsch.flexmark:flexmark-all:0.62.2'
3339
}
3440

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
/*
2+
* Copyright 2021 DiffPlug
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
package com.diffplug.spotless.glue.ktlint;
17+
18+
import java.io.File;
19+
import java.util.Collections;
20+
import java.util.List;
21+
import java.util.Map;
22+
import java.util.logging.Logger;
23+
24+
import com.pinterest.ktlint.core.KtLint;
25+
import com.pinterest.ktlint.core.KtLint.Params;
26+
import com.pinterest.ktlint.core.LintError;
27+
import com.pinterest.ktlint.core.RuleSet;
28+
import com.pinterest.ktlint.ruleset.standard.StandardRuleSetProvider;
29+
30+
import com.diffplug.spotless.FormatterFunc;
31+
32+
import kotlin.Unit;
33+
import kotlin.jvm.functions.Function2;
34+
35+
public class KtlintFormatterFunc implements FormatterFunc.NeedsFile {
36+
private static final Logger logger = Logger.getLogger(KtlintFormatterFunc.class.getName());
37+
38+
private final List<RuleSet> rulesets;
39+
private final Map<String, String> userData;
40+
private final Function2<? super LintError, ? super Boolean, Unit> formatterCallback;
41+
private final boolean isScript;
42+
43+
public KtlintFormatterFunc(boolean isScript, Map<String, String> userData) {
44+
rulesets = Collections.singletonList(new StandardRuleSetProvider().get());
45+
this.userData = userData;
46+
formatterCallback = new FormatterCallback();
47+
this.isScript = isScript;
48+
}
49+
50+
static class FormatterCallback implements Function2<LintError, Boolean, Unit> {
51+
@Override
52+
public Unit invoke(LintError lint, Boolean corrected) {
53+
if (!corrected) {
54+
throw new AssertionError("Error on line: " + lint.getLine() + ", column: " + lint.getCol() + "\n" + lint.getDetail());
55+
}
56+
return null;
57+
}
58+
}
59+
60+
@Override
61+
public String applyWithFile(String unix, File file) throws Exception {
62+
return KtLint.INSTANCE.format(new Params(
63+
file.getName(),
64+
unix,
65+
rulesets,
66+
userData,
67+
formatterCallback,
68+
isScript,
69+
null,
70+
false));
71+
}
72+
}

0 commit comments

Comments
 (0)