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