flex-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From aha...@apache.org
Subject git commit: [flex-utilities] [refs/heads/develop] - Add callbackMode so the UI gets updated during the run
Date Tue, 10 Dec 2013 20:05:26 GMT
Updated Branches:
  refs/heads/develop 377f1f2bf -> 8c90c12b4


Add callbackMode so the UI gets updated during the run


Project: http://git-wip-us.apache.org/repos/asf/flex-utilities/repo
Commit: http://git-wip-us.apache.org/repos/asf/flex-utilities/commit/8c90c12b
Tree: http://git-wip-us.apache.org/repos/asf/flex-utilities/tree/8c90c12b
Diff: http://git-wip-us.apache.org/repos/asf/flex-utilities/diff/8c90c12b

Branch: refs/heads/develop
Commit: 8c90c12b40ffd041e56f027a80dc00bb5fe34000
Parents: 377f1f2
Author: Alex Harui <aharui@apache.org>
Authored: Tue Dec 10 12:05:13 2013 -0800
Committer: Alex Harui <aharui@apache.org>
Committed: Tue Dec 10 12:05:13 2013 -0800

----------------------------------------------------------------------
 ant_on_air/src/org/apache/flex/ant/Ant.as       | 23 +++++-
 .../src/org/apache/flex/ant/tags/Available.as   |  4 +-
 .../src/org/apache/flex/ant/tags/Condition.as   |  4 +-
 ant_on_air/src/org/apache/flex/ant/tags/Copy.as |  5 +-
 .../src/org/apache/flex/ant/tags/Delete.as      |  4 +-
 ant_on_air/src/org/apache/flex/ant/tags/Echo.as |  4 +-
 ant_on_air/src/org/apache/flex/ant/tags/Fail.as |  6 +-
 .../src/org/apache/flex/ant/tags/Mkdir.as       |  4 +-
 .../src/org/apache/flex/ant/tags/Project.as     |  8 +-
 .../src/org/apache/flex/ant/tags/Property.as    |  2 +-
 .../src/org/apache/flex/ant/tags/Target.as      | 17 ++++-
 .../tags/supportClasses/FileSetTaskHandler.as   | 77 +++++++++++++++++---
 .../flex/ant/tags/supportClasses/TaskHandler.as |  7 +-
 ant_on_air/tests/AntTest.mxml                   | 14 +++-
 ant_on_air/tests/TestTarget.as                  |  2 +-
 15 files changed, 141 insertions(+), 40 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/flex-utilities/blob/8c90c12b/ant_on_air/src/org/apache/flex/ant/Ant.as
----------------------------------------------------------------------
diff --git a/ant_on_air/src/org/apache/flex/ant/Ant.as b/ant_on_air/src/org/apache/flex/ant/Ant.as
index 7476daf..e0121d5 100644
--- a/ant_on_air/src/org/apache/flex/ant/Ant.as
+++ b/ant_on_air/src/org/apache/flex/ant/Ant.as
@@ -55,7 +55,7 @@ package org.apache.flex.ant
          *   @param context Object An object containing an optional targets property listing
the targets to run.
          *   @return true if XML file was processed synchronously.  If false, then add listener
for Event.COMPLETE.
          */
