Update of /cvsroot/hibernate/HibernateExt/tools/src/java/org/hibernate/tool/ant
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv5019/src/java/org/hibernate/tool/ant
Modified Files:
HibernateToolTask.java
Log Message:
HBX-602 Better error reporting from <hibernatetool> in ant
Index: HibernateToolTask.java
===================================================================
RCS file: /cvsroot/hibernate/HibernateExt/tools/src/java/org/hibernate/tool/ant/HibernateToolTask.java,v
retrieving revision 1.17
retrieving revision 1.18
diff -u -d -r1.17 -r1.18
--- HibernateToolTask.java 6 Feb 2006 09:08:09 -0000 1.17
+++ HibernateToolTask.java 17 Feb 2006 16:31:57 -0000 1.18
@@ -12,11 +12,13 @@
import org.apache.tools.ant.AntClassLoader;
import org.apache.tools.ant.BuildException;
+import org.apache.tools.ant.Project;
import org.apache.tools.ant.Task;
import org.apache.tools.ant.types.Environment;
import org.apache.tools.ant.types.Path;
import org.apache.tools.ant.types.PropertySet;
import org.hibernate.cfg.Configuration;
+import org.hibernate.util.StringHelper;
/**
* @author max
@@ -142,6 +144,8 @@
log(count++ + ". task: " + generatorTask.getName() );
generatorTask.execute();
}
+ } catch (RuntimeException re) {
+ reportException(re);
}
finally {
if (loader != null) {
@@ -151,6 +155,30 @@
}
}
+ private void reportException(Throwable re) {
+ log("An exception occurred. To get the full stack trace run ant with -verbose", Project.MSG_ERR);
+ log(re.toString(), Project.MSG_ERR);
+ String ex = new String();
+ Throwable cause = re.getCause();
+ while(cause!=null) {
+ ex += cause.toString() + "\n";
+ if(cause==cause.getCause()) {
+ break; // we reached the top.
+ } else {
+ cause=cause.getCause();
+ }
+ }
+ if(StringHelper.isNotEmpty(ex)) {
+ log(ex, Project.MSG_ERR);
+ }
+
+ if(re instanceof BuildException) {
+ throw (BuildException)re;
+ } else {
+ throw new BuildException(re, getLocation());
+ }
+ }
+
private void validateParameters() {
if(generators.isEmpty()) {
throw new BuildException("No exporters specified in <hibernatetool>. There has to be at least one specified. An exporter is e.g. <hbm2java> or <hbmtemplate>. See documentation for details.", getLocation());
|