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