From 491515e6e34c866b768842a5e798b54f283f9c7c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andreas=20H=C3=B6hmann?= Date: Tue, 29 Oct 2024 10:29:19 +0100 Subject: [PATCH 1/2] Complete support for project.build.outputTimestamp This commit completes the support of project.build.outputTimestamp to also support a value that's expressed as seconds since the epoch. See gh-42922 --- .../boot/maven/BuildInfoIntegrationTests.java | 10 ++++++ .../pom.xml | 32 +++++++++++++++++++ .../main/java/org/test/SampleApplication.java | 24 ++++++++++++++ .../boot/maven/BuildInfoMojo.java | 2 +- 4 files changed, 67 insertions(+), 1 deletion(-) create mode 100644 spring-boot-project/spring-boot-tools/spring-boot-maven-plugin/src/intTest/projects/build-info-reproducible-epochseconds/pom.xml create mode 100644 spring-boot-project/spring-boot-tools/spring-boot-maven-plugin/src/intTest/projects/build-info-reproducible-epochseconds/src/main/java/org/test/SampleApplication.java diff --git a/spring-boot-project/spring-boot-tools/spring-boot-maven-plugin/src/intTest/java/org/springframework/boot/maven/BuildInfoIntegrationTests.java b/spring-boot-project/spring-boot-tools/spring-boot-maven-plugin/src/intTest/java/org/springframework/boot/maven/BuildInfoIntegrationTests.java index 036aa6912d3..9dd8f1b8b65 100644 --- a/spring-boot-project/spring-boot-tools/spring-boot-maven-plugin/src/intTest/java/org/springframework/boot/maven/BuildInfoIntegrationTests.java +++ b/spring-boot-project/spring-boot-tools/spring-boot-maven-plugin/src/intTest/java/org/springframework/boot/maven/BuildInfoIntegrationTests.java @@ -83,6 +83,16 @@ class BuildInfoIntegrationTests { .hasBuildTime("2021-04-21T11:22:33Z"))); } + @TestTemplate + void generatedBuildInfoReproducibleEpochSeconds(MavenBuild mavenBuild) { + mavenBuild.project("build-info-reproducible-epochseconds") + .execute(buildInfo((buildInfo) -> assertThat(buildInfo).hasBuildGroup("org.springframework.boot.maven.it") + .hasBuildArtifact("build-reproducible-epochseconds") + .hasBuildName("Generate build info with build time from project.build.outputTimestamp") + .hasBuildVersion("0.0.1.BUILD-SNAPSHOT") + .hasBuildTime("1976-01-09T12:00:00Z"))); + } + @TestTemplate void buildInfoPropertiesAreGeneratedToCustomOutputLocation(MavenBuild mavenBuild) { mavenBuild.project("build-info-custom-file") diff --git a/spring-boot-project/spring-boot-tools/spring-boot-maven-plugin/src/intTest/projects/build-info-reproducible-epochseconds/pom.xml b/spring-boot-project/spring-boot-tools/spring-boot-maven-plugin/src/intTest/projects/build-info-reproducible-epochseconds/pom.xml new file mode 100644 index 00000000000..5a8aa26d4d2 --- /dev/null +++ b/spring-boot-project/spring-boot-tools/spring-boot-maven-plugin/src/intTest/projects/build-info-reproducible-epochseconds/pom.xml @@ -0,0 +1,32 @@ + + + 4.0.0 + org.springframework.boot.maven.it + build-reproducible-epochseconds + 0.0.1.BUILD-SNAPSHOT + Generate build info with build time from project.build.outputTimestamp + + UTF-8 + @java.version@ + @java.version@ + + 190036800 + + + + + @project.groupId@ + @project.artifactId@ + @project.version@ + + + + build-info + + + + + + + diff --git a/spring-boot-project/spring-boot-tools/spring-boot-maven-plugin/src/intTest/projects/build-info-reproducible-epochseconds/src/main/java/org/test/SampleApplication.java b/spring-boot-project/spring-boot-tools/spring-boot-maven-plugin/src/intTest/projects/build-info-reproducible-epochseconds/src/main/java/org/test/SampleApplication.java new file mode 100644 index 00000000000..1277cdbc5a6 --- /dev/null +++ b/spring-boot-project/spring-boot-tools/spring-boot-maven-plugin/src/intTest/projects/build-info-reproducible-epochseconds/src/main/java/org/test/SampleApplication.java @@ -0,0 +1,24 @@ +/* + * Copyright 2012-2024 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.test; + +public class SampleApplication { + + public static void main(String[] args) { + } + +} diff --git a/spring-boot-project/spring-boot-tools/spring-boot-maven-plugin/src/main/java/org/springframework/boot/maven/BuildInfoMojo.java b/spring-boot-project/spring-boot-tools/spring-boot-maven-plugin/src/main/java/org/springframework/boot/maven/BuildInfoMojo.java index bef8512f282..720f0e4db0c 100644 --- a/spring-boot-project/spring-boot-tools/spring-boot-maven-plugin/src/main/java/org/springframework/boot/maven/BuildInfoMojo.java +++ b/spring-boot-project/spring-boot-tools/spring-boot-maven-plugin/src/main/java/org/springframework/boot/maven/BuildInfoMojo.java @@ -154,7 +154,7 @@ public class BuildInfoMojo extends AbstractMojo { if ("off".equalsIgnoreCase(this.time)) { return null; } - return Instant.parse(this.time); + return new MavenBuildOutputTimestamp(this.time).toInstant(); } } From 1a3f1a41b1979a9912caff118dca1ab534967e0a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?St=C3=A9phane=20Nicoll?= Date: Wed, 30 Oct 2024 11:04:48 +0900 Subject: [PATCH 2/2] Polish "Complete support for project.build.outputTimestamp" See gh-42922 --- .../boot/maven/BuildInfoIntegrationTests.java | 9 +++++---- .../pom.xml | 5 ++--- .../src/main/java/org/test/SampleApplication.java | 0 .../org/springframework/boot/maven/BuildInfoMojo.java | 2 +- 4 files changed, 8 insertions(+), 8 deletions(-) rename spring-boot-project/spring-boot-tools/spring-boot-maven-plugin/src/intTest/projects/{build-info-reproducible-epochseconds => build-info-reproducible-epoch-seconds}/pom.xml (83%) rename spring-boot-project/spring-boot-tools/spring-boot-maven-plugin/src/intTest/projects/{build-info-reproducible-epochseconds => build-info-reproducible-epoch-seconds}/src/main/java/org/test/SampleApplication.java (100%) diff --git a/spring-boot-project/spring-boot-tools/spring-boot-maven-plugin/src/intTest/java/org/springframework/boot/maven/BuildInfoIntegrationTests.java b/spring-boot-project/spring-boot-tools/spring-boot-maven-plugin/src/intTest/java/org/springframework/boot/maven/BuildInfoIntegrationTests.java index 9dd8f1b8b65..f5b144b7066 100644 --- a/spring-boot-project/spring-boot-tools/spring-boot-maven-plugin/src/intTest/java/org/springframework/boot/maven/BuildInfoIntegrationTests.java +++ b/spring-boot-project/spring-boot-tools/spring-boot-maven-plugin/src/intTest/java/org/springframework/boot/maven/BuildInfoIntegrationTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2023 the original author or authors. + * Copyright 2012-2024 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -19,6 +19,7 @@ package org.springframework.boot.maven; import java.io.File; import java.io.FileReader; import java.io.IOException; +import java.time.Instant; import java.util.Properties; import java.util.function.Consumer; @@ -85,12 +86,12 @@ class BuildInfoIntegrationTests { @TestTemplate void generatedBuildInfoReproducibleEpochSeconds(MavenBuild mavenBuild) { - mavenBuild.project("build-info-reproducible-epochseconds") + mavenBuild.project("build-info-reproducible-epoch-seconds") .execute(buildInfo((buildInfo) -> assertThat(buildInfo).hasBuildGroup("org.springframework.boot.maven.it") - .hasBuildArtifact("build-reproducible-epochseconds") + .hasBuildArtifact("build-reproducible-epoch-seconds") .hasBuildName("Generate build info with build time from project.build.outputTimestamp") .hasBuildVersion("0.0.1.BUILD-SNAPSHOT") - .hasBuildTime("1976-01-09T12:00:00Z"))); + .hasBuildTime(Instant.ofEpochSecond(1619004153).toString()))); } @TestTemplate diff --git a/spring-boot-project/spring-boot-tools/spring-boot-maven-plugin/src/intTest/projects/build-info-reproducible-epochseconds/pom.xml b/spring-boot-project/spring-boot-tools/spring-boot-maven-plugin/src/intTest/projects/build-info-reproducible-epoch-seconds/pom.xml similarity index 83% rename from spring-boot-project/spring-boot-tools/spring-boot-maven-plugin/src/intTest/projects/build-info-reproducible-epochseconds/pom.xml rename to spring-boot-project/spring-boot-tools/spring-boot-maven-plugin/src/intTest/projects/build-info-reproducible-epoch-seconds/pom.xml index 5a8aa26d4d2..a63b3dc21b1 100644 --- a/spring-boot-project/spring-boot-tools/spring-boot-maven-plugin/src/intTest/projects/build-info-reproducible-epochseconds/pom.xml +++ b/spring-boot-project/spring-boot-tools/spring-boot-maven-plugin/src/intTest/projects/build-info-reproducible-epoch-seconds/pom.xml @@ -3,15 +3,14 @@ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd"> 4.0.0 org.springframework.boot.maven.it - build-reproducible-epochseconds + build-reproducible-epoch-seconds 0.0.1.BUILD-SNAPSHOT Generate build info with build time from project.build.outputTimestamp UTF-8 @java.version@ @java.version@ - - 190036800 + 1619004153 diff --git a/spring-boot-project/spring-boot-tools/spring-boot-maven-plugin/src/intTest/projects/build-info-reproducible-epochseconds/src/main/java/org/test/SampleApplication.java b/spring-boot-project/spring-boot-tools/spring-boot-maven-plugin/src/intTest/projects/build-info-reproducible-epoch-seconds/src/main/java/org/test/SampleApplication.java similarity index 100% rename from spring-boot-project/spring-boot-tools/spring-boot-maven-plugin/src/intTest/projects/build-info-reproducible-epochseconds/src/main/java/org/test/SampleApplication.java rename to spring-boot-project/spring-boot-tools/spring-boot-maven-plugin/src/intTest/projects/build-info-reproducible-epoch-seconds/src/main/java/org/test/SampleApplication.java diff --git a/spring-boot-project/spring-boot-tools/spring-boot-maven-plugin/src/main/java/org/springframework/boot/maven/BuildInfoMojo.java b/spring-boot-project/spring-boot-tools/spring-boot-maven-plugin/src/main/java/org/springframework/boot/maven/BuildInfoMojo.java index 720f0e4db0c..9d8319a7025 100644 --- a/spring-boot-project/spring-boot-tools/spring-boot-maven-plugin/src/main/java/org/springframework/boot/maven/BuildInfoMojo.java +++ b/spring-boot-project/spring-boot-tools/spring-boot-maven-plugin/src/main/java/org/springframework/boot/maven/BuildInfoMojo.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2023 the original author or authors. + * Copyright 2012-2024 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License.