Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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 @@ -115,7 +115,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
81 changes: 80 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,6 +19,7 @@
* 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.Mojo;
Expand Down Expand Up @@ -48,6 +49,12 @@ public class CleanMojo
extends AbstractMojo
{

public static final String FAST_MODE_BACKGROUND = "background";

public static final String FAST_MODE_AT_END = "at-end";

public static final String FAST_MODE_DEFER = "defer";

/**
* This is where build results go.
*/
Expand Down Expand Up @@ -161,6 +168,49 @@ public class CleanMojo
@Parameter( property = "maven.clean.excludeDefaultDirectories", defaultValue = "false" )
private boolean excludeDefaultDirectories;

/**
* Enables fast clean if possible. If set to <code>true</code>, when the plugin is executed, a directory to
* be deleted will be atomically moved inside the <code>maven.clean.fastDir</code> directory and a thread will
* be launched to delete the needed files in the background. When the build is completed, maven will wait
* until all the files have been deleted. If any problem occurs during the atomic move of the directories,
* the plugin will default to the traditional deletion mechanism.
*
* @since 3.2
*/
@Parameter( property = "maven.clean.fast", defaultValue = "false" )
private boolean fast;

/**
* When fast clean is specified, the <code>fastDir</code> property will be used as the location where directories
* to be deleted will be moved prior to background deletion. If not specified, the
* <code>${maven.multiModuleProjectDirectory}/target/.clean</code> directory will be used. If the
* <code>${build.directory}</code> has been modified, you'll have to adjust this property explicitly.
* In order for fast clean to work correctly, this directory and the various directories that will be deleted
* should usually reside on the same volume. The exact conditions are system dependant though, but if an atomic
* move is not supported, the standard deletion mechanism will be used.
*
* @since 3.2
* @see #fast
*/
@Parameter( property = "maven.clean.fastDir" )
private File fastDir;
Comment thread
gnodet marked this conversation as resolved.

/**
* Mode to use when using fast clean. Values are: <code>background</code> to start deletion immediately and
* 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).
*
* @since 3.2
* @see #fast
*/
@Parameter( property = "maven.clean.fastMode", defaultValue = FAST_MODE_BACKGROUND )
private String fastMode;

@Parameter( defaultValue = "${session}", readonly = true )
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 +227,36 @@ public void execute()
return;
}

Cleaner cleaner = new Cleaner( getLog(), isVerbose() );
String multiModuleProjectDirectory = session != null
Comment thread
michael-o marked this conversation as resolved.
? session.getSystemProperties().getProperty( "maven.multiModuleProjectDirectory" ) : null;
File fastDir;
if ( fast && this.fastDir != null )
{
fastDir = this.fastDir;
}
else if ( fast && multiModuleProjectDirectory != null )
{
fastDir = new File( multiModuleProjectDirectory, "target/.clean" );
Comment thread
gnodet marked this conversation as resolved.
}
else
{
fastDir = null;
if ( fast )
{
getLog().warn( "Fast clean requires maven 3.3.1 or newer, "
+ "or an explicit directory to be specified with the 'fastDir' configuration of "
+ "this plugin, or the 'maven.clean.fastDir' user property to be set." );
}
}
if ( fast && !FAST_MODE_BACKGROUND.equals( fastMode )
&& !FAST_MODE_AT_END.equals( fastMode )
&& !FAST_MODE_DEFER.equals( fastMode ) )
{
throw new IllegalArgumentException( "Illegal value '" + fastMode + "' for fastMode. Allowed values are '"
+ FAST_MODE_BACKGROUND + "', '" + FAST_MODE_AT_END + "' and '" + FAST_MODE_DEFER + "'." );
}
Comment thread
gnodet marked this conversation as resolved.

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

try
{
Expand Down
Loading