# HG changeset patch
# User mcimadamore
# Date 1535734907 -3600
# Node ID bdac20c6c8dd7cc4d64da046e891daf5c5a2c6ac
# Parent 2ef81feac8b8e794554b302fe66b004cfb6f7e39
8210226: Add support for multiple project folders to idea.sh
Summary: Overhaul templating logic for idea.sh; add support for -o option
Reviewed-by: erikj, ihse
diff -r 2ef81feac8b8 -r bdac20c6c8dd bin/idea.sh
--- a/bin/idea.sh Fri Aug 31 09:53:37 2018 -0700
+++ b/bin/idea.sh Fri Aug 31 18:01:47 2018 +0100
@@ -49,7 +49,7 @@
;;
-o | --output )
- IDEA_OUTPUT=$2
+ IDEA_OUTPUT=$2/.idea
shift
;;
@@ -64,28 +64,25 @@
shift
done
-mkdir $IDEA_OUTPUT || exit 1
+mkdir -p $IDEA_OUTPUT || exit 1
cd $IDEA_OUTPUT; IDEA_OUTPUT=`pwd`
+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/idea"
IDEA_TEMPLATE="$IDEA_MAKE/template"
cp -r "$IDEA_TEMPLATE"/* "$IDEA_OUTPUT"
-#init template variables
-for file in `ls -p $IDEA_TEMPLATE | grep -v /`; do
- VAR_SUFFIX=`echo $file | cut -d'.' -f1 | tr [:lower:] [:upper:]`
- eval "$VAR_SUFFIX"_TEMPLATE="$IDEA_TEMPLATE"/$file
- eval IDEA_"$VAR_SUFFIX"="$IDEA_OUTPUT"/$file
-done
-
-#override template variables
+#override template
if [ -d "$TEMPLATES_OVERRIDE" ] ; then
for file in `ls -p "$TEMPLATES_OVERRIDE" | grep -v /`; do
cp "$TEMPLATES_OVERRIDE"/$file "$IDEA_OUTPUT"/
- VAR_SUFFIX=`echo $file | cut -d'.' -f1 | tr [:lower:] [:upper:]`
- eval "$VAR_SUFFIX"_TEMPLATE="$TEMPLATES_OVERRIDE"/$file
done
fi
@@ -94,14 +91,6 @@
echo "idea template dir: $IDEA_TEMPLATE"
fi
-if [ ! -f "$JDK_TEMPLATE" ] ; then
- echo "FATAL: cannot find $JDK_TEMPLATE" >&2; exit 1
-fi
-
-if [ ! -f "$ANT_TEMPLATE" ] ; then
- echo "FATAL: cannot find $ANT_TEMPLATE" >&2; exit 1
-fi
-
cd $TOP ; make -f "$IDEA_MAKE/idea.gmk" -I $MAKE_DIR/.. idea MAKEOVERRIDES= OUT=$IDEA_OUTPUT/env.cfg MODULES="$*" || exit 1
cd $SCRIPT_DIR
@@ -124,8 +113,6 @@
echo "FATAL: SPEC is empty" >&2; exit 1
fi
-SOURCE_FOLDER=" "
-SOURCE_FOLDERS_DONE="false"
addSourceFolder() {
root=$@
@@ -134,84 +121,45 @@
printf "%s\n" "$folder" >> $IDEA_JDK
}
-### Generate project iml
+### Replace template variables
+
+NUM_REPLACEMENTS=0
-rm -f $IDEA_JDK
-while IFS= read -r line
-do
- if echo "$line" | egrep "^ .* /dev/null ; then
- if [ "$SOURCE_FOLDERS_DONE" = "false" ] ; then
- SOURCE_FOLDERS_DONE="true"
- for root in $MODULE_ROOTS; do
- addSourceFolder $root
- done
- fi
- else
- printf "%s\n" "$line" >> $IDEA_JDK
- fi
-done < "$JDK_TEMPLATE"
-
-
-MODULE_NAME=" "
-
-addModuleName() {
- mn="`echo "$MODULE_NAME" | sed -e s@"\(.*\)####\(.*\)"@"\1$MODULE_NAMES\2"@`"
- printf "%s\n" "$mn" >> $IDEA_ANT
+replace_template_file() {
+ for i in $(seq 1 $NUM_REPLACEMENTS); do
+ eval "sed -i \"s|\${FROM${i}}|\${TO${i}}|g\" $1"
+ done
}
-BUILD_DIR=" "
-
-addBuildDir() {
- DIR=`dirname $SPEC`
- mn="`echo "$BUILD_DIR" | sed -e s@"\(.*\)####\(.*\)"@"\1$DIR\2"@`"
- printf "%s\n" "$mn" >> $IDEA_ANT
+replace_template_dir() {
+ for f in `find $1 -type f` ; do
+ replace_template_file $f
+ done
}
-### Generate ant.xml
-
-rm -f $IDEA_ANT
-while IFS= read -r line
-do
- if echo "$line" | egrep "^ .* /dev/null ; then
- addModuleName
- elif echo "$line" | egrep "^ .* /dev/null ; then
- addBuildDir
- else
- printf "%s\n" "$line" >> $IDEA_ANT
- fi
-done < "$ANT_TEMPLATE"
-
-### Generate misc.xml
-
-rm -f $IDEA_MISC
-
-JTREG_HOME=" ####"
-
-IMAGES_DIR=" "
-
-addImagesDir() {
- DIR=`dirname $SPEC`/images/jdk
- mn="`echo "$IMAGES_DIR" | sed -e s@"\(.*\)####\(.*\)"@"\1$DIR\2"@`"
- printf "%s\n" "$mn" >> $IDEA_MISC
+add_replacement() {
+ NUM_REPLACEMENTS=`expr $NUM_REPLACEMENTS + 1`
+ eval FROM$NUM_REPLACEMENTS='$1'
+ eval TO$NUM_REPLACEMENTS='$2'
}
-addJtregHome() {
- DIR=`dirname $SPEC`
- mn="`echo "$JTREG_HOME" | sed -e s@"\(.*\)####\(.*\)"@"\1$JT_HOME\2"@`"
- printf "%s\n" "$mn" >> $IDEA_MISC
-}
+add_replacement "###BUILD_DIR###" "`dirname $SPEC`"
+add_replacement "###MODULE_NAMES###" "$MODULE_NAMES"
+add_replacement "###JTREG_HOME###" "$JT_HOME"
+add_replacement "###IMAGES_DIR###" "`dirname $SPEC`/images/jdk"
+add_replacement "###ROOT_DIR###" "$TOPLEVEL_DIR"
+add_replacement "###IDEA_DIR###" "$IDEA_OUTPUT"
-rm -f $MISC_ANT
-while IFS= read -r line
-do
- if echo "$line" | egrep "^ .*jtreg_home" > /dev/null ; then
- addJtregHome
- elif echo "$line" | egrep "^ .* /dev/null ; then
- addImagesDir
- else
- printf "%s\n" "$line" >> $IDEA_MISC
- fi
-done < "$MISC_TEMPLATE"
+SOURCE_PREFIX=""
+
+for root in $MODULE_ROOTS; do
+ SOURCES=$SOURCES"\n$SOURCE_PREFIX""$root""$SOURCE_POSTFIX"
+done
+
+add_replacement "###SOURCE_ROOTS###" "$SOURCES"
+
+replace_template_dir "$IDEA_OUTPUT"
### Compile the custom Logger
diff -r 2ef81feac8b8 -r bdac20c6c8dd make/idea/template/ant.xml
--- a/make/idea/template/ant.xml Fri Aug 31 09:53:37 2018 -0700
+++ b/make/idea/template/ant.xml Fri Aug 31 18:01:47 2018 +0100
@@ -1,12 +1,12 @@
-
+
-
-
-
+
+
+
diff -r 2ef81feac8b8 -r bdac20c6c8dd make/idea/template/compiler.xml
--- a/make/idea/template/compiler.xml Fri Aug 31 09:53:37 2018 -0700
+++ b/make/idea/template/compiler.xml Fri Aug 31 18:01:47 2018 +0100
@@ -3,10 +3,10 @@
-
-
-
-
+
+
+
+
@@ -25,4 +25,5 @@
-
\ No newline at end of file
+
+
diff -r 2ef81feac8b8 -r bdac20c6c8dd make/idea/template/jdk.iml
--- a/make/idea/template/jdk.iml Fri Aug 31 09:53:37 2018 -0700
+++ b/make/idea/template/jdk.iml Fri Aug 31 18:01:47 2018 +0100
@@ -2,10 +2,10 @@
-
-
-
-
+
+ ###SOURCE_ROOTS###
+
+
diff -r 2ef81feac8b8 -r bdac20c6c8dd make/idea/template/misc.xml
--- a/make/idea/template/misc.xml Fri Aug 31 09:53:37 2018 -0700
+++ b/make/idea/template/misc.xml Fri Aug 31 18:01:47 2018 +0100
@@ -4,15 +4,15 @@
- jtreg_home
- build
-
+ ###JTREG_HOME###
+ ###BUILD_DIR###
+
-
+
-
+
diff -r 2ef81feac8b8 -r bdac20c6c8dd make/idea/template/vcs.xml
--- a/make/idea/template/vcs.xml Fri Aug 31 09:53:37 2018 -0700
+++ b/make/idea/template/vcs.xml Fri Aug 31 18:01:47 2018 +0100
@@ -1,7 +1,6 @@
-
+
-
diff -r 2ef81feac8b8 -r bdac20c6c8dd make/idea/template/workspace.xml
--- a/make/idea/template/workspace.xml Fri Aug 31 09:53:37 2018 -0700
+++ b/make/idea/template/workspace.xml Fri Aug 31 18:01:47 2018 +0100
@@ -2,7 +2,7 @@
-
+
@@ -11,7 +11,7 @@
-
+
diff -r 2ef81feac8b8 -r bdac20c6c8dd make/langtools/intellij/build.xml
--- a/make/langtools/intellij/build.xml Fri Aug 31 09:53:37 2018 -0700
+++ b/make/langtools/intellij/build.xml Fri Aug 31 18:01:47 2018 +0100
@@ -1,7 +1,7 @@
-
diff -r 2ef81feac8b8 -r bdac20c6c8dd make/langtools/intellij/template/ant.xml
--- a/make/langtools/intellij/template/ant.xml Fri Aug 31 09:53:37 2018 -0700
+++ b/make/langtools/intellij/template/ant.xml Fri Aug 31 18:01:47 2018 +0100
@@ -5,7 +5,6 @@
-
diff -r 2ef81feac8b8 -r bdac20c6c8dd make/langtools/intellij/template/misc.xml
--- a/make/langtools/intellij/template/misc.xml Fri Aug 31 09:53:37 2018 -0700
+++ b/make/langtools/intellij/template/misc.xml Fri Aug 31 18:01:47 2018 +0100
@@ -13,6 +13,6 @@
-
+