mirror of https://github.com/apache/maven.git
o Fixed model building to account for default values that can't be set in the MDO. The use case we have for this is the scope for dependencies: Setting this in the MDO would cause injection of the default in the raw model and would interfere with the superposition of dependency management. The 2.x code handles this via a side effect of MavenMetadataSource.createArtifact() which doesn't look like a clean way to go.
git-svn-id: https://svn.apache.org/repos/asf/maven/components/trunk@782376 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
958f69c50f
commit
d07123e796
|
@ -1405,8 +1405,7 @@ public class PomConstructionTest
|
|||
{
|
||||
PomTestWrapper pom = buildPom( "dependency-scope-inheritance/sub" );
|
||||
String scope = (String) pom.getValue("dependencies[1]/scope");
|
||||
assertNull("Scope not null: " + scope, scope);
|
||||
|
||||
assertEquals( "compile", scope );
|
||||
}
|
||||
|
||||
public void testDependencyScope()
|
||||
|
|
|
@ -175,6 +175,8 @@ public class DefaultModelBuilder
|
|||
|
||||
managementInjector.injectManagement( resultModel, request );
|
||||
|
||||
modelNormalizer.injectDefaultValues( resultModel, request );
|
||||
|
||||
if ( request.isProcessPlugins() )
|
||||
{
|
||||
pluginConfigurationExpander.expandPluginConfiguration( resultModel, request );
|
||||
|
|
|
@ -26,11 +26,13 @@ import java.util.List;
|
|||
import java.util.Map;
|
||||
|
||||
import org.apache.maven.model.Build;
|
||||
import org.apache.maven.model.Dependency;
|
||||
import org.apache.maven.model.Model;
|
||||
import org.apache.maven.model.ModelBuildingRequest;
|
||||
import org.apache.maven.model.Plugin;
|
||||
import org.apache.maven.model.merge.MavenModelMerger;
|
||||
import org.codehaus.plexus.component.annotations.Component;
|
||||
import org.codehaus.plexus.util.StringUtils;
|
||||
|
||||
/**
|
||||
* Handles normalization of a model.
|
||||
|
@ -78,4 +80,30 @@ public class DefaultModelNormalizer
|
|||
|
||||
}
|
||||
|
||||
public void injectDefaultValues( Model model, ModelBuildingRequest request )
|
||||
{
|
||||
injectDependencyDefaults( model.getDependencies() );
|
||||
|
||||
Build build = model.getBuild();
|
||||
if ( build != null )
|
||||
{
|
||||
for ( Plugin plugin : build.getPlugins() )
|
||||
{
|
||||
injectDependencyDefaults( plugin.getDependencies() );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void injectDependencyDefaults( List<Dependency> dependencies )
|
||||
{
|
||||
for ( Dependency dependency : dependencies )
|
||||
{
|
||||
if ( StringUtils.isEmpty( dependency.getScope() ) )
|
||||
{
|
||||
// we cannot set this directly in the MDO due to the interactions with dependency management
|
||||
dependency.setScope( "compile" );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -23,7 +23,8 @@ import org.apache.maven.model.Model;
|
|||
import org.apache.maven.model.ModelBuildingRequest;
|
||||
|
||||
/**
|
||||
* Handles normalization of a model.
|
||||
* Handles normalization of a model. In this context, normalization is the process of producing a canonical
|
||||
* representation for models that physically look different but are semantically equivalent.
|
||||
*
|
||||
* @author Benjamin Bentmann
|
||||
*/
|
||||
|
@ -38,4 +39,13 @@ public interface ModelNormalizer
|
|||
*/
|
||||
void mergeDuplicates( Model model, ModelBuildingRequest request );
|
||||
|
||||
/**
|
||||
* Sets default values in the specified model that for technical reasons cannot be set directly in the Modello
|
||||
* definition.
|
||||
*
|
||||
* @param model The model in which to set the default values, must not be {@code null}.
|
||||
* @param request The model building request that holds further settings, must not be {@code null}.
|
||||
*/
|
||||
void injectDefaultValues( Model model, ModelBuildingRequest request );
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue