improved documentation

git-svn-id: https://svn.apache.org/repos/asf/maven/plugin-tools/trunk@1342927 13f79535-47bb-0310-9956-ffa450edef68
master
Herve Boutemy 2012-05-26 17:06:12 +00:00
parent 402137be54
commit a50582836c
1 changed files with 16 additions and 23 deletions

View File

@ -28,6 +28,7 @@ import org.apache.maven.project.MavenProject;
import org.apache.maven.tools.plugin.ExtendedMojoDescriptor; import org.apache.maven.tools.plugin.ExtendedMojoDescriptor;
import org.apache.maven.tools.plugin.PluginToolsRequest; import org.apache.maven.tools.plugin.PluginToolsRequest;
import org.codehaus.plexus.util.IOUtil; import org.codehaus.plexus.util.IOUtil;
import org.codehaus.plexus.util.PropertyUtils;
import org.codehaus.plexus.util.StringUtils; import org.codehaus.plexus.util.StringUtils;
import org.codehaus.plexus.util.xml.PrettyPrintXMLWriter; import org.codehaus.plexus.util.xml.PrettyPrintXMLWriter;
import org.codehaus.plexus.util.xml.XMLWriter; import org.codehaus.plexus.util.xml.XMLWriter;
@ -51,7 +52,8 @@ import java.util.Properties;
import java.util.Set; import java.util.Set;
/** /**
* Generate a <a href="/ref/current/maven-plugin-api/plugin.html">Maven Plugin Descriptor XML file</a>. * Generate a <a href="/ref/current/maven-plugin-api/plugin.html">Maven Plugin Descriptor XML file</a> and
* corresponding help content.
* *
* @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
@ -74,22 +76,10 @@ public class PluginDescriptorGenerator
if ( tmpPropertiesFile.exists() ) if ( tmpPropertiesFile.exists() )
{ {
Properties properties = new Properties(); Properties properties = PropertyUtils.loadProperties( tmpPropertiesFile );
FileInputStream fis = null;
try
{
fis = new FileInputStream( tmpPropertiesFile );
properties.load( fis );
}
catch ( IOException e )
{
throw new GeneratorException( e.getMessage(), e );
}
finally
{
IOUtil.close( fis );
}
String helpPackageName = properties.getProperty( "helpPackageName" ); String helpPackageName = properties.getProperty( "helpPackageName" );
// if helpPackageName property is empty we have to rewrite the class with a better package name than empty // if helpPackageName property is empty we have to rewrite the class with a better package name than empty
if ( StringUtils.isEmpty( helpPackageName ) ) if ( StringUtils.isEmpty( helpPackageName ) )
{ {
@ -105,8 +95,11 @@ public class PluginDescriptorGenerator
try try
{ {
// write complete plugin.xml descriptor
File f = new File( destinationDirectory, "plugin.xml" ); File f = new File( destinationDirectory, "plugin.xml" );
writeDescriptor( f, request, false ); writeDescriptor( f, request, false );
// write plugin-description.xml help-descriptor
MavenProject mavenProject = request.getProject(); MavenProject mavenProject = request.getProject();
String pluginDescriptionFilePath = String pluginDescriptionFilePath =
"META-INF/maven/" + mavenProject.getGroupId() + "/" + mavenProject.getArtifactId() "META-INF/maven/" + mavenProject.getGroupId() + "/" + mavenProject.getArtifactId()
@ -124,7 +117,7 @@ public class PluginDescriptorGenerator
} }
} }
public void writeDescriptor( File destinationFile, PluginToolsRequest request, boolean cleanDescription ) public void writeDescriptor( File destinationFile, PluginToolsRequest request, boolean helpDescriptor )
throws IOException, DuplicateMojoDescriptorException throws IOException, DuplicateMojoDescriptorException
{ {
PluginDescriptor pluginDescriptor = request.getPluginDescriptor(); PluginDescriptor pluginDescriptor = request.getPluginDescriptor();
@ -153,7 +146,7 @@ public class PluginDescriptorGenerator
w.startElement( "plugin" ); w.startElement( "plugin" );
GeneratorUtils.element( w, "name", pluginDescriptor.getName() ); GeneratorUtils.element( w, "name", pluginDescriptor.getName() );
if ( cleanDescription ) if ( helpDescriptor )
{ {
GeneratorUtils.element( w, "description", GeneratorUtils.toText( pluginDescriptor.getDescription() ) ); GeneratorUtils.element( w, "description", GeneratorUtils.toText( pluginDescriptor.getDescription() ) );
} }
@ -181,7 +174,7 @@ public class PluginDescriptorGenerator
@SuppressWarnings( "unchecked" ) List<MojoDescriptor> descriptors = pluginDescriptor.getMojos(); @SuppressWarnings( "unchecked" ) List<MojoDescriptor> descriptors = pluginDescriptor.getMojos();
for ( MojoDescriptor descriptor : descriptors ) for ( MojoDescriptor descriptor : descriptors )
{ {
processMojoDescriptor( descriptor, w, cleanDescription ); processMojoDescriptor( descriptor, w, helpDescriptor );
} }
} }
@ -208,9 +201,9 @@ public class PluginDescriptorGenerator
/** /**
* @param mojoDescriptor not null * @param mojoDescriptor not null
* @param w not null * @param w not null
* @param cleanDescription will clean html content from description fields * @param helpDescriptor will clean html content from description fields
*/ */
protected void processMojoDescriptor( MojoDescriptor mojoDescriptor, XMLWriter w, boolean cleanDescription ) protected void processMojoDescriptor( MojoDescriptor mojoDescriptor, XMLWriter w, boolean helpDescriptor )
{ {
w.startElement( "mojo" ); w.startElement( "mojo" );
@ -231,7 +224,7 @@ public class PluginDescriptorGenerator
if ( description != null ) if ( description != null )
{ {
w.startElement( "description" ); w.startElement( "description" );
if ( cleanDescription ) if ( helpDescriptor )
{ {
w.writeText( GeneratorUtils.toText( mojoDescriptor.getDescription() ) ); w.writeText( GeneratorUtils.toText( mojoDescriptor.getDescription() ) );
} }
@ -482,7 +475,7 @@ public class PluginDescriptorGenerator
GeneratorUtils.element( w, "required", Boolean.toString( parameter.isRequired() ) ); GeneratorUtils.element( w, "required", Boolean.toString( parameter.isRequired() ) );
GeneratorUtils.element( w, "editable", Boolean.toString( parameter.isEditable() ) ); GeneratorUtils.element( w, "editable", Boolean.toString( parameter.isEditable() ) );
if ( cleanDescription ) if ( helpDescriptor )
{ {
GeneratorUtils.element( w, "description", GeneratorUtils.toText( parameter.getDescription() ) ); GeneratorUtils.element( w, "description", GeneratorUtils.toText( parameter.getDescription() ) );
} }