Author: krosenvold
Date: Wed Feb 9 20:13:16 2011
New Revision: 1069066
URL: http://svn.apache.org/viewvc?rev=1069066&view=rev
Log:
[SUREFIRE-694] NPE On empty additionalClassPath element
Patch by Stefan Birkner, applied with merge
Modified:
maven/surefire/trunk/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/AbstractSurefireMojo.java
maven/surefire/trunk/surefire-booter/src/main/java/org/apache/maven/surefire/booter/Classpath.java
maven/surefire/trunk/surefire-booter/src/test/java/org/apache/maven/surefire/booter/ClasspathTest.java
maven/surefire/trunk/surefire-integration-tests/src/test/resources/additional-classpath/pom.xml
Modified:
maven/surefire/trunk/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/AbstractSurefireMojo.java
URL:
http://svn.apache.org/viewvc/maven/surefire/trunk/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/AbstractSurefireMojo.java?rev=1069066&r1=1069065&r2=1069066&view=diff
==============================================================================
---
maven/surefire/trunk/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/AbstractSurefireMojo.java
(original)
+++
maven/surefire/trunk/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/AbstractSurefireMojo.java
Wed Feb 9 20:13:16 2011
@@ -375,21 +375,29 @@ public abstract class AbstractSurefireMo
throw new MojoExecutionException( "Unable to generate test
classpath: " + e, e );
}
- getLog().debug( "Test Classpath :" );
+ addClasspathElementsToClasspathConfiguration(classpathElements,
classpathConfiguration);
+ return new StartupConfiguration( providerName, classpathConfiguration,
classLoaderConfiguration,
+ forkConfiguration.isForking(), false,
isRedirectTestOutputToFile() );
+ }
+ private void addClasspathElementsToClasspathConfiguration(List
classpathElements, ClasspathConfiguration classpathConfiguration)
+ {
+ getLog().debug( "Test classpath:" );
for ( Iterator i = classpathElements.iterator(); i.hasNext(); )
{
String classpathElement = (String) i.next();
-
- getLog().debug( " " + classpathElement );
-
- classpathConfiguration.addClasspathUrl( classpathElement );
+ if ( classpathElement == null )
+ {
+ getLog().warn("The test classpath contains a null element.");
+ }
+ else
+ {
+ getLog().debug( " " + classpathElement );
+ classpathConfiguration.addClasspathUrl( classpathElement );
+ }
}
- return new StartupConfiguration( providerName, classpathConfiguration,
classLoaderConfiguration,
- forkConfiguration.isForking(), false,
isRedirectTestOutputToFile() );
}
-
private boolean isSpecificTestSpecified()
{
return getTest() != null;
Modified:
maven/surefire/trunk/surefire-booter/src/main/java/org/apache/maven/surefire/booter/Classpath.java
URL:
http://svn.apache.org/viewvc/maven/surefire/trunk/surefire-booter/src/main/java/org/apache/maven/surefire/booter/Classpath.java?rev=1069066&r1=1069065&r2=1069066&view=diff
==============================================================================
---
maven/surefire/trunk/surefire-booter/src/main/java/org/apache/maven/surefire/booter/Classpath.java
(original)
+++
maven/surefire/trunk/surefire-booter/src/main/java/org/apache/maven/surefire/booter/Classpath.java
Wed Feb 9 20:13:16 2011
@@ -19,6 +19,8 @@ package org.apache.maven.surefire.booter
* under the License.
*/
+import org.apache.maven.surefire.util.UrlUtils;
+
import java.io.File;
import java.net.MalformedURLException;
import java.util.ArrayList;
@@ -27,8 +29,6 @@ import java.util.Iterator;
import java.util.List;
import java.util.Properties;
-import org.apache.maven.surefire.util.UrlUtils;
-
/**
* An ordered set of classpath elements
*
Modified:
maven/surefire/trunk/surefire-booter/src/test/java/org/apache/maven/surefire/booter/ClasspathTest.java
URL:
http://svn.apache.org/viewvc/maven/surefire/trunk/surefire-booter/src/test/java/org/apache/maven/surefire/booter/ClasspathTest.java?rev=1069066&r1=1069065&r2=1069066&view=diff
==============================================================================
---
maven/surefire/trunk/surefire-booter/src/test/java/org/apache/maven/surefire/booter/ClasspathTest.java
(original)
+++
maven/surefire/trunk/surefire-booter/src/test/java/org/apache/maven/surefire/booter/ClasspathTest.java
Wed Feb 9 20:13:16 2011
@@ -82,33 +82,7 @@ public class ClasspathTest
assertEquals( DUMMY_URL_2, properties.get( "test1" ) );
}
- public void
testShouldThrowIllegalArgumentExceptionWhenNullIsAddedAsClassPathElementUrl()
- throws Exception
- {
- Classpath classpath = new Classpath();
- try
- {
- classpath.addClassPathElementUrl( null );
- fail( "IllegalArgumentException not thrown." );
- }
- catch ( IllegalArgumentException expected )
- {
- }
- }
- public void testShouldNotAddNullAsClassPathElementUrl()
- throws Exception
- {
- Classpath classpath = new Classpath();
- try
- {
- classpath.addClassPathElementUrl( null );
- }
- catch ( IllegalArgumentException ignored )
- {
- }
- assertEmptyClasspath( classpath );
- }
public void testShouldJoinTwoNullClasspaths()
{
@@ -183,4 +157,32 @@ public class ClasspathTest
classpath.addClassPathElementUrl( DUMMY_URL_2 );
return classpath;
}
+
+ public void
testShouldThrowIllegalArgumentExceptionWhenNullIsAddedAsClassPathElementUrl()
+ throws Exception
+ {
+ Classpath classpath = new Classpath();
+ try
+ {
+ classpath.addClassPathElementUrl( null );
+ fail("IllegalArgumentException not thrown.");
+ }
+ catch (IllegalArgumentException expected)
+ {
+ }
+ }
+
+ public void testShouldNotAddNullAsClassPathElementUrl()
+ throws Exception
+ {
+ Classpath classpath = new Classpath();
+ try
+ {
+ classpath.addClassPathElementUrl( null );
+ }
+ catch (IllegalArgumentException ignored)
+ {
+ }
+ assertEmptyClasspath( classpath );
+ }
}
Modified:
maven/surefire/trunk/surefire-integration-tests/src/test/resources/additional-classpath/pom.xml
URL:
http://svn.apache.org/viewvc/maven/surefire/trunk/surefire-integration-tests/src/test/resources/additional-classpath/pom.xml?rev=1069066&r1=1069065&r2=1069066&view=diff
==============================================================================
---
maven/surefire/trunk/surefire-integration-tests/src/test/resources/additional-classpath/pom.xml
(original)
+++
maven/surefire/trunk/surefire-integration-tests/src/test/resources/additional-classpath/pom.xml
Wed Feb 9 20:13:16 2011
@@ -36,6 +36,8 @@
<configuration>
<additionalClasspathElements>
<additionalClasspathElement>${basedir}/extraResource</additionalClasspathElement>
+
<additionalClasspathElement>${abc}</additionalClasspathElement><!--
SUREFIRE-694 -->
+ <additionalClasspathElement></additionalClasspathElement><!--
SUREFIRE-694 -->
</additionalClasspathElements>
</configuration>
</plugin>