8268768: idea.sh has been updated in surprising and incompatible ways

Reviewed-by: erikj
This commit is contained in:
Maurizio Cimadamore 2021-06-15 20:37:20 +00:00
parent 9ac0609ed1
commit 788b309563
12 changed files with 625 additions and 196 deletions

View File

@ -25,21 +25,7 @@
# Shell script for generating an IDEA project from a given list of modules
usage() {
echo "Usage: $0 [-h|--help] [-q|--quiet] [-a|--absolute-paths] [-o|--output <path>] [modules...]"
echo " -h | --help"
echo " -q | --quiet
No stdout output"
echo " -a | --absolute-paths
Use absolute paths to this jdk, so that generated .idea
project files can be moved independently of jdk sources"
echo " -o | --output <path>
Where .idea directory with project files will be generated
(e.g. using '-o .' will place project files in './.idea')
Default: $TOPLEVEL_DIR"
echo " [modules...]
Generate project modules for specific java modules
(e.g. 'java.base java.desktop')
Default: all existing modules (java.* and jdk.*)"
echo "usage: $0 [-h|--help] [-v|--verbose] [-o|--output <path>] [modules]+"
exit 1
}
@ -47,12 +33,10 @@ SCRIPT_DIR=`dirname $0`
#assume TOP is the dir from which the script has been called
TOP=`pwd`
cd $SCRIPT_DIR; SCRIPT_DIR=`pwd`
cd .. ; TOPLEVEL_DIR=`pwd`
cd $TOP;
IDEA_OUTPUT=$TOPLEVEL_DIR/.idea
VERBOSE=true
ABSOLUTE_PATHS=false
IDEA_OUTPUT=$TOP/.idea
VERBOSE="false"
while [ $# -gt 0 ]
do
case $1 in
@ -60,12 +44,8 @@ do
usage
;;
-q | --quiet )
VERBOSE=false
;;
-a | --absolute-paths )
ABSOLUTE_PATHS=true
-v | --vebose )
VERBOSE="true"
;;
-o | --output )
@ -86,13 +66,18 @@ done
mkdir -p $IDEA_OUTPUT || exit 1
cd $IDEA_OUTPUT; IDEA_OUTPUT=`pwd`
cd ..; IDEA_OUTPUT_PARENT=`pwd`
MAKE_DIR="$TOPLEVEL_DIR/make"
if [ "x$TOPLEVEL_DIR" = "x" ] ; then
cd $SCRIPT_DIR/..
TOPLEVEL_DIR=`pwd`
cd $IDEA_OUTPUT
fi
MAKE_DIR="$SCRIPT_DIR/../make"
IDEA_MAKE="$MAKE_DIR/ide/idea/jdk"
IDEA_TEMPLATE="$IDEA_MAKE/template"
cp -rn "$IDEA_TEMPLATE"/* "$IDEA_OUTPUT"
cp -r "$IDEA_TEMPLATE"/* "$IDEA_OUTPUT"
#override template
if [ -d "$TEMPLATES_OVERRIDE" ] ; then
@ -101,31 +86,31 @@ if [ -d "$TEMPLATES_OVERRIDE" ] ; then
done
fi
if [ "$VERBOSE" = true ] ; then
echo "Will generate IDEA project files in \"$IDEA_OUTPUT\" for project \"$TOPLEVEL_DIR\""
if [ "$VERBOSE" = "true" ] ; then
echo "output dir: $IDEA_OUTPUT"
echo "idea template dir: $IDEA_TEMPLATE"
fi
cd $TOP ; make -f "$IDEA_MAKE/idea.gmk" -I "$TOPLEVEL_DIR" idea \
MAKEOVERRIDES= IDEA_OUTPUT_PARENT="$IDEA_OUTPUT_PARENT" OUT="$IDEA_OUTPUT/env.cfg" MODULES="$*" || exit 1
cd $TOP ; make -f "$IDEA_MAKE/idea.gmk" -I $MAKE_DIR/.. idea MAKEOVERRIDES= OUT=$IDEA_OUTPUT/env.cfg MODULES="$*" || exit 1
cd $SCRIPT_DIR
. $IDEA_OUTPUT/env.cfg
# Expect MODULES, MODULE_NAMES, RELATIVE_PROJECT_DIR, RELATIVE_BUILD_DIR to be set
if [ "xMODULES" = "x" ] ; then
echo "FATAL: MODULES is empty" >&2; exit 1
# Expect MODULE_ROOTS, MODULE_NAMES, BOOT_JDK & SPEC to be set
if [ "x$MODULE_ROOTS" = "x" ] ; then
echo "FATAL: MODULE_ROOTS is empty" >&2; exit 1
fi
if [ "x$MODULE_NAMES" = "x" ] ; then
echo "FATAL: MODULE_NAMES is empty" >&2; exit 1
fi
if [ "x$RELATIVE_PROJECT_DIR" = "x" ] ; then
echo "FATAL: RELATIVE_PROJECT_DIR is empty" >&2; exit 1
if [ "x$BOOT_JDK" = "x" ] ; then
echo "FATAL: BOOT_JDK is empty" >&2; exit 1
fi
if [ "x$RELATIVE_BUILD_DIR" = "x" ] ; then
echo "FATAL: RELATIVE_BUILD_DIR is empty" >&2; exit 1
if [ "x$SPEC" = "x" ] ; then
echo "FATAL: SPEC is empty" >&2; exit 1
fi
if [ -d "$TOPLEVEL_DIR/.hg" ] ; then
@ -136,29 +121,6 @@ if [ -d "$TOPLEVEL_DIR/.git" ] ; then
VCS_TYPE="Git"
fi
if [ "$ABSOLUTE_PATHS" = true ] ; then
if [ "x$PATHTOOL" != "x" ]; then
PROJECT_DIR="`$PATHTOOL -am $TOPLEVEL_DIR`"
else
PROJECT_DIR="$TOPLEVEL_DIR"
fi
MODULE_DIR="$PROJECT_DIR"
cd "$TOPLEVEL_DIR" && cd "$RELATIVE_BUILD_DIR" && BUILD_DIR="`pwd`"
else
if [ "$RELATIVE_PROJECT_DIR" = "." ] ; then
PROJECT_DIR=""
else
PROJECT_DIR="/$RELATIVE_PROJECT_DIR"
fi
MODULE_DIR="\$MODULE_DIR\$$PROJECT_DIR"
PROJECT_DIR="\$PROJECT_DIR\$$PROJECT_DIR"
BUILD_DIR="\$PROJECT_DIR\$/$RELATIVE_BUILD_DIR"
fi
if [ "$VERBOSE" = true ] ; then
echo "Project root: $PROJECT_DIR"
echo "Generating IDEA project files..."
fi
### Replace template variables
NUM_REPLACEMENTS=0
@ -182,82 +144,105 @@ add_replacement() {
eval TO$NUM_REPLACEMENTS='$2'
}
add_replacement "###PROJECT_DIR###" "$PROJECT_DIR"
add_replacement "###MODULE_DIR###" "$MODULE_DIR"
add_replacement "###MODULE_NAMES###" "$MODULE_NAMES"
add_replacement "###VCS_TYPE###" "$VCS_TYPE"
add_replacement "###BUILD_DIR###" "$BUILD_DIR"
if [ "x$PATHTOOL" != "x" ]; then
add_replacement "###BASH_RUNNER_PREFIX###" "\$PROJECT_DIR\$/.idea/bash.bat"
else
add_replacement "###BASH_RUNNER_PREFIX###" ""
fi
if [ "x$PATHTOOL" != "x" ]; then
SPEC_DIR=`dirname $SPEC`
if [ "x$CYGPATH" != "x" ]; then
add_replacement "###BUILD_DIR###" "`cygpath -am $SPEC_DIR`"
add_replacement "###IMAGES_DIR###" "`cygpath -am $SPEC_DIR`/images/jdk"
add_replacement "###ROOT_DIR###" "`cygpath -am $TOPLEVEL_DIR`"
add_replacement "###IDEA_DIR###" "`cygpath -am $IDEA_OUTPUT`"
if [ "x$JT_HOME" = "x" ]; then
add_replacement "###JTREG_HOME###" ""
else
add_replacement "###JTREG_HOME###" "`$PATHTOOL -am $JT_HOME`"
add_replacement "###JTREG_HOME###" "`cygpath -am $JT_HOME`"
fi
elif [ "x$WSL_DISTRO_NAME" != "x" ]; then
add_replacement "###BUILD_DIR###" "`wslpath -am $SPEC_DIR`"
add_replacement "###IMAGES_DIR###" "`wslpath -am $SPEC_DIR`/images/jdk"
add_replacement "###ROOT_DIR###" "`wslpath -am $TOPLEVEL_DIR`"
add_replacement "###IDEA_DIR###" "`wslpath -am $IDEA_OUTPUT`"
if [ "x$JT_HOME" = "x" ]; then
add_replacement "###JTREG_HOME###" ""
else
add_replacement "###JTREG_HOME###" "`wslpath -am $JT_HOME`"
fi
else
add_replacement "###BUILD_DIR###" "$SPEC_DIR"
add_replacement "###JTREG_HOME###" "$JT_HOME"
add_replacement "###IMAGES_DIR###" "$SPEC_DIR/images/jdk"
add_replacement "###ROOT_DIR###" "$TOPLEVEL_DIR"
add_replacement "###IDEA_DIR###" "$IDEA_OUTPUT"
fi
MODULE_IMLS=""
TEST_MODULE_DEPENDENCIES=""
for module in $MODULE_NAMES; do
MODULE_IMLS="$MODULE_IMLS<module fileurl=\"file://\$PROJECT_DIR$/.idea/$module.iml\" filepath=\"\$PROJECT_DIR$/.idea/$module.iml\" /> "
TEST_MODULE_DEPENDENCIES="$TEST_MODULE_DEPENDENCIES<orderEntry type=\"module\" module-name=\"$module\" scope=\"TEST\" /> "
SOURCE_PREFIX="<sourceFolder url=\"file://"
SOURCE_POSTFIX="\" isTestSource=\"false\" />"
for root in $MODULE_ROOTS; do
if [ "x$CYGPATH" != "x" ]; then
root=`cygpath -am $root`
elif [ "x$WSL_DISTRO_NAME" != "x" ]; then
root=`wslpath -am $root`
fi
VM_CI="jdk.internal.vm.ci/share/classes"
VM_COMPILER="src/jdk.internal.vm.compiler/share/classes"
if test "${root#*$VM_CI}" != "$root" || test "${root#*$VM_COMPILER}" != "$root"; then
for subdir in "$root"/*; do
if [ -d "$subdir" ]; then
SOURCES=$SOURCES" $SOURCE_PREFIX""$subdir"/src"$SOURCE_POSTFIX"
fi
done
else
SOURCES=$SOURCES" $SOURCE_PREFIX""$root""$SOURCE_POSTFIX"
fi
done
add_replacement "###MODULE_IMLS###" "$MODULE_IMLS"
add_replacement "###TEST_MODULE_DEPENDENCIES###" "$TEST_MODULE_DEPENDENCIES"
add_replacement "###SOURCE_ROOTS###" "$SOURCES"
replace_template_dir "$IDEA_OUTPUT"
### Generate module project files
### Compile the custom Logger
if [ "$VERBOSE" = true ] ; then
echo "Generating project modules:"
fi
(
DEFAULT_IFS="$IFS"
IFS='#'
for value in $MODULES; do
(
eval "$value"
if [ "$VERBOSE" = true ] ; then
echo " $module"
fi
add_replacement "###MODULE_CONTENT###" "src/$module"
SOURCE_DIRS=""
IFS=' '
for dir in $moduleSrcDirs; do
case $dir in # Exclude generated sources to avoid module-info conflicts, see https://youtrack.jetbrains.com/issue/IDEA-185108
"src/"*) SOURCE_DIRS="$SOURCE_DIRS<sourceFolder url=\"file://$MODULE_DIR/$dir\" isTestSource=\"false\" /> "
esac
done
add_replacement "###SOURCE_DIRS###" "$SOURCE_DIRS"
DEPENDENCIES=""
for dep in $moduleDependencies; do
case $MODULE_NAMES in # Exclude skipped modules from dependencies
*"$dep"*) DEPENDENCIES="$DEPENDENCIES<orderEntry type=\"module\" module-name=\"$dep\" /> "
esac
done
add_replacement "###DEPENDENCIES###" "$DEPENDENCIES"
cp "$IDEA_OUTPUT/module.iml" "$IDEA_OUTPUT/$module.iml"
IFS="$DEFAULT_IFS"
replace_template_file "$IDEA_OUTPUT/$module.iml"
)
done
)
rm "$IDEA_OUTPUT/module.iml"
CLASSES=$IDEA_OUTPUT/classes
### Create shell script runner for Windows
if [ "x$PATHTOOL" != "x" ]; then
echo "@echo off" > "$IDEA_OUTPUT/bash.bat"
if [ "x$WSL_DISTRO_NAME" != "x" ] ; then
echo "wsl -d $WSL_DISTRO_NAME --cd \"%cd%\" -e %*" >> "$IDEA_OUTPUT/bash.bat"
else
echo "$WINENV_ROOT\bin\bash.exe -l -c \"cd %CD:\=/%/ && %*\"" >> "$IDEA_OUTPUT/bash.bat"
fi
if [ "x$ANT_HOME" = "x" ] ; then
# try some common locations, before giving up
if [ -f "/usr/share/ant/lib/ant.jar" ] ; then
ANT_HOME="/usr/share/ant"
elif [ -f "/usr/local/Cellar/ant/1.9.4/libexec/lib/ant.jar" ] ; then
ANT_HOME="/usr/local/Cellar/ant/1.9.4/libexec"
else
echo "FATAL: cannot find ant. Try setting ANT_HOME." >&2; exit 1
fi
fi
CP=$ANT_HOME/lib/ant.jar
rm -rf $CLASSES; mkdir $CLASSES
if [ "x$CYGPATH" != "x" ] ; then ## CYGPATH may be set in env.cfg
JAVAC_SOURCE_FILE=`cygpath -am $IDEA_OUTPUT/src/idea/IdeaLoggerWrapper.java`
JAVAC_SOURCE_PATH=`cygpath -am $IDEA_OUTPUT/src`
JAVAC_CLASSES=`cygpath -am $CLASSES`
JAVAC_CP=`cygpath -am $CP`
JAVAC=javac
elif [ "x$WSL_DISTRO_NAME" != "x" ]; then
JAVAC_SOURCE_FILE=`realpath --relative-to=./ $IDEA_OUTPUT/src/idea/IdeaLoggerWrapper.java`
JAVAC_SOURCE_PATH=`realpath --relative-to=./ $IDEA_OUTPUT/src`
JAVAC_CLASSES=`realpath --relative-to=./ $CLASSES`
ANT_TEMP=`mktemp -d -p ./`
cp $ANT_HOME/lib/ant.jar $ANT_TEMP/ant.jar
JAVAC_CP=$ANT_TEMP/ant.jar
JAVAC=javac.exe
else
JAVAC_SOURCE_FILE=$IDEA_OUTPUT/src/idea/IdeaLoggerWrapper.java
JAVAC_SOURCE_PATH=$IDEA_OUTPUT/src
JAVAC_CLASSES=$CLASSES
JAVAC_CP=$CP
JAVAC=javac
fi
$BOOT_JDK/bin/$JAVAC -d $JAVAC_CLASSES -sourcepath $JAVAC_SOURCE_PATH -cp $JAVAC_CP $JAVAC_SOURCE_FILE
if [ "x$WSL_DISTRO_NAME" != "x" ]; then
rm -rf $ANT_TEMP
fi

View File

@ -0,0 +1,42 @@
<!-- importing.xml -->
<project name="jdk">
<taskdef name="wrapLogger" classname="idea.IdeaLoggerWrapper" classpath="${idea.dir}/classes"/>
<wrapLogger/>
<macrodef name="call-make">
<attribute name="dir"/>
<attribute name="args"/>
<sequential>
<exec executable="make" dir="@{dir}" failonerror="true">
<arg line="@{args}"/>
<env key="CLASSPATH" value = ""/>
</exec>
</sequential>
</macrodef>
<target name="cond-clean" unless="${intellij.ismake}">
<antcall target="clean"/>
</target>
<target name="post-make" depends="cond-clean, build-module"/>
<!--
**** Global JDK Build Targets
-->
<target name="clean">
<echo message="base = ${basedir}"/>
<call-make dir = "${build.target.dir}" args = "reconfigure"/>
<call-make dir = "${build.target.dir}" args = "clean"/>
</target>
<target name="images">
<call-make dir = "${build.target.dir}" args = "images"/>
</target>
<target name="build-module">
<call-make dir = "${build.target.dir}" args = "${module.name}"/>
</target>
</project>

View File

@ -46,16 +46,13 @@ else #with SPEC
endif
idea:
$(ECHO) "MODULES=\"$(foreach mod, $(SEL_MODULES), \
module='$(mod)' \
moduleSrcDirs='$(foreach m,$(call FindModuleSrcDirs,$(mod)),$(call RelativePath,$m,$(topdir)))' \
moduleDependencies='$(call FindTransitiveDepsForModule,$(mod))' \
#)\"" > $(OUT)
$(ECHO) "SUPPORT=$(SUPPORT_OUTPUTDIR)" >> $(OUT)
$(ECHO) "MODULE_ROOTS=\"$(foreach mod, $(SEL_MODULES), $(call FindModuleSrcDirs,$(mod)))\"" >> $(OUT)
$(ECHO) "MODULE_NAMES=\"$(strip $(foreach mod, $(SEL_MODULES), $(mod)))\"" >> $(OUT)
$(ECHO) "RELATIVE_PROJECT_DIR=\"$(call RelativePath,$(topdir),$(IDEA_OUTPUT_PARENT))\"" >> $(OUT)
$(ECHO) "RELATIVE_BUILD_DIR=\"$(call RelativePath,$(OUTPUTDIR),$(IDEA_OUTPUT_PARENT))\"" >> $(OUT)
$(ECHO) "PATHTOOL=\"$(PATHTOOL)\"" >> $(OUT)
$(ECHO) "SEL_MODULES=\"$(SEL_MODULES)\"" >> $(OUT)
$(ECHO) "BOOT_JDK=\"$(BOOT_JDK)\"" >> $(OUT)
$(ECHO) "CYGPATH=\"$(PATHTOOL)\"" >> $(OUT)
$(ECHO) "SPEC=\"$(SPEC)\"" >> $(OUT)
$(ECHO) "JT_HOME=\"$(JT_HOME)\"" >> $(OUT)
$(ECHO) "WINENV_ROOT=\"$(WINENV_ROOT)\"" >> $(OUT)
endif

View File

@ -0,0 +1,14 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="AntConfiguration">
<buildFile url="file://###ROOT_DIR###/make/ide/idea/jdk/build.xml">
<properties>
<property name="intellij.ismake" value="$IsMake$" />
<property name="build.target.dir" value="###BUILD_DIR###" />
<property name="module.name" value="###MODULE_NAMES###" />
<property name="idea.dir" value="###IDEA_DIR###" />
</properties>
<executeOn event="afterCompilation" target="post-make" />
</buildFile>
</component>
</project>

View File

@ -3,10 +3,10 @@
<component name="CompilerConfiguration">
<option name="DEFAULT_COMPILER" value="Javac" />
<excludeFromCompile>
<directory url="file://###PROJECT_DIR###/src" includeSubdirectories="true" />
<directory url="file://###PROJECT_DIR###/build" includeSubdirectories="true" />
<directory url="file://###PROJECT_DIR###/make" includeSubdirectories="true" />
<directory url="file://###PROJECT_DIR###/test" includeSubdirectories="false" />
<directory url="file://###ROOT_DIR###/src" includeSubdirectories="true" />
<directory url="file://###ROOT_DIR###/build" includeSubdirectories="true" />
<directory url="file://###ROOT_DIR###/make" includeSubdirectories="true" />
<directory url="file://###ROOT_DIR###/test" includeSubdirectories="true" />
</excludeFromCompile>
<resourceExtensions />
<wildcardResourcePatterns>

View File

@ -2,9 +2,10 @@
<module type="JAVA_MODULE" version="4">
<component name="NewModuleRootManager" inherit-compiler-output="true">
<exclude-output />
<content url="file://###MODULE_DIR###">
<excludeFolder url="file://###MODULE_DIR###/build" />
<excludeFolder url="file://###MODULE_DIR###/make" />
<content url="file://###ROOT_DIR###">
###SOURCE_ROOTS###
<excludeFolder url="file://###ROOT_DIR###/build" />
<excludeFolder url="file://###ROOT_DIR###/make" />
</content>
<orderEntry type="sourceFolder" forTests="false" />
<orderEntry type="inheritedJdk" />

View File

@ -6,8 +6,11 @@
<component name="JTRegService">
<path>###JTREG_HOME###</path>
<workDir>###BUILD_DIR###</workDir>
<jre alt="true" value="###BUILD_DIR###/images/jdk" />
<jre alt="true" value="###IMAGES_DIR###" />
<options></options>
<ant>
<target file="file://###ROOT_DIR###/make/ide/idea/jdk/build.xml" name="images" />
</ant>
</component>
<component name="ProjectRootManager" version="2" languageLevel="JDK_16" assert-keyword="true" jdk-15="true">
<output url="file://###BUILD_DIR###/idea" />

View File

@ -3,8 +3,6 @@
<component name="ProjectModuleManager">
<modules>
<module fileurl="file://$PROJECT_DIR$/.idea/jdk.iml" filepath="$PROJECT_DIR$/.idea/jdk.iml" />
###MODULE_IMLS###
<module fileurl="file://$PROJECT_DIR$/.idea/test.iml" filepath="$PROJECT_DIR$/.idea/test.iml" />
</modules>
</component>
</project>

View File

@ -0,0 +1,13 @@
package idea;
import org.apache.tools.ant.Task;
/**
* This class implements a custom Ant task which replaces the standard Intellij IDEA Ant logger
* with a custom one which generates tighter output.
*/
public class IdeaLoggerWrapper extends Task {
public void execute() {
new JdkIdeaAntLogger(getProject());
}
}

