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 9c0b5e1a783c9..943c7eca84b37 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; @@ -68,7 +67,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; + } + } }