jjg@897: /* jjg@897: * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved. jjg@897: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. jjg@897: * jjg@897: * This code is free software; you can redistribute it and/or modify it jjg@897: * under the terms of the GNU General Public License version 2 only, as jjg@897: * published by the Free Software Foundation. jjg@897: * jjg@897: * This code is distributed in the hope that it will be useful, but WITHOUT jjg@897: * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or jjg@897: * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License jjg@897: * version 2 for more details (a copy is included in the LICENSE file that jjg@897: * accompanied this code). jjg@897: * jjg@897: * You should have received a copy of the GNU General Public License version jjg@897: * 2 along with this work; if not, write to the Free Software Foundation, jjg@897: * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. jjg@897: * jjg@897: * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA jjg@897: * or visit www.oracle.com if you need additional information or have any jjg@897: * questions. jjg@897: */ jjg@897: jjg@897: jjg@897: /* jjg@897: * @test jjg@897: * @bug 7022337 jjg@897: * @summary repeated warnings about bootclasspath not set darcy@1466: * @library /tools/javac/lib jjg@897: * @build JavacTestingAbstractProcessor T7022337 jjg@897: * @run main T7022337 jjg@897: */ jjg@897: jjg@897: import java.io.*; jjg@897: import java.util.*; jjg@897: import javax.annotation.processing.*; jjg@897: import javax.lang.model.element.*; jjg@897: import javax.tools.*; jjg@897: jjg@897: public class T7022337 extends JavacTestingAbstractProcessor { jjg@897: public static void main(String... args) throws Exception { jjg@897: new T7022337().run(); jjg@897: } jjg@897: jjg@897: void run() throws Exception { jjg@897: String myName = T7022337.class.getSimpleName(); jjg@897: File testSrc = new File(System.getProperty("test.src")); jjg@897: File file = new File(testSrc, myName + ".java"); jjg@897: jjg@897: String out = compile( jjg@897: "-XDrawDiagnostics", jjg@897: "-d", ".", jjg@897: "-processor", myName, jjg@897: "-source", "6", // explicit use of older source value without bootclasspath jjg@897: file.getPath()); jjg@897: jjg@897: int count = 0; jjg@897: for (String line: out.split("[\r\n]+")) { jjg@897: if (line.contains("compiler.warn.source.no.bootclasspath")) jjg@897: count++; jjg@897: } jjg@897: if (count != 1) jjg@897: throw new Exception("unexpected number of warnings found: " + count + ", expected: 1"); jjg@897: } jjg@897: jjg@897: String compile(String... args) throws Exception { jjg@897: StringWriter sw = new StringWriter(); jjg@897: PrintWriter pw = new PrintWriter(sw); jjg@897: int rc = com.sun.tools.javac.Main.compile(args, pw); jjg@897: pw.close(); jjg@897: String out = sw.toString(); jjg@897: if (!out.isEmpty()) jjg@897: System.err.println(out); jjg@897: if (rc != 0) jjg@897: throw new Exception("compilation failed unexpectedly: rc=" + rc); jjg@897: return out; jjg@897: } jjg@897: jjg@897: // ---------- jjg@897: jjg@897: int round = 0; jjg@897: jjg@897: @Override jjg@897: public boolean process(Set annotations, RoundEnvironment roundEnv) { jjg@897: round++; jjg@897: jjg@897: final int MAXROUNDS = 3; jjg@897: if (round < MAXROUNDS) jjg@897: generate("Gen" + round); jjg@897: jjg@897: return true; jjg@897: } jjg@897: jjg@897: void generate(String name) { jjg@897: try { jjg@897: JavaFileObject fo = filer.createSourceFile(name); jjg@897: Writer out = fo.openWriter(); jjg@897: try { jjg@897: out.write("class " + name + " { }"); jjg@897: } finally { jjg@897: out.close(); jjg@897: } jjg@897: } catch (IOException e) { jjg@897: throw new Error(e); jjg@897: } jjg@897: } jjg@897: }