test/tools/apt/Discovery/discovery.sh

Thu, 25 Aug 2011 17:18:25 -0700

author
schien
date
Thu, 25 Aug 2011 17:18:25 -0700
changeset 1067
f497fac86cf9
parent 554
9d9f26857129
permissions
-rw-r--r--

Added tag jdk8-b02 for changeset b3c059de2a61

     1 #!/bin/sh
     3 #
     4 # Copyright (c) 1999, 2008, 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 #
    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
   112 # cleanup file to prevent accidental discovery in current directory
   113 rm -f META-INF/services/com.sun.mirror.apt.AnnotationProcessorFactory
   115 # Jar files created; verify right output file is touched
   117 #---------------------------------------------------------
   119 # Test different combinations of classpath, sourcepath, and
   120 # destination directories
   123 #
   124 # Classpath on commandline; no output directories
   125 #
   127 rm -f touched 
   128 rm -f HelloWorld.java
   129 rm -f Empty.class
   131 unset CLASSPATH
   132 printf "%s\n" "-classpath ${JARCP}"     > options1
   133 printf "%s\n" "-sourcepath ${SOURCEP}" >> options1
   134 printf "%s\n" "${TESTSRC}/Touch.java"  >> options1
   136 ${APTNC} @options1
   138 echo "Testing case 1"
   139 TestFile "touched"
   140 TestFile "HelloWorld.java"
   141 TestFile "Empty.class"
   143 #
   144 # Class path set through environment variable
   145 #
   147 rm -f touched
   148 rm -f HelloWorld.java
   149 rm -f Empty.class
   151 unset CLASSPATH
   152 CLASSPATH=${JARCP}
   153 export CLASSPATH
   154 printf "%s\n" "-sourcepath ${SOURCEP}" > options2
   155 printf "%s\n" "${TESTSRC}/Touch.java" >> options2
   157 ${APTNC} @options2
   159 echo "Testing case 2"
   160 TestFile "touched"
   161 TestFile "HelloWorld.java"
   162 TestFile "Empty.class"
   164 #
   165 # No explicit source path
   166 #
   168 rm -f touched
   169 rm -f HelloWorld.java
   170 rm -f Empty.class
   172 unset CLASSPATH
   173 CLASSPATH=${FULLCP}
   174 export CLASSPATH
   175 printf "%s\n" "${TESTSRC}/Touch.java"  > options3
   177 ${APTNC} @options3
   179 echo "Testing case 3"
   180 TestFile "touched"
   181 TestFile "HelloWorld.java"
   182 TestFile "Empty.class"
   185 #
   186 # Classpath on commandline; class output directory
   187 #
   189 rm -f touched
   190 rm -f HelloWorld.java
   191 rm -Rf classes/Empty.class
   193 unset CLASSPATH
   194 printf "%s\n" "-classpath ${JARCP}"     > options4
   195 printf "%s\n" "-sourcepath ${SOURCEP}" >> options4
   196 printf "%s\n" "-d classes"             >> options4
   197 printf "%s\n" "${TESTSRC}/Touch.java"  >> options4
   199 ${APTNC} @options4
   201 echo "Testing case 4"
   202 TestFile "touched"
   203 TestFile "HelloWorld.java"
   204 TestFile "classes/Empty.class"
   206 #
   207 # Classpath on commandline; source output directory
   208 #
   210 rm -f touched
   211 rm -Rf src
   212 rm -f Empty.class
   214 unset CLASSPATH
   215 printf "%s\n" "-classpath ${JARCP}"     > options5
   216 printf "%s\n" "-sourcepath ${SOURCEP}" >> options5
   217 printf "%s\n" "-s src"                 >> options5
   218 printf "%s\n" "${TESTSRC}/Touch.java"  >> options5
   220 ${APTNC} @options5
   222 echo "Testing case 5"
   223 TestFile "touched"
   224 TestFile "src/HelloWorld.java"
   225 TestFile "Empty.class"
   228 #
   229 # Classpath on commandline; class and source output directory
   230 #
   232 rm -f touched
   233 rm -Rf src
   234 rm -Rf classes
   236 unset CLASSPATH
   237 printf "%s\n" "-classpath ${JARCP}"     > options6
   238 printf "%s\n" "-sourcepath ${SOURCEP}" >> options6
   239 printf "%s\n" "-d classes"             >> options6
   240 printf "%s\n" "-s src"                 >> options6
   241 printf "%s\n" "${TESTSRC}/Touch.java"  >> options6
   243 ${APTNC} @options6
   245 echo "Testing case 6"
   246 TestFile "touched"
   247 TestFile "src/HelloWorld.java"
   248 TestFile "classes/Empty.class"
   250 #
   251 # Classpath appended to bootclasspath; no output directories
   252 #
   254 rm -f touched
   255 rm -f HelloWorld.java
   256 rm -f Empty.class
   258 unset CLASSPATH
   259 printf "%s\n" "-Xbootclasspath/a:${JARCP}" > options7
   260 printf "%s\n" "-classpath /dev/null"      >> options7
   261 printf "%s\n" "${TESTSRC}/Touch.java"     >> options7
   263 ${APTNC} @options7
   265 echo "Testing case 7"
   266 TestFile "touched"
   267 TestFile "HelloWorld.java"
   268 TestFile "Empty.class"
   270 #
   271 # Classpath in extdirs; no output directories
   272 #
   274 rm -f touched
   275 rm -f HelloWorld.java
   276 rm -f Empty.class
   278 unset CLASSPATH
   279 printf "%s\n" "-extdirs ."              > options8
   280 printf "%s\n" "-classpath ${TOOLSJAR}" >> options8
   281 printf "%s\n" "${TESTSRC}/Touch.java"  >> options8
   283 ${APTNC} @options8
   285 echo "Testing case 8"
   286 TestFile "touched"
   287 TestFile "HelloWorld.java"
   288 TestFile "Empty.class"
   290 #
   291 # Classpath in extdirs, take 2; no output directories
   292 #
   294 rm -f touched
   295 rm -f HelloWorld.java
   296 rm -f Empty.class
   298 unset CLASSPATH
   299 printf "%s\n" "-Djava.ext.dirs=."        > options9
   300 printf "%s\n" "-classpath ${TOOLSJAR}"  >> options9
   301 printf "%s\n" "${TESTSRC}/Touch.java"   >> options9
   303 ${APTNC} @options9
   305 echo "Testing case 9"
   306 TestFile "touched"
   307 TestFile "HelloWorld.java"
   308 TestFile "Empty.class"
   310 #
   311 # Classpath in -endorseddirs; no output directories
   312 #
   314 rm -f touched
   315 rm -f HelloWorld.java
   316 rm -f Empty.class
   318 unset CLASSPATH
   319 printf "%s\n" "-endorseddirs ."          > options10
   320 printf "%s\n" "-classpath ${TOOLSJAR}"  >> options10
   321 printf "%s\n" "${TESTSRC}/Touch.java"   >> options10
   323 ${APTNC} @options10
   325 echo "Testing case 10"
   326 TestFile "touched"
   327 TestFile "HelloWorld.java"
   328 TestFile "Empty.class"
   330 #
   331 # Testing apt invocation with no command line options
   332 #
   334 rm -f touched
   335 rm -f HelloWorld.java
   336 rm -f Empty.class
   338 unset CLASSPATH
   339 CLASSPATH=./phantom/phantom.jar
   340 export CLASSPATH
   342 ${APT}
   344 echo "Testing empty command line"
   345 TestFile "touched"
   346 TestFile "HelloWorld.java"
   349 #
   350 # Verify apt and JSR 269 annotation processors can be run from same
   351 # invocation and both use the output directories
   352 #
   354 rm -f touched
   355 rm -f src/HelloWorld.java
   356 rm -f src/GoodbyeWorld.java
   357 rm -f classes/HelloWorld.class
   358 rm -f classes/GoodbyeWorld.class
   360 unset CLASSPATH
   363 printf "%s\n" "-classpath ./phantom/phantom.jar" > options11
   364 printf "%s\n" "-sourcepath ${SOURCEP}"          >> options11
   365 printf "%s\n" "-factory PhantomTouch "          >> options11
   366 printf "%s\n" "-s src"                          >> options11
   367 printf "%s\n" "-d classes"                      >> options11
   368 printf "%s\n" "-A"             	                >> options11
   369 printf "%s\n" "-Afoo"          	                >> options11
   370 printf "%s\n" "-Abar=baz"      	                >> options11
   371 printf "%s\n" "-processorpath $TESTCLASSES"     >> options11
   372 printf "%s\n" "-processor PhantomUpdate"        >> options11
   374 ${APT} @options11
   376 echo "Testing combined apt and JSR 269 processing"
   377 TestFile touched
   378 TestFile "src/HelloWorld.java"
   379 TestFile "src/GoodbyeWorld.java"
   380 TestFile "classes/HelloWorld.class"
   381 TestFile "classes/GoodbyeWorld.class"
   383 #
   384 # Verify running with badTouch doesn't exit successfully
   385 #
   387 rm -f ./META-INF/services/com.sun.mirror.apt.AnnotationProcessorFactory
   388 cp ${TESTSRC}/servicesBadTouch ./META-INF/services/com.sun.mirror.apt.AnnotationProcessorFactory
   390 ${JAR} cf0 badTouch.jar Touch*.class META-INF
   393 unset CLASSPATH
   394 printf "%s\n" "-classpath ${BADCP}"     > optionsBad
   395 printf "%s\n" "-sourcepath ${SOURCEP}" >> optionsBad
   396 printf "%s\n" "${TESTSRC}/Touch.java"  >> optionsBad
   398 ${APTNC} @optionsBad 2> /dev/null
   400 RESULT=$?
   402 case "${RESULT}" in
   403         0  )
   404 	echo "Improper exit zero with bad services information."
   405 	exit 1
   406         ;;
   407 esac
   410 exit 0;

mercurial