use strong_xml::XmlRead; use crate::maven::metadata::Versioning; /// The Maven variant to parse poms /// These structs is directly modelled after the XML because that is what strong-xml plugin requires #[derive(XmlRead, PartialEq, Debug)] #[xml(tag = "project")] pub struct Pom { #[xml(child = "modelVersion")] pub model_version: ModelVersion, #[xml(child = "parent")] pub parent: Option, #[xml(child = "groupId")] pub group_id: Option, #[xml(child = "artifactId")] pub artifact_id: ArtifactId, #[xml(child = "version")] pub version: Option, #[xml(child = "name")] pub name: Name, #[xml(child = "packaging")] pub packaging: Option, #[xml(child = "url")] pub url: Option, #[xml(child = "description")] pub description: Description, #[xml(child = "licenses")] pub licences: Option, #[xml(child = "scm")] pub scm: Option, #[xml(child = "developers")] pub developers: Option, #[xml(child = "dependencies")] pub dependencies: Option, } #[derive(XmlRead, PartialEq, Debug)] #[xml(tag = "modelVersion")] pub struct ModelVersion { #[xml(text)] value: String, } #[derive(XmlRead, PartialEq, Debug)] #[xml(tag = "groupId")] pub struct GroupId { #[xml(text)] pub value: String, } #[derive(XmlRead, PartialEq, Debug)] #[xml(tag = "artifactId")] pub struct ArtifactId { #[xml(text)] pub value: String, } #[derive(XmlRead, PartialEq, Debug)] #[xml(tag = "version")] pub struct Version { #[xml(text)] pub value: String, } #[derive(XmlRead, PartialEq, Debug)] #[xml(tag = "name")] pub struct Name { #[xml(text)] value: String, } #[derive(XmlRead, PartialEq, Debug)] #[xml(tag = "id")] pub struct Id { #[xml(text)] value: String, } #[derive(XmlRead, PartialEq, Debug)] #[xml(tag = "packaging")] pub struct Packaging { #[xml(text)] value: String, } #[derive(XmlRead, PartialEq, Debug)] #[xml(tag = "url")] pub struct Url { #[xml(text)] value: String, } #[derive(XmlRead, PartialEq, Debug)] #[xml(tag = "description")] pub struct Description { #[xml(text)] value: String, } #[derive(XmlRead, PartialEq, Debug)] #[xml(tag = "licenses")] pub struct Licenses { #[xml(child = "license")] licenses: Vec, } #[derive(XmlRead, PartialEq, Debug)] #[xml(tag = "distribution")] pub struct Distribution { #[xml(text)] value: String, } #[derive(XmlRead, PartialEq, Debug)] #[xml(tag = "license")] pub struct License { #[xml(child = "name")] name: Name, #[xml(child = "url")] url: Url, #[xml(child = "distribution")] distribution: Option, } #[derive(XmlRead, PartialEq, Debug)] #[xml(tag = "parent")] pub struct Parent { #[xml(child = "groupId")] group_id: GroupId, #[xml(child = "artifactId")] artifact_id: ArtifactId, #[xml(child = "version")] version: Version, } #[derive(XmlRead, PartialEq, Debug)] #[xml(tag = "scm")] pub struct Scm { #[xml(child = "url")] url: Url, } #[derive(XmlRead, PartialEq, Debug)] #[xml(tag = "developers")] pub struct Developers { #[xml(child = "developer")] developers: Vec, } #[derive(XmlRead, PartialEq, Debug)] #[xml(tag = "developer")] struct Developer { #[xml(child = "id")] id: Option, #[xml(child = "name")] name: Name, } #[derive(XmlRead, PartialEq, Debug)] #[xml(tag = "dependencies")] pub struct Dependencies { #[xml(child = "dependency")] pub value: Vec, } #[derive(XmlRead, PartialEq, Debug)] #[xml(tag = "dependency")] pub struct Dependency { #[xml(child = "groupId")] pub group_id: GroupId, #[xml(child = "artifactId")] pub artifact_id: ArtifactId, #[xml(child = "version")] pub version: Option, } #[cfg(test)] mod test { use strong_xml::XmlRead; use crate::maven::pom::Pom; #[test] fn parse_should_not_fail() { Pom::from_str(r#" 4.0.0 org.mockito mockito-core 1.9.5 Mockito jar http://www.mockito.org Mock objects library for java The MIT License http://code.google.com/p/mockito/wiki/License repo http://code.google.com/p/mockito/source/browse/ szczepiq Szczepan Faber org.hamcrest hamcrest-core 1.1 org.objenesis objenesis 1.0 "#).unwrap(); } }