[MNG-5209] MavenProject.getTestClasspathElements can return null elements

Submitted by Jesse Glick.

git-svn-id: https://svn.apache.org/repos/asf/maven/maven-3/trunk@1212980 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Olivier Lamy 2011-12-11 08:47:50 +00:00
parent 4b637c5a2f
commit 87884c7bc1
2 changed files with 45 additions and 7 deletions

View File

@ -504,7 +504,11 @@ public class MavenProject
{ {
List<String> list = new ArrayList<String>( getArtifacts().size() + 1 ); List<String> list = new ArrayList<String>( getArtifacts().size() + 1 );
list.add( getBuild().getOutputDirectory() ); String d = getBuild().getOutputDirectory();
if ( d != null )
{
list.add( d );
}
for ( Artifact a : getArtifacts() ) for ( Artifact a : getArtifacts() )
{ {
@ -580,9 +584,17 @@ public class MavenProject
{ {
List<String> list = new ArrayList<String>( getArtifacts().size() + 2 ); List<String> list = new ArrayList<String>( getArtifacts().size() + 2 );
list.add( getBuild().getTestOutputDirectory() ); String d = getBuild().getTestOutputDirectory();
if ( d != null )
{
list.add( d );
}
list.add( getBuild().getOutputDirectory() ); d = getBuild().getOutputDirectory();
if ( d != null )
{
list.add( d );
}
for ( Artifact a : getArtifacts() ) for ( Artifact a : getArtifacts() )
{ {
@ -644,7 +656,11 @@ public class MavenProject
{ {
List<String> list = new ArrayList<String>( getArtifacts().size() + 1 ); List<String> list = new ArrayList<String>( getArtifacts().size() + 1 );
list.add( getBuild().getOutputDirectory() ); String d = getBuild().getOutputDirectory();
if ( d != null )
{
list.add( d );
}
for ( Artifact a : getArtifacts() ) for ( Artifact a : getArtifacts() )
{ {
@ -717,7 +733,11 @@ public class MavenProject
{ {
List<String> list = new ArrayList<String>( getArtifacts().size() ); List<String> list = new ArrayList<String>( getArtifacts().size() );
list.add( getBuild().getOutputDirectory() ); String d = getBuild().getOutputDirectory();
if ( d != null )
{
list.add( d );
}
for ( Artifact a : getArtifacts() ) for ( Artifact a : getArtifacts() )
{ {

View File

@ -146,7 +146,8 @@ public class MavenProjectTest
assertEquals( "..", pathAdjustment ); assertEquals( "..", pathAdjustment );
} }
public void testCloneWithDistributionManagement() throws Exception public void testCloneWithDistributionManagement()
throws Exception
{ {
File f = getFileForClasspathResource( "distributionManagement-pom.xml" ); File f = getFileForClasspathResource( "distributionManagement-pom.xml" );
@ -156,7 +157,8 @@ public class MavenProjectTest
assertNotNull( "clonedProject - distributionManagement", clonedProject.getDistributionManagementArtifactRepository() ); assertNotNull( "clonedProject - distributionManagement", clonedProject.getDistributionManagementArtifactRepository() );
} }
public void testCloneWithActiveProfile() throws Exception public void testCloneWithActiveProfile()
throws Exception
{ {
File f = getFileForClasspathResource( "withActiveByDefaultProfile-pom.xml" ); File f = getFileForClasspathResource( "withActiveByDefaultProfile-pom.xml" );
@ -174,4 +176,20 @@ public class MavenProjectTest
assertNotSame( "The list of active profiles should have been cloned too but is same", activeProfilesOrig, assertNotSame( "The list of active profiles should have been cloned too but is same", activeProfilesOrig,
activeProfilesClone ); activeProfilesClone );
} }
public void testUndefinedOutputDirectory()
throws Exception
{
MavenProject p = new MavenProject();
assertNoNulls( p.getCompileClasspathElements() );
assertNoNulls( p.getSystemClasspathElements() );
assertNoNulls( p.getRuntimeClasspathElements() );
assertNoNulls( p.getTestClasspathElements() );
}
private void assertNoNulls( List<String> elements )
{
assertFalse( elements.contains( null ) );
}
} }