langtools/make/intellij/src/idea/LangtoolsIdeaAntLogger.java
author kzhaldyb
Wed, 13 Jan 2016 20:26:54 +0300
changeset 35524 a761ec11cbd5
parent 27996 4ae3503fd196
child 36526 3b41f1c69604
permissions -rw-r--r--
8132717: Add tests checking that instances of j.l.Classes of a large size are allocated as Humongous Reviewed-by: jmasa, dfazunen
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
25697
b71804e27eb1 8049234: Add support for running/debugging bootstrap tools in IntelliJ
mcimadamore
parents:
diff changeset
     1
/*
b71804e27eb1 8049234: Add support for running/debugging bootstrap tools in IntelliJ
mcimadamore
parents:
diff changeset
     2
 * Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved.
b71804e27eb1 8049234: Add support for running/debugging bootstrap tools in IntelliJ
mcimadamore
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
b71804e27eb1 8049234: Add support for running/debugging bootstrap tools in IntelliJ
mcimadamore
parents:
diff changeset
     4
 *
b71804e27eb1 8049234: Add support for running/debugging bootstrap tools in IntelliJ
mcimadamore
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
b71804e27eb1 8049234: Add support for running/debugging bootstrap tools in IntelliJ
mcimadamore
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
b71804e27eb1 8049234: Add support for running/debugging bootstrap tools in IntelliJ
mcimadamore
parents:
diff changeset
     7
 * published by the Free Software Foundation.  Oracle designates this
b71804e27eb1 8049234: Add support for running/debugging bootstrap tools in IntelliJ
mcimadamore
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
b71804e27eb1 8049234: Add support for running/debugging bootstrap tools in IntelliJ
mcimadamore
parents:
diff changeset
     9
 * by Oracle in the LICENSE file that accompanied this code.
b71804e27eb1 8049234: Add support for running/debugging bootstrap tools in IntelliJ
mcimadamore
parents:
diff changeset
    10
 *
b71804e27eb1 8049234: Add support for running/debugging bootstrap tools in IntelliJ
mcimadamore
parents:
diff changeset
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
b71804e27eb1 8049234: Add support for running/debugging bootstrap tools in IntelliJ
mcimadamore
parents:
diff changeset
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
b71804e27eb1 8049234: Add support for running/debugging bootstrap tools in IntelliJ
mcimadamore
parents:
diff changeset
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
b71804e27eb1 8049234: Add support for running/debugging bootstrap tools in IntelliJ
mcimadamore
parents:
diff changeset
    14
 * version 2 for more details (a copy is included in the LICENSE file that
b71804e27eb1 8049234: Add support for running/debugging bootstrap tools in IntelliJ
mcimadamore
parents:
diff changeset
    15
 * accompanied this code).
b71804e27eb1 8049234: Add support for running/debugging bootstrap tools in IntelliJ
mcimadamore
parents:
diff changeset
    16
 *
b71804e27eb1 8049234: Add support for running/debugging bootstrap tools in IntelliJ
mcimadamore
parents:
diff changeset
    17
 * You should have received a copy of the GNU General Public License version
b71804e27eb1 8049234: Add support for running/debugging bootstrap tools in IntelliJ
mcimadamore
parents:
diff changeset
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
b71804e27eb1 8049234: Add support for running/debugging bootstrap tools in IntelliJ
mcimadamore
parents:
diff changeset
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
b71804e27eb1 8049234: Add support for running/debugging bootstrap tools in IntelliJ
mcimadamore
parents:
diff changeset
    20
 *
b71804e27eb1 8049234: Add support for running/debugging bootstrap tools in IntelliJ
mcimadamore
parents:
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
b71804e27eb1 8049234: Add support for running/debugging bootstrap tools in IntelliJ
mcimadamore
parents:
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
b71804e27eb1 8049234: Add support for running/debugging bootstrap tools in IntelliJ
mcimadamore
parents:
diff changeset
    23
 * questions.
b71804e27eb1 8049234: Add support for running/debugging bootstrap tools in IntelliJ
mcimadamore
parents:
diff changeset
    24
 */
b71804e27eb1 8049234: Add support for running/debugging bootstrap tools in IntelliJ
mcimadamore
parents:
diff changeset
    25
b71804e27eb1 8049234: Add support for running/debugging bootstrap tools in IntelliJ
mcimadamore
parents:
diff changeset
    26
package idea;
b71804e27eb1 8049234: Add support for running/debugging bootstrap tools in IntelliJ
mcimadamore
parents:
diff changeset
    27
b71804e27eb1 8049234: Add support for running/debugging bootstrap tools in IntelliJ
mcimadamore
parents:
diff changeset
    28
import org.apache.tools.ant.BuildEvent;
27548
d3f506b108e5 8064367: Fix IntelliJ langtools support to use new dev build
mcimadamore
parents: 25697
diff changeset
    29
import org.apache.tools.ant.BuildListener;
25697
b71804e27eb1 8049234: Add support for running/debugging bootstrap tools in IntelliJ
mcimadamore
parents:
diff changeset
    30
import org.apache.tools.ant.DefaultLogger;
27548
d3f506b108e5 8064367: Fix IntelliJ langtools support to use new dev build
mcimadamore
parents: 25697
diff changeset
    31
import org.apache.tools.ant.Project;
25697
b71804e27eb1 8049234: Add support for running/debugging bootstrap tools in IntelliJ
mcimadamore
parents:
diff changeset
    32
b71804e27eb1 8049234: Add support for running/debugging bootstrap tools in IntelliJ
mcimadamore
parents:
diff changeset
    33
import java.util.EnumSet;
b71804e27eb1 8049234: Add support for running/debugging bootstrap tools in IntelliJ
mcimadamore
parents:
diff changeset
    34
import java.util.Stack;
b71804e27eb1 8049234: Add support for running/debugging bootstrap tools in IntelliJ
mcimadamore
parents:
diff changeset
    35
b71804e27eb1 8049234: Add support for running/debugging bootstrap tools in IntelliJ
mcimadamore
parents:
diff changeset
    36
import static org.apache.tools.ant.Project.*;
b71804e27eb1 8049234: Add support for running/debugging bootstrap tools in IntelliJ
mcimadamore
parents:
diff changeset
    37
b71804e27eb1 8049234: Add support for running/debugging bootstrap tools in IntelliJ
mcimadamore
parents:
diff changeset
    38
/**
b71804e27eb1 8049234: Add support for running/debugging bootstrap tools in IntelliJ
mcimadamore
parents:
diff changeset
    39
 * This class is used to wrap the IntelliJ ant logger in order to provide more meaningful
b71804e27eb1 8049234: Add support for running/debugging bootstrap tools in IntelliJ
mcimadamore
parents:
diff changeset
    40
 * output when building langtools. The basic ant output in IntelliJ can be quite cumbersome to
b71804e27eb1 8049234: Add support for running/debugging bootstrap tools in IntelliJ
mcimadamore
parents:
diff changeset
    41
 * work with, as it provides two separate views: (i) a tree view, which is good to display build task
b71804e27eb1 8049234: Add support for running/debugging bootstrap tools in IntelliJ
mcimadamore
parents:
diff changeset
    42
 * in a hierarchical fashion as they are processed; and a (ii) plain text view, which gives you
b71804e27eb1 8049234: Add support for running/debugging bootstrap tools in IntelliJ
mcimadamore
parents:
diff changeset
    43
 * the full ant output. The main problem is that javac-related messages are buried into the
b71804e27eb1 8049234: Add support for running/debugging bootstrap tools in IntelliJ
mcimadamore
parents:
diff changeset
    44
 * ant output (which is made very verbose by IntelliJ in order to support the tree view). It is
b71804e27eb1 8049234: Add support for running/debugging bootstrap tools in IntelliJ
mcimadamore
parents:
diff changeset
    45
 * not easy to figure out which node to expand in order to see the error message; switching
b71804e27eb1 8049234: Add support for running/debugging bootstrap tools in IntelliJ
mcimadamore
parents:
diff changeset
    46
 * to plain text doesn't help either, as now the output is totally flat.
b71804e27eb1 8049234: Add support for running/debugging bootstrap tools in IntelliJ
mcimadamore
parents:
diff changeset
    47
 *
b71804e27eb1 8049234: Add support for running/debugging bootstrap tools in IntelliJ
mcimadamore
parents:
diff changeset
    48
 * This logger class removes a lot of verbosity from the IntelliJ ant logger by not propagating
b71804e27eb1 8049234: Add support for running/debugging bootstrap tools in IntelliJ
mcimadamore
parents:
diff changeset
    49
 * all the events to the IntelliJ's logger. In addition, certain events are handled in a custom
b71804e27eb1 8049234: Add support for running/debugging bootstrap tools in IntelliJ
mcimadamore
parents:
diff changeset
    50
 * fashion, to generate better output during the build.
b71804e27eb1 8049234: Add support for running/debugging bootstrap tools in IntelliJ
mcimadamore
parents:
diff changeset
    51
 */
