T6358166.java revision 3573:c4a18ee691c4
1238104Sdes/* 2238104Sdes * Copyright (c) 2006, 2016, Oracle and/or its affiliates. All rights reserved. 3238104Sdes * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4238104Sdes * 5238104Sdes * This code is free software; you can redistribute it and/or modify it 6238104Sdes * under the terms of the GNU General Public License version 2 only, as 7238104Sdes * published by the Free Software Foundation. 8238104Sdes * 9238104Sdes * This code is distributed in the hope that it will be useful, but WITHOUT 10238104Sdes * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 11238104Sdes * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 12238104Sdes * version 2 for more details (a copy is included in the LICENSE file that 13238104Sdes * accompanied this code). 14238104Sdes * 15238104Sdes * You should have received a copy of the GNU General Public License version 16238104Sdes * 2 along with this work; if not, write to the Free Software Foundation, 17238104Sdes * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 18238104Sdes * 19238104Sdes * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 20238104Sdes * or visit www.oracle.com if you need additional information or have any 21238104Sdes * questions. 22238104Sdes */ 23238104Sdes 24238104Sdes/* 25238104Sdes * @test 26238104Sdes * @bug 6358166 27238104Sdes * @summary -verbose reports absurd times when annotation processing involved 28238104Sdes * @modules jdk.compiler/com.sun.tools.javac.api 29238104Sdes * jdk.compiler/com.sun.tools.javac.file 30238104Sdes * jdk.compiler/com.sun.tools.javac.main 31238104Sdes * jdk.compiler/com.sun.tools.javac.util 32238104Sdes */ 33238104Sdes 34238104Sdesimport java.io.*; 35238104Sdesimport java.util.*; 36238104Sdes 37238104Sdesimport javax.annotation.processing.*; 38238104Sdesimport javax.lang.model.element.*; 39238104Sdesimport javax.tools.*; 40238104Sdes 41238104Sdesimport com.sun.tools.javac.api.JavacTaskImpl; 42238104Sdesimport com.sun.tools.javac.api.JavacTool; 43266114Sdesimport com.sun.tools.javac.file.JavacFileManager; 44238104Sdesimport com.sun.tools.javac.main.JavaCompiler; 45238104Sdesimport com.sun.tools.javac.util.Context; 46266114Sdes 47266114Sdes 48266114Sdes@SupportedAnnotationTypes("*") 49238104Sdespublic class T6358166 extends AbstractProcessor { 50266114Sdes public static void main(String... args) throws Throwable { 51238104Sdes String self = T6358166.class.getName(); 52266114Sdes 53238104Sdes String testSrc = System.getProperty("test.src"); 54266114Sdes 55238104Sdes JavacFileManager fm = new JavacFileManager(new Context(), false, null); 56266114Sdes JavaFileObject f = fm.getJavaFileObject(testSrc + File.separatorChar + self + ".java"); 57238104Sdes 58266114Sdes List<String> addExports = Arrays.asList( 59238104Sdes "--add-exports", "jdk.compiler/com.sun.tools.javac.api=ALL-UNNAMED", 60266114Sdes "--add-exports", "jdk.compiler/com.sun.tools.javac.file=ALL-UNNAMED", 61238104Sdes "--add-exports", "jdk.compiler/com.sun.tools.javac.main=ALL-UNNAMED", 62266114Sdes "--add-exports", "jdk.compiler/com.sun.tools.javac.util=ALL-UNNAMED"); 63238104Sdes 64266114Sdes test(fm, f, addExports, "-verbose", "-d", "."); 65266114Sdes 66266114Sdes test(fm, f, addExports, "-verbose", "-d", ".", "-XprintRounds", "-processorpath", ".", "-processor", self); 67266114Sdes } 68238104Sdes 69266114Sdes static void test(JavacFileManager fm, JavaFileObject f, List<String> addExports, String... args) throws Throwable { 70266114Sdes List<String> allArgs = new ArrayList<>(); 71266114Sdes allArgs.addAll(addExports); 72266114Sdes allArgs.addAll(Arrays.asList(args)); 73266114Sdes 74266114Sdes Context context = new Context(); 75266114Sdes 76238104Sdes JavacTool tool = JavacTool.create(); 77238104Sdes JavacTaskImpl task = (JavacTaskImpl) tool.getTask(null, fm, null, allArgs, null, List.of(f), context); 78238104Sdes task.call(); 79238104Sdes 80238104Sdes JavaCompiler c = JavaCompiler.instance(context); 81238104Sdes if (c.errorCount() != 0) 82238104Sdes throw new AssertionError("compilation failed"); 83238104Sdes 84238104Sdes long msec = c.elapsed_msec; 85238104Sdes if (msec < 0 || msec > 5 * 60 * 1000) // allow test 5 mins to execute, should be more than enough! 86238104Sdes throw new AssertionError("elapsed time is suspect: " + msec); 87238104Sdes } 88238104Sdes 89238104Sdes public boolean process(Set<? extends TypeElement> tes, RoundEnvironment renv) { 90238104Sdes return true; 91238104Sdes } 92238104Sdes} 93238104Sdes