langtools/test/tools/apt/Basics/apt.sh
author darcy
Sun, 26 Jul 2009 21:27:11 -0700
changeset 3378 22011d9a9398
parent 10 06bc494ca11e
child 3769 5fd6cfd5a9a0
permissions -rw-r--r--
6381698: Warn of decommissioning of apt Reviewed-by: jjg
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
10
06bc494ca11e Initial load
duke
parents:
diff changeset
     1
#!/bin/sh
06bc494ca11e Initial load
duke
parents:
diff changeset
     2
06bc494ca11e Initial load
duke
parents:
diff changeset
     3
#
06bc494ca11e Initial load
duke
parents:
diff changeset
     4
# Copyright 2004-2007 Sun Microsystems, Inc.  All Rights Reserved.
06bc494ca11e Initial load
duke
parents:
diff changeset
     5
# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
06bc494ca11e Initial load
duke
parents:
diff changeset
     6
#
06bc494ca11e Initial load
duke
parents:
diff changeset
     7
# This code is free software; you can redistribute it and/or modify it
06bc494ca11e Initial load
duke
parents:
diff changeset
     8
# under the terms of the GNU General Public License version 2 only, as
06bc494ca11e Initial load
duke
parents:
diff changeset
     9
# published by the Free Software Foundation.
06bc494ca11e Initial load
duke
parents:
diff changeset
    10
#
06bc494ca11e Initial load
duke
parents:
diff changeset
    11
# This code is distributed in the hope that it will be useful, but WITHOUT
06bc494ca11e Initial load
duke
parents:
diff changeset
    12
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
06bc494ca11e Initial load
duke
parents:
diff changeset
    13
# FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
06bc494ca11e Initial load
duke
parents:
diff changeset
    14
# version 2 for more details (a copy is included in the LICENSE file that
06bc494ca11e Initial load
duke
parents:
diff changeset
    15
# accompanied this code).
06bc494ca11e Initial load
duke
parents:
diff changeset
    16
#
06bc494ca11e Initial load
duke
parents:
diff changeset
    17
# You should have received a copy of the GNU General Public License version
06bc494ca11e Initial load
duke
parents:
diff changeset
    18
# 2 along with this work; if not, write to the Free Software Foundation,
06bc494ca11e Initial load
duke
parents:
diff changeset
    19
# Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
06bc494ca11e Initial load
duke
parents:
diff changeset
    20
#
06bc494ca11e Initial load
duke
parents:
diff changeset
    21
# Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
06bc494ca11e Initial load
duke
parents:
diff changeset
    22
# CA 95054 USA or visit www.sun.com if you need additional information or
06bc494ca11e Initial load
duke
parents:
diff changeset
    23
# have any questions.
06bc494ca11e Initial load
duke
parents:
diff changeset
    24
#
06bc494ca11e Initial load
duke
parents:
diff changeset
    25
06bc494ca11e Initial load
duke
parents:
diff changeset
    26
# @test
06bc494ca11e Initial load
duke
parents:
diff changeset
    27
# @bug 4908512 5024825 4957203 4993280 4996963 6174696 6177059
06bc494ca11e Initial load
duke
parents:
diff changeset
    28
# @run shell ../verifyVariables.sh
06bc494ca11e Initial load
duke
parents:
diff changeset
    29
# @build Milk MethodAnnotations NestedClassAnnotations StaticFieldAnnotations StaticMethodAnnotations ParameterAnnotations 
06bc494ca11e Initial load
duke
parents:
diff changeset
    30
# @run shell apt.sh
06bc494ca11e Initial load
duke
parents:
diff changeset
    31
# @summary test consistency of annotation discovery
06bc494ca11e Initial load
duke
parents:
diff changeset
    32
# @author Joseph D. Darcy
06bc494ca11e Initial load
duke
parents:
diff changeset
    33
06bc494ca11e Initial load
duke
parents:
diff changeset
    34
OS=`uname -s`;
06bc494ca11e Initial load
duke
parents:
diff changeset
    35
case "${OS}" in
06bc494ca11e Initial load
duke
parents:
diff changeset
    36
        Windows* | CYGWIN* )
06bc494ca11e Initial load
duke
parents:
diff changeset
    37
                SEP=";"
06bc494ca11e Initial load
duke
parents:
diff changeset
    38
        ;;
06bc494ca11e Initial load
duke
parents:
diff changeset
    39
06bc494ca11e Initial load
duke
parents:
diff changeset
    40
	* )
06bc494ca11e Initial load
duke
parents:
diff changeset
    41
	SEP=":"
06bc494ca11e Initial load
duke
parents:
diff changeset
    42
	;;
06bc494ca11e Initial load
duke
parents:
diff changeset
    43
