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 14:54:56 UTC
[maven] 02/02: [MNG-7063] Add unittest to ensure rereading a pom
won't return the cached Model
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 66c0415afdd6a28773b1b98c22662de01a21bfee
Author: rfscholte <rf...@apache.org>
AuthorDate: Sun Feb 14 15:53:23 2021 +0100
[MNG-7063] Add unittest to ensure rereading a pom won't return the cached Model
---
.../project/DefaultMavenProjectBuilderTest.java | 83 ++++++++++------------
.../src/test/resources/projects/reread/pom1.xml | 6 ++
.../src/test/resources/projects/reread/pom2.xml | 7 ++
3 files changed, 51 insertions(+), 45 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..18e2357 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,20 +19,11 @@ 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.hamcrest.Matchers.nullValue;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertNotNull;
@@ -40,50 +31,34 @@ 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.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 )
@@ -356,5 +331,23 @@ public class DefaultMavenProjectBuilderTest
assertNotNull( e.getMessage() );
assertThat( e.getMessage(), containsString( "Version must be a constant" ) );
}
+
+ @Test
+ public void rereadPom_mng7063() throws Exception
+ {
+ final Path pom = projectRoot.resolve( "pom.xml" );
+
+ Files.copy( DefaultMavenProjectBuilderTest.class.getResourceAsStream( "/projects/reread/pom1.xml" ),
+ pom, StandardCopyOption.REPLACE_EXISTING );
+
+ MavenProject project = getProject( pom.toFile() );
+ assertThat( project.getName(), is( "aid" ) ); // inherited from artifactId
+
+ Files.copy( DefaultMavenProjectBuilderTest.class.getResourceAsStream( "/projects/reread/pom2.xml" ),
+ 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..c439214
--- /dev/null
+++ b/maven-core/src/test/resources/projects/reread/pom1.xml
@@ -0,0 +1,6 @@
+<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..b71b8a8
--- /dev/null
+++ b/maven-core/src/test/resources/projects/reread/pom2.xml
@@ -0,0 +1,7 @@
+<project>
+ <modelVersion>4.0.0</modelVersion>
+ <groupId>gid</groupId>
+ <artifactId>aid</artifactId>
+ <version>1.0</version>
+ <name>PROJECT NAME</name>
+</project>