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 995996 2016-08-26 22:31:42Z rfscholte $
39   * @since 2.4
40   */
41  @Mojo( name = "helpmojo", defaultPhase = LifecyclePhase.GENERATE_SOURCES, threadSafe = true,
42                  requiresDependencyResolution = ResolutionScope.COMPILE )
43  public class HelpGeneratorMojo
44      extends AbstractGeneratorMojo
45  {
46      /**
47       * The directory where the generated <code>HelpMojo</code> file will be put.
48       */
49      @Parameter( defaultValue = "${project.build.directory}/generated-sources/plugin" )
50      protected File outputDirectory;
51  
52      /**
53       * The name of the package for the generated <code>HelpMojo</code>. By default, the package will be calculated based
54       * on the packages of the other plugin goals.
55       * 
56       * @since 2.6
57       */
58      @Parameter
59      private String helpPackageName;
60  
61      /**
62       * Velocity component.
63       */
64      @Component
65      private VelocityComponent velocity;
66  
67      /**
68       * {@inheritDoc}
69       */
70      protected File getOutputDirectory()
71      {
72          return outputDirectory;
73      }
74  
75      /**
76       * {@inheritDoc}
77       */
78      protected Generator createGenerator()
79      {
80          return new PluginHelpGenerator().setHelpPackageName( helpPackageName ).setVelocityComponent( this.velocity );
81      }
82  
83      /**
84       * {@inheritDoc}
85       */
86      public void execute()
87          throws MojoExecutionException
88      {
89          // force value for this plugin
90          skipErrorNoDescriptorsFound = true;
91  
92          super.execute();
93  
94          if ( !project.getCompileSourceRoots().contains( outputDirectory.getAbsolutePath() ) && !skip )
95          {
96              project.addCompileSourceRoot( outputDirectory.getAbsolutePath() );
97          }
98  
99      }
100 
101 }