mirror of https://github.com/apache/maven.git
[MNG-3641] Lack of error checks on profiles
git-svn-id: https://svn.apache.org/repos/asf/maven/components/trunk@787045 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
c646df62b4
commit
c17c9564cc
|
@ -20,9 +20,11 @@ import java.io.IOException;
|
|||
import java.text.SimpleDateFormat;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collection;
|
||||
import java.util.Date;
|
||||
import java.util.HashMap;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.LinkedHashSet;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
|
@ -44,6 +46,7 @@ import org.apache.maven.repository.DelegatingLocalArtifactRepository;
|
|||
import org.codehaus.plexus.PlexusContainer;
|
||||
import org.codehaus.plexus.component.annotations.Component;
|
||||
import org.codehaus.plexus.component.annotations.Requirement;
|
||||
import org.codehaus.plexus.logging.Logger;
|
||||
import org.codehaus.plexus.util.Os;
|
||||
import org.codehaus.plexus.util.StringUtils;
|
||||
import org.codehaus.plexus.util.dag.CycleDetectedException;
|
||||
|
@ -55,6 +58,10 @@ import org.codehaus.plexus.util.dag.CycleDetectedException;
|
|||
public class DefaultMaven
|
||||
implements Maven
|
||||
{
|
||||
|
||||
@Requirement
|
||||
private Logger logger;
|
||||
|
||||
@Requirement
|
||||
protected ProjectBuilder projectBuilder;
|
||||
|
||||
|
@ -140,7 +147,9 @@ public class DefaultMaven
|
|||
}
|
||||
|
||||
lifecycleExecutor.execute( session );
|
||||
|
||||
|
||||
validateActivatedProfiles( session.getProjects(), request.getActiveProfiles() );
|
||||
|
||||
if ( session.getResult().hasExceptions() )
|
||||
{
|
||||
return processResult( result, session.getResult().getExceptions().get( 0 ) );
|
||||
|
@ -246,4 +255,23 @@ public class DefaultMaven
|
|||
|
||||
return projects;
|
||||
}
|
||||
|
||||
private void validateActivatedProfiles( List<MavenProject> projects, List<String> activeProfileIds )
|
||||
{
|
||||
Collection<String> notActivatedProfileIds = new LinkedHashSet<String>( activeProfileIds );
|
||||
|
||||
for ( MavenProject project : projects )
|
||||
{
|
||||
for ( List<String> profileIds : project.getInjectedProfileIds().values() )
|
||||
{
|
||||
notActivatedProfileIds.removeAll( profileIds );
|
||||
}
|
||||
}
|
||||
|
||||
for ( String notActivatedProfileId : notActivatedProfileIds )
|
||||
{
|
||||
logger.warn( "Profile with id \"" + notActivatedProfileId + "\" has not been activated." );
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -133,10 +133,28 @@ public class DefaultProjectBuilder
|
|||
activeProfiles.addAll( result.getActivePomProfiles( result.getModelIds().get( 0 ) ) );
|
||||
activeProfiles.addAll( result.getActiveExternalProfiles() );
|
||||
project.setActiveProfiles( activeProfiles );
|
||||
|
||||
|
||||
project.setInjectedProfileIds( "external", getProfileIds( result.getActiveExternalProfiles() ) );
|
||||
for ( String modelId : result.getModelIds() )
|
||||
{
|
||||
project.setInjectedProfileIds( modelId, getProfileIds( result.getActivePomProfiles( modelId ) ) );
|
||||
}
|
||||
|
||||
return project;
|
||||
}
|
||||
|
||||
private List<String> getProfileIds( List<Profile> profiles )
|
||||
{
|
||||
List<String> ids = new ArrayList<String>( profiles.size() );
|
||||
|
||||
for ( Profile profile : profiles )
|
||||
{
|
||||
ids.add( profile.getId() );
|
||||
}
|
||||
|
||||
return ids;
|
||||
}
|
||||
|
||||
private ModelBuildingRequest getModelBuildingRequest( ProjectBuildingRequest configuration )
|
||||
{
|
||||
ModelResolver resolver =
|
||||
|
|
|
@ -25,6 +25,7 @@ import java.util.Collections;
|
|||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.Iterator;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.LinkedHashSet;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
@ -125,6 +126,8 @@ public class MavenProject
|
|||
|
||||
private List<Profile> activeProfiles = new ArrayList<Profile>();
|
||||
|
||||
private Map<String, List<String>> injectedProfileIds = new LinkedHashMap<String, List<String>>();
|
||||
|
||||
private Set<Artifact> dependencyArtifacts;
|
||||
|
||||
private Artifact artifact;
|
||||
|
@ -1411,6 +1414,33 @@ public class MavenProject
|
|||
return activeProfiles;
|
||||
}
|
||||
|
||||
public void setInjectedProfileIds( String source, List<String> injectedProfileIds )
|
||||
{
|
||||
if ( injectedProfileIds != null )
|
||||
{
|
||||
this.injectedProfileIds.put( source, new ArrayList<String>( injectedProfileIds ) );
|
||||
}
|
||||
else
|
||||
{
|
||||
this.injectedProfileIds.remove( source );
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the identifiers of all profiles that contributed to this project's effective model. This includes active
|
||||
* profiles from the project's POM and all its parent POMs as well as from external sources like the {@code
|
||||
* settings.xml}. The profile identifiers are grouped by the identifier of their source, e.g. {@code
|
||||
* <groupId>:<artifactId>:<version>} for a POM profile or {@code external} for profiles from the {@code
|
||||
* settings.xml}.
|
||||
*
|
||||
* @return The identifiers of all injected profiles, indexed by the source from which the profiles originated, never
|
||||
* {@code null}.
|
||||
*/
|
||||
public Map<String, List<String>> getInjectedProfileIds()
|
||||
{
|
||||
return this.injectedProfileIds;
|
||||
}
|
||||
|
||||
public void addAttachedArtifact( Artifact artifact )
|
||||
throws DuplicateArtifactAttachmentException
|
||||
{
|
||||
|
|
Loading…
Reference in New Issue