diff --git a/maven-plugin-plugin/src/it/beanshell-simple/invoker.properties b/maven-plugin-plugin/src/it/beanshell-simple/invoker.properties new file mode 100644 index 0000000..7cec502 --- /dev/null +++ b/maven-plugin-plugin/src/it/beanshell-simple/invoker.properties @@ -0,0 +1,3 @@ +invoker.goals.1 = clean install -DskipTests +invoker.goals.2 = org.apache.maven.beanshell.it:maven-beanshell-it-basic:1.0-SNAPSHOT:touch -Dname=touch.txt + diff --git a/maven-plugin-plugin/src/it/beanshell-simple/pom.xml b/maven-plugin-plugin/src/it/beanshell-simple/pom.xml new file mode 100644 index 0000000..c9dc8e7 --- /dev/null +++ b/maven-plugin-plugin/src/it/beanshell-simple/pom.xml @@ -0,0 +1,66 @@ + + + + + + 4.0.0 + org.apache.maven.beanshell.it + maven-beanshell-it-basic + Basic Beanshell-Mojo Integration Test + 1.0-SNAPSHOT + maven-plugin + + + @project.version@ + + + + + bsh + bsh + 1.3.0 + + + org.apache.maven + maven-script-beanshell + 2.2.1 + + + + + + + org.apache.maven.plugins + maven-plugin-plugin + ${pluginPluginVersion} + + beanshellBasic + + + + org.apache.maven.plugin-tools + maven-plugin-tools-beanshell + ${pluginPluginVersion} + + + + + + diff --git a/maven-plugin-plugin/src/it/beanshell-simple/src/main/scripts/touch.bsh b/maven-plugin-plugin/src/it/beanshell-simple/src/main/scripts/touch.bsh new file mode 100644 index 0000000..5ad2c5c --- /dev/null +++ b/maven-plugin-plugin/src/it/beanshell-simple/src/main/scripts/touch.bsh @@ -0,0 +1,44 @@ +/** + * Touches a test file. + * + * @goal touch + * @requiresDependencyResolution=test + * @deprecated Don't use! + * @since 1.2 + */ + +import org.apache.maven.plugin.Mojo; +import org.apache.maven.script.beanshell.BeanshellMojoAdapter; +import org.codehaus.plexus.util.FileUtils; + + + +execute() +{ + logger.info( "Executing beanshell mojo..." ); + FileUtils.fileWrite( outDir + "/" + name, "This is a Beanshell test" ); +} + +/** + * Output directory for files. + * + * @parameter expression="${project.build.directory}" + * @required + */ +setOutDir( file ) +{ + outDir = file; +} + +/** + * + * + * @parameter expression="${name}" + * @required + */ +setName( name ) +{ + name = name; +} + +return new BeanshellMojoAdapter( (Mojo) this, this.interpreter ); \ No newline at end of file diff --git a/maven-plugin-plugin/src/it/beanshell-simple/verify.groovy b/maven-plugin-plugin/src/it/beanshell-simple/verify.groovy new file mode 100644 index 0000000..e44f964 --- /dev/null +++ b/maven-plugin-plugin/src/it/beanshell-simple/verify.groovy @@ -0,0 +1,8 @@ +File touchFile = new File( basedir, "target/touch.txt" ) +assert touchFile.exists() +assert touchFile.isFile() +content = touchFile.text +assert content.contains('This is a Beanshell test'); + + +return true; diff --git a/maven-plugin-tools-beanshell/src/main/java/org/apache/maven/tools/plugin/extractor/beanshell/BeanshellMojoDescriptorExtractor.java b/maven-plugin-tools-beanshell/src/main/java/org/apache/maven/tools/plugin/extractor/beanshell/BeanshellMojoDescriptorExtractor.java index e7ef14a..3b80923 100644 --- a/maven-plugin-tools-beanshell/src/main/java/org/apache/maven/tools/plugin/extractor/beanshell/BeanshellMojoDescriptorExtractor.java +++ b/maven-plugin-tools-beanshell/src/main/java/org/apache/maven/tools/plugin/extractor/beanshell/BeanshellMojoDescriptorExtractor.java @@ -19,6 +19,16 @@ 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.tools.plugin.PluginToolsRequest; +import org.apache.maven.tools.plugin.extractor.AbstractScriptedMojoDescriptorExtractor; +import org.apache.maven.tools.plugin.extractor.ExtractionException; +import org.apache.maven.tools.plugin.extractor.MojoDescriptorExtractor; +import org.codehaus.plexus.component.annotations.Component; + import java.io.File; import java.io.InputStreamReader; import java.io.UnsupportedEncodingException; @@ -27,39 +37,33 @@ import java.util.List; import java.util.Map; import java.util.Set; -import org.apache.maven.plugin.descriptor.InvalidPluginDescriptorException; -import org.apache.maven.plugin.descriptor.MojoDescriptor; -import org.apache.maven.tools.plugin.PluginToolsRequest; -import org.apache.maven.tools.plugin.extractor.AbstractScriptedMojoDescriptorExtractor; -import org.apache.maven.tools.plugin.extractor.ExtractionException; - -import bsh.EvalError; -import bsh.Interpreter; -import org.apache.maven.tools.plugin.extractor.MojoDescriptorExtractor; -import org.codehaus.plexus.component.annotations.Component; - /** * Extracts Mojo descriptors from BeanShell sources. * + * @version $Id$ * @todo share constants * @todo add example usage tag that can be shown in the doco * @todo need to add validation directives so that systems embedding maven2 can * get validation directives to help users in IDEs. - * @version $Id$ */ -@Component( role = MojoDescriptorExtractor.class, hint = "bsh") +@Component( role = MojoDescriptorExtractor.class, hint = "bsh" ) public class BeanshellMojoDescriptorExtractor extends AbstractScriptedMojoDescriptorExtractor implements MojoDescriptorExtractor { - /** {@inheritDoc} */ + /** + * {@inheritDoc} + */ protected String getScriptFileExtension( PluginToolsRequest request ) { return ".bsh"; } - /** {@inheritDoc} */ - protected List extractMojoDescriptors( Map> scriptFilesKeyedByBasedir, PluginToolsRequest request ) + /** + * {@inheritDoc} + */ + protected List extractMojoDescriptors( Map> scriptFilesKeyedByBasedir, + PluginToolsRequest request ) throws ExtractionException, InvalidPluginDescriptorException { List descriptors = new ArrayList(); @@ -91,11 +95,12 @@ public class BeanshellMojoDescriptorExtractor } /** - * @param basedir not null + * @param basedir not null * @param resource not null - * @param request not null + * @param request not null * @return a new Mojo descriptor instance - * @throws InvalidPluginDescriptorException if any + * @throws InvalidPluginDescriptorException + * if any */ private MojoDescriptor createMojoDescriptor( String basedir, String resource, PluginToolsRequest request ) throws InvalidPluginDescriptorException @@ -116,6 +121,8 @@ public class BeanshellMojoDescriptorExtractor interpreter.set( "mojoDescriptor", mojoDescriptor ); + interpreter.set( "encoding", "UTF-8" ); + interpreter.eval( new InputStreamReader( getClass().getResourceAsStream( "/extractor.bsh" ), "UTF-8" ) ); } catch ( EvalError evalError )