Moved over the profile code to maven-project-builder. Centralizing more of the model building.

git-svn-id: https://svn.apache.org/repos/asf/maven/components/trunk@765802 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Britton Isbell 2009-04-16 23:41:31 +00:00
parent 554927a598
commit f117208e6b
21 changed files with 32 additions and 61 deletions

View File

@ -263,7 +263,7 @@ END SNIPPET: ant-bootstrap -->
<modello file="maven-model/src/main/mdo/maven.mdo" version="4.0.0"/> <modello file="maven-model/src/main/mdo/maven.mdo" version="4.0.0"/>
<modello file="maven-lifecycle/src/main/mdo/maven-lifecycle.mdo"/> <modello file="maven-lifecycle/src/main/mdo/maven-lifecycle.mdo"/>
<modello file="maven-plugin-api/src/main/mdo/lifecycle.mdo"/> <modello file="maven-plugin-api/src/main/mdo/lifecycle.mdo"/>
<modello file="maven-project/src/main/mdo/profiles.mdo"/> <modello file="maven-project-builder/src/main/mdo/profiles.mdo"/>
<modello file="maven-core/src/main/mdo/settings.mdo"/> <modello file="maven-core/src/main/mdo/settings.mdo"/>
<modello file="maven-toolchain/src/main/mdo/toolchains.xml"/> <modello file="maven-toolchain/src/main/mdo/toolchains.xml"/>
<modello file="maven-compat/src/main/mdo/metadata.mdo"/> <modello file="maven-compat/src/main/mdo/metadata.mdo"/>

View File

@ -166,7 +166,7 @@ END SNIPPET: ant-bootstrap -->
<modello file="maven-model/src/main/mdo/maven.mdo" version="4.0.0"/> <modello file="maven-model/src/main/mdo/maven.mdo" version="4.0.0"/>
<modello file="maven-lifecycle/src/main/mdo/maven-lifecycle.mdo"/> <modello file="maven-lifecycle/src/main/mdo/maven-lifecycle.mdo"/>
<modello file="maven-plugin-api/src/main/mdo/lifecycle.mdo"/> <modello file="maven-plugin-api/src/main/mdo/lifecycle.mdo"/>
<modello file="maven-project/src/main/mdo/profiles.mdo"/> <modello file="maven-project-builder/src/main/mdo/profiles.mdo"/>
<modello file="maven-core/src/main/mdo/settings.mdo"/> <modello file="maven-core/src/main/mdo/settings.mdo"/>
<modello file="maven-toolchain/src/main/mdo/toolchains.xml"/> <modello file="maven-toolchain/src/main/mdo/toolchains.xml"/>
<modello file="maven-compat/src/main/mdo/metadata.mdo"/> <modello file="maven-compat/src/main/mdo/metadata.mdo"/>

View File

