aoqi@0: /* aoqi@0: * Copyright (c) 2012, Oracle and/or its affiliates. All rights reserved. aoqi@0: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. aoqi@0: * aoqi@0: * This code is free software; you can redistribute it and/or modify it aoqi@0: * under the terms of the GNU General Public License version 2 only, as aoqi@0: * published by the Free Software Foundation. aoqi@0: * aoqi@0: * This code is distributed in the hope that it will be useful, but WITHOUT aoqi@0: * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or aoqi@0: * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License aoqi@0: * version 2 for more details (a copy is included in the LICENSE file that aoqi@0: * accompanied this code). aoqi@0: * aoqi@0: * You should have received a copy of the GNU General Public License version aoqi@0: * 2 along with this work; if not, write to the Free Software Foundation, aoqi@0: * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. aoqi@0: * aoqi@0: * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA aoqi@0: * or visit www.oracle.com if you need additional information or have any aoqi@0: * questions. aoqi@0: */ aoqi@0: aoqi@0: /* aoqi@0: * @test aoqi@0: * @bug 7142672 aoqi@0: * @summary Problems with the value passed to the 'classes' param of JavaCompiler.CompilationTask.getTask(...) aoqi@0: * @author holmlund aoqi@0: * @compile AnnoProcessor.java Bug.java Test3.java aoqi@0: * @run main Bug Test2.java aoqi@0: * @run main Bug Test2.foo aoqi@0: * @run main Bug Test3.java aoqi@0: */ aoqi@0: import java.io.*; aoqi@0: import java.util.*; aoqi@0: import javax.tools.*; aoqi@0: aoqi@0: // Each run should output the 'could not find class file' message, and not throw an AssertError. aoqi@0: public class Bug { aoqi@0: public static void main(String... arg) throws Throwable { aoqi@0: String name = arg[0]; aoqi@0: final String expectedMsg = "error: Could not find class file for '" + name + "'."; aoqi@0: JavaCompiler javac = ToolProvider.getSystemJavaCompiler(); aoqi@0: JavaCompiler.CompilationTask task2; aoqi@0: StringWriter sw = new StringWriter(); aoqi@0: final PrintWriter pw = new PrintWriter(sw); aoqi@0: aoqi@0: aoqi@0: DiagnosticListener dl = aoqi@0: new DiagnosticListener() { aoqi@0: public void report(Diagnostic message) { aoqi@0: pw.print("Diagnostic:\n"+ message.toString()+"\n"); aoqi@0: if (!message.toString().equals(expectedMsg)){ aoqi@0: System.err.println("Diagnostic:\n"+ message.toString()+"\n"); aoqi@0: System.err.println("--Failed: Unexpected diagnostic"); aoqi@0: System.exit(1); aoqi@0: } aoqi@0: } aoqi@0: }; aoqi@0: aoqi@0: StandardJavaFileManager sjfm = javac.getStandardFileManager(dl,null,null); aoqi@0: aoqi@0: List opts = new ArrayList(); aoqi@0: opts.add("-proc:only"); aoqi@0: opts.add("-processor"); aoqi@0: opts.add("AnnoProcessor"); aoqi@0: aoqi@0: boolean xxx; aoqi@0: aoqi@0: System.err.println("\n-- " + name); aoqi@0: task2 = javac.getTask(pw, sjfm, dl, opts, Arrays.asList(name), null); aoqi@0: xxx = task2.call(); aoqi@0: aoqi@0: String out = sw.toString(); aoqi@0: System.err.println(out); aoqi@0: if (out.contains("Assert")) { aoqi@0: System.err.println("--Failed: Assertion failure"); aoqi@0: System.exit(1); aoqi@0: } aoqi@0: if (!out.contains(expectedMsg)) { aoqi@0: System.err.println("--Failed: Expected diagnostic not found"); aoqi@0: System.exit(1); aoqi@0: } aoqi@0: } aoqi@0: }