1 #!/bin/sh |
|
2 |
|
3 # |
|
4 # Copyright (c) 2004, 2009, Oracle and/or its affiliates. All rights reserved. |
|
5 # DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
|
6 # |
|
7 # This code is free software; you can redistribute it and/or modify it |
|
8 # under the terms of the GNU General Public License version 2 only, as |
|
9 # published by the Free Software Foundation. |
|
10 # |
|
11 # This code is distributed in the hope that it will be useful, but WITHOUT |
|
12 # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
|
13 # FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
|
14 # version 2 for more details (a copy is included in the LICENSE file that |
|
15 # accompanied this code). |
|
16 # |
|
17 # You should have received a copy of the GNU General Public License version |
|
18 # 2 along with this work; if not, write to the Free Software Foundation, |
|
19 # Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
|
20 # |
|
21 # Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
|
22 # or visit www.oracle.com if you need additional information or have any |
|
23 # questions. |
|
24 # |
|
25 |
|
26 # @test |
|
27 # @bug 5033855 4990902 5023880 5043516 5048534 5048535 5041279 5048539 5067261 5068145 5023881 4996963 5095716 6191667 6433634 |
|
28 # @run shell ../verifyVariables.sh |
|
29 # @build ErrorAPF |
|
30 # @build WarnAPF |
|
31 # @build StaticApf |
|
32 # @build ClassDeclApf |
|
33 # @build ClassDeclApf2 |
|
34 # @build Rounds |
|
35 # @build Round1Apf Round2Apf Round3Apf Round4Apf |
|
36 # @build WrappedStaticApf |
|
37 # @run shell compile.sh |
|
38 # @summary Test simple usages of apt, including delegating to javac |
|
39 # @author Joseph D. Darcy |
|
40 |
|
41 # If the file *does* exist, exit with an error |
|
42 TestNoFile() { |
|
43 if [ -f ${1} ]; then |
|
44 printf "%s\n" "File ${1} found." |
|
45 exit 1 |
|
46 fi |
|
47 } |
|
48 |
|
49 # If the file does not exist, exit with an error |
|
50 TestFile() { |
|
51 if [ ! -f ${1} ]; then |
|
52 printf "%s\n" "File ${1} not found." |
|
53 exit 1 |
|
54 fi |
|
55 } |
|
56 |
|
57 |
|
58 OS=`uname -s`; |
|
59 case "${OS}" in |
|
60 Windows* ) |
|
61 SEP=";" |
|
62 ;; |
|
63 |
|
64 CYGWIN* ) |
|
65 DIFFOPTS="--strip-trailing-cr" |
|
66 SEP=";" |
|
67 ;; |
|
68 |
|
69 * ) |
|
70 SEP=":" |
|
71 ;; |
|
72 esac |
|
73 |
|
74 |
|
75 APT="${TESTJAVA}/bin/apt ${TESTTOOLVMOPTS} -XDsuppress-tool-api-removal-message " |
|
76 JAVA="${TESTJAVA}/bin/java ${TESTVMOPTS} " |
|
77 JAVAC="${TESTJAVA}/bin/javac ${TESTTOOLVMOPTS} " |
|
78 |
|
79 unset CLASSPATH |
|
80 |
|
81 |
|
82 # --------------------------------------------------------------- |
|
83 echo "Verify that source 1.6 is not supported |
|
84 rm -f HelloWorld.class |
|
85 |
|
86 printf "%s\n" "-source 1.6" > options0 |
|
87 printf "%s\n" "${TESTSRC}/HelloWorld.java" >> options0 |
|
88 ${APT} @options0 |
|
89 |
|
90 RESULT=$? |
|
91 case "$RESULT" in |
|
92 0 ) |
|
93 echo "FAILED: accepted source 1.6" |
|
94 exit 1 |
|
95 ;; |
|
96 esac |
|
97 |
|
98 TestNoFile "HelloWorld.class" |
|
99 |
|
100 # --------------------------------------------------------------- |
|
101 |
|
102 echo "Verify that target 1.6 is not supported |
|
103 rm -f HelloWorld.class |
|
104 |
|
105 printf "%s\n" "-target 1.6" > options00 |
|
106 printf "%s\n" "${TESTSRC}/HelloWorld.java" >> options00 |
|
107 ${APT} @options00 |
|
108 |
|
109 RESULT=$? |
|
110 case "$RESULT" in |
|
111 0 ) |
|
112 echo "FAILED: accepted target 1.6" |
|
113 exit 1 |
|
114 ;; |
|
115 esac |
|
116 |
|
117 TestNoFile "HelloWorld.class" |
|
118 |
|
119 # --------------------------------------------------------------- |
|
120 |
|
121 echo "Testing javac pass-through with -A in options file" |
|
122 rm -f HelloWorld.class |
|
123 |
|
124 printf "%s\n" "-A" > options1 |
|
125 printf "%s\n" "-d ." >> options1 |
|
126 printf "%s\n" "${TESTSRC}/HelloWorld.java" >> options1 |
|
127 ${APT} @options1 |
|
128 |
|
129 RESULT=$? |
|
130 case "$RESULT" in |
|
131 0 ) |
|
132 ;; |
|
133 |
|
134 * ) |
|
135 echo "FAILED: javac with -A in options file did not compile" |
|
136 exit 1 |
|
137 esac |
|
138 TestFile "HelloWorld.class" |
|
139 |
|
140 |
|
141 # --------------------------------------------------------------- |
|
142 |
|
143 echo "Verifying reporting an error will prevent compilation" |
|
144 rm -f HelloWorld.class |
|
145 if [ ! -f HelloWorld.java ]; then |
|
146 cp ${TESTSRC}/HelloWorld.java . |
|
147 fi |
|
148 |
|
149 |
|
150 printf "%s\n" "-factory ErrorAPF" > options2 |
|
151 printf "%s\n" "-d ." >> options2 |
|
152 printf "%s\n" "-cp ${TESTCLASSES}" >> options2 |
|
153 printf "%s\n" "HelloWorld.java" >> options2 |
|
154 ${APT} @options2 2> output |
|
155 |
|
156 TestNoFile "HelloWorld.class" |
|
157 |
|
158 diff ${DIFFOPTS} output ${TESTSRC}/golden.txt |
|
159 |
|
160 RESULT=$? |
|
161 case "$RESULT" in |
|
162 0 ) |
|
163 ;; |
|
164 |
|
165 * ) |
|
166 echo "FAILED: did not record expected error messages" |
|
167 exit 1 |
|
168 esac |
|
169 |
|
170 |
|
171 |
|
172 # --------------------------------------------------------------- |
|
173 |
|
174 echo "Verifying reporting a warning *won't* prevent compilation" |
|
175 |
|
176 rm -f HelloAnnotation.class |
|
177 if [ ! -f HelloAnnotation.java ]; then |
|
178 cp ${TESTSRC}/HelloAnnotation.java . |
|
179 fi |
|
180 |
|
181 |
|
182 printf "%s\n" "-factory WarnAPF" > options3 |
|
183 printf "%s\n" "-d ." >> options3 |
|
184 printf "%s\n" "-cp ${TESTCLASSES}" >> options3 |
|
185 printf "%s\n" "HelloAnnotation.java" >> options3 |
|
186 ${APT} @options3 2> output |
|
187 |
|
188 diff ${DIFFOPTS} output ${TESTSRC}/goldenWarn.txt |
|
189 |
|
190 RESULT=$? |
|
191 case "$RESULT" in |
|
192 0 ) |
|
193 ;; |
|
194 |
|
195 * ) |
|
196 echo "FAILED: did not record expected warning messages" |
|
197 exit 1 |
|
198 esac |
|
199 |
|
200 TestFile "HelloAnnotation.class" |
|
201 |
|
202 # --------------------------------------------------------------- |
|
203 |
|
204 echo "Verifying static state is available across apt rounds; -factory, -cp" |
|
205 |
|
206 mkdir -p ./src |
|
207 mkdir -p ./class |
|
208 |
|
209 rm -Rf ./src/* |
|
210 rm -Rf ./class/* |
|
211 |
|
212 printf "%s\n" "-factory StaticApf" > options4 |
|
213 printf "%s\n" "-s ./src" >> options4 |
|
214 printf "%s\n" "-d ./class" >> options4 |
|
215 printf "%s\n" "-cp ${TESTCLASSES}" >> options4 |
|
216 # printf "%s\n" "-XPrintAptRounds" >> options4 |
|
217 ${APT} @options4 |
|
218 |
|
219 TestFile "./class/AndAhTwo.class" |
|
220 |
|
221 # --------------------------------------------------------------- |
|
222 |
|
223 echo "Verifying static state is available across apt rounds; -factory, -factorypath" |
|
224 |
|
225 rm -Rf ./src/* |
|
226 rm -Rf ./class/* |
|
227 |
|
228 printf "%s\n" "-factory StaticApf" > options5 |
|
229 printf "%s\n" "-s ./src" >> options5 |
|
230 printf "%s\n" "-d ./class" >> options5 |
|
231 printf "%s\n" "-factorypath ${TESTCLASSES}" >> options5 |
|
232 # printf "%s\n" "-XPrintAptRounds" >> options5 |
|
233 ${APT} @options5 |
|
234 |
|
235 TestFile "./class/AndAhTwo.class" |
|
236 |
|
237 # -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= |
|
238 |
|
239 # Create jar file for StaticApf |
|
240 JAR="${TESTJAVA}/bin/jar " |
|
241 mkdir -p META-INF/services |
|
242 cp ${TESTSRC}/servicesStaticApf META-INF/services/com.sun.mirror.apt.AnnotationProcessorFactory |
|
243 cp ${TESTCLASSES}/StaticApf*.class . |
|
244 ${JAR} cf0 staticApf.jar StaticApf*.class META-INF |
|
245 |
|
246 # --------------------------------------------------------------- |
|
247 |
|
248 echo "Verifying static state is available across apt rounds; -cp" |
|
249 |
|
250 rm -Rf ./src/* |
|
251 rm -Rf ./class/* |
|
252 |
|
253 printf "%s\n" "-cp staticApf.jar" > options6 |
|
254 printf "%s\n" "-s ./src" >> options6 |
|
255 printf "%s\n" "-d ./class" >> options6 |
|
256 printf "%s\n" "-XPrintAptRounds" >> options6 |
|
257 ${APT} @options6 |
|
258 |
|
259 TestFile "./class/AndAhTwo.class" |
|
260 |
|
261 # --------------------------------------------------------------- |
|
262 |
|
263 echo "Verifying static state is available across apt rounds; -factorypath" |
|
264 |
|
265 rm -Rf ./src/* |
|
266 rm -Rf ./class/* |
|
267 |
|
268 printf "%s\n" "-factorypath staticApf.jar" > options7 |
|
269 printf "%s\n" "-s ./src" >> options7 |
|
270 printf "%s\n" "-d ./class" >> options7 |
|
271 printf "%s\n" "-XPrintAptRounds" >> options7 |
|
272 ${APT} @options7 |
|
273 |
|
274 TestFile "./class/AndAhTwo.class" |
|
275 |
|
276 # --------------------------------------------------------------- |
|
277 |
|
278 echo "Verifying -XclassesAsDecls handles class files properly" |
|
279 |
|
280 rm -Rf ./src/* |
|
281 rm -Rf ./class/* |
|
282 |
|
283 mkdir -p ./tmp/classes |
|
284 |
|
285 ${JAVAC} -d ./tmp/classes ${TESTSRC}/src/Round1Class.java ${TESTSRC}/src/AhOneClass.java ${TESTSRC}/src/AndAhTwoClass.java |
|
286 |
|
287 RESULT=$? |
|
288 case "$RESULT" in |
|
289 0 ) |
|
290 ;; |
|
291 |
|
292 * ) |
|
293 echo "FAILED: javac failed to succesfully compile." |
|
294 exit 1 |
|
295 esac |
|
296 |
|
297 printf "%s\n" "-factorypath ${TESTCLASSES}" > options7a |
|
298 printf "%s\n" "-factory ClassDeclApf" >> options7a |
|
299 printf "%s\n" "-s ./src" >> options7a |
|
300 printf "%s\n" "-d ./class" >> options7a |
|
301 printf "%s\n" "-XPrintAptRounds" >> options7a |
|
302 printf "%s\n" "-XclassesAsDecls" >> options7a |
|
303 ${APT} @options7a |
|
304 |
|
305 TestFile "./class/AndAhTwoClass.class" |
|
306 |
|
307 # --------------------------------------------------------------- |
|
308 |
|
309 echo "Verifying -XclassesAsDecls works with command-line arguments" |
|
310 |
|
311 rm -Rf ./src/* |
|
312 rm -Rf ./class/* |
|
313 rm -Rf ./tmp/classes |
|
314 |
|
315 mkdir -p ./tmp/classes |
|
316 |
|
317 ${JAVAC} -d ./tmp/classes ${TESTSRC}/src/Round1Class.java ${TESTSRC}/src/AndAhTwoClass.java |
|
318 |
|
319 RESULT=$? |
|
320 case "$RESULT" in |
|
321 0 ) |
|
322 ;; |
|
323 |
|
324 * ) |
|
325 echo "FAILED: javac failed to succesfully compile." |
|
326 exit 1 |
|
327 esac |
|
328 |
|
329 printf "%s\n" "-factorypath ${TESTCLASSES}" > options7b |
|
330 printf "%s\n" "-factory ClassDeclApf2" >> options7b |
|
331 printf "%s\n" "-XPrintAptRounds" >> options7b |
|
332 printf "%s\n" "-XclassesAsDecls" >> options7b |
|
333 printf "%s\n" "-cp ${TESTCLASSES}" >> options7b |
|
334 printf "%s\n" "ErrorAPF" >> options7b |
|
335 printf "%s\n" "WarnAPF" >> options7b |
|
336 printf "%s\n" "-s ./src" >> options7b |
|
337 printf "%s\n" "-d ./class" >> options7b |
|
338 printf "%s\n" "ClassDeclApf" >> options7b |
|
339 ${APT} @options7b |
|
340 |
|
341 RESULT=$? |
|
342 case "$RESULT" in |
|
343 0 ) |
|
344 ;; |
|
345 |
|
346 * ) |
|
347 echo "FAILED: apt exited with an error code." |
|
348 exit 1 |
|
349 esac |
|
350 |
|
351 TestFile "./class/AndAhTwoClass.class" |
|
352 TestFile "./class/AhOne.class" |
|
353 |
|
354 # --------------------------------------------------------------- |
|
355 |
|
356 echo "Verifying -XclassesAsDecls works with all source files" |
|
357 |
|
358 rm -Rf ./src/* |
|
359 rm -Rf ./class/* |
|
360 rm -Rf ./tmp/classes |
|
361 |
|
362 mkdir -p ./tmp/classes |
|
363 |
|
364 ${JAVAC} -d ./tmp/classes ${TESTSRC}/src/Round1Class.java ${TESTSRC}/src/AndAhTwoClass.java |
|
365 |
|
366 RESULT=$? |
|
367 case "$RESULT" in |
|
368 0 ) |
|
369 ;; |
|
370 |
|
371 * ) |
|
372 echo "FAILED: javac failed to succesfully compile." |
|
373 exit 1 |
|
374 esac |
|
375 |
|
376 printf "%s\n" "-factorypath ${TESTCLASSES}" > options7c |
|
377 printf "%s\n" "-factory ClassDeclApf2" >> options7c |
|
378 printf "%s\n" "-s ./src" >> options7c |
|
379 printf "%s\n" "-d ./class" >> options7c |
|
380 printf "%s\n" "-sourcepath ${TESTSRC}" >> options7c |
|
381 printf "%s\n" "${TESTSRC}/HelloAnnotation.java" >> options7c |
|
382 printf "%s\n" "${TESTSRC}/HelloWorld.java" >> options7c |
|
383 printf "%s\n" "${TESTSRC}/Dummy1.java" >> options7c |
|
384 printf "%s\n" "-XPrintAptRounds" >> options7c |
|
385 printf "%s\n" "-XclassesAsDecls" >> options7c |
|
386 printf "%s\n" "-cp ${TESTCLASSES}" >> options7c |
|
387 ${APT} @options7c |
|
388 |
|
389 RESULT=$? |
|
390 case "$RESULT" in |
|
391 0 ) |
|
392 ;; |
|
393 |
|
394 * ) |
|
395 echo "FAILED: apt exited with an error code." |
|
396 exit 1 |
|
397 esac |
|
398 |
|
399 TestFile "./class/AndAhTwoClass.class" |
|
400 TestFile "./class/AhOne.class" |
|
401 TestFile "./class/HelloWorld.class" |
|
402 |
|
403 # --------------------------------------------------------------- |
|
404 |
|
405 echo "Verifying -XclassesAsDecls works with mixed class and source files" |
|
406 |
|
407 rm -Rf ./src/* |
|
408 rm -Rf ./class/* |
|
409 rm -Rf ./tmp/classes |
|
410 |
|
411 mkdir -p ./tmp/classes |
|
412 |
|
413 ${JAVAC} -d ./tmp/classes ${TESTSRC}/src/Round1Class.java ${TESTSRC}/src/AndAhTwoClass.java |
|
414 |
|
415 RESULT=$? |
|
416 case "$RESULT" in |
|
417 0 ) |
|
418 ;; |
|
419 |
|
420 * ) |
|
421 echo "FAILED: javac failed to succesfully compile." |
|
422 exit 1 |
|
423 esac |
|
424 |
|
425 printf "%s\n" "-factorypath ${TESTCLASSES}" > options7d |
|
426 printf "%s\n" "-factory ClassDeclApf2" >> options7d |
|
427 printf "%s\n" "-s ./src" >> options7d |
|
428 printf "%s\n" "-XclassesAsDecls" >> options7d |
|
429 printf "%s\n" "ClassDeclApf" >> options7d |
|
430 printf "%s\n" "-d ./class" >> options7d |
|
431 printf "%s\n" "ErrorAPF" >> options7d |
|
432 printf "%s\n" "-XPrintAptRounds" >> options7d |
|
433 printf "%s\n" "${TESTSRC}/HelloWorld.java" >> options7d |
|
434 printf "%s\n" "-cp ${TESTCLASSES}" >> options7d |
|
435 ${APT} @options7d |
|
436 |
|
437 RESULT=$? |
|
438 case "$RESULT" in |
|
439 0 ) |
|
440 ;; |
|
441 |
|
442 * ) |
|
443 echo "FAILED: apt exited with an error code." |
|
444 exit 1 |
|
445 esac |
|
446 |
|
447 TestFile "./class/AndAhTwoClass.class" |
|
448 TestFile "./class/AhOne.class" |
|
449 TestFile "./class/HelloWorld.class" |
|
450 |
|
451 # --------------------------------------------------------------- |
|
452 |
|
453 echo "Testing productive factories are called on subsequent rounds" |
|
454 |
|
455 rm -Rf ./src/* |
|
456 rm -Rf ./class/* |
|
457 |
|
458 rm -Rf META-INF/services/* |
|
459 cp ${TESTSRC}/servicesRound1 META-INF/services/com.sun.mirror.apt.AnnotationProcessorFactory |
|
460 cp ${TESTCLASSES}/Round1Apf*.class . |
|
461 ${JAR} cf0 round1Apf.jar Round1Apf*.class META-INF |
|
462 |
|
463 rm -Rf META-INF/services/* |
|
464 cp ${TESTSRC}/servicesRound2 META-INF/services/com.sun.mirror.apt.AnnotationProcessorFactory |
|
465 cp ${TESTCLASSES}/Round2Apf*.class . |
|
466 ${JAR} cf0 round2Apf.jar Round2Apf*.class META-INF |
|
467 |
|
468 rm -Rf META-INF/services/* |
|
469 cp ${TESTSRC}/servicesRound3 META-INF/services/com.sun.mirror.apt.AnnotationProcessorFactory |
|
470 cp ${TESTCLASSES}/Round3Apf*.class . |
|
471 ${JAR} cf0 round3Apf.jar Round3Apf*.class META-INF |
|
472 |
|
473 rm -Rf META-INF/services/* |
|
474 cp ${TESTSRC}/servicesRound4 META-INF/services/com.sun.mirror.apt.AnnotationProcessorFactory |
|
475 cp ${TESTCLASSES}/Round4Apf*.class . |
|
476 ${JAR} cf0 round4Apf.jar Round4Apf*.class META-INF |
|
477 |
|
478 cp ${TESTCLASSES}/Round?.class . |
|
479 ${JAR} cf0 rounds.jar Round?.class |
|
480 |
|
481 # cleanup file to prevent accidental discovery in current directory |
|
482 rm -Rf META-INF/services/* |
|
483 |
|
484 printf "%s\n" "-factorypath round1Apf.jar${SEP}round2Apf.jar${SEP}round3Apf.jar${SEP}round4Apf.jar" > options8 |
|
485 printf "%s\n" "-classpath rounds.jar" >> options8 |
|
486 printf "%s\n" "-s ./src" >> options8 |
|
487 printf "%s\n" "-d ./class" >> options8 |
|
488 #printf "%s\n" "-XPrintFactoryInfo" >> options8 |
|
489 #printf "%s\n" "-XPrintAptRounds" >> options8 |
|
490 printf "%s\n" "${TESTSRC}/Dummy1.java" >> options8 |
|
491 ${APT} @options8 > multiRoundOutput 2> multiRoundError |
|
492 |
|
493 diff ${DIFFOPTS} multiRoundOutput ${TESTSRC}/goldenFactory.txt |
|
494 |
|
495 RESULT=$? |
|
496 case "$RESULT" in |
|
497 0 ) |
|
498 ;; |
|
499 |
|
500 * ) |
|
501 echo "FAILED: unexpected factory state" |
|
502 exit 1 |
|
503 esac |
|
504 |
|
505 TestFile "./class/Dummy5.class" |
|
506 |
|
507 # --------------------------------------------------------------- |
|
508 |
|
509 echo "Verifying static state with programmatic apt entry; no factory options" |
|
510 rm -Rf ./src/* |
|
511 rm -Rf ./class/* |
|
512 ${JAVA} -cp ${TESTJAVA}/lib/tools.jar${SEP}${TESTCLASSES} WrappedStaticApf -s ./src -d ./class -XPrintAptRounds |
|
513 TestFile "./class/AndAhTwo.class" |
|
514 |
|
515 echo "Verifying static state with programmatic apt entry; -factory" |
|
516 rm -Rf ./src/* |
|
517 rm -Rf ./class/* |
|
518 ${JAVA} -cp ${TESTJAVA}/lib/tools.jar${SEP}${TESTCLASSES} WrappedStaticApf -factory ErrorAPF -s ./src -d ./class -XPrintAptRounds |
|
519 TestFile "./class/AndAhTwo.class" |
|
520 |
|
521 echo "Verifying static state with programmatic apt entry; -factorypath" |
|
522 rm -Rf ./src/* |
|
523 rm -Rf ./class/* |
|
524 ${JAVA} -cp ${TESTJAVA}/lib/tools.jar${SEP}${TESTCLASSES} WrappedStaticApf -factorypath round1Apf.jar -s ./src -d ./class -XPrintAptRounds |
|
525 TestFile "./class/AndAhTwo.class" |
|
526 |
|
527 echo "Verifying static state with programmatic apt entry; -factory and -factorypath" |
|
528 rm -Rf ./src/* |
|
529 rm -Rf ./class/* |
|
530 ${JAVA} -cp ${TESTJAVA}/lib/tools.jar${SEP}${TESTCLASSES} WrappedStaticApf -factorypath round1Apf.jar -factory Round1Apf -s ./src -d ./class -XPrintAptRounds |
|
531 TestFile "./class/AndAhTwo.class" |
|
532 |
|
533 exit 0 |
|