1 package org.apache.maven.project; 2 3 18 19 import org.apache.maven.model.Activation; 20 import org.apache.maven.model.ActivationFile; 21 import org.apache.maven.model.ActivationProperty; 22 import org.apache.maven.model.Build; 23 import org.apache.maven.model.BuildBase; 24 import org.apache.maven.model.Dependency; 25 import org.apache.maven.model.DependencyManagement; 26 import org.apache.maven.model.DeploymentRepository; 27 import org.apache.maven.model.DistributionManagement; 28 import org.apache.maven.model.Exclusion; 29 import org.apache.maven.model.Extension; 30 import org.apache.maven.model.Model; 31 import org.apache.maven.model.Parent; 32 import org.apache.maven.model.Plugin; 33 import org.apache.maven.model.PluginContainer; 34 import org.apache.maven.model.PluginExecution; 35 import org.apache.maven.model.PluginManagement; 36 import org.apache.maven.model.Profile; 37 import org.apache.maven.model.Relocation; 38 import org.apache.maven.model.ReportPlugin; 39 import org.apache.maven.model.ReportSet; 40 import org.apache.maven.model.Reporting; 41 import org.apache.maven.model.Repository; 42 import org.apache.maven.model.RepositoryBase; 43 import org.apache.maven.model.RepositoryPolicy; 44 import org.apache.maven.model.Resource; 45 import org.apache.maven.model.Site; 46 import org.apache.maven.project.inheritance.DefaultModelInheritanceAssembler; 47 import org.apache.maven.project.inheritance.ModelInheritanceAssembler; 48 import org.codehaus.plexus.util.xml.Xpp3Dom; 49 50 import java.util.ArrayList ; 51 import java.util.Iterator ; 52 import java.util.List ; 53 import java.util.Map ; 54 import java.util.Properties ; 55 import java.util.TreeMap ; 56 import java.util.HashMap ; 57 58 public final class ModelUtils 59 { 60 public static void mergePluginLists( PluginContainer childContainer, PluginContainer parentContainer, 61 boolean handleAsInheritance ) 62 { 63 if ( childContainer == null || parentContainer == null ) 64 { 65 return; 67 } 68 69 List mergedPlugins = new ArrayList (); 70 71 List parentPlugins = parentContainer.getPlugins(); 72 73 if ( parentPlugins != null && !parentPlugins.isEmpty() ) 74 { 75 Map assembledPlugins = new TreeMap (); 76 77 Map childPlugins = childContainer.getPluginsAsMap(); 78 79 for ( Iterator it = parentPlugins.iterator(); it.hasNext(); ) 80 { 81 Plugin parentPlugin = (Plugin) it.next(); 82 83 String parentInherited = parentPlugin.getInherited(); 84 85 if ( !handleAsInheritance || parentInherited == null || 86 Boolean.valueOf( parentInherited ).booleanValue() ) 87 { 88 89 Plugin assembledPlugin = parentPlugin; 90 91 Plugin childPlugin = (Plugin) childPlugins.get( parentPlugin.getKey() ); 92 93 if ( childPlugin != null ) 94 { 95 assembledPlugin = childPlugin; 96 97 mergePluginDefinitions( childPlugin, parentPlugin, handleAsInheritance ); 98 } 99 100 if ( handleAsInheritance && parentInherited == null ) 101 { 102 assembledPlugin.unsetInheritanceApplied(); 103 } 104 105 mergedPlugins.add(assembledPlugin); 106 } 107 } 108 109 for ( Iterator it = childPlugins.values().iterator(); it.hasNext(); ) 110 { 111 Plugin childPlugin = (Plugin) it.next(); 112 113 if ( !assembledPlugins.containsKey( childPlugin.getKey() ) ) 114 { 115 mergedPlugins.add(childPlugin); 116 } 117 } 118 119 childContainer.setPlugins(mergedPlugins); 120 121 childContainer.flushPluginMap(); 122 } 123 } 124 125 public static void mergeReportPluginLists( Reporting child, Reporting parent, boolean handleAsInheritance ) 126 { 127 if ( child == null || parent == null ) 128 { 129 return; 131 } 132 133 List parentPlugins = parent.getPlugins(); 134 135 if ( parentPlugins != null && !parentPlugins.isEmpty() ) 136 { 137 Map assembledPlugins = new TreeMap (); 138 139 Map childPlugins = child.getReportPluginsAsMap(); 140 141 for ( Iterator it = parentPlugins.iterator(); it.hasNext(); ) 142 { 143 ReportPlugin parentPlugin = (ReportPlugin) it.next(); 144 145 String parentInherited = parentPlugin.getInherited(); 146 147 if ( !handleAsInheritance || parentInherited == null || 148 Boolean.valueOf( parentInherited ).booleanValue() ) 149 { 150 151 ReportPlugin assembledPlugin = parentPlugin; 152 153 ReportPlugin childPlugin = (ReportPlugin) childPlugins.get( parentPlugin.getKey() ); 154 155 if ( childPlugin != null ) 156 { 157 assembledPlugin = childPlugin; 158 159 mergeReportPluginDefinitions( childPlugin, parentPlugin, handleAsInheritance ); 160 } 161 162 if ( handleAsInheritance && parentInherited == null ) 163 { 164 assembledPlugin.unsetInheritanceApplied(); 165 } 166 167 assembledPlugins.put( assembledPlugin.getKey(), assembledPlugin ); 168 } 169 } 170 171 for ( Iterator it = childPlugins.values().iterator(); it.hasNext(); ) 172 { 173 ReportPlugin childPlugin = (ReportPlugin) it.next(); 174 175 if ( !assembledPlugins.containsKey( childPlugin.getKey() ) ) 176 { 177 assembledPlugins.put( childPlugin.getKey(), childPlugin ); 178 } 179 } 180 181 child.setPlugins( new ArrayList ( assembledPlugins.values() ) ); 182 183 child.flushReportPluginMap(); 184 } 185 } 186 187 public static void mergePluginDefinitions( Plugin child, Plugin parent, boolean handleAsInheritance ) 188 { 189 if ( child == null || parent == null ) 190 { 191 return; 193 } 194 195 if ( parent.isExtensions() ) 196 { 197 child.setExtensions( true ); 198 } 199 200 if ( child.getVersion() == null && parent.getVersion() != null ) 201 { 202 child.setVersion( parent.getVersion() ); 203 } 204 205 Xpp3Dom childConfiguration = (Xpp3Dom) child.getConfiguration(); 206 Xpp3Dom parentConfiguration = (Xpp3Dom) parent.getConfiguration(); 207 208 childConfiguration = Xpp3Dom.mergeXpp3Dom( childConfiguration, parentConfiguration ); 209 210 child.setConfiguration( childConfiguration ); 211 212 child.setDependencies( mergeDependencyList( child.getDependencies(), parent.getDependencies() ) ); 213 214 String parentInherited = parent.getInherited(); 216 217 boolean parentIsInherited = parentInherited == null || Boolean.valueOf( parentInherited ).booleanValue(); 218 219 List parentExecutions = parent.getExecutions(); 220 221 if ( parentExecutions != null && !parentExecutions.isEmpty() ) 222 { 223 List mergedExecutions = new ArrayList (); 224 225 Map assembledExecutions = new TreeMap (); 226 227 Map childExecutions = child.getExecutionsAsMap(); 228 229 for ( Iterator it = parentExecutions.iterator(); it.hasNext(); ) 230 { 231 PluginExecution parentExecution = (PluginExecution) it.next(); 232 233 if ( !handleAsInheritance || parentIsInherited ) 234 { 235 PluginExecution assembled = parentExecution; 236 237 PluginExecution childExecution = (PluginExecution) childExecutions.get( parentExecution.getId() ); 238 239 if ( childExecution != null ) 240 { 241 mergePluginExecutionDefinitions( childExecution, parentExecution ); 242 243 assembled = childExecution; 244 } 245 else if ( handleAsInheritance && parentInherited == null ) 246 { 247 parentExecution.unsetInheritanceApplied(); 248 } 249 250 assembledExecutions.put( assembled.getId(), assembled ); 251 mergedExecutions.add(assembled); 252 } 253 } 254 255 for ( Iterator it = child.getExecutions().iterator(); it.hasNext(); ) 256 { 257 PluginExecution childExecution = (PluginExecution)it.next(); 258 259 if ( !assembledExecutions.containsKey( childExecution.getId() ) ) 260 { 261 mergedExecutions.add(childExecution); 262 } 263 } 264 265 child.setExecutions(mergedExecutions); 266 267 child.flushExecutionMap(); 268 } 269 270 } 271 272 public static void mergeReportPluginDefinitions( ReportPlugin child, ReportPlugin parent, 273 boolean handleAsInheritance ) 274 { 275 if ( child == null || parent == null ) 276 { 277 return; 279 } 280 281 if ( child.getVersion() == null && parent.getVersion() != null ) 282 { 283 child.setVersion( parent.getVersion() ); 284 } 285 286 String parentInherited = parent.getInherited(); 288 289 boolean parentIsInherited = parentInherited == null || Boolean.valueOf( parentInherited ).booleanValue(); 290 291 List parentReportSets = parent.getReportSets(); 292 293 if ( parentReportSets != null && !parentReportSets.isEmpty() ) 294 { 295 Map assembledReportSets = new TreeMap (); 296 297 Map childReportSets = child.getReportSetsAsMap(); 298 299 for ( Iterator it = parentReportSets.iterator(); it.hasNext(); ) 300 { 301 ReportSet parentReportSet = (ReportSet) it.next(); 302 303 if ( !handleAsInheritance || parentIsInherited ) 304 { 305 ReportSet assembledReportSet = parentReportSet; 306 307 ReportSet childReportSet = (ReportSet) childReportSets.get( parentReportSet.getId() ); 308 309 if ( childReportSet != null ) 310 { 311 mergeReportSetDefinitions( childReportSet, parentReportSet ); 312 313 assembledReportSet = childReportSet; 314 } 315 else if ( handleAsInheritance && parentInherited == null ) 316 { 317 parentReportSet.unsetInheritanceApplied(); 318 } 319 320 assembledReportSets.put( assembledReportSet.getId(), assembledReportSet ); 321 } 322 } 323 324 for ( Iterator it = childReportSets.entrySet().iterator(); it.hasNext(); ) 325 { 326 Map.Entry entry = (Map.Entry ) it.next(); 327 328 String id = (String ) entry.getKey(); 329 330 if ( !assembledReportSets.containsKey( id ) ) 331 { 332 assembledReportSets.put( id, entry.getValue() ); 333 } 334 } 335 336 child.setReportSets( new ArrayList ( assembledReportSets.values() ) ); 337 338 child.flushReportSetMap(); 339 } 340 341 } 342 343 private static void mergePluginExecutionDefinitions( PluginExecution child, PluginExecution parent ) 344 { 345 if ( child.getPhase() == null ) 346 { 347 child.setPhase( parent.getPhase() ); 348 } 349 350 List parentGoals = parent.getGoals(); 351 List childGoals = child.getGoals(); 352 353 List goals = new ArrayList (); 354 355 if ( childGoals != null && !childGoals.isEmpty() ) 356 { 357 goals.addAll( childGoals ); 358 } 359 360 if ( parentGoals != null ) 361 { 362 for ( Iterator goalIterator = parentGoals.iterator(); goalIterator.hasNext(); ) 363 { 364 String goal = (String ) goalIterator.next(); 365 366 if ( !goals.contains( goal ) ) 367 { 368 goals.add( goal ); 369 } 370 } 371 } 372 373 child.setGoals( goals ); 374 375 Xpp3Dom childConfiguration = (Xpp3Dom) child.getConfiguration(); 376 Xpp3Dom parentConfiguration = (Xpp3Dom) parent.getConfiguration(); 377 378 childConfiguration = Xpp3Dom.mergeXpp3Dom( childConfiguration, parentConfiguration ); 379 380 child.setConfiguration( childConfiguration ); 381 } 382 383 private static void mergeReportSetDefinitions( ReportSet child, ReportSet parent ) 384 { 385 List parentReports = parent.getReports(); 386 List childReports = child.getReports(); 387 388 List reports = new ArrayList (); 389 390 if ( childReports != null && !childReports.isEmpty() ) 391 { 392 reports.addAll( childReports ); 393 } 394 395 if ( parentReports != null ) 396 { 397 for ( Iterator i = parentReports.iterator(); i.hasNext(); ) 398 { 399 String report = (String ) i.next(); 400 401 if ( !reports.contains( report ) ) 402 { 403 reports.add( report ); 404 } 405 } 406 } 407 408 child.setReports( reports ); 409 410 Xpp3Dom childConfiguration = (Xpp3Dom) child.getConfiguration(); 411 Xpp3Dom parentConfiguration = (Xpp3Dom) parent.getConfiguration(); 412 413 childConfiguration = Xpp3Dom.mergeXpp3Dom( childConfiguration, parentConfiguration ); 414 415 child.setConfiguration( childConfiguration ); 416 } 417 418 public static Model cloneModel( Model model ) 419 { 420 Model newModel = new Model(); 422 ModelInheritanceAssembler assembler = new DefaultModelInheritanceAssembler(); 423 newModel.setModelVersion( model.getModelVersion() ); 424 newModel.setName( model.getName() ); 425 newModel.setParent( cloneParent( model.getParent() ) ); 426 newModel.setVersion( model.getVersion() ); 427 newModel.setArtifactId( model.getArtifactId() ); 428 newModel.setProperties( new Properties ( model.getProperties() ) ); 429 newModel.setGroupId( model.getGroupId() ); 430 newModel.setPackaging( model.getPackaging() ); 431 newModel.setModules( cloneModules( model.getModules() ) ); 432 433 newModel.setProfiles( cloneProfiles( model.getProfiles() ) ); 434 435 assembler.copyModel( newModel, model ); 436 437 return newModel; 438 } 439 440 private static List cloneProfiles( List profiles ) 441 { 442 if ( profiles == null ) 443 { 444 return profiles; 445 } 446 447 List newProfiles = new ArrayList ( profiles.size() ); 448 449 for ( Iterator it = profiles.iterator(); it.hasNext(); ) 450 { 451 Profile profile = (Profile) it.next(); 452 453 Profile newProfile = new Profile(); 454 455 newProfile.setId( profile.getId() ); 456 457 newProfile.setActivation( cloneProfileActivation( profile.getActivation() ) ); 458 459 newProfile.setBuild( cloneProfileBuild( profile.getBuild() ) ); 460 461 newProfile.setDependencies( cloneProfileDependencies( profile.getDependencies() ) ); 462 463 DependencyManagement dm = profile.getDependencyManagement(); 464 465 if ( dm != null ) 466 { 467 DependencyManagement newDM = new DependencyManagement(); 468 469 newDM.setDependencies( cloneProfileDependencies( dm.getDependencies() ) ); 470 471 newProfile.setDependencyManagement( newDM ); 472 } 473 474 newProfile.setDistributionManagement( cloneProfileDistributionManagement( profile 475 .getDistributionManagement() ) ); 476 477 List modules = profile.getModules(); 478 479 if ( modules != null && !modules.isEmpty() ) 480 { 481 newProfile.setModules( new ArrayList ( modules ) ); 482 } 483 484 newProfile.setPluginRepositories( cloneProfileRepositories( profile.getPluginRepositories() ) ); 485 486 Properties props = profile.getProperties(); 487 488 if ( props != null ) 489 { 490 Properties newProps = new Properties (); 491 newProps.putAll( props ); 492 493 newProfile.setProperties( newProps ); 494 } 495 496 newProfile.setReporting( cloneProfileReporting( profile.getReporting() ) ); 497 498 newProfile.setReports( profile.getReports() ); 499 500 newProfile.setRepositories( cloneProfileRepositories( profile.getRepositories() ) ); 501 502 newProfile.setSource( profile.getSource() ); 503 504 newProfiles.add( newProfile ); 505 } 506 507 return newProfiles; 508 } 509 510 private static Reporting cloneProfileReporting( Reporting reporting ) 511 { 512 Reporting newR = null; 513 514 if ( reporting != null ) 515 { 516 newR = new Reporting(); 517 518 newR.setOutputDirectory( reporting.getOutputDirectory() ); 519 520 List plugins = reporting.getPlugins(); 521 522 if ( plugins != null ) 523 { 524 List newP = new ArrayList ( plugins.size() ); 525 526 for ( Iterator it = plugins.iterator(); it.hasNext(); ) 527 { 528 ReportPlugin plugin = (ReportPlugin) it.next(); 529 530 ReportPlugin newPlugin = new ReportPlugin(); 531 532 newPlugin.setArtifactId( plugin.getArtifactId() ); 533 newPlugin.setGroupId( plugin.getGroupId() ); 534 newPlugin.setVersion( plugin.getVersion() ); 535 newPlugin.setInherited( plugin.getInherited() ); 536 newPlugin.setReportSets( cloneReportSets( plugin.getReportSets() ) ); 537 538 newPlugin.setConfiguration( plugin.getConfiguration() ); 540 541 newP.add( newPlugin ); 542 } 543 544 newR.setPlugins( newP ); 545 } 546 } 547 548 return newR; 549 } 550 551 private static List cloneReportSets( List sets ) 552 { 553 List newSets = null; 554 555 if ( sets != null ) 556 { 557 newSets = new ArrayList ( sets.size() ); 558 559 for ( Iterator it = sets.iterator(); it.hasNext(); ) 560 { 561 ReportSet set = (ReportSet) it.next(); 562 563 ReportSet newSet = new ReportSet(); 564 565 newSet.setConfiguration( set.getConfiguration() ); 567 568 newSet.setId( set.getId() ); 569 newSet.setInherited( set.getInherited() ); 570 571 newSet.setReports( new ArrayList ( set.getReports() ) ); 572 573 newSets.add( newSet ); 574 } 575 } 576 577 return newSets; 578 } 579 580 private static List cloneProfileRepositories( List repos ) 581 { 582 List newRepos = null; 583 584 if ( repos != null ) 585 { 586 newRepos = new ArrayList ( repos.size() ); 587 588 for ( Iterator it = repos.iterator(); it.hasNext(); ) 589 { 590 Repository repo = (Repository) it.next(); 591 592 Repository newRepo = new Repository(); 593 594 newRepo.setId( repo.getId() ); 595 newRepo.setLayout( repo.getLayout() ); 596 newRepo.setName( repo.getName() ); 597 598 RepositoryPolicy releasePolicy = repo.getReleases(); 599 600 if ( releasePolicy != null ) 601 { 602 RepositoryPolicy newPolicy = new RepositoryPolicy(); 603 newPolicy.setEnabled( releasePolicy.isEnabled() ); 604 newPolicy.setChecksumPolicy( releasePolicy.getChecksumPolicy() ); 605 newPolicy.setUpdatePolicy( releasePolicy.getUpdatePolicy() ); 606 607 newRepo.setReleases( newPolicy ); 608 } 609 610 RepositoryPolicy snapPolicy = repo.getSnapshots(); 611 612 if ( snapPolicy != null ) 613 { 614 RepositoryPolicy newPolicy = new RepositoryPolicy(); 615 newPolicy.setEnabled( snapPolicy.isEnabled() ); 616 newPolicy.setChecksumPolicy( snapPolicy.getChecksumPolicy() ); 617 newPolicy.setUpdatePolicy( snapPolicy.getUpdatePolicy() ); 618 619 newRepo.setSnapshots( newPolicy ); 620 } 621 622 newRepo.setUrl( repo.getUrl() ); 623 624 newRepos.add( newRepo ); 625 } 626 } 627 628 return newRepos; 629 } 630 631 private static DistributionManagement cloneProfileDistributionManagement( DistributionManagement dm ) 632 { 633 DistributionManagement newDM = null; 634 635 if ( dm != null ) 636 { 637 newDM = new DistributionManagement(); 638 639 newDM.setDownloadUrl( dm.getDownloadUrl() ); 640 newDM.setStatus( dm.getStatus() ); 641 642 Relocation relocation = dm.getRelocation(); 643 644 if ( relocation != null ) 645 { 646 Relocation newR = new Relocation(); 647 648 newR.setArtifactId( relocation.getArtifactId() ); 649 newR.setGroupId( relocation.getGroupId() ); 650 newR.setMessage( relocation.getMessage() ); 651 newR.setVersion( relocation.getVersion() ); 652 653 newDM.setRelocation( newR ); 654 } 655 656 RepositoryBase repo = dm.getRepository(); 657 658 if ( repo != null ) 659 { 660 DeploymentRepository newRepo = new DeploymentRepository(); 661 662 newRepo.setId( repo.getId() ); 663 newRepo.setLayout( repo.getLayout() ); 664 newRepo.setName( repo.getName() ); 665 newRepo.setUrl( repo.getUrl() ); 666 667 newDM.setRepository( newRepo ); 668 } 669 670 Site site = dm.getSite(); 671 672 if ( site != null ) 673 { 674 Site newSite = new Site(); 675 676 newSite.setId( site.getId() ); 677 newSite.setName( site.getName() ); 678 newSite.setUrl( site.getUrl() ); 679 680 newDM.setSite( newSite ); 681 } 682 683 RepositoryBase sRepo = dm.getSnapshotRepository(); 684 685 if ( sRepo != null ) 686 { 687 DeploymentRepository newRepo = new DeploymentRepository(); 688 689 newRepo.setId( sRepo.getId() ); 690 newRepo.setLayout( sRepo.getLayout() ); 691 newRepo.setName( sRepo.getName() ); 692 newRepo.setUrl( sRepo.getUrl() ); 693 694 newDM.setSnapshotRepository( newRepo ); 695 } 696 } 697 698 return newDM; 699 } 700 701 private static List cloneProfileDependencies( List dependencies ) 702 { 703 List newDependencies = null; 704 705 if ( dependencies != null ) 706 { 707 newDependencies = new ArrayList ( dependencies.size() ); 708 709 for ( Iterator it = dependencies.iterator(); it.hasNext(); ) 710 { 711 Dependency dep = (Dependency) it.next(); 712 713 Dependency newDep = new Dependency(); 714 715 newDep.setArtifactId( dep.getArtifactId() ); 716 newDep.setClassifier( dep.getClassifier() ); 717 newDep.setExclusions( cloneDependencyExclusions( dep.getExclusions() ) ); 718 newDep.setGroupId( dep.getGroupId() ); 719 newDep.setScope( dep.getScope() ); 720 newDep.setSystemPath( dep.getSystemPath() ); 721 newDep.setType( dep.getType() ); 722 newDep.setVersion( dep.getVersion() ); 723 724 newDependencies.add( newDep ); 725 } 726 } 727 728 return newDependencies; 729 } 730 731 private static List cloneDependencyExclusions( List ex ) 732 { 733 List newEx = null; 734 735 if ( ex != null ) 736 { 737 newEx = new ArrayList ( ex.size() ); 738 739 for ( Iterator it = ex.iterator(); it.hasNext(); ) 740 { 741 Exclusion exclusion = (Exclusion) it.next(); 742 743 Exclusion newExclusion = new Exclusion(); 744 745 newExclusion.setArtifactId( exclusion.getArtifactId() ); 746 newExclusion.setGroupId( exclusion.getGroupId() ); 747 748 newEx.add( newExclusion ); 749 } 750 } 751 752 return newEx; 753 } 754 755 private static BuildBase cloneProfileBuild( BuildBase build ) 756 { 757 BuildBase newBuild = null; 758 if ( build != null ) 759 { 760 newBuild = new BuildBase(); 761 762 newBuild.setDefaultGoal( build.getDefaultGoal() ); 763 newBuild.setDirectory( build.getDirectory() ); 764 newBuild.setFinalName( build.getFinalName() ); 765 766 newBuild.setPluginManagement( cloneProfilePluginManagement( build.getPluginManagement() ) ); 767 newBuild.setPlugins( cloneProfilePlugins( build.getPlugins() ) ); 768 newBuild.setResources( cloneProfileResources( build.getResources() ) ); 769 newBuild.setTestResources( cloneProfileResources( build.getTestResources() ) ); 770 } 771 772 return newBuild; 773 } 774 775 private static List cloneProfileResources( List resources ) 776 { 777 List newResources = null; 778 779 if ( resources != null ) 780 { 781 newResources = new ArrayList ( resources.size() ); 782 783 for ( Iterator it = resources.iterator(); it.hasNext(); ) 784 { 785 Resource resource = (Resource) it.next(); 786 787 Resource newResource = new Resource(); 788 789 newResource.setDirectory( resource.getDirectory() ); 790 newResource.setExcludes( new ArrayList ( resource.getExcludes() ) ); 791 newResource.setFiltering( resource.isFiltering() ); 792 newResource.setIncludes( new ArrayList ( resource.getIncludes() ) ); 793 newResource.setTargetPath( resource.getTargetPath() ); 794 795 newResources.add( newResource ); 796 } 797 } 798 799 return newResources; 800 } 801 802 private static PluginManagement cloneProfilePluginManagement( PluginManagement pluginManagement ) 803 { 804 PluginManagement newPM = null; 805 806 if ( pluginManagement != null ) 807 { 808 newPM = new PluginManagement(); 809 810 List plugins = pluginManagement.getPlugins(); 811 812 newPM.setPlugins( cloneProfilePlugins( plugins ) ); 813 } 814 815 return newPM; 816 } 817 818 private static List cloneProfilePlugins( List plugins ) 819 { 820 List newPlugins = null; 821 822 if ( plugins != null ) 823 { 824 newPlugins = new ArrayList ( plugins.size() ); 825 826 for ( Iterator it = plugins.iterator(); it.hasNext(); ) 827 { 828 Plugin plugin = (Plugin) it.next(); 829 830 Plugin newPlugin = new Plugin(); 831 832 newPlugin.setArtifactId( plugin.getArtifactId() ); 833 newPlugin.setExtensions( plugin.isExtensions() ); 834 newPlugin.setGroupId( plugin.getGroupId() ); 835 newPlugin.setInherited( plugin.getInherited() ); 836 newPlugin.setVersion( plugin.getVersion() ); 837 838 newPlugin.setConfiguration( plugin.getConfiguration() ); 840 841 newPlugin.setExecutions( cloneExecutions( plugin.getExecutions() ) ); 842 843 newPlugins.add( newPlugin ); 844 } 845 } 846 847 return newPlugins; 848 } 849 850 private static List cloneExecutions( List executions ) 851 { 852 List newExecs = null; 853 854 if ( executions != null ) 855 { 856 newExecs = new ArrayList ( executions.size() ); 857 858 for ( Iterator it = executions.iterator(); it.hasNext(); ) 859 { 860 PluginExecution exec = (PluginExecution) it.next(); 861 862 PluginExecution newExec = new PluginExecution(); 863 864 newExec.setConfiguration( exec.getConfiguration() ); 866 867 newExec.setId( exec.getId() ); 868 newExec.setInherited( exec.getInherited() ); 869 newExec.setPhase( exec.getPhase() ); 870 871 List goals = exec.getGoals(); 872 873 if ( goals != null && !goals.isEmpty() ) 874 { 875 newExec.setGoals( new ArrayList ( goals ) ); 876 } 877 878 newExecs.add( newExec ); 879 } 880 } 881 882 return newExecs; 883 } 884 885 private static Activation cloneProfileActivation( Activation activation ) 886 { 887 Activation newActivation = null; 888 if ( activation != null ) 889 { 890 newActivation = new Activation(); 891 892 newActivation.setActiveByDefault( activation.isActiveByDefault() ); 893 894 ActivationFile af = activation.getFile(); 895 896 if ( af != null ) 897 { 898 ActivationFile afNew = new ActivationFile(); 899 afNew.setExists( af.getExists() ); 900 afNew.setMissing( af.getMissing() ); 901 902 newActivation.setFile( afNew ); 903 } 904 905 newActivation.setJdk( activation.getJdk() ); 906 907 ActivationProperty ap = activation.getProperty(); 908 909 if ( ap != null ) 910 { 911 ActivationProperty newAp = new ActivationProperty(); 912 913 newAp.setName( ap.getName() ); 914 newAp.setValue( ap.getValue() ); 915 916 newActivation.setProperty( newAp ); 917 } 918 } 919 920 return newActivation; 921 } 922 923 private static List cloneModules( List modules ) 924 { 925 if ( modules == null ) 926 { 927 return modules; 928 } 929 return new ArrayList ( modules ); 930 } 931 932 private static Parent cloneParent( Parent parent ) 933 { 934 if ( parent == null ) 935 { 936 return parent; 937 } 938 939 Parent newParent = new Parent(); 940 newParent.setArtifactId( parent.getArtifactId() ); 941 newParent.setGroupId( parent.getGroupId() ); 942 newParent.setRelativePath( parent.getRelativePath() ); 943 newParent.setVersion( parent.getVersion() ); 944 return newParent; 945 } 946 947 public static List mergeRepositoryLists( List dominant, List recessive ) 948 { 949 List repositories = new ArrayList (); 950 951 for ( Iterator it = dominant.iterator(); it.hasNext(); ) 952 { 953 Repository repository = (Repository) it.next(); 954 955 repositories.add( repository ); 956 } 957 958 for ( Iterator it = recessive.iterator(); it.hasNext(); ) 959 { 960 Repository repository = (Repository) it.next(); 961 962 if ( !repositories.contains( repository ) ) 963 { 964 repositories.add( repository ); 965 } 966 } 967 968 return repositories; 969 } 970 971 public static void mergeExtensionLists( Build childBuild, Build parentBuild ) 972 { 973 for ( Iterator i = parentBuild.getExtensions().iterator(); i.hasNext(); ) 974 { 975 Extension e = (Extension) i.next(); 976 if ( !childBuild.getExtensions().contains( e ) ) 977 { 978 childBuild.addExtension( e ); 979 } 980 } 981 } 982 983 public static void mergeResourceLists( List childResources, List parentResources ) 984 { 985 for ( Iterator i = parentResources.iterator(); i.hasNext(); ) 986 { 987 Resource r = (Resource) i.next(); 988 if ( !childResources.contains( r ) ) 989 { 990 childResources.add( r ); 991 } 992 } 993 } 994 995 public static void mergeFilterLists( List childFilters, List parentFilters ) 996 { 997 for ( Iterator i = parentFilters.iterator(); i.hasNext(); ) 998 { 999 String f = (String ) i.next(); 1000 if ( !childFilters.contains( f ) ) 1001 { 1002 childFilters.add( f ); 1003 } 1004 } 1005 } 1006 1007 public static List mergeDependencyList( List child, List parent ) 1008 { 1009 Map depsMap = new HashMap (); 1010 1011 if ( parent != null ) 1012 { 1013 for ( Iterator it = parent.iterator(); it.hasNext(); ) 1014 { 1015 Dependency dependency = (Dependency) it.next(); 1016 depsMap.put( dependency.getManagementKey(), dependency ); 1017 } 1018 } 1019 1020 if ( child != null ) 1021 { 1022 for ( Iterator it = child.iterator(); it.hasNext(); ) 1023 { 1024 Dependency dependency = (Dependency) it.next(); 1025 depsMap.put( dependency.getManagementKey(), dependency ); 1026 } 1027 } 1028 1029 return new ArrayList ( depsMap.values() ); 1030 } 1031 1032} 1033 | Popular Tags |