[MPLUGIN-101] Add encoding parameter to maven-plugin-plugin mojos, and add encoding to PluginToolsRequest to allow it to pass through the plugin tools when executed.
git-svn-id: https://svn.apache.org/repos/asf/maven/plugin-tools/trunk@746366 13f79535-47bb-0310-9956-ffa450edef68master
parent
0e1c3d6155
commit
03ed8882f2
|
|
@ -61,7 +61,7 @@
|
|||
<properties>
|
||||
<doxiaVersion>1.0-alpha-10</doxiaVersion>
|
||||
<doxia-sitetoolsVersion>1.0-alpha-10</doxia-sitetoolsVersion>
|
||||
<pluginToolsVersion>[2.5-SNAPSHOT,)</pluginToolsVersion>
|
||||
<pluginToolsVersion>2.5-SNAPSHOT</pluginToolsVersion>
|
||||
</properties>
|
||||
|
||||
<!-- Copy from project up -->
|
||||
|
|
|
|||
|
|
@ -61,6 +61,14 @@ public abstract class AbstractGeneratorMojo
|
|||
*/
|
||||
protected MojoScanner mojoScanner;
|
||||
|
||||
/**
|
||||
* The file encoding of the source files.
|
||||
*
|
||||
* @parameter expression="${encoding}" default-value="ISO-8859-1"
|
||||
* @since 2.5
|
||||
*/
|
||||
protected String encoding;
|
||||
|
||||
/**
|
||||
* The goal prefix that will appear before the ":".
|
||||
*
|
||||
|
|
@ -147,7 +155,7 @@ public abstract class AbstractGeneratorMojo
|
|||
{
|
||||
pluginDescriptor.setDependencies( PluginUtils.toComponentDependencies( project.getRuntimeDependencies() ) );
|
||||
|
||||
PluginToolsRequest request = new DefaultPluginToolsRequest( project, pluginDescriptor );
|
||||
PluginToolsRequest request = new DefaultPluginToolsRequest( project, pluginDescriptor ).setEncoding( encoding );
|
||||
|
||||
mojoScanner.populatePluginDescriptor( request );
|
||||
|
||||
|
|
|
|||
|
|
@ -5,9 +5,8 @@ import org.apache.maven.plugin.descriptor.PluginDescriptor;
|
|||
import org.apache.maven.project.MavenProject;
|
||||
|
||||
/**
|
||||
* 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.
|
||||
* 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
|
||||
*/
|
||||
|
|
@ -16,8 +15,11 @@ public class DefaultPluginToolsRequest
|
|||
{
|
||||
|
||||
private PluginDescriptor pluginDescriptor;
|
||||
|
||||
private MavenProject project;
|
||||
|
||||
|
||||
private String encoding = "ISO-8859-1";
|
||||
|
||||
public DefaultPluginToolsRequest( MavenProject project, PluginDescriptor pluginDescriptor )
|
||||
{
|
||||
this.project = project;
|
||||
|
|
@ -31,7 +33,7 @@ public class DefaultPluginToolsRequest
|
|||
{
|
||||
return pluginDescriptor;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
|
|
@ -40,4 +42,26 @@ public class DefaultPluginToolsRequest
|
|||
return project;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public String getEncoding()
|
||||
{
|
||||
return this.encoding;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public PluginToolsRequest setEncoding( String encoding )
|
||||
{
|
||||
if ( encoding == null )
|
||||
{
|
||||
throw new IllegalArgumentException( "unspecified source file encoding" );
|
||||
}
|
||||
this.encoding = encoding;
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -24,4 +24,16 @@ public interface PluginToolsRequest
|
|||
*/
|
||||
PluginDescriptor getPluginDescriptor();
|
||||
|
||||
/**
|
||||
* Gets the file encoding of the source files.
|
||||
*
|
||||
* @return The file encoding of the source files, never <code>null</code>.
|
||||
*/
|
||||
public String getEncoding();
|
||||
|
||||
/**
|
||||
* @see PluginToolsRequest#getEncoding()
|
||||
*/
|
||||
public PluginToolsRequest setEncoding( String encoding );
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -238,4 +238,4 @@ public abstract class AbstractScriptedMojoDescriptorExtractor
|
|||
*/
|
||||
protected abstract String getScriptFileExtension( PluginToolsRequest request );
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -56,6 +56,7 @@ public interface MojoDescriptorExtractor
|
|||
* @return a list of mojo descriptors.
|
||||
* @throws ExtractionException if any
|
||||
* @throws InvalidPluginDescriptorException if any
|
||||
* @since 2.5
|
||||
*/
|
||||
List execute( PluginToolsRequest request )
|
||||
throws ExtractionException, InvalidPluginDescriptorException;
|
||||
|
|
|
|||
|
|
@ -184,4 +184,5 @@ public class DefaultMojoScanner
|
|||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -53,6 +53,7 @@ public interface MojoScanner
|
|||
* @param pluginDescriptor not null
|
||||
* @throws ExtractionException if any
|
||||
* @throws InvalidPluginDescriptorException if any
|
||||
* @since 2.5
|
||||
*/
|
||||
void populatePluginDescriptor( PluginToolsRequest request )
|
||||
throws ExtractionException, InvalidPluginDescriptorException;
|
||||
|
|
@ -68,4 +69,4 @@ public interface MojoScanner
|
|||
*/
|
||||
void setActiveExtractors( Set/* <String> */extractors );
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -60,4 +60,4 @@ public class ScannerTestExtractor
|
|||
return Collections.singletonList( desc );
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -50,4 +50,4 @@ public class TestExtractor
|
|||
return Collections.singletonList( desc );
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -19,11 +19,8 @@ package org.apache.maven.tools.plugin.extractor.beanshell;
|
|||
* under the License.
|
||||
*/
|
||||
|
||||
import bsh.EvalError;
|
||||
import bsh.Interpreter;
|
||||
import org.apache.maven.plugin.descriptor.InvalidPluginDescriptorException;
|
||||
import org.apache.maven.plugin.descriptor.MojoDescriptor;
|
||||
import org.apache.maven.plugin.descriptor.PluginDescriptor;
|
||||
import org.apache.maven.tools.plugin.PluginToolsRequest;
|
||||
import org.apache.maven.tools.plugin.extractor.AbstractScriptedMojoDescriptorExtractor;
|
||||
import org.apache.maven.tools.plugin.extractor.ExtractionException;
|
||||
|
|
@ -37,6 +34,9 @@ import java.util.List;
|
|||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
import bsh.EvalError;
|
||||
import bsh.Interpreter;
|
||||
|
||||
/**
|
||||
* Extracts Mojo descriptors from <a href="http://www.beanshell.org/">BeanShell</a> sources.
|
||||
*
|
||||
|
|
@ -83,7 +83,7 @@ public class BeanshellMojoDescriptorExtractor
|
|||
|
||||
relativePath = relativePath.replace( '\\', '/' );
|
||||
|
||||
MojoDescriptor mojoDescriptor = createMojoDescriptor( basedir, relativePath, request.getPluginDescriptor() );
|
||||
MojoDescriptor mojoDescriptor = createMojoDescriptor( basedir, relativePath, request );
|
||||
descriptors.add( mojoDescriptor );
|
||||
}
|
||||
}
|
||||
|
|
@ -98,11 +98,11 @@ public class BeanshellMojoDescriptorExtractor
|
|||
* @return a new Mojo descriptor instance
|
||||
* @throws InvalidPluginDescriptorException if any
|
||||
*/
|
||||
private MojoDescriptor createMojoDescriptor( String basedir, String resource, PluginDescriptor pluginDescriptor )
|
||||
private MojoDescriptor createMojoDescriptor( String basedir, String resource, PluginToolsRequest request )
|
||||
throws InvalidPluginDescriptorException
|
||||
{
|
||||
MojoDescriptor mojoDescriptor = new MojoDescriptor();
|
||||
mojoDescriptor.setPluginDescriptor( pluginDescriptor );
|
||||
mojoDescriptor.setPluginDescriptor( request.getPluginDescriptor() );
|
||||
|
||||
mojoDescriptor.setLanguage( "bsh" );
|
||||
mojoDescriptor.setComponentConfigurator( "bsh" );
|
||||
|
|
@ -117,7 +117,7 @@ public class BeanshellMojoDescriptorExtractor
|
|||
|
||||
interpreter.set( "mojoDescriptor", mojoDescriptor );
|
||||
|
||||
interpreter.eval( new InputStreamReader( getClass().getResourceAsStream( "/extractor.bsh" ), "UTF-8" ) );
|
||||
interpreter.eval( new InputStreamReader( getClass().getResourceAsStream( "/extractor.bsh" ), request.getEncoding() ) );
|
||||
}
|
||||
catch ( EvalError evalError )
|
||||
{
|
||||
|
|
|
|||
|
|
@ -1,6 +1,7 @@
|
|||
import bsh.*;
|
||||
import java.util.regex.Pattern;
|
||||
import java.io.FileReader;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.InputStreamReader;
|
||||
import org.codehaus.plexus.util.StringUtils;
|
||||
import org.apache.maven.plugin.descriptor.Parameter;
|
||||
import org.apache.maven.plugin.descriptor.InvalidPluginDescriptorException;
|
||||
|
|
@ -120,9 +121,9 @@ getDescription( text )
|
|||
}
|
||||
}
|
||||
|
||||
extract( file, mojoDescriptor )
|
||||
extract( file, encoding, mojoDescriptor )
|
||||
{
|
||||
this.parser = new Parser( new FileReader( file ) );
|
||||
this.parser = new Parser( new InputStreamReader( new FileInputStream( file ), encoding ) );
|
||||
parser.setRetainComments( true );
|
||||
|
||||
this.lastNode = null;
|
||||
|
|
@ -219,4 +220,4 @@ extract( file, mojoDescriptor )
|
|||
}
|
||||
}
|
||||
|
||||
extract( file, mojoDescriptor );
|
||||
extract( file, encoding, mojoDescriptor );
|
||||
|
|
|
|||
|
|
@ -589,7 +589,7 @@ public class JavaMojoDescriptorExtractor
|
|||
public List execute( PluginToolsRequest request )
|
||||
throws ExtractionException, InvalidPluginDescriptorException
|
||||
{
|
||||
JavaClass[] javaClasses = discoverClasses( request.getProject() );
|
||||
JavaClass[] javaClasses = discoverClasses( request );
|
||||
|
||||
List descriptors = new ArrayList();
|
||||
|
||||
|
|
@ -614,11 +614,15 @@ public class JavaMojoDescriptorExtractor
|
|||
|
||||
/**
|
||||
* @param project not null
|
||||
* @param encoding The file encoding of the source files, must not be <code>null</code>.
|
||||
* @return an array of java class
|
||||
*/
|
||||
protected JavaClass[] discoverClasses( final MavenProject project )
|
||||
protected JavaClass[] discoverClasses( final PluginToolsRequest request )
|
||||
{
|
||||
JavaDocBuilder builder = new JavaDocBuilder();
|
||||
builder.setEncoding( request.getEncoding() );
|
||||
|
||||
MavenProject project = request.getProject();
|
||||
|
||||
for ( Iterator i = project.getCompileSourceRoots().iterator(); i.hasNext(); )
|
||||
{
|
||||
|
|
|
|||
|
|
@ -25,6 +25,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 java.io.File;
|
||||
import java.io.UnsupportedEncodingException;
|
||||
|
|
@ -59,7 +61,11 @@ public class JavaMojoDescriptorExtractorTest
|
|||
|
||||
PluginDescriptor pluginDescriptor = new PluginDescriptor();
|
||||
pluginDescriptor.setGoalPrefix( "test" );
|
||||
List results = extractor.execute( project, pluginDescriptor );
|
||||
|
||||
PluginToolsRequest request = new DefaultPluginToolsRequest( project, pluginDescriptor );
|
||||
|
||||
List results = extractor.execute( request );
|
||||
|
||||
assertEquals( "Extracted mojos", 2, results.size() );
|
||||
|
||||
for ( int i = 0; i < 2; i++ )
|
||||
|
|
@ -92,7 +98,10 @@ public class JavaMojoDescriptorExtractorTest
|
|||
|
||||
PluginDescriptor pluginDescriptor = new PluginDescriptor();
|
||||
pluginDescriptor.setGoalPrefix( "test" );
|
||||
List results = extractor.execute( project, pluginDescriptor );
|
||||
|
||||
PluginToolsRequest request = new DefaultPluginToolsRequest( project, pluginDescriptor );
|
||||
|
||||
List results = extractor.execute( request );
|
||||
assertEquals( 1, results.size() );
|
||||
|
||||
MojoDescriptor mojoDescriptor = (MojoDescriptor) results.get( 0 );
|
||||
|
|
@ -156,7 +165,10 @@ public class JavaMojoDescriptorExtractorTest
|
|||
|
||||
PluginDescriptor pluginDescriptor = new PluginDescriptor();
|
||||
pluginDescriptor.setGoalPrefix( "test" );
|
||||
List results = extractor.execute( project, pluginDescriptor );
|
||||
|
||||
PluginToolsRequest request = new DefaultPluginToolsRequest( project, pluginDescriptor );
|
||||
|
||||
List results = extractor.execute( request );
|
||||
assertEquals( 0, results.size() );
|
||||
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue