我正在编写新的 maven 插件,我已经成功地将 StaleSourceScanner 与 SuffixMapping 结合使用,但它不能与 SingleTargetSourceMapping 一起使用。始终将所有文件检测为已修改。
更具体地说,这将是一个分析类文件的工具,所以我的源文件在 ${project.build.outputDirectory} 中。我为上次运行创建了一个时间戳文件,用于比较更改。
不幸的是,StaleSourceScanner 根本没有记录。
(Maven 阶段是:process-classes;staleMillis = 0 显示在调试中)
代码是:
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;
}