merge from branch rev.379473

git-svn-id: https://svn.apache.org/repos/asf/maven/components/trunk@379481 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Emmanuel Venisse 2006-02-21 15:08:26 +00:00
parent 17302c0e24
commit 8a630687b7
2 changed files with 86 additions and 44 deletions

View File

@ -22,6 +22,11 @@
<artifactId>maven-profile</artifactId>
<version>2.1-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>org.apache.maven</groupId>
<artifactId>maven-settings</artifactId>
<version>2.0.3-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>org.apache.maven</groupId>
<artifactId>maven-model</artifactId>

View File

@ -4,6 +4,8 @@ import org.apache.maven.model.Activation;
import org.apache.maven.model.Profile;
import org.apache.maven.profiles.activation.ProfileActivationException;
import org.apache.maven.profiles.activation.ProfileActivator;
import org.apache.maven.settings.Settings;
import org.apache.maven.settings.SettingsUtils;
import org.codehaus.plexus.PlexusContainer;
import org.codehaus.plexus.component.repository.exception.ComponentLifecycleException;
import org.codehaus.plexus.component.repository.exception.ComponentLookupException;
@ -31,54 +33,63 @@ import java.util.Map.Entry;
* limitations under the License.
*/
public class DefaultProfileManager implements ProfileManager
public class DefaultProfileManager
implements ProfileManager
{
private PlexusContainer container;
private List activatedIds = new ArrayList();
private List deactivatedIds = new ArrayList();
private List defaultIds = new ArrayList();
private Map profilesById = new HashMap();
public DefaultProfileManager( PlexusContainer container )
{
this.container = container;
this( container, null );
}
public DefaultProfileManager( PlexusContainer container, Settings settings )
{
this.container = container;
loadSettingsProfiles( settings );
}
public Map getProfilesById()
{
return profilesById;
}
/* (non-Javadoc)
* @see org.apache.maven.profiles.ProfileManager#addProfile(org.apache.maven.model.Profile)
*/
* @see org.apache.maven.profiles.ProfileManager#addProfile(org.apache.maven.model.Profile)
*/
public void addProfile( Profile profile )
{
String profileId = profile.getId();
Profile existing = (Profile) profilesById.get( profileId );
if ( existing != null )
{
container.getLogger().warn(
"Overriding profile: \'" + profileId + "\' (source: " + existing.getSource()
+ ") with new instance from source: " + profile.getSource() );
container.getLogger().warn( "Overriding profile: \'" + profileId + "\' (source: " + existing.getSource() +
") with new instance from source: " + profile.getSource() );
}
profilesById.put( profile.getId(), profile );
Activation activation = profile.getActivation();
if ( activation != null && activation.isActiveByDefault() )
{
activateAsDefault( profileId );
}
}
/* (non-Javadoc)
* @see org.apache.maven.profiles.ProfileManager#explicitlyActivate(java.lang.String)
*/
* @see org.apache.maven.profiles.ProfileManager#explicitlyActivate(java.lang.String)
*/
public void explicitlyActivate( String profileId )
{
if ( !activatedIds.contains( profileId ) )
@ -88,23 +99,23 @@ public class DefaultProfileManager implements ProfileManager
activatedIds.add( profileId );
}
}
/* (non-Javadoc)
* @see org.apache.maven.profiles.ProfileManager#explicitlyActivate(java.util.List)
*/
* @see org.apache.maven.profiles.ProfileManager#explicitlyActivate(java.util.List)
*/
public void explicitlyActivate( List profileIds )
{
for ( Iterator it = profileIds.iterator(); it.hasNext(); )
{
String profileId = (String) it.next();
explicitlyActivate( profileId );
}
}
/* (non-Javadoc)
* @see org.apache.maven.profiles.ProfileManager#explicitlyDeactivate(java.lang.String)
*/
* @see org.apache.maven.profiles.ProfileManager#explicitlyDeactivate(java.lang.String)
*/
public void explicitlyDeactivate( String profileId )
{
if ( !deactivatedIds.contains( profileId ) )
@ -114,34 +125,35 @@ public class DefaultProfileManager implements ProfileManager
deactivatedIds.add( profileId );
}
}
/* (non-Javadoc)
* @see org.apache.maven.profiles.ProfileManager#explicitlyDeactivate(java.util.List)
*/
* @see org.apache.maven.profiles.ProfileManager#explicitlyDeactivate(java.util.List)
*/
public void explicitlyDeactivate( List profileIds )
{
for ( Iterator it = profileIds.iterator(); it.hasNext(); )
{
String profileId = (String) it.next();
explicitlyDeactivate( profileId );
}
}
/* (non-Javadoc)
* @see org.apache.maven.profiles.ProfileManager#getActiveProfiles()
*/
public List getActiveProfiles() throws ProfileActivationException
* @see org.apache.maven.profiles.ProfileManager#getActiveProfiles()
*/
public List getActiveProfiles()
throws ProfileActivationException
{
List active = new ArrayList( profilesById.size() );
for ( Iterator it = profilesById.entrySet().iterator(); it.hasNext(); )
{
Map.Entry entry = (Entry) it.next();
String profileId = (String) entry.getKey();
Profile profile = (Profile) entry.getValue();
if ( activatedIds.contains( profileId ) )
{
active.add( profile );
@ -151,22 +163,22 @@ public class DefaultProfileManager implements ProfileManager
active.add( profile );
}
}
if ( active.isEmpty() )
{
for ( Iterator it = defaultIds.iterator(); it.hasNext(); )
{
String profileId = (String) it.next();
Profile profile = (Profile) profilesById.get( profileId );
active.add( profile );
}
}
return active;
}
private boolean isActive( Profile profile )
throws ProfileActivationException
{
@ -184,7 +196,7 @@ public class DefaultProfileManager implements ProfileManager
return activator.isActive( profile );
}
}
return false;
}
catch ( ComponentLookupException e )
@ -212,7 +224,7 @@ public class DefaultProfileManager implements ProfileManager
for ( Iterator it = profiles.iterator(); it.hasNext(); )
{
Profile profile = (Profile) it.next();
addProfile( profile );
}
}
@ -239,5 +251,30 @@ public class DefaultProfileManager implements ProfileManager
{
return defaultIds;
}
private void loadSettingsProfiles( Settings settings )
{
if ( settings == null )
{
return;
}
List settingsProfiles = settings.getProfiles();
if ( settingsProfiles != null && !settingsProfiles.isEmpty() )
{
List settingsActiveProfileIds = settings.getActiveProfiles();
explicitlyActivate( settingsActiveProfileIds );
for ( Iterator it = settings.getProfiles().iterator(); it.hasNext(); )
{
org.apache.maven.settings.Profile rawProfile = (org.apache.maven.settings.Profile) it.next();
Profile profile = SettingsUtils.convertFromSettingsProfile( rawProfile );
addProfile( profile );
}
}
}
}