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).
14 *
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.
18 *
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.
22 */
23
24 /**
25 * @test
26 * @bug 8207954
27 * @summary Verify that CreateSymbols can handle classfiles from the current release.
28 * @library /tools/lib /tools/javac/lib
29 * @modules jdk.compiler/com.sun.tools.javac.api
30 * jdk.compiler/com.sun.tools.javac.main
31 * @build toolbox.ToolBox toolbox.JavacTask toolbox.Task
32 * @run main CanHandleClassFilesTest
33 */
34
35 import java.io.Writer;
36 import java.nio.file.Files;
37 import java.nio.file.Path;
38 import java.nio.file.Paths;
39
40 import javax.tools.StandardLocation;
41
42 import toolbox.JavacTask;
43 import toolbox.ToolBox;
44
45 public class CanHandleClassFilesTest {
46
47 public static void main(String... args) throws Exception {
48 new CanHandleClassFilesTest().run();
49 }
50
51 void run() throws Exception {
52 var testSrc = Paths.get(System.getProperty("test.src", "."));
53 var targetDir = Paths.get(".");
54 Path createSymbols = null;
55 Path includeList = null;
56 for (Path d = testSrc; d != null; d = d.getParent()) {
57 if (Files.exists(d.resolve("TEST.ROOT"))) {
58 d = d.getParent().getParent();
76 "--add-exports", "jdk.compiler/com.sun.tools.javac.jvm=ALL-UNNAMED",
77 "--add-exports", "jdk.compiler/com.sun.tools.javac.util=ALL-UNNAMED",
78 "--add-modules", "jdk.jdeps")
79 .files(createSymbols)
80 .fileManager(mfm)
81 .run()
82 .writeAll();
83
84 ClassLoader cl = new ClassLoader() {
85 @Override
86 protected Class<?> findClass(String name) throws ClassNotFoundException {
87 byte[] data = mfm.getFileBytes(StandardLocation.CLASS_OUTPUT, name);
88 if (data != null) {
89 return defineClass(name, data, 0, data.length);
90 } else {
91 throw new ClassNotFoundException(name);
92 }
93 }
94 };
95
96 var createSymbolsClass = Class.forName("build.tools.symbolgenerator.CreateSymbols", false, cl);
97 var main = createSymbolsClass.getDeclaredMethod("main", String[].class);
98 var symbols = targetDir.resolve("symbols");
99
100 try (Writer w = Files.newBufferedWriter(symbols)) {}
101
102 main.invoke(null,
103 (Object) new String[] {"build-description-incremental",
104 symbols.toAbsolutePath().toString(),
105 includeList.toAbsolutePath().toString()});
106
107 main.invoke(null,
108 (Object) new String[] {"build-ctsym",
109 "does-not-exist",
110 symbols.toAbsolutePath().toString(),
111 targetDir.resolve("ct.sym").toAbsolutePath().toString()});
112 }
113 }
114
115 }
|
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).
14 *
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.
18 *
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.
22 */
23
24 /**
25 * @test
26 * @bug 8207954
27 * @summary Verify that CreateSymbols can handle classfiles from the current release.
28 * @library /tools/lib /tools/javac/lib
29 * @modules jdk.compiler/com.sun.tools.javac.api:+open
30 * jdk.compiler/com.sun.tools.javac.main
31 * jdk.compiler/com.sun.tools.javac.jvm:+open
32 * jdk.compiler/com.sun.tools.javac.util:+open
33 * jdk.jdeps/com.sun.tools.classfile:+open
34 * @build toolbox.ToolBox toolbox.JavacTask toolbox.Task
35 * @run main CanHandleClassFilesTest
36 */
37
38 import java.io.Writer;
39 import java.nio.file.Files;
40 import java.nio.file.Path;
41 import java.nio.file.Paths;
42 import java.util.stream.Stream;
43
44 import javax.tools.StandardLocation;
45
46 import toolbox.JavacTask;
47 import toolbox.ToolBox;
48
49 public class CanHandleClassFilesTest {
50
51 public static void main(String... args) throws Exception {
52 new CanHandleClassFilesTest().run();
53 }
54
55 void run() throws Exception {
56 var testSrc = Paths.get(System.getProperty("test.src", "."));
57 var targetDir = Paths.get(".");
58 Path createSymbols = null;
59 Path includeList = null;
60 for (Path d = testSrc; d != null; d = d.getParent()) {
61 if (Files.exists(d.resolve("TEST.ROOT"))) {
62 d = d.getParent().getParent();
80 "--add-exports", "jdk.compiler/com.sun.tools.javac.jvm=ALL-UNNAMED",
81 "--add-exports", "jdk.compiler/com.sun.tools.javac.util=ALL-UNNAMED",
82 "--add-modules", "jdk.jdeps")
83 .files(createSymbols)
84 .fileManager(mfm)
85 .run()
86 .writeAll();
87
88 ClassLoader cl = new ClassLoader() {
89 @Override
90 protected Class<?> findClass(String name) throws ClassNotFoundException {
91 byte[] data = mfm.getFileBytes(StandardLocation.CLASS_OUTPUT, name);
92 if (data != null) {
93 return defineClass(name, data, 0, data.length);
94 } else {
95 throw new ClassNotFoundException(name);
96 }
97 }
98 };
99
100 // open the non-exported packages needed by CreateSymbols to its module
101 Module targetModule = cl.getUnnamedModule();
102 Stream.of("jdk.compiler/com.sun.tools.javac.api",
103 "jdk.compiler/com.sun.tools.javac.jvm",
104 "jdk.compiler/com.sun.tools.javac.util",
105 "jdk.jdeps/com.sun.tools.classfile")
106 .forEach(p -> open(p, targetModule));
107
108 var createSymbolsClass = Class.forName("build.tools.symbolgenerator.CreateSymbols", false, cl);
109 var main = createSymbolsClass.getMethod("main", String[].class);
110 var symbols = targetDir.resolve("symbols");
111
112 try (Writer w = Files.newBufferedWriter(symbols)) {}
113
114 main.invoke(null,
115 (Object) new String[] {"build-description-incremental",
116 symbols.toAbsolutePath().toString(),
117 includeList.toAbsolutePath().toString()});
118
119 main.invoke(null,
120 (Object) new String[] {"build-ctsym",
121 "does-not-exist",
122 symbols.toAbsolutePath().toString(),
123 targetDir.resolve("ct.sym").toAbsolutePath().toString()});
124 }
125 }
126
127 void open(String moduleAndPackage, Module target) {
128 String[] s = moduleAndPackage.split("/");
129 var moduleName = s[0];
130 var packageName = s[1];
131 ModuleLayer.boot().findModule(moduleName).orElseThrow().addOpens(packageName, target);
132 }
133
134 }
|