From 54e6350d42a2249d33eee75d9316021b923dd839 Mon Sep 17 00:00:00 2001 From: Olivia Brooks <109807080+Cutieguwu@users.noreply.github.com> Date: Tue, 27 Jan 2026 22:01:41 -0500 Subject: [PATCH] Code cleanup. --- src/java.rs | 35 ++++++++++++++++++----------------- src/main.rs | 4 ++-- 2 files changed, 20 insertions(+), 19 deletions(-) diff --git a/src/java.rs b/src/java.rs index 7a89ccf..8b4285e 100644 --- a/src/java.rs +++ b/src/java.rs @@ -17,11 +17,15 @@ pub struct JVMBuilder { monitor: bool, ram_min: Option, ram_max: Option, + class_path: PathBuf, } impl JVMBuilder { - pub fn new() -> Self { - Self::default() + pub fn new>(class_path: P) -> Self { + Self { + class_path: class_path.as_ref().to_path_buf(), + ..Default::default() + } } pub fn assertions(&mut self, assertions: bool) -> &mut Self { @@ -46,7 +50,9 @@ impl JVMBuilder { } pub fn build(&self) -> JVM { - let mut flags = vec![]; + let mut flags = vec![VMFlag::Classpath { + path: self.class_path.to_owned(), + }]; if self.assertions { flags.push(VMFlag::EnableAssert); @@ -86,17 +92,7 @@ impl JVM { .flat_map(|f| Into::>::into(f)), ); - for part in &cmd { - println!("{}", part); - } - cmd.push("-cp".to_string()); - cmd.push(entry_point.as_ref().display().to_string()); - - // Jave needs a class path and a file name to run. - cmd.push("Test".to_string()); - - println!("{:?}", cmd.as_slice()); - + cmd.push(entry_point.as_ref().to_path_buf().display().to_string()); let result = crate::io::run_process(cmd.as_slice()); @@ -121,6 +117,7 @@ impl JVM { #[derive(Debug, Clone)] pub enum VMFlag { + Classpath { path: PathBuf }, EnableAssert, HeapMax { size: ByteSize }, HeapMin { size: ByteSize }, @@ -129,7 +126,10 @@ pub enum VMFlag { impl Into> for VMFlag { fn into(self) -> Vec { - vec![self.to_string()] + self.to_string() + .split_ascii_whitespace() + .map(|s| s.to_string()) + .collect() } } @@ -141,6 +141,7 @@ impl fmt::Display for VMFlag { f, "-{}", match self { + Self::Classpath { path } => format!("classpath {}", path.display()), Self::EnableAssert => String::from("ea"), Self::HeapMax { size } => format!("Xmx{}", size.as_u64()), Self::HeapMin { size } => format!("Xms{}", size.as_u64()), @@ -219,14 +220,14 @@ impl Compiler { #[derive(Debug, Clone)] pub enum CompilerFlag { - Destination { path: PathBuf }, Classpath { path: PathBuf }, + Destination { path: PathBuf }, } impl Into> for CompilerFlag { fn into(self) -> Vec { match self { - Self::Classpath { path } => vec!["-cp".to_string(), path.display().to_string()], + Self::Classpath { path } => vec!["-classpath".to_string(), path.display().to_string()], Self::Destination { path } => vec!["-d".to_string(), path.display().to_string()], } } diff --git a/src/main.rs b/src/main.rs index 4ed07bb..ed58804 100644 --- a/src/main.rs +++ b/src/main.rs @@ -240,7 +240,7 @@ fn run>( // JRE pathing will be messed up without this. crate::env::set_cwd(DIR_TARGET.as_path())?; - java::JVMBuilder::new() + java::JVMBuilder::new(DIR_TARGET.as_path()) .assertions(assertions) .monitor(true) .build() @@ -257,7 +257,7 @@ fn test(assertions: bool) -> anyhow::Result<(Option, Option)> { // Change cwd to avoid Java pathing issues. crate::env::set_cwd(DIR_TARGET.as_path())?; - java::JVMBuilder::new() + java::JVMBuilder::new(DIR_TARGET.as_path()) .assertions(assertions) .ram_min(ByteSize::mib(128)) .ram_max(ByteSize::mib(512))