add Replace, LoadProperties and PropertyFile tasks, and Equals condition
Project: http://git-wip-us.apache.org/repos/asf/flex-utilities/repo Commit: http://git-wip-us.apache.org/repos/asf/flex-utilities/commit/505b253d Tree: http://git-wip-us.apache.org/repos/asf/flex-utilities/tree/505b253d Diff: http://git-wip-us.apache.org/repos/asf/flex-utilities/diff/505b253d Branch: refs/heads/develop Commit: 505b253d88217fba475ed6590820f2a1832fd833 Parents: 321ebd7 Author: Alex Harui <[email protected]> Authored: Wed Dec 11 12:02:41 2013 -0800 Committer: Alex Harui <[email protected]> Committed: Wed Dec 11 12:02:41 2013 -0800 ---------------------------------------------------------------------- ant_on_air/src/AntClasses.as | 4 + .../src/org/apache/flex/ant/tags/Entry.as | 51 ++++++++++ .../src/org/apache/flex/ant/tags/Equals.as | 76 ++++++++++++++ .../org/apache/flex/ant/tags/LoadProperties.as | 100 +++++++++++++++++++ .../org/apache/flex/ant/tags/PropertyFile.as | 90 +++++++++++++++++ .../src/org/apache/flex/ant/tags/Replace.as | 78 +++++++++++++++ ant_on_air/tests/test.xml | 33 ++++++ 7 files changed, 432 insertions(+) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/flex-utilities/blob/505b253d/ant_on_air/src/AntClasses.as ---------------------------------------------------------------------- diff --git a/ant_on_air/src/AntClasses.as b/ant_on_air/src/AntClasses.as index ddb6a65..cd4a0f2 100644 --- a/ant_on_air/src/AntClasses.as +++ b/ant_on_air/src/AntClasses.as @@ -30,16 +30,20 @@ package import org.apache.flex.ant.tags.Copy; Copy; import org.apache.flex.ant.tags.Delete; Delete; import org.apache.flex.ant.tags.Echo; Echo; + import org.apache.flex.ant.tags.Equals; Equals; import org.apache.flex.ant.tags.Fail; Fail; import org.apache.flex.ant.tags.FileSet; FileSet; import org.apache.flex.ant.tags.FileSetExclude; FileSetExclude; import org.apache.flex.ant.tags.FileSetInclude; FileSetInclude; import org.apache.flex.ant.tags.Get; Get; import org.apache.flex.ant.tags.IsSet; IsSet; + import org.apache.flex.ant.tags.LoadProperties; LoadProperties; import org.apache.flex.ant.tags.Mkdir; Mkdir; import org.apache.flex.ant.tags.Not; Not; import org.apache.flex.ant.tags.OS; OS; import org.apache.flex.ant.tags.Property; Property; + import org.apache.flex.ant.tags.PropertyFile; PropertyFile; + import org.apache.flex.ant.tags.Replace; Replace; import org.apache.flex.ant.tags.Untar; Untar; import org.apache.flex.ant.tags.Unzip; Unzip; } http://git-wip-us.apache.org/repos/asf/flex-utilities/blob/505b253d/ant_on_air/src/org/apache/flex/ant/tags/Entry.as ---------------------------------------------------------------------- diff --git a/ant_on_air/src/org/apache/flex/ant/tags/Entry.as b/ant_on_air/src/org/apache/flex/ant/tags/Entry.as new file mode 100644 index 0000000..6435df6 --- /dev/null +++ b/ant_on_air/src/org/apache/flex/ant/tags/Entry.as @@ -0,0 +1,51 @@ +//////////////////////////////////////////////////////////////////////////////// +// +// 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 var key:String; + public var value:String; + + override protected function processAttribute(name:String, value:String):void + { + if (name == "key") + key = value; + else if (name == value) + this.value = value; + } + + } +} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/flex-utilities/blob/505b253d/ant_on_air/src/org/apache/flex/ant/tags/Equals.as ---------------------------------------------------------------------- diff --git a/ant_on_air/src/org/apache/flex/ant/tags/Equals.as b/ant_on_air/src/org/apache/flex/ant/tags/Equals.as new file mode 100644 index 0000000..66af57b --- /dev/null +++ b/ant_on_air/src/org/apache/flex/ant/tags/Equals.as @@ -0,0 +1,76 @@ +//////////////////////////////////////////////////////////////////////////////// +// +// 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 var arg1:String; + private var arg2:String; + private var casesensitive:Boolean; + private var trim:Boolean; + + public function get value():Object + { + 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; + } + + override protected function processAttribute(name:String, value:String):void + { + if (name == "arg1") + arg1 = value; + else if (name == "arg2") + arg2 = value; + else if (name == "casesensitive") + casesensitive = value == "true"; + else if (name == "trim") + casesensitive = value == "true"; + } + + } +} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/flex-utilities/blob/505b253d/ant_on_air/src/org/apache/flex/ant/tags/LoadProperties.as ---------------------------------------------------------------------- diff --git a/ant_on_air/src/org/apache/flex/ant/tags/LoadProperties.as b/ant_on_air/src/org/apache/flex/ant/tags/LoadProperties.as new file mode 100644 index 0000000..54ffb5f --- /dev/null +++ b/ant_on_air/src/org/apache/flex/ant/tags/LoadProperties.as @@ -0,0 +1,100 @@ +//////////////////////////////////////////////////////////////////////////////// +// +// 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; + import org.apache.flex.xml.XMLTagProcessor; + + [Mixin] + public class LoadProperties extends TaskHandler + { + public static function init(mf:IFlexModuleFactory):void + { + Ant.antTagProcessors["loadproperties"] = LoadProperties; + } + + public function LoadProperties() + { + } + + override public function init(xml:XML, context:Object, xmlProcessor:XMLTagProcessor):void + { + super.init(xml, context, xmlProcessor); + } + + override public function execute(callbackMode:Boolean):Boolean + { + var f:File = new File(fileName); + 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 var fileName:String; + + override protected function processAttribute(name:String, value:String):void + { + if (name == "srcFile") + { + fileName = value; + } + else + super.processAttribute(name, value); + } + + + } +} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/flex-utilities/blob/505b253d/ant_on_air/src/org/apache/flex/ant/tags/PropertyFile.as ---------------------------------------------------------------------- diff --git a/ant_on_air/src/org/apache/flex/ant/tags/PropertyFile.as b/ant_on_air/src/org/apache/flex/ant/tags/PropertyFile.as new file mode 100644 index 0000000..25c1627 --- /dev/null +++ b/ant_on_air/src/org/apache/flex/ant/tags/PropertyFile.as @@ -0,0 +1,90 @@ +//////////////////////////////////////////////////////////////////////////////// +// +// 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; + import org.apache.flex.xml.XMLTagProcessor; + + [Mixin] + public class PropertyFile extends TaskHandler + { + public static function init(mf:IFlexModuleFactory):void + { + Ant.antTagProcessors["propertyfile"] = PropertyFile; + } + + public function PropertyFile() + { + } + + override public function init(xml:XML, context:Object, xmlProcessor:XMLTagProcessor):void + { + super.init(xml, context, xmlProcessor); + } + + override public function execute(callbackMode:Boolean):Boolean + { + super.execute(callbackMode); + var f:File = new File(fileName); + 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; + if (entry) + { + var s:String = entry.key + "=" + entry.value + "\n"; + fs.writeUTFBytes(s); + } + } + fs.close(); + return true; + } + + private var fileName:String; + + override protected function processAttribute(name:String, value:String):void + { + if (name == "file") + { + fileName = value; + } + else + super.processAttribute(name, value); + } + + + } +} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/flex-utilities/blob/505b253d/ant_on_air/src/org/apache/flex/ant/tags/Replace.as ---------------------------------------------------------------------- diff --git a/ant_on_air/src/org/apache/flex/ant/tags/Replace.as b/ant_on_air/src/org/apache/flex/ant/tags/Replace.as new file mode 100644 index 0000000..0a1fe04 --- /dev/null +++ b/ant_on_air/src/org/apache/flex/ant/tags/Replace.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 flash.events.Event; + 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 var file:String; + private var token:String; + private var value:String; + + override protected function processAttribute(name:String, value:String):void + { + if (name == "file") + file = value; + else if (name == "token") + token = value; + else if (name == "value") + this.value = value; + else + super.processAttribute(name, value); + } + + override public function execute(callbackMode:Boolean):Boolean + { + super.execute(callbackMode); + + var f:File = File.applicationDirectory.resolvePath(file); + var fs:FileStream = new FileStream(); + fs.open(f, FileMode.READ); + var s:String = fs.readUTFBytes(fs.bytesAvailable); + fs.close(); + var regex:RegExp = new RegExp(token, "g"); + s = s.replace(regex, value); + fs.open(f, FileMode.WRITE); + fs.writeUTFBytes(s); + fs.close(); + return true; + } + } +} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/flex-utilities/blob/505b253d/ant_on_air/tests/test.xml ---------------------------------------------------------------------- diff --git a/ant_on_air/tests/test.xml b/ant_on_air/tests/test.xml index 73ab2de..82a8089 100644 --- a/ant_on_air/tests/test.xml +++ b/ant_on_air/tests/test.xml @@ -110,6 +110,11 @@ <checksum file="${basedir}/temp/apache-rat-0.10-src.zip" todir="${basedir}/temp" verifyproperty="rat.md5" /> <echo>rat checksum match = ${rat.md5}</echo> + <fail message="checksum did not match"> + <condition> + <equals arg1="${rat.md5}" arg2="false" /> + </condition> + </fail> <mkdir dir="${basedir}/temp/unzip" /> <unzip src="${basedir}/temp/apache-rat-0.10-src.zip" dest="${basedir}/temp/unzip" /> <fail message="unzip did not result in expected files"> @@ -137,6 +142,34 @@ </not> </condition> </fail> + <propertyfile file="${basedir}/temp/custom.properties" > + <entry key="somekey" value="somevalue" /> + <entry key="somekey1" value="somevalue1" /> + </propertyfile> + <fail message="propertyfile did not result in expected file"> + <condition> + <not> + <available file="${basedir}/temp/custom.properties" /> + </not> + </condition> + </fail> + <replace file="${basedir}/temp/custom.properties" token="somekey" value="replacedkey" /> + <loadproperties srcFile="${basedir}/temp/custom.properties" /> + <fail message="replace did not work: found somekey"> + <condition> + <isset property="somekey" /> + </condition> + </fail> + <fail message="replace did not work: did not find replacedkey"> + <condition> + <equals arg1="${replacedkey}" arg2="somevalue" /> + </condition> + </fail> + <fail message="replace did not work: did not find replacedkey1"> + <condition> + <equals arg1="${replacedkey1}" arg2="somevalue1" /> + </condition> + </fail> <delete dir="${basedir}/temp" /> <available file="${basedir}/temp/org/apache/flex/ant/tags/Project.as" property="project.doesnt.exist.after.delete" value="didn't get deleted" /> <fail message="temp/copied.xml was not deleted">
