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