[MPLUGIN-148] PluginXdocGenerator generates poorly formed output when default values contain XML

Submitted by: Brent N Atkinson

o Enriched with test

git-svn-id: https://svn.apache.org/repos/asf/maven/plugin-tools/trunk@821512 13f79535-47bb-0310-9956-ffa450edef68
master
Benjamin Bentmann 2009-10-04 11:22:41 +00:00
parent 6cb48fbe1e
commit d11dfa4223
5 changed files with 40 additions and 4 deletions

View File

@ -51,7 +51,7 @@ public class MyMojo
/**
* This is a test.
*
* @parameter expression="${string}" default-value="${project.version}"
* @parameter expression="${string}" default-value="${project.version}/</markup-must-be-escaped>"
* @deprecated Just testing.
* @since 1.1
*/

View File

@ -20,7 +20,7 @@ try
{
File file = new File( siteDir, path );
System.out.println( "Checking for existence of doc file: " + file );
if ( !file.isFile() )
if ( !file.isFile() || file.length() <= 0 )
{
System.out.println( "FAILED!" );
return false;

View File

@ -563,7 +563,8 @@ public class PluginXdocGenerator
w.startElement( "ul" );
addedUl = true;
}
writeDetail( getString( "pluginxdoc.mojodescriptor.parameter.default" ), parameter.getDefaultValue(), w );
writeDetail( getString( "pluginxdoc.mojodescriptor.parameter.default" ),
escapeXml( parameter.getDefaultValue() ), w );
if ( addedUl )
{
@ -696,7 +697,7 @@ public class PluginXdocGenerator
if ( StringUtils.isNotEmpty( parameter.getDefaultValue() ) )
{
w.writeMarkup( format( "pluginxdoc.mojodescriptor.parameter.defaultValue",
parameter.getDefaultValue() ) );
escapeXml( parameter.getDefaultValue() ) ) );
}
w.endElement(); //td
w.endElement(); //tr
@ -781,4 +782,22 @@ public class PluginXdocGenerator
return messageFormat.format( args );
}
/**
* @param text the string to escape
* @return A string escaped with XML entities
*/
private String escapeXml( String text )
{
if ( text != null )
{
text = text.replaceAll( "&", "&amp;" );
text = text.replaceAll( "<", "&lt;" );
text = text.replaceAll( ">", "&gt;" );
text = text.replaceAll( "\"", "&quot;" );
text = text.replaceAll( "\'", "&apos;" );
}
return text;
}
}

View File

@ -64,6 +64,7 @@ public abstract class AbstractGeneratorTestCase
Parameter param = new Parameter();
param.setExpression( "${project.build.directory}" );
param.setDefaultValue( "</markup-must-be-escaped>" );
param.setName( "dir" );
param.setRequired( true );
param.setType( "java.lang.String" );

View File

@ -19,6 +19,11 @@ package org.apache.maven.tools.plugin.generator;
* under the License.
*/
import java.io.File;
import org.codehaus.plexus.util.ReaderFactory;
import org.codehaus.plexus.util.xml.Xpp3DomBuilder;
/**
* @author <a href="mailto:jason@maven.org">Jason van Zyl </a>
* @author <a href="mailto:vincent.siveton@gmail.com">Vincent Siveton</a>
@ -27,5 +32,16 @@ package org.apache.maven.tools.plugin.generator;
public class PluginXdocGeneratorTest
extends AbstractGeneratorTestCase
{
// inherits tests from base class
protected void validate( File destinationDirectory )
throws Exception
{
File docFile = new File( destinationDirectory, "testGoal-mojo.xml" );
// sanity check: is the output well-formed?
Xpp3DomBuilder.build( ReaderFactory.newXmlReader( docFile ) );
}
}