Source Code Cross Referenced for ModelUtils.java in  » Build » maven » org » apache » maven » project » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » Build » maven » org.apache.maven.project 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


0001:        package org.apache.maven.project;
0002:
0003:        /*
0004:         * Licensed to the Apache Software Foundation (ASF) under one
0005:         * or more contributor license agreements.  See the NOTICE file
0006:         * distributed with this work for additional information
0007:         * regarding copyright ownership.  The ASF licenses this file
0008:         * to you under the Apache License, Version 2.0 (the
0009:         * "License"); you may not use this file except in compliance
0010:         * with the License.  You may obtain a copy of the License at
0011:         *
0012:         *  http://www.apache.org/licenses/LICENSE-2.0
0013:         *
0014:         * Unless required by applicable law or agreed to in writing,
0015:         * software distributed under the License is distributed on an
0016:         * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
0017:         * KIND, either express or implied.  See the License for the
0018:         * specific language governing permissions and limitations
0019:         * under the License.
0020:         */
0021:
0022:        import org.apache.maven.model.Activation;
0023:        import org.apache.maven.model.ActivationFile;
0024:        import org.apache.maven.model.ActivationProperty;
0025:        import org.apache.maven.model.Build;
0026:        import org.apache.maven.model.BuildBase;
0027:        import org.apache.maven.model.Dependency;
0028:        import org.apache.maven.model.DependencyManagement;
0029:        import org.apache.maven.model.DeploymentRepository;
0030:        import org.apache.maven.model.DistributionManagement;
0031:        import org.apache.maven.model.Exclusion;
0032:        import org.apache.maven.model.Extension;
0033:        import org.apache.maven.model.Model;
0034:        import org.apache.maven.model.Parent;
0035:        import org.apache.maven.model.Plugin;
0036:        import org.apache.maven.model.PluginContainer;
0037:        import org.apache.maven.model.PluginExecution;
0038:        import org.apache.maven.model.PluginManagement;
0039:        import org.apache.maven.model.Profile;
0040:        import org.apache.maven.model.Relocation;
0041:        import org.apache.maven.model.ReportPlugin;
0042:        import org.apache.maven.model.ReportSet;
0043:        import org.apache.maven.model.Reporting;
0044:        import org.apache.maven.model.Repository;
0045:        import org.apache.maven.model.RepositoryBase;
0046:        import org.apache.maven.model.RepositoryPolicy;
0047:        import org.apache.maven.model.Resource;
0048:        import org.apache.maven.model.Site;
0049:        import org.apache.maven.project.inheritance.DefaultModelInheritanceAssembler;
0050:        import org.apache.maven.project.inheritance.ModelInheritanceAssembler;
0051:        import org.codehaus.plexus.util.xml.Xpp3Dom;
0052:
0053:        import java.util.ArrayList;
0054:        import java.util.HashMap;
0055:        import java.util.Iterator;
0056:        import java.util.List;
0057:        import java.util.Map;
0058:        import java.util.Properties;
0059:        import java.util.TreeMap;
0060:
0061:        public final class ModelUtils {
0062:
0063:            /**
0064:             * This should be the resulting ordering of plugins after merging:
0065:             * 
0066:             * Given:
0067:             * 
0068:             *   parent: X -> A -> B -> D -> E
0069:             *   child: Y -> A -> C -> D -> F
0070:             *  
0071:             * Result: 
0072:             * 
0073:             *   X -> Y -> A -> B -> C -> D -> E -> F
0074:             */
0075:            public static void mergePluginLists(PluginContainer childContainer,
0076:                    PluginContainer parentContainer, boolean handleAsInheritance) {
0077:                if (childContainer == null || parentContainer == null) {
0078:                    // nothing to do.
0079:                    return;
0080:                }
0081:
0082:                List parentPlugins = parentContainer.getPlugins();
0083:
0084:                if (parentPlugins != null && !parentPlugins.isEmpty()) {
0085:                    parentPlugins = new ArrayList(parentPlugins);
0086:
0087:                    // If we're processing this merge as an inheritance, we have to build up a list of 
0088:                    // plugins that were considered for inheritance.
0089:                    if (handleAsInheritance) {
0090:                        for (Iterator it = parentPlugins.iterator(); it
0091:                                .hasNext();) {
0092:                            Plugin plugin = (Plugin) it.next();
0093:
0094:                            String inherited = plugin.getInherited();
0095:
0096:                            if (inherited != null
0097:                                    && !Boolean.valueOf(inherited)
0098:                                            .booleanValue()) {
0099:                                it.remove();
0100:                            }
0101:                        }
0102:                    }
0103:
0104:                    List assembledPlugins = new ArrayList();
0105:
0106:                    Map childPlugins = childContainer.getPluginsAsMap();
0107:
0108:                    for (Iterator it = parentPlugins.iterator(); it.hasNext();) {
0109:                        Plugin parentPlugin = (Plugin) it.next();
0110:
0111:                        String parentInherited = parentPlugin.getInherited();
0112:
0113:                        // only merge plugin definition from the parent if at least one 
0114:                        // of these is true:
0115:                        // 1. we're not processing the plugins in an inheritance-based merge
0116:                        // 2. the parent's <inherited/> flag is not set
0117:                        // 3. the parent's <inherited/> flag is set to true
0118:                        if (!handleAsInheritance
0119:                                || parentInherited == null
0120:                                || Boolean.valueOf(parentInherited)
0121:                                        .booleanValue()) {
0122:                            Plugin childPlugin = (Plugin) childPlugins
0123:                                    .get(parentPlugin.getKey());
0124:
0125:                            if (childPlugin != null
0126:                                    && !assembledPlugins.contains(childPlugin)) {
0127:                                Plugin assembledPlugin = childPlugin;
0128:
0129:                                mergePluginDefinitions(childPlugin,
0130:                                        parentPlugin, handleAsInheritance);
0131:
0132:                                // fix for MNG-2221 (assembly cache was not being populated for later reference):
0133:                                assembledPlugins.add(assembledPlugin);
0134:                            }
0135:
0136:                            // if we're processing this as an inheritance-based merge, and
0137:                            // the parent's <inherited/> flag is not set, then we need to
0138:                            // clear the inherited flag in the merge result.
0139:                            if (handleAsInheritance && parentInherited == null) {
0140:                                parentPlugin.unsetInheritanceApplied();
0141:                            }
0142:                        }
0143:
0144:                        // very important to use the parentPlugins List, rather than parentContainer.getPlugins()
0145:                        // since this list is a local one, and may have been modified during processing.
0146:                        List results = ModelUtils.orderAfterMerge(
0147:                                assembledPlugins, parentPlugins, childContainer
0148:                                        .getPlugins());
0149:
0150:                        childContainer.setPlugins(results);
0151:
0152:                        childContainer.flushPluginMap();
0153:                    }
0154:                }
0155:            }
0156:
0157:            public static List orderAfterMerge(List merged,
0158:                    List highPrioritySource, List lowPrioritySource) {
0159:                List results = new ArrayList();
0160:
0161:                if (!merged.isEmpty()) {
0162:                    results.addAll(merged);
0163:                }
0164:
0165:                List missingFromResults = new ArrayList();
0166:
0167:                List sources = new ArrayList();
0168:
0169:                sources.add(highPrioritySource);
0170:                sources.add(lowPrioritySource);
0171:
0172:                for (Iterator sourceIterator = sources.iterator(); sourceIterator
0173:                        .hasNext();) {
0174:                    List source = (List) sourceIterator.next();
0175:
0176:                    for (Iterator it = source.iterator(); it.hasNext();) {
0177:                        Object item = it.next();
0178:
0179:                        if (results.contains(item)) {
0180:                            if (!missingFromResults.isEmpty()) {
0181:                                int idx = results.indexOf(item);
0182:
0183:                                if (idx < 0) {
0184:                                    idx = 0;
0185:                                }
0186:
0187:                                results.addAll(idx, missingFromResults);
0188:
0189:                                missingFromResults.clear();
0190:                            }
0191:                        } else {
0192:                            missingFromResults.add(item);
0193:                        }
0194:                    }
0195:
0196:                    if (!missingFromResults.isEmpty()) {
0197:                        results.addAll(missingFromResults);
0198:
0199:                        missingFromResults.clear();
0200:                    }
0201:                }
0202:
0203:                return results;
0204:            }
0205:
0206:            public static void mergeReportPluginLists(Reporting child,
0207:                    Reporting parent, boolean handleAsInheritance) {
0208:                if (child == null || parent == null) {
0209:                    // nothing to do.
0210:                    return;
0211:                }
0212:
0213:                List parentPlugins = parent.getPlugins();
0214:
0215:                if (parentPlugins != null && !parentPlugins.isEmpty()) {
0216:                    Map assembledPlugins = new TreeMap();
0217:
0218:                    Map childPlugins = child.getReportPluginsAsMap();
0219:
0220:                    for (Iterator it = parentPlugins.iterator(); it.hasNext();) {
0221:                        ReportPlugin parentPlugin = (ReportPlugin) it.next();
0222:
0223:                        String parentInherited = parentPlugin.getInherited();
0224:
0225:                        if (!handleAsInheritance
0226:                                || parentInherited == null
0227:                                || Boolean.valueOf(parentInherited)
0228:                                        .booleanValue()) {
0229:
0230:                            ReportPlugin assembledPlugin = parentPlugin;
0231:
0232:                            ReportPlugin childPlugin = (ReportPlugin) childPlugins
0233:                                    .get(parentPlugin.getKey());
0234:
0235:                            if (childPlugin != null) {
0236:                                assembledPlugin = childPlugin;
0237:
0238:                                mergeReportPluginDefinitions(childPlugin,
0239:                                        parentPlugin, handleAsInheritance);
0240:                            }
0241:
0242:                            if (handleAsInheritance && parentInherited == null) {
0243:                                assembledPlugin.unsetInheritanceApplied();
0244:                            }
0245:
0246:                            assembledPlugins.put(assembledPlugin.getKey(),
0247:                                    assembledPlugin);
0248:                        }
0249:                    }
0250:
0251:                    for (Iterator it = childPlugins.values().iterator(); it
0252:                            .hasNext();) {
0253:                        ReportPlugin childPlugin = (ReportPlugin) it.next();
0254:
0255:                        if (!assembledPlugins.containsKey(childPlugin.getKey())) {
0256:                            assembledPlugins.put(childPlugin.getKey(),
0257:                                    childPlugin);
0258:                        }
0259:                    }
0260:
0261:                    child.setPlugins(new ArrayList(assembledPlugins.values()));
0262:
0263:                    child.flushReportPluginMap();
0264:                }
0265:            }
0266:
0267:            public static void mergePluginDefinitions(Plugin child,
0268:                    Plugin parent, boolean handleAsInheritance) {
0269:                if (child == null || parent == null) {
0270:                    // nothing to do.
0271:                    return;
0272:                }
0273:
0274:                if (parent.isExtensions()) {
0275:                    child.setExtensions(true);
0276:                }
0277:
0278:                if (child.getVersion() == null && parent.getVersion() != null) {
0279:                    child.setVersion(parent.getVersion());
0280:                }
0281:
0282:                Xpp3Dom childConfiguration = (Xpp3Dom) child.getConfiguration();
0283:                Xpp3Dom parentConfiguration = (Xpp3Dom) parent
0284:                        .getConfiguration();
0285:
0286:                childConfiguration = Xpp3Dom.mergeXpp3Dom(childConfiguration,
0287:                        parentConfiguration);
0288:
0289:                child.setConfiguration(childConfiguration);
0290:
0291:                child.setDependencies(mergeDependencyList(child
0292:                        .getDependencies(), parent.getDependencies()));
0293:
0294:                // from here to the end of the method is dealing with merging of the <executions/> section.
0295:                String parentInherited = parent.getInherited();
0296:
0297:                boolean parentIsInherited = parentInherited == null
0298:                        || Boolean.valueOf(parentInherited).booleanValue();
0299:
0300:                List parentExecutions = parent.getExecutions();
0301:
0302:                if (parentExecutions != null && !parentExecutions.isEmpty()) {
0303:                    List mergedExecutions = new ArrayList();
0304:
0305:                    Map assembledExecutions = new TreeMap();
0306:
0307:                    Map childExecutions = child.getExecutionsAsMap();
0308:
0309:                    for (Iterator it = parentExecutions.iterator(); it
0310:                            .hasNext();) {
0311:                        PluginExecution parentExecution = (PluginExecution) it
0312:                                .next();
0313:
0314:                        if (!handleAsInheritance || parentIsInherited) {
0315:                            PluginExecution assembled = parentExecution;
0316:
0317:                            PluginExecution childExecution = (PluginExecution) childExecutions
0318:                                    .get(parentExecution.getId());
0319:
0320:                            if (childExecution != null) {
0321:                                mergePluginExecutionDefinitions(childExecution,
0322:                                        parentExecution);
0323:
0324:                                assembled = childExecution;
0325:                            } else if (handleAsInheritance
0326:                                    && parentInherited == null) {
0327:                                parentExecution.unsetInheritanceApplied();
0328:                            }
0329:
0330:                            assembledExecutions.put(assembled.getId(),
0331:                                    assembled);
0332:                            mergedExecutions.add(assembled);
0333:                        }
0334:                    }
0335:
0336:                    for (Iterator it = child.getExecutions().iterator(); it
0337:                            .hasNext();) {
0338:                        PluginExecution childExecution = (PluginExecution) it
0339:                                .next();
0340:
0341:                        if (!assembledExecutions.containsKey(childExecution
0342:                                .getId())) {
0343:                            mergedExecutions.add(childExecution);
0344:                        }
0345:                    }
0346:
0347:                    child.setExecutions(mergedExecutions);
0348:
0349:                    child.flushExecutionMap();
0350:                }
0351:
0352:            }
0353:
0354:            public static void mergeReportPluginDefinitions(ReportPlugin child,
0355:                    ReportPlugin parent, boolean handleAsInheritance) {
0356:                if (child == null || parent == null) {
0357:                    // nothing to do.
0358:                    return;
0359:                }
0360:
0361:                if (child.getVersion() == null && parent.getVersion() != null) {
0362:                    child.setVersion(parent.getVersion());
0363:                }
0364:
0365:                // from here to the end of the method is dealing with merging of the <executions/> section.
0366:                String parentInherited = parent.getInherited();
0367:
0368:                boolean parentIsInherited = parentInherited == null
0369:                        || Boolean.valueOf(parentInherited).booleanValue();
0370:
0371:                List parentReportSets = parent.getReportSets();
0372:
0373:                if (parentReportSets != null && !parentReportSets.isEmpty()) {
0374:                    Map assembledReportSets = new TreeMap();
0375:
0376:                    Map childReportSets = child.getReportSetsAsMap();
0377:
0378:                    for (Iterator it = parentReportSets.iterator(); it
0379:                            .hasNext();) {
0380:                        ReportSet parentReportSet = (ReportSet) it.next();
0381:
0382:                        if (!handleAsInheritance || parentIsInherited) {
0383:                            ReportSet assembledReportSet = parentReportSet;
0384:
0385:                            ReportSet childReportSet = (ReportSet) childReportSets
0386:                                    .get(parentReportSet.getId());
0387:
0388:                            if (childReportSet != null) {
0389:                                mergeReportSetDefinitions(childReportSet,
0390:                                        parentReportSet);
0391:
0392:                                assembledReportSet = childReportSet;
0393:                            } else if (handleAsInheritance
0394:                                    && parentInherited == null) {
0395:                                parentReportSet.unsetInheritanceApplied();
0396:                            }
0397:
0398:                            assembledReportSets.put(assembledReportSet.getId(),
0399:                                    assembledReportSet);
0400:                        }
0401:                    }
0402:
0403:                    for (Iterator it = childReportSets.entrySet().iterator(); it
0404:                            .hasNext();) {
0405:                        Map.Entry entry = (Map.Entry) it.next();
0406:
0407:                        String id = (String) entry.getKey();
0408:
0409:                        if (!assembledReportSets.containsKey(id)) {
0410:                            assembledReportSets.put(id, entry.getValue());
0411:                        }
0412:                    }
0413:
0414:                    child.setReportSets(new ArrayList(assembledReportSets
0415:                            .values()));
0416:
0417:                    child.flushReportSetMap();
0418:                }
0419:
0420:            }
0421:
0422:            private static void mergePluginExecutionDefinitions(
0423:                    PluginExecution child, PluginExecution parent) {
0424:                if (child.getPhase() == null) {
0425:                    child.setPhase(parent.getPhase());
0426:                }
0427:
0428:                List parentGoals = parent.getGoals();
0429:                List childGoals = child.getGoals();
0430:
0431:                List goals = new ArrayList();
0432:
0433:                if (childGoals != null && !childGoals.isEmpty()) {
0434:                    goals.addAll(childGoals);
0435:                }
0436:
0437:                if (parentGoals != null) {
0438:                    for (Iterator goalIterator = parentGoals.iterator(); goalIterator
0439:                            .hasNext();) {
0440:                        String goal = (String) goalIterator.next();
0441:
0442:                        if (!goals.contains(goal)) {
0443:                            goals.add(goal);
0444:                        }
0445:                    }
0446:                }
0447:
0448:                child.setGoals(goals);
0449:
0450:                Xpp3Dom childConfiguration = (Xpp3Dom) child.getConfiguration();
0451:                Xpp3Dom parentConfiguration = (Xpp3Dom) parent
0452:                        .getConfiguration();
0453:
0454:                childConfiguration = Xpp3Dom.mergeXpp3Dom(childConfiguration,
0455:                        parentConfiguration);
0456:
0457:                child.setConfiguration(childConfiguration);
0458:            }
0459:
0460:            private static void mergeReportSetDefinitions(ReportSet child,
0461:                    ReportSet parent) {
0462:                List parentReports = parent.getReports();
0463:                List childReports = child.getReports();
0464:
0465:                List reports = new ArrayList();
0466:
0467:                if (childReports != null && !childReports.isEmpty()) {
0468:                    reports.addAll(childReports);
0469:                }
0470:
0471:                if (parentReports != null) {
0472:                    for (Iterator i = parentReports.iterator(); i.hasNext();) {
0473:                        String report = (String) i.next();
0474:
0475:                        if (!reports.contains(report)) {
0476:                            reports.add(report);
0477:                        }
0478:                    }
0479:                }
0480:
0481:                child.setReports(reports);
0482:
0483:                Xpp3Dom childConfiguration = (Xpp3Dom) child.getConfiguration();
0484:                Xpp3Dom parentConfiguration = (Xpp3Dom) parent
0485:                        .getConfiguration();
0486:
0487:                childConfiguration = Xpp3Dom.mergeXpp3Dom(childConfiguration,
0488:                        parentConfiguration);
0489:
0490:                child.setConfiguration(childConfiguration);
0491:            }
0492:
0493:            public static Model cloneModel(Model model) {
0494:                // TODO: would be nice for the modello:java code to generate this as a copy constructor
0495:                Model newModel = new Model();
0496:                ModelInheritanceAssembler assembler = new DefaultModelInheritanceAssembler();
0497:                newModel.setModelVersion(model.getModelVersion());
0498:                newModel.setName(model.getName());
0499:                newModel.setParent(cloneParent(model.getParent()));
0500:                newModel.setVersion(model.getVersion());
0501:                newModel.setArtifactId(model.getArtifactId());
0502:                newModel.setProperties(new Properties(model.getProperties()));
0503:                newModel.setGroupId(model.getGroupId());
0504:                newModel.setPackaging(model.getPackaging());
0505:                newModel.setModules(cloneModules(model.getModules()));
0506:
0507:                newModel.setProfiles(cloneProfiles(model.getProfiles()));
0508:
0509:                assembler.copyModel(newModel, model);
0510:
0511:                return newModel;
0512:            }
0513:
0514:            private static List cloneProfiles(List profiles) {
0515:                if (profiles == null) {
0516:                    return profiles;
0517:                }
0518:
0519:                List newProfiles = new ArrayList(profiles.size());
0520:
0521:                for (Iterator it = profiles.iterator(); it.hasNext();) {
0522:                    Profile profile = (Profile) it.next();
0523:
0524:                    Profile newProfile = new Profile();
0525:
0526:                    newProfile.setId(profile.getId());
0527:
0528:                    newProfile.setActivation(cloneProfileActivation(profile
0529:                            .getActivation()));
0530:
0531:                    newProfile.setBuild(cloneProfileBuild(profile.getBuild()));
0532:
0533:                    newProfile.setDependencies(cloneProfileDependencies(profile
0534:                            .getDependencies()));
0535:
0536:                    DependencyManagement dm = profile.getDependencyManagement();
0537:
0538:                    if (dm != null) {
0539:                        DependencyManagement newDM = new DependencyManagement();
0540:
0541:                        newDM.setDependencies(cloneProfileDependencies(dm
0542:                                .getDependencies()));
0543:
0544:                        newProfile.setDependencyManagement(newDM);
0545:                    }
0546:
0547:                    newProfile
0548:                            .setDistributionManagement(cloneProfileDistributionManagement(profile
0549:                                    .getDistributionManagement()));
0550:
0551:                    List modules = profile.getModules();
0552:
0553:                    if (modules != null && !modules.isEmpty()) {
0554:                        newProfile.setModules(new ArrayList(modules));
0555:                    }
0556:
0557:                    newProfile
0558:                            .setPluginRepositories(cloneProfileRepositories(profile
0559:                                    .getPluginRepositories()));
0560:
0561:                    Properties props = profile.getProperties();
0562:
0563:                    if (props != null) {
0564:                        Properties newProps = new Properties();
0565:                        newProps.putAll(props);
0566:
0567:                        newProfile.setProperties(newProps);
0568:                    }
0569:
0570:                    newProfile.setReporting(cloneProfileReporting(profile
0571:                            .getReporting()));
0572:
0573:                    newProfile.setReports(profile.getReports());
0574:
0575:                    newProfile.setRepositories(cloneProfileRepositories(profile
0576:                            .getRepositories()));
0577:
0578:                    newProfile.setSource(profile.getSource());
0579:
0580:                    newProfiles.add(newProfile);
0581:                }
0582:
0583:                return newProfiles;
0584:            }
0585:
0586:            private static Reporting cloneProfileReporting(Reporting reporting) {
0587:                Reporting newR = null;
0588:
0589:                if (reporting != null) {
0590:                    newR = new Reporting();
0591:
0592:                    newR.setOutputDirectory(reporting.getOutputDirectory());
0593:
0594:                    List plugins = reporting.getPlugins();
0595:
0596:                    if (plugins != null) {
0597:                        List newP = new ArrayList(plugins.size());
0598:
0599:                        for (Iterator it = plugins.iterator(); it.hasNext();) {
0600:                            ReportPlugin plugin = (ReportPlugin) it.next();
0601:
0602:                            ReportPlugin newPlugin = new ReportPlugin();
0603:
0604:                            newPlugin.setArtifactId(plugin.getArtifactId());
0605:                            newPlugin.setGroupId(plugin.getGroupId());
0606:                            newPlugin.setVersion(plugin.getVersion());
0607:                            newPlugin.setInherited(plugin.getInherited());
0608:                            newPlugin.setReportSets(cloneReportSets(plugin
0609:                                    .getReportSets()));
0610:
0611:                            // TODO: Implement deep-copy of configuration.
0612:                            newPlugin.setConfiguration(plugin
0613:                                    .getConfiguration());
0614:
0615:                            newP.add(newPlugin);
0616:                        }
0617:
0618:                        newR.setPlugins(newP);
0619:                    }
0620:                }
0621:
0622:                return newR;
0623:            }
0624:
0625:            private static List cloneReportSets(List sets) {
0626:                List newSets = null;
0627:
0628:                if (sets != null) {
0629:                    newSets = new ArrayList(sets.size());
0630:
0631:                    for (Iterator it = sets.iterator(); it.hasNext();) {
0632:                        ReportSet set = (ReportSet) it.next();
0633:
0634:                        ReportSet newSet = new ReportSet();
0635:
0636:                        // TODO: Deep-copy config.
0637:                        newSet.setConfiguration(set.getConfiguration());
0638:
0639:                        newSet.setId(set.getId());
0640:                        newSet.setInherited(set.getInherited());
0641:
0642:                        newSet.setReports(new ArrayList(set.getReports()));
0643:
0644:                        newSets.add(newSet);
0645:                    }
0646:                }
0647:
0648:                return newSets;
0649:            }
0650:
0651:            private static List cloneProfileRepositories(List repos) {
0652:                List newRepos = null;
0653:
0654:                if (repos != null) {
0655:                    newRepos = new ArrayList(repos.size());
0656:
0657:                    for (Iterator it = repos.iterator(); it.hasNext();) {
0658:                        Repository repo = (Repository) it.next();
0659:
0660:                        Repository newRepo = new Repository();
0661:
0662:                        newRepo.setId(repo.getId());
0663:                        newRepo.setLayout(repo.getLayout());
0664:                        newRepo.setName(repo.getName());
0665:
0666:                        RepositoryPolicy releasePolicy = repo.getReleases();
0667:
0668:                        if (releasePolicy != null) {
0669:                            RepositoryPolicy newPolicy = new RepositoryPolicy();
0670:                            newPolicy.setEnabled(releasePolicy.isEnabled());
0671:                            newPolicy.setChecksumPolicy(releasePolicy
0672:                                    .getChecksumPolicy());
0673:                            newPolicy.setUpdatePolicy(releasePolicy
0674:                                    .getUpdatePolicy());
0675:
0676:                            newRepo.setReleases(newPolicy);
0677:                        }
0678:
0679:                        RepositoryPolicy snapPolicy = repo.getSnapshots();
0680:
0681:                        if (snapPolicy != null) {
0682:                            RepositoryPolicy newPolicy = new RepositoryPolicy();
0683:                            newPolicy.setEnabled(snapPolicy.isEnabled());
0684:                            newPolicy.setChecksumPolicy(snapPolicy
0685:                                    .getChecksumPolicy());
0686:                            newPolicy.setUpdatePolicy(snapPolicy
0687:                                    .getUpdatePolicy());
0688:
0689:                            newRepo.setSnapshots(newPolicy);
0690:                        }
0691:
0692:                        newRepo.setUrl(repo.getUrl());
0693:
0694:                        newRepos.add(newRepo);
0695:                    }
0696:                }
0697:
0698:                return newRepos;
0699:            }
0700:
0701:            private static DistributionManagement cloneProfileDistributionManagement(
0702:                    DistributionManagement dm) {
0703:                DistributionManagement newDM = null;
0704:
0705:                if (dm != null) {
0706:                    newDM = new DistributionManagement();
0707:
0708:                    newDM.setDownloadUrl(dm.getDownloadUrl());
0709:                    newDM.setStatus(dm.getStatus());
0710:
0711:                    Relocation relocation = dm.getRelocation();
0712:
0713:                    if (relocation != null) {
0714:                        Relocation newR = new Relocation();
0715:
0716:                        newR.setArtifactId(relocation.getArtifactId());
0717:                        newR.setGroupId(relocation.getGroupId());
0718:                        newR.setMessage(relocation.getMessage());
0719:                        newR.setVersion(relocation.getVersion());
0720:
0721:                        newDM.setRelocation(newR);
0722:                    }
0723:
0724:                    RepositoryBase repo = dm.getRepository();
0725:
0726:                    if (repo != null) {
0727:                        DeploymentRepository newRepo = new DeploymentRepository();
0728:
0729:                        newRepo.setId(repo.getId());
0730:                        newRepo.setLayout(repo.getLayout());
0731:                        newRepo.setName(repo.getName());
0732:                        newRepo.setUrl(repo.getUrl());
0733:
0734:                        newDM.setRepository(newRepo);
0735:                    }
0736:
0737:                    Site site = dm.getSite();
0738:
0739:                    if (site != null) {
0740:                        Site newSite = new Site();
0741:
0742:                        newSite.setId(site.getId());
0743:                        newSite.setName(site.getName());
0744:                        newSite.setUrl(site.getUrl());
0745:
0746:                        newDM.setSite(newSite);
0747:                    }
0748:
0749:                    RepositoryBase sRepo = dm.getSnapshotRepository();
0750:
0751:                    if (sRepo != null) {
0752:                        DeploymentRepository newRepo = new DeploymentRepository();
0753:
0754:                        newRepo.setId(sRepo.getId());
0755:                        newRepo.setLayout(sRepo.getLayout());
0756:                        newRepo.setName(sRepo.getName());
0757:                        newRepo.setUrl(sRepo.getUrl());
0758:
0759:                        newDM.setSnapshotRepository(newRepo);
0760:                    }
0761:                }
0762:
0763:                return newDM;
0764:            }
0765:
0766:            private static List cloneProfileDependencies(List dependencies) {
0767:                List newDependencies = null;
0768:
0769:                if (dependencies != null) {
0770:                    newDependencies = new ArrayList(dependencies.size());
0771:
0772:                    for (Iterator it = dependencies.iterator(); it.hasNext();) {
0773:                        Dependency dep = (Dependency) it.next();
0774:
0775:                        Dependency newDep = new Dependency();
0776:
0777:                        newDep.setArtifactId(dep.getArtifactId());
0778:                        newDep.setClassifier(dep.getClassifier());
0779:                        newDep.setExclusions(cloneDependencyExclusions(dep
0780:                                .getExclusions()));
0781:                        newDep.setGroupId(dep.getGroupId());
0782:                        newDep.setScope(dep.getScope());
0783:                        newDep.setSystemPath(dep.getSystemPath());
0784:                        newDep.setType(dep.getType());
0785:                        newDep.setVersion(dep.getVersion());
0786:
0787:                        newDependencies.add(newDep);
0788:                    }
0789:                }
0790:
0791:                return newDependencies;
0792:            }
0793:
0794:            private static List cloneDependencyExclusions(List ex) {
0795:                List newEx = null;
0796:
0797:                if (ex != null) {
0798:                    newEx = new ArrayList(ex.size());
0799:
0800:                    for (Iterator it = ex.iterator(); it.hasNext();) {
0801:                        Exclusion exclusion = (Exclusion) it.next();
0802:
0803:                        Exclusion newExclusion = new Exclusion();
0804:
0805:                        newExclusion.setArtifactId(exclusion.getArtifactId());
0806:                        newExclusion.setGroupId(exclusion.getGroupId());
0807:
0808:                        newEx.add(newExclusion);
0809:                    }
0810:                }
0811:
0812:                return newEx;
0813:            }
0814:
0815:            private static BuildBase cloneProfileBuild(BuildBase build) {
0816:                BuildBase newBuild = null;
0817:                if (build != null) {
0818:                    newBuild = new BuildBase();
0819:
0820:                    newBuild.setDefaultGoal(build.getDefaultGoal());
0821:                    newBuild.setDirectory(build.getDirectory());
0822:                    newBuild.setFinalName(build.getFinalName());
0823:
0824:                    newBuild
0825:                            .setPluginManagement(cloneProfilePluginManagement(build
0826:                                    .getPluginManagement()));
0827:                    newBuild
0828:                            .setPlugins(cloneProfilePlugins(build.getPlugins()));
0829:                    newBuild.setResources(cloneProfileResources(build
0830:                            .getResources()));
0831:                    newBuild.setTestResources(cloneProfileResources(build
0832:                            .getTestResources()));
0833:                }
0834:
0835:                return newBuild;
0836:            }
0837:
0838:            private static List cloneProfileResources(List resources) {
0839:                List newResources = null;
0840:
0841:                if (resources != null) {
0842:                    newResources = new ArrayList(resources.size());
0843:
0844:                    for (Iterator it = resources.iterator(); it.hasNext();) {
0845:                        Resource resource = (Resource) it.next();
0846:
0847:                        Resource newResource = new Resource();
0848:
0849:                        newResource.setDirectory(resource.getDirectory());
0850:                        newResource.setExcludes(new ArrayList(resource
0851:                                .getExcludes()));
0852:                        newResource.setFiltering(resource.isFiltering());
0853:                        newResource.setIncludes(new ArrayList(resource
0854:                                .getIncludes()));
0855:                        newResource.setTargetPath(resource.getTargetPath());
0856:
0857:                        newResources.add(newResource);
0858:                    }
0859:                }
0860:
0861:                return newResources;
0862:            }
0863:
0864:            private static PluginManagement cloneProfilePluginManagement(
0865:                    PluginManagement pluginManagement) {
0866:                PluginManagement newPM = null;
0867:
0868:                if (pluginManagement != null) {
0869:                    newPM = new PluginManagement();
0870:
0871:                    List plugins = pluginManagement.getPlugins();
0872:
0873:                    newPM.setPlugins(cloneProfilePlugins(plugins));
0874:                }
0875:
0876:                return newPM;
0877:            }
0878:
0879:            private static List cloneProfilePlugins(List plugins) {
0880:                List newPlugins = null;
0881:
0882:                if (plugins != null) {
0883:                    newPlugins = new ArrayList(plugins.size());
0884:
0885:                    for (Iterator it = plugins.iterator(); it.hasNext();) {
0886:                        Plugin plugin = (Plugin) it.next();
0887:
0888:                        Plugin newPlugin = new Plugin();
0889:
0890:                        newPlugin.setArtifactId(plugin.getArtifactId());
0891:                        newPlugin.setExtensions(plugin.isExtensions());
0892:                        newPlugin.setGroupId(plugin.getGroupId());
0893:                        newPlugin.setInherited(plugin.getInherited());
0894:                        newPlugin.setVersion(plugin.getVersion());
0895:
0896:                        // TODO: Deep-copy this!
0897:                        newPlugin.setConfiguration(plugin.getConfiguration());
0898:
0899:                        newPlugin.setExecutions(cloneExecutions(plugin
0900:                                .getExecutions()));
0901:
0902:                        newPlugins.add(newPlugin);
0903:                    }
0904:                }
0905:
0906:                return newPlugins;
0907:            }
0908:
0909:            private static List cloneExecutions(List executions) {
0910:                List newExecs = null;
0911:
0912:                if (executions != null) {
0913:                    newExecs = new ArrayList(executions.size());
0914:
0915:                    for (Iterator it = executions.iterator(); it.hasNext();) {
0916:                        PluginExecution exec = (PluginExecution) it.next();
0917:
0918:                        PluginExecution newExec = new PluginExecution();
0919:
0920:                        // TODO: Deep-copy configs.
0921:                        newExec.setConfiguration(exec.getConfiguration());
0922:
0923:                        newExec.setId(exec.getId());
0924:                        newExec.setInherited(exec.getInherited());
0925:                        newExec.setPhase(exec.getPhase());
0926:
0927:                        List goals = exec.getGoals();
0928:
0929:                        if (goals != null && !goals.isEmpty()) {
0930:                            newExec.setGoals(new ArrayList(goals));
0931:                        }
0932:
0933:                        newExecs.add(newExec);
0934:                    }
0935:                }
0936:
0937:                return newExecs;
0938:            }
0939:
0940:            private static Activation cloneProfileActivation(
0941:                    Activation activation) {
0942:                Activation newActivation = null;
0943:                if (activation != null) {
0944:                    newActivation = new Activation();
0945:
0946:                    newActivation.setActiveByDefault(activation
0947:                            .isActiveByDefault());
0948:
0949:                    ActivationFile af = activation.getFile();
0950:
0951:                    if (af != null) {
0952:                        ActivationFile afNew = new ActivationFile();
0953:                        afNew.setExists(af.getExists());
0954:                        afNew.setMissing(af.getMissing());
0955:
0956:                        newActivation.setFile(afNew);
0957:                    }
0958:
0959:                    newActivation.setJdk(activation.getJdk());
0960:
0961:                    ActivationProperty ap = activation.getProperty();
0962:
0963:                    if (ap != null) {
0964:                        ActivationProperty newAp = new ActivationProperty();
0965:
0966:                        newAp.setName(ap.getName());
0967:                        newAp.setValue(ap.getValue());
0968:
0969:                        newActivation.setProperty(newAp);
0970:                    }
0971:                }
0972:
0973:                return newActivation;
0974:            }
0975:
0976:            private static List cloneModules(List modules) {
0977:                if (modules == null) {
0978:                    return modules;
0979:                }
0980:                return new ArrayList(modules);
0981:            }
0982:
0983:            private static Parent cloneParent(Parent parent) {
0984:                if (parent == null) {
0985:                    return parent;
0986:                }
0987:
0988:                Parent newParent = new Parent();
0989:                newParent.setArtifactId(parent.getArtifactId());
0990:                newParent.setGroupId(parent.getGroupId());
0991:                newParent.setRelativePath(parent.getRelativePath());
0992:                newParent.setVersion(parent.getVersion());
0993:                return newParent;
0994:            }
0995:
0996:            public static List mergeRepositoryLists(List dominant,
0997:                    List recessive) {
0998:                List repositories = new ArrayList();
0999:
1000:                for (Iterator it = dominant.iterator(); it.hasNext();) {
1001:                    Repository repository = (Repository) it.next();
1002:
1003:                    repositories.add(repository);
1004:                }
1005:
1006:                for (Iterator it = recessive.iterator(); it.hasNext();) {
1007:                    Repository repository = (Repository) it.next();
1008:
1009:                    if (!repositories.contains(repository)) {
1010:                        repositories.add(repository);
1011:                    }
1012:                }
1013:
1014:                return repositories;
1015:            }
1016:
1017:            public static void mergeExtensionLists(Build childBuild,
1018:                    Build parentBuild) {
1019:                for (Iterator i = parentBuild.getExtensions().iterator(); i
1020:                        .hasNext();) {
1021:                    Extension e = (Extension) i.next();
1022:                    if (!childBuild.getExtensions().contains(e)) {
1023:                        childBuild.addExtension(e);
1024:                    }
1025:                }
1026:            }
1027:
1028:            public static void mergeResourceLists(List childResources,
1029:                    List parentResources) {
1030:                for (Iterator i = parentResources.iterator(); i.hasNext();) {
1031:                    Resource r = (Resource) i.next();
1032:                    if (!childResources.contains(r)) {
1033:                        childResources.add(r);
1034:                    }
1035:                }
1036:            }
1037:
1038:            public static void mergeFilterLists(List childFilters,
1039:                    List parentFilters) {
1040:                for (Iterator i = parentFilters.iterator(); i.hasNext();) {
1041:                    String f = (String) i.next();
1042:                    if (!childFilters.contains(f)) {
1043:                        childFilters.add(f);
1044:                    }
1045:                }
1046:            }
1047:
1048:            public static List mergeDependencyList(List child, List parent) {
1049:                Map depsMap = new HashMap();
1050:
1051:                if (parent != null) {
1052:                    for (Iterator it = parent.iterator(); it.hasNext();) {
1053:                        Dependency dependency = (Dependency) it.next();
1054:                        depsMap.put(dependency.getManagementKey(), dependency);
1055:                    }
1056:                }
1057:
1058:                if (child != null) {
1059:                    for (Iterator it = child.iterator(); it.hasNext();) {
1060:                        Dependency dependency = (Dependency) it.next();
1061:                        depsMap.put(dependency.getManagementKey(), dependency);
1062:                    }
1063:                }
1064:
1065:                return new ArrayList(depsMap.values());
1066:            }
1067:
1068:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.