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() {
|
|
28 |
echo "usage: $0 [-h|--help] [-v|--verbose] [-o|--output <path>] [modules]+"
|
|
29 |
exit 1
|
|
30 |
}
|
|
31 |
|
|
32 |
SCRIPT_DIR=`dirname $0`
|
|
33 |
PWD=`pwd`
|
|
34 |
cd $SCRIPT_DIR; SCRIPT_DIR=`pwd`
|
|
35 |
cd ../../; TOP=`pwd`; cd $PWD
|
|
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"
|
|
73 |
IDEA_IML="$IDEA_OUTPUT/jdk.iml"
|
|
74 |
IDEA_ANT="$IDEA_OUTPUT/ant.xml"
|
|
75 |
|
|
76 |
if [ "$VERBOSE" = "true" ] ; then
|
|
77 |
echo "output dir: $IDEA_OUTPUT"
|
|
78 |
echo "idea template dir: $IDEA_TEMPLATE"
|
|
79 |
fi
|
|
80 |
|
|
81 |
if [ ! -f "$IML_TEMPLATE" ] ; then
|
|
82 |
echo "FATAL: cannot find $IML_TEMPLATE" >&2; exit 1
|
|
83 |
fi
|
|
84 |
|
|
85 |
if [ ! -f "$ANT_TEMPLATE" ] ; then
|
|
86 |
echo "FATAL: cannot find $ANT_TEMPLATE" >&2; exit 1
|
|
87 |
fi
|
|
88 |
|
|
89 |
cp -r "$IDEA_TEMPLATE"/* "$IDEA_OUTPUT"
|
|
90 |
cd $TOP ; make -f "$IDEA_MAKE/idea.gmk" -I make/common idea MAKEOVERRIDES= OUT=$IDEA_OUTPUT/env.cfg MODULES="$*" || exit 1
|
|
91 |
cd $SCRIPT_DIR
|
|
92 |
|
|
93 |
. $IDEA_OUTPUT/env.cfg
|
|
94 |
|
|
95 |
# Expect MODULE_ROOTS, MODULE_NAMES, BOOT_JDK & SPEC to be set
|
|
96 |
if [ "x$MODULE_ROOTS" = "x" ] ; then
|
|
97 |
echo "FATAL: MODULE_ROOTS is empty" >&2; exit 1
|
|
98 |
fi
|
|
99 |
|
|
100 |
if [ "x$MODULE_NAMES" = "x" ] ; then
|
|
101 |
echo "FATAL: MODULE_NAMES is empty" >&2; exit 1
|
|
102 |
fi
|
|
103 |
|
|
104 |
if [ "x$BOOT_JDK" = "x" ] ; then
|
|
105 |
echo "FATAL: BOOT_JDK is empty" >&2; exit 1
|
|
106 |
fi
|
|
107 |
|
|
108 |
if [ "x$SPEC" = "x" ] ; then
|
|
109 |
echo "FATAL: SPEC is empty" >&2; exit 1
|
|
110 |
fi
|
|
111 |
|
|
112 |
SOURCE_FOLDER=" <sourceFolder url=\"file://\$MODULE_DIR\$/####\" isTestSource=\"false\" />"
|
|
113 |
SOURCE_FOLDERS_DONE="false"
|
|
114 |
|
|
115 |
addSourceFolder() {
|
|
116 |
root=$@
|
|
117 |
relativePath="`echo "$root" | sed -e s@"$TOP/\(.*$\)"@"\1"@`"
|
|
118 |
folder="`echo "$SOURCE_FOLDER" | sed -e s@"\(.*/\)####\(.*\)"@"\1$relativePath\2"@`"
|
|
119 |
printf "%s\n" "$folder" >> $IDEA_IML
|
|
120 |
}
|
|
121 |
|
|
122 |
### Generate project iml
|
|
123 |
RELATIVE_BUILD_DIR="`dirname $SPEC | sed -e s@"$TOP/\(.*$\)"@"\1"@`"
|
|
124 |
rm -f $IDEA_IML
|
|
125 |
while IFS= read -r line
|
|
126 |
do
|
|
127 |
if echo "$line" | egrep "^ .* <sourceFolder.*####" > /dev/null ; then
|
|
128 |
if [ "$SOURCE_FOLDERS_DONE" = "false" ] ; then
|
|
129 |
SOURCE_FOLDERS_DONE="true"
|
|
130 |
for root in $MODULE_ROOTS; do
|
|
131 |
addSourceFolder $root
|
|
132 |
done
|
|
133 |
fi
|
|
134 |
elif echo "$line" | egrep "^ .* <excludeFolder.*####" > /dev/null ; then
|
|
135 |
ul="`echo "$line" | sed -e s@"\(.*/\)####\(.*\)"@"\1$RELATIVE_BUILD_DIR\2"@`"
|
|
136 |
printf "%s\n" "$ul" >> $IDEA_IML
|
|
137 |
else
|
|
138 |
printf "%s\n" "$line" >> $IDEA_IML
|
|
139 |
fi
|
|
140 |
done < "$IML_TEMPLATE"
|
|
141 |
|
|
142 |
|
|
143 |
MODULE_NAME=" <property name=\"module.name\" value=\"####\" />"
|
|
144 |
|
|
145 |
addModuleName() {
|
|
146 |
mn="`echo "$MODULE_NAME" | sed -e s@"\(.*\)####\(.*\)"@"\1$MODULE_NAMES\2"@`"
|
|
147 |
printf "%s\n" "$mn" >> $IDEA_ANT
|
|
148 |
}
|
|
149 |
|
|
150 |
BUILD_DIR=" <property name=\"build.target.dir\" value=\"####\" />"
|
|
151 |
|
|
152 |
addBuildDir() {
|
|
153 |
DIR=`dirname $SPEC`
|
|
154 |
mn="`echo "$BUILD_DIR" | sed -e s@"\(.*\)####\(.*\)"@"\1$DIR\2"@`"
|
|
155 |
printf "%s\n" "$mn" >> $IDEA_ANT
|
|
156 |
}
|
|
157 |
|
|
158 |
### Generate ant.xml
|
|
159 |
|
|
160 |
rm -f $IDEA_ANT
|
|
161 |
while IFS= read -r line
|
|
162 |
do
|
|
163 |
if echo "$line" | egrep "^ .* <property name=\"module.name\"" > /dev/null ; then
|
|
164 |
addModuleName
|
|
165 |
elif echo "$line" | egrep "^ .* <property name=\"build.target.dir\"" > /dev/null ; then
|
|
166 |
addBuildDir
|
|
167 |
else
|
|
168 |
printf "%s\n" "$line" >> $IDEA_ANT
|
|
169 |
fi
|
|
170 |
done < "$ANT_TEMPLATE"
|
|
171 |
|
|
172 |
### Compile the custom Logger
|
|
173 |
|
|
174 |
CLASSES=$IDEA_OUTPUT/classes
|
|
175 |
|
|
176 |
if [ "x$ANT_HOME" = "x" ] ; then
|
|
177 |
# try some common locations, before giving up
|
|
178 |
if [ -f "/usr/share/ant/lib/ant.jar" ] ; then
|
|
179 |
ANT_HOME="/usr/share/ant"
|
|
180 |
elif [ -f "/usr/local/Cellar/ant/1.9.4/libexec/lib/ant.jar" ] ; then
|
|
181 |
ANT_HOME="/usr/local/Cellar/ant/1.9.4/libexec"
|
|
182 |
else
|
|
183 |
echo "FATAL: cannot find ant. Try setting ANT_HOME." >&2; exit 1
|
|
184 |
fi
|
|
185 |
fi
|
|
186 |
CP=$ANT_HOME/lib/ant.jar
|
|
187 |
rm -rf $CLASSES; mkdir $CLASSES
|
|
188 |
|
|
189 |
if [ "x$CYGPATH" = "x" ] ; then ## CYGPATH may be set in env.cfg
|
|
190 |
JAVAC_SOURCE_FILE=$IDEA_OUTPUT/src/idea/JdkIdeaAntLogger.java
|
|
191 |
JAVAC_CLASSES=$CLASSES
|
|
192 |
JAVAC_CP=$CP
|
|
193 |
else
|
|
194 |
JAVAC_SOURCE_FILE=`cygpath -am $IDEA_OUTPUT/src/idea/JdkIdeaAntLogger.java`
|
|
195 |
JAVAC_CLASSES=`cygpath -am $CLASSES`
|
|
196 |
JAVAC_CP=`cygpath -am $CP`
|
|
197 |
fi
|
|
198 |
|
|
199 |
$BOOT_JDK/bin/javac -d $JAVAC_CLASSES -cp $JAVAC_CP $JAVAC_SOURCE_FILE
|