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,19 +33,29 @@ 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, null );
}
public DefaultProfileManager( PlexusContainer container, Settings settings )
{
this.container = container;
loadSettingsProfiles( settings );
}
public Map getProfilesById()
@ -52,8 +64,8 @@ public class DefaultProfileManager implements ProfileManager
}
/* (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();
@ -61,9 +73,8 @@ public class DefaultProfileManager implements ProfileManager
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 );
@ -77,8 +88,8 @@ public class DefaultProfileManager implements ProfileManager
}
/* (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 ) )
@ -90,8 +101,8 @@ public class DefaultProfileManager implements ProfileManager
}
/* (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(); )
@ -103,8 +114,8 @@ public class DefaultProfileManager implements ProfileManager
}
/* (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 ) )
@ -116,8 +127,8 @@ public class DefaultProfileManager implements ProfileManager
}
/* (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(); )
@ -129,9 +140,10 @@ public class DefaultProfileManager implements ProfileManager
}
/* (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() );
@ -240,4 +252,29 @@ 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 );
}
}
}
}