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