test/tools/apt/Compile/compile.sh

Fri, 17 Oct 2008 10:34:06 -0700

author
jjg
date
Fri, 17 Oct 2008 10:34:06 -0700
changeset 148
eca4bf37b66e
parent 1
9a66ca7c79fa
child 174
fdfed22db054
permissions
-rw-r--r--

6760805: empty element on bootclasspath breaks test/tools/apt/Compile/compile.sh
Reviewed-by: darcy

     1 #!/bin/sh
     3 #
     4 # Copyright 2004-2007 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 5033855 4990902 5023880 5043516 5048534 5048535 5041279 5048539 5067261 5068145 5023881 4996963 5095716 6191667 6433634
    28 # @run shell ../verifyVariables.sh
    29 # @build ErrorAPF
    30 # @build WarnAPF
    31 # @build StaticApf
    32 # @build ClassDeclApf
    33 # @build ClassDeclApf2
    34 # @build Rounds
    35 # @build Round1Apf Round2Apf Round3Apf Round4Apf
    36 # @build WrappedStaticApf
    37 # @run shell compile.sh
    38 # @summary Test simple usages of apt, including delegating to javac
    39 # @author Joseph D. Darcy
    41 # If the file *does* exist, exit with an error
    42 TestNoFile() {
    43         if [ -f ${1} ]; then
    44                 printf "%s\n" "File ${1} found."
    45                 exit 1
    46         fi
    47 }
    49 # If the file does not exist, exit with an error
    50 TestFile() {
    51         if [ ! -f ${1} ]; then
    52                 printf "%s\n" "File ${1} not found."
    53                 exit 1
    54         fi
    55 }
    58 OS=`uname -s`;
    59 case "${OS}" in
    60         Windows* | CYGWIN* )
    61                 SEP=";"
    62         ;;
    64         * )
    65         SEP=":"
    66         ;;
    67 esac
    70 APT="${TESTJAVA}/bin/apt ${TESTTOOLVMOPTS} "
    71 JAVA="${TESTJAVA}/bin/java ${TESTVMOPTS} "
    72 JAVAC="${TESTJAVA}/bin/javac ${TESTTOOLVMOPTS} "
    74 unset CLASSPATH
    77 # ---------------------------------------------------------------
    78 echo "Verify that source 1.6 is not supported
    79 rm -f HelloWorld.class
    81 printf "%s\n" "-source 1.6"     > options0
    82 printf "%s\n" "${TESTSRC}/HelloWorld.java"  >> options0
    83 ${APT} @options0
    85 RESULT=$?
    86 case "$RESULT" in
    87 	0  )
    88         echo "FAILED: accepted source 1.6"
    89 	exit 1
    90         ;;
    91 esac
    93 TestNoFile "HelloWorld.class"
    95 # ---------------------------------------------------------------
    97 echo "Verify that target 1.6 is not supported
    98 rm -f HelloWorld.class
   100 printf "%s\n" "-target 1.6"     > options00
   101 printf "%s\n" "${TESTSRC}/HelloWorld.java"  >> options00
   102 ${APT} @options00
   104 RESULT=$?
   105 case "$RESULT" in
   106 	0  )
   107         echo "FAILED: accepted target 1.6"
   108 	exit 1
   109         ;;
   110 esac
   112 TestNoFile "HelloWorld.class"
   114 # ---------------------------------------------------------------
   116 echo "Testing javac pass-through with -A in options file"
   117 rm -f HelloWorld.class
   119 printf "%s\n" "-A"     > options1
   120 printf "%s\n" "-d ."     >> options1
   121 printf "%s\n" "${TESTSRC}/HelloWorld.java"  >> options1
   122 ${APT} @options1
   124 RESULT=$?
   125 case "$RESULT" in
   126 	0  )
   127         ;;
   129         * )
   130         echo "FAILED: javac with -A in options file did not compile"
   131         exit 1
   132 esac
   133 TestFile "HelloWorld.class"
   136 # ---------------------------------------------------------------
   138 echo "Verifying reporting an error will prevent compilation"
   139 rm -f HelloWorld.class
   140 if [ ! -f HelloWorld.java ]; then
   141 	cp ${TESTSRC}/HelloWorld.java .
   142 fi
   145 printf "%s\n" "-factory ErrorAPF"            > options2
   146 printf "%s\n" "-d ."                        >> options2
   147 printf "%s\n" "-cp ${TESTCLASSES}"          >> options2
   148 printf "%s\n" "HelloWorld.java"             >> options2
   149 ${APT} @options2 2> output
   151 TestNoFile "HelloWorld.class"
   153 diff output ${TESTSRC}/golden.txt
   155 RESULT=$?
   156 case "$RESULT" in
   157 	0  )
   158         ;;
   160         * )
   161         echo "FAILED: did not record expected error messages"
   162         exit 1
   163 esac
   167 # ---------------------------------------------------------------
   169 echo "Verifying reporting a warning *won't* prevent compilation"
   171 rm -f HelloAnnotation.class
   172 if [ ! -f HelloAnnotation.java ]; then
   173 	cp ${TESTSRC}/HelloAnnotation.java .
   174 fi
   177 printf "%s\n" "-factory WarnAPF"             > options3
   178 printf "%s\n" "-d ."                        >> options3
   179 printf "%s\n" "-cp ${TESTCLASSES}"          >> options3
   180 printf "%s\n" "HelloAnnotation.java"        >> options3
   181 ${APT} @options3 2> output
   183 diff output ${TESTSRC}/goldenWarn.txt
   185 RESULT=$?
   186 case "$RESULT" in
   187 	0  )
   188         ;;
   190         * )
   191         echo "FAILED: did not record expected warning messages"
   192         exit 1
   193 esac
   195 TestFile "HelloAnnotation.class"
   197 # ---------------------------------------------------------------
   199 echo "Verifying static state is available across apt rounds; -factory, -cp"
   201 mkdir -p ./src
   202 mkdir -p ./class
   204 rm -Rf ./src/*
   205 rm -Rf ./class/*
   207 printf "%s\n" "-factory StaticApf"           > options4
   208 printf "%s\n" "-s ./src"                    >> options4
   209 printf "%s\n" "-d ./class"                  >> options4
   210 printf "%s\n" "-cp ${TESTCLASSES}"          >> options4
   211 # printf "%s\n" "-XPrintAptRounds"            >> options4
   212 ${APT} @options4
   214 TestFile "./class/AndAhTwo.class"
   216 # ---------------------------------------------------------------
   218 echo "Verifying static state is available across apt rounds; -factory, -factorypath"
   220 rm -Rf ./src/*
   221 rm -Rf ./class/*
   223 printf "%s\n" "-factory StaticApf"           > options5
   224 printf "%s\n" "-s ./src"                    >> options5
   225 printf "%s\n" "-d ./class"                  >> options5
   226 printf "%s\n" "-factorypath ${TESTCLASSES}" >> options5
   227 # printf "%s\n" "-XPrintAptRounds"          >> options5
   228 ${APT} @options5
   230 TestFile "./class/AndAhTwo.class"
   232 # -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
   234 # Create jar file for StaticApf
   235 JAR="${TESTJAVA}/bin/jar "
   236 mkdir -p META-INF/services
   237 cp ${TESTSRC}/servicesStaticApf META-INF/services/com.sun.mirror.apt.AnnotationProcessorFactory
   238 cp ${TESTCLASSES}/StaticApf*.class .
   239 ${JAR} cf0 staticApf.jar StaticApf*.class META-INF
   241 # ---------------------------------------------------------------
   243 echo "Verifying static state is available across apt rounds; -cp"
   245 rm -Rf ./src/*
   246 rm -Rf ./class/*
   248 printf "%s\n" "-cp staticApf.jar"           > options6
   249 printf "%s\n" "-s ./src"                    >> options6
   250 printf "%s\n" "-d ./class"                  >> options6
   251 printf "%s\n" "-XPrintAptRounds"          >> options6
   252 ${APT} @options6
   254 TestFile "./class/AndAhTwo.class"
   256 # ---------------------------------------------------------------
   258 echo "Verifying static state is available across apt rounds; -factorypath"
   260 rm -Rf ./src/*
   261 rm -Rf ./class/*
   263 printf "%s\n" "-factorypath staticApf.jar"   > options7
   264 printf "%s\n" "-s ./src"                    >> options7
   265 printf "%s\n" "-d ./class"                  >> options7
   266 printf "%s\n" "-XPrintAptRounds"            >> options7
   267 ${APT} @options7
   269 TestFile "./class/AndAhTwo.class"
   271 # ---------------------------------------------------------------
   273 echo "Verifying -XclassesAsDecls handles class files properly"
   275 rm -Rf ./src/*
   276 rm -Rf ./class/*
   278 mkdir -p ./tmp/classes
   280 ${JAVAC} -d ./tmp/classes ${TESTSRC}/src/Round1Class.java ${TESTSRC}/src/AhOneClass.java ${TESTSRC}/src/AndAhTwoClass.java
   282 RESULT=$?
   283 case "$RESULT" in
   284 	0  )
   285         ;;
   287         * )
   288         echo "FAILED: javac failed to succesfully compile."
   289         exit 1
   290 esac
   292 printf "%s\n" "-factorypath ${TESTCLASSES}"  > options7a
   293 printf "%s\n" "-factory ClassDeclApf"       >> options7a
   294 printf "%s\n" "-s ./src"                    >> options7a
   295 printf "%s\n" "-d ./class"                  >> options7a
   296 printf "%s\n" "-XPrintAptRounds"            >> options7a
   297 printf "%s\n" "-XclassesAsDecls"            >> options7a
   298 ${APT} @options7a
   300 TestFile "./class/AndAhTwoClass.class"
   302 # ---------------------------------------------------------------
   304 echo "Verifying -XclassesAsDecls works with command-line arguments"
   306 rm -Rf ./src/*
   307 rm -Rf ./class/*
   308 rm -Rf ./tmp/classes
   310 mkdir -p ./tmp/classes
   312 ${JAVAC} -d ./tmp/classes ${TESTSRC}/src/Round1Class.java ${TESTSRC}/src/AndAhTwoClass.java
   314 RESULT=$?
   315 case "$RESULT" in
   316 	0  )
   317         ;;
   319         * )
   320         echo "FAILED: javac failed to succesfully compile."
   321         exit 1
   322 esac
   324 printf "%s\n" "-factorypath ${TESTCLASSES}"  > options7b
   325 printf "%s\n" "-factory ClassDeclApf2"       >> options7b
   326 printf "%s\n" "-XPrintAptRounds"            >> options7b
   327 printf "%s\n" "-XclassesAsDecls"            >> options7b
   328 printf "%s\n" "-cp ${TESTCLASSES}"          >> options7b
   329 printf "%s\n" "ErrorAPF"                    >> options7b
   330 printf "%s\n" "WarnAPF"                     >> options7b
   331 printf "%s\n" "-s ./src"                    >> options7b
   332 printf "%s\n" "-d ./class"                  >> options7b
   333 printf "%s\n" "ClassDeclApf"                >> options7b
   334 ${APT} @options7b
   336 RESULT=$?
   337 case "$RESULT" in
   338 	0  )
   339         ;;
   341         * )
   342         echo "FAILED: apt exited with an error code."
   343         exit 1
   344 esac
   346 TestFile "./class/AndAhTwoClass.class"
   347 TestFile "./class/AhOne.class"
   349 # ---------------------------------------------------------------
   351 echo "Verifying -XclassesAsDecls works with all source files"
   353 rm -Rf ./src/*
   354 rm -Rf ./class/*
   355 rm -Rf ./tmp/classes
   357 mkdir -p ./tmp/classes
   359 ${JAVAC} -d ./tmp/classes ${TESTSRC}/src/Round1Class.java ${TESTSRC}/src/AndAhTwoClass.java
   361 RESULT=$?
   362 case "$RESULT" in
   363 	0  )
   364         ;;
   366         * )
   367         echo "FAILED: javac failed to succesfully compile."
   368         exit 1
   369 esac
   371 printf "%s\n" "-factorypath ${TESTCLASSES}"      > options7c
   372 printf "%s\n" "-factory ClassDeclApf2"          >> options7c
   373 printf "%s\n" "-s ./src"                        >> options7c
   374 printf "%s\n" "-d ./class"                      >> options7c
   375 printf "%s\n" "-sourcepath ${TESTSRC}"          >> options7c
   376 printf "%s\n" "${TESTSRC}/HelloAnnotation.java" >> options7c
   377 printf "%s\n" "${TESTSRC}/HelloWorld.java"      >> options7c
   378 printf "%s\n" "${TESTSRC}/Dummy1.java"          >> options7c
   379 printf "%s\n" "-XPrintAptRounds"                >> options7c
   380 printf "%s\n" "-XclassesAsDecls"                >> options7c
   381 printf "%s\n" "-cp ${TESTCLASSES}"              >> options7c
   382 ${APT} @options7c
   384 RESULT=$?
   385 case "$RESULT" in
   386 	0  )
   387         ;;
   389         * )
   390         echo "FAILED: apt exited with an error code."
   391         exit 1
   392 esac
   394 TestFile "./class/AndAhTwoClass.class"
   395 TestFile "./class/AhOne.class"
   396 TestFile "./class/HelloWorld.class"
   398 # ---------------------------------------------------------------
   400 echo "Verifying -XclassesAsDecls works with mixed class and source files"
   402 rm -Rf ./src/*
   403 rm -Rf ./class/*
   404 rm -Rf ./tmp/classes
   406 mkdir -p ./tmp/classes
   408 ${JAVAC} -d ./tmp/classes ${TESTSRC}/src/Round1Class.java ${TESTSRC}/src/AndAhTwoClass.java
   410 RESULT=$?
   411 case "$RESULT" in
   412 	0  )
   413         ;;
   415         * )
   416         echo "FAILED: javac failed to succesfully compile."
   417         exit 1
   418 esac
   420 printf "%s\n" "-factorypath ${TESTCLASSES}"  > options7d
   421 printf "%s\n" "-factory ClassDeclApf2"      >> options7d
   422 printf "%s\n" "-s ./src"                    >> options7d
   423 printf "%s\n" "-XclassesAsDecls"            >> options7d
   424 printf "%s\n" "ClassDeclApf"                >> options7d
   425 printf "%s\n" "-d ./class"                  >> options7d
   426 printf "%s\n" "ErrorAPF"                    >> options7d
   427 printf "%s\n" "-XPrintAptRounds"            >> options7d
   428 printf "%s\n" "${TESTSRC}/HelloWorld.java"  >> options7d
   429 printf "%s\n" "-cp ${TESTCLASSES}"          >> options7d
   430 ${APT} @options7d
   432 RESULT=$?
   433 case "$RESULT" in
   434 	0  )
   435         ;;
   437         * )
   438         echo "FAILED: apt exited with an error code."
   439         exit 1
   440 esac
   442 TestFile "./class/AndAhTwoClass.class"
   443 TestFile "./class/AhOne.class"
   444 TestFile "./class/HelloWorld.class"
   446 # ---------------------------------------------------------------
   448 echo "Testing productive factories are called on subsequent rounds"
   450 rm -Rf ./src/*
   451 rm -Rf ./class/*
   453 rm -Rf META-INF/services/*
   454 cp ${TESTSRC}/servicesRound1 META-INF/services/com.sun.mirror.apt.AnnotationProcessorFactory
   455 cp ${TESTCLASSES}/Round1Apf*.class .
   456 ${JAR} cf0 round1Apf.jar Round1Apf*.class META-INF
   458 rm -Rf META-INF/services/*
   459 cp ${TESTSRC}/servicesRound2 META-INF/services/com.sun.mirror.apt.AnnotationProcessorFactory
   460 cp ${TESTCLASSES}/Round2Apf*.class .
   461 ${JAR} cf0 round2Apf.jar Round2Apf*.class META-INF
   463 rm -Rf META-INF/services/*
   464 cp ${TESTSRC}/servicesRound3 META-INF/services/com.sun.mirror.apt.AnnotationProcessorFactory
   465 cp ${TESTCLASSES}/Round3Apf*.class .
   466 ${JAR} cf0 round3Apf.jar Round3Apf*.class META-INF
   468 rm -Rf META-INF/services/*
   469 cp ${TESTSRC}/servicesRound4 META-INF/services/com.sun.mirror.apt.AnnotationProcessorFactory
   470 cp ${TESTCLASSES}/Round4Apf*.class .
   471 ${JAR} cf0 round4Apf.jar Round4Apf*.class META-INF
   473 cp ${TESTCLASSES}/Round?.class .
   474 ${JAR} cf0 rounds.jar Round?.class
   476 # cleanup file to prevent accidental discovery in current directory
   477 rm -Rf META-INF/services/*
   479 printf "%s\n" "-factorypath round1Apf.jar${SEP}round2Apf.jar${SEP}round3Apf.jar${SEP}round4Apf.jar"   > options8
   480 printf "%s\n" "-classpath rounds.jar"  >> options8
   481 printf "%s\n" "-s ./src"               >> options8
   482 printf "%s\n" "-d ./class"             >> options8
   483 #printf "%s\n" "-XPrintFactoryInfo"     >> options8
   484 #printf "%s\n" "-XPrintAptRounds"       >> options8
   485 printf "%s\n" "${TESTSRC}/Dummy1.java" >> options8
   486 ${APT} @options8 > multiRoundOutput 2> multiRoundError
   488 diff multiRoundOutput  ${TESTSRC}/goldenFactory.txt
   490 RESULT=$?
   491 case "$RESULT" in
   492 	0  )
   493         ;;
   495         * )
   496         echo "FAILED: unexpected factory state"
   497         exit 1
   498 esac
   500 TestFile "./class/Dummy5.class"
   502 # ---------------------------------------------------------------
   504 echo "Verifying static state with programmatic apt entry; no factory options"
   505 rm -Rf ./src/*
   506 rm -Rf ./class/*
   507 ${JAVA} -cp ${TESTJAVA}/lib/tools.jar${SEP}${TESTCLASSES} WrappedStaticApf -s ./src -d ./class -XPrintAptRounds
   508 TestFile "./class/AndAhTwo.class"
   510 echo "Verifying static state with programmatic apt entry; -factory"
   511 rm -Rf ./src/*
   512 rm -Rf ./class/*
   513 ${JAVA} -cp ${TESTJAVA}/lib/tools.jar${SEP}${TESTCLASSES} WrappedStaticApf -factory ErrorAPF -s ./src -d ./class -XPrintAptRounds
   514 TestFile "./class/AndAhTwo.class"
   516 echo "Verifying static state with programmatic apt entry; -factorypath"
   517 rm -Rf ./src/*
   518 rm -Rf ./class/*
   519 ${JAVA} -cp ${TESTJAVA}/lib/tools.jar${SEP}${TESTCLASSES} WrappedStaticApf -factorypath round1Apf.jar -s ./src -d ./class -XPrintAptRounds
   520 TestFile "./class/AndAhTwo.class"
   522 echo "Verifying static state with programmatic apt entry; -factory and -factorypath"
   523 rm -Rf ./src/*
   524 rm -Rf ./class/*
   525 ${JAVA} -cp ${TESTJAVA}/lib/tools.jar${SEP}${TESTCLASSES} WrappedStaticApf -factorypath round1Apf.jar -factory Round1Apf -s ./src -d ./class -XPrintAptRounds
   526 TestFile "./class/AndAhTwo.class"
   528 exit 0

mercurial