Less spammy ant task error reporting, further narya-tools dependencies.

git-svn-id: svn+ssh://src.earth.threerings.net/narya/trunk@5864 542714f4-19e9-0310-aa3c-eee0fc999fb1
This commit is contained in:
Michael Bayne
2009-07-12 22:19:22 +00:00
parent f7152e9ac6
commit 4bcc8ab7c4
5 changed files with 148 additions and 215 deletions
+2 -4
View File
@@ -236,10 +236,8 @@
<jar destfile="${deploy.dir}/${lib.name}-tools.jar"> <jar destfile="${deploy.dir}/${lib.name}-tools.jar">
<fileset dir="${classes.dir}"> <fileset dir="${classes.dir}">
<include name="com/threerings/io/**"/> <include name="com/threerings/io/**"/>
<include name="com/threerings/presents/annotation/**"/> <include name="com/threerings/presents/**"/>
<include name="com/threerings/presents/dobj/**"/> <include name="com/threerings/util/**"/>
<include name="com/threerings/**/tools/**"/>
<include name="com/threerings/**/tools.properties"/>
</fileset> </fileset>
<zipfileset src="${deploy.dir}/lib/samskivert.jar"/> <zipfileset src="${deploy.dir}/lib/samskivert.jar"/>
<zipfileset src="${deploy.dir}/lib/velocity-1.5-dev.jar"/> <zipfileset src="${deploy.dir}/lib/velocity-1.5-dev.jar"/>
@@ -118,32 +118,25 @@ public class GenDObjectTask extends Task
/** Processes a distributed object source file. */ /** Processes a distributed object source file. */
protected void processObject (File source) protected void processObject (File source)
{ {
// System.err.println("Processing " + source + "...");
// load up the file and determine it's package and classname // load up the file and determine it's package and classname
String name = null; String name = null;
try { try {
// System.err.println("Processing " + source + "...");
name = GenUtil.readClassName(source); name = GenUtil.readClassName(source);
} catch (Exception e) {
System.err.println(
"Failed to parse " + source + ": " + e.getMessage());
}
try {
processObject(source, _cloader.loadClass(name)); processObject(source, _cloader.loadClass(name));
} catch (ClassNotFoundException cnfe) { } catch (ClassNotFoundException cnfe) {
System.err.println( System.err.println("Failed to load " + name + ".\n" +
"Failed to load " + name + ".\n" + "Missing class: " + cnfe.getMessage());
"Missing class: " + cnfe.getMessage()); System.err.println("Be sure to set the 'classpathref' attribute to a classpath\n" +
System.err.println( "that contains your projects invocation service classes.");
"Be sure to set the 'classpathref' attribute to a classpath\n" +
"that contains your projects invocation service classes.");
} catch (Exception e) { } catch (Exception e) {
e.printStackTrace(System.err); throw new BuildException("Failed to process " + source.getName() + ": " + e, e);
} }
} }
/** Processes a resolved distributed object class instance. */ /** Processes a resolved distributed object class instance. */
protected void processObject (File source, Class<?> oclass) protected void processObject (File source, Class<?> oclass)
throws Exception
{ {
// make sure we extend distributed object // make sure we extend distributed object
if (!_doclass.isAssignableFrom(oclass) || _doclass.equals(oclass)) { if (!_doclass.isAssignableFrom(oclass) || _doclass.equals(oclass)) {
@@ -166,12 +159,7 @@ public class GenDObjectTask extends Task
// slurp our source file into newline separated strings // slurp our source file into newline separated strings
SourceFile sfile = new SourceFile(); SourceFile sfile = new SourceFile();
try { sfile.readFrom(source);
sfile.readFrom(source);
} catch (IOException ioe) {
System.err.println("Error reading '" + source + "': " + ioe);
return;
}
// generate our fields section and our methods section // generate our fields section and our methods section
StringBuilder fsection = new StringBuilder(); StringBuilder fsection = new StringBuilder();
@@ -244,13 +232,8 @@ public class GenDObjectTask extends Task
// now generate our bits // now generate our bits
StringWriter fwriter = new StringWriter(); StringWriter fwriter = new StringWriter();
StringWriter mwriter = new StringWriter(); StringWriter mwriter = new StringWriter();
try { _velocity.mergeTemplate(NAME_TMPL, "UTF-8", ctx, fwriter);
_velocity.mergeTemplate(NAME_TMPL, "UTF-8", ctx, fwriter); _velocity.mergeTemplate(BASE_TMPL + tname, "UTF-8", ctx, mwriter);
_velocity.mergeTemplate(
BASE_TMPL + tname, "UTF-8", ctx, mwriter);
} catch (Exception e) {
throw new BuildException("Failed processing template", e);
}
// and append them as appropriate to the string buffers // and append them as appropriate to the string buffers
if (ii > 0) { if (ii > 0) {
@@ -262,11 +245,7 @@ public class GenDObjectTask extends Task
} }
// now bolt everything back together into a class declaration // now bolt everything back together into a class declaration
try { sfile.writeTo(source, fsection.toString(), msection.toString());
sfile.writeTo(source, fsection.toString(), msection.toString());
} catch (IOException ioe) {
System.err.println("Error writing '" + source + "': " + ioe);
}
} }
/** A list of filesets that contain tile images. */ /** A list of filesets that contain tile images. */
@@ -47,6 +47,7 @@ public class GenReceiverTask extends InvocationTask
{ {
@Override @Override
protected void processService (File source, Class<?> receiver) protected void processService (File source, Class<?> receiver)
throws Exception
{ {
System.out.println("Processing " + receiver.getName() + "..."); System.out.println("Processing " + receiver.getName() + "...");
String rname = receiver.getName(); String rname = receiver.getName();
@@ -95,6 +96,7 @@ public class GenReceiverTask extends InvocationTask
protected void generateSender (File source, String rname, String rpackage, protected void generateSender (File source, String rname, String rpackage,
List<?> methods, Iterator<String> imports) List<?> methods, Iterator<String> imports)
throws Exception
{ {
String name = StringUtil.replace(rname, "Receiver", ""); String name = StringUtil.replace(rname, "Receiver", "");
String spackage = StringUtil.replace(rpackage, ".client", ".server"); String spackage = StringUtil.replace(rpackage, ".client", ".server");
@@ -115,25 +117,19 @@ public class GenReceiverTask extends InvocationTask
ctx.put("methods", methods); ctx.put("methods", methods);
ctx.put("imports", implist); ctx.put("imports", implist);
try { StringWriter sw = new StringWriter();
StringWriter sw = new StringWriter(); _velocity.mergeTemplate(SENDER_TMPL, "UTF-8", ctx, sw);
_velocity.mergeTemplate(SENDER_TMPL, "UTF-8", ctx, sw);
// determine the path to our sender file // determine the path to our sender file
String mpath = source.getPath(); String mpath = source.getPath();
mpath = StringUtil.replace(mpath, "Receiver", "Sender"); mpath = StringUtil.replace(mpath, "Receiver", "Sender");
mpath = replacePath(mpath, "/client/", "/server/"); mpath = replacePath(mpath, "/client/", "/server/");
writeFile(mpath, sw.toString());
writeFile(mpath, sw.toString());
} catch (Exception e) {
System.err.println("Failed processing template");
e.printStackTrace(System.err);
}
} }
protected void generateDecoder ( protected void generateDecoder (File source, String rname, String rpackage,
File source, String rname, String rpackage, List<?> methods, Iterator<String> imports) List<?> methods, Iterator<String> imports)
throws Exception
{ {
String name = StringUtil.replace(rname, "Receiver", ""); String name = StringUtil.replace(rname, "Receiver", "");
@@ -150,20 +146,13 @@ public class GenReceiverTask extends InvocationTask
ctx.put("methods", methods); ctx.put("methods", methods);
ctx.put("imports", implist); ctx.put("imports", implist);
try { StringWriter sw = new StringWriter();
StringWriter sw = new StringWriter(); _velocity.mergeTemplate(DECODER_TMPL, "UTF-8", ctx, sw);
_velocity.mergeTemplate(DECODER_TMPL, "UTF-8", ctx, sw);
// determine the path to our sender file // determine the path to our sender file
String mpath = source.getPath(); String mpath = source.getPath();
mpath = StringUtil.replace(mpath, "Receiver", "Decoder"); mpath = StringUtil.replace(mpath, "Receiver", "Decoder");
writeFile(mpath, sw.toString());
writeFile(mpath, sw.toString());
} catch (Exception e) {
System.err.println("Failed processing template");
e.printStackTrace(System.err);
}
} }
/** Specifies the path to the sender template. */ /** Specifies the path to the sender template. */
@@ -29,6 +29,7 @@ import java.util.HashSet;
import java.io.File; import java.io.File;
import java.io.StringWriter; import java.io.StringWriter;
import org.apache.tools.ant.BuildException;
import org.apache.velocity.VelocityContext; import org.apache.velocity.VelocityContext;
import com.google.common.base.Predicate; import com.google.common.base.Predicate;
@@ -173,6 +174,7 @@ public class GenServiceTask extends InvocationTask
// documentation inherited // documentation inherited
@Override @Override
protected void processService (File source, Class<?> service) protected void processService (File source, Class<?> service)
throws Exception
{ {
System.out.println("Processing " + service.getName() + "..."); System.out.println("Processing " + service.getName() + "...");
@@ -195,6 +197,7 @@ public class GenServiceTask extends InvocationTask
} }
protected void generateMarshaller (File source, ServiceDescription sdesc, boolean skipAS) protected void generateMarshaller (File source, ServiceDescription sdesc, boolean skipAS)
throws Exception
{ {
if (_verbose) { if (_verbose) {
System.out.println("Generating marshaller"); System.out.println("Generating marshaller");
@@ -253,15 +256,9 @@ public class GenServiceTask extends InvocationTask
mpath = StringUtil.replace(mpath, "Service", "Marshaller"); mpath = StringUtil.replace(mpath, "Service", "Marshaller");
mpath = replacePath(mpath, "/client/", "/data/"); mpath = replacePath(mpath, "/client/", "/data/");
try { StringWriter sw = new StringWriter();
StringWriter sw = new StringWriter(); _velocity.mergeTemplate(MARSHALLER_TMPL, "UTF-8", ctx, sw);
_velocity.mergeTemplate(MARSHALLER_TMPL, "UTF-8", ctx, sw); writeFile(mpath, sw.toString());
writeFile(mpath, sw.toString());
} catch (Exception e) {
System.err.println("Failed processing template");
e.printStackTrace(System.err);
}
// if we're not configured with an ActionScript source root, don't generate the // if we're not configured with an ActionScript source root, don't generate the
// ActionScript versions // ActionScript versions
@@ -321,63 +318,55 @@ public class GenServiceTask extends InvocationTask
ctx.put("imports", imports.toList()); ctx.put("imports", imports.toList());
// now generate ActionScript versions of our marshaller // now generate ActionScript versions of our marshaller
try {
// make sure our marshaller directory exists
String mppath = mpackage.replace('.', File.separatorChar);
new File(_asroot + File.separator + mppath).mkdirs();
// generate an ActionScript version of our marshaller // make sure our marshaller directory exists
String ampath = _asroot + File.separator + mppath + String mppath = mpackage.replace('.', File.separatorChar);
File.separator + mname + ".as"; new File(_asroot + File.separator + mppath).mkdirs();
StringWriter sw = new StringWriter();
_velocity.mergeTemplate(AS_MARSHALLER_TMPL, "UTF-8", ctx, sw);
writeFile(ampath, sw.toString());
// ----------- Part III - as listener marshallers // generate an ActionScript version of our marshaller
String ampath = _asroot + File.separator + mppath + File.separator + mname + ".as";
sw = new StringWriter();
_velocity.mergeTemplate(AS_MARSHALLER_TMPL, "UTF-8", ctx, sw);
writeFile(ampath, sw.toString());
Class<?> imlm = InvocationMarshaller.ListenerMarshaller.class; // ----------- Part III - as listener marshallers
// now generate ActionScript versions of our listener marshallers Class<?> imlm = InvocationMarshaller.ListenerMarshaller.class;
// because those have to be in separate files
for (ServiceListener listener : sdesc.listeners) {
// start imports with just those used by listener methods
imports = listener.imports.clone();
// always need the super class and the listener class // now generate ActionScript versions of our listener marshallers
imports.add(imlm); // because those have to be in separate files
imports.add(listener.listener); for (ServiceListener listener : sdesc.listeners) {
// start imports with just those used by listener methods
imports = listener.imports.clone();
// replace '$' with '_' for action script naming convention // always need the super class and the listener class
imports.translateInnerClasses(); imports.add(imlm);
imports.add(listener.listener);
// convert primitive java types to ooo util types // replace '$' with '_' for action script naming convention
imports.replace("long", "com.threerings.util.Long"); imports.translateInnerClasses();
// convert object arrays to typed arrays // convert primitive java types to ooo util types
if (imports.removeAll("[L*") > 0) { imports.replace("long", "com.threerings.util.Long");
imports.add("com.threerings.io.TypedArray");
}
// get rid of remaining primitives and java.lang types // convert object arrays to typed arrays
imports.removeGlobals(); if (imports.removeAll("[L*") > 0) {
imports.add("com.threerings.io.TypedArray");
// remove imports in our own package
imports.removeSamePackage(mpackage);
ctx.put("imports", imports.toList());
ctx.put("listener", listener);
sw = new StringWriter();
_velocity.mergeTemplate(
AS_LISTENER_MARSHALLER_TMPL, "UTF-8", ctx, sw);
String aslpath = _asroot + File.separator + mppath +
File.separator + mname + "_" +
listener.getName() + "Marshaller.as";
writeFile(aslpath, sw.toString());
} }
} catch (Exception e) { // get rid of remaining primitives and java.lang types
System.err.println("Failed processing template"); imports.removeGlobals();
e.printStackTrace(System.err);
// remove imports in our own package
imports.removeSamePackage(mpackage);
ctx.put("imports", imports.toList());
ctx.put("listener", listener);
sw = new StringWriter();
_velocity.mergeTemplate(AS_LISTENER_MARSHALLER_TMPL, "UTF-8", ctx, sw);
String aslpath = _asroot + File.separator + mppath +
File.separator + mname + "_" + listener.getName() + "Marshaller.as";
writeFile(aslpath, sw.toString());
} }
// ----------- Part IV - as service // ----------- Part IV - as service
@@ -418,77 +407,69 @@ public class GenServiceTask extends InvocationTask
ctx.put("imports", imports.toList()); ctx.put("imports", imports.toList());
ctx.put("package", sdesc.spackage); ctx.put("package", sdesc.spackage);
try { // make sure our service directory exists
// make sure our service directory exists String sppath = sdesc.spackage.replace('.', File.separatorChar);
String sppath = sdesc.spackage.replace('.', File.separatorChar); new File(_asroot + File.separator + sppath).mkdirs();
new File(_asroot + File.separator + sppath).mkdirs();
// generate an ActionScript version of our service // generate an ActionScript version of our service
String aspath = _asroot + File.separator + sppath + String aspath = _asroot + File.separator + sppath + File.separator + sname + ".as";
File.separator + sname + ".as"; sw = new StringWriter();
StringWriter sw = new StringWriter(); _velocity.mergeTemplate(AS_SERVICE_TMPL, "UTF-8", ctx, sw);
_velocity.mergeTemplate(AS_SERVICE_TMPL, "UTF-8", ctx, sw); writeFile(aspath, sw.toString());
writeFile(aspath, sw.toString());
// ----------- Part V - as service listeners // ----------- Part V - as service listeners
Class<?> isil = InvocationService.InvocationListener.class;
Class<?> isil = InvocationService.InvocationListener.class; // also generate ActionScript versions of any inner listener
// interfaces because those have to be in separate files
for (ServiceListener listener : sdesc.listeners) {
// start with just the imports needed by listener methods
imports = listener.imports.clone();
// also generate ActionScript versions of any inner listener // add things needed by all listeners
// interfaces because those have to be in separate files imports.add(isil);
for (ServiceListener listener : sdesc.listeners) { imports.add(listener.listener);
// start with just the imports needed by listener methods // change Foo$Bar to Foo_Bar
imports = listener.imports.clone(); imports.translateInnerClasses();
// add things needed by all listeners // use a typed array for any arrays of objects
imports.add(isil); if (imports.removeAll("[L*") > 0) {
imports.add(listener.listener); imports.add("com.threerings.io.TypedArray");
// change Foo$Bar to Foo_Bar
imports.translateInnerClasses();
// use a typed array for any arrays of objects
if (imports.removeAll("[L*") > 0) {
imports.add("com.threerings.io.TypedArray");
}
// convert java primitive types to ooo util types
imports.replace("long", "com.threerings.util.Long");
// get rid of remaining primitives and java.lang types
imports.removeGlobals();
// remove imports in our own package
imports.removeSamePackage(sdesc.spackage);
ctx.put("imports", imports.toList());
ctx.put("listener", listener);
sw = new StringWriter();
_velocity.mergeTemplate(AS_LISTENER_SERVICE_TMPL, "UTF-8", ctx, sw);
String aslpath = _asroot + File.separator + sppath +
File.separator + sname + "_" +
listener.getName() + "Listener.as";
writeFile(aslpath, sw.toString());
if (_aslistenerAdapters.contains(sname)) {
sw = new StringWriter();
_velocity.mergeTemplate(AS_LISTENER_ADAPTER_SERVICE_TMPL, "UTF-8", ctx, sw);
String aslapath = _asroot + File.separator + sppath +
File.separator + sname + "_" +
listener.getName() + "ListenerAdapter.as";
writeFile(aslapath, sw.toString());
}
} }
} catch (Exception e) { // convert java primitive types to ooo util types
System.err.println("Failed processing template"); imports.replace("long", "com.threerings.util.Long");
e.printStackTrace(System.err);
// get rid of remaining primitives and java.lang types
imports.removeGlobals();
// remove imports in our own package
imports.removeSamePackage(sdesc.spackage);
ctx.put("imports", imports.toList());
ctx.put("listener", listener);
sw = new StringWriter();
_velocity.mergeTemplate(AS_LISTENER_SERVICE_TMPL, "UTF-8", ctx, sw);
String aslpath = _asroot + File.separator + sppath +
File.separator + sname + "_" +
listener.getName() + "Listener.as";
writeFile(aslpath, sw.toString());
if (_aslistenerAdapters.contains(sname)) {
sw = new StringWriter();
_velocity.mergeTemplate(AS_LISTENER_ADAPTER_SERVICE_TMPL, "UTF-8", ctx, sw);
String aslapath = _asroot + File.separator + sppath +
File.separator + sname + "_" +
listener.getName() + "ListenerAdapter.as";
writeFile(aslapath, sw.toString());
}
} }
} }
protected void generateDispatcher (File source, ServiceDescription sdesc) protected void generateDispatcher (File source, ServiceDescription sdesc)
throws Exception
{ {
if (_verbose) { if (_verbose) {
System.out.println("Generating dispatcher"); System.out.println("Generating dispatcher");
@@ -540,24 +521,19 @@ public class GenServiceTask extends InvocationTask
ctx.put("methods", sdesc.methods); ctx.put("methods", sdesc.methods);
ctx.put("imports", imports.toList()); ctx.put("imports", imports.toList());
try { StringWriter sw = new StringWriter();
StringWriter sw = new StringWriter(); _velocity.mergeTemplate(DISPATCHER_TMPL, "UTF-8", ctx, sw);
_velocity.mergeTemplate(DISPATCHER_TMPL, "UTF-8", ctx, sw);
// determine the path to our marshaller file // determine the path to our marshaller file
String mpath = source.getPath(); String mpath = source.getPath();
mpath = StringUtil.replace(mpath, "Service", "Dispatcher"); mpath = StringUtil.replace(mpath, "Service", "Dispatcher");
mpath = replacePath(mpath, "/client/", "/server/"); mpath = replacePath(mpath, "/client/", "/server/");
writeFile(mpath, sw.toString()); writeFile(mpath, sw.toString());
} catch (Exception e) {
System.err.println("Failed processing template");
e.printStackTrace(System.err);
}
} }
protected void generateProvider (File source, ServiceDescription sdesc) protected void generateProvider (File source, ServiceDescription sdesc)
throws Exception
{ {
if (_verbose) { if (_verbose) {
System.out.println("Generating provider"); System.out.println("Generating provider");
@@ -604,21 +580,15 @@ public class GenServiceTask extends InvocationTask
ctx.put("listeners", sdesc.listeners); ctx.put("listeners", sdesc.listeners);
ctx.put("imports", imports.toList()); ctx.put("imports", imports.toList());
try { StringWriter sw = new StringWriter();
StringWriter sw = new StringWriter(); _velocity.mergeTemplate(PROVIDER_TMPL, "UTF-8", ctx, sw);
_velocity.mergeTemplate(PROVIDER_TMPL, "UTF-8", ctx, sw);
// determine the path to our provider file // determine the path to our provider file
String mpath = source.getPath(); String mpath = source.getPath();
mpath = StringUtil.replace(mpath, "Service", "Provider"); mpath = StringUtil.replace(mpath, "Service", "Provider");
mpath = replacePath(mpath, "/client/", "/server/"); mpath = replacePath(mpath, "/client/", "/server/");
writeFile(mpath, sw.toString()); writeFile(mpath, sw.toString());
} catch (Exception e) {
System.err.println("Failed processing template");
e.printStackTrace(System.err);
}
} }
/** Rolls up everything needed for the generate* methods. */ /** Rolls up everything needed for the generate* methods. */
@@ -411,26 +411,23 @@ public abstract class InvocationTask extends Task
try { try {
name = GenUtil.readClassName(source); name = GenUtil.readClassName(source);
} catch (Exception e) { } catch (Exception e) {
System.err.println( throw new BuildException("Failed to parse " + source + ": " + e.getMessage());
"Failed to parse " + source + ": " + e.getMessage());
} }
try { try {
processService(source, _cloader.loadClass(name)); processService(source, _cloader.loadClass(name));
} catch (ClassNotFoundException cnfe) { } catch (ClassNotFoundException cnfe) {
System.err.println( System.err.println("Failed to load " + name + ".\n" +
"Failed to load " + name + ".\n" + "Missing class: " + cnfe.getMessage());
"Missing class: " + cnfe.getMessage()); System.err.println("Be sure to set the 'classpathref' attribute to a classpath\n" +
System.err.println( "that contains your projects invocation service classes.");
"Be sure to set the 'classpathref' attribute to a classpath\n" +
"that contains your projects invocation service classes.");
} catch (Exception e) { } catch (Exception e) {
e.printStackTrace(System.err); throw new BuildException("Failed to process " + source.getName() + ": " + e, e);
} }
} }
/** Processes a resolved invocation service class instance. */ /** Processes a resolved invocation service class instance. */
protected abstract void processService (File source, Class<?> service); protected abstract void processService (File source, Class<?> service) throws Exception;
protected void writeFile (String path, String data) protected void writeFile (String path, String data)
throws IOException throws IOException