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

/bin/cgs

https://code.google.com/p/xmeta/
Korn Shell | 127 lines | 76 code | 17 blank | 34 comment | 12 complexity | 597403b0e785b73f9cbd0536c5f8d145 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: cgs
  19. # AUTHOR: hiarcs <fey.young@gmail.com>
  20. # DATE: 2011-3-13
  21. #
  22. # PURPOSE: create a scala class (TBD: and related junit test)
  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. working_directory=`pwd`
  31. project_directory=
  32. ############################## FUNCTIONS ##################################
  33. function usage {
  34. echo "Usage: cgs classname template"
  35. echo "Exampls:"
  36. echo " cgs com.youngfey.util.Timer class use full class name"
  37. echo " cgs util.Timer class if working directory is src/main/scala/com.youngfey"
  38. exit 1
  39. }
  40. ################################# MAIN ####################################
  41. # make sure you are in a project folder
  42. while [ -z $project_directory ]
  43. do
  44. if [ -s .xmeta ]
  45. then
  46. project_directory=`pwd`
  47. . $project_directory/.xmeta
  48. export author email project_name license code_name
  49. else
  50. cd ..
  51. fi
  52. if [ `pwd` = / ]
  53. then
  54. echo "\"$working_directory\" does not appear to be part of a Xmeta project"
  55. exit 2
  56. fi
  57. done
  58. # check args
  59. if (( $# != 2 ))
  60. then
  61. usage
  62. fi
  63. # file name and package name
  64. class_name=${ basename `pkg2path $1` }
  65. if [ `echo "$working_directory" | grep ^$project_directory/src/main/scala` ]
  66. then
  67. src_pkg_pf=`path2pkg ${working_directory#$project_directory/src/main/scala/}`
  68. if [ `echo $1 | grep '\.'` ]
  69. then
  70. if [ `echo $1 | grep ^$package_name` ]
  71. then
  72. src_package=${1%%.$class_name}
  73. else
  74. src_package=$src_pkg_pf.${1%%.$class_name}
  75. fi
  76. else
  77. src_package=$src_pkg_pf
  78. fi
  79. else
  80. if [ `echo $1 | grep '\.'` ]
  81. then
  82. src_package=${1%%.$class_name}
  83. else
  84. src_package=$package_name
  85. fi
  86. fi
  87. export class_name
  88. src_path=$project_directory/src/main/scala/`pkg2path $src_package`
  89. src_file=$src_path/$class_name.scala
  90. if [ -s $src_file ]
  91. then
  92. echo "file $class_name already existed"
  93. exit 3
  94. fi
  95. mkdir -p $src_path
  96. export package_name=$src_package
  97. export import_text=
  98. cast $XMETA_HOME/templates/scala/$2 > $src_file
  99. if [ `echo $2 | grep ^class` ]
  100. then
  101. test_path=$project_directory/src/test/scala/`pkg2path $src_package`
  102. test_file=$test_path/${class_name}Test.scala
  103. if [ -s $test_file ]
  104. then
  105. echo "Warning: created class $class_name, but test file already exists."
  106. fi
  107. mkdir -p $test_path
  108. cast $XMETA_HOME/templates/scala/junit > $test_file
  109. fi
  110. # End of script