Skip to content

Commit

Permalink
Resolve conflicts of rukai-prefer_std_over_fs_extra before merging to…
Browse files Browse the repository at this point in the history
… master
  • Loading branch information
astonbitecode committed May 28, 2024
2 parents b9811a9 + f35df98 commit a434c26
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 34 deletions.
31 changes: 16 additions & 15 deletions rust/src/api/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,12 @@ use std::convert::TryFrom;
use std::env;
use std::ops::Drop;
use std::os::raw::c_void;
use std::path::{Path, PathBuf, MAIN_SEPARATOR};
use std::path::{Path, PathBuf};
use std::ptr;
use std::sync::mpsc::channel;
use std::{fs, thread, time};
use std::borrow::Borrow;

use fs_extra::dir::get_dir_content;
use jni_sys::{
self, jint, jobject, jsize, jstring, JNIEnv, JavaVM, JavaVMInitArgs, JavaVMOption,
JNI_EDETACHED, JNI_EEXIST, JNI_EINVAL, JNI_ENOMEM, JNI_ERR, JNI_EVERSION, JNI_OK, JNI_TRUE,
Expand Down Expand Up @@ -1846,23 +1845,25 @@ impl<'a> JvmBuilder<'a> {
} else {
// The default classpath contains all the jars in the jassets directory
let jassets_path = self.get_jassets_path()?;
let all_jars = get_dir_content(&jassets_path)?.files;
// This is the j4rs jar that should be included in the classpath
let j4rs_jar_to_use = format!("j4rs-{}-jar-with-dependencies.jar", j4rs_version());
let j4rs_testing_jar_to_use = format!("j4rs-testing-{}.jar", j4rs_version());
let j4rs_javafx_jar_to_use = format!("j4rs-javafx-{}.jar", j4rs_version());
// Filter out possible incorrect jars of j4rs
let filtered_jars: Vec<String> = all_jars
.into_iter()
.filter(|jar_full_path| {
let jarname = jar_full_path
.split(MAIN_SEPARATOR)
.last()
.unwrap_or(jar_full_path);
!jarname.contains("j4rs-") || jarname.ends_with(&j4rs_jar_to_use) || jarname.ends_with(&j4rs_testing_jar_to_use) || jarname.ends_with(&j4rs_javafx_jar_to_use)
})
.collect();
let cp_string = filtered_jars.join(utils::classpath_sep());
let mut cp_string = String::new();
for entry in std::fs::read_dir(jassets_path)? {
let path = entry?.path();
if let Some(file_name) = opt_to_res(path.file_name())?.to_str() {
if !file_name.contains("j4rs-") || file_name.ends_with(&j4rs_jar_to_use) || file_name.ends_with(&j4rs_testing_jar_to_use) || file_name.ends_with(&j4rs_javafx_jar_to_use) {
if !cp_string.is_empty() {
cp_string.push_str(utils::classpath_sep());
}
if let Some(path) = path.to_str() {
cp_string.push_str(path);
}
}
}
}

let default_class_path = format!("-Djava.class.path={}", cp_string);

Expand Down Expand Up @@ -2108,7 +2109,7 @@ mod api_unit_tests {
let newdir = "./newdir";
Jvm::copy_j4rs_libs_under(newdir)?;

let _ = fs_extra::remove_items(&vec![newdir]);
let _ = std::fs::remove_dir_all(newdir);

Ok(())
}
Expand Down
6 changes: 2 additions & 4 deletions rust/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -167,8 +167,6 @@ mod lib_unit_tests {
use std::thread::JoinHandle;
use std::{thread, time};

use fs_extra::remove_items;

use crate::api::{self, JavaClass};
use crate::provisioning::JavaArtifact;
use crate::{LocalJarArtifact, MavenArtifactRepo, MavenSettings, Null};
Expand Down Expand Up @@ -715,7 +713,7 @@ mod lib_unit_tests {
jassets_path().unwrap().to_str().unwrap(),
MAIN_SEPARATOR
);
let _ = remove_items(&vec![to_remove]);
let _ = std::fs::remove_dir_all(to_remove);

assert!(jvm.deploy_artifact(&UnknownArtifact {}).is_err());

Expand All @@ -738,7 +736,7 @@ mod lib_unit_tests {
jassets_path().unwrap().to_str().unwrap(),
MAIN_SEPARATOR
);
let _ = remove_items(&vec![to_remove]);
let _ = std::fs::remove_dir_all(to_remove);

Ok(())
}
Expand Down
26 changes: 11 additions & 15 deletions rust/src/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ use std::{self, env, fs, str};

use cesu8::{from_java_cesu8, to_java_cesu8};
use dunce::canonicalize;
use fs_extra::dir::get_dir_content;
use libc::{self, c_char};

use crate::api::{
Expand Down Expand Up @@ -86,26 +85,23 @@ pub(crate) fn jassets_path() -> errors::Result<PathBuf> {
pub(crate) fn default_jassets_path() -> errors::Result<PathBuf> {
let is_build_script = env::var("OUT_DIR").is_ok();

let mut jassets_path = if is_build_script {
let mut start_path = if is_build_script {
PathBuf::from(env::var("OUT_DIR")?)
} else {
env::current_exe()?
};
jassets_path = canonicalize(jassets_path)?;

let mut tmp_vec = Vec::new();

while tmp_vec.is_empty() {
jassets_path.pop();
tmp_vec = get_dir_content(&jassets_path)?
.directories
.into_iter()
.filter(|path| path.ends_with("jassets"))
.collect();
start_path = canonicalize(start_path)?;

while start_path.pop() {
for entry in std::fs::read_dir(&start_path)? {
let path = entry?.path();
if path.file_name().map(|x| x == "jassets").unwrap_or(false) {
return Ok(path);
}
}
}

jassets_path.push("jassets");
Ok(jassets_path)
Err(errors::J4RsError::GeneralError("Can not find jassets directory".to_owned()))
}

pub(crate) fn find_j4rs_dynamic_libraries_names() -> errors::Result<Vec<String>> {
Expand Down

0 comments on commit a434c26

Please sign in to comment.