test/tools/pack200/Utils.java
Print this page
@@ -1,7 +1,7 @@
/*
- * Copyright (c) 2007, 2013, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2007, 2014, 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
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
@@ -52,12 +52,11 @@
*
* @author ksrini
*/
/*
- * This class contains all the commonly used utilities used by various tests
- * in this directory.
+ * This class contains the commonly used utilities.
*/
class Utils {
static final String JavaHome = System.getProperty("test.java",
System.getProperty("java.home"));
static final boolean IsWindows =
@@ -77,16 +76,10 @@
static final File VerifierJar = new File(VERIFIER_DIR_NAME + JAR_FILE_EXT);
static final File XCLASSES = new File("xclasses");
private Utils() {} // all static
- static {
- if (!JavaHome.endsWith("jre")) {
- throw new RuntimeException("Error: requires an SDK to run");
- }
- }
-
private static void init() throws IOException {
if (VerifierJar.exists()) {
return;
}
File srcDir = new File(TEST_SRC_DIR, VERIFIER_DIR_NAME);
@@ -135,12 +128,11 @@
static void doCompareVerify(File reference, File specimen) throws IOException {
init();
List<String> cmds = new ArrayList<String>();
cmds.add(getJavaCmd());
cmds.add("-cp");
- cmds.add(Utils.locateJar("tools.jar") +
- System.getProperty("path.separator") + VerifierJar.getName());
+ cmds.add(VerifierJar.getName());
cmds.add("sun.tools.pack.verify.Main");
cmds.add(reference.getAbsolutePath());
cmds.add(specimen.getAbsolutePath());
cmds.add("-O");
runExec(cmds);
@@ -150,12 +142,11 @@
throws IOException {
init();
List<String> cmds = new ArrayList<String>();
cmds.add(getJavaCmd());
cmds.add("-cp");
- cmds.add(Utils.locateJar("tools.jar")
- + System.getProperty("path.separator") + VerifierJar.getName());
+ cmds.add(VerifierJar.getName());
cmds.add("sun.tools.pack.verify.Main");
cmds.add(reference.getName());
cmds.add(specimen.getName());
cmds.add("-O");
cmds.add("-b");
@@ -341,21 +332,25 @@
} catch (IOException ignore) {
}
}
static void compiler(String... javacCmds) {
- if (com.sun.tools.javac.Main.compile(javacCmds) != 0) {
- throw new RuntimeException("compilation failed");
+ List<String> cmdList = new ArrayList<>();
+ cmdList.add(getJavacCmd());
+ for (String x : javacCmds) {
+ cmdList.add(x);
}
+ runExec(cmdList);
}
static void jar(String... jargs) {
- sun.tools.jar.Main jarTool =
- new sun.tools.jar.Main(System.out, System.err, "jartool");
- if (!jarTool.run(jargs)) {
- throw new RuntimeException("jar command failed");
+ List<String> cmdList = new ArrayList<>();
+ cmdList.add(getJarCmd());
+ for (String x : jargs) {
+ cmdList.add(x);
}
+ runExec(cmdList);
}
static void testWithRepack(File inFile, String... repackOpts) throws IOException {
File cwd = new File(".");
// pack using --repack in native mode
@@ -526,10 +521,22 @@
static String getJavaCmd() {
return getAjavaCmd("java");
}
+ static String getJavacCmd() {
+ return getAjavaCmd("javac");
+ }
+
+ static String getJarCmd() {
+ return getAjavaCmd("jar");
+ }
+
+ static String getJimageCmd() {
+ return getAjavaCmd("jimage");
+ }
+
static String getAjavaCmd(String cmdStr) {
File binDir = new File(JavaHome, "bin");
File unpack200File = IsWindows
? new File(binDir, cmdStr + ".exe")
: new File(binDir, cmdStr);
@@ -540,10 +547,35 @@
cmd + " exists and is executable");
}
return cmd;
}
+ static File createRtJar() throws IOException {
+ File LibDir = new File(JavaHome, "lib");
+ File ModuleDir = new File(LibDir, "modules");
+ File BootModules = new File(ModuleDir, "bootmodules.jimage");
+ List<String> cmdList = new ArrayList<>();
+ cmdList.add(getJimageCmd());
+ cmdList.add("extract");
+ cmdList.add(BootModules.getAbsolutePath());
+ cmdList.add("--dir");
+ cmdList.add("out");
+ runExec(cmdList);
+
+ File rtJar = new File("rt.jar");
+ cmdList.clear();
+ cmdList.add(getJarCmd());
+ cmdList.add("cvf");
+ cmdList.add(rtJar.getName());
+ cmdList.add("-C");
+ cmdList.add("out");
+ cmdList.add(".");
+ runExec(cmdList);
+
+ recursiveDelete(new File("out"));
+ return rtJar;
+ }
private static List<File> locaterCache = null;
// search the source dir and jdk dir for requested file and returns
// the first location it finds.
static File locateJar(String name) {
try {