PR: MNG-895

merge resource lists

git-svn-id: https://svn.apache.org/repos/asf/maven/components/trunk@293205 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Brett Leslie Porter 2005-10-03 02:09:04 +00:00
parent 95282adf58
commit 41c129e593
4 changed files with 81 additions and 55 deletions

View File

@ -19,11 +19,13 @@ package org.apache.maven.project;
import org.apache.maven.model.Activation;
import org.apache.maven.model.ActivationFile;
import org.apache.maven.model.ActivationProperty;
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.Exclusion;
import org.apache.maven.model.Extension;
import org.apache.maven.model.Goal;
import org.apache.maven.model.Model;
import org.apache.maven.model.Parent;
@ -1035,4 +1037,40 @@ public final class ModelUtils
return repositories;
}
public static void mergeExtensionLists( Build childBuild, Build parentBuild )
{
for ( Iterator i = parentBuild.getExtensions().iterator(); i.hasNext(); )
{
Extension e = (Extension) i.next();
if ( !childBuild.getExtensions().contains( e ) )
{
childBuild.addExtension( e );
}
}
}
public static void mergeResourceLists( List childResources, List parentResources )
{
for ( Iterator i = parentResources.iterator(); i.hasNext(); )
{
Resource r = (Resource) i.next();
if ( !childResources.contains( r ) )
{
childResources.add( r );
}
}
}
public static void mergeFilterLists( List childFilters, List parentFilters )
{
for ( Iterator i = parentFilters.iterator(); i.hasNext(); )
{
String f = (String) i.next();
if ( !childFilters.contains( f ) )
{
childFilters.add( f );
}
}
}
}

View File

@ -20,7 +20,6 @@ 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.Reporting;
@ -173,11 +172,11 @@ public class DefaultModelInheritanceAssembler
assembleDependencyManagementInheritance( child, parent );
assembleDistributionManagementInheritance( child, parent );
Properties props = new Properties();
props.putAll( parent.getProperties() );
props.putAll( child.getProperties() );
child.setProperties( props );
}
@ -350,7 +349,7 @@ public class DefaultModelInheritanceAssembler
}
// Extensions are accumlated
mergeExtensionLists( childBuild, parentBuild );
ModelUtils.mergeExtensionLists( childBuild, parentBuild );
if ( childBuild.getDirectory() == null )
{
@ -367,17 +366,9 @@ public class DefaultModelInheritanceAssembler
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() );
}
ModelUtils.mergeFilterLists( childBuild.getFilters(), parentBuild.getFilters() );
ModelUtils.mergeResourceLists( childBuild.getResources(), parentBuild.getResources() );
ModelUtils.mergeResourceLists( childBuild.getTestResources(), parentBuild.getTestResources() );
// Plugins are aggregated if Plugin.inherit != false
ModelUtils.mergePluginLists( childBuild, parentBuild, true );
@ -398,7 +389,6 @@ public class DefaultModelInheritanceAssembler
}
}
private void assembleScmInheritance( Model child, Model parent, boolean appendPaths )
{
if ( parent.getScm() != null )
@ -523,15 +513,4 @@ public class DefaultModelInheritanceAssembler
}
}
private void mergeExtensionLists( Build childBuild, Build parentBuild )
{
for ( Iterator i = parentBuild.getExtensions().iterator(); i.hasNext(); )
{
Extension e = (Extension) i.next();
if ( !childBuild.getExtensions().contains( e ) )
{
childBuild.addExtension( e );
}
}
}
}

View File

@ -1,5 +1,21 @@
package org.apache.maven.project.injection;
/*
* 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.
*/
import org.apache.maven.model.Build;
import org.apache.maven.model.BuildBase;
import org.apache.maven.model.ConfigurationContainer;
@ -99,31 +115,9 @@ public class DefaultProfileInjector
modelBuild.setFinalName( profileBuild.getFinalName() );
}
List profileResources = profileBuild.getResources();
if ( profileResources != null && !profileResources.isEmpty() )
{
modelBuild.setResources( profileResources );
}
List profileTestResources = profileBuild.getTestResources();
if ( profileTestResources != null && !profileTestResources.isEmpty() )
{
modelBuild.setTestResources( profileTestResources );
}
if ( profileBuild.getFilters() != null )
{
if ( modelBuild.getFilters() == null )
{
modelBuild.setFilters( profileBuild.getFilters() );
}
else
{
modelBuild.getFilters().addAll( profileBuild.getFilters() );
}
}
ModelUtils.mergeFilterLists( modelBuild.getFilters(), profileBuild.getFilters() );
ModelUtils.mergeResourceLists( modelBuild.getResources(), profileBuild.getResources() );
ModelUtils.mergeResourceLists( modelBuild.getTestResources(), profileBuild.getTestResources() );
injectPlugins( profileBuild, modelBuild );
@ -299,7 +293,7 @@ public class DefaultProfileInjector
}
/**
* Append modules specified in the profile to the end of the list supplied by the model, if
* Append modules specified in the profile to the end of the list supplied by the model, if
* they don't already exist.
*/
private void injectModules( Profile profile, Model model )

View File

@ -1,13 +1,28 @@
package org.apache.maven.project.injection;
/*
* 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.
*/
import org.apache.maven.model.Model;
import org.apache.maven.model.Profile;
public interface ProfileInjector
{
String ROLE = ProfileInjector.class.getName();
void inject( Profile profile, Model model );
}