Skip to content

Instantly share code, notes, and snippets.

@mrdon
Created February 9, 2010 00:01
Show Gist options
  • Save mrdon/298752 to your computer and use it in GitHub Desktop.
Save mrdon/298752 to your computer and use it in GitHub Desktop.
#!/bin/sh
# This script creates a parent pom for all listed modules, allowing you to open them up in IDEA
# in one go and have IDEA automatically link up dependencies
if [ "$1" == "--help" -o $# -lt 2 ]; then
echo "Usage: wksp.sh WORKSPACE_NAME MODULE_NAME..."
echo ""
echo "This command is meant to be ran from the root directory for all projects"
exit 1
fi
base=`pwd`
# Use the _name-workspace pattern to ensure the module is the first one in IDEA
wsName="_$1-workspace"
# Get rid of the workspace name so it isn't mistaken for a module later on
shift
wsDir="$base/.maven-workspace/$wsName"
if [ ! -d $wsDir ];
then
mkdir -p $wsDir
fi
wsPom="$wsDir/pom.xml"
echo "<project" > $wsPom
echo " xmlns=\"http://maven.apache.org/POM/4.0.0\"" >> $wsPom
echo " xlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" " >> $wsPom
echo " xsi:schemaLocation=\"http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd\">" >> $wsPom
echo " " >> $wsPom
echo " <modelVersion>4.0.0</modelVersion>" >> $wsPom
echo " " >> $wsPom
echo " <groupId>maven-workspace</groupId>" >> $wsPom
echo " <artifactId>$wsName</artifactId>" >> $wsPom
echo " <version>1</version>" >> $wsPom
echo " <packaging>pom</packaging>" >> $wsPom
echo " " >> $wsPom
echo " <modules>" >> $wsPom
while [ "$1" ]
do
rawModuleName="$1"
# Strip any trailing /
moduleName=`echo $rawModuleName | sed -e 's/\(.*\)\//\1/'`
echo " <module>../../$moduleName</module>" >> $wsPom
shift
done
echo " </modules>" >> $wsPom
echo "</project>" >> $wsPom
echo "Workspace created at $wsPom"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment