Working on: MNG-483

Fixing profile application to separate profiles discovered in and around POM from those in settings.xml, and apply them separately in the order: 

for-each-project-in-inheritance:{POM, profiles.xml}, settings.xml

Added common interface for accumulating, explicitly activating and deactivating, and retrieving profiles to be applied to a given project. This manager interface (ProfileManager) is general enough to be applicable to both the project-level and settings-level profiles.

Added 'performRelease'-keyed profile to super-POM which will be used by the release plugin and anyone using a parallel process, and which will enable '-DupdateReleaseInfo=true' for the deploy mojo, along with enabling the source attachment for the project.

Added 'attach' parameter to JarSourceMojo to allow local POM to turn off source attachments, overriding release profile in super-pom.

Updated the release:perform mojo to use '-DperformRelease=true' for switching on the new release profile, rather than just using '-DupdateReleaseInfo=true'...



git-svn-id: https://svn.apache.org/repos/asf/maven/components/trunk@233013 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
John Dennis Casey 2005-08-16 16:31:02 +00:00
parent 531c1c4f79
commit fe5a91b0d6
26 changed files with 595 additions and 375 deletions

View File

@ -31,10 +31,8 @@ import org.apache.maven.model.Profile;
import org.apache.maven.monitor.event.EventDispatcher;
import org.apache.maven.monitor.event.MavenEvents;
import org.apache.maven.plugin.MojoExecutionException;
import org.apache.maven.profiles.AlwaysOnActivation;
import org.apache.maven.profiles.MavenProfilesBuilder;
import org.apache.maven.profiles.ProfilesConversionUtils;
import org.apache.maven.profiles.ProfilesRoot;
import org.apache.maven.profiles.ProfileManager;
import org.apache.maven.profiles.activation.ProfileActivationException;
import org.apache.maven.project.MavenProject;
import org.apache.maven.project.MavenProjectBuilder;
import org.apache.maven.project.ProjectBuildingException;
@ -55,7 +53,6 @@ import org.codehaus.plexus.logging.AbstractLogEnabled;
import org.codehaus.plexus.personality.plexus.lifecycle.phase.Contextualizable;
import org.codehaus.plexus.util.FileUtils;
import org.codehaus.plexus.util.dag.CycleDetectedException;
import org.codehaus.plexus.util.xml.pull.XmlPullParserException;
import java.io.File;
import java.io.IOException;
@ -82,15 +79,13 @@ public class DefaultMaven
// ----------------------------------------------------------------------
protected MavenProjectBuilder projectBuilder;
protected LifecycleExecutor lifecycleExecutor;
protected PlexusContainer container;
protected Map errorDiagnosers;
protected MavenProfilesBuilder profilesBuilder;
protected RuntimeInformation runtimeInformation;
private static final long MB = 1024 * 1024;
@ -132,22 +127,23 @@ public class DefaultMaven
ReactorManager rm;
ProfileManager globalProfileManager = request.getGlobalProfileManager();
try
{
loadSettingsProfiles( globalProfileManager, request.getSettings() );
List files = getProjectFiles( request );
List projects = collectProjects( files, request.getLocalRepository(), request.isRecursive(),
request.getSettings() );
request.getSettings(), globalProfileManager );
// the reasoning here is that the list is still unsorted according to dependency, so the first project
// SHOULD BE the top-level, or the one we want to start with if we're doing an aggregated build.
if ( projects.isEmpty() )
{
List externalProfiles = getActiveExternalProfiles( null, request.getSettings() );
MavenProject superProject = projectBuilder.buildStandaloneSuperProject( request.getLocalRepository(),
externalProfiles );
MavenProject superProject = projectBuilder.buildStandaloneSuperProject( request.getLocalRepository() );
projects.add( superProject );
}
@ -176,6 +172,10 @@ public class DefaultMaven
{
return dispatchErrorResponse( dispatcher, event, request.getBaseDirectory(), e );
}
catch ( ProfileActivationException e )
{
return dispatchErrorResponse( dispatcher, event, request.getBaseDirectory(), e );
}
try
{
@ -324,8 +324,9 @@ public class DefaultMaven
return response;
}
private List collectProjects( List files, ArtifactRepository localRepository, boolean recursive, Settings settings )
throws ProjectBuildingException, ReactorException, IOException, ArtifactResolutionException
private List collectProjects( List files, ArtifactRepository localRepository, boolean recursive, Settings settings,
ProfileManager globalProfileManager )
throws ProjectBuildingException, ReactorException, IOException, ArtifactResolutionException, ProfileActivationException
{
List projects = new ArrayList( files.size() );
@ -338,7 +339,7 @@ public class DefaultMaven
getLogger().info( "NOTE: Using release-pom: " + file + " in reactor build." );
}
MavenProject project = getProject( file, localRepository, settings );
MavenProject project = getProject( file, localRepository, settings, globalProfileManager );
if ( project.getPrerequesites() != null && project.getPrerequesites().getMaven() != null )
{
@ -365,7 +366,7 @@ public class DefaultMaven
moduleFiles.add( new File( basedir, name + "/pom.xml" ) );
}
List collectedProjects = collectProjects( moduleFiles, localRepository, recursive, settings );
List collectedProjects = collectProjects( moduleFiles, localRepository, recursive, settings, globalProfileManager );
projects.addAll( collectedProjects );
project.setCollectedProjects( collectedProjects );
}
@ -375,8 +376,9 @@ public class DefaultMaven
return projects;
}
public MavenProject getProject( File pom, ArtifactRepository localRepository, Settings settings )
throws ProjectBuildingException, ArtifactResolutionException
public MavenProject getProject( File pom, ArtifactRepository localRepository, Settings settings,
ProfileManager globalProfileManager )
throws ProjectBuildingException, ArtifactResolutionException, ProfileActivationException
{
if ( pom.exists() )
{
@ -387,22 +389,18 @@ public class DefaultMaven
}
}
List externalProfiles = getActiveExternalProfiles( pom, settings );
return projectBuilder.build( pom, localRepository, externalProfiles );
return projectBuilder.build( pom, localRepository, globalProfileManager );
}
private List getActiveExternalProfiles( File pom, Settings settings )
throws ProjectBuildingException
private void loadSettingsProfiles( ProfileManager profileManager, Settings settings )
{
// TODO: apply profiles.xml and settings.xml Profiles here.
List externalProfiles = new ArrayList();
List settingsProfiles = settings.getProfiles();
if ( settingsProfiles != null && !settingsProfiles.isEmpty() )
{
List settingsActiveProfileIds = settings.getActiveProfiles();
profileManager.explicitlyActivate( settingsActiveProfileIds );
for ( Iterator it = settings.getProfiles().iterator(); it.hasNext(); )
{
@ -410,44 +408,12 @@ public class DefaultMaven
Profile profile = SettingsUtils.convertFromSettingsProfile( rawProfile );
if ( settingsActiveProfileIds.contains( rawProfile.getId() ) )
{
profile.setActivation( new AlwaysOnActivation() );
}
externalProfiles.add( profile );
profileManager.addProfile( profile );
}
}
if ( pom != null )
{
try
{
ProfilesRoot root = profilesBuilder.buildProfiles( pom.getParentFile() );
if ( root != null )
{
for ( Iterator it = root.getProfiles().iterator(); it.hasNext(); )
{
org.apache.maven.profiles.Profile rawProfile = (org.apache.maven.profiles.Profile) it.next();
externalProfiles.add( ProfilesConversionUtils.convertFromProfileXmlProfile( rawProfile ) );
}
}
}
catch ( IOException e )
{
throw new ProjectBuildingException( "Cannot read profiles.xml resource for pom: " + pom, e );
}
catch ( XmlPullParserException e )
{
throw new ProjectBuildingException( "Cannot parse profiles.xml resource for pom: " + pom, e );
}
}
return externalProfiles;
}
// ----------------------------------------------------------------------
// Methods used by all execution request handlers
// ----------------------------------------------------------------------

