-
Notifications
You must be signed in to change notification settings - Fork 543
Support using projects as step dependency (ktlint rule sets only at this time) #2999
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
bric3
wants to merge
8
commits into
diffplug:main
Choose a base branch
from
bric3:support-using-projects-as-the-dependency
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
fe2faba
fix: restore project rule set substitution
bric3 e3f57b4
feat: support ktlint rule set project dependencies
bric3 fce8630
fix: resolve ktlint project rule sets in one graph
bric3 3dd8599
test: cover predeclared ktlint cache reuse
bric3 2bc4e8d
chore: Fill in the changes
bric3 0e5aa82
fix: tests on Windows
bric3 acb7005
fix: Try fix Windows build with using a build service param
bric3 7f8e9f3
fix: close formatter classloaders after each build
bric3 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
87 changes: 87 additions & 0 deletions
87
lib/src/main/java/com/diffplug/spotless/kotlin/PromisedClasspath.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,87 @@ | ||
| /* | ||
| * Copyright 2026 DiffPlug | ||
| * | ||
| * Licensed under the Apache License, Version 2.0 (the "License"); | ||
| * you may not use this file except in compliance with the License. | ||
| * You may obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, software | ||
| * distributed under the License is distributed on an "AS IS" BASIS, | ||
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| * See the License for the specific language governing permissions and | ||
| * limitations under the License. | ||
| */ | ||
| package com.diffplug.spotless.kotlin; | ||
|
|
||
| import java.io.File; | ||
| import java.io.IOException; | ||
| import java.io.ObjectOutputStream; | ||
| import java.io.Serial; | ||
| import java.io.Serializable; | ||
| import java.util.ArrayList; | ||
| import java.util.List; | ||
| import java.util.Objects; | ||
|
|
||
| import javax.annotation.Nullable; | ||
|
|
||
| import com.diffplug.spotless.FileSignature; | ||
| import com.diffplug.spotless.JarState; | ||
| import com.diffplug.spotless.ThrowingEx; | ||
|
|
||
| import edu.umd.cs.findbugs.annotations.SuppressFBWarnings; | ||
|
|
||
| /** | ||
| * Configuration-cache-safe promise for a generated classpath. | ||
| * <p> | ||
| * {@link JarState.Promised} and {@link FileSignature.Promised} represent signed file contents when | ||
| * materialized. That is too early for project artifacts, which might not exist while Gradle serializes | ||
| * formatter state. This promise serializes only the resolved file paths; Gradle tracks their contents as | ||
| * a separate {@code @Classpath} task input, and {@link KtLintStep.State#createFormat()} signs them after | ||
| * the producer tasks have run. | ||
| * <p> | ||
| * Resolution is synchronized because Gradle can serialize the roundtrip and equality views concurrently. | ||
| */ | ||
| final class PromisedClasspath implements Serializable { | ||
| @Serial | ||
| private static final long serialVersionUID = 1L; | ||
| @SuppressFBWarnings(value = "SE_TRANSIENT_FIELD_NOT_RESTORED", justification = "Serialized file paths replace the supplier after a configuration-cache roundtrip") | ||
| private final transient ThrowingEx.Supplier<? extends Iterable<File>> supplier; | ||
| @Nullable private volatile List<File> files; | ||
|
|
||
| PromisedClasspath(ThrowingEx.Supplier<? extends Iterable<File>> supplier) { | ||
| this.supplier = supplier; | ||
| } | ||
|
|
||
| /** | ||
| * Returns the promised classpath paths, materializing the supplier at most once. | ||
| * <p> | ||
| * Materialization resolves only paths. The referenced files may not exist yet because their Gradle producer tasks | ||
| * can run after formatter-state serialization. File contents are signed later by | ||
| * {@link KtLintStep.State#createFormat()}. | ||
| * <p> | ||
| * After a serialization roundtrip, the serialized path list is reused and the transient supplier is no longer | ||
| * required. | ||
| */ | ||
| List<File> get() { | ||
| List<File> result = files; | ||
| if (result == null) { | ||
| synchronized (this) { | ||
| result = files; | ||
| if (result == null) { | ||
| ThrowingEx.Supplier<? extends Iterable<File>> availableSupplier = Objects.requireNonNull(supplier, "supplier"); | ||
| List<File> suppliedFiles = new ArrayList<>(); | ||
| ThrowingEx.get(availableSupplier).forEach(suppliedFiles::add); | ||
| files = result = List.copyOf(suppliedFiles); | ||
| } | ||
| } | ||
| } | ||
| return result; | ||
| } | ||
|
|
||
| private void writeObject(ObjectOutputStream out) throws IOException { | ||
| get(); | ||
| out.defaultWriteObject(); | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We only need the cache-clearing behavior when this is met, correct?