Last active
December 25, 2015 22:39
-
-
Save goldeneggg/7051403 to your computer and use it in GitHub Desktop.
sbtを使用したscalaプロジェクトのスケルトン・ディレクトリ生成スクリプト
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
NAME="" | |
PACKAGE_PATH="" | |
SCALA_VERSION="2.11.0" | |
SCALATEST_VERSION="2.1.3" | |
DIR=`pwd` | |
usage() { | |
cat << __EOT__ | |
Usage: $0 [-p <src package path>] [-v <scala version>] <project name> | |
Generate skelton file of build.sbt | |
Options: | |
-p[=package path] src package path (default: project name) | |
-v[=scala version] scala version (default: ${SCALA_VERSION}) | |
-h print a summary of the options | |
Args: | |
project name *require* project name | |
__EOT__ | |
} | |
while getopts "p:v:h" opt | |
do | |
case $opt in | |
¥?) | |
OPT_ERROR=1 | |
;; | |
p) | |
PACKAGE_PATH=$OPTARG | |
;; | |
v) | |
SCALA_VERSION=$OPTARG | |
;; | |
h) | |
usage | |
exit 0 | |
;; | |
esac | |
done | |
if [ $OPT_ERROR ] | |
then | |
echo "$0: invalid option is assigned" | |
usage | |
exit 1 | |
fi | |
shift $(( $OPTIND - 1 )) | |
ARGS="$@" | |
echo "ARGS count = ${#ARGS[@]}" | |
if [ ${#ARGS[@]} -lt 1 ] | |
then | |
echo "$0: project name is not assigned" | |
usage | |
exit 1 | |
fi | |
NAME=${ARGS[0]} | |
if [ "${NAME}" = "" ] | |
then | |
echo "$0: project name [${NAME}] is invalid" | |
usage | |
exit 1 | |
fi | |
if [ "${PACKAGE_PATH}" = "" ] | |
then | |
PACKAGE_PATH=${NAME} | |
fi | |
if [ -d "${DIR}/${NAME}" ] | |
then | |
echo "$0: directory ${NAME} already exists" | |
usage | |
exit 1 | |
fi | |
mkdir -p ${DIR}/${NAME} | |
cd ${DIR}/${NAME} | |
# generate build.sbt | |
cat << EOF > build.sbt | |
name := "${NAME}" | |
version := "0.1" | |
scalaVersion := "${SCALA_VERSION}" | |
//organization := "me" | |
//retrieveManaged := true | |
//resolvers ++= Seq( | |
// "Sonatype Snapshots" at "http://oss.sonatype.org/content/repositories/snapshots" | |
// ,"Sonatype Releases" at "http://oss.sonatype.org/content/repositories/releases" | |
//) | |
libraryDependencies ++= Seq( | |
"junit" % "junit" % "4.11" % "test" | |
,"org.scalatest" %% "scalatest" % "${SCALATEST_VERSION}" % "test" | |
) | |
EOF | |
# resolvers list | |
# >>>>> | |
#"Sonatype Snapshots" at "http://oss.sonatype.org/content/repositories/snapshots" | |
#"Sonatype Releases" at "http://oss.sonatype.org/content/repositories/releases" | |
#"spray repo" at "http://repo.spray.io/" | |
# <<<<< | |
# librarydependencies list | |
# >>>>> | |
#"org.scalacheck" %% "scalacheck" % "1.11.1" % "test" | |
#"org.specs2" %% "specs2" % "2.3.4" % "test" | |
#"org.testng" % "testng" % "6.8.7" % "test" | |
#"mysql" % "mysql-connector-java" % "5.1.27" | |
#"com.typesafe.akka" %% "akka-actor" % "2.2.1" | |
#"com.github.scala-incubator.io" %% "scala-io-core" % "0.4.2" | |
#"com.github.scala-incubator.io" %% "scala-io-file" % "0.4.2" | |
#"com.fasterxml.jackson.module" %% "jackson-module-scala" % "2.2.3" | |
#"net.databinder.dispatch" %% "dispatch-core" % "0.11.0" | |
#"net.databinder.dispatch" %% "dispatch-jsoup" % "0.11.0" | |
#"org.scala-lang" % "scala-actors" % "${SCALA_VERSION}" | |
# <<<<< | |
# make directory | |
mkdir -p src/{main,test}/scala/${PACKAGE_PATH} | |
mkdir -p src/main/resources | |
mkdir -p lib | |
sbt update | |
sbt reload | |
# generate gitignore | |
cat << EOF > .gitignore | |
target | |
*.swp | |
.gitignore | |
EOF | |
# generate README | |
cat << EOF > README.md | |
# ${NAME} | |
EOF | |
exit 0 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment