1b6f195
From f72d45fb261a3910885a3073c33cc0f98f14392f Mon Sep 17 00:00:00 2001
b81da61
From: Jan Sievers <jan.sievers@sap.com>
b81da61
Date: Tue, 4 Sep 2012 16:02:52 +0200
94c249b
Subject: [PATCH] Resolve all necessary dependencies for Tycho Surefire.
416b074
416b074
When running an Eclipse bundle's tests, Tycho Surefire resolves its
416b074
runtime dependencies using a class loader, which is in fact just looking
416b074
through Bundle-ClassPath. As a result, it must copy over and include
416b074
system jars in its Bundle-ClassPath. We use Fedora system jars to
416b074
satisfy these dependencies but even these jars differ slightly in terms
416b074
of provided classes. This patch addresses this issue.
416b074
416b074
Basically, the jars added to the Bundle-ClassPath in this patch, provide
416b074
the additional classes that are in the original jars used upstream.
50be185
b90c413
Change-Id: I9ef0239eed887fa47c380efcdce968934c788c9f
416b074
---
1b6f195
 pom.xml                                            |  2 +-
1b6f195
 .../META-INF/MANIFEST.MF                           |  5 ++--
1b6f195
 .../org.eclipse.tycho.surefire.junit/pom.xml       |  5 ++++
1b6f195
 .../META-INF/MANIFEST.MF                           |  4 +++-
1b6f195
 .../org.eclipse.tycho.surefire.junit4/pom.xml      | 10 ++++++++
1b6f195
 .../META-INF/MANIFEST.MF                           |  8 ++++---
1b6f195
 .../org.eclipse.tycho.surefire.junit47/pom.xml     | 10 ++++++++
1b6f195
 .../META-INF/MANIFEST.MF                           |  7 +++---
1b6f195
 .../org.eclipse.tycho.surefire.osgibooter/pom.xml  |  5 ++++
1b6f195
 .../surefire/osgibooter/OsgiSurefireBooter.java    | 17 +++++++++-----
1b6f195
 tycho-surefire/pom.xml                             |  2 +-
1b6f195
 .../java/org/eclipse/tycho/surefire/TestMojo.java  | 27 +++++++++++++++++++---
1b6f195
 12 files changed, 82 insertions(+), 20 deletions(-)
416b074
1b6f195
diff --git a/pom.xml b/pom.xml
1b6f195
index c43cc8d..6e5fde4 100644
1b6f195
--- a/pom.xml
1b6f195
+++ b/pom.xml
1b6f195
@@ -380,7 +380,7 @@
1b6f195
 				<plugin>
1b6f195
 					<groupId>org.apache.maven.plugins</groupId>
1b6f195
 					<artifactId>maven-surefire-plugin</artifactId>
1b6f195
-					<version>2.17</version>
1b6f195
+					<version>2.19</version>
1b6f195
 				</plugin>
1b6f195
 				<plugin>
1b6f195
 					<groupId>org.apache.maven.plugins</groupId>
416b074
diff --git a/tycho-surefire/org.eclipse.tycho.surefire.junit/META-INF/MANIFEST.MF b/tycho-surefire/org.eclipse.tycho.surefire.junit/META-INF/MANIFEST.MF
1b6f195
index da31140..fb5803f 100644
416b074
--- a/tycho-surefire/org.eclipse.tycho.surefire.junit/META-INF/MANIFEST.MF
416b074
+++ b/tycho-surefire/org.eclipse.tycho.surefire.junit/META-INF/MANIFEST.MF
1b6f195
@@ -6,6 +6,7 @@ Bundle-Version: 0.23.0
416b074
 Fragment-Host: org.eclipse.tycho.surefire.osgibooter;bundle-version="0.14.0"
416b074
 Bundle-RequiredExecutionEnvironment: J2SE-1.5,
416b074
  JavaSE-1.6
