test/tools/apt/Discovery/discovery.sh

changeset 1
9a66ca7c79fa
child 149
2eec479619d8
equal deleted inserted replaced
-1:000000000000 1:9a66ca7c79fa
1 #!/bin/sh
2
3 #
4 # Copyright 1999-2002 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 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
113
114 # Jar files created; verify right output file is touched
115
116 #---------------------------------------------------------
117
118 # Test different combinations of classpath, sourcepath, and
119 # destination directories
120
121
122 #
123 # Classpath on commandline; no output directories
124 #
125
126 rm -f touched
127 rm -f HelloWorld.java
128 rm -f Empty.class
129
130 unset CLASSPATH
131 printf "%s\n" "-classpath ${JARCP}" > options1
132 printf "%s\n" "-sourcepath ${SOURCEP}" >> options1
133 printf "%s\n" "${TESTSRC}/Touch.java" >> options1
134
135 ${APTNC} @options1
136
137 echo "Testing case 1"
138 TestFile "touched"
139 TestFile "HelloWorld.java"
140 TestFile "Empty.class"
141
142 #
143 # Class path set through environment variable
144 #
145
146 rm -f touched
147 rm -f HelloWorld.java
148 rm -f Empty.class
149
150 unset CLASSPATH
151 CLASSPATH=${JARCP}
152 export CLASSPATH
153 printf "%s\n" "-sourcepath ${SOURCEP}" > options2
154 printf "%s\n" "${TESTSRC}/Touch.java" >> options2
155
156 ${APTNC} @options2
157
158 echo "Testing case 2"
159 TestFile "touched"
160 TestFile "HelloWorld.java"
161 TestFile "Empty.class"
162
163 #
164 # No explicit source path
165 #
166
167 rm -f touched
168 rm -f HelloWorld.java
169 rm -f Empty.class
170
171 unset CLASSPATH
172 CLASSPATH=${FULLCP}
173 export CLASSPATH
174 printf "%s\n" "${TESTSRC}/Touch.java" > options3
175
176 ${APTNC} @options3
177
178 echo "Testing case 3"
179 TestFile "touched"
180 TestFile "HelloWorld.java"
181 TestFile "Empty.class"
182
183
184 #
185 # Classpath on commandline; class output directory
186 #
187
188 rm -f touched
189 rm -f HelloWorld.java
190 rm -Rf classes/Empty.class
191
192 unset CLASSPATH
193 printf "%s\n" "-classpath ${JARCP}" > options4
194 printf "%s\n" "-sourcepath ${SOURCEP}" >> options4
195 printf "%s\n" "-d classes" >> options4
196 printf "%s\n" "${TESTSRC}/Touch.java" >> options4
197
198 ${APTNC} @options4
199
200 echo "Testing case 4"
201 TestFile "touched"
202 TestFile "HelloWorld.java"
203 TestFile "classes/Empty.class"
204
205 #
206 # Classpath on commandline; source output directory
207 #
208
209 rm -f touched
210 rm -Rf src
211 rm -f Empty.class
212
213 unset CLASSPATH
214 printf "%s\n" "-classpath ${JARCP}" > options5
215 printf "%s\n" "-sourcepath ${SOURCEP}" >> options5
216 printf "%s\n" "-s src" >> options5
217 printf "%s\n" "${TESTSRC}/Touch.java" >> options5
218
219 ${APTNC} @options5
220
221 echo "Testing case 5"
222 TestFile "touched"
223 TestFile "src/HelloWorld.java"
224 TestFile "Empty.class"
225
226
227 #
228 # Classpath on commandline; class and source output directory
229 #
230
231 rm -f touched
232 rm -Rf src
233 rm -Rf classes
234
235 unset CLASSPATH
236 printf "%s\n" "-classpath ${JARCP}" > options6
237 printf "%s\n" "-sourcepath ${SOURCEP}" >> options6
238 printf "%s\n" "-d classes" >> options6
239 printf "%s\n" "-s src" >> options6
240 printf "%s\n" "${TESTSRC}/Touch.java" >> options6
241
242 ${APTNC} @options6
243
244 echo "Testing case 6"
245 TestFile "touched"
246 TestFile "src/HelloWorld.java"
247 TestFile "classes/Empty.class"
248
249 #
250 # Classpath appended to bootclasspath; no output directories
251 #
252
253 rm -f touched
254 rm -f HelloWorld.java
255 rm -f Empty.class
256
257 unset CLASSPATH
258 printf "%s\n" "-Xbootclasspath/a:${JARCP}" > options7
259 printf "%s\n" "-classpath /dev/null" >> options7
260 printf "%s\n" "${TESTSRC}/Touch.java" >> options7
261
262 ${APTNC} @options7
263
264 echo "Testing case 7"
265 TestFile "touched"
266 TestFile "HelloWorld.java"
267 TestFile "Empty.class"
268
269 #
270 # Classpath in extdirs; no output directories
271 #
272
273 rm -f touched
274 rm -f HelloWorld.java
275 rm -f Empty.class
276
277 unset CLASSPATH
278 printf "%s\n" "-extdirs ." > options8
279 printf "%s\n" "-classpath ${TOOLSJAR}" >> options8
280 printf "%s\n" "${TESTSRC}/Touch.java" >> options8
281
282 ${APTNC} @options8
283
284 echo "Testing case 8"
285 TestFile "touched"
286 TestFile "HelloWorld.java"
287 TestFile "Empty.class"
288
289 #
290 # Classpath in extdirs, take 2; no output directories
291 #
292
293 rm -f touched
294 rm -f HelloWorld.java
295 rm -f Empty.class
296
297 unset CLASSPATH
298 printf "%s\n" "-Djava.ext.dirs=." > options9
299 printf "%s\n" "-classpath ${TOOLSJAR}" >> options9
300 printf "%s\n" "${TESTSRC}/Touch.java" >> options9
301
302 ${APTNC} @options9
303
304 echo "Testing case 9"
305 TestFile "touched"
306 TestFile "HelloWorld.java"
307 TestFile "Empty.class"
308
309 #
310 # Classpath in -endorseddirs; no output directories
311 #
312
313 rm -f touched
314 rm -f HelloWorld.java
315 rm -f Empty.class
316
317 unset CLASSPATH
318 printf "%s\n" "-endorseddirs ." > options10
319 printf "%s\n" "-classpath ${TOOLSJAR}" >> options10
320 printf "%s\n" "${TESTSRC}/Touch.java" >> options10
321
322 ${APTNC} @options10
323
324 echo "Testing case 10"
325 TestFile "touched"
326 TestFile "HelloWorld.java"
327 TestFile "Empty.class"
328
329 #
330 # Testing apt invocation with no command line options
331 #
332
333 rm -f touched
334 rm -f HelloWorld.java
335 rm -f Empty.class
336
337 unset CLASSPATH
338 CLASSPATH=./phantom/phantom.jar
339 export CLASSPATH
340
341 ${APT}
342
343 echo "Testing empty command line"
344 TestFile "touched"
345 TestFile "HelloWorld.java"
346
347
348 #
349 # Verify apt and JSR 269 annotation processors can be run from same
350 # invocation and both use the output directories
351 #
352
353 rm -f touched
354 rm -f src/HelloWorld.java
355 rm -f src/GoodbyeWorld.java
356 rm -f classes/HelloWorld.class
357 rm -f classes/GoodbyeWorld.class
358
359 unset CLASSPATH
360
361
362 printf "%s\n" "-classpath ./phantom/phantom.jar" > options11
363 printf "%s\n" "-sourcepath ${SOURCEP}" >> options11
364 printf "%s\n" "-factory PhantomTouch " >> options11
365 printf "%s\n" "-s src" >> options11
366 printf "%s\n" "-d classes" >> options11
367 printf "%s\n" "-A" >> options11
368 printf "%s\n" "-Afoo" >> options11
369 printf "%s\n" "-Abar=baz" >> options11
370 printf "%s\n" "-processorpath $TESTCLASSES" >> options11
371 printf "%s\n" "-processor PhantomUpdate" >> options11
372
373 ${APT} @options11
374
375 echo "Testing combined apt and JSR 269 processing"
376 TestFile touched
377 TestFile "src/HelloWorld.java"
378 TestFile "src/GoodbyeWorld.java"
379 TestFile "classes/HelloWorld.class"
380 TestFile "classes/GoodbyeWorld.class"
381
382 #
383 # Verify running with badTouch doesn't exit successfully
384 #
385
386 rm -f ./META-INF/services/com.sun.mirror.apt.AnnotationProcessorFactory
387 cp ${TESTSRC}/servicesBadTouch ./META-INF/services/com.sun.mirror.apt.AnnotationProcessorFactory
388
389 ${JAR} cf0 badTouch.jar Touch*.class META-INF
390
391
392 unset CLASSPATH
393 printf "%s\n" "-classpath ${BADCP}" > optionsBad
394 printf "%s\n" "-sourcepath ${SOURCEP}" >> optionsBad
395 printf "%s\n" "${TESTSRC}/Touch.java" >> optionsBad
396
397 ${APTNC} @optionsBad 2> /dev/null
398
399 RESULT=$?
400
401 case "${RESULT}" in
402 0 )
403 echo "Improper exit zero with bad services information."
404 exit 1
405 ;;
406 esac
407
408
409 exit 0;

mercurial