8196081: Add support for customized intellij project templates
authormcimadamore
Thu, 25 Jan 2018 12:06:00 +0000
changeset 48667 f2344724a475
parent 48666 d626620a1844
child 48668 2da4a52715d8
8196081: Add support for customized intellij project templates Summary: Override template used for project creation using env variable Reviewed-by: ihse
bin/idea.sh
make/idea/idea.gmk
make/idea/template/ant.xml
make/idea/template/build.xml
make/idea/template/jdk.iml
--- a/bin/idea.sh	Thu Jan 25 16:22:52 2018 +0530
+++ b/bin/idea.sh	Thu Jan 25 12:06:00 2018 +0000
@@ -30,9 +30,10 @@
 }
 
 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 @@
 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 @@
   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 "^ .* <sourceFolder.*####" > /dev/null ; then
@@ -133,9 +147,9 @@
       done
     fi
   else
-    printf "%s\n" "$line" >> $IDEA_IML
+    printf "%s\n" "$line" >> $IDEA_JDK
   fi
-done < "$IML_TEMPLATE"
+done < "$JDK_TEMPLATE"
 
 
 MODULE_NAME="        <property name=\"module.name\" value=\"####\" />"
--- a/make/idea/idea.gmk	Thu Jan 25 16:22:52 2018 +0530
+++ b/make/idea/idea.gmk	Thu Jan 25 12:06:00 2018 +0000
@@ -20,16 +20,9 @@
     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)
--- a/make/idea/template/ant.xml	Thu Jan 25 16:22:52 2018 +0530
+++ b/make/idea/template/ant.xml	Thu Jan 25 12:06:00 2018 +0000
@@ -3,7 +3,6 @@
   <component name="AntConfiguration">
     <buildFile url="file://$PROJECT_DIR$/.idea/build.xml">
       <properties>
-        <property name="boot.java.home" value="$JDKPath$" />
         <property name="intellij.ismake" value="$IsMake$" />
         <property name="build.target.dir" value="specDir" /> <!-- this will be replaced -->
         <property name="module.name" value="java.base" /> <!-- this will be replaced -->
--- a/make/idea/template/build.xml	Thu Jan 25 16:22:52 2018 +0530
+++ b/make/idea/template/build.xml	Thu Jan 25 12:06:00 2018 +0000
@@ -6,32 +6,16 @@
         new JdkLogger(project)
     </script>
 
-     <!-- java.marker is set to a marker file to check for within a Java install dir.
-         The best file to check for across Solaris/Linux/Windows/MacOS is one of the
-         executables; regrettably, that is OS-specific. -->
-    <condition property="java.marker" value="bin/java">
-        <os family="unix"/>
-    </condition>
-    <condition property="java.marker" value="bin/java.exe">
-        <os family="windows"/>
-    </condition>
-
-    <target name="-check-jtreg.home" depends="-def-check">
-        <check name="jtreg" property="jtreg.home" marker="lib/jtreg.jar"/>
-    </target>
-
-    <property name="test.dir" value="${basedir}/jdk/test"/>
-
     <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>
+        <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"/>
@@ -43,71 +27,17 @@
         **** Global JDK Build Targets
     -->
 
-    <target name="clean" depends="-do-configure">
-        <echo message="base = ${basedir}"/>
-        <call-make dir = "${build.target.dir}" args = "clean"/>
-    </target>
-
-    <target name="-do-configure">
+    <target name="clean">
         <echo message="base = ${basedir}"/>
-        <fail message="Not part of a full JDK forest">
-            <condition>
-                <not>
-                    <available file="${basedir}/configure" />
-                </not>
-            </condition>
-        </fail>
-        <exec executable="sh" dir="${basedir}" failonerror="true">
-            <arg line="configure --with-boot-jdk=${boot.java.home}"/>
-        </exec>
+        <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="jimages">
-        <call-make dir = "${build.target.dir}" args = "jimages"/>
-    </target>
-
-    <target name="check-env">
-        <exec executable="env" dir="${basedir}"/>
-    </target>
-
     <target name="build-module">
         <call-make dir = "${build.target.dir}" args = "${module.name}"/>
     </target>
-
-    <target name="-check-boot.java.home" depends="-def-check">
-        <check name="bootstrap java" property="boot.java.home" marker="${java.marker}"/>
-    </target>
-
-    <target name="-def-check">
-        <macrodef name="check">
-            <attribute name="name"/>
-            <attribute name="property"/>
-            <attribute name="marker" default=""/>
-            <sequential>
-                <fail message="Cannot locate @{name}: please set @{property} to its location">
-                    <condition>
-                        <not>
-                            <isset property="@{property}"/>
-                        </not>
-                    </condition>
-                </fail>
-                <fail message="@{name} is not installed in ${@{property}}">
-                    <condition>
-                        <and>
-                            <not>
-                                <equals arg1="@{marker}" arg2=""/>
-                            </not>
-                            <not>
-                                <available file="${@{property}}/@{marker}"/>
-                            </not>
-                        </and>
-                    </condition>
-                </fail>
-            </sequential>
-        </macrodef>
-    </target>
 </project>
--- a/make/idea/template/jdk.iml	Thu Jan 25 16:22:52 2018 +0530
+++ b/make/idea/template/jdk.iml	Thu Jan 25 12:06:00 2018 +0000
@@ -4,11 +4,9 @@
     <exclude-output />
     <content url="file://$MODULE_DIR$">
       <sourceFolder url="file://$MODULE_DIR$/####" isTestSource="false" />
-      <sourceFolder url="file://$MODULE_DIR$/test" isTestSource="true" />
-      <excludeFolder url="file://$MODULE_DIR$/src" />
       <excludeFolder url="file://$MODULE_DIR$/build" />
       <excludeFolder url="file://$MODULE_DIR$/make" />
-    </content>    
+    </content>
     <orderEntry type="sourceFolder" forTests="false" />
     <orderEntry type="inheritedJdk" />
   </component>