I think I finished it...

This commit is contained in:
Cutieguwu
2026-02-15 17:39:48 -05:00
parent 0fad1b74bc
commit 79629391c5
33 changed files with 215 additions and 389 deletions

28
Cargo.lock generated
View File

@@ -155,26 +155,6 @@ version = "1.0.4"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b05b61dc5112cbb17e4b6cd61790d9845d13888356391624cbe7e41efeac1e75" 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]] [[package]]
name = "convert_case" name = "convert_case"
version = "0.10.0" version = "0.10.0"
@@ -383,13 +363,6 @@ version = "1.70.2"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "384b8ab6d37215f3c5301a95a4accb5d64aa607f1fcb26a11b5303878451b4fe" checksum = "384b8ab6d37215f3c5301a95a4accb5d64aa607f1fcb26a11b5303878451b4fe"
[[package]]
name = "path"
version = "0.1.0"
dependencies = [
"const_format",
]
[[package]] [[package]]
name = "pathsub" name = "pathsub"
version = "0.1.1" version = "0.1.1"
@@ -442,7 +415,6 @@ dependencies = [
"fs", "fs",
"io", "io",
"java", "java",
"path",
"toml", "toml",
] ]

View File

@@ -10,7 +10,6 @@ license = "MIT"
repository = "https://gitea.cutieguwu.ca/Cutieguwu/raven" repository = "https://gitea.cutieguwu.ca/Cutieguwu/raven"
publish = false publish = false
test = true
[workspace.dependencies] [workspace.dependencies]
# #
@@ -21,7 +20,6 @@ fs = { path = "crates/fs" }
io = { path = "crates/io" } io = { path = "crates/io" }
java = { path = "crates/java" } java = { path = "crates/java" }
core = { path = "crates/core" } core = { path = "crates/core" }
path = { path = "crates/path" }
pom = { path = "crates/pom" } pom = { path = "crates/pom" }
raven = { path = "crates/raven" } raven = { path = "crates/raven" }

View File

@@ -8,7 +8,6 @@ description = "Raven's CLI"
repository.workspace = true repository.workspace = true
publish.workspace = true publish.workspace = true
test.workspace = true
[dependencies.clap] [dependencies.clap]
version = "4.5" version = "4.5"

View File

