2
* Copyright (c) 2008, 2016, Oracle and/or its affiliates. All rights reserved.
3
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5
* This code is free software; you can redistribute it and/or modify it
6
* under the terms of the GNU General Public License version 2 only, as
7
* published by the Free Software Foundation.
9
* This code is distributed in the hope that it will be useful, but WITHOUT
10
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12
* version 2 for more details (a copy is included in the LICENSE file that
13
* accompanied this code).
15
* You should have received a copy of the GNU General Public License version
16
* 2 along with this work; if not, write to the Free Software Foundation,
17
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
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
27
* @summary cleanup file separator handling in JavacFileManager
28
* (This test is specifically to test the new impl of inferBinaryName)
30
* @modules jdk.compiler/com.sun.tools.javac.api
31
* jdk.compiler/com.sun.tools.javac.main
32
* @build toolbox.ToolBox toolbox.JarTask p.A
33
* @run main TestInferBinaryName
40
import static javax.tools.JavaFileObject.Kind.*;
41
import static javax.tools.StandardLocation.*;
43
import toolbox.JarTask;
44
import toolbox.ToolBox;
47
* Verify the various implementations of inferBinaryName, but configuring
48
* different instances of a file manager, getting a file object, and checking
49
* the impl of inferBinaryName for that file object.
51
public class TestInferBinaryName {
52
public static void main(String... args) throws Exception {
53
new TestInferBinaryName().run();
56
void run() throws Exception {
59
File testJar = createJar();
60
testZipArchive(testJar);
63
throw new Exception(errors + " error found");
66
File createJar() throws IOException {
67
File f = new File("test.jar");
68
try (JavaFileManager fm = ToolProvider.getSystemJavaCompiler()
69
.getStandardFileManager(null, null, null)) {
70
ToolBox tb = new ToolBox();
71
new JarTask(tb, f.getPath())
72
.files(fm, StandardLocation.PLATFORM_CLASS_PATH, "java.lang.*")
78
void testDirectory() throws IOException {
79
String testClassName = "p.A";
80
List<File> testClasses = Arrays.asList(new File(System.getProperty("test.classes")));
81
try (JavaFileManager fm = getFileManager(testClasses)) {
83
fm, testClassName, "SimpleFileObject");
87
void testZipArchive(File testJar) throws IOException {
88
String testClassName = "java.lang.String";
89
List<File> path = Arrays.asList(testJar);
90
try (JavaFileManager fm = getFileManager(path)) {
91
test("testZipArchive",
92
fm, testClassName, "JarFileObject");
97
* @param testName for debugging
98
* @param fm suitably configured file manager
99
* @param testClassName the classname to test
100
* @param implClassName the expected classname of the JavaFileObject impl,
101
* used for checking that we are checking the expected impl of
104
void test(String testName,
105
JavaFileManager fm, String testClassName, String implClassName) throws IOException {
106
JavaFileObject fo = fm.getJavaFileForInput(CLASS_PATH, testClassName, CLASS);
108
System.err.println("Can't find " + testClassName);
113
String cn = fo.getClass().getSimpleName();
114
String bn = fm.inferBinaryName(CLASS_PATH, fo);
115
System.err.println(testName + " " + cn + " " + bn);
116
checkEqual(cn, implClassName);
117
checkEqual(bn, testClassName);
118
System.err.println("OK");
121
JavaFileManager getFileManager(List<File> path)
123
StandardJavaFileManager fm = ToolProvider.getSystemJavaCompiler()
124
.getStandardFileManager(null, null, null);
125
fm.setLocation(CLASS_PATH, path);
129
List<File> getPath(String s) {
130
List<File> path = new ArrayList<>();
131
for (String f: s.split(File.pathSeparator)) {
133
path.add(new File(f));
135
//System.err.println("path: " + path);
139
void checkEqual(String found, String expect) {
140
if (!found.equals(expect)) {
141
System.err.println("Expected: " + expect);
142
System.err.println(" Found: " + found);