pub mod audit;
pub mod check;
pub mod update;
pub use audit::{AuditResult, Severity, Vulnerability};
pub use check::{VersionResult, VersionStatus};
pub use update::{UpdateResult, UpdateStatus};
#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, serde::Serialize)]
#[serde(rename_all = "lowercase")]
pub enum Ecosystem {
Maven,
Npm,
}
impl std::fmt::Display for Ecosystem {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
match self {
Self::Maven => write!(f, "Maven"),
Self::Npm => write!(f, "npm"),
}
}
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord)]
pub enum DependencyKind {
Dependency,
Plugin,
ToolVersion,
NpmDep,
NpmDevDep,
}
impl std::fmt::Display for DependencyKind {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
match self {
Self::Dependency => write!(f, "Dependency"),
Self::Plugin => write!(f, "Plugin"),
Self::ToolVersion => write!(f, "Tool Version"),
Self::NpmDep => write!(f, "Dependency"),
Self::NpmDevDep => write!(f, "Dev Dependency"),
}
}
}
pub trait DependencyInfo {
fn ecosystem(&self) -> Ecosystem;
fn kind(&self) -> DependencyKind;
fn artifact(&self) -> &str;
fn property(&self) -> Option<&str>;
fn source(&self) -> &str;
fn has_property(&self) -> bool {
self.property().is_some()
}
}
#[derive(Debug, Clone)]
pub struct Dependency {
pub ecosystem: Ecosystem,
pub kind: DependencyKind,
pub artifact: String,
pub property: Option<String>,
pub source: String,
}
impl Dependency {
pub fn new(
ecosystem: Ecosystem,
kind: DependencyKind,
artifact: String,
property: Option<String>,
source: String,
) -> Self {
Self {
ecosystem,
kind,
artifact,
property,
source,
}
}
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn ecosystem_display() {
assert_eq!(Ecosystem::Maven.to_string(), "Maven");
assert_eq!(Ecosystem::Npm.to_string(), "npm");
}
#[test]
fn dependency_kind_display() {
assert_eq!(DependencyKind::Dependency.to_string(), "Dependency");
assert_eq!(DependencyKind::Plugin.to_string(), "Plugin");
assert_eq!(DependencyKind::ToolVersion.to_string(), "Tool Version");
assert_eq!(DependencyKind::NpmDep.to_string(), "Dependency");
assert_eq!(DependencyKind::NpmDevDep.to_string(), "Dev Dependency");
}
#[test]
fn dependency_with_property() {
let id = Dependency::new(
Ecosystem::Maven,
DependencyKind::Dependency,
"org.junit:junit".to_string(),
Some("version.junit".to_string()),
String::new(),
);
assert!(id.property.is_some());
assert_eq!(id.property, Some("version.junit".to_string()));
}
#[test]
fn dependency_without_property() {
let id = Dependency::new(
Ecosystem::Maven,
DependencyKind::Dependency,
"com.google.guava:guava".into(),
None,
String::new(),
);
assert!(id.property.is_none());
}
}