use of org.apache.maven.surefire.booter.PropertiesWrapper in project tycho by eclipse.
the class TestMojo method createSurefireProperties.
private void createSurefireProperties(TestFrameworkProvider provider) throws MojoExecutionException {
PropertiesWrapper wrapper = new PropertiesWrapper(new HashMap<String, String>());
wrapper.setProperty("testpluginname", getTestBundleSymbolicName());
wrapper.setProperty("testclassesdirectory", testClassesDirectory.getAbsolutePath());
wrapper.setProperty("reportsdirectory", reportsDirectory.getAbsolutePath());
wrapper.setProperty("redirectTestOutputToFile", String.valueOf(redirectTestOutputToFile));
wrapper.setProperty("failifnotests", String.valueOf(failIfNoTests));
wrapper.setProperty("runOrder", runOrder);
wrapper.setProperty("skipAfterFailureCount", String.valueOf(skipAfterFailureCount));
wrapper.setProperty("rerunFailingTestsCount", String.valueOf(rerunFailingTestsCount));
Properties mergedProviderProperties = getMergedProviderProperties();
mergedProviderProperties.putAll(provider.getProviderSpecificProperties());
ScanResult scanResult = scanForTests();
Map<String, String> providerPropertiesAsMap = propertiesAsMap(mergedProviderProperties);
scanResult.writeTo(providerPropertiesAsMap);
for (Map.Entry<String, String> entry : providerPropertiesAsMap.entrySet()) {
wrapper.setProperty("__provider." + entry.getKey(), entry.getValue().toString());
}
wrapper.setProperty("testprovider", provider.getSurefireProviderClassName());
getLog().debug("Using test framework provider " + provider.getClass().getName());
wrapper.addList(suiteXmlFiles, BooterConstants.TEST_SUITE_XML_FILES);
storeProperties(wrapper.getProperties(), surefireProperties);
}
use of org.apache.maven.surefire.booter.PropertiesWrapper in project tycho by eclipse.
the class OsgiSurefireBooter method run.
public static int run(String[] args) throws Exception {
Properties testProps = loadProperties(getTestProperties(args));
boolean failIfNoTests = Boolean.parseBoolean(testProps.getProperty("failifnotests", "false"));
boolean redirectTestOutputToFile = Boolean.parseBoolean(testProps.getProperty("redirectTestOutputToFile", "false"));
String testPlugin = testProps.getProperty("testpluginname");
File testClassesDir = new File(testProps.getProperty("testclassesdirectory"));
File reportsDir = new File(testProps.getProperty("reportsdirectory"));
String provider = testProps.getProperty("testprovider");
String runOrder = testProps.getProperty("runOrder");
int skipAfterFailureCount = Integer.parseInt(testProps.getProperty("skipAfterFailureCount", "0"));
int rerunFailingTestsCount = Integer.parseInt(testProps.getProperty("rerunFailingTestsCount", "0"));
Map<String, String> propertiesMap = new HashMap<String, String>();
for (String key : testProps.stringPropertyNames()) {
propertiesMap.put(key, testProps.getProperty(key));
}
PropertiesWrapper wrapper = new PropertiesWrapper(propertiesMap);
List<String> suiteXmlFiles = wrapper.getStringList(BooterConstants.TEST_SUITE_XML_FILES);
boolean forkRequested = true;
boolean inForkedVM = true;
boolean trimStacktrace = true;
boolean useSystemClassloader = false;
boolean useManifestOnlyJar = false;
boolean useFile = true;
boolean printSummary = true;
boolean disableXmlReport = false;
ClasspathConfiguration classPathConfig = new ClasspathConfiguration(false, false);
StartupConfiguration startupConfiguration = new StartupConfiguration(provider, classPathConfig, new ClassLoaderConfiguration(useSystemClassloader, useManifestOnlyJar), forkRequested, inForkedVM);
// TODO dir scanning with no includes done here (done in TestMojo already)
// but without dirScannerParams we get an NPE accessing runOrder
DirectoryScannerParameters dirScannerParams = new DirectoryScannerParameters(testClassesDir, Collections.<String>emptyList(), Collections.<String>emptyList(), Collections.<String>emptyList(), failIfNoTests, runOrder);
ReporterConfiguration reporterConfig = new ReporterConfiguration(reportsDir, trimStacktrace);
TestRequest testRequest = new TestRequest(suiteXmlFiles, testClassesDir, TestListResolver.getEmptyTestListResolver());
ProviderConfiguration providerConfiguration = new ProviderConfiguration(dirScannerParams, new RunOrderParameters(runOrder, null), failIfNoTests, reporterConfig, null, testRequest, extractProviderProperties(testProps), null, false, Collections.<CommandLineOption>emptyList(), skipAfterFailureCount, Shutdown.DEFAULT);
StartupReportConfiguration startupReportConfig = new StartupReportConfiguration(useFile, printSummary, StartupReportConfiguration.PLAIN_REPORT_FORMAT, redirectTestOutputToFile, disableXmlReport, reportsDir, trimStacktrace, null, "TESTHASH", false, rerunFailingTestsCount);
ReporterFactory reporterFactory = new DefaultReporterFactory(startupReportConfig);
// API indicates we should use testClassLoader below but surefire also tries
// to load surefire classes using this classloader
RunResult result = ProviderFactory.invokeProvider(null, createCombinedClassLoader(testPlugin), reporterFactory, providerConfiguration, false, startupConfiguration, true);
// counter-intuitive, but null indicates OK here
return result.getFailsafeCode() == null ? 0 : result.getFailsafeCode();
}
Aggregations