You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@maven.apache.org by rf...@apache.org on 2021/02/14 15:57:32 UTC
[maven] branch master updated (f820b41 -> 84a1ff2)
This is an automated email from the ASF dual-hosted git repository.
rfscholte pushed a change to branch master
in repository https://gitbox.apache.org/repos/asf/maven.git.
from f820b41 [MNG-7095] Fix resume for parallel builds
add 619973b [MNG-7063] Infinite loop using Shade plugin and JUnit 5 dependency
new 84a1ff2 [MNG-7063] Add unittest to ensure rereading a pom won't return the cached Model
The 1 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails. The revisions
listed as "add" were already present in the repository and have only
been added to this reference.
Summary of changes:
.../maven/project/DefaultProjectBuilder.java | 32 +-
.../apache/maven/project/ReactorModelCache.java | 160 -----
.../project/DefaultMavenProjectBuilderTest.java | 125 ++--
.../apache/maven/project/ProjectBuilderTest.java | 9 -
.../pom.xml => resources/projects/reread/pom1.xml} | 6 +-
.../pom.xml => resources/projects/reread/pom2.xml} | 7 +-
.../main/java/org/apache/maven/cli/MavenCli.java | 6 +
.../maven/model/building/DefaultModelBuilder.java | 649 ++++++---------------
.../building/DefaultModelBuildingRequest.java | 1 +
.../maven/model/building/FileToRawModelMerger.java | 190 ++++++
.../apache/maven/model/building/ModelCache.java | 56 ++
.../model/building/FileToRawModelMergerTest.java | 1 -
.../repository/internal/DefaultModelCache.java | 153 ++++-
13 files changed, 631 insertions(+), 764 deletions(-)
delete mode 100644 maven-core/src/main/java/org/apache/maven/project/ReactorModelCache.java
copy maven-core/src/test/{resources-project-builder/system-property-interpolation/pom.xml => resources/projects/reread/pom1.xml} (91%)
copy maven-core/src/test/{resources-project-builder/system-property-interpolation/pom.xml => resources/projects/reread/pom2.xml} (91%)
create mode 100644 maven-model-builder/src/main/java/org/apache/maven/model/building/FileToRawModelMerger.java
[maven] 01/01: [MNG-7063] Add unittest to ensure rereading a pom
won't return the cached Model
Posted by rf...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
rfscholte pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/maven.git
commit 84a1ff2d5cb7bf49fa3171dd92f7ac088e837185
Author: rfscholte <rf...@apache.org>
AuthorDate: Sun Feb 14 16:56:25 2021 +0100
[MNG-7063] Add unittest to ensure rereading a pom won't return the cached Model
---
.../project/DefaultMavenProjectBuilderTest.java | 125 +++++++++------------
.../src/test/resources/projects/reread/pom1.xml | 26 +++++
.../src/test/resources/projects/reread/pom2.xml | 27 +++++
3 files changed, 105 insertions(+), 73 deletions(-)
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 73942a0..1996208 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
@@ -19,71 +19,45 @@ package org.apache.maven.project;
* under the License.
*/
-import java.io.File;
-import java.util.ArrayList;
-import java.util.List;
-
-import org.apache.maven.artifact.Artifact;
-import org.apache.maven.artifact.repository.ArtifactRepository;
-import org.codehaus.plexus.util.FileUtils;
-import org.junit.jupiter.api.AfterEach;
-import org.junit.jupiter.api.BeforeEach;
-import org.junit.jupiter.api.Test;
-
import static org.apache.maven.test.PlexusExtension.getTestFile;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.containsString;
+import static org.hamcrest.Matchers.is;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertNull;
import static org.junit.jupiter.api.Assertions.assertThrows;
-import static org.junit.jupiter.api.Assertions.fail;
+
+import java.io.File;
+import java.io.InputStream;
+import java.nio.file.Files;
+import java.nio.file.Path;
+import java.nio.file.StandardCopyOption;
+import java.util.List;
+
+import org.apache.maven.artifact.Artifact;
+import org.apache.maven.artifact.repository.ArtifactRepository;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.io.TempDir;
public class DefaultMavenProjectBuilderTest
extends AbstractMavenProjectTestCase
{
-
- private List<File> filesToDelete = new ArrayList<>();
-
- private File localRepoDir;
+ @TempDir
+ File localRepoDir;
+
+ // only use by reread()
+ @TempDir
+ Path projectRoot;
@Override
@BeforeEach
public void setUp()
throws Exception
{
- super.setUp();
-
projectBuilder = getContainer().lookup( ProjectBuilder.class );
-
- localRepoDir = new File( System.getProperty( "java.io.tmpdir" ), "local-repo." + System.currentTimeMillis() );
- localRepoDir.mkdirs();
-
- filesToDelete.add( localRepoDir );
- }
-
- @AfterEach
- public void tearDown()
- throws Exception
- {
- if ( !filesToDelete.isEmpty() )
- {
- for ( File file : filesToDelete )
- {
- if ( file.exists() )
- {
- if ( file.isDirectory() )
- {
- FileUtils.deleteDirectory( file );
- }
- else
- {
- file.delete();
- }
- }
- }
- }
}
protected MavenProject getProject( Artifact pom, boolean allowStub )
@@ -135,7 +109,7 @@ public class DefaultMavenProjectBuilderTest
ProjectBuildingException.class,
() -> getProject( f1 ),
"Expected to fail for future versions" );
- assertContains( "Building this project requires a newer version of Maven", e.getMessage() );
+ assertThat( e.getMessage(), containsString( "Building this project requires a newer version of Maven" ) );
}
@Test
@@ -150,7 +124,7 @@ public class DefaultMavenProjectBuilderTest
ProjectBuildingException.class,
() -> getProject( f1 ),
"Expected to fail for past versions" );
- assertContains( "Building this project requires an older version of Maven", e.getMessage() );
+ assertThat( e.getMessage(), containsString( "Building this project requires an older version of Maven" ) );
}
@Test
@@ -163,17 +137,7 @@ public class DefaultMavenProjectBuilderTest
ProjectBuildingException.class,
() -> getProject( f1 ),
"Expected to fail for future versions" );
- assertContains( "Building this project requires a newer version of Maven", e.getMessage() );
- }
-
- private void assertContains( String expected, String actual )
- {
- if ( actual == null || !actual.contains( expected ) )
- {
- fail( "Expected: a string containing " + expected + "\nActual: " + ( actual == null
- ? "null"
- : "'" + actual + "'" ) );
- }
+ assertThat( e.getMessage(), containsString( "Building this project requires a newer version of Maven" ) );
}
@Test
@@ -204,16 +168,6 @@ public class DefaultMavenProjectBuilderTest
return repositorySystem.createLocalRepository( getLocalRepositoryPath() );
}
- public void xtestLoop()
- throws Exception
- {
- while ( true )
- {
- File f1 = getTestFile( "src/test/resources/projects/duplicate-plugins-merged-pom.xml" );
- getProject( f1 );
- }
- }
-
@Test
public void testPartialResultUponBadDependencyDeclaration()
throws Exception
@@ -273,7 +227,6 @@ public class DefaultMavenProjectBuilderTest
ProjectBuildingException.class,
() -> getProject( f1 ),
"Expected 'ProjectBuildingException' not thrown." );
- assertNotNull( e.getMessage() );
assertThat( e.getMessage(), containsString( "Version must be a constant" ) );
}
@@ -293,7 +246,6 @@ public class DefaultMavenProjectBuilderTest
ProjectBuildingException.class,
() -> getProject( f1 ),
"Expected 'ProjectBuildingException' not thrown." );
- assertNotNull( e.getMessage() );
assertThat( e.getMessage(), containsString( "Version must be a constant" ) );
}
@@ -333,7 +285,6 @@ public class DefaultMavenProjectBuilderTest
ProjectBuildingException.class,
() -> getProjectFromRemoteRepository( f1 ),
"Expected 'ProjectBuildingException' not thrown." );
- assertNotNull( e.getMessage() );
assertThat( e.getMessage(), containsString( "Version must be a constant" ) );
}
@@ -353,8 +304,36 @@ public class DefaultMavenProjectBuilderTest
ProjectBuildingException.class,
() -> getProjectFromRemoteRepository( f1 ),
"Expected 'ProjectBuildingException' not thrown." );
- assertNotNull( e.getMessage() );
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" ) )
+ {
+ 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 );
+ }
+
+ project = getProject( pom.toFile() );
+ assertThat( project.getName(), is( "PROJECT NAME" ) );
+ }
}
diff --git a/maven-core/src/test/resources/projects/reread/pom1.xml b/maven-core/src/test/resources/projects/reread/pom1.xml
new file mode 100644
index 0000000..724f2cc
--- /dev/null
+++ b/maven-core/src/test/resources/projects/reread/pom1.xml
@@ -0,0 +1,26 @@
+<?xml version="1.0" encoding="UTF-8"?>
+
+<!--
+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
+regarding copyright ownership. The ASF licenses this file
+to you under the Apache License, Version 2.0 (the
+"License"); you may not use this file except in compliance
+with the License. You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing,
+software distributed under the License is distributed on an
+"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+KIND, either express or implied. See the License for the
+specific language governing permissions and limitations
+under the License.
+-->
+<project>
+ <modelVersion>4.0.0</modelVersion>
+ <groupId>gid</groupId>
+ <artifactId>aid</artifactId>
+ <version>1.0</version>
+</project>
diff --git a/maven-core/src/test/resources/projects/reread/pom2.xml b/maven-core/src/test/resources/projects/reread/pom2.xml
new file mode 100644
index 0000000..ebcafa1
--- /dev/null
+++ b/maven-core/src/test/resources/projects/reread/pom2.xml
@@ -0,0 +1,27 @@
+<?xml version="1.0" encoding="UTF-8"?>
+
+<!--
+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
+regarding copyright ownership. The ASF licenses this file
+to you under the Apache License, Version 2.0 (the
+"License"); you may not use this file except in compliance
+with the License. You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing,
+software distributed under the License is distributed on an
+"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+KIND, either express or implied. See the License for the
+specific language governing permissions and limitations
+under the License.
+-->
+<project>
+ <modelVersion>4.0.0</modelVersion>
+ <groupId>gid</groupId>
+ <artifactId>aid</artifactId>
+ <version>1.0</version>
+ <name>PROJECT NAME</name>
+</project>