* @throws MojoExecutionException when instrumentation fails
* @see com.atlassian.maven.plugin.clover.CloverInstrumentInternalMojo#calcIncludedFilesForGroovy()
* @see com.atlassian.maven.plugin.clover.CloverInstrumentInternalMojo#redirectOutputDirectories()
*/
public void instrument() throws MojoExecutionException {
final CloverSourceScanner scanner = getSourceScanner();
// get source files to be instrumented, but only for Java as they will be instrumented by CloverInstr
final Map<String, String[]> javaFilesToInstrument = scanner.getSourceFilesToInstrument(LanguageFileExtensionFilter.JAVA_LANGUAGE, true);
if (javaFilesToInstrument.isEmpty()) {
getConfiguration().getLog().info("No Clover instrumentation done on source files in: "
+ getCompileSourceRoots() + " as no matching sources files found (JAVA_LANGUAGE)");
} else {
instrumentSources(javaFilesToInstrument, outputSourceDirectory);
}
// find groovy files in all compilation roots and copy them
//
// 1) in case when 'src/main/java' (or 'src/test/java') contains *.groovy source files (this is a trick possible
// with a groovy-eclipse-plugin, see http://groovy.codehaus.org/Groovy-Eclipse+compiler+plugin+for+Maven
// "Setting up source folders / Do nothing") we must copy *.groovy files as well
// reason: 'src/main/java' (or 'src/test/java') will be redirected to 'target/clover/src-instrumented'
// (or 'target/clover/src-test-instrumented') and Groovy compiler must be able to find these groovy sources
//
// 2) however we shall not copy groovy files from 'src/(main|test)/groovy' because these source roots are not
// being redirected to 'target/clover/src-(test-)instrumented'; furthermore groovy-eclipse-plugin has
// 'src/(main|test)/groovy' location hardcoded, so copying files would end up with 'duplicate class' build error
final Map<String, String[]> groovyFilesToInstrument = scanner.getSourceFilesToInstrument(LanguageFileExtensionFilter.GROOVY_LANGUAGE, true);
// copy groovy files
if (!groovyFilesToInstrument.isEmpty()) {
copyExcludedFiles(groovyFilesToInstrument, outputSourceDirectory);
}
// We need to copy excluded files too as otherwise they won't be in the new Clover source directory and
// thus won't be compiled by the compile plugin. This will lead to compilation errors if any other
// file depends on any of these excluded files.
if (configuration.isCopyExcludedFiles()) {
final Map<String, String[]> explicitlyExcludedFiles = scanner.getExcludedFiles();
// 'src/(main|test)/groovy' is already filtered-out in getExcludedFiles()
copyExcludedFiles(explicitlyExcludedFiles, outputSourceDirectory);
}
}