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.Component; 25 import org.apache.maven.plugins.annotations.LifecyclePhase; 26 import org.apache.maven.plugins.annotations.Mojo; 27 import org.apache.maven.plugins.annotations.Parameter; 28 import org.apache.maven.plugins.annotations.ResolutionScope; 29 import org.apache.maven.tools.plugin.generator.Generator; 30 import org.apache.maven.tools.plugin.generator.PluginDescriptorGenerator; 31 import org.codehaus.plexus.logging.Logger; 32 33 /** 34 * Generate a plugin descriptor. 35 * <br/> 36 * <b>Note:</b> Since 3.0, for Java 5 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 * 42 * @author <a href="mailto:jason@maven.org">Jason van Zyl</a> 43 * @version $Id: DescriptorGeneratorMojo.java 1406615 2012-11-07 13:26:25Z krosenvold $ 44 * @since 2.0 45 */ 46 @Mojo( name = "descriptor", defaultPhase = LifecyclePhase.PROCESS_CLASSES, 47 requiresDependencyResolution = ResolutionScope.RUNTIME, threadSafe = true ) 48 public class DescriptorGeneratorMojo 49 extends AbstractGeneratorMojo 50 { 51 /** 52 * The directory where the generated <code>plugin.xml</code> file will be put. 53 */ 54 @Parameter( defaultValue = "${project.build.outputDirectory}/META-INF/maven" ) 55 protected File outputDirectory; 56 57 /** 58 * A flag to disable generation of the <code>plugin.xml</code> in favor of a hand authored plugin descriptor. 59 * 60 * @since 2.6 61 */ 62 @Parameter( defaultValue = "false" ) 63 private boolean skipDescriptor; 64 65 /** 66 * {@inheritDoc} 67 */ 68 protected File getOutputDirectory() 69 { 70 return outputDirectory; 71 } 72 73 /** 74 * {@inheritDoc} 75 */ 76 protected Generator createGenerator() 77 { 78 return new PluginDescriptorGenerator( getLog() ); 79 } 80 81 /** 82 * {@inheritDoc} 83 */ 84 public void execute() 85 throws MojoExecutionException 86 { 87 if ( skipDescriptor ) 88 { 89 return; 90 } 91 92 super.execute(); 93 } 94 95 }