Skip to content

Commit 1ba2338

Browse files
committed
Print framework state on failing bundles
If plugin test do not work as expected the user is currently quite blind. At best there is an exception in the log about a failing bundle, at worst there is only a message "No tests found" and then nothing is executed at all. This now first checks if there are any unresolved plugins and print the current bundles and their state if anything is failing, and also makes the additional manifest to use non optional imports as otherwise things are possibly missing.
1 parent 80aebec commit 1ba2338

2 files changed

Lines changed: 47 additions & 1 deletion

File tree

ui/org.eclipse.pde.junit.runtime/src/org/eclipse/pde/internal/junit/runtime/RemotePluginTestRunner.java

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,34 @@ protected Enumeration<URL> findResources(String name) throws IOException {
7272
* @see RemoteTestRunner
7373
*/
7474
public static void main(String[] args) {
75+
BundleContext bundleContext = FrameworkUtil.getBundle(RemotePluginTestRunner.class).getBundleContext();
76+
if (bundleContext != null) {
77+
Bundle[] bundles = bundleContext.getBundles();
78+
int failures = 0;
79+
for (Bundle bundle : bundles) {
80+
int state = bundle.getState();
81+
if (state != Bundle.ACTIVE && state != Bundle.RESOLVED && state != Bundle.STARTING) {
82+
if (failures == 0) {
83+
System.err.println("##################################################"); //$NON-NLS-1$
84+
System.out.println();
85+
System.err.println("WARNING: There are failing bundles:"); //$NON-NLS-1$
86+
}
87+
System.err.println(String.format(" %s %s can't be resolved!", bundle.getSymbolicName(), bundle.getVersion())); //$NON-NLS-1$
88+
failures++;
89+
}
90+
}
91+
if (failures > 0) {
92+
System.err.println();
93+
System.err.println("Current Framework state is:"); //$NON-NLS-1$
94+
for (Bundle bundle : bundles) {
95+
System.err.println(String.format(" [%s][%d] %s %s", getState(bundle.getState()), bundle.getBundleId(), bundle.getSymbolicName(), bundle.getVersion())); //$NON-NLS-1$
96+
}
97+
System.err.println();
98+
System.err.println(String.format("%d bundle(s) fail to resolve!", failures)); //$NON-NLS-1$
99+
System.out.println();
100+
System.err.println("##################################################"); //$NON-NLS-1$
101+
}
102+
}
75103
RemotePluginTestRunner testRunner = new RemotePluginTestRunner();
76104
testRunner.init(args);
77105
ClassLoader currentTCCL = Thread.currentThread().getContextClassLoader();
@@ -86,6 +114,24 @@ public static void main(String[] args) {
86114
}
87115
}
88116

117+
private static String getState(int state) {
118+
switch (state) {
119+
case Bundle.ACTIVE :
120+
return "ACTIVE "; //$NON-NLS-1$
121+
case Bundle.INSTALLED :
122+
return "INSTALLED "; //$NON-NLS-1$
123+
case Bundle.RESOLVED :
124+
return "RESOLVED "; //$NON-NLS-1$
125+
case Bundle.STARTING :
126+
return "STARTING "; //$NON-NLS-1$
127+
case Bundle.STOPPING :
128+
return "STOPPING "; //$NON-NLS-1$
129+
case Bundle.UNINSTALLED :
130+
return "UNINSTALLED"; //$NON-NLS-1$
131+
}
132+
return Integer.toString(state);
133+
}
134+
89135
private static ClassLoader createJUnit5PluginClassLoader(String testPluginName) {
90136
Bundle testBundle = Platform.getBundle(testPluginName);
91137
if (testBundle == null) {

ui/org.eclipse.pde.launching/src/org/eclipse/pde/launching/JUnitLaunchConfigurationDelegate.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -235,7 +235,7 @@ protected void collectExecutionArguments(ILaunchConfiguration configuration, Lis
235235
//if this is a junit container project it means a user can use additional classes (from the junit container and possible other) that
236236
//are not required to be imported, we compute a fragment manifest here to add additional imports ...
237237
try (PdeProjectAnalyzer analyzer = new PdeProjectAnalyzer(javaProject.getProject(), true)) {
238-
analyzer.setImportPackage("*;resolution:=optional"); //$NON-NLS-1$
238+
analyzer.setImportPackage("*"); //$NON-NLS-1$
239239
String bsn = testPlugin.getId() + "-additional-test-probe-imports"; //$NON-NLS-1$
240240
analyzer.setBundleSymbolicName(bsn);
241241
analyzer.set(Constants.FRAGMENT_HOST, testPlugin.getId());

0 commit comments

Comments
 (0)