You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@maven.apache.org by hb...@apache.org on 2019/01/14 13:02:49 UTC

[maven] 03/05: [MNG-6533] Test: ProjectBuildingException miss reference to MavenProject

This is an automated email from the ASF dual-hosted git repository.

hboutemy pushed a commit to branch MNG-6533-2
in repository https://gitbox.apache.org/repos/asf/maven.git

commit ae1c32aa099b63e68200128c5bd526a08c07b9f5
Author: Mickael Istria <mi...@redhat.com>
AuthorDate: Thu Nov 29 18:26:46 2018 +0100

    [MNG-6533] Test: ProjectBuildingException miss reference to MavenProject
---
 .../apache/maven/project/ProjectBuilderTest.java   | 41 ++++++++++++++++++++++
 .../resources/projects/artifactMissingVersion.xml  | 34 ++++++++++++++++++
 2 files changed, 75 insertions(+)

diff --git a/maven-core/src/test/java/org/apache/maven/project/ProjectBuilderTest.java b/maven-core/src/test/java/org/apache/maven/project/ProjectBuilderTest.java
index c472e47..369b22e 100644
--- a/maven-core/src/test/java/org/apache/maven/project/ProjectBuilderTest.java
+++ b/maven-core/src/test/java/org/apache/maven/project/ProjectBuilderTest.java
@@ -27,6 +27,7 @@ import java.util.Properties;
 import org.apache.maven.AbstractCoreMavenComponentTestCase;
 import org.apache.maven.execution.MavenSession;
 import org.apache.maven.model.building.FileModelSource;
+import org.apache.maven.model.building.ModelBuildingRequest;
 import org.apache.maven.model.building.ModelSource;
 import org.apache.maven.shared.utils.io.FileUtils;
 
@@ -167,4 +168,44 @@ public class ProjectBuilderTest
             FileUtils.deleteDirectory( tempDir );
         }
     }
+
+    public void testReadErroneousMavenProjectContainsReference()
+        throws Exception
+    {
+        File pomFile = new File( "src/test/resources/projects/artifactMissingVersion.xml" ).getAbsoluteFile();
+        MavenSession mavenSession = createMavenSession( null );
+        ProjectBuildingRequest configuration = new DefaultProjectBuildingRequest();
+        configuration.setValidationLevel( ModelBuildingRequest.VALIDATION_LEVEL_MINIMAL );
+        configuration.setRepositorySession( mavenSession.getRepositorySession() );
+        org.apache.maven.project.ProjectBuilder projectBuilder =
+            lookup( org.apache.maven.project.ProjectBuilder.class );
+
+        // single project build entry point
+        try
+        {
+            projectBuilder.build( pomFile, configuration );
+        }
+        catch ( ProjectBuildingException ex )
+        {
+            assertEquals( 1, ex.getResults().size() );
+            MavenProject project = ex.getResults().get( 0 ).getProject();
+            assertNotNull( project );
+            assertEquals( "testArtifactMissingVersion", project.getArtifactId() );
+            assertEquals( pomFile, project.getFile() );
+        }
+
+        // multi projects build entry point
+        try
+        {
+            projectBuilder.build( Collections.singletonList( pomFile ), false, configuration );
+        }
+        catch ( ProjectBuildingException ex )
+        {
+            assertEquals( 1, ex.getResults().size() );
+            MavenProject project = ex.getResults().get( 0 ).getProject();
+            assertNotNull( project );
+            assertEquals( "testArtifactMissingVersion", project.getArtifactId() );
+            assertEquals( pomFile, project.getFile() );
+        }
+    }
 }
diff --git a/maven-core/src/test/resources/projects/artifactMissingVersion.xml b/maven-core/src/test/resources/projects/artifactMissingVersion.xml
new file mode 100644
index 0000000..b87aa28
--- /dev/null
+++ b/maven-core/src/test/resources/projects/artifactMissingVersion.xml
@@ -0,0 +1,34 @@
+<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 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+  <modelVersion>4.0.0</modelVersion>
+  <groupId>markerTest</groupId>
+  <artifactId>testArtifactMissingVersion</artifactId>
+  <version>0.0.1-SNAPSHOT</version>
+
+  <dependencies>
+    <dependency>
+      <groupId>missing</groupId>
+      <artifactId>missing</artifactId>
+    </dependency>
+  </dependencies>
+  <build>
+    <plugins>
+      <plugin>
+        <artifactId>maven-compiler-plugin</artifactId>
+        <version>2.0.2</version>
+      </plugin>
+      <plugin>
+        <artifactId>maven-jar-plugin</artifactId>
+        <version>2.2</version>
+      </plugin>
+      <plugin>
+        <artifactId>maven-resources-plugin</artifactId>
+        <version>2.4.1</version>
+      </plugin>
+      <plugin>
+        <artifactId>maven-surefire-plugin</artifactId>
+        <version>2.4.3</version>
+      </plugin>
+    </plugins>
+  </build>
+</project>