1 /*
2 * Copyright (c) 2011, 2015, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
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.
8 *
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 */
116 * Test a method in a user supplied component, to verify javac's handling
117 * of any exceptions thrown by that method.
118 */
119 void test(Method m) throws Exception {
120 testNum++;
121
122 File extDirs = new File("empty-extdirs");
123 extDirs.mkdirs();
124
125 File testClasses = new File("test" + testNum);
126 testClasses.mkdirs();
127 defaultFileManager.setLocation(StandardLocation.CLASS_OUTPUT, Arrays.asList(testClasses));
128
129 System.err.println("test " + testNum + ": "
130 + m.getDeclaringClass().getSimpleName() + "." + m.getName());
131
132 StringWriter sw = new StringWriter();
133 PrintWriter pw = new PrintWriter(sw);
134
135 List<String> javacOptions = Arrays.asList(
136 "-XaddExports:jdk.compiler/com.sun.tools.javac.api=ALL-UNNAMED",
137 "-extdirs", extDirs.getPath(), // for use by filemanager handleOption
138 "-processor", TestClientCodeWrapper.class.getName()
139 );
140
141 List<String> classes = Collections.emptyList();
142
143 JavacTool tool = JavacTool.create();
144 try {
145 JavacTask task = tool.getTask(pw,
146 getFileManager(m, defaultFileManager),
147 getDiagnosticListener(m, pw),
148 javacOptions,
149 classes,
150 getCompilationUnits(m));
151
152 if (isDeclaredIn(m, Processor.class))
153 task.setProcessors(getProcessors(m));
154
155 if (isDeclaredIn(m, TaskListener.class))
156 task.setTaskListener(getTaskListener(m, pw));
|
1 /*
2 * Copyright (c) 2011, 2016, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
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.
8 *
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 */
116 * Test a method in a user supplied component, to verify javac's handling
117 * of any exceptions thrown by that method.
118 */
119 void test(Method m) throws Exception {
120 testNum++;
121
122 File extDirs = new File("empty-extdirs");
123 extDirs.mkdirs();
124
125 File testClasses = new File("test" + testNum);
126 testClasses.mkdirs();
127 defaultFileManager.setLocation(StandardLocation.CLASS_OUTPUT, Arrays.asList(testClasses));
128
129 System.err.println("test " + testNum + ": "
130 + m.getDeclaringClass().getSimpleName() + "." + m.getName());
131
132 StringWriter sw = new StringWriter();
133 PrintWriter pw = new PrintWriter(sw);
134
135 List<String> javacOptions = Arrays.asList(
136 "--add-exports", "jdk.compiler/com.sun.tools.javac.api=ALL-UNNAMED",
137 "-extdirs", extDirs.getPath(), // for use by filemanager handleOption
138 "-processor", TestClientCodeWrapper.class.getName()
139 );
140
141 List<String> classes = Collections.emptyList();
142
143 JavacTool tool = JavacTool.create();
144 try {
145 JavacTask task = tool.getTask(pw,
146 getFileManager(m, defaultFileManager),
147 getDiagnosticListener(m, pw),
148 javacOptions,
149 classes,
150 getCompilationUnits(m));
151
152 if (isDeclaredIn(m, Processor.class))
153 task.setProcessors(getProcessors(m));
154
155 if (isDeclaredIn(m, TaskListener.class))
156 task.setTaskListener(getTaskListener(m, pw));
|