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

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