o as the profile has been removed from the super pom, we do not need to inject or process any profiles

related to it. this great simplifies a lot of code
o caching the super project in the default project builder as it's never going to change now as no profiles
  are inject so it will only have to be constructed once an instance.


git-svn-id: https://svn.apache.org/repos/asf/maven/components/trunk@571910 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Jason van Zyl 2007-09-02 00:56:30 +00:00
parent e0dbac1e24
commit f196fefba4
6 changed files with 27 additions and 131 deletions

View File

@ -127,9 +127,6 @@ public class DefaultMaven
MavenExecutionResult result = new DefaultMavenExecutionResult();
// old doExecute
getLogger().info( "Scanning for projects..." );
boolean foundProjects = true;
@ -174,6 +171,9 @@ public class DefaultMaven
return result;
}
// Display the order of the projects
//CLI:move
if ( reactorManager.hasMultipleProjects() )
{
getLogger().info( "Reactor build order: " );
@ -313,9 +313,7 @@ public class DefaultMaven
MavenProject superProject;
try
{
superProject = projectBuilder.buildStandaloneSuperProject( request.getLocalRepository(),
new DefaultProfileManager( container,
request.getProperties() ) );
superProject = projectBuilder.buildStandaloneSuperProject();
}
catch ( ProjectBuildingException e )

View File

@ -115,6 +115,7 @@ public class DefaultBuildExtensionScanner
Map inheritedInterpolationValues = new HashMap();
List inheritedRemoteRepositories = new ArrayList();
inheritedRemoteRepositories.addAll( originalRemoteRepositories );
for ( ModelLineageIterator lineageIterator = lineage.reversedLineageIterator(); lineageIterator.hasNext(); )
@ -345,9 +346,10 @@ public class DefaultBuildExtensionScanner
throws ExtensionScanningException
{
MavenProject superProject;
try
{
superProject = projectBuilder.buildStandaloneSuperProject( localRepository, globalProfileManager );
superProject = projectBuilder.buildStandaloneSuperProject();
}
catch ( ProjectBuildingException e )
{
@ -356,6 +358,8 @@ public class DefaultBuildExtensionScanner
+ e.getMessage(), e );
}
System.out.println( "superProject = " + superProject );
return superProject.getRemoteArtifactRepositories();
}

View File

