1 #!/bin/sh
   2 
   3 #
   4 # Copyright (c) 2004, 2007, 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 4989093 5009164 5023880 5029482 6206786
  28 # @run shell ../verifyVariables.sh
  29 # @run shell scanner.sh
  30 # @summary Test source order scanner
  31 # @author Joseph D. Darcy
  32 
  33 OS=`uname -s`;
  34 case "${OS}" in
  35         Windows* | CYGWIN* )
  36                 SEP=";"
  37         ;;
  38 
  39         * )
  40         SEP=":"
  41         ;;
  42 esac
  43 
  44 JARCP=scanner.jar
  45 
  46 # Construct path to apt executable
  47 APT="${TESTJAVA}/bin/apt ${TESTTOOLVMOPTS} -nocompile "
  48 
  49 printf "%s\n" "APT = ${APT}"
  50 
  51 # Construct path to javac executable
  52 JAVAC="${TESTJAVA}/bin/javac ${TESTTOOLVMOPTS} -source 1.5 -sourcepath ${TESTSRC} -classpath ${TESTJAVA}/lib/tools.jar -d . "
  53 JAR="${TESTJAVA}/bin/jar "
  54 
  55 ${JAVAC} ${TESTSRC}/Scanner.java ${TESTSRC}/VisitOrder.java ${TESTSRC}/Counter.java ${TESTSRC}/MemberOrderApf.java
  56 RESULT=$?
  57 
  58 case "${RESULT}" in
  59         0  )
  60         ;;
  61 
  62         * )
  63         echo "Compilation failed."
  64         exit 1
  65 esac
  66 
  67 
  68 echo "Making services directory and copying services information."
  69 mkdir -p META-INF/services
  70 
  71 cp ${TESTSRC}/servicesScanner META-INF/services/com.sun.mirror.apt.AnnotationProcessorFactory
  72 
  73 ${JAR} cf0 scanner.jar Scanner*.class META-INF
  74 
  75 # Jar files created; verify options properly present on both initial
  76 # and recursive apt runs
  77 
  78 #---------------------------------------------------------
  79 
  80 unset CLASSPATH
  81 
  82 printf "%s\n" "-classpath ${JARCP}"     > options
  83 printf "%s\n" "-sourcepath ${TESTSRC}" >> options
  84 printf "%s\n" "${TESTSRC}/Order.java"  >> options
  85 
  86 ${APT} @options
  87 
  88 RESULT=$?
  89 case "${RESULT}" in
  90         0  )
  91         ;;      
  92         
  93         * )
  94         echo "Program elements visited in wrong order"
  95         exit 1
  96         ;;
  97 esac
  98 
  99 #---------------------------------------------------------
 100 
 101 # Verify that plain decl' scanner and source order decl' scanner
 102 # record the same number of elements for an enum
 103 
 104 printf "%s\n" "-factorypath ."            > options2
 105 printf "%s\n" "-factory Counter"         >> options2
 106 printf "%s\n" "-sourcepath ${TESTSRC}"   >> options2
 107 printf "%s\n" "${TESTSRC}/TestEnum.java" >> options2
 108 
 109 
 110 $APT @options2
 111 
 112 RESULT=$?
 113 case "${RESULT}" in
 114         0  )
 115         ;;      
 116         
 117         * )
 118         echo "Improper counts"
 119         exit 1
 120         ;;
 121 esac
 122 
 123 #---------------------------------------------------------
 124 
 125 # Verify that members happen to be returned in source order
 126 
 127 printf "%s\n" "-factorypath ."            > options3
 128 printf "%s\n" "-factory MemberOrderApf"  >> options3
 129 printf "%s\n" "-sourcepath ${TESTSRC}"   >> options3
 130 printf "%s\n" "${TESTSRC}/Order.java"    >> options3
 131 
 132 $APT @options3
 133 
 134 RESULT=$?
 135 case "${RESULT}" in
 136         0  )
 137         ;;      
 138         
 139         * )
 140         echo "Improper counts"
 141         exit 1
 142         ;;
 143 esac
 144 
 145 
 146 exit 0;