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