@ -247,19 +247,16 @@ public class DefaultMavenProjectBuilder
return buildFromRepository( artifact, remoteArtifactRepositories, localRepository, true );
}
// what is using this externally? jvz.
public MavenProject buildStandaloneSuperProject( ArtifactRepository localRepository )
private MavenProject superProject;
public MavenProject buildStandaloneSuperProject()
throws ProjectBuildingException
{
//TODO mkleint - use the (Container, Properties) constructor to make system properties embeddable
ProfileManager profileManager = new DefaultProfileManager( container );
return buildStandaloneSuperProject( localRepository, profileManager );
if ( this.superProject != null )
{
return this.superProject;
}
public MavenProject buildStandaloneSuperProject( ArtifactRepository localRepository,
ProfileManager profileManager )
throws ProjectBuildingException
{
Model superModel = getSuperModel();
superModel.setGroupId( STANDALONE_SUPERPOM_GROUPID );
@ -268,54 +265,23 @@ public class DefaultMavenProjectBuilder
superModel.setVersion( STANDALONE_SUPERPOM_VERSION );
MavenProject project = new MavenProject( superModel );
ProjectBuildContext projectContext = ProjectBuildContext.getProjectBuildContext( buildContextManager, true );
projectContext.setCurrentProject( project );
projectContext.store( buildContextManager );
String projectId = safeVersionlessKey( STANDALONE_SUPERPOM_GROUPID, STANDALONE_SUPERPOM_ARTIFACTID );
project.setManagedVersionMap( createManagedVersionMap( projectId, superModel.getDependencyManagement(), null ) );
List activeProfiles = profileAdvisor.applyActivatedProfiles( superModel, null, profileManager.getExplicitlyActivatedIds(), profileManager.getExplicitlyDeactivatedIds() );
List activeExternalProfiles = profileAdvisor.applyActivatedExternalProfiles( superModel, null, profileManager );
LinkedHashSet profiles = new LinkedHashSet();
if ( ( activeProfiles != null ) && !activeProfiles.isEmpty() )
{
profiles.addAll( activeProfiles );
}
if ( ( activeExternalProfiles != null ) && !activeExternalProfiles.isEmpty() )
{
profiles.addAll( activeExternalProfiles );
}
project.setActiveProfiles( new ArrayList( profiles ) );
project.setOriginalModel( superModel );
superProject = new MavenProject( superModel );
try
{
project = processProjectLogic( "<Super-POM>", project, null, null, STRICT_MODEL_PARSING );
project.setExecutionRoot( true );
return project;
}
catch ( ModelInterpolationException e )
{
throw new ProjectBuildingException( projectId, e.getMessage(), e );
superProject.setRemoteArtifactRepositories( mavenTools.buildArtifactRepositories( superModel.getRepositories() ) );
}
catch ( InvalidRepositoryException e )
{
throw new ProjectBuildingException( projectId, e.getMessage(), e );
}
// This will never happen with the repositories in the SuperPOM
}
superProject.setOriginalModel( superModel );
superProject.setExecutionRoot( true );
return superProject;
}
public MavenProjectBuildingResult buildWithDependencies( File projectDescriptor,
ArtifactRepository localRepository,

View File

@ -110,12 +110,6 @@ public interface MavenProjectBuilder
ArtifactRepository localRepository, boolean allowStubModel )
throws ProjectBuildingException;
MavenProject buildStandaloneSuperProject( ArtifactRepository localRepository )
throws ProjectBuildingException;
/**
* need to pass a profilemanager with correct context (eg. with execution properties)
*/
MavenProject buildStandaloneSuperProject( ArtifactRepository localRepository, ProfileManager profileManager )
MavenProject buildStandaloneSuperProject()
throws ProjectBuildingException;
}

View File

@ -263,7 +263,7 @@ public class MavenMetadataSource
{
try
{
superProject = mavenProjectBuilder.buildStandaloneSuperProject( null );
superProject = mavenProjectBuilder.buildStandaloneSuperProject();
}
catch ( ProjectBuildingException e )
{

View File

@ -84,72 +84,6 @@ public class DefaultMavenProjectBuilderTest
}
}
public void testShouldInjectOneProfileToStandaloneSuperPom()
throws Exception
{
ProfileManager pm = new DefaultProfileManager( getContainer(), new Properties() );
String profileId = "test-profile";
String key = "test";
String value = "value";
Profile profile = new Profile();
profile.setId( profileId );
profile.addProperty( key, value );
pm.addProfile( profile );
pm.explicitlyActivate( profileId );
MavenProject project = projectBuilder.buildStandaloneSuperProject( getLocalRepository(), pm );
assertEquals( value, project.getProperties().getProperty( key ) );
}
public void testShouldInjectProfileWithRepositoryToStandaloneSuperPom()
throws Exception
{
ProfileManager pm = new DefaultProfileManager( getContainer(), new Properties() );
String profileId = "test-profile";
String repoId = "test-repo";
Profile profile = new Profile();
profile.setId( profileId );
Repository repo = new Repository();
repo.setId( repoId );
repo.setUrl( "http://www.google.com" );
profile.addRepository( repo );
pm.addProfile( profile );
pm.explicitlyActivate( profileId );
MavenProject project = projectBuilder.buildStandaloneSuperProject( getLocalRepository(), pm );
List repositories = project.getRepositories();
assertNotNull( repositories );
Repository result = null;
for ( Iterator it = repositories.iterator(); it.hasNext(); )
{
Repository candidate = (Repository) it.next();
if ( repoId.equals( candidate.getId() ) )
{
result = candidate;
break;
}
}
assertNotNull( "Profile-injected repository not found in super-POM.", result );
assertEquals( "Profile-injected repository was not first in repo list within super-POM", repoId,
( (Repository) repositories.get( 0 ) ).getId() );
}
/**
* Check that we can build ok from the middle pom of a (parent,child,grandchild) heirarchy
* @throws Exception