esac
06bc494ca11e Initial load
duke
parents:
diff changeset
    44
06bc494ca11e Initial load
duke
parents:
diff changeset
    45
# Construct path to apt executable
3378
22011d9a9398 6381698: Warn of decommissioning of apt
darcy
parents: 10
diff changeset
    46
APT="${TESTJAVA}/bin/apt ${TESTTOOLVMOPTS} -XDsuppress-tool-api-removal-message "
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    47
06bc494ca11e Initial load
duke
parents:
diff changeset
    48
printf "%s\n" "-classpath ${TESTCLASSES}"                    > options
06bc494ca11e Initial load
duke
parents:
diff changeset
    49
printf "%s\n" "-factorypath ./nullap.jar"                   >> options
06bc494ca11e Initial load
duke
parents:
diff changeset
    50
printf "%s\n" "-sourcepath ${TESTSRC} "                     >> options
06bc494ca11e Initial load
duke
parents:
diff changeset
    51
printf "%s\n" "-nocompile"                                  >> options
06bc494ca11e Initial load
duke
parents:
diff changeset
    52
printf "%s\n" "-XListAnnotationTypes"                       >> options
06bc494ca11e Initial load
duke
parents:
diff changeset
    53
06bc494ca11e Initial load
duke
parents:
diff changeset
    54
printf "%s\n" "-classpath ${TESTCLASSES}"                    > options1
06bc494ca11e Initial load
duke
parents:
diff changeset
    55
printf "%s\n" "-factorypath ./nullap.jar"                   >> options1
06bc494ca11e Initial load
duke
parents:
diff changeset
    56
printf "%s\n" "-sourcepath ${TESTSRC} "                     >> options1
06bc494ca11e Initial load
duke
parents:
diff changeset
    57
printf "%s\n" "-nocompile"                                  >> options1
06bc494ca11e Initial load
duke
parents:
diff changeset
    58
printf "%s\n" "-XListAnnotationTypes"                       >> options1
06bc494ca11e Initial load
duke
parents:
diff changeset
    59
printf "%s\n" "-XclassesAsDecls"                            >> options1
06bc494ca11e Initial load
duke
parents:
diff changeset
    60
3378
22011d9a9398 6381698: Warn of decommissioning of apt
darcy
parents: 10
diff changeset
    61
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    62
# Construct path to javac executable
06bc494ca11e Initial load
duke
parents:
diff changeset
    63
JAVAC="${TESTJAVA}/bin/javac ${TESTTOOLVMOPTS} -source 1.5 -sourcepath ${TESTSRC} -classpath ${TESTJAVA}/lib/tools.jar -d . "
06bc494ca11e Initial load
duke
parents:
diff changeset
    64
JAR="${TESTJAVA}/bin/jar "
06bc494ca11e Initial load
duke
parents:
diff changeset
    65
06bc494ca11e Initial load
duke
parents:
diff changeset
    66
$JAVAC ${TESTSRC}/NullAPF.java \
06bc494ca11e Initial load
duke
parents:
diff changeset
    67
${TESTSRC}/FreshnessApf.java  \
06bc494ca11e Initial load
duke
parents:
diff changeset
    68
${TESTSRC}/TestGetTypeDeclarationApf.java \
06bc494ca11e Initial load
duke
parents:
diff changeset
    69
${TESTSRC}/TestGetPackageApf.java
06bc494ca11e Initial load
duke
parents:
diff changeset
    70
RESULT=$?
06bc494ca11e Initial load
duke
parents:
diff changeset
    71
06bc494ca11e Initial load
duke
parents:
diff changeset
    72
case "${RESULT}" in
06bc494ca11e Initial load
duke
parents:
diff changeset
    73
        0  )
06bc494ca11e Initial load
duke
parents:
diff changeset
    74
        ;;
06bc494ca11e Initial load
duke
parents:
diff changeset
    75
06bc494ca11e Initial load
duke
parents:
diff changeset
    76
        * )
06bc494ca11e Initial load
duke
parents:
diff changeset
    77
        echo "Compilation failed."
06bc494ca11e Initial load
duke
parents:
diff changeset
    78
        exit 1
06bc494ca11e Initial load
duke
parents:
diff changeset
    79
esac
06bc494ca11e Initial load
duke
parents:
diff changeset
    80
06bc494ca11e Initial load
duke
parents:
diff changeset
    81
echo "Making services directory and copying services information."
06bc494ca11e Initial load
duke
parents:
diff changeset
    82
mkdir -p META-INF/services
06bc494ca11e Initial load
duke
parents:
diff changeset
    83
cp ${TESTSRC}/com.sun.mirror.apt.AnnotationProcessorFactory ./META-INF/services
06bc494ca11e Initial load
duke
parents:
diff changeset
    84
