use std::collections::HashMap; use std::env; use std::fmt::Display; use std::path::PathBuf; use std::sync::LazyLock; /// the maven object model const HOME: LazyLock = LazyLock::new(|| env::var("HOME").unwrap()); #[derive(PartialEq, Debug)] pub struct Pom { pub parent: Option, pub group_id: Option, pub artifact_id: String, pub version: Option, pub name: Option, pub packaging: Option, pub url: Option, pub dependencies: Vec, pub dependency_management: Vec, pub properties: HashMap, pub module_names: Vec, pub modules: Vec, pub directory: PathBuf, } impl Pom {} #[derive(PartialEq, Debug)] pub struct License { pub name: String, pub url: String, pub distribution: Option, } #[derive(PartialEq, Debug)] pub struct Parent { pub group_id: String, pub artifact_id: String, pub version: String, } #[derive(PartialEq, Debug)] pub struct Developer { pub id: Option, pub name: String, } #[derive(PartialEq, Debug, Clone)] pub struct Dependency { pub group_id: String, pub artifact_id: String, pub version: Option, // pub scope: Option, // TODO need this? } impl Dependency { /// returns a relative path to the dependency location pub fn to_jar_path(&self) -> PathBuf { let mut path = PathBuf::new(); path.push(self.group_id.replace(".", "/")); path.push(&self.artifact_id); let version = self.version.clone().unwrap_or_else(|| "latest".to_string()); path.push(&version); path.push(format!("{}-{}.jar", &self.artifact_id, &version)); path // why is the version (in the filename) wrong when I use PathBuf::set_extension("jar") ??? } /// returns an absolute path based on the default maven localRepository location // useful? pub fn to_absolute_jar_path(&self) -> PathBuf { let mut absolute_path = PathBuf::from(HOME.as_str()); absolute_path.push(".m2/repository"); absolute_path.push(self.to_jar_path()); absolute_path } } use std::fmt; impl Display for Dependency { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { let version = self.version.clone().unwrap_or_else(|| "latest".to_string()); write!( f, "{}/{}/{}/{}-{}", self.group_id.replace(".","/"), self.artifact_id, version, self.artifact_id, version ) } }