Skip to content

Instantly share code, notes, and snippets.

@hattorix
Created March 8, 2012 11:38
Show Gist options
  • Save hattorix/2000618 to your computer and use it in GitHub Desktop.
Save hattorix/2000618 to your computer and use it in GitHub Desktop.
sbt executor
#!/bin/bash
BASEDIR=`dirname $0`
SBT_VERSION=0.11.3
SBT_OPTS=
SBT_ARGS=()
function get-launcher() {
if [[ $# -ne 1 ]]; then
exit 1
fi
local _version=$1
if [[ -f ${BASEDIR}/sbt-launch_${_version}.jar ]]; then
echo "Exists: version ""'"${_version}"'"
return 1
fi
# download
echo ${_version} | grep -E "^0\.(9|10|11)\.[0-9]+$" > /dev/null
if [[ $? -eq 0 ]]; then
# get XSBT
echo ${_version} | grep -E "^0\.(11\.[3-9]|12\.0-.*)$" > /dev/null
if [[ $? -eq 0 ]]; then
curl -o ${BASEDIR}/sbt-launch_${_version}.jar http://typesafe.artifactoryonline.com/typesafe/ivy-releases/org.scala-sbt/sbt-launch/${_version}/sbt-launch.jar
else
curl -o ${BASEDIR}/sbt-launch_${_version}.jar http://typesafe.artifactoryonline.com/typesafe/ivy-releases/org.scala-tools.sbt/sbt-launch/${_version}/sbt-launch.jar
fi
return $?
else
echo ${_version} | grep -E "^0\.7\.[457]$" > /dev/null
if [[ $? -eq 0 ]]; then
# get SBT
curl -o ${BASEDIR}/sbt-launch_${_version}.jar http://simple-build-tool.googlecode.com/files/sbt-launch-${_version}.jar
return $?
fi
fi
return 1
}
function rm-launcher() {
if [[ $# -ne 1 ]]; then
exit 1
fi
rm ${BASEDIR}/sbt-launch_$1.jar > /dev/null 2>&1
}
function list-launcher() {
for fullname in ${BASEDIR}/sbt-launch_*.jar
do
basename ${fullname} | sed -e 's/sbt-launch_\(.*\).jar/\1/'
done
}
function run-sbt() {
if [[ ! -f ${BASEDIR}/sbt-launch_${SBT_VERSION}.jar ]]; then
echo "Not found: version ""'"${SBT_VERSION}"'"
return 1
fi
java ${SBT_OPTS} \
-Xms512M \
-Xmx1536M \
-Xss1M \
-XX:+CMSClassUnloadingEnabled \
-XX:MaxPermSize=384M \
-jar ${BASEDIR}/sbt-launch_${SBT_VERSION}.jar "$@"
}
while [[ $# -gt 0 ]]
do
if [[ $1 == "-nc" ]]; then
SBT_OPTS="-Dsbt.log.noformat=true"
elif [[ $1 == "-use" ]]; then
shift
if [[ $# -gt 0 ]]; then
SBT_VERSION=$1
else
exit 1
fi
elif [[ $1 == "-get" ]]; then
get-launcher $2
if [[ $? -eq 0 ]]; then
echo "OK!!"
else
echo "NG.."
fi
exit
elif [[ $1 == "-rm" ]]; then
rm-launcher $2
exit
elif [[ $1 == "-list" ]]; then
list-launcher
exit
elif [[ $1 == "-version" ]]; then
echo "version: ${SBT_VERSION}"
exit
elif [[ $1 == "-h" ]]; then
echo "Usage: `basename $0` [OPTION]... [TARGET]..."
echo "sbt, a build tool for Scala"
echo
echo "OPTIONS:"
echo " -nc"
echo " -get version"
echo " -rm version"
echo " -list"
echo " -use version"
echo " -version"
echo " -h"
exit
else
if [[ "`echo $1 | cut -c1`" == "-" ]]; then
echo "Unknown option: $1"
echo "Try "'`'`basename $0`" -h' for more information."
exit 1
fi
SBT_ARGS[${#SBT_ARGS[@]}]="$1"
fi
shift
done
run-sbt "${SBT_ARGS[@]}"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment