View Javadoc
1   package org.apache.maven.model.building;
2   
3   /*
4    * Licensed to the Apache Software Foundation (ASF) under one
5    * or more contributor license agreements.  See the NOTICE file
6    * distributed with this work for additional information
7    * regarding copyright ownership.  The ASF licenses this file
8    * to you under the Apache License, Version 2.0 (the
9    * "License"); you may not use this file except in compliance
10   * with the License.  You may obtain a copy of the License at
11   *
12   *   http://www.apache.org/licenses/LICENSE-2.0
13   *
14   * Unless required by applicable law or agreed to in writing,
15   * software distributed under the License is distributed on an
16   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
17   * KIND, either express or implied.  See the License for the
18   * specific language governing permissions and limitations
19   * under the License.
20   */
21  
22  import java.util.ArrayList;
23  import java.util.HashMap;
24  import java.util.List;
25  import java.util.Map;
26  
27  import org.apache.maven.model.Model;
28  import org.apache.maven.model.Profile;
29  
30  /**
31   * Collects the output of the model builder.
32   * 
33   * @author Benjamin Bentmann
34   */
35  class DefaultModelBuildingResult
36      implements ModelBuildingResult
37  {
38  
39      private Model effectiveModel;
40  
41      private List<String> modelIds;
42  
43      private Map<String, Model> rawModels;
44  
45      private Map<String, List<Profile>> activePomProfiles;
46  
47      private List<Profile> activeExternalProfiles;
48  
49      private List<ModelProblem> problems;
50  
51      public DefaultModelBuildingResult()
52      {
53          modelIds = new ArrayList<String>();
54          rawModels = new HashMap<String, Model>();
55          activePomProfiles = new HashMap<String, List<Profile>>();
56          activeExternalProfiles = new ArrayList<Profile>();
57          problems = new ArrayList<ModelProblem>();
58      }
59  
60      public Model getEffectiveModel()
61      {
62          return effectiveModel;
63      }
64  
65      public DefaultModelBuildingResult setEffectiveModel( Model model )
66      {
67          this.effectiveModel = model;
68  
69          return this;
70      }
71  
72      public List<String> getModelIds()
73      {
74          return modelIds;
75      }
76  
77      public DefaultModelBuildingResult addModelId( String modelId )
78      {
79          if ( modelId == null )
80          {
81              throw new IllegalArgumentException( "no model identifier specified" );
82          }
83  
84          modelIds.add( modelId );
85  
86          return this;
87      }
88  
89      public Model getRawModel()
90      {
91          return rawModels.get( modelIds.get( 0 ) );
92      }
93  
94      public Model getRawModel( String modelId )
95      {
96          return rawModels.get( modelId );
97      }
98  
99      public DefaultModelBuildingResult setRawModel( String modelId, Model rawModel )
100     {
101         if ( modelId == null )
102         {
103             throw new IllegalArgumentException( "no model identifier specified" );
104         }
105 
106         rawModels.put( modelId, rawModel );
107 
108         return this;
109     }
110 
111     public List<Profile> getActivePomProfiles( String modelId )
112     {
113         return activePomProfiles.get( modelId );
114     }
115 
116     public DefaultModelBuildingResult setActivePomProfiles( String modelId, List<Profile> activeProfiles )
117     {
118         if ( modelId == null )
119         {
120             throw new IllegalArgumentException( "no model identifier specified" );
121         }
122 
123         if ( activeProfiles != null )
124         {
125             this.activePomProfiles.put( modelId, new ArrayList<Profile>( activeProfiles ) );
126         }
127         else
128         {
129             this.activePomProfiles.remove( modelId );
130         }
131 
132         return this;
133     }
134 
135     public List<Profile> getActiveExternalProfiles()
136     {
137         return activeExternalProfiles;
138     }
139 
140     public DefaultModelBuildingResult setActiveExternalProfiles( List<Profile> activeProfiles )
141     {
142         if ( activeProfiles != null )
143         {
144             this.activeExternalProfiles = new ArrayList<Profile>( activeProfiles );
145         }
146         else
147         {
148             this.activeExternalProfiles.clear();
149         }
150 
151         return this;
152     }
153 
154     public List<ModelProblem> getProblems()
155     {
156         return problems;
157     }
158 
159     public DefaultModelBuildingResult setProblems( List<ModelProblem> problems )
160     {
161         if ( problems != null )
162         {
163             this.problems = new ArrayList<ModelProblem>( problems );
164         }
165         else
166         {
167             this.problems.clear();
168         }
169 
170         return this;
171     }
172 
173 }