-        public function processXMLFile(file:File, context:Object = null):Boolean
+        public function processXMLFile(file:File, context:Object = null, callbackMode:Boolean
= true):Boolean
         {
             this.file = file;
             var fs:FileStream = new FileStream();
@@ -70,7 +70,7 @@ package org.apache.flex.ant
             this.context = context;
             var project:Project = processXMLTag(xml, context) as Project;
             Ant.project = project;
-            if (!project.execute())
+            if (!project.execute(callbackMode))
             {
                 project.addEventListener(Event.COMPLETE, completeHandler);
                 return false;                
@@ -78,6 +78,25 @@ package org.apache.flex.ant
             return true;
         }
     
+        /**
+         *  Set by various classes to defer processing in callbackMode
+         */
+        public var functionToCall:Function;
+        
+        /**
+         *  If you set callbackMode = true, you must call this method until you receive
+         *  the Event.COMPLETE 
+         */
+        public function doCallback():void   
+        {
+            if (functionToCall != null)
+            {
+                var f:Function = functionToCall;
+                functionToCall = null;
+                f();
+            }
+        }
+        
         private var context:Object;
         public static var ant:Ant;
         public static var project:Project;

http://git-wip-us.apache.org/repos/asf/flex-utilities/blob/8c90c12b/ant_on_air/src/org/apache/flex/ant/tags/Available.as
----------------------------------------------------------------------
diff --git a/ant_on_air/src/org/apache/flex/ant/tags/Available.as b/ant_on_air/src/org/apache/flex/ant/tags/Available.as
index e3abf87..9942359 100644
--- a/ant_on_air/src/org/apache/flex/ant/tags/Available.as
+++ b/ant_on_air/src/org/apache/flex/ant/tags/Available.as
@@ -58,9 +58,9 @@ package org.apache.flex.ant.tags
             return true;
         }
 
-        override public function execute():Boolean
+        override public function execute(callbackMode:Boolean):Boolean
         {
-            super.execute();
+            super.execute(callbackMode);
             if (value)
                 if (!context.hasOwnProperty(_property))
                     context[_property] = _value;

http://git-wip-us.apache.org/repos/asf/flex-utilities/blob/8c90c12b/ant_on_air/src/org/apache/flex/ant/tags/Condition.as
----------------------------------------------------------------------
diff --git a/ant_on_air/src/org/apache/flex/ant/tags/Condition.as b/ant_on_air/src/org/apache/flex/ant/tags/Condition.as
index 814811d..dd5238f 100644
--- a/ant_on_air/src/org/apache/flex/ant/tags/Condition.as
+++ b/ant_on_air/src/org/apache/flex/ant/tags/Condition.as
@@ -39,9 +39,9 @@ package org.apache.flex.ant.tags
             super();
         }
         
-        override public function execute():Boolean
+        override public function execute(callbackMode:Boolean):Boolean
         {
-            super.execute();
+            super.execute(callbackMode);
             
             // if the property is not already set
             if (_property && _value != null && !context.hasOwnProperty(_property))

http://git-wip-us.apache.org/repos/asf/flex-utilities/blob/8c90c12b/ant_on_air/src/org/apache/flex/ant/tags/Copy.as
----------------------------------------------------------------------
diff --git a/ant_on_air/src/org/apache/flex/ant/tags/Copy.as b/ant_on_air/src/org/apache/flex/ant/tags/Copy.as
index 3636ad0..b1c0c46 100644
--- a/ant_on_air/src/org/apache/flex/ant/tags/Copy.as
+++ b/ant_on_air/src/org/apache/flex/ant/tags/Copy.as
@@ -76,9 +76,9 @@ package org.apache.flex.ant.tags
             srcFile.copyTo(destFile, overwrite);
         }
         
-        override public function execute():Boolean
+        override public function execute(callbackMode:Boolean):Boolean
         {
-            var retVal:Boolean = super.execute();
+            var retVal:Boolean = super.execute(callbackMode);
             if (numChildren > 0)
                 return retVal;
             
@@ -88,7 +88,6 @@ package org.apache.flex.ant.tags
             //var resolveName:String = destFile.nativePath.substr(destFile.nativePath.lastIndexOf(File.separator)
+ 1);
             //destDir.resolvePath(resolveName);
             
-            
             srcFile.copyTo(destFile, overwrite);
             return true;
         }

http://git-wip-us.apache.org/repos/asf/flex-utilities/blob/8c90c12b/ant_on_air/src/org/apache/flex/ant/tags/Delete.as
----------------------------------------------------------------------
diff --git a/ant_on_air/src/org/apache/flex/ant/tags/Delete.as b/ant_on_air/src/org/apache/flex/ant/tags/Delete.as
index 40f697a..0d5b010 100644
--- a/ant_on_air/src/org/apache/flex/ant/tags/Delete.as
+++ b/ant_on_air/src/org/apache/flex/ant/tags/Delete.as
@@ -65,9 +65,9 @@ package org.apache.flex.ant.tags
                 delFile.deleteFile();
         }
         
