Skip to content

Instantly share code, notes, and snippets.

@topolik
Created February 25, 2016 09:01
Show Gist options
  • Save topolik/e749669ad2d4e0c35815 to your computer and use it in GitHub Desktop.
Save topolik/e749669ad2d4e0c35815 to your computer and use it in GitHub Desktop.
Bash script for IntelliJ IDEA setup of Liferay Portal modules
#!/bin/bash
#
# Bash script to create Liferay modules structure in IntelliJ IDEA
#
# The script is provided as-is under GNU GPL v3 license, use at your own risk.
#
# Prerequisites:
# ==============
# 1, There is only one module "portal-master" that references all portal
# sources - portal-impl, portal-service, portal-web, util-*
# 2, The "portal-master" module is saved in portal-master.iml file in
# Liferay portal sources root dir
#
# Usage:
# ======
# 1, Backup your .idea folder and all *.iml files
# 2, Copy script to the root direcotry of liferay-portal sources
# 3, (optional) If you don't want to download dependencies source files,
# update modules/build-module.gradle with:
#
# apply plugin: 'idea'
# idea {
# module {
# downloadSources = false
# }
# }
#
# 4, Generate iml files for modules using gradle:
# cd modules/
# ../gradlew cleanIdea idea
# cd ..
# 5, Run script: ./idea.sh
#
F=".idea/modules.xml"
if [ -e $F ]; then
COUNTER=0
while [ -e "$F.$COUNTER" ]; do
let COUNTER=COUNTER+1
done
echo "File $F already exists, renaming to $F.$COUNTER"
mv $F $F.$COUNTER
fi
touch $F
echo '<project version="4"><component name="ProjectModuleManager"><modules>' > $F
echo '<module fileurl="file://$PROJECT_DIR$/portal-master.iml" filepath="$PROJECT_DIR$/portal-master.iml" />' >> $F
for file in `find modules -name '*.iml'`
do
GROUP=`echo $file | sed 's/modules\/\(.*\)\/[^\/]\+\/[^\/]\+/modules\/\1/'`
echo "<module fileurl=\"file://\$PROJECT_DIR$/$file\" filepath=\"\$PROJECT_DIR$/$file\" group=\"$GROUP\"/>" >> $F
# Add dependency on portal-master sources
grep '<orderEntry type="module" module-name="portal-master" />' $file > /dev/null || sed -i 's/inheritedJdk"/inheritedJdk" \/>\n<orderEntry type="module" module-name="portal-master"/' $file
# remove references to portal-master compiled jars, we need modules to reference real java classes, not gradle cached JARs
sed -i 's/com\/liferay\/portal\/portal-impl/replaced-by-idea-sh-script/gi' $file
sed -i 's/com\/liferay\/portal\/portal-service/replaced-by-idea-sh-script/gi' $file
sed -i 's/com\/liferay\/portal\/util-bridges/replaced-by-idea-sh-script/gi' $file
sed -i 's/com\/liferay\/portal\/util-java/replaced-by-idea-sh-script/gi' $file
sed -i 's/com\/liferay\/portal\/util-taglib/replaced-by-idea-sh-script/gi' $file
done
echo '</modules></component></project>' >> $F
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment