mirror of https://github.com/jenv/jenv.git
26 changed files with 302 additions and 37 deletions
@ -0,0 +1,26 @@
@@ -0,0 +1,26 @@
|
||||
#!/usr/bin/env bash |
||||
# |
||||
# Summary: Set or show the global Java options |
||||
# |
||||
# Usage: jenv global <options> |
||||
# |
||||
# Sets the global Java options. You can override the global options at |
||||
# any time by setting a directory-specific options with `jenv local-options' |
||||
# or by setting the `JENV_OPTIONS' environment variable. |
||||
# |
||||
# <options> should be a string matching a Java options known to jenv. |
||||
# The special options string `system' will use your default system Java. |
||||
# Run `jenv optionss' for a list of available Java optionss. |
||||
|
||||
set -e |
||||
[ -n "$JENV_DEBUG" ] && set -x |
||||
|
||||
|
||||
JENV_OPTIONS="$1" |
||||
JENV_OPTIONS_FILE="${JENV_ROOT}/options" |
||||
|
||||
if [ -n "$JENV_OPTIONS" ]; then |
||||
jenv-options-file-write "$JENV_OPTIONS_FILE" "$JENV_OPTIONS" |
||||
else |
||||
jenv-options-file-read "$JENV_OPTIONS_FILE" |
||||
fi |
||||
@ -0,0 +1,63 @@
@@ -0,0 +1,63 @@
|
||||
#!/usr/bin/env bash |
||||
# |
||||
# Summary: Run an executable with the selected Java version |
||||
# |
||||
# Usage: jenv exec <command> [arg1 arg2...] |
||||
# |
||||
# Runs an executable by first preparing PATH so that the selected Java |
||||
# version's `bin' directory is at the front. |
||||
# |
||||
# For example, if the currently selected Java version is 1.9.3-p327: |
||||
# jenv exec bundle install |
||||
# |
||||
# is equivalent to: |
||||
# PATH="$JENV_ROOT/versions/1.9.3-p327/bin:$PATH" bundle install |
||||
|
||||
set -e |
||||
[ -n "$JENV_DEBUG" ] && set -x |
||||
|
||||
|
||||
|
||||
exportVariable(){ |
||||
exportedKey[$1]=$1; |
||||
exportedValue[$2]=$2; |
||||
export $1=$2 |
||||
} |
||||
|
||||
# Provide jenv completions |
||||
if [ "$1" = "--complete" ]; then |
||||
exec jenv shims --short |
||||
fi |
||||
|
||||
export JENV_VERSION="$(jenv-version-name)" |
||||
|
||||
export JENV_OPTIONS="$(jenv-options)" |
||||
|
||||
|
||||
JENV_COMMAND="$1" |
||||
|
||||
export JAVA_HOME="$JENV_ROOT/versions/$JENV_VERSION" |
||||
|
||||
|
||||
|
||||
|
||||
JENV_COMMAND_PATH="$(jenv-which "$JENV_COMMAND")" |
||||
JENV_BIN_PATH="${JENV_COMMAND_PATH%/*}" |
||||
|
||||
|
||||
for script in $(jenv-hooks exec); do |
||||
source "$script" |
||||
done |
||||
|
||||
shift 1 |
||||
if [ "$JENV_VERSION" != "system" ]; then |
||||
export PATH="${JENV_BIN_PATH}:${PATH}" |
||||
fi |
||||
echo "Jenv will exec : $JENV_COMMAND_PATH" $JENV_OPTIONS "$@" |
||||
echo "Exported variables : " |
||||
for i in "${!exportedKey[@]}" |
||||
do |
||||
key="${exportedKey[$i]}" |
||||
value=${exportedValue[$key]} |
||||
echo "$key=$value" |
||||
done |
||||
@ -0,0 +1,38 @@
@@ -0,0 +1,38 @@
|
||||
#!/usr/bin/env bash |
||||
# |
||||
# Summary: Set or show the local application-specific JVM options |
||||
# |
||||
# Usage: jenv local <jvm options> |
||||
# jenv local --unset |
||||
# |
||||
# Sets the local application-specific JVM Options by writing the |
||||
# options to a file named `.java-options'. |
||||
# |
||||
# When you run a Java command, jenv will look for a `.java-options' |
||||
# file in the current directory and each parent directory. If no such |
||||
# file is found in the tree, jenv will use the global Java Options |
||||
# specified with `jenv global'. A version specified with the |
||||
# `JENV_JAVAOPT' environment variable takes precedence over local |
||||
# and global versions. |
||||
# |
||||
|
||||
set -e |
||||
[ -n "$JENV_DEBUG" ] && set -x |
||||
|
||||
# Provide jenv completions |
||||
if [ "$1" = "--complete" ]; then |
||||
echo --unset |
||||
fi |
||||
|
||||
JENV_JAVAOPT="$1" |
||||
|
||||
if [ "$JENV_JAVAOPT" = "--unset" ]; then |
||||
rm -f .java-options |
||||
elif [ -n "$JENV_JAVAOPT" ]; then |
||||
jenv-options-file-write .java-options "$JENV_JAVAOPT" |
||||
else |
||||
jenv-options-file-read .java-options || |
||||
{ echo "jenv: no local JVM options configured for this directory" |
||||
exit 1 |
||||
} >&2 |
||||
fi |
||||
@ -0,0 +1,21 @@
@@ -0,0 +1,21 @@
|
||||
#!/usr/bin/env bash |
||||
# Summary: Show the current Java version |
||||
set -e |
||||
[ -n "$JENV_DEBUG" ] && set -x |
||||
|
||||
if [ -z "$JENV_OPTIONS" ]; then |
||||
JENV_OPTIONS_FILE="$(jenv-options-file)" |
||||
JENV_OPTIONS="$(jenv-options-file-read "$JENV_OPTIONS_FILE" || true)" |
||||
fi |
||||
|
||||
if [ -z "$JENV_OPTIONS" ] ; then |
||||
echo "" |
||||
exit |
||||
fi |
||||
|
||||
|
||||
if [ "$1" = "--verbose" ] ; then |
||||
echo "$JENV_OPTIONS (set by $(jenv-options-origin))" |
||||
else |
||||
echo "$JENV_OPTIONS" |
||||
fi; |
||||
@ -0,0 +1,26 @@
@@ -0,0 +1,26 @@
|
||||
#!/usr/bin/env bash |
||||
# Summary: Detect the file that sets the current jenv jvm options |
||||
set -e |
||||
[ -n "$JENV_DEBUG" ] && set -x |
||||
|
||||
find_local_version_file() { |
||||
local root="$1" |
||||
while [ -n "$root" ]; do |
||||
if [ -e "${root}/.java-options" ]; then |
||||
echo "${root}/.java-options" |
||||
exit |
||||
fi |
||||
root="${root%/*}" |
||||
done |
||||
} |
||||
|
||||
find_local_version_file "$JENV_DIR" |
||||
[ "$JENV_DIR" = "$PWD" ] || find_local_version_file "$PWD" |
||||
|
||||
global_version_file="${JENV_ROOT}/options" |
||||
|
||||
if [ -e "$global_version_file" ]; then |
||||
echo "$global_version_file" |
||||
else |
||||
echo "$global_version_file" |
||||
fi |
||||
@ -0,0 +1,20 @@
@@ -0,0 +1,20 @@
|
||||
#!/usr/bin/env bash |
||||
# Usage: jenv options-file-read <file> |
||||
set -e |
||||
[ -n "$JENV_DEBUG" ] && set -x |
||||
|
||||
OPTIONS_FILE="$1" |
||||
|
||||
if [ -e "$OPTIONS_FILE" ]; then |
||||
# Read the first non-whitespace word from the specified options file. |
||||
# Be careful not to load it whole in case there's something crazy in it. |
||||
options=$(head -n 1 $OPTIONS_FILE) |
||||
|
||||
|
||||
if [ -n "$options" ]; then |
||||
echo "$options" |
||||
exit |
||||
fi |
||||
fi |
||||
|
||||
exit 1 |
||||
@ -0,0 +1,18 @@
@@ -0,0 +1,18 @@
|
||||
#!/usr/bin/env bash |
||||
# Usage: jenv options-file-write <file> <options> |
||||
|
||||
set -e |
||||
[ -n "$JENV_DEBUG" ] && set -x |
||||
|
||||
JENV_OPTIONS_FILE="$1" |
||||
JENV_OPTIONS="$2" |
||||
|
||||
if [ -z "$JENV_OPTIONS" ] || [ -z "$JENV_OPTIONS_FILE" ]; then |
||||
jenv-help --usage options-file-write >&2 |
||||
exit 1 |
||||
fi |
||||
|
||||
|
||||
|
||||
# Write the options out to disk. |
||||
echo "$JENV_OPTIONS" > "$JENV_OPTIONS_FILE" |
||||
@ -0,0 +1,10 @@
@@ -0,0 +1,10 @@
|
||||
#!/usr/bin/env bash |
||||
# Summary: Explain how the current Java version is set |
||||
set -e |
||||
[ -n "$JENV_DEBUG" ] && set -x |
||||
|
||||
if [ -n "$JENV_OPTIONS" ]; then |
||||
echo "JENV_OPTIONS environment variable" |
||||
else |
||||
jenv-options-file |
||||
fi |
||||
@ -0,0 +1,36 @@
@@ -0,0 +1,36 @@
|
||||
#!/usr/bin/env bash |
||||
# |
||||
# Summary: Set or show the shell-specific Java options |
||||
# |
||||
# Usage: jenv shell <options> |
||||
# jenv shell --unset |
||||
# |
||||
# Sets a shell-specific Java options by setting the `JENV_OPTIONS' |
||||
# environment variable in your shell. This options overrides local |
||||
# application-specific optionss and the global options. |
||||
# |
||||
# <options> should be a string matching a Java options known to jenv. |
||||
|
||||
set -e |
||||
[ -n "$JENV_DEBUG" ] && set -x |
||||
|
||||
|
||||
options="$1" |
||||
|
||||
if [ -z "$options" ]; then |
||||
if [ -z "$JENV_OPTIONS" ]; then |
||||
echo "jenv: no shell-specific options configured" >&2 |
||||
exit 1 |
||||
else |
||||
echo "echo \"\$JENV_OPTIONS\"" |
||||
exit |
||||
fi |
||||
fi |
||||
|
||||
if [ "$options" = "--unset" ]; then |
||||
echo "unset JENV_OPTIONS" |
||||
exit |
||||
fi |
||||
|
||||
|
||||
echo "export JENV_OPTIONS=\"${options}\"" |
||||
@ -0,0 +1,4 @@
@@ -0,0 +1,4 @@
|
||||
if [ "$1" = "ant" ]; then |
||||
exportVariable ANT_OPTS $JENV_OPTIONS |
||||
unset JENV_OPTIONS |
||||
fi |
||||
@ -1 +0,0 @@
@@ -1 +0,0 @@
|
||||
echo "Before Ant" |
||||
@ -0,0 +1,4 @@
@@ -0,0 +1,4 @@
|
||||
if [ "$1" = "gradle" ]; then |
||||
exportVariable GRADLE_OPTS $JENV_OPTIONS |
||||
unset JENV_OPTIONS |
||||
fi |
||||
@ -1 +0,0 @@
@@ -1 +0,0 @@
|
||||
echo "Before Gradle" |
||||
Loading…
Reference in new issue