-        override public function execute():Boolean
+        override public function execute(callbackMode:Boolean):Boolean
         {
-            var retVal:Boolean = super.execute();
+            var retVal:Boolean = super.execute(callbackMode);
             if (numChildren > 0)
                 return retVal;
             

http://git-wip-us.apache.org/repos/asf/flex-utilities/blob/8c90c12b/ant_on_air/src/org/apache/flex/ant/tags/Echo.as
----------------------------------------------------------------------
diff --git a/ant_on_air/src/org/apache/flex/ant/tags/Echo.as b/ant_on_air/src/org/apache/flex/ant/tags/Echo.as
index d20e991..2e92f18 100644
--- a/ant_on_air/src/org/apache/flex/ant/tags/Echo.as
+++ b/ant_on_air/src/org/apache/flex/ant/tags/Echo.as
@@ -52,9 +52,9 @@ package org.apache.flex.ant.tags
                 super.processAttribute(name, value);
         }
 
-        override public function execute():Boolean
+        override public function execute(callbackMode:Boolean):Boolean
         {
-            super.execute();
+            super.execute(callbackMode);
             ant.output(ant.getValue(text, context));
             return true;
         }

http://git-wip-us.apache.org/repos/asf/flex-utilities/blob/8c90c12b/ant_on_air/src/org/apache/flex/ant/tags/Fail.as
----------------------------------------------------------------------
diff --git a/ant_on_air/src/org/apache/flex/ant/tags/Fail.as b/ant_on_air/src/org/apache/flex/ant/tags/Fail.as
index 1016b62..8ac8bf5 100644
--- a/ant_on_air/src/org/apache/flex/ant/tags/Fail.as
+++ b/ant_on_air/src/org/apache/flex/ant/tags/Fail.as
@@ -53,15 +53,15 @@ package org.apache.flex.ant.tags
                 super.processAttribute(name, value);
         }
 
