Skip to content

Commit 3e76088

Browse files
committed
Fix #52 Allow to supply debug options to tycho-surefire
Signed-off-by: Christoph Läubrich <laeubi@laeubi-soft.de>
1 parent af7f47c commit 3e76088

File tree

2 files changed

+46
-8
lines changed

2 files changed

+46
-8
lines changed

tycho-surefire/org.eclipse.tycho.surefire.osgibooter/src/main/java/org/eclipse/tycho/surefire/osgibooter/OsgiSurefireBooter.java

+20-4
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@
5555
import org.eclipse.osgi.service.resolver.ResolverError;
5656
import org.osgi.framework.Bundle;
5757
import org.osgi.framework.BundleException;
58+
import org.osgi.framework.Constants;
5859

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

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

185196
private static ClassLoader getBundleClassLoader(String symbolicName) throws BundleException {
186-
Bundle bundle = Activator.getBundle(symbolicName);
187-
if (bundle == null) {
188-
throw new RuntimeException("Bundle " + symbolicName + " is not found");
189-
}
197+
Bundle bundle = getBundle(symbolicName);
190198
try {
191199
bundle.start();
192200
} catch (BundleException ex) {
@@ -207,6 +215,14 @@ private static ClassLoader getBundleClassLoader(String symbolicName) throws Bund
207215
return new BundleClassLoader(bundle);
208216
}
209217

218+
protected static Bundle getBundle(String symbolicName) {
219+
Bundle bundle = Activator.getBundle(symbolicName);
220+
if (bundle == null) {
221+
throw new RuntimeException("Bundle " + symbolicName + " is not found");
222+
}
223+
return bundle;
224+
}
225+
210226
private static class BundleClassLoader extends ClassLoader {
211227
private Bundle bundle;
212228

tycho-surefire/tycho-surefire-plugin/src/main/java/org/eclipse/tycho/surefire/AbstractTestMojo.java

+26-4
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,16 @@ public abstract class AbstractTestMojo extends AbstractMojo {
141141
@Parameter(property = "debugPort")
142142
private int debugPort;
143143

144+
/**
145+
* if set to a non-null value, the platform is put in debug mode. If the value is a non-empty
146+
* string it is interpreted as the location of the .options file. This file indicates what debug
147+
* points are available for a plug-in and whether or not they are enabled. for a list of
148+
* available options see <a href=
149+
* "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>
150+
*/
151+
@Parameter(property = "osgi.debug")
152+
private String debugOptions;
153+
144154
/**
145155
* List of patterns (separated by commas) used to specify the tests that should be included in
146156
* testing. When not specified and when the <code>test</code> parameter is not specified, the
@@ -205,11 +215,17 @@ public abstract class AbstractTestMojo extends AbstractMojo {
205215
private String excludedGroups;
206216

207217
/**
208-
* Enables -debug -consolelog for the test OSGi runtime
218+
* Enables -consolelog for the test OSGi runtime
209219
*/
210220
@Parameter(property = "tycho.showEclipseLog", defaultValue = "false")
211221
private boolean showEclipseLog;
212222

223+
/**
224+
* prints all loaded bundles
225+
*/
226+
@Parameter(property = "tycho.printBundles", defaultValue = "false")
227+
private boolean printBundles;
228+
213229
/**
214230
* Set this to "true" to redirect the unit test standard output to a file (found in
215231
* reportsDirectory/testName-output.txt).
@@ -893,6 +909,7 @@ protected PropertiesWrapper createSurefireProperties(TestFrameworkProvider provi
893909
wrapper.setProperty("trimStackTrace", String.valueOf(trimStackTrace));
894910
wrapper.setProperty("skipAfterFailureCount", String.valueOf(skipAfterFailureCount));
895911
wrapper.setProperty("rerunFailingTestsCount", String.valueOf(rerunFailingTestsCount));
912+
wrapper.setProperty("printBundles", String.valueOf(printBundles));
896913
Properties mergedProviderProperties = getMergedProviderProperties();
897914
mergedProviderProperties.putAll(provider.getProviderSpecificProperties());
898915
ScanResult scanResult = scanForTests();
@@ -1133,11 +1150,16 @@ private EquinoxLaunchConfiguration createCommandLine(EquinoxInstallation testRun
11331150
for (Map.Entry<String, String> entry : getMergedSystemProperties().entrySet()) {
11341151
cli.addVMArguments("-D" + entry.getKey() + "=" + entry.getValue());
11351152
}
1136-
1153+
if (debugOptions != null || getLog().isDebugEnabled()) {
1154+
if (debugOptions == null || debugOptions.isBlank()) {
1155+
cli.addProgramArguments("-debug");
1156+
} else {
1157+
cli.addProgramArguments("-debug", new File(debugOptions).getAbsolutePath());
1158+
}
1159+
}
11371160
if (getLog().isDebugEnabled() || showEclipseLog) {
1138-
cli.addProgramArguments("-debug", "-consolelog");
1161+
cli.addProgramArguments("-consolelog");
11391162
}
1140-
11411163
addProgramArgs(cli, "-data", osgiDataDirectory.getAbsolutePath(), //
11421164
"-install", testRuntime.getLocation().getAbsolutePath(), //
11431165
"-configuration", testRuntime.getConfigurationLocation().getAbsolutePath(), //

0 commit comments

Comments
 (0)