$JAR cvf0 nullap.jar NullAPF*.class META-INF
06bc494ca11e Initial load
duke
parents:
diff changeset
    85
06bc494ca11e Initial load
duke
parents:
diff changeset
    86
ANNOTATION_FILES="${TESTSRC}/ClassAnnotations.java \
06bc494ca11e Initial load
duke
parents:
diff changeset
    87
${TESTSRC}/MethodAnnotations.java \
06bc494ca11e Initial load
duke
parents:
diff changeset
    88
${TESTSRC}/NestedClassAnnotations.java \
06bc494ca11e Initial load
duke
parents:
diff changeset
    89
${TESTSRC}/StaticFieldAnnotations.java \
06bc494ca11e Initial load
duke
parents:
diff changeset
    90
${TESTSRC}/StaticMethodAnnotations.java \
06bc494ca11e Initial load
duke
parents:
diff changeset
    91
${TESTSRC}/ParameterAnnotations.java"
06bc494ca11e Initial load
duke
parents:
diff changeset
    92
06bc494ca11e Initial load
duke
parents:
diff changeset
    93
for i in ${ANNOTATION_FILES}
06bc494ca11e Initial load
duke
parents:
diff changeset
    94
do
06bc494ca11e Initial load
duke
parents:
diff changeset
    95
	printf "%s\n" "Testing annotations on source file ${i}"
06bc494ca11e Initial load
duke
parents:
diff changeset
    96
	${APT} @options ${i} 2> result.txt
06bc494ca11e Initial load
duke
parents:
diff changeset
    97
	diff ${TESTSRC}/golden.txt result.txt
06bc494ca11e Initial load
duke
parents:
diff changeset
    98
06bc494ca11e Initial load
duke
parents:
diff changeset
    99
	RESULT=$?
06bc494ca11e Initial load
duke
parents:
diff changeset
   100
	case "$RESULT" in
06bc494ca11e Initial load
duke
parents:
diff changeset
   101
	        0  )
06bc494ca11e Initial load
duke
parents:
diff changeset
   102
	        ;;
06bc494ca11e Initial load
duke
parents:
diff changeset
   103
06bc494ca11e Initial load
duke
parents:
diff changeset
   104
	        * )
06bc494ca11e Initial load
duke
parents:
diff changeset
   105
	        echo "Unexpected set of annotations on source files found."
06bc494ca11e Initial load
duke
parents:
diff changeset
   106
	        exit 1
06bc494ca11e Initial load
duke
parents:
diff changeset
   107
	esac
06bc494ca11e Initial load
duke
parents:
diff changeset
   108
06bc494ca11e Initial load
duke
parents:
diff changeset
   109
	CLASS=`basename ${i} .java`
06bc494ca11e Initial load
duke
parents:
diff changeset
   110
	printf "%s\n" "Testing annotations on class file ${CLASS}"
06bc494ca11e Initial load
duke
parents:
diff changeset
   111
	${APT} @options1 ${CLASS} 2> result2.txt
06bc494ca11e Initial load
duke
parents:
diff changeset
   112
	diff ${TESTSRC}/golden.txt result2.txt
06bc494ca11e Initial load
duke
parents:
diff changeset
   113
06bc494ca11e Initial load
duke
parents:
diff changeset
   114
	RESULT=$?
06bc494ca11e Initial load
duke
parents:
diff changeset
   115
	case "$RESULT" in
06bc494ca11e Initial load
duke
parents:
diff changeset
   116
	        0  )
06bc494ca11e Initial load
duke
parents:
diff changeset
   117
	        ;;
06bc494ca11e Initial load
duke
parents:
diff changeset
   118
06bc494ca11e Initial load
duke
parents:
diff changeset
   119
	        * )
06bc494ca11e Initial load
duke
parents:
diff changeset
   120
	        echo "Unexpected set of annotations on class files found."
06bc494ca11e Initial load
duke
parents:
diff changeset
   121
	        exit 1
06bc494ca11e Initial load
duke
parents:
diff changeset
   122
	esac
06bc494ca11e Initial load
duke
parents:
diff changeset
   123
done
06bc494ca11e Initial load
duke
parents:
diff changeset
   124
06bc494ca11e Initial load
duke
parents:
diff changeset
   125
# Verify source files are favored over class files
06bc494ca11e Initial load
duke
parents:
diff changeset
   126
06bc494ca11e Initial load
duke
parents:
diff changeset
   127
printf "%s\n" "-factorypath ."			 > options2
06bc494ca11e Initial load
duke
parents:
diff changeset
   128
printf "%s\n" "-factory FreshnessApf"		>> options2
06bc494ca11e Initial load
duke
parents:
diff changeset
   129
