From 4496ec9ae4ba714477325af16e886cae912fccdf Mon Sep 17 00:00:00 2001 From: Ray Greenwell Date: Wed, 7 Apr 2010 16:12:04 +0000 Subject: [PATCH] Mdb dislikes the date and points out that our tasks regenerate these files every time, so it'll get in the way of version control. Mrmph. So: make the date optional, and leave it out for now. Other comments? git-svn-id: svn+ssh://src.earth.threerings.net/narya/trunk@6051 542714f4-19e9-0310-aa3c-eee0fc999fb1 --- .../presents/tools/GenDObjectTask.java | 2 +- .../presents/tools/GenServiceTask.java | 12 ++++----- .../threerings/presents/tools/GenUtil.java | 27 +++++++++++-------- 3 files changed, 23 insertions(+), 18 deletions(-) diff --git a/src/java/com/threerings/presents/tools/GenDObjectTask.java b/src/java/com/threerings/presents/tools/GenDObjectTask.java index ba7f77014..99ad41901 100644 --- a/src/java/com/threerings/presents/tools/GenDObjectTask.java +++ b/src/java/com/threerings/presents/tools/GenDObjectTask.java @@ -171,7 +171,7 @@ public class GenDObjectTask extends Task // create our velocity context VelocityContext ctx = new VelocityContext(); ctx.put("field", fname); - ctx.put("generated", GenUtil.getGeneratedAnnotation(getClass(), 4)); + ctx.put("generated", GenUtil.getGeneratedAnnotation(getClass(), 4, false)); ctx.put("type", GenUtil.simpleName(f)); ctx.put("wrapfield", GenUtil.boxArgument(ftype, "value")); ctx.put("wrapofield", GenUtil.boxArgument(ftype, "ovalue")); diff --git a/src/java/com/threerings/presents/tools/GenServiceTask.java b/src/java/com/threerings/presents/tools/GenServiceTask.java index f39cb9d97..fc5496f98 100644 --- a/src/java/com/threerings/presents/tools/GenServiceTask.java +++ b/src/java/com/threerings/presents/tools/GenServiceTask.java @@ -265,7 +265,7 @@ public class GenServiceTask extends InvocationTask VelocityContext ctx = new VelocityContext(); ctx.put("name", name); - ctx.put("generated", getGeneratedAnnotation()); + ctx.put("generated", getGeneratedAnnotation(name)); ctx.put("package", mpackage); ctx.put("methods", sdesc.methods); ctx.put("listeners", sdesc.listeners); @@ -537,7 +537,7 @@ public class GenServiceTask extends InvocationTask VelocityContext ctx = new VelocityContext(); ctx.put("name", name); - ctx.put("generated", getGeneratedAnnotation()); + ctx.put("generated", getGeneratedAnnotation(name)); ctx.put("package", dpackage); ctx.put("methods", sdesc.methods); ctx.put("imports", imports.toList()); @@ -596,7 +596,7 @@ public class GenServiceTask extends InvocationTask VelocityContext ctx = new VelocityContext(); ctx.put("name", name); - ctx.put("generated", getGeneratedAnnotation()); + ctx.put("generated", getGeneratedAnnotation(name)); ctx.put("package", mpackage); ctx.put("methods", sdesc.methods); ctx.put("listeners", sdesc.listeners); @@ -616,10 +616,10 @@ public class GenServiceTask extends InvocationTask /** * Helper to get the appropriate "@Generated" annotation for service classes. */ - protected String getGeneratedAnnotation () + protected String getGeneratedAnnotation (String name) { - return GenUtil.getGeneratedAnnotation(getClass(), 0, - "Derived from the Service class java source."); + return GenUtil.getGeneratedAnnotation(getClass(), 0, false, + "Derived from " + name + "Service.java."); } /** Rolls up everything needed for the generate* methods. */ diff --git a/src/java/com/threerings/presents/tools/GenUtil.java b/src/java/com/threerings/presents/tools/GenUtil.java index 51e66befc..97ef758fa 100644 --- a/src/java/com/threerings/presents/tools/GenUtil.java +++ b/src/java/com/threerings/presents/tools/GenUtil.java @@ -246,24 +246,29 @@ public class GenUtil extends com.samskivert.util.GenUtil * * @param clazz the class doing the code generation, NOT the generation target. * @param indent the number of spaces that the annotation is indented. + * @param includeDate include the date? * @param comments joined by a space and used as explanatory comments. */ - public static String getGeneratedAnnotation (Class clazz, int indent, String... comments) + public static String getGeneratedAnnotation ( + Class clazz, int indent, boolean includeDate, String... comments) { final int LINE_LENGTH = 100; String comm = StringUtil.join(comments, " "); boolean hasComment = !StringUtil.isBlank(comm); - String anno = "@Generated(value={\"" + clazz.getName() + "\"},"; - // ISO 8601 date - String date = " date=\"" + - new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ssZ").format(new Date()) + "\""; - // wrap the date onto a new line if it's going to be too long, or if we're - // adding a comment (which is also on a new line) - if (hasComment || anno.length() + date.length() + 1 + indent > LINE_LENGTH) { - // put the date on a new line, space it right - date = "\n" + StringUtil.fill(' ', indent + 10) + date; + String anno = "@Generated(value={\"" + clazz.getName() + "\"}"; + if (includeDate) { + anno += ","; + // ISO 8601 date + String date = " date=\"" + + new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ssZ").format(new Date()) + "\""; + // wrap the date onto a new line if it's going to be too long, or if we're + // adding a comment (which is also on a new line) + if (hasComment || anno.length() + date.length() + 1 + indent > LINE_LENGTH) { + // put the date on a new line, space it right + date = "\n" + StringUtil.fill(' ', indent + 10) + date; + } + anno += date; } - anno += date; if (hasComment) { anno += ",\n" + StringUtil.fill(' ', indent + 11) + "comments=\"" + comm + "\""; }