langtools/test/tools/javac/T6705935.java
changeset 34569 8b372e28f106
parent 34559 9229cc3b3802
parent 34568 afc0330fa0d4
child 34570 8a8f52a733dd
equal deleted inserted replaced
34559:9229cc3b3802 34569:8b372e28f106
     1 /*
       
     2  * Copyright (c) 2008, 2015, Oracle and/or its affiliates. All rights reserved.
       
     3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
       
     4  *
       
     5  * This code is free software; you can redistribute it and/or modify it
       
     6  * under the terms of the GNU General Public License version 2 only, as
       
     7  * published by the Free Software Foundation.
       
     8  *
       
     9  * This code is distributed in the hope that it will be useful, but WITHOUT
       
    10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
       
    11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
       
    12  * version 2 for more details (a copy is included in the LICENSE file that
       
    13  * accompanied this code).
       
    14  *
       
    15  * You should have received a copy of the GNU General Public License version
       
    16  * 2 along with this work; if not, write to the Free Software Foundation,
       
    17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
       
    18  *
       
    19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
       
    20  * or visit www.oracle.com if you need additional information or have any
       
    21  * questions.
       
    22  */
       
    23 
       
    24 /*
       
    25  * @test
       
    26  * @bug 6705935
       
    27  * @summary javac reports path name of entry in ZipFileIndex incorectly
       
    28  * @modules jdk.compiler/com.sun.tools.javac.file
       
    29  */
       
    30 
       
    31 import java.io.*;
       
    32 import java.util.*;
       
    33 import javax.tools.*;
       
    34 import com.sun.tools.javac.file.*;
       
    35 import com.sun.tools.javac.file.ZipArchive.ZipFileObject;
       
    36 import com.sun.tools.javac.file.ZipFileIndexArchive.ZipFileIndexFileObject;
       
    37 
       
    38 public class T6705935 {
       
    39     public static void main(String... args) throws Exception {
       
    40         new T6705935().run();
       
    41     }
       
    42 
       
    43     public void run() throws Exception {
       
    44         File java_home = new File(System.getProperty("java.home"));
       
    45 
       
    46         JavaCompiler c = ToolProvider.getSystemJavaCompiler();
       
    47         try (StandardJavaFileManager fm = c.getStandardFileManager(null, null, null)) {
       
    48             //System.err.println("platform class path: " + asList(fm.getLocation(StandardLocation.PLATFORM_CLASS_PATH)));
       
    49 
       
    50             for (JavaFileObject fo: fm.list(StandardLocation.PLATFORM_CLASS_PATH,
       
    51                                             "java.lang",
       
    52                                             Collections.singleton(JavaFileObject.Kind.CLASS),
       
    53                                             false)) {
       
    54                 test++;
       
    55 
       
    56                 if (!(fo instanceof ZipFileObject || fo instanceof ZipFileIndexFileObject)) {
       
    57                     System.out.println("Skip " + fo.getClass().getSimpleName() + " " + fo.getName());
       
    58                     skip++;
       
    59                     continue;
       
    60                 }
       
    61 
       
    62                 //System.err.println(fo.getName());
       
    63                 String p = fo.getName();
       
    64                 int bra = p.indexOf("(");
       
    65                 int ket = p.indexOf(")");
       
    66                 //System.err.println(bra + "," + ket + "," + p.length());
       
    67                 if (bra == -1 || ket != p.length() -1)
       
    68                     throw new Exception("unexpected path: " + p + "[" + bra + "," + ket + "," + p.length());
       
    69                 String part1 = p.substring(0, bra);
       
    70                 String part2 = p.substring(bra + 1, ket);
       
    71                 //System.err.println("[" + part1 + "|" + part2 + "]" + " " + java_home);
       
    72                 if (part1.equals(part2) || !part1.startsWith(java_home.getPath()))
       
    73                     throw new Exception("bad path: " + p);
       
    74 
       
    75             }
       
    76 
       
    77             if (test == 0)
       
    78                 throw new Exception("no files found");
       
    79 
       
    80             if (skip == 0)
       
    81                 System.out.println(test + " files found");
       
    82             else
       
    83                 System.out.println(test + " files found, " + skip + " files skipped");
       
    84 
       
    85             if (test == skip)
       
    86                 System.out.println("Warning: all files skipped; no platform classes found in zip files.");
       
    87         }
       
    88     }
       
    89 
       
    90     private <T> List<T> asList(Iterable<? extends T> items) {
       
    91         List<T> list = new ArrayList<T>();
       
    92         for (T item: items)
       
    93             list.add(item);
       
    94         return list;
       
    95      }
       
    96 
       
    97     private int skip;
       
    98     private int test;
       
    99 }