b71804e27eb1 8049234: Add support for running/debugging bootstrap tools in IntelliJ
mcimadamore
parents:
diff changeset
    52
public final class LangtoolsIdeaAntLogger extends DefaultLogger {
b71804e27eb1 8049234: Add support for running/debugging bootstrap tools in IntelliJ
mcimadamore
parents:
diff changeset
    53
b71804e27eb1 8049234: Add support for running/debugging bootstrap tools in IntelliJ
mcimadamore
parents:
diff changeset
    54
    /**
b71804e27eb1 8049234: Add support for running/debugging bootstrap tools in IntelliJ
mcimadamore
parents:
diff changeset
    55
     * This is just a way to pass in customized binary string predicates;
b71804e27eb1 8049234: Add support for running/debugging bootstrap tools in IntelliJ
mcimadamore
parents:
diff changeset
    56
     *
b71804e27eb1 8049234: Add support for running/debugging bootstrap tools in IntelliJ
mcimadamore
parents:
diff changeset
    57
     * TODO: replace with @code{BiPredicate<String, String>} and method reference when moving to 8
b71804e27eb1 8049234: Add support for running/debugging bootstrap tools in IntelliJ
mcimadamore
parents:
diff changeset
    58
     */
b71804e27eb1 8049234: Add support for running/debugging bootstrap tools in IntelliJ
mcimadamore
parents:
diff changeset
    59
    enum StringBinaryPredicate {
b71804e27eb1 8049234: Add support for running/debugging bootstrap tools in IntelliJ
mcimadamore
parents:
diff changeset
    60
        CONTAINS() {
b71804e27eb1 8049234: Add support for running/debugging bootstrap tools in IntelliJ
mcimadamore
parents:
diff changeset
    61
            @Override
b71804e27eb1 8049234: Add support for running/debugging bootstrap tools in IntelliJ
mcimadamore
parents:
diff changeset
    62
            boolean apply(String s1, String s2) {
b71804e27eb1 8049234: Add support for running/debugging bootstrap tools in IntelliJ
mcimadamore
parents:
diff changeset
    63
                return s1.contains(s2);
b71804e27eb1 8049234: Add support for running/debugging bootstrap tools in IntelliJ
mcimadamore
parents:
diff changeset
    64
            }
b71804e27eb1 8049234: Add support for running/debugging bootstrap tools in IntelliJ
mcimadamore
parents:
diff changeset
    65
        },
b71804e27eb1 8049234: Add support for running/debugging bootstrap tools in IntelliJ
mcimadamore
parents:
diff changeset
    66
        STARTS_WITH {
b71804e27eb1 8049234: Add support for running/debugging bootstrap tools in IntelliJ
mcimadamore
parents:
diff changeset
    67
            @Override
b71804e27eb1 8049234: Add support for running/debugging bootstrap tools in IntelliJ
mcimadamore
parents:
diff changeset
    68
            boolean apply(String s1, String s2) {
b71804e27eb1 8049234: Add support for running/debugging bootstrap tools in IntelliJ
mcimadamore
parents:
diff changeset
    69
                return s1.startsWith(s2);
b71804e27eb1 8049234: Add support for running/debugging bootstrap tools in IntelliJ
mcimadamore
parents:
diff changeset
    70
            }
b71804e27eb1 8049234: Add support for running/debugging bootstrap tools in IntelliJ
mcimadamore
parents:
diff changeset
    71
        };
b71804e27eb1 8049234: Add support for running/debugging bootstrap tools in IntelliJ
mcimadamore
parents:
diff changeset
    72
b71804e27eb1 8049234: Add support for running/debugging bootstrap tools in IntelliJ
mcimadamore
parents:
diff changeset
    73
        abstract boolean apply(String s1, String s2);
b71804e27eb1 8049234: Add support for running/debugging bootstrap tools in IntelliJ
mcimadamore
parents:
diff changeset
    74
    }
b71804e27eb1 8049234: Add support for running/debugging bootstrap tools in IntelliJ
mcimadamore
parents:
diff changeset
    75
b71804e27eb1 8049234: Add support for running/debugging bootstrap tools in IntelliJ
mcimadamore
parents:
diff changeset
    76
    /**
b71804e27eb1 8049234: Add support for running/debugging bootstrap tools in IntelliJ
mcimadamore
parents:
diff changeset
    77
     * Various kinds of ant messages that we shall intercept
b71804e27eb1 8049234: Add support for running/debugging bootstrap tools in IntelliJ
mcimadamore
parents:
diff changeset
    78
     */
b71804e27eb1 8049234: Add support for running/debugging bootstrap tools in IntelliJ
mcimadamore
parents:
diff changeset
    79
    enum MessageKind {
b71804e27eb1 8049234: Add support for running/debugging bootstrap tools in IntelliJ
mcimadamore
parents:
diff changeset
    80
b71804e27eb1 8049234: Add support for running/debugging bootstrap tools in IntelliJ
mcimadamore
parents:
diff changeset
    81
        /** a javac error */
b71804e27eb1 8049234: Add support for running/debugging bootstrap tools in IntelliJ
mcimadamore
parents:
diff changeset
    82
        JAVAC_ERROR(StringBinaryPredicate.CONTAINS, MSG_ERR, "error:", "compiler.err"),
b71804e27eb1 8049234: Add support for running/debugging bootstrap tools in IntelliJ
mcimadamore
parents:
diff changeset
    83
        /** a javac warning */
b71804e27eb1 8049234: Add support for running/debugging bootstrap tools in IntelliJ
mcimadamore
parents:
diff changeset
    84
        JAVAC_WARNING(StringBinaryPredicate.CONTAINS, MSG_WARN, "warning:", "compiler.warn"),
b71804e27eb1 8049234: Add support for running/debugging bootstrap tools in IntelliJ
mcimadamore
parents:
diff changeset
    85
        /** a javac note */
b71804e27eb1 8049234: Add support for running/debugging bootstrap tools in IntelliJ
mcimadamore
parents:
diff changeset
    86
        JAVAC_NOTE(StringBinaryPredicate.CONTAINS, MSG_INFO, "note:", "compiler.note"),
b71804e27eb1 8049234: Add support for running/debugging bootstrap tools in IntelliJ
mcimadamore
parents:
diff changeset
    87
        /** continuation of some javac error message */
b71804e27eb1 8049234: Add support for running/debugging bootstrap tools in IntelliJ
mcimadamore
parents:
diff changeset
    88
        JAVAC_NESTED_DIAG(StringBinaryPredicate.STARTS_WITH, MSG_INFO, "  "),
b71804e27eb1 8049234: Add support for running/debugging bootstrap tools in IntelliJ
mcimadamore
parents:
diff changeset
    89
        /** a javac crash */
b71804e27eb1 8049234: Add support for running/debugging bootstrap tools in IntelliJ
mcimadamore
parents:
diff changeset
    90
        JAVAC_CRASH(StringBinaryPredicate.STARTS_WITH, MSG_ERR, "An exception has occurred in the compiler"),
b71804e27eb1 8049234: Add support for running/debugging bootstrap tools in IntelliJ
mcimadamore
parents:
diff changeset
    91
        /** jtreg test success */
b71804e27eb1 8049234: Add support for running/debugging bootstrap tools in IntelliJ
mcimadamore
parents:
diff changeset
    92
        JTREG_TEST_PASSED(StringBinaryPredicate.STARTS_WITH, MSG_INFO, "Passed: "),
b71804e27eb1 8049234: Add support for running/debugging bootstrap tools in IntelliJ
mcimadamore
parents:
diff changeset
    93
        /** jtreg test failure */
b71804e27eb1 8049234: Add support for running/debugging bootstrap tools in IntelliJ
mcimadamore
parents:
diff changeset
    94
        JTREG_TEST_FAILED(StringBinaryPredicate.STARTS_WITH, MSG_ERR, "FAILED: "),
b71804e27eb1 8049234: Add support for running/debugging bootstrap tools in IntelliJ
mcimadamore
parents:
diff changeset
    95
        /** jtreg test error */
27996
4ae3503fd196 8067006: Tweak IntelliJ langtools project to show jtreg report directory
mcimadamore
parents: 27548
diff changeset
    96
        JTREG_TEST_ERROR(StringBinaryPredicate.STARTS_WITH, MSG_ERR, "Error: "),
4ae3503fd196 8067006: Tweak IntelliJ langtools project to show jtreg report directory
mcimadamore
parents: 27548
diff changeset
    97
        /** jtreg report */
4ae3503fd196 8067006: Tweak IntelliJ langtools project to show jtreg report directory
mcimadamore
parents: 27548
diff changeset
    98
        JTREG_TEST_REPORT(StringBinaryPredicate.STARTS_WITH, MSG_INFO, "Report written");
25697
b71804e27eb1 8049234: Add support for running/debugging bootstrap tools in IntelliJ
mcimadamore
parents:
diff changeset
    99
b71804e27eb1 8049234: Add support for running/debugging bootstrap tools in IntelliJ
mcimadamore
parents:
diff changeset
   100
        StringBinaryPredicate sbp;
b71804e27eb1 8049234: Add support for running/debugging bootstrap tools in IntelliJ
mcimadamore
parents:
diff changeset
   101
        int priority;
b71804e27eb1 8049234: Add support for running/debugging bootstrap tools in IntelliJ
mcimadamore
parents:
diff changeset
   102
        String[] keys;
b71804e27eb1 8049234: Add support for running/debugging bootstrap tools in IntelliJ
mcimadamore
parents:
diff changeset
   103
b71804e27eb1 8049234: Add support for running/debugging bootstrap tools in IntelliJ
mcimadamore
parents:
diff changeset
   104
        MessageKind(StringBinaryPredicate sbp, int priority, String... keys) {
b71804e27eb1 8049234: Add support for running/debugging bootstrap tools in IntelliJ
mcimadamore
parents:
diff changeset
   105
            this.sbp = sbp;
b71804e27eb1 8049234: Add support for running/debugging bootstrap tools in IntelliJ
mcimadamore
parents:
diff changeset
   106
            this.priority = priority;
b71804e27eb1 8049234: Add support for running/debugging bootstrap tools in IntelliJ
mcimadamore
parents:
diff changeset
   107
            this.keys = keys;
b71804e27eb1 8049234: Add support for running/debugging bootstrap tools in IntelliJ
mcimadamore
parents:
diff changeset
   108
        }
b71804e27eb1 8049234: Add support for running/debugging bootstrap tools in IntelliJ
mcimadamore
parents:
diff changeset
   109
b71804e27eb1 8049234: Add support for running/debugging bootstrap tools in IntelliJ
mcimadamore
parents:
diff changeset
   110
        /**
b71804e27eb1 8049234: Add support for running/debugging bootstrap tools in IntelliJ
mcimadamore
parents:
diff changeset
   111
         * Does a given message string matches this kind?
b71804e27eb1 8049234: Add support for running/debugging bootstrap tools in IntelliJ
mcimadamore
parents:
diff changeset
   112
         */
b71804e27eb1 8049234: Add support for running/debugging bootstrap tools in IntelliJ
mcimadamore
parents:
diff changeset
   113
        boolean matches(String s) {
b71804e27eb1 8049234: Add support for running/debugging bootstrap tools in IntelliJ
mcimadamore
parents:
diff changeset
   114
            for (String key : keys) {
b71804e27eb1 8049234: Add support for running/debugging bootstrap tools in IntelliJ
mcimadamore
parents:
diff changeset
   115
                if (sbp.apply(s, key)) {
b71804e27eb1 8049234: Add support for running/debugging bootstrap tools in IntelliJ
mcimadamore
parents:
diff changeset
   116
                    return true;
b71804e27eb1 8049234: Add support for running/debugging bootstrap tools in IntelliJ
mcimadamore
parents:
diff changeset
   117
                }
b71804e27eb1 8049234: Add support for running/debugging bootstrap tools in IntelliJ
mcimadamore
parents:
diff changeset
   118
            }
b71804e27eb1 8049234: Add support for running/debugging bootstrap tools in IntelliJ
mcimadamore
parents:
diff changeset
   119
            return false;
b71804e27eb1 8049234: Add support for running/debugging bootstrap tools in IntelliJ
mcimadamore
parents:
diff changeset
   120
        }
b71804e27eb1 8049234: Add support for running/debugging bootstrap tools in IntelliJ
mcimadamore
parents:
diff changeset
   121
    }
b71804e27eb1 8049234: Add support for running/debugging bootstrap tools in IntelliJ
mcimadamore
parents:
diff changeset
   122
b71804e27eb1 8049234: Add support for running/debugging bootstrap tools in IntelliJ
mcimadamore
parents:
diff changeset
   123
    /**
b71804e27eb1 8049234: Add support for running/debugging bootstrap tools in IntelliJ
mcimadamore
parents:
diff changeset
   124
     * This enum is used to represent the list of tasks we need to keep track of during logging.
b71804e27eb1 8049234: Add support for running/debugging bootstrap tools in IntelliJ
mcimadamore
parents:
diff changeset
   125
     */
b71804e27eb1 8049234: Add support for running/debugging bootstrap tools in IntelliJ
mcimadamore
parents:
diff changeset
   126
    enum Task {
b71804e27eb1 8049234: Add support for running/debugging bootstrap tools in IntelliJ
mcimadamore
parents:
diff changeset
   127
        /** javac task - invoked during compilation */
b71804e27eb1 8049234: Add support for running/debugging bootstrap tools in IntelliJ
mcimadamore
parents:
diff changeset
   128
        JAVAC("javac", MessageKind.JAVAC_ERROR, MessageKind.JAVAC_WARNING, MessageKind.JAVAC_NOTE,
b71804e27eb1 8049234: Add support for running/debugging bootstrap tools in IntelliJ
mcimadamore
parents:
diff changeset
   129
                       MessageKind.JAVAC_NESTED_DIAG, MessageKind.JAVAC_CRASH),
b71804e27eb1 8049234: Add support for running/debugging bootstrap tools in IntelliJ
mcimadamore
parents:
diff changeset
   130
        /** jtreg task - invoked during test execution */
27996
4ae3503fd196 8067006: Tweak IntelliJ langtools project to show jtreg report directory
mcimadamore
parents: 27548
diff changeset
   131
        JTREG("jtreg", MessageKind.JTREG_TEST_PASSED, MessageKind.JTREG_TEST_FAILED, MessageKind.JTREG_TEST_ERROR, MessageKind.JTREG_TEST_REPORT),
25697
b71804e27eb1 8049234: Add support for running/debugging bootstrap tools in IntelliJ
mcimadamore
parents:
diff changeset
   132
        /** initial synthetic task when the logger is created */
b71804e27eb1 8049234: Add support for running/debugging bootstrap tools in IntelliJ
mcimadamore
parents:
diff changeset
   133
        ROOT("") {
b71804e27eb1 8049234: Add support for running/debugging bootstrap tools in IntelliJ
mcimadamore
parents:
diff changeset
   134
            @Override
b71804e27eb1 8049234: Add support for running/debugging bootstrap tools in IntelliJ
mcimadamore
parents:
diff changeset
   135
            boolean matches(String s) {
b71804e27eb1 8049234: Add support for running/debugging bootstrap tools in IntelliJ
mcimadamore
parents:
diff changeset
   136
                return false;
b71804e27eb1 8049234: Add support for running/debugging bootstrap tools in IntelliJ
mcimadamore
parents:
diff changeset
   137
            }
b71804e27eb1 8049234: Add support for running/debugging bootstrap tools in IntelliJ
mcimadamore
parents:
diff changeset
   138
        },
b71804e27eb1 8049234: Add support for running/debugging bootstrap tools in IntelliJ
mcimadamore
parents:
diff changeset
   139
        /** synthetic task catching any other tasks not in this list */
b71804e27eb1 8049234: Add support for running/debugging bootstrap tools in IntelliJ
mcimadamore
parents:
diff changeset
   140
        ANY("") {
b71804e27eb1 8049234: Add support for running/debugging bootstrap tools in IntelliJ
mcimadamore
parents:
diff changeset
   141
            @Override
b71804e27eb1 8049234: Add support for running/debugging bootstrap tools in IntelliJ
mcimadamore
parents:
diff changeset
   142
            boolean matches(String s) {
b71804e27eb1 8049234: Add support for running/debugging bootstrap tools in IntelliJ
mcimadamore
parents:
diff changeset
   143
                return true;
b71804e27eb1 8049234: Add support for running/debugging bootstrap tools in IntelliJ
mcimadamore
parents:
diff changeset
   144
            }
b71804e27eb1 8049234: Add support for running/debugging bootstrap tools in IntelliJ
mcimadamore
parents:
diff changeset
   145
        };
b71804e27eb1 8049234: Add support for running/debugging bootstrap tools in IntelliJ
mcimadamore
parents:
diff changeset
   146
b71804e27eb1 8049234: Add support for running/debugging bootstrap tools in IntelliJ
mcimadamore
parents:
diff changeset
   147
        String taskName;
b71804e27eb1 8049234: Add support for running/debugging bootstrap tools in IntelliJ
mcimadamore
parents:
diff changeset
   148
        MessageKind[] msgs;
b71804e27eb1 8049234: Add support for running/debugging bootstrap tools in IntelliJ
mcimadamore
parents:
diff changeset
   149
b71804e27eb1 8049234: Add support for running/debugging bootstrap tools in IntelliJ
mcimadamore
parents:
diff changeset
   150
        Task(String taskName, MessageKind... msgs) {
b71804e27eb1 8049234: Add support for running/debugging bootstrap tools in IntelliJ
mcimadamore
parents:
diff changeset
   151
            this.taskName = taskName;
b71804e27eb1 8049234: Add support for running/debugging bootstrap tools in IntelliJ
mcimadamore
parents:
diff changeset
   152
            this.msgs = msgs;
b71804e27eb1 8049234: Add support for running/debugging bootstrap tools in IntelliJ
mcimadamore
parents:
diff changeset
   153
        }
b71804e27eb1 8049234: Add support for running/debugging bootstrap tools in IntelliJ
mcimadamore
parents:
diff changeset
   154
b71804e27eb1 8049234: Add support for running/debugging bootstrap tools in IntelliJ
mcimadamore
parents:
diff changeset
   155
        boolean matches(String s) {
b71804e27eb1 8049234: Add support for running/debugging bootstrap tools in IntelliJ
mcimadamore
parents:
diff changeset
   156
            return s.equals(taskName);
b71804e27eb1 8049234: Add support for running/debugging bootstrap tools in IntelliJ
mcimadamore
parents:
diff changeset
   157
        }
b71804e27eb1 8049234: Add support for running/debugging bootstrap tools in IntelliJ
mcimadamore
parents:
diff changeset
   158
    }
b71804e27eb1 8049234: Add support for running/debugging bootstrap tools in IntelliJ
mcimadamore
parents:
diff changeset
   159
b71804e27eb1 8049234: Add support for running/debugging bootstrap tools in IntelliJ
mcimadamore
parents:
diff changeset
   160
    /**
b71804e27eb1 8049234: Add support for running/debugging bootstrap tools in IntelliJ
mcimadamore
parents:
diff changeset
   161
     * This enum is used to represent the list of targets we need to keep track of during logging.
b71804e27eb1 8049234: Add support for running/debugging bootstrap tools in IntelliJ
mcimadamore
parents:
diff changeset
   162
     * A regular expression is used to match a given target name.
b71804e27eb1 8049234: Add support for running/debugging bootstrap tools in IntelliJ
mcimadamore
parents:
diff changeset
   163
     */
b71804e27eb1 8049234: Add support for running/debugging bootstrap tools in IntelliJ
mcimadamore
parents:
diff changeset
   164
    enum Target {
b71804e27eb1 8049234: Add support for running/debugging bootstrap tools in IntelliJ
mcimadamore
parents:
diff changeset
   165
        /** jtreg target - executed when launching tests */
b71804e27eb1 8049234: Add support for running/debugging bootstrap tools in IntelliJ
mcimadamore
parents:
diff changeset
   166
        JTREG("jtreg") {
b71804e27eb1 8049234: Add support for running/debugging bootstrap tools in IntelliJ
mcimadamore
parents:
diff changeset
   167
            @Override
b71804e27eb1 8049234: Add support for running/debugging bootstrap tools in IntelliJ
mcimadamore
parents:
diff changeset
   168
            String getDisplayMessage(BuildEvent e) {
b71804e27eb1 8049234: Add support for running/debugging bootstrap tools in IntelliJ
mcimadamore
parents:
diff changeset
   169
                return "Running jtreg tests: " + e.getProject().getProperty("jtreg.tests");
b71804e27eb1 8049234: Add support for running/debugging bootstrap tools in IntelliJ
mcimadamore
parents:
diff changeset
   170
            }
b71804e27eb1 8049234: Add support for running/debugging bootstrap tools in IntelliJ
mcimadamore
parents:
diff changeset
   171
        },
b71804e27eb1 8049234: Add support for running/debugging bootstrap tools in IntelliJ
mcimadamore
parents:
diff changeset
   172
        /** build bootstrap tool target - executed when bootstrapping javac */
27548
d3f506b108e5 8064367: Fix IntelliJ langtools support to use new dev build
mcimadamore
parents: 25697
diff changeset
   173
        BUILD_BOOTSTRAP_JAVAC("build-bootstrap-javac-classes") {
25697
b71804e27eb1 8049234: Add support for running/debugging bootstrap tools in IntelliJ
mcimadamore
parents:
diff changeset
   174
            @Override
b71804e27eb1 8049234: Add support for running/debugging bootstrap tools in IntelliJ
mcimadamore
parents:
diff changeset
   175
            String getDisplayMessage(BuildEvent e) {
27548
d3f506b108e5 8064367: Fix IntelliJ langtools support to use new dev build
mcimadamore
parents: 25697
diff changeset
   176
                return "Building bootstrap javac...";
25697
b71804e27eb1 8049234: Add support for running/debugging bootstrap tools in IntelliJ
mcimadamore
parents:
diff changeset
   177
            }
b71804e27eb1 8049234: Add support for running/debugging bootstrap tools in IntelliJ
mcimadamore
parents:
diff changeset
   178
        },
b71804e27eb1 8049234: Add support for running/debugging bootstrap tools in IntelliJ
mcimadamore
parents:
diff changeset
   179
        /** build classes target - executed when building classes of given tool */
27548
d3f506b108e5 8064367: Fix IntelliJ langtools support to use new dev build
mcimadamore
parents: 25697
diff changeset
   180
        BUILD_ALL_CLASSES("build-all-classes") {
25697
b71804e27eb1 8049234: Add support for running/debugging bootstrap tools in IntelliJ
mcimadamore
parents:
diff changeset
   181
            @Override
b71804e27eb1 8049234: Add support for running/debugging bootstrap tools in IntelliJ
mcimadamore
parents:
diff changeset
   182
            String getDisplayMessage(BuildEvent e) {
27548
d3f506b108e5 8064367: Fix IntelliJ langtools support to use new dev build
mcimadamore
parents: 25697
diff changeset
   183
                return "Building all classes...";
25697
b71804e27eb1 8049234: Add support for running/debugging bootstrap tools in IntelliJ
mcimadamore
parents:
diff changeset
   184
            }
b71804e27eb1 8049234: Add support for running/debugging bootstrap tools in IntelliJ
mcimadamore
parents:
diff changeset
   185
        },
b71804e27eb1 8049234: Add support for running/debugging bootstrap tools in IntelliJ
mcimadamore
parents:
diff changeset
   186
        /** synthetic target catching any other target not in this list */
b71804e27eb1 8049234: Add support for running/debugging bootstrap tools in IntelliJ
mcimadamore
parents:
diff changeset
   187
        ANY("") {
b71804e27eb1 8049234: Add support for running/debugging bootstrap tools in IntelliJ
mcimadamore
parents:
diff changeset
   188
            @Override
b71804e27eb1 8049234: Add support for running/debugging bootstrap tools in IntelliJ
mcimadamore
parents:
diff changeset
   189
            String getDisplayMessage(BuildEvent e) {
b71804e27eb1 8049234: Add support for running/debugging bootstrap tools in IntelliJ
mcimadamore
parents:
diff changeset
   190
                return "Executing Ant target(s): " + e.getProject().getProperty("ant.project.invoked-targets");
b71804e27eb1 8049234: Add support for running/debugging bootstrap tools in IntelliJ
mcimadamore
parents:
diff changeset
   191
            }
b71804e27eb1 8049234: Add support for running/debugging bootstrap tools in IntelliJ
mcimadamore
parents:
diff changeset
   192
            @Override
b71804e27eb1 8049234: Add support for running/debugging bootstrap tools in IntelliJ
mcimadamore
parents:
diff changeset
   193
            boolean matches(String msg) {
b71804e27eb1 8049234: Add support for running/debugging bootstrap tools in IntelliJ
mcimadamore
parents:
diff changeset
   194
                return true;
b71804e27eb1 8049234: Add support for running/debugging bootstrap tools in IntelliJ
mcimadamore
parents:
diff changeset
   195
            }
b71804e27eb1 8049234: Add support for running/debugging bootstrap tools in IntelliJ
mcimadamore
parents:
diff changeset
   196
        };
b71804e27eb1 8049234: Add support for running/debugging bootstrap tools in IntelliJ
mcimadamore
parents:
diff changeset
   197
27548
d3f506b108e5 8064367: Fix IntelliJ langtools support to use new dev build
mcimadamore
parents: 25697
diff changeset
   198
        String targetName;
25697
b71804e27eb1 8049234: Add support for running/debugging bootstrap tools in IntelliJ
mcimadamore
parents:
diff changeset
   199
27548
d3f506b108e5 8064367: Fix IntelliJ langtools support to use new dev build
mcimadamore
parents: 25697
diff changeset
   200
        Target(String targetName) {
d3f506b108e5 8064367: Fix IntelliJ langtools support to use new dev build
mcimadamore
parents: 25697
diff changeset
   201
            this.targetName = targetName;
25697
b71804e27eb1 8049234: Add support for running/debugging bootstrap tools in IntelliJ
mcimadamore
parents:
diff changeset
   202
        }
b71804e27eb1 8049234: Add support for running/debugging bootstrap tools in IntelliJ
mcimadamore
parents:
diff changeset
   203
b71804e27eb1 8049234: Add support for running/debugging bootstrap tools in IntelliJ
mcimadamore
parents:
diff changeset
   204
        boolean matches(String msg) {
27548
d3f506b108e5 8064367: Fix IntelliJ langtools support to use new dev build
mcimadamore
parents: 25697
diff changeset
   205
            return msg.equals(targetName);
25697
b71804e27eb1 8049234: Add support for running/debugging bootstrap tools in IntelliJ
mcimadamore
parents:
diff changeset
   206
        }
b71804e27eb1 8049234: Add support for running/debugging bootstrap tools in IntelliJ
mcimadamore
parents:
diff changeset
   207
b71804e27eb1 8049234: Add support for running/debugging bootstrap tools in IntelliJ
mcimadamore
parents:
diff changeset
   208
        abstract String getDisplayMessage(BuildEvent e);
b71804e27eb1 8049234: Add support for running/debugging bootstrap tools in IntelliJ
mcimadamore
parents:
diff changeset
   209
    }
b71804e27eb1 8049234: Add support for running/debugging bootstrap tools in IntelliJ
mcimadamore
parents:
diff changeset
   210
b71804e27eb1 8049234: Add support for running/debugging bootstrap tools in IntelliJ
mcimadamore
parents:
diff changeset
   211
    /**
b71804e27eb1 8049234: Add support for running/debugging bootstrap tools in IntelliJ
mcimadamore
parents:
diff changeset
   212
     * A custom build event used to represent status changes which should be notified inside
b71804e27eb1 8049234: Add support for running/debugging bootstrap tools in IntelliJ
mcimadamore
parents:
diff changeset
   213
     * Intellij
b71804e27eb1 8049234: Add support for running/debugging bootstrap tools in IntelliJ
mcimadamore
parents:
diff changeset
   214
     */
b71804e27eb1 8049234: Add support for running/debugging bootstrap tools in IntelliJ
mcimadamore
parents:
diff changeset
   215
    static class StatusEvent extends BuildEvent {
b71804e27eb1 8049234: Add support for running/debugging bootstrap tools in IntelliJ
mcimadamore
parents:
diff changeset
   216
b71804e27eb1 8049234: Add support for running/debugging bootstrap tools in IntelliJ
mcimadamore
parents:
diff changeset
   217
        /** the target to which the status update refers */
b71804e27eb1 8049234: Add support for running/debugging bootstrap tools in IntelliJ
mcimadamore
parents:
diff changeset
   218
        Target target;
b71804e27eb1 8049234: Add support for running/debugging bootstrap tools in IntelliJ
mcimadamore
parents:
diff changeset
   219
b71804e27eb1 8049234: Add support for running/debugging bootstrap tools in IntelliJ
mcimadamore
parents:
diff changeset
   220
        StatusEvent(BuildEvent e, Target target) {
b71804e27eb1 8049234: Add support for running/debugging bootstrap tools in IntelliJ
mcimadamore
parents:
diff changeset
   221
            super(new StatusTask(e, target.getDisplayMessage(e)));
b71804e27eb1 8049234: Add support for running/debugging bootstrap tools in IntelliJ
mcimadamore
parents:
diff changeset
   222
            this.target = target;
b71804e27eb1 8049234: Add support for running/debugging bootstrap tools in IntelliJ
mcimadamore
parents:
diff changeset
   223
            setMessage(getTask().getTaskName(), 2);
b71804e27eb1 8049234: Add support for running/debugging bootstrap tools in IntelliJ
mcimadamore
parents:
diff changeset
   224
        }
b71804e27eb1 8049234: Add support for running/debugging bootstrap tools in IntelliJ
mcimadamore
parents:
diff changeset
   225
b71804e27eb1 8049234: Add support for running/debugging bootstrap tools in IntelliJ
mcimadamore
parents:
diff changeset
   226
        /**
b71804e27eb1 8049234: Add support for running/debugging bootstrap tools in IntelliJ
mcimadamore
parents:
diff changeset
   227
         * A custom task used to channel info regarding a status change
b71804e27eb1 8049234: Add support for running/debugging bootstrap tools in IntelliJ
mcimadamore
parents:
diff changeset
   228
         */
b71804e27eb1 8049234: Add support for running/debugging bootstrap tools in IntelliJ
mcimadamore
parents:
diff changeset
   229
        static class StatusTask extends org.apache.tools.ant.Task {
b71804e27eb1 8049234: Add support for running/debugging bootstrap tools in IntelliJ
mcimadamore
parents:
diff changeset
   230
            StatusTask(BuildEvent event, String msg) {
b71804e27eb1 8049234: Add support for running/debugging bootstrap tools in IntelliJ
mcimadamore
parents:
diff changeset
   231
                setProject(event.getProject());
b71804e27eb1 8049234: Add support for running/debugging bootstrap tools in IntelliJ
mcimadamore
parents:
diff changeset
   232
                setOwningTarget(event.getTarget());
b71804e27eb1 8049234: Add support for running/debugging bootstrap tools in IntelliJ
mcimadamore
parents:
diff changeset
   233
                setTaskName(msg);
b71804e27eb1 8049234: Add support for running/debugging bootstrap tools in IntelliJ
mcimadamore
parents:
diff changeset
   234
            }
b71804e27eb1 8049234: Add support for running/debugging bootstrap tools in IntelliJ
mcimadamore
parents:
diff changeset
   235
        }
b71804e27eb1 8049234: Add support for running/debugging bootstrap tools in IntelliJ
mcimadamore
parents:
diff changeset
   236
    }
b71804e27eb1 8049234: Add support for running/debugging bootstrap tools in IntelliJ
mcimadamore
parents:
diff changeset
   237
b71804e27eb1 8049234: Add support for running/debugging bootstrap tools in IntelliJ
mcimadamore
parents:
diff changeset
   238
    /** wrapped ant logger (IntelliJ's own logger) */
b71804e27eb1 8049234: Add support for running/debugging bootstrap tools in IntelliJ
mcimadamore
parents:
diff changeset
   239
    DefaultLogger logger;
b71804e27eb1 8049234: Add support for running/debugging bootstrap tools in IntelliJ
mcimadamore
parents:
diff changeset
   240
b71804e27eb1 8049234: Add support for running/debugging bootstrap tools in IntelliJ
mcimadamore
parents:
diff changeset
   241
    /** flag - is this the first target we encounter? */
b71804e27eb1 8049234: Add support for running/debugging bootstrap tools in IntelliJ
mcimadamore
parents:
diff changeset
   242
    boolean firstTarget = true;
b71804e27eb1 8049234: Add support for running/debugging bootstrap tools in IntelliJ
mcimadamore
parents:
diff changeset
   243
b71804e27eb1 8049234: Add support for running/debugging bootstrap tools in IntelliJ
mcimadamore
parents:
diff changeset
   244
    /** flag - should subsequenet failures be suppressed ? */
b71804e27eb1 8049234: Add support for running/debugging bootstrap tools in IntelliJ
mcimadamore
parents:
diff changeset
   245
    boolean suppressTaskFailures = false;
b71804e27eb1 8049234: Add support for running/debugging bootstrap tools in IntelliJ
mcimadamore
parents:
diff changeset
   246
b71804e27eb1 8049234: Add support for running/debugging bootstrap tools in IntelliJ
mcimadamore
parents:
diff changeset
   247
    /** flag - have we ran into a javac crash ? */
b71804e27eb1 8049234: Add support for running/debugging bootstrap tools in IntelliJ
mcimadamore
parents:
diff changeset
   248
    boolean crashFound = false;
b71804e27eb1 8049234: Add support for running/debugging bootstrap tools in IntelliJ
mcimadamore
parents:
diff changeset
   249
b71804e27eb1 8049234: Add support for running/debugging bootstrap tools in IntelliJ
mcimadamore
parents:
diff changeset
   250
    /** stack of status changes associated with pending targets */
b71804e27eb1 8049234: Add support for running/debugging bootstrap tools in IntelliJ
mcimadamore
parents:
diff changeset
   251
    Stack<StatusEvent> statusEvents = new Stack<>();
b71804e27eb1 8049234: Add support for running/debugging bootstrap tools in IntelliJ
mcimadamore
parents:
diff changeset
   252
b71804e27eb1 8049234: Add support for running/debugging bootstrap tools in IntelliJ
mcimadamore
parents:
diff changeset
   253
    /** stack of pending tasks */
b71804e27eb1 8049234: Add support for running/debugging bootstrap tools in IntelliJ
mcimadamore
parents:
diff changeset
   254
    Stack<Task> tasks = new Stack<>();
b71804e27eb1 8049234: Add support for running/debugging bootstrap tools in IntelliJ
mcimadamore
parents:
diff changeset
   255
27548
d3f506b108e5 8064367: Fix IntelliJ langtools support to use new dev build
mcimadamore
parents: 25697
diff changeset
   256
    public LangtoolsIdeaAntLogger(Project project) {
d3f506b108e5 8064367: Fix IntelliJ langtools support to use new dev build
mcimadamore
parents: 25697
diff changeset
   257
        for (Object o : project.getBuildListeners()) {
d3f506b108e5 8064367: Fix IntelliJ langtools support to use new dev build
mcimadamore
parents: 25697
diff changeset
   258
            if (o instanceof DefaultLogger) {
d3f506b108e5 8064367: Fix IntelliJ langtools support to use new dev build
mcimadamore
parents: 25697
diff changeset
   259
                this.logger = (DefaultLogger)o;
d3f506b108e5 8064367: Fix IntelliJ langtools support to use new dev build
mcimadamore
parents: 25697
diff changeset
   260
                project.removeBuildListener((BuildListener)o);
d3f506b108e5 8064367: Fix IntelliJ langtools support to use new dev build
mcimadamore
parents: 25697
diff changeset
   261
                project.addBuildListener(this);
d3f506b108e5 8064367: Fix IntelliJ langtools support to use new dev build
mcimadamore
parents: 25697
diff changeset
   262
            }
d3f506b108e5 8064367: Fix IntelliJ langtools support to use new dev build
mcimadamore
parents: 25697
diff changeset
   263
        }
25697
b71804e27eb1 8049234: Add support for running/debugging bootstrap tools in IntelliJ
mcimadamore
parents:
diff changeset
   264
        tasks.push(Task.ROOT);
b71804e27eb1 8049234: Add support for running/debugging bootstrap tools in IntelliJ
mcimadamore
parents:
diff changeset
   265
    }
b71804e27eb1 8049234: Add support for running/debugging bootstrap tools in IntelliJ
mcimadamore
parents:
diff changeset
   266
b71804e27eb1 8049234: Add support for running/debugging bootstrap tools in IntelliJ
mcimadamore
parents:
diff changeset
   267
    @Override
b71804e27eb1 8049234: Add support for running/debugging bootstrap tools in IntelliJ
mcimadamore
parents:
diff changeset
   268
    public void buildStarted(BuildEvent event) {
b71804e27eb1 8049234: Add support for running/debugging bootstrap tools in IntelliJ
mcimadamore
parents:
diff changeset
   269
        //do nothing
b71804e27eb1 8049234: Add support for running/debugging bootstrap tools in IntelliJ
mcimadamore
parents:
diff changeset
   270
    }
b71804e27eb1 8049234: Add support for running/debugging bootstrap tools in IntelliJ
mcimadamore
parents:
diff changeset
   271
b71804e27eb1 8049234: Add support for running/debugging bootstrap tools in IntelliJ
mcimadamore
parents:
diff changeset
   272
    @Override
b71804e27eb1 8049234: Add support for running/debugging bootstrap tools in IntelliJ
mcimadamore
parents:
diff changeset
   273
    public void buildFinished(BuildEvent event) {
b71804e27eb1 8049234: Add support for running/debugging bootstrap tools in IntelliJ
mcimadamore
parents:
diff changeset
   274
        //do nothing
b71804e27eb1 8049234: Add support for running/debugging bootstrap tools in IntelliJ
mcimadamore
parents:
diff changeset
   275
    }
b71804e27eb1 8049234: Add support for running/debugging bootstrap tools in IntelliJ
mcimadamore
parents:
diff changeset
   276
b71804e27eb1 8049234: Add support for running/debugging bootstrap tools in IntelliJ
mcimadamore
parents:
diff changeset
   277
    @Override
b71804e27eb1 8049234: Add support for running/debugging bootstrap tools in IntelliJ
mcimadamore
parents:
diff changeset
   278
    public void targetStarted(BuildEvent event) {
b71804e27eb1 8049234: Add support for running/debugging bootstrap tools in IntelliJ
mcimadamore
parents:
diff changeset
   279
        EnumSet<Target> statusKinds = firstTarget ?
b71804e27eb1 8049234: Add support for running/debugging bootstrap tools in IntelliJ
mcimadamore
parents:
diff changeset
   280
                EnumSet.allOf(Target.class) :
b71804e27eb1 8049234: Add support for running/debugging bootstrap tools in IntelliJ
mcimadamore
parents:
diff changeset
   281
                EnumSet.complementOf(EnumSet.of(Target.ANY));
b71804e27eb1 8049234: Add support for running/debugging bootstrap tools in IntelliJ
mcimadamore
parents:
diff changeset
   282
b71804e27eb1 8049234: Add support for running/debugging bootstrap tools in IntelliJ
mcimadamore
parents:
diff changeset
   283
        String targetName = event.getTarget().getName();
b71804e27eb1 8049234: Add support for running/debugging bootstrap tools in IntelliJ
mcimadamore
parents:
diff changeset
   284
b71804e27eb1 8049234: Add support for running/debugging bootstrap tools in IntelliJ
mcimadamore
parents:
diff changeset
   285
        for (Target statusKind : statusKinds) {
b71804e27eb1 8049234: Add support for running/debugging bootstrap tools in IntelliJ
mcimadamore
parents:
diff changeset
   286
            if (statusKind.matches(targetName)) {
b71804e27eb1 8049234: Add support for running/debugging bootstrap tools in IntelliJ
mcimadamore
parents:
diff changeset
   287
                StatusEvent statusEvent = new StatusEvent(event, statusKind);
b71804e27eb1 8049234: Add support for running/debugging bootstrap tools in IntelliJ
mcimadamore
parents:
diff changeset
   288
                statusEvents.push(statusEvent);
b71804e27eb1 8049234: Add support for running/debugging bootstrap tools in IntelliJ
mcimadamore
parents:
diff changeset
   289
                logger.taskStarted(statusEvent);
b71804e27eb1 8049234: Add support for running/debugging bootstrap tools in IntelliJ
mcimadamore
parents:
diff changeset
   290
                firstTarget = false;
b71804e27eb1 8049234: Add support for running/debugging bootstrap tools in IntelliJ
mcimadamore
parents:
diff changeset
   291
                return;
b71804e27eb1 8049234: Add support for running/debugging bootstrap tools in IntelliJ
mcimadamore
parents:
diff changeset
   292
            }
b71804e27eb1 8049234: Add support for running/debugging bootstrap tools in IntelliJ
mcimadamore
parents:
diff changeset
   293
        }
b71804e27eb1 8049234: Add support for running/debugging bootstrap tools in IntelliJ
mcimadamore
parents:
diff changeset
   294
    }
b71804e27eb1 8049234: Add support for running/debugging bootstrap tools in IntelliJ
mcimadamore
parents:
diff changeset
   295
b71804e27eb1 8049234: Add support for running/debugging bootstrap tools in IntelliJ
mcimadamore
parents:
diff changeset
   296
    @Override
b71804e27eb1 8049234: Add support for running/debugging bootstrap tools in IntelliJ
mcimadamore
parents:
diff changeset
   297
    public void targetFinished(BuildEvent event) {
b71804e27eb1 8049234: Add support for running/debugging bootstrap tools in IntelliJ
mcimadamore
parents:
diff changeset
   298
        if (!statusEvents.isEmpty()) {
b71804e27eb1 8049234: Add support for running/debugging bootstrap tools in IntelliJ
mcimadamore
parents:
diff changeset
   299
            StatusEvent lastEvent = statusEvents.pop();
b71804e27eb1 8049234: Add support for running/debugging bootstrap tools in IntelliJ
mcimadamore
parents:
diff changeset
   300
            if (lastEvent.target.matches(event.getTarget().getName())) {
b71804e27eb1 8049234: Add support for running/debugging bootstrap tools in IntelliJ
mcimadamore
parents:
diff changeset
   301
                logger.taskFinished(lastEvent);
b71804e27eb1 8049234: Add support for running/debugging bootstrap tools in IntelliJ
mcimadamore
parents:
diff changeset
   302
            }
b71804e27eb1 8049234: Add support for running/debugging bootstrap tools in IntelliJ
mcimadamore
parents:
diff changeset
   303
        }
b71804e27eb1 8049234: Add support for running/debugging bootstrap tools in IntelliJ
mcimadamore
parents:
diff changeset
   304
    }
b71804e27eb1 8049234: Add support for running/debugging bootstrap tools in IntelliJ
mcimadamore
parents:
diff changeset
   305
b71804e27eb1 8049234: Add support for running/debugging bootstrap tools in IntelliJ
mcimadamore
parents:
diff changeset
   306
    @Override
b71804e27eb1 8049234: Add support for running/debugging bootstrap tools in IntelliJ
mcimadamore
parents:
diff changeset
   307
    public void taskStarted(BuildEvent event) {
b71804e27eb1 8049234: Add support for running/debugging bootstrap tools in IntelliJ
mcimadamore
parents:
diff changeset
   308
        String taskName = event.getTask().getTaskName();
b71804e27eb1 8049234: Add support for running/debugging bootstrap tools in IntelliJ
mcimadamore
parents:
diff changeset
   309
        for (Task task : Task.values()) {
b71804e27eb1 8049234: Add support for running/debugging bootstrap tools in IntelliJ
mcimadamore
parents:
diff changeset
   310
            if (task.matches(taskName)) {
b71804e27eb1 8049234: Add support for running/debugging bootstrap tools in IntelliJ
mcimadamore
parents:
diff changeset
   311
                tasks.push(task);
b71804e27eb1 8049234: Add support for running/debugging bootstrap tools in IntelliJ
mcimadamore
parents:
diff changeset
   312
                return;
b71804e27eb1 8049234: Add support for running/debugging bootstrap tools in IntelliJ
mcimadamore
parents:
diff changeset
   313
            }
b71804e27eb1 8049234: Add support for running/debugging bootstrap tools in IntelliJ
mcimadamore
parents:
diff changeset
   314
        }
b71804e27eb1 8049234: Add support for running/debugging bootstrap tools in IntelliJ
mcimadamore
parents:
diff changeset
   315
    }
b71804e27eb1 8049234: Add support for running/debugging bootstrap tools in IntelliJ
mcimadamore
parents:
diff changeset
   316
b71804e27eb1 8049234: Add support for running/debugging bootstrap tools in IntelliJ
mcimadamore
parents:
diff changeset
   317
    @Override
b71804e27eb1 8049234: Add support for running/debugging bootstrap tools in IntelliJ
mcimadamore
parents:
diff changeset
   318
    public void taskFinished(BuildEvent event) {
b71804e27eb1 8049234: Add support for running/debugging bootstrap tools in IntelliJ
mcimadamore
parents:
diff changeset
   319
        if (tasks.peek() == Task.ROOT) {
b71804e27eb1 8049234: Add support for running/debugging bootstrap tools in IntelliJ
mcimadamore
parents:
diff changeset
   320
            //we need to 'close' the root task to get nicer output
b71804e27eb1 8049234: Add support for running/debugging bootstrap tools in IntelliJ
mcimadamore
parents:
diff changeset
   321
            logger.taskFinished(event);
b71804e27eb1 8049234: Add support for running/debugging bootstrap tools in IntelliJ
mcimadamore
parents:
diff changeset
   322
        } else if (!suppressTaskFailures && event.getException() != null) {
b71804e27eb1 8049234: Add support for running/debugging bootstrap tools in IntelliJ
mcimadamore
parents:
diff changeset
   323
            //the first (innermost) task failure should always be logged
b71804e27eb1 8049234: Add support for running/debugging bootstrap tools in IntelliJ
mcimadamore
parents:
diff changeset
   324
            event.setMessage(event.getException().toString(), 0);
b71804e27eb1 8049234: Add support for running/debugging bootstrap tools in IntelliJ
mcimadamore
parents:
diff changeset
   325
            event.setException(null);
b71804e27eb1 8049234: Add support for running/debugging bootstrap tools in IntelliJ
mcimadamore
parents:
diff changeset
   326
            //note: we turn this into a plain message to avoid stack trace being logged by Idea
b71804e27eb1 8049234: Add support for running/debugging bootstrap tools in IntelliJ
mcimadamore
parents:
diff changeset
   327
            logger.messageLogged(event);
b71804e27eb1 8049234: Add support for running/debugging bootstrap tools in IntelliJ
mcimadamore
parents:
diff changeset
   328
            suppressTaskFailures = true;
b71804e27eb1 8049234: Add support for running/debugging bootstrap tools in IntelliJ
mcimadamore
parents:
diff changeset
   329
        }
b71804e27eb1 8049234: Add support for running/debugging bootstrap tools in IntelliJ
mcimadamore
parents:
diff changeset
   330
        tasks.pop();
b71804e27eb1 8049234: Add support for running/debugging bootstrap tools in IntelliJ
mcimadamore
parents:
diff changeset
   331
    }
b71804e27eb1 8049234: Add support for running/debugging bootstrap tools in IntelliJ
mcimadamore
parents:
diff changeset
   332
b71804e27eb1 8049234: Add support for running/debugging bootstrap tools in IntelliJ
mcimadamore
parents:
diff changeset
   333
    @Override
b71804e27eb1 8049234: Add support for running/debugging bootstrap tools in IntelliJ
mcimadamore
parents:
diff changeset
   334
    public void messageLogged(BuildEvent event) {
b71804e27eb1 8049234: Add support for running/debugging bootstrap tools in IntelliJ
mcimadamore
parents:
diff changeset
   335
        String msg = event.getMessage();
b71804e27eb1 8049234: Add support for running/debugging bootstrap tools in IntelliJ
mcimadamore
parents:
diff changeset
   336
b71804e27eb1 8049234: Add support for running/debugging bootstrap tools in IntelliJ
mcimadamore
parents:
diff changeset
   337
        boolean processed = false;
b71804e27eb1 8049234: Add support for running/debugging bootstrap tools in IntelliJ
mcimadamore
parents:
diff changeset
   338
b71804e27eb1 8049234: Add support for running/debugging bootstrap tools in IntelliJ
mcimadamore
parents:
diff changeset
   339
        if (!tasks.isEmpty()) {
b71804e27eb1 8049234: Add support for running/debugging bootstrap tools in IntelliJ
mcimadamore
parents:
diff changeset
   340
            Task task = tasks.peek();
b71804e27eb1 8049234: Add support for running/debugging bootstrap tools in IntelliJ
mcimadamore
parents:
diff changeset
   341
            for (MessageKind messageKind : task.msgs) {
b71804e27eb1 8049234: Add support for running/debugging bootstrap tools in IntelliJ
mcimadamore
parents:
diff changeset
   342
                if (messageKind.matches(msg)) {
b71804e27eb1 8049234: Add support for running/debugging bootstrap tools in IntelliJ
mcimadamore
parents:
diff changeset
   343
                    event.setMessage(msg, messageKind.priority);
b71804e27eb1 8049234: Add support for running/debugging bootstrap tools in IntelliJ
mcimadamore
parents:
diff changeset
   344
                    processed = true;
b71804e27eb1 8049234: Add support for running/debugging bootstrap tools in IntelliJ
mcimadamore
parents:
diff changeset
   345
                    if (messageKind == MessageKind.JAVAC_CRASH) {
b71804e27eb1 8049234: Add support for running/debugging bootstrap tools in IntelliJ
mcimadamore
parents:
diff changeset
   346
                        crashFound = true;
b71804e27eb1 8049234: Add support for running/debugging bootstrap tools in IntelliJ
mcimadamore
parents:
diff changeset
   347
                    }
b71804e27eb1 8049234: Add support for running/debugging bootstrap tools in IntelliJ
mcimadamore
parents:
diff changeset
   348
                    break;
b71804e27eb1 8049234: Add support for running/debugging bootstrap tools in IntelliJ
mcimadamore
parents:
diff changeset
   349
                }
b71804e27eb1 8049234: Add support for running/debugging bootstrap tools in IntelliJ
mcimadamore
parents:
diff changeset
   350
            }
b71804e27eb1 8049234: Add support for running/debugging bootstrap tools in IntelliJ
mcimadamore
parents:
diff changeset
   351
        }
b71804e27eb1 8049234: Add support for running/debugging bootstrap tools in IntelliJ
mcimadamore
parents:
diff changeset
   352
b71804e27eb1 8049234: Add support for running/debugging bootstrap tools in IntelliJ
mcimadamore
parents:
diff changeset
   353
        if (event.getPriority() == MSG_ERR || crashFound) {
b71804e27eb1 8049234: Add support for running/debugging bootstrap tools in IntelliJ
mcimadamore
parents:
diff changeset
   354
            //we log errors regardless of owning task
b71804e27eb1 8049234: Add support for running/debugging bootstrap tools in IntelliJ
mcimadamore
parents:
diff changeset
   355
            logger.messageLogged(event);
b71804e27eb1 8049234: Add support for running/debugging bootstrap tools in IntelliJ
mcimadamore
parents:
diff changeset
   356
            suppressTaskFailures = true;
b71804e27eb1 8049234: Add support for running/debugging bootstrap tools in IntelliJ
mcimadamore
parents:
diff changeset
   357
        } else if (processed) {
b71804e27eb1 8049234: Add support for running/debugging bootstrap tools in IntelliJ
mcimadamore
parents:
diff changeset
   358
            logger.messageLogged(event);
b71804e27eb1 8049234: Add support for running/debugging bootstrap tools in IntelliJ
mcimadamore
parents:
diff changeset
   359
        }
b71804e27eb1 8049234: Add support for running/debugging bootstrap tools in IntelliJ
mcimadamore
parents:
diff changeset
   360
    }
b71804e27eb1 8049234: Add support for running/debugging bootstrap tools in IntelliJ
mcimadamore
parents:
diff changeset
   361
}