Most of the refactor. Need to switch machines.

This commit is contained in:
Olivia Brooks
2026-02-15 09:36:04 -05:00
parent dda863e512
commit e41d4bcd76
61 changed files with 3390 additions and 618 deletions

18
crates/pom/Cargo.toml Normal file
View 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
View 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
View 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
View 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)?)
}
}