View Javadoc
1   package org.apache.maven.plugin.plugin;
2   
3   /*
4    * Licensed to the Apache Software Foundation (ASF) under one
5    * or more contributor license agreements.  See the NOTICE file
6    * distributed with this work for additional information
7    * regarding copyright ownership.  The ASF licenses this file
8    * to you under the Apache License, Version 2.0 (the
9    * "License"); you may not use this file except in compliance
10   * with the License.  You may obtain a copy of the License at
11   *
12   *   http://www.apache.org/licenses/LICENSE-2.0
13   *
14   * Unless required by applicable law or agreed to in writing,
15   * software distributed under the License is distributed on an
16   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
17   * KIND, either express or implied.  See the License for the
18   * specific language governing permissions and limitations
19   * under the License.
20   */
21  
22  import java.io.File;
23  
24  import org.apache.maven.plugin.MojoExecutionException;
25  import org.apache.maven.plugins.annotations.Component;
26  import org.apache.maven.plugins.annotations.LifecyclePhase;
27  import org.apache.maven.plugins.annotations.Mojo;
28  import org.apache.maven.plugins.annotations.Parameter;
29  import org.apache.maven.plugins.annotations.ResolutionScope;
30  import org.apache.maven.tools.plugin.generator.Generator;
31  import org.apache.maven.tools.plugin.generator.PluginHelpGenerator;
32  import org.codehaus.plexus.velocity.VelocityComponent;
33  
34  /**
35   * Generates a <code>HelpMojo</code> class.
36   * 
37   * @author <a href="mailto:vincent.siveton@gmail.com">Vincent Siveton</a>
38   * @version $Id: HelpGeneratorMojo.html 907040 2014-04-27 09:50:12Z hboutemy $
39   * @since 2.4
40   */
41  @Mojo( name = "helpmojo", defaultPhase = LifecyclePhase.GENERATE_SOURCES, threadSafe = true, requiresDependencyResolution = ResolutionScope.COMPILE )
42  public class HelpGeneratorMojo
43      extends AbstractGeneratorMojo
44  {
45      /**
46       * The directory where the generated <code>HelpMojo</code> file will be put.
47       */
48      @Parameter( defaultValue = "${project.build.directory}/generated-sources/plugin" )
49      protected File outputDirectory;
50  
51      /**
52       * The name of the package for the generated <code>HelpMojo</code>. By default, the package will be calculated based
53       * on the packages of the other plugin goals.
54       * 
55       * @since 2.6
56       */
57      @Parameter
58      private String helpPackageName;
59  
60      /**
61       * Velocity component.
62       */
63      @Component
64      private VelocityComponent velocity;
65  
66      /**
67       * {@inheritDoc}
68       */
69      protected File getOutputDirectory()
70      {
71          return outputDirectory;
72      }
73  
74      /**
75       * {@inheritDoc}
76       */
77      protected Generator createGenerator()
78      {
79          return new PluginHelpGenerator().setHelpPackageName( helpPackageName ).setVelocityComponent( this.velocity );
80      }
81  
82      /**
83       * {@inheritDoc}
84       */
85      public void execute()
86          throws MojoExecutionException
87      {
88          super.execute();
89  
90          if ( !project.getCompileSourceRoots().contains( outputDirectory.getAbsolutePath() ) && !skip )
91          {
92              project.addCompileSourceRoot( outputDirectory.getAbsolutePath() );
93          }
94  
95      }
96  
97  }