[MPLUGIN-100] Pass new PluginToolsRequest through Generator instances too, so generators like the help mojo generator can use the encoding, etc. parameters.

git-svn-id: https://svn.apache.org/repos/asf/maven/plugin-tools/trunk@746372 13f79535-47bb-0310-9956-ffa450edef68
master
John Dennis Casey 2009-02-20 21:42:27 +00:00
parent 03ed8882f2
commit d488f9c649
9 changed files with 91 additions and 8 deletions

View File

@ -161,7 +161,7 @@ public abstract class AbstractGeneratorMojo
getOutputDirectory().mkdirs();
createGenerator().execute( getOutputDirectory(), pluginDescriptor );
createGenerator().execute( getOutputDirectory(), request );
}
catch ( IOException e )
{

View File

@ -39,6 +39,8 @@ import org.apache.maven.project.MavenProject;
import org.apache.maven.reporting.AbstractMavenReport;
import org.apache.maven.reporting.AbstractMavenReportRenderer;
import org.apache.maven.reporting.MavenReportException;
import org.apache.maven.tools.plugin.DefaultPluginToolsRequest;
import org.apache.maven.tools.plugin.PluginToolsRequest;
import org.apache.maven.tools.plugin.extractor.ExtractionException;
import org.apache.maven.tools.plugin.generator.PluginXdocGenerator;
import org.apache.maven.tools.plugin.scanner.MojoScanner;
@ -179,8 +181,10 @@ public class PluginReport
try
{
pluginDescriptor.setDependencies( PluginUtils.toComponentDependencies( project.getRuntimeDependencies() ) );
PluginToolsRequest request = new DefaultPluginToolsRequest( project, pluginDescriptor );
mojoScanner.populatePluginDescriptor( project, pluginDescriptor );
mojoScanner.populatePluginDescriptor( request );
// Generate the plugin's documentation
generatePluginDocumentation( pluginDescriptor, locale );

View File

@ -3,22 +3,26 @@ package org.apache.maven.tools.plugin;
import org.apache.maven.plugin.descriptor.MojoDescriptor;
import org.apache.maven.plugin.descriptor.PluginDescriptor;
import org.apache.maven.project.MavenProject;
import org.codehaus.plexus.util.ReaderFactory;
/**
* Default implementation of {@link PluginToolsRequest}, which is used to pass parameters to components used to extract
* {@link MojoDescriptor} instances from different types of metadata for a given plugin.
*
* @author jdcasey
* @since 2.5
*/
public class DefaultPluginToolsRequest
implements PluginToolsRequest
{
public static final String DEFAULT_ENCODING = ReaderFactory.FILE_ENCODING;
private PluginDescriptor pluginDescriptor;
private MavenProject project;
private String encoding = "ISO-8859-1";
private String encoding = DEFAULT_ENCODING;
public DefaultPluginToolsRequest( MavenProject project, PluginDescriptor pluginDescriptor )
{
@ -33,6 +37,15 @@ public class DefaultPluginToolsRequest
{
return pluginDescriptor;
}
/**
* {@inheritDoc}
*/
public PluginToolsRequest setPluginDescriptor( PluginDescriptor pluginDescriptor )
{
this.pluginDescriptor = pluginDescriptor;
return this;
}
/**
* {@inheritDoc}
@ -41,6 +54,15 @@ public class DefaultPluginToolsRequest
{
return project;
}
/**
* {@inheritDoc}
*/
public PluginToolsRequest setProject( MavenProject project )
{
this.project = project;
return this;
}
/**
* {@inheritDoc}

View File

@ -9,6 +9,7 @@ import org.apache.maven.project.MavenProject;
* instances from metadata for a certain type of mojo.
*
* @author jdcasey
* @since 2.5
*/
public interface PluginToolsRequest
{
@ -18,22 +19,32 @@ public interface PluginToolsRequest
*/
MavenProject getProject();
/**
* @see PluginToolsRequest#getProject()
*/
PluginToolsRequest setProject( MavenProject project );
/**
* Return the {@link PluginDescriptor} currently being populated as part of the build of the
* current plugin project.
*/
PluginDescriptor getPluginDescriptor();
/**
* @see PluginToolsRequest#getPluginDescriptor()
*/
PluginToolsRequest setPluginDescriptor( PluginDescriptor pluginDescriptor );
/**
* Gets the file encoding of the source files.
*
* @return The file encoding of the source files, never <code>null</code>.
*/
public String getEncoding();
String getEncoding();
/**
* @see PluginToolsRequest#getEncoding()
*/
public PluginToolsRequest setEncoding( String encoding );
PluginToolsRequest setEncoding( String encoding );
}

View File

@ -20,6 +20,7 @@ package org.apache.maven.tools.plugin.generator;
*/
import org.apache.maven.plugin.descriptor.PluginDescriptor;
import org.apache.maven.tools.plugin.PluginToolsRequest;
import java.io.File;
import java.io.IOException;
@ -38,7 +39,21 @@ public interface Generator
* @param destinationDirectory required
* @param pluginDescriptor required
* @throws IOException if any
*
* @deprecated Use {@link Generator#execute(File, PluginToolsRequest)} instead.
*/
void execute( File destinationDirectory, PluginDescriptor pluginDescriptor )
throws IOException;
/**
* Execute the generation for a given plugin descriptor.
*
* @param destinationDirectory required
* @param pluginDescriptor required
* @throws IOException if any
*
* @since 2.5
*/
void execute( File destinationDirectory, PluginToolsRequest request )
throws IOException;
}

View File

@ -23,6 +23,8 @@ import org.apache.maven.plugin.descriptor.MojoDescriptor;
import org.apache.maven.plugin.descriptor.Parameter;
import org.apache.maven.plugin.descriptor.PluginDescriptor;
import org.apache.maven.plugin.descriptor.Requirement;
import org.apache.maven.tools.plugin.DefaultPluginToolsRequest;
import org.apache.maven.tools.plugin.PluginToolsRequest;
import org.apache.maven.tools.plugin.util.PluginUtils;
import org.codehaus.plexus.util.IOUtil;
import org.codehaus.plexus.util.StringUtils;
@ -55,6 +57,15 @@ public class PluginDescriptorGenerator
public void execute( File destinationDirectory, PluginDescriptor pluginDescriptor )
throws IOException
{
execute( destinationDirectory, new DefaultPluginToolsRequest( null, pluginDescriptor ) );
}
/** {@inheritDoc} */
public void execute( File destinationDirectory, PluginToolsRequest request )
throws IOException
{
PluginDescriptor pluginDescriptor = request.getPluginDescriptor();
String encoding = "UTF-8";
File f = new File( destinationDirectory, "plugin.xml" );

View File

@ -35,6 +35,8 @@ import java.util.Properties;
import org.apache.maven.plugin.descriptor.MojoDescriptor;
import org.apache.maven.plugin.descriptor.Parameter;
import org.apache.maven.plugin.descriptor.PluginDescriptor;
import org.apache.maven.tools.plugin.DefaultPluginToolsRequest;
import org.apache.maven.tools.plugin.PluginToolsRequest;
import org.apache.maven.tools.plugin.util.PluginUtils;
import org.codehaus.plexus.logging.AbstractLogEnabled;
import org.codehaus.plexus.logging.Logger;
@ -78,6 +80,15 @@ public class PluginHelpGenerator
public void execute( File destinationDirectory, PluginDescriptor pluginDescriptor )
throws IOException
{
execute( destinationDirectory, new DefaultPluginToolsRequest( null, pluginDescriptor ) );
}
/** {@inheritDoc} */
public void execute( File destinationDirectory, PluginToolsRequest request )
throws IOException
{
PluginDescriptor pluginDescriptor = request.getPluginDescriptor();
if ( pluginDescriptor.getMojos() == null || pluginDescriptor.getMojos().size() < 1 )
{
return;

View File

@ -36,6 +36,8 @@ import org.apache.maven.plugin.descriptor.MojoDescriptor;
import org.apache.maven.plugin.descriptor.Parameter;
import org.apache.maven.plugin.descriptor.PluginDescriptor;
import org.apache.maven.project.MavenProject;
import org.apache.maven.tools.plugin.DefaultPluginToolsRequest;
import org.apache.maven.tools.plugin.PluginToolsRequest;
import org.apache.maven.tools.plugin.util.PluginUtils;
import org.codehaus.plexus.util.IOUtil;
import org.codehaus.plexus.util.StringUtils;
@ -97,9 +99,16 @@ public class PluginXdocGenerator
public void execute( File destinationDirectory, PluginDescriptor pluginDescriptor )
throws IOException
{
if ( pluginDescriptor.getMojos() != null )
execute( destinationDirectory, new DefaultPluginToolsRequest( project, pluginDescriptor ) );
}
/** {@inheritDoc} */
public void execute( File destinationDirectory, PluginToolsRequest request )
throws IOException
{
if ( request.getPluginDescriptor().getMojos() != null )
{
for ( Iterator it = pluginDescriptor.getMojos().iterator(); it.hasNext(); )
for ( Iterator it = request.getPluginDescriptor().getMojos().iterator(); it.hasNext(); )
{
MojoDescriptor descriptor = (MojoDescriptor) it.next();

View File

@ -117,7 +117,7 @@ public class BeanshellMojoDescriptorExtractor
interpreter.set( "mojoDescriptor", mojoDescriptor );
interpreter.eval( new InputStreamReader( getClass().getResourceAsStream( "/extractor.bsh" ), request.getEncoding() ) );
interpreter.eval( new InputStreamReader( getClass().getResourceAsStream( "/extractor.bsh" ), "UTF-8" ) );
}
catch ( EvalError evalError )
{