This is an automated email from the ASF dual-hosted git repository. rfscholte pushed a commit to branch MNG-7063 in repository https://gitbox.apache.org/repos/asf/maven.git
commit d834d1489d34600acf68b3c61d836531aebdd351 Author: rfscholte <rfscho...@apache.org> AuthorDate: Sat Feb 20 20:14:36 2021 +0100 [MNG-7063] Infinite loop using Shade plugin and JUnit 5 dependency --- .../maven/project/DefaultProjectBuilder.java | 6 ++- .../project/AbstractMavenProjectTestCase.java | 2 + .../project/DefaultMavenProjectBuilderTest.java | 53 +++++++++++----------- 3 files changed, 34 insertions(+), 27 deletions(-) diff --git a/maven-core/src/main/java/org/apache/maven/project/DefaultProjectBuilder.java b/maven-core/src/main/java/org/apache/maven/project/DefaultProjectBuilder.java index 29f86b8..12e6e23 100644 --- a/maven-core/src/main/java/org/apache/maven/project/DefaultProjectBuilder.java +++ b/maven-core/src/main/java/org/apache/maven/project/DefaultProjectBuilder.java @@ -279,7 +279,11 @@ public class DefaultProjectBuilder request.setUserProperties( configuration.getUserProperties() ); request.setBuildStartTime( configuration.getBuildStartTime() ); request.setModelResolver( resolver ); - request.setModelCache( DefaultModelCache.newInstance( config.session ) ); + // this is a hint that we want to build 1 file, so don't cache. See MNG-7063 + if ( config.modelPool != null ) + { + request.setModelCache( DefaultModelCache.newInstance( config.session ) ); + } request.setTransformerContextBuilder( config.transformerContextBuilder ); return request; diff --git a/maven-core/src/test/java/org/apache/maven/project/AbstractMavenProjectTestCase.java b/maven-core/src/test/java/org/apache/maven/project/AbstractMavenProjectTestCase.java index d146927..3952467 100644 --- a/maven-core/src/test/java/org/apache/maven/project/AbstractMavenProjectTestCase.java +++ b/maven-core/src/test/java/org/apache/maven/project/AbstractMavenProjectTestCase.java @@ -29,6 +29,7 @@ import org.apache.maven.repository.RepositorySystem; import org.apache.maven.repository.internal.MavenRepositorySystemUtils; import org.apache.maven.test.PlexusTest; import org.codehaus.plexus.PlexusContainer; +import org.eclipse.aether.DefaultRepositoryCache; import org.eclipse.aether.DefaultRepositorySystemSession; import org.junit.jupiter.api.AfterEach; import org.junit.jupiter.api.BeforeEach; @@ -171,6 +172,7 @@ public abstract class AbstractMavenProjectTestCase { File localRepo = new File( request.getLocalRepository().getBasedir() ); DefaultRepositorySystemSession repoSession = MavenRepositorySystemUtils.newSession(); + repoSession.setCache( new DefaultRepositoryCache() ); repoSession.setLocalRepositoryManager( new LegacyLocalRepositoryManager( localRepo ) ); request.setRepositorySession( repoSession ); } diff --git a/maven-core/src/test/java/org/apache/maven/project/DefaultMavenProjectBuilderTest.java b/maven-core/src/test/java/org/apache/maven/project/DefaultMavenProjectBuilderTest.java index 1996208..9338cd2 100644 --- a/maven-core/src/test/java/org/apache/maven/project/DefaultMavenProjectBuilderTest.java +++ b/maven-core/src/test/java/org/apache/maven/project/DefaultMavenProjectBuilderTest.java @@ -307,33 +307,34 @@ public class DefaultMavenProjectBuilderTest assertThat( e.getMessage(), containsString( "Version must be a constant" ) ); } - /** - * Ensure that when re-reading a pom, it should not use the cached Model - * - * @throws Exception - */ - @Test - public void rereadPom_mng7063() throws Exception - { - final Path pom = projectRoot.resolve( "pom.xml" ); - - try ( InputStream pomResource = - DefaultMavenProjectBuilderTest.class.getResourceAsStream( "/projects/reread/pom1.xml" ) ) + /** + * Ensure that when re-reading a pom, it should not use the cached Model + * + * @throws Exception + */ + @Test + public void rereadPom_mng7063() throws Exception { - Files.copy( pomResource, pom, StandardCopyOption.REPLACE_EXISTING ); - } - - MavenProject project = getProject( pom.toFile() ); - assertThat( project.getName(), is( "aid" ) ); // inherited from artifactId - - try ( InputStream pomResource = - DefaultMavenProjectBuilderTest.class.getResourceAsStream( "/projects/reread/pom2.xml" ) ) - { - Files.copy( pomResource, pom, StandardCopyOption.REPLACE_EXISTING ); + final Path pom = projectRoot.resolve( "pom.xml" ); + final ProjectBuildingRequest buildingRequest = newBuildingRequest(); + + try ( InputStream pomResource = + DefaultMavenProjectBuilderTest.class.getResourceAsStream( "/projects/reread/pom1.xml" ) ) + { + Files.copy( pomResource, pom, StandardCopyOption.REPLACE_EXISTING ); + } + + MavenProject project = projectBuilder.build( pom.toFile(), buildingRequest ).getProject(); + assertThat( project.getName(), is( "aid" ) ); // inherited from artifactId + + try ( InputStream pomResource = + DefaultMavenProjectBuilderTest.class.getResourceAsStream( "/projects/reread/pom2.xml" ) ) + { + Files.copy( pomResource, pom, StandardCopyOption.REPLACE_EXISTING ); + } + + project = projectBuilder.build( pom.toFile(), buildingRequest ).getProject(); + assertThat( project.getName(), is( "PROJECT NAME" ) ); } - project = getProject( pom.toFile() ); - assertThat( project.getName(), is( "PROJECT NAME" ) ); - } - }