langtools/test/tools/javac/T6705935.java
author akulyakh
Thu, 21 May 2015 11:41:04 -0700
changeset 30730 d3ce7619db2c
parent 27579 d1a63c99cdd5
permissions -rw-r--r--
8076543: Add @modules as needed to the langtools tests Reviewed-by: jjg, shurailine
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
/*
30730
d3ce7619db2c 8076543: Add @modules as needed to the langtools tests
akulyakh
parents: 27579
diff changeset
     2
 * Copyright (c) 2008, 2015, 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
30730
d3ce7619db2c 8076543: Add @modules as needed to the langtools tests
akulyakh
parents: 27579
diff changeset
    28
 * @modules jdk.compiler/com.sun.tools.javac.file
657
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
99cc2b9325f2 6705935: javac reports path name of entry in ZipFileIndex incorectly
jjg
parents:
diff changeset
    31
import java.io.*;
99cc2b9325f2 6705935: javac reports path name of entry in ZipFileIndex incorectly
jjg
parents:
diff changeset
    32
import java.util.*;
99cc2b9325f2 6705935: javac reports path name of entry in ZipFileIndex incorectly
jjg
parents:
diff changeset
    33
import javax.tools.*;
731
1dd22bdb9ca5 6714364: refactor javac File handling code into new javac.file package
jjg
parents: 657
diff changeset
    34
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
    35
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
    36
import com.sun.tools.javac.file.ZipFileIndexArchive.ZipFileIndexFileObject;
657
99cc2b9325f2 6705935: javac reports path name of entry in ZipFileIndex incorectly
jjg
parents:
diff changeset
    37
99cc2b9325f2 6705935: javac reports path name of entry in ZipFileIndex incorectly
jjg
parents:
diff changeset
    38
public class T6705935 {
99cc2b9325f2 6705935: javac reports path name of entry in ZipFileIndex incorectly
jjg
parents:
diff changeset
    39
    public static void main(String... args) throws Exception {
99cc2b9325f2 6705935: javac reports path name of entry in ZipFileIndex incorectly
jjg
parents:
diff changeset
    40
        new T6705935().run();
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
99cc2b9325f2 6705935: javac reports path name of entry in ZipFileIndex incorectly
jjg
parents:
diff changeset
    43
    public void run() throws Exception {
99cc2b9325f2 6705935: javac reports path name of entry in ZipFileIndex incorectly
jjg
parents:
diff changeset
    44
        File java_home = new File(System.getProperty("java.home"));
99cc2b9325f2 6705935: javac reports path name of entry in ZipFileIndex incorectly
jjg
parents:
diff changeset
    45
99cc2b9325f2 6705935: javac reports path name of entry in ZipFileIndex incorectly
jjg
parents:
diff changeset
    46
        JavaCompiler c = ToolProvider.getSystemJavaCompiler();
27319
030080f03e4f 8062348: langtools tests should close file manager (group 1)
jjg
parents: 7681
diff changeset
    47
        try (StandardJavaFileManager fm = c.getStandardFileManager(null, null, null)) {
030080f03e4f 8062348: langtools tests should close file manager (group 1)
jjg
parents: 7681
diff changeset
    48
            //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
    49
030080f03e4f 8062348: langtools tests should close file manager (group 1)
jjg
parents: 7681
diff changeset
    50
            for (JavaFileObject fo: fm.list(StandardLocation.PLATFORM_CLASS_PATH,
030080f03e4f 8062348: langtools tests should close file manager (group 1)
jjg
parents: 7681
diff changeset
    51
                                            "java.lang",
030080f03e4f 8062348: langtools tests should close file manager (group 1)
jjg
parents: 7681
diff changeset
    52
                                            Collections.singleton(JavaFileObject.Kind.CLASS),
030080f03e4f 8062348: langtools tests should close file manager (group 1)
jjg
parents: 7681
diff changeset
    53
                                            false)) {
030080f03e4f 8062348: langtools tests should close file manager (group 1)
jjg
parents: 7681
diff changeset
    54
                test++;
6932
ded41b98a923 6908476: test/tools/javac/T6705935.java fails if non-zip files found on platform class path
jjg
parents: 5520
diff changeset
    55
27319
030080f03e4f 8062348: langtools tests should close file manager (group 1)
jjg
parents: 7681
diff changeset
    56
                if (!(fo instanceof ZipFileObject || fo instanceof ZipFileIndexFileObject)) {
030080f03e4f 8062348: langtools tests should close file manager (group 1)
jjg
parents: 7681
diff changeset
    57
                    System.out.println("Skip " + fo.getClass().getSimpleName() + " " + fo.getName());
030080f03e4f 8062348: langtools tests should close file manager (group 1)
jjg
parents: 7681
diff changeset
    58
                    skip++;
030080f03e4f 8062348: langtools tests should close file manager (group 1)
jjg
parents: 7681
diff changeset
    59
                    continue;
030080f03e4f 8062348: langtools tests should close file manager (group 1)
jjg
parents: 7681
diff changeset
    60
                }
6932
ded41b98a923 6908476: test/tools/javac/T6705935.java fails if non-zip files found on platform class path
jjg
parents: 5520
diff changeset
    61
27319
030080f03e4f 8062348: langtools tests should close file manager (group 1)
jjg
parents: 7681
diff changeset
    62
                //System.err.println(fo.getName());
030080f03e4f 8062348: langtools tests should close file manager (group 1)
jjg
parents: 7681
diff changeset
    63
                String p = fo.getName();
030080f03e4f 8062348: langtools tests should close file manager (group 1)
jjg
parents: 7681
diff changeset
    64
                int bra = p.indexOf("(");
030080f03e4f 8062348: langtools tests should close file manager (group 1)
jjg
parents: 7681
diff changeset
    65
                int ket = p.indexOf(")");
030080f03e4f 8062348: langtools tests should close file manager (group 1)
jjg
parents: 7681
diff changeset
    66
                //System.err.println(bra + "," + ket + "," + p.length());
030080f03e4f 8062348: langtools tests should close file manager (group 1)
jjg
parents: 7681
diff changeset
    67
                if (bra == -1 || ket != p.length() -1)
030080f03e4f 8062348: langtools tests should close file manager (group 1)
jjg
parents: 7681
diff changeset
    68
                    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
    69
                String part1 = p.substring(0, bra);
030080f03e4f 8062348: langtools tests should close file manager (group 1)
jjg
parents: 7681
diff changeset
    70
                String part2 = p.substring(bra + 1, ket);
030080f03e4f 8062348: langtools tests should close file manager (group 1)
jjg
parents: 7681
diff changeset
    71
                //System.err.println("[" + part1 + "|" + part2 + "]" + " " + java_home);
030080f03e4f 8062348: langtools tests should close file manager (group 1)
jjg
parents: 7681
diff changeset
    72
                if (part1.equals(part2) || !part1.startsWith(java_home.getPath()))
030080f03e4f 8062348: langtools tests should close file manager (group 1)
jjg
parents: 7681
diff changeset
    73
                    throw new Exception("bad path: " + p);
030080f03e4f 8062348: langtools tests should close file manager (group 1)
jjg
parents: 7681
diff changeset
    74
6932
ded41b98a923 6908476: test/tools/javac/T6705935.java fails if non-zip files found on platform class path
jjg
parents: 5520
diff changeset
    75
            }
ded41b98a923 6908476: test/tools/javac/T6705935.java fails if non-zip files found on platform class path
jjg
parents: 5520
diff changeset
    76
27319
030080f03e4f 8062348: langtools tests should close file manager (group 1)
jjg
parents: 7681
diff changeset
    77
            if (test == 0)
030080f03e4f 8062348: langtools tests should close file manager (group 1)
jjg
parents: 7681
diff changeset
    78
                throw new Exception("no files found");
657
99cc2b9325f2 6705935: javac reports path name of entry in ZipFileIndex incorectly
jjg
parents:
diff changeset
    79
27319
030080f03e4f 8062348: langtools tests should close file manager (group 1)
jjg
parents: 7681
diff changeset
    80
            if (skip == 0)
030080f03e4f 8062348: langtools tests should close file manager (group 1)
jjg
parents: 7681
diff changeset
    81
                System.out.println(test + " files found");
030080f03e4f 8062348: langtools tests should close file manager (group 1)
jjg
parents: 7681
diff changeset
    82
            else
030080f03e4f 8062348: langtools tests should close file manager (group 1)
jjg
parents: 7681
diff changeset
    83
                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
    84
27319
030080f03e4f 8062348: langtools tests should close file manager (group 1)
jjg
parents: 7681
diff changeset
    85
            if (test == skip)
030080f03e4f 8062348: langtools tests should close file manager (group 1)
jjg
parents: 7681
diff changeset
    86
                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
    87
        }
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
}