Skip to content
Permalink
Browse files
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
  • Loading branch information
breautek committed May 9, 2021
1 parent a458043 commit ae4dba2bb87e53310c1949861c482ecfd0f812d0
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 2 deletions.
@@ -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');
@@ -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('');

0 comments on commit ae4dba2

Please sign in to comment.