author | akulyakh |
Thu, 21 May 2015 11:41:04 -0700 (2015-05-21) | |
changeset 30730 | d3ce7619db2c |
parent 5520 | 86e4b9a9da40 |
permissions | -rw-r--r-- |
10 | 1 |
/* |
30730
d3ce7619db2c
8076543: Add @modules as needed to the langtools tests
akulyakh
parents:
5520
diff
changeset
|
2 |
* Copyright (c) 2006, 2015, Oracle and/or its affiliates. All rights reserved. |
10 | 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 |
* |
|
5520 | 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. |
|
10 | 22 |
*/ |
23 |
||
24 |
/* |
|
25 |
* @test |
|
26 |
* @bug 6350124 6410012 |
|
30730
d3ce7619db2c
8076543: Add @modules as needed to the langtools tests
akulyakh
parents:
5520
diff
changeset
|
27 |
* @modules java.compiler |
d3ce7619db2c
8076543: Add @modules as needed to the langtools tests
akulyakh
parents:
5520
diff
changeset
|
28 |
* jdk.compiler |
10 | 29 |
* @summary javac -s does not have the generated source files |
30 |
*/ |
|
31 |
||
32 |
import java.io.File; |
|
33 |
import java.io.PrintWriter; |
|
34 |
import javax.tools.Tool; |
|
35 |
import javax.tools.ToolProvider; |
|
36 |
||
37 |
public class T6350124 { |
|
38 |
public static void main(String[] args) { |
|
39 |
String classpath = System.getProperty("java.class.path"); |
|
40 |
File srcDir = new File(System.getProperty("test.src")); |
|
41 |
||
42 |
// ensure the output directories are empty |
|
43 |
mkCleanDir(new File("aClasses")); |
|
44 |
mkCleanDir(new File("newClasses")); |
|
45 |
mkCleanDir(new File("newSrc")); |
|
46 |
||
47 |
// compile the annotation processor |
|
48 |
compile("-cp", classpath, |
|
49 |
"-d", "aClasses", path(srcDir, "HelloWorldAP.java")); |
|
50 |
||
51 |
// compile the test program, invoking the anotation processor |
|
52 |
compile("-cp", classpath, |
|
53 |
"-sourcepath", srcDir.getPath(), |
|
54 |
"-d", "newClasses", |
|
55 |
"-s", "newSrc", |
|
56 |
"-processorpath", "aClasses", |
|
57 |
"-processor", "HelloWorldAP", // specify processor for simplicity |
|
58 |
"-proc:only", |
|
59 |
path(srcDir, "Marked.java")); |
|
60 |
||
61 |
File hw = new File("newSrc", "HelloWorld.java"); |
|
62 |
if (!hw.exists()) |
|
63 |
throw new AssertionError("generated source file not found"); |
|
64 |
||
65 |
File dc = new File("newClasses", "HelloWorldAP.class"); |
|
66 |
if (!dc.exists()) |
|
67 |
throw new AssertionError("generated class file not found"); |
|
68 |
} |
|
69 |
||
70 |
//--- the following can be considered "library code" for the test |
|
71 |
||
72 |
// note: jtreg @clean will only clean class files; not source files |
|
73 |
static void clean(File file) { |
|
74 |
if (!file.exists()) |
|
75 |
return; |
|
76 |
if (file.isDirectory()) { |
|
77 |
for (File f: file.listFiles()) |
|
78 |
clean(f); |
|
79 |
} |
|
80 |
file.delete(); |
|
81 |
} |
|
82 |
||
83 |
static void mkCleanDir(File dir) { |
|
84 |
clean(dir); |
|
85 |
dir.mkdirs(); |
|
86 |
} |
|
87 |
||
88 |
// note: jtreg @compile does not allow -d to be specified |
|
89 |
static void compile(String... args) { |
|
90 |
StringBuffer sb = new StringBuffer("compile:"); |
|
91 |
for (String a: args) |
|
92 |
sb.append(' ').append(a); |
|
93 |
System.err.println(sb); |
|
94 |
||
95 |
Tool t = ToolProvider.getSystemJavaCompiler(); |
|
96 |
int rc = t.run(System.in, System.out, System.err, args); |
|
97 |
System.out.flush(); |
|
98 |
System.err.flush(); |
|
99 |
if (rc != 0) |
|
100 |
throw new Error("compilation failed"); |
|
101 |
} |
|
102 |
||
103 |
static String path(File dir, String name) { |
|
104 |
return new File(dir, name).getPath(); |
|
105 |
} |
|
106 |
} |