1 package org.apache.maven.model.building;
2
3 /*
4 * Licensed to the Apache Software Foundation (ASF) under one
5 * or more contributor license agreements. See the NOTICE file
6 * distributed with this work for additional information
7 * regarding copyright ownership. The ASF licenses this file
8 * to you under the Apache License, Version 2.0 (the
9 * "License"); you may not use this file except in compliance
10 * with the License. You may obtain a copy of the License at
11 *
12 * http://www.apache.org/licenses/LICENSE-2.0
13 *
14 * Unless required by applicable law or agreed to in writing,
15 * software distributed under the License is distributed on an
16 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
17 * KIND, either express or implied. See the License for the
18 * specific language governing permissions and limitations
19 * under the License.
20 */
21
22 import java.io.File;
23 import java.util.Date;
24 import java.util.List;
25 import java.util.Properties;
26
27 import org.apache.maven.model.Model;
28 import org.apache.maven.model.Profile;
29 import org.apache.maven.model.resolution.ModelResolver;
30 import org.apache.maven.model.resolution.WorkspaceModelResolver;
31
32 /**
33 * Collects settings that control the building of effective models.
34 *
35 * @author Benjamin Bentmann
36 */
37 public interface ModelBuildingRequest
38 {
39
40 /**
41 * Denotes minimal validation of POMs. This validation level is meant for processing of POMs from repositories
42 * during metadata retrieval.
43 */
44 int VALIDATION_LEVEL_MINIMAL = 0;
45
46 /**
47 * Denotes validation as performed by Maven 2.0. This validation level is meant as a compatibility mode to allow
48 * users to migrate their projects.
49 */
50 int VALIDATION_LEVEL_MAVEN_2_0 = 20;
51
52 /**
53 * Denotes validation as performed by Maven 3.0. This validation level is meant for existing projects.
54 */
55 int VALIDATION_LEVEL_MAVEN_3_0 = 30;
56
57 /**
58 * Denotes validation as performed by Maven 3.1. This validation level is meant for new projects.
59 */
60 int VALIDATION_LEVEL_MAVEN_3_1 = 31;
61
62 /**
63 * Denotes strict validation as recommended by the current Maven version.
64 */
65 int VALIDATION_LEVEL_STRICT = VALIDATION_LEVEL_MAVEN_3_0;
66
67 /**
68 * Gets the raw model to build. If not set, model source will be used to load raw model.
69 *
70 * @return The raw model to build or {@code null} if not set.
71 */
72 Model getRawModel();
73
74 /**
75 * Set raw model.
76 *
77 * @param rawModel
78 */
79 ModelBuildingRequest setRawModel( Model rawModel );
80
81 /**
82 * Gets the source of the POM to process.
83 *
84 * @return The source of the POM or {@code null} if not set.
85 */
86 ModelSource getModelSource();
87
88 /**
89 * Sets the source of the POM to process. Eventually, either {@link #setModelSource(ModelSource)} or
90 * {@link #setPomFile(File)} must be set.
91 *
92 * @param modelSource The source of the POM to process, may be {@code null}.
93 * @return This request, never {@code null}.
94 */
95 ModelBuildingRequest setModelSource( ModelSource modelSource );
96
97 /**
98 * Gets the POM file of the project to build.
99 *
100 * @return The POM file of the project or {@code null} if not applicable (i.e. when processing a POM from the
101 * repository).
102 */
103 File getPomFile();
104
105 /**
106 * Sets the POM file of the project to build. Note that providing the path to a POM file via this method will make
107 * the model builder operate in project mode. This mode is meant for effective models that are employed during the
108 * build process of a local project. Hence the effective model will support the notion of a project directory. To
109 * build the model for a POM from the repository, use {@link #setModelSource(ModelSource)} in combination with a
110 * {@link FileModelSource} instead.
111 *
112 * @param pomFile The POM file of the project to build the effective model for, may be {@code null} to build the
113 * model of some POM from the repository.
114 * @return This request, never {@code null}.
115 */
116 ModelBuildingRequest setPomFile( File pomFile );
117
118 /**
119 * Gets the level of validation to perform on processed models.
120 *
121 * @return The level of validation to perform on processed models.
122 */
123 int getValidationLevel();
124
125 /**
126 * Sets the level of validation to perform on processed models. For building of projects,
127 * {@link #VALIDATION_LEVEL_STRICT} should be used to ensure proper building. For the mere retrieval of dependencies
128 * during artifact resolution, {@link #VALIDATION_LEVEL_MINIMAL} should be used to account for models of poor
129 * quality. By default, models are validated in strict mode.
130 *
131 * @param validationLevel The level of validation to perform on processed models.
132 * @return This request, never {@code null}.
133 */
134 ModelBuildingRequest setValidationLevel( int validationLevel );
135
136 /**
137 * Indicates whether plugin executions and configurations should be processed. If enabled, lifecycle-induced plugin
138 * executions will be injected into the model and common plugin configuration will be propagated to individual
139 * executions.
140 *
141 * @return {@code true} if plugins should be processed, {@code false} otherwise.
142 */
143 boolean isProcessPlugins();
144
145 /**
146 * Controls the processing of plugin executions and configurations.
147 *
148 * @param processPlugins {@code true} to enable plugin processing, {@code false} otherwise.
149 * @return This request, never {@code null}.
150 */
151 ModelBuildingRequest setProcessPlugins( boolean processPlugins );
152
153 /**
154 * Indicates whether the model building should happen in two phases. If enabled, the initial invocation of the model
155 * builder will only produce an interim result which may be used to analyze inter-model dependencies before the
156 * final invocation of the model builder is performed.
157 *
158 * @return {@code true} if two-phase building is enabled, {@code false} if the model should be build in a single
159 * step.
160 */
161 boolean isTwoPhaseBuilding();
162
163 /**
164 * Enables/disables two-phase building. If enabled, the initial invocation of the model builder will only produce an
165 * interim result which may be used to analyze inter-model dependencies before the final invocation of the model
166 * builder is performed.
167 *
168 * @param twoPhaseBuilding {@code true} to enable two-phase building, {@code false} if the model should be build in
169 * a single step.
170 * @return This request, never {@code null}.
171 */
172 ModelBuildingRequest setTwoPhaseBuilding( boolean twoPhaseBuilding );
173
174 /**
175 * Indicates whether the model should track the line/column number of the model source from which it was parsed.
176 *
177 * @return {@code true} if location tracking is enabled, {@code false} otherwise.
178 */
179 boolean isLocationTracking();
180
181 /**
182 * Enables/disables the tracking of line/column numbers for the model source being parsed. By default, input
183 * locations are not tracked.
184 *
185 * @param locationTracking {@code true} to enable location tracking, {@code false} to disable it.
186 * @return This request, never {@code null}.
187 */
188 ModelBuildingRequest setLocationTracking( boolean locationTracking );
189
190 /**
191 * Gets the external profiles that should be considered for model building.
192 *
193 * @return The external profiles that should be considered for model building, never {@code null}.
194 */
195 List<Profile> getProfiles();
196
197 /**
198 * Sets the external profiles that should be considered for model building.
199 *
200 * @param profiles The external profiles that should be considered for model building, may be {@code null}.
201 * @return This request, never {@code null}.
202 */
203 ModelBuildingRequest setProfiles( List<Profile> profiles );
204
205 /**
206 * Gets the identifiers of those profiles that should be activated by explicit demand.
207 *
208 * @return The identifiers of those profiles to activate, never {@code null}.
209 */
210 List<String> getActiveProfileIds();
211
212 /**
213 * Sets the identifiers of those profiles that should be activated by explicit demand.
214 *
215 * @param activeProfileIds The identifiers of those profiles to activate, may be {@code null}.
216 * @return This request, never {@code null}.
217 */
218 ModelBuildingRequest setActiveProfileIds( List<String> activeProfileIds );
219
220 /**
221 * Gets the identifiers of those profiles that should be deactivated by explicit demand.
222 *
223 * @return The identifiers of those profiles to deactivate, never {@code null}.
224 */
225 List<String> getInactiveProfileIds();
226
227 /**
228 * Sets the identifiers of those profiles that should be deactivated by explicit demand.
229 *
230 * @param inactiveProfileIds The identifiers of those profiles to deactivate, may be {@code null}.
231 * @return This request, never {@code null}.
232 */
233 ModelBuildingRequest setInactiveProfileIds( List<String> inactiveProfileIds );
234
235 /**
236 * Gets the system properties to use for interpolation and profile activation. The system properties are collected
237 * from the runtime environment like {@link System#getProperties()} and environment variables.
238 *
239 * @return The system properties, never {@code null}.
240 */
241 Properties getSystemProperties();
242
243 /**
244 * Sets the system properties to use for interpolation and profile activation. The system properties are collected
245 * from the runtime environment like {@link System#getProperties()} and environment variables.
246 *
247 * @param systemProperties The system properties, may be {@code null}.
248 * @return This request, never {@code null}.
249 */
250 ModelBuildingRequest setSystemProperties( Properties systemProperties );
251
252 /**
253 * Gets the user properties to use for interpolation and profile activation. The user properties have been
254 * configured directly by the user on his discretion, e.g. via the {@code -Dkey=value} parameter on the command
255 * line.
256 *
257 * @return The user properties, never {@code null}.
258 */
259 Properties getUserProperties();
260
261 /**
262 * Sets the user properties to use for interpolation and profile activation. The user properties have been
263 * configured directly by the user on his discretion, e.g. via the {@code -Dkey=value} parameter on the command
264 * line.
265 *
266 * @param userProperties The user properties, may be {@code null}.
267 * @return This request, never {@code null}.
268 */
269 ModelBuildingRequest setUserProperties( Properties userProperties );
270
271 /**
272 * Gets the start time of the build.
273 *
274 * @return The start time of the build or {@code null} if unknown.
275 */
276 Date getBuildStartTime();
277
278 /**
279 * Sets the start time of the build.
280 *
281 * @param buildStartTime The start time of the build, may be {@code null}.
282 * @return This request, never {@code null}.
283 */
284 ModelBuildingRequest setBuildStartTime( Date buildStartTime );
285
286 /**
287 * Gets the model resolver to use for resolution of mixins or parents that are not locally reachable from the
288 * project directory.
289 *
290 * @return The model resolver or {@code null} if not set.
291 */
292 ModelResolver getModelResolver();
293
294 /**
295 * Sets the model resolver to use for resolution of mixins or parents that are not locally reachable from the
296 * project directory.
297 *
298 * @param modelResolver The model resolver to use, never {@code null}.
299 * @return This request, never {@code null}.
300 */
301 ModelBuildingRequest setModelResolver( ModelResolver modelResolver );
302
303 /**
304 * Gets the model building listener to notify during the build process.
305 *
306 * @return The model building listener to notify or {@code null} if none.
307 */
308 ModelBuildingListener getModelBuildingListener();
309
310 /**
311 * Sets the model building listener to notify during the build process.
312 *
313 * @param modelBuildingListener The model building listener to notify, may be {@code null}.
314 * @return This request, never {@code null}.
315 */
316 ModelBuildingRequest setModelBuildingListener( ModelBuildingListener modelBuildingListener );
317
318 /**
319 * Gets the model cache to use for reuse of previously built models.
320 *
321 * @return The model cache or {@code null} if not set.
322 */
323 ModelCache getModelCache();
324
325 /**
326 * Sets the model cache to use for reuse of previously built models. This is an optional component that serves
327 * performance optimizations.
328 *
329 * @param modelCache The model cache to use, may be {@code null}.
330 * @return This request, never {@code null}.
331 */
332 ModelBuildingRequest setModelCache( ModelCache modelCache );
333
334 WorkspaceModelResolver getWorkspaceModelResolver();
335
336 ModelBuildingRequest setWorkspaceModelResolver( WorkspaceModelResolver workspaceResolver );
337
338 }