Refactor management of activated, deactivated, and default-activated profile ids, so the context tracks all of that stuff.

git-svn-id: https://svn.apache.org/repos/asf/maven/components/trunk@612186 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
John Dennis Casey 2008-01-15 18:34:58 +00:00
parent a35ec37b54
commit ca169d0262
34 changed files with 285 additions and 134 deletions

View File

@ -12,7 +12,6 @@ import org.apache.maven.execution.MavenExecutionRequest;
import org.apache.maven.execution.MavenExecutionResult;
import org.apache.maven.execution.MavenSession;
import org.apache.maven.extension.DefaultExtensionManager;
import org.apache.maven.execution.MavenRealmManager;
import org.apache.maven.artifact.Artifact;
import org.apache.maven.artifact.factory.ArtifactFactory;
import org.apache.maven.artifact.metadata.ResolutionGroup;
@ -33,6 +32,7 @@ import org.apache.maven.plugin.descriptor.PluginDescriptor;
import org.apache.maven.plugin.version.PluginVersionNotFoundException;
import org.apache.maven.plugin.version.PluginVersionResolutionException;
import org.apache.maven.project.MavenProject;
import org.apache.maven.realm.MavenRealmManager;
import org.apache.maven.settings.MavenSettingsBuilder;
import org.apache.maven.settings.DefaultMavenSettingsBuilder;
import org.apache.maven.settings.Settings;

View File

@ -8,7 +8,6 @@ import org.apache.maven.artifact.versioning.InvalidVersionSpecificationException
import org.apache.maven.artifact.Artifact;
import org.apache.maven.artifact.metadata.ArtifactMetadataRetrievalException;
import org.apache.maven.execution.MavenExecutionRequest;
import org.apache.maven.execution.RealmManagementException;
import org.apache.maven.plugin.PluginNotFoundException;
import org.apache.maven.plugin.version.PluginVersionNotFoundException;
import org.apache.maven.plugin.version.PluginVersionResolutionException;
@ -28,6 +27,7 @@ import org.apache.maven.extension.DefaultExtensionManager;
import org.apache.maven.model.Prerequisites;
import org.apache.maven.plugin.DefaultPluginManager;
import org.apache.maven.plugin.version.DefaultPluginVersionManager;
import org.apache.maven.realm.RealmManagementException;
import org.apache.maven.execution.RuntimeInformation;
import java.io.File;

View File

@ -12,7 +12,6 @@ import org.apache.maven.artifact.versioning.ArtifactVersion;
import org.apache.maven.artifact.versioning.InvalidVersionSpecificationException;
import org.apache.maven.execution.MavenExecutionRequest;
import org.apache.maven.execution.MavenSession;
import org.apache.maven.execution.RealmManagementException;
import org.apache.maven.extension.ExtensionManagerException;
import org.apache.maven.lifecycle.LifecycleException;
import org.apache.maven.lifecycle.LifecycleExecutionException;
@ -40,6 +39,7 @@ import org.apache.maven.project.error.ProjectErrorReporter;
import org.apache.maven.project.interpolation.ModelInterpolationException;
import org.apache.maven.project.path.PathTranslator;
import org.apache.maven.reactor.MavenExecutionException;
import org.apache.maven.realm.RealmManagementException;
import org.codehaus.plexus.component.configurator.expression.ExpressionEvaluationException;
import org.codehaus.plexus.component.repository.exception.ComponentLookupException;
import org.codehaus.plexus.configuration.PlexusConfiguration;

View File

@ -7,7 +7,6 @@ import org.apache.maven.artifact.resolver.AbstractArtifactResolutionException;
import org.apache.maven.artifact.resolver.ArtifactResolutionResult;
import org.apache.maven.artifact.versioning.ArtifactVersion;
import org.apache.maven.artifact.versioning.InvalidVersionSpecificationException;
import org.apache.maven.execution.RealmManagementException;
import org.apache.maven.lifecycle.LifecycleException;
import org.apache.maven.lifecycle.model.MojoBinding;
import org.apache.maven.model.Model;
@ -23,6 +22,7 @@ import org.apache.maven.plugin.version.PluginVersionResolutionException;
import org.apache.maven.project.MavenProject;
import org.apache.maven.project.artifact.InvalidDependencyVersionException;
import org.apache.maven.project.interpolation.ModelInterpolationException;
import org.apache.maven.realm.RealmManagementException;
import org.codehaus.plexus.component.repository.exception.ComponentLookupException;
import org.codehaus.plexus.configuration.PlexusConfiguration;

View File

@ -15,7 +15,6 @@ import org.apache.maven.artifact.versioning.ArtifactVersion;
import org.apache.maven.artifact.versioning.InvalidVersionSpecificationException;
import org.apache.maven.execution.MavenExecutionRequest;
import org.apache.maven.execution.MavenSession;
import org.apache.maven.execution.RealmManagementException;
import org.apache.maven.extension.ExtensionManagerException;
import org.apache.maven.lifecycle.LifecycleException;
import org.apache.maven.lifecycle.LifecycleExecutionException;
@ -48,6 +47,7 @@ import org.apache.maven.project.error.ProjectReporterManager;
import org.apache.maven.project.interpolation.ModelInterpolationException;
import org.apache.maven.project.path.PathTranslator;
import org.apache.maven.reactor.MavenExecutionException;
import org.apache.maven.realm.RealmManagementException;
import org.codehaus.plexus.component.configurator.expression.ExpressionEvaluationException;
import org.codehaus.plexus.component.repository.exception.ComponentLookupException;
import org.codehaus.plexus.configuration.PlexusConfiguration;

