mirror of https://github.com/jenv/jenv.git
32 changed files with 741 additions and 207 deletions
@ -0,0 +1,20 @@
@@ -0,0 +1,20 @@
|
||||
Copyright (c) 2013 Gildas Cuisinier |
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining |
||||
a copy of this software and associated documentation files (the |
||||
"Software"), to deal in the Software without restriction, including |
||||
without limitation the rights to use, copy, modify, merge, publish, |
||||
distribute, sublicense, and/or sell copies of the Software, and to |
||||
permit persons to whom the Software is furnished to do so, subject to |
||||
the following conditions: |
||||
|
||||
The above copyright notice and this permission notice shall be |
||||
included in all copies or substantial portions of the Software. |
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, |
||||
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF |
||||
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND |
||||
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE |
||||
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION |
||||
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION |
||||
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. |
||||
@ -0,0 +1,121 @@
@@ -0,0 +1,121 @@
|
||||
# Master your Java Environnement with jenv |
||||
|
||||
jenv is for Java, |
||||
|
||||
## How It Works |
||||
|
||||
|
||||
## Command Reference |
||||
|
||||
Like `git`, the `jenv` command delegates to subcommands based on its |
||||
first argument. The most common subcommands are: |
||||
|
||||
### jenv local |
||||
|
||||
Sets a local application-specific Java version by writing the version |
||||
name to a `.java-version` file in the current directory. This version |
||||
overrides the global version, and can be overridden itself by setting |
||||
the `JENV_VERSION` environment variable or with the `jenv shell` |
||||
command. |
||||
|
||||
$ jenv local 1.9.3-p327 |
||||
|
||||
When run without a version number, `jenv local` reports the currently |
||||
configured local version. You can also unset the local version: |
||||
|
||||
$ jenv local --unset |
||||
|
||||
Previous versions of jenv stored local version specifications in a |
||||
file named `.jenv-version`. For backwards compatibility, jenv will |
||||
read a local version specified in an `.jenv-version` file, but a |
||||
`.java-version` file in the same directory will take precedence. |
||||
|
||||
### jenv global |
||||
|
||||
Sets the global version of Java to be used in all shells by writing |
||||
the version name to the `~/.jenv/version` file. This version can be |
||||
overridden by an application-specific `.java-version` file, or by |
||||
setting the `JENV_VERSION` environment variable. |
||||
|
||||
$ jenv global oracle-1.6 |
||||
|
||||
The special version name `system` tells jenv to use the system Java |
||||
(detected by searching your `$PATH`). |
||||
|
||||
When run without a version number, `jenv global` reports the |
||||
currently configured global version. |
||||
|
||||
### jenv shell |
||||
|
||||
Sets a shell-specific Java version by setting the `JENV_VERSION` |
||||
environment variable in your shell. This version overrides |
||||
application-specific versions and the global version. |
||||
|
||||
$ jenv shell jJava-1.7.1 |
||||
|
||||
When run without a version number, `jenv shell` reports the current |
||||
value of `JENV_VERSION`. You can also unset the shell version: |
||||
|
||||
$ jenv shell --unset |
||||
|
||||
Note that you'll need jenv's shell integration enabled (step 3 of |
||||
the installation instructions) in order to use this command. If you |
||||
prefer not to use shell integration, you may simply set the |
||||
`JENV_VERSION` variable yourself: |
||||
|
||||
$ export JENV_VERSION=oracle-1.6 |
||||
|
||||
### jenv versions |
||||
|
||||
Lists all Java versions known to jenv, and shows an asterisk next to |
||||
the currently active version. |
||||
|
||||
$ jenv versions |
||||
oracle-1.6 |
||||
* oracle-1.7 (set by /Users/hikage/.jenv/version) |
||||
|
||||
### jenv version |
||||
|
||||
Displays the currently active Java version, along with information on |
||||
how it was set. |
||||
|
||||
$ jenv version |
||||
oracle-1.6 (set by /tmp/test/.java-version) |
||||
|
||||
### jenv rehash |
||||
|
||||
Installs shims for all Java executables known to jenv (i.e., |
||||
`~/.jenv/versions/*/bin/*`). Run this command after you install a new |
||||
version of Java. |
||||
|
||||
$ jenv rehash |
||||
|
||||
### jenv which |
||||
|
||||
Displays the full path to the executable that jenv will invoke when |
||||
you run the given command. |
||||
|
||||
$ jenv which java |
||||
/Users/sam/.jenv/versions/oracle-1.6/bin/java |
||||
|
||||
### jenv whence |
||||
|
||||
Lists all Java versions with the given command installed. |
||||
|
||||
$ jenv whence java |
||||
oracle-1.6 |
||||
oracle-1.7 |
||||
|
||||
## Development |
||||
|
||||
The jenv source code is [hosted on |
||||
GitHub](https://github.com/hikage/jenv). It's clean, modular, |
||||
and easy to understand, even if you're not a shell hacker. |
||||
|
||||
It is based on [rbenv](https://github.com/hikage/jenv). |
||||
|
||||
Please feel free to submit pull requests and file bugs on the [issue |
||||
tracker](https://github.com/hikage/jenv/issues). |
||||
|
||||
### Version History |
||||
|
||||
@ -0,0 +1,87 @@
@@ -0,0 +1,87 @@
|
||||
#!/usr/bin/env bash |
||||
set -e |
||||
|
||||
if [ "$1" = "--debug" ]; then |
||||
export JENV_DEBUG=1 |
||||
shift |
||||
fi |
||||
|
||||
if [ -n "$JENV_DEBUG" ]; then |
||||
export PS4='+ [${BASH_SOURCE##*/}:${LINENO}] ' |
||||
set -x |
||||
fi |
||||
|
||||
resolve_link() { |
||||
$(type -p greadlink readlink | head -1) "$1" |
||||
} |
||||
|
||||
abs_dirname() { |
||||
local cwd="$(pwd)" |
||||
local path="$1" |
||||
|
||||
while [ -n "$path" ]; do |
||||
cd "${path%/*}" |
||||
local name="${path##*/}" |
||||
path="$(resolve_link "$name" || true)" |
||||
done |
||||
|
||||
pwd |
||||
cd "$cwd" |
||||
} |
||||
|
||||
if [ -z "${JENV_ROOT}" ]; then |
||||
JENV_ROOT="${HOME}/.jenv" |
||||
else |
||||
JENV_ROOT="${JENV_ROOT%/}" |
||||
fi |
||||
export JENV_ROOT |
||||
|
||||
if [ -z "${JENV_DIR}" ]; then |
||||
JENV_DIR="$(pwd)" |
||||
else |
||||
cd "$JENV_DIR" 2>/dev/null || { |
||||
echo "jenv: cannot change working directory to \`$JENV_DIR'" |
||||
exit 1 |
||||
} >&2 |
||||
JENV_DIR="$(pwd)" |
||||
cd "$OLDPWD" |
||||
fi |
||||
export JENV_DIR |
||||
|
||||
|
||||
shopt -s nullglob |
||||
|
||||
bin_path="$(abs_dirname "$0")" |
||||
for plugin_bin in "${JENV_ROOT}/plugins/"*/bin; do |
||||
bin_path="${bin_path}:${plugin_bin}" |
||||
done |
||||
export PATH="${bin_path}:${PATH}" |
||||
|
||||
hook_path="${JENV_HOOK_PATH}:${JENV_ROOT}/jenv.d:/usr/local/etc/jenv.d:/etc/jenv.d:/usr/lib/jenv/hooks" |
||||
for plugin_hook in "${JENV_ROOT}/plugins/"*/etc/jenv.d; do |
||||
hook_path="${hook_path}:${plugin_hook}" |
||||
done |
||||
export JENV_HOOK_PATH="$hook_path" |
||||
|
||||
shopt -u nullglob |
||||
|
||||
|
||||
command="$1" |
||||
case "$command" in |
||||
"" | "-h" | "--help" ) |
||||
echo -e "$(jenv---version)\n$(jenv-help)" >&2 |
||||
;; |
||||
"-v" ) |
||||
exec jenv---version |
||||
;; |
||||
* ) |
||||
command_path="$(command -v "jenv-$command" || true)" |
||||
if [ -z "$command_path" ]; then |
||||
echo "jenv: no such command \`$command'" >&2 |
||||
exit 1 |
||||
fi |
||||
|
||||
shift 1 |
||||
exec "$command_path" "$@" |
||||
;; |
||||
esac |
||||
@ -0,0 +1,23 @@
@@ -0,0 +1,23 @@
|
||||
#!/usr/bin/env bash |
||||
# |
||||
# `ruby-local-exec` is a drop-in replacement for the standard Ruby |
||||
# shebang line: |
||||
# |
||||
# #!/usr/bin/env ruby-local-exec |
||||
# |
||||
# Use it for scripts inside a project with an `.jenv-version` |
||||
# file. When you run the scripts, they'll use the project-specified |
||||
# Ruby version, regardless of what directory they're run from. Useful |
||||
# for e.g. running project tasks in cron scripts without needing to |
||||
# `cd` into the project first. |
||||
|
||||
set -e |
||||
export JENV_DIR="${1%/*}" |
||||
|
||||
[ -n "$JENV_SILENCE_WARNINGS" ] || { |
||||
echo "jenv: \`ruby-local-exec' is deprecated and will be removed in the next release." |
||||
echo " To upgrade: https://github.com/sstephenson/jenv/wiki/ruby-local-exec" |
||||
echo |
||||
} >&2 |
||||
|
||||
exec ruby "$@" |
||||
@ -0,0 +1,21 @@
@@ -0,0 +1,21 @@
|
||||
#!/usr/bin/env bash |
||||
# Summary: Display the version of jenv |
||||
# |
||||
# Displays the version number of this jenv release, including the |
||||
# current revision from git, if available. |
||||
# |
||||
# The format of the git revision is: |
||||
# <version>-<num_commits>-<git_sha> |
||||
# where `num_commits` is the number of commits since `version` was |
||||
# tagged. |
||||
|
||||
set -e |
||||
[ -n "$JENV_DEBUG" ] && set -x |
||||
|
||||
version="0.1.0" |
||||
|
||||
cd "$JENV_ROOT" |
||||
git_revision="$(git describe --tags HEAD 2>/dev/null || true)" |
||||
git_revision="${git_revision#v}" |
||||
|
||||
echo "jenv ${git_revision:-$version}" |
||||
@ -1,88 +1,162 @@
@@ -1,88 +1,162 @@
|
||||
#!/usr/bin/env bash |
||||
# |
||||
# Summary: Display help for a command |
||||
# |
||||
# Usage: jenv help [--usage] COMMAND |
||||
# |
||||
# Parses and displays help contents from a command's source file. |
||||
# |
||||
# A command is considered documented if it starts with a comment block |
||||
# that has a `Summary:' or `Usage:' section. Usage instructions can |
||||
# span multiple lines as long as subsequent lines are indented. |
||||
# The remainder of the comment block is displayed as extended |
||||
# documentation. |
||||
|
||||
set -e |
||||
[ -n "$JENV_DEBUG" ] && set -x |
||||
|
||||
print_set_version() { |
||||
echo "<version> should be a string matching a Ruby version known by jenv." |
||||
command_path() { |
||||
local command="$1" |
||||
command -v jenv-"$command" || command -v jenv-sh-"$command" || true |
||||
} |
||||
|
||||
extract_initial_comment_block() { |
||||
sed -ne " |
||||
/^#/ !{ |
||||
q |
||||
} |
||||
|
||||
s/^#$/# / |
||||
|
||||
/^# / { |
||||
s/^# // |
||||
p |
||||
} |
||||
" |
||||
} |
||||
|
||||
collect_documentation() { |
||||
awk ' |
||||
/^Summary:/ { |
||||
summary = substr($0, 10) |
||||
next |
||||
} |
||||
|
||||
/^Usage:/ { |
||||
reading_usage = 1 |
||||
usage = usage "\n" $0 |
||||
next |
||||
} |
||||
|
||||
local versions="$(jenv-versions --bare)" |
||||
if [ -z "$versions" ]; then |
||||
echo "There are currently no Ruby versions installed for jenv." |
||||
/^( *$| )/ && reading_usage { |
||||
usage = usage "\n" $0 |
||||
next |
||||
} |
||||
|
||||
{ |
||||
reading_usage = 0 |
||||
help = help "\n" $0 |
||||
} |
||||
|
||||
function escape(str) { |
||||
gsub(/[`\\$"]/, "\\\\&", str) |
||||
return str |
||||
} |
||||
|
||||
function trim(str) { |
||||
sub(/^\n*/, "", str) |
||||
sub(/\n*$/, "", str) |
||||
return str |
||||
} |
||||
|
||||
END { |
||||
if (usage || summary) { |
||||
print "summary=\"" escape(summary) "\"" |
||||
print "usage=\"" escape(trim(usage)) "\"" |
||||
print "help=\"" escape(trim(help)) "\"" |
||||
} |
||||
} |
||||
' |
||||
} |
||||
|
||||
documentation_for() { |
||||
local filename="$(command_path "$1")" |
||||
if [ -n "$filename" ]; then |
||||
extract_initial_comment_block < "$filename" | collect_documentation |
||||
fi |
||||
} |
||||
|
||||
print_summary() { |
||||
local command="$1" |
||||
local summary usage help |
||||
eval "$(documentation_for "$command")" |
||||
|
||||
if [ -n "$summary" ]; then |
||||
printf " %-9s %s\n" "$command" "$summary" |
||||
fi |
||||
} |
||||
|
||||
print_summaries() { |
||||
for command; do |
||||
print_summary "$command" |
||||
done |
||||
} |
||||
|
||||
print_help() { |
||||
local command="$1" |
||||
local summary usage help |
||||
eval "$(documentation_for "$command")" |
||||
[ -n "$help" ] || help="$summary" |
||||
|
||||
if [ -n "$usage" -o -n "$summary" ]; then |
||||
if [ -n "$usage" ]; then |
||||
echo "$usage" |
||||
else |
||||
echo "Usage: jenv ${command}" |
||||
fi |
||||
if [ -n "$help" ]; then |
||||
echo |
||||
echo "$help" |
||||
echo |
||||
fi |
||||
else |
||||
echo "The currently installed Ruby versions are:" |
||||
echo "$versions" | sed 's/^/ /' |
||||
echo "Sorry, this command isn't documented yet." >&2 |
||||
return 1 |
||||
fi |
||||
} |
||||
|
||||
echo |
||||
echo "The special version string 'system' will use your default system Ruby." |
||||
print_usage() { |
||||
local command="$1" |
||||
local summary usage help |
||||
eval "$(documentation_for "$command")" |
||||
[ -z "$usage" ] || echo "$usage" |
||||
} |
||||
|
||||
case "$1" in |
||||
"") echo "usage: jenv <command> [<args>] |
||||
|
||||
Some useful jenv commands are: |
||||
commands List all jenv commands |
||||
rehash Rehash jenv shims (run this after installing binaries) |
||||
global Set or show the global Ruby version |
||||
local Set or show the local directory-specific Ruby version |
||||
shell Set or show the shell-specific Ruby version |
||||
version Show the current Ruby version |
||||
versions List all Ruby versions known by jenv |
||||
which Show the full path for the given Ruby command |
||||
whence List all Ruby versions with the given command |
||||
|
||||
See 'jenv help <command>' for information on a specific command. |
||||
For full documentation, see: https://github.com/sstephenson/jenv#readme" |
||||
;; |
||||
global) echo "usage: jenv global <version> |
||||
|
||||
Sets the global Ruby version. You can override the global version at |
||||
any time by setting a directory-specific version with \`jenv local' |
||||
or by setting the JENV_VERSION environment variable. |
||||
|
||||
$(print_set_version)" |
||||
;; |
||||
local) echo "usage: jenv local <version> |
||||
jenv local --unset |
||||
|
||||
Sets the local directory-specific Ruby version by writing the version |
||||
name to a file named '.jenv-version'. |
||||
|
||||
When you run a Ruby command, jenv will look for an '.jenv-version' |
||||
file in the current directory and each parent directory. If no such |
||||
file is found in the tree, jenv will use the global Ruby version |
||||
specified with \`jenv global', or the version specified in the |
||||
JENV_VERSION environment variable. |
||||
|
||||
$(print_set_version)" |
||||
;; |
||||
shell) echo "usage: jenv shell <version> |
||||
jenv shell --unset |
||||
|
||||
Sets a shell-specific Ruby version by setting the 'JENV_VERSION' |
||||
environment variable in your shell. This version overrides both |
||||
project-specific versions and the global version. |
||||
|
||||
$(print_set_version)" |
||||
;; |
||||
which) echo "usage: jenv which <command> |
||||
|
||||
Displays the full path to the binary that jenv will execute when you |
||||
run the given command." |
||||
;; |
||||
whence) echo "usage: jenv whence <command> |
||||
|
||||
Lists all Ruby versions with the given command installed." |
||||
;; |
||||
*) |
||||
command_path="$(command -v "jenv-$1" || true)" |
||||
if [ -n "$command_path" ]; then |
||||
echo "Sorry, the \`$1' command isn't documented yet." |
||||
echo |
||||
echo "You can view the command's source here:" |
||||
echo "$command_path" |
||||
echo |
||||
unset usage |
||||
if [ "$1" = "--usage" ]; then |
||||
usage="1" |
||||
shift |
||||
fi |
||||
|
||||
if [ -z "$1" ] || [ "$1" == "jenv" ]; then |
||||
echo "Usage: jenv <command> [<args>]" |
||||
[ -z "$usage" ] || exit |
||||
echo |
||||
echo "Some useful jenv commands are:" |
||||
print_summaries commands local global shell install uninstall rehash version versions which whence |
||||
echo |
||||
echo "See \`jenv help <command>' for information on a specific command." |
||||
echo "For full documentation, see: https://github.com/sstephenson/jenv#readme" |
||||
else |
||||
command="$1" |
||||
if [ -n "$(command_path "$command")" ]; then |
||||
if [ -n "$usage" ]; then |
||||
print_usage "$command" |
||||
else |
||||
print_help "$command" |
||||
fi |
||||
else |
||||
echo "jenv: no such command \`$1'" |
||||
echo "jenv: no such command \`$command'" >&2 |
||||
exit 1 |
||||
fi |
||||
esac |
||||
fi |
||||
|
||||
@ -0,0 +1,27 @@
@@ -0,0 +1,27 @@
|
||||
#!/usr/bin/env bash |
||||
set -e |
||||
[ -n "$JENV_DEBUG" ] && set -x |
||||
|
||||
# Provide jenv completions |
||||
if [ "$1" = "--complete" ]; then |
||||
echo --unset |
||||
echo system |
||||
exec jenv-versions --bare |
||||
fi |
||||
|
||||
JENV_VERSION="$1" |
||||
JENV_JAVAPATH="$2" |
||||
JENV_VERSION_FILE=".jenv-version" |
||||
|
||||
echo $JENV_VERSION |
||||
echo $JENV_JAVAPATH |
||||
|
||||
|
||||
|
||||
if [ -f "$JENV_JAVAPATH/bin/java" ]; |
||||
then |
||||
ln -s "$JENV_JAVAPATH" "${JENV_ROOT}/versions/$JENV_VERSION" |
||||
$(jenv-rehash) |
||||
else |
||||
echo "$JENV_JAVAPATH is not a valid path to java installation" |
||||
fi |
||||
@ -1,2 +1,3 @@
@@ -1,2 +1,3 @@
|
||||
#!/usr/bin/env bash |
||||
# Summary: Display the root directory where versions and shims are kept |
||||
echo $JENV_ROOT |
||||
|
||||
@ -0,0 +1,13 @@
@@ -0,0 +1,13 @@
|
||||
#!/usr/bin/env bash |
||||
set -e |
||||
[ -n "$JENV_DEBUG" ] && set -x |
||||
|
||||
# Provide jenv completions |
||||
if [ "$1" = "--complete" ]; then |
||||
exec jenv-rehash --complete |
||||
fi |
||||
|
||||
# When jenv shell integration is enabled, delegate to jenv-rehash, |
||||
# then tell the shell to empty its command lookup cache. |
||||
jenv-rehash |
||||
echo "hash -r" |
||||
@ -1,27 +1,39 @@
@@ -1,27 +1,39 @@
|
||||
#!/usr/bin/env bash |
||||
# Summary: List all Ruby versions available to jenv |
||||
# Usage: jenv versions [--bare] |
||||
# |
||||
# Lists all Ruby versions found in `$JENV_ROOT/versions/*'. |
||||
|
||||
set -e |
||||
[ -n "$JENV_DEBUG" ] && set -x |
||||
|
||||
JENV_VERSION_NAME="$(jenv-version-name)" |
||||
|
||||
if [ "$1" = "--bare" ]; then |
||||
hit_prefix="" |
||||
miss_prefix="" |
||||
print_version="$JENV_VERSION_NAME" |
||||
current_version="" |
||||
include_system="" |
||||
else |
||||
hit_prefix="* " |
||||
miss_prefix=" " |
||||
print_version="$(jenv-version)" |
||||
current_version="$(jenv-version-name || true)" |
||||
include_system="1" |
||||
fi |
||||
|
||||
print_version() { |
||||
if [ "$1" == "$current_version" ]; then |
||||
echo "${hit_prefix}$(jenv-version 2>/dev/null)" |
||||
else |
||||
echo "${miss_prefix}$1" |
||||
fi |
||||
} |
||||
|
||||
# Include "system" in the non-bare output, if it exists |
||||
if [ -n "$include_system" ] && JENV_VERSION=system jenv-which ruby >/dev/null 2>&1; then |
||||
print_version system |
||||
fi |
||||
|
||||
for path in "${JENV_ROOT}/versions/"*; do |
||||
if [ -d "$path" ]; then |
||||
version="${path##*/}" |
||||
|
||||
if [ "$version" == "$JENV_VERSION_NAME" ]; then |
||||
echo "${hit_prefix}${print_version}" |
||||
else |
||||
echo "${miss_prefix}${version}" |
||||
fi |
||||
print_version "${path##*/}" |
||||
fi |
||||
done |
||||
|
||||
Loading…
Reference in new issue