From dd61a0c90d6104eba0eecfc2e2f9d16b77da348f Mon Sep 17 00:00:00 2001 From: Maurizio Cimadamore Date: Thu, 25 Jan 2018 12:06:00 +0000 Subject: [PATCH] 8196081: Add support for customized intellij project templates Override template used for project creation using env variable Reviewed-by: ihse --- bin/idea.sh | 48 ++++++++++++------- make/idea/idea.gmk | 9 +--- make/idea/template/ant.xml | 1 - make/idea/template/build.xml | 92 +++++------------------------------- make/idea/template/jdk.iml | 4 +- 5 files changed, 44 insertions(+), 110 deletions(-) diff --git a/bin/idea.sh b/bin/idea.sh index 13c47490292..03b9eee13da 100644 --- a/bin/idea.sh +++ b/bin/idea.sh @@ -30,9 +30,10 @@ usage() { } SCRIPT_DIR=`dirname $0` -PWD=`pwd` +#assume TOP is the dir from which the script has been called +TOP=`pwd` cd $SCRIPT_DIR; SCRIPT_DIR=`pwd` -cd ../; TOP=`pwd`; cd $PWD +cd $TOP; IDEA_OUTPUT=$TOP/.idea VERBOSE="false" @@ -66,30 +67,42 @@ done mkdir $IDEA_OUTPUT || exit 1 cd $IDEA_OUTPUT; IDEA_OUTPUT=`pwd` -IDEA_MAKE="$TOP/make/idea" +MAKE_DIR="$SCRIPT_DIR/../make" +IDEA_MAKE="$MAKE_DIR/idea" IDEA_TEMPLATE="$IDEA_MAKE/template" -IML_TEMPLATE="$IDEA_TEMPLATE/jdk.iml" -ANT_TEMPLATE="$IDEA_TEMPLATE/ant.xml" -MISC_TEMPLATE="$IDEA_TEMPLATE/misc.xml" -IDEA_IML="$IDEA_OUTPUT/jdk.iml" -IDEA_ANT="$IDEA_OUTPUT/ant.xml" -IDEA_MISC="$IDEA_OUTPUT/misc.xml" + +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 +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 if [ "$VERBOSE" = "true" ] ; then echo "output dir: $IDEA_OUTPUT" echo "idea template dir: $IDEA_TEMPLATE" fi -if [ ! -f "$IML_TEMPLATE" ] ; then - echo "FATAL: cannot find $IML_TEMPLATE" >&2; exit 1 +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 -cp -r "$IDEA_TEMPLATE"/* "$IDEA_OUTPUT" -cd $TOP ; make -f "$IDEA_MAKE/idea.gmk" -I make/common idea MAKEOVERRIDES= 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 @@ -118,11 +131,12 @@ addSourceFolder() { root=$@ relativePath="`echo "$root" | sed -e s@"$TOP/\(.*$\)"@"\1"@`" folder="`echo "$SOURCE_FOLDER" | sed -e s@"\(.*/\)####\(.*\)"@"\1$relativePath\2"@`" - printf "%s\n" "$folder" >> $IDEA_IML + printf "%s\n" "$folder" >> $IDEA_JDK } ### Generate project iml -rm -f $IDEA_IML + +rm -f $IDEA_JDK while IFS= read -r line do if echo "$line" | egrep "^ .* /dev/null ; then @@ -133,9 +147,9 @@ do done fi else - printf "%s\n" "$line" >> $IDEA_IML + printf "%s\n" "$line" >> $IDEA_JDK fi -done < "$IML_TEMPLATE" +done < "$JDK_TEMPLATE" MODULE_NAME=" " diff --git a/make/idea/idea.gmk b/make/idea/idea.gmk index 299ffe805bc..8b9d862794b 100644 --- a/make/idea/idea.gmk +++ b/make/idea/idea.gmk @@ -20,16 +20,9 @@ else #with SPEC SEL_MODULES := $(MODULES) endif - # Find all source dirs for a particular module - # $1 - Module to find source dirs for - FindIdeaModuleSrcDirs = \ - $(strip $(addsuffix /$(strip $1), $(GENERATED_SRC_DIRS) $(IMPORT_MODULES_SRC)) \ - $(wildcard $(foreach sub, $(SRC_SUBDIRS), $(addsuffix /$(strip $1)/$(sub), $(TOP_SRC_DIRS))))) - - idea: $(ECHO) "SUPPORT=$(SUPPORT_OUTPUTDIR)" >> $(OUT) - $(ECHO) "MODULE_ROOTS=\"$(foreach mod, $(SEL_MODULES), $(call FindIdeaModuleSrcDirs,$(mod)))\"" >> $(OUT) + $(ECHO) "MODULE_ROOTS=\"$(foreach mod, $(SEL_MODULES), $(call FindModuleSrcDirs,$(mod)))\"" >> $(OUT) $(ECHO) "MODULE_NAMES=\"$(strip $(foreach mod, $(SEL_MODULES), $(mod)))\"" >> $(OUT) $(ECHO) "SEL_MODULES=\"$(SEL_MODULES)\"" >> $(OUT) $(ECHO) "BOOT_JDK=\"$(BOOT_JDK)\"" >> $(OUT) diff --git a/make/idea/template/ant.xml b/make/idea/template/ant.xml index 9e7c19b8c89..74d7c1e34c2 100644 --- a/make/idea/template/ant.xml +++ b/make/idea/template/ant.xml @@ -3,7 +3,6 @@ - diff --git a/make/idea/template/build.xml b/make/idea/template/build.xml index 7f0eff40e3b..a553a940d2b 100644 --- a/make/idea/template/build.xml +++ b/make/idea/template/build.xml @@ -6,32 +6,16 @@ new JdkLogger(project) - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + @@ -43,71 +27,17 @@ **** Global JDK Build Targets --> - + + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/make/idea/template/jdk.iml b/make/idea/template/jdk.iml index 384f7806d3b..c3fb9c6963a 100644 --- a/make/idea/template/jdk.iml +++ b/make/idea/template/jdk.iml @@ -4,11 +4,9 @@ - - - +