add one more check for awt
This commit is contained in:
parent
2a711c1ef3
commit
d45153a41c
3 changed files with 39 additions and 12 deletions
Binary file not shown.
|
|
@ -19,6 +19,7 @@ public final class JavaInfo {
|
|||
|
||||
System.out.println("java.awt=" + hasClass("java.awt.Toolkit"));
|
||||
System.out.println("java.awt.natives=" + hasAwtNatives());
|
||||
System.out.println("java.awt.link=" + awtLinks());
|
||||
System.out.println("java.jdk=" + hasCompiler());
|
||||
|
||||
System.exit(returnCode);
|
||||
|
|
@ -76,6 +77,17 @@ public final class JavaInfo {
|
|||
return false;
|
||||
}
|
||||
|
||||
private static boolean awtLinks() {
|
||||
try {
|
||||
java.awt.GraphicsEnvironment.getLocalGraphicsEnvironment().getClass();
|
||||
return true;
|
||||
} catch (LinkageError broken) {
|
||||
return false;
|
||||
} catch (Throwable ignored) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
private static boolean hasCompiler() {
|
||||
try {
|
||||
return javax.tools.ToolProvider.getSystemJavaCompiler() != null;
|
||||
|
|
|
|||
|
|
@ -73,6 +73,7 @@ pub async fn check_java_runtime(absolute_path: String) -> JavaResult<JavaCheckIn
|
|||
path = %absolute_path,
|
||||
classes = probe_flag(&info, "java.awt"),
|
||||
natives = probe_flag(&info, "java.awt.natives"),
|
||||
links = probe_flag(&info, "java.awt.link"),
|
||||
"java installation has no usable java.awt support"
|
||||
);
|
||||
return Err(JavaError::MissingAwtSupport { path: absolute_path });
|
||||
|
|
@ -93,7 +94,9 @@ pub async fn check_java_runtime(absolute_path: String) -> JavaResult<JavaCheckIn
|
|||
}
|
||||
|
||||
fn has_usable_awt(info: &HashMap<String, String>) -> bool {
|
||||
probe_flag(info, "java.awt") && probe_flag(info, "java.awt.natives")
|
||||
probe_flag(info, "java.awt")
|
||||
&& probe_flag(info, "java.awt.natives")
|
||||
&& probe_flag(info, "java.awt.link")
|
||||
}
|
||||
|
||||
fn probe_flag(info: &HashMap<String, String>, key: &str) -> bool {
|
||||
|
|
@ -141,21 +144,33 @@ mod tests {
|
|||
assert!(!probe_flag(&info(&[("java.awt", "false")]), "java.awt"));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn awt_classes_without_their_natives_are_not_usable() {
|
||||
assert!(!has_usable_awt(&info(&[
|
||||
("java.awt", "true"),
|
||||
("java.awt.natives", "false"),
|
||||
])));
|
||||
fn awt(classes: &str, natives: &str, link: &str) -> HashMap<String, String> {
|
||||
info(&[
|
||||
("java.awt", classes),
|
||||
("java.awt.natives", natives),
|
||||
("java.awt.link", link),
|
||||
])
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn awt_needs_both_halves() {
|
||||
assert!(has_usable_awt(&info(&[
|
||||
("java.awt", "true"),
|
||||
("java.awt.natives", "true"),
|
||||
])));
|
||||
fn a_complete_image_is_usable() {
|
||||
assert!(has_usable_awt(&awt("true", "true", "true")));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn awt_classes_without_their_natives_are_not_usable() {
|
||||
assert!(!has_usable_awt(&awt("true", "false", "true")));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn natives_that_refuse_to_link_are_not_usable() {
|
||||
assert!(!has_usable_awt(&awt("true", "true", "false")));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn every_half_is_required() {
|
||||
assert!(!has_usable_awt(&info(&[("java.awt", "true")])));
|
||||
assert!(!has_usable_awt(&info(&[("java.awt.natives", "true")])));
|
||||
assert!(!has_usable_awt(&info(&[("java.awt.link", "true")])));
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue