Class IncrementalBuildHelper
- java.lang.Object
-
- org.apache.maven.shared.incremental.IncrementalBuildHelper
-
public class IncrementalBuildHelper extends java.lang.Object
Various helper methods to support incremental builds
-
-
Field Summary
Fields Modifier and Type Field Description static java.lang.String
CREATED_FILES_LST_FILENAME
private org.apache.maven.shared.utils.io.DirectoryScanner
directoryScanner
Used for detecting changes between the Mojo execution.private static java.lang.String[]
EMPTY_ARRAY
private java.lang.String[]
filesBeforeAction
Once thebeforeRebuildExecution(org.apache.maven.shared.incremental.IncrementalBuildHelperRequest)
got called, this will contain the list of files in the build directory.private static java.lang.String
INPUT_FILES_LST_FILENAME
private static java.lang.String
MAVEN_STATUS_ROOT
the root directory to store status information about Maven executions in.private org.apache.maven.project.MavenProject
mavenProject
Needed for storing the status for the incremental build support.private org.apache.maven.plugin.MojoExecution
mojoExecution
Needed for storing the status for the incremental build support.
-
Constructor Summary
Constructors Constructor Description IncrementalBuildHelper(org.apache.maven.plugin.MojoExecution mojoExecution, org.apache.maven.execution.MavenSession mavenSession)
IncrementalBuildHelper(org.apache.maven.plugin.MojoExecution mojoExecution, org.apache.maven.project.MavenProject mavenProject)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description void
afterRebuildExecution(IncrementalBuildHelperRequest incrementalBuildHelperRequest)
This method collects and stores all information about files changed since the call tobeforeRebuildExecution(org.apache.maven.shared.incremental.IncrementalBuildHelperRequest)
.java.lang.String[]
beforeRebuildExecution(IncrementalBuildHelperRequest incrementalBuildHelperRequest)
This method shall get invoked before the actual Mojo task gets triggered, e.g.org.apache.maven.shared.utils.io.DirectoryScanner
getDirectoryScanner()
Get the existing DirectoryScanner used by this helper, or create new a DirectoryScanner if none is yet set.private static org.apache.maven.project.MavenProject
getMavenProject(org.apache.maven.execution.MavenSession mavenSession)
small helper method to allow for the nullcheck in the ct invocationjava.io.File
getMojoStatusDirectory()
We use a specific status directory for each Mojo execution to store state which is needed during the next build invocation run.boolean
inputFileTreeChanged(IncrementalBuildHelperRequest incrementalBuildHelperRequest)
Detect whether the list of detected files has changed since the last build.boolean
inputFileTreeChanged(org.apache.maven.shared.utils.io.DirectoryScanner dirScanner)
Detect whether the list of detected files picked up by the DirectoryScanner has changed since the last build.void
setDirectoryScanner(org.apache.maven.shared.utils.io.DirectoryScanner directoryScanner)
Set the DirectoryScanner which shall get used by this build helper.private java.lang.String[]
toArrayOfPath(java.util.Set<java.io.File> files)
-
-
-
Field Detail
-
MAVEN_STATUS_ROOT
private static final java.lang.String MAVEN_STATUS_ROOT
the root directory to store status information about Maven executions in.- See Also:
- Constant Field Values
-
CREATED_FILES_LST_FILENAME
public static final java.lang.String CREATED_FILES_LST_FILENAME
- See Also:
- Constant Field Values
-
INPUT_FILES_LST_FILENAME
private static final java.lang.String INPUT_FILES_LST_FILENAME
- See Also:
- Constant Field Values
-
EMPTY_ARRAY
private static final java.lang.String[] EMPTY_ARRAY
-
mojoExecution
private org.apache.maven.plugin.MojoExecution mojoExecution
Needed for storing the status for the incremental build support.
-
mavenProject
private org.apache.maven.project.MavenProject mavenProject
Needed for storing the status for the incremental build support.
-
directoryScanner
private org.apache.maven.shared.utils.io.DirectoryScanner directoryScanner
Used for detecting changes between the Mojo execution.
-
filesBeforeAction
private java.lang.String[] filesBeforeAction
Once thebeforeRebuildExecution(org.apache.maven.shared.incremental.IncrementalBuildHelperRequest)
got called, this will contain the list of files in the build directory.
-
-
Constructor Detail
-
IncrementalBuildHelper
public IncrementalBuildHelper(org.apache.maven.plugin.MojoExecution mojoExecution, org.apache.maven.execution.MavenSession mavenSession)
-
IncrementalBuildHelper
public IncrementalBuildHelper(org.apache.maven.plugin.MojoExecution mojoExecution, org.apache.maven.project.MavenProject mavenProject)
-
-
Method Detail
-
getMavenProject
private static org.apache.maven.project.MavenProject getMavenProject(org.apache.maven.execution.MavenSession mavenSession)
small helper method to allow for the nullcheck in the ct invocation
-
getDirectoryScanner
public org.apache.maven.shared.utils.io.DirectoryScanner getDirectoryScanner()
Get the existing DirectoryScanner used by this helper, or create new a DirectoryScanner if none is yet set. The DirectoryScanner is used for detecting changes in a directory
-
setDirectoryScanner
public void setDirectoryScanner(org.apache.maven.shared.utils.io.DirectoryScanner directoryScanner)
Set the DirectoryScanner which shall get used by this build helper.- Parameters:
directoryScanner
-
-
getMojoStatusDirectory
public java.io.File getMojoStatusDirectory() throws org.apache.maven.plugin.MojoExecutionException
We use a specific status directory for each Mojo execution to store state which is needed during the next build invocation run.- Returns:
- the directory for storing status information of the current Mojo execution.
- Throws:
org.apache.maven.plugin.MojoExecutionException
-
inputFileTreeChanged
public boolean inputFileTreeChanged(IncrementalBuildHelperRequest incrementalBuildHelperRequest) throws org.apache.maven.plugin.MojoExecutionException
Detect whether the list of detected files has changed since the last build. We simply load the list of files for the previous build from a status file and compare it with the new list. Afterwards we store the new list in the status file.- Parameters:
incrementalBuildHelperRequest
-- Returns:
true
if the set of inputFiles got changed since the last build.- Throws:
org.apache.maven.plugin.MojoExecutionException
-
inputFileTreeChanged
public boolean inputFileTreeChanged(org.apache.maven.shared.utils.io.DirectoryScanner dirScanner) throws org.apache.maven.plugin.MojoExecutionException
Detect whether the list of detected files picked up by the DirectoryScanner has changed since the last build. We simply load the list of files for the previous build from a status file and compare it with the result of the new DirectoryScanner#scan(). Afterwards we store the new list in the status file.- Parameters:
dirScanner
-- Returns:
true
if the set of inputFiles got changed since the last build.- Throws:
org.apache.maven.plugin.MojoExecutionException
-
beforeRebuildExecution
public java.lang.String[] beforeRebuildExecution(IncrementalBuildHelperRequest incrementalBuildHelperRequest) throws org.apache.maven.plugin.MojoExecutionException
This method shall get invoked before the actual Mojo task gets triggered, e.g. the actual compile in maven-compiler-plugin.
Attention: This method shall only get invoked if the plugin re-creates all the output.
It first picks up the list of files created in the previous build and delete them. This step is necessary to prevent left-overs. After that we take a 'directory snapshot' (list of all files which exist in the outputDirectory after the clean).
After the actual Mojo task got executed you should invoke the method
afterRebuildExecution(org.apache.maven.shared.incremental.IncrementalBuildHelperRequest)
to collect the list of files which got changed by this task.- Parameters:
incrementalBuildHelperRequest
-- Returns:
- all files which got created in the previous build and have been deleted now.
- Throws:
org.apache.maven.plugin.MojoExecutionException
-
afterRebuildExecution
public void afterRebuildExecution(IncrementalBuildHelperRequest incrementalBuildHelperRequest) throws org.apache.maven.plugin.MojoExecutionException
This method collects and stores all information about files changed since the call to
beforeRebuildExecution(org.apache.maven.shared.incremental.IncrementalBuildHelperRequest)
.Attention: This method shall only get invoked if the plugin re-creates all the output.
- Parameters:
incrementalBuildHelperRequest
- will contains file sources to store if create files are not yet stored- Throws:
org.apache.maven.plugin.MojoExecutionException
-
toArrayOfPath
private java.lang.String[] toArrayOfPath(java.util.Set<java.io.File> files)
-
-