test/tools/apt/Compile/compile.sh

Thu, 27 Aug 2009 17:50:21 -0700

author
jjg
date
Thu, 27 Aug 2009 17:50:21 -0700
changeset 387
f29068bfeaed
parent 331
d043adadc8b6
child 404
14735c7932d7
permissions
-rw-r--r--

6876755: apt tests fail on Windows
Reviewed-by: darcy

     1 #!/bin/sh
     3 #
     4 # Copyright 2004-2008 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* )
    61                 SEP=";"
    62         ;;
    64         CYGWIN* )
    65 		DIFFOPTS="--strip-trailing-cr"
    66                 SEP=";"
    67         ;;
    69         * )
    70         SEP=":"
    71         ;;
    72 esac
    75 APT="${TESTJAVA}/bin/apt ${TESTTOOLVMOPTS} -XDsuppress-tool-api-removal-message "
    76 JAVA="${TESTJAVA}/bin/java ${TESTVMOPTS} "
    77 JAVAC="${TESTJAVA}/bin/javac ${TESTTOOLVMOPTS} "
    79 unset CLASSPATH
    82 # ---------------------------------------------------------------
    83 echo "Verify that source 1.6 is not supported
    84 rm -f HelloWorld.class
    86 printf "%s\n" "-source 1.6"     > options0
    87 printf "%s\n" "${TESTSRC}/HelloWorld.java"  >> options0
    88 ${APT} @options0
    90 RESULT=$?
    91 case "$RESULT" in
    92 	0  )
    93         echo "FAILED: accepted source 1.6"
    94 	exit 1
    95         ;;
    96 esac
    98 TestNoFile "HelloWorld.class"
   100 # ---------------------------------------------------------------
   102 echo "Verify that target 1.6 is not supported
   103 rm -f HelloWorld.class
   105 printf "%s\n" "-target 1.6"     > options00
   106 printf "%s\n" "${TESTSRC}/HelloWorld.java"  >> options00
   107 ${APT} @options00
   109 RESULT=$?
   110 case "$RESULT" in
   111 	0  )
   112         echo "FAILED: accepted target 1.6"
   113 	exit 1
   114         ;;
   115 esac
   117 TestNoFile "HelloWorld.class"
   119 # ---------------------------------------------------------------
   121 echo "Testing javac pass-through with -A in options file"
   122 rm -f HelloWorld.class
   124 printf "%s\n" "-A"     > options1
   125 printf "%s\n" "-d ."     >> options1
   126 printf "%s\n" "${TESTSRC}/HelloWorld.java"  >> options1
   127 ${APT} @options1
   129 RESULT=$?
   130 case "$RESULT" in
   131 	0  )
   132         ;;
   134         * )
   135         echo "FAILED: javac with -A in options file did not compile"
   136         exit 1
   137 esac
   138 TestFile "HelloWorld.class"
   141 # ---------------------------------------------------------------
   143 echo "Verifying reporting an error will prevent compilation"
   144 rm -f HelloWorld.class
   145 if [ ! -f HelloWorld.java ]; then
   146 	cp ${TESTSRC}/HelloWorld.java .
   147 fi
   150 printf "%s\n" "-factory ErrorAPF"            > options2
   151 printf "%s\n" "-d ."                        >> options2
   152 printf "%s\n" "-cp ${TESTCLASSES}"          >> options2
   153 printf "%s\n" "HelloWorld.java"             >> options2
   154 ${APT} @options2 2> output
   156 TestNoFile "HelloWorld.class"
   158 diff ${DIFFOPTS} output ${TESTSRC}/golden.txt
   160 RESULT=$?
   161 case "$RESULT" in
   162 	0  )
   163         ;;
   165         * )
   166         echo "FAILED: did not record expected error messages"
   167         exit 1
   168 esac
   172 # ---------------------------------------------------------------
   174 echo "Verifying reporting a warning *won't* prevent compilation"
   176 rm -f HelloAnnotation.class
   177 if [ ! -f HelloAnnotation.java ]; then
   178 	cp ${TESTSRC}/HelloAnnotation.java .
   179 fi
   182 printf "%s\n" "-factory WarnAPF"             > options3
   183 printf "%s\n" "-d ."                        >> options3
   184 printf "%s\n" "-cp ${TESTCLASSES}"          >> options3
   185 printf "%s\n" "HelloAnnotation.java"        >> options3
   186 ${APT} @options3 2> output
   188 diff ${DIFFOPTS} output ${TESTSRC}/goldenWarn.txt
   190 RESULT=$?
   191 case "$RESULT" in
   192 	0  )
   193         ;;
   195         * )
   196         echo "FAILED: did not record expected warning messages"
   197         exit 1
   198 esac
   200 TestFile "HelloAnnotation.class"
   202 # ---------------------------------------------------------------
   204 echo "Verifying static state is available across apt rounds; -factory, -cp"
   206 mkdir -p ./src
   207 mkdir -p ./class
   209 rm -Rf ./src/*
   210 rm -Rf ./class/*
   212 printf "%s\n" "-factory StaticApf"           > options4
   213 printf "%s\n" "-s ./src"                    >> options4
   214 printf "%s\n" "-d ./class"                  >> options4
   215 printf "%s\n" "-cp ${TESTCLASSES}"          >> options4
   216 # printf "%s\n" "-XPrintAptRounds"            >> options4
   217 ${APT} @options4
   219 TestFile "./class/AndAhTwo.class"
   221 # ---------------------------------------------------------------
   223 echo "Verifying static state is available across apt rounds; -factory, -factorypath"
   225 rm -Rf ./src/*
   226 rm -Rf ./class/*
   228 printf "%s\n" "-factory StaticApf"           > options5
   229 printf "%s\n" "-s ./src"                    >> options5
   230 printf "%s\n" "-d ./class"                  >> options5
   231 printf "%s\n" "-factorypath ${TESTCLASSES}" >> options5
   232 # printf "%s\n" "-XPrintAptRounds"          >> options5
   233 ${APT} @options5
   235 TestFile "./class/AndAhTwo.class"
   237 # -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
   239 # Create jar file for StaticApf
   240 JAR="${TESTJAVA}/bin/jar "
   241 mkdir -p META-INF/services
   242 cp ${TESTSRC}/servicesStaticApf META-INF/services/com.sun.mirror.apt.AnnotationProcessorFactory
   243 cp ${TESTCLASSES}/StaticApf*.class .
   244 ${JAR} cf0 staticApf.jar StaticApf*.class META-INF
   246 # ---------------------------------------------------------------
   248 echo "Verifying static state is available across apt rounds; -cp"
   250 rm -Rf ./src/*
   251 rm -Rf ./class/*
   253 printf "%s\n" "-cp staticApf.jar"           > options6
   254 printf "%s\n" "-s ./src"                    >> options6
   255 printf "%s\n" "-d ./class"                  >> options6
   256 printf "%s\n" "-XPrintAptRounds"          >> options6
   257 ${APT} @options6
   259 TestFile "./class/AndAhTwo.class"
   261 # ---------------------------------------------------------------
   263 echo "Verifying static state is available across apt rounds; -factorypath"
   265 rm -Rf ./src/*
   266 rm -Rf ./class/*
   268 printf "%s\n" "-factorypath staticApf.jar"   > options7
   269 printf "%s\n" "-s ./src"                    >> options7
   270 printf "%s\n" "-d ./class"                  >> options7
   271 printf "%s\n" "-XPrintAptRounds"            >> options7
   272 ${APT} @options7
   274 TestFile "./class/AndAhTwo.class"
   276 # ---------------------------------------------------------------
   278 echo "Verifying -XclassesAsDecls handles class files properly"
   280 rm -Rf ./src/*
   281 rm -Rf ./class/*
   283 mkdir -p ./tmp/classes
   285 ${JAVAC} -d ./tmp/classes ${TESTSRC}/src/Round1Class.java ${TESTSRC}/src/AhOneClass.java ${TESTSRC}/src/AndAhTwoClass.java
   287 RESULT=$?
   288 case "$RESULT" in
   289 	0  )
   290         ;;
   292         * )
   293         echo "FAILED: javac failed to succesfully compile."
   294         exit 1
   295 esac
   297 printf "%s\n" "-factorypath ${TESTCLASSES}"  > options7a
   298 printf "%s\n" "-factory ClassDeclApf"       >> options7a
   299 printf "%s\n" "-s ./src"                    >> options7a
   300 printf "%s\n" "-d ./class"                  >> options7a
   301 printf "%s\n" "-XPrintAptRounds"            >> options7a
   302 printf "%s\n" "-XclassesAsDecls"            >> options7a
   303 ${APT} @options7a
   305 TestFile "./class/AndAhTwoClass.class"
   307 # ---------------------------------------------------------------
   309 echo "Verifying -XclassesAsDecls works with command-line arguments"
   311 rm -Rf ./src/*
   312 rm -Rf ./class/*
   313 rm -Rf ./tmp/classes
   315 mkdir -p ./tmp/classes
   317 ${JAVAC} -d ./tmp/classes ${TESTSRC}/src/Round1Class.java ${TESTSRC}/src/AndAhTwoClass.java
   319 RESULT=$?
   320 case "$RESULT" in
   321 	0  )
   322         ;;
   324         * )
   325         echo "FAILED: javac failed to succesfully compile."
   326         exit 1
   327 esac
   329 printf "%s\n" "-factorypath ${TESTCLASSES}"  > options7b
   330 printf "%s\n" "-factory ClassDeclApf2"       >> options7b
   331 printf "%s\n" "-XPrintAptRounds"            >> options7b
   332 printf "%s\n" "-XclassesAsDecls"            >> options7b
   333 printf "%s\n" "-cp ${TESTCLASSES}"          >> options7b
   334 printf "%s\n" "ErrorAPF"                    >> options7b
   335 printf "%s\n" "WarnAPF"                     >> options7b
   336 printf "%s\n" "-s ./src"                    >> options7b
   337 printf "%s\n" "-d ./class"                  >> options7b
   338 printf "%s\n" "ClassDeclApf"                >> options7b
   339 ${APT} @options7b
   341 RESULT=$?
   342 case "$RESULT" in
   343 	0  )
   344         ;;
   346         * )
   347         echo "FAILED: apt exited with an error code."
   348         exit 1
   349 esac
   351 TestFile "./class/AndAhTwoClass.class"
   352 TestFile "./class/AhOne.class"
   354 # ---------------------------------------------------------------
   356 echo "Verifying -XclassesAsDecls works with all source files"
   358 rm -Rf ./src/*
   359 rm -Rf ./class/*
   360 rm -Rf ./tmp/classes
   362 mkdir -p ./tmp/classes
   364 ${JAVAC} -d ./tmp/classes ${TESTSRC}/src/Round1Class.java ${TESTSRC}/src/AndAhTwoClass.java
   366 RESULT=$?
   367 case "$RESULT" in
   368 	0  )
   369         ;;
   371         * )
   372         echo "FAILED: javac failed to succesfully compile."
   373         exit 1
   374 esac
   376 printf "%s\n" "-factorypath ${TESTCLASSES}"      > options7c
   377 printf "%s\n" "-factory ClassDeclApf2"          >> options7c
   378 printf "%s\n" "-s ./src"                        >> options7c
   379 printf "%s\n" "-d ./class"                      >> options7c
   380 printf "%s\n" "-sourcepath ${TESTSRC}"          >> options7c
   381 printf "%s\n" "${TESTSRC}/HelloAnnotation.java" >> options7c
   382 printf "%s\n" "${TESTSRC}/HelloWorld.java"      >> options7c
   383 printf "%s\n" "${TESTSRC}/Dummy1.java"          >> options7c
   384 printf "%s\n" "-XPrintAptRounds"                >> options7c
   385 printf "%s\n" "-XclassesAsDecls"                >> options7c
   386 printf "%s\n" "-cp ${TESTCLASSES}"              >> options7c
   387 ${APT} @options7c
   389 RESULT=$?
   390 case "$RESULT" in
   391 	0  )
   392         ;;
   394         * )
   395         echo "FAILED: apt exited with an error code."
   396         exit 1
   397 esac
   399 TestFile "./class/AndAhTwoClass.class"
   400 TestFile "./class/AhOne.class"
   401 TestFile "./class/HelloWorld.class"
   403 # ---------------------------------------------------------------
   405 echo "Verifying -XclassesAsDecls works with mixed class and source files"
   407 rm -Rf ./src/*
   408 rm -Rf ./class/*
   409 rm -Rf ./tmp/classes
   411 mkdir -p ./tmp/classes
   413 ${JAVAC} -d ./tmp/classes ${TESTSRC}/src/Round1Class.java ${TESTSRC}/src/AndAhTwoClass.java
   415 RESULT=$?
   416 case "$RESULT" in
   417 	0  )
   418         ;;
   420         * )
   421         echo "FAILED: javac failed to succesfully compile."
   422         exit 1
   423 esac
   425 printf "%s\n" "-factorypath ${TESTCLASSES}"  > options7d
   426 printf "%s\n" "-factory ClassDeclApf2"      >> options7d
   427 printf "%s\n" "-s ./src"                    >> options7d
   428 printf "%s\n" "-XclassesAsDecls"            >> options7d
   429 printf "%s\n" "ClassDeclApf"                >> options7d
   430 printf "%s\n" "-d ./class"                  >> options7d
   431 printf "%s\n" "ErrorAPF"                    >> options7d
   432 printf "%s\n" "-XPrintAptRounds"            >> options7d
   433 printf "%s\n" "${TESTSRC}/HelloWorld.java"  >> options7d
   434 printf "%s\n" "-cp ${TESTCLASSES}"          >> options7d
   435 ${APT} @options7d
   437 RESULT=$?
   438 case "$RESULT" in
   439 	0  )
   440         ;;
   442         * )
   443         echo "FAILED: apt exited with an error code."
   444         exit 1
   445 esac
   447 TestFile "./class/AndAhTwoClass.class"
   448 TestFile "./class/AhOne.class"
   449 TestFile "./class/HelloWorld.class"
   451 # ---------------------------------------------------------------
   453 echo "Testing productive factories are called on subsequent rounds"
   455 rm -Rf ./src/*
   456 rm -Rf ./class/*
   458 rm -Rf META-INF/services/*
   459 cp ${TESTSRC}/servicesRound1 META-INF/services/com.sun.mirror.apt.AnnotationProcessorFactory
   460 cp ${TESTCLASSES}/Round1Apf*.class .
   461 ${JAR} cf0 round1Apf.jar Round1Apf*.class META-INF
   463 rm -Rf META-INF/services/*
   464 cp ${TESTSRC}/servicesRound2 META-INF/services/com.sun.mirror.apt.AnnotationProcessorFactory
   465 cp ${TESTCLASSES}/Round2Apf*.class .
   466 ${JAR} cf0 round2Apf.jar Round2Apf*.class META-INF
   468 rm -Rf META-INF/services/*
   469 cp ${TESTSRC}/servicesRound3 META-INF/services/com.sun.mirror.apt.AnnotationProcessorFactory
   470 cp ${TESTCLASSES}/Round3Apf*.class .
   471 ${JAR} cf0 round3Apf.jar Round3Apf*.class META-INF
   473 rm -Rf META-INF/services/*
   474 cp ${TESTSRC}/servicesRound4 META-INF/services/com.sun.mirror.apt.AnnotationProcessorFactory
   475 cp ${TESTCLASSES}/Round4Apf*.class .
   476 ${JAR} cf0 round4Apf.jar Round4Apf*.class META-INF
   478 cp ${TESTCLASSES}/Round?.class .
   479 ${JAR} cf0 rounds.jar Round?.class
   481 # cleanup file to prevent accidental discovery in current directory
   482 rm -Rf META-INF/services/*
   484 printf "%s\n" "-factorypath round1Apf.jar${SEP}round2Apf.jar${SEP}round3Apf.jar${SEP}round4Apf.jar"   > options8
   485 printf "%s\n" "-classpath rounds.jar"  >> options8
   486 printf "%s\n" "-s ./src"               >> options8
   487 printf "%s\n" "-d ./class"             >> options8
   488 #printf "%s\n" "-XPrintFactoryInfo"     >> options8
   489 #printf "%s\n" "-XPrintAptRounds"       >> options8
   490 printf "%s\n" "${TESTSRC}/Dummy1.java" >> options8
   491 ${APT} @options8 > multiRoundOutput 2> multiRoundError
   493 diff ${DIFFOPTS} multiRoundOutput  ${TESTSRC}/goldenFactory.txt
   495 RESULT=$?
   496 case "$RESULT" in
   497 	0  )
   498         ;;
   500         * )
   501         echo "FAILED: unexpected factory state"
   502         exit 1
   503 esac
   505 TestFile "./class/Dummy5.class"
   507 # ---------------------------------------------------------------
   509 echo "Verifying static state with programmatic apt entry; no factory options"
   510 rm -Rf ./src/*
   511 rm -Rf ./class/*
   512 ${JAVA} -cp ${TESTJAVA}/lib/tools.jar${SEP}${TESTCLASSES} WrappedStaticApf -s ./src -d ./class -XPrintAptRounds
   513 TestFile "./class/AndAhTwo.class"
   515 echo "Verifying static state with programmatic apt entry; -factory"
   516 rm -Rf ./src/*
   517 rm -Rf ./class/*
   518 ${JAVA} -cp ${TESTJAVA}/lib/tools.jar${SEP}${TESTCLASSES} WrappedStaticApf -factory ErrorAPF -s ./src -d ./class -XPrintAptRounds
   519 TestFile "./class/AndAhTwo.class"
   521 echo "Verifying static state with programmatic apt entry; -factorypath"
   522 rm -Rf ./src/*
   523 rm -Rf ./class/*
   524 ${JAVA} -cp ${TESTJAVA}/lib/tools.jar${SEP}${TESTCLASSES} WrappedStaticApf -factorypath round1Apf.jar -s ./src -d ./class -XPrintAptRounds
   525 TestFile "./class/AndAhTwo.class"
   527 echo "Verifying static state with programmatic apt entry; -factory and -factorypath"
   528 rm -Rf ./src/*
   529 rm -Rf ./class/*
   530 ${JAVA} -cp ${TESTJAVA}/lib/tools.jar${SEP}${TESTCLASSES} WrappedStaticApf -factorypath round1Apf.jar -factory Round1Apf -s ./src -d ./class -XPrintAptRounds
   531 TestFile "./class/AndAhTwo.class"
   533 exit 0

mercurial