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