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  import org.apache.maven.plugin.MojoExecutionException;
24  import org.apache.maven.plugins.annotations.LifecyclePhase;
25  import org.apache.maven.plugins.annotations.Mojo;
26  import org.apache.maven.plugins.annotations.Parameter;
27  import org.apache.maven.plugins.annotations.ResolutionScope;
28  import org.apache.maven.tools.plugin.generator.Generator;
29  import org.apache.maven.tools.plugin.generator.PluginDescriptorGenerator;
30  
31  /**
32   * Generate a plugin descriptor.
33   * <br/>
34   * <b>Note:</b> Since 3.0, for Java 5 plugin annotations support,
35   * default <a href="http://maven.apache.org/ref/current/maven-core/lifecycles.html">phase</a>
36   * defined by this goal is after the "compilation" of any scripts. This doesn't override
37   * <a href="/ref/current/maven-core/default-bindings.html#Bindings_for_maven-plugin_packaging">the default binding coded
38   * at generate-resources phase</a> in Maven core.
39   *
40   * @author <a href="mailto:jason@maven.org">Jason van Zyl</a>
41   * @version $Id: DescriptorGeneratorMojo.html 995996 2016-08-26 22:31:42Z rfscholte $
42   * @since 2.0
43   */
44  @Mojo( name = "descriptor", defaultPhase = LifecyclePhase.PROCESS_CLASSES,
45         requiresDependencyResolution = ResolutionScope.RUNTIME, threadSafe = true )
46  public class DescriptorGeneratorMojo
47      extends AbstractGeneratorMojo
48  {
49      /**
50       * The directory where the generated <code>plugin.xml</code> file will be put.
51       */
52      @Parameter( defaultValue = "${project.build.outputDirectory}/META-INF/maven" )
53      protected File outputDirectory;
54  
55      /**
56       * A flag to disable generation of the <code>plugin.xml</code> in favor of a hand authored plugin descriptor.
57       *
58       * @since 2.6
59       */
60      @Parameter( defaultValue = "false" )
61      private boolean skipDescriptor;
62  
63      /**
64       * {@inheritDoc}
65       */
66      protected File getOutputDirectory()
67      {
68          return outputDirectory;
69      }
70  
71      /**
72       * {@inheritDoc}
73       */
74      protected Generator createGenerator()
75      {
76          return new PluginDescriptorGenerator( getLog() );
77      }
78  
79      /**
80       * {@inheritDoc}
81       */
82      public void execute()
83          throws MojoExecutionException
84      {
85          if ( skipDescriptor )
86          {
87              return;
88          }
89  
90          super.execute();
91      }
92  
93  }