You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@flex.apache.org by ah...@apache.org on 2013/12/03 00:37:50 UTC

git commit: [flex-utilities] [refs/heads/develop] - add environment variable support to Ant Property. Worked on Mac. Needs testing on Windows

Updated Branches:
  refs/heads/develop a7871a7d7 -> 6f763a74b


add environment variable support to Ant Property.  Worked on Mac.  Needs testing on Windows


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

Branch: refs/heads/develop
Commit: 6f763a74b5c2e46e64bbe9a3d30aca8817a9bcf3
Parents: a7871a7
Author: Alex Harui <ah...@apache.org>
Authored: Mon Dec 2 15:37:34 2013 -0800
Committer: Alex Harui <ah...@apache.org>
Committed: Mon Dec 2 15:37:34 2013 -0800

----------------------------------------------------------------------
 ant_on_air/build.xml                            |  3 +-
 ant_on_air/src/org/apache/flex/ant/Ant.as       | 35 ++++++++-
 .../src/org/apache/flex/ant/tags/Property.as    | 76 ++++++++++++++++++--
 ant_on_air/tests/TestTarget-app.xml             |  1 +
 ant_on_air/tests/TestTarget.as                  |  9 ++-
 5 files changed, 117 insertions(+), 7 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/flex-utilities/blob/6f763a74/ant_on_air/build.xml
----------------------------------------------------------------------
diff --git a/ant_on_air/build.xml b/ant_on_air/build.xml
index 9515465..276c04b 100644
--- a/ant_on_air/build.xml
+++ b/ant_on_air/build.xml
@@ -73,6 +73,7 @@
             fork="true"
             maxmemory="512m">
             <source-path path-element="${SOURCE_DIR}"/>
+			<load-config filename="${FLEX_HOME}/frameworks/air-config.xml"/>
             <external-library-path file="${AIR_HOME}/frameworks/libs/air/airglobal.swc" append="true"/>
 			<include-classes>AntClasses</include-classes>
 
@@ -83,8 +84,8 @@
 			failonerror="true"
             fork="true"
             maxmemory="512m">
+			<load-config filename="${FLEX_HOME}/frameworks/air-config.xml"/>
             <source-path path-element="${SOURCE_DIR}"/>
-            <external-library-path file="${AIR_HOME}/frameworks/libs/air/airglobal.swc" append="true"/>
 		</mxmlc>
     </target>
 

http://git-wip-us.apache.org/repos/asf/flex-utilities/blob/6f763a74/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 b81d8b6..af2f1f5 100644
--- a/ant_on_air/src/org/apache/flex/ant/Ant.as
+++ b/ant_on_air/src/org/apache/flex/ant/Ant.as
@@ -62,8 +62,41 @@ package org.apache.flex.ant
             tagMap = antTagProcessors;
             if (!context)
                 context = {};
+            this.context = context;
             var project:Project = processXMLTag(xml, context) as Project;
-            project.execute();
+            if (waiting == 0)
+                project.execute();
+            else
+                this.project = project;
+        }
+    
+        private var context:Object;
+        private var project:Project;
+        
+        private var _waiting:int = 0;
+        
+        /**
+         *  A flag used to defer execution if
+         *  waiting on something async like loading
+         *  environment variables.
+         */
+        public function get waiting():int
+        {
+            return _waiting;
+        }
+        
+        /**
+         *  @private
+         */
+        public function set waiting(value:int):void
+        {
+            if (value >= 0)
+                _waiting = value;
+            
+            if (value == 0)
+                if (project)
+                    project.execute()
+                        
         }
         
         /**

http://git-wip-us.apache.org/repos/asf/flex-utilities/blob/6f763a74/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 60bd6f8..6215ab5 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
@@ -21,6 +21,12 @@ package org.apache.flex.ant.tags
     import flash.filesystem.File;
     import flash.filesystem.FileMode;
     import flash.filesystem.FileStream;
+    import flash.desktop.NativeProcess;
+    import flash.desktop.NativeProcessStartupInfo;
+    import flash.events.NativeProcessExitEvent;
+    import flash.events.ProgressEvent;
+    import flash.system.Capabilities;
+    import flash.utils.IDataInput;
     
     import mx.core.IFlexModuleFactory;
     import mx.utils.StringUtil;
@@ -74,7 +80,7 @@ package org.apache.flex.ant.tags
                         else
                         {
                             parts.shift();
-                            val = parts.joint("=");
+                            val = parts.join("=");
                         }
                         context[key] = val;
                     }
@@ -89,11 +95,73 @@ package org.apache.flex.ant.tags
             else if (name == "environment")
             {
                 envPrefix = value;
-                // TODO
-                ant.output("environment attribute is not supported");
+                ant.waiting++;
+                requestEnvironmentVariables();
             }
             else
                 super.processAttribute(name, value);
         }
-    }
+        
+        private var process:NativeProcess;
+        
+        public function requestEnvironmentVariables():void
+        {
+            var file:File = File.applicationDirectory;
+            if (Capabilities.os.indexOf('Mac OS') > -1)
+                file = new File("/bin/bash");
+            else
+                file = file.resolvePath("C:\\Windows\\System32\\cmd.exe");
+            var nativeProcessStartupInfo:NativeProcessStartupInfo = new NativeProcessStartupInfo();
+            nativeProcessStartupInfo.executable = file;
+            var args:Vector.<String> = new Vector.<String>();
+            if (Capabilities.os.indexOf('Mac OS') > -1)
+                args.push("-c");
+            args.push("set");
+            nativeProcessStartupInfo.arguments = args;
+            process = new NativeProcess();
+            process.addEventListener(ProgressEvent.STANDARD_OUTPUT_DATA, onOutputData); 
+            process.addEventListener(ProgressEvent.STANDARD_ERROR_DATA, onOutputErrorData); 
+            process.start(nativeProcessStartupInfo);
+            process.addEventListener(NativeProcessExitEvent.EXIT, exitHandler);
+        }
+         
+        private function exitHandler(event:NativeProcessExitEvent):void
+        {
+        }
+
+        private function onOutputErrorData(event:ProgressEvent):void 
+        { 
+            var stdError:IDataInput = process.standardError; 
+            var data:String = stdError.readUTFBytes(process.standardError.bytesAvailable); 
+            trace("Got Error Output: ", data); 
+            ant.waiting--;
+        }
+        
+        private function onOutputData(event:ProgressEvent):void 
+        { 
+            var stdOut:IDataInput = process.standardOutput; 
+            var data:String = stdOut.readUTFBytes(process.standardOutput.bytesAvailable); 
+            trace("Got: ", data); 
+            var propLines:Array = data.split("\n");
+            for each (var line:String in propLines)
+            {
+                var parts:Array = line.split("=");
+                if (parts.length >= 2)
+                {
+                    var key:String = StringUtil.trim(parts[0]);
+                    var val:String;
+                    if (parts.length == 2)
+                        val = parts[1];
+                    else
+                    {
+                        parts.shift();
+                        val = parts.join("=");
+                    }
+                    context[key] = val;
+                }
+            }
+            ant.waiting--;
+        }
+
+    } 
 }
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/flex-utilities/blob/6f763a74/ant_on_air/tests/TestTarget-app.xml
----------------------------------------------------------------------
diff --git a/ant_on_air/tests/TestTarget-app.xml b/ant_on_air/tests/TestTarget-app.xml
index 5b823a8..2cb5795 100644
--- a/ant_on_air/tests/TestTarget-app.xml
+++ b/ant_on_air/tests/TestTarget-app.xml
@@ -134,6 +134,7 @@
 	<!-- (i.e., to only mobile devices) then add this element and list -->
 	<!-- only the profiles which your application does support. -->
 	<!-- <supportedProfiles>desktop extendedDesktop mobileDevice extendedMobileDevice</supportedProfiles> -->
+	<supportedProfiles>extendedDesktop</supportedProfiles> -->
 
 	<!-- The subpath of the standard default installation location to use. Optional. -->
 	<!-- <installFolder></installFolder> -->

http://git-wip-us.apache.org/repos/asf/flex-utilities/blob/6f763a74/ant_on_air/tests/TestTarget.as
----------------------------------------------------------------------
diff --git a/ant_on_air/tests/TestTarget.as b/ant_on_air/tests/TestTarget.as
index 0f7db80..c541b9b 100644
--- a/ant_on_air/tests/TestTarget.as
+++ b/ant_on_air/tests/TestTarget.as
@@ -20,6 +20,7 @@ package
 {
     import flash.desktop.NativeApplication;
     import flash.display.Sprite;
+    import flash.events.Event;
     import flash.filesystem.File;
     import org.apache.flex.ant.Ant;
     import org.apache.flex.ant.tags.Condition; Condition.init(null);
@@ -39,7 +40,13 @@ package
             var file:File = File.applicationDirectory;
             file = file.resolvePath("test.xml");
             ant.processXMLFile(file, context);
-            NativeApplication.nativeApplication.exit();
+            addEventListener(Event.ENTER_FRAME, enterFrameHandler);
+        }
+        
+        private function enterFrameHandler(event:Event):void
+        {
+            if (ant.waiting == 0)
+                NativeApplication.nativeApplication.exit();
         }
         
         private var ant:Ant;