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/03 13:45:46 UTC
svn commit: r761629 - in
/maven/components/trunk/maven-project/src/main/java/org/apache/maven:
profiles/ project/
Author: sisbell
Date: Fri Apr 3 11:45:45 2009
New Revision: 761629
URL: http://svn.apache.org/viewvc?rev=761629&view=rev
Log:
Collapsed the ProfileContext into the ProfileManager - serves similar function.
Added:
maven/components/trunk/maven-project/src/main/java/org/apache/maven/profiles/ProfileManagerInfo.java (contents, props changed)
- copied, changed from r761609, maven/components/trunk/maven-project/src/main/java/org/apache/maven/profiles/ProfileContextInfo.java
Removed:
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/profiles/ProfileContextInfo.java
Modified:
maven/components/trunk/maven-project/src/main/java/org/apache/maven/profiles/DefaultProfileManager.java
maven/components/trunk/maven-project/src/main/java/org/apache/maven/profiles/ProfileManager.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/DefaultProfileManager.java
URL: http://svn.apache.org/viewvc/maven/components/trunk/maven-project/src/main/java/org/apache/maven/profiles/DefaultProfileManager.java?rev=761629&r1=761628&r2=761629&view=diff
==============================================================================
--- maven/components/trunk/maven-project/src/main/java/org/apache/maven/profiles/DefaultProfileManager.java (original)
+++ maven/components/trunk/maven-project/src/main/java/org/apache/maven/profiles/DefaultProfileManager.java Fri Apr 3 11:45:45 2009
@@ -30,6 +30,7 @@
import org.apache.maven.profiles.matchers.ProfileMatcher;
import org.apache.maven.profiles.matchers.PropertyMatcher;
import org.apache.maven.shared.model.InterpolatorProperty;
+import org.apache.maven.project.ProjectBuilderConfiguration;
import org.apache.maven.project.builder.PomInterpolatorTag;
import org.codehaus.plexus.PlexusContainer;
import org.codehaus.plexus.MutablePlexusContainer;
@@ -45,6 +46,11 @@
private Map<String, Profile> profilesById = new LinkedHashMap<String, Profile>();
private ProfileActivationContext profileActivationContext;
+
+ private static final ProfileMatcher defaultMatcher = new DefaultMatcher();
+
+ private static final List<ProfileMatcher> matchers =
+ Collections.unmodifiableList( Arrays.asList( new DefaultMatcher(), new PropertyMatcher() ) );
/**
* the properties passed to the profile manager are the props that
@@ -195,6 +201,83 @@
return allActive;
}
+ 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 static Collection<Profile> getActiveProfiles(List<Profile> profiles, ProfileManagerInfo profileContextInfo)
+ {
+ List<InterpolatorProperty> properties = profileContextInfo.getInterpolatorProperties();
+ Collection<String> activeProfileIds = profileContextInfo.getActiveProfileIds();
+ Collection<String> inactiveProfileIds = profileContextInfo.getInactiveProfileIds();
+
+ List<Profile> matchedProfiles = new ArrayList<Profile>();
+ List<Profile> defaultProfiles = new ArrayList<Profile>();
+ for ( Profile profile : profiles )
+ {
+ String profileId = profile.getId();
+
+ if ( !inactiveProfileIds.contains( profileId ) )
+ {
+ if ( activeProfileIds.contains( profileId ) )
+ {
+ matchedProfiles.add( profile );
+ }
+ else if ( defaultMatcher.isMatch( profile, properties ) )
+ {
+ defaultProfiles.add( profile );
+ }
+ else
+ {
+ for ( ProfileMatcher matcher : matchers )
+ {
+ if ( matcher.isMatch( profile, properties ) )
+ {
+ matchedProfiles.add( profile );
+ break;
+ }
+ }
+ }
+ }
+ }
+
+ if ( matchedProfiles.isEmpty() )
+ {
+ matchedProfiles = defaultProfiles;
+ }
+
+ return matchedProfiles;
+ }
+
+ /* (non-Javadoc)
+ * @see org.apache.maven.project.ProfileManager#addProfiles(java.util.List)
+ */
+ public void addProfiles( List<Profile> profiles )
+ {
+ for ( Iterator it = profiles.iterator(); it.hasNext(); )
+ {
+ Profile profile = (Profile) it.next();
+
+ addProfile( profile );
+ }
+ }
+
private static List<Profile> getDefaultProfiles(List<Profile> profiles)
{
List<Profile> defaults = new ArrayList<Profile>();
@@ -208,9 +291,6 @@
return defaults;
}
- private static List<ProfileMatcher> matchers = Arrays.asList( (ProfileMatcher) new DefaultMatcher(),
- (ProfileMatcher) new PropertyMatcher());
-
private boolean isActive( Profile profile, ProfileActivationContext context )
throws ProfileActivationException
{
@@ -232,19 +312,6 @@
return false;
}
- /* (non-Javadoc)
- * @see org.apache.maven.project.ProfileManager#addProfiles(java.util.List)
- */
- public void addProfiles( List<Profile> profiles )
- {
- for ( Iterator it = profiles.iterator(); it.hasNext(); )
- {
- Profile profile = (Profile) it.next();
-
- addProfile( profile );
- }
- }
-
private void activateAsDefault( String profileId )
{
List defaultIds = profileActivationContext.getActiveByDefaultProfileIds();
Modified: maven/components/trunk/maven-project/src/main/java/org/apache/maven/profiles/ProfileManager.java
URL: http://svn.apache.org/viewvc/maven/components/trunk/maven-project/src/main/java/org/apache/maven/profiles/ProfileManager.java?rev=761629&r1=761628&r2=761629&view=diff
==============================================================================
--- maven/components/trunk/maven-project/src/main/java/org/apache/maven/profiles/ProfileManager.java (original)
+++ maven/components/trunk/maven-project/src/main/java/org/apache/maven/profiles/ProfileManager.java Fri Apr 3 11:45:45 2009
@@ -40,5 +40,5 @@
throws ProfileActivationException;
List<Profile> getActiveProfiles( )
- throws ProfileActivationException;
+ throws ProfileActivationException;
}
\ No newline at end of file
Copied: maven/components/trunk/maven-project/src/main/java/org/apache/maven/profiles/ProfileManagerInfo.java (from r761609, maven/components/trunk/maven-project/src/main/java/org/apache/maven/profiles/ProfileContextInfo.java)
URL: http://svn.apache.org/viewvc/maven/components/trunk/maven-project/src/main/java/org/apache/maven/profiles/ProfileManagerInfo.java?p2=maven/components/trunk/maven-project/src/main/java/org/apache/maven/profiles/ProfileManagerInfo.java&p1=maven/components/trunk/maven-project/src/main/java/org/apache/maven/profiles/ProfileContextInfo.java&r1=761609&r2=761629&rev=761629&view=diff
==============================================================================
--- maven/components/trunk/maven-project/src/main/java/org/apache/maven/profiles/ProfileContextInfo.java (original)
+++ maven/components/trunk/maven-project/src/main/java/org/apache/maven/profiles/ProfileManagerInfo.java Fri Apr 3 11:45:45 2009
@@ -6,7 +6,7 @@
import org.apache.maven.shared.model.InterpolatorProperty;
-public class ProfileContextInfo
+public class ProfileManagerInfo
{
private List<InterpolatorProperty> interpolatorProperties;
@@ -14,7 +14,7 @@
private Collection<String> inactiveProfileIds;
- public ProfileContextInfo(List<InterpolatorProperty> interpolatorProperties, Collection<String> activeProfileIds, Collection<String> inactiveProfileIds)
+ public ProfileManagerInfo(List<InterpolatorProperty> interpolatorProperties, Collection<String> activeProfileIds, Collection<String> inactiveProfileIds)
{
this.interpolatorProperties = (interpolatorProperties != null) ? interpolatorProperties : new ArrayList<InterpolatorProperty>();
this.activeProfileIds = (activeProfileIds != null) ? activeProfileIds : new ArrayList<String>();
Propchange: maven/components/trunk/maven-project/src/main/java/org/apache/maven/profiles/ProfileManagerInfo.java
------------------------------------------------------------------------------
--- svn:mergeinfo (added)
+++ svn:mergeinfo Fri Apr 3 11:45:45 2009
@@ -0,0 +1,7 @@
+/maven/components/branches/MNG-3932-1/maven-project/src/main/java/org/apache/maven/profiles/ProfileContextInfo.java:746145-746157
+/maven/components/branches/maven-2.0.10-RC/maven-project/src/main/java/org/apache/maven/profiles/ProfileContextInfo.java:680477
+/maven/components/branches/maven-2.0.x/maven-project/src/main/java/org/apache/maven/profiles/ProfileContextInfo.java:679206,708871,720042,726541,727548,727998,728264,728940,729060,729738,729785,730631
+/maven/components/branches/maven-2.1.x/maven-project/src/main/java/org/apache/maven/profiles/ProfileContextInfo.java:739385,741841,747468,747683,748815,749612
+/maven/components/branches/sisbell-plugin-manager/maven-project/src/main/java/org/apache/maven/profiles/ProfileContextInfo.java:738973-739966
+/maven/components/sisbell-plugin-manager/maven-project/src/main/java/org/apache/maven/profiles/ProfileContextInfo.java:738757-738972
+/maven/components/trunk/maven-project/src/main/java/org/apache/maven/profiles/ProfileContextInfo.java:688587-696625,696644-699681
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=761629&r1=761628&r2=761629&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 Fri Apr 3 11:45:45 2009
@@ -45,12 +45,11 @@
import org.apache.maven.profiles.DefaultProfileManager;
import org.apache.maven.profiles.ProfileActivationContext;
import org.apache.maven.profiles.ProfileActivationException;
-import org.apache.maven.profiles.ProfileContextInfo;
+import org.apache.maven.profiles.ProfileManagerInfo;
import org.apache.maven.profiles.ProfileManager;
import org.apache.maven.project.artifact.InvalidDependencyVersionException;
import org.apache.maven.project.builder.PomClassicDomainModel;
import org.apache.maven.project.builder.PomInterpolatorTag;
-import org.apache.maven.profiles.ProfileContext;
import org.apache.maven.project.processor.ProcessorContext;
import org.apache.maven.project.validation.ModelValidationResult;
import org.apache.maven.project.validation.ModelValidator;
@@ -127,7 +126,7 @@
PomClassicDomainModel domainModel;
try
{
- domainModel = buildWithoutProfiles( "unknown", pomFile, configuration );
+ domainModel = build( "unknown", pomFile, configuration );
}
catch (IOException e)
{
@@ -138,7 +137,7 @@
List<Profile> projectProfiles;
try
{
- projectProfiles = ProfileContext.getActiveProfilesFrom(configuration, domainModel.getModel(), container);
+ projectProfiles = DefaultProfileManager.getActiveProfilesFrom(configuration, domainModel.getModel(), container);
}
catch ( ProfileActivationException e )
{
@@ -220,7 +219,7 @@
PomClassicDomainModel domainModel;
try
{
- domainModel = buildWithoutProfiles( "unknown", artifact.getFile(), configuration );
+ domainModel = build( "unknown", artifact.getFile(), configuration );
}
catch (IOException e)
{
@@ -230,7 +229,7 @@
List<Profile> projectProfiles;
try
{
- projectProfiles = ProfileContext.getActiveProfilesFrom(configuration, domainModel.getModel(), container);
+ projectProfiles = DefaultProfileManager.getActiveProfilesFrom(configuration, domainModel.getModel(), container);
}
catch ( ProfileActivationException e )
{
@@ -414,7 +413,7 @@
return project;
}
- private PomClassicDomainModel buildWithoutProfiles( String projectId, File pomFile, ProjectBuilderConfiguration projectBuilderConfiguration )
+ private PomClassicDomainModel build( String projectId, File pomFile, ProjectBuilderConfiguration projectBuilderConfiguration )
throws ProjectBuildingException, IOException
{
List<String> activeProfileIds = ( projectBuilderConfiguration != null && projectBuilderConfiguration.getGlobalProfileManager() != null && projectBuilderConfiguration.getGlobalProfileManager()
@@ -424,7 +423,7 @@
.getGlobalProfileManager().getProfileActivationContext() != null ) ? projectBuilderConfiguration.getGlobalProfileManager().getProfileActivationContext().getExplicitlyInactiveProfileIds()
: new ArrayList<String>();
- ProfileContextInfo profileInfo = new ProfileContextInfo(null, activeProfileIds, inactiveProfileIds);
+ ProfileManagerInfo profileInfo = new ProfileManagerInfo(null, activeProfileIds, inactiveProfileIds);
PomClassicDomainModel domainModel = new PomClassicDomainModel( pomFile );
domainModel.setProjectDirectory( pomFile.getParentFile() );
domainModel.setMostSpecialized( true );
@@ -469,8 +468,7 @@
if(!dm.getModel().getProfiles().isEmpty())
{
- ProfileContext profileContext1 = new ProfileContext( dm.getModel().getProfiles(), profileInfo );
- Collection<Profile> profiles = profileContext1.getActiveProfiles();
+ Collection<Profile> profiles = DefaultProfileManager.getActiveProfiles(dm.getModel().getProfiles(), profileInfo);
if(!profiles.isEmpty())
{
profileModels.add(ProcessorContext.mergeProfilesIntoModel( profiles, dm ));