Now we do interpolation before management processing. This allow depMng/pluginMng to have interpolated values for group/artifact ids.

git-svn-id: https://svn.apache.org/repos/asf/maven/components/trunk@768421 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Britton Isbell 2009-04-24 21:32:57 +00:00
parent cfda1d9f8d
commit b4874e382d
7 changed files with 95 additions and 15 deletions

View File

@ -119,7 +119,7 @@ public List<ArtifactMetadata> getDependencies( ArtifactMetadata bmd, MetadataRea
}
iModels.get(0).setMostSpecialized(true);
return new MavenDomainModel(ProcessorContext.build(iModels, null)).getDependencyMetadata();
return new MavenDomainModel( ProcessorContext.processManagementNodes(ProcessorContext.build(iModels, null).getModel() ) ).getDependencyMetadata();
} catch (IOException e) {
throw new DependencyProcessorException(e);
}

View File

@ -27,6 +27,7 @@
import org.apache.maven.mercury.artifact.ArtifactMetadata;
import org.apache.maven.model.Dependency;
import org.apache.maven.model.Exclusion;
import org.apache.maven.model.Model;
import org.apache.maven.model.Parent;
import org.apache.maven.model.PomClassicDomainModel;
@ -54,6 +55,12 @@ public MavenDomainModel(PomClassicDomainModel model)
super(model.getModel());
}
public MavenDomainModel(Model model)
throws IOException
{
super(model);
}
public boolean hasParent()
{
return getParentMetadata() != null;

View File

@ -251,6 +251,14 @@ else if ( i < length - 2 )
}
}
}
return target;
}
public static Model processManagementNodes(Model target)
throws IOException
{
// Dependency Management
DependencyManagementProcessor depProc = new DependencyManagementProcessor();
@ -261,16 +269,14 @@ else if ( i < length - 2 )
}
// Plugin Management
PluginsManagementProcessor procMng = new PluginsManagementProcessor();
if ( target.getBuild() != null && target.getBuild().getPluginManagement() != null)
{
procMng.process( null, new ArrayList<Plugin>( target.getBuild().getPluginManagement().getPlugins() ),
target.getBuild().getPlugins(), true );
}
return target;
return target;
}
public static Profile copyOfProfile(Profile profile)

View File

@ -160,14 +160,22 @@ public MavenProject build( File pomFile, ProjectBuilderConfiguration configurati
}
domainModel = ProcessorContext.mergeProfilesIntoModel( externalProfiles, domainModel );
}
catch ( IOException e )
{
throw new ProjectBuildingException("", "");
}
//Interpolation
MavenProject project = interpolateDomainModel( domainModel, configuration, pomFile );
//Interpolation & Management
MavenProject project;
try {
Model model = ProcessorContext.processManagementNodes(interpolateDomainModel( domainModel, configuration, pomFile ));
project = this.fromDomainModelToMavenProject(model, domainModel.getParentFile(), configuration, pomFile);
} catch (IOException e) {
throw new ProjectBuildingException("", "");
}
project.setActiveProfiles( projectProfiles );
Build build = project.getBuild();
@ -269,7 +277,14 @@ public MavenProject buildFromRepository(Artifact artifact, ProjectBuilderConfigu
{
throw new ProjectBuildingException("", "");
}
project = interpolateDomainModel( domainModel, configuration, artifact.getFile() );
try {
Model model = ProcessorContext.processManagementNodes(interpolateDomainModel( domainModel, configuration, artifact.getFile() ));
project = this.fromDomainModelToMavenProject(model, domainModel.getParentFile(), configuration, artifact.getFile());
} catch (IOException e) {
throw new ProjectBuildingException("", "");
}
project.setActiveProfiles( projectProfiles );
artifact.setFile( artifact.getFile() );
project.setVersion( artifact.getVersion() );
@ -368,7 +383,7 @@ public MavenProjectBuildingResult buildProjectWithDependencies( File pomFile, Pr
return new MavenProjectBuildingResult( project, result );
}
private MavenProject interpolateDomainModel( PomClassicDomainModel domainModel, ProjectBuilderConfiguration config, File projectDescriptor )
private Model interpolateDomainModel( PomClassicDomainModel domainModel, ProjectBuilderConfiguration config, File projectDescriptor )
throws ProjectBuildingException
{
Model model;
@ -403,9 +418,15 @@ private MavenProject interpolateDomainModel( PomClassicDomainModel domainModel,
throw new ProjectBuildingException(projectId, "", projectDescriptor, e);
}
return model;
}
private MavenProject fromDomainModelToMavenProject(Model model, File parentFile, ProjectBuilderConfiguration config, File projectDescriptor)
throws InvalidProjectModelException, IOException
{
MavenProject project;
String projectId = safeVersionlessKey( model.getGroupId(), model.getArtifactId() );
try
{
project = new MavenProject( model, repositorySystem, this, config );
@ -415,7 +436,7 @@ private MavenProject interpolateDomainModel( PomClassicDomainModel domainModel,
Artifact projectArtifact = repositorySystem.createArtifact( project.getGroupId(), project.getArtifactId(), project.getVersion(), null, project.getPackaging() );
project.setArtifact( projectArtifact );
project.setParentFile( domainModel.getParentFile() );
project.setParentFile( parentFile );
}
catch ( InvalidRepositoryException e )
@ -423,7 +444,7 @@ private MavenProject interpolateDomainModel( PomClassicDomainModel domainModel,
throw new InvalidProjectModelException( projectId, e.getMessage(), projectDescriptor, e );
}
return project;
return project;
}
private PomClassicDomainModel build( String projectId, File pomFile, ProjectBuilderConfiguration projectBuilderConfiguration )

View File

@ -1419,13 +1419,23 @@ public void testDependencyScopeInheritance()
assertNull("Scope not null: " + scope, scope);
System.out.println(pom.getDomainModel().asString());
}
}
public void testDependencyScope()
throws Exception
{
PomTestWrapper pom = buildPom( "dependency-scope/sub" );
System.out.println(pom.getDomainModel().asString());
}
// System.out.println(pom.getDomainModel().asString());
}
//This will fail on a validation error if incorrect
public void testDependencyManagementWithInterpolation()
throws Exception
{
PomTestWrapper pom = buildPom( "dependency-management-with-interpolation/sub" );
}
private void assertPathSuffixEquals( String expected, Object actual )
{
String a = actual.toString();

View File

@ -0,0 +1,19 @@
<project>
<modelVersion>4.0.0</modelVersion>
<artifactId>asm-parent</artifactId>
<groupId>asm</groupId>
<version>3.0</version>
<packaging>pom</packaging>
<dependencyManagement>
<dependencies>
<dependency>
<artifactId>asm-util</artifactId>
<groupId>${project.groupId}</groupId>
<version>${project.version}</version>
</dependency>
</dependencies>
</dependencyManagement>
</project>

View File

@ -0,0 +1,17 @@
<?xml version="1.0"?><project>
<parent>
<artifactId>asm-parent</artifactId>
<groupId>asm</groupId>
<version>3.0</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>asm-xml</artifactId>
<version>3.0</version>
<dependencies>
<dependency>
<groupId>asm</groupId>
<artifactId>asm-util</artifactId>
</dependency>
</dependencies>
</project>