Skip to content

Commit

Permalink
Provide better error message when jdk metadata cannot be resolved (el…
Browse files Browse the repository at this point in the history
…astic#76607) (elastic#76608)

This should help track down problems with the GlobalInfoPlugin people reported
  • Loading branch information
breskeby authored Aug 17, 2021
1 parent bc278d6 commit 0055c15
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 @@ -68,7 +67,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 0055c15

Please sign in to comment.