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