Title: [766] trunk/core/src/java/org/jbehave/core/util: Moved path finder functionality to util class in core - so it can be re-used by other components.
Revision
766
Author
mauro
Date
2007-07-15 10:22:15 -0500 (Sun, 15 Jul 2007)

Log Message

Moved path finder functionality to util class in core - so it can be re-used by other components.

Modified Paths

Added Paths

Diff

Added: trunk/core/src/java/org/jbehave/core/util/PathFinder.java (0 => 766)

--- trunk/core/src/java/org/jbehave/core/util/PathFinder.java	                        (rev 0)
+++ trunk/core/src/java/org/jbehave/core/util/PathFinder.java	2007-07-15 15:22:15 UTC (rev 766)
@@ -0,0 +1,54 @@
+package org.jbehave.core.util;
+
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Iterator;
+import java.util.List;
+
+import org.apache.tools.ant.DirectoryScanner;
+
+/**
+ * A utility path finder
+ * 
+ * @author Mauro Talevi
+ */
+public class PathFinder {
+
+    /**
+     * Scanner used to list relative paths
+     */
+    private DirectoryScanner scanner = new DirectoryScanner();
+
+    /**
+     * Lists paths from a basedir, allowing for includes/excludes
+     * 
+     * @param basedir the basedir path
+     * @param rootPath the root path prefixed to all paths found, or
+     *            <code>null</code> if none
+     * @param includes the List of include patterns, or <code>null</code> if
+     *            none
+     * @param excludes the List of exclude patterns, or <code>null</code> if
+     *            none
+     * @return A List of paths
+     */
+    public List listPaths(String basedir, String rootPath, List includes, List excludes) {
+        scanner.setBasedir(basedir);
+        if (includes != null) {
+            scanner.setIncludes((String[]) includes.toArray(new String[includes.size()]));
+        }
+        if (excludes != null) {
+            scanner.setExcludes((String[]) excludes.toArray(new String[excludes.size()]));
+        }
+        scanner.scan();
+        List paths = new ArrayList();
+        String basePath = (rootPath != null ? rootPath + "/" : "");
+        List relativePaths = Arrays.asList(scanner.getIncludedFiles());
+        for (Iterator i = relativePaths.iterator(); i.hasNext();) {
+            String relativePath = (String) i.next();
+            String path = basePath + relativePath;
+            paths.add(path);
+        }
+        return paths;
+    }
+
+}

Modified: trunk/plugins/maven/src/main/java/org/jbehave/mojo/AbstractStoryMojo.java (765 => 766)

--- trunk/plugins/maven/src/main/java/org/jbehave/mojo/AbstractStoryMojo.java	2007-07-15 14:56:57 UTC (rev 765)
+++ trunk/plugins/maven/src/main/java/org/jbehave/mojo/AbstractStoryMojo.java	2007-07-15 15:22:15 UTC (rev 766)
@@ -3,60 +3,62 @@
 import java.io.File;
 import java.net.MalformedURLException;
 import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.Iterator;
 import java.util.List;
 
-import org.apache.tools.ant.DirectoryScanner;
 import org.jbehave.core.story.StoryLoader;
 import org.jbehave.core.story.codegen.parser.StoryParser;
 import org.jbehave.core.story.renderer.Renderer;
