View Javadoc
1   /*
2    * SPDX-License-Identifier: Apache-2.0
3    * See LICENSE file for details.
4    *
5    * Copyright 2025-2026 Hazendaz
6    * Copyright 2011-2025 Acegi Technology Pty Limited.
7    */
8   package au.com.acegi.xmlformat;
9   
10  import static au.com.acegi.xmlformat.FormatUtil.formatInPlace;
11  import static org.apache.maven.plugins.annotations.LifecyclePhase.PREPARE_PACKAGE;
12  
13  import java.io.File;
14  import java.io.IOException;
15  
16  import org.apache.maven.plugins.annotations.Mojo;
17  import org.dom4j.DocumentException;
18  
19  /**
20   * Finds the XML files in a project and automatically reformats them.
21   */
22  @Mojo(name = "xml-format", defaultPhase = PREPARE_PACKAGE, threadSafe = true)
23  public final class XmlFormatPlugin extends AbstractXmlPlugin {
24  
25      @Override
26      protected boolean processFile(final File input, final XmlOutputFormat fmt) throws DocumentException, IOException {
27          final boolean changed = formatInPlace(input, fmt);
28          if (getLog().isDebugEnabled()) {
29              final String msg = changed ? "Formatted" : "Unchanged";
30              getLog().debug("[xml-format] " + msg + ": " + input);
31          }
32          return changed;
33      }
34  
35      @Override
36      protected void afterAllProcessed(final boolean neededFormatting) {
37          // nothing to do
38      }
39  }