GeezerVison is showing github.com — Merge branch 'main' into fix/npm-cache-directory-race · diffplug/spotless@0c70ca8
File treeExpand file treeCollapse file tree Open diff view settings groovy/java/com/diffplug/spotless/extra/glue/groovy main/java/com/diffplug/spotless/extra
main/java/com/diffplug/gradle/spotless test/java/com/diffplug/gradle/spotless
Expand file treeCollapse file tree Open diff view settings Collapse file Copy file name to clipboardExpand all lines: CHANGES.md +2Lines changed: 2 additions & 0 deletions - Display the source diff
- Display the rich diff
| Original file line number | Diff line number | Diff line change |
|---|
@@ -27,6 +27,8 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format ( | 27 | 27 |
| 28 | 28 | ### Fixed | 29 | 29 | - Fix race when creating the npm install cache directory. (([#3096](https://github.com/diffplug/spotless/pull/3096)) | | 30 | +- GrEclipse no longer emits expected OSGi and nested-jar warnings during initialization. ([#2445](https://github.com/diffplug/spotless/issues/2445)) | | 31 | +- `typescript` `prettier()` no longer emits a warning when its parser is already set to `typescript`. ([#3098](https://github.com/diffplug/spotless/pull/3098)) | 30 | 32 | - `VersionCatalogStep` preserves standalone comments at section boundaries and the end of the file. ([#3048](https://github.com/diffplug/spotless/issues/3048)) | 31 | 33 | - `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)) | 32 | 34 | - `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)) | |
Collapse file Copy file name to clipboardExpand all lines: lib-extra/src/groovy/java/com/diffplug/spotless/extra/glue/groovy/GrEclipseFormatterStepImpl.java +66-4Lines changed: 66 additions & 4 deletions | Original file line number | Diff line number | Diff line change |
|---|
| 17 | 17 |
| 18 | 18 | import java.io.ByteArrayInputStream; | 19 | 19 | import java.io.ByteArrayOutputStream; | | 20 | +import java.io.File; | 20 | 21 | import java.io.IOException; | | 22 | +import java.lang.reflect.Proxy; | | 23 | +import java.net.URISyntaxException; | | 24 | +import java.net.URLClassLoader; | 21 | 25 | import java.nio.file.Files; | 22 | 26 | import java.util.ArrayList; | 23 | 27 | import java.util.Collections; | | 42 | 46 | import org.eclipse.osgi.internal.location.EquinoxLocations; | 43 | 47 | import org.eclipse.text.edits.TextEdit; | 44 | 48 | import org.osgi.framework.Constants; | | 49 | +import org.slf4j.Logger; | | 50 | +import org.slf4j.LoggerFactory; | 45 | 51 |
| 46 | 52 | import dev.equo.solstice.NestedJars; | 47 | 53 | import dev.equo.solstice.ShimIdeBootstrapServices; | | 50 | 56 |
| 51 | 57 | /** Spotless-Formatter step which calls out to the Groovy-Eclipse formatter. */ | 52 | 58 | public class GrEclipseFormatterStepImpl { | | 59 | + | | 60 | + private static final Logger LOGGER = LoggerFactory.getLogger(GrEclipseFormatterStepImpl.class); | | 61 | + | | 62 | + private static Logger warnAsInfo(Logger delegate) { | | 63 | + return (Logger) Proxy.newProxyInstance( | | 64 | + Logger.class.getClassLoader(), | | 65 | + new Class<?>[]{Logger.class}, | | 66 | + (proxy, method, args) -> { | | 67 | + String name = method.getName(); | | 68 | + | | 69 | + if ("warn".equals(name)) { | | 70 | + return Logger.class | | 71 | + .getMethod("info", method.getParameterTypes()) | | 72 | + .invoke(delegate, args); | | 73 | + } | | 74 | + if ("isWarnEnabled".equals(name)) { | | 75 | + return Logger.class | | 76 | + .getMethod("isInfoEnabled", method.getParameterTypes()) | | 77 | + .invoke(delegate, args); | | 78 | + } | | 79 | + | | 80 | + return method.invoke(delegate, args); | | 81 | + }); | | 82 | + } | | 83 | + | 53 | 84 | static { | 54 | 85 | NestedJars.setToWarnOnly(); | 55 | | - NestedJars.onClassPath().confirmAllNestedJarsArePresentOnClasspath(CacheLocations.p2nestedJars()); | | 86 | + NestedJars.onClassPath().confirmAllNestedJarsArePresentOnClasspath(nestedJarFolder()); | | 87 | + | 56 | 88 | try { | 57 | 89 | var solstice = Solstice.findBundlesOnClasspath(); | 58 | | - solstice.warnAndModifyManifestsToFix(); | 59 | | - var props = Map.of("osgi.nl", "en_US", | | 90 | + | | 91 | + // Missing OSGi requirements are expected in the minimal Eclipse runtime | | 92 | + // used by the formatter. Solstice removes them before starting it. | | 93 | + solstice.warnAndModifyManifestsToFix(warnAsInfo(LOGGER)); | | 94 | + | | 95 | + var props = Map.of( | | 96 | + "osgi.nl", "en_US", | 60 | 97 | Constants.FRAMEWORK_STORAGE_CLEAN, Constants.FRAMEWORK_STORAGE_CLEAN_ONFIRSTINIT, | 61 | | - EquinoxLocations.PROP_INSTANCE_AREA, Files.createTempDirectory("spotless-groovy").toAbsolutePath().toString()); | | 98 | + EquinoxLocations.PROP_INSTANCE_AREA, | | 99 | + Files.createTempDirectory("spotless-groovy-instance").toAbsolutePath().toString(), | | 100 | + EquinoxLocations.PROP_CONFIG_AREA, | | 101 | + Files.createTempDirectory("spotless-groovy-config").toAbsolutePath().toString()); | | 102 | + | 62 | 103 | solstice.openShim(props); | 63 | 104 | ShimIdeBootstrapServices.apply(props, solstice.getContext()); | 64 | 105 | solstice.start("org.apache.felix.scr"); | @@ -69,6 +110,27 @@ public class GrEclipseFormatterStepImpl { | 69 | 110 | } | 70 | 111 | } | 71 | 112 |
| | 113 | + private static File nestedJarFolder() { | | 114 | + ClassLoader classLoader = GrEclipseFormatterStepImpl.class.getClassLoader(); | | 115 | + if (classLoader instanceof URLClassLoader urlClassLoader) { | | 116 | + for (var url : urlClassLoader.getURLs()) { | | 117 | + if (!"file".equals(url.getProtocol())) { | | 118 | + continue; | | 119 | + } | | 120 | + try { | | 121 | + File file = new File(url.toURI()); | | 122 | + File parent = file.getParentFile(); | | 123 | + if (parent != null && NestedJars.DIR.equals(parent.getName())) { | | 124 | + return parent; | | 125 | + } | | 126 | + } catch (URISyntaxException e) { | | 127 | + throw new RuntimeException(e); | | 128 | + } | | 129 | + } | | 130 | + } | | 131 | + return CacheLocations.p2nestedJars(); | | 132 | + } | | 133 | + | 72 | 134 | /** | 73 | 135 | * Groovy compiler problems can be ignored. | 74 | 136 | * <p> | |
Collapse file Copy file name to clipboardExpand all lines: lib-extra/src/main/java/com/diffplug/spotless/extra/EquoBasedStepBuilder.java +1-5Lines changed: 1 addition & 5 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -132,11 +132,7 @@ public FormatterStep build() { | 132 | 132 | } | 133 | 133 | P2Model model = createModelWithMirrors(); | 134 | 134 | P2ModelWrapper modelWrapper = P2ModelWrapper.wrap(model); | 135 | | - List<File> classpath = p2Provisioner.provisionP2Dependencies(modelWrapper, mavenProvisioner, cacheDirectory).stream() | 136 | | - // work around https://github.com/equodev/equo-ide/pull/193 | 137 | | - .filter(f -> !f.getName().contains("groovy-test")) | 138 | | - .toList(); | 139 | | - return JarState.preserveOrder(classpath); | | 135 | + return JarState.preserveOrder(p2Provisioner.provisionP2Dependencies(modelWrapper, mavenProvisioner, cacheDirectory)); | 140 | 136 | }), stepProperties.build()); | 141 | 137 | return FormatterStep.create(formatterName, roundtrippableState, EquoStep::state, stateToFormatter); | 142 | 138 | } | |
Collapse file Copy file name to clipboardExpand all lines: plugin-gradle/CHANGES.md +2Lines changed: 2 additions & 0 deletions - Display the source diff
- Display the rich diff
| Original file line number | Diff line number | Diff line change |
|---|
@@ -20,6 +20,8 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format ( | 20 | 20 |
| 21 | 21 | ### Fixed | 22 | 22 | - Fix race when creating the npm install cache directory. (([#3096](https://github.com/diffplug/spotless/pull/3096)) | | 23 | +- GrEclipse no longer emits expected OSGi and nested-jar warnings during initialization. ([#2445](https://github.com/diffplug/spotless/issues/2445)) | | 24 | +- `typescript` `prettier()` no longer emits a warning when its parser is already set to `typescript`. ([#3098](https://github.com/diffplug/spotless/pull/3098)) | 23 | 25 | - `versionCatalog()` preserves standalone comments at section boundaries and the end of the file. ([#3048](https://github.com/diffplug/spotless/issues/3048)) | 24 | 26 | - `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)) | 25 | 27 | - `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)) | |
Collapse file Copy file name to clipboardExpand all lines: plugin-gradle/src/main/java/com/diffplug/gradle/spotless/TypescriptExtension.java +2-2Lines changed: 2 additions & 2 deletions | Original file line number | Diff line number | Diff line change |
|---|
| 1 | 1 | /* | 2 | | - * Copyright 2016-2025 DiffPlug | | 2 | + * Copyright 2016-2026 DiffPlug | 3 | 3 | * | 4 | 4 | * Licensed under the Apache License, Version 2.0 (the "License"); | 5 | 5 | * you may not use this file except in compliance with the License. | @@ -170,7 +170,7 @@ protected FormatterStep createStep() { | 170 | 170 | private void fixParserToTypescript() { | 171 | 171 | if (this.prettierConfig == null) { | 172 | 172 | this.prettierConfig = new TreeMap<>(Map.of("parser", "typescript")); | 173 | | - } else { | | 173 | + } else if (!Objects.equals(this.prettierConfig.get("parser"), "typescript")) { | 174 | 174 | final Object replaced = this.prettierConfig.put("parser", "typescript"); | 175 | 175 | if (replaced != null) { | 176 | 176 | getProject().getLogger().warn("overriding parser option to 'typescript'. Was set to '{}'", | |
Collapse file Copy file name to clipboardExpand all lines: plugin-gradle/src/test/java/com/diffplug/gradle/spotless/TypescriptExtensionTest.java +48-1Lines changed: 48 additions & 1 deletion | Original file line number | Diff line number | Diff line change |
|---|
| 1 | 1 | /* | 2 | | - * Copyright 2016-2024 DiffPlug | | 2 | + * Copyright 2016-2026 DiffPlug | 3 | 3 | * | 4 | 4 | * Licensed under the Apache License, Version 2.0 (the "License"); | 5 | 5 | * you may not use this file except in compliance with the License. | | 17 | 17 |
| 18 | 18 | import java.io.IOException; | 19 | 19 |
| | 20 | +import org.assertj.core.api.Assertions; | | 21 | +import org.gradle.testkit.runner.BuildResult; | 20 | 22 | import org.junit.jupiter.api.Disabled; | 21 | 23 | import org.junit.jupiter.api.Test; | 22 | 24 |
| @@ -209,4 +211,49 @@ void useEslintStandardWithTypescriptRules() throws IOException { | 209 | 211 | gradleRunner().withArguments("--stacktrace", "spotlessApply").build(); | 210 | 212 | assertFile("test.ts").sameAsResource("npm/eslint/typescript/styleguide/standard_with_typescript/typescript.clean"); | 211 | 213 | } | | 214 | + | | 215 | + @Test | | 216 | + void prettierDoesNotWarnWhenTypescriptParserIsAlreadySet() throws IOException { | | 217 | + setFile(".prettierrc.json").toContent("{}"); | | 218 | + setFile("build.gradle").toLines( | | 219 | + "plugins {", | | 220 | + " id 'com.diffplug.spotless'", | | 221 | + "}", | | 222 | + "repositories { mavenCentral() }", | | 223 | + "spotless {", | | 224 | + " typescript {", | | 225 | + " target 'test.ts'", | | 226 | + " prettier().npmInstallCache().configFile('.prettierrc.json')", | | 227 | + " }", | | 228 | + "}"); | | 229 | + setFile("test.ts").toResource("npm/prettier/filetypes/typescript/typescript.dirty"); | | 230 | + | | 231 | + BuildResult result = gradleRunner().withArguments("--stacktrace", "spotlessApply").build(); | | 232 | + | | 233 | + Assertions.assertThat(result.getOutput()) | | 234 | + .doesNotContain("overriding parser option to 'typescript'. Was set to 'typescript'"); | | 235 | + assertFile("test.ts").sameAsResource("npm/prettier/filetypes/typescript/typescript.clean"); | | 236 | + } | | 237 | + | | 238 | + @Test | | 239 | + void prettierWarnsWhenOverridingNonTypescriptParser() throws IOException { | | 240 | + setFile("build.gradle").toLines( | | 241 | + "plugins {", | | 242 | + " id 'com.diffplug.spotless'", | | 243 | + "}", | | 244 | + "repositories { mavenCentral() }", | | 245 | + "spotless {", | | 246 | + " typescript {", | | 247 | + " target 'test.ts'", | | 248 | + " prettier().config(['parser': 'babel'])", | | 249 | + " }", | | 250 | + "}"); | | 251 | + setFile("test.ts").toResource("npm/prettier/filetypes/typescript/typescript.dirty"); | | 252 | + | | 253 | + BuildResult result = gradleRunner().withArguments("--stacktrace", "spotlessApply").build(); | | 254 | + | | 255 | + Assertions.assertThat(result.getOutput()) | | 256 | + .contains("overriding parser option to 'typescript'. Was set to 'babel'"); | | 257 | + assertFile("test.ts").sameAsResource("npm/prettier/filetypes/typescript/typescript.clean"); | | 258 | + } | 212 | 259 | } |
Collapse file Copy file name to clipboardExpand all lines: plugin-maven/CHANGES.md +2Lines changed: 2 additions & 0 deletions - Display the source diff
- Display the rich diff
| Original file line number | Diff line number | Diff line change |
|---|
@@ -19,6 +19,8 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format ( | 19 | 19 |
| 20 | 20 | ### Fixed | 21 | 21 | - Fix race when creating the npm install cache directory. (([#3096](https://github.com/diffplug/spotless/pull/3096)) | | 22 | +- GrEclipse no longer emits expected OSGi and nested-jar warnings during initialization. ([#2445](https://github.com/diffplug/spotless/issues/2445)) | | 23 | +- `typescript` `prettier()` no longer emits a warning when its parser is already set to `typescript`. ([#3098](https://github.com/diffplug/spotless/pull/3098)) | 22 | 24 | - `<versionCatalog>` preserves standalone comments at section boundaries and the end of the file. ([#3048](https://github.com/diffplug/spotless/issues/3048)) | 23 | 25 | - `<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)) | 24 | 26 | - `<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)) | |
|