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