View Javadoc
1   package org.codehaus.plexus.maven.plugin;
2   
3   /*
4    * Copyright (c) 2004-2005, 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  
24  import org.apache.maven.plugin.MojoExecutionException;
25  import org.codehaus.plexus.metadata.MetadataGenerationRequest;
26  
27  /**
28   * Generates a Plexus <tt>components.xml</tt> component descriptor file from source (javadoc) or
29   * class annotations.
30   * 
31   * @goal generate-metadata
32   * @phase process-classes
33   * @requiresDependencyResolution compile
34   * @author Jason van Zyl
35   * @author Trygve Laugst&oslash;l
36   * @version $Id$
37   */
38  public class PlexusDescriptorMojo
39      extends AbstractDescriptorMojo
40  {
41      /**
42       * The output location for the generated descriptor.
43       * 
44       * @parameter default-value="${project.build.outputDirectory}/META-INF/plexus/components.xml"
45       * @required
46       */
47      protected File generatedMetadata;
48  
49      /**
50       * The location of manually crafted component descriptors. The contents of the descriptor files in this directory is
51       * merged with the information extracted from the project's sources/classes.
52       * 
53       * @parameter default-value="${basedir}/src/main/resources/META-INF/plexus"
54       * @required
55       */
56      protected File staticMetadataDirectory;
57  
58      /**
59       * The output location for the intermediary descriptor. This descriptors contains only the information extracted
60       * from the project's sources/classes.
61       * 
62       * @parameter default-value="${project.build.directory}/components.xml"
63       * @required
64       */
65      protected File intermediaryMetadata;
66  
67      public void execute()
68          throws MojoExecutionException
69      {
70          MetadataGenerationRequest request = new MetadataGenerationRequest();
71  
72          try
73          {
74              request.classpath = mavenProject.getCompileClasspathElements();
75              request.classesDirectory = new File( mavenProject.getBuild().getOutputDirectory() );
76              request.sourceDirectories = mavenProject.getCompileSourceRoots();
77              request.sourceEncoding = sourceEncoding;
78              request.componentDescriptorDirectory = staticMetadataDirectory;
79              request.intermediaryFile = intermediaryMetadata;
80              request.outputFile = generatedMetadata;
81              
82              metadataGenerator.generateDescriptor( request );
83          }
84          catch ( Exception e )
85          {
86              throw new MojoExecutionException( "Error generating metadata: ", e );
87          }
88      }
89  }