View File

@ -38,7 +38,8 @@ import org.apache.maven.monitor.event.DefaultEventDispatcher;
import org.apache.maven.monitor.event.DefaultEventMonitor;
import org.apache.maven.monitor.event.EventDispatcher;
import org.apache.maven.plugin.Mojo;
import org.apache.maven.profiles.activation.ProfileActivationUtils;
import org.apache.maven.profiles.DefaultProfileManager;
import org.apache.maven.profiles.ProfileManager;
import org.apache.maven.reactor.ReactorException;
import org.apache.maven.settings.MavenSettingsBuilder;
import org.apache.maven.settings.Settings;
@ -55,6 +56,7 @@ import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.util.Properties;
import java.util.StringTokenizer;
/**
* @author <a href="mailto:jason@maven.org">Jason van Zyl</a>
@ -112,12 +114,6 @@ public class MavenCli
initializeSystemProperties( commandLine );
if ( commandLine.hasOption( CLIManager.ACTIVATE_PROFILES ) )
{
System.setProperty( ProfileActivationUtils.ACTIVE_PROFILE_IDS,
commandLine.getOptionValue( CLIManager.ACTIVATE_PROFILES ) );
}
boolean debug = commandLine.hasOption( CLIManager.DEBUG );
boolean showErrors = debug || commandLine.hasOption( CLIManager.ERRORS );
@ -240,17 +236,45 @@ public class MavenCli
Maven maven = null;
MavenExecutionRequest request = null;
LoggerManager manager = null;
LoggerManager loggerManager = null;
try
{
// logger must be created first
manager = (LoggerManager) embedder.lookup( LoggerManager.ROLE );
loggerManager = (LoggerManager) embedder.lookup( LoggerManager.ROLE );
if ( debug )
{
manager.setThreshold( Logger.LEVEL_DEBUG );
loggerManager.setThreshold( Logger.LEVEL_DEBUG );
}
ProfileManager profileManager = new DefaultProfileManager( embedder.getContainer() );
if ( commandLine.hasOption( CLIManager.ACTIVATE_PROFILES ) )
{
String profilesLine = commandLine.getOptionValue( CLIManager.ACTIVATE_PROFILES );
StringTokenizer profileTokens = new StringTokenizer( profilesLine, "," );
while( profileTokens.hasMoreTokens() )
{
String profileAction = profileTokens.nextToken().trim();
if ( profileAction.startsWith( "-" ) )
{
profileManager.explicitlyDeactivate( profileAction.substring( 1 ) );
}
else if ( profileAction.startsWith( "+" ) )
{
profileManager.explicitlyActivate(profileAction.substring( 1 ) );
}
else
{
// TODO: deprecate this eventually!
profileManager.explicitlyActivate( profileAction );
}
}
}
request = createRequest( embedder, commandLine, settings, eventDispatcher, manager );
request = createRequest( embedder, commandLine, settings, eventDispatcher, loggerManager, profileManager );
setProjectFileOptions( commandLine, request );
@ -263,11 +287,11 @@ public class MavenCli
}
finally
{
if ( manager != null )
if ( loggerManager != null )
{
try
{
embedder.release( manager );
embedder.release( loggerManager );
}
catch ( ComponentLifecycleException e )
{
@ -324,7 +348,7 @@ public class MavenCli
private static MavenExecutionRequest createRequest( Embedder embedder, CommandLine commandLine,
Settings settings, EventDispatcher eventDispatcher,
LoggerManager manager )
LoggerManager loggerManager, ProfileManager profileManager )
throws ComponentLookupException
{
MavenExecutionRequest request = null;
@ -332,10 +356,10 @@ public class MavenCli
ArtifactRepository localRepository = createLocalRepository( embedder, settings, commandLine );
request = new DefaultMavenExecutionRequest( localRepository, settings, eventDispatcher,
commandLine.getArgList(), userDir.getPath() );
commandLine.getArgList(), userDir.getPath(), profileManager );
// TODO [BP]: do we set one per mojo? where to do it?
Logger logger = manager.getLoggerForComponent( Mojo.ROLE );
Logger logger = loggerManager.getLoggerForComponent( Mojo.ROLE );
if ( logger != null )
{
request.addEventMonitor( new DefaultEventMonitor( logger ) );

View File

@ -19,6 +19,7 @@ package org.apache.maven.execution;
import org.apache.maven.artifact.repository.ArtifactRepository;
import org.apache.maven.monitor.event.EventDispatcher;
import org.apache.maven.monitor.event.EventMonitor;
import org.apache.maven.profiles.ProfileManager;
import org.apache.maven.settings.Settings;
import java.util.List;
@ -53,8 +54,11 @@ public class DefaultMavenExecutionRequest
private String failureBehavior;
private final ProfileManager globalProfileManager;
public DefaultMavenExecutionRequest( ArtifactRepository localRepository, Settings settings,
EventDispatcher eventDispatcher, List goals, String baseDirectory )
EventDispatcher eventDispatcher, List goals, String baseDirectory,
ProfileManager globalProfileManager )
{
this.localRepository = localRepository;
@ -65,6 +69,8 @@ public class DefaultMavenExecutionRequest
this.eventDispatcher = eventDispatcher;
this.baseDirectory = baseDirectory;
this.globalProfileManager = globalProfileManager;
}
public Settings getSettings()
@ -150,4 +156,9 @@ public class DefaultMavenExecutionRequest
{
return failureBehavior;
}
public ProfileManager getGlobalProfileManager()
{
return globalProfileManager;
}
}

View File

@ -19,6 +19,7 @@ package org.apache.maven.execution;
import org.apache.maven.artifact.repository.ArtifactRepository;
import org.apache.maven.monitor.event.EventDispatcher;
import org.apache.maven.monitor.event.EventMonitor;
import org.apache.maven.profiles.ProfileManager;
import org.apache.maven.settings.Settings;
import java.util.List;
@ -60,4 +61,6 @@ public interface MavenExecutionRequest
void setFailureBehavior( String failureBehavior );
String getFailureBehavior();
ProfileManager getGlobalProfileManager();
}

View File

@ -71,9 +71,6 @@
<role>org.apache.maven.usability.ErrorDiagnoser</role>
<field-name>errorDiagnosers</field-name>
</requirement>
<requirement>
<role>org.apache.maven.profiles.MavenProfilesBuilder</role>
</requirement>
<requirement>
<role>org.apache.maven.execution.RuntimeInformation</role>
</requirement>

View File

@ -40,7 +40,7 @@ public class MBoot
String[] builds = new String[]{"maven-model", "maven-settings", "maven-monitor", "maven-plugin-api",
"maven-artifact", "maven-plugin-descriptor", "maven-artifact-manager", "maven-artifact-test",
"maven-plugin-mapping",
"maven-script/maven-script-beanshell", "maven-script/maven-script-marmalade", "maven-project", "maven-profile",
"maven-script/maven-script-beanshell", "maven-script/maven-script-marmalade", "maven-profile", "maven-project",
"maven-plugin-registry", "maven-reporting/maven-reporting-api", "maven-reporting/maven-reporting-impl", "maven-core", "maven-archiver",
"maven-plugin-tools/maven-plugin-tools-api", "maven-plugin-tools/maven-plugin-tools-java",
"maven-plugin-tools/maven-plugin-tools-beanshell", "maven-plugin-tools/maven-plugin-tools-pluggy",

View File

@ -29,7 +29,6 @@ import java.io.File;
import java.io.FileReader;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Iterator;
import java.util.List;
@ -72,7 +71,7 @@ public class EclipsePluginTest
ArtifactRepository localRepository = new DefaultArtifactRepository( "local", "file://" + repo.getAbsolutePath(),
localRepositoryLayout );
MavenProject project = builder.buildWithDependencies( new File( basedir, "project.xml" ), localRepository, Collections.EMPTY_LIST );
MavenProject project = builder.buildWithDependencies( new File( basedir, "project.xml" ), localRepository, null );
for ( Iterator it = project.getArtifacts().iterator(); it.hasNext(); )
{

View File

@ -101,7 +101,7 @@ public class PerformReleaseMojo
cl.createArgument().setLine( goals );
cl.createArgument().setLine( "-DupdateReleaseInfo=true" );
cl.createArgument().setLine( "-DperformRelease=true" );
cl.createArgument().setLine( "--no-plugin-updates" );

View File

@ -54,6 +54,11 @@ public class JarSourceMojo
* @required
*/
private String finalName;
/**
* @parameter expression="${attach}" default-value="true"
*/
private boolean attach = true;
/**
* @parameter expression="${project.compileSourceRoots}"
@ -66,10 +71,17 @@ public class JarSourceMojo
* @required
*/
private File outputDirectory;
public void execute()
throws MojoExecutionException
{
if ( !attach )
{
getLog().info( "NOT adding java-sources to attached artifacts list." );
return;
}
// TODO: this should be via a release profile instead
if ( project.getVersion().indexOf( "SNAPSHOT" ) < 0 )
{

View File

@ -22,11 +22,11 @@
<artifactId>maven-model</artifactId>
<version>2.0-beta-1-SNAPSHOT</version>
</dependency>
<dependency>
<!-- dependency>
<groupId>org.apache.maven</groupId>
<artifactId>maven-project</artifactId>
<version>2.0-beta-1-SNAPSHOT</version>
</dependency>
</dependency -->
</dependencies>
<build>
<plugins>

View File

@ -18,6 +18,11 @@
<artifactId>maven-model</artifactId>
<version>2.0-beta-1-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>org.apache.maven</groupId>
<artifactId>maven-profile</artifactId>
<version>2.0-beta-1-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>org.apache.maven</groupId>
<artifactId>maven-artifact</artifactId>

View File

@ -0,0 +1,214 @@
package org.apache.maven.profiles;
import org.apache.maven.model.Profile;
import org.apache.maven.profiles.activation.ProfileActivationException;
import org.apache.maven.profiles.activation.ProfileActivator;
import org.codehaus.plexus.PlexusContainer;
import org.codehaus.plexus.component.repository.exception.ComponentLifecycleException;
import org.codehaus.plexus.component.repository.exception.ComponentLookupException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.Map.Entry;
/*
* Copyright 2001-2005 The Apache Software Foundation.
*
* Licensed 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.
*/
public class DefaultProfileManager implements ProfileManager
{
private PlexusContainer container;
private Set activatedIds = new HashSet();
private Set deactivatedIds = new HashSet();
private Map profilesById = new HashMap();
public DefaultProfileManager( PlexusContainer container )
{
this.container = container;
}
public DefaultProfileManager( ProfileManager globals, PlexusContainer container )
{
this.container = container;
this.activatedIds.addAll( globals.getActivatedIds() );
this.deactivatedIds.addAll( globals.getDeactivatedIds() );
this.profilesById.putAll( globals.getProfilesById() );
}
public Set getActivatedIds()
{
return activatedIds;
}
public Set getDeactivatedIds()
{
return deactivatedIds;
}
public Map getProfilesById()
{
return profilesById;
}
/* (non-Javadoc)
* @see org.apache.maven.profiles.ProfileManager#addProfile(org.apache.maven.model.Profile)
*/
public void addProfile( Profile profile )
{
String profileId = profile.getId();
Profile existing = (Profile) profilesById.get( profileId );
if ( existing != null )
{
container.getLogger().warn(
"Overriding profile: \'" + profileId + "\' (source: " + existing.getSource()
+ ") with new instance from source: " + profile.getSource() );
}
profilesById.put( profile.getId(), profile );
}
/* (non-Javadoc)
* @see org.apache.maven.profiles.ProfileManager#explicitlyActivate(java.lang.String)
*/
public void explicitlyActivate( String profileId )
{
container.getLogger().debug( "Profile with id: \'" + profileId + "\' has been explicitly activated." );
activatedIds.add( profileId );
}
/* (non-Javadoc)
* @see org.apache.maven.profiles.ProfileManager#explicitlyActivate(java.util.List)
*/
public void explicitlyActivate( List profileIds )
{
for ( Iterator it = profileIds.iterator(); it.hasNext(); )
{
String profileId = (String) it.next();
explicitlyActivate( profileId );
}
}
/* (non-Javadoc)
* @see org.apache.maven.profiles.ProfileManager#explicitlyDeactivate(java.lang.String)
*/
public void explicitlyDeactivate( String profileId )
{
container.getLogger().debug( "Profile with id: \'" + profileId + "\' has been explicitly deactivated." );
deactivatedIds.add( profileId );
}
/* (non-Javadoc)
* @see org.apache.maven.profiles.ProfileManager#explicitlyDeactivate(java.util.List)
*/
public void explicitlyDeactivate( List profileIds )
{
for ( Iterator it = profileIds.iterator(); it.hasNext(); )
{
String profileId = (String) it.next();
explicitlyDeactivate( profileId );
}
}
/* (non-Javadoc)
* @see org.apache.maven.profiles.ProfileManager#getActiveProfiles()
*/
public List getActiveProfiles() throws ProfileActivationException
{
List active = new ArrayList( profilesById.size() );
for ( Iterator it = profilesById.entrySet().iterator(); it.hasNext(); )
{
Map.Entry entry = (Entry) it.next();
String profileId = (String) entry.getKey();
Profile profile = (Profile) entry.getValue();
if ( activatedIds.contains( profileId ) )
{
active.add( profile );
}
else if ( !deactivatedIds.contains( profileId ) && isActive( profile ) )
{
active.add( profile );
}
}
return active;
}
private boolean isActive( Profile profile )
throws ProfileActivationException
{
List activators = null;
try
{
activators = container.lookupList( ProfileActivator.ROLE );
for ( Iterator activatorIterator = activators.iterator(); activatorIterator.hasNext(); )
{
ProfileActivator activator = (ProfileActivator) activatorIterator.next();
if ( activator.canDetermineActivation( profile ) )
{
return activator.isActive( profile );
}
}
return false;
}
catch ( ComponentLookupException e )
{
throw new ProfileActivationException( "Cannot retrieve list of profile activators.", e );
}
finally
{
try
{
container.releaseAll( activators );
}
catch ( ComponentLifecycleException e )
{
container.getLogger().debug( "Error releasing profile activators - ignoring.", e );
}
}
}
/* (non-Javadoc)
* @see org.apache.maven.profiles.ProfileManager#addProfiles(java.util.List)
*/
public void addProfiles( List profiles )
{
for ( Iterator it = profiles.iterator(); it.hasNext(); )
{
Profile profile = (Profile) it.next();
addProfile( profile );
}
}
}

View File

@ -0,0 +1,34 @@
package org.apache.maven.profiles;
import org.apache.maven.model.Profile;
import org.apache.maven.profiles.activation.ProfileActivationException;
import java.util.List;
import java.util.Map;
import java.util.Set;
public interface ProfileManager
{
void addProfile( Profile profile );
void explicitlyActivate( String profileId );
void explicitlyActivate( List profileIds );
void explicitlyDeactivate( String profileId );
void explicitlyDeactivate( List profileIds );
List getActiveProfiles()
throws ProfileActivationException;
void addProfiles( List profiles );
public Set getActivatedIds();
public Set getDeactivatedIds();
public Map getProfilesById();
}

View File

@ -23,7 +23,7 @@ public abstract class DetectedProfileActivator
{
public boolean canDetermineActivation( Profile profile )
{
return !ProfileActivationUtils.profilesWereExplicitlyGiven() && canDetectActivation( profile );
return canDetectActivation( profile );
}
protected abstract boolean canDetectActivation( Profile profile );

View File

@ -1,34 +0,0 @@
package org.apache.maven.profiles.activation;
import org.apache.maven.model.Profile;
/*
* Copyright 2001-2005 The Apache Software Foundation.
*
* Licensed 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.
*/
public class ExplicitListingProfileActivator
implements ProfileActivator
{
public boolean canDetermineActivation( Profile profile )
{
return ProfileActivationUtils.profilesWereExplicitlyGiven();
}
public boolean isActive( Profile profile )
{
return ProfileActivationUtils.getExplicitProfileList().contains( profile.getId() );
}
}

View File

@ -1,105 +0,0 @@
package org.apache.maven.profiles.activation;
import org.apache.maven.model.Activation;
import org.apache.maven.model.Profile;
import org.apache.maven.project.ProjectBuildingException;
import org.codehaus.plexus.PlexusConstants;
import org.codehaus.plexus.PlexusContainer;
import org.codehaus.plexus.component.repository.exception.ComponentLifecycleException;
import org.codehaus.plexus.component.repository.exception.ComponentLookupException;
import org.codehaus.plexus.context.Context;
import org.codehaus.plexus.context.ContextException;
import org.codehaus.plexus.logging.AbstractLogEnabled;
import org.codehaus.plexus.personality.plexus.lifecycle.phase.Contextualizable;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
/*
* Copyright 2001-2005 The Apache Software Foundation.
*
* Licensed 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.
*/
public class ProfileActivationCalculator
extends AbstractLogEnabled
implements Contextualizable
{
public static final String ROLE = ProfileActivationCalculator.class.getName();
private PlexusContainer container;
public List calculateActiveProfiles( List profiles )
throws ProjectBuildingException
{
List activators = null;
try
{
activators = container.lookupList( ProfileActivator.ROLE );
List active = new ArrayList( profiles.size() );
for ( Iterator it = profiles.iterator(); it.hasNext(); )
{
Profile profile = (Profile) it.next();
boolean isActive = true;
Activation activation = profile.getActivation();
activatorLoop:
for ( Iterator activatorIterator = activators.iterator(); activatorIterator.hasNext(); )
{
ProfileActivator activator = (ProfileActivator) activatorIterator.next();
if ( activator.canDetermineActivation( profile ) )
{
if ( activator.isActive( profile ) )
{
active.add( profile );
}
else
{
break activatorLoop;
}
}
}
}
return active;
}
catch ( ComponentLookupException e )
{
throw new ProjectBuildingException( "Cannot retrieve list of profile activators.", e );
}
finally
{
try
{
container.releaseAll( activators );
}
catch ( ComponentLifecycleException e )
{
getLogger().debug( "Error releasing profile activators - ignoring.", e );
}
}
}
public void contextualize( Context context )
throws ContextException
{
this.container = (PlexusContainer) context.get( PlexusConstants.PLEXUS_KEY );
}
}

View File

@ -0,0 +1,17 @@
package org.apache.maven.profiles.activation;
public class ProfileActivationException
extends Exception
{
public ProfileActivationException( String message, Throwable cause )
{
super( message, cause );
}
public ProfileActivationException( String message )
{
super( message );
}
}

View File

@ -1,67 +0,0 @@
package org.apache.maven.profiles.activation;
import org.codehaus.plexus.util.StringUtils;
import java.util.ArrayList;
import java.util.List;
import java.util.StringTokenizer;
/*
* Copyright 2001-2005 The Apache Software Foundation.
*
* Licensed 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.
*/
public final class ProfileActivationUtils
{
public static final String ACTIVE_PROFILE_IDS = "org.apache.maven.ActiveProfiles";
private static List profileList;
private ProfileActivationUtils()
{
}
public static boolean profilesWereExplicitlyGiven()
{
return StringUtils.isNotEmpty( System.getProperty( ACTIVE_PROFILE_IDS ) );
}
public static List getExplicitProfileList()
{
if ( !profilesWereExplicitlyGiven() )
{
return null;
}
if ( profileList == null )
{
profileList = new ArrayList();
StringTokenizer profileTokens = new StringTokenizer( System.getProperty( ACTIVE_PROFILE_IDS ), "," );
while ( profileTokens.hasMoreTokens() )
{
String token = profileTokens.nextToken().trim();
if ( StringUtils.isNotEmpty( token ) )
{
profileList.add( token );
}
}
}
return profileList;
}
}

View File

@ -40,7 +40,12 @@ import org.apache.maven.model.Profile;
import org.apache.maven.model.ReportPlugin;
import org.apache.maven.model.Repository;
import org.apache.maven.model.io.xpp3.MavenXpp3Reader;
import org.apache.maven.profiles.activation.ProfileActivationCalculator;
import org.apache.maven.profiles.DefaultProfileManager;
import org.apache.maven.profiles.MavenProfilesBuilder;
import org.apache.maven.profiles.ProfileManager;
import org.apache.maven.profiles.ProfilesConversionUtils;
import org.apache.maven.profiles.ProfilesRoot;
import org.apache.maven.profiles.activation.ProfileActivationException;
import org.apache.maven.project.inheritance.ModelInheritanceAssembler;
import org.apache.maven.project.injection.ModelDefaultsInjector;
import org.apache.maven.project.injection.ProfileInjector;
@ -90,6 +95,8 @@ public class DefaultMavenProjectBuilder
// TODO: remove
private PlexusContainer container;
protected MavenProfilesBuilder profilesBuilder;
protected ArtifactResolver artifactResolver;
protected ArtifactMetadataSource artifactMetadataSource;
@ -113,8 +120,6 @@ public class DefaultMavenProjectBuilder
private ArtifactRepositoryFactory artifactRepositoryFactory;
private ProfileActivationCalculator profileActivationCalculator;
private final Map modelCache = new HashMap();
public static final String MAVEN_MODEL_VERSION = "4.0.0";
@ -133,11 +138,10 @@ public class DefaultMavenProjectBuilder
/**
* @todo move to metadatasource itself?
*/
public MavenProject buildWithDependencies( File projectDescriptor, ArtifactRepository localRepository,
List externalProfiles )
public MavenProject buildWithDependencies( File projectDescriptor, ArtifactRepository localRepository, ProfileManager profileManager )
throws ProjectBuildingException, ArtifactResolutionException
{
MavenProject project = buildFromSourceFile( projectDescriptor, localRepository, externalProfiles );
MavenProject project = buildFromSourceFile( projectDescriptor, localRepository, profileManager );
// ----------------------------------------------------------------------
// Typically when the project builder is being used from maven proper
@ -224,14 +228,13 @@ public class DefaultMavenProjectBuilder
return map;
}
public MavenProject build( File projectDescriptor, ArtifactRepository localRepository, List externalProfiles )
public MavenProject build( File projectDescriptor, ArtifactRepository localRepository, ProfileManager profileManager )
throws ProjectBuildingException
{
return buildFromSourceFile( projectDescriptor, localRepository, externalProfiles );
return buildFromSourceFile( projectDescriptor, localRepository, profileManager );
}
private MavenProject buildFromSourceFile( File projectDescriptor, ArtifactRepository localRepository,
List externalProfiles )
private MavenProject buildFromSourceFile( File projectDescriptor, ArtifactRepository localRepository, ProfileManager profileManager )
throws ProjectBuildingException
{
Model model = readModel( projectDescriptor );
@ -240,8 +243,7 @@ public class DefaultMavenProjectBuilder
modelCache.put( createCacheKey( model.getGroupId(), model.getArtifactId(), model.getVersion() ), model );
MavenProject project = build( projectDescriptor.getAbsolutePath(), model, localRepository,
Collections.EMPTY_LIST, externalProfiles,
projectDescriptor.getAbsoluteFile().getParentFile() );
Collections.EMPTY_LIST, projectDescriptor.getAbsoluteFile().getParentFile(), profileManager );
if ( project.getDistributionManagement() != null && project.getDistributionManagement().getStatus() != null )
{
@ -277,7 +279,7 @@ public class DefaultMavenProjectBuilder
Model model = findModelFromRepository( artifact, remoteArtifactRepositories, localRepository );
return build( "Artifact [" + artifact.getId() + "]", model, localRepository, remoteArtifactRepositories,
Collections.EMPTY_LIST, null );
null, null );
}
private Model findModelFromRepository( Artifact artifact, List remoteArtifactRepositories,
@ -387,7 +389,7 @@ public class DefaultMavenProjectBuilder
}
private MavenProject build( String pomLocation, Model model, ArtifactRepository localRepository,
List parentSearchRepositories, List externalProfiles, File projectDir )
List parentSearchRepositories, File projectDir, ProfileManager profileManager )
throws ProjectBuildingException
{
Model superModel = getSuperModel();
@ -401,7 +403,24 @@ public class DefaultMavenProjectBuilder
artifactRepositoryFactory,
container ) );
for ( Iterator i = externalProfiles.iterator(); i.hasNext(); )
List activeExternalProfiles;
try
{
if ( profileManager != null )
{
activeExternalProfiles = profileManager.getActiveProfiles();
}
else
{
activeExternalProfiles = Collections.EMPTY_LIST;
}
}
catch ( ProfileActivationException e )
{
throw new ProjectBuildingException( "Failed to calculate active external profiles.", e );
}
for ( Iterator i = activeExternalProfiles.iterator(); i.hasNext(); )
{
Profile externalProfile = (Profile) i.next();
@ -419,8 +438,8 @@ public class DefaultMavenProjectBuilder
Model originalModel = ModelUtils.cloneModel( model );
MavenProject project = assembleLineage( model, lineage, localRepository, externalProfiles, projectDir,
parentSearchRepositories, aggregatedRemoteWagonRepositories );
MavenProject project = assembleLineage( model, lineage, localRepository, projectDir, parentSearchRepositories,
aggregatedRemoteWagonRepositories );
project.setOriginalModel( originalModel );
@ -440,8 +459,7 @@ public class DefaultMavenProjectBuilder
try
{
project = processProjectLogic( pomLocation, project, new ArrayList( aggregatedRemoteWagonRepositories ),
externalProfiles );
project = processProjectLogic( pomLocation, project, new ArrayList( aggregatedRemoteWagonRepositories ), profileManager );
}
catch ( ModelInterpolationException e )
{
@ -460,8 +478,7 @@ public class DefaultMavenProjectBuilder
* the resolved source roots, etc for the parent - that occurs for the parent when it is constructed independently
* and projects are not cached or reused
*/
private MavenProject processProjectLogic( String pomLocation, MavenProject project, List remoteRepositories,
List externalProfiles )
private MavenProject processProjectLogic( String pomLocation, MavenProject project, List remoteRepositories, ProfileManager profileMgr )
throws ProjectBuildingException, ModelInterpolationException
{
Model model = project.getModel();
@ -471,26 +488,26 @@ public class DefaultMavenProjectBuilder
{
modelCache.put( key, model );
}
List activeProfiles = new ArrayList( externalProfiles );
List activePomProfiles = profileActivationCalculator.calculateActiveProfiles( model.getProfiles() );
activeProfiles.addAll( activePomProfiles );
Properties profileProperties = new Properties();
for ( Iterator it = activeProfiles.iterator(); it.hasNext(); )
Properties profileProperties = project.getProfileProperties();
if ( profileProperties == null )
{
Profile profile = (Profile) it.next();
profileInjector.inject( profile, model );
profileProperties.putAll( profile.getProperties() );
profileProperties = new Properties();
}
List activeProfiles = project.getActiveProfiles();
if ( activeProfiles == null )
{
activeProfiles = new ArrayList();
}
List injectedProfiles = injectActiveProfiles( profileMgr, model, profileProperties );
activeProfiles.addAll( injectedProfiles );
// TODO: Clean this up...we're using this to 'jump' the interpolation step for model properties not expressed in XML.
model = modelInterpolator.interpolate( model );
// interpolation is before injection, because interpolation is off-limits in the injected variables
@ -507,13 +524,14 @@ public class DefaultMavenProjectBuilder
//=======================================================================
project = new MavenProject( model );
project.addProfileProperties( profileProperties );
project.setActiveProfiles( activeProfiles );
project.setOriginalModel( originalModel );
project.setActiveProfiles( activeProfiles );
project.addProfileProperties( profileProperties );
project.assembleProfilePropertiesInheritance();
// TODO: maybe not strictly correct, while we should enfore that packaging has a type handler of the same id, we don't
Artifact projectArtifact = artifactFactory.createBuildArtifact( project.getGroupId(), project.getArtifactId(),
project.getVersion(), project.getPackaging() );
@ -569,7 +587,7 @@ public class DefaultMavenProjectBuilder
* @noinspection CollectionDeclaredAsConcreteClass
*/
private MavenProject assembleLineage( Model model, LinkedList lineage, ArtifactRepository localRepository,
List externalProfiles, File projectDir, List parentSearchRepositories,
File projectDir, List parentSearchRepositories,
Set aggregatedRemoteWagonRepositories )
throws ProjectBuildingException
{
@ -589,8 +607,31 @@ public class DefaultMavenProjectBuilder
}
}
ProfileManager profileManager = new DefaultProfileManager( container );
List activeProfiles;
Properties profileProperties = new Properties();
try
{
profileManager.addProfiles( model.getProfiles() );
loadProjectExternalProfiles( profileManager, projectDir );
activeProfiles = injectActiveProfiles( profileManager, model, profileProperties );
}
catch ( ProfileActivationException e )
{
throw new ProjectBuildingException( "Failed to activate local (project-level) build profiles.", e );
}
MavenProject project = new MavenProject( model );
project.addProfileProperties( profileProperties );
project.setActiveProfiles( activeProfiles );
lineage.addFirst( project );
Parent parentModel = model.getParent();
@ -686,8 +727,8 @@ public class DefaultMavenProjectBuilder
model = findModelFromRepository( parentArtifact, remoteRepositories, localRepository );
}
MavenProject parent = assembleLineage( model, lineage, localRepository, externalProfiles, parentProjectDir,
parentSearchRepositories, aggregatedRemoteWagonRepositories );
MavenProject parent = assembleLineage( model, lineage, localRepository, parentProjectDir, parentSearchRepositories,
aggregatedRemoteWagonRepositories );
project.setParent( parent );
@ -697,6 +738,69 @@ public class DefaultMavenProjectBuilder
return project;
}
private List injectActiveProfiles( ProfileManager profileManager, Model model, Properties profileProperties )
throws ProjectBuildingException
{
List activeProfiles;
if ( profileManager != null )
{
try
{
activeProfiles = profileManager.getActiveProfiles();
}
catch ( ProfileActivationException e )
{
throw new ProjectBuildingException( "Failed to calculate active build profiles.", e );
}
for ( Iterator it = activeProfiles.iterator(); it.hasNext(); )
{
Profile profile = (Profile) it.next();
profileInjector.inject( profile, model );
profileProperties.putAll( profile.getProperties() );
}
}
else
{
activeProfiles = Collections.EMPTY_LIST;
}
return activeProfiles;
}
private void loadProjectExternalProfiles( ProfileManager profileManager, File projectDir )
throws ProfileActivationException
{
if ( projectDir != null )
{
try
{
ProfilesRoot root = profilesBuilder.buildProfiles( projectDir );
if ( root != null )
{
for ( Iterator it = root.getProfiles().iterator(); it.hasNext(); )
{
org.apache.maven.profiles.Profile rawProfile = (org.apache.maven.profiles.Profile) it.next();
profileManager.addProfile( ProfilesConversionUtils.convertFromProfileXmlProfile( rawProfile ) );
}
}
}
catch ( IOException e )
{
throw new ProfileActivationException( "Cannot read profiles.xml resource from directory: " + projectDir, e );
}
catch ( XmlPullParserException e )
{
throw new ProfileActivationException( "Cannot parse profiles.xml resource from directory: " + projectDir, e );
}
}
}
private Model readModel( File file )
throws ProjectBuildingException
{
@ -885,7 +989,7 @@ public class DefaultMavenProjectBuilder
return extensionArtifacts;
}
public MavenProject buildStandaloneSuperProject( ArtifactRepository localRepository, List externalProfiles )
public MavenProject buildStandaloneSuperProject( ArtifactRepository localRepository )
throws ProjectBuildingException
{
Model superModel = getSuperModel();
@ -907,7 +1011,7 @@ public class DefaultMavenProjectBuilder
List remoteRepositories = ProjectUtils.buildArtifactRepositories( superModel.getRepositories(),
artifactRepositoryFactory, container );
project = processProjectLogic( "<Super-POM>", project, remoteRepositories, externalProfiles );
project = processProjectLogic( "<Super-POM>", project, remoteRepositories, null );
return project;
}

