Path: blob/master/test/langtools/tools/javap/T6474890.java
41144 views
/*1* Copyright (c) 2008, 2016, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation.7*8* This code is distributed in the hope that it will be useful, but WITHOUT9* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or10* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License11* version 2 for more details (a copy is included in the LICENSE file that12* accompanied this code).13*14* You should have received a copy of the GNU General Public License version15* 2 along with this work; if not, write to the Free Software Foundation,16* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.17*18* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA19* or visit www.oracle.com if you need additional information or have any20* questions.21*/2223/*24* @test25* @bug 647489026* @summary javap does not open .zip files in -classpath27* @modules jdk.jdeps/com.sun.tools.javap28*/2930import java.io.*;31import java.util.zip.*;3233public class T6474890 {34public static void main(String[] args) throws Exception {35new T6474890().run();36}3738public void run() throws IOException {39File classDir = new File("classes");40classDir.mkdir();4142String className = "Test";43File javaFile = writeTestFile(className);44compileTestFile(classDir, javaFile);4546File zipFile = zip(classDir, new File(classDir + ".zip"));47javap("-classpath", zipFile.getPath(), className);4849File jarFile = zip(classDir, new File(classDir + ".jar"));50javap("-classpath", zipFile.getPath(), className);51}5253File writeTestFile(String name) throws IOException {54File f = new File(name + ".java");55PrintWriter out = new PrintWriter(new BufferedWriter(new FileWriter(f)));56out.println("class " + name + " { }");57out.close();58return f;59}6061void compileTestFile(File classDir, File file) {62int rc = com.sun.tools.javac.Main.compile(63new String[] { "-d", classDir.getPath(), file.getPath() });64if (rc != 0)65throw new Error("compilation failed. rc=" + rc);66}6768File zip(File dir, File zipFile) throws IOException {69ZipOutputStream zipOut = new ZipOutputStream(new FileOutputStream(zipFile));70for (File file: dir.listFiles()) {71if (file.isFile()) {72byte[] data = new byte[(int) file.length()];73DataInputStream in = new DataInputStream(new FileInputStream(file));74in.readFully(data);75in.close();76zipOut.putNextEntry(new ZipEntry(file.getName()));77zipOut.write(data, 0, data.length);78zipOut.closeEntry();79}80}81zipOut.close();82return zipFile;83}8485String javap(String... args) {86StringWriter sw = new StringWriter();87PrintWriter out = new PrintWriter(sw);88//sun.tools.javap.Main.entry(args);89int rc = com.sun.tools.javap.Main.run(args, out);90if (rc != 0)91throw new Error("javap failed. rc=" + rc);92out.close();93return sw.toString();94}95}969798