Skip to content

Commit

Permalink
[MNG-6405] Fix basedir in MavenProject.deepCopy (#225)
Browse files Browse the repository at this point in the history
* [MNG-6405] Fix basedir in MavenProject.deepCopy.

* Reproduced bug in test.
Failure without patch:
junit.framework.AssertionFailedError: Base directory is preserved across clone expected:<…/maven-core/target/test-classes> but was:<…/maven-core/target/test-classes/target>
	at org.apache.maven.project.MavenProjectTest.testCloneWithBaseDir(MavenProjectTest.java:188)

* Code style. Not enforced in tests during build?
  • Loading branch information
jglick authored and olamy committed Apr 16, 2019
1 parent 715d90b commit 0940c7c
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
Expand Up @@ -1207,7 +1207,8 @@ private void deepCopy( MavenProject project )
// disown the parent

// copy fields
setFile( project.getFile() );
file = project.file;
basedir = project.basedir;

// don't need a deep copy, they don't get modified or added/removed to/from - but make them unmodifiable to be
// sure!
Expand Down
Expand Up @@ -177,6 +177,17 @@ public void testCloneWithActiveProfile()
activeProfilesClone );
}

public void testCloneWithBaseDir()
throws Exception
{
File f = getFileForClasspathResource( "canonical-pom.xml" );
MavenProject projectToClone = getProject( f );
projectToClone.setPomFile( new File( new File( f.getParentFile(), "target" ), "flattened.xml" ) );
MavenProject clonedProject = projectToClone.clone();
assertEquals( "POM file is preserved across clone", projectToClone.getFile(), clonedProject.getFile() );
assertEquals( "Base directory is preserved across clone", projectToClone.getBasedir(), clonedProject.getBasedir() );
}

public void testUndefinedOutputDirectory()
throws Exception
{
Expand Down

0 comments on commit 0940c7c

Please sign in to comment.