ant-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bode...@apache.org
Subject svn commit: r441847 - in /ant/antlibs/antunit/trunk/src/main/org/apache/ant/antunit: AntUnit.java AntUnitListener.java listener/BaseAntUnitListener.java
Date Sat, 09 Sep 2006 19:44:18 GMT
Author: bodewig
Date: Sat Sep  9 12:44:17 2006
New Revision: 441847

URL: http://svn.apache.org/viewvc?view=rev&rev=441847
Log:
make sure we get the [antunit] banner in plainlistener

Modified:
    ant/antlibs/antunit/trunk/src/main/org/apache/ant/antunit/AntUnit.java
    ant/antlibs/antunit/trunk/src/main/org/apache/ant/antunit/AntUnitListener.java
    ant/antlibs/antunit/trunk/src/main/org/apache/ant/antunit/listener/BaseAntUnitListener.java

Modified: ant/antlibs/antunit/trunk/src/main/org/apache/ant/antunit/AntUnit.java
URL: http://svn.apache.org/viewvc/ant/antlibs/antunit/trunk/src/main/org/apache/ant/antunit/AntUnit.java?view=diff&rev=441847&r1=441846&r2=441847
==============================================================================
--- ant/antlibs/antunit/trunk/src/main/org/apache/ant/antunit/AntUnit.java (original)
+++ ant/antlibs/antunit/trunk/src/main/org/apache/ant/antunit/AntUnit.java Sat Sep  9 12:44:17
2006
@@ -131,6 +131,7 @@
      */
     public void add(AntUnitListener al) {
         listeners.add(al);
+        al.setParentTask(this);
     }
 
     /**
@@ -250,6 +251,12 @@
                             fireError(name, e);
                         }
                     } finally {
+                        // fire endTest her instead of the endTarget
+                        // event, otherwise an error would be
+                        // registered after the endTest event -
+                        // endTarget is called before out catch block
+                        // is reached.
+                        fireEndTest(name);
                         // clean up
                         if (tearDown != null) {
                             newProject.executeTarget(TEARDOWN);
@@ -391,6 +398,17 @@
     }
 
     /**
+     * invokes endTest on all registered test listeners.
+     */
+    private void fireEndTest(String targetName) {
+        Iterator it = listeners.iterator();
+        while (it.hasNext()) {
+            AntUnitListener al = (AntUnitListener) it.next();
+            al.endTest(targetName);
+        }
+    }
+
+    /**
      * Adapts AntUnitListener to BuildListener.
      */
     private class BuildToAntUnitListener implements BuildListener {
@@ -415,10 +433,6 @@
             }
         }
         public void targetFinished(BuildEvent event) {
-            String tName = event.getTarget().getName();
-            if (tName.startsWith(TEST)) {
-                a.endTest(tName);
-            }
         }
         public void taskStarted(BuildEvent event) {}
         public void taskFinished(BuildEvent event) {}

Modified: ant/antlibs/antunit/trunk/src/main/org/apache/ant/antunit/AntUnitListener.java
URL: http://svn.apache.org/viewvc/ant/antlibs/antunit/trunk/src/main/org/apache/ant/antunit/AntUnitListener.java?view=diff&rev=441847&r1=441846&r2=441847
==============================================================================
--- ant/antlibs/antunit/trunk/src/main/org/apache/ant/antunit/AntUnitListener.java (original)
+++ ant/antlibs/antunit/trunk/src/main/org/apache/ant/antunit/AntUnitListener.java Sat Sep
 9 12:44:17 2006
@@ -21,11 +21,18 @@
 package org.apache.ant.antunit;
 
 import org.apache.tools.ant.Project;
