Skip to content

Commit 74f2ee8

Browse files
committed
Merge branch 'main' into feat/equo-ide
2 parents b4d9de5 + 2872741 commit 74f2ee8

File tree

53 files changed

+1157
-123
lines changed

Some content is hidden

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

53 files changed

+1157
-123
lines changed

CHANGES.md

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +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+
### Fixed
14+
* `JacksonJsonFormatterFunc` handles json files with an Array as root. ([#1585](https://github.com/diffplug/spotless/pull/1585))
15+
16+
## [2.35.0] - 2023-02-10
17+
### Added
18+
* CleanThat Java Refactorer. ([#1560](https://github.com/diffplug/spotless/pull/1560))
19+
* Introduce `LazyArgLogger` to allow for lazy evaluation of log messages in slf4j logging. ([#1565](https://github.com/diffplug/spotless/pull/1565))
20+
### Fixed
21+
* 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))
22+
* `ktfmt` default style uses correct continuation indent. ([#1562](https://github.com/diffplug/spotless/pull/1562))
23+
### Changes
24+
* Bump default `ktfmt` version to latest `0.42` -> `0.43` ([#1561](https://github.com/diffplug/spotless/pull/1561))
25+
* Bump default `jackson` version to latest `2.14.1` -> `2.14.2` ([#1536](https://github.com/diffplug/spotless/pull/1536))
1326

1427
## [2.34.1] - 2023-02-05
1528
### Changes

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/java-publish.gradle

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -170,11 +170,11 @@ model {
170170
}
171171
}
172172

173-
if (System.env['JITPACK'] == 'true') {
173+
if (System.env['JITPACK'] == 'true' || version.endsWith('-SNAPSHOT')) {
174174
signing {
175175
setRequired(false)
176176
}
177-
} else if (!version.endsWith('-SNAPSHOT')) {
177+
} else {
178178
signing {
179179
String gpg_key = decode64('ORG_GRADLE_PROJECT_gpg_key64')
180180
useInMemoryPgpKeys(gpg_key, System.env['ORG_GRADLE_PROJECT_gpg_passphrase'])
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
distributionBase=GRADLE_USER_HOME
22
distributionPath=wrapper/dists
3-
distributionUrl=https\://services.gradle.org/distributions/gradle-7.6-bin.zip
3+
distributionUrl=https\://services.gradle.org/distributions/gradle-7.6.1-bin.zip
44
networkTimeout=10000
55
zipStoreBase=GRADLE_USER_HOME
66
zipStorePath=wrapper/dists

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: 14 additions & 4 deletions
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

@@ -62,10 +69,10 @@ dependencies {
6269
palantirJavaFormatCompileOnly 'com.palantir.javaformat:palantir-java-format:1.1.0' // this version needs to stay compilable against Java 8 for CI Job testNpm
6370

6471
// used jackson-based formatters
65-
jacksonCompileOnly 'com.fasterxml.jackson.core:jackson-databind:2.14.1'
66-
jacksonCompileOnly 'com.fasterxml.jackson.dataformat:jackson-dataformat-yaml:2.14.1'
72+
jacksonCompileOnly 'com.fasterxml.jackson.core:jackson-databind:2.14.2'
73+
jacksonCompileOnly 'com.fasterxml.jackson.dataformat:jackson-dataformat-yaml:2.14.2'
6774

68-
String VER_KTFMT = '0.42'
75+
String VER_KTFMT = '0.43'
6976
ktfmtCompileOnly "com.facebook:ktfmt:$VER_KTFMT"
7077
String VER_KTLINT_GOOGLE_JAVA_FORMAT = '1.7' // for JDK 8 compatibility
7178
ktfmtCompileOnly("com.google.googlejavaformat:google-java-format") {
@@ -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.6'
112+
compatCleanthat2Dot1CompileAndTestOnly 'io.github.solven-eu.cleanthat:java:2.6'
103113
}
104114

105115
// we'll hold the core lib to a high standard
Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
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+
private boolean includeDraft;
46+
47+
public JavaCleanthatRefactorerFunc(String jdkVersion, List<String> included, List<String> excluded, boolean includeDraft) {
48+
this.jdkVersion = jdkVersion == null ? IJdkVersionConstants.JDK_8 : jdkVersion;
49+
this.included = included == null ? Collections.emptyList() : included;
50+
this.excluded = excluded == null ? Collections.emptyList() : excluded;
51+
this.includeDraft = includeDraft;
52+
}
53+
54+
public JavaCleanthatRefactorerFunc() {
55+
this(IJdkVersionConstants.JDK_8, Arrays.asList("SafeAndConsensual"), Arrays.asList(), false);
56+
}
57+
58+
@Override
59+
public String apply(String input) throws Exception {
60+
// https://stackoverflow.com/questions/1771679/difference-between-threads-context-class-loader-and-normal-classloader
61+
ClassLoader originalClassLoader = Thread.currentThread().getContextClassLoader();
62+
try {
63+
// Ensure CleanThat main Thread has its custom classLoader while executing its refactoring
64+
Thread.currentThread().setContextClassLoader(getClass().getClassLoader());
65+
return doApply(input);
66+
} finally {
67+
// Restore the originalClassLoader
68+
Thread.currentThread().setContextClassLoader(originalClassLoader);
69+
}
70+
}
71+
72+
private String doApply(String input) throws InterruptedException, IOException {
73+
// call some API that uses reflection without taking ClassLoader param
74+
CleanthatEngineProperties engineProperties = CleanthatEngineProperties.builder().engineVersion(jdkVersion).build();
75+
76+
// Spotless will push us LF content
77+
engineProperties.setSourceCode(SourceCodeProperties.builder().lineEnding(LineEnding.LF).build());
78+
79+
JavaRefactorerProperties refactorerProperties = new JavaRefactorerProperties();
80+
81+
refactorerProperties.setIncluded(included);
82+
refactorerProperties.setExcluded(excluded);
83+
84+
refactorerProperties.setIncludeDraft(includeDraft);
85+
86+
JavaRefactorer refactorer = new JavaRefactorer(engineProperties, refactorerProperties);
87+
88+
LOGGER.debug("Processing sourceJdk={} included={} excluded={}", jdkVersion, included, excluded, includeDraft);
89+
LOGGER.debug("Available mutators: {}", JavaRefactorer.getAllIncluded());
90+
91+
// Spotless calls steps always with LF eol.
92+
return refactorer.doFormat(input, LineEnding.LF);
93+
}
94+
95+
}

lib/src/jackson/java/com/diffplug/spotless/glue/json/AJacksonFormatterFunc.java

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616
package com.diffplug.spotless.glue.json;
1717

1818
import java.io.IOException;
19-
import java.util.Map;
2019

2120
import com.fasterxml.jackson.core.JsonFactory;
2221
import com.fasterxml.jackson.core.JsonProcessingException;
@@ -49,7 +48,7 @@ public String apply(String input) throws Exception {
4948
protected String format(ObjectMapper objectMapper, String input) throws IllegalArgumentException, IOException {
5049
try {
5150
// ObjectNode is not compatible with SerializationFeature.ORDER_MAP_ENTRIES_BY_KEYS
52-
Map objectNode = objectMapper.readValue(input, Map.class);
51+
Object objectNode = objectMapper.readValue(input, inferType(input));
5352
String output = objectMapper.writerWithDefaultPrettyPrinter().writeValueAsString(objectNode);
5453

5554
return output;
@@ -58,6 +57,13 @@ protected String format(ObjectMapper objectMapper, String input) throws IllegalA
5857
}
5958
}
6059

60+
/**
61+
*
62+
* @param input
63+
* @return the {@link Class} into which the String has to be deserialized
64+
*/
65+
protected abstract Class<?> inferType(String input);
66+
6167
/**
6268
* @return a {@link JsonFactory}. May be overridden to handle alternative formats.
6369
* @see <a href="https://github.com/FasterXML/jackson-dataformats-text">jackson-dataformats-text</a>

lib/src/jackson/java/com/diffplug/spotless/glue/json/JacksonJsonFormatterFunc.java

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,9 @@
1515
*/
1616
package com.diffplug.spotless.glue.json;
1717

18+
import java.util.Collection;
19+
import java.util.Map;
20+
1821
import com.fasterxml.jackson.core.JsonFactory;
1922
import com.fasterxml.jackson.core.JsonFactoryBuilder;
2023
import com.fasterxml.jackson.core.JsonGenerator;
@@ -37,6 +40,15 @@ public JacksonJsonFormatterFunc(JacksonJsonConfig jacksonConfig) {
3740
this.jacksonConfig = jacksonConfig;
3841
}
3942

43+
@Override
44+
protected Class<?> inferType(String input) {
45+
if (input.trim().startsWith("[")) {
46+
return Collection.class;
47+
} else {
48+
return Map.class;
49+
}
50+
}
51+
4052
/**
4153
* @return a {@link JsonFactory}. May be overridden to handle alternative formats.
4254
* @see <a href="https://github.com/FasterXML/jackson-dataformats-text">jackson-dataformats-text</a>

lib/src/jackson/java/com/diffplug/spotless/glue/yaml/JacksonYamlFormatterFunc.java

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,13 +58,18 @@ protected JsonFactory makeJsonFactory() {
5858
return yamlFactoryBuilder.build();
5959
}
6060

61+
@Override
62+
protected Class<?> inferType(String input) {
63+
return JsonNode.class;
64+
}
65+
6166
@Override
6267
protected String format(ObjectMapper objectMapper, String input) throws IllegalArgumentException, IOException {
6368
try {
6469
// https://stackoverflow.com/questions/25222327/deserialize-pojos-from-multiple-yaml-documents-in-a-single-file-in-jackson
6570
// https://github.com/FasterXML/jackson-dataformats-text/issues/66#issuecomment-375328648
6671
JsonParser yamlParser = objectMapper.getFactory().createParser(input);
67-
List<JsonNode> documents = objectMapper.readValues(yamlParser, JsonNode.class).readAll();
72+
List<?> documents = objectMapper.readValues(yamlParser, inferType(input)).readAll();
6873

6974
// https://github.com/FasterXML/jackson-dataformats-text/issues/66#issuecomment-554265055
7075
// https://github.com/FasterXML/jackson-dataformats-text/issues/66#issuecomment-554265055

0 commit comments

Comments
 (0)