View File

@ -23,6 +23,8 @@ import org.apache.maven.artifact.repository.ArtifactRepository;
import org.apache.maven.errors.CoreErrorReporter;
import org.apache.maven.monitor.event.EventMonitor;
import org.apache.maven.profiles.ProfileManager;
import org.apache.maven.profiles.activation.ProfileActivationContext;
import org.apache.maven.realm.MavenRealmManager;
import org.apache.maven.settings.Settings;
import org.apache.maven.wagon.events.TransferListener;
@ -530,6 +532,8 @@ public class DefaultMavenExecutionRequest
private CoreErrorReporter errorReporter;
private ProfileActivationContext profileActivationContext;
public MavenExecutionRequest setSettings( Settings settings )
{
this.settings = settings;
@ -637,4 +641,15 @@ public class DefaultMavenExecutionRequest
errorReporter = reporter;
return this;
}
public ProfileActivationContext getProfileActivationContext()
{
return profileActivationContext;
}
public MavenExecutionRequest setProfileActivationContext( ProfileActivationContext profileActivationContext )
{
this.profileActivationContext = profileActivationContext;
return this;
}
}

View File

@ -24,6 +24,8 @@ import org.apache.maven.artifact.repository.ArtifactRepositoryPolicy;
import org.apache.maven.errors.CoreErrorReporter;
import org.apache.maven.monitor.event.EventMonitor;
import org.apache.maven.profiles.ProfileManager;
import org.apache.maven.profiles.activation.ProfileActivationContext;
import org.apache.maven.realm.MavenRealmManager;
import org.apache.maven.settings.Settings;
import org.apache.maven.wagon.events.TransferListener;
import org.codehaus.plexus.logging.Logger;
@ -192,6 +194,9 @@ public interface MavenExecutionRequest
ProfileManager getProfileManager();
MavenExecutionRequest setProfileManager( ProfileManager profileManager );
ProfileActivationContext getProfileActivationContext();
MavenExecutionRequest setProfileActivationContext( ProfileActivationContext profileActivationContext );
boolean isProjectPresent();
MavenExecutionRequest setProjectPresent( boolean isProjectPresent );

View File

@ -24,6 +24,7 @@ import org.apache.maven.monitor.event.EventDispatcher;
import org.apache.maven.plugin.descriptor.MojoDescriptor;
import org.apache.maven.plugin.descriptor.PluginDescriptor;
import org.apache.maven.project.MavenProject;
import org.apache.maven.realm.MavenRealmManager;
import org.apache.maven.reporting.MavenReport;
import org.apache.maven.settings.Settings;
import org.codehaus.plexus.PlexusContainer;

View File

@ -38,10 +38,7 @@ import org.apache.maven.artifact.versioning.DefaultArtifactVersion;
import org.apache.maven.artifact.versioning.InvalidVersionSpecificationException;
import org.apache.maven.artifact.versioning.VersionRange;
import org.apache.maven.execution.MavenExecutionRequest;
import org.apache.maven.execution.MavenRealmManager;
import org.apache.maven.execution.MavenSession;
import org.apache.maven.execution.RealmManagementException;
import org.apache.maven.execution.RealmUtils;
import org.apache.maven.model.Extension;
import org.apache.maven.model.Model;
import org.apache.maven.model.Parent;
@ -56,6 +53,9 @@ import org.apache.maven.plugin.descriptor.PluginDescriptor;
import org.apache.maven.plugin.version.PluginVersionNotFoundException;
import org.apache.maven.plugin.version.PluginVersionResolutionException;
import org.apache.maven.project.MavenProject;
import org.apache.maven.realm.MavenRealmManager;
import org.apache.maven.realm.RealmManagementException;
import org.apache.maven.realm.RealmUtils;
import org.codehaus.plexus.MutablePlexusContainer;
import org.codehaus.plexus.PlexusConstants;
import org.codehaus.plexus.context.Context;

View File

@ -5,12 +5,12 @@ import org.apache.maven.artifact.metadata.ArtifactMetadataRetrievalException;
import org.apache.maven.artifact.resolver.ArtifactNotFoundException;
import org.apache.maven.artifact.resolver.ArtifactResolutionException;
import org.apache.maven.artifact.resolver.ArtifactResolutionResult;
import org.apache.maven.execution.RealmManagementException;
import org.apache.maven.plugin.InvalidPluginException;
import org.apache.maven.plugin.PluginManagerException;
import org.apache.maven.plugin.PluginNotFoundException;
import org.apache.maven.plugin.version.PluginVersionNotFoundException;
import org.apache.maven.plugin.version.PluginVersionResolutionException;
import org.apache.maven.realm.RealmManagementException;
public class ExtensionManagerException
extends Exception

View File

