GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — Merge branch 'main' into add-cache-directory-dsl · diffplug/spotless@a266fc2

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
  • CHANGES.md
  • lib-extra
    • build.gradle
    • src/jdt/java/com/diffplug/spotless/extra/glue/jdt
      • DefaultJavaElementComparator.java
      • EclipseJdtSortMembers.java
  • lib/src
    • javaParser/java/com/diffplug/spotless/glue/javaparser
      • ExpandWildcardsFormatterFunc.java
    • main/java/com/diffplug/spotless
      • java
        • ForbidModuleImportsStep.java
        • ForbidWildcardImportsStep.java
      • toml
        • VersionCatalogStep.java
  • plugin-gradle
    • CHANGES.md
    • src/main/java/com/diffplug/gradle/spotless
      • TomlExtension.java
  • plugin-maven
    • CHANGES.md
    • src
      • main/java/com/diffplug/spotless/maven/toml
        • VersionCatalog.java
      • test/java/com/diffplug/spotless/maven/java
        • ExpandWildcardImportsStepTest.java
  • testlib/src
    • main/resources
      • java/expandwildcardimports
        • PomDepWildcardImportsFormatted.test
        • PomDepWildcardImportsUnformatted.test
        • example-model.jar
      • toml
        • versionCatalogClean.toml
    • test/java/com/diffplug/spotless
      • java
        • ForbidModuleImportsStepTest.java
        • ForbidWildcardImportsStepTest.java
      • toml
        • VersionCatalogStepTest.java
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎CHANGES.md‎

