From: <hib...@li...> - 2006-07-27 12:10:55
|
Author: max...@jb... Date: 2006-07-26 08:18:38 -0400 (Wed, 26 Jul 2006) New Revision: 10157 Modified: trunk/HibernateExt/tools/src/java/org/hibernate/tool/ant/HibernateToolTask.java Log: HBX-710 bomb detection Modified: trunk/HibernateExt/tools/src/java/org/hibernate/tool/ant/HibernateToolTask.java =================================================================== --- trunk/HibernateExt/tools/src/java/org/hibernate/tool/ant/HibernateToolTask.java 2006-07-26 11:38:41 UTC (rev 10156) +++ trunk/HibernateExt/tools/src/java/org/hibernate/tool/ant/HibernateToolTask.java 2006-07-26 12:18:38 UTC (rev 10157) @@ -17,6 +17,8 @@ import org.apache.tools.ant.types.Environment; import org.apache.tools.ant.types.Path; import org.apache.tools.ant.types.PropertySet; +import org.hibernate.MappingException; +import org.hibernate.MappingNotFoundException; import org.hibernate.cfg.Configuration; import org.hibernate.util.StringHelper; @@ -173,6 +175,7 @@ private void reportException(Throwable re, int count, ExporterTask generatorTask) { log("An exception occurred while running exporter #" + count + ":" + generatorTask.getName(), Project.MSG_ERR); log("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(); @@ -187,6 +190,11 @@ if(StringHelper.isNotEmpty(ex)) { log(ex, Project.MSG_ERR); } + + String newbieMessage = getProbableSolutionOrCause(re); + if(newbieMessage!=null) { + log(newbieMessage); + } if(re instanceof BuildException) { throw (BuildException)re; @@ -195,6 +203,50 @@ } } + private String getProbableSolutionOrCause(Throwable re) { + if(re==null) return null; + + if(re instanceof MappingNotFoundException) { + MappingNotFoundException mnf = (MappingNotFoundException)re; + if("resource".equals(mnf.getType())) { + return "A " + mnf.getType() + " located at " + mnf.getPath() + " was not found.\n" + + "Check the following:\n" + + "\n" + + "1) Is the spelling/casing correct ?\n" + + "2) Is " + mnf.getPath() + " available via the classpath ?\n" + + "3) Does it actually exist ?\n"; + } else { + return "A " + mnf.getType() + " located at " + mnf.getPath() + " was not found.\n" + + "Check the following:\n" + + "\n" + + "1) Is the spelling/casing correct ?\n" + + "2) Do you permission to access " + mnf.getPath() + " ?\n" + + "3) Does it actually exist ?\n"; + } + } + + if(re instanceof ClassNotFoundException || re instanceof NoClassDefFoundError) { + + return "A class were not found in the classpath of the Ant task.\n" + + "Ensure that the classpath contains the classes needed for Hibernate and your code are in the classpath.\n"; + + } + + if(re instanceof UnsupportedClassVersionError) { + return "You are most likely running the ant task with a JRE that is older than the JRE required to use the classes.\n" + + "e.g. running with JRE 1.3 or 1.4 when using JDK 1.5 annotations is not possible.\n" + + "Ensure that you are using a correct JRE."; + } + + + + if(re.getCause()!=re) { + return getProbableSolutionOrCause( re.getCause() ); + } + + return null; + } + 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()); |