Updated Branches:
  refs/heads/develop 0dace696b -> e5fea860d

add Move task


Project: http://git-wip-us.apache.org/repos/asf/flex-utilities/repo
Commit: http://git-wip-us.apache.org/repos/asf/flex-utilities/commit/15de3174
Tree: http://git-wip-us.apache.org/repos/asf/flex-utilities/tree/15de3174
Diff: http://git-wip-us.apache.org/repos/asf/flex-utilities/diff/15de3174

Branch: refs/heads/develop
Commit: 15de3174a8fdc3549b3cd40eb8602edc004686cd
Parents: 0dace69
Author: Alex Harui <aha...@apache.org>
Authored: Thu Jan 2 22:19:13 2014 -0800
Committer: Alex Harui <aha...@apache.org>
Committed: Thu Jan 2 22:19:13 2014 -0800

----------------------------------------------------------------------
 ant_on_air/src/AntClasses.as                    |   1 +
 ant_on_air/src/org/apache/flex/ant/tags/Move.as | 200 +++++++++++++++++++
 ant_on_air/tests/test.xml                       |  10 +
 3 files changed, 211 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/flex-utilities/blob/15de3174/ant_on_air/src/AntClasses.as
----------------------------------------------------------------------
diff --git a/ant_on_air/src/AntClasses.as b/ant_on_air/src/AntClasses.as
index d781e69..95542c2 100644
--- a/ant_on_air/src/AntClasses.as
+++ b/ant_on_air/src/AntClasses.as
@@ -45,6 +45,7 @@ package
             import org.apache.flex.ant.tags.LoadProperties; LoadProperties;
                        import org.apache.flex.ant.tags.Matches; Matches;
             import org.apache.flex.ant.tags.Mkdir; Mkdir;
+            import org.apache.flex.ant.tags.Move; Move;
             import org.apache.flex.ant.tags.Not; Not;
             import org.apache.flex.ant.tags.OS; OS;
                        import org.apache.flex.ant.tags.Param; Param;

http://git-wip-us.apache.org/repos/asf/flex-utilities/blob/15de3174/ant_on_air/src/org/apache/flex/ant/tags/Move.as
----------------------------------------------------------------------
diff --git a/ant_on_air/src/org/apache/flex/ant/tags/Move.as 
b/ant_on_air/src/org/apache/flex/ant/tags/Move.as
new file mode 100644
index 0000000..3b403cc
--- /dev/null
+++ b/ant_on_air/src/org/apache/flex/ant/tags/Move.as
@@ -0,0 +1,200 @@
+////////////////////////////////////////////////////////////////////////////////
+//
+//  Licensed to the Apache Software Foundation (ASF) under one or more
+//  contributor license agreements.  See the NOTICE file distributed with
+//  this work for additional information regarding copyright ownership.
+//  The ASF licenses this file to You under the Apache License, Version 2.0
+//  (the "License"); you may not use this file except in compliance with
+//  the License.  You may obtain a copy of the License at
+//
+//      http://www.apache.org/licenses/LICENSE-2.0
+//
+//  Unless required by applicable law or agreed to in writing, software
+//  distributed under the License is distributed on an "AS IS" BASIS,
+//  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+//  See the License for the specific language governing permissions and
+//  limitations under the License.
+//
+////////////////////////////////////////////////////////////////////////////////
+package org.apache.flex.ant.tags
+{
+    import flash.filesystem.File;
+    
+    import mx.core.IFlexModuleFactory;
+    import mx.resources.ResourceManager;
+    
+    import org.apache.flex.ant.Ant;
+    import org.apache.flex.ant.tags.supportClasses.FileSetTaskHandler;
+    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.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.status = false;
+                return;                                                        
+            }
+            
+            srcFile.moveTo(destFile, overwrite);
+        }
+        
+        override protected function outputTotal(total:int):void
+        {
+            var s:String = ResourceManager.getInstance().getString('ant', 
'COPYFILES');
+            s = s.replace("%1", total.toString());
+            s = s.replace("%2", toDirName);
+            ant.output(ant.formatOutput("copy", s));
+        }
+        
+        override public function execute(callbackMode:Boolean, 
context:Object):Boolean
+        {
+            var retVal:Boolean = super.execute(callbackMode, context);
+            if (numChildren > 0)
+                return retVal;
+            
+            try {
+                var srcFile:File = 
File.applicationDirectory.resolvePath(fileName);
+            } 
+            catch (e:Error)
+            {
+                ant.output(fileName);
+                ant.output(e.message);
+                if (failonerror)
+                    ant.project.status = false;
+                return true;                                                   
+            }
+            
+            try {
+                var destFile:File = 
File.applicationDirectory.resolvePath(toFileName);
+            } 
+            catch (e:Error)
+            {
+                ant.output(toFileName);
+                ant.output(e.message);
+                if (failonerror)
+                    ant.project.status = false;
+                return true;                                                   
+            }
+            
+            //var destDir:File = destFile.parent;
+            //var resolveName:String = 
destFile.nativePath.substr(destFile.nativePath.lastIndexOf(File.separator) + 1);
+            //destDir.resolvePath(resolveName);
+            
+            var s:String = ResourceManager.getInstance().getString('ant', 
'COPY');
+            s = s.replace("%1", "1");
+            s = s.replace("%2", destFile.nativePath);
+            ant.output(ant.formatOutput("copy", s));
+            srcFile.copyTo(destFile, overwrite);
+            return true;
+        }
+    }
+}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/flex-utilities/blob/15de3174/ant_on_air/tests/test.xml
----------------------------------------------------------------------
diff --git a/ant_on_air/tests/test.xml b/ant_on_air/tests/test.xml
index dafa981..ecc57ca 100644
--- a/ant_on_air/tests/test.xml
+++ b/ant_on_air/tests/test.xml
@@ -74,6 +74,16 @@
             </condition>
         </fail>
         <echo>copied ${copied.doesnt.exist}.  Should say: got copied</echo>
+        <move file="${basedir}/temp/copied.xml" 
toFile="${basedir}/temp/moved.xml" />
+        <available file="${basedir}/temp/moved.xml" 
property="moved.doesnt.exist" value="got moved" />
+        <fail message="copied.xml was not moved to temp/moved.xml">
+            <condition>
+                <not>
+                    <available file="${basedir}/temp/moved.xml" />
+                </not>
+            </condition>
+        </fail>
+        <echo>moved ${moved.doesnt.exist}.  Should say: got moved</echo>
         <copy todir="${basedir}/temp">
             <fileset dir="${basedir}/../src">
                 <include name="**/**" />

Reply via email to