langtools/test/tools/javac/api/T6838467.java
author ksrini
Fri, 18 Feb 2011 08:12:06 -0800
changeset 8432 d3380b1e4779
parent 5520 86e4b9a9da40
child 8837 141b22c7e7b2
permissions -rw-r--r--
7018859: javac turn off the Zip optimization by default Reviewed-by: jjg
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
/*
8432
d3380b1e4779 7018859: javac turn off the Zip optimization by default
ksrini
parents: 5520
diff changeset
     2
 * Copyright (c) 2009, 2011 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.
9788f4549740 6838467: JSR199 FileObjects don't obey general contract of equals.
jjg
parents:
diff changeset
    28
 */
9788f4549740 6838467: JSR199 FileObjects don't obey general contract of equals.
jjg
parents:
diff changeset
    29
9788f4549740 6838467: JSR199 FileObjects don't obey general contract of equals.
jjg
parents:
diff changeset
    30
import java.io.*;
9788f4549740 6838467: JSR199 FileObjects don't obey general contract of equals.
jjg
parents:
diff changeset
    31
import java.util.*;
9788f4549740 6838467: JSR199 FileObjects don't obey general contract of equals.
jjg
parents:
diff changeset
    32
import java.util.zip.*;
9788f4549740 6838467: JSR199 FileObjects don't obey general contract of equals.
jjg
parents:
diff changeset
    33
import javax.tools.*;
9788f4549740 6838467: JSR199 FileObjects don't obey general contract of equals.
jjg
parents:
diff changeset
    34
import com.sun.tools.javac.file.JavacFileManager;
8432
d3380b1e4779 7018859: javac turn off the Zip optimization by default
ksrini
parents: 5520
diff changeset
    35
import com.sun.tools.javac.main.OptionName;
4073
9788f4549740 6838467: JSR199 FileObjects don't obey general contract of equals.
jjg
parents:
diff changeset
    36
import com.sun.tools.javac.util.Context;
8432
d3380b1e4779 7018859: javac turn off the Zip optimization by default
ksrini
parents: 5520
diff changeset
    37
import com.sun.tools.javac.util.Options;
4073
9788f4549740 6838467: JSR199 FileObjects don't obey general contract of equals.
jjg
parents:
diff changeset
    38
9788f4549740 6838467: JSR199 FileObjects don't obey general contract of equals.
jjg
parents:
diff changeset
    39
