1   
2   
3   
4   
5   
6   
7   
8   
9   
10  
11  
12  
13  
14  
15  
16  
17  
18  
19  package org.apache.maven.model.building;
20  
21  import java.util.ArrayList;
22  import java.util.HashMap;
23  import java.util.List;
24  import java.util.Map;
25  import java.util.Objects;
26  
27  import org.apache.maven.model.Model;
28  import org.apache.maven.model.Profile;
29  
30  
31  
32  
33  
34  
35  class DefaultModelBuildingResult implements ModelBuildingResult {
36  
37      private Model effectiveModel;
38  
39      private List<String> modelIds;
40  
41      private Map<String, Model> rawModels;
42  
43      private Map<String, List<Profile>> activePomProfiles;
44  
45      private List<Profile> activeExternalProfiles;
46  
47      private List<ModelProblem> problems;
48  
49      DefaultModelBuildingResult() {
50          modelIds = new ArrayList<>();
51          rawModels = new HashMap<>();
52          activePomProfiles = new HashMap<>();
53          activeExternalProfiles = new ArrayList<>();
54          problems = new ArrayList<>();
55      }
56  
57      @Override
58      public Model getEffectiveModel() {
59          return effectiveModel;
60      }
61  
62      public DefaultModelBuildingResult setEffectiveModel(Model model) {
63          this.effectiveModel = model;
64  
65          return this;
66      }
67  
68      @Override
69      public List<String> getModelIds() {
70          return modelIds;
71      }
72  
73      public DefaultModelBuildingResult addModelId(String modelId) {
74          
75          Objects.requireNonNull(modelId, "modelId cannot null");
76  
77          modelIds.add(modelId);
78  
79          return this;
80      }
81  
82      @Override
83      public Model getRawModel() {
84          return rawModels.get(modelIds.get(0));
85      }
86  
87      @Override
88      public Model getRawModel(String modelId) {
89          return rawModels.get(modelId);
90      }
91  
92      public DefaultModelBuildingResult setRawModel(String modelId, Model rawModel) {
93          
94          Objects.requireNonNull(modelId, "modelId cannot null");
95  
96          rawModels.put(modelId, rawModel);
97  
98          return this;
99      }
100 
101     @Override
102     public List<Profile> getActivePomProfiles(String modelId) {
103         return activePomProfiles.get(modelId);
104     }
105 
106     public DefaultModelBuildingResult setActivePomProfiles(String modelId, List<Profile> activeProfiles) {
107         
108         Objects.requireNonNull(modelId, "modelId cannot null");
109 
110         if (activeProfiles != null) {
111             this.activePomProfiles.put(modelId, new ArrayList<>(activeProfiles));
112         } else {
113             this.activePomProfiles.remove(modelId);
114         }
115 
116         return this;
117     }
118 
119     @Override
120     public List<Profile> getActiveExternalProfiles() {
121         return activeExternalProfiles;
122     }
123 
124     public DefaultModelBuildingResult setActiveExternalProfiles(List<Profile> activeProfiles) {
125         if (activeProfiles != null) {
126             this.activeExternalProfiles = new ArrayList<>(activeProfiles);
127         } else {
128             this.activeExternalProfiles.clear();
129         }
130 
131         return this;
132     }
133 
134     @Override
135     public List<ModelProblem> getProblems() {
136         return problems;
137     }
138 
139     public DefaultModelBuildingResult setProblems(List<ModelProblem> problems) {
140         if (problems != null) {
141             this.problems = new ArrayList<>(problems);
142         } else {
143             this.problems.clear();
144         }
145 
146         return this;
147     }
148 }