You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@maven.apache.org by ev...@apache.org on 2006/02/21 15:59:53 UTC

svn commit: r379473 - in /maven/components/branches/maven-2.0.x/maven-project: pom.xml src/main/java/org/apache/maven/profiles/DefaultProfileManager.java

Author: evenisse
Date: Tue Feb 21 06:59:52 2006
New Revision: 379473

URL: http://svn.apache.org/viewcvs?rev=379473&view=rev
Log:
Auto-load profiles from settings.

Modified:
    maven/components/branches/maven-2.0.x/maven-project/pom.xml
    maven/components/branches/maven-2.0.x/maven-project/src/main/java/org/apache/maven/profiles/DefaultProfileManager.java

Modified: maven/components/branches/maven-2.0.x/maven-project/pom.xml
URL: http://svn.apache.org/viewcvs/maven/components/branches/maven-2.0.x/maven-project/pom.xml?rev=379473&r1=379472&r2=379473&view=diff
==============================================================================
--- maven/components/branches/maven-2.0.x/maven-project/pom.xml (original)
+++ maven/components/branches/maven-2.0.x/maven-project/pom.xml Tue Feb 21 06:59:52 2006
@@ -24,6 +24,11 @@
     </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>
       <version>2.0.3-SNAPSHOT</version>
     </dependency>

Modified: maven/components/branches/maven-2.0.x/maven-project/src/main/java/org/apache/maven/profiles/DefaultProfileManager.java
URL: http://svn.apache.org/viewcvs/maven/components/branches/maven-2.0.x/maven-project/src/main/java/org/apache/maven/profiles/DefaultProfileManager.java?rev=379473&r1=379472&r2=379473&view=diff
==============================================================================
--- maven/components/branches/maven-2.0.x/maven-project/src/main/java/org/apache/maven/profiles/DefaultProfileManager.java (original)
+++ maven/components/branches/maven-2.0.x/maven-project/src/main/java/org/apache/maven/profiles/DefaultProfileManager.java Tue Feb 21 06:59:52 2006
@@ -4,6 +4,8 @@
 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 @@
  * 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()
     {
         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 @@
             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 @@
             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 @@
                 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 @@
                     return activator.isActive( profile );
                 }
             }
-            
+
             return false;
         }
         catch ( ComponentLookupException e )
@@ -212,7 +224,7 @@
         for ( Iterator it = profiles.iterator(); it.hasNext(); )
         {
             Profile profile = (Profile) it.next();
-            
+
             addProfile( profile );
         }
     }
@@ -239,5 +251,30 @@
     {
         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 );
+            }
+        }
+    }
 }