+import org.jbehave.core.util.PathFinder;
 
 /**
- * Abstract mojo for story-related goals 
+ * Abstract mojo for story-related goals
  * 
  * @author Mauro Talevi
  */
 public abstract class AbstractStoryMojo extends AbstractJBehaveMojo {
-      
+
     /**
      * @parameter _expression_="${project.build.sourceDirectory}"
      * @required
      * @readonly
-     */        
+     */
     private String sourceDirectory;
-    
+
     /**
      * @parameter _expression_="${project.build.testSourceDirectory}"
      * @required
      * @readonly
-     */        
+     */
     private String testSourceDirectory;
-    
+
     /**
      * Path specifying a single story
+     * 
      * @parameter
      */
     private String storyPath;
 
     /**
      * Directory containing multiple stories, relative to the sourceDirectory
+     * 
      * @parameter
      */
     private String storyDirectory;
-    
+
     /**
-     * Story include filters, relative to the storyDirectory 
+     * Story include filters, relative to the storyDirectory
+     * 
      * @parameter
      */
     private List storyIncludes;
 
     /**
-     * Story exclude filters, relative to the storyDirectory 
+     * Story exclude filters, relative to the storyDirectory
+     * 
      * @parameter
      */
     private List storyExcludes;
-    
+
     /**
      * @parameter
      * @required true
@@ -64,19 +66,19 @@
     private String storyPackage;
 
     /**
-     * @parameter default-value="org.jbehave.core.story.codegen.parser.TextStoryParser" 
+     * @parameter default-value="org.jbehave.core.story.codegen.parser.TextStoryParser"
      */
     private String storyParserClassName;
-        
+
     /**
-     * @parameter default-value="org.jbehave.core.story.renderer.ConsolePlainTextRenderer" 
+     * @parameter default-value="org.jbehave.core.story.renderer.ConsolePlainTextRenderer"
      */
     private String storyRendererClassName;
-   
+
     /**
-     * Directory scanner used to list story paths
+     * PathFinder used to list story paths
      */
-    private DirectoryScanner scanner = new DirectoryScanner();
+    private PathFinder pathFinder = new PathFinder();
 
     private Object createInstance(String className) {
         try {
@@ -86,16 +88,16 @@
             throw new InvalidClassNameException(className, e);
         }
     }
-        
+
     protected StoryParser getStoryParser() {
-        StoryParser storyParser = (StoryParser) createInstance(storyParserClassName);       
-        getLog().debug("Using story parser "+storyParser.getClass().getName());
+        StoryParser storyParser = (StoryParser) createInstance(storyParserClassName);
+        getLog().debug("Using story parser " + storyParser.getClass().getName());
         return storyParser;
     }
 
     protected Renderer getStoryRenderer() {
-        Renderer storyRenderer = (Renderer) createInstance(storyRendererClassName);       
-        getLog().debug("Using story renderer "+storyRenderer.getClass().getName());
+        Renderer storyRenderer = (Renderer) createInstance(storyRendererClassName);
+        getLog().debug("Using story renderer " + storyRenderer.getClass().getName());
         return storyRenderer;
     }
 
@@ -109,55 +111,36 @@
 
     protected List getStoryPaths() {
         // a single story path is specified
-        if ( storyPath != null ){
+        if (storyPath != null) {
             List storyPaths = new ArrayList();
             storyPaths.add(storyPath);
             return storyPaths;
-        }        
+        }
         return listStoryPaths();
     }
-    
-    private List listStoryPaths() {        
-        scanner.setBasedir( getStorySourceDirectory() );
-        getLog().debug( "Listing story paths from directory " + storyDirectory );
-        if ( storyIncludes != null )
-        {
-            getLog().debug( "Setting includes " + storyIncludes );
-            scanner.setIncludes( (String[])storyIncludes.toArray(new String[storyIncludes.size()]) );
-        }
-        if ( storyExcludes != null )
-        {
-            getLog().debug( "Setting excludes " + storyExcludes );
-            scanner.setExcludes( (String[])storyExcludes.toArray(new String[storyExcludes.size()]) );
-        }
-        scanner.scan();
-        List relativePaths = Arrays.asList(scanner.getIncludedFiles());
-        List storyPaths = new ArrayList();
-        for ( Iterator i = relativePaths.iterator(); i.hasNext(); ){
-            String relativePath = (String)i.next();
-            String storyPath = storyDirectory+"/"+relativePath;
-            storyPaths.add(storyPath);
-        }
-        getLog().debug("Listed story paths "+storyPaths);
+
+    private List listStoryPaths() {
+        List storyPaths = pathFinder.listPaths(getStorySourceDirectory().getPath(), storyDirectory, storyIncludes,
+                storyExcludes);
+        getLog().debug("Listed story paths " + storyPaths);
         return storyPaths;
     }
 
     private String getRootSourceDirectory() {
-        if ( isTestScope() ){
+        if (isTestScope()) {
             return testSourceDirectory;
-        } 
+        }
         return sourceDirectory;
     }
-    
+
     protected File getStorySourceDirectory() {
-       return new File( getRootSourceDirectory(), storyDirectory );
+        return new File(getRootSourceDirectory(), storyDirectory);
     }
 
     public static class InvalidClassNameException extends RuntimeException {
         public InvalidClassNameException(String message, Throwable cause) {
             super(message, cause);
-        }        
+        }
     }
 
-
 }


To unsubscribe from this list please visit:

http://xircles.codehaus.org/manage_email

Reply via email to