From 1435e485788672f0c8c252eea6914c7fb2df55fa Mon Sep 17 00:00:00 2001 From: Rene Groeschke Date: Tue, 17 Aug 2021 12:02:58 +0200 Subject: [PATCH] Provide better error message when jdk metadata cannot be resolved (#76607) This should help track down problems with the GlobalInfoPlugin people reported --- .../internal/info/GlobalBuildInfoPlugin.java | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/build-tools-internal/src/main/java/org/elasticsearch/gradle/internal/info/GlobalBuildInfoPlugin.java b/build-tools-internal/src/main/java/org/elasticsearch/gradle/internal/info/GlobalBuildInfoPlugin.java index 24b45872ec414..feb0a9105a98a 100644 --- a/build-tools-internal/src/main/java/org/elasticsearch/gradle/internal/info/GlobalBuildInfoPlugin.java +++ b/build-tools-internal/src/main/java/org/elasticsearch/gradle/internal/info/GlobalBuildInfoPlugin.java @@ -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; @@ -67,7 +66,7 @@ public GlobalBuildInfoPlugin( ProviderFactory providers ) { this.javaInstallationRegistry = javaInstallationRegistry; - this.metadataDetector = metadataDetector; + this.metadataDetector = new ErrorTraceMetadataDetector(metadataDetector); this.providers = providers; } @@ -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; + } + } }