http://git-wip-us.apache.org/repos/asf/flex-utilities/blob/f954e6f6/flex-installer/ant_on_air/src/org/apache/flex/ant/Ant.as ---------------------------------------------------------------------- diff --git a/flex-installer/ant_on_air/src/org/apache/flex/ant/Ant.as b/flex-installer/ant_on_air/src/org/apache/flex/ant/Ant.as new file mode 100644 index 0000000..42bb4f9 --- /dev/null +++ b/flex-installer/ant_on_air/src/org/apache/flex/ant/Ant.as @@ -0,0 +1,251 @@ +//////////////////////////////////////////////////////////////////////////////// +// +// 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 +{ + + import flash.events.Event; + import flash.filesystem.File; + import flash.filesystem.FileMode; + import flash.filesystem.FileStream; + + import org.apache.flex.ant.tags.Project; + import org.apache.flex.xml.XMLTagProcessor; + + /** + * An XMLTagProcessor that tries to emulate Apache Ant + */ + public class Ant extends XMLTagProcessor + { + /** + * Constructor + */ + public function Ant() + { + super(); + ant = this; + } + + /** + * @private + * The file being processed. Used to determine basedir. + */ + private var file:File; + + /** + * Open a file, read the XML, create ITagHandlers for every tag, then process them. + * When finished, check the project's status property. If it is true then all + * tasks completed successfully + * @param file File The file to open. + * @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, callbackMode:Boolean = true):Boolean + { + Ant.ants.push(this); + this.file = file; + var fs:FileStream = new FileStream(); + fs.open(file, FileMode.READ); + var s:String = fs.readUTFBytes(fs.bytesAvailable); + var xml:XML = XML(s); + fs.close(); + + tagMap = antTagProcessors; + if (!context) + context = {}; + this.context = context; + var project:Project = processXMLTag(xml) as Project; + var basedir:String = project.basedir; + if (basedir == "") + basedir = "."; + try { + basedir = file.parent.resolvePath(basedir).nativePath; + } + catch (e:Error) + { + ant.output(basedir); + ant.output(e.message); + ant.project.failureMessage = e.message; + ant.project.status = false; + return true; + } + + context.basedir = basedir; + this.project = project; + if (!project.execute(callbackMode, context)) + { + project.addEventListener(Event.COMPLETE, completeHandler); + return false; + } + if (Ant.ants.length > 1) + { + var status:Boolean = ant.project.status; + var failureMessage:String = ant.project.failureMessage; + Ant.ants.pop(); + if (!status) + { + currentAnt.project.status = status; + currentAnt.project.failureMessage = failureMessage; + } + } + return true; + } + + private var _functionToCall:Function; + + /** + * Set by various classes to defer processing in callbackMode + */ + public function set functionToCall(value:Function):void + { + if (parentAnt) + parentAnt.functionToCall = value; + else + _functionToCall = value; + } + + public function get functionToCall():Function + { + return _functionToCall; + } + + /** + * 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(); + } + } + + /** + * the instance of the class dispatching progress events + */ + public var progressClass:Object; + + private var context:Object; + public var parentAnt:Ant; + public var ant:Ant; + public var project:Project; + + // the stack of ant instances (ant can call <ant/>) + public static var ants:Array = []; + + public static function get currentAnt():Ant + { + if (ants.length == 0) + return null; + return ants[ants.length - 1] as Ant; + } + + private function completeHandler(event:Event):void + { + if (Ant.ants.length > 1) + { + var status:Boolean = ant.project.status; + var failureMessage:String = ant.project.failureMessage; + Ant.ants.pop(); + if (!status) + { + currentAnt.project.status = status; + currentAnt.project.failureMessage = failureMessage; + } + } + event.target.removeEventListener(Event.COMPLETE, completeHandler); + dispatchEvent(event); + } + + /** + * The map of XML tags to classes + */ + public static var antTagProcessors:Object = {}; + + /** + * Adds a class to the map. + * + * @param tagQName String The QName.toString() of the tag + * @param processor Class The class that will process the tag. + */ + public static function addTagProcessor(tagQName:String, processor:Class):void + { + antTagProcessors[tagQName] = processor; + } + + /** + * Does string replacements based on properties in the context object. + * + * @param input String The input string. + * @param context Object The object of property values. + * @return String The input string with replaced values. + */ + public function getValue(input:String, context:Object):String + { + var i:int = input.indexOf("${"); + while (i != -1) + { + if (i == 0 || (i > 0 && input.charAt(i - 1) != "$")) + { + var c:int = input.indexOf("}", i); + if (c != -1) + { + var token:String = input.substring(i + 2, c); + if (context.hasOwnProperty(token)) + { + var rep:String = context[token]; + input = input.replace("${" + token + "}", rep); + i += rep.length - token.length - 3; + } + } + } + else if (i > 0 && input.charAt(i - 1) == "$") + { + input = input.substring(0, i - 1) + input.substring(i); + i++; + } + i++; + i = input.indexOf("${", i); + } + return input; + } + + public static const spaces:String = " "; + + public function formatOutput(tag:String, data:String):String + { + var s:String = spaces.substr(0, Math.max(spaces.length - tag.length - 2, 0)) + + "[" + tag + "] " + data; + return s; + } + + public static function log(s:String, level:int):void + { + currentAnt.output(s); + } + + /** + * Output for Echo. Defaults to trace(). + */ + public var output:Function = function(s:String):void { trace(s) }; + + } +} \ No newline at end of file
http://git-wip-us.apache.org/repos/asf/flex-utilities/blob/f954e6f6/flex-installer/ant_on_air/src/org/apache/flex/ant/tags/And.as ---------------------------------------------------------------------- diff --git a/flex-installer/ant_on_air/src/org/apache/flex/ant/tags/And.as b/flex-installer/ant_on_air/src/org/apache/flex/ant/tags/And.as new file mode 100644 index 0000000..04c97c7 --- /dev/null +++ b/flex-installer/ant_on_air/src/org/apache/flex/ant/tags/And.as @@ -0,0 +1,61 @@ +//////////////////////////////////////////////////////////////////////////////// +// +// 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 mx.core.IFlexModuleFactory; + + import org.apache.flex.ant.Ant; + import org.apache.flex.ant.tags.supportClasses.IValueTagHandler; + import org.apache.flex.ant.tags.supportClasses.ParentTagHandler; + + [Mixin] + public class And extends ParentTagHandler implements IValueTagHandler + { + public static function init(mf:IFlexModuleFactory):void + { + Ant.antTagProcessors["and"] = And; + } + + public function And() + { + super(); + } + + public function getValue(context:Object):Object + { + ant.processChildren(xml, this); + if (numChildren > 0) + { + var n:int = numChildren; + for (var i:int = 0; i < n; i++) + { + var value:IValueTagHandler = getChildAt(i) as IValueTagHandler; + // get the value from the children + var val:Object = IValueTagHandler(value).getValue(context); + if (!(val == "true" || val == true)) + { + return false; + } + } + return true; + } + return false; + } + } +} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/flex-utilities/blob/f954e6f6/flex-installer/ant_on_air/src/org/apache/flex/ant/tags/AntCall.as ---------------------------------------------------------------------- diff --git a/flex-installer/ant_on_air/src/org/apache/flex/ant/tags/AntCall.as b/flex-installer/ant_on_air/src/org/apache/flex/ant/tags/AntCall.as new file mode 100644 index 0000000..6539260 --- /dev/null +++ b/flex-installer/ant_on_air/src/org/apache/flex/ant/tags/AntCall.as @@ -0,0 +1,80 @@ +//////////////////////////////////////////////////////////////////////////////// +// +// 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.Event; + + import mx.core.IFlexModuleFactory; + + import org.apache.flex.ant.Ant; + import org.apache.flex.ant.tags.supportClasses.TaskHandler; + + [Mixin] + public class AntCall extends TaskHandler + { + public static function init(mf:IFlexModuleFactory):void + { + Ant.antTagProcessors["antcall"] = AntCall; + } + + public function AntCall() + { + super(); + } + + private function get target():String + { + return getAttributeValue("@target"); + } + + override public function execute(callbackMode:Boolean, context:Object):Boolean + { + super.execute(callbackMode, context); + + // I think properties set in the sub-script to not affect the main script + // so clone the properties here + var subContext:Object = {}; + for (var p:String in context) + subContext[p] = context[p]; + + if (numChildren > 0) + { + for (var i:int = 0; i < numChildren; i++) + { + var param:Param = getChildAt(i) as Param; + param.setContext(context); + subContext[param.name] = param.value; + } + } + var t:Target = ant.project.getTarget(target); + if (!t.execute(callbackMode, subContext)) + { + t.addEventListener(Event.COMPLETE, completeHandler); + return false; + } + return true; + } + + private function completeHandler(event:Event):void + { + event.target.removeEventListener(Event.COMPLETE, completeHandler); + dispatchEvent(event); + } + } +} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/flex-utilities/blob/f954e6f6/flex-installer/ant_on_air/src/org/apache/flex/ant/tags/AntTask.as ---------------------------------------------------------------------- diff --git a/flex-installer/ant_on_air/src/org/apache/flex/ant/tags/AntTask.as b/flex-installer/ant_on_air/src/org/apache/flex/ant/tags/AntTask.as new file mode 100644 index 0000000..4c3b8cb --- /dev/null +++ b/flex-installer/ant_on_air/src/org/apache/flex/ant/tags/AntTask.as @@ -0,0 +1,140 @@ +//////////////////////////////////////////////////////////////////////////////// +// +// 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.Event; + import flash.events.KeyboardEvent; + import flash.events.ProgressEvent; + import flash.filesystem.File; + + import mx.core.IFlexModuleFactory; + + import org.apache.flex.ant.Ant; + import org.apache.flex.ant.tags.supportClasses.TaskHandler; + + [Mixin] + public class AntTask extends TaskHandler + { + public static function init(mf:IFlexModuleFactory):void + { + Ant.antTagProcessors["ant"] = AntTask; + } + + public function AntTask() + { + super(); + } + + private function get file():String + { + return getAttributeValue("@antfile"); + } + + private function get dir():String + { + return getAttributeValue("@dir"); + } + + private function get target():String + { + return getAttributeValue("@target"); + } + + private var subant:Ant; + + override public function execute(callbackMode:Boolean, context:Object):Boolean + { + super.execute(callbackMode, context); + + // I think properties set in the sub-script to not affect the main script + // so clone the properties here + var subContext:Object = {}; + for (var p:String in context) + subContext[p] = context[p]; + if (subContext.hasOwnProperty("targets")) + delete subContext["targets"]; + if (target) + subContext["targets"] = target; + + subant = new Ant(); + subant.parentAnt = ant; + subant.output = ant.output; + var file:File = File.applicationDirectory; + try { + file = file.resolvePath(dir + File.separator + this.file); + } + catch (e:Error) + { + ant.output(dir + File.separator + this.file); + ant.output(e.message); + if (failonerror) + { + ant.project.failureMessage = e.message; + ant.project.status = false; + } + return true; + } + + if (!subant.processXMLFile(file, subContext, true)) + { + subant.addEventListener("statusChanged", statusHandler); + subant.addEventListener(Event.COMPLETE, completeHandler); + subant.addEventListener(ProgressEvent.PROGRESS, progressEventHandler); + // redispatch keyboard events off of ant so input task can see them + ant.addEventListener(KeyboardEvent.KEY_DOWN, ant_keyDownHandler); + return false; + } + else + completeHandler(null); + return true; + } + + private function completeHandler(event:Event):void + { + event.target.removeEventListener("statusChanged", statusHandler); + event.target.removeEventListener(Event.COMPLETE, completeHandler); + event.target.removeEventListener(ProgressEvent.PROGRESS, progressEventHandler); + ant.removeEventListener(KeyboardEvent.KEY_DOWN, ant_keyDownHandler); + + dispatchEvent(event); + } + + private function statusHandler(event:Event):void + { + event.target.removeEventListener("statusChanged", statusHandler); + event.target.removeEventListener(Event.COMPLETE, completeHandler); + event.target.removeEventListener(ProgressEvent.PROGRESS, progressEventHandler); + ant.removeEventListener(KeyboardEvent.KEY_DOWN, ant_keyDownHandler); + ant.project.status = subant.project.status; + ant.project.failureMessage = subant.project.failureMessage; + dispatchEvent(new Event(Event.COMPLETE)); + } + + private function progressEventHandler(event:ProgressEvent):void + { + ant.dispatchEvent(event); + } + + private function ant_keyDownHandler(event:KeyboardEvent):void + { + subant.dispatchEvent(event); + } + + } +} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/flex-utilities/blob/f954e6f6/flex-installer/ant_on_air/src/org/apache/flex/ant/tags/Arg.as ---------------------------------------------------------------------- diff --git a/flex-installer/ant_on_air/src/org/apache/flex/ant/tags/Arg.as b/flex-installer/ant_on_air/src/org/apache/flex/ant/tags/Arg.as new file mode 100644 index 0000000..47abb6f --- /dev/null +++ b/flex-installer/ant_on_air/src/org/apache/flex/ant/tags/Arg.as @@ -0,0 +1,45 @@ +//////////////////////////////////////////////////////////////////////////////// +// +// 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 mx.core.IFlexModuleFactory; + + import org.apache.flex.ant.Ant; + import org.apache.flex.ant.tags.supportClasses.TagHandler; + + [Mixin] + public class Arg extends TagHandler + { + public static function init(mf:IFlexModuleFactory):void + { + Ant.antTagProcessors["arg"] = Arg; + } + + public function Arg() + { + super(); + } + + public function get value():String + { + return getAttributeValue("@value"); + } + + } +} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/flex-utilities/blob/f954e6f6/flex-installer/ant_on_air/src/org/apache/flex/ant/tags/Available.as ---------------------------------------------------------------------- diff --git a/flex-installer/ant_on_air/src/org/apache/flex/ant/tags/Available.as b/flex-installer/ant_on_air/src/org/apache/flex/ant/tags/Available.as new file mode 100644 index 0000000..b606b8a --- /dev/null +++ b/flex-installer/ant_on_air/src/org/apache/flex/ant/tags/Available.as @@ -0,0 +1,99 @@ +//////////////////////////////////////////////////////////////////////////////// +// +// 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.filesystem.File; + + import mx.core.IFlexModuleFactory; + + import org.apache.flex.ant.Ant; + import org.apache.flex.ant.tags.supportClasses.IValueTagHandler; + import org.apache.flex.ant.tags.supportClasses.TaskHandler; + + [Mixin] + public class Available extends TaskHandler implements IValueTagHandler + { + public static function init(mf:IFlexModuleFactory):void + { + Ant.antTagProcessors["available"] = Available; + } + + public function Available() + { + super(); + } + + private function get file():String + { + return getNullOrAttributeValue("@file"); + } + + private function get type():String + { + return getNullOrAttributeValue("@type"); + } + + private function get property():String + { + return getNullOrAttributeValue("@property"); + } + + private function get value():String + { + return getNullOrAttributeValue("@value"); + } + + public function getValue(context:Object):Object + { + this.context = context; + + if (this.file == null) return false; + + try + { + var file:File = new File(this.file); + } + catch (e:Error) + { + return false; + } + + if (!file.exists) + return false; + + if (type == "dir" && !file.isDirectory) + return false; + + return true; + } + + override public function execute(callbackMode:Boolean, context:Object):Boolean + { + super.execute(callbackMode, context); + var avail:Object = getValue(context); + if (avail) + { + if (!context.hasOwnProperty(property)) + context[property] = value != null ? value : true; + } + return true; + } + + } +} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/flex-utilities/blob/f954e6f6/flex-installer/ant_on_air/src/org/apache/flex/ant/tags/Checksum.as ---------------------------------------------------------------------- diff --git a/flex-installer/ant_on_air/src/org/apache/flex/ant/tags/Checksum.as b/flex-installer/ant_on_air/src/org/apache/flex/ant/tags/Checksum.as new file mode 100644 index 0000000..5df7ee7 --- /dev/null +++ b/flex-installer/ant_on_air/src/org/apache/flex/ant/tags/Checksum.as @@ -0,0 +1,218 @@ +//////////////////////////////////////////////////////////////////////////////// +// +// 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 org.apache.flex.crypto.MD5Stream; + + import flash.events.Event; + import flash.events.ProgressEvent; + import flash.filesystem.File; + import flash.filesystem.FileMode; + import flash.filesystem.FileStream; + import flash.utils.ByteArray; + + import mx.core.IFlexModuleFactory; + import mx.utils.StringUtil; + + import org.apache.flex.ant.Ant; + import org.apache.flex.ant.tags.supportClasses.TaskHandler; + + [Mixin] + public class Checksum extends TaskHandler + { + private static var DEFAULT_READBUFFER_SIZE:int = 2 * 1024 * 1024; + + public static function init(mf:IFlexModuleFactory):void + { + Ant.antTagProcessors["checksum"] = Checksum; + } + + public function Checksum() + { + super(); + } + + private function get file():String + { + return getAttributeValue("@file"); + } + + private function get toDir():String + { + return getNullOrAttributeValue("@todir"); + } + + private function get fileExt():String + { + var val:String = getNullOrAttributeValue("@fileext"); + return val == null ? ".md5" : val; + } + + private function get property():String + { + return getNullOrAttributeValue("@property"); + } + + private function get verifyproperty():String + { + return getNullOrAttributeValue("@verifyproperty"); + } + + private function get readbuffersize():int + { + var val:String = getNullOrAttributeValue("@readbuffersize"); + return val == null ? DEFAULT_READBUFFER_SIZE : int(val); + } + + private var md5:MD5Stream; + private var fs:FileStream; + private var totalLength:int; + + override public function execute(callbackMode:Boolean, context:Object):Boolean + { + super.execute(callbackMode, context); + + try { + var f:File = File.applicationDirectory.resolvePath(this.file); + } + catch (e:Error) + { + ant.output(this.file); + ant.output(e.message); + if (failonerror) + { + ant.project.failureMessage = e.message; + ant.project.status = false; + } + dispatchEvent(new Event(Event.COMPLETE)); + return true; + } + + if (!f.exists) + return true; + + fs = new FileStream(); + fs.open(f, FileMode.READ); + totalLength = fs.bytesAvailable; + md5 = new MD5Stream(); + md5.resetFields(); + return getSum(); + } + + private function getSum():Boolean + { + if (fs.bytesAvailable < DEFAULT_READBUFFER_SIZE) + { + sumComplete(); + return true; + } + md5.update(fs, DEFAULT_READBUFFER_SIZE); + ant.functionToCall = getSum; + ant.progressClass = this; + ant.dispatchEvent(new ProgressEvent(ProgressEvent.PROGRESS, false, false, + fs.position, fs.position + fs.bytesAvailable)); + return false; + } + + private var sum:String; + + private function sumComplete():void + { + sum = md5.complete(fs, totalLength); + fs.close(); + if (verifyproperty && property) + { + if (sum == property) + context[verifyproperty] = "true"; + else + context[verifyproperty] = "false"; + } + else if (!toDir && property) + { + context[property] = sum; + } + else + { + var sumFile:File = getSumFile(); + if (sumFile) + { + var fs:FileStream = new FileStream(); + if (verifyproperty) + { + fs.open(sumFile, FileMode.READ); + var expected:String = fs.readUTFBytes(fs.bytesAvailable); + expected = StringUtil.trim(expected); + fs.close(); + if (sum != expected) + context[verifyproperty != null ? verifyproperty : property] = "false"; + else + context[verifyproperty != null ? verifyproperty : property] = "true"; + } + else + { + fs.open(sumFile, FileMode.WRITE); + fs.writeUTFBytes(sum); + fs.close(); + } + } + } + ant.dispatchEvent(new ProgressEvent(ProgressEvent.PROGRESS, false, false, + totalLength, totalLength)); + dispatchEvent(new Event(Event.COMPLETE)); + } + + private function getSumFile():File + { + try { + var sumFile:File; + if (toDir) + sumFile = File.applicationDirectory.resolvePath(toDir); + else + { + var f:File = File.applicationDirectory.resolvePath(this.file); + sumFile = f.parent; + } + } + catch (e:Error) + { + ant.output(toDir); + ant.output(e.message); + if (failonerror) + { + ant.project.failureMessage = e.message; + ant.project.status = false; + } + return null; + } + + if (sumFile.isDirectory) + { + var fileName:String = file + fileExt; + var c:int = fileName.indexOf("?"); + if (c != -1) + fileName = fileName.substring(0, c); + c = fileName.lastIndexOf("/"); + if (c != -1) + fileName = fileName.substr(c + 1); + sumFile = sumFile.resolvePath(fileName); + } + return sumFile; + } + } +} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/flex-utilities/blob/f954e6f6/flex-installer/ant_on_air/src/org/apache/flex/ant/tags/Condition.as ---------------------------------------------------------------------- diff --git a/flex-installer/ant_on_air/src/org/apache/flex/ant/tags/Condition.as b/flex-installer/ant_on_air/src/org/apache/flex/ant/tags/Condition.as new file mode 100644 index 0000000..9fe9063 --- /dev/null +++ b/flex-installer/ant_on_air/src/org/apache/flex/ant/tags/Condition.as @@ -0,0 +1,78 @@ +//////////////////////////////////////////////////////////////////////////////// +// +// 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 mx.core.IFlexModuleFactory; + + import org.apache.flex.ant.Ant; + import org.apache.flex.ant.tags.supportClasses.IValueTagHandler; + import org.apache.flex.ant.tags.supportClasses.TaskHandler; + + [Mixin] + + public class Condition extends TaskHandler + { + public static function init(mf:IFlexModuleFactory):void + { + Ant.antTagProcessors["condition"] = Condition; + } + + public function Condition() + { + super(); + } + + override public function execute(callbackMode:Boolean, context:Object):Boolean + { + super.execute(callbackMode, context); + + // if the property is not already set + if (property && !context.hasOwnProperty(property)) + { + var val:Object = computedValue; + if (val == "true" || val == true) + { + // set it if we should + if (value != null) + val = value; + context[property] = val; + } + } + return true; + } + + public function get computedValue():Object + { + // get the value from the children + var val:Object = IValueTagHandler(getChildAt(0)).getValue(context); + return val; + } + + private function get property():String + { + return getNullOrAttributeValue("@property"); + } + + private function get value():Object + { + return getNullOrAttributeValue("@value"); + } + + } +} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/flex-utilities/blob/f954e6f6/flex-installer/ant_on_air/src/org/apache/flex/ant/tags/Contains.as ---------------------------------------------------------------------- diff --git a/flex-installer/ant_on_air/src/org/apache/flex/ant/tags/Contains.as b/flex-installer/ant_on_air/src/org/apache/flex/ant/tags/Contains.as new file mode 100644 index 0000000..64f8738 --- /dev/null +++ b/flex-installer/ant_on_air/src/org/apache/flex/ant/tags/Contains.as @@ -0,0 +1,58 @@ +//////////////////////////////////////////////////////////////////////////////// +// +// 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 mx.core.IFlexModuleFactory; + + import org.apache.flex.ant.Ant; + import org.apache.flex.ant.tags.supportClasses.IValueTagHandler; + import org.apache.flex.ant.tags.supportClasses.TagHandler; + + [Mixin] + public class Contains extends TagHandler implements IValueTagHandler + { + public static function init(mf:IFlexModuleFactory):void + { + Ant.antTagProcessors["contains"] = Contains; + } + + public function Contains() + { + super(); + } + + private function get string():String + { + return getAttributeValue("@string"); + } + + private function get substring():String + { + return getAttributeValue("@substring"); + } + + public function getValue(context:Object):Object + { + this.context = context; + var pat:String = substring; + return string.indexOf(substring) != -1; + } + + } +} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/flex-utilities/blob/f954e6f6/flex-installer/ant_on_air/src/org/apache/flex/ant/tags/Copy.as ---------------------------------------------------------------------- diff --git a/flex-installer/ant_on_air/src/org/apache/flex/ant/tags/Copy.as b/flex-installer/ant_on_air/src/org/apache/flex/ant/tags/Copy.as new file mode 100644 index 0000000..0cdd755 --- /dev/null +++ b/flex-installer/ant_on_air/src/org/apache/flex/ant/tags/Copy.as @@ -0,0 +1,253 @@ +//////////////////////////////////////////////////////////////////////////////// +// +// 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.Event; + import flash.filesystem.File; + + import mx.core.IFlexModuleFactory; + import mx.resources.ResourceManager; + + import org.apache.flex.ant.Ant; + import org.apache.flex.ant.tags.supportClasses.FileSetTaskHandler; + import org.apache.flex.xml.ITagHandler; + + [ResourceBundle("ant")] + [Mixin] + public class Copy extends FileSetTaskHandler + { + public static function init(mf:IFlexModuleFactory):void + { + Ant.antTagProcessors["copy"] = Copy; + } + + public function Copy() + { + super(); + } + + private function get fileName():String + { + return getAttributeValue("@file"); + } + + private function get toFileName():String + { + var val:String = getNullOrAttributeValue("@toFile"); + if (val != null) + return val; + return getNullOrAttributeValue("@tofile"); + + } + + private function get toDirName():String + { + return getAttributeValue("@todir"); + } + + private function get overwrite():Boolean + { + return getAttributeValue("@overwrite") == "true"; + } + + private var mapper:GlobMapper; + + private function mapFileName(name:String):String + { + var from:String = mapper.from; + if (from.indexOf(".*") == -1) + from = from.replace("*", ".*"); + var regex:RegExp = new RegExp(from); + var results:Array = name.match(regex); + if (results && results.length == 1) + { + name = mapper.to.replace("*", results[0]); + return name; + } + return null; + } + + private var searchedForMapper:Boolean; + + override protected function actOnFile(dir:String, fileName:String):void + { + if (!searchedForMapper) + { + // look for a mapper + for (var i:int = 0; i < numChildren; i++) + { + var child:ITagHandler = getChildAt(i); + if (child is GlobMapper) + { + mapper = child as GlobMapper; + mapper.setContext(context); + break; + } + } + searchedForMapper = true; + } + + var srcName:String; + if (dir) + srcName = dir + File.separator + fileName; + else + srcName = fileName; + try { + var srcFile:File = File.applicationDirectory.resolvePath(srcName); + } + catch (e:Error) + { + ant.output(srcName); + ant.output(e.message); + if (failonerror) + { + ant.project.failureMessage = e.message; + ant.project.status = false; + } + return; + } + + + if (mapper) + { + fileName = mapFileName(fileName); + if (fileName == null) + return; + } + + var destName:String; + if (toDirName) + destName = toDirName + File.separator + fileName; + else + destName = toFileName; + try { + var destFile:File = File.applicationDirectory.resolvePath(destName); + } + catch (e:Error) + { + ant.output(destName); + ant.output(e.message); + if (failonerror) + { + ant.project.failureMessage = e.message; + ant.project.status = false; + } + return; + } + + try { + srcFile.copyTo(destFile, overwrite); + } + catch (e:Error) + { + ant.output(destName); + ant.output(e.message); + if (failonerror) + { + ant.project.failureMessage = e.message; + ant.project.status = false; + } + return; + } + } + + override protected function outputTotal(total:int):void + { + var s:String = ResourceManager.getInstance().getString('ant', 'COPYFILES'); + s = s.replace("%1", total.toString()); + s = s.replace("%2", toDirName); + ant.output(ant.formatOutput("copy", s)); + } + + private var srcFile:File; + private var destFile:File; + + override public function execute(callbackMode:Boolean, context:Object):Boolean + { + var retVal:Boolean = super.execute(callbackMode, context); + if (numChildren > 0) + return retVal; + + try { + srcFile = File.applicationDirectory.resolvePath(fileName); + } + catch (e:Error) + { + ant.output(fileName); + ant.output(e.message); + if (failonerror) + { + ant.project.failureMessage = e.message; + ant.project.status = false; + } + return true; + } + + try { + destFile = File.applicationDirectory.resolvePath(toFileName); + } + catch (e:Error) + { + ant.output(toFileName); + ant.output(e.message); + if (failonerror) + { + ant.project.failureMessage = e.message; + ant.project.status = false; + } + return true; + } + + //var destDir:File = destFile.parent; + //var resolveName:String = destFile.nativePath.substr(destFile.nativePath.lastIndexOf(File.separator) + 1); + //destDir.resolvePath(resolveName); + + var s:String = ResourceManager.getInstance().getString('ant', 'COPY'); + s = s.replace("%1", "1"); + s = s.replace("%2", destFile.nativePath); + ant.output(ant.formatOutput("copy", s)); + if (callbackMode) + { + ant.functionToCall = doCopy; + return false; + } + + try { + doCopy(); + } + catch (e:Error) + { + ant.output(toFileName); + ant.output(e.message); + if (failonerror) + { + ant.project.failureMessage = e.message; + ant.project.status = false; + } + } + return true; + } + + protected function doCopy():void + { + srcFile.copyTo(destFile, overwrite); + dispatchEvent(new Event(Event.COMPLETE)); + } + } +} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/flex-utilities/blob/f954e6f6/flex-installer/ant_on_air/src/org/apache/flex/ant/tags/Delete.as ---------------------------------------------------------------------- diff --git a/flex-installer/ant_on_air/src/org/apache/flex/ant/tags/Delete.as b/flex-installer/ant_on_air/src/org/apache/flex/ant/tags/Delete.as new file mode 100644 index 0000000..2c4cbae --- /dev/null +++ b/flex-installer/ant_on_air/src/org/apache/flex/ant/tags/Delete.as @@ -0,0 +1,137 @@ +//////////////////////////////////////////////////////////////////////////////// +// +// 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.filesystem.File; + + import mx.core.IFlexModuleFactory; + import mx.resources.ResourceManager; + + import org.apache.flex.ant.Ant; + import org.apache.flex.ant.tags.supportClasses.FileSetTaskHandler; + + [ResourceBundle("ant")] + [Mixin] + public class Delete extends FileSetTaskHandler + { + public static function init(mf:IFlexModuleFactory):void + { + Ant.antTagProcessors["delete"] = Delete; + } + + public function Delete() + { + super(); + } + + private function get fileName():String + { + return getAttributeValue("@file"); + } + + private function get dirName():String + { + return getAttributeValue("@dir"); + } + + override protected function actOnFile(dir:String, fileName:String):void + { + var srcName:String; + if (dir) + srcName = dir + File.separator + fileName; + else + srcName = fileName; + try { + var delFile:File = File.applicationDirectory.resolvePath(srcName); + } + catch (e:Error) + { + ant.output(fileName); + ant.output(e.message); + if (failonerror) + { + ant.project.failureMessage = e.message; + ant.project.status = false; + } + return; + } + + if (delFile.isDirectory) + delFile.deleteDirectory(true); + else + delFile.deleteFile(); + } + + override public function execute(callbackMode:Boolean, context:Object):Boolean + { + var retVal:Boolean = super.execute(callbackMode, context); + if (numChildren > 0) + return retVal; + + var s:String; + + if (fileName) + { + try { + var delFile:File = File.applicationDirectory.resolvePath(fileName); + } + catch (e:Error) + { + ant.output(fileName); + ant.output(e.message); + if (failonerror) + { + ant.project.failureMessage = e.message; + ant.project.status = false; + } + return true; + } + + s = ResourceManager.getInstance().getString('ant', 'DELETEFILE'); + s = s.replace("%1", delFile.nativePath); + ant.output(ant.formatOutput("delete", s)); + delFile.deleteFile(); + } + else if (dirName) + { + try { + var delDir:File = File.applicationDirectory.resolvePath(dirName); + } + catch (e:Error) + { + ant.output(fileName); + ant.output(e.message); + if (failonerror) + { + ant.project.failureMessage = e.message; + ant.project.status = false; + } + return true; + } + + s = ResourceManager.getInstance().getString('ant', 'DELETEDIR'); + s = s.replace("%1", delDir.nativePath); + ant.output(ant.formatOutput("delete", s)); + delDir.deleteDirectory(true); + } + return true; + } + + } +} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/flex-utilities/blob/f954e6f6/flex-installer/ant_on_air/src/org/apache/flex/ant/tags/Echo.as ---------------------------------------------------------------------- diff --git a/flex-installer/ant_on_air/src/org/apache/flex/ant/tags/Echo.as b/flex-installer/ant_on_air/src/org/apache/flex/ant/tags/Echo.as new file mode 100644 index 0000000..9493e2c --- /dev/null +++ b/flex-installer/ant_on_air/src/org/apache/flex/ant/tags/Echo.as @@ -0,0 +1,93 @@ +//////////////////////////////////////////////////////////////////////////////// +// +// 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.filesystem.File; + import flash.filesystem.FileMode; + import flash.filesystem.FileStream; + + import mx.core.IFlexModuleFactory; + + import org.apache.flex.ant.Ant; + import org.apache.flex.ant.tags.supportClasses.TaskHandler; + import org.apache.flex.xml.ITextTagHandler; + + [Mixin] + public class Echo extends TaskHandler implements ITextTagHandler + { + public static function init(mf:IFlexModuleFactory):void + { + Ant.antTagProcessors["echo"] = Echo; + } + + public function Echo() + { + super(); + } + + private var _text:String; + + private function get text():String + { + if (_text != null) + return _text; + + return getAttributeValue("@message"); + } + private function get fileName():String + { + return getNullOrAttributeValue("@file"); + } + + public function setText(text:String):void + { + _text = text; + } + + override public function execute(callbackMode:Boolean, context:Object):Boolean + { + super.execute(callbackMode, context); + if (fileName != null) + { + try { + var f:File = new File(fileName); + } + catch (e:Error) + { + ant.output(fileName); + ant.output(e.message); + if (failonerror) + { + ant.project.failureMessage = e.message; + ant.project.status = false; + } + return true; + } + + var fs:FileStream = new FileStream(); + fs.open(f, FileMode.WRITE); + fs.writeUTFBytes(ant.getValue(text, context)); + fs.close(); + } + else + ant.output(ant.formatOutput("echo", ant.getValue(text, context))); + return true; + } + } +} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/flex-utilities/blob/f954e6f6/flex-installer/ant_on_air/src/org/apache/flex/ant/tags/Entry.as ---------------------------------------------------------------------- diff --git a/flex-installer/ant_on_air/src/org/apache/flex/ant/tags/Entry.as b/flex-installer/ant_on_air/src/org/apache/flex/ant/tags/Entry.as new file mode 100644 index 0000000..7f56457 --- /dev/null +++ b/flex-installer/ant_on_air/src/org/apache/flex/ant/tags/Entry.as @@ -0,0 +1,50 @@ +//////////////////////////////////////////////////////////////////////////////// +// +// 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 mx.core.IFlexModuleFactory; + + import org.apache.flex.ant.Ant; + import org.apache.flex.ant.tags.supportClasses.TagHandler; + + [Mixin] + public class Entry extends TagHandler + { + public static function init(mf:IFlexModuleFactory):void + { + Ant.antTagProcessors["entry"] = Entry; + } + + public function Entry() + { + super(); + } + + public function get key():String + { + return getAttributeValue("@key"); + } + + public function get value():String + { + return getNullOrAttributeValue("@value"); + } + + } +} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/flex-utilities/blob/f954e6f6/flex-installer/ant_on_air/src/org/apache/flex/ant/tags/Equals.as ---------------------------------------------------------------------- diff --git a/flex-installer/ant_on_air/src/org/apache/flex/ant/tags/Equals.as b/flex-installer/ant_on_air/src/org/apache/flex/ant/tags/Equals.as new file mode 100644 index 0000000..2ff7dc1 --- /dev/null +++ b/flex-installer/ant_on_air/src/org/apache/flex/ant/tags/Equals.as @@ -0,0 +1,80 @@ +//////////////////////////////////////////////////////////////////////////////// +// +// 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 mx.core.IFlexModuleFactory; + import mx.utils.StringUtil; + + import org.apache.flex.ant.Ant; + import org.apache.flex.ant.tags.supportClasses.IValueTagHandler; + import org.apache.flex.ant.tags.supportClasses.TagHandler; + + [Mixin] + public class Equals extends TagHandler implements IValueTagHandler + { + public static function init(mf:IFlexModuleFactory):void + { + Ant.antTagProcessors["equals"] = Equals; + } + + public function Equals() + { + super(); + } + + private function get arg1():String + { + return getAttributeValue("@arg1"); + } + + private function get arg2():String + { + return getAttributeValue("@arg2"); + } + + private function get casesensitive():Boolean + { + return getAttributeValue("@casesensitive") == "true"; + } + + private function get trim():Boolean + { + return getAttributeValue("@trim") == "true"; + } + + public function getValue(context:Object):Object + { + this.context = context; + var val1:String = arg1; + var val2:String = arg2; + if (casesensitive) + { + val1 = val1.toLowerCase(); + val2 = val2.toLowerCase(); + } + if (trim) + { + val1 = StringUtil.trim(val1 as String); + val2 = StringUtil.trim(val2 as String); + } + return val1 == val2; + } + + } +} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/flex-utilities/blob/f954e6f6/flex-installer/ant_on_air/src/org/apache/flex/ant/tags/Exec.as ---------------------------------------------------------------------- diff --git a/flex-installer/ant_on_air/src/org/apache/flex/ant/tags/Exec.as b/flex-installer/ant_on_air/src/org/apache/flex/ant/tags/Exec.as new file mode 100644 index 0000000..bc503a6 --- /dev/null +++ b/flex-installer/ant_on_air/src/org/apache/flex/ant/tags/Exec.as @@ -0,0 +1,161 @@ +//////////////////////////////////////////////////////////////////////////////// +// +// 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 flash.utils.IDataInput; + + import mx.core.IFlexModuleFactory; + import mx.utils.StringUtil; + + import org.apache.flex.ant.Ant; + import org.apache.flex.ant.tags.supportClasses.TaskHandler; + + [Mixin] + public class Exec extends TaskHandler + { + public static function init(mf:IFlexModuleFactory):void + { + Ant.antTagProcessors["exec"] = Exec; + } + + public function Exec() + { + } + + override public function execute(callbackMode:Boolean, context:Object):Boolean + { + super.execute(callbackMode, context); + + var thisOS:String = Capabilities.os.toLowerCase(); + var osArr:Array = osFamily.split(","); + var ok:Boolean = false; + for each (var p:String in osArr) + { + if (p.toLowerCase() == "windows") + p = "win"; + if (thisOS.indexOf(p.toLowerCase()) != -1) + { + ok = true; + break; + } + } + if (!ok) return true; + + var file:File = File.applicationDirectory; + if (Capabilities.os.toLowerCase().indexOf('win') == -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.toLowerCase().indexOf('win') == -1) + args.push("-c"); + else + args.push("/c"); + if (numChildren > 0) + { + var cmdline:String = fileName; + for (var i:int = 0; i < numChildren; i++) + { + var arg:Arg = getChildAt(i) as Arg; + arg.setContext(context); + cmdline += " " + quoteIfNeeded(arg.value); + } + args.push(cmdline); + } + else + args.push(fileName); + nativeProcessStartupInfo.arguments = args; + if (dir) + { + var wd:File; + wd = File.applicationDirectory; + wd = wd.resolvePath(dir); + nativeProcessStartupInfo.workingDirectory = wd; + } + + 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); + + return false; + } + + private function get dir():String + { + return getNullOrAttributeValue("@dir"); + } + + private function get fileName():String + { + return getAttributeValue("@executable"); + } + + private function get osFamily():String + { + return getAttributeValue("@osfamily"); + } + + private function get outputProperty():String + { + return getAttributeValue("@outputproperty"); + } + + private var process:NativeProcess; + + private function exitHandler(event:NativeProcessExitEvent):void + { + dispatchEvent(new Event(Event.COMPLETE)); + } + + private function onOutputErrorData(event:ProgressEvent):void + { + var stdError:IDataInput = process.standardError; + var data:String = stdError.readUTFBytes(process.standardError.bytesAvailable); + trace("Got Error Output: ", data); + } + + private function onOutputData(event:ProgressEvent):void + { + var stdOut:IDataInput = process.standardOutput; + var data:String = stdOut.readUTFBytes(process.standardOutput.bytesAvailable); + trace("Got: ", data); + if (outputProperty) + context[outputProperty] = StringUtil.trim(data); + } + + private function quoteIfNeeded(s:String):String + { + // has spaces but no quotes + if (s.indexOf(" ") != -1 && s.indexOf('"') == -1) + return '"' + s + '"'; + return s; + } + } +} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/flex-utilities/blob/f954e6f6/flex-installer/ant_on_air/src/org/apache/flex/ant/tags/Fail.as ---------------------------------------------------------------------- diff --git a/flex-installer/ant_on_air/src/org/apache/flex/ant/tags/Fail.as b/flex-installer/ant_on_air/src/org/apache/flex/ant/tags/Fail.as new file mode 100644 index 0000000..6dd9b30 --- /dev/null +++ b/flex-installer/ant_on_air/src/org/apache/flex/ant/tags/Fail.as @@ -0,0 +1,78 @@ +//////////////////////////////////////////////////////////////////////////////// +// +// 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 mx.core.IFlexModuleFactory; + + import org.apache.flex.ant.Ant; + import org.apache.flex.ant.tags.supportClasses.TaskHandler; + + [Mixin] + public class Fail extends TaskHandler + { + public static function init(mf:IFlexModuleFactory):void + { + Ant.antTagProcessors["fail"] = Fail; + } + + public function Fail() + { + super(); + } + + private var _text:String; + private function get text():String + { + if (_text != null) + return _text; + + return getAttributeValue("@message"); + } + + public function setText(text:String):void + { + _text = text; + } + + override public function execute(callbackMode:Boolean, context:Object):Boolean + { + super.execute(callbackMode, context); + if (numChildren == 1) + { + var child:Condition = getChildAt(0) as Condition; + if (child) + { + child.execute(false, context); + var val:Object = child.computedValue; + if (!(val == "true" || val == true)) + { + return true; + } + } + } + if (text) + { + ant.output(ant.getValue(text, context)); + ant.project.failureMessage = ant.getValue(text, context); + } + ant.project.status = false; + return true; + } + } +} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/flex-utilities/blob/f954e6f6/flex-installer/ant_on_air/src/org/apache/flex/ant/tags/FileSet.as ---------------------------------------------------------------------- diff --git a/flex-installer/ant_on_air/src/org/apache/flex/ant/tags/FileSet.as b/flex-installer/ant_on_air/src/org/apache/flex/ant/tags/FileSet.as new file mode 100644 index 0000000..41f80d5 --- /dev/null +++ b/flex-installer/ant_on_air/src/org/apache/flex/ant/tags/FileSet.as @@ -0,0 +1,81 @@ +//////////////////////////////////////////////////////////////////////////////// +// +// 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 mx.core.IFlexModuleFactory; + + import org.apache.flex.ant.Ant; + import org.apache.flex.ant.tags.filesetClasses.DirectoryScanner; + import org.apache.flex.ant.tags.filesetClasses.exceptions.BuildException; + import org.apache.flex.ant.tags.supportClasses.IValueTagHandler; + import org.apache.flex.ant.tags.supportClasses.NamedTagHandler; + import org.apache.flex.ant.tags.supportClasses.ParentTagHandler; + + [Mixin] + public class FileSet extends ParentTagHandler implements IValueTagHandler + { + public static function init(mf:IFlexModuleFactory):void + { + Ant.antTagProcessors["fileset"] = FileSet; + } + + public function FileSet() + { + super(); + } + + public function get dir():String + { + return getNullOrAttributeValue("@dir"); + } + + private var _value:Vector.<String>; + + public function getValue(context:Object):Object + { + if (_value) return _value; + this.context = context; + + ant.processChildren(xml, this); + var ds:DirectoryScanner = new DirectoryScanner(); + var n:int = numChildren; + var includes:Vector.<String> = new Vector.<String>(); + var excludes:Vector.<String> = new Vector.<String>(); + for (var i:int = 0; i < n; i++) + { + var tag:NamedTagHandler = getChildAt(i) as NamedTagHandler; + tag.setContext(context); + if (tag is FileSetInclude) + includes.push(tag.name); + else if (tag is FileSetExclude) + excludes.push(tag.name); + else + throw new BuildException("Unsupported Tag at index " + i); + } + ds.setIncludes(includes); + ds.setExcludes(excludes); + if (dir != null) + ds.setBasedir(dir); + ds.scan(); + _value = ds.getIncludedFiles(); + return _value; + } + + } +} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/flex-utilities/blob/f954e6f6/flex-installer/ant_on_air/src/org/apache/flex/ant/tags/FileSetExclude.as ---------------------------------------------------------------------- diff --git a/flex-installer/ant_on_air/src/org/apache/flex/ant/tags/FileSetExclude.as b/flex-installer/ant_on_air/src/org/apache/flex/ant/tags/FileSetExclude.as new file mode 100644 index 0000000..e2c0f02 --- /dev/null +++ b/flex-installer/ant_on_air/src/org/apache/flex/ant/tags/FileSetExclude.as @@ -0,0 +1,40 @@ +//////////////////////////////////////////////////////////////////////////////// +// +// 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 mx.core.IFlexModuleFactory; + + import org.apache.flex.ant.Ant; + import org.apache.flex.ant.tags.supportClasses.NamedTagHandler; + + [Mixin] + public class FileSetExclude extends NamedTagHandler + { + public static function init(mf:IFlexModuleFactory):void + { + Ant.antTagProcessors["exclude"] = FileSetExclude; + } + + public function FileSetExclude() + { + super(); + } + + } +} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/flex-utilities/blob/f954e6f6/flex-installer/ant_on_air/src/org/apache/flex/ant/tags/FileSetInclude.as ---------------------------------------------------------------------- diff --git a/flex-installer/ant_on_air/src/org/apache/flex/ant/tags/FileSetInclude.as b/flex-installer/ant_on_air/src/org/apache/flex/ant/tags/FileSetInclude.as new file mode 100644 index 0000000..8c6f98f --- /dev/null +++ b/flex-installer/ant_on_air/src/org/apache/flex/ant/tags/FileSetInclude.as @@ -0,0 +1,40 @@ +//////////////////////////////////////////////////////////////////////////////// +// +// 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 mx.core.IFlexModuleFactory; + + import org.apache.flex.ant.Ant; + import org.apache.flex.ant.tags.supportClasses.NamedTagHandler; + + [Mixin] + public class FileSetInclude extends NamedTagHandler + { + public static function init(mf:IFlexModuleFactory):void + { + Ant.antTagProcessors["include"] = FileSetInclude; + } + + public function FileSetInclude() + { + super(); + } + + } +} \ No newline at end of file
