PageRenderTime 53ms CodeModel.GetById 25ms RepoModel.GetById 0ms app.codeStats 0ms

/javac/test/tools/apt/Discovery/discovery.sh

https://bitbucket.org/line47/major-java7
Shell | 410 lines | 224 code | 107 blank | 79 comment | 1 complexity | eccdaab6b58fd1690c0884d9312f951f MD5 | raw file
Possible License(s): Apache-2.0, GPL-2.0
  1. #!/bin/sh
  2. #
  3. # Copyright (c) 1999, 2008, Oracle and/or its affiliates. All rights reserved.
  4. # DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  5. #
  6. # This code is free software; you can redistribute it and/or modify it
  7. # under the terms of the GNU General Public License version 2 only, as
  8. # published by the Free Software Foundation.
  9. #
  10. # This code is distributed in the hope that it will be useful, but WITHOUT
  11. # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  12. # FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
  13. # version 2 for more details (a copy is included in the LICENSE file that
  14. # accompanied this code).
  15. #
  16. # You should have received a copy of the GNU General Public License version
  17. # 2 along with this work; if not, write to the Free Software Foundation,
  18. # Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  19. #
  20. # Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  21. # or visit www.oracle.com if you need additional information or have any
  22. # questions.
  23. #
  24. # @test
  25. # @bug 4984412 4985113 4908512 4990905 4998007 4998218 5002340 5023882 6370261 6363481
  26. # @run shell ../verifyVariables.sh
  27. # @compile PhantomUpdate.java
  28. # @run shell discovery.sh
  29. # @summary Test consistency of annotation discovery
  30. # @author Joseph D. Darcy
  31. # If the file does not exist, exit with an error
  32. TestFile() {
  33. if [ ! -f ${1} ]; then
  34. printf "%s\n" "File ${1} not found."
  35. exit 1
  36. fi
  37. }
  38. OS=`uname -s`;
  39. case "${OS}" in
  40. Windows* | CYGWIN* )
  41. SEP=";"
  42. ;;
  43. * )
  44. SEP=":"
  45. ;;
  46. esac
  47. TOOLSJAR=${TESTJAVA}/lib/tools.jar
  48. OLDCP=${CLASSPATH}
  49. JARCP=tweedle.jar${SEP}touch.jar${SEP}${TOOLSJAR}
  50. SOURCEP=${TESTSRC}
  51. FULLCP=${JARCP}${SEP}${SOURCEP}
  52. BADCP=tweedle.jar${SEP}badTouch.jar${SEP}${TOOLSJAR}
  53. # Construct path to apt executable
  54. APT="${TESTJAVA}/bin/apt ${TESTTOOLVMOPTS} "
  55. # Construct path to apt executable, no compilation
  56. APTNC="${APT} -nocompile "
  57. printf "%s\n" "APT = ${APT}"
  58. # Construct path to javac executable
  59. JAVAC="${TESTJAVA}/bin/javac ${TESTTOOLVMOPTS} -source 1.5 -sourcepath ${TESTSRC} -classpath ${TOOLSJAR} -d . "
  60. JAR="${TESTJAVA}/bin/jar "
  61. $JAVAC ${TESTSRC}/Dee.java ${TESTSRC}/Dum.java ${TESTSRC}/Touch.java ${TESTSRC}/PhantomTouch.java ${TESTSRC}/Empty.java
  62. RESULT=$?
  63. case "${RESULT}" in
  64. 0 )
  65. ;;
  66. * )
  67. echo "Compilation failed."
  68. exit 1
  69. esac
  70. mv Empty.class Empty.clazz
  71. echo "Making services directory and copying services information."
  72. mkdir -p META-INF/services
  73. mkdir -p phantom
  74. rm -f touch.jar
  75. rm -f badTouch.jar
  76. cp ${TESTSRC}/servicesTweedle META-INF/services/com.sun.mirror.apt.AnnotationProcessorFactory
  77. ${JAR} cf0 tweedle.jar Dee*.class Dum*.class META-INF
  78. rm -f META-INF/services/com.sun.mirror.apt.AnnotationProcessorFactory
  79. cp ${TESTSRC}/servicesTouch ./META-INF/services/com.sun.mirror.apt.AnnotationProcessorFactory
  80. ${JAR} cf0 touch.jar Touch*.class META-INF
  81. rm -f META-INF/services/com.sun.mirror.apt.AnnotationProcessorFactory
  82. cp ${TESTSRC}/servicesPhantomTouch ./META-INF/services/com.sun.mirror.apt.AnnotationProcessorFactory
  83. ${JAR} cf0 phantom/phantom.jar PhantomTouch*.class META-INF
  84. # cleanup file to prevent accidental discovery in current directory
  85. rm -f META-INF/services/com.sun.mirror.apt.AnnotationProcessorFactory
  86. # Jar files created; verify right output file is touched
  87. #---------------------------------------------------------
  88. # Test different combinations of classpath, sourcepath, and
  89. # destination directories
  90. #
  91. # Classpath on commandline; no output directories
  92. #
  93. rm -f touched
  94. rm -f HelloWorld.java
  95. rm -f Empty.class
  96. unset CLASSPATH
  97. printf "%s\n" "-classpath ${JARCP}" > options1
  98. printf "%s\n" "-sourcepath ${SOURCEP}" >> options1
  99. printf "%s\n" "${TESTSRC}/Touch.java" >> options1
  100. ${APTNC} @options1
  101. echo "Testing case 1"
  102. TestFile "touched"
  103. TestFile "HelloWorld.java"
  104. TestFile "Empty.class"
  105. #
  106. # Class path set through environment variable
  107. #
  108. rm -f touched
  109. rm -f HelloWorld.java
  110. rm -f Empty.class
  111. unset CLASSPATH
  112. CLASSPATH=${JARCP}
  113. export CLASSPATH
  114. printf "%s\n" "-sourcepath ${SOURCEP}" > options2
  115. printf "%s\n" "${TESTSRC}/Touch.java" >> options2
  116. ${APTNC} @options2
  117. echo "Testing case 2"
  118. TestFile "touched"
  119. TestFile "HelloWorld.java"
  120. TestFile "Empty.class"
  121. #
  122. # No explicit source path
  123. #
  124. rm -f touched
  125. rm -f HelloWorld.java
  126. rm -f Empty.class
  127. unset CLASSPATH
  128. CLASSPATH=${FULLCP}
  129. export CLASSPATH
  130. printf "%s\n" "${TESTSRC}/Touch.java" > options3
  131. ${APTNC} @options3
  132. echo "Testing case 3"
  133. TestFile "touched"
  134. TestFile "HelloWorld.java"
  135. TestFile "Empty.class"
  136. #
  137. # Classpath on commandline; class output directory
  138. #
  139. rm -f touched
  140. rm -f HelloWorld.java
  141. rm -Rf classes/Empty.class
  142. unset CLASSPATH
  143. printf "%s\n" "-classpath ${JARCP}" > options4
  144. printf "%s\n" "-sourcepath ${SOURCEP}" >> options4
  145. printf "%s\n" "-d classes" >> options4
  146. printf "%s\n" "${TESTSRC}/Touch.java" >> options4
  147. ${APTNC} @options4
  148. echo "Testing case 4"
  149. TestFile "touched"
  150. TestFile "HelloWorld.java"
  151. TestFile "classes/Empty.class"
  152. #
  153. # Classpath on commandline; source output directory
  154. #
  155. rm -f touched
  156. rm -Rf src
  157. rm -f Empty.class
  158. unset CLASSPATH
  159. printf "%s\n" "-classpath ${JARCP}" > options5
  160. printf "%s\n" "-sourcepath ${SOURCEP}" >> options5
  161. printf "%s\n" "-s src" >> options5
  162. printf "%s\n" "${TESTSRC}/Touch.java" >> options5
  163. ${APTNC} @options5
  164. echo "Testing case 5"
  165. TestFile "touched"
  166. TestFile "src/HelloWorld.java"
  167. TestFile "Empty.class"
  168. #
  169. # Classpath on commandline; class and source output directory
  170. #
  171. rm -f touched
  172. rm -Rf src
  173. rm -Rf classes
  174. unset CLASSPATH
  175. printf "%s\n" "-classpath ${JARCP}" > options6
  176. printf "%s\n" "-sourcepath ${SOURCEP}" >> options6
  177. printf "%s\n" "-d classes" >> options6
  178. printf "%s\n" "-s src" >> options6
  179. printf "%s\n" "${TESTSRC}/Touch.java" >> options6
  180. ${APTNC} @options6
  181. echo "Testing case 6"
  182. TestFile "touched"
  183. TestFile "src/HelloWorld.java"
  184. TestFile "classes/Empty.class"
  185. #
  186. # Classpath appended to bootclasspath; no output directories
  187. #
  188. rm -f touched
  189. rm -f HelloWorld.java
  190. rm -f Empty.class
  191. unset CLASSPATH
  192. printf "%s\n" "-Xbootclasspath/a:${JARCP}" > options7
  193. printf "%s\n" "-classpath /dev/null" >> options7
  194. printf "%s\n" "${TESTSRC}/Touch.java" >> options7
  195. ${APTNC} @options7
  196. echo "Testing case 7"
  197. TestFile "touched"
  198. TestFile "HelloWorld.java"
  199. TestFile "Empty.class"
  200. #
  201. # Classpath in extdirs; no output directories
  202. #
  203. rm -f touched
  204. rm -f HelloWorld.java
  205. rm -f Empty.class
  206. unset CLASSPATH
  207. printf "%s\n" "-extdirs ." > options8
  208. printf "%s\n" "-classpath ${TOOLSJAR}" >> options8
  209. printf "%s\n" "${TESTSRC}/Touch.java" >> options8
  210. ${APTNC} @options8
  211. echo "Testing case 8"
  212. TestFile "touched"
  213. TestFile "HelloWorld.java"
  214. TestFile "Empty.class"
  215. #
  216. # Classpath in extdirs, take 2; no output directories
  217. #
  218. rm -f touched
  219. rm -f HelloWorld.java
  220. rm -f Empty.class
  221. unset CLASSPATH
  222. printf "%s\n" "-Djava.ext.dirs=." > options9
  223. printf "%s\n" "-classpath ${TOOLSJAR}" >> options9
  224. printf "%s\n" "${TESTSRC}/Touch.java" >> options9
  225. ${APTNC} @options9
  226. echo "Testing case 9"
  227. TestFile "touched"
  228. TestFile "HelloWorld.java"
  229. TestFile "Empty.class"
  230. #
  231. # Classpath in -endorseddirs; no output directories
  232. #
  233. rm -f touched
  234. rm -f HelloWorld.java
  235. rm -f Empty.class
  236. unset CLASSPATH
  237. printf "%s\n" "-endorseddirs ." > options10
  238. printf "%s\n" "-classpath ${TOOLSJAR}" >> options10
  239. printf "%s\n" "${TESTSRC}/Touch.java" >> options10
  240. ${APTNC} @options10
  241. echo "Testing case 10"
  242. TestFile "touched"
  243. TestFile "HelloWorld.java"
  244. TestFile "Empty.class"
  245. #
  246. # Testing apt invocation with no command line options
  247. #
  248. rm -f touched
  249. rm -f HelloWorld.java
  250. rm -f Empty.class
  251. unset CLASSPATH
  252. CLASSPATH=./phantom/phantom.jar
  253. export CLASSPATH
  254. ${APT}
  255. echo "Testing empty command line"
  256. TestFile "touched"
  257. TestFile "HelloWorld.java"
  258. #
  259. # Verify apt and JSR 269 annotation processors can be run from same
  260. # invocation and both use the output directories
  261. #
  262. rm -f touched
  263. rm -f src/HelloWorld.java
  264. rm -f src/GoodbyeWorld.java
  265. rm -f classes/HelloWorld.class
  266. rm -f classes/GoodbyeWorld.class
  267. unset CLASSPATH
  268. printf "%s\n" "-classpath ./phantom/phantom.jar" > options11
  269. printf "%s\n" "-sourcepath ${SOURCEP}" >> options11
  270. printf "%s\n" "-factory PhantomTouch " >> options11
  271. printf "%s\n" "-s src" >> options11
  272. printf "%s\n" "-d classes" >> options11
  273. printf "%s\n" "-A" >> options11
  274. printf "%s\n" "-Afoo" >> options11
  275. printf "%s\n" "-Abar=baz" >> options11
  276. printf "%s\n" "-processorpath $TESTCLASSES" >> options11
  277. printf "%s\n" "-processor PhantomUpdate" >> options11
  278. ${APT} @options11
  279. echo "Testing combined apt and JSR 269 processing"
  280. TestFile touched
  281. TestFile "src/HelloWorld.java"
  282. TestFile "src/GoodbyeWorld.java"
  283. TestFile "classes/HelloWorld.class"
  284. TestFile "classes/GoodbyeWorld.class"
  285. #
  286. # Verify running with badTouch doesn't exit successfully
  287. #
  288. rm -f ./META-INF/services/com.sun.mirror.apt.AnnotationProcessorFactory
  289. cp ${TESTSRC}/servicesBadTouch ./META-INF/services/com.sun.mirror.apt.AnnotationProcessorFactory
  290. ${JAR} cf0 badTouch.jar Touch*.class META-INF
  291. unset CLASSPATH
  292. printf "%s\n" "-classpath ${BADCP}" > optionsBad
  293. printf "%s\n" "-sourcepath ${SOURCEP}" >> optionsBad
  294. printf "%s\n" "${TESTSRC}/Touch.java" >> optionsBad
  295. ${APTNC} @optionsBad 2> /dev/null
  296. RESULT=$?
  297. case "${RESULT}" in
  298. 0 )
  299. echo "Improper exit zero with bad services information."
  300. exit 1
  301. ;;
  302. esac
  303. exit 0;