You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cordova.apache.org by no...@apache.org on 2021/05/09 20:02:32 UTC

[cordova-android] branch master updated: feat: CORDOVA_JAVA_HOME env variable (#1229)

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

normanbreau 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 ae4dba2  feat: CORDOVA_JAVA_HOME env variable (#1229)
ae4dba2 is described below

commit ae4dba2bb87e53310c1949861c482ecfd0f812d0
Author: Norman Breau <no...@normanbreau.com>
AuthorDate: Sun May 9 17:02:25 2021 -0300

    feat: CORDOVA_JAVA_HOME env variable (#1229)
    
    * feat: CORDOVA_JAVA_HOME env variable
    
    * refactor: Improve CORDOVA_JAVA_HOME env test
    
    * fix(test) path separator issue
---
 bin/templates/cordova/lib/env/java.js |  6 ++++--
 spec/unit/java.spec.js                | 13 +++++++++++++
 2 files changed, 17 insertions(+), 2 deletions(-)

diff --git a/bin/templates/cordova/lib/env/java.js b/bin/templates/cordova/lib/env/java.js
index 90d5340..2cd720c 100644
--- a/bin/templates/cordova/lib/env/java.js
+++ b/bin/templates/cordova/lib/env/java.js
@@ -94,8 +94,10 @@ const java = {
         }
 
         const javacPath = utils.forgivingWhichSync('javac');
-        const hasJavaHome = !!environment.JAVA_HOME;
-        if (hasJavaHome) {
+        const javaHome = environment.CORDOVA_JAVA_HOME || environment.JAVA_HOME;
+        if (javaHome) {
+            // Ensure that CORDOVA_JAVA_HOME overrides
+            environment.JAVA_HOME = javaHome;
             // Windows java installer doesn't add javac to PATH, nor set JAVA_HOME (ugh).
             if (!javacPath) {
                 environment.PATH += path.delimiter + path.join(environment.JAVA_HOME, 'bin');
diff --git a/spec/unit/java.spec.js b/spec/unit/java.spec.js
index 0b01179..d19f1b0 100644
--- a/spec/unit/java.spec.js
+++ b/spec/unit/java.spec.js
@@ -76,6 +76,19 @@ describe('Java', () => {
             Java.__set__('javaIsEnsured', false);
         });
 
+        it('CORDOVA_JAVA_HOME overrides JAVA_HOME', async () => {
+            spyOn(utils, 'forgivingWhichSync').and.returnValue('');
+
+            const env = {
+                CORDOVA_JAVA_HOME: '/tmp/jdk'
+            };
+
+            await Java._ensure(env);
+
+            expect(env.JAVA_HOME).toBe('/tmp/jdk');
+            expect(env.PATH.split(path.delimiter)).toContain(['', 'tmp', 'jdk', 'bin'].join(path.sep));
+        });
+
         it('with JAVA_HOME / without javac', async () => {
             spyOn(utils, 'forgivingWhichSync').and.returnValue('');
 

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