[yocto] [eclipse-poky][PATCH] scripts/setup.sh: check java version

Randle, William C william.c.randle at intel.com
Wed Aug 24 15:59:57 PDT 2016


On Wed, 2016-08-24 at 15:22 -0700, Tim Orling wrote:

Make it obvious when run on autobuilder if java version is too low.
While we are at it, check that java is present.

[YOCTO #10156]

Borrowing heavily from:
http://stackoverflow.com/questions/7334754/correct-way-to-check-java-version-from-bash-script

Signed-off-by: Tim Orling <timothy.t.orling at linux.intel.com<mailto:timothy.t.orling at linux.intel.com>>
---
 scripts/setup.sh | 23 +++++++++++++++++++++++
 1 file changed, 23 insertions(+)

diff --git a/scripts/setup.sh b/scripts/setup.sh
index 75310ab..c2b32a4 100755
--- a/scripts/setup.sh
+++ b/scripts/setup.sh
@@ -67,6 +67,29 @@ if [ "x$url" != "x" ]; then
     [ "x$port" != "x" ] && PROXY_PARAM="${PROXY_PARAM} -Dhttp.proxyPort=$port"
 fi

+echo "#### Checking that Java is available ####"
+if type -p java; then
+    echo java found in PATH
+    _java=java
+elif [[ -n "$JAVA_HOME" ]] && [[ -x "$JAVA_HOME/bin/java" ]]; then
+    echo java found in JAVA_HOME
+    _java="$JAVA_HOME/bin/java"
+else
+    err_exit 2 "no java"
+fi
+echo "#### Checking that the appropriate Java version is available ####"
+JAVA_VER_STRING=1.8
+JAVA_VER_INT=001008
+if [[ "$_java" ]]; then
+    version=$("$_java" -version 2>&1 | awk -F '"' '/version/ {print $2}')
+    echo java version as string = $version
+    version_int=$(echo "$version" | awk -F. '{printf("%03d%03d",$1,$2);}')
+    echo java version as integer = $version_int
+    if [ $version_int -lt $JAVA_VER_INT ]; then
+        err_exit 1 "Java version must be $JAVA_VER_STRING+"
+    fi
+fi
+
 # prepare the base Eclipse installation in folder "eclipse"
 ep_rel="R-"
 ep_ver="4.6"
--
2.7.4



Tim,

FYI, the dash shell used on Ubuntu does not recognize the "[[" construct, because it's a bash extension and not POSIX. I suggest you replace it with something POSIX compliant.

    -Bill
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.yoctoproject.org/pipermail/yocto/attachments/20160824/9d3f008c/attachment.html>


More information about the yocto mailing list