View Javadoc
1   package org.codehaus.plexus.maven.plugin;
2   
3   /*
4    * Copyright (c) 2004-2006, Codehaus.org
5    *
6    * Permission is hereby granted, free of charge, to any person obtaining a copy of this software and
7    * associated documentation files (the "Software"), to deal in the Software without restriction,
8    * including without limitation the rights to use, copy, modify, merge, publish, distribute,
9    * sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is
10   * furnished to do so, subject to the following conditions:
11   *
12   * The above copyright notice and this permission notice shall be included in all copies or
13   * substantial portions of the Software.
14   *
15   * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT
16   * NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17   * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
18   * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19   * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
20   */
21  
22  import java.io.File;
23  import java.io.IOException;
24  import java.util.ArrayList;
25  import java.util.Arrays;
26  import java.util.List;
27  
28  import org.apache.maven.plugin.AbstractMojo;
29  import org.apache.maven.plugin.MojoExecutionException;
30  import org.apache.maven.plugins.annotations.Component;
31  import org.apache.maven.plugins.annotations.LifecyclePhase;
32  import org.apache.maven.plugins.annotations.Mojo;
33  import org.apache.maven.plugins.annotations.Parameter;
34  import org.codehaus.plexus.metadata.merge.Merger;
35  
36  /**
37   * Merges a set of Plexus descriptors into one descriptor file.
38   *
39   * @author Jason van Zyl
40   * @author Trygve Laugstøl
41   */
42  @Mojo(name = "merge-metadata", defaultPhase = LifecyclePhase.PROCESS_CLASSES)
43  public class PlexusMergeMojo extends AbstractMojo {
44      /**
45       * The destination for the merged descriptor.
46       */
47      @Parameter(defaultValue = "${project.build.outputDirectory}/META-INF/plexus/components.xml", required = true)
48      private File output;
49  
50      /**
51       * The paths of the input descriptors to merge.
52       */
53      @Parameter
54      private File[] descriptors;
55  
56      @Component(hint = "componentsXml")
57      private Merger merger;
58  
59      public void execute() throws MojoExecutionException {
60          List<File> files = new ArrayList<File>();
61  
62          if (descriptors != null) {
63              files.addAll(Arrays.asList(descriptors));
64          }
65  
66          if (files.isEmpty()) {
67              return;
68          }
69  
70          try {
71              merger.mergeDescriptors(output, files);
72          } catch (IOException e) {
73              throw new MojoExecutionException("Error while executing component descriptor creator.", e);
74          }
75      }
76  }