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