-
Notifications
You must be signed in to change notification settings - Fork 466
fix: allow concurrent prettier setups #2462
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
simschla
wants to merge
11
commits into
diffplug:main
Choose a base branch
from
simschla:bugfix/allow-concurrent-prettier-setups
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
11 commits
Select commit
Hold shift + click to select a range
da3b75b
fix: separate node_modules dir per npm based formatter
simschla 4589ca9
docs: add node_modules separation to CHANGELOG
simschla 215793d
docs: apply correct pr number
simschla fe34e9c
chore: add input validation for formatName
simschla 0f50012
Revert "chore: add input validation for formatName"
simschla e4b8f30
Revert "fix: separate node_modules dir per npm based formatter"
simschla 2466e47
fix: make sure node_modules dir is exclusively created
simschla 1f50067
feat: allow process to be started using instance_id
simschla 01f4ded
chore: add more logging to server starting
simschla 65b4e08
docs: adapt CHANGES.md files to new approach
simschla 279372b
fix: spotbugs issue
simschla 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
67 changes: 67 additions & 0 deletions
67
lib/src/main/java/com/diffplug/spotless/npm/ExclusiveFolderAccess.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,67 @@ | ||
/* | ||
* Copyright 2025 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.npm; | ||
|
||
import java.io.File; | ||
import java.util.Objects; | ||
import java.util.concurrent.ConcurrentHashMap; | ||
import java.util.concurrent.locks.Lock; | ||
import java.util.concurrent.locks.ReentrantLock; | ||
|
||
import javax.annotation.Nonnull; | ||
|
||
import com.diffplug.spotless.ThrowingEx; | ||
|
||
interface ExclusiveFolderAccess { | ||
|
||
static ExclusiveFolderAccess forFolder(@Nonnull File folder) { | ||
return forFolder(folder.getAbsolutePath()); | ||
} | ||
|
||
static ExclusiveFolderAccess forFolder(@Nonnull String path) { | ||
return new ExclusiveFolderAccessSharedMutex(Objects.requireNonNull(path)); | ||
} | ||
|
||
void runExclusively(ThrowingEx.Runnable runnable); | ||
|
||
class ExclusiveFolderAccessSharedMutex implements ExclusiveFolderAccess { | ||
|
||
private static final ConcurrentHashMap<String, Lock> mutexes = new ConcurrentHashMap<>(); | ||
|
||
private final String path; | ||
|
||
private ExclusiveFolderAccessSharedMutex(@Nonnull String path) { | ||
this.path = Objects.requireNonNull(path); | ||
} | ||
|
||
private Lock getMutex() { | ||
return mutexes.computeIfAbsent(path, k -> new ReentrantLock()); | ||
} | ||
|
||
@Override | ||
public void runExclusively(ThrowingEx.Runnable runnable) { | ||
final Lock lock = getMutex(); | ||
try { | ||
lock.lock(); | ||
runnable.run(); | ||
} catch (Exception e) { | ||
throw ThrowingEx.asRuntime(e); | ||
} finally { | ||
lock.unlock(); | ||
} | ||
} | ||
} | ||
} |
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
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
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.
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.
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.
Seems like we don't need the UUID because we have the ExclusiveFolderAccess?
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.
I'm using the ExclusiveFolderAccess to make sure that
npm install
is not run concurrently. Launching the server in parallel, however, is now explicitly supported and thus we use theUUID
to give each java thread its corresponding running npm server (differentiated via the UUID passed on launch). Hope that clears things up.