duke@1: /* ohair@798: * Copyright (c) 2006, 2010, Oracle and/or its affiliates. All rights reserved. duke@1: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. duke@1: * duke@1: * This code is free software; you can redistribute it and/or modify it duke@1: * under the terms of the GNU General Public License version 2 only, as duke@1: * published by the Free Software Foundation. duke@1: * duke@1: * This code is distributed in the hope that it will be useful, but WITHOUT duke@1: * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or duke@1: * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License duke@1: * version 2 for more details (a copy is included in the LICENSE file that duke@1: * accompanied this code). duke@1: * duke@1: * You should have received a copy of the GNU General Public License version duke@1: * 2 along with this work; if not, write to the Free Software Foundation, duke@1: * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. duke@1: * ohair@554: * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA ohair@554: * or visit www.oracle.com if you need additional information or have any ohair@554: * questions. duke@1: */ duke@1: duke@1: /* duke@1: * @test duke@1: * @bug 6358024 duke@1: * @summary TaskListener should be propogated between processing rounds duke@1: */ duke@1: duke@1: import java.io.*; duke@1: import java.util.*; duke@1: import java.util.List; duke@1: import javax.annotation.processing.*; duke@1: import javax.lang.model.element.*; duke@1: import javax.tools.*; duke@1: import com.sun.source.util.*; duke@1: import com.sun.tools.javac.api.*; jjg@50: import com.sun.tools.javac.file.*; jjg@58: import com.sun.tools.javac.file.JavacFileManager; duke@1: import com.sun.tools.javac.main.*; duke@1: import com.sun.tools.javac.util.*; duke@1: duke@1: duke@1: @SupportedAnnotationTypes("*") duke@1: public class T6358024 extends AbstractProcessor { duke@1: static JavacFileManager fm; duke@1: public static void main(String... args) throws Throwable { duke@1: String self = T6358024.class.getName(); duke@1: duke@1: String testSrc = System.getProperty("test.src"); duke@1: duke@1: fm = new JavacFileManager(new Context(), false, null); duke@1: JavaFileObject f = fm.getFileForInput(testSrc + File.separatorChar + self + ".java"); duke@1: duke@1: test(fm, f, duke@1: new Option[] { new Option("-d", ".")}, duke@1: 7); duke@1: duke@1: test(fm, f, duke@1: new Option[] { new XOption("-XprintRounds"), duke@1: new Option("-processorpath", "."), duke@1: new Option("-processor", self) }, jjg@642: 12); duke@1: } duke@1: duke@1: static void test(JavacFileManager fm, JavaFileObject f, Option[] opts, int expect) throws Throwable { duke@1: PrintWriter out = new PrintWriter(System.err, true); duke@1: duke@1: JavacTool tool = JavacTool.create(); duke@1: List flags = new ArrayList(); duke@1: for (Option opt: opts) { duke@1: flags.add(opt.name); duke@1: for (Object arg : opt.args) duke@1: flags.add(arg.toString()); duke@1: } duke@1: duke@1: JavacTaskImpl task = (JavacTaskImpl) tool.getTask(out, duke@1: fm, duke@1: null, duke@1: flags, duke@1: null, duke@1: Arrays.asList(f)); duke@1: MyTaskListener tl = new MyTaskListener(); duke@1: task.setTaskListener(tl); duke@1: task.call(); duke@1: if (tl.started != expect) duke@1: throw new AssertionError("Unexpected number of TaskListener events; " duke@1: + "expected " + expect + ", found " + tl.started); duke@1: } duke@1: duke@1: public boolean process(Set tes, RoundEnvironment renv) { duke@1: return true; duke@1: } duke@1: duke@1: static class MyTaskListener implements TaskListener { duke@1: public void started(TaskEvent e) { duke@1: System.err.println("Started: " + e); duke@1: started++; duke@1: } duke@1: public void finished(TaskEvent e) { duke@1: } duke@1: duke@1: int started = 0; duke@1: } duke@1: duke@1: static class Option { duke@1: Option(String name, String... args) { duke@1: this.name = name; duke@1: this.args = args; duke@1: } duke@1: public final String name; duke@1: public final String[] args; duke@1: } duke@1: duke@1: static class XOption extends Option { duke@1: XOption(String name, String... args) { duke@1: super(name, args); duke@1: } duke@1: } duke@1: }