Copy file name to clipboardExpand all lines: CHANGES.md
+4Lines changed: 4 additions & 0 deletions
  • Display the source diff
  • Display the rich diff
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,12 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format (
1212
## [Unreleased]
1313
### Fixed
1414
- `P2Provisioner` now passes cache directory overrides directly to Solstice. ([#2944](https://github.com/diffplug/spotless/pull/2944))
15+
- `forbidWildcardImports` and `forbidModuleImports` now detect imports that have leading whitespace (indentation/tabs). ([#2939](https://github.com/diffplug/spotless/pull/2939))
16+
- `versionCatalog` step no longer splits long inline tables across multiple lines — Gradle's TOML 1.0 parser cannot read multi-line inline tables. The `maxLineLength` option has been removed. ([#2948](https://github.com/diffplug/spotless/issues/2948))
1517
### Changes
18+
- `EclipseJdtFormtterStep` now can conditionally set compiler source/compliance options. Allows for better parsing of AST Node for newer language features and more correct sorting; e.g. records or seal classes. ([#2942](https://github.com/diffplug/spotless/pull/2942))
1619
- `Formatter` no longer recomputes line-ending normalization (`LineEnding.toUnix`) a second time for every formatter step that changes content, removing redundant O(n) work from the core formatting loop. ([#2934](https://github.com/diffplug/spotless/pull/2934))
20+
- expandWildcardImports support pom type dependency. ([#2839](https://github.com/diffplug/spotless/issues/2839))
1721

1822
## [4.6.1] - 2026-05-15
1923
### Fixed
Collapse file

‎lib-extra/build.gradle‎

Copy file name to clipboardExpand all lines: lib-extra/build.gradle
+3Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,9 @@ def jar = tasks.named('jar', Jar) {
7070
tasks.withType(Test).configureEach {
7171
dependsOn jar
7272
classpath += jar.get().outputs.files
73+
// P2 tests use a process-level file lock; parallel forks race for it.
74+
// In-JVM synchronization in TestP2Provisioner is enough, so one fork is sufficient.
75+
maxParallelForks = 1
7376
}
7477

7578
apply plugin: 'dev.equo.p2deps'
Collapse file

‎lib-extra/src/jdt/java/com/diffplug/spotless/extra/glue/jdt/DefaultJavaElementComparator.java‎

Copy file name to clipboardExpand all lines: lib-extra/src/jdt/java/com/diffplug/spotless/extra/glue/jdt/DefaultJavaElementComparator.java
+2Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -190,6 +190,7 @@ private int category(BodyDeclaration bodyDeclaration) {
190190
}
191191
case ASTNode.TYPE_DECLARATION:
192192
case ASTNode.ENUM_DECLARATION:
193+
case ASTNode.RECORD_DECLARATION:
193194
case ASTNode.ANNOTATION_TYPE_DECLARATION:
194195
return TYPE_INDEX;
195196
case ASTNode.ENUM_CONSTANT_DECLARATION:
@@ -315,6 +316,7 @@ public int compare(BodyDeclaration bodyDeclaration1, BodyDeclaration bodyDeclara
315316
}
316317
case ASTNode.TYPE_DECLARATION:
317318
case ASTNode.ENUM_DECLARATION:
319+
case ASTNode.RECORD_DECLARATION:
318320
case ASTNode.ANNOTATION_TYPE_DECLARATION: {
319321
AbstractTypeDeclaration type1 = (AbstractTypeDeclaration) bodyDeclaration1;
320322
AbstractTypeDeclaration type2 = (AbstractTypeDeclaration) bodyDeclaration2;
Collapse file

‎lib-extra/src/jdt/java/com/diffplug/spotless/extra/glue/jdt/EclipseJdtSortMembers.java‎

Copy file name to clipboardExpand all lines: lib-extra/src/jdt/java/com/diffplug/spotless/extra/glue/jdt/EclipseJdtSortMembers.java
+49-2Lines changed: 49 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2024-2025 DiffPlug
2+
* Copyright 2024-2026 DiffPlug
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -29,6 +29,7 @@
2929
import org.eclipse.jdt.core.ICompilationUnit;
3030
import org.eclipse.jdt.core.IJavaElement;
3131
import org.eclipse.jdt.core.IOpenable;
32+
import org.eclipse.jdt.core.JavaCore;
3233
import org.eclipse.jdt.core.JavaModelException;
3334
import org.eclipse.jdt.core.dom.AST;
3435
import org.eclipse.jdt.internal.core.SortElementsOperation;
@@ -220,7 +221,53 @@ private static class JavaProject extends org.eclipse.jdt.internal.core.JavaProje
220221

221222
@Override
222223
public Map<String, String> getOptions(boolean inheritJavaCoreOptions) {
223-
return Map.of();
224+
String javaVersion = getCompilerSourceAndComplianceVersion();
225+
if (javaVersion == null) {
226+
return Map.of();
227+
}
228+
229+
return Map.of(
230+
JavaCore.COMPILER_SOURCE, javaVersion,
231+
JavaCore.COMPILER_COMPLIANCE, javaVersion);
232+
}
233+
234+
/**
235+
* Returns the Java major version. This will format it in a way consistent with the {@link JavaCore}'s version
236+
* constants. 1.8.0_123 -> 1.8 per {@link JavaCore#VERSION_1_8}
237+
*/
238+
private String extractMajorVersion(String version) {
239+
if (version.startsWith("1.")) {
240+
// Legacy format: "1.8.0_301" -> "1.8"
241+
int secondDot = version.indexOf(".", 2);
242+
return secondDot != -1 ? version.substring(0, secondDot) : version;
243+
} else {
244+
// Modern format: "17.0.1" -> "17"
245+
int firstDot = version.indexOf(".");
246+
return firstDot != -1 ? version.substring(0, firstDot) : version;
247+
}
248+
}
249+
250+
/**
251+
* Use the java runtime version to guess version to use for compiler source & compiler compliance.
252+
*
253+
* @see JavaCore#COMPILER_SOURCE
254+
* @see JavaCore#COMPILER_COMPLIANCE
255+
*/
256+
private String getCompilerSourceAndComplianceVersion() {
257+
String major = extractMajorVersion(System.getProperty("java.version"));
258+
if (JavaCore.getAllVersions().contains(major)) {
259+
return major;
260+
}
261+
try {
262+
String maxSupported = JavaCore.latestSupportedJavaVersion();
263+
if (Double.parseDouble(major) > Double.parseDouble(maxSupported)) {
264+
return maxSupported;
265+
}
266+
} catch (NumberFormatException e) {
267+
// fall through
268+
}
269+
// if we cannot determine version number leave unspecified.
270+
return null;
224271
}
225272
}
226273

Collapse file

‎lib/src/javaParser/java/com/diffplug/spotless/glue/javaparser/ExpandWildcardsFormatterFunc.java‎

Copy file name to clipboardExpand all lines: lib/src/javaParser/java/com/diffplug/spotless/glue/javaparser/ExpandWildcardsFormatterFunc.java
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ public ExpandWildcardsFormatterFunc(Collection<File> typeSolverClasspath) throws
7272
CombinedTypeSolver combinedTypeSolver = new CombinedTypeSolver();
7373
combinedTypeSolver.add(new ReflectionTypeSolver(ReflectionTypeSolver.JCL_ONLY));
7474
for (File element : typeSolverClasspath) {
75-
if (element.isFile()) {
75+
if (element.isFile() && element.getName().endsWith(".jar")) {
7676
combinedTypeSolver.add(new JarTypeSolver(element));
7777
} else if (element.isDirectory()) {
7878
combinedTypeSolver.add(new JavaParserTypeSolver(element));
Collapse file

‎lib/src/main/java/com/diffplug/spotless/java/ForbidModuleImportsStep.java‎

Copy file name to clipboardExpand all lines: lib/src/main/java/com/diffplug/spotless/java/ForbidModuleImportsStep.java
+2-2Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2025 DiffPlug
2+
* Copyright 2025-2026 DiffPlug
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -24,7 +24,7 @@ public final class ForbidModuleImportsStep {
2424
/**
2525
* Matches lines like 'import module java.base;' or 'import module java.sql;'.
2626
*/
27-
private static final String REGEX = "(?m)^import module[^;\\n]*;\\R?";
27+
private static final String REGEX = "(?m)^[ \\t]*import\\s+module\\s+[^;\\n]*;\\R?";
2828
private static final String NAME = "forbidModuleImports";
2929
private static final String ERROR = "Do not use module imports - replace with specific class imports as 'spotlessApply' cannot auto-fix this";
3030

Collapse file

‎lib/src/main/java/com/diffplug/spotless/java/ForbidWildcardImportsStep.java‎

Copy file name to clipboardExpand all lines: lib/src/main/java/com/diffplug/spotless/java/ForbidWildcardImportsStep.java
+2-2Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2025 DiffPlug
2+
* Copyright 2025-2026 DiffPlug
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -24,7 +24,7 @@ public final class ForbidWildcardImportsStep {
2424
/**
2525
* Matches lines like 'import foo.*;' or 'import static foo.*;'.
2626
*/
27-
private static final String REGEX = "(?m)^import\\s+(?:static\\s+)?[^;\\n]*\\*;\\R?";
27+
private static final String REGEX = "(?m)^[ \\t]*import\\s+(?:static\\s+)?[^;\\n]*\\*;\\R?";
2828
private static final String NAME = "forbidWildcardImports";
2929
private static final String ERROR = "Do not use wildcard imports (e.g. java.util.*) - replace with specific class imports (e.g. java.util.List) as 'spotlessApply' cannot auto-fix this";
3030

Collapse file

‎lib/src/main/java/com/diffplug/spotless/toml/VersionCatalogStep.java‎

Copy file name to clipboardExpand all lines: lib/src/main/java/com/diffplug/spotless/toml/VersionCatalogStep.java
+8-63Lines changed: 8 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,6 @@ public final class VersionCatalogStep {
3333
private VersionCatalogStep() {}
3434

3535
private static final String NAME = "versionCatalog";
36-
private static final int DEFAULT_MAX_LINE_LENGTH = 120;
3736

3837
private static final List<String> TABLE_ORDER = Arrays.asList(
3938
"[versions]",
@@ -45,20 +44,16 @@ private VersionCatalogStep() {}
4544
private static final Pattern ENTRY_LINE = Pattern.compile("^([^=]+)=(.+)$");
4645

4746
public static FormatterStep create() {
48-
return create(false, DEFAULT_MAX_LINE_LENGTH);
47+
return create(false);
4948
}
5049

5150
public static FormatterStep create(boolean stripQuotedKeys) {
52-
return create(stripQuotedKeys, DEFAULT_MAX_LINE_LENGTH);
53-
}
54-
55-
public static FormatterStep create(boolean stripQuotedKeys, int maxLineLength) {
5651
return FormatterStep.createLazy(NAME,
57-
() -> new State(stripQuotedKeys, maxLineLength),
52+
() -> new State(stripQuotedKeys),
5853
State::toFormatter);
5954
}
6055

61-
static String format(String raw, boolean stripQuotedKeys, int maxLineLength) {
56+
static String format(String raw, boolean stripQuotedKeys) {
6257
if (raw.trim().isEmpty()) {
6358
return raw;
6459
}
@@ -95,8 +90,7 @@ static String format(String raw, boolean stripQuotedKeys, int maxLineLength) {
9590
result.append(header).append('\n');
9691

9792
for (Entry entry : entries) {
98-
String formatted = formatEntry(entry.content, stripQuotedKeys);
99-
entry.formatted = applyLineLength(formatted, maxLineLength);
93+
entry.formatted = formatEntry(entry.content, stripQuotedKeys);
10094
}
10195
Collections.sort(entries, Comparator.comparing(Entry::sortKey));
10296

@@ -191,8 +185,7 @@ private static boolean isBalanced(String text) {
191185
}
192186

193187
private static String extractKey(String formattedEntry) {
194-
String firstLine = formattedEntry.contains("\n") ? formattedEntry.substring(0, formattedEntry.indexOf('\n')) : formattedEntry;
195-
Matcher matcher = ENTRY_LINE.matcher(firstLine);
188+
Matcher matcher = ENTRY_LINE.matcher(formattedEntry);
196189
if (!matcher.matches()) {
197190
return formattedEntry;
198191
}
@@ -231,52 +224,6 @@ static String formatEntry(String entry, boolean stripQuotedKeys) {
231224
return key + " = " + value;
232225
}
233226

234-
private static String applyLineLength(String formattedEntry, int maxLineLength) {
235-
if (maxLineLength <= 0) {
236-
return formattedEntry;
237-
}
238-
239-
String inlineComment = extractInlineComment(formattedEntry);
240-
String entryWithoutComment = inlineComment != null
241-
? formattedEntry.substring(0, formattedEntry.length() - inlineComment.length()).trim()
242-
: formattedEntry;
243-
244-
Matcher matcher = ENTRY_LINE.matcher(entryWithoutComment);
245-
if (!matcher.matches()) {
246-
return formattedEntry;
247-
}
248-
249-
String key = matcher.group(1).trim();
250-
String value = matcher.group(2).trim();
251-
String commentSuffix = inlineComment != null ? " " + inlineComment : "";
252-
253-
if (value.startsWith("{") && value.endsWith("}")) {
254-
if (formattedEntry.length() > maxLineLength) {
255-
return splitInlineTable(key, value, commentSuffix);
256-
}
257-
return formattedEntry;
258-
}
259-
260-
return formattedEntry;
261-
}
262-
263-
private static String splitInlineTable(String key, String value, String commentSuffix) {
264-
String inner = value.substring(1, value.length() - 1).trim();
265-
String[] pairs = splitTopLevel(inner, ',');
266-
267-
StringBuilder result = new StringBuilder();
268-
result.append(key).append(" = {").append(commentSuffix).append('\n');
269-
for (int i = 0; i < pairs.length; i++) {
270-
String pair = pairs[i].trim();
271-
if (pair.isEmpty()) {
272-
continue;
273-
}
274-
result.append(" ").append(pair).append(',').append('\n');
275-
}
276-
result.append('}');
277-
return result.toString();
278-
}
279-
280227
private static String extractInlineComment(String valueAndComment) {
281228
boolean inQuote = false;
282229
int depth = 0;
@@ -398,18 +345,16 @@ private static boolean isBareKey(String key) {
398345
}
399346

400347
private static final class State implements Serializable {
401-
private static final long serialVersionUID = 2L;
348+
private static final long serialVersionUID = 3L;
402349

403350
private final boolean stripQuotedKeys;
404-
private final int maxLineLength;
405351

406-
State(boolean stripQuotedKeys, int maxLineLength) {
352+
State(boolean stripQuotedKeys) {
407353
this.stripQuotedKeys = stripQuotedKeys;
408-
this.maxLineLength = maxLineLength;
409354
}
410355

411356
FormatterFunc toFormatter() {
412-
return raw -> format(raw, stripQuotedKeys, maxLineLength);
357+
return raw -> format(raw, stripQuotedKeys);
413358
}
414359
}
415360

Collapse file

‎plugin-gradle/CHANGES.md‎

Copy file name to clipboardExpand all lines: plugin-gradle/CHANGES.md
+4Lines changed: 4 additions & 0 deletions
  • Display the source diff
  • Display the rich diff
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,10 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format (
55
## [Unreleased]
66
### Added
77
- Add `cacheDirectory(...)` to `eclipse()`, `eclipseCdt()`, and `greclipse()`; the default P2 cache is `$GRADLE_USER_HOME/caches/p2-data`. ([#2944](https://github.com/diffplug/spotless/pull/2944))
8+
### Fixed
9+
- `forbidWildcardImports` and `forbidModuleImports` now detect imports that have leading whitespace (indentation/tabs). ([#2939](https://github.com/diffplug/spotless/pull/2939))
10+
- `versionCatalog()` no longer splits long inline tables across multiple lines — Gradle's TOML 1.0 parser cannot read multi-line inline tables. The `maxLineLength` option has been removed. ([#2948](https://github.com/diffplug/spotless/issues/2948))
11+
- `EclipseJdtFormtterStep` now can conditionally set compiler source/compliance options. Allows for better parsing of AST Node for newer language features and more correct sorting; e.g. records or seal classes. ([#2942](https://github.com/diffplug/spotless/pull/2942))
812
### Changes
913
- Improved formatting performance by eliminating redundant per-step line-ending normalization in the core formatter loop. ([#2934](https://github.com/diffplug/spotless/pull/2934))
1014

Collapse file

‎plugin-gradle/src/main/java/com/diffplug/gradle/spotless/TomlExtension.java‎

Copy file name to clipboardExpand all lines: plugin-gradle/src/main/java/com/diffplug/gradle/spotless/TomlExtension.java
+1-7Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,6 @@ public VersionCatalogConfig versionCatalog() {
4242

4343
public class VersionCatalogConfig {
4444
private boolean stripQuotedKeys;
45-
private int maxLineLength = 120;
4645

4746
public VersionCatalogConfig() {
4847
this.stripQuotedKeys = false;
@@ -54,13 +53,8 @@ public void stripQuotedKeys(boolean stripQuotedKeys) {
5453
replaceStep(createStep());
5554
}
5655

57-
public void maxLineLength(int maxLineLength) {
58-
this.maxLineLength = maxLineLength;
59-
replaceStep(createStep());
60-
}
61-
6256
private FormatterStep createStep() {
63-
return VersionCatalogStep.create(stripQuotedKeys, maxLineLength);
57+
return VersionCatalogStep.create(stripQuotedKeys);
6458
}
6559
}
6660
}

0 commit comments

Comments
0 (0)
You are visitor 01402775 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.