public class T6838467 {
9788f4549740 6838467: JSR199 FileObjects don't obey general contract of equals.
jjg
parents:
diff changeset
    40
    boolean fileSystemIsCaseSignificant = !new File("a").equals(new File("A"));
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
    enum FileKind {
9788f4549740 6838467: JSR199 FileObjects don't obey general contract of equals.
jjg
parents:
diff changeset
    43
        DIR("dir"),
9788f4549740 6838467: JSR199 FileObjects don't obey general contract of equals.
jjg
parents:
diff changeset
    44
        ZIP("zip"),
9788f4549740 6838467: JSR199 FileObjects don't obey general contract of equals.
jjg
parents:
diff changeset
    45
        ZIPFILEINDEX("zip");
9788f4549740 6838467: JSR199 FileObjects don't obey general contract of equals.
jjg
parents:
diff changeset
    46
        FileKind(String path) {
9788f4549740 6838467: JSR199 FileObjects don't obey general contract of equals.
jjg
parents:
diff changeset
    47
            file = new File(path);
9788f4549740 6838467: JSR199 FileObjects don't obey general contract of equals.
jjg
parents:
diff changeset
    48
        }
9788f4549740 6838467: JSR199 FileObjects don't obey general contract of equals.
jjg
parents:
diff changeset
    49
        final File file;
9788f4549740 6838467: JSR199 FileObjects don't obey general contract of equals.
jjg
parents:
diff changeset
    50
    };
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
    enum CompareKind {
9788f4549740 6838467: JSR199 FileObjects don't obey general contract of equals.
jjg
parents:
diff changeset
    53
        SAME {
9788f4549740 6838467: JSR199 FileObjects don't obey general contract of equals.
jjg
parents:
diff changeset
    54
            File other(File f) { return f; }
9788f4549740 6838467: JSR199 FileObjects don't obey general contract of equals.
jjg
parents:
diff changeset
    55
        },
9788f4549740 6838467: JSR199 FileObjects don't obey general contract of equals.
jjg
parents:
diff changeset
    56
        ABSOLUTE {
9788f4549740 6838467: JSR199 FileObjects don't obey general contract of equals.
jjg
parents:
diff changeset
    57
            File other(File f) { return f.getAbsoluteFile(); }
9788f4549740 6838467: JSR199 FileObjects don't obey general contract of equals.
jjg
parents:
diff changeset
    58
        },
9788f4549740 6838467: JSR199 FileObjects don't obey general contract of equals.
jjg
parents:
diff changeset
    59
        DIFFERENT {
9788f4549740 6838467: JSR199 FileObjects don't obey general contract of equals.
jjg
parents:
diff changeset
    60
            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
    61
        },
9788f4549740 6838467: JSR199 FileObjects don't obey general contract of equals.
jjg
parents:
diff changeset
    62
        CASEEQUIV {
9788f4549740 6838467: JSR199 FileObjects don't obey general contract of equals.
jjg
parents:
diff changeset
    63
            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
    64
        };
9788f4549740 6838467: JSR199 FileObjects don't obey general contract of equals.
jjg
parents:
diff changeset
    65
        abstract File other(File f);
9788f4549740 6838467: JSR199 FileObjects don't obey general contract of equals.
jjg
parents:
diff changeset
    66
    };
9788f4549740 6838467: JSR199 FileObjects don't obey general contract of equals.
jjg
parents:
diff changeset
    67
9788f4549740 6838467: JSR199 FileObjects don't obey general contract of equals.
jjg
parents:
diff changeset
    68
    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
    69
9788f4549740 6838467: JSR199 FileObjects don't obey general contract of equals.
jjg
parents:
diff changeset
    70
    public static void main(String... args) throws Exception {
9788f4549740 6838467: JSR199 FileObjects don't obey general contract of equals.
jjg
parents:
diff changeset
    71
        new T6838467().run();
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
9788f4549740 6838467: JSR199 FileObjects don't obey general contract of equals.
jjg
parents:
diff changeset
    74
    void run() throws Exception {
9788f4549740 6838467: JSR199 FileObjects don't obey general contract of equals.
jjg
parents:
diff changeset
    75
        // on Windows, verify file system is not case significant
9788f4549740 6838467: JSR199 FileObjects don't obey general contract of equals.
jjg
parents:
diff changeset
    76
        if (System.getProperty("os.name").toLowerCase().startsWith("windows")
9788f4549740 6838467: JSR199 FileObjects don't obey general contract of equals.
jjg
parents:
diff changeset
    77
                && fileSystemIsCaseSignificant) {
9788f4549740 6838467: JSR199 FileObjects don't obey general contract of equals.
jjg
parents:
diff changeset
    78
            error("fileSystemIsCaseSignificant is set on Windows.");
9788f4549740 6838467: JSR199 FileObjects don't obey general contract of equals.
jjg
parents:
diff changeset
    79
        }
9788f4549740 6838467: JSR199 FileObjects don't obey general contract of equals.
jjg
parents:
diff changeset
    80
9788f4549740 6838467: JSR199 FileObjects don't obey general contract of equals.
jjg
parents:
diff changeset
    81
        // 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
    82
        createTestDir(new File("dir"), paths);
9788f4549740 6838467: JSR199 FileObjects don't obey general contract of equals.
jjg
parents:
diff changeset
    83
        createTestDir(new File("not_dir"), paths);
9788f4549740 6838467: JSR199 FileObjects don't obey general contract of equals.
jjg
parents:
diff changeset
    84
        createTestZip(new File("zip"), paths);
9788f4549740 6838467: JSR199 FileObjects don't obey general contract of equals.
jjg
parents:
diff changeset
    85
        createTestZip(new File("not_zip"), paths);
9788f4549740 6838467: JSR199 FileObjects don't obey general contract of equals.
jjg
parents:
diff changeset
    86
        if (fileSystemIsCaseSignificant) {
9788f4549740 6838467: JSR199 FileObjects don't obey general contract of equals.
jjg
parents:
diff changeset
    87
            createTestDir(new File("DIR"), paths);
9788f4549740 6838467: JSR199 FileObjects don't obey general contract of equals.
jjg
parents:
diff changeset
    88
            createTestZip(new File("ZIP"), paths);
9788f4549740 6838467: JSR199 FileObjects don't obey general contract of equals.
jjg
parents:
diff changeset
    89
        }
9788f4549740 6838467: JSR199 FileObjects don't obey general contract of equals.
jjg
parents:
diff changeset
    90
9788f4549740 6838467: JSR199 FileObjects don't obey general contract of equals.
jjg
parents:
diff changeset
    91
        // 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
    92
        // 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
    93
        for (FileKind fk: FileKind.values()) {
9788f4549740 6838467: JSR199 FileObjects don't obey general contract of equals.
jjg
parents:
diff changeset
    94
            for (CompareKind ck: CompareKind.values()) {
9788f4549740 6838467: JSR199 FileObjects don't obey general contract of equals.
jjg
parents:
diff changeset
    95
                test(fk, ck);
9788f4549740 6838467: JSR199 FileObjects don't obey general contract of equals.
jjg
parents:
diff changeset
    96
            }
9788f4549740 6838467: JSR199 FileObjects don't obey general contract of equals.
jjg
parents:
diff changeset
    97
        }
9788f4549740 6838467: JSR199 FileObjects don't obey general contract of equals.
jjg
parents:
diff changeset
    98
9788f4549740 6838467: JSR199 FileObjects don't obey general contract of equals.
jjg
parents:
diff changeset
    99
        // 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
   100
        // tested
9788f4549740 6838467: JSR199 FileObjects don't obey general contract of equals.
jjg
parents:
diff changeset
   101
        Set<String> expectClasses = new HashSet<String>(Arrays.asList(
9788f4549740 6838467: JSR199 FileObjects don't obey general contract of equals.
jjg
parents:
diff changeset
   102
                "RegularFileObject", "ZipFileObject", "ZipFileIndexFileObject" ));
9788f4549740 6838467: JSR199 FileObjects don't obey general contract of equals.
jjg
parents:
diff changeset
   103
        if (!foundClasses.equals(expectClasses)) {
9788f4549740 6838467: JSR199 FileObjects don't obey general contract of equals.
jjg
parents:
diff changeset
   104
            error("expected fileobject classes not found\n"
9788f4549740 6838467: JSR199 FileObjects don't obey general contract of equals.
jjg
parents:
diff changeset
   105
                    + "expected: " + expectClasses + "\n"
9788f4549740 6838467: JSR199 FileObjects don't obey general contract of equals.
jjg
parents:
diff changeset
   106
                    + "found: " + foundClasses);
9788f4549740 6838467: JSR199 FileObjects don't obey general contract of equals.
jjg
parents:
diff changeset
   107
        }
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
        if (errors > 0)
9788f4549740 6838467: JSR199 FileObjects don't obey general contract of equals.
jjg
parents:
diff changeset
   110
            throw new Exception(errors + " errors");
9788f4549740 6838467: JSR199 FileObjects don't obey general contract of equals.
jjg
parents:
diff changeset
   111
    }
9788f4549740 6838467: JSR199 FileObjects don't obey general contract of equals.
jjg
parents:
diff changeset
   112
9788f4549740 6838467: JSR199 FileObjects don't obey general contract of equals.
jjg
parents:
diff changeset
   113
    void test(FileKind fk, CompareKind ck) throws IOException {
9788f4549740 6838467: JSR199 FileObjects don't obey general contract of equals.
jjg
parents:
diff changeset
   114
        File f1 = fk.file;
9788f4549740 6838467: JSR199 FileObjects don't obey general contract of equals.
jjg
parents:
diff changeset
   115
        JavaFileManager fm1 = createFileManager(fk, f1);
9788f4549740 6838467: JSR199 FileObjects don't obey general contract of equals.
jjg
parents:
diff changeset
   116
9788f4549740 6838467: JSR199 FileObjects don't obey general contract of equals.
jjg
parents:
diff changeset
   117
        File f2 = ck.other(fk.file);
9788f4549740 6838467: JSR199 FileObjects don't obey general contract of equals.
jjg
parents:
diff changeset
   118
        JavaFileManager fm2 = createFileManager(fk, f2);
9788f4549740 6838467: JSR199 FileObjects don't obey general contract of equals.
jjg
parents:
diff changeset
   119
9788f4549740 6838467: JSR199 FileObjects don't obey general contract of equals.
jjg
parents:
diff changeset
   120
        try {
9788f4549740 6838467: JSR199 FileObjects don't obey general contract of equals.
jjg
parents:
diff changeset
   121
            // 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
   122
            // 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
   123
            // entries in the the directories or zip files.
9788f4549740 6838467: JSR199 FileObjects don't obey general contract of equals.
jjg
parents:
diff changeset
   124
            // 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
   125
            // we obviously don't expect any of their contents to match either.
9788f4549740 6838467: JSR199 FileObjects don't obey general contract of equals.
jjg
parents:
diff changeset
   126
            int expect = (f1.getAbsoluteFile().equals(f2.getAbsoluteFile()) ? paths.length : 0);
9788f4549740 6838467: JSR199 FileObjects don't obey general contract of equals.
jjg
parents:
diff changeset
   127
9788f4549740 6838467: JSR199 FileObjects don't obey general contract of equals.
jjg
parents:
diff changeset
   128
            System.err.println("test " + (++count) + " " + fk + " " + ck + " " + f1 + " " + f2);
9788f4549740 6838467: JSR199 FileObjects don't obey general contract of equals.
jjg
parents:
diff changeset
   129
            test(fm1, fm2, expect);
9788f4549740 6838467: JSR199 FileObjects don't obey general contract of equals.
jjg
parents:
diff changeset
   130
9788f4549740 6838467: JSR199 FileObjects don't obey general contract of equals.
jjg
parents:
diff changeset
   131
        } finally {
9788f4549740 6838467: JSR199 FileObjects don't obey general contract of equals.
jjg
parents:
diff changeset
   132
            fm1.close();
9788f4549740 6838467: JSR199 FileObjects don't obey general contract of equals.
jjg
parents:
diff changeset
   133
            fm2.close();
9788f4549740 6838467: JSR199 FileObjects don't obey general contract of equals.
jjg
parents:
diff changeset
   134
        }
9788f4549740 6838467: JSR199 FileObjects don't obey general contract of equals.
jjg
parents:
diff changeset
   135
    }
9788f4549740 6838467: JSR199 FileObjects don't obey general contract of equals.
jjg
parents:
diff changeset
   136
9788f4549740 6838467: JSR199 FileObjects don't obey general contract of equals.
jjg
parents:
diff changeset
   137
    // 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
   138
    // 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
   139
    // 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
   140
    // 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
   141
    // expected number of matches was found.
9788f4549740 6838467: JSR199 FileObjects don't obey general contract of equals.
jjg
parents:
diff changeset
   142
    void test(JavaFileManager fm1, JavaFileManager fm2, int expectEqualCount) throws IOException {
9788f4549740 6838467: JSR199 FileObjects don't obey general contract of equals.
jjg
parents:
diff changeset
   143
        boolean foundFiles1 = false;
9788f4549740 6838467: JSR199 FileObjects don't obey general contract of equals.
jjg
parents:
diff changeset
   144
        boolean foundFiles2 = false;
9788f4549740 6838467: JSR199 FileObjects don't obey general contract of equals.
jjg
parents:
diff changeset
   145
        int foundEqualCount = 0;
9788f4549740 6838467: JSR199 FileObjects don't obey general contract of equals.
jjg
parents:
diff changeset
   146
        Set<JavaFileObject.Kind> kinds =  EnumSet.allOf(JavaFileObject.Kind.class);
9788f4549740 6838467: JSR199 FileObjects don't obey general contract of equals.
jjg
parents:
diff changeset
   147
        for (FileObject fo1: fm1.list(StandardLocation.CLASS_PATH, "p", kinds, false)) {
9788f4549740 6838467: JSR199 FileObjects don't obey general contract of equals.
jjg
parents:
diff changeset
   148
            foundFiles1 = true;
9788f4549740 6838467: JSR199 FileObjects don't obey general contract of equals.
jjg
parents:
diff changeset
   149
            foundClasses.add(fo1.getClass().getSimpleName());
9788f4549740 6838467: JSR199 FileObjects don't obey general contract of equals.
jjg
parents:
diff changeset
   150
            for (FileObject fo2: fm2.list(StandardLocation.CLASS_PATH, "p", kinds, false)) {
9788f4549740 6838467: JSR199 FileObjects don't obey general contract of equals.
jjg
parents:
diff changeset
   151
                foundFiles2 = true;
9788f4549740 6838467: JSR199 FileObjects don't obey general contract of equals.
jjg
parents:
diff changeset
   152
                foundClasses.add(fo1.getClass().getSimpleName());
9788f4549740 6838467: JSR199 FileObjects don't obey general contract of equals.
jjg
parents:
diff changeset
   153
                System.err.println("compare " + fo1 + " " + fo2);
9788f4549740 6838467: JSR199 FileObjects don't obey general contract of equals.
jjg
parents:
diff changeset
   154
                if (fo1.equals(fo2)) {
9788f4549740 6838467: JSR199 FileObjects don't obey general contract of equals.
jjg
parents:
diff changeset
   155
                    foundEqualCount++;
9788f4549740 6838467: JSR199 FileObjects don't obey general contract of equals.
jjg
parents:
diff changeset
   156
                    int hash1 = fo1.hashCode();
9788f4549740 6838467: JSR199 FileObjects don't obey general contract of equals.
jjg
parents:
diff changeset
   157
                    int hash2 = fo2.hashCode();
9788f4549740 6838467: JSR199 FileObjects don't obey general contract of equals.
jjg
parents:
diff changeset
   158
                    if (hash1 != hash2)
9788f4549740 6838467: JSR199 FileObjects don't obey general contract of equals.
jjg
parents:
diff changeset
   159
                        error("hashCode error: " + fo1 + " [" + hash1 + "] "
9788f4549740 6838467: JSR199 FileObjects don't obey general contract of equals.
jjg
parents:
diff changeset
   160
                                + fo2 + " [" + hash2 + "]");
9788f4549740 6838467: JSR199 FileObjects don't obey general contract of equals.
jjg
parents:
diff changeset
   161
                }
9788f4549740 6838467: JSR199 FileObjects don't obey general contract of equals.
jjg
parents:
diff changeset
   162
            }
9788f4549740 6838467: JSR199 FileObjects don't obey general contract of equals.
jjg
parents:
diff changeset
   163
        }
9788f4549740 6838467: JSR199 FileObjects don't obey general contract of equals.
jjg
parents:
diff changeset
   164
        if (!foundFiles1)
9788f4549740 6838467: JSR199 FileObjects don't obey general contract of equals.
jjg
parents:
diff changeset
   165
            error("no files found for file manager 1");
9788f4549740 6838467: JSR199 FileObjects don't obey general contract of equals.
jjg
parents:
diff changeset
   166
        if (!foundFiles2)
9788f4549740 6838467: JSR199 FileObjects don't obey general contract of equals.
jjg
parents:
diff changeset
   167
            error("no files found for file manager 2");
9788f4549740 6838467: JSR199 FileObjects don't obey general contract of equals.
jjg
parents:
diff changeset
   168
        // verify the expected number of matches were found
9788f4549740 6838467: JSR199 FileObjects don't obey general contract of equals.
jjg
parents:
diff changeset
   169
        if (foundEqualCount != expectEqualCount)
9788f4549740 6838467: JSR199 FileObjects don't obey general contract of equals.
jjg
parents:
diff changeset
   170
            error("expected matches not found: expected " + expectEqualCount + ", found " + foundEqualCount);
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
    // create a file manager to test a FileKind, with a given directory
9788f4549740 6838467: JSR199 FileObjects don't obey general contract of equals.
jjg
parents:
diff changeset
   174
    // or zip file placed on the classpath
9788f4549740 6838467: JSR199 FileObjects don't obey general contract of equals.
jjg
parents:
diff changeset
   175
    JavaFileManager createFileManager(FileKind fk, File classpath) throws IOException {
9788f4549740 6838467: JSR199 FileObjects don't obey general contract of equals.
jjg
parents:
diff changeset
   176
        StandardJavaFileManager fm = createFileManager(fk == FileKind.ZIP);
9788f4549740 6838467: JSR199 FileObjects don't obey general contract of equals.
jjg
parents:
diff changeset
   177
        fm.setLocation(StandardLocation.CLASS_PATH, Arrays.asList(classpath));
9788f4549740 6838467: JSR199 FileObjects don't obey general contract of equals.
jjg
parents:
diff changeset
   178
        return fm;
9788f4549740 6838467: JSR199 FileObjects don't obey general contract of equals.
jjg
parents:
diff changeset
   179
    }
9788f4549740 6838467: JSR199 FileObjects don't obey general contract of equals.
jjg
parents:
diff changeset
   180
8432
d3380b1e4779 7018859: javac turn off the Zip optimization by default
ksrini
parents: 5520
diff changeset
   181
    JavacFileManager createFileManager(boolean useOptimedZipIndex) {
d3380b1e4779 7018859: javac turn off the Zip optimization by default
ksrini
parents: 5520
diff changeset
   182
        Context ctx = new Context();
d3380b1e4779 7018859: javac turn off the Zip optimization by default
ksrini
parents: 5520
diff changeset
   183
        if (useOptimedZipIndex) {
d3380b1e4779 7018859: javac turn off the Zip optimization by default
ksrini
parents: 5520
diff changeset
   184
            Options options = Options.instance(ctx);
d3380b1e4779 7018859: javac turn off the Zip optimization by default
ksrini
parents: 5520
diff changeset
   185
            options.put("useOptimizedZip", "true");
4073
9788f4549740 6838467: JSR199 FileObjects don't obey general contract of equals.
jjg
parents:
diff changeset
   186
        }
8432
d3380b1e4779 7018859: javac turn off the Zip optimization by default
ksrini
parents: 5520
diff changeset
   187
        return new JavacFileManager(ctx, false, null);
4073
9788f4549740 6838467: JSR199 FileObjects don't obey general contract of equals.
jjg
parents:
diff changeset
   188
    }
9788f4549740 6838467: JSR199 FileObjects don't obey general contract of equals.
jjg
parents:
diff changeset
   189
9788f4549740 6838467: JSR199 FileObjects don't obey general contract of equals.
jjg
parents:
diff changeset
   190
    // create a directory containing a given set of paths
9788f4549740 6838467: JSR199 FileObjects don't obey general contract of equals.
jjg
parents:
diff changeset
   191
    void createTestDir(File dir, String[] paths) throws IOException {
9788f4549740 6838467: JSR199 FileObjects don't obey general contract of equals.
jjg
parents:
diff changeset
   192
        for (String p: paths) {
9788f4549740 6838467: JSR199 FileObjects don't obey general contract of equals.
jjg
parents:
diff changeset
   193
            File file = new File(dir, p);
9788f4549740 6838467: JSR199 FileObjects don't obey general contract of equals.
jjg
parents:
diff changeset
   194
            file.getParentFile().mkdirs();
9788f4549740 6838467: JSR199 FileObjects don't obey general contract of equals.
jjg
parents:
diff changeset
   195
            FileWriter out = new FileWriter(file);
9788f4549740 6838467: JSR199 FileObjects don't obey general contract of equals.
jjg
parents:
diff changeset
   196
            try {
9788f4549740 6838467: JSR199 FileObjects don't obey general contract of equals.
jjg
parents:
diff changeset
   197
                out.write(p);
9788f4549740 6838467: JSR199 FileObjects don't obey general contract of equals.
jjg
parents:
diff changeset
   198
            } finally {
9788f4549740 6838467: JSR199 FileObjects don't obey general contract of equals.
jjg
parents:
diff changeset
   199
                out.close();
9788f4549740 6838467: JSR199 FileObjects don't obey general contract of equals.
jjg
parents:
diff changeset
   200
            }
9788f4549740 6838467: JSR199 FileObjects don't obey general contract of equals.
jjg
parents:
diff changeset
   201
        }
9788f4549740 6838467: JSR199 FileObjects don't obey general contract of equals.
jjg
parents:
diff changeset
   202
    }
9788f4549740 6838467: JSR199 FileObjects don't obey general contract of equals.
jjg
parents:
diff changeset
   203
9788f4549740 6838467: JSR199 FileObjects don't obey general contract of equals.
jjg
parents:
diff changeset
   204
    // create a sip file containing a given set of entries
9788f4549740 6838467: JSR199 FileObjects don't obey general contract of equals.
jjg
parents:
diff changeset
   205
    void createTestZip(File zip, String[] paths) throws IOException {
9788f4549740 6838467: JSR199 FileObjects don't obey general contract of equals.
jjg
parents:
diff changeset
   206
        if (zip.getParentFile() != null)
9788f4549740 6838467: JSR199 FileObjects don't obey general contract of equals.
jjg
parents:
diff changeset
   207
            zip.getParentFile().mkdirs();
9788f4549740 6838467: JSR199 FileObjects don't obey general contract of equals.
jjg
parents:
diff changeset
   208
        ZipOutputStream zos = new ZipOutputStream(new FileOutputStream(zip));
9788f4549740 6838467: JSR199 FileObjects don't obey general contract of equals.
jjg
parents:
diff changeset
   209
        try {
9788f4549740 6838467: JSR199 FileObjects don't obey general contract of equals.
jjg
parents:
diff changeset
   210
            for (String p: paths) {
9788f4549740 6838467: JSR199 FileObjects don't obey general contract of equals.
jjg
parents:
diff changeset
   211
                ZipEntry ze = new ZipEntry(p);
9788f4549740 6838467: JSR199 FileObjects don't obey general contract of equals.
jjg
parents:
diff changeset
   212
                zos.putNextEntry(ze);
9788f4549740 6838467: JSR199 FileObjects don't obey general contract of equals.
jjg
parents:
diff changeset
   213
                byte[] bytes = p.getBytes();
9788f4549740 6838467: JSR199 FileObjects don't obey general contract of equals.
jjg
parents:
diff changeset
   214
                zos.write(bytes, 0, bytes.length);
9788f4549740 6838467: JSR199 FileObjects don't obey general contract of equals.
jjg
parents:
diff changeset
   215
                zos.closeEntry();
9788f4549740 6838467: JSR199 FileObjects don't obey general contract of equals.
jjg
parents:
diff changeset
   216
            }
9788f4549740 6838467: JSR199 FileObjects don't obey general contract of equals.
jjg
parents:
diff changeset
   217
        } finally {
9788f4549740 6838467: JSR199 FileObjects don't obey general contract of equals.
jjg
parents:
diff changeset
   218
            zos.close();
9788f4549740 6838467: JSR199 FileObjects don't obey general contract of equals.
jjg
parents:
diff changeset
   219
        }
9788f4549740 6838467: JSR199 FileObjects don't obey general contract of equals.
jjg
parents:
diff changeset
   220
    }
9788f4549740 6838467: JSR199 FileObjects don't obey general contract of equals.
jjg
parents:
diff changeset
   221
9788f4549740 6838467: JSR199 FileObjects don't obey general contract of equals.
jjg
parents:
diff changeset
   222
    void error(String msg) {
9788f4549740 6838467: JSR199 FileObjects don't obey general contract of equals.
jjg
parents:
diff changeset
   223
        System.err.println("Error: " + msg);
9788f4549740 6838467: JSR199 FileObjects don't obey general contract of equals.
jjg
parents:
diff changeset
   224
        errors++;
9788f4549740 6838467: JSR199 FileObjects don't obey general contract of equals.
jjg
parents:
diff changeset
   225
    }
9788f4549740 6838467: JSR199 FileObjects don't obey general contract of equals.
jjg
parents:
diff changeset
   226
9788f4549740 6838467: JSR199 FileObjects don't obey general contract of equals.
jjg
parents:
diff changeset
   227
    int count;
9788f4549740 6838467: JSR199 FileObjects don't obey general contract of equals.
jjg
parents:
diff changeset
   228
    int errors;
9788f4549740 6838467: JSR199 FileObjects don't obey general contract of equals.
jjg
parents:
diff changeset
   229
    Set<String> foundClasses = new HashSet<String>();
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