/hg/icedtea-web: 2 new changesets
jvanek at icedtea.classpath.org
jvanek at icedtea.classpath.org
Fri Nov 30 18:12:55 UTC 2018
changeset e44b9395ae5b in /hg/icedtea-web
details: http://icedtea.classpath.org/hg/icedtea-web?cmd=changeset;node=e44b9395ae5b
author: Jiri Vanek <jvanek at redhat.com>
date: Fri Nov 30 19:04:42 2018 +0100
Rust properties parser generalized to be reusable
* rust-launcher/src/dirs_paths_helper.rs: new file, including get_xdg_config_dir, deployment.properties and similar originally from jvm_from_properties.rs
* rust-launcher/src/main.rs: adapted to re-factored state
* rust-launcher/src/os_access.rs: added and for Linux implemented get_system_config_javadir, get_user_config_dir
* rust-launcher/src/property_from_file.rs: renamed from jvm_from_properties_file and generalized
* rust-launcher/src/property_from_files_resolver.rs: renamed from jvm_from_files_resolver and generalized
* rust-launcher/src/utils.rs: adapted to renamed JRE_PROPERTY_NAME from PROPERTY_NAME
changeset 9bac379fb97e in /hg/icedtea-web
details: http://icedtea.classpath.org/hg/icedtea-web?cmd=changeset;node=9bac379fb97e
author: Jiri Vanek <jvanek at redhat.com>
date: Fri Nov 30 19:12:09 2018 +0100
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
diffstat:
ChangeLog | 18 +
rust-launcher/src/dirs_paths_helper.rs | 95 ++++++
rust-launcher/src/jvm_from_properties.rs | 305 ----------------------
rust-launcher/src/jvm_from_properties_resolver.rs | 221 ---------------
rust-launcher/src/main.rs | 17 +-
rust-launcher/src/os_access.rs | 39 ++
rust-launcher/src/property_from_file.rs | 254 ++++++++++++++++++
rust-launcher/src/property_from_files_resolver.rs | 246 +++++++++++++++++
rust-launcher/src/utils.rs | 4 +-
9 files changed, 662 insertions(+), 537 deletions(-)
diffs (truncated from 1295 to 500 lines):
diff -r 612ff5eded4f -r 9bac379fb97e ChangeLog
--- a/ChangeLog Wed Nov 28 12:35:38 2018 +0100
+++ b/ChangeLog Fri Nov 30 19:12:09 2018 +0100
@@ -1,3 +1,21 @@
+2018-11-30 Jiri Vanek <jvanek at 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 at redhat.com>
+
+ Rust properties parser generalized to be reusable
+ * rust-launcher/src/dirs_paths_helper.rs: new file, including get_xdg_config_dir, deployment.properties and similar
+ originally from jvm_from_properties.rs
+ * rust-launcher/src/main.rs: adapted to re-factored state
+ * rust-launcher/src/os_access.rs: added and for Linux implemented get_system_config_javadir, get_user_config_dir
+ * rust-launcher/src/property_from_file.rs: renamed from jvm_from_properties_file and generalized
+ * rust-launcher/src/property_from_files_resolver.rs: renamed from jvm_from_files_resolver and generalized
+ * rust-launcher/src/utils.rs: adapted to renamed JRE_PROPERTY_NAME from PROPERTY_NAME
+
2018-11-28 Jiri Vanek <jvanek at redhat.com>
deployment.config now support generic url instead just file
diff -r 612ff5eded4f -r 9bac379fb97e rust-launcher/src/dirs_paths_helper.rs
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/rust-launcher/src/dirs_paths_helper.rs Fri Nov 30 19:12:09 2018 +0100
@@ -0,0 +1,95 @@
+use os_access;
+
+use std;
+use std::env;
+
+pub static ICEDTEA_WEB: &'static str = "icedtea-web";
+pub static DEPLOYMENT_PROPERTIES: &'static str = "deployment.properties";
+
+pub fn get_home() -> Option<std::path::PathBuf> {
+ match env::home_dir() {
+ Some(p) => Some(p),
+ None => None
+ }
+}
+
+pub fn get_xdg_config_dir() -> Option<std::path::PathBuf> {
+ match env::var("XDG_CONFIG_HOME") {
+ Ok(war) => {
+ Some(std::path::PathBuf::from(war))
+ }
+ Err(_) => {
+ match get_home() {
+ Some(mut p) => {
+ p.push(".config");
+ Some(p)
+ }
+ None => None
+ }
+ }
+ }
+}
+
+pub fn append_deployment_file(dir: Option<std::path::PathBuf>) -> Option<std::path::PathBuf> {
+ match dir {
+ Some(mut p) => {
+ p.push(DEPLOYMENT_PROPERTIES);
+ Some(p)
+ }
+ None => None
+ }
+}
+
+
+pub fn get_itw_config_file(os: &os_access::Os) -> Option<std::path::PathBuf> {
+ append_deployment_file(os.get_user_config_dir())
+}
+
+pub fn get_itw_legacy_config_file(os: &os_access::Os) -> Option<std::path::PathBuf> {
+ append_deployment_file(os.get_legacy_user_config_dir())
+}
+
+
+pub fn get_itw_legacy_global_config_file(os: &os_access::Os) -> Option<std::path::PathBuf> {
+ append_deployment_file(os.get_legacy_system_config_javadir())
+}
+
+pub fn get_itw_global_config_file(os: &os_access::Os) -> Option<std::path::PathBuf> {
+ append_deployment_file(os.get_system_config_javadir())
+}
+
+
+/*tests*/
+#[cfg(test)]
+mod tests {
+ use os_access;
+
+ #[test]
+ fn check_config_files_paths() {
+ let os = os_access::Linux::new(false);
+ let p3 = super::get_itw_config_file(&os);
+ let p4 = super::get_itw_legacy_config_file(&os);
+ let p5 = super::get_itw_legacy_global_config_file(&os);
+ let p6 = super::get_itw_global_config_file(&os);
+ assert_ne!(None, p3);
+ assert_ne!(None, p4);
+ assert_ne!(None, p5);
+ assert_ne!(None, p6);
+ println!("{}", p3.clone().expect("unwrap failed").display());
+ println!("{}", p4.clone().expect("unwrap failed").display());
+ println!("{}", p5.clone().expect("unwrap failed").display());
+ println!("{}", p6.clone().expect("unwrap failed").display());
+ assert_eq!(true, p3.clone().expect("unwrap failed").display().to_string().contains("icedtea-web"));
+ assert_eq!(true, p3.clone().expect("unwrap failed").display().to_string().ends_with("deployment.properties"));
+ assert_eq!(true, p4.clone().expect("unwrap failed").display().to_string().contains(".icedtea"));
+ assert_eq!(true, p4.clone().expect("unwrap failed").display().to_string().ends_with("deployment.properties"));
+ assert_eq!(true, p5.clone().expect("unwrap failed").display().to_string().contains("etc"));
+ assert_eq!(true, p5.clone().expect("unwrap failed").display().to_string().contains(".java"));
+ assert_eq!(true, p5.clone().expect("unwrap failed").display().to_string().contains(".deploy"));
+ assert_eq!(true, p5.clone().expect("unwrap failed").display().to_string().ends_with("deployment.properties"));
+ assert_eq!(true, p5.clone().expect("unwrap failed").display().to_string().contains("etc"));
+ assert_eq!(true, p5.clone().expect("unwrap failed").display().to_string().contains(".java"));
+ assert_eq!(true, p5.clone().expect("unwrap failed").display().to_string().contains("deployment"));
+ assert_eq!(true, p6.clone().expect("unwrap failed").display().to_string().ends_with("deployment.properties"));
+ }
+}
diff -r 612ff5eded4f -r 9bac379fb97e rust-launcher/src/jvm_from_properties.rs
--- a/rust-launcher/src/jvm_from_properties.rs Wed Nov 28 12:35:38 2018 +0100
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,305 +0,0 @@
-use property;
-
-use std;
-use std::env;
-use std::string::String;
-use std::fs::File;
-
-static ICEDTEA_WEB: &'static str = "icedtea-web";
-pub static DEPLOYMENT_PROPERTIES: &'static str = "deployment.properties";
-pub static PROPERTY_NAME: &'static str = "deployment.jre.dir";
-
-fn is_file(path: &std::path::PathBuf) -> bool {
- let mdr = path.metadata();
- match mdr {
- Ok(md) => md.is_file(),
- Err(_e) => false
- }
-}
-
-fn get_home() -> Option<std::path::PathBuf> {
- match env::home_dir() {
- Some(p) => Some(p),
- None => None
- }
-}
-
-fn get_config_dir() -> Option<std::path::PathBuf> {
- match env::var("XDG_CONFIG_HOME") {
- Ok(war) => {
- Some(std::path::PathBuf::from(war))
- }
- Err(_e) => {
- match get_home() {
- Some(mut p) => {
- p.push(".config");
- Some(p)
- }
- None => None
- }
- }
- }
-}
-
-pub fn get_itw_config_dir() -> Option<std::path::PathBuf> {
- match get_config_dir() {
- Some(mut p) => {
- p.push(ICEDTEA_WEB);
- Some(p)
- }
- None => None
- }
-}
-
-
-pub fn get_itw_legacy_config_dir() -> Option<std::path::PathBuf> {
- match get_home() {
- Some(mut p) => {
- p.push(".icedtea");
- Some(p)
- }
- None => None
- }
-}
-
-
-pub fn get_itw_config_file() -> Option<std::path::PathBuf> {
- match get_itw_config_dir() {
- Some(mut p) => {
- p.push(DEPLOYMENT_PROPERTIES);
- Some(p)
- }
- None => None
- }
-}
-
-pub fn get_itw_legacy_config_file() -> Option<std::path::PathBuf> {
- match get_itw_legacy_config_dir() {
- Some(mut p) => {
- p.push(DEPLOYMENT_PROPERTIES);
- Some(p)
- }
- None => None
- }
-}
-
-
-pub fn get_itw_legacy_global_config_file() -> Option<std::path::PathBuf> {
- let mut path = std::path::PathBuf::from("/etc/.java/.deploy");
- path.push(DEPLOYMENT_PROPERTIES);
- Some(path)
-}
-
-pub fn get_itw_global_config_file() -> Option<std::path::PathBuf> {
- let mut path = std::path::PathBuf::from("/etc/.java/deployment");
- path.push(DEPLOYMENT_PROPERTIES);
- Some(path)
-}
-
-
-pub fn check_file_for_property_jredir(file: File) -> Option<String> {
- check_file_for_property(file, PROPERTY_NAME)
-}
-
-fn check_file_for_property(file: File, key: &str) -> Option<String> {
- let p = property::Property::load(file, key);
- match p {
- None => { None }
- Some(property) => {
- Some(property.value)
- }
- }
-}
-
-
-pub fn get_jre_from_file(file: Option<std::path::PathBuf>) -> Option<String> {
- match file {
- None => None,
- Some(path) => {
- get_jre_from_file_direct(path)
- }
- }
-}
-
-fn get_jre_from_file_direct(path: std::path::PathBuf) -> Option<String> {
- if !path.exists() {
- None
- } else if !is_file(&path) {
- return None;
- } else {
- let fileresult = File::open(path);
- match fileresult {
- Err(_fe) => None,
- Ok(file) => {
- let result = check_file_for_property_jredir(file);
- result
- }
- }
- }
-}
-
-pub fn verify_jdk_string(file: &String) -> bool {
- verify_jdk_path(&std::path::PathBuf::from(file))
-}
-
-fn verify_jdk_path(ffile: &std::path::PathBuf) -> bool {
- let mut file = ffile.clone();
- file.push("bin");
- file.push("java");
- if !file.exists() {
- false
- } else if !is_file(&file) {
- false
- } else {
- true
- }
-}
-
-/*tests*/
-#[cfg(test)]
-mod tests {
- use std;
- use std::fs::File;
- use utils::tests_utils as tu;
-
-
- #[test]
- fn is_not_file_() {
- let r = super::is_file(&std::path::PathBuf::from("/definitely/not/existing/file"));
- assert_eq!(false, r);
- }
-
- #[test]
- fn is_file_() {
- let dir = tu::create_tmp_file();
- let r = super::is_file(&dir);
- tu::debuggable_remove_file(&dir);
- assert_eq!(true, r);
- }
-
- #[test]
- fn check_file_for_property_jredir_not_found() {
- let path = tu::create_tmp_file();
- let f = File::open(&path);
- let prop = super::check_file_for_property_jredir(f.expect("file was not opened"));
- tu::debuggable_remove_file(&path);
- assert_eq!(None, prop);
- }
-
- #[test]
- fn check_file_for_property_jredir() {
- let path = tu::create_tmp_propfile_with_content();
- let f = File::open(&path);
- let prop = super::check_file_for_property_jredir(f.expect("file was not opened"));
- tu::debuggable_remove_file(&path);
- assert_eq!("/some/jre", prop.expect("property was supposed to be loaded"));
- }
-
-
- #[test]
- fn check_file_for_property_not_found() {
- let path = tu::create_tmp_propfile_with_content();
- let f = File::open(&path);
- let k = "not_existing_key";
- let prop = super::check_file_for_property(f.expect("file was not opened"), k);
- tu::debuggable_remove_file(&path);
- assert_eq!(None, prop);
- }
-
- #[test]
- fn check_file_for_property_item_exists() {
- let path = tu::create_tmp_propfile_with_content();
- let f = File::open(&path);
- let k = "key2";
- let prop = super::check_file_for_property(f.expect("file was not opened"), k);
- tu::debuggable_remove_file(&path);
- assert_eq!("val2", prop.expect("property was supposed to be loaded"));
- }
-
- #[test]
- fn get_jre_from_file_exists() {
- let path = tu::create_tmp_propfile_with_content();
- let prop = super::get_jre_from_file(Some(path.clone()));
- tu::debuggable_remove_file(&path);
- assert_eq!("/some/jre", prop.expect("property was supposed to be loaded"));
- }
-
- #[test]
- fn get_jre_from_file_not_found() {
- let path = tu::create_tmp_file();
- let prop = super::get_jre_from_file(Some(path.clone()));
- tu::debuggable_remove_file(&path);
- assert_eq!(None, prop);
- }
-
-
- #[test]
- fn get_jre_from_file_notexists() {
- let path = tu::create_tmp_file();
- tu::debuggable_remove_file(&path);
- let prop = super::get_jre_from_file(Some(path));
- assert_eq!(None, prop);
- }
-
- #[test]
- fn get_jre_from_file_none() {
- let prop = super::get_jre_from_file(None);
- assert_eq!(None, prop);
- }
-
- #[test]
- fn verify_jdk_string_verify_jdk_path_jdk_ok() {
- let master_dir = tu::fake_jre(true);
- let vs = super::verify_jdk_string(&master_dir.display().to_string());
- let vp = super::verify_jdk_path(&master_dir);
- tu::debuggable_remove_dir(&master_dir);
- assert_eq!(true, vs);
- assert_eq!(true, vp);
- }
-
- #[test]
- fn verify_jdk_string_verify_jdk_path_jdk_bad() {
- let master_dir = tu::fake_jre(false);
- let vs = super::verify_jdk_string(&master_dir.display().to_string());
- let vp = super::verify_jdk_path(&master_dir);
- tu::debuggable_remove_dir(&master_dir);
- assert_eq!(false, vs);
- assert_eq!(false, vp);
- }
-
- #[test]
- fn check_config_files_paths() {
- let p1 = super::get_itw_config_dir();
- let p2 = super::get_itw_legacy_config_dir();
- let p3 = super::get_itw_config_file();
- let p4 = super::get_itw_legacy_config_file();
- let p5 = super::get_itw_legacy_global_config_file();
- let p6 = super::get_itw_global_config_file();
- assert_ne!(None, p1);
- assert_ne!(None, p2);
- assert_ne!(None, p3);
- assert_ne!(None, p4);
- assert_ne!(None, p5);
- assert_ne!(None, p6);
- println!("{}", p1.clone().expect("unwrap failed").display());
- println!("{}", p2.clone().expect("unwrap failed").display());
- println!("{}", p3.clone().expect("unwrap failed").display());
- println!("{}", p4.clone().expect("unwrap failed").display());
- println!("{}", p5.clone().expect("unwrap failed").display());
- println!("{}", p6.clone().expect("unwrap failed").display());
- assert_eq!(true, p1.clone().expect("unwrap failed").display().to_string().contains("icedtea-web"));
- assert_eq!(true, p2.clone().expect("unwrap failed").display().to_string().contains(".icedtea"));
- assert_eq!(true, p3.clone().expect("unwrap failed").display().to_string().contains("icedtea-web"));
- assert_eq!(true, p3.clone().expect("unwrap failed").display().to_string().ends_with("deployment.properties"));
- assert_eq!(true, p4.clone().expect("unwrap failed").display().to_string().contains(".icedtea"));
- assert_eq!(true, p4.clone().expect("unwrap failed").display().to_string().ends_with("deployment.properties"));
- assert_eq!(true, p5.clone().expect("unwrap failed").display().to_string().contains("etc"));
- assert_eq!(true, p5.clone().expect("unwrap failed").display().to_string().contains(".java"));
- assert_eq!(true, p5.clone().expect("unwrap failed").display().to_string().contains(".deploy"));
- assert_eq!(true, p5.clone().expect("unwrap failed").display().to_string().ends_with("deployment.properties"));
- assert_eq!(true, p5.clone().expect("unwrap failed").display().to_string().contains("etc"));
- assert_eq!(true, p5.clone().expect("unwrap failed").display().to_string().contains(".java"));
- assert_eq!(true, p5.clone().expect("unwrap failed").display().to_string().contains("deployment"));
- assert_eq!(true, p6.clone().expect("unwrap failed").display().to_string().ends_with("deployment.properties"));
- }
-}
diff -r 612ff5eded4f -r 9bac379fb97e rust-launcher/src/jvm_from_properties_resolver.rs
--- a/rust-launcher/src/jvm_from_properties_resolver.rs Wed Nov 28 12:35:38 2018 +0100
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,221 +0,0 @@
-use hardcoded_paths;
-use jvm_from_properties;
-use os_access;
-
-use std;
-use std::string::String;
-use std::fmt::Write;
-
-pub fn try_jdk_from_properties(logger: &os_access::Os) -> Option<String> {
- let array: [Option<std::path::PathBuf>; 4] = [
- jvm_from_properties::get_itw_config_file(),
- jvm_from_properties::get_itw_legacy_config_file(),
- jvm_from_properties::get_itw_legacy_global_config_file(),
- jvm_from_properties::get_itw_global_config_file()
- ];
- try_jdk_from_properties_files(logger, &array)
-}
-
-fn try_jdk_from_properties_files(logger: &os_access::Os, array: &[Option<std::path::PathBuf>]) -> Option<String> {
- for jdk in array {
- let mut info1 = String::new();
- write!(&mut info1, "{} ", "itw-rust-debug: checking jre in:").expect("unwrap failed");
- write!(&mut info1, "{}", jdk.clone().unwrap_or(std::path::PathBuf::from("None")).display()).expect("unwrap failed");
- logger.log(&info1);
- match jvm_from_properties::get_jre_from_file(jdk.clone()) {
- Some(path) => {
- let mut info2 = String::new();
- write!(&mut info2, "{} ", "itw-rust-debug: located").expect("unwrap failed");
- write!(&mut info2, "{}", path).expect("unwrap failed");
- write!(&mut info2, " in file {}", jdk.clone().expect("file should be already verified").display()).expect("unwrap failed");
- logger.log(&info2);
- if jvm_from_properties::verify_jdk_string(&path) {
- return Some(path);
- } else {
- //the only output out of verbose mode
- let mut res = String::new();
- write!(&mut res, "{}", "Your custom JRE ").expect("unwrap failed");
- write!(&mut res, "{}", path).expect("unwrap failed");
- write!(&mut res, "{}", " read from ").expect("unwrap failed");
- write!(&mut res, "{}", jdk.clone().expect("jre path should be loaded").display()).expect("unwrap failed");
- write!(&mut res, "{}", " under key ").expect("unwrap failed");
- write!(&mut res, "{}", jvm_from_properties::PROPERTY_NAME).expect("unwrap failed");
- write!(&mut res, "{}", " is not valid. Trying other config files, then using default (").expect("unwrap failed");
- write!(&mut res, "{}", hardcoded_paths::get_java()).expect("unwrap failed");
- write!(&mut res, "{}", ", ").expect("unwrap failed");
- write!(&mut res, "{}", hardcoded_paths::get_jre()).expect("unwrap failed");
- write!(&mut res, "{}", ", registry or JAVA_HOME) in attempt to start. Please fix this.").expect("unwrap failed");
- logger.info(&res);
- }
- }
- None => {
- logger.log("itw-rust-debug: property not located or file inaccessible");
- }
- }
- }
- None
-}
-
-/*tests*/
-/*To print the diagnostic output use `cargo test -- --nocapture
-`*/
-#[cfg(test)]
-mod tests {
More information about the distro-pkg-dev
mailing list