[Swift-commit] r3457 - in branches/tests-01: . libexec src/org/griphyn/vdl/karajan/lib/swiftscript tests/language-behaviour
noreply at svn.ci.uchicago.edu
noreply at svn.ci.uchicago.edu
Thu Jul 22 11:34:09 CDT 2010
Author: wozniak
Date: 2010-07-22 11:34:09 -0500 (Thu, 22 Jul 2010)
New Revision: 3457
Added:
branches/tests-01/src/org/griphyn/vdl/karajan/lib/swiftscript/Tracef.java
branches/tests-01/tests/language-behaviour/tracef.swift
Modified:
branches/tests-01/.classpath
branches/tests-01/libexec/vdl-lib.xml
branches/tests-01/src/org/griphyn/vdl/karajan/lib/swiftscript/Java.java
branches/tests-01/src/org/griphyn/vdl/karajan/lib/swiftscript/Misc.java
Log:
Move tracef() to its own class and add test
Modified: branches/tests-01/.classpath
===================================================================
--- branches/tests-01/.classpath 2010-07-21 22:03:40 UTC (rev 3456)
+++ branches/tests-01/.classpath 2010-07-22 16:34:09 UTC (rev 3457)
@@ -21,5 +21,7 @@
<classpathentry combineaccessrules="false" kind="src" path="/provider-wonky"/>
<classpathentry kind="lib" path="lib/jline-0.9.94.jar"/>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
+ <classpathentry kind="lib" path="/util/lib/log4j-1.2.8.jar"/>
+ <classpathentry kind="lib" path="/util/lib/backport-util-concurrent.jar"/>
<classpathentry kind="output" path=".build"/>
</classpath>
Modified: branches/tests-01/libexec/vdl-lib.xml
===================================================================
--- branches/tests-01/libexec/vdl-lib.xml 2010-07-21 22:03:40 UTC (rev 3456)
+++ branches/tests-01/libexec/vdl-lib.xml 2010-07-22 16:34:09 UTC (rev 3457)
@@ -8,14 +8,14 @@
<export name="writedata"><elementDef classname="org.griphyn.vdl.karajan.lib.swiftscript.WriteData"/></export>
<export name="strcat"><elementDef classname="org.griphyn.vdl.karajan.lib.swiftscript.Misc"/></export>
<export name="strcut"><elementDef classname="org.griphyn.vdl.karajan.lib.swiftscript.Misc"/></export>
- <export name="strstr"><elementDef classname="org.griphyn.vdl.karajan.lib.swiftscript.Misc"/></export>
+ <export name="strstr"><elementDef classname="org.griphyn.vdl.karajan.lib.swiftscript.Misc"/></export>
<export name="strsplit"><elementDef classname="org.griphyn.vdl.karajan.lib.swiftscript.Misc"/></export>
<export name="regexp"><elementDef classname="org.griphyn.vdl.karajan.lib.swiftscript.Misc"/></export>
<export name="toint"><elementDef classname="org.griphyn.vdl.karajan.lib.swiftscript.Misc"/></export>
<export name="tofloat"><elementDef classname="org.griphyn.vdl.karajan.lib.swiftscript.Misc"/></export>
<export name="tostring"><elementDef classname="org.griphyn.vdl.karajan.lib.swiftscript.Misc"/></export>
<export name="trace"><elementDef classname="org.griphyn.vdl.karajan.lib.swiftscript.Misc"/></export>
- <export name="tracef"><elementDef classname="org.griphyn.vdl.karajan.lib.swiftscript.Misc"/></export>
+ <export name="tracef"><elementDef classname="org.griphyn.vdl.karajan.lib.swiftscript.Tracef"/></export>
<export name="java"><elementDef classname="org.griphyn.vdl.karajan.lib.swiftscript.Java"/></export>
<export name="fileName"><elementDef classname="org.griphyn.vdl.karajan.lib.swiftscript.FileName"/></export>
<export name="fileNames"><elementDef classname="org.griphyn.vdl.karajan.lib.swiftscript.FileNames"/></export>
@@ -88,7 +88,7 @@
<export name="log"><elementDef classname="org.griphyn.vdl.karajan.lib.Log"/></export>
<export name="kickstart"><elementDef classname="org.griphyn.vdl.karajan.lib.Kickstart"/></export>
-
+
<export name="dirname"><elementDef classname="org.griphyn.vdl.karajan.lib.PathUtils"/></export>
<export name="reldirname"><elementDef classname="org.griphyn.vdl.karajan.lib.PathUtils"/></export>
<export name="basename"><elementDef classname="org.griphyn.vdl.karajan.lib.PathUtils"/></export>
@@ -96,12 +96,12 @@
<export name="hostname"><elementDef classname="org.griphyn.vdl.karajan.lib.PathUtils"/></export>
<export name="dircat"><elementDef classname="org.griphyn.vdl.karajan.lib.PathUtils"/></export>
<export name="pathnames"><elementDef classname="org.griphyn.vdl.karajan.lib.PathUtils"/></export>
-
+
<export name="execute"><elementDef classname="org.griphyn.vdl.karajan.lib.Execute"/></export>
<export name="expandArguments"><elementDef classname="org.griphyn.vdl.karajan.lib.ExpandArguments"/></export>
-
+
<export name="tparallelFor"><elementDef classname="org.griphyn.vdl.karajan.lib.ThrottledParallelFor"/></export>
-
+
<export name="appStageins"><elementDef classname="org.griphyn.vdl.karajan.lib.AppStageins"/></export>
<export name="appStageouts"><elementDef classname="org.griphyn.vdl.karajan.lib.AppStageouts"/></export>
</namespace>
Modified: branches/tests-01/src/org/griphyn/vdl/karajan/lib/swiftscript/Java.java
===================================================================
--- branches/tests-01/src/org/griphyn/vdl/karajan/lib/swiftscript/Java.java 2010-07-21 22:03:40 UTC (rev 3456)
+++ branches/tests-01/src/org/griphyn/vdl/karajan/lib/swiftscript/Java.java 2010-07-22 16:34:09 UTC (rev 3457)
@@ -132,8 +132,8 @@
catch (Exception e) {
e.printStackTrace();
throw new RuntimeException
- ("Error attempting to invoke: " + method.getDeclaringClass() +
- "." + method);
+ ("Error attempting to invoke: " +
+ method.getDeclaringClass() + "." + method);
}
return result;
}
Modified: branches/tests-01/src/org/griphyn/vdl/karajan/lib/swiftscript/Misc.java
===================================================================
--- branches/tests-01/src/org/griphyn/vdl/karajan/lib/swiftscript/Misc.java 2010-07-21 22:03:40 UTC (rev 3456)
+++ branches/tests-01/src/org/griphyn/vdl/karajan/lib/swiftscript/Misc.java 2010-07-22 16:34:09 UTC (rev 3457)
@@ -11,14 +11,12 @@
import org.globus.cog.karajan.util.TypeUtil;
import org.globus.cog.karajan.workflow.ExecutionException;
import org.globus.cog.karajan.workflow.nodes.functions.FunctionsCollection;
-import org.griphyn.vdl.karajan.lib.PathUtils;
import org.griphyn.vdl.karajan.lib.SwiftArg;
import org.griphyn.vdl.karajan.lib.VDLFunction;
import org.griphyn.vdl.mapping.DSHandle;
import org.griphyn.vdl.mapping.HandleOpenException;
import org.griphyn.vdl.mapping.InvalidPathException;
import org.griphyn.vdl.mapping.Path;
-import org.griphyn.vdl.mapping.ArrayDataNode;
import org.griphyn.vdl.mapping.RootArrayDataNode;
import org.griphyn.vdl.mapping.RootDataNode;
import org.griphyn.vdl.type.NoSuchTypeException;
@@ -38,7 +36,6 @@
static {
setArguments("swiftscript_trace", new Arg[] { Arg.VARGS });
- setArguments("swiftscript_tracef", new Arg[] { Arg.VARGS });
setArguments("swiftscript_strcat", new Arg[] { Arg.VARGS });
setArguments("swiftscript_strcut", new Arg[] { PA_INPUT, PA_PATTERN });
setArguments("swiftscript_strstr", new Arg[] { PA_INPUT, PA_PATTERN });
@@ -47,7 +44,7 @@
setArguments("swiftscript_toint", new Arg[] { PA_INPUT });
setArguments("swiftscript_tofloat", new Arg[] { PA_INPUT });
setArguments("swiftscript_tostring", new Arg[] { PA_INPUT });
- setArguments("swiftscript_dirname", new Arg[] { Arg.VARGS });
+ setArguments("swiftscript_dirname", new Arg[] { Arg.VARGS });
}
private static final Logger traceLogger = Logger.getLogger("org.globus.swift.trace");
@@ -67,171 +64,7 @@
traceLogger.warn(buf);
return null;
}
-
- /**
- Formatted trace output. <br>
- Example: tracef("\t%s\n", "hello"); <br>
- Differences from trace():
- 1) respects \t, \n and \\;
- 2) allows for typechecked format specifiers;
- 3) allows for consumption of variables without display (%k);
- 4) does not impose any formatting (commas, etc.). <br><br>
- Format specifiers: <br>
- %%: % sign. <br>
- %p: Not typechecked, output as in trace(). <br>
- %i: Typechecked int output. <br>
- %s: Typechecked string output. <br>
- %k: Variable sKipped, no output.
- */
- public DSHandle swiftscript_tracef(VariableStack stack)
- throws ExecutionException, NoSuchTypeException,
- InvalidPathException {
- DSHandle[] args = SwiftArg.VARGS.asDSHandleArray(stack);
-
- StringBuffer buf = new StringBuffer();
- for (int i = 0; i < args.length; i++) {
- DSHandle handle = args[i];
- VDLFunction.waitFor(stack, handle);
- }
- String msg = format(args);
- buf.append(msg);
- traceLogger.warn(buf);
- return null;
- }
-
- /**
- Helper for {@link #swiftscript_tracef}.
- */
- private String format(DSHandle[] args) throws ExecutionException {
- if (! (args[0].getType() == Types.STRING))
- throw new ExecutionException("First argument to tracef() must be a string!");
-
- String spec = args[0].toString();
- StringBuffer output = new StringBuffer();
- int i = 0;
- int a = 1;
- while (i < spec.length()) {
- char c = spec.charAt(i);
- if (c == '%') {
- char d = spec.charAt(++i);
- a = append(d, a, args, output);
- }
- else if (c == '\\') {
- char d = spec.charAt(++i);
- escape(d, output);
- }
- else {
- output.append(c);
- }
- i++;
- }
- String result = output.toString();
- return result;
- }
-
- /**
- Helper for {@link #swiftscript_tracef}.
- */
- private int append(char c, int arg, DSHandle[] args, StringBuffer output) throws ExecutionException {
- if (c == '%') {
- output.append('%');
- return arg;
- }
- if (arg >= args.length) {
- throw new ExecutionException("tracef(): too many specifiers!");
- }
- if (c == 'p') {
- output.append(args[arg].toString());
- }
- else if (c == 'M') {
- try {
- synchronized (args[arg].getRoot()) {
- String[] names = VDLFunction.filename(args[arg]);
- if (names.length > 1)
- output.append(names);
- else
- output.append(names[0]);
- }
- }
- catch (Exception e) {
- throw new ExecutionException("tracef(%M): Could not lookup: " + args[arg]);
- }
- }
- else if (c == 's') {
- if (args[arg].getType() == Types.STRING) {
- output.append(args[arg]).toString();
- }
- else {
- throw new ExecutionException("tracef(): %s requires a string!");
- }
- }
- else if (c == 'i') {
- if (args[arg].getType() == Types.INT) {
- output.append(args[arg]).toString();
- }
- else {
- throw new ExecutionException("tracef(): %i requires an int!");
- }
- }
- else if (c == 'f') {
- if (args[arg].getType() == Types.FLOAT) {
- output.append(args[arg]).toString();
- }
- else {
- throw new ExecutionException("tracef(): %f requires a float!");
- }
- }
- else if (c == 'q') {
- if (args[arg] instanceof ArrayDataNode) {
- ArrayDataNode node = (ArrayDataNode) args[arg];
- output.append("[");
- try {
- int size = node.size();
- for (int i = 0; i < size; i++) {
- String entry = ""+i;
- DSHandle handle = node.getField(Path.parse(entry));
- output.append(handle);
- if (i < size-1)
- output.append(",");
- }
- }
- catch (Exception e) {
- e.printStackTrace();
- throw new ExecutionException("trace(%q): Could not get children of: " + args[arg]);
- }
- output.append("]");
- }
- else {
- throw new ExecutionException("tracef(): %q requires an array!");
- }
- }
- else if (c == 'k') {
- ;
- }
- else {
- throw new ExecutionException("tracef(): Unknown format: %" + c);
- }
- return arg+1;
- }
-
- /**
- Helper for {@link #swiftscript_tracef}.
- */
- private void escape(char c, StringBuffer output) throws ExecutionException {
- if (c == '\\') {
- output.append('\\');
- }
- else if (c == 'n') {
- output.append('\n');
- }
- else if (c == 't') {
- output.append('\t');
- }
- else {
- throw new ExecutionException("tracef(): unknown backslash escape sequence!");
- }
- }
-
+
public DSHandle swiftscript_strcat(VariableStack stack) throws ExecutionException, NoSuchTypeException,
InvalidPathException {
Object[] args = SwiftArg.VARGS.asArray(stack);
Added: branches/tests-01/src/org/griphyn/vdl/karajan/lib/swiftscript/Tracef.java
===================================================================
--- branches/tests-01/src/org/griphyn/vdl/karajan/lib/swiftscript/Tracef.java (rev 0)
+++ branches/tests-01/src/org/griphyn/vdl/karajan/lib/swiftscript/Tracef.java 2010-07-22 16:34:09 UTC (rev 3457)
@@ -0,0 +1,194 @@
+package org.griphyn.vdl.karajan.lib.swiftscript;
+
+import org.apache.log4j.Logger;
+import org.globus.cog.karajan.arguments.Arg;
+import org.globus.cog.karajan.stack.VariableStack;
+import org.globus.cog.karajan.workflow.ExecutionException;
+import org.griphyn.vdl.karajan.lib.SwiftArg;
+import org.griphyn.vdl.karajan.lib.VDLFunction;
+import org.griphyn.vdl.mapping.ArrayDataNode;
+import org.griphyn.vdl.mapping.DSHandle;
+import org.griphyn.vdl.mapping.Path;
+import org.griphyn.vdl.type.Types;
+
+/**
+ Formatted trace output. <br>
+ Example: tracef("\t%s\n", "hello"); <br>
+ Differences from trace():
+ 1) respects \t, \n and \\;
+ 2) allows for typechecked format specifiers;
+ 3) allows for consumption of variables without display (%k);
+ 4) does not impose any formatting (commas, etc.). <br><br>
+ Format specifiers: <br>
+ %%: % sign. <br>
+ %p: Not typechecked, output as in trace(). <br>
+ %i: Typechecked int output. <br>
+ %s: Typechecked string output. <br>
+ %k: Variable sKipped, no output.
+ */
+public class Tracef extends VDLFunction {
+
+ private static final Logger logger =
+ Logger.getLogger(Tracef.class);
+
+ static {
+ setArguments(Tracef.class, new Arg[] { Arg.VARGS });
+ }
+
+ @Override
+ protected Object function(VariableStack stack)
+ throws ExecutionException {
+ DSHandle[] args = SwiftArg.VARGS.asDSHandleArray(stack);
+
+ for (int i = 0; i < args.length; i++) {
+ DSHandle handle = args[i];
+ VDLFunction.waitFor(stack, handle);
+ }
+ String msg = format(args);
+ logger.info(msg);
+ System.out.print(msg);
+ return null;
+ }
+
+ private String format(DSHandle[] args)
+ throws ExecutionException {
+ if (! (args[0].getType() == Types.STRING))
+ throw new ExecutionException
+ ("First argument to tracef() must be a string!");
+
+ String spec = args[0].toString();
+ StringBuffer output = new StringBuffer();
+ int i = 0;
+ int a = 1;
+ while (i < spec.length()) {
+ char c = spec.charAt(i);
+ if (c == '%') {
+ char d = spec.charAt(++i);
+ a = append(d, a, args, output);
+ }
+ else if (c == '\\') {
+ char d = spec.charAt(++i);
+ escape(d, output);
+ }
+ else {
+ output.append(c);
+ }
+ i++;
+ }
+ String result = output.toString();
+ return result;
+ }
+
+ private int append(char c, int arg, DSHandle[] args,
+ StringBuffer output)
+ throws ExecutionException {
+ if (c == '%') {
+ output.append('%');
+ return arg;
+ }
+ if (arg >= args.length) {
+ throw new ExecutionException
+ ("tracef(): too many specifiers!");
+ }
+ if (c == 'p') {
+ output.append(args[arg].toString());
+ }
+ else if (c == 'M') {
+ try {
+ synchronized (args[arg].getRoot()) {
+ String[] names = VDLFunction.filename(args[arg]);
+ if (names.length > 1)
+ output.append(names);
+ else
+ output.append(names[0]);
+ }
+ }
+ catch (Exception e) {
+ throw new ExecutionException
+ ("tracef(%M): Could not lookup: " + args[arg]);
+ }
+ }
+ else if (c == 's') {
+ if (args[arg].getType() == Types.STRING) {
+ output.append(args[arg]).toString();
+ }
+ else {
+ throw new ExecutionException
+ ("tracef(): %s requires a string!");
+ }
+ }
+ else if (c == 'i') {
+ if (args[arg].getType() == Types.INT) {
+ output.append(args[arg]).toString();
+ }
+ else {
+ throw new ExecutionException
+ ("tracef(): %i requires an int!");
+ }
+ }
+ else if (c == 'f') {
+ if (args[arg].getType() == Types.FLOAT) {
+ output.append(args[arg]).toString();
+ }
+ else {
+ throw new ExecutionException
+ ("tracef(): %f requires a float!");
+ }
+ }
+ else if (c == 'q') {
+ if (args[arg] instanceof ArrayDataNode) {
+ ArrayDataNode node = (ArrayDataNode) args[arg];
+ output.append("[");
+ try {
+ int size = node.size();
+ for (int i = 0; i < size; i++) {
+ String entry = ""+i;
+ DSHandle handle =
+ node.getField(Path.parse(entry));
+ output.append(handle);
+ if (i < size-1)
+ output.append(",");
+ }
+ }
+ catch (Exception e) {
+ e.printStackTrace();
+ throw new ExecutionException
+ ("trace(%q): Could not get children of: " +
+ args[arg]);
+ }
+ output.append("]");
+ }
+ else {
+ throw new ExecutionException
+ ("tracef(): %q requires an array!");
+ }
+ }
+ else if (c == 'k') {
+ ;
+ }
+ else {
+ throw new ExecutionException
+ ("tracef(): Unknown format: %" + c);
+ }
+ return arg+1;
+ }
+
+ private void escape(char c, StringBuffer output)
+ throws ExecutionException {
+ if (c == '\\') {
+ output.append('\\');
+ }
+ else if (c == 'n') {
+ output.append('\n');
+ }
+ else if (c == 't') {
+ output.append('\t');
+ }
+ else {
+ throw new ExecutionException
+ ("tracef(): unknown backslash escape sequence!");
+ }
+ }
+
+
+}
Added: branches/tests-01/tests/language-behaviour/tracef.swift
===================================================================
--- branches/tests-01/tests/language-behaviour/tracef.swift (rev 0)
+++ branches/tests-01/tests/language-behaviour/tracef.swift 2010-07-22 16:34:09 UTC (rev 3457)
@@ -0,0 +1,4 @@
+
+tracef("3:%i\n", 3);
+tracef("4:%s\n", "4");
+tracef("fraction:%f\n", 22.0/7.0);
More information about the Swift-commit
mailing list