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
This commit is contained in:
Norman Breau 2021-05-09 17:02:25 -03:00 committed by GitHub
parent a45804329b
commit ae4dba2bb8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 17 additions and 2 deletions

View File

@ -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');

View File

@ -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('');