Load the InvocationListener class using the same classloader we use to
load the project's service classes so that they are comparable. Also sort everything to avoid pointless changes in regenerated source files when Java decides to arbitrarily return the methods in a different order. git-svn-id: svn+ssh://src.earth.threerings.net/narya/trunk@3242 542714f4-19e9-0310-aa3c-eee0fc999fb1
This commit is contained in:
@@ -12,6 +12,7 @@ import java.lang.reflect.Modifier;
|
|||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.Iterator;
|
import java.util.Iterator;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
import org.apache.velocity.VelocityContext;
|
import org.apache.velocity.VelocityContext;
|
||||||
|
|
||||||
@@ -34,11 +35,11 @@ import com.threerings.presents.server.InvocationException;
|
|||||||
public class GenServiceTask extends InvocationTask
|
public class GenServiceTask extends InvocationTask
|
||||||
{
|
{
|
||||||
/** Used to keep track of custom InvocationListener derivations. */
|
/** Used to keep track of custom InvocationListener derivations. */
|
||||||
public static class ServiceListener
|
public class ServiceListener implements Comparable<ServiceListener>
|
||||||
{
|
{
|
||||||
public Class listener;
|
public Class listener;
|
||||||
|
|
||||||
public ArrayList methods = new ArrayList();
|
public SortableArrayList methods = new SortableArrayList();
|
||||||
|
|
||||||
public ServiceListener (Class service, Class listener, HashMap imports)
|
public ServiceListener (Class service, Class listener, HashMap imports)
|
||||||
{
|
{
|
||||||
@@ -53,6 +54,12 @@ public class GenServiceTask extends InvocationTask
|
|||||||
}
|
}
|
||||||
methods.add(new ServiceMethod(service, m, imports));
|
methods.add(new ServiceMethod(service, m, imports));
|
||||||
}
|
}
|
||||||
|
methods.sort();
|
||||||
|
}
|
||||||
|
|
||||||
|
public int compareTo (ServiceListener other)
|
||||||
|
{
|
||||||
|
return getName().compareTo(other.getName());
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getName ()
|
public String getName ()
|
||||||
@@ -85,8 +92,8 @@ public class GenServiceTask extends InvocationTask
|
|||||||
}
|
}
|
||||||
|
|
||||||
HashMap imports = new HashMap();
|
HashMap imports = new HashMap();
|
||||||
ArrayList methods = new ArrayList();
|
SortableArrayList methods = new SortableArrayList();
|
||||||
ArrayList listeners = new ArrayList();
|
SortableArrayList listeners = new SortableArrayList();
|
||||||
|
|
||||||
// we need to import the service itself
|
// we need to import the service itself
|
||||||
imports.put(importify(service.getName()), Boolean.TRUE);
|
imports.put(importify(service.getName()), Boolean.TRUE);
|
||||||
@@ -104,7 +111,7 @@ public class GenServiceTask extends InvocationTask
|
|||||||
// check this method for custom listener declarations
|
// check this method for custom listener declarations
|
||||||
Class[] args = m.getParameterTypes();
|
Class[] args = m.getParameterTypes();
|
||||||
for (int aa = 0; aa < args.length; aa++) {
|
for (int aa = 0; aa < args.length; aa++) {
|
||||||
if (InvocationListener.class.isAssignableFrom(args[aa]) &&
|
if (_ilistener.isAssignableFrom(args[aa]) &&
|
||||||
simpleName(args[aa]).startsWith(sname + ".")) {
|
simpleName(args[aa]).startsWith(sname + ".")) {
|
||||||
listeners.add(new ServiceListener(
|
listeners.add(new ServiceListener(
|
||||||
service, args[aa], imports));
|
service, args[aa], imports));
|
||||||
@@ -112,6 +119,8 @@ public class GenServiceTask extends InvocationTask
|
|||||||
}
|
}
|
||||||
methods.add(new ServiceMethod(service, m, imports));
|
methods.add(new ServiceMethod(service, m, imports));
|
||||||
}
|
}
|
||||||
|
listeners.sort();
|
||||||
|
methods.sort();
|
||||||
|
|
||||||
generateMarshaller(source, sname, spackage, methods, listeners,
|
generateMarshaller(source, sname, spackage, methods, listeners,
|
||||||
imports.keySet().iterator());
|
imports.keySet().iterator());
|
||||||
@@ -120,8 +129,8 @@ public class GenServiceTask extends InvocationTask
|
|||||||
}
|
}
|
||||||
|
|
||||||
protected void generateMarshaller (
|
protected void generateMarshaller (
|
||||||
File source, String sname, String spackage, ArrayList methods,
|
File source, String sname, String spackage, List methods,
|
||||||
ArrayList listeners, Iterator imports)
|
List listeners, Iterator imports)
|
||||||
{
|
{
|
||||||
String name = StringUtil.replace(sname, "Service", "");
|
String name = StringUtil.replace(sname, "Service", "");
|
||||||
String mname = StringUtil.replace(sname, "Service", "Marshaller");
|
String mname = StringUtil.replace(sname, "Service", "Marshaller");
|
||||||
@@ -160,7 +169,7 @@ public class GenServiceTask extends InvocationTask
|
|||||||
}
|
}
|
||||||
|
|
||||||
protected void generateDispatcher (
|
protected void generateDispatcher (
|
||||||
File source, String sname, String spackage, ArrayList methods,
|
File source, String sname, String spackage, List methods,
|
||||||
Iterator imports)
|
Iterator imports)
|
||||||
{
|
{
|
||||||
String name = StringUtil.replace(sname, "Service", "");
|
String name = StringUtil.replace(sname, "Service", "");
|
||||||
|
|||||||
@@ -43,7 +43,7 @@ import com.threerings.presents.client.InvocationService.InvocationListener;
|
|||||||
public abstract class InvocationTask extends Task
|
public abstract class InvocationTask extends Task
|
||||||
{
|
{
|
||||||
/** Used to keep track of invocation service method listener arguments. */
|
/** Used to keep track of invocation service method listener arguments. */
|
||||||
public static class ListenerArgument
|
public class ListenerArgument
|
||||||
{
|
{
|
||||||
public int index;
|
public int index;
|
||||||
|
|
||||||
@@ -68,7 +68,7 @@ public abstract class InvocationTask extends Task
|
|||||||
}
|
}
|
||||||
|
|
||||||
/** Used to keep track of invocation service methods. */
|
/** Used to keep track of invocation service methods. */
|
||||||
public static class ServiceMethod
|
public class ServiceMethod implements Comparable<ServiceMethod>
|
||||||
{
|
{
|
||||||
public Method method;
|
public Method method;
|
||||||
|
|
||||||
@@ -89,7 +89,7 @@ public abstract class InvocationTask extends Task
|
|||||||
|
|
||||||
// if this is a listener, we need to add a listener
|
// if this is a listener, we need to add a listener
|
||||||
// argument info for it
|
// argument info for it
|
||||||
if (InvocationListener.class.isAssignableFrom(arg)) {
|
if (_ilistener.isAssignableFrom(arg)) {
|
||||||
listenerArgs.add(new ListenerArgument(ii, arg));
|
listenerArgs.add(new ListenerArgument(ii, arg));
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -106,7 +106,7 @@ public abstract class InvocationTask extends Task
|
|||||||
// if it's a listener and not one of the special
|
// if it's a listener and not one of the special
|
||||||
// InvocationService listeners, we need to import its
|
// InvocationService listeners, we need to import its
|
||||||
// marshaller as well
|
// marshaller as well
|
||||||
if (InvocationListener.class.isAssignableFrom(arg) &&
|
if (_ilistener.isAssignableFrom(arg) &&
|
||||||
!simpleName(arg).startsWith("InvocationService")) {
|
!simpleName(arg).startsWith("InvocationService")) {
|
||||||
String mname = arg.getName();
|
String mname = arg.getName();
|
||||||
mname = StringUtil.replace(mname, "Service", "Marshaller");
|
mname = StringUtil.replace(mname, "Service", "Marshaller");
|
||||||
@@ -153,6 +153,11 @@ public abstract class InvocationTask extends Task
|
|||||||
return (method.getParameterTypes().length > 1);
|
return (method.getParameterTypes().length > 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public int compareTo (ServiceMethod other)
|
||||||
|
{
|
||||||
|
return getCode().compareTo(other.getCode());
|
||||||
|
}
|
||||||
|
|
||||||
public String getUnwrappedArgList (boolean listenerMode)
|
public String getUnwrappedArgList (boolean listenerMode)
|
||||||
{
|
{
|
||||||
StringBuffer buf = new StringBuffer();
|
StringBuffer buf = new StringBuffer();
|
||||||
@@ -185,7 +190,7 @@ public abstract class InvocationTask extends Task
|
|||||||
return "new Float(arg" + index + ")";
|
return "new Float(arg" + index + ")";
|
||||||
} else if (clazz == Double.TYPE) {
|
} else if (clazz == Double.TYPE) {
|
||||||
return "new Double(arg" + index + ")";
|
return "new Double(arg" + index + ")";
|
||||||
} else if (InvocationListener.class.isAssignableFrom(clazz)) {
|
} else if (_ilistener.isAssignableFrom(clazz)) {
|
||||||
return "listener" + index;
|
return "listener" + index;
|
||||||
} else {
|
} else {
|
||||||
return "arg" + index;
|
return "arg" + index;
|
||||||
@@ -211,8 +216,7 @@ public abstract class InvocationTask extends Task
|
|||||||
return "((Float)args[" + index + "]).floatValue()";
|
return "((Float)args[" + index + "]).floatValue()";
|
||||||
} else if (clazz == Double.TYPE) {
|
} else if (clazz == Double.TYPE) {
|
||||||
return "((Double)args[" + index + "]).doubleValue()";
|
return "((Double)args[" + index + "]).doubleValue()";
|
||||||
} else if (listenerMode &&
|
} else if (listenerMode && _ilistener.isAssignableFrom(clazz)) {
|
||||||
InvocationListener.class.isAssignableFrom(clazz)) {
|
|
||||||
return "listener" + index;
|
return "listener" + index;
|
||||||
} else {
|
} else {
|
||||||
return "(" + simpleName(clazz) + ")args[" + index + "]";
|
return "(" + simpleName(clazz) + ")args[" + index + "]";
|
||||||
@@ -265,6 +269,13 @@ public abstract class InvocationTask extends Task
|
|||||||
throw new BuildException("Failure initializing Velocity", e);
|
throw new BuildException("Failure initializing Velocity", e);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// resolve the InvocationListener class using our classloader
|
||||||
|
try {
|
||||||
|
_ilistener = _cloader.loadClass(InvocationListener.class.getName());
|
||||||
|
} catch (Exception e) {
|
||||||
|
throw new BuildException("Can't resolve InvocationListener", e);
|
||||||
|
}
|
||||||
|
|
||||||
ArrayList files = new ArrayList();
|
ArrayList files = new ArrayList();
|
||||||
for (Iterator iter = _filesets.iterator(); iter.hasNext(); ) {
|
for (Iterator iter = _filesets.iterator(); iter.hasNext(); ) {
|
||||||
FileSet fs = (FileSet)iter.next();
|
FileSet fs = (FileSet)iter.next();
|
||||||
@@ -379,6 +390,10 @@ public abstract class InvocationTask extends Task
|
|||||||
/** Used to generate source files from templates. */
|
/** Used to generate source files from templates. */
|
||||||
protected VelocityEngine _velocity;
|
protected VelocityEngine _velocity;
|
||||||
|
|
||||||
|
/** {@link InvocationListener} resolved with the proper classloader so
|
||||||
|
* that we can compare it to loaded derived classes. */
|
||||||
|
protected Class _ilistener;
|
||||||
|
|
||||||
/** A regular expression for matching the package declaration. */
|
/** A regular expression for matching the package declaration. */
|
||||||
protected static final Pattern PACKAGE_PATTERN =
|
protected static final Pattern PACKAGE_PATTERN =
|
||||||
Pattern.compile("^\\s*package\\s+(\\S+)\\W");
|
Pattern.compile("^\\s*package\\s+(\\S+)\\W");
|
||||||
|
|||||||
Reference in New Issue
Block a user