test/com/sun/tools/attach/ApplicationSetup.sh

Print this page




  24 #
  25 
  26 
  27 #
  28 #
  29 # Application Setup - creates ${TESTCLASSES}/Application.jar and the following
  30 # procedures:
  31 #       startApplication - starts target application
  32 #       stopApplication $1 - stops application via TCP shutdown port $1
  33 
  34 $JAVAC -d "${TESTCLASSES}" "${TESTSRC}"/Application.java "${TESTSRC}"/Shutdown.java
  35 $JAR -cfm "${TESTCLASSES}"/Application.jar "${TESTSRC}"/application.mf \
  36   -C "${TESTCLASSES}" Application.class
  37 
  38 OUTPUTFILE=${TESTCLASSES}/Application.out
  39 rm -f ${OUTPUTFILE}
  40 
  41 startApplication() 
  42 {
  43   # put all output from the app into ${OUTPUTFILE}
  44   ${JAVA} $1 $2 $3 -jar "${TESTCLASSES}"/Application.jar > ${OUTPUTFILE} 2>&1 &
  45   pid="$!"
  46 
  47   # MKS creates an intermediate shell to launch ${JAVA} so
  48   # ${pid} is not the actual pid. We have put in a small sleep
  49   # to give the intermediate shell process time to launch the
  50   # "java" process.
  51   if [ "$OS" = "Windows" ]; then
  52     sleep 2
  53     if [ "${isCygwin}" = "true" ] ; then
  54       realpid=`ps -p ${pid} | tail -1 | awk '{print $4;}'`
  55     else
  56       realpid=`ps -o pid,ppid,comm|grep ${pid}|grep "java"|cut -c1-6`
  57     fi
  58     pid=${realpid}
  59   fi
  60                                                                                                                   
  61   echo "Waiting for Application to initialize..."
  62   attempts=0
  63   while true; do
  64     sleep 1
  65     port=`tail -1 ${OUTPUTFILE} | sed -e 's@\\r@@g' `
  66     if [ ! -z "$port" ]; then
  67       # In case of errors wait time for output to be flushed
  68       sleep 1
  69       cat ${OUTPUTFILE}
  70       break
  71     fi
  72     attempts=`expr $attempts + 1`
  73     echo "Waiting $attempts second(s) ..."
  74   done
  75   echo "Application is process $pid, shutdown port is $port"
  76   return $port
  77 }
  78 
  79 stopApplication() 
  80 {
  81   $JAVA -classpath "${TESTCLASSES}" Shutdown $1
  82 }
  83 


  24 #
  25 
  26 
  27 #
  28 #
  29 # Application Setup - creates ${TESTCLASSES}/Application.jar and the following
  30 # procedures:
  31 #       startApplication - starts target application
  32 #       stopApplication $1 - stops application via TCP shutdown port $1
  33 
  34 $JAVAC -d "${TESTCLASSES}" "${TESTSRC}"/Application.java "${TESTSRC}"/Shutdown.java
  35 $JAR -cfm "${TESTCLASSES}"/Application.jar "${TESTSRC}"/application.mf \
  36   -C "${TESTCLASSES}" Application.class
  37 
  38 OUTPUTFILE=${TESTCLASSES}/Application.out
  39 rm -f ${OUTPUTFILE}
  40 
  41 startApplication() 
  42 {
  43   # put all output from the app into ${OUTPUTFILE}
  44   ${JAVA} ${TESTVMOPTS} $1 $2 $3 -jar "${TESTCLASSES}"/Application.jar > ${OUTPUTFILE} 2>&1 &
  45   pid="$!"
  46 
  47   # MKS creates an intermediate shell to launch ${JAVA} so
  48   # ${pid} is not the actual pid. We have put in a small sleep
  49   # to give the intermediate shell process time to launch the
  50   # "java" process.
  51   if [ "$OS" = "Windows" ]; then
  52     sleep 2
  53     if [ "${isCygwin}" = "true" ] ; then
  54       realpid=`ps -p ${pid} | tail -1 | awk '{print $4;}'`
  55     else
  56       realpid=`ps -o pid,ppid,comm|grep ${pid}|grep "java"|cut -c1-6`
  57     fi
  58     pid=${realpid}
  59   fi
  60                                                                                                                   
  61   echo "Waiting for Application to initialize..."
  62   attempts=0
  63   while true; do
  64     sleep 1
  65     port=`tail -1 ${OUTPUTFILE} | sed -e 's@\\r@@g' `
  66     if [ ! -z "$port" ]; then
  67       # In case of errors wait time for output to be flushed
  68       sleep 1
  69       cat ${OUTPUTFILE}
  70       break
  71     fi
  72     attempts=`expr $attempts + 1`
  73     echo "Waiting $attempts second(s) ..."
  74   done
  75   echo "Application is process $pid, shutdown port is $port"
  76   return $port
  77 }
  78 
  79 stopApplication() 
  80 {
  81   $JAVA ${TESTVMOPTS} -classpath "${TESTCLASSES}" Shutdown $1
  82 }
  83