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 * Generate a plugin descriptor. 033 * <br/> 034 * <b>Note:</b> Since 3.0, for Java 5 plugin annotations support, 035 * default <a href="http://maven.apache.org/ref/current/maven-core/lifecycles.html">phase</a> 036 * defined by this goal is after the "compilation" of any scripts. This doesn't override 037 * <a href="/ref/current/maven-core/default-bindings.html#Bindings_for_maven-plugin_packaging">the default binding coded 038 * at generate-resources phase</a> in Maven core. 039 * 040 * @author <a href="mailto:jason@maven.org">Jason van Zyl</a> 041 * @version $Id: DescriptorGeneratorMojo.html 1030109 2018-05-20 14:45:18Z hboutemy $ 042 * @since 2.0 043 */ 044@Mojo( name = "descriptor", defaultPhase = LifecyclePhase.PROCESS_CLASSES, 045 requiresDependencyResolution = ResolutionScope.RUNTIME, threadSafe = true ) 046public class DescriptorGeneratorMojo 047 extends AbstractGeneratorMojo 048{ 049 /** 050 * The directory where the generated <code>plugin.xml</code> file will be put. 051 */ 052 @Parameter( defaultValue = "${project.build.outputDirectory}/META-INF/maven" ) 053 protected File outputDirectory; 054 055 /** 056 * A flag to disable generation of the <code>plugin.xml</code> in favor of a hand authored plugin descriptor. 057 * 058 * @since 2.6 059 */ 060 @Parameter( defaultValue = "false" ) 061 private boolean skipDescriptor; 062 063 /** 064 * {@inheritDoc} 065 */ 066 protected File getOutputDirectory() 067 { 068 return outputDirectory; 069 } 070 071 /** 072 * {@inheritDoc} 073 */ 074 protected Generator createGenerator() 075 { 076 return new PluginDescriptorGenerator( getLog() ); 077 } 078 079 /** 080 * {@inheritDoc} 081 */ 082 public void execute() 083 throws MojoExecutionException 084 { 085 if ( skipDescriptor ) 086 { 087 return; 088 } 089 090 super.execute(); 091 } 092 093}