1use std::collections::HashMap;
2use std::path::PathBuf;
3
4use crate::settings::Settings;
5use crate::core::project::MavenProject;
6
7#[derive(Debug, Clone)]
9pub struct MavenSession {
10 pub current_project: Option<MavenProject>,
12
13 pub projects: Vec<MavenProject>,
15
16 pub settings: Settings,
18
19 pub system_properties: HashMap<String, String>,
21
22 pub user_properties: HashMap<String, String>,
24
25 pub execution_root: PathBuf,
27
28 pub local_repository: PathBuf,
30}
31
32impl MavenSession {
33 pub fn new(execution_root: PathBuf, settings: Settings) -> Self {
34 let local_repo = settings
35 .local_repository
36 .as_ref()
37 .map(PathBuf::from)
38 .unwrap_or_else(|| {
39 let home = std::env::var("HOME").unwrap_or_else(|_| ".".to_string());
40 let mut path = PathBuf::from(home);
41 path.push(".m2");
42 path.push("repository");
43 path
44 });
45
46 Self {
47 current_project: None,
48 projects: Vec::new(),
49 settings,
50 system_properties: HashMap::new(),
51 user_properties: HashMap::new(),
52 execution_root,
53 local_repository: local_repo,
54 }
55 }
56
57 pub fn with_project(mut self, project: MavenProject) -> Self {
58 self.current_project = Some(project.clone());
59 self.projects.push(project);
60 self
61 }
62}
63