Search in sources :

Example 1 with IPlatformRunnable

use of org.eclipse.core.runtime.IPlatformRunnable in project eclipse.platform.releng by eclipse.

the class UITestApplication method runDeprecatedApplication.

/*
	 * If we are in pre-3.0 mode, then the application to run is
	 * "org.eclipse.ui.workbench" Therefore, we safely cast the runnable object
	 * to IWorkbenchWindow. We add a listener to it, so that we know when the
	 * window opens so that we can start running the tests. When the tests are
	 * done, we explicitly call close() on the workbench.
	 */
private Object runDeprecatedApplication(IPlatformRunnable object, final Object args) throws Exception {
    Assert.assertTrue(object instanceof IWorkbench);
    final IWorkbench workbench = (IWorkbench) object;
    // the 'started' flag is used so that we only run tests when the window
    // is opened
    // for the first time only.
    final boolean[] started = { false };
    workbench.addWindowListener(new IWindowListener() {

        @Override
        public void windowOpened(IWorkbenchWindow w) {
            if (started[0])
                return;
            w.getShell().getDisplay().asyncExec(() -> {
                started[0] = true;
                try {
                    fTestRunnerResult = EclipseTestRunner.run((String[]) args);
                } catch (IOException e) {
                    e.printStackTrace();
                }
                workbench.close();
            });
        }

        @Override
        public void windowActivated(IWorkbenchWindow window) {
        }

        @Override
        public void windowDeactivated(IWorkbenchWindow window) {
        }

        @Override
        public void windowClosed(IWorkbenchWindow window) {
        }
    });
    return ((IPlatformRunnable) workbench).run(args);
}
Also used : IWorkbench(org.eclipse.ui.IWorkbench) IWorkbenchWindow(org.eclipse.ui.IWorkbenchWindow) IWindowListener(org.eclipse.ui.IWindowListener) IOException(java.io.IOException) IPlatformRunnable(org.eclipse.core.runtime.IPlatformRunnable)

Example 2 with IPlatformRunnable

use of org.eclipse.core.runtime.IPlatformRunnable in project eclipse.platform.releng by eclipse.

the class UITestApplication method getApplication.

/*
	 * return the application to run, or null if not even the default application
	 * is found.
	 */
private Object getApplication(String[] args) throws CoreException {
    // Assume we are in 3.0 mode.
    // Find the name of the application as specified by the PDE JUnit launcher.
    // If no application is specified, the 3.0 default workbench application
    // is returned.
    IExtension extension = Platform.getExtensionRegistry().getExtension(Platform.PI_RUNTIME, Platform.PT_APPLICATIONS, getApplicationToRun(args));
    // Set the deprecated flag to true
    if (extension == null) {
        extension = Platform.getExtensionRegistry().getExtension(Platform.PI_RUNTIME, Platform.PT_APPLICATIONS, DEFAULT_APP_PRE_3_0);
        fInDeprecatedMode = true;
    }
    Assert.assertNotNull(extension);
    // If the extension does not have the correct grammar, return null.
    // Otherwise, return the application object.
    IConfigurationElement[] elements = extension.getConfigurationElements();
    if (elements.length > 0) {
        // $NON-NLS-1$
        IConfigurationElement[] runs = elements[0].getChildren("run");
        if (runs.length > 0) {
            // $NON-NLS-1$
            Object runnable = runs[0].createExecutableExtension("class");
            if (runnable instanceof IPlatformRunnable)
                return runnable;
            if (runnable instanceof IApplication)
                return runnable;
        }
    }
    return null;
}
Also used : IApplication(org.eclipse.equinox.app.IApplication) IExtension(org.eclipse.core.runtime.IExtension) TestableObject(org.eclipse.ui.testing.TestableObject) IPlatformRunnable(org.eclipse.core.runtime.IPlatformRunnable) IConfigurationElement(org.eclipse.core.runtime.IConfigurationElement)

Example 3 with IPlatformRunnable

use of org.eclipse.core.runtime.IPlatformRunnable in project eclipse.platform.releng by eclipse.

the class UITestApplication method run.

@Override
public Object run(final Object args) throws Exception {
    // Get the application to test
    Object application = getApplication((String[]) args);
    Assert.assertNotNull(application);
    Object result;
    if (fInDeprecatedMode && (application instanceof IPlatformRunnable)) {
        result = runDeprecatedApplication((IPlatformRunnable) application, args);
    } else {
        result = runApplication(application, args);
    }
    if (!IPlatformRunnable.EXIT_OK.equals(result)) {
        System.err.println("UITestRunner: Unexpected result from running application " + application + ": " + result);
    }
    return Integer.valueOf(fTestRunnerResult);
}
Also used : TestableObject(org.eclipse.ui.testing.TestableObject) IPlatformRunnable(org.eclipse.core.runtime.IPlatformRunnable)

Aggregations

IPlatformRunnable (org.eclipse.core.runtime.IPlatformRunnable)3 TestableObject (org.eclipse.ui.testing.TestableObject)2 IOException (java.io.IOException)1 IConfigurationElement (org.eclipse.core.runtime.IConfigurationElement)1 IExtension (org.eclipse.core.runtime.IExtension)1 IApplication (org.eclipse.equinox.app.IApplication)1 IWindowListener (org.eclipse.ui.IWindowListener)1 IWorkbench (org.eclipse.ui.IWorkbench)1 IWorkbenchWindow (org.eclipse.ui.IWorkbenchWindow)1