[MNG-7226] DefaultModelBuilder.buildRawModel fails (#528)

as it ignores pom file
This commit is contained in:
Mickael Istria 2021-09-03 09:56:30 +02:00 committed by GitHub
parent 92d2c2e3b4
commit 76d7f58a61
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 19 additions and 5 deletions

View File

@ -636,7 +636,8 @@ public class DefaultModelBuilder
public Result<? extends Model> buildRawModel( File pomFile, int validationLevel, boolean locationTracking )
{
final ModelBuildingRequest request = new DefaultModelBuildingRequest().setValidationLevel( validationLevel )
.setLocationTracking( locationTracking );
.setLocationTracking( locationTracking )
.setModelSource( new FileModelSource( pomFile ) );
final DefaultModelProblemCollector collector =
new DefaultModelProblemCollector( new DefaultModelBuildingResult() );
try

View File

@ -1,6 +1,11 @@
package org.apache.maven.model.building;
/*
import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertThrows;
import java.io.File;
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
@ -20,6 +25,7 @@ package org.apache.maven.model.building;
*/
import org.apache.maven.model.Dependency;
import org.apache.maven.model.Model;
import org.apache.maven.model.Parent;
import org.apache.maven.model.Repository;
import org.apache.maven.model.resolution.InvalidRepositoryException;
@ -27,9 +33,6 @@ import org.apache.maven.model.resolution.ModelResolver;
import org.apache.maven.model.resolution.UnresolvableModelException;
import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertThrows;
/**
* @author Guillaume Nodet
*/
@ -144,4 +147,14 @@ public class DefaultModelBuilderTest
}
}
@Test
public void testBuildRawModel()
throws Exception
{
ModelBuilder builder = new DefaultModelBuilderFactory().newInstance();
assertNotNull( builder );
Result<? extends Model> res = builder.buildRawModel( new File( getClass().getResource("/poms/factory/simple.xml" ).getFile() ), ModelBuildingRequest.VALIDATION_LEVEL_MINIMAL, false);
assertNotNull( res.get() );
}
}