mirror of https://github.com/apache/maven.git
Switching to use AbstractScriptedMojoDescriptorExtractor and scriptSourceDirectory.
git-svn-id: https://svn.apache.org/repos/asf/maven/components/trunk@328904 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
008685017d
commit
e21bf422e1
|
@ -18,20 +18,20 @@ package org.apache.maven.tools.plugin.extractor.beanshell;
|
||||||
|
|
||||||
import bsh.EvalError;
|
import bsh.EvalError;
|
||||||
import bsh.Interpreter;
|
import bsh.Interpreter;
|
||||||
|
|
||||||
import org.apache.maven.plugin.descriptor.InvalidPluginDescriptorException;
|
import org.apache.maven.plugin.descriptor.InvalidPluginDescriptorException;
|
||||||
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.tools.plugin.extractor.AbstractScriptedMojoDescriptorExtractor;
|
||||||
import org.apache.maven.tools.plugin.extractor.MojoDescriptorExtractor;
|
import org.apache.maven.tools.plugin.extractor.ExtractionException;
|
||||||
import org.codehaus.plexus.logging.AbstractLogEnabled;
|
|
||||||
import org.codehaus.plexus.util.FileUtils;
|
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.IOException;
|
|
||||||
import java.io.InputStreamReader;
|
import java.io.InputStreamReader;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Iterator;
|
import java.util.Iterator;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.Set;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @todo share constants
|
* @todo share constants
|
||||||
|
@ -40,10 +40,9 @@ import java.util.List;
|
||||||
* get validation directives to help users in IDEs.
|
* get validation directives to help users in IDEs.
|
||||||
*/
|
*/
|
||||||
public class BeanshellMojoDescriptorExtractor
|
public class BeanshellMojoDescriptorExtractor
|
||||||
extends AbstractLogEnabled
|
extends AbstractScriptedMojoDescriptorExtractor
|
||||||
implements MojoDescriptorExtractor
|
|
||||||
{
|
{
|
||||||
private MojoDescriptor createMojoDescriptor( File basedir, String resource, PluginDescriptor pluginDescriptor )
|
private MojoDescriptor createMojoDescriptor( String basedir, String resource, PluginDescriptor pluginDescriptor )
|
||||||
throws InvalidPluginDescriptorException
|
throws InvalidPluginDescriptorException
|
||||||
{
|
{
|
||||||
MojoDescriptor mojoDescriptor = new MojoDescriptor();
|
MojoDescriptor mojoDescriptor = new MojoDescriptor();
|
||||||
|
@ -72,37 +71,43 @@ public class BeanshellMojoDescriptorExtractor
|
||||||
return mojoDescriptor;
|
return mojoDescriptor;
|
||||||
}
|
}
|
||||||
|
|
||||||
public List execute( MavenProject project, PluginDescriptor pluginDescriptor )
|
protected String getScriptFileExtension()
|
||||||
throws InvalidPluginDescriptorException
|
{
|
||||||
|
return ".bsh";
|
||||||
|
}
|
||||||
|
|
||||||
|
protected List extractMojoDescriptors( Map scriptFilesKeyedByBasedir, PluginDescriptor pluginDescriptor )
|
||||||
|
throws ExtractionException, InvalidPluginDescriptorException
|
||||||
{
|
{
|
||||||
List descriptors = new ArrayList();
|
List descriptors = new ArrayList();
|
||||||
|
|
||||||
for ( Iterator i = project.getScriptSourceRoots().iterator(); i.hasNext(); )
|
for ( Iterator mapIterator = scriptFilesKeyedByBasedir.entrySet().iterator(); mapIterator.hasNext(); )
|
||||||
{
|
{
|
||||||
try
|
Map.Entry entry = (Map.Entry) mapIterator.next();
|
||||||
{
|
|
||||||
File basedir = new File( (String) i.next() );
|
|
||||||
|
|
||||||
if ( basedir.exists() )
|
String basedir = (String) entry.getKey();
|
||||||
|
Set metadataFiles = (Set) entry.getValue();
|
||||||
|
|
||||||
|
for ( Iterator it = metadataFiles.iterator(); it.hasNext(); )
|
||||||
|
{
|
||||||
|
File scriptFile = (File) it.next();
|
||||||
|
|
||||||
|
String relativePath = null;
|
||||||
|
|
||||||
|
if ( basedir.endsWith( "/" ) )
|
||||||
{
|
{
|
||||||
List files = FileUtils.getFiles( basedir, "**/*.bsh", null, false );
|
basedir = basedir.substring( 0, basedir.length() - 2 );
|
||||||
|
|
||||||
for ( Iterator j = files.iterator(); j.hasNext(); )
|
|
||||||
{
|
|
||||||
File resource = (File) j.next();
|
|
||||||
String resourcePath = "/" + resource.getPath().replace( '\\', '/' );
|
|
||||||
MojoDescriptor mojoDescriptor = createMojoDescriptor( basedir, resourcePath, pluginDescriptor );
|
|
||||||
descriptors.add( mojoDescriptor );
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
|
||||||
catch ( IOException e )
|
relativePath = scriptFile.getPath().substring( basedir.length() );
|
||||||
{
|
|
||||||
throw new InvalidPluginDescriptorException( "Unable to locate files to process", e );
|
relativePath = relativePath.replace( '\\', '/' );
|
||||||
|
|
||||||
|
MojoDescriptor mojoDescriptor = createMojoDescriptor( basedir, relativePath, pluginDescriptor );
|
||||||
|
descriptors.add( mojoDescriptor );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return descriptors;
|
return descriptors;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
Loading…
Reference in New Issue