mirror of
https://github.com/apache/cordova-android.git
synced 2025-01-19 07:02:51 +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 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');
|
||||
|
@ -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('');
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user