-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Introduce TempDirDeletionStrategy
#5424
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
marcphilipp
wants to merge
17
commits into
main
Choose a base branch
from
marc/temp-dir-deletion-strategy
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
17 commits
Select commit
Hold shift + click to select a range
8023b15
Introduce `TempDirDeletionStrategy`
marcphilipp d457eef
Make `Standard` final
marcphilipp 7c4e870
Merge branch 'main' into marc/temp-dir-deletion-strategy
marcphilipp d6f3af5
Introduce `DeletionResult` and `DeletionFailure` result objects
marcphilipp 27e2e47
Add `TempDirDeletionStrategy.IgnoreFailures`
marcphilipp 96f4505
Use proper super class
marcphilipp 89ccae2
Document
marcphilipp b6d4430
Improve logging
marcphilipp 357e2d2
Avoid exception for non-default file systems
marcphilipp 8c55968
Return an `Optional` from `toException()`
marcphilipp ad967e1
Avoid checking for default file system
marcphilipp 421e9a8
Introduce `Constants` for `TempDir` config params
marcphilipp 72652a3
Check preconditions
marcphilipp 59bf296
Add to release notes
marcphilipp 79b715b
Merge branch 'main' into marc/temp-dir-deletion-strategy
marcphilipp 2161634
Replace isPresent with ifPresent
mpkorstanje d9f4867
Break up long sentence for clarity
mpkorstanje 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
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
89 changes: 89 additions & 0 deletions
89
junit-jupiter-api/src/main/java/org/junit/jupiter/api/io/DefaultDeletionResult.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,89 @@ | ||
| /* | ||
| * Copyright 2026 the original author or authors. | ||
| * | ||
| * All rights reserved. This program and the accompanying materials are | ||
| * made available under the terms of the Eclipse Public License v2.0 which | ||
| * accompanies this distribution and is available at | ||
| * | ||
| * https://www.eclipse.org/legal/epl-v20.html | ||
| */ | ||
|
|
||
| package org.junit.jupiter.api.io; | ||
|
|
||
| import static java.util.Comparator.comparing; | ||
| import static java.util.stream.Collectors.joining; | ||
|
|
||
| import java.nio.file.Path; | ||
| import java.util.ArrayList; | ||
| import java.util.List; | ||
| import java.util.Optional; | ||
|
|
||
| import org.junit.jupiter.api.io.TempDirDeletionStrategy.DeletionException; | ||
| import org.junit.jupiter.api.io.TempDirDeletionStrategy.DeletionFailure; | ||
| import org.junit.jupiter.api.io.TempDirDeletionStrategy.DeletionResult; | ||
| import org.junit.platform.commons.util.Preconditions; | ||
|
|
||
| record DefaultDeletionResult(Path rootDir, List<DeletionFailure> failures) implements DeletionResult { | ||
|
|
||
| DefaultDeletionResult(Path rootDir, List<DeletionFailure> failures) { | ||
| this.rootDir = rootDir; | ||
| this.failures = List.copyOf(failures); | ||
| } | ||
|
|
||
| @Override | ||
| public Optional<DeletionException> toException() { | ||
| if (isSuccessful()) { | ||
| return Optional.empty(); | ||
| } | ||
| var joinedPaths = failures().stream() // | ||
| .map(DeletionFailure::path) // | ||
| .sorted() // | ||
| .distinct() // | ||
| .map(path -> relativizeSafely(rootDir(), path).toString()) // | ||
| .map(path -> path.isEmpty() ? "<root>" : path) // | ||
| .collect(joining(", ")); | ||
| var exception = new DeletionException("Failed to delete temp directory " + rootDir().toAbsolutePath() | ||
| + ". The following paths could not be deleted (see suppressed exceptions for details): " + joinedPaths); | ||
| failures().stream() // | ||
| .sorted(comparing(DeletionFailure::path)) // | ||
| .map(DeletionFailure::cause) // | ||
| .forEach(exception::addSuppressed); | ||
| return Optional.of(exception); | ||
| } | ||
|
|
||
| private static Path relativizeSafely(Path rootDir, Path path) { | ||
| try { | ||
| return rootDir.relativize(path); | ||
| } | ||
| catch (IllegalArgumentException e) { | ||
| return path; | ||
| } | ||
| } | ||
|
|
||
| static final class Builder implements DeletionResult.Builder { | ||
|
|
||
| private final Path rootDir; | ||
| private final List<DeletionFailure> failures = new ArrayList<>(); | ||
|
|
||
| Builder(Path rootDir) { | ||
| this.rootDir = rootDir; | ||
| } | ||
|
|
||
| @Override | ||
| public Builder addFailure(Path path, Exception cause) { | ||
| Preconditions.notNull(path, "path must not be null"); | ||
| Preconditions.notNull(cause, "cause must not be null"); | ||
| failures.add(new DefaultDeletionFailure(path, cause)); | ||
| return this; | ||
| } | ||
|
|
||
| @Override | ||
| public DefaultDeletionResult build() { | ||
| return new DefaultDeletionResult(rootDir, failures); | ||
| } | ||
|
|
||
| } | ||
|
|
||
| record DefaultDeletionFailure(Path path, Exception cause) implements DeletionFailure { | ||
| } | ||
| } | ||
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.