1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/test/tools/apt/Basics/apt.sh Sat Dec 01 00:00:00 2007 +0000 1.3 @@ -0,0 +1,176 @@ 1.4 +#!/bin/sh 1.5 + 1.6 +# 1.7 +# Copyright 2004-2007 Sun Microsystems, Inc. All Rights Reserved. 1.8 +# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 1.9 +# 1.10 +# This code is free software; you can redistribute it and/or modify it 1.11 +# under the terms of the GNU General Public License version 2 only, as 1.12 +# published by the Free Software Foundation. 1.13 +# 1.14 +# This code is distributed in the hope that it will be useful, but WITHOUT 1.15 +# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 1.16 +# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 1.17 +# version 2 for more details (a copy is included in the LICENSE file that 1.18 +# accompanied this code). 1.19 +# 1.20 +# You should have received a copy of the GNU General Public License version 1.21 +# 2 along with this work; if not, write to the Free Software Foundation, 1.22 +# Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 1.23 +# 1.24 +# Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, 1.25 +# CA 95054 USA or visit www.sun.com if you need additional information or 1.26 +# have any questions. 1.27 +# 1.28 + 1.29 +# @test 1.30 +# @bug 4908512 5024825 4957203 4993280 4996963 6174696 6177059 1.31 +# @run shell ../verifyVariables.sh 1.32 +# @build Milk MethodAnnotations NestedClassAnnotations StaticFieldAnnotations StaticMethodAnnotations ParameterAnnotations 1.33 +# @run shell apt.sh 1.34 +# @summary test consistency of annotation discovery 1.35 +# @author Joseph D. Darcy 1.36 + 1.37 +OS=`uname -s`; 1.38 +case "${OS}" in 1.39 + Windows* | CYGWIN* ) 1.40 + SEP=";" 1.41 + ;; 1.42 + 1.43 + * ) 1.44 + SEP=":" 1.45 + ;; 1.46 +esac 1.47 + 1.48 +# Construct path to apt executable 1.49 +APT="${TESTJAVA}/bin/apt ${TESTTOOLVMOPTS}" 1.50 + 1.51 +printf "%s\n" "-classpath ${TESTCLASSES}" > options 1.52 +printf "%s\n" "-factorypath ./nullap.jar" >> options 1.53 +printf "%s\n" "-sourcepath ${TESTSRC} " >> options 1.54 +printf "%s\n" "-nocompile" >> options 1.55 +printf "%s\n" "-XListAnnotationTypes" >> options 1.56 + 1.57 +printf "%s\n" "-classpath ${TESTCLASSES}" > options1 1.58 +printf "%s\n" "-factorypath ./nullap.jar" >> options1 1.59 +printf "%s\n" "-sourcepath ${TESTSRC} " >> options1 1.60 +printf "%s\n" "-nocompile" >> options1 1.61 +printf "%s\n" "-XListAnnotationTypes" >> options1 1.62 +printf "%s\n" "-XclassesAsDecls" >> options1 1.63 + 1.64 +# Construct path to javac executable 1.65 +JAVAC="${TESTJAVA}/bin/javac ${TESTTOOLVMOPTS} -source 1.5 -sourcepath ${TESTSRC} -classpath ${TESTJAVA}/lib/tools.jar -d . " 1.66 +JAR="${TESTJAVA}/bin/jar " 1.67 + 1.68 +$JAVAC ${TESTSRC}/NullAPF.java \ 1.69 +${TESTSRC}/FreshnessApf.java \ 1.70 +${TESTSRC}/TestGetTypeDeclarationApf.java \ 1.71 +${TESTSRC}/TestGetPackageApf.java 1.72 +RESULT=$? 1.73 + 1.74 +case "${RESULT}" in 1.75 + 0 ) 1.76 + ;; 1.77 + 1.78 + * ) 1.79 + echo "Compilation failed." 1.80 + exit 1 1.81 +esac 1.82 + 1.83 +echo "Making services directory and copying services information." 1.84 +mkdir -p META-INF/services 1.85 +cp ${TESTSRC}/com.sun.mirror.apt.AnnotationProcessorFactory ./META-INF/services 1.86 +$JAR cvf0 nullap.jar NullAPF*.class META-INF 1.87 + 1.88 +ANNOTATION_FILES="${TESTSRC}/ClassAnnotations.java \ 1.89 +${TESTSRC}/MethodAnnotations.java \ 1.90 +${TESTSRC}/NestedClassAnnotations.java \ 1.91 +${TESTSRC}/StaticFieldAnnotations.java \ 1.92 +${TESTSRC}/StaticMethodAnnotations.java \ 1.93 +${TESTSRC}/ParameterAnnotations.java" 1.94 + 1.95 +for i in ${ANNOTATION_FILES} 1.96 +do 1.97 + printf "%s\n" "Testing annotations on source file ${i}" 1.98 + ${APT} @options ${i} 2> result.txt 1.99 + diff ${TESTSRC}/golden.txt result.txt 1.100 + 1.101 + RESULT=$? 1.102 + case "$RESULT" in 1.103 + 0 ) 1.104 + ;; 1.105 + 1.106 + * ) 1.107 + echo "Unexpected set of annotations on source files found." 1.108 + exit 1 1.109 + esac 1.110 + 1.111 + CLASS=`basename ${i} .java` 1.112 + printf "%s\n" "Testing annotations on class file ${CLASS}" 1.113 + ${APT} @options1 ${CLASS} 2> result2.txt 1.114 + diff ${TESTSRC}/golden.txt result2.txt 1.115 + 1.116 + RESULT=$? 1.117 + case "$RESULT" in 1.118 + 0 ) 1.119 + ;; 1.120 + 1.121 + * ) 1.122 + echo "Unexpected set of annotations on class files found." 1.123 + exit 1 1.124 + esac 1.125 +done 1.126 + 1.127 +# Verify source files are favored over class files 1.128 + 1.129 +printf "%s\n" "-factorypath ." > options2 1.130 +printf "%s\n" "-factory FreshnessApf" >> options2 1.131 +printf "%s\n" "-sourcepath ${TESTSRC}" >> options2 1.132 +printf "%s\n" "-classpath ${TESTCLASSES}" >> options2 1.133 +printf "%s\n" "-nocompile" >> options2 1.134 + 1.135 +${APT} @options2 ${TESTSRC}/Indirect.java 1.136 + 1.137 +RESULT=$? 1.138 +case "$RESULT" in 1.139 + 0 ) 1.140 + ;; 1.141 + 1.142 + * ) 1.143 + exit 1 1.144 +esac 1.145 + 1.146 +# Verify new classes can be loaded by getTypeDeclaration 1.147 + 1.148 +printf "%s\n" "-factorypath ." > options3 1.149 +printf "%s\n" "-factory TestGetTypeDeclarationApf" >> options3 1.150 +printf "%s\n" "-sourcepath ${TESTSRC}" >> options3 1.151 + 1.152 +# ${APT} @options3 1.153 + 1.154 +RESULT=$? 1.155 +case "$RESULT" in 1.156 + 0 ) 1.157 + ;; 1.158 + 1.159 + * ) 1.160 + exit 1 1.161 +esac 1.162 + 1.163 +# Verify packages can be loaded by getPackage 1.164 + 1.165 +printf "%s\n" "-factorypath ." > options4 1.166 +printf "%s\n" "-factory TestGetPackageApf" >> options4 1.167 +printf "%s\n" "-sourcepath ${TESTSRC}" >> options4 1.168 + 1.169 +${APT} @options4 1.170 + 1.171 +RESULT=$? 1.172 +case "$RESULT" in 1.173 + 0 ) 1.174 + ;; 1.175 + 1.176 + * ) 1.177 + exit 1 1.178 +esac 1.179 +exit 0