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.Profile;
028import org.apache.maven.model.resolution.ModelResolver;
029
030/**
031 * Collects settings that control the building of effective models.
032 *
033 * @author Benjamin Bentmann
034 */
035public interface ModelBuildingRequest
036{
037
038    /**
039     * Denotes minimal validation of POMs. This validation level is meant for processing of POMs from repositories
040     * during metadata retrieval.
041     */
042    int VALIDATION_LEVEL_MINIMAL = 0;
043
044    /**
045     * Denotes validation as performed by Maven 2.0. This validation level is meant as a compatibility mode to allow
046     * users to migrate their projects.
047     */
048    int VALIDATION_LEVEL_MAVEN_2_0 = 20;
049
050    /**
051     * Denotes validation as performed by Maven 3.0. This validation level is meant for existing projects.
052     */
053    int VALIDATION_LEVEL_MAVEN_3_0 = 30;
054
055    /**
056     * Denotes validation as performed by Maven 3.1. This validation level is meant for new projects.
057     */
058    int VALIDATION_LEVEL_MAVEN_3_1 = 31;
059
060    /**
061     * Denotes strict validation as recommended by the current Maven version.
062     */
063    int VALIDATION_LEVEL_STRICT = VALIDATION_LEVEL_MAVEN_3_0;
064
065    /**
066     * Gets the source of the POM to process.
067     *
068     * @return The source of the POM or {@code null} if not set.
069     */
070    ModelSource getModelSource();
071
072    /**
073     * Sets the source of the POM to process. Eventually, either {@link #setModelSource(ModelSource)} or
074     * {@link #setPomFile(File)} must be set.
075     *
076     * @param modelSource The source of the POM to process, may be {@code null}.
077     * @return This request, never {@code null}.
078     */
079    ModelBuildingRequest setModelSource( ModelSource modelSource );
080
081    /**
082     * Gets the POM file of the project to build.
083     *
084     * @return The POM file of the project or {@code null} if not applicable (i.e. when processing a POM from the
085     *         repository).
086     */
087    File getPomFile();
088
089    /**
090     * Sets the POM file of the project to build. Note that providing the path to a POM file via this method will make
091     * the model builder operate in project mode. This mode is meant for effective models that are employed during the
092     * build process of a local project. Hence the effective model will support the notion of a project directory. To
093     * build the model for a POM from the repository, use {@link #setModelSource(ModelSource)} in combination with a
094     * {@link FileModelSource} instead.
095     *
096     * @param pomFile The POM file of the project to build the effective model for, may be {@code null} to build the
097     *            model of some POM from the repository.
098     * @return This request, never {@code null}.
099     */
100    ModelBuildingRequest setPomFile( File pomFile );
101
102    /**
103     * Gets the level of validation to perform on processed models.
104     *
105     * @return The level of validation to perform on processed models.
106     */
107    int getValidationLevel();
108
109    /**
110     * Sets the level of validation to perform on processed models. For building of projects,
111     * {@link #VALIDATION_LEVEL_STRICT} should be used to ensure proper building. For the mere retrievel of dependencies
112     * during artifact resolution, {@link #VALIDATION_LEVEL_MINIMAL} should be used to account for models of poor
113     * quality. By default, models are validated in strict mode.
114     *
115     * @param validationLevel The level of validation to perform on processed models.
116     * @return This request, never {@code null}.
117     */
118    ModelBuildingRequest setValidationLevel( int validationLevel );
119
120    /**
121     * Indicates whether plugin executions and configurations should be processed. If enabled, lifecycle-induced plugin
122     * executions will be injected into the model and common plugin configuration will be propagated to individual
123     * executions.
124     *
125     * @return {@code true} if plugins should be processed, {@code false} otherwise.
126     */
127    boolean isProcessPlugins();
128
129    /**
130     * Controls the processing of plugin executions and configurations.
131     *
132     * @param processPlugins {@code true} to enable plugin processing, {@code false} otherwise.
133     * @return This request, never {@code null}.
134     */
135    ModelBuildingRequest setProcessPlugins( boolean processPlugins );
136
137    /**
138     * Indicates whether the model building should happen in two phases. If enabled, the initial invocation of the model
139     * builder will only produce an interim result which may be used to analyze inter-model dependencies before the
140     * final invocation of the model builder is performed.
141     *
142     * @return {@code true} if two-phase building is enabled, {@code false} if the model should be build in a single
143     *         step.
144     */
145    boolean isTwoPhaseBuilding();
146
147    /**
148     * Enables/disables two-phase building. If enabled, the initial invocation of the model builder will only produce an
149     * interim result which may be used to analyze inter-model dependencies before the final invocation of the model
150     * builder is performed.
151     *
152     * @param twoPhaseBuilding {@code true} to enable two-phase building, {@code false} if the model should be build in
153     *            a single step.
154     * @return This request, never {@code null}.
155     */
156    ModelBuildingRequest setTwoPhaseBuilding( boolean twoPhaseBuilding );
157
158    /**
159     * Indicates whether the model should track the line/column number of the model source from which it was parsed.
160     * 
161     * @return {@code true} if location tracking is enabled, {@code false} otherwise.
162     */
163    boolean isLocationTracking();
164
165    /**
166     * Enables/disables the tracking of line/column numbers for the model source being parsed. By default, input
167     * locations are not tracked.
168     * 
169     * @param locationTracking {@code true} to enable location tracking, {@code false} to disable it.
170     * @return This request, never {@code null}.
171     */
172    ModelBuildingRequest setLocationTracking( boolean locationTracking );
173
174    /**
175     * Gets the external profiles that should be considered for model building.
176     *
177     * @return The external profiles that should be considered for model building, never {@code null}.
178     */
179    List<Profile> getProfiles();
180
181    /**
182     * Sets the external profiles that should be considered for model building.
183     *
184     * @param profiles The external profiles that should be considered for model building, may be {@code null}.
185     * @return This request, never {@code null}.
186     */
187    ModelBuildingRequest setProfiles( List<Profile> profiles );
188
189    /**
190     * Gets the identifiers of those profiles that should be activated by explicit demand.
191     *
192     * @return The identifiers of those profiles to activate, never {@code null}.
193     */
194    List<String> getActiveProfileIds();
195
196    /**
197     * Sets the identifiers of those profiles that should be activated by explicit demand.
198     *
199     * @param activeProfileIds The identifiers of those profiles to activate, may be {@code null}.
200     * @return This request, never {@code null}.
201     */
202    ModelBuildingRequest setActiveProfileIds( List<String> activeProfileIds );
203
204    /**
205     * Gets the identifiers of those profiles that should be deactivated by explicit demand.
206     *
207     * @return The identifiers of those profiles to deactivate, never {@code null}.
208     */
209    List<String> getInactiveProfileIds();
210
211    /**
212     * Sets the identifiers of those profiles that should be deactivated by explicit demand.
213     *
214     * @param inactiveProfileIds The identifiers of those profiles to deactivate, may be {@code null}.
215     * @return This request, never {@code null}.
216     */
217    ModelBuildingRequest setInactiveProfileIds( List<String> inactiveProfileIds );
218
219    /**
220     * Gets the system properties to use for interpolation and profile activation. The system properties are collected
221     * from the runtime environment like {@link System#getProperties()} and environment variables.
222     *
223     * @return The system properties, never {@code null}.
224     */
225    Properties getSystemProperties();
226
227    /**
228     * Sets the system properties to use for interpolation and profile activation. The system properties are collected
229     * from the runtime environment like {@link System#getProperties()} and environment variables.
230     *
231     * @param systemProperties The system properties, may be {@code null}.
232     * @return This request, never {@code null}.
233     */
234    ModelBuildingRequest setSystemProperties( Properties systemProperties );
235
236    /**
237     * Gets the user properties to use for interpolation and profile activation. The user properties have been
238     * configured directly by the user on his discretion, e.g. via the {@code -Dkey=value} parameter on the command
239     * line.
240     *
241     * @return The user properties, never {@code null}.
242     */
243    Properties getUserProperties();
244
245    /**
246     * Sets the user properties to use for interpolation and profile activation. The user properties have been
247     * configured directly by the user on his discretion, e.g. via the {@code -Dkey=value} parameter on the command
248     * line.
249     *
250     * @param userProperties The user properties, may be {@code null}.
251     * @return This request, never {@code null}.
252     */
253    ModelBuildingRequest setUserProperties( Properties userProperties );
254
255    /**
256     * Gets the start time of the build.
257     *
258     * @return The start time of the build or {@code null} if unknown.
259     */
260    Date getBuildStartTime();
261
262    /**
263     * Sets the start time of the build.
264     *
265     * @param buildStartTime The start time of the build, may be {@code null}.
266     * @return This request, never {@code null}.
267     */
268    ModelBuildingRequest setBuildStartTime( Date buildStartTime );
269
270    /**
271     * Gets the model resolver to use for resolution of mixins or parents that are not locally reachable from the
272     * project directory.
273     *
274     * @return The model resolver or {@code null} if not set.
275     */
276    ModelResolver getModelResolver();
277
278    /**
279     * Sets the model resolver to use for resolution of mixins or parents that are not locally reachable from the
280     * project directory.
281     *
282     * @param modelResolver The model resolver to use, may be {@code null}.
283     * @return This request, never {@code null}.
284     */
285    ModelBuildingRequest setModelResolver( ModelResolver modelResolver );
286
287    /**
288     * Gets the model building listener to notify during the build process.
289     *
290     * @return The model building listener to notify or {@code null} if none.
291     */
292    ModelBuildingListener getModelBuildingListener();
293
294    /**
295     * Sets the model building listener to notify during the build process.
296     *
297     * @param modelBuildingListener The model building listener to notify, may be {@code null}.
298     * @return This request, never {@code null}.
299     */
300    ModelBuildingRequest setModelBuildingListener( ModelBuildingListener modelBuildingListener );
301
302    /**
303     * Gets the model cache to use for reuse of previously built models.
304     *
305     * @return The model cache or {@code null} if not set.
306     */
307    ModelCache getModelCache();
308
309    /**
310     * Sets the model cache to use for reuse of previously built models. This is an optional component that serves
311     * performance optimizations.
312     *
313     * @param modelCache The model cache to use, may be {@code null}.
314     * @return This request, never {@code null}.
315     */
316    ModelBuildingRequest setModelCache( ModelCache modelCache );
317
318}