From f7b9a00893c3958ec290b206e14d7dfae8f0c760 Mon Sep 17 00:00:00 2001 From: Mark Thomas Date: Thu, 24 Mar 2022 17:00:22 +0000 Subject: [PATCH] Fix build when ant.tstamp.now is not specified --- build.xml | 2 +- .../tomcat/buildutil/RepeatableArchive.java | 23 ++++++++++++++++--- 2 files changed, 21 insertions(+), 4 deletions(-) diff --git a/build.xml b/build.xml index a231c1719769..b0f96d316606 100644 --- a/build.xml +++ b/build.xml @@ -2879,7 +2879,7 @@ skip.installer property in build.properties" /> - + diff --git a/java/org/apache/tomcat/buildutil/RepeatableArchive.java b/java/org/apache/tomcat/buildutil/RepeatableArchive.java index 29975884d8b6..1348ee64c9a3 100644 --- a/java/org/apache/tomcat/buildutil/RepeatableArchive.java +++ b/java/org/apache/tomcat/buildutil/RepeatableArchive.java @@ -23,6 +23,9 @@ import java.nio.file.Files; import java.nio.file.StandardCopyOption; import java.nio.file.attribute.FileTime; +import java.text.ParseException; +import java.text.SimpleDateFormat; +import java.util.Date; import java.util.Enumeration; import java.util.LinkedList; import java.util.List; @@ -48,7 +51,8 @@ public class RepeatableArchive extends Task { private final List filesets = new LinkedList<>(); - private long datetime; + private String datetime; + private String pattern; /** * Sets the files to be processed @@ -60,16 +64,29 @@ public void addFileset(FileSet fs) { } - public void setDatetime(long datetime) { + public void setDatetime(String datetime) { this.datetime = datetime; } + public void setPattern(String pattern) { + this.pattern = pattern; + } + + @Override public void execute() throws BuildException { + SimpleDateFormat sdf = new SimpleDateFormat(pattern); + Date date; + try { + date = sdf.parse(datetime); + } catch (ParseException e) { + throw new BuildException(e); + } + byte[] buf = new byte[8192]; - FileTime lastModified = FileTime.fromMillis(datetime); + FileTime lastModified = FileTime.fromMillis(date.getTime()); for (FileSet fs : filesets) { DirectoryScanner ds = fs.getDirectoryScanner(getProject());