Lines 11-19
Link Here
|
11 |
*******************************************************************************/ |
11 |
*******************************************************************************/ |
12 |
package org.eclipse.pde.internal.junit.runtime; |
12 |
package org.eclipse.pde.internal.junit.runtime; |
13 |
|
13 |
|
14 |
import junit.framework.Assert; |
14 |
import org.eclipse.core.runtime.Platform; |
15 |
import org.eclipse.core.runtime.*; |
|
|
16 |
import org.eclipse.equinox.app.IApplication; |
17 |
import org.eclipse.equinox.app.IApplicationContext; |
15 |
import org.eclipse.equinox.app.IApplicationContext; |
18 |
import org.eclipse.ui.PlatformUI; |
16 |
import org.eclipse.ui.PlatformUI; |
19 |
import org.eclipse.ui.testing.ITestHarness; |
17 |
import org.eclipse.ui.testing.ITestHarness; |
Lines 23-107
Link Here
|
23 |
* A Workbench that runs a test suite specified in the |
21 |
* A Workbench that runs a test suite specified in the |
24 |
* command line arguments. |
22 |
* command line arguments. |
25 |
*/ |
23 |
*/ |
26 |
public class UITestApplication implements IApplication, ITestHarness { |
24 |
public class UITestApplication extends NonUIThreadTestApplication implements ITestHarness { |
27 |
|
25 |
|
28 |
private static final String DEFAULT_APP_3_0 = "org.eclipse.ui.ide.workbench"; //$NON-NLS-1$ |
26 |
private static final String DEFAULT_APP_3_0 = "org.eclipse.ui.ide.workbench"; //$NON-NLS-1$ |
29 |
|
27 |
|
30 |
protected TestableObject fTestableObject; |
28 |
protected TestableObject fTestableObject; |
31 |
protected IApplication fApplication; |
|
|
32 |
|
29 |
|
33 |
/* |
30 |
/* (non-Javadoc) |
34 |
* (non-Javadoc) |
31 |
* @see org.eclipse.pde.internal.junit.runtime.NonUIThreadTestApplication#getDefaultApplicationId() |
35 |
* @see org.eclipse.equinox.app.IApplication#start(org.eclipse.equinox.app.IApplicationContext) |
|
|
36 |
*/ |
37 |
public Object start(IApplicationContext context) throws Exception { |
38 |
String[] args = (String[]) context.getArguments().get(IApplicationContext.APPLICATION_ARGS); |
39 |
Object app = getApplication(args); |
40 |
|
41 |
Assert.assertNotNull(app); |
42 |
|
43 |
fTestableObject = PlatformUI.getTestableObject(); |
44 |
fTestableObject.setTestHarness(this); |
45 |
if (app instanceof IApplication) { |
46 |
fApplication = (IApplication) app; |
47 |
return fApplication.start(context); |
48 |
} |
49 |
return ((IPlatformRunnable) app).run(args); |
50 |
} |
51 |
|
52 |
/* |
53 |
* (non-Javadoc) |
54 |
* @see org.eclipse.equinox.app.IApplication#stop() |
55 |
*/ |
32 |
*/ |
56 |
public void stop() { |
33 |
protected String getDefaultApplicationId() { |
57 |
if (fApplication != null) |
34 |
// In 3.0, the default is the "org.eclipse.ui.ide.worbench" application. |
58 |
fApplication.stop(); |
35 |
return DEFAULT_APP_3_0; |
59 |
} |
36 |
} |
60 |
|
37 |
|
61 |
/* |
38 |
/* (non-Javadoc) |
62 |
* return the application to run, or null if not even the default application |
39 |
* @see org.eclipse.pde.internal.junit.runtime.NonUIThreadTestApplication#runApp(java.lang.Object, org.eclipse.equinox.app.IApplicationContext, java.lang.String[]) |
63 |
* is found. |
|
|
64 |
*/ |
40 |
*/ |
65 |
private Object getApplication(String[] args) throws CoreException { |
41 |
protected Object runApp(Object app, IApplicationContext context, String[] args) throws Exception { |
66 |
// Find the name of the application as specified by the PDE JUnit launcher. |
42 |
fTestableObject = PlatformUI.getTestableObject(); |
67 |
// If no application is specified, the 3.0 default workbench application |
43 |
fTestableObject.setTestHarness(this); |
68 |
// is returned. |
44 |
return super.runApp(app, context, args); |
69 |
IExtension extension = Platform.getExtensionRegistry().getExtension(Platform.PI_RUNTIME, Platform.PT_APPLICATIONS, getApplicationToRun(args)); |
|
|
70 |
|
71 |
Assert.assertNotNull(extension); |
72 |
|
73 |
// If the extension does not have the correct grammar, return null. |
74 |
// Otherwise, return the application object. |
75 |
IConfigurationElement[] elements = extension.getConfigurationElements(); |
76 |
if (elements.length > 0) { |
77 |
IConfigurationElement[] runs = elements[0].getChildren("run"); //$NON-NLS-1$ |
78 |
if (runs.length > 0) { |
79 |
Object runnable = runs[0].createExecutableExtension("class"); //$NON-NLS-1$ |
80 |
if (runnable instanceof IPlatformRunnable || runnable instanceof IApplication) |
81 |
return runnable; |
82 |
} |
83 |
} |
84 |
return null; |
85 |
} |
86 |
|
87 |
/* |
88 |
* The -testApplication argument specifies the application to be run. |
89 |
* If the PDE JUnit launcher did not set this argument, then return |
90 |
* the name of the default application. |
91 |
* In 3.0, the default is the "org.eclipse.ui.ide.worbench" application. |
92 |
* |
93 |
* see bug 228044 |
94 |
* |
95 |
*/ |
96 |
private String getApplicationToRun(String[] args) { |
97 |
for (int i = 0; i < args.length; i++) { |
98 |
if (args[i].equals("-testApplication") && i < args.length - 1) //$NON-NLS-1$ |
99 |
return args[i + 1]; |
100 |
} |
101 |
IProduct product = Platform.getProduct(); |
102 |
if (product != null) |
103 |
return product.getApplication(); |
104 |
return DEFAULT_APP_3_0; |
105 |
} |
45 |
} |
106 |
|
46 |
|
107 |
/* |
47 |
/* |