langtools/test/tools/javac/api/T6838467.java
author jjg
Mon, 07 Dec 2015 14:02:55 -0800
changeset 34560 b6a567b677f7
parent 30730 d3ce7619db2c
permissions -rw-r--r--
8059976: Convert JavacFileManager to use java.nio.file internally Reviewed-by: jlahoda
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
4073
9788f4549740 6838467: JSR199 FileObjects don't obey general contract of equals.
jjg
parents:
diff changeset
     1
/*
30730
d3ce7619db2c 8076543: Add @modules as needed to the langtools tests
akulyakh
parents: 11318
diff changeset
     2
 * Copyright (c) 2009, 2015, Oracle and/or its affiliates. All rights reserved.
4073
9788f4549740 6838467: JSR199 FileObjects don't obey general contract of equals.
jjg
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
9788f4549740 6838467: JSR199 FileObjects don't obey general contract of equals.
jjg
parents:
diff changeset
     4
 *
9788f4549740 6838467: JSR199 FileObjects don't obey general contract of equals.
jjg
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
9788f4549740 6838467: JSR199 FileObjects don't obey general contract of equals.
jjg
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
9788f4549740 6838467: JSR199 FileObjects don't obey general contract of equals.
jjg
parents:
diff changeset
     7
 * published by the Free Software Foundation.
9788f4549740 6838467: JSR199 FileObjects don't obey general contract of equals.
jjg
parents:
diff changeset
     8
 *
9788f4549740 6838467: JSR199 FileObjects don't obey general contract of equals.
jjg
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
9788f4549740 6838467: JSR199 FileObjects don't obey general contract of equals.
jjg
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
9788f4549740 6838467: JSR199 FileObjects don't obey general contract of equals.
jjg
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
9788f4549740 6838467: JSR199 FileObjects don't obey general contract of equals.
jjg
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
9788f4549740 6838467: JSR199 FileObjects don't obey general contract of equals.
jjg
parents:
diff changeset
    13
 * accompanied this code).
9788f4549740 6838467: JSR199 FileObjects don't obey general contract of equals.
jjg
parents:
diff changeset
    14
 *
9788f4549740 6838467: JSR199 FileObjects don't obey general contract of equals.
jjg
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
9788f4549740 6838467: JSR199 FileObjects don't obey general contract of equals.
jjg
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
9788f4549740 6838467: JSR199 FileObjects don't obey general contract of equals.
jjg
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
9788f4549740 6838467: JSR199 FileObjects don't obey general contract of equals.
jjg
parents:
diff changeset
    18
 *
5520
86e4b9a9da40 6943119: Rebrand source copyright notices
ohair
parents: 4073
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
86e4b9a9da40 6943119: Rebrand source copyright notices
ohair
parents: 4073
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
86e4b9a9da40 6943119: Rebrand source copyright notices
ohair
parents: 4073
diff changeset
    21
 * questions.
4073
9788f4549740 6838467: JSR199 FileObjects don't obey general contract of equals.
jjg
parents:
diff changeset
    22
 */
9788f4549740 6838467: JSR199 FileObjects don't obey general contract of equals.
jjg
parents:
diff changeset
    23
9788f4549740 6838467: JSR199 FileObjects don't obey general contract of equals.
jjg
parents:
diff changeset
    24
/*
9788f4549740 6838467: JSR199 FileObjects don't obey general contract of equals.
jjg
parents:
diff changeset
    25
 * @test
9788f4549740 6838467: JSR199 FileObjects don't obey general contract of equals.
jjg
parents:
diff changeset
    26
 * @bug 6838467
9788f4549740 6838467: JSR199 FileObjects don't obey general contract of equals.
jjg
parents:
diff changeset
    27
 * @summary JSR199 FileObjects don't obey general contract of equals.
30730
d3ce7619db2c 8076543: Add @modules as needed to the langtools tests
akulyakh
parents: 11318
diff changeset
    28
 * @modules jdk.compiler/com.sun.tools.javac.file
d3ce7619db2c 8076543: Add @modules as needed to the langtools tests
akulyakh
parents: 11318
diff changeset
    29
 *          jdk.compiler/com.sun.tools.javac.util
4073
9788f4549740 6838467: JSR199 FileObjects don't obey general contract of equals.
jjg
parents:
diff changeset
    30
 */
9788f4549740 6838467: JSR199 FileObjects don't obey general contract of equals.
jjg
parents:
diff changeset
    31
9788f4549740 6838467: JSR199 FileObjects don't obey general contract of equals.
jjg
parents:
diff changeset
    32
import java.io.*;
9788f4549740 6838467: JSR199 FileObjects don't obey general contract of equals.
jjg
parents:
diff changeset
    33
import java.util.*;
9788f4549740 6838467: JSR199 FileObjects don't obey general contract of equals.
jjg
parents:
diff changeset
    34
import java.util.zip.*;
34560
b6a567b677f7 8059976: Convert JavacFileManager to use java.nio.file internally
jjg
parents: 30730
diff changeset
    35
4073
9788f4549740 6838467: JSR199 FileObjects don't obey general contract of equals.
jjg
parents:
diff changeset
    36
