o Removed static processor context and move its remaining bits into the project builder

git-svn-id: https://svn.apache.org/repos/asf/maven/components/branches/MNG-2766@778441 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Benjamin Bentmann 2009-05-25 15:49:43 +00:00
parent 0a5b7985f6
commit bbc97f4eb9
2 changed files with 103 additions and 167 deletions

View File

@ -20,6 +20,7 @@ import java.io.IOException;
import java.io.Reader;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.List;
import org.apache.maven.artifact.Artifact;
@ -36,15 +37,17 @@ import org.apache.maven.model.Build;
import org.apache.maven.model.DomainModel;
import org.apache.maven.model.Model;
import org.apache.maven.model.ModelEventListener;
import org.apache.maven.model.ProcessorContext;
import org.apache.maven.model.Profile;
import org.apache.maven.model.Repository;
import org.apache.maven.model.inheritance.InheritanceAssembler;
import org.apache.maven.model.interpolator.Interpolator;
import org.apache.maven.model.io.xpp3.MavenXpp3Reader;
import org.apache.maven.model.lifecycle.LifecycleBindingsInjector;
import org.apache.maven.model.management.ManagementInjector;
import org.apache.maven.model.normalization.ModelNormalizer;
import org.apache.maven.model.plugin.PluginConfigurationExpander;
import org.apache.maven.model.profile.ProfileActivationException;
import org.apache.maven.model.profile.ProfileInjector;
import org.apache.maven.model.profile.ProfileSelector;
import org.apache.maven.profiles.ProfileManager;
import org.apache.maven.project.validation.ModelValidationResult;
@ -82,12 +85,21 @@ public class DefaultMavenProjectBuilder
@Requirement
private ModelNormalizer normalizer;
@Requirement
private InheritanceAssembler inheritanceAssembler;
@Requirement
private Interpolator interpolator;
@Requirement
private ProfileSelector profileSelector;
@Requirement
private ProfileInjector profileInjector;
@Requirement
private ManagementInjector managementInjector;
@Requirement
private LifecycleBindingsInjector lifecycleBindingsInjector;
@ -152,17 +164,15 @@ public class DefaultMavenProjectBuilder
try
{
List<Profile> externalProfiles = new ArrayList<Profile>();
for ( Profile p : projectProfiles )
{
if ( !"pom".equals( p.getSource() ) )
{
logger.debug( "Merging profile into model (build): Model = " + domainModel.getId() + ", Profile = " + p.getId() );
externalProfiles.add( p );
logger.debug( "Merging profile into model (build): Model = " + domainModel.getId() + ", Profile = "
+ p.getId() );
profileInjector.injectProfile( domainModel.getModel(), p );
}
}
domainModel = ProcessorContext.mergeProfilesIntoModel( externalProfiles, domainModel );
}
catch ( IOException e )
{
@ -178,7 +188,7 @@ public class DefaultMavenProjectBuilder
lifecycleBindingsInjector.injectLifecycleBindings( model );
}
ProcessorContext.processManagementNodes( model );
managementInjector.injectManagement( model );
project = this.fromDomainModelToMavenProject( model, domainModel.getParentFile(), configuration, pomFile );
@ -473,21 +483,14 @@ public class DefaultMavenProjectBuilder
for ( Profile p : profiles )
{
logger.debug( "Merging profile into model: Model = " + dm.getId() + ", Profile = " + p.getId() );
profileInjector.injectProfile( dm.getModel(), p );
}
profileModels.add( ProcessorContext.mergeProfilesIntoModel( profiles, dm ) );
}
else
{
profileModels.add( dm );
}
}
else
{
profileModels.add( dm );
}
profileModels.add( dm );
}
DomainModel transformedDomainModel = ProcessorContext.build( profileModels, listeners );
DomainModel transformedDomainModel = build( profileModels, listeners );
// Lineage count is inclusive to add the POM read in itself.
transformedDomainModel.setLineageCount( lineageCount + 1 );
@ -496,6 +499,89 @@ public class DefaultMavenProjectBuilder
return transformedDomainModel;
}
/**
* Parent domain models on bottom.
*
* @param domainModels
* @param listeners
* @return
* @throws IOException
*/
private DomainModel build( List<DomainModel> domainModels, List<ModelEventListener> listeners )
throws IOException
{
DomainModel child = null;
for ( DomainModel domainModel : domainModels )
{
if ( domainModel.isMostSpecialized() )
{
child = domainModel;
}
}
if ( child == null )
{
throw new IOException( "Could not find child model" );
}
Model target = processModelsForInheritance( convertDomainModelsToMavenModels( domainModels ) );
if ( listeners != null )
{
for ( ModelEventListener listener : listeners )
{
listener.fire( target );
}
}
DomainModel domainModel = new DomainModel( target, child.isMostSpecialized() );
domainModel.setProjectDirectory( child.getProjectDirectory() );
domainModel.setParentFile( child.getParentFile() );
return domainModel;
}
private List<Model> convertDomainModelsToMavenModels( List<DomainModel> domainModels )
throws IOException
{
List<Model> models = new ArrayList<Model>();
for ( DomainModel domainModel : domainModels )
{
DomainModel dm = domainModel;
if ( dm.getModel() != null )
{
if ( dm.isMostSpecialized() )
{
models.add( 0, dm.getModel() );
}
else
{
models.add( dm.getModel() );
}
}
else
{
throw new IOException( "model: null" );
}
}
return models;
}
private Model processModelsForInheritance( List<Model> models )
{
Collections.reverse( models );
Model previousModel = null;
for ( Model currentModel : models )
{
inheritanceAssembler.assembleModelInheritance( currentModel, previousModel );
previousModel = currentModel;
}
return previousModel;
}
private void validateModel( Model model, File pomFile, boolean lenient )
throws InvalidProjectModelException
{

View File

@ -1,150 +0,0 @@
package org.apache.maven.model;
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you 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 java.io.IOException;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.List;
import org.apache.maven.model.inheritance.DefaultInheritanceAssembler;
import org.apache.maven.model.inheritance.InheritanceAssembler;
import org.apache.maven.model.management.DefaultManagementInjector;
import org.apache.maven.model.management.ManagementInjector;
import org.apache.maven.model.profile.DefaultProfileInjector;
import org.apache.maven.model.profile.ProfileInjector;
/*
* TODO: Get rid of this class and go back to an inheritance assembler, profile injector and default injector, all
* orchestrated by the model builder. The processors will also by replaced by the merger.
*/
public class ProcessorContext
{
/**
* Parent domain models on bottom.
*
* @param domainModels
* @param listeners
* @return
* @throws IOException
*/
public static DomainModel build( List<DomainModel> domainModels, List<ModelEventListener> listeners )
throws IOException
{
DomainModel child = null;
for ( DomainModel domainModel : domainModels )
{
if(domainModel.isMostSpecialized())
{
child = domainModel;
}
}
if(child == null)
{
throw new IOException("Could not find child model");
}
Model target = processModelsForInheritance( convertDomainModelsToMavenModels( domainModels ) );
if(listeners != null)
{
for(ModelEventListener listener : listeners)
{
listener.fire(target);
}
}
DomainModel domainModel = new DomainModel( target, child.isMostSpecialized() );
domainModel.setProjectDirectory(child.getProjectDirectory());
domainModel.setParentFile(child.getParentFile());
return domainModel;
}
private static ProfileInjector profileInjector = new DefaultProfileInjector();
public static DomainModel mergeProfilesIntoModel(Collection<Profile> profiles, DomainModel domainModel) throws IOException
{
Model model = domainModel.getModel();
for ( Profile profile : profiles )
{
profileInjector.injectProfile( model, profile );
}
return domainModel;
}
private static List<Model> convertDomainModelsToMavenModels(List<DomainModel> domainModels) throws IOException
{
List<Model> models = new ArrayList<Model>();
for(DomainModel domainModel : domainModels)
{
DomainModel dm = domainModel;
if(dm.getModel() != null)
{
if(dm.isMostSpecialized())
{
models.add(0, dm.getModel() );
}
else
{
models.add( dm.getModel() );
}
}
else
{
throw new IOException( "model: null" );
}
}
return models;
}
private static InheritanceAssembler inheritanceAssembler = new DefaultInheritanceAssembler();
private static Model processModelsForInheritance(List<Model> models)
{
Collections.reverse( models );
Model previousModel = null;
for ( Model currentModel : models )
{
inheritanceAssembler.assembleModelInheritance( currentModel, previousModel );
previousModel = currentModel;
}
return previousModel;
}
private static ManagementInjector managementInjector = new DefaultManagementInjector();
public static Model processManagementNodes(Model target)
throws IOException
{
managementInjector.injectManagement( target );
return target;
}
}