Skip to content

Commit 657e0bc

Browse files
committed
Added EquoBasedStepBuilder.addPlatformRepo which handles how the core platform IUs change with different versions.
1 parent 3ed28db commit 657e0bc

File tree

5 files changed

+45
-14
lines changed

5 files changed

+45
-14
lines changed

lib-extra/src/groovy/java/com/diffplug/spotless/extra/glue/groovy/GrEclipseFormatterStepImpl.java

Lines changed: 18 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@
3939
import org.eclipse.jface.text.IDocument;
4040
import org.eclipse.jface.text.TextSelection;
4141
import org.eclipse.text.edits.TextEdit;
42+
import org.osgi.framework.Constants;
4243

4344
import dev.equo.solstice.NestedJars;
4445
import dev.equo.solstice.ShimIdeBootstrapServices;
@@ -47,6 +48,23 @@
4748

4849
/** Spotless-Formatter step which calls out to the Groovy-Eclipse formatter. */
4950
public class GrEclipseFormatterStepImpl {
51+
static {
52+
System.setProperty("org.slf4j.simpleLogger.defaultLogLevel", "info");
53+
NestedJars.setToWarnOnly();
54+
NestedJars.onClassPath().confirmAllNestedJarsArePresentOnClasspath(CacheLocations.nestedJars());
55+
56+
var solstice = Solstice.findBundlesOnClasspath();
57+
solstice.warnAndModifyManifestsToFix();
58+
var props = Map.of("osgi.nl", "en_US",
59+
Constants.FRAMEWORK_STORAGE_CLEAN, Constants.FRAMEWORK_STORAGE_CLEAN_ONFIRSTINIT);
60+
solstice.openShim(props);
61+
ShimIdeBootstrapServices.apply(props, solstice.getContext());
62+
solstice.start("org.apache.felix.scr");
63+
solstice.startAllWithLazy(false);
64+
// solstice.start("org.eclipse.core.resources");
65+
solstice.start("org.codehaus.groovy.eclipse.core");
66+
}
67+
5068
/**
5169
* Groovy compiler problems can be ignored.
5270
* <p>
@@ -59,16 +77,6 @@ public class GrEclipseFormatterStepImpl {
5977
private final boolean ignoreFormatterProblems;
6078

6179
public GrEclipseFormatterStepImpl(final Properties properties) throws Exception {
62-
var solstice = Solstice.findBundlesOnClasspath();
63-
NestedJars.setToWarnOnly();
64-
NestedJars.onClassPath().confirmAllNestedJarsArePresentOnClasspath(CacheLocations.nestedJars());
65-
solstice.warnAndModifyManifestsToFix();
66-
var props = Map.<String, String> of();
67-
solstice.openShim(props);
68-
ShimIdeBootstrapServices.apply(props, solstice.getContext());
69-
solstice.startAllWithLazy(false);
70-
solstice.startWithoutTransitives("org.codehaus.groovy.eclipse.core");
71-
7280
PreferenceStore preferences = createPreferences(properties);
7381
preferencesStore = new FormatterPreferencesOnStore(preferences);
7482
ignoreFormatterProblems = Boolean.parseBoolean(properties.getProperty(IGNORE_FORMATTER_PROBLEMS, "false"));

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

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
import java.io.File;
1919
import java.io.Serializable;
2020
import java.util.ArrayList;
21+
import java.util.List;
2122
import java.util.Properties;
2223

2324
import com.diffplug.spotless.FileSignature;
@@ -65,12 +66,31 @@ public FormatterStep build() {
6566

6667
protected abstract P2Model model(String version);
6768

69+
protected void addPlatformRepo(P2Model model, String version) {
70+
if (!version.startsWith("4.")) {
71+
throw new IllegalArgumentException("Expected 4.x");
72+
}
73+
int minorVersion = Integer.parseInt(version.substring("4.".length()));
74+
75+
model.addP2Repo("https://download.eclipse.org/eclipse/updates/" + version + "/");
76+
model.getInstall().addAll(List.of(
77+
"org.apache.felix.scr",
78+
"org.eclipse.equinox.event"));
79+
if (minorVersion >= 25) {
80+
model.getInstall().addAll(List.of(
81+
"org.osgi.service.cm",
82+
"org.osgi.service.metatype"));
83+
}
84+
}
85+
6886
/** Creates the state of the configuration. */
6987
EquoBasedStepBuilder.State get() throws Exception {
7088
var query = model(formatterVersion).query(P2ClientCache.PREFER_OFFLINE, P2QueryCache.ALLOW);
7189
var classpath = new ArrayList<File>();
7290
var mavenDeps = new ArrayList<String>();
7391
mavenDeps.add("dev.equo.ide:solstice:0.19.1");
92+
mavenDeps.add("com.diffplug.durian:durian-swt.os:4.1.1");
93+
mavenDeps.add("org.slf4j:slf4j-simple:1.7.36");
7494
mavenDeps.addAll(query.getJarsOnMavenCentral());
7595
classpath.addAll(mavenProvisioner.provisionWithTransitives(false, mavenDeps));
7696
classpath.addAll(query.getJarsNotOnMavenCentral());

lib-extra/src/main/java/com/diffplug/spotless/extra/groovy/GrEclipseFormatterStep.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,13 +57,16 @@ protected P2Model model(String version) {
5757
greclipseVersion = "3." + (eVersion - 8) + ".0";
5858
}
5959
var model = new P2Model();
60-
model.addP2Repo("https://download.eclipse.org/eclipse/updates/" + version + "/");
60+
addPlatformRepo(model, version);
6161
model.addP2Repo("https://groovy.jfrog.io/artifactory/plugins-release/org/codehaus/groovy/groovy-eclipse-integration/" + greclipseVersion + "/e" + version + "/");
6262
model.getInstall().addAll(List.of(
6363
"org.codehaus.groovy.eclipse.refactoring",
6464
"org.codehaus.groovy.eclipse.core",
6565
"org.eclipse.jdt.groovy.core",
6666
"org.codehaus.groovy"));
67+
model.addFilterAndValidate("no-debug", filter -> {
68+
filter.exclude("org.eclipse.jdt.debug");
69+
});
6770
return model;
6871
}
6972

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ public static EquoBasedStepBuilder createBuilder(Provisioner provisioner) {
4242
@Override
4343
protected P2Model model(String version) {
4444
var model = new P2Model();
45-
model.addP2Repo("https://download.eclipse.org/eclipse/updates/" + version + "/");
45+
addPlatformRepo(model, version);
4646
model.getInstall().add("org.eclipse.jdt.core");
4747
return model;
4848
}
@@ -51,7 +51,7 @@ protected P2Model model(String version) {
5151
public void setVersion(String version) {
5252
if (version.endsWith(".0")) {
5353
String newVersion = version.substring(0, version.length() - 2);
54-
System.err.println("Recommend replacing '" + version + "' with '" + newVersion + "' for eclipse JDT");
54+
System.err.println("Recommend replacing '" + version + "' with '" + newVersion + "' for Eclipse JDT");
5555
version = newVersion;
5656
}
5757
super.setVersion(version);

lib-extra/src/test/java/com/diffplug/spotless/extra/groovy/GrEclipseFormatterStepTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,6 @@ void formatWithVersion(String version) throws Exception {
3838
}
3939

4040
private static Stream<String> formatWithVersion() {
41-
return Stream.of("4.25", GrEclipseFormatterStep.defaultVersion());
41+
return Stream.of("4.21", GrEclipseFormatterStep.defaultVersion());
4242
}
4343
}

0 commit comments

Comments
 (0)