You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@maven.apache.org by mi...@apache.org on 2019/07/25 12:30:53 UTC

[maven] branch MNG-6723 updated (2deeba3 -> 55080cb)

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

michaelo pushed a change to branch MNG-6723
in repository https://gitbox.apache.org/repos/asf/maven.git.


 discard 2deeba3  [MNG-6723] MavenProject.getParentFile() not set when using ProjectBuilder.build()
     new 55080cb  [MNG-6723] MavenProject.getParentFile() not set when using ProjectBuilder.build()

This update added new revisions after undoing existing revisions.
That is to say, some revisions that were in the old version of the
branch are not in the new version.  This situation occurs
when a user --force pushes a change and generates a repository
containing something like this:

 * -- * -- B -- O -- O -- O   (2deeba3)
            \
             N -- N -- N   refs/heads/MNG-6723 (55080cb)

You should already have received notification emails for all of the O
revisions, and so the following emails describe only the N revisions
from the common base, B.

Any revisions marked "omit" are not gone; other references still
refer to them.  Any revisions marked "discard" are gone forever.

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:
 .../apache/maven/project/ProjectBuilderTest.java   | 27 ++++++++++++++--------
 .../project-builder/MNG-6723/child/pom.xml         | 16 ++++++-------
 .../test/projects/project-builder/MNG-6723/pom.xml | 16 ++++++-------
 3 files changed, 33 insertions(+), 26 deletions(-)


[maven] 01/01: [MNG-6723] MavenProject.getParentFile() not set when using ProjectBuilder.build()

Posted by mi...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

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

commit 55080cb66f66b7cbac1aaa3cbbc339eb46bc7481
Author: Mickael Istria <mi...@redhat.com>
AuthorDate: Fri Jul 19 14:16:16 2019 +0200

    [MNG-6723] MavenProject.getParentFile() not set when using ProjectBuilder.build()
    
    This closes #273
---
 .../maven/project/DefaultProjectBuilder.java       |  4 ++
 .../apache/maven/project/ProjectBuilderTest.java   | 61 ++++++++++++++++++++++
 .../project-builder/MNG-6723/child/pom.xml         | 11 ++++
 .../test/projects/project-builder/MNG-6723/pom.xml | 11 ++++
 4 files changed, 87 insertions(+)

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 400b716..51c90cc 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
@@ -976,6 +976,10 @@ public class DefaultProjectBuilder
                 }
             }
             project.setParent( parent );
+            if ( project.getParentFile() == null && parent != null )
+            {
+                project.setParentFile( parent.getFile() );
+            }
         }
     }
 
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 a7ed939..95c3149 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
@@ -20,6 +20,7 @@ package org.apache.maven.project;
  */
 
 import java.io.File;
+import java.util.ArrayList;
 import java.util.Collections;
 import java.util.List;
 import java.util.Properties;
@@ -245,4 +246,64 @@ public class ProjectBuilderTest
         }
     }
 
+    public void testReadParentAndChildWithRegularVersionSetParentFile()
+        throws Exception
+    {
+        List<File> toRead = new ArrayList<>( 2 );
+        File parentPom = getProject( "MNG-6723" );
+        toRead.add( parentPom );
+        toRead.add( new File( parentPom.getParentFile(), "child/pom.xml" ) );
+        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 );
+
+        // read poms separately
+        boolean parentFileWasFoundOnChild = false;
+        for ( File file : toRead )
+        {
+            List<ProjectBuildingResult> results = projectBuilder.build( Collections.singletonList( file ), false, configuration );
+            assertResultShowNoError( results );
+            MavenProject project = findChildProject( results );
+            if ( project != null )
+            {
+                assertEquals( parentPom, project.getParentFile() );
+                parentFileWasFoundOnChild = true;
+            }
+        }
+        assertTrue( parentFileWasFoundOnChild );
+
+        // read projects together
+        List<ProjectBuildingResult> results = projectBuilder.build( toRead, false, configuration );
+        assertResultShowNoError( results );
+        assertEquals( parentPom, findChildProject( results ).getParentFile() );
+        Collections.reverse( toRead );
+        results = projectBuilder.build( toRead, false, configuration );
+        assertResultShowNoError( results );
+        assertEquals( parentPom, findChildProject( results ).getParentFile() );
+    }
+
+    private MavenProject findChildProject( List<ProjectBuildingResult> results )
+    {
+        for ( ProjectBuildingResult result : results )
+        {
+            if ( result.getPomFile().getParentFile().getName().equals( "child" ) )
+            {
+                return result.getProject();
+            }
+        }
+        return null;
+    }
+
+    private void assertResultShowNoError(List<ProjectBuildingResult> results)
+    {
+        for ( ProjectBuildingResult result : results )
+        {
+            assertTrue( result.getProblems().isEmpty() );
+            assertNotNull( result.getProject() );
+        }
+    }
+
 }
diff --git a/maven-core/src/test/projects/project-builder/MNG-6723/child/pom.xml b/maven-core/src/test/projects/project-builder/MNG-6723/child/pom.xml
new file mode 100644
index 0000000..20284eb
--- /dev/null
+++ b/maven-core/src/test/projects/project-builder/MNG-6723/child/pom.xml
@@ -0,0 +1,11 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<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 https://maven.apache.org/xsd/maven-4.0.0.xsd">
+  <modelVersion>4.0.0</modelVersion>
+  <parent>
+    <groupId>example.eclipse-548652</groupId>
+    <artifactId>parent</artifactId>
+    <version>0.0.1-SNAPSHOT</version>
+  </parent>
+  <artifactId>child</artifactId>
+  <packaging>jar</packaging>
+</project>
diff --git a/maven-core/src/test/projects/project-builder/MNG-6723/pom.xml b/maven-core/src/test/projects/project-builder/MNG-6723/pom.xml
new file mode 100644
index 0000000..e21f824
--- /dev/null
+++ b/maven-core/src/test/projects/project-builder/MNG-6723/pom.xml
@@ -0,0 +1,11 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<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 https://maven.apache.org/xsd/maven-4.0.0.xsd">
+  <modelVersion>4.0.0</modelVersion>
+  <groupId>example.eclipse-548652</groupId>
+  <artifactId>parent</artifactId>
+  <version>0.0.1-SNAPSHOT</version>
+  <packaging>pom</packaging>
+  <modules>
+    <module>child</module>
+  </modules>
+</project>