From 29878afcc69550795eecc210b7b1b82558a80e19 Mon Sep 17 00:00:00 2001 From: John Dennis Casey Date: Tue, 7 Jun 2005 22:36:44 +0000 Subject: [PATCH] o pom-level profiles are working now git-svn-id: https://svn.apache.org/repos/asf/maven/components/trunk@189464 13f79535-47bb-0310-9956-ffa450edef68 --- maven-core-it/README.txt | 3 + maven-core-it/integration-tests.txt | 1 + maven-core-it/it0021/expected-results.txt | 1 + maven-core-it/it0021/goals.txt | 1 + maven-core-it/it0021/pom.xml | 28 +++++ maven-core-it/it0021/prebuild-hook.txt | 1 + .../java/org/apache/maven/it0021/Person.java | 16 +++ maven-core-it/it0021/system.properties | 1 + maven-model/maven.mdo | 28 ++++- maven-profile/profiles.mdo | 28 ++++- .../activation/ActivationConstants.java | 28 +++++ .../ExplicitListingProfileActivator.java | 56 +++++++++ .../activation/JdkPrefixProfileActivator.java | 44 +++++++ .../ProfileActivationCalculator.java | 105 ++++++++++++++++ .../profile/activation/ProfileActivator.java | 30 +++++ .../SystemPropertyProfileActivator.java | 58 +++++++++ .../project/DefaultMavenProjectBuilder.java | 14 ++- .../DefaultModelInheritanceAssembler.java | 116 ++++++++++++------ .../ModelInheritanceAssembler.java | 3 + .../resources/META-INF/plexus/components.xml | 42 +++++++ maven-settings/settings.mdo | 28 ++++- 21 files changed, 591 insertions(+), 41 deletions(-) create mode 100644 maven-core-it/it0021/expected-results.txt create mode 100644 maven-core-it/it0021/goals.txt create mode 100644 maven-core-it/it0021/pom.xml create mode 100755 maven-core-it/it0021/prebuild-hook.txt create mode 100644 maven-core-it/it0021/src/main/java/org/apache/maven/it0021/Person.java create mode 100644 maven-core-it/it0021/system.properties create mode 100644 maven-project/src/main/java/org/apache/maven/profile/activation/ActivationConstants.java create mode 100644 maven-project/src/main/java/org/apache/maven/profile/activation/ExplicitListingProfileActivator.java create mode 100644 maven-project/src/main/java/org/apache/maven/profile/activation/JdkPrefixProfileActivator.java create mode 100644 maven-project/src/main/java/org/apache/maven/profile/activation/ProfileActivationCalculator.java create mode 100644 maven-project/src/main/java/org/apache/maven/profile/activation/ProfileActivator.java create mode 100644 maven-project/src/main/java/org/apache/maven/profile/activation/SystemPropertyProfileActivator.java diff --git a/maven-core-it/README.txt b/maven-core-it/README.txt index 24b58ceaa2..06eca6399d 100644 --- a/maven-core-it/README.txt +++ b/maven-core-it/README.txt @@ -67,6 +67,9 @@ it0019: Test that a version is managed by pluginManagement in the super POM it0020: Test beanshell mojo support. +it0021: Test pom-level profile inclusion (this one is activated by system + property). + ------------------------------------------------------------------------------- - generated sources diff --git a/maven-core-it/integration-tests.txt b/maven-core-it/integration-tests.txt index 104fff7543..eeb0d76974 100644 --- a/maven-core-it/integration-tests.txt +++ b/maven-core-it/integration-tests.txt @@ -19,3 +19,4 @@ it0017 it0018 it0019 it0020 +it0021 diff --git a/maven-core-it/it0021/expected-results.txt b/maven-core-it/it0021/expected-results.txt new file mode 100644 index 0000000000..eb29685b1f --- /dev/null +++ b/maven-core-it/it0021/expected-results.txt @@ -0,0 +1 @@ +${artifact:org.apache.maven:maven-core-it-support:1.0:jar} diff --git a/maven-core-it/it0021/goals.txt b/maven-core-it/it0021/goals.txt new file mode 100644 index 0000000000..f8808babbb --- /dev/null +++ b/maven-core-it/it0021/goals.txt @@ -0,0 +1 @@ +compile \ No newline at end of file diff --git a/maven-core-it/it0021/pom.xml b/maven-core-it/it0021/pom.xml new file mode 100644 index 0000000000..0eb61770ed --- /dev/null +++ b/maven-core-it/it0021/pom.xml @@ -0,0 +1,28 @@ + + 4.0.0 + org.apache.maven.plugins + maven-it0021-plugin + maven-plugin + 1.0-SNAPSHOT + + + + test-profile + + + + includeProfile + + + + + + org.apache.maven + maven-core-it-support + 1.0 + + + + + + \ No newline at end of file diff --git a/maven-core-it/it0021/prebuild-hook.txt b/maven-core-it/it0021/prebuild-hook.txt new file mode 100755 index 0000000000..513bc6161f --- /dev/null +++ b/maven-core-it/it0021/prebuild-hook.txt @@ -0,0 +1 @@ +rm ${artifact:org.apache.maven:maven-core-it-support:1.0:jar} diff --git a/maven-core-it/it0021/src/main/java/org/apache/maven/it0021/Person.java b/maven-core-it/it0021/src/main/java/org/apache/maven/it0021/Person.java new file mode 100644 index 0000000000..c16eaf1526 --- /dev/null +++ b/maven-core-it/it0021/src/main/java/org/apache/maven/it0021/Person.java @@ -0,0 +1,16 @@ +package org.apache.maven.it0021; + +public class Person +{ + private String name; + + public void setName( String name ) + { + this.name = name; + } + + public String getName() + { + return name; + } +} diff --git a/maven-core-it/it0021/system.properties b/maven-core-it/it0021/system.properties new file mode 100644 index 0000000000..c1a145a6c6 --- /dev/null +++ b/maven-core-it/it0021/system.properties @@ -0,0 +1 @@ +includeProfile=true diff --git a/maven-model/maven.mdo b/maven-model/maven.mdo index b7e8608cf9..8af8bce3c8 100644 --- a/maven-model/maven.mdo +++ b/maven-model/maven.mdo @@ -2342,10 +2342,36 @@ property 4.0.0 - String + + ActivationProperty + + + + + + ActivationProperty + 4.0.0 + + + + name + 4.0.0 + String + true + The name of the property to be used to activate a profile + + + value + 4.0.0 + String + The value of the property to be used to activate a profile diff --git a/maven-profile/profiles.mdo b/maven-profile/profiles.mdo index fdf93549cf..212757bc59 100644 --- a/maven-profile/profiles.mdo +++ b/maven-profile/profiles.mdo @@ -119,10 +119,12 @@ property 1.0.0 - String + + ActivationProperty + @@ -197,5 +199,29 @@ + + ActivationProperty + 1.0.0 + + + + name + 1.0.0 + String + true + The name of the property to be used to activate a profile + + + value + 1.0.0 + String + The value of the property to be used to activate a profile + + + \ No newline at end of file diff --git a/maven-project/src/main/java/org/apache/maven/profile/activation/ActivationConstants.java b/maven-project/src/main/java/org/apache/maven/profile/activation/ActivationConstants.java new file mode 100644 index 0000000000..d3211baf38 --- /dev/null +++ b/maven-project/src/main/java/org/apache/maven/profile/activation/ActivationConstants.java @@ -0,0 +1,28 @@ +package org.apache.maven.profile.activation; + +/* + * Copyright 2001-2005 The Apache Software Foundation. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +public final class ActivationConstants +{ + + public static final String ACTIVE_PROFILE_IDS = "org.apache.maven.ActiveProfileIds"; + + private ActivationConstants() + { + } + +} diff --git a/maven-project/src/main/java/org/apache/maven/profile/activation/ExplicitListingProfileActivator.java b/maven-project/src/main/java/org/apache/maven/profile/activation/ExplicitListingProfileActivator.java new file mode 100644 index 0000000000..b3ed42138c --- /dev/null +++ b/maven-project/src/main/java/org/apache/maven/profile/activation/ExplicitListingProfileActivator.java @@ -0,0 +1,56 @@ +package org.apache.maven.profile.activation; + +import org.apache.maven.model.Profile; + +import java.util.StringTokenizer; + +/* + * Copyright 2001-2005 The Apache Software Foundation. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +public class ExplicitListingProfileActivator + implements ProfileActivator +{ + + public boolean canDetermineActivation( Profile profile ) + { + return profile.getActivation() == null; + } + + public boolean isActive( Profile profile ) + { + String activeProfiles = System.getProperty( ActivationConstants.ACTIVE_PROFILE_IDS ); + + if ( activeProfiles != null ) + { + String profileId = profile.getId(); + + StringTokenizer profileTokens = new StringTokenizer( activeProfiles, "," ); + + while ( profileTokens.hasMoreTokens() ) + { + String currentToken = profileTokens.nextToken().trim(); + + if ( profileId.equals( currentToken ) ) + { + return true; + } + } + } + + return false; + } + +} diff --git a/maven-project/src/main/java/org/apache/maven/profile/activation/JdkPrefixProfileActivator.java b/maven-project/src/main/java/org/apache/maven/profile/activation/JdkPrefixProfileActivator.java new file mode 100644 index 0000000000..3968e055d1 --- /dev/null +++ b/maven-project/src/main/java/org/apache/maven/profile/activation/JdkPrefixProfileActivator.java @@ -0,0 +1,44 @@ +package org.apache.maven.profile.activation; + +import org.apache.maven.model.Activation; +import org.apache.maven.model.Profile; +import org.codehaus.plexus.util.StringUtils; + +/* + * Copyright 2001-2005 The Apache Software Foundation. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +public class JdkPrefixProfileActivator + implements ProfileActivator +{ + + private static final String JDK_VERSION = System.getProperty( "java.version" ); + + public boolean isActive( Profile profile ) + { + Activation activation = profile.getActivation(); + + String jdk = activation.getJdk(); + + // null case is covered by canDetermineActivation(), so we can do a straight startsWith() here. + return JDK_VERSION.startsWith( jdk ); + } + + public boolean canDetermineActivation( Profile profile ) + { + return profile.getActivation() != null && StringUtils.isNotEmpty( profile.getActivation().getJdk() ); + } + +} diff --git a/maven-project/src/main/java/org/apache/maven/profile/activation/ProfileActivationCalculator.java b/maven-project/src/main/java/org/apache/maven/profile/activation/ProfileActivationCalculator.java new file mode 100644 index 0000000000..4014bde1ca --- /dev/null +++ b/maven-project/src/main/java/org/apache/maven/profile/activation/ProfileActivationCalculator.java @@ -0,0 +1,105 @@ +package org.apache.maven.profile.activation; + +import org.apache.maven.model.Activation; +import org.apache.maven.model.Profile; +import org.apache.maven.project.ProjectBuildingException; +import org.codehaus.plexus.PlexusConstants; +import org.codehaus.plexus.PlexusContainer; +import org.codehaus.plexus.component.repository.exception.ComponentLifecycleException; +import org.codehaus.plexus.component.repository.exception.ComponentLookupException; +import org.codehaus.plexus.context.Context; +import org.codehaus.plexus.context.ContextException; +import org.codehaus.plexus.logging.AbstractLogEnabled; +import org.codehaus.plexus.personality.plexus.lifecycle.phase.Contextualizable; + +import java.util.ArrayList; +import java.util.Iterator; +import java.util.List; + +/* + * Copyright 2001-2005 The Apache Software Foundation. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +public class ProfileActivationCalculator + extends AbstractLogEnabled + implements Contextualizable +{ + + public static final String ROLE = ProfileActivationCalculator.class.getName(); + + private PlexusContainer container; + + public List calculateActiveProfiles( List profiles ) + throws ProjectBuildingException + { + List activators = null; + try + { + activators = container.lookupList( ProfileActivator.ROLE ); + + List active = new ArrayList( profiles.size() ); + + for ( Iterator it = profiles.iterator(); it.hasNext(); ) + { + Profile profile = (Profile) it.next(); + + boolean isActive = true; + + Activation activation = profile.getActivation(); + + activatorLoop: for ( Iterator activatorIterator = activators.iterator(); activatorIterator.hasNext(); ) + { + ProfileActivator activator = (ProfileActivator) activatorIterator.next(); + + if ( activator.canDetermineActivation( profile ) ) + { + if ( activator.isActive( profile ) ) + { + active.add( profile ); + } + else + { + break activatorLoop; + } + } + } + } + + return active; + } + catch ( ComponentLookupException e ) + { + throw new ProjectBuildingException( "Cannot retrieve list of profile activators.", e ); + } + finally + { + try + { + container.releaseAll( activators ); + } + catch ( ComponentLifecycleException e ) + { + getLogger().debug( "Error releasing profile activators - ignoring.", e ); + } + } + } + + public void contextualize( Context context ) + throws ContextException + { + this.container = (PlexusContainer) context.get( PlexusConstants.PLEXUS_KEY ); + } + +} diff --git a/maven-project/src/main/java/org/apache/maven/profile/activation/ProfileActivator.java b/maven-project/src/main/java/org/apache/maven/profile/activation/ProfileActivator.java new file mode 100644 index 0000000000..bc8b74161b --- /dev/null +++ b/maven-project/src/main/java/org/apache/maven/profile/activation/ProfileActivator.java @@ -0,0 +1,30 @@ +package org.apache.maven.profile.activation; + +import org.apache.maven.model.Profile; + +/* + * Copyright 2001-2005 The Apache Software Foundation. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +public interface ProfileActivator +{ + + static final String ROLE = ProfileActivator.class.getName(); + + boolean canDetermineActivation( Profile profile ); + + boolean isActive( Profile profile ); + +} diff --git a/maven-project/src/main/java/org/apache/maven/profile/activation/SystemPropertyProfileActivator.java b/maven-project/src/main/java/org/apache/maven/profile/activation/SystemPropertyProfileActivator.java new file mode 100644 index 0000000000..60327db4c8 --- /dev/null +++ b/maven-project/src/main/java/org/apache/maven/profile/activation/SystemPropertyProfileActivator.java @@ -0,0 +1,58 @@ +package org.apache.maven.profile.activation; + +import org.apache.maven.model.Activation; +import org.apache.maven.model.ActivationProperty; +import org.apache.maven.model.Profile; +import org.codehaus.plexus.util.StringUtils; + +/* + * Copyright 2001-2005 The Apache Software Foundation. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +public class SystemPropertyProfileActivator + implements ProfileActivator +{ + + public boolean canDetermineActivation( Profile profile ) + { + return profile.getActivation() != null && profile.getActivation().getProperty() != null; + } + + public boolean isActive( Profile profile ) + { + Activation activation = profile.getActivation(); + + ActivationProperty property = activation.getProperty(); + + if ( property != null ) + { + String sysValue = System.getProperty( property.getName() ); + + String propValue = property.getValue(); + if ( StringUtils.isNotEmpty( propValue ) ) + { + // we have a value, so it has to match the system value... + return propValue.equals( sysValue ); + } + else + { + return StringUtils.isNotEmpty( sysValue ); + } + } + + return false; + } + +} diff --git a/maven-project/src/main/java/org/apache/maven/project/DefaultMavenProjectBuilder.java b/maven-project/src/main/java/org/apache/maven/project/DefaultMavenProjectBuilder.java index 45a99d0af1..4395ed77ce 100644 --- a/maven-project/src/main/java/org/apache/maven/project/DefaultMavenProjectBuilder.java +++ b/maven-project/src/main/java/org/apache/maven/project/DefaultMavenProjectBuilder.java @@ -27,13 +27,14 @@ import org.apache.maven.artifact.resolver.ArtifactResolutionResult; import org.apache.maven.artifact.resolver.ArtifactResolver; import org.apache.maven.artifact.transform.ReleaseArtifactTransformation; import org.apache.maven.model.Build; -import org.apache.maven.model.Dependency; import org.apache.maven.model.DistributionManagement; import org.apache.maven.model.Model; import org.apache.maven.model.Parent; import org.apache.maven.model.Plugin; +import org.apache.maven.model.Profile; import org.apache.maven.model.Repository; import org.apache.maven.model.io.xpp3.MavenXpp3Reader; +import org.apache.maven.profile.activation.ProfileActivationCalculator; import org.apache.maven.project.inheritance.ModelInheritanceAssembler; import org.apache.maven.project.injection.ModelDefaultsInjector; import org.apache.maven.project.interpolation.ModelInterpolationException; @@ -98,6 +99,8 @@ public class DefaultMavenProjectBuilder private ModelInterpolator modelInterpolator; private ArtifactRepositoryFactory artifactRepositoryFactory; + + private ProfileActivationCalculator profileActivationCalculator; private final Map modelCache = new HashMap(); @@ -263,6 +266,15 @@ public class DefaultMavenProjectBuilder { modelCache.put( key, model ); } + + // TODO: Add profiles support here? + List activePomProfiles = profileActivationCalculator.calculateActiveProfiles( model.getProfiles() ); + for ( Iterator it = activePomProfiles.iterator(); it.hasNext(); ) + { + Profile profile = (Profile) it.next(); + + modelInheritanceAssembler.mergeProfileWithModel( cachedModel, profile ); + } model = modelInterpolator.interpolate( model ); diff --git a/maven-project/src/main/java/org/apache/maven/project/inheritance/DefaultModelInheritanceAssembler.java b/maven-project/src/main/java/org/apache/maven/project/inheritance/DefaultModelInheritanceAssembler.java index cbcc61c063..a40660dcd4 100644 --- a/maven-project/src/main/java/org/apache/maven/project/inheritance/DefaultModelInheritanceAssembler.java +++ b/maven-project/src/main/java/org/apache/maven/project/inheritance/DefaultModelInheritanceAssembler.java @@ -17,11 +17,14 @@ package org.apache.maven.project.inheritance; */ 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.Model; +import org.apache.maven.model.ModelBase; import org.apache.maven.model.Plugin; +import org.apache.maven.model.Profile; import org.apache.maven.model.Repository; import org.apache.maven.model.Scm; import org.apache.maven.model.Site; @@ -44,6 +47,12 @@ public class DefaultModelInheritanceAssembler { public void assembleModelInheritance( Model child, Model parent ) { + // cannot inherit from null parent. + if ( parent == null ) + { + return; + } + // Group id if ( child.getGroupId() == null ) { @@ -56,7 +65,7 @@ public class DefaultModelInheritanceAssembler { // The parent version may have resolved to something different, so we take what we asked for... // instead of - child.setVersion( parent.getVersion() ); - + if ( child.getParent() != null ) { child.setVersion( child.getParent().getVersion() ); @@ -134,8 +143,24 @@ public class DefaultModelInheritanceAssembler } // Build - assembleBuildInheritance( child, parent ); + assembleBuildInheritance( child, parent.getBuild() ); + assembleModelBaseInheritance( child, parent ); + } + + public void mergeProfileWithModel( Model model, Profile profile ) + { + assembleModelBaseInheritance( model, profile ); + + Build modelBuild = model.getBuild(); + + BuildBase profileBuild = profile.getBuild(); + + assembleBuildBaseInheritance( modelBuild, profileBuild ); + } + + private void assembleModelBaseInheritance( ModelBase child, ModelBase parent ) + { // Dependencies :: aggregate List dependencies = parent.getDependencies(); @@ -175,7 +200,7 @@ public class DefaultModelInheritanceAssembler child.addPluginRepository( repository ); } } - + // Reports :: aggregate if ( child.getReports() != null && parent.getReports() != null ) { @@ -201,8 +226,8 @@ public class DefaultModelInheritanceAssembler assembleDependencyManagementInheritance( child, parent ); } - - private void assembleDependencyManagementInheritance( Model child, Model parent ) + + private void assembleDependencyManagementInheritance( ModelBase child, ModelBase parent ) { DependencyManagement parentDepMgmt = parent.getDependencyManagement(); @@ -237,10 +262,15 @@ public class DefaultModelInheritanceAssembler } } - private void assembleBuildInheritance( Model child, Model parent ) + private void assembleBuildInheritance( Model child, Build parentBuild ) { + // cannot inherit from null parent... + if ( parentBuild == null ) + { + return; + } + Build childBuild = child.getBuild(); - Build parentBuild = parent.getBuild(); if ( parentBuild != null ) { @@ -253,11 +283,6 @@ public class DefaultModelInheritanceAssembler // values // that have not been set by the child. - if ( childBuild.getDefaultGoal() == null ) - { - childBuild.setDefaultGoal( parentBuild.getDefaultGoal() ); - } - if ( childBuild.getDirectory() == null ) { childBuild.setDirectory( parentBuild.getDirectory() ); @@ -288,31 +313,47 @@ public class DefaultModelInheritanceAssembler childBuild.setTestOutputDirectory( parentBuild.getTestOutputDirectory() ); } - if ( childBuild.getFinalName() == null ) - { - childBuild.setFinalName( parentBuild.getFinalName() ); - } + assembleBuildBaseInheritance( childBuild, parentBuild ); + } + } - List resources = childBuild.getResources(); - if ( resources == null || resources.isEmpty() ) - { - childBuild.setResources( parentBuild.getResources() ); - } + private void assembleBuildBaseInheritance( BuildBase childBuild, BuildBase parentBuild ) + { + // if the parent build is null, obviously we cannot inherit from it... + if ( parentBuild == null ) + { + return; + } - resources = childBuild.getTestResources(); - if ( resources == null || resources.isEmpty() ) - { - childBuild.setTestResources( parentBuild.getTestResources() ); - } + if ( childBuild.getDefaultGoal() == null ) + { + childBuild.setDefaultGoal( parentBuild.getDefaultGoal() ); + } - // Plugins are aggregated if Plugin.inherit != false - ModelUtils.mergePluginLists( childBuild, parentBuild, true ); - - // Plugin management :: aggregate - if( childBuild != null && parentBuild != null ) - { - ModelUtils.mergePluginLists( childBuild.getPluginManagement(), parentBuild.getPluginManagement(), false ); - } + 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 + if ( childBuild != null && parentBuild != null ) + { + ModelUtils.mergePluginLists( childBuild.getPluginManagement(), parentBuild.getPluginManagement(), false ); } } @@ -336,10 +377,11 @@ public class DefaultModelInheritanceAssembler childScm.setConnection( appendPath( parentScm.getConnection(), child.getArtifactId() ) ); } - if ( StringUtils.isEmpty( childScm.getDeveloperConnection() ) && - !StringUtils.isEmpty( parentScm.getDeveloperConnection() ) ) + if ( StringUtils.isEmpty( childScm.getDeveloperConnection() ) + && !StringUtils.isEmpty( parentScm.getDeveloperConnection() ) ) { - childScm.setDeveloperConnection( appendPath( parentScm.getDeveloperConnection(), child.getArtifactId() ) ); + childScm + .setDeveloperConnection( appendPath( parentScm.getDeveloperConnection(), child.getArtifactId() ) ); } if ( StringUtils.isEmpty( childScm.getUrl() ) && !StringUtils.isEmpty( parentScm.getUrl() ) ) diff --git a/maven-project/src/main/java/org/apache/maven/project/inheritance/ModelInheritanceAssembler.java b/maven-project/src/main/java/org/apache/maven/project/inheritance/ModelInheritanceAssembler.java index cc859642f5..82288c2de6 100644 --- a/maven-project/src/main/java/org/apache/maven/project/inheritance/ModelInheritanceAssembler.java +++ b/maven-project/src/main/java/org/apache/maven/project/inheritance/ModelInheritanceAssembler.java @@ -17,6 +17,7 @@ package org.apache.maven.project.inheritance; */ import org.apache.maven.model.Model; +import org.apache.maven.model.Profile; /** * @author Jason van Zyl @@ -27,4 +28,6 @@ public interface ModelInheritanceAssembler String ROLE = ModelInheritanceAssembler.class.getName(); void assembleModelInheritance( Model child, Model parent ); + + void mergeProfileWithModel( Model model, Profile profile ); } diff --git a/maven-project/src/main/resources/META-INF/plexus/components.xml b/maven-project/src/main/resources/META-INF/plexus/components.xml index 3b8206676e..2bd6c249c1 100644 --- a/maven-project/src/main/resources/META-INF/plexus/components.xml +++ b/maven-project/src/main/resources/META-INF/plexus/components.xml @@ -51,8 +51,50 @@ org.apache.maven.artifact.repository.ArtifactRepositoryFactory + + org.apache.maven.profile.activation.ProfileActivationCalculator + + + + org.apache.maven.profile.activation.ProfileActivationCalculator + org.apache.maven.profile.activation.ProfileActivationCalculator + + + + org.apache.maven.profile.activation.ProfileActivator + jdk-prefix + org.apache.maven.profile.activation.JdkPrefixProfileActivator + + + + org.apache.maven.profile.activation.ProfileActivator + system-property + org.apache.maven.profile.activation.SystemPropertyProfileActivator + + + + org.apache.maven.profile.activation.ProfileActivator + explicit-listing + org.apache.maven.profile.activation.ExplicitListingProfileActivator + \ No newline at end of file