- Revision
- 750
- Author
- mauro
- Date
- 2007-07-11 07:57:51 -0500 (Wed, 11 Jul 2007)
Log Message
JBEHAVE-91: Refactored story mojos to print and run a list of stories. The configuration still supports the specification of a single story and configuration of multiple stories will be optional - and still to be added.
Modified Paths
Diff
Modified: trunk/plugins/maven/src/main/java/org/jbehave/mojo/AbstractStoryMojo.java (749 => 750)
--- trunk/plugins/maven/src/main/java/org/jbehave/mojo/AbstractStoryMojo.java 2007-07-11 12:44:27 UTC (rev 749) +++ trunk/plugins/maven/src/main/java/org/jbehave/mojo/AbstractStoryMojo.java 2007-07-11 12:57:51 UTC (rev 750) @@ -1,6 +1,8 @@ package org.jbehave.mojo; import java.net.MalformedURLException; +import java.util.ArrayList; +import java.util.List; import org.jbehave.core.story.StoryLoader; import org.jbehave.core.story.codegen.parser.StoryParser; @@ -17,13 +19,13 @@ * @parameter * @required true */ - protected String storyPath; + private String storyPath; /** * @parameter * @required true */ - protected String storyPackage; + private String storyPackage; /** * @parameter default-value="org.jbehave.core.story.codegen.parser.TextStoryParser" @@ -60,10 +62,25 @@ return new StoryLoader(getStoryParser(), createBehavioursClassLoader()); } + protected String getStoryPackage() { + return storyPackage; + } + + protected List getStoryPaths() { + List storyPaths = new ArrayList(); + // a single story path is specified + if ( storyPath != null ){ + storyPaths.add(storyPath); + return storyPaths; + } + return storyPaths; + } + public static class InvalidClassNameException extends RuntimeException { public InvalidClassNameException(String message, Throwable cause) { super(message, cause); } } + }
Modified: trunk/plugins/maven/src/main/java/org/jbehave/mojo/StoryPrinterMojo.java (749 => 750)
--- trunk/plugins/maven/src/main/java/org/jbehave/mojo/StoryPrinterMojo.java 2007-07-11 12:44:27 UTC (rev 749) +++ trunk/plugins/maven/src/main/java/org/jbehave/mojo/StoryPrinterMojo.java 2007-07-11 12:57:51 UTC (rev 750) @@ -1,11 +1,15 @@ package org.jbehave.mojo; +import java.net.MalformedURLException; +import java.util.Iterator; +import java.util.List; + import org.apache.maven.plugin.MojoExecutionException; import org.apache.maven.plugin.MojoFailureException; import org.jbehave.core.story.StoryPrinter; /** - * Mojo to print a story + * Mojo to print stories * * @author Mauro Talevi * @goal print-story @@ -13,13 +17,22 @@ public class StoryPrinterMojo extends AbstractStoryMojo { public void execute() throws MojoExecutionException, MojoFailureException { + String storyPackage = getStoryPackage(); + List storyPaths = getStoryPaths(); try { - getLog().debug("Printing story "+ storyPath); - StoryPrinter storyPrinter = new StoryPrinter(getStoryLoader(), getStoryRenderer()); - storyPrinter.print(storyPath, storyPackage); + for ( Iterator i = storyPaths.iterator(); i.hasNext(); ){ + String storyPath = (String)i.next(); + printStory(storyPackage, storyPath); + } } catch (Exception e) { - throw new MojoExecutionException("Failed to print story "+storyPath+" with package "+storyPackage, e); + throw new MojoExecutionException("Failed to print stories "+storyPaths+" with package "+storyPackage, e); } } + + private void printStory(String storyPackage, String storyPath) throws MalformedURLException { + getLog().debug("Printing story "+ storyPath+" using package "+storyPackage); + StoryPrinter storyPrinter = new StoryPrinter(getStoryLoader(), getStoryRenderer()); + storyPrinter.print(storyPath, storyPackage); + } }
Modified: trunk/plugins/maven/src/main/java/org/jbehave/mojo/StoryRunnerMojo.java (749 => 750)
--- trunk/plugins/maven/src/main/java/org/jbehave/mojo/StoryRunnerMojo.java 2007-07-11 12:44:27 UTC (rev 749) +++ trunk/plugins/maven/src/main/java/org/jbehave/mojo/StoryRunnerMojo.java 2007-07-11 12:57:51 UTC (rev 750) @@ -1,6 +1,10 @@ package org.jbehave.mojo; +import java.net.MalformedURLException; +import java.util.Iterator; +import java.util.List; + import org.apache.maven.plugin.MojoExecutionException; import org.apache.maven.plugin.MojoFailureException; import org.jbehave.core.story.StoryLoader; @@ -8,7 +12,7 @@ import org.jbehave.core.story.domain.Story; /** - * Mojo to run a story + * Mojo to run stories * * @author Mauro Talevi * @goal run-story @@ -19,16 +23,24 @@ private StoryRunner storyRunner = new StoryRunner(); public void execute() throws MojoExecutionException, MojoFailureException { + String storyPackage = getStoryPackage(); + List storyPaths = getStoryPaths(); try { - getLog().debug("Running story "+ storyPath); - StoryLoader loader = getStoryLoader(); - Story story = loader.loadStory(storyPath, storyPackage); - story.specify(); - storyRunner.run(story); + for ( Iterator i = storyPaths.iterator(); i.hasNext(); ){ + String storyPath = (String)i.next(); + runStory(storyPackage, storyPath); + } } catch (Exception e) { - throw new MojoExecutionException("Failed to run story "+storyPath+" with package "+storyPackage, e); + throw new MojoExecutionException("Failed to run stories "+storyPaths+" with package "+storyPackage, e); } } - + private void runStory(String storyPackage, String storyPath) throws MalformedURLException { + getLog().debug("Running story "+ storyPath+" using package "+storyPackage); + StoryLoader loader = getStoryLoader(); + Story story = loader.loadStory(storyPath, storyPackage); + story.specify(); + storyRunner.run(story); + } + }
To unsubscribe from this list please visit: