1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package org.apache.maven.model.superpom;
20
21 import javax.inject.Inject;
22 import javax.inject.Named;
23 import javax.inject.Singleton;
24
25 import java.io.IOException;
26 import java.io.InputStream;
27 import java.util.HashMap;
28 import java.util.Map;
29
30 import org.apache.maven.model.InputSource;
31 import org.apache.maven.model.Model;
32 import org.apache.maven.model.building.ModelProcessor;
33
34
35
36
37
38
39 @Named
40 @Singleton
41 @Deprecated(since = "4.0.0")
42 public class DefaultSuperPomProvider implements SuperPomProvider {
43
44
45
46
47 private Model superModel;
48
49 @Inject
50 private ModelProcessor modelProcessor;
51
52 public DefaultSuperPomProvider setModelProcessor(ModelProcessor modelProcessor) {
53 this.modelProcessor = modelProcessor;
54 return this;
55 }
56
57 @Override
58 public Model getSuperModel(String version) {
59 if (superModel == null) {
60 String resource = "/org/apache/maven/model/pom-" + version + ".xml";
61
62 InputStream is = getClass().getResourceAsStream(resource);
63
64 if (is == null) {
65 throw new IllegalStateException("The super POM " + resource + " was not found"
66 + ", please verify the integrity of your Maven installation");
67 }
68
69 try {
70 Map<String, Object> options = new HashMap<>();
71 options.put("xml:4.0.0", "xml:4.0.0");
72
73 String modelId = "org.apache.maven:maven-model-builder:"
74 + this.getClass().getPackage().getImplementationVersion() + ":super-pom";
75 InputSource inputSource = new InputSource();
76 inputSource.setModelId(modelId);
77 inputSource.setLocation(getClass().getResource(resource).toExternalForm());
78 options.put(ModelProcessor.INPUT_SOURCE, inputSource);
79
80 superModel = modelProcessor.read(is, options);
81 } catch (IOException e) {
82 throw new IllegalStateException(
83 "The super POM " + resource + " is damaged"
84 + ", please verify the integrity of your Maven installation",
85 e);
86 }
87 }
88
89 return superModel;
90 }
91 }