import javax.tools.*;
34560
b6a567b677f7 8059976: Convert JavacFileManager to use java.nio.file internally
jjg
parents: 30730
diff changeset
    37
import javax.tools.JavaFileManager.Location;
b6a567b677f7 8059976: Convert JavacFileManager to use java.nio.file internally
jjg
parents: 30730
diff changeset
    38
4073
9788f4549740 6838467: JSR199 FileObjects don't obey general contract of equals.
jjg
parents:
diff changeset
    39
import com.sun.tools.javac.file.JavacFileManager;
9788f4549740 6838467: JSR199 FileObjects don't obey general contract of equals.
jjg
parents:
diff changeset
    40
import com.sun.tools.javac.util.Context;
9788f4549740 6838467: JSR199 FileObjects don't obey general contract of equals.
jjg
parents:
diff changeset
    41
9788f4549740 6838467: JSR199 FileObjects don't obey general contract of equals.
jjg
parents:
diff changeset
    42
public class T6838467 {
9788f4549740 6838467: JSR199 FileObjects don't obey general contract of equals.
jjg
parents:
diff changeset
    43
9788f4549740 6838467: JSR199 FileObjects don't obey general contract of equals.
jjg
parents:
diff changeset
    44
    enum FileKind {
9788f4549740 6838467: JSR199 FileObjects don't obey general contract of equals.
jjg
parents:
diff changeset
    45
        DIR("dir"),
34560
b6a567b677f7 8059976: Convert JavacFileManager to use java.nio.file internally
jjg
parents: 30730
diff changeset
    46
        ZIP("zip");
4073
9788f4549740 6838467: JSR199 FileObjects don't obey general contract of equals.
jjg
parents:
diff changeset
    47
        FileKind(String path) {
9788f4549740 6838467: JSR199 FileObjects don't obey general contract of equals.
jjg
parents:
diff changeset
    48
            file = new File(path);
9788f4549740 6838467: JSR199 FileObjects don't obey general contract of equals.
jjg
parents:
diff changeset
    49
        }
9788f4549740 6838467: JSR199 FileObjects don't obey general contract of equals.
jjg
parents:
diff changeset
    50
        final File file;
9788f4549740 6838467: JSR199 FileObjects don't obey general contract of equals.
jjg
parents:
diff changeset
    51
    };
9788f4549740 6838467: JSR199 FileObjects don't obey general contract of equals.
jjg
parents:
diff changeset
    52
9788f4549740 6838467: JSR199 FileObjects don't obey general contract of equals.
jjg
parents:
diff changeset
    53
    enum CompareKind {
9788f4549740 6838467: JSR199 FileObjects don't obey general contract of equals.
jjg
parents:
diff changeset
    54
        SAME {
34560
b6a567b677f7 8059976: Convert JavacFileManager to use java.nio.file internally
jjg
parents: 30730
diff changeset
    55
            @Override
4073
9788f4549740 6838467: JSR199 FileObjects don't obey general contract of equals.
jjg
parents:
diff changeset
    56
            File other(File f) { return f; }
9788f4549740 6838467: JSR199 FileObjects don't obey general contract of equals.
jjg
parents:
diff changeset
    57
        },
9788f4549740 6838467: JSR199 FileObjects don't obey general contract of equals.
jjg
parents:
diff changeset
    58
        ABSOLUTE {
34560
b6a567b677f7 8059976: Convert JavacFileManager to use java.nio.file internally
jjg
parents: 30730
diff changeset
    59
            @Override
4073
9788f4549740 6838467: JSR199 FileObjects don't obey general contract of equals.
jjg
parents:
diff changeset
    60
            File other(File f) { return f.getAbsoluteFile(); }
9788f4549740 6838467: JSR199 FileObjects don't obey general contract of equals.
jjg
parents:
diff changeset
    61
        },
9788f4549740 6838467: JSR199 FileObjects don't obey general contract of equals.
jjg
parents:
diff changeset
    62
        DIFFERENT {
34560
b6a567b677f7 8059976: Convert JavacFileManager to use java.nio.file internally
jjg
parents: 30730
diff changeset
    63
            @Override
4073
9788f4549740 6838467: JSR199 FileObjects don't obey general contract of equals.
jjg
parents:
diff changeset
    64
            File other(File f) { return new File("not_" + f.getPath()); }
9788f4549740 6838467: JSR199 FileObjects don't obey general contract of equals.
jjg
parents:
diff changeset
    65
        },
9788f4549740 6838467: JSR199 FileObjects don't obey general contract of equals.
jjg
parents:
diff changeset
    66
        CASEEQUIV {
34560
b6a567b677f7 8059976: Convert JavacFileManager to use java.nio.file internally
jjg
parents: 30730
diff changeset
    67
            @Override
4073
9788f4549740 6838467: JSR199 FileObjects don't obey general contract of equals.
jjg
parents:
diff changeset
    68
            File other(File f) { return new File(f.getPath().toUpperCase()); }
9788f4549740 6838467: JSR199 FileObjects don't obey general contract of equals.
jjg
parents:
diff changeset
    69
        };
9788f4549740 6838467: JSR199 FileObjects don't obey general contract of equals.
jjg
parents:
diff changeset
    70
        abstract File other(File f);
9788f4549740 6838467: JSR199 FileObjects don't obey general contract of equals.
jjg
parents:
diff changeset
    71
    };
9788f4549740 6838467: JSR199 FileObjects don't obey general contract of equals.
jjg
parents:
diff changeset
    72
9788f4549740 6838467: JSR199 FileObjects don't obey general contract of equals.
jjg
parents:
diff changeset
    73
    String[] paths = { "p/A.java", "p/B.java", "p/C.java" };
9788f4549740 6838467: JSR199 FileObjects don't obey general contract of equals.
jjg
parents:
diff changeset
    74
9788f4549740 6838467: JSR199 FileObjects don't obey general contract of equals.
jjg
parents:
diff changeset
    75
    public static void main(String... args) throws Exception {
9788f4549740 6838467: JSR199 FileObjects don't obey general contract of equals.
jjg
parents:
diff changeset
    76
        new T6838467().run();
9788f4549740 6838467: JSR199 FileObjects don't obey general contract of equals.
jjg
parents:
diff changeset
    77
    }
9788f4549740 6838467: JSR199 FileObjects don't obey general contract of equals.
jjg
parents:
diff changeset
    78
9788f4549740 6838467: JSR199 FileObjects don't obey general contract of equals.
jjg
parents:
diff changeset
    79
    void run() throws Exception {
34560
b6a567b677f7 8059976: Convert JavacFileManager to use java.nio.file internally
jjg
parents: 30730
diff changeset
    80
        boolean fileNameIsCaseSignificant = isFileNameCaseSignificant();
b6a567b677f7 8059976: Convert JavacFileManager to use java.nio.file internally
jjg
parents: 30730
diff changeset
    81
        boolean fileLookupIsCaseSignificant = isFileLookupCaseSignificant();
b6a567b677f7 8059976: Convert JavacFileManager to use java.nio.file internally
jjg
parents: 30730
diff changeset
    82
b6a567b677f7 8059976: Convert JavacFileManager to use java.nio.file internally
jjg
parents: 30730
diff changeset
    83
        String osName = System.getProperty("os.name");
b6a567b677f7 8059976: Convert JavacFileManager to use java.nio.file internally
jjg
parents: 30730
diff changeset
    84
        System.err.println("OS: " + osName);
b6a567b677f7 8059976: Convert JavacFileManager to use java.nio.file internally
jjg
parents: 30730
diff changeset
    85
        System.err.println("fileNameIsCaseSignificant:" + fileNameIsCaseSignificant);
b6a567b677f7 8059976: Convert JavacFileManager to use java.nio.file internally
jjg
parents: 30730
diff changeset
    86
        System.err.println("fileLookupIsCaseSignificant:" + fileLookupIsCaseSignificant);
b6a567b677f7 8059976: Convert JavacFileManager to use java.nio.file internally
jjg
parents: 30730
diff changeset
    87
4073
9788f4549740 6838467: JSR199 FileObjects don't obey general contract of equals.
jjg
parents:
diff changeset
    88
        // on Windows, verify file system is not case significant
34560
b6a567b677f7 8059976: Convert JavacFileManager to use java.nio.file internally
jjg
parents: 30730
diff changeset
    89
        if ((osName.startsWith("windows")) && fileNameIsCaseSignificant) {
b6a567b677f7 8059976: Convert JavacFileManager to use java.nio.file internally
jjg
parents: 30730
diff changeset
    90
            error("fileNameIsCaseSignificant is set on " + osName + ".");
4073
9788f4549740 6838467: JSR199 FileObjects don't obey general contract of equals.
jjg
parents:
diff changeset
    91
        }
9788f4549740 6838467: JSR199 FileObjects don't obey general contract of equals.
jjg
parents:
diff changeset
    92
9788f4549740 6838467: JSR199 FileObjects don't obey general contract of equals.
jjg
parents:
diff changeset
    93
        // create a set of directories and zip files to compare
9788f4549740 6838467: JSR199 FileObjects don't obey general contract of equals.
jjg
parents:
diff changeset
    94
        createTestDir(new File("dir"), paths);
9788f4549740 6838467: JSR199 FileObjects don't obey general contract of equals.
jjg
parents:
diff changeset
    95
        createTestDir(new File("not_dir"), paths);
9788f4549740 6838467: JSR199 FileObjects don't obey general contract of equals.
jjg
parents:
diff changeset
    96
        createTestZip(new File("zip"), paths);
9788f4549740 6838467: JSR199 FileObjects don't obey general contract of equals.
jjg
parents:
diff changeset
    97
        createTestZip(new File("not_zip"), paths);
34560
b6a567b677f7 8059976: Convert JavacFileManager to use java.nio.file internally
jjg
parents: 30730
diff changeset
    98
        if (fileNameIsCaseSignificant || fileLookupIsCaseSignificant) {
4073
9788f4549740 6838467: JSR199 FileObjects don't obey general contract of equals.
jjg
parents:
diff changeset
    99
            createTestDir(new File("DIR"), paths);
9788f4549740 6838467: JSR199 FileObjects don't obey general contract of equals.
jjg
parents:
diff changeset
   100
            createTestZip(new File("ZIP"), paths);
9788f4549740 6838467: JSR199 FileObjects don't obey general contract of equals.
jjg
parents:
diff changeset
   101
        }
9788f4549740 6838467: JSR199 FileObjects don't obey general contract of equals.
jjg
parents:
diff changeset
   102
9788f4549740 6838467: JSR199 FileObjects don't obey general contract of equals.
jjg
parents:
diff changeset
   103
        // test the various sorts of file objects that can be obtained from
9788f4549740 6838467: JSR199 FileObjects don't obey general contract of equals.
jjg
parents:
diff changeset
   104
        // the file manager, and for various values that may or may not match.
9788f4549740 6838467: JSR199 FileObjects don't obey general contract of equals.
jjg
parents:
diff changeset
   105
        for (FileKind fk: FileKind.values()) {
9788f4549740 6838467: JSR199 FileObjects don't obey general contract of equals.
jjg
parents:
diff changeset
   106
            for (CompareKind ck: CompareKind.values()) {
9788f4549740 6838467: JSR199 FileObjects don't obey general contract of equals.
jjg
parents:
diff changeset
   107
                test(fk, ck);
9788f4549740 6838467: JSR199 FileObjects don't obey general contract of equals.
jjg
parents:
diff changeset
   108
            }
9788f4549740 6838467: JSR199 FileObjects don't obey general contract of equals.
jjg
parents:
diff changeset
   109
        }
9788f4549740 6838467: JSR199 FileObjects don't obey general contract of equals.
jjg
parents:
diff changeset
   110
9788f4549740 6838467: JSR199 FileObjects don't obey general contract of equals.
jjg
parents:
diff changeset
   111
        // verify that the various different types of file object were all
9788f4549740 6838467: JSR199 FileObjects don't obey general contract of equals.
jjg
parents:
diff changeset
   112
        // tested
34560
b6a567b677f7 8059976: Convert JavacFileManager to use java.nio.file internally
jjg
parents: 30730
diff changeset
   113
        Set<String> expectClasses = new HashSet<>(Arrays.asList(
b6a567b677f7 8059976: Convert JavacFileManager to use java.nio.file internally
jjg
parents: 30730
diff changeset
   114
                "DirectoryFileObject",
b6a567b677f7 8059976: Convert JavacFileManager to use java.nio.file internally
jjg
parents: 30730
diff changeset
   115
                "JarFileObject" ));
4073
9788f4549740 6838467: JSR199 FileObjects don't obey general contract of equals.
jjg
parents:
diff changeset
   116
        if (!foundClasses.equals(expectClasses)) {
9788f4549740 6838467: JSR199 FileObjects don't obey general contract of equals.
jjg
parents:
diff changeset
   117
            error("expected fileobject classes not found\n"
9788f4549740 6838467: JSR199 FileObjects don't obey general contract of equals.
jjg
parents:
diff changeset
   118
                    + "expected: " + expectClasses + "\n"
9788f4549740 6838467: JSR199 FileObjects don't obey general contract of equals.
jjg
parents:
diff changeset
   119
                    + "found: " + foundClasses);
9788f4549740 6838467: JSR199 FileObjects don't obey general contract of equals.
jjg
parents:
diff changeset
   120
        }
9788f4549740 6838467: JSR199 FileObjects don't obey general contract of equals.
jjg
parents:
diff changeset
   121
9788f4549740 6838467: JSR199 FileObjects don't obey general contract of equals.
jjg
parents:
diff changeset
   122
        if (errors > 0)
9788f4549740 6838467: JSR199 FileObjects don't obey general contract of equals.
jjg
parents:
diff changeset
   123
            throw new Exception(errors + " errors");
9788f4549740 6838467: JSR199 FileObjects don't obey general contract of equals.
jjg
parents:
diff changeset
   124
    }
9788f4549740 6838467: JSR199 FileObjects don't obey general contract of equals.
jjg
parents:
diff changeset
   125
9788f4549740 6838467: JSR199 FileObjects don't obey general contract of equals.
jjg
parents:
diff changeset
   126
    void test(FileKind fk, CompareKind ck) throws IOException {
34560
b6a567b677f7 8059976: Convert JavacFileManager to use java.nio.file internally
jjg
parents: 30730
diff changeset
   127
        try (StandardJavaFileManager fm = createFileManager()) {
b6a567b677f7 8059976: Convert JavacFileManager to use java.nio.file internally
jjg
parents: 30730
diff changeset
   128
            File f1 = fk.file;
b6a567b677f7 8059976: Convert JavacFileManager to use java.nio.file internally
jjg
parents: 30730
diff changeset
   129
            Location l1 = createLocation(fm, "l1", f1);
4073
9788f4549740 6838467: JSR199 FileObjects don't obey general contract of equals.
jjg
parents:
diff changeset
   130
34560
b6a567b677f7 8059976: Convert JavacFileManager to use java.nio.file internally
jjg
parents: 30730
diff changeset
   131
            File f2 = ck.other(fk.file);
b6a567b677f7 8059976: Convert JavacFileManager to use java.nio.file internally
jjg
parents: 30730
diff changeset
   132
            Location l2 = createLocation(fm, "l2", f2);
4073
9788f4549740 6838467: JSR199 FileObjects don't obey general contract of equals.
jjg
parents:
diff changeset
   133
9788f4549740 6838467: JSR199 FileObjects don't obey general contract of equals.
jjg
parents:
diff changeset
   134
            // If the directories or zip files match, we expect "n" matches in
9788f4549740 6838467: JSR199 FileObjects don't obey general contract of equals.
jjg
parents:
diff changeset
   135
            // the "n-squared" comparisons to come, where "n" is the number of
9788f4549740 6838467: JSR199 FileObjects don't obey general contract of equals.
jjg
parents:
diff changeset
   136
            // entries in the the directories or zip files.
9788f4549740 6838467: JSR199 FileObjects don't obey general contract of equals.
jjg
parents:
diff changeset
   137
            // If the directories or zip files don't themselves match,
9788f4549740 6838467: JSR199 FileObjects don't obey general contract of equals.
jjg
parents:
diff changeset
   138
            // we obviously don't expect any of their contents to match either.
34560
b6a567b677f7 8059976: Convert JavacFileManager to use java.nio.file internally
jjg
parents: 30730
diff changeset
   139
            int expectEqualCount = (f1.getCanonicalFile().equals(f2.getCanonicalFile()) ? paths.length : 0);
4073
9788f4549740 6838467: JSR199 FileObjects don't obey general contract of equals.
jjg
parents:
diff changeset
   140
9788f4549740 6838467: JSR199 FileObjects don't obey general contract of equals.
jjg
parents:
diff changeset
   141
            System.err.println("test " + (++count) + " " + fk + " " + ck + " " + f1 + " " + f2);
34560
b6a567b677f7 8059976: Convert JavacFileManager to use java.nio.file internally
jjg
parents: 30730
diff changeset
   142
            test(fm, l1, l2, expectEqualCount);
4073
9788f4549740 6838467: JSR199 FileObjects don't obey general contract of equals.
jjg
parents:
diff changeset
   143
        }
9788f4549740 6838467: JSR199 FileObjects don't obey general contract of equals.
jjg
parents:
diff changeset
   144
    }
9788f4549740 6838467: JSR199 FileObjects don't obey general contract of equals.
jjg
parents:
diff changeset
   145
9788f4549740 6838467: JSR199 FileObjects don't obey general contract of equals.
jjg
parents:
diff changeset
   146
    // For a pair of file managers that may or may not have similar entries
9788f4549740 6838467: JSR199 FileObjects don't obey general contract of equals.
jjg
parents:
diff changeset
   147
    // on the classpath, compare all files returned from one against all files
9788f4549740 6838467: JSR199 FileObjects don't obey general contract of equals.
jjg
parents:
diff changeset
   148
    // returned from the other.  For each pair of files, verify that if they
9788f4549740 6838467: JSR199 FileObjects don't obey general contract of equals.
jjg
parents:
diff changeset
   149
    // are equal, the hashcode is equal as well, and finally verify that the
9788f4549740 6838467: JSR199 FileObjects don't obey general contract of equals.
jjg
parents:
diff changeset
   150
    // expected number of matches was found.
34560
b6a567b677f7 8059976: Convert JavacFileManager to use java.nio.file internally
jjg
parents: 30730
diff changeset
   151
    void test(JavaFileManager fm, Location l1, Location l2, int expectEqualCount) throws IOException {
4073
9788f4549740 6838467: JSR199 FileObjects don't obey general contract of equals.
jjg
parents:
diff changeset
   152
        boolean foundFiles1 = false;
9788f4549740 6838467: JSR199 FileObjects don't obey general contract of equals.
jjg
parents:
diff changeset
   153
        boolean foundFiles2 = false;
9788f4549740 6838467: JSR199 FileObjects don't obey general contract of equals.
jjg
parents:
diff changeset
   154
        int foundEqualCount = 0;
9788f4549740 6838467: JSR199 FileObjects don't obey general contract of equals.
jjg
parents:
diff changeset
   155
        Set<JavaFileObject.Kind> kinds =  EnumSet.allOf(JavaFileObject.Kind.class);
34560
b6a567b677f7 8059976: Convert JavacFileManager to use java.nio.file internally
jjg
parents: 30730
diff changeset
   156
        for (FileObject fo1: fm.list(l1, "p", kinds, false)) {
4073
9788f4549740 6838467: JSR199 FileObjects don't obey general contract of equals.
jjg
parents:
diff changeset
   157
            foundFiles1 = true;
9788f4549740 6838467: JSR199 FileObjects don't obey general contract of equals.
jjg
parents:
diff changeset
   158
            foundClasses.add(fo1.getClass().getSimpleName());
34560
b6a567b677f7 8059976: Convert JavacFileManager to use java.nio.file internally
jjg
parents: 30730
diff changeset
   159
            for (FileObject fo2: fm.list(l2, "p", kinds, false)) {
4073
9788f4549740 6838467: JSR199 FileObjects don't obey general contract of equals.
jjg
parents:
diff changeset
   160
                foundFiles2 = true;
34560
b6a567b677f7 8059976: Convert JavacFileManager to use java.nio.file internally
jjg
parents: 30730
diff changeset
   161
                foundClasses.add(fo2.getClass().getSimpleName());
4073
9788f4549740 6838467: JSR199 FileObjects don't obey general contract of equals.
jjg
parents:
diff changeset
   162
                System.err.println("compare " + fo1 + " " + fo2);
9788f4549740 6838467: JSR199 FileObjects don't obey general contract of equals.
jjg
parents:
diff changeset
   163
                if (fo1.equals(fo2)) {
9788f4549740 6838467: JSR199 FileObjects don't obey general contract of equals.
jjg
parents:
diff changeset
   164
                    foundEqualCount++;
9788f4549740 6838467: JSR199 FileObjects don't obey general contract of equals.
jjg
parents:
diff changeset
   165
                    int hash1 = fo1.hashCode();
9788f4549740 6838467: JSR199 FileObjects don't obey general contract of equals.
jjg
parents:
diff changeset
   166
                    int hash2 = fo2.hashCode();
9788f4549740 6838467: JSR199 FileObjects don't obey general contract of equals.
jjg
parents:
diff changeset
   167
                    if (hash1 != hash2)
9788f4549740 6838467: JSR199 FileObjects don't obey general contract of equals.
jjg
parents:
diff changeset
   168
                        error("hashCode error: " + fo1 + " [" + hash1 + "] "
9788f4549740 6838467: JSR199 FileObjects don't obey general contract of equals.
jjg
parents:
diff changeset
   169
                                + fo2 + " [" + hash2 + "]");
9788f4549740 6838467: JSR199 FileObjects don't obey general contract of equals.
jjg
parents:
diff changeset
   170
                }
9788f4549740 6838467: JSR199 FileObjects don't obey general contract of equals.
jjg
parents:
diff changeset
   171
            }
9788f4549740 6838467: JSR199 FileObjects don't obey general contract of equals.
jjg
parents:
diff changeset
   172
        }
9788f4549740 6838467: JSR199 FileObjects don't obey general contract of equals.
jjg
parents:
diff changeset
   173
        if (!foundFiles1)
34560
b6a567b677f7 8059976: Convert JavacFileManager to use java.nio.file internally
jjg
parents: 30730
diff changeset
   174
            error("no files found for location " + l1);
4073
9788f4549740 6838467: JSR199 FileObjects don't obey general contract of equals.
jjg
parents:
diff changeset
   175
        if (!foundFiles2)
34560
b6a567b677f7 8059976: Convert JavacFileManager to use java.nio.file internally
jjg
parents: 30730
diff changeset
   176
            error("no files found for location " + l2);
4073
9788f4549740 6838467: JSR199 FileObjects don't obey general contract of equals.
jjg
parents:
diff changeset
   177
        // verify the expected number of matches were found
9788f4549740 6838467: JSR199 FileObjects don't obey general contract of equals.
jjg
parents:
diff changeset
   178
        if (foundEqualCount != expectEqualCount)
9788f4549740 6838467: JSR199 FileObjects don't obey general contract of equals.
jjg
parents:
diff changeset
   179
            error("expected matches not found: expected " + expectEqualCount + ", found " + foundEqualCount);
9788f4549740 6838467: JSR199 FileObjects don't obey general contract of equals.
jjg
parents:
diff changeset
   180
    }
9788f4549740 6838467: JSR199 FileObjects don't obey general contract of equals.
jjg
parents:
diff changeset
   181
34560
b6a567b677f7 8059976: Convert JavacFileManager to use java.nio.file internally
jjg
parents: 30730
diff changeset
   182
    // create and initialize a location to test a FileKind, with a given directory
b6a567b677f7 8059976: Convert JavacFileManager to use java.nio.file internally
jjg
parents: 30730
diff changeset
   183
    // or zip file placed on the path
b6a567b677f7 8059976: Convert JavacFileManager to use java.nio.file internally
jjg
parents: 30730
diff changeset
   184
    Location createLocation(StandardJavaFileManager fm, String name, File classpath) throws IOException {
b6a567b677f7 8059976: Convert JavacFileManager to use java.nio.file internally
jjg
parents: 30730
diff changeset
   185
        Location l = new Location() {
b6a567b677f7 8059976: Convert JavacFileManager to use java.nio.file internally
jjg
parents: 30730
diff changeset
   186
            @Override
b6a567b677f7 8059976: Convert JavacFileManager to use java.nio.file internally
jjg
parents: 30730
diff changeset
   187
            public String getName() {
b6a567b677f7 8059976: Convert JavacFileManager to use java.nio.file internally
jjg
parents: 30730
diff changeset
   188
                return name;
b6a567b677f7 8059976: Convert JavacFileManager to use java.nio.file internally
jjg
parents: 30730
diff changeset
   189
            }
b6a567b677f7 8059976: Convert JavacFileManager to use java.nio.file internally
jjg
parents: 30730
diff changeset
   190
b6a567b677f7 8059976: Convert JavacFileManager to use java.nio.file internally
jjg
parents: 30730
diff changeset
   191
            @Override
b6a567b677f7 8059976: Convert JavacFileManager to use java.nio.file internally
jjg
parents: 30730
diff changeset
   192
            public boolean isOutputLocation() {
b6a567b677f7 8059976: Convert JavacFileManager to use java.nio.file internally
jjg
parents: 30730
diff changeset
   193
                return false;
b6a567b677f7 8059976: Convert JavacFileManager to use java.nio.file internally
jjg
parents: 30730
diff changeset
   194
            }
b6a567b677f7 8059976: Convert JavacFileManager to use java.nio.file internally
jjg
parents: 30730
diff changeset
   195
b6a567b677f7 8059976: Convert JavacFileManager to use java.nio.file internally
jjg
parents: 30730
diff changeset
   196
        };
b6a567b677f7 8059976: Convert JavacFileManager to use java.nio.file internally
jjg
parents: 30730
diff changeset
   197
        fm.setLocation(l, Arrays.asList(classpath));
b6a567b677f7 8059976: Convert JavacFileManager to use java.nio.file internally
jjg
parents: 30730
diff changeset
   198
        return l;
4073
9788f4549740 6838467: JSR199 FileObjects don't obey general contract of equals.
jjg
parents:
diff changeset
   199
    }
9788f4549740 6838467: JSR199 FileObjects don't obey general contract of equals.
jjg
parents:
diff changeset
   200
34560
b6a567b677f7 8059976: Convert JavacFileManager to use java.nio.file internally
jjg
parents: 30730
diff changeset
   201
    JavacFileManager createFileManager() {
8432
d3380b1e4779 7018859: javac turn off the Zip optimization by default
ksrini
parents: 5520
diff changeset
   202
        Context ctx = new Context();
d3380b1e4779 7018859: javac turn off the Zip optimization by default
ksrini
parents: 5520
diff changeset
   203
        return new JavacFileManager(ctx, false, null);
4073
9788f4549740 6838467: JSR199 FileObjects don't obey general contract of equals.
jjg
parents:
diff changeset
   204
    }
9788f4549740 6838467: JSR199 FileObjects don't obey general contract of equals.
jjg
parents:
diff changeset
   205
9788f4549740 6838467: JSR199 FileObjects don't obey general contract of equals.
jjg
parents:
diff changeset
   206
    // create a directory containing a given set of paths
9788f4549740 6838467: JSR199 FileObjects don't obey general contract of equals.
jjg
parents:
diff changeset
   207
    void createTestDir(File dir, String[] paths) throws IOException {
9788f4549740 6838467: JSR199 FileObjects don't obey general contract of equals.
jjg
parents:
diff changeset
   208
        for (String p: paths) {
9788f4549740 6838467: JSR199 FileObjects don't obey general contract of equals.
jjg
parents:
diff changeset
   209
            File file = new File(dir, p);
9788f4549740 6838467: JSR199 FileObjects don't obey general contract of equals.
jjg
parents:
diff changeset
   210
            file.getParentFile().mkdirs();
34560
b6a567b677f7 8059976: Convert JavacFileManager to use java.nio.file internally
jjg
parents: 30730
diff changeset
   211
            try (FileWriter out = new FileWriter(file)) {
4073
9788f4549740 6838467: JSR199 FileObjects don't obey general contract of equals.
jjg
parents:
diff changeset
   212
                out.write(p);
9788f4549740 6838467: JSR199 FileObjects don't obey general contract of equals.
jjg
parents:
diff changeset
   213
            }
9788f4549740 6838467: JSR199 FileObjects don't obey general contract of equals.
jjg
parents:
diff changeset
   214
        }
9788f4549740 6838467: JSR199 FileObjects don't obey general contract of equals.
jjg
parents:
diff changeset
   215
    }
9788f4549740 6838467: JSR199 FileObjects don't obey general contract of equals.
jjg
parents:
diff changeset
   216
34560
b6a567b677f7 8059976: Convert JavacFileManager to use java.nio.file internally
jjg
parents: 30730
diff changeset
   217
    // create a zip file containing a given set of entries
4073
9788f4549740 6838467: JSR199 FileObjects don't obey general contract of equals.
jjg
parents:
diff changeset
   218
    void createTestZip(File zip, String[] paths) throws IOException {
9788f4549740 6838467: JSR199 FileObjects don't obey general contract of equals.
jjg
parents:
diff changeset
   219
        if (zip.getParentFile() != null)
9788f4549740 6838467: JSR199 FileObjects don't obey general contract of equals.
jjg
parents:
diff changeset
   220
            zip.getParentFile().mkdirs();
34560
b6a567b677f7 8059976: Convert JavacFileManager to use java.nio.file internally
jjg
parents: 30730
diff changeset
   221
        try (ZipOutputStream zos = new ZipOutputStream(new FileOutputStream(zip))) {
4073
9788f4549740 6838467: JSR199 FileObjects don't obey general contract of equals.
jjg
parents:
diff changeset
   222
            for (String p: paths) {
9788f4549740 6838467: JSR199 FileObjects don't obey general contract of equals.
jjg
parents:
diff changeset
   223
                ZipEntry ze = new ZipEntry(p);
9788f4549740 6838467: JSR199 FileObjects don't obey general contract of equals.
jjg
parents:
diff changeset
   224
                zos.putNextEntry(ze);
9788f4549740 6838467: JSR199 FileObjects don't obey general contract of equals.
jjg
parents:
diff changeset
   225
                byte[] bytes = p.getBytes();
9788f4549740 6838467: JSR199 FileObjects don't obey general contract of equals.
jjg
parents:
diff changeset
   226
                zos.write(bytes, 0, bytes.length);
9788f4549740 6838467: JSR199 FileObjects don't obey general contract of equals.
jjg
parents:
diff changeset
   227
                zos.closeEntry();
9788f4549740 6838467: JSR199 FileObjects don't obey general contract of equals.
jjg
parents:
diff changeset
   228
            }
9788f4549740 6838467: JSR199 FileObjects don't obey general contract of equals.
jjg
parents:
diff changeset
   229
        }
9788f4549740 6838467: JSR199 FileObjects don't obey general contract of equals.
jjg
parents:
diff changeset
   230
    }
9788f4549740 6838467: JSR199 FileObjects don't obey general contract of equals.
jjg
parents:
diff changeset
   231
9788f4549740 6838467: JSR199 FileObjects don't obey general contract of equals.
jjg
parents:
diff changeset
   232
    void error(String msg) {
9788f4549740 6838467: JSR199 FileObjects don't obey general contract of equals.
jjg
parents:
diff changeset
   233
        System.err.println("Error: " + msg);
9788f4549740 6838467: JSR199 FileObjects don't obey general contract of equals.
jjg
parents:
diff changeset
   234
        errors++;
9788f4549740 6838467: JSR199 FileObjects don't obey general contract of equals.
jjg
parents:
diff changeset
   235
    }
9788f4549740 6838467: JSR199 FileObjects don't obey general contract of equals.
jjg
parents:
diff changeset
   236
34560
b6a567b677f7 8059976: Convert JavacFileManager to use java.nio.file internally
jjg
parents: 30730
diff changeset
   237
    boolean isFileNameCaseSignificant() {
b6a567b677f7 8059976: Convert JavacFileManager to use java.nio.file internally
jjg
parents: 30730
diff changeset
   238
        File lower = new File("test.txt");
b6a567b677f7 8059976: Convert JavacFileManager to use java.nio.file internally
jjg
parents: 30730
diff changeset
   239
        File upper = new File(lower.getPath().toUpperCase());
b6a567b677f7 8059976: Convert JavacFileManager to use java.nio.file internally
jjg
parents: 30730
diff changeset
   240
        return !lower.equals(upper);
b6a567b677f7 8059976: Convert JavacFileManager to use java.nio.file internally
jjg
parents: 30730
diff changeset
   241
    }
b6a567b677f7 8059976: Convert JavacFileManager to use java.nio.file internally
jjg
parents: 30730
diff changeset
   242
b6a567b677f7 8059976: Convert JavacFileManager to use java.nio.file internally
jjg
parents: 30730
diff changeset
   243
    boolean isFileLookupCaseSignificant() throws IOException {
b6a567b677f7 8059976: Convert JavacFileManager to use java.nio.file internally
jjg
parents: 30730
diff changeset
   244
        File lower = new File("test.txt");
b6a567b677f7 8059976: Convert JavacFileManager to use java.nio.file internally
jjg
parents: 30730
diff changeset
   245
        File upper = new File(lower.getPath().toUpperCase());
b6a567b677f7 8059976: Convert JavacFileManager to use java.nio.file internally
jjg
parents: 30730
diff changeset
   246
        if (upper.exists()) {
b6a567b677f7 8059976: Convert JavacFileManager to use java.nio.file internally
jjg
parents: 30730
diff changeset
   247
            upper.delete();
b6a567b677f7 8059976: Convert JavacFileManager to use java.nio.file internally
jjg
parents: 30730
diff changeset
   248
        }
b6a567b677f7 8059976: Convert JavacFileManager to use java.nio.file internally
jjg
parents: 30730
diff changeset
   249
        try (FileWriter out = new FileWriter(lower)) { }
b6a567b677f7 8059976: Convert JavacFileManager to use java.nio.file internally
jjg
parents: 30730
diff changeset
   250
        return !upper.exists();
b6a567b677f7 8059976: Convert JavacFileManager to use java.nio.file internally
jjg
parents: 30730
diff changeset
   251
    }
b6a567b677f7 8059976: Convert JavacFileManager to use java.nio.file internally
jjg
parents: 30730
diff changeset
   252
4073
9788f4549740 6838467: JSR199 FileObjects don't obey general contract of equals.
jjg
parents:
diff changeset
   253
    int count;
9788f4549740 6838467: JSR199 FileObjects don't obey general contract of equals.
jjg
parents:
diff changeset
   254
    int errors;
34560
b6a567b677f7 8059976: Convert JavacFileManager to use java.nio.file internally
jjg
parents: 30730
diff changeset
   255
    Set<String> foundClasses = new HashSet<>();
4073
9788f4549740 6838467: JSR199 FileObjects don't obey general contract of equals.
jjg
parents:
diff changeset
   256
}
9788f4549740 6838467: JSR199 FileObjects don't obey general contract of equals.
jjg
parents:
diff changeset
   257