Mercurial > hg > release > icedtea-web-1.8
changeset 1529:9bac379fb97e
verbose also from deployment.properties
* rust-launcher/src/main.rs: now reading verbose also from deployment.properties
* rust-launcher/src/property_from_file.rs: added wrapping functions to load deployment.log boolean
* rust-launcher/src/property_from_files_resolver.rs: refactored to use new validators
author | Jiri Vanek <jvanek@redhat.com> |
---|---|
date | Fri, 30 Nov 2018 19:12:09 +0100 |
parents | e44b9395ae5b |
children | 99b77a265f54 |
files | ChangeLog rust-launcher/src/main.rs rust-launcher/src/property_from_file.rs rust-launcher/src/property_from_files_resolver.rs |
diffstat | 4 files changed, 83 insertions(+), 3 deletions(-) [+] |
line wrap: on
line diff
--- a/ChangeLog Fri Nov 30 19:04:42 2018 +0100 +++ b/ChangeLog Fri Nov 30 19:12:09 2018 +0100 @@ -1,3 +1,10 @@ +2018-11-30 Jiri Vanek <jvanek@redhat.com> + + verbose also from deployment.properties + * rust-launcher/src/main.rs: now reading verbose also from deployment.properties + * rust-launcher/src/property_from_file.rs: added wrapping functions to load deployment.log boolean + * rust-launcher/src/property_from_files_resolver.rs: refactored to use new validators + 2018-11-30 Jiri Vanek <jvanek@redhat.com> Rust properties parser generalized to be reusable
--- a/rust-launcher/src/main.rs Fri Nov 30 19:04:42 2018 +0100 +++ b/rust-launcher/src/main.rs Fri Nov 30 19:12:09 2018 +0100 @@ -19,7 +19,8 @@ return true; } } - return false; + let os = os_access::Linux::new(false); + return property_from_files_resolver::try_main_verbose_from_properties(&os); } fn main() {
--- a/rust-launcher/src/property_from_file.rs Fri Nov 30 19:04:42 2018 +0100 +++ b/rust-launcher/src/property_from_file.rs Fri Nov 30 19:12:09 2018 +0100 @@ -31,6 +31,29 @@ } } +pub struct BoolValidator {} + + +impl Validator for BoolValidator { + fn validate(&self, s: &str) -> bool { + verify_bool_string(&s.to_string()) + } + + fn get_fail_message(&self, key: &str, value: &str, file: &Option<std::path::PathBuf>) -> String { + let mut res = String::new(); + write!(&mut res, "the boolean value of {} read from {} under key {} is not valid. Expected true or false (key insensitive)", value, file.clone().expect("jre path should be loaded").display(), key).expect("unwrap failed"); + return res; + } +} + +fn verify_bool_string(val: &String) -> bool { + val.trim().to_lowercase() == "true" || val.trim().to_lowercase() == "false" +} + +pub fn str_to_bool(val: &String) -> bool { + val.trim().to_lowercase() == "true" +} + fn is_file(path: &std::path::PathBuf) -> bool { path.metadata().map(|md| md.is_file()).unwrap_or(false) } @@ -166,6 +189,38 @@ assert_eq!(None, prop); } + #[test] + fn verify_bool_string_true() { + assert_eq!(true, super::verify_bool_string(&String::from("true"))); + assert_eq!(true, super::verify_bool_string(&String::from("True"))); + assert_eq!(true, super::verify_bool_string(&String::from("TRUE"))); + assert_eq!(true, super::verify_bool_string(&String::from("false"))); + assert_eq!(true, super::verify_bool_string(&String::from("FALSE"))); + assert_eq!(true, super::verify_bool_string(&String::from("False"))); + } + + #[test] + fn verify_bool_string_false() { + assert_eq!(false, super::verify_bool_string(&String::from("truee"))); + assert_eq!(false, super::verify_bool_string(&String::from("WHATEVER"))); + } + + #[test] + fn str_to_bool_true() { + assert_eq!(true, super::str_to_bool(&String::from("true"))); + assert_eq!(true, super::str_to_bool(&String::from("True"))); + assert_eq!(true, super::str_to_bool(&String::from("TRUE"))); + } + + #[test] + fn str_to_bool_false() { + assert_eq!(false, super::str_to_bool(&String::from("truee"))); + assert_eq!(false, super::str_to_bool(&String::from("WHATEVER"))); + assert_eq!(false, super::str_to_bool(&String::from("false"))); + assert_eq!(false, super::str_to_bool(&String::from("FALSE"))); + assert_eq!(false, super::str_to_bool(&String::from("False"))); + } + #[test] fn get_jre_from_file_notexists() {
--- a/rust-launcher/src/property_from_files_resolver.rs Fri Nov 30 19:04:42 2018 +0100 +++ b/rust-launcher/src/property_from_files_resolver.rs Fri Nov 30 19:12:09 2018 +0100 @@ -6,7 +6,8 @@ use std::string::String; use std::fmt::Write; -pub fn try_jdk_from_properties(logger: &os_access::Os) -> Option<String> { + +fn get_basic_array(logger: &os_access::Os) -> [Option<std::path::PathBuf>; 4] { //obviously search in jre dir is missing, when we search for jre let array: [Option<std::path::PathBuf>; 4] = [ dirs_paths_helper::get_itw_config_file(logger), @@ -14,7 +15,23 @@ dirs_paths_helper::get_itw_legacy_global_config_file(logger), dirs_paths_helper::get_itw_global_config_file(logger) ]; - try_key_from_properties_files(logger, &array, property_from_file::JRE_PROPERTY_NAME, &property_from_file::JreValidator {}) + array +} + +pub fn try_jdk_from_properties(logger: &os_access::Os) -> Option<String> { + try_key_from_properties_files(logger, &get_basic_array(logger), property_from_file::JRE_PROPERTY_NAME, &property_from_file::JreValidator {}) +} + +pub fn try_main_verbose_from_properties(logger: &os_access::Os) -> bool { + let str_bool = try_key_from_properties_files(logger, &get_basic_array(logger), property_from_file::VERBOSE_PROPERTY_NAME, &property_from_file::BoolValidator {}); + match str_bool { + Some(val) => { + property_from_file::str_to_bool(&val) + } + None => { + false + } + } } fn try_key_from_properties_files(logger: &os_access::Os, array: &[Option<std::path::PathBuf>], key: &str, validator: &property_from_file::Validator) -> Option<String> {