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
  46 APT="${TESTJAVA}/bin/apt ${TESTTOOLVMOPTS}"
  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 
  61 # Construct path to javac executable
  62 JAVAC="${TESTJAVA}/bin/javac ${TESTTOOLVMOPTS} -source 1.5 -sourcepath ${TESTSRC} -classpath ${TESTJAVA}/lib/tools.jar -d . "
  63 JAR="${TESTJAVA}/bin/jar "
  64 
  65 $JAVAC ${TESTSRC}/NullAPF.java \
  66 ${TESTSRC}/FreshnessApf.java  \
  67 ${TESTSRC}/TestGetTypeDeclarationApf.java \
  68 ${TESTSRC}/TestGetPackageApf.java
  69 RESULT=$?
  70 
  71 case "${RESULT}" in
  72         0  )
  73         ;;
  74 
  75         * )
  76         echo "Compilation failed."
  77         exit 1
  78 esac
  79 
  80 echo "Making services directory and copying services information."
  81 mkdir -p META-INF/services
  82 cp ${TESTSRC}/com.sun.mirror.apt.AnnotationProcessorFactory ./META-INF/services
  83 $JAR cvf0 nullap.jar NullAPF*.class META-INF
  84 
  85 ANNOTATION_FILES="${TESTSRC}/ClassAnnotations.java \
  86 ${TESTSRC}/MethodAnnotations.java \
  87 ${TESTSRC}/NestedClassAnnotations.java \
  88 ${TESTSRC}/StaticFieldAnnotations.java \
  89 ${TESTSRC}/StaticMethodAnnotations.java \
  90 ${TESTSRC}/ParameterAnnotations.java"
  91 
  92 for i in ${ANNOTATION_FILES}
  93 do
  94         printf "%s\n" "Testing annotations on source file ${i}"
  95         ${APT} @options ${i} 2> result.txt
  96         diff ${TESTSRC}/golden.txt result.txt
  97 
  98         RESULT=$?
  99         case "$RESULT" in
 100                 0  )
 101                 ;;
 102 
 103                 * )
 104                 echo "Unexpected set of annotations on source files found."
 105                 exit 1
 106         esac
 107 
 108         CLASS=`basename ${i} .java`
 109         printf "%s\n" "Testing annotations on class file ${CLASS}"
 110         ${APT} @options1 ${CLASS} 2> result2.txt
 111         diff ${TESTSRC}/golden.txt result2.txt
 112 
 113         RESULT=$?
 114         case "$RESULT" in
 115                 0  )
 116                 ;;
 117 
 118                 * )
 119                 echo "Unexpected set of annotations on class files found."
 120                 exit 1
 121         esac
 122 done
 123 
 124 # Verify source files are favored over class files
 125 
 126 printf "%s\n" "-factorypath ."                   > options2
 127 printf "%s\n" "-factory FreshnessApf"           >> options2
 128 printf "%s\n" "-sourcepath ${TESTSRC}"          >> options2
 129 printf "%s\n" "-classpath  ${TESTCLASSES}"      >> options2
 130 printf "%s\n" "-nocompile"                      >> options2
 131 
 132 ${APT} @options2 ${TESTSRC}/Indirect.java
 133 
 134 RESULT=$?
 135 case "$RESULT" in
 136         0  )
 137         ;;
 138 
 139         * )
 140         exit 1
 141 esac
 142 
 143 # Verify new classes can be loaded by getTypeDeclaration
 144 
 145 printf "%s\n" "-factorypath ."                          > options3
 146 printf "%s\n" "-factory TestGetTypeDeclarationApf"      >> options3
 147 printf "%s\n" "-sourcepath ${TESTSRC}"                  >> options3
 148 
 149 # ${APT} @options3
 150 
 151 RESULT=$?
 152 case "$RESULT" in
 153         0  )
 154         ;;
 155 
 156         * )
 157         exit 1
 158 esac
 159 
 160 # Verify packages can be loaded by getPackage
 161 
 162 printf "%s\n" "-factorypath ."                          > options4
 163 printf "%s\n" "-factory TestGetPackageApf"              >> options4
 164 printf "%s\n" "-sourcepath ${TESTSRC}"                  >> options4
 165 
 166 ${APT} @options4
 167 
 168 RESULT=$?
 169 case "$RESULT" in
 170         0  )
 171         ;;
 172 
 173         * )
 174         exit 1
 175 esac
 176 exit 0