author | lana |
Thu, 21 Jan 2016 09:46:01 -0800 | |
changeset 35340 | 38f7386ed942 |
parent 34752 | 9c262a013456 |
permissions | -rw-r--r-- |
8618 | 1 |
/* |
30730
d3ce7619db2c
8076543: Add @modules as needed to the langtools tests
akulyakh
parents:
25445
diff
changeset
|
2 |
* Copyright (c) 2011, 2015, Oracle and/or its affiliates. All rights reserved. |
8618 | 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 |
*/ |
|
23 |
||
24 |
/* |
|
25 |
* @test |
|
26 |
* @bug 7022337 |
|
27 |
* @summary repeated warnings about bootclasspath not set |
|
14963
974d4423c999
8005282: Use @library tag with non-relative path for javac tests
darcy
parents:
8618
diff
changeset
|
28 |
* @library /tools/javac/lib |
30730
d3ce7619db2c
8076543: Add @modules as needed to the langtools tests
akulyakh
parents:
25445
diff
changeset
|
29 |
* @modules jdk.compiler |
8618 | 30 |
* @build JavacTestingAbstractProcessor T7022337 |
31 |
* @run main T7022337 |
|
32 |
*/ |
|
33 |
||
34 |
import java.io.*; |
|
35 |
import java.util.*; |
|
36 |
import javax.annotation.processing.*; |
|
37 |
import javax.lang.model.element.*; |
|
38 |
import javax.tools.*; |
|
39 |
||
40 |
public class T7022337 extends JavacTestingAbstractProcessor { |
|
41 |
public static void main(String... args) throws Exception { |
|
42 |
new T7022337().run(); |
|
43 |
} |
|
44 |
||
45 |
void run() throws Exception { |
|
46 |
String myName = T7022337.class.getSimpleName(); |
|
47 |
File testSrc = new File(System.getProperty("test.src")); |
|
48 |
File file = new File(testSrc, myName + ".java"); |
|
49 |
||
50 |
String out = compile( |
|
51 |
"-XDrawDiagnostics", |
|
52 |
"-d", ".", |
|
53 |
"-processor", myName, |
|
25445
603f0c93d5c9
8011044: Remove support for 1.5 and earlier source and target options
ntoda
parents:
14963
diff
changeset
|
54 |
"-source", "8", // explicit use of older source value without bootclasspath |
8618 | 55 |
file.getPath()); |
56 |
||
57 |
int count = 0; |
|
58 |
for (String line: out.split("[\r\n]+")) { |
|
59 |
if (line.contains("compiler.warn.source.no.bootclasspath")) |
|
60 |
count++; |
|
61 |
} |
|
62 |
if (count != 1) |
|
63 |
throw new Exception("unexpected number of warnings found: " + count + ", expected: 1"); |
|
64 |
} |
|
65 |
||
66 |
String compile(String... args) throws Exception { |
|
67 |
StringWriter sw = new StringWriter(); |
|
68 |
PrintWriter pw = new PrintWriter(sw); |
|
69 |
int rc = com.sun.tools.javac.Main.compile(args, pw); |
|
70 |
pw.close(); |
|
71 |
String out = sw.toString(); |
|
72 |
if (!out.isEmpty()) |
|
73 |
System.err.println(out); |
|
74 |
if (rc != 0) |
|
75 |
throw new Exception("compilation failed unexpectedly: rc=" + rc); |
|
76 |
return out; |
|
77 |
} |
|
78 |
||
79 |
// ---------- |
|
80 |
||
81 |
int round = 0; |
|
82 |
||
83 |
@Override |
|
84 |
public boolean process(Set<? extends TypeElement> annotations, RoundEnvironment roundEnv) { |
|
85 |
round++; |
|
86 |
||
87 |
final int MAXROUNDS = 3; |
|
88 |
if (round < MAXROUNDS) |
|
89 |
generate("Gen" + round); |
|
90 |
||
91 |
return true; |
|
92 |
} |
|
93 |
||
94 |
void generate(String name) { |
|
95 |
try { |
|
96 |
JavaFileObject fo = filer.createSourceFile(name); |
|
97 |
Writer out = fo.openWriter(); |
|
98 |
try { |
|
99 |
out.write("class " + name + " { }"); |
|
100 |
} finally { |
|
101 |
out.close(); |
|
102 |
} |
|
103 |
} catch (IOException e) { |
|
104 |
throw new Error(e); |
|
105 |
} |
|
106 |
} |
|
107 |
} |