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.text.SimpleDateFormat;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
|
import java.util.Collection;
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.LinkedHashMap;
|
import java.util.LinkedHashMap;
|
||||||
|
import java.util.LinkedHashSet;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
|
@ -44,6 +46,7 @@ import org.apache.maven.repository.DelegatingLocalArtifactRepository;
|
||||||
import org.codehaus.plexus.PlexusContainer;
|
import org.codehaus.plexus.PlexusContainer;
|
||||||
import org.codehaus.plexus.component.annotations.Component;
|
import org.codehaus.plexus.component.annotations.Component;
|
||||||
import org.codehaus.plexus.component.annotations.Requirement;
|
import org.codehaus.plexus.component.annotations.Requirement;
|
||||||
|
import org.codehaus.plexus.logging.Logger;
|
||||||
import org.codehaus.plexus.util.Os;
|
import org.codehaus.plexus.util.Os;
|
||||||
import org.codehaus.plexus.util.StringUtils;
|
import org.codehaus.plexus.util.StringUtils;
|
||||||
import org.codehaus.plexus.util.dag.CycleDetectedException;
|
import org.codehaus.plexus.util.dag.CycleDetectedException;
|
||||||
|
@ -55,6 +58,10 @@ import org.codehaus.plexus.util.dag.CycleDetectedException;
|
||||||
public class DefaultMaven
|
public class DefaultMaven
|
||||||
implements Maven
|
implements Maven
|
||||||
{
|
{
|
||||||
|
|
||||||
|
@Requirement
|
||||||
|
private Logger logger;
|
||||||
|
|
||||||
@Requirement
|
@Requirement
|
||||||
protected ProjectBuilder projectBuilder;
|
protected ProjectBuilder projectBuilder;
|
||||||
|
|
||||||
|
@ -141,6 +148,8 @@ public class DefaultMaven
|
||||||
|
|
||||||
lifecycleExecutor.execute( session );
|
lifecycleExecutor.execute( session );
|
||||||
|
|
||||||
|
validateActivatedProfiles( session.getProjects(), request.getActiveProfiles() );
|
||||||
|
|
||||||
if ( session.getResult().hasExceptions() )
|
if ( session.getResult().hasExceptions() )
|
||||||
{
|
{
|
||||||
return processResult( result, session.getResult().getExceptions().get( 0 ) );
|
return processResult( result, session.getResult().getExceptions().get( 0 ) );
|
||||||
|
@ -246,4 +255,23 @@ public class DefaultMaven
|
||||||
|
|
||||||
return projects;
|
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." );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -134,9 +134,27 @@ public class DefaultProjectBuilder
|
||||||
activeProfiles.addAll( result.getActiveExternalProfiles() );
|
activeProfiles.addAll( result.getActiveExternalProfiles() );
|
||||||
project.setActiveProfiles( activeProfiles );
|
project.setActiveProfiles( activeProfiles );
|
||||||
|
|
||||||
|
project.setInjectedProfileIds( "external", getProfileIds( result.getActiveExternalProfiles() ) );
|
||||||
|
for ( String modelId : result.getModelIds() )
|
||||||
|
{
|
||||||
|
project.setInjectedProfileIds( modelId, getProfileIds( result.getActivePomProfiles( modelId ) ) );
|
||||||
|
}
|
||||||
|
|
||||||
return project;
|
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 )
|
private ModelBuildingRequest getModelBuildingRequest( ProjectBuildingRequest configuration )
|
||||||
{
|
{
|
||||||
ModelResolver resolver =
|
ModelResolver resolver =
|
||||||
|
|
|
@ -25,6 +25,7 @@ import java.util.Collections;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
import java.util.Iterator;
|
import java.util.Iterator;
|
||||||
|
import java.util.LinkedHashMap;
|
||||||
import java.util.LinkedHashSet;
|
import java.util.LinkedHashSet;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
@ -125,6 +126,8 @@ public class MavenProject
|
||||||
|
|
||||||
private List<Profile> activeProfiles = new ArrayList<Profile>();
|
private List<Profile> activeProfiles = new ArrayList<Profile>();
|
||||||
|
|
||||||
|
private Map<String, List<String>> injectedProfileIds = new LinkedHashMap<String, List<String>>();
|
||||||
|
|
||||||
private Set<Artifact> dependencyArtifacts;
|
private Set<Artifact> dependencyArtifacts;
|
||||||
|
|
||||||
private Artifact artifact;
|
private Artifact artifact;
|
||||||
|
@ -1411,6 +1414,33 @@ public class MavenProject
|
||||||
return activeProfiles;
|
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 )
|
public void addAttachedArtifact( Artifact artifact )
|
||||||
throws DuplicateArtifactAttachmentException
|
throws DuplicateArtifactAttachmentException
|
||||||
{
|
{
|
||||||
|
|
Loading…
Reference in New Issue