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