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