mirror of https://github.com/apache/maven.git
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
This commit is contained in:
parent
975ac84b45
commit
c612913a70
|
@ -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<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 @@ public class DefaultModelBuilder
|
|||
|
||||
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 @@ public class DefaultModelBuilder
|
|||
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 )
|
||||
|
|
|
@ -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<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 @@ public class DefaultProfileSelector
|
|||
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 @@ 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<ProfileActivationException> 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;
|
||||
|
|
|
@ -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<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;
|
||||
}
|
||||
|
||||
}
|
|
@ -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<Profile> profiles, ProfileActivationContext context );
|
||||
List<Profile> getActiveProfiles( Collection<Profile> profiles, ProfileActivationContext context,
|
||||
ModelProblemCollector problems );
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue