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