--- old/test/ProblemList.txt Tue Apr 5 20:40:41 2016 +++ new/test/ProblemList.txt Tue Apr 5 20:40:41 2016 @@ -315,8 +315,6 @@ tools/pack200/Pack200Test.java 8059906,8151901 generic-all -tools/pack200/Pack200Props.java 8152622 macosx-all - tools/launcher/FXLauncherTest.java 8068049 linux-all,macosx-all ############################################################################ --- old/test/tools/pack200/ModuleAttributes.java Tue Apr 5 20:40:42 2016 +++ new/test/tools/pack200/ModuleAttributes.java Tue Apr 5 20:40:42 2016 @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014, 2015, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2014, 2016, 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 @@ -39,38 +39,10 @@ } public void run() throws Exception { - File file = createModuleJar(); + File file = Utils.createRtJar(".*module-info\\.class"); Utils.testWithRepack(file, "--effort=1", "--unknown-attribute=error"); + Utils.cleanup(); } - - File createModuleJar() throws IOException { - File libDir = new File(Utils.JavaHome, "lib"); - File modules = new File(libDir, "modules"); - File outDir = new File("out"); - - List cmdList = new ArrayList<>(); - cmdList.add(Utils.getJimageCmd()); - cmdList.add("extract"); - cmdList.add(modules.getAbsolutePath()); - cmdList.add("--dir"); - cmdList.add(outDir.getName()); - Utils.runExec(cmdList); - - FileFilter filter = (File file) -> file.getName().equals("module-info.class"); - List mfiles = Utils.findFiles(outDir, filter); - - List contents = new ArrayList<>(mfiles.size()); - mfiles.stream().forEach((f) -> { - contents.add(f.getAbsolutePath()); - }); - - File listFile = new File("mfiles.list"); - Utils.createFile(listFile, contents); - File testFile = new File("test.jar"); - Utils.jar("cvf", testFile.getName(), "@" + listFile.getName()); - Utils.recursiveDelete(outDir); - return testFile; - } } --- old/test/tools/pack200/Pack200Props.java Tue Apr 5 20:40:44 2016 +++ new/test/tools/pack200/Pack200Props.java Tue Apr 5 20:40:44 2016 @@ -1,5 +1,5 @@ /* - * Copyright (c) 2010, 2015, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2010, 2016, 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 @@ -31,7 +31,6 @@ */ import java.io.File; -import java.io.IOException; import java.util.ArrayList; import java.util.HashMap; import java.util.List; @@ -38,6 +37,7 @@ import java.util.Map; import java.util.jar.Pack200; import java.util.jar.Pack200.Packer; +import java.util.logging.Logger; /* * Run this against a large jar file, by default the packer should generate only @@ -46,20 +46,22 @@ public class Pack200Props { - public static void main(String... args) throws IOException { + final static Logger log = Logger.getLogger("Pack200Props"); + + public static void main(String... args) throws Exception { verifyDefaults(); File out = new File("test" + Utils.PACK_FILE_EXT); out.delete(); verifySegmentLimit(out); + log.info("cleanup"); Utils.cleanup(); } - static void verifySegmentLimit(File outFile) throws IOException { - File sdkHome = Utils.JavaSDK; + static void verifySegmentLimit(File outFile) throws Exception { + log.info("creating jar"); File testJar = Utils.createRtJar(); - System.out.println("using pack200: " + Utils.getPack200Cmd()); - + log.info("using pack200: " + Utils.getPack200Cmd()); List cmdsList = new ArrayList<>(); cmdsList.add(Utils.getPack200Cmd()); cmdsList.add("-J-Xshare:off"); @@ -71,6 +73,7 @@ cmdsList.add(testJar.getAbsolutePath()); List outList = Utils.runExec(cmdsList); + log.info("verifying"); int count = 0; for (String line : outList) { System.out.println(line); @@ -78,6 +81,7 @@ count++; } } + log.info("fini"); if (count == 0) { throw new RuntimeException("no segments or no output ????"); } else if (count > 1) { @@ -86,6 +90,7 @@ } private static void verifyDefaults() { + log.info("start"); Map expectedDefaults = new HashMap<>(); Packer p = Pack200.newPacker(); expectedDefaults.put("com.sun.java.util.jar.pack.disable.native", @@ -121,6 +126,7 @@ } } } + log.info("fini"); if (errors > 0) { throw new RuntimeException(errors + " error(s) encountered in default properties verification"); --- old/test/tools/pack200/Utils.java Tue Apr 5 20:40:45 2016 +++ new/test/tools/pack200/Utils.java Tue Apr 5 20:40:45 2016 @@ -32,7 +32,14 @@ import java.io.InputStream; import java.io.InputStreamReader; import java.io.PrintStream; +import java.net.URI; +import java.net.URL; import java.nio.charset.Charset; +import java.nio.file.attribute.BasicFileAttributes; +import java.nio.file.FileSystem; +import java.nio.file.FileSystems; +import java.nio.file.FileVisitResult; +import java.nio.file.FileVisitor; import java.nio.file.Files; import java.util.ArrayList; import java.util.Arrays; @@ -39,9 +46,12 @@ import java.util.Collections; import java.util.List; import java.util.Map; +import java.util.HashMap; import java.util.jar.JarFile; import java.util.jar.JarOutputStream; import java.util.jar.Pack200; +import java.util.regex.Matcher; +import java.util.regex.Pattern; import java.util.zip.ZipEntry; import java.util.zip.ZipFile; @@ -48,6 +58,7 @@ import static java.nio.file.StandardCopyOption.*; import static java.nio.file.StandardOpenOption.*; + /** * * @author ksrini @@ -544,10 +555,6 @@ return getAjavaCmd("jar"); } - static String getJimageCmd() { - return getAjavaCmd("jimage"); - } - static String getAjavaCmd(String cmdStr) { File binDir = new File(JavaHome, "bin"); File unpack200File = IsWindows @@ -562,29 +569,84 @@ return cmd; } - static File createRtJar() throws IOException { - File libDir = new File(JavaHome, "lib"); - File modules = new File(libDir, "modules"); - List cmdList = new ArrayList<>(); - cmdList.add(getJimageCmd()); - cmdList.add("extract"); - cmdList.add(modules.getAbsolutePath()); - cmdList.add("--dir"); - cmdList.add("out"); - runExec(cmdList); - + // used to get all classes + static File createRtJar() throws Exception { File rtJar = new File("rt.jar"); - cmdList.clear(); - cmdList.add(getJarCmd()); - // cmdList.add("cvf"); too noisy - cmdList.add("cf"); - cmdList.add(rtJar.getName()); - cmdList.add("-C"); - cmdList.add("out"); - cmdList.add("."); - runExec(cmdList); + new JrtToZip(".*\\.class", rtJar).run(); + return rtJar; + } - recursiveDelete(new File("out")); + // used to select the contents + static File createRtJar(String pattern) throws Exception { + File rtJar = new File("rt.jar"); + new JrtToZip(pattern, rtJar).run(); return rtJar; } + + /* + * A helper class to create a pseudo rt.jar. + */ + static class JrtToZip { + + final File outFile; + final Pattern pattern; + + public static void main(String[] args) throws Exception { + new JrtToZip(args[0], new File(args[1])).run(); + } + + JrtToZip(String pattern, File outFile) throws Exception { + this.pattern = Pattern.compile(pattern); + this.outFile = outFile; + } + + void run() throws Exception { + URI uri = URI.create("jar:file:///" + outFile.getAbsolutePath().replace("\\", "/")); + Map env = new HashMap<>(); + env.put("create", "true"); + try (FileSystem zipfs = FileSystems.newFileSystem(uri, env)) { + toZipfs(zipfs); + } + } + + void toZipfs(FileSystem zipfs) throws Exception { + FileSystem jrtfs = FileSystems.getFileSystem(new URL("jrt:/").toURI()); + for (Path p : jrtfs.getRootDirectories()) { + Files.walkFileTree(p, new FileVisitor() { + @Override + public FileVisitResult preVisitDirectory(Path dir, BasicFileAttributes attrs) throws IOException { + // ignore unneeded directory + if (dir.startsWith("/packages")) + return FileVisitResult.SKIP_SUBTREE; + + // pre-create required directories + Path zpath = zipfs.getPath(dir.toString()); + Files.createDirectories(zpath); + return FileVisitResult.CONTINUE; + } + + @Override + public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException { + Matcher matcher = pattern.matcher(file.toString()); + if (matcher.matches()) { + // System.out.println("x: " + file); + Path zpath = zipfs.getPath(file.toString()); + Files.copy(file, zpath, REPLACE_EXISTING); + } + return FileVisitResult.CONTINUE; + } + + @Override + public FileVisitResult visitFileFailed(Path file, IOException exc) throws IOException { + return FileVisitResult.CONTINUE; + } + + @Override + public FileVisitResult postVisitDirectory(Path dir, IOException exc) throws IOException { + return FileVisitResult.CONTINUE; + } + }); + } + } + } }