Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand All @@ -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");
Expand All @@ -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.
* <p>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -132,11 +132,7 @@ public FormatterStep build() {
}
P2Model model = createModelWithMirrors();
P2ModelWrapper modelWrapper = P2ModelWrapper.wrap(model);
List<File> classpath = p2Provisioner.provisionP2Dependencies(modelWrapper, mavenProvisioner, cacheDirectory).stream()
// work around https://github.com/equodev/equo-ide/pull/193
.filter(f -> !f.getName().contains("groovy-test"))
.toList();
return JarState.preserveOrder(classpath);
return JarState.preserveOrder(p2Provisioner.provisionP2Dependencies(modelWrapper, mavenProvisioner, cacheDirectory));
}), stepProperties.build());
return FormatterStep.create(formatterName, roundtrippableState, EquoStep::state, stateToFormatter);
}
Expand Down
3 changes: 2 additions & 1 deletion plugin-gradle/CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format (
- We no longer publish a plugin marker for the legacy `com.diffplug.gradle.spotless` id, which has been redirecting to `com.diffplug.spotless` since 4.0. Builds that still request it now fail with `Plugin [id: 'com.diffplug.gradle.spotless'] was not found` instead of the migration message. ([#3086](https://github.com/diffplug/spotless/pull/3086))

### 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))
- `versionCatalog()` preserves standalone comments at section boundaries and the end of the file. ([#3048](https://github.com/diffplug/spotless/issues/3048))
- `versionCatalog()` 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))
- `versionCatalog()` 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))
Expand Down
3 changes: 2 additions & 1 deletion plugin-maven/CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,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))
- `<versionCatalog>` preserves standalone comments at section boundaries and the end of the file. ([#3048](https://github.com/diffplug/spotless/issues/3048))
- `<versionCatalog>` 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))
- `<versionCatalog>` 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))
Expand Down
Loading