langtools/test/tools/javac/T6705935.java
author chegar
Wed, 03 Dec 2014 14:25:46 +0000
changeset 27579 d1a63c99cdd5
parent 27319 030080f03e4f
child 30730 d3ce7619db2c
permissions -rw-r--r--
8049367: Modular Run-Time Images Reviewed-by: jlahoda, ksrini Contributed-by: alan.bateman@oracle.com, alex.buckley@oracle.com, bradford.wetmore@oracle.com, chris.hegarty@oracle.com, erik.joelsson@oracle.com, james.laskey@oracle.com, jonathan.gibbons@oracle.com, karen.kinnear@oracle.com, magnus.ihse.bursie@oracle.com, mandy.chung@oracle.com, mark.reinhold@oracle.com, paul.sandoz@oracle.com, sundararajan.athijegannathan@oracle.com
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
/*
27319
030080f03e4f 8062348: langtools tests should close file manager (group 1)
jjg
parents: 7681
diff changeset
     2
 * Copyright (c) 2008, 2014, 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
99cc2b9325f2 6705935: javac reports path name of entry in ZipFileIndex incorectly
jjg
parents:
diff changeset
    45
        JavaCompiler c = ToolProvider.getSystemJavaCompiler();
27319
030080f03e4f 8062348: langtools tests should close file manager (group 1)
jjg
parents: 7681
diff changeset
    46
        try (StandardJavaFileManager fm = c.getStandardFileManager(null, null, null)) {
030080f03e4f 8062348: langtools tests should close file manager (group 1)
jjg
parents: 7681
diff changeset
    47
            //System.err.println("platform class path: " + asList(fm.getLocation(StandardLocation.PLATFORM_CLASS_PATH)));
030080f03e4f 8062348: langtools tests should close file manager (group 1)
jjg
parents: 7681
diff changeset
    48
030080f03e4f 8062348: langtools tests should close file manager (group 1)
jjg
parents: 7681
diff changeset
    49
            for (JavaFileObject fo: fm.list(StandardLocation.PLATFORM_CLASS_PATH,
030080f03e4f 8062348: langtools tests should close file manager (group 1)
jjg
parents: 7681
diff changeset
    50
                                            "java.lang",
030080f03e4f 8062348: langtools tests should close file manager (group 1)
jjg
parents: 7681
diff changeset
    51
                                            Collections.singleton(JavaFileObject.Kind.CLASS),
030080f03e4f 8062348: langtools tests should close file manager (group 1)
jjg
parents: 7681
diff changeset
    52
                                            false)) {
030080f03e4f 8062348: langtools tests should close file manager (group 1)
jjg
parents: 7681
diff changeset
    53
                test++;
6932
ded41b98a923 6908476: test/tools/javac/T6705935.java fails if non-zip files found on platform class path
jjg
parents: 5520
diff changeset
    54
27319
030080f03e4f 8062348: langtools tests should close file manager (group 1)
jjg
parents: 7681
diff changeset
    55
                if (!(fo instanceof ZipFileObject || fo instanceof ZipFileIndexFileObject)) {
030080f03e4f 8062348: langtools tests should close file manager (group 1)
jjg
parents: 7681
diff changeset
    56
                    System.out.println("Skip " + fo.getClass().getSimpleName() + " " + fo.getName());
030080f03e4f 8062348: langtools tests should close file manager (group 1)
jjg
parents: 7681
diff changeset
    57
                    skip++;
030080f03e4f 8062348: langtools tests should close file manager (group 1)
jjg
parents: 7681
diff changeset
    58
                    continue;
030080f03e4f 8062348: langtools tests should close file manager (group 1)
jjg
parents: 7681
diff changeset
    59
                }
6932
ded41b98a923 6908476: test/tools/javac/T6705935.java fails if non-zip files found on platform class path
jjg
parents: 5520
diff changeset
    60
27319
030080f03e4f 8062348: langtools tests should close file manager (group 1)
jjg
parents: 7681
diff changeset
    61
                //System.err.println(fo.getName());
030080f03e4f 8062348: langtools tests should close file manager (group 1)
jjg
parents: 7681
diff changeset
    62
                String p = fo.getName();
030080f03e4f 8062348: langtools tests should close file manager (group 1)
jjg
parents: 7681
diff changeset
    63
                int bra = p.indexOf("(");
030080f03e4f 8062348: langtools tests should close file manager (group 1)
jjg
parents: 7681
diff changeset
    64
                int ket = p.indexOf(")");
030080f03e4f 8062348: langtools tests should close file manager (group 1)
jjg
parents: 7681
diff changeset
    65
                //System.err.println(bra + "," + ket + "," + p.length());
030080f03e4f 8062348: langtools tests should close file manager (group 1)
jjg
parents: 7681
diff changeset
    66
                if (bra == -1 || ket != p.length() -1)
030080f03e4f 8062348: langtools tests should close file manager (group 1)
jjg
parents: 7681
diff changeset
    67
                    throw new Exception("unexpected path: " + p + "[" + bra + "," + ket + "," + p.length());
030080f03e4f 8062348: langtools tests should close file manager (group 1)
jjg
parents: 7681
diff changeset
    68
                String part1 = p.substring(0, bra);
030080f03e4f 8062348: langtools tests should close file manager (group 1)
jjg
parents: 7681
diff changeset
    69
                String part2 = p.substring(bra + 1, ket);
030080f03e4f 8062348: langtools tests should close file manager (group 1)
jjg
parents: 7681
diff changeset
    70
                //System.err.println("[" + part1 + "|" + part2 + "]" + " " + java_home);
030080f03e4f 8062348: langtools tests should close file manager (group 1)
jjg
parents: 7681
diff changeset
    71
                if (part1.equals(part2) || !part1.startsWith(java_home.getPath()))
030080f03e4f 8062348: langtools tests should close file manager (group 1)
jjg
parents: 7681
diff changeset
    72
                    throw new Exception("bad path: " + p);
030080f03e4f 8062348: langtools tests should close file manager (group 1)
jjg
parents: 7681
diff changeset
    73
6932
ded41b98a923 6908476: test/tools/javac/T6705935.java fails if non-zip files found on platform class path
jjg
parents: 5520
diff changeset
    74
            }
ded41b98a923 6908476: test/tools/javac/T6705935.java fails if non-zip files found on platform class path
jjg
parents: 5520
diff changeset
    75
27319
030080f03e4f 8062348: langtools tests should close file manager (group 1)
jjg
parents: 7681
diff changeset
    76
            if (test == 0)
030080f03e4f 8062348: langtools tests should close file manager (group 1)
jjg
parents: 7681
diff changeset
    77
                throw new Exception("no files found");
657
99cc2b9325f2 6705935: javac reports path name of entry in ZipFileIndex incorectly
jjg
parents:
diff changeset
    78
27319
030080f03e4f 8062348: langtools tests should close file manager (group 1)
jjg
parents: 7681
diff changeset
    79
            if (skip == 0)
030080f03e4f 8062348: langtools tests should close file manager (group 1)
jjg
parents: 7681
diff changeset
    80
                System.out.println(test + " files found");
030080f03e4f 8062348: langtools tests should close file manager (group 1)
jjg
parents: 7681
diff changeset
    81
            else
030080f03e4f 8062348: langtools tests should close file manager (group 1)
jjg
parents: 7681
diff changeset
    82
                System.out.println(test + " files found, " + skip + " files skipped");
6932
ded41b98a923 6908476: test/tools/javac/T6705935.java fails if non-zip files found on platform class path
jjg
parents: 5520
diff changeset
    83
27319
030080f03e4f 8062348: langtools tests should close file manager (group 1)
jjg
parents: 7681
diff changeset
    84
            if (test == skip)
030080f03e4f 8062348: langtools tests should close file manager (group 1)
jjg
parents: 7681
diff changeset
    85
                System.out.println("Warning: all files skipped; no platform classes found in zip files.");
030080f03e4f 8062348: langtools tests should close file manager (group 1)
jjg
parents: 7681
diff changeset
    86
        }
657
99cc2b9325f2 6705935: javac reports path name of entry in ZipFileIndex incorectly
jjg
parents:
diff changeset
    87
    }
6932
ded41b98a923 6908476: test/tools/javac/T6705935.java fails if non-zip files found on platform class path
jjg
parents: 5520
diff changeset
    88
ded41b98a923 6908476: test/tools/javac/T6705935.java fails if non-zip files found on platform class path
jjg
parents: 5520
diff changeset
    89
    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
    90
        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
    91
        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
    92
            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
    93
        return list;
ded41b98a923 6908476: test/tools/javac/T6705935.java fails if non-zip files found on platform class path
jjg
parents: 5520
diff changeset
    94
     }
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
    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
    97
    private int test;
657
99cc2b9325f2 6705935: javac reports path name of entry in ZipFileIndex incorectly
jjg
parents:
diff changeset
    98
}