mirror of
https://github.com/openjdk/jdk.git
synced 2025-08-27 14:54:52 +02:00
8199290: [TESTBUG] sun.hotspot.WhiteBox$WhiteBoxPermission is not copied
Reviewed-by: iignatyev, dholmes
This commit is contained in:
parent
83163dbfe6
commit
8b2453f93b
2 changed files with 73 additions and 9 deletions
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright (c) 2016, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 2016, 2019, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
|
@ -32,6 +32,7 @@ import java.nio.file.Files;
|
|||
import java.nio.file.Path;
|
||||
import java.nio.file.Paths;
|
||||
import java.nio.file.StandardCopyOption;
|
||||
import java.util.ArrayList;
|
||||
import java.util.zip.ZipEntry;
|
||||
import java.util.zip.ZipOutputStream;
|
||||
|
||||
|
@ -84,17 +85,47 @@ public class ClassFileInstaller {
|
|||
"where possible options include:\n" +
|
||||
" -jar <path> Write to the JAR file <path>");
|
||||
}
|
||||
writeJar(args[1], null, args, 2, args.length);
|
||||
String jarFile = args[1];
|
||||
String[] classes = addInnerClasses(args, 2);
|
||||
writeJar_impl(jarFile, null, classes);
|
||||
} else {
|
||||
if (DEBUG) {
|
||||
System.out.println("ClassFileInstaller: Writing to " + System.getProperty("user.dir"));
|
||||
}
|
||||
for (String arg : args) {
|
||||
writeClassToDisk(arg);
|
||||
String[] classes = addInnerClasses(args, 0);
|
||||
for (String cls : classes) {
|
||||
writeClassToDisk(cls);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Add commonly used inner classes that are often omitted by mistake. Currently
|
||||
// we support only sun.hotspot.WhiteBox$WhiteBoxPermission. See JDK-8199290
|
||||
private static String[] addInnerClasses(String[] classes, int startIdx) {
|
||||
boolean seenWB = false;
|
||||
boolean seenWBInner = false;
|
||||
final String wb = "sun.hotspot.WhiteBox";
|
||||
final String wbInner = "sun.hotspot.WhiteBox$WhiteBoxPermission";
|
||||
|
||||
ArrayList<String> list = new ArrayList<>();
|
||||
|
||||
for (int i = startIdx; i < classes.length; i++) {
|
||||
String cls = classes[i];
|
||||
list.add(cls);
|
||||
switch (cls) {
|
||||
case wb: seenWB = true; break;
|
||||
case wbInner: seenWBInner = true; break;
|
||||
}
|
||||
}
|
||||
if (seenWB && !seenWBInner) {
|
||||
list.add(wbInner);
|
||||
}
|
||||
|
||||
String[] array = new String[list.size()];
|
||||
list.toArray(array);
|
||||
return array;
|
||||
}
|
||||
|
||||
public static class Manifest {
|
||||
private InputStream in;
|
||||
|
||||
|
@ -122,7 +153,7 @@ public class ClassFileInstaller {
|
|||
}
|
||||
}
|
||||
|
||||
private static void writeJar(String jarFile, Manifest manifest, String classes[], int from, int to) throws Exception {
|
||||
private static void writeJar_impl(String jarFile, Manifest manifest, String classes[]) throws Exception {
|
||||
if (DEBUG) {
|
||||
System.out.println("ClassFileInstaller: Writing to " + getJarPath(jarFile));
|
||||
}
|
||||
|
@ -137,8 +168,8 @@ public class ClassFileInstaller {
|
|||
writeToDisk(zos, "META-INF/MANIFEST.MF", manifest.getInputStream());
|
||||
}
|
||||
|
||||
for (int i=from; i<to; i++) {
|
||||
writeClassToDisk(zos, classes[i]);
|
||||
for (String cls : classes) {
|
||||
writeClassToDisk(zos, cls);
|
||||
}
|
||||
|
||||
zos.close();
|
||||
|
@ -157,12 +188,14 @@ public class ClassFileInstaller {
|
|||
* @build ClassFileInstaller
|
||||
*/
|
||||
public static String writeJar(String jarFile, String... classes) throws Exception {
|
||||
writeJar(jarFile, null, classes, 0, classes.length);
|
||||
classes = addInnerClasses(classes, 0);
|
||||
writeJar_impl(jarFile, null, classes);
|
||||
return getJarPath(jarFile);
|
||||
}
|
||||
|
||||
public static String writeJar(String jarFile, Manifest manifest, String... classes) throws Exception {
|
||||
writeJar(jarFile, manifest, classes, 0, classes.length);
|
||||
classes = addInnerClasses(classes, 0);
|
||||
writeJar_impl(jarFile, manifest, classes);
|
||||
return getJarPath(jarFile);
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue