Title: [1098] trunk/core/examples/trader: JBEHAVE-158: Added StepDocReporter and Ant/Maven integration.

Diff

Modified: trunk/core/examples/trader/build.xml (1097 => 1098)

--- trunk/core/examples/trader/build.xml	2009-02-22 12:40:48 UTC (rev 1097)
+++ trunk/core/examples/trader/build.xml	2009-02-22 13:21:51 UTC (rev 1098)
@@ -3,7 +3,7 @@
     Note: Use of <artifact:dependencies/> requires
     ../../lib/build/maven-ant-tasks-2.0.9.jar in $ANT_HOME/lib
   -->
-<project name="trader" default="run"
+<project name="trader" default="run-scenario"
   xmlns:artifact="antlib:org.apache.maven.artifact.ant">
 
   <artifact:dependencies pathId="dependency.classpath">
@@ -35,7 +35,7 @@
     </javac>
   </target>
 
-  <target name="run" depends="compile">
+  <target name="run-scenario" depends="compile">
     <property name="dependency.classpath" refid="dependency.classpath" />
     <path id="scenario.classpath">
       <pathelement location="target/classes" />
@@ -47,4 +47,16 @@
       scenarioExcludes="**/*Steps.java" skip="false" />
   </target>
 
+  <target name="stepdoc" depends="compile">
+    <property name="dependency.classpath" refid="dependency.classpath" />
+    <path id="scenario.classpath">
+      <pathelement location="target/classes" />
+      <pathelement path="${dependency.classpath}" />
+    </path>
+    <taskdef name="stepdoc" classname="org.jbehave.ant.StepdocTask"
+      classpathref="scenario.classpath" />
+    <stepdoc scenarioIncludes="org/jbehave/examples/trader/scenarios/*.java"
+      scenarioExcludes="**/*Steps.java" skip="false" />
+  </target>
+
 </project> 
\ No newline at end of file

Modified: trunk/core/examples/trader/pom.xml (1097 => 1098)

--- trunk/core/examples/trader/pom.xml	2009-02-22 12:40:48 UTC (rev 1097)
+++ trunk/core/examples/trader/pom.xml	2009-02-22 13:21:51 UTC (rev 1098)
@@ -36,12 +36,28 @@
               <scenarioExcludes>
                 <scenarioExclude>**/*Steps.java</scenarioExclude>
               </scenarioExcludes>
-              <skip>true</skip>
+              <skip>false</skip>
             </configuration>
             <goals>
               <goal>run-scenarios</goal>
             </goals>
           </execution>
+          <execution>
+            <id>stepdoc</id>
+            <phase>integration-test</phase>
+            <configuration>
+              <scenarioIncludes>
+                <scenarioInclude>org/jbehave/examples/trader/scenarios/*.java</scenarioInclude>
+              </scenarioIncludes>
+              <scenarioExcludes>
+                <scenarioExclude>**/*Steps.java</scenarioExclude>
+              </scenarioExcludes>
+              <skip>false</skip>
+            </configuration>
+            <goals>
+              <goal>stepdoc</goal>
+            </goals>
+          </execution>
         </executions>
       </plugin>
       <plugin>
@@ -55,17 +71,29 @@
               <tasks>
                 <taskdef name="scenarioRunner" classname="org.jbehave.ant.ScenarioRunnerTask" classpathref="maven.runtime.classpath" />
                 <scenarioRunner scenarioIncludes="org/jbehave/examples/trader/scenarios/*.java"
-                  scenarioExcludes="**/*Steps.java" skip="false" />
+                  scenarioExcludes="**/*Steps.java" skip="true" />
               </tasks>
             </configuration>
             <goals>
               <goal>run</goal>
             </goals>
           </execution>
