#!/bin/sh # Shell script that starts up Ptolemy II Java classes # Author: Christopher Hylands # Version: $Id: ptinvoke.in,v 1.74 2002/05/15 23:01:40 cxh Exp $ # # Copyright (c) 1998-2002 The Regents of the University of California. # All Rights Reserved. # # Permission is hereby granted, without written agreement and without # license or royalty fees, to use, copy, modify, and distribute this # software and its documentation for any purpose, provided that the # above copyright notice and the following two paragraphs appear in all # copies of this software. # # IN NO EVENT SHALL THE UNIVERSITY OF CALIFORNIA BE LIABLE TO ANY PARTY # FOR DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES # ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF # THE UNIVERSITY OF CALIFORNIA HAS BEEN ADVISED OF THE POSSIBILITY OF # SUCH DAMAGE. # # THE UNIVERSITY OF CALIFORNIA SPECIFICALLY DISCLAIMS ANY WARRANTIES, # INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF # MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE # PROVIDED HEREUNDER IS ON AN "AS IS" BASIS, AND THE UNIVERSITY OF # CALIFORNIA HAS NO OBLIGATION TO PROVIDE MAINTENANCE, SUPPORT, UPDATES, # ENHANCEMENTS, OR MODIFICATIONS. # # PT_COPYRIGHT_VERSION_2 # COPYRIGHTENDKEY # If this script is named 'ptolemy', 'ptplot', or 'vergil', don't edit it! # instead, edit ptinvoke.in and run configure # # configure substitutes in variables that are surrounded with @, # #### Generic stuff. # Location of the Ptolemy II tree. The bin directory should be found # at $PTIIDEFAULT/bin PTII_DEFAULT="@PTII_DEFAULT@" # Check that PTII is set, and that we can find the proper sources if [ -z "$PTII" ]; then if [ -d "$PTII_DEFAULT" ]; then PTII="$PTII_DEFAULT" export PTII fi if [ ! -d "$PTII/$javasourcedir" ]; then echo "$0: Could not find '$PTII/$javasourcedir'. Perhaps your PTII" echo " variable is not set properly?" fi fi # Default JDK Home, may have /cygdrive in it PTJAVA_DIR="@PTJAVA_DIR@" # PTJAVA_DIR without /cygdrive PTJAVA_DIR_CLEAN="`echo "$PTJAVA_DIR" | sed 's@/cygdrive/\([a-z]\)@\1:@'`" # Java CLASSPATH separator # For Unix, this would be : # For Cygwin, this would be ; CLASSPATHSEPARATOR="@CLASSPATHSEPARATOR@" #### Jini stuff. # Jini directory JINI_DIR="@JINI_DIR@" # Jini lib directory JINI_LIB_DIR="$JINI_DIR/lib" # Flags needed for Jini JINI_JFLAG=\""-Djava.security.policy=${PTII}/bin/policy.all -Doutrigger.spacename=JavaSpaces -Dcom.sun.jini.lookup.groups=public -Djava.rmi.server.codebase=http://localhost:4444/"\" # Jini Jar files JINI_CORE_JAR="${JINI_LIB_DIR}/jini-core.jar" JINI_JSPACES_JAR="${JINI_LIB_DIR}/jini-jspaces.jar" JINI_MAHALO_JAR="${JINI_LIB_DIR}/mahalo-dl.jar" JINI_JARS="${JINI_JSPACES_JAR}${CLASSPATHSEPARATOR}${JINI_MAHALO_JAR}" #### Jacl stuff # Location of ptjacl.jar PTJACL_JAR="@PTJACL_JAR@" # Flag to pass to java. Solaris JDK1.2 reference version needs -native PTJACL_JFLAG="@PTJACL_JFLAG@" # Jar file for JHDL JHDL_JAR="@JHDL_JAR@" #### Serial port stuff # Directory that contains the Java Serial Comm API, see # http://java.sun.com/products/javacomm/ COMMAPI_DIR="@COMMAPI_DIR@" # If Commapi is present, then set to yes, otherwise set to no COMMAPI_PRESENT="@COMMAPI_PRESENT@" # The location of comm.jar COMMAPI_JAR="" if [ "$COMMAPI_PRESENT" ]; then COMMAPI_JAR="${CLASSPATHSEPARATOR}${COMMAPI_DIR}/comm.jar" fi #### Diva stuff # The diva jar file. DIVA_JAR="${PTII}/lib/diva.jar" DIVA_JFLAG= #### Jode.. Java decompiler # The jode jar file. # JODE_JAR might contain ${JODE_DIR) JODE_DIR="@JODE_DIR@" JODE_JAR="@JODE_CLASSES@" JODE_JFLAG= #### Soot.. Java compiler and optimizer package. Jasmin: a java assembler. # The soot and jasmin jar files. SOOT_DIR="@SOOT_DIR@" JAVA_SYSTEM_JAR="@JAVA_SYSTEM_JAR@" SOOT_JAR="@SOOT_CLASSES@" SOOT_JFLAG= # PTCOPERNICUS_DIR is non empty if soot is present. PTCOPERNICUS_DIR=@PTCOPERNICUS_DIR@ # SOOT_JARS has the classpath separator prepended. SOOT_JARS="" if [ "$PTCOPERNICUS_DIR" ]; then SOOT_JARS="${CLASSPATHSEPARATOR}${SOOT_JAR}" fi #### All the jar files. Useful for Vergil and ptolemy rules which must load # arbitrary files ALL_JAR="${DIVA_JAR}${CLASSPATHSEPARATOR}${JINI_JARS}${COMMAPI_JAR}${SOOT_JARS}${CLASSPATHSEPARATOR}${PTJACL_JAR}" ALL_JFLAG="${DIVA_JFLAG} ${JINI_JFLAG}" #### Sandbox # Use a fairly tight sandbox to provide security when running models if [ "$1" = "-sandbox" ]; then shift ALL_JFLAG="-Djava.security.manager \"-Djava.security.policy=${PTII}/bin/sandbox.policy\"" ALL_JAR="${DIVA_JAR}" echo "Running in sandbox mode with minimal set of jars." if [ $# -eq 0 ]; then echo "Note that the file browser does not work well in the sandbox" echo " To run a model, specify the model on the command line:" echo " vergil -sandbox \"$PTII/ptolemy/moml/demo/modulation.xml\"" echo " -----" fi fi # Optional jar file jarfile="$ALL_JAR" # javaflag contains optional flags passed to java that may be # set by this script # JAVAFLAGS may be set by the user to pass a user selected flag # to java. For example # setenv JAVAFLAGS -Djava.compiler= # ptolemy foo.xml # will turn off the Just In Time (JIT) compiler, which will # result in exception messages with line numbers. # To see what sort of options are available, type 'java -h' # To see what sort of properties are available, type # echo "source $PTII/util/testsuite/jdktools.tcl; jdkProperties; exit" | ptjacl # javaflag="$ALL_JFLAG" # Keep these alphabetical case `basename "$0"` in copernicus) # Do deep codegen javastartupclass=ptolemy.copernicus.kernel.Copernicus javasourcedir= ;; decompile) # Call either jode or javap if [ -f "$JODE_JAR" ]; then javastartupclass=jode.decompiler.Main javasourcedir= jarfile="$JODE_JAR$CLASSPATHSEPARATOR$JHDL_JAR" javaflag="$JODE_JFLAG" else echo "Jode was not found when $PTII/configure was run, " echo " so we are running javap instead." echo " To run Jode, download Jode from:" echo " http://jode.sourceforge.net/download.php" echo " and run: " echo " cd $PTII; rm config.*; ./configure; cd bin; make" fi ;; histogram) # Histogram Plotter javastartupclass=ptolemy.plot.plotml.HistogramMLApplication javasourcedir=ptolemy/plot/plotml ;; htmlconverter) # Java Plug-in applet converter javastartupclass=HTMLConverter jarfile="$PTJAVA_DIR_CLEAN/lib/htmlconverter.jar" if [ ! -f "$jarfile" ]; then echo "$0: '$jarfile' does not exist or is not a file" exit 2 fi PTII_CLEAN="`echo "$PTII" | sed 's@\\\@/@g'`" applicationflags="-template \"$PTII_CLEAN/doc/coding/templates/ptExtend.tpl\"" ;; jode) # JAva decompiler javastartupclass=jode.decompiler.Main javasourcedir= jarfile="$JODE_JAR$CLASSPATHSEPARATOR$JHDL_JAR" javaflag="$JODE_JFLAG" ;; obfuscate) # JAva decompiler javastartupclass=jode.obfuscator.Main javasourcedir= jarfile="$JODE_JAR$CLASSPATHSEPARATOR$JHDL_JAR" javaflag="$JODE_JFLAG" ;; mescal) # Mescal UI javastartupclass=mescal.MescalApplication javasourcedir=mescal jarfile="$ALL_JAR$CLASSPATHSEPARATOR$PTII/mescal/lib/jsat.jar$CLASSPATHSEPARATOR$PTII/mescal/lib/mescal_java_cup.jar" javaflag="$ALL_JFLAG \"-DmescalBinaries=$PTII/mescal/bin\"" ;; moml) # Moml application # This has no default configuration, run moml when you want # to run your own graphical editor, for example: # moml myBiggerBetterVergilConfiguration.xml foo.xml javastartupclass=ptolemy.actor.gui.MoMLApplication javasourcedir= jarfile="$ALL_JAR" javaflag="$ALL_JFLAG" ;; ptexecute) # This takes over what CompositeActorApplication used to do (with the # addition that you can give it either class files or MoML files). # That is, it instantiates models, and all the models that are # instances of CompositeActor, it runs. javastartupclass=ptolemy.actor.gui.PtExecuteApplication javasourcedir= ;; ptinvoke) # Invoke the class named by the first argument javastartupclass=$1 javasourcedir= jarfile="$ALL_JAR" javaflag="$ALL_JFLAG" shift ;; ptjacl) # tcl.lang.Shell brings up the Jacl prompt in the current window javastartupclass=tcl.lang.Shell javasourcedir= jarfile="$PTJACL_JAR$CLASSPATHSEPARATOR$ALL_JAR$CLASSPATHSEPARATOR$SOOT_JAR" javaflag="$PTJACL_FLAG" ;; ptjaclapp) # tcl.lang.PanelShellApp brings up Jacl in a separate window javastartupclass=tcl.lang.PanelShellApp javasourcedir= jarfile="$PTJACL_JAR" javaflag="$PTJACL_FLAG" ;; ptstartjini) # Ptolemy II Application that starts up Jini javastartupclass=com.sun.jini.example.service.StartService javasourcedir=ptolemy/actor/gui jarfile="$JINI_LIB_DIR/jini-examples.jar" case "${OSTYPE-no}" in cygwin*) JINI_ROOT_DIR=`echo $JINI_DIR | sed 's@/@\\\\@g' | sed 's@\\\jini1_0_1@@'` javaflag="-Dcom.sun.jini.example.service.rootDir=\"$JINI_ROOT_DIR\"" ;; *) JINI_ROOT_DIR=`echo $JINI_DIR | sed 's/jini1_0_1//'` javaflag="-Dcom.sun.jini.example.service.rootDir=$JINI_ROOT_DIR" ;; esac ;; ptjini) # Ptolemy II Application that uses Jini javastartupclass=ptolemy.actor.gui.PtolemyApplication javasourcedir=ptolemy/actor/gui jarfile="$ALL_JAR" javaflag="$ALL_JFLAG" ;; ptolemy) # Ptolemy II Application # Bring up a control panel for each model rather than running it # like ptinvoke. javastartupclass=ptolemy.actor.gui.PtolemyApplication javasourcedir=ptolemy/actor/gui # Please don't add jini or commapi to ptolemy. # If you want to start up jini or commapi, the run ptjini -cxh 7/00 jarfile="${DIVA_JAR}" javaflag="${DIVA_JFLAG}" ;; ptplot) # Signal Plotter javastartupclass=ptolemy.plot.plotml.EditablePlotMLApplication javasourcedir=ptolemy/plot/plotml ;; pxgraph) # Plotter compatible with old X11 pxgraph javastartupclass=ptolemy.plot.compat.PxgraphApplication javasourcedir=ptolemy/plot/compat ;; soot) # Soot optimizer javastartupclass=soot.Main javasourcedir= jarfile="$SOOT_JAR" javaflag="$SOOT_JFLAG" ;; vergil) # Ptolemy II UI javastartupclass=ptolemy.vergil.VergilApplication javasourcedir=ptolemy/vergil jarfile="$ALL_JAR" javaflag="$ALL_JFLAG" ;; esac # Special check for Jacl with a better error message if [ "$jarfile" = "$PTJACL_JAR" ]; then if [ ! -f "$PTJACL_JAR" ]; then echo "$0: Warning '$PTJACL_JAR' not found." echo " ptjacl.jar can be found at" echo " http://ptolemy.eecs.berkeley.edu/~cxh/java/jacl/ptjacl.html" echo " You only need run Jacl if you want to run the Ptolemy II" echo " test suites." fi fi # Determine if we are on windows and try to set JAVAHOME windows=no if [ "${OSTYPE-no}" = "no" ]; then case "`uname -s`" in CYGWIN*) windows=yes;; # Tcsh Windows*) windows=yes;; esac else case "${OSTYPE-no}" in # Cygwin Bash cygwin*) windows=yes;; # Tcsh Windows*) windows=yes;; esac fi # If JAVAHOME is not set, then try to set it if [ -z "$JAVAHOME" ]; then if [ -d "$PTJAVA_DIR" ]; then JAVAHOME="$PTJAVA_DIR" export JAVAHOME else if [ "$windows" = "yes" ]; then searchfile=java.exe else searchfile=java fi oldifs="$IFS"; IFS=":" for i in $PATH do if [ -x "$i/$searchfile" -a ! -d "$i/$searchfile" ]; then JAVAHOME=`dirname $i` export JAVAHOME break fi done IFS="$oldifs" fi if [ -z "$JAVAHOME" ]; then if [ -d "/usr/eesww/lang/jdk1.1latest" ]; then # Locally, Java can sometimes be found here. JAVAHOME=/usr/eesww/lang/jdk1.1latest fi fi if [ -z "$JAVAHOME" ]; then echo "$0: Could not find $searchfile in your \$PATH" echo " Please set \$JAVAHOME to the directory that contains your" echo " Java distribution" exit 3 fi fi javac="\$JAVAHOME/bin/java" jdbflags="" quiet=0 # ${1#-} will not work under Solaris 8 #while [ "${1#-}" != "$1" ]; do while [ "$1" != "" -a "`echo $1 | egrep '^-'`" = "$1" ]; do # If -debug is supplied then allow debugger attaches to java VM. # Run "jdb -attach javadebug" to attach debugger to JVM. if [ "$1" = "-debug" ]; then # TODO: jvm interface selection based on platform. This works on Windows jdbflags="-Xdebug -Xrunjdwp:transport=dt_shmem,server=y,suspend=n" shift continue fi # If -jdb is supplied then run jdb instead of java. if [ "$1" = "-jdb" ]; then javac="\$JAVAHOME/bin/jdb" shift continue fi if [ "$1" = "-q" ]; then # Do not echo the command. Useful for batch mode (repeated test runs) # to reduce stdout clutter quiet=1 shift continue fi if [ "$1" = "-profiler" ]; then # This could be done "manually" through JAVAFLAGS, but here it is canned javaflag="-Xrunhprof:cpu=samples,format=a $javaflag" shift continue fi # If we get to here, we saw an argument with a leading -, but it # was not one of the args we were looking for. break; done # Unfortunately, there are issues around setting PTII if your # Cygwin installation is installed in c:/cygwin. # Briefly, if Cygwin is installed in c:/cygwin, and your ptII tree # is installed in c:/ptII, then if you cd to c:/ptII and do 'pwd', # in bash, you will get something like /cygdrive/c/ptII/, which # will not work with the JDK. For details, see # $PTII/doc/install.htm#setting.htm if [ "$windows" = "yes" ]; then # Windows via Cygwin32 # chdir prints the current directory in DOS format. # The tr command deletes the \r at the end case "`uname -s`" in CYGWIN_98-*) # Windows 98 is not a real os, and it does not have CMD. # So, we punt PTII_DIR=$PTII;; *) PTII_DIR=`(cd "$PTII"; cmd /c chdir) | tr -d '\r'` esac # Set the path to include $PTII/bin so that the Matlab interface # will work. # Unfortunately, we need to change things like d: to /cygdrive/d, # and deal with backslashes. Note that java does not understand # /cygdrive, so we can't use PTII_CYGDRIVE when we invoke java. PTII_CYGDRIVE=`echo "$PTII_DIR" | sed 's@^\([a-zA-Z]\):@/cygdrive/\1@' | sed 's@\\\\@//@'` # It would be nice to check if the PTII_CYGDRIVE was already in the PATH. PATH="${PTII_CYGDRIVE};$PATH" export PATH base=`/usr/bin/basename "$0"` else PTII_DIR=$PTII base=`basename "$0"` fi # Add the user classpath (we prepend to be able to override classes, # but Berkeley prefers to append, so append) if [ "$CLASSPATH" != "" ]; then CLASSPATH="$PTII_DIR$CLASSPATHSEPARATOR$jarfile${CLASSPATHSEPARATOR}${CLASSPATH}" else CLASSPATH="$PTII_DIR$CLASSPATHSEPARATOR$jarfile" fi if [ "$base" = "decompile" -a ! -f "$JODE_JAR" ]; then str="\"$JAVAHOME/bin/javap\" -classpath \"$CLASSPATH\" ${1+"$@"}" else # If JAVAHOME has spaces in it, we need to jump through hoops str="\"$javac\" $jdbflags $javaflag \"-Dptolemy.ptII.dir=$PTII\" $JAVAFLAGS -classpath \"$CLASSPATH\" $javastartupclass $applicationflags ${1+"$@"}" fi if [ "$quiet" = "0" ]; then echo $str;fi eval exec $str