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
024 import org.apache.maven.plugin.MojoExecutionException;
025 import org.apache.maven.plugins.annotations.Component;
026 import org.apache.maven.plugins.annotations.LifecyclePhase;
027 import org.apache.maven.plugins.annotations.Mojo;
028 import org.apache.maven.plugins.annotations.Parameter;
029 import org.apache.maven.plugins.annotations.ResolutionScope;
030 import org.apache.maven.tools.plugin.generator.Generator;
031 import org.apache.maven.tools.plugin.generator.PluginHelpGenerator;
032 import org.codehaus.plexus.velocity.VelocityComponent;
033
034 /**
035 * Generates a <code>HelpMojo</code> class.
036 *
037 * @author <a href="mailto:vincent.siveton@gmail.com">Vincent Siveton</a>
038 * @version $Id: HelpGeneratorMojo.java 1406001 2012-11-05 22:34:46Z rfscholte $
039 * @since 2.4
040 */
041 @Mojo( name = "helpmojo", defaultPhase = LifecyclePhase.GENERATE_SOURCES, threadSafe = true, requiresDependencyResolution = ResolutionScope.COMPILE )
042 public class HelpGeneratorMojo
043 extends AbstractGeneratorMojo
044 {
045 /**
046 * The directory where the generated <code>HelpMojo</code> file will be put.
047 */
048 @Parameter( defaultValue = "${project.build.directory}/generated-sources/plugin" )
049 protected File outputDirectory;
050
051 /**
052 * The name of the package for the generated <code>HelpMojo</code>. By default, the package will be calculated based
053 * on the packages of the other plugin goals.
054 *
055 * @since 2.6
056 */
057 @Parameter
058 private String helpPackageName;
059
060 /**
061 * Velocity component.
062 */
063 @Component
064 private VelocityComponent velocity;
065
066 /**
067 * {@inheritDoc}
068 */
069 protected File getOutputDirectory()
070 {
071 return outputDirectory;
072 }
073
074 /**
075 * {@inheritDoc}
076 */
077 protected Generator createGenerator()
078 {
079 return new PluginHelpGenerator().setHelpPackageName( helpPackageName ).setVelocityComponent( this.velocity );
080 }
081
082 /**
083 * {@inheritDoc}
084 */
085 public void execute()
086 throws MojoExecutionException
087 {
088 super.execute();
089
090 if ( !project.getCompileSourceRoots().contains( outputDirectory.getAbsolutePath() ) && !skip )
091 {
092 project.addCompileSourceRoot( outputDirectory.getAbsolutePath() );
093 }
094
095 }
096
097 }