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

feat: CORDOVA_JAVA_HOME env variable #1229

Merged
merged 3 commits into from
May 9, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
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 @@ -73,8 +73,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.PATH.split(path.delimiter))
.toContain(path.join(env.JAVA_HOME, 'bin'));
PieterVanPoyer marked this conversation as resolved.
Show resolved Hide resolved
});

it('with JAVA_HOME / without javac', async () => {
spyOn(utils, 'forgivingWhichSync').and.returnValue('');

Expand Down