test/tools/apt/Discovery/discovery.sh

changeset 1
9a66ca7c79fa
child 149
2eec479619d8
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/test/tools/apt/Discovery/discovery.sh	Sat Dec 01 00:00:00 2007 +0000
     1.3 @@ -0,0 +1,409 @@
     1.4 +#!/bin/sh
     1.5 +
     1.6 +#
     1.7 +# Copyright 1999-2002 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 4984412 4985113 4908512 4990905 4998007 4998218 5002340 5023882 6370261 6363481
    1.31 +# @run shell ../verifyVariables.sh
    1.32 +# @compile PhantomUpdate.java
    1.33 +# @run shell discovery.sh
    1.34 +# @summary Test consistency of annotation discovery
    1.35 +# @author Joseph D. Darcy
    1.36 +
    1.37 +
    1.38 +# If the file does not exist, exit with an error
    1.39 +TestFile() {
    1.40 +	if [ ! -f ${1} ]; then
    1.41 +		printf "%s\n" "File ${1} not found."
    1.42 +		exit 1
    1.43 +	fi
    1.44 +}
    1.45 +
    1.46 +OS=`uname -s`;
    1.47 +case "${OS}" in
    1.48 +        Windows* | CYGWIN* )
    1.49 +                SEP=";"
    1.50 +        ;;
    1.51 +
    1.52 +	* )
    1.53 +	SEP=":"
    1.54 +	;;
    1.55 +esac
    1.56 +
    1.57 +TOOLSJAR=${TESTJAVA}/lib/tools.jar
    1.58 +
    1.59 +OLDCP=${CLASSPATH}
    1.60 +
    1.61 +JARCP=tweedle.jar${SEP}touch.jar${SEP}${TOOLSJAR}
    1.62 +SOURCEP=${TESTSRC}
    1.63 +FULLCP=${JARCP}${SEP}${SOURCEP}
    1.64 +BADCP=tweedle.jar${SEP}badTouch.jar${SEP}${TOOLSJAR}
    1.65 +
    1.66 +# Construct path to apt executable
    1.67 +APT="${TESTJAVA}/bin/apt ${TESTTOOLVMOPTS} "
    1.68 +
    1.69 +
    1.70 +# Construct path to apt executable, no compilation
    1.71 +APTNC="${APT} -nocompile "
    1.72 +
    1.73 +
    1.74 +printf "%s\n" "APT = ${APT}"
    1.75 +
    1.76 +# Construct path to javac executable
    1.77 +JAVAC="${TESTJAVA}/bin/javac ${TESTTOOLVMOPTS} -source 1.5 -sourcepath ${TESTSRC} -classpath ${TOOLSJAR} -d . "
    1.78 +JAR="${TESTJAVA}/bin/jar "
    1.79 +
    1.80 +$JAVAC ${TESTSRC}/Dee.java ${TESTSRC}/Dum.java ${TESTSRC}/Touch.java ${TESTSRC}/PhantomTouch.java ${TESTSRC}/Empty.java
    1.81 +RESULT=$?
    1.82 +
    1.83 +case "${RESULT}" in
    1.84 +        0  )
    1.85 +        ;;
    1.86 +
    1.87 +        * )
    1.88 +        echo "Compilation failed."
    1.89 +        exit 1
    1.90 +esac
    1.91 +
    1.92 +mv Empty.class Empty.clazz
    1.93 +
    1.94 +echo "Making services directory and copying services information."
    1.95 +mkdir -p META-INF/services
    1.96 +mkdir -p phantom
    1.97 +
    1.98 +rm -f touch.jar
    1.99 +rm -f badTouch.jar
   1.100 +
   1.101 +cp ${TESTSRC}/servicesTweedle META-INF/services/com.sun.mirror.apt.AnnotationProcessorFactory
   1.102 +
   1.103 +${JAR} cf0 tweedle.jar Dee*.class Dum*.class META-INF
   1.104 +
   1.105 +rm -f META-INF/services/com.sun.mirror.apt.AnnotationProcessorFactory
   1.106 +cp ${TESTSRC}/servicesTouch ./META-INF/services/com.sun.mirror.apt.AnnotationProcessorFactory
   1.107 +
   1.108 +${JAR} cf0 touch.jar Touch*.class META-INF
   1.109 +
   1.110 +rm -f META-INF/services/com.sun.mirror.apt.AnnotationProcessorFactory
   1.111 +cp ${TESTSRC}/servicesPhantomTouch ./META-INF/services/com.sun.mirror.apt.AnnotationProcessorFactory
   1.112 +
   1.113 +${JAR} cf0 phantom/phantom.jar PhantomTouch*.class META-INF
   1.114 +
   1.115 +
   1.116 +
   1.117 +# Jar files created; verify right output file is touched
   1.118 +
   1.119 +#---------------------------------------------------------
   1.120 +
   1.121 +# Test different combinations of classpath, sourcepath, and
   1.122 +# destination directories
   1.123 +
   1.124 +
   1.125 +#
   1.126 +# Classpath on commandline; no output directories
   1.127 +#
   1.128 +
   1.129 +rm -f touched 
   1.130 +rm -f HelloWorld.java
   1.131 +rm -f Empty.class
   1.132 +
   1.133 +unset CLASSPATH
   1.134 +printf "%s\n" "-classpath ${JARCP}"     > options1
   1.135 +printf "%s\n" "-sourcepath ${SOURCEP}" >> options1
   1.136 +printf "%s\n" "${TESTSRC}/Touch.java"  >> options1
   1.137 +
   1.138 +${APTNC} @options1
   1.139 +
   1.140 +echo "Testing case 1"
   1.141 +TestFile "touched"
   1.142 +TestFile "HelloWorld.java"
   1.143 +TestFile "Empty.class"
   1.144 +
   1.145 +#
   1.146 +# Class path set through environment variable
   1.147 +#
   1.148 +
   1.149 +rm -f touched
   1.150 +rm -f HelloWorld.java
   1.151 +rm -f Empty.class
   1.152 +
   1.153 +unset CLASSPATH
   1.154 +CLASSPATH=${JARCP}
   1.155 +export CLASSPATH
   1.156 +printf "%s\n" "-sourcepath ${SOURCEP}" > options2
   1.157 +printf "%s\n" "${TESTSRC}/Touch.java" >> options2
   1.158 +
   1.159 +${APTNC} @options2
   1.160 +
   1.161 +echo "Testing case 2"
   1.162 +TestFile "touched"
   1.163 +TestFile "HelloWorld.java"
   1.164 +TestFile "Empty.class"
   1.165 +
   1.166 +#
   1.167 +# No explicit source path
   1.168 +#
   1.169 +
   1.170 +rm -f touched
   1.171 +rm -f HelloWorld.java
   1.172 +rm -f Empty.class
   1.173 +
   1.174 +unset CLASSPATH
   1.175 +CLASSPATH=${FULLCP}
   1.176 +export CLASSPATH
   1.177 +printf "%s\n" "${TESTSRC}/Touch.java"  > options3
   1.178 +
   1.179 +${APTNC} @options3
   1.180 +
   1.181 +echo "Testing case 3"
   1.182 +TestFile "touched"
   1.183 +TestFile "HelloWorld.java"
   1.184 +TestFile "Empty.class"
   1.185 +
   1.186 +
   1.187 +#
   1.188 +# Classpath on commandline; class output directory
   1.189 +#
   1.190 +
   1.191 +rm -f touched
   1.192 +rm -f HelloWorld.java
   1.193 +rm -Rf classes/Empty.class
   1.194 +
   1.195 +unset CLASSPATH
   1.196 +printf "%s\n" "-classpath ${JARCP}"     > options4
   1.197 +printf "%s\n" "-sourcepath ${SOURCEP}" >> options4
   1.198 +printf "%s\n" "-d classes"             >> options4
   1.199 +printf "%s\n" "${TESTSRC}/Touch.java"  >> options4
   1.200 +
   1.201 +${APTNC} @options4
   1.202 +
   1.203 +echo "Testing case 4"
   1.204 +TestFile "touched"
   1.205 +TestFile "HelloWorld.java"
   1.206 +TestFile "classes/Empty.class"
   1.207 +
   1.208 +#
   1.209 +# Classpath on commandline; source output directory
   1.210 +#
   1.211 +
   1.212 +rm -f touched
   1.213 +rm -Rf src
   1.214 +rm -f Empty.class
   1.215 +
   1.216 +unset CLASSPATH
   1.217 +printf "%s\n" "-classpath ${JARCP}"     > options5
   1.218 +printf "%s\n" "-sourcepath ${SOURCEP}" >> options5
   1.219 +printf "%s\n" "-s src"                 >> options5
   1.220 +printf "%s\n" "${TESTSRC}/Touch.java"  >> options5
   1.221 +
   1.222 +${APTNC} @options5
   1.223 +
   1.224 +echo "Testing case 5"
   1.225 +TestFile "touched"
   1.226 +TestFile "src/HelloWorld.java"
   1.227 +TestFile "Empty.class"
   1.228 +
   1.229 +
   1.230 +#
   1.231 +# Classpath on commandline; class and source output directory
   1.232 +#
   1.233 +
   1.234 +rm -f touched
   1.235 +rm -Rf src
   1.236 +rm -Rf classes
   1.237 +
   1.238 +unset CLASSPATH
   1.239 +printf "%s\n" "-classpath ${JARCP}"     > options6
   1.240 +printf "%s\n" "-sourcepath ${SOURCEP}" >> options6
   1.241 +printf "%s\n" "-d classes"             >> options6
   1.242 +printf "%s\n" "-s src"                 >> options6
   1.243 +printf "%s\n" "${TESTSRC}/Touch.java"  >> options6
   1.244 +
   1.245 +${APTNC} @options6
   1.246 +
   1.247 +echo "Testing case 6"
   1.248 +TestFile "touched"
   1.249 +TestFile "src/HelloWorld.java"
   1.250 +TestFile "classes/Empty.class"
   1.251 +
   1.252 +#
   1.253 +# Classpath appended to bootclasspath; no output directories
   1.254 +#
   1.255 +
   1.256 +rm -f touched
   1.257 +rm -f HelloWorld.java
   1.258 +rm -f Empty.class
   1.259 +
   1.260 +unset CLASSPATH
   1.261 +printf "%s\n" "-Xbootclasspath/a:${JARCP}" > options7
   1.262 +printf "%s\n" "-classpath /dev/null"      >> options7
   1.263 +printf "%s\n" "${TESTSRC}/Touch.java"     >> options7
   1.264 +
   1.265 +${APTNC} @options7
   1.266 +
   1.267 +echo "Testing case 7"
   1.268 +TestFile "touched"
   1.269 +TestFile "HelloWorld.java"
   1.270 +TestFile "Empty.class"
   1.271 +
   1.272 +#
   1.273 +# Classpath in extdirs; no output directories
   1.274 +#
   1.275 +
   1.276 +rm -f touched
   1.277 +rm -f HelloWorld.java
   1.278 +rm -f Empty.class
   1.279 +
   1.280 +unset CLASSPATH
   1.281 +printf "%s\n" "-extdirs ."              > options8
   1.282 +printf "%s\n" "-classpath ${TOOLSJAR}" >> options8
   1.283 +printf "%s\n" "${TESTSRC}/Touch.java"  >> options8
   1.284 +
   1.285 +${APTNC} @options8
   1.286 +
   1.287 +echo "Testing case 8"
   1.288 +TestFile "touched"
   1.289 +TestFile "HelloWorld.java"
   1.290 +TestFile "Empty.class"
   1.291 +
   1.292 +#
   1.293 +# Classpath in extdirs, take 2; no output directories
   1.294 +#
   1.295 +
   1.296 +rm -f touched
   1.297 +rm -f HelloWorld.java
   1.298 +rm -f Empty.class
   1.299 +
   1.300 +unset CLASSPATH
   1.301 +printf "%s\n" "-Djava.ext.dirs=."        > options9
   1.302 +printf "%s\n" "-classpath ${TOOLSJAR}"  >> options9
   1.303 +printf "%s\n" "${TESTSRC}/Touch.java"   >> options9
   1.304 +
   1.305 +${APTNC} @options9
   1.306 +
   1.307 +echo "Testing case 9"
   1.308 +TestFile "touched"
   1.309 +TestFile "HelloWorld.java"
   1.310 +TestFile "Empty.class"
   1.311 +
   1.312 +#
   1.313 +# Classpath in -endorseddirs; no output directories
   1.314 +#
   1.315 +
   1.316 +rm -f touched
   1.317 +rm -f HelloWorld.java
   1.318 +rm -f Empty.class
   1.319 +
   1.320 +unset CLASSPATH
   1.321 +printf "%s\n" "-endorseddirs ."          > options10
   1.322 +printf "%s\n" "-classpath ${TOOLSJAR}"  >> options10
   1.323 +printf "%s\n" "${TESTSRC}/Touch.java"   >> options10
   1.324 +
   1.325 +${APTNC} @options10
   1.326 +
   1.327 +echo "Testing case 10"
   1.328 +TestFile "touched"
   1.329 +TestFile "HelloWorld.java"
   1.330 +TestFile "Empty.class"
   1.331 +
   1.332 +#
   1.333 +# Testing apt invocation with no command line options
   1.334 +#
   1.335 +
   1.336 +rm -f touched
   1.337 +rm -f HelloWorld.java
   1.338 +rm -f Empty.class
   1.339 +
   1.340 +unset CLASSPATH
   1.341 +CLASSPATH=./phantom/phantom.jar
   1.342 +export CLASSPATH
   1.343 +
   1.344 +${APT}
   1.345 +
   1.346 +echo "Testing empty command line"
   1.347 +TestFile "touched"
   1.348 +TestFile "HelloWorld.java"
   1.349 +
   1.350 +
   1.351 +#
   1.352 +# Verify apt and JSR 269 annotation processors can be run from same
   1.353 +# invocation and both use the output directories
   1.354 +#
   1.355 +
   1.356 +rm -f touched
   1.357 +rm -f src/HelloWorld.java
   1.358 +rm -f src/GoodbyeWorld.java
   1.359 +rm -f classes/HelloWorld.class
   1.360 +rm -f classes/GoodbyeWorld.class
   1.361 +
   1.362 +unset CLASSPATH
   1.363 +
   1.364 +
   1.365 +printf "%s\n" "-classpath ./phantom/phantom.jar" > options11
   1.366 +printf "%s\n" "-sourcepath ${SOURCEP}"          >> options11
   1.367 +printf "%s\n" "-factory PhantomTouch "          >> options11
   1.368 +printf "%s\n" "-s src"                          >> options11
   1.369 +printf "%s\n" "-d classes"                      >> options11
   1.370 +printf "%s\n" "-A"             	                >> options11
   1.371 +printf "%s\n" "-Afoo"          	                >> options11
   1.372 +printf "%s\n" "-Abar=baz"      	                >> options11
   1.373 +printf "%s\n" "-processorpath $TESTCLASSES"     >> options11
   1.374 +printf "%s\n" "-processor PhantomUpdate"        >> options11
   1.375 +
   1.376 +${APT} @options11
   1.377 +
   1.378 +echo "Testing combined apt and JSR 269 processing"
   1.379 +TestFile touched
   1.380 +TestFile "src/HelloWorld.java"
   1.381 +TestFile "src/GoodbyeWorld.java"
   1.382 +TestFile "classes/HelloWorld.class"
   1.383 +TestFile "classes/GoodbyeWorld.class"
   1.384 +
   1.385 +#
   1.386 +# Verify running with badTouch doesn't exit successfully
   1.387 +#
   1.388 +
   1.389 +rm -f ./META-INF/services/com.sun.mirror.apt.AnnotationProcessorFactory
   1.390 +cp ${TESTSRC}/servicesBadTouch ./META-INF/services/com.sun.mirror.apt.AnnotationProcessorFactory
   1.391 +
   1.392 +${JAR} cf0 badTouch.jar Touch*.class META-INF
   1.393 +
   1.394 +
   1.395 +unset CLASSPATH
   1.396 +printf "%s\n" "-classpath ${BADCP}"     > optionsBad
   1.397 +printf "%s\n" "-sourcepath ${SOURCEP}" >> optionsBad
   1.398 +printf "%s\n" "${TESTSRC}/Touch.java"  >> optionsBad
   1.399 +
   1.400 +${APTNC} @optionsBad 2> /dev/null
   1.401 +
   1.402 +RESULT=$?
   1.403 +
   1.404 +case "${RESULT}" in
   1.405 +        0  )
   1.406 +	echo "Improper exit zero with bad services information."
   1.407 +	exit 1
   1.408 +        ;;
   1.409 +esac
   1.410 +
   1.411 +
   1.412 +exit 0;

mercurial