[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(); getOutputDirectory().mkdirs();
createGenerator().execute( getOutputDirectory(), pluginDescriptor ); createGenerator().execute( getOutputDirectory(), request );
} }
catch ( IOException e ) 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.AbstractMavenReport;
import org.apache.maven.reporting.AbstractMavenReportRenderer; import org.apache.maven.reporting.AbstractMavenReportRenderer;
import org.apache.maven.reporting.MavenReportException; 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.extractor.ExtractionException;
import org.apache.maven.tools.plugin.generator.PluginXdocGenerator; import org.apache.maven.tools.plugin.generator.PluginXdocGenerator;
import org.apache.maven.tools.plugin.scanner.MojoScanner; import org.apache.maven.tools.plugin.scanner.MojoScanner;
@ -180,7 +182,9 @@ public class PluginReport
{ {
pluginDescriptor.setDependencies( PluginUtils.toComponentDependencies( project.getRuntimeDependencies() ) ); pluginDescriptor.setDependencies( PluginUtils.toComponentDependencies( project.getRuntimeDependencies() ) );
mojoScanner.populatePluginDescriptor( project, pluginDescriptor ); PluginToolsRequest request = new DefaultPluginToolsRequest( project, pluginDescriptor );
mojoScanner.populatePluginDescriptor( request );
// Generate the plugin's documentation // Generate the plugin's documentation
generatePluginDocumentation( pluginDescriptor, locale ); 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.MojoDescriptor;
import org.apache.maven.plugin.descriptor.PluginDescriptor; import org.apache.maven.plugin.descriptor.PluginDescriptor;
import org.apache.maven.project.MavenProject; 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 * 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. * {@link MojoDescriptor} instances from different types of metadata for a given plugin.
* *
* @author jdcasey * @author jdcasey
* @since 2.5
*/ */
public class DefaultPluginToolsRequest public class DefaultPluginToolsRequest
implements PluginToolsRequest implements PluginToolsRequest
{ {
public static final String DEFAULT_ENCODING = ReaderFactory.FILE_ENCODING;
private PluginDescriptor pluginDescriptor; private PluginDescriptor pluginDescriptor;
private MavenProject project; private MavenProject project;
private String encoding = "ISO-8859-1"; private String encoding = DEFAULT_ENCODING;
public DefaultPluginToolsRequest( MavenProject project, PluginDescriptor pluginDescriptor ) public DefaultPluginToolsRequest( MavenProject project, PluginDescriptor pluginDescriptor )
{ {
@ -34,6 +38,15 @@ public class DefaultPluginToolsRequest
return pluginDescriptor; return pluginDescriptor;
} }
/**
* {@inheritDoc}
*/
public PluginToolsRequest setPluginDescriptor( PluginDescriptor pluginDescriptor )
{
this.pluginDescriptor = pluginDescriptor;
return this;
}
/** /**
* {@inheritDoc} * {@inheritDoc}
*/ */
@ -42,6 +55,15 @@ public class DefaultPluginToolsRequest
return project; return project;
} }
/**
* {@inheritDoc}
*/
public PluginToolsRequest setProject( MavenProject project )
{
this.project = project;
return this;
}
/** /**
* {@inheritDoc} * {@inheritDoc}
*/ */

View File

@ -9,6 +9,7 @@ import org.apache.maven.project.MavenProject;
* instances from metadata for a certain type of mojo. * instances from metadata for a certain type of mojo.
* *
* @author jdcasey * @author jdcasey
* @since 2.5
*/ */
public interface PluginToolsRequest public interface PluginToolsRequest
{ {
@ -18,22 +19,32 @@ public interface PluginToolsRequest
*/ */
MavenProject getProject(); MavenProject getProject();
/**
* @see PluginToolsRequest#getProject()
*/
PluginToolsRequest setProject( MavenProject project );
/** /**
* Return the {@link PluginDescriptor} currently being populated as part of the build of the * Return the {@link PluginDescriptor} currently being populated as part of the build of the
* current plugin project. * current plugin project.
*/ */
PluginDescriptor getPluginDescriptor(); PluginDescriptor getPluginDescriptor();
/**
* @see PluginToolsRequest#getPluginDescriptor()
*/
PluginToolsRequest setPluginDescriptor( PluginDescriptor pluginDescriptor );
/** /**
* Gets the file encoding of the source files. * Gets the file encoding of the source files.
* *
* @return The file encoding of the source files, never <code>null</code>. * @return The file encoding of the source files, never <code>null</code>.
*/ */
public String getEncoding(); String getEncoding();
/** /**
* @see PluginToolsRequest#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.plugin.descriptor.PluginDescriptor;
import org.apache.maven.tools.plugin.PluginToolsRequest;
import java.io.File; import java.io.File;
import java.io.IOException; import java.io.IOException;
@ -38,7 +39,21 @@ public interface Generator
* @param destinationDirectory required * @param destinationDirectory required
* @param pluginDescriptor required * @param pluginDescriptor required
* @throws IOException if any * @throws IOException if any
*
* @deprecated Use {@link Generator#execute(File, PluginToolsRequest)} instead.
*/ */
void execute( File destinationDirectory, PluginDescriptor pluginDescriptor ) void execute( File destinationDirectory, PluginDescriptor pluginDescriptor )
throws IOException; 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.Parameter;
import org.apache.maven.plugin.descriptor.PluginDescriptor; import org.apache.maven.plugin.descriptor.PluginDescriptor;
import org.apache.maven.plugin.descriptor.Requirement; 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.apache.maven.tools.plugin.util.PluginUtils;
import org.codehaus.plexus.util.IOUtil; import org.codehaus.plexus.util.IOUtil;
import org.codehaus.plexus.util.StringUtils; import org.codehaus.plexus.util.StringUtils;
@ -55,6 +57,15 @@ public class PluginDescriptorGenerator
public void execute( File destinationDirectory, PluginDescriptor pluginDescriptor ) public void execute( File destinationDirectory, PluginDescriptor pluginDescriptor )
throws IOException 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"; String encoding = "UTF-8";
File f = new File( destinationDirectory, "plugin.xml" ); 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.MojoDescriptor;
import org.apache.maven.plugin.descriptor.Parameter; import org.apache.maven.plugin.descriptor.Parameter;
import org.apache.maven.plugin.descriptor.PluginDescriptor; 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.apache.maven.tools.plugin.util.PluginUtils;
import org.codehaus.plexus.logging.AbstractLogEnabled; import org.codehaus.plexus.logging.AbstractLogEnabled;
import org.codehaus.plexus.logging.Logger; import org.codehaus.plexus.logging.Logger;
@ -78,6 +80,15 @@ public class PluginHelpGenerator
public void execute( File destinationDirectory, PluginDescriptor pluginDescriptor ) public void execute( File destinationDirectory, PluginDescriptor pluginDescriptor )
throws IOException 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 ) if ( pluginDescriptor.getMojos() == null || pluginDescriptor.getMojos().size() < 1 )
{ {
return; 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.Parameter;
import org.apache.maven.plugin.descriptor.PluginDescriptor; import org.apache.maven.plugin.descriptor.PluginDescriptor;
import org.apache.maven.project.MavenProject; 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.apache.maven.tools.plugin.util.PluginUtils;
import org.codehaus.plexus.util.IOUtil; import org.codehaus.plexus.util.IOUtil;
import org.codehaus.plexus.util.StringUtils; import org.codehaus.plexus.util.StringUtils;
@ -97,9 +99,16 @@ public class PluginXdocGenerator
public void execute( File destinationDirectory, PluginDescriptor pluginDescriptor ) public void execute( File destinationDirectory, PluginDescriptor pluginDescriptor )
throws IOException 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(); MojoDescriptor descriptor = (MojoDescriptor) it.next();

View File

@ -117,7 +117,7 @@ public class BeanshellMojoDescriptorExtractor
interpreter.set( "mojoDescriptor", mojoDescriptor ); 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 ) catch ( EvalError evalError )
{ {