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      @Override
57      public Model getSuperModel( String version )
58      {
59          if ( superModel == null )
60          {
61              String resource = "/org/apache/maven/model/pom-" + version + ".xml";
62  
63              InputStream is = getClass().getResourceAsStream( resource );
64  
65              if ( is == null )
66              {
67                  throw new IllegalStateException( "The super POM " + resource + " was not found"
68                      + ", please verify the integrity of your Maven installation" );
69              }
70  
71              try
72              {
73                  Map<String, String> options = new HashMap<>();
74                  options.put( "xml:4.0.0", "xml:4.0.0" );
75                  superModel = modelProcessor.read( is, options );
76              }
77              catch ( IOException e )
78              {
79                  throw new IllegalStateException( "The super POM " + resource + " is damaged"
80                      + ", please verify the integrity of your Maven installation", e );
81              }
82          }
83  
84          return superModel;
85      }
86  
87  }