jjg@38: /* ohair@798: * Copyright (c) 2008, 2010, Oracle and/or its affiliates. All rights reserved. jjg@38: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. jjg@38: * jjg@38: * This code is free software; you can redistribute it and/or modify it jjg@38: * under the terms of the GNU General Public License version 2 only, as jjg@38: * published by the Free Software Foundation. jjg@38: * jjg@38: * This code is distributed in the hope that it will be useful, but WITHOUT jjg@38: * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or jjg@38: * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License jjg@38: * version 2 for more details (a copy is included in the LICENSE file that jjg@38: * accompanied this code). jjg@38: * jjg@38: * You should have received a copy of the GNU General Public License version jjg@38: * 2 along with this work; if not, write to the Free Software Foundation, jjg@38: * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. jjg@38: * ohair@554: * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA ohair@554: * or visit www.oracle.com if you need additional information or have any ohair@554: * questions. jjg@38: */ jjg@38: jjg@38: /* jjg@38: * @test jjg@38: * @bug 6705935 jjg@38: * @summary javac reports path name of entry in ZipFileIndex incorectly jjg@38: */ jjg@38: jjg@38: import java.io.*; jjg@38: import java.util.*; jjg@38: import javax.tools.*; jjg@50: import com.sun.tools.javac.file.*; jjg@714: import com.sun.tools.javac.file.ZipArchive.ZipFileObject; jjg@714: import com.sun.tools.javac.file.ZipFileIndexArchive.ZipFileIndexFileObject; jjg@38: jjg@38: public class T6705935 { jjg@38: public static void main(String... args) throws Exception { jjg@38: new T6705935().run(); jjg@38: } jjg@38: jjg@38: public void run() throws Exception { jjg@38: File java_home = new File(System.getProperty("java.home")); jjg@38: if (java_home.getName().equals("jre")) jjg@38: java_home = java_home.getParentFile(); jjg@38: jjg@38: JavaCompiler c = ToolProvider.getSystemJavaCompiler(); jjg@714: StandardJavaFileManager fm = c.getStandardFileManager(null, null, null); jjg@714: //System.err.println("platform class path: " + asList(fm.getLocation(StandardLocation.PLATFORM_CLASS_PATH))); jjg@714: jjg@38: for (JavaFileObject fo: fm.list(StandardLocation.PLATFORM_CLASS_PATH, jjg@38: "java.lang", jjg@38: Collections.singleton(JavaFileObject.Kind.CLASS), jjg@38: false)) { jjg@714: test++; jjg@714: jjg@714: if (!(fo instanceof ZipFileObject || fo instanceof ZipFileIndexFileObject)) { jjg@714: System.out.println("Skip " + fo.getClass().getSimpleName() + " " + fo.getName()); jjg@714: skip++; jjg@714: continue; jjg@714: } jjg@714: jjg@714: //System.err.println(fo.getName()); jjg@415: String p = fo.getName(); jjg@38: int bra = p.indexOf("("); jjg@38: int ket = p.indexOf(")"); jjg@38: //System.err.println(bra + "," + ket + "," + p.length()); jjg@38: if (bra == -1 || ket != p.length() -1) jjg@38: throw new Exception("unexpected path: " + p + "[" + bra + "," + ket + "," + p.length()); jjg@38: String part1 = p.substring(0, bra); jjg@38: String part2 = p.substring(bra + 1, ket); jjg@38: //System.err.println("[" + part1 + "|" + part2 + "]" + " " + java_home); jjg@38: if (part1.equals(part2) || !part1.startsWith(java_home.getPath())) jjg@38: throw new Exception("bad path: " + p); jjg@38: jjg@38: } jjg@714: jjg@714: if (test == 0) jjg@714: throw new Exception("no files found"); jjg@714: jjg@714: if (skip == 0) jjg@714: System.out.println(test + " files found"); jjg@714: else jjg@714: System.out.println(test + " files found, " + skip + " files skipped"); jjg@714: jjg@714: if (test == skip) jjg@714: System.out.println("Warning: all files skipped; no platform classes found in zip files."); jjg@38: } jjg@714: jjg@714: private List asList(Iterable items) { jjg@714: List list = new ArrayList(); jjg@714: for (T item: items) jjg@714: list.add(item); jjg@714: return list; jjg@714: } jjg@714: jjg@714: private int skip; jjg@714: private int test; jjg@38: }