45N/A/*
553N/A * Copyright (c) 2008, Oracle and/or its affiliates. All rights reserved.
45N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
45N/A *
45N/A * This code is free software; you can redistribute it and/or modify it
45N/A * under the terms of the GNU General Public License version 2 only, as
45N/A * published by the Free Software Foundation.
45N/A *
45N/A * This code is distributed in the hope that it will be useful, but WITHOUT
45N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
45N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
45N/A * version 2 for more details (a copy is included in the LICENSE file that
45N/A * accompanied this code).
45N/A *
45N/A * You should have received a copy of the GNU General Public License version
45N/A * 2 along with this work; if not, write to the Free Software Foundation,
45N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
45N/A *
553N/A * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
553N/A * or visit www.oracle.com if you need additional information or have any
553N/A * questions.
45N/A */
45N/A
45N/A/*
45N/A * @test
45N/A * @bug 6474890
45N/A * @summary javap does not open .zip files in -classpath
45N/A */
45N/A
45N/Aimport java.io.*;
45N/Aimport java.util.zip.*;
45N/A
45N/Apublic class T6474890 {
45N/A public static void main(String[] args) throws Exception {
45N/A new T6474890().run();
45N/A }
45N/A
45N/A public void run() throws IOException {
45N/A File classDir = new File("classes");
45N/A classDir.mkdir();
45N/A
45N/A String className = "Test";
45N/A File javaFile = writeTestFile(className);
45N/A compileTestFile(classDir, javaFile);
45N/A
45N/A File zipFile = zip(classDir, new File(classDir + ".zip"));
45N/A javap("-classpath", zipFile.getPath(), className);
45N/A
45N/A File jarFile = zip(classDir, new File(classDir + ".jar"));
45N/A javap("-classpath", zipFile.getPath(), className);
45N/A }
45N/A
45N/A File writeTestFile(String name) throws IOException {
45N/A File f = new File(name + ".java");
45N/A PrintWriter out = new PrintWriter(new BufferedWriter(new FileWriter(f)));
45N/A out.println("class " + name + " { }");
45N/A out.close();
45N/A return f;
45N/A }
45N/A
45N/A void compileTestFile(File classDir, File file) {
45N/A int rc = com.sun.tools.javac.Main.compile(
45N/A new String[] { "-d", classDir.getPath(), file.getPath() });
45N/A if (rc != 0)
45N/A throw new Error("compilation failed. rc=" + rc);
45N/A }
45N/A
45N/A File zip(File dir, File zipFile) throws IOException {
45N/A ZipOutputStream zipOut = new ZipOutputStream(new FileOutputStream(zipFile));
45N/A for (File file: dir.listFiles()) {
45N/A if (file.isFile()) {
45N/A byte[] data = new byte[(int) file.length()];
45N/A DataInputStream in = new DataInputStream(new FileInputStream(file));
45N/A in.readFully(data);
45N/A in.close();
45N/A zipOut.putNextEntry(new ZipEntry(file.getName()));
45N/A zipOut.write(data, 0, data.length);
45N/A zipOut.closeEntry();
45N/A }
45N/A }
45N/A zipOut.close();
45N/A return zipFile;
45N/A }
45N/A
45N/A String javap(String... args) {
45N/A StringWriter sw = new StringWriter();
45N/A PrintWriter out = new PrintWriter(sw);
45N/A //sun.tools.javap.Main.entry(args);
45N/A int rc = com.sun.tools.javap.Main.run(args, out);
45N/A if (rc != 0)
45N/A throw new Error("javap failed. rc=" + rc);
45N/A out.close();
45N/A return sw.toString();
45N/A }
45N/A}