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.codehaus.plexus.metadata.merge.Merger;
31  
32  /**
33   * Merges a set of Plexus descriptors into one descriptor file.
34   * 
35   * @goal merge-metadata
36   * @phase process-classes
37   * @author Jason van Zyl
38   * @author Trygve Laugstøl
39   * @version $Id$
40   */
41  public class PlexusMergeMojo
42      extends AbstractMojo
43  {
44      /**
45       * The destination for the merged descriptor.
46       * 
47       * @parameter default-value="${project.build.outputDirectory}/META-INF/plexus/components.xml"
48       * @required
49       */
50      private File output;
51  
52      /**
53       * The paths of the input descriptors to merge.
54       * 
55       * @parameter
56       */
57      private File[] descriptors;
58  
59      /** @component role-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  }