You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cordova.apache.org by ra...@apache.org on 2018/06/12 20:19:10 UTC

[cordova-android] branch master updated: CB-14101 Fix Java version check for Java >= 9 (#446)

This is an automated email from the ASF dual-hosted git repository.

raphinesse pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/cordova-android.git


The following commit(s) were added to refs/heads/master by this push:
     new bf29fe0  CB-14101 Fix Java version check for Java >= 9 (#446)
bf29fe0 is described below

commit bf29fe0e10334938d2e6ee8116f9a30c762c40b4
Author: Raphael von der GrĂ¼n <ra...@gmail.com>
AuthorDate: Tue Jun 12 22:18:55 2018 +0200

    CB-14101 Fix Java version check for Java >= 9 (#446)
    
    This also checks that we have exactly 1.8 since nothing else works with
    the Android SDK. The user facing error was updated accordingly.
---
 bin/templates/cordova/lib/check_reqs.js | 44 ++++++++++++++-------------------
 1 file changed, 18 insertions(+), 26 deletions(-)

diff --git a/bin/templates/cordova/lib/check_reqs.js b/bin/templates/cordova/lib/check_reqs.js
index 2ef5aa8..95ef89f 100644
--- a/bin/templates/cordova/lib/check_reqs.js
+++ b/bin/templates/cordova/lib/check_reqs.js
@@ -39,17 +39,6 @@ function forgivingWhichSync (cmd) {
     }
 }
 
-function tryCommand (cmd, errMsg, catchStderr) {
-    var d = Q.defer();
-    child_process.exec(cmd, function (err, stdout, stderr) {
-        if (err) d.reject(new CordovaError(errMsg));
-        // Sometimes it is necessary to return an stderr instead of stdout in case of success, since
-        // some commands prints theirs output to stderr instead of stdout. 'javac' is the example
-        else d.resolve((catchStderr ? stderr : stdout).trim());
-    });
-    return d.promise;
-}
-
 module.exports.isWindows = function () {
     return (os.platform() === 'win32');
 };
@@ -205,19 +194,22 @@ module.exports.check_java = function () {
             }
         }
     }).then(function () {
-        var msg =
-            'Failed to run "javac -version", make sure that you have a JDK installed.\n' +
-            'You can get it from: http://www.oracle.com/technetwork/java/javase/downloads.\n';
-        if (process.env['JAVA_HOME']) {
-            msg += 'Your JAVA_HOME is invalid: ' + process.env['JAVA_HOME'] + '\n';
-        }
-        // We use tryCommand with catchStderr = true, because
-        // javac writes version info to stderr instead of stdout
-        return tryCommand('javac -version', msg, true).then(function (output) {
-            // Let's check for at least Java 8, and keep it future proof so we can support Java 10
-            var match = /javac ((?:1\.)(?:[8-9]\.)(?:\d+))|((?:1\.)(?:[1-9]\d+\.)(?:\d+))/i.exec(output);
-            return match && match[1];
-        });
+        return Q.denodeify(child_process.exec)('javac -version')
+            .then(outputs => {
+                // outputs contains two entries: stdout and stderr
+                // Java <= 8 writes version info to stderr, Java >= 9 to stdout
+                const output = outputs.join('').trim();
+                const match = /javac\s+([\d.]+)/i.exec(output);
+                return match && match[1];
+            }, () => {
+                var msg =
+                'Failed to run "javac -version", make sure that you have a JDK installed.\n' +
+                'You can get it from: http://www.oracle.com/technetwork/java/javase/downloads.\n';
+                if (process.env['JAVA_HOME']) {
+                    msg += 'Your JAVA_HOME is invalid: ' + process.env['JAVA_HOME'] + '\n';
+                }
+                throw new CordovaError(msg);
+            });
     });
 };
 
@@ -364,8 +356,8 @@ module.exports.run = function () {
         console.log('ANDROID_HOME=' + process.env['ANDROID_HOME']);
         console.log('JAVA_HOME=' + process.env['JAVA_HOME']);
 
-        if (!values[0]) {
-            throw new CordovaError('Requirements check failed for JDK 1.8 or greater');
+        if (!String(values[0]).startsWith('1.8.')) {
+            throw new CordovaError('Requirements check failed for JDK 1.8');
         }
 
         if (!values[1]) {

-- 
To stop receiving notification emails like this one, please contact
raphinesse@apache.org.

---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@cordova.apache.org
For additional commands, e-mail: commits-help@cordova.apache.org