Title: [1472] trunk/core/examples/trader: JBEHAVE-228: STATS format now specified as default formats for builder.

Diff

Modified: trunk/core/distribution/src/site/content/reports.html (1471 => 1472)

--- trunk/core/distribution/src/site/content/reports.html	2009-12-26 11:11:17 UTC (rev 1471)
+++ trunk/core/distribution/src/site/content/reports.html	2009-12-27 11:46:30 UTC (rev 1472)
@@ -55,10 +55,9 @@
             public ScenarioReporter forReportingScenarios() {
                 return new ScenarioReporterBuilder(new FilePrintStreamFactory(scenarioClass, converter))
                             .with(CONSOLE) // report to System.out
-                            .with(STATS)  // report to .stats file in Properties format
-                            .with(TXT)    // report to .txt file in PLAIN format
-                            .with(HTML)   // report to .html file in HTML format
-                            .with(XML)    // report to .xml file in XML format
+                            .with(TXT)     // report to .txt file in PLAIN format
+                            .with(HTML)    // report to .html file in HTML format
+                            .with(XML)     // report to .xml file in XML format
                             .build();
             }
 
@@ -76,11 +75,14 @@
 name resolution mechanism used for mapping Java classes and textual
 scenarios. So, e.g., if the scenario class is <b>com.example.MyScenario</b>,
 we'll end up with file report outputs of the form: <b>com.example.my_scenario.[format]</b>
-(where <b>format</b> is any of <b>txt,html,xml,stats</b> in the example above).</p>
+(where <b>format</b> is any of <b>txt,html,xml</b> in the example
+above).</p>
 
-<p>The builder provides defaults for all the formats supported, but if the user needs to create a bespoke instance of 
-a reporter for a given format, it can be easily done by overriding the default.  E.g. to override the reporter for <b>TXT</b> format
-to use a ".text" extension (a possibly keywords for a different Locale):</p>
+<p>The builder provides defaults for all the formats supported, but
+if the user needs to create a bespoke instance of a reporter for a given
+format, it can be easily done by overriding the default. E.g. to
+override the reporter for <b>TXT</b> format to use a ".text" extension
+(a possibly keywords for a different Locale):</p>
 <pre class="brush: java">
 
         ScenarioReporter reporter = new ScenarioReporterBuilder(factory){
@@ -88,12 +90,13 @@
                        switch (format) {
                            case TXT:
                                factory.useConfiguration(new FileConfiguration("text"));
-                               return new PrintStreamScenarioReporter(factory.getPrintStream(), new Properties(),  new I18nKeyWords(Locale.ITALIAN), true);
+                               return new PrintStreamScenarioReporter(factory.getPrintStream(), new Properties(), new I18nKeyWords(Locale.ITALIAN), true);
                             default:
                                return super.reporterFor(format);
                        }
                    }
 </pre>
+
 <h2>Report Rendering</h2>
 
 <p>The generation of the reports is only the first part of a
@@ -118,16 +121,41 @@
 and <b>jbehave-reports/style</b> directories. Also note that the default
 style makes use of images found in the <b>jbehave-site-resources.jar</b>.</p>
 
-<span class="followup">Note that the <b>stats</b> report defined
-above is treated in the rendering slightly differently from other
-reports, in that the statistics are displayed in the index page, if
-available. Conventionally, it looks for a report format named <b>stats</b>,
-so if you configure it with a different name or not configure it at all,
-the statistics will be displayed as not available (<b>N/A</b>). Also,
-note that the report formats configured should match ones found in the
-Ant or Maven execution for the report rendering task or goal (c.f. <a
-    href="" scenarios</a> for examples).</span>
+<p>Also, note that the report formats configured should match ones
+found in the Ant or Maven execution for the report rendering task or
+goal (c.f. <a href="" scenarios</a> for
+examples).</p>
 
