<?xml version="1.0" encoding="UTF-8"?>
<commit>
  <added type="array">
    <added>
      <filename>lib/easyb-0.8.jar</filename>
    </added>
  </added>
  <modified type="array">
    <modified>
      <diff>@@ -23,8 +23,35 @@ import org.springframework.transaction.support.TransactionTemplate
 import org.springframework.transaction.support.TransactionCallback
 import org.springframework.transaction.TransactionStatus
 import org.apache.commons.logging.LogFactory
-//import br.com.urubatan.easybtest.BehaviorRunner;
+import org.codehaus.groovy.grails.commons.ApplicationHolder;
 import org.disco.easyb.report.Report;
+import groovy.lang.GroovyShell;
+
+import java.io.File;
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.List;
+
+import org.apache.commons.cli.CommandLine;
+import org.apache.commons.cli.CommandLineParser;
+import org.apache.commons.cli.GnuParser;
+import org.apache.commons.cli.HelpFormatter;
+import org.apache.commons.cli.Option;
+import org.apache.commons.cli.OptionBuilder;
+import org.apache.commons.cli.Options;
+import org.apache.commons.cli.ParseException;
+import org.disco.easyb.listener.BehaviorListener;
+import org.disco.easyb.listener.DefaultListener;
+import org.disco.easyb.report.XmlReportWriter;
+import org.disco.easyb.report.ReportWriter;
+import org.disco.easyb.report.Report;
+import org.disco.easyb.report.TxtSpecificationReportWriter;
+import org.disco.easyb.report.TxtStoryReportWriter;
+import org.disco.easyb.util.BehaviorStepType;
+import org.disco.easyb.util.ReportFormat;
+import org.disco.easyb.util.ReportType;
+import org.disco.easyb.*;
 
 
 Ant.property(environment: &quot;env&quot;)
