1 /* |
1 /* |
2 * Copyright (c) 2008, 2015, Oracle and/or its affiliates. All rights reserved. |
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. |
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
4 * |
4 * |
5 * This code is free software; you can redistribute it and/or modify it |
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 |
6 * under the terms of the GNU General Public License version 2 only, as |
7 * published by the Free Software Foundation. |
7 * published by the Free Software Foundation. |
26 * @bug 6508981 |
26 * @bug 6508981 |
27 * @summary cleanup file separator handling in JavacFileManager |
27 * @summary cleanup file separator handling in JavacFileManager |
28 * (This test is specifically to test the new impl of inferBinaryName) |
28 * (This test is specifically to test the new impl of inferBinaryName) |
29 * @library /tools/lib |
29 * @library /tools/lib |
30 * @modules jdk.compiler/com.sun.tools.javac.api |
30 * @modules jdk.compiler/com.sun.tools.javac.api |
31 * jdk.compiler/com.sun.tools.javac.file |
|
32 * jdk.compiler/com.sun.tools.javac.main |
31 * jdk.compiler/com.sun.tools.javac.main |
33 * jdk.compiler/com.sun.tools.javac.util |
32 * @build toolbox.ToolBox toolbox.JarTask p.A |
34 * jdk.jdeps/com.sun.tools.javap |
|
35 * @build ToolBox p.A |
|
36 * @run main TestInferBinaryName |
33 * @run main TestInferBinaryName |
37 */ |
34 */ |
38 |
35 |
39 import java.io.*; |
36 import java.io.*; |
40 import java.util.*; |
37 import java.util.*; |
41 import javax.tools.*; |
38 import javax.tools.*; |
42 |
39 |
43 import com.sun.tools.javac.file.JavacFileManager; |
|
44 import com.sun.tools.javac.util.Context; |
|
45 import com.sun.tools.javac.util.Options; |
|
46 |
|
47 import static javax.tools.JavaFileObject.Kind.*; |
40 import static javax.tools.JavaFileObject.Kind.*; |
48 import static javax.tools.StandardLocation.*; |
41 import static javax.tools.StandardLocation.*; |
49 |
42 |
|
43 import toolbox.JarTask; |
|
44 import toolbox.ToolBox; |
50 |
45 |
51 /** |
46 /** |
52 * Verify the various implementations of inferBinaryName, but configuring |
47 * Verify the various implementations of inferBinaryName, but configuring |
53 * 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 |
54 * the impl of inferBinaryName for that file object. |
49 * the impl of inferBinaryName for that file object. |
68 throw new Exception(errors + " error found"); |
63 throw new Exception(errors + " error found"); |
69 } |
64 } |
70 |
65 |
71 File createJar() throws IOException { |
66 File createJar() throws IOException { |
72 File f = new File("test.jar"); |
67 File f = new File("test.jar"); |
73 try (JavaFileManager fm = new JavacFileManager(new Context(), false, null)) { |
68 try (JavaFileManager fm = ToolProvider.getSystemJavaCompiler() |
|
69 .getStandardFileManager(null, null, null)) { |
74 ToolBox tb = new ToolBox(); |
70 ToolBox tb = new ToolBox(); |
75 tb.new JarTask(f.getPath()) |
71 new JarTask(tb, f.getPath()) |
76 .files(fm, StandardLocation.PLATFORM_CLASS_PATH, "java.lang.*") |
72 .files(fm, StandardLocation.PLATFORM_CLASS_PATH, "java.lang.*") |
77 .run(); |
73 .run(); |
78 } |
74 } |
79 return f; |
75 return f; |
80 } |
76 } |
122 System.err.println("OK"); |
118 System.err.println("OK"); |
123 } |
119 } |
124 |
120 |
125 JavaFileManager getFileManager(List<File> path) |
121 JavaFileManager getFileManager(List<File> path) |
126 throws IOException { |
122 throws IOException { |
127 Context ctx = new Context(); |
123 StandardJavaFileManager fm = ToolProvider.getSystemJavaCompiler() |
128 |
124 .getStandardFileManager(null, null, null); |
129 JavacFileManager fm = new JavacFileManager(ctx, false, null); |
|
130 fm.setLocation(CLASS_PATH, path); |
125 fm.setLocation(CLASS_PATH, path); |
131 return fm; |
126 return fm; |
132 } |
127 } |
133 |
128 |
134 List<File> getPath(String s) { |
129 List<File> getPath(String s) { |