printf "%s\n" "-sourcepath ${TESTSRC}"		>> options2
06bc494ca11e Initial load
duke
parents:
diff changeset
   130
printf "%s\n" "-classpath  ${TESTCLASSES}"	>> options2
06bc494ca11e Initial load
duke
parents:
diff changeset
   131
printf "%s\n" "-nocompile"			>> options2
06bc494ca11e Initial load
duke
parents:
diff changeset
   132
06bc494ca11e Initial load
duke
parents:
diff changeset
   133
${APT} @options2 ${TESTSRC}/Indirect.java
06bc494ca11e Initial load
duke
parents:
diff changeset
   134
06bc494ca11e Initial load
duke
parents:
diff changeset
   135
RESULT=$?
06bc494ca11e Initial load
duke
parents:
diff changeset
   136
case "$RESULT" in
06bc494ca11e Initial load
duke
parents:
diff changeset
   137
        0  )
06bc494ca11e Initial load
duke
parents:
diff changeset
   138
        ;;
06bc494ca11e Initial load
duke
parents:
diff changeset
   139
06bc494ca11e Initial load
duke
parents:
diff changeset
   140
        * )
06bc494ca11e Initial load
duke
parents:
diff changeset
   141
        exit 1
06bc494ca11e Initial load
duke
parents:
diff changeset
   142
esac
06bc494ca11e Initial load
duke
parents:
diff changeset
   143
06bc494ca11e Initial load
duke
parents:
diff changeset
   144
# Verify new classes can be loaded by getTypeDeclaration
06bc494ca11e Initial load
duke
parents:
diff changeset
   145
06bc494ca11e Initial load
duke
parents:
diff changeset
   146
printf "%s\n" "-factorypath ."			 	> options3
06bc494ca11e Initial load
duke
parents:
diff changeset
   147
printf "%s\n" "-factory TestGetTypeDeclarationApf"	>> options3
06bc494ca11e Initial load
duke
parents:
diff changeset
   148
printf "%s\n" "-sourcepath ${TESTSRC}"			>> options3
06bc494ca11e Initial load
duke
parents:
diff changeset
   149
06bc494ca11e Initial load
duke
parents:
diff changeset
   150
# ${APT} @options3
06bc494ca11e Initial load
duke
parents:
diff changeset
   151
06bc494ca11e Initial load
duke
parents:
diff changeset
   152
RESULT=$?
06bc494ca11e Initial load
duke
parents:
diff changeset
   153
case "$RESULT" in
06bc494ca11e Initial load
duke
parents:
diff changeset
   154
        0  )
06bc494ca11e Initial load
duke
parents:
diff changeset
   155
        ;;
06bc494ca11e Initial load
duke
parents:
diff changeset
   156
06bc494ca11e Initial load
duke
parents:
diff changeset
   157
        * )
06bc494ca11e Initial load
duke
parents:
diff changeset
   158
        exit 1
06bc494ca11e Initial load
duke
parents:
diff changeset
   159
esac
06bc494ca11e Initial load
duke
parents:
diff changeset
   160
06bc494ca11e Initial load
duke
parents:
diff changeset
   161
# Verify packages can be loaded by getPackage
06bc494ca11e Initial load
duke
parents:
diff changeset
   162
06bc494ca11e Initial load
duke
parents:
diff changeset
   163
printf "%s\n" "-factorypath ."			 	> options4
06bc494ca11e Initial load
duke
parents:
diff changeset
   164
printf "%s\n" "-factory TestGetPackageApf"		>> options4
06bc494ca11e Initial load
duke
parents:
diff changeset
   165
printf "%s\n" "-sourcepath ${TESTSRC}"			>> options4
06bc494ca11e Initial load
duke
parents:
diff changeset
   166
06bc494ca11e Initial load
duke
parents:
diff changeset
   167
${APT} @options4
06bc494ca11e Initial load
duke
parents:
diff changeset
   168
06bc494ca11e Initial load
duke
parents:
diff changeset
   169
RESULT=$?
06bc494ca11e Initial load
duke
parents:
diff changeset
   170
case "$RESULT" in
06bc494ca11e Initial load
duke
parents:
diff changeset
   171
        0  )
06bc494ca11e Initial load
duke
parents:
diff changeset
   172
        ;;
06bc494ca11e Initial load
duke
parents:
diff changeset
   173
06bc494ca11e Initial load
duke
parents:
diff changeset
   174
        * )
06bc494ca11e Initial load
duke
parents:
diff changeset
   175
        exit 1
06bc494ca11e Initial load
duke
parents:
diff changeset
   176
esac
06bc494ca11e Initial load
duke
parents:
diff changeset
   177
exit 0