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