+<h2>Reporting Statistics</h2>
+
+<p>The scenario statistics report above is treated in the rendering
+slightly differently from other reports, in that the statistics are
+displayed on the index page, if available. To ensure they are always
+available the scenario reporter builder automatically builds with the <b>stats</b>
+reporter included by default. To change or remove default formats simply
+override the method:</p>
+<pre class="brush: java">
+        new ScenarioReporterBuilder(factory){
+               protected void withDefaultFormats() {
+                    with(Format.STATS);
+               }
+        }
+</pre>
+
+<p>By default, JBehave outputs file reports to the directory <b>jbehave-reports</b>
+(relative to the scenario class code source location, e.g. the <b>target</b> directory in Maven), 
+but this can be changed via the builder:</p>
+
+<pre class="brush: java">
+        new ScenarioReporterBuilder(factory).outputTo("my-reports")
+</pre>
+
+<p>If the default formats or the output file directory are modified via the builder,
+then correspondingly we need to inform the report render of these changes.  See
+<a href="" scenarios</a> for details on how to configure
+these changes.
+</p>
+
 <h2>Next?</h2>
 
 <span class="followup">The <a

Modified: trunk/core/distribution/src/site/content/running-scenarios.html (1471 => 1472)

--- trunk/core/distribution/src/site/content/running-scenarios.html	2009-12-26 11:11:17 UTC (rev 1471)
+++ trunk/core/distribution/src/site/content/running-scenarios.html	2009-12-27 11:46:30 UTC (rev 1472)
@@ -39,7 +39,7 @@
     classpathref="your.runtime.classpath" />
   
   <renderReports outputDirectory="${basedir}/target/jbehave-reports"
-    formats="txt,html,xml,stats" />
+    formats="txt,html,xml" templateProperties="defaultFormats=stats" />
     
 ]]></script>
 
@@ -89,8 +89,13 @@
                 <format>txt</format>
                 <format>html</format>
                 <format>xml</format>
-                <format>stats</format>
               </formats>
+              <templateProperties>
+                <property>
+                  <name>defaultFormats</name>
+                  <value>stats</value>
+                </property>
+              </templateProperties>
             </configuration>
             <goals>
               <goal>render-reports</goal>

Modified: trunk/core/examples/trader/build.xml (1471 => 1472)

--- trunk/core/examples/trader/build.xml	2009-12-26 11:11:17 UTC (rev 1471)
+++ trunk/core/examples/trader/build.xml	2009-12-27 11:46:30 UTC (rev 1472)
@@ -98,7 +98,7 @@
       classpathref="scenario.classpath" />
 
     <reportRenderer outputDirectory="${basedir}/target/jbehave-reports"
-      formats="txt,html,xml,stats" />
+      formats="txt,html,xml" templateProperties="defaultFormats=stats"/>
 
   </target>
 

Modified: trunk/core/examples/trader/pom.xml (1471 => 1472)

--- trunk/core/examples/trader/pom.xml	2009-12-26 11:11:17 UTC (rev 1471)
+++ trunk/core/examples/trader/pom.xml	2009-12-27 11:46:30 UTC (rev 1472)
@@ -144,12 +144,18 @@
             <id>render-reports-generated</id>
             <phase>post-integration-test</phase>
             <configuration>
+              <outputDirectory>${project.build.directory}/jbehave-reports</outputDirectory>
               <formats>
                 <format>txt</format>
                 <format>html</format>
                 <format>xml</format>
-                <format>stats</format>
               </formats>
+              <templateProperties>
+                <property>
+                  <name>defaultFormats</name>
+                  <value>stats</value>
+                </property>
+              </templateProperties>
             </configuration>
             <goals>
               <goal>render-reports</goal>

Modified: trunk/core/examples/trader/src/main/java/org/jbehave/examples/trader/TraderScenario.java (1471 => 1472)

--- trunk/core/examples/trader/src/main/java/org/jbehave/examples/trader/TraderScenario.java	2009-12-26 11:11:17 UTC (rev 1471)
+++ trunk/core/examples/trader/src/main/java/org/jbehave/examples/trader/TraderScenario.java	2009-12-27 11:46:30 UTC (rev 1472)
@@ -2,7 +2,6 @@
 
 import static org.jbehave.scenario.reporters.ScenarioReporterBuilder.Format.CONSOLE;
 import static org.jbehave.scenario.reporters.ScenarioReporterBuilder.Format.HTML;
-import static org.jbehave.scenario.reporters.ScenarioReporterBuilder.Format.STATS;
 import static org.jbehave.scenario.reporters.ScenarioReporterBuilder.Format.TXT;
 import static org.jbehave.scenario.reporters.ScenarioReporterBuilder.Format.XML;
 
