View | Details | Raw Unified | Return to bug 311979 | Differences between
and this patch

Collapse All | Expand All

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

Return to bug 311979