mirror of
https://github.com/halcyon/asdf-java.git
synced 2024-10-06 07:42:09 +08:00
Switching to new architecture. Previous architecture archived to skotchpine
branch
This commit is contained in:
parent
f6c327a770
commit
a39f3bbb79
21
LICENSE
21
LICENSE
@ -1,21 +0,0 @@
|
||||
MIT License
|
||||
|
||||
Copyright (c) 2017 William Tyler Cinnamon
|
||||
|
||||
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.
|
83
README.md
83
README.md
@ -1,83 +0,0 @@
|
||||
# asdf-java
|
||||
|
||||
[![travis ci](https://travis-ci.org/skotchpine/asdf-java.svg?branch=master)](https://travis-ci.org/skotchpine/asdf-java)
|
||||
|
||||
[Java](https://www.java.com/en/) plugin for the [asdf](https://github.com/asdf-vm/asdf) version manager.
|
||||
|
||||
## Install
|
||||
|
||||
After installing [asdf](https://github.com/asdf-vm/asdf),
|
||||
you can add this plugin like this:
|
||||
|
||||
```bash
|
||||
asdf plugin-add java
|
||||
```
|
||||
|
||||
and install new versions like this:
|
||||
|
||||
```bash
|
||||
asdf install java openjdk-11.0.1
|
||||
```
|
||||
|
||||
and switch versions like this:
|
||||
|
||||
```bash
|
||||
asdf global java openjdk-11.0.1
|
||||
```
|
||||
|
||||
If you want or need `JAVA_HOME` set you can load our `asdf` wrapper to your shell initialization (in `.bashrc`, for example):
|
||||
|
||||
```bash
|
||||
. ~/.asdf/plugins/java/asdf-java-wrapper.bash
|
||||
```
|
||||
|
||||
Or in `.zshrc`
|
||||
|
||||
```zsh
|
||||
. ~/.asdf/plugins/java/asdf-java-wrapper.zsh
|
||||
```
|
||||
|
||||
If you need to disable colors, try:
|
||||
|
||||
```bash
|
||||
export ASDF_JAVA_PLAIN=truthy
|
||||
```
|
||||
|
||||
If you need Gradle or Maven, you can use asdf plugins for those, too.
|
||||
|
||||
```bash
|
||||
asdf plugin-add maven https://github.com/skotchpine/asdf-maven
|
||||
asdf plugin-add gradle https://github.com/rfrancis/asdf-gradle
|
||||
```
|
||||
|
||||
## Obey
|
||||
|
||||
By using this software you agree to:
|
||||
|
||||
- [Oracle Binary Code License Agreement for the Java SE Platform Products and JavaFX](http://www.oracle.com/technetwork/java/javase/terms/license/index.html)
|
||||
- [Oracle Technology Network Early Adopter Development License Agreement](http://www.oracle.com/technetwork/licenses/ea-license-noexhibits-1938914.html) in case of EA releases
|
||||
- Apple's Software License Agreement in case of "Java for OS X"
|
||||
- [International License Agreement for Non-Warranted Programs](http://www14.software.ibm.com/cgi-bin/weblap/lap.pl?la_formnum=&li_formnum=L-PMAA-A3Z8P2&l=en) in case of IBM SDK, Java Technology Edition.
|
||||
|
||||
## Reading
|
||||
|
||||
Read the [asdf readme](https://github.com/asdf-vm/asdf)
|
||||
for instructions on how to install and manage versions of any language.
|
||||
|
||||
If you have trouble with any expected features,
|
||||
have any feature requests or want to contribute,
|
||||
please [do an issue](https://github.com/skotchpine/asdf-java/issues).
|
||||
|
||||
## Homage
|
||||
|
||||
This plugin wouldn't be possible without the current Java version managers.
|
||||
Here's a list of repos with similar affects that were heavily referenced here:
|
||||
|
||||
- [jabba](https://github.com/hsyiko/jabba)
|
||||
- [sdkman](https://github.com/sdkman/sdkman-cli)
|
||||
- [Arch's JDK](https://aur.archlinux.org/packages/jdk/)
|
||||
|
||||
## Development
|
||||
|
||||
- asdf's [creating-plugins.md](https://github.com/asdf-vm/asdf/blob/master/docs/creating-plugins.md)
|
||||
- [Bash Hackers Wiki](http://wiki.bash-hackers.org/)
|
@ -1,12 +0,0 @@
|
||||
# Credit: github.com/trustin
|
||||
asdf_java_wrapper() {
|
||||
if \asdf "$@"; then
|
||||
if [[ "$(\asdf current java 2>&1)" =~ "(^([-_.a-zA-Z0-9]+)[[:space:]]*\(set by.*$)" ]]; then
|
||||
export JAVA_HOME=$(\asdf where java ${BASH_REMATCH[2]})
|
||||
else
|
||||
export JAVA_HOME=''
|
||||
fi
|
||||
fi
|
||||
}
|
||||
|
||||
alias asdf='asdf_java_wrapper'
|
@ -1,12 +0,0 @@
|
||||
# Credit: github.com/trustin
|
||||
asdf_java_wrapper() {
|
||||
if \asdf "$@"; then
|
||||
if [[ "$(\asdf current java 2>&1)" =~ "^([-_.a-zA-Z0-9]+)[[:space:]]*\(set by.*$" ]]; then
|
||||
export JAVA_HOME=$(\asdf where java ${match[1]})
|
||||
else
|
||||
export JAVA_HOME=''
|
||||
fi
|
||||
fi
|
||||
}
|
||||
|
||||
alias asdf='asdf_java_wrapper'
|
@ -1,10 +0,0 @@
|
||||
. "$(dirname $(dirname $BASH_SOURCE))/asdf-java-wrapper.bash"
|
||||
[[ -z $ASDF_JAVA_PLAIN ]] || tput setaf 1
|
||||
echo "
|
||||
|
||||
asdf-java-wrapper has moved! For details, see the README:
|
||||
|
||||
https://github.com/skotchpine/asdf-java
|
||||
|
||||
" >/dev/stderr
|
||||
[[ -z $ASDF_JAVA_PLAIN ]] || tput sgr0
|
@ -1,3 +0,0 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
export JAVA_HOME=$ASDF_INSTALL_PATH
|
270
bin/install
270
bin/install
@ -1,270 +0,0 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
# this is global for error reporting
|
||||
ASDF_JAVA_ERROR=""
|
||||
|
||||
log() {
|
||||
# set colors unless ASDF_JAVA_PLAIN is set
|
||||
[[ -z $ASDF_JAVA_PLAIN ]] && tput setab $1 && tput setaf 0
|
||||
|
||||
echo -n "░asdf java $2░"
|
||||
|
||||
# set colors unless ASDF_JAVA_PLAIN is set
|
||||
[[ -z $ASDF_JAVA_PLAIN ]] && tput sgr0 && tput setaf $1
|
||||
echo " ${@:3}"
|
||||
|
||||
# unset colors
|
||||
tput sgr0
|
||||
}
|
||||
|
||||
log_info() {
|
||||
log 2 ':)' "$@"
|
||||
}
|
||||
|
||||
log_warning() {
|
||||
log 3 ':o' "$@"
|
||||
}
|
||||
|
||||
log_error() {
|
||||
log 1 ':(' "$@"
|
||||
}
|
||||
|
||||
# Download the java source from Oracle or OpenJDK, copy files and cleanup.
|
||||
install_java() {
|
||||
local versionstr=$1
|
||||
local destdir=$2
|
||||
|
||||
IFS=- read -r distro version <<< "${versionstr}"
|
||||
|
||||
local variant=$(get_variant $distro)
|
||||
[[ -z "$ASDF_JAVA_ERROR" ]] || return
|
||||
|
||||
# Perform all operations is a temporary directory that will be
|
||||
# automatically cleaned up on exit (success or failure).
|
||||
local wrkdir
|
||||
case "$(uname -s)" in
|
||||
Darwin) wrkdir=$(mktemp -dt asdf-java) ;;
|
||||
*) wrkdir=$(mktemp -dp /tmp asdf-java.XXXXXXXX) ;;
|
||||
esac
|
||||
# shellcheck disable=SC2064
|
||||
trap "cd ${PWD}; rm -rf ${wrkdir}" EXIT
|
||||
cd "${wrkdir}"
|
||||
|
||||
get_java "${distro}" "${version}" "${variant}"
|
||||
[[ -z "$ASDF_JAVA_ERROR" ]] || return
|
||||
|
||||
unpack_java $variant $destdir
|
||||
[[ -z "$ASDF_JAVA_ERROR" ]] || return
|
||||
}
|
||||
|
||||
# Get the "variant" piece of the Oracle url.
|
||||
get_variant() {
|
||||
local distro=$1
|
||||
case "$(uname -s)" in
|
||||
Linux)
|
||||
case "$(uname -m)" in
|
||||
x86_64)
|
||||
case $distro in
|
||||
adoptopenjdk) echo linux_hotspot ;;
|
||||
corretto) echo linux-x64.tar.gz ;;
|
||||
oracle) echo linux-x64.tar.gz ;;
|
||||
openjdk) echo linux-x64_bin.tar.gz ;;
|
||||
zulu) echo linux_x64.tar.gz;;
|
||||
*) ;;
|
||||
esac ;;
|
||||
i[[3-9]]86)
|
||||
case $distro in
|
||||
oracle) echo linux-i586.tar.gz ;;
|
||||
openjdk) echo linux-i586_bin.tar.gz ;;
|
||||
zulu) echo linux_i686.tar.gz ;;
|
||||
*) ;;
|
||||
esac ;;
|
||||
*) ASDF_JAVA_ERROR="$(uname -m) is not supported on linux" ;;
|
||||
esac ;;
|
||||
Darwin)
|
||||
case "$(uname -m)" in
|
||||
x86_64)
|
||||
case $distro in
|
||||
adoptopenjdk) echo mac_hotspot ;;
|
||||
corretto) echo macosx-x64.tar.gz ;;
|
||||
oracle) echo macosx-x64.dmg ;;
|
||||
openjdk) echo osx-x64_bin.tar.gz ;;
|
||||
zulu) echo macosx_x64.zip ;;
|
||||
*) ;;
|
||||
esac ;;
|
||||
*) ASDF_JAVA_ERROR="$(uname -m) is not supported on MacOS" ;;
|
||||
esac ;;
|
||||
*) ASDF_JAVA_ERROR="$(uname -s) is not supported" ;;
|
||||
esac
|
||||
}
|
||||
|
||||
get_current_variant() {
|
||||
local variant=$1
|
||||
|
||||
if [[ "$variant" == *"mac"* ]]; then
|
||||
variant=$(echo $variant | sed -e 's|mac||')
|
||||
fi
|
||||
|
||||
if [[ "$variant" == *"tar"* ]]; then
|
||||
echo $variant | sed -e 's|.tar|_bin.tar|'
|
||||
elif [[ "$variant" == *"dmg"* ]]; then
|
||||
echo $variant | sed -e 's|.dmg|_bin.dmg|'
|
||||
fi
|
||||
}
|
||||
|
||||
get_base_url() {
|
||||
local distro=$1
|
||||
case $distro in
|
||||
adoptopenjdk) echo "https://github.com/AdoptOpenJDK/" ;;
|
||||
corretto) echo "https://d3pxv6yz143wms.cloudfront.net/" ;;
|
||||
oracle) echo "https://download.oracle.com/" ;;
|
||||
openjdk) echo "https://download.java.net/java/GA/jdk" ;;
|
||||
zulu) echo "https://cdn.azul.com/zulu/bin/" ;;
|
||||
*) ;;
|
||||
esac
|
||||
}
|
||||
|
||||
# Download java from Oracle.
|
||||
get_java() {
|
||||
local distro=$1
|
||||
local version=$2
|
||||
local variant=$3
|
||||
|
||||
local base=$(get_base_url $distro)
|
||||
|
||||
case $distro-$version in
|
||||
adoptopenjdk-8.212) url=${base}openjdk8-binaries/releases/download/jdk8u212-b03/OpenJDK8U-jdk_x64_${variant}_8u212b03.tar.gz ;;
|
||||
adoptopenjdk-11.0.3) url=${base}openjdk11-binaries/releases/download/jdk-11.0.3+7/OpenJDK11U-jdk_x64_${variant}_11.0.3_7.tar.gz ;;
|
||||
corretto-8.212) url=${base}8.212.04.2/amazon-${distro}-${version}.04.2-${variant} ;;
|
||||
corretto-11.0.3) url=${base}11.0.3.7.1/amazon-${distro}-${version}.7.1-${variant} ;;
|
||||
oracle-8.131) url=${base}otn-pub/java/jdk/8u131-b11/d54c1d3a095b4ff2b6607d096fa80163/jdk-8u131-${variant} ;;
|
||||
oracle-8.141) url=${base}otn-pub/java/jdk/8u141-b15/336fa29ff2bb4ef291e347e091f7f4a7/jdk-8u141-${variant} ;;
|
||||
openjdk-10.0.2)url=${base}10/${version}/19aef61b38124481863b1413dce1855f/13/openjdk-${version}_${variant} ;;
|
||||
openjdk-11)url=${base/GA/ga}11/openjdk-11_${variant} ;;
|
||||
openjdk-11.0.1) url=${base}11/13/GPL/openjdk-11.0.1_${variant} ;;
|
||||
openjdk-12.0.1)url=${base}12.0.1/69cfe15208a647278a19ef0990eea691/12/GPL/openjdk-${version}_${variant};;
|
||||
zulu-7.0.222) url=${base}zulu7.29.0.5-ca-jdk7.0.222-${variant} ;;
|
||||
zulu-8.0.212) url=${base}zulu8.38.0.13-ca-jdk8.0.212-${variant} ;;
|
||||
zulu-11.0.3) url=${base}zulu11.31.11-ca-jdk11.0.3-${variant} ;;
|
||||
zulu-12.0.1) url=${base}zulu12.2.3-ca-jdk12.0.1-${variant} ;;
|
||||
|
||||
*) ASDF_JAVA_ERROR="$version is not a supported version" ;;
|
||||
esac
|
||||
[[ -z "$ASDF_JAVA_ERROR" ]] || return
|
||||
|
||||
log_info downloading $url
|
||||
|
||||
curl -fLC - \
|
||||
--progress-bar \
|
||||
--retry 3 --retry-delay 3 \
|
||||
-b oraclelicense=accept-securebackup-cookie \
|
||||
-o ./${variant} ${url}
|
||||
|
||||
[[ $? != 0 ]] && ASDF_JAVA_ERROR="downloading java dist"
|
||||
}
|
||||
|
||||
# Unpacks all kinds of sources.
|
||||
unpack_java() {
|
||||
local variant=$1
|
||||
local destdir=$2
|
||||
|
||||
log_info expanding java dist
|
||||
|
||||
mkdir -p "${destdir}"
|
||||
case $variant in
|
||||
*linux_hotspot | *.tar.gz | *mac_hotspot) unpack_tar $variant $destdir ;;
|
||||
*.dmg) unpack_dmg $variant $destdir ;;
|
||||
*.zip) unpack_zip $variant $destdir ;;
|
||||
*) ASDF_JAVA_ERROR="$variant is not supported" ;;
|
||||
esac
|
||||
}
|
||||
|
||||
# Unarchive a tar archive into the install directory and cleanup.
|
||||
#
|
||||
# TODO: Should be sanitized with error reporting.
|
||||
unpack_tar() {
|
||||
local archive=${1}
|
||||
local destdir=${2}
|
||||
tar -xzf "${archive}" || { ASDF_JAVA_ERROR="expanding java dist"; return; }
|
||||
local jdk_dir
|
||||
jdk_dir=$(ls | grep -v ${archive})
|
||||
if [[ -d ${jdk_dir}/Contents/Home ]]; then
|
||||
jdk_dir="${jdk_dir}/Contents/Home"
|
||||
fi
|
||||
mv "${jdk_dir}"/* "${destdir}/"
|
||||
}
|
||||
|
||||
# Unarchive a tar archive into the install directory and cleanup.
|
||||
#
|
||||
# NOTE: Using $origin as a memo rather than executing in a subshell
|
||||
# because errors won't be persisted from a subshell.
|
||||
#
|
||||
# TODO: Should be sanitized with error reporting.
|
||||
unpack_dmg() {
|
||||
local image=${1}
|
||||
local destdir=${2}
|
||||
local pkgdir=./asdf_tmp_pkgdir
|
||||
local imgdir=./asdf_tmp_imgdir
|
||||
|
||||
mount_dmg $imgdir $image
|
||||
[[ -z "$ASDF_JAVA_ERROR" ]] || return
|
||||
|
||||
if pkgutil --expand $imgdir/*.pkg $pkgdir; then
|
||||
if gzip -dc < ${pkgdir}/jdk*.pkg/Payload | cpio -i \
|
||||
&& [[ -d Contents ]]; then
|
||||
mv Contents/Home/* $destdir/
|
||||
else
|
||||
ASDF_JAVA_ERROR="demangling dist payload"
|
||||
fi
|
||||
else
|
||||
ASDF_JAVA_ERROR="expanding java dist"
|
||||
fi
|
||||
|
||||
unmount_dmg "${imgdir}"
|
||||
}
|
||||
|
||||
mount_dmg() {
|
||||
local dir=$1
|
||||
local dev=$2
|
||||
|
||||
hdiutil mount -quiet -mountpoint $dir $dev
|
||||
[[ $? == 0 ]] || ASDF_JAVA_ERROR="mounting java dist"
|
||||
}
|
||||
|
||||
unmount_dmg() {
|
||||
local dir=$1
|
||||
|
||||
hdiutil unmount -quiet $dir
|
||||
if [[ $? != 0 ]]; then
|
||||
[[ -z "$ASDF_JAVA_ERROR" ]] || \
|
||||
ASDF_JAVA_ERROR="unmounting java dist"
|
||||
|
||||
log_warning "The java dist is still mounted at $dir."
|
||||
log_warning " Use hdiutil unmount to unmount it."
|
||||
fi
|
||||
}
|
||||
|
||||
unpack_zip() {
|
||||
local archive=${1}
|
||||
local destdir=${2}
|
||||
unzip "${archive}" || { ASDF_JAVA_ERROR="expanding java dist"; return; }
|
||||
local jdk_dir
|
||||
jdk_dir=$(ls | grep -v ${archive})
|
||||
if [[ -d ${jdk_dir}/Contents/Home ]]; then
|
||||
jdk_dir="${jdk_dir}/Contents/Home"
|
||||
fi
|
||||
mv "${jdk_dir}"/* "${destdir}/"
|
||||
}
|
||||
|
||||
#
|
||||
# MAIN
|
||||
#
|
||||
install_java "$ASDF_INSTALL_VERSION" "$ASDF_INSTALL_PATH"
|
||||
|
||||
if [[ -z "$ASDF_JAVA_ERROR" ]]; then
|
||||
log_info "$ASDF_INSTALL_VERSION was installed successfully"
|
||||
else
|
||||
log_error "asdf java failed. $ASDF_JAVA_ERROR"
|
||||
fi
|
||||
|
||||
unset ASDF_JAVA_ERROR
|
18
bin/list-all
18
bin/list-all
@ -1,18 +0,0 @@
|
||||
#!/bin/env bash
|
||||
|
||||
echo $(echo "
|
||||
adoptopenjdk-8.212
|
||||
adoptopenjdk-11.0.3
|
||||
corretto-8.212
|
||||
corretto-11.0.3
|
||||
oracle-8.131
|
||||
oracle-8.141
|
||||
openjdk-10.0.2
|
||||
openjdk-11
|
||||
openjdk-11.0.1
|
||||
openjdk-12.0.1
|
||||
zulu-7.0.222
|
||||
zulu-8.0.212
|
||||
zulu-11.0.3
|
||||
zulu-12.0.1
|
||||
")
|
Loading…
Reference in New Issue
Block a user