mirror of https://github.com/apache/maven.git
[MNG-3106,3983,4107] - profile fixes.
git-svn-id: https://svn.apache.org/repos/asf/maven/components/trunk@761825 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
1c57f3a99b
commit
d40d830ecd
|
@ -133,6 +133,9 @@ public class ProcessorContext
|
|||
model.setDistributionManagement( p.getDistributionManagement() );
|
||||
model.setProperties( p.getProperties() );
|
||||
model.setModules( new ArrayList<String>(p.getModules() ) );
|
||||
model.setRepositories(p.getRepositories());
|
||||
model.setPluginRepositories(p.getPluginRepositories());
|
||||
model.setReporting(p.getReporting());
|
||||
BuildProcessor proc = new BuildProcessor( new ArrayList<Processor>());
|
||||
proc.processWithProfile( p.getBuild(), model);
|
||||
return model;
|
||||
|
@ -548,6 +551,9 @@ public class ProcessorContext
|
|||
p.setBuild( copyBuild(profile.getBuild()) );
|
||||
p.setId( profile.getId() );
|
||||
p.setActivation( profile.getActivation() );
|
||||
p.setRepositories(profile.getRepositories());
|
||||
p.setPluginRepositories(profile.getPluginRepositories());
|
||||
p.setReporting(profile.getReporting());
|
||||
return p;
|
||||
}
|
||||
|
||||
|
|
|
@ -22,11 +22,11 @@ package org.apache.maven.profiles;
|
|||
import org.apache.maven.model.Activation;
|
||||
import org.apache.maven.model.Model;
|
||||
import org.apache.maven.model.Profile;
|
||||
import org.apache.maven.model.Parent;
|
||||
import org.apache.maven.profiles.ProfileActivationContext;
|
||||
import org.apache.maven.profiles.ProfileActivationException;
|
||||
import org.apache.maven.profiles.ProfileManager;
|
||||
import org.apache.maven.profiles.matchers.DefaultMatcher;
|
||||
import org.apache.maven.profiles.matchers.FileMatcher;
|
||||
import org.apache.maven.profiles.matchers.ProfileMatcher;
|
||||
import org.apache.maven.profiles.matchers.PropertyMatcher;
|
||||
import org.apache.maven.shared.model.InterpolatorProperty;
|
||||
|
@ -50,7 +50,7 @@ public class DefaultProfileManager
|
|||
private static final ProfileMatcher defaultMatcher = new DefaultMatcher();
|
||||
|
||||
private static final List<ProfileMatcher> matchers =
|
||||
Collections.unmodifiableList( Arrays.asList( new DefaultMatcher(), new PropertyMatcher() ) );
|
||||
(List<ProfileMatcher>) Collections.unmodifiableList( Arrays.asList( new DefaultMatcher(), new PropertyMatcher(), new FileMatcher() ) );
|
||||
|
||||
/**
|
||||
* the properties passed to the profile manager are the props that
|
||||
|
@ -134,7 +134,6 @@ public class DefaultProfileManager
|
|||
{
|
||||
List<Profile> activeFromPom = new ArrayList<Profile>();
|
||||
List<Profile> activeExternal = new ArrayList<Profile>();
|
||||
|
||||
for ( Iterator it = profilesById.entrySet().iterator(); it.hasNext(); )
|
||||
{
|
||||
Map.Entry entry = (Entry) it.next();
|
||||
|
@ -142,17 +141,8 @@ public class DefaultProfileManager
|
|||
String profileId = (String) entry.getKey();
|
||||
Profile profile = (Profile) entry.getValue();
|
||||
|
||||
boolean shouldAdd = false;
|
||||
if ( profileActivationContext.isExplicitlyActive( profileId ) )
|
||||
{
|
||||
shouldAdd = true;
|
||||
}
|
||||
else if ( isActive( profile, profileActivationContext ) )
|
||||
{
|
||||
shouldAdd = true;
|
||||
}
|
||||
|
||||
if ( !profileActivationContext.isExplicitlyInactive( profileId ) && shouldAdd )
|
||||
if ( !profileActivationContext.isExplicitlyInactive( profileId )
|
||||
&& (profileActivationContext.isExplicitlyActive( profileId ) || isActive( profile, profileActivationContext ) ) )
|
||||
{
|
||||
if ( "pom".equals( profile.getSource() ) )
|
||||
{
|
||||
|
@ -207,9 +197,12 @@ public class DefaultProfileManager
|
|||
List<Profile> projectProfiles = new ArrayList<Profile>();
|
||||
ProfileManager externalProfileManager = config.getGlobalProfileManager();
|
||||
|
||||
ProfileActivationContext profileActivationContext = (externalProfileManager == null) ? new ProfileActivationContext( config.getExecutionProperties(), false ):
|
||||
Properties props = new Properties(config.getExecutionProperties());
|
||||
props.putAll(config.getUserProperties());
|
||||
|
||||
ProfileActivationContext profileActivationContext = (externalProfileManager == null) ? new ProfileActivationContext( props, false ):
|
||||
externalProfileManager.getProfileActivationContext();
|
||||
|
||||
|
||||
if(externalProfileManager != null)
|
||||
{
|
||||
projectProfiles.addAll( externalProfileManager.getActiveProfiles() );
|
||||
|
|
|
@ -0,0 +1,34 @@
|
|||
package org.apache.maven.profiles.matchers;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.List;
|
||||
|
||||
import org.apache.maven.model.ActivationFile;
|
||||
import org.apache.maven.model.Profile;
|
||||
import org.apache.maven.shared.model.InterpolatorProperty;
|
||||
|
||||
public class FileMatcher implements ProfileMatcher {
|
||||
|
||||
public boolean isMatch(Profile profile, List<InterpolatorProperty> properties) {
|
||||
if (profile == null) {
|
||||
throw new IllegalArgumentException("profile: null");
|
||||
}
|
||||
|
||||
if(profile.getActivation() == null || profile.getActivation().getFile() == null)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
ActivationFile f = profile.getActivation().getFile();
|
||||
|
||||
if (f.getExists() != null && !new File(f.getExists()).exists()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (f.getMissing() != null && new File(f.getMissing()).exists()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
|
@ -31,7 +31,7 @@ public class PropertyMatcher implements ProfileMatcher
|
|||
if (profile == null) {
|
||||
throw new IllegalArgumentException("profile: null");
|
||||
}
|
||||
|
||||
|
||||
if(profile.getActivation() == null || profile.getActivation().getProperty() == null)
|
||||
{
|
||||
return false;
|
||||
|
|
|
@ -43,7 +43,6 @@ import org.apache.maven.model.Profile;
|
|||
import org.apache.maven.model.io.xpp3.MavenXpp3Reader;
|
||||
import org.apache.maven.model.io.xpp3.MavenXpp3Writer;
|
||||
import org.apache.maven.profiles.DefaultProfileManager;
|
||||
import org.apache.maven.profiles.ProfileActivationContext;
|
||||
import org.apache.maven.profiles.ProfileActivationException;
|
||||
import org.apache.maven.profiles.ProfileManagerInfo;
|
||||
import org.apache.maven.profiles.ProfileManager;
|
||||
|
@ -147,9 +146,14 @@ public class DefaultMavenProjectBuilder
|
|||
{
|
||||
throw new ProjectBuildingException( "", "Failed to activate pom profiles.");
|
||||
}
|
||||
|
||||
|
||||
try
|
||||
{
|
||||
for(Profile p : projectProfiles)
|
||||
{
|
||||
logger.debug("Merging profile into model (build): Model = " + domainModel.getId() + ", Profile = " + p.getId() );
|
||||
}
|
||||
|
||||
domainModel = ProcessorContext.mergeProfilesIntoModel( projectProfiles, domainModel );
|
||||
}
|
||||
catch ( IOException e )
|
||||
|
@ -159,7 +163,7 @@ public class DefaultMavenProjectBuilder
|
|||
//Interpolation
|
||||
MavenProject project = interpolateDomainModel( domainModel, configuration, pomFile );
|
||||
project.setActiveProfiles( projectProfiles );
|
||||
|
||||
|
||||
Build build = project.getBuild();
|
||||
// NOTE: setting this script-source root before path translation, because
|
||||
// the plugin tools compose basedir and scriptSourceRoot into a single file.
|
||||
|
@ -174,6 +178,8 @@ public class DefaultMavenProjectBuilder
|
|||
|
||||
return project;
|
||||
}
|
||||
|
||||
// private static void setRepositoriesOn(MavenProject project, )
|
||||
|
||||
//!! This is used by the RR plugin
|
||||
public MavenProject buildFromRepository( Artifact artifact, List<ArtifactRepository> remoteArtifactRepositories, ArtifactRepository localRepository, boolean allowStubs )
|
||||
|
@ -242,6 +248,11 @@ public class DefaultMavenProjectBuilder
|
|||
|
||||
try
|
||||
{
|
||||
for(Profile p : projectProfiles)
|
||||
{
|
||||
logger.debug("Merging profile into model (buildFromRepository): Model = " + domainModel.getId() + ", Profile = " + p.getId() );
|
||||
}
|
||||
|
||||
domainModel = ProcessorContext.mergeProfilesIntoModel( projectProfiles, domainModel );
|
||||
}
|
||||
catch ( IOException e )
|
||||
|
@ -471,6 +482,10 @@ public class DefaultMavenProjectBuilder
|
|||
Collection<Profile> profiles = DefaultProfileManager.getActiveProfiles(dm.getModel().getProfiles(), profileInfo);
|
||||
if(!profiles.isEmpty())
|
||||
{
|
||||
for(Profile p : profiles)
|
||||
{
|
||||
logger.debug("Merging profile into model: Model = " + dm.getId() + ", Profile = " + p.getId() );
|
||||
}
|
||||
profileModels.add(ProcessorContext.mergeProfilesIntoModel( profiles, dm ));
|
||||
}
|
||||
else
|
||||
|
|
|
@ -240,7 +240,15 @@ public class MavenProject
|
|||
}
|
||||
*/
|
||||
|
||||
setRemoteArtifactRepositories( (projectBuilderConfiguration.getRemoteRepositories() != null) ? projectBuilderConfiguration.getRemoteRepositories() : new ArrayList<ArtifactRepository>());
|
||||
setRemoteArtifactRepositories( (projectBuilderConfiguration.getRemoteRepositories() != null) ? projectBuilderConfiguration.getRemoteRepositories() : new ArrayList<ArtifactRepository>());
|
||||
for(Repository r: model.getPluginRepositories())
|
||||
{
|
||||
try {
|
||||
remoteArtifactRepositories.add(repositorySystem.buildArtifactRepository( r ));
|
||||
} catch (InvalidRepositoryException e) {
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -378,7 +386,7 @@ public class MavenProject
|
|||
{
|
||||
return remoteArtifactRepositories;
|
||||
}
|
||||
|
||||
|
||||
public boolean hasParent()
|
||||
{
|
||||
return getParent() != null;
|
||||
|
|
Loading…
Reference in New Issue