+import org.apache.tools.ant.Task;
 
 /**
  * A test listener for <antunit>.
  */
 public interface AntUnitListener {
+    /**
+     * Set a reference to the AntUnit task executing the tests, this
+     * provides access to the containing project, target or Ant's
+     * logging system.
+     */
+    void setParentTask(Task t);
     /**
      * Invoked once per build file, before any targets get executed.
      */

Modified: ant/antlibs/antunit/trunk/src/main/org/apache/ant/antunit/listener/BaseAntUnitListener.java
URL: http://svn.apache.org/viewvc/ant/antlibs/antunit/trunk/src/main/org/apache/ant/antunit/listener/BaseAntUnitListener.java?view=diff&rev=441847&r1=441846&r2=441847
==============================================================================
--- ant/antlibs/antunit/trunk/src/main/org/apache/ant/antunit/listener/BaseAntUnitListener.java
(original)
+++ ant/antlibs/antunit/trunk/src/main/org/apache/ant/antunit/listener/BaseAntUnitListener.java
Sat Sep  9 12:44:17 2006
@@ -32,8 +32,9 @@
 import org.apache.ant.antunit.AssertionFailedException;
 
 import org.apache.tools.ant.BuildException;
+import org.apache.tools.ant.Location;
 import org.apache.tools.ant.Project;
-import org.apache.tools.ant.ProjectComponent;
+import org.apache.tools.ant.Task;
 import org.apache.tools.ant.taskdefs.LogOutputStream;
 import org.apache.tools.ant.types.EnumeratedAttribute;
 import org.apache.tools.ant.util.FileUtils;
@@ -43,7 +44,7 @@
  * A test listener for <antunit> modeled aftern the Plain JUnit
  * test listener that is part of Ant.
  */
-public abstract class BaseAntUnitListener extends ProjectComponent
+public abstract class BaseAntUnitListener
     implements AntUnitListener {
 
     protected BaseAntUnitListener(SendLogTo defaultReportTarget,
@@ -87,6 +88,19 @@
     private SendLogTo logTo;
 
     /**
+     * Where to send the test report.
+     */
+    protected void setSendLogTo(SendLogTo logTo) {
+        this.logTo = logTo;
+    }
+
+    private Task parentTask;
+
+    public void setParentTask(Task t) {
+        parentTask = t;
+    }
+
+    /**
      * keeps track of the numer of executed targets, the failures an errors.
      */
     protected int runCount, failureCount, errorCount;
@@ -95,13 +109,6 @@
      */
     protected long start, testStart;
 
-    /**
-     * Where to send the test report.
-     */
-    protected void setSendLogTo(SendLogTo logTo) {
-        this.logTo = logTo;
-    }
-
     public void startTestSuite(Project testProject, String buildFile) {
         start = System.currentTimeMillis();
         runCount = failureCount = errorCount = 0;
@@ -129,7 +136,11 @@
         l = f = null;
         if (logTo.getValue().equals(SendLogTo.ANT_LOG)
             || logTo.getValue().equals(SendLogTo.BOTH)) {
-            l = new LogOutputStream(this, Project.MSG_INFO);
+            if (parentTask != null) {
+                l = new LogOutputStream(parentTask, Project.MSG_INFO);
+            } else {
+                l = System.out;
+            }
             if (logTo.getValue().equals(SendLogTo.ANT_LOG)) {
                 return l;
             }
@@ -139,7 +150,9 @@
 
             String fileName = "TEST-" + normalize(buildFile) + "." + extension;
             File file = toDir == null
-                ? getProject().resolveFile(fileName)
+                ? (parentTask != null 
+                   ? parentTask.getProject().resolveFile(fileName)
+                   : new File(fileName))
                 : new File(toDir, fileName);
             try {
                 f = new FileOutputStream(file);
@@ -159,9 +172,11 @@
      * junitreport.
      */
     protected final String normalize(String buildFile) {
+        File base = parentTask != null
+            ? parentTask.getProject().getBaseDir()
+            : new File(System.getProperty("user.dir"));
         buildFile = FileUtils.getFileUtils()
-            .removeLeadingPath(getProject().getBaseDir(),
-                               new File(buildFile));
+            .removeLeadingPath(base, new File(buildFile));
         if (buildFile.length() > 0
             && buildFile.charAt(0) == File.separatorChar) {
             buildFile = buildFile.substring(1);
@@ -169,6 +184,17 @@
 
         return buildFile.replace('.', '_').replace(':', '_')
             .replace(File.separatorChar, '.');
+    }
+
+    protected final Location getLocation(Throwable t) {
+        Location l = Location.UNKNOWN_LOCATION;
+        if (t instanceof BuildException) {
+            Location l2 = ((BuildException) t).getLocation();
+            if (l2 != null) {
+                l = l2;
+            }
+        }
+        return l;
     }
 
     public static class SendLogTo extends EnumeratedAttribute {



---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@ant.apache.org
For additional commands, e-mail: dev-help@ant.apache.org


Mime
View raw message