This is an automated email from the ASF dual-hosted git repository.
ddekany pushed a commit to branch 2.3-gae
in repository https://gitbox.apache.org/repos/asf/freemarker.git
The following commit(s) were added to refs/heads/2.3-gae by this push:
new 663925cd Build: Reproducible build conde cleanup, and more
documentation for it.
663925cd is described below
commit 663925cd3989a1f798d0098cdfd87ec875dc7dbc
Author: ddekany <[email protected]>
AuthorDate: Wed Dec 27 11:41:59 2023 +0100
Build: Reproducible build conde cleanup, and more documentation for it.
---
README.md | 3 +++
build.gradle.kts | 23 ++++++++++------------
.../java/freemarker/template/Configuration.java | 11 ++++++-----
.../src/main/java/freemarker/template/Version.java | 4 +++-
freemarker-manual/src/main/docgen/en_US/book.xml | 16 +++++++++++++++
5 files changed, 38 insertions(+), 19 deletions(-)
diff --git a/README.md b/README.md
index 5c23bd74..e2826286 100644
--- a/README.md
+++ b/README.md
@@ -137,6 +137,9 @@ see `gradle.properties` in this project for those!
See `gradle.properties` for some Gradle properties that you may what to set,
especially if you are building a release.
+Reproducible builds: If the resulting `freemarker.jar` is not identical with
the official jar, see the build environment
+in the `.buildinfo` file packed into the official source distribution, and
also into the Maven "sources" artifact!
+
IDE setup
---------
diff --git a/build.gradle.kts b/build.gradle.kts
index fc37519d..be443d8d 100644
--- a/build.gradle.kts
+++ b/build.gradle.kts
@@ -17,11 +17,11 @@
* under the License.
*/
+import java.io.FileOutputStream
import java.nio.charset.StandardCharsets
import java.nio.file.Files
+import java.util.*
import java.util.stream.Collectors
-import java.util.Properties
-import java.io.FileOutputStream
plugins {
`freemarker-root`
@@ -99,6 +99,9 @@ val compileJavacc =
tasks.register<freemarker.build.CompileJavaccTask>("compileJ
}
sourceSets.main.get().java.srcDir(compileJavacc)
+fun buildInfoFile(): File
+ =
project.layout.buildDirectory.get().asFile.resolve("buildinfo").resolve(".buildinfo")
+
tasks.sourcesJar.configure {
from(compileJavacc.flatMap { it.sourceDirectory })
@@ -108,9 +111,7 @@ tasks.sourcesJar.configure {
// Depend on the createBuildInfo task and include the generated file
dependsOn(createBuildInfo)
- from(File(project.buildDir, "tmp/buildinfo")) {
- include(".buildinfo")
- }
+ from(buildInfoFile())
}
tasks.javadocJar.configure {
@@ -422,7 +423,7 @@ val distBin = tasks.register<Tar>("distBin") {
val jarFile = tasks.named<Jar>("jar").flatMap { jar -> jar.archiveFile }
from(jarFile) {
- rename { name -> "freemarker.jar" }
+ rename { _ -> "freemarker.jar" }
}
from(tasks.named("manualOffline")) {
@@ -435,10 +436,9 @@ val distBin = tasks.register<Tar>("distBin") {
}
registerDistSupportTasks(distBin)
-// Task to generate buildinfo.properties
val createBuildInfo = tasks.register("createBuildInfo") {
doLast {
- val buildInfoFile = File(project.buildDir, "tmp/buildinfo/.buildinfo")
+ val buildInfoFile = buildInfoFile()
buildInfoFile.parentFile.mkdirs()
val props = Properties().apply {
@@ -458,7 +458,7 @@ val createBuildInfo = tasks.register("createBuildInfo") {
}
FileOutputStream(buildInfoFile).use { outputStream ->
- props.store(outputStream, "Effective recorded build environment
information")
+ props.store(outputStream, " Build environment information recorded
for reproducible builds")
}
}
}
@@ -495,12 +495,9 @@ val distSrc = tasks.register<Tar>("distSrc") {
)
}
-
// Depend on the createBuildInfo task and include the generated file
dependsOn(createBuildInfo)
- from(File(project.buildDir, "tmp/buildinfo")) {
- include(".buildinfo")
- }
+ from(buildInfoFile())
}
registerDistSupportTasks(distSrc)
diff --git
a/freemarker-core/src/main/java/freemarker/template/Configuration.java
b/freemarker-core/src/main/java/freemarker/template/Configuration.java
index a2d9dcc8..331f5aed 100644
--- a/freemarker-core/src/main/java/freemarker/template/Configuration.java
+++ b/freemarker-core/src/main/java/freemarker/template/Configuration.java
@@ -26,10 +26,8 @@ import java.lang.reflect.InvocationTargetException;
import java.net.URLConnection;
import java.text.Collator;
import java.text.DecimalFormat;
-import java.text.SimpleDateFormat;
import java.util.Collection;
import java.util.Collections;
-import java.util.Date;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
@@ -3704,8 +3702,8 @@ public class Configuration extends Configurable
implements Cloneable, ParserConf
* do NOT use this as the value of the {@code incompatible_improvements}
setting (as the parameter to
* {@link Configuration#Configuration(Version)}), as then your application
can break when you upgrade FreeMarker!
* Use a constant value, like {@link #VERSION_2_3_28}, to protect your
application from fixes/changes that aren't
- * entirely backward compatible. Fixes and features that are backward
compatible are always enabled.
- *
+ * entirely backward compatible. Fixes and features that are backward
compatible are always enabled.
+ *
* On FreeMarker version numbering rules:
* <ul>
* <li>For final/stable releases the version number is like
major.minor.micro, like 2.3.19. (Historically,
@@ -3728,7 +3726,10 @@ public class Configuration extends Configurable
implements Cloneable, ParserConf
* Also, "pre" and "rc" was lowercase, and was followd by a
number without 0-padding.</li>
* </ul>
* </ul>
- *
+ *
+ * <p>Starting from 2.3.33, {@link Version#getBuildDate()} will return
{@code null}, as we don't store the build
+ * date anymore, to make the build reproducible.
+ *
* @since 2.3.20
*/
public static Version getVersion() {
diff --git a/freemarker-core/src/main/java/freemarker/template/Version.java
b/freemarker-core/src/main/java/freemarker/template/Version.java
index ac25be11..24b7501f 100644
--- a/freemarker-core/src/main/java/freemarker/template/Version.java
+++ b/freemarker-core/src/main/java/freemarker/template/Version.java
@@ -229,7 +229,9 @@ public final class Version implements Serializable {
}
/**
- * @deprecated do not used anymore
+ * @deprecated Will always return {@code null} for the FreeMarker version,
as we can't store the build date anymore
+ * in the jar, in order to have a reproducible build.
+ *
* @return The build date if known, or {@code null}.
*/
public Date getBuildDate() {
diff --git a/freemarker-manual/src/main/docgen/en_US/book.xml
b/freemarker-manual/src/main/docgen/en_US/book.xml
index e1942050..dfeadb1e 100644
--- a/freemarker-manual/src/main/docgen/en_US/book.xml
+++ b/freemarker-manual/src/main/docgen/en_US/book.xml
@@ -30278,6 +30278,15 @@ TemplateModel x = env.getVariable("x"); // get
variable x</programlisting>
was removed from the JDK, starting with JDK 15.)</para>
</listitem>
+ <listitem>
+
<para><literal>Configuration.getVersion().getBuildDate()</literal>
+ will now always return <literal>null</literal>, as we don't
+ store the build date anymore, to make the build reproducible.
+ For same reason, <literal>META-INF/MANIFEST.FM</literal> now
+ will not store any timestamps, nor information about the build
+ environment.</para>
+ </listitem>
+
<listitem>
<para>Build changes (in case you build FreeMarker itself, not
just depend on it):</para>
@@ -30302,6 +30311,13 @@ TemplateModel x = env.getVariable("x"); // get
variable x</programlisting>
<para>JavaDoc is now generated with JDK 16 (so now we have
search on it)</para>
</listitem>
+
+ <listitem>
+ <para>The build is now reproducible (see <link
+
xlink:href="https://reproducible-builds.org">reproducible-builds.org</link>).
+ However, therefore it doesn't contain any build timestamps
+ anymore.</para>
+ </listitem>
</itemizedlist>
</listitem>