Move all the fileset and classloading wanging into GenTask
git-svn-id: svn+ssh://src.earth.threerings.net/narya/trunk@6213 542714f4-19e9-0310-aa3c-eee0fc999fb1
This commit is contained in:
@@ -24,7 +24,6 @@ package com.threerings.presents.tools;
|
|||||||
import java.lang.reflect.Field;
|
import java.lang.reflect.Field;
|
||||||
import java.lang.reflect.Modifier;
|
import java.lang.reflect.Modifier;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
@@ -35,14 +34,9 @@ import java.io.FileWriter;
|
|||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.PrintWriter;
|
import java.io.PrintWriter;
|
||||||
|
|
||||||
import org.apache.tools.ant.BuildException;
|
|
||||||
import org.apache.tools.ant.DirectoryScanner;
|
|
||||||
import org.apache.tools.ant.types.FileSet;
|
|
||||||
|
|
||||||
import com.google.common.base.Charsets;
|
import com.google.common.base.Charsets;
|
||||||
import com.google.common.base.Splitter;
|
import com.google.common.base.Splitter;
|
||||||
import com.google.common.collect.Iterables;
|
import com.google.common.collect.Iterables;
|
||||||
import com.google.common.collect.Lists;
|
|
||||||
import com.google.common.io.Files;
|
import com.google.common.io.Files;
|
||||||
|
|
||||||
import com.threerings.io.ObjectInputStream;
|
import com.threerings.io.ObjectInputStream;
|
||||||
@@ -60,14 +54,6 @@ import com.threerings.presents.dobj.DObject;
|
|||||||
*/
|
*/
|
||||||
public class GenActionScriptTask extends GenTask
|
public class GenActionScriptTask extends GenTask
|
||||||
{
|
{
|
||||||
/**
|
|
||||||
* Adds a nested <fileset> element which enumerates streamable source files.
|
|
||||||
*/
|
|
||||||
public void addFileset (FileSet set)
|
|
||||||
{
|
|
||||||
_filesets.add(set);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Configures the path to our ActionScript source files.
|
* Configures the path to our ActionScript source files.
|
||||||
*/
|
*/
|
||||||
@@ -88,50 +74,11 @@ public class GenActionScriptTask extends GenTask
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Performs the actual work of the task.
|
|
||||||
*/
|
|
||||||
@Override
|
|
||||||
public void execute ()
|
|
||||||
{
|
|
||||||
for (FileSet fs : _filesets) {
|
|
||||||
DirectoryScanner ds = fs.getDirectoryScanner(getProject());
|
|
||||||
File fromDir = fs.getDir(getProject());
|
|
||||||
String[] srcFiles = ds.getIncludedFiles();
|
|
||||||
for (String srcFile : srcFiles) {
|
|
||||||
processClass(new File(fromDir, srcFile));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Processes a Streamable source file.
|
|
||||||
*/
|
|
||||||
protected void processClass (File source)
|
|
||||||
{
|
|
||||||
// System.err.println("Processing " + source + "...");
|
|
||||||
|
|
||||||
// load up the file and determine it's package and classname
|
|
||||||
String name = null;
|
|
||||||
try {
|
|
||||||
name = GenUtil.readClassName(source);
|
|
||||||
} catch (Exception e) {
|
|
||||||
System.err.println("Failed to parse " + source + ": " + e.getMessage());
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
Class<?> sclass = loadClass(name);
|
|
||||||
try {
|
|
||||||
processClass(source, sclass);
|
|
||||||
} catch (Exception e) {
|
|
||||||
throw new BuildException(e);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Processes a resolved Streamable class instance.
|
* Processes a resolved Streamable class instance.
|
||||||
*/
|
*/
|
||||||
protected void processClass (File source, Class<?> sclass)
|
@Override
|
||||||
|
public void processClass (File source, Class<?> sclass)
|
||||||
throws Exception
|
throws Exception
|
||||||
{
|
{
|
||||||
// make sure we implement Streamable but don't extend DObject or InvocationMarshaller and
|
// make sure we implement Streamable but don't extend DObject or InvocationMarshaller and
|
||||||
@@ -397,9 +344,6 @@ public class GenActionScriptTask extends GenTask
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/** A list of filesets that contain tile images. */
|
|
||||||
protected ArrayList<FileSet> _filesets = Lists.newArrayList();
|
|
||||||
|
|
||||||
/** A header to put on all generated source files. */
|
/** A header to put on all generated source files. */
|
||||||
protected String _header;
|
protected String _header;
|
||||||
|
|
||||||
@@ -412,4 +356,5 @@ public class GenActionScriptTask extends GenTask
|
|||||||
"public function writeObject (out :ObjectOutputStream) :void";
|
"public function writeObject (out :ObjectOutputStream) :void";
|
||||||
|
|
||||||
protected static final Splitter DOT_SPLITTER = Splitter.on('.');
|
protected static final Splitter DOT_SPLITTER = Splitter.on('.');
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -31,11 +31,6 @@ import java.util.HashMap;
|
|||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.IOException;
|
|
||||||
|
|
||||||
import org.apache.tools.ant.BuildException;
|
|
||||||
import org.apache.tools.ant.DirectoryScanner;
|
|
||||||
import org.apache.tools.ant.types.FileSet;
|
|
||||||
import com.google.common.collect.Lists;
|
import com.google.common.collect.Lists;
|
||||||
|
|
||||||
import com.samskivert.util.StringUtil;
|
import com.samskivert.util.StringUtil;
|
||||||
@@ -50,14 +45,6 @@ import com.threerings.presents.dobj.OidList;
|
|||||||
*/
|
*/
|
||||||
public class GenDObjectTask extends GenTask
|
public class GenDObjectTask extends GenTask
|
||||||
{
|
{
|
||||||
/**
|
|
||||||
* Adds a nested <fileset> element which enumerates service declaration source files.
|
|
||||||
*/
|
|
||||||
public void addFileset (FileSet set)
|
|
||||||
{
|
|
||||||
_filesets.add(set);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void execute ()
|
public void execute ()
|
||||||
{
|
{
|
||||||
@@ -66,36 +53,12 @@ public class GenDObjectTask extends GenTask
|
|||||||
_dsclass = loadClass(DSet.class.getName());
|
_dsclass = loadClass(DSet.class.getName());
|
||||||
_olclass = loadClass(OidList.class.getName());
|
_olclass = loadClass(OidList.class.getName());
|
||||||
|
|
||||||
for (FileSet fs : _filesets) {
|
super.execute();
|
||||||
DirectoryScanner ds = fs.getDirectoryScanner(getProject());
|
|
||||||
File fromDir = fs.getDir(getProject());
|
|
||||||
String[] srcFiles = ds.getIncludedFiles();
|
|
||||||
for (String srcFile : srcFiles) {
|
|
||||||
processObject(new File(fromDir, srcFile));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/** Processes a distributed object source file. */
|
|
||||||
protected void processObject (File source)
|
|
||||||
{
|
|
||||||
// load up the file and determine it's package and classname
|
|
||||||
String name;
|
|
||||||
try{
|
|
||||||
name = GenUtil.readClassName(source);
|
|
||||||
} catch (IOException io) {
|
|
||||||
throw new BuildException("Couldn't read class name: " + source, io);
|
|
||||||
}
|
|
||||||
Class<?> klass = loadClass(name);
|
|
||||||
try {
|
|
||||||
processObject(source, klass);
|
|
||||||
} catch (Exception e) {
|
|
||||||
throw new BuildException("Failed to process " + source.getName(), e);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Processes a resolved distributed object class instance. */
|
/** Processes a resolved distributed object class instance. */
|
||||||
protected void processObject (File source, Class<?> oclass)
|
@Override
|
||||||
|
public void processClass (File source, Class<?> oclass)
|
||||||
throws Exception
|
throws Exception
|
||||||
{
|
{
|
||||||
// make sure we extend distributed object
|
// make sure we extend distributed object
|
||||||
@@ -203,9 +166,6 @@ public class GenDObjectTask extends GenTask
|
|||||||
sfile.writeTo(source, fsection.toString(), msection.toString());
|
sfile.writeTo(source, fsection.toString(), msection.toString());
|
||||||
}
|
}
|
||||||
|
|
||||||
/** A list of filesets that contain tile images. */
|
|
||||||
protected ArrayList<FileSet> _filesets = Lists.newArrayList();
|
|
||||||
|
|
||||||
/** {@link DObject} resolved with the proper classloader so that we
|
/** {@link DObject} resolved with the proper classloader so that we
|
||||||
* can compare it to loaded derived classes. */
|
* can compare it to loaded derived classes. */
|
||||||
protected Class<?> _doclass;
|
protected Class<?> _doclass;
|
||||||
|
|||||||
@@ -44,7 +44,7 @@ import com.threerings.presents.server.InvocationSender;
|
|||||||
public class GenReceiverTask extends InvocationTask
|
public class GenReceiverTask extends InvocationTask
|
||||||
{
|
{
|
||||||
@Override
|
@Override
|
||||||
protected void processService (File source, Class<?> receiver)
|
public void processClass (File source, Class<?> receiver)
|
||||||
throws Exception
|
throws Exception
|
||||||
{
|
{
|
||||||
System.out.println("Processing " + receiver.getName() + "...");
|
System.out.println("Processing " + receiver.getName() + "...");
|
||||||
|
|||||||
@@ -191,7 +191,7 @@ public class GenServiceTask extends InvocationTask
|
|||||||
|
|
||||||
// documentation inherited
|
// documentation inherited
|
||||||
@Override
|
@Override
|
||||||
protected void processService (File source, Class<?> service)
|
public void processClass (File source, Class<?> service)
|
||||||
throws Exception
|
throws Exception
|
||||||
{
|
{
|
||||||
System.out.println("Processing " + service.getName() + "...");
|
System.out.println("Processing " + service.getName() + "...");
|
||||||
|
|||||||
@@ -21,18 +21,24 @@
|
|||||||
|
|
||||||
package com.threerings.presents.tools;
|
package com.threerings.presents.tools;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
import java.io.StringWriter;
|
import java.io.StringWriter;
|
||||||
|
|
||||||
import org.apache.tools.ant.AntClassLoader;
|
import org.apache.tools.ant.AntClassLoader;
|
||||||
import org.apache.tools.ant.BuildException;
|
import org.apache.tools.ant.BuildException;
|
||||||
|
import org.apache.tools.ant.DirectoryScanner;
|
||||||
import org.apache.tools.ant.Task;
|
import org.apache.tools.ant.Task;
|
||||||
|
import org.apache.tools.ant.types.FileSet;
|
||||||
import org.apache.tools.ant.types.Reference;
|
import org.apache.tools.ant.types.Reference;
|
||||||
import org.apache.tools.ant.util.ClasspathUtils;
|
import org.apache.tools.ant.util.ClasspathUtils;
|
||||||
import org.apache.velocity.VelocityContext;
|
import org.apache.velocity.VelocityContext;
|
||||||
import org.apache.velocity.app.VelocityEngine;
|
import org.apache.velocity.app.VelocityEngine;
|
||||||
|
|
||||||
|
import com.google.common.collect.Lists;
|
||||||
|
|
||||||
import com.samskivert.velocity.VelocityUtil;
|
import com.samskivert.velocity.VelocityUtil;
|
||||||
|
|
||||||
public abstract class GenTask extends Task
|
public abstract class GenTask extends Task
|
||||||
@@ -46,6 +52,14 @@ public abstract class GenTask extends Task
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Adds a nested <fileset> element which enumerates service declaration source files.
|
||||||
|
*/
|
||||||
|
public void addFileset (FileSet set)
|
||||||
|
{
|
||||||
|
_filesets.add(set);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Configures to output extra information when generating code.
|
* Configures to output extra information when generating code.
|
||||||
*/
|
*/
|
||||||
@@ -65,6 +79,27 @@ public abstract class GenTask extends Task
|
|||||||
((AntClassLoader)_cloader).setParent(getClass().getClassLoader());
|
((AntClassLoader)_cloader).setParent(getClass().getClassLoader());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Performs the actual work of the task.
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public void execute ()
|
||||||
|
{
|
||||||
|
for (FileSet fs : _filesets) {
|
||||||
|
DirectoryScanner ds = fs.getDirectoryScanner(getProject());
|
||||||
|
File fromDir = fs.getDir(getProject());
|
||||||
|
String[] srcFiles = ds.getIncludedFiles();
|
||||||
|
for (String srcFile : srcFiles) {
|
||||||
|
File source = new File(fromDir, srcFile);
|
||||||
|
try {
|
||||||
|
processClass(source, loadClass(source));
|
||||||
|
} catch (Exception e) {
|
||||||
|
throw new BuildException(e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Merges the specified template using the supplied mapping of keys to objects.
|
* Merges the specified template using the supplied mapping of keys to objects.
|
||||||
*
|
*
|
||||||
@@ -108,6 +143,25 @@ public abstract class GenTask extends Task
|
|||||||
return writer.toString();
|
return writer.toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Process a class found from the given source file that was on the filesets given to this
|
||||||
|
* task.
|
||||||
|
*/
|
||||||
|
protected abstract void processClass (File source, Class<?> klass)
|
||||||
|
throws Exception;
|
||||||
|
|
||||||
|
protected Class<?> loadClass (File source)
|
||||||
|
{
|
||||||
|
// load up the file and determine it's package and classname
|
||||||
|
String name;
|
||||||
|
try {
|
||||||
|
name = GenUtil.readClassName(source);
|
||||||
|
} catch (Exception e) {
|
||||||
|
throw new BuildException("Failed to parse " + source + ": " + e.getMessage());
|
||||||
|
}
|
||||||
|
return loadClass(name);
|
||||||
|
}
|
||||||
|
|
||||||
protected Class<?> loadClass (String name)
|
protected Class<?> loadClass (String name)
|
||||||
{
|
{
|
||||||
if (_cloader == null) {
|
if (_cloader == null) {
|
||||||
@@ -123,6 +177,9 @@ public abstract class GenTask extends Task
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** A list of filesets that contain java source to be processed. */
|
||||||
|
protected List<FileSet> _filesets = Lists.newArrayList();
|
||||||
|
|
||||||
/** Show extra output if set. */
|
/** Show extra output if set. */
|
||||||
protected boolean _verbose;
|
protected boolean _verbose;
|
||||||
|
|
||||||
|
|||||||
@@ -36,8 +36,6 @@ import java.io.IOException;
|
|||||||
import java.io.PrintWriter;
|
import java.io.PrintWriter;
|
||||||
|
|
||||||
import org.apache.tools.ant.BuildException;
|
import org.apache.tools.ant.BuildException;
|
||||||
import org.apache.tools.ant.DirectoryScanner;
|
|
||||||
import org.apache.tools.ant.types.FileSet;
|
|
||||||
import com.google.common.base.Predicate;
|
import com.google.common.base.Predicate;
|
||||||
import com.google.common.collect.Iterables;
|
import com.google.common.collect.Iterables;
|
||||||
import com.google.common.collect.Lists;
|
import com.google.common.collect.Lists;
|
||||||
@@ -50,8 +48,8 @@ import com.threerings.presents.net.Transport;
|
|||||||
import com.threerings.presents.client.InvocationService.InvocationListener;
|
import com.threerings.presents.client.InvocationService.InvocationListener;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A base Ant task for generating invocation service related marshalling
|
* A base Ant task for generating invocation service related marshalling and unmarshalling
|
||||||
* and unmarshalling classes.
|
* classes.
|
||||||
*/
|
*/
|
||||||
public abstract class InvocationTask extends GenTask
|
public abstract class InvocationTask extends GenTask
|
||||||
{
|
{
|
||||||
@@ -340,15 +338,6 @@ public abstract class InvocationTask extends GenTask
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Adds a nested <fileset> element which enumerates service
|
|
||||||
* declaration source files.
|
|
||||||
*/
|
|
||||||
public void addFileset (FileSet set)
|
|
||||||
{
|
|
||||||
_filesets.add(set);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Configures us with a header file that we'll prepend to all
|
* Configures us with a header file that we'll prepend to all
|
||||||
* generated source files.
|
* generated source files.
|
||||||
@@ -369,39 +358,9 @@ public abstract class InvocationTask extends GenTask
|
|||||||
// resolve the InvocationListener class using our classloader
|
// resolve the InvocationListener class using our classloader
|
||||||
_ilistener = loadClass(InvocationListener.class.getName());
|
_ilistener = loadClass(InvocationListener.class.getName());
|
||||||
|
|
||||||
for (FileSet fs : _filesets) {
|
super.execute();
|
||||||
DirectoryScanner ds = fs.getDirectoryScanner(getProject());
|
|
||||||
File fromDir = fs.getDir(getProject());
|
|
||||||
String[] srcFiles = ds.getIncludedFiles();
|
|
||||||
for (String srcFile : srcFiles) {
|
|
||||||
processService(new File(fromDir, srcFile));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Processes an invocation service source file. */
|
|
||||||
protected void processService (File source)
|
|
||||||
{
|
|
||||||
// System.err.println("Processing " + source + "...");
|
|
||||||
// load up the file and determine it's package and classname
|
|
||||||
String name = null;
|
|
||||||
try {
|
|
||||||
name = GenUtil.readClassName(source);
|
|
||||||
} catch (Exception e) {
|
|
||||||
throw new BuildException("Failed to parse " + source + ": " + e.getMessage());
|
|
||||||
}
|
|
||||||
|
|
||||||
Class<?> serviceClass = loadClass(name);
|
|
||||||
try {
|
|
||||||
processService(source, serviceClass);
|
|
||||||
} catch (Exception e) {
|
|
||||||
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) throws Exception;
|
|
||||||
|
|
||||||
protected void writeFile (String path, String data)
|
protected void writeFile (String path, String data)
|
||||||
throws IOException
|
throws IOException
|
||||||
{
|
{
|
||||||
@@ -431,9 +390,6 @@ public abstract class InvocationTask extends GenTask
|
|||||||
newstr.replace('/', File.separatorChar));
|
newstr.replace('/', File.separatorChar));
|
||||||
}
|
}
|
||||||
|
|
||||||
/** A list of filesets that contain tile images. */
|
|
||||||
protected List<FileSet> _filesets = Lists.newArrayList();
|
|
||||||
|
|
||||||
/** A header to put on all generated source files. */
|
/** A header to put on all generated source files. */
|
||||||
protected String _header;
|
protected String _header;
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user