Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

add run'' script

  • Loading branch information...
commit f28e87c9ea9306404fcd09aef7c69751898e1843 1 parent 1c484ef
marius a. eriksen authored March 17, 2011

Showing 1 changed file with 125 additions and 0 deletions. Show diff stats Hide diff stats

  1. 125  lib/template/run
125  lib/template/run
... ...
@@ -0,0 +1,125 @@
  1
+#!/bin/bash
  2
+
  3
+function path_append {
  4
+  _var=$1
  5
+  _path=$2
  6
+  eval "
  7
+    if [[ -z \"\$$_var\" ]] ; then
  8
+      export $_var=$_path
  9
+    elif ! echo \$$_var | egrep -q \"(^|:)$_path($|:)\" ; then
  10
+      export $_var=\$$_var:$_path
  11
+    fi"
  12
+}
  13
+
  14
+function path_prepend() {
  15
+    _var=$1
  16
+    _path=$2
  17
+    eval "
  18
+    if [[ -z \"\$$_var\" ]] ; then
  19
+      export $_var=$_path
  20
+    elif ! echo \$$_var | egrep -q \"(^|:)$_path($|:)\" ; then
  21
+      export $_var=$_path:\$$_var
  22
+    fi"
  23
+}
  24
+
  25
+function find_sbt_root {
  26
+  while [ ! -d project -a "x$PWD" != "x/" ] ; do
  27
+    cd ..
  28
+  done
  29
+
  30
+  if [ "x$PWD" = "/" ]; then
  31
+    echo "couldn't find sbt project!" 1>&2
  32
+    exit 1
  33
+  fi
  34
+
  35
+  echo $PWD
  36
+}
  37
+
  38
+function ensure_java_bin_on_path {
  39
+  if [ -d "$JAVA_HOME" ]; then
  40
+      __java_bindir="$JAVA_HOME/bin"
  41
+  else
  42
+      __java_bindir=`which java | xargs readlink | xargs dirname`
  43
+  fi
  44
+
  45
+  if [ -x "$__java_bindir/java" ]; then
  46
+    path_append PATH $__java_bindir
  47
+  else
  48
+    echo "Binary 'java' is not on the PATH, and JAVA_HOME is not set. Fix one of these."
  49
+    exit 1
  50
+  fi
  51
+}
  52
+
  53
+function include {
  54
+  _var=$1
  55
+  _dir=$2
  56
+
  57
+  for jar in $_dir/lib_managed/compile/*.jar; do
  58
+    path_append $_var $jar
  59
+  done
  60
+
  61
+  for jar in $_dir/lib/*.jar; do
  62
+    path_append $_var $jar
  63
+  done
  64
+
  65
+  path_append $_var $_dir/src/main/resources
  66
+  path_append $_var $_dir/target/classes
  67
+}
  68
+
  69
+ensure_java_bin_on_path
  70
+
  71
+root=$(find_sbt_root)
  72
+if [ $? -ne 0 ]; then
  73
+  exit 1
  74
+fi
  75
+
  76
+if [ -z $project ]; then
  77
+  project="."
  78
+fi
  79
+
  80
+set -- $(getopt i:ygdh: "$@")
  81
+while [ $# -gt 0 ]; do
  82
+  case "$1" in
  83
+    -i)
  84
+      include CP $2
  85
+      ;;
  86
+    -y)
  87
+      JAVA_OPTS="-agentlib:yjpagent $JAVA_OPTS"
  88
+      ;;
  89
+    -g)
  90
+      GC_OPTS="-verbosegc -XX:+PrintGCDetails -XX:+PrintGCTimeStamps -XX:+PrintGCDateStamps -Xloggc:/tmp/gc.log"
  91
+      ;;
  92
+    -d)
  93
+      JAVA_OPTS="-Xdebug -Xrunjdwp:transport=dt_socket,address=8000,server=y,suspend=n $JAVA_OPTS"
  94
+      ;;
  95
+    -h)
  96
+      path_prepend DYLD_LIBRARY_PATH $2
  97
+      JAVA_OPTS="-Xbootclasspath/a:$2 -agentlib:heapster $JAVA_OPTS"
  98
+      ;;
  99
+    --) shift; break;;
  100
+  esac
  101
+  shift
  102
+done
  103
+
  104
+if [ $# -eq 0 ]; then
  105
+    echo "usage: $0 [-i INCLUDE] [-h HEAPSTER] [-ygd] CLASS ..." >&2
  106
+    echo "  -i INCLUDE include in the classpath the project with the sbt root INCLUDE" >&2 
  107
+    echo "  -h HEAPSTER use heapster in the directory HEAPSTER"  >&2
  108
+    echo "  -y enable yourkit debugging" >&2
  109
+    echo "  -g enable GC debugging/logging" >&2
  110
+    echo "  -d enable JVM debugging" >&2
  111
+    exit 1
  112
+fi
  113
+
  114
+## Set up the classpath. Scala base jars first.
  115
+path_prepend CP $root/project/boot/scala-2.8.1/lib/scala-library.jar
  116
+path_prepend CP $root/project/boot/scala-2.8.1/lib/scala-compiler.jar
  117
+
  118
+# This goes last:
  119
+include CP $root
  120
+
  121
+# Disable IPv6
  122
+export JAVA_OPTS="-Djava.net.preferIPv4Stack=true $JAVA_OPTS"
  123
+
  124
+export JAVA_OPTS="$JAVA_OPTS -server -Xmx2G -XX:MaxPermSize=256m -XX:+UseConcMarkSweepGC -XX:+UseParNewGC $GC_OPTS"
  125
+exec java $JAVA_OPTS -cp $CP "$@"

0 notes on commit f28e87c

Please sign in to comment.
Something went wrong with that request. Please try again.