@@ -43,7 +70,7 @@ target('default': &quot;Run a Grails applications easyb tests&quot;) {
 
 
 target(testApp: &quot;The test app implementation target&quot;) {
-  depends(packageApp, classpath, checkVersion, configureProxy, bootstrap)
+  depends(classpath, checkVersion, configureProxy,packageApp,bootstrap)
 
   antTestSource = Ant.path {
     fileset ( dir : &quot;${basedir}/test/behavior&quot; , includes : '**/*' ){
@@ -70,7 +97,264 @@ target(testApp: &quot;The test app implementation target&quot;) {
 
   reports = [new Report(location:&quot;${testDir}/xml/easyb.xml&quot;,format:&quot;xml&quot;,type:&quot;easyb&quot;),new Report(location:&quot;${testDir}/plain/stories.xml&quot;,format:&quot;txt&quot;,type:&quot;story&quot;),new Report(location:&quot;${testDir}/plain/specifications.txt&quot;,format:&quot;txt&quot;,type:&quot;specification&quot;)];
 
-  br.com.urubatan.easybtest.BehaviorRunner br = new br.com.urubatan.easybtest.BehaviorRunner(reports);
+  BehaviorRunner br = new BehaviorRunner(reports,appCtx,ApplicationHolder.application);
   br.runBehavior(testSource)
 
 }
+
+class BehaviorRunner {
+
+  def reports = [];
+    Object appCtx;
+    Object grailsApp;
+
+    public BehaviorRunner() {
+      this(null);
+    }
+
+    public BehaviorRunner(List&lt;Report&gt; reports, Object appCtx, Object grailsApp) {
+      this.appCtx = appCtx;
+      this.grailsApp = grailsApp;
+      this.reports = addDefaultReports(reports);
+    }
+
+    /**
+    * @param specs collection of files that contain the specifications
+    * @throws Exception if unable to write report file
+    */
+    public void runBehavior(Collection&lt;File&gt; specs) throws Exception {
+
+      BehaviorListener listener = new DefaultListener();
+
+      executeSpecifications(specs, listener);
+
+      System.out.println(&quot;\n&quot; +
+      //prints &quot;1 behavior run&quot; or &quot;x behaviors run&quot;
+      (listener.getBehaviorCount() &gt; 1 ? listener.getBehaviorCount()  + &quot; total behaviors run&quot; : &quot;1 behavior run&quot;)
+      //outer ternary prints either 1..X failure(s) or no failures
+      //inner ternary determines if more than one failure and makes it plural if so
+      + (listener.getFailedBehaviorCount() &gt; 0 ? &quot; with &quot;
+      + (listener.getFailedBehaviorCount() == 1 ? &quot;1 failure&quot; : listener.getFailedBehaviorCount() + &quot; failures&quot;) : &quot; with no failures&quot;));
+
+      produceReports(listener);
+
+      if (listener.getFailedBehaviorCount() &gt; 0) {
+        System.exit(-6);
+      }
+    }
+    /**
+    *
+    * @param listener
+    */
+    private void produceReports(BehaviorListener listener) {
+
+      for (Report report : reports) {
+        if (report.getFormat().concat(report.getType()).equals(Report.XML_EASYB)) {
+          new XmlReportWriter(report, listener).writeReport();
+        } else if (report.getFormat().concat(report.getType()).equals(Report.TXT_STORY)) {
+          new TxtStoryReportWriter(report, listener).writeReport();
+        } else if (report.getFormat().concat(report.getType()).equals(Report.TXT_SPECIFICATION)) {
+          new TxtSpecificationReportWriter(report, listener).writeReport();
+        }
+      }
+
+    }
+    /**
+    *
+    * @param behaviorFiles
+    * @param listener
+    * @throws IOException
+    */
+    private void executeSpecifications(final Collection&lt;File&gt; behaviorFiles, final BehaviorListener listener) throws IOException {
+      for (File behaviorFile : behaviorFiles) {
+        def behavior = null;
+          try {
+            behavior = BehaviorFactory.createBehavior(behaviorFile);
+          } catch(IllegalArgumentException iae) {
+            System.out.println(iae.getMessage());
+            System.exit(-1);
+          }
+
+          long startTime = System.currentTimeMillis();
+          System.out.println(
+          &quot;Running ${behavior.getPhrase()} ${((behavior instanceof Story) ? ' story' : ' specification')} (${behaviorFile.getName()})&quot;
+          );
+
+
+          BehaviorStep currentStep;
+          GroovyShell g = null;
+          if (behavior instanceof Story) {
+            currentStep = listener.startStep(BehaviorStepType.STORY, behavior.getPhrase());
+            g = new GroovyShell(StoryBinding.getBinding(listener));
+          } else {
+            currentStep = listener.startStep(BehaviorStepType.SPECIFICATION, behavior.getPhrase());
+            g = new GroovyShell(SpecificationBinding.getBinding(listener));
+          }
+          g.getContext().setVariable(&quot;grailsApp&quot;,grailsApp);
+          g.getContext().setVariable(&quot;appCtx&quot;,appCtx);
+          g.evaluate(behaviorFile);
+          listener.stopStep();
+
+          long endTime = System.currentTimeMillis();
+
+          printMetrics(behavior, startTime, currentStep, endTime);
+        }
+      }
+
+      private void printMetrics(Behavior behavior, long startTime, BehaviorStep currentStep, long endTime) {
+        if(behavior instanceof Story) {
+          System.out.println((currentStep.getFailedScenarioCountRecursively() == 0 ? &quot;&quot; : &quot;FAILURE &quot;) +
+          &quot;Scenarios run: &quot; + currentStep.getScenarioCountRecursively() +
+          &quot;, Failures: &quot; + currentStep.getFailedScenarioCountRecursively() +
+          &quot;, Pending: &quot; + currentStep.getPendingScenarioCountRecursively() +
+          &quot;, Time Elapsed: &quot; + (endTime - startTime) / 1000f + &quot; sec&quot;);
+        } else {
+          System.out.println((currentStep.getFailedSpecificationCountRecursively() == 0 ? &quot;&quot; : &quot;FAILURE &quot;) +
+          &quot;Specifications run: &quot; + currentStep.getSpecificationCountRecursively() +
+          &quot;, Failures: &quot; + currentStep.getFailedSpecificationCountRecursively() +
+          &quot;, Pending: &quot; + currentStep.getPendingSpecificationCountRecursively() +
+          &quot;, Time Elapsed: &quot; + (endTime - startTime) / 1000f + &quot; sec&quot;);
+        }
+      }
+
+      /**
+      * @param args the command line arguments
+      */
+      public static void main(String[] args) {
+        Options options = getOptionsForMain();
+
+        try {
+          CommandLine commandLine = getCommandLineForMain(args, options);
+          validateArguments(commandLine);
+
+          BehaviorRunner runner = new BehaviorRunner(getConfiguredReports(commandLine));
+
+          runner.runBehavior(getFileCollection(commandLine.getArgs()));
+        } catch (IllegalArgumentException iae) {
+          System.out.println(iae.getMessage());
+          handleHelpForMain(options);
+        } catch (ParseException pe) {
+          System.out.println(pe.getMessage());
+          handleHelpForMain(options);
+        } catch (Exception e) {
+          System.err.println(&quot;There was an error running the script&quot;);
+          e.printStackTrace(System.err);
+          System.exit(-6);
+        }
+      }
+
+      private static void validateArguments(CommandLine commandLine) throws IllegalArgumentException {
+        if (commandLine.getArgs().length == 0) {
+          throw new IllegalArgumentException(&quot;Required arguments missing.&quot;);
+        }
+      }
+
+      private static List&lt;Report&gt; getConfiguredReports(CommandLine line) {
+
+        def configuredReports = new ArrayList&lt;Report&gt;();
+          if (line.hasOption(Report.TXT_STORY)) {
+            Report report = new Report();
+            report.setFormat(ReportFormat.TXT.format());
+            if (line.getOptionValue(Report.TXT_STORY) == null) {
+              report.setLocation(&quot;easyb-story-report.txt&quot;);
+            } else {
+              report.setLocation(line.getOptionValue(Report.TXT_STORY));
+            }
+            report.setType(ReportType.STORY.type());
+
+            configuredReports.add(report);
+          }
+
+          if (line.hasOption(Report.TXT_SPECIFICATION)) {
+            Report report = new Report();
+            report.setFormat(ReportFormat.TXT.format());
+            if (line.getOptionValue(Report.TXT_SPECIFICATION) == null) {
+              report.setLocation(&quot;easyb-specification-report.txt&quot;);
+            } else {
+              report.setLocation(line.getOptionValue(Report.TXT_SPECIFICATION));
+            }
+            report.setType(ReportType.SPECIFICATION.type());
+
+            configuredReports.add(report);
+          }
+
+          if (line.hasOption(Report.XML_EASYB)) {
+            Report report = new Report();
+            report.setFormat(ReportFormat.XML.format());
+            if (line.getOptionValue(Report.XML_EASYB) == null) {
+              report.setLocation(&quot;easyb-report.xml&quot;);
+            } else {
+              report.setLocation(line.getOptionValue(Report.XML_EASYB));
+            }
+            report.setType(ReportType.EASYB.type());
+
+            configuredReports.add(report);
+          }
+
+          return configuredReports;
+        }
+
+        /**
+        * @param paths locations of the specifications to be loaded
+        * @return collection of files where the only element is the file of the spec to be run
+        */
+        private static Collection&lt;File&gt; getFileCollection(String[] paths) {
+          def coll = new ArrayList&lt;File&gt;();
+            for (String path : paths) {
+              coll.add(new File(path));
+            }
+            return coll;
+          }
+
+          /**
+          * @param options options that are available to this specification runner
+          */
+          private static void handleHelpForMain(Options options) {
+            new HelpFormatter().printHelp(&quot;BehaviorRunner my/path/to/MyFile.groovy&quot;, options);
+          }
+
+          /**
+          * @param args    command line arguments passed into main
+          * @param options options that are available to this specification runner
+          * @return representation of command line arguments passed in that match the available options
+          * @throws ParseException if there are any problems encountered while parsing the command line tokens
+          */
+          private static CommandLine getCommandLineForMain(String[] args, Options options) throws ParseException {
+            CommandLineParser commandLineParser = new GnuParser();
+            return commandLineParser.parse(options, args);
+          }
+
+          /**
+          * @return representation of a collection of Option objects, which describe the possible options for a command-line.
+          */
+          private static Options getOptionsForMain() {
+            Options options = new Options();
+
+            //noinspection AccessStaticViaInstance
+            Option xmleasybreport = OptionBuilder.withArgName(&quot;file&quot;).hasOptionalArg()
+            .withDescription(&quot;create an easyb report in xml format&quot;).create(Report.XML_EASYB);
+            options.addOption(xmleasybreport);
+
+            //noinspection AccessStaticViaInstance
+            Option storyreport = OptionBuilder.withArgName(&quot;file&quot;).hasOptionalArg()
+            .withDescription(&quot;create a story report&quot;).create(Report.TXT_STORY);
+            options.addOption(storyreport);
+
+            //noinspection AccessStaticViaInstance
+            Option behaviorreport = OptionBuilder.withArgName(&quot;file&quot;).hasOptionalArg()
+            .withDescription(&quot;create a behavior report&quot;).create(Report.TXT_SPECIFICATION);
+            options.addOption(behaviorreport);
+
+            return options;
+          }
+
+          private List&lt;Report&gt; addDefaultReports(List&lt;Report&gt; userConfiguredReports) {
+            def configuredReports = new ArrayList&lt;Report&gt;();
+
+              if (userConfiguredReports != null) {
+                configuredReports.addAll(userConfiguredReports);
+              }
+
+              return configuredReports;
+            }
+          }</diff>
      <filename>scripts/EasyTest.groovy</filename>
    </modified>
    <modified>
      <diff>@@ -9,6 +9,6 @@
 // Ant.mkdir(dir:&quot;c:\Documents and Settings\jardimr\Desktop/easybtest/grails-app/jobs&quot;)
 //
 
-Ant.property(environment:&quot;env&quot;)
-grailsHome = Ant.antProject.properties.&quot;env.GRAILS_HOME&quot;
-Ant.mkdir(dir:&quot;${basedir}/test/behavior&quot;
+//Ant.property(environment:&quot;env&quot;)
+//grailsHome = Ant.antProject.properties.&quot;env.GRAILS_HOME&quot;
+//Ant.mkdir(dir:&quot;${basedir}/test/behavior&quot;</diff>
      <filename>scripts/_Install.groovy</filename>
    </modified>
    <modified>
      <diff>@@ -3,6 +3,6 @@ scenario &quot;Any Test could be here&quot;, {
 	given &quot;Any thing&quot;,{}
 	when &quot;Some thing happens&quot;, {}
 	then &quot;A test must run&quot;, {
-		def sf = ctx.getBean(&quot;sessionFactory&quot;)
+		def sf = appCtx.getBean(&quot;sessionFactory&quot;)
 	}
 }</diff>
      <filename>test/behavior/TestStory.groovy</filename>
    </modified>
  </modified>
  <removed type="array">
    <removed>
      <filename>.classpath</filename>
    </removed>
    <removed>
      <filename>lib/easyb-0.7.jar</filename>
    </removed>
    <removed>
      <filename>src/groovy/br/com/urubatan/easybtest/BehaviorRunner.groovy</filename>
    </removed>
  </removed>
  <parents type="array">
    <parent>
      <id>599f40b7984d3ba40503e990485a649660f76be8</id>
    </parent>
  </parents>
  <author>
    <name>Rodrigo Urubatan Ferreira Jardim</name>
    <email>rodrigo@urubatan.com.br</email>
  </author>
  <url>http://github.com/urubatan/easybtest/commit/00974604dbe13e6b35aa48ff571ed9d6d3aa8a05</url>
  <id>00974604dbe13e6b35aa48ff571ed9d6d3aa8a05</id>
  <committed-date>2008-04-04T10:25:51-07:00</committed-date>
  <authored-date>2008-04-04T10:25:51-07:00</authored-date>
  <message>there is still hope, running tests in the grails context now</message>
  <tree>aef05177d1b8f036be63596c4f5ca61685022bc8</tree>
  <committer>
    <name>Rodrigo Urubatan Ferreira Jardim</name>
    <email>rodrigo@urubatan.com.br</email>
  </committer>
</commit>
