Throw a BuildException if Velocity fails so that we don't write bogus data back

out to the source file.
This commit is contained in:
Michael Bayne
2009-07-11 21:26:33 +00:00
parent bc7a31c661
commit 21ceb241b4
@@ -125,6 +125,7 @@ public class GenRecordTask extends Task
name = readClassName(source); name = readClassName(source);
} catch (Exception e) { } catch (Exception e) {
System.err.println("Failed to parse " + source + ": " + e.getMessage()); System.err.println("Failed to parse " + source + ": " + e.getMessage());
return;
} }
try { try {
@@ -389,14 +390,13 @@ public class GenRecordTask extends Task
/** Helper function for generating our boilerplate code. */ /** Helper function for generating our boilerplate code. */
protected String mergeTemplate (String tmpl, VelocityContext ctx) protected String mergeTemplate (String tmpl, VelocityContext ctx)
{ {
StringWriter writer = new StringWriter();
try { try {
StringWriter writer = new StringWriter();
_velocity.mergeTemplate(tmpl, "UTF-8", ctx, writer); _velocity.mergeTemplate(tmpl, "UTF-8", ctx, writer);
return writer.toString();
} catch (Exception e) { } catch (Exception e) {
System.err.println("Failed processing template [tmpl=" + tmpl + "]"); throw new BuildException("Failed processing template [tmpl=" + tmpl + "]", e);
e.printStackTrace(System.err);
} }
return writer.toString();
} }
protected static boolean hasAnnotation (Field field, Class<?> annotation) protected static boolean hasAnnotation (Field field, Class<?> annotation)