From 87884c7bc1400ea4af3c2157953fe9a120ca1543 Mon Sep 17 00:00:00 2001 From: Olivier Lamy Date: Sun, 11 Dec 2011 08:47:50 +0000 Subject: [PATCH] [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 --- .../apache/maven/project/MavenProject.java | 30 +++++++++++++++---- .../maven/project/MavenProjectTest.java | 22 ++++++++++++-- 2 files changed, 45 insertions(+), 7 deletions(-) diff --git a/maven-core/src/main/java/org/apache/maven/project/MavenProject.java b/maven-core/src/main/java/org/apache/maven/project/MavenProject.java index 088289dc95..1e235f2477 100644 --- a/maven-core/src/main/java/org/apache/maven/project/MavenProject.java +++ b/maven-core/src/main/java/org/apache/maven/project/MavenProject.java @@ -504,7 +504,11 @@ public class MavenProject { List list = new ArrayList( getArtifacts().size() + 1 ); - list.add( getBuild().getOutputDirectory() ); + String d = getBuild().getOutputDirectory(); + if ( d != null ) + { + list.add( d ); + } for ( Artifact a : getArtifacts() ) { @@ -580,9 +584,17 @@ public class MavenProject { List list = new ArrayList( 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() ) { @@ -644,7 +656,11 @@ public class MavenProject { List list = new ArrayList( getArtifacts().size() + 1 ); - list.add( getBuild().getOutputDirectory() ); + String d = getBuild().getOutputDirectory(); + if ( d != null ) + { + list.add( d ); + } for ( Artifact a : getArtifacts() ) { @@ -717,7 +733,11 @@ public class MavenProject { List list = new ArrayList( getArtifacts().size() ); - list.add( getBuild().getOutputDirectory() ); + String d = getBuild().getOutputDirectory(); + if ( d != null ) + { + list.add( d ); + } for ( Artifact a : getArtifacts() ) { diff --git a/maven-core/src/test/java/org/apache/maven/project/MavenProjectTest.java b/maven-core/src/test/java/org/apache/maven/project/MavenProjectTest.java index 83f664db39..f70153b501 100644 --- a/maven-core/src/test/java/org/apache/maven/project/MavenProjectTest.java +++ b/maven-core/src/test/java/org/apache/maven/project/MavenProjectTest.java @@ -146,7 +146,8 @@ public class MavenProjectTest assertEquals( "..", pathAdjustment ); } - public void testCloneWithDistributionManagement() throws Exception + public void testCloneWithDistributionManagement() + throws Exception { File f = getFileForClasspathResource( "distributionManagement-pom.xml" ); @@ -156,7 +157,8 @@ public class MavenProjectTest assertNotNull( "clonedProject - distributionManagement", clonedProject.getDistributionManagementArtifactRepository() ); } - public void testCloneWithActiveProfile() throws Exception + public void testCloneWithActiveProfile() + throws Exception { 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, 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 elements ) + { + assertFalse( elements.contains( null ) ); + } + }