avoid code duplication for plugin-help.xml path between PluginDescriptorGenerator and PluginHelpGenerator

git-svn-id: https://svn.apache.org/repos/asf/maven/plugin-tools/trunk@1389657 13f79535-47bb-0310-9956-ffa450edef68
master
Herve Boutemy 2012-09-24 23:57:41 +00:00
parent 55e9f2dcfb
commit b93ab8fca8
2 changed files with 13 additions and 10 deletions

View File

@ -48,7 +48,7 @@ import java.util.Set;
/** /**
* Generate a <a href="/ref/current/maven-plugin-api/plugin.html">Maven Plugin Descriptor XML file</a> and * Generate a <a href="/ref/current/maven-plugin-api/plugin.html">Maven Plugin Descriptor XML file</a> and
* corresponding help content. * corresponding <code>plugin-help.xml</code> help content for {@link PluginHelpGenerator}.
* *
* @version $Id$ * @version $Id$
* @todo add example usage tag that can be shown in the doco * @todo add example usage tag that can be shown in the doco
@ -76,10 +76,11 @@ public class PluginDescriptorGenerator
// write plugin-help.xml help-descriptor // write plugin-help.xml help-descriptor
MavenProject mavenProject = request.getProject(); MavenProject mavenProject = request.getProject();
String pluginHelpFilePath =
"META-INF/maven/" + mavenProject.getGroupId() + "/" + mavenProject.getArtifactId() + "/plugin-help.xml";
f = new File( request.getProject().getBuild().getOutputDirectory(), pluginHelpFilePath ); f =
new File( mavenProject.getBuild().getOutputDirectory(),
PluginHelpGenerator.getPluginHelpPath( mavenProject ) );
writeDescriptor( f, request, true ); writeDescriptor( f, request, true );
} }
catch ( IOException e ) catch ( IOException e )

View File

@ -138,10 +138,7 @@ public class PluginHelpGenerator
File helpClass = new File( destinationDirectory, sourcePath ); File helpClass = new File( destinationDirectory, sourcePath );
helpClass.getParentFile().mkdirs(); helpClass.getParentFile().mkdirs();
MavenProject mavenProject = request.getProject(); String helpClassSources = getHelpClassSources( getPluginHelpPath( request.getProject() ), pluginDescriptor );
String pluginResourcesPath = "META-INF/maven/" + mavenProject.getGroupId() + "/" + mavenProject.getArtifactId();
String helpClassSources = getHelpClassSources( pluginResourcesPath, pluginDescriptor );
FileUtils.fileWrite( helpClass, request.getEncoding(), helpClassSources ); FileUtils.fileWrite( helpClass, request.getEncoding(), helpClassSources );
} }
@ -172,7 +169,7 @@ public class PluginHelpGenerator
// Private methods // Private methods
// ---------------------------------------------------------------------- // ----------------------------------------------------------------------
private String getHelpClassSources( String pluginResourcesPath, PluginDescriptor pluginDescriptor ) private String getHelpClassSources( String pluginHelpPath, PluginDescriptor pluginDescriptor )
{ {
Properties properties = new Properties(); Properties properties = new Properties();
VelocityContext context = new VelocityContext( properties ); VelocityContext context = new VelocityContext( properties );
@ -184,7 +181,7 @@ public class PluginHelpGenerator
{ {
properties.put( "helpPackageName", "" ); properties.put( "helpPackageName", "" );
} }
properties.put( "pluginHelpPath", pluginResourcesPath + "/plugin-help.xml" ); properties.put( "pluginHelpPath", pluginHelpPath );
properties.put( "artifactId", pluginDescriptor.getArtifactId() ); properties.put( "artifactId", pluginDescriptor.getArtifactId() );
properties.put( "goalPrefix", pluginDescriptor.getGoalPrefix() ); properties.put( "goalPrefix", pluginDescriptor.getGoalPrefix() );
@ -256,6 +253,11 @@ public class PluginHelpGenerator
} }
} }
static String getPluginHelpPath( MavenProject mavenProject )
{
return "META-INF/maven/" + mavenProject.getGroupId() + "/" + mavenProject.getArtifactId() + "/plugin-help.xml";
}
/** /**
* Rewrite Help Mojo to match actual Mojos package name if it was not available at source generation * Rewrite Help Mojo to match actual Mojos package name if it was not available at source generation
* time. This is used at descriptor generation time. * time. This is used at descriptor generation time.