MCPcopy Create free account
hub / github.com/Snapchat/Valdi / checkJavaInstallation

Method checkJavaInstallation

npm_modules/cli/src/commands/doctor.ts:732–893  ·  view source on GitHub ↗

* Validates Java JDK installation and configuration as set up by dev_setup. * * Checks for Java installation and configuration that dev_setup manages: * - Java JDK availability and version (Java 17+) * - JAVA_HOME environment variable * - Java symlink configuration (macOS) * - Java

()

Source from the content-addressed store, hash-verified

730 * @private
731 */
732 private async checkJavaInstallation(): Promise<void> {
733 // Check if Java is available
734 if (checkCommandExists('java')) {
735 try {
736 const { stdout, stderr } = await runCliCommand('java -version');
737 // java -version typically outputs to stderr, but check both
738 const versionInfo = stderr || stdout || '';
739
740 // Try multiple version string formats:
741 // 1. version "17.0.16" (older format)
742 // 2. openjdk 17.0.16 (OpenJDK format)
743 // 3. java version "17.0.16" (alternative format)
744 let versionMatch = versionInfo.match(/version "([^"]+)"/);
745 if (!versionMatch) {
746 versionMatch = versionInfo.match(/openjdk\s+(\d+\.\d+\.\d+)/i);
747 }
748 if (!versionMatch) {
749 versionMatch = versionInfo.match(/java\s+(\d+\.\d+\.\d+)/i);
750 }
751
752 const version = versionMatch?.[1] ?? 'Unknown version';
753
754 // Check if Java version is 17 or higher
755 const majorVersionMatch = version.match(/^(\d+)/);
756 const majorVersion = majorVersionMatch?.[1] ? Number.parseInt(majorVersionMatch[1], 10) : 0;
757
758 if (majorVersion >= 17) {
759 this.addResult({
760 name: 'Java Runtime',
761 status: 'pass',
762 message: `Java is installed: ${version}`,
763 category: 'Java installation',
764 });
765 } else if (majorVersion > 0) {
766 this.addResult({
767 name: 'Java Runtime',
768 status: 'fail',
769 message: `Java ${version} is outdated. Java 17+ is required`,
770 details: 'dev_setup installs Java 17 for Android development',
771 fixable: true,
772 fixCommand: this.getJavaInstallCommand(),
773 category: 'Java installation',
774 });
775 } else {
776 // Could detect java but not parse version
777 this.addResult({
778 name: 'Java Runtime',
779 status: 'pass',
780 message: 'Java is installed',
781 details: `Version info: ${versionInfo.split('\n')[0] || 'Unable to parse version'}`,
782 category: 'Java installation',
783 });
784 }
785 } catch {
786 this.addResult({
787 name: 'Java Runtime',
788 status: 'pass',
789 message: 'Java is installed',

Callers 1

runDiagnosticsMethod · 0.95

Calls 7

addResultMethod · 0.95
getJavaInstallCommandMethod · 0.95
checkCommandExistsFunction · 0.90
runCliCommandFunction · 0.90
splitMethod · 0.80
matchMethod · 0.45
parseIntMethod · 0.45

Tested by

no test coverage detected