in src/main/java/org/apache/jackrabbit/filevault/maven/packaging/mojo/FormatDocviewXmlMojo.java [130:171]
protected void executeInternal(@NotNull File sourceDirectory)
throws MojoExecutionException, MojoFailureException {
if (includes.isEmpty()) {
includes.add("**/*.xml");
}
Log log = getLog();
List<File> malformedFiles = new LinkedList<>();
DocViewFormat docViewFormat = new DocViewFormat();
Scanner directoryScanner = buildContext.newScanner(sourceDirectory);
directoryScanner.setIncludes(includes.toArray(new String[includes.size()]));
directoryScanner.setExcludes(excludes.toArray(new String[excludes.size()]));
directoryScanner.scan();
for (String subpath : directoryScanner.getIncludedFiles()) {
File toCheck = new File(sourceDirectory, subpath);
try {
if (docViewFormat.format(toCheck, validateOnly)) {
if (validateOnly) {
// collect all malformed files to emit one failure at the end
malformedFiles.add(toCheck);
// emit violations for m2e (https://www.eclipse.org/m2e/documentation/m2e-making-maven-plugins-compat.html)
buildContext.addMessage(toCheck, 0, 0, MSG_MALFORMED_FILE + ". " + MSG_COUNTERMEASURE, BuildContext.SEVERITY_ERROR, null);
log.error(MSG_MALFORMED_FILE + ":" + toCheck.getCanonicalPath());
} else {
log.info("Reformatted file '" + toCheck.getCanonicalPath() + "'.");
}
} else {
buildContext.removeMessages(toCheck);
}
} catch (IOException ex) {
throw new MojoExecutionException("Failed to read " + toCheck, ex);
}
}
if (!malformedFiles.isEmpty()) {
String message = "Found " + malformedFiles.size() + " files being malformed according to DocView format: Please check error message emitted above." +
"\n\n" + MSG_COUNTERMEASURE;
throw new MojoFailureException(message);
}
}