mirror of https://github.com/apache/maven.git
o Updated profile selector to support collecting activation errors
git-svn-id: https://svn.apache.org/repos/asf/maven/components/trunk@782293 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
a35801fd1d
commit
bfe55515a0
|
@ -41,6 +41,7 @@ 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;
|
||||
|
@ -251,37 +252,30 @@ public class DefaultModelBuilder
|
|||
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 )
|
||||
|
|
|
@ -25,7 +25,9 @@ import java.util.ArrayList;
|
|||
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
|
||||
*/
|
||||
|
|
|
@ -43,8 +43,7 @@ public class DefaultProfileSelector
|
|||
@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 @@ 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 ) )
|
||||
if ( activatedIds.contains( profile.getId() ) || isActive( profile, context, activationExceptions ) )
|
||||
{
|
||||
activeProfiles.add( profile );
|
||||
|
||||
|
@ -86,17 +87,28 @@ public class DefaultProfileSelector
|
|||
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
|
||||
{
|
||||
return true;
|
||||
if ( activator.isActive( profile, context ) )
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
catch ( ProfileActivationException e )
|
||||
{
|
||||
exceptions.add( e );
|
||||
}
|
||||
}
|
||||
return false;
|
||||
|
|
|
@ -57,6 +57,7 @@ public class ProfileActivationException
|
|||
public ProfileActivationException( String message, Profile profile )
|
||||
{
|
||||
super( message );
|
||||
this.profile = profile;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
||||
}
|
|
@ -20,7 +20,6 @@ package org.apache.maven.model.profile;
|
|||
*/
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
|
||||
import org.apache.maven.model.Profile;
|
||||
|
||||
|
@ -39,11 +38,8 @@ 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 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 );
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue