Skip to content

Commit

Permalink
Fix java incompatibility check
Browse files Browse the repository at this point in the history
  • Loading branch information
donat committed Jul 31, 2024
1 parent 42824d1 commit dbb3bf2
Showing 1 changed file with 16 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ public static IStatus validateToolingApiCompatibility(GradleBuild gradleBuild, B
BuildEnvironment environment = gradleBuild.withConnection(connection -> connection.getModel(BuildEnvironment.class), monitor);
gradleVersion = environment.getGradle().getGradleVersion();
} catch (Exception e) {
if (e.getMessage().contains(UNSUPPORTED_BUILD_ENVIRONMENT_MESSAGE)) {
if (hasUnsupportedBuildEnvironmentMessage(e)) {
return ToolingApiStatus.from("Project synchronization", new UnsupportedJavaVersionException(String.format("The current build uses Java %s which is not supported. Please consult the Gradle documentation to find the compatible combinations: https://docs.gradle.org/current/userguide/compatibility.html.", javaVersion)));
}
return ToolingApiStatus.from("Project synchronization", e);
Expand All @@ -72,6 +72,21 @@ public static IStatus validateToolingApiCompatibility(GradleBuild gradleBuild, B
return new Status(IStatus.OK, CorePlugin.PLUGIN_ID, "tooling API compatibility check passed");
}

private static boolean hasUnsupportedBuildEnvironmentMessage(Exception e) {
Set<Throwable> seen = new HashSet<>();
Throwable current = e;
while (current != null) {
if (current.getMessage().contains(UNSUPPORTED_BUILD_ENVIRONMENT_MESSAGE)) {
return true;
}
if (!seen.add(current)) {
break;
}
current = current.getCause();
}
return false;
}

private static Map<String, Set<String>> loadCompatibilityMap() throws GradlePluginsRuntimeException {
Map<String, Set<String>> compatibilityMatrix = new HashMap<>();
URL resource = CompatibilityChecker.class.getResource(PROPERTIES_FILE);
Expand Down

0 comments on commit dbb3bf2

Please sign in to comment.