@ -65,7 +65,7 @@ public class PomConstructionWithSettingsTest
Settings settings = readSettingsFile(settingsFile); Settings settings = readSettingsFile(settingsFile);
ProfileActivationContext pCtx = new ProfileActivationContext(null, true); ProfileActivationContext pCtx = new ProfileActivationContext(null, true);
ProfileManager profileManager = new DefaultProfileManager(getContainer(), pCtx); ProfileManager profileManager = new DefaultProfileManager(pCtx);
for ( org.apache.maven.settings.Profile rawProfile : settings.getProfiles() ) for ( org.apache.maven.settings.Profile rawProfile : settings.getProfiles() )
{ {

View File

@ -526,7 +526,7 @@ public class DefaultMavenExecutionRequestPopulator
activationContext.setExplicitlyActiveProfileIds( request.getActiveProfiles() ); activationContext.setExplicitlyActiveProfileIds( request.getActiveProfiles() );
activationContext.setExplicitlyInactiveProfileIds( request.getInactiveProfiles() ); activationContext.setExplicitlyInactiveProfileIds( request.getInactiveProfiles() );
ProfileManager globalProfileManager = new DefaultProfileManager( container, activationContext ); ProfileManager globalProfileManager = new DefaultProfileManager( activationContext );
request.setProfileManager( globalProfileManager ); request.setProfileManager( globalProfileManager );
request.setProfileActivationContext( activationContext ); request.setProfileActivationContext( activationContext );

View File

@ -30,11 +30,8 @@ import org.apache.maven.profiles.matchers.FileMatcher;
import org.apache.maven.profiles.matchers.JdkMatcher; import org.apache.maven.profiles.matchers.JdkMatcher;
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.project.ProjectBuilderConfiguration;
import org.apache.maven.project.builder.InterpolatorProperty; import org.apache.maven.project.builder.InterpolatorProperty;
import org.apache.maven.project.builder.PomInterpolatorTag; import org.apache.maven.project.builder.PomInterpolatorTag;
import org.codehaus.plexus.PlexusContainer;
import org.codehaus.plexus.MutablePlexusContainer;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Arrays; import java.util.Arrays;
@ -48,7 +45,6 @@ import java.util.Properties;
public class DefaultProfileManager public class DefaultProfileManager
implements ProfileManager implements ProfileManager
{ {
private MutablePlexusContainer container;
private Map<String, Profile> profilesById = new LinkedHashMap<String, Profile>(); private Map<String, Profile> profilesById = new LinkedHashMap<String, Profile>();
@ -63,9 +59,8 @@ public class DefaultProfileManager
* 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
*/ */
public DefaultProfileManager( PlexusContainer container, ProfileActivationContext profileActivationContext ) public DefaultProfileManager( ProfileActivationContext profileActivationContext )
{ {
this.container = (MutablePlexusContainer) container;
if ( profileActivationContext == null ) if ( profileActivationContext == null )
{ {
this.profileActivationContext = createDefaultActivationContext(); this.profileActivationContext = createDefaultActivationContext();
@ -76,17 +71,6 @@ public class DefaultProfileManager
} }
} }
// TODO: Remove this, if possible. It uses system properties, which are not safe for IDE and other embedded environments.
/**
* @deprecated Using this is dangerous when extensions or non-global system properties are in play.
*/
public DefaultProfileManager( PlexusContainer container )
{
this.container = (MutablePlexusContainer) container;
profileActivationContext = createDefaultActivationContext();
}
private ProfileActivationContext createDefaultActivationContext() private ProfileActivationContext createDefaultActivationContext()
{ {
@ -118,7 +102,7 @@ public class DefaultProfileManager
Profile existing = profilesById.get( profileId ); Profile existing = profilesById.get( profileId );
if ( existing != null ) if ( existing != null )
{ {
container.getLogger().warn( "Overriding profile: \'" + profileId + "\' (source: " + existing.getSource() + System.out.println( "Overriding profile: \'" + profileId + "\' (source: " + existing.getSource() +
") with new instance from source: " + profile.getSource() ); ") with new instance from source: " + profile.getSource() );
} }
@ -196,26 +180,21 @@ public class DefaultProfileManager
return allActive; return allActive;
} }
public static List<Profile> getActiveProfilesFrom(ProjectBuilderConfiguration config, Model model, PlexusContainer container) public static List<Profile> getActiveProfilesFrom(ProfileManager globalProfileManager, Properties properties, Model model)
throws ProfileActivationException throws ProfileActivationException
{ {
List<Profile> projectProfiles = new ArrayList<Profile>(); List<Profile> projectProfiles = new ArrayList<Profile>();
ProfileManager externalProfileManager = config.getGlobalProfileManager();
Properties props = new Properties(); ProfileActivationContext profileActivationContext = (globalProfileManager == null) ? new ProfileActivationContext( new Properties(), false ):
props.putAll(config.getExecutionProperties()); globalProfileManager.getProfileActivationContext();
props.putAll(config.getUserProperties()); profileActivationContext.getExecutionProperties().putAll(properties);
ProfileActivationContext profileActivationContext = (externalProfileManager == null) ? new ProfileActivationContext( new Properties(), false ): if(globalProfileManager != null)
externalProfileManager.getProfileActivationContext();
profileActivationContext.getExecutionProperties().putAll(props);
if(externalProfileManager != null)
{ {
projectProfiles.addAll( externalProfileManager.getActiveProfiles() ); projectProfiles.addAll( globalProfileManager.getActiveProfiles() );
} }
ProfileManager profileManager = new DefaultProfileManager( container, profileActivationContext ); ProfileManager profileManager = new DefaultProfileManager( profileActivationContext );
profileManager.addProfiles( model.getProfiles() ); profileManager.addProfiles( model.getProfiles() );
projectProfiles.addAll( profileManager.getActiveProfiles() ); projectProfiles.addAll( profileManager.getActiveProfiles() );
return projectProfiles; return projectProfiles;

View File

@ -27,7 +27,6 @@ import java.util.Properties;
public class ProfileActivationContext public class ProfileActivationContext
{ {
private boolean isCustomActivatorFailureSuppressed; private boolean isCustomActivatorFailureSuppressed;
private final Properties executionProperties; private final Properties executionProperties;

View File

@ -60,10 +60,6 @@ under the License.
<groupId>org.codehaus.woodstox</groupId> <groupId>org.codehaus.woodstox</groupId>
<artifactId>wstx-asl</artifactId> <artifactId>wstx-asl</artifactId>
</dependency> </dependency>
<dependency>
<groupId>org.sonatype.spice</groupId>
<artifactId>model-builder</artifactId>
</dependency>
<dependency> <dependency>
<groupId>org.apache.maven</groupId> <groupId>org.apache.maven</groupId>
<artifactId>maven-project-builder</artifactId> <artifactId>maven-project-builder</artifactId>
@ -92,16 +88,6 @@ under the License.
<groupId>org.codehaus.plexus</groupId> <groupId>org.codehaus.plexus</groupId>
<artifactId>plexus-component-metadata</artifactId> <artifactId>plexus-component-metadata</artifactId>
</plugin> </plugin>
<plugin>
<groupId>org.codehaus.modello</groupId>
<artifactId>modello-maven-plugin</artifactId>
<configuration>
<version>1.0.0</version>
<models>
<model>src/main/mdo/profiles.mdo</model>
</models>
</configuration>
</plugin>
</plugins> </plugins>
</build> </build>
</project> </project>

View File

@ -22,6 +22,7 @@ import java.text.SimpleDateFormat;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collection; import java.util.Collection;
import java.util.HashMap; import java.util.HashMap;
import java.util.Properties;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
@ -134,9 +135,12 @@ public class DefaultMavenProjectBuilder
//Profiles //Profiles
List<Profile> projectProfiles; List<Profile> projectProfiles;
Properties props = new Properties();
props.putAll(configuration.getExecutionProperties());
props.putAll(configuration.getUserProperties());
try try
{ {
projectProfiles = DefaultProfileManager.getActiveProfilesFrom(configuration, domainModel.getModel(), container); projectProfiles = DefaultProfileManager.getActiveProfilesFrom(configuration.getGlobalProfileManager(), props, domainModel.getModel() );
} }
catch ( ProfileActivationException e ) catch ( ProfileActivationException e )
{ {
@ -239,9 +243,13 @@ public class DefaultMavenProjectBuilder
} }
List<Profile> projectProfiles; List<Profile> projectProfiles;
Properties props = new Properties();
props.putAll(configuration.getExecutionProperties());
props.putAll(configuration.getUserProperties());
try try
{ {
projectProfiles = DefaultProfileManager.getActiveProfilesFrom(configuration, domainModel.getModel(), container); projectProfiles = DefaultProfileManager.getActiveProfilesFrom(configuration.getGlobalProfileManager(), props, domainModel.getModel() );
} }
catch ( ProfileActivationException e ) catch ( ProfileActivationException e )
{ {

View File

@ -25,7 +25,7 @@ import java.util.Properties;
import org.apache.maven.artifact.repository.ArtifactRepository; import org.apache.maven.artifact.repository.ArtifactRepository;
import org.apache.maven.profiles.ProfileManager; import org.apache.maven.profiles.ProfileManager;
import org.apache.maven.shared.model.ModelEventListener; import org.apache.maven.project.builder.ModelEventListener;
public class DefaultProjectBuilderConfiguration public class DefaultProjectBuilderConfiguration
implements ProjectBuilderConfiguration implements ProjectBuilderConfiguration

View File

@ -20,7 +20,6 @@ package org.apache.maven.profiles.manager;
*/ */
import org.apache.maven.model.Activation; import org.apache.maven.model.Activation;
import org.apache.maven.model.ActivationOS;
import org.apache.maven.model.ActivationProperty; import org.apache.maven.model.ActivationProperty;
import org.apache.maven.model.Profile; import org.apache.maven.model.Profile;
import org.apache.maven.profiles.DefaultProfileManager; import org.apache.maven.profiles.DefaultProfileManager;
@ -65,7 +64,7 @@ public class DefaultProfileManagerTest
Properties props = new Properties(); Properties props = new Properties();
ProfileActivationContext ctx = new ProfileActivationContext( props, false ); ProfileActivationContext ctx = new ProfileActivationContext( props, false );
ProfileManager profileManager = new DefaultProfileManager( getContainer(), ctx ); ProfileManager profileManager = new DefaultProfileManager( ctx );
profileManager.addProfile( notActivated ); profileManager.addProfile( notActivated );
profileManager.addProfile( defaultActivated ); profileManager.addProfile( defaultActivated );
@ -104,7 +103,7 @@ public class DefaultProfileManagerTest
Properties props = System.getProperties(); Properties props = System.getProperties();
ProfileActivationContext ctx = new ProfileActivationContext( props, false ); ProfileActivationContext ctx = new ProfileActivationContext( props, false );
ProfileManager profileManager = new DefaultProfileManager( getContainer(), ctx ); ProfileManager profileManager = new DefaultProfileManager( ctx );
profileManager.addProfile( syspropActivated ); profileManager.addProfile( syspropActivated );
profileManager.addProfile( defaultActivated ); profileManager.addProfile( defaultActivated );
@ -135,7 +134,7 @@ public class DefaultProfileManagerTest
Properties props = System.getProperties(); Properties props = System.getProperties();
ProfileActivationContext ctx = new ProfileActivationContext( props, false ); ProfileActivationContext ctx = new ProfileActivationContext( props, false );
ProfileManager profileManager = new DefaultProfileManager( getContainer(), ctx ); ProfileManager profileManager = new DefaultProfileManager( ctx );
profileManager.addProfile( syspropActivated ); profileManager.addProfile( syspropActivated );
@ -163,7 +162,7 @@ public class DefaultProfileManagerTest
Properties props = System.getProperties(); Properties props = System.getProperties();
ProfileActivationContext ctx = new ProfileActivationContext( props, false ); ProfileActivationContext ctx = new ProfileActivationContext( props, false );
ProfileManager profileManager = new DefaultProfileManager( getContainer(), ctx ); ProfileManager profileManager = new DefaultProfileManager( ctx );
profileManager.addProfile( syspropActivated ); profileManager.addProfile( syspropActivated );
@ -194,7 +193,7 @@ public class DefaultProfileManagerTest
Properties props = System.getProperties(); Properties props = System.getProperties();
ProfileActivationContext ctx = new ProfileActivationContext( props, false ); ProfileActivationContext ctx = new ProfileActivationContext( props, false );
ProfileManager profileManager = new DefaultProfileManager( getContainer(), ctx ); ProfileManager profileManager = new DefaultProfileManager( ctx );
profileManager.addProfile( syspropActivated ); profileManager.addProfile( syspropActivated );

View File

@ -139,7 +139,7 @@ public abstract class AbstractMavenProjectTestCase
ProjectBuilderConfiguration pbc = new DefaultProjectBuilderConfiguration(); ProjectBuilderConfiguration pbc = new DefaultProjectBuilderConfiguration();
pbc.setLocalRepository( getLocalRepository() ); pbc.setLocalRepository( getLocalRepository() );
pbc.setGlobalProfileManager( new DefaultProfileManager( getContainer(), ctx ) ); pbc.setGlobalProfileManager( new DefaultProfileManager( ctx ) );
return projectBuilder.build( pom, pbc ); return projectBuilder.build( pom, pbc );
} }

View File

@ -1393,7 +1393,7 @@ public class PomConstructionTest
ProfileActivationContext pCtx = new ProfileActivationContext(null, true); ProfileActivationContext pCtx = new ProfileActivationContext(null, true);
config.setExecutionProperties(properties); config.setExecutionProperties(properties);
config.setGlobalProfileManager(new DefaultProfileManager(this.getContainer(), pCtx)); config.setGlobalProfileManager(new DefaultProfileManager(pCtx));
return new PomTestWrapper( pomFile, mavenProjectBuilder.build( pomFile, config ) ); return new PomTestWrapper( pomFile, mavenProjectBuilder.build( pomFile, config ) );
} }
@ -1413,7 +1413,7 @@ public class PomConstructionTest
pCtx.setExplicitlyActiveProfileIds( Arrays.asList( profileIds ) ); pCtx.setExplicitlyActiveProfileIds( Arrays.asList( profileIds ) );
} }
config.setGlobalProfileManager(new DefaultProfileManager(this.getContainer(), pCtx)); config.setGlobalProfileManager(new DefaultProfileManager(pCtx));
return new PomTestWrapper( pomFile, mavenProjectBuilder.build( pomFile, config ) ); return new PomTestWrapper( pomFile, mavenProjectBuilder.build( pomFile, config ) );
} }