http://git-wip-us.apache.org/repos/asf/flex-utilities/blob/f954e6f6/flex-installer/ant_on_air/src/org/apache/flex/ant/tags/Get.as ---------------------------------------------------------------------- diff --git a/flex-installer/ant_on_air/src/org/apache/flex/ant/tags/Get.as b/flex-installer/ant_on_air/src/org/apache/flex/ant/tags/Get.as new file mode 100644 index 0000000..2042d32 --- /dev/null +++ b/flex-installer/ant_on_air/src/org/apache/flex/ant/tags/Get.as @@ -0,0 +1,265 @@ +//////////////////////////////////////////////////////////////////////////////// +// +// 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.HTTPStatusEvent; + import flash.events.IOErrorEvent; + import flash.events.ProgressEvent; + import flash.events.SecurityErrorEvent; + import flash.filesystem.File; + import flash.filesystem.FileMode; + import flash.filesystem.FileStream; + import flash.net.URLLoader; + import flash.net.URLLoaderDataFormat; + import flash.net.URLRequest; + import flash.net.URLRequestHeader; + import flash.utils.ByteArray; + + import mx.core.IFlexModuleFactory; + import mx.resources.ResourceManager; + + import org.apache.flex.ant.Ant; + import org.apache.flex.ant.tags.supportClasses.TaskHandler; + + [ResourceBundle("ant")] + [Mixin] + public class Get extends TaskHandler + { + public static function init(mf:IFlexModuleFactory):void + { + Ant.antTagProcessors["get"] = Get; + } + + private static const DOWNLOADS_SOURCEFORGE_NET:String = "http://downloads.sourceforge.net/"; + private static const SOURCEFORGE_NET:String = "http://sourceforge.net/"; + private static const DL_SOURCEFORGE_NET:String = ".dl.sourceforge.net/"; + private static const USE_MIRROR:String = "use_mirror="; + + public function Get() + { + super(); + } + + private function get src():String + { + return getAttributeValue("@src"); + } + + private function get dest():String + { + return getAttributeValue("@dest"); + } + + private function get skipexisting():Boolean + { + return getAttributeValue("@skipexisting") == "true"; + } + + private function get ignoreerrors():Boolean + { + return getAttributeValue("@ignoreerrors") == "true"; + } + + private var urlLoader:URLLoader; + + override public function execute(callbackMode:Boolean, context:Object):Boolean + { + super.execute(callbackMode, context); + + if (skipexisting) + { + var destFile:File = getDestFile(); + if (destFile.exists) + return true; + } + var s:String = ResourceManager.getInstance().getString('ant', 'GETTING'); + s = s.replace("%1", src); + ant.output(ant.formatOutput("get", s)); + s = ResourceManager.getInstance().getString('ant', 'GETTO'); + s = s.replace("%1", getDestFile().nativePath); + ant.output(ant.formatOutput("get", s)); + + var actualSrc:String = src; + var urlRequest:URLRequest = new URLRequest(actualSrc); + urlRequest.followRedirects = false; + urlRequest.manageCookies = false; + urlRequest.userAgent = "Java"; // required to get sourceforge redirects to do the right thing + urlLoader = new URLLoader(); + urlLoader.load(urlRequest); + urlLoader.dataFormat = URLLoaderDataFormat.BINARY; + urlLoader.addEventListener(Event.COMPLETE, completeHandler); + urlLoader.addEventListener(HTTPStatusEvent.HTTP_RESPONSE_STATUS, statusHandler); + urlLoader.addEventListener(ProgressEvent.PROGRESS, progressHandler); + urlLoader.addEventListener(IOErrorEvent.IO_ERROR, ioErrorEventHandler); + urlLoader.addEventListener(SecurityErrorEvent.SECURITY_ERROR, securityErrorHandler); + return false; + } + + private function statusHandler(event:HTTPStatusEvent):void + { + if (event.status >= 300 && event.status < 400) + { + // redirect response + + urlLoader.close(); + + // remove handlers from old request + urlLoader.removeEventListener(Event.COMPLETE, completeHandler); + urlLoader.removeEventListener(HTTPStatusEvent.HTTP_RESPONSE_STATUS, statusHandler); + urlLoader.removeEventListener(ProgressEvent.PROGRESS, progressHandler); + urlLoader.removeEventListener(IOErrorEvent.IO_ERROR, ioErrorEventHandler); + urlLoader.removeEventListener(SecurityErrorEvent.SECURITY_ERROR, securityErrorHandler); + + var newlocation:String; + for each (var header:URLRequestHeader in event.responseHeaders) + { + if (header.name == "Location") + { + newlocation = header.value; + break; + } + } + if (newlocation) + { + var srcIndex:int = src.indexOf(DOWNLOADS_SOURCEFORGE_NET); + var sfIndex:int = newlocation.indexOf(SOURCEFORGE_NET); + var mirrorIndex:int = newlocation.indexOf(USE_MIRROR); + if (srcIndex == 0 && sfIndex == 0 && mirrorIndex != -1 && event.status == 307) + { + // SourceForge redirects AIR requests differently from Ant requests. + // We can't control some of the additional headers that are sent + // but that appears to make the difference. Just pick out the + // mirror and use it against dl.sourceforge.net + var mirror:String = newlocation.substring(mirrorIndex + USE_MIRROR.length); + newlocation = "http://" + mirror + DL_SOURCEFORGE_NET; + newlocation += src.substring(DOWNLOADS_SOURCEFORGE_NET.length); + } + ant.output(ant.formatOutput("get", "Redirected to: " + newlocation)); + var urlRequest:URLRequest = new URLRequest(newlocation); + var refHeader:URLRequestHeader = new URLRequestHeader("Referer", src); + urlRequest.requestHeaders.push(refHeader); + urlRequest.manageCookies = false; + urlRequest.followRedirects = false; + urlRequest.userAgent = "Java"; // required to get sourceforge redirects to do the right thing + urlLoader = new URLLoader(); + urlLoader.load(urlRequest); + urlLoader.dataFormat = URLLoaderDataFormat.BINARY; + urlLoader.addEventListener(Event.COMPLETE, completeHandler); + urlLoader.addEventListener(HTTPStatusEvent.HTTP_RESPONSE_STATUS, statusHandler); + urlLoader.addEventListener(ProgressEvent.PROGRESS, progressHandler); + urlLoader.addEventListener(IOErrorEvent.IO_ERROR, ioErrorEventHandler); + urlLoader.addEventListener(SecurityErrorEvent.SECURITY_ERROR, securityErrorHandler); + } + } + } + + private function ioErrorEventHandler(event:IOErrorEvent):void + { + ant.output(event.toString()); + if (!ignoreerrors) + { + ant.project.failureMessage = ant.formatOutput("get", event.toString()); + ant.project.status = false; + } + dispatchEvent(new Event(Event.COMPLETE)); + event.preventDefault(); + urlLoader = null; + } + + private function securityErrorHandler(event:SecurityErrorEvent):void + { + ant.output(event.toString()); + if (!ignoreerrors) + { + ant.project.failureMessage = ant.formatOutput("get", event.toString()); + ant.project.status = false; + } + dispatchEvent(new Event(Event.COMPLETE)); + event.preventDefault(); + urlLoader = null; + } + + private function progressHandler(event:ProgressEvent):void + { + ant.progressClass = this; + ant.dispatchEvent(event); + } + + private function completeHandler(event:Event):void + { + var destFile:File = getDestFile(); + if (destFile) + { + var fs:FileStream = new FileStream(); + fs.open(destFile, FileMode.WRITE); + fs.writeBytes(urlLoader.data as ByteArray); + fs.close(); + } + + dispatchEvent(new Event(Event.COMPLETE)); + urlLoader = null; + } + + private function getDestFile():File + { + try { + var destFile:File = File.applicationDirectory.resolvePath(dest); + } + catch (e:Error) + { + ant.output(dest); + ant.output(e.message); + if (failonerror) + { + ant.project.failureMessage = ant.formatOutput("get", e.message); + ant.project.status = false; + } + return null; + } + + if (destFile.isDirectory) + { + var fileName:String = src; + var c:int = fileName.indexOf("?"); + if (c != -1) + fileName = fileName.substring(0, c); + c = fileName.lastIndexOf("/"); + if (c != -1) + fileName = fileName.substr(c + 1); + try { + destFile = destFile.resolvePath(fileName); + } + catch (e:Error) + { + ant.output(fileName); + ant.output(e.message); + if (failonerror) + { + ant.project.failureMessage = ant.formatOutput("get", e.message); + ant.project.status = false; + } + return null; + } + + } + return destFile; + } + } +} \ 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/GlobMapper.as ---------------------------------------------------------------------- diff --git a/flex-installer/ant_on_air/src/org/apache/flex/ant/tags/GlobMapper.as b/flex-installer/ant_on_air/src/org/apache/flex/ant/tags/GlobMapper.as new file mode 100644 index 0000000..dfedeb8 --- /dev/null +++ b/flex-installer/ant_on_air/src/org/apache/flex/ant/tags/GlobMapper.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 GlobMapper extends TagHandler + { + public static function init(mf:IFlexModuleFactory):void + { + Ant.antTagProcessors["globmapper"] = GlobMapper; + } + + public function GlobMapper() + { + super(); + } + + public function get from():String + { + return getAttributeValue("@from"); + } + + public function get to():String + { + return getAttributeValue("@to"); + } + + } +} \ 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/HasFreeSpace.as ---------------------------------------------------------------------- diff --git a/flex-installer/ant_on_air/src/org/apache/flex/ant/tags/HasFreeSpace.as b/flex-installer/ant_on_air/src/org/apache/flex/ant/tags/HasFreeSpace.as new file mode 100644 index 0000000..11e7564 --- /dev/null +++ b/flex-installer/ant_on_air/src/org/apache/flex/ant/tags/HasFreeSpace.as @@ -0,0 +1,70 @@ +/* + * 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.TagHandler; + + [Mixin] + public class HasFreeSpace extends TagHandler implements IValueTagHandler + { + public static function init(mf:IFlexModuleFactory):void + { + Ant.antTagProcessors["hasfreespace"] = HasFreeSpace; + } + + public function HasFreeSpace() + { + super(); + } + + private function get partition():String + { + return getAttributeValue("@partition"); + } + + private function get needed():String + { + return getAttributeValue("@needed"); + } + + public function getValue(context:Object):Object + { + this.context = context; + + var file:File = new File(partition); + var space:Number = file.spaceAvailable; + var postfix:String = needed.substr(-1,1); + var amount:Number = Number(needed.substr(0, needed.length-1)); + + for each (var modifier:String in ["K","M","G","T","P"]) { + amount *= 1024; + if (postfix == modifier) { + break; + } + } + + return (space >= amount); + } + + } +} \ 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/Input.as ---------------------------------------------------------------------- diff --git a/flex-installer/ant_on_air/src/org/apache/flex/ant/tags/Input.as b/flex-installer/ant_on_air/src/org/apache/flex/ant/tags/Input.as new file mode 100644 index 0000000..f5808f4 --- /dev/null +++ b/flex-installer/ant_on_air/src/org/apache/flex/ant/tags/Input.as @@ -0,0 +1,96 @@ +//////////////////////////////////////////////////////////////////////////////// +// +// 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.ui.Keyboard; + + import mx.core.IFlexModuleFactory; + + import org.apache.flex.ant.Ant; + import org.apache.flex.ant.tags.supportClasses.TaskHandler; + + [Mixin] + public class Input extends TaskHandler + { + public static function init(mf:IFlexModuleFactory):void + { + Ant.antTagProcessors["input"] = Input; + } + + public function Input() + { + super(); + } + + private function get text():String + { + return getAttributeValue("@message"); + } + + private function get validArgs():Array + { + var val:String = getNullOrAttributeValue("@validargs"); + return val == null ? null : val.split(","); + } + + private function get property():String + { + return getAttributeValue("@addproperty"); + } + + private function get defaultValue():String + { + return getAttributeValue("@defaultvalue"); + } + + override public function execute(callbackMode:Boolean, context:Object):Boolean + { + super.execute(callbackMode, context); + var s:String = ""; + if (text) + s += ant.getValue(text, context); + if (validArgs) + s += " (" + validArgs + ")"; + ant.output(ant.formatOutput("input", s)); + ant.addEventListener(KeyboardEvent.KEY_DOWN, keyDownHandler); + return false; + } + + // consumer should re-dispatch keyboard events from ant instance + private function keyDownHandler(event:KeyboardEvent):void + { + var val:String; + + if (validArgs == null && event.keyCode == Keyboard.ENTER) + val = defaultValue; + else if (validArgs.indexOf(String.fromCharCode(event.charCode)) != -1) + val = String.fromCharCode(event.charCode); + + if (val != null) + { + ant.removeEventListener(KeyboardEvent.KEY_DOWN, keyDownHandler); + if (!context.hasOwnProperty(property)) + context[property] = val; + 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/IsFalse.as ---------------------------------------------------------------------- diff --git a/flex-installer/ant_on_air/src/org/apache/flex/ant/tags/IsFalse.as b/flex-installer/ant_on_air/src/org/apache/flex/ant/tags/IsFalse.as new file mode 100644 index 0000000..7019d35 --- /dev/null +++ b/flex-installer/ant_on_air/src/org/apache/flex/ant/tags/IsFalse.as @@ -0,0 +1,53 @@ +//////////////////////////////////////////////////////////////////////////////// +// +// 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 IsFalse extends TagHandler implements IValueTagHandler + { + public static function init(mf:IFlexModuleFactory):void + { + Ant.antTagProcessors["isfalse"] = IsFalse; + } + + public function IsFalse() + { + super(); + } + + private function get value():String + { + return getAttributeValue("@value"); + } + + public function getValue(context:Object):Object + { + this.context = context; + + return !(value == "true" || value == "on" || value == "yes"); + } + + } +} \ 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/IsReference.as ---------------------------------------------------------------------- diff --git a/flex-installer/ant_on_air/src/org/apache/flex/ant/tags/IsReference.as b/flex-installer/ant_on_air/src/org/apache/flex/ant/tags/IsReference.as new file mode 100644 index 0000000..99a2222 --- /dev/null +++ b/flex-installer/ant_on_air/src/org/apache/flex/ant/tags/IsReference.as @@ -0,0 +1,54 @@ +//////////////////////////////////////////////////////////////////////////////// +// +// 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 IsReference extends TagHandler implements IValueTagHandler + { + public static function init(mf:IFlexModuleFactory):void + { + Ant.antTagProcessors["isreference"] = IsReference; + } + + public function IsReference() + { + super(); + } + + private function get refid():String + { + return getNullOrAttributeValue("@refid"); + } + + public function getValue(context:Object):Object + { + this.context = context; + if (refid == null) return false; + + return ant.project.refids.hasOwnProperty(refid); + } + + } +} \ 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/IsSet.as ---------------------------------------------------------------------- diff --git a/flex-installer/ant_on_air/src/org/apache/flex/ant/tags/IsSet.as b/flex-installer/ant_on_air/src/org/apache/flex/ant/tags/IsSet.as new file mode 100644 index 0000000..7fb0199 --- /dev/null +++ b/flex-installer/ant_on_air/src/org/apache/flex/ant/tags/IsSet.as @@ -0,0 +1,54 @@ +//////////////////////////////////////////////////////////////////////////////// +// +// 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 IsSet extends TagHandler implements IValueTagHandler + { + public static function init(mf:IFlexModuleFactory):void + { + Ant.antTagProcessors["isset"] = IsSet; + } + + public function IsSet() + { + super(); + } + + private function get property():String + { + return getNullOrAttributeValue("@property"); + } + + public function getValue(context:Object):Object + { + this.context = context; + if (property == null) return false; + + return context.hasOwnProperty(property); + } + + } +} \ 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/IsTrue.as ---------------------------------------------------------------------- diff --git a/flex-installer/ant_on_air/src/org/apache/flex/ant/tags/IsTrue.as b/flex-installer/ant_on_air/src/org/apache/flex/ant/tags/IsTrue.as new file mode 100644 index 0000000..9234be4 --- /dev/null +++ b/flex-installer/ant_on_air/src/org/apache/flex/ant/tags/IsTrue.as @@ -0,0 +1,53 @@ +//////////////////////////////////////////////////////////////////////////////// +// +// 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 IsTrue extends TagHandler implements IValueTagHandler + { + public static function init(mf:IFlexModuleFactory):void + { + Ant.antTagProcessors["istrue"] = IsTrue; + } + + public function IsTrue() + { + super(); + } + + private function get value():String + { + return getAttributeValue("@value"); + } + + public function getValue(context:Object):Object + { + this.context = context; + + return (value == "true" || value == "on" || value == "yes"); + } + + } +} \ 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/LoadProperties.as ---------------------------------------------------------------------- diff --git a/flex-installer/ant_on_air/src/org/apache/flex/ant/tags/LoadProperties.as b/flex-installer/ant_on_air/src/org/apache/flex/ant/tags/LoadProperties.as new file mode 100644 index 0000000..6db0c68 --- /dev/null +++ b/flex-installer/ant_on_air/src/org/apache/flex/ant/tags/LoadProperties.as @@ -0,0 +1,95 @@ +//////////////////////////////////////////////////////////////////////////////// +// +// 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 mx.utils.StringUtil; + + import org.apache.flex.ant.Ant; + import org.apache.flex.ant.tags.supportClasses.TaskHandler; + + [Mixin] + public class LoadProperties extends TaskHandler + { + public static function init(mf:IFlexModuleFactory):void + { + Ant.antTagProcessors["loadproperties"] = LoadProperties; + } + + public function LoadProperties() + { + } + + override public function execute(callbackMode:Boolean, context:Object):Boolean + { + super.execute(callbackMode, context); + + 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.READ); + var data:String = fs.readUTFBytes(fs.bytesAvailable); + 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("="); + } + if (!context.hasOwnProperty(key)) + context[key] = val; + } + + } + fs.close(); + return true; + } + + private function get fileName():String + { + return getAttributeValue("@srcFile"); + } + + } +} \ 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/Matches.as ---------------------------------------------------------------------- diff --git a/flex-installer/ant_on_air/src/org/apache/flex/ant/tags/Matches.as b/flex-installer/ant_on_air/src/org/apache/flex/ant/tags/Matches.as new file mode 100644 index 0000000..ce38d98 --- /dev/null +++ b/flex-installer/ant_on_air/src/org/apache/flex/ant/tags/Matches.as @@ -0,0 +1,62 @@ +//////////////////////////////////////////////////////////////////////////////// +// +// 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 Matches extends TagHandler implements IValueTagHandler + { + public static function init(mf:IFlexModuleFactory):void + { + Ant.antTagProcessors["matches"] = Matches; + } + + public function Matches() + { + super(); + } + + private function get string():String + { + return getAttributeValue("@string"); + } + + private function get pattern():String + { + return getAttributeValue("@pattern"); + } + + public function getValue(context:Object):Object + { + this.context = context; + var pat:String = pattern; + if (pat.indexOf(".*") == -1) + pat = pat.replace("*", ".*"); + var regex:RegExp = new RegExp(pat); + var results:Array = string.match(regex); + return results && results.length > 0; + } + + } +} \ 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/Mkdir.as ---------------------------------------------------------------------- diff --git a/flex-installer/ant_on_air/src/org/apache/flex/ant/tags/Mkdir.as b/flex-installer/ant_on_air/src/org/apache/flex/ant/tags/Mkdir.as new file mode 100644 index 0000000..9ce69dc --- /dev/null +++ b/flex-installer/ant_on_air/src/org/apache/flex/ant/tags/Mkdir.as @@ -0,0 +1,77 @@ +//////////////////////////////////////////////////////////////////////////////// +// +// 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.TaskHandler; + + [ResourceBundle("ant")] + [Mixin] + public class Mkdir extends TaskHandler + { + public static function init(mf:IFlexModuleFactory):void + { + Ant.antTagProcessors["mkdir"] = Mkdir; + } + + public function Mkdir() + { + super(); + } + + private function get _dir():String + { + return getAttributeValue("@dir"); + } + + override public function execute(callbackMode:Boolean, context:Object):Boolean + { + super.execute(callbackMode, context); + + try + { + var dir:File = new File(_dir); + } + catch (e:Error) + { + ant.output(_dir); + ant.output(e.message); + if (failonerror) + { + ant.project.failureMessage = e.message; + ant.project.status = false; + } + return true; + } + + dir.createDirectory(); + + var s:String = ResourceManager.getInstance().getString('ant', 'MKDIR'); + s = s.replace("%1", dir.nativePath); + ant.output(ant.formatOutput("mkdir", s)); + 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/Move.as ---------------------------------------------------------------------- diff --git a/flex-installer/ant_on_air/src/org/apache/flex/ant/tags/Move.as b/flex-installer/ant_on_air/src/org/apache/flex/ant/tags/Move.as new file mode 100644 index 0000000..9e6a0d3 --- /dev/null +++ b/flex-installer/ant_on_air/src/org/apache/flex/ant/tags/Move.as @@ -0,0 +1,237 @@ +//////////////////////////////////////////////////////////////////////////////// +// +// 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 Move extends FileSetTaskHandler + { + public static function init(mf:IFlexModuleFactory):void + { + Ant.antTagProcessors["move"] = Move; + } + + public function Move() + { + 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; + } + + srcFile.moveTo(destFile, overwrite); + } + + override protected function outputTotal(total:int):void + { + var s:String = ResourceManager.getInstance().getString('ant', 'MOVEFILES'); + s = s.replace("%1", total.toString()); + s = s.replace("%2", toDirName); + ant.output(ant.formatOutput("move", 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; + } + + var destFileName:String; + if (toDirName) + { + var stem:String = srcFile.nativePath.substr(srcFile.parent.nativePath.length); + destFileName = toDirName + stem; + } + else + destFileName = toFileName; + + try { + destFile = File.applicationDirectory.resolvePath(destFileName); + } + catch (e:Error) + { + ant.output(destFileName); + 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', 'MOVE'); + s = s.replace("%1", "1"); + s = s.replace("%2", destFile.nativePath); + ant.output(ant.formatOutput("move", s)); + if (callbackMode) + { + ant.functionToCall = doMove; + return false; + } + + doMove(); + return true; + } + + protected function doMove():void + { + srcFile.moveTo(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/Not.as ---------------------------------------------------------------------- diff --git a/flex-installer/ant_on_air/src/org/apache/flex/ant/tags/Not.as b/flex-installer/ant_on_air/src/org/apache/flex/ant/tags/Not.as new file mode 100644 index 0000000..f4273d3 --- /dev/null +++ b/flex-installer/ant_on_air/src/org/apache/flex/ant/tags/Not.as @@ -0,0 +1,57 @@ +//////////////////////////////////////////////////////////////////////////////// +// +// 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 Not extends ParentTagHandler implements IValueTagHandler + { + public static function init(mf:IFlexModuleFactory):void + { + Ant.antTagProcessors["not"] = Not; + } + + public function Not() + { + super(); + } + + public function getValue(context:Object):Object + { + this.context = context; + ant.processChildren(xml, this); + if (numChildren == 1) + { + var value:IValueTagHandler = getChildAt(0) as IValueTagHandler; + // get the value from the children + var val:Object = IValueTagHandler(value).getValue(context); + if (!(val == "true" || val == true)) + { + 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/OS.as ---------------------------------------------------------------------- diff --git a/flex-installer/ant_on_air/src/org/apache/flex/ant/tags/OS.as b/flex-installer/ant_on_air/src/org/apache/flex/ant/tags/OS.as new file mode 100644 index 0000000..5074573 --- /dev/null +++ b/flex-installer/ant_on_air/src/org/apache/flex/ant/tags/OS.as @@ -0,0 +1,57 @@ +//////////////////////////////////////////////////////////////////////////////// +// +// 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.system.Capabilities; + + 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 OS extends TagHandler implements IValueTagHandler + { + public static function init(mf:IFlexModuleFactory):void + { + Ant.antTagProcessors["os"] = OS; + } + + public function OS() + { + super(); + } + + private function get family():String + { + return getNullOrAttributeValue("@family"); + } + + public function getValue(context:Object):Object + { + this.context = context; + + if (family == null) return false; + + return Capabilities.os.toLowerCase().indexOf(family.toLowerCase()) != -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/Or.as ---------------------------------------------------------------------- diff --git a/flex-installer/ant_on_air/src/org/apache/flex/ant/tags/Or.as b/flex-installer/ant_on_air/src/org/apache/flex/ant/tags/Or.as new file mode 100644 index 0000000..35e8890 --- /dev/null +++ b/flex-installer/ant_on_air/src/org/apache/flex/ant/tags/Or.as @@ -0,0 +1,65 @@ +//////////////////////////////////////////////////////////////////////////////// +// +// 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 Or extends ParentTagHandler implements IValueTagHandler + { + public static function init(mf:IFlexModuleFactory):void + { + Ant.antTagProcessors["or"] = Or; + } + + public function Or() + { + super(); + } + + public function getValue(context:Object):Object + { + ant.processChildren(xml, this); + + if (numChildren > 0) + { + var n:int = numChildren; + var result:Boolean; + + 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); + + result = result || (val == "true" || val == true); + + if (result) + 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/Param.as ---------------------------------------------------------------------- diff --git a/flex-installer/ant_on_air/src/org/apache/flex/ant/tags/Param.as b/flex-installer/ant_on_air/src/org/apache/flex/ant/tags/Param.as new file mode 100644 index 0000000..6e68c98 --- /dev/null +++ b/flex-installer/ant_on_air/src/org/apache/flex/ant/tags/Param.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 Param extends TagHandler + { + public static function init(mf:IFlexModuleFactory):void + { + Ant.antTagProcessors["param"] = Param; + } + + public function Param() + { + super(); + } + + public function get name():String + { + return getAttributeValue("@name"); + } + + 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/PatternSet.as ---------------------------------------------------------------------- diff --git a/flex-installer/ant_on_air/src/org/apache/flex/ant/tags/PatternSet.as b/flex-installer/ant_on_air/src/org/apache/flex/ant/tags/PatternSet.as new file mode 100644 index 0000000..4540de8 --- /dev/null +++ b/flex-installer/ant_on_air/src/org/apache/flex/ant/tags/PatternSet.as @@ -0,0 +1,96 @@ +//////////////////////////////////////////////////////////////////////////////// +// +// 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.SelectorUtils; + import org.apache.flex.ant.tags.filesetClasses.exceptions.BuildException; + import org.apache.flex.ant.tags.supportClasses.NamedTagHandler; + import org.apache.flex.ant.tags.supportClasses.ParentTagHandler; + + [Mixin] + public class PatternSet extends ParentTagHandler + { + public static function init(mf:IFlexModuleFactory):void + { + Ant.antTagProcessors["patternset"] = PatternSet; + } + + public function PatternSet() + { + super(); + } + + private var includes:Vector.<String>; + private var excludes:Vector.<String>; + + private var processedChildren:Boolean; + + public function matches(path:String):Boolean + { + if (!processedChildren) + { + ant.processChildren(xml, this); + processedChildren = true; + } + + if (numChildren == 0) + return true; + + if (includes == null) + { + 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); + } + } + var result:Boolean = false; + for each (var inc:String in includes) + { + if (SelectorUtils.match(inc, path)) + { + result = true; + break; + } + } + for each (var exc:String in excludes) + { + if (SelectorUtils.match(exc, path)) + { + result = false; + break; + } + } + return result; + } + + } +} \ 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/Project.as ---------------------------------------------------------------------- diff --git a/flex-installer/ant_on_air/src/org/apache/flex/ant/tags/Project.as b/flex-installer/ant_on_air/src/org/apache/flex/ant/tags/Project.as new file mode 100644 index 0000000..f7628e7 --- /dev/null +++ b/flex-installer/ant_on_air/src/org/apache/flex/ant/tags/Project.as @@ -0,0 +1,241 @@ +//////////////////////////////////////////////////////////////////////////////// +// +// 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 mx.utils.StringUtil; + + import org.apache.flex.ant.Ant; + import org.apache.flex.ant.tags.filesetClasses.Reference; + import org.apache.flex.ant.tags.supportClasses.TaskHandler; + import org.apache.flex.xml.ITagHandler; + + [Mixin] + public class Project extends TaskHandler + { + /** Message priority of "error". */ + public static const MSG_ERR:int = 0; + /** Message priority of "warning". */ + public static const MSG_WARN:int = 1; + /** Message priority of "information". */ + public static const MSG_INFO:int = 2; + /** Message priority of "verbose". */ + public static const MSG_VERBOSE:int = 3; + /** Message priority of "debug". */ + public static const MSG_DEBUG:int = 4; + + public static function init(mf:IFlexModuleFactory):void + { + Ant.antTagProcessors["project"] = Project; + } + + public function Project() + { + } + + private var _status:Boolean; + /** + * true if tasks completed successfully. + * Do not monitor this property to determine if the project is done executing. + * This property is set to true and a failing task sets it to false. + */ + public function get status():Boolean + { + return _status; + } + + public function set status(value:Boolean):void + { + if (_status != value) + { + _status = value; + ant.dispatchEvent(new Event("statusChanged")); + } + } + + private var _failureMessage:String; + /** + * null if tasks completed successfully. + * if status == false, then this will be + * set if a <fail> message set status to false + * or some other condition set status to false. + * + */ + public function get failureMessage():String + { + return _failureMessage; + } + + public function set failureMessage(value:String):void + { + if (_failureMessage != value) + { + _failureMessage = value; + ant.dispatchEvent(new Event("failureMessageChanged")); + } + } + + public function get basedir():String + { + return getAttributeValue("@basedir"); + } + + public function get defaultTarget():String + { + return getAttributeValue("@default"); + } + + public var refids:Object = {}; + + private var targets:Array; + + override public function execute(callbackMode:Boolean, context:Object):Boolean + { + super.execute(callbackMode, context); + + this.callbackMode = callbackMode; + + status = true; + + if (context.targets == null) + context.targets = defaultTarget; + + targets = context.targets.split(","); + + // execute all children in order except for targets + return executeChildren(); + } + + private var current:int = 0; + + private function executeChildren():Boolean + { + if (!status) + { + dispatchEvent(new Event(Event.COMPLETE)); + return true; + } + + if (current == numChildren) + return executeTargets(); + + while (current < numChildren) + { + var child:ITagHandler = getChildAt(current++); + if (child is Target) + continue; + if (child is TaskHandler) + { + var task:TaskHandler = TaskHandler(child); + if (!task.execute(callbackMode, context)) + { + task.addEventListener(Event.COMPLETE, childCompleteHandler); + return false; + } + if (!status) + { + dispatchEvent(new Event(Event.COMPLETE)); + return true; + } + } + } + return executeTargets(); + } + + private function executeTargets():Boolean + { + while (targets.length > 0) + { + var targetName:String = targets.shift(); + if (!executeTarget(targetName)) + return false; + if (!status) + { + dispatchEvent(new Event(Event.COMPLETE)); + return true; + } + + } + if (targets.length == 0) + dispatchEvent(new Event(Event.COMPLETE)); + + return true; + } + + public function getTarget(targetName:String):Target + { + targetName = StringUtil.trim(targetName); + var n:int = numChildren; + for (var i:int = 0; i < n; i++) + { + var child:ITagHandler = getChildAt(i); + if (child is Target) + { + var t:Target = child as Target; + if (t.name == targetName) + { + return t; + } + } + } + trace("missing target: ", targetName); + throw new Error("missing target: " + targetName); + return null; + } + + public function executeTarget(targetName:String):Boolean + { + var t:Target = getTarget(targetName); + if (!t.execute(callbackMode, context)) + { + t.addEventListener(Event.COMPLETE, completeHandler); + return false; + } + return true; + } + + private function completeHandler(event:Event):void + { + event.target.removeEventListener(Event.COMPLETE, completeHandler); + executeTargets(); + } + + private function childCompleteHandler(event:Event):void + { + event.target.removeEventListener(Event.COMPLETE, childCompleteHandler); + executeChildren(); + } + + private var references:Object = {}; + + public function addReference(referenceName:String, value:Object):void + { + references[referenceName] = value; + } + public function getReference(referenceName:String):Reference + { + if (references.hasOwnProperty(referenceName)) + return references[referenceName]; + + return null; + } + } +} \ 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/Property.as ---------------------------------------------------------------------- diff --git a/flex-installer/ant_on_air/src/org/apache/flex/ant/tags/Property.as b/flex-installer/ant_on_air/src/org/apache/flex/ant/tags/Property.as new file mode 100644 index 0000000..3acf3a3 --- /dev/null +++ b/flex-installer/ant_on_air/src/org/apache/flex/ant/tags/Property.as @@ -0,0 +1,234 @@ +//////////////////////////////////////////////////////////////////////////////// +// +// 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.filesystem.FileMode; + import flash.filesystem.FileStream; + 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 Property extends TaskHandler + { + public static function init(mf:IFlexModuleFactory):void + { + Ant.antTagProcessors["property"] = Property; + } + + public function Property() + { + } + + override public function execute(callbackMode:Boolean, context:Object):Boolean + { + super.execute(callbackMode, context); + + if (name && (value || location || refid) && !context.hasOwnProperty(name)) + { + if (value) + context[name] = value; + else if (refid) + context[name] = context[ant.project.refids[refid]]; + else + context[name] = location; + } + else 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; + } + + if (f.exists) + { + var fs:FileStream = new FileStream(); + fs.open(f, FileMode.READ); + var data:String = fs.readUTFBytes(fs.bytesAvailable); + var propLines:Array = data.split("\n"); + var collectingParts:Boolean; + var val:String; + var key:String; + for each (var line:String in propLines) + { + if (line.charAt(line.length - 1) == "\r") + line = line.substr(0, line.length - 1); + if (collectingParts) + { + if (line.charAt(line.length - 1) == "\\") + val += line.substr(0, line.length - 1); + else + { + collectingParts = false; + val += line; + val = StringUtil.trim(val); + val = val.replace(/\\n/g, "\n"); + if (!context.hasOwnProperty(key)) + context[key] = ant.getValue(val, context); + } + continue; + } + var parts:Array = line.split("="); + if (parts.length >= 2) + { + key = StringUtil.trim(parts[0]); + if (parts.length == 2) + val = parts[1]; + else + { + parts.shift(); + val = parts.join("="); + } + if (val.charAt(val.length - 1) == "\\") + { + collectingParts = true; + val = val.substr(0, val.length - 1); + } + else if (!context.hasOwnProperty(key)) + context[key] = ant.getValue(StringUtil.trim(val), context); + } + + } + fs.close(); + } + } + else if (envPrefix != null) + { + requestEnvironmentVariables(); + return false; + } + return true; + } + + private function get fileName():String + { + return getNullOrAttributeValue("@file"); + } + + private function get refid():String + { + return getNullOrAttributeValue("@refid"); + } + + private function get value():String + { + return getNullOrAttributeValue("@value"); + } + + private function get location():String + { + return getNullOrAttributeValue("@location"); + } + + private function get envPrefix():String + { + return getNullOrAttributeValue("@environment"); + } + + private var process:NativeProcess; + + public function requestEnvironmentVariables():void + { + 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"); + 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 + { + 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); + var propLines:Array; + if (Capabilities.os.indexOf('Mac OS') > -1) + propLines = data.split("\n"); + else + propLines = data.split("\r\n"); + var prefix:String = envPrefix; + for each (var line:String in propLines) + { + var parts:Array = line.split("="); + if (parts.length >= 2) + { + var key:String = envPrefix + "." + StringUtil.trim(parts[0]); + var val:String; + if (parts.length == 2) + val = parts[1]; + else + { + parts.shift(); + val = parts.join("="); + } + if (!context.hasOwnProperty(key)) + context[key] = val; + } + } + } + + } +} \ 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/PropertyFile.as ---------------------------------------------------------------------- diff --git a/flex-installer/ant_on_air/src/org/apache/flex/ant/tags/PropertyFile.as b/flex-installer/ant_on_air/src/org/apache/flex/ant/tags/PropertyFile.as new file mode 100644 index 0000000..1d2c067 --- /dev/null +++ b/flex-installer/ant_on_air/src/org/apache/flex/ant/tags/PropertyFile.as @@ -0,0 +1,84 @@ +//////////////////////////////////////////////////////////////////////////////// +// +// 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; + + [Mixin] + public class PropertyFile extends TaskHandler + { + public static function init(mf:IFlexModuleFactory):void + { + Ant.antTagProcessors["propertyfile"] = PropertyFile; + } + + public function PropertyFile() + { + } + + override public function execute(callbackMode:Boolean, context:Object):Boolean + { + super.execute(callbackMode, context); + + 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); + var n:int = numChildren; + for (var i:int = 0; i < n; i++) + { + var entry:Entry = getChildAt(i) as Entry; + entry.setContext(context); + if (entry) + { + var s:String = entry.key + "=" + entry.value + "\n"; + fs.writeUTFBytes(s); + } + } + fs.close(); + return true; + } + + private function get fileName():String + { + return getAttributeValue("@file"); + } + + } +} \ 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/Replace.as ---------------------------------------------------------------------- diff --git a/flex-installer/ant_on_air/src/org/apache/flex/ant/tags/Replace.as b/flex-installer/ant_on_air/src/org/apache/flex/ant/tags/Replace.as new file mode 100644 index 0000000..2873ee1 --- /dev/null +++ b/flex-installer/ant_on_air/src/org/apache/flex/ant/tags/Replace.as @@ -0,0 +1,142 @@ +//////////////////////////////////////////////////////////////////////////////// +// +// 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.ITagHandler; + + [Mixin] + public class Replace extends TaskHandler + { + public static function init(mf:IFlexModuleFactory):void + { + Ant.antTagProcessors["replace"] = Replace; + } + + public function Replace() + { + super(); + } + + private function get file():String + { + return getAttributeValue("@file"); + } + + private function get token():String + { + return getNullOrAttributeValue("@token"); + } + + private function get value():String + { + return getAttributeValue("@value"); + } + + override public function execute(callbackMode:Boolean, context:Object):Boolean + { + super.execute(callbackMode, context); + + try { + var f:File = File.applicationDirectory.resolvePath(file); + } + catch (e:Error) + { + ant.output(file); + 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.READ); + var s:String = fs.readUTFBytes(fs.bytesAvailable); + fs.close(); + var tokens:Vector.<String> = new Vector.<String>(); + var reps:Vector.<String> = new Vector.<String>(); + if (token != null) + { + tokens.push(token); + reps.push(value); + } + if (numChildren > 0) + { + for (var i:int = 0; i < numChildren; i++) + { + var child:ITagHandler = getChildAt(i); + if(child is ReplaceFilter) + { + var rf:ReplaceFilter = child as ReplaceFilter; + rf.setContext(context); + tokens.push(rf.token); + reps.push(rf.value); + } + else if(child is ReplaceToken) + { + var rt:ReplaceToken = child as ReplaceToken; + rt.setContext(context); + tokens.push(rt.text); + } + else if(child is ReplaceValue) + { + var rv:ReplaceValue = child as ReplaceValue; + rv.setContext(context); + reps.push(rv.text); + } + } + } + var n:int = tokens.length; + var c:int = 0; + for (i = 0; i < n; i++) + { + var cur:int = 0; + // only look at the portion we haven't looked at yet. + // otherwise certain kinds of replacements can + // cause infinite looping, like replacing + // 'foo' with 'food' + do + { + c = s.indexOf(tokens[i], cur) + if (c != -1) + { + var firstHalf:String = s.substr(0, c); + var secondHalf:String = s.substr(c); + s = firstHalf + secondHalf.replace(tokens[i], reps[i]); + cur = c + reps[i].length; + } + } while (c != -1) + } + fs.open(f, FileMode.WRITE); + fs.writeUTFBytes(s); + fs.close(); + return true; + } + } +} \ No newline at end of file
