add a simple it for beanshell mojo
git-svn-id: https://svn.apache.org/repos/asf/maven/plugin-tools/trunk@1338290 13f79535-47bb-0310-9956-ffa450edef68master
parent
5dd3ecc698
commit
dd9b113101
|
|
@ -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
|
||||||
|
|
||||||
|
|
@ -0,0 +1,66 @@
|
||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
|
||||||
|
<!--
|
||||||
|
~ Licensed to the Apache Software Foundation (ASF) under one
|
||||||
|
~ or more contributor license agreements. See the NOTICE file
|
||||||
|
~ distributed with this work for additional information
|
||||||
|
~ regarding copyright ownership. The ASF licenses this file
|
||||||
|
~ to you under the Apache License, Version 2.0 (the
|
||||||
|
~ "License"); you may not use this file except in compliance
|
||||||
|
~ with the License. You may obtain a copy of the License at
|
||||||
|
~
|
||||||
|
~ http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
~
|
||||||
|
~ Unless required by applicable law or agreed to in writing,
|
||||||
|
~ software distributed under the License is distributed on an
|
||||||
|
~ "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||||
|
~ KIND, either express or implied. See the License for the
|
||||||
|
~ specific language governing permissions and limitations
|
||||||
|
~ under the License.
|
||||||
|
-->
|
||||||
|
|
||||||
|
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 ../../../../maven-site/target/site/maven-v4_0_0.xsd ">
|
||||||
|
<modelVersion>4.0.0</modelVersion>
|
||||||
|
<groupId>org.apache.maven.beanshell.it</groupId>
|
||||||
|
<artifactId>maven-beanshell-it-basic</artifactId>
|
||||||
|
<name>Basic Beanshell-Mojo Integration Test</name>
|
||||||
|
<version>1.0-SNAPSHOT</version>
|
||||||
|
<packaging>maven-plugin</packaging>
|
||||||
|
|
||||||
|
<properties>
|
||||||
|
<pluginPluginVersion>@project.version@</pluginPluginVersion><!-- -->
|
||||||
|
</properties>
|
||||||
|
|
||||||
|
<dependencies>
|
||||||
|
<dependency>
|
||||||
|
<groupId>bsh</groupId>
|
||||||
|
<artifactId>bsh</artifactId>
|
||||||
|
<version>1.3.0</version>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.apache.maven</groupId>
|
||||||
|
<artifactId>maven-script-beanshell</artifactId>
|
||||||
|
<version>2.2.1</version>
|
||||||
|
</dependency>
|
||||||
|
</dependencies>
|
||||||
|
|
||||||
|
<build>
|
||||||
|
<plugins>
|
||||||
|
<plugin>
|
||||||
|
<groupId>org.apache.maven.plugins</groupId>
|
||||||
|
<artifactId>maven-plugin-plugin</artifactId>
|
||||||
|
<version>${pluginPluginVersion}</version>
|
||||||
|
<configuration>
|
||||||
|
<prefix>beanshellBasic</prefix>
|
||||||
|
</configuration>
|
||||||
|
<dependencies>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.apache.maven.plugin-tools</groupId>
|
||||||
|
<artifactId>maven-plugin-tools-beanshell</artifactId>
|
||||||
|
<version>${pluginPluginVersion}</version>
|
||||||
|
</dependency>
|
||||||
|
</dependencies>
|
||||||
|
</plugin>
|
||||||
|
</plugins>
|
||||||
|
</build>
|
||||||
|
</project>
|
||||||
|
|
@ -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 );
|
||||||
|
|
@ -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;
|
||||||
|
|
@ -19,6 +19,16 @@ package org.apache.maven.tools.plugin.extractor.beanshell;
|
||||||
* under the License.
|
* 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.File;
|
||||||
import java.io.InputStreamReader;
|
import java.io.InputStreamReader;
|
||||||
import java.io.UnsupportedEncodingException;
|
import java.io.UnsupportedEncodingException;
|
||||||
|
|
@ -27,39 +37,33 @@ import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Set;
|
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 <a href="http://www.beanshell.org/">BeanShell</a> sources.
|
* Extracts Mojo descriptors from <a href="http://www.beanshell.org/">BeanShell</a> sources.
|
||||||
*
|
*
|
||||||
|
* @version $Id$
|
||||||
* @todo share constants
|
* @todo share constants
|
||||||
* @todo add example usage tag that can be shown in the doco
|
* @todo add example usage tag that can be shown in the doco
|
||||||
* @todo need to add validation directives so that systems embedding maven2 can
|
* @todo need to add validation directives so that systems embedding maven2 can
|
||||||
* get validation directives to help users in IDEs.
|
* 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
|
public class BeanshellMojoDescriptorExtractor
|
||||||
extends AbstractScriptedMojoDescriptorExtractor
|
extends AbstractScriptedMojoDescriptorExtractor
|
||||||
implements MojoDescriptorExtractor
|
implements MojoDescriptorExtractor
|
||||||
{
|
{
|
||||||
/** {@inheritDoc} */
|
/**
|
||||||
|
* {@inheritDoc}
|
||||||
|
*/
|
||||||
protected String getScriptFileExtension( PluginToolsRequest request )
|
protected String getScriptFileExtension( PluginToolsRequest request )
|
||||||
{
|
{
|
||||||
return ".bsh";
|
return ".bsh";
|
||||||
}
|
}
|
||||||
|
|
||||||
/** {@inheritDoc} */
|
/**
|
||||||
protected List<MojoDescriptor> extractMojoDescriptors( Map<String, Set<File>> scriptFilesKeyedByBasedir, PluginToolsRequest request )
|
* {@inheritDoc}
|
||||||
|
*/
|
||||||
|
protected List<MojoDescriptor> extractMojoDescriptors( Map<String, Set<File>> scriptFilesKeyedByBasedir,
|
||||||
|
PluginToolsRequest request )
|
||||||
throws ExtractionException, InvalidPluginDescriptorException
|
throws ExtractionException, InvalidPluginDescriptorException
|
||||||
{
|
{
|
||||||
List<MojoDescriptor> descriptors = new ArrayList<MojoDescriptor>();
|
List<MojoDescriptor> descriptors = new ArrayList<MojoDescriptor>();
|
||||||
|
|
@ -95,7 +99,8 @@ public class BeanshellMojoDescriptorExtractor
|
||||||
* @param resource not null
|
* @param resource not null
|
||||||
* @param request not null
|
* @param request not null
|
||||||
* @return a new Mojo descriptor instance
|
* @return a new Mojo descriptor instance
|
||||||
* @throws InvalidPluginDescriptorException if any
|
* @throws InvalidPluginDescriptorException
|
||||||
|
* if any
|
||||||
*/
|
*/
|
||||||
private MojoDescriptor createMojoDescriptor( String basedir, String resource, PluginToolsRequest request )
|
private MojoDescriptor createMojoDescriptor( String basedir, String resource, PluginToolsRequest request )
|
||||||
throws InvalidPluginDescriptorException
|
throws InvalidPluginDescriptorException
|
||||||
|
|
@ -116,6 +121,8 @@ public class BeanshellMojoDescriptorExtractor
|
||||||
|
|
||||||
interpreter.set( "mojoDescriptor", mojoDescriptor );
|
interpreter.set( "mojoDescriptor", mojoDescriptor );
|
||||||
|
|
||||||
|
interpreter.set( "encoding", "UTF-8" );
|
||||||
|
|
||||||
interpreter.eval( new InputStreamReader( getClass().getResourceAsStream( "/extractor.bsh" ), "UTF-8" ) );
|
interpreter.eval( new InputStreamReader( getClass().getResourceAsStream( "/extractor.bsh" ), "UTF-8" ) );
|
||||||
}
|
}
|
||||||
catch ( EvalError evalError )
|
catch ( EvalError evalError )
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue