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