View File

@ -0,0 +1,375 @@
/*
* Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
package idea;
import org.apache.tools.ant.BuildEvent;
import org.apache.tools.ant.BuildListener;
import org.apache.tools.ant.DefaultLogger;
import org.apache.tools.ant.Project;
import java.util.EnumSet;
import java.util.Stack;
import static org.apache.tools.ant.Project.*;
/**
* This class is used to wrap the IntelliJ ant logger in order to provide more meaningful
* output when building langtools. The basic ant output in IntelliJ can be quite cumbersome to
* work with, as it provides two separate views: (i) a tree view, which is good to display build task
* in a hierarchical fashion as they are processed; and a (ii) plain text view, which gives you
* the full ant output. The main problem is that javac-related messages are buried into the
* ant output (which is made very verbose by IntelliJ in order to support the tree view). It is
* not easy to figure out which node to expand in order to see the error message; switching
* to plain text doesn't help either, as now the output is totally flat.
*
* This logger class removes a lot of verbosity from the IntelliJ ant logger by not propagating
* all the events to the IntelliJ's logger. In addition, certain events are handled in a custom
* fashion, to generate better output during the build.
*/
public final class JdkIdeaAntLogger extends DefaultLogger {
/**
* This is just a way to pass in customized binary string predicates;
*
* TODO: replace with @code{BiPredicate<String, String>} and method reference when moving to 8
*/
enum StringBinaryPredicate {
CONTAINS() {
@Override
boolean apply(String s1, String s2) {
return s1.contains(s2);
}
},
STARTS_WITH {
@Override
boolean apply(String s1, String s2) {
return s1.startsWith(s2);
}
},
MATCHES {
@Override
boolean apply(String s1, String s2) {
return s1.matches(s2);
}
};
abstract boolean apply(String s1, String s2);
}
/**
* Various kinds of ant messages that we shall intercept
*/
enum MessageKind {
/** a make error */
MAKE_ERROR(StringBinaryPredicate.CONTAINS, MSG_ERR, "error:", "compiler.err"),
/** a make warning */
MAKE_WARNING(StringBinaryPredicate.CONTAINS, MSG_WARN, "warning:", "compiler.warn"),
/** a make note */
MAKE_NOTE(StringBinaryPredicate.CONTAINS, MSG_INFO, "note:", "compiler.note"),
/** std make output */
MAKE_OTHER(StringBinaryPredicate.MATCHES, MSG_INFO, ".*"),
/** a javac crash */
JAVAC_CRASH(StringBinaryPredicate.STARTS_WITH, MSG_ERR, "An exception has occurred in the compiler"),
/** jtreg test success */
JTREG_TEST_PASSED(StringBinaryPredicate.STARTS_WITH, MSG_INFO, "Passed: "),
/** jtreg test failure */
JTREG_TEST_FAILED(StringBinaryPredicate.STARTS_WITH, MSG_ERR, "FAILED: "),
/** jtreg test error */
JTREG_TEST_ERROR(StringBinaryPredicate.STARTS_WITH, MSG_ERR, "Error: "),
/** jtreg report */
JTREG_TEST_REPORT(StringBinaryPredicate.STARTS_WITH, MSG_INFO, "Report written");
StringBinaryPredicate sbp;
int priority;
String[] keys;
MessageKind(StringBinaryPredicate sbp, int priority, String... keys) {
this.sbp = sbp;
this.priority = priority;
this.keys = keys;
}
/**
* Does a given message string matches this kind?
*/
boolean matches(String s) {
for (String key : keys) {
if (sbp.apply(s, key)) {
return true;
}
}
return false;
}
}
/**
* This enum is used to represent the list of tasks we need to keep track of during logging.
*/
enum Task {
/** javac task - invoked during compilation */
MAKE("exec", MessageKind.MAKE_ERROR, MessageKind.MAKE_WARNING, MessageKind.MAKE_NOTE,
MessageKind.MAKE_OTHER, MessageKind.JAVAC_CRASH),
/** jtreg task - invoked during test execution */
JTREG("jtreg", MessageKind.JTREG_TEST_PASSED, MessageKind.JTREG_TEST_FAILED, MessageKind.JTREG_TEST_ERROR, MessageKind.JTREG_TEST_REPORT),
/** initial synthetic task when the logger is created */
ROOT("") {
@Override
boolean matches(String s) {
return false;
}
},
/** synthetic task catching any other tasks not in this list */
ANY("") {
@Override
boolean matches(String s) {
return true;
}
};
String taskName;
MessageKind[] msgs;
Task(String taskName, MessageKind... msgs) {
this.taskName = taskName;
this.msgs = msgs;
}
boolean matches(String s) {
return s.equals(taskName);
}
}
/**
* This enum is used to represent the list of targets we need to keep track of during logging.
* A regular expression is used to match a given target name.
*/
enum Target {
/** jtreg target - executed when launching tests */
JTREG("jtreg") {
@Override
String getDisplayMessage(BuildEvent e) {
return "Running jtreg tests: " + e.getProject().getProperty("jtreg.tests");
}
},
/** build selected modules */
BUILD_MODULE("build-module") {
@Override
String getDisplayMessage(BuildEvent e) {
return "Building modules: " + e.getProject().getProperty("module.name") + "...";
}
},
/** build images */
BUILD_IMAGES("images") {
@Override
String getDisplayMessage(BuildEvent e) {
return "Building images...";
}
},
/** build images */
CONFIGURE("-do-configure") {
@Override
String getDisplayMessage(BuildEvent e) {
return "Configuring build...";
}
},
/** synthetic target catching any other target not in this list */
ANY("") {
@Override
String getDisplayMessage(BuildEvent e) {
return "Executing Ant target(s): " + e.getProject().getProperty("ant.project.invoked-targets");
}
@Override
boolean matches(String msg) {
return true;
}
};
String targetRegex;
Target(String targetRegex) {
this.targetRegex = targetRegex;
}
boolean matches(String msg) {
return msg.matches(targetRegex);
}
abstract String getDisplayMessage(BuildEvent e);
}
/**
* A custom build event used to represent status changes which should be notified inside
* Intellij
*/
static class StatusEvent extends BuildEvent {
/** the target to which the status update refers */
Target target;
StatusEvent(BuildEvent e, Target target) {
super(new StatusTask(e, target.getDisplayMessage(e)));
this.target = target;
setMessage(getTask().getTaskName(), 2);
}
/**
* A custom task used to channel info regarding a status change
*/
static class StatusTask extends org.apache.tools.ant.Task {
StatusTask(BuildEvent event, String msg) {
setProject(event.getProject());
setOwningTarget(event.getTarget());
setTaskName(msg);
}
}
}
/** wrapped ant logger (IntelliJ's own logger) */
DefaultLogger logger;
/** flag - is this the first target we encounter? */
boolean firstTarget = true;
/** flag - should subsequenet failures be suppressed ? */
boolean suppressTaskFailures = false;
/** flag - have we ran into a javac crash ? */
boolean crashFound = false;
/** stack of status changes associated with pending targets */
Stack<StatusEvent> statusEvents = new Stack<>();
/** stack of pending tasks */
Stack<Task> tasks = new Stack<>();
public JdkIdeaAntLogger(Project project) {
for (Object o : project.getBuildListeners()) {
if (o instanceof DefaultLogger) {
this.logger = (DefaultLogger)o;
project.removeBuildListener((BuildListener)o);
project.addBuildListener(this);
}
}
tasks.push(Task.ROOT);
}
@Override
public void buildStarted(BuildEvent event) {
//do nothing
}
@Override
public void buildFinished(BuildEvent event) {
//do nothing
}
@Override
public void targetStarted(BuildEvent event) {
EnumSet<Target> statusKinds = firstTarget ?
EnumSet.allOf(Target.class) :
EnumSet.complementOf(EnumSet.of(Target.ANY));
String targetName = event.getTarget().getName();
for (Target statusKind : statusKinds) {
if (statusKind.matches(targetName)) {
StatusEvent statusEvent = new StatusEvent(event, statusKind);
statusEvents.push(statusEvent);
logger.taskStarted(statusEvent);
firstTarget = false;
return;
}
}
}
@Override
public void targetFinished(BuildEvent event) {
if (!statusEvents.isEmpty()) {
StatusEvent lastEvent = statusEvents.pop();
if (lastEvent.target.matches(event.getTarget().getName())) {
logger.taskFinished(lastEvent);
}
}
}
@Override
public void taskStarted(BuildEvent event) {
String taskName = event.getTask().getTaskName();
System.err.println("task started " + taskName);
for (Task task : Task.values()) {
if (task.matches(taskName)) {
tasks.push(task);
return;
}
}
}
@Override
public void taskFinished(BuildEvent event) {
if (tasks.peek() == Task.ROOT) {
//we need to 'close' the root task to get nicer output
logger.taskFinished(event);
} else if (!suppressTaskFailures && event.getException() != null) {
//the first (innermost) task failure should always be logged
event.setMessage(event.getException().toString(), 0);
event.setException(null);
//note: we turn this into a plain message to avoid stack trace being logged by Idea
logger.messageLogged(event);
suppressTaskFailures = true;
}
tasks.pop();
}
@Override
public void messageLogged(BuildEvent event) {
String msg = event.getMessage();
boolean processed = false;
if (!tasks.isEmpty()) {
Task task = tasks.peek();
for (MessageKind messageKind : task.msgs) {
if (messageKind.matches(msg)) {
event.setMessage(msg, messageKind.priority);
processed = true;
if (messageKind == MessageKind.JAVAC_CRASH) {
crashFound = true;
}
break;
}
}
}
if (event.getPriority() == MSG_ERR || crashFound) {
//we log errors regardless of owning task
logger.messageLogged(event);
suppressTaskFailures = true;
} else if (processed) {
logger.messageLogged(event);
}
}
}

