1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/test/tools/javac/T6705935.java Wed Apr 27 01:34:52 2016 +0800 1.3 @@ -0,0 +1,99 @@ 1.4 +/* 1.5 + * Copyright (c) 2008, 2010, Oracle and/or its affiliates. All rights reserved. 1.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 1.7 + * 1.8 + * This code is free software; you can redistribute it and/or modify it 1.9 + * under the terms of the GNU General Public License version 2 only, as 1.10 + * published by the Free Software Foundation. 1.11 + * 1.12 + * This code is distributed in the hope that it will be useful, but WITHOUT 1.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 1.14 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 1.15 + * version 2 for more details (a copy is included in the LICENSE file that 1.16 + * accompanied this code). 1.17 + * 1.18 + * You should have received a copy of the GNU General Public License version 1.19 + * 2 along with this work; if not, write to the Free Software Foundation, 1.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 1.21 + * 1.22 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 1.23 + * or visit www.oracle.com if you need additional information or have any 1.24 + * questions. 1.25 + */ 1.26 + 1.27 +/* 1.28 + * @test 1.29 + * @bug 6705935 1.30 + * @summary javac reports path name of entry in ZipFileIndex incorectly 1.31 + */ 1.32 + 1.33 +import java.io.*; 1.34 +import java.util.*; 1.35 +import javax.tools.*; 1.36 +import com.sun.tools.javac.file.*; 1.37 +import com.sun.tools.javac.file.ZipArchive.ZipFileObject; 1.38 +import com.sun.tools.javac.file.ZipFileIndexArchive.ZipFileIndexFileObject; 1.39 + 1.40 +public class T6705935 { 1.41 + public static void main(String... args) throws Exception { 1.42 + new T6705935().run(); 1.43 + } 1.44 + 1.45 + public void run() throws Exception { 1.46 + File java_home = new File(System.getProperty("java.home")); 1.47 + if (java_home.getName().equals("jre")) 1.48 + java_home = java_home.getParentFile(); 1.49 + 1.50 + JavaCompiler c = ToolProvider.getSystemJavaCompiler(); 1.51 + StandardJavaFileManager fm = c.getStandardFileManager(null, null, null); 1.52 + //System.err.println("platform class path: " + asList(fm.getLocation(StandardLocation.PLATFORM_CLASS_PATH))); 1.53 + 1.54 + for (JavaFileObject fo: fm.list(StandardLocation.PLATFORM_CLASS_PATH, 1.55 + "java.lang", 1.56 + Collections.singleton(JavaFileObject.Kind.CLASS), 1.57 + false)) { 1.58 + test++; 1.59 + 1.60 + if (!(fo instanceof ZipFileObject || fo instanceof ZipFileIndexFileObject)) { 1.61 + System.out.println("Skip " + fo.getClass().getSimpleName() + " " + fo.getName()); 1.62 + skip++; 1.63 + continue; 1.64 + } 1.65 + 1.66 + //System.err.println(fo.getName()); 1.67 + String p = fo.getName(); 1.68 + int bra = p.indexOf("("); 1.69 + int ket = p.indexOf(")"); 1.70 + //System.err.println(bra + "," + ket + "," + p.length()); 1.71 + if (bra == -1 || ket != p.length() -1) 1.72 + throw new Exception("unexpected path: " + p + "[" + bra + "," + ket + "," + p.length()); 1.73 + String part1 = p.substring(0, bra); 1.74 + String part2 = p.substring(bra + 1, ket); 1.75 + //System.err.println("[" + part1 + "|" + part2 + "]" + " " + java_home); 1.76 + if (part1.equals(part2) || !part1.startsWith(java_home.getPath())) 1.77 + throw new Exception("bad path: " + p); 1.78 + 1.79 + } 1.80 + 1.81 + if (test == 0) 1.82 + throw new Exception("no files found"); 1.83 + 1.84 + if (skip == 0) 1.85 + System.out.println(test + " files found"); 1.86 + else 1.87 + System.out.println(test + " files found, " + skip + " files skipped"); 1.88 + 1.89 + if (test == skip) 1.90 + System.out.println("Warning: all files skipped; no platform classes found in zip files."); 1.91 + } 1.92 + 1.93 + private <T> List<T> asList(Iterable<? extends T> items) { 1.94 + List<T> list = new ArrayList<T>(); 1.95 + for (T item: items) 1.96 + list.add(item); 1.97 + return list; 1.98 + } 1.99 + 1.100 + private int skip; 1.101 + private int test; 1.102 +}