[MNG-2006] Fixing url rewriting for child POMs in sibling directories of parent POM (or anything other than subdir). First guess is based on parent POM file, but if parent POM is built from repository, will use the module artifactId as a basis instead.

git-svn-id: https://svn.apache.org/repos/asf/maven/components/trunk@379572 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
John Dennis Casey 2006-02-21 20:10:52 +00:00
parent bd540e30b7
commit 6fb187fa98
11 changed files with 180 additions and 23 deletions

View File

@ -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

View File

@ -1,3 +1,4 @@
it0095
it0094
it0092
# it0091 currrently fails. Not sure if there is an associated JIRA.

View File

@ -0,0 +1 @@
integration-test

View File

@ -0,0 +1,19 @@
<project>
<modelVersion>4.0.0</modelVersion>
<groupId>org.apache.maven.it.mng2006</groupId>
<artifactId>parent</artifactId>
<version>1</version>
<packaging>pom</packaging>
<distributionManagement>
<site>
<id>website</id>
<url>scp://host/path/parent</url>
</site>
</distributionManagement>
<modules>
<module>../sub1</module>
</modules>
</project>

View File

@ -0,0 +1,16 @@
<project>
<modelVersion>4.0.0</modelVersion>
<groupId>org.apache.maven.it.mng2006</groupId>
<artifactId>bootstrapper</artifactId>
<version>1</version>
<packaging>pom</packaging>
<modules>
<module>parent</module>
</modules>
<build>
<defaultGoal>integration-test</defaultGoal>
</build>
</project>

View File

@ -0,0 +1,44 @@
<project>
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.apache.maven.it.mng2006</groupId>
<artifactId>parent</artifactId>
<version>1</version>
<relativePath>../parent</relativePath>
</parent>
<artifactId>sub1</artifactId>
<build>
<defaultGoal>integration-test</defaultGoal>
<plugins>
<plugin>
<artifactId>maven-help-plugin</artifactId>
<configuration>
<output>${project.build.directory}/effective-pom.xml</output>
</configuration>
<executions>
<execution>
<id>effective-pom</id>
<phase>generate-resources</phase>
<goals>
<goal>effective-pom</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<artifactId>maven-verifier-plugin</artifactId>
<executions>
<execution>
<id>verify</id>
<goals>
<goal>verify</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>

View File

@ -0,0 +1,8 @@
<verifications>
<files>
<file>
<location>target/effective-pom.xml</location>
<contains>scp://host/path/sub1</contains>
</file>
</files>
</verifications>

View File

@ -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 )
{
File myDir = myFile.getCanonicalFile().getParentFile();
if ( modules != null )
{
for ( Iterator it = modules.iterator(); it.hasNext(); )
{
String modulePath = (String) it.next();
String moduleName = modulePath;
File moduleFile = new File( myDir, modulePath ).getCanonicalFile();
moduleFiles.put( moduleFile, modulePath );
if ( moduleName.endsWith( "/" ) || moduleName.endsWith( "\\" ) )
{
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 );
}
// ----------------------------------------------------------------------

View File

@ -506,8 +506,11 @@ public class DefaultModelInheritanceAssembler
pathFragments.add( pathAdjustment );
}
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 );
}

View File

@ -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 );
}
}

View File

@ -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";