/bin/cgp
Korn Shell | 189 lines | 130 code | 22 blank | 37 comment | 10 complexity | aabd981d248a9fd5f0b8b65ed5513569 MD5 | raw file
- #!/bin/env ksh
- #
- # Copyright (C) 2010 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: cgp
- # AUTHOR: Young, Fey <fey.young@gmail.com>
- # DATE: 2010-09-02
- #
- # PURPOSE: create a groovy 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
- init_version=0.1
- main_class=Main
- code_name=
- groovy_version=`groovy_version`
- junit_filename=`junit_filename`
- lib_path='lib'
- ################################ FUNCTIONS ###################################
- function usage {
- echo "Usage: cgp [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 " -L/A, create a library or an application (lib by default)"
- echo " -m Main-Class Main class name (only for application)"
- echo " -u junit ver, version of JUnit (junit 4.8 by default)"
- echo " -v version, init version of the project (0.1 by default)"
- echo " -g groovy ver, version of groovy (groovy 1.7.3 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:LAu:m:v:g:c:h" arg
- do
- case $arg in
- l)
- license=$OPTARG
- ;;
- n)
- code_name=$OPTARG
- ;;
- p)
- package_name=$OPTARG
- ;;
- a)
- author=$OPTARG
- ;;
- e)
- email=$OPTARG
- ;;
- L)
- project_type=library
- ;;
- A)
- project_type=application
- ;;
- g)
- groovy_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 project_type groovy_version junit_filename init_version main_class email lib_path
- # 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/groovy/$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
- project_type=$project_type
- junit_filename=$junit_filename
- source_compatibility=$source_compatibility
- init_version=$init_version
- main_class=$main_class
- EOF
- # create build.gradle
- if [ $project_type = application ]
- then
- gradle_template=groovy.app
- export import_text=
- cast $XMETA_HOME/templates/java/main.groovy > src/main/groovy/$pkg_path/$main_class.groovy
- else
- gradle_template=groovy.lib
- fi
- cast $XMETA_HOME/templates/$gradle_template --nolicense > build.gradle
- # copy library files
- mkdir lib
- # cp $GROOVY_HOME/../groovy-$groovy_version/embeddable/groovy-all-$groovy_version.jar lib
- if [ ! -z $common_classpath ]
- then
- cp $common_classpath/*.jar lib
- fi
- # attach license
- cast $XMETA_HOME/templates/license/$license > LICENSE
- # End of script