use std::collections::HashMap;
use std::path::PathBuf;
use crate::settings::Settings;
use crate::core::project::MavenProject;
#[derive(Debug, Clone)]
pub struct MavenExecutionRequest {
pub base_directory: PathBuf,
pub goals: Vec<String>,
pub active_profiles: Vec<String>,
pub system_properties: HashMap<String, String>,
pub user_properties: HashMap<String, String>,
pub show_errors: bool,
pub reactor_active: bool,
pub settings: Option<Settings>,
pub pom_file: Option<PathBuf>,
}
impl MavenExecutionRequest {
pub fn new(base_directory: PathBuf) -> Self {
Self {
base_directory,
goals: Vec::new(),
active_profiles: Vec::new(),
system_properties: HashMap::new(),
user_properties: HashMap::new(),
show_errors: false,
reactor_active: true,
settings: None,
pom_file: None,
}
}
pub fn with_goals(mut self, goals: Vec<String>) -> Self {
self.goals = goals;
self
}
pub fn with_pom_file(mut self, pom_file: PathBuf) -> Self {
self.pom_file = Some(pom_file);
self
}
}
#[derive(Debug)]
pub struct MavenExecutionResult {
pub projects: Vec<MavenProject>,
pub exceptions: Vec<anyhow::Error>,
pub success: bool,
}
impl MavenExecutionResult {
pub fn new() -> Self {
Self {
projects: Vec::new(),
exceptions: Vec::new(),
success: true,
}
}
pub fn add_exception(&mut self, error: anyhow::Error) {
self.exceptions.push(error);
self.success = false;
}
}
impl Default for MavenExecutionResult {
fn default() -> Self {
Self::new()
}
}
pub trait Maven {
fn execute(&self, request: MavenExecutionRequest) -> anyhow::Result<MavenExecutionResult>;
}