mirror of
https://github.com/apache/cordova-android.git
synced 2025-03-16 16:51:02 +08:00
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:
parent
a45804329b
commit
ae4dba2bb8
6
bin/templates/cordova/lib/env/java.js
vendored
6
bin/templates/cordova/lib/env/java.js
vendored
@ -94,8 +94,10 @@ const java = {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const javacPath = utils.forgivingWhichSync('javac');
|
const javacPath = utils.forgivingWhichSync('javac');
|
||||||
const hasJavaHome = !!environment.JAVA_HOME;
|
const javaHome = environment.CORDOVA_JAVA_HOME || environment.JAVA_HOME;
|
||||||
if (hasJavaHome) {
|
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).
|
// Windows java installer doesn't add javac to PATH, nor set JAVA_HOME (ugh).
|
||||||
if (!javacPath) {
|
if (!javacPath) {
|
||||||
environment.PATH += path.delimiter + path.join(environment.JAVA_HOME, 'bin');
|
environment.PATH += path.delimiter + path.join(environment.JAVA_HOME, 'bin');
|
||||||
|
@ -76,6 +76,19 @@ describe('Java', () => {
|
|||||||
Java.__set__('javaIsEnsured', false);
|
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 () => {
|
it('with JAVA_HOME / without javac', async () => {
|
||||||
spyOn(utils, 'forgivingWhichSync').and.returnValue('');
|
spyOn(utils, 'forgivingWhichSync').and.returnValue('');
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user