Browse Source
* Improve error messages when checking tasks Previously some errors in checkRuntime task were reported as a nested exception. By default, Gradle shows only top-level error message of an exception, which made some errors confusing. For example, when javac was missing from JDK, Gradle only showed "Could not infer Java runtime version for Java home directory". The part that said javac was missing was only shown, when Gradle was run with --stacktrace argument. This is suboptimal UX, so this commit refactors checkRuntime to make error messages more descriptive. #3133 * Handle JDK 1.8 correctly * Prebuild jdk version probepull/3220/head
Alexey Tsvetkov
2 years ago
committed by
GitHub
9 changed files with 157 additions and 104 deletions
@ -0,0 +1,14 @@ |
|||||||
|
plugins { |
||||||
|
java |
||||||
|
id("maven-publish") |
||||||
|
} |
||||||
|
|
||||||
|
mavenPublicationConfig { |
||||||
|
displayName = "JDK version probe" |
||||||
|
description = "JDK version probe (Internal)" |
||||||
|
artifactId = "gradle-plugin-internal-jdk-version-probe" |
||||||
|
} |
||||||
|
|
||||||
|
tasks.jar.configure { |
||||||
|
manifest.attributes["Main-Class"] = "org.jetbrains.compose.desktop.application.internal.JdkVersionProbe" |
||||||
|
} |
@ -0,0 +1,38 @@ |
|||||||
|
/* |
||||||
|
* Copyright 2020-2023 JetBrains s.r.o. and respective authors and developers. |
||||||
|
* Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE.txt file. |
||||||
|
*/ |
||||||
|
package org.jetbrains.compose.desktop.application.internal; |
||||||
|
|
||||||
|
import java.lang.reflect.Method; |
||||||
|
|
||||||
|
public class JdkVersionProbe { |
||||||
|
public static void main(String[] args) { |
||||||
|
Class<Runtime> runtimeClass = Runtime.class; |
||||||
|
try { |
||||||
|
Method version = runtimeClass.getMethod("version"); |
||||||
|
Object runtimeVer = version.invoke(runtimeClass); |
||||||
|
Class<?> runtimeVerClass = runtimeVer.getClass(); |
||||||
|
try { |
||||||
|
int feature = (int) runtimeVerClass.getMethod("feature").invoke(runtimeVer); |
||||||
|
printVersionAndHalt((Integer.valueOf(feature)).toString()); |
||||||
|
} catch (NoSuchMethodException e) { |
||||||
|
int major = (int) runtimeVerClass.getMethod("major").invoke(runtimeVer); |
||||||
|
printVersionAndHalt((Integer.valueOf(major)).toString()); |
||||||
|
} |
||||||
|
} catch (Exception e) { |
||||||
|
String javaVersion = System.getProperty("java.version"); |
||||||
|
String[] parts = javaVersion.split("\\."); |
||||||
|
if (parts.length > 2 && "1".equalsIgnoreCase(parts[0])) { |
||||||
|
printVersionAndHalt(parts[1]); |
||||||
|
} else { |
||||||
|
throw new IllegalStateException("Could not determine JDK version from string: '" + javaVersion + "'"); |
||||||
|
} |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
private static void printVersionAndHalt(String version) { |
||||||
|
System.out.println(version); |
||||||
|
Runtime.getRuntime().exit(0); |
||||||
|
} |
||||||
|
} |
Loading…
Reference in new issue