Thu, 07 Jun 2012 20:30:57 -0700
7170079: Adjustments to build-infra makefiles
Reviewed-by: ohair, ohrstrom, ihse, jonas
Contributed-by: jonas <jonas.oreland@oracle.com>, erikj <erik.joelsson@oracle.com>, ihse <magnus.ihse.bursie@oracle.com>, tgranat <torbjorn.granat@oracle.com>, ykantser <yekaterina.kantserova@oracle.com>
1 /*
2 * Copyright (c) 2011, 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 */
25 /*
26 * @test
27 * @bug 7022337
28 * @summary repeated warnings about bootclasspath not set
29 * @library ../lib
30 * @build JavacTestingAbstractProcessor T7022337
31 * @run main T7022337
32 */
34 import java.io.*;
35 import java.util.*;
36 import javax.annotation.processing.*;
37 import javax.lang.model.element.*;
38 import javax.tools.*;
40 public class T7022337 extends JavacTestingAbstractProcessor {
41 public static void main(String... args) throws Exception {
42 new T7022337().run();
43 }
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");
50 String out = compile(
51 "-XDrawDiagnostics",
52 "-d", ".",
53 "-processor", myName,
54 "-source", "6", // explicit use of older source value without bootclasspath
55 file.getPath());
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 }
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 }
79 // ----------
81 int round = 0;
83 @Override
84 public boolean process(Set<? extends TypeElement> annotations, RoundEnvironment roundEnv) {
85 round++;
87 final int MAXROUNDS = 3;
88 if (round < MAXROUNDS)
89 generate("Gen" + round);
91 return true;
92 }
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 }