@@ -33,7 +32,6 @@
             public ScenarioReporter forReportingScenarios() {
                 return new ScenarioReporterBuilder(new FilePrintStreamFactory(scenarioClass, converter))
                             .with(CONSOLE)
-                            .with(STATS)
                             .with(TXT)
                             .with(HTML)
                             .with(XML)

Modified: trunk/core/jbehave-ant/src/main/java/org/jbehave/ant/ReportRendererTask.java (1471 => 1472)

--- trunk/core/jbehave-ant/src/main/java/org/jbehave/ant/ReportRendererTask.java	2009-12-26 11:11:17 UTC (rev 1471)
+++ trunk/core/jbehave-ant/src/main/java/org/jbehave/ant/ReportRendererTask.java	2009-12-27 11:46:30 UTC (rev 1472)
@@ -5,7 +5,10 @@
 import static org.apache.tools.ant.Project.MSG_WARN;
 
 import java.io.File;
+import java.io.IOException;
+import java.io.StringReader;
 import java.util.List;
+import java.util.Properties;
 
 import org.apache.tools.ant.BuildException;
 import org.apache.tools.ant.Task;
@@ -29,13 +32,20 @@
      */
     private List<String> formats = asList();
 
+    /**
+     * The template properties
+     */
+    private Properties templateProperties = new Properties();
+
     public void execute() throws BuildException {
-        ReportRenderer renderer = new FreemarkerReportRenderer();
+        ReportRenderer renderer = new FreemarkerReportRenderer(templateProperties);
         try {
-            log("Rendering reports in '" + outputDirectory + "' using formats '" + formats + "'", MSG_INFO);
+            log("Rendering reports in '" + outputDirectory + "' using formats '" + formats + "'"
+               +" and template properties '"+templateProperties+"'", MSG_INFO);
             renderer.render(new File(outputDirectory), formats);
         } catch (Throwable e) {
-            String message = "Failed to render reports in '" + outputDirectory + "' using formats '" + formats + "'";
+            String message = "Failed to render reports in '" + outputDirectory + "' using formats '" + formats + "'"
+                            +" and template properties '"+templateProperties+"'";
             log(message, MSG_WARN);
             throw new BuildException(message, e);
         }
@@ -50,6 +60,15 @@
     public void setFormats(String formats) {
         this.formats = asList(formats.split(","));
     }
+    
+    public void setTemplateProperties(String properties){
+        try {
+            templateProperties.load(new StringReader(properties));
+        } catch (IOException e) {
+            String message = "Failed to load template properties: "+properties;
+            log(message, MSG_WARN);
+        }        
+    }
 
     
 }

Modified: trunk/core/jbehave-core/src/behaviour/java/org/jbehave/scenario/reporters/PrintStreamScenarioReporterBehaviour.java (1471 => 1472)

--- trunk/core/jbehave-core/src/behaviour/java/org/jbehave/scenario/reporters/PrintStreamScenarioReporterBehaviour.java	2009-12-26 11:11:17 UTC (rev 1471)
+++ trunk/core/jbehave-core/src/behaviour/java/org/jbehave/scenario/reporters/PrintStreamScenarioReporterBehaviour.java	2009-12-27 11:46:30 UTC (rev 1472)
@@ -4,7 +4,6 @@
 import static org.hamcrest.CoreMatchers.equalTo;
 import static org.jbehave.Ensure.ensureThat;
 import static org.jbehave.scenario.reporters.ScenarioReporterBuilder.Format.HTML;
-import static org.jbehave.scenario.reporters.ScenarioReporterBuilder.Format.STATS;
 import static org.jbehave.scenario.reporters.ScenarioReporterBuilder.Format.TXT;
 import static org.junit.Assert.assertEquals;
 
@@ -322,14 +321,14 @@
         Class<MyScenario> scenarioClass = MyScenario.class;
         ScenarioNameResolver nameResolver = new UnderscoredCamelCaseResolver();
         FilePrintStreamFactory printStreamFactory = new FilePrintStreamFactory(scenarioClass, nameResolver);
-        ScenarioReporter reporter = new ScenarioReporterBuilder(printStreamFactory).with(HTML).with(TXT).with(STATS)
+        ScenarioReporter reporter = new ScenarioReporterBuilder(printStreamFactory).with(HTML).with(TXT)
                 .build();
 
         // When
         narrateAnInterestingStory(reporter);
         File outputDirectory = printStreamFactory.getOutputFile().getParentFile();
         ReportRenderer renderer = new FreemarkerReportRenderer();
-        renderer.render(outputDirectory, asList("html", "txt", "stats"));
+        renderer.render(outputDirectory, asList("html", "txt"));
 
         // Then
         ensureFileExists(new File(outputDirectory, "rendered/index.html"));

Added: trunk/core/jbehave-core/src/behaviour/java/org/jbehave/scenario/reporters/ScenarioReporterBuilderBehaviour.java (0 => 1472)

--- trunk/core/jbehave-core/src/behaviour/java/org/jbehave/scenario/reporters/ScenarioReporterBuilderBehaviour.java	                        (rev 0)
+++ trunk/core/jbehave-core/src/behaviour/java/org/jbehave/scenario/reporters/ScenarioReporterBuilderBehaviour.java	2009-12-27 11:46:30 UTC (rev 1472)
@@ -0,0 +1,86 @@
+package org.jbehave.scenario.reporters;
+
+import static org.hamcrest.CoreMatchers.equalTo;
+import static org.jbehave.Ensure.ensureThat;
+import static org.jbehave.scenario.reporters.ScenarioReporterBuilder.Format.STATS;
+import static org.jbehave.scenario.reporters.ScenarioReporterBuilder.Format.TXT;
+
+import java.io.IOException;
+import java.util.Map;
+import java.util.Properties;
+
+import org.jbehave.scenario.Scenario;
+import org.jbehave.scenario.i18n.I18nKeyWords;
+import org.jbehave.scenario.parser.ScenarioNameResolver;
+import org.jbehave.scenario.parser.UnderscoredCamelCaseResolver;
+import org.jbehave.scenario.reporters.FilePrintStreamFactory.FileConfiguration;
+import org.jbehave.scenario.reporters.ScenarioReporterBuilder.Format;
+import org.junit.Test;
+
+public class ScenarioReporterBuilderBehaviour {
+
+
+    @Test
+    public void shouldBuildWithStatsByDefault() throws IOException {
+        Class<MyScenario> scenarioClass = MyScenario.class;
+        ScenarioNameResolver nameResolver = new UnderscoredCamelCaseResolver();
+        FilePrintStreamFactory factory = new FilePrintStreamFactory(scenarioClass, nameResolver);
+        ScenarioReporterBuilder builder = new ScenarioReporterBuilder(factory);
+
+        // When
+        ScenarioReporter reporter = builder.build();
+        
+        // Then
+        ensureThat(reporter instanceof DelegatingScenarioReporter);
+        Map<Format, ScenarioReporter> delegates = builder.getDelegates();
+        ensureThat(delegates.size(), equalTo(1));
+        ensureThat(delegates.get(STATS) instanceof StatisticsScenarioReporter);
+    }
+
+    @Test
+    public void shouldAllowOverrideOfDefaultFileDirectory() throws IOException {
+        Class<MyScenario> scenarioClass = MyScenario.class;
+        ScenarioNameResolver nameResolver = new UnderscoredCamelCaseResolver();
+        FilePrintStreamFactory factory = new FilePrintStreamFactory(scenarioClass, nameResolver);
+        ScenarioReporterBuilder builder = new ScenarioReporterBuilder(factory);
+
+        // When
+        String fileDirectory = "my-reports";
+        builder.outputTo(fileDirectory);
+        
+        // Then
+        ensureThat(builder.fileConfiguration("").getDirectory().endsWith(fileDirectory));
+    }
+
+    @Test
+    public void shouldBuildAndOverrideDefaultReporterForAGivenFormat() throws IOException {
+        Class<MyScenario> scenarioClass = MyScenario.class;
+        ScenarioNameResolver nameResolver = new UnderscoredCamelCaseResolver();
+        FilePrintStreamFactory factory = new FilePrintStreamFactory(scenarioClass, nameResolver);
+        final ScenarioReporter txtReporter = new PrintStreamScenarioReporter(factory.getPrintStream(), new Properties(),  new I18nKeyWords(), true);
+        ScenarioReporterBuilder builder = new ScenarioReporterBuilder(factory){
+               public ScenarioReporter reporterFor(Format format){
+                       switch (format) {
+                           case TXT:
+                               factory.useConfiguration(new FileConfiguration("text"));
+                               return txtReporter;
+                            default:
+                               return super.reporterFor(format);
+                       }
+                   }
+        };
+        
+        // When
+        ScenarioReporter reporter = builder.with(TXT).build();
+        
+        // Then
+        ensureThat(reporter instanceof DelegatingScenarioReporter);
+        Map<Format, ScenarioReporter> delegates = builder.getDelegates();
+        ensureThat(delegates.size(), equalTo(2));
+        ensureThat(delegates.get(TXT), equalTo(txtReporter));
+    }
+
+    private static class MyScenario extends Scenario {
+
+    }
+}

Modified: trunk/core/jbehave-core/src/main/java/org/jbehave/scenario/reporters/FreemarkerReportRenderer.java (1471 => 1472)

--- trunk/core/jbehave-core/src/main/java/org/jbehave/scenario/reporters/FreemarkerReportRenderer.java	2009-12-26 11:11:17 UTC (rev 1471)
+++ trunk/core/jbehave-core/src/main/java/org/jbehave/scenario/reporters/FreemarkerReportRenderer.java	2009-12-27 11:46:30 UTC (rev 1472)
@@ -1,5 +1,7 @@
 package org.jbehave.scenario.reporters;
 
+import static java.util.Arrays.asList;
+
 import java.io.File;
 import java.io.FileInputStream;
 import java.io.FileReader;
@@ -23,12 +25,19 @@
 import freemarker.template.TemplateException;
 
 /**
- * Freemarker-based report renderer, using the file outputs generated by the
+ * <p>Freemarker-based report renderer, using the file outputs generated by the
  * reporters for the given formats. The FTL templates for the index and single
  * views are injectable via the {...@link FreemarkerReportRender(Properties)}
  * constructor, but defaults are provided. To override, specify the the path the
- * new template under keys "index" and "single".
- * 
+ * new template under keys "index" and "single".</p>
+ * <p>The report renderer provids the following template resources:
+ * <pre>
+ * resources.setProperty("index", "ftl/jbehave-reports-index.ftl");
+ * resources.setProperty("single", "ftl/jbehave-reports-single.ftl");
+ * resources.setProperty("renderedDirectory", "rendered");
+ * resources.setProperty("defaultFormats", "stats");
+ * </pre>  
+ * </p>
  * @author Mauro Talevi
  */
 public class FreemarkerReportRenderer implements ReportRenderer {
@@ -44,6 +53,8 @@
         Properties resources = new Properties();
         resources.setProperty("index", "ftl/jbehave-reports-index.ftl");
         resources.setProperty("single", "ftl/jbehave-reports-single.ftl");
+        resources.setProperty("renderedDirectory", "rendered");
+        resources.setProperty("defaultFormats", "stats");
         return resources;
     }
 
@@ -63,9 +74,10 @@
     }
 
     private void createIndex(File outputDirectory, List<String> formats) {
-        String outputName = "rendered/index.html";
+        String outputName = templateResource("renderedDirectory")+"/index.html";
         String resource = templateResource("index");
-        Map<String, List<File>> reportFiles = generatedReportFiles(outputDirectory, outputName, formats);
+        List<String> mergedFormats = mergeWithDefaults(formats);
+        Map<String, List<File>> reportFiles = generatedReportFiles(outputDirectory, outputName, mergedFormats);
         List<Report> renderedReports = renderedReports(reportFiles);
         Map<String, Object> dataModel = newDataModel();
         dataModel.put("reports", renderedReports);
@@ -73,6 +85,13 @@
         write(outputDirectory, outputName, resource, dataModel);
     }
 