416b074
-Require-Bundle: org.junit;bundle-version="[3.8.0,4.0.0)"
b81da61
-Bundle-ClassPath: jars/surefire-junit3-2.17.jar
a9e1e45
+Require-Bundle: org.junit;bundle-version="[3.8.0,5.0.0)"
1b6f195
+Bundle-ClassPath: jars/surefire-junit3-2.19.jar,
1b6f195
+ jars/common-junit3-2.19.jar
416b074
 Bundle-Vendor: %providerName
416b074
diff --git a/tycho-surefire/org.eclipse.tycho.surefire.junit/pom.xml b/tycho-surefire/org.eclipse.tycho.surefire.junit/pom.xml
1b6f195
index f99c319..0224cc6 100644
416b074
--- a/tycho-surefire/org.eclipse.tycho.surefire.junit/pom.xml
416b074
+++ b/tycho-surefire/org.eclipse.tycho.surefire.junit/pom.xml
50be185
@@ -44,6 +44,11 @@
416b074
 									<artifactId>surefire-junit3</artifactId>
416b074
 									<version>${surefire-version}</version>
416b074
 								</artifactItem>
416b074
+								<artifactItem>
416b074
+									<groupId>org.apache.maven.surefire</groupId>
416b074
+									<artifactId>common-junit3</artifactId>
416b074
+									<version>${surefire-version}</version>
416b074
+								</artifactItem>
416b074
 							</artifactItems>
416b074
 						</configuration>
416b074
 					</execution>
416b074
diff --git a/tycho-surefire/org.eclipse.tycho.surefire.junit4/META-INF/MANIFEST.MF b/tycho-surefire/org.eclipse.tycho.surefire.junit4/META-INF/MANIFEST.MF
1b6f195
index 50be5ea..0d8e8d8 100644
416b074
--- a/tycho-surefire/org.eclipse.tycho.surefire.junit4/META-INF/MANIFEST.MF
416b074
+++ b/tycho-surefire/org.eclipse.tycho.surefire.junit4/META-INF/MANIFEST.MF
1b6f195
@@ -6,7 +6,9 @@ Bundle-Version: 0.23.0
416b074
 Fragment-Host: org.eclipse.tycho.surefire.osgibooter;bundle-version="0.14.0"
416b074
 Bundle-RequiredExecutionEnvironment: J2SE-1.5,
416b074
  JavaSE-1.6
b81da61
-Bundle-ClassPath: jars/surefire-junit4-2.17.jar
1b6f195
+Bundle-ClassPath: jars/surefire-junit4-2.19.jar,
1b6f195
+ jars/common-junit3-2.19.jar,
1b6f195
+ jars/common-junit4-2.19.jar
b90c413
 Import-Package: junit.framework;version="3.0.0",
416b074
  org.junit;version="4.0.0",
416b074
  org.junit.runner;version="4.0.0",
416b074
diff --git a/tycho-surefire/org.eclipse.tycho.surefire.junit4/pom.xml b/tycho-surefire/org.eclipse.tycho.surefire.junit4/pom.xml
1b6f195
index 9628b06..2a09e91 100644
416b074
--- a/tycho-surefire/org.eclipse.tycho.surefire.junit4/pom.xml
416b074
+++ b/tycho-surefire/org.eclipse.tycho.surefire.junit4/pom.xml
50be185
@@ -44,6 +44,16 @@
416b074
 									<artifactId>surefire-junit4</artifactId>
416b074
 									<version>${surefire-version}</version>
416b074
 								</artifactItem>
416b074
+								<artifactItem>
416b074
+									<groupId>org.apache.maven.surefire</groupId>
416b074
+									<artifactId>common-junit3</artifactId>
416b074
+									<version>${surefire-version}</version>
b90c413
+									</artifactItem>
416b074
+								<artifactItem>
416b074
+									<groupId>org.apache.maven.surefire</groupId>
416b074
+									<artifactId>common-junit4</artifactId>
416b074
+									<version>${surefire-version}</version>
416b074
+								</artifactItem>
416b074
 							</artifactItems>
416b074
 						</configuration>
416b074
 					</execution>
