[MNG-2302] Added code to nullify parent's descriptor location in cases where the parent MavenProject instance was loaded from the repository. In these cases, the descriptor location value is incorrect anyway, and it was causing an incorrect null return value for MavenProject.getModulePathAlignment(..), which in turn produces an incorrect URL path calculation for multi-tiered inheritance where the top tiers are resolved from the repository.

git-svn-id: https://svn.apache.org/repos/asf/maven/components/trunk@426112 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
John Dennis Casey 2006-07-27 16:02:26 +00:00
parent ef76da9daa
commit 75c7380801
4 changed files with 119 additions and 35 deletions

View File

@ -955,6 +955,8 @@ public class DefaultMavenProjectBuilder
/**
* @noinspection CollectionDeclaredAsConcreteClass
* @todo We need to find an effective way to unit test parts of this method!
* @todo Refactor this into smaller methods with discrete purposes.
*/
private MavenProject assembleLineage( Model model,
LinkedList lineage,
@ -1146,6 +1148,10 @@ public class DefaultMavenProjectBuilder
// only resolve the parent model from the repository system if we didn't find it on disk...
if ( model == null )
{
// MNG-2302: parent's File was being populated incorrectly when parent is loaded from repo.
// keep this in line with other POMs loaded from the repository...the file should be null.
parentDescriptor = null;
//!! (**)
// ----------------------------------------------------------------------
// Do we have the necessary information to actually find the parent
@ -1192,9 +1198,11 @@ public class DefaultMavenProjectBuilder
{
parentProjectDir = parentDescriptor.getParentFile();
}
MavenProject parent = assembleLineage( model, lineage, localRepository, parentProjectDir,
parentSearchRepositories, aggregatedRemoteWagonRepositories,
externalProfileManager, strict );
parent.setFile( parentDescriptor );
project.setParent( parent );

View File

@ -16,6 +16,18 @@ package org.apache.maven.project;
* limitations under the License.
*/
import java.io.File;
import java.io.IOException;
import java.io.Writer;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Properties;
import java.util.Set;
import org.apache.maven.artifact.Artifact;
import org.apache.maven.artifact.ArtifactUtils;
import org.apache.maven.artifact.DependencyResolutionRequiredException;
@ -34,7 +46,6 @@ import org.apache.maven.model.License;
import org.apache.maven.model.MailingList;
import org.apache.maven.model.Model;
import org.apache.maven.model.Organization;
import org.apache.maven.model.Parent;
import org.apache.maven.model.Plugin;
import org.apache.maven.model.PluginExecution;
import org.apache.maven.model.PluginManagement;
@ -51,18 +62,6 @@ import org.apache.maven.project.artifact.MavenMetadataSource;
import org.apache.maven.project.overlay.BuildOverlay;
import org.codehaus.plexus.util.xml.Xpp3Dom;
import java.io.File;
import java.io.IOException;
import java.io.Writer;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Properties;
import java.util.Set;
/**
* The concern of the project is provide runtime values based on the model. <p/>
* The values in the model remain untouched but during the process of building a
@ -259,6 +258,11 @@ public class MavenProject
{
// FIXME: This is hacky. What if module directory doesn't match artifactid, and parent
// is coming from the repository??
// FIXME: If there is a hierarchy of three projects, with the url specified at the top,
// and the top two projects are referenced from copies that are in the repository, the
// middle-level POM doesn't have a File associated with it (or the file's directory is
// of an unexpected name), and module path adjustments fail.
String module = moduleProject.getArtifactId();
File moduleFile = moduleProject.getFile();

View File

@ -25,62 +25,88 @@ import org.apache.maven.model.Parent;
public class MavenProjectTest
extends AbstractMavenProjectTestCase
{
public void testShouldInterpretChildPathAdjustmentBasedOnModulePaths()
throws IOException
{
Model parentModel = new Model();
parentModel.addModule( "../child" );
MavenProject parentProject = new MavenProject( parentModel );
Model childModel = new Model();
childModel.setArtifactId( "artifact" );
MavenProject childProject = new MavenProject( childModel );
File childFile = new File( System.getProperty( "java.io.tmpdir" ), "maven-project-tests" + System.currentTimeMillis() + "/child/pom.xml" );
childProject.setFile( childFile );
String adjustment = parentProject.getModulePathAdjustment( childProject );
assertNotNull( adjustment );
assertEquals( "..", adjustment );
}
public void testIdentityProtoInheritance()
{
Parent parent = new Parent();
parent.setGroupId( "test-group" );
parent.setVersion( "1000" );
parent.setArtifactId( "test-artifact" );
Model model = new Model();
model.setParent( parent );
model.setArtifactId( "real-artifact" );
MavenProject project = new MavenProject( model );
assertEquals( "groupId proto-inheritance failed.", "test-group", project.getGroupId() );
assertEquals( "artifactId is masked.", "real-artifact", project.getArtifactId() );
assertEquals( "version proto-inheritance failed.", "1000", project.getVersion() );
// draw the NPE.
project.getId();
}
public void testEmptyConstructor()
{
MavenProject project = new MavenProject();
assertEquals( MavenProject.EMPTY_PROJECT_GROUP_ID + ":" + MavenProject.EMPTY_PROJECT_ARTIFACT_ID + ":jar:"
+ MavenProject.EMPTY_PROJECT_VERSION, project.getId() );
+ MavenProject.EMPTY_PROJECT_VERSION, project.getId() );
}
public void testCopyConstructor() throws Exception
public void testCopyConstructor()
throws Exception
{
File f = getFileForClasspathResource( "canonical-pom.xml" );
MavenProject projectToClone = getProject(f);
MavenProject projectToClone = getProject( f );
MavenProject clonedProject = new MavenProject(projectToClone);
assertEquals("maven-core", clonedProject.getArtifactId());
MavenProject clonedProject = new MavenProject( projectToClone );
assertEquals( "maven-core", clonedProject.getArtifactId() );
}
public void testGetModulePathAdjustment() throws IOException
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

@ -50,6 +50,52 @@ public class DefaultModelInheritanceAssemblerTest
{
private ModelInheritanceAssembler assembler = new DefaultModelInheritanceAssembler();
public void testShouldAdjustChildUrlBasedOnParentAndModulePathInSiblingDir()
{
Model parent = makeBaseModel( "parent" );
parent.setUrl( "http://www.google.com/parent" );
Model child = makeBaseModel( "child" );
// TODO: this is probably what we should be appending...
// child.setUrl( "/child.dir" );
parent.addModule( "../child" );
assembler.assembleModelInheritance( child, parent, ".." );
String resultingUrl = child.getUrl();
System.out.println( resultingUrl );
assertEquals( "http://www.google.com/child", resultingUrl );
}
public void testShouldAdjustPathsThreeLevelsDeepAncestryInRepoAndNonStandardModulePaths()
{
Model top = makeBaseModel( "top" );
top.setUrl( "http://www.google.com/top" );
Model middle = makeBaseModel( "middle" );
top.addModule( "../middle" );
Model bottom = makeBaseModel( "bottom" );
middle.addModule( "../bottom" );
assembler.assembleModelInheritance( middle, top, ".." );
assembler.assembleModelInheritance( bottom, middle, ".." );
String resultingUrl = bottom.getUrl();
System.out.println( resultingUrl );
assertEquals( "http://www.google.com/bottom", resultingUrl );
}
public void testShouldMergeSuccessiveDependencyManagementSectionsOverThreeLevels()
{
Model top = makeBaseModel( "top" );