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.interpolation;
20  
21  import javax.inject.Named;
22  import javax.inject.Singleton;
23  
24  import java.io.File;
25  import java.util.HashMap;
26  import java.util.List;
27  import java.util.ListIterator;
28  import java.util.Map;
29  import java.util.Properties;
30  
31  import org.apache.maven.model.Activation;
32  import org.apache.maven.model.ActivationFile;
33  import org.apache.maven.model.ActivationOS;
34  import org.apache.maven.model.ActivationProperty;
35  import org.apache.maven.model.Build;
36  import org.apache.maven.model.BuildBase;
37  import org.apache.maven.model.CiManagement;
38  import org.apache.maven.model.Contributor;
39  import org.apache.maven.model.Dependency;
40  import org.apache.maven.model.DependencyManagement;
41  import org.apache.maven.model.Developer;
42  import org.apache.maven.model.DistributionManagement;
43  import org.apache.maven.model.Exclusion;
44  import org.apache.maven.model.Extension;
45  import org.apache.maven.model.IssueManagement;
46  import org.apache.maven.model.License;
47  import org.apache.maven.model.MailingList;
48  import org.apache.maven.model.Model;
49  import org.apache.maven.model.ModelBase;
50  import org.apache.maven.model.Notifier;
51  import org.apache.maven.model.Organization;
52  import org.apache.maven.model.Parent;
53  import org.apache.maven.model.Plugin;
54  import org.apache.maven.model.PluginExecution;
55  import org.apache.maven.model.PluginManagement;
56  import org.apache.maven.model.Prerequisites;
57  import org.apache.maven.model.Profile;
58  import org.apache.maven.model.Relocation;
59  import org.apache.maven.model.ReportPlugin;
60  import org.apache.maven.model.ReportSet;
61  import org.apache.maven.model.Reporting;
62  import org.apache.maven.model.Repository;
63  import org.apache.maven.model.RepositoryBase;
64  import org.apache.maven.model.RepositoryPolicy;
65  import org.apache.maven.model.Resource;
66  import org.apache.maven.model.Scm;
67  import org.apache.maven.model.Site;
68  import org.apache.maven.model.building.ModelBuildingRequest;
69  import org.apache.maven.model.building.ModelProblem.Severity;
70  import org.apache.maven.model.building.ModelProblem.Version;
71  import org.apache.maven.model.building.ModelProblemCollector;
72  import org.apache.maven.model.building.ModelProblemCollectorRequest;
73  import org.codehaus.plexus.interpolation.InterpolationException;
74  import org.codehaus.plexus.interpolation.InterpolationPostProcessor;
75  import org.codehaus.plexus.interpolation.RecursionInterceptor;
76  import org.codehaus.plexus.interpolation.StringSearchInterpolator;
77  import org.codehaus.plexus.interpolation.ValueSource;
78  import org.codehaus.plexus.util.xml.Xpp3Dom;
79  
80  /**
81   * StringVisitorModelInterpolator
82   *
83   * @since 3.6.2
84   */
85  @Named
86  @Singleton
87  public class StringVisitorModelInterpolator extends AbstractStringBasedModelInterpolator {
88  
89      interface InnerInterpolator {
90          String interpolate(String value);
91      }
92  
93      @Override
94      public Model interpolateModel(
95              Model model, File projectDir, ModelBuildingRequest config, ModelProblemCollector problems) {
96          List<? extends ValueSource> valueSources = createValueSources(model, projectDir, config, problems);
97          List<? extends InterpolationPostProcessor> postProcessors = createPostProcessors(model, projectDir, config);
98  
99          InnerInterpolator innerInterpolator = createInterpolator(valueSources, postProcessors, problems);
100 
101         new ModelVisitor(innerInterpolator).visit(model);
102 
103         return model;
104     }
105 
106     private InnerInterpolator createInterpolator(
107             List<? extends ValueSource> valueSources,
108             List<? extends InterpolationPostProcessor> postProcessors,
109             final ModelProblemCollector problems) {
110         final Map<String, String> cache = new HashMap<>();
111         final StringSearchInterpolator interpolator = new StringSearchInterpolator();
112         interpolator.setCacheAnswers(true);
113         for (ValueSource vs : valueSources) {
114             interpolator.addValueSource(vs);
115         }
116         for (InterpolationPostProcessor postProcessor : postProcessors) {
117             interpolator.addPostProcessor(postProcessor);
118         }
119         final RecursionInterceptor recursionInterceptor = createRecursionInterceptor();
120         return new InnerInterpolator() {
121             @Override
122             public String interpolate(String value) {
123                 if (value != null && value.contains("${")) {
124                     String c = cache.get(value);
125                     if (c == null) {
126                         try {
127                             c = interpolator.interpolate(value, recursionInterceptor);
128                         } catch (InterpolationException e) {
129                             problems.add(new ModelProblemCollectorRequest(Severity.ERROR, Version.BASE)
130                                     .setMessage(e.getMessage())
131                                     .setException(e));
132                         }
133                         cache.put(value, c);
134                     }
135                     return c;
136                 }
137                 return value;
138             }
139         };
140     }
141 
142     @SuppressWarnings("StringEquality")
143     private static final class ModelVisitor {
144         private final InnerInterpolator interpolator;
145 
146         ModelVisitor(InnerInterpolator interpolator) {
147             this.interpolator = interpolator;
148         }
149 
150         void visit(Model model) {
151             if (model != null) {
152                 visit((ModelBase) model);
153                 // ModelVersion
154                 String orgModelVersion = model.getModelVersion();
155                 String intModelVersion = interpolate(orgModelVersion);
156                 if (orgModelVersion != intModelVersion) {
157                     model.setModelVersion(intModelVersion);
158                 }
159                 visit(model.getParent());
160                 // GroupId
161                 String orgGroupId = model.getGroupId();
162                 String intGroupId = interpolate(orgGroupId);
163                 if (orgGroupId != intGroupId) {
164                     model.setGroupId(intGroupId);
165                 }
166                 // ArtifactId
167                 String orgArtifactId = model.getArtifactId();
168                 String intArtifactId = interpolate(orgArtifactId);
169                 if (orgArtifactId != intArtifactId) {
170                     model.setArtifactId(intArtifactId);
171                 }
172                 // Version
173                 String orgVersion = model.getVersion();
174                 String intVersion = interpolate(orgVersion);
175                 if (orgVersion != intVersion) {
176                     model.setVersion(intVersion);
177                 }
178 
179                 // Packaging
180                 String orgPackaging = model.getPackaging();
181                 String intPackaging = interpolate(orgPackaging);
182                 if (orgPackaging != intPackaging) {
183                     model.setPackaging(intPackaging);
184                 }
185                 // Name
186                 String orgName = model.getName();
187                 String intName = interpolate(orgName);
188                 if (orgName != intName) {
189                     model.setName(intName);
190                 }
191                 // Description
192                 String orgDescription = model.getDescription();
193                 String intDescription = interpolate(orgDescription);
194                 if (orgDescription != intDescription) {
195                     model.setDescription(intDescription);
196                 }
197                 // Url
198                 String orgUrl = model.getUrl();
199                 String intUrl = interpolate(orgUrl);
200                 if (orgUrl != intUrl) {
201                     model.setUrl(intUrl);
202                 }
203                 // ChildProjectUrlInheritAppendPath
204                 String orgChildProjectUrlInheritAppendPath = model.getChildProjectUrlInheritAppendPath();
205                 String intChildProjectUrlInheritAppendPath = interpolate(orgChildProjectUrlInheritAppendPath);
206                 if (orgChildProjectUrlInheritAppendPath != intChildProjectUrlInheritAppendPath) {
207                     model.setChildProjectUrlInheritAppendPath(intChildProjectUrlInheritAppendPath);
208                 }
209                 // InceptionYear
210                 String orgInceptionYear = model.getInceptionYear();
211                 String intInceptionYear = interpolate(orgInceptionYear);
212                 if (orgInceptionYear != intInceptionYear) {
213                     model.setInceptionYear(intInceptionYear);
214                 }
215                 visit(model.getOrganization());
216                 for (License license : model.getLicenses()) {
217                     visit(license);
218                 }
219                 for (Developer developer : model.getDevelopers()) {
220                     visit(developer);
221                 }
222                 for (Contributor contributor : model.getContributors()) {
223                     visit(contributor);
224                 }
225                 for (MailingList mailingList : model.getMailingLists()) {
226                     visit(mailingList);
227                 }
228                 visit(model.getPrerequisites());
229                 visit(model.getScm());
230                 visit(model.getIssueManagement());
231                 visit(model.getCiManagement());
232                 visit(model.getBuild());
233                 for (Profile profile : model.getProfiles()) {
234                     visit(profile);
235                 }
236             }
237         }
238 
239         private void visit(Parent parent) {
240             if (parent != null) {
241                 String org, val;
242                 // GroupId
243                 org = parent.getGroupId();
244                 val = interpolate(org);
245                 if (org != val) {
246                     parent.setGroupId(val);
247                 }
248                 // ArtifactId
249                 org = parent.getArtifactId();
250                 val = interpolate(org);
251                 if (org != val) {
252                     parent.setArtifactId(val);
253                 }
254                 // Version
255                 org = parent.getVersion();
256                 val = interpolate(org);
257                 if (org != val) {
258                     parent.setVersion(val);
259                 }
260                 // RelativePath
261                 org = parent.getRelativePath();
262                 val = interpolate(org);
263                 if (org != val) {
264                     parent.setRelativePath(val);
265                 }
266             }
267         }
268 
269         private void visit(Organization organization) {
270             if (organization != null) {
271                 String org, val;
272                 // Name
273                 org = organization.getName();
274                 val = interpolate(org);
275                 if (org != val) {
276                     organization.setName(val);
277                 }
278                 // Url
279                 org = organization.getUrl();
280                 val = interpolate(org);
281                 if (org != val) {
282                     organization.setUrl(val);
283                 }
284             }
285         }
286 
287         private void visit(License license) {
288             if (license != null) {
289                 String org, val;
290                 // Name
291                 org = license.getName();
292                 val = interpolate(org);
293                 if (org != val) {
294                     license.setName(val);
295                 }
296                 // Url
297                 org = license.getUrl();
298                 val = interpolate(org);
299                 if (org != val) {
300                     license.setUrl(val);
301                 }
302                 // Distribution
303                 org = license.getDistribution();
304                 val = interpolate(org);
305                 if (org != val) {
306                     license.setDistribution(val);
307                 }
308                 // Comments
309                 org = license.getComments();
310                 val = interpolate(org);
311                 if (org != val) {
312                     license.setComments(val);
313                 }
314             }
315         }
316 
317         private void visit(Developer developer) {
318             if (developer != null) {
319                 String org, val;
320                 // Contributor
321                 visit((Contributor) developer);
322                 // Distribution
323                 org = developer.getId();
324                 val = interpolate(org);
325                 if (org != val) {
326                     developer.setId(val);
327                 }
328             }
329         }
330 
331         private void visit(Contributor contributor) {
332             if (contributor != null) {
333                 String org, val;
334                 // Name
335                 org = contributor.getName();
336                 val = interpolate(org);
337                 if (org != val) {
338                     contributor.setName(val);
339                 }
340                 // Email
341                 org = contributor.getEmail();
342                 val = interpolate(org);
343                 if (org != val) {
344                     contributor.setEmail(val);
345                 }
346                 // Url
347                 org = contributor.getUrl();
348                 val = interpolate(org);
349                 if (org != val) {
350                     contributor.setUrl(val);
351                 }
352                 // Organization
353                 org = contributor.getOrganization();
354                 val = interpolate(org);
355                 if (org != val) {
356                     contributor.setOrganization(val);
357                 }
358                 // OrganizationUrl
359                 org = contributor.getOrganizationUrl();
360                 val = interpolate(org);
361                 if (org != val) {
362                     contributor.setOrganizationUrl(val);
363                 }
364                 // Roles
365                 visit(contributor.getRoles());
366             }
367         }
368 
369         private void visit(MailingList mailingList) {
370             if (mailingList != null) {
371                 String org, val;
372                 // Name
373                 org = mailingList.getName();
374                 val = interpolate(org);
375                 if (org != val) {
376                     mailingList.setName(val);
377                 }
378                 // Subscribe
379                 org = mailingList.getSubscribe();
380                 val = interpolate(org);
381                 if (org != val) {
382                     mailingList.setSubscribe(val);
383                 }
384                 // Unsubscribe
385                 org = mailingList.getUnsubscribe();
386                 val = interpolate(org);
387                 if (org != val) {
388                     mailingList.setUnsubscribe(val);
389                 }
390                 // Post
391                 org = mailingList.getPost();
392                 val = interpolate(org);
393                 if (org != val) {
394                     mailingList.setPost(val);
395                 }
396                 // Archive
397                 org = mailingList.getArchive();
398                 val = interpolate(org);
399                 if (org != val) {
400                     mailingList.setArchive(val);
401                 }
402             }
403         }
404 
405         private void visit(Prerequisites prerequisites) {
406             if (prerequisites != null) {
407                 String org, val;
408                 // Maven
409                 org = prerequisites.getMaven();
410                 val = interpolate(org);
411                 if (org != val) {
412                     prerequisites.setMaven(val);
413                 }
414             }
415         }
416 
417         private void visit(Scm scm) {
418             if (scm != null) {
419                 String org, val;
420                 // Connection
421                 org = scm.getConnection();
422                 val = interpolate(org);
423                 if (org != val) {
424                     scm.setConnection(val);
425                 }
426                 // DeveloperConnection
427                 org = scm.getDeveloperConnection();
428                 val = interpolate(org);
429                 if (org != val) {
430                     scm.setDeveloperConnection(val);
431                 }
432                 // Tag
433                 org = scm.getTag();
434                 val = interpolate(org);
435                 if (org != val) {
436                     scm.setTag(val);
437                 }
438                 // Url
439                 org = scm.getUrl();
440                 val = interpolate(org);
441                 if (org != val) {
442                     scm.setUrl(val);
443                 }
444                 // ChildScmConnectionInheritAppendPath
445                 org = scm.getChildScmConnectionInheritAppendPath();
446                 val = interpolate(org);
447                 if (org != val) {
448                     scm.setChildScmConnectionInheritAppendPath(val);
449                 }
450                 // ChildScmDeveloperConnectionInheritAppendPath
451                 org = scm.getChildScmDeveloperConnectionInheritAppendPath();
452                 val = interpolate(org);
453                 if (org != val) {
454                     scm.setChildScmDeveloperConnectionInheritAppendPath(val);
455                 }
456                 // ChildScmUrlInheritAppendPath
457                 org = scm.getChildScmUrlInheritAppendPath();
458                 val = interpolate(org);
459                 if (org != val) {
460                     scm.setChildScmUrlInheritAppendPath(val);
461                 }
462             }
463         }
464 
465         private void visit(IssueManagement issueManagement) {
466             if (issueManagement != null) {
467                 String org, val;
468                 // System
469                 org = issueManagement.getSystem();
470                 val = interpolate(org);
471                 if (org != val) {
472                     issueManagement.setSystem(val);
473                 }
474                 // Url
475                 org = issueManagement.getUrl();
476                 val = interpolate(org);
477                 if (org != val) {
478                     issueManagement.setUrl(val);
479                 }
480             }
481         }
482 
483         private void visit(CiManagement ciManagement) {
484             if (ciManagement != null) {
485                 String org, val;
486                 // System
487                 org = ciManagement.getSystem();
488                 val = interpolate(org);
489                 if (org != val) {
490                     ciManagement.setSystem(val);
491                 }
492                 // Url
493                 org = ciManagement.getUrl();
494                 val = interpolate(org);
495                 if (org != val) {
496                     ciManagement.setUrl(val);
497                 }
498                 // Notifiers
499                 for (Notifier notifier : ciManagement.getNotifiers()) {
500                     visit(notifier);
501                 }
502             }
503         }
504 
505         private void visit(Notifier notifier) {
506             if (notifier != null) {
507                 String org, val;
508                 // Type
509                 org = notifier.getType();
510                 val = interpolate(org);
511                 if (org != val) {
512                     notifier.setType(val);
513                 }
514                 // Configuration
515                 visit(notifier.getConfiguration());
516             }
517         }
518 
519         private void visit(BuildBase build) {
520             if (build != null) {
521                 String org, val;
522                 // Plugins
523                 for (Plugin plugin : build.getPlugins()) {
524                     visit(plugin);
525                 }
526                 // PluginManagement
527                 visit(build.getPluginManagement());
528                 // DefaultGoal
529                 org = build.getDefaultGoal();
530                 val = interpolate(org);
531                 if (org != val) {
532                     build.setDefaultGoal(val);
533                 }
534                 // Resources
535                 for (Resource resource : build.getResources()) {
536                     visit(resource);
537                 }
538                 // TestResources
539                 for (Resource resource : build.getTestResources()) {
540                     visit(resource);
541                 }
542                 // Directory
543                 org = build.getDirectory();
544                 val = interpolate(org);
545                 if (org != val) {
546                     build.setDirectory(val);
547                 }
548                 // FinalName
549                 org = build.getFinalName();
550                 val = interpolate(org);
551                 if (org != val) {
552                     build.setFinalName(val);
553                 }
554                 // Filters
555                 visit(build.getFilters());
556             }
557         }
558 
559         private void visit(PluginManagement pluginManagement) {
560             if (pluginManagement != null) {
561                 for (Plugin plugin : pluginManagement.getPlugins()) {
562                     visit(plugin);
563                 }
564             }
565         }
566 
567         private void visit(Build build) {
568             if (build != null) {
569                 String org, val;
570                 // BuildBase
571                 visit((BuildBase) build);
572                 // SourceDirectory
573                 org = build.getSourceDirectory();
574                 val = interpolate(org);
575                 if (org != val) {
576                     build.setSourceDirectory(val);
577                 }
578                 // ScriptSourceDirectory
579                 org = build.getScriptSourceDirectory();
580                 val = interpolate(org);
581                 if (org != val) {
582                     build.setScriptSourceDirectory(val);
583                 }
584                 // TestSourceDirectory
585                 org = build.getTestSourceDirectory();
586                 val = interpolate(org);
587                 if (org != val) {
588                     build.setTestSourceDirectory(val);
589                 }
590                 // OutputDirectory
591                 org = build.getOutputDirectory();
592                 val = interpolate(org);
593                 if (org != val) {
594                     build.setOutputDirectory(val);
595                 }
596                 // TestOutputDirectory
597                 org = build.getTestOutputDirectory();
598                 val = interpolate(org);
599                 if (org != val) {
600                     build.setTestOutputDirectory(val);
601                 }
602                 // Extensions
603                 for (Extension extension : build.getExtensions()) {
604                     visit(extension);
605                 }
606             }
607         }
608 
609         private void visit(Resource resource) {
610             if (resource != null) {
611                 String org, val;
612                 // Includes
613                 visit(resource.getIncludes());
614                 // Excludes
615                 visit(resource.getExcludes());
616                 // Directory
617                 org = resource.getDirectory();
618                 val = interpolate(org);
619                 if (org != val) {
620                     resource.setDirectory(val);
621                 }
622                 // TargetPath
623                 org = resource.getTargetPath();
624                 val = interpolate(org);
625                 if (org != val) {
626                     resource.setTargetPath(val);
627                 }
628                 // Filtering
629                 org = resource.getFiltering();
630                 val = interpolate(org);
631                 if (org != val) {
632                     resource.setFiltering(val);
633                 }
634             }
635         }
636 
637         private void visit(Plugin plugin) {
638             if (plugin != null) {
639                 String org, val;
640                 // Inherited
641                 org = plugin.getInherited();
642                 val = interpolate(org);
643                 if (org != val) {
644                     plugin.setInherited(val);
645                 }
646                 // Configuration
647                 visit((Xpp3Dom) plugin.getConfiguration());
648                 // GroupId
649                 org = plugin.getGroupId();
650                 val = interpolate(org);
651                 if (org != val) {
652                     plugin.setGroupId(val);
653                 }
654                 // ArtifactId
655                 org = plugin.getArtifactId();
656                 val = interpolate(org);
657                 if (org != val) {
658                     plugin.setArtifactId(val);
659                 }
660                 // Version
661                 org = plugin.getVersion();
662                 val = interpolate(org);
663                 if (org != val) {
664                     plugin.setVersion(val);
665                 }
666                 // Extensions
667                 org = plugin.getExtensions();
668                 val = interpolate(org);
669                 if (org != val) {
670                     plugin.setExtensions(val);
671                 }
672                 // Executions
673                 for (PluginExecution execution : plugin.getExecutions()) {
674                     visit(execution);
675                 }
676                 // Dependencies
677                 for (Dependency dependency : plugin.getDependencies()) {
678                     visit(dependency);
679                 }
680             }
681         }
682 
683         private void visit(PluginExecution execution) {
684             if (execution != null) {
685                 String org, val;
686                 // Inherited
687                 org = execution.getInherited();
688                 val = interpolate(org);
689                 if (org != val) {
690                     execution.setInherited(val);
691                 }
692                 // Configuration
693                 visit((Xpp3Dom) execution.getConfiguration());
694                 // Id
695                 org = execution.getId();
696                 val = interpolate(org);
697                 if (org != val) {
698                     execution.setId(val);
699                 }
700                 // Phase
701                 org = execution.getPhase();
702                 val = interpolate(org);
703                 if (org != val) {
704                     execution.setPhase(val);
705                 }
706                 // Goals
707                 visit(execution.getGoals());
708             }
709         }
710 
711         private void visit(Xpp3Dom dom) {
712             if (dom != null) {
713                 String org, val;
714                 // Content
715                 org = dom.getValue();
716                 val = interpolate(org);
717                 if (org != val) {
718                     dom.setValue(val);
719                 }
720                 // Attributes
721                 for (String attr : dom.getAttributeNames()) {
722                     org = dom.getAttribute(attr);
723                     val = interpolate(org);
724                     if (org != val) {
725                         dom.setAttribute(attr, val);
726                     }
727                 }
728                 // Children
729                 for (int i = 0, l = dom.getChildCount(); i < l; i++) {
730                     visit(dom.getChild(i));
731                 }
732             }
733         }
734 
735         private void visit(Extension extension) {
736             if (extension != null) {
737                 String org, val;
738                 // GroupId
739                 org = extension.getGroupId();
740                 val = interpolate(org);
741                 if (org != val) {
742                     extension.setGroupId(val);
743                 }
744                 // ArtifactId
745                 org = extension.getArtifactId();
746                 val = interpolate(org);
747                 if (org != val) {
748                     extension.setArtifactId(val);
749                 }
750                 // Version
751                 org = extension.getVersion();
752                 val = interpolate(org);
753                 if (org != val) {
754                     extension.setVersion(val);
755                 }
756             }
757         }
758 
759         private void visit(Profile profile) {
760             if (profile != null) {
761                 String org, val;
762                 // ModelBase
763                 visit((ModelBase) profile);
764                 // Id
765                 org = profile.getId();
766                 val = interpolate(org);
767                 if (org != val) {
768                     profile.setId(val);
769                 }
770                 // Activation
771                 visit(profile.getActivation());
772                 // Build
773                 visit(profile.getBuild());
774             }
775         }
776 
777         private void visit(Activation activation) {
778             if (activation != null) {
779                 String org, val;
780                 // Jdk
781                 org = activation.getJdk();
782                 val = interpolate(org);
783                 if (org != val) {
784                     activation.setJdk(val);
785                 }
786                 // OS
787                 visit(activation.getOs());
788                 // Property
789                 visit(activation.getProperty());
790                 // File
791                 visit(activation.getFile());
792             }
793         }
794 
795         private void visit(ActivationOS activationOS) {
796             if (activationOS != null) {
797                 String org, val;
798                 // Name
799                 org = activationOS.getName();
800                 val = interpolate(org);
801                 if (org != val) {
802                     activationOS.setName(val);
803                 }
804                 // Family
805                 org = activationOS.getFamily();
806                 val = interpolate(org);
807                 if (org != val) {
808                     activationOS.setFamily(val);
809                 }
810                 // Arch
811                 org = activationOS.getArch();
812                 val = interpolate(org);
813                 if (org != val) {
814                     activationOS.setArch(val);
815                 }
816                 // Version
817                 org = activationOS.getVersion();
818                 val = interpolate(org);
819                 if (org != val) {
820                     activationOS.setVersion(val);
821                 }
822             }
823         }
824 
825         private void visit(ActivationProperty activationProperty) {
826             if (activationProperty != null) {
827                 String org, val;
828                 // Name
829                 org = activationProperty.getName();
830                 val = interpolate(org);
831                 if (org != val) {
832                     activationProperty.setName(val);
833                 }
834                 // Value
835                 org = activationProperty.getValue();
836                 val = interpolate(org);
837                 if (org != val) {
838                     activationProperty.setValue(val);
839                 }
840             }
841         }
842 
843         private void visit(ActivationFile activationFile) {
844             if (activationFile != null) {
845                 String org, val;
846                 // Missing
847                 org = activationFile.getMissing();
848                 val = interpolate(org);
849                 if (org != val) {
850                     activationFile.setMissing(val);
851                 }
852                 // Exists
853                 org = activationFile.getExists();
854                 val = interpolate(org);
855                 if (org != val) {
856                     activationFile.setExists(val);
857                 }
858             }
859         }
860 
861         private void visit(ModelBase modelBase) {
862             if (modelBase != null) {
863                 visit(modelBase.getModules());
864                 visit(modelBase.getDistributionManagement());
865                 visit(modelBase.getProperties());
866                 visit(modelBase.getDependencyManagement());
867                 for (Dependency dependency : modelBase.getDependencies()) {
868                     visit(dependency);
869                 }
870                 for (Repository repository : modelBase.getRepositories()) {
871                     visit(repository);
872                 }
873                 for (Repository repository : modelBase.getPluginRepositories()) {
874                     visit(repository);
875                 }
876                 visit(modelBase.getReporting());
877             }
878         }
879 
880         private void visit(DistributionManagement distributionManagement) {
881             if (distributionManagement != null) {
882                 String org, val;
883                 // Repository
884                 visit(distributionManagement.getRepository());
885                 // SnapshotRepository
886                 visit(distributionManagement.getSnapshotRepository());
887                 // Site
888                 visit(distributionManagement.getSite());
889                 // DownloadUrl
890                 org = distributionManagement.getDownloadUrl();
891                 val = interpolate(org);
892                 if (org != val) {
893                     distributionManagement.setDownloadUrl(val);
894                 }
895                 // Relocation
896                 visit(distributionManagement.getRelocation());
897             }
898         }
899 
900         private void visit(Site site) {
901             if (site != null) {
902                 String org, val;
903                 // Id
904                 org = site.getId();
905                 val = interpolate(org);
906                 if (org != val) {
907                     site.setId(val);
908                 }
909                 // Name
910                 org = site.getName();
911                 val = interpolate(org);
912                 if (org != val) {
913                     site.setName(val);
914                 }
915                 // Url
916                 org = site.getUrl();
917                 val = interpolate(org);
918                 if (org != val) {
919                     site.setUrl(val);
920                 }
921                 // ChildSiteUrlInheritAppendPath
922                 org = site.getChildSiteUrlInheritAppendPath();
923                 val = interpolate(org);
924                 if (org != val) {
925                     site.setChildSiteUrlInheritAppendPath(val);
926                 }
927             }
928         }
929 
930         private void visit(Relocation relocation) {
931             if (relocation != null) {
932                 String org, val;
933                 // GroupId
934                 org = relocation.getGroupId();
935                 val = interpolate(org);
936                 if (org != val) {
937                     relocation.setGroupId(val);
938                 }
939                 // ArtifactId
940                 org = relocation.getArtifactId();
941                 val = interpolate(org);
942                 if (org != val) {
943                     relocation.setArtifactId(val);
944                 }
945                 // Version
946                 org = relocation.getVersion();
947                 val = interpolate(org);
948                 if (org != val) {
949                     relocation.setVersion(val);
950                 }
951                 // Message
952                 org = relocation.getMessage();
953                 val = interpolate(org);
954                 if (org != val) {
955                     relocation.setMessage(val);
956                 }
957             }
958         }
959 
960         private void visit(DependencyManagement dependencyManagement) {
961             if (dependencyManagement != null) {
962                 // Dependencies
963                 for (Dependency dependency : dependencyManagement.getDependencies()) {
964                     visit(dependency);
965                 }
966             }
967         }
968 
969         private void visit(Repository repository) {
970             if (repository != null) {
971                 visit((RepositoryBase) repository);
972                 visit(repository.getReleases());
973                 visit(repository.getSnapshots());
974             }
975         }
976 
977         private void visit(RepositoryBase repositoryBase) {
978             if (repositoryBase != null) {
979                 // Id
980                 String orgId = repositoryBase.getId();
981                 String intId = interpolate(orgId);
982                 if (orgId != intId) {
983                     repositoryBase.setId(intId);
984                 }
985                 // Name
986                 String orgName = repositoryBase.getName();
987                 String intName = interpolate(orgName);
988                 if (orgName != intName) {
989                     repositoryBase.setName(intName);
990                 }
991                 // Url
992                 String orgUrl = repositoryBase.getUrl();
993                 String intUrl = interpolate(orgUrl);
994                 if (orgUrl != intUrl) {
995                     repositoryBase.setUrl(intUrl);
996                 }
997                 // Layout
998                 String orgLayout = repositoryBase.getLayout();
999                 String intLayout = interpolate(orgLayout);
1000                 if (orgLayout != intLayout) {
1001                     repositoryBase.setLayout(intLayout);
1002                 }
1003             }
1004         }
1005 
1006         private void visit(RepositoryPolicy repositoryPolicy) {
1007             if (repositoryPolicy != null) {
1008                 // Enabled
1009                 String orgEnabled = repositoryPolicy.getEnabled();
1010                 String intEnabled = interpolate(orgEnabled);
1011                 if (orgEnabled != intEnabled) {
1012                     repositoryPolicy.setEnabled(intEnabled);
1013                 }
1014                 // UpdatePolicy
1015                 String orgUpdatePolicy = repositoryPolicy.getUpdatePolicy();
1016                 String intUpdatePolicy = interpolate(orgUpdatePolicy);
1017                 if (orgUpdatePolicy != intUpdatePolicy) {
1018                     repositoryPolicy.setUpdatePolicy(intUpdatePolicy);
1019                 }
1020                 // ChecksumPolicy
1021                 String orgChecksumPolicy = repositoryPolicy.getChecksumPolicy();
1022                 String intChecksumPolicy = interpolate(orgChecksumPolicy);
1023                 if (orgChecksumPolicy != intChecksumPolicy) {
1024                     repositoryPolicy.setChecksumPolicy(intChecksumPolicy);
1025                 }
1026             }
1027         }
1028 
1029         private void visit(Dependency dependency) {
1030             if (dependency != null) {
1031                 String org, val;
1032                 // GroupId
1033                 org = dependency.getGroupId();
1034                 val = interpolate(org);
1035                 if (org != val) {
1036                     dependency.setGroupId(val);
1037                     dependency.clearManagementKey();
1038                 }
1039                 // ArtifactId
1040                 org = dependency.getArtifactId();
1041                 val = interpolate(org);
1042                 if (org != val) {
1043                     dependency.setArtifactId(val);
1044                     dependency.clearManagementKey();
1045                 }
1046                 // Version
1047                 org = dependency.getVersion();
1048                 val = interpolate(org);
1049                 if (org != val) {
1050                     dependency.setVersion(val);
1051                 }
1052                 // Type
1053                 org = dependency.getType();
1054                 val = interpolate(org);
1055                 if (org != val) {
1056                     dependency.setType(val);
1057                     dependency.clearManagementKey();
1058                 }
1059                 // Classifier
1060                 org = dependency.getClassifier();
1061                 val = interpolate(org);
1062                 if (org != val) {
1063                     dependency.setClassifier(val);
1064                     dependency.clearManagementKey();
1065                 }
1066                 // Scope
1067                 org = dependency.getScope();
1068                 val = interpolate(org);
1069                 if (org != val) {
1070                     dependency.setScope(val);
1071                 }
1072                 // SystemPath
1073                 org = dependency.getSystemPath();
1074                 val = interpolate(org);
1075                 if (org != val) {
1076                     dependency.setSystemPath(val);
1077                 }
1078                 // Exclusions
1079                 for (Exclusion exclusion : dependency.getExclusions()) {
1080                     visit(exclusion);
1081                 }
1082                 // Optional
1083                 org = dependency.getOptional();
1084                 val = interpolate(org);
1085                 if (org != val) {
1086                     dependency.setOptional(val);
1087                 }
1088             }
1089         }
1090 
1091         private void visit(Exclusion exclusion) {
1092             if (exclusion != null) {
1093                 String org, val;
1094                 // GroupId
1095                 org = exclusion.getGroupId();
1096                 val = interpolate(org);
1097                 if (org != val) {
1098                     exclusion.setGroupId(val);
1099                 }
1100                 // ArtifactId
1101                 org = exclusion.getArtifactId();
1102                 val = interpolate(org);
1103                 if (org != val) {
1104                     exclusion.setArtifactId(val);
1105                 }
1106             }
1107         }
1108 
1109         private void visit(Reporting reporting) {
1110             if (reporting != null) {
1111                 String org, val;
1112                 // ExcludeDefaults
1113                 org = reporting.getExcludeDefaults();
1114                 val = interpolate(org);
1115                 if (org != val) {
1116                     reporting.setExcludeDefaults(val);
1117                 }
1118                 // OutputDirectory
1119                 org = reporting.getOutputDirectory();
1120                 val = interpolate(org);
1121                 if (org != val) {
1122                     reporting.setOutputDirectory(val);
1123                 }
1124                 // Plugins
1125                 for (ReportPlugin plugin : reporting.getPlugins()) {
1126                     visit(plugin);
1127                 }
1128             }
1129         }
1130 
1131         private void visit(ReportPlugin plugin) {
1132             if (plugin != null) {
1133                 String org, val;
1134                 // Inherited
1135                 org = plugin.getInherited();
1136                 val = interpolate(org);
1137                 if (org != val) {
1138                     plugin.setInherited(val);
1139                 }
1140                 // Configuration
1141                 visit((Xpp3Dom) plugin.getConfiguration());
1142                 // GroupId
1143                 org = plugin.getGroupId();
1144                 val = interpolate(org);
1145                 if (org != val) {
1146                     plugin.setGroupId(val);
1147                 }
1148                 // ArtifactId
1149                 org = plugin.getArtifactId();
1150                 val = interpolate(org);
1151                 if (org != val) {
1152                     plugin.setArtifactId(val);
1153                 }
1154                 // Version
1155                 org = plugin.getVersion();
1156                 val = interpolate(org);
1157                 if (org != val) {
1158                     plugin.setVersion(val);
1159                 }
1160                 // ReportSets
1161                 for (ReportSet reportSet : plugin.getReportSets()) {
1162                     visit(reportSet);
1163                 }
1164             }
1165         }
1166 
1167         private void visit(ReportSet reportSet) {
1168             if (reportSet != null) {
1169                 String org, val;
1170                 // Inherited
1171                 org = reportSet.getInherited();
1172                 val = interpolate(org);
1173                 if (org != val) {
1174                     reportSet.setInherited(val);
1175                 }
1176                 // Configuration
1177                 visit((Xpp3Dom) reportSet.getConfiguration());
1178                 // Id
1179                 org = reportSet.getId();
1180                 val = interpolate(org);
1181                 if (org != val) {
1182                     reportSet.setId(val);
1183                 }
1184                 // Reports
1185                 visit(reportSet.getReports());
1186             }
1187         }
1188 
1189         private void visit(Properties properties) {
1190             if (properties != null) {
1191                 for (Map.Entry<Object, Object> entry : properties.entrySet()) {
1192                     Object v = entry.getValue();
1193                     if (v instanceof String) {
1194                         String value = (String) v;
1195                         String inter = interpolate(value);
1196                         if (value != inter && inter != null) {
1197                             entry.setValue(inter);
1198                         }
1199                     }
1200                 }
1201             }
1202         }
1203 
1204         private void visit(List<String> list) {
1205             if (list != null) {
1206                 ListIterator<String> it = list.listIterator();
1207                 while (it.hasNext()) {
1208                     String value = it.next();
1209                     String inter = interpolate(value);
1210                     if (value != inter) {
1211                         it.set(inter);
1212                     }
1213                 }
1214             }
1215         }
1216 
1217         private String interpolate(String value) {
1218             return interpolator.interpolate(value);
1219         }
1220     }
1221 }