50be185
diff --git a/tycho-surefire/org.eclipse.tycho.surefire.junit47/META-INF/MANIFEST.MF b/tycho-surefire/org.eclipse.tycho.surefire.junit47/META-INF/MANIFEST.MF
1b6f195
index 595265b..1ac6c5d 100644
50be185
--- a/tycho-surefire/org.eclipse.tycho.surefire.junit47/META-INF/MANIFEST.MF
50be185
+++ b/tycho-surefire/org.eclipse.tycho.surefire.junit47/META-INF/MANIFEST.MF
1b6f195
@@ -6,9 +6,11 @@ Bundle-Version: 0.23.0
1b6f195
 Fragment-Host: org.eclipse.tycho.surefire.osgibooter;bundle-version="0.16.0"
1b6f195
 Bundle-RequiredExecutionEnvironment: J2SE-1.5
50be185
 Bundle-ClassPath: .,
1b6f195
- jars/surefire-junit47-2.17.jar,
1b6f195
- jars/common-junit48-2.17.jar,
b81da61
- jars/surefire-grouper-2.17.jar
1b6f195
+ jars/surefire-junit47-2.19.jar,
1b6f195
+ jars/common-junit48-2.19.jar,
1b6f195
+ jars/surefire-grouper-2.19.jar,
1b6f195
+ jars/common-junit3-2.19.jar,
1b6f195
+ jars/common-junit4-2.19.jar
b90c413
 Import-Package: junit.framework;version="3.0.0",
50be185
  org.junit;version="[4.7,5)",
50be185
  org.junit.runner;version="[4.7,5)",
50be185
diff --git a/tycho-surefire/org.eclipse.tycho.surefire.junit47/pom.xml b/tycho-surefire/org.eclipse.tycho.surefire.junit47/pom.xml
1b6f195
index dc49a46..db453ac 100644
50be185
--- a/tycho-surefire/org.eclipse.tycho.surefire.junit47/pom.xml
50be185
+++ b/tycho-surefire/org.eclipse.tycho.surefire.junit47/pom.xml
b90c413
@@ -54,6 +54,16 @@
b90c413
 									<artifactId>surefire-grouper</artifactId>
50be185
 									<version>${surefire-version}</version>
50be185
 								</artifactItem>
50be185
+								<artifactItem>
50be185
+									<groupId>org.apache.maven.surefire</groupId>
50be185
+									<artifactId>common-junit4</artifactId>
50be185
+									<version>${surefire-version}</version>
50be185
+								</artifactItem>
50be185
+								<artifactItem>
50be185
+									<groupId>org.apache.maven.surefire</groupId>
50be185
+									<artifactId>common-junit3</artifactId>
50be185
+									<version>${surefire-version}</version>
50be185
+								</artifactItem>
50be185
 							</artifactItems>
50be185
 						</configuration>
50be185
 					</execution>
b81da61
diff --git a/tycho-surefire/org.eclipse.tycho.surefire.osgibooter/META-INF/MANIFEST.MF b/tycho-surefire/org.eclipse.tycho.surefire.osgibooter/META-INF/MANIFEST.MF
1b6f195
index 991edc1..83732d5 100644
b81da61
--- a/tycho-surefire/org.eclipse.tycho.surefire.osgibooter/META-INF/MANIFEST.MF
b81da61
+++ b/tycho-surefire/org.eclipse.tycho.surefire.osgibooter/META-INF/MANIFEST.MF
1b6f195
@@ -5,9 +5,10 @@ Require-Bundle: org.eclipse.osgi;bundle-version="3.2.2",
1b6f195
 Eclipse-AutoStart: true
1b6f195
 Bundle-Version: 0.23.0
b81da61
 Bundle-ClassPath: .,
1b6f195
- jars/surefire-booter-2.17.jar,
1b6f195
- jars/surefire-api-2.17.jar,
b81da61
- jars/maven-surefire-common-2.17.jar
1b6f195
+ jars/surefire-booter-2.19.jar,
1b6f195
+ jars/surefire-api-2.19.jar,
1b6f195
+ jars/maven-surefire-common-2.19.jar,
b81da61
+ jars/plexus-utils-3.0.jar
b81da61
 Bundle-Name: Tycho Surefire OSGi Booter Eclipse Application (Incubation)
