langtools/test/tools/javac/T6705935.java
author jeff
Wed, 22 Jun 2011 10:10:54 -0700
changeset 9916 c35ecac744a5
parent 7681 1f0819a3341f
child 27319 030080f03e4f
permissions -rw-r--r--
7057046: Add embedded license to THIRD PARTY README Reviewed-by: lana
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
657
99cc2b9325f2 6705935: javac reports path name of entry in ZipFileIndex incorectly
jjg
parents:
diff changeset
     1
/*
7681
1f0819a3341f 6962318: Update copyright year
ohair
parents: 6932
diff changeset
     2
 * Copyright (c) 2008, 2010, Oracle and/or its affiliates. All rights reserved.
657
99cc2b9325f2 6705935: javac reports path name of entry in ZipFileIndex incorectly
jjg
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
99cc2b9325f2 6705935: javac reports path name of entry in ZipFileIndex incorectly
jjg
parents:
diff changeset
     4
 *
99cc2b9325f2 6705935: javac reports path name of entry in ZipFileIndex incorectly
jjg
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
99cc2b9325f2 6705935: javac reports path name of entry in ZipFileIndex incorectly
jjg
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
99cc2b9325f2 6705935: javac reports path name of entry in ZipFileIndex incorectly
jjg
parents:
diff changeset
     7
 * published by the Free Software Foundation.
99cc2b9325f2 6705935: javac reports path name of entry in ZipFileIndex incorectly
jjg
parents:
diff changeset
     8
 *
99cc2b9325f2 6705935: javac reports path name of entry in ZipFileIndex incorectly
jjg
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
99cc2b9325f2 6705935: javac reports path name of entry in ZipFileIndex incorectly
jjg
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
99cc2b9325f2 6705935: javac reports path name of entry in ZipFileIndex incorectly
jjg
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
99cc2b9325f2 6705935: javac reports path name of entry in ZipFileIndex incorectly
jjg
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
99cc2b9325f2 6705935: javac reports path name of entry in ZipFileIndex incorectly
jjg
parents:
diff changeset
    13
 * accompanied this code).
99cc2b9325f2 6705935: javac reports path name of entry in ZipFileIndex incorectly
jjg
parents:
diff changeset
    14
 *
99cc2b9325f2 6705935: javac reports path name of entry in ZipFileIndex incorectly
jjg
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
99cc2b9325f2 6705935: javac reports path name of entry in ZipFileIndex incorectly
jjg
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
99cc2b9325f2 6705935: javac reports path name of entry in ZipFileIndex incorectly
jjg
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
99cc2b9325f2 6705935: javac reports path name of entry in ZipFileIndex incorectly
jjg
parents:
diff changeset
    18
 *
5520
86e4b9a9da40 6943119: Rebrand source copyright notices
ohair
parents: 3995
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
86e4b9a9da40 6943119: Rebrand source copyright notices
ohair
parents: 3995
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
86e4b9a9da40 6943119: Rebrand source copyright notices
ohair
parents: 3995
diff changeset
    21
 * questions.
657
99cc2b9325f2 6705935: javac reports path name of entry in ZipFileIndex incorectly
jjg
parents:
diff changeset
    22
 */
99cc2b9325f2 6705935: javac reports path name of entry in ZipFileIndex incorectly
jjg
parents:
diff changeset
    23
99cc2b9325f2 6705935: javac reports path name of entry in ZipFileIndex incorectly
jjg
parents:
diff changeset
    24
/*
99cc2b9325f2 6705935: javac reports path name of entry in ZipFileIndex incorectly
jjg
parents:
diff changeset
    25
 * @test
99cc2b9325f2 6705935: javac reports path name of entry in ZipFileIndex incorectly
jjg
parents:
diff changeset
    26
 * @bug 6705935
99cc2b9325f2 6705935: javac reports path name of entry in ZipFileIndex incorectly
jjg
parents:
diff changeset
    27
 * @summary javac reports path name of entry in ZipFileIndex incorectly
99cc2b9325f2 6705935: javac reports path name of entry in ZipFileIndex incorectly
jjg
parents:
diff changeset
    28
 */
99cc2b9325f2 6705935: javac reports path name of entry in ZipFileIndex incorectly
jjg
parents:
diff changeset
    29
