forked 6ad82c3339 and refactored to combine prey.toml with nest.toml. The WorkspaceHandler.discover_packages() function is very broken
This commit is contained in:
@@ -1,18 +1,18 @@
|
||||
use std::hash::Hash;
|
||||
use std::path::{Path, PathBuf};
|
||||
|
||||
use semver::Version;
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
use crate::class::Class;
|
||||
use crate::prey::{F_PREY_LOCK, F_PREY_TOML, Prey, PreyLock};
|
||||
use crate::nest::{F_NEST_LOCK, Nest, NestLock};
|
||||
|
||||
pub const DIR_JAVA: &str = "java/";
|
||||
|
||||
/// Hashing is only based off the Prey.
|
||||
#[derive(Debug, Clone, PartialEq, Eq)]
|
||||
#[derive(Debug, Clone)]
|
||||
pub struct PackageHandler {
|
||||
prey: Prey,
|
||||
prey_lock: PreyLock,
|
||||
prey: Nest,
|
||||
prey_lock: NestLock,
|
||||
/// Path relative to WORKSPACE/src
|
||||
package_root: PathBuf,
|
||||
target_dir: PathBuf,
|
||||
@@ -21,21 +21,21 @@ pub struct PackageHandler {
|
||||
impl PackageHandler {
|
||||
pub fn new<P: AsRef<Path>>(src_dir: P, package_root: P, target_dir: P) -> crate::Result<Self> {
|
||||
let package_root = src_dir.as_ref().join(package_root.as_ref());
|
||||
let prey_lock = if let Ok(prey_lock) = PreyLock::try_from(package_root.join(F_PREY_LOCK)) {
|
||||
let prey_lock = if let Ok(prey_lock) = NestLock::try_from(package_root.join(F_NEST_LOCK)) {
|
||||
prey_lock
|
||||
} else {
|
||||
PreyLock::new(package_root.clone(), package_root.join(DIR_JAVA))?
|
||||
NestLock::new(package_root.clone(), package_root.join(DIR_JAVA))?
|
||||
};
|
||||
|
||||
Ok(Self {
|
||||
prey: Prey::try_from(package_root.join(F_PREY_TOML))?,
|
||||
prey: Nest::try_from(package_root.join(F_NEST_LOCK))?,
|
||||
prey_lock,
|
||||
package_root,
|
||||
target_dir: target_dir.as_ref().to_path_buf(),
|
||||
})
|
||||
}
|
||||
|
||||
pub fn entry_point(&self) -> PathBuf {
|
||||
pub fn entry_point(&self) -> Option<PathBuf> {
|
||||
self.prey.entry_point()
|
||||
}
|
||||
|
||||
@@ -47,7 +47,7 @@ impl PackageHandler {
|
||||
self.prey.version()
|
||||
}
|
||||
|
||||
pub fn prey_lock(&mut self) -> &mut PreyLock {
|
||||
pub fn prey_lock(&mut self) -> &mut NestLock {
|
||||
&mut self.prey_lock
|
||||
}
|
||||
|
||||
@@ -70,16 +70,46 @@ impl PackageHandler {
|
||||
}
|
||||
}
|
||||
|
||||
impl Hash for PackageHandler {
|
||||
fn hash<H: std::hash::Hasher>(&self, state: &mut H) {
|
||||
self.prey.hash(state);
|
||||
}
|
||||
}
|
||||
// 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,
|
||||
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>,
|
||||
pub entry_point: Option<PathBuf>,
|
||||
}
|
||||
|
||||
//impl Into<Dependency> for Package {}
|
||||
impl Package {
|
||||
pub fn new<S: ToString>(name: S) -> Self {
|
||||
let mut package = Self::default();
|
||||
package.name = name.to_string();
|
||||
package
|
||||
}
|
||||
}
|
||||
|
||||
impl Default for Package {
|
||||
fn default() -> Self {
|
||||
Package {
|
||||
name: String::from("Main"),
|
||||
version: Version::new(0, 1, 0),
|
||||
authors: None,
|
||||
repository: None,
|
||||
license: None,
|
||||
license_file: None,
|
||||
entry_point: None,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user