test/tools/apt/Basics/apt.sh

Print this page


   1 #!/bin/sh
   2 
   3 #
   4 # Copyright (c) 2004, 2009, Oracle and/or its affiliates. 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 Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22 # or visit www.oracle.com if you need additional information or have any
  23 # 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         CYGWIN* )
  37                 DIFFOPTS="--strip-trailing-cr"
  38         ;;
  39 
  40         * )
  41         ;;
  42 esac
  43 
  44 # Construct path to apt executable
  45 APT="${TESTJAVA}/bin/apt ${TESTTOOLVMOPTS} -XDsuppress-tool-api-removal-message "
  46 
  47 printf "%s\n" "-classpath ${TESTCLASSES}"                    > options
  48 printf "%s\n" "-factorypath ./nullap.jar"                   >> options
  49 printf "%s\n" "-sourcepath ${TESTSRC} "                     >> options
  50 printf "%s\n" "-nocompile"                                  >> options
  51 printf "%s\n" "-XListAnnotationTypes"                       >> options
  52 
  53 printf "%s\n" "-classpath ${TESTCLASSES}"                    > options1
  54 printf "%s\n" "-factorypath ./nullap.jar"                   >> options1
  55 printf "%s\n" "-sourcepath ${TESTSRC} "                     >> options1
  56 printf "%s\n" "-nocompile"                                  >> options1
  57 printf "%s\n" "-XListAnnotationTypes"                       >> options1
  58 printf "%s\n" "-XclassesAsDecls"                            >> options1
  59 
  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 ${DIFFOPTS} ${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 ${DIFFOPTS} ${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
   1 #!/bin/sh
   2 
   3 #
   4 # Copyright (c) 2004, 2012, Oracle and/or its affiliates. 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 Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22 # or visit www.oracle.com if you need additional information or have any
  23 # questions.
  24 #
  25 
  26 # @test
  27 # @bug 4908512 5024825 4957203 4993280 4996963 6174696 6177059 7041249
  28 # @run shell ../verifyVariables.sh

  29 # @run shell apt.sh
  30 # @summary Make sure apt is removed and doesn't come back
  31 # @author Joseph D. Darcy
  32 
  33 OS=`uname -s`;
  34 case "${OS}" in
  35         CYGWIN* )
  36                 DIFFOPTS="--strip-trailing-cr"
  37         ;;
  38 
  39         * )
  40         ;;
  41 esac
  42 
  43 # Verify apt executable does not exist
  44 test -e "${TESTJAVA}/bin/apt"
  45 






















  46 RESULT=$?
  47 
  48 case "${RESULT}" in
  49         0  )
  50         echo "apt executable should not exist."



  51         exit 1























  52         ;;
  53 
  54         * )

































  55         ;;



  56 esac
  57 

  58 
  59 # Construct path to javac executable
  60 JAVAC="${TESTJAVA}/bin/javac ${TESTTOOLVMOPTS} -source 1.5 -sourcepath ${TESTSRC} -classpath ${TESTJAVA}/lib/tools.jar -d . "



  61 
  62 $JAVAC ${TESTSRC}/NullAPF.java
  63 RESULT=$?



  64 
  65 case "${RESULT}" in













  66         0  )
  67         echo "Compilation of apt-using source passed improperly."
  68         exit 1
  69         ;;
  70 
  71         * )
  72         ;;
  73 esac