mirror of https://github.com/apache/maven.git
[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:
parent
bd540e30b7
commit
6fb187fa98
|
@ -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
|
||||
|
|
|
@ -1,3 +1,4 @@
|
|||
it0095
|
||||
it0094
|
||||
it0092
|
||||
# it0091 currrently fails. Not sure if there is an associated JIRA.
|
||||
|
|
|
@ -0,0 +1 @@
|
|||
integration-test
|
|
@ -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>
|
|
@ -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>
|
|
@ -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>
|
|
@ -0,0 +1,8 @@
|
|||
<verifications>
|
||||
<files>
|
||||
<file>
|
||||
<location>target/effective-pom.xml</location>
|
||||
<contains>scp://host/path/sub1</contains>
|
||||
</file>
|
||||
</files>
|
||||
</verifications>
|
|
@ -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 );
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------
|
||||
|
|
|
@ -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 );
|
||||
}
|
||||
|
|
|
@ -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 );
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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";
|
||||
|
|
Loading…
Reference in New Issue