001    package 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    
022    import java.io.File;
023    import org.apache.maven.plugin.MojoExecutionException;
024    import org.apache.maven.plugins.annotations.Component;
025    import org.apache.maven.plugins.annotations.LifecyclePhase;
026    import org.apache.maven.plugins.annotations.Mojo;
027    import org.apache.maven.plugins.annotations.Parameter;
028    import org.apache.maven.plugins.annotations.ResolutionScope;
029    import org.apache.maven.tools.plugin.generator.Generator;
030    import org.apache.maven.tools.plugin.generator.PluginDescriptorGenerator;
031    import org.codehaus.plexus.logging.Logger;
032    
033    /**
034     * Generate a plugin descriptor.
035     * <br/>
036     * <b>Note:</b> Since 3.0, for Java 5 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     *
042     * @author <a href="mailto:jason@maven.org">Jason van Zyl</a>
043     * @version $Id: DescriptorGeneratorMojo.java 1406615 2012-11-07 13:26:25Z krosenvold $
044     * @since 2.0
045     */
046    @Mojo( name = "descriptor", defaultPhase = LifecyclePhase.PROCESS_CLASSES,
047           requiresDependencyResolution = ResolutionScope.RUNTIME, threadSafe = true )
048    public class DescriptorGeneratorMojo
049        extends AbstractGeneratorMojo
050    {
051        /**
052         * The directory where the generated <code>plugin.xml</code> file will be put.
053         */
054        @Parameter( defaultValue = "${project.build.outputDirectory}/META-INF/maven" )
055        protected File outputDirectory;
056    
057        /**
058         * A flag to disable generation of the <code>plugin.xml</code> in favor of a hand authored plugin descriptor.
059         *
060         * @since 2.6
061         */
062        @Parameter( defaultValue = "false" )
063        private boolean skipDescriptor;
064    
065        /**
066         * {@inheritDoc}
067         */
068        protected File getOutputDirectory()
069        {
070            return outputDirectory;
071        }
072    
073        /**
074         * {@inheritDoc}
075         */
076        protected Generator createGenerator()
077        {
078            return new PluginDescriptorGenerator( getLog() );
079        }
080    
081        /**
082         * {@inheritDoc}
083         */
084        public void execute()
085            throws MojoExecutionException
086        {
087            if ( skipDescriptor )
088            {
089                return;
090            }
091    
092            super.execute();
093        }
094    
095    }