47 * Verify the various implementations of inferBinaryName, but configuring |
47 * Verify the various implementations of inferBinaryName, but configuring |
48 * different instances of a file manager, getting a file object, and checking |
48 * different instances of a file manager, getting a file object, and checking |
49 * the impl of inferBinaryName for that file object. |
49 * the impl of inferBinaryName for that file object. |
50 */ |
50 */ |
51 public class TestInferBinaryName { |
51 public class TestInferBinaryName { |
52 static final boolean IGNORE_SYMBOL_FILE = false; |
|
53 static final boolean USE_SYMBOL_FILE = true; |
|
54 static final boolean DONT_USE_ZIP_FILE_INDEX = false; |
52 static final boolean DONT_USE_ZIP_FILE_INDEX = false; |
55 static final boolean USE_ZIP_FILE_INDEX = true; |
53 static final boolean USE_ZIP_FILE_INDEX = true; |
56 |
54 |
57 public static void main(String... args) throws Exception { |
55 public static void main(String... args) throws Exception { |
58 new TestInferBinaryName().run(); |
56 new TestInferBinaryName().run(); |
59 } |
57 } |
60 |
58 |
61 void run() throws Exception { |
59 void run() throws Exception { |
62 //System.err.println(System.getProperties()); |
|
63 testDirectory(); |
60 testDirectory(); |
64 testSymbolArchive(); |
|
65 |
61 |
66 File testJar = createJar(); |
62 File testJar = createJar(); |
67 |
63 |
68 testZipArchive(testJar); |
64 testZipArchive(testJar); |
69 testZipFileIndexArchive(testJar); |
65 testZipFileIndexArchive(testJar); |
70 testZipFileIndexArchive2(testJar); |
66 testZipFileIndexArchive2(testJar); |
|
67 |
71 if (errors > 0) |
68 if (errors > 0) |
72 throw new Exception(errors + " error found"); |
69 throw new Exception(errors + " error found"); |
73 } |
70 } |
74 |
71 |
75 File createJar() throws IOException { |
72 File createJar() throws IOException { |
85 |
82 |
86 void testDirectory() throws IOException { |
83 void testDirectory() throws IOException { |
87 String testClassName = "p.A"; |
84 String testClassName = "p.A"; |
88 List<File> testClasses = Arrays.asList(new File(System.getProperty("test.classes"))); |
85 List<File> testClasses = Arrays.asList(new File(System.getProperty("test.classes"))); |
89 try (JavaFileManager fm = |
86 try (JavaFileManager fm = |
90 getFileManager(testClasses, USE_SYMBOL_FILE, USE_ZIP_FILE_INDEX)) { |
87 getFileManager(testClasses, USE_ZIP_FILE_INDEX)) { |
91 test("testDirectory", |
88 test("testDirectory", |
92 fm, testClassName, "com.sun.tools.javac.file.RegularFileObject"); |
89 fm, testClassName, "com.sun.tools.javac.file.RegularFileObject"); |
93 } |
|
94 } |
|
95 |
|
96 void testSymbolArchive() throws IOException { |
|
97 String testClassName = "java.lang.String"; |
|
98 List<File> path = getPath(System.getProperty("sun.boot.class.path")); |
|
99 try (JavaFileManager fm = |
|
100 getFileManager(path, USE_SYMBOL_FILE, DONT_USE_ZIP_FILE_INDEX)) { |
|
101 test("testSymbolArchive", |
|
102 fm, testClassName, "com.sun.tools.javac.file.SymbolArchive$SymbolFileObject"); |
|
103 } |
90 } |
104 } |
91 } |
105 |
92 |
106 void testZipArchive(File testJar) throws IOException { |
93 void testZipArchive(File testJar) throws IOException { |
107 String testClassName = "java.lang.String"; |
94 String testClassName = "java.lang.String"; |
108 List<File> path = Arrays.asList(testJar); |
95 List<File> path = Arrays.asList(testJar); |
109 try (JavaFileManager fm = |
96 try (JavaFileManager fm = |
110 getFileManager(path, IGNORE_SYMBOL_FILE, DONT_USE_ZIP_FILE_INDEX)) { |
97 getFileManager(path, DONT_USE_ZIP_FILE_INDEX)) { |
111 test("testZipArchive", |
98 test("testZipArchive", |
112 fm, testClassName, "com.sun.tools.javac.file.ZipArchive$ZipFileObject"); |
99 fm, testClassName, "com.sun.tools.javac.file.ZipArchive$ZipFileObject"); |
113 } |
100 } |
114 } |
101 } |
115 |
102 |
116 void testZipFileIndexArchive(File testJar) throws IOException { |
103 void testZipFileIndexArchive(File testJar) throws IOException { |
117 String testClassName = "java.lang.String"; |
104 String testClassName = "java.lang.String"; |
118 List<File> path = Arrays.asList(testJar); |
105 List<File> path = Arrays.asList(testJar); |
119 try (JavaFileManager fm = |
106 try (JavaFileManager fm = |
120 getFileManager(path, USE_SYMBOL_FILE, USE_ZIP_FILE_INDEX)) { |
107 getFileManager(path, USE_ZIP_FILE_INDEX)) { |
121 test("testZipFileIndexArchive", |
108 test("testZipFileIndexArchive", |
122 fm, testClassName, "com.sun.tools.javac.file.ZipFileIndexArchive$ZipFileIndexFileObject"); |
109 fm, testClassName, "com.sun.tools.javac.file.ZipFileIndexArchive$ZipFileIndexFileObject"); |
123 } |
110 } |
124 } |
111 } |
125 |
112 |
126 void testZipFileIndexArchive2(File testJar) throws IOException { |
113 void testZipFileIndexArchive2(File testJar) throws IOException { |
127 String testClassName = "java.lang.String"; |
114 String testClassName = "java.lang.String"; |
128 List<File> path = Arrays.asList(testJar); |
115 List<File> path = Arrays.asList(testJar); |
129 try (JavaFileManager fm = |
116 try (JavaFileManager fm = |
130 getFileManager(path, IGNORE_SYMBOL_FILE, USE_ZIP_FILE_INDEX)) { |
117 getFileManager(path, USE_ZIP_FILE_INDEX)) { |
131 test("testZipFileIndexArchive2", |
118 test("testZipFileIndexArchive2", |
132 fm, testClassName, "com.sun.tools.javac.file.ZipFileIndexArchive$ZipFileIndexFileObject"); |
119 fm, testClassName, "com.sun.tools.javac.file.ZipFileIndexArchive$ZipFileIndexFileObject"); |
133 } |
120 } |
134 } |
121 } |
135 |
122 |
157 check(bn, testClassName); |
144 check(bn, testClassName); |
158 System.err.println("OK"); |
145 System.err.println("OK"); |
159 } |
146 } |
160 |
147 |
161 JavaFileManager getFileManager(List<File> path, |
148 JavaFileManager getFileManager(List<File> path, |
162 boolean symFileKind, |
|
163 boolean zipFileIndexKind) |
149 boolean zipFileIndexKind) |
164 throws IOException { |
150 throws IOException { |
165 Context ctx = new Context(); |
151 Context ctx = new Context(); |
166 Options options = Options.instance(ctx); |
152 Options options = Options.instance(ctx); |
167 options.put("useOptimizedZip", |
153 options.put("useOptimizedZip", |
168 Boolean.toString(zipFileIndexKind == USE_ZIP_FILE_INDEX)); |
154 Boolean.toString(zipFileIndexKind == USE_ZIP_FILE_INDEX)); |
169 |
155 |
170 if (symFileKind == IGNORE_SYMBOL_FILE) |
|
171 options.put("ignore.symbol.file", "true"); |
|
172 JavacFileManager fm = new JavacFileManager(ctx, false, null); |
156 JavacFileManager fm = new JavacFileManager(ctx, false, null); |
173 fm.setLocation(CLASS_PATH, path); |
157 fm.setLocation(CLASS_PATH, path); |
174 return fm; |
158 return fm; |
175 } |
159 } |
176 |
160 |