You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@maven.apache.org by si...@apache.org on 2009/04/02 02:30:00 UTC
svn commit: r761121 - in
/maven/components/trunk/maven-project/src/main/java/org/apache/maven:
profiles/ProfileContext.java project/DefaultMavenProjectBuilder.java
Author: sisbell
Date: Thu Apr 2 00:30:00 2009
New Revision: 761121
URL: http://svn.apache.org/viewvc?rev=761121&view=rev
Log:
Collapsed methods, moved logic for active profiles from ProjectBuilder to ProfileContext.
Modified:
maven/components/trunk/maven-project/src/main/java/org/apache/maven/profiles/ProfileContext.java
maven/components/trunk/maven-project/src/main/java/org/apache/maven/project/DefaultMavenProjectBuilder.java
Modified: maven/components/trunk/maven-project/src/main/java/org/apache/maven/profiles/ProfileContext.java
URL: http://svn.apache.org/viewvc/maven/components/trunk/maven-project/src/main/java/org/apache/maven/profiles/ProfileContext.java?rev=761121&r1=761120&r2=761121&view=diff
==============================================================================
--- maven/components/trunk/maven-project/src/main/java/org/apache/maven/profiles/ProfileContext.java (original)
+++ maven/components/trunk/maven-project/src/main/java/org/apache/maven/profiles/ProfileContext.java Thu Apr 2 00:30:00 2009
@@ -28,9 +28,13 @@
import org.apache.maven.profiles.matchers.DefaultMatcher;
import org.apache.maven.profiles.matchers.ProfileMatcher;
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.model.Model;
import org.apache.maven.model.Profile;
+import org.codehaus.plexus.PlexusContainer;
public class ProfileContext
{
@@ -55,7 +59,26 @@
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()
{
Modified: maven/components/trunk/maven-project/src/main/java/org/apache/maven/project/DefaultMavenProjectBuilder.java
URL: http://svn.apache.org/viewvc/maven/components/trunk/maven-project/src/main/java/org/apache/maven/project/DefaultMavenProjectBuilder.java?rev=761121&r1=761120&r2=761121&view=diff
==============================================================================
--- maven/components/trunk/maven-project/src/main/java/org/apache/maven/project/DefaultMavenProjectBuilder.java (original)
+++ maven/components/trunk/maven-project/src/main/java/org/apache/maven/project/DefaultMavenProjectBuilder.java Thu Apr 2 00:30:00 2009
@@ -306,34 +306,10 @@
String projectId = safeVersionlessKey( model.getGroupId(), model.getArtifactId() );
- List<Profile> projectProfiles = new ArrayList<Profile>();
- 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());
+ List<Profile> projectProfiles;
try
{
- //System.out.println("PROFILE POM - ACTIVE: COUNT = " + profileManager.getActiveProfiles( model ).size() +"," + projectProfiles.size());
- projectProfiles.addAll( profileManager.getActiveProfiles() );
+ projectProfiles = ProfileContext.getActiveProfilesFrom(config, model, container);
}
catch ( ProfileActivationException e )
{
@@ -388,19 +364,85 @@
return project;
}
-
private PomClassicDomainModel buildWithoutProfiles( String projectId, File pomFile, ProjectBuilderConfiguration projectBuilderConfiguration )
throws ProjectBuildingException, IOException
- {
-
+ {
List<String> activeProfileIds = ( projectBuilderConfiguration != null && projectBuilderConfiguration.getGlobalProfileManager() != null && projectBuilderConfiguration.getGlobalProfileManager()
.getProfileActivationContext() != null ) ? projectBuilderConfiguration.getGlobalProfileManager().getProfileActivationContext().getExplicitlyActiveProfileIds() : new ArrayList<String>();
List<String> inactiveProfileIds = ( projectBuilderConfiguration != null && projectBuilderConfiguration.getGlobalProfileManager() != null && projectBuilderConfiguration
.getGlobalProfileManager().getProfileActivationContext() != null ) ? projectBuilderConfiguration.getGlobalProfileManager().getProfileActivationContext().getExplicitlyInactiveProfileIds()
: 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 )
@@ -450,85 +492,7 @@
}
}
- 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 );
-
- 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 )
+ private static PomClassicDomainModel convertToDomainModel( Model model, boolean isMostSpecialized )
throws IOException
{
if ( model == null )
@@ -562,7 +526,7 @@
* @return true if the relative path of the specified parent references a pom, otherwise returns
* fals
*/
- private boolean isParentLocal( String relativePath, File projectDirectory )
+ private static boolean isParentLocal( String relativePath, File projectDirectory )
{
try
{