aboutsummaryrefslogtreecommitdiff
path: root/vo/java/topcat
blob: 0c5909a9d33f01cf972a780c86731d28f220a7a7 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
#!/bin/sh

#+
#  Name:
#     topcat

#  Purpose:
#     Invokes the TOPCAT application on unix

#  Description:
#     This shell script invokes the TOPCAT application.
#     It's not very complicated, but performs some argument manipulation
#     prior to invoking java with the right classpath and classname.
#
#     1. if a class path is specified using either the CLASSPATH
#        environment variable or the -classpath flag to this script,
#        it will be added to the application classpath
#
#     2. any command-line arguments which look like they are destined
#        for java itself (starting with -D or -X, or prefixed with -J) will
#        be sent to java, and the others will be sent to the application

#  Requisites:
#     - java should be on the path.
#
#     - relative to the directory in which this script is installed,
#       one of the following jar files should exist and contain the
#       TOPCAT classes:
#          ./topcat-full.jar
#          ./topcat-lite.jar
#          ../../lib/topcat/topcat.jar

#  Authors:
#     MBT: Mark Taylor (Starlink)
#-

# Set locations of acceptable jar files (relative to this script).
topcat_jars="\
 ../lib/topcat/topcat.jar\
 topcat-full.jar\
 topcat-lite.jar\
"

#  Find where this script is located.
bindir="`dirname $0`"

# Mac-specific items.
javaArgs0=""
if test -x /usr/bin/sw_vers && /usr/bin/sw_vers | grep -q 'OS.X'; then

   # Look for the jar in the resource bundle, since we may have been
   # installed that way.
   topcat_jars="$topcat_jars ../Contents/Resources/Java/topcat-full.jar ../TOPCAT.app/Contents/Resources/Java/topcat-full.jar"

   # Look for an icon file and prepare to start java in such a way that
   # it gets used for the dock icon (rather than the generic java one).
   icns_files="../TOPCAT.app/Contents/Resources/Topcat.icns ../lib/topcat/MacOS/Topcat.icns"
   icns_file=""
   for f in $icns_files; do
      if test -r "$bindir/$f"; then
         icns_file="$bindir/$f"
      fi
   done
   if test -r "$icns_file" && java -X | grep -q -- -Xdock:icon; then
      javaArgs0="$javaArgs0 "\'-Xdock:icon=$icns_file\'
   fi

   # Set Mac application name.
   javaArgs0="$javaArgs0 -Dcom.apple.mrj.application.apple.menu.about.name=TOPCAT"
fi

#  Locate the application jar file. 
for j in $topcat_jars; do
   if test -z "$appjar" -a -f "$bindir/$j"; then
      appjar="$bindir/$j"
   fi
done
if test ! -f "$appjar"
then
   echo 1>&2 "Can't find topcat classes in ${bindir} - looked for:$topcat_jars"
   exit 1
fi

#  Divide the arguments into two parts: those destined as flags for
#  the java binary, and the rest.
javaArgs=""
appArgs=""
while test "$1"
do
   if echo $1 | grep -- '^-[XD]' >/dev/null; then
      javaArgs="$javaArgs "\'$1\'
   elif echo $1 | grep -- '^-J' >/dev/null; then
      javaArgs="$javaArgs "\'`echo $1 | sed s/^-J//`\'
   elif [ "$1" = "-classpath" -a -n "$2" ]; then
      shift
      export CLASSPATH="$1"
   else
      appArgs="$appArgs "\'$1\'
   fi
   shift
done

#  Check for Cygwin and transform paths.
case "`uname`" in
  CYGWIN*) 
    if test -n "$CLASSPATH"; then
       CLASSPATH=`cygpath --path --windows "${appjar}:$CLASSPATH"`
    else
       CLASSPATH=`cygpath --windows "${appjar}"`
    fi
  ;;
  *)
    CLASSPATH="${appjar}:${CLASSPATH}"
  ;;
esac

#  Run topcat.
cmd="java \
        $javaArgs0 \
        $javaArgs \
        -Duk.ac.starlink.topcat.cmdname=topcat \
        -classpath \${CLASSPATH} uk.ac.starlink.topcat.Driver \
        $appArgs"
eval "$cmd"