View File

@ -61,6 +61,7 @@ import java.util.List;
import java.util.Map;
import java.util.Properties;
import java.util.Set;
import java.util.Stack;
/**
* The concern of the project is provide runtime values based on the model. <p/>
@ -1309,5 +1310,32 @@ public class MavenProject
{
return groupId + ":" + artifactId;
}
public void assembleProfilePropertiesInheritance()
{
Stack propertyStack = new Stack();
MavenProject current = this;
while( current != null )
{
Properties toAdd = current.profileProperties;
if ( toAdd != null && !toAdd.isEmpty() )
{
propertyStack.push( toAdd );
}
current = current.getParent();
}
Properties newProfilesProperties = new Properties();
while( !propertyStack.isEmpty() )
{
newProfilesProperties.putAll( (Properties) propertyStack.pop() );
}
this.profileProperties = newProfilesProperties;
}
}

View File

@ -19,6 +19,7 @@ package org.apache.maven.project;
import org.apache.maven.artifact.Artifact;
import org.apache.maven.artifact.repository.ArtifactRepository;
import org.apache.maven.artifact.resolver.ArtifactResolutionException;
import org.apache.maven.profiles.ProfileManager;
import java.io.File;
import java.util.List;
@ -33,10 +34,10 @@ public interface MavenProjectBuilder
String STANDALONE_SUPERPOM_VERSION = "2.0";
MavenProject build( File project, ArtifactRepository localRepository, List profiles )
MavenProject build( File project, ArtifactRepository localRepository, ProfileManager globalProfileManager )
throws ProjectBuildingException;
MavenProject buildWithDependencies( File project, ArtifactRepository localRepository, List externalProfiles )
MavenProject buildWithDependencies( File project, ArtifactRepository localRepository, ProfileManager globalProfileManager )
throws ProjectBuildingException, ArtifactResolutionException;
/**
@ -52,6 +53,6 @@ public interface MavenProjectBuilder
ArtifactRepository localRepository )
throws ProjectBuildingException;
MavenProject buildStandaloneSuperProject( ArtifactRepository localRepository, List externalProfiles )
MavenProject buildStandaloneSuperProject( ArtifactRepository localRepository )
throws ProjectBuildingException;
}

View File

@ -36,6 +36,9 @@
<role>org.apache.maven.project.MavenProjectBuilder</role>
<implementation>org.apache.maven.project.DefaultMavenProjectBuilder</implementation>
<requirements>
<requirement>
<role>org.apache.maven.profiles.MavenProfilesBuilder</role>
</requirement>
<requirement>
<role>org.apache.maven.project.injection.ProfileInjector</role>
</requirement>
@ -63,20 +66,8 @@
<requirement>
<role>org.apache.maven.artifact.repository.ArtifactRepositoryFactory</role>
</requirement>
<requirement>
<role>org.apache.maven.profiles.activation.ProfileActivationCalculator</role>
</requirement>
</requirements>
</component>
<!--
|
|
|
-->
<component>
<role>org.apache.maven.profiles.activation.ProfileActivationCalculator</role>
<implementation>org.apache.maven.profiles.activation.ProfileActivationCalculator</implementation>
</component>
<!--
|
|
@ -107,16 +98,6 @@
<role-hint>system-property</role-hint>
<implementation>org.apache.maven.profiles.activation.SystemPropertyProfileActivator</implementation>
</component>
<!--
|
|
|
-->
<component>
<role>org.apache.maven.profiles.activation.ProfileActivator</role>
<role-hint>explicit-listing</role-hint>
<implementation>org.apache.maven.profiles.activation.ExplicitListingProfileActivator</implementation>
</component>
<!--
|
|

View File

@ -46,5 +46,37 @@
</testResource>
</testResources>
</build>
<profiles>
<profile>
<id>release-profile</id>
<activation>
<property>
<name>performRelease</name>
</property>
</activation>
<build>
<plugins>
<plugin>
<inherit>true</inherit>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-source-plugin</artifactId>
</plugin>
<plugin>
<inherit>true</inherit>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-deploy-plugin</artifactId>
<configuration>
<updateReleaseInfo>true</updateReleaseInfo>
</configuration>
</plugin>
</plugins>
</build>
</profile>
</profiles>
</project>
<!-- END SNIPPET: superpom -->

View File

@ -20,12 +20,10 @@ import org.apache.maven.artifact.repository.ArtifactRepository;
import org.apache.maven.artifact.repository.DefaultArtifactRepository;
import org.apache.maven.artifact.repository.layout.ArtifactRepositoryLayout;
import org.codehaus.plexus.PlexusTestCase;
import org.codehaus.plexus.component.repository.exception.ComponentLookupException;
import java.io.File;
import java.io.FileNotFoundException;
import java.net.URL;
import java.util.Collections;
/**
* @author <a href="mailto:jason@maven.org">Jason van Zyl </a>
@ -104,13 +102,13 @@ public abstract class MavenProjectTestCase
protected MavenProject getProjectWithDependencies( File pom )
throws Exception
{
return projectBuilder.buildWithDependencies( pom, getLocalRepository(), Collections.EMPTY_LIST );
return projectBuilder.buildWithDependencies( pom, getLocalRepository(), null );
}
protected MavenProject getProject( File pom )
throws Exception
{
return projectBuilder.build( pom, getLocalRepository(), Collections.EMPTY_LIST );
return projectBuilder.build( pom, getLocalRepository(), null );
}
}

View File

@ -37,6 +37,9 @@
<role-hint>test</role-hint>
<implementation>org.apache.maven.project.TestProjectBuilder</implementation>
<requirements>
<requirement>
<role>org.apache.maven.profiles.MavenProfilesBuilder</role>
</requirement>
<requirement>
<role>org.apache.maven.project.injection.ModelDefaultsInjector</role>
</requirement>
@ -61,9 +64,6 @@
<requirement>
<role>org.apache.maven.artifact.repository.ArtifactRepositoryFactory</role>
</requirement>
<requirement>
<role>org.apache.maven.profiles.activation.ProfileActivationCalculator</role>
</requirement>
</requirements>
</component>
</components>