b81da61
 Bundle-ManifestVersion: 2
b81da61
 Bundle-SymbolicName: org.eclipse.tycho.surefire.osgibooter;singleton:=true
b81da61
diff --git a/tycho-surefire/org.eclipse.tycho.surefire.osgibooter/pom.xml b/tycho-surefire/org.eclipse.tycho.surefire.osgibooter/pom.xml
1b6f195
index 82700eb..3fbc3a3 100644
b81da61
--- a/tycho-surefire/org.eclipse.tycho.surefire.osgibooter/pom.xml
b81da61
+++ b/tycho-surefire/org.eclipse.tycho.surefire.osgibooter/pom.xml
b81da61
@@ -57,6 +57,11 @@
b81da61
 									<artifactId>maven-surefire-common</artifactId>
b81da61
 									<version>${surefire-version}</version>
b81da61
 								</artifactItem>
b81da61
+								<artifactItem>
b81da61
+									<groupId>org.codehaus.plexus</groupId>
b81da61
+									<artifactId>plexus-utils</artifactId>
b81da61
+									<version>3.0</version>
b81da61
+								</artifactItem>
b81da61
 							</artifactItems>
b81da61
 						</configuration>
b81da61
 					</execution>
1b6f195
diff --git a/tycho-surefire/org.eclipse.tycho.surefire.osgibooter/src/main/java/org/eclipse/tycho/surefire/osgibooter/OsgiSurefireBooter.java b/tycho-surefire/org.eclipse.tycho.surefire.osgibooter/src/main/java/org/eclipse/tycho/surefire/osgibooter/OsgiSurefireBooter.java
1b6f195
index 19eeab9..7accf71 100644
1b6f195
--- a/tycho-surefire/org.eclipse.tycho.surefire.osgibooter/src/main/java/org/eclipse/tycho/surefire/osgibooter/OsgiSurefireBooter.java
1b6f195
+++ b/tycho-surefire/org.eclipse.tycho.surefire.osgibooter/src/main/java/org/eclipse/tycho/surefire/osgibooter/OsgiSurefireBooter.java
1b6f195
@@ -21,7 +21,9 @@ import java.io.IOException;
1b6f195
 import java.net.URL;
1b6f195
 import java.util.ArrayList;
1b6f195
 import java.util.Arrays;
1b6f195
+import java.util.Collections;
1b6f195
 import java.util.Enumeration;
1b6f195
+import java.util.HashMap;
1b6f195
 import java.util.List;
1b6f195
 import java.util.Map;
1b6f195
 import java.util.Properties;
1b6f195
@@ -34,7 +36,9 @@ import org.apache.maven.surefire.booter.ClasspathConfiguration;
1b6f195
 import org.apache.maven.surefire.booter.ForkedBooter;
1b6f195
 import org.apache.maven.surefire.booter.ProviderConfiguration;
1b6f195
 import org.apache.maven.surefire.booter.ProviderFactory;
1b6f195
+import org.apache.maven.surefire.booter.Shutdown;
1b6f195
 import org.apache.maven.surefire.booter.StartupConfiguration;
1b6f195
+import org.apache.maven.surefire.cli.CommandLineOption;
1b6f195
 import org.apache.maven.surefire.report.ReporterConfiguration;
1b6f195
 import org.apache.maven.surefire.report.ReporterFactory;
1b6f195
 import org.apache.maven.surefire.suite.RunResult;
1b6f195
@@ -75,13 +79,14 @@ public class OsgiSurefireBooter {
1b6f195
                 new ClassLoaderConfiguration(useSystemClassloader, useManifestOnlyJar), forkRequested, inForkedVM);
1b6f195
         // TODO dir scanning with no includes done here (done in TestMojo already) 
1b6f195
         // but without dirScannerParams we get an NPE accessing runOrder
