mirror of https://github.com/apache/maven.git
Collapsed the ProfileContext into the ProfileManager - serves similar function.
git-svn-id: https://svn.apache.org/repos/asf/maven/components/trunk@761629 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
db49936302
commit
1c57f3a99b
|
@ -30,6 +30,7 @@ import org.apache.maven.profiles.matchers.DefaultMatcher;
|
||||||
import org.apache.maven.profiles.matchers.ProfileMatcher;
|
import org.apache.maven.profiles.matchers.ProfileMatcher;
|
||||||
import org.apache.maven.profiles.matchers.PropertyMatcher;
|
import org.apache.maven.profiles.matchers.PropertyMatcher;
|
||||||
import org.apache.maven.shared.model.InterpolatorProperty;
|
import org.apache.maven.shared.model.InterpolatorProperty;
|
||||||
|
import org.apache.maven.project.ProjectBuilderConfiguration;
|
||||||
import org.apache.maven.project.builder.PomInterpolatorTag;
|
import org.apache.maven.project.builder.PomInterpolatorTag;
|
||||||
import org.codehaus.plexus.PlexusContainer;
|
import org.codehaus.plexus.PlexusContainer;
|
||||||
import org.codehaus.plexus.MutablePlexusContainer;
|
import org.codehaus.plexus.MutablePlexusContainer;
|
||||||
|
@ -46,6 +47,11 @@ public class DefaultProfileManager
|
||||||
|
|
||||||
private ProfileActivationContext profileActivationContext;
|
private ProfileActivationContext profileActivationContext;
|
||||||
|
|
||||||
|
private static final ProfileMatcher defaultMatcher = new DefaultMatcher();
|
||||||
|
|
||||||
|
private static final List<ProfileMatcher> matchers =
|
||||||
|
Collections.unmodifiableList( Arrays.asList( new DefaultMatcher(), new PropertyMatcher() ) );
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* the properties passed to the profile manager are the props that
|
* the properties passed to the profile manager are the props that
|
||||||
* are passed to maven, possibly containing profile activator properties
|
* are passed to maven, possibly containing profile activator properties
|
||||||
|
@ -195,6 +201,83 @@ public class DefaultProfileManager
|
||||||
return allActive;
|
return allActive;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static List<Profile> getActiveProfilesFrom(ProjectBuilderConfiguration config, Model model, PlexusContainer container)
|
||||||
|
throws ProfileActivationException
|
||||||
|
{
|
||||||
|
List<Profile> projectProfiles = new ArrayList<Profile>();
|
||||||
|
ProfileManager externalProfileManager = config.getGlobalProfileManager();
|
||||||
|
|
||||||
|
ProfileActivationContext profileActivationContext = (externalProfileManager == null) ? new ProfileActivationContext( config.getExecutionProperties(), false ):
|
||||||
|
externalProfileManager.getProfileActivationContext();
|
||||||
|
|
||||||
|
if(externalProfileManager != null)
|
||||||
|
{
|
||||||
|
projectProfiles.addAll( externalProfileManager.getActiveProfiles() );
|
||||||
|
}
|
||||||
|
|
||||||
|
ProfileManager profileManager = new DefaultProfileManager( container, profileActivationContext );
|
||||||
|
profileManager.addProfiles( model.getProfiles() );
|
||||||
|
projectProfiles.addAll( profileManager.getActiveProfiles() );
|
||||||
|
return projectProfiles;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Collection<Profile> getActiveProfiles(List<Profile> profiles, ProfileManagerInfo profileContextInfo)
|
||||||
|
{
|
||||||
|
List<InterpolatorProperty> properties = profileContextInfo.getInterpolatorProperties();
|
||||||
|
Collection<String> activeProfileIds = profileContextInfo.getActiveProfileIds();
|
||||||
|
Collection<String> inactiveProfileIds = profileContextInfo.getInactiveProfileIds();
|
||||||
|
|
||||||
|
List<Profile> matchedProfiles = new ArrayList<Profile>();
|
||||||
|
List<Profile> defaultProfiles = new ArrayList<Profile>();
|
||||||
|
for ( Profile profile : profiles )
|
||||||
|
{
|
||||||
|
String profileId = profile.getId();
|
||||||
|
|
||||||
|
if ( !inactiveProfileIds.contains( profileId ) )
|
||||||
|
{
|
||||||
|
if ( activeProfileIds.contains( profileId ) )
|
||||||
|
{
|
||||||
|
matchedProfiles.add( profile );
|
||||||
|
}
|
||||||
|
else if ( defaultMatcher.isMatch( profile, properties ) )
|
||||||
|
{
|
||||||
|
defaultProfiles.add( profile );
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
for ( ProfileMatcher matcher : matchers )
|
||||||
|
{
|
||||||
|
if ( matcher.isMatch( profile, properties ) )
|
||||||
|
{
|
||||||
|
matchedProfiles.add( profile );
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if ( matchedProfiles.isEmpty() )
|
||||||
|
{
|
||||||
|
matchedProfiles = defaultProfiles;
|
||||||
|
}
|
||||||
|
|
||||||
|
return matchedProfiles;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* (non-Javadoc)
|
||||||
|
* @see org.apache.maven.project.ProfileManager#addProfiles(java.util.List)
|
||||||
|
*/
|
||||||
|
public void addProfiles( List<Profile> profiles )
|
||||||
|
{
|
||||||
|
for ( Iterator it = profiles.iterator(); it.hasNext(); )
|
||||||
|
{
|
||||||
|
Profile profile = (Profile) it.next();
|
||||||
|
|
||||||
|
addProfile( profile );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private static List<Profile> getDefaultProfiles(List<Profile> profiles)
|
private static List<Profile> getDefaultProfiles(List<Profile> profiles)
|
||||||
{
|
{
|
||||||
List<Profile> defaults = new ArrayList<Profile>();
|
List<Profile> defaults = new ArrayList<Profile>();
|
||||||
|
@ -208,9 +291,6 @@ public class DefaultProfileManager
|
||||||
return defaults;
|
return defaults;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static List<ProfileMatcher> matchers = Arrays.asList( (ProfileMatcher) new DefaultMatcher(),
|
|
||||||
(ProfileMatcher) new PropertyMatcher());
|
|
||||||
|
|
||||||
private boolean isActive( Profile profile, ProfileActivationContext context )
|
private boolean isActive( Profile profile, ProfileActivationContext context )
|
||||||
throws ProfileActivationException
|
throws ProfileActivationException
|
||||||
{
|
{
|
||||||
|
@ -232,19 +312,6 @@ public class DefaultProfileManager
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* (non-Javadoc)
|
|
||||||
* @see org.apache.maven.project.ProfileManager#addProfiles(java.util.List)
|
|
||||||
*/
|
|
||||||
public void addProfiles( List<Profile> profiles )
|
|
||||||
{
|
|
||||||
for ( Iterator it = profiles.iterator(); it.hasNext(); )
|
|
||||||
{
|
|
||||||
Profile profile = (Profile) it.next();
|
|
||||||
|
|
||||||
addProfile( profile );
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private void activateAsDefault( String profileId )
|
private void activateAsDefault( String profileId )
|
||||||
{
|
{
|
||||||
List defaultIds = profileActivationContext.getActiveByDefaultProfileIds();
|
List defaultIds = profileActivationContext.getActiveByDefaultProfileIds();
|
||||||
|
|
|
@ -1,122 +0,0 @@
|
||||||
package org.apache.maven.profiles;
|
|
||||||
|
|
||||||
/*
|
|
||||||
* 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.Arrays;
|
|
||||||
import java.util.Collection;
|
|
||||||
import java.util.Collections;
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
import org.apache.maven.profiles.matchers.DefaultMatcher;
|
|
||||||
import org.apache.maven.profiles.matchers.ProfileMatcher;
|
|
||||||
import org.apache.maven.profiles.matchers.PropertyMatcher;
|
|
||||||
import org.apache.maven.project.ProjectBuilderConfiguration;
|
|
||||||
import org.apache.maven.project.ProjectBuildingException;
|
|
||||||
import org.apache.maven.shared.model.InterpolatorProperty;
|
|
||||||
|
|
||||||
import org.apache.maven.model.Model;
|
|
||||||
import org.apache.maven.model.Profile;
|
|
||||||
import org.codehaus.plexus.PlexusContainer;
|
|
||||||
|
|
||||||
public class ProfileContext
|
|
||||||
{
|
|
||||||
private List<InterpolatorProperty> properties;
|
|
||||||
|
|
||||||
private Collection<String> activeProfileIds;
|
|
||||||
|
|
||||||
private Collection<String> inactiveProfileIds;
|
|
||||||
|
|
||||||
private List<Profile> profiles;
|
|
||||||
|
|
||||||
private ProfileMatcher defaultMatcher = new DefaultMatcher();
|
|
||||||
|
|
||||||
private List<ProfileMatcher> matchers =
|
|
||||||
Collections.unmodifiableList( Arrays.asList( new DefaultMatcher(), new PropertyMatcher() ) );
|
|
||||||
|
|
||||||
public ProfileContext( List<Profile> profiles, ProfileContextInfo profileContextInfo )
|
|
||||||
{
|
|
||||||
this.profiles = new ArrayList<Profile>( profiles );
|
|
||||||
this.properties = profileContextInfo.getInterpolatorProperties();
|
|
||||||
this.activeProfileIds = profileContextInfo.getActiveProfileIds();
|
|
||||||
this.inactiveProfileIds = profileContextInfo.getInactiveProfileIds();
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
public static List<Profile> getActiveProfilesFrom(ProjectBuilderConfiguration config, Model model, PlexusContainer container)
|
|
||||||
throws ProfileActivationException
|
|
||||||
{
|
|
||||||
List<Profile> projectProfiles = new ArrayList<Profile>();
|
|
||||||
ProfileManager externalProfileManager = config.getGlobalProfileManager();
|
|
||||||
|
|
||||||
ProfileActivationContext profileActivationContext = (externalProfileManager == null) ? new ProfileActivationContext( config.getExecutionProperties(), false ):
|
|
||||||
externalProfileManager.getProfileActivationContext();
|
|
||||||
|
|
||||||
if(externalProfileManager != null)
|
|
||||||
{
|
|
||||||
projectProfiles.addAll( externalProfileManager.getActiveProfiles() );
|
|
||||||
}
|
|
||||||
|
|
||||||
ProfileManager profileManager = new DefaultProfileManager( container, profileActivationContext );
|
|
||||||
profileManager.addProfiles( model.getProfiles() );
|
|
||||||
projectProfiles.addAll( profileManager.getActiveProfiles() );
|
|
||||||
return projectProfiles;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Collection<Profile> getActiveProfiles()
|
|
||||||
{
|
|
||||||
List<Profile> matchedProfiles = new ArrayList<Profile>();
|
|
||||||
List<Profile> defaultProfiles = new ArrayList<Profile>();
|
|
||||||
for ( Profile profile : profiles )
|
|
||||||
{
|
|
||||||
String profileId = profile.getId();
|
|
||||||
|
|
||||||
if ( !inactiveProfileIds.contains( profileId ) )
|
|
||||||
{
|
|
||||||
if ( activeProfileIds.contains( profileId ) )
|
|
||||||
{
|
|
||||||
matchedProfiles.add( profile );
|
|
||||||
}
|
|
||||||
else if ( defaultMatcher.isMatch( profile, properties ) )
|
|
||||||
{
|
|
||||||
defaultProfiles.add( profile );
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
for ( ProfileMatcher matcher : matchers )
|
|
||||||
{
|
|
||||||
if ( matcher.isMatch( profile, properties ) )
|
|
||||||
{
|
|
||||||
matchedProfiles.add( profile );
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if ( matchedProfiles.isEmpty() )
|
|
||||||
{
|
|
||||||
matchedProfiles = defaultProfiles;
|
|
||||||
}
|
|
||||||
|
|
||||||
return matchedProfiles;
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -40,5 +40,5 @@ public interface ProfileManager
|
||||||
throws ProfileActivationException;
|
throws ProfileActivationException;
|
||||||
|
|
||||||
List<Profile> getActiveProfiles( )
|
List<Profile> getActiveProfiles( )
|
||||||
throws ProfileActivationException;
|
throws ProfileActivationException;
|
||||||
}
|
}
|
|
@ -6,7 +6,7 @@ import java.util.List;
|
||||||
|
|
||||||
import org.apache.maven.shared.model.InterpolatorProperty;
|
import org.apache.maven.shared.model.InterpolatorProperty;
|
||||||
|
|
||||||
public class ProfileContextInfo
|
public class ProfileManagerInfo
|
||||||
{
|
{
|
||||||
private List<InterpolatorProperty> interpolatorProperties;
|
private List<InterpolatorProperty> interpolatorProperties;
|
||||||
|
|
||||||
|
@ -14,7 +14,7 @@ public class ProfileContextInfo
|
||||||
|
|
||||||
private Collection<String> inactiveProfileIds;
|
private Collection<String> inactiveProfileIds;
|
||||||
|
|
||||||
public ProfileContextInfo(List<InterpolatorProperty> interpolatorProperties, Collection<String> activeProfileIds, Collection<String> inactiveProfileIds)
|
public ProfileManagerInfo(List<InterpolatorProperty> interpolatorProperties, Collection<String> activeProfileIds, Collection<String> inactiveProfileIds)
|
||||||
{
|
{
|
||||||
this.interpolatorProperties = (interpolatorProperties != null) ? interpolatorProperties : new ArrayList<InterpolatorProperty>();
|
this.interpolatorProperties = (interpolatorProperties != null) ? interpolatorProperties : new ArrayList<InterpolatorProperty>();
|
||||||
this.activeProfileIds = (activeProfileIds != null) ? activeProfileIds : new ArrayList<String>();
|
this.activeProfileIds = (activeProfileIds != null) ? activeProfileIds : new ArrayList<String>();
|
|
@ -45,12 +45,11 @@ import org.apache.maven.model.io.xpp3.MavenXpp3Writer;
|
||||||
import org.apache.maven.profiles.DefaultProfileManager;
|
import org.apache.maven.profiles.DefaultProfileManager;
|
||||||
import org.apache.maven.profiles.ProfileActivationContext;
|
import org.apache.maven.profiles.ProfileActivationContext;
|
||||||
import org.apache.maven.profiles.ProfileActivationException;
|
import org.apache.maven.profiles.ProfileActivationException;
|
||||||
import org.apache.maven.profiles.ProfileContextInfo;
|
import org.apache.maven.profiles.ProfileManagerInfo;
|
||||||
import org.apache.maven.profiles.ProfileManager;
|
import org.apache.maven.profiles.ProfileManager;
|
||||||
import org.apache.maven.project.artifact.InvalidDependencyVersionException;
|
import org.apache.maven.project.artifact.InvalidDependencyVersionException;
|
||||||
import org.apache.maven.project.builder.PomClassicDomainModel;
|
import org.apache.maven.project.builder.PomClassicDomainModel;
|
||||||
import org.apache.maven.project.builder.PomInterpolatorTag;
|
import org.apache.maven.project.builder.PomInterpolatorTag;
|
||||||
import org.apache.maven.profiles.ProfileContext;
|
|
||||||
import org.apache.maven.project.processor.ProcessorContext;
|
import org.apache.maven.project.processor.ProcessorContext;
|
||||||
import org.apache.maven.project.validation.ModelValidationResult;
|
import org.apache.maven.project.validation.ModelValidationResult;
|
||||||
import org.apache.maven.project.validation.ModelValidator;
|
import org.apache.maven.project.validation.ModelValidator;
|
||||||
|
@ -127,7 +126,7 @@ public class DefaultMavenProjectBuilder
|
||||||
PomClassicDomainModel domainModel;
|
PomClassicDomainModel domainModel;
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
domainModel = buildWithoutProfiles( "unknown", pomFile, configuration );
|
domainModel = build( "unknown", pomFile, configuration );
|
||||||
}
|
}
|
||||||
catch (IOException e)
|
catch (IOException e)
|
||||||
{
|
{
|
||||||
|
@ -138,7 +137,7 @@ public class DefaultMavenProjectBuilder
|
||||||
List<Profile> projectProfiles;
|
List<Profile> projectProfiles;
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
projectProfiles = ProfileContext.getActiveProfilesFrom(configuration, domainModel.getModel(), container);
|
projectProfiles = DefaultProfileManager.getActiveProfilesFrom(configuration, domainModel.getModel(), container);
|
||||||
}
|
}
|
||||||
catch ( ProfileActivationException e )
|
catch ( ProfileActivationException e )
|
||||||
{
|
{
|
||||||
|
@ -220,7 +219,7 @@ public class DefaultMavenProjectBuilder
|
||||||
PomClassicDomainModel domainModel;
|
PomClassicDomainModel domainModel;
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
domainModel = buildWithoutProfiles( "unknown", artifact.getFile(), configuration );
|
domainModel = build( "unknown", artifact.getFile(), configuration );
|
||||||
}
|
}
|
||||||
catch (IOException e)
|
catch (IOException e)
|
||||||
{
|
{
|
||||||
|
@ -230,7 +229,7 @@ public class DefaultMavenProjectBuilder
|
||||||
List<Profile> projectProfiles;
|
List<Profile> projectProfiles;
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
projectProfiles = ProfileContext.getActiveProfilesFrom(configuration, domainModel.getModel(), container);
|
projectProfiles = DefaultProfileManager.getActiveProfilesFrom(configuration, domainModel.getModel(), container);
|
||||||
}
|
}
|
||||||
catch ( ProfileActivationException e )
|
catch ( ProfileActivationException e )
|
||||||
{
|
{
|
||||||
|
@ -414,7 +413,7 @@ public class DefaultMavenProjectBuilder
|
||||||
return project;
|
return project;
|
||||||
}
|
}
|
||||||
|
|
||||||
private PomClassicDomainModel buildWithoutProfiles( String projectId, File pomFile, ProjectBuilderConfiguration projectBuilderConfiguration )
|
private PomClassicDomainModel build( String projectId, File pomFile, ProjectBuilderConfiguration projectBuilderConfiguration )
|
||||||
throws ProjectBuildingException, IOException
|
throws ProjectBuildingException, IOException
|
||||||
{
|
{
|
||||||
List<String> activeProfileIds = ( projectBuilderConfiguration != null && projectBuilderConfiguration.getGlobalProfileManager() != null && projectBuilderConfiguration.getGlobalProfileManager()
|
List<String> activeProfileIds = ( projectBuilderConfiguration != null && projectBuilderConfiguration.getGlobalProfileManager() != null && projectBuilderConfiguration.getGlobalProfileManager()
|
||||||
|
@ -424,7 +423,7 @@ public class DefaultMavenProjectBuilder
|
||||||
.getGlobalProfileManager().getProfileActivationContext() != null ) ? projectBuilderConfiguration.getGlobalProfileManager().getProfileActivationContext().getExplicitlyInactiveProfileIds()
|
.getGlobalProfileManager().getProfileActivationContext() != null ) ? projectBuilderConfiguration.getGlobalProfileManager().getProfileActivationContext().getExplicitlyInactiveProfileIds()
|
||||||
: new ArrayList<String>();
|
: new ArrayList<String>();
|
||||||
|
|
||||||
ProfileContextInfo profileInfo = new ProfileContextInfo(null, activeProfileIds, inactiveProfileIds);
|
ProfileManagerInfo profileInfo = new ProfileManagerInfo(null, activeProfileIds, inactiveProfileIds);
|
||||||
PomClassicDomainModel domainModel = new PomClassicDomainModel( pomFile );
|
PomClassicDomainModel domainModel = new PomClassicDomainModel( pomFile );
|
||||||
domainModel.setProjectDirectory( pomFile.getParentFile() );
|
domainModel.setProjectDirectory( pomFile.getParentFile() );
|
||||||
domainModel.setMostSpecialized( true );
|
domainModel.setMostSpecialized( true );
|
||||||
|
@ -469,8 +468,7 @@ public class DefaultMavenProjectBuilder
|
||||||
|
|
||||||
if(!dm.getModel().getProfiles().isEmpty())
|
if(!dm.getModel().getProfiles().isEmpty())
|
||||||
{
|
{
|
||||||
ProfileContext profileContext1 = new ProfileContext( dm.getModel().getProfiles(), profileInfo );
|
Collection<Profile> profiles = DefaultProfileManager.getActiveProfiles(dm.getModel().getProfiles(), profileInfo);
|
||||||
Collection<Profile> profiles = profileContext1.getActiveProfiles();
|
|
||||||
if(!profiles.isEmpty())
|
if(!profiles.isEmpty())
|
||||||
{
|
{
|
||||||
profileModels.add(ProcessorContext.mergeProfilesIntoModel( profiles, dm ));
|
profileModels.add(ProcessorContext.mergeProfilesIntoModel( profiles, dm ));
|
||||||
|
|
Loading…
Reference in New Issue