These are both pretty busted, so let's kill them to eliminate confusion with the functional
GenActionScriptStreamableTask. git-svn-id: svn+ssh://src.earth.threerings.net/narya/trunk@6345 542714f4-19e9-0310-aa3c-eee0fc999fb1
This commit is contained in:
File diff suppressed because it is too large
Load Diff
@@ -1,169 +0,0 @@
|
||||
//
|
||||
// $Id$
|
||||
//
|
||||
// Narya library - tools for developing networked games
|
||||
// Copyright (C) 2002-2010 Three Rings Design, Inc., All Rights Reserved
|
||||
// http://code.google.com/p/narya/
|
||||
//
|
||||
// This library is free software; you can redistribute it and/or modify it
|
||||
// under the terms of the GNU Lesser General Public License as published
|
||||
// by the Free Software Foundation; either version 2.1 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// This library is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
// Lesser General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU Lesser General Public
|
||||
// License along with this library; if not, write to the Free Software
|
||||
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
|
||||
package com.threerings.presents.tools;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Date;
|
||||
import java.util.Map;
|
||||
import java.util.Properties;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.PrintWriter;
|
||||
|
||||
import org.apache.tools.ant.BuildException;
|
||||
import org.apache.tools.ant.DirectoryScanner;
|
||||
import org.apache.tools.ant.Task;
|
||||
import org.apache.tools.ant.types.FileSet;
|
||||
|
||||
import com.google.common.collect.Lists;
|
||||
|
||||
/**
|
||||
* Generates our own ResourceBundle classes.
|
||||
*
|
||||
* NOTE: This is not used. We are just using the standard ResourceBundles
|
||||
* after all.
|
||||
*/
|
||||
public class GenActionScriptBundlesTask extends Task
|
||||
{
|
||||
public void addFileset (FileSet set)
|
||||
{
|
||||
_filesets.add(set);
|
||||
}
|
||||
|
||||
public void setAsroot (File asroot)
|
||||
{
|
||||
_asroot = asroot;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void execute ()
|
||||
{
|
||||
// boilerplate
|
||||
for (FileSet fs : _filesets) {
|
||||
DirectoryScanner ds = fs.getDirectoryScanner(getProject());
|
||||
File fromDir = fs.getDir(getProject());
|
||||
String[] srcFiles = ds.getIncludedFiles();
|
||||
for (String srcFile : srcFiles) {
|
||||
try {
|
||||
processBundle(new File(fromDir, srcFile));
|
||||
} catch (IOException ioe) {
|
||||
throw new BuildException(ioe);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
protected void processBundle (File source)
|
||||
throws IOException
|
||||
{
|
||||
Properties props = new Properties();
|
||||
props.load(new FileInputStream(source));
|
||||
|
||||
String name = source.getName();
|
||||
name = name.replace('.', '_');
|
||||
File outfile = new File(_asroot, name + ".as");
|
||||
PrintWriter out = new PrintWriter(outfile);
|
||||
|
||||
out.println("package {");
|
||||
out.println();
|
||||
out.println("import com.threerings.util.ResourceBundle;");
|
||||
out.println();
|
||||
out.println("// Generated at " + new Date());
|
||||
out.println("public class " + name + " extends ResourceBundle");
|
||||
out.println("{");
|
||||
out.println(" override protected function getContent () :Object");
|
||||
out.println(" {");
|
||||
|
||||
// create an array with all the values, then populate in a loop
|
||||
out.println(" var data :Array = [");
|
||||
for (Map.Entry<Object, Object> entry : props.entrySet()) {
|
||||
String key = saveConvert((String) entry.getKey());
|
||||
String val = saveConvert((String) entry.getValue());
|
||||
out.println(" \"" + key + "\", \"" + val + "\",");
|
||||
}
|
||||
out.println(" null];");
|
||||
out.println(" var o :Object = new Object();");
|
||||
out.println(" for (var ii :int = 0; ii < data.length; ii += 2) {");
|
||||
out.println(" o[data[ii]] = data[ii + 1];");
|
||||
out.println(" }");
|
||||
|
||||
// // alternate impl: just set each value directly. For non-trivial
|
||||
// // resource bundles, this generates a larger class after compilation
|
||||
// out.println(" var o :Object = new Object();");
|
||||
// for (Map.Entry<Object, Object> entry : props.entrySet()) {
|
||||
// String key = saveConvert((String) entry.getKey());
|
||||
// String val = saveConvert((String) entry.getValue());
|
||||
// out.println(" o[\"" + key + "\"] = \"" + val + "\";");
|
||||
// }
|
||||
|
||||
out.println(" return o;");
|
||||
out.println(" }");
|
||||
out.println("}}");
|
||||
out.close();
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert a string to be safe to output inside a string constant.
|
||||
*/
|
||||
protected String saveConvert (String str)
|
||||
{
|
||||
int len = str.length();
|
||||
StringBuilder buf = new StringBuilder(len * 2);
|
||||
|
||||
for (int ii = 0; ii < len; ii++) {
|
||||
char ch = str.charAt(ii);
|
||||
switch (ch) {
|
||||
case '\\':
|
||||
case '"':
|
||||
buf.append('\\').append(ch);
|
||||
break;
|
||||
|
||||
case '\t':
|
||||
buf.append('\\').append('t');
|
||||
break;
|
||||
|
||||
case '\n':
|
||||
buf.append('\\').append('n');
|
||||
break;
|
||||
|
||||
case '\r':
|
||||
buf.append('\\').append('r');
|
||||
break;
|
||||
|
||||
case '\f':
|
||||
buf.append('\\').append('f');
|
||||
break;
|
||||
|
||||
default:
|
||||
buf.append(ch);
|
||||
break;
|
||||
}
|
||||
}
|
||||
return buf.toString();
|
||||
}
|
||||
|
||||
protected ArrayList<FileSet> _filesets = Lists.newArrayList();
|
||||
|
||||
protected File _asroot;
|
||||
}
|
||||
@@ -1,158 +0,0 @@
|
||||
//
|
||||
// $Id$
|
||||
//
|
||||
// Narya library - tools for developing networked games
|
||||
// Copyright (C) 2002-2010 Three Rings Design, Inc., All Rights Reserved
|
||||
// http://code.google.com/p/narya/
|
||||
//
|
||||
// This library is free software; you can redistribute it and/or modify it
|
||||
// under the terms of the GNU Lesser General Public License as published
|
||||
// by the Free Software Foundation; either version 2.1 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// This library is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
// Lesser General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU Lesser General Public
|
||||
// License along with this library; if not, write to the Free Software
|
||||
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
|
||||
package com.threerings.presents.tools;
|
||||
|
||||
import java.lang.reflect.Field;
|
||||
import java.lang.reflect.Modifier;
|
||||
|
||||
import java.io.BufferedWriter;
|
||||
import java.io.File;
|
||||
import java.io.FileWriter;
|
||||
import java.io.PrintWriter;
|
||||
|
||||
import com.threerings.io.ObjectInputStream;
|
||||
import com.threerings.io.ObjectOutputStream;
|
||||
import com.threerings.io.Streamable;
|
||||
|
||||
import com.threerings.presents.data.InvocationMarshaller;
|
||||
import com.threerings.presents.dobj.DObject;
|
||||
|
||||
/**
|
||||
* Generates ActionScript versions of {@link Streamable} classes and provides routines used by the
|
||||
* {@link GenDObjectTask} to create ActionScript versions of distributed objects.
|
||||
*/
|
||||
public class GenActionScriptTask extends GenTask
|
||||
{
|
||||
/**
|
||||
* Configures the path to our ActionScript source files.
|
||||
*/
|
||||
public void setAsroot (File asroot)
|
||||
{
|
||||
_asroot = asroot;
|
||||
}
|
||||
|
||||
/**
|
||||
* Processes a resolved Streamable class instance.
|
||||
*/
|
||||
@Override
|
||||
public void processClass (File javaSource, Class<?> sclass)
|
||||
throws Exception
|
||||
{
|
||||
// make sure we implement Streamable but don't extend DObject or InvocationMarshaller and
|
||||
// that we're a class not an interface
|
||||
if (!Streamable.class.isAssignableFrom(sclass) ||
|
||||
DObject.class.isAssignableFrom(sclass) ||
|
||||
InvocationMarshaller.class.isAssignableFrom(sclass) ||
|
||||
((sclass.getModifiers() & Modifier.INTERFACE) != 0) ||
|
||||
ActionScriptUtils.hasOmitAnnotation(sclass)) {
|
||||
// System.err.println("Skipping " + sclass.getName() + "...");
|
||||
return;
|
||||
}
|
||||
|
||||
File output = ActionScriptUtils.createActionScriptPath(_asroot, sclass);
|
||||
|
||||
System.err.println("Converting " + sclass.getName() + "...");
|
||||
// parse the existing ActionScript source and generate what we don't
|
||||
// have from the Java class
|
||||
ActionScriptSource assrc = new ActionScriptSource(sclass);
|
||||
assrc.absorbJava(javaSource);
|
||||
assrc.imports.add(ObjectInputStream.class.getName());
|
||||
assrc.imports.add(ObjectOutputStream.class.getName());
|
||||
|
||||
// see if our parent also implements Streamable
|
||||
boolean needSuper = Streamable.class.isAssignableFrom(sclass.getSuperclass());
|
||||
|
||||
// add readObject() and writeObject() definitions
|
||||
ActionScriptSource.Member member;
|
||||
member = new ActionScriptSource.Member(
|
||||
"readObject", (needSuper ? "override " : "") + READ_SIG);
|
||||
member.noreplace = true;
|
||||
member.comment = " // from interface Streamable\n";
|
||||
StringBuilder body = new StringBuilder(" {\n");
|
||||
if (needSuper) {
|
||||
body.append(" super.readObject(ins);\n");
|
||||
}
|
||||
int added = 0;
|
||||
for (Field field : sclass.getDeclaredFields()) {
|
||||
if (!isStreamable(field)) {
|
||||
continue;
|
||||
}
|
||||
body.append(" ");
|
||||
body.append(field.getName()).append(" = ins.");
|
||||
body.append(ActionScriptUtils.toReadObject(field.getType()));
|
||||
body.append(";\n");
|
||||
added++;
|
||||
}
|
||||
member.body = body.append(" }\n").toString();
|
||||
if (added > 0) {
|
||||
assrc.publicMethods.add(member);
|
||||
}
|
||||
|
||||
member = new ActionScriptSource.Member(
|
||||
"writeObject", (needSuper ? "override " : "") + WRITE_SIG);
|
||||
member.noreplace = true;
|
||||
member.comment = " // from interface Streamable\n";
|
||||
body = new StringBuilder(" {\n");
|
||||
if (needSuper) {
|
||||
body.append(" super.writeObject(out);\n");
|
||||
}
|
||||
added = 0;
|
||||
for (Field field : sclass.getDeclaredFields()) {
|
||||
if (!isStreamable(field)) {
|
||||
continue;
|
||||
}
|
||||
body.append(" out.");
|
||||
body.append(ActionScriptUtils.toWriteObject(field.getType(), field.getName()));
|
||||
body.append(";\n");
|
||||
added++;
|
||||
}
|
||||
member.body = body.append(" }\n").toString();
|
||||
if (added > 0) {
|
||||
assrc.publicMethods.add(member);
|
||||
}
|
||||
|
||||
// now we can parse existing definitions from any extant ActionScript source file
|
||||
assrc.absorbActionScript(output);
|
||||
|
||||
// make sure our parent directory exists
|
||||
output.getParentFile().mkdirs();
|
||||
|
||||
// now write all that out to the target source file
|
||||
BufferedWriter out = new BufferedWriter(new FileWriter(output));
|
||||
assrc.write(new PrintWriter(out));
|
||||
}
|
||||
|
||||
protected boolean isStreamable (Field field)
|
||||
{
|
||||
int mods = field.getModifiers();
|
||||
return !Modifier.isStatic(mods) && !Modifier.isTransient(mods);
|
||||
}
|
||||
|
||||
/** The path to our ActionScript source files. */
|
||||
protected File _asroot;
|
||||
|
||||
protected static final String READ_SIG =
|
||||
"public function readObject (ins :ObjectInputStream) :void";
|
||||
protected static final String WRITE_SIG =
|
||||
"public function writeObject (out :ObjectOutputStream) :void";
|
||||
|
||||
}
|
||||
@@ -2,7 +2,6 @@ gendobj=com.threerings.presents.tools.GenDObjectTask
|
||||
genservice=com.threerings.presents.tools.GenServiceTask
|
||||
genreceiver=com.threerings.presents.tools.GenReceiverTask
|
||||
instream=com.threerings.presents.tools.InstrumentStreamableTask
|
||||
genascript=com.threerings.presents.tools.GenActionScriptTask
|
||||
genascriptstreamable=com.threerings.presents.tools.GenActionScriptStreamableTask
|
||||
gencppservice=com.threerings.presents.tools.cpp.GenCPPServiceTask
|
||||
gencppstreamable=com.threerings.presents.tools.cpp.GenCPPStreamableTask
|
||||
|
||||
Reference in New Issue
Block a user