Skip to content
Permalink
Browse files
Bugfix/java checks (#1228)
* fix: Java version parsing if java executable prints out additional information with --version

* fix: Ensure JAVA_HOME path comes first in the PATH environment

* refactor: Removed redundent code in favour of keeping a change introduced from another PR
  • Loading branch information
breautek committed May 9, 2021
1 parent ae4dba2 commit 6d803e2f7236db32fc963150c1683e097f453867
Showing 2 changed files with 16 additions and 7 deletions.
@@ -93,16 +93,15 @@ const java = {
return;
}

const javacPath = utils.forgivingWhichSync('javac');
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');
}
// Ensure that the JAVA_HOME bin path is before anything else
// to cover cases where different Java versions is in the PATH
environment.PATH = path.join(environment.JAVA_HOME, 'bin') + path.delimiter + environment.PATH;
} else {
const javacPath = utils.forgivingWhichSync('javac');
if (javacPath) {
// OS X has a command for finding JAVA_HOME.
const find_java = '/usr/libexec/java_home';
@@ -47,9 +47,19 @@ describe('Java', () => {
all: 'javac 1.8.0_275'
}));

console.log('BEFORE', process.env.JAVA_HOME);
const result = await Java.getVersion();
console.log('AFTER', process.env.JAVA_HOME);
expect(result.major).toBe(1);
expect(result.minor).toBe(8);
expect(result.patch).toBe(0);
expect(result.version).toBe('1.8.0');
});

it('detects JDK when additional details are printed', async () => {
Java.__set__('execa', () => Promise.resolve({
all: 'Picked up JAVA_TOOL_OPTIONS: -Dfile.encoding=UTF8\njavac 1.8.0_275'
}));

const result = await Java.getVersion();
expect(result.major).toBe(1);
expect(result.minor).toBe(8);
expect(result.patch).toBe(0);

0 comments on commit 6d803e2

Please sign in to comment.