View File

@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="VcsDirectoryMappings">
<mapping directory="###PROJECT_DIR###" vcs="###VCS_TYPE###" />
<mapping directory="###ROOT_DIR###" vcs="###VCS_TYPE###" />
</component>
</project>

View File

@ -2,62 +2,63 @@
<project version="4">
<component name="ChangeListManager">
<ignored path="jdk.iws" />
<ignored path="###PROJECT_DIR###/build/idea/out/" />
<ignored path="###ROOT_DIR###/build/idea/out/" />
<ignored path=".idea/" />
</component>
<component name="StructureViewFactory">
<option name="ACTIVE_ACTIONS" value=",ALPHA_COMPARATOR" />
</component>
<component name="RunManager" selected="Shell Script.images">
<configuration name="clean" type="ShConfigurationType" folderName="make">
<option name="SCRIPT_TEXT" value="###BASH_RUNNER_PREFIX### make clean" />
<option name="INDEPENDENT_SCRIPT_PATH" value="true" />
<option name="SCRIPT_PATH" value="" />
<option name="SCRIPT_OPTIONS" value="" />
<option name="INDEPENDENT_SCRIPT_WORKING_DIRECTORY" value="true" />
<option name="SCRIPT_WORKING_DIRECTORY" value="###PROJECT_DIR###" />
<option name="INDEPENDENT_INTERPRETER_PATH" value="true" />
<option name="INTERPRETER_PATH" value="" />
<option name="INTERPRETER_OPTIONS" value="" />
<option name="EXECUTE_IN_TERMINAL" value="true" />
<option name="EXECUTE_SCRIPT_FILE" value="false" />
<envs />
<method v="2" />
</configuration>
<configuration name="images" type="ShConfigurationType" folderName="make">
<option name="SCRIPT_TEXT" value="###BASH_RUNNER_PREFIX### make images" />
<option name="INDEPENDENT_SCRIPT_PATH" value="true" />
<option name="SCRIPT_PATH" value="" />
<option name="SCRIPT_OPTIONS" value="" />
<option name="INDEPENDENT_SCRIPT_WORKING_DIRECTORY" value="true" />
<option name="SCRIPT_WORKING_DIRECTORY" value="###PROJECT_DIR###" />
<option name="INDEPENDENT_INTERPRETER_PATH" value="true" />
<option name="INTERPRETER_PATH" value="" />
<option name="INTERPRETER_OPTIONS" value="" />
<option name="EXECUTE_IN_TERMINAL" value="true" />
<option name="EXECUTE_SCRIPT_FILE" value="false" />
<envs />
<method v="2" />
</configuration>
<configuration name="reconfigure" type="ShConfigurationType" folderName="make">
<option name="SCRIPT_TEXT" value="###BASH_RUNNER_PREFIX### make reconfigure" />
<option name="INDEPENDENT_SCRIPT_PATH" value="true" />
<option name="SCRIPT_PATH" value="" />
<option name="SCRIPT_OPTIONS" value="" />
<option name="INDEPENDENT_SCRIPT_WORKING_DIRECTORY" value="true" />
<option name="SCRIPT_WORKING_DIRECTORY" value="###PROJECT_DIR###" />
<option name="INDEPENDENT_INTERPRETER_PATH" value="true" />
<option name="INTERPRETER_PATH" value="" />
<option name="INTERPRETER_OPTIONS" value="" />
<option name="EXECUTE_IN_TERMINAL" value="true" />
<option name="EXECUTE_SCRIPT_FILE" value="false" />
<envs />
<method v="2" />
</configuration>
<list>
<item itemvalue="Shell Script.images" />
<item itemvalue="Shell Script.clean" />
<item itemvalue="Shell Script.reconfigure" />
</list>
<component name="antWorkspaceConfiguration">
<option name="IS_AUTOSCROLL_TO_SOURCE" value="false" />
<option name="FILTER_TARGETS" value="false" />
<buildFile url="file://###ROOT_DIR###/make/ide/idea/jdk/build.xml">
<runInBackground value="false" />
<targetFilters>
<filter targetName="clean" isVisible="true" />
<filter targetName="images" isVisible="true" />
</targetFilters>
<treeView value="false" />
<expanded value="true" />
</buildFile>
</component>
<component name="ProjectView">
<navigator currentView="ProjectPane" proportions="" version="1">
<flattenPackages />
<showMembers />
<showModules />
<showLibraryContents />
<hideEmptyPackages />
<abbreviatePackageNames />
<autoscrollToSource />
<autoscrollFromSource />
<sortByType />
</navigator>
<panes>
<pane id="ProjectPane">
<subPane>
<PATH>
<PATH_ELEMENT>
<option name="myItemId" value="jdk" />
<option name="myItemType" value="com.intellij.ide.projectView.impl.nodes.ProjectViewProjectNode" />
</PATH_ELEMENT>
</PATH>
</subPane>
</pane>
<pane id="PackagesPane">
<subPane>
<PATH>
<PATH_ELEMENT>
<option name="myItemId" value="jdk" />
<option name="myItemType" value="com.intellij.ide.projectView.impl.nodes.PackageViewProjectNode" />
</PATH_ELEMENT>
<PATH_ELEMENT>
<option name="myItemId" value="jdk" />
<option name="myItemType" value="com.intellij.ide.projectView.impl.nodes.PackageViewModuleNode" />
</PATH_ELEMENT>
</PATH>
</subPane>
</pane>
<pane id="Scope" />
</panes>
</component>
</project>