T6358024.java revision 3573:c4a18ee691c4
1102227Smike/* 2102227Smike * Copyright (c) 2006, 2016, Oracle and/or its affiliates. All rights reserved. 3102227Smike * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4102227Smike * 5102227Smike * This code is free software; you can redistribute it and/or modify it 6102227Smike * under the terms of the GNU General Public License version 2 only, as 7102227Smike * published by the Free Software Foundation. 8102227Smike * 9102227Smike * This code is distributed in the hope that it will be useful, but WITHOUT 10102227Smike * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 11102227Smike * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 12102227Smike * version 2 for more details (a copy is included in the LICENSE file that 13102227Smike * accompanied this code). 14102227Smike * 15102227Smike * You should have received a copy of the GNU General Public License version 16102227Smike * 2 along with this work; if not, write to the Free Software Foundation, 17102227Smike * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 18102227Smike * 19102227Smike * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 20102227Smike * or visit www.oracle.com if you need additional information or have any 21102227Smike * questions. 22102227Smike */ 23102227Smike 24102227Smike/* 25102227Smike * @test 26102227Smike * @bug 6358024 27102227Smike * @summary TaskListener should be propogated between processing rounds 28102227Smike * @modules jdk.compiler/com.sun.tools.javac.api 29102227Smike * jdk.compiler/com.sun.tools.javac.file 30102227Smike * jdk.compiler/com.sun.tools.javac.util 31102227Smike */ 32102227Smike 33102227Smikeimport java.io.*; 34102227Smikeimport java.util.*; 35102227Smikeimport java.util.List; 36102227Smikeimport javax.annotation.processing.*; 37102227Smikeimport javax.lang.model.element.*; 38143063Sjoergimport javax.tools.*; 39143063Sjoergimport com.sun.source.util.*; 40143063Sjoergimport com.sun.tools.javac.api.*; 41143063Sjoergimport com.sun.tools.javac.file.JavacFileManager; 42102227Smikeimport com.sun.tools.javac.util.*; 43102227Smike 44102227Smike 45102227Smike@SupportedAnnotationTypes("*") 46102227Smikepublic class T6358024 extends AbstractProcessor { 47102227Smike static JavacFileManager fm; 48102227Smike public static void main(String... args) throws Throwable { 49102227Smike String self = T6358024.class.getName(); 50102227Smike 51102227Smike String testSrc = System.getProperty("test.src"); 52102227Smike 53102227Smike fm = new JavacFileManager(new Context(), false, null); 54102227Smike JavaFileObject f = fm.getJavaFileObject(testSrc + File.separatorChar + self + ".java"); 55102227Smike 56102227Smike test(fm, f, 57102227Smike new Option[] { new Option("-d", ".")}, 58127239Smarcel 8); 59102227Smike 60110566Smike test(fm, f, 61110566Smike new Option[] { new XOption("-XprintRounds"), 62102227Smike new Option("-processorpath", "."), 63102227Smike new Option("-processor", self) }, 64102227Smike 13); 65102227Smike } 66102227Smike 67102227Smike static void test(JavacFileManager fm, JavaFileObject f, Option[] opts, int expect) throws Throwable { 68102227Smike PrintWriter out = new PrintWriter(System.err, true); 69102227Smike 70102227Smike JavacTool tool = JavacTool.create(); 71102227Smike List<String> flags = new ArrayList<String>(); 72102227Smike flags.addAll(Arrays.asList( 73102227Smike "--add-exports", "jdk.compiler/com.sun.tools.javac.api=ALL-UNNAMED", 74102227Smike "--add-exports", "jdk.compiler/com.sun.tools.javac.file=ALL-UNNAMED", 75102227Smike "--add-exports", "jdk.compiler/com.sun.tools.javac.util=ALL-UNNAMED")); 76102227Smike for (Option opt: opts) { 77102227Smike flags.add(opt.name); 78126817Sgad for (Object arg : opt.args) 79102227Smike flags.add(arg.toString()); 80102227Smike } 81102227Smike 82102227Smike JavacTaskImpl task = (JavacTaskImpl) tool.getTask(out, 83102227Smike fm, 84102227Smike null, 85102227Smike flags, 86102227Smike null, 87102227Smike Arrays.asList(f)); 88102227Smike MyTaskListener tl = new MyTaskListener(); 89102227Smike task.setTaskListener(tl); 90102227Smike task.call(); 91102227Smike if (tl.started != expect) 92102227Smike throw new AssertionError("Unexpected number of TaskListener events; " 93112569Sjake + "expected " + expect + ", found " + tl.started); 94102227Smike } 95102227Smike 96102227Smike public boolean process(Set<? extends TypeElement> tes, RoundEnvironment renv) { 97102227Smike return true; 98102227Smike } 99102227Smike 100143063Sjoerg static class MyTaskListener implements TaskListener { 101102227Smike public void started(TaskEvent e) { 102102227Smike System.err.println("Started: " + e); 103102227Smike started++; 104143063Sjoerg } 105143063Sjoerg public void finished(TaskEvent e) { 106143063Sjoerg } 107102227Smike 108102227Smike int started = 0; 109102227Smike } 110102227Smike 111102227Smike static class Option { 112 Option(String name, String... args) { 113 this.name = name; 114 this.args = args; 115 } 116 public final String name; 117 public final String[] args; 118 } 119 120 static class XOption extends Option { 121 XOption(String name, String... args) { 122 super(name, args); 123 } 124 } 125} 126