Path: blob/aarch64-shenandoah-jdk8u272-b10/langtools/test/tools/javap/T6474890.java
32285 views
/*1* Copyright (c) 2008, 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*/2829import java.io.*;30import java.util.zip.*;3132public class T6474890 {33public static void main(String[] args) throws Exception {34new T6474890().run();35}3637public void run() throws IOException {38File classDir = new File("classes");39classDir.mkdir();4041String className = "Test";42File javaFile = writeTestFile(className);43compileTestFile(classDir, javaFile);4445File zipFile = zip(classDir, new File(classDir + ".zip"));46javap("-classpath", zipFile.getPath(), className);4748File jarFile = zip(classDir, new File(classDir + ".jar"));49javap("-classpath", zipFile.getPath(), className);50}5152File writeTestFile(String name) throws IOException {53File f = new File(name + ".java");54PrintWriter out = new PrintWriter(new BufferedWriter(new FileWriter(f)));55out.println("class " + name + " { }");56out.close();57return f;58}5960void compileTestFile(File classDir, File file) {61int rc = com.sun.tools.javac.Main.compile(62new String[] { "-d", classDir.getPath(), file.getPath() });63if (rc != 0)64throw new Error("compilation failed. rc=" + rc);65}6667File zip(File dir, File zipFile) throws IOException {68ZipOutputStream zipOut = new ZipOutputStream(new FileOutputStream(zipFile));69for (File file: dir.listFiles()) {70if (file.isFile()) {71byte[] data = new byte[(int) file.length()];72DataInputStream in = new DataInputStream(new FileInputStream(file));73in.readFully(data);74in.close();75zipOut.putNextEntry(new ZipEntry(file.getName()));76zipOut.write(data, 0, data.length);77zipOut.closeEntry();78}79}80zipOut.close();81return zipFile;82}8384String javap(String... args) {85StringWriter sw = new StringWriter();86PrintWriter out = new PrintWriter(sw);87//sun.tools.javap.Main.entry(args);88int rc = com.sun.tools.javap.Main.run(args, out);89if (rc != 0)90throw new Error("javap failed. rc=" + rc);91out.close();92return sw.toString();93}94}959697