Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix tests for multi-release JARs on JDK 17 #27229

Closed
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2012-2020 the original author or authors.
* Copyright 2012-2021 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.
Expand Down Expand Up @@ -34,6 +34,22 @@
*/
public abstract class TestJarCreator {

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 createTestJar(File file) throws Exception {
createTestJar(file, false);
}
Expand Down Expand Up @@ -90,15 +106,9 @@ private static byte[] getNestedJarData(boolean multiRelease) throws Exception {
jarOutputStream.setComment("nested");
writeManifest(jarOutputStream, "j2", multiRelease);
if (multiRelease) {
writeEntry(jarOutputStream, "multi-release.dat", 8);
writeEntry(jarOutputStream, "META-INF/versions/9/multi-release.dat", 9);
writeEntry(jarOutputStream, "META-INF/versions/10/multi-release.dat", 10);
writeEntry(jarOutputStream, "META-INF/versions/11/multi-release.dat", 11);
writeEntry(jarOutputStream, "META-INF/versions/12/multi-release.dat", 12);
writeEntry(jarOutputStream, "META-INF/versions/13/multi-release.dat", 13);
writeEntry(jarOutputStream, "META-INF/versions/14/multi-release.dat", 14);
writeEntry(jarOutputStream, "META-INF/versions/15/multi-release.dat", 15);
writeEntry(jarOutputStream, "META-INF/versions/16/multi-release.dat", 16);
writeEntry(jarOutputStream, "multi-release.dat", BASE_VERSION);
writeEntry(jarOutputStream, String.format("META-INF/versions/%d/multi-release.dat", RUNTIME_VERSION),
RUNTIME_VERSION);
}
else {
writeEntry(jarOutputStream, "3.dat", 3);
Expand Down