-
Notifications
You must be signed in to change notification settings - Fork 905
/
jdk.ts
70 lines (61 loc) · 2.07 KB
/
jdk.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
import {join} from 'path';
import {link} from '@react-native-community/cli-tools';
import versionRanges from '../versionRanges';
import {doesSoftwareNeedToBeFixed} from '../checkInstallation';
import {HealthCheckInterface} from '../../types';
import {downloadAndUnzip} from '../downloadAndUnzip';
import {
setEnvironment,
updateEnvironment,
} from '../windows/environmentVariables';
export default {
label: 'JDK',
description: 'Required to compile Java code',
getDiagnostics: async ({Languages}) => ({
needsToBeFixed: doesSoftwareNeedToBeFixed({
version:
typeof Languages.Java === 'string'
? Languages.Java
: Languages.Java.version,
versionRange: versionRanges.JAVA,
}),
version:
typeof Languages.Java === 'string'
? Languages.Java
: Languages.Java.version,
versionRange: versionRanges.JAVA,
}),
win32AutomaticFix: async ({loader}) => {
try {
// Installing JDK 11 because later versions seem to cause issues with gradle at the moment
const installerUrl =
'https://download.java.net/java/GA/jdk11/9/GPL/openjdk-11.0.2_windows-x64_bin.zip';
const installPath = process.env.LOCALAPPDATA || ''; // The zip is in a folder `jdk-11.02` so it can be unzipped directly there
await downloadAndUnzip({
loader,
downloadUrl: installerUrl,
component: 'JDK',
installPath,
});
loader.text = 'Updating environment variables';
const jdkPath = join(installPath, 'jdk-11.0.2');
await setEnvironment('JAVA_HOME', jdkPath);
await updateEnvironment('PATH', join(jdkPath, 'bin'));
loader.succeed(
'JDK installed successfully. Please restart your shell to see the changes',
);
} catch (e) {
loader.fail(e as any);
}
},
runAutomaticFix: async ({logManualInstallation, loader}) => {
loader.fail();
logManualInstallation({
healthcheck: 'JDK',
url: link.docs('environment-setup', 'android', {
hash: 'jdk-studio',
guide: 'native',
}),
});
},
} as HealthCheckInterface;