diff options
author | Rafael H. Schloming <rhs@apache.org> | 2006-09-19 22:06:50 +0000 |
---|---|---|
committer | Rafael H. Schloming <rhs@apache.org> | 2006-09-19 22:06:50 +0000 |
commit | 913489deb2ee9dbf44455de5f407ddaf4bd8c540 (patch) | |
tree | 7ea442d6867d0076f1c9ea4f4265664059e7aff5 /java/common/bin/qpid-run | |
download | qpid-python-913489deb2ee9dbf44455de5f407ddaf4bd8c540.tar.gz |
Import of qpid from etp:
URL: https://etp.108.redhat.com/svn/etp/trunk/blaze
Repository Root: https://etp.108.redhat.com/svn/etp
Repository UUID: 06e15bec-b515-0410-bef0-cc27a458cf48
Revision: 608
git-svn-id: https://svn.apache.org/repos/asf/incubator/qpid/trunk/qpid@447994 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'java/common/bin/qpid-run')
-rw-r--r-- | java/common/bin/qpid-run | 176 |
1 files changed, 176 insertions, 0 deletions
diff --git a/java/common/bin/qpid-run b/java/common/bin/qpid-run new file mode 100644 index 0000000000..ef2348d45e --- /dev/null +++ b/java/common/bin/qpid-run @@ -0,0 +1,176 @@ +#!/bin/bash +# +# Copyright (c) 2006 The Apache Software Foundation +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +die() { + if [[ $1 = -usage ]]; then + shift + usage=true + else + usage=false + fi + echo "$@" + $usage && echo + $usage && usage + exit 1 +} + +if [ -z "$QPID_HOME" ]; then + die "QPID_HOME must be set" +fi + +program=$(basename $0) +sourced=${BASH_SOURCE[0]} +if [[ -z ${sourced:-''} ]]; then + sourced=$(which qpid-run) || ${QPID_HOME}/bin/qpid-run +fi + +usage() { + echo Usage: $program ... "[-run:<option>]" ... + echo + echo Options: + egrep -B 1 "^\s*#USAGE: " ${sourced} |\ + sed "s/#USAGE:/ /" |\ + sed "s/-run:\(.*\))/-run:\1/" |\ + sed "s/-run:\(.*\)=\*/-run:\1=<value>/" |\ + sed "s/^--$//" +} + +cygwin=false +if [[ "$(uname -a | fgrep Cygwin)" != "" ]]; then + cygwin=true +fi + +export EXTERNAL_CLASSPATH=$CLASSPATH +unset CLASSPATH + +conf=$QPID_HOME/etc/$program.conf +if [ ! -e $conf ]; then + conf=$QPID_HOME/etc/$(basename ${sourced}).conf +fi + +if [ -r $conf ]; then + . $conf +else + die "unable to source $conf" +fi + +declare -a RUN_ARGS JAVA_ARGS +for arg in "$@"; do + if [[ $arg == -run:* ]]; then + RUN_ARGS[${#RUN_ARGS[@]}]="$arg" + else + JAVA_ARGS[${#JAVA_ARGS[@]}]="$arg" + fi +done + +# this defines the default behavior, it may be modified during option +# processing below +DISPATCH() { + if $debug; then + echo "CLASSPATH=${CLASSPATH}" + echo "${COMMAND[@]}" + fi + + exec "${COMMAND[@]}" +} + +exclusive() { + if [ -z "$PREVIOUS_ARGS" ]; then + PREVIOUS_ARGS=$1 + else + PREVIOUS_ARGS+=", $1" + DISPATCH() { + die -usage "you must choose one of: $PREVIOUS_ARGS" + } + fi +} + +debug=false + +for arg in "${RUN_ARGS[@]}"; do + case $arg in + -run:debug) +#USAGE: print the classpath and command before running it + debug=true + ;; + -run:jpda) +#USAGE: adds debugging options to the java command, use +#USAGE: JDPA_TRANSPORT and JPDA_ADDRESS to customize the debugging +#USAGE: behavior and use JPDA_OPTS to override it entirely + if [ -z "$JPDA_OPTS" ]; then + JPDA_OPTS="-Xdebug -Xrunjdwp:transport=${JPDA_TRANSPORT:-dt_socket},address=${JPDA_ADDRESS:-8000},server=y,suspend=n" + fi + QPID_OPTS+=" ${JPDA_OPTS}" + ;; + -run:external-classpath=*) +#USAGE: controls how the CLASSPATH environment variable is used by +#USAGE: this script, value can be one of ignore (the default), first, +#USAGE: last, and only + case $arg in + *=ignore) + # do nothing + ;; + *=first) + CLASSPATH=$EXTERNAL_CLASSPATH:$CLASSPATH + ;; + *=last) + CLASSPATH=$CLASSPATH:$EXTERNAL_CLASSPATH + ;; + *=only) + CLASSPATH=$EXTERNAL_CLASSPATH + ;; + *) + die -usage $(echo $arg | sed "s/=/: invalid value '/")\' + ;; + esac + ;; + -run:print-classpath) +#USAGE: print the classpath + DISPATCH() { + echo $CLASSPATH + } + exclusive $arg + ;; + -run:print-command) +#USAGE: print the command + DISPATCH() { + echo "${COMMAND[@]}" + } + exclusive $arg + ;; + -run:help) +#USAGE: print this message + DISPATCH() { + usage + } + exclusive $arg + ;; + *) + die -usage "unrecognized -run option '$arg'" + ;; + esac +done + +if $cygwin; then + QPID_HOME=$(cygpath -w $QPID_HOME) + CLASSPATH=$(cygpath -w -p $CLASSPATH) + JAVA=$(cygpath -u $JAVA) +fi + +COMMAND=($JAVA $JAVA_VM $JAVA_MEM -DQPID_HOME=$QPID_HOME $JAVA_OPTS $QPID_OPTS "${JAVA_ARGS[@]}") + +DISPATCH |