+          <execution>
+            <id>stepdoc-via-ant</id>
+            <phase>integration-test</phase>
+            <configuration>
+              <tasks>
+                <taskdef name="stepdoc" classname="org.jbehave.ant.StepdocTask" classpathref="maven.runtime.classpath" />
+                <stepdoc scenarioIncludes="org/jbehave/examples/trader/scenarios/*.java"
+                  scenarioExcludes="**/*Steps.java" skip="true" />
+              </tasks>
+            </configuration>
+            <goals>
+              <goal>run</goal>
+            </goals>
+          </execution>
         </executions>
       </plugin>
-
-
     </plugins>
   </build>
 </project>
\ No newline at end of file

Modified: trunk/core/jbehave-ant/src/main/java/org/jbehave/ant/ScenarioRunnerTask.java (1097 => 1098)

--- trunk/core/jbehave-ant/src/main/java/org/jbehave/ant/ScenarioRunnerTask.java	2009-02-22 12:40:48 UTC (rev 1097)
+++ trunk/core/jbehave-ant/src/main/java/org/jbehave/ant/ScenarioRunnerTask.java	2009-02-22 13:21:51 UTC (rev 1098)
@@ -12,43 +12,44 @@
  * @author Mauro Talevi
  */
 public class ScenarioRunnerTask extends AbstractScenarioTask {
-    /**
-     * The boolean flag to skip running scenario
-     */
-    private boolean skip = false;
+	/**
+	 * The boolean flag to skip running scenario
+	 */
+	private boolean skip = false;
 
-    /**
-     * The boolean flag to ignoreFailure
-     */
-    private boolean ignoreFailure = false;
+	/**
+	 * The boolean flag to ignoreFailure
+	 */
+	private boolean ignoreFailure = false;
 
-    public void execute() throws BuildException {
-        if (skip) {
-            log("Skipped running scenarios", MSG_INFO);
-            return;
-        }
-        for (RunnableScenario scenario : scenarios()) {
-            try {
-                log("Running scenario " + scenario.getClass().getName());
-                scenario.runScenario();
-            } catch (Throwable e) {
-                String message = "Failed to run scenario " + scenario.getClass().getName();
-                if (ignoreFailure) {
-                    log(message, e, MSG_WARN);
-                } else {
-                    throw new BuildException(message, e);
-                }
-            }
-        }
-    }
+	public void execute() throws BuildException {
+		if (skip) {
+			log("Skipped running scenarios", MSG_INFO);
+			return;
+		}
+		for (RunnableScenario scenario : scenarios()) {
+			String scenarioName = scenario.getClass().getName();
+			try {
+				log("Running scenario " + scenarioName);
+				scenario.runScenario();
+			} catch (Throwable e) {
+				String message = "Failed to run scenario " + scenarioName;
+				if (ignoreFailure) {
+					log(message, e, MSG_WARN);
+				} else {
+					throw new BuildException(message, e);
+				}
+			}
+		}
+	}
 
-    // Setters
-    public void setSkip(boolean skip) {
-        this.skip = skip;
-    }
+	// Setters
+	public void setSkip(boolean skip) {
+		this.skip = skip;
+	}
 
-    public void setIgnoreFailure(boolean ignoreFailure) {
-        this.ignoreFailure = ignoreFailure;
-    }
+	public void setIgnoreFailure(boolean ignoreFailure) {
+		this.ignoreFailure = ignoreFailure;
+	}
 
 }

Added: trunk/core/jbehave-ant/src/main/java/org/jbehave/ant/StepdocTask.java (0 => 1098)

