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