Skip to content

Commit

Permalink
Provide better error message when jdk metadata cannot be resolved (#7…
Browse files Browse the repository at this point in the history
…6607)

This should help track down problems with the GlobalInfoPlugin people reported
  • Loading branch information
breskeby authored Aug 17, 2021
1 parent 5aa4a94 commit 1435e48
Showing 1 changed file with 17 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@
import org.gradle.jvm.toolchain.internal.InstallationLocation;
import org.gradle.jvm.toolchain.internal.JavaInstallationRegistry;
import org.gradle.util.GradleVersion;
import org.jetbrains.annotations.NotNull;

import javax.inject.Inject;
import java.io.BufferedReader;
Expand Down Expand Up @@ -67,7 +66,7 @@ public GlobalBuildInfoPlugin(
ProviderFactory providers
) {
this.javaInstallationRegistry = javaInstallationRegistry;
this.metadataDetector = metadataDetector;
this.metadataDetector = new ErrorTraceMetadataDetector(metadataDetector);
this.providers = providers;
}

Expand Down Expand Up @@ -364,5 +363,21 @@ public static String getResourceContents(String resourcePath) {
}
}

private static class ErrorTraceMetadataDetector implements JvmMetadataDetector {
private final JvmMetadataDetector delegate;

ErrorTraceMetadataDetector(JvmMetadataDetector delegate) {
this.delegate = delegate;
}

@Override
public JvmInstallationMetadata getMetadata(File file) {
JvmInstallationMetadata metadata = delegate.getMetadata(file);
if(metadata instanceof JvmInstallationMetadata.FailureInstallationMetadata) {
throw new GradleException("Jvm Metadata cannot be resolved for " + metadata.getJavaHome().toString());
}
return metadata;
}
}

}

0 comments on commit 1435e48

Please sign in to comment.