1b6f195
-        DirectoryScannerParameters dirScannerParams = new DirectoryScannerParameters(testClassesDir, emptyList(),
1b6f195
-                emptyList(), emptyList(), failIfNoTests, runOrder);
1b6f195
+        DirectoryScannerParameters dirScannerParams = new DirectoryScannerParameters(testClassesDir, Collections.<String>emptyList(),
1b6f195
+                Collections.<String>emptyList(), Collections.<String>emptyList(), failIfNoTests, runOrder);
1b6f195
         ReporterConfiguration reporterConfig = new ReporterConfiguration(reportsDir, trimStacktrace);
1b6f195
         TestRequest testRequest = new TestRequest(null, testClassesDir, null);
1b6f195
         ProviderConfiguration providerConfiguration = new ProviderConfiguration(dirScannerParams,
1b6f195
                 new RunOrderParameters(runOrder, null), failIfNoTests, reporterConfig, null, testRequest,
1b6f195
-                extractProviderProperties(testProps), null, false);
1b6f195
+                extractProviderProperties(testProps), null, false, Collections.<CommandLineOption>emptyList(),
1b6f195
+                0, Shutdown.DEFAULT);
1b6f195
         StartupReportConfiguration startupReportConfig = new StartupReportConfiguration(useFile, printSummary,
1b6f195
                 StartupReportConfiguration.PLAIN_REPORT_FORMAT, redirectTestOutputToFile, disableXmlReport, reportsDir,
1b6f195
                 trimStacktrace, null, "TESTHASH", false, 0);
