-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Improve error messages when checking tasks (#3194)
* 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 probe
- Loading branch information
1 parent
dab4531
commit 0319db1
Showing
9 changed files
with
157 additions
and
104 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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" | ||
} |
38 changes: 38 additions & 0 deletions
38
...obe/src/main/java/org/jetbrains/compose/desktop/application/internal/JdkVersionProbe.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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); | ||
} | ||
} |
Oops, something went wrong.