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 @Deprecated(since = "4.0.0")
36 class DefaultModelBuildingResult implements ModelBuildingResult {
37 private Model fileModel;
38
39 private Model effectiveModel;
40
41 private List<String> modelIds;
42
43 private Map<String, Model> rawModels;
44
45 private Map<String, List<Profile>> activePomProfiles;
46
47 private List<Profile> activeExternalProfiles;
48
49 private List<ModelProblem> problems;
50
51 DefaultModelBuildingResult() {
52 modelIds = new ArrayList<>();
53 rawModels = new HashMap<>();
54 activePomProfiles = new HashMap<>();
55 activeExternalProfiles = new ArrayList<>();
56 problems = new ArrayList<>();
57 }
58
59 DefaultModelBuildingResult(ModelBuildingResult result) {
60 this();
61 this.activeExternalProfiles.addAll(result.getActiveExternalProfiles());
62 this.effectiveModel = result.getEffectiveModel();
63 this.fileModel = result.getFileModel();
64 this.problems.addAll(result.getProblems());
65
66 for (String modelId : result.getModelIds()) {
67 this.modelIds.add(modelId);
68 this.rawModels.put(modelId, result.getRawModel(modelId));
69 this.activePomProfiles.put(modelId, result.getActivePomProfiles(modelId));
70 }
71 }
72
73 @Override
74 public Model getFileModel() {
75 return fileModel;
76 }
77
78 public DefaultModelBuildingResult setFileModel(Model fileModel) {
79 this.fileModel = fileModel;
80
81 return this;
82 }
83
84 @Override
85 public Model getEffectiveModel() {
86 return effectiveModel;
87 }
88
89 public DefaultModelBuildingResult setEffectiveModel(Model model) {
90 this.effectiveModel = model;
91
92 return this;
93 }
94
95 @Override
96 public List<String> getModelIds() {
97 return modelIds;
98 }
99
100 public DefaultModelBuildingResult addModelId(String modelId) {
101
102 Objects.requireNonNull(modelId, "modelId cannot null");
103
104 modelIds.add(modelId);
105
106 return this;
107 }
108
109 @Override
110 public Model getRawModel() {
111 return rawModels.get(modelIds.get(0));
112 }
113
114 @Override
115 public Model getRawModel(String modelId) {
116 return rawModels.get(modelId);
117 }
118
119 public DefaultModelBuildingResult setRawModel(String modelId, Model rawModel) {
120
121 Objects.requireNonNull(modelId, "modelId cannot null");
122
123 rawModels.put(modelId, rawModel);
124
125 return this;
126 }
127
128 @Override
129 public List<Profile> getActivePomProfiles(String modelId) {
130 return activePomProfiles.get(modelId);
131 }
132
133 public DefaultModelBuildingResult setActivePomProfiles(String modelId, List<Profile> activeProfiles) {
134
135 Objects.requireNonNull(modelId, "modelId cannot null");
136
137 if (activeProfiles != null) {
138 this.activePomProfiles.put(modelId, new ArrayList<>(activeProfiles));
139 } else {
140 this.activePomProfiles.remove(modelId);
141 }
142
143 return this;
144 }
145
146 @Override
147 public List<Profile> getActiveExternalProfiles() {
148 return activeExternalProfiles;
149 }
150
151 public DefaultModelBuildingResult setActiveExternalProfiles(List<Profile> activeProfiles) {
152 if (activeProfiles != null) {
153 this.activeExternalProfiles = new ArrayList<>(activeProfiles);
154 } else {
155 this.activeExternalProfiles.clear();
156 }
157
158 return this;
159 }
160
161 @Override
162 public List<ModelProblem> getProblems() {
163 return problems;
164 }
165
166 public DefaultModelBuildingResult setProblems(List<ModelProblem> problems) {
167 if (problems != null) {
168 this.problems = new ArrayList<>(problems);
169 } else {
170 this.problems.clear();
171 }
172
173 return this;
174 }
175 }