- Revision
- 693
- Author
- sirenian
- Date
- 2007-03-04 09:52:39 -0600 (Sun, 04 Mar 2007)
Log Message
[EK] Fixed StoryPrinter Added StoryPrinterBehaviour to AllStories Put main method back on StoryPrinter Created task to output stories to a directory.
Modified Paths
- trunk/build.xml
- trunk/core/src/behaviour/org/jbehave/core/story/AllBehaviours.java
- trunk/core/src/behaviour/org/jbehave/core/story/StoryPrinterBehaviour.java
- trunk/core/src/java/org/jbehave/core/story/StoryPrinter.java
- trunk/extensions/ant/src/behaviour/org/jbehave/ant/FailingStoryClass.java
- trunk/extensions/ant/src/java/org/jbehave/ant/AbstractRunnerTask.java
- trunk/plugins/maven/src/main/java/org/jbehave/mojo/BehavioursClassLoader.java
Added Paths
Diff
Modified: trunk/build.xml (692 => 693)
--- trunk/build.xml 2007-02-26 18:13:24 UTC (rev 692) +++ trunk/build.xml 2007-03-04 15:52:39 UTC (rev 693) @@ -42,6 +42,7 @@ <property name="example.behaviours" value="com.sirenian.hellbound.AllBehaviours" /> <property name="behaviour.runner.task" value="org.jbehave.ant.BehaviourRunnerTask"/> <property name="story.runner.task" value="org.jbehave.ant.StoryRunnerTask"/> + <property name="story.printer.task" value="org.jbehave.ant.StoryPrinterTask"/> <!-- general targets --> <target name="clean" description="Clean out output directory"> @@ -188,15 +189,15 @@ </target> <target name="run-example-behaviours" depends="compile-example-behaviours" description="Runs behaviours for examples"> - <taskdef name="jbehave" classname="${behaviour.runner.task}" classpath="${jbehave_jar}" /> - <jbehave><!-- behavioursClassName="${example.behaviours}"--> + <taskdef name="runbehaviours" classname="${behaviour.runner.task}" classpath="${jbehave_jar}" /> + <runbehaviours> <classpath> <path refid="libs" /> <pathelement path="${example_classes_dir}" /> <pathelement path="${example_behaviour_classes_dir}" /> </classpath> <behaviours dir="${examples_dir}/${example}/src/behaviour" includes="**/*Behaviour.java" /> - </jbehave> + </runbehaviours> </target> <target name="compile-example-stories" depends="build-jar" description="Compile behaviours for examples"> @@ -226,9 +227,9 @@ </javac> </target> - <target name="run-example-stories" depends="compile-example-behaviours, compile-example-stories" description="Runs behaviours for examples"> - <taskdef name="jbehavestory" classname="${story.runner.task}" classpath="${jbehave_jar}" /> - <jbehavestory> + <target name="run-example-stories" depends="compile-example-behaviours, compile-example-stories" description="Runs stories for examples"> + <taskdef name="runstories" classname="${story.runner.task}" classpath="${jbehave_jar}" /> + <runstories> <classpath> <path refid="libs" /> <pathelement path="${example_classes_dir}" /> @@ -236,8 +237,19 @@ <pathelement path="${example_story_classes_dir}" /> </classpath> <stories dir="${examples_dir}/${example}/src/stories" includes="**/stories/*" /> - </jbehavestory> + </runstories> </target> - + <target name="print-example-stories" depends="compile-example-behaviours, compile-example-stories" description="Prints stories for examples"> + <taskdef name="printstories" classname="${story.printer.task}" classpath="${jbehave_jar}" /> + <printstories destdir="${dist_dir}"> + <classpath> + <path refid="libs" /> + <pathelement path="${example_classes_dir}" /> + <pathelement path="${example_behaviour_classes_dir}" /> + <pathelement path="${example_story_classes_dir}" /> + </classpath> + <stories dir="${examples_dir}/${example}/src/stories" includes="**/stories/*" /> + </printstories> + </target> </project>
Modified: trunk/core/src/behaviour/org/jbehave/core/story/AllBehaviours.java (692 => 693)
--- trunk/core/src/behaviour/org/jbehave/core/story/AllBehaviours.java 2007-02-26 18:13:24 UTC (rev 692) +++ trunk/core/src/behaviour/org/jbehave/core/story/AllBehaviours.java 2007-03-04 15:52:39 UTC (rev 693) @@ -29,6 +29,8 @@ return new Class[] { StoryBuilderBehaviour.class, StoryRunnerBehaviour.class, + StoryPrinterBehaviour.class, + StoryToDirectoryPrinterBehaviour.class, TextStoryParserBehaviour.class, GivenStepBehaviour.class, GivenScenarioBehaviour.class,
Added: trunk/core/src/behaviour/org/jbehave/core/story/FileWhichExists ( => )
Modified: trunk/core/src/behaviour/org/jbehave/core/story/StoryPrinterBehaviour.java =================================================================== --- trunk/core/src/behaviour/org/jbehave/core/story/StoryPrinterBehaviour.java 2007-02-26 18:13:24 UTC (rev 692) +++ trunk/core/src/behaviour/org/jbehave/core/story/StoryPrinterBehaviour.java 2007-03-04 15:52:39 UTC (rev 693) @@ -16,7 +16,7 @@ StoryPrinter printer = new StoryPrinter( new StoryLoader(new TextStoryParser(), Thread.currentThread().getContextClassLoader()), - new PlainTextRenderer(System.out)); + new PlainTextRenderer(printStream)); printer.print(SimpleStory.class.getName()); String result = byteStream.toString();
Added: trunk/core/src/behaviour/org/jbehave/core/story/StoryToDirectoryPrinterBehaviour.java (0 => 693)
--- trunk/core/src/behaviour/org/jbehave/core/story/StoryToDirectoryPrinterBehaviour.java (rev 0) +++ trunk/core/src/behaviour/org/jbehave/core/story/StoryToDirectoryPrinterBehaviour.java 2007-03-04 15:52:39 UTC (rev 693) @@ -0,0 +1,37 @@ +package org.jbehave.core.story; + +import java.io.File; + +import org.jbehave.core.Block; +import org.jbehave.core.mock.UsingMatchers; + +public class StoryToDirectoryPrinterBehaviour extends UsingMatchers { + + public void shouldThrowIllegalArgumentExceptionIfDirectoryDoesNotExist() throws Exception { + Exception exception = runAndCatch(IllegalArgumentException.class, new Block() { + public void run() throws Exception { + new StoryToDirectoryPrinter(null, new File("FileWhichDoesNotExist")); + } + }); + + ensureThat(exception, isNotNull()); + } + + + public void shouldThrowIllegalArgumentExceptionIfFileIsNotDirectory() throws Exception { + Exception exception = runAndCatch(IllegalArgumentException.class, new Block() { + public void run() throws Exception { + new StoryToDirectoryPrinter(null, new File("FileWhichExists")); + } + }); + + ensureThat(exception, isNotNull()); + } + + public void shouldUseStoryPrinterToOutputStoriesByNameToDirectory() { + // No way of describing this behaviour yet without creating a number of files, + // which I don't want to do. If you change the StoryToDirectoryPrinter, + // please describe this behaviour or at least make sure that the + // print-example-stories task works. + } +}
Modified: trunk/core/src/java/org/jbehave/core/story/StoryPrinter.java (692 => 693)
--- trunk/core/src/java/org/jbehave/core/story/StoryPrinter.java 2007-02-26 18:13:24 UTC (rev 692) +++ trunk/core/src/java/org/jbehave/core/story/StoryPrinter.java 2007-03-04 15:52:39 UTC (rev 693) @@ -8,7 +8,9 @@ package org.jbehave.core.story; import java.net.MalformedURLException; +import org.jbehave.core.story.codegen.parser.TextStoryParser; import org.jbehave.core.story.domain.Story; +import org.jbehave.core.story.renderer.PlainTextRenderer; import org.jbehave.core.story.renderer.Renderer; /** @@ -34,7 +36,20 @@ public void print(String storyClassName) throws InstantiationException, IllegalAccessException, ClassNotFoundException{ Story story = storyLoader.loadStory(storyClassName); + story.specify(); story.narrateTo(renderer); } + public static void main(String[] args) { + try { + StoryPrinter printer = new StoryPrinter( + new StoryLoader(new TextStoryParser(), StoryPrinter.class.getClassLoader()), + new PlainTextRenderer(System.out)); + for (int i = 0; i < args.length; i++) { + printer.print(args[i]); + } + } catch (Exception e) { + e.printStackTrace(); + } + } }
Added: trunk/core/src/java/org/jbehave/core/story/StoryToDirectoryPrinter.java (0 => 693)
--- trunk/core/src/java/org/jbehave/core/story/StoryToDirectoryPrinter.java (rev 0) +++ trunk/core/src/java/org/jbehave/core/story/StoryToDirectoryPrinter.java 2007-03-04 15:52:39 UTC (rev 693) @@ -0,0 +1,61 @@ +package org.jbehave.core.story; + +import java.io.File; +import java.io.FileOutputStream; +import java.io.IOException; +import java.io.OutputStream; +import java.io.PrintStream; + +import org.jbehave.core.story.codegen.parser.TextStoryParser; +import org.jbehave.core.story.domain.Story; +import org.jbehave.core.story.renderer.PlainTextRenderer; + +public class StoryToDirectoryPrinter { + + private final StoryLoader loader; + private final File directory; + + public StoryToDirectoryPrinter(StoryLoader loader, File directory) { + if (!directory.exists()) { + throw new IllegalArgumentException("Directory " + directory + " does not exist."); + } + if (!directory.isDirectory()) { + throw new IllegalArgumentException("Directory " + directory + " is not a directory."); + } + + this.loader = loader; + this.directory = directory; + } + + + private void print(String storyClass) throws InstantiationException, IllegalAccessException, ClassNotFoundException, IOException { + Story story = loader.loadStory(storyClass); + String[] storyNameParts = story.getClass().getName().split("\\."); + String simpleStoryName = storyNameParts[storyNameParts.length - 1]; + + File file = new File(directory, simpleStoryName + ".story"); + if (!file.exists()) { + file.createNewFile(); + } + OutputStream outputStream = new FileOutputStream(file); + new StoryPrinter(loader, new PlainTextRenderer(new PrintStream(outputStream))).print(storyClass); + + outputStream.close(); + } + + public static void main(String[] args) { + File directory = new File(args[0]); + + try { + StoryToDirectoryPrinter printer = new StoryToDirectoryPrinter( + new StoryLoader(new TextStoryParser(), StoryPrinter.class.getClassLoader()), + directory); + + for (int i = 1; i < args.length; i++) { + printer.print(args[i]); + } + } catch (Exception e) { + e.printStackTrace(); + } + } +}
Modified: trunk/extensions/ant/src/behaviour/org/jbehave/ant/FailingStoryClass.java (692 => 693)
--- trunk/extensions/ant/src/behaviour/org/jbehave/ant/FailingStoryClass.java 2007-02-26 18:13:24 UTC (rev 692) +++ trunk/extensions/ant/src/behaviour/org/jbehave/ant/FailingStoryClass.java 2007-03-04 15:52:39 UTC (rev 693) @@ -1,6 +1,5 @@ package org.jbehave.ant; -import org.jbehave.core.exception.PendingException; import org.jbehave.core.exception.VerificationException; import org.jbehave.core.story.domain.Narrative; import org.jbehave.core.story.domain.ScenarioDrivenStory;
Modified: trunk/extensions/ant/src/java/org/jbehave/ant/AbstractRunnerTask.java (692 => 693)
--- trunk/extensions/ant/src/java/org/jbehave/ant/AbstractRunnerTask.java 2007-02-26 18:13:24 UTC (rev 692) +++ trunk/extensions/ant/src/java/org/jbehave/ant/AbstractRunnerTask.java 2007-03-04 15:52:39 UTC (rev 693) @@ -18,7 +18,7 @@ private final Class runnerClass; private final FilesetParser filesetParser; - private List targetClassList = new LinkedList(); + private List targetArgumentList = new LinkedList(); private List filesets = new ArrayList(); public AbstractRunnerTask(Class runnerClass, CommandRunner runner, FilesetParser filesetParser) { @@ -28,9 +28,14 @@ } public void addTarget(String targetClass) { - targetClassList.add(targetClass); + targetArgumentList.add(targetClass); } + + + public void addTarget(int index, String dir) { + targetArgumentList.add(index, dir); + } public void execute() { appendAntTaskJar(); @@ -56,7 +61,7 @@ commandLine.setClassname(runnerClass.getName()); - for (Iterator iterator = targetClassList.iterator(); iterator.hasNext();) { + for (Iterator iterator = targetArgumentList.iterator(); iterator.hasNext();) { String className = iterator.next().toString(); commandLine.createArgument().setLine(className); }
Added: trunk/extensions/ant/src/java/org/jbehave/ant/StoryPrinterTask.java (0 => 693)
--- trunk/extensions/ant/src/java/org/jbehave/ant/StoryPrinterTask.java (rev 0) +++ trunk/extensions/ant/src/java/org/jbehave/ant/StoryPrinterTask.java 2007-03-04 15:52:39 UTC (rev 693) @@ -0,0 +1,24 @@ +package org.jbehave.ant; + +import org.apache.tools.ant.types.FileSet; +import org.jbehave.core.story.StoryToDirectoryPrinter; + +public class StoryPrinterTask extends AbstractRunnerTask { + + public StoryPrinterTask() { + super(StoryToDirectoryPrinter.class, new CommandRunnerImpl(), new TrimFilesetParser()); + } + + public void setDestDir(String dir) { + super.addTarget(0, dir); + } + + public void setStoryClassName(String storyClassName) { + super.addTarget(storyClassName); + } + + + public void addStories(FileSet fileset) { + super.addFilesetTarget(fileset); + } +}
Modified: trunk/plugins/maven/src/main/java/org/jbehave/mojo/BehavioursClassLoader.java (692 => 693)
--- trunk/plugins/maven/src/main/java/org/jbehave/mojo/BehavioursClassLoader.java 2007-02-26 18:13:24 UTC (rev 692) +++ trunk/plugins/maven/src/main/java/org/jbehave/mojo/BehavioursClassLoader.java 2007-03-04 15:52:39 UTC (rev 693) @@ -5,7 +5,6 @@ import java.net.URL; import java.net.URLClassLoader; import java.util.ArrayList; -import java.util.Arrays; import java.util.Iterator; import java.util.List; @@ -39,7 +38,7 @@ public Behaviours newBehaviours(String behavioursName) throws InstantiationException, IllegalAccessException { String behavioursNotFound = "The behaviours " + behavioursName - + " was not found in " + Arrays.toString(getURLs()); + + " was not found in " + toString(getURLs()); try { Behaviours behavious = (Behaviours) loadClass(behavioursName).newInstance(); Thread.currentThread().setContextClassLoader(this); @@ -54,6 +53,17 @@ } } + private String toString(URL[] urls) { + StringBuffer buffer = new StringBuffer(); + for (int i = 0; i < urls.length; i++) { + buffer.append(urls[i].toString()); + if (i < urls.length - 1) { + buffer.append(", "); + } + } + return buffer.toString(); + } + protected static URL[] toClasspathURLs(List classpathElements) throws MalformedURLException { List urls = new ArrayList();
To unsubscribe from this list please visit:
