mirror of
https://github.com/apache/maven.git
synced 2025-02-10 03:56:01 +00:00
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:
parent
cfda1d9f8d
commit
b4874e382d
@ -119,7 +119,7 @@ public List<ArtifactMetadata> getDependencies( ArtifactMetadata bmd, MetadataRea
|
|||||||
}
|
}
|
||||||
iModels.get(0).setMostSpecialized(true);
|
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) {
|
} catch (IOException e) {
|
||||||
throw new DependencyProcessorException(e);
|
throw new DependencyProcessorException(e);
|
||||||
}
|
}
|
||||||
|
@ -27,6 +27,7 @@
|
|||||||
import org.apache.maven.mercury.artifact.ArtifactMetadata;
|
import org.apache.maven.mercury.artifact.ArtifactMetadata;
|
||||||
import org.apache.maven.model.Dependency;
|
import org.apache.maven.model.Dependency;
|
||||||
import org.apache.maven.model.Exclusion;
|
import org.apache.maven.model.Exclusion;
|
||||||
|
import org.apache.maven.model.Model;
|
||||||
import org.apache.maven.model.Parent;
|
import org.apache.maven.model.Parent;
|
||||||
import org.apache.maven.model.PomClassicDomainModel;
|
import org.apache.maven.model.PomClassicDomainModel;
|
||||||
|
|
||||||
@ -54,6 +55,12 @@ public MavenDomainModel(PomClassicDomainModel model)
|
|||||||
super(model.getModel());
|
super(model.getModel());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public MavenDomainModel(Model model)
|
||||||
|
throws IOException
|
||||||
|
{
|
||||||
|
super(model);
|
||||||
|
}
|
||||||
|
|
||||||
public boolean hasParent()
|
public boolean hasParent()
|
||||||
{
|
{
|
||||||
return getParentMetadata() != null;
|
return getParentMetadata() != null;
|
||||||
|
@ -251,6 +251,14 @@ else if ( i < length - 2 )
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return target;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Model processManagementNodes(Model target)
|
||||||
|
throws IOException
|
||||||
|
{
|
||||||
|
|
||||||
// Dependency Management
|
// Dependency Management
|
||||||
DependencyManagementProcessor depProc = new DependencyManagementProcessor();
|
DependencyManagementProcessor depProc = new DependencyManagementProcessor();
|
||||||
@ -261,16 +269,14 @@ else if ( i < length - 2 )
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Plugin Management
|
// Plugin Management
|
||||||
|
|
||||||
PluginsManagementProcessor procMng = new PluginsManagementProcessor();
|
PluginsManagementProcessor procMng = new PluginsManagementProcessor();
|
||||||
if ( target.getBuild() != null && target.getBuild().getPluginManagement() != null)
|
if ( target.getBuild() != null && target.getBuild().getPluginManagement() != null)
|
||||||
{
|
{
|
||||||
procMng.process( null, new ArrayList<Plugin>( target.getBuild().getPluginManagement().getPlugins() ),
|
procMng.process( null, new ArrayList<Plugin>( target.getBuild().getPluginManagement().getPlugins() ),
|
||||||
target.getBuild().getPlugins(), true );
|
target.getBuild().getPlugins(), true );
|
||||||
}
|
}
|
||||||
|
|
||||||
return target;
|
return target;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Profile copyOfProfile(Profile profile)
|
public static Profile copyOfProfile(Profile profile)
|
||||||
|
@ -160,14 +160,22 @@ public MavenProject build( File pomFile, ProjectBuilderConfiguration configurati
|
|||||||
}
|
}
|
||||||
|
|
||||||
domainModel = ProcessorContext.mergeProfilesIntoModel( externalProfiles, domainModel );
|
domainModel = ProcessorContext.mergeProfilesIntoModel( externalProfiles, domainModel );
|
||||||
|
|
||||||
}
|
}
|
||||||
catch ( IOException e )
|
catch ( IOException e )
|
||||||
{
|
{
|
||||||
throw new ProjectBuildingException("", "");
|
throw new ProjectBuildingException("", "");
|
||||||
}
|
}
|
||||||
|
|
||||||
//Interpolation
|
//Interpolation & Management
|
||||||
MavenProject project = interpolateDomainModel( domainModel, configuration, pomFile );
|
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 );
|
project.setActiveProfiles( projectProfiles );
|
||||||
|
|
||||||
Build build = project.getBuild();
|
Build build = project.getBuild();
|
||||||
@ -269,7 +277,14 @@ public MavenProject buildFromRepository(Artifact artifact, ProjectBuilderConfigu
|
|||||||
{
|
{
|
||||||
throw new ProjectBuildingException("", "");
|
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 );
|
project.setActiveProfiles( projectProfiles );
|
||||||
artifact.setFile( artifact.getFile() );
|
artifact.setFile( artifact.getFile() );
|
||||||
project.setVersion( artifact.getVersion() );
|
project.setVersion( artifact.getVersion() );
|
||||||
@ -368,7 +383,7 @@ public MavenProjectBuildingResult buildProjectWithDependencies( File pomFile, Pr
|
|||||||
return new MavenProjectBuildingResult( project, result );
|
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
|
throws ProjectBuildingException
|
||||||
{
|
{
|
||||||
Model model;
|
Model model;
|
||||||
@ -403,9 +418,15 @@ private MavenProject interpolateDomainModel( PomClassicDomainModel domainModel,
|
|||||||
throw new ProjectBuildingException(projectId, "", projectDescriptor, e);
|
throw new ProjectBuildingException(projectId, "", projectDescriptor, e);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return model;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
private MavenProject fromDomainModelToMavenProject(Model model, File parentFile, ProjectBuilderConfiguration config, File projectDescriptor)
|
||||||
|
throws InvalidProjectModelException, IOException
|
||||||
|
{
|
||||||
MavenProject project;
|
MavenProject project;
|
||||||
|
String projectId = safeVersionlessKey( model.getGroupId(), model.getArtifactId() );
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
project = new MavenProject( model, repositorySystem, this, config );
|
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() );
|
Artifact projectArtifact = repositorySystem.createArtifact( project.getGroupId(), project.getArtifactId(), project.getVersion(), null, project.getPackaging() );
|
||||||
project.setArtifact( projectArtifact );
|
project.setArtifact( projectArtifact );
|
||||||
|
|
||||||
project.setParentFile( domainModel.getParentFile() );
|
project.setParentFile( parentFile );
|
||||||
|
|
||||||
}
|
}
|
||||||
catch ( InvalidRepositoryException e )
|
catch ( InvalidRepositoryException e )
|
||||||
@ -423,7 +444,7 @@ private MavenProject interpolateDomainModel( PomClassicDomainModel domainModel,
|
|||||||
throw new InvalidProjectModelException( projectId, e.getMessage(), projectDescriptor, e );
|
throw new InvalidProjectModelException( projectId, e.getMessage(), projectDescriptor, e );
|
||||||
}
|
}
|
||||||
|
|
||||||
return project;
|
return project;
|
||||||
}
|
}
|
||||||
|
|
||||||
private PomClassicDomainModel build( String projectId, File pomFile, ProjectBuilderConfiguration projectBuilderConfiguration )
|
private PomClassicDomainModel build( String projectId, File pomFile, ProjectBuilderConfiguration projectBuilderConfiguration )
|
||||||
|
@ -1419,13 +1419,23 @@ public void testDependencyScopeInheritance()
|
|||||||
assertNull("Scope not null: " + scope, scope);
|
assertNull("Scope not null: " + scope, scope);
|
||||||
System.out.println(pom.getDomainModel().asString());
|
System.out.println(pom.getDomainModel().asString());
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testDependencyScope()
|
public void testDependencyScope()
|
||||||
throws Exception
|
throws Exception
|
||||||
{
|
{
|
||||||
PomTestWrapper pom = buildPom( "dependency-scope/sub" );
|
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 )
|
private void assertPathSuffixEquals( String expected, Object actual )
|
||||||
{
|
{
|
||||||
String a = actual.toString();
|
String a = actual.toString();
|
||||||
|
@ -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>
|
@ -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>
|
Loading…
x
Reference in New Issue
Block a user