duke@1: #!/bin/sh duke@1: duke@1: # duke@1: # Copyright 2004-2007 Sun Microsystems, Inc. All Rights Reserved. duke@1: # DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. duke@1: # duke@1: # This code is free software; you can redistribute it and/or modify it duke@1: # under the terms of the GNU General Public License version 2 only, as duke@1: # published by the Free Software Foundation. duke@1: # duke@1: # This code is distributed in the hope that it will be useful, but WITHOUT duke@1: # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or duke@1: # FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License duke@1: # version 2 for more details (a copy is included in the LICENSE file that duke@1: # accompanied this code). duke@1: # duke@1: # You should have received a copy of the GNU General Public License version duke@1: # 2 along with this work; if not, write to the Free Software Foundation, duke@1: # Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. duke@1: # duke@1: # Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, duke@1: # CA 95054 USA or visit www.sun.com if you need additional information or duke@1: # have any questions. duke@1: # duke@1: duke@1: # @test duke@1: # @bug 4908512 5024825 4957203 4993280 4996963 6174696 6177059 duke@1: # @run shell ../verifyVariables.sh duke@1: # @build Milk MethodAnnotations NestedClassAnnotations StaticFieldAnnotations StaticMethodAnnotations ParameterAnnotations duke@1: # @run shell apt.sh duke@1: # @summary test consistency of annotation discovery duke@1: # @author Joseph D. Darcy duke@1: duke@1: OS=`uname -s`; duke@1: case "${OS}" in duke@1: Windows* | CYGWIN* ) duke@1: SEP=";" duke@1: ;; duke@1: duke@1: * ) duke@1: SEP=":" duke@1: ;; duke@1: esac duke@1: duke@1: # Construct path to apt executable duke@1: APT="${TESTJAVA}/bin/apt ${TESTTOOLVMOPTS}" duke@1: duke@1: printf "%s\n" "-classpath ${TESTCLASSES}" > options duke@1: printf "%s\n" "-factorypath ./nullap.jar" >> options duke@1: printf "%s\n" "-sourcepath ${TESTSRC} " >> options duke@1: printf "%s\n" "-nocompile" >> options duke@1: printf "%s\n" "-XListAnnotationTypes" >> options duke@1: duke@1: printf "%s\n" "-classpath ${TESTCLASSES}" > options1 duke@1: printf "%s\n" "-factorypath ./nullap.jar" >> options1 duke@1: printf "%s\n" "-sourcepath ${TESTSRC} " >> options1 duke@1: printf "%s\n" "-nocompile" >> options1 duke@1: printf "%s\n" "-XListAnnotationTypes" >> options1 duke@1: printf "%s\n" "-XclassesAsDecls" >> options1 duke@1: duke@1: # Construct path to javac executable duke@1: JAVAC="${TESTJAVA}/bin/javac ${TESTTOOLVMOPTS} -source 1.5 -sourcepath ${TESTSRC} -classpath ${TESTJAVA}/lib/tools.jar -d . " duke@1: JAR="${TESTJAVA}/bin/jar " duke@1: duke@1: $JAVAC ${TESTSRC}/NullAPF.java \ duke@1: ${TESTSRC}/FreshnessApf.java \ duke@1: ${TESTSRC}/TestGetTypeDeclarationApf.java \ duke@1: ${TESTSRC}/TestGetPackageApf.java duke@1: RESULT=$? duke@1: duke@1: case "${RESULT}" in duke@1: 0 ) duke@1: ;; duke@1: duke@1: * ) duke@1: echo "Compilation failed." duke@1: exit 1 duke@1: esac duke@1: duke@1: echo "Making services directory and copying services information." duke@1: mkdir -p META-INF/services duke@1: cp ${TESTSRC}/com.sun.mirror.apt.AnnotationProcessorFactory ./META-INF/services duke@1: $JAR cvf0 nullap.jar NullAPF*.class META-INF duke@1: duke@1: ANNOTATION_FILES="${TESTSRC}/ClassAnnotations.java \ duke@1: ${TESTSRC}/MethodAnnotations.java \ duke@1: ${TESTSRC}/NestedClassAnnotations.java \ duke@1: ${TESTSRC}/StaticFieldAnnotations.java \ duke@1: ${TESTSRC}/StaticMethodAnnotations.java \ duke@1: ${TESTSRC}/ParameterAnnotations.java" duke@1: duke@1: for i in ${ANNOTATION_FILES} duke@1: do duke@1: printf "%s\n" "Testing annotations on source file ${i}" duke@1: ${APT} @options ${i} 2> result.txt duke@1: diff ${TESTSRC}/golden.txt result.txt duke@1: duke@1: RESULT=$? duke@1: case "$RESULT" in duke@1: 0 ) duke@1: ;; duke@1: duke@1: * ) duke@1: echo "Unexpected set of annotations on source files found." duke@1: exit 1 duke@1: esac duke@1: duke@1: CLASS=`basename ${i} .java` duke@1: printf "%s\n" "Testing annotations on class file ${CLASS}" duke@1: ${APT} @options1 ${CLASS} 2> result2.txt duke@1: diff ${TESTSRC}/golden.txt result2.txt duke@1: duke@1: RESULT=$? duke@1: case "$RESULT" in duke@1: 0 ) duke@1: ;; duke@1: duke@1: * ) duke@1: echo "Unexpected set of annotations on class files found." duke@1: exit 1 duke@1: esac duke@1: done duke@1: duke@1: # Verify source files are favored over class files duke@1: duke@1: printf "%s\n" "-factorypath ." > options2 duke@1: printf "%s\n" "-factory FreshnessApf" >> options2 duke@1: printf "%s\n" "-sourcepath ${TESTSRC}" >> options2 duke@1: printf "%s\n" "-classpath ${TESTCLASSES}" >> options2 duke@1: printf "%s\n" "-nocompile" >> options2 duke@1: duke@1: ${APT} @options2 ${TESTSRC}/Indirect.java duke@1: duke@1: RESULT=$? duke@1: case "$RESULT" in duke@1: 0 ) duke@1: ;; duke@1: duke@1: * ) duke@1: exit 1 duke@1: esac duke@1: duke@1: # Verify new classes can be loaded by getTypeDeclaration duke@1: duke@1: printf "%s\n" "-factorypath ." > options3 duke@1: printf "%s\n" "-factory TestGetTypeDeclarationApf" >> options3 duke@1: printf "%s\n" "-sourcepath ${TESTSRC}" >> options3 duke@1: duke@1: # ${APT} @options3 duke@1: duke@1: RESULT=$? duke@1: case "$RESULT" in duke@1: 0 ) duke@1: ;; duke@1: duke@1: * ) duke@1: exit 1 duke@1: esac duke@1: duke@1: # Verify packages can be loaded by getPackage duke@1: duke@1: printf "%s\n" "-factorypath ." > options4 duke@1: printf "%s\n" "-factory TestGetPackageApf" >> options4 duke@1: printf "%s\n" "-sourcepath ${TESTSRC}" >> options4 duke@1: duke@1: ${APT} @options4 duke@1: duke@1: RESULT=$? duke@1: case "$RESULT" in duke@1: 0 ) duke@1: ;; duke@1: duke@1: * ) duke@1: exit 1 duke@1: esac duke@1: exit 0