From 374690d5793248f26d5894a33bb5ed562e22da91 Mon Sep 17 00:00:00 2001 From: Mark Thomas Date: Fri, 9 Oct 2020 14:02:50 +0100 Subject: [PATCH] Fix BZ 64784. Don't include timestamp in .java file when pre-compiling --- java/org/apache/jasper/JspC.java | 13 +++++++++++++ java/org/apache/jasper/Options.java | 12 ++++++++++++ java/org/apache/jasper/compiler/Generator.java | 6 ++++-- webapps/docs/changelog.xml | 6 ++++++ 4 files changed, 35 insertions(+), 2 deletions(-) diff --git a/java/org/apache/jasper/JspC.java b/java/org/apache/jasper/JspC.java index ff28ed105bdb..3804d2aec54e 100644 --- a/java/org/apache/jasper/JspC.java +++ b/java/org/apache/jasper/JspC.java @@ -1124,6 +1124,19 @@ public TagPluginManager getTagPluginManager() { return tagPluginManager; } + + /** + * {@inheritDoc} + *

+ * Hard-coded to {@code false} for pre-compiled code to enable repeatable + * builds. + */ + @Override + public boolean getGeneratedJavaAddTimestamp() { + return false; + } + + /** * Adds servlet declaration and mapping for the JSP page servlet to the * generated web.xml fragment. diff --git a/java/org/apache/jasper/Options.java b/java/org/apache/jasper/Options.java index 4b100aa78b4c..19f394749e65 100644 --- a/java/org/apache/jasper/Options.java +++ b/java/org/apache/jasper/Options.java @@ -360,4 +360,16 @@ public default String getTempVariableNamePrefix() { public default boolean getUseInstanceManagerForTags() { return false; } + + + /** + * Should the container include the time the file was generated in the + * comments at the start of a Java file generated from a JSP or tag. + * Defaults to {@code true}. + * + * @return {@code true} to include the timestamp, otherwise don't include it + */ + public default boolean getGeneratedJavaAddTimestamp() { + return true; + } } diff --git a/java/org/apache/jasper/compiler/Generator.java b/java/org/apache/jasper/compiler/Generator.java index bcd0412cd1f2..21593d8c85e1 100644 --- a/java/org/apache/jasper/compiler/Generator.java +++ b/java/org/apache/jasper/compiler/Generator.java @@ -3669,8 +3669,10 @@ private void generateCommentHeader() { out.println("/*"); out.println(" * Generated by the Jasper component of Apache Tomcat"); out.println(" * Version: " + ctxt.getServletContext().getServerInfo()); - out.println(" * Generated at: " + timestampFormat.format(new Date()) + - " UTC"); + if (ctxt.getOptions().getGeneratedJavaAddTimestamp()) { + out.println(" * Generated at: " + timestampFormat.format(new Date()) + + " UTC"); + } out.println(" * Note: The last modified time of this file was set to"); out.println(" * the last modified time of the source file after"); out.println(" * generation to assist with modification tracking."); diff --git a/webapps/docs/changelog.xml b/webapps/docs/changelog.xml index 68859ce9552d..691ec3112039 100644 --- a/webapps/docs/changelog.xml +++ b/webapps/docs/changelog.xml @@ -73,6 +73,12 @@ + + 64784: Don't include the time the Java file was generated as + a comment when generating Java files for JSPs and/or tags if the Java + file was created during pre-compilation. This is to aid repeatable + builds. (markt) + 64794: Security exception reading system property on JspRuntimeLibrary use. (remm)