Skip to content

Commit dbf5ca8

Browse files
committed
chore: cleaning up eclipse-wtp
1 parent aacef93 commit dbf5ca8

File tree

10 files changed

+206
-284
lines changed

10 files changed

+206
-284
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -154,6 +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)
157158
format-annotations Corrects line break formatting of type annotations in
158159
java files.
159160
google-java-format Runs google java format

app/build.gradle

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,6 @@ import com.diffplug.spotless.cli.picocli.usage.GenerateUsagePropertiesTask
22
import com.diffplug.spotless.extra.wtp.EclipseWtpFormatterStep
33
import org.gradle.plugins.ide.eclipse.model.EclipseWtp
44

5-
//buildscript {
6-
// dependencies {
7-
// classpath libs.spotless.lib.extra
8-
// }
9-
//}
10-
115
plugins {
126
id 'buildlogic.picocli-conventions'
137
id 'buildlogic.java-special-tests-conventions'
@@ -27,14 +21,18 @@ dependencies {
2721
// this is necessary to allow for native compilation where reflective access to dynamic jars is not possible
2822
implementation libs.bundles.native.includes
2923

24+
// Eclipse WTP formatter used a custom lockfile to ensure the formatter has the
25+
// correct version of all its libraries
3026
def resourceName = "/com/diffplug/spotless/extra/eclipse_wtp_formatter/v4.21.0.lockfile"
31-
println("resource: " + resourceName)
32-
EclipseWtpFormatterStep.getResource(resourceName)
27+
logger.debug("reading eclipse wtp resource: " + resourceName)
28+
EclipseWtpFormatterStep.getResource(resourceName)
3329
.readLines()
34-
.findAll { !it.startsWith('#')} // filter out comments
35-
.each { implementation("${it}") {
36-
transitive=false
37-
} }
30+
.findAll { !it.startsWith('#')} // filter out comments
31+
.each {
32+
implementation("${it}") {
33+
transitive=false
34+
}
35+
}
3836
}
3937

4038
application {

app/src/main/java/com/diffplug/spotless/cli/SpotlessCLI.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@
2424
import java.util.concurrent.Executors;
2525
import java.util.concurrent.Future;
2626

27-
import com.diffplug.spotless.cli.steps.EclipseWtp;
2827
import org.jetbrains.annotations.NotNull;
2928
import org.slf4j.Logger;
3029
import org.slf4j.LoggerFactory;
Lines changed: 43 additions & 82 deletions
Original file line numberDiff line numberDiff line change
@@ -1,123 +1,84 @@
1+
/*
2+
* Copyright 2025 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+
*/
116
package com.diffplug.spotless.cli.steps;
217

18+
import java.nio.file.Path;
19+
import java.util.List;
20+
21+
import org.jetbrains.annotations.NotNull;
322

423
import com.diffplug.spotless.FormatterStep;
5-
import com.diffplug.spotless.ThrowingEx;
624
import com.diffplug.spotless.cli.core.SpotlessActionContext;
725
import com.diffplug.spotless.cli.help.OptionConstants;
826
import com.diffplug.spotless.extra.EclipseBasedStepBuilder;
927
import com.diffplug.spotless.extra.wtp.EclipseWtpFormatterStep;
10-
import org.jetbrains.annotations.NotNull;
11-
import picocli.CommandLine;
1228

13-
import java.lang.reflect.Constructor;
14-
import java.nio.file.Path;
15-
import java.util.List;
16-
import java.util.Properties;
29+
import picocli.CommandLine;
1730

18-
@CommandLine.Command(name = "eclipse-wtp", description = "Runs Eclipse WTP formatter (" + EclipseWtp.ECLIPSE_WTP_VERSION+")")
31+
@CommandLine.Command(
32+
name = "eclipse-wtp",
33+
description = "Runs Eclipse WTP formatter (" + EclipseWtp.ECLIPSE_WTP_VERSION + ")")
1934
public class EclipseWtp extends SpotlessFormatterStep {
2035

2136
public static final String ECLIPSE_WTP_VERSION = "4.21.0"; // TODO we need to slurp in the lock file also
2237

2338
@CommandLine.Option(
2439
names = {"-f", "--config-file"},
2540
arity = "0",
26-
description = "The path to the Eclipse WTP configuration file.\n" +
27-
"For supported config file options see <https://github.com/diffplug/spotless/tree/main/plugin-gradle#eclipse-web-tools-platform>"
28-
)
41+
description =
42+
"The path to the Eclipse WTP configuration file.\n"
43+
+ "For supported config file options see <https://github.com/diffplug/spotless/tree/main/plugin-gradle#eclipse-web-tools-platform>")
2944
List<Path> configFiles;
3045

3146
@CommandLine.Option(
32-
names = { "-t", "--type" },
47+
names = {"-t", "--type"},
3348
description = "The type of the Eclipse WTP formatter." + OptionConstants.VALID_VALUES_SUFFIX,
34-
required = true
35-
)
36-
Type type;
49+
required = true)
50+
Type type; // TODO: might trying inferring type
3751

3852
public enum Type {
39-
CSS,
40-
HTML,
41-
JS,
42-
JSON,
43-
XML,
44-
XHTML;
53+
CSS(EclipseWtpFormatterStep.CSS),
54+
HTML(EclipseWtpFormatterStep.HTML),
55+
JS(EclipseWtpFormatterStep.JS),
56+
JSON(EclipseWtpFormatterStep.JSON),
57+
XML(EclipseWtpFormatterStep.XML),
58+
XHTML(EclipseWtpFormatterStep.HTML); // XHTML is treated as HTML in Eclipse WTP
4559

46-
public void initCorrespondingEclipseWtpCorePlugin() {
47-
// due to internals of eclipse wtp, invoking various variants of the formatter in the same java process
48-
// requires some static initialization to take place
60+
private final EclipseWtpFormatterStep backendEclipseWtpType;
4961

62+
Type(EclipseWtpFormatterStep backendEclipseWtpType) {
63+
this.backendEclipseWtpType = backendEclipseWtpType;
5064
}
5165

5266
public @NotNull EclipseWtpFormatterStep toEclipseWtpType() {
53-
EclipseWtpFormatterStep step = switch (this) {
54-
case CSS -> EclipseWtpFormatterStep.CSS;
55-
case HTML, XHTML -> EclipseWtpFormatterStep.HTML; // XHTML is treated as HTML in Eclipse WTP
56-
case JS -> EclipseWtpFormatterStep.JS;
57-
case JSON -> EclipseWtpFormatterStep.JSON;
58-
case XML -> EclipseWtpFormatterStep.XML;
59-
};
60-
61-
@SuppressWarnings("unused") Class<?> reverseLookup = lookupClass(step);
62-
return step;
63-
}
64-
65-
static Class<?> lookupClass(EclipseWtpFormatterStep step) {
66-
/* this statement is only here to
67-
1) get compile errors in case a new type is added in EclipseWtpFormatterStep
68-
2) allow graal to collect reflective Metadata*/
69-
@SuppressWarnings("unused") Class<?> reverseLookup = switch(step) {
70-
case CSS -> EclipseWtpMetadata.cssClass();
71-
case HTML -> EclipseWtpMetadata.htmlClass();
72-
case JS -> EclipseWtpMetadata.jsClass();
73-
case JSON -> EclipseWtpMetadata.jsonClass();
74-
case XML -> EclipseWtpMetadata.xmlClass();
75-
};
76-
return reverseLookup;
67+
return this.backendEclipseWtpType;
7768
}
7869
}
7970

80-
8171
@Override
8272
public @NotNull List<FormatterStep> prepareFormatterSteps(SpotlessActionContext context) {
8373
EclipseWtpFormatterStep wtpType = type.toEclipseWtpType();
8474
EclipseBasedStepBuilder builder = wtpType.createBuilder(context.provisioner());
8575
builder.setVersion(ECLIPSE_WTP_VERSION);
8676
if (configFiles != null && !configFiles.isEmpty()) {
87-
builder.setPreferences(
88-
configFiles.stream()
89-
.map(context::resolvePath)
90-
.map(Path::toFile)
91-
.toList());
77+
builder.setPreferences(configFiles.stream()
78+
.map(context::resolvePath)
79+
.map(Path::toFile)
80+
.toList());
9281
}
9382
return List.of(builder.build());
9483
}
95-
96-
97-
static class EclipseWtpMetadata {
98-
99-
private static Class<?> cssClass() {
100-
return ThrowingEx.get(() -> Class.forName("com.diffplug.spotless.extra.eclipse.wtp.EclipseCssFormatterStepImpl"));
101-
}
102-
103-
private static Class<?> htmlClass() {
104-
return ThrowingEx.get(() -> {
105-
Class<?> result = Class.forName("com.diffplug.spotless.extra.eclipse.wtp.EclipseHtmlFormatterStepImpl");
106-
Constructor<?> declaredConstructor = result.getDeclaredConstructor(Properties.class);
107-
return result;
108-
});
109-
}
110-
111-
private static Class<?> jsClass() {
112-
return ThrowingEx.get(() -> Class.forName("com.diffplug.spotless.extra.eclipse.wtp.EclipseJsFormatterStepImpl"));
113-
}
114-
115-
private static Class<?> jsonClass() {
116-
return ThrowingEx.get(() -> Class.forName("com.diffplug.spotless.extra.eclipse.wtp.EclipseJsonFormatterStepImpl"));
117-
}
118-
119-
private static Class<?> xmlClass() {
120-
return ThrowingEx.get(() -> Class.forName("com.diffplug.spotless.extra.eclipse.wtp.EclipseXmlFormatterStepImpl"));
121-
}
122-
}
12384
}

app/src/nativecompile/reflectconfig.json

Lines changed: 0 additions & 39 deletions
This file was deleted.

0 commit comments

Comments
 (0)