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/06/06 20:09:43 UTC

svn commit: r782293 - in /maven/components/trunk/maven-model-builder/src/main/java/org/apache/maven/model: ./ profile/

Author: bentmann
Date: Sat Jun  6 18:09:42 2009
New Revision: 782293

URL: http://svn.apache.org/viewvc?rev=782293&view=rev
Log:
o Updated profile selector to support collecting activation errors

Added:
    maven/components/trunk/maven-model-builder/src/main/java/org/apache/maven/model/profile/ProfileSelectionResult.java   (with props)
Modified:
    maven/components/trunk/maven-model-builder/src/main/java/org/apache/maven/model/DefaultModelBuilder.java
    maven/components/trunk/maven-model-builder/src/main/java/org/apache/maven/model/ModelBuildingException.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/ProfileActivationException.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/DefaultModelBuilder.java
URL: http://svn.apache.org/viewvc/maven/components/trunk/maven-model-builder/src/main/java/org/apache/maven/model/DefaultModelBuilder.java?rev=782293&r1=782292&r2=782293&view=diff
==============================================================================
--- maven/components/trunk/maven-model-builder/src/main/java/org/apache/maven/model/DefaultModelBuilder.java (original)
+++ maven/components/trunk/maven-model-builder/src/main/java/org/apache/maven/model/DefaultModelBuilder.java Sat Jun  6 18:09:42 2009
@@ -41,6 +41,7 @@
 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;
@@ -251,37 +252,30 @@
     private List<Profile> getActiveExternalProfiles( ModelBuildingRequest request, ProfileActivationContext context,
                                                      List<ModelProblem> problems )
     {
-        try
-        {
-            return profileSelector.getActiveProfiles( request.getProfiles(), context );
-        }
-        catch ( ProfileActivationException e )
+        ProfileSelectionResult result = profileSelector.getActiveProfiles( request.getProfiles(), context );
+
+        for ( ProfileActivationException e : result.getActivationExceptions() )
         {
             problems.add( new ModelProblem( "Invalid activation condition for external profile "
                 + e.getProfile().getId() + ": " + e.getMessage(), "(external profiles)", e ) );
-
-            // FIXME: Update profile selector to integrate better with the problem reporting
-            return new ArrayList<Profile>();
         }
+
+        return result.getActiveProfiles();
     }
 
     private List<Profile> getActiveProjectProfiles( Model model, ProfileActivationContext context,
                                                     List<ModelProblem> problems )
-        throws ModelBuildingException
     {
-        try
-        {
-            return profileSelector.getActiveProfiles( model.getProfiles(), context );
-        }
-        catch ( ProfileActivationException e )
+        ProfileSelectionResult result = profileSelector.getActiveProfiles( model.getProfiles(), context );
+
+        for ( ProfileActivationException e : result.getActivationExceptions() )
         {
             problems.add( new ModelProblem( "Invalid activation condition for project profile "
                 + e.getProfile().getId() + " in POM " + toSourceHint( model ) + ": " + e.getMessage(),
                                             toSourceHint( model ), e ) );
-
-            // FIXME: Update profile selector to integrate better with the problem reporting
-            return new ArrayList<Profile>();
         }
+
+        return result.getActiveProfiles();
     }
 
     private void configureResolver( ModelResolver modelResolver, Model model, List<ModelProblem> problems )

Modified: maven/components/trunk/maven-model-builder/src/main/java/org/apache/maven/model/ModelBuildingException.java
URL: http://svn.apache.org/viewvc/maven/components/trunk/maven-model-builder/src/main/java/org/apache/maven/model/ModelBuildingException.java?rev=782293&r1=782292&r2=782293&view=diff
==============================================================================
--- maven/components/trunk/maven-model-builder/src/main/java/org/apache/maven/model/ModelBuildingException.java (original)
+++ maven/components/trunk/maven-model-builder/src/main/java/org/apache/maven/model/ModelBuildingException.java Sat Jun  6 18:09:42 2009
@@ -25,7 +25,9 @@
 import java.util.List;
 
 /**
- * Signals an error during model building.
+ * Signals one ore more errors during model building. The model builder tries to collect as many problems as possible
+ * before eventually failing to provide callers with rich error information. Use {@link #getProblems()} to query the
+ * details of the failure.
  * 
  * @author Benjamin Bentmann
  */

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=782293&r1=782292&r2=782293&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 Sat Jun  6 18:09:42 2009
@@ -43,8 +43,7 @@
     @Requirement( role = ProfileActivator.class )
     private List<ProfileActivator> activators;
 
-    public List<Profile> getActiveProfiles( Collection<Profile> profiles, ProfileActivationContext context )
-        throws ProfileActivationException
+    public ProfileSelectionResult getActiveProfiles( Collection<Profile> profiles, ProfileActivationContext context )
     {
         Collection<String> activatedIds = new HashSet<String>( context.getActiveProfileIds() );
         Collection<String> deactivatedIds = new HashSet<String>( context.getInactiveProfileIds() );
@@ -53,11 +52,13 @@
         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 ) )
+                if ( activatedIds.contains( profile.getId() ) || isActive( profile, context, activationExceptions ) )
                 {
                     activeProfiles.add( profile );
 
@@ -86,17 +87,28 @@
             activeProfiles.addAll( activePomProfilesByDefault );
         }
 
