Disable tests that requires JDK 8 when using compile.sh

Also fix the OS X travis build file.

--
MOS_MIGRATED_REVID=96683399
diff --git a/.travis/build.sh b/.travis/build.sh
index 0a160ee..03c419f 100755
--- a/.travis/build.sh
+++ b/.travis/build.sh
@@ -23,21 +23,17 @@
 
 if [[ $TRAVIS_OS_NAME = 'osx' ]]; then
     export JAVA_VERSION=1.7
-    sed -i.bak 's/_version = "8",/_version = "7",/' tools/jdk/BUILD
-    cat .travis/jdk7.WORKSPACE >WORKSPACE
-    # Ignore zip tests as they requires to much space and jdk8 stuff
-    cat <<'EOF' >.bazelrc
-build --test_tag_filters -zip,-jdk8,-skyframe
-EOF
-    export BAZELRC=$PWD/.bazelrc
+    # Ignore zip tests as they requires to much space.
+    export BAZEL_TEST_FILTERS="-zip,-skyframe"
     ./compile.sh all
 else
     sudo apt-get update -qq
     sudo apt-get install -y netcat-traditional
     sudo update-alternatives --set nc /bin/nc.traditional
     export JAVA_HOME=/usr/lib/jvm/java-8-oracle
-    export JAVA_OPTS="-Xmx3000m"
     cat > .bazelrc <<EOF
+startup --host_jvm_args=-Xmx2500m
+startup --host_jvm_args=-Xms2500m"
 test --ram_utilization_factor=10
 EOF
     export BAZELRC="$(pwd)/.bazelrc"
diff --git a/compile.sh b/compile.sh
index cf12377..bb93313 100755
--- a/compile.sh
+++ b/compile.sh
@@ -157,7 +157,20 @@
 if [ $DO_TESTS ]; then
   new_step "Running tests"
   display "."
+  [ -n "$JAVAC_VERSION" ] || get_java_version
+  if [[ ! "${BAZEL_TEST_FILTERS-}" =~ "-jdk8" ]] \
+      && [ "8" -gt ${JAVAC_VERSION#*.} ]; then
+    display "$WARNING Your version of Java is lower than 1.8!"
+    display "$WARNING Deactivating Java 8 tests, please use a JDK 8 to fully"
+    display "$WARNING test Bazel."
+    if [ -n "${BAZEL_TEST_FILTERS-}" ]; then
+      BAZEL_TEST_FILTERS="${BAZEL_TEST_FILTERS},-jdk8"
+    else
+      BAZEL_TEST_FILTERS="-jdk8"
+    fi
+  fi
   $BAZEL --blazerc=${BAZELRC} --nomaster_blazerc test \
+      --test_tag_filters="${BAZEL_TEST_FILTERS-}" \
       --build_tests_only \
       --javacopt="-source ${JAVA_VERSION} -target ${JAVA_VERSION}" \
       -k --test_output=errors //src/... //third_party/ijar/... //scripts/... \
diff --git a/scripts/bootstrap/buildenv.sh b/scripts/bootstrap/buildenv.sh
index 3be93df..812e319 100755
--- a/scripts/bootstrap/buildenv.sh
+++ b/scripts/bootstrap/buildenv.sh
@@ -81,6 +81,7 @@
 
 LEAVES="\xF0\x9F\x8D\x83"
 INFO="\033[32mINFO\033[0m:"
+WARNING="\033[31mWARN\033[0m:"
 
 first_step=1
 function new_step() {
@@ -109,3 +110,20 @@
     md5sum $1
   }
 fi
+
+# Gets the java version from JAVA_HOME
+# Sets JAVAC and JAVAC_VERSION with respectively the path to javac and
+# the version of javac.
+function get_java_version() {
+  test -z "$JAVA_HOME" && fail "JDK not found, please set \$JAVA_HOME."
+  JAVAC="${JAVA_HOME}/bin/javac"
+  [[ -x "${JAVAC}" ]] \
+    || fail "JAVA_HOME ($JAVA_HOME) is not a path to a working JDK."
+
+  JAVAC_VERSION=$("${JAVAC}" -version 2>&1)
+  if [[ "$JAVAC_VERSION" =~ ^"javac "(1\.([789]|[1-9][0-9])).*$ ]]; then
+    JAVAC_VERSION=${BASH_REMATCH[1]}
+  else
+    fail "Cannot determine JDK version, please set \$JAVA_HOME."
+  fi
+}
diff --git a/scripts/bootstrap/compile.sh b/scripts/bootstrap/compile.sh
index 5ac4efe..9161905 100755
--- a/scripts/bootstrap/compile.sh
+++ b/scripts/bootstrap/compile.sh
@@ -134,22 +134,10 @@
 [[ -x "${PROTOC-}" ]] \
     || fail "Protobuf compiler not found in ${PROTOC-}"
 
-test -z "$JAVA_HOME" && fail "JDK not found, please set \$JAVA_HOME."
-
-JAVAC="${JAVA_HOME}/bin/javac"
-
-[[ -x "${JAVAC}" ]] \
-    || fail "JAVA_HOME ($JAVA_HOME) is not a path to a working JDK."
-
 # Check that javac -version returns a upper version than $JAVA_VERSION.
-JAVAC_VERSION=$("${JAVAC}" -version 2>&1)
-if [[ "$JAVAC_VERSION" =~ ^"javac "(1\.([789]|[1-9][0-9])).*$ ]]; then
-  JAVAC_VERSION=${BASH_REMATCH[1]}
-  [ ${JAVA_VERSION#*.} -le ${JAVAC_VERSION#*.} ] || \
-     fail "JDK version (${JAVAC_VERSION}) is lower than ${JAVA_VERSION}, please set \$JAVA_HOME."
-else
-  fail "Cannot determine JDK version, please set \$JAVA_HOME."
-fi
+get_java_version
+[ ${JAVA_VERSION#*.} -le ${JAVAC_VERSION#*.} ] || \
+  fail "JDK version (${JAVAC_VERSION}) is lower than ${JAVA_VERSION}, please set \$JAVA_HOME."
 
 JAR="${JAVA_HOME}/bin/jar"