Skip to content

Commit

Permalink
feat: CORDOVA_JAVA_HOME env variable (apache#1229)
Browse files Browse the repository at this point in the history
* feat: CORDOVA_JAVA_HOME env variable

* refactor: Improve CORDOVA_JAVA_HOME env test

* fix(test) path separator issue
  • Loading branch information
breautek authored and wedgberto committed May 17, 2022
1 parent 290cef4 commit 0ebf18e
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 2 deletions.
6 changes: 4 additions & 2 deletions bin/templates/cordova/lib/env/java.js
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand Down
13 changes: 13 additions & 0 deletions spec/unit/java.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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('');

Expand Down

0 comments on commit 0ebf18e

Please sign in to comment.