Skip to content

Commit

Permalink
Fix #52 Allow to supply debug options to tycho-surefire (#56)
Browse files Browse the repository at this point in the history
Signed-off-by: Christoph Läubrich <laeubi@laeubi-soft.de>
  • Loading branch information
laeubi authored Apr 12, 2021
1 parent af7f47c commit 518381b
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@
import org.eclipse.osgi.service.resolver.ResolverError;
import org.osgi.framework.Bundle;
import org.osgi.framework.BundleException;
import org.osgi.framework.Constants;

public class OsgiSurefireBooter {
private static final String XSD = "https://maven.apache.org/surefire/maven-surefire-plugin/xsd/surefire-test-report.xsd";
Expand All @@ -76,6 +77,16 @@ public static int run(String[] args) throws Exception {
for (String key : testProps.stringPropertyNames()) {
propertiesMap.put(key, testProps.getProperty(key));
}
if (Boolean.parseBoolean(testProps.getProperty("printBundles"))) {
System.out.println("====== Installed Bundles ========");
Bundle fwbundle = getBundle(Constants.SYSTEM_BUNDLE_SYMBOLICNAME);
Bundle[] bundles = fwbundle.getBundleContext().getBundles();
for (Bundle bundle : bundles) {
System.out.println("[" + bundle.getBundleId() + "][" + bundle.getState() + "] "
+ bundle.getSymbolicName() + " (" + bundle.getVersion() + ")");
}
System.out.println("=================================");
}
PropertiesWrapper wrapper = new PropertiesWrapper(propertiesMap);
List<String> suiteXmlFiles = wrapper.getStringList(BooterConstants.TEST_SUITE_XML_FILES);

Expand Down Expand Up @@ -183,10 +194,7 @@ private static Properties loadProperties(File file) throws IOException {
}

private static ClassLoader getBundleClassLoader(String symbolicName) throws BundleException {
Bundle bundle = Activator.getBundle(symbolicName);
if (bundle == null) {
throw new RuntimeException("Bundle " + symbolicName + " is not found");
}
Bundle bundle = getBundle(symbolicName);
try {
bundle.start();
} catch (BundleException ex) {
Expand All @@ -207,6 +215,14 @@ private static ClassLoader getBundleClassLoader(String symbolicName) throws Bund
return new BundleClassLoader(bundle);
}

protected static Bundle getBundle(String symbolicName) {
Bundle bundle = Activator.getBundle(symbolicName);
if (bundle == null) {
throw new RuntimeException("Bundle " + symbolicName + " is not found");
}
return bundle;
}

private static class BundleClassLoader extends ClassLoader {
private Bundle bundle;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,16 @@ public abstract class AbstractTestMojo extends AbstractMojo {
@Parameter(property = "debugPort")
private int debugPort;

/**
* if set to a non-null value, the platform is put in debug mode. If the value is a non-empty
* string it is interpreted as the location of the .options file. This file indicates what debug
* points are available for a plug-in and whether or not they are enabled. for a list of
* available options see <a href=
* "https://git.eclipse.org/c/equinox/rt.equinox.framework.git/plain/bundles/org.eclipse.osgi/.options">https://git.eclipse.org/c/equinox/rt.equinox.framework.git/plain/bundles/org.eclipse.osgi/.options</a>
*/
@Parameter(property = "osgi.debug")
private String debugOptions;

/**
* List of patterns (separated by commas) used to specify the tests that should be included in
* testing. When not specified and when the <code>test</code> parameter is not specified, the
Expand Down Expand Up @@ -205,11 +215,17 @@ public abstract class AbstractTestMojo extends AbstractMojo {
private String excludedGroups;

/**
* Enables -debug -consolelog for the test OSGi runtime
* Enables -consolelog for the test OSGi runtime
*/
@Parameter(property = "tycho.showEclipseLog", defaultValue = "false")
private boolean showEclipseLog;

/**
* prints all loaded bundles
*/
@Parameter(property = "tycho.printBundles", defaultValue = "false")
private boolean printBundles;

/**
* Set this to "true" to redirect the unit test standard output to a file (found in
* reportsDirectory/testName-output.txt).
Expand Down Expand Up @@ -893,6 +909,7 @@ protected PropertiesWrapper createSurefireProperties(TestFrameworkProvider provi
wrapper.setProperty("trimStackTrace", String.valueOf(trimStackTrace));
wrapper.setProperty("skipAfterFailureCount", String.valueOf(skipAfterFailureCount));
wrapper.setProperty("rerunFailingTestsCount", String.valueOf(rerunFailingTestsCount));
wrapper.setProperty("printBundles", String.valueOf(printBundles));
Properties mergedProviderProperties = getMergedProviderProperties();
mergedProviderProperties.putAll(provider.getProviderSpecificProperties());
ScanResult scanResult = scanForTests();
Expand Down Expand Up @@ -1133,11 +1150,16 @@ private EquinoxLaunchConfiguration createCommandLine(EquinoxInstallation testRun
for (Map.Entry<String, String> entry : getMergedSystemProperties().entrySet()) {
cli.addVMArguments("-D" + entry.getKey() + "=" + entry.getValue());
}

if (debugOptions != null || getLog().isDebugEnabled()) {
if (debugOptions == null || debugOptions.isBlank()) {
cli.addProgramArguments("-debug");
} else {
cli.addProgramArguments("-debug", new File(debugOptions).getAbsolutePath());
}
}
if (getLog().isDebugEnabled() || showEclipseLog) {
cli.addProgramArguments("-debug", "-consolelog");
cli.addProgramArguments("-consolelog");
}

addProgramArgs(cli, "-data", osgiDataDirectory.getAbsolutePath(), //
"-install", testRuntime.getLocation().getAbsolutePath(), //
"-configuration", testRuntime.getConfigurationLocation().getAbsolutePath(), //
Expand Down

0 comments on commit 518381b

Please sign in to comment.