2016-05-10 12:34:30 +00:00
|
|
|
#!/bin/sh
|
|
|
|
#
|
2020-02-12 14:38:59 +00:00
|
|
|
# Copyright (c) 2009, 2020, Oracle and/or its affiliates. All rights reserved.
|
2016-05-10 12:34:30 +00:00
|
|
|
# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
|
|
|
#
|
|
|
|
# This code is free software; you can redistribute it and/or modify it
|
|
|
|
# under the terms of the GNU General Public License version 2 only, as
|
|
|
|
# published by the Free Software Foundation.
|
|
|
|
#
|
|
|
|
# This code is distributed in the hope that it will be useful, but WITHOUT
|
|
|
|
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
|
|
|
# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
|
|
|
# version 2 for more details (a copy is included in the LICENSE file that
|
|
|
|
# accompanied this code).
|
|
|
|
#
|
|
|
|
# You should have received a copy of the GNU General Public License version
|
|
|
|
# 2 along with this work; if not, write to the Free Software Foundation,
|
|
|
|
# Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
|
|
|
#
|
|
|
|
# Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
|
|
|
# or visit www.oracle.com if you need additional information or have any
|
|
|
|
# questions.
|
|
|
|
#
|
|
|
|
|
|
|
|
# Shell script for generating an IDEA project from a given list of modules
|
|
|
|
|
|
|
|
usage() {
|
2021-06-08 14:35:58 +00:00
|
|
|
echo "Usage: $0 [-h|--help] [-q|--quiet] [-a|--absolute-paths] [-o|--output <path>] [modules...]"
|
|
|
|
echo " -h | --help"
|
|
|
|
echo " -q | --quiet
|
|
|
|
No stdout output"
|
|
|
|
echo " -a | --absolute-paths
|
|
|
|
Use absolute paths to this jdk, so that generated .idea
|
|
|
|
project files can be moved independently of jdk sources"
|
|
|
|
echo " -o | --output <path>
|
|
|
|
Where .idea directory with project files will be generated
|
|
|
|
(e.g. using '-o .' will place project files in './.idea')
|
|
|
|
Default: $TOPLEVEL_DIR"
|
|
|
|
echo " [modules...]
|
|
|
|
Generate project modules for specific java modules
|
|
|
|
(e.g. 'java.base java.desktop')
|
|
|
|
Default: all existing modules (java.* and jdk.*)"
|
2016-05-10 12:34:30 +00:00
|
|
|
exit 1
|
|
|
|
}
|
|
|
|
|
|
|
|
SCRIPT_DIR=`dirname $0`
|
2018-01-25 12:06:00 +00:00
|
|
|
#assume TOP is the dir from which the script has been called
|
|
|
|
TOP=`pwd`
|
2016-05-10 12:34:30 +00:00
|
|
|
cd $SCRIPT_DIR; SCRIPT_DIR=`pwd`
|
2021-06-08 14:35:58 +00:00
|
|
|
cd .. ; TOPLEVEL_DIR=`pwd`
|
2018-01-25 12:06:00 +00:00
|
|
|
cd $TOP;
|
2016-05-10 12:34:30 +00:00
|
|
|
|
2021-06-08 14:35:58 +00:00
|
|
|
IDEA_OUTPUT=$TOPLEVEL_DIR/.idea
|
|
|
|
VERBOSE=true
|
|
|
|
ABSOLUTE_PATHS=false
|
2016-05-10 12:34:30 +00:00
|
|
|
while [ $# -gt 0 ]
|
|
|
|
do
|
|
|
|
case $1 in
|
|
|
|
-h | --help )
|
|
|
|
usage
|
|
|
|
;;
|
|
|
|
|
2021-06-08 14:35:58 +00:00
|
|
|
-q | --quiet )
|
|
|
|
VERBOSE=false
|
|
|
|
;;
|
|
|
|
|
|
|
|
-a | --absolute-paths )
|
|
|
|
ABSOLUTE_PATHS=true
|
2016-05-10 12:34:30 +00:00
|
|
|
;;
|
|
|
|
|
|
|
|
-o | --output )
|
2018-08-31 17:01:47 +00:00
|
|
|
IDEA_OUTPUT=$2/.idea
|
2016-05-10 12:34:30 +00:00
|
|
|
shift
|
|
|
|
;;
|
|
|
|
|
|
|
|
-*) # bad option
|
|
|
|
usage
|
|
|
|
;;
|
|
|
|
|
|
|
|
* ) # non option
|
|
|
|
break
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
shift
|
|
|
|
done
|
|
|
|
|
2018-08-31 17:01:47 +00:00
|
|
|
mkdir -p $IDEA_OUTPUT || exit 1
|
2016-05-10 12:34:30 +00:00
|
|
|
cd $IDEA_OUTPUT; IDEA_OUTPUT=`pwd`
|
2021-06-08 14:35:58 +00:00
|
|
|
cd ..; IDEA_OUTPUT_PARENT=`pwd`
|
2016-05-10 12:34:30 +00:00
|
|
|
|
2021-06-08 14:35:58 +00:00
|
|
|
MAKE_DIR="$TOPLEVEL_DIR/make"
|
2020-05-19 13:49:46 +00:00
|
|
|
IDEA_MAKE="$MAKE_DIR/ide/idea/jdk"
|
2016-05-10 12:34:30 +00:00
|
|
|
IDEA_TEMPLATE="$IDEA_MAKE/template"
|
2018-01-25 12:06:00 +00:00
|
|
|
|
2021-05-28 19:53:57 +00:00
|
|
|
cp -rn "$IDEA_TEMPLATE"/* "$IDEA_OUTPUT"
|
2018-01-25 12:06:00 +00:00
|
|
|
|
2018-08-31 17:01:47 +00:00
|
|
|
#override template
|
2018-01-25 12:06:00 +00:00
|
|
|
if [ -d "$TEMPLATES_OVERRIDE" ] ; then
|
|
|
|
for file in `ls -p "$TEMPLATES_OVERRIDE" | grep -v /`; do
|
|
|
|
cp "$TEMPLATES_OVERRIDE"/$file "$IDEA_OUTPUT"/
|
|
|
|
done
|
|
|
|
fi
|
2016-05-10 12:34:30 +00:00
|
|
|
|
2021-06-08 14:35:58 +00:00
|
|
|
if [ "$VERBOSE" = true ] ; then
|
|
|
|
echo "Will generate IDEA project files in \"$IDEA_OUTPUT\" for project \"$TOPLEVEL_DIR\""
|
2016-05-10 12:34:30 +00:00
|
|
|
fi
|
|
|
|
|
2021-06-08 14:35:58 +00:00
|
|
|
cd $TOP ; make -f "$IDEA_MAKE/idea.gmk" -I "$TOPLEVEL_DIR" idea \
|
|
|
|
MAKEOVERRIDES= IDEA_OUTPUT_PARENT="$IDEA_OUTPUT_PARENT" OUT="$IDEA_OUTPUT/env.cfg" MODULES="$*" || exit 1
|
2016-05-10 12:34:30 +00:00
|
|
|
cd $SCRIPT_DIR
|
|
|
|
|
|
|
|
. $IDEA_OUTPUT/env.cfg
|
|
|
|
|
2021-06-08 14:35:58 +00:00
|
|
|
# Expect MODULES, MODULE_NAMES, RELATIVE_PROJECT_DIR, RELATIVE_BUILD_DIR to be set
|
2021-05-28 19:53:57 +00:00
|
|
|
if [ "xMODULES" = "x" ] ; then
|
|
|
|
echo "FATAL: MODULES is empty" >&2; exit 1
|
2016-05-10 12:34:30 +00:00
|
|
|
fi
|
|
|
|
|
|
|
|
if [ "x$MODULE_NAMES" = "x" ] ; then
|
|
|
|
echo "FATAL: MODULE_NAMES is empty" >&2; exit 1
|
|
|
|
fi
|
|
|
|
|
2021-06-08 14:35:58 +00:00
|
|
|
if [ "x$RELATIVE_PROJECT_DIR" = "x" ] ; then
|
|
|
|
echo "FATAL: RELATIVE_PROJECT_DIR is empty" >&2; exit 1
|
2016-05-10 12:34:30 +00:00
|
|
|
fi
|
|
|
|
|
2021-06-08 14:35:58 +00:00
|
|
|
if [ "x$RELATIVE_BUILD_DIR" = "x" ] ; then
|
|
|
|
echo "FATAL: RELATIVE_BUILD_DIR is empty" >&2; exit 1
|
2016-05-10 12:34:30 +00:00
|
|
|
fi
|
|
|
|
|
2020-02-12 14:38:59 +00:00
|
|
|
if [ -d "$TOPLEVEL_DIR/.hg" ] ; then
|
|
|
|
VCS_TYPE="hg4idea"
|
|
|
|
fi
|
|
|
|
|
|
|
|
if [ -d "$TOPLEVEL_DIR/.git" ] ; then
|
|
|
|
VCS_TYPE="Git"
|
|
|
|
fi
|
|
|
|
|
2021-06-08 14:35:58 +00:00
|
|
|
if [ "$ABSOLUTE_PATHS" = true ] ; then
|
|
|
|
if [ "x$PATHTOOL" != "x" ]; then
|
|
|
|
PROJECT_DIR="`$PATHTOOL -am $TOPLEVEL_DIR`"
|
|
|
|
else
|
|
|
|
PROJECT_DIR="$TOPLEVEL_DIR"
|
|
|
|
fi
|
|
|
|
MODULE_DIR="$PROJECT_DIR"
|
|
|
|
cd "$TOPLEVEL_DIR" && cd "$RELATIVE_BUILD_DIR" && BUILD_DIR="`pwd`"
|
|
|
|
else
|
|
|
|
if [ "$RELATIVE_PROJECT_DIR" = "." ] ; then
|
|
|
|
PROJECT_DIR=""
|
|
|
|
else
|
|
|
|
PROJECT_DIR="/$RELATIVE_PROJECT_DIR"
|
|
|
|
fi
|
|
|
|
MODULE_DIR="\$MODULE_DIR\$$PROJECT_DIR"
|
|
|
|
PROJECT_DIR="\$PROJECT_DIR\$$PROJECT_DIR"
|
|
|
|
BUILD_DIR="\$PROJECT_DIR\$/$RELATIVE_BUILD_DIR"
|
|
|
|
fi
|
|
|
|
if [ "$VERBOSE" = true ] ; then
|
|
|
|
echo "Project root: $PROJECT_DIR"
|
|
|
|
echo "Generating IDEA project files..."
|
|
|
|
fi
|
|
|
|
|
2018-08-31 17:01:47 +00:00
|
|
|
### Replace template variables
|
2016-05-10 12:34:30 +00:00
|
|
|
|
2018-08-31 17:01:47 +00:00
|
|
|
NUM_REPLACEMENTS=0
|
2016-05-10 12:34:30 +00:00
|
|
|
|
2018-08-31 17:01:47 +00:00
|
|
|
replace_template_file() {
|
|
|
|
for i in $(seq 1 $NUM_REPLACEMENTS); do
|
2018-09-06 12:13:35 +00:00
|
|
|
eval "sed \"s|\${FROM${i}}|\${TO${i}}|g\" $1 > $1.tmp"
|
|
|
|
mv $1.tmp $1
|
2018-08-31 17:01:47 +00:00
|
|
|
done
|
2016-05-10 12:34:30 +00:00
|
|
|
}
|
|
|
|
|
2018-08-31 17:01:47 +00:00
|
|
|
replace_template_dir() {
|
|
|
|
for f in `find $1 -type f` ; do
|
|
|
|
replace_template_file $f
|
|
|
|
done
|
|
|
|
}
|
2017-09-12 17:03:56 +00:00
|
|
|
|
2018-08-31 17:01:47 +00:00
|
|
|
add_replacement() {
|
|
|
|
NUM_REPLACEMENTS=`expr $NUM_REPLACEMENTS + 1`
|
|
|
|
eval FROM$NUM_REPLACEMENTS='$1'
|
|
|
|
eval TO$NUM_REPLACEMENTS='$2'
|
|
|
|
}
|
2017-09-12 17:03:56 +00:00
|
|
|
|
2021-06-08 14:35:58 +00:00
|
|
|
add_replacement "###PROJECT_DIR###" "$PROJECT_DIR"
|
|
|
|
add_replacement "###MODULE_DIR###" "$MODULE_DIR"
|
2018-08-31 17:01:47 +00:00
|
|
|
add_replacement "###MODULE_NAMES###" "$MODULE_NAMES"
|
2020-02-12 14:38:59 +00:00
|
|
|
add_replacement "###VCS_TYPE###" "$VCS_TYPE"
|
2021-06-08 14:35:58 +00:00
|
|
|
add_replacement "###BUILD_DIR###" "$BUILD_DIR"
|
2021-05-28 19:53:57 +00:00
|
|
|
if [ "x$PATHTOOL" != "x" ]; then
|
2021-06-08 14:35:58 +00:00
|
|
|
add_replacement "###BASH_RUNNER_PREFIX###" "\$PROJECT_DIR\$/.idea/bash.bat"
|
2021-05-28 19:53:57 +00:00
|
|
|
else
|
|
|
|
add_replacement "###BASH_RUNNER_PREFIX###" ""
|
|
|
|
fi
|
|
|
|
if [ "x$PATHTOOL" != "x" ]; then
|
2020-08-01 11:25:02 +00:00
|
|
|
if [ "x$JT_HOME" = "x" ]; then
|
|
|
|
add_replacement "###JTREG_HOME###" ""
|
|
|
|
else
|
2021-05-28 19:53:57 +00:00
|
|
|
add_replacement "###JTREG_HOME###" "`$PATHTOOL -am $JT_HOME`"
|
2020-08-01 11:25:02 +00:00
|
|
|
fi
|
|
|
|
else
|
|
|
|
add_replacement "###JTREG_HOME###" "$JT_HOME"
|
2018-11-14 08:19:31 +00:00
|
|
|
fi
|
2017-09-12 17:03:56 +00:00
|
|
|
|
2021-05-28 19:53:57 +00:00
|
|
|
MODULE_IMLS=""
|
|
|
|
TEST_MODULE_DEPENDENCIES=""
|
|
|
|
for module in $MODULE_NAMES; do
|
|
|
|
MODULE_IMLS="$MODULE_IMLS<module fileurl=\"file://\$PROJECT_DIR$/.idea/$module.iml\" filepath=\"\$PROJECT_DIR$/.idea/$module.iml\" /> "
|
|
|
|
TEST_MODULE_DEPENDENCIES="$TEST_MODULE_DEPENDENCIES<orderEntry type=\"module\" module-name=\"$module\" scope=\"TEST\" /> "
|
2018-08-31 17:01:47 +00:00
|
|
|
done
|
2021-05-28 19:53:57 +00:00
|
|
|
add_replacement "###MODULE_IMLS###" "$MODULE_IMLS"
|
|
|
|
add_replacement "###TEST_MODULE_DEPENDENCIES###" "$TEST_MODULE_DEPENDENCIES"
|
2017-09-12 17:03:56 +00:00
|
|
|
|
2018-08-31 17:01:47 +00:00
|
|
|
replace_template_dir "$IDEA_OUTPUT"
|
2017-09-12 17:03:56 +00:00
|
|
|
|
2021-05-28 19:53:57 +00:00
|
|
|
### Generate module project files
|
2016-05-10 12:34:30 +00:00
|
|
|
|
2021-06-08 14:35:58 +00:00
|
|
|
if [ "$VERBOSE" = true ] ; then
|
|
|
|
echo "Generating project modules:"
|
|
|
|
fi
|
2021-05-28 19:53:57 +00:00
|
|
|
(
|
|
|
|
DEFAULT_IFS="$IFS"
|
|
|
|
IFS='#'
|
|
|
|
for value in $MODULES; do
|
|
|
|
(
|
|
|
|
eval "$value"
|
2021-06-08 14:35:58 +00:00
|
|
|
if [ "$VERBOSE" = true ] ; then
|
|
|
|
echo " $module"
|
2021-05-28 19:53:57 +00:00
|
|
|
fi
|
2021-06-08 14:35:58 +00:00
|
|
|
add_replacement "###MODULE_CONTENT###" "src/$module"
|
2021-05-28 19:53:57 +00:00
|
|
|
SOURCE_DIRS=""
|
|
|
|
IFS=' '
|
|
|
|
for dir in $moduleSrcDirs; do
|
|
|
|
case $dir in # Exclude generated sources to avoid module-info conflicts, see https://youtrack.jetbrains.com/issue/IDEA-185108
|
2021-06-08 14:35:58 +00:00
|
|
|
"src/"*) SOURCE_DIRS="$SOURCE_DIRS<sourceFolder url=\"file://$MODULE_DIR/$dir\" isTestSource=\"false\" /> "
|
2021-05-28 19:53:57 +00:00
|
|
|
esac
|
|
|
|
done
|
|
|
|
add_replacement "###SOURCE_DIRS###" "$SOURCE_DIRS"
|
|
|
|
DEPENDENCIES=""
|
|
|
|
for dep in $moduleDependencies; do
|
2021-06-08 14:35:58 +00:00
|
|
|
case $MODULE_NAMES in # Exclude skipped modules from dependencies
|
|
|
|
*"$dep"*) DEPENDENCIES="$DEPENDENCIES<orderEntry type=\"module\" module-name=\"$dep\" /> "
|
|
|
|
esac
|
2021-05-28 19:53:57 +00:00
|
|
|
done
|
|
|
|
add_replacement "###DEPENDENCIES###" "$DEPENDENCIES"
|
|
|
|
cp "$IDEA_OUTPUT/module.iml" "$IDEA_OUTPUT/$module.iml"
|
|
|
|
IFS="$DEFAULT_IFS"
|
|
|
|
replace_template_file "$IDEA_OUTPUT/$module.iml"
|
|
|
|
)
|
|
|
|
done
|
|
|
|
)
|
|
|
|
rm "$IDEA_OUTPUT/module.iml"
|
|
|
|
|
|
|
|
### Create shell script runner for Windows
|
|
|
|
|
|
|
|
if [ "x$PATHTOOL" != "x" ]; then
|
|
|
|
echo "@echo off" > "$IDEA_OUTPUT/bash.bat"
|
|
|
|
if [ "x$WSL_DISTRO_NAME" != "x" ] ; then
|
|
|
|
echo "wsl -d $WSL_DISTRO_NAME --cd \"%cd%\" -e %*" >> "$IDEA_OUTPUT/bash.bat"
|
|
|
|
else
|
|
|
|
echo "$WINENV_ROOT\bin\bash.exe -l -c \"cd %CD:\=/%/ && %*\"" >> "$IDEA_OUTPUT/bash.bat"
|
|
|
|
fi
|
2016-05-10 12:34:30 +00:00
|
|
|
fi
|