View Javadoc
1   /*
2    * XML Format Maven Plugin (https://github.com/acegi/xml-format-maven-plugin)
3    *
4    * Copyright 2011-2025 Acegi Technology Pty Limited.
5    *
6    * Licensed under the Apache License, Version 2.0 (the "License");
7    * you may not use this file except in compliance with the License.
8    * You may obtain a copy of the License at
9    *
10   *      https://www.apache.org/licenses/LICENSE-2.0
11   *
12   * Unless required by applicable law or agreed to in writing, software
13   * distributed under the License is distributed on an "AS IS" BASIS,
14   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15   * See the License for the specific language governing permissions and
16   * limitations under the License.
17   */
18  package au.com.acegi.xmlformat;
19  
20  import static au.com.acegi.xmlformat.FormatUtil.formatInPlace;
21  import static org.apache.maven.plugins.annotations.LifecyclePhase.PREPARE_PACKAGE;
22  
23  import java.io.File;
24  import java.io.IOException;
25  
26  import org.apache.maven.plugins.annotations.Mojo;
27  import org.dom4j.DocumentException;
28  
29  /**
30   * Finds the XML files in a project and automatically reformats them.
31   */
32  @Mojo(name = "xml-format", defaultPhase = PREPARE_PACKAGE, threadSafe = true)
33  public final class XmlFormatPlugin extends AbstractXmlPlugin {
34  
35      @Override
36      protected boolean processFile(final File input, final XmlOutputFormat fmt) throws DocumentException, IOException {
37          final boolean changed = formatInPlace(input, fmt);
38          if (getLog().isDebugEnabled()) {
39              final String msg = changed ? "Formatted" : "Unchanged";
40              getLog().debug("[xml-format] " + msg + ": " + input);
41          }
42          return changed;
43      }
44  
45      @Override
46      protected void afterAllProcessed(final boolean neededFormatting) {
47          // nothing to do
48      }
49  }