-        override public function execute():Boolean
+        override public function execute(callbackMode:Boolean):Boolean
         {
-            super.execute();
+            super.execute(callbackMode);
             if (numChildren == 1)
             {
                 var child:Condition = getChildAt(0) as Condition;
                 if (child)
                 {
-                    child.execute();
+                    child.execute(false);
                     var val:Object = child.computedValue;
                     if (!(val == "true" || val == true))
                     {

http://git-wip-us.apache.org/repos/asf/flex-utilities/blob/8c90c12b/ant_on_air/src/org/apache/flex/ant/tags/Mkdir.as
----------------------------------------------------------------------
diff --git a/ant_on_air/src/org/apache/flex/ant/tags/Mkdir.as b/ant_on_air/src/org/apache/flex/ant/tags/Mkdir.as
index 111b0aa..3c41623 100644
--- a/ant_on_air/src/org/apache/flex/ant/tags/Mkdir.as
+++ b/ant_on_air/src/org/apache/flex/ant/tags/Mkdir.as
@@ -40,9 +40,9 @@ package org.apache.flex.ant.tags
         
         private var _dir:String;
         
-        override public function execute():Boolean
+        override public function execute(callbackMode:Boolean):Boolean
         {
-            super.execute();
+            super.execute(callbackMode);
             
             var dir:File = new File(_dir);
             dir.createDirectory();

http://git-wip-us.apache.org/repos/asf/flex-utilities/blob/8c90c12b/ant_on_air/src/org/apache/flex/ant/tags/Project.as
----------------------------------------------------------------------
diff --git a/ant_on_air/src/org/apache/flex/ant/tags/Project.as b/ant_on_air/src/org/apache/flex/ant/tags/Project.as
index 22435f4..91f8f98 100644
--- a/ant_on_air/src/org/apache/flex/ant/tags/Project.as
+++ b/ant_on_air/src/org/apache/flex/ant/tags/Project.as
@@ -92,8 +92,10 @@ package org.apache.flex.ant.tags
                 super.processAttribute(name, value);
         }
 
-        override public function execute():Boolean
+        override public function execute(callbackMode:Boolean):Boolean
         {
+            this.callbackMode = callbackMode;
+            
             status = true;
             
             if (context.targets == null)
@@ -126,7 +128,7 @@ package org.apache.flex.ant.tags
                 if (child is TaskHandler)
                 {
                     var task:TaskHandler = TaskHandler(child);
-                    if (!task.execute())
+                    if (!task.execute(callbackMode))
                     {
                         task.addEventListener(Event.COMPLETE, childCompleteHandler);
                         return false;
@@ -185,7 +187,7 @@ package org.apache.flex.ant.tags
         public function executeTarget(targetName:String):Boolean
         {
             var t:Target = getTarget(targetName);
-            if (!t.execute())
+            if (!t.execute(callbackMode))
             {
                 t.addEventListener(Event.COMPLETE, completeHandler);
                 return false;

http://git-wip-us.apache.org/repos/asf/flex-utilities/blob/8c90c12b/ant_on_air/src/org/apache/flex/ant/tags/Property.as
----------------------------------------------------------------------
diff --git a/ant_on_air/src/org/apache/flex/ant/tags/Property.as b/ant_on_air/src/org/apache/flex/ant/tags/Property.as
index 73fb2c1..0d7619c 100644
--- a/ant_on_air/src/org/apache/flex/ant/tags/Property.as
+++ b/ant_on_air/src/org/apache/flex/ant/tags/Property.as
@@ -53,7 +53,7 @@ package org.apache.flex.ant.tags
             super.init(xml, context, xmlProcessor);
         }
         
-        override public function execute():Boolean
+        override public function execute(callbackMode:Boolean):Boolean
         {
             if (name && value && !context.hasOwnProperty(name))
                 context[name] = value;

http://git-wip-us.apache.org/repos/asf/flex-utilities/blob/8c90c12b/ant_on_air/src/org/apache/flex/ant/tags/Target.as
----------------------------------------------------------------------
diff --git a/ant_on_air/src/org/apache/flex/ant/tags/Target.as b/ant_on_air/src/org/apache/flex/ant/tags/Target.as
index 0504237..185498f 100644
--- a/ant_on_air/src/org/apache/flex/ant/tags/Target.as
+++ b/ant_on_air/src/org/apache/flex/ant/tags/Target.as
@@ -82,7 +82,7 @@ package org.apache.flex.ant.tags
             {
                 var depend:String = dependsList.shift();
                 var t:Target = project.getTarget(depend);
-                if (!t.execute())
+                if (!t.execute(callbackMode))
                 {
                     t.addEventListener(Event.COMPLETE, dependCompleteHandler);
                     return false;
@@ -97,8 +97,9 @@ package org.apache.flex.ant.tags
             processDepends();
         }
         
-        override public function execute():Boolean
+        override public function execute(callbackMode:Boolean):Boolean
         {
+            this.callbackMode = callbackMode;
             if (_depends)
             {
                 dependsList = _depends.split(",");
@@ -130,13 +131,18 @@ package org.apache.flex.ant.tags
             while (current < numChildren)
             {
                 var step:TaskHandler = getChildAt(current++) as TaskHandler;
-                if (!step.execute())
+                if (!step.execute(callbackMode))
                 {
                     step.addEventListener(Event.COMPLETE, completeHandler);
                     return false;
                 }
                 if (!Ant.project.status)
                     return true;
+                if (callbackMode)
+                {
+                    ant.functionToCall = processSteps;
+                    return false;
+                }
             }
             dispatchEvent(new Event(Event.COMPLETE));
             return true;
@@ -149,7 +155,10 @@ package org.apache.flex.ant.tags
                 dispatchEvent(new Event(Event.COMPLETE));
                 return;                
             }
-            processSteps();
+            if (callbackMode)
+                ant.functionToCall = processSteps;
+            else
+                processSteps();
         }
     }
 }
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/flex-utilities/blob/8c90c12b/ant_on_air/src/org/apache/flex/ant/tags/supportClasses/FileSetTaskHandler.as
----------------------------------------------------------------------
diff --git a/ant_on_air/src/org/apache/flex/ant/tags/supportClasses/FileSetTaskHandler.as
b/ant_on_air/src/org/apache/flex/ant/tags/supportClasses/FileSetTaskHandler.as
index 21ffc9b..a5519c4 100644
--- a/ant_on_air/src/org/apache/flex/ant/tags/supportClasses/FileSetTaskHandler.as
+++ b/ant_on_air/src/org/apache/flex/ant/tags/supportClasses/FileSetTaskHandler.as
@@ -18,6 +18,8 @@
 ////////////////////////////////////////////////////////////////////////////////
 package org.apache.flex.ant.tags.supportClasses
 {
+    import flash.events.Event;
+    import flash.events.ProgressEvent;
     import flash.filesystem.File;
     
     import org.apache.flex.ant.Ant;
@@ -32,17 +34,25 @@ package org.apache.flex.ant.tags.supportClasses
         {
         }
         
+        private var current:int = 0;
+        private var currentFile:int;
+        private var currentList:Vector.<String>;
+        private var currentDir:File;
+        private var totalFiles:int;
+        private var thisFile:int;
+        
         /**
          *  Do the work.
          *  TaskHandlers lazily create their children so
          *  super.execute() should be called before
          *  doing any real work. 
          */
-        override public function execute():Boolean
+        override public function execute(callbackMode:Boolean):Boolean
         {
-            ant.processChildren(this.xml, context, this);
-            var n:int = numChildren;
-            for (var i:int = 0; i < n; i++)
+            super.execute(callbackMode);
+            totalFiles = 0;
+            thisFile = 0;
+            for (var i:int = 0; i < numChildren; i++)
             {
                 var fs:FileSet = getChildAt(i) as FileSet;
                 if (fs)
@@ -52,11 +62,7 @@ package org.apache.flex.ant.tags.supportClasses
                         var list:Vector.<String> = fs.value as Vector.<String>;
                         if (list)
                         {
-                            var dir:File = new File(fs.dir);
-                            for each (var fileName:String in list)
-                            {
-                                actOnFile(dir.nativePath, fileName);
-                            }
+                            totalFiles += list.length;
                         }
                     }
                     catch (e:Error)
@@ -69,7 +75,58 @@ package org.apache.flex.ant.tags.supportClasses
                     }
                 }
             }
-            return true;
+            actOnFileSets();
+            return !callbackMode;
+        }
+        
+        private function actOnFileSets():void
+        {
+            if (current == numChildren)
+            {
+                dispatchEvent(new Event(Event.COMPLETE));
+                return;
+            }
+            
+            while (current < numChildren)
+            {
+                var fs:FileSet = getChildAt(current++) as FileSet;
+                if (fs)
+                {
+                    var list:Vector.<String> = fs.value as Vector.<String>;
+                    if (list)
+                    {
+                        currentDir = new File(fs.dir);
+                        currentFile = 0;
+                        currentList = list;
+                        actOnList();
+                        if (callbackMode)
+                            return;
+                    }
+                }
+            }
+        }
+
+        private function actOnList():void
+        {
+            if (currentFile == currentList.length)
+            {
+                ant.functionToCall = actOnFileSets;
+                ant.dispatchEvent(new ProgressEvent(ProgressEvent.PROGRESS, false, false,
thisFile, totalFiles));
+                return;
+            }
+            
+            while (currentFile < currentList.length)
+            {
+                var fileName:String = currentList[currentFile++];
+                ant.dispatchEvent(new ProgressEvent(ProgressEvent.PROGRESS, false, false,
thisFile, totalFiles));
+                actOnFile(currentDir.nativePath, fileName);
+                thisFile++;
+                if (callbackMode)
+                {
+                    ant.functionToCall = actOnList;
+                    return;
+                }
+            }
         }
         
         protected function actOnFile(dir:String, fileName:String):void

http://git-wip-us.apache.org/repos/asf/flex-utilities/blob/8c90c12b/ant_on_air/src/org/apache/flex/ant/tags/supportClasses/TaskHandler.as
----------------------------------------------------------------------
diff --git a/ant_on_air/src/org/apache/flex/ant/tags/supportClasses/TaskHandler.as b/ant_on_air/src/org/apache/flex/ant/tags/supportClasses/TaskHandler.as
index d5fdcba..673189e 100644
--- a/ant_on_air/src/org/apache/flex/ant/tags/supportClasses/TaskHandler.as
+++ b/ant_on_air/src/org/apache/flex/ant/tags/supportClasses/TaskHandler.as
@@ -28,7 +28,9 @@ package org.apache.flex.ant.tags.supportClasses
         {
         }
         
-        public var failonerror:Boolean = true
+        public var failonerror:Boolean = true;
+        
+        protected var callbackMode:Boolean;
         
         /**
          *  Do the work.
@@ -36,8 +38,9 @@ package org.apache.flex.ant.tags.supportClasses
          *  super.execute() should be called before
          *  doing any real work. 
          */
-        public function execute():Boolean
+        public function execute(callbackMode:Boolean):Boolean
         {
+            this.callbackMode = callbackMode;
             ant.processChildren(this.xml, context, this);
             return true;
         }

http://git-wip-us.apache.org/repos/asf/flex-utilities/blob/8c90c12b/ant_on_air/tests/AntTest.mxml
----------------------------------------------------------------------
diff --git a/ant_on_air/tests/AntTest.mxml b/ant_on_air/tests/AntTest.mxml
index eae1e4a..f3daaa7 100644
--- a/ant_on_air/tests/AntTest.mxml
+++ b/ant_on_air/tests/AntTest.mxml
@@ -49,8 +49,12 @@ limitations under the License.
                 var context:Object = { targets: "test" };
                 var file:File = File.applicationDirectory;
                 file = file.resolvePath("test.xml");
-                if (!ant.processXMLFile(file, context))
+                addEventListener(Event.ENTER_FRAME, enterFrameHandler);
+                if (!ant.processXMLFile(file, context, true))
+                {
                     ant.addEventListener(Event.COMPLETE, completeHandler);
+                    pb.source = ant;
+                }
                 else
                     completeHandler(null);
             }
@@ -79,7 +83,15 @@ limitations under the License.
                 console.verticalScrollPosition = console.maxVerticalScrollPosition;
             }
             
+            private function enterFrameHandler(event:Event):void
+            {
+                ant.doCallback();
+            }
         ]]>
     </fx:Script>
+    <s:layout>
+        <s:VerticalLayout />
+    </s:layout>
     <mx:TextArea id="console" width="100%" height="100%" />
+    <mx:ProgressBar id="pb" width="100%" mode="event" label="Copying %1 of %2" />
 </s:WindowedApplication>
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/flex-utilities/blob/8c90c12b/ant_on_air/tests/TestTarget.as
----------------------------------------------------------------------
diff --git a/ant_on_air/tests/TestTarget.as b/ant_on_air/tests/TestTarget.as
index 2570c20..287d13a 100644
--- a/ant_on_air/tests/TestTarget.as
+++ b/ant_on_air/tests/TestTarget.as
@@ -48,7 +48,7 @@ package
             var context:Object = { targets: "test" };
             var file:File = File.applicationDirectory;
             file = file.resolvePath("test.xml");
-            if (!ant.processXMLFile(file, context))
+            if (!ant.processXMLFile(file, context, false))
                 ant.addEventListener(Event.COMPLETE, completeHandler);
             else
                 completeHandler(null);


Mime
View raw message