+    private List<String> mergeWithDefaults(List<String> formats) {
+        List<String> merged = new ArrayList<String>();
+        merged.addAll(asList(templateResource("defaultFormats").split(",")));        
+        merged.addAll(formats);
+        return merged;
+    }
+
     private Map<String, List<File>> generatedReportFiles(File outputDirectory, final String outputName,
             final List<String> formats) {
         Map<String, List<File>> reports = new HashMap<String, List<File>>();
@@ -108,6 +127,7 @@
     private List<Report> renderedReports(Map<String, List<File>> reportFiles) {
         try {
             String resource = templateResource("single");
+            String renderedDirectory = templateResource("renderedDirectory");
             List<Report> reports = new ArrayList<Report>();
             for (String name : reportFiles.keySet()) {
                 Map<String, File> filesByFormat = new HashMap<String, File>();
@@ -119,7 +139,7 @@
                     dataModel.put("body", IOUtils.toString(new FileReader(file)));
                     dataModel.put("format", format);
                     File outputDirectory = file.getParentFile();
-                    String outputName = "rendered/" + fileName;
+                    String outputName = renderedDirectory+ "/" + fileName;
                     if (!format.equals("html")) {
                         outputName = outputName + ".html";
                     }

Modified: trunk/core/jbehave-core/src/main/java/org/jbehave/scenario/reporters/ScenarioReporterBuilder.java (1471 => 1472)

--- trunk/core/jbehave-core/src/main/java/org/jbehave/scenario/reporters/ScenarioReporterBuilder.java	2009-12-26 11:11:17 UTC (rev 1471)
+++ trunk/core/jbehave-core/src/main/java/org/jbehave/scenario/reporters/ScenarioReporterBuilder.java	2009-12-27 11:46:30 UTC (rev 1472)
@@ -1,5 +1,6 @@
 package org.jbehave.scenario.reporters;
 
+import java.util.Collections;
 import java.util.HashMap;
 import java.util.Map;
 
@@ -16,18 +17,34 @@
  * </p>
  * <p>
  * To build reporter with default delegates for given formats:
- * 
  * <pre>
  * Class&lt;MyScenario&gt; scenarioClass = MyScenario.class;
  * ScenarioNameResolver nameResolver = new UnderscoredCamelCaseResolver();
  * FilePrintStreamFactory printStreamFactory = new FilePrintStreamFactory(scenarioClass, nameResolver);
- * ScenarioReporter reporter = new ScenarioReporterBuilder(printStreamFactory).with(HTML).with(TXT).with(STATS).build();
+ * ScenarioReporter reporter = new ScenarioReporterBuilder(printStreamFactory).with(HTML).with(TXT).build();
  * </pre> 
  * </p>
- * <p>To override the default instance of a given reporter delegate, e.g. to report format <b>TXT</b> to <b>.text</b> files
- * and to inject other non-default parameters, such as keywords for a different locale:
+ * <p>The builder is configured to build with the {...@link Format#STATS} format by default.  To change the default formats
+ * the user can override the method:
  * <pre>
- * ScenarioReporter reporter = new ScenarioReporterBuilder(printStreamFactory){
+ * new ScenarioReporterBuilder(printStreamFactory){
+ *    protected void withDefaultFormats() {
+ *      with(Format.STATS);
+ *    }
+ *  }
+ * </pre>
+ * </p>
+ * <p>The builder configures the file-based reporters to output to the default file directory {...@link FileConfiguration#DIRECTORY}.
+ * To change the default:
+ * <pre>
+ * new ScenarioReporterBuilder(printStreamFactory).outputTo("my-reports").with(HTML).with(TXT).build();
+ * </pre>
+ * </p> 
+ * <p>The builder provides default instances for all reporters.  To change the reporter for a specific instance, 
+ * e.g. to report format <b>TXT</b> to <b>.text</b> files and to inject other non-default parameters, 
+ * such as keywords for a different locale:
+ * <pre>
+ * new ScenarioReporterBuilder(printStreamFactory){
  *   public ScenarioReporter reporterFor(Format format){
  *       switch (format) {
  *           case TXT:
@@ -47,15 +64,26 @@
 
     protected final FilePrintStreamFactory factory;
     protected Map<Format, ScenarioReporter> delegates = new HashMap<Format, ScenarioReporter>();
+    private String fileDirectory = new FileConfiguration().getDirectory();
 
     public ScenarioReporterBuilder(FilePrintStreamFactory factory) {
         this.factory = factory;
+        withDefaultFormats();
     }
 
+    protected void withDefaultFormats() {
+        with(Format.STATS);
+    }
+
     public ScenarioReporter build() {
         return new DelegatingScenarioReporter(delegates.values());
     }
 
+    public ScenarioReporterBuilder outputTo(String fileDirectory){        
+        this.fileDirectory = fileDirectory;
+        return this;
+    }
+    
     public ScenarioReporterBuilder with(Format format) {
         delegates.put(format, reporterFor(format));
         return this;
@@ -66,22 +94,30 @@
             case CONSOLE:
                 return new PrintStreamScenarioReporter();
             case STATS:
-                factory.useConfiguration(new FileConfiguration("stats"));
+                factory.useConfiguration(fileConfiguration("stats"));
                 return new StatisticsScenarioReporter(factory.getPrintStream());
             case TXT:
-                factory.useConfiguration(new FileConfiguration("txt"));
+                factory.useConfiguration(fileConfiguration("txt"));
                 return new PrintStreamScenarioReporter(factory.getPrintStream());
             case HTML:
-                factory.useConfiguration(new FileConfiguration("html"));
+                factory.useConfiguration(fileConfiguration("html"));
                 return new HtmlPrintStreamScenarioReporter(factory.getPrintStream());
             case XML:
-                factory.useConfiguration(new FileConfiguration("xml"));
+                factory.useConfiguration(fileConfiguration("xml"));
                 return new XmlPrintStreamScenarioReporter(factory.getPrintStream());
             default:
                 throw new UnsupportedReporterFormatException(format);
         }
     }
+    
+    public Map<Format, ScenarioReporter> getDelegates() {
+        return Collections.unmodifiableMap(delegates);
+    }
 
+    protected FileConfiguration fileConfiguration(String extension) {
+        return new FileConfiguration(fileDirectory, extension);
+    }
+
     @SuppressWarnings("serial")
     public static class UnsupportedReporterFormatException extends RuntimeException {
 

Modified: trunk/core/jbehave-maven-plugin/src/main/java/org/jbehave/mojo/ReportRendererMojo.java (1471 => 1472)

--- trunk/core/jbehave-maven-plugin/src/main/java/org/jbehave/mojo/ReportRendererMojo.java	2009-12-26 11:11:17 UTC (rev 1471)
+++ trunk/core/jbehave-maven-plugin/src/main/java/org/jbehave/mojo/ReportRendererMojo.java	2009-12-27 11:46:30 UTC (rev 1472)
@@ -5,6 +5,7 @@
 import java.io.File;
 import java.util.List;
 import java.util.Locale;
+import java.util.Properties;
 
 import org.apache.maven.doxia.siterenderer.Renderer;
 import org.apache.maven.project.MavenProject;
@@ -39,6 +40,13 @@
     private List<String> formats = asList();
 
     /**
+     * Non-default template properties. Defaults to new Properties().
+     * 
+     * @parameter 
+     */
+    private Properties templateProperties = new Properties();
+
+    /**
      * <i>Maven Internal</i>: The Doxia Site Renderer.
      * 
      * @component
@@ -83,13 +91,14 @@
     }
 
     protected void executeReport(Locale locale) throws MavenReportException {
-        ReportRenderer reportRenderer = new FreemarkerReportRenderer();
+        ReportRenderer reportRenderer = new FreemarkerReportRenderer(templateProperties);
         try {
-            getLog().info("Rendering reports in '" + outputDirectory + "' using formats '" + formats + "'");
+            getLog().info("Rendering reports in '" + outputDirectory + "' using formats '" + formats + "'" 
+            		    + " and template properties '"+templateProperties+"'");
             reportRenderer.render(outputDirectory, formats);
         } catch (RuntimeException e) {
             String message = "Failed to render reports in outputDirectory " + outputDirectory
-                    + " using formats " + formats;
+                    + " using formats " + formats + " and template properties '"+templateProperties+"'";
             getLog().warn(message, e);
             throw new MavenReportException(message, e);
         }


To unsubscribe from this list please visit:

http://xircles.codehaus.org/manage_email

Reply via email to