From 79629391c512ac9b53f9b7a3ad0b6db23eeef0fb Mon Sep 17 00:00:00 2001 From: Cutieguwu Date: Sun, 15 Feb 2026 17:39:48 -0500 Subject: [PATCH] I think I finished it... --- Cargo.lock | 28 ------ Cargo.toml | 2 - crates/cli/Cargo.toml | 1 - crates/cli/src/lib.rs | 4 +- crates/core/Cargo.toml | 1 - crates/core/src/dependency.rs | 2 +- crates/core/src/error.rs | 2 +- crates/core/src/lib.rs | 2 - crates/core/src/nest.rs | 7 +- crates/core/src/package.rs | 42 ++++----- crates/core/src/prey.rs | 17 +++- crates/core/src/workspace.rs | 148 +++++++++++++++++++++--------- crates/fs/Cargo.toml | 1 - crates/io/Cargo.toml | 1 - crates/io/src/error.rs | 2 +- crates/java/Cargo.toml | 1 - crates/java/src/error.rs | 2 +- crates/path/Cargo.toml | 14 --- crates/path/src/lib.rs | 151 ------------------------------- crates/pom/Cargo.toml | 1 - crates/pom/src/error.rs | 2 +- crates/raven/Cargo.toml | 2 - crates/raven/src/env.rs | 19 ---- crates/raven/src/main.rs | 100 +++++--------------- crates/raven/src/manager.rs | 11 --- demo/.java-version | 1 + demo/Nest.toml | 8 ++ demo/src/main/Prey.toml | 6 ++ demo/src/main/java/Main.java | 10 ++ demo/src/test/Prey.toml | 6 ++ demo/src/test/java/MainTest.java | 10 ++ demo/target/Main.class | Bin 0 -> 471 bytes demo/target/MainTest.class | Bin 0 -> 631 bytes 33 files changed, 215 insertions(+), 389 deletions(-) delete mode 100644 crates/path/Cargo.toml delete mode 100644 crates/path/src/lib.rs delete mode 100644 crates/raven/src/env.rs delete mode 100644 crates/raven/src/manager.rs create mode 100644 demo/.java-version create mode 100644 demo/Nest.toml create mode 100644 demo/src/main/Prey.toml create mode 100644 demo/src/main/java/Main.java create mode 100644 demo/src/test/Prey.toml create mode 100644 demo/src/test/java/MainTest.java create mode 100644 demo/target/Main.class create mode 100644 demo/target/MainTest.class diff --git a/Cargo.lock b/Cargo.lock index 1ee2f6f..a9cbd7d 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -155,26 +155,6 @@ version = "1.0.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b05b61dc5112cbb17e4b6cd61790d9845d13888356391624cbe7e41efeac1e75" -[[package]] -name = "const_format" -version = "0.2.35" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7faa7469a93a566e9ccc1c73fe783b4a65c274c5ace346038dca9c39fe0030ad" -dependencies = [ - "const_format_proc_macros", -] - -[[package]] -name = "const_format_proc_macros" -version = "0.2.34" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1d57c2eccfb16dbac1f4e61e206105db5820c9d26c3c472bc17c774259ef7744" -dependencies = [ - "proc-macro2", - "quote", - "unicode-xid", -] - [[package]] name = "convert_case" version = "0.10.0" @@ -383,13 +363,6 @@ version = "1.70.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "384b8ab6d37215f3c5301a95a4accb5d64aa607f1fcb26a11b5303878451b4fe" -[[package]] -name = "path" -version = "0.1.0" -dependencies = [ - "const_format", -] - [[package]] name = "pathsub" version = "0.1.1" @@ -442,7 +415,6 @@ dependencies = [ "fs", "io", "java", - "path", "toml", ] diff --git a/Cargo.toml b/Cargo.toml index 265e5d2..ecaa01c 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -10,7 +10,6 @@ license = "MIT" repository = "https://gitea.cutieguwu.ca/Cutieguwu/raven" publish = false -test = true [workspace.dependencies] # @@ -21,7 +20,6 @@ fs = { path = "crates/fs" } io = { path = "crates/io" } java = { path = "crates/java" } core = { path = "crates/core" } -path = { path = "crates/path" } pom = { path = "crates/pom" } raven = { path = "crates/raven" } diff --git a/crates/cli/Cargo.toml b/crates/cli/Cargo.toml index 1960a8c..dfb1e04 100644 --- a/crates/cli/Cargo.toml +++ b/crates/cli/Cargo.toml @@ -8,7 +8,6 @@ description = "Raven's CLI" repository.workspace = true publish.workspace = true -test.workspace = true [dependencies.clap] version = "4.5" diff --git a/crates/cli/src/lib.rs b/crates/cli/src/lib.rs index b45c8ed..c014835 100644 --- a/crates/cli/src/lib.rs +++ b/crates/cli/src/lib.rs @@ -19,7 +19,7 @@ pub enum Command { New { #[clap(flatten)] type_: ProjectFlag, - name: String, + project_name: String, }, /// Create a new raven project in an existing directory Init, @@ -49,7 +49,7 @@ pub struct Assertions { assertions: bool, } -impl Into for Assertions { +impl Into for &Assertions { fn into(self) -> bool { self.assertions } diff --git a/crates/core/Cargo.toml b/crates/core/Cargo.toml index 4a062ea..ec1d14d 100644 --- a/crates/core/Cargo.toml +++ b/crates/core/Cargo.toml @@ -8,7 +8,6 @@ description = "Raven's core, including metadata tooling and resources" repository.workspace = true publish.workspace = true -test.workspace = true [dependencies] derive_more.workspace = true diff --git a/crates/core/src/dependency.rs b/crates/core/src/dependency.rs index a18223b..36342a9 100644 --- a/crates/core/src/dependency.rs +++ b/crates/core/src/dependency.rs @@ -45,6 +45,6 @@ impl From for Dependency { } /// TODO: This is just a placeholder at present. -fn is_url(path: S) -> bool { +fn is_url(_path: S) -> bool { return false; } diff --git a/crates/core/src/error.rs b/crates/core/src/error.rs index ec13601..cf7da5d 100644 --- a/crates/core/src/error.rs +++ b/crates/core/src/error.rs @@ -1,6 +1,6 @@ use derive_more::{Display, From}; -pub type Result = core::result::Result; +pub type Result = std::result::Result; #[derive(Debug, From, Display)] pub enum Error { diff --git a/crates/core/src/lib.rs b/crates/core/src/lib.rs index b11cf46..88f608f 100644 --- a/crates/core/src/lib.rs +++ b/crates/core/src/lib.rs @@ -1,5 +1,3 @@ -#![allow(dead_code)] - pub mod class; pub mod dependency; pub mod error; diff --git a/crates/core/src/nest.rs b/crates/core/src/nest.rs index 4b458df..07c5cf2 100644 --- a/crates/core/src/nest.rs +++ b/crates/core/src/nest.rs @@ -5,8 +5,8 @@ use std::path::{Path, PathBuf}; use serde::{Deserialize, Serialize}; +use crate::dependency::Dependency; use crate::meta::Meta; -use crate::prelude::Dependency; use crate::workspace::Workspace; pub const F_NEST_TOML: &str = "Nest.toml"; @@ -30,6 +30,11 @@ impl Nest { } pub fn write>(&self, path: P) -> crate::Result<()> { + let mut path = path.as_ref().to_path_buf(); + if path.is_dir() { + path = path.join(F_NEST_TOML); + } + Ok(OpenOptions::new() .write(true) .create(true) diff --git a/crates/core/src/package.rs b/crates/core/src/package.rs index 6debff9..0bc47b1 100644 --- a/crates/core/src/package.rs +++ b/crates/core/src/package.rs @@ -19,8 +19,8 @@ pub struct PackageHandler { impl PackageHandler { const DIR_JAVA: &str = "java/"; - pub fn new>(package_root: P, target_dir: P) -> crate::Result { - let package_root = package_root.as_ref().to_path_buf(); + pub fn new>(src_dir: P, package_root: P, target_dir: P) -> crate::Result { + let package_root = src_dir.as_ref().join(package_root.as_ref()); Ok(Self { prey: Prey::try_from(package_root.join(F_PREY_TOML))?, @@ -42,32 +42,32 @@ impl PackageHandler { self.prey.version() } - pub fn get_update_targets(&mut self) -> crate::Result> { - let mut targets = vec![]; - + pub fn get_update_targets(&mut self) -> crate::Result> { if self.prey_lock.is_none() { // Try to pass a reference to the class so that there's mutability of the object // available at the workspace level instead of parsing all the way down the // tree. How I do this, idk. My brain is friend from a few days of JS. - self.prey_lock = Some(PreyLock::from(expand_files(Self::DIR_JAVA)?)); - return Ok(self - .prey_lock - .clone() - .unwrap() - .classes - .iter() - .map(|mut *class| &mut class) - .collect()); + self.prey_lock = Some(PreyLock::from(expand_files( + self.package_root.join(Self::DIR_JAVA), + )?)); + return Ok(self.prey_lock.as_ref().unwrap().classes.iter().collect()); } - for mut tracked in self.prey_lock.unwrap().classes { - if !tracked.is_updated()? { - targets.push(&mut tracked); - } - } - - Ok(targets) + Ok(self + .prey_lock + .as_ref() + .unwrap() + .classes + .iter() + .filter_map(|tracked| { + if tracked.is_updated().is_ok_and(|v| v == true) { + Some(tracked) + } else { + None + } + }) + .collect()) } } diff --git a/crates/core/src/prey.rs b/crates/core/src/prey.rs index afc83be..08e2705 100644 --- a/crates/core/src/prey.rs +++ b/crates/core/src/prey.rs @@ -1,14 +1,12 @@ -use std::collections::HashSet; use std::fs::{File, OpenOptions}; use std::io::Read; -use std::path::{Path, PathBuf}; +use std::path::PathBuf; use serde::{Deserialize, Serialize}; use crate::class::Class; use crate::meta::Meta; use crate::package::Package; -use crate::prelude::Dependency; pub const F_PREY_TOML: &str = "Prey.toml"; pub const F_PREY_LOCK: &str = "Prey.lock"; @@ -21,6 +19,15 @@ pub struct Prey { } impl Prey { + pub fn new(name: S) -> Self { + Self { + package: Package { + entry_point: PathBuf::from(""), + }, + meta: Meta::new(name), + } + } + pub fn entry_point(&self) -> PathBuf { self.package.entry_point.clone() } @@ -56,12 +63,12 @@ impl TryFrom for Prey { /// Data struct #[derive(Debug, Clone, Default, Deserialize, Serialize, PartialEq, Eq)] pub struct PreyLock { - pub classes: HashSet, + pub classes: Vec, } impl PreyLock { pub fn with_class(&mut self, class: Class) -> &mut Self { - self.classes.insert(class); + self.classes.push(class); self } } diff --git a/crates/core/src/workspace.rs b/crates/core/src/workspace.rs index 6d34dd3..477a989 100644 --- a/crates/core/src/workspace.rs +++ b/crates/core/src/workspace.rs @@ -11,8 +11,9 @@ use serde::{Deserialize, Serialize}; use crate::Error; use crate::nest::{F_NEST_LOCK, F_NEST_TOML, Nest, NestLock}; use crate::package::PackageHandler; -use crate::prey::F_PREY_TOML; +use crate::prey::{F_PREY_TOML, Prey}; +#[derive(Debug)] pub struct WorkspaceHandler { nest: Nest, nest_lock: Option, @@ -56,7 +57,7 @@ impl WorkspaceHandler { } pub fn write(&self) -> crate::Result<()> { - self.nest.write(self.project_root.join(F_NEST_TOML))?; + self.write_nest()?; if let Option::Some(lock) = self.nest_lock.clone() { lock.write(self.project_root.join(F_NEST_LOCK))?; @@ -65,8 +66,6 @@ impl WorkspaceHandler { Ok(()) } - //pub fn refresh_packages(&mut self) -> crate::Result<()> {} - /* /// Future `build` method. pub fn compile(&self, target: Option) -> crate::Result<()> { @@ -87,13 +86,9 @@ impl WorkspaceHandler { Ok(()) } - - fn make_compiler_job>(target: P) { - // Generate dependency tree. - } */ - pub fn init(&mut self) -> crate::Result<()> { + pub fn init(&mut self) -> crate::Result<&mut Self> { let is_empty = read_dir(self.project_root.as_path()).is_ok_and(|tree| tree.count() == 0); // ORDER MATTERS. THIS MUST COME FIRST. @@ -103,10 +98,7 @@ impl WorkspaceHandler { // Make .java-version self.write_java_version()?; - // Make src/, target/, test/ - self.write_dir_tree()?; - - if !is_empty { + if is_empty { self.write_example_project()?; self.discover_packages()?; @@ -134,30 +126,72 @@ impl WorkspaceHandler { } } - Ok(()) + Ok(self) } // This is the naive build - pub fn build(&mut self) -> crate::Result<()> { + pub fn build(&mut self) -> crate::Result<&mut Self> { let mut targets = vec![]; - for (_name, mut handler) in self.packages.clone() { + for handler in self.packages.values_mut() { targets.append(&mut handler.get_update_targets()?); } let compiler = java::compiler::CompilerBuilder::new() .class_path(Self::DIR_TARGET) - .class_path(Self::DIR_TARGET) + .destination(Self::DIR_TARGET) .build(); - for target in targets { + for target in targets.iter() { // Possibly come up with a source file handler for this? - if let Ok(_) = compiler.clone().compile(target) { + if let Ok(_) = compiler.clone().compile(target.path.as_path()) { // No, this does not run O(1) + //target.update()?; } } - Ok(()) + Ok(self) + } + + pub fn run>( + &mut self, + entry_point: Option

