Skip to content

Commit

Permalink
fix - Use 'java.import.gradle.java.home' when it's specified (#1552)
Browse files Browse the repository at this point in the history
  • Loading branch information
jdneo authored Aug 2, 2024
1 parent 4b505ad commit b71fcb2
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 4 deletions.
2 changes: 1 addition & 1 deletion .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
"request": "attach",
"hostName": "localhost",
"port": "8089",
"projectName": "com.github.badsyntax.gradle"
"projectName": "gradle-server"
},
{
"name": "Debug Gradle Server & Extension",
Expand Down
4 changes: 4 additions & 0 deletions extension/src/util/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,7 @@ export function getGradleConfig(): GradleConfig {
const gradleUserHome = getConfigJavaImportGradleUserHome();
const gradleJvmArguments = getConfigJavaImportGradleJvmArguments();
const gradleVersion = getConfigJavaImportGradleVersion();
const javaHome = getConfigJavaImportGradleJavaHome();
if (gradleHome !== null) {
gradleConfig.setGradleHome(gradleHome);
}
Expand All @@ -213,6 +214,9 @@ export function getGradleConfig(): GradleConfig {
if (gradleVersion !== null) {
gradleConfig.setVersion(gradleVersion);
}
if (javaHome !== null) {
gradleConfig.setJavaHome(javaHome);
}
gradleConfig.setWrapperEnabled(getConfigJavaImportGradleWrapperEnabled());
const javaExtension = vscode.extensions.getExtension("redhat.java");
if (javaExtension) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import com.github.badsyntax.gradle.exceptions.GradleBuildRunnerException;
import com.google.common.base.Strings;
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
Expand Down Expand Up @@ -112,6 +113,10 @@ private void runBuild(ProjectConnection connection) throws GradleBuildRunnerExce
build.setJvmArguments(gradleConfig.getJvmArguments());
}

if (!Strings.isNullOrEmpty(gradleConfig.getJavaHome())) {
build.setJavaHome(new File(gradleConfig.getJavaHome()));
}

build.run();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,9 @@ public void run() {
action.withCancellationToken(cancellationToken).addProgressListener(progressListener, progressEvents)
.setStandardOutput(standardOutputListener).setStandardError(standardErrorListener)
.setColorOutput(req.getShowOutputColors());
if (!Strings.isNullOrEmpty(req.getGradleConfig().getJavaHome())) {
action.setJavaHome(new File(req.getGradleConfig().getJavaHome()));
}
GradleProjectModel gradleModel = action.run();
if (gradleModel == null) {
throw new Exception("Error occurs in querying custom model.");
Expand Down Expand Up @@ -193,13 +196,15 @@ private Environment buildEnvironment(ProjectConnection connection) {
BuildEnvironment environment = buildEnvironment.get();
org.gradle.tooling.model.build.GradleEnvironment gradleEnvironment = environment.getGradle();
org.gradle.tooling.model.build.JavaEnvironment javaEnvironment = environment.getJava();
String javaHome = Strings.isNullOrEmpty(req.getGradleConfig().getJavaHome())
? javaEnvironment.getJavaHome().getAbsolutePath()
: req.getGradleConfig().getJavaHome();
return Environment.newBuilder()
.setGradleEnvironment(GradleEnvironment.newBuilder()
.setGradleUserHome(gradleEnvironment.getGradleUserHome().getAbsolutePath())
.setGradleVersion(gradleEnvironment.getGradleVersion()))
.setJavaEnvironment(
JavaEnvironment.newBuilder().setJavaHome(javaEnvironment.getJavaHome().getAbsolutePath())
.addAllJvmArgs(javaEnvironment.getJvmArguments()))
.setJavaEnvironment(JavaEnvironment.newBuilder().setJavaHome(javaHome)
.addAllJvmArgs(javaEnvironment.getJvmArguments()))
.build();
} finally {
GradleBuildCancellation.clearToken(req.getCancellationKey());
Expand Down
1 change: 1 addition & 0 deletions proto/gradle.proto
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,7 @@ message GradleConfig {
bool wrapper_enabled = 4;
string version = 5;
string java_extension_version = 6;
string java_home = 7;
}

message GradleBuild { GradleProject project = 1; }
Expand Down

0 comments on commit b71fcb2

Please sign in to comment.