|
1 | 1 | #!/bin/bash |
2 | 2 |
|
3 | | -dir=`dirname $0` |
| 3 | +METAFACTURE_HOME=$( dirname "$( realpath "$0" )" ) |
4 | 4 |
|
5 | | -jarfile="${project.build.finalName}.jar" |
| 5 | +# Fix path if running under cygwin: |
| 6 | +if uname | grep -iq cygwin ; then |
| 7 | + METAFACTURE_HOME=$( cygpath -am "$METAFACTURE_HOME" ) |
| 8 | +fi |
| 9 | + |
| 10 | +# Use the java command available on the path by default. |
| 11 | +# Define FLUX_JAVA_BIN in your environment to use a |
| 12 | +# different executable. |
| 13 | +if [ -z "$FLUX_JAVA_BIN" ] ; then |
| 14 | + FLUX_JAVA_BIN=java |
| 15 | +fi |
| 16 | + |
| 17 | +java_opts_file="$METAFACTURE_HOME/config/java-options.conf" |
| 18 | +jar_file="$METAFACTURE_HOME/${project.build.finalName}.jar" |
| 19 | + |
| 20 | +# Load java options from configuration file. Lines starting |
| 21 | +# with # are treated as comments. Empty lines are ignored. |
| 22 | +java_opts=$( cat "$java_opts_file" | grep -v "^#" | tr "\n\r" " " ) |
6 | 23 |
|
7 | | -if uname | grep -iq cygwin; then |
8 | | - java -Xmx512M -jar "`cygpath -am $dir/$jarfile`" $* |
9 | | -else |
10 | | - java -Xmx512M -jar "$dir/$jarfile" $* |
| 24 | +# Substitute environment variables. Undefined variables |
| 25 | +# remain in the configuration. Since FLUX_JAVA_OPTIONS is |
| 26 | +# included in the configuration by default we make sure that |
| 27 | +# it can always be substituted. |
| 28 | +if [ -z "$FLUX_JAVA_OPTIONS" ] ; then |
| 29 | + FLUX_JAVA_OPTIONS= |
11 | 30 | fi |
| 31 | +# This sed script turns the output of set into a sed script |
| 32 | +# which replaces the dollar prefixed name of each environment |
| 33 | +# variable with its value: |
| 34 | +vars_to_script=$( cat <<'EOF' |
| 35 | + s/\\/\\\\/g ; |
| 36 | + s/!/\\!/g ; |
| 37 | + s/='(.*)'$/=\1/ ; |
| 38 | + s/^([^=]+)=(.*)$/s!\\$\1!\2!g ; /g |
| 39 | +EOF |
| 40 | +) |
| 41 | +substitute_vars_script=$( set | sed -r "$vars_to_script" ) |
| 42 | +# Substitute environment variables in the java options: |
| 43 | +java_opts=$( echo "$java_opts" | sed "$substitute_vars_script") |
12 | 44 |
|
| 45 | +# Turn java options string into an array to allow passing |
| 46 | +# the options as command parameters. Options may be partially |
| 47 | +# quoted with single or double quotes and may contain |
| 48 | +# escape sequences. Quotes are removed after splitting because |
| 49 | +# the shell quotes the parameters again: |
| 50 | +option_pattern="[^\"' ]*(\"[^\"\\]*(\\\\.[^\"\\]*)*\"|'[^'\\]*(\\\\.[^'\\]*)*'|\\.[^\"' ]*)*" |
| 51 | +remove_quotes="s/(^[\"'])|(([^\\])[\"'])/\3/g" |
| 52 | +java_opts_array=() |
| 53 | +while read line ; do |
| 54 | + line=$( echo "$line" | sed -r "$remove_quotes" ) |
| 55 | + java_opts_array+=("$line") |
| 56 | +done < <( echo "$java_opts" | grep -Eo "$option_pattern" ) |
13 | 57 |
|
| 58 | +# Start flux: |
| 59 | +"$FLUX_JAVA_BIN" "${java_opts_array[@]}" -jar "$jar_file" "$@" |
0 commit comments