Skip to content

Commit ec15646

Browse files
committed
Merge branch 'main' into bugfix/fix-freshmark-on-jdk15-and-higher
2 parents 8e18650 + 1774837 commit ec15646

Some content is hidden

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

44 files changed

+468
-90
lines changed

CHANGES.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format (
1212
## [Unreleased]
1313
### Changes
1414
* **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))
15+
* **POTENTIALLY BREAKING** `sortByKeys` for JSON formatting now takes into account objects inside arrays ([#1546](https://github.com/diffplug/spotless/pull/1546))
1516

1617
## [2.34.0] - 2023-01-26
1718
### 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: 34 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,45 @@
11
# <img align="left" src="_images/spotless_logo.png"> Spotless: Keep your code spotless
22

3-
<!---freshmark shields
4-
output = [
5-
link(image('Circle CI', 'https://circleci.com/gh/diffplug/spotless/tree/main.svg?style=shield'), 'https://circleci.com/gh/diffplug/spotless/tree/main'),
6-
link(shield('Live chat', 'gitter', 'chat', 'brightgreen'), 'https://gitter.im/{{org}}/{{name}}'),
7-
link(shield('License Apache', 'license', 'apache', 'brightgreen'), 'https://tldrlegal.com/license/apache-license-2.0-(apache-2.0)')
8-
].join('\n');
9-
-->
10-
[![Circle CI](https://circleci.com/gh/diffplug/spotless/tree/main.svg?style=shield)](https://circleci.com/gh/diffplug/spotless/tree/main)
11-
[![Live chat](https://img.shields.io/badge/gitter-chat-brightgreen.svg)](https://gitter.im/diffplug/spotless)
12-
[![License Apache](https://img.shields.io/badge/license-apache-brightgreen.svg)](https://tldrlegal.com/license/apache-license-2.0-(apache-2.0))
13-
<!---freshmark /shields -->
3+
[![Gradle Plugin](https://img.shields.io/gradle-plugin-portal/v/com.diffplug.spotless?color=blue&label=gradle%20plugin)](plugin-gradle)
4+
[![Maven Plugin](https://img.shields.io/maven-central/v/com.diffplug.spotless/spotless-maven-plugin?color=blue&label=maven%20plugin)](plugin-maven)
5+
[![SBT Plugin](https://img.shields.io/badge/sbt%20plugin-0.1.3-blue)](https://github.com/moznion/sbt-spotless)
146

15-
Spotless can format &lt;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 &lt;gradle | maven | anything>.
7+
Spotless can format &lt;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 &lt;gradle | maven | sbt | anything>.
168

179
You probably want one of the links below:
1810

1911
## [❇️ 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))
12+
13+
```console
14+
user@machine repo % ./gradlew build
15+
:spotlessJavaCheck FAILED
16+
The following files had format violations:
17+
src\main\java\com\diffplug\gradle\spotless\FormatExtension.java
18+
-\t\t····if·(targets.length·==·0)·{
19+
+\t\tif·(targets.length·==·0)·{
20+
Run './gradlew spotlessApply' to fix these violations.
21+
user@machine repo % ./gradlew spotlessApply
22+
:spotlessApply
23+
BUILD SUCCESSFUL
24+
user@machine repo % ./gradlew build
25+
BUILD SUCCESSFUL
26+
```
27+
2028
## [❇️ Spotless for Maven](plugin-maven)
29+
30+
```console
31+
user@machine repo % mvn spotless:check
32+
[ERROR] > The following files had format violations:
33+
[ERROR] src\main\java\com\diffplug\gradle\spotless\FormatExtension.java
34+
[ERROR] -\t\t····if·(targets.length·==·0)·{
35+
[ERROR] +\t\tif·(targets.length·==·0)·{
36+
[ERROR] Run 'mvn spotless:apply' to fix these violations.
37+
user@machine repo % mvn spotless:apply
38+
[INFO] BUILD SUCCESS
39+
user@machine repo % mvn spotless:check
40+
[INFO] BUILD SUCCESS
41+
```
42+
2143
## [❇️ Spotless for SBT (external for now)](https://github.com/moznion/sbt-spotless)
2244
## [Other build systems](CONTRIBUTING.md#how-to-add-a-new-plugin-for-a-build-system)
2345

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

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/src/gson/java/com/diffplug/spotless/glue/gson/GsonFormatterFunc.java

Lines changed: 25 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121

2222
import com.google.gson.Gson;
2323
import com.google.gson.GsonBuilder;
24+
import com.google.gson.JsonArray;
2425
import com.google.gson.JsonElement;
2526
import com.google.gson.JsonObject;
2627
import com.google.gson.stream.JsonWriter;
@@ -57,8 +58,8 @@ public String apply(String inputString) {
5758
if (jsonElement == null) {
5859
throw new AssertionError(FAILED_TO_PARSE_ERROR_MESSAGE);
5960
}
60-
if (gsonConfig.isSortByKeys() && jsonElement.isJsonObject()) {
61-
jsonElement = sortByKeys(jsonElement.getAsJsonObject());
61+
if (gsonConfig.isSortByKeys()) {
62+
jsonElement = sortByKeys(jsonElement);
6263
}
6364
try (StringWriter stringWriter = new StringWriter()) {
6465
JsonWriter jsonWriter = new JsonWriter(stringWriter);
@@ -72,19 +73,36 @@ public String apply(String inputString) {
7273
return result;
7374
}
7475

76+
private JsonElement sortByKeys(JsonElement jsonElement) {
77+
if (jsonElement.isJsonArray()) {
78+
return sortByKeys(jsonElement.getAsJsonArray());
79+
} else if (jsonElement.isJsonObject()) {
80+
return sortByKeys(jsonElement.getAsJsonObject());
81+
} else {
82+
return jsonElement;
83+
}
84+
}
85+
7586
private JsonElement sortByKeys(JsonObject jsonObject) {
7687
JsonObject result = new JsonObject();
7788
jsonObject.keySet().stream().sorted()
7889
.forEach(key -> {
79-
JsonElement element = jsonObject.get(key);
80-
if (element.isJsonObject()) {
81-
element = sortByKeys(element.getAsJsonObject());
82-
}
83-
result.add(key, element);
90+
JsonElement sorted = sortByKeys(jsonObject.get(key));
91+
result.add(key, sorted);
8492
});
8593
return result;
8694
}
8795

96+
private JsonElement sortByKeys(JsonArray jsonArray) {
97+
var result = new JsonArray();
98+
for (JsonElement element : jsonArray) {
99+
JsonElement sorted = sortByKeys(element);
100+
result.add(sorted);
101+
}
102+
103+
return result;
104+
}
105+
88106
private String generateIndent(int indentSpaces) {
89107
return String.join("", Collections.nCopies(indentSpaces, " "));
90108
}

lib/src/main/java/com/diffplug/spotless/Formatter.java

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,13 +39,16 @@
3939
public final class Formatter implements Serializable, AutoCloseable {
4040
private static final long serialVersionUID = 1L;
4141

42+
// The name is used for logging purpose. It does not convey any applicative purpose
43+
private String name;
4244
private LineEnding.Policy lineEndingsPolicy;
4345
private Charset encoding;
4446
private Path rootDir;
4547
private List<FormatterStep> steps;
4648
private FormatExceptionPolicy exceptionPolicy;
4749

48-
private Formatter(LineEnding.Policy lineEndingsPolicy, Charset encoding, Path rootDirectory, List<FormatterStep> steps, FormatExceptionPolicy exceptionPolicy) {
50+
private Formatter(String name, LineEnding.Policy lineEndingsPolicy, Charset encoding, Path rootDirectory, List<FormatterStep> steps, FormatExceptionPolicy exceptionPolicy) {
51+
this.name = name;
4952
this.lineEndingsPolicy = Objects.requireNonNull(lineEndingsPolicy, "lineEndingsPolicy");
5053
this.encoding = Objects.requireNonNull(encoding, "encoding");
5154
this.rootDir = Objects.requireNonNull(rootDirectory, "rootDir");
@@ -55,6 +58,7 @@ private Formatter(LineEnding.Policy lineEndingsPolicy, Charset encoding, Path ro
5558

5659
// override serialize output
5760
private void writeObject(ObjectOutputStream out) throws IOException {
61+
out.writeObject(name);
5862
out.writeObject(lineEndingsPolicy);
5963
out.writeObject(encoding.name());
6064
out.writeObject(rootDir.toString());
@@ -65,6 +69,7 @@ private void writeObject(ObjectOutputStream out) throws IOException {
6569
// override serialize input
6670
@SuppressWarnings("unchecked")
6771
private void readObject(ObjectInputStream in) throws IOException, ClassNotFoundException {
72+
name = (String) in.readObject();
6873
lineEndingsPolicy = (LineEnding.Policy) in.readObject();
6974
encoding = Charset.forName((String) in.readObject());
7075
rootDir = Paths.get((String) in.readObject());
@@ -78,6 +83,10 @@ private void readObjectNoData() throws ObjectStreamException {
7883
throw new UnsupportedOperationException();
7984
}
8085

86+
public String getName() {
87+
return name;
88+
}
89+
8190
public LineEnding.Policy getLineEndingsPolicy() {
8291
return lineEndingsPolicy;
8392
}
@@ -103,6 +112,8 @@ public static Formatter.Builder builder() {
103112
}
104113

105114
public static class Builder {
115+
// optional parameters
116+
private String name = "unnamed";
106117
// required parameters
107118
private LineEnding.Policy lineEndingsPolicy;
108119
private Charset encoding;
@@ -112,6 +123,11 @@ public static class Builder {
112123

113124
private Builder() {}
114125

126+
public Builder name(String name) {
127+
this.name = name;
128+
return this;
129+
}
130+
115131
public Builder lineEndingsPolicy(LineEnding.Policy lineEndingsPolicy) {
116132
this.lineEndingsPolicy = lineEndingsPolicy;
117133
return this;
@@ -138,7 +154,7 @@ public Builder exceptionPolicy(FormatExceptionPolicy exceptionPolicy) {
138154
}
139155

140156
public Formatter build() {
141-
return new Formatter(lineEndingsPolicy, encoding, rootDir, steps,
157+
return new Formatter(name, lineEndingsPolicy, encoding, rootDir, steps,
142158
exceptionPolicy == null ? FormatExceptionPolicy.failOnlyOnError() : exceptionPolicy);
143159
}
144160
}
@@ -253,6 +269,7 @@ public String compute(String unix, File file) {
253269
public int hashCode() {
254270
final int prime = 31;
255271
int result = 1;
272+
result = prime * result + name.hashCode();
256273
result = prime * result + encoding.hashCode();
257274
result = prime * result + lineEndingsPolicy.hashCode();
258275
result = prime * result + rootDir.hashCode();
@@ -273,7 +290,8 @@ public boolean equals(Object obj) {
273290
return false;
274291
}
275292
Formatter other = (Formatter) obj;
276-
return encoding.equals(other.encoding) &&
293+
return name.equals(other.name) &&
294+
encoding.equals(other.encoding) &&
277295
lineEndingsPolicy.equals(other.lineEndingsPolicy) &&
278296
rootDir.equals(other.rootDir) &&
279297
steps.equals(other.steps) &&

plugin-gradle/CHANGES.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format (starting after version `3.27.0`).
44

55
## [Unreleased]
6+
### Changes
7+
* **POTENTIALLY BREAKING** `sortByKeys` for JSON formatting now takes into account objects inside arrays ([#1546](https://github.com/diffplug/spotless/pull/1546))
68

79
## [6.14.0] - 2023-01-26
810
### Added

plugin-gradle/README.md

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4,26 +4,20 @@
44
<!---freshmark shields
55
output = [
66
link(shield('Gradle plugin', 'plugins.gradle.org', 'com.diffplug.spotless', 'blue'), 'https://plugins.gradle.org/plugin/com.diffplug.spotless'),
7-
link(shield('Maven central', 'mavencentral', 'yes', 'blue'), 'https://search.maven.org/#search%7Cgav%7C1%7Cg%3A%22com.diffplug.spotless%22%20AND%20a%3A%22spotless-plugin-gradle%22'),
8-
link(shield('Javadoc', 'javadoc', 'yes', 'blue'), 'https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/{{versionLast}}/index.html'),
9-
link(shield('License Apache', 'license', 'apache', 'blue'), 'https://tldrlegal.com/license/apache-license-2.0-(apache-2.0)'),
107
link(shield('Changelog', 'changelog', '{{versionLast}}', 'blue'), 'CHANGES.md'),
8+
link(shield('Maven central', 'mavencentral', 'here', 'blue'), 'https://search.maven.org/#search%7Cgav%7C1%7Cg%3A%22com.diffplug.spotless%22%20AND%20a%3A%22spotless-plugin-gradle%22'),
9+
link(shield('Javadoc', 'javadoc', 'here', 'blue'), 'https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/{{versionLast}}/index.html'),
1110
'',
12-
link(image('Circle CI', 'https://circleci.com/gh/diffplug/spotless/tree/main.svg?style=shield'), 'https://circleci.com/gh/diffplug/spotless/tree/main'),
13-
link(shield('Live chat', 'gitter', 'chat', 'brightgreen'), 'https://gitter.im/{{org}}/{{name}}'),
1411
link(shield('VS Code plugin', 'IDE', 'VS Code', 'blueviolet'), 'https://marketplace.visualstudio.com/items?itemName=richardwillis.vscode-spotless-gradle'),
1512
link(shield('IntelliJ plugin', 'IDE', 'IntelliJ', 'blueviolet'), 'https://plugins.jetbrains.com/plugin/18321-spotless-gradle'),
1613
link(shield('Add other IDE', 'IDE', 'add yours', 'blueviolet'), 'IDE_HOOK.md')
1714
].join('\n');
1815
-->
1916
[![Gradle plugin](https://img.shields.io/badge/plugins.gradle.org-com.diffplug.spotless-blue.svg)](https://plugins.gradle.org/plugin/com.diffplug.spotless)
20-
[![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)
21-
[![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)
22-
[![License Apache](https://img.shields.io/badge/license-apache-blue.svg)](https://tldrlegal.com/license/apache-license-2.0-(apache-2.0))
2317
[![Changelog](https://img.shields.io/badge/changelog-6.14.0-blue.svg)](CHANGES.md)
18+
[![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)
19+
[![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)
2420

25-
[![Circle CI](https://circleci.com/gh/diffplug/spotless/tree/main.svg?style=shield)](https://circleci.com/gh/diffplug/spotless/tree/main)
26-
[![Live chat](https://img.shields.io/badge/gitter-chat-brightgreen.svg)](https://gitter.im/diffplug/spotless)
2721
[![VS Code plugin](https://img.shields.io/badge/IDE-VS_Code-blueviolet.svg)](https://marketplace.visualstudio.com/items?itemName=richardwillis.vscode-spotless-gradle)
2822
[![IntelliJ plugin](https://img.shields.io/badge/IDE-IntelliJ-blueviolet.svg)](https://plugins.jetbrains.com/plugin/18321-spotless-gradle)
2923
[![Add other IDE](https://img.shields.io/badge/IDE-add_yours-blueviolet.svg)](IDE_HOOK.md)
@@ -33,7 +27,7 @@ output = [
3327
output = prefixDelimiterReplace(input, 'https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/', '/', versionLast)
3428
-->
3529

36-
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.
30+
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.
3731

3832
To people who use your build, it looks like this ([IDE support also available](IDE_HOOK.md)):
3933

0 commit comments

Comments
 (0)