PageRenderTime 49ms CodeModel.GetById 21ms RepoModel.GetById 0ms app.codeStats 0ms

/javac/test/tools/apt/Compile/compile.sh

https://bitbucket.org/line47/major-java7
Shell | 533 lines | 450 code | 39 blank | 44 comment | 3 complexity | 1aa904e6edc883cdf6587d4f51ce4b95 MD5 | raw file
Possible License(s): Apache-2.0, GPL-2.0
  1. #!/bin/sh
  2. #
  3. # Copyright (c) 2004, 2009, 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 5033855 4990902 5023880 5043516 5048534 5048535 5041279 5048539 5067261 5068145 5023881 4996963 5095716 6191667 6433634
  26. # @run shell ../verifyVariables.sh
  27. # @build ErrorAPF
  28. # @build WarnAPF
  29. # @build StaticApf
  30. # @build ClassDeclApf
  31. # @build ClassDeclApf2
  32. # @build Rounds
  33. # @build Round1Apf Round2Apf Round3Apf Round4Apf
  34. # @build WrappedStaticApf
  35. # @run shell compile.sh
  36. # @summary Test simple usages of apt, including delegating to javac
  37. # @author Joseph D. Darcy
  38. # If the file *does* exist, exit with an error
  39. TestNoFile() {
  40. if [ -f ${1} ]; then
  41. printf "%s\n" "File ${1} found."
  42. exit 1
  43. fi
  44. }
  45. # If the file does not exist, exit with an error
  46. TestFile() {
  47. if [ ! -f ${1} ]; then
  48. printf "%s\n" "File ${1} not found."
  49. exit 1
  50. fi
  51. }
  52. OS=`uname -s`;
  53. case "${OS}" in
  54. Windows* )
  55. SEP=";"
  56. ;;
  57. CYGWIN* )
  58. DIFFOPTS="--strip-trailing-cr"
  59. SEP=";"
  60. ;;
  61. * )
  62. SEP=":"
  63. ;;
  64. esac
  65. APT="${TESTJAVA}/bin/apt ${TESTTOOLVMOPTS} -XDsuppress-tool-api-removal-message "
  66. JAVA="${TESTJAVA}/bin/java ${TESTVMOPTS} "
  67. JAVAC="${TESTJAVA}/bin/javac ${TESTTOOLVMOPTS} "
  68. unset CLASSPATH
  69. # ---------------------------------------------------------------
  70. echo "Verify that source 1.6 is not supported
  71. rm -f HelloWorld.class
  72. printf "%s\n" "-source 1.6" > options0
  73. printf "%s\n" "${TESTSRC}/HelloWorld.java" >> options0
  74. ${APT} @options0
  75. RESULT=$?
  76. case "$RESULT" in
  77. 0 )
  78. echo "FAILED: accepted source 1.6"
  79. exit 1
  80. ;;
  81. esac
  82. TestNoFile "HelloWorld.class"
  83. # ---------------------------------------------------------------
  84. echo "Verify that target 1.6 is not supported
  85. rm -f HelloWorld.class
  86. printf "%s\n" "-target 1.6" > options00
  87. printf "%s\n" "${TESTSRC}/HelloWorld.java" >> options00
  88. ${APT} @options00
  89. RESULT=$?
  90. case "$RESULT" in
  91. 0 )
  92. echo "FAILED: accepted target 1.6"
  93. exit 1
  94. ;;
  95. esac
  96. TestNoFile "HelloWorld.class"
  97. # ---------------------------------------------------------------
  98. echo "Testing javac pass-through with -A in options file"
  99. rm -f HelloWorld.class
  100. printf "%s\n" "-A" > options1
  101. printf "%s\n" "-d ." >> options1
  102. printf "%s\n" "${TESTSRC}/HelloWorld.java" >> options1
  103. ${APT} @options1
  104. RESULT=$?
  105. case "$RESULT" in
  106. 0 )
  107. ;;
  108. * )
  109. echo "FAILED: javac with -A in options file did not compile"
  110. exit 1
  111. esac
  112. TestFile "HelloWorld.class"
  113. # ---------------------------------------------------------------
  114. echo "Verifying reporting an error will prevent compilation"
  115. rm -f HelloWorld.class
  116. if [ ! -f HelloWorld.java ]; then
  117. cp ${TESTSRC}/HelloWorld.java .
  118. fi
  119. printf "%s\n" "-factory ErrorAPF" > options2
  120. printf "%s\n" "-d ." >> options2
  121. printf "%s\n" "-cp ${TESTCLASSES}" >> options2
  122. printf "%s\n" "HelloWorld.java" >> options2
  123. ${APT} @options2 2> output
  124. TestNoFile "HelloWorld.class"
  125. diff ${DIFFOPTS} output ${TESTSRC}/golden.txt
  126. RESULT=$?
  127. case "$RESULT" in
  128. 0 )
  129. ;;
  130. * )
  131. echo "FAILED: did not record expected error messages"
  132. exit 1
  133. esac
  134. # ---------------------------------------------------------------
  135. echo "Verifying reporting a warning *won't* prevent compilation"
  136. rm -f HelloAnnotation.class
  137. if [ ! -f HelloAnnotation.java ]; then
  138. cp ${TESTSRC}/HelloAnnotation.java .
  139. fi
  140. printf "%s\n" "-factory WarnAPF" > options3
  141. printf "%s\n" "-d ." >> options3
  142. printf "%s\n" "-cp ${TESTCLASSES}" >> options3
  143. printf "%s\n" "HelloAnnotation.java" >> options3
  144. ${APT} @options3 2> output
  145. diff ${DIFFOPTS} output ${TESTSRC}/goldenWarn.txt
  146. RESULT=$?
  147. case "$RESULT" in
  148. 0 )
  149. ;;
  150. * )
  151. echo "FAILED: did not record expected warning messages"
  152. exit 1
  153. esac
  154. TestFile "HelloAnnotation.class"
  155. # ---------------------------------------------------------------
  156. echo "Verifying static state is available across apt rounds; -factory, -cp"
  157. mkdir -p ./src
  158. mkdir -p ./class
  159. rm -Rf ./src/*
  160. rm -Rf ./class/*
  161. printf "%s\n" "-factory StaticApf" > options4
  162. printf "%s\n" "-s ./src" >> options4
  163. printf "%s\n" "-d ./class" >> options4
  164. printf "%s\n" "-cp ${TESTCLASSES}" >> options4
  165. # printf "%s\n" "-XPrintAptRounds" >> options4
  166. ${APT} @options4
  167. TestFile "./class/AndAhTwo.class"
  168. # ---------------------------------------------------------------
  169. echo "Verifying static state is available across apt rounds; -factory, -factorypath"
  170. rm -Rf ./src/*
  171. rm -Rf ./class/*
  172. printf "%s\n" "-factory StaticApf" > options5
  173. printf "%s\n" "-s ./src" >> options5
  174. printf "%s\n" "-d ./class" >> options5
  175. printf "%s\n" "-factorypath ${TESTCLASSES}" >> options5
  176. # printf "%s\n" "-XPrintAptRounds" >> options5
  177. ${APT} @options5
  178. TestFile "./class/AndAhTwo.class"
  179. # -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
  180. # Create jar file for StaticApf
  181. JAR="${TESTJAVA}/bin/jar "
  182. mkdir -p META-INF/services
  183. cp ${TESTSRC}/servicesStaticApf META-INF/services/com.sun.mirror.apt.AnnotationProcessorFactory
  184. cp ${TESTCLASSES}/StaticApf*.class .
  185. ${JAR} cf0 staticApf.jar StaticApf*.class META-INF
  186. # ---------------------------------------------------------------
  187. echo "Verifying static state is available across apt rounds; -cp"
  188. rm -Rf ./src/*
  189. rm -Rf ./class/*
  190. printf "%s\n" "-cp staticApf.jar" > options6
  191. printf "%s\n" "-s ./src" >> options6
  192. printf "%s\n" "-d ./class" >> options6
  193. printf "%s\n" "-XPrintAptRounds" >> options6
  194. ${APT} @options6
  195. TestFile "./class/AndAhTwo.class"
  196. # ---------------------------------------------------------------
  197. echo "Verifying static state is available across apt rounds; -factorypath"
  198. rm -Rf ./src/*
  199. rm -Rf ./class/*
  200. printf "%s\n" "-factorypath staticApf.jar" > options7
  201. printf "%s\n" "-s ./src" >> options7
  202. printf "%s\n" "-d ./class" >> options7
  203. printf "%s\n" "-XPrintAptRounds" >> options7
  204. ${APT} @options7
  205. TestFile "./class/AndAhTwo.class"
  206. # ---------------------------------------------------------------
  207. echo "Verifying -XclassesAsDecls handles class files properly"
  208. rm -Rf ./src/*
  209. rm -Rf ./class/*
  210. mkdir -p ./tmp/classes
  211. ${JAVAC} -d ./tmp/classes ${TESTSRC}/src/Round1Class.java ${TESTSRC}/src/AhOneClass.java ${TESTSRC}/src/AndAhTwoClass.java
  212. RESULT=$?
  213. case "$RESULT" in
  214. 0 )
  215. ;;
  216. * )
  217. echo "FAILED: javac failed to succesfully compile."
  218. exit 1
  219. esac
  220. printf "%s\n" "-factorypath ${TESTCLASSES}" > options7a
  221. printf "%s\n" "-factory ClassDeclApf" >> options7a
  222. printf "%s\n" "-s ./src" >> options7a
  223. printf "%s\n" "-d ./class" >> options7a
  224. printf "%s\n" "-XPrintAptRounds" >> options7a
  225. printf "%s\n" "-XclassesAsDecls" >> options7a
  226. ${APT} @options7a
  227. TestFile "./class/AndAhTwoClass.class"
  228. # ---------------------------------------------------------------
  229. echo "Verifying -XclassesAsDecls works with command-line arguments"
  230. rm -Rf ./src/*
  231. rm -Rf ./class/*
  232. rm -Rf ./tmp/classes
  233. mkdir -p ./tmp/classes
  234. ${JAVAC} -d ./tmp/classes ${TESTSRC}/src/Round1Class.java ${TESTSRC}/src/AndAhTwoClass.java
  235. RESULT=$?
  236. case "$RESULT" in
  237. 0 )
  238. ;;
  239. * )
  240. echo "FAILED: javac failed to succesfully compile."
  241. exit 1
  242. esac
  243. printf "%s\n" "-factorypath ${TESTCLASSES}" > options7b
  244. printf "%s\n" "-factory ClassDeclApf2" >> options7b
  245. printf "%s\n" "-XPrintAptRounds" >> options7b
  246. printf "%s\n" "-XclassesAsDecls" >> options7b
  247. printf "%s\n" "-cp ${TESTCLASSES}" >> options7b
  248. printf "%s\n" "ErrorAPF" >> options7b
  249. printf "%s\n" "WarnAPF" >> options7b
  250. printf "%s\n" "-s ./src" >> options7b
  251. printf "%s\n" "-d ./class" >> options7b
  252. printf "%s\n" "ClassDeclApf" >> options7b
  253. ${APT} @options7b
  254. RESULT=$?
  255. case "$RESULT" in
  256. 0 )
  257. ;;
  258. * )
  259. echo "FAILED: apt exited with an error code."
  260. exit 1
  261. esac
  262. TestFile "./class/AndAhTwoClass.class"
  263. TestFile "./class/AhOne.class"
  264. # ---------------------------------------------------------------
  265. echo "Verifying -XclassesAsDecls works with all source files"
  266. rm -Rf ./src/*
  267. rm -Rf ./class/*
  268. rm -Rf ./tmp/classes
  269. mkdir -p ./tmp/classes
  270. ${JAVAC} -d ./tmp/classes ${TESTSRC}/src/Round1Class.java ${TESTSRC}/src/AndAhTwoClass.java
  271. RESULT=$?
  272. case "$RESULT" in
  273. 0 )
  274. ;;
  275. * )
  276. echo "FAILED: javac failed to succesfully compile."
  277. exit 1
  278. esac
  279. printf "%s\n" "-factorypath ${TESTCLASSES}" > options7c
  280. printf "%s\n" "-factory ClassDeclApf2" >> options7c
  281. printf "%s\n" "-s ./src" >> options7c
  282. printf "%s\n" "-d ./class" >> options7c
  283. printf "%s\n" "-sourcepath ${TESTSRC}" >> options7c
  284. printf "%s\n" "${TESTSRC}/HelloAnnotation.java" >> options7c
  285. printf "%s\n" "${TESTSRC}/HelloWorld.java" >> options7c
  286. printf "%s\n" "${TESTSRC}/Dummy1.java" >> options7c
  287. printf "%s\n" "-XPrintAptRounds" >> options7c
  288. printf "%s\n" "-XclassesAsDecls" >> options7c
  289. printf "%s\n" "-cp ${TESTCLASSES}" >> options7c
  290. ${APT} @options7c
  291. RESULT=$?
  292. case "$RESULT" in
  293. 0 )
  294. ;;
  295. * )
  296. echo "FAILED: apt exited with an error code."
  297. exit 1
  298. esac
  299. TestFile "./class/AndAhTwoClass.class"
  300. TestFile "./class/AhOne.class"
  301. TestFile "./class/HelloWorld.class"
  302. # ---------------------------------------------------------------
  303. echo "Verifying -XclassesAsDecls works with mixed class and source files"
  304. rm -Rf ./src/*
  305. rm -Rf ./class/*
  306. rm -Rf ./tmp/classes
  307. mkdir -p ./tmp/classes
  308. ${JAVAC} -d ./tmp/classes ${TESTSRC}/src/Round1Class.java ${TESTSRC}/src/AndAhTwoClass.java
  309. RESULT=$?
  310. case "$RESULT" in
  311. 0 )
  312. ;;
  313. * )
  314. echo "FAILED: javac failed to succesfully compile."
  315. exit 1
  316. esac
  317. printf "%s\n" "-factorypath ${TESTCLASSES}" > options7d
  318. printf "%s\n" "-factory ClassDeclApf2" >> options7d
  319. printf "%s\n" "-s ./src" >> options7d
  320. printf "%s\n" "-XclassesAsDecls" >> options7d
  321. printf "%s\n" "ClassDeclApf" >> options7d
  322. printf "%s\n" "-d ./class" >> options7d
  323. printf "%s\n" "ErrorAPF" >> options7d
  324. printf "%s\n" "-XPrintAptRounds" >> options7d
  325. printf "%s\n" "${TESTSRC}/HelloWorld.java" >> options7d
  326. printf "%s\n" "-cp ${TESTCLASSES}" >> options7d
  327. ${APT} @options7d
  328. RESULT=$?
  329. case "$RESULT" in
  330. 0 )
  331. ;;
  332. * )
  333. echo "FAILED: apt exited with an error code."
  334. exit 1
  335. esac
  336. TestFile "./class/AndAhTwoClass.class"
  337. TestFile "./class/AhOne.class"
  338. TestFile "./class/HelloWorld.class"
  339. # ---------------------------------------------------------------
  340. echo "Testing productive factories are called on subsequent rounds"
  341. rm -Rf ./src/*
  342. rm -Rf ./class/*
  343. rm -Rf META-INF/services/*
  344. cp ${TESTSRC}/servicesRound1 META-INF/services/com.sun.mirror.apt.AnnotationProcessorFactory
  345. cp ${TESTCLASSES}/Round1Apf*.class .
  346. ${JAR} cf0 round1Apf.jar Round1Apf*.class META-INF
  347. rm -Rf META-INF/services/*
  348. cp ${TESTSRC}/servicesRound2 META-INF/services/com.sun.mirror.apt.AnnotationProcessorFactory
  349. cp ${TESTCLASSES}/Round2Apf*.class .
  350. ${JAR} cf0 round2Apf.jar Round2Apf*.class META-INF
  351. rm -Rf META-INF/services/*
  352. cp ${TESTSRC}/servicesRound3 META-INF/services/com.sun.mirror.apt.AnnotationProcessorFactory
  353. cp ${TESTCLASSES}/Round3Apf*.class .
  354. ${JAR} cf0 round3Apf.jar Round3Apf*.class META-INF
  355. rm -Rf META-INF/services/*
  356. cp ${TESTSRC}/servicesRound4 META-INF/services/com.sun.mirror.apt.AnnotationProcessorFactory
  357. cp ${TESTCLASSES}/Round4Apf*.class .
  358. ${JAR} cf0 round4Apf.jar Round4Apf*.class META-INF
  359. cp ${TESTCLASSES}/Round?.class .
  360. ${JAR} cf0 rounds.jar Round?.class
  361. # cleanup file to prevent accidental discovery in current directory
  362. rm -Rf META-INF/services/*
  363. printf "%s\n" "-factorypath round1Apf.jar${SEP}round2Apf.jar${SEP}round3Apf.jar${SEP}round4Apf.jar" > options8
  364. printf "%s\n" "-classpath rounds.jar" >> options8
  365. printf "%s\n" "-s ./src" >> options8
  366. printf "%s\n" "-d ./class" >> options8
  367. #printf "%s\n" "-XPrintFactoryInfo" >> options8
  368. #printf "%s\n" "-XPrintAptRounds" >> options8
  369. printf "%s\n" "${TESTSRC}/Dummy1.java" >> options8
  370. ${APT} @options8 > multiRoundOutput 2> multiRoundError
  371. diff ${DIFFOPTS} multiRoundOutput ${TESTSRC}/goldenFactory.txt
  372. RESULT=$?
  373. case "$RESULT" in
  374. 0 )
  375. ;;
  376. * )
  377. echo "FAILED: unexpected factory state"
  378. exit 1
  379. esac
  380. TestFile "./class/Dummy5.class"
  381. # ---------------------------------------------------------------
  382. echo "Verifying static state with programmatic apt entry; no factory options"
  383. rm -Rf ./src/*
  384. rm -Rf ./class/*
  385. ${JAVA} -cp ${TESTJAVA}/lib/tools.jar${SEP}${TESTCLASSES} WrappedStaticApf -s ./src -d ./class -XPrintAptRounds
  386. TestFile "./class/AndAhTwo.class"
  387. echo "Verifying static state with programmatic apt entry; -factory"
  388. rm -Rf ./src/*
  389. rm -Rf ./class/*
  390. ${JAVA} -cp ${TESTJAVA}/lib/tools.jar${SEP}${TESTCLASSES} WrappedStaticApf -factory ErrorAPF -s ./src -d ./class -XPrintAptRounds
  391. TestFile "./class/AndAhTwo.class"
  392. echo "Verifying static state with programmatic apt entry; -factorypath"
  393. rm -Rf ./src/*
  394. rm -Rf ./class/*
  395. ${JAVA} -cp ${TESTJAVA}/lib/tools.jar${SEP}${TESTCLASSES} WrappedStaticApf -factorypath round1Apf.jar -s ./src -d ./class -XPrintAptRounds
  396. TestFile "./class/AndAhTwo.class"
  397. echo "Verifying static state with programmatic apt entry; -factory and -factorypath"
  398. rm -Rf ./src/*
  399. rm -Rf ./class/*
  400. ${JAVA} -cp ${TESTJAVA}/lib/tools.jar${SEP}${TESTCLASSES} WrappedStaticApf -factorypath round1Apf.jar -factory Round1Apf -s ./src -d ./class -XPrintAptRounds
  401. TestFile "./class/AndAhTwo.class"
  402. exit 0