mirror of https://github.com/apache/maven.git
Updated to use latest model-builder. Now detect most specialized model through method, not order of domain model list.
git-svn-id: https://svn.apache.org/repos/asf/maven/components/trunk@749870 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
9ef5c6edbe
commit
1492907f1b
|
@ -96,6 +96,7 @@ public final class MavenDependencyProcessor
|
|||
}
|
||||
|
||||
MavenDomainModel domainModel = new MavenDomainModel( superBytes );
|
||||
domainModel.setMostSpecialized(true);
|
||||
domainModels.add( domainModel );
|
||||
|
||||
Collection<ModelContainer> activeProfiles = domainModel.getActiveProfileContainers( interpolatorProperties );
|
||||
|
|
|
@ -62,6 +62,8 @@ public class PomClassicDomainModel implements InputStreamDomainModel
|
|||
private List<ModelProperty> modelProperties;
|
||||
|
||||
private int lineageCount;
|
||||
|
||||
private boolean isMostSpecialized = false;
|
||||
|
||||
private String parentGroupId = null, parentArtifactId = null, parentVersion = null, parentId = null, parentRelativePath;
|
||||
|
||||
|
@ -79,6 +81,13 @@ public class PomClassicDomainModel implements InputStreamDomainModel
|
|||
}
|
||||
initializeProperties( modelProperties );
|
||||
}
|
||||
|
||||
public PomClassicDomainModel( List<ModelProperty> modelProperties, boolean isMostSpecialized )
|
||||
{
|
||||
this( modelProperties );
|
||||
this.isMostSpecialized = isMostSpecialized;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
|
@ -97,6 +106,13 @@ public class PomClassicDomainModel implements InputStreamDomainModel
|
|||
modelProperties = getModelProperties();
|
||||
initializeProperties( modelProperties );
|
||||
}
|
||||
|
||||
public PomClassicDomainModel( InputStream inputStream, boolean isMostSpecialized )
|
||||
throws IOException
|
||||
{
|
||||
this( inputStream );
|
||||
this.isMostSpecialized = isMostSpecialized;
|
||||
}
|
||||
|
||||
private void initializeProperties(List<ModelProperty> modelProperties)
|
||||
{
|
||||
|
@ -299,7 +315,7 @@ public class PomClassicDomainModel implements InputStreamDomainModel
|
|||
s.add(ProjectUri.Profiles.Profile.Reporting.Plugins.Plugin.ReportSets.xUri);
|
||||
s.add(ProjectUri.Profiles.Profile.Reporting.Plugins.Plugin.ReportSets.ReportSet.configuration);
|
||||
s.add(ProjectUri.Profiles.Profile.Build.Plugins.Plugin.Executions.Execution.configuration);
|
||||
|
||||
s.add(ProjectUri.Profiles.Profile.properties);
|
||||
s.add(ProjectUri.Profiles.Profile.modules);
|
||||
s.add(ProjectUri.Profiles.Profile.Dependencies.xUri);
|
||||
s.add(ProjectUri.Profiles.Profile.Build.Plugins.Plugin.configuration);
|
||||
|
@ -366,4 +382,14 @@ public class PomClassicDomainModel implements InputStreamDomainModel
|
|||
}
|
||||
}
|
||||
|
||||
public boolean isMostSpecialized()
|
||||
{
|
||||
return isMostSpecialized;
|
||||
}
|
||||
|
||||
public void setMostSpecialized(boolean isMostSpecialized)
|
||||
{
|
||||
this.isMostSpecialized = isMostSpecialized;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -95,6 +95,7 @@ public class PomTransformer
|
|||
ProjectUri.Build.PluginManagement.Plugins.Plugin.Dependencies.xUri,
|
||||
ProjectUri.Build.PluginManagement.Plugins.Plugin.Dependencies.Dependency.Exclusions.xUri,
|
||||
ProjectUri.Build.Plugins.xUri,
|
||||
ProjectUri.properties,
|
||||
ProjectUri.Build.Plugins.Plugin.configuration,
|
||||
ProjectUri.Reporting.Plugins.xUri,
|
||||
ProjectUri.Reporting.Plugins.Plugin.configuration,
|
||||
|
@ -472,24 +473,21 @@ public class PomTransformer
|
|||
boolean containsDistSnapRepo = false;
|
||||
boolean containsDistSite = false;
|
||||
|
||||
int domainModelIndex = -1;
|
||||
|
||||
for ( DomainModel domainModel : domainModels )
|
||||
{
|
||||
domainModelIndex++;
|
||||
|
||||
List<ModelProperty> tmp = domainModel.getModelProperties();
|
||||
|
||||
List clearedProperties = new ArrayList<ModelProperty>();
|
||||
List<ModelProperty> clearedProperties = new ArrayList<ModelProperty>();
|
||||
|
||||
for(TransformerRule rule : transformerRules)
|
||||
{
|
||||
rule.execute(tmp, domainModelIndex);
|
||||
rule.execute(tmp, domainModel.isMostSpecialized());
|
||||
}
|
||||
|
||||
for(TransformerRemovalRule rule : transformerRemovalRules)
|
||||
{
|
||||
tmp.removeAll(rule.executeWithReturnPropertiesToRemove(tmp, domainModelIndex));
|
||||
tmp.removeAll(rule.executeWithReturnPropertiesToRemove(tmp, domainModel.isMostSpecialized()));
|
||||
}
|
||||
|
||||
// Project URL TransformerRule
|
||||
|
@ -506,7 +504,7 @@ public class PomTransformer
|
|||
// Profiles TransformerRule: not inherited
|
||||
// Prerequisites TransformerRule: not inherited
|
||||
// DistributionManagent.Relocation TransformerRule: not inherited
|
||||
if ( domainModelIndex > 0 )
|
||||
if ( !domainModel.isMostSpecialized() )
|
||||
{
|
||||
for ( ModelProperty mp : tmp )
|
||||
{
|
||||
|
@ -581,7 +579,7 @@ public class PomTransformer
|
|||
//Rules processed on collapsed pom
|
||||
|
||||
//TransformerRule: Remove duplicate filters
|
||||
modelProperties.removeAll(new DuplicateFiltersTransformerRule().executeWithReturnPropertiesToRemove( modelProperties , 0));
|
||||
modelProperties.removeAll(new DuplicateFiltersTransformerRule().executeWithReturnPropertiesToRemove( modelProperties , false));
|
||||
|
||||
//TransformerRule: Build plugin config overrides reporting plugin config
|
||||
return new OverideConfigTransformerRule().execute( modelProperties );
|
||||
|
|
|
@ -1375,7 +1375,7 @@ public class ProjectUri
|
|||
"http://apache.org/maven/project/profiles#collection/profile/distributionManagement/status";
|
||||
}
|
||||
|
||||
public static String properties = "http://apache.org/maven/project/profiles#collection/profile/properties#collection";
|
||||
public static String properties = "http://apache.org/maven/project/profiles#collection/profile/properties";
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -7,6 +7,6 @@ import java.util.List;
|
|||
|
||||
public interface TransformerRemovalRule {
|
||||
|
||||
List<ModelProperty> executeWithReturnPropertiesToRemove(List<ModelProperty> modelProperties, int domainIndex)
|
||||
List<ModelProperty> executeWithReturnPropertiesToRemove(List<ModelProperty> modelProperties, boolean isMostSpecialized)
|
||||
throws DataSourceException;
|
||||
}
|
||||
|
|
|
@ -7,6 +7,6 @@ import java.util.List;
|
|||
|
||||
public interface TransformerRule
|
||||
{
|
||||
void execute(List<ModelProperty> modelProperties, int domainIndex) throws DataSourceException;
|
||||
void execute(List<ModelProperty> modelProperties, boolean isMostSpecialized) throws DataSourceException;
|
||||
|
||||
}
|
||||
|
|
|
@ -18,10 +18,10 @@ import java.util.Arrays;
|
|||
*/
|
||||
public class DefaultDependencyScopeTransformerRule implements TransformerRule
|
||||
{
|
||||
public void execute(List<ModelProperty> modelProperties, int domainIndex)
|
||||
public void execute(List<ModelProperty> modelProperties, boolean isMostSpecialized)
|
||||
throws DataSourceException
|
||||
{
|
||||
if(domainIndex == 0)
|
||||
if(isMostSpecialized)
|
||||
{
|
||||
ModelDataSource s = new DefaultModelDataSource( modelProperties, Arrays.asList( new ArtifactModelContainerFactory()) );
|
||||
for(ModelContainer mc : s.queryFor(ProjectUri.Dependencies.Dependency.xUri))
|
||||
|
|
|
@ -13,7 +13,7 @@ import java.util.ArrayList;
|
|||
*/
|
||||
public class DefaultExecutionIdTransformerRule implements TransformerRemovalRule
|
||||
{
|
||||
public List<ModelProperty> executeWithReturnPropertiesToRemove(List<ModelProperty> modelProperties, int domainIndex)
|
||||
public List<ModelProperty> executeWithReturnPropertiesToRemove(List<ModelProperty> modelProperties, boolean isMostSpecialized)
|
||||
throws DataSourceException
|
||||
{
|
||||
List<ModelProperty> replace = new ArrayList<ModelProperty>();
|
||||
|
|
|
@ -10,7 +10,7 @@ import java.util.ArrayList;
|
|||
|
||||
public class DuplicateFiltersTransformerRule implements TransformerRemovalRule
|
||||
{
|
||||
public List<ModelProperty> executeWithReturnPropertiesToRemove(List<ModelProperty> modelProperties, int domainIndex)
|
||||
public List<ModelProperty> executeWithReturnPropertiesToRemove(List<ModelProperty> modelProperties, boolean isMostSpecialized)
|
||||
throws DataSourceException
|
||||
{
|
||||
List<ModelProperty> removedProperties = new ArrayList<ModelProperty>();
|
||||
|
|
|
@ -13,7 +13,7 @@ import java.util.List;
|
|||
*/
|
||||
public class MissingGroupIdTransformerRule implements TransformerRule
|
||||
{
|
||||
public void execute(List<ModelProperty> modelProperties, int domainIndex) throws DataSourceException
|
||||
public void execute(List<ModelProperty> modelProperties, boolean isMostSpecialized) throws DataSourceException
|
||||
{
|
||||
if ( getPropertyFor( ProjectUri.groupId, modelProperties ) == null )
|
||||
{
|
||||
|
|
|
@ -13,7 +13,7 @@ import java.util.List;
|
|||
*/
|
||||
public class MissingVersionTransformerRule implements TransformerRule
|
||||
{
|
||||
public void execute(List<ModelProperty> modelProperties, int domainIndex) throws DataSourceException
|
||||
public void execute(List<ModelProperty> modelProperties, boolean isMostSpecialized) throws DataSourceException
|
||||
{
|
||||
if ( PomTransformer.getPropertyFor( ProjectUri.version, modelProperties ) == null )
|
||||
{
|
||||
|
|
|
@ -14,10 +14,10 @@ import java.util.ArrayList;
|
|||
*/
|
||||
public class ModulesNotInheritedTransformerRule implements TransformerRemovalRule
|
||||
{
|
||||
public List<ModelProperty> executeWithReturnPropertiesToRemove(List<ModelProperty> modelProperties, int domainIndex)
|
||||
public List<ModelProperty> executeWithReturnPropertiesToRemove(List<ModelProperty> modelProperties, boolean isMostSpecialized)
|
||||
throws DataSourceException
|
||||
{
|
||||
if (domainIndex > 0)
|
||||
if (!isMostSpecialized)
|
||||
{
|
||||
ModelProperty modulesProperty = PomTransformer.getPropertyFor(ProjectUri.Modules.xUri, modelProperties);
|
||||
if (modulesProperty != null)
|
||||
|
|
|
@ -13,11 +13,11 @@ import java.util.ArrayList;
|
|||
*/
|
||||
public class NameNotInheritedTransformerRule implements TransformerRemovalRule
|
||||
{
|
||||
public List<ModelProperty> executeWithReturnPropertiesToRemove(List<ModelProperty> modelProperties, int domainIndex)
|
||||
public List<ModelProperty> executeWithReturnPropertiesToRemove(List<ModelProperty> modelProperties, boolean isMostSpecialized)
|
||||
throws DataSourceException
|
||||
{
|
||||
List<ModelProperty> removedProperties = new ArrayList<ModelProperty>();
|
||||
if ( domainIndex > 0 )
|
||||
if ( !isMostSpecialized )
|
||||
{
|
||||
for ( ModelProperty mp : modelProperties )
|
||||
{
|
||||
|
|
|
@ -19,12 +19,12 @@ import java.util.Arrays;
|
|||
*/
|
||||
public class NotInheritedPluginExecutionTransformerRule implements TransformerRemovalRule
|
||||
{
|
||||
public List<ModelProperty> executeWithReturnPropertiesToRemove(List<ModelProperty> modelProperties, int domainIndex)
|
||||
public List<ModelProperty> executeWithReturnPropertiesToRemove(List<ModelProperty> modelProperties, boolean isMostSpecialized)
|
||||
throws DataSourceException
|
||||
{
|
||||
List<ModelProperty> removeProperties = new ArrayList<ModelProperty>();
|
||||
|
||||
if ( domainIndex > 0 )
|
||||
if ( !isMostSpecialized)
|
||||
{
|
||||
ModelDataSource source = new DefaultModelDataSource( modelProperties, Arrays.asList(
|
||||
new ArtifactModelContainerFactory(), new PluginExecutionIdModelContainerFactory() ));
|
||||
|
|
|
@ -17,11 +17,11 @@ import java.util.ArrayList;
|
|||
*/
|
||||
public class NotInheritedPluginTransformerRule implements TransformerRemovalRule
|
||||
{
|
||||
public List<ModelProperty> executeWithReturnPropertiesToRemove(List<ModelProperty> modelProperties, int domainIndex)
|
||||
public List<ModelProperty> executeWithReturnPropertiesToRemove(List<ModelProperty> modelProperties, boolean isMostSpecialized)
|
||||
throws DataSourceException
|
||||
{
|
||||
List<ModelProperty> removeProperties = new ArrayList<ModelProperty>();
|
||||
if ( domainIndex > 0 )
|
||||
if ( !isMostSpecialized)
|
||||
{
|
||||
ModelDataSource source = new DefaultModelDataSource( modelProperties, PomTransformer.MODEL_CONTAINER_FACTORIES );
|
||||
List<ModelContainer> containers = source.queryFor( ProjectUri.Build.Plugins.Plugin.xUri );
|
||||
|
|
|
@ -10,11 +10,11 @@ import java.util.ArrayList;
|
|||
|
||||
public class PackagingNotInheritedTransformerRule implements TransformerRemovalRule
|
||||
{
|
||||
public List<ModelProperty> executeWithReturnPropertiesToRemove(List<ModelProperty> modelProperties, int domainIndex)
|
||||
public List<ModelProperty> executeWithReturnPropertiesToRemove(List<ModelProperty> modelProperties, boolean isMostSpecialized)
|
||||
throws DataSourceException
|
||||
{
|
||||
List<ModelProperty> removedProperties = new ArrayList<ModelProperty>();
|
||||
if ( domainIndex > 0 )
|
||||
if ( !isMostSpecialized )
|
||||
{
|
||||
for ( ModelProperty mp : modelProperties )
|
||||
{
|
||||
|
|
|
@ -13,11 +13,11 @@ import java.util.ArrayList;
|
|||
*/
|
||||
public class RelativePathNotInheritedTransformerRule implements TransformerRemovalRule
|
||||
{
|
||||
public List<ModelProperty> executeWithReturnPropertiesToRemove(List<ModelProperty> modelProperties, int domainIndex)
|
||||
public List<ModelProperty> executeWithReturnPropertiesToRemove(List<ModelProperty> modelProperties, boolean isMostSpecialized)
|
||||
throws DataSourceException
|
||||
{
|
||||
List<ModelProperty> removedProperties = new ArrayList<ModelProperty>();
|
||||
if ( domainIndex > 0 )
|
||||
if ( !isMostSpecialized )
|
||||
{
|
||||
for ( ModelProperty mp : modelProperties )
|
||||
{
|
||||
|
|
|
@ -13,8 +13,8 @@ public class DefaultDomainModel extends PomClassicDomainModel {
|
|||
|
||||
private List<ModelProperty> modelProperties;
|
||||
|
||||
public DefaultDomainModel(List<ModelProperty> modelProperties) {
|
||||
super( modelProperties);
|
||||
public DefaultDomainModel(List<ModelProperty> modelProperties, boolean isMostSpecialized) {
|
||||
super( modelProperties, isMostSpecialized);
|
||||
this.modelProperties = modelProperties;
|
||||
}
|
||||
|
||||
|
|
|
@ -9,6 +9,6 @@ import java.io.IOException;
|
|||
|
||||
public class DefaultDomainModelFactory implements DomainModelFactory {
|
||||
public DomainModel createDomainModel(List<ModelProperty> modelProperties) throws IOException {
|
||||
return new DefaultDomainModel(modelProperties);
|
||||
return new DefaultDomainModel(modelProperties, false);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -41,8 +41,8 @@ public class EnforcerPomTest
|
|||
mp2.add(new ModelProperty(ProjectUri.Dependencies.Dependency.artifactId, "aid"));
|
||||
mp2.add(new ModelProperty(ProjectUri.Dependencies.Dependency.classifier, "tests"));
|
||||
|
||||
DomainModel childModel = new DefaultDomainModel(mp2);
|
||||
DomainModel parentModel = new DefaultDomainModel(mp);
|
||||
DomainModel childModel = new DefaultDomainModel(mp2, true);
|
||||
DomainModel parentModel = new DefaultDomainModel(mp, false);
|
||||
|
||||
ModelTransformerContext ctx = new ModelTransformerContext(PomTransformer.MODEL_CONTAINER_INFOS );
|
||||
|
||||
|
|
|
@ -49,12 +49,12 @@ public class PluginSpecTest {
|
|||
mp.add(new ModelProperty(ProjectUri.Build.PluginManagement.Plugins.Plugin.Executions.Execution.Goals.goal, "xpp3-reader"));
|
||||
mp.add(new ModelProperty(ProjectUri.Build.PluginManagement.Plugins.Plugin.Executions.Execution.Goals.goal, "xpp3-writer"));
|
||||
|
||||
DomainModel parentModel = new DefaultDomainModel(mp);
|
||||
DomainModel parentModel = new DefaultDomainModel(mp, false);
|
||||
|
||||
ModelTransformerContext ctx = new ModelTransformerContext(PomTransformer.MODEL_CONTAINER_INFOS );
|
||||
|
||||
ModelTransformer transformer = new PomTransformer(new DefaultDomainModelFactory());
|
||||
DomainModel domainModel = ctx.transform( Arrays.asList(parentModel, new DefaultDomainModel(mp0)), transformer, transformer );
|
||||
DomainModel domainModel = ctx.transform( Arrays.asList(parentModel, new DefaultDomainModel(mp0, true)), transformer, transformer );
|
||||
|
||||
|
||||
List<ModelContainerFactory> factories = new ArrayList<ModelContainerFactory>(PomTransformer.MODEL_CONTAINER_FACTORIES);
|
||||
|
|
|
@ -478,7 +478,7 @@ public class DefaultMavenProjectBuilder
|
|||
|
||||
PomClassicDomainModel transformedDomainModel;
|
||||
try {
|
||||
transformedDomainModel = ( (PomClassicDomainModel) ctx.transform( Arrays.asList( new PomClassicDomainModel(transformed), convertToDomainModel(model)),
|
||||
transformedDomainModel = ( (PomClassicDomainModel) ctx.transform( Arrays.asList( new PomClassicDomainModel(transformed, false), convertToDomainModel(model, true)),
|
||||
transformer,
|
||||
transformer,
|
||||
Collections.EMPTY_LIST,
|
||||
|
@ -619,8 +619,10 @@ public class DefaultMavenProjectBuilder
|
|||
|
||||
PomClassicDomainModel domainModel = new PomClassicDomainModel( pom );
|
||||
domainModel.setProjectDirectory( pom.getParentFile() );
|
||||
domainModel.setMostSpecialized(true);
|
||||
|
||||
List<DomainModel> domainModels = new ArrayList<DomainModel>();
|
||||
domainModels.add( domainModel );
|
||||
|
||||
|
||||
//Process Profile on most specialized child model
|
||||
ProfileContext profileContext = new ProfileContext(new DefaultModelDataSource(domainModel.getModelProperties(),
|
||||
|
@ -640,9 +642,10 @@ public class DefaultMavenProjectBuilder
|
|||
mp.getResolvedValue()));
|
||||
}
|
||||
}
|
||||
domainModels.add(new PomClassicDomainModel(transformed));
|
||||
domainModels.add(new PomClassicDomainModel(transformed, false));
|
||||
}
|
||||
|
||||
domainModels.add( domainModel );
|
||||
|
||||
File parentFile = null;
|
||||
int lineageCount = 0;
|
||||
if ( domainModel.getParentId() != null )
|
||||
|
@ -672,7 +675,7 @@ public class DefaultMavenProjectBuilder
|
|||
domainModels.addAll( mavenParents );
|
||||
}
|
||||
|
||||
domainModels.add( convertToDomainModel( getSuperModel() ) );
|
||||
domainModels.add( convertToDomainModel( getSuperModel() , false ));
|
||||
|
||||
PomTransformer transformer = new PomTransformer( new PomClassicDomainModelFactory() );
|
||||
|
||||
|
@ -691,7 +694,7 @@ public class DefaultMavenProjectBuilder
|
|||
return transformedDomainModel;
|
||||
}
|
||||
|
||||
private PomClassicDomainModel convertToDomainModel(Model model) throws IOException
|
||||
private PomClassicDomainModel convertToDomainModel(Model model, boolean isMostSpecialized) throws IOException
|
||||
{
|
||||
if ( model == null )
|
||||
{
|
||||
|
@ -712,7 +715,7 @@ public class DefaultMavenProjectBuilder
|
|||
out.close();
|
||||
}
|
||||
}
|
||||
return new PomClassicDomainModel(new ByteArrayInputStream(baos.toByteArray()));
|
||||
return new PomClassicDomainModel(new ByteArrayInputStream(baos.toByteArray()), isMostSpecialized);
|
||||
}
|
||||
|
||||
protected MavenProject buildFromLocalPath(File pom,
|
||||
|
|
|
@ -119,14 +119,14 @@ public class PomConstructionTest
|
|||
}
|
||||
|
||||
/*MNG-3900*/
|
||||
/*
|
||||
public void testProfilePropertiesInterpolation()
|
||||
throws Exception
|
||||
{
|
||||
PomTestWrapper pom = buildPomFromMavenProject( "profile-properties-interpolation", "a" );
|
||||
PomTestWrapper pom = buildPomFromMavenProject( "profile-properties-interpolation", "interpolation-profile" );
|
||||
assertEquals("PASSED", pom.getValue("properties[1]/test"));
|
||||
assertEquals("PASSED", pom.getValue("properties[1]/property"));
|
||||
}
|
||||
*/
|
||||
|
||||
|
||||
// Some better conventions for the test poms needs to be created and each of these tests
|
||||
// that represent a verification of a specification item needs to be a couple lines at most.
|
||||
|
|
|
@ -48,6 +48,7 @@
|
|||
<!-- This profile defines the properties to use for interpolation. -->
|
||||
<properties>
|
||||
<test>PASSED</test>
|
||||
<test1>PASSED</test1>
|
||||
</properties>
|
||||
</profile>
|
||||
</profiles>
|
||||
|
|
Loading…
Reference in New Issue