, + assertions: bool, + ) -> crate::Result<&mut Self> { + let mut entry_point = if entry_point.is_none() { + self.nest.default_package() + } else { + entry_point.unwrap().as_ref().to_path_buf() + }; + + if !entry_point.is_file() { + // Use is_file to skip messing with pathing for src/ + // If target is not a file (explicit entry point), check if it's a known package + // and use that's package's default entry point. + entry_point = entry_point.join( + self.packages + .get(&entry_point) + .ok_or(Error::UnknownPackage)? + .entry_point(), + ); + } + + // JRE pathing will be messed up without this. + std::env::set_current_dir(Self::DIR_TARGET)?; + + java::runtime::JVMBuilder::new(Self::DIR_TARGET) + .assertions(assertions) + .monitor(true) + .build() + .run(entry_point)?; + + Ok(self) + } + + pub fn clean(&mut self) -> crate::Result<&mut Self> { + std::fs::remove_file(self.project_root.join(F_NEST_LOCK))?; + std::fs::remove_dir_all(Self::DIR_TARGET)?; + Ok(self) } /// Add any newly created packages. @@ -174,7 +208,7 @@ impl WorkspaceHandler { // Yes, I know this looks like shit. // That's because it is. - for file in read_dir(Self::DIR_SRC)? + for file in read_dir(self.project_root.join(Self::DIR_SRC))? // Get directories .filter_map(|entry| { if entry.as_ref().is_ok_and(|entry| entry.path().is_dir()) { @@ -203,12 +237,22 @@ impl WorkspaceHandler { }) .flatten() { - let package_root = - pathsub::sub_paths(file.as_path(), PathBuf::from(Self::DIR_SRC).as_path()).unwrap(); + let package_root = pathsub::sub_paths( + file.as_path(), + self.project_root.join(Self::DIR_SRC).as_path(), + ) + .unwrap() + .parent() + .unwrap() + .to_path_buf(); self.packages.insert( package_root.to_path_buf(), - PackageHandler::new(package_root, PathBuf::from(Self::DIR_TARGET))?, + PackageHandler::new( + self.project_root.join(Self::DIR_SRC), + package_root, + self.project_root.join(Self::DIR_TARGET), + )?, ); } @@ -216,15 +260,7 @@ impl WorkspaceHandler { } fn write_nest(&self) -> crate::Result<()> { - if let Result::Ok(mut f) = OpenOptions::new() - .write(true) - .create_new(true) - .open(F_NEST_TOML) - { - f.write_all(toml::to_string_pretty(&self.nest)?.as_bytes())?; - } - - Ok(()) + Ok(self.nest.write(self.project_root.clone())?) } fn write_java_version(&self) -> crate::Result<()> { @@ -251,22 +287,46 @@ impl WorkspaceHandler { Ok(()) } - fn write_example_project(&self) -> std::io::Result<()> { + fn write_example_project(&self) -> crate::Result<()> { + let main: PathBuf = PathBuf::from(Self::DIR_SRC).join("main/"); + let test: PathBuf = PathBuf::from(Self::DIR_SRC).join("test/"); + + // Make src/, target/, test/ + self.write_dir_tree()?; + + // Make src/main/Prey.toml + if let Result::Ok(mut f) = OpenOptions::new() + .write(true) + .create_new(true) + .open(main.join(F_PREY_TOML)) + { + f.write_all(toml::to_string_pretty(&Prey::new("main"))?.as_bytes())?; + } + // Make src/main/Main.java - if let Result::Ok(mut f) = OpenOptions::new().write(true).create_new(true).open( - PathBuf::from(Self::DIR_SRC) - .join("main/java/Main") - .with_extension(JAVA_EXT_SOURCE), - ) { + if let Result::Ok(mut f) = OpenOptions::new() + .write(true) + .create_new(true) + .open(main.join("java/Main").with_extension(JAVA_EXT_SOURCE)) + { f.write_all(include_bytes!("../assets/Main.java"))?; } + // Make src/test/Prey.toml + if let Result::Ok(mut f) = OpenOptions::new() + .write(true) + .create_new(true) + .open(test.join(F_PREY_TOML)) + { + f.write_all(toml::to_string_pretty(&Prey::new("test"))?.as_bytes())?; + } + // Make src/test/MainTest.java - if let Result::Ok(mut f) = OpenOptions::new().write(true).create_new(true).open( - PathBuf::from(Self::DIR_SRC) - .join("test/java/MainTest") - .with_extension(JAVA_EXT_SOURCE), - ) { + if let Result::Ok(mut f) = OpenOptions::new() + .write(true) + .create_new(true) + .open(test.join("java/MainTest").with_extension(JAVA_EXT_SOURCE)) + { f.write_all(include_bytes!("../assets/MainTest.java"))?; } diff --git a/crates/fs/Cargo.toml b/crates/fs/Cargo.toml index 2ce3924..c9c8c8e 100644 --- a/crates/fs/Cargo.toml +++ b/crates/fs/Cargo.toml @@ -8,7 +8,6 @@ description = "Raven's FS utilities" repository.workspace = true publish.workspace = true -test.workspace = true [dependencies] derive_more.workspace = true diff --git a/crates/io/Cargo.toml b/crates/io/Cargo.toml index e87e5e8..c41e5a0 100644 --- a/crates/io/Cargo.toml +++ b/crates/io/Cargo.toml @@ -8,7 +8,6 @@ description = "Raven's IO utilities" repository.workspace = true publish.workspace = true -test.workspace = true [dependencies] derive_more.workspace = true diff --git a/crates/io/src/error.rs b/crates/io/src/error.rs index 69a7ec7..c5df1d1 100644 --- a/crates/io/src/error.rs +++ b/crates/io/src/error.rs @@ -1,6 +1,6 @@ use derive_more::{Display, From}; -pub type Result = core::result::Result; +pub type Result = std::result::Result; #[derive(Debug, From, Display)] pub enum Error { diff --git a/crates/java/Cargo.toml b/crates/java/Cargo.toml index 66e88a7..215d26c 100644 --- a/crates/java/Cargo.toml +++ b/crates/java/Cargo.toml @@ -11,7 +11,6 @@ description = "Tools for interfacing with the Java Development Kit" repository.workspace = true publish.workspace = true -test.workspace = true [dependencies] bytesize.workspace = true diff --git a/crates/java/src/error.rs b/crates/java/src/error.rs index 54ed1b4..e7791f4 100644 --- a/crates/java/src/error.rs +++ b/crates/java/src/error.rs @@ -1,6 +1,6 @@ use derive_more::{Display, From}; -pub type Result = core::result::Result; +pub type Result = std::result::Result; #[derive(Debug, From, Display)] pub enum Error { diff --git a/crates/path/Cargo.toml b/crates/path/Cargo.toml deleted file mode 100644 index 5f3bcc8..0000000 --- a/crates/path/Cargo.toml +++ /dev/null @@ -1,14 +0,0 @@ -[package] -name = "path" -version = "0.1.0" -edition.workspace = true -license.workspace = true - -description = "Raven's pathing tools" -repository.workspace = true - -publish.workspace = true -test.workspace = true - -[dependencies] -const_format.workspace = true diff --git a/crates/path/src/lib.rs b/crates/path/src/lib.rs deleted file mode 100644 index b8bbb2e..0000000 --- a/crates/path/src/lib.rs +++ /dev/null @@ -1,151 +0,0 @@ -use std::collections::HashMap; -use std::path::{Path, PathBuf}; -use std::sync::{Arc, Mutex}; - -//TODO: Clean this up. Shouldn't need duplicated DIR_SRC consts about the workspace. - -const DIR_SRC: &str = "src/"; -const DIR_TARGET: &str = "target/"; - -const DIR_MAIN: &str = const_format::concatcp!(DIR_SRC, "main/"); -const DIR_TEST: &str = const_format::concatcp!(DIR_SRC, "test/"); - -#[derive(Debug, Clone)] -pub struct PathHandler { - root_path: PathBuf, - // This is a short-living binary. This doesn't need an LRU like Moka. - derived_path_cache: HashMap, -} - -impl PathHandler { - pub fn new(root_path: PathBuf) -> Self { - Self::from(root_path) - } - - pub fn root_path(&self) -> PathBuf { - self.root_path.clone() - } - - /// This is a readability helper. - /// Make sure to set the root of this `PathHandler` to the project root. - /// This simply calls upon the root_path() of the `PathHandler`. - pub fn project_root(&self) -> PathBuf { - self.root_path() - } - - pub fn dir_src(&mut self) -> PathBuf { - self.get_path(DIR_SRC) - } - - pub fn dir_target(&mut self) -> PathBuf { - self.get_path(DIR_TARGET) - } - - pub fn dir_main(&mut self) -> PathBuf { - self.get_path(DIR_MAIN) - } - - pub fn dir_test(&mut self) -> PathBuf { - self.get_path(DIR_TEST) - } - - /// Attempts to load from cache, else generates the path and clones it to the cache. - /// Returns the requested path. - fn get_path(&mut self, k: S) -> PathBuf - where - S: ToString + AsRef, - { - self.from_cache(k.as_ref()) - .unwrap_or_else(|| { - self.gen_key(k.to_string(), self.root_path().join(k.to_string())); - self.get_path(k.as_ref()) - }) - .to_path_buf() - } - - /// Attempts to pull the value for the given key from the cache. - fn from_cache>(&self, path_key: S) -> Option { - self.derived_path_cache - .get(path_key.as_ref()) - .and_then(|v| Some(v.to_owned())) - } - - /// Tries to generate a new key-value pair in the cache - fn gen_key(&mut self, k: S, v: P) -> Option - where - P: AsRef, - S: ToString, - { - self.derived_path_cache - .insert(k.to_string(), v.as_ref().to_path_buf()) - } -} - -impl

From

for PathHandler -where - P: AsRef, -{ - fn from(value: P) -> Self { - Self { - root_path: value.as_ref().to_path_buf(), - derived_path_cache: Default::default(), - } - } -} - -pub trait PathHandled { - fn set_path_handler(&mut self, ph: Arc>) {} - - fn with_path_handler(&mut self, ph: Arc>) -> &mut Self { - self - } -} - -#[cfg(test)] -mod tests { - use super::*; - - const ROOT: &str = "/root"; - - #[test] - fn ph_get_path() { - let root = PathBuf::from(ROOT); - let expected = root.join(DIR_SRC); - - let mut ph = PathHandler::from(root); - - assert!(ph.dir_src() == expected); - } - - #[test] - fn ph_cache_gen() { - let root = PathBuf::from(ROOT); - let expected = root.join(DIR_SRC); - - let ph = PathHandler::from(root); - - assert!( - ph.derived_path_cache - .get(DIR_SRC) - .is_some_and(|v| *v == expected) - ); - } - - #[test] - fn ph_cache_pull() { - let faux_path = "faux/path"; - - let mut ph = PathHandler::from("false/root"); - ph.derived_path_cache - .insert(faux_path.to_string(), PathBuf::from(faux_path)); - - // Use the method that attempts a fallback. - // By using a false root, this will create a different path to the injected one, - // making it possible to determine if the cache load fails. - // - // I.e. - // Expected: faux/path as PathBuf - // Failed: false/root/faux/path as PathBuf - assert!(ph.get_path(faux_path) == PathBuf::from(faux_path)); - } -} diff --git a/crates/pom/Cargo.toml b/crates/pom/Cargo.toml index 266b875..2715308 100644 --- a/crates/pom/Cargo.toml +++ b/crates/pom/Cargo.toml @@ -8,7 +8,6 @@ description = "Library for serializing and deserializing Maven's POM" repository.workspace = true publish.workspace = true -test.workspace = true [dependencies] derive_more.workspace = true diff --git a/crates/pom/src/error.rs b/crates/pom/src/error.rs index 567db1b..4ec9dde 100644 --- a/crates/pom/src/error.rs +++ b/crates/pom/src/error.rs @@ -1,6 +1,6 @@ use derive_more::{Display, From}; -pub type Result = core::result::Result; +pub type Result = std::result::Result; #[derive(Debug, From, Display)] pub enum Error { diff --git a/crates/raven/Cargo.toml b/crates/raven/Cargo.toml index ad08a98..6026a1b 100644 --- a/crates/raven/Cargo.toml +++ b/crates/raven/Cargo.toml @@ -10,7 +10,6 @@ categories = ["development-tools::build-utils"] repository.workspace = true publish.workspace = true -test.workspace = true [dependencies] anyhow.workspace = true @@ -20,5 +19,4 @@ core.workspace = true fs.workspace = true io.workspace = true java.workspace = true -path.workspace = true toml.workspace = true diff --git a/crates/raven/src/env.rs b/crates/raven/src/env.rs deleted file mode 100644 index 706c977..0000000 --- a/crates/raven/src/env.rs +++ /dev/null @@ -1,19 +0,0 @@ -use std::path::PathBuf; - -use anyhow::Context; - -pub fn in_path>(binary: S) -> Result { - std::env::var("PATH").and_then(|paths| { - Ok(paths - .split(":") - .map(|p| PathBuf::from(p).join(binary.as_ref())) - .any(|p| p.exists())) - }) -} - -pub fn get_project_root() -> anyhow::Result { - nest::locate_nest().context( - "Attempted to find Nest.toml, but it could not be located.\n - It's likely that a call for get_project_root occurred before runtime checks were ran.", - ) -} diff --git a/crates/raven/src/main.rs b/crates/raven/src/main.rs index 1cc735c..df07529 100644 --- a/crates/raven/src/main.rs +++ b/crates/raven/src/main.rs @@ -1,68 +1,37 @@ -mod env; -mod manager; - -use std::fs::OpenOptions; -use std::io::{Read, Write}; -use std::path::{Path, PathBuf}; -use std::sync::{Arc, Mutex}; +use core::prelude::WorkspaceHandler; +use anyhow::anyhow; use cli::{CLI_ARGS, Command}; -use java::{FN_JAVA_VERSION, JAVA_EXT_CLASS, JAVA_EXT_SOURCE}; -//use nest::prelude::{Class, F_NEST_LOCK, F_NEST_TOML, Nest, NestLock, Prey, PreyLock}; -//use path::{PathHandled, PathHandler}; - -use anyhow::{Context, anyhow}; -use bytesize::ByteSize; fn main() -> anyhow::Result<()> { - // Ensure that ph is constructed with the assumption that it is at the project root. - let mut ph = match CLI_ARGS.command.clone() { - Command::Init => PathHandler::new(std::env::current_dir()?), - Command::New { name, .. } => PathHandler::new(std::env::current_dir()?.join(name)), - _ => PathHandler::new(crate::env::get_project_root()?), - }; + // type_ is yet unused. + if let Command::New { project_name, .. } = &CLI_ARGS.command { + new(project_name.to_owned())?; + } - // Ensure that Nest.toml exists in the way functions need. - // Init does not need one, but it's easier to deal with the minor unnecessary computation - // of running the default contrustor, thand to fight the compiler. - let mut nest = match CLI_ARGS.command { - Command::Build | Command::Run { .. } => Nest::try_from(ph.project_root().join(F_NEST_TOML)) - .map_err(|err| { - anyhow!( - "No {} found in project directory: {}.\n{}", - F_NEST_TOML, - ph.project_root().display(), - err.to_string() - ) - })?, - _ => Nest::default(), - }; + let project_root = std::env::current_dir()?; - match CLI_ARGS.command.clone() { - Command::Init => init(ph)?, - Command::New { name, .. } => { - new(name.to_owned())?; - init(ph)?; - } - Command::Build => { - build(&mut ph, &mut nest)?; - } + let mut wh: WorkspaceHandler = match &CLI_ARGS.command { + Command::New { .. } | Command::Init => WorkspaceHandler::new(project_root), + _ => WorkspaceHandler::load(project_root), + } + .map_err(|err| anyhow!(err))?; + + dbg!(); + match &CLI_ARGS.command { + Command::New { .. } | Command::Init => wh.init(), + Command::Build => wh.build(), Command::Run { entry_point, assertions, - } => { - build(&mut ph, &mut nest)?; - run( - &mut ph, - entry_point.unwrap_or(nest.workspace.default_package), - assertions.into(), - )?; - } - Command::Test { assertions } => { - test(&mut ph, assertions.into())?; - } - Command::Clean => clean(&mut ph), + } => wh + .build() + .map_err(|err| anyhow!(err))? + .run(entry_point.to_owned(), assertions.into()), + Command::Clean => wh.clean(), + Command::Test { .. } => unimplemented!(), } + .map_err(|err| anyhow!(err))?; Ok(()) } @@ -75,24 +44,3 @@ fn new(project_name: String) -> anyhow::Result<()> { Ok(()) } - -fn run>( - ph: &mut PathHandler, - entry_point: P, - assertions: bool, -) -> anyhow::Result<(Option, Option)> { - // JRE pathing will be messed up without this. - std::env::set_current_dir(ph.dir_target())?; - - java::runtime::JVMBuilder::new(ph.dir_target()) - .assertions(assertions) - .monitor(true) - .build() - .run(entry_point) - .map_err(|err| anyhow!(err)) -} - -fn clean(ph: &mut PathHandler) { - let _ = std::fs::remove_file(ph.project_root().join(F_NEST_LOCK)); - let _ = std::fs::remove_dir_all(ph.dir_target()); -} diff --git a/crates/raven/src/manager.rs b/crates/raven/src/manager.rs deleted file mode 100644 index 6aeabe2..0000000 --- a/crates/raven/src/manager.rs +++ /dev/null @@ -1,11 +0,0 @@ -use std::collections::HashSet; - -use nest::prelude::{Nest, NestLock}; -use path::PathHandler; - -pub struct ProjectManager { - ph: PathHandler, - nest: Nest, - nest_lock: NestLock, - // HashSet -} diff --git a/demo/.java-version b/demo/.java-version new file mode 100644 index 0000000..aabe6ec --- /dev/null +++ b/demo/.java-version @@ -0,0 +1 @@ +21 diff --git a/demo/Nest.toml b/demo/Nest.toml new file mode 100644 index 0000000..f936757 --- /dev/null +++ b/demo/Nest.toml @@ -0,0 +1,8 @@ +dependencies = [] + +[workspace] +default_package = "main" + +[meta] +name = "demo" +version = "0.1.0" diff --git a/demo/src/main/Prey.toml b/demo/src/main/Prey.toml new file mode 100644 index 0000000..f2dc644 --- /dev/null +++ b/demo/src/main/Prey.toml @@ -0,0 +1,6 @@ +[package] +entry_point = "" + +[meta] +name = "main" +version = "0.1.0" diff --git a/demo/src/main/java/Main.java b/demo/src/main/java/Main.java new file mode 100644 index 0000000..52b9fad --- /dev/null +++ b/demo/src/main/java/Main.java @@ -0,0 +1,10 @@ +public class Main { + + public static void main(String[] args) { + System.out.println("Hello, world!"); + } + + public static int add(int a, int b) { + return a + b; + } +} diff --git a/demo/src/test/Prey.toml b/demo/src/test/Prey.toml new file mode 100644 index 0000000..078176b --- /dev/null +++ b/demo/src/test/Prey.toml @@ -0,0 +1,6 @@ +[package] +entry_point = "" + +[meta] +name = "test" +version = "0.1.0" diff --git a/demo/src/test/java/MainTest.java b/demo/src/test/java/MainTest.java new file mode 100644 index 0000000..ed111a6 --- /dev/null +++ b/demo/src/test/java/MainTest.java @@ -0,0 +1,10 @@ +public class MainTest { + + public static void main(String[] args) { + testAdd(); + } + + public static void testAdd() { + assert Main.add(2, 2) == 4; + } +} diff --git a/demo/target/Main.class b/demo/target/Main.class new file mode 100644 index 0000000000000000000000000000000000000000..96e9d9392c88cf3ce06669fca0c797bd985acbc7 GIT binary patch literal 471 zcmZvZ+e*Vg5QhJ4lBS8Nt*x!vgS8hzDqH#Xf@y2bllr1?(OcmeB8@*8Q z!Uyo7#Mvkmp?fhiJM;e^!|vDj$0vYev}|Ocna~{=$TAdX{DF6U9!|TLey*LH%@6 StKUASzy&-aai6)GYgQY0RSAf(dMCSIY1;8eEL55t8c zXIiNskl@aTs+chezU=JI{O321eg1#{2%v$_9&)fGY#$Et0;MzcTdj3fc)E7jKGU5< zAir)xlYAGjYV~6eE(#K!j}ex;`^tnzIwqM+$TWhWK#HP|QH%*puBbTHQDS;wylrCD z?&?55oOl?=gv6weDZCS~nL>OOP}He4oAstdMWC8B(-?AgqNo>nD8uqFgIS3=AM;oc z7|X<4T`DV34s>iH9lYhX5|#8RK!co6)vaEjDR0k&`k;T&*3l6+NP&yAopSBxUdC)C zkqJ+~)sF>=#Oa*xt6u}XyWZ&zR^+vM{ivgN4Reaa<*YIWi?o;=EnSqVydApPpmC9> z^F6)h$qKU0ms^M%7UBb)9Oiq0083<9%6|6RcaWKqzmlOAK@0pp1NBDg2daPIUt-E} z?og6f7