From 42f50fa2925ff4809e09d65a88730c7db5508186 Mon Sep 17 00:00:00 2001 From: Phillip Webb Date: Tue, 3 Oct 2023 20:29:33 -0700 Subject: [PATCH] Attempt to fix CI failures Attempt to fix CI failures caused by timezone differences and different JDK versions. See gh-37668 --- .../boot/loader/jar/NestedJarFileTests.java | 6 ++++-- .../loader/launch/ExplodedArchiveTests.java | 4 ++-- .../boot/loader/testsupport/TestJar.java | 21 +++++-------------- ...CentralDirectoryFileHeaderRecordTests.java | 5 ++++- 4 files changed, 15 insertions(+), 21 deletions(-) diff --git a/spring-boot-project/spring-boot-tools/spring-boot-loader/src/test/java/org/springframework/boot/loader/jar/NestedJarFileTests.java b/spring-boot-project/spring-boot-tools/spring-boot-loader/src/test/java/org/springframework/boot/loader/jar/NestedJarFileTests.java index 1944f30b9f4..59b3e7cc8fd 100644 --- a/spring-boot-project/spring-boot-tools/spring-boot-loader/src/test/java/org/springframework/boot/loader/jar/NestedJarFileTests.java +++ b/spring-boot-project/spring-boot-tools/spring-boot-loader/src/test/java/org/springframework/boot/loader/jar/NestedJarFileTests.java @@ -352,7 +352,8 @@ class NestedJarFileTests { assertThat(jar.stream().map((entry) -> entry.getName() + ":" + entry.getRealName())).containsExactly( "META-INF/:META-INF/", "META-INF/MANIFEST.MF:META-INF/MANIFEST.MF", "multi-release.dat:multi-release.dat", - "META-INF/versions/17/multi-release.dat:META-INF/versions/17/multi-release.dat"); + "META-INF/versions/%1$d/multi-release.dat:META-INF/versions/%1$d/multi-release.dat" + .formatted(TestJar.MULTI_JAR_VERSION)); } } @@ -361,7 +362,8 @@ class NestedJarFileTests { try (NestedJarFile jar = new NestedJarFile(this.file, "multi-release.jar", Runtime.version())) { assertThat(jar.versionedStream().map((entry) -> entry.getName() + ":" + entry.getRealName())) .containsExactly("META-INF/:META-INF/", "META-INF/MANIFEST.MF:META-INF/MANIFEST.MF", - "multi-release.dat:META-INF/versions/17/multi-release.dat"); + "multi-release.dat:META-INF/versions/%1$d/multi-release.dat" + .formatted(TestJar.MULTI_JAR_VERSION)); } } diff --git a/spring-boot-project/spring-boot-tools/spring-boot-loader/src/test/java/org/springframework/boot/loader/launch/ExplodedArchiveTests.java b/spring-boot-project/spring-boot-tools/spring-boot-loader/src/test/java/org/springframework/boot/loader/launch/ExplodedArchiveTests.java index 96107512a33..b18164f7513 100755 --- a/spring-boot-project/spring-boot-tools/spring-boot-loader/src/test/java/org/springframework/boot/loader/launch/ExplodedArchiveTests.java +++ b/spring-boot-project/spring-boot-tools/spring-boot-loader/src/test/java/org/springframework/boot/loader/launch/ExplodedArchiveTests.java @@ -85,7 +85,7 @@ class ExplodedArchiveTests { } @Test - void getClassPathUrlsWhenNoPredicartesReturnsUrls() throws Exception { + void getClassPathUrlsWhenNoPredicatesReturnsUrls() throws Exception { Set urls = this.archive.getClassPathUrls(Archive.ALL_ENTRIES); URL[] expectedUrls = TestJar.expectedEntries().stream().map(this::toUrl).toArray(URL[]::new); assertThat(urls).containsExactlyInAnyOrder(expectedUrls); @@ -123,7 +123,7 @@ class ExplodedArchiveTests { Enumeration entries = jarFile.entries(); while (entries.hasMoreElements()) { JarEntry entry = entries.nextElement(); - File destination = new File(this.rootDirectory.getAbsolutePath() + File.separator + entry.getName()); + File destination = new File(this.rootDirectory, entry.getName()); destination.getParentFile().mkdirs(); if (entry.isDirectory()) { destination.mkdir(); diff --git a/spring-boot-project/spring-boot-tools/spring-boot-loader/src/test/java/org/springframework/boot/loader/testsupport/TestJar.java b/spring-boot-project/spring-boot-tools/spring-boot-loader/src/test/java/org/springframework/boot/loader/testsupport/TestJar.java index 292fd44b66e..efa625e59ce 100644 --- a/spring-boot-project/spring-boot-tools/spring-boot-loader/src/test/java/org/springframework/boot/loader/testsupport/TestJar.java +++ b/spring-boot-project/spring-boot-tools/spring-boot-loader/src/test/java/org/springframework/boot/loader/testsupport/TestJar.java @@ -35,22 +35,10 @@ import java.util.zip.ZipEntry; */ public abstract class TestJar { + public static final int MULTI_JAR_VERSION = Runtime.version().feature(); + private static final int BASE_VERSION = 8; - private static final int RUNTIME_VERSION; - - static { - int version; - try { - Object runtimeVersion = Runtime.class.getMethod("version").invoke(null); - version = (int) runtimeVersion.getClass().getMethod("major").invoke(runtimeVersion); - } - catch (Throwable ex) { - version = BASE_VERSION; - } - RUNTIME_VERSION = version; - } - public static void create(File file) throws Exception { create(file, false); } @@ -120,8 +108,9 @@ public abstract class TestJar { writeManifest(jarOutputStream, "j2", multiRelease); if (multiRelease) { writeEntry(jarOutputStream, "multi-release.dat", BASE_VERSION); - writeEntry(jarOutputStream, String.format("META-INF/versions/%d/multi-release.dat", RUNTIME_VERSION), - RUNTIME_VERSION); + writeEntry(jarOutputStream, + String.format("META-INF/versions/%d/multi-release.dat", MULTI_JAR_VERSION), + MULTI_JAR_VERSION); } else { writeEntry(jarOutputStream, "3.dat", 3); diff --git a/spring-boot-project/spring-boot-tools/spring-boot-loader/src/test/java/org/springframework/boot/loader/zip/ZipCentralDirectoryFileHeaderRecordTests.java b/spring-boot-project/spring-boot-tools/spring-boot-loader/src/test/java/org/springframework/boot/loader/zip/ZipCentralDirectoryFileHeaderRecordTests.java index a0a8645e9c1..5fe7e9ee889 100644 --- a/spring-boot-project/spring-boot-tools/spring-boot-loader/src/test/java/org/springframework/boot/loader/zip/ZipCentralDirectoryFileHeaderRecordTests.java +++ b/spring-boot-project/spring-boot-tools/spring-boot-loader/src/test/java/org/springframework/boot/loader/zip/ZipCentralDirectoryFileHeaderRecordTests.java @@ -16,6 +16,8 @@ package org.springframework.boot.loader.zip; +import java.time.ZoneId; +import java.time.ZonedDateTime; import java.util.zip.ZipEntry; import org.junit.jupiter.api.Test; @@ -129,7 +131,8 @@ class ZipCentralDirectoryFileHeaderRecordTests { record.copyTo(dataBlock, 0, entry); assertThat(entry.getMethod()).isEqualTo(ZipEntry.DEFLATED); assertThat(entry.getTimeLocal()).hasYear(2007); - assertThat(entry.getTime()).isEqualTo(1172356386000L); + ZonedDateTime expectedTime = ZonedDateTime.of(2007, 02, 24, 14, 33, 06, 0, ZoneId.systemDefault()); + assertThat(entry.getTime()).isEqualTo(expectedTime.toEpochSecond() * 1000); assertThat(entry.getCrc()).isEqualTo(0xFFFFFFFFL); assertThat(entry.getCompressedSize()).isEqualTo(1); assertThat(entry.getSize()).isEqualTo(2);