1
2
3
4
5
6
7
8 package au.com.acegi.xmlformat;
9
10 import static au.com.acegi.xmlformat.FormatUtil.needsFormatting;
11 import static org.apache.maven.plugins.annotations.LifecyclePhase.PROCESS_SOURCES;
12
13 import java.io.File;
14 import java.io.IOException;
15
16 import org.apache.maven.plugin.MojoExecutionException;
17 import org.apache.maven.plugin.logging.Log;
18 import org.apache.maven.plugins.annotations.Mojo;
19 import org.dom4j.DocumentException;
20
21
22
23
24
25 @Mojo(name = "xml-check", defaultPhase = PROCESS_SOURCES, threadSafe = true)
26 public final class XmlCheckPlugin extends AbstractXmlPlugin {
27
28 @Override
29 protected boolean processFile(final File input, final XmlOutputFormat fmt) throws DocumentException, IOException {
30 final boolean needsFormatting = needsFormatting(input, fmt);
31 final Log log = getLog();
32 if (needsFormatting && log.isErrorEnabled()) {
33 log.error("[xml-check] Needs formatting:" + input);
34 } else if (log.isDebugEnabled()) {
35 log.debug("[xml-check] Correctly formatted: " + input);
36 }
37 return needsFormatting;
38 }
39
40 @Override
41 protected void afterAllProcessed(final boolean neededFormatting) throws MojoExecutionException {
42 if (neededFormatting) {
43 throw new MojoExecutionException(
44 "[xml-check] At least one XML file needs formatting, see the error logs above)");
45 }
46 }
47 }