8267706: bin/idea.sh tries to use cygpath on WSL

Reviewed-by: erikj
This commit is contained in:
Nikita Gubarkov 2021-05-28 19:53:57 +00:00 committed by Alexey Ushakov
parent 591b0c3a46
commit 964bac9e38
14 changed files with 172 additions and 599 deletions

View File

@ -36,6 +36,7 @@ cd $SCRIPT_DIR; SCRIPT_DIR=`pwd`
cd $TOP;
IDEA_OUTPUT=$TOP/.idea
CUSTOM_IDEA_OUTPUT=false
VERBOSE="false"
while [ $# -gt 0 ]
do
@ -50,6 +51,7 @@ do
-o | --output )
IDEA_OUTPUT=$2/.idea
CUSTOM_IDEA_OUTPUT=true
shift
;;
@ -77,7 +79,7 @@ MAKE_DIR="$SCRIPT_DIR/../make"
IDEA_MAKE="$MAKE_DIR/ide/idea/jdk"
IDEA_TEMPLATE="$IDEA_MAKE/template"
cp -r "$IDEA_TEMPLATE"/* "$IDEA_OUTPUT"
cp -rn "$IDEA_TEMPLATE"/* "$IDEA_OUTPUT"
#override template
if [ -d "$TEMPLATES_OVERRIDE" ] ; then
@ -96,9 +98,9 @@ cd $SCRIPT_DIR
. $IDEA_OUTPUT/env.cfg
# 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
# Expect MODULES, MODULE_NAMES, BOOT_JDK & SPEC to be set
if [ "xMODULES" = "x" ] ; then
echo "FATAL: MODULES is empty" >&2; exit 1
fi
if [ "x$MODULE_NAMES" = "x" ] ; then
@ -147,102 +149,89 @@ add_replacement() {
add_replacement "###MODULE_NAMES###" "$MODULE_NAMES"
add_replacement "###VCS_TYPE###" "$VCS_TYPE"
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`"
RELATIVE_SPEC_DIR="`realpath --relative-to=\"$TOPLEVEL_DIR\" \"$SPEC_DIR\"`"
add_replacement "###BUILD_DIR###" "$RELATIVE_SPEC_DIR"
add_replacement "###IMAGES_DIR###" "$RELATIVE_SPEC_DIR/images/jdk"
if [ "x$PATHTOOL" != "x" ]; then
if [ "$CUSTOM_IDEA_OUTPUT" = true ]; then
add_replacement "###BASH_RUNNER_PREFIX###" "`$PATHTOOL -am $IDEA_OUTPUT/.idea/bash.bat`"
else
add_replacement "###BASH_RUNNER_PREFIX###" ".idea\\\\bash.bat"
fi
else
add_replacement "###BASH_RUNNER_PREFIX###" ""
fi
if [ "x$PATHTOOL" != "x" ]; then
if [ "x$JT_HOME" = "x" ]; then
add_replacement "###JTREG_HOME###" ""
else
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`"
add_replacement "###JTREG_HOME###" "`$PATHTOOL -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
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
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\" /> "
done
add_replacement "###SOURCE_ROOTS###" "$SOURCES"
add_replacement "###MODULE_IMLS###" "$MODULE_IMLS"
add_replacement "###TEST_MODULE_DEPENDENCIES###" "$TEST_MODULE_DEPENDENCIES"
replace_template_dir "$IDEA_OUTPUT"
### Compile the custom Logger
### Generate module project files
CLASSES=$IDEA_OUTPUT/classes
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
(
DEFAULT_IFS="$IFS"
IFS='#'
if [ "x$PATHTOOL" != "x" ]; then
TOPDIR_FOR_RELATIVITY_CHECKS="`echo \"$TOPLEVEL_DIR\" | tr '[:upper:]' '[:lower:]'`"
else
JAVAC_SOURCE_FILE=$IDEA_OUTPUT/src/idea/IdeaLoggerWrapper.java
JAVAC_SOURCE_PATH=$IDEA_OUTPUT/src
JAVAC_CLASSES=$CLASSES
JAVAC_CP=$CP
JAVAC=javac
TOPDIR_FOR_RELATIVITY_CHECKS="$TOPLEVEL_DIR"
fi
for value in $MODULES; do
(
eval "$value"
if [ "$VERBOSE" = "true" ] ; then
echo "generating project module: $module"
fi
add_replacement "###MODULE_DIR###" "src/$module"
SOURCE_DIRS=""
IFS=' '
for dir in $moduleSrcDirs; do
if [ "x$PATHTOOL" != "x" ]; then
dir="`echo \"$dir\" | tr '[:upper:]' '[:lower:]'`"
fi
dir="`realpath --relative-to=\"$TOPDIR_FOR_RELATIVITY_CHECKS\" \"$dir\"`"
case $dir in # Exclude generated sources to avoid module-info conflicts, see https://youtrack.jetbrains.com/issue/IDEA-185108
"$SPEC_DIR"*) ;;
*) 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
DEPENDENCIES="$DEPENDENCIES<orderEntry type=\"module\" module-name=\"$dep\" /> "
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"
$BOOT_JDK/bin/$JAVAC -d $JAVAC_CLASSES -sourcepath $JAVAC_SOURCE_PATH -cp $JAVAC_CP $JAVAC_SOURCE_FILE
### Create shell script runner for Windows
if [ "x$WSL_DISTRO_NAME" != "x" ]; then
rm -rf $ANT_TEMP
fi
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
fi

View File

@ -1,42 +0,0 @@
<!-- 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,13 +46,18 @@ else #with SPEC
endif
idea:
$(ECHO) "SUPPORT=$(SUPPORT_OUTPUTDIR)" >> $(OUT)
$(ECHO) "MODULE_ROOTS=\"$(foreach mod, $(SEL_MODULES), $(call FindModuleSrcDirs,$(mod)))\"" >> $(OUT)
$(ECHO) "SUPPORT=$(SUPPORT_OUTPUTDIR)" > $(OUT)
$(ECHO) "MODULES=\"$(foreach mod, $(SEL_MODULES), \
module='$(mod)' \
moduleSrcDirs='$(call FindModuleSrcDirs,$(mod))' \
moduleDependencies='$(call FindTransitiveDepsForModule,$(mod))' \
#)\"" >> $(OUT)
$(ECHO) "MODULE_NAMES=\"$(strip $(foreach mod, $(SEL_MODULES), $(mod)))\"" >> $(OUT)
$(ECHO) "SEL_MODULES=\"$(SEL_MODULES)\"" >> $(OUT)
$(ECHO) "BOOT_JDK=\"$(BOOT_JDK)\"" >> $(OUT)
$(ECHO) "CYGPATH=\"$(PATHTOOL)\"" >> $(OUT)
$(ECHO) "PATHTOOL=\"$(PATHTOOL)\"" >> $(OUT)
$(ECHO) "SPEC=\"$(SPEC)\"" >> $(OUT)
$(ECHO) "JT_HOME=\"$(JT_HOME)\"" >> $(OUT)
$(ECHO) "WINENV_ROOT=\"$(WINENV_ROOT)\"" >> $(OUT)
endif

View File

@ -1,14 +0,0 @@
<?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://###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" />
<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" />
</excludeFromCompile>
<resourceExtensions />
<wildcardResourcePatterns>

View File

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

View File

@ -5,14 +5,14 @@
</component>
<component name="JTRegService">
<path>###JTREG_HOME###</path>
<workDir>###BUILD_DIR###</workDir>
<jre alt="true" value="###IMAGES_DIR###" />
<workDir>$PROJECT_DIR$/###BUILD_DIR###</workDir>
<jre alt="true" value="$PROJECT_DIR$/###IMAGES_DIR###" />
<options></options>
<ant>
<target file="file://###ROOT_DIR###/make/ide/idea/jdk/build.xml" name="images" />
<target file="file://$PROJECT_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" />
<output url="file://$PROJECT_DIR$/###BUILD_DIR###/idea" />
</component>
</project>

View File

@ -0,0 +1,13 @@
<?xml version="1.0" encoding="UTF-8"?>
<module type="JAVA_MODULE" version="4">
<component name="NewModuleRootManager" inherit-compiler-output="true">
<exclude-output />
<content url="file://$MODULE_DIR$/###MODULE_DIR###">
###SOURCE_DIRS###
</content>
<orderEntry type="sourceFolder" forTests="false" />
###DEPENDENCIES###
<orderEntry type="inheritedJdk" />
</component>
</module>

View File

@ -3,6 +3,8 @@
<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

@ -1,13 +0,0 @@
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

@ -1,375 +0,0 @@
/*
* 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

@ -0,0 +1,10 @@
<?xml version="1.0" encoding="UTF-8"?>
<module type="JAVA_MODULE" version="4">
<component name="NewModuleRootManager" inherit-compiler-output="true">
<exclude-output />
<content url="file://$MODULE_DIR$/test/jdk"></content>
<orderEntry type="sourceFolder" forTests="true" />
###TEST_MODULE_DEPENDENCIES###
<orderEntry type="inheritedJdk" />
</component>
</module>

View File

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

View File

@ -2,63 +2,62 @@
<project version="4">
<component name="ChangeListManager">
<ignored path="jdk.iws" />
<ignored path="###ROOT_DIR###/build/idea/out/" />
<ignored path="$PROJECT_DIR$/build/idea/out/" />
<ignored path=".idea/" />
</component>
<component name="StructureViewFactory">
<option name="ACTIVE_ACTIONS" value=",ALPHA_COMPARATOR" />
</component>
<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 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>
</project>