You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@maven.apache.org by jd...@apache.org on 2005/08/24 22:31:40 UTC
svn commit: r239918 - in /maven/components/trunk: maven-core-it/
maven-core-it/it0058/ maven-core-it/it0058/subproject/
maven-core-it/it0058/subproject/src/
maven-core-it/it0058/subproject/src/main/
maven-core-it/it0058/subproject/src/main/java/ maven-...
Author: jdcasey
Date: Wed Aug 24 13:31:29 2005
New Revision: 239918
URL: http://svn.apache.org/viewcvs?rev=239918&view=rev
Log:
Resolving: MNG-773
o Separated profile injection logic from the inheritance assembly. While they look similar superficially, the
merge-out vs. merge-in semantics make it pretty complex to put this logic together in the same methods. It's
easier to understand what's going on if they remain similar but separate code...
o Added it0058 to test that application of a profile from settings.xml doesn't transport module lists from POM
to POM inside of a reactor build.
Added:
maven/components/trunk/maven-core-it/it0058/
maven/components/trunk/maven-core-it/it0058/cli-options.txt (with props)
maven/components/trunk/maven-core-it/it0058/expected-results.txt (with props)
maven/components/trunk/maven-core-it/it0058/goals.txt (with props)
maven/components/trunk/maven-core-it/it0058/pom.xml (with props)
maven/components/trunk/maven-core-it/it0058/settings.xml (with props)
maven/components/trunk/maven-core-it/it0058/subproject/
maven/components/trunk/maven-core-it/it0058/subproject/pom.xml (with props)
maven/components/trunk/maven-core-it/it0058/subproject/src/
maven/components/trunk/maven-core-it/it0058/subproject/src/main/
maven/components/trunk/maven-core-it/it0058/subproject/src/main/java/
maven/components/trunk/maven-core-it/it0058/subproject/src/main/java/org/
maven/components/trunk/maven-core-it/it0058/subproject/src/main/java/org/apache/
maven/components/trunk/maven-core-it/it0058/subproject/src/main/java/org/apache/maven/
maven/components/trunk/maven-core-it/it0058/subproject/src/main/java/org/apache/maven/it0001/
maven/components/trunk/maven-core-it/it0058/subproject/src/main/java/org/apache/maven/it0001/Person.java (with props)
maven/components/trunk/maven-core-it/it0058/subproject/src/main/resources/
maven/components/trunk/maven-core-it/it0058/subproject/src/main/resources/it0001.properties (with props)
maven/components/trunk/maven-core-it/it0058/subproject/src/test/
maven/components/trunk/maven-core-it/it0058/subproject/src/test/java/
maven/components/trunk/maven-core-it/it0058/subproject/src/test/java/org/
maven/components/trunk/maven-core-it/it0058/subproject/src/test/java/org/apache/
maven/components/trunk/maven-core-it/it0058/subproject/src/test/java/org/apache/maven/
maven/components/trunk/maven-core-it/it0058/subproject/src/test/java/org/apache/maven/it0001/
maven/components/trunk/maven-core-it/it0058/subproject/src/test/java/org/apache/maven/it0001/PersonTest.java (with props)
Modified:
maven/components/trunk/maven-core-it/README.txt
maven/components/trunk/maven-core-it/integration-tests.txt
maven/components/trunk/maven-project/src/main/java/org/apache/maven/project/ModelUtils.java
maven/components/trunk/maven-project/src/main/java/org/apache/maven/project/inheritance/DefaultModelInheritanceAssembler.java
maven/components/trunk/maven-project/src/main/java/org/apache/maven/project/injection/DefaultProfileInjector.java
Modified: maven/components/trunk/maven-core-it/README.txt
URL: http://svn.apache.org/viewcvs/maven/components/trunk/maven-core-it/README.txt?rev=239918&r1=239917&r2=239918&view=diff
==============================================================================
--- maven/components/trunk/maven-core-it/README.txt (original)
+++ maven/components/trunk/maven-core-it/README.txt Wed Aug 24 13:31:29 2005
@@ -161,6 +161,9 @@
it0057: Verify that scope == 'provided' dependencies are available to tests.
+it0058: Verify that profiles from settings.xml do not pollute module lists
+ across projects in a reactorized build.
+
-------------------------------------------------------------------------------
- generated sources
Modified: maven/components/trunk/maven-core-it/integration-tests.txt
URL: http://svn.apache.org/viewcvs/maven/components/trunk/maven-core-it/integration-tests.txt?rev=239918&r1=239917&r2=239918&view=diff
==============================================================================
--- maven/components/trunk/maven-core-it/integration-tests.txt (original)
+++ maven/components/trunk/maven-core-it/integration-tests.txt Wed Aug 24 13:31:29 2005
@@ -1,3 +1,4 @@
+it0058
it0057
it0056
it0055
Added: maven/components/trunk/maven-core-it/it0058/cli-options.txt
URL: http://svn.apache.org/viewcvs/maven/components/trunk/maven-core-it/it0058/cli-options.txt?rev=239918&view=auto
==============================================================================
--- maven/components/trunk/maven-core-it/it0058/cli-options.txt (added)
+++ maven/components/trunk/maven-core-it/it0058/cli-options.txt Wed Aug 24 13:31:29 2005
@@ -0,0 +1 @@
+--settings ./settings.xml
Propchange: maven/components/trunk/maven-core-it/it0058/cli-options.txt
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: maven/components/trunk/maven-core-it/it0058/cli-options.txt
------------------------------------------------------------------------------
svn:keywords = "Author Date Id Revision"
Added: maven/components/trunk/maven-core-it/it0058/expected-results.txt
URL: http://svn.apache.org/viewcvs/maven/components/trunk/maven-core-it/it0058/expected-results.txt?rev=239918&view=auto
==============================================================================
--- maven/components/trunk/maven-core-it/it0058/expected-results.txt (added)
+++ maven/components/trunk/maven-core-it/it0058/expected-results.txt Wed Aug 24 13:31:29 2005
@@ -0,0 +1 @@
+subproject/target/maven-core-it0058-subproject-1.0.jar
Propchange: maven/components/trunk/maven-core-it/it0058/expected-results.txt
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: maven/components/trunk/maven-core-it/it0058/expected-results.txt
------------------------------------------------------------------------------
svn:keywords = "Author Date Id Revision"
Added: maven/components/trunk/maven-core-it/it0058/goals.txt
URL: http://svn.apache.org/viewcvs/maven/components/trunk/maven-core-it/it0058/goals.txt?rev=239918&view=auto
==============================================================================
--- maven/components/trunk/maven-core-it/it0058/goals.txt (added)
+++ maven/components/trunk/maven-core-it/it0058/goals.txt Wed Aug 24 13:31:29 2005
@@ -0,0 +1 @@
+package
Propchange: maven/components/trunk/maven-core-it/it0058/goals.txt
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: maven/components/trunk/maven-core-it/it0058/goals.txt
------------------------------------------------------------------------------
svn:keywords = "Author Date Id Revision"
Added: maven/components/trunk/maven-core-it/it0058/pom.xml
URL: http://svn.apache.org/viewcvs/maven/components/trunk/maven-core-it/it0058/pom.xml?rev=239918&view=auto
==============================================================================
--- maven/components/trunk/maven-core-it/it0058/pom.xml (added)
+++ maven/components/trunk/maven-core-it/it0058/pom.xml Wed Aug 24 13:31:29 2005
@@ -0,0 +1,11 @@
+<model>
+ <modelVersion>4.0.0</modelVersion>
+ <groupId>org.apache.maven.it</groupId>
+ <artifactId>maven-core-it0058</artifactId>
+ <packaging>pom</packaging>
+ <version>1.0</version>
+
+ <modules>
+ <module>subproject</module>
+ </modules>
+</model>
Propchange: maven/components/trunk/maven-core-it/it0058/pom.xml
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: maven/components/trunk/maven-core-it/it0058/pom.xml
------------------------------------------------------------------------------
svn:keywords = "Author Date Id Revision"
Added: maven/components/trunk/maven-core-it/it0058/settings.xml
URL: http://svn.apache.org/viewcvs/maven/components/trunk/maven-core-it/it0058/settings.xml?rev=239918&view=auto
==============================================================================
--- maven/components/trunk/maven-core-it/it0058/settings.xml (added)
+++ maven/components/trunk/maven-core-it/it0058/settings.xml Wed Aug 24 13:31:29 2005
@@ -0,0 +1,19 @@
+<settings>
+
+ <profiles>
+ <profile>
+ <id>test-repo</id>
+ <repositories>
+ <repository>
+ <id>test-repo</id>
+ <url>file:../../test-repo</url>
+ </repository>
+ </repositories>
+ </profile>
+ </profiles>
+
+ <activeProfiles>
+ <activeProfile>test-repo</activeProfile>
+ </activeProfiles>
+
+</settings>
Propchange: maven/components/trunk/maven-core-it/it0058/settings.xml
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: maven/components/trunk/maven-core-it/it0058/settings.xml
------------------------------------------------------------------------------
svn:keywords = "Author Date Id Revision"
Added: maven/components/trunk/maven-core-it/it0058/subproject/pom.xml
URL: http://svn.apache.org/viewcvs/maven/components/trunk/maven-core-it/it0058/subproject/pom.xml?rev=239918&view=auto
==============================================================================
--- maven/components/trunk/maven-core-it/it0058/subproject/pom.xml (added)
+++ maven/components/trunk/maven-core-it/it0058/subproject/pom.xml Wed Aug 24 13:31:29 2005
@@ -0,0 +1,18 @@
+<model>
+ <modelVersion>4.0.0</modelVersion>
+ <parent>
+ <groupId>org.apache.maven.it</groupId>
+ <artifactId>maven-core-it0058</artifactId>
+ <version>1.0</version>
+ </parent>
+ <artifactId>maven-core-it0058-subproject</artifactId>
+ <dependencies>
+ <dependency>
+ <groupId>junit</groupId>
+ <artifactId>junit</artifactId>
+ <version>3.8.1</version>
+ <type>jar</type>
+ <scope>test</scope>
+ </dependency>
+ </dependencies>
+</model>
Propchange: maven/components/trunk/maven-core-it/it0058/subproject/pom.xml
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: maven/components/trunk/maven-core-it/it0058/subproject/pom.xml
------------------------------------------------------------------------------
svn:keywords = "Author Date Id Revision"
Added: maven/components/trunk/maven-core-it/it0058/subproject/src/main/java/org/apache/maven/it0001/Person.java
URL: http://svn.apache.org/viewcvs/maven/components/trunk/maven-core-it/it0058/subproject/src/main/java/org/apache/maven/it0001/Person.java?rev=239918&view=auto
==============================================================================
--- maven/components/trunk/maven-core-it/it0058/subproject/src/main/java/org/apache/maven/it0001/Person.java (added)
+++ maven/components/trunk/maven-core-it/it0058/subproject/src/main/java/org/apache/maven/it0001/Person.java Wed Aug 24 13:31:29 2005
@@ -0,0 +1,16 @@
+package org.apache.maven.it0001;
+
+public class Person
+{
+ private String name;
+
+ public void setName( String name )
+ {
+ this.name = name;
+ }
+
+ public String getName()
+ {
+ return name;
+ }
+}
Propchange: maven/components/trunk/maven-core-it/it0058/subproject/src/main/java/org/apache/maven/it0001/Person.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: maven/components/trunk/maven-core-it/it0058/subproject/src/main/java/org/apache/maven/it0001/Person.java
------------------------------------------------------------------------------
svn:keywords = "Author Date Id Revision"
Added: maven/components/trunk/maven-core-it/it0058/subproject/src/main/resources/it0001.properties
URL: http://svn.apache.org/viewcvs/maven/components/trunk/maven-core-it/it0058/subproject/src/main/resources/it0001.properties?rev=239918&view=auto
==============================================================================
--- maven/components/trunk/maven-core-it/it0058/subproject/src/main/resources/it0001.properties (added)
+++ maven/components/trunk/maven-core-it/it0058/subproject/src/main/resources/it0001.properties Wed Aug 24 13:31:29 2005
@@ -0,0 +1 @@
+name = jason
Propchange: maven/components/trunk/maven-core-it/it0058/subproject/src/main/resources/it0001.properties
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: maven/components/trunk/maven-core-it/it0058/subproject/src/main/resources/it0001.properties
------------------------------------------------------------------------------
svn:keywords = "Author Date Id Revision"
Added: maven/components/trunk/maven-core-it/it0058/subproject/src/test/java/org/apache/maven/it0001/PersonTest.java
URL: http://svn.apache.org/viewcvs/maven/components/trunk/maven-core-it/it0058/subproject/src/test/java/org/apache/maven/it0001/PersonTest.java?rev=239918&view=auto
==============================================================================
--- maven/components/trunk/maven-core-it/it0058/subproject/src/test/java/org/apache/maven/it0001/PersonTest.java (added)
+++ maven/components/trunk/maven-core-it/it0058/subproject/src/test/java/org/apache/maven/it0001/PersonTest.java Wed Aug 24 13:31:29 2005
@@ -0,0 +1,16 @@
+package org.apache.maven.it0001;
+
+import junit.framework.TestCase;
+
+public class PersonTest
+ extends TestCase
+{
+ public void testPerson()
+ {
+ Person person = new Person();
+
+ person.setName( "foo" );
+
+ assertEquals( "foo", person.getName() );
+ }
+}
Propchange: maven/components/trunk/maven-core-it/it0058/subproject/src/test/java/org/apache/maven/it0001/PersonTest.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: maven/components/trunk/maven-core-it/it0058/subproject/src/test/java/org/apache/maven/it0001/PersonTest.java
------------------------------------------------------------------------------
svn:keywords = "Author Date Id Revision"
Modified: maven/components/trunk/maven-project/src/main/java/org/apache/maven/project/ModelUtils.java
URL: http://svn.apache.org/viewcvs/maven/components/trunk/maven-project/src/main/java/org/apache/maven/project/ModelUtils.java?rev=239918&r1=239917&r2=239918&view=diff
==============================================================================
--- maven/components/trunk/maven-project/src/main/java/org/apache/maven/project/ModelUtils.java (original)
+++ maven/components/trunk/maven-project/src/main/java/org/apache/maven/project/ModelUtils.java Wed Aug 24 13:31:29 2005
@@ -16,30 +16,17 @@
* limitations under the License.
*/
-import org.apache.maven.model.Build;
-import org.apache.maven.model.BuildBase;
-import org.apache.maven.model.Dependency;
-import org.apache.maven.model.DependencyManagement;
-import org.apache.maven.model.DistributionManagement;
import org.apache.maven.model.Goal;
import org.apache.maven.model.Model;
-import org.apache.maven.model.ModelBase;
import org.apache.maven.model.Plugin;
import org.apache.maven.model.PluginContainer;
import org.apache.maven.model.PluginExecution;
-import org.apache.maven.model.PluginManagement;
-import org.apache.maven.model.Profile;
-import org.apache.maven.model.ReportPlugin;
-import org.apache.maven.model.ReportSet;
-import org.apache.maven.model.Reporting;
import org.apache.maven.model.Repository;
import org.apache.maven.project.inheritance.DefaultModelInheritanceAssembler;
import org.apache.maven.project.inheritance.ModelInheritanceAssembler;
-import org.codehaus.plexus.util.StringUtils;
import org.codehaus.plexus.util.xml.Xpp3Dom;
import java.util.ArrayList;
-import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
@@ -258,128 +245,67 @@
private static void mergePluginExecutionDefinitions( PluginExecution child, PluginExecution parent )
{
- List parentGoals = parent.getGoals();
-
- // if the supplemental goals are non-existent, then nothing related to goals changes.
- if ( parentGoals != null && !parentGoals.isEmpty() )
- {
- List goals = new ArrayList( parentGoals );
- if ( child.getGoals() != null )
- {
- goals.addAll( child.getGoals() );
- }
-
- child.setGoals( goals );
- }
-
- Xpp3Dom childConfiguration = (Xpp3Dom) child.getConfiguration();
- Xpp3Dom parentConfiguration = (Xpp3Dom) parent.getConfiguration();
-
- childConfiguration = Xpp3Dom.mergeXpp3Dom( childConfiguration, parentConfiguration );
-
- child.setConfiguration( childConfiguration );
- }
-
- public static void mergeModelBases( ModelBase dominant, ModelBase recessive, boolean mergePathStructures )
- {
- mergeDependencies( dominant, recessive );
-
- if ( mergePathStructures )
+ if ( child.getPhase() == null )
{
- mergeModules( dominant, recessive );
+ child.setPhase( parent.getPhase() );
}
- dominant.setRepositories( mergeRepositoryLists( dominant.getRepositories(), recessive.getRepositories() ) );
- dominant.setPluginRepositories( mergeRepositoryLists( dominant.getPluginRepositories(), recessive.getPluginRepositories() ) );
-
- mergeReporting( dominant, recessive );
-
- mergeDependencyManagementSections( dominant, recessive );
-
- mergeDistributionManagementSections( dominant, recessive );
- }
-
- private static void mergeModules( ModelBase dominant, ModelBase recessive )
- {
- List modules = new ArrayList();
+ List parentGoals = parent.getGoals();
+ List childGoals = child.getGoals();
- List dominantModules = dominant.getModules();
+ List goals = new ArrayList();
- if ( dominantModules != null && !dominantModules.isEmpty() )
+ if ( childGoals != null && !childGoals.isEmpty() )
{
- modules.addAll( dominantModules );
+ goals.addAll( childGoals );
}
- List recessiveModules = recessive.getModules();
-
- if ( recessiveModules != null )
+ if ( parentGoals != null )
{
- for ( Iterator it = recessiveModules.iterator(); it.hasNext(); )
+ for ( Iterator goalIterator = parentGoals.iterator(); goalIterator.hasNext(); )
{
- String module = (String) it.next();
+ String goal = (String) goalIterator.next();
- if ( !modules.contains( module ) )
+ if ( !goals.contains( goal ) )
{
- modules.add( module );
+ goals.add( goal );
}
}
}
- dominant.setModules( modules );
+ child.setGoals( goals );
+
+ Xpp3Dom childConfiguration = (Xpp3Dom) child.getConfiguration();
+ Xpp3Dom parentConfiguration = (Xpp3Dom) parent.getConfiguration();
+
+ childConfiguration = Xpp3Dom.mergeXpp3Dom( childConfiguration, parentConfiguration );
+
+ child.setConfiguration( childConfiguration );
}
- private static void mergeDistributionManagementSections( ModelBase dominant, ModelBase recessive )
+ static Model cloneModel( Model model )
{
- DistributionManagement dDistMgmt = dominant.getDistributionManagement();
- DistributionManagement rDistMgmt = recessive.getDistributionManagement();
-
- if ( dDistMgmt == null )
- {
- dominant.setDistributionManagement( rDistMgmt );
- }
- else if ( rDistMgmt != null )
- {
- if ( dDistMgmt.getRepository() == null )
- {
- dDistMgmt.setRepository( rDistMgmt.getRepository() );
- }
-
- if ( dDistMgmt.getSnapshotRepository() == null )
- {
- dDistMgmt.setSnapshotRepository( rDistMgmt.getSnapshotRepository() );
- }
-
- if ( StringUtils.isEmpty( dDistMgmt.getDownloadUrl() ) )
- {
- dDistMgmt.setDownloadUrl( rDistMgmt.getDownloadUrl() );
- }
-
- if ( dDistMgmt.getRelocation() == null )
- {
- dDistMgmt.setRelocation( rDistMgmt.getRelocation() );
- }
-
- if ( dDistMgmt.getSite() == null )
- {
- dDistMgmt.setSite( rDistMgmt.getSite() );
- }
-
- // NOTE: We SHOULD NOT be inheriting status, since this is an assessment of the POM quality.
- }
+ // TODO: would be nice for the modello:java code to generate this as a copy constructor
+ Model newModel = new Model();
+ ModelInheritanceAssembler assembler = new DefaultModelInheritanceAssembler();
+ assembler.assembleModelInheritance( newModel, model );
+ newModel.setVersion( model.getVersion() );
+ newModel.setArtifactId( model.getArtifactId() );
+ return newModel;
}
- private static List mergeRepositoryLists( List dominantRepositories, List recessiveRepositories )
+ public static List mergeRepositoryLists( List dominant, List recessive )
{
List repositories = new ArrayList();
- for ( Iterator it = dominantRepositories.iterator(); it.hasNext(); )
+ for ( Iterator it = dominant.iterator(); it.hasNext(); )
{
Repository repository = (Repository) it.next();
repositories.add( repository );
}
- for ( Iterator it = recessiveRepositories.iterator(); it.hasNext(); )
+ for ( Iterator it = recessive.iterator(); it.hasNext(); )
{
Repository repository = (Repository) it.next();
@@ -390,313 +316,5 @@
}
return repositories;
- }
-
- private static void mergeDependencies( ModelBase dominant, ModelBase recessive )
- {
- Map depsMap = new HashMap();
-
- List deps = recessive.getDependencies();
-
- if ( deps != null )
- {
- for ( Iterator it = deps.iterator(); it.hasNext(); )
- {
- Dependency dependency = (Dependency) it.next();
- depsMap.put( dependency.getManagementKey(), dependency );
- }
- }
-
- deps = dominant.getDependencies();
-
- if ( deps != null )
- {
- for ( Iterator it = deps.iterator(); it.hasNext(); )
- {
- Dependency dependency = (Dependency) it.next();
- depsMap.put( dependency.getManagementKey(), dependency );
- }
- }
-
- dominant.setDependencies( new ArrayList( depsMap.values() ) );
- }
-
- public static void mergeReporting( ModelBase dominant, ModelBase recessive )
- {
- // Reports :: aggregate
- Reporting dominantReporting = dominant.getReporting();
- Reporting modelReporting = recessive.getReporting();
-
- if ( dominantReporting != null && modelReporting != null )
- {
- if ( StringUtils.isEmpty( dominantReporting.getOutputDirectory() ) )
- {
- dominantReporting.setOutputDirectory( modelReporting.getOutputDirectory() );
- }
-
- Map mergedReportPlugins = new HashMap();
-
- Map dominantReportersByKey = dominantReporting.getReportPluginsAsMap();
-
- List parentReportPlugins = modelReporting.getPlugins();
-
- if ( parentReportPlugins != null )
- {
- for ( Iterator it = parentReportPlugins.iterator(); it.hasNext(); )
- {
- ReportPlugin recessiveReportPlugin = (ReportPlugin) it.next();
-
- String inherited = recessiveReportPlugin.getInherited();
-
- if ( StringUtils.isEmpty( inherited ) || Boolean.valueOf( inherited ).booleanValue() )
- {
- ReportPlugin dominantReportPlugin = (ReportPlugin) dominantReportersByKey.get(
- recessiveReportPlugin.getKey() );
-
- ReportPlugin mergedReportPlugin = recessiveReportPlugin;
-
- if ( dominantReportPlugin != null )
- {
- mergedReportPlugin = dominantReportPlugin;
-
- mergeReportPlugins( dominantReportPlugin, recessiveReportPlugin );
- }
- else if ( StringUtils.isEmpty( inherited ) )
- {
- mergedReportPlugin.unsetInheritanceApplied();
- }
-
- mergedReportPlugins.put( mergedReportPlugin.getKey(), mergedReportPlugin );
- }
- }
- }
-
- for ( Iterator it = dominantReportersByKey.entrySet().iterator(); it.hasNext(); )
- {
- Map.Entry entry = (Map.Entry) it.next();
-
- String key = (String) entry.getKey();
-
- if ( !mergedReportPlugins.containsKey( key ) )
- {
- mergedReportPlugins.put( key, entry.getValue() );
- }
- }
-
- dominantReporting.setPlugins( new ArrayList( mergedReportPlugins.values() ) );
-
- dominantReporting.flushReportPluginMap();
- }
- }
-
- public static void mergeDependencyManagementSections( ModelBase dominant, ModelBase recessive )
- {
- DependencyManagement recessiveDepMgmt = recessive.getDependencyManagement();
-
- DependencyManagement dominantDepMgmt = dominant.getDependencyManagement();
-
- if ( recessiveDepMgmt != null )
- {
- if ( dominantDepMgmt == null )
- {
- dominant.setDependencyManagement( recessiveDepMgmt );
- }
- else
- {
- List dominantDeps = dominantDepMgmt.getDependencies();
-
- Map mappedDominantDeps = new TreeMap();
- for ( Iterator it = dominantDeps.iterator(); it.hasNext(); )
- {
- Dependency dep = (Dependency) it.next();
- mappedDominantDeps.put( dep.getManagementKey(), dep );
- }
-
- for ( Iterator it = recessiveDepMgmt.getDependencies().iterator(); it.hasNext(); )
- {
- Dependency dep = (Dependency) it.next();
- if ( !mappedDominantDeps.containsKey( dep.getManagementKey() ) )
- {
- dominantDepMgmt.addDependency( dep );
- }
- }
- }
- }
- }
-
- public static void mergeReportPlugins( ReportPlugin dominant, ReportPlugin recessive )
- {
- if ( StringUtils.isEmpty( dominant.getVersion() ) )
- {
- dominant.setVersion( recessive.getVersion() );
- }
-
- Xpp3Dom dominantConfig = (Xpp3Dom) dominant.getConfiguration();
- Xpp3Dom recessiveConfig = (Xpp3Dom) recessive.getConfiguration();
-
- dominant.setConfiguration( Xpp3Dom.mergeXpp3Dom( dominantConfig, recessiveConfig ) );
-
- Map mergedReportSets = new HashMap();
-
- Map dominantReportSetsById = dominant.getReportSetsAsMap();
-
- for ( Iterator it = recessive.getReportSets().iterator(); it.hasNext(); )
- {
- ReportSet recessiveReportSet = (ReportSet) it.next();
-
- String inherited = recessiveReportSet.getInherited();
-
- if ( StringUtils.isEmpty( inherited ) || Boolean.valueOf( inherited ).booleanValue() )
- {
- ReportSet dominantReportSet = (ReportSet) dominantReportSetsById.get( recessiveReportSet.getId() );
-
- ReportSet merged = recessiveReportSet;
-
- if ( dominantReportSet != null )
- {
- merged = dominantReportSet;
-
- Xpp3Dom recessiveRSConfig = (Xpp3Dom) recessiveReportSet.getConfiguration();
- Xpp3Dom mergedRSConfig = (Xpp3Dom) merged.getConfiguration();
-
- merged.setConfiguration( Xpp3Dom.mergeXpp3Dom( mergedRSConfig, recessiveRSConfig ) );
-
- List mergedReports = merged.getReports();
-
- if ( mergedReports == null )
- {
- mergedReports = new ArrayList();
-
- merged.setReports( mergedReports );
- }
-
- List recessiveRSReports = recessiveReportSet.getReports();
-
- if ( recessiveRSReports != null )
- {
- for ( Iterator reportIterator = recessiveRSReports.iterator(); reportIterator.hasNext(); )
- {
- String report = (String) reportIterator.next();
-
- if ( !mergedReports.contains( report ) )
- {
- mergedReports.add( report );
- }
- }
- }
- }
- else if ( StringUtils.isEmpty( inherited ) )
- {
- merged.unsetInheritanceApplied();
- }
-
- mergedReportSets.put( merged.getId(), merged );
- }
- }
-
- for ( Iterator rsIterator = dominantReportSetsById.entrySet().iterator(); rsIterator.hasNext(); )
- {
- Map.Entry entry = (Map.Entry) rsIterator.next();
-
- String key = (String) entry.getKey();
-
- if ( !mergedReportSets.containsKey( key ) )
- {
- mergedReportSets.put( key, entry.getValue() );
- }
- }
-
- dominant.setReportSets( new ArrayList( mergedReportSets.values() ) );
-
- dominant.flushReportSetMap();
- }
-
- public static void mergeBuildBases( BuildBase dominant, BuildBase recessive )
- {
- // NOTE: This assumes that the dominant build is not null.
- //If it is null, the action taken should have been external to this method.
-
- // if the parent build is null, obviously we cannot inherit from it...
- if ( recessive != null )
- {
- if ( dominant.getDirectory() == null )
- {
- dominant.setDirectory( recessive.getDirectory() );
- }
-
- if ( dominant.getDefaultGoal() == null )
- {
- dominant.setDefaultGoal( recessive.getDefaultGoal() );
- }
-
- if ( dominant.getFinalName() == null )
- {
- dominant.setFinalName( recessive.getFinalName() );
- }
-
- List resources = dominant.getResources();
- if ( resources == null || resources.isEmpty() )
- {
- dominant.setResources( recessive.getResources() );
- }
-
- resources = dominant.getTestResources();
- if ( resources == null || resources.isEmpty() )
- {
- dominant.setTestResources( recessive.getTestResources() );
- }
-
- // Plugins are aggregated if Plugin.inherit != false
- ModelUtils.mergePluginLists( dominant, recessive, true );
-
- // Plugin management :: aggregate
- PluginManagement dominantPM = dominant.getPluginManagement();
- PluginManagement recessivePM = recessive.getPluginManagement();
-
- if ( dominantPM == null && recessivePM != null )
- {
- dominant.setPluginManagement( recessivePM );
- }
- else
- {
- ModelUtils.mergePluginLists( dominant.getPluginManagement(), recessive.getPluginManagement(),
- false );
- }
- }
- }
-
- static Model cloneModel( Model model )
- {
- // TODO: would be nice for the modello:java code to generate this as a copy constructor
- Model newModel = new Model();
- ModelInheritanceAssembler assembler = new DefaultModelInheritanceAssembler();
- assembler.assembleModelInheritance( newModel, model );
- newModel.setVersion( model.getVersion() );
- newModel.setArtifactId( model.getArtifactId() );
- return newModel;
- }
-
- public static void overrideModelBase( Model target, ModelBase overrides )
- {
- target.setDependencies( overrides.getDependencies() );
- target.setDependencyManagement( overrides.getDependencyManagement() );
- target.setDistributionManagement( overrides.getDistributionManagement() );
- target.setModules( overrides.getModules() );
- target.setPluginRepositories( overrides.getPluginRepositories() );
- target.setReporting( overrides.getReporting() );
- target.setRepositories( overrides.getRepositories() );
- }
-
- public static void overrideBuildBase( Build target, BuildBase overrides )
- {
- target.setDefaultGoal( overrides.getDefaultGoal() );
- target.setFinalName( overrides.getFinalName() );
- target.setPluginManagement( overrides.getPluginManagement() );
-
- target.setPlugins( overrides.getPlugins() );
- target.flushPluginMap();
-
- target.setResources( overrides.getResources() );
- target.setTestResources( overrides.getTestResources() );
}
}
Modified: maven/components/trunk/maven-project/src/main/java/org/apache/maven/project/inheritance/DefaultModelInheritanceAssembler.java
URL: http://svn.apache.org/viewcvs/maven/components/trunk/maven-project/src/main/java/org/apache/maven/project/inheritance/DefaultModelInheritanceAssembler.java?rev=239918&r1=239917&r2=239918&view=diff
==============================================================================
--- maven/components/trunk/maven-project/src/main/java/org/apache/maven/project/inheritance/DefaultModelInheritanceAssembler.java (original)
+++ maven/components/trunk/maven-project/src/main/java/org/apache/maven/project/inheritance/DefaultModelInheritanceAssembler.java Wed Aug 24 13:31:29 2005
@@ -17,16 +17,28 @@
*/
import org.apache.maven.model.Build;
+import org.apache.maven.model.Dependency;
+import org.apache.maven.model.DependencyManagement;
import org.apache.maven.model.DistributionManagement;
import org.apache.maven.model.Extension;
import org.apache.maven.model.Model;
+import org.apache.maven.model.PluginManagement;
+import org.apache.maven.model.ReportPlugin;
+import org.apache.maven.model.ReportSet;
+import org.apache.maven.model.Reporting;
import org.apache.maven.model.Repository;
import org.apache.maven.model.Scm;
import org.apache.maven.model.Site;
import org.apache.maven.project.ModelUtils;
import org.codehaus.plexus.util.StringUtils;
+import org.codehaus.plexus.util.xml.Xpp3Dom;
+import java.util.ArrayList;
+import java.util.HashMap;
import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+import java.util.TreeMap;
/**
* @author <a href="mailto:jason@maven.org">Jason van Zyl </a>
@@ -141,8 +153,276 @@
// Build
assembleBuildInheritance( child, parent.getBuild() );
+
+ assembleDependencyInheritance( child, parent );
- ModelUtils.mergeModelBases( child, parent, false );
+ child.setRepositories( ModelUtils.mergeRepositoryLists( child.getRepositories(), parent.getRepositories() ) );
+ child.setPluginRepositories( ModelUtils.mergeRepositoryLists( child.getPluginRepositories(), parent.getPluginRepositories() ) );
+
+ assembleReportingInheritance( child, parent );
+
+ assembleDependencyManagementInheritance( child, parent );
+
+ assembleDistributionManagementInheritance( child, parent );
+ }
+
+ private void assembleDistributionManagementInheritance( Model child, Model parent )
+ {
+ DistributionManagement cDistMgmt = child.getDistributionManagement();
+ DistributionManagement pDistMgmt = parent.getDistributionManagement();
+
+ if ( cDistMgmt == null )
+ {
+ child.setDistributionManagement( pDistMgmt );
+ }
+ else if ( pDistMgmt != null )
+ {
+ if ( cDistMgmt.getRepository() == null )
+ {
+ cDistMgmt.setRepository( pDistMgmt.getRepository() );
+ }
+
+ if ( cDistMgmt.getSnapshotRepository() == null )
+ {
+ cDistMgmt.setSnapshotRepository( pDistMgmt.getSnapshotRepository() );
+ }
+
+ if ( StringUtils.isEmpty( cDistMgmt.getDownloadUrl() ) )
+ {
+ cDistMgmt.setDownloadUrl( pDistMgmt.getDownloadUrl() );
+ }
+
+ if ( cDistMgmt.getRelocation() == null )
+ {
+ cDistMgmt.setRelocation( pDistMgmt.getRelocation() );
+ }
+
+ if ( cDistMgmt.getSite() == null )
+ {
+ cDistMgmt.setSite( pDistMgmt.getSite() );
+ }
+
+ // NOTE: We SHOULD NOT be inheriting status, since this is an assessment of the POM quality.
+ }
+ }
+
+ private void assembleDependencyManagementInheritance( Model child, Model parent )
+ {
+ DependencyManagement parentDepMgmt = parent.getDependencyManagement();
+
+ DependencyManagement childDepMgmt = child.getDependencyManagement();
+
+ if ( parentDepMgmt != null )
+ {
+ if ( childDepMgmt == null )
+ {
+ child.setDependencyManagement( parentDepMgmt );
+ }
+ else
+ {
+ List childDeps = childDepMgmt.getDependencies();
+
+ Map mappedChildDeps = new TreeMap();
+ for ( Iterator it = childDeps.iterator(); it.hasNext(); )
+ {
+ Dependency dep = (Dependency) it.next();
+ mappedChildDeps.put( dep.getManagementKey(), dep );
+ }
+
+ for ( Iterator it = parentDepMgmt.getDependencies().iterator(); it.hasNext(); )
+ {
+ Dependency dep = (Dependency) it.next();
+ if ( !mappedChildDeps.containsKey( dep.getManagementKey() ) )
+ {
+ childDepMgmt.addDependency( dep );
+ }
+ }
+ }
+ }
+ }
+
+ private void assembleReportingInheritance( Model child, Model parent )
+ {
+ // Reports :: aggregate
+ Reporting childReporting = child.getReporting();
+ Reporting parentReporting = parent.getReporting();
+
+ if ( childReporting != null && parentReporting != null )
+ {
+ if ( StringUtils.isEmpty( childReporting.getOutputDirectory() ) )
+ {
+ childReporting.setOutputDirectory( parentReporting.getOutputDirectory() );
+ }
+
+ Map mergedReportPlugins = new HashMap();
+
+ Map childReportersByKey = childReporting.getReportPluginsAsMap();
+
+ List parentReportPlugins = parentReporting.getPlugins();
+
+ if ( parentReportPlugins != null )
+ {
+ for ( Iterator it = parentReportPlugins.iterator(); it.hasNext(); )
+ {
+ ReportPlugin parentReportPlugin = (ReportPlugin) it.next();
+
+ String inherited = parentReportPlugin.getInherited();
+
+ if ( StringUtils.isEmpty( inherited ) || Boolean.valueOf( inherited ).booleanValue() )
+ {
+ ReportPlugin childReportPlugin = (ReportPlugin) childReportersByKey.get(
+ parentReportPlugin.getKey() );
+
+ ReportPlugin mergedReportPlugin = parentReportPlugin;
+
+ if ( childReportPlugin != null )
+ {
+ mergedReportPlugin = childReportPlugin;
+
+ mergeReportPlugins( childReportPlugin, parentReportPlugin );
+ }
+ else if ( StringUtils.isEmpty( inherited ) )
+ {
+ mergedReportPlugin.unsetInheritanceApplied();
+ }
+
+ mergedReportPlugins.put( mergedReportPlugin.getKey(), mergedReportPlugin );
+ }
+ }
+ }
+
+ for ( Iterator it = childReportersByKey.entrySet().iterator(); it.hasNext(); )
+ {
+ Map.Entry entry = (Map.Entry) it.next();
+
+ String key = (String) entry.getKey();
+
+ if ( !mergedReportPlugins.containsKey( key ) )
+ {
+ mergedReportPlugins.put( key, entry.getValue() );
+ }
+ }
+
+ childReporting.setPlugins( new ArrayList( mergedReportPlugins.values() ) );
+
+ childReporting.flushReportPluginMap();
+ }
+ }
+
+ private void mergeReportPlugins( ReportPlugin childReportPlugin, ReportPlugin parentReportPlugin )
+ {
+ if ( StringUtils.isEmpty( childReportPlugin.getVersion() ) )
+ {
+ childReportPlugin.setVersion( parentReportPlugin.getVersion() );
+ }
+
+ Xpp3Dom childConfig = (Xpp3Dom) childReportPlugin.getConfiguration();
+ Xpp3Dom parentConfig = (Xpp3Dom) parentReportPlugin.getConfiguration();
+
+ childReportPlugin.setConfiguration( Xpp3Dom.mergeXpp3Dom( childConfig, parentConfig ) );
+
+ Map mergedReportSets = new HashMap();
+
+ Map childReportSetsById = childReportPlugin.getReportSetsAsMap();
+
+ for ( Iterator it = parentReportPlugin.getReportSets().iterator(); it.hasNext(); )
+ {
+ ReportSet parentReportSet = (ReportSet) it.next();
+
+ String inherited = parentReportSet.getInherited();
+
+ if ( StringUtils.isEmpty( inherited ) || Boolean.valueOf( inherited ).booleanValue() )
+ {
+ ReportSet childReportSet = (ReportSet) childReportSetsById.get( parentReportSet.getId() );
+
+ ReportSet merged = parentReportSet;
+
+ if ( childReportSet != null )
+ {
+ merged = childReportSet;
+
+ Xpp3Dom parentRSConfig = (Xpp3Dom) parentReportSet.getConfiguration();
+ Xpp3Dom mergedRSConfig = (Xpp3Dom) merged.getConfiguration();
+
+ merged.setConfiguration( Xpp3Dom.mergeXpp3Dom( mergedRSConfig, parentRSConfig ) );
+
+ List mergedReports = merged.getReports();
+
+ if ( mergedReports == null )
+ {
+ mergedReports = new ArrayList();
+
+ merged.setReports( mergedReports );
+ }
+
+ List parentRSReports = parentReportSet.getReports();
+
+ if ( parentRSReports != null )
+ {
+ for ( Iterator reportIterator = parentRSReports.iterator(); reportIterator.hasNext(); )
+ {
+ String report = (String) reportIterator.next();
+
+ if ( !mergedReports.contains( report ) )
+ {
+ mergedReports.add( report );
+ }
+ }
+ }
+ }
+ else if ( StringUtils.isEmpty( inherited ) )
+ {
+ merged.unsetInheritanceApplied();
+ }
+
+ mergedReportSets.put( merged.getId(), merged );
+ }
+ }
+
+ for ( Iterator rsIterator = childReportSetsById.entrySet().iterator(); rsIterator.hasNext(); )
+ {
+ Map.Entry entry = (Map.Entry) rsIterator.next();
+
+ String key = (String) entry.getKey();
+
+ if ( !mergedReportSets.containsKey( key ) )
+ {
+ mergedReportSets.put( key, entry.getValue() );
+ }
+ }
+
+ childReportPlugin.setReportSets( new ArrayList( mergedReportSets.values() ) );
+
+ childReportPlugin.flushReportSetMap();
+ }
+
+ private void assembleDependencyInheritance( Model child, Model parent )
+ {
+ Map depsMap = new HashMap();
+
+ List deps = parent.getDependencies();
+
+ if ( deps != null )
+ {
+ for ( Iterator it = deps.iterator(); it.hasNext(); )
+ {
+ Dependency dependency = (Dependency) it.next();
+ depsMap.put( dependency.getManagementKey(), dependency );
+ }
+ }
+
+ deps = child.getDependencies();
+
+ if ( deps != null )
+ {
+ for ( Iterator it = deps.iterator(); it.hasNext(); )
+ {
+ Dependency dependency = (Dependency) it.next();
+ depsMap.put( dependency.getManagementKey(), dependency );
+ }
+ }
+
+ child.setDependencies( new ArrayList( depsMap.values() ) );
}
private void assembleBuildInheritance( Model child, Build parentBuild )
@@ -188,7 +468,49 @@
// Extensions are accumlated
mergeExtensionLists( childBuild, parentBuild );
- ModelUtils.mergeBuildBases( childBuild, parentBuild );
+ if ( childBuild.getDirectory() == null )
+ {
+ childBuild.setDirectory( parentBuild.getDirectory() );
+ }
+
+ if ( childBuild.getDefaultGoal() == null )
+ {
+ childBuild.setDefaultGoal( parentBuild.getDefaultGoal() );
+ }
+
+ if ( childBuild.getFinalName() == null )
+ {
+ childBuild.setFinalName( parentBuild.getFinalName() );
+ }
+
+ List resources = childBuild.getResources();
+ if ( resources == null || resources.isEmpty() )
+ {
+ childBuild.setResources( parentBuild.getResources() );
+ }
+
+ resources = childBuild.getTestResources();
+ if ( resources == null || resources.isEmpty() )
+ {
+ childBuild.setTestResources( parentBuild.getTestResources() );
+ }
+
+ // Plugins are aggregated if Plugin.inherit != false
+ ModelUtils.mergePluginLists( childBuild, parentBuild, true );
+
+ // Plugin management :: aggregate
+ PluginManagement dominantPM = childBuild.getPluginManagement();
+ PluginManagement recessivePM = parentBuild.getPluginManagement();
+
+ if ( dominantPM == null && recessivePM != null )
+ {
+ childBuild.setPluginManagement( recessivePM );
+ }
+ else
+ {
+ ModelUtils.mergePluginLists( childBuild.getPluginManagement(), parentBuild.getPluginManagement(),
+ false );
+ }
}
}
@@ -297,7 +619,7 @@
}
}
- private static String appendPath( String url, String path )
+ private String appendPath( String url, String path )
{
if ( url.endsWith( "/" ) )
{
@@ -309,7 +631,7 @@
}
}
- private static void mergeExtensionLists( Build childBuild, Build parentBuild )
+ private void mergeExtensionLists( Build childBuild, Build parentBuild )
{
for ( Iterator i = parentBuild.getExtensions().iterator(); i.hasNext(); )
{
Modified: maven/components/trunk/maven-project/src/main/java/org/apache/maven/project/injection/DefaultProfileInjector.java
URL: http://svn.apache.org/viewcvs/maven/components/trunk/maven-project/src/main/java/org/apache/maven/project/injection/DefaultProfileInjector.java?rev=239918&r1=239917&r2=239918&view=diff
==============================================================================
--- maven/components/trunk/maven-project/src/main/java/org/apache/maven/project/injection/DefaultProfileInjector.java (original)
+++ maven/components/trunk/maven-project/src/main/java/org/apache/maven/project/injection/DefaultProfileInjector.java Wed Aug 24 13:31:29 2005
@@ -2,32 +2,575 @@
import org.apache.maven.model.Build;
import org.apache.maven.model.BuildBase;
+import org.apache.maven.model.ConfigurationContainer;
+import org.apache.maven.model.Dependency;
+import org.apache.maven.model.DependencyManagement;
+import org.apache.maven.model.DistributionManagement;
import org.apache.maven.model.Model;
+import org.apache.maven.model.Plugin;
+import org.apache.maven.model.PluginContainer;
+import org.apache.maven.model.PluginExecution;
+import org.apache.maven.model.PluginManagement;
import org.apache.maven.model.Profile;
+import org.apache.maven.model.ReportPlugin;
+import org.apache.maven.model.ReportSet;
+import org.apache.maven.model.Reporting;
import org.apache.maven.project.ModelUtils;
+import org.codehaus.plexus.util.StringUtils;
+import org.codehaus.plexus.util.xml.Xpp3Dom;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+import java.util.TreeMap;
+
+/**
+ * Inject profile data into a Model, using the profile as the dominant data source, and
+ * persisting results of the injection in the Model.
+ *
+ * This will look similar to the ModelUtils/DefaultModelInheritanceAssembler code, but
+ * they are distinct. In model inheritance, the child provides data dominance AND persists
+ * the results of the merge...sort of a 'merge-out' system.
+ *
+ * In this system, the profile is dominant, but the model receives the merge result...sort
+ * of a 'merge-in' system. The two pieces of code look like they could be combined with a
+ * set of flags to determine which direction to merge 'to', but there are enough differences
+ * in the code to justify the extra code involved with separating them, in order to simplify
+ * the logic.
+ */
public class DefaultProfileInjector
implements ProfileInjector
{
public void inject( Profile profile, Model model )
{
- // [jc 11-aug-2005] NOTE: the following merge-then-override procedure is used to preserve proper dominance
- // (profile wins), while ensuring that any changes are pushed to the model.
- ModelUtils.mergeModelBases( profile, model, true );
-
- ModelUtils.overrideModelBase( model, profile );
+ injectDependencies( profile, model );
+
+ injectModules( profile, model );
+
+ model.setRepositories( ModelUtils.mergeRepositoryLists( profile.getRepositories(), model.getRepositories() ) );
+ model.setPluginRepositories( ModelUtils.mergeRepositoryLists( profile.getPluginRepositories(), model
+ .getPluginRepositories() ) );
+
+ injectReporting( profile, model );
+
+ injectDependencyManagement( profile, model );
+
+ injectDistributionManagement( profile, model );
+ injectBuild( profile, model );
+ }
+
+ private void injectBuild( Profile profile, Model model )
+ {
BuildBase profileBuild = profile.getBuild();
+ Build modelBuild = model.getBuild();
+ // if the parent build is null, obviously we cannot inherit from it...
if ( profileBuild != null )
{
- ModelUtils.mergeBuildBases( profile.getBuild(), model.getBuild() );
+ if ( modelBuild == null )
+ {
+ modelBuild = new Build();
+ model.setBuild( modelBuild );
+ }
- Build modelBuild = model.getBuild();
+ if ( profileBuild.getDirectory() != null )
+ {
+ modelBuild.setDirectory( profileBuild.getDirectory() );
+ }
+
+ if ( profileBuild.getDefaultGoal() != null )
+ {
+ modelBuild.setDefaultGoal( profileBuild.getDefaultGoal() );
+ }
+
+ if ( profileBuild.getFinalName() != null )
+ {
+ modelBuild.setFinalName( profileBuild.getFinalName() );
+ }
+
+ List profileResources = profileBuild.getResources();
+
+ if ( profileResources != null )
+ {
+ modelBuild.setResources( profileResources );
+ }
+
+ List profileTestResources = profileBuild.getTestResources();
- ModelUtils.overrideBuildBase( modelBuild, profileBuild );
+ if ( profileTestResources != null )
+ {
+ modelBuild.setTestResources( profileTestResources );
+ }
+
+ injectPlugins( profileBuild, modelBuild );
+
+ // Plugin management :: aggregate
+ PluginManagement profilePM = profileBuild.getPluginManagement();
+ PluginManagement modelPM = modelBuild.getPluginManagement();
+
+ if ( modelPM == null )
+ {
+ modelBuild.setPluginManagement( profilePM );
+ }
+ else
+ {
+ injectPlugins( profilePM, modelPM );
+ }
+ }
+ }
+
+ private void injectPlugins( PluginContainer profileContainer, PluginContainer modelContainer )
+ {
+ List modelPlugins = modelContainer.getPlugins();
+
+ if ( modelPlugins == null )
+ {
+ modelContainer.setPlugins( profileContainer.getPlugins() );
+ }
+ else if ( profileContainer.getPlugins() != null )
+ {
+ Map mergedPlugins = new TreeMap();
+
+ Map profilePlugins = profileContainer.getPluginsAsMap();
+
+ for ( Iterator it = modelPlugins.iterator(); it.hasNext(); )
+ {
+ Plugin modelPlugin = (Plugin) it.next();
+
+ Plugin mergedPlugin = modelPlugin;
+
+ Plugin profilePlugin = (Plugin) profilePlugins.get( modelPlugin.getKey() );
+
+ if ( profilePlugin != null )
+ {
+ mergedPlugin = profilePlugin;
+
+ injectPluginDefinition( profilePlugin, modelPlugin );
+ }
+
+ mergedPlugins.put( mergedPlugin.getKey(), mergedPlugin );
+ }
+
+ for ( Iterator it = profilePlugins.values().iterator(); it.hasNext(); )
+ {
+ Plugin profilePlugin = (Plugin) it.next();
+
+ if ( !mergedPlugins.containsKey( profilePlugin.getKey() ) )
+ {
+ mergedPlugins.put( profilePlugin.getKey(), profilePlugin );
+ }
+ }
+
+ modelContainer.setPlugins( new ArrayList( mergedPlugins.values() ) );
+
+ modelContainer.flushPluginMap();
+ }
+ }
+
+ private void injectPluginDefinition( Plugin profilePlugin, Plugin modelPlugin )
+ {
+ if ( profilePlugin == null || modelPlugin == null )
+ {
+ // nothing to do.
+ return;
+ }
+
+ if ( profilePlugin.isExtensions() )
+ {
+ modelPlugin.setExtensions( true );
+ }
+
+ if ( profilePlugin.getVersion() != null )
+ {
+ modelPlugin.setVersion( profilePlugin.getVersion() );
+ }
+
+ // merge the lists of goals that are not attached to an <execution/>
+ injectConfigurationContainer( profilePlugin, modelPlugin );
+
+ // from here to the end of the method is dealing with merging of the <executions/> section.
+ List modelExecutions = modelPlugin.getExecutions();
+
+ if ( modelExecutions == null || modelExecutions.isEmpty() )
+ {
+ modelPlugin.setExecutions( profilePlugin.getExecutions() );
+ }
+ else
+ {
+ Map executions = new TreeMap();
+
+ Map profileExecutions = profilePlugin.getExecutionsAsMap();
+
+ for ( Iterator it = modelExecutions.iterator(); it.hasNext(); )
+ {
+ PluginExecution modelExecution = (PluginExecution) it.next();
+
+ PluginExecution profileExecution = (PluginExecution) profileExecutions.get( modelExecution.getId() );
+
+ if ( profileExecution != null )
+ {
+ injectConfigurationContainer( profileExecution, modelExecution );
+
+ if ( profileExecution.getPhase() != null )
+ {
+ modelExecution.setPhase( profileExecution.getPhase() );
+ }
+
+ List profileGoals = profileExecution.getGoals();
+ List modelGoals = modelExecution.getGoals();
+
+ List goals = new ArrayList();
+
+ if ( modelGoals != null && !modelGoals.isEmpty() )
+ {
+ goals.addAll( modelGoals );
+ }
+
+ if ( profileGoals != null )
+ {
+ for ( Iterator goalIterator = profileGoals.iterator(); goalIterator.hasNext(); )
+ {
+ String goal = (String) goalIterator.next();
+
+ if ( !goals.contains( goal ) )
+ {
+ goals.add( goal );
+ }
+ }
+ }
+
+ modelExecution.setGoals( goals );
+ }
+
+ executions.put( modelExecution.getId(), modelExecution );
+ }
+
+ for ( Iterator it = profileExecutions.entrySet().iterator(); it.hasNext(); )
+ {
+ Map.Entry entry = (Map.Entry) it.next();
+
+ String id = (String) entry.getKey();
+
+ if ( !executions.containsKey( id ) )
+ {
+ executions.put( id, entry.getValue() );
+ }
+ }
+
+ modelPlugin.setExecutions( new ArrayList( executions.values() ) );
+
+ modelPlugin.flushExecutionMap();
}
+
+ }
+
+ private void injectConfigurationContainer( ConfigurationContainer profileContainer,
+ ConfigurationContainer modelContainer )
+ {
+ Xpp3Dom configuration = (Xpp3Dom) profileContainer.getConfiguration();
+ Xpp3Dom parentConfiguration = (Xpp3Dom) modelContainer.getConfiguration();
+
+ configuration = Xpp3Dom.mergeXpp3Dom( configuration, parentConfiguration );
+
+ modelContainer.setConfiguration( configuration );
+ }
+
+ private void injectModules( Profile profile, Model model )
+ {
+ List modules = new ArrayList();
+
+ List profileModules = profile.getModules();
+
+ if ( profileModules != null && !profileModules.isEmpty() )
+ {
+ modules.addAll( profileModules );
+ }
+
+ List modelModules = model.getModules();
+
+ if ( modelModules != null )
+ {
+ for ( Iterator it = modelModules.iterator(); it.hasNext(); )
+ {
+ String module = (String) it.next();
+
+ if ( !modules.contains( module ) )
+ {
+ modules.add( module );
+ }
+ }
+ }
+
+ model.setModules( modules );
+ }
+
+ private void injectDistributionManagement( Profile profile, Model model )
+ {
+ DistributionManagement pDistMgmt = profile.getDistributionManagement();
+ DistributionManagement mDistMgmt = model.getDistributionManagement();
+
+ if ( mDistMgmt == null )
+ {
+ model.setDistributionManagement( pDistMgmt );
+ }
+ else if ( pDistMgmt != null )
+ {
+ if ( pDistMgmt.getRepository() != null )
+ {
+ mDistMgmt.setRepository( pDistMgmt.getRepository() );
+ }
+
+ if ( pDistMgmt.getSnapshotRepository() != null )
+ {
+ mDistMgmt.setSnapshotRepository( pDistMgmt.getSnapshotRepository() );
+ }
+
+ if ( StringUtils.isNotEmpty( pDistMgmt.getDownloadUrl() ) )
+ {
+ mDistMgmt.setDownloadUrl( pDistMgmt.getDownloadUrl() );
+ }
+
+ if ( pDistMgmt.getRelocation() != null )
+ {
+ mDistMgmt.setRelocation( pDistMgmt.getRelocation() );
+ }
+
+ if ( pDistMgmt.getSite() != null )
+ {
+ mDistMgmt.setSite( pDistMgmt.getSite() );
+ }
+
+ // NOTE: We SHOULD NOT be inheriting status, since this is an assessment of the POM quality.
+ }
+ }
+
+ private void injectDependencyManagement( Profile profile, Model model )
+ {
+ DependencyManagement modelDepMgmt = model.getDependencyManagement();
+
+ DependencyManagement profileDepMgmt = profile.getDependencyManagement();
+
+ if ( profileDepMgmt != null )
+ {
+ if ( modelDepMgmt == null )
+ {
+ model.setDependencyManagement( profileDepMgmt );
+ }
+ else
+ {
+ Map depsMap = new HashMap();
+
+ List deps = modelDepMgmt.getDependencies();
+
+ if ( deps != null )
+ {
+ for ( Iterator it = deps.iterator(); it.hasNext(); )
+ {
+ Dependency dependency = (Dependency) it.next();
+ depsMap.put( dependency.getManagementKey(), dependency );
+ }
+ }
+
+ deps = profileDepMgmt.getDependencies();
+
+ if ( deps != null )
+ {
+ for ( Iterator it = deps.iterator(); it.hasNext(); )
+ {
+ Dependency dependency = (Dependency) it.next();
+ depsMap.put( dependency.getManagementKey(), dependency );
+ }
+ }
+
+ modelDepMgmt.setDependencies( new ArrayList( depsMap.values() ) );
+ }
+ }
+ }
+
+ private void injectReporting( Profile profile, Model model )
+ {
+ // Reports :: aggregate
+ Reporting profileReporting = profile.getReporting();
+ Reporting modelReporting = model.getReporting();
+
+ if ( profileReporting != null )
+ {
+ if ( modelReporting == null )
+ {
+ model.setReporting( profileReporting );
+ }
+ else
+ {
+ if ( StringUtils.isEmpty( modelReporting.getOutputDirectory() ) )
+ {
+ modelReporting.setOutputDirectory( profileReporting.getOutputDirectory() );
+ }
+
+ Map mergedReportPlugins = new HashMap();
+
+ Map profileReportersByKey = profileReporting.getReportPluginsAsMap();
+
+ List modelReportPlugins = modelReporting.getPlugins();
+
+ if ( modelReportPlugins != null )
+ {
+ for ( Iterator it = modelReportPlugins.iterator(); it.hasNext(); )
+ {
+ ReportPlugin modelReportPlugin = (ReportPlugin) it.next();
+
+ String inherited = modelReportPlugin.getInherited();
+
+ if ( StringUtils.isEmpty( inherited ) || Boolean.valueOf( inherited ).booleanValue() )
+ {
+ ReportPlugin profileReportPlugin = (ReportPlugin) profileReportersByKey
+ .get( modelReportPlugin.getKey() );
+
+ ReportPlugin mergedReportPlugin = modelReportPlugin;
+
+ if ( profileReportPlugin != null )
+ {
+ mergedReportPlugin = profileReportPlugin;
+
+ mergeReportPlugins( profileReportPlugin, modelReportPlugin );
+ }
+ else if ( StringUtils.isEmpty( inherited ) )
+ {
+ mergedReportPlugin.unsetInheritanceApplied();
+ }
+
+ mergedReportPlugins.put( mergedReportPlugin.getKey(), mergedReportPlugin );
+ }
+ }
+ }
+
+ for ( Iterator it = profileReportersByKey.entrySet().iterator(); it.hasNext(); )
+ {
+ Map.Entry entry = (Map.Entry) it.next();
+
+ String key = (String) entry.getKey();
+
+ if ( !mergedReportPlugins.containsKey( key ) )
+ {
+ mergedReportPlugins.put( key, entry.getValue() );
+ }
+ }
+
+ profileReporting.setPlugins( new ArrayList( mergedReportPlugins.values() ) );
+
+ profileReporting.flushReportPluginMap();
+ }
+ }
+ }
+
+ private void mergeReportPlugins( ReportPlugin dominant, ReportPlugin recessive )
+ {
+ if ( StringUtils.isEmpty( recessive.getVersion() ) )
+ {
+ recessive.setVersion( dominant.getVersion() );
+ }
+
+ Xpp3Dom dominantConfig = (Xpp3Dom) dominant.getConfiguration();
+ Xpp3Dom recessiveConfig = (Xpp3Dom) recessive.getConfiguration();
+
+ recessive.setConfiguration( Xpp3Dom.mergeXpp3Dom( dominantConfig, recessiveConfig ) );
+
+ Map mergedReportSets = new HashMap();
+
+ Map dominantReportSetsById = dominant.getReportSetsAsMap();
+
+ for ( Iterator it = recessive.getReportSets().iterator(); it.hasNext(); )
+ {
+ ReportSet recessiveReportSet = (ReportSet) it.next();
+
+ ReportSet dominantReportSet = (ReportSet) dominantReportSetsById.get( recessiveReportSet.getId() );
+
+ ReportSet merged = recessiveReportSet;
+
+ if ( dominantReportSet != null )
+ {
+ merged = recessiveReportSet;
+
+ Xpp3Dom dominantRSConfig = (Xpp3Dom) dominantReportSet.getConfiguration();
+ Xpp3Dom mergedRSConfig = (Xpp3Dom) merged.getConfiguration();
+
+ merged.setConfiguration( Xpp3Dom.mergeXpp3Dom( dominantRSConfig, mergedRSConfig ) );
+
+ List mergedReports = merged.getReports();
+
+ if ( mergedReports == null )
+ {
+ mergedReports = new ArrayList();
+
+ merged.setReports( mergedReports );
+ }
+
+ List dominantRSReports = dominantReportSet.getReports();
+
+ if ( dominantRSReports != null )
+ {
+ for ( Iterator reportIterator = dominantRSReports.iterator(); reportIterator.hasNext(); )
+ {
+ String report = (String) reportIterator.next();
+
+ if ( !mergedReports.contains( report ) )
+ {
+ mergedReports.add( report );
+ }
+ }
+ }
+
+ mergedReportSets.put( merged.getId(), merged );
+ }
+ }
+
+ for ( Iterator rsIterator = dominantReportSetsById.entrySet().iterator(); rsIterator.hasNext(); )
+ {
+ Map.Entry entry = (Map.Entry) rsIterator.next();
+
+ String key = (String) entry.getKey();
+
+ if ( !mergedReportSets.containsKey( key ) )
+ {
+ mergedReportSets.put( key, entry.getValue() );
+ }
+ }
+
+ recessive.setReportSets( new ArrayList( mergedReportSets.values() ) );
+
+ recessive.flushReportSetMap();
+ }
+
+ private void injectDependencies( Profile profile, Model model )
+ {
+ Map depsMap = new HashMap();
+
+ List deps = model.getDependencies();
+
+ if ( deps != null )
+ {
+ for ( Iterator it = deps.iterator(); it.hasNext(); )
+ {
+ Dependency dependency = (Dependency) it.next();
+ depsMap.put( dependency.getManagementKey(), dependency );
+ }
+ }
+
+ deps = profile.getDependencies();
+
+ if ( deps != null )
+ {
+ for ( Iterator it = deps.iterator(); it.hasNext(); )
+ {
+ Dependency dependency = (Dependency) it.next();
+ depsMap.put( dependency.getManagementKey(), dependency );
+ }
+ }
+
+ model.setDependencies( new ArrayList( depsMap.values() ) );
}
}
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@maven.apache.org
For additional commands, e-mail: dev-help@maven.apache.org