1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package org.apache.maven.model.building;
20
21 import java.util.Arrays;
22
23 import org.apache.maven.api.Version;
24 import org.apache.maven.api.VersionRange;
25 import org.apache.maven.api.spi.ModelParser;
26 import org.apache.maven.model.Model;
27 import org.apache.maven.model.composition.DefaultDependencyManagementImporter;
28 import org.apache.maven.model.composition.DependencyManagementImporter;
29 import org.apache.maven.model.inheritance.DefaultInheritanceAssembler;
30 import org.apache.maven.model.inheritance.InheritanceAssembler;
31 import org.apache.maven.model.interpolation.DefaultModelVersionProcessor;
32 import org.apache.maven.model.interpolation.ModelInterpolator;
33 import org.apache.maven.model.interpolation.ModelVersionProcessor;
34 import org.apache.maven.model.interpolation.StringVisitorModelInterpolator;
35 import org.apache.maven.model.io.DefaultModelReader;
36 import org.apache.maven.model.io.ModelReader;
37 import org.apache.maven.model.locator.DefaultModelLocator;
38 import org.apache.maven.model.locator.ModelLocator;
39 import org.apache.maven.model.management.DefaultDependencyManagementInjector;
40 import org.apache.maven.model.management.DefaultPluginManagementInjector;
41 import org.apache.maven.model.management.DependencyManagementInjector;
42 import org.apache.maven.model.management.PluginManagementInjector;
43 import org.apache.maven.model.normalization.DefaultModelNormalizer;
44 import org.apache.maven.model.normalization.ModelNormalizer;
45 import org.apache.maven.model.path.DefaultModelPathTranslator;
46 import org.apache.maven.model.path.DefaultModelUrlNormalizer;
47 import org.apache.maven.model.path.DefaultPathTranslator;
48 import org.apache.maven.model.path.DefaultUrlNormalizer;
49 import org.apache.maven.model.path.ModelPathTranslator;
50 import org.apache.maven.model.path.ModelUrlNormalizer;
51 import org.apache.maven.model.path.PathTranslator;
52 import org.apache.maven.model.path.ProfileActivationFilePathInterpolator;
53 import org.apache.maven.model.path.UrlNormalizer;
54 import org.apache.maven.model.plugin.DefaultPluginConfigurationExpander;
55 import org.apache.maven.model.plugin.DefaultReportConfigurationExpander;
56 import org.apache.maven.model.plugin.DefaultReportingConverter;
57 import org.apache.maven.model.plugin.LifecycleBindingsInjector;
58 import org.apache.maven.model.plugin.PluginConfigurationExpander;
59 import org.apache.maven.model.plugin.ReportConfigurationExpander;
60 import org.apache.maven.model.plugin.ReportingConverter;
61 import org.apache.maven.model.profile.DefaultProfileInjector;
62 import org.apache.maven.model.profile.DefaultProfileSelector;
63 import org.apache.maven.model.profile.ProfileInjector;
64 import org.apache.maven.model.profile.ProfileSelector;
65 import org.apache.maven.model.profile.activation.FileProfileActivator;
66 import org.apache.maven.model.profile.activation.JdkVersionProfileActivator;
67 import org.apache.maven.model.profile.activation.OperatingSystemProfileActivator;
68 import org.apache.maven.model.profile.activation.ProfileActivator;
69 import org.apache.maven.model.profile.activation.PropertyProfileActivator;
70 import org.apache.maven.model.root.DefaultRootLocator;
71 import org.apache.maven.model.root.RootLocator;
72 import org.apache.maven.model.superpom.DefaultSuperPomProvider;
73 import org.apache.maven.model.superpom.SuperPomProvider;
74 import org.apache.maven.model.validation.DefaultModelValidator;
75 import org.apache.maven.model.validation.ModelValidator;
76 import org.apache.maven.model.version.VersionParser;
77
78 import static java.util.Objects.requireNonNull;
79
80
81
82
83
84
85
86
87
88 public class DefaultModelBuilderFactory {
89
90 private ModelProcessor modelProcessor;
91 private ModelValidator modelValidator;
92 private ModelNormalizer modelNormalizer;
93 private ModelInterpolator modelInterpolator;
94 private ModelPathTranslator modelPathTranslator;
95 private ModelUrlNormalizer modelUrlNormalizer;
96 private SuperPomProvider superPomProvider;
97 private InheritanceAssembler inheritanceAssembler;
98 private ProfileSelector profileSelector;
99 private ProfileInjector profileInjector;
100 private PluginManagementInjector pluginManagementInjector;
101 private DependencyManagementInjector dependencyManagementInjector;
102 private DependencyManagementImporter dependencyManagementImporter;
103 private LifecycleBindingsInjector lifecycleBindingsInjector;
104 private PluginConfigurationExpander pluginConfigurationExpander;
105 private ReportConfigurationExpander reportConfigurationExpander;
106 private ProfileActivationFilePathInterpolator profileActivationFilePathInterpolator;
107 private ModelVersionProcessor versionProcessor;
108 private ModelSourceTransformer transformer;
109 private VersionParser versionParser;
110
111 public DefaultModelBuilderFactory setModelProcessor(ModelProcessor modelProcessor) {
112 this.modelProcessor = modelProcessor;
113 return this;
114 }
115
116 public DefaultModelBuilderFactory setModelValidator(ModelValidator modelValidator) {
117 this.modelValidator = modelValidator;
118 return this;
119 }
120
121 public DefaultModelBuilderFactory setModelNormalizer(ModelNormalizer modelNormalizer) {
122 this.modelNormalizer = modelNormalizer;
123 return this;
124 }
125
126 public DefaultModelBuilderFactory setModelInterpolator(ModelInterpolator modelInterpolator) {
127 this.modelInterpolator = modelInterpolator;
128 return this;
129 }
130
131 public DefaultModelBuilderFactory setModelPathTranslator(ModelPathTranslator modelPathTranslator) {
132 this.modelPathTranslator = modelPathTranslator;
133 return this;
134 }
135
136 public DefaultModelBuilderFactory setModelUrlNormalizer(ModelUrlNormalizer modelUrlNormalizer) {
137 this.modelUrlNormalizer = modelUrlNormalizer;
138 return this;
139 }
140
141 public DefaultModelBuilderFactory setSuperPomProvider(SuperPomProvider superPomProvider) {
142 this.superPomProvider = superPomProvider;
143 return this;
144 }
145
146 public DefaultModelBuilderFactory setInheritanceAssembler(InheritanceAssembler inheritanceAssembler) {
147 this.inheritanceAssembler = inheritanceAssembler;
148 return this;
149 }
150
151 public DefaultModelBuilderFactory setProfileSelector(ProfileSelector profileSelector) {
152 this.profileSelector = profileSelector;
153 return this;
154 }
155
156 public DefaultModelBuilderFactory setProfileInjector(ProfileInjector profileInjector) {
157 this.profileInjector = profileInjector;
158 return this;
159 }
160
161 public DefaultModelBuilderFactory setPluginManagementInjector(PluginManagementInjector pluginManagementInjector) {
162 this.pluginManagementInjector = pluginManagementInjector;
163 return this;
164 }
165
166 public DefaultModelBuilderFactory setDependencyManagementInjector(
167 DependencyManagementInjector dependencyManagementInjector) {
168 this.dependencyManagementInjector = dependencyManagementInjector;
169 return this;
170 }
171
172 public DefaultModelBuilderFactory setDependencyManagementImporter(
173 DependencyManagementImporter dependencyManagementImporter) {
174 this.dependencyManagementImporter = dependencyManagementImporter;
175 return this;
176 }
177
178 public DefaultModelBuilderFactory setLifecycleBindingsInjector(
179 LifecycleBindingsInjector lifecycleBindingsInjector) {
180 this.lifecycleBindingsInjector = lifecycleBindingsInjector;
181 return this;
182 }
183
184 public DefaultModelBuilderFactory setPluginConfigurationExpander(
185 PluginConfigurationExpander pluginConfigurationExpander) {
186 this.pluginConfigurationExpander = pluginConfigurationExpander;
187 return this;
188 }
189
190 public DefaultModelBuilderFactory setReportConfigurationExpander(
191 ReportConfigurationExpander reportConfigurationExpander) {
192 this.reportConfigurationExpander = reportConfigurationExpander;
193 return this;
194 }
195
196 @Deprecated
197 public DefaultModelBuilderFactory setReportingConverter(ReportingConverter reportingConverter) {
198 return this;
199 }
200
201 public DefaultModelBuilderFactory setProfileActivationFilePathInterpolator(
202 ProfileActivationFilePathInterpolator profileActivationFilePathInterpolator) {
203 this.profileActivationFilePathInterpolator = profileActivationFilePathInterpolator;
204 return this;
205 }
206
207 public DefaultModelBuilderFactory setVersionProcessor(ModelVersionProcessor versionProcessor) {
208 this.versionProcessor = versionProcessor;
209 return this;
210 }
211
212 public DefaultModelBuilderFactory setTransformer(ModelSourceTransformer transformer) {
213 this.transformer = transformer;
214 return this;
215 }
216
217 public DefaultModelBuilderFactory setModelVersionParser(VersionParser versionParser) {
218 this.versionParser = versionParser;
219 return this;
220 }
221
222 protected ModelProcessor newModelProcessor() {
223 return new DefaultModelProcessor(Arrays.asList(newModelParsers()), newModelLocator(), newModelReader());
224 }
225
226 protected ModelParser[] newModelParsers() {
227 return new ModelParser[0];
228 }
229
230 protected ModelLocator newModelLocator() {
231 return new DefaultModelLocator();
232 }
233
234 protected ModelReader newModelReader() {
235 return new DefaultModelReader(newModelSourceTransformer());
236 }
237
238 protected ProfileSelector newProfileSelector() {
239 return new DefaultProfileSelector(Arrays.asList(newProfileActivators()));
240 }
241
242 protected ProfileActivator[] newProfileActivators() {
243 return new ProfileActivator[] {
244 new JdkVersionProfileActivator(),
245 new OperatingSystemProfileActivator(),
246 new PropertyProfileActivator(),
247 new FileProfileActivator(newProfileActivationFilePathInterpolator())
248 };
249 }
250
251 protected ProfileActivationFilePathInterpolator newProfileActivationFilePathInterpolator() {
252 return new ProfileActivationFilePathInterpolator(newPathTranslator(), newRootLocator());
253 }
254
255 protected UrlNormalizer newUrlNormalizer() {
256 return new DefaultUrlNormalizer();
257 }
258
259 protected PathTranslator newPathTranslator() {
260 return new DefaultPathTranslator();
261 }
262
263 protected RootLocator newRootLocator() {
264 return new DefaultRootLocator();
265 }
266
267 protected ModelInterpolator newModelInterpolator() {
268 UrlNormalizer normalizer = newUrlNormalizer();
269 PathTranslator pathTranslator = newPathTranslator();
270 RootLocator rootLocator = newRootLocator();
271 return new StringVisitorModelInterpolator(pathTranslator, normalizer, rootLocator);
272 }
273
274 protected ModelVersionProcessor newModelVersionPropertiesProcessor() {
275 return new DefaultModelVersionProcessor();
276 }
277
278 protected ModelValidator newModelValidator() {
279 ModelVersionProcessor processor = newModelVersionPropertiesProcessor();
280 return new DefaultModelValidator(processor);
281 }
282
283 protected ModelNormalizer newModelNormalizer() {
284 return new DefaultModelNormalizer();
285 }
286
287 protected ModelPathTranslator newModelPathTranslator() {
288 return new DefaultModelPathTranslator(newPathTranslator());
289 }
290
291 protected ModelUrlNormalizer newModelUrlNormalizer() {
292 return new DefaultModelUrlNormalizer(newUrlNormalizer());
293 }
294
295 protected InheritanceAssembler newInheritanceAssembler() {
296 return new DefaultInheritanceAssembler();
297 }
298
299 protected ProfileInjector newProfileInjector() {
300 return new DefaultProfileInjector();
301 }
302
303 protected SuperPomProvider newSuperPomProvider() {
304 return new DefaultSuperPomProvider(newModelProcessor());
305 }
306
307 protected DependencyManagementImporter newDependencyManagementImporter() {
308 return new DefaultDependencyManagementImporter();
309 }
310
311 protected DependencyManagementInjector newDependencyManagementInjector() {
312 return new DefaultDependencyManagementInjector();
313 }
314
315 protected LifecycleBindingsInjector newLifecycleBindingsInjector() {
316 return new StubLifecycleBindingsInjector();
317 }
318
319 protected PluginManagementInjector newPluginManagementInjector() {
320 return new DefaultPluginManagementInjector();
321 }
322
323 protected PluginConfigurationExpander newPluginConfigurationExpander() {
324 return new DefaultPluginConfigurationExpander();
325 }
326
327 protected ReportConfigurationExpander newReportConfigurationExpander() {
328 return new DefaultReportConfigurationExpander();
329 }
330
331 @Deprecated
332 protected ReportingConverter newReportingConverter() {
333 return new DefaultReportingConverter();
334 }
335
336 private ModelSourceTransformer newModelSourceTransformer() {
337 return new BuildModelSourceTransformer();
338 }
339
340 private VersionParser newModelVersionParser() {
341
342
343 return new VersionParser() {
344 @Override
345 public Version parseVersion(String version) {
346 requireNonNull(version, "version");
347 return new Version() {
348 @Override
349 public String asString() {
350 return version;
351 }
352
353 @Override
354 public int compareTo(Version o) {
355 return version.compareTo(o.asString());
356 }
357 };
358 }
359
360 @Override
361 public VersionRange parseVersionRange(String range) {
362 throw new IllegalArgumentException("ranges not supported by this parser");
363 }
364 };
365 }
366
367
368
369
370
371
372 public DefaultModelBuilder newInstance() {
373 return new DefaultModelBuilder(
374 modelProcessor != null ? modelProcessor : newModelProcessor(),
375 modelValidator != null ? modelValidator : newModelValidator(),
376 modelNormalizer != null ? modelNormalizer : newModelNormalizer(),
377 modelInterpolator != null ? modelInterpolator : newModelInterpolator(),
378 modelPathTranslator != null ? modelPathTranslator : newModelPathTranslator(),
379 modelUrlNormalizer != null ? modelUrlNormalizer : newModelUrlNormalizer(),
380 superPomProvider != null ? superPomProvider : newSuperPomProvider(),
381 inheritanceAssembler != null ? inheritanceAssembler : newInheritanceAssembler(),
382 profileSelector != null ? profileSelector : newProfileSelector(),
383 profileInjector != null ? profileInjector : newProfileInjector(),
384 pluginManagementInjector != null ? pluginManagementInjector : newPluginManagementInjector(),
385 dependencyManagementInjector != null ? dependencyManagementInjector : newDependencyManagementInjector(),
386 dependencyManagementImporter != null ? dependencyManagementImporter : newDependencyManagementImporter(),
387 lifecycleBindingsInjector != null ? lifecycleBindingsInjector : newLifecycleBindingsInjector(),
388 pluginConfigurationExpander != null ? pluginConfigurationExpander : newPluginConfigurationExpander(),
389 reportConfigurationExpander != null ? reportConfigurationExpander : newReportConfigurationExpander(),
390 profileActivationFilePathInterpolator != null
391 ? profileActivationFilePathInterpolator
392 : newProfileActivationFilePathInterpolator(),
393 versionProcessor != null ? versionProcessor : newModelVersionPropertiesProcessor(),
394 transformer != null ? transformer : newModelSourceTransformer(),
395 versionParser != null ? versionParser : newModelVersionParser());
396 }
397
398 private static class StubLifecycleBindingsInjector implements LifecycleBindingsInjector {
399
400 @Override
401 public void injectLifecycleBindings(
402 Model model, ModelBuildingRequest request, ModelProblemCollector problems) {}
403 }
404 }