Skip to content

Commit 64d94c4

Browse files
author
Vincent Potucek
committed
new step to expand java wildcard imports #2744 #2594
1 parent fed07d9 commit 64d94c4

File tree

19 files changed

+539
-57
lines changed

19 files changed

+539
-57
lines changed

.github/workflows/ci.yml

Lines changed: 30 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,51 +1,47 @@
1-
# BUILDCACHE_USER
2-
# BUILDCACHE_PASS
3-
# - rw access to buildcache.diffplug.com
4-
1+
name: CI ♻️
52
on:
63
pull_request:
74
push:
85
branches: [main, release]
96
workflow_dispatch:
10-
117
concurrency:
128
group: ${{ github.workflow }}-${{ github.ref }}
139
cancel-in-progress: true
1410
jobs:
1511
sanity-check:
16-
name: SanityCheck
12+
name: SanityCheck 🕊️
1713
runs-on: ubuntu-latest
1814
env:
1915
buildcacheuser: ${{ secrets.BUILDCACHE_USER }}
2016
buildcachepass: ${{ secrets.BUILDCACHE_PASS }}
2117
steps:
22-
- name: Checkout
18+
- name: Checkout 📥
2319
uses: actions/checkout@v6
2420
with:
2521
fetch-depth: 0
26-
- uses: actions/setup-java@v5
22+
- name: Setup Java ☕️
23+
uses: actions/setup-java@v5
2724
with:
2825
distribution: "temurin"
2926
java-version: 21
30-
- name: gradle caching
27+
- name: Gradle Caching 💾
3128
uses: gradle/actions/setup-gradle@v5
32-
- name: spotlessCheck
29+
- name: Spotless Check ✨
3330
run: ./gradlew spotlessCheck
34-
- name: rewriteDryRun
31+
- name: Rewrite Dry Run 🌀
3532
run: ./gradlew rewriteDryRun
36-
- name: assemble testClasses
33+
- name: Assemble TestClasses ⚙️
3734
run: ./gradlew assemble testClasses
3835
build:
36+
name: Build 🏗️
3937
needs: sanity-check
4038
strategy:
4139
fail-fast: false
4240
matrix:
4341
kind: [maven, gradle]
44-
# Test on the latest Java version once Gradle & Maven support it.
45-
jre: [17, 21, 24]
42+
jre: [17, 21, 24] # Test on the latest Java version once Gradle & Maven support it.
4643
os: [ubuntu-latest, windows-latest]
47-
include:
48-
# npm on linux only (crazy slow on windows)
44+
include: # npm on linux only (crazy slow on windows)
4945
- kind: npm
5046
jre: 17
5147
os: ubuntu-latest
@@ -58,36 +54,37 @@ jobs:
5854
os: ubuntu-latest
5955
runs-on: ${{ matrix.os }}
6056
steps:
61-
- name: Checkout
57+
- name: Checkout 📥
6258
uses: actions/checkout@v6
63-
- uses: actions/setup-java@v5
59+
- name: Setup Java ☕️
60+
uses: actions/setup-java@v5
6461
with:
6562
distribution: "temurin"
6663
java-version: ${{ matrix.jre }}
67-
- name: gradle caching
64+
- name: Gradle Caching 💾
6865
uses: gradle/actions/setup-gradle@v5
69-
- name: build (maven-only)
66+
- name: Build (Maven) 🏗️
7067
if: matrix.kind == 'maven'
7168
run: ./gradlew :plugin-maven:build -x spotlessCheck -x rewriteDryRun
72-
- name: build (everything-but-maven)
69+
- name: Build (Gradle) 🏗️
7370
if: matrix.kind == 'gradle'
7471
run: ./gradlew build -x spotlessCheck -x rewriteDryRun -PSPOTLESS_EXCLUDE_MAVEN=true
75-
- name: test npm
72+
- name: Test NPM 🧪
7673
if: matrix.kind == 'npm'
7774
run: ./gradlew testNpm
78-
- name: Setup go
75+
- name: Setup Go 🦫
7976
if: matrix.kind == 'shfmt'
8077
uses: actions/setup-go@v6
8178
with:
8279
go-version: 'stable'
83-
- name: Install shfmt
80+
- name: Install shfmt 🔧
8481
if: matrix.kind == 'shfmt'
8582
run: |
8683
go install mvdan.cc/sh/v3/cmd/shfmt@${{ matrix.shfmt-version }}
87-
- name: Test shfmt
84+
- name: Test shfmt 🧪
8885
if: matrix.kind == 'shfmt'
8986
run: ./gradlew testShfmt
90-
- name: Test idea
87+
- name: Test IntelliJ IDEA 🧪
9188
if: matrix.kind == 'idea'
9289
run: |
9390
download_link=$(curl https://data.services.jetbrains.com/products/releases\?code\=IIC\&latest\=true\&type\=release | jq -r '.IIC[0].downloads.linux.link')
@@ -97,27 +94,26 @@ jobs:
9794
export PATH=${PATH}:$(pwd)/bin
9895
cd ..
9996
./gradlew testIdea
100-
- name: junit result
97+
- name: Test Results 📊
10198
uses: mikepenz/action-junit-report@v6
10299
if: always() # always run even if the previous step fails
103100
with:
104-
check_name: JUnit ${{ matrix.kind }} ${{ matrix.jre }} ${{ matrix.os }}
101+
check_name: JUnit (Build 🏗 ${{ matrix.kind }}️, Java ☕️ ${{ matrix.jre }}, OS 💿 ${{ matrix.os }})
105102
report_paths: '*/build/test-results/*/TEST-*.xml'
106103
check_retries: true
107-
108-
# Status check that is required in branch protection rules.
109-
final-status:
104+
final-status: # Status check that is required in branch protection rules.
105+
name: Final Status 🎯
110106
needs:
111107
- sanity-check
112108
- build
113109
runs-on: ubuntu-latest
114110
if: always()
115111
steps:
116-
- name: Check
112+
- name: Check All Jobs ✅
117113
run: |
118114
results=$(tr -d '\n' <<< '${{ toJSON(needs.*.result) }}')
119115
if ! grep -q -v -E '(failure|cancelled)' <<< "$results"; then
120-
echo "One or more required jobs failed"
116+
echo "One or more required jobs failed"
121117
exit 1
122118
fi
123-
echo "All required jobs completed successfully."
119+
echo "All required jobs completed successfully."

CHANGES.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,11 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format (
1111

1212
## [Unreleased]
1313
### Added
14+
- Add a `expandWildcardImports` API for java ([#2679](https://github.com/diffplug/spotless/issues/2594))
1415
- Add the ability to specify a wildcard version (`*`) for external formatter executables. ([#2757](https://github.com/diffplug/spotless/issues/2757))
1516
### Changes
16-
* Bump default `ktlint` version to latest `1.7.1` -> `1.8.0`. ([2763](https://github.com/diffplug/spotless/pull/2763))
17-
* Bump default `gherkin-utils` version to latest `9.2.0` -> `10.0.0`. ([#2619](https://github.com/diffplug/spotless/pull/2619))
17+
- Bump default `ktlint` version to latest `1.7.1` -> `1.8.0`. ([2763](https://github.com/diffplug/spotless/pull/2763))
18+
- Bump default `gherkin-utils` version to latest `9.2.0` -> `10.0.0`. ([#2619](https://github.com/diffplug/spotless/pull/2619))
1819

1920
## [4.1.0] - 2025-11-18
2021
### Changes

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,7 @@ lib('java.GoogleJavaFormatStep') +'{{yes}} | {{yes}}
8585
lib('java.ImportOrderStep') +'{{yes}} | {{yes}} | {{yes}} | {{no}} |',
8686
lib('java.PalantirJavaFormatStep') +'{{yes}} | {{yes}} | {{no}} | {{no}} |',
8787
lib('java.RemoveUnusedImportsStep') +'{{yes}} | {{yes}} | {{yes}} | {{no}} |',
88+
lib('java.ExpandWildcardImportsStep') +'{{yes}} | {{no}} | {{no}} | {{no}} |',
8889
lib('java.ForbidWildcardImportsStep') +'{{yes}} | {{yes}} | {{yes}} | {{no}} |',
8990
lib('java.ForbidModuleImportsStep') +'{{yes}} | {{yes}} | {{no}} | {{no}} |',
9091
extra('java.EclipseJdtFormatterStep') +'{{yes}} | {{yes}} | {{yes}} | {{no}} |',
@@ -142,6 +143,7 @@ lib('yaml.JacksonYamlStep') +'{{yes}} | {{yes}}
142143
| [`java.ImportOrderStep`](lib/src/main/java/com/diffplug/spotless/java/ImportOrderStep.java) | :+1: | :+1: | :+1: | :white_large_square: |
143144
| [`java.PalantirJavaFormatStep`](lib/src/main/java/com/diffplug/spotless/java/PalantirJavaFormatStep.java) | :+1: | :+1: | :white_large_square: | :white_large_square: |
144145
| [`java.RemoveUnusedImportsStep`](lib/src/main/java/com/diffplug/spotless/java/RemoveUnusedImportsStep.java) | :+1: | :+1: | :+1: | :white_large_square: |
146+
| [`java.ExpandWildcardImportsStep`](lib/src/main/java/com/diffplug/spotless/java/ExpandWildcardImportsStep.java) | :+1: | :white_large_square: | :white_large_square: | :white_large_square: |
145147
| [`java.ForbidWildcardImportsStep`](lib/src/main/java/com/diffplug/spotless/java/ForbidWildcardImportsStep.java) | :+1: | :+1: | :+1: | :white_large_square: |
146148
| [`java.ForbidModuleImportsStep`](lib/src/main/java/com/diffplug/spotless/java/ForbidModuleImportsStep.java) | :+1: | :+1: | :white_large_square: | :white_large_square: |
147149
| [`java.EclipseJdtFormatterStep`](lib-extra/src/main/java/com/diffplug/spotless/extra/java/EclipseJdtFormatterStep.java) | :+1: | :+1: | :+1: | :white_large_square: |

gradle/spotless.gradle

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,16 +3,17 @@ spotless {
33
if (project != rootProject) {
44
// the rootProject doesn't have any java
55
java {
6-
ratchetFrom 'origin/main'
76
bumpThisNumberIfACustomStepChanges(1)
8-
licenseHeaderFile rootProject.file('gradle/spotless.license')
9-
importOrderFile rootProject.file('gradle/spotless.importorder')
107
eclipse().configFile rootProject.file('gradle/spotless.eclipseformat.xml')
11-
trimTrailingWhitespace()
12-
removeUnusedImports()
13-
formatAnnotations()
8+
// expandWildcardImports() todo: use after release (No signature of method: com.diffplug.gradle.spotless.JavaExtension.expandWildcardImports() is applicable for argument types: () values: [])
149
forbidWildcardImports()
1510
forbidRegex('ForbidGradleInternal', 'import org\\.gradle\\.api\\.internal\\.(.*)', "Don't use Gradle's internal API")
11+
formatAnnotations()
12+
importOrderFile rootProject.file('gradle/spotless.importorder')
13+
licenseHeaderFile rootProject.file('gradle/spotless.license')
14+
ratchetFrom 'origin/main'
15+
removeUnusedImports()
16+
trimTrailingWhitespace()
1617
}
1718
}
1819
groovyGradle {

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

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,9 @@
1515
*/
1616
package com.diffplug.spotless.extra;
1717

18+
import static com.diffplug.spotless.FileSignature.pathNativeToUnix;
19+
import static org.eclipse.jgit.treewalk.TreeWalk.forPath;
20+
1821
import java.io.File;
1922
import java.io.IOException;
2023
import java.util.HashMap;
@@ -45,7 +48,6 @@
4548
import com.diffplug.common.base.Errors;
4649
import com.diffplug.common.collect.HashBasedTable;
4750
import com.diffplug.common.collect.Table;
48-
import com.diffplug.spotless.FileSignature;
4951

5052
/**
5153
* How to use:
@@ -57,9 +59,7 @@
5759
public abstract class GitRatchet<Project> implements AutoCloseable {
5860

5961
public boolean isClean(Project project, ObjectId treeSha, File file) throws IOException {
60-
Repository repo = repositoryFor(project);
61-
String relativePath = FileSignature.pathNativeToUnix(repo.getWorkTree().toPath().relativize(file.toPath()).toString());
62-
return isClean(project, treeSha, relativePath);
62+
return isClean(project, treeSha, pathNativeToUnix(repositoryFor(project).getWorkTree().toPath().relativize(file.toPath()).toString()));
6363
}
6464

6565
private final Map<Repository, DirCache> dirCaches = new HashMap<>();
@@ -210,8 +210,7 @@ public synchronized ObjectId subtreeShaOf(Project project, ObjectId rootTreeSha)
210210
if (repo.getWorkTree().equals(directory)) {
211211
subtreeSha = rootTreeSha;
212212
} else {
213-
String subpath = FileSignature.pathNativeToUnix(repo.getWorkTree().toPath().relativize(directory.toPath()).toString());
214-
TreeWalk treeWalk = TreeWalk.forPath(repo, subpath, rootTreeSha);
213+
TreeWalk treeWalk = forPath(repo, pathNativeToUnix(repo.getWorkTree().toPath().relativize(directory.toPath()).toString()), rootTreeSha);
215214
subtreeSha = treeWalk == null ? ObjectId.zeroId() : treeWalk.getObjectId(0);
216215
}
217216
subtreeShaCache.put(project, subtreeSha.copy());

0 commit comments

Comments
 (0)