001package org.apache.maven.plugin.plugin; 002 003/* 004 * Licensed to the Apache Software Foundation (ASF) under one 005 * or more contributor license agreements. See the NOTICE file 006 * distributed with this work for additional information 007 * regarding copyright ownership. The ASF licenses this file 008 * to you under the Apache License, Version 2.0 (the 009 * "License"); you may not use this file except in compliance 010 * with the License. You may obtain a copy of the License at 011 * 012 * http://www.apache.org/licenses/LICENSE-2.0 013 * 014 * Unless required by applicable law or agreed to in writing, 015 * software distributed under the License is distributed on an 016 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 017 * KIND, either express or implied. See the License for the 018 * specific language governing permissions and limitations 019 * under the License. 020 */ 021 022import java.io.File; 023import org.apache.maven.plugin.MojoExecutionException; 024import org.apache.maven.plugins.annotations.LifecyclePhase; 025import org.apache.maven.plugins.annotations.Mojo; 026import org.apache.maven.plugins.annotations.Parameter; 027import org.apache.maven.plugins.annotations.ResolutionScope; 028import org.apache.maven.tools.plugin.generator.Generator; 029import org.apache.maven.tools.plugin.generator.PluginDescriptorGenerator; 030 031/** 032 * <p> 033 * Generate a plugin descriptor. 034 * </p> 035 * <p> 036 * <b>Note:</b> Since 3.0, for Java plugin annotations support, 037 * default <a href="http://maven.apache.org/ref/current/maven-core/lifecycles.html">phase</a> 038 * defined by this goal is after the "compilation" of any scripts. This doesn't override 039 * <a href="/ref/current/maven-core/default-bindings.html#Bindings_for_maven-plugin_packaging">the default binding coded 040 * at generate-resources phase</a> in Maven core. 041 * </p> 042 * @author <a href="mailto:jason@maven.org">Jason van Zyl</a> 043 * @since 2.0 044 */ 045@Mojo( name = "descriptor", defaultPhase = LifecyclePhase.PROCESS_CLASSES, 046 requiresDependencyResolution = ResolutionScope.COMPILE_PLUS_RUNTIME, threadSafe = true ) 047public class DescriptorGeneratorMojo 048 extends AbstractGeneratorMojo 049{ 050 /** 051 * The directory where the generated <code>plugin.xml</code> file will be put. 052 */ 053 @Parameter( defaultValue = "${project.build.outputDirectory}/META-INF/maven", readonly = true ) 054 protected File outputDirectory; 055 056 /** 057 * A flag to disable generation of the <code>plugin.xml</code> in favor of a hand authored plugin descriptor. 058 * 059 * @since 2.6 060 */ 061 @Parameter( defaultValue = "false" ) 062 private boolean skipDescriptor; 063 064 /** 065 * {@inheritDoc} 066 */ 067 @Override 068 protected File getOutputDirectory() 069 { 070 return outputDirectory; 071 } 072 073 /** 074 * {@inheritDoc} 075 */ 076 @Override 077 protected Generator createGenerator() 078 { 079 return new PluginDescriptorGenerator( getLog() ); 080 } 081 082 /** 083 * {@inheritDoc} 084 */ 085 @Override 086 public void execute() 087 throws MojoExecutionException 088 { 089 if ( skipDescriptor ) 090 { 091 return; 092 } 093 094 super.execute(); 095 } 096 097}