Skip to main content

jbuild/core/
session.rs

1use std::collections::HashMap;
2use std::path::PathBuf;
3
4use crate::settings::Settings;
5use crate::core::project::MavenProject;
6
7/// Maven execution session
8#[derive(Debug, Clone)]
9pub struct MavenSession {
10    /// Current project
11    pub current_project: Option<MavenProject>,
12
13    /// All projects in the reactor
14    pub projects: Vec<MavenProject>,
15
16    /// Settings
17    pub settings: Settings,
18
19    /// System properties
20    pub system_properties: HashMap<String, String>,
21
22    /// User properties
23    pub user_properties: HashMap<String, String>,
24
25    /// Execution root directory
26    pub execution_root: PathBuf,
27
28    /// Local repository path
29    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