Permalink
Browse files

replaced massive.neko.io.FileError with FileException

updated CommandLineRunner tests
added ability to skip a command (skip property) after initialisation has been called
  • Loading branch information...
1 parent 9645c14 commit 7e02cddf2523a178341e3a0b2bec976583d6917e Massive Interactive committed Mar 8, 2011
View
@@ -22,7 +22,7 @@
#run tests
-#-cmd haxe test.hxml
+-cmd haxe test.hxml
-cmd neko mlib.n install
#-cmd neko mlib.n submit
View
BIN mlib.n
Binary file not shown.
@@ -37,7 +37,6 @@ import massive.neko.haxe.HaxeWrapper;
import massive.neko.haxelib.Haxelib;
import massive.neko.haxelib.HaxelibTools;
import massive.neko.io.File;
-import massive.neko.io.FileError;
import massive.neko.io.FileException;
import massive.neko.io.FileSys;
import massive.neko.util.PathUtil;
@@ -43,11 +43,14 @@ class Command implements ICommand
public var postRequisites:Array<CommandInstance>;
public var console:Console;
public var data:Dynamic;
+
+ public var skip(default, null):Bool;
public function new():Void
{
preRequisites = [];
postRequisites = [];
+ skip = false;
}
public function setData(?data:Dynamic = null):Void
@@ -107,8 +107,8 @@ class CommandLineRunner
if(commandClass != null)
{
- var hash:Hash<Dynamic> = new Hash();
- runCommand(commandClass, hash);
+
+ runCommand(commandClass);
exit(0);
}
else if(commandArg == null)
@@ -234,32 +234,34 @@ class CommandLineRunner
/**
* Note - will ignore recursive dependencies to avoid recursion loops!
*/
- private function runCommand(commandClass:Class<ICommand>, ?data:Dynamic=null, ?hash:Hash<Dynamic>=null):Void
+ private function runCommand(commandClass:Class<ICommand>, ?data:Dynamic=null):Void
{
- if(hash == null) hash = new Hash();
-
var className:String = Type.getClassName(commandClass);
- if(hash.exists(className)) return;
-
- hash.set(className, commandClass);
+
var cmd:ICommand = createCommandInstance(commandClass);
cmd.setData(data);
cmd.initialise();
+ if(cmd.skip)
+ {
+ Log.debug("skip " + className);
+ return;
+ }
+
for(pre in cmd.preRequisites)
{
- runCommand(pre.commandClass, pre.data, hash);
+ runCommand(pre.commandClass, pre.data);
}
- Log.debug(className);
+ Log.debug("execute " + className);
cmd.execute();
-
+
for(post in cmd.postRequisites)
{
- runCommand(post.commandClass, post.data, hash);
+ runCommand(post.commandClass, post.data);
}
}
@@ -30,7 +30,7 @@
package massive.neko.cmd;
import massive.neko.io.File;
-import massive.neko.io.FileError;
+import massive.neko.io.FileException;
import massive.neko.io.FileSys;
import neko.FileSystem;
import neko.vm.Thread;
@@ -211,7 +211,7 @@ class Console
{
file = File.create(path);
}
- catch(e:FileError)
+ catch(e:FileException)
{
//Log.info(e + "\n" + a);
}
@@ -59,6 +59,9 @@ interface ICommand
var console:Console;
+ var skip(default, null):Bool;
+
+
function setData(?data:Dynamic=null):Void;
/**
@@ -91,6 +91,8 @@ class File
public static function create(path:String, ?file:File=null, ?posInfos:PosInfos):File
{
+
+
if(FileSys.isWindows && path.indexOf(":") == 1 && path.lastIndexOf("/") == path.length-1)
{
path = path.substr(0, -1) + "\\";
@@ -102,15 +104,23 @@ class File
}
else if(file != null)
{
- return file.resolvePath(path);
+ try
+ {
+ return file.resolvePath(path);
+ }
+ catch(e:Dynamic)
+ {
+ throw new FileException("Unable to resolve path ( " + path + " ) aginst file ( " + file.nativePath + " ) " + e);
+ }
+
}
else if(path == ".")
{
return File.current;
}
else
{
- throw new FileError("Path isn't absolute and no reference path provided", null, path, posInfos);
+ throw new FileException("Path isn't absolute and no reference file provided: " + path);
}
return null;
}
@@ -260,7 +270,7 @@ class File
}
else if(type != existingType)
{
- throw new FileError("Specified type doesn't match file/dir in system.", this, [type, existingType]);
+ throw new FileException("Specified type doesn't match file/dir in system: " + [type, existingType], this);
}
@@ -345,19 +355,23 @@ class File
}
else
{
+ var p:File = this;
+
+ if(isFile) p = this.parent;
+
if(value.indexOf("./") == 0)
{
- value = value.substr(2);
+ value = value.substr(2);
}
- var p:File = this;
+
while(value.indexOf("../") == 0)
{
p = p.parent;
if(p == null)
{
- throw new FileError("Invalid path.", this, value, posInfos);
+ throw new FileException("Invalid path: " + value, this);
}
value = value.substr(3);
}
@@ -524,7 +538,7 @@ class File
{
if(isFile)
{
- throw new FileError("Cannot call createDirectory for a file.", this, nativePath);
+ throw new FileException("Cannot call createDirectory for a file ", this);
}
if(parent != null && !parent.exists) parent.createDirectory(true);
@@ -569,7 +583,7 @@ class File
if(!isDirectory)
{
- throw new FileError("cannot deleteDirectory for type " + type, this);
+ throw new FileException("cannot deleteDirectory for type: " + type, this);
}
if(deleteContents == false && !isEmpty)
@@ -627,11 +641,11 @@ class File
{
if(isDirectory)
{
- throw new FileError("Cannot call createFile for a directory object.", this);
+ throw new FileException("Cannot call createFile for a directory object.", this);
}
else if(isFile && exists)
{
- throw new FileError("File already exists", this);
+ throw new FileException("File already exists", this);
}
if(isUnknown)
@@ -659,7 +673,7 @@ class File
}
catch(e:Dynamic)
{
- throw new FileError("Error deleting directory", this, e);
+ throw new FileException("Error deleting directory (" + e + ")", this);
}
}
@@ -675,11 +689,11 @@ class File
{
if(!exists)
{
- throw new FileError("Cannot copy a file or directory that doesn't exist.", this);
+ throw new FileException("Cannot copy a file or directory that doesn't exist.", this);
}
if(isDirectory && !dst.isDirectory)
{
- throw new FileError("Cannot copy a directory to a file.", this, dst.toDebugString());
+ throw new FileException("Cannot copy a directory to a file (" + dst + ")", this);
}
@@ -750,7 +764,7 @@ class File
{
if(!dst.isDirectory)
{
- throw new FileError("Cannot copy a directory to a file.", this, dst.toDebugString());
+ throw new FileException("Cannot copy a directory to a file (" + dst +")", this);
}
if(isDirectory)
@@ -792,7 +806,7 @@ class File
{
if(!dst.isDirectory)
{
- throw new FileError("Cannot move a directory to a file.", this, dst.toDebugString());
+ throw new FileException("Cannot move a directory to a file (" + dst + ")", this);
return;
}
@@ -815,7 +829,7 @@ class File
{
if(isDirectory)
{
- throw new FileError("Cannot write string to a file object.", this);
+ throw new FileException("Cannot write string to a file object.", this);
}
if(!parent.exists) parent.createDirectory(true);
@@ -840,12 +854,12 @@ class File
if(!exists && isFile)
{
return null;
- //throw new FileError("File doesn't exist.", this);
+ //throw new FileException("File doesn't exist.", this);
}
if(!exists || !isFile)
{
- throw new FileError("File isn't of type file. Cannot load string content.", this);
+ throw new FileException("File isn't of type file. Cannot load string content.", this);
}
@@ -855,7 +869,7 @@ class File
}
catch(e:Dynamic)
{
- throw new FileError("Unknown", this, e);
+ throw new FileException("Unknown error (" + e + ")", this);
}
@@ -869,7 +883,7 @@ class File
{
if(!isDirectory)
{
- throw new FileError("Cannot get directory listing for a file object.", this);
+ throw new FileException("Cannot get directory listing for a file object.", this);
}
if(!exists)
{
@@ -1,56 +0,0 @@
-/****
-* Copyright 2011 Massive Interactive. All rights reserved.
-*
-* Redistribution and use in source and binary forms, with or without modification, are
-* permitted provided that the following conditions are met:
-*
-* 1. Redistributions of source code must retain the above copyright notice, this list of
-* conditions and the following disclaimer.
-*
-* 2. Redistributions in binary form must reproduce the above copyright notice, this list
-* of conditions and the following disclaimer in the documentation and/or other materials
-* provided with the distribution.
-*
-* THIS SOFTWARE IS PROVIDED BY MASSIVE INTERACTIVE "AS IS" AND ANY EXPRESS OR IMPLIED
-* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
-* FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL MASSIVE INTERACTIVE OR
-* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
-* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
-* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
-* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
-* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
-* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-*
-* The views and conclusions contained in the software and documentation are those of the
-* authors and should not be interpreted as representing official policies, either expressed
-* or implied, of Massive Interactive.
-*
-****/
-
-package massive.neko.io;
-
-import massive.neko.io.File;
-import haxe.PosInfos;
-
-
-class FileError
-{
- public var error:String;
- public var message:String;
- public var file:File;
- public var posInfos:PosInfos;
-
- public function new(error:String, file:File, ?message:Dynamic=null, ?posInfos:PosInfos=null):Void
- {
- this.error = error;
- this.file = file;
- this.message = Std.string(message);
- this.posInfos = posInfos;
- }
-
- public function toString():String
- {
- return error + "\n " + (message != null ? "message: " + message + "\n" : "") + (file != null ? file.toDebugString() + "\n" : "" )+ posInfos + "\n" + haxe.Stack.toString(haxe.Stack.callStack());
- }
-}
-
@@ -33,8 +33,23 @@ import haxe.PosInfos;
class FileException extends Exception
{
- public function new(message:String, ?posInfos:PosInfos)
+ public var file:File;
+ public function new(message:String, ?file:File=null, ?posInfos:PosInfos)
{
+ this.file = file;
super(message, posInfos);
}
+
+ override public function toString():String
+ {
+ var str:String = super.toString();
+
+ if(file != null)
+ {
+ str += "[File=" + file.nativePath + "]";
+ }
+
+
+ return str;
+ }
}
Oops, something went wrong.

0 comments on commit 7e02cdd

Please sign in to comment.