PageRenderTime 41ms CodeModel.GetById 0ms RepoModel.GetById 0ms app.codeStats 0ms

/bin/cgp

https://code.google.com/p/xmeta/
Korn Shell | 189 lines | 130 code | 22 blank | 37 comment | 10 complexity | aabd981d248a9fd5f0b8b65ed5513569 MD5 | raw file
  1. #!/bin/env ksh
  2. #
  3. # Copyright (C) 2010 Young, Fey <fey.young@gmail.com>
  4. #
  5. # This program is free software: you can redistribute it and/or modify
  6. # it under the terms of the GNU General Public License as published by
  7. # the Free Software Foundation, either version 3 of the License, or
  8. # (at your option) any later version.
  9. #
  10. # This program is distributed in the hope that it will be useful,
  11. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. # GNU General Public License for more details.
  14. #
  15. # You should have received a copy of the GNU General Public License
  16. # along with this program. If not, see <http://www.gnu.org/licenses/>.
  17. #
  18. # SCRIPT: cgp
  19. # AUTHOR: Young, Fey <fey.young@gmail.com>
  20. # DATE: 2010-09-02
  21. #
  22. # PURPOSE: create a groovy project
  23. #
  24. # set -n # Uncomment to check syntax without execution
  25. #
  26. # set -x # Uncomment to debug
  27. #
  28. ########################### FILES AND VARIABLES ##############################
  29. . ~/.xmeta/xmeta.conf
  30. author=$xmeta_user
  31. package_name=$xmeta_user
  32. init_version=0.1
  33. main_class=Main
  34. code_name=
  35. groovy_version=`groovy_version`
  36. junit_filename=`junit_filename`
  37. lib_path='lib'
  38. ################################ FUNCTIONS ###################################
  39. function usage {
  40. echo "Usage: cgp [options] project_name"
  41. echo "Options:"
  42. echo " -l, select license (gpl3 by default)"
  43. echo " -n code_name, project (code) name"
  44. echo " -p package, package (system username by default)"
  45. echo " -a author, author name (system username by default)"
  46. echo " -e email, email of author"
  47. echo " -L/A, create a library or an application (lib by default)"
  48. echo " -m Main-Class Main class name (only for application)"
  49. echo " -u junit ver, version of JUnit (junit 4.8 by default)"
  50. echo " -v version, init version of the project (0.1 by default)"
  51. echo " -g groovy ver, version of groovy (groovy 1.7.3 by default)"
  52. echo " -c compatibility, source compatibility (1.6 by default)"
  53. echo " -h, print this message and exit"
  54. }
  55. ################################### MAIN #####################################
  56. if (( $# == 0 ))
  57. then
  58. usage
  59. exit 1
  60. fi
  61. while getopts "l:n:p:a:e:LAu:m:v:g:c:h" arg
  62. do
  63. case $arg in
  64. l)
  65. license=$OPTARG
  66. ;;
  67. n)
  68. code_name=$OPTARG
  69. ;;
  70. p)
  71. package_name=$OPTARG
  72. ;;
  73. a)
  74. author=$OPTARG
  75. ;;
  76. e)
  77. email=$OPTARG
  78. ;;
  79. L)
  80. project_type=library
  81. ;;
  82. A)
  83. project_type=application
  84. ;;
  85. g)
  86. groovy_version=$OPTARG
  87. ;;
  88. u)
  89. junit_filename="junit-$OPTARG.jar"
  90. ;;
  91. m)
  92. main_class=$OPTARG
  93. ;;
  94. v)
  95. init_version=$OPTARG
  96. ;;
  97. c)
  98. source_compatibility=$OPTARG
  99. ;;
  100. h)
  101. usage
  102. exit 0
  103. ;;
  104. *)
  105. usage
  106. exit 1
  107. ;;
  108. esac
  109. done
  110. shift $(($OPTIND - 1))
  111. if [ -z $code_name ]
  112. then
  113. code_name=$1
  114. fi
  115. export source_compatibility project_name code_name license package_name author project_type groovy_version junit_filename init_version main_class email lib_path
  116. # create default project folder structure
  117. if [ -s $1 ]
  118. then
  119. echo "$1 already exists, please run from a clean directory"
  120. exit 2
  121. fi
  122. mkdir $1
  123. if (( $? != 0 ))
  124. then
  125. echo "cannot create directory '$1', check the file name or permission"
  126. fi
  127. cd $1
  128. pkg_path=`pkg2path $package_name`
  129. for t in main test
  130. do
  131. mkdir -p src/$t/groovy/$pkg_path
  132. mkdir -p src/$t/resources
  133. done
  134. # create .xmeta
  135. cat > .xmeta << EOF
  136. project_name=$1
  137. code_name="$code_name"
  138. license=$license
  139. package_name=$package_name
  140. author="$author"
  141. email=$email
  142. project_type=$project_type
  143. junit_filename=$junit_filename
  144. source_compatibility=$source_compatibility
  145. init_version=$init_version
  146. main_class=$main_class
  147. EOF
  148. # create build.gradle
  149. if [ $project_type = application ]
  150. then
  151. gradle_template=groovy.app
  152. export import_text=
  153. cast $XMETA_HOME/templates/java/main.groovy > src/main/groovy/$pkg_path/$main_class.groovy
  154. else
  155. gradle_template=groovy.lib
  156. fi
  157. cast $XMETA_HOME/templates/$gradle_template --nolicense > build.gradle
  158. # copy library files
  159. mkdir lib
  160. # cp $GROOVY_HOME/../groovy-$groovy_version/embeddable/groovy-all-$groovy_version.jar lib
  161. if [ ! -z $common_classpath ]
  162. then
  163. cp $common_classpath/*.jar lib
  164. fi
  165. # attach license
  166. cast $XMETA_HOME/templates/license/$license > LICENSE
  167. # End of script