Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMartin Schreiber2015-06-19 16:05:46 -0400
committerGerrit Code Review @ Eclipse.org2015-06-30 06:19:54 -0400
commit052c143f73fe284f0bf2eede187160fa8ca26290 (patch)
treeab85ed9547f51217177d14e62ba30f93362b5670
parent5edbe32812d255f27d6fd8684a80d61575e6afdc (diff)
downloadorg.eclipse.tycho-052c143f73fe284f0bf2eede187160fa8ca26290.tar.gz
org.eclipse.tycho-052c143f73fe284f0bf2eede187160fa8ca26290.tar.xz
org.eclipse.tycho-052c143f73fe284f0bf2eede187160fa8ca26290.zip
469230 Unresolved parameter interpolation must not fail test
execution If parameters are used within <includes> or <excludes> that could not be interpolated, the interpolator adds null to the excludes/includes list which will end up in a NPE within the DirectoryScanner. This fix removes the nulls from the lists. Change-Id: I6dcf03571d1cba73527479be180a30a1dbdcb926 Signed-off-by: Martin Schreiber <martin.schreiber@bachmann.info>
-rw-r--r--tycho-surefire/tycho-surefire-plugin/pom.xml5
-rw-r--r--tycho-surefire/tycho-surefire-plugin/src/main/java/org/eclipse/tycho/surefire/TestMojo.java12
-rw-r--r--tycho-surefire/tycho-surefire-plugin/src/test/java/org/eclipse/tycho/surefire/TestMojoTest.java32
-rw-r--r--tycho-surefire/tycho-surefire-plugin/src/test/resources/excludesIncludesTestDirectory/ATest.txt11
-rw-r--r--tycho-surefire/tycho-surefire-plugin/src/test/resources/excludesIncludesTestDirectory/AnotherTestCase.txt11
5 files changed, 69 insertions, 2 deletions
diff --git a/tycho-surefire/tycho-surefire-plugin/pom.xml b/tycho-surefire/tycho-surefire-plugin/pom.xml
index 27788ef19..65e830c9c 100644
--- a/tycho-surefire/tycho-surefire-plugin/pom.xml
+++ b/tycho-surefire/tycho-surefire-plugin/pom.xml
@@ -138,5 +138,10 @@
<groupId>org.mockito</groupId>
<artifactId>mockito-core</artifactId>
</dependency>
+ <dependency>
+ <groupId>org.eclipse.tycho</groupId>
+ <artifactId>tycho-testing-harness</artifactId>
+ <version>${project.version}</version>
+ </dependency>
</dependencies>
</project>
diff --git a/tycho-surefire/tycho-surefire-plugin/src/main/java/org/eclipse/tycho/surefire/TestMojo.java b/tycho-surefire/tycho-surefire-plugin/src/main/java/org/eclipse/tycho/surefire/TestMojo.java
index 9f1e3324b..2e0d8e36d 100644
--- a/tycho-surefire/tycho-surefire-plugin/src/main/java/org/eclipse/tycho/surefire/TestMojo.java
+++ b/tycho-surefire/tycho-surefire-plugin/src/main/java/org/eclipse/tycho/surefire/TestMojo.java
@@ -866,6 +866,7 @@ public class TestMojo extends AbstractMojo {
List<String> defaultIncludes = Arrays.asList("**/Test*.class", "**/*Test.class", "**/*TestCase.class");
List<String> defaultExcludes = Arrays.asList("**/*$*");
List<String> includeList;
+ List<String> excludeList;
if (test != null) {
String test = this.test;
test = test.replace('.', '/');
@@ -876,11 +877,18 @@ public class TestMojo extends AbstractMojo {
includeList = Collections.singletonList(testClass.replace('.', '/') + ".class");
} else if (includes != null) {
includeList = includes;
+ includeList.removeAll(Collections.singleton(null));
} else {
includeList = defaultIncludes;
}
- DirectoryScanner scanner = new DirectoryScanner(testClassesDirectory, includeList, excludes != null ? excludes
- : defaultExcludes, Collections.<String> emptyList());
+ if (excludes != null) {
+ excludeList = excludes;
+ excludeList.removeAll(Collections.singleton(null));
+ } else {
+ excludeList = defaultExcludes;
+ }
+ DirectoryScanner scanner = new DirectoryScanner(testClassesDirectory, includeList, excludeList,
+ Collections.<String> emptyList());
DefaultScanResult scanResult = scanner.scan();
return scanResult;
}
diff --git a/tycho-surefire/tycho-surefire-plugin/src/test/java/org/eclipse/tycho/surefire/TestMojoTest.java b/tycho-surefire/tycho-surefire-plugin/src/test/java/org/eclipse/tycho/surefire/TestMojoTest.java
index cf1eaf413..f5a032779 100644
--- a/tycho-surefire/tycho-surefire-plugin/src/test/java/org/eclipse/tycho/surefire/TestMojoTest.java
+++ b/tycho-surefire/tycho-surefire-plugin/src/test/java/org/eclipse/tycho/surefire/TestMojoTest.java
@@ -14,14 +14,18 @@ import static org.hamcrest.CoreMatchers.containsString;
import static org.junit.Assert.assertThat;
import java.lang.reflect.Field;
+import java.util.ArrayList;
+import java.util.List;
import junit.framework.TestCase;
import org.apache.maven.plugin.MojoExecutionException;
+import org.apache.maven.surefire.util.ScanResult;
import org.codehaus.plexus.util.ReflectionUtils;
import org.eclipse.sisu.equinox.launching.DefaultEquinoxInstallationDescription;
import org.eclipse.sisu.equinox.launching.internal.DefaultEquinoxInstallation;
import org.eclipse.sisu.equinox.launching.internal.EquinoxLaunchConfiguration;
+import org.eclipse.tycho.testing.TestUtil;
public class TestMojoTest extends TestCase {
@@ -98,6 +102,34 @@ public class TestMojoTest extends TestCase {
assertTrue(testMojo.shouldSkip());
}
+ public void testExcludes() throws Exception {
+ List<String> includes = new ArrayList<String>();
+ includes.add("*.*");
+ List<String> excludes = new ArrayList<String>();
+ // adding a null to simulate an unresolved parameter interpolation
+ excludes.add(null);
+ excludes.add("*Another*");
+ ScanResult result = executeScanForTests(includes, excludes);
+ assertEquals(1, result.size());
+ }
+
+ public void testIncludes() throws Exception {
+ List<String> includes = new ArrayList<String>();
+ includes.add("*Another*");
+ includes.add(null);
+ ScanResult result = executeScanForTests(includes, null);
+ assertEquals(1, result.size());
+ }
+
+ public ScanResult executeScanForTests(List<String> includes, List<String> excludes) throws Exception {
+ TestMojo testMojo = new TestMojo();
+ setParameter(testMojo, "includes", includes);
+ setParameter(testMojo, "excludes", excludes);
+ setParameter(testMojo, "testClassesDirectory",
+ TestUtil.getTestResourceLocation("excludesIncludesTestDirectory"));
+ return testMojo.scanForTests();
+ }
+
private void setParameter(Object object, String variable, Object value) throws IllegalArgumentException,
IllegalAccessException {
Field field = ReflectionUtils.getFieldByNameIncludingSuperclasses(variable, object.getClass());
diff --git a/tycho-surefire/tycho-surefire-plugin/src/test/resources/excludesIncludesTestDirectory/ATest.txt b/tycho-surefire/tycho-surefire-plugin/src/test/resources/excludesIncludesTestDirectory/ATest.txt
new file mode 100644
index 000000000..a9f284bf7
--- /dev/null
+++ b/tycho-surefire/tycho-surefire-plugin/src/test/resources/excludesIncludesTestDirectory/ATest.txt
@@ -0,0 +1,11 @@
+/*******************************************************************************
+ * Copyright (c) 2015 Bachmann GmbH and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Bachmann Gmbh
+ ******************************************************************************/
+ Dummy File for tests \ No newline at end of file
diff --git a/tycho-surefire/tycho-surefire-plugin/src/test/resources/excludesIncludesTestDirectory/AnotherTestCase.txt b/tycho-surefire/tycho-surefire-plugin/src/test/resources/excludesIncludesTestDirectory/AnotherTestCase.txt
new file mode 100644
index 000000000..a9f284bf7
--- /dev/null
+++ b/tycho-surefire/tycho-surefire-plugin/src/test/resources/excludesIncludesTestDirectory/AnotherTestCase.txt
@@ -0,0 +1,11 @@
+/*******************************************************************************
+ * Copyright (c) 2015 Bachmann GmbH and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Bachmann Gmbh
+ ******************************************************************************/
+ Dummy File for tests \ No newline at end of file

Back to the top