Skip to content

Commit caf1e48

Browse files
committed
Merge branch 'main' into 1679-gjf-compile-only-issue
2 parents 0183cc2 + 94ba918 commit caf1e48

File tree

65 files changed

+3305
-46
lines changed

Some content is hidden

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

65 files changed

+3305
-46
lines changed

CHANGES.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,13 @@ 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-
1413
### Added
1514
* `Jvm.Support` now accepts `-SNAPSHOT` versions, treated as the non`-SNAPSHOT`. ([#1583](https://github.com/diffplug/spotless/issues/1583))
15+
* Support Rome as a formatter for JavaScript and TypeScript code. Adds a new `rome` step to `javascript` and `typescript` formatter configurations. ([#1663](https://github.com/diffplug/spotless/pull/1663))
16+
### Fixed
17+
* When P2 download fails, indicate the responsible formatter. ([#1698](https://github.com/diffplug/spotless/issues/1698))
18+
### Changes
19+
* Bump default sortpom version to latest `3.0.0` -> `3.2.1`. ([#1675](https://github.com/diffplug/spotless/pull/1675))
1620

1721
## [2.38.0] - 2023-04-06
1822
### Added

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,7 @@ lib('npm.PrettierFormatterStep') +'{{yes}} | {{yes}}
9999
lib('npm.TsFmtFormatterStep') +'{{yes}} | {{yes}} | {{no}} | {{no}} |',
100100
lib('pom.SortPomStep') +'{{no}} | {{yes}} | {{no}} | {{no}} |',
101101
lib('python.BlackStep') +'{{yes}} | {{no}} | {{no}} | {{no}} |',
102+
lib('rome.RomeStep') +'{{yes}} | {{yes}} | {{no}} | {{no}} |',
102103
lib('scala.ScalaFmtStep') +'{{yes}} | {{yes}} | {{yes}} | {{no}} |',
103104
lib('sql.DBeaverSQLFormatterStep') +'{{yes}} | {{yes}} | {{yes}} | {{no}} |',
104105
extra('wtp.EclipseWtpFormatterStep') +'{{yes}} | {{yes}} | {{no}} | {{no}} |',
@@ -148,6 +149,7 @@ lib('yaml.JacksonYamlStep') +'{{yes}} | {{yes}}
148149
| [`npm.TsFmtFormatterStep`](lib/src/main/java/com/diffplug/spotless/npm/TsFmtFormatterStep.java) | :+1: | :+1: | :white_large_square: | :white_large_square: |
149150
| [`pom.SortPomStep`](lib/src/main/java/com/diffplug/spotless/pom/SortPomStep.java) | :white_large_square: | :+1: | :white_large_square: | :white_large_square: |
150151
| [`python.BlackStep`](lib/src/main/java/com/diffplug/spotless/python/BlackStep.java) | :+1: | :white_large_square: | :white_large_square: | :white_large_square: |
152+
| [`rome.RomeStep`](lib/src/main/java/com/diffplug/spotless/rome/RomeStep.java) | :+1: | :+1: | :white_large_square: | :white_large_square: |
151153
| [`scala.ScalaFmtStep`](lib/src/main/java/com/diffplug/spotless/scala/ScalaFmtStep.java) | :+1: | :+1: | :+1: | :white_large_square: |
152154
| [`sql.DBeaverSQLFormatterStep`](lib/src/main/java/com/diffplug/spotless/sql/DBeaverSQLFormatterStep.java) | :+1: | :+1: | :+1: | :white_large_square: |
153155
| [`wtp.EclipseWtpFormatterStep`](lib-extra/src/main/java/com/diffplug/spotless/extra/wtp/EclipseWtpFormatterStep.java) | :+1: | :+1: | :white_large_square: | :white_large_square: |

gradle.properties

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,6 @@ VER_SLF4J=[1.6,2.0[
3030
# Used in multiple places
3131
VER_DURIAN=1.2.0
3232
VER_JGIT=6.5.0.202303070854-r
33-
VER_JUNIT=5.9.2
33+
VER_JUNIT=5.9.3
3434
VER_ASSERTJ=3.24.2
35-
VER_MOCKITO=5.3.0
35+
VER_MOCKITO=5.3.1

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

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
package com.diffplug.spotless.extra;
1717

1818
import java.io.File;
19+
import java.io.IOException;
1920
import java.io.Serializable;
2021
import java.util.ArrayList;
2122
import java.util.List;
@@ -36,6 +37,7 @@
3637
import dev.equo.solstice.p2.P2ClientCache;
3738
import dev.equo.solstice.p2.P2Model;
3839
import dev.equo.solstice.p2.P2QueryCache;
40+
import dev.equo.solstice.p2.P2QueryResult;
3941

4042
/**
4143
* Generic Eclipse based formatter step {@link State} builder.
@@ -100,7 +102,12 @@ protected void addPlatformRepo(P2Model model, String version) {
100102

101103
/** Creates the state of the configuration. */
102104
EquoBasedStepBuilder.State get() throws Exception {
103-
var query = createModelWithMirrors().query(P2ClientCache.PREFER_OFFLINE, P2QueryCache.ALLOW);
105+
P2QueryResult query;
106+
try {
107+
query = createModelWithMirrors().query(P2ClientCache.PREFER_OFFLINE, P2QueryCache.ALLOW);
108+
} catch (Exception x) {
109+
throw new IOException("Failed to load " + formatterName + ": " + x, x);
110+
}
104111
var classpath = new ArrayList<File>();
105112
var mavenDeps = new ArrayList<String>();
106113
mavenDeps.add("dev.equo.ide:solstice:1.0.3");

lib/build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ dependencies {
115115
// scalafmt
116116
scalafmtCompileOnly "org.scalameta:scalafmt-core_2.13:3.7.3"
117117
// sortPom
118-
sortPomCompileOnly 'com.github.ekryd.sortpom:sortpom-sorter:3.0.0'
118+
sortPomCompileOnly 'com.github.ekryd.sortpom:sortpom-sorter:3.2.1'
119119
sortPomCompileOnly 'org.slf4j:slf4j-api:2.0.0'
120120
}
121121

lib/src/main/java/com/diffplug/spotless/pom/SortPomCfg.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2021 DiffPlug
2+
* Copyright 2021-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.
@@ -21,6 +21,8 @@
2121
public class SortPomCfg implements Serializable {
2222
private static final long serialVersionUID = 1L;
2323

24+
public String version = "3.2.1";
25+
2426
public String encoding = "UTF-8";
2527

2628
public String lineSeparator = System.getProperty("line.separator");
@@ -43,6 +45,8 @@ public class SortPomCfg implements Serializable {
4345

4446
public String sortDependencies = null;
4547

48+
public String sortDependencyManagement = null;
49+
4650
public String sortDependencyExclusions = null;
4751

4852
public String sortPlugins = null;

lib/src/main/java/com/diffplug/spotless/pom/SortPomStep.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2021 DiffPlug
2+
* Copyright 2021-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.
@@ -27,6 +27,8 @@
2727

2828
public class SortPomStep {
2929
public static final String NAME = "sortPom";
30+
static final String PACKAGE = "com.github.ekryd.sortpom";
31+
static final String MAVEN_COORDINATE = PACKAGE + ":sortpom-sorter:";
3032

3133
private SortPomStep() {}
3234

@@ -42,7 +44,7 @@ static class State implements Serializable {
4244

4345
public State(SortPomCfg cfg, Provisioner provisioner) throws IOException {
4446
this.cfg = cfg;
45-
this.jarState = JarState.from("com.github.ekryd.sortpom:sortpom-sorter:3.0.0", provisioner);
47+
this.jarState = JarState.from(MAVEN_COORDINATE + cfg.version, provisioner);
4648
}
4749

4850
FormatterFunc createFormat() throws ClassNotFoundException, NoSuchMethodException, InvocationTargetException, InstantiationException, IllegalAccessException {
Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
/*
2+
* Copyright 2016-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.rome;
17+
18+
/**
19+
* Enumeration of possible computer architectures.
20+
*/
21+
enum Architecture {
22+
/** The arm64 architecture */
23+
ARM64,
24+
/** Either x64 or x64_32 architecture */
25+
X64;
26+
27+
/**
28+
* Attempts to guess the architecture of the environment running the JVM.
29+
*
30+
* @return The best guess for the architecture.
31+
*/
32+
public static Architecture guess() {
33+
var arch = System.getProperty("os.arch");
34+
var version = System.getProperty("os.version");
35+
36+
if (arch == null || arch.isBlank()) {
37+
throw new IllegalStateException("No OS information is available, specify the Rome executable manually");
38+
}
39+
40+
var msg = "Unsupported architecture " + arch + "/" + version
41+
+ ", specify the path to the Rome executable manually";
42+
43+
if (arch.equals("ppc64le")) {
44+
throw new IllegalStateException(msg);
45+
}
46+
if (arch.equals("aarch64")) {
47+
throw new IllegalStateException(msg);
48+
}
49+
if (arch.equals("s390x")) {
50+
throw new IllegalStateException(msg);
51+
}
52+
if (arch.equals("ppc64")) {
53+
throw new IllegalStateException(msg);
54+
}
55+
if (arch.equals("ppc")) {
56+
throw new IllegalStateException(msg);
57+
}
58+
if (arch.equals("arm")) {
59+
if (version.contains("v7")) {
60+
throw new IllegalStateException(msg);
61+
}
62+
return ARM64;
63+
}
64+
if (arch.contains("64")) {
65+
return X64;
66+
}
67+
throw new IllegalStateException(msg);
68+
}
69+
}
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
/*
2+
* Copyright 2016-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.rome;
17+
18+
import java.util.Locale;
19+
20+
/**
21+
* Enumeration of possible computer operation systems.
22+
*/
23+
enum OS {
24+
/** Any derivate of a Linux operation system. */
25+
LINUX,
26+
/** The Macintosh operating system/ */
27+
MAC_OS,
28+
/** The Microsoft Windows operating system. */
29+
WINDOWS,;
30+
31+
/**
32+
* Attempts to guess the OS of the environment running the JVM.
33+
*
34+
* @return The best guess for the architecture.
35+
* @throws IllegalStateException When the OS is either unsupported or no
36+
* information about the OS could be retrieved.
37+
*/
38+
public static OS guess() {
39+
var osName = System.getProperty("os.name");
40+
if (osName == null || osName.isBlank()) {
41+
throw new IllegalStateException("No OS information is available, specify the Rome executable manually");
42+
}
43+
var osNameUpper = osName.toUpperCase(Locale.ROOT);
44+
if (osNameUpper.contains("SUNOS") || osName.contains("AIX")) {
45+
throw new IllegalStateException(
46+
"Unsupported OS " + osName + ", specify the path to the Rome executable manually");
47+
}
48+
if (osNameUpper.contains("WINDOWS")) {
49+
return OS.WINDOWS;
50+
} else if (osNameUpper.contains("MAC")) {
51+
return OS.MAC_OS;
52+
} else {
53+
return OS.LINUX;
54+
}
55+
}
56+
}
Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
/*
2+
* Copyright 2016-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.rome;
17+
18+
/**
19+
* Represents a platform where code is run, consisting of an operating system
20+
* and an architecture.
21+
*/
22+
class Platform {
23+
/**
24+
* Attempts to guess the platform of the hosting environment running the JVM
25+
* machine.
26+
*
27+
* @return The best guess for the current OS and architecture.
28+
* @throws IllegalStateException When no OS information is available, or when
29+
* the OS or architecture is unsupported.
30+
*/
31+
public static Platform guess() {
32+
var os = OS.guess();
33+
var architecture = Architecture.guess();
34+
return new Platform(os, architecture);
35+
}
36+
37+
private final Architecture architecture;
38+
39+
private final OS os;
40+
41+
/**
42+
* Creates a new Platform descriptor for the given OS and architecture.
43+
*
44+
* @param os Operating system of the platform.
45+
* @param architecture Architecture of the platform.
46+
*/
47+
public Platform(OS os, Architecture architecture) {
48+
this.os = os;
49+
this.architecture = architecture;
50+
}
51+
52+
/**
53+
* @return The architecture of this platform.
54+
*/
55+
public Architecture getArchitecture() {
56+
return architecture;
57+
}
58+
59+
/**
60+
* @return The operating system of this platform.
61+
*/
62+
public OS getOs() {
63+
return os;
64+
}
65+
66+
/**
67+
* @return Whether the operating system is Linux.
68+
*/
69+
public boolean isLinux() {
70+
return os == OS.LINUX;
71+
}
72+
73+
/**
74+
* @return Whether the operating system is Mac.
75+
*/
76+
public boolean isMac() {
77+
return os == OS.MAC_OS;
78+
}
79+
80+
/**
81+
* @return Whether the operating system is Windows.
82+
*/
83+
public boolean isWindows() {
84+
return os == OS.WINDOWS;
85+
}
86+
87+
@Override
88+
public String toString() {
89+
return String.format("Platform[os=%s,architecture=%s]", os, architecture);
90+
}
91+
}

0 commit comments

Comments
 (0)