PageRenderTime 182ms CodeModel.GetById 14ms RepoModel.GetById 0ms app.codeStats 0ms

/bin/csp

https://code.google.com/p/xmeta/
Korn Shell | 171 lines | 115 code | 20 blank | 36 comment | 8 complexity | 94e9b294512da72fdb7f87eb16ff55b2 MD5 | raw file
  1. #!/bin/env ksh
  2. #
  3. # Copyright (C) 2011 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: csp
  19. # AUTHOR: Young, Fey <fey.young@gmail.com>
  20. # DATE: 2011-3-13
  21. #
  22. # PURPOSE: create a scala 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. junit_filename=`junit_filename`
  33. scala_version=latest
  34. init_version=0.1
  35. code_name=
  36. ############################## FUNCTIONS ##################################
  37. function usage {
  38. echo "Usage: csp [options] project_name"
  39. echo "Options:"
  40. echo " -l, select license (gpl3 by default)"
  41. echo " -n code_name, project (code) name"
  42. echo " -p package, package (system username by default)"
  43. echo " -a author, author name (system username by default)"
  44. echo " -e email, email of author"
  45. echo " -u junit ver, version of JUnit (junit 4.8 by default)"
  46. echo " -v version, init ver of the project (0.1 by default)"
  47. echo " -s scala version, version of groovy (latest by default)"
  48. echo " -c compatibility, source compatibility (1.6 by default)"
  49. echo " -h, print this message and exit"
  50. }
  51. ################################# MAIN ####################################
  52. if (( $# == 0 ))
  53. then
  54. usage
  55. exit 1
  56. fi
  57. while getopts "l:n:p:a:e:u:v:s:c:h" arg
  58. do
  59. case $arg in
  60. l)
  61. license=$OPTARG
  62. ;;
  63. n)
  64. code_name=$OPTARG
  65. ;;
  66. p)
  67. package_name=$OPTARG
  68. ;;
  69. a)
  70. author=$OPTARG
  71. ;;
  72. e)
  73. email=$OPTARG
  74. ;;
  75. s)
  76. scala_version=$OPTARG
  77. ;;
  78. u)
  79. junit_filename="junit-$OPTARG.jar"
  80. ;;
  81. m)
  82. main_class=$OPTARG
  83. ;;
  84. v)
  85. init_version=$OPTARG
  86. ;;
  87. c)
  88. source_compatibility=$OPTARG
  89. ;;
  90. h)
  91. usage
  92. exit 0
  93. ;;
  94. *)
  95. usage
  96. exit 1
  97. ;;
  98. esac
  99. done
  100. shift $(($OPTIND - 1))
  101. if [ -z $code_name ]
  102. then
  103. code_name=$1
  104. fi
  105. export source_compatibility project_name code_name license package_name author scala_version junit_filename init_version main_class email
  106. # create default project folder structure
  107. if [ -s $1 ]
  108. then
  109. echo "$1 already exists, please run from a clean directory"
  110. exit 2
  111. fi
  112. mkdir $1
  113. if (( $? != 0 ))
  114. then
  115. echo "cannot create directory '$1', check the file name or permission"
  116. fi
  117. cd $1
  118. pkg_path=`pkg2path $package_name`
  119. for t in main test
  120. do
  121. mkdir -p src/$t/scala/$pkg_path
  122. mkdir -p src/$t/resources
  123. done
  124. # create .xmeta
  125. cat > .xmeta << EOF
  126. project_name=$1
  127. code_name="$code_name"
  128. license=$license
  129. package_name=$package_name
  130. author="$author"
  131. email=$email
  132. scala_version=$scala_version
  133. junit_filename=$junit_filename
  134. source_compatibility=$source_compatibility
  135. init_version=$init_version
  136. EOF
  137. # create build.gradle
  138. gradle_template=scala.lib
  139. cast $XMETA_HOME/templates/$gradle_template --nolicense > build.gradle
  140. # copy library files
  141. mkdir lib
  142. cp $SCALA_HOME/../scala-$scala_version/lib/scala-library.jar lib
  143. cp $SCALA_HOME/../scala-$scala_version/lib/scala-compiler.jar lib
  144. if [ ! -z $common_classpath ]
  145. then
  146. cp $common_classpath/*.jar lib
  147. cp $common_classpath/junit/$junit_filename lib
  148. fi
  149. # attach license
  150. cast $XMETA_HOME/templates/license/$license > LICENSE
  151. # End of script