@ -35,9 +35,7 @@ import org.apache.maven.artifact.resolver.filter.ScopeArtifactFilter;
import org.apache.maven.artifact.versioning.DefaultArtifactVersion;
import org.apache.maven.artifact.versioning.InvalidVersionSpecificationException;
import org.apache.maven.artifact.versioning.VersionRange;
import org.apache.maven.execution.MavenRealmManager;
import org.apache.maven.execution.MavenSession;
import org.apache.maven.execution.RealmManagementException;
import org.apache.maven.execution.RuntimeInformation;
import org.apache.maven.lifecycle.statemgmt.StateManagementUtils;
import org.apache.maven.model.Plugin;
@ -59,6 +57,8 @@ import org.apache.maven.project.ProjectBuildingException;
import org.apache.maven.project.artifact.InvalidDependencyVersionException;
import org.apache.maven.project.artifact.MavenMetadataSource;
import org.apache.maven.project.path.PathTranslator;
import org.apache.maven.realm.MavenRealmManager;
import org.apache.maven.realm.RealmManagementException;
import org.apache.maven.reporting.MavenReport;
import org.codehaus.plexus.MutablePlexusContainer;
import org.codehaus.plexus.PlexusConstants;

View File

@ -1,8 +1,8 @@
package org.apache.maven.plugin;
import org.apache.maven.execution.RealmManagementException;
import org.apache.maven.model.Plugin;
import org.apache.maven.plugin.descriptor.MojoDescriptor;
import org.apache.maven.realm.RealmManagementException;
import org.codehaus.plexus.classworlds.realm.ClassRealm;
import org.codehaus.plexus.component.repository.exception.ComponentLookupException;
import org.codehaus.plexus.component.repository.exception.ComponentRepositoryException;

View File

@ -1,11 +1,11 @@
package org.apache.maven.plugin;
import org.apache.maven.artifact.versioning.InvalidVersionSpecificationException;
import org.apache.maven.execution.RealmManagementException;
import org.apache.maven.model.Plugin;
import org.apache.maven.plugin.descriptor.MojoDescriptor;
import org.apache.maven.plugin.descriptor.PluginDescriptor;
import org.apache.maven.project.MavenProject;
import org.apache.maven.realm.RealmManagementException;
import org.codehaus.plexus.PlexusContainerException;
import org.codehaus.plexus.classworlds.realm.NoSuchRealmException;
import org.codehaus.plexus.component.repository.exception.ComponentRepositoryException;

View File

@ -2,6 +2,7 @@ package org.apache.maven.execution;
import org.apache.maven.artifact.Artifact;
import org.apache.maven.artifact.factory.ArtifactFactory;
import org.apache.maven.realm.DefaultMavenRealmManager;
import org.codehaus.plexus.PlexusTestCase;
import org.codehaus.plexus.logging.Logger;
import org.codehaus.plexus.logging.console.ConsoleLogger;

View File

@ -11,13 +11,13 @@ import org.apache.maven.artifact.repository.DefaultArtifactRepository;
import org.apache.maven.artifact.repository.layout.DefaultRepositoryLayout;
import org.apache.maven.artifact.resolver.ArtifactResolver;
import org.apache.maven.execution.DefaultMavenExecutionRequest;
import org.apache.maven.execution.DefaultMavenRealmManager;
import org.apache.maven.execution.MavenExecutionRequest;
import org.apache.maven.execution.MavenRealmManager;
import org.apache.maven.lifecycle.mapping.LifecycleMapping;
import org.apache.maven.model.Build;
import org.apache.maven.model.Extension;
import org.apache.maven.model.Model;
import org.apache.maven.realm.DefaultMavenRealmManager;
import org.apache.maven.realm.MavenRealmManager;
import org.codehaus.plexus.MutablePlexusContainer;
import org.codehaus.plexus.PlexusTestCase;
import org.codehaus.plexus.classworlds.realm.ClassRealm;

View File

@ -2,9 +2,7 @@ package org.apache.maven.lifecycle.binding;
import org.apache.maven.artifact.Artifact;
import org.apache.maven.execution.DefaultMavenExecutionRequest;
import org.apache.maven.execution.DefaultMavenRealmManager;
import org.apache.maven.execution.MavenExecutionRequest;
import org.apache.maven.execution.MavenRealmManager;
import org.apache.maven.execution.MavenSession;
import org.apache.maven.lifecycle.LifecycleLoaderException;
import org.apache.maven.lifecycle.LifecycleSpecificationException;
@ -18,6 +16,8 @@ import org.apache.maven.model.Plugin;
import org.apache.maven.model.PluginExecution;
import org.apache.maven.model.PluginManagement;
import org.apache.maven.project.MavenProject;
import org.apache.maven.realm.DefaultMavenRealmManager;
import org.apache.maven.realm.MavenRealmManager;
import org.apache.maven.shared.tools.easymock.MockManager;
import org.codehaus.plexus.PlexusTestCase;
import org.codehaus.plexus.logging.Logger;

View File

@ -2,9 +2,7 @@ package org.apache.maven.lifecycle.plan;
import org.apache.maven.artifact.Artifact;
import org.apache.maven.execution.DefaultMavenExecutionRequest;
import org.apache.maven.execution.DefaultMavenRealmManager;
import org.apache.maven.execution.MavenExecutionRequest;
import org.apache.maven.execution.MavenRealmManager;
import org.apache.maven.execution.MavenSession;
import org.apache.maven.lifecycle.MojoBindingUtils;
import org.apache.maven.lifecycle.model.MojoBinding;
@ -17,6 +15,8 @@ import org.apache.maven.plugin.descriptor.MojoDescriptor;
import org.apache.maven.plugin.descriptor.PluginDescriptor;
import org.apache.maven.plugin.loader.PluginLoader;
import org.apache.maven.project.MavenProject;
import org.apache.maven.realm.DefaultMavenRealmManager;
import org.apache.maven.realm.MavenRealmManager;
import org.apache.maven.shared.tools.easymock.MockManager;
import org.codehaus.plexus.PlexusTestCase;
import org.codehaus.plexus.logging.Logger;

View File

@ -19,7 +19,7 @@ package org.apache.maven.embedder;
*/
import org.apache.maven.errors.CoreErrorReporter;
import org.apache.maven.execution.MavenRealmManager;
import org.apache.maven.realm.MavenRealmManager;
import org.codehaus.plexus.PlexusContainer;
import org.codehaus.plexus.classworlds.ClassWorld;

View File

@ -19,7 +19,7 @@ package org.apache.maven.embedder;
*/
import org.apache.maven.errors.CoreErrorReporter;
import org.apache.maven.execution.MavenRealmManager;
import org.apache.maven.realm.MavenRealmManager;
import org.codehaus.plexus.PlexusContainer;
import org.codehaus.plexus.classworlds.ClassWorld;

View File

@ -29,7 +29,6 @@ import org.apache.maven.embedder.Configuration;
import org.apache.maven.embedder.MavenEmbedder;
import org.apache.maven.embedder.MavenEmbedderException;
import org.apache.maven.errors.DefaultCoreErrorReporter;
import org.apache.maven.execution.DefaultMavenRealmManager;
import org.apache.maven.execution.MavenExecutionRequest;
import org.apache.maven.model.Profile;
import org.apache.maven.model.Repository;
@ -39,6 +38,7 @@ import org.apache.maven.profiles.DefaultProfileManager;
import org.apache.maven.profiles.ProfileManager;
import org.apache.maven.profiles.activation.DefaultProfileActivationContext;
import org.apache.maven.profiles.activation.ProfileActivationContext;
import org.apache.maven.realm.DefaultMavenRealmManager;
import org.apache.maven.settings.MavenSettingsBuilder;
import org.apache.maven.settings.Mirror;
import org.apache.maven.settings.Proxy;
@ -119,12 +119,12 @@ public class DefaultMavenExecutionRequestPopulator
eventing( request, configuration );
realmManager( request, configuration );
profileManager( request, configuration );
processSettings( request, configuration );
realmManager( request, configuration );
return request;
}
@ -655,14 +655,20 @@ public class DefaultMavenExecutionRequestPopulator
//
// ------------------------------------------------------------------------
ProfileActivationContext activationContext = new DefaultProfileActivationContext( request.getProperties(), false );
ProfileActivationContext activationContext = request.getProfileActivationContext();
if ( activationContext == null )
{
activationContext = new DefaultProfileActivationContext( request.getRealmManager(),
request.getProperties(), false );
}
activationContext.setExplicitlyActiveProfileIds( request.getActiveProfiles() );
activationContext.setExplicitlyInactiveProfileIds( request.getInactiveProfiles() );
ProfileManager globalProfileManager = new DefaultProfileManager( container, activationContext );
globalProfileManager.explicitlyActivate( request.getActiveProfiles() );
globalProfileManager.explicitlyDeactivate( request.getInactiveProfiles() );
request.setProfileManager( globalProfileManager );
request.setProfileActivationContext( activationContext );
}
// ----------------------------------------------------------------------------

View File

@ -15,7 +15,6 @@ import org.apache.maven.artifact.versioning.InvalidVersionSpecificationException
import org.apache.maven.errors.DefaultCoreErrorReporter;
import org.apache.maven.execution.MavenExecutionRequest;
import org.apache.maven.execution.MavenSession;
import org.apache.maven.execution.RealmManagementException;
import org.apache.maven.extension.ExtensionManagerException;
import org.apache.maven.lifecycle.LifecycleException;
import org.apache.maven.lifecycle.LifecycleExecutionException;
@ -54,6 +53,7 @@ import org.apache.maven.project.build.model.ModelAndFile;
import org.apache.maven.project.interpolation.ModelInterpolationException;
import org.apache.maven.project.path.PathTranslator;
import org.apache.maven.reactor.MavenExecutionException;
import org.apache.maven.realm.RealmManagementException;
import org.codehaus.plexus.component.configurator.expression.ExpressionEvaluationException;
import org.codehaus.plexus.component.repository.exception.ComponentLookupException;
import org.codehaus.plexus.configuration.PlexusConfiguration;

View File

