changeset 1563:28e4c119eb8b

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
author Jiri Vanek <jvanek@redhat.com>
date Wed, 20 Feb 2019 18:23:45 +0100
parents 79a273bcbf4a
children a2f3b98774ab
files ChangeLog netx/net/sourceforge/jnlp/config/BasicValueValidators.java netx/net/sourceforge/jnlp/config/Defaults.java netx/net/sourceforge/jnlp/resources/Messages.properties rust-launcher/src/jars_helper.rs rust-launcher/src/property_from_files_resolver.rs rust-launcher/src/utils.rs
diffstat 7 files changed, 157 insertions(+), 5 deletions(-) [+]
line wrap: on
line diff
--- 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 <jvanek@redhat.com>
+
+	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 <jvanek@redhat.com>
 
 	Implemented forgotten support for mslinks.jar library in rust launchers
--- 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 = ",";
 
--- 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<String, Setting<String>> result = new HashMap<>();
--- 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
--- 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<std::path::PathBuf>) {
+    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<std::path::PathBuf>) {
+    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<std::path::PathBuf>) {
+    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<std::path::PathBuf>) {
+    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<std::path::PathBuf> {
     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<std::path::PathBuf> {
+fn get_cp_members(jre_path: &std::path::PathBuf, os: &os_access::Os) -> Vec<std::path::PathBuf> {
     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<std::path::PathBuf> = 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<std::path::PathBuf> = 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);
+
+    }
 }
--- 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<std::path::PathBuf>], key: &str, validator: &property_from_file::Validator) -> Option<String> {
     for file in array {
--- 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<std::path::PathBuf> {
-            panic!("not implemented");
+            None
         }
 
         fn get_user_config_dir(&self) -> Option<std::path::PathBuf> {
-            panic!("not implemented");
+            None
         }
 
         fn get_legacy_system_config_javadir(&self) -> Option<std::path::PathBuf> {
-            panic!("not implemented");
+            None
         }
 
         fn get_legacy_user_config_dir(&self) -> Option<std::path::PathBuf> {
-            panic!("not implemented");
+           None
         }
 
         fn get_home(&self) -> Option<std::path::PathBuf> {