1 #!/bin/sh |
|
2 |
|
3 # |
|
4 # Copyright (c) 1999, 2008, 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 4984412 4985113 4908512 4990905 4998007 4998218 5002340 5023882 6370261 6363481 |
|
28 # @run shell ../verifyVariables.sh |
|
29 # @compile PhantomUpdate.java |
|
30 # @run shell discovery.sh |
|
31 # @summary Test consistency of annotation discovery |
|
32 # @author Joseph D. Darcy |
|
33 |
|
34 |
|
35 # If the file does not exist, exit with an error |
|
36 TestFile() { |
|
37 if [ ! -f ${1} ]; then |
|
38 printf "%s\n" "File ${1} not found." |
|
39 exit 1 |
|
40 fi |
|
41 } |
|
42 |
|
43 OS=`uname -s`; |
|
44 case "${OS}" in |
|
45 Windows* | CYGWIN* ) |
|
46 SEP=";" |
|
47 ;; |
|
48 |
|
49 * ) |
|
50 SEP=":" |
|
51 ;; |
|
52 esac |
|
53 |
|
54 TOOLSJAR=${TESTJAVA}/lib/tools.jar |
|
55 |
|
56 OLDCP=${CLASSPATH} |
|
57 |
|
58 JARCP=tweedle.jar${SEP}touch.jar${SEP}${TOOLSJAR} |
|
59 SOURCEP=${TESTSRC} |
|
60 FULLCP=${JARCP}${SEP}${SOURCEP} |
|
61 BADCP=tweedle.jar${SEP}badTouch.jar${SEP}${TOOLSJAR} |
|
62 |
|
63 # Construct path to apt executable |
|
64 APT="${TESTJAVA}/bin/apt ${TESTTOOLVMOPTS} " |
|
65 |
|
66 |
|
67 # Construct path to apt executable, no compilation |
|
68 APTNC="${APT} -nocompile " |
|
69 |
|
70 |
|
71 printf "%s\n" "APT = ${APT}" |
|
72 |
|
73 # Construct path to javac executable |
|
74 JAVAC="${TESTJAVA}/bin/javac ${TESTTOOLVMOPTS} -source 1.5 -sourcepath ${TESTSRC} -classpath ${TOOLSJAR} -d . " |
|
75 JAR="${TESTJAVA}/bin/jar " |
|
76 |
|
77 $JAVAC ${TESTSRC}/Dee.java ${TESTSRC}/Dum.java ${TESTSRC}/Touch.java ${TESTSRC}/PhantomTouch.java ${TESTSRC}/Empty.java |
|
78 RESULT=$? |
|
79 |
|
80 case "${RESULT}" in |
|
81 0 ) |
|
82 ;; |
|
83 |
|
84 * ) |
|
85 echo "Compilation failed." |
|
86 exit 1 |
|
87 esac |
|
88 |
|
89 mv Empty.class Empty.clazz |
|
90 |
|
91 echo "Making services directory and copying services information." |
|
92 mkdir -p META-INF/services |
|
93 mkdir -p phantom |
|
94 |
|
95 rm -f touch.jar |
|
96 rm -f badTouch.jar |
|
97 |
|
98 cp ${TESTSRC}/servicesTweedle META-INF/services/com.sun.mirror.apt.AnnotationProcessorFactory |
|
99 |
|
100 ${JAR} cf0 tweedle.jar Dee*.class Dum*.class META-INF |
|
101 |
|
102 rm -f META-INF/services/com.sun.mirror.apt.AnnotationProcessorFactory |
|
103 cp ${TESTSRC}/servicesTouch ./META-INF/services/com.sun.mirror.apt.AnnotationProcessorFactory |
|
104 |
|
105 ${JAR} cf0 touch.jar Touch*.class META-INF |
|
106 |
|
107 rm -f META-INF/services/com.sun.mirror.apt.AnnotationProcessorFactory |
|
108 cp ${TESTSRC}/servicesPhantomTouch ./META-INF/services/com.sun.mirror.apt.AnnotationProcessorFactory |
|
109 |
|
110 ${JAR} cf0 phantom/phantom.jar PhantomTouch*.class META-INF |
|
111 |
|
112 # cleanup file to prevent accidental discovery in current directory |
|
113 rm -f META-INF/services/com.sun.mirror.apt.AnnotationProcessorFactory |
|
114 |
|
115 # Jar files created; verify right output file is touched |
|
116 |
|
117 #--------------------------------------------------------- |
|
118 |
|
119 # Test different combinations of classpath, sourcepath, and |
|
120 # destination directories |
|
121 |
|
122 |
|
123 # |
|
124 # Classpath on commandline; no output directories |
|
125 # |
|
126 |
|
127 rm -f touched |
|
128 rm -f HelloWorld.java |
|
129 rm -f Empty.class |
|
130 |
|
131 unset CLASSPATH |
|
132 printf "%s\n" "-classpath ${JARCP}" > options1 |
|
133 printf "%s\n" "-sourcepath ${SOURCEP}" >> options1 |
|
134 printf "%s\n" "${TESTSRC}/Touch.java" >> options1 |
|
135 |
|
136 ${APTNC} @options1 |
|
137 |
|
138 echo "Testing case 1" |
|
139 TestFile "touched" |
|
140 TestFile "HelloWorld.java" |
|
141 TestFile "Empty.class" |
|
142 |
|
143 # |
|
144 # Class path set through environment variable |
|
145 # |
|
146 |
|
147 rm -f touched |
|
148 rm -f HelloWorld.java |
|
149 rm -f Empty.class |
|
150 |
|
151 unset CLASSPATH |
|
152 CLASSPATH=${JARCP} |
|
153 export CLASSPATH |
|
154 printf "%s\n" "-sourcepath ${SOURCEP}" > options2 |
|
155 printf "%s\n" "${TESTSRC}/Touch.java" >> options2 |
|
156 |
|
157 ${APTNC} @options2 |
|
158 |
|
159 echo "Testing case 2" |
|
160 TestFile "touched" |
|
161 TestFile "HelloWorld.java" |
|
162 TestFile "Empty.class" |
|
163 |
|
164 # |
|
165 # No explicit source path |
|
166 # |
|
167 |
|
168 rm -f touched |
|
169 rm -f HelloWorld.java |
|
170 rm -f Empty.class |
|
171 |
|
172 unset CLASSPATH |
|
173 CLASSPATH=${FULLCP} |
|
174 export CLASSPATH |
|
175 printf "%s\n" "${TESTSRC}/Touch.java" > options3 |
|
176 |
|
177 ${APTNC} @options3 |
|
178 |
|
179 echo "Testing case 3" |
|
180 TestFile "touched" |
|
181 TestFile "HelloWorld.java" |
|
182 TestFile "Empty.class" |
|
183 |
|
184 |
|
185 # |
|
186 # Classpath on commandline; class output directory |
|
187 # |
|
188 |
|
189 rm -f touched |
|
190 rm -f HelloWorld.java |
|
191 rm -Rf classes/Empty.class |
|
192 |
|
193 unset CLASSPATH |
|
194 printf "%s\n" "-classpath ${JARCP}" > options4 |
|
195 printf "%s\n" "-sourcepath ${SOURCEP}" >> options4 |
|
196 printf "%s\n" "-d classes" >> options4 |
|
197 printf "%s\n" "${TESTSRC}/Touch.java" >> options4 |
|
198 |
|
199 ${APTNC} @options4 |
|
200 |
|
201 echo "Testing case 4" |
|
202 TestFile "touched" |
|
203 TestFile "HelloWorld.java" |
|
204 TestFile "classes/Empty.class" |
|
205 |
|
206 # |
|
207 # Classpath on commandline; source output directory |
|
208 # |
|
209 |
|
210 rm -f touched |
|
211 rm -Rf src |
|
212 rm -f Empty.class |
|
213 |
|
214 unset CLASSPATH |
|
215 printf "%s\n" "-classpath ${JARCP}" > options5 |
|
216 printf "%s\n" "-sourcepath ${SOURCEP}" >> options5 |
|
217 printf "%s\n" "-s src" >> options5 |
|
218 printf "%s\n" "${TESTSRC}/Touch.java" >> options5 |
|
219 |
|
220 ${APTNC} @options5 |
|
221 |
|
222 echo "Testing case 5" |
|
223 TestFile "touched" |
|
224 TestFile "src/HelloWorld.java" |
|
225 TestFile "Empty.class" |
|
226 |
|
227 |
|
228 # |
|
229 # Classpath on commandline; class and source output directory |
|
230 # |
|
231 |
|
232 rm -f touched |
|
233 rm -Rf src |
|
234 rm -Rf classes |
|
235 |
|
236 unset CLASSPATH |
|
237 printf "%s\n" "-classpath ${JARCP}" > options6 |
|
238 printf "%s\n" "-sourcepath ${SOURCEP}" >> options6 |
|
239 printf "%s\n" "-d classes" >> options6 |
|
240 printf "%s\n" "-s src" >> options6 |
|
241 printf "%s\n" "${TESTSRC}/Touch.java" >> options6 |
|
242 |
|
243 ${APTNC} @options6 |
|
244 |
|
245 echo "Testing case 6" |
|
246 TestFile "touched" |
|
247 TestFile "src/HelloWorld.java" |
|
248 TestFile "classes/Empty.class" |
|
249 |
|
250 # |
|
251 # Classpath appended to bootclasspath; no output directories |
|
252 # |
|
253 |
|
254 rm -f touched |
|
255 rm -f HelloWorld.java |
|
256 rm -f Empty.class |
|
257 |
|
258 unset CLASSPATH |
|
259 printf "%s\n" "-Xbootclasspath/a:${JARCP}" > options7 |
|
260 printf "%s\n" "-classpath /dev/null" >> options7 |
|
261 printf "%s\n" "${TESTSRC}/Touch.java" >> options7 |
|
262 |
|
263 ${APTNC} @options7 |
|
264 |
|
265 echo "Testing case 7" |
|
266 TestFile "touched" |
|
267 TestFile "HelloWorld.java" |
|
268 TestFile "Empty.class" |
|
269 |
|
270 # |
|
271 # Classpath in extdirs; no output directories |
|
272 # |
|
273 |
|
274 rm -f touched |
|
275 rm -f HelloWorld.java |
|
276 rm -f Empty.class |
|
277 |
|
278 unset CLASSPATH |
|
279 printf "%s\n" "-extdirs ." > options8 |
|
280 printf "%s\n" "-classpath ${TOOLSJAR}" >> options8 |
|
281 printf "%s\n" "${TESTSRC}/Touch.java" >> options8 |
|
282 |
|
283 ${APTNC} @options8 |
|
284 |
|
285 echo "Testing case 8" |
|
286 TestFile "touched" |
|
287 TestFile "HelloWorld.java" |
|
288 TestFile "Empty.class" |
|
289 |
|
290 # |
|
291 # Classpath in extdirs, take 2; no output directories |
|
292 # |
|
293 |
|
294 rm -f touched |
|
295 rm -f HelloWorld.java |
|
296 rm -f Empty.class |
|
297 |
|
298 unset CLASSPATH |
|
299 printf "%s\n" "-Djava.ext.dirs=." > options9 |
|
300 printf "%s\n" "-classpath ${TOOLSJAR}" >> options9 |
|
301 printf "%s\n" "${TESTSRC}/Touch.java" >> options9 |
|
302 |
|
303 ${APTNC} @options9 |
|
304 |
|
305 echo "Testing case 9" |
|
306 TestFile "touched" |
|
307 TestFile "HelloWorld.java" |
|
308 TestFile "Empty.class" |
|
309 |
|
310 # |
|
311 # Classpath in -endorseddirs; no output directories |
|
312 # |
|
313 |
|
314 rm -f touched |
|
315 rm -f HelloWorld.java |
|
316 rm -f Empty.class |
|
317 |
|
318 unset CLASSPATH |
|
319 printf "%s\n" "-endorseddirs ." > options10 |
|
320 printf "%s\n" "-classpath ${TOOLSJAR}" >> options10 |
|
321 printf "%s\n" "${TESTSRC}/Touch.java" >> options10 |
|
322 |
|
323 ${APTNC} @options10 |
|
324 |
|
325 echo "Testing case 10" |
|
326 TestFile "touched" |
|
327 TestFile "HelloWorld.java" |
|
328 TestFile "Empty.class" |
|
329 |
|
330 # |
|
331 # Testing apt invocation with no command line options |
|
332 # |
|
333 |
|
334 rm -f touched |
|
335 rm -f HelloWorld.java |
|
336 rm -f Empty.class |
|
337 |
|
338 unset CLASSPATH |
|
339 CLASSPATH=./phantom/phantom.jar |
|
340 export CLASSPATH |
|
341 |
|
342 ${APT} |
|
343 |
|
344 echo "Testing empty command line" |
|
345 TestFile "touched" |
|
346 TestFile "HelloWorld.java" |
|
347 |
|
348 |
|
349 # |
|
350 # Verify apt and JSR 269 annotation processors can be run from same |
|
351 # invocation and both use the output directories |
|
352 # |
|
353 |
|
354 rm -f touched |
|
355 rm -f src/HelloWorld.java |
|
356 rm -f src/GoodbyeWorld.java |
|
357 rm -f classes/HelloWorld.class |
|
358 rm -f classes/GoodbyeWorld.class |
|
359 |
|
360 unset CLASSPATH |
|
361 |
|
362 |
|
363 printf "%s\n" "-classpath ./phantom/phantom.jar" > options11 |
|
364 printf "%s\n" "-sourcepath ${SOURCEP}" >> options11 |
|
365 printf "%s\n" "-factory PhantomTouch " >> options11 |
|
366 printf "%s\n" "-s src" >> options11 |
|
367 printf "%s\n" "-d classes" >> options11 |
|
368 printf "%s\n" "-A" >> options11 |
|
369 printf "%s\n" "-Afoo" >> options11 |
|
370 printf "%s\n" "-Abar=baz" >> options11 |
|
371 printf "%s\n" "-processorpath $TESTCLASSES" >> options11 |
|
372 printf "%s\n" "-processor PhantomUpdate" >> options11 |
|
373 |
|
374 ${APT} @options11 |
|
375 |
|
376 echo "Testing combined apt and JSR 269 processing" |
|
377 TestFile touched |
|
378 TestFile "src/HelloWorld.java" |
|
379 TestFile "src/GoodbyeWorld.java" |
|
380 TestFile "classes/HelloWorld.class" |
|
381 TestFile "classes/GoodbyeWorld.class" |
|
382 |
|
383 # |
|
384 # Verify running with badTouch doesn't exit successfully |
|
385 # |
|
386 |
|
387 rm -f ./META-INF/services/com.sun.mirror.apt.AnnotationProcessorFactory |
|
388 cp ${TESTSRC}/servicesBadTouch ./META-INF/services/com.sun.mirror.apt.AnnotationProcessorFactory |
|
389 |
|
390 ${JAR} cf0 badTouch.jar Touch*.class META-INF |
|
391 |
|
392 |
|
393 unset CLASSPATH |
|
394 printf "%s\n" "-classpath ${BADCP}" > optionsBad |
|
395 printf "%s\n" "-sourcepath ${SOURCEP}" >> optionsBad |
|
396 printf "%s\n" "${TESTSRC}/Touch.java" >> optionsBad |
|
397 |
|
398 ${APTNC} @optionsBad 2> /dev/null |
|
399 |
|
400 RESULT=$? |
|
401 |
|
402 case "${RESULT}" in |
|
403 0 ) |
|
404 echo "Improper exit zero with bad services information." |
|
405 exit 1 |
|
406 ;; |
|
407 esac |
|
408 |
|
409 |
|
410 exit 0; |
|