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, } #[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, } #[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, } #[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 for Project { type Error = Error; fn try_from(value: File) -> Result { let mut value = value; let mut buf = String::new(); value.read_to_string(&mut buf)?; Ok(Project::from_str(&buf)?) } }