flex-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From aha...@apache.org
Subject [1/3] git commit: [flex-utilities] [refs/heads/develop] - add Unzip task
Date Wed, 11 Dec 2013 07:44:30 GMT
Updated Branches:
  refs/heads/develop 1a38abfd8 -> 486673be7


add Unzip task


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

Branch: refs/heads/develop
Commit: 9dc5a00a8f3795828d3c05aa0892d0c8cac713e3
Parents: 1a38abf
Author: Alex Harui <aharui@apache.org>
Authored: Tue Dec 10 22:36:42 2013 -0800
Committer: Alex Harui <aharui@apache.org>
Committed: Tue Dec 10 22:36:42 2013 -0800

----------------------------------------------------------------------
 ant_on_air/build.xml                            |   2 +
 ant_on_air/src/AntClasses.as                    |   3 +
 .../src/org/apache/flex/ant/tags/Unzip.as       | 141 +++++++++++++++++++
 ant_on_air/tests/test.xml                       |   2 +
 4 files changed, 148 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/flex-utilities/blob/9dc5a00a/ant_on_air/build.xml
----------------------------------------------------------------------
diff --git a/ant_on_air/build.xml b/ant_on_air/build.xml
index 82cb24d..8c0f9cb 100644
--- a/ant_on_air/build.xml
+++ b/ant_on_air/build.xml
@@ -99,6 +99,7 @@
             <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"/>
+            <external-library-path file="${basedir}/../installer/libs" append="true"/>
 			<include-classes>AntClasses</include-classes>
 
         </compc>
@@ -122,6 +123,7 @@
             maxmemory="512m">
 			<load-config filename="${FLEX_HOME}/frameworks/air-config.xml"/>
             <source-path path-element="${SOURCE_DIR}"/>
+            <library-path file="${basedir}/../installer/libs" append="true"/>
 		</mxmlc>
         <exec executable="${AIR_HOME}/bin/${adl}" dir="${basedir}/tests" failonerror="true">
             <arg value="-runtime" />

http://git-wip-us.apache.org/repos/asf/flex-utilities/blob/9dc5a00a/ant_on_air/src/AntClasses.as
----------------------------------------------------------------------
diff --git a/ant_on_air/src/AntClasses.as b/ant_on_air/src/AntClasses.as
index 4e7491c..d894c62 100644
--- a/ant_on_air/src/AntClasses.as
+++ b/ant_on_air/src/AntClasses.as
@@ -25,6 +25,7 @@ package
             import org.apache.flex.ant.Ant; Ant;
             import org.apache.flex.ant.tags.Project; Project;
             import org.apache.flex.ant.tags.Available; Available;
+            import org.apache.flex.ant.tags.Checksum; Checksum;
             import org.apache.flex.ant.tags.Condition; Condition;
             import org.apache.flex.ant.tags.Copy; Copy;
             import org.apache.flex.ant.tags.Delete; Delete;
@@ -33,11 +34,13 @@ package
             import org.apache.flex.ant.tags.FileSet; FileSet;
             import org.apache.flex.ant.tags.FileSetExclude; FileSetExclude;
             import org.apache.flex.ant.tags.FileSetInclude; FileSetInclude;
+            import org.apache.flex.ant.tags.Get; Get;
             import org.apache.flex.ant.tags.IsSet; IsSet;
             import org.apache.flex.ant.tags.Mkdir; Mkdir;
             import org.apache.flex.ant.tags.Not; Not;
             import org.apache.flex.ant.tags.OS; OS;
             import org.apache.flex.ant.tags.Property; Property;
+            import org.apache.flex.ant.tags.Unzip; Unzip;
         }
     }
 }
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/flex-utilities/blob/9dc5a00a/ant_on_air/src/org/apache/flex/ant/tags/Unzip.as
----------------------------------------------------------------------
diff --git a/ant_on_air/src/org/apache/flex/ant/tags/Unzip.as b/ant_on_air/src/org/apache/flex/ant/tags/Unzip.as
new file mode 100644
index 0000000..3424ea7
--- /dev/null
+++ b/ant_on_air/src/org/apache/flex/ant/tags/Unzip.as
@@ -0,0 +1,141 @@
+////////////////////////////////////////////////////////////////////////////////
+//
+//  Licensed to the Apache Software Foundation (ASF) under one or more
+//  contributor license agreements.  See the NOTICE file distributed with
+//  this work for additional information regarding copyright ownership.
+//  The ASF licenses this file to You under the Apache License, Version 2.0
+//  (the "License"); you may not use this file except in compliance with
+//  the License.  You may obtain a copy of the License at
+//
+//      http://www.apache.org/licenses/LICENSE-2.0
+//
+//  Unless required by applicable law or agreed to in writing, software
+//  distributed under the License is distributed on an "AS IS" BASIS,
+//  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+//  See the License for the specific language governing permissions and
+//  limitations under the License.
+//
+////////////////////////////////////////////////////////////////////////////////
+package org.apache.flex.ant.tags
+{
+    import flash.events.ErrorEvent;
+    import flash.events.Event;
+    import flash.filesystem.File;
+    import flash.filesystem.FileMode;
+    import flash.filesystem.FileStream;
+    import flash.utils.ByteArray;
+    
+    import mx.core.IFlexModuleFactory;
+    
+    import org.apache.flex.ant.Ant;
+    import org.apache.flex.ant.tags.supportClasses.TaskHandler;
+    import org.as3commons.zip.Zip;
+    import org.as3commons.zip.ZipEvent;
+    import org.as3commons.zip.ZipFile;
+    
+    [Mixin]
+    public class Unzip extends TaskHandler
+    {
+        public static function init(mf:IFlexModuleFactory):void
+        {
+            Ant.antTagProcessors["unzip"] = Unzip;
+        }
+
+        public function Unzip()
+        {
+            super();
+        }
+        
+        private var src:String;
+        private var dest:String;
+        private var overwrite:Boolean;
+        
+        override protected function processAttribute(name:String, value:String):void
+        {
+            if (name == "src")
+                src = value;
+            else if (name == "dest")
+                dest = value;
+            else if (name == "overwrite")
+                overwrite = value == "true";
+            else
+                super.processAttribute(name, value);
+        }
+        
+        private var destFile:File;
+        
+        override public function execute(callbackMode:Boolean):Boolean
+        {
+            super.execute(callbackMode);
+         
+            var srcFile:File = File.applicationDirectory.resolvePath(src);
+            destFile = File.applicationDirectory.resolvePath(dest);
+
+            unzip(srcFile);
+            return true;
+        }
+        
+        private function unzip(fileToUnzip:File):void {
+            var zipFileBytes:ByteArray = new ByteArray();
+            var fs:FileStream = new FileStream();
+            var fzip:Zip = new Zip();
+            
+            fs.open(fileToUnzip, FileMode.READ);
+            fs.readBytes(zipFileBytes);
+            fs.close();
+            
+            fzip.addEventListener(ZipEvent.FILE_LOADED, onFileLoaded);
+            fzip.addEventListener(Event.COMPLETE, onUnzipComplete, false, 0, true);
+            fzip.addEventListener(ErrorEvent.ERROR, onUnzipError, false, 0, true);
+
+            // synchronous, so no progress events
+            fzip.loadBytes(zipFileBytes);
+        }
+        
+        private function isDirectory(f:ZipFile):Boolean {
+            if (f.filename.substr(f.filename.length - 1) == "/" || f.filename.substr(f.filename.length
- 1) == "\\") {
+                return true;
+            }
+            return false;
+        }
+        
+        private function onFileLoaded(e:ZipEvent):void {
+            try {
+                var fzf:ZipFile = e.file;
+                var f:File = destFile.resolvePath(fzf.filename);
+                var fs:FileStream = new FileStream();
+                
+                if (isDirectory(fzf)) {
+                    // Is a directory, not a file. Dont try to write anything into it.
+                    return;
+                }
+                
+                fs.open(f, FileMode.WRITE);
+                fs.writeBytes(fzf.content);
+                fs.close();
+                
+            } catch (error:Error) {
+                if (failonerror)
+                    Ant.project.status = false;
+            }
+        }
+        
+        private function onUnzipComplete(event:Event):void {
+            var fzip:Zip = event.target as Zip;
+            fzip.close();
+            fzip.removeEventListener(ZipEvent.FILE_LOADED, onFileLoaded);
+            fzip.removeEventListener(Event.COMPLETE, onUnzipComplete);            
+            fzip.removeEventListener(ErrorEvent.ERROR, onUnzipError);            
+        }
+
+        private function onUnzipError(event:Event):void {
+            var fzip:Zip = event.target as Zip;
+            fzip.close();
+            fzip.removeEventListener(ZipEvent.FILE_LOADED, onFileLoaded);
+            fzip.removeEventListener(Event.COMPLETE, onUnzipComplete);            
+            fzip.removeEventListener(ErrorEvent.ERROR, onUnzipError);
+            if (failonerror)
+                Ant.project.status = false;
+        }
+    }
+}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/flex-utilities/blob/9dc5a00a/ant_on_air/tests/test.xml
----------------------------------------------------------------------
diff --git a/ant_on_air/tests/test.xml b/ant_on_air/tests/test.xml
index ba2b1a9..cb32a8d 100644
--- a/ant_on_air/tests/test.xml
+++ b/ant_on_air/tests/test.xml
@@ -107,6 +107,8 @@
         <checksum file="${basedir}/temp/apache-rat-0.10-src.zip" todir="${basedir}/temp"
             verifyproperty="rat.md5" />
         <echo>rat checksum match = ${rat.md5}</echo>
+        <mkdir dir="${basedir}/temp/unzip" />
+        <unzip src="${basedir}/temp/apache-rat-0.10-src.zip" dest="${basedir}/temp/unzip"
/>
         <delete dir="${basedir}/temp" />
         <available file="${basedir}/temp/org/apache/flex/ant/tags/Project.as" property="project.doesnt.exist.after.delete"
value="didn't get deleted" />
         <fail message="temp/copied.xml was not deleted">


Mime
View raw message