Skip to content

Commit 242bdbe

Browse files
committed
fix to ensure a build-time link to the modify timestamp of resource download
1 parent 0acbe19 commit 242bdbe

File tree

5 files changed

+47
-13
lines changed

5 files changed

+47
-13
lines changed

haikudepotserver-core/pom.xml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,11 @@
1212
<artifactId>haikudepotserver-core</artifactId>
1313
<packaging>jar</packaging>
1414

15+
<properties>
16+
<!-- https://stackoverflow.com/questions/13228472/how-to-access-maven-build-timestamp-for-resource-filtering -->
17+
<hds.build.timestamp>${maven.build.timestamp}</hds.build.timestamp>
18+
</properties>
19+
1520
<dependencies>
1621

1722
<dependency>

haikudepotserver-core/src/main/java/org/haiku/haikudepotserver/reference/job/ReferenceDumpExportJobRunner.java

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2018-2019, Andrew Lindesay
2+
* Copyright 2018-2020, Andrew Lindesay
33
* Distributed under the terms of the MIT License.
44
*/
55

@@ -101,11 +101,21 @@ private void writeData(
101101
objectMapper.writeValue(jsonGenerator, dumpExportReference.getPkgCategories());
102102
}
103103

104-
private ArchiveInfo createArchiveInfo(ObjectContext context) {
104+
public static Date getModifyTimestamp(ObjectContext context, RuntimeInformationService runtimeInformationService) {
105105
Date modifyTimestamp = GeneralQueryHelper.getLastModifyTimestampSecondAccuracy(
106106
context,
107107
Country.class, NaturalLanguage.class, PkgCategory.class);
108-
return new ArchiveInfo(modifyTimestamp, runtimeInformationService.getProjectVersion());
108+
Date buildTimestamp = new Date(runtimeInformationService.getBuildTimestamp().toEpochMilli());
109+
if (buildTimestamp.getTime() > modifyTimestamp.getTime()) {
110+
return buildTimestamp;
111+
}
112+
return modifyTimestamp;
113+
}
114+
115+
private ArchiveInfo createArchiveInfo(ObjectContext context) {
116+
return new ArchiveInfo(
117+
getModifyTimestamp(context, runtimeInformationService),
118+
runtimeInformationService.getProjectVersion());
109119
}
110120

111121
private DumpExportReference createDumpExportReference(ReferenceDumpExportJobSpecification specification) {

haikudepotserver-core/src/main/java/org/haiku/haikudepotserver/support/RuntimeInformationService.java

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,18 @@
11
/*
2-
* Copyright 2018, Andrew Lindesay
2+
* Copyright 2018-2020, Andrew Lindesay
33
* Distributed under the terms of the MIT License.
44
*/
55

66
package org.haiku.haikudepotserver.support;
77

88
import com.google.common.base.Strings;
9+
import org.apache.commons.lang3.StringUtils;
910

1011
import java.io.IOException;
1112
import java.io.InputStream;
13+
import java.time.Instant;
14+
import java.time.format.DateTimeFormatter;
15+
import java.util.Optional;
1216
import java.util.Properties;
1317

1418
/**
@@ -49,6 +53,16 @@ public String getProjectVersion() {
4953
return versionOrPlaceholder(getBuildProperties().getProperty("project.version"));
5054
}
5155

56+
public Instant getBuildTimestamp() {
57+
return Optional.of(getBuildProperties().getProperty("build.timestamp"))
58+
.filter(StringUtils::isNotBlank)
59+
.filter(s -> !StringUtils.startsWith(s, "${"))
60+
// ^^ if the variable is not substituted in the build process
61+
.map(DateTimeFormatter.ISO_INSTANT::parse)
62+
.map(Instant::from)
63+
.orElseGet(() -> Instant.ofEpochMilli(0L));
64+
}
65+
5266
public String getJavaVersion() {
5367
return versionOrPlaceholder(System.getProperty("java.version"));
5468
}
Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
# Values in this properties file will be replaced as part of the build process.
2-
project.version=${project.version}
2+
project.version=${project.version}
3+
build.timestamp=${hds.build.timestamp}

haikudepotserver-webapp/src/main/java/org/haiku/haikudepotserver/reference/controller/ReferenceController.java

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2018, Andrew Lindesay
2+
* Copyright 2018-2020, Andrew Lindesay
33
* Distributed under the terms of the MIT License.
44
*/
55

@@ -8,13 +8,11 @@
88
import com.google.common.base.Preconditions;
99
import com.google.common.net.HttpHeaders;
1010
import org.apache.cayenne.configuration.server.ServerRuntime;
11-
import org.haiku.haikudepotserver.dataobjects.Country;
12-
import org.haiku.haikudepotserver.dataobjects.NaturalLanguage;
13-
import org.haiku.haikudepotserver.dataobjects.PkgCategory;
1411
import org.haiku.haikudepotserver.job.controller.JobController;
1512
import org.haiku.haikudepotserver.job.model.JobService;
13+
import org.haiku.haikudepotserver.reference.job.ReferenceDumpExportJobRunner;
1614
import org.haiku.haikudepotserver.reference.model.ReferenceDumpExportJobSpecification;
17-
import org.haiku.haikudepotserver.support.cayenne.GeneralQueryHelper;
15+
import org.haiku.haikudepotserver.support.RuntimeInformationService;
1816
import org.haiku.haikudepotserver.support.web.AbstractController;
1917
import org.springframework.stereotype.Controller;
2018
import org.springframework.web.bind.annotation.PathVariable;
@@ -31,10 +29,15 @@ public class ReferenceController extends AbstractController {
3129

3230
private final static String KEY_NATURALLANGUAGECODE = "naturalLanguageCode";
3331

32+
private final RuntimeInformationService runtimeInformationService;
3433
private final ServerRuntime serverRuntime;
3534
private final JobService jobService;
3635

37-
public ReferenceController(ServerRuntime serverRuntime, JobService jobService) {
36+
public ReferenceController(
37+
RuntimeInformationService runtimeInformationService,
38+
ServerRuntime serverRuntime,
39+
JobService jobService) {
40+
this.runtimeInformationService = runtimeInformationService;
3841
this.serverRuntime = Preconditions.checkNotNull(serverRuntime);
3942
this.jobService = Preconditions.checkNotNull(jobService);
4043
}
@@ -60,9 +63,10 @@ public void getAllAsJson(
6063
response,
6164
jobService,
6265
ifModifiedSinceHeader,
63-
GeneralQueryHelper.getLastModifyTimestampSecondAccuracy(
66+
ReferenceDumpExportJobRunner.getModifyTimestamp(
6467
serverRuntime.newContext(),
65-
Country.class, NaturalLanguage.class, PkgCategory.class),
68+
runtimeInformationService
69+
),
6670
specification);
6771
}
6872

0 commit comments

Comments
 (0)