--- trunk/core/jbehave-ant/src/main/java/org/jbehave/ant/StepdocTask.java	                        (rev 0)
+++ trunk/core/jbehave-ant/src/main/java/org/jbehave/ant/StepdocTask.java	2009-02-22 13:21:51 UTC (rev 1098)
@@ -0,0 +1,69 @@
+package org.jbehave.ant;
+
+import static org.apache.tools.ant.Project.MSG_INFO;
+import static org.apache.tools.ant.Project.MSG_WARN;
+
+import java.util.List;
+
+import org.apache.tools.ant.BuildException;
+import org.jbehave.scenario.RunnableScenario;
+import org.jbehave.scenario.reporters.PrintStreamStepDocReporter;
+import org.jbehave.scenario.reporters.StepDocReporter;
+import org.jbehave.scenario.steps.CandidateSteps;
+import org.jbehave.scenario.steps.DefaultStepDocGenerator;
+import org.jbehave.scenario.steps.StepDoc;
+import org.jbehave.scenario.steps.StepDocGenerator;
+
+/**
+ * Ant task that generate stepdocs
+ * 
+ * @author Mauro Talevi
+ */
+public class StepdocTask extends AbstractScenarioTask {
+	/**
+	 * The boolean flag to skip running scenario
+	 */
+	private boolean skip = false;
+
+	/**
+	 * The boolean flag to ignoreFailure
+	 */
+	private boolean ignoreFailure = false;
+
+	private StepDocGenerator generator = new DefaultStepDocGenerator();
+	private StepDocReporter reporter = new PrintStreamStepDocReporter();
+	
+	public void execute() throws BuildException {
+		if (skip) {
+			log("Skipped running scenarios", MSG_INFO);
+			return;
+		}
+		for (RunnableScenario scenario : scenarios()) {
+			String scenarioName = scenario.getClass().getName();
+			try {
+				log("Generating stepdoc for " + scenarioName);
+				for (CandidateSteps steps : scenario.getSteps()) {
+					List<StepDoc> stepdocs = generator.generate(steps.getClass());
+					reporter.report(stepdocs);
+				}
+			} catch (Throwable e) {
+				String message = "Failed to generate stepdoc for " + scenarioName;
+				if (ignoreFailure) {
+					log(message, e, MSG_WARN);
+				} else {
+					throw new BuildException(message, e);
+				}
+			}
+		}
+	}
+
+	// Setters
+	public void setSkip(boolean skip) {
+		this.skip = skip;
+	}
+
+	public void setIgnoreFailure(boolean ignoreFailure) {
+		this.ignoreFailure = ignoreFailure;
+	}
+
+}

Modified: trunk/core/jbehave-core/src/java/org/jbehave/scenario/AbstractScenario.java (1097 => 1098)

--- trunk/core/jbehave-core/src/java/org/jbehave/scenario/AbstractScenario.java	2009-02-22 12:40:48 UTC (rev 1097)
+++ trunk/core/jbehave-core/src/java/org/jbehave/scenario/AbstractScenario.java	2009-02-22 13:21:51 UTC (rev 1098)
@@ -75,4 +75,9 @@
     public void addSteps(CandidateSteps... steps) {
         this.candidateSteps.addAll(asList(steps));
     }
+
+	public List<CandidateSteps> getSteps() {
+		return candidateSteps;
+	}    
+    
 }

Modified: trunk/core/jbehave-core/src/java/org/jbehave/scenario/JUnitScenario.java (1097 => 1098)

--- trunk/core/jbehave-core/src/java/org/jbehave/scenario/JUnitScenario.java	2009-02-22 12:40:48 UTC (rev 1097)
+++ trunk/core/jbehave-core/src/java/org/jbehave/scenario/JUnitScenario.java	2009-02-22 13:21:51 UTC (rev 1098)
@@ -1,5 +1,7 @@
 package org.jbehave.scenario;
 
+import java.util.List;
+
 import junit.framework.TestCase;
 
 import org.jbehave.scenario.steps.CandidateSteps;
@@ -49,11 +51,14 @@
         this.delegate.runScenario();
     }
 
-
     public void addSteps(CandidateSteps... steps) {
         this.delegate.addSteps(steps);
     }
 
