T6358166.java revision 2599:50b448c5be54
1/*
2 * Copyright (c) 2006, 2014, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation.
8 *
9 * This code is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
12 * version 2 for more details (a copy is included in the LICENSE file that
13 * accompanied this code).
14 *
15 * You should have received a copy of the GNU General Public License version
16 * 2 along with this work; if not, write to the Free Software Foundation,
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18 *
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20 * or visit www.oracle.com if you need additional information or have any
21 * questions.
22 */
23
24/*
25 * @test
26 * @bug 6358166
27 * @summary -verbose reports absurd times when annotation processing involved
28 */
29
30import java.io.*;
31import java.util.*;
32
33import javax.annotation.processing.*;
34import javax.lang.model.element.*;
35import javax.tools.*;
36
37import com.sun.tools.javac.api.JavacTaskImpl;
38import com.sun.tools.javac.api.JavacTool;
39import com.sun.tools.javac.file.JavacFileManager;
40import com.sun.tools.javac.main.JavaCompiler;
41import com.sun.tools.javac.util.*;
42import com.sun.tools.javac.util.List; // disambiguate
43
44
45@SupportedAnnotationTypes("*")
46public class T6358166 extends AbstractProcessor {
47    public static void main(String... args) throws Throwable {
48        String self = T6358166.class.getName();
49
50        String testSrc = System.getProperty("test.src");
51
52        JavacFileManager fm = new JavacFileManager(new Context(), false, null);
53        JavaFileObject f = fm.getFileForInput(testSrc + File.separatorChar + self + ".java");
54
55        test(fm, f, "-verbose", "-d", ".");
56
57        test(fm, f, "-verbose", "-d", ".", "-XprintRounds", "-processorpath", ".", "-processor", self);
58    }
59
60    static void test(JavacFileManager fm, JavaFileObject f, String... args) throws Throwable {
61        Context context = new Context();
62
63        JavacTool tool = JavacTool.create();
64        JavacTaskImpl task = (JavacTaskImpl) tool.getTask(null, fm, null, Arrays.asList(args), null, List.of(f), context);
65        task.call();
66
67        JavaCompiler c = JavaCompiler.instance(context);
68        if (c.errorCount() != 0)
69            throw new AssertionError("compilation failed");
70
71        long msec = c.elapsed_msec;
72        if (msec < 0 || msec > 5 * 60 * 1000) // allow test 5 mins to execute, should be more than enough!
73            throw new AssertionError("elapsed time is suspect: " + msec);
74    }
75
76    public boolean process(Set<? extends TypeElement> tes, RoundEnvironment renv) {
77        return true;
78    }
79}
80