|
1 #!/bin/sh |
|
2 |
|
3 # |
|
4 # Copyright 2004-2007 Sun Microsystems, Inc. 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 Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, |
|
22 # CA 95054 USA or visit www.sun.com if you need additional information or |
|
23 # have any 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* | CYGWIN* ) |
|
61 SEP=";" |
|
62 ;; |
|
63 |
|
64 * ) |
|
65 SEP=":" |
|
66 ;; |
|
67 esac |
|
68 |
|
69 |
|
70 APT="${TESTJAVA}/bin/apt ${TESTTOOLVMOPTS} " |
|
71 JAVA="${TESTJAVA}/bin/java ${TESTVMOPTS} " |
|
72 JAVAC="${TESTJAVA}/bin/javac ${TESTTOOLVMOPTS} " |
|
73 |
|
74 unset CLASSPATH |
|
75 |
|
76 |
|
77 # --------------------------------------------------------------- |
|
78 echo "Verify that source 1.6 is not supported |
|
79 rm -f HelloWorld.class |
|
80 |
|
81 printf "%s\n" "-source 1.6" > options0 |
|
82 printf "%s\n" "${TESTSRC}/HelloWorld.java" >> options0 |
|
83 ${APT} @options0 |
|
84 |
|
85 RESULT=$? |
|
86 case "$RESULT" in |
|
87 0 ) |
|
88 echo "FAILED: accepted source 1.6" |
|
89 exit 1 |
|
90 ;; |
|
91 esac |
|
92 |
|
93 TestNoFile "HelloWorld.class" |
|
94 |
|
95 # --------------------------------------------------------------- |
|
96 |
|
97 echo "Verify that target 1.6 is not supported |
|
98 rm -f HelloWorld.class |
|
99 |
|
100 printf "%s\n" "-target 1.6" > options00 |
|
101 printf "%s\n" "${TESTSRC}/HelloWorld.java" >> options00 |
|
102 ${APT} @options00 |
|
103 |
|
104 RESULT=$? |
|
105 case "$RESULT" in |
|
106 0 ) |
|
107 echo "FAILED: accepted target 1.6" |
|
108 exit 1 |
|
109 ;; |
|
110 esac |
|
111 |
|
112 TestNoFile "HelloWorld.class" |
|
113 |
|
114 # --------------------------------------------------------------- |
|
115 |
|
116 echo "Testing javac pass-through with -A in options file" |
|
117 rm -f HelloWorld.class |
|
118 |
|
119 printf "%s\n" "-A" > options1 |
|
120 printf "%s\n" "-d ." >> options1 |
|
121 printf "%s\n" "${TESTSRC}/HelloWorld.java" >> options1 |
|
122 ${APT} @options1 |
|
123 |
|
124 RESULT=$? |
|
125 case "$RESULT" in |
|
126 0 ) |
|
127 ;; |
|
128 |
|
129 * ) |
|
130 echo "FAILED: javac with -A in options file did not compile" |
|
131 exit 1 |
|
132 esac |
|
133 TestFile "HelloWorld.class" |
|
134 |
|
135 |
|
136 # --------------------------------------------------------------- |
|
137 |
|
138 echo "Verifying reporting an error will prevent compilation" |
|
139 rm -f HelloWorld.class |
|
140 if [ ! -f HelloWorld.java ]; then |
|
141 cp ${TESTSRC}/HelloWorld.java . |
|
142 fi |
|
143 |
|
144 |
|
145 printf "%s\n" "-factory ErrorAPF" > options2 |
|
146 printf "%s\n" "-d ." >> options2 |
|
147 printf "%s\n" "-cp ${TESTCLASSES}" >> options2 |
|
148 printf "%s\n" "HelloWorld.java" >> options2 |
|
149 ${APT} @options2 2> output |
|
150 |
|
151 TestNoFile "HelloWorld.class" |
|
152 |
|
153 diff output ${TESTSRC}/golden.txt |
|
154 |
|
155 RESULT=$? |
|
156 case "$RESULT" in |
|
157 0 ) |
|
158 ;; |
|
159 |
|
160 * ) |
|
161 echo "FAILED: did not record expected error messages" |
|
162 exit 1 |
|
163 esac |
|
164 |
|
165 |
|
166 |
|
167 # --------------------------------------------------------------- |
|
168 |
|
169 echo "Verifying reporting a warning *won't* prevent compilation" |
|
170 |
|
171 rm -f HelloAnnotation.class |
|
172 if [ ! -f HelloAnnotation.java ]; then |
|
173 cp ${TESTSRC}/HelloAnnotation.java . |
|
174 fi |
|
175 |
|
176 |
|
177 printf "%s\n" "-factory WarnAPF" > options3 |
|
178 printf "%s\n" "-d ." >> options3 |
|
179 printf "%s\n" "-cp ${TESTCLASSES}" >> options3 |
|
180 printf "%s\n" "HelloAnnotation.java" >> options3 |
|
181 ${APT} @options3 2> output |
|
182 |
|
183 diff output ${TESTSRC}/goldenWarn.txt |
|
184 |
|
185 RESULT=$? |
|
186 case "$RESULT" in |
|
187 0 ) |
|
188 ;; |
|
189 |
|
190 * ) |
|
191 echo "FAILED: did not record expected warning messages" |
|
192 exit 1 |
|
193 esac |
|
194 |
|
195 TestFile "HelloAnnotation.class" |
|
196 |
|
197 # --------------------------------------------------------------- |
|
198 |
|
199 echo "Verifying static state is available across apt rounds; -factory, -cp" |
|
200 |
|
201 mkdir -p ./src |
|
202 mkdir -p ./class |
|
203 |
|
204 rm -Rf ./src/* |
|
205 rm -Rf ./class/* |
|
206 |
|
207 printf "%s\n" "-factory StaticApf" > options4 |
|
208 printf "%s\n" "-s ./src" >> options4 |
|
209 printf "%s\n" "-d ./class" >> options4 |
|
210 printf "%s\n" "-cp ${TESTCLASSES}" >> options4 |
|
211 # printf "%s\n" "-XPrintAptRounds" >> options4 |
|
212 ${APT} @options4 |
|
213 |
|
214 TestFile "./class/AndAhTwo.class" |
|
215 |
|
216 # --------------------------------------------------------------- |
|
217 |
|
218 echo "Verifying static state is available across apt rounds; -factory, -factorypath" |
|
219 |
|
220 rm -Rf ./src/* |
|
221 rm -Rf ./class/* |
|
222 |
|
223 printf "%s\n" "-factory StaticApf" > options5 |
|
224 printf "%s\n" "-s ./src" >> options5 |
|
225 printf "%s\n" "-d ./class" >> options5 |
|
226 printf "%s\n" "-factorypath ${TESTCLASSES}" >> options5 |
|
227 # printf "%s\n" "-XPrintAptRounds" >> options5 |
|
228 ${APT} @options5 |
|
229 |
|
230 TestFile "./class/AndAhTwo.class" |
|
231 |
|
232 # -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= |
|
233 |
|
234 # Create jar file for StaticApf |
|
235 JAR="${TESTJAVA}/bin/jar " |
|
236 mkdir -p META-INF/services |
|
237 cp ${TESTSRC}/servicesStaticApf META-INF/services/com.sun.mirror.apt.AnnotationProcessorFactory |
|
238 cp ${TESTCLASSES}/StaticApf*.class . |
|
239 ${JAR} cf0 staticApf.jar StaticApf*.class META-INF |
|
240 |
|
241 # --------------------------------------------------------------- |
|
242 |
|
243 echo "Verifying static state is available across apt rounds; -cp" |
|
244 |
|
245 rm -Rf ./src/* |
|
246 rm -Rf ./class/* |
|
247 |
|
248 printf "%s\n" "-cp staticApf.jar" > options6 |
|
249 printf "%s\n" "-s ./src" >> options6 |
|
250 printf "%s\n" "-d ./class" >> options6 |
|
251 printf "%s\n" "-XPrintAptRounds" >> options6 |
|
252 ${APT} @options6 |
|
253 |
|
254 TestFile "./class/AndAhTwo.class" |
|
255 |
|
256 # --------------------------------------------------------------- |
|
257 |
|
258 echo "Verifying static state is available across apt rounds; -factorypath" |
|
259 |
|
260 rm -Rf ./src/* |
|
261 rm -Rf ./class/* |
|
262 |
|
263 printf "%s\n" "-factorypath staticApf.jar" > options7 |
|
264 printf "%s\n" "-s ./src" >> options7 |
|
265 printf "%s\n" "-d ./class" >> options7 |
|
266 printf "%s\n" "-XPrintAptRounds" >> options7 |
|
267 ${APT} @options7 |
|
268 |
|
269 TestFile "./class/AndAhTwo.class" |
|
270 |
|
271 # --------------------------------------------------------------- |
|
272 |
|
273 echo "Verifying -XclassesAsDecls handles class files properly" |
|
274 |
|
275 rm -Rf ./src/* |
|
276 rm -Rf ./class/* |
|
277 |
|
278 mkdir -p ./tmp/classes |
|
279 |
|
280 ${JAVAC} -d ./tmp/classes ${TESTSRC}/src/Round1Class.java ${TESTSRC}/src/AhOneClass.java ${TESTSRC}/src/AndAhTwoClass.java |
|
281 |
|
282 RESULT=$? |
|
283 case "$RESULT" in |
|
284 0 ) |
|
285 ;; |
|
286 |
|
287 * ) |
|
288 echo "FAILED: javac failed to succesfully compile." |
|
289 exit 1 |
|
290 esac |
|
291 |
|
292 printf "%s\n" "-factorypath ${TESTCLASSES}" > options7a |
|
293 printf "%s\n" "-factory ClassDeclApf" >> options7a |
|
294 printf "%s\n" "-s ./src" >> options7a |
|
295 printf "%s\n" "-d ./class" >> options7a |
|
296 printf "%s\n" "-XPrintAptRounds" >> options7a |
|
297 printf "%s\n" "-XclassesAsDecls" >> options7a |
|
298 ${APT} @options7a |
|
299 |
|
300 TestFile "./class/AndAhTwoClass.class" |
|
301 |
|
302 # --------------------------------------------------------------- |
|
303 |
|
304 echo "Verifying -XclassesAsDecls works with command-line arguments" |
|
305 |
|
306 rm -Rf ./src/* |
|
307 rm -Rf ./class/* |
|
308 rm -Rf ./tmp/classes |
|
309 |
|
310 mkdir -p ./tmp/classes |
|
311 |
|
312 ${JAVAC} -d ./tmp/classes ${TESTSRC}/src/Round1Class.java ${TESTSRC}/src/AndAhTwoClass.java |
|
313 |
|
314 RESULT=$? |
|
315 case "$RESULT" in |
|
316 0 ) |
|
317 ;; |
|
318 |
|
319 * ) |
|
320 echo "FAILED: javac failed to succesfully compile." |
|
321 exit 1 |
|
322 esac |
|
323 |
|
324 printf "%s\n" "-factorypath ${TESTCLASSES}" > options7b |
|
325 printf "%s\n" "-factory ClassDeclApf2" >> options7b |
|
326 printf "%s\n" "-XPrintAptRounds" >> options7b |
|
327 printf "%s\n" "-XclassesAsDecls" >> options7b |
|
328 printf "%s\n" "-cp ${TESTCLASSES}" >> options7b |
|
329 printf "%s\n" "ErrorAPF" >> options7b |
|
330 printf "%s\n" "WarnAPF" >> options7b |
|
331 printf "%s\n" "-s ./src" >> options7b |
|
332 printf "%s\n" "-d ./class" >> options7b |
|
333 printf "%s\n" "ClassDeclApf" >> options7b |
|
334 ${APT} @options7b |
|
335 |
|
336 RESULT=$? |
|
337 case "$RESULT" in |
|
338 0 ) |
|
339 ;; |
|
340 |
|
341 * ) |
|
342 echo "FAILED: apt exited with an error code." |
|
343 exit 1 |
|
344 esac |
|
345 |
|
346 TestFile "./class/AndAhTwoClass.class" |
|
347 TestFile "./class/AhOne.class" |
|
348 |
|
349 # --------------------------------------------------------------- |
|
350 |
|
351 echo "Verifying -XclassesAsDecls works with all source files" |
|
352 |
|
353 rm -Rf ./src/* |
|
354 rm -Rf ./class/* |
|
355 rm -Rf ./tmp/classes |
|
356 |
|
357 mkdir -p ./tmp/classes |
|
358 |
|
359 ${JAVAC} -d ./tmp/classes ${TESTSRC}/src/Round1Class.java ${TESTSRC}/src/AndAhTwoClass.java |
|
360 |
|
361 RESULT=$? |
|
362 case "$RESULT" in |
|
363 0 ) |
|
364 ;; |
|
365 |
|
366 * ) |
|
367 echo "FAILED: javac failed to succesfully compile." |
|
368 exit 1 |
|
369 esac |
|
370 |
|
371 printf "%s\n" "-factorypath ${TESTCLASSES}" > options7c |
|
372 printf "%s\n" "-factory ClassDeclApf2" >> options7c |
|
373 printf "%s\n" "-s ./src" >> options7c |
|
374 printf "%s\n" "-d ./class" >> options7c |
|
375 printf "%s\n" "-sourcepath ${TESTSRC}" >> options7c |
|
376 printf "%s\n" "${TESTSRC}/HelloAnnotation.java" >> options7c |
|
377 printf "%s\n" "${TESTSRC}/HelloWorld.java" >> options7c |
|
378 printf "%s\n" "${TESTSRC}/Dummy1.java" >> options7c |
|
379 printf "%s\n" "-XPrintAptRounds" >> options7c |
|
380 printf "%s\n" "-XclassesAsDecls" >> options7c |
|
381 printf "%s\n" "-cp ${TESTCLASSES}" >> options7c |
|
382 ${APT} @options7c |
|
383 |
|
384 RESULT=$? |
|
385 case "$RESULT" in |
|
386 0 ) |
|
387 ;; |
|
388 |
|
389 * ) |
|
390 echo "FAILED: apt exited with an error code." |
|
391 exit 1 |
|
392 esac |
|
393 |
|
394 TestFile "./class/AndAhTwoClass.class" |
|
395 TestFile "./class/AhOne.class" |
|
396 TestFile "./class/HelloWorld.class" |
|
397 |
|
398 # --------------------------------------------------------------- |
|
399 |
|
400 echo "Verifying -XclassesAsDecls works with mixed class and source files" |
|
401 |
|
402 rm -Rf ./src/* |
|
403 rm -Rf ./class/* |
|
404 rm -Rf ./tmp/classes |
|
405 |
|
406 mkdir -p ./tmp/classes |
|
407 |
|
408 ${JAVAC} -d ./tmp/classes ${TESTSRC}/src/Round1Class.java ${TESTSRC}/src/AndAhTwoClass.java |
|
409 |
|
410 RESULT=$? |
|
411 case "$RESULT" in |
|
412 0 ) |
|
413 ;; |
|
414 |
|
415 * ) |
|
416 echo "FAILED: javac failed to succesfully compile." |
|
417 exit 1 |
|
418 esac |
|
419 |
|
420 printf "%s\n" "-factorypath ${TESTCLASSES}" > options7d |
|
421 printf "%s\n" "-factory ClassDeclApf2" >> options7d |
|
422 printf "%s\n" "-s ./src" >> options7d |
|
423 printf "%s\n" "-XclassesAsDecls" >> options7d |
|
424 printf "%s\n" "ClassDeclApf" >> options7d |
|
425 printf "%s\n" "-d ./class" >> options7d |
|
426 printf "%s\n" "ErrorAPF" >> options7d |
|
427 printf "%s\n" "-XPrintAptRounds" >> options7d |
|
428 printf "%s\n" "${TESTSRC}/HelloWorld.java" >> options7d |
|
429 printf "%s\n" "-cp ${TESTCLASSES}" >> options7d |
|
430 ${APT} @options7d |
|
431 |
|
432 RESULT=$? |
|
433 case "$RESULT" in |
|
434 0 ) |
|
435 ;; |
|
436 |
|
437 * ) |
|
438 echo "FAILED: apt exited with an error code." |
|
439 exit 1 |
|
440 esac |
|
441 |
|
442 TestFile "./class/AndAhTwoClass.class" |
|
443 TestFile "./class/AhOne.class" |
|
444 TestFile "./class/HelloWorld.class" |
|
445 |
|
446 # --------------------------------------------------------------- |
|
447 |
|
448 echo "Testing productive factories are called on subsequent rounds" |
|
449 |
|
450 rm -Rf ./src/* |
|
451 rm -Rf ./class/* |
|
452 |
|
453 rm -Rf META-INF/services/* |
|
454 cp ${TESTSRC}/servicesRound1 META-INF/services/com.sun.mirror.apt.AnnotationProcessorFactory |
|
455 cp ${TESTCLASSES}/Round1Apf*.class . |
|
456 ${JAR} cf0 round1Apf.jar Round1Apf*.class META-INF |
|
457 |
|
458 rm -Rf META-INF/services/* |
|
459 cp ${TESTSRC}/servicesRound2 META-INF/services/com.sun.mirror.apt.AnnotationProcessorFactory |
|
460 cp ${TESTCLASSES}/Round2Apf*.class . |
|
461 ${JAR} cf0 round2Apf.jar Round2Apf*.class META-INF |
|
462 |
|
463 rm -Rf META-INF/services/* |
|
464 cp ${TESTSRC}/servicesRound3 META-INF/services/com.sun.mirror.apt.AnnotationProcessorFactory |
|
465 cp ${TESTCLASSES}/Round3Apf*.class . |
|
466 ${JAR} cf0 round3Apf.jar Round3Apf*.class META-INF |
|
467 |
|
468 rm -Rf META-INF/services/* |
|
469 cp ${TESTSRC}/servicesRound4 META-INF/services/com.sun.mirror.apt.AnnotationProcessorFactory |
|
470 cp ${TESTCLASSES}/Round4Apf*.class . |
|
471 ${JAR} cf0 round4Apf.jar Round4Apf*.class META-INF |
|
472 |
|
473 cp ${TESTCLASSES}/Round?.class . |
|
474 ${JAR} cf0 rounds.jar Round?.class |
|
475 |
|
476 printf "%s\n" "-factorypath round1Apf.jar${SEP}round2Apf.jar${SEP}round3Apf.jar${SEP}round4Apf.jar" > options8 |
|
477 printf "%s\n" "-classpath rounds.jar" >> options8 |
|
478 printf "%s\n" "-s ./src" >> options8 |
|
479 printf "%s\n" "-d ./class" >> options8 |
|
480 #printf "%s\n" "-XPrintFactoryInfo" >> options8 |
|
481 #printf "%s\n" "-XPrintAptRounds" >> options8 |
|
482 printf "%s\n" "${TESTSRC}/Dummy1.java" >> options8 |
|
483 ${APT} @options8 > multiRoundOutput 2> multiRoundError |
|
484 |
|
485 diff multiRoundOutput ${TESTSRC}/goldenFactory.txt |
|
486 |
|
487 RESULT=$? |
|
488 case "$RESULT" in |
|
489 0 ) |
|
490 ;; |
|
491 |
|
492 * ) |
|
493 echo "FAILED: unexpected factory state" |
|
494 exit 1 |
|
495 esac |
|
496 |
|
497 TestFile "./class/Dummy5.class" |
|
498 |
|
499 # --------------------------------------------------------------- |
|
500 |
|
501 echo "Verifying static state with programmatic apt entry; no factory options" |
|
502 rm -Rf ./src/* |
|
503 rm -Rf ./class/* |
|
504 ${JAVA} -cp ${TESTJAVA}/lib/tools.jar${SEP}${TESTCLASSES} WrappedStaticApf -s ./src -d ./class -XPrintAptRounds |
|
505 TestFile "./class/AndAhTwo.class" |
|
506 |
|
507 echo "Verifying static state with programmatic apt entry; -factory" |
|
508 rm -Rf ./src/* |
|
509 rm -Rf ./class/* |
|
510 ${JAVA} -cp ${TESTJAVA}/lib/tools.jar${SEP}${TESTCLASSES} WrappedStaticApf -factory ErrorAPF -s ./src -d ./class -XPrintAptRounds |
|
511 TestFile "./class/AndAhTwo.class" |
|
512 |
|
513 echo "Verifying static state with programmatic apt entry; -factorypath" |
|
514 rm -Rf ./src/* |
|
515 rm -Rf ./class/* |
|
516 ${JAVA} -cp ${TESTJAVA}/lib/tools.jar${SEP}${TESTCLASSES} WrappedStaticApf -factorypath round1Apf.jar -s ./src -d ./class -XPrintAptRounds |
|
517 TestFile "./class/AndAhTwo.class" |
|
518 |
|
519 echo "Verifying static state with programmatic apt entry; -factory and -factorypath" |
|
520 rm -Rf ./src/* |
|
521 rm -Rf ./class/* |
|
522 ${JAVA} -cp ${TESTJAVA}/lib/tools.jar${SEP}${TESTCLASSES} WrappedStaticApf -factorypath round1Apf.jar -factory Round1Apf -s ./src -d ./class -XPrintAptRounds |
|
523 TestFile "./class/AndAhTwo.class" |
|
524 |
|
525 exit 0 |