Skip to content

fix: Allow to use environment executable java to launch servers#1263

Merged
CsCherrYY merged 2 commits intodevelopfrom
cs-issue1249
Aug 26, 2022
Merged

fix: Allow to use environment executable java to launch servers#1263
CsCherrYY merged 2 commits intodevelopfrom
cs-issue1249

Conversation

@CsCherrYY
Copy link
Collaborator

fix #1249

This pr checks and keeps the consistent of the two servers (Gradle server and Gradle language server), and follow Gradle behavior.

We will check the following ones (with descent priority), Beside VS Code configuration, we use step 4-5 to keep consistent with Gradle itself behavior.

  1. config "java.import.gradle.java.home"
  2. config "java.jdt.ls.java.home"
  3. config "java.home" (deprecated)
  4. environment JAVA_HOME
  5. environment executable java(.exe)

@CsCherrYY CsCherrYY added the bug Something isn't working label Aug 5, 2022
@CsCherrYY CsCherrYY added this to the Augest 2022 milestone Aug 5, 2022
return getConfigGradleJavaHome() || process.env.JAVA_HOME;
}

export async function checkEnvJavaExecutable(): Promise<boolean> {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't see any async statements in the body.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let me remove "async" of this function and getGradleServerEnv().

VSCODE_JAVA_HOME: javaHome,
});
} else if (!(await checkEnvJavaExecutable())) {
return undefined;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what will happen if undefined is returned? compared with previous behavior where env is returned.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

prompt NO_JAVA_EXECUTABLE early before actually executing it?

Copy link
Collaborator Author

@CsCherrYY CsCherrYY Aug 26, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

prompt NO_JAVA_EXECUTABLE early before actually executing it?

Yes. Please refer: https://github.com/microsoft/vscode-gradle/pull/1263/files#diff-3369ade313508c278005bfe83330cb8fb4852a75783f5f5843d8d89a46423fc6R43-R46, if we can't find a proper java executable, will return early.

The previous behavior is always to run the start script via cmd variable, in this way, Gradle will report an error if no java executable can be found.

const javaHome = getConfigGradleJavaHome() || process.env.JAVA_HOME;
const javaHome = getJavaHome();
let javaCommand;
if (!javaHome) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just 2 cents, flip the if-else branch would be more human-readable for me, because you don't assign a new javaHome in if !javaHome block..

Below makes more sense to me:

a)

if (!javaHome) {
    javaHome = .....
    // do something requiring javaHome
} else {
    // do something requiring javaHome
}

b)

if (javaHome) {
    // do something requiring javaHome
} else {
    // do something unrelated with javaHome
}

@CsCherrYY CsCherrYY merged commit 5415347 into develop Aug 26, 2022
@CsCherrYY CsCherrYY deleted the cs-issue1249 branch August 26, 2022 05:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

JAVA_HOME or java.jdt.ls.java.home should not be required for projects that don't develop Java code

2 participants