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