Author: markt Date: Wed May 10 19:57:33 2017 New Revision: 1794752 URL: http://svn.apache.org/viewvc?rev=1794752&view=rev Log: Fix https://bz.apache.org/bugzilla/show_bug.cgi?id=53011 When pre-compiling with JspC, report all compilation errors rather than stopping after the first error. A new option -failFast can be used to restore the previous behaviour of stopping after the first error. Based on a patch provided by Marc Pompl.
Modified: tomcat/trunk/java/org/apache/jasper/JspC.java tomcat/trunk/java/org/apache/jasper/resources/LocalStrings.properties tomcat/trunk/webapps/docs/changelog.xml Modified: tomcat/trunk/java/org/apache/jasper/JspC.java URL: http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/jasper/JspC.java?rev=1794752&r1=1794751&r2=1794752&view=diff ============================================================================== --- tomcat/trunk/java/org/apache/jasper/JspC.java (original) +++ tomcat/trunk/java/org/apache/jasper/JspC.java Wed May 10 19:57:33 2017 @@ -114,6 +114,7 @@ public class JspC extends Task implement protected static final String SWITCH_CLASS_NAME = "-c"; protected static final String SWITCH_FULL_STOP = "--"; protected static final String SWITCH_COMPILE = "-compile"; + protected static final String SWITCH_FAIL_FAST = "-failFast"; protected static final String SWITCH_SOURCE = "-source"; protected static final String SWITCH_TARGET = "-target"; protected static final String SWITCH_URI_BASE = "-uribase"; @@ -185,6 +186,7 @@ public class JspC extends Task implement protected int dieLevel; protected boolean helpNeeded = false; protected boolean compile = false; + protected boolean failFast = false; protected boolean smapSuppressed = true; protected boolean smapDumped = false; protected boolean caching = true; @@ -313,6 +315,8 @@ public class JspC extends Task implement targetPackage = nextArg(); } else if (tok.equals(SWITCH_COMPILE)) { compile=true; + } else if (tok.equals(SWITCH_FAIL_FAST)) { + failFast = true; } else if (tok.equals(SWITCH_CLASS_NAME)) { targetClassName = nextArg(); } else if (tok.equals(SWITCH_URI_BASE)) { @@ -1279,14 +1283,7 @@ public class JspC extends Task implement file), rootCause); } - - // Bugzilla 35114. - if(getFailOnError()) { - throw je; - } else { - log.error(je.getMessage()); - } - + throw je; } catch (Exception e) { if ((e instanceof FileNotFoundException) && log.isWarnEnabled()) { log.warn(Localizer.getMessage("jspc.error.fileDoesNotExist", @@ -1389,6 +1386,9 @@ public class JspC extends Task implement initWebXml(); + int errorCount = 0; + long start = System.currentTimeMillis(); + for (String nextjsp : pages) { File fjsp = new File(nextjsp); if (!fjsp.isAbsolute()) { @@ -1409,7 +1409,24 @@ public class JspC extends Task implement if (nextjsp.startsWith("." + File.separatorChar)) { nextjsp = nextjsp.substring(2); } - processFile(nextjsp); + try { + processFile(nextjsp); + } catch (JasperException e) { + if (failFast) { + throw e; + } + errorCount++; + log.error(nextjsp + ":" + e.getMessage()); + } + } + + long time = System.currentTimeMillis() - start; + String msg = Localizer.getMessage("jspc.compilation.result", + Integer.toString(errorCount), Long.toString(time)); + if (failOnError && errorCount > 0) { + throw new BuildException(msg); + } else { + log.info(msg); } completeWebXml(); @@ -1422,15 +1439,9 @@ public class JspC extends Task implement throw new BuildException(ioe); } catch (JasperException je) { - Throwable rootCause = je; - while (rootCause instanceof JasperException - && ((JasperException) rootCause).getRootCause() != null) { - rootCause = ((JasperException) rootCause).getRootCause(); - } - if (rootCause != je) { - rootCause.printStackTrace(); + if (failOnError) { + throw new BuildException(je); } - throw new BuildException(je); } finally { if (loader != null) { LogFactory.release(loader); Modified: tomcat/trunk/java/org/apache/jasper/resources/LocalStrings.properties URL: http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/jasper/resources/LocalStrings.properties?rev=1794752&r1=1794751&r2=1794752&view=diff ============================================================================== --- tomcat/trunk/java/org/apache/jasper/resources/LocalStrings.properties (original) +++ tomcat/trunk/java/org/apache/jasper/resources/LocalStrings.properties Wed May 10 19:57:33 2017 @@ -152,6 +152,7 @@ jsp.warning.compiler.javafile.delete.fai jsp.error.jspc.uriroot_not_dir=The -uriroot option must specify a pre-existing directory jsp.error.jspc.missingTarget=Missing target: Must specify -webapp or -uriroot, or one or more JSP pages jsp.error.jspc.no_uriroot=The uriroot is not specified and cannot be located with the specified JSP file(s) +jspc.compilation.result=Compilation completed with [{0}] errors in [{1}] milliseconds jspc.implicit.uriRoot=uriRoot implicitly set to [{0}] jspc.usage=Usage: jspc <options> [--] <jsp files>\n\ where jsp files is\n\ @@ -173,6 +174,7 @@ where options include:\n\ \ (default "/")\n\ \ -uriroot <dir> Same as -webapp\n\ \ -compile Compiles generated servlets\n\ +\ -failFast Stop on first compile error\n\ \ -webinc <file> Creates a partial servlet mappings in the file\n\ \ -webxml <file> Creates a complete web.xml in the file\n\ \ -webxmlencoding <enc> Set the encoding charset used to read and write the web.xml\n\ Modified: tomcat/trunk/webapps/docs/changelog.xml URL: http://svn.apache.org/viewvc/tomcat/trunk/webapps/docs/changelog.xml?rev=1794752&r1=1794751&r2=1794752&view=diff ============================================================================== --- tomcat/trunk/webapps/docs/changelog.xml (original) +++ tomcat/trunk/webapps/docs/changelog.xml Wed May 10 19:57:33 2017 @@ -59,6 +59,17 @@ </fix> </changelog> </subsection> + <subsection name="Jasper"> + <changelog> + <fix> + <bug>53011</bug>: When pre-compiling with JspC, report all compilation + errors rather than stopping after the first error. A new option + <code>-failFast</code> can be used to restore the previous behaviour of + stopping after the first error. Based on a patch provided by Marc Pompl. + (markt) + </fix> + </changelog> + </subsection> </section> <section name="Tomcat 9.0.0.M21 (markt)" rtext="release in progress"> <subsection name="General"> --------------------------------------------------------------------- To unsubscribe, e-mail: dev-unsubscr...@tomcat.apache.org For additional commands, e-mail: dev-h...@tomcat.apache.org