# HG changeset patch # User Jiri Vanek # Date 1550683425 -3600 # Node ID 28e4c119eb8b3b51eca1da9f7bd73646363207b7 # Parent 79a273bcbf4a8658c7b183261574b4ce15b1bb19 Implemented way how to modify cp/bootcp in native launchers * netx/net/sourceforge/jnlp/config/BasicValueValidators.java: added (RustCpValidator) as provider for help for new properties * netx/net/sourceforge/jnlp/config/Defaults.java: declared for properties to control native lanchers cp/bootcp deployment.launcher.rust.{cp,bootcp}.{add,remove} * netx/net/sourceforge/jnlp/resources/Messages.properties: added help message for new properties * rust-launcher/src/jars_helper.rs: (get_{bootcp,cp}_members) method nw filter items in and from based on properties added and tested new methods (filter_in_val) to add string to vector, and (filter_out_val) to remove matching items from vector * rust-launcher/src/property_from_files_resolver.rs: added try_direct_key_from_properties to get raw property without validation and without option. * rust-launcher/src/utils.rs: test logger return none rather then panic for providing of properties files diff -r 79a273bcbf4a -r 28e4c119eb8b ChangeLog --- a/ChangeLog Mon Feb 18 17:41:52 2019 +0100 +++ b/ChangeLog Wed Feb 20 18:23:45 2019 +0100 @@ -1,3 +1,17 @@ +2019-02-20 Jiri Vanek + + Implemented way how to modify cp/bootcp in native launchers + * netx/net/sourceforge/jnlp/config/BasicValueValidators.java: added (RustCpValidator) as provider for help for new + properties + * netx/net/sourceforge/jnlp/config/Defaults.java: declared for properties to control native lanchers cp/bootcp + deployment.launcher.rust.{cp,bootcp}.{add,remove} + * netx/net/sourceforge/jnlp/resources/Messages.properties: added help message for new properties + * rust-launcher/src/jars_helper.rs: (get_{bootcp,cp}_members) method nw filter items in and from based on properties + added and tested new methods (filter_in_val) to add string to vector, and (filter_out_val) to remove matching items from vector + * rust-launcher/src/property_from_files_resolver.rs: added try_direct_key_from_properties to get raw property without validation + and without option. + * rust-launcher/src/utils.rs: test logger return none rather then panic for providing of properties files + 2019-02-18 Jiri Vanek Implemented forgotten support for mslinks.jar library in rust launchers diff -r 79a273bcbf4a -r 28e4c119eb8b netx/net/sourceforge/jnlp/config/BasicValueValidators.java --- a/netx/net/sourceforge/jnlp/config/BasicValueValidators.java Mon Feb 18 17:41:52 2019 +0100 +++ b/netx/net/sourceforge/jnlp/config/BasicValueValidators.java Wed Feb 20 18:23:45 2019 +0100 @@ -267,6 +267,24 @@ } } + + + public static class RustCpValidator implements ValueValidator { + + + @Override + public void validate(Object value) throws IllegalArgumentException { + //cant be wrong... + //but we need that getPossibleValues description + } + + + @Override + public String getPossibleValues() { + return R("VVRustCpModifiers"); + } + + } private final static String DELIMITER = ","; diff -r 79a273bcbf4a -r 28e4c119eb8b netx/net/sourceforge/jnlp/config/Defaults.java --- a/netx/net/sourceforge/jnlp/config/Defaults.java Mon Feb 18 17:41:52 2019 +0100 +++ b/netx/net/sourceforge/jnlp/config/Defaults.java Wed Feb 20 18:23:45 2019 +0100 @@ -465,7 +465,33 @@ DeploymentConfiguration.KEY_SMALL_SIZE_OVERRIDE_TRESHOLD, BasicValueValidators.getRangedIntegerValidator(0, 1000), String.valueOf(10)// treshold when applet is considered as too small + }, + //************** + //* Native (rust) only - beggin + //************** + { + "deployment.launcher.rust.cp.add", + new BasicValueValidators.RustCpValidator(), + "" + }, + { + "deployment.launcher.rust.cp.remove", + new BasicValueValidators.RustCpValidator(), + "" + }, + { + "deployment.launcher.rust.bootcp.add", + new BasicValueValidators.RustCpValidator(), + null + }, + { + "deployment.launcher.rust.bootcp.remove", + new BasicValueValidators.RustCpValidator(), + "" } + //************** + //* Native (rust) only - end + //************** }; HashMap> result = new HashMap<>(); diff -r 79a273bcbf4a -r 28e4c119eb8b netx/net/sourceforge/jnlp/resources/Messages.properties --- a/netx/net/sourceforge/jnlp/resources/Messages.properties Mon Feb 18 17:41:52 2019 +0100 +++ b/netx/net/sourceforge/jnlp/resources/Messages.properties Wed Feb 20 18:23:45 2019 +0100 @@ -586,6 +586,7 @@ DCmaindircheckRwproblem=Your configuration directory {0} cannot be read/written properly. # Value Validator messages. Messages should follow "Possible values ..." +VVRustCpModifiers=Rust native launchers only! CP and XBootCP properties are space separated members of bootcp/cp to be removed or added. eg `...cp.add=/usr/java/rhino.jar /usr/java/scary.jar` will add those two jars to cp. Eg: `...bootcp.remove=rhino.jar tagsoup.jar` will remove those two jars no meter of path. Removal is done first. VVPossibleValues=Possible values {0} VVPossibleBooleanValues=are {0} or {1} VVPossibleFileValues=include an absolute path to a file or directory diff -r 79a273bcbf4a -r 28e4c119eb8b rust-launcher/src/jars_helper.rs --- a/rust-launcher/src/jars_helper.rs Mon Feb 18 17:41:52 2019 +0100 +++ b/rust-launcher/src/jars_helper.rs Wed Feb 20 18:23:45 2019 +0100 @@ -2,6 +2,7 @@ use env; use hardcoded_paths; use hardcoded_paths::ItwLibSearch; +use property_from_files_resolver; use os_access; use dirs_paths_helper; use std::fmt::Write; @@ -128,6 +129,39 @@ } } +pub static XCP_MODS_DELMITER: &'static str = " "; + +fn filter_out_val(val: String, vec: &mut Vec) { + let mut i:i32 = 0; + while i < (vec.len() as i32) { + let cpstring=dirs_paths_helper::path_to_string(vec.get(i as usize).expect("string should be there")); + for value in val.split(XCP_MODS_DELMITER) { + if !String::from(String::from(value).trim()).is_empty() && cpstring.contains(value) { + vec.remove(i as usize); + i = i - 1; + break; + } + } + i = i + 1; + } +} + +fn filter_out_key(key: &str, os: &os_access::Os, vec: &mut Vec) { + let val = property_from_files_resolver::try_direct_key_from_properties(key, os); + filter_out_val(val, vec); +} + +fn filter_in_val(val: String, vec: &mut Vec) { + for value in val.split(" ") { + vec.push(std::path::PathBuf::from(value)); + } +} + +fn filter_in_key(key: &str, os: &os_access::Os, vec: &mut Vec) { + let val = property_from_files_resolver::try_direct_key_from_properties(key, os); + filter_in_val(val, vec) +} + //TODO what to do with rt.jar, nashorn and javafx.jar with jdk11 and up? fn get_bootcp_members(jre_path: &std::path::PathBuf, os: &os_access::Os) -> Vec { let mut cp_parts = Vec::new(); @@ -142,12 +176,14 @@ nashorn_jar.push("ext"); nashorn_jar.push("nashorn.jar"); cp_parts.push(nashorn_jar); + filter_out_key("deployment.launcher.rust.bootcp.remove", os, &mut cp_parts, ); + filter_in_key("deployment.launcher.rust.bootcp.add", os, &mut cp_parts); cp_parts } //can this be buggy? Shouldnt jfxrt.jar be in boot classapth? Copied from shell launchers... //see eg: http://mail.openjdk.java.net/pipermail/distro-pkg-dev/2018-November/040492.html -fn get_cp_members(jre_path: &std::path::PathBuf, _os: &os_access::Os) -> Vec { +fn get_cp_members(jre_path: &std::path::PathBuf, os: &os_access::Os) -> Vec { let mut cp_parts = Vec::new(); let mut rt_jar = jre_path.clone(); rt_jar.push("lib"); @@ -157,6 +193,8 @@ jfxrt_jar.push("lib"); jfxrt_jar.push("jfxrt.jar"); cp_parts.push(jfxrt_jar); + filter_out_key("deployment.launcher.rust.cp.remove", os, &mut cp_parts, ); + filter_in_key("deployment.launcher.rust.cp.add", os, &mut cp_parts); cp_parts } @@ -185,6 +223,7 @@ #[cfg(test)] mod tests { use utils::tests_utils as tu; + use std::path::PathBuf; #[test] fn compose_class_path_test_emty() { @@ -212,4 +251,46 @@ std::path::PathBuf::from("a/b"), ], &tu::TestLogger::create_new())); } + + #[test] + fn filter_out_val_test1() { + let mut vec = vec![std::path::PathBuf::from("a"), std::path::PathBuf::from("b"), std::path::PathBuf::from("c")]; + super::filter_out_val(String::from("a c"), &mut vec); + assert_eq!(vec![std::path::PathBuf::from("b")], vec); + super::filter_out_val(String::from(""), &mut vec); + assert_eq!(vec![std::path::PathBuf::from("b")], vec); + super::filter_out_val(String::from(" "), &mut vec); + assert_eq!(vec![std::path::PathBuf::from("b")], vec); + super::filter_out_val(String::from("b"), &mut vec); + let mut empty: Vec = Vec::new(); + assert_eq!(empty, vec); + + } + + #[test] + fn filter_out_val_test2() { + let mut vec = vec![std::path::PathBuf::from("a"), std::path::PathBuf::from("b"), std::path::PathBuf::from("c")]; + super::filter_out_val(String::from("b"), &mut vec); + assert_eq!(vec![std::path::PathBuf::from("a"), std::path::PathBuf::from("c")], vec); + super::filter_out_val(String::from("a c"), &mut vec); + let mut empty: Vec = Vec::new(); + assert_eq!(empty, vec); + + } + + #[test] + fn filter_in_val_test1() { + let mut vec = vec![std::path::PathBuf::from("a")]; + super::filter_in_val(String::from("b"), &mut vec); + assert_eq!(vec![std::path::PathBuf::from("a"), std::path::PathBuf::from("b")], vec); + + } + + #[test] + fn filter_in_val_test2() { + let mut vec = vec![]; + super::filter_in_val(String::from("b"), &mut vec); + assert_eq!(vec![std::path::PathBuf::from("b")], vec); + + } } diff -r 79a273bcbf4a -r 28e4c119eb8b rust-launcher/src/property_from_files_resolver.rs --- a/rust-launcher/src/property_from_files_resolver.rs Mon Feb 18 17:41:52 2019 +0100 +++ b/rust-launcher/src/property_from_files_resolver.rs Wed Feb 20 18:23:45 2019 +0100 @@ -108,6 +108,18 @@ } } +pub fn try_direct_key_from_properties(key: &str, logger: &os_access::Os) -> String { + let str_candidate = try_key_from_properties_files(logger, &get_basic_array(logger), key, &property_from_file::NotMandatoryPathValidator {}); + match str_candidate { + Some(val) => { + val + } + None => { + return String::from("") + } + } +} + fn try_key_from_properties_files(logger: &os_access::Os, array: &[Option], key: &str, validator: &property_from_file::Validator) -> Option { for file in array { diff -r 79a273bcbf4a -r 28e4c119eb8b rust-launcher/src/utils.rs --- a/rust-launcher/src/utils.rs Mon Feb 18 17:41:52 2019 +0100 +++ b/rust-launcher/src/utils.rs Wed Feb 20 18:23:45 2019 +0100 @@ -252,19 +252,19 @@ } fn get_system_config_javadir(&self) -> Option { - panic!("not implemented"); + None } fn get_user_config_dir(&self) -> Option { - panic!("not implemented"); + None } fn get_legacy_system_config_javadir(&self) -> Option { - panic!("not implemented"); + None } fn get_legacy_user_config_dir(&self) -> Option { - panic!("not implemented"); + None } fn get_home(&self) -> Option {