add support for failonerror and reporting failures
Project: http://git-wip-us.apache.org/repos/asf/flex-utilities/repo Commit: http://git-wip-us.apache.org/repos/asf/flex-utilities/commit/1d9886dd Tree: http://git-wip-us.apache.org/repos/asf/flex-utilities/tree/1d9886dd Diff: http://git-wip-us.apache.org/repos/asf/flex-utilities/diff/1d9886dd Branch: refs/heads/develop Commit: 1d9886ddbd2dc91c94ce9190a8a408a2e9990ee5 Parents: a8ab9e1 Author: Alex Harui <[email protected]> Authored: Mon Dec 9 15:27:45 2013 -0800 Committer: Alex Harui <[email protected]> Committed: Mon Dec 9 15:27:45 2013 -0800 ---------------------------------------------------------------------- ant_on_air/src/org/apache/flex/ant/Ant.as | 5 +++- .../src/org/apache/flex/ant/tags/Condition.as | 12 ++++++-- .../src/org/apache/flex/ant/tags/Project.as | 28 ++++++++++++++++++- .../src/org/apache/flex/ant/tags/Target.as | 9 ++++++ .../tags/supportClasses/FileSetTaskHandler.as | 22 +++++++++++---- .../flex/ant/tags/supportClasses/TaskHandler.as | 10 +++++++ ant_on_air/tests/TestTarget.as | 6 ++++ ant_on_air/tests/test.xml | 29 ++++++++++++++++++++ 8 files changed, 111 insertions(+), 10 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/flex-utilities/blob/1d9886dd/ant_on_air/src/org/apache/flex/ant/Ant.as ---------------------------------------------------------------------- diff --git a/ant_on_air/src/org/apache/flex/ant/Ant.as b/ant_on_air/src/org/apache/flex/ant/Ant.as index 0f487a3..7476daf 100644 --- a/ant_on_air/src/org/apache/flex/ant/Ant.as +++ b/ant_on_air/src/org/apache/flex/ant/Ant.as @@ -48,9 +48,12 @@ package org.apache.flex.ant private var file:File; /** - * Open a file, read the XML and create ITagHandlers for every tag + * 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):Boolean { http://git-wip-us.apache.org/repos/asf/flex-utilities/blob/1d9886dd/ant_on_air/src/org/apache/flex/ant/tags/Condition.as ---------------------------------------------------------------------- diff --git a/ant_on_air/src/org/apache/flex/ant/tags/Condition.as b/ant_on_air/src/org/apache/flex/ant/tags/Condition.as index 7f94d8f..814811d 100644 --- a/ant_on_air/src/org/apache/flex/ant/tags/Condition.as +++ b/ant_on_air/src/org/apache/flex/ant/tags/Condition.as @@ -46,19 +46,25 @@ package org.apache.flex.ant.tags // if the property is not already set if (_property && _value != null && !context.hasOwnProperty(_property)) { - // get the value from the children - var val:Object = IValueTagHandler(getChildAt(0)).value; + 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)).value; + return val; + } + private var _property:String; private var _value:Object; http://git-wip-us.apache.org/repos/asf/flex-utilities/blob/1d9886dd/ant_on_air/src/org/apache/flex/ant/tags/Project.as ---------------------------------------------------------------------- diff --git a/ant_on_air/src/org/apache/flex/ant/tags/Project.as b/ant_on_air/src/org/apache/flex/ant/tags/Project.as index 5136f55..22435f4 100644 --- a/ant_on_air/src/org/apache/flex/ant/tags/Project.as +++ b/ant_on_air/src/org/apache/flex/ant/tags/Project.as @@ -52,6 +52,13 @@ package org.apache.flex.ant.tags { } + /** + * 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 var status:Boolean; + override public function init(xml:XML, context:Object, xmlProcessor:XMLTagProcessor):void { context.project = this; @@ -87,6 +94,8 @@ package org.apache.flex.ant.tags override public function execute():Boolean { + status = true; + if (context.targets == null) context.targets == _defaultTarget; @@ -100,6 +109,12 @@ package org.apache.flex.ant.tags private function executeChildren():Boolean { + if (!status) + { + dispatchEvent(new Event(Event.COMPLETE)); + return true; + } + if (current == numChildren) return executeTargets(); @@ -116,6 +131,11 @@ package org.apache.flex.ant.tags task.addEventListener(Event.COMPLETE, childCompleteHandler); return false; } + if (!status) + { + dispatchEvent(new Event(Event.COMPLETE)); + return true; + } } } return executeTargets(); @@ -127,7 +147,13 @@ package org.apache.flex.ant.tags { var targetName:String = targets.shift(); if (!executeTarget(targetName)) - return false; + return false; + if (!status) + { + dispatchEvent(new Event(Event.COMPLETE)); + return true; + } + } if (targets.length == 0) dispatchEvent(new Event(Event.COMPLETE)); http://git-wip-us.apache.org/repos/asf/flex-utilities/blob/1d9886dd/ant_on_air/src/org/apache/flex/ant/tags/Target.as ---------------------------------------------------------------------- diff --git a/ant_on_air/src/org/apache/flex/ant/tags/Target.as b/ant_on_air/src/org/apache/flex/ant/tags/Target.as index df47ffa..0504237 100644 --- a/ant_on_air/src/org/apache/flex/ant/tags/Target.as +++ b/ant_on_air/src/org/apache/flex/ant/tags/Target.as @@ -111,6 +111,8 @@ package org.apache.flex.ant.tags private function continueOnToSteps():Boolean { + if (!Ant.project.status) + return true; ant.processChildren(xml, context, this); return processSteps(); } @@ -133,6 +135,8 @@ package org.apache.flex.ant.tags step.addEventListener(Event.COMPLETE, completeHandler); return false; } + if (!Ant.project.status) + return true; } dispatchEvent(new Event(Event.COMPLETE)); return true; @@ -140,6 +144,11 @@ package org.apache.flex.ant.tags private function completeHandler(event:Event):void { + if (!Ant.project.status) + { + dispatchEvent(new Event(Event.COMPLETE)); + return; + } processSteps(); } } http://git-wip-us.apache.org/repos/asf/flex-utilities/blob/1d9886dd/ant_on_air/src/org/apache/flex/ant/tags/supportClasses/FileSetTaskHandler.as ---------------------------------------------------------------------- diff --git a/ant_on_air/src/org/apache/flex/ant/tags/supportClasses/FileSetTaskHandler.as b/ant_on_air/src/org/apache/flex/ant/tags/supportClasses/FileSetTaskHandler.as index c0320a8..21ffc9b 100644 --- a/ant_on_air/src/org/apache/flex/ant/tags/supportClasses/FileSetTaskHandler.as +++ b/ant_on_air/src/org/apache/flex/ant/tags/supportClasses/FileSetTaskHandler.as @@ -20,6 +20,7 @@ package org.apache.flex.ant.tags.supportClasses { import flash.filesystem.File; + import org.apache.flex.ant.Ant; import org.apache.flex.ant.tags.FileSet; /** @@ -46,13 +47,24 @@ package org.apache.flex.ant.tags.supportClasses var fs:FileSet = getChildAt(i) as FileSet; if (fs) { - var list:Vector.<String> = fs.value as Vector.<String>; - if (list) + try { - var dir:File = new File(fs.dir); - for each (var fileName:String in list) + var list:Vector.<String> = fs.value as Vector.<String>; + if (list) { - actOnFile(dir.nativePath, fileName); + var dir:File = new File(fs.dir); + for each (var fileName:String in list) + { + actOnFile(dir.nativePath, fileName); + } + } + } + catch (e:Error) + { + if (failonerror) + { + Ant.project.status = false; + return true; } } } http://git-wip-us.apache.org/repos/asf/flex-utilities/blob/1d9886dd/ant_on_air/src/org/apache/flex/ant/tags/supportClasses/TaskHandler.as ---------------------------------------------------------------------- diff --git a/ant_on_air/src/org/apache/flex/ant/tags/supportClasses/TaskHandler.as b/ant_on_air/src/org/apache/flex/ant/tags/supportClasses/TaskHandler.as index 910753e..d5fdcba 100644 --- a/ant_on_air/src/org/apache/flex/ant/tags/supportClasses/TaskHandler.as +++ b/ant_on_air/src/org/apache/flex/ant/tags/supportClasses/TaskHandler.as @@ -28,6 +28,8 @@ package org.apache.flex.ant.tags.supportClasses { } + public var failonerror:Boolean = true + /** * Do the work. * TaskHandlers lazily create their children so @@ -39,5 +41,13 @@ package org.apache.flex.ant.tags.supportClasses ant.processChildren(this.xml, context, this); return true; } + + override protected function processAttribute(name:String, value:String):void + { + if (name == "failonerror") + failonerror = value == "true"; + else + super.processAttribute(name, value); + } } } \ No newline at end of file http://git-wip-us.apache.org/repos/asf/flex-utilities/blob/1d9886dd/ant_on_air/tests/TestTarget.as ---------------------------------------------------------------------- diff --git a/ant_on_air/tests/TestTarget.as b/ant_on_air/tests/TestTarget.as index 722986a..2570c20 100644 --- a/ant_on_air/tests/TestTarget.as +++ b/ant_on_air/tests/TestTarget.as @@ -28,11 +28,13 @@ package import org.apache.flex.ant.tags.Copy; Copy.init(null); import org.apache.flex.ant.tags.Delete; Delete.init(null); import org.apache.flex.ant.tags.Echo; Echo.init(null); + import org.apache.flex.ant.tags.Fail; Fail.init(null); import org.apache.flex.ant.tags.FileSet; FileSet.init(null); import org.apache.flex.ant.tags.FileSetExclude; FileSetExclude.init(null); import org.apache.flex.ant.tags.FileSetInclude; FileSetInclude.init(null); import org.apache.flex.ant.tags.IsSet; IsSet.init(null); import org.apache.flex.ant.tags.Mkdir; Mkdir.init(null); + import org.apache.flex.ant.tags.Not; Not.init(null); import org.apache.flex.ant.tags.OS; OS.init(null); import org.apache.flex.ant.tags.Project; Project.init(null); import org.apache.flex.ant.tags.Property; Property.init(null); @@ -54,6 +56,10 @@ package private function completeHandler(event:Event):void { + if (Ant.project.status) + trace("SUCCESS!"); + else + trace("FAILURE!"); NativeApplication.nativeApplication.exit(); } http://git-wip-us.apache.org/repos/asf/flex-utilities/blob/1d9886dd/ant_on_air/tests/test.xml ---------------------------------------------------------------------- diff --git a/ant_on_air/tests/test.xml b/ant_on_air/tests/test.xml index 8114225..df33ee7 100644 --- a/ant_on_air/tests/test.xml +++ b/ant_on_air/tests/test.xml @@ -48,6 +48,13 @@ <mkdir dir="${basedir}/temp" /> <copy file="${basedir}/test.xml" toFile="${basedir}/temp/copied.xml" /> <available file="${basedir}/temp/copied.xml" property="copied.doesnt.exist" value="got copied" /> + <fail message="test.xml was not copied to temp/copied.xml"> + <condition> + <not> + <available file="${basedir}/temp/copied.xml" /> + </not> + </condition> + </fail> <echo>copied ${copied.doesnt.exist}. Should say: got copied</echo> <copy toDir="${basedir}/temp"> <fileset dir="${basedir}/../src"> @@ -56,14 +63,36 @@ </fileset> </copy> <available file="${basedir}/temp/org/apache/flex/ant/Ant.as" property="ant.doesnt.exist" value="got copied" /> + <fail message="Ant.as was copied to temp"> + <condition> + <available file="${basedir}/temp/org/apache/flex/ant/Ant.as" /> + </condition> + </fail> <echo>Ant.as ${ant.doesnt.exist}. Should NOT say: got copied</echo> <available file="${basedir}/temp/org/apache/flex/ant/tags/Project.as" property="project.doesnt.exist" value="got copied" /> + <fail message="Project.as was not copied to temp"> + <condition> + <not> + <available file="${basedir}/temp/org/apache/flex/ant/tags/Project.as" /> + </not> + </condition> + </fail> <echo>Project.as ${project.doesnt.exist}. Should say: got copied</echo> <delete file="${basedir}/temp/copied.xml" /> <available file="${basedir}/temp/copied.xml" property="copied.doesnt.exist.after.delete" value="didn't get deleted" /> + <fail message="temp/copied.xml was not deleted"> + <condition> + <available file="${basedir}/temp/copied.xml" /> + </condition> + </fail> <echo>copied.xml ${copied.doesnt.exist.after.delete}. Should NOT say: didn't get deleted</echo> <delete dir="${basedir}/temp" /> <available file="${basedir}/temp/org/apache/flex/ant/tags/Project.as" property="project.doesnt.exist.after.delete" value="didn't get deleted" /> + <fail message="temp/copied.xml was not deleted"> + <condition> + <available file="${basedir}/temp/org/apache/flex/ant/tags/Project.as" /> + </condition> + </fail> <echo>Project.as ${project.doesnt.exist.after.delete}. Should NOT say: didn't get deleted</echo> </target>
