test/tools/javac/T6705935.java

Wed, 14 Nov 2018 10:18:25 -0800

author
diazhou
date
Wed, 14 Nov 2018 10:18:25 -0800
changeset 3762
7909abb85562
parent 798
4868a36f6fd8
child 2525
2eb010b6cb22
permissions
-rw-r--r--

Added tag jdk8u201-b04 for changeset a7f48b9dfb82

     1 /*
     2  * Copyright (c) 2008, 2010, 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  */
    24 /*
    25  * @test
    26  * @bug 6705935
    27  * @summary javac reports path name of entry in ZipFileIndex incorectly
    28  */
    30 import java.io.*;
    31 import java.util.*;
    32 import javax.tools.*;
    33 import com.sun.tools.javac.file.*;
    34 import com.sun.tools.javac.file.ZipArchive.ZipFileObject;
    35 import com.sun.tools.javac.file.ZipFileIndexArchive.ZipFileIndexFileObject;
    37 public class T6705935 {
    38     public static void main(String... args) throws Exception {
    39         new T6705935().run();
    40     }
    42     public void run() throws Exception {
    43         File java_home = new File(System.getProperty("java.home"));
    44         if (java_home.getName().equals("jre"))
    45             java_home = java_home.getParentFile();
    47         JavaCompiler c = ToolProvider.getSystemJavaCompiler();
    48         StandardJavaFileManager fm = c.getStandardFileManager(null, null, null);
    49         //System.err.println("platform class path: " + asList(fm.getLocation(StandardLocation.PLATFORM_CLASS_PATH)));
    51         for (JavaFileObject fo: fm.list(StandardLocation.PLATFORM_CLASS_PATH,
    52                                         "java.lang",
    53                                         Collections.singleton(JavaFileObject.Kind.CLASS),
    54                                         false)) {
    55             test++;
    57             if (!(fo instanceof ZipFileObject || fo instanceof ZipFileIndexFileObject)) {
    58                 System.out.println("Skip " + fo.getClass().getSimpleName() + " " + fo.getName());
    59                 skip++;
    60                 continue;
    61             }
    63             //System.err.println(fo.getName());
    64             String p = fo.getName();
    65             int bra = p.indexOf("(");
    66             int ket = p.indexOf(")");
    67             //System.err.println(bra + "," + ket + "," + p.length());
    68             if (bra == -1 || ket != p.length() -1)
    69                 throw new Exception("unexpected path: " + p + "[" + bra + "," + ket + "," + p.length());
    70             String part1 = p.substring(0, bra);
    71             String part2 = p.substring(bra + 1, ket);
    72             //System.err.println("[" + part1 + "|" + part2 + "]" + " " + java_home);
    73             if (part1.equals(part2) || !part1.startsWith(java_home.getPath()))
    74                 throw new Exception("bad path: " + p);
    76         }
    78         if (test == 0)
    79             throw new Exception("no files found");
    81         if (skip == 0)
    82             System.out.println(test + " files found");
    83         else
    84             System.out.println(test + " files found, " + skip + " files skipped");
    86         if (test == skip)
    87             System.out.println("Warning: all files skipped; no platform classes found in zip files.");
    88     }
    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      }
    97     private int skip;
    98     private int test;
    99 }

mercurial