diff --git a/maven-core-it/README.txt b/maven-core-it/README.txt
index aa0532b655..bf1e6f6c66 100644
--- a/maven-core-it/README.txt
+++ b/maven-core-it/README.txt
@@ -256,6 +256,8 @@ it0092: Test that legacy repositories with legacy snapshots download correctly.
it0094: Test classloading issues with mojos after 2.0 (MNG-1898).
+it0095: Test URL calculation when modules are in sibling dirs of parent. (MNG-2006)
+
-------------------------------------------------------------------------------
- generated sources
diff --git a/maven-core-it/integration-tests.txt b/maven-core-it/integration-tests.txt
index ee7263e425..ae840aab46 100644
--- a/maven-core-it/integration-tests.txt
+++ b/maven-core-it/integration-tests.txt
@@ -1,3 +1,4 @@
+it0095
it0094
it0092
# it0091 currrently fails. Not sure if there is an associated JIRA.
diff --git a/maven-core-it/it0095/goals.txt b/maven-core-it/it0095/goals.txt
new file mode 100644
index 0000000000..cc578f82d6
--- /dev/null
+++ b/maven-core-it/it0095/goals.txt
@@ -0,0 +1 @@
+integration-test
diff --git a/maven-core-it/it0095/parent/pom.xml b/maven-core-it/it0095/parent/pom.xml
new file mode 100644
index 0000000000..5e56537221
--- /dev/null
+++ b/maven-core-it/it0095/parent/pom.xml
@@ -0,0 +1,19 @@
+
+ 4.0.0
+
+ org.apache.maven.it.mng2006
+ parent
+ 1
+ pom
+
+
+
+ website
+ scp://host/path/parent
+
+
+
+
+ ../sub1
+
+
diff --git a/maven-core-it/it0095/pom.xml b/maven-core-it/it0095/pom.xml
new file mode 100644
index 0000000000..c8b753911e
--- /dev/null
+++ b/maven-core-it/it0095/pom.xml
@@ -0,0 +1,16 @@
+
+ 4.0.0
+ org.apache.maven.it.mng2006
+ bootstrapper
+ 1
+
+ pom
+
+
+ parent
+
+
+
+ integration-test
+
+
diff --git a/maven-core-it/it0095/sub1/pom.xml b/maven-core-it/it0095/sub1/pom.xml
new file mode 100644
index 0000000000..cad2fc78dc
--- /dev/null
+++ b/maven-core-it/it0095/sub1/pom.xml
@@ -0,0 +1,44 @@
+
+ 4.0.0
+
+ org.apache.maven.it.mng2006
+ parent
+ 1
+ ../parent
+
+
+ sub1
+
+
+ integration-test
+
+
+
+ maven-help-plugin
+
+
+
+
+
+ effective-pom
+ generate-resources
+
+ effective-pom
+
+
+
+
+
+ maven-verifier-plugin
+
+
+ verify
+
+ verify
+
+
+
+
+
+
+
diff --git a/maven-core-it/it0095/sub1/src/test/verifier/verifications.xml b/maven-core-it/it0095/sub1/src/test/verifier/verifications.xml
new file mode 100644
index 0000000000..a19537cee0
--- /dev/null
+++ b/maven-core-it/it0095/sub1/src/test/verifier/verifications.xml
@@ -0,0 +1,8 @@
+
+
+
+ target/effective-pom.xml
+ scp://host/path/sub1
+
+
+
diff --git a/maven-project/src/main/java/org/apache/maven/project/MavenProject.java b/maven-project/src/main/java/org/apache/maven/project/MavenProject.java
index fbda980d1e..f47bb8ffb9 100644
--- a/maven-project/src/main/java/org/apache/maven/project/MavenProject.java
+++ b/maven-project/src/main/java/org/apache/maven/project/MavenProject.java
@@ -136,7 +136,7 @@ public class MavenProject
private boolean executionRoot;
- private Map moduleFiles;
+ private Map moduleAdjustments;
public MavenProject( Model model )
{
@@ -193,40 +193,57 @@ public class MavenProject
public String getModulePathAdjustment( MavenProject moduleProject ) throws IOException
{
- File module = moduleProject.getFile();
+ // FIXME: This is hacky. What if module directory doesn't match artifactid, and parent
+ // is coming from the repository??
+ String module = moduleProject.getArtifactId();
- if ( module == null )
+ File moduleFile = moduleProject.getFile();
+
+ if ( moduleFile != null )
{
- return null;
+ File moduleDir = moduleFile.getCanonicalFile().getParentFile();
+
+ module = moduleDir.getName();
}
- module = module.getCanonicalFile();
-
- if ( moduleFiles == null )
+ if ( moduleAdjustments == null )
{
- moduleFiles = new HashMap();
+ moduleAdjustments = new HashMap();
List modules = getModules();
- File myFile = getFile();
-
- if ( myFile != null )
+ if ( modules != null )
{
- File myDir = myFile.getCanonicalFile().getParentFile();
- if ( modules != null )
+ for ( Iterator it = modules.iterator(); it.hasNext(); )
{
- for ( Iterator it = modules.iterator(); it.hasNext(); )
+ String modulePath = (String) it.next();
+ String moduleName = modulePath;
+
+ if ( moduleName.endsWith( "/" ) || moduleName.endsWith( "\\" ) )
{
- String modulePath = (String) it.next();
-
- File moduleFile = new File( myDir, modulePath ).getCanonicalFile();
-
- moduleFiles.put( moduleFile, modulePath );
+ moduleName = moduleName.substring( 0, moduleName.length() - 1 );
}
+
+ int lastSlash = moduleName.lastIndexOf( '/' );
+
+ if ( lastSlash < 0 )
+ {
+ lastSlash = moduleName.lastIndexOf( '\\' );
+ }
+
+ String adjustment = null;
+
+ if ( lastSlash > -1 )
+ {
+ moduleName = moduleName.substring( lastSlash + 1 );
+ adjustment = modulePath.substring( 0, lastSlash );
+ }
+
+ moduleAdjustments.put( moduleName, adjustment );
}
- }
+ }
}
- return (String) moduleFiles.get( module );
+ return (String) moduleAdjustments.get( module );
}
// ----------------------------------------------------------------------
diff --git a/maven-project/src/main/java/org/apache/maven/project/inheritance/DefaultModelInheritanceAssembler.java b/maven-project/src/main/java/org/apache/maven/project/inheritance/DefaultModelInheritanceAssembler.java
index 1d2268fb01..0b7fcc2f38 100644
--- a/maven-project/src/main/java/org/apache/maven/project/inheritance/DefaultModelInheritanceAssembler.java
+++ b/maven-project/src/main/java/org/apache/maven/project/inheritance/DefaultModelInheritanceAssembler.java
@@ -506,7 +506,10 @@ public class DefaultModelInheritanceAssembler
pathFragments.add( pathAdjustment );
}
- pathFragments.add( childPath );
+ if ( childPath != null )
+ {
+ pathFragments.add( childPath );
+ }
}
StringBuffer cleanedPath = new StringBuffer();
@@ -548,7 +551,18 @@ public class DefaultModelInheritanceAssembler
}
}
- if ( !childPath.endsWith( "/" ) && appendPaths )
+ String lastPathPart = childPath;
+ if ( lastPathPart == null )
+ {
+ lastPathPart = pathAdjustment;
+ }
+
+ if ( lastPathPart == null )
+ {
+ lastPathPart = parentPath;
+ }
+
+ if ( appendPaths && lastPathPart != null && !lastPathPart.endsWith( "/" ) )
{
cleanedPath.setLength( cleanedPath.length() - 1 );
}
diff --git a/maven-project/src/test/java/org/apache/maven/project/MavenProjectTest.java b/maven-project/src/test/java/org/apache/maven/project/MavenProjectTest.java
index 3075717cce..8b409112e6 100644
--- a/maven-project/src/test/java/org/apache/maven/project/MavenProjectTest.java
+++ b/maven-project/src/test/java/org/apache/maven/project/MavenProjectTest.java
@@ -17,6 +17,9 @@ package org.apache.maven.project;
*/
import java.io.File;
+import java.io.IOException;
+
+import org.apache.maven.model.Model;
public class MavenProjectTest
extends AbstractMavenProjectTestCase
@@ -29,4 +32,22 @@ public class MavenProjectTest
MavenProject clonedProject = new MavenProject(projectToClone);
assertEquals("maven-core", clonedProject.getArtifactId());
}
+
+ public void testGetModulePathAdjustment() throws IOException
+ {
+ Model moduleModel = new Model();
+
+ MavenProject module = new MavenProject( moduleModel );
+ module.setFile( new File( "module-dir/pom.xml" ) );
+
+ Model parentModel = new Model();
+ parentModel.addModule( "../module-dir" );
+
+ MavenProject parent = new MavenProject( parentModel );
+ parent.setFile( new File( "parent-dir/pom.xml" ) );
+
+ String pathAdjustment = parent.getModulePathAdjustment( module );
+
+ assertEquals( "..", pathAdjustment );
+ }
}
diff --git a/maven-project/src/test/java/org/apache/maven/project/inheritance/DefaultModelInheritanceAssemblerTest.java b/maven-project/src/test/java/org/apache/maven/project/inheritance/DefaultModelInheritanceAssemblerTest.java
index fcde7f0b56..a118f90b17 100644
--- a/maven-project/src/test/java/org/apache/maven/project/inheritance/DefaultModelInheritanceAssemblerTest.java
+++ b/maven-project/src/test/java/org/apache/maven/project/inheritance/DefaultModelInheritanceAssemblerTest.java
@@ -48,6 +48,20 @@ public class DefaultModelInheritanceAssemblerTest
{
private ModelInheritanceAssembler assembler = new DefaultModelInheritanceAssembler();
+ public void testShouldAppendChildPathAdjustmentWithNoChildPart()
+ {
+ String parentPath = "http://maven.apache.org/shared/maven-shared-parent";
+ String childPath = null;
+ String pathAdjustment = "../file-management";
+
+ String result =
+ ( (DefaultModelInheritanceAssembler) assembler ).appendPath( parentPath, childPath, pathAdjustment, true );
+
+ System.out.println( "Resulting path is: \'" + result + "\'" );
+
+ assertEquals( "Append with path adjustment failed.", "http://maven.apache.org/shared/file-management", result );
+ }
+
public void testShouldAppendPathWithChildPathAdjustment()
{
String parentPath = "http://maven.apache.org/shared/maven-shared-parent";