You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@maven.apache.org by be...@apache.org on 2009/08/03 17:30:37 UTC

svn commit: r800426 - in /maven/components/trunk/maven-model-builder/src/main/java/org/apache/maven/model: building/DefaultModelBuilder.java profile/DefaultProfileSelector.java profile/ProfileSelectionResult.java profile/ProfileSelector.java

Author: bentmann
Date: Mon Aug  3 15:30:37 2009
New Revision: 800426

URL: http://svn.apache.org/viewvc?rev=800426&view=rev
Log:
o Refactored profile selector to use problem collector

Removed:
    maven/components/trunk/maven-model-builder/src/main/java/org/apache/maven/model/profile/ProfileSelectionResult.java
Modified:
    maven/components/trunk/maven-model-builder/src/main/java/org/apache/maven/model/building/DefaultModelBuilder.java
    maven/components/trunk/maven-model-builder/src/main/java/org/apache/maven/model/profile/DefaultProfileSelector.java
    maven/components/trunk/maven-model-builder/src/main/java/org/apache/maven/model/profile/ProfileSelector.java

Modified: maven/components/trunk/maven-model-builder/src/main/java/org/apache/maven/model/building/DefaultModelBuilder.java
URL: http://svn.apache.org/viewvc/maven/components/trunk/maven-model-builder/src/main/java/org/apache/maven/model/building/DefaultModelBuilder.java?rev=800426&r1=800425&r2=800426&view=diff
==============================================================================
--- maven/components/trunk/maven-model-builder/src/main/java/org/apache/maven/model/building/DefaultModelBuilder.java (original)
+++ maven/components/trunk/maven-model-builder/src/main/java/org/apache/maven/model/building/DefaultModelBuilder.java Mon Aug  3 15:30:37 2009
@@ -47,9 +47,7 @@
 import org.apache.maven.model.plugin.PluginConfigurationExpander;
 import org.apache.maven.model.profile.DefaultProfileActivationContext;
 import org.apache.maven.model.profile.ProfileActivationContext;
-import org.apache.maven.model.profile.ProfileActivationException;
 import org.apache.maven.model.profile.ProfileInjector;
-import org.apache.maven.model.profile.ProfileSelectionResult;
 import org.apache.maven.model.profile.ProfileSelector;
 import org.apache.maven.model.resolution.InvalidRepositoryException;
 import org.apache.maven.model.resolution.ModelResolver;
@@ -120,7 +118,8 @@
         ProfileActivationContext profileActivationContext = getProfileActivationContext( request );
 
         problems.setSourceHint( "(external profiles)" );
-        List<Profile> activeExternalProfiles = getActiveExternalProfiles( request, profileActivationContext, problems );
+        List<Profile> activeExternalProfiles =
+            profileSelector.getActiveProfiles( request.getProfiles(), profileActivationContext, problems );
 
         Model inputModel = readModel( request.getModelSource(), request.getPomFile(), request, problems.getProblems() );
 
@@ -141,7 +140,8 @@
 
             modelNormalizer.mergeDuplicates( tmpModel, request );
 
-            List<Profile> activePomProfiles = getActivePomProfiles( rawModel, profileActivationContext, problems );
+            List<Profile> activePomProfiles =
+                profileSelector.getActiveProfiles( rawModel.getProfiles(), profileActivationContext, problems );
             currentData.setActiveProfiles( activePomProfiles );
 
             for ( Profile activeProfile : activePomProfiles )
@@ -343,34 +343,6 @@
         return context;
     }
 
