author | rfield |
Fri, 16 Feb 2018 16:18:55 -0800 | |
changeset 49092 | 6dc5e0cdb44c |
parent 48667 | f2344724a475 |
child 51266 | f8696e0ab9b7 |
permissions | -rw-r--r-- |
37861 | 1 |
#!/bin/sh |
2 |
# |
|
3 |
# Copyright (c) 2009, 2014, Oracle and/or its affiliates. All rights reserved. |
|
4 |
# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
|
5 |
# |
|
6 |
# This code is free software; you can redistribute it and/or modify it |
|
7 |
# under the terms of the GNU General Public License version 2 only, as |
|
8 |
# published by the Free Software Foundation. |
|
9 |
# |
|
10 |
# This code is distributed in the hope that it will be useful, but WITHOUT |
|
11 |
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
|
12 |
# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
|
13 |
# version 2 for more details (a copy is included in the LICENSE file that |
|
14 |
# accompanied this code). |
|
15 |
# |
|
16 |
# You should have received a copy of the GNU General Public License version |
|
17 |
# 2 along with this work; if not, write to the Free Software Foundation, |
|
18 |
# Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
|
19 |
# |
|
20 |
# Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
|
21 |
# or visit www.oracle.com if you need additional information or have any |
|
22 |
# questions. |
|
23 |
# |
|
24 |
||
25 |
# Shell script for generating an IDEA project from a given list of modules |
|
26 |
||
27 |
usage() { |
|
47217 | 28 |
echo "usage: $0 [-h|--help] [-v|--verbose] [-o|--output <path>] [modules]+" |
37861 | 29 |
exit 1 |
30 |
} |
|
31 |
||
32 |
SCRIPT_DIR=`dirname $0` |
|
48667
f2344724a475
8196081: Add support for customized intellij project templates
mcimadamore
parents:
47217
diff
changeset
|
33 |
#assume TOP is the dir from which the script has been called |
f2344724a475
8196081: Add support for customized intellij project templates
mcimadamore
parents:
47217
diff
changeset
|
34 |
TOP=`pwd` |
37861 | 35 |
cd $SCRIPT_DIR; SCRIPT_DIR=`pwd` |
48667
f2344724a475
8196081: Add support for customized intellij project templates
mcimadamore
parents:
47217
diff
changeset
|
36 |
cd $TOP; |
37861 | 37 |
|
38 |
IDEA_OUTPUT=$TOP/.idea |
|
39 |
VERBOSE="false" |
|
40 |
while [ $# -gt 0 ] |
|
41 |
do |
|
42 |
case $1 in |
|
43 |
-h | --help ) |
|
44 |
usage |
|
45 |
;; |
|
46 |
||
47 |
-v | --vebose ) |
|
48 |
VERBOSE="true" |
|
49 |
;; |
|
50 |
||
51 |
-o | --output ) |
|
52 |
IDEA_OUTPUT=$2 |
|
53 |
shift |
|
54 |
;; |
|
55 |
||
56 |
-*) # bad option |
|
57 |
usage |
|
58 |
;; |
|
59 |
||
60 |
* ) # non option |
|
61 |
break |
|
62 |
;; |
|
63 |
esac |
|
64 |
shift |
|
65 |
done |
|
66 |
||
67 |
mkdir $IDEA_OUTPUT || exit 1 |
|
68 |
cd $IDEA_OUTPUT; IDEA_OUTPUT=`pwd` |
|
69 |
||
48667
f2344724a475
8196081: Add support for customized intellij project templates
mcimadamore
parents:
47217
diff
changeset
|
70 |
MAKE_DIR="$SCRIPT_DIR/../make" |
f2344724a475
8196081: Add support for customized intellij project templates
mcimadamore
parents:
47217
diff
changeset
|
71 |
IDEA_MAKE="$MAKE_DIR/idea" |
37861 | 72 |
IDEA_TEMPLATE="$IDEA_MAKE/template" |
48667
f2344724a475
8196081: Add support for customized intellij project templates
mcimadamore
parents:
47217
diff
changeset
|
73 |
|
f2344724a475
8196081: Add support for customized intellij project templates
mcimadamore
parents:
47217
diff
changeset
|
74 |
cp -r "$IDEA_TEMPLATE"/* "$IDEA_OUTPUT" |
f2344724a475
8196081: Add support for customized intellij project templates
mcimadamore
parents:
47217
diff
changeset
|
75 |
|
f2344724a475
8196081: Add support for customized intellij project templates
mcimadamore
parents:
47217
diff
changeset
|
76 |
#init template variables |
f2344724a475
8196081: Add support for customized intellij project templates
mcimadamore
parents:
47217
diff
changeset
|
77 |
for file in `ls -p $IDEA_TEMPLATE | grep -v /`; do |
f2344724a475
8196081: Add support for customized intellij project templates
mcimadamore
parents:
47217
diff
changeset
|
78 |
VAR_SUFFIX=`echo $file | cut -d'.' -f1 | tr [:lower:] [:upper:]` |
f2344724a475
8196081: Add support for customized intellij project templates
mcimadamore
parents:
47217
diff
changeset
|
79 |
eval "$VAR_SUFFIX"_TEMPLATE="$IDEA_TEMPLATE"/$file |
f2344724a475
8196081: Add support for customized intellij project templates
mcimadamore
parents:
47217
diff
changeset
|
80 |
eval IDEA_"$VAR_SUFFIX"="$IDEA_OUTPUT"/$file |
f2344724a475
8196081: Add support for customized intellij project templates
mcimadamore
parents:
47217
diff
changeset
|
81 |
done |
f2344724a475
8196081: Add support for customized intellij project templates
mcimadamore
parents:
47217
diff
changeset
|
82 |
|
f2344724a475
8196081: Add support for customized intellij project templates
mcimadamore
parents:
47217
diff
changeset
|
83 |
#override template variables |
f2344724a475
8196081: Add support for customized intellij project templates
mcimadamore
parents:
47217
diff
changeset
|
84 |
if [ -d "$TEMPLATES_OVERRIDE" ] ; then |
f2344724a475
8196081: Add support for customized intellij project templates
mcimadamore
parents:
47217
diff
changeset
|
85 |
for file in `ls -p "$TEMPLATES_OVERRIDE" | grep -v /`; do |
f2344724a475
8196081: Add support for customized intellij project templates
mcimadamore
parents:
47217
diff
changeset
|
86 |
cp "$TEMPLATES_OVERRIDE"/$file "$IDEA_OUTPUT"/ |
f2344724a475
8196081: Add support for customized intellij project templates
mcimadamore
parents:
47217
diff
changeset
|
87 |
VAR_SUFFIX=`echo $file | cut -d'.' -f1 | tr [:lower:] [:upper:]` |
f2344724a475
8196081: Add support for customized intellij project templates
mcimadamore
parents:
47217
diff
changeset
|
88 |
eval "$VAR_SUFFIX"_TEMPLATE="$TEMPLATES_OVERRIDE"/$file |
f2344724a475
8196081: Add support for customized intellij project templates
mcimadamore
parents:
47217
diff
changeset
|
89 |
done |
f2344724a475
8196081: Add support for customized intellij project templates
mcimadamore
parents:
47217
diff
changeset
|
90 |
fi |
37861 | 91 |
|
92 |
if [ "$VERBOSE" = "true" ] ; then |
|
93 |
echo "output dir: $IDEA_OUTPUT" |
|
94 |
echo "idea template dir: $IDEA_TEMPLATE" |
|
95 |
fi |
|
96 |
||
48667
f2344724a475
8196081: Add support for customized intellij project templates
mcimadamore
parents:
47217
diff
changeset
|
97 |
if [ ! -f "$JDK_TEMPLATE" ] ; then |
f2344724a475
8196081: Add support for customized intellij project templates
mcimadamore
parents:
47217
diff
changeset
|
98 |
echo "FATAL: cannot find $JDK_TEMPLATE" >&2; exit 1 |
37861 | 99 |
fi |
100 |
||
101 |
if [ ! -f "$ANT_TEMPLATE" ] ; then |
|
102 |
echo "FATAL: cannot find $ANT_TEMPLATE" >&2; exit 1 |
|
103 |
fi |
|
104 |
||
48667
f2344724a475
8196081: Add support for customized intellij project templates
mcimadamore
parents:
47217
diff
changeset
|
105 |
cd $TOP ; make -f "$IDEA_MAKE/idea.gmk" -I $MAKE_DIR/.. idea MAKEOVERRIDES= OUT=$IDEA_OUTPUT/env.cfg MODULES="$*" || exit 1 |
37861 | 106 |
cd $SCRIPT_DIR |
107 |
||
108 |
. $IDEA_OUTPUT/env.cfg |
|
109 |
||
110 |
# Expect MODULE_ROOTS, MODULE_NAMES, BOOT_JDK & SPEC to be set |
|
111 |
if [ "x$MODULE_ROOTS" = "x" ] ; then |
|
112 |
echo "FATAL: MODULE_ROOTS is empty" >&2; exit 1 |
|
113 |
fi |
|
114 |
||
115 |
if [ "x$MODULE_NAMES" = "x" ] ; then |
|
116 |
echo "FATAL: MODULE_NAMES is empty" >&2; exit 1 |
|
117 |
fi |
|
118 |
||
119 |
if [ "x$BOOT_JDK" = "x" ] ; then |
|
120 |
echo "FATAL: BOOT_JDK is empty" >&2; exit 1 |
|
121 |
fi |
|
122 |
||
123 |
if [ "x$SPEC" = "x" ] ; then |
|
124 |
echo "FATAL: SPEC is empty" >&2; exit 1 |
|
125 |
fi |
|
126 |
||
127 |
SOURCE_FOLDER=" <sourceFolder url=\"file://\$MODULE_DIR\$/####\" isTestSource=\"false\" />" |
|
128 |
SOURCE_FOLDERS_DONE="false" |
|
129 |
||
130 |
addSourceFolder() { |
|
131 |
root=$@ |
|
132 |
relativePath="`echo "$root" | sed -e s@"$TOP/\(.*$\)"@"\1"@`" |
|
133 |
folder="`echo "$SOURCE_FOLDER" | sed -e s@"\(.*/\)####\(.*\)"@"\1$relativePath\2"@`" |
|
48667
f2344724a475
8196081: Add support for customized intellij project templates
mcimadamore
parents:
47217
diff
changeset
|
134 |
printf "%s\n" "$folder" >> $IDEA_JDK |
37861 | 135 |
} |
136 |
||
137 |
### Generate project iml |
|
48667
f2344724a475
8196081: Add support for customized intellij project templates
mcimadamore
parents:
47217
diff
changeset
|
138 |
|
f2344724a475
8196081: Add support for customized intellij project templates
mcimadamore
parents:
47217
diff
changeset
|
139 |
rm -f $IDEA_JDK |
37861 | 140 |
while IFS= read -r line |
141 |
do |
|
142 |
if echo "$line" | egrep "^ .* <sourceFolder.*####" > /dev/null ; then |
|
47217 | 143 |
if [ "$SOURCE_FOLDERS_DONE" = "false" ] ; then |
37861 | 144 |
SOURCE_FOLDERS_DONE="true" |
145 |
for root in $MODULE_ROOTS; do |
|
146 |
addSourceFolder $root |
|
147 |
done |
|
148 |
fi |
|
149 |
else |
|
48667
f2344724a475
8196081: Add support for customized intellij project templates
mcimadamore
parents:
47217
diff
changeset
|
150 |
printf "%s\n" "$line" >> $IDEA_JDK |
37861 | 151 |
fi |
48667
f2344724a475
8196081: Add support for customized intellij project templates
mcimadamore
parents:
47217
diff
changeset
|
152 |
done < "$JDK_TEMPLATE" |
37861 | 153 |
|
154 |
||
155 |
MODULE_NAME=" <property name=\"module.name\" value=\"####\" />" |
|
156 |
||
157 |
addModuleName() { |
|
158 |
mn="`echo "$MODULE_NAME" | sed -e s@"\(.*\)####\(.*\)"@"\1$MODULE_NAMES\2"@`" |
|
159 |
printf "%s\n" "$mn" >> $IDEA_ANT |
|
160 |
} |
|
161 |
||
162 |
BUILD_DIR=" <property name=\"build.target.dir\" value=\"####\" />" |
|
163 |
||
164 |
addBuildDir() { |
|
165 |
DIR=`dirname $SPEC` |
|
166 |
mn="`echo "$BUILD_DIR" | sed -e s@"\(.*\)####\(.*\)"@"\1$DIR\2"@`" |
|
167 |
printf "%s\n" "$mn" >> $IDEA_ANT |
|
168 |
} |
|
169 |
||
170 |
### Generate ant.xml |
|
171 |
||
172 |
rm -f $IDEA_ANT |
|
173 |
while IFS= read -r line |
|
174 |
do |
|
175 |
if echo "$line" | egrep "^ .* <property name=\"module.name\"" > /dev/null ; then |
|
176 |
addModuleName |
|
177 |
elif echo "$line" | egrep "^ .* <property name=\"build.target.dir\"" > /dev/null ; then |
|
178 |
addBuildDir |
|
179 |
else |
|
180 |
printf "%s\n" "$line" >> $IDEA_ANT |
|
181 |
fi |
|
182 |
done < "$ANT_TEMPLATE" |
|
183 |
||
47217 | 184 |
### Generate misc.xml |
185 |
||
186 |
rm -f $IDEA_MISC |
|
187 |
||
188 |
JTREG_HOME=" <path>####</path>" |
|
189 |
||
190 |
IMAGES_DIR=" <jre alt=\"true\" value=\"####\" />" |
|
191 |
||
192 |
addImagesDir() { |
|
193 |
DIR=`dirname $SPEC`/images/jdk |
|
194 |
mn="`echo "$IMAGES_DIR" | sed -e s@"\(.*\)####\(.*\)"@"\1$DIR\2"@`" |
|
195 |
printf "%s\n" "$mn" >> $IDEA_MISC |
|
196 |
} |
|
197 |
||
198 |
addJtregHome() { |
|
199 |
DIR=`dirname $SPEC` |
|
200 |
mn="`echo "$JTREG_HOME" | sed -e s@"\(.*\)####\(.*\)"@"\1$JT_HOME\2"@`" |
|
201 |
printf "%s\n" "$mn" >> $IDEA_MISC |
|
202 |
} |
|
203 |
||
204 |
rm -f $MISC_ANT |
|
205 |
while IFS= read -r line |
|
206 |
do |
|
207 |
if echo "$line" | egrep "^ .*<path>jtreg_home</path>" > /dev/null ; then |
|
208 |
addJtregHome |
|
209 |
elif echo "$line" | egrep "^ .*<jre alt=\"true\" value=\"images_jdk\"" > /dev/null ; then |
|
210 |
addImagesDir |
|
211 |
else |
|
212 |
printf "%s\n" "$line" >> $IDEA_MISC |
|
213 |
fi |
|
214 |
done < "$MISC_TEMPLATE" |
|
215 |
||
37861 | 216 |
### Compile the custom Logger |
217 |
||
218 |
CLASSES=$IDEA_OUTPUT/classes |
|
219 |
||
220 |
if [ "x$ANT_HOME" = "x" ] ; then |
|
221 |
# try some common locations, before giving up |
|
222 |
if [ -f "/usr/share/ant/lib/ant.jar" ] ; then |
|
223 |
ANT_HOME="/usr/share/ant" |
|
224 |
elif [ -f "/usr/local/Cellar/ant/1.9.4/libexec/lib/ant.jar" ] ; then |
|
225 |
ANT_HOME="/usr/local/Cellar/ant/1.9.4/libexec" |
|
226 |
else |
|
227 |
echo "FATAL: cannot find ant. Try setting ANT_HOME." >&2; exit 1 |
|
228 |
fi |
|
229 |
fi |
|
230 |
CP=$ANT_HOME/lib/ant.jar |
|
231 |
rm -rf $CLASSES; mkdir $CLASSES |
|
232 |
||
233 |
if [ "x$CYGPATH" = "x" ] ; then ## CYGPATH may be set in env.cfg |
|
234 |
JAVAC_SOURCE_FILE=$IDEA_OUTPUT/src/idea/JdkIdeaAntLogger.java |
|
235 |
JAVAC_CLASSES=$CLASSES |
|
236 |
JAVAC_CP=$CP |
|
237 |
else |
|
238 |
JAVAC_SOURCE_FILE=`cygpath -am $IDEA_OUTPUT/src/idea/JdkIdeaAntLogger.java` |
|
239 |
JAVAC_CLASSES=`cygpath -am $CLASSES` |
|
240 |
JAVAC_CP=`cygpath -am $CP` |
|
241 |
fi |
|
242 |
||
243 |
$BOOT_JDK/bin/javac -d $JAVAC_CLASSES -cp $JAVAC_CP $JAVAC_SOURCE_FILE |