1b6f195
@@ -103,12 +108,12 @@ public class OsgiSurefireBooter {
1b6f195
     /*
1b6f195
      * See TestMojo#mergeProviderProperties
1b6f195
      */
1b6f195
-    private static Properties extractProviderProperties(Properties surefireProps) {
1b6f195
-        Properties providerProps = new Properties();
1b6f195
+    private static Map<String, String> extractProviderProperties(Properties surefireProps) {
1b6f195
+        Map<String, String> providerProps = new HashMap<String, String>();
1b6f195
         for (Map.Entry entry : surefireProps.entrySet()) {
1b6f195
             String key = (String) entry.getKey();
1b6f195
             if (key.startsWith("__provider.")) {
1b6f195
-                providerProps.put(key.substring("__provider.".length()), entry.getValue());
1b6f195
+                providerProps.put(key.substring("__provider.".length()), (String)entry.getValue());
1b6f195
             }
1b6f195
         }
1b6f195
         return providerProps;
1b6f195
diff --git a/tycho-surefire/pom.xml b/tycho-surefire/pom.xml
1b6f195
index cb2b826..bbe5f29 100644
1b6f195
--- a/tycho-surefire/pom.xml
1b6f195
+++ b/tycho-surefire/pom.xml
1b6f195
@@ -26,7 +26,7 @@
1b6f195
 	<name>Tycho Surefire Parent (Incubation)</name>
1b6f195
 
1b6f195
 	<properties>
1b6f195
-		<surefire-version>2.17</surefire-version>
1b6f195
+		<surefire-version>2.19</surefire-version>
1b6f195
 		
1b6f195
 		statements to JUnit packages required for org.eclipse.tycho.surefire.junit* OSGi wrappers.
1b6f195
 		Surefire jars are shaded but not fully self-contained (various package dependencies to org.apache.maven.* 
1b6f195
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
1b6f195
index 9f1e332..62a16fb 100644
1b6f195
--- a/tycho-surefire/tycho-surefire-plugin/src/main/java/org/eclipse/tycho/surefire/TestMojo.java
1b6f195
+++ b/tycho-surefire/tycho-surefire-plugin/src/main/java/org/eclipse/tycho/surefire/TestMojo.java
1b6f195
@@ -20,6 +20,7 @@ import java.net.MalformedURLException;
1b6f195
 import java.util.ArrayList;
1b6f195
 import java.util.Arrays;
1b6f195
 import java.util.Collections;
1b6f195
+import java.util.HashMap;
1b6f195
 import java.util.LinkedHashMap;
1b6f195
 import java.util.List;
1b6f195
 import java.util.Map;
1b6f195
@@ -45,6 +46,7 @@ import org.apache.maven.plugins.annotations.ResolutionScope;
1b6f195
 import org.apache.maven.project.MavenProject;
1b6f195
 import org.apache.maven.repository.RepositorySystem;
1b6f195
 import org.apache.maven.surefire.booter.ProviderParameterNames;
1b6f195
+import org.apache.maven.surefire.testset.TestListResolver;
1b6f195
 import org.apache.maven.surefire.util.DefaultScanResult;
1b6f195
 import org.apache.maven.surefire.util.ScanResult;
1b6f195
 import org.apache.maven.toolchain.Toolchain;
1b6f195
@@ -835,7 +837,7 @@ public class TestMojo extends AbstractMojo {
1b6f195
 
1b6f195
         p.put("failifnotests", String.valueOf(failIfNoTests));
1b6f195
         p.put("runOrder", runOrder);
1b6f195
-        Properties mergedProviderProperties = getMergedProviderProperties();
1b6f195
+        Map<String, String> mergedProviderProperties = getMergedProviderPropertiesMap();
1b6f195
         ScanResult scanResult = scanForTests();
1b6f195
         scanResult.writeTo(mergedProviderProperties);
1b6f195
         for (Map.Entry entry : mergedProviderProperties.entrySet()) {
1b6f195
@@ -862,6 +864,24 @@ public class TestMojo extends AbstractMojo {
1b6f195
         return result;
1b6f195
     }
1b6f195
 
1b6f195
+    private Map<String, String> getMergedProviderPropertiesMap() {
1b6f195
+        Map<String, String> result = new HashMap<String, String>();
1b6f195
+        for (Map.Entry e : providerProperties.entrySet()) {
1b6f195
+            result.put((String) e.getKey(), (String) e.getValue());
1b6f195
+        }
1b6f195
+        if (parallel != null) {
1b6f195
+            result.put(ProviderParameterNames.PARALLEL_PROP, parallel.name());
1b6f195
+            if (threadCount > 0) {
1b6f195
+                result.put(ProviderParameterNames.THREADCOUNT_PROP, String.valueOf(threadCount));
1b6f195
+            }
1b6f195
+            result.put(/* JUnitCoreParameters.PERCORETHREADCOUNT_KEY */"perCoreThreadCount",
1b6f195
+                    String.valueOf(perCoreThreadCount));
1b6f195
+            result.put(/* JUnitCoreParameters.USEUNLIMITEDTHREADS_KEY */"useUnlimitedThreads",
1b6f195
+                    String.valueOf(useUnlimitedThreads));
1b6f195
+        }
1b6f195
+        return result;
1b6f195
+    }
1b6f195
+
1b6f195
     protected ScanResult scanForTests() {
1b6f195
         List<String> defaultIncludes = Arrays.asList("**/Test*.class", "**/*Test.class", "**/*TestCase.class");
1b6f195
         List<String> defaultExcludes = Arrays.asList("**/*$*");
1b6f195
@@ -879,8 +899,9 @@ public class TestMojo extends AbstractMojo {
1b6f195
         } else {
1b6f195
             includeList = defaultIncludes;
1b6f195
         }
1b6f195
-        DirectoryScanner scanner = new DirectoryScanner(testClassesDirectory, includeList, excludes != null ? excludes
1b6f195
-                : defaultExcludes, Collections.<String> emptyList());
1b6f195
+        DirectoryScanner scanner = new DirectoryScanner(testClassesDirectory,
1b6f195
+                new TestListResolver(includeList, excludes != null ? excludes : defaultExcludes),
1b6f195
+                new TestListResolver(Collections.<String> emptyList()));
1b6f195
         DefaultScanResult scanResult = scanner.scan();
1b6f195
         return scanResult;
1b6f195
     }
416b074
-- 
1b6f195
2.4.3
416b074