diff --git a/CHANGES.md b/CHANGES.md index f49f92c98c..8f6920ca6c 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -26,7 +26,8 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format ( - Bump default `gherkin-utils` version `10.0.0` -> `12.0.2`. ([#2979](https://github.com/diffplug/spotless/pull/2979)) ### Fixed -* `typescript` `prettier()` no longer emits a warning when its parser is already set to `typescript`. ([#3098](https://github.com/diffplug/spotless/pull/3098)) +- GrEclipse no longer emits expected OSGi and nested-jar warnings during initialization. ([#2445](https://github.com/diffplug/spotless/issues/2445)) +- `typescript` `prettier()` no longer emits a warning when its parser is already set to `typescript`. ([#3098](https://github.com/diffplug/spotless/pull/3098)) - `VersionCatalogStep` preserves standalone comments at section boundaries and the end of the file. ([#3048](https://github.com/diffplug/spotless/issues/3048)) - `VersionCatalogStep` preserves entries when comments contain unmatched brackets, preserves commas inside quoted strings, and keeps significant line boundaries in multiline entries. ([#3042](https://github.com/diffplug/spotless/pull/3042)) - `VersionCatalogStep` now reports unfinished entries as lints at their starting line. These fail formatting by default, so upgrading may expose catalog errors that previously caused silent data loss. ([#3042](https://github.com/diffplug/spotless/pull/3042)) diff --git a/lib-extra/src/groovy/java/com/diffplug/spotless/extra/glue/groovy/GrEclipseFormatterStepImpl.java b/lib-extra/src/groovy/java/com/diffplug/spotless/extra/glue/groovy/GrEclipseFormatterStepImpl.java index 170588e954..861729e798 100644 --- a/lib-extra/src/groovy/java/com/diffplug/spotless/extra/glue/groovy/GrEclipseFormatterStepImpl.java +++ b/lib-extra/src/groovy/java/com/diffplug/spotless/extra/glue/groovy/GrEclipseFormatterStepImpl.java @@ -17,7 +17,11 @@ import java.io.ByteArrayInputStream; import java.io.ByteArrayOutputStream; +import java.io.File; import java.io.IOException; +import java.lang.reflect.Proxy; +import java.net.URISyntaxException; +import java.net.URLClassLoader; import java.nio.file.Files; import java.util.ArrayList; import java.util.Collections; @@ -42,6 +46,8 @@ import org.eclipse.osgi.internal.location.EquinoxLocations; import org.eclipse.text.edits.TextEdit; import org.osgi.framework.Constants; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import dev.equo.solstice.NestedJars; import dev.equo.solstice.ShimIdeBootstrapServices; @@ -50,15 +56,50 @@ /** Spotless-Formatter step which calls out to the Groovy-Eclipse formatter. */ public class GrEclipseFormatterStepImpl { + + private static final Logger LOGGER = LoggerFactory.getLogger(GrEclipseFormatterStepImpl.class); + + private static Logger warnAsInfo(Logger delegate) { + return (Logger) Proxy.newProxyInstance( + Logger.class.getClassLoader(), + new Class>[]{Logger.class}, + (proxy, method, args) -> { + String name = method.getName(); + + if ("warn".equals(name)) { + return Logger.class + .getMethod("info", method.getParameterTypes()) + .invoke(delegate, args); + } + if ("isWarnEnabled".equals(name)) { + return Logger.class + .getMethod("isInfoEnabled", method.getParameterTypes()) + .invoke(delegate, args); + } + + return method.invoke(delegate, args); + }); + } + static { NestedJars.setToWarnOnly(); - NestedJars.onClassPath().confirmAllNestedJarsArePresentOnClasspath(CacheLocations.p2nestedJars()); + NestedJars.onClassPath().confirmAllNestedJarsArePresentOnClasspath(nestedJarFolder()); + try { var solstice = Solstice.findBundlesOnClasspath(); - solstice.warnAndModifyManifestsToFix(); - var props = Map.of("osgi.nl", "en_US", + + // Missing OSGi requirements are expected in the minimal Eclipse runtime + // used by the formatter. Solstice removes them before starting it. + solstice.warnAndModifyManifestsToFix(warnAsInfo(LOGGER)); + + var props = Map.of( + "osgi.nl", "en_US", Constants.FRAMEWORK_STORAGE_CLEAN, Constants.FRAMEWORK_STORAGE_CLEAN_ONFIRSTINIT, - EquinoxLocations.PROP_INSTANCE_AREA, Files.createTempDirectory("spotless-groovy").toAbsolutePath().toString()); + EquinoxLocations.PROP_INSTANCE_AREA, + Files.createTempDirectory("spotless-groovy-instance").toAbsolutePath().toString(), + EquinoxLocations.PROP_CONFIG_AREA, + Files.createTempDirectory("spotless-groovy-config").toAbsolutePath().toString()); + solstice.openShim(props); ShimIdeBootstrapServices.apply(props, solstice.getContext()); solstice.start("org.apache.felix.scr"); @@ -69,6 +110,27 @@ public class GrEclipseFormatterStepImpl { } } + private static File nestedJarFolder() { + ClassLoader classLoader = GrEclipseFormatterStepImpl.class.getClassLoader(); + if (classLoader instanceof URLClassLoader urlClassLoader) { + for (var url : urlClassLoader.getURLs()) { + if (!"file".equals(url.getProtocol())) { + continue; + } + try { + File file = new File(url.toURI()); + File parent = file.getParentFile(); + if (parent != null && NestedJars.DIR.equals(parent.getName())) { + return parent; + } + } catch (URISyntaxException e) { + throw new RuntimeException(e); + } + } + } + return CacheLocations.p2nestedJars(); + } + /** * Groovy compiler problems can be ignored. *
diff --git a/lib-extra/src/main/java/com/diffplug/spotless/extra/EquoBasedStepBuilder.java b/lib-extra/src/main/java/com/diffplug/spotless/extra/EquoBasedStepBuilder.java
index b6a4a1be08..9c17ca9163 100644
--- a/lib-extra/src/main/java/com/diffplug/spotless/extra/EquoBasedStepBuilder.java
+++ b/lib-extra/src/main/java/com/diffplug/spotless/extra/EquoBasedStepBuilder.java
@@ -132,11 +132,7 @@ public FormatterStep build() {
}
P2Model model = createModelWithMirrors();
P2ModelWrapper modelWrapper = P2ModelWrapper.wrap(model);
- List