mirror of https://github.com/apache/maven.git
Collapsed methods, moved logic for active profiles from ProjectBuilder to ProfileContext.
git-svn-id: https://svn.apache.org/repos/asf/maven/components/trunk@761121 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
421732b443
commit
38e8586852
|
@ -28,9 +28,13 @@ import java.util.List;
|
||||||
import org.apache.maven.profiles.matchers.DefaultMatcher;
|
import org.apache.maven.profiles.matchers.DefaultMatcher;
|
||||||
import org.apache.maven.profiles.matchers.ProfileMatcher;
|
import org.apache.maven.profiles.matchers.ProfileMatcher;
|
||||||
import org.apache.maven.profiles.matchers.PropertyMatcher;
|
import org.apache.maven.profiles.matchers.PropertyMatcher;
|
||||||
|
import org.apache.maven.project.ProjectBuilderConfiguration;
|
||||||
|
import org.apache.maven.project.ProjectBuildingException;
|
||||||
import org.apache.maven.shared.model.InterpolatorProperty;
|
import org.apache.maven.shared.model.InterpolatorProperty;
|
||||||
|
|
||||||
|
import org.apache.maven.model.Model;
|
||||||
import org.apache.maven.model.Profile;
|
import org.apache.maven.model.Profile;
|
||||||
|
import org.codehaus.plexus.PlexusContainer;
|
||||||
|
|
||||||
public class ProfileContext
|
public class ProfileContext
|
||||||
{
|
{
|
||||||
|
@ -55,7 +59,26 @@ public class ProfileContext
|
||||||
this.inactiveProfileIds = profileContextInfo.getInactiveProfileIds();
|
this.inactiveProfileIds = profileContextInfo.getInactiveProfileIds();
|
||||||
}
|
}
|
||||||
|
|
||||||
// public Collection<Profile> getActiveProfilesFrom(ProfileManager manaa)
|
|
||||||
|
public static List<Profile> getActiveProfilesFrom(ProjectBuilderConfiguration config, Model model, PlexusContainer container)
|
||||||
|
throws ProfileActivationException
|
||||||
|
{
|
||||||
|
List<Profile> projectProfiles = new ArrayList<Profile>();
|
||||||
|
ProfileManager externalProfileManager = config.getGlobalProfileManager();
|
||||||
|
|
||||||
|
ProfileActivationContext profileActivationContext = (externalProfileManager == null) ? new ProfileActivationContext( config.getExecutionProperties(), false ):
|
||||||
|
externalProfileManager.getProfileActivationContext();
|
||||||
|
|
||||||
|
if(externalProfileManager != null)
|
||||||
|
{
|
||||||
|
projectProfiles.addAll( externalProfileManager.getActiveProfiles() );
|
||||||
|
}
|
||||||
|
|
||||||
|
ProfileManager profileManager = new DefaultProfileManager( container, profileActivationContext );
|
||||||
|
profileManager.addProfiles( model.getProfiles() );
|
||||||
|
projectProfiles.addAll( profileManager.getActiveProfiles() );
|
||||||
|
return projectProfiles;
|
||||||
|
}
|
||||||
|
|
||||||
public Collection<Profile> getActiveProfiles()
|
public Collection<Profile> getActiveProfiles()
|
||||||
{
|
{
|
||||||
|
|
|
@ -306,34 +306,10 @@ public class DefaultMavenProjectBuilder
|
||||||
|
|
||||||
String projectId = safeVersionlessKey( model.getGroupId(), model.getArtifactId() );
|
String projectId = safeVersionlessKey( model.getGroupId(), model.getArtifactId() );
|
||||||
|
|
||||||
List<Profile> projectProfiles = new ArrayList<Profile>();
|
List<Profile> projectProfiles;
|
||||||
ProfileManager externalProfileManager = config.getGlobalProfileManager();
|
|
||||||
|
|
||||||
ProfileActivationContext profileActivationContext = (externalProfileManager == null) ? new ProfileActivationContext( config.getExecutionProperties(), false ):
|
|
||||||
externalProfileManager.getProfileActivationContext();
|
|
||||||
|
|
||||||
if(externalProfileManager != null)
|
|
||||||
{
|
|
||||||
//System.out.println("PROFILES = " + externalProfileManager.getProfilesById().toString());
|
|
||||||
|
|
||||||
try
|
|
||||||
{
|
|
||||||
projectProfiles.addAll( externalProfileManager.getActiveProfiles() );
|
|
||||||
}
|
|
||||||
catch ( ProfileActivationException e )
|
|
||||||
{
|
|
||||||
throw new ProjectBuildingException( projectId, "Failed to activate external profiles.", projectDescriptor,
|
|
||||||
e );
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
ProfileManager profileManager = new DefaultProfileManager( container, profileActivationContext );
|
|
||||||
profileManager.addProfiles( model.getProfiles() );
|
|
||||||
//System.out.println("PROFILE POM: COUNT = " + model.getProfiles().size());
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
//System.out.println("PROFILE POM - ACTIVE: COUNT = " + profileManager.getActiveProfiles( model ).size() +"," + projectProfiles.size());
|
projectProfiles = ProfileContext.getActiveProfilesFrom(config, model, container);
|
||||||
projectProfiles.addAll( profileManager.getActiveProfiles() );
|
|
||||||
}
|
}
|
||||||
catch ( ProfileActivationException e )
|
catch ( ProfileActivationException e )
|
||||||
{
|
{
|
||||||
|
@ -388,19 +364,85 @@ public class DefaultMavenProjectBuilder
|
||||||
return project;
|
return project;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
private PomClassicDomainModel buildWithoutProfiles( String projectId, File pomFile, ProjectBuilderConfiguration projectBuilderConfiguration )
|
private PomClassicDomainModel buildWithoutProfiles( String projectId, File pomFile, ProjectBuilderConfiguration projectBuilderConfiguration )
|
||||||
throws ProjectBuildingException, IOException
|
throws ProjectBuildingException, IOException
|
||||||
{
|
{
|
||||||
|
|
||||||
List<String> activeProfileIds = ( projectBuilderConfiguration != null && projectBuilderConfiguration.getGlobalProfileManager() != null && projectBuilderConfiguration.getGlobalProfileManager()
|
List<String> activeProfileIds = ( projectBuilderConfiguration != null && projectBuilderConfiguration.getGlobalProfileManager() != null && projectBuilderConfiguration.getGlobalProfileManager()
|
||||||
.getProfileActivationContext() != null ) ? projectBuilderConfiguration.getGlobalProfileManager().getProfileActivationContext().getExplicitlyActiveProfileIds() : new ArrayList<String>();
|
.getProfileActivationContext() != null ) ? projectBuilderConfiguration.getGlobalProfileManager().getProfileActivationContext().getExplicitlyActiveProfileIds() : new ArrayList<String>();
|
||||||
|
|
||||||
List<String> inactiveProfileIds = ( projectBuilderConfiguration != null && projectBuilderConfiguration.getGlobalProfileManager() != null && projectBuilderConfiguration
|
List<String> inactiveProfileIds = ( projectBuilderConfiguration != null && projectBuilderConfiguration.getGlobalProfileManager() != null && projectBuilderConfiguration
|
||||||
.getGlobalProfileManager().getProfileActivationContext() != null ) ? projectBuilderConfiguration.getGlobalProfileManager().getProfileActivationContext().getExplicitlyInactiveProfileIds()
|
.getGlobalProfileManager().getProfileActivationContext() != null ) ? projectBuilderConfiguration.getGlobalProfileManager().getProfileActivationContext().getExplicitlyInactiveProfileIds()
|
||||||
: new ArrayList<String>();
|
: new ArrayList<String>();
|
||||||
|
|
||||||
return buildModel( pomFile, new ProfileContextInfo(null, activeProfileIds, inactiveProfileIds), projectBuilderConfiguration );
|
ProfileContextInfo profileInfo = new ProfileContextInfo(null, activeProfileIds, inactiveProfileIds);
|
||||||
|
PomClassicDomainModel domainModel = new PomClassicDomainModel( pomFile );
|
||||||
|
domainModel.setProjectDirectory( pomFile.getParentFile() );
|
||||||
|
domainModel.setMostSpecialized( true );
|
||||||
|
|
||||||
|
List<DomainModel> domainModels = new ArrayList<DomainModel>();
|
||||||
|
|
||||||
|
domainModels.add( domainModel );
|
||||||
|
ArtifactRepository localRepository = projectBuilderConfiguration.getLocalRepository();
|
||||||
|
List<ArtifactRepository> remoteRepositories = projectBuilderConfiguration.getRemoteRepositories();
|
||||||
|
|
||||||
|
File parentFile = null;
|
||||||
|
int lineageCount = 0;
|
||||||
|
if ( domainModel.getParentId() != null )
|
||||||
|
{
|
||||||
|
List<DomainModel> mavenParents;
|
||||||
|
if ( isParentLocal( domainModel.getRelativePathOfParent(), pomFile.getParentFile() ) )
|
||||||
|
{
|
||||||
|
mavenParents = getDomainModelParentsFromLocalPath( domainModel, localRepository, remoteRepositories, pomFile.getParentFile() );
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
mavenParents = getDomainModelParentsFromRepository( domainModel, localRepository, remoteRepositories );
|
||||||
|
}
|
||||||
|
|
||||||
|
if ( mavenParents.size() > 0 )
|
||||||
|
{
|
||||||
|
PomClassicDomainModel dm = (PomClassicDomainModel) mavenParents.get( 0 );
|
||||||
|
parentFile = dm.getFile();
|
||||||
|
domainModel.setParentFile( parentFile );
|
||||||
|
lineageCount = mavenParents.size();
|
||||||
|
}
|
||||||
|
|
||||||
|
domainModels.addAll( mavenParents );
|
||||||
|
}
|
||||||
|
|
||||||
|
domainModels.add( convertToDomainModel( getSuperModel(), false ) );
|
||||||
|
List<DomainModel> profileModels = new ArrayList<DomainModel>();
|
||||||
|
//Process Profiles
|
||||||
|
for(DomainModel domain : domainModels)
|
||||||
|
{
|
||||||
|
PomClassicDomainModel dm = (PomClassicDomainModel) domain;
|
||||||
|
|
||||||
|
if(!dm.getModel().getProfiles().isEmpty())
|
||||||
|
{
|
||||||
|
ProfileContext profileContext1 = new ProfileContext( dm.getModel().getProfiles(), profileInfo );
|
||||||
|
Collection<Profile> profiles = profileContext1.getActiveProfiles();
|
||||||
|
if(!profiles.isEmpty())
|
||||||
|
{
|
||||||
|
profileModels.add(ProcessorContext.mergeProfilesIntoModel( profileContext1.getActiveProfiles(), dm ));
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
profileModels.add( dm );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
profileModels.add( dm );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
PomClassicDomainModel transformedDomainModel = ProcessorContext.build( profileModels, null );
|
||||||
|
|
||||||
|
// Lineage count is inclusive to add the POM read in itself.
|
||||||
|
transformedDomainModel.setLineageCount( lineageCount + 1 );
|
||||||
|
transformedDomainModel.setParentFile( parentFile );
|
||||||
|
|
||||||
|
return transformedDomainModel;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void validateModel( Model model, File pomFile )
|
private void validateModel( Model model, File pomFile )
|
||||||
|
@ -450,85 +492,7 @@ public class DefaultMavenProjectBuilder
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private PomClassicDomainModel buildModel( File pom, ProfileContextInfo profileInfo, ProjectBuilderConfiguration config )
|
private static PomClassicDomainModel convertToDomainModel( Model model, boolean isMostSpecialized )
|
||||||
throws IOException
|
|
||||||
{
|
|
||||||
if ( pom == null )
|
|
||||||
{
|
|
||||||
throw new IllegalArgumentException( "pom: null" );
|
|
||||||
}
|
|
||||||
|
|
||||||
PomClassicDomainModel domainModel = new PomClassicDomainModel( pom );
|
|
||||||
domainModel.setProjectDirectory( pom.getParentFile() );
|
|
||||||
domainModel.setMostSpecialized( true );
|
|
||||||
|
|
||||||
List<DomainModel> domainModels = new ArrayList<DomainModel>();
|
|
||||||
|
|
||||||
domainModels.add( domainModel );
|
|
||||||
ArtifactRepository localRepository = config.getLocalRepository();
|
|
||||||
List<ArtifactRepository> remoteRepositories = config.getRemoteRepositories();
|
|
||||||
|
|
||||||
File parentFile = null;
|
|
||||||
int lineageCount = 0;
|
|
||||||
if ( domainModel.getParentId() != null )
|
|
||||||
{
|
|
||||||
List<DomainModel> mavenParents;
|
|
||||||
if ( isParentLocal( domainModel.getRelativePathOfParent(), pom.getParentFile() ) )
|
|
||||||
{
|
|
||||||
mavenParents = getDomainModelParentsFromLocalPath( domainModel, localRepository, remoteRepositories, pom.getParentFile() );
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
mavenParents = getDomainModelParentsFromRepository( domainModel, localRepository, remoteRepositories );
|
|
||||||
}
|
|
||||||
|
|
||||||
if ( mavenParents.size() > 0 )
|
|
||||||
{
|
|
||||||
PomClassicDomainModel dm = (PomClassicDomainModel) mavenParents.get( 0 );
|
|
||||||
parentFile = dm.getFile();
|
|
||||||
domainModel.setParentFile( parentFile );
|
|
||||||
lineageCount = mavenParents.size();
|
|
||||||
}
|
|
||||||
|
|
||||||
domainModels.addAll( mavenParents );
|
|
||||||
}
|
|
||||||
|
|
||||||
domainModels.add( convertToDomainModel( getSuperModel(), false ) );
|
|
||||||
List<DomainModel> profileModels = new ArrayList<DomainModel>();
|
|
||||||
//Process Profiles
|
|
||||||
for(DomainModel domain : domainModels)
|
|
||||||
{
|
|
||||||
PomClassicDomainModel dm = (PomClassicDomainModel) domain;
|
|
||||||
|
|
||||||
if(!dm.getModel().getProfiles().isEmpty())
|
|
||||||
{
|
|
||||||
ProfileContext profileContext1 = new ProfileContext( dm.getModel().getProfiles(), profileInfo );
|
|
||||||
Collection<Profile> profiles = profileContext1.getActiveProfiles();
|
|
||||||
if(!profiles.isEmpty())
|
|
||||||
{
|
|
||||||
profileModels.add(ProcessorContext.mergeProfilesIntoModel( profileContext1.getActiveProfiles(), dm ));
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
profileModels.add( dm );
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
profileModels.add( dm );
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
PomClassicDomainModel transformedDomainModel = ProcessorContext.build( profileModels, null );
|
|
||||||
|
|
||||||
// Lineage count is inclusive to add the POM read in itself.
|
|
||||||
transformedDomainModel.setLineageCount( lineageCount + 1 );
|
|
||||||
transformedDomainModel.setParentFile( parentFile );
|
|
||||||
|
|
||||||
return transformedDomainModel;
|
|
||||||
}
|
|
||||||
|
|
||||||
private PomClassicDomainModel convertToDomainModel( Model model, boolean isMostSpecialized )
|
|
||||||
throws IOException
|
throws IOException
|
||||||
{
|
{
|
||||||
if ( model == null )
|
if ( model == null )
|
||||||
|
@ -562,7 +526,7 @@ public class DefaultMavenProjectBuilder
|
||||||
* @return true if the relative path of the specified parent references a pom, otherwise returns
|
* @return true if the relative path of the specified parent references a pom, otherwise returns
|
||||||
* fals
|
* fals
|
||||||
*/
|
*/
|
||||||
private boolean isParentLocal( String relativePath, File projectDirectory )
|
private static boolean isParentLocal( String relativePath, File projectDirectory )
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
|
|
Loading…
Reference in New Issue