Skip to content

Commit e7d0939

Browse files
committed
feat: allow dynamic version selection for eclipse-wtp
1 parent d1d3a9e commit e7d0939

File tree

3 files changed

+20
-26
lines changed

3 files changed

+20
-26
lines changed

README.md

Lines changed: 6 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,7 @@ or apply the formatting to the files.
154154
Available formatting steps:
155155
clang-format Runs clang-format
156156
clean-that CleanThat enables automatic refactoring of Java code.
157-
eclipse-wtp Runs Eclipse WTP formatter (4.21.0)
157+
eclipse-wtp Runs Eclipse WTP formatter.
158158
format-annotations Corrects line break formatting of type annotations in
159159
java files.
160160
google-java-format Runs google java format
@@ -309,18 +309,6 @@ spotless --target '**/src/**/*.java' clean-that --exclude-mutator=StreamAnyMatch
309309

310310
### eclipse-wtp
311311

312-
<!---freshmark eclipsewtpshields
313-
output = [
314-
link(shield('spotless eclipse wtp version', 'spotless-eclipse-wtp', '{{libs.versions.native.include.spotlessEclipseWtp}}', 'blue'), 'https://central.sonatype.com/artifact/com.diffplug.spotless/spotless-eclipse-wtp/{{libs.versions.native.include.spotlessEclipseWtp}}'),
315-
link(shield('eclipse wtp version', 'eclipse-wtp-formatter', '{{libs.versions.native.include.spotlessEclipseWtpFormatter}}', 'blue'), 'https://github.com/diffplug/spotless/blob/main/lib-extra/src/main/resources/com/diffplug/spotless/extra/eclipse_wtp_formatter/v{{libs.versions.native.include.spotlessEclipseWtpFormatter}}'),
316-
].join('\n')
317-
-->
318-
319-
[![spotless eclipse wtp version](https://img.shields.io/badge/spotless--eclipse--wtp-3.23.0-blue.svg)](https://central.sonatype.com/artifact/com.diffplug.spotless/spotless-eclipse-wtp/3.23.0)
320-
[![eclipse wtp version](https://img.shields.io/badge/eclipse--wtp--formatter-4.21.0-blue.svg)](https://github.com/diffplug/spotless/blob/main/lib-extra/src/main/resources/com/diffplug/spotless/extra/eclipse_wtp_formatter/v4.21.0)
321-
322-
<!---freshmark /eclipsewtpshields -->
323-
324312
The [eclipse web tools platform (WTP)](https://projects.eclipse.org/projects/webtools) formatter is a formatter for web files such as HTML, CSS, JavaScript, JSON, XML and XHTML.
325313

326314
It comes with reasonable defaults but can be configured using configuration files. For details see the [spotless documentation](https://github.com/diffplug/spotless/tree/main/plugin-gradle#eclipse-web-tools-platform).
@@ -335,8 +323,8 @@ output =
335323
-->
336324

337325
```
338-
Usage: spotless eclipse-wtp [-hV] [-f]... [-t=<type>]
339-
Runs Eclipse WTP formatter (4.21.0)
326+
Usage: spotless eclipse-wtp [-hV] [-f]... [-t=<type>] [-v=<useVersion>]
327+
Runs Eclipse WTP formatter.
340328
-f, --config-file The path to the Eclipse WTP configuration file. For
341329
supported config file options see spotless
342330
documentation (additional info links).
@@ -346,6 +334,9 @@ Runs Eclipse WTP formatter (4.21.0)
346334
we find. If that does not work, we fail the formatting
347335
run.
348336
One of: CSS, HTML, JS, JSON, XML, XHTML
337+
-v, --use-version=<useVersion>
338+
The version of Eclipse WTP formatter to use.
339+
(default: 4.21.0)
349340
-V, --version Print version information and exit.
350341
351342
✅ This step supports the following file types:

app/src/main/java/com/diffplug/spotless/cli/steps/EclipseWtp.java

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -34,17 +34,20 @@
3434

3535
import picocli.CommandLine;
3636

37-
@CommandLine.Command(
38-
name = "eclipse-wtp",
39-
description = "Runs Eclipse WTP formatter (" + EclipseWtp.ECLIPSE_WTP_VERSION + ")")
37+
@CommandLine.Command(name = "eclipse-wtp", description = "Runs Eclipse WTP formatter.")
4038
@SupportedFileTypes({"css", "html", "js", "json", "xml", "xhtml"})
4139
@AdditionalInfoLinks({
4240
"https://github.com/diffplug/spotless/tree/main/plugin-gradle#eclipse-web-tools-platform",
4341
"https://projects.eclipse.org/projects/webtools"
4442
})
4543
public class EclipseWtp extends SpotlessFormatterStep {
4644

47-
public static final String ECLIPSE_WTP_VERSION = "4.21.0"; // TODO we need to slurp in the lock file also
45+
private static final String DEFAULT_VERSION_SYSPROP = "steps.eclipse-wtp.default-version";
46+
47+
static {
48+
// workaround for dynamic property values in annotations
49+
System.setProperty(DEFAULT_VERSION_SYSPROP, EclipseWtpFormatterStep.defaultVersion());
50+
}
4851

4952
@CommandLine.Option(
5053
names = {"-f", "--config-file"},
@@ -60,6 +63,12 @@ public class EclipseWtp extends SpotlessFormatterStep {
6063
+ OptionConstants.VALID_VALUES_SUFFIX)
6164
Type type;
6265

66+
@CommandLine.Option(
67+
names = {"--use-version", "-v"},
68+
defaultValue = "${sys:" + DEFAULT_VERSION_SYSPROP + "}",
69+
description = "The version of Eclipse WTP formatter to use." + OptionConstants.DEFAULT_VALUE_SUFFIX)
70+
String useVersion;
71+
6372
public enum Type {
6473
CSS(EclipseWtpFormatterStep.CSS),
6574
HTML(EclipseWtpFormatterStep.HTML),
@@ -95,7 +104,7 @@ public enum Type {
95104
public @NotNull List<FormatterStep> prepareFormatterSteps(SpotlessActionContext context) {
96105
EclipseWtpFormatterStep wtpType = type(context::targetFileType).toEclipseWtpType();
97106
EclipseBasedStepBuilder builder = wtpType.createBuilder(context.provisioner());
98-
builder.setVersion(ECLIPSE_WTP_VERSION);
107+
builder.setVersion(useVersion);
99108
if (configFiles != null && !configFiles.isEmpty()) {
100109
builder.setPreferences(configFiles.stream()
101110
.map(context::resolvePath)

gradle/libs.versions.toml

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,6 @@ durian = "1.2.0"
77
junit = "5.8.1"
88
maven-resolver = "2.0.13"
99
mockito = "5.17.0"
10-
# to find required version here check eclipse_wtp_formatter/v4.21.0.lockfile
11-
# where <4.21.0> is the default version of com.diffplug.spotless.extra.wtp.EclipseWtpFormatterStep#defaultVersion
12-
native-include-spotlessEclipseWtp = "3.23.0"
13-
native-include-spotlessEclipseWtpFormatter = "4.21.0"
1410
picocli = "4.7.6"
1511
selfie = "2.5.5"
1612
slf4j = "2.0.17"
@@ -36,7 +32,6 @@ maven-resolver-transport-apache = { module = "org.apache.maven.resolver:maven-re
3632
maven-resolver-transport-file = { module = "org.apache.maven.resolver:maven-resolver-transport-file" } # version from bom
3733
maven-resolver-util = { module = "org.apache.maven.resolver:maven-resolver-util" } # version from bom
3834
mockito = { module = "org.mockito:mockito-core", version.ref = "mockito" }
39-
native-include-spotlessEclipseWtp = { module = "com.diffplug.spotless:spotless-eclipse-wtp", version.ref = "native-include-spotlessEclipseWtp" }
4035
picocli = { module = "info.picocli:picocli", version.ref = "picocli" }
4136
picocli-codegen = { module = "info.picocli:picocli-codegen", version.ref = "picocli" }
4237
selfie = { module = "com.diffplug.selfie:selfie-runner-junit5", version.ref = "selfie" }
@@ -59,7 +54,6 @@ maven-resolver-impl-libs = [
5954
"maven-resolver-supplier-mvn4",
6055
]
6156
native-includes = [
62-
"native-include-spotlessEclipseWtp",
6357
]
6458
spotless-libs = ["spotless-lib", "spotless-lib-extra"]
6559
test-libs = ["assertj-core", "junit-jupiter-api", "selfie", "mockito"]

0 commit comments

Comments
 (0)