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 index 1f4d869029..1a9ca9b5cc 100644 --- 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 @@ -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"; @@ -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 suiteXmlFiles = wrapper.getStringList(BooterConstants.TEST_SUITE_XML_FILES); @@ -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) { @@ -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; diff --git a/tycho-surefire/tycho-surefire-plugin/src/main/java/org/eclipse/tycho/surefire/AbstractTestMojo.java b/tycho-surefire/tycho-surefire-plugin/src/main/java/org/eclipse/tycho/surefire/AbstractTestMojo.java index caabf5383c..ba9ac3b8ab 100644 --- a/tycho-surefire/tycho-surefire-plugin/src/main/java/org/eclipse/tycho/surefire/AbstractTestMojo.java +++ b/tycho-surefire/tycho-surefire-plugin/src/main/java/org/eclipse/tycho/surefire/AbstractTestMojo.java @@ -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 https://git.eclipse.org/c/equinox/rt.equinox.framework.git/plain/bundles/org.eclipse.osgi/.options + */ + @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 test parameter is not specified, the @@ -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). @@ -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(); @@ -1133,11 +1150,16 @@ private EquinoxLaunchConfiguration createCommandLine(EquinoxInstallation testRun for (Map.Entry 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(), //