99cc2b9325f2 6705935: javac reports path name of entry in ZipFileIndex incorectly
jjg
parents:
diff changeset
    30
import java.io.*;
99cc2b9325f2 6705935: javac reports path name of entry in ZipFileIndex incorectly
jjg
parents:
diff changeset
    31
import java.util.*;
99cc2b9325f2 6705935: javac reports path name of entry in ZipFileIndex incorectly
jjg
parents:
diff changeset
    32
import javax.tools.*;
731
1dd22bdb9ca5 6714364: refactor javac File handling code into new javac.file package
jjg
parents: 657
diff changeset
    33
import com.sun.tools.javac.file.*;
6932
ded41b98a923 6908476: test/tools/javac/T6705935.java fails if non-zip files found on platform class path
jjg
parents: 5520
diff changeset
    34
import com.sun.tools.javac.file.ZipArchive.ZipFileObject;
ded41b98a923 6908476: test/tools/javac/T6705935.java fails if non-zip files found on platform class path
jjg
parents: 5520
diff changeset
    35
import com.sun.tools.javac.file.ZipFileIndexArchive.ZipFileIndexFileObject;
657
99cc2b9325f2 6705935: javac reports path name of entry in ZipFileIndex incorectly
jjg
parents:
diff changeset
    36
99cc2b9325f2 6705935: javac reports path name of entry in ZipFileIndex incorectly
jjg
parents:
diff changeset
    37
public class T6705935 {
99cc2b9325f2 6705935: javac reports path name of entry in ZipFileIndex incorectly
jjg
parents:
diff changeset
    38
    public static void main(String... args) throws Exception {
99cc2b9325f2 6705935: javac reports path name of entry in ZipFileIndex incorectly
jjg
parents:
diff changeset
    39
        new T6705935().run();
99cc2b9325f2 6705935: javac reports path name of entry in ZipFileIndex incorectly
jjg
parents:
diff changeset
    40
    }
99cc2b9325f2 6705935: javac reports path name of entry in ZipFileIndex incorectly
jjg
parents:
diff changeset
    41
99cc2b9325f2 6705935: javac reports path name of entry in ZipFileIndex incorectly
jjg
parents:
diff changeset
    42
    public void run() throws Exception {
99cc2b9325f2 6705935: javac reports path name of entry in ZipFileIndex incorectly
jjg
parents:
diff changeset
    43
        File java_home = new File(System.getProperty("java.home"));
99cc2b9325f2 6705935: javac reports path name of entry in ZipFileIndex incorectly
jjg
parents:
diff changeset
    44
        if (java_home.getName().equals("jre"))
99cc2b9325f2 6705935: javac reports path name of entry in ZipFileIndex incorectly
jjg
parents:
diff changeset
    45
            java_home = java_home.getParentFile();
99cc2b9325f2 6705935: javac reports path name of entry in ZipFileIndex incorectly
jjg
parents:
diff changeset
    46
99cc2b9325f2 6705935: javac reports path name of entry in ZipFileIndex incorectly
jjg
parents:
diff changeset
    47
        JavaCompiler c = ToolProvider.getSystemJavaCompiler();
6932
ded41b98a923 6908476: test/tools/javac/T6705935.java fails if non-zip files found on platform class path
jjg
parents: 5520
diff changeset
    48
        StandardJavaFileManager fm = c.getStandardFileManager(null, null, null);
ded41b98a923 6908476: test/tools/javac/T6705935.java fails if non-zip files found on platform class path
jjg
parents: 5520
diff changeset
    49
        //System.err.println("platform class path: " + asList(fm.getLocation(StandardLocation.PLATFORM_CLASS_PATH)));
ded41b98a923 6908476: test/tools/javac/T6705935.java fails if non-zip files found on platform class path
jjg
parents: 5520
diff changeset
    50
657
99cc2b9325f2 6705935: javac reports path name of entry in ZipFileIndex incorectly
jjg
parents:
diff changeset
    51
        for (JavaFileObject fo: fm.list(StandardLocation.PLATFORM_CLASS_PATH,
99cc2b9325f2 6705935: javac reports path name of entry in ZipFileIndex incorectly
jjg
parents:
diff changeset
    52
                                        "java.lang",
99cc2b9325f2 6705935: javac reports path name of entry in ZipFileIndex incorectly
jjg
parents:
diff changeset
    53
                                        Collections.singleton(JavaFileObject.Kind.CLASS),
99cc2b9325f2 6705935: javac reports path name of entry in ZipFileIndex incorectly
jjg
parents:
diff changeset
    54
                                        false)) {
6932
ded41b98a923 6908476: test/tools/javac/T6705935.java fails if non-zip files found on platform class path
jjg
parents: 5520
diff changeset
    55
            test++;
ded41b98a923 6908476: test/tools/javac/T6705935.java fails if non-zip files found on platform class path
jjg
parents: 5520
diff changeset
    56
ded41b98a923 6908476: test/tools/javac/T6705935.java fails if non-zip files found on platform class path
jjg
parents: 5520
diff changeset
    57
            if (!(fo instanceof ZipFileObject || fo instanceof ZipFileIndexFileObject)) {
ded41b98a923 6908476: test/tools/javac/T6705935.java fails if non-zip files found on platform class path
jjg
parents: 5520
diff changeset
    58
                System.out.println("Skip " + fo.getClass().getSimpleName() + " " + fo.getName());
ded41b98a923 6908476: test/tools/javac/T6705935.java fails if non-zip files found on platform class path
jjg
parents: 5520
diff changeset
    59
                skip++;
ded41b98a923 6908476: test/tools/javac/T6705935.java fails if non-zip files found on platform class path
jjg
parents: 5520
diff changeset
    60
                continue;
ded41b98a923 6908476: test/tools/javac/T6705935.java fails if non-zip files found on platform class path
jjg
parents: 5520
diff changeset
    61
            }
ded41b98a923 6908476: test/tools/javac/T6705935.java fails if non-zip files found on platform class path
jjg
parents: 5520
diff changeset
    62
ded41b98a923 6908476: test/tools/javac/T6705935.java fails if non-zip files found on platform class path
jjg
parents: 5520
diff changeset
    63
            //System.err.println(fo.getName());
3995
73af8b6fb8bc 6410637: Make decision on deprecated methods in DefaultFileManager and BaseFileObject.
jjg
parents: 731
diff changeset
    64
            String p = fo.getName();
657
99cc2b9325f2 6705935: javac reports path name of entry in ZipFileIndex incorectly
jjg
parents:
diff changeset
    65
            int bra = p.indexOf("(");
99cc2b9325f2 6705935: javac reports path name of entry in ZipFileIndex incorectly
jjg
parents:
diff changeset
    66
            int ket = p.indexOf(")");
99cc2b9325f2 6705935: javac reports path name of entry in ZipFileIndex incorectly
jjg
parents:
diff changeset
    67
            //System.err.println(bra + "," + ket + "," + p.length());
99cc2b9325f2 6705935: javac reports path name of entry in ZipFileIndex incorectly
jjg
parents:
diff changeset
    68
            if (bra == -1 || ket != p.length() -1)
99cc2b9325f2 6705935: javac reports path name of entry in ZipFileIndex incorectly
jjg
parents:
diff changeset
    69
                throw new Exception("unexpected path: " + p + "[" + bra + "," + ket + "," + p.length());
99cc2b9325f2 6705935: javac reports path name of entry in ZipFileIndex incorectly
jjg
parents:
diff changeset
    70
            String part1 = p.substring(0, bra);
99cc2b9325f2 6705935: javac reports path name of entry in ZipFileIndex incorectly
jjg
parents:
diff changeset
    71
            String part2 = p.substring(bra + 1, ket);
99cc2b9325f2 6705935: javac reports path name of entry in ZipFileIndex incorectly
jjg
parents:
diff changeset
    72
            //System.err.println("[" + part1 + "|" + part2 + "]" + " " + java_home);
99cc2b9325f2 6705935: javac reports path name of entry in ZipFileIndex incorectly
jjg
parents:
diff changeset
    73
            if (part1.equals(part2) || !part1.startsWith(java_home.getPath()))
99cc2b9325f2 6705935: javac reports path name of entry in ZipFileIndex incorectly
jjg
parents:
diff changeset
    74
                throw new Exception("bad path: " + p);
99cc2b9325f2 6705935: javac reports path name of entry in ZipFileIndex incorectly
jjg
parents:
diff changeset
    75
99cc2b9325f2 6705935: javac reports path name of entry in ZipFileIndex incorectly
jjg
parents:
diff changeset
    76
        }
6932
ded41b98a923 6908476: test/tools/javac/T6705935.java fails if non-zip files found on platform class path
jjg
parents: 5520
diff changeset
    77
ded41b98a923 6908476: test/tools/javac/T6705935.java fails if non-zip files found on platform class path
jjg
parents: 5520
diff changeset
    78
        if (test == 0)
ded41b98a923 6908476: test/tools/javac/T6705935.java fails if non-zip files found on platform class path
jjg
parents: 5520
diff changeset
    79
            throw new Exception("no files found");
ded41b98a923 6908476: test/tools/javac/T6705935.java fails if non-zip files found on platform class path
jjg
parents: 5520
diff changeset
    80
ded41b98a923 6908476: test/tools/javac/T6705935.java fails if non-zip files found on platform class path
jjg
parents: 5520
diff changeset
    81
        if (skip == 0)
ded41b98a923 6908476: test/tools/javac/T6705935.java fails if non-zip files found on platform class path
jjg
parents: 5520
diff changeset
    82
            System.out.println(test + " files found");
ded41b98a923 6908476: test/tools/javac/T6705935.java fails if non-zip files found on platform class path
jjg
parents: 5520
diff changeset
    83
        else
ded41b98a923 6908476: test/tools/javac/T6705935.java fails if non-zip files found on platform class path
jjg
parents: 5520
diff changeset
    84
            System.out.println(test + " files found, " + skip + " files skipped");
ded41b98a923 6908476: test/tools/javac/T6705935.java fails if non-zip files found on platform class path
jjg
parents: 5520
diff changeset
    85
ded41b98a923 6908476: test/tools/javac/T6705935.java fails if non-zip files found on platform class path
jjg
parents: 5520
diff changeset
    86
        if (test == skip)
ded41b98a923 6908476: test/tools/javac/T6705935.java fails if non-zip files found on platform class path
jjg
parents: 5520
diff changeset
    87
            System.out.println("Warning: all files skipped; no platform classes found in zip files.");
657
99cc2b9325f2 6705935: javac reports path name of entry in ZipFileIndex incorectly
jjg
parents:
diff changeset
    88
    }
6932
ded41b98a923 6908476: test/tools/javac/T6705935.java fails if non-zip files found on platform class path
jjg
parents: 5520
diff changeset
    89
ded41b98a923 6908476: test/tools/javac/T6705935.java fails if non-zip files found on platform class path
jjg
parents: 5520
diff changeset
    90
    private <T> List<T> asList(Iterable<? extends T> items) {
ded41b98a923 6908476: test/tools/javac/T6705935.java fails if non-zip files found on platform class path
jjg
parents: 5520
diff changeset
    91
        List<T> list = new ArrayList<T>();
ded41b98a923 6908476: test/tools/javac/T6705935.java fails if non-zip files found on platform class path
jjg
parents: 5520
diff changeset
    92
        for (T item: items)
ded41b98a923 6908476: test/tools/javac/T6705935.java fails if non-zip files found on platform class path
jjg
parents: 5520
diff changeset
    93
            list.add(item);
ded41b98a923 6908476: test/tools/javac/T6705935.java fails if non-zip files found on platform class path
jjg
parents: 5520
diff changeset
    94
        return list;
ded41b98a923 6908476: test/tools/javac/T6705935.java fails if non-zip files found on platform class path
jjg
parents: 5520
diff changeset
    95
     }
ded41b98a923 6908476: test/tools/javac/T6705935.java fails if non-zip files found on platform class path
jjg
parents: 5520
diff changeset
    96
ded41b98a923 6908476: test/tools/javac/T6705935.java fails if non-zip files found on platform class path
jjg
parents: 5520
diff changeset
    97
    private int skip;
ded41b98a923 6908476: test/tools/javac/T6705935.java fails if non-zip files found on platform class path
jjg
parents: 5520
diff changeset
    98
    private int test;
657
99cc2b9325f2 6705935: javac reports path name of entry in ZipFileIndex incorectly
jjg
parents:
diff changeset
    99
}