/hg/icedtea-web: Native launchers got splash support
jvanek at icedtea.classpath.org
jvanek at icedtea.classpath.org
Mon Feb 4 16:50:37 UTC 2019
changeset 3bb7eb063740 in /hg/icedtea-web
details: http://icedtea.classpath.org/hg/icedtea-web?cmd=changeset;node=3bb7eb063740
author: Jiri Vanek <jvanek at redhat.com>
date: Mon Feb 04 17:50:17 2019 +0100
Native launchers got splash support
* rust-launcher/src/main.rs: made parsing of variables and arguments testable; added handling of splash Fixed issue with wrongly parsed -switch from commandline; splash is now added to java command if not forbidden or headless added tests for all above
diffstat:
ChangeLog | 7 +
rust-launcher/src/main.rs | 229 +++++++++++++++++++++++++++++++++++++++++++--
2 files changed, 223 insertions(+), 13 deletions(-)
diffs (314 lines):
diff -r 4c5a2c8d2db4 -r 3bb7eb063740 ChangeLog
--- a/ChangeLog Tue Jan 15 18:08:34 2019 +0100
+++ b/ChangeLog Mon Feb 04 17:50:17 2019 +0100
@@ -1,3 +1,10 @@
+2019-02-04 Jiri Vanek <jvanek at redhat.com>
+
+ Native launchers got splash support
+ * rust-launcher/src/main.rs: made parsing of variables and arguments testable; added handling of splash
+ Fixed issue with wrongly parsed -switch from commandline; splash is now added to java command if not forbidden or headless
+ added tests for all above
+
2019-01-15 Jiri Vanek <jvanek at redhat.com>
Relaxed vendor and title to be no longer mandatory - based on oracle javaws behavior
diff -r 4c5a2c8d2db4 -r 3bb7eb063740 rust-launcher/src/main.rs
--- a/rust-launcher/src/main.rs Tue Jan 15 18:08:34 2019 +0100
+++ b/rust-launcher/src/main.rs Mon Feb 04 17:50:17 2019 +0100
@@ -13,19 +13,56 @@
use std::env;
fn is_debug_on() -> bool {
- for s in env::args() {
- //this can go wrong with case like -jnlp file-verbose or -html file-verbose
- //but it is really unlikely case as those are ususally .jnlp or .html suffixed
- if s.ends_with("-verbose") {
+ match is_debug_on_testable(env::args().collect::<Vec<_>>()) {
+ Some(val) => {
+ return val;
+ }
+ _none => {
+ let os = os_access::Linux::new(false);
+ return property_from_files_resolver::try_main_verbose_from_properties(&os);
+ }
+ }
+}
+
+fn is_debug_on_testable(aargs: Vec<String>) -> Option<bool> {
+ for s in aargs {
+ if clean_param(s) == ("-verbose") {
+ return Some(true);
+ }
+ }
+ None
+}
+
+fn is_headless_enforced() -> bool {
+ is_headless_enforced_testable(env::args().collect::<Vec<_>>())
+}
+
+fn is_headless_enforced_testable(aargs: Vec<String>) -> bool {
+ for s in aargs {
+ if clean_param(s) == ("-headless") {
return true;
}
}
- let os = os_access::Linux::new(false);
- return property_from_files_resolver::try_main_verbose_from_properties(&os);
+ false
+}
+
+fn is_splash_forbidden() -> bool {
+ is_splash_forbidden_testable(env::vars().collect::<Vec<_>>())
+}
+
+fn is_splash_forbidden_testable(vars: Vec<(String, String)>) -> bool {
+ for (key, value) in vars {
+ if key == "ICEDTEA_WEB_SPLASH" {
+ if value.to_lowercase() == "true" {
+ return false;
+ }
+ return true;
+ }
+ }
+ false
}
fn main() {
- //TODO verbose will be populated by also from deployment properties
let os = os_access::Linux::new(is_debug_on());
os.log(&dirs_paths_helper::path_to_string(&dirs_paths_helper::current_program()));
let mut info1 = String::new();
@@ -40,7 +77,7 @@
let s = a.skip(1);
let c: std::vec::Vec<String> = s.collect();
- let mut child = os.spawn_java_process(&java_dir, &compose_arguments(&java_dir, &c, &os));
+ let mut child = os.spawn_java_process(&java_dir, &compose_arguments(&java_dir, &c, &os));
let ecode = child.wait().expect("failed to wait on child");
let code = ecode.code().expect("code should be always here");
std::process::exit(code)
@@ -74,7 +111,6 @@
write!(&mut info2, "itw-rust-debug: current bin: {}", &dirs_paths_helper::path_to_string(¤t_bin)).expect("unwrap failed");
os.log(&info2);
- let splash = jars_helper::resolve_splash(os);
let mut bin_name = String::from("-Dicedtea-web.bin.name=");
let mut bin_location = String::from("-Dicedtea-web.bin.location=");
//no metter what ITW_LIBS are saying, imho using current pgm is always correct comapred to hardcoded values
@@ -85,6 +121,15 @@
include_dashJs_values(&original_args, &mut all_args, os);
+ match get_splash(os) {
+ Some(switch) => {
+ all_args.push(switch);
+ }
+ _none => {
+ os.log("itw-rust-debug: splash excluded");
+ }
+ }
+
all_args.push(bootcp);
all_args.push(String::from("-classpath"));
all_args.push(cp);
@@ -97,6 +142,37 @@
all_args
}
+fn get_splash(os: &os_access::Os) -> Option<String> {
+ let headless = is_headless_enforced();
+ let splash_forbidden = is_splash_forbidden();
+ get_splash_testable(headless, splash_forbidden, os)
+}
+
+fn get_splash_testable(headless: bool, splash_forbidden: bool, os: &os_access::Os) -> Option<String> {
+ if !headless && !splash_forbidden {
+ let splash_location = dirs_paths_helper::path_to_string(&jars_helper::resolve_splash(os));
+ let mut owned_string: String = splash_location.to_owned();
+ let splash_switch: &str = "-splash:";
+ owned_string.insert_str(0, splash_switch);
+ let r = String::from(owned_string);
+ Some(r)
+ } else {
+ None
+ }
+}
+
+fn clean_param(s: String) -> String {
+ let mut ss = String::from(s);
+ let was = ss.starts_with("-");
+ while ss.starts_with("-") {
+ ss = ss[1..ss.len()].to_string();
+ }
+ if was {
+ ss.insert_str(0, "-");
+ }
+ String::from(ss)
+}
+
#[allow(non_snake_case)]
fn include_not_dashJs(srcs: &Vec<std::string::String>, target: &mut Vec<std::string::String>) {
for f in srcs.iter() {
@@ -124,6 +200,131 @@
pub mod tests_main {
use utils::tests_utils as tu;
+ #[test]
+ fn is_splash_forbidden_test() {
+ let mut vec: Vec<(String, String)> = Vec::new();
+ assert_eq!(super::is_splash_forbidden_testable(vec), false);
+ vec = Vec::new();
+ vec.push(("".to_string(), "".to_string()));
+ assert_eq!(super::is_splash_forbidden_testable(vec), false);
+ vec = Vec::new();
+ vec.push(("-blah".to_string(), "-blah".to_string()));
+ vec.push(("-verbose".to_string(), "-blah".to_string()));
+ assert_eq!(super::is_splash_forbidden_testable(vec), false);
+ vec = Vec::new();
+ vec.push(("-blah".to_string(), "-blah".to_string()));
+ vec.push(("ICEDTEA_WEB_SPLASH".to_string(), "".to_string()));
+ vec.push(("-headless".to_string(),"-blah".to_string()));
+ assert_eq!(super::is_splash_forbidden_testable(vec), true);
+ vec = Vec::new();
+ vec.push(("-blah".to_string(), "-blah".to_string()));
+ vec.push(("ICEDTEA_WEB_SPLASH".to_string(), "".to_string()));
+ vec.push(("---headless".to_string(), "-blah".to_string()));
+ assert_eq!(super::is_splash_forbidden_testable(vec), true);
+ vec = Vec::new();
+ vec.push(("-blah".to_string(), "-blah".to_string()));
+ vec.push(("aICEDTEA_WEB_SPLASH".to_string(), "".to_string()));
+ vec.push(("---headless".to_string(), "-blah".to_string()));
+ assert_eq!(super::is_splash_forbidden_testable(vec), false);
+ vec = Vec::new();
+ vec.push(("-blah".to_string(), "-blah".to_string()));
+ vec.push(("ICEDTEA_WEB_SPLASHb".to_string(), "".to_string()));
+ vec.push(("---headless".to_string(), "-blah".to_string()));
+ assert_eq!(super::is_splash_forbidden_testable(vec), false);
+ vec = Vec::new();
+ vec.push(("-blah".to_string(), "-blah".to_string()));
+ vec.push(("aICEDTEA_WEB_SPLASHb".to_string(), "".to_string()));
+ vec.push(("---headless".to_string(), "-blah".to_string()));
+ assert_eq!(super::is_splash_forbidden_testable(vec), false);
+ vec = Vec::new();
+ vec.push(("ICEDTEA_WEB_SPLASH".to_string(), "value".to_string()));
+ vec.push(("---headless".to_string(), "-blah".to_string()));
+ assert_eq!(super::is_splash_forbidden_testable(vec), true);
+ vec = Vec::new();
+ vec.push(("ICEDTEA_WEB_SPLASH".to_string(), "true".to_string()));
+ vec.push(("---headless".to_string(), "-blah".to_string()));
+ assert_eq!(super::is_splash_forbidden_testable(vec), false);
+ }
+
+ #[test]
+ fn is_headless_enforced_test() {
+ let mut vec: Vec<String> = Vec::new();
+ assert_eq!(super::is_headless_enforced_testable(vec), false);
+ vec = Vec::new();
+ vec.push("".to_string());
+ assert_eq!(super::is_headless_enforced_testable(vec), false);
+ vec = Vec::new();
+ vec.push("-blah".to_string());
+ vec.push("-verbose".to_string());
+ assert_eq!(super::is_headless_enforced_testable(vec), false);
+ vec = Vec::new();
+ vec.push("-blah".to_string());
+ vec.push("-verbose".to_string());
+ vec.push("headless".to_string());
+ assert_eq!(super::is_headless_enforced_testable(vec), false);
+ vec = Vec::new();
+ vec.push("-blah".to_string());
+ vec.push("-verbose".to_string());
+ vec.push("-headless".to_string());
+ assert_eq!(super::is_headless_enforced_testable(vec), true);
+ vec = Vec::new();
+ vec.push("-blah".to_string());
+ vec.push("-verbose".to_string());
+ vec.push("---headless".to_string());
+ assert_eq!(super::is_headless_enforced_testable(vec), true);
+ }
+
+ #[test]
+ fn is_debug_on_test() {
+ let mut vec: Vec<String> = Vec::new();
+ assert_eq!(super::is_debug_on_testable(vec), None);
+ vec = Vec::new();
+ vec.push("".to_string());
+ assert_eq!(super::is_debug_on_testable(vec), None);
+ vec = Vec::new();
+ vec.push("-blah".to_string());
+ vec.push("-headless".to_string());
+ assert_eq!(super::is_debug_on_testable(vec), None);
+ vec = Vec::new();
+ vec.push("-blah".to_string());
+ vec.push("verbose".to_string());
+ vec.push("-headless".to_string());
+ assert_eq!(super::is_debug_on_testable(vec), None);
+ vec = Vec::new();
+ vec.push("-blah".to_string());
+ vec.push("-verbose".to_string());
+ vec.push("-headless".to_string());
+ assert_eq!(super::is_debug_on_testable(vec), Some(true));
+ vec = Vec::new();
+ vec.push("-blah".to_string());
+ vec.push("---verbose".to_string());
+ vec.push("-headless".to_string());
+ assert_eq!(super::is_debug_on_testable(vec), Some(true));
+ }
+
+ #[test]
+ fn get_splash_test() {
+ assert_eq!(super::get_splash_testable(true, false, &tu::TestLogger::create_new()), None);
+ assert_eq!(super::get_splash_testable(false, true, &tu::TestLogger::create_new()), None);
+ assert_eq!(super::get_splash_testable(true, true, &tu::TestLogger::create_new()), None);
+ let some = super::get_splash_testable(false, false, &tu::TestLogger::create_new());
+ assert_eq!(some == None, false);
+ let val = some.expect("is known to be not none");
+ assert_eq!(val.starts_with("-splash:"), true);
+ }
+
+ #[test]
+ fn clean_param_test() {
+ assert_eq!(super::clean_param(String::from("-verbose")), String::from("-verbose"));
+ assert_eq!(super::clean_param(String::from("--verbose")), String::from("-verbose"));
+ assert_eq!(super::clean_param(String::from("------verbose")), String::from("-verbose"));
+ assert_eq!(super::clean_param(String::from("a-headless")), String::from("a-headless"));
+ assert_eq!(super::clean_param(String::from("-a-headless")), String::from("-a-headless"));
+ assert_eq!(super::clean_param(String::from("----a-headless")), String::from("-a-headless"));
+ assert_eq!(super::clean_param(String::from("test-")), String::from("test-"));
+ assert_eq!(super::clean_param(String::from("-test-")), String::from("-test-"));
+ assert_eq!(super::clean_param(String::from("verbose")), String::from("verbose"));
+ }
#[test]
fn compose_arguments_test() {
@@ -131,11 +332,10 @@
let switches = vec![
String::from("-a"),
String::from("-J-b")];
- let result = super::compose_arguments(&std::path::PathBuf::from("/some/jre"),&switches, &tu::TestLogger::create_new());
- assert_eq!(result.len()>3, true);
+ let result = super::compose_arguments(&std::path::PathBuf::from("/some/jre"), &switches, &tu::TestLogger::create_new());
+ assert_eq!(result.len() > 3, true);
assert_eq!(result.get(0).expect("first item should exists"), &String::from("-b"));
- assert_eq!(result.get(result.len()-1).expect("last item should exists"), &String::from("-a"));
-
+ assert_eq!(result.get(result.len() - 1).expect("last item should exists"), &String::from("-a"));
}
#[test]
@@ -173,11 +373,14 @@
String::from("-J-a"),
String::from("-b"),
String::from("--Jc"),
+ String::from("-J"), //not added, have no arg
+ String::from("-J-"), //added
String::from("-Jd")];
let mut result = Vec::new();
super::include_dashJs_values(&switches, &mut result, &tu::TestLogger::create_new());
let ex = vec![
String::from("-a"),
+ String::from("-"),
String::from("d")];
assert_eq!(ex, result);
}
More information about the distro-pkg-dev
mailing list