-
Notifications
You must be signed in to change notification settings - Fork 53
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
[MCLEAN-126] Replaced old File API with new Path equivalent where possible #62
Merged
slachiewicz
merged 3 commits into
apache:maven-clean-plugin-3.x
from
peterdemaeyer:MCLEAN-126
Jan 19, 2025
Merged
Changes from 1 commit
Commits
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 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 |
---|---|---|
|
@@ -20,6 +20,8 @@ | |
|
||
import java.io.File; | ||
import java.io.IOException; | ||
import java.nio.file.FileSystems; | ||
import java.nio.file.Path; | ||
|
||
import org.apache.maven.execution.MavenSession; | ||
import org.apache.maven.plugin.AbstractMojo; | ||
|
@@ -197,7 +199,7 @@ public class CleanMojo extends AbstractMojo { | |
* waiting for all files to be deleted when the session ends, <code>at-end</code> to indicate that the actual | ||
* deletion should be performed synchronously when the session ends, or <code>defer</code> to specify that | ||
* the actual file deletion should be started in the background when the session ends (this should only be used | ||
* when maven is embedded in a long running process). | ||
* when maven is embedded in a long-running process). | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. period inside parentheses There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I see your point. Maybe even drop the parentheses altogether? |
||
* | ||
* @see #fast | ||
* @since 3.2 | ||
|
@@ -223,11 +225,14 @@ public void execute() throws MojoExecutionException { | |
|
||
String multiModuleProjectDirectory = | ||
session != null ? session.getSystemProperties().getProperty("maven.multiModuleProjectDirectory") : null; | ||
File fastDir; | ||
Path fastDir; | ||
if (fast && this.fastDir != null) { | ||
fastDir = this.fastDir; | ||
fastDir = toNullablePath(this.fastDir); | ||
} else if (fast && multiModuleProjectDirectory != null) { | ||
fastDir = new File(multiModuleProjectDirectory, "target/.clean"); | ||
fastDir = FileSystems.getDefault() | ||
.getPath(multiModuleProjectDirectory) | ||
.resolve("target") | ||
.resolve(".clean"); | ||
} else { | ||
fastDir = null; | ||
if (fast) { | ||
|
@@ -247,7 +252,7 @@ public void execute() throws MojoExecutionException { | |
Cleaner cleaner = new Cleaner(session, getLog(), isVerbose(), fastDir, fastMode); | ||
|
||
try { | ||
for (File directoryItem : getDirectories()) { | ||
for (Path directoryItem : getDirectories()) { | ||
if (directoryItem != null) { | ||
cleaner.delete(directoryItem, null, followSymLinks, failOnError, retryOnError); | ||
} | ||
|
@@ -270,7 +275,11 @@ public void execute() throws MojoExecutionException { | |
selector = null; | ||
} | ||
cleaner.delete( | ||
fileset.getDirectory(), selector, fileset.isFollowSymlinks(), failOnError, retryOnError); | ||
fileset.getDirectory().toPath(), | ||
selector, | ||
fileset.isFollowSymlinks(), | ||
failOnError, | ||
retryOnError); | ||
} | ||
} | ||
} catch (IOException e) { | ||
|
@@ -292,13 +301,22 @@ private boolean isVerbose() { | |
* | ||
* @return The directories to clean or an empty array if none, never <code>null</code>. | ||
*/ | ||
private File[] getDirectories() { | ||
File[] directories; | ||
private Path[] getDirectories() { | ||
Path[] directories; | ||
if (excludeDefaultDirectories) { | ||
directories = new File[0]; | ||
directories = new Path[0]; | ||
} else { | ||
directories = new File[] {directory, outputDirectory, testOutputDirectory, reportDirectory}; | ||
directories = new Path[] { | ||
toNullablePath(directory), | ||
toNullablePath(outputDirectory), | ||
toNullablePath(testOutputDirectory), | ||
toNullablePath(reportDirectory) | ||
}; | ||
} | ||
return directories; | ||
} | ||
|
||
private static Path toNullablePath(File file) { | ||
return file != null ? file.toPath() : null; | ||
} | ||
} |
This file contains 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 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 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
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.
session ends. (This should only be used