Most of the refactor. Need to switch machines.
This commit is contained in:
15
crates/cli/Cargo.toml
Normal file
15
crates/cli/Cargo.toml
Normal file
@@ -0,0 +1,15 @@
|
||||
[package]
|
||||
name = "cli"
|
||||
version = "0.1.0"
|
||||
edition.workspace = true
|
||||
license.workspace = true
|
||||
|
||||
description = "Raven's CLI"
|
||||
repository.workspace = true
|
||||
|
||||
publish.workspace = true
|
||||
test.workspace = true
|
||||
|
||||
[dependencies.clap]
|
||||
version = "4.5"
|
||||
features = ["cargo", "derive"]
|
||||
153
crates/cli/src/lib.rs
Normal file
153
crates/cli/src/lib.rs
Normal file
@@ -0,0 +1,153 @@
|
||||
use std::sync::LazyLock;
|
||||
use std::{fmt::Display, path::PathBuf};
|
||||
|
||||
use clap::{ArgAction, Args, Parser, Subcommand, ValueEnum};
|
||||
|
||||
pub static CLI_ARGS: LazyLock<CliArgs> = LazyLock::new(|| CliArgs::parse());
|
||||
|
||||
#[derive(Debug, Parser)]
|
||||
#[clap(author, version)]
|
||||
#[command(help_template = "{author-section}\n{usage-heading} {usage}\n\n{all-args}")]
|
||||
pub struct CliArgs {
|
||||
#[command(subcommand)]
|
||||
pub command: Command,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Subcommand)]
|
||||
pub enum Command {
|
||||
/// Create a new raven project
|
||||
New {
|
||||
#[clap(flatten)]
|
||||
type_: ProjectFlag,
|
||||
name: String,
|
||||
},
|
||||
/// Create a new raven project in an existing directory
|
||||
Init,
|
||||
/// Compile the current project
|
||||
Build,
|
||||
/// Run the current project
|
||||
Run {
|
||||
#[clap(value_hint = clap::ValueHint::DirPath)]
|
||||
entry_point: Option<PathBuf>,
|
||||
|
||||
#[clap(flatten)]
|
||||
assertions: Assertions,
|
||||
},
|
||||
/// !!! BORKED !!! Run the tests
|
||||
Test {
|
||||
#[clap(flatten)]
|
||||
assertions: Assertions,
|
||||
},
|
||||
/// Remove the target directory and caching
|
||||
Clean,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Copy, PartialEq, Eq, Args)]
|
||||
pub struct Assertions {
|
||||
/// Disable assertions.
|
||||
#[arg(short, long = "no-assert", action = ArgAction::SetFalse)]
|
||||
assertions: bool,
|
||||
}
|
||||
|
||||
impl Into<bool> for Assertions {
|
||||
fn into(self) -> bool {
|
||||
self.assertions
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Default, Clone, Copy, PartialEq, Eq, Args)]
|
||||
#[group(multiple = false)]
|
||||
pub struct ProjectFlag {
|
||||
#[arg(long, action = ArgAction::SetTrue)]
|
||||
_nest: (),
|
||||
#[arg(long, action = ArgAction::SetTrue)]
|
||||
_package: (),
|
||||
|
||||
#[arg(
|
||||
hide = true,
|
||||
required = false,
|
||||
short,
|
||||
long,
|
||||
default_value_ifs = [
|
||||
("_nest", "true", "nest"),
|
||||
("_package", "true", "package"),
|
||||
("_nest", "false", "nest"),
|
||||
],
|
||||
)]
|
||||
pub project_type: ProjectType,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Copy, Default, PartialEq, Eq, ValueEnum)]
|
||||
#[value(rename_all = "kebab-case")]
|
||||
pub enum ProjectType {
|
||||
#[default]
|
||||
Nest,
|
||||
Package,
|
||||
}
|
||||
|
||||
impl Display for ProjectType {
|
||||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
||||
write!(f, "{}", Self::to_string(&self))
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
|
||||
#[test]
|
||||
fn args_new_w_arg() {
|
||||
let args: CliArgs = Parser::try_parse_from(["raven", "new", "demo"]).unwrap();
|
||||
let type_ = match args.command {
|
||||
Command::New { type_, .. } => type_,
|
||||
_ => unreachable!(),
|
||||
};
|
||||
|
||||
assert!(type_.project_type == ProjectType::Nest);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn args_new_nest() {
|
||||
let args: CliArgs = Parser::try_parse_from(["raven", "new", "--nest", "demo"]).unwrap();
|
||||
let type_ = match args.command {
|
||||
Command::New { type_, .. } => type_,
|
||||
_ => unreachable!(),
|
||||
};
|
||||
|
||||
assert!(type_.project_type == ProjectType::Nest);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn args_new_package() {
|
||||
let args: CliArgs = Parser::try_parse_from(["raven", "new", "--package", "demo"]).unwrap();
|
||||
let type_ = match args.command {
|
||||
Command::New { type_, .. } => type_,
|
||||
_ => unreachable!(),
|
||||
};
|
||||
|
||||
assert!(type_.project_type == ProjectType::Package);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn args_run_assert() {
|
||||
let args: CliArgs = Parser::try_parse_from(["raven", "run", "Main"]).unwrap();
|
||||
let assertions: bool = match args.command {
|
||||
Command::Run { assertions, .. } => assertions.assertions,
|
||||
_ => unreachable!(),
|
||||
};
|
||||
|
||||
assert!(assertions == true)
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn args_run_no_assert() {
|
||||
let args: CliArgs =
|
||||
Parser::try_parse_from(["raven", "run", "--no-assert", "Main"]).unwrap();
|
||||
let assertions: bool = match args.command {
|
||||
Command::Run { assertions, .. } => assertions.assertions,
|
||||
_ => unreachable!(),
|
||||
};
|
||||
|
||||
assert!(assertions == false)
|
||||
}
|
||||
}
|
||||
29
crates/core/Cargo.toml
Normal file
29
crates/core/Cargo.toml
Normal file
@@ -0,0 +1,29 @@
|
||||
[package]
|
||||
name = "core"
|
||||
version = "0.1.0"
|
||||
edition.workspace = true
|
||||
license.workspace = true
|
||||
|
||||
description = "Raven's core, including metadata tooling and resources"
|
||||
repository.workspace = true
|
||||
|
||||
publish.workspace = true
|
||||
test.workspace = true
|
||||
|
||||
[dependencies]
|
||||
derive_more.workspace = true
|
||||
fs.workspace = true
|
||||
io.workspace = true
|
||||
java.workspace = true
|
||||
pathsub.workspace = true
|
||||
semver.workspace = true
|
||||
serde.workspace = true
|
||||
sha256.workspace = true
|
||||
toml.workspace = true
|
||||
|
||||
[dependencies.anyhow]
|
||||
workspace = true
|
||||
optional = true
|
||||
|
||||
[features]
|
||||
into_anyhow = ["dep:anyhow"]
|
||||
10
crates/core/assets/Main.java
Normal file
10
crates/core/assets/Main.java
Normal 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;
|
||||
}
|
||||
}
|
||||
10
crates/core/assets/MainTest.java
Normal file
10
crates/core/assets/MainTest.java
Normal 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;
|
||||
}
|
||||
}
|
||||
10
crates/core/src/class.rs
Normal file
10
crates/core/src/class.rs
Normal file
@@ -0,0 +1,10 @@
|
||||
use std::path::PathBuf;
|
||||
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
/// Data struct
|
||||
#[derive(Debug, Clone, Deserialize, Serialize, Hash, PartialEq, Eq, PartialOrd, Ord)]
|
||||
pub struct Class {
|
||||
pub path: PathBuf,
|
||||
pub checksum: String,
|
||||
}
|
||||
43
crates/core/src/dependency.rs
Normal file
43
crates/core/src/dependency.rs
Normal file
@@ -0,0 +1,43 @@
|
||||
use semver::Version;
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
use crate::package::PackageHandler;
|
||||
|
||||
/// Data struct
|
||||
#[derive(Debug, Clone, Deserialize, Serialize, Hash, PartialEq, Eq, PartialOrd, Ord)]
|
||||
pub struct Dependency {
|
||||
name: String,
|
||||
version: Version,
|
||||
pub checksum: String,
|
||||
#[serde(skip_serializing_if = "<Option<_>>::is_none")]
|
||||
source: Option<String>, // Path / URL
|
||||
}
|
||||
|
||||
impl Dependency {
|
||||
/// Returns a path to the dependency in local storage
|
||||
/// if there is one.
|
||||
pub fn local_path(&self) -> String {
|
||||
if self.source.as_ref().is_some_and(|path| !is_url(path)) {
|
||||
return self.source.clone().unwrap();
|
||||
}
|
||||
|
||||
// TODO: Convert from reverse domain name to path.
|
||||
return self.name.clone();
|
||||
}
|
||||
}
|
||||
|
||||
impl From<PackageHandler> for Dependency {
|
||||
fn from(value: PackageHandler) -> Self {
|
||||
Dependency {
|
||||
name: value.name(),
|
||||
version: value.version(),
|
||||
checksum: String::new(),
|
||||
source: None,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// TODO: This is just a placeholder at present.
|
||||
fn is_url<S: ToString>(path: S) -> bool {
|
||||
return false;
|
||||
}
|
||||
25
crates/core/src/error.rs
Normal file
25
crates/core/src/error.rs
Normal file
@@ -0,0 +1,25 @@
|
||||
use derive_more::{Display, From};
|
||||
|
||||
pub type Result<T> = core::result::Result<T, Error>;
|
||||
|
||||
#[derive(Debug, From, Display)]
|
||||
pub enum Error {
|
||||
#[from]
|
||||
Io(io::Error),
|
||||
|
||||
#[from]
|
||||
Java(java::Error),
|
||||
|
||||
MissingFileName,
|
||||
|
||||
#[from]
|
||||
StdIo(std::io::Error),
|
||||
|
||||
#[from]
|
||||
TomlDeserialize(toml::de::Error),
|
||||
|
||||
#[from]
|
||||
TomlSerialize(toml::ser::Error),
|
||||
|
||||
UnknownPackage,
|
||||
}
|
||||
13
crates/core/src/lib.rs
Normal file
13
crates/core/src/lib.rs
Normal file
@@ -0,0 +1,13 @@
|
||||
#![allow(dead_code)]
|
||||
|
||||
pub mod class;
|
||||
pub mod dependency;
|
||||
pub mod error;
|
||||
pub mod meta;
|
||||
pub mod nest;
|
||||
pub mod package;
|
||||
pub mod prelude;
|
||||
pub mod prey;
|
||||
pub mod workspace;
|
||||
|
||||
pub use error::{Error, Result};
|
||||
40
crates/core/src/meta.rs
Normal file
40
crates/core/src/meta.rs
Normal file
@@ -0,0 +1,40 @@
|
||||
use std::path::PathBuf;
|
||||
|
||||
use semver::Version;
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
/// Data struct
|
||||
#[derive(Debug, Clone, Deserialize, Serialize, Hash, PartialEq, Eq, PartialOrd, Ord)]
|
||||
pub struct Meta {
|
||||
pub name: String,
|
||||
pub version: Version,
|
||||
#[serde(skip_serializing_if = "<Option<_>>::is_none")]
|
||||
pub authors: Option<Vec<String>>,
|
||||
#[serde(skip_serializing_if = "<Option<_>>::is_none")]
|
||||
pub repository: Option<String>,
|
||||
#[serde(skip_serializing_if = "<Option<_>>::is_none")]
|
||||
pub license: Option<String>,
|
||||
#[serde(skip_serializing_if = "<Option<_>>::is_none")]
|
||||
pub license_file: Option<PathBuf>,
|
||||
}
|
||||
|
||||
impl Meta {
|
||||
pub fn new<S: ToString>(name: S) -> Self {
|
||||
let mut meta = Self::default();
|
||||
meta.name = name.to_string();
|
||||
meta
|
||||
}
|
||||
}
|
||||
|
||||
impl Default for Meta {
|
||||
fn default() -> Self {
|
||||
Meta {
|
||||
name: String::from("Main"),
|
||||
version: Version::new(0, 1, 0),
|
||||
authors: None,
|
||||
repository: None,
|
||||
license: None,
|
||||
license_file: None,
|
||||
}
|
||||
}
|
||||
}
|
||||
105
crates/core/src/nest.rs
Normal file
105
crates/core/src/nest.rs
Normal file
@@ -0,0 +1,105 @@
|
||||
use std::collections::HashSet;
|
||||
use std::fs::{File, OpenOptions};
|
||||
use std::io::{Read, Write};
|
||||
use std::path::{Path, PathBuf};
|
||||
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
use crate::meta::Meta;
|
||||
use crate::prelude::Dependency;
|
||||
use crate::workspace::Workspace;
|
||||
|
||||
pub const F_NEST_TOML: &str = "Nest.toml";
|
||||
pub const F_NEST_LOCK: &str = "Nest.lock";
|
||||
|
||||
/// Data struct
|
||||
#[derive(Debug, Clone, Default, Deserialize, Serialize, PartialEq, Eq)]
|
||||
pub struct Nest {
|
||||
workspace: Workspace,
|
||||
meta: Meta,
|
||||
dependencies: HashSet<Dependency>,
|
||||
}
|
||||
|
||||
impl Nest {
|
||||
pub fn new<S: ToString>(name: S) -> Self {
|
||||
Self {
|
||||
workspace: Workspace::default(),
|
||||
meta: Meta::new(name),
|
||||
dependencies: Default::default(),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn write<P: AsRef<Path>>(&self, path: P) -> crate::Result<()> {
|
||||
Ok(OpenOptions::new()
|
||||
.write(true)
|
||||
.create(true)
|
||||
.open(path)?
|
||||
.write_all(toml::to_string_pretty(&self)?.as_bytes())?)
|
||||
}
|
||||
|
||||
pub fn default_package(&self) -> PathBuf {
|
||||
self.workspace.default_package.clone()
|
||||
}
|
||||
|
||||
pub fn name(&self) -> String {
|
||||
self.meta.name.clone()
|
||||
}
|
||||
|
||||
pub fn set_default_package<P: AsRef<Path>>(&mut self, package: P) {
|
||||
self.workspace.default_package = package.as_ref().to_path_buf();
|
||||
}
|
||||
}
|
||||
|
||||
impl TryFrom<PathBuf> for Nest {
|
||||
type Error = crate::Error;
|
||||
|
||||
fn try_from(value: PathBuf) -> Result<Self, Self::Error> {
|
||||
let f = OpenOptions::new().read(true).open(value)?;
|
||||
Self::try_from(f)
|
||||
}
|
||||
}
|
||||
|
||||
impl TryFrom<File> for Nest {
|
||||
type Error = crate::Error;
|
||||
|
||||
fn try_from(mut value: File) -> Result<Self, Self::Error> {
|
||||
let mut buf = String::new();
|
||||
value.read_to_string(&mut buf)?;
|
||||
Ok(toml::from_str(buf.as_str())?)
|
||||
}
|
||||
}
|
||||
|
||||
/// Data struct
|
||||
#[derive(Debug, Clone, Default, Deserialize, Serialize, PartialEq, Eq)]
|
||||
pub struct NestLock {
|
||||
pub dependencies: Vec<Dependency>,
|
||||
}
|
||||
|
||||
impl NestLock {
|
||||
pub fn write<P: AsRef<Path>>(&self, path: P) -> crate::Result<()> {
|
||||
Ok(OpenOptions::new()
|
||||
.write(true)
|
||||
.create(true)
|
||||
.open(path)?
|
||||
.write_all(toml::to_string_pretty(&self)?.as_bytes())?)
|
||||
}
|
||||
}
|
||||
|
||||
impl TryFrom<PathBuf> for NestLock {
|
||||
type Error = crate::Error;
|
||||
|
||||
fn try_from(value: PathBuf) -> Result<Self, Self::Error> {
|
||||
let f = OpenOptions::new().read(true).open(value)?;
|
||||
Self::try_from(f)
|
||||
}
|
||||
}
|
||||
|
||||
impl TryFrom<File> for NestLock {
|
||||
type Error = crate::Error;
|
||||
|
||||
fn try_from(mut value: File) -> Result<Self, Self::Error> {
|
||||
let mut buf = String::new();
|
||||
value.read_to_string(&mut buf)?;
|
||||
Ok(toml::from_str(buf.as_str())?)
|
||||
}
|
||||
}
|
||||
56
crates/core/src/package.rs
Normal file
56
crates/core/src/package.rs
Normal file
@@ -0,0 +1,56 @@
|
||||
use std::hash::Hash;
|
||||
use std::path::{Path, PathBuf};
|
||||
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
use crate::prey::{F_PREY_LOCK, F_PREY_TOML, Prey, PreyLock};
|
||||
|
||||
/// Hashing is only based off the Prey.
|
||||
#[derive(Debug, Clone, PartialEq, Eq)]
|
||||
pub struct PackageHandler {
|
||||
prey: Prey,
|
||||
prey_lock: Option<PreyLock>,
|
||||
package_root: PathBuf,
|
||||
target_dir: PathBuf,
|
||||
}
|
||||
|
||||
impl PackageHandler {
|
||||
pub fn new<P: AsRef<Path>>(package_root: P, target_dir: P) -> crate::Result<Self> {
|
||||
let package_root = package_root.as_ref().to_path_buf();
|
||||
|
||||
Ok(Self {
|
||||
prey: Prey::try_from(package_root.join(F_PREY_TOML))?,
|
||||
prey_lock: PreyLock::try_from(package_root.join(F_PREY_LOCK)).ok(),
|
||||
package_root,
|
||||
target_dir: target_dir.as_ref().to_path_buf(),
|
||||
})
|
||||
}
|
||||
|
||||
pub fn update_class_cache(&self) {}
|
||||
|
||||
pub fn entry_point(&self) -> PathBuf {
|
||||
self.prey.entry_point()
|
||||
}
|
||||
|
||||
pub fn name(&self) -> String {
|
||||
self.prey.name()
|
||||
}
|
||||
|
||||
pub fn version(&self) -> semver::Version {
|
||||
self.prey.version()
|
||||
}
|
||||
}
|
||||
|
||||
impl Hash for PackageHandler {
|
||||
fn hash<H: std::hash::Hasher>(&self, state: &mut H) {
|
||||
self.prey.hash(state);
|
||||
}
|
||||
}
|
||||
|
||||
/// Data struct
|
||||
#[derive(Debug, Clone, Deserialize, Serialize, Hash, PartialEq, Eq, PartialOrd, Ord)]
|
||||
pub struct Package {
|
||||
pub entry_point: PathBuf,
|
||||
}
|
||||
|
||||
//impl Into<Dependency> for Package {}
|
||||
9
crates/core/src/prelude.rs
Normal file
9
crates/core/src/prelude.rs
Normal file
@@ -0,0 +1,9 @@
|
||||
#![allow(unused_imports)]
|
||||
|
||||
pub use crate::class::Class;
|
||||
pub use crate::dependency::Dependency;
|
||||
pub use crate::meta::Meta;
|
||||
pub use crate::nest::{F_NEST_LOCK, F_NEST_TOML, Nest, NestLock};
|
||||
pub use crate::package::{Package, PackageHandler};
|
||||
pub use crate::prey::{F_PREY_LOCK, F_PREY_TOML, Prey, PreyLock};
|
||||
pub use crate::workspace::{Workspace, WorkspaceHandler};
|
||||
78
crates/core/src/prey.rs
Normal file
78
crates/core/src/prey.rs
Normal file
@@ -0,0 +1,78 @@
|
||||
use std::collections::HashSet;
|
||||
use std::fs::{File, OpenOptions};
|
||||
use std::io::Read;
|
||||
use std::path::PathBuf;
|
||||
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
use crate::class::Class;
|
||||
use crate::meta::Meta;
|
||||
use crate::package::Package;
|
||||
|
||||
pub const F_PREY_TOML: &str = "Prey.toml";
|
||||
pub const F_PREY_LOCK: &str = "Prey.lock";
|
||||
|
||||
/// Data struct
|
||||
#[derive(Debug, Clone, Deserialize, Serialize, Hash, PartialEq, Eq)]
|
||||
pub struct Prey {
|
||||
package: Package,
|
||||
meta: Meta,
|
||||
}
|
||||
|
||||
impl Prey {
|
||||
pub fn entry_point(&self) -> PathBuf {
|
||||
self.package.entry_point.clone()
|
||||
}
|
||||
|
||||
pub fn name(&self) -> String {
|
||||
self.meta.name.clone()
|
||||
}
|
||||
|
||||
pub fn version(&self) -> semver::Version {
|
||||
self.meta.version.clone()
|
||||
}
|
||||
}
|
||||
|
||||
impl TryFrom<PathBuf> for Prey {
|
||||
type Error = crate::Error;
|
||||
|
||||
fn try_from(value: PathBuf) -> Result<Self, Self::Error> {
|
||||
let f = OpenOptions::new().read(true).open(value)?;
|
||||
Self::try_from(f)
|
||||
}
|
||||
}
|
||||
|
||||
impl TryFrom<File> for Prey {
|
||||
type Error = crate::Error;
|
||||
|
||||
fn try_from(mut value: File) -> Result<Self, Self::Error> {
|
||||
let mut buf = String::new();
|
||||
value.read_to_string(&mut buf)?;
|
||||
Ok(toml::from_str(buf.as_str())?)
|
||||
}
|
||||
}
|
||||
|
||||
/// Data struct
|
||||
#[derive(Debug, Clone, Deserialize, Serialize, PartialEq, Eq)]
|
||||
pub struct PreyLock {
|
||||
classes: HashSet<Class>,
|
||||
}
|
||||
|
||||
impl TryFrom<PathBuf> for PreyLock {
|
||||
type Error = crate::Error;
|
||||
|
||||
fn try_from(value: PathBuf) -> Result<Self, Self::Error> {
|
||||
let f = OpenOptions::new().read(true).open(value)?;
|
||||
Self::try_from(f)
|
||||
}
|
||||
}
|
||||
|
||||
impl TryFrom<File> for PreyLock {
|
||||
type Error = crate::Error;
|
||||
|
||||
fn try_from(mut value: File) -> Result<Self, Self::Error> {
|
||||
let mut buf = String::new();
|
||||
value.read_to_string(&mut buf)?;
|
||||
Ok(toml::from_str(buf.as_str())?)
|
||||
}
|
||||
}
|
||||
272
crates/core/src/workspace.rs
Normal file
272
crates/core/src/workspace.rs
Normal file
@@ -0,0 +1,272 @@
|
||||
use std::collections::HashMap;
|
||||
use std::fs::{OpenOptions, read_dir};
|
||||
use std::io::{Read, Write};
|
||||
use std::path::{Path, PathBuf};
|
||||
|
||||
use fs::{self, expand_files};
|
||||
use io::run_process;
|
||||
use java::{self, JAVA_EXT_CLASS, JAVA_EXT_SOURCE};
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
use crate::Error;
|
||||
use crate::dependency::Dependency;
|
||||
use crate::nest::{F_NEST_LOCK, F_NEST_TOML, Nest, NestLock};
|
||||
use crate::package::PackageHandler;
|
||||
use crate::prey::F_PREY_TOML;
|
||||
|
||||
pub struct WorkspaceHandler {
|
||||
nest: Nest,
|
||||
nest_lock: Option<NestLock>,
|
||||
project_root: PathBuf,
|
||||
packages: HashMap<PathBuf, PackageHandler>,
|
||||
}
|
||||
|
||||
impl WorkspaceHandler {
|
||||
const DIR_SRC: &str = "src/";
|
||||
const DIR_TARGET: &str = "target/";
|
||||
|
||||
pub fn new<P: AsRef<Path>>(project_root: P) -> crate::Result<Self> {
|
||||
let project_root = project_root.as_ref().canonicalize()?;
|
||||
|
||||
Ok(Self {
|
||||
nest: Nest::new(
|
||||
project_root
|
||||
.file_name()
|
||||
.ok_or(Error::MissingFileName)?
|
||||
.display(),
|
||||
),
|
||||
nest_lock: None,
|
||||
packages: HashMap::new(),
|
||||
project_root,
|
||||
})
|
||||
}
|
||||
|
||||
pub fn load<P: AsRef<Path>>(project_root: P) -> crate::Result<Self> {
|
||||
let project_root = project_root.as_ref().canonicalize()?;
|
||||
|
||||
let mut workspace_manager = Self {
|
||||
nest: Nest::try_from(project_root.join(F_NEST_TOML))?,
|
||||
nest_lock: NestLock::try_from(project_root.join(F_NEST_LOCK)).ok(),
|
||||
packages: HashMap::new(),
|
||||
project_root,
|
||||
};
|
||||
|
||||
workspace_manager.discover_packages()?;
|
||||
|
||||
Ok(workspace_manager)
|
||||
}
|
||||
|
||||
pub fn write(&self) -> crate::Result<()> {
|
||||
self.nest.write(self.project_root.join(F_NEST_TOML))?;
|
||||
|
||||
if let Option::Some(lock) = self.nest_lock.clone() {
|
||||
lock.write(self.project_root.join(F_NEST_LOCK))?;
|
||||
}
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
//pub fn refresh_packages(&mut self) -> crate::Result<()> {}
|
||||
|
||||
/*
|
||||
/// Future `build` method.
|
||||
pub fn compile(&self, target: Option<PathBuf>) -> crate::Result<()> {
|
||||
let mut target = target.unwrap_or(self.nest.default_package());
|
||||
if !target.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.
|
||||
target = target.join(
|
||||
self.packages
|
||||
.get(&target)
|
||||
.ok_or(Error::UnknownPackage)?
|
||||
.entry_point(),
|
||||
);
|
||||
}
|
||||
|
||||
//java::Compiler::new();
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn make_compiler_job<P: AsRef<Path>>(target: P) {
|
||||
// Generate dependency tree.
|
||||
}
|
||||
*/
|
||||
|
||||
pub fn init(&mut self) -> crate::Result<()> {
|
||||
let is_empty = read_dir(self.project_root.as_path()).is_ok_and(|tree| tree.count() == 0);
|
||||
|
||||
// ORDER MATTERS. THIS MUST COME FIRST.
|
||||
// Make config file.
|
||||
self.write_nest()?;
|
||||
|
||||
// Make .java-version
|
||||
self.write_java_version()?;
|
||||
|
||||
// Make src/, target/, test/
|
||||
self.write_dir_tree()?;
|
||||
|
||||
if !is_empty {
|
||||
self.write_example_project()?;
|
||||
self.discover_packages()?;
|
||||
|
||||
run_process(&["git", "init", "."])?;
|
||||
}
|
||||
|
||||
// Append to .gitignore
|
||||
if let Result::Ok(mut f) = OpenOptions::new()
|
||||
.append(true)
|
||||
.create(true)
|
||||
.read(true)
|
||||
.open(".gitignore")
|
||||
{
|
||||
let mut buf = String::new();
|
||||
f.read_to_string(&mut buf)?;
|
||||
|
||||
for ignored in [
|
||||
"# Automatically added by Raven".to_string(),
|
||||
Self::DIR_TARGET.to_string(),
|
||||
format!("*.{}", JAVA_EXT_CLASS),
|
||||
] {
|
||||
if !buf.contains(&ignored) {
|
||||
f.write(format!("{}\n", ignored).as_bytes())?;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
// This is the naive build
|
||||
pub fn build(&mut self) -> crate::Result<()> {
|
||||
Ok(())
|
||||
}
|
||||
|
||||
/// Add any newly created packages.
|
||||
fn discover_packages(&mut self) -> crate::Result<()> {
|
||||
// Scan the src/ directory for entries,
|
||||
// filter out the files,
|
||||
// then construct PackageManagers for each package
|
||||
|
||||
// Promote *not* using reverse domain name tree structures
|
||||
// by improving the speed of package discovery by using read_dir
|
||||
// and checking for an immediate Prey.toml before expanding the
|
||||
// whole subtree.
|
||||
//
|
||||
// Yes, I know this looks like shit.
|
||||
// That's because it is.
|
||||
|
||||
for file in read_dir(Self::DIR_SRC)?
|
||||
// Get directories
|
||||
.filter_map(|entry| {
|
||||
if entry.as_ref().is_ok_and(|entry| entry.path().is_dir()) {
|
||||
Some(entry.unwrap().path())
|
||||
} else {
|
||||
None
|
||||
}
|
||||
})
|
||||
// Get Prey.toml files
|
||||
.filter_map(|dir| {
|
||||
Some(if dir.join(F_PREY_TOML).exists() {
|
||||
vec![dir.join(F_PREY_TOML)]
|
||||
} else {
|
||||
expand_files(dir)
|
||||
.ok()?
|
||||
.iter()
|
||||
.filter_map(|file| {
|
||||
if file.ends_with(PathBuf::from(F_PREY_TOML)) {
|
||||
Some(file.to_owned())
|
||||
} else {
|
||||
None
|
||||
}
|
||||
})
|
||||
.collect()
|
||||
})
|
||||
})
|
||||
.flatten()
|
||||
{
|
||||
let package_root =
|
||||
pathsub::sub_paths(file.as_path(), PathBuf::from(Self::DIR_SRC).as_path()).unwrap();
|
||||
|
||||
self.packages.insert(
|
||||
package_root.to_path_buf(),
|
||||
PackageHandler::new(package_root, PathBuf::from(Self::DIR_TARGET))?,
|
||||
);
|
||||
}
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
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(())
|
||||
}
|
||||
|
||||
fn write_java_version(&self) -> crate::Result<()> {
|
||||
if let Result::Ok(mut f) = OpenOptions::new()
|
||||
.write(true)
|
||||
.create_new(true)
|
||||
.open(java::F_JAVA_VERSION)
|
||||
{
|
||||
f.write_all(format!("{}\n", java::get_javac_ver()?.major.to_string()).as_bytes())?;
|
||||
}
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn write_dir_tree(&self) -> std::io::Result<()> {
|
||||
for dir in [
|
||||
format!("{}main/java", Self::DIR_SRC),
|
||||
format!("{}test/java", Self::DIR_SRC),
|
||||
Self::DIR_TARGET.to_string(),
|
||||
] {
|
||||
std::fs::create_dir_all(std::env::current_dir()?.join(dir))?;
|
||||
}
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn write_example_project(&self) -> std::io::Result<()> {
|
||||
// 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),
|
||||
) {
|
||||
f.write_all(include_bytes!("../assets/Main.java"))?;
|
||||
}
|
||||
|
||||
// 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),
|
||||
) {
|
||||
f.write_all(include_bytes!("../assets/MainTest.java"))?;
|
||||
}
|
||||
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
/// Data struct
|
||||
#[derive(Debug, Clone, Deserialize, Serialize, Hash, PartialEq, Eq, PartialOrd, Ord)]
|
||||
pub struct Workspace {
|
||||
pub default_package: PathBuf,
|
||||
}
|
||||
|
||||
impl Default for Workspace {
|
||||
fn default() -> Self {
|
||||
Workspace {
|
||||
default_package: PathBuf::from("main"),
|
||||
}
|
||||
}
|
||||
}
|
||||
14
crates/fs/Cargo.toml
Normal file
14
crates/fs/Cargo.toml
Normal file
@@ -0,0 +1,14 @@
|
||||
[package]
|
||||
name = "fs"
|
||||
version = "0.1.0"
|
||||
edition.workspace = true
|
||||
license.workspace = true
|
||||
|
||||
description = "Raven's FS utilities"
|
||||
repository.workspace = true
|
||||
|
||||
publish.workspace = true
|
||||
test.workspace = true
|
||||
|
||||
[dependencies]
|
||||
derive_more.workspace = true
|
||||
24
crates/fs/src/lib.rs
Normal file
24
crates/fs/src/lib.rs
Normal file
@@ -0,0 +1,24 @@
|
||||
use std::path::{Path, PathBuf};
|
||||
|
||||
pub const EXT_TOML: &str = ".toml";
|
||||
pub const EXT_LOCK: &str = ".lock";
|
||||
|
||||
pub fn expand_files<P: AsRef<Path>>(path: P) -> std::io::Result<Vec<PathBuf>> {
|
||||
let path = path.as_ref();
|
||||
|
||||
if path.is_file() {
|
||||
return Ok(vec![path.to_path_buf()]);
|
||||
}
|
||||
|
||||
Ok(std::fs::read_dir(path)?
|
||||
.filter_map(|entry| {
|
||||
let path = entry.ok()?.path();
|
||||
if path.is_dir() {
|
||||
Some(expand_files(path).ok()?)
|
||||
} else {
|
||||
Some(vec![path])
|
||||
}
|
||||
})
|
||||
.flatten()
|
||||
.collect())
|
||||
}
|
||||
15
crates/io/Cargo.toml
Normal file
15
crates/io/Cargo.toml
Normal file
@@ -0,0 +1,15 @@
|
||||
[package]
|
||||
name = "io"
|
||||
version = "0.1.0"
|
||||
edition.workspace = true
|
||||
license.workspace = true
|
||||
|
||||
description = "Raven's IO utilities"
|
||||
repository.workspace = true
|
||||
|
||||
publish.workspace = true
|
||||
test.workspace = true
|
||||
|
||||
[dependencies]
|
||||
derive_more.workspace = true
|
||||
subprocess.workspace = true
|
||||
11
crates/io/src/error.rs
Normal file
11
crates/io/src/error.rs
Normal file
@@ -0,0 +1,11 @@
|
||||
use derive_more::{Display, From};
|
||||
|
||||
pub type Result<T> = core::result::Result<T, Error>;
|
||||
|
||||
#[derive(Debug, From, Display)]
|
||||
pub enum Error {
|
||||
#[from]
|
||||
Io(std::io::Error),
|
||||
#[from]
|
||||
Popen(subprocess::PopenError),
|
||||
}
|
||||
30
crates/io/src/lib.rs
Normal file
30
crates/io/src/lib.rs
Normal file
@@ -0,0 +1,30 @@
|
||||
mod error;
|
||||
|
||||
use std::ffi;
|
||||
|
||||
pub use error::{Error, Result};
|
||||
|
||||
pub fn run_process<S>(argv: &[S]) -> Result<(Option<String>, Option<String>)>
|
||||
where
|
||||
S: AsRef<ffi::OsStr>,
|
||||
{
|
||||
let mut process = subprocess::Popen::create(
|
||||
argv,
|
||||
subprocess::PopenConfig {
|
||||
stdout: subprocess::Redirection::Pipe,
|
||||
..Default::default()
|
||||
},
|
||||
)?;
|
||||
|
||||
let result = process.communicate(None)?;
|
||||
|
||||
if process
|
||||
.wait_timeout(std::time::Duration::from_secs(5))
|
||||
.is_err()
|
||||
|| process.exit_status().is_none()
|
||||
{
|
||||
process.terminate()?;
|
||||
}
|
||||
|
||||
Ok(result)
|
||||
}
|
||||
21
crates/java/Cargo.toml
Normal file
21
crates/java/Cargo.toml
Normal file
@@ -0,0 +1,21 @@
|
||||
# May want to find a better name, more reflective of the JDK part
|
||||
# than the entire Java language.
|
||||
|
||||
[package]
|
||||
name = "java"
|
||||
version = "0.1.0"
|
||||
edition.workspace = true
|
||||
license.workspace = true
|
||||
|
||||
description = "Tools for interfacing with the Java Development Kit"
|
||||
repository.workspace = true
|
||||
|
||||
publish.workspace = true
|
||||
test.workspace = true
|
||||
|
||||
[dependencies]
|
||||
bytesize.workspace = true
|
||||
derive_more.workspace = true
|
||||
fs.workspace = true
|
||||
io.workspace = true
|
||||
semver.workspace = true
|
||||
80
crates/java/src/compiler.rs
Normal file
80
crates/java/src/compiler.rs
Normal file
@@ -0,0 +1,80 @@
|
||||
use std::path::{Path, PathBuf};
|
||||
|
||||
use crate::JAVA_BIN_COMPILER;
|
||||
use crate::Result;
|
||||
|
||||
#[derive(Debug, Default, Clone)]
|
||||
pub struct CompilerBuilder {
|
||||
class_path: Option<PathBuf>,
|
||||
destination: Option<PathBuf>,
|
||||
}
|
||||
|
||||
impl CompilerBuilder {
|
||||
pub fn new() -> Self {
|
||||
Self::default()
|
||||
}
|
||||
|
||||
pub fn class_path<S: AsRef<Path>>(&mut self, class_path: S) -> &mut Self {
|
||||
self.class_path = Some(class_path.as_ref().to_path_buf());
|
||||
self
|
||||
}
|
||||
|
||||
pub fn destination<S: AsRef<Path>>(&mut self, destination: S) -> &mut Self {
|
||||
self.destination = Some(destination.as_ref().to_path_buf());
|
||||
self
|
||||
}
|
||||
|
||||
pub fn build(&self) -> Compiler {
|
||||
let mut flags = vec![];
|
||||
|
||||
if let Option::Some(path) = self.destination.to_owned() {
|
||||
flags.push(CompilerFlag::Destination { path });
|
||||
}
|
||||
|
||||
if let Option::Some(path) = self.class_path.to_owned() {
|
||||
flags.push(CompilerFlag::Classpath { path });
|
||||
}
|
||||
|
||||
Compiler { flags }
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone)]
|
||||
pub struct Compiler {
|
||||
flags: Vec<CompilerFlag>,
|
||||
}
|
||||
|
||||
impl Compiler {
|
||||
pub fn compile<P: AsRef<Path>>(self, path: P) -> Result<(Option<String>, Option<String>)> {
|
||||
let mut cmd: Vec<String> = vec![JAVA_BIN_COMPILER.to_string()];
|
||||
|
||||
cmd.extend(
|
||||
self.flags
|
||||
.clone()
|
||||
.into_iter()
|
||||
.flat_map(|f| Into::<Vec<String>>::into(f)),
|
||||
);
|
||||
cmd.extend(
|
||||
fs::expand_files(path)?
|
||||
.into_iter()
|
||||
.filter_map(|f| Some(f.to_str()?.to_string())),
|
||||
);
|
||||
|
||||
Ok(io::run_process(cmd.as_slice())?)
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone)]
|
||||
pub enum CompilerFlag {
|
||||
Classpath { path: PathBuf },
|
||||
Destination { path: PathBuf },
|
||||
}
|
||||
|
||||
impl Into<Vec<String>> for CompilerFlag {
|
||||
fn into(self) -> Vec<String> {
|
||||
match self {
|
||||
Self::Classpath { path } => vec!["-classpath".to_string(), path.display().to_string()],
|
||||
Self::Destination { path } => vec!["-d".to_string(), path.display().to_string()],
|
||||
}
|
||||
}
|
||||
}
|
||||
19
crates/java/src/error.rs
Normal file
19
crates/java/src/error.rs
Normal file
@@ -0,0 +1,19 @@
|
||||
use derive_more::{Display, From};
|
||||
|
||||
pub type Result<T> = core::result::Result<T, Error>;
|
||||
|
||||
#[derive(Debug, From, Display)]
|
||||
pub enum Error {
|
||||
EmptyStdout,
|
||||
|
||||
#[from]
|
||||
Io(io::Error),
|
||||
|
||||
NthOutOfBounds,
|
||||
|
||||
#[from]
|
||||
Semver(semver::Error),
|
||||
|
||||
#[from]
|
||||
StdIo(std::io::Error),
|
||||
}
|
||||
49
crates/java/src/lib.rs
Normal file
49
crates/java/src/lib.rs
Normal file
@@ -0,0 +1,49 @@
|
||||
pub mod compiler;
|
||||
pub mod error;
|
||||
pub mod runtime;
|
||||
|
||||
use std::str::FromStr;
|
||||
|
||||
pub use error::{Error, Result};
|
||||
use runtime::VMFlag;
|
||||
|
||||
pub const JAVA_BIN_VM: &str = "java";
|
||||
pub const JAVA_BIN_COMPILER: &str = "javac";
|
||||
|
||||
pub const JAVA_EXT_SOURCE: &str = "java";
|
||||
pub const JAVA_EXT_CLASS: &str = "class";
|
||||
|
||||
pub const F_JAVA_VERSION: &str = ".java-version";
|
||||
|
||||
/// Uses the java binary to parse its stdout for version information.
|
||||
///
|
||||
/// This is non-caching.
|
||||
pub fn get_javac_ver() -> Result<semver::Version> {
|
||||
// TODO: Consider making this pull the version info from javac instead?
|
||||
|
||||
/*
|
||||
* $ java --version
|
||||
* openjdk 21.0.9 2025-10-21
|
||||
* OpenJDK Runtime Environment (build 21.0.9+10)
|
||||
* OpenJDK 64-Bit Server VM (build 21.0.9+10, mixed mode, sharing)
|
||||
*/
|
||||
|
||||
Ok(semver::Version::from_str(
|
||||
get_java_version_info()?
|
||||
.lines()
|
||||
.nth(0)
|
||||
.ok_or(Error::EmptyStdout)?
|
||||
.split_ascii_whitespace()
|
||||
.nth(1)
|
||||
.ok_or(Error::NthOutOfBounds)?,
|
||||
)?)
|
||||
}
|
||||
|
||||
/// Calls the java binary, returning the complete stdout version information.
|
||||
fn get_java_version_info() -> Result<String> {
|
||||
Ok(
|
||||
io::run_process(&[JAVA_BIN_VM, VMFlag::Version.to_string().as_str()])?
|
||||
.0
|
||||
.ok_or(Error::EmptyStdout)?,
|
||||
)
|
||||
}
|
||||
144
crates/java/src/runtime.rs
Normal file
144
crates/java/src/runtime.rs
Normal file
@@ -0,0 +1,144 @@
|
||||
use std::fmt;
|
||||
use std::path::{Path, PathBuf};
|
||||
|
||||
use crate::JAVA_BIN_VM;
|
||||
use crate::Result;
|
||||
|
||||
use bytesize::ByteSize;
|
||||
|
||||
#[derive(Debug, Default, Clone)]
|
||||
pub struct JVMBuilder {
|
||||
assertions: bool,
|
||||
monitor: bool,
|
||||
ram_min: Option<ByteSize>,
|
||||
ram_max: Option<ByteSize>,
|
||||
class_path: PathBuf,
|
||||
}
|
||||
|
||||
impl JVMBuilder {
|
||||
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 {
|
||||
self.assertions = assertions;
|
||||
self
|
||||
}
|
||||
|
||||
pub fn ram_min(&mut self, ram_min: ByteSize) -> &mut Self {
|
||||
self.ram_min = Some(ram_min);
|
||||
self
|
||||
}
|
||||
|
||||
pub fn ram_max(&mut self, ram_max: ByteSize) -> &mut Self {
|
||||
self.ram_max = Some(ram_max);
|
||||
self
|
||||
}
|
||||
|
||||
/// Monitor stdout and stderr in raven's process.
|
||||
pub fn monitor(&mut self, monitor: bool) -> &mut Self {
|
||||
self.monitor = monitor;
|
||||
self
|
||||
}
|
||||
|
||||
pub fn build(&self) -> JVM {
|
||||
let mut flags = vec![VMFlag::Classpath {
|
||||
path: self.class_path.to_owned(),
|
||||
}];
|
||||
|
||||
if self.assertions {
|
||||
flags.push(VMFlag::EnableAssert);
|
||||
}
|
||||
|
||||
if let Option::Some(size) = self.ram_min {
|
||||
flags.push(VMFlag::HeapMin { size });
|
||||
}
|
||||
|
||||
if let Option::Some(size) = self.ram_max {
|
||||
flags.push(VMFlag::HeapMax { size });
|
||||
}
|
||||
|
||||
JVM {
|
||||
monitor: self.monitor,
|
||||
flags,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub struct JVM {
|
||||
monitor: bool,
|
||||
flags: Vec<VMFlag>,
|
||||
}
|
||||
|
||||
impl JVM {
|
||||
pub fn run<P: AsRef<Path>>(self, entry_point: P) -> Result<(Option<String>, Option<String>)> {
|
||||
let mut cmd = vec![JAVA_BIN_VM.to_string()];
|
||||
|
||||
cmd.extend(
|
||||
self.flags
|
||||
.clone()
|
||||
.into_iter()
|
||||
.flat_map(|f| Into::<Vec<String>>::into(f)),
|
||||
);
|
||||
|
||||
cmd.push(entry_point.as_ref().to_path_buf().display().to_string());
|
||||
|
||||
let result = io::run_process(cmd.as_slice())?;
|
||||
|
||||
if self.monitor {
|
||||
let (stdout, stderr) = &result;
|
||||
|
||||
if let Option::Some(stdout) = stdout
|
||||
&& stdout.len() > 0
|
||||
{
|
||||
print!("{stdout}");
|
||||
}
|
||||
if let Option::Some(stderr) = stderr
|
||||
&& stderr.len() > 0
|
||||
{
|
||||
eprintln!("{stderr}");
|
||||
}
|
||||
}
|
||||
|
||||
Ok(result)
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone)]
|
||||
pub enum VMFlag {
|
||||
Classpath { path: PathBuf },
|
||||
EnableAssert,
|
||||
HeapMax { size: ByteSize },
|
||||
HeapMin { size: ByteSize },
|
||||
Version,
|
||||
}
|
||||
|
||||
impl Into<Vec<String>> for VMFlag {
|
||||
fn into(self) -> Vec<String> {
|
||||
self.to_string()
|
||||
.split_ascii_whitespace()
|
||||
.map(|s| s.to_string())
|
||||
.collect()
|
||||
}
|
||||
}
|
||||
|
||||
// Currently being kept around because it's fine for the current branches,
|
||||
// and is currently serving a to_string() method for the Java version fetch.
|
||||
impl fmt::Display for VMFlag {
|
||||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||
write!(
|
||||
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()),
|
||||
Self::Version => String::from("-version"), // --version
|
||||
}
|
||||
)
|
||||
}
|
||||
}
|
||||
14
crates/path/Cargo.toml
Normal file
14
crates/path/Cargo.toml
Normal file
@@ -0,0 +1,14 @@
|
||||
[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
|
||||
151
crates/path/src/lib.rs
Normal file
151
crates/path/src/lib.rs
Normal file
@@ -0,0 +1,151 @@
|
||||
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));
|
||||
}
|
||||
}
|
||||
18
crates/pom/Cargo.toml
Normal file
18
crates/pom/Cargo.toml
Normal file
@@ -0,0 +1,18 @@
|
||||
[package]
|
||||
name = "pom"
|
||||
version = "0.1.0"
|
||||
edition.workspace = true
|
||||
license.workspace = true
|
||||
|
||||
description = "Library for serializing and deserializing Maven's POM"
|
||||
repository.workspace = true
|
||||
|
||||
publish.workspace = true
|
||||
test.workspace = true
|
||||
|
||||
[dependencies]
|
||||
derive_more.workspace = true
|
||||
hard-xml.workspace = true
|
||||
serde.workspace = true
|
||||
semver.workspace = true
|
||||
strum.workspace = true
|
||||
12
crates/pom/src/error.rs
Normal file
12
crates/pom/src/error.rs
Normal file
@@ -0,0 +1,12 @@
|
||||
use derive_more::{Display, From};
|
||||
|
||||
pub type Result<T> = core::result::Result<T, Error>;
|
||||
|
||||
#[derive(Debug, From, Display)]
|
||||
pub enum Error {
|
||||
#[from]
|
||||
Io(std::io::Error),
|
||||
|
||||
#[from]
|
||||
Xml(hard_xml::XmlError),
|
||||
}
|
||||
25
crates/pom/src/lib.rs
Normal file
25
crates/pom/src/lib.rs
Normal file
@@ -0,0 +1,25 @@
|
||||
pub mod error;
|
||||
pub mod xml;
|
||||
|
||||
pub use error::{Error, Result};
|
||||
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
#[derive(Debug, Clone, Deserialize, Serialize, PartialEq, Eq)]
|
||||
pub struct Pom {
|
||||
model_version: semver::Version,
|
||||
}
|
||||
|
||||
impl Pom {
|
||||
pub fn is_empty(&self) -> bool {
|
||||
self == &Self::default()
|
||||
}
|
||||
}
|
||||
|
||||
impl Default for Pom {
|
||||
fn default() -> Self {
|
||||
Self {
|
||||
model_version: semver::Version::new(4, 0, 0),
|
||||
}
|
||||
}
|
||||
}
|
||||
118
crates/pom/src/xml.rs
Normal file
118
crates/pom/src/xml.rs
Normal file
@@ -0,0 +1,118 @@
|
||||
use std::{fs::File, io::Read};
|
||||
|
||||
use crate::Error;
|
||||
|
||||
use hard_xml::{XmlRead, XmlWrite};
|
||||
use serde::{Deserialize, Serialize};
|
||||
use strum::EnumString;
|
||||
|
||||
// start with the super POM idiot.
|
||||
|
||||
#[derive(Debug, Clone, Deserialize, Serialize, XmlRead, XmlWrite)]
|
||||
#[xml(tag = "project")]
|
||||
pub struct Project {
|
||||
#[xml(attr = "xmlns")]
|
||||
xmlns: String,
|
||||
#[xml(attr = "xlmns:xsi")]
|
||||
xmlns_xsi: String,
|
||||
#[xml(attr = "xsi:schemaLocation")]
|
||||
xsi_schema_location: String,
|
||||
|
||||
#[xml(flatten_text = "modelVersion")]
|
||||
model_version: semver::Version,
|
||||
|
||||
#[xml(flatten_text = "groupId")]
|
||||
group_id: String,
|
||||
|
||||
#[xml(flatten_text = "artifactId")]
|
||||
artifact_id: String,
|
||||
|
||||
#[xml(flatten_text = "version")]
|
||||
version: String,
|
||||
|
||||
#[xml(flatten_text = "packaging")]
|
||||
packaging: String,
|
||||
|
||||
#[xml(child = "properties")]
|
||||
properties: Properties,
|
||||
|
||||
#[xml(child = "dependencyManagement")]
|
||||
dependency_management: DependencyManagement,
|
||||
|
||||
#[xml(child = "dependencies")]
|
||||
dependencies: Vec<Dependency>,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Deserialize, Serialize, XmlRead, XmlWrite)]
|
||||
#[xml(tag = "properties")]
|
||||
pub struct Properties {
|
||||
#[xml(flatten_text = "maven.compiler.source")]
|
||||
source: String,
|
||||
|
||||
#[xml(flatten_text = "maven.compiler.target")]
|
||||
target: String,
|
||||
// lwjgl.version
|
||||
// lwjgl.natives
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Deserialize, Serialize, XmlRead, XmlWrite)]
|
||||
#[xml(tag = "dependencyManagement")]
|
||||
pub struct DependencyManagement {
|
||||
#[xml(child = "dependencies")]
|
||||
dependencies: Vec<Dependency>,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Deserialize, Serialize, XmlRead, XmlWrite)]
|
||||
#[xml(tag = "dependency")]
|
||||
pub struct Dependency {
|
||||
#[xml(flatten_text = "groupId")]
|
||||
group_id: String,
|
||||
|
||||
#[xml(flatten_text = "artifactId")]
|
||||
artifact_id: String,
|
||||
|
||||
#[xml(flatten_text = "version")]
|
||||
version: semver::Version,
|
||||
|
||||
#[xml(flatten_text = "scope")]
|
||||
scope: String,
|
||||
|
||||
#[xml(flatten_text = "type")]
|
||||
type_: String,
|
||||
|
||||
#[xml(flatten_text = "optional")]
|
||||
optional: bool,
|
||||
|
||||
#[xml(child = "exclusions")]
|
||||
exclusions: Vec<Exclusion>,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Deserialize, Serialize, XmlRead, XmlWrite)]
|
||||
#[xml(tag = "exclusion")]
|
||||
pub struct Exclusion {
|
||||
#[xml(flatten_text = "groupId")]
|
||||
group_id: String,
|
||||
|
||||
#[xml(flatten_text = "artifactId")]
|
||||
artifact_id: String,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Copy, Default, Deserialize, Serialize, EnumString)]
|
||||
#[strum(serialize_all = "camelCase")]
|
||||
pub enum Packaging {
|
||||
#[default]
|
||||
Pom,
|
||||
Jar,
|
||||
}
|
||||
|
||||
impl TryFrom<File> for Project {
|
||||
type Error = Error;
|
||||
|
||||
fn try_from(value: File) -> Result<Self, Self::Error> {
|
||||
let mut value = value;
|
||||
let mut buf = String::new();
|
||||
value.read_to_string(&mut buf)?;
|
||||
|
||||
Ok(Project::from_str(&buf)?)
|
||||
}
|
||||
}
|
||||
671
crates/raven/Cargo.lock
generated
Normal file
671
crates/raven/Cargo.lock
generated
Normal file
@@ -0,0 +1,671 @@
|
||||
# This file is automatically @generated by Cargo.
|
||||
# It is not intended for manual editing.
|
||||
version = 4
|
||||
|
||||
[[package]]
|
||||
name = "anstream"
|
||||
version = "0.6.21"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "43d5b281e737544384e969a5ccad3f1cdd24b48086a0fc1b2a5262a26b8f4f4a"
|
||||
dependencies = [
|
||||
"anstyle",
|
||||
"anstyle-parse",
|
||||
"anstyle-query",
|
||||
"anstyle-wincon",
|
||||
"colorchoice",
|
||||
"is_terminal_polyfill",
|
||||
"utf8parse",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "anstyle"
|
||||
version = "1.0.13"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "5192cca8006f1fd4f7237516f40fa183bb07f8fbdfedaa0036de5ea9b0b45e78"
|
||||
|
||||
[[package]]
|
||||
name = "anstyle-parse"
|
||||
version = "0.2.7"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "4e7644824f0aa2c7b9384579234ef10eb7efb6a0deb83f9630a49594dd9c15c2"
|
||||
dependencies = [
|
||||
"utf8parse",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "anstyle-query"
|
||||
version = "1.1.5"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "40c48f72fd53cd289104fc64099abca73db4166ad86ea0b4341abe65af83dadc"
|
||||
dependencies = [
|
||||
"windows-sys",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "anstyle-wincon"
|
||||
version = "3.0.11"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "291e6a250ff86cd4a820112fb8898808a366d8f9f58ce16d1f538353ad55747d"
|
||||
dependencies = [
|
||||
"anstyle",
|
||||
"once_cell_polyfill",
|
||||
"windows-sys",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "anyhow"
|
||||
version = "1.0.100"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "a23eb6b1614318a8071c9b2521f36b424b2c83db5eb3a0fead4a6c0809af6e61"
|
||||
|
||||
[[package]]
|
||||
name = "async-trait"
|
||||
version = "0.1.89"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "9035ad2d096bed7955a320ee7e2230574d28fd3c3a0f186cbea1ff3c7eed5dbb"
|
||||
dependencies = [
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"syn 2.0.114",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "bitflags"
|
||||
version = "2.10.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "812e12b5285cc515a9c72a5c1d3b6d46a19dac5acfef5265968c166106e31dd3"
|
||||
dependencies = [
|
||||
"serde_core",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "block-buffer"
|
||||
version = "0.10.4"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "3078c7629b62d3f0439517fa394996acacc5cbc91c5a20d8c658e77abd503a71"
|
||||
dependencies = [
|
||||
"generic-array",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "bytes"
|
||||
version = "1.11.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "b35204fbdc0b3f4446b89fc1ac2cf84a8a68971995d0bf2e925ec7cd960f9cb3"
|
||||
|
||||
[[package]]
|
||||
name = "bytesize"
|
||||
version = "2.3.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "6bd91ee7b2422bcb158d90ef4d14f75ef67f340943fc4149891dcce8f8b972a3"
|
||||
|
||||
[[package]]
|
||||
name = "cfg-if"
|
||||
version = "1.0.4"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "9330f8b2ff13f34540b44e946ef35111825727b38d33286ef986142615121801"
|
||||
|
||||
[[package]]
|
||||
name = "clap"
|
||||
version = "4.5.54"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "c6e6ff9dcd79cff5cd969a17a545d79e84ab086e444102a591e288a8aa3ce394"
|
||||
dependencies = [
|
||||
"clap_builder",
|
||||
"clap_derive",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "clap_builder"
|
||||
version = "4.5.54"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "fa42cf4d2b7a41bc8f663a7cab4031ebafa1bf3875705bfaf8466dc60ab52c00"
|
||||
dependencies = [
|
||||
"anstream",
|
||||
"anstyle",
|
||||
"clap_lex",
|
||||
"strsim",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "clap_derive"
|
||||
version = "4.5.49"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "2a0b5487afeab2deb2ff4e03a807ad1a03ac532ff5a2cee5d86884440c7f7671"
|
||||
dependencies = [
|
||||
"heck",
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"syn 2.0.114",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "clap_lex"
|
||||
version = "0.7.7"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "c3e64b0cc0439b12df2fa678eae89a1c56a529fd067a9115f7827f1fffd22b32"
|
||||
|
||||
[[package]]
|
||||
name = "colorchoice"
|
||||
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 = "cpufeatures"
|
||||
version = "0.2.17"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "59ed5838eebb26a2bb2e58f6d5b5316989ae9d08bab10e0e6d103e656d1b0280"
|
||||
dependencies = [
|
||||
"libc",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "crypto-common"
|
||||
version = "0.1.7"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "78c8292055d1c1df0cce5d180393dc8cce0abec0a7102adb6c7b1eef6016d60a"
|
||||
dependencies = [
|
||||
"generic-array",
|
||||
"typenum",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "digest"
|
||||
version = "0.10.7"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "9ed9a281f7bc9b7576e61468ba615a66a5c8cfdff42420a70aa82701a3b1e292"
|
||||
dependencies = [
|
||||
"block-buffer",
|
||||
"crypto-common",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "equivalent"
|
||||
version = "1.0.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "877a4ace8713b0bcf2a4e7eec82529c029f1d0619886d18145fea96c3ffe5c0f"
|
||||
|
||||
[[package]]
|
||||
name = "generic-array"
|
||||
version = "0.14.7"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "85649ca51fd72272d7821adaf274ad91c288277713d9c18820d8499a7ff69e9a"
|
||||
dependencies = [
|
||||
"typenum",
|
||||
"version_check",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "hard-xml"
|
||||
version = "1.41.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "3b07b8ba970e18a03dbb79f6786b6e4d6f198a0ac839aa5182017001bb8dee17"
|
||||
dependencies = [
|
||||
"hard-xml-derive",
|
||||
"jetscii",
|
||||
"lazy_static",
|
||||
"memchr",
|
||||
"xmlparser",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "hard-xml-derive"
|
||||
version = "1.41.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "f0c43e7c3212bd992c11b6b9796563388170950521ae8487f5cdf6f6e792f1c8"
|
||||
dependencies = [
|
||||
"bitflags",
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"syn 1.0.109",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "hashbrown"
|
||||
version = "0.16.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "841d1cc9bed7f9236f321df977030373f4a4163ae1a7dbfe1a51a2c1a51d9100"
|
||||
|
||||
[[package]]
|
||||
name = "heck"
|
||||
version = "0.5.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "2304e00983f87ffb38b55b444b5e3b60a884b5d30c0fca7d82fe33449bbe55ea"
|
||||
|
||||
[[package]]
|
||||
name = "hex"
|
||||
version = "0.4.3"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "7f24254aa9a54b5c858eaee2f5bccdb46aaf0e486a595ed5fd8f86ba55232a70"
|
||||
|
||||
[[package]]
|
||||
name = "indexmap"
|
||||
version = "2.13.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "7714e70437a7dc3ac8eb7e6f8df75fd8eb422675fc7678aff7364301092b1017"
|
||||
dependencies = [
|
||||
"equivalent",
|
||||
"hashbrown",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "is_terminal_polyfill"
|
||||
version = "1.70.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "a6cb138bb79a146c1bd460005623e142ef0181e3d0219cb493e02f7d08a35695"
|
||||
|
||||
[[package]]
|
||||
name = "jetscii"
|
||||
version = "0.5.3"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "47f142fe24a9c9944451e8349de0a56af5f3e7226dc46f3ed4d4ecc0b85af75e"
|
||||
|
||||
[[package]]
|
||||
name = "lazy_static"
|
||||
version = "1.5.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "bbd2bcb4c963f2ddae06a2efc7e9f3591312473c50c6685e1f298068316e66fe"
|
||||
|
||||
[[package]]
|
||||
name = "lenient_semver"
|
||||
version = "0.4.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "de8de3f4f3754c280ce1c8c42ed8dd26a9c8385c2e5ad4ec5a77e774cea9c1ec"
|
||||
dependencies = [
|
||||
"lenient_semver_parser",
|
||||
"semver",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "lenient_semver_parser"
|
||||
version = "0.4.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "7f650c1d024ddc26b4bb79c3076b30030f2cf2b18292af698c81f7337a64d7d6"
|
||||
dependencies = [
|
||||
"lenient_semver_version_builder",
|
||||
"semver",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "lenient_semver_version_builder"
|
||||
version = "0.4.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "9049f8ff49f75b946f95557148e70230499c8a642bf2d6528246afc7d0282d17"
|
||||
dependencies = [
|
||||
"semver",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "libc"
|
||||
version = "0.2.180"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "bcc35a38544a891a5f7c865aca548a982ccb3b8650a5b06d0fd33a10283c56fc"
|
||||
|
||||
[[package]]
|
||||
name = "memchr"
|
||||
version = "2.7.6"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "f52b00d39961fc5b2736ea853c9cc86238e165017a493d1d5c8eac6bdc4cc273"
|
||||
|
||||
[[package]]
|
||||
name = "once_cell"
|
||||
version = "1.21.3"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "42f5e15c9953c5e4ccceeb2e7382a716482c34515315f7b03532b8b4e8393d2d"
|
||||
|
||||
[[package]]
|
||||
name = "once_cell_polyfill"
|
||||
version = "1.70.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "384b8ab6d37215f3c5301a95a4accb5d64aa607f1fcb26a11b5303878451b4fe"
|
||||
|
||||
[[package]]
|
||||
name = "pathsub"
|
||||
version = "0.1.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "dadd38133bcbe43264410412c48614bab4ef899f0792ffc4530dc19ec000a970"
|
||||
|
||||
[[package]]
|
||||
name = "pin-project-lite"
|
||||
version = "0.2.16"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "3b3cff922bd51709b605d9ead9aa71031d81447142d828eb4a6eba76fe619f9b"
|
||||
|
||||
[[package]]
|
||||
name = "proc-macro2"
|
||||
version = "1.0.106"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "8fd00f0bb2e90d81d1044c2b32617f68fcb9fa3bb7640c23e9c748e53fb30934"
|
||||
dependencies = [
|
||||
"unicode-ident",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "quote"
|
||||
version = "1.0.43"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "dc74d9a594b72ae6656596548f56f667211f8a97b3d4c3d467150794690dc40a"
|
||||
dependencies = [
|
||||
"proc-macro2",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "raven"
|
||||
version = "0.1.0"
|
||||
dependencies = [
|
||||
"anyhow",
|
||||
"bytesize",
|
||||
"clap",
|
||||
"const_format",
|
||||
"hard-xml",
|
||||
"lenient_semver",
|
||||
"pathsub",
|
||||
"ron",
|
||||
"semver",
|
||||
"serde",
|
||||
"sha256",
|
||||
"strum",
|
||||
"subprocess",
|
||||
"toml",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "ron"
|
||||
version = "0.12.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "fd490c5b18261893f14449cbd28cb9c0b637aebf161cd77900bfdedaff21ec32"
|
||||
dependencies = [
|
||||
"bitflags",
|
||||
"once_cell",
|
||||
"serde",
|
||||
"serde_derive",
|
||||
"typeid",
|
||||
"unicode-ident",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "semver"
|
||||
version = "1.0.27"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "d767eb0aabc880b29956c35734170f26ed551a859dbd361d140cdbeca61ab1e2"
|
||||
dependencies = [
|
||||
"serde",
|
||||
"serde_core",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "serde"
|
||||
version = "1.0.228"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "9a8e94ea7f378bd32cbbd37198a4a91436180c5bb472411e48b5ec2e2124ae9e"
|
||||
dependencies = [
|
||||
"serde_core",
|
||||
"serde_derive",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "serde_core"
|
||||
version = "1.0.228"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "41d385c7d4ca58e59fc732af25c3983b67ac852c1a25000afe1175de458b67ad"
|
||||
dependencies = [
|
||||
"serde_derive",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "serde_derive"
|
||||
version = "1.0.228"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "d540f220d3187173da220f885ab66608367b6574e925011a9353e4badda91d79"
|
||||
dependencies = [
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"syn 2.0.114",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "serde_spanned"
|
||||
version = "1.0.4"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "f8bbf91e5a4d6315eee45e704372590b30e260ee83af6639d64557f51b067776"
|
||||
dependencies = [
|
||||
"serde_core",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "sha2"
|
||||
version = "0.10.9"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "a7507d819769d01a365ab707794a4084392c824f54a7a6a7862f8c3d0892b283"
|
||||
dependencies = [
|
||||
"cfg-if",
|
||||
"cpufeatures",
|
||||
"digest",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "sha256"
|
||||
version = "1.6.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "f880fc8562bdeb709793f00eb42a2ad0e672c4f883bbe59122b926eca935c8f6"
|
||||
dependencies = [
|
||||
"async-trait",
|
||||
"bytes",
|
||||
"hex",
|
||||
"sha2",
|
||||
"tokio",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "strsim"
|
||||
version = "0.11.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "7da8b5736845d9f2fcb837ea5d9e2628564b3b043a70948a3f0b778838c5fb4f"
|
||||
|
||||
[[package]]
|
||||
name = "strum"
|
||||
version = "0.27.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "af23d6f6c1a224baef9d3f61e287d2761385a5b88fdab4eb4c6f11aeb54c4bcf"
|
||||
dependencies = [
|
||||
"strum_macros",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "strum_macros"
|
||||
version = "0.27.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "7695ce3845ea4b33927c055a39dc438a45b059f7c1b3d91d38d10355fb8cbca7"
|
||||
dependencies = [
|
||||
"heck",
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"syn 2.0.114",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "subprocess"
|
||||
version = "0.2.13"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "f75238edb5be30a9ea3035b945eb9c319dde80e879411cdc9a8978e1ac822960"
|
||||
dependencies = [
|
||||
"libc",
|
||||
"winapi",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "syn"
|
||||
version = "1.0.109"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "72b64191b275b66ffe2469e8af2c1cfe3bafa67b529ead792a6d0160888b4237"
|
||||
dependencies = [
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"unicode-ident",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "syn"
|
||||
version = "2.0.114"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "d4d107df263a3013ef9b1879b0df87d706ff80f65a86ea879bd9c31f9b307c2a"
|
||||
dependencies = [
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"unicode-ident",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "tokio"
|
||||
version = "1.49.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "72a2903cd7736441aac9df9d7688bd0ce48edccaadf181c3b90be801e81d3d86"
|
||||
dependencies = [
|
||||
"bytes",
|
||||
"pin-project-lite",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "toml"
|
||||
version = "0.9.11+spec-1.1.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "f3afc9a848309fe1aaffaed6e1546a7a14de1f935dc9d89d32afd9a44bab7c46"
|
||||
dependencies = [
|
||||
"indexmap",
|
||||
"serde_core",
|
||||
"serde_spanned",
|
||||
"toml_datetime",
|
||||
"toml_parser",
|
||||
"toml_writer",
|
||||
"winnow",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "toml_datetime"
|
||||
version = "0.7.5+spec-1.1.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "92e1cfed4a3038bc5a127e35a2d360f145e1f4b971b551a2ba5fd7aedf7e1347"
|
||||
dependencies = [
|
||||
"serde_core",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "toml_parser"
|
||||
version = "1.0.6+spec-1.1.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "a3198b4b0a8e11f09dd03e133c0280504d0801269e9afa46362ffde1cbeebf44"
|
||||
dependencies = [
|
||||
"winnow",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "toml_writer"
|
||||
version = "1.0.6+spec-1.1.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "ab16f14aed21ee8bfd8ec22513f7287cd4a91aa92e44edfe2c17ddd004e92607"
|
||||
|
||||
[[package]]
|
||||
name = "typeid"
|
||||
version = "1.0.3"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "bc7d623258602320d5c55d1bc22793b57daff0ec7efc270ea7d55ce1d5f5471c"
|
||||
|
||||
[[package]]
|
||||
name = "typenum"
|
||||
version = "1.19.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "562d481066bde0658276a35467c4af00bdc6ee726305698a55b86e61d7ad82bb"
|
||||
|
||||
[[package]]
|
||||
name = "unicode-ident"
|
||||
version = "1.0.22"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "9312f7c4f6ff9069b165498234ce8be658059c6728633667c526e27dc2cf1df5"
|
||||
|
||||
[[package]]
|
||||
name = "unicode-xid"
|
||||
version = "0.2.6"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "ebc1c04c71510c7f702b52b7c350734c9ff1295c464a03335b00bb84fc54f853"
|
||||
|
||||
[[package]]
|
||||
name = "utf8parse"
|
||||
version = "0.2.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "06abde3611657adf66d383f00b093d7faecc7fa57071cce2578660c9f1010821"
|
||||
|
||||
[[package]]
|
||||
name = "version_check"
|
||||
version = "0.9.5"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "0b928f33d975fc6ad9f86c8f283853ad26bdd5b10b7f1542aa2fa15e2289105a"
|
||||
|
||||
[[package]]
|
||||
name = "winapi"
|
||||
version = "0.3.9"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "5c839a674fcd7a98952e593242ea400abe93992746761e38641405d28b00f419"
|
||||
dependencies = [
|
||||
"winapi-i686-pc-windows-gnu",
|
||||
"winapi-x86_64-pc-windows-gnu",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "winapi-i686-pc-windows-gnu"
|
||||
version = "0.4.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "ac3b87c63620426dd9b991e5ce0329eff545bccbbb34f3be09ff6fb6ab51b7b6"
|
||||
|
||||
[[package]]
|
||||
name = "winapi-x86_64-pc-windows-gnu"
|
||||
version = "0.4.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f"
|
||||
|
||||
[[package]]
|
||||
name = "windows-link"
|
||||
version = "0.2.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "f0805222e57f7521d6a62e36fa9163bc891acd422f971defe97d64e70d0a4fe5"
|
||||
|
||||
[[package]]
|
||||
name = "windows-sys"
|
||||
version = "0.61.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "ae137229bcbd6cdf0f7b80a31df61766145077ddf49416a728b02cb3921ff3fc"
|
||||
dependencies = [
|
||||
"windows-link",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "winnow"
|
||||
version = "0.7.14"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "5a5364e9d77fcdeeaa6062ced926ee3381faa2ee02d3eb83a5c27a8825540829"
|
||||
|
||||
[[package]]
|
||||
name = "xmlparser"
|
||||
version = "0.13.6"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "66fee0b777b0f5ac1c69bb06d361268faafa61cd4682ae064a171c16c433e9e4"
|
||||
24
crates/raven/Cargo.toml
Normal file
24
crates/raven/Cargo.toml
Normal file
@@ -0,0 +1,24 @@
|
||||
[package]
|
||||
name = "raven"
|
||||
version = "0.1.0"
|
||||
edition.workspace = true
|
||||
license.workspace = true
|
||||
|
||||
description = "A simple build tool for Java"
|
||||
keywords = ["java", "tool"]
|
||||
categories = ["development-tools::build-utils"]
|
||||
repository.workspace = true
|
||||
|
||||
publish.workspace = true
|
||||
test.workspace = true
|
||||
|
||||
[dependencies]
|
||||
anyhow.workspace = true
|
||||
bytesize.workspace = true
|
||||
cli.workspace = true
|
||||
core.workspace = true
|
||||
fs.workspace = true
|
||||
io.workspace = true
|
||||
java.workspace = true
|
||||
path.workspace = true
|
||||
toml.workspace = true
|
||||
19
crates/raven/src/env.rs
Normal file
19
crates/raven/src/env.rs
Normal file
@@ -0,0 +1,19 @@
|
||||
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.",
|
||||
)
|
||||
}
|
||||
98
crates/raven/src/main.rs
Normal file
98
crates/raven/src/main.rs
Normal file
@@ -0,0 +1,98 @@
|
||||
mod env;
|
||||
mod manager;
|
||||
|
||||
use std::fs::OpenOptions;
|
||||
use std::io::{Read, Write};
|
||||
use std::path::{Path, PathBuf};
|
||||
use std::sync::{Arc, Mutex};
|
||||
|
||||
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()?),
|
||||
};
|
||||
|
||||
// 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(),
|
||||
};
|
||||
|
||||
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)?;
|
||||
}
|
||||
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),
|
||||
}
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn new(project_name: String) -> anyhow::Result<()> {
|
||||
let cwd = std::env::current_dir()?.join(project_name);
|
||||
|
||||
std::fs::create_dir(&cwd)?;
|
||||
std::env::set_current_dir(&cwd)?;
|
||||
|
||||
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());
|
||||
}
|
||||
11
crates/raven/src/manager.rs
Normal file
11
crates/raven/src/manager.rs
Normal file
@@ -0,0 +1,11 @@
|
||||
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 }>
|
||||
}
|
||||
Reference in New Issue
Block a user