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`
|
|
33 |
PWD=`pwd`
|
|
34 |
cd $SCRIPT_DIR; SCRIPT_DIR=`pwd`
|
47217
|
35 |
cd ../; TOP=`pwd`; cd $PWD
|
37861
|
36 |
|
|
37 |
IDEA_OUTPUT=$TOP/.idea
|
|
38 |
VERBOSE="false"
|
|
39 |
while [ $# -gt 0 ]
|
|
40 |
do
|
|
41 |
case $1 in
|
|
42 |
-h | --help )
|
|
43 |
usage
|
|
44 |
;;
|
|
45 |
|
|
46 |
-v | --vebose )
|
|
47 |
VERBOSE="true"
|
|
48 |
;;
|
|
49 |
|
|
50 |
-o | --output )
|
|
51 |
IDEA_OUTPUT=$2
|
|
52 |
shift
|
|
53 |
;;
|
|
54 |
|
|
55 |
-*) # bad option
|
|
56 |
usage
|
|
57 |
;;
|
|
58 |
|
|
59 |
* ) # non option
|
|
60 |
break
|
|
61 |
;;
|
|
62 |
esac
|
|
63 |
shift
|
|
64 |
done
|
|
65 |
|
|
66 |
mkdir $IDEA_OUTPUT || exit 1
|
|
67 |
cd $IDEA_OUTPUT; IDEA_OUTPUT=`pwd`
|
|
68 |
|
|
69 |
IDEA_MAKE="$TOP/make/idea"
|
|
70 |
IDEA_TEMPLATE="$IDEA_MAKE/template"
|
|
71 |
IML_TEMPLATE="$IDEA_TEMPLATE/jdk.iml"
|
|
72 |
ANT_TEMPLATE="$IDEA_TEMPLATE/ant.xml"
|
47217
|
73 |
MISC_TEMPLATE="$IDEA_TEMPLATE/misc.xml"
|
37861
|
74 |
IDEA_IML="$IDEA_OUTPUT/jdk.iml"
|
|
75 |
IDEA_ANT="$IDEA_OUTPUT/ant.xml"
|
47217
|
76 |
IDEA_MISC="$IDEA_OUTPUT/misc.xml"
|
37861
|
77 |
|
|
78 |
if [ "$VERBOSE" = "true" ] ; then
|
|
79 |
echo "output dir: $IDEA_OUTPUT"
|
|
80 |
echo "idea template dir: $IDEA_TEMPLATE"
|
|
81 |
fi
|
|
82 |
|
|
83 |
if [ ! -f "$IML_TEMPLATE" ] ; then
|
|
84 |
echo "FATAL: cannot find $IML_TEMPLATE" >&2; exit 1
|
|
85 |
fi
|
|
86 |
|
|
87 |
if [ ! -f "$ANT_TEMPLATE" ] ; then
|
|
88 |
echo "FATAL: cannot find $ANT_TEMPLATE" >&2; exit 1
|
|
89 |
fi
|
|
90 |
|
|
91 |
cp -r "$IDEA_TEMPLATE"/* "$IDEA_OUTPUT"
|
|
92 |
cd $TOP ; make -f "$IDEA_MAKE/idea.gmk" -I make/common idea MAKEOVERRIDES= OUT=$IDEA_OUTPUT/env.cfg MODULES="$*" || exit 1
|
|
93 |
cd $SCRIPT_DIR
|
|
94 |
|
|
95 |
. $IDEA_OUTPUT/env.cfg
|
|
96 |
|
|
97 |
# Expect MODULE_ROOTS, MODULE_NAMES, BOOT_JDK & SPEC to be set
|
|
98 |
if [ "x$MODULE_ROOTS" = "x" ] ; then
|
|
99 |
echo "FATAL: MODULE_ROOTS is empty" >&2; exit 1
|
|
100 |
fi
|
|
101 |
|
|
102 |
if [ "x$MODULE_NAMES" = "x" ] ; then
|
|
103 |
echo "FATAL: MODULE_NAMES is empty" >&2; exit 1
|
|
104 |
fi
|
|
105 |
|
|
106 |
if [ "x$BOOT_JDK" = "x" ] ; then
|
|
107 |
echo "FATAL: BOOT_JDK is empty" >&2; exit 1
|
|
108 |
fi
|
|
109 |
|
|
110 |
if [ "x$SPEC" = "x" ] ; then
|
|
111 |
echo "FATAL: SPEC is empty" >&2; exit 1
|
|
112 |
fi
|
|
113 |
|
|
114 |
SOURCE_FOLDER=" <sourceFolder url=\"file://\$MODULE_DIR\$/####\" isTestSource=\"false\" />"
|
|
115 |
SOURCE_FOLDERS_DONE="false"
|
|
116 |
|
|
117 |
addSourceFolder() {
|
|
118 |
root=$@
|
|
119 |
relativePath="`echo "$root" | sed -e s@"$TOP/\(.*$\)"@"\1"@`"
|
|
120 |
folder="`echo "$SOURCE_FOLDER" | sed -e s@"\(.*/\)####\(.*\)"@"\1$relativePath\2"@`"
|
|
121 |
printf "%s\n" "$folder" >> $IDEA_IML
|
|
122 |
}
|
|
123 |
|
|
124 |
### Generate project iml
|
|
125 |
rm -f $IDEA_IML
|
|
126 |
while IFS= read -r line
|
|
127 |
do
|
|
128 |
if echo "$line" | egrep "^ .* <sourceFolder.*####" > /dev/null ; then
|
47217
|
129 |
if [ "$SOURCE_FOLDERS_DONE" = "false" ] ; then
|
37861
|
130 |
SOURCE_FOLDERS_DONE="true"
|
|
131 |
for root in $MODULE_ROOTS; do
|
|
132 |
addSourceFolder $root
|
|
133 |
done
|
|
134 |
fi
|
|
135 |
else
|
|
136 |
printf "%s\n" "$line" >> $IDEA_IML
|
|
137 |
fi
|
|
138 |
done < "$IML_TEMPLATE"
|
|
139 |
|
|
140 |
|
|
141 |
MODULE_NAME=" <property name=\"module.name\" value=\"####\" />"
|
|
142 |
|
|
143 |
addModuleName() {
|
|
144 |
mn="`echo "$MODULE_NAME" | sed -e s@"\(.*\)####\(.*\)"@"\1$MODULE_NAMES\2"@`"
|
|
145 |
printf "%s\n" "$mn" >> $IDEA_ANT
|
|
146 |
}
|
|
147 |
|
|
148 |
BUILD_DIR=" <property name=\"build.target.dir\" value=\"####\" />"
|
|
149 |
|
|
150 |
addBuildDir() {
|
|
151 |
DIR=`dirname $SPEC`
|
|
152 |
mn="`echo "$BUILD_DIR" | sed -e s@"\(.*\)####\(.*\)"@"\1$DIR\2"@`"
|
|
153 |
printf "%s\n" "$mn" >> $IDEA_ANT
|
|
154 |
}
|
|
155 |
|
|
156 |
### Generate ant.xml
|
|
157 |
|
|
158 |
rm -f $IDEA_ANT
|
|
159 |
while IFS= read -r line
|
|
160 |
do
|
|
161 |
if echo "$line" | egrep "^ .* <property name=\"module.name\"" > /dev/null ; then
|
|
162 |
addModuleName
|
|
163 |
elif echo "$line" | egrep "^ .* <property name=\"build.target.dir\"" > /dev/null ; then
|
|
164 |
addBuildDir
|
|
165 |
else
|
|
166 |
printf "%s\n" "$line" >> $IDEA_ANT
|
|
167 |
fi
|
|
168 |
done < "$ANT_TEMPLATE"
|
|
169 |
|
47217
|
170 |
### Generate misc.xml
|
|
171 |
|
|
172 |
rm -f $IDEA_MISC
|
|
173 |
|
|
174 |
JTREG_HOME=" <path>####</path>"
|
|
175 |
|
|
176 |
IMAGES_DIR=" <jre alt=\"true\" value=\"####\" />"
|
|
177 |
|
|
178 |
addImagesDir() {
|
|
179 |
DIR=`dirname $SPEC`/images/jdk
|
|
180 |
mn="`echo "$IMAGES_DIR" | sed -e s@"\(.*\)####\(.*\)"@"\1$DIR\2"@`"
|
|
181 |
printf "%s\n" "$mn" >> $IDEA_MISC
|
|
182 |
}
|
|
183 |
|
|
184 |
addJtregHome() {
|
|
185 |
DIR=`dirname $SPEC`
|
|
186 |
mn="`echo "$JTREG_HOME" | sed -e s@"\(.*\)####\(.*\)"@"\1$JT_HOME\2"@`"
|
|
187 |
printf "%s\n" "$mn" >> $IDEA_MISC
|
|
188 |
}
|
|
189 |
|
|
190 |
rm -f $MISC_ANT
|
|
191 |
while IFS= read -r line
|
|
192 |
do
|
|
193 |
if echo "$line" | egrep "^ .*<path>jtreg_home</path>" > /dev/null ; then
|
|
194 |
addJtregHome
|
|
195 |
elif echo "$line" | egrep "^ .*<jre alt=\"true\" value=\"images_jdk\"" > /dev/null ; then
|
|
196 |
addImagesDir
|
|
197 |
else
|
|
198 |
printf "%s\n" "$line" >> $IDEA_MISC
|
|
199 |
fi
|
|
200 |
done < "$MISC_TEMPLATE"
|
|
201 |
|
37861
|
202 |
### Compile the custom Logger
|
|
203 |
|
|
204 |
CLASSES=$IDEA_OUTPUT/classes
|
|
205 |
|
|
206 |
if [ "x$ANT_HOME" = "x" ] ; then
|
|
207 |
# try some common locations, before giving up
|
|
208 |
if [ -f "/usr/share/ant/lib/ant.jar" ] ; then
|
|
209 |
ANT_HOME="/usr/share/ant"
|
|
210 |
elif [ -f "/usr/local/Cellar/ant/1.9.4/libexec/lib/ant.jar" ] ; then
|
|
211 |
ANT_HOME="/usr/local/Cellar/ant/1.9.4/libexec"
|
|
212 |
else
|
|
213 |
echo "FATAL: cannot find ant. Try setting ANT_HOME." >&2; exit 1
|
|
214 |
fi
|
|
215 |
fi
|
|
216 |
CP=$ANT_HOME/lib/ant.jar
|
|
217 |
rm -rf $CLASSES; mkdir $CLASSES
|
|
218 |
|
|
219 |
if [ "x$CYGPATH" = "x" ] ; then ## CYGPATH may be set in env.cfg
|
|
220 |
JAVAC_SOURCE_FILE=$IDEA_OUTPUT/src/idea/JdkIdeaAntLogger.java
|
|
221 |
JAVAC_CLASSES=$CLASSES
|
|
222 |
JAVAC_CP=$CP
|
|
223 |
else
|
|
224 |
JAVAC_SOURCE_FILE=`cygpath -am $IDEA_OUTPUT/src/idea/JdkIdeaAntLogger.java`
|
|
225 |
JAVAC_CLASSES=`cygpath -am $CLASSES`
|
|
226 |
JAVAC_CP=`cygpath -am $CP`
|
|
227 |
fi
|
|
228 |
|
|
229 |
$BOOT_JDK/bin/javac -d $JAVAC_CLASSES -cp $JAVAC_CP $JAVAC_SOURCE_FILE
|