@@ -19,7 +19,7 @@ pub enum Command {
New { New {
#[clap(flatten)] #[clap(flatten)]
type_: ProjectFlag, type_: ProjectFlag,
name: String, project_name: String,
}, },
/// Create a new raven project in an existing directory /// Create a new raven project in an existing directory
Init, Init,
@@ -49,7 +49,7 @@ pub struct Assertions {
assertions: bool, assertions: bool,
} }
impl Into<bool> for Assertions { impl Into<bool> for &Assertions {
fn into(self) -> bool { fn into(self) -> bool {
self.assertions self.assertions
} }

View File

@@ -8,7 +8,6 @@ description = "Raven's core, including metadata tooling and resources"
repository.workspace = true repository.workspace = true
publish.workspace = true publish.workspace = true
test.workspace = true
[dependencies] [dependencies]
derive_more.workspace = true derive_more.workspace = true

View File

@@ -45,6 +45,6 @@ impl From<PackageHandler> for Dependency {
} }
/// TODO: This is just a placeholder at present. /// TODO: This is just a placeholder at present.
fn is_url<S: ToString>(path: S) -> bool { fn is_url<S: ToString>(_path: S) -> bool {
return false; return false;
} }

View File

@@ -1,6 +1,6 @@
use derive_more::{Display, From}; use derive_more::{Display, From};
pub type Result<T> = core::result::Result<T, Error>; pub type Result<T> = std::result::Result<T, Error>;
#[derive(Debug, From, Display)] #[derive(Debug, From, Display)]
pub enum Error { pub enum Error {

View File

@@ -1,5 +1,3 @@
#![allow(dead_code)]
pub mod class; pub mod class;
pub mod dependency; pub mod dependency;
pub mod error; pub mod error;

View File

@@ -5,8 +5,8 @@ use std::path::{Path, PathBuf};
use serde::{Deserialize, Serialize}; use serde::{Deserialize, Serialize};
use crate::dependency::Dependency;
use crate::meta::Meta; use crate::meta::Meta;
use crate::prelude::Dependency;
use crate::workspace::Workspace; use crate::workspace::Workspace;
pub const F_NEST_TOML: &str = "Nest.toml"; pub const F_NEST_TOML: &str = "Nest.toml";
@@ -30,6 +30,11 @@ impl Nest {
} }
pub fn write<P: AsRef<Path>>(&self, path: P) -> crate::Result<()> { pub fn write<P: AsRef<Path>>(&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() Ok(OpenOptions::new()
.write(true) .write(true)
.create(true) .create(true)

View File

@@ -19,8 +19,8 @@ pub struct PackageHandler {
impl PackageHandler { impl PackageHandler {
const DIR_JAVA: &str = "java/"; const DIR_JAVA: &str = "java/";
pub fn new<P: AsRef<Path>>(package_root: P, target_dir: P) -> crate::Result<Self> { pub fn new<P: AsRef<Path>>(src_dir: P, package_root: P, target_dir: P) -> crate::Result<Self> {
let package_root = package_root.as_ref().to_path_buf(); let package_root = src_dir.as_ref().join(package_root.as_ref());
Ok(Self { Ok(Self {
prey: Prey::try_from(package_root.join(F_PREY_TOML))?, prey: Prey::try_from(package_root.join(F_PREY_TOML))?,
@@ -42,32 +42,32 @@ impl PackageHandler {
self.prey.version() self.prey.version()
} }
pub fn get_update_targets(&mut self) -> crate::Result<Vec<&mut Class>> { pub fn get_update_targets(&mut self) -> crate::Result<Vec<&Class>> {
let mut targets = vec![];
if self.prey_lock.is_none() { if self.prey_lock.is_none() {
// Try to pass a reference to the class so that there's mutability of the object // 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 // 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. // 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)?)); self.prey_lock = Some(PreyLock::from(expand_files(
return Ok(self self.package_root.join(Self::DIR_JAVA),
.prey_lock )?));
.clone() return Ok(self.prey_lock.as_ref().unwrap().classes.iter().collect());
.unwrap()
.classes
.iter()
.map(|mut *class| &mut class)
.collect());
} }
for mut tracked in self.prey_lock.unwrap().classes { Ok(self
if !tracked.is_updated()? { .prey_lock
targets.push(&mut tracked); .as_ref()
} .unwrap()
} .classes
.iter()
Ok(targets) .filter_map(|tracked| {
if tracked.is_updated().is_ok_and(|v| v == true) {
Some(tracked)
} else {
None
}
})
.collect())
} }
} }

View File

@@ -1,14 +1,12 @@
use std::collections::HashSet;
use std::fs::{File, OpenOptions}; use std::fs::{File, OpenOptions};
use std::io::Read; use std::io::Read;
use std::path::{Path, PathBuf}; use std::path::PathBuf;
use serde::{Deserialize, Serialize}; use serde::{Deserialize, Serialize};
use crate::class::Class; use crate::class::Class;
use crate::meta::Meta; use crate::meta::Meta;
use crate::package::Package; use crate::package::Package;
use crate::prelude::Dependency;
pub const F_PREY_TOML: &str = "Prey.toml"; pub const F_PREY_TOML: &str = "Prey.toml";
pub const F_PREY_LOCK: &str = "Prey.lock"; pub const F_PREY_LOCK: &str = "Prey.lock";
@@ -21,6 +19,15 @@ pub struct Prey {
} }
impl Prey { impl Prey {
pub fn new<S: ToString>(name: S) -> Self {
Self {
package: Package {
entry_point: PathBuf::from(""),
},
meta: Meta::new(name),
}
}
pub fn entry_point(&self) -> PathBuf { pub fn entry_point(&self) -> PathBuf {
self.package.entry_point.clone() self.package.entry_point.clone()
} }
@@ -56,12 +63,12 @@ impl TryFrom<File> for Prey {
/// Data struct /// Data struct
#[derive(Debug, Clone, Default, Deserialize, Serialize, PartialEq, Eq)] #[derive(Debug, Clone, Default, Deserialize, Serialize, PartialEq, Eq)]
pub struct PreyLock { pub struct PreyLock {
pub classes: HashSet<Class>, pub classes: Vec<Class>,
} }
impl PreyLock { impl PreyLock {
pub fn with_class(&mut self, class: Class) -> &mut Self { pub fn with_class(&mut self, class: Class) -> &mut Self {
self.classes.insert(class); self.classes.push(class);
self self
} }
} }

View File

@@ -11,8 +11,9 @@ use serde::{Deserialize, Serialize};
use crate::Error; use crate::Error;
use crate::nest::{F_NEST_LOCK, F_NEST_TOML, Nest, NestLock}; use crate::nest::{F_NEST_LOCK, F_NEST_TOML, Nest, NestLock};
use crate::package::PackageHandler; use crate::package::PackageHandler;
use crate::prey::F_PREY_TOML; use crate::prey::{F_PREY_TOML, Prey};
#[derive(Debug)]
pub struct WorkspaceHandler { pub struct WorkspaceHandler {
nest: Nest, nest: Nest,
nest_lock: Option<NestLock>, nest_lock: Option<NestLock>,
@@ -56,7 +57,7 @@ impl WorkspaceHandler {
} }
pub fn write(&self) -> crate::Result<()> { 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() { if let Option::Some(lock) = self.nest_lock.clone() {
lock.write(self.project_root.join(F_NEST_LOCK))?; lock.write(self.project_root.join(F_NEST_LOCK))?;
@@ -65,8 +66,6 @@ impl WorkspaceHandler {
Ok(()) Ok(())
} }
//pub fn refresh_packages(&mut self) -> crate::Result<()> {}
/* /*
/// Future `build` method. /// Future `build` method.
pub fn compile(&self, target: Option<PathBuf>) -> crate::Result<()> { pub fn compile(&self, target: Option<PathBuf>) -> crate::Result<()> {
@@ -87,13 +86,9 @@ impl WorkspaceHandler {
Ok(()) Ok(())
} }
fn make_compiler_job<P: AsRef<Path>>(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); let is_empty = read_dir(self.project_root.as_path()).is_ok_and(|tree| tree.count() == 0);
// ORDER MATTERS. THIS MUST COME FIRST. // ORDER MATTERS. THIS MUST COME FIRST.
@@ -103,10 +98,7 @@ impl WorkspaceHandler {
// Make .java-version // Make .java-version
self.write_java_version()?; self.write_java_version()?;
// Make src/, target/, test/ if is_empty {
self.write_dir_tree()?;
if !is_empty {
self.write_example_project()?; self.write_example_project()?;
self.discover_packages()?; self.discover_packages()?;
@@ -134,30 +126,72 @@ impl WorkspaceHandler {
} }
} }
Ok(()) Ok(self)
} }
// This is the naive build // 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![]; 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()?); targets.append(&mut handler.get_update_targets()?);
} }
let compiler = java::compiler::CompilerBuilder::new() let compiler = java::compiler::CompilerBuilder::new()
.class_path(Self::DIR_TARGET) .class_path(Self::DIR_TARGET)
.class_path(Self::DIR_TARGET) .destination(Self::DIR_TARGET)
.build(); .build();
for target in targets { for target in targets.iter() {
// Possibly come up with a source file handler for this? // 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) // No, this does not run O(1)
//target.update()?;
} }
} }
Ok(()) Ok(self)
}
pub fn run<P: AsRef<Path>>(
&mut self,
entry_point: Option<P>,
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. /// Add any newly created packages.
@@ -174,7 +208,7 @@ impl WorkspaceHandler {
// Yes, I know this looks like shit. // Yes, I know this looks like shit.
// That's because it is. // 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 // Get directories
.filter_map(|entry| { .filter_map(|entry| {
if entry.as_ref().is_ok_and(|entry| entry.path().is_dir()) { if entry.as_ref().is_ok_and(|entry| entry.path().is_dir()) {
@@ -203,12 +237,22 @@ impl WorkspaceHandler {
}) })
.flatten() .flatten()
{ {
let package_root = let package_root = pathsub::sub_paths(
pathsub::sub_paths(file.as_path(), PathBuf::from(Self::DIR_SRC).as_path()).unwrap(); file.as_path(),
self.project_root.join(Self::DIR_SRC).as_path(),
)
.unwrap()
.parent()
.unwrap()
.to_path_buf();
self.packages.insert( self.packages.insert(
package_root.to_path_buf(), 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<()> { fn write_nest(&self) -> crate::Result<()> {
if let Result::Ok(mut f) = OpenOptions::new() Ok(self.nest.write(self.project_root.clone())?)
.write(true)
.create_new(true)
.open(F_NEST_TOML)
{
f.write_all(toml::to_string_pretty(&self.nest)?.as_bytes())?;
}
Ok(())
} }
fn write_java_version(&self) -> crate::Result<()> { fn write_java_version(&self) -> crate::Result<()> {
@@ -251,22 +287,46 @@ impl WorkspaceHandler {
Ok(()) 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 // Make src/main/Main.java
if let Result::Ok(mut f) = OpenOptions::new().write(true).create_new(true).open( if let Result::Ok(mut f) = OpenOptions::new()
PathBuf::from(Self::DIR_SRC) .write(true)
.join("main/java/Main") .create_new(true)
.with_extension(JAVA_EXT_SOURCE), .open(main.join("java/Main").with_extension(JAVA_EXT_SOURCE))
) { {
f.write_all(include_bytes!("../assets/Main.java"))?; 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 // Make src/test/MainTest.java
if let Result::Ok(mut f) = OpenOptions::new().write(true).create_new(true).open( if let Result::Ok(mut f) = OpenOptions::new()
PathBuf::from(Self::DIR_SRC) .write(true)
.join("test/java/MainTest") .create_new(true)
.with_extension(JAVA_EXT_SOURCE), .open(test.join("java/MainTest").with_extension(JAVA_EXT_SOURCE))
) { {
f.write_all(include_bytes!("../assets/MainTest.java"))?; f.write_all(include_bytes!("../assets/MainTest.java"))?;
} }

View File

@@ -8,7 +8,6 @@ description = "Raven's FS utilities"
repository.workspace = true repository.workspace = true
publish.workspace = true publish.workspace = true
test.workspace = true
[dependencies] [dependencies]
derive_more.workspace = true derive_more.workspace = true

View File

@@ -8,7 +8,6 @@ description = "Raven's IO utilities"
repository.workspace = true repository.workspace = true
publish.workspace = true publish.workspace = true
test.workspace = true
[dependencies] [dependencies]
derive_more.workspace = true derive_more.workspace = true

View File

@@ -1,6 +1,6 @@
use derive_more::{Display, From}; use derive_more::{Display, From};
pub type Result<T> = core::result::Result<T, Error>; pub type Result<T> = std::result::Result<T, Error>;
#[derive(Debug, From, Display)] #[derive(Debug, From, Display)]
pub enum Error { pub enum Error {

View File

@@ -11,7 +11,6 @@ description = "Tools for interfacing with the Java Development Kit"
repository.workspace = true repository.workspace = true
publish.workspace = true publish.workspace = true
test.workspace = true
[dependencies] [dependencies]
bytesize.workspace = true bytesize.workspace = true

View File

@@ -1,6 +1,6 @@
use derive_more::{Display, From}; use derive_more::{Display, From};
pub type Result<T> = core::result::Result<T, Error>; pub type Result<T> = std::result::Result<T, Error>;
#[derive(Debug, From, Display)] #[derive(Debug, From, Display)]
pub enum Error { pub enum Error {

View File

@@ -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

View File

@@ -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<String, PathBuf>,
}
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<S>(&mut self, k: S) -> PathBuf
where
S: ToString + AsRef<str>,
{
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<S: AsRef<str>>(&self, path_key: S) -> Option<PathBuf> {
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<P, S>(&mut self, k: S, v: P) -> Option<PathBuf>
where
P: AsRef<Path>,
S: ToString,
{
self.derived_path_cache
.insert(k.to_string(), v.as_ref().to_path_buf())
}
}
impl<P> From<P> for PathHandler
where
P: AsRef<Path>,
{
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<Mutex<PathHandler>>) {}
fn with_path_handler(&mut self, ph: Arc<Mutex<PathHandler>>) -> &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));
}
}

View File

@@ -8,7 +8,6 @@ description = "Library for serializing and deserializing Maven's POM"
repository.workspace = true repository.workspace = true
publish.workspace = true publish.workspace = true
test.workspace = true
[dependencies] [dependencies]
derive_more.workspace = true derive_more.workspace = true

View File

@@ -1,6 +1,6 @@
use derive_more::{Display, From}; use derive_more::{Display, From};
pub type Result<T> = core::result::Result<T, Error>; pub type Result<T> = std::result::Result<T, Error>;
#[derive(Debug, From, Display)] #[derive(Debug, From, Display)]
pub enum Error { pub enum Error {

View File

@@ -10,7 +10,6 @@ categories = ["development-tools::build-utils"]
repository.workspace = true repository.workspace = true
publish.workspace = true publish.workspace = true
test.workspace = true
[dependencies] [dependencies]
anyhow.workspace = true anyhow.workspace = true
@@ -20,5 +19,4 @@ core.workspace = true
fs.workspace = true fs.workspace = true
io.workspace = true io.workspace = true
java.workspace = true java.workspace = true
path.workspace = true
toml.workspace = true toml.workspace = true

View File

@@ -1,19 +0,0 @@
use std::path::PathBuf;
use anyhow::Context;
pub fn in_path<S: AsRef<str>>(binary: S) -> Result<bool, std::env::VarError> {
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<PathBuf> {
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.",
)
}

View File

@@ -1,68 +1,37 @@
mod env; use core::prelude::WorkspaceHandler;
mod manager;
use std::fs::OpenOptions;
use std::io::{Read, Write};
use std::path::{Path, PathBuf};
use std::sync::{Arc, Mutex};
use anyhow::anyhow;
use cli::{CLI_ARGS, Command}; 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<()> { fn main() -> anyhow::Result<()> {
// Ensure that ph is constructed with the assumption that it is at the project root. // type_ is yet unused.
let mut ph = match CLI_ARGS.command.clone() { if let Command::New { project_name, .. } = &CLI_ARGS.command {
Command::Init => PathHandler::new(std::env::current_dir()?), new(project_name.to_owned())?;
Command::New { name, .. } => PathHandler::new(std::env::current_dir()?.join(name)), }
_ => PathHandler::new(crate::env::get_project_root()?),
};
// Ensure that Nest.toml exists in the way functions need. let project_root = std::env::current_dir()?;
// 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(),
};
match CLI_ARGS.command.clone() { let mut wh: WorkspaceHandler = match &CLI_ARGS.command {
Command::Init => init(ph)?, Command::New { .. } | Command::Init => WorkspaceHandler::new(project_root),
Command::New { name, .. } => { _ => WorkspaceHandler::load(project_root),
new(name.to_owned())?; }
init(ph)?; .map_err(|err| anyhow!(err))?;
}
Command::Build => { dbg!();
build(&mut ph, &mut nest)?; match &CLI_ARGS.command {
} Command::New { .. } | Command::Init => wh.init(),
Command::Build => wh.build(),
Command::Run { Command::Run {
entry_point, entry_point,
assertions, assertions,
} => { } => wh
build(&mut ph, &mut nest)?; .build()
run( .map_err(|err| anyhow!(err))?
&mut ph, .run(entry_point.to_owned(), assertions.into()),
entry_point.unwrap_or(nest.workspace.default_package), Command::Clean => wh.clean(),
assertions.into(), Command::Test { .. } => unimplemented!(),
)?;
}
Command::Test { assertions } => {
test(&mut ph, assertions.into())?;
}
Command::Clean => clean(&mut ph),
} }
.map_err(|err| anyhow!(err))?;
Ok(()) Ok(())
} }
@@ -75,24 +44,3 @@ fn new(project_name: String) -> anyhow::Result<()> {
Ok(()) Ok(())
} }
fn run<P: AsRef<Path>>(
ph: &mut PathHandler,
entry_point: P,
assertions: bool,
) -> anyhow::Result<(Option<String>, Option<String>)> {
// 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());
}

View File

@@ -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<Crates { prey, prey_lock }>
}

1
demo/.java-version Normal file
View File

@@ -0,0 +1 @@
21

8
demo/Nest.toml Normal file
View File

@@ -0,0 +1,8 @@
dependencies = []
[workspace]
default_package = "main"
[meta]
name = "demo"
version = "0.1.0"

6
demo/src/main/Prey.toml Normal file
View File

@@ -0,0 +1,6 @@
[package]
entry_point = ""
[meta]
name = "main"
version = "0.1.0"

View File

@@ -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;
}
}

6
demo/src/test/Prey.toml Normal file
View File

@@ -0,0 +1,6 @@
[package]
entry_point = ""
[meta]
name = "test"
version = "0.1.0"

View File

@@ -0,0 +1,10 @@
public class MainTest {
public static void main(String[] args) {
testAdd();
}
public static void testAdd() {
assert Main.add(2, 2) == 4;
}
}

BIN
demo/target/Main.class Normal file

Binary file not shown.

BIN
demo/target/MainTest.class Normal file

Binary file not shown.