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 org.apache.maven.model.InputSource;
28 import org.apache.maven.model.Model;
29 import org.apache.maven.model.building.ModelProcessor;
30 import org.codehaus.plexus.component.annotations.Component;
31 import org.codehaus.plexus.component.annotations.Requirement;
32
33
34
35
36
37
38 @Component( role = SuperPomProvider.class )
39 public class DefaultSuperPomProvider
40 implements SuperPomProvider
41 {
42
43
44
45
46 private Model superModel;
47
48 @Requirement
49 private ModelProcessor modelProcessor;
50
51 public DefaultSuperPomProvider setModelProcessor( ModelProcessor modelProcessor )
52 {
53 this.modelProcessor = modelProcessor;
54 return this;
55 }
56
57 @Override
58 public Model getSuperModel( String version )
59 {
60 if ( superModel == null )
61 {
62 String resource = "/org/apache/maven/model/pom-" + version + ".xml";
63
64 InputStream is = getClass().getResourceAsStream( resource );
65
66 if ( is == null )
67 {
68 throw new IllegalStateException( "The super POM " + resource + " was not found"
69 + ", please verify the integrity of your Maven installation" );
70 }
71
72 try
73 {
74 Map<String, Object> options = new HashMap<>();
75 options.put( "xml:4.0.0", "xml:4.0.0" );
76
77 String modelId = "org.apache.maven:maven-model-builder:"
78 + this.getClass().getPackage().getImplementationVersion() + ":super-pom";
79 InputSource inputSource = new InputSource();
80 inputSource.setModelId( modelId );
81 inputSource.setLocation( getClass().getResource( resource ).toExternalForm() );
82 options.put( ModelProcessor.INPUT_SOURCE, inputSource );
83
84 superModel = modelProcessor.read( is, options );
85 }
86 catch ( IOException e )
87 {
88 throw new IllegalStateException( "The super POM " + resource + " is damaged"
89 + ", please verify the integrity of your Maven installation", e );
90 }
91 }
92
93 return superModel;
94 }
95
96 }