author | avstepan |
Tue, 19 May 2015 16:04:14 +0400 | |
changeset 30655 | d83f50188ca9 |
parent 11318 | e114b7d53b9b |
child 30730 | d3ce7619db2c |
permissions | -rw-r--r-- |
4073
9788f4549740
6838467: JSR199 FileObjects don't obey general contract of equals.
jjg
parents:
diff
changeset
|
1 |
/* |
9744
3e48977e539d
7044486: open jdk repos have files with incorrect copyright headers, which can end up in src bundles
katleman
parents:
8837
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 | 19 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
20 |
* or visit www.oracle.com if you need additional information or have any |
|
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; |
9788f4549740
6838467: JSR199 FileObjects don't obey general contract of equals.
jjg
parents:
diff
changeset
|
35 |
import com.sun.tools.javac.util.Context; |
8432
d3380b1e4779
7018859: javac turn off the Zip optimization by default
ksrini
parents:
5520
diff
changeset
|
36 |
import com.sun.tools.javac.util.Options; |
4073
9788f4549740
6838467: JSR199 FileObjects don't obey general contract of equals.
jjg
parents:
diff
changeset
|
37 |
|
9788f4549740
6838467: JSR199 FileObjects don't obey general contract of equals.
jjg
parents:
diff
changeset
|
38 |
public class T6838467 { |
9788f4549740
6838467: JSR199 FileObjects don't obey general contract of equals.
jjg
parents:
diff
changeset
|
39 |
boolean fileSystemIsCaseSignificant = !new File("a").equals(new File("A")); |
9788f4549740
6838467: JSR199 FileObjects don't obey general contract of equals.
jjg
parents:
diff
changeset
|
40 |
|
9788f4549740
6838467: JSR199 FileObjects don't obey general contract of equals.
jjg
parents:
diff
changeset
|
41 |
enum FileKind { |
9788f4549740
6838467: JSR199 FileObjects don't obey general contract of equals.
jjg
parents:
diff
changeset
|
42 |
DIR("dir"), |
9788f4549740
6838467: JSR199 FileObjects don't obey general contract of equals.
jjg
parents:
diff
changeset
|
43 |
ZIP("zip"), |
9788f4549740
6838467: JSR199 FileObjects don't obey general contract of equals.
jjg
parents:
diff
changeset
|
44 |
ZIPFILEINDEX("zip"); |
9788f4549740
6838467: JSR199 FileObjects don't obey general contract of equals.
jjg
parents:
diff
changeset
|
45 |
FileKind(String path) { |
9788f4549740
6838467: JSR199 FileObjects don't obey general contract of equals.
jjg
parents:
diff
changeset
|
46 |
file = new File(path); |
9788f4549740
6838467: JSR199 FileObjects don't obey general contract of equals.
jjg
parents:
diff
changeset
|
47 |
} |
9788f4549740
6838467: JSR199 FileObjects don't obey general contract of equals.
jjg
parents:
diff
changeset
|
48 |
final File file; |
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 |
|
9788f4549740
6838467: JSR199 FileObjects don't obey general contract of equals.
jjg
parents:
diff
changeset
|
51 |
enum CompareKind { |
9788f4549740
6838467: JSR199 FileObjects don't obey general contract of equals.
jjg
parents:
diff
changeset
|
52 |
SAME { |
9788f4549740
6838467: JSR199 FileObjects don't obey general contract of equals.
jjg
parents:
diff
changeset
|
53 |
File other(File f) { return f; } |
9788f4549740
6838467: JSR199 FileObjects don't obey general contract of equals.
jjg
parents:
diff
changeset
|
54 |
}, |
9788f4549740
6838467: JSR199 FileObjects don't obey general contract of equals.
jjg
parents:
diff
changeset
|
55 |
ABSOLUTE { |
9788f4549740
6838467: JSR199 FileObjects don't obey general contract of equals.
jjg
parents:
diff
changeset
|
56 |
File other(File f) { return f.getAbsoluteFile(); } |
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 |
DIFFERENT { |
9788f4549740
6838467: JSR199 FileObjects don't obey general contract of equals.
jjg
parents:
diff
changeset
|
59 |
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
|
60 |
}, |
9788f4549740
6838467: JSR199 FileObjects don't obey general contract of equals.
jjg
parents:
diff
changeset
|
61 |
CASEEQUIV { |
9788f4549740
6838467: JSR199 FileObjects don't obey general contract of equals.
jjg
parents:
diff
changeset
|
62 |
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
|
63 |
}; |
9788f4549740
6838467: JSR199 FileObjects don't obey general contract of equals.
jjg
parents:
diff
changeset
|
64 |
abstract File other(File f); |
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 |
|
9788f4549740
6838467: JSR199 FileObjects don't obey general contract of equals.
jjg
parents:
diff
changeset
|
67 |
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
|
68 |
|
9788f4549740
6838467: JSR199 FileObjects don't obey general contract of equals.
jjg
parents:
diff
changeset
|
69 |
public static void main(String... args) throws Exception { |
9788f4549740
6838467: JSR199 FileObjects don't obey general contract of equals.
jjg
parents:
diff
changeset
|
70 |
new T6838467().run(); |
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 |
void run() throws Exception { |
9788f4549740
6838467: JSR199 FileObjects don't obey general contract of equals.
jjg
parents:
diff
changeset
|
74 |
// on Windows, verify file system is not case significant |
9788f4549740
6838467: JSR199 FileObjects don't obey general contract of equals.
jjg
parents:
diff
changeset
|
75 |
if (System.getProperty("os.name").toLowerCase().startsWith("windows") |
9788f4549740
6838467: JSR199 FileObjects don't obey general contract of equals.
jjg
parents:
diff
changeset
|
76 |
&& fileSystemIsCaseSignificant) { |
9788f4549740
6838467: JSR199 FileObjects don't obey general contract of equals.
jjg
parents:
diff
changeset
|
77 |
error("fileSystemIsCaseSignificant is set on Windows."); |
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 |
|
9788f4549740
6838467: JSR199 FileObjects don't obey general contract of equals.
jjg
parents:
diff
changeset
|
80 |
// 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
|
81 |
createTestDir(new File("dir"), paths); |
9788f4549740
6838467: JSR199 FileObjects don't obey general contract of equals.
jjg
parents:
diff
changeset
|
82 |
createTestDir(new File("not_dir"), paths); |
9788f4549740
6838467: JSR199 FileObjects don't obey general contract of equals.
jjg
parents:
diff
changeset
|
83 |
createTestZip(new File("zip"), paths); |
9788f4549740
6838467: JSR199 FileObjects don't obey general contract of equals.
jjg
parents:
diff
changeset
|
84 |
createTestZip(new File("not_zip"), paths); |
9788f4549740
6838467: JSR199 FileObjects don't obey general contract of equals.
jjg
parents:
diff
changeset
|
85 |
if (fileSystemIsCaseSignificant) { |
9788f4549740
6838467: JSR199 FileObjects don't obey general contract of equals.
jjg
parents:
diff
changeset
|
86 |
createTestDir(new File("DIR"), paths); |
9788f4549740
6838467: JSR199 FileObjects don't obey general contract of equals.
jjg
parents:
diff
changeset
|
87 |
createTestZip(new File("ZIP"), paths); |
9788f4549740
6838467: JSR199 FileObjects don't obey general contract of equals.
jjg
parents:
diff
changeset
|
88 |
} |
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 |
// 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
|
91 |
// 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
|
92 |
for (FileKind fk: FileKind.values()) { |
9788f4549740
6838467: JSR199 FileObjects don't obey general contract of equals.
jjg
parents:
diff
changeset
|
93 |
for (CompareKind ck: CompareKind.values()) { |
9788f4549740
6838467: JSR199 FileObjects don't obey general contract of equals.
jjg
parents:
diff
changeset
|
94 |
test(fk, ck); |
9788f4549740
6838467: JSR199 FileObjects don't obey general contract of equals.
jjg
parents:
diff
changeset
|
95 |
} |
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 |
// 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
|
99 |
// tested |
9788f4549740
6838467: JSR199 FileObjects don't obey general contract of equals.
jjg
parents:
diff
changeset
|
100 |
Set<String> expectClasses = new HashSet<String>(Arrays.asList( |
9788f4549740
6838467: JSR199 FileObjects don't obey general contract of equals.
jjg
parents:
diff
changeset
|
101 |
"RegularFileObject", "ZipFileObject", "ZipFileIndexFileObject" )); |
9788f4549740
6838467: JSR199 FileObjects don't obey general contract of equals.
jjg
parents:
diff
changeset
|
102 |
if (!foundClasses.equals(expectClasses)) { |
9788f4549740
6838467: JSR199 FileObjects don't obey general contract of equals.
jjg
parents:
diff
changeset
|
103 |
error("expected fileobject classes not found\n" |
9788f4549740
6838467: JSR199 FileObjects don't obey general contract of equals.
jjg
parents:
diff
changeset
|
104 |
+ "expected: " + expectClasses + "\n" |
9788f4549740
6838467: JSR199 FileObjects don't obey general contract of equals.
jjg
parents:
diff
changeset
|
105 |
+ "found: " + foundClasses); |
9788f4549740
6838467: JSR199 FileObjects don't obey general contract of equals.
jjg
parents:
diff
changeset
|
106 |
} |
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 |
if (errors > 0) |
9788f4549740
6838467: JSR199 FileObjects don't obey general contract of equals.
jjg
parents:
diff
changeset
|
109 |
throw new Exception(errors + " errors"); |
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 |
|
9788f4549740
6838467: JSR199 FileObjects don't obey general contract of equals.
jjg
parents:
diff
changeset
|
112 |
void test(FileKind fk, CompareKind ck) throws IOException { |
9788f4549740
6838467: JSR199 FileObjects don't obey general contract of equals.
jjg
parents:
diff
changeset
|
113 |
File f1 = fk.file; |
9788f4549740
6838467: JSR199 FileObjects don't obey general contract of equals.
jjg
parents:
diff
changeset
|
114 |
JavaFileManager fm1 = createFileManager(fk, f1); |
9788f4549740
6838467: JSR199 FileObjects don't obey general contract of equals.
jjg
parents:
diff
changeset
|
115 |
|
9788f4549740
6838467: JSR199 FileObjects don't obey general contract of equals.
jjg
parents:
diff
changeset
|
116 |
File f2 = ck.other(fk.file); |
9788f4549740
6838467: JSR199 FileObjects don't obey general contract of equals.
jjg
parents:
diff
changeset
|
117 |
JavaFileManager fm2 = createFileManager(fk, f2); |
9788f4549740
6838467: JSR199 FileObjects don't obey general contract of equals.
jjg
parents:
diff
changeset
|
118 |
|
9788f4549740
6838467: JSR199 FileObjects don't obey general contract of equals.
jjg
parents:
diff
changeset
|
119 |
try { |
9788f4549740
6838467: JSR199 FileObjects don't obey general contract of equals.
jjg
parents:
diff
changeset
|
120 |
// 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
|
121 |
// 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
|
122 |
// entries in the the directories or zip files. |
9788f4549740
6838467: JSR199 FileObjects don't obey general contract of equals.
jjg
parents:
diff
changeset
|
123 |
// 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
|
124 |
// 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
|
125 |
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
|
126 |
|
9788f4549740
6838467: JSR199 FileObjects don't obey general contract of equals.
jjg
parents:
diff
changeset
|
127 |
System.err.println("test " + (++count) + " " + fk + " " + ck + " " + f1 + " " + f2); |
9788f4549740
6838467: JSR199 FileObjects don't obey general contract of equals.
jjg
parents:
diff
changeset
|
128 |
test(fm1, fm2, expect); |
9788f4549740
6838467: JSR199 FileObjects don't obey general contract of equals.
jjg
parents:
diff
changeset
|
129 |
|
9788f4549740
6838467: JSR199 FileObjects don't obey general contract of equals.
jjg
parents:
diff
changeset
|
130 |
} finally { |
9788f4549740
6838467: JSR199 FileObjects don't obey general contract of equals.
jjg
parents:
diff
changeset
|
131 |
fm1.close(); |
9788f4549740
6838467: JSR199 FileObjects don't obey general contract of equals.
jjg
parents:
diff
changeset
|
132 |
fm2.close(); |
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 |
} |
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 |
// 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
|
137 |
// 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
|
138 |
// 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
|
139 |
// 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
|
140 |
// expected number of matches was found. |
9788f4549740
6838467: JSR199 FileObjects don't obey general contract of equals.
jjg
parents:
diff
changeset
|
141 |
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
|
142 |
boolean foundFiles1 = false; |
9788f4549740
6838467: JSR199 FileObjects don't obey general contract of equals.
jjg
parents:
diff
changeset
|
143 |
boolean foundFiles2 = false; |
9788f4549740
6838467: JSR199 FileObjects don't obey general contract of equals.
jjg
parents:
diff
changeset
|
144 |
int foundEqualCount = 0; |
9788f4549740
6838467: JSR199 FileObjects don't obey general contract of equals.
jjg
parents:
diff
changeset
|
145 |
Set<JavaFileObject.Kind> kinds = EnumSet.allOf(JavaFileObject.Kind.class); |
9788f4549740
6838467: JSR199 FileObjects don't obey general contract of equals.
jjg
parents:
diff
changeset
|
146 |
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
|
147 |
foundFiles1 = true; |
9788f4549740
6838467: JSR199 FileObjects don't obey general contract of equals.
jjg
parents:
diff
changeset
|
148 |
foundClasses.add(fo1.getClass().getSimpleName()); |
9788f4549740
6838467: JSR199 FileObjects don't obey general contract of equals.
jjg
parents:
diff
changeset
|
149 |
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
|
150 |
foundFiles2 = true; |
9788f4549740
6838467: JSR199 FileObjects don't obey general contract of equals.
jjg
parents:
diff
changeset
|
151 |
foundClasses.add(fo1.getClass().getSimpleName()); |
9788f4549740
6838467: JSR199 FileObjects don't obey general contract of equals.
jjg
parents:
diff
changeset
|
152 |
System.err.println("compare " + fo1 + " " + fo2); |
9788f4549740
6838467: JSR199 FileObjects don't obey general contract of equals.
jjg
parents:
diff
changeset
|
153 |
if (fo1.equals(fo2)) { |
9788f4549740
6838467: JSR199 FileObjects don't obey general contract of equals.
jjg
parents:
diff
changeset
|
154 |
foundEqualCount++; |
9788f4549740
6838467: JSR199 FileObjects don't obey general contract of equals.
jjg
parents:
diff
changeset
|
155 |
int hash1 = fo1.hashCode(); |
9788f4549740
6838467: JSR199 FileObjects don't obey general contract of equals.
jjg
parents:
diff
changeset
|
156 |
int hash2 = fo2.hashCode(); |
9788f4549740
6838467: JSR199 FileObjects don't obey general contract of equals.
jjg
parents:
diff
changeset
|
157 |
if (hash1 != hash2) |
9788f4549740
6838467: JSR199 FileObjects don't obey general contract of equals.
jjg
parents:
diff
changeset
|
158 |
error("hashCode error: " + fo1 + " [" + hash1 + "] " |
9788f4549740
6838467: JSR199 FileObjects don't obey general contract of equals.
jjg
parents:
diff
changeset
|
159 |
+ fo2 + " [" + hash2 + "]"); |
9788f4549740
6838467: JSR199 FileObjects don't obey general contract of equals.
jjg
parents:
diff
changeset
|
160 |
} |
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 |
if (!foundFiles1) |
9788f4549740
6838467: JSR199 FileObjects don't obey general contract of equals.
jjg
parents:
diff
changeset
|
164 |
error("no files found for file manager 1"); |
9788f4549740
6838467: JSR199 FileObjects don't obey general contract of equals.
jjg
parents:
diff
changeset
|
165 |
if (!foundFiles2) |
9788f4549740
6838467: JSR199 FileObjects don't obey general contract of equals.
jjg
parents:
diff
changeset
|
166 |
error("no files found for file manager 2"); |
9788f4549740
6838467: JSR199 FileObjects don't obey general contract of equals.
jjg
parents:
diff
changeset
|
167 |
// verify the expected number of matches were found |
9788f4549740
6838467: JSR199 FileObjects don't obey general contract of equals.
jjg
parents:
diff
changeset
|
168 |
if (foundEqualCount != expectEqualCount) |
9788f4549740
6838467: JSR199 FileObjects don't obey general contract of equals.
jjg
parents:
diff
changeset
|
169 |
error("expected matches not found: expected " + expectEqualCount + ", found " + foundEqualCount); |
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 |
// 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
|
173 |
// or zip file placed on the classpath |
9788f4549740
6838467: JSR199 FileObjects don't obey general contract of equals.
jjg
parents:
diff
changeset
|
174 |
JavaFileManager createFileManager(FileKind fk, File classpath) throws IOException { |
9788f4549740
6838467: JSR199 FileObjects don't obey general contract of equals.
jjg
parents:
diff
changeset
|
175 |
StandardJavaFileManager fm = createFileManager(fk == FileKind.ZIP); |
9788f4549740
6838467: JSR199 FileObjects don't obey general contract of equals.
jjg
parents:
diff
changeset
|
176 |
fm.setLocation(StandardLocation.CLASS_PATH, Arrays.asList(classpath)); |
9788f4549740
6838467: JSR199 FileObjects don't obey general contract of equals.
jjg
parents:
diff
changeset
|
177 |
return fm; |
9788f4549740
6838467: JSR199 FileObjects don't obey general contract of equals.
jjg
parents:
diff
changeset
|
178 |
} |
9788f4549740
6838467: JSR199 FileObjects don't obey general contract of equals.
jjg
parents:
diff
changeset
|
179 |
|
8837 | 180 |
JavacFileManager createFileManager(boolean useOptimizedZip) { |
8432
d3380b1e4779
7018859: javac turn off the Zip optimization by default
ksrini
parents:
5520
diff
changeset
|
181 |
Context ctx = new Context(); |
8837 | 182 |
Options options = Options.instance(ctx); |
183 |
options.put("useOptimizedZip", Boolean.toString(useOptimizedZip)); |
|
8432
d3380b1e4779
7018859: javac turn off the Zip optimization by default
ksrini
parents:
5520
diff
changeset
|
184 |
return new JavacFileManager(ctx, false, null); |
4073
9788f4549740
6838467: JSR199 FileObjects don't obey general contract of equals.
jjg
parents:
diff
changeset
|
185 |
} |
9788f4549740
6838467: JSR199 FileObjects don't obey general contract of equals.
jjg
parents:
diff
changeset
|
186 |
|
9788f4549740
6838467: JSR199 FileObjects don't obey general contract of equals.
jjg
parents:
diff
changeset
|
187 |
// create a directory containing a given set of paths |
9788f4549740
6838467: JSR199 FileObjects don't obey general contract of equals.
jjg
parents:
diff
changeset
|
188 |
void createTestDir(File dir, String[] paths) throws IOException { |
9788f4549740
6838467: JSR199 FileObjects don't obey general contract of equals.
jjg
parents:
diff
changeset
|
189 |
for (String p: paths) { |
9788f4549740
6838467: JSR199 FileObjects don't obey general contract of equals.
jjg
parents:
diff
changeset
|
190 |
File file = new File(dir, p); |
9788f4549740
6838467: JSR199 FileObjects don't obey general contract of equals.
jjg
parents:
diff
changeset
|
191 |
file.getParentFile().mkdirs(); |
9788f4549740
6838467: JSR199 FileObjects don't obey general contract of equals.
jjg
parents:
diff
changeset
|
192 |
FileWriter out = new FileWriter(file); |
9788f4549740
6838467: JSR199 FileObjects don't obey general contract of equals.
jjg
parents:
diff
changeset
|
193 |
try { |
9788f4549740
6838467: JSR199 FileObjects don't obey general contract of equals.
jjg
parents:
diff
changeset
|
194 |
out.write(p); |
9788f4549740
6838467: JSR199 FileObjects don't obey general contract of equals.
jjg
parents:
diff
changeset
|
195 |
} finally { |
9788f4549740
6838467: JSR199 FileObjects don't obey general contract of equals.
jjg
parents:
diff
changeset
|
196 |
out.close(); |
9788f4549740
6838467: JSR199 FileObjects don't obey general contract of equals.
jjg
parents:
diff
changeset
|
197 |
} |
9788f4549740
6838467: JSR199 FileObjects don't obey general contract of equals.
jjg
parents:
diff
changeset
|
198 |
} |
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 |
|
9788f4549740
6838467: JSR199 FileObjects don't obey general contract of equals.
jjg
parents:
diff
changeset
|
201 |
// 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
|
202 |
void createTestZip(File zip, String[] paths) throws IOException { |
9788f4549740
6838467: JSR199 FileObjects don't obey general contract of equals.
jjg
parents:
diff
changeset
|
203 |
if (zip.getParentFile() != null) |
9788f4549740
6838467: JSR199 FileObjects don't obey general contract of equals.
jjg
parents:
diff
changeset
|
204 |
zip.getParentFile().mkdirs(); |
9788f4549740
6838467: JSR199 FileObjects don't obey general contract of equals.
jjg
parents:
diff
changeset
|
205 |
ZipOutputStream zos = new ZipOutputStream(new FileOutputStream(zip)); |
9788f4549740
6838467: JSR199 FileObjects don't obey general contract of equals.
jjg
parents:
diff
changeset
|
206 |
try { |
9788f4549740
6838467: JSR199 FileObjects don't obey general contract of equals.
jjg
parents:
diff
changeset
|
207 |
for (String p: paths) { |
9788f4549740
6838467: JSR199 FileObjects don't obey general contract of equals.
jjg
parents:
diff
changeset
|
208 |
ZipEntry ze = new ZipEntry(p); |
9788f4549740
6838467: JSR199 FileObjects don't obey general contract of equals.
jjg
parents:
diff
changeset
|
209 |
zos.putNextEntry(ze); |
9788f4549740
6838467: JSR199 FileObjects don't obey general contract of equals.
jjg
parents:
diff
changeset
|
210 |
byte[] bytes = p.getBytes(); |
9788f4549740
6838467: JSR199 FileObjects don't obey general contract of equals.
jjg
parents:
diff
changeset
|
211 |
zos.write(bytes, 0, bytes.length); |
9788f4549740
6838467: JSR199 FileObjects don't obey general contract of equals.
jjg
parents:
diff
changeset
|
212 |
zos.closeEntry(); |
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 |
} finally { |
9788f4549740
6838467: JSR199 FileObjects don't obey general contract of equals.
jjg
parents:
diff
changeset
|
215 |
zos.close(); |
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 |
} |
9788f4549740
6838467: JSR199 FileObjects don't obey general contract of equals.
jjg
parents:
diff
changeset
|
218 |
|
9788f4549740
6838467: JSR199 FileObjects don't obey general contract of equals.
jjg
parents:
diff
changeset
|
219 |
void error(String msg) { |
9788f4549740
6838467: JSR199 FileObjects don't obey general contract of equals.
jjg
parents:
diff
changeset
|
220 |
System.err.println("Error: " + msg); |
9788f4549740
6838467: JSR199 FileObjects don't obey general contract of equals.
jjg
parents:
diff
changeset
|
221 |
errors++; |
9788f4549740
6838467: JSR199 FileObjects don't obey general contract of equals.
jjg
parents:
diff
changeset
|
222 |
} |
9788f4549740
6838467: JSR199 FileObjects don't obey general contract of equals.
jjg
parents:
diff
changeset
|
223 |
|
9788f4549740
6838467: JSR199 FileObjects don't obey general contract of equals.
jjg
parents:
diff
changeset
|
224 |
int count; |
9788f4549740
6838467: JSR199 FileObjects don't obey general contract of equals.
jjg
parents:
diff
changeset
|
225 |
int errors; |
9788f4549740
6838467: JSR199 FileObjects don't obey general contract of equals.
jjg
parents:
diff
changeset
|
226 |
Set<String> foundClasses = new HashSet<String>(); |
9788f4549740
6838467: JSR199 FileObjects don't obey general contract of equals.
jjg
parents:
diff
changeset
|
227 |
} |
9788f4549740
6838467: JSR199 FileObjects don't obey general contract of equals.
jjg
parents:
diff
changeset
|
228 |