sbt/bin/sbt-setup

183 lines
3.6 KiB
Plaintext
Raw Normal View History

2011-04-03 03:08:04 +02:00
#!/usr/bin/env bash
#
2011-04-03 03:08:04 +02:00
BINDIR=$(abspath $(dirname "$0"))
. $BINDIR/util.sh
BASE=$(abspath $BINDIR/..)
2011-04-03 03:08:04 +02:00
declare -a args
TEMPLATE="simple"
SCALA_VERSION="2.8.1"
2011-04-03 03:08:04 +02:00
PROJECT_VERSION="0.0.1"
2011-04-03 03:45:23 +02:00
DO_GITHUB=
2011-04-03 03:08:04 +02:00
while [ $# -gt 0 ]; do
case "$1" in
--simple)
TEMPLATE="simple"
shift
;;
--fancy)
TEMPLATE="fancy"
shift
;;
--version)
shift
PROJECT_VERSION="$1"
shift
;;
2011-04-03 03:45:23 +02:00
--github)
shift
DO_GITHUB="true"
;;
2011-04-03 03:08:04 +02:00
--28)
SCALA_VERSION="2.8.1"
shift
;;
--29)
SCALA_VERSION="2.9.0.RC1"
shift
;;
*)
args=("${args[@]}" "$1")
shift
;;
esac
done
# reset "$@" to the remaining args
set -- "${args[@]}"
if [[ $# -ne 1 ]]; then
cat <<EOM
Usage: $(basename $0) [options] <project> [dependencies]
2011-04-03 03:45:23 +02:00
--hub create github project (requires hub and more)
2011-04-03 03:08:04 +02:00
--simple use simple project template
--fancy use multi-file project template
--28 latest release of scala 2.8.x
--29 latest release of scala 2.9.x
--version <version> project initial version
EOM
exit 1
fi
2011-04-03 03:08:04 +02:00
if [ -z "$1" ]; then
echo "Usage: $0 <project name>"
exit 1
fi
2011-04-03 03:08:04 +02:00
PROJECT="$1"
PACKAGE=${ORGANIZATION:-template}
SBT_VERSION="0.7.6.RC0"
DIR=$(echo ${PROJECT} | tr '[A-Z]' '[a-z]')
2011-04-03 03:08:04 +02:00
PROJECT_CC=`camelCase ${PROJECT}`
PROJECT_CLASS=${PROJECT_CC}Project
SPEC_CLASS=${PROJECT_CC}Spec
2011-04-03 03:08:04 +02:00
[[ -e $DIR ]] && { echo "$DIR exists, please remove it first." ; exit 1; }
2011-04-03 03:08:04 +02:00
mkdir -p $DIR
cd $DIR
echo "Creating \"${PACKAGE} % ${PROJECT} % ${PROJECT_VERSION}\" from template \"$TEMPLATE\"."
echo "Building against scala $SCALA_VERSION with sbt $SBT_VERSION."
echo "Repository in ${PWD} ."
echo
2011-04-03 03:08:04 +02:00
for dir in project/build project/plugins src/main/scala src/main/java src/test/scala src/test/java
do
mkdir -p $dir
done
cat > project/build.properties <<EOF
#Project properties
2011-04-03 03:08:04 +02:00
#Generated by sbt-setup on $(date)
project.organization=$PACKAGE
project.name=$PROJECT
sbt.version=$SBT_VERSION
2011-04-03 03:08:04 +02:00
project.version=$PROJECT_VERSION
build.scala.versions=$SCALA_VERSION
project.initialize=false
EOF
cat > src/main/scala/Main.scala <<EOF
package $PACKAGE
object Main {
2011-04-03 03:08:04 +02:00
def main(args: Array[String]): Unit = ()
}
EOF
cat > src/test/scala/${SPEC_CLASS}.scala <<EOF
package $PACKAGE
import org.specs._
class ${SPEC_CLASS} extends Specification {
"A skeletal specification" should {
"do little beyond creating a skeleton" >> {
1 mustEqual 1
}
}
}
EOF
2011-04-03 03:08:04 +02:00
FILE=project/build/${PROJECT_CLASS}.scala
if [[ $TEMPLATE == "fancy" ]]; then
cp $BASE/src/template/Libraries.scala project/build
cp $BASE/src/template/Repositories.scala project/build
cp $BASE/src/template/Plugins.scala project/plugins
cat > $FILE <<EOF
import sbt._
class ${PROJECT_CLASS}(info: ProjectInfo) extends DefaultProject(info) with Libraries {
// ...
}
EOF
else
cat > $FILE <<EOF
import sbt._
class ${PROJECT_CLASS}(info: ProjectInfo) extends DefaultProject(info) with ProjectSupport {
}
EOF
cat $BASE/src/main/resources/support.scala >> $FILE
cp $BASE/src/template/Plugins.scala project/plugins
fi
ln -s $FILE
cat > .gitignore <<EOF
/${PROJECT_CLASS}.scala
target
/project/boot
/project/plugins
lib_managed
src_managed
/ext
EOF
git init
2011-04-03 03:08:04 +02:00
git add .gitignore project src
git add -f project/plugins/Plugins.scala
git commit -m "Initial Import for ${PROJECT_CC} (autogenerated by sbt-setup)."
sbt update package test
2011-04-03 03:45:23 +02:00
if [[ $DO_GITHUB ]]; then
GIT_URL="git@github.com:$(githubUser)/$PROJECT.git"
echo Creating $GIT_URL
hub create
git config --local --add branch.master.remote origin
git config --local --add branch.master.merge refs/heads/master
git push origin master
fi
echo ""
echo "Ready to roll in $PWD"