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/11 08:44:32 UTC
[3/3] git commit: [flex-utilities] [refs/heads/develop] - add untar
task
add untar 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/486673be
Tree: http://git-wip-us.apache.org/repos/asf/flex-utilities/tree/486673be
Diff: http://git-wip-us.apache.org/repos/asf/flex-utilities/diff/486673be
Branch: refs/heads/develop
Commit: 486673be7be5ddf94fe1798b26006e1245842739
Parents: ee94181
Author: Alex Harui <ah...@apache.org>
Authored: Tue Dec 10 23:43:48 2013 -0800
Committer: Alex Harui <ah...@apache.org>
Committed: Tue Dec 10 23:43:48 2013 -0800
----------------------------------------------------------------------
ant_on_air/src/AntClasses.as | 1 +
.../src/org/apache/flex/ant/tags/Untar.as | 124 +++++++++++++++++++
ant_on_air/tests/test.xml | 28 +++++
3 files changed, 153 insertions(+)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/flex-utilities/blob/486673be/ant_on_air/src/AntClasses.as
----------------------------------------------------------------------
diff --git a/ant_on_air/src/AntClasses.as b/ant_on_air/src/AntClasses.as
index d894c62..ddb6a65 100644
--- a/ant_on_air/src/AntClasses.as
+++ b/ant_on_air/src/AntClasses.as
@@ -40,6 +40,7 @@ package
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.Untar; Untar;
import org.apache.flex.ant.tags.Unzip; Unzip;
}
}
http://git-wip-us.apache.org/repos/asf/flex-utilities/blob/486673be/ant_on_air/src/org/apache/flex/ant/tags/Untar.as
----------------------------------------------------------------------
diff --git a/ant_on_air/src/org/apache/flex/ant/tags/Untar.as b/ant_on_air/src/org/apache/flex/ant/tags/Untar.as
new file mode 100644
index 0000000..a7a27f2
--- /dev/null
+++ b/ant_on_air/src/org/apache/flex/ant/tags/Untar.as
@@ -0,0 +1,124 @@
+////////////////////////////////////////////////////////////////////////////////
+//
+// 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.desktop.NativeProcess;
+ import flash.desktop.NativeProcessStartupInfo;
+ import flash.events.Event;
+ import flash.events.NativeProcessExitEvent;
+ import flash.events.ProgressEvent;
+ import flash.filesystem.File;
+ import flash.system.Capabilities;
+
+ import mx.core.IFlexModuleFactory;
+
+ import org.apache.flex.ant.Ant;
+ import org.apache.flex.ant.tags.supportClasses.TaskHandler;
+
+ [Mixin]
+ public class Untar extends TaskHandler
+ {
+ public static function init(mf:IFlexModuleFactory):void
+ {
+ Ant.antTagProcessors["untar"] = Untar;
+ }
+
+ public function Untar()
+ {
+ 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);
+
+ untar(srcFile);
+ return false;
+ }
+
+ private var _process:NativeProcess;
+
+ private function untar(source:File):void
+ {
+ var tar:File;
+ var startupInfo:NativeProcessStartupInfo = new NativeProcessStartupInfo();
+ var arguments:Vector.<String> = new Vector.<String>();
+
+ if (Capabilities.os.indexOf("Linux") != -1)
+ tar = new File("/bin/tar");
+ else
+ tar = new File("/usr/bin/tar");
+
+ arguments.push("xf");
+ arguments.push(source.nativePath);
+ arguments.push("-C");
+ arguments.push(destFile.nativePath);
+
+ startupInfo.executable = tar;
+ startupInfo.arguments = arguments;
+
+ _process = new NativeProcess();
+ _process.addEventListener(ProgressEvent.STANDARD_OUTPUT_DATA, unTarFileProgress);
+ _process.addEventListener(ProgressEvent.STANDARD_ERROR_DATA, unTarError);
+ _process.addEventListener(NativeProcessExitEvent.EXIT, unTarComplete);
+ _process.start(startupInfo);
+ }
+
+ private function unTarError(event:Event):void {
+ var output:String = _process.standardError.readUTFBytes(_process.standardError.bytesAvailable);
+ ant.output(output);
+ if (failonerror)
+ Ant.project.status = false;
+ dispatchEvent(new Event(Event.COMPLETE));
+ }
+
+ private function unTarFileProgress(event:Event):void {
+ var output:String = _process.standardOutput.readUTFBytes(_process.standardOutput.bytesAvailable);
+ ant.output(output);
+ }
+
+ private function unTarComplete(event:NativeProcessExitEvent):void {
+ _process.closeInput();
+ _process.exit(true);
+ dispatchEvent(new Event(Event.COMPLETE));
+ }
+
+ }
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/flex-utilities/blob/486673be/ant_on_air/tests/test.xml
----------------------------------------------------------------------
diff --git a/ant_on_air/tests/test.xml b/ant_on_air/tests/test.xml
index cb32a8d..73ab2de 100644
--- a/ant_on_air/tests/test.xml
+++ b/ant_on_air/tests/test.xml
@@ -42,6 +42,9 @@
<condition property="theOS" value="Mac">
<os family="mac"/>
</condition>
+ <condition property="isMac" value="Mac">
+ <os family="mac"/>
+ </condition>
<target name="test">
<echo>FLEX_HOME is ${FLEX_HOME}. DEBUG is ${DEBUG_FLAG}. The OS is ${theOS}</echo>
@@ -109,6 +112,31 @@
<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" />
+ <fail message="unzip did not result in expected files">
+ <condition>
+ <not>
+ <available file="${basedir}/temp/unzip/apache-rat-0.10/pom.xml" />
+ </not>
+ </condition>
+ </fail>
+ <get src="http://archive.apache.org/dist/creadur/apache-rat-0.10/apache-rat-0.10-src.tar.gz"
+ dest="${basedir}/temp" />
+ <fail message="apache-rat-0.10-src.tar.gz was not copied to temp">
+ <condition>
+ <not>
+ <available file="${basedir}/temp/apache-rat-0.10-src.tar.gz" />
+ </not>
+ </condition>
+ </fail>
+ <mkdir dir="${basedir}/temp/untar" />
+ <untar src="${basedir}/temp/apache-rat-0.10-src.tar.gz" dest="${basedir}/temp/untar" if="isMac" />
+ <fail message="untar did not result in expected files">
+ <condition>
+ <not>
+ <available file="${basedir}/temp/untar/apache-rat-0.10/pom.xml" />
+ </not>
+ </condition>
+ </fail>
<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">