From 66b8670c59c425e309fc932cd4e214841a6ca641 Mon Sep 17 00:00:00 2001 From: Eugene Yokota Date: Thu, 15 Feb 2018 13:02:03 -0500 Subject: [PATCH 1/2] Add macOS testing --- .travis.yml | 26 ++++++++++++++++++++------ 1 file changed, 20 insertions(+), 6 deletions(-) diff --git a/.travis.yml b/.travis.yml index 186b785db..84a1ba6cd 100644 --- a/.travis.yml +++ b/.travis.yml @@ -12,18 +12,30 @@ matrix: - script: - sbt -Dsbt.build.version=$SBT_VER universal:packageBin - cd citest && ./test.sh + jdk: oraclejdk8 + + ## build using JDK 8, test using JDK 8, on macOS + - script: + - sbt -Dsbt.build.version=$SBT_VER universal:packageBin + - cd citest && ./test.sh + ## https://github.com/travis-ci/travis-ci/issues/2316 + language: java + os: osx + osx_image: xcode9.2 ## build using JDK 8, test using JDK 9 - script: - sbt -Dsbt.build.version=$SBT_VER universal:packageBin - jdk_switcher use oraclejdk9 - cd citest && ./test.sh + jdk: oraclejdk8 ## build using JDK 8, test using JDK 10 - script: - sbt -Dsbt.build.version=$SBT_VER universal:packageBin - citest/install-jdk10.sh - cd citest && ./test.sh + jdk: oraclejdk8 - script: - sbt -Dsbt.build.version=$SBT_VER rpm:packageBin debian:packageBin @@ -32,16 +44,18 @@ matrix: packages: - fakeroot - rpm + jdk: oraclejdk8 scala: - 2.10.7 -jdk: - - oraclejdk8 - -# Undo _JAVA_OPTIONS environment variable -before_script: - - _JAVA_OPTIONS= +before_install: + # https://github.com/travis-ci/travis-ci/issues/8408 + - unset _JAVA_OPTIONS + - if [[ "$TRAVIS_OS_NAME" = "osx" ]]; then + brew update; + brew install sbt; + fi cache: directories: From 21cf71e384b8d3dba4c56d167837a9236d294c9d Mon Sep 17 00:00:00 2001 From: Eugene Yokota Date: Thu, 15 Feb 2018 19:33:18 -0500 Subject: [PATCH 2/2] more portable jdk_version function I've reimplemented java version detection as a bash function. This no longer uses grep. Also this no longer uses `?` in sed, which doesn't work on macOS. Fixes https://github.com/sbt/sbt/issues/3873 --- src/universal/bin/sbt-launch-lib.bash | 30 ++++++++++++++++++++++++--- 1 file changed, 27 insertions(+), 3 deletions(-) diff --git a/src/universal/bin/sbt-launch-lib.bash b/src/universal/bin/sbt-launch-lib.bash index 00280ac5b..37127e7e2 100755 --- a/src/universal/bin/sbt-launch-lib.bash +++ b/src/universal/bin/sbt-launch-lib.bash @@ -146,6 +146,32 @@ is_function_defined() { declare -f "$1" > /dev/null } +# parses JDK version from the -version output line. +# 8 for 1.8.0_nn, 9 for 9-ea etc, and "no_java" for undetected +jdk_version() { + local result + local lines=$("$java_cmd" -Xms32M -Xmx32M -version 2>&1 | tr '\r' '\n') + local IFS=$'\n' + for line in $lines; do + if [[ (-z $result) && ($line = *"version \""*) ]] + then + local ver=$(echo $line | sed -e 's/.*version "\(.*\)"\(.*\)/\1/; 1q') + # on macOS sed doesn't support '?' + if [[ $ver = "1."* ]] + then + result=$(echo $ver | sed -e 's/1\.\([0-9]*\)\(.*\)/\1/; 1q') + else + result=$(echo $ver | sed -e 's/\([0-9]*\)\(.*\)/\1/; 1q') + fi + fi + done + if [[ -z $result ]] + then + result=no_java + fi + echo "$result" +} + process_args () { while [[ $# -gt 0 ]]; do case "$1" in @@ -179,9 +205,7 @@ process_args () { process_my_args "${myargs[@]}" } - ## parses java version from the -version output line - ## https://regex101.com/r/0r3kKb/1/tests - java_version=$("$java_cmd" -Xms128M -Xmx512M -version 2>&1 | tr '\r' '\n' | grep ' version "' | sed 's/.*version "\(1\.\)\?\([0-9]*\)\{0,1\}\(.*\)*/\2/; 1q') + java_version="$(jdk_version)" vlog "[process_args] java_version = '$java_version'" }