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