I'm writing new maven plugins, I've successfully used StaleSourceScanner in a combination with SuffixMapping, but it is just not working with SingleTargetSourceMapping. Always all files are detected as modified.
To be more specific this will be a tool, that analyzes class files, so my source files are in ${project.build.outputDirectory}. I have created a timestamp file for the last run, to compare changes with.
Unfortunately StaleSourceScanner is not documented at all.
(Maven phase is: process-classes; staleMillis = 0 show in the debug)
Code is:
private Set<File> findChangedFilesSimple() throws MojoExecutionException
{
HashSet<String> sourceIncludes =
new HashSet<>(Arrays.asList("**/*.class"));
Set sourceExcludes = Collections.EMPTY_SET;
StaleSourceScanner sourceInclusionScanner =
new StaleSourceScanner(
staleMillis, sourceIncludes, sourceExcludes);
sourceInclusionScanner.addSourceMapping(
new SingleTargetSourceMapping(
".class", timeStampFile.getPath()));
Set<File> effectedFiles;
try
{
effectedFiles =
sourceInclusionScanner.getIncludedSources(
classesDirectory, timestampDirectory);
}
catch (InclusionScanException e)
{
throw new MojoExecutionException(
"Error scanning source directory: " + classesDirectory, e);
}
return effectedFiles;
}