Code cleanup.
This commit is contained in:
35
src/java.rs
35
src/java.rs
@@ -17,11 +17,15 @@ pub struct JVMBuilder {
|
||||
monitor: bool,
|
||||
ram_min: Option<ByteSize>,
|
||||
ram_max: Option<ByteSize>,
|
||||
class_path: PathBuf,
|
||||
}
|
||||
|
||||
impl JVMBuilder {
|
||||
pub fn new() -> Self {
|
||||
Self::default()
|
||||
pub fn new<P: AsRef<Path>>(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::<Vec<String>>::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<Vec<String>> for VMFlag {
|
||||
fn into(self) -> Vec<String> {
|
||||
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<Vec<String>> for CompilerFlag {
|
||||
fn into(self) -> Vec<String> {
|
||||
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()],
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user