10
|
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 4908512 5024825 4957203 4993280 4996963 6174696 6177059
|
|
28 |
# @run shell ../verifyVariables.sh
|
|
29 |
# @build Milk MethodAnnotations NestedClassAnnotations StaticFieldAnnotations StaticMethodAnnotations ParameterAnnotations
|
|
30 |
# @run shell apt.sh
|
|
31 |
# @summary test consistency of annotation discovery
|
|
32 |
# @author Joseph D. Darcy
|
|
33 |
|
|
34 |
OS=`uname -s`;
|
|
35 |
case "${OS}" in
|
|
36 |
Windows* | CYGWIN* )
|
|
37 |
SEP=";"
|
|
38 |
;;
|
|
39 |
|
|
40 |
* )
|
|
41 |
SEP=":"
|
|
42 |
;;
|
|
43 |
esac
|
|
44 |
|
|
45 |
# Construct path to apt executable
|
3378
|
46 |
APT="${TESTJAVA}/bin/apt ${TESTTOOLVMOPTS} -XDsuppress-tool-api-removal-message "
|
10
|
47 |
|
|
48 |
printf "%s\n" "-classpath ${TESTCLASSES}" > options
|
|
49 |
printf "%s\n" "-factorypath ./nullap.jar" >> options
|
|
50 |
printf "%s\n" "-sourcepath ${TESTSRC} " >> options
|
|
51 |
printf "%s\n" "-nocompile" >> options
|
|
52 |
printf "%s\n" "-XListAnnotationTypes" >> options
|
|
53 |
|
|
54 |
printf "%s\n" "-classpath ${TESTCLASSES}" > options1
|
|
55 |
printf "%s\n" "-factorypath ./nullap.jar" >> options1
|
|
56 |
printf "%s\n" "-sourcepath ${TESTSRC} " >> options1
|
|
57 |
printf "%s\n" "-nocompile" >> options1
|
|
58 |
printf "%s\n" "-XListAnnotationTypes" >> options1
|
|
59 |
printf "%s\n" "-XclassesAsDecls" >> options1
|
|
60 |
|
3378
|
61 |
|
10
|
62 |
# Construct path to javac executable
|
|
63 |
JAVAC="${TESTJAVA}/bin/javac ${TESTTOOLVMOPTS} -source 1.5 -sourcepath ${TESTSRC} -classpath ${TESTJAVA}/lib/tools.jar -d . "
|
|
64 |
JAR="${TESTJAVA}/bin/jar "
|
|
65 |
|
|
66 |
$JAVAC ${TESTSRC}/NullAPF.java \
|
|
67 |
${TESTSRC}/FreshnessApf.java \
|
|
68 |
${TESTSRC}/TestGetTypeDeclarationApf.java \
|
|
69 |
${TESTSRC}/TestGetPackageApf.java
|
|
70 |
RESULT=$?
|
|
71 |
|
|
72 |
case "${RESULT}" in
|
|
73 |
0 )
|
|
74 |
;;
|
|
75 |
|
|
76 |
* )
|
|
77 |
echo "Compilation failed."
|
|
78 |
exit 1
|
|
79 |
esac
|
|
80 |
|
|
81 |
echo "Making services directory and copying services information."
|
|
82 |
mkdir -p META-INF/services
|
|
83 |
cp ${TESTSRC}/com.sun.mirror.apt.AnnotationProcessorFactory ./META-INF/services
|
|
84 |
$JAR cvf0 nullap.jar NullAPF*.class META-INF
|
|
85 |
|
|
86 |
ANNOTATION_FILES="${TESTSRC}/ClassAnnotations.java \
|
|
87 |
${TESTSRC}/MethodAnnotations.java \
|
|
88 |
${TESTSRC}/NestedClassAnnotations.java \
|
|
89 |
${TESTSRC}/StaticFieldAnnotations.java \
|
|
90 |
${TESTSRC}/StaticMethodAnnotations.java \
|
|
91 |
${TESTSRC}/ParameterAnnotations.java"
|
|
92 |
|
|
93 |
for i in ${ANNOTATION_FILES}
|
|
94 |
do
|
|
95 |
printf "%s\n" "Testing annotations on source file ${i}"
|
|
96 |
${APT} @options ${i} 2> result.txt
|
|
97 |
diff ${TESTSRC}/golden.txt result.txt
|
|
98 |
|
|
99 |
RESULT=$?
|
|
100 |
case "$RESULT" in
|
|
101 |
0 )
|
|
102 |
;;
|
|
103 |
|
|
104 |
* )
|
|
105 |
echo "Unexpected set of annotations on source files found."
|
|
106 |
exit 1
|
|
107 |
esac
|
|
108 |
|
|
109 |
CLASS=`basename ${i} .java`
|
|
110 |
printf "%s\n" "Testing annotations on class file ${CLASS}"
|
|
111 |
${APT} @options1 ${CLASS} 2> result2.txt
|
|
112 |
diff ${TESTSRC}/golden.txt result2.txt
|
|
113 |
|
|
114 |
RESULT=$?
|
|
115 |
case "$RESULT" in
|
|
116 |
0 )
|
|
117 |
;;
|
|
118 |
|
|
119 |
* )
|
|
120 |
echo "Unexpected set of annotations on class files found."
|
|
121 |
exit 1
|
|
122 |
esac
|
|
123 |
done
|
|
124 |
|
|
125 |
# Verify source files are favored over class files
|
|
126 |
|
|
127 |
printf "%s\n" "-factorypath ." > options2
|
|
128 |
printf "%s\n" "-factory FreshnessApf" >> options2
|
|
129 |
printf "%s\n" "-sourcepath ${TESTSRC}" >> options2
|
|
130 |
printf "%s\n" "-classpath ${TESTCLASSES}" >> options2
|
|
131 |
printf "%s\n" "-nocompile" >> options2
|
|
132 |
|
|
133 |
${APT} @options2 ${TESTSRC}/Indirect.java
|
|
134 |
|
|
135 |
RESULT=$?
|
|
136 |
case "$RESULT" in
|
|
137 |
0 )
|
|
138 |
;;
|
|
139 |
|
|
140 |
* )
|
|
141 |
exit 1
|
|
142 |
esac
|
|
143 |
|
|
144 |
# Verify new classes can be loaded by getTypeDeclaration
|
|
145 |
|
|
146 |
printf "%s\n" "-factorypath ." > options3
|
|
147 |
printf "%s\n" "-factory TestGetTypeDeclarationApf" >> options3
|
|
148 |
printf "%s\n" "-sourcepath ${TESTSRC}" >> options3
|
|
149 |
|
|
150 |
# ${APT} @options3
|
|
151 |
|
|
152 |
RESULT=$?
|
|
153 |
case "$RESULT" in
|
|
154 |
0 )
|
|
155 |
;;
|
|
156 |
|
|
157 |
* )
|
|
158 |
exit 1
|
|
159 |
esac
|
|
160 |
|
|
161 |
# Verify packages can be loaded by getPackage
|
|
162 |
|
|
163 |
printf "%s\n" "-factorypath ." > options4
|
|
164 |
printf "%s\n" "-factory TestGetPackageApf" >> options4
|
|
165 |
printf "%s\n" "-sourcepath ${TESTSRC}" >> options4
|
|
166 |
|
|
167 |
${APT} @options4
|
|
168 |
|
|
169 |
RESULT=$?
|
|
170 |
case "$RESULT" in
|
|
171 |
0 )
|
|
172 |
;;
|
|
173 |
|
|
174 |
* )
|
|
175 |
exit 1
|
|
176 |
esac
|
|
177 |
exit 0
|