-    private List<Profile> getActiveExternalProfiles( ModelBuildingRequest request, ProfileActivationContext context,
-                                                     ModelProblemCollector problems )
-    {
-        ProfileSelectionResult result = profileSelector.getActiveProfiles( request.getProfiles(), context );
-
-        for ( ProfileActivationException e : result.getActivationExceptions() )
-        {
-            problems.addError( "Invalid activation condition for external profile " + e.getProfile().getId() + ": "
-                + e.getMessage(), e );
-        }
-
-        return result.getActiveProfiles();
-    }
-
-    private List<Profile> getActivePomProfiles( Model model, ProfileActivationContext context,
-                                                ModelProblemCollector problems )
-    {
-        ProfileSelectionResult result = profileSelector.getActiveProfiles( model.getProfiles(), context );
-
-        for ( ProfileActivationException e : result.getActivationExceptions() )
-        {
-            problems.addError( "Invalid activation condition for project profile " + e.getProfile().getId() + ": "
-                + e.getMessage(), e );
-        }
-
-        return result.getActiveProfiles();
-    }
-
     private void configureResolver( ModelResolver modelResolver, Model model, DefaultModelProblemCollector problems )
     {
         if ( modelResolver == null )

Modified: maven/components/trunk/maven-model-builder/src/main/java/org/apache/maven/model/profile/DefaultProfileSelector.java
URL: http://svn.apache.org/viewvc/maven/components/trunk/maven-model-builder/src/main/java/org/apache/maven/model/profile/DefaultProfileSelector.java?rev=800426&r1=800425&r2=800426&view=diff
==============================================================================
--- maven/components/trunk/maven-model-builder/src/main/java/org/apache/maven/model/profile/DefaultProfileSelector.java (original)
+++ maven/components/trunk/maven-model-builder/src/main/java/org/apache/maven/model/profile/DefaultProfileSelector.java Mon Aug  3 15:30:37 2009
@@ -26,6 +26,7 @@
 
 import org.apache.maven.model.Activation;
 import org.apache.maven.model.Profile;
+import org.apache.maven.model.building.ModelProblemCollector;
 import org.apache.maven.model.profile.activation.ProfileActivator;
 import org.codehaus.plexus.component.annotations.Component;
 import org.codehaus.plexus.component.annotations.Requirement;
@@ -43,7 +44,8 @@
     @Requirement( role = ProfileActivator.class )
     private List<ProfileActivator> activators;
 
-    public ProfileSelectionResult getActiveProfiles( Collection<Profile> profiles, ProfileActivationContext context )
+    public List<Profile> getActiveProfiles( Collection<Profile> profiles, ProfileActivationContext context,
+                                            ModelProblemCollector problems )
     {
         Collection<String> activatedIds = new HashSet<String>( context.getActiveProfileIds() );
         Collection<String> deactivatedIds = new HashSet<String>( context.getInactiveProfileIds() );
@@ -52,13 +54,11 @@
         List<Profile> activePomProfilesByDefault = new ArrayList<Profile>();
         boolean activatedPomProfileNotByDefault = false;
 
-        List<ProfileActivationException> activationExceptions = new ArrayList<ProfileActivationException>();
-
         for ( Profile profile : profiles )
         {
             if ( !deactivatedIds.contains( profile.getId() ) )
             {
-                if ( activatedIds.contains( profile.getId() ) || isActive( profile, context, activationExceptions ) )
+                if ( activatedIds.contains( profile.getId() ) || isActive( profile, context, problems ) )
                 {
                     activeProfiles.add( profile );
 
@@ -87,15 +87,10 @@
             activeProfiles.addAll( activePomProfilesByDefault );
         }
 
-        ProfileSelectionResult result = new ProfileSelectionResult();
-        result.setActiveProfiles( activeProfiles );
-        result.setActivationExceptions( activationExceptions );
-
-        return result;
+        return activeProfiles;
     }
 
-    private boolean isActive( Profile profile, ProfileActivationContext context,
-                              List<ProfileActivationException> exceptions )
+    private boolean isActive( Profile profile, ProfileActivationContext context, ModelProblemCollector problems )
     {
         for ( ProfileActivator activator : activators )
         {
@@ -108,7 +103,8 @@
             }
             catch ( ProfileActivationException e )
             {
-                exceptions.add( e );
+                problems.addError( "Invalid activation condition for profile " + profile.getId() + ": "
+                    + e.getMessage() );
             }
         }
         return false;

Modified: maven/components/trunk/maven-model-builder/src/main/java/org/apache/maven/model/profile/ProfileSelector.java
URL: http://svn.apache.org/viewvc/maven/components/trunk/maven-model-builder/src/main/java/org/apache/maven/model/profile/ProfileSelector.java?rev=800426&r1=800425&r2=800426&view=diff
==============================================================================
--- maven/components/trunk/maven-model-builder/src/main/java/org/apache/maven/model/profile/ProfileSelector.java (original)
+++ maven/components/trunk/maven-model-builder/src/main/java/org/apache/maven/model/profile/ProfileSelector.java Mon Aug  3 15:30:37 2009
@@ -20,8 +20,10 @@
  */
 
 import java.util.Collection;
+import java.util.List;
 
 import org.apache.maven.model.Profile;
+import org.apache.maven.model.building.ModelProblemCollector;
 
 /**
  * Calculates the active profiles among a given collection of profiles.
@@ -38,8 +40,10 @@
      * @param profiles The profiles whose activation status should be determined, must not be {@code null}.
      * @param context The environmental context used to determine the activation status of a profile, must not be
      *            {@code null}.
-     * @return The result of the selection process, never {@code null}.
+     * @param problems The container used to collect problems that were encountered, must not be {@code null}.
+     * @return The profiles that have been activated, never {@code null}.
      */
-    ProfileSelectionResult getActiveProfiles( Collection<Profile> profiles, ProfileActivationContext context );
+    List<Profile> getActiveProfiles( Collection<Profile> profiles, ProfileActivationContext context,
+                                     ModelProblemCollector problems );
 
 }