blob: 13c474902926fd24ae05544eac541ad3662b856d [file] [log] [blame]
Chris Hegarty47ddb952016-05-10 13:34:30 +01001#!/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
27usage() {
Erik Joelsson72c4ec52017-09-12 19:03:56 +020028 echo "usage: $0 [-h|--help] [-v|--verbose] [-o|--output <path>] [modules]+"
Chris Hegarty47ddb952016-05-10 13:34:30 +010029 exit 1
30}
31
32SCRIPT_DIR=`dirname $0`
33PWD=`pwd`
34cd $SCRIPT_DIR; SCRIPT_DIR=`pwd`
Erik Joelsson72c4ec52017-09-12 19:03:56 +020035cd ../; TOP=`pwd`; cd $PWD
Chris Hegarty47ddb952016-05-10 13:34:30 +010036
37IDEA_OUTPUT=$TOP/.idea
38VERBOSE="false"
39while [ $# -gt 0 ]
40do
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
64done
65
66mkdir $IDEA_OUTPUT || exit 1
67cd $IDEA_OUTPUT; IDEA_OUTPUT=`pwd`
68
69IDEA_MAKE="$TOP/make/idea"
70IDEA_TEMPLATE="$IDEA_MAKE/template"
71IML_TEMPLATE="$IDEA_TEMPLATE/jdk.iml"
72ANT_TEMPLATE="$IDEA_TEMPLATE/ant.xml"
Erik Joelsson72c4ec52017-09-12 19:03:56 +020073MISC_TEMPLATE="$IDEA_TEMPLATE/misc.xml"
Chris Hegarty47ddb952016-05-10 13:34:30 +010074IDEA_IML="$IDEA_OUTPUT/jdk.iml"
75IDEA_ANT="$IDEA_OUTPUT/ant.xml"
Erik Joelsson72c4ec52017-09-12 19:03:56 +020076IDEA_MISC="$IDEA_OUTPUT/misc.xml"
Chris Hegarty47ddb952016-05-10 13:34:30 +010077
78if [ "$VERBOSE" = "true" ] ; then
79 echo "output dir: $IDEA_OUTPUT"
80 echo "idea template dir: $IDEA_TEMPLATE"
81fi
82
83if [ ! -f "$IML_TEMPLATE" ] ; then
84 echo "FATAL: cannot find $IML_TEMPLATE" >&2; exit 1
85fi
86
87if [ ! -f "$ANT_TEMPLATE" ] ; then
88 echo "FATAL: cannot find $ANT_TEMPLATE" >&2; exit 1
89fi
90
91cp -r "$IDEA_TEMPLATE"/* "$IDEA_OUTPUT"
92cd $TOP ; make -f "$IDEA_MAKE/idea.gmk" -I make/common idea MAKEOVERRIDES= OUT=$IDEA_OUTPUT/env.cfg MODULES="$*" || exit 1
93cd $SCRIPT_DIR
94
95. $IDEA_OUTPUT/env.cfg
96
97# Expect MODULE_ROOTS, MODULE_NAMES, BOOT_JDK & SPEC to be set
98if [ "x$MODULE_ROOTS" = "x" ] ; then
99 echo "FATAL: MODULE_ROOTS is empty" >&2; exit 1
100fi
101
102if [ "x$MODULE_NAMES" = "x" ] ; then
103 echo "FATAL: MODULE_NAMES is empty" >&2; exit 1
104fi
105
106if [ "x$BOOT_JDK" = "x" ] ; then
107 echo "FATAL: BOOT_JDK is empty" >&2; exit 1
108fi
109
110if [ "x$SPEC" = "x" ] ; then
111 echo "FATAL: SPEC is empty" >&2; exit 1
112fi
113
114SOURCE_FOLDER=" <sourceFolder url=\"file://\$MODULE_DIR\$/####\" isTestSource=\"false\" />"
115SOURCE_FOLDERS_DONE="false"
116
117addSourceFolder() {
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
Chris Hegarty47ddb952016-05-10 13:34:30 +0100125rm -f $IDEA_IML
126while IFS= read -r line
127do
128 if echo "$line" | egrep "^ .* <sourceFolder.*####" > /dev/null ; then
Erik Joelsson72c4ec52017-09-12 19:03:56 +0200129 if [ "$SOURCE_FOLDERS_DONE" = "false" ] ; then
Chris Hegarty47ddb952016-05-10 13:34:30 +0100130 SOURCE_FOLDERS_DONE="true"
131 for root in $MODULE_ROOTS; do
132 addSourceFolder $root
133 done
134 fi
Chris Hegarty47ddb952016-05-10 13:34:30 +0100135 else
136 printf "%s\n" "$line" >> $IDEA_IML
137 fi
138done < "$IML_TEMPLATE"
139
140
141MODULE_NAME=" <property name=\"module.name\" value=\"####\" />"
142
143addModuleName() {
144 mn="`echo "$MODULE_NAME" | sed -e s@"\(.*\)####\(.*\)"@"\1$MODULE_NAMES\2"@`"
145 printf "%s\n" "$mn" >> $IDEA_ANT
146}
147
148BUILD_DIR=" <property name=\"build.target.dir\" value=\"####\" />"
149
150addBuildDir() {
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
158rm -f $IDEA_ANT
159while IFS= read -r line
160do
161 if echo "$line" | egrep "^ .* <property name=\"module.name\"" > /dev/null ; then
162 addModuleName
Chris Hegarty47ddb952016-05-10 13:34:30 +0100163 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
168done < "$ANT_TEMPLATE"
169
Erik Joelsson72c4ec52017-09-12 19:03:56 +0200170### Generate misc.xml
171
172rm -f $IDEA_MISC
173
174JTREG_HOME=" <path>####</path>"
175
176IMAGES_DIR=" <jre alt=\"true\" value=\"####\" />"
177
178addImagesDir() {
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
184addJtregHome() {
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
190rm -f $MISC_ANT
191while IFS= read -r line
192do
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
200done < "$MISC_TEMPLATE"
201
Chris Hegarty47ddb952016-05-10 13:34:30 +0100202### Compile the custom Logger
203
204CLASSES=$IDEA_OUTPUT/classes
205
206if [ "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
215fi
216CP=$ANT_HOME/lib/ant.jar
217rm -rf $CLASSES; mkdir $CLASSES
218
219if [ "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
223else
224 JAVAC_SOURCE_FILE=`cygpath -am $IDEA_OUTPUT/src/idea/JdkIdeaAntLogger.java`
225 JAVAC_CLASSES=`cygpath -am $CLASSES`
226 JAVAC_CP=`cygpath -am $CP`
227fi
228
229$BOOT_JDK/bin/javac -d $JAVAC_CLASSES -cp $JAVAC_CP $JAVAC_SOURCE_FILE