erisu commented on a change in pull request #1130:
URL: https://github.com/apache/cordova-android/pull/1130#discussion_r528295023



##########
File path: bin/templates/cordova/lib/Java.js
##########
@@ -0,0 +1,157 @@
+/*
+       Licensed to the Apache Software Foundation (ASF) under one
+       or more contributor license agreements.  See the NOTICE file
+       distributed with this work for additional information
+       regarding copyright ownership.  The ASF licenses this file
+       to you under the Apache License, Version 2.0 (the
+       "License"); you may not use this file except in compliance
+       with the License.  You may obtain a copy of the License at
+
+         http://www.apache.org/licenses/LICENSE-2.0
+
+       Unless required by applicable law or agreed to in writing,
+       software distributed under the License is distributed on an
+       "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+       KIND, either express or implied.  See the License for the
+       specific language governing permissions and limitations
+       under the License.
+*/
+
+const execa = require('execa');
+const fs = require('fs-extra');
+const path = require('path');
+const glob = require('fast-glob');
+const { CordovaError, events } = require('cordova-common');
+const utils = require('./utils');
+
+let javaIsEnsured = false;
+
+module.exports = class Java {
+    /**
+     * Gets the version from the javac executable.
+     * @returns {Object}
+     * {
+     *      major: number
+     *      minor: number
+     *      patch: number
+     *      build: number
+     * }
+     */
+    static async getVersion () {
+        await Java._ensure();
+
+        // Java <= 8 writes version info to stderr, Java >= 9 to stdout
+        let version = null;
+        try {
+            version = (await execa('javac', ['-version'], { all: true })).all;
+        } catch (ex) {
+            events.emit('verbose', ex.shortMessage);
+
+            let msg =
+            'Failed to run "javac -version", make sure that you have a JDK 
version 8 installed.\n' +
+            'You can get it from the following location:\n' +
+            
'https://www.oracle.com/technetwork/java/javase/downloads/jdk8-downloads-2133151.html';
+            if (process.env.JAVA_HOME) {
+                msg += '\n\n';
+                msg += 'Your JAVA_HOME is invalid: ' + process.env.JAVA_HOME;
+            }
+            throw new CordovaError(msg);
+        }
+
+        return Java._parseVersion(version);
+    }
+
+    /**
+     * Parses a java version output, ie: "javac 1.8.0_275"
+     *
+     * @param {String} version
+     * @returns {Object}
+     * {
+     *      major: number
+     *      minor: number
+     *      patch: number
+     *      build: number
+     * }
+     */
+    static _parseVersion (version) {
+        version = version.replace('javac ', '');
+
+        const mainParts = version.split('.');
+
+        const output = {
+            major: parseInt(mainParts[0]),
+            minor: parseInt(mainParts[1]),

Review comment:
       ```suggestion
               major: parseInt(mainParts[0], 10),
               minor: parseInt(mainParts[1], 10),
   ```
   
   I typically always try to include the `radix` argument for reliability. 
There used to be cases in the past that lead to unexpected results, but I think 
most of these were resolved since, so providing it might not be as necessary.




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
[email protected]



---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to