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.setDistributionManagement( p.getDistributionManagement() );
|
||||||
model.setProperties( p.getProperties() );
|
model.setProperties( p.getProperties() );
|
||||||
model.setModules( new ArrayList<String>(p.getModules() ) );
|
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>());
|
BuildProcessor proc = new BuildProcessor( new ArrayList<Processor>());
|
||||||
proc.processWithProfile( p.getBuild(), model);
|
proc.processWithProfile( p.getBuild(), model);
|
||||||
return model;
|
return model;
|
||||||
|
@ -548,6 +551,9 @@ public class ProcessorContext
|
||||||
p.setBuild( copyBuild(profile.getBuild()) );
|
p.setBuild( copyBuild(profile.getBuild()) );
|
||||||
p.setId( profile.getId() );
|
p.setId( profile.getId() );
|
||||||
p.setActivation( profile.getActivation() );
|
p.setActivation( profile.getActivation() );
|
||||||
|
p.setRepositories(profile.getRepositories());
|
||||||
|
p.setPluginRepositories(profile.getPluginRepositories());
|
||||||
|
p.setReporting(profile.getReporting());
|
||||||
return p;
|
return p;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -22,11 +22,11 @@ package org.apache.maven.profiles;
|
||||||
import org.apache.maven.model.Activation;
|
import org.apache.maven.model.Activation;
|
||||||
import org.apache.maven.model.Model;
|
import org.apache.maven.model.Model;
|
||||||
import org.apache.maven.model.Profile;
|
import org.apache.maven.model.Profile;
|
||||||
import org.apache.maven.model.Parent;
|
|
||||||
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.ProfileManager;
|
import org.apache.maven.profiles.ProfileManager;
|
||||||
import org.apache.maven.profiles.matchers.DefaultMatcher;
|
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.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;
|
||||||
|
@ -50,7 +50,7 @@ public class DefaultProfileManager
|
||||||
private static final ProfileMatcher defaultMatcher = new DefaultMatcher();
|
private static final ProfileMatcher defaultMatcher = new DefaultMatcher();
|
||||||
|
|
||||||
private static final List<ProfileMatcher> matchers =
|
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
|
* 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> activeFromPom = new ArrayList<Profile>();
|
||||||
List<Profile> activeExternal = new ArrayList<Profile>();
|
List<Profile> activeExternal = new ArrayList<Profile>();
|
||||||
|
|
||||||
for ( Iterator it = profilesById.entrySet().iterator(); it.hasNext(); )
|
for ( Iterator it = profilesById.entrySet().iterator(); it.hasNext(); )
|
||||||
{
|
{
|
||||||
Map.Entry entry = (Entry) it.next();
|
Map.Entry entry = (Entry) it.next();
|
||||||
|
@ -142,17 +141,8 @@ public class DefaultProfileManager
|
||||||
String profileId = (String) entry.getKey();
|
String profileId = (String) entry.getKey();
|
||||||
Profile profile = (Profile) entry.getValue();
|
Profile profile = (Profile) entry.getValue();
|
||||||
|
|
||||||
boolean shouldAdd = false;
|
if ( !profileActivationContext.isExplicitlyInactive( profileId )
|
||||||
if ( profileActivationContext.isExplicitlyActive( profileId ) )
|
&& (profileActivationContext.isExplicitlyActive( profileId ) || isActive( profile, profileActivationContext ) ) )
|
||||||
{
|
|
||||||
shouldAdd = true;
|
|
||||||
}
|
|
||||||
else if ( isActive( profile, profileActivationContext ) )
|
|
||||||
{
|
|
||||||
shouldAdd = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
if ( !profileActivationContext.isExplicitlyInactive( profileId ) && shouldAdd )
|
|
||||||
{
|
{
|
||||||
if ( "pom".equals( profile.getSource() ) )
|
if ( "pom".equals( profile.getSource() ) )
|
||||||
{
|
{
|
||||||
|
@ -207,7 +197,10 @@ public class DefaultProfileManager
|
||||||
List<Profile> projectProfiles = new ArrayList<Profile>();
|
List<Profile> projectProfiles = new ArrayList<Profile>();
|
||||||
ProfileManager externalProfileManager = config.getGlobalProfileManager();
|
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();
|
externalProfileManager.getProfileActivationContext();
|
||||||
|
|
||||||
if(externalProfileManager != null)
|
if(externalProfileManager != null)
|
||||||
|
|
|
@ -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;
|
||||||
|
}
|
||||||
|
}
|
|
@ -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.MavenXpp3Reader;
|
||||||
import org.apache.maven.model.io.xpp3.MavenXpp3Writer;
|
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.ProfileActivationException;
|
import org.apache.maven.profiles.ProfileActivationException;
|
||||||
import org.apache.maven.profiles.ProfileManagerInfo;
|
import org.apache.maven.profiles.ProfileManagerInfo;
|
||||||
import org.apache.maven.profiles.ProfileManager;
|
import org.apache.maven.profiles.ProfileManager;
|
||||||
|
@ -150,6 +149,11 @@ public class DefaultMavenProjectBuilder
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
|
for(Profile p : projectProfiles)
|
||||||
|
{
|
||||||
|
logger.debug("Merging profile into model (build): Model = " + domainModel.getId() + ", Profile = " + p.getId() );
|
||||||
|
}
|
||||||
|
|
||||||
domainModel = ProcessorContext.mergeProfilesIntoModel( projectProfiles, domainModel );
|
domainModel = ProcessorContext.mergeProfilesIntoModel( projectProfiles, domainModel );
|
||||||
}
|
}
|
||||||
catch ( IOException e )
|
catch ( IOException e )
|
||||||
|
@ -175,6 +179,8 @@ public class DefaultMavenProjectBuilder
|
||||||
return project;
|
return project;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// private static void setRepositoriesOn(MavenProject project, )
|
||||||
|
|
||||||
//!! This is used by the RR plugin
|
//!! This is used by the RR plugin
|
||||||
public MavenProject buildFromRepository( Artifact artifact, List<ArtifactRepository> remoteArtifactRepositories, ArtifactRepository localRepository, boolean allowStubs )
|
public MavenProject buildFromRepository( Artifact artifact, List<ArtifactRepository> remoteArtifactRepositories, ArtifactRepository localRepository, boolean allowStubs )
|
||||||
throws ProjectBuildingException
|
throws ProjectBuildingException
|
||||||
|
@ -242,6 +248,11 @@ public class DefaultMavenProjectBuilder
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
|
for(Profile p : projectProfiles)
|
||||||
|
{
|
||||||
|
logger.debug("Merging profile into model (buildFromRepository): Model = " + domainModel.getId() + ", Profile = " + p.getId() );
|
||||||
|
}
|
||||||
|
|
||||||
domainModel = ProcessorContext.mergeProfilesIntoModel( projectProfiles, domainModel );
|
domainModel = ProcessorContext.mergeProfilesIntoModel( projectProfiles, domainModel );
|
||||||
}
|
}
|
||||||
catch ( IOException e )
|
catch ( IOException e )
|
||||||
|
@ -471,6 +482,10 @@ public class DefaultMavenProjectBuilder
|
||||||
Collection<Profile> profiles = DefaultProfileManager.getActiveProfiles(dm.getModel().getProfiles(), profileInfo);
|
Collection<Profile> profiles = DefaultProfileManager.getActiveProfiles(dm.getModel().getProfiles(), profileInfo);
|
||||||
if(!profiles.isEmpty())
|
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 ));
|
profileModels.add(ProcessorContext.mergeProfilesIntoModel( profiles, dm ));
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
|
|
@ -241,6 +241,14 @@ 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) {
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
Loading…
Reference in New Issue