-        return activeProfiles;
+        ProfileSelectionResult result = new ProfileSelectionResult();
+        result.setActiveProfiles( activeProfiles );
+        result.setActivationExceptions( activationExceptions );
+
+        return result;
     }
 
-    private boolean isActive( Profile profile, ProfileActivationContext context )
-        throws ProfileActivationException
+    private boolean isActive( Profile profile, ProfileActivationContext context,
+                              List<ProfileActivationException> exceptions )
     {
         for ( ProfileActivator activator : activators )
         {
-            if ( activator.isActive( profile, context ) )
+            try
+            {
+                if ( activator.isActive( profile, context ) )
+                {
+                    return true;
+                }
+            }
+            catch ( ProfileActivationException e )
             {
-                return true;
+                exceptions.add( e );
             }
         }
         return false;

Modified: maven/components/trunk/maven-model-builder/src/main/java/org/apache/maven/model/profile/ProfileActivationException.java
URL: http://svn.apache.org/viewvc/maven/components/trunk/maven-model-builder/src/main/java/org/apache/maven/model/profile/ProfileActivationException.java?rev=782293&r1=782292&r2=782293&view=diff
==============================================================================
--- maven/components/trunk/maven-model-builder/src/main/java/org/apache/maven/model/profile/ProfileActivationException.java (original)
+++ maven/components/trunk/maven-model-builder/src/main/java/org/apache/maven/model/profile/ProfileActivationException.java Sat Jun  6 18:09:42 2009
@@ -57,6 +57,7 @@
     public ProfileActivationException( String message, Profile profile )
     {
         super( message );
+        this.profile = profile;
     }
 
     /**

Added: maven/components/trunk/maven-model-builder/src/main/java/org/apache/maven/model/profile/ProfileSelectionResult.java
URL: http://svn.apache.org/viewvc/maven/components/trunk/maven-model-builder/src/main/java/org/apache/maven/model/profile/ProfileSelectionResult.java?rev=782293&view=auto
==============================================================================
--- maven/components/trunk/maven-model-builder/src/main/java/org/apache/maven/model/profile/ProfileSelectionResult.java (added)
+++ maven/components/trunk/maven-model-builder/src/main/java/org/apache/maven/model/profile/ProfileSelectionResult.java Sat Jun  6 18:09:42 2009
@@ -0,0 +1,99 @@
+package org.apache.maven.model.profile;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.apache.maven.model.Profile;
+
+/**
+ * Collects the results of the profile selector.
+ * 
+ * @author Benjamin Bentmann
+ */
+public class ProfileSelectionResult
+{
+
+    private List<Profile> activeProfiles;
+
+    private List<ProfileActivationException> activationExceptions;
+
+    public ProfileSelectionResult()
+    {
+        activeProfiles = new ArrayList<Profile>();
+        activationExceptions = new ArrayList<ProfileActivationException>();
+    }
+
+    /**
+     * Gets the profiles that have been activated.
+     * 
+     * @return The profiles that have been activated, never {@code null}.
+     */
+    public List<Profile> getActiveProfiles()
+    {
+        return this.activeProfiles;
+    }
+
+    /**
+     * Sets the profiles that have been activated.
+     * 
+     * @param activeProfiles The profiles that have been activated, may be {@code null}.
+     * @return This result, never {@code null}.
+     */
+    public ProfileSelectionResult setActiveProfiles( List<Profile> activeProfiles )
+    {
+        this.activeProfiles.clear();
+        if ( activeProfiles != null )
+        {
+            this.activeProfiles.addAll( activeProfiles );
+        }
+
+        return this;
+    }
+
+    /**
+     * Gets the exceptions that have occurred during profile activation.
+     * 
+     * @return The exceptions that have occurred during profile activation, never {@code null}.
+     */
+    public List<ProfileActivationException> getActivationExceptions()
+    {
+        return activationExceptions;
+    }
+
+    /**
+     * Sets the exceptions that have occurred during profile activation.
+     * 
+     * @param activationExceptions The exceptions that have occurred during profile activation, may be {@code null}.
+     * @return This result, never {@code null}.
+     */
+    public ProfileSelectionResult setActivationExceptions( List<ProfileActivationException> activationExceptions )
+    {
+        this.activationExceptions.clear();
+        if ( activationExceptions != null )
+        {
+            this.activationExceptions.addAll( activationExceptions );
+        }
+
+        return this;
+    }
+
+}

Propchange: maven/components/trunk/maven-model-builder/src/main/java/org/apache/maven/model/profile/ProfileSelectionResult.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: maven/components/trunk/maven-model-builder/src/main/java/org/apache/maven/model/profile/ProfileSelectionResult.java
------------------------------------------------------------------------------
    svn:keywords = Author Date Id Revision

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=782293&r1=782292&r2=782293&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 Sat Jun  6 18:09:42 2009
@@ -20,7 +20,6 @@
  */
 
 import java.util.Collection;
-import java.util.List;
 
 import org.apache.maven.model.Profile;
 
@@ -39,11 +38,8 @@
      * @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 list of active profiles, never {@code null}.
-     * @throws ProfileActivationException If the activation status of any profile could not be determined (e.g. due to
-     *             missing values or bad syntax).
+     * @return The result of the selection process, never {@code null}.
      */
-    List<Profile> getActiveProfiles( Collection<Profile> profiles, ProfileActivationContext context )
-        throws ProfileActivationException;
+    ProfileSelectionResult getActiveProfiles( Collection<Profile> profiles, ProfileActivationContext context );
 
 }