/bin/csp
Korn Shell | 171 lines | 115 code | 20 blank | 36 comment | 8 complexity | 94e9b294512da72fdb7f87eb16ff55b2 MD5 | raw file
- #!/bin/env ksh
- #
- # Copyright (C) 2011 Young, Fey <fey.young@gmail.com>
- #
- # This program is free software: you can redistribute it and/or modify
- # it under the terms of the GNU General Public License as published by
- # the Free Software Foundation, either version 3 of the License, or
- # (at your option) any later version.
- #
- # This program is distributed in the hope that it will be useful,
- # but WITHOUT ANY WARRANTY; without even the implied warranty of
- # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- # GNU General Public License for more details.
- #
- # You should have received a copy of the GNU General Public License
- # along with this program. If not, see <http://www.gnu.org/licenses/>.
- #
- # SCRIPT: csp
- # AUTHOR: Young, Fey <fey.young@gmail.com>
- # DATE: 2011-3-13
- #
- # PURPOSE: create a scala project
- #
- # set -n # Uncomment to check syntax without execution
- #
- # set -x # Uncomment to debug
- #
- ######################### FILES AND VARIABLES #############################
- . ~/.xmeta/xmeta.conf
- author=$xmeta_user
- package_name=$xmeta_user
- junit_filename=`junit_filename`
- scala_version=latest
- init_version=0.1
- code_name=
- ############################## FUNCTIONS ##################################
- function usage {
- echo "Usage: csp [options] project_name"
- echo "Options:"
- echo " -l, select license (gpl3 by default)"
- echo " -n code_name, project (code) name"
- echo " -p package, package (system username by default)"
- echo " -a author, author name (system username by default)"
- echo " -e email, email of author"
- echo " -u junit ver, version of JUnit (junit 4.8 by default)"
- echo " -v version, init ver of the project (0.1 by default)"
- echo " -s scala version, version of groovy (latest by default)"
- echo " -c compatibility, source compatibility (1.6 by default)"
- echo " -h, print this message and exit"
- }
- ################################# MAIN ####################################
-
- if (( $# == 0 ))
- then
- usage
- exit 1
- fi
- while getopts "l:n:p:a:e:u:v:s:c:h" arg
- do
- case $arg in
- l)
- license=$OPTARG
- ;;
- n)
- code_name=$OPTARG
- ;;
- p)
- package_name=$OPTARG
- ;;
- a)
- author=$OPTARG
- ;;
- e)
- email=$OPTARG
- ;;
- s)
- scala_version=$OPTARG
- ;;
- u)
- junit_filename="junit-$OPTARG.jar"
- ;;
- m)
- main_class=$OPTARG
- ;;
- v)
- init_version=$OPTARG
- ;;
- c)
- source_compatibility=$OPTARG
- ;;
- h)
- usage
- exit 0
- ;;
- *)
- usage
- exit 1
- ;;
- esac
- done
- shift $(($OPTIND - 1))
- if [ -z $code_name ]
- then
- code_name=$1
- fi
- export source_compatibility project_name code_name license package_name author scala_version junit_filename init_version main_class email
- # create default project folder structure
- if [ -s $1 ]
- then
- echo "$1 already exists, please run from a clean directory"
- exit 2
- fi
- mkdir $1
- if (( $? != 0 ))
- then
- echo "cannot create directory '$1', check the file name or permission"
- fi
- cd $1
- pkg_path=`pkg2path $package_name`
- for t in main test
- do
- mkdir -p src/$t/scala/$pkg_path
- mkdir -p src/$t/resources
- done
- # create .xmeta
- cat > .xmeta << EOF
- project_name=$1
- code_name="$code_name"
- license=$license
- package_name=$package_name
- author="$author"
- email=$email
- scala_version=$scala_version
- junit_filename=$junit_filename
- source_compatibility=$source_compatibility
- init_version=$init_version
- EOF
- # create build.gradle
- gradle_template=scala.lib
- cast $XMETA_HOME/templates/$gradle_template --nolicense > build.gradle
- # copy library files
- mkdir lib
- cp $SCALA_HOME/../scala-$scala_version/lib/scala-library.jar lib
- cp $SCALA_HOME/../scala-$scala_version/lib/scala-compiler.jar lib
- if [ ! -z $common_classpath ]
- then
- cp $common_classpath/*.jar lib
- cp $common_classpath/junit/$junit_filename lib
- fi
- # attach license
- cast $XMETA_HOME/templates/license/$license > LICENSE
- # End of script