You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@maven.apache.org by "Stephan Schroevers (JIRA)" <ji...@codehaus.org> on 2015/03/18 12:11:17 UTC

[jira] (MNG-5786) Variable maven.multiModuleProjectDirectory may be set incorrectly

Stephan Schroevers created MNG-5786:
---------------------------------------

             Summary: Variable maven.multiModuleProjectDirectory may be set incorrectly
                 Key: MNG-5786
                 URL: https://jira.codehaus.org/browse/MNG-5786
             Project: Maven
          Issue Type: Bug
          Components: Bootstrap & Build
    Affects Versions: 3.3.1
         Environment: Linux
            Reporter: Stephan Schroevers
         Attachments: dummy-project.zip

Consider the following sequence of commands, executed using the attached [^dummy-project.zip]:
{noformat}
$ cd /tmp/
$ unzip dummy-project.zip
Archive:  dummy-project.zip
   creating: dummy/
   creating: dummy/.mvn/
   creating: dummy/project/
   creating: dummy/project/.mvn/
  inflating: dummy/project/pom.xml   
$ cd dummy/project/
$ mvn help:effective-pom | grep effectiveMultiModuleProjectDirectory
    <effectiveMultiModuleProjectDirectory>/tmp/dummy</effectiveMultiModuleProjectDirectory>
{noformat}

As you can see, the {{maven.multiModuleProjectDirectory}} variable is set to {{/tmp/dummy}}, even though the project is executed from within {{/tmp/dummy/project}}, which itself also contains a {{.mvn}} directory.

Based on MNG-5767 and the comments in the [relevant change|https://git-wip-us.apache.org/repos/asf?p=maven.git;a=blobdiff;f=apache-maven/src/bin/mvn;h=26feda4218197811e95390b746e2e002b585dd3b;hp=1ed3024b3fe442dc1e95fef193661abcde298a19;hb=8ed9a1caa8890773b45c6c408a4e40acf4f4b0fd;hpb=ee7dbab69dd87d219031b0715105527cdbf12639], I suspect this is a bug. The {{find_maven_basedir}} function should test for the presence of {{.mvn}} before traversing to the current working directory's parent directory.

Suggested fix:
{noformat}
diff --git a/apache-maven/src/bin/mvn b/apache-maven/src/bin/mvn
index 902de4a..5b6fed4 100755
--- a/apache-maven/src/bin/mvn
+++ b/apache-maven/src/bin/mvn
@@ -199,12 +199,14 @@ fi
 find_maven_basedir() {
   local basedir=$(pwd)
   local wdir=$(pwd)
-  while [ "$wdir" != '/' ] ; do
-    wdir=$(cd "$wdir/.."; pwd)
+  while true ; do
     if [ -d "$wdir"/.mvn ] ; then
       basedir=$wdir
       break
+    elif [ "$wdir" = '/' ] ; then
+      break;
     fi
+    wdir=$(cd "$wdir/.."; pwd)
   done
   echo "${basedir}"
 }
{noformat}

Two notes:
* I didn't check whether this issue affects {{mvn.cmd}}, as I'm not familiar with Windows shell scripts and do not have a Windows machine at my disposal.
* The patch does not simply move the {{wdir}} assignment below the {{if}}-statement, because that would break the case in which there is a sole {{.mvn}} in the file system root. (That'd be weird, yes, but allowed.)



--
This message was sent by Atlassian JIRA
(v6.1.6#6162)