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:
Britton Isbell 2009-04-02 00:30:00 +00:00
parent 421732b443
commit 38e8586852
2 changed files with 99 additions and 112 deletions

View File

@ -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()
{ {

View File

@ -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 try
{ {
projectProfiles.addAll( externalProfileManager.getActiveProfiles() ); projectProfiles = ProfileContext.getActiveProfilesFrom(config, model, container);
}
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
{
//System.out.println("PROFILE POM - ACTIVE: COUNT = " + profileManager.getActiveProfiles( model ).size() +"," + projectProfiles.size());
projectProfiles.addAll( profileManager.getActiveProfiles() );
} }
catch ( ProfileActivationException e ) catch ( ProfileActivationException e )
{ {
@ -388,11 +364,9 @@ 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>();
@ -400,82 +374,25 @@ public class DefaultMavenProjectBuilder
.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() );
private void validateModel( Model model, File pomFile )
throws InvalidProjectModelException
{
// Must validate before artifact construction to make sure dependencies are good
ModelValidationResult validationResult = validator.validate( model );
String projectId = safeVersionlessKey( model.getGroupId(), model.getArtifactId() );
if ( validationResult.getMessageCount() > 0 )
{
for ( String s : (List<String>) validationResult.getMessages() )
{
logger.debug( s );
}
throw new InvalidProjectModelException( projectId, "Failed to validate POM", pomFile, validationResult );
}
}
private static String safeVersionlessKey( String groupId, String artifactId )
{
String gid = groupId;
if ( StringUtils.isEmpty( gid ) )
{
gid = "unknown";
}
String aid = artifactId;
if ( StringUtils.isEmpty( aid ) )
{
aid = "unknown";
}
return ArtifactUtils.versionlessKey( gid, aid );
}
private static void setBuildOutputDirectoryOnParent( MavenProject project )
{
MavenProject parent = project.getParent();
if ( parent != null && parent.getFile() != null && parent.getModel().getBuild() != null )
{
parent.getModel().getBuild().setDirectory( parent.getFile().getAbsolutePath() );
setBuildOutputDirectoryOnParent( parent );
}
}
private PomClassicDomainModel buildModel( File pom, ProfileContextInfo profileInfo, ProjectBuilderConfiguration config )
throws IOException
{
if ( pom == null )
{
throw new IllegalArgumentException( "pom: null" );
}
PomClassicDomainModel domainModel = new PomClassicDomainModel( pom );
domainModel.setProjectDirectory( pom.getParentFile() );
domainModel.setMostSpecialized( true ); domainModel.setMostSpecialized( true );
List<DomainModel> domainModels = new ArrayList<DomainModel>(); List<DomainModel> domainModels = new ArrayList<DomainModel>();
domainModels.add( domainModel ); domainModels.add( domainModel );
ArtifactRepository localRepository = config.getLocalRepository(); ArtifactRepository localRepository = projectBuilderConfiguration.getLocalRepository();
List<ArtifactRepository> remoteRepositories = config.getRemoteRepositories(); List<ArtifactRepository> remoteRepositories = projectBuilderConfiguration.getRemoteRepositories();
File parentFile = null; File parentFile = null;
int lineageCount = 0; int lineageCount = 0;
if ( domainModel.getParentId() != null ) if ( domainModel.getParentId() != null )
{ {
List<DomainModel> mavenParents; List<DomainModel> mavenParents;
if ( isParentLocal( domainModel.getRelativePathOfParent(), pom.getParentFile() ) ) if ( isParentLocal( domainModel.getRelativePathOfParent(), pomFile.getParentFile() ) )
{ {
mavenParents = getDomainModelParentsFromLocalPath( domainModel, localRepository, remoteRepositories, pom.getParentFile() ); mavenParents = getDomainModelParentsFromLocalPath( domainModel, localRepository, remoteRepositories, pomFile.getParentFile() );
} }
else else
{ {
@ -528,7 +445,54 @@ public class DefaultMavenProjectBuilder
return transformedDomainModel; return transformedDomainModel;
} }
private PomClassicDomainModel convertToDomainModel( Model model, boolean isMostSpecialized ) private void validateModel( Model model, File pomFile )
throws InvalidProjectModelException
{
// Must validate before artifact construction to make sure dependencies are good
ModelValidationResult validationResult = validator.validate( model );
String projectId = safeVersionlessKey( model.getGroupId(), model.getArtifactId() );
if ( validationResult.getMessageCount() > 0 )
{
for ( String s : (List<String>) validationResult.getMessages() )
{
logger.debug( s );
}
throw new InvalidProjectModelException( projectId, "Failed to validate POM", pomFile, validationResult );
}
}
private static String safeVersionlessKey( String groupId, String artifactId )
{
String gid = groupId;
if ( StringUtils.isEmpty( gid ) )
{
gid = "unknown";
}
String aid = artifactId;
if ( StringUtils.isEmpty( aid ) )
{
aid = "unknown";
}
return ArtifactUtils.versionlessKey( gid, aid );
}
private static void setBuildOutputDirectoryOnParent( MavenProject project )
{
MavenProject parent = project.getParent();
if ( parent != null && parent.getFile() != null && parent.getModel().getBuild() != null )
{
parent.getModel().getBuild().setDirectory( parent.getFile().getAbsolutePath() );
setBuildOutputDirectoryOnParent( parent );
}
}
private static 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
{ {