Skip to content

Commit 5a04060

Browse files
committed
Merge branch 'main' into renovate/com.fasterxml.jackson.core-jackson-databind-2.x
2 parents 4fac2e9 + 4ed7074 commit 5a04060

File tree

80 files changed

+1416
-196
lines changed

Some content is hidden

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

80 files changed

+1416
-196
lines changed

CHANGES.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,19 @@ This document is intended for Spotless developers.
1010
We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format (starting after version `1.27.0`).
1111

1212
## [Unreleased]
13+
### Added
14+
* CleanThat Java Refactorer. ([#1560](https://github.com/diffplug/spotless/pull/1560))
15+
* Introduce `LazyArgLogger` to allow for lazy evaluation of log messages in slf4j logging. ([#1565](https://github.com/diffplug/spotless/pull/1565))
16+
### Fixed
17+
* 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))
18+
* `ktfmt` default style uses correct continuation indent. ([#1562](https://github.com/diffplug/spotless/pull/1562))
19+
20+
## [2.34.1] - 2023-02-05
1321
### Changes
1422
* **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))
23+
### Fixed
24+
* **POTENTIALLY BREAKING** `sortByKeys` for JSON formatting now takes into account objects inside arrays ([#1546](https://github.com/diffplug/spotless/pull/1546))
25+
* `freshmark` fixed on java 15+ ([#1304](https://github.com/diffplug/spotless/pull/1304) fixes [#803](https://github.com/diffplug/spotless/issues/803))
1526

1627
## [2.34.0] - 2023-01-26
1728
### Added

CONTRIBUTING.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -207,7 +207,7 @@ If it doesn't work, you can check the JitPack log at `https://jitpack.io/com/git
207207

208208
### Maven
209209

210-
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).
210+
Run `./gradlew publishToMavenLocal` to publish this to your local repository. You can also use the JitPack artifacts, using the same principles as Gradle above.
211211

212212
## License
213213

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,7 @@ lib('java.PalantirJavaFormatStep') +'{{yes}} | {{yes}}
8484
lib('java.RemoveUnusedImportsStep') +'{{yes}} | {{yes}} | {{yes}} | {{no}} |',
8585
extra('java.EclipseJdtFormatterStep') +'{{yes}} | {{yes}} | {{yes}} | {{no}} |',
8686
lib('java.FormatAnnotationsStep') +'{{yes}} | {{yes}} | {{no}} | {{no}} |',
87+
lib('java.CleanthatJavaStep') +'{{yes}} | {{yes}} | {{no}} | {{no}} |',
8788
lib('json.gson.GsonStep') +'{{yes}} | {{yes}} | {{no}} | {{no}} |',
8889
lib('json.JacksonJsonStep') +'{{yes}} | {{yes}} | {{no}} | {{no}} |',
8990
lib('json.JsonSimpleStep') +'{{yes}} | {{yes}} | {{no}} | {{no}} |',
@@ -131,6 +132,7 @@ lib('yaml.JacksonYamlStep') +'{{yes}} | {{yes}}
131132
| [`java.RemoveUnusedImportsStep`](lib/src/main/java/com/diffplug/spotless/java/RemoveUnusedImportsStep.java) | :+1: | :+1: | :+1: | :white_large_square: |
132133
| [`java.EclipseJdtFormatterStep`](lib-extra/src/main/java/com/diffplug/spotless/extra/java/EclipseJdtFormatterStep.java) | :+1: | :+1: | :+1: | :white_large_square: |
133134
| [`java.FormatAnnotationsStep`](lib/src/main/java/com/diffplug/spotless/java/FormatAnnotationsStep.java) | :+1: | :+1: | :white_large_square: | :white_large_square: |
135+
| [`java.CleanthatJavaStep`](lib/src/main/java/com/diffplug/spotless/java/CleanthatJavaStep.java) | :+1: | :+1: | :white_large_square: | :white_large_square: |
134136
| [`json.gson.GsonStep`](lib/src/main/java/com/diffplug/spotless/json/gson/GsonStep.java) | :+1: | :+1: | :white_large_square: | :white_large_square: |
135137
| [`json.JacksonJsonStep`](lib/src/main/java/com/diffplug/spotless/json/JacksonJsonStep.java) | :+1: | :+1: | :white_large_square: | :white_large_square: |
136138
| [`json.JsonSimpleStep`](lib/src/main/java/com/diffplug/spotless/json/JsonSimpleStep.java) | :+1: | :+1: | :white_large_square: | :white_large_square: |

gradle.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,4 +28,4 @@ VER_DURIAN=1.2.0
2828
VER_JGIT=6.4.0.202211300538-r
2929
VER_JUNIT=5.9.2
3030
VER_ASSERTJ=3.24.2
31-
VER_MOCKITO=5.0.0
31+
VER_MOCKITO=5.1.1

gradle/java-publish.gradle

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,11 @@ model {
170170
}
171171
}
172172

173-
if (!version.endsWith('-SNAPSHOT')) {
173+
if (System.env['JITPACK'] == 'true' || version.endsWith('-SNAPSHOT')) {
174+
signing {
175+
setRequired(false)
176+
}
177+
} else {
174178
signing {
175179
String gpg_key = decode64('ORG_GRADLE_PROJECT_gpg_key64')
176180
useInMemoryPgpKeys(gpg_key, System.env['ORG_GRADLE_PROJECT_gpg_passphrase'])

gradle/spotless-freshmark.gradle

Lines changed: 0 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,4 @@
11

2-
import java.util.regex.Matcher
3-
import java.util.regex.Pattern
4-
5-
6-
def thisVm() {
7-
String jre = System.getProperty("java.version")
8-
if (jre.startsWith("1.8")) {
9-
return 8
10-
} else {
11-
Matcher matcher = Pattern.compile("(\\d+)").matcher(jre)
12-
if (!matcher.find()) {
13-
throw new IllegalArgumentException("Expected " + jre + " to start with an integer")
14-
}
15-
int version = Integer.parseInt(matcher.group(1))
16-
if (version <= 8) {
17-
throw new IllegalArgumentException("Expected " + jre + " to start with an integer greater than 8")
18-
}
19-
return version
20-
}
21-
}
22-
23-
if (thisVm() >= 15) {
24-
// freshmark doesn't run on JRE 15+
25-
return
26-
}
27-
282
apply plugin: 'com.diffplug.spotless'
293

304
import com.diffplug.gradle.spotless.FreshMarkExtension

jitpack.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
jdk:
2+
- openjdk11

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

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2016-2022 DiffPlug
2+
* Copyright 2016-2023 DiffPlug
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -42,6 +42,8 @@
4242
import org.eclipse.jgit.storage.file.FileBasedConfig;
4343
import org.eclipse.jgit.util.FS;
4444
import org.eclipse.jgit.util.SystemReader;
45+
import org.slf4j.Logger;
46+
import org.slf4j.LoggerFactory;
4547

4648
import com.googlecode.concurrenttrees.radix.ConcurrentRadixTree;
4749
import com.googlecode.concurrenttrees.radix.node.concrete.DefaultCharSequenceNodeFactory;
@@ -61,6 +63,8 @@
6163
* back to the platform native.
6264
*/
6365
public final class GitAttributesLineEndings {
66+
private static final Logger LOGGER = LoggerFactory.getLogger(GitAttributesLineEndings.class);
67+
6468
// prevent direct instantiation
6569
private GitAttributesLineEndings() {}
6670

@@ -261,7 +265,7 @@ private static String convertEolToLineEnding(String eol, File file) {
261265
case "crlf":
262266
return LineEnding.WINDOWS.str();
263267
default:
264-
System.err.println(".gitattributes file has unspecified eol value: " + eol + " for " + file + ", defaulting to platform native");
268+
LOGGER.warn(".gitattributes file has unspecified eol value: {} for {}, defaulting to platform native", eol, file);
265269
return LineEnding.PLATFORM_NATIVE.str();
266270
}
267271
}
@@ -341,8 +345,7 @@ private static List<AttributesRule> parseRules(@Nullable File file) {
341345
return parsed.getRules();
342346
} catch (IOException e) {
343347
// no need to crash the whole plugin
344-
System.err.println("Problem parsing " + file.getAbsolutePath());
345-
e.printStackTrace();
348+
LOGGER.warn("Problem parsing {}", file.getAbsolutePath(), e);
346349
}
347350
}
348351
return Collections.emptyList();

lib/build.gradle

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,8 @@ def NEEDS_GLUE = [
1616
'diktat',
1717
'scalafmt',
1818
'jackson',
19-
'gson'
19+
'gson',
20+
'cleanthat'
2021
]
2122
for (glue in NEEDS_GLUE) {
2223
sourceSets.register(glue) {
@@ -39,6 +40,12 @@ versionCompatibility {
3940
]
4041
targetSourceSetName = 'ktlint'
4142
}
43+
namespaces.register('Cleanthat') {
44+
versions = [
45+
'2.1',
46+
]
47+
targetSourceSetName = 'cleanthat'
48+
}
4249
}
4350
}
4451

@@ -100,6 +107,9 @@ dependencies {
100107
flexmarkCompileOnly 'com.vladsch.flexmark:flexmark-all:0.62.2'
101108

102109
gsonCompileOnly 'com.google.code.gson:gson:2.10.1'
110+
111+
cleanthatCompileOnly 'io.github.solven-eu.cleanthat:java:2.1'
112+
compatCleanthat2Dot1CompileAndTestOnly 'io.github.solven-eu.cleanthat:java:2.1'
103113
}
104114

105115
// we'll hold the core lib to a high standard
Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
/*
2+
* Copyright 2023 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.java;
17+
18+
import java.io.IOException;
19+
import java.util.Arrays;
20+
import java.util.Collections;
21+
import java.util.List;
22+
23+
import org.slf4j.Logger;
24+
import org.slf4j.LoggerFactory;
25+
26+
import com.diffplug.spotless.FormatterFunc;
27+
28+
import eu.solven.cleanthat.config.pojo.CleanthatEngineProperties;
29+
import eu.solven.cleanthat.config.pojo.SourceCodeProperties;
30+
import eu.solven.cleanthat.engine.java.IJdkVersionConstants;
31+
import eu.solven.cleanthat.engine.java.refactorer.JavaRefactorer;
32+
import eu.solven.cleanthat.engine.java.refactorer.JavaRefactorerProperties;
33+
import eu.solven.cleanthat.formatter.LineEnding;
34+
35+
/**
36+
* The glue for CleanThat: it is build over the version in build.gradle, but at runtime it will be executed over
37+
* the version loaded in JarState, which is by default defined in com.diffplug.spotless.java.CleanthatJavaStep#JVM_SUPPORT
38+
*/
39+
public class JavaCleanthatRefactorerFunc implements FormatterFunc {
40+
private static final Logger LOGGER = LoggerFactory.getLogger(JavaCleanthatRefactorerFunc.class);
41+
42+
private String jdkVersion;
43+
private List<String> included;
44+
private List<String> excluded;
45+
46+
public JavaCleanthatRefactorerFunc(String jdkVersion, List<String> included, List<String> excluded) {
47+
this.jdkVersion = jdkVersion == null ? IJdkVersionConstants.JDK_8 : jdkVersion;
48+
this.included = included == null ? Collections.emptyList() : included;
49+
this.excluded = excluded == null ? Collections.emptyList() : excluded;
50+
}
51+
52+
public JavaCleanthatRefactorerFunc() {
53+
this(IJdkVersionConstants.JDK_8, Arrays.asList(JavaRefactorerProperties.WILDCARD), Arrays.asList());
54+
}
55+
56+
@Override
57+
public String apply(String input) throws Exception {
58+
// https://stackoverflow.com/questions/1771679/difference-between-threads-context-class-loader-and-normal-classloader
59+
ClassLoader originalClassLoader = Thread.currentThread().getContextClassLoader();
60+
try {
61+
// Ensure CleanThat main Thread has its custom classLoader while executing its refactoring
62+
Thread.currentThread().setContextClassLoader(getClass().getClassLoader());
63+
return doApply(input);
64+
} finally {
65+
// Restore the originalClassLoader
66+
Thread.currentThread().setContextClassLoader(originalClassLoader);
67+
}
68+
}
69+
70+
private String doApply(String input) throws InterruptedException, IOException {
71+
// call some API that uses reflection without taking ClassLoader param
72+
CleanthatEngineProperties engineProperties = CleanthatEngineProperties.builder().engineVersion(jdkVersion).build();
73+
74+
// Spotless will push us LF content
75+
engineProperties.setSourceCode(SourceCodeProperties.builder().lineEnding(LineEnding.LF).build());
76+
77+
JavaRefactorerProperties refactorerProperties = new JavaRefactorerProperties();
78+
79+
refactorerProperties.setIncluded(included);
80+
refactorerProperties.setExcluded(excluded);
81+
82+
JavaRefactorer refactorer = new JavaRefactorer(engineProperties, refactorerProperties);
83+
84+
LOGGER.debug("Processing sourceJdk={} included={} excluded={}", jdkVersion, included, excluded);
85+
LOGGER.debug("Available mutators: {}", JavaRefactorer.getAllIncluded());
86+
87+
// Spotless calls steps always with LF eol.
88+
return refactorer.doFormat(input, LineEnding.LF);
89+
}
90+
91+
}

0 commit comments

Comments
 (0)