|
17 | 17 | package org.springframework.boot.maven;
|
18 | 18 |
|
19 | 19 | import java.io.File;
|
20 |
| -import java.io.IOException; |
21 |
| -import java.util.List; |
22 |
| -import java.util.concurrent.atomic.AtomicReference; |
23 |
| -import java.util.jar.JarFile; |
24 |
| -import java.util.stream.Collectors; |
| 20 | +import java.io.FileReader; |
25 | 21 |
|
26 | 22 | import org.junit.jupiter.api.TestTemplate;
|
27 | 23 | import org.junit.jupiter.api.extension.ExtendWith;
|
28 | 24 |
|
29 |
| -import org.springframework.boot.loader.tools.FileUtils; |
30 |
| -import org.springframework.util.FileSystemUtils; |
| 25 | +import org.springframework.util.FileCopyUtils; |
31 | 26 |
|
32 | 27 | import static org.assertj.core.api.Assertions.assertThat;
|
33 | 28 |
|
@@ -72,34 +67,17 @@ void whenRequiresUnpackConfigurationIsProvidedItIsReflectedInTheRepackagedWar(Ma
|
72 | 67 | }
|
73 | 68 |
|
74 | 69 | @TestTemplate
|
75 |
| - void whenWarIsRepackagedWithOutputTimestampConfiguredThenWarIsReproducible(MavenBuild mavenBuild) |
| 70 | + void whenWarIsRepackagedWithOutputTimestampTheBuildFailsAsItIsNotSupported(MavenBuild mavenBuild) |
76 | 71 | throws InterruptedException {
|
77 |
| - String firstHash = buildWarWithOutputTimestamp(mavenBuild); |
78 |
| - Thread.sleep(1500); |
79 |
| - String secondHash = buildWarWithOutputTimestamp(mavenBuild); |
80 |
| - assertThat(firstHash).isEqualTo(secondHash); |
81 |
| - } |
82 |
| - |
83 |
| - private String buildWarWithOutputTimestamp(MavenBuild mavenBuild) { |
84 |
| - AtomicReference<String> warHash = new AtomicReference<>(); |
85 |
| - mavenBuild.project("war-output-timestamp").execute((project) -> { |
86 |
| - File repackaged = new File(project, "target/war-output-timestamp-0.0.1.BUILD-SNAPSHOT.war"); |
87 |
| - assertThat(repackaged).isFile(); |
88 |
| - assertThat(repackaged.lastModified()).isEqualTo(1584352800000L); |
89 |
| - try (JarFile jar = new JarFile(repackaged)) { |
90 |
| - List<String> unreproducibleEntries = jar.stream() |
91 |
| - .filter((entry) -> entry.getLastModifiedTime().toMillis() != 1584352800000L) |
92 |
| - .map((entry) -> entry.getName() + ": " + entry.getLastModifiedTime()) |
93 |
| - .collect(Collectors.toList()); |
94 |
| - assertThat(unreproducibleEntries).isEmpty(); |
95 |
| - warHash.set(FileUtils.sha1Hash(repackaged)); |
96 |
| - FileSystemUtils.deleteRecursively(project); |
| 72 | + mavenBuild.project("war-output-timestamp").executeAndFail((project) -> { |
| 73 | + try { |
| 74 | + String log = FileCopyUtils.copyToString(new FileReader(new File(project, "target/build.log"))); |
| 75 | + assertThat(log).contains("Reproducible repackaging is not supported with war packaging"); |
97 | 76 | }
|
98 |
| - catch (IOException ex) { |
| 77 | + catch (Exception ex) { |
99 | 78 | throw new RuntimeException(ex);
|
100 | 79 | }
|
101 | 80 | });
|
102 |
| - return warHash.get(); |
103 | 81 | }
|
104 | 82 |
|
105 | 83 | }
|
0 commit comments