test/tools/pack200/Utils.java

Print this page




 297         }
 298         try {
 299             c.close();
 300         } catch (IOException ignore) {
 301         }
 302     }
 303 
 304     static void compiler(String... javacCmds) {
 305         if (com.sun.tools.javac.Main.compile(javacCmds) != 0) {
 306             throw new RuntimeException("compilation failed");
 307         }
 308     }
 309 
 310     static void jar(String... jargs) {
 311         sun.tools.jar.Main jarTool =
 312                 new sun.tools.jar.Main(System.out, System.err, "jartool");
 313         if (!jarTool.run(jargs)) {
 314             throw new RuntimeException("jar command failed");
 315         }
 316     }














 317     static List<String> repack(File inFile, File outFile,
 318             boolean disableNative, String... extraOpts) {
 319         List<String> cmdList = new ArrayList<>();
 320         cmdList.clear();
 321         cmdList.add(Utils.getJavaCmd());
 322         cmdList.add("-ea");
 323         cmdList.add("-esa");
 324         if (disableNative) {
 325             cmdList.add("-Dcom.sun.java.util.jar.pack.disable.native=true");
 326         }
 327         cmdList.add("com.sun.java.util.jar.pack.Driver");
 328         cmdList.add("--repack");
 329         if (extraOpts != null) {
 330            for (String opt: extraOpts) {
 331                cmdList.add(opt);
 332            }
 333         }
 334         cmdList.add(outFile.getName());
 335         cmdList.add(inFile.getName());
 336         return Utils.runExec(cmdList);




 297         }
 298         try {
 299             c.close();
 300         } catch (IOException ignore) {
 301         }
 302     }
 303 
 304     static void compiler(String... javacCmds) {
 305         if (com.sun.tools.javac.Main.compile(javacCmds) != 0) {
 306             throw new RuntimeException("compilation failed");
 307         }
 308     }
 309 
 310     static void jar(String... jargs) {
 311         sun.tools.jar.Main jarTool =
 312                 new sun.tools.jar.Main(System.out, System.err, "jartool");
 313         if (!jarTool.run(jargs)) {
 314             throw new RuntimeException("jar command failed");
 315         }
 316     }
 317 
 318     static void testWithRepack(File inFile, String... repackOpts) throws IOException {
 319         File cwd = new File(".");
 320         // pack using --repack in native mode
 321         File nativejarFile = new File(cwd, "out-n" + Utils.JAR_FILE_EXT);
 322         repack(inFile, nativejarFile, false, repackOpts);
 323         doCompareVerify(inFile, nativejarFile);
 324 
 325         // ensure bit compatibility between the unpacker variants
 326         File javajarFile = new File(cwd, "out-j" + Utils.JAR_FILE_EXT);
 327         repack(inFile, javajarFile, true, repackOpts);
 328         doCompareBitWise(javajarFile, nativejarFile);
 329     }
 330 
 331     static List<String> repack(File inFile, File outFile,
 332             boolean disableNative, String... extraOpts) {
 333         List<String> cmdList = new ArrayList<>();
 334         cmdList.clear();
 335         cmdList.add(Utils.getJavaCmd());
 336         cmdList.add("-ea");
 337         cmdList.add("-esa");
 338         if (disableNative) {
 339             cmdList.add("-Dcom.sun.java.util.jar.pack.disable.native=true");
 340         }
 341         cmdList.add("com.sun.java.util.jar.pack.Driver");
 342         cmdList.add("--repack");
 343         if (extraOpts != null) {
 344            for (String opt: extraOpts) {
 345                cmdList.add(opt);
 346            }
 347         }
 348         cmdList.add(outFile.getName());
 349         cmdList.add(inFile.getName());
 350         return Utils.runExec(cmdList);