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   * @version $Id$
42   */
43  @Mojo( name = "merge-metadata", defaultPhase = LifecyclePhase.PROCESS_CLASSES )
44  public class PlexusMergeMojo
45      extends AbstractMojo
46  {
47      /**
48       * The destination for the merged descriptor.
49       */
50      @Parameter( defaultValue = "${project.build.outputDirectory}/META-INF/plexus/components.xml", required = true )
51      private File output;
52  
53      /**
54       * The paths of the input descriptors to merge.
55       */
56      @Parameter
57      private File[] descriptors;
58  
59      @Component( hint = "componentsXml" )
60      private Merger merger;
61  
62      public void execute()
63          throws MojoExecutionException
64      {
65          List<File> files = new ArrayList<File>();
66  
67          if ( descriptors != null )
68          {
69              files.addAll( Arrays.asList( descriptors ) );
70          }
71  
72          if ( files.isEmpty() )
73          {
74              return;
75          }
76  
77          try
78          {
79              merger.mergeDescriptors( output, files );
80          }
81          catch ( IOException e )
82          {
83              throw new MojoExecutionException( "Error while executing component descritor creator.", e );
84          }
85      }
86  }