@ -25,9 +25,12 @@ import org.apache.maven.profiles.activation.DefaultProfileActivationContext;
import org.apache.maven.profiles.activation.ProfileActivationContext;
import org.apache.maven.profiles.activation.ProfileActivationException;
import org.apache.maven.profiles.activation.ProfileActivator;
import org.apache.maven.realm.DefaultMavenRealmManager;
import org.apache.maven.realm.MavenRealmManager;
import org.codehaus.plexus.PlexusContainer;
import org.codehaus.plexus.component.repository.exception.ComponentLifecycleException;
import org.codehaus.plexus.component.repository.exception.ComponentLookupException;
import org.codehaus.plexus.logging.Logger;
import java.util.ArrayList;
import java.util.Iterator;
@ -41,12 +44,6 @@ public class DefaultProfileManager
{
private PlexusContainer container;
private List activatedIds = new ArrayList();
private List deactivatedIds = new ArrayList();
private List defaultIds = new ArrayList();
private Map profilesById = new LinkedHashMap();
private ProfileActivationContext profileActivationContext;
@ -63,10 +60,18 @@ public class DefaultProfileManager
}
// TODO: Remove this, if possible. It uses system properties, which are not safe for IDE and other embedded environments.
/**
* @deprecated Using this is dangerous when extensions or non-global system properties are in play.
*/
public DefaultProfileManager( PlexusContainer container )
{
this.container = container;
profileActivationContext = new DefaultProfileActivationContext( System.getProperties(), false );
// create the necessary bits to get a skeletal profile manager running.
Logger logger = container.getLoggerManager().getLoggerForComponent( DefaultProfileManager.class.getName() );
MavenRealmManager manager = new DefaultMavenRealmManager( container, logger );
profileActivationContext = new DefaultProfileActivationContext( manager, System.getProperties(), false );
}
public ProfileActivationContext getProfileActivationContext()
@ -113,11 +118,12 @@ public class DefaultProfileManager
*/
public void explicitlyActivate( String profileId )
{
List activatedIds = profileActivationContext.getExplicitlyActiveProfileIds();
if ( !activatedIds.contains( profileId ) )
{
container.getLogger().debug( "Profile with id: \'" + profileId + "\' has been explicitly activated." );
activatedIds.add( profileId );
profileActivationContext.setActive( profileId );
}
}
@ -139,11 +145,12 @@ public class DefaultProfileManager
*/
public void explicitlyDeactivate( String profileId )
{
List deactivatedIds = profileActivationContext.getExplicitlyInactiveProfileIds();
if ( !deactivatedIds.contains( profileId ) )
{
container.getLogger().debug( "Profile with id: \'" + profileId + "\' has been explicitly deactivated." );
deactivatedIds.add( profileId );
profileActivationContext.setInactive( profileId );
}
}
@ -177,11 +184,11 @@ public class DefaultProfileManager
Profile profile = (Profile) entry.getValue();
boolean shouldAdd = false;
if ( activatedIds.contains( profileId ) )
if ( profileActivationContext.isExplicitlyActive( profileId ) )
{
shouldAdd = true;
}
else if ( !deactivatedIds.contains( profileId ) && isActive( profile, profileActivationContext ) )
else if ( !profileActivationContext.isExplicitlyInactive( profileId ) && isActive( profile, profileActivationContext ) )
{
shouldAdd = true;
}
@ -201,13 +208,18 @@ public class DefaultProfileManager
if ( activeFromPom.isEmpty() )
{
List defaultIds = profileActivationContext.getActiveByDefaultProfileIds();
for ( Iterator it = defaultIds.iterator(); it.hasNext(); )
{
String profileId = (String) it.next();
Profile profile = (Profile) profilesById.get( profileId );
activeFromPom.add( profile );
if ( profile != null )
{
activeFromPom.add( profile );
}
}
}
@ -283,24 +295,26 @@ public class DefaultProfileManager
public void activateAsDefault( String profileId )
{
List defaultIds = profileActivationContext.getActiveByDefaultProfileIds();
if ( !defaultIds.contains( profileId ) )
{
defaultIds.add( profileId );
profileActivationContext.setActiveByDefault( profileId );
}
}
public List getExplicitlyActivatedIds()
{
return activatedIds;
return profileActivationContext.getExplicitlyActiveProfileIds();
}
public List getExplicitlyDeactivatedIds()
{
return deactivatedIds;
return profileActivationContext.getExplicitlyInactiveProfileIds();
}
public List getIdsActivatedByDefault()
{
return defaultIds;
return profileActivationContext.getActiveByDefaultProfileIds();
}
}

View File

@ -30,14 +30,29 @@ public interface ProfileManager
{
void addProfile( Profile profile );
/**
* @deprecated Use {@link ProfileActivationContext} methods instead.
*/
void explicitlyActivate( String profileId );
/**
* @deprecated Use {@link ProfileActivationContext} methods instead.
*/
void explicitlyActivate( List profileIds );
/**
* @deprecated Use {@link ProfileActivationContext} methods instead.
*/
void explicitlyDeactivate( String profileId );
/**
* @deprecated Use {@link ProfileActivationContext} methods instead.
*/
void explicitlyDeactivate( List profileIds );
/**
* @deprecated Use {@link ProfileActivationContext} methods instead.
*/
void activateAsDefault( String profileId );
ProfileActivationContext getProfileActivationContext();
@ -51,9 +66,18 @@ public interface ProfileManager
Map getProfilesById();
/**
* @deprecated Use {@link ProfileActivationContext} methods instead.
*/
List getExplicitlyActivatedIds();
/**
* @deprecated Use {@link ProfileActivationContext} methods instead.
*/
List getExplicitlyDeactivatedIds();
/**
* @deprecated Use {@link ProfileActivationContext} methods instead.
*/
List getIdsActivatedByDefault();
}

View File

@ -1,5 +1,10 @@
package org.apache.maven.profiles.activation;
import org.apache.maven.realm.MavenRealmManager;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Properties;
public class DefaultProfileActivationContext
@ -8,12 +13,23 @@ public class DefaultProfileActivationContext
private boolean isCustomActivatorFailureSuppressed;
private final Properties executionProperties;
List explicitlyActive;
List explicitlyInactive;
private final MavenRealmManager realmManager;
private List activeByDefault;
public DefaultProfileActivationContext( MavenRealmManager realmManager, Properties executionProperties, boolean isCustomActivatorFailureSuppressed )
{
this.realmManager = realmManager;
this.executionProperties = executionProperties;
this.isCustomActivatorFailureSuppressed = isCustomActivatorFailureSuppressed;
}
public DefaultProfileActivationContext( Properties executionProperties, boolean isCustomActivatorFailureSuppressed )
{
realmManager = null;
this.executionProperties = executionProperties;
this.isCustomActivatorFailureSuppressed = isCustomActivatorFailureSuppressed;
}
public Properties getExecutionProperties()
@ -31,4 +47,99 @@ public class DefaultProfileActivationContext
isCustomActivatorFailureSuppressed = suppressed;
}
public List getExplicitlyActiveProfileIds()
{
if ( explicitlyActive == null )
{
return Collections.EMPTY_LIST;
}
return explicitlyActive;
}
public void setExplicitlyActiveProfileIds( List active )
{
explicitlyActive = active;
}
public List getExplicitlyInactiveProfileIds()
{
if ( explicitlyInactive == null )
{
return Collections.EMPTY_LIST;
}
return explicitlyInactive;
}
public void setExplicitlyInactiveProfileIds( List inactive )
{
explicitlyInactive = inactive;
}
public MavenRealmManager getRealmManager()
{
return realmManager;
}
public void setActive( String profileId )
{
if ( explicitlyActive == null )
{
explicitlyActive = new ArrayList();
}
explicitlyActive.add( profileId );
}
public void setInactive( String profileId )
{
if ( explicitlyInactive == null )
{
explicitlyInactive = new ArrayList();
}
explicitlyInactive.add( profileId );
}
public boolean isExplicitlyActive( String profileId )
{
return ( explicitlyActive != null ) && explicitlyActive.contains( profileId );
}
public boolean isExplicitlyInactive( String profileId )
{
return ( explicitlyInactive != null ) && explicitlyInactive.contains( profileId );
}
public List getActiveByDefaultProfileIds()
{
if ( activeByDefault == null )
{
return Collections.EMPTY_LIST;
}
return activeByDefault;
}
public boolean isActiveByDefault( String profileId )
{
return ( activeByDefault != null ) && activeByDefault.contains( profileId );
}
public void setActiveByDefault( String profileId )
{
if ( activeByDefault == null )
{
activeByDefault = new ArrayList();
}
activeByDefault.add( profileId );
}
public void setActiveByDefaultProfileIds( List activeByDefault )
{
this.activeByDefault = activeByDefault;
}
}

View File

@ -1,14 +1,43 @@
package org.apache.maven.profiles.activation;
import org.apache.maven.realm.MavenRealmManager;
import java.util.List;
import java.util.Properties;
public interface ProfileActivationContext
{
List getExplicitlyActiveProfileIds();
List getExplicitlyInactiveProfileIds();
MavenRealmManager getRealmManager();
Properties getExecutionProperties();
boolean isCustomActivatorFailureSuppressed();
void setCustomActivatorFailureSuppressed( boolean suppressed );
void setExplicitlyActiveProfileIds( List inactive );
void setExplicitlyInactiveProfileIds( List inactive );
void setActive( String profileId );
void setInactive( String profileId );
boolean isExplicitlyActive( String profileId );
boolean isExplicitlyInactive( String profileId );
List getActiveByDefaultProfileIds();
void setActiveByDefaultProfileIds( List activeByDefault );
void setActiveByDefault( String profileId );
boolean isActiveByDefault( String profileId );
}

View File

