WIP properties
This commit is contained in:
parent
2c714a211c
commit
869dac9d38
4 changed files with 69 additions and 5 deletions
39
Cargo.lock
generated
39
Cargo.lock
generated
|
|
@ -17,6 +17,15 @@ version = "1.0.2"
|
|||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "f26201604c87b1e01bd3d98f8d5d9a8fcbb815e8cedb41ffccbeb4bf593a35fe"
|
||||
|
||||
[[package]]
|
||||
name = "aho-corasick"
|
||||
version = "1.1.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "b2969dcb958b36655471fc61f7e416fa76033bdd4bfed0678d8fee1e2d07a1f0"
|
||||
dependencies = [
|
||||
"memchr",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "anyhow"
|
||||
version = "1.0.79"
|
||||
|
|
@ -436,6 +445,7 @@ dependencies = [
|
|||
"colored",
|
||||
"hex",
|
||||
"home",
|
||||
"regex",
|
||||
"reqwest",
|
||||
"sha1",
|
||||
"strong-xml",
|
||||
|
|
@ -651,6 +661,35 @@ dependencies = [
|
|||
"bitflags 1.3.2",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "regex"
|
||||
version = "1.10.3"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "b62dbe01f0b06f9d8dc7d49e05a0785f153b00b2c227856282f671e0318c9b15"
|
||||
dependencies = [
|
||||
"aho-corasick",
|
||||
"memchr",
|
||||
"regex-automata",
|
||||
"regex-syntax",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "regex-automata"
|
||||
version = "0.4.4"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "3b7fa1134405e2ec9353fd416b17f8dacd46c473d7d3fd1cf202706a14eb792a"
|
||||
dependencies = [
|
||||
"aho-corasick",
|
||||
"memchr",
|
||||
"regex-syntax",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "regex-syntax"
|
||||
version = "0.8.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "c08c74e62047bb2de4ff487b251e4a92e24f48745648451635cec7d591162d9f"
|
||||
|
||||
[[package]]
|
||||
name = "reqwest"
|
||||
version = "0.11.23"
|
||||
|
|
|
|||
|
|
@ -15,3 +15,4 @@ bytes = "1.5"
|
|||
home = "0.5"
|
||||
sha1 = "0.10"
|
||||
hex = "0.4"
|
||||
regex="1.10"
|
||||
|
|
@ -32,7 +32,7 @@ pub struct Pom {
|
|||
#[xml(child = "dependencies")]
|
||||
pub(crate) dependencies: Option<Dependencies>,
|
||||
#[xml(child = "dependencyManagement")]
|
||||
pub(crate) dependency_management: Option<Dependencies>,
|
||||
pub(crate) dependency_management: Option<DependencyManagement>,
|
||||
}
|
||||
|
||||
#[derive(XmlRead, PartialEq, Debug)]
|
||||
|
|
@ -157,13 +157,20 @@ struct Developer {
|
|||
pub(crate) name: Name,
|
||||
}
|
||||
|
||||
#[derive(XmlRead, PartialEq, Debug)]
|
||||
#[derive(XmlRead, PartialEq, Debug, Clone)]
|
||||
#[xml(tag = "dependencies")]
|
||||
pub struct Dependencies {
|
||||
#[xml(child = "dependency")]
|
||||
pub(crate) value: Vec<Dependency>,
|
||||
}
|
||||
|
||||
#[derive(XmlRead, PartialEq, Debug, Clone)]
|
||||
#[xml(tag = "dependencyManagement")]
|
||||
pub struct DependencyManagement {
|
||||
#[xml(child = "dependencies")]
|
||||
pub(crate) value: Dependencies,
|
||||
}
|
||||
|
||||
#[derive(XmlRead, PartialEq, Debug, Clone)]
|
||||
#[xml(tag = "dependency")]
|
||||
pub struct Dependency {
|
||||
|
|
|
|||
|
|
@ -1,4 +1,5 @@
|
|||
use anyhow::Error;
|
||||
use regex::Regex;
|
||||
use strong_xml::XmlRead;
|
||||
|
||||
use crate::deploader;
|
||||
|
|
@ -7,7 +8,7 @@ use crate::project::{Artifact, Project};
|
|||
|
||||
/// offers a (non-mutable) view on the pom-as-xml-representation
|
||||
/// the main use of this is that it resolves the parent information when needed
|
||||
pub struct PomView<'a> {
|
||||
pub(crate) struct PomView<'a> {
|
||||
pom: Pom,
|
||||
project: &'a Project,
|
||||
parent: Option<Box<PomView<'a>>>,
|
||||
|
|
@ -86,6 +87,7 @@ impl<'a> PomView<'a> {
|
|||
.dependency_management
|
||||
.as_ref()
|
||||
.map(|d| d.value.clone())
|
||||
.map(|d|d.value)
|
||||
.unwrap_or(vec![]),
|
||||
}
|
||||
}
|
||||
|
|
@ -99,6 +101,7 @@ impl<'a> PomView<'a> {
|
|||
} else {
|
||||
if let Some(parent) = &self.parent {
|
||||
search_version(dep, parent.dependency_management())
|
||||
.map(|v| resolve_props(parent, v))
|
||||
} else {
|
||||
None
|
||||
}
|
||||
|
|
@ -117,6 +120,20 @@ impl<'a> PomView<'a> {
|
|||
}
|
||||
}
|
||||
|
||||
fn resolve_props(pom: &PomView, version: String) -> String {
|
||||
let p = Regex::new("\\$\\{(?<prop>.+?)}").expect("wrong regex"); //TODO instantiate once
|
||||
let v2 = if let Some(capture) = p.captures(&version) {
|
||||
match &capture["prop"] {
|
||||
"project.version" => pom.version(),
|
||||
_ => pom.
|
||||
}
|
||||
} else {
|
||||
version
|
||||
};
|
||||
println!("{}", v2);
|
||||
v2
|
||||
}
|
||||
|
||||
fn search_version(dep: &Dependency, depman: DependencyManagementView) -> Option<String> {
|
||||
for mandep in depman.dependencies {
|
||||
if mandep.group_id == dep.group_id && mandep.artifact_id == dep.artifact_id {
|
||||
|
|
@ -150,7 +167,7 @@ pub(crate) struct DependencyView<'a> {
|
|||
version: String,
|
||||
}
|
||||
|
||||
struct DependencyManagementView {
|
||||
pub(crate) struct DependencyManagementView {
|
||||
dependencies: Vec<Dependency>,
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue