author | peterz |
Fri, 28 May 2010 13:32:40 +0400 | |
changeset 5594 | 3db39773da2e |
parent 4073 | 9788f4549740 |
child 5520 | 86e4b9a9da40 |
permissions | -rw-r--r-- |
4073
9788f4549740
6838467: JSR199 FileObjects don't obey general contract of equals.
jjg
parents:
diff
changeset
|
1 |
/* |
9788f4549740
6838467: JSR199 FileObjects don't obey general contract of equals.
jjg
parents:
diff
changeset
|
2 |
* Copyright 2009 Sun Microsystems, Inc. All Rights Reserved. |
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 |
* |
9788f4549740
6838467: JSR199 FileObjects don't obey general contract of equals.
jjg
parents:
diff
changeset
|
19 |
* Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, |
9788f4549740
6838467: JSR199 FileObjects don't obey general contract of equals.
jjg
parents:
diff
changeset
|
20 |
* CA 95054 USA or visit www.sun.com if you need additional information or |
9788f4549740
6838467: JSR199 FileObjects don't obey general contract of equals.
jjg
parents:
diff
changeset
|
21 |
* have any questions. |
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; |
9788f4549740
6838467: JSR199 FileObjects don't obey general contract of equals.
jjg
parents:
diff
changeset
|
36 |
|
9788f4549740
6838467: JSR199 FileObjects don't obey general contract of equals.
jjg
parents:
diff
changeset
|
37 |
public class T6838467 { |
9788f4549740
6838467: JSR199 FileObjects don't obey general contract of equals.
jjg
parents:
diff
changeset
|
38 |
boolean fileSystemIsCaseSignificant = !new File("a").equals(new File("A")); |
9788f4549740
6838467: JSR199 FileObjects don't obey general contract of equals.
jjg
parents:
diff
changeset
|
39 |
|
9788f4549740
6838467: JSR199 FileObjects don't obey general contract of equals.
jjg
parents:
diff
changeset
|
40 |
enum FileKind { |
9788f4549740
6838467: JSR199 FileObjects don't obey general contract of equals.
jjg
parents:
diff
changeset
|
41 |
DIR("dir"), |
9788f4549740
6838467: JSR199 FileObjects don't obey general contract of equals.
jjg
parents:
diff
changeset
|
42 |
ZIP("zip"), |
9788f4549740
6838467: JSR199 FileObjects don't obey general contract of equals.
jjg
parents:
diff
changeset
|
43 |
ZIPFILEINDEX("zip"); |
9788f4549740
6838467: JSR199 FileObjects don't obey general contract of equals.
jjg
parents:
diff
changeset
|
44 |
FileKind(String path) { |
9788f4549740
6838467: JSR199 FileObjects don't obey general contract of equals.
jjg
parents:
diff
changeset
|
45 |
file = new File(path); |
9788f4549740
6838467: JSR199 FileObjects don't obey general contract of equals.
jjg
parents:
diff
changeset
|
46 |
} |
9788f4549740
6838467: JSR199 FileObjects don't obey general contract of equals.
jjg
parents:
diff
changeset
|
47 |
final File file; |
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 |
|
9788f4549740
6838467: JSR199 FileObjects don't obey general contract of equals.
jjg
parents:
diff
changeset
|
50 |
enum CompareKind { |
9788f4549740
6838467: JSR199 FileObjects don't obey general contract of equals.
jjg
parents:
diff
changeset
|
51 |
SAME { |
9788f4549740
6838467: JSR199 FileObjects don't obey general contract of equals.
jjg
parents:
diff
changeset
|
52 |
File other(File f) { return f; } |
9788f4549740
6838467: JSR199 FileObjects don't obey general contract of equals.
jjg
parents:
diff
changeset
|
53 |
}, |
9788f4549740
6838467: JSR199 FileObjects don't obey general contract of equals.
jjg
parents:
diff
changeset
|
54 |
ABSOLUTE { |
9788f4549740
6838467: JSR199 FileObjects don't obey general contract of equals.
jjg
parents:
diff
changeset
|
55 |
File other(File f) { return f.getAbsoluteFile(); } |
9788f4549740
6838467: JSR199 FileObjects don't obey general contract of equals.
jjg
parents:
diff
changeset
|
56 |
}, |
9788f4549740
6838467: JSR199 FileObjects don't obey general contract of equals.
jjg
parents:
diff
changeset
|
57 |
DIFFERENT { |
9788f4549740
6838467: JSR199 FileObjects don't obey general contract of equals.
jjg
parents:
diff
changeset
|
58 |
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
|
59 |
}, |
9788f4549740
6838467: JSR199 FileObjects don't obey general contract of equals.
jjg
parents:
diff
changeset
|
60 |
CASEEQUIV { |
9788f4549740
6838467: JSR199 FileObjects don't obey general contract of equals.
jjg
parents:
diff
changeset
|
61 |
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
|
62 |
}; |
9788f4549740
6838467: JSR199 FileObjects don't obey general contract of equals.
jjg
parents:
diff
changeset
|
63 |
abstract File other(File f); |
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 |
|
9788f4549740
6838467: JSR199 FileObjects don't obey general contract of equals.
jjg
parents:
diff
changeset
|
66 |
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
|
67 |
|
9788f4549740
6838467: JSR199 FileObjects don't obey general contract of equals.
jjg
parents:
diff
changeset
|
68 |
public static void main(String... args) throws Exception { |
9788f4549740
6838467: JSR199 FileObjects don't obey general contract of equals.
jjg
parents:
diff
changeset
|
69 |
new T6838467().run(); |
9788f4549740
6838467: JSR199 FileObjects don't obey general contract of equals.
jjg
parents:
diff
changeset
|
70 |
} |
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 |
void run() throws Exception { |
9788f4549740
6838467: JSR199 FileObjects don't obey general contract of equals.
jjg
parents:
diff
changeset
|
73 |
// on Windows, verify file system is not case significant |
9788f4549740
6838467: JSR199 FileObjects don't obey general contract of equals.
jjg
parents:
diff
changeset
|
74 |
if (System.getProperty("os.name").toLowerCase().startsWith("windows") |
9788f4549740
6838467: JSR199 FileObjects don't obey general contract of equals.
jjg
parents:
diff
changeset
|
75 |
&& fileSystemIsCaseSignificant) { |
9788f4549740
6838467: JSR199 FileObjects don't obey general contract of equals.
jjg
parents:
diff
changeset
|
76 |
error("fileSystemIsCaseSignificant is set on Windows."); |
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 |
// 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
|
80 |
createTestDir(new File("dir"), paths); |
9788f4549740
6838467: JSR199 FileObjects don't obey general contract of equals.
jjg
parents:
diff
changeset
|
81 |
createTestDir(new File("not_dir"), paths); |
9788f4549740
6838467: JSR199 FileObjects don't obey general contract of equals.
jjg
parents:
diff
changeset
|
82 |
createTestZip(new File("zip"), paths); |
9788f4549740
6838467: JSR199 FileObjects don't obey general contract of equals.
jjg
parents:
diff
changeset
|
83 |
createTestZip(new File("not_zip"), paths); |
9788f4549740
6838467: JSR199 FileObjects don't obey general contract of equals.
jjg
parents:
diff
changeset
|
84 |
if (fileSystemIsCaseSignificant) { |
9788f4549740
6838467: JSR199 FileObjects don't obey general contract of equals.
jjg
parents:
diff
changeset
|
85 |
createTestDir(new File("DIR"), paths); |
9788f4549740
6838467: JSR199 FileObjects don't obey general contract of equals.
jjg
parents:
diff
changeset
|
86 |
createTestZip(new File("ZIP"), paths); |
9788f4549740
6838467: JSR199 FileObjects don't obey general contract of equals.
jjg
parents:
diff
changeset
|
87 |
} |
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 |
// 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
|
90 |
// 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
|
91 |
for (FileKind fk: FileKind.values()) { |
9788f4549740
6838467: JSR199 FileObjects don't obey general contract of equals.
jjg
parents:
diff
changeset
|
92 |
for (CompareKind ck: CompareKind.values()) { |
9788f4549740
6838467: JSR199 FileObjects don't obey general contract of equals.
jjg
parents:
diff
changeset
|
93 |
test(fk, ck); |
9788f4549740
6838467: JSR199 FileObjects don't obey general contract of equals.
jjg
parents:
diff
changeset
|
94 |
} |
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 |
// 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
|
98 |
// tested |
9788f4549740
6838467: JSR199 FileObjects don't obey general contract of equals.
jjg
parents:
diff
changeset
|
99 |
Set<String> expectClasses = new HashSet<String>(Arrays.asList( |
9788f4549740
6838467: JSR199 FileObjects don't obey general contract of equals.
jjg
parents:
diff
changeset
|
100 |
"RegularFileObject", "ZipFileObject", "ZipFileIndexFileObject" )); |
9788f4549740
6838467: JSR199 FileObjects don't obey general contract of equals.
jjg
parents:
diff
changeset
|
101 |
if (!foundClasses.equals(expectClasses)) { |
9788f4549740
6838467: JSR199 FileObjects don't obey general contract of equals.
jjg
parents:
diff
changeset
|
102 |
error("expected fileobject classes not found\n" |
9788f4549740
6838467: JSR199 FileObjects don't obey general contract of equals.
jjg
parents:
diff
changeset
|
103 |
+ "expected: " + expectClasses + "\n" |
9788f4549740
6838467: JSR199 FileObjects don't obey general contract of equals.
jjg
parents:
diff
changeset
|
104 |
+ "found: " + foundClasses); |
9788f4549740
6838467: JSR199 FileObjects don't obey general contract of equals.
jjg
parents:
diff
changeset
|
105 |
} |
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 |
if (errors > 0) |
9788f4549740
6838467: JSR199 FileObjects don't obey general contract of equals.
jjg
parents:
diff
changeset
|
108 |
throw new Exception(errors + " errors"); |
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 |
void test(FileKind fk, CompareKind ck) throws IOException { |
9788f4549740
6838467: JSR199 FileObjects don't obey general contract of equals.
jjg
parents:
diff
changeset
|
112 |
File f1 = fk.file; |
9788f4549740
6838467: JSR199 FileObjects don't obey general contract of equals.
jjg
parents:
diff
changeset
|
113 |
JavaFileManager fm1 = createFileManager(fk, f1); |
9788f4549740
6838467: JSR199 FileObjects don't obey general contract of equals.
jjg
parents:
diff
changeset
|
114 |
|
9788f4549740
6838467: JSR199 FileObjects don't obey general contract of equals.
jjg
parents:
diff
changeset
|
115 |
File f2 = ck.other(fk.file); |
9788f4549740
6838467: JSR199 FileObjects don't obey general contract of equals.
jjg
parents:
diff
changeset
|
116 |
JavaFileManager fm2 = createFileManager(fk, f2); |
9788f4549740
6838467: JSR199 FileObjects don't obey general contract of equals.
jjg
parents:
diff
changeset
|
117 |
|
9788f4549740
6838467: JSR199 FileObjects don't obey general contract of equals.
jjg
parents:
diff
changeset
|
118 |
try { |
9788f4549740
6838467: JSR199 FileObjects don't obey general contract of equals.
jjg
parents:
diff
changeset
|
119 |
// 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
|
120 |
// 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
|
121 |
// entries in the the directories or zip files. |
9788f4549740
6838467: JSR199 FileObjects don't obey general contract of equals.
jjg
parents:
diff
changeset
|
122 |
// 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
|
123 |
// 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
|
124 |
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
|
125 |
|
9788f4549740
6838467: JSR199 FileObjects don't obey general contract of equals.
jjg
parents:
diff
changeset
|
126 |
System.err.println("test " + (++count) + " " + fk + " " + ck + " " + f1 + " " + f2); |
9788f4549740
6838467: JSR199 FileObjects don't obey general contract of equals.
jjg
parents:
diff
changeset
|
127 |
test(fm1, fm2, expect); |
9788f4549740
6838467: JSR199 FileObjects don't obey general contract of equals.
jjg
parents:
diff
changeset
|
128 |
|
9788f4549740
6838467: JSR199 FileObjects don't obey general contract of equals.
jjg
parents:
diff
changeset
|
129 |
} finally { |
9788f4549740
6838467: JSR199 FileObjects don't obey general contract of equals.
jjg
parents:
diff
changeset
|
130 |
fm1.close(); |
9788f4549740
6838467: JSR199 FileObjects don't obey general contract of equals.
jjg
parents:
diff
changeset
|
131 |
fm2.close(); |
9788f4549740
6838467: JSR199 FileObjects don't obey general contract of equals.
jjg
parents:
diff
changeset
|
132 |
} |
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 |
// 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
|
136 |
// 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
|
137 |
// 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
|
138 |
// 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
|
139 |
// expected number of matches was found. |
9788f4549740
6838467: JSR199 FileObjects don't obey general contract of equals.
jjg
parents:
diff
changeset
|
140 |
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
|
141 |
boolean foundFiles1 = false; |
9788f4549740
6838467: JSR199 FileObjects don't obey general contract of equals.
jjg
parents:
diff
changeset
|
142 |
boolean foundFiles2 = false; |
9788f4549740
6838467: JSR199 FileObjects don't obey general contract of equals.
jjg
parents:
diff
changeset
|
143 |
int foundEqualCount = 0; |
9788f4549740
6838467: JSR199 FileObjects don't obey general contract of equals.
jjg
parents:
diff
changeset
|
144 |
Set<JavaFileObject.Kind> kinds = EnumSet.allOf(JavaFileObject.Kind.class); |
9788f4549740
6838467: JSR199 FileObjects don't obey general contract of equals.
jjg
parents:
diff
changeset
|
145 |
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
|
146 |
foundFiles1 = true; |
9788f4549740
6838467: JSR199 FileObjects don't obey general contract of equals.
jjg
parents:
diff
changeset
|
147 |
foundClasses.add(fo1.getClass().getSimpleName()); |
9788f4549740
6838467: JSR199 FileObjects don't obey general contract of equals.
jjg
parents:
diff
changeset
|
148 |
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
|
149 |
foundFiles2 = true; |
9788f4549740
6838467: JSR199 FileObjects don't obey general contract of equals.
jjg
parents:
diff
changeset
|
150 |
foundClasses.add(fo1.getClass().getSimpleName()); |
9788f4549740
6838467: JSR199 FileObjects don't obey general contract of equals.
jjg
parents:
diff
changeset
|
151 |
System.err.println("compare " + fo1 + " " + fo2); |
9788f4549740
6838467: JSR199 FileObjects don't obey general contract of equals.
jjg
parents:
diff
changeset
|
152 |
if (fo1.equals(fo2)) { |
9788f4549740
6838467: JSR199 FileObjects don't obey general contract of equals.
jjg
parents:
diff
changeset
|
153 |
foundEqualCount++; |
9788f4549740
6838467: JSR199 FileObjects don't obey general contract of equals.
jjg
parents:
diff
changeset
|
154 |
int hash1 = fo1.hashCode(); |
9788f4549740
6838467: JSR199 FileObjects don't obey general contract of equals.
jjg
parents:
diff
changeset
|
155 |
int hash2 = fo2.hashCode(); |
9788f4549740
6838467: JSR199 FileObjects don't obey general contract of equals.
jjg
parents:
diff
changeset
|
156 |
if (hash1 != hash2) |
9788f4549740
6838467: JSR199 FileObjects don't obey general contract of equals.
jjg
parents:
diff
changeset
|
157 |
error("hashCode error: " + fo1 + " [" + hash1 + "] " |
9788f4549740
6838467: JSR199 FileObjects don't obey general contract of equals.
jjg
parents:
diff
changeset
|
158 |
+ fo2 + " [" + hash2 + "]"); |
9788f4549740
6838467: JSR199 FileObjects don't obey general contract of equals.
jjg
parents:
diff
changeset
|
159 |
} |
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 |
if (!foundFiles1) |
9788f4549740
6838467: JSR199 FileObjects don't obey general contract of equals.
jjg
parents:
diff
changeset
|
163 |
error("no files found for file manager 1"); |
9788f4549740
6838467: JSR199 FileObjects don't obey general contract of equals.
jjg
parents:
diff
changeset
|
164 |
if (!foundFiles2) |
9788f4549740
6838467: JSR199 FileObjects don't obey general contract of equals.
jjg
parents:
diff
changeset
|
165 |
error("no files found for file manager 2"); |
9788f4549740
6838467: JSR199 FileObjects don't obey general contract of equals.
jjg
parents:
diff
changeset
|
166 |
// verify the expected number of matches were found |
9788f4549740
6838467: JSR199 FileObjects don't obey general contract of equals.
jjg
parents:
diff
changeset
|
167 |
if (foundEqualCount != expectEqualCount) |
9788f4549740
6838467: JSR199 FileObjects don't obey general contract of equals.
jjg
parents:
diff
changeset
|
168 |
error("expected matches not found: expected " + expectEqualCount + ", found " + foundEqualCount); |
9788f4549740
6838467: JSR199 FileObjects don't obey general contract of equals.
jjg
parents:
diff
changeset
|
169 |
} |
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 |
// 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
|
172 |
// or zip file placed on the classpath |
9788f4549740
6838467: JSR199 FileObjects don't obey general contract of equals.
jjg
parents:
diff
changeset
|
173 |
JavaFileManager createFileManager(FileKind fk, File classpath) throws IOException { |
9788f4549740
6838467: JSR199 FileObjects don't obey general contract of equals.
jjg
parents:
diff
changeset
|
174 |
StandardJavaFileManager fm = createFileManager(fk == FileKind.ZIP); |
9788f4549740
6838467: JSR199 FileObjects don't obey general contract of equals.
jjg
parents:
diff
changeset
|
175 |
fm.setLocation(StandardLocation.CLASS_PATH, Arrays.asList(classpath)); |
9788f4549740
6838467: JSR199 FileObjects don't obey general contract of equals.
jjg
parents:
diff
changeset
|
176 |
return fm; |
9788f4549740
6838467: JSR199 FileObjects don't obey general contract of equals.
jjg
parents:
diff
changeset
|
177 |
} |
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 |
JavacFileManager createFileManager(boolean useJavaUtilZip) { |
9788f4549740
6838467: JSR199 FileObjects don't obey general contract of equals.
jjg
parents:
diff
changeset
|
180 |
// javac should really not be using system properties like this |
9788f4549740
6838467: JSR199 FileObjects don't obey general contract of equals.
jjg
parents:
diff
changeset
|
181 |
// -- it should really be using (hidden) options -- but until then |
9788f4549740
6838467: JSR199 FileObjects don't obey general contract of equals.
jjg
parents:
diff
changeset
|
182 |
// take care to leave system properties as we find them, so as not |
9788f4549740
6838467: JSR199 FileObjects don't obey general contract of equals.
jjg
parents:
diff
changeset
|
183 |
// to adversely affect other tests that might follow. |
9788f4549740
6838467: JSR199 FileObjects don't obey general contract of equals.
jjg
parents:
diff
changeset
|
184 |
String prev = System.getProperty("useJavaUtilZip"); |
9788f4549740
6838467: JSR199 FileObjects don't obey general contract of equals.
jjg
parents:
diff
changeset
|
185 |
boolean resetProperties = false; |
9788f4549740
6838467: JSR199 FileObjects don't obey general contract of equals.
jjg
parents:
diff
changeset
|
186 |
try { |
9788f4549740
6838467: JSR199 FileObjects don't obey general contract of equals.
jjg
parents:
diff
changeset
|
187 |
if (useJavaUtilZip) { |
9788f4549740
6838467: JSR199 FileObjects don't obey general contract of equals.
jjg
parents:
diff
changeset
|
188 |
System.setProperty("useJavaUtilZip", "true"); |
9788f4549740
6838467: JSR199 FileObjects don't obey general contract of equals.
jjg
parents:
diff
changeset
|
189 |
resetProperties = true; |
9788f4549740
6838467: JSR199 FileObjects don't obey general contract of equals.
jjg
parents:
diff
changeset
|
190 |
} else if (System.getProperty("useJavaUtilZip") != null) { |
9788f4549740
6838467: JSR199 FileObjects don't obey general contract of equals.
jjg
parents:
diff
changeset
|
191 |
System.getProperties().remove("useJavaUtilZip"); |
9788f4549740
6838467: JSR199 FileObjects don't obey general contract of equals.
jjg
parents:
diff
changeset
|
192 |
resetProperties = true; |
9788f4549740
6838467: JSR199 FileObjects don't obey general contract of equals.
jjg
parents:
diff
changeset
|
193 |
} |
9788f4549740
6838467: JSR199 FileObjects don't obey general contract of equals.
jjg
parents:
diff
changeset
|
194 |
|
9788f4549740
6838467: JSR199 FileObjects don't obey general contract of equals.
jjg
parents:
diff
changeset
|
195 |
Context c = new Context(); |
9788f4549740
6838467: JSR199 FileObjects don't obey general contract of equals.
jjg
parents:
diff
changeset
|
196 |
return new JavacFileManager(c, false, null); |
9788f4549740
6838467: JSR199 FileObjects don't obey general contract of equals.
jjg
parents:
diff
changeset
|
197 |
} finally { |
9788f4549740
6838467: JSR199 FileObjects don't obey general contract of equals.
jjg
parents:
diff
changeset
|
198 |
if (resetProperties) { |
9788f4549740
6838467: JSR199 FileObjects don't obey general contract of equals.
jjg
parents:
diff
changeset
|
199 |
if (prev == null) { |
9788f4549740
6838467: JSR199 FileObjects don't obey general contract of equals.
jjg
parents:
diff
changeset
|
200 |
System.getProperties().remove("useJavaUtilZip"); |
9788f4549740
6838467: JSR199 FileObjects don't obey general contract of equals.
jjg
parents:
diff
changeset
|
201 |
} else { |
9788f4549740
6838467: JSR199 FileObjects don't obey general contract of equals.
jjg
parents:
diff
changeset
|
202 |
System.setProperty("useJavaUtilZip", prev); |
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 |
} |
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 |
} |
9788f4549740
6838467: JSR199 FileObjects don't obey general contract of equals.
jjg
parents:
diff
changeset
|
207 |
|
9788f4549740
6838467: JSR199 FileObjects don't obey general contract of equals.
jjg
parents:
diff
changeset
|
208 |
// create a directory containing a given set of paths |
9788f4549740
6838467: JSR199 FileObjects don't obey general contract of equals.
jjg
parents:
diff
changeset
|
209 |
void createTestDir(File dir, String[] paths) throws IOException { |
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 |
File file = new File(dir, p); |
9788f4549740
6838467: JSR199 FileObjects don't obey general contract of equals.
jjg
parents:
diff
changeset
|
212 |
file.getParentFile().mkdirs(); |
9788f4549740
6838467: JSR199 FileObjects don't obey general contract of equals.
jjg
parents:
diff
changeset
|
213 |
FileWriter out = new FileWriter(file); |
9788f4549740
6838467: JSR199 FileObjects don't obey general contract of equals.
jjg
parents:
diff
changeset
|
214 |
try { |
9788f4549740
6838467: JSR199 FileObjects don't obey general contract of equals.
jjg
parents:
diff
changeset
|
215 |
out.write(p); |
9788f4549740
6838467: JSR199 FileObjects don't obey general contract of equals.
jjg
parents:
diff
changeset
|
216 |
} finally { |
9788f4549740
6838467: JSR199 FileObjects don't obey general contract of equals.
jjg
parents:
diff
changeset
|
217 |
out.close(); |
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 |
} |
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 |
// 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
|
223 |
void createTestZip(File zip, String[] paths) throws IOException { |
9788f4549740
6838467: JSR199 FileObjects don't obey general contract of equals.
jjg
parents:
diff
changeset
|
224 |
if (zip.getParentFile() != null) |
9788f4549740
6838467: JSR199 FileObjects don't obey general contract of equals.
jjg
parents:
diff
changeset
|
225 |
zip.getParentFile().mkdirs(); |
9788f4549740
6838467: JSR199 FileObjects don't obey general contract of equals.
jjg
parents:
diff
changeset
|
226 |
ZipOutputStream zos = new ZipOutputStream(new FileOutputStream(zip)); |
9788f4549740
6838467: JSR199 FileObjects don't obey general contract of equals.
jjg
parents:
diff
changeset
|
227 |
try { |
9788f4549740
6838467: JSR199 FileObjects don't obey general contract of equals.
jjg
parents:
diff
changeset
|
228 |
for (String p: paths) { |
9788f4549740
6838467: JSR199 FileObjects don't obey general contract of equals.
jjg
parents:
diff
changeset
|
229 |
ZipEntry ze = new ZipEntry(p); |
9788f4549740
6838467: JSR199 FileObjects don't obey general contract of equals.
jjg
parents:
diff
changeset
|
230 |
zos.putNextEntry(ze); |
9788f4549740
6838467: JSR199 FileObjects don't obey general contract of equals.
jjg
parents:
diff
changeset
|
231 |
byte[] bytes = p.getBytes(); |
9788f4549740
6838467: JSR199 FileObjects don't obey general contract of equals.
jjg
parents:
diff
changeset
|
232 |
zos.write(bytes, 0, bytes.length); |
9788f4549740
6838467: JSR199 FileObjects don't obey general contract of equals.
jjg
parents:
diff
changeset
|
233 |
zos.closeEntry(); |
9788f4549740
6838467: JSR199 FileObjects don't obey general contract of equals.
jjg
parents:
diff
changeset
|
234 |
} |
9788f4549740
6838467: JSR199 FileObjects don't obey general contract of equals.
jjg
parents:
diff
changeset
|
235 |
} finally { |
9788f4549740
6838467: JSR199 FileObjects don't obey general contract of equals.
jjg
parents:
diff
changeset
|
236 |
zos.close(); |
9788f4549740
6838467: JSR199 FileObjects don't obey general contract of equals.
jjg
parents:
diff
changeset
|
237 |
} |
9788f4549740
6838467: JSR199 FileObjects don't obey general contract of equals.
jjg
parents:
diff
changeset
|
238 |
} |
9788f4549740
6838467: JSR199 FileObjects don't obey general contract of equals.
jjg
parents:
diff
changeset
|
239 |
|
9788f4549740
6838467: JSR199 FileObjects don't obey general contract of equals.
jjg
parents:
diff
changeset
|
240 |
void error(String msg) { |
9788f4549740
6838467: JSR199 FileObjects don't obey general contract of equals.
jjg
parents:
diff
changeset
|
241 |
System.err.println("Error: " + msg); |
9788f4549740
6838467: JSR199 FileObjects don't obey general contract of equals.
jjg
parents:
diff
changeset
|
242 |
errors++; |
9788f4549740
6838467: JSR199 FileObjects don't obey general contract of equals.
jjg
parents:
diff
changeset
|
243 |
} |
9788f4549740
6838467: JSR199 FileObjects don't obey general contract of equals.
jjg
parents:
diff
changeset
|
244 |
|
9788f4549740
6838467: JSR199 FileObjects don't obey general contract of equals.
jjg
parents:
diff
changeset
|
245 |
int count; |
9788f4549740
6838467: JSR199 FileObjects don't obey general contract of equals.
jjg
parents:
diff
changeset
|
246 |
int errors; |
9788f4549740
6838467: JSR199 FileObjects don't obey general contract of equals.
jjg
parents:
diff
changeset
|
247 |
Set<String> foundClasses = new HashSet<String>(); |
9788f4549740
6838467: JSR199 FileObjects don't obey general contract of equals.
jjg
parents:
diff
changeset
|
248 |
} |
9788f4549740
6838467: JSR199 FileObjects don't obey general contract of equals.
jjg
parents:
diff
changeset
|
249 |