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

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

Merged
merged 2 commits into from
Aug 26, 2022

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().

const env = { ...process.env };
if (javaHome) {
Object.assign(env, {
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.

@@ -53,30 +54,24 @@ export async function startLanguageServer(
serverOptions = awaitServerConnection.bind(null, port);
} else {
// keep consistent with gRPC server
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