You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@maven.apache.org by jd...@apache.org on 2005/10/27 17:54:00 UTC
svn commit: r328904 -
/maven/components/trunk/maven-plugin-tools/maven-plugin-tools-beanshell/src/main/java/org/apache/maven/tools/plugin/extractor/beanshell/BeanshellMojoDescriptorExtractor.java
Author: jdcasey
Date: Thu Oct 27 08:53:56 2005
New Revision: 328904
URL: http://svn.apache.org/viewcvs?rev=328904&view=rev
Log:
Switching to use AbstractScriptedMojoDescriptorExtractor and scriptSourceDirectory.
Modified:
maven/components/trunk/maven-plugin-tools/maven-plugin-tools-beanshell/src/main/java/org/apache/maven/tools/plugin/extractor/beanshell/BeanshellMojoDescriptorExtractor.java
Modified: maven/components/trunk/maven-plugin-tools/maven-plugin-tools-beanshell/src/main/java/org/apache/maven/tools/plugin/extractor/beanshell/BeanshellMojoDescriptorExtractor.java
URL: http://svn.apache.org/viewcvs/maven/components/trunk/maven-plugin-tools/maven-plugin-tools-beanshell/src/main/java/org/apache/maven/tools/plugin/extractor/beanshell/BeanshellMojoDescriptorExtractor.java?rev=328904&r1=328903&r2=328904&view=diff
==============================================================================
--- maven/components/trunk/maven-plugin-tools/maven-plugin-tools-beanshell/src/main/java/org/apache/maven/tools/plugin/extractor/beanshell/BeanshellMojoDescriptorExtractor.java (original)
+++ maven/components/trunk/maven-plugin-tools/maven-plugin-tools-beanshell/src/main/java/org/apache/maven/tools/plugin/extractor/beanshell/BeanshellMojoDescriptorExtractor.java Thu Oct 27 08:53:56 2005
@@ -18,20 +18,20 @@
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.project.MavenProject;
-import org.apache.maven.tools.plugin.extractor.MojoDescriptorExtractor;
-import org.codehaus.plexus.logging.AbstractLogEnabled;
-import org.codehaus.plexus.util.FileUtils;
+import org.apache.maven.tools.plugin.extractor.AbstractScriptedMojoDescriptorExtractor;
+import org.apache.maven.tools.plugin.extractor.ExtractionException;
import java.io.File;
-import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
+import java.util.Map;
+import java.util.Set;
/**
* @todo share constants
@@ -40,10 +40,9 @@
* get validation directives to help users in IDEs.
*/
public class BeanshellMojoDescriptorExtractor
- extends AbstractLogEnabled
- implements MojoDescriptorExtractor
+ extends AbstractScriptedMojoDescriptorExtractor
{
- private MojoDescriptor createMojoDescriptor( File basedir, String resource, PluginDescriptor pluginDescriptor )
+ private MojoDescriptor createMojoDescriptor( String basedir, String resource, PluginDescriptor pluginDescriptor )
throws InvalidPluginDescriptorException
{
MojoDescriptor mojoDescriptor = new MojoDescriptor();
@@ -72,37 +71,43 @@
return mojoDescriptor;
}
- public List execute( MavenProject project, PluginDescriptor pluginDescriptor )
- throws InvalidPluginDescriptorException
+ protected String getScriptFileExtension()
+ {
+ return ".bsh";
+ }
+
+ protected List extractMojoDescriptors( Map scriptFilesKeyedByBasedir, PluginDescriptor pluginDescriptor )
+ throws ExtractionException, InvalidPluginDescriptorException
{
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();
+
+ String basedir = (String) entry.getKey();
+ Set metadataFiles = (Set) entry.getValue();
+
+ for ( Iterator it = metadataFiles.iterator(); it.hasNext(); )
{
- File basedir = new File( (String) i.next() );
+ File scriptFile = (File) it.next();
- if ( basedir.exists() )
- {
- List files = FileUtils.getFiles( basedir, "**/*.bsh", null, false );
+ String relativePath = null;
- 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 );
- }
+ if ( basedir.endsWith( "/" ) )
+ {
+ basedir = basedir.substring( 0, basedir.length() - 2 );
}
- }
- catch ( IOException e )
- {
- throw new InvalidPluginDescriptorException( "Unable to locate files to process", e );
+
+ relativePath = scriptFile.getPath().substring( basedir.length() );
+
+ relativePath = relativePath.replace( '\\', '/' );
+
+ MojoDescriptor mojoDescriptor = createMojoDescriptor( basedir, relativePath, pluginDescriptor );
+ descriptors.add( mojoDescriptor );
}
}
return descriptors;
}
-
}