mirror of https://github.com/apache/maven.git
[MNG-7170] Allow to associate pomFile/${basedir} with DefaultProjectBuilder.build(ModelSource, ...)
Actually a subset backport of MNG-5669 (5cdb8332f9
)
Also-By: rfscholte <rfscholte@apache.org>
This closes #478
This commit is contained in:
parent
3a465e1477
commit
5a89973126
|
@ -39,6 +39,8 @@ import org.apache.maven.execution.MavenSession;
|
|||
import org.apache.maven.model.Plugin;
|
||||
import org.apache.maven.model.building.FileModelSource;
|
||||
import org.apache.maven.model.building.ModelBuildingRequest;
|
||||
import org.apache.maven.model.building.ModelProblem;
|
||||
import org.apache.maven.model.building.ModelProblem.Severity;
|
||||
import org.apache.maven.model.building.ModelSource;
|
||||
import org.apache.maven.shared.utils.io.FileUtils;
|
||||
|
||||
|
@ -83,6 +85,30 @@ public class ProjectBuilderTest
|
|||
assertNotNull( result.getProject().getParentFile() );
|
||||
}
|
||||
|
||||
public void testBuildFromModelSourceResolvesBasedir()
|
||||
throws Exception
|
||||
{
|
||||
File pomFile = new File( "src/test/resources/projects/modelsourcebasedir/pom.xml" );
|
||||
MavenSession mavenSession = createMavenSession( null );
|
||||
ProjectBuildingRequest configuration = new DefaultProjectBuildingRequest();
|
||||
configuration.setRepositorySession( mavenSession.getRepositorySession() );
|
||||
ModelSource modelSource = new FileModelSource( pomFile );
|
||||
ProjectBuildingResult result =
|
||||
getContainer().lookup( org.apache.maven.project.ProjectBuilder.class ).build( modelSource, configuration );
|
||||
|
||||
assertEquals( pomFile.getAbsoluteFile(), result.getProject().getModel().getPomFile().getAbsoluteFile() );
|
||||
int errors = 0;
|
||||
for ( ModelProblem p : result.getProblems() )
|
||||
{
|
||||
if ( p.getSeverity() == Severity.ERROR )
|
||||
{
|
||||
errors++;
|
||||
}
|
||||
}
|
||||
assertEquals( 0, errors );
|
||||
}
|
||||
|
||||
|
||||
public void testVersionlessManagedDependency()
|
||||
throws Exception
|
||||
{
|
||||
|
|
|
@ -0,0 +1,19 @@
|
|||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<groupId>test.readparent</groupId>
|
||||
<artifactId>local-parent</artifactId>
|
||||
<packaging>pom</packaging>
|
||||
<version>1.0</version>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>blah</groupId>
|
||||
<artifactId>blah</artifactId>
|
||||
<version>0.0.1-SNASPSHOT</version>
|
||||
<scope>system</scope>
|
||||
<systemPath>${basedir}/blah.jar</systemPath>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
</project>
|
|
@ -617,7 +617,14 @@ public class DefaultModelBuilder
|
|||
throw problems.newModelBuildingException();
|
||||
}
|
||||
|
||||
if ( pomFile != null )
|
||||
{
|
||||
model.setPomFile( pomFile );
|
||||
}
|
||||
else if ( modelSource instanceof FileModelSource )
|
||||
{
|
||||
model.setPomFile( ( (FileModelSource) modelSource ).getFile() );
|
||||
}
|
||||
|
||||
problems.setSource( model );
|
||||
modelValidator.validateRawModel( model, request, problems );
|
||||
|
|
Loading…
Reference in New Issue