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.Iterator;
22  import java.util.Map;
23  import java.util.stream.Collectors;
24  import org.apache.maven.api.model.Build;
25  import org.apache.maven.api.model.BuildBase;
26  import org.apache.maven.api.model.CiManagement;
27  import org.apache.maven.api.model.Dependency;
28  import org.apache.maven.api.model.DependencyManagement;
29  import org.apache.maven.api.model.Model;
30  import org.apache.maven.api.model.ModelBase;
31  import org.apache.maven.api.model.Plugin;
32  import org.apache.maven.api.model.PluginContainer;
33  import org.apache.maven.api.model.Profile;
34  import org.apache.maven.api.model.ReportPlugin;
35  import org.apache.maven.api.model.Reporting;
36  import org.apache.maven.model.v4.MavenMerger;
37  
38  /**
39   * As long as Maven controls the BuildPomXMLFilter, the entities that need merging are known.
40   * All others can simply be copied from source to target to restore the locationTracker
41   *
42   * @author Robert Scholte
43   * @since 4.0.0
44   */
45  class FileToRawModelMerger extends MavenMerger {
46  
47      @Override
48      protected void mergeBuild_Extensions(
49              Build.Builder builder, Build target, Build source, boolean sourceDominant, Map<Object, Object> context) {
50          // don't merge
51      }
52  
53      @Override
54      protected void mergeBuildBase_Resources(
55              BuildBase.Builder builder,
56              BuildBase target,
57              BuildBase source,
58              boolean sourceDominant,
59              Map<Object, Object> context) {
60          // don't merge
61      }
62  
63      @Override
64      protected void mergeBuildBase_TestResources(
65              BuildBase.Builder builder,
66              BuildBase target,
67              BuildBase source,
68              boolean sourceDominant,
69              Map<Object, Object> context) {
70          // don't merge
71      }
72  
73      @Override
74      protected void mergeCiManagement_Notifiers(
75              CiManagement.Builder builder,
76              CiManagement target,
77              CiManagement source,
78              boolean sourceDominant,
79              Map<Object, Object> context) {
80          // don't merge
81      }
82  
83      @Override
84      protected void mergeDependencyManagement_Dependencies(
85              DependencyManagement.Builder builder,
86              DependencyManagement target,
87              DependencyManagement source,
88              boolean sourceDominant,
89              Map<Object, Object> context) {
90          Iterator<Dependency> sourceIterator = source.getDependencies().iterator();
91          builder.dependencies(target.getDependencies().stream()
92                  .map(d -> mergeDependency(d, sourceIterator.next(), sourceDominant, context))
93                  .collect(Collectors.toList()));
94      }
95  
96      @Override
97      protected void mergeDependency_Exclusions(
98              Dependency.Builder builder,
99              Dependency target,
100             Dependency source,
101             boolean sourceDominant,
102             Map<Object, Object> context) {
103         // don't merge
104     }
105 
106     @Override
107     protected void mergeModel_Contributors(
108             Model.Builder builder, Model target, Model source, boolean sourceDominant, Map<Object, Object> context) {
109         // don't merge
110     }
111 
112     @Override
113     protected void mergeModel_Developers(
114             Model.Builder builder, Model target, Model source, boolean sourceDominant, Map<Object, Object> context) {
115         // don't merge
116     }
117 
118     @Override
119     protected void mergeModel_Licenses(
120             Model.Builder builder, Model target, Model source, boolean sourceDominant, Map<Object, Object> context) {
121         // don't merge
122     }
123 
124     @Override
125     protected void mergeModel_MailingLists(
126             Model.Builder builder, Model target, Model source, boolean sourceDominant, Map<Object, Object> context) {
127         // don't merge
128     }
129 
130     @Override
131     protected void mergeModel_Profiles(
132             Model.Builder builder, Model target, Model source, boolean sourceDominant, Map<Object, Object> context) {
133         Iterator<Profile> sourceIterator = source.getProfiles().iterator();
134         builder.profiles(target.getProfiles().stream()
135                 .map(d -> mergeProfile(d, sourceIterator.next(), sourceDominant, context))
136                 .collect(Collectors.toList()));
137     }
138 
139     @Override
140     protected void mergeModelBase_Dependencies(
141             ModelBase.Builder builder,
142             ModelBase target,
143             ModelBase source,
144             boolean sourceDominant,
145             Map<Object, Object> context) {
146         Iterator<Dependency> sourceIterator = source.getDependencies().iterator();
147         builder.dependencies(target.getDependencies().stream()
148                 .map(d -> mergeDependency(d, sourceIterator.next(), sourceDominant, context))
149                 .collect(Collectors.toList()));
150     }
151 
152     @Override
153     protected void mergeModelBase_PluginRepositories(
154             ModelBase.Builder builder,
155             ModelBase target,
156             ModelBase source,
157             boolean sourceDominant,
158             Map<Object, Object> context) {
159         builder.pluginRepositories(source.getPluginRepositories());
160     }
161 
162     @Override
163     protected void mergeModelBase_Repositories(
164             ModelBase.Builder builder,
165             ModelBase target,
166             ModelBase source,
167             boolean sourceDominant,
168             Map<Object, Object> context) {
169         // don't merge
170     }
171 
172     @Override
173     protected void mergePlugin_Dependencies(
174             Plugin.Builder builder, Plugin target, Plugin source, boolean sourceDominant, Map<Object, Object> context) {
175         Iterator<Dependency> sourceIterator = source.getDependencies().iterator();
176         builder.dependencies(target.getDependencies().stream()
177                 .map(d -> mergeDependency(d, sourceIterator.next(), sourceDominant, context))
178                 .collect(Collectors.toList()));
179     }
180 
181     @Override
182     protected void mergePlugin_Executions(
183             Plugin.Builder builder, Plugin target, Plugin source, boolean sourceDominant, Map<Object, Object> context) {
184         // don't merge
185     }
186 
187     @Override
188     protected void mergeReporting_Plugins(
189             Reporting.Builder builder,
190             Reporting target,
191             Reporting source,
192             boolean sourceDominant,
193             Map<Object, Object> context) {
194         // don't merge
195     }
196 
197     @Override
198     protected void mergeReportPlugin_ReportSets(
199             ReportPlugin.Builder builder,
200             ReportPlugin target,
201             ReportPlugin source,
202             boolean sourceDominant,
203             Map<Object, Object> context) {
204         // don't merge
205     }
206 
207     @Override
208     protected void mergePluginContainer_Plugins(
209             PluginContainer.Builder builder,
210             PluginContainer target,
211             PluginContainer source,
212             boolean sourceDominant,
213             Map<Object, Object> context) {
214         // don't merge
215     }
216 }