test/tools/apt/Discovery/discovery.sh

Tue, 07 Oct 2008 15:39:19 -0700

author
jjg
date
Tue, 07 Oct 2008 15:39:19 -0700
changeset 132
a54ef8459576
parent 1
9a66ca7c79fa
child 149
2eec479619d8
permissions
-rw-r--r--

6749967: regression tests for apt should be same-vm friendly
Reviewed-by: darcy

     1 #!/bin/sh
     3 #
     4 # Copyright 1999-2002 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 #
    26 # @test
    27 # @bug 4984412 4985113 4908512 4990905 4998007 4998218 5002340 5023882 6370261 6363481
    28 # @run shell ../verifyVariables.sh
    29 # @compile PhantomUpdate.java
    30 # @run shell discovery.sh
    31 # @summary Test consistency of annotation discovery
    32 # @author Joseph D. Darcy
    35 # If the file does not exist, exit with an error
    36 TestFile() {
    37 	if [ ! -f ${1} ]; then
    38 		printf "%s\n" "File ${1} not found."
    39 		exit 1
    40 	fi
    41 }
    43 OS=`uname -s`;
    44 case "${OS}" in
    45         Windows* | CYGWIN* )
    46                 SEP=";"
    47         ;;
    49 	* )
    50 	SEP=":"
    51 	;;
    52 esac
    54 TOOLSJAR=${TESTJAVA}/lib/tools.jar
    56 OLDCP=${CLASSPATH}
    58 JARCP=tweedle.jar${SEP}touch.jar${SEP}${TOOLSJAR}
    59 SOURCEP=${TESTSRC}
    60 FULLCP=${JARCP}${SEP}${SOURCEP}
    61 BADCP=tweedle.jar${SEP}badTouch.jar${SEP}${TOOLSJAR}
    63 # Construct path to apt executable
    64 APT="${TESTJAVA}/bin/apt ${TESTTOOLVMOPTS} "
    67 # Construct path to apt executable, no compilation
    68 APTNC="${APT} -nocompile "
    71 printf "%s\n" "APT = ${APT}"
    73 # Construct path to javac executable
    74 JAVAC="${TESTJAVA}/bin/javac ${TESTTOOLVMOPTS} -source 1.5 -sourcepath ${TESTSRC} -classpath ${TOOLSJAR} -d . "
    75 JAR="${TESTJAVA}/bin/jar "
    77 $JAVAC ${TESTSRC}/Dee.java ${TESTSRC}/Dum.java ${TESTSRC}/Touch.java ${TESTSRC}/PhantomTouch.java ${TESTSRC}/Empty.java
    78 RESULT=$?
    80 case "${RESULT}" in
    81         0  )
    82         ;;
    84         * )
    85         echo "Compilation failed."
    86         exit 1
    87 esac
    89 mv Empty.class Empty.clazz
    91 echo "Making services directory and copying services information."
    92 mkdir -p META-INF/services
    93 mkdir -p phantom
    95 rm -f touch.jar
    96 rm -f badTouch.jar
    98 cp ${TESTSRC}/servicesTweedle META-INF/services/com.sun.mirror.apt.AnnotationProcessorFactory
   100 ${JAR} cf0 tweedle.jar Dee*.class Dum*.class META-INF
   102 rm -f META-INF/services/com.sun.mirror.apt.AnnotationProcessorFactory
   103 cp ${TESTSRC}/servicesTouch ./META-INF/services/com.sun.mirror.apt.AnnotationProcessorFactory
   105 ${JAR} cf0 touch.jar Touch*.class META-INF
   107 rm -f META-INF/services/com.sun.mirror.apt.AnnotationProcessorFactory
   108 cp ${TESTSRC}/servicesPhantomTouch ./META-INF/services/com.sun.mirror.apt.AnnotationProcessorFactory
   110 ${JAR} cf0 phantom/phantom.jar PhantomTouch*.class META-INF
   114 # Jar files created; verify right output file is touched
   116 #---------------------------------------------------------
   118 # Test different combinations of classpath, sourcepath, and
   119 # destination directories
   122 #
   123 # Classpath on commandline; no output directories
   124 #
   126 rm -f touched 
   127 rm -f HelloWorld.java
   128 rm -f Empty.class
   130 unset CLASSPATH
   131 printf "%s\n" "-classpath ${JARCP}"     > options1
   132 printf "%s\n" "-sourcepath ${SOURCEP}" >> options1
   133 printf "%s\n" "${TESTSRC}/Touch.java"  >> options1
   135 ${APTNC} @options1
   137 echo "Testing case 1"
   138 TestFile "touched"
   139 TestFile "HelloWorld.java"
   140 TestFile "Empty.class"
   142 #
   143 # Class path set through environment variable
   144 #
   146 rm -f touched
   147 rm -f HelloWorld.java
   148 rm -f Empty.class
   150 unset CLASSPATH
   151 CLASSPATH=${JARCP}
   152 export CLASSPATH
   153 printf "%s\n" "-sourcepath ${SOURCEP}" > options2
   154 printf "%s\n" "${TESTSRC}/Touch.java" >> options2
   156 ${APTNC} @options2
   158 echo "Testing case 2"
   159 TestFile "touched"
   160 TestFile "HelloWorld.java"
   161 TestFile "Empty.class"
   163 #
   164 # No explicit source path
   165 #
   167 rm -f touched
   168 rm -f HelloWorld.java
   169 rm -f Empty.class
   171 unset CLASSPATH
   172 CLASSPATH=${FULLCP}
   173 export CLASSPATH
   174 printf "%s\n" "${TESTSRC}/Touch.java"  > options3
   176 ${APTNC} @options3
   178 echo "Testing case 3"
   179 TestFile "touched"
   180 TestFile "HelloWorld.java"
   181 TestFile "Empty.class"
   184 #
   185 # Classpath on commandline; class output directory
   186 #
   188 rm -f touched
   189 rm -f HelloWorld.java
   190 rm -Rf classes/Empty.class
   192 unset CLASSPATH
   193 printf "%s\n" "-classpath ${JARCP}"     > options4
   194 printf "%s\n" "-sourcepath ${SOURCEP}" >> options4
   195 printf "%s\n" "-d classes"             >> options4
   196 printf "%s\n" "${TESTSRC}/Touch.java"  >> options4
   198 ${APTNC} @options4
   200 echo "Testing case 4"
   201 TestFile "touched"
   202 TestFile "HelloWorld.java"
   203 TestFile "classes/Empty.class"
   205 #
   206 # Classpath on commandline; source output directory
   207 #
   209 rm -f touched
   210 rm -Rf src
   211 rm -f Empty.class
   213 unset CLASSPATH
   214 printf "%s\n" "-classpath ${JARCP}"     > options5
   215 printf "%s\n" "-sourcepath ${SOURCEP}" >> options5
   216 printf "%s\n" "-s src"                 >> options5
   217 printf "%s\n" "${TESTSRC}/Touch.java"  >> options5
   219 ${APTNC} @options5
   221 echo "Testing case 5"
   222 TestFile "touched"
   223 TestFile "src/HelloWorld.java"
   224 TestFile "Empty.class"
   227 #
   228 # Classpath on commandline; class and source output directory
   229 #
   231 rm -f touched
   232 rm -Rf src
   233 rm -Rf classes
   235 unset CLASSPATH
   236 printf "%s\n" "-classpath ${JARCP}"     > options6
   237 printf "%s\n" "-sourcepath ${SOURCEP}" >> options6
   238 printf "%s\n" "-d classes"             >> options6
   239 printf "%s\n" "-s src"                 >> options6
   240 printf "%s\n" "${TESTSRC}/Touch.java"  >> options6
   242 ${APTNC} @options6
   244 echo "Testing case 6"
   245 TestFile "touched"
   246 TestFile "src/HelloWorld.java"
   247 TestFile "classes/Empty.class"
   249 #
   250 # Classpath appended to bootclasspath; no output directories
   251 #
   253 rm -f touched
   254 rm -f HelloWorld.java
   255 rm -f Empty.class
   257 unset CLASSPATH
   258 printf "%s\n" "-Xbootclasspath/a:${JARCP}" > options7
   259 printf "%s\n" "-classpath /dev/null"      >> options7
   260 printf "%s\n" "${TESTSRC}/Touch.java"     >> options7
   262 ${APTNC} @options7
   264 echo "Testing case 7"
   265 TestFile "touched"
   266 TestFile "HelloWorld.java"
   267 TestFile "Empty.class"
   269 #
   270 # Classpath in extdirs; no output directories
   271 #
   273 rm -f touched
   274 rm -f HelloWorld.java
   275 rm -f Empty.class
   277 unset CLASSPATH
   278 printf "%s\n" "-extdirs ."              > options8
   279 printf "%s\n" "-classpath ${TOOLSJAR}" >> options8
   280 printf "%s\n" "${TESTSRC}/Touch.java"  >> options8
   282 ${APTNC} @options8
   284 echo "Testing case 8"
   285 TestFile "touched"
   286 TestFile "HelloWorld.java"
   287 TestFile "Empty.class"
   289 #
   290 # Classpath in extdirs, take 2; no output directories
   291 #
   293 rm -f touched
   294 rm -f HelloWorld.java
   295 rm -f Empty.class
   297 unset CLASSPATH
   298 printf "%s\n" "-Djava.ext.dirs=."        > options9
   299 printf "%s\n" "-classpath ${TOOLSJAR}"  >> options9
   300 printf "%s\n" "${TESTSRC}/Touch.java"   >> options9
   302 ${APTNC} @options9
   304 echo "Testing case 9"
   305 TestFile "touched"
   306 TestFile "HelloWorld.java"
   307 TestFile "Empty.class"
   309 #
   310 # Classpath in -endorseddirs; no output directories
   311 #
   313 rm -f touched
   314 rm -f HelloWorld.java
   315 rm -f Empty.class
   317 unset CLASSPATH
   318 printf "%s\n" "-endorseddirs ."          > options10
   319 printf "%s\n" "-classpath ${TOOLSJAR}"  >> options10
   320 printf "%s\n" "${TESTSRC}/Touch.java"   >> options10
   322 ${APTNC} @options10
   324 echo "Testing case 10"
   325 TestFile "touched"
   326 TestFile "HelloWorld.java"
   327 TestFile "Empty.class"
   329 #
   330 # Testing apt invocation with no command line options
   331 #
   333 rm -f touched
   334 rm -f HelloWorld.java
   335 rm -f Empty.class
   337 unset CLASSPATH
   338 CLASSPATH=./phantom/phantom.jar
   339 export CLASSPATH
   341 ${APT}
   343 echo "Testing empty command line"
   344 TestFile "touched"
   345 TestFile "HelloWorld.java"
   348 #
   349 # Verify apt and JSR 269 annotation processors can be run from same
   350 # invocation and both use the output directories
   351 #
   353 rm -f touched
   354 rm -f src/HelloWorld.java
   355 rm -f src/GoodbyeWorld.java
   356 rm -f classes/HelloWorld.class
   357 rm -f classes/GoodbyeWorld.class
   359 unset CLASSPATH
   362 printf "%s\n" "-classpath ./phantom/phantom.jar" > options11
   363 printf "%s\n" "-sourcepath ${SOURCEP}"          >> options11
   364 printf "%s\n" "-factory PhantomTouch "          >> options11
   365 printf "%s\n" "-s src"                          >> options11
   366 printf "%s\n" "-d classes"                      >> options11
   367 printf "%s\n" "-A"             	                >> options11
   368 printf "%s\n" "-Afoo"          	                >> options11
   369 printf "%s\n" "-Abar=baz"      	                >> options11
   370 printf "%s\n" "-processorpath $TESTCLASSES"     >> options11
   371 printf "%s\n" "-processor PhantomUpdate"        >> options11
   373 ${APT} @options11
   375 echo "Testing combined apt and JSR 269 processing"
   376 TestFile touched
   377 TestFile "src/HelloWorld.java"
   378 TestFile "src/GoodbyeWorld.java"
   379 TestFile "classes/HelloWorld.class"
   380 TestFile "classes/GoodbyeWorld.class"
   382 #
   383 # Verify running with badTouch doesn't exit successfully
   384 #
   386 rm -f ./META-INF/services/com.sun.mirror.apt.AnnotationProcessorFactory
   387 cp ${TESTSRC}/servicesBadTouch ./META-INF/services/com.sun.mirror.apt.AnnotationProcessorFactory
   389 ${JAR} cf0 badTouch.jar Touch*.class META-INF
   392 unset CLASSPATH
   393 printf "%s\n" "-classpath ${BADCP}"     > optionsBad
   394 printf "%s\n" "-sourcepath ${SOURCEP}" >> optionsBad
   395 printf "%s\n" "${TESTSRC}/Touch.java"  >> optionsBad
   397 ${APTNC} @optionsBad 2> /dev/null
   399 RESULT=$?
   401 case "${RESULT}" in
   402         0  )
   403 	echo "Improper exit zero with bad services information."
   404 	exit 1
   405         ;;
   406 esac
   409 exit 0;

mercurial