001package org.apache.maven.model.building;
002
003/*
004 * Licensed to the Apache Software Foundation (ASF) under one
005 * or more contributor license agreements.  See the NOTICE file
006 * distributed with this work for additional information
007 * regarding copyright ownership.  The ASF licenses this file
008 * to you under the Apache License, Version 2.0 (the
009 * "License"); you may not use this file except in compliance
010 * with the License.  You may obtain a copy of the License at
011 *
012 *   http://www.apache.org/licenses/LICENSE-2.0
013 *
014 * Unless required by applicable law or agreed to in writing,
015 * software distributed under the License is distributed on an
016 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
017 * KIND, either express or implied.  See the License for the
018 * specific language governing permissions and limitations
019 * under the License.
020 */
021
022import java.io.File;
023import java.util.Date;
024import java.util.List;
025import java.util.Properties;
026
027import org.apache.maven.model.Model;
028import org.apache.maven.model.Profile;
029import org.apache.maven.model.resolution.ModelResolver;
030import org.apache.maven.model.resolution.WorkspaceModelResolver;
031
032/**
033 * Collects settings that control the building of effective models.
034 *
035 * @author Benjamin Bentmann
036 */
037public interface ModelBuildingRequest
038{
039
040    /**
041     * Denotes minimal validation of POMs. This validation level is meant for processing of POMs from repositories
042     * during metadata retrieval.
043     */
044    int VALIDATION_LEVEL_MINIMAL = 0;
045
046    /**
047     * Denotes validation as performed by Maven 2.0. This validation level is meant as a compatibility mode to allow
048     * users to migrate their projects.
049     */
050    int VALIDATION_LEVEL_MAVEN_2_0 = 20;
051
052    /**
053     * Denotes validation as performed by Maven 3.0. This validation level is meant for existing projects.
054     */
055    int VALIDATION_LEVEL_MAVEN_3_0 = 30;
056
057    /**
058     * Denotes validation as performed by Maven 3.1. This validation level is meant for new projects.
059     */
060    int VALIDATION_LEVEL_MAVEN_3_1 = 31;
061
062    /**
063     * Denotes strict validation as recommended by the current Maven version.
064     */
065    int VALIDATION_LEVEL_STRICT = VALIDATION_LEVEL_MAVEN_3_0;
066
067    /**
068     * Gets the raw model to build. If not set, model source will be used to load raw model.
069     * 
070     * @return The raw model to build or {@code null} if not set.
071     */
072    Model getRawModel();
073
074    /**
075     * Set raw model.
076     *
077     * @param model
078     */
079    ModelBuildingRequest setRawModel( Model rawModel );
080
081    /**
082     * Gets the source of the POM to process.
083     *
084     * @return The source of the POM or {@code null} if not set.
085     */
086    ModelSource getModelSource();
087
088    /**
089     * Sets the source of the POM to process. Eventually, either {@link #setModelSource(ModelSource)} or
090     * {@link #setPomFile(File)} must be set.
091     *
092     * @param modelSource The source of the POM to process, may be {@code null}.
093     * @return This request, never {@code null}.
094     */
095    ModelBuildingRequest setModelSource( ModelSource modelSource );
096
097    /**
098     * Gets the POM file of the project to build.
099     *
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 retrievel 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, may be {@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}