Skip to content
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-95] Add a fast clean option #6

Merged
merged 25 commits into from
Jan 10, 2022
Merged
Show file tree
Hide file tree
Changes from 18 commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
42f4274
Add a fast clean option
gnodet Dec 16, 2021
3b3fdbe
folder -> dir
gnodet Dec 16, 2021
4018375
Avoid magic constants
gnodet Dec 16, 2021
40902c3
Add a bit of doc to explain the fallback to the usual deletion mechanism
gnodet Dec 16, 2021
8dfd612
Handle use case where the fastDir is inside the target folder
gnodet Dec 16, 2021
0a2030d
Wait for file deletion to finish at the end of the maven session
gnodet Dec 16, 2021
5e3d086
Use [project]/target/.clean as the temporary cleaning folder, make su…
gnodet Dec 16, 2021
c807f9e
Require maven 3.3.1
gnodet Dec 16, 2021
2b80a51
Fix unit tests and avoid the usage of EventSpyDispatcher
gnodet Dec 16, 2021
5b6b7c1
Use the field which is available in both 3.x and 4.x until we get a p…
gnodet Dec 17, 2021
b3830d0
Relying on EventtSpy does not work with plain maven, so use the Execu…
gnodet Dec 17, 2021
68c3aa6
Extract in a method and add a bit of doc
gnodet Dec 17, 2021
e2e8a65
Missed that folder -> dir rename
gnodet Dec 17, 2021
7bff5b5
Refactor the fastDelete method to use nio Path instead of File, add w…
gnodet Dec 17, 2021
605656b
Add support for the ExecutionListener being null
gnodet Dec 17, 2021
2340ce1
Fix checkstyle
gnodet Dec 17, 2021
ac67308
A File is expected to be used
gnodet Dec 17, 2021
035c756
Revert maven 3.3.1 requirement down to 3.1.1
gnodet Dec 17, 2021
d737e20
Clean mojo properties
gnodet Dec 17, 2021
8a5159f
A bit more doc
gnodet Dec 17, 2021
7bfb97a
Small improvements
gnodet Dec 19, 2021
3ca9c81
Add a comment about session being eventually null during unit tests
gnodet Dec 19, 2021
8a8fd39
Add a fastMode to further specify when files are actually deleted
gnodet Jan 4, 2022
3fc91de
Throw an exception instead of a warning
gnodet Jan 4, 2022
cf1684f
Merge remote-tracking branch 'origin/master' into fastclean
gnodet Jan 10, 2022
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ under the License.
<groupId>org.apache.maven</groupId>
<artifactId>maven-core</artifactId>
<version>${mavenVersion}</version>
<scope>test</scope>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>junit</groupId>
Expand Down
36 changes: 35 additions & 1 deletion src/main/java/org/apache/maven/plugins/clean/CleanMojo.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,13 @@
* under the License.
*/

import org.apache.maven.execution.MavenSession;
import org.apache.maven.plugin.AbstractMojo;
import org.apache.maven.plugin.MojoExecutionException;
import org.apache.maven.plugins.annotations.Component;
import org.apache.maven.plugins.annotations.Mojo;
import org.apache.maven.plugins.annotations.Parameter;
import org.eclipse.sisu.Nullable;

import java.io.File;
import java.io.IOException;
Expand Down Expand Up @@ -161,6 +164,19 @@ public class CleanMojo
@Parameter( property = "maven.clean.excludeDefaultDirectories", defaultValue = "false" )
private boolean excludeDefaultDirectories;

@Parameter( property = "maven.clean.fast", defaultValue = "false" )
private boolean fast;

@Parameter( defaultValue = "${maven.multiModuleProjectDirectory}" )
private String multiModuleProjectDirectory;

@Parameter( property = "maven.clean.fastDir" )
private File fastDir;
gnodet marked this conversation as resolved.
Show resolved Hide resolved

@Component
@Nullable
private MavenSession session;

/**
* Deletes file-sets in the following project build directory order: (source) directory, output directory, test
* directory, report directory, and then the additional file-sets.
Expand All @@ -177,7 +193,25 @@ public void execute()
return;
}

Cleaner cleaner = new Cleaner( getLog(), isVerbose() );
File fastDir;
if ( fast && this.fastDir != null )
{
fastDir = this.fastDir;
}
else if ( fast && multiModuleProjectDirectory != null )
{
fastDir = new File( multiModuleProjectDirectory, "target/.clean" );
gnodet marked this conversation as resolved.
Show resolved Hide resolved
}
else
{
fastDir = null;
if ( fast )
{
getLog().warn( "Fast deletion requires maven 3.3.1" );
gnodet marked this conversation as resolved.
Show resolved Hide resolved
}
}

Cleaner cleaner = new Cleaner( session, getLog(), isVerbose(), fastDir );

try
{
Expand Down
Loading