929N/A/*
1011N/A * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
929N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
929N/A *
929N/A * This code is free software; you can redistribute it and/or modify it
929N/A * under the terms of the GNU General Public License version 2 only, as
929N/A * published by the Free Software Foundation.
929N/A *
929N/A * This code is distributed in the hope that it will be useful, but WITHOUT
929N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
929N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
929N/A * version 2 for more details (a copy is included in the LICENSE file that
929N/A * accompanied this code).
929N/A *
929N/A * You should have received a copy of the GNU General Public License version
929N/A * 2 along with this work; if not, write to the Free Software Foundation,
929N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
929N/A *
929N/A * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
929N/A * or visit www.oracle.com if you need additional information or have any
929N/A * questions.
929N/A */
929N/A
929N/A/*
929N/A * @test
929N/A * @bug 7026509
929N/A * @summary Cannot use JavaCompiler to create multiple CompilationTasks for partial compilations
929N/A */
929N/A
929N/Aimport java.io.*;
929N/Aimport java.util.*;
929N/Aimport javax.tools.*;
929N/Aimport javax.tools.JavaCompiler.CompilationTask;
929N/Aimport com.sun.source.util.*;
929N/A
929N/Apublic class TestJavacTask_Lock {
929N/A public static void main(String... args) throws Exception {
929N/A new TestJavacTask_Lock().run();
929N/A }
929N/A
929N/A enum MethodKind {
929N/A CALL {
929N/A int test(CompilationTask t) {
929N/A boolean ok = t.call();
929N/A if (!ok)
929N/A throw new Error("compilation failed");
929N/A return 1;
929N/A }
929N/A },
929N/A PARSE {
929N/A int test(CompilationTask t) {
929N/A try {
929N/A ((JavacTask) t).parse();
929N/A return 1;
929N/A } catch (IOException ex) {
929N/A throw new Error(ex);
929N/A }
929N/A }
929N/A
929N/A };
929N/A abstract int test(CompilationTask t);
929N/A }
929N/A
929N/A JavaCompiler comp;
929N/A StandardJavaFileManager fm;
929N/A
929N/A void run() throws Exception {
929N/A comp = ToolProvider.getSystemJavaCompiler();
929N/A fm = comp.getStandardFileManager(null, null, null);
929N/A
929N/A for (MethodKind first: MethodKind.values()) {
929N/A for (MethodKind second: MethodKind.values()) {
929N/A test(first, second);
929N/A }
929N/A }
929N/A
929N/A if (errors > 0)
929N/A throw new Exception(errors + " errors found");
929N/A }
929N/A
929N/A void test(MethodKind first, MethodKind second) {
929N/A System.err.println("test: " + first + ", " + second);
929N/A File testSrc = new File(System.getProperty("test.src"));
929N/A String thisClassName = TestJavacTask_Lock.class.getName();
929N/A Iterable<? extends JavaFileObject> files =
929N/A fm.getJavaFileObjects(new File(testSrc, thisClassName + ".java"));
929N/A File tmpDir = new File(first + "_" + second);
929N/A tmpDir.mkdirs();
929N/A List<String> options = Arrays.asList( "-d", tmpDir.getPath() );
929N/A CompilationTask t = comp.getTask(null, fm, null, options, null, files);
929N/A
929N/A try {
929N/A first.test(t);
929N/A second.test(t);
929N/A error("No exception thrown");
929N/A } catch (IllegalStateException e) {
929N/A System.err.println("Expected exception caught: " + e);
929N/A } catch (Exception e) {
929N/A error("Unexpected exception caught: " + e);
929N/A e.printStackTrace(System.err);
929N/A }
929N/A
929N/A }
929N/A
929N/A void error(String msg) {
929N/A System.err.println("Error: " + msg);
929N/A errors++;
929N/A }
929N/A
929N/A int errors;
929N/A}