Attempt to fix CI failures

Attempt to fix CI failures caused by timezone differences and different
JDK versions.

See gh-37668
pull/37640/head
Phillip Webb 1 year ago
parent 560527945b
commit 42f50fa292

@ -352,7 +352,8 @@ class NestedJarFileTests {
assertThat(jar.stream().map((entry) -> entry.getName() + ":" + entry.getRealName())).containsExactly( assertThat(jar.stream().map((entry) -> entry.getName() + ":" + entry.getRealName())).containsExactly(
"META-INF/:META-INF/", "META-INF/MANIFEST.MF:META-INF/MANIFEST.MF", "META-INF/:META-INF/", "META-INF/MANIFEST.MF:META-INF/MANIFEST.MF",
"multi-release.dat:multi-release.dat", "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())) { try (NestedJarFile jar = new NestedJarFile(this.file, "multi-release.jar", Runtime.version())) {
assertThat(jar.versionedStream().map((entry) -> entry.getName() + ":" + entry.getRealName())) assertThat(jar.versionedStream().map((entry) -> entry.getName() + ":" + entry.getRealName()))
.containsExactly("META-INF/:META-INF/", "META-INF/MANIFEST.MF:META-INF/MANIFEST.MF", .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));
} }
} }

@ -85,7 +85,7 @@ class ExplodedArchiveTests {
} }
@Test @Test
void getClassPathUrlsWhenNoPredicartesReturnsUrls() throws Exception { void getClassPathUrlsWhenNoPredicatesReturnsUrls() throws Exception {
Set<URL> urls = this.archive.getClassPathUrls(Archive.ALL_ENTRIES); Set<URL> urls = this.archive.getClassPathUrls(Archive.ALL_ENTRIES);
URL[] expectedUrls = TestJar.expectedEntries().stream().map(this::toUrl).toArray(URL[]::new); URL[] expectedUrls = TestJar.expectedEntries().stream().map(this::toUrl).toArray(URL[]::new);
assertThat(urls).containsExactlyInAnyOrder(expectedUrls); assertThat(urls).containsExactlyInAnyOrder(expectedUrls);
@ -123,7 +123,7 @@ class ExplodedArchiveTests {
Enumeration<JarEntry> entries = jarFile.entries(); Enumeration<JarEntry> entries = jarFile.entries();
while (entries.hasMoreElements()) { while (entries.hasMoreElements()) {
JarEntry entry = entries.nextElement(); 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(); destination.getParentFile().mkdirs();
if (entry.isDirectory()) { if (entry.isDirectory()) {
destination.mkdir(); destination.mkdir();

@ -35,21 +35,9 @@ import java.util.zip.ZipEntry;
*/ */
public abstract class TestJar { public abstract class TestJar {
private static final int BASE_VERSION = 8; public static final int MULTI_JAR_VERSION = Runtime.version().feature();
private static final int RUNTIME_VERSION;
static { private static final int BASE_VERSION = 8;
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 { public static void create(File file) throws Exception {
create(file, false); create(file, false);
@ -120,8 +108,9 @@ public abstract class TestJar {
writeManifest(jarOutputStream, "j2", multiRelease); writeManifest(jarOutputStream, "j2", multiRelease);
if (multiRelease) { if (multiRelease) {
writeEntry(jarOutputStream, "multi-release.dat", BASE_VERSION); writeEntry(jarOutputStream, "multi-release.dat", BASE_VERSION);
writeEntry(jarOutputStream, String.format("META-INF/versions/%d/multi-release.dat", RUNTIME_VERSION), writeEntry(jarOutputStream,
RUNTIME_VERSION); String.format("META-INF/versions/%d/multi-release.dat", MULTI_JAR_VERSION),
MULTI_JAR_VERSION);
} }
else { else {
writeEntry(jarOutputStream, "3.dat", 3); writeEntry(jarOutputStream, "3.dat", 3);

@ -16,6 +16,8 @@
package org.springframework.boot.loader.zip; package org.springframework.boot.loader.zip;
import java.time.ZoneId;
import java.time.ZonedDateTime;
import java.util.zip.ZipEntry; import java.util.zip.ZipEntry;
import org.junit.jupiter.api.Test; import org.junit.jupiter.api.Test;
@ -129,7 +131,8 @@ class ZipCentralDirectoryFileHeaderRecordTests {
record.copyTo(dataBlock, 0, entry); record.copyTo(dataBlock, 0, entry);
assertThat(entry.getMethod()).isEqualTo(ZipEntry.DEFLATED); assertThat(entry.getMethod()).isEqualTo(ZipEntry.DEFLATED);
assertThat(entry.getTimeLocal()).hasYear(2007); 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.getCrc()).isEqualTo(0xFFFFFFFFL);
assertThat(entry.getCompressedSize()).isEqualTo(1); assertThat(entry.getCompressedSize()).isEqualTo(1);
assertThat(entry.getSize()).isEqualTo(2); assertThat(entry.getSize()).isEqualTo(2);

Loading…
Cancel
Save