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

feat: Support local Gradle installation #926

Merged
merged 1 commit into from
Aug 20, 2021
Merged
Show file tree
Hide file tree
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
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,7 @@ This extension supports the following settings which are contributed by the [Jav
- `java.import.gradle.jvmArguments`: JVM arguments to pass to Gradle
- `java.import.gradle.wrapper.enabled`: Enable/disable the Gradle wrapper
- `java.import.gradle.version`: Gradle version, used if the Gradle wrapper is missing or disabled
- `java.import.gradle.home`: Use Gradle from the specified local installation directory or GRADLE_HOME if the Gradle wrapper is missing or disabled and no 'java.import.gradle.version' is specified.

### Class References

Expand Down
10 changes: 10 additions & 0 deletions extension/src/util/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,12 @@ export function getConfigJavaImportGradleVersion(): string | null {
.get<string | null>('import.gradle.version', null);
}

export function getConfigJavaImportGradleHome(): string | null {
return vscode.workspace
.getConfiguration('java')
.get<string | null>('import.gradle.home', null);
}

export function getConfigIsDebugEnabled(): boolean {
return vscode.workspace
.getConfiguration('gradle')
Expand Down Expand Up @@ -107,9 +113,13 @@ export function getConfigJavaDebug(

export function getGradleConfig(): GradleConfig {
const gradleConfig = new GradleConfig();
const gradleHome = getConfigJavaImportGradleHome();
const gradleUserHome = getConfigJavaImportGradleUserHome();
const gradleJvmArguments = getConfigJavaImportGradleJvmArguments();
const gradleVersion = getConfigJavaImportGradleVersion();
if (gradleHome !== null) {
gradleConfig.setGradleHome(gradleHome);
}
if (gradleUserHome !== null) {
gradleConfig.setUserHome(gradleUserHome);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,15 @@ private static void setConnectorConfig(
gradleConnector.useGradleUserHomeDir(
buildGradleUserHomeFile(config.getUserHome(), projectDir));
}
if (!config.getWrapperEnabled() && Strings.isNullOrEmpty(config.getVersion())) {
throw new GradleConnectionException("Gradle version is required");
}
if (!Strings.isNullOrEmpty(config.getVersion())) {
gradleConnector.useGradleVersion(config.getVersion());
if (!config.getWrapperEnabled()) {
if (!Strings.isNullOrEmpty(config.getVersion())) {
gradleConnector.useGradleVersion(config.getVersion());
} else if (!Strings.isNullOrEmpty(config.getGradleHome())) {
gradleConnector.useInstallation(new File(config.getGradleHome()));
} else {
throw new GradleConnectionException(
"java.import.gradle.home is invalid, please check it again.");
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,8 @@ public void getBuild_shouldUseGradleUserHome() throws IOException {
}

@Test
public void getBuild_shouldThrowIfWrapperNotEnabledAndNoVersionSpecified() throws IOException {
public void getBuild_shouldThrowIfWrapperNotEnabledAndNoVersionAndNoGradleHomeSpecified()
throws IOException {
StreamObserver<GetBuildReply> mockResponseObserver =
(StreamObserver<GetBuildReply>) mock(StreamObserver.class);

Expand All @@ -213,7 +214,9 @@ public void getBuild_shouldThrowIfWrapperNotEnabledAndNoVersionSpecified() throw
ArgumentCaptor<Throwable> onError = ArgumentCaptor.forClass(Throwable.class);
stub.getBuild(req, mockResponseObserver);
verify(mockResponseObserver).onError(onError.capture());
assertEquals("INTERNAL: Gradle version is required", onError.getValue().getMessage());
assertEquals(
"INTERNAL: java.import.gradle.home is invalid, please check it again.",
onError.getValue().getMessage());
}

@Test
Expand Down Expand Up @@ -342,7 +345,8 @@ public void runBuild_shouldUseGradleUserHome() throws IOException {
}

@Test
public void runBuild_shouldThrowIfWrapperNotEnabledAndNoVersionSpecified() throws IOException {
public void runBuild_shouldThrowIfWrapperNotEnabledAndNoVersionAndNoGradleHomeSpecified()
throws IOException {
StreamObserver<RunBuildReply> mockResponseObserver =
(StreamObserver<RunBuildReply>) mock(StreamObserver.class);

Expand All @@ -356,7 +360,9 @@ public void runBuild_shouldThrowIfWrapperNotEnabledAndNoVersionSpecified() throw
ArgumentCaptor<Throwable> onError = ArgumentCaptor.forClass(Throwable.class);
stub.runBuild(req, mockResponseObserver);
verify(mockResponseObserver).onError(onError.capture());
assertEquals("INTERNAL: Gradle version is required", onError.getValue().getMessage());
assertEquals(
"INTERNAL: java.import.gradle.home is invalid, please check it again.",
onError.getValue().getMessage());
}

@Test
Expand Down
1 change: 1 addition & 0 deletions proto/gradle.proto
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,7 @@ message DaemonInfo {
}

message GradleConfig {
string gradle_home = 1;
string user_home = 2;
string jvm_arguments = 3;
bool wrapper_enabled = 4;
Expand Down