Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bugfix/java checks #1228

Merged
merged 3 commits into from
May 9, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
9 changes: 4 additions & 5 deletions bin/templates/cordova/lib/env/java.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
breautek marked this conversation as resolved.
Show resolved Hide resolved
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';
Expand Down
14 changes: 12 additions & 2 deletions spec/unit/java.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down