From c612913a702ad80dc2ad997b8a214c1ade4ca482 Mon Sep 17 00:00:00 2001 From: Benjamin Bentmann Date: Mon, 3 Aug 2009 15:30:37 +0000 Subject: [PATCH] o Refactored profile selector to use problem collector git-svn-id: https://svn.apache.org/repos/asf/maven/components/trunk@800426 13f79535-47bb-0310-9956-ffa450edef68 --- .../model/building/DefaultModelBuilder.java | 36 +------ .../model/profile/DefaultProfileSelector.java | 20 ++-- .../model/profile/ProfileSelectionResult.java | 99 ------------------- .../maven/model/profile/ProfileSelector.java | 8 +- 4 files changed, 18 insertions(+), 145 deletions(-) delete mode 100644 maven-model-builder/src/main/java/org/apache/maven/model/profile/ProfileSelectionResult.java diff --git a/maven-model-builder/src/main/java/org/apache/maven/model/building/DefaultModelBuilder.java b/maven-model-builder/src/main/java/org/apache/maven/model/building/DefaultModelBuilder.java index 9c9d862f60..10030a2b06 100644 --- a/maven-model-builder/src/main/java/org/apache/maven/model/building/DefaultModelBuilder.java +++ b/maven-model-builder/src/main/java/org/apache/maven/model/building/DefaultModelBuilder.java @@ -47,9 +47,7 @@ import org.apache.maven.model.plugin.LifecycleBindingsInjector; 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 @@ public class DefaultModelBuilder ProfileActivationContext profileActivationContext = getProfileActivationContext( request ); problems.setSourceHint( "(external profiles)" ); - List activeExternalProfiles = getActiveExternalProfiles( request, profileActivationContext, problems ); + List activeExternalProfiles = + profileSelector.getActiveProfiles( request.getProfiles(), profileActivationContext, problems ); Model inputModel = readModel( request.getModelSource(), request.getPomFile(), request, problems.getProblems() ); @@ -141,7 +140,8 @@ public class DefaultModelBuilder modelNormalizer.mergeDuplicates( tmpModel, request ); - List activePomProfiles = getActivePomProfiles( rawModel, profileActivationContext, problems ); + List activePomProfiles = + profileSelector.getActiveProfiles( rawModel.getProfiles(), profileActivationContext, problems ); currentData.setActiveProfiles( activePomProfiles ); for ( Profile activeProfile : activePomProfiles ) @@ -343,34 +343,6 @@ public class DefaultModelBuilder return context; } - private List 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 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 ) diff --git a/maven-model-builder/src/main/java/org/apache/maven/model/profile/DefaultProfileSelector.java b/maven-model-builder/src/main/java/org/apache/maven/model/profile/DefaultProfileSelector.java index 5360381696..b803f35fe3 100644 --- a/maven-model-builder/src/main/java/org/apache/maven/model/profile/DefaultProfileSelector.java +++ b/maven-model-builder/src/main/java/org/apache/maven/model/profile/DefaultProfileSelector.java @@ -26,6 +26,7 @@ import java.util.List; 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 @@ public class DefaultProfileSelector @Requirement( role = ProfileActivator.class ) private List activators; - public ProfileSelectionResult getActiveProfiles( Collection profiles, ProfileActivationContext context ) + public List getActiveProfiles( Collection profiles, ProfileActivationContext context, + ModelProblemCollector problems ) { Collection activatedIds = new HashSet( context.getActiveProfileIds() ); Collection deactivatedIds = new HashSet( context.getInactiveProfileIds() ); @@ -52,13 +54,11 @@ public class DefaultProfileSelector List activePomProfilesByDefault = new ArrayList(); boolean activatedPomProfileNotByDefault = false; - List activationExceptions = new ArrayList(); - 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 @@ public class DefaultProfileSelector 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 exceptions ) + private boolean isActive( Profile profile, ProfileActivationContext context, ModelProblemCollector problems ) { for ( ProfileActivator activator : activators ) { @@ -108,7 +103,8 @@ public class DefaultProfileSelector } catch ( ProfileActivationException e ) { - exceptions.add( e ); + problems.addError( "Invalid activation condition for profile " + profile.getId() + ": " + + e.getMessage() ); } } return false; diff --git a/maven-model-builder/src/main/java/org/apache/maven/model/profile/ProfileSelectionResult.java b/maven-model-builder/src/main/java/org/apache/maven/model/profile/ProfileSelectionResult.java deleted file mode 100644 index aea0ab5e92..0000000000 --- a/maven-model-builder/src/main/java/org/apache/maven/model/profile/ProfileSelectionResult.java +++ /dev/null @@ -1,99 +0,0 @@ -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 activeProfiles; - - private List activationExceptions; - - public ProfileSelectionResult() - { - activeProfiles = new ArrayList(); - activationExceptions = new ArrayList(); - } - - /** - * Gets the profiles that have been activated. - * - * @return The profiles that have been activated, never {@code null}. - */ - public List 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 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 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 activationExceptions ) - { - this.activationExceptions.clear(); - if ( activationExceptions != null ) - { - this.activationExceptions.addAll( activationExceptions ); - } - - return this; - } - -} diff --git a/maven-model-builder/src/main/java/org/apache/maven/model/profile/ProfileSelector.java b/maven-model-builder/src/main/java/org/apache/maven/model/profile/ProfileSelector.java index 2f34aff38d..f58dcc8936 100644 --- a/maven-model-builder/src/main/java/org/apache/maven/model/profile/ProfileSelector.java +++ b/maven-model-builder/src/main/java/org/apache/maven/model/profile/ProfileSelector.java @@ -20,8 +20,10 @@ package org.apache.maven.model.profile; */ 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 @@ public interface ProfileSelector * @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 profiles, ProfileActivationContext context ); + List getActiveProfiles( Collection profiles, ProfileActivationContext context, + ModelProblemCollector problems ); }