ApplicationSetup.sh revision 2078
1040N/A#!/bin/sh
3261N/A
1040N/A#
1040N/A# Copyright 2005 Sun Microsystems, Inc. All Rights Reserved.
1040N/A# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
1040N/A#
1040N/A# This code is free software; you can redistribute it and/or modify it
1040N/A# under the terms of the GNU General Public License version 2 only, as
1040N/A# published by the Free Software Foundation.
1040N/A#
1040N/A# This code is distributed in the hope that it will be useful, but WITHOUT
1040N/A# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
1040N/A# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
1040N/A# version 2 for more details (a copy is included in the LICENSE file that
1040N/A# accompanied this code).
1040N/A#
1040N/A# You should have received a copy of the GNU General Public License version
1040N/A# 2 along with this work; if not, write to the Free Software Foundation,
2362N/A# Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
2362N/A#
2362N/A# Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
1040N/A# CA 95054 USA or visit www.sun.com if you need additional information or
1040N/A# have any questions.
1040N/A#
1040N/A
1040N/A
1040N/A#
1040N/A#
1040N/A# Application Setup - creates ${TESTCLASSES}/Application.jar and the following
1040N/A# procedures:
1040N/A# startApplication - starts target application
1040N/A# stopApplication $1 - stops application via TCP shutdown port $1
1040N/A
1040N/A$JAVAC -d "${TESTCLASSES}" "${TESTSRC}"/Application.java "${TESTSRC}"/Shutdown.java
1040N/A$JAR -cfm "${TESTCLASSES}"/Application.jar "${TESTSRC}"/application.mf \
2736N/A -C "${TESTCLASSES}" Application.class
2736N/A
2736N/AOUTPUTFILE=${TESTCLASSES}/Application.out
2736N/Arm -f ${OUTPUTFILE}
2736N/A
2736N/AstartApplication()
2736N/A{
2736N/A ${JAVA} $1 $2 $3 -jar "${TESTCLASSES}"/Application.jar > ${OUTPUTFILE} &
2736N/A pid="$!"
1040N/A
1040N/A # MKS creates an intermediate shell to launch ${JAVA} so
1040N/A # ${pid} is not the actual pid. We have put in a small sleep
1040N/A # to give the intermediate shell process time to launch the
1040N/A # "java" process.
1040N/A if [ "$OS" = "Windows" ]; then
1040N/A sleep 2
1040N/A if [ "${isCygwin}" = "true" ] ; then
1040N/A realpid=`ps -p ${pid} | tail -1 | awk '{print $4;}'`
1040N/A else
1040N/A realpid=`ps -o pid,ppid,comm|grep ${pid}|grep "java"|cut -c1-6`
1040N/A fi
1040N/A pid=${realpid}
1040N/A fi
1040N/A
2736N/A echo "Waiting for Application to initialize..."
1040N/A attempts=0
1040N/A while true; do
1040N/A sleep 1
1040N/A port=`tail -1 ${OUTPUTFILE} | sed -e 's@\\r@@g' `
1040N/A if [ ! -z "$port" ]; then
2736N/A # In case of errors wait time for output to be flushed
1040N/A sleep 1
1040N/A cat ${OUTPUTFILE}
1040N/A break
1040N/A fi
1040N/A attempts=`expr $attempts + 1`
1040N/A echo "Waiting $attempts second(s) ..."
1040N/A done
echo "Application is process $pid, shutdown port is $port"
return $port
}
stopApplication()
{
$JAVA -classpath "${TESTCLASSES}" Shutdown $1
}