use std::collections::HashMap;
use std::path::PathBuf;
use crate::settings::Settings;
use crate::core::project::MavenProject;
#[derive(Debug, Clone)]
pub struct MavenSession {
pub current_project: Option<MavenProject>,
pub projects: Vec<MavenProject>,
pub settings: Settings,
pub system_properties: HashMap<String, String>,
pub user_properties: HashMap<String, String>,
pub execution_root: PathBuf,
pub local_repository: PathBuf,
}
impl MavenSession {
pub fn new(execution_root: PathBuf, settings: Settings) -> Self {
let local_repo = settings
.local_repository
.as_ref()
.map(PathBuf::from)
.unwrap_or_else(|| {
let home = std::env::var("HOME").unwrap_or_else(|_| ".".to_string());
let mut path = PathBuf::from(home);
path.push(".m2");
path.push("repository");
path
});
Self {
current_project: None,
projects: Vec::new(),
settings,
system_properties: HashMap::new(),
user_properties: HashMap::new(),
execution_root,
local_repository: local_repo,
}
}
pub fn with_project(mut self, project: MavenProject) -> Self {
self.current_project = Some(project.clone());
self.projects.push(project);
self
}
}