+    public List<CandidateSteps> getSteps() {
+    	return delegate.getSteps();
+    }
+    
     /**
      * A JUnit 3-compatibile runnable method which simply delegates
      * {...@link RunnableScenario#runScenario()}

Modified: trunk/core/jbehave-core/src/java/org/jbehave/scenario/RunnableScenario.java (1097 => 1098)

--- trunk/core/jbehave-core/src/java/org/jbehave/scenario/RunnableScenario.java	2009-02-22 12:40:48 UTC (rev 1097)
+++ trunk/core/jbehave-core/src/java/org/jbehave/scenario/RunnableScenario.java	2009-02-22 13:21:51 UTC (rev 1098)
@@ -1,5 +1,7 @@
 package org.jbehave.scenario;
 
+import java.util.List;
+
 import org.jbehave.scenario.steps.CandidateSteps;
 
 /**
@@ -21,4 +23,6 @@
 
     void addSteps(CandidateSteps... steps);
 
+    List<CandidateSteps> getSteps();
+
 }

Added: trunk/core/jbehave-core/src/java/org/jbehave/scenario/reporters/PrintStreamStepDocReporter.java (0 => 1098)

--- trunk/core/jbehave-core/src/java/org/jbehave/scenario/reporters/PrintStreamStepDocReporter.java	                        (rev 0)
+++ trunk/core/jbehave-core/src/java/org/jbehave/scenario/reporters/PrintStreamStepDocReporter.java	2009-02-22 13:21:51 UTC (rev 1098)
@@ -0,0 +1,44 @@
+package org.jbehave.scenario.reporters;
+
+import java.io.PrintStream;
+import java.util.List;
+
+import org.jbehave.scenario.steps.StepDoc;
+
+/**
+ * <p>
+ * StepDoc reporter that outputs to a PrintStream, defaulting to System.out.
+ * </p>
+ */
+public class PrintStreamStepDocReporter implements StepDocReporter {
+
+	private final PrintStream output;
+	private final boolean reportMethods;
+
+	public PrintStreamStepDocReporter() {
+		this(System.out);
+	}
+
+	public PrintStreamStepDocReporter(PrintStream output) {
+		this(output, false);
+	}
+
+	public PrintStreamStepDocReporter(PrintStream output, boolean reportMethods) {
+		this.output = output;
+		this.reportMethods = reportMethods;
+	}
+
+	public void report(List<StepDoc> stepdocs) {
+		for (StepDoc stepdoc : stepdocs) {
+			output.println(stepdoc.getAnnotation().getSimpleName() + " "
+					+ stepdoc.getPattern());
+			if (stepdoc.getAliasPatterns().size() > 0) {
+				output.println("Aliases: " + stepdoc.getAliasPatterns());
+			}
+			if (reportMethods) {
+				output.println("Method: " + stepdoc.getMethod());
+			}
+		}
+	}
+
+}

Added: trunk/core/jbehave-core/src/java/org/jbehave/scenario/reporters/StepDocReporter.java (0 => 1098)

--- trunk/core/jbehave-core/src/java/org/jbehave/scenario/reporters/StepDocReporter.java	                        (rev 0)
+++ trunk/core/jbehave-core/src/java/org/jbehave/scenario/reporters/StepDocReporter.java	2009-02-22 13:21:51 UTC (rev 1098)
@@ -0,0 +1,16 @@
+package org.jbehave.scenario.reporters;
+
+import java.util.List;
+
+import org.jbehave.scenario.steps.StepDoc;
+
+/**
+ * Generates reports of generated StepDocs
+ * 
+ * @author Mauro Talevi
+ */
+public interface StepDocReporter {
+
+	void report(List<StepDoc> stepdocs);
+
+}

Modified: trunk/core/jbehave-core/src/java/org/jbehave/scenario/steps/DefaultStepDocGenerator.java (1097 => 1098)

--- trunk/core/jbehave-core/src/java/org/jbehave/scenario/steps/DefaultStepDocGenerator.java	2009-02-22 12:40:48 UTC (rev 1097)
+++ trunk/core/jbehave-core/src/java/org/jbehave/scenario/steps/DefaultStepDocGenerator.java	2009-02-22 13:21:51 UTC (rev 1098)
@@ -1,5 +1,6 @@
 package org.jbehave.scenario.steps;
 
+import java.io.OutputStream;
 import java.lang.reflect.Method;
 import java.util.Collections;
 import java.util.LinkedList;
@@ -39,5 +40,10 @@
 		return new String[]{};
 	}
 
+	public void reportTo(List<StepDoc> stepdocs, OutputStream outputStream) {
+		// TODO Auto-generated method stub
+		
+	}
 
+
 }

Modified: trunk/core/jbehave-maven-plugin/src/main/java/org/jbehave/mojo/ScenarioRunnerMojo.java (1097 => 1098)

--- trunk/core/jbehave-maven-plugin/src/main/java/org/jbehave/mojo/ScenarioRunnerMojo.java	2009-02-22 12:40:48 UTC (rev 1097)
+++ trunk/core/jbehave-maven-plugin/src/main/java/org/jbehave/mojo/ScenarioRunnerMojo.java	2009-02-22 13:21:51 UTC (rev 1098)
@@ -32,11 +32,12 @@
             return;
         }
         for (RunnableScenario scenario : scenarios()) {
+            String scenarioName = scenario.getClass().getName();
             try {
-                getLog().info("Running scenario " + scenario.getClass().getName());
+				getLog().info("Running scenario " + scenarioName);
                 scenario.runScenario();
             } catch (Throwable e) {
-                String message = "Failed to run scenario " + scenario.getClass().getName();
+                String message = "Failed to run scenario " + scenarioName;
                 if ( ignoreFailure ){
                     getLog().warn(message, e);
                 } else {

Added: trunk/core/jbehave-maven-plugin/src/main/java/org/jbehave/mojo/StepdocMojo.java (0 => 1098)

--- trunk/core/jbehave-maven-plugin/src/main/java/org/jbehave/mojo/StepdocMojo.java	                        (rev 0)
+++ trunk/core/jbehave-maven-plugin/src/main/java/org/jbehave/mojo/StepdocMojo.java	2009-02-22 13:21:51 UTC (rev 1098)
@@ -0,0 +1,64 @@
+package org.jbehave.mojo;
+
+import java.util.List;
+
+import org.apache.maven.plugin.MojoExecutionException;
+import org.apache.maven.plugin.MojoFailureException;
+import org.jbehave.scenario.RunnableScenario;
+import org.jbehave.scenario.reporters.PrintStreamStepDocReporter;
+import org.jbehave.scenario.reporters.StepDocReporter;
+import org.jbehave.scenario.steps.CandidateSteps;
+import org.jbehave.scenario.steps.DefaultStepDocGenerator;
+import org.jbehave.scenario.steps.StepDoc;
+import org.jbehave.scenario.steps.StepDocGenerator;
+
+/**
+ * Mojo to generate stepdocs
+ * 
+ * @author Mauro Talevi
+ * @goal stepdoc
+ */
+public class StepdocMojo extends AbstractScenarioMojo {
+
+	/**
+	 * The boolean flag to skip running scenario
+	 * 
+	 * @parameter default-value="false"
+	 */
+	private boolean skip;
+
+	/**
+	 * The boolean flag to ignoreFailure
+	 * 
+	 * @parameter default-value="false"
+	 */
+	private boolean ignoreFailure;
+
+	private StepDocGenerator generator = new DefaultStepDocGenerator();
+	private StepDocReporter reporter = new PrintStreamStepDocReporter();
+
+	public void execute() throws MojoExecutionException, MojoFailureException {
+		if (skip) {
+			getLog().info("Skipped generating stepdoc");
+			return;
+		}
+		for (RunnableScenario scenario : scenarios()) {
+			String scenarioName = scenario.getClass().getName();
+			try {
+				getLog().info("Generating stepdoc for " + scenarioName);
+				for (CandidateSteps steps : scenario.getSteps()) {
+					List<StepDoc> stepdocs = generator.generate(steps.getClass());
+					reporter.report(stepdocs);
+				}
+			} catch (Throwable e) {
+				String message = "Failed to generate stepdoc for "+scenarioName;						
+				if (ignoreFailure) {
+					getLog().warn(message, e);
+				} else {
+					throw new MojoExecutionException(message, e);
+				}
+			}
+		}
+	}
+
+}


To unsubscribe from this list please visit:

http://xircles.codehaus.org/manage_email

Reply via email to