1 /*******************************************************************************
2  * Copyright (c) 2017, 2018 IBM Corporation.
3  *
4  * This program and the accompanying materials
5  * are made available under the terms of the Eclipse Public License 2.0
6  * which accompanies this distribution, and is available at
7  * https://www.eclipse.org/legal/epl-2.0/
8  *
9  * SPDX-License-Identifier: EPL-2.0
10  *
11  * Contributors:
12  *     IBM Corporation - initial API and implementation
13  *******************************************************************************/
14 
15 package org.eclipse.jdt.compiler.apt.tests;
16 
17 import java.io.ByteArrayOutputStream;
18 import java.io.File;
19 import java.io.IOException;
20 import java.io.PrintWriter;
21 import java.util.ArrayList;
22 import java.util.List;
23 
24 import javax.lang.model.SourceVersion;
25 import javax.tools.JavaCompiler;
26 import javax.tools.ToolProvider;
27 
28 import org.eclipse.jdt.compiler.apt.tests.NegativeTests.TestDiagnosticListener;
29 import org.eclipse.jdt.internal.compiler.tool.EclipseCompiler;
30 
31 import junit.framework.TestCase;
32 
33 public class Java9ElementsTests extends TestCase {
34 	private static final String MODULE_PROC = "org.eclipse.jdt.compiler.apt.tests.processors.elements.Java9ElementProcessor";
35 
_testRootElements1Javac()36 	public void _testRootElements1Javac() throws IOException {
37 		JavaCompiler compiler = ToolProvider.getSystemJavaCompiler();
38 		if (compiler == null) {
39 			System.out.println("No system java compiler available");
40 			return;
41 		}
42 		internalTest2(compiler, MODULE_PROC, "testRootElements1", null);
43 	}
_testRootElements1()44 	public void _testRootElements1() throws IOException {
45 		JavaCompiler compiler = BatchTestUtils.getEclipseCompiler();
46 		internalTest2(compiler, MODULE_PROC, "testRootElements1", null);
47 	}
48 
_testRootElements2Javac()49 	public void _testRootElements2Javac() throws IOException {
50 		JavaCompiler compiler = ToolProvider.getSystemJavaCompiler();
51 		if (compiler == null) {
52 			System.out.println("No system java compiler available");
53 			return;
54 		}
55 		internalTest2(compiler, MODULE_PROC, "testRootElements2", null);
56 	}
_testRootElements2()57 	public void _testRootElements2() throws IOException {
58 		JavaCompiler compiler = BatchTestUtils.getEclipseCompiler();
59 		internalTest2(compiler, MODULE_PROC, "testRootElements2", null);
60 	}
61 
testAnnotations1Javac()62 	public void testAnnotations1Javac() throws IOException {
63 		JavaCompiler compiler = ToolProvider.getSystemJavaCompiler();
64 		if (compiler == null) {
65 			System.out.println("No system java compiler available");
66 			return;
67 		}
68 		internalTest2(compiler, MODULE_PROC, "testModuleAnnotation1", null);
69 	}
testAnnotations1()70 	public void testAnnotations1() throws IOException {
71 		JavaCompiler compiler = BatchTestUtils.getEclipseCompiler();
72 		internalTest2(compiler, MODULE_PROC, "testModuleAnnotation1", null);
73 	}
74 
testModuleElement1Javac()75 	public void testModuleElement1Javac() throws IOException {
76 		JavaCompiler compiler = ToolProvider.getSystemJavaCompiler();
77 		if (compiler == null) {
78 			System.out.println("No system java compiler available");
79 			return;
80 		}
81 		internalTest2(compiler, MODULE_PROC, "testModuleElement1", null);
82 	}
testModuleElement1()83 	public void testModuleElement1() throws IOException {
84 		JavaCompiler compiler = BatchTestUtils.getEclipseCompiler();
85 		internalTest2(compiler, MODULE_PROC, "testModuleElement1", null);
86 	}
87 
testModuleElement2Javac()88 	public void testModuleElement2Javac() throws IOException {
89 		JavaCompiler compiler = ToolProvider.getSystemJavaCompiler();
90 		if (compiler == null) {
91 			System.out.println("No system java compiler available");
92 			return;
93 		}
94 		internalTest2(compiler, MODULE_PROC, "testModuleElement2", null);
95 	}
testModuleElement2()96 	public void testModuleElement2() throws IOException {
97 		JavaCompiler compiler = BatchTestUtils.getEclipseCompiler();
98 		internalTest2(compiler, MODULE_PROC, "testModuleElement2", null);
99 	}
100 
testModuleElement3Javac()101 	public void testModuleElement3Javac() throws IOException {
102 		JavaCompiler compiler = ToolProvider.getSystemJavaCompiler();
103 		if (compiler == null) {
104 			System.out.println("No system java compiler available");
105 			return;
106 		}
107 		internalTest2(compiler, MODULE_PROC, "testModuleElement3", null);
108 	}
testModuleElement3()109 	public void testModuleElement3() throws IOException {
110 		JavaCompiler compiler = BatchTestUtils.getEclipseCompiler();
111 		internalTest2(compiler, MODULE_PROC, "testModuleElement3", null);
112 	}
testModuleElement4Javac()113 	public void testModuleElement4Javac() throws IOException {
114 		JavaCompiler compiler = ToolProvider.getSystemJavaCompiler();
115 		if (compiler == null) {
116 			System.out.println("No system java compiler available");
117 			return;
118 		}
119 		internalTest2(compiler, MODULE_PROC, "testModuleElement4", null);
120 	}
testModuleElement4()121 	public void testModuleElement4() throws IOException {
122 		JavaCompiler compiler = BatchTestUtils.getEclipseCompiler();
123 		internalTest2(compiler, MODULE_PROC, "testModuleElement4", null);
124 	}
125 
testModuleElement5Javac()126 	public void testModuleElement5Javac() throws IOException {
127 		JavaCompiler compiler = ToolProvider.getSystemJavaCompiler();
128 		if (compiler == null) {
129 			System.out.println("No system java compiler available");
130 			return;
131 		}
132 		internalTest2(compiler, MODULE_PROC, "testModuleElement5", null);
133 	}
testModuleElement5()134 	public void testModuleElement5() throws IOException {
135 		JavaCompiler compiler = BatchTestUtils.getEclipseCompiler();
136 		internalTest2(compiler, MODULE_PROC, "testModuleElement5", null);
137 	}
138 
testModuleElement6Javac()139 	public void testModuleElement6Javac() throws IOException {
140 		JavaCompiler compiler = ToolProvider.getSystemJavaCompiler();
141 		if (compiler == null) {
142 			System.out.println("No system java compiler available");
143 			return;
144 		}
145 		internalTest2(compiler, MODULE_PROC, "testModuleElement6", null);
146 	}
testModuleElement6()147 	public void testModuleElement6() throws IOException {
148 		JavaCompiler compiler = BatchTestUtils.getEclipseCompiler();
149 		internalTest2(compiler, MODULE_PROC, "testModuleElement6", null);
150 	}
151 
_testModuleElement7Javac()152 	public void _testModuleElement7Javac() throws IOException {
153 		JavaCompiler compiler = ToolProvider.getSystemJavaCompiler();
154 		if (compiler == null) {
155 			System.out.println("No system java compiler available");
156 			return;
157 		}
158 		internalTest2(compiler, MODULE_PROC, "testModuleElement7", null);
159 	}
testModuleElement7()160 	public void testModuleElement7() throws IOException {
161 		JavaCompiler compiler = BatchTestUtils.getEclipseCompiler();
162 		internalTest2(compiler, MODULE_PROC, "testModuleElement7", null);
163 	}
164 
testModuleJavaBase1Javac()165 	public void testModuleJavaBase1Javac() throws IOException {
166 		JavaCompiler compiler = ToolProvider.getSystemJavaCompiler();
167 		if (compiler == null) {
168 			System.out.println("No system java compiler available");
169 			return;
170 		}
171 		internalTest2(compiler, MODULE_PROC, "testModuleJavaBase1", null);
172 	}
testModuleJavaBase1()173 	public void testModuleJavaBase1() throws IOException {
174 		JavaCompiler compiler = BatchTestUtils.getEclipseCompiler();
175 		internalTest2(compiler, MODULE_PROC, "testModuleJavaBase1", null);
176 	}
177 
178 
testModuleJavaBase2Javac()179 	public void testModuleJavaBase2Javac() throws IOException {
180 		JavaCompiler compiler = ToolProvider.getSystemJavaCompiler();
181 		if (compiler == null) {
182 			System.out.println("No system java compiler available");
183 			return;
184 		}
185 		internalTest2(compiler, MODULE_PROC, "testModuleJavaBase2", null);
186 	}
testModuleJavaBase2()187 	public void testModuleJavaBase2() throws IOException {
188 		JavaCompiler compiler = BatchTestUtils.getEclipseCompiler();
189 		internalTest2(compiler, MODULE_PROC, "testModuleJavaBase2", null);
190 	}
191 
192 
testModuleJavaBase3Javac()193 	public void testModuleJavaBase3Javac() throws IOException {
194 		JavaCompiler compiler = ToolProvider.getSystemJavaCompiler();
195 		if (compiler == null) {
196 			System.out.println("No system java compiler available");
197 			return;
198 		}
199 		internalTest2(compiler, MODULE_PROC, "testModuleJavaBase3", null);
200 	}
testModuleJavaBase3()201 	public void testModuleJavaBase3() throws IOException {
202 		JavaCompiler compiler = BatchTestUtils.getEclipseCompiler();
203 		internalTest2(compiler, MODULE_PROC, "testModuleJavaBase3", null);
204 	}
205 
testModuleJavaBase4Javac()206 	public void testModuleJavaBase4Javac() throws IOException {
207 		JavaCompiler compiler = ToolProvider.getSystemJavaCompiler();
208 		if (compiler == null) {
209 			System.out.println("No system java compiler available");
210 			return;
211 		}
212 		internalTest2(compiler, MODULE_PROC, "testModuleJavaBase4", null);
213 	}
testModuleJavaBase4()214 	public void testModuleJavaBase4() throws IOException {
215 		JavaCompiler compiler = BatchTestUtils.getEclipseCompiler();
216 		internalTest2(compiler, MODULE_PROC, "testModuleJavaBase4", null);
217 	}
218 
testModuleJavaBase5Javac()219 	public void testModuleJavaBase5Javac() throws IOException {
220 		JavaCompiler compiler = ToolProvider.getSystemJavaCompiler();
221 		if (compiler == null) {
222 			System.out.println("No system java compiler available");
223 			return;
224 		}
225 		internalTest2(compiler, MODULE_PROC, "testModuleJavaBase5", null);
226 	}
testModuleJavaBase5()227 	public void testModuleJavaBase5() throws IOException {
228 		JavaCompiler compiler = BatchTestUtils.getEclipseCompiler();
229 		internalTest2(compiler, MODULE_PROC, "testModuleJavaBase5", null);
230 	}
231 
testModuleTypeMirror1Javac()232 	public void testModuleTypeMirror1Javac() throws IOException {
233 		JavaCompiler compiler = ToolProvider.getSystemJavaCompiler();
234 		if (compiler == null) {
235 			System.out.println("No system java compiler available");
236 			return;
237 		}
238 		internalTest2(compiler, MODULE_PROC, "testModuleTypeMirror1", null);
239 	}
testModuleTypeMirror1()240 	public void testModuleTypeMirror1() throws IOException {
241 		JavaCompiler compiler = BatchTestUtils.getEclipseCompiler();
242 		internalTest2(compiler, MODULE_PROC, "testModuleTypeMirror1", null);
243 	}
244 
testModuleTypeMirror2Javac()245 	public void testModuleTypeMirror2Javac() throws IOException {
246 		JavaCompiler compiler = ToolProvider.getSystemJavaCompiler();
247 		if (compiler == null) {
248 			System.out.println("No system java compiler available");
249 			return;
250 		}
251 		internalTest2(compiler, MODULE_PROC, "testModuleTypeMirror2", null);
252 	}
testModuleTypeMirror2()253 	public void testModuleTypeMirror2() throws IOException {
254 		JavaCompiler compiler = BatchTestUtils.getEclipseCompiler();
255 		internalTest2(compiler, MODULE_PROC, "testModuleTypeMirror2", null);
256 	}
257 
testModuleJavaSql1Javac()258 	public void testModuleJavaSql1Javac() throws IOException {
259 		JavaCompiler compiler = ToolProvider.getSystemJavaCompiler();
260 		if (compiler == null) {
261 			System.out.println("No system java compiler available");
262 			return;
263 		}
264 		internalTest2(compiler, MODULE_PROC, "testModuleJavaSql1", null);
265 	}
testModuleJavaSql1()266 	public void testModuleJavaSql1() throws IOException {
267 		JavaCompiler compiler = BatchTestUtils.getEclipseCompiler();
268 		internalTest2(compiler, MODULE_PROC, "testModuleJavaSql1", null);
269 	}
270 
testSourceModule1Javac()271 	public void testSourceModule1Javac() throws IOException {
272 		JavaCompiler compiler = ToolProvider.getSystemJavaCompiler();
273 		if (compiler == null) {
274 			System.out.println("No system java compiler available");
275 			return;
276 		}
277 		internalTest2(compiler, MODULE_PROC, "testSourceModule1", null);
278 	}
testSourceModule1()279 	public void testSourceModule1() throws IOException {
280 		JavaCompiler compiler = BatchTestUtils.getEclipseCompiler();
281 		internalTest2(compiler, MODULE_PROC, "testSourceModule1", null);
282 	}
283 
testSourceModule2Javac()284 	public void testSourceModule2Javac() throws IOException {
285 		JavaCompiler compiler = ToolProvider.getSystemJavaCompiler();
286 		if (compiler == null) {
287 			System.out.println("No system java compiler available");
288 			return;
289 		}
290 		internalTest2(compiler, MODULE_PROC, "testSourceModule2", null);
291 	}
testSourceModule2()292 	public void testSourceModule2() throws IOException {
293 		JavaCompiler compiler = BatchTestUtils.getEclipseCompiler();
294 		internalTest2(compiler, MODULE_PROC, "testSourceModule2", null);
295 	}
testUnnamedModule1Javac()296 	public void testUnnamedModule1Javac() throws IOException {
297 		JavaCompiler compiler = ToolProvider.getSystemJavaCompiler();
298 		if (compiler == null) {
299 			System.out.println("No system java compiler available");
300 			return;
301 		}
302 		internalTest(compiler, MODULE_PROC, "testUnnamedModule1", null, "model9");
303 	}
testUnnamedModule1()304 	public void testUnnamedModule1() throws IOException {
305 		JavaCompiler compiler = BatchTestUtils.getEclipseCompiler();
306 		internalTest(compiler, MODULE_PROC, "testUnnamedModule1", null, "model9");
307 	}
testUnnamedModule2Javac()308 	public void testUnnamedModule2Javac() throws IOException {
309 		JavaCompiler compiler = ToolProvider.getSystemJavaCompiler();
310 		if (compiler == null) {
311 			System.out.println("No system java compiler available");
312 			return;
313 		}
314 		internalTest(compiler, MODULE_PROC, "testUnnamedModule2", null, "model9");
315 	}
testUnnamedModule2()316 	public void testUnnamedModule2() throws IOException {
317 		JavaCompiler compiler = BatchTestUtils.getEclipseCompiler();
318 		internalTest(compiler, MODULE_PROC, "testUnnamedModule2", null, "model9");
319 	}
testUnnamedModule3Javac()320 	public void testUnnamedModule3Javac() throws IOException {
321 		JavaCompiler compiler = ToolProvider.getSystemJavaCompiler();
322 		if (compiler == null) {
323 			System.out.println("No system java compiler available");
324 			return;
325 		}
326 		internalTest(compiler, MODULE_PROC, "testUnnamedModule3", null, "model9a");
327 	}
testUnnamedModule3()328 	public void testUnnamedModule3() throws IOException {
329 		JavaCompiler compiler = BatchTestUtils.getEclipseCompiler();
330 		internalTest(compiler, MODULE_PROC, "testUnnamedModule3", null, "model9a");
331 	}
testUnnamedModule4Javac()332 	public void testUnnamedModule4Javac() throws IOException {
333 		JavaCompiler compiler = ToolProvider.getSystemJavaCompiler();
334 		if (compiler == null) {
335 			System.out.println("No system java compiler available");
336 			return;
337 		}
338 		internalTest(compiler, MODULE_PROC, "testUnnamedModule4", null, "model9a");
339 	}
testUnnamedModule4()340 	public void testUnnamedModule4() throws IOException {
341 		JavaCompiler compiler = BatchTestUtils.getEclipseCompiler();
342 		internalTest(compiler, MODULE_PROC, "testUnnamedModule4", null, "model9a");
343 	}
testUnnamedModule5Javac()344 	public void testUnnamedModule5Javac() throws IOException {
345 		JavaCompiler compiler = ToolProvider.getSystemJavaCompiler();
346 		if (compiler == null) {
347 			System.out.println("No system java compiler available");
348 			return;
349 		}
350 		internalTest(compiler, MODULE_PROC, "testUnnamedModule5", null, new String[] {
351 				"targets/model9x/X.java",
352 				"package targets.model9x;\n" +
353 				"public class X {\n" +
354 				"    X(final int j) {\n" +
355 				"        j = 4;\n" +
356 				"    }\n" +
357 				"}\n"
358 		});
359 	}
testUnnamedModule5()360 	public void testUnnamedModule5() throws IOException {
361 		JavaCompiler compiler = BatchTestUtils.getEclipseCompiler();
362 		internalTest(compiler, MODULE_PROC, "testUnnamedModule5", null, new String[] {
363 				"targets/model9x/X.java",
364 				"package targets.model9x;\n" +
365 				"public class X {\n" +
366 				"    X(final int j) {\n" +
367 				"        j = 4;\n" +
368 				"    }\n" +
369 				"}\n"
370 		});
371 	}
testBug521723()372 	public void testBug521723() throws IOException {
373 		JavaCompiler compiler = BatchTestUtils.getEclipseCompiler();
374 		internalTestWithBinary(compiler, MODULE_PROC, "9", "testBug521723", null, "bug521723");
375 	}
testBug521723Javac()376 	public void testBug521723Javac() throws IOException {
377 		JavaCompiler compiler = ToolProvider.getSystemJavaCompiler();
378 		internalTestWithBinary(compiler, MODULE_PROC, "9", "testBug521723", null, "bug521723");
379 	}
testDirectiveVisitorJavac()380 	public void testDirectiveVisitorJavac() throws IOException {
381 		JavaCompiler compiler = ToolProvider.getSystemJavaCompiler();
382 		internalTest2(compiler, MODULE_PROC, "testDirectiveVisitor", null);
383 	}
testTypesImpl()384 	public void testTypesImpl() throws IOException {
385 		JavaCompiler compiler = BatchTestUtils.getEclipseCompiler();
386 		internalTest2(compiler, MODULE_PROC, "testTypesImpl", null);
387 	}
testBug498022a()388 	public void testBug498022a() throws IOException {
389 		JavaCompiler compiler = BatchTestUtils.getEclipseCompiler();
390 		internalTest(compiler, MODULE_PROC, "testBug498022a", null, "model9");
391 	}
testBug498022aJavac()392 	public void testBug498022aJavac() throws IOException {
393 		JavaCompiler compiler = ToolProvider.getSystemJavaCompiler();
394 		internalTest(compiler, MODULE_PROC, "testBug498022a", null, "model9");
395 	}
testBug498022b()396 	public void testBug498022b() throws IOException {
397 		JavaCompiler compiler = BatchTestUtils.getEclipseCompiler();
398 		internalTest(compiler, MODULE_PROC, "testBug498022b", null, "model9");
399 	}
testBug498022bJavac()400 	public void testBug498022bJavac() throws IOException {
401 		JavaCompiler compiler = ToolProvider.getSystemJavaCompiler();
402 		internalTest(compiler, MODULE_PROC, "testBug498022b", null, "model9");
403 	}
testBug535819()404 	public void testBug535819() throws IOException {
405 		JavaCompiler compiler = BatchTestUtils.getEclipseCompiler();
406 		internalTest(compiler, MODULE_PROC, "testBug535819", null, "bug535819", true);
407 	}
internalTestWithBinary(JavaCompiler compiler, String processor, String compliance, String testMethod, String testClass, String resourceArea)408 	protected void internalTestWithBinary(JavaCompiler compiler, String processor, String compliance, String testMethod, String testClass, String resourceArea) throws IOException {
409 		if (!canRunJava9()) {
410 			return;
411 		}
412 		System.clearProperty(processor);
413 		File targetFolder = TestUtils.concatPath(BatchTestUtils.getSrcFolderName(), "targets", resourceArea);
414 		if (testClass == null || testClass.equals("")) {
415 			BatchTestUtils.copyResources("targets/" + resourceArea, targetFolder);
416 		} else {
417 			BatchTestUtils.copyResource("targets/" + resourceArea + "/" + testClass, targetFolder);
418 		}
419 
420 
421 		List<String> options = new ArrayList<String>();
422 		options.add("-A" + processor);
423 		options.add("-A" + testMethod);
424 		options.add("-processor");
425 		options.add(processor);
426 		// Javac 1.8 doesn't (yet?) support the -1.8 option
427 		if (compiler instanceof EclipseCompiler) {
428 			options.add("-" + compliance);
429 		} else {
430 			options.add("-source");
431 			options.add(compliance);
432 		}
433 		BatchTestUtils.compileTreeAndProcessBinaries(compiler, options, processor, targetFolder, null);
434 
435 		// If it succeeded, the processor will have set this property to "succeeded";
436 		// if not, it will set it to an error value.
437 		assertEquals("succeeded", System.getProperty(processor));
438 	}
internalTest(JavaCompiler compiler, String processor, String testMethod, String testClass, String[] source)439 	private void internalTest(JavaCompiler compiler, String processor, String testMethod, String testClass, String[] source) throws IOException {
440 		if (!canRunJava9()) {
441 			return;
442 		}
443 		if ((source.length % 2) != 0) return;
444 
445 		File targetFolder = TestUtils.concatPath(BatchTestUtils.getSrcFolderName());
446 		for(int i = 0; i < source.length;) {
447 			File targetFile = TestUtils.concatPath(BatchTestUtils.getSrcFolderName(), source[i++]);
448 			BatchTestUtils.writeFile(targetFile, source[i++].getBytes());
449 		}
450 
451 		List<String> options = new ArrayList<String>();
452 		options.add("-processor");
453 		options.add(MODULE_PROC);
454 		options.add("-A" + processor);
455 		options.add("-A" + testMethod);
456 		if (compiler instanceof EclipseCompiler) {
457 			options.add("-9");
458 		}
459 		BatchTestUtils.compileTreeWithErrors(compiler, options, targetFolder, null, true, true);
460 
461 		// If it succeeded, the processor will have set this property to "succeeded";
462 		// if not, it will set it to an error value.
463 		assertEquals("succeeded", System.getProperty(processor));
464 	}
internalTest(JavaCompiler compiler, String processor, String testMethod, String testClass, String resourceArea)465 	private void internalTest(JavaCompiler compiler, String processor, String testMethod, String testClass, String resourceArea) throws IOException {
466 		internalTest(compiler, processor, testMethod, testClass, resourceArea, false);
467 	}
internalTest(JavaCompiler compiler, String processor, String testMethod, String testClass, String resourceArea, boolean continueWithErrors)468 	private void internalTest(JavaCompiler compiler, String processor, String testMethod, String testClass, String resourceArea, boolean continueWithErrors) throws IOException {
469 		if (!canRunJava9()) {
470 			return;
471 		}
472 		System.clearProperty(processor);
473 		File targetFolder = TestUtils.concatPath(BatchTestUtils.getSrcFolderName(), "targets", resourceArea);
474 		if (testClass == null || testClass.equals("")) {
475 			BatchTestUtils.copyResources("targets/" + resourceArea, targetFolder);
476 		} else {
477 			BatchTestUtils.copyResource("targets/" + resourceArea + "/" + testClass, targetFolder);
478 		}
479 
480 
481 		List<String> options = new ArrayList<String>();
482 		options.add("-A" + processor);
483 		options.add("-A" + testMethod);
484 		if (compiler instanceof EclipseCompiler) {
485 			options.add("-9");
486 		}
487 		ByteArrayOutputStream errBuffer = new ByteArrayOutputStream();
488 		PrintWriter printWriter = new PrintWriter(errBuffer);
489 		TestDiagnosticListener diagnosticListener = new TestDiagnosticListener(printWriter);
490 		if (continueWithErrors) {
491 			BatchTestUtils.compileTreeWithErrors(compiler, options, targetFolder, diagnosticListener, true, true);
492 		} else {
493 			BatchTestUtils.compileTree(compiler, options, targetFolder, true);
494 		}
495 
496 		// If it succeeded, the processor will have set this property to "succeeded";
497 		// if not, it will set it to an error value.
498 		assertEquals("succeeded", System.getProperty(processor));
499 	}
500 	/*
501 	 * Tests are run in multi-module mode
502 	 */
internalTest2(JavaCompiler compiler, String processor, String testMethod, String testClass)503 	private void internalTest2(JavaCompiler compiler, String processor, String testMethod, String testClass) throws IOException {
504 		if (!canRunJava9()) {
505 			return;
506 		}
507 		System.clearProperty(MODULE_PROC);
508 		File srcRoot = TestUtils.concatPath(BatchTestUtils.getSrcFolderName());
509 		BatchTestUtils.copyResources("mod_locations/modules", srcRoot);
510 
511 		List<String> options = new ArrayList<String>();
512 		options.add("-processor");
513 		options.add(MODULE_PROC);
514 		options.add("-A" + MODULE_PROC);
515 		options.add("-A" + testMethod);
516 		if (compiler instanceof EclipseCompiler) {
517 			options.add("-9");
518 		}
519 		BatchTestUtils.compileInModuleMode(compiler, options, MODULE_PROC, srcRoot, null, true);
520 		assertEquals("succeeded", System.getProperty(MODULE_PROC));
521 	}
canRunJava9()522 	public boolean canRunJava9() {
523 		try {
524 			SourceVersion.valueOf("RELEASE_9");
525 		} catch(IllegalArgumentException iae) {
526 			return false;
527 		}
528 		return true;
529 	}
530 	/* (non-Javadoc)
531 	 * @see junit.framework.TestCase#setUp()
532 	 */
533 	@Override
setUp()534 	protected void setUp() throws Exception {
535 		super.setUp();
536 		BatchTestUtils.init();
537 	}
538 
539 	/* (non-Javadoc)
540 	 * @see junit.framework.TestCase#tearDown()
541 	 */
542 	@Override
tearDown()543 	protected void tearDown() throws Exception {
544 		super.tearDown();
545 	}
546 
547 }