Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add java detection from java.jdt.ls.java.home as primary #611

Merged
merged 1 commit into from
Aug 30, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 21 additions & 5 deletions vscode-wpilib/src/jdkdetector.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,15 +39,31 @@ export function getJavaVersion(javaHome: string): Promise<number> {

export async function findJdkPath(api: IExternalAPI): Promise<string | undefined> {
// Check for java property, as thats easily user settable, and we want it to win
const vscodeJavaHome = vscode.workspace.getConfiguration('java').get<string>('home');
const vscodeJavaHome = vscode.workspace.getConfiguration('java').get<string>('jdt.ls.java.home');
if (vscodeJavaHome) {
try {
const javaVersion = await getJavaVersion(vscodeJavaHome);
if (javaVersion >= 17) {
logger.log(`Found Java Home Version: ${javaVersion} at ${vscodeJavaHome}`);
logger.log(`Found jdt.ls.java.home Version: ${javaVersion} at ${vscodeJavaHome}`);
return vscodeJavaHome;
} else {
logger.info(`Bad Java version ${javaVersion} at ${vscodeJavaHome}`);
logger.info(`Bad Java version ${javaVersion} at ${vscodeJavaHome} from jdt.ls.java.home Version`);
}
} catch (err) {
logger.log('Error loading java from jdt.ls.java.home, skipping', err);
}
}

// Check for deprecated java property, as that was used before 2024
const vscodeOldJavaHome = vscode.workspace.getConfiguration('java').get<string>('home');
if (vscodeOldJavaHome) {
try {
const javaVersion = await getJavaVersion(vscodeOldJavaHome);
if (javaVersion >= 17) {
logger.log(`Found Java Home Version: ${javaVersion} at ${vscodeOldJavaHome}`);
return vscodeOldJavaHome;
} else {
logger.info(`Bad Java version ${javaVersion} at ${vscodeOldJavaHome} from java.home`);
}
} catch (err) {
logger.log('Error loading java from java.home, skipping', err);
Expand Down Expand Up @@ -80,7 +96,7 @@ export async function findJdkPath(api: IExternalAPI): Promise<string | undefined
logger.log(`Found Java Home Version: ${javaVersion} at ${javaHome}`);
return javaHome;
} else {
logger.info(`Bad Java version ${javaVersion} at ${javaHome}`);
logger.info(`Bad Java version ${javaVersion} at ${javaHome} from JAVA_HOME`);
}
} catch (err) {
logger.log('Error loading java from JAVA_HOME, skipping', err);
Expand All @@ -96,7 +112,7 @@ export async function findJdkPath(api: IExternalAPI): Promise<string | undefined
logger.log(`Found Java Home Version: ${javaVersion} at ${jdkHome}`);
return jdkHome;
} else {
logger.info(`Bad Java version ${javaVersion} at ${jdkHome}`);
logger.info(`Bad Java version ${javaVersion} at ${jdkHome} from JDK_HOME`);
}
} catch (err) {
logger.log('Error loading java from JDK_HOME, skipping', err);
Expand Down