1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package org.apache.maven.project;
20
21 import java.util.ArrayList;
22 import java.util.Date;
23 import java.util.List;
24 import java.util.Objects;
25 import java.util.Properties;
26 import org.apache.maven.artifact.repository.ArtifactRepository;
27 import org.apache.maven.model.Profile;
28 import org.apache.maven.model.building.ModelBuildingRequest;
29 import org.apache.maven.properties.internal.SystemProperties;
30 import org.eclipse.aether.RepositorySystemSession;
31
32
33
34
35 public class DefaultProjectBuildingRequest implements ProjectBuildingRequest {
36
37 private RepositorySystemSession repositorySession;
38
39 private ArtifactRepository localRepository;
40
41 private List<ArtifactRepository> remoteRepositories;
42
43 private List<ArtifactRepository> pluginArtifactRepositories;
44
45 private MavenProject project;
46
47 private int validationLevel = ModelBuildingRequest.VALIDATION_LEVEL_STRICT;
48
49 private boolean processPlugins;
50
51 private List<Profile> profiles;
52
53 private List<String> activeProfileIds;
54
55 private List<String> inactiveProfileIds;
56
57 private Properties systemProperties;
58
59 private Properties userProperties;
60
61 private Date buildStartTime;
62
63 private boolean resolveDependencies;
64
65 @Deprecated
66 private boolean resolveVersionRanges;
67
68 private RepositoryMerging repositoryMerging = RepositoryMerging.POM_DOMINANT;
69
70 public DefaultProjectBuildingRequest() {
71 processPlugins = true;
72 profiles = new ArrayList<>();
73 activeProfileIds = new ArrayList<>();
74 inactiveProfileIds = new ArrayList<>();
75 systemProperties = new Properties();
76 userProperties = new Properties();
77 remoteRepositories = new ArrayList<>();
78 pluginArtifactRepositories = new ArrayList<>();
79 }
80
81 public DefaultProjectBuildingRequest(ProjectBuildingRequest request) {
82 this();
83 setProcessPlugins(request.isProcessPlugins());
84 setProfiles(request.getProfiles());
85 setActiveProfileIds(request.getActiveProfileIds());
86 setInactiveProfileIds(request.getInactiveProfileIds());
87 setSystemProperties(request.getSystemProperties());
88 setUserProperties(request.getUserProperties());
89 setRemoteRepositories(request.getRemoteRepositories());
90 setPluginArtifactRepositories(request.getPluginArtifactRepositories());
91 setRepositorySession(request.getRepositorySession());
92 setLocalRepository(request.getLocalRepository());
93 setBuildStartTime(request.getBuildStartTime());
94 setProject(request.getProject());
95 setResolveDependencies(request.isResolveDependencies());
96 setValidationLevel(request.getValidationLevel());
97 setResolveVersionRanges(request.isResolveVersionRanges());
98 setRepositoryMerging(request.getRepositoryMerging());
99 }
100
101 public MavenProject getProject() {
102 return project;
103 }
104
105 public void setProject(MavenProject mavenProject) {
106 this.project = mavenProject;
107 }
108
109 public ProjectBuildingRequest setLocalRepository(ArtifactRepository localRepository) {
110 this.localRepository = localRepository;
111 return this;
112 }
113
114 public ArtifactRepository getLocalRepository() {
115 return localRepository;
116 }
117
118 public List<ArtifactRepository> getRemoteRepositories() {
119 return remoteRepositories;
120 }
121
122 public ProjectBuildingRequest setRemoteRepositories(List<ArtifactRepository> remoteRepositories) {
123 if (remoteRepositories != null) {
124 this.remoteRepositories = new ArrayList<>(remoteRepositories);
125 } else {
126 this.remoteRepositories.clear();
127 }
128
129 return this;
130 }
131
132 public List<ArtifactRepository> getPluginArtifactRepositories() {
133 return pluginArtifactRepositories;
134 }
135
136 public ProjectBuildingRequest setPluginArtifactRepositories(List<ArtifactRepository> pluginArtifactRepositories) {
137 if (pluginArtifactRepositories != null) {
138 this.pluginArtifactRepositories = new ArrayList<>(pluginArtifactRepositories);
139 } else {
140 this.pluginArtifactRepositories.clear();
141 }
142
143 return this;
144 }
145
146 public Properties getSystemProperties() {
147 return systemProperties;
148 }
149
150 public ProjectBuildingRequest setSystemProperties(Properties systemProperties) {
151 if (systemProperties != null) {
152 this.systemProperties = SystemProperties.copyProperties(systemProperties);
153 } else {
154 this.systemProperties.clear();
155 }
156
157 return this;
158 }
159
160 public Properties getUserProperties() {
161 return userProperties;
162 }
163
164 public ProjectBuildingRequest setUserProperties(Properties userProperties) {
165 if (userProperties != null) {
166 this.userProperties = new Properties();
167 this.userProperties.putAll(userProperties);
168 } else {
169 this.userProperties.clear();
170 }
171
172 return this;
173 }
174
175 public boolean isProcessPlugins() {
176 return processPlugins;
177 }
178
179 public ProjectBuildingRequest setProcessPlugins(boolean processPlugins) {
180 this.processPlugins = processPlugins;
181 return this;
182 }
183
184 public ProjectBuildingRequest setResolveDependencies(boolean resolveDependencies) {
185 this.resolveDependencies = resolveDependencies;
186 return this;
187 }
188
189 public boolean isResolveDependencies() {
190 return resolveDependencies;
191 }
192
193
194
195
196
197
198 @Deprecated
199 public ProjectBuildingRequest setResolveVersionRanges(boolean value) {
200 this.resolveVersionRanges = value;
201 return this;
202 }
203
204
205
206
207
208
209 @Deprecated
210 public boolean isResolveVersionRanges() {
211 return this.resolveVersionRanges;
212 }
213
214 public ProjectBuildingRequest setValidationLevel(int validationLevel) {
215 this.validationLevel = validationLevel;
216 return this;
217 }
218
219 public int getValidationLevel() {
220 return validationLevel;
221 }
222
223 public List<String> getActiveProfileIds() {
224 return activeProfileIds;
225 }
226
227 public void setActiveProfileIds(List<String> activeProfileIds) {
228 if (activeProfileIds != null) {
229 this.activeProfileIds = new ArrayList<>(activeProfileIds);
230 } else {
231 this.activeProfileIds.clear();
232 }
233 }
234
235 public List<String> getInactiveProfileIds() {
236 return inactiveProfileIds;
237 }
238
239 public void setInactiveProfileIds(List<String> inactiveProfileIds) {
240 if (inactiveProfileIds != null) {
241 this.inactiveProfileIds = new ArrayList<>(inactiveProfileIds);
242 } else {
243 this.inactiveProfileIds.clear();
244 }
245 }
246
247 public void setProfiles(List<Profile> profiles) {
248 if (profiles != null) {
249 this.profiles = new ArrayList<>(profiles);
250 } else {
251 this.profiles.clear();
252 }
253 }
254
255 public void addProfile(Profile profile) {
256 profiles.add(profile);
257 }
258
259 public List<Profile> getProfiles() {
260 return profiles;
261 }
262
263 public Date getBuildStartTime() {
264 return buildStartTime;
265 }
266
267 public void setBuildStartTime(Date buildStartTime) {
268 this.buildStartTime = buildStartTime;
269 }
270
271 public RepositorySystemSession getRepositorySession() {
272 return repositorySession;
273 }
274
275 public DefaultProjectBuildingRequest setRepositorySession(RepositorySystemSession repositorySession) {
276 this.repositorySession = repositorySession;
277 return this;
278 }
279
280 public DefaultProjectBuildingRequest setRepositoryMerging(RepositoryMerging repositoryMerging) {
281 this.repositoryMerging = Objects.requireNonNull(repositoryMerging, "repositoryMerging cannot be null");
282 return this;
283 }
284
285 public RepositoryMerging getRepositoryMerging() {
286 return repositoryMerging;
287 }
288 }