[MNG-6533] Test: ProjectBuildingException miss reference to MavenProject
authorMickael Istria <mistria@redhat.com>
Thu, 29 Nov 2018 17:26:46 +0000 (18:26 +0100)
committerHervé Boutemy <hboutemy@apache.org>
Mon, 14 Jan 2019 12:55:44 +0000 (13:55 +0100)
maven-core/src/test/java/org/apache/maven/project/ProjectBuilderTest.java
maven-core/src/test/resources/projects/artifactMissingVersion.xml [new file with mode: 0644]

index c472e47..369b22e 100644 (file)
@@ -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 (file)
index 0000000..b87aa28
--- /dev/null
@@ -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>