ant-notifications mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From gscok...@apache.org
Subject svn commit: r736770 - /ant/antlibs/antunit/trunk/src/main/org/apache/ant/antunit/AntUnit.java
Date Thu, 22 Jan 2009 20:05:28 GMT
Author: gscokart
Date: Thu Jan 22 12:05:28 2009
New Revision: 736770

URL: http://svn.apache.org/viewvc?rev=736770&view=rev
Log:
extract script 'scanning' and regroup methods in a class

Modified:
    ant/antlibs/antunit/trunk/src/main/org/apache/ant/antunit/AntUnit.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?rev=736770&r1=736769&r2=736770&view=diff
==============================================================================
--- 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 Thu Jan 22 12:05:28
2009
@@ -223,8 +223,34 @@
         }
     }
 
+    private class AntUnitScriptRunner {
+        private boolean setUp;
+        private boolean tearDown;
+        private boolean suiteSetUp;
+        private boolean suiteTearDown;
+        
+        public List scanFile(File f) {
+            // setup project instance
+            newProject = createProjectForFile(f);
+
+            // find targets
+            Map targets = newProject.getTargets();
+            setUp = targets.containsKey(SETUP);
+            tearDown = targets.containsKey(TEARDOWN);
+            suiteSetUp = targets.containsKey(SUITESETUP);
+            suiteTearDown = targets.containsKey(SUITETEARDOWN);
+            List testTargets = new LinkedList();
+            Iterator it = targets.keySet().iterator();
+            while (it.hasNext()) {
+                String name = (String) it.next();
+                if (name.startsWith(TEST) && !name.equals(TEST)) {
+                    testTargets.add(name);
+                }
+            }
+            return testTargets;
+        }
 
-    private boolean startSuite(boolean suiteSetUp) {
+    public boolean startSuite() {
         newProject.fireBuildStarted();
         if (suiteSetUp) {
             try {
@@ -242,7 +268,7 @@
         return true;
     }
 
-    private void runTarget(boolean setUp, boolean tearDown, String name) {
+    public void runTarget(String name) {
         Vector v = new Vector();
         if (setUp) {
             v.add(SETUP);
@@ -277,7 +303,7 @@
         }
     }
 
-    private void endSuite(boolean suiteTearDown, Throwable caught) {
+    public void endSuite(Throwable caught) {
         if (suiteTearDown) {
             try {
                 newProject.executeTarget(SUITETEARDOWN);
@@ -291,41 +317,26 @@
         }
         newProject.fireBuildFinished(caught);
     }    
+    }
     
     /**
      * Processes a single build file.
      */
     private void doFile(File f) {
         log("Running tests in build file " + f, Project.MSG_DEBUG);
-
-        // setup project instance
-        newProject = createProjectForFile(f);
-
-        // find targets
-        Map targets = newProject.getTargets();
-        boolean setUp = targets.containsKey(SETUP);
-        boolean tearDown = targets.containsKey(TEARDOWN);
-        boolean suiteSetUp = targets.containsKey(SUITESETUP);
-        boolean suiteTearDown = targets.containsKey(SUITETEARDOWN);
-        List testTargets = new LinkedList();
-        Iterator it = targets.keySet().iterator();
-        while (it.hasNext()) {
-            String name = (String) it.next();
-            if (name.startsWith(TEST) && !name.equals(TEST)) {
-                testTargets.add(name);
-            }
-        }
+        AntUnitScriptRunner scriptRunner = new AntUnitScriptRunner();
+        List testTargets = scriptRunner.scanFile(f);
 
         // start test
         Throwable caught = null;
         try {
-            if (!startSuite(suiteSetUp)) {
+            if (!scriptRunner.startSuite()) {
                 return;
             }
             Iterator iter = testTargets.iterator();
             while (iter.hasNext()) {
                 String name = (String) iter.next();
-                runTarget(setUp, tearDown, name);
+                scriptRunner.runTarget(name);
                 if (iter.hasNext()) {
                     newProject = createProjectForFile(f);
                 }
@@ -333,7 +344,7 @@
         } catch (Throwable e) {
             caught = e;
         } finally {
-            endSuite(suiteTearDown, caught);            
+            scriptRunner.endSuite(caught);            
             newProject = null;
         }
     }



Mime
View raw message