@ -69,8 +69,6 @@ public class DefaultProfileAdvisor
public List applyActivatedProfiles( Model model,
File pomFile,
List explicitlyActiveIds,
List explicitlyInactiveIds,
boolean useProfilesXml,
ProfileActivationContext activationContext )
throws ProjectBuildingException
@ -79,8 +77,6 @@ public class DefaultProfileAdvisor
+ pomFile );
ProfileManager profileManager = buildProfileManager( model,
pomFile,
explicitlyActiveIds,
explicitlyInactiveIds,
useProfilesXml,
activationContext );
@ -152,18 +148,12 @@ public class DefaultProfileAdvisor
private ProfileManager buildProfileManager( Model model,
File pomFile,
List explicitlyActiveIds,
List explicitlyInactiveIds,
boolean useProfilesXml,
ProfileActivationContext profileActivationContext )
throws ProjectBuildingException
{
ProfileManager profileManager = new DefaultProfileManager( container, profileActivationContext );
profileManager.explicitlyActivate( explicitlyActiveIds );
profileManager.explicitlyDeactivate( explicitlyInactiveIds );
profileManager.addProfiles( model.getProfiles() );
if ( useProfilesXml && ( pomFile != null ) )
@ -204,22 +194,24 @@ public class DefaultProfileAdvisor
for ( Iterator i = activeExternalProfiles.iterator(); i.hasNext(); )
{
Profile externalProfile = (Profile) i.next();
for ( Iterator repoIterator = externalProfile.getRepositories().iterator(); repoIterator.hasNext(); )
if ( externalProfile.getRepositories() != null )
{
Repository mavenRepo = (Repository) repoIterator.next();
ArtifactRepository artifactRepo;
try
for ( Iterator repoIterator = externalProfile.getRepositories().iterator(); repoIterator.hasNext(); )
{
artifactRepo = mavenTools.buildArtifactRepository( mavenRepo );
}
catch ( InvalidRepositoryException e )
{
throw new ProjectBuildingException( modelId, e.getMessage(), e );
}
Repository mavenRepo = (Repository) repoIterator.next();
remoteRepositories.add( artifactRepo );
ArtifactRepository artifactRepo;
try
{
artifactRepo = mavenTools.buildArtifactRepository( mavenRepo );
}
catch ( InvalidRepositoryException e )
{
throw new ProjectBuildingException( modelId, e.getMessage(), e );
}
remoteRepositories.add( artifactRepo );
}
}
}
@ -229,16 +221,12 @@ public class DefaultProfileAdvisor
public LinkedHashSet getArtifactRepositoriesFromActiveProfiles( Model model,
File pomFile,
List explicitlyActiveIds,
List explicitlyInactiveIds,
boolean useProfilesXml,
ProfileActivationContext activationContext )
throws ProjectBuildingException
{
ProfileManager profileManager = buildProfileManager( model,
pomFile,
explicitlyActiveIds,
explicitlyInactiveIds,
useProfilesXml,
activationContext );
@ -263,7 +251,8 @@ public class DefaultProfileAdvisor
if ( ( active != null ) && !active.isEmpty() )
{
profileManager.explicitlyActivate( root.getActiveProfiles() );
ProfileActivationContext ctx = profileManager.getProfileActivationContext();
ctx.setExplicitlyActiveProfileIds( root.getActiveProfiles() );
}
for ( Iterator it = root.getProfiles().iterator(); it.hasNext(); )

View File

@ -45,16 +45,12 @@ public interface ProfileAdvisor
LinkedHashSet getArtifactRepositoriesFromActiveProfiles( Model model,
File pomFile,
List explicitlyActiveIds,
List explicitlyInactiveIds,
boolean useProfilesXml,
ProfileActivationContext profileActivationContext )
throws ProjectBuildingException;
List applyActivatedProfiles( Model model,
File pomFile,
List explicitlyActiveIds,
List explicitlyInactiveIds,
boolean useProfilesXml,
ProfileActivationContext activationContext )
throws ProjectBuildingException;

View File

@ -570,10 +570,6 @@ public class DefaultMavenProjectBuilder
String projectId = safeVersionlessKey( model.getGroupId(), model.getArtifactId() );
List explicitlyActive;
List explicitlyInactive;
// FIXME: Find a way to pass in this context, so it's never null!
ProfileActivationContext profileActivationContext;
@ -589,18 +585,10 @@ public class DefaultMavenProjectBuilder
throw new ProjectBuildingException( projectId, "Failed to activate external profiles.", projectDescriptor, e );
}
explicitlyActive = externalProfileManager.getExplicitlyActivatedIds();
explicitlyInactive = externalProfileManager.getExplicitlyDeactivatedIds();
profileActivationContext = externalProfileManager.getProfileActivationContext();
}
else
{
explicitlyActive = Collections.EMPTY_LIST;
explicitlyInactive = Collections.EMPTY_LIST;
profileActivationContext = new DefaultProfileActivationContext( System.getProperties(), false );
}
@ -611,7 +599,7 @@ public class DefaultMavenProjectBuilder
activeInSuperPom.addAll( activated );
}
activated = profileAdvisor.applyActivatedProfiles( superModel, projectDescriptor, explicitlyActive, explicitlyInactive, validProfilesXmlLocation, profileActivationContext );
activated = profileAdvisor.applyActivatedProfiles( superModel, projectDescriptor, validProfilesXmlLocation, profileActivationContext );
if ( !activated.isEmpty() )
{
activeInSuperPom.addAll( activated );
@ -624,8 +612,7 @@ public class DefaultMavenProjectBuilder
LinkedHashSet aggregatedRemoteWagonRepositories = collectInitialRepositories( model, superModel,
parentSearchRepositories,
projectDescriptor, explicitlyActive,
explicitlyInactive,
projectDescriptor,
validProfilesXmlLocation,
profileActivationContext );
@ -741,17 +728,15 @@ public class DefaultMavenProjectBuilder
Model superModel,
List parentSearchRepositories,
File pomFile,
List explicitlyActive,
List explicitlyInactive,
boolean validProfilesXmlLocation,
ProfileActivationContext profileActivationContext )
throws ProjectBuildingException
{
LinkedHashSet collected = new LinkedHashSet();
collectInitialRepositoriesFromModel( collected, model, pomFile, explicitlyActive, explicitlyInactive, validProfilesXmlLocation, profileActivationContext );
collectInitialRepositoriesFromModel( collected, model, pomFile, validProfilesXmlLocation, profileActivationContext );
collectInitialRepositoriesFromModel( collected, superModel, null, explicitlyActive, explicitlyInactive, validProfilesXmlLocation, profileActivationContext );
collectInitialRepositoriesFromModel( collected, superModel, null, validProfilesXmlLocation, profileActivationContext );
if ( ( parentSearchRepositories != null ) && !parentSearchRepositories.isEmpty() )
{
@ -764,13 +749,11 @@ public class DefaultMavenProjectBuilder
private void collectInitialRepositoriesFromModel( LinkedHashSet collected,
Model model,
File pomFile,
List explicitlyActive,
List explicitlyInactive,
boolean validProfilesXmlLocation,
ProfileActivationContext profileActivationContext )
throws ProjectBuildingException
{
Set reposFromProfiles = profileAdvisor.getArtifactRepositoriesFromActiveProfiles( model, pomFile, explicitlyActive, explicitlyInactive, validProfilesXmlLocation, profileActivationContext );
Set reposFromProfiles = profileAdvisor.getArtifactRepositoriesFromActiveProfiles( model, pomFile, validProfilesXmlLocation, profileActivationContext );
if ( ( reposFromProfiles != null ) && !reposFromProfiles.isEmpty() )
{
@ -974,25 +957,15 @@ public class DefaultMavenProjectBuilder
modelLineageBuilder.resumeBuildingModelLineage( modelLineage, localRepository, externalProfileManager, !strict );
List explicitlyActive;
List explicitlyInactive;
// FIXME: Find a way to pass in this context, so it's never null!
ProfileActivationContext profileActivationContext;
if ( externalProfileManager != null )
{
explicitlyActive = externalProfileManager.getExplicitlyActivatedIds();
explicitlyInactive = externalProfileManager.getExplicitlyDeactivatedIds();
profileActivationContext = externalProfileManager.getProfileActivationContext();
}
else
{
explicitlyActive = Collections.EMPTY_LIST;
explicitlyInactive = Collections.EMPTY_LIST;
profileActivationContext = new DefaultProfileActivationContext( System.getProperties(), false );
}
@ -1017,8 +990,7 @@ public class DefaultMavenProjectBuilder
// NOTE: the caching aspect may replace the parent project instance, so we apply profiles here.
// TODO: Review this...is that a good idea, to allow application of profiles when other profiles could have been applied already?
project.setActiveProfiles( profileAdvisor.applyActivatedProfiles( project.getModel(), project.getFile(), explicitlyActive,
explicitlyInactive, validProfilesXmlLocation, profileActivationContext ) );
project.setActiveProfiles( profileAdvisor.applyActivatedProfiles( project.getModel(), project.getFile(), validProfilesXmlLocation, profileActivationContext ) );
lineage.addFirst( project );

View File

@ -47,7 +47,6 @@ import java.io.File;
import java.io.IOException;
import java.io.Reader;
import java.util.ArrayList;
import java.util.Collections;
import java.util.LinkedHashSet;
import java.util.List;
import java.util.Set;
@ -280,22 +279,15 @@ public class DefaultModelLineageBuilder
{
getLogger().debug( "Grabbing profile-injected repositories for: " + model.getId() );
List explicitlyActive;
List explicitlyInactive;
// FIXME: Find a way to pass in this context, so it's never null!
ProfileActivationContext context;
if ( profileManager != null )
{
explicitlyActive = profileManager.getExplicitlyActivatedIds();
explicitlyInactive = profileManager.getExplicitlyDeactivatedIds();
context = profileManager.getProfileActivationContext();
}
else
{
explicitlyActive = Collections.EMPTY_LIST;
explicitlyInactive = Collections.EMPTY_LIST;
context = new DefaultProfileActivationContext( System.getProperties(), false );
}
@ -307,8 +299,6 @@ public class DefaultModelLineageBuilder
LinkedHashSet pomProfileRepos = profileAdvisor.getArtifactRepositoriesFromActiveProfiles( model,
pomFile,
explicitlyActive,
explicitlyInactive,
useProfilesXml,
context );

View File

@ -1,4 +1,4 @@
package org.apache.maven.execution;
package org.apache.maven.realm;
/*
* Licensed to the Apache Software Foundation (ASF) under one
@ -54,7 +54,7 @@ public class DefaultMavenRealmManager
private Map pluginArtifacts = new HashMap();
private Set managedRealmIds = new HashSet();
private final ClassWorld world;
private final PlexusContainer container;
private final Logger logger;
@ -66,10 +66,10 @@ public class DefaultMavenRealmManager
this.container = container;
this.logger = logger;
}
//mkleint: the clearing is fine for sequenced operations. Even though the
//mkleint: the clearing is fine for sequenced operations. Even though the
// MavenRealmManager is associated with request, the paralel execution will
// eventualy fail as the ClassWorld and PlexusContainer are not meant for
// eventualy fail as the ClassWorld and PlexusContainer are not meant for
// multithreaded environment.
public void clear()
{

View File

@ -1,4 +1,4 @@
package org.apache.maven.execution;
package org.apache.maven.realm;
import org.apache.maven.artifact.Artifact;
import org.apache.maven.model.Plugin;

View File

@ -1,4 +1,4 @@
package org.apache.maven.execution;
package org.apache.maven.realm;
import org.apache.maven.artifact.Artifact;
import org.codehaus.plexus.classworlds.realm.DuplicateRealmException;

View File

@ -1,4 +1,4 @@
package org.apache.maven.execution;
package org.apache.maven.realm;
/*
* Licensed to the Apache Software Foundation (ASF) under one

View File

@ -104,19 +104,17 @@ under the License.
-->
<component>
<role>org.apache.maven.project.MavenProjectBuilder</role>
<role-hint>default</role-hint>
<implementation>org.apache.maven.project.DefaultMavenProjectBuilder</implementation>
<requirements>
<requirement>
<role>org.apache.maven.artifact.metadata.ArtifactMetadataSource</role>
<role-hint>default</role-hint>
</requirement>
<requirement>
<role>org.apache.maven.project.build.model.ModelLineageBuilder</role>
<role-hint>default</role-hint>
</requirement>
<requirement>
<role>org.apache.maven.profiles.build.ProfileAdvisor</role>
<role-hint>default</role-hint>
</requirement>
<requirement>
<role>org.apache.maven.profiles.MavenProfilesBuilder</role>