Search in sources :

Example 1 with IApplication

use of org.eclipse.equinox.app.IApplication 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 2 with IApplication

use of org.eclipse.equinox.app.IApplication in project equinox.bundles by eclipse-equinox.

the class EclipseAppHandle method run.

@Override
public Object run(Object context) throws Exception {
    if (context != null) {
        // always force the use of the context if it is not null
        arguments.put(IApplicationContext.APPLICATION_ARGS, context);
    } else {
        // get the context from the arguments
        context = arguments.get(IApplicationContext.APPLICATION_ARGS);
        if (context == null) {
            // if context is null then use the args from CommandLineArgs
            context = CommandLineArgs.getApplicationArgs();
            arguments.put(IApplicationContext.APPLICATION_ARGS, context);
        }
    }
    Object tempResult = null;
    try {
        Object app;
        synchronized (this) {
            if ((status & (EclipseAppHandle.FLAG_STARTING | EclipseAppHandle.FLAG_STOPPING)) == 0)
                throw new ApplicationException(ApplicationException.APPLICATION_INTERNAL_ERROR, NLS.bind(Messages.application_instance_stopped, getInstanceId()));
            // $NON-NLS-1$
            application = getConfiguration().createExecutableExtension("run");
            app = application;
            notifyAll();
        }
        if (app instanceof IApplication)
            tempResult = ((IApplication) app).start(this);
        else
            // $NON-NLS-1$
            tempResult = EclipseAppContainer.callMethodWithException(app, "run", new Class[] { Object.class }, new Object[] { context });
        if (tempResult == null)
            tempResult = NULL_RESULT;
    } finally {
        tempResult = setInternalResult(tempResult, false, null);
    }
    if (Activator.DEBUG)
        // $NON-NLS-1$
        System.out.println(NLS.bind(Messages.application_returned, (new String[] { getApplicationDescriptor().getApplicationId(), tempResult == null ? "null" : tempResult.toString() })));
    return tempResult;
}
Also used : IApplication(org.eclipse.equinox.app.IApplication) ApplicationException(org.osgi.service.application.ApplicationException)

Example 3 with IApplication

use of org.eclipse.equinox.app.IApplication in project reddeer 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 {
    // 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.
    String applicationToRun = getApplicationToRun(args);
    IExtension extension = Platform.getExtensionRegistry().getExtension(Platform.PI_RUNTIME, Platform.PT_APPLICATIONS, applicationToRun);
    Assert.isNotNull(extension, "Could not find IExtension for application: " + applicationToRun);
    // 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 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) IConfigurationElement(org.eclipse.core.runtime.IConfigurationElement)

Example 4 with IApplication

use of org.eclipse.equinox.app.IApplication in project hale by halestudio.

the class ApplicationUtil method launchSyncApplication.

/**
 * Launch an application.
 *
 * @param application the application instance
 * @param argList the application arguments
 * @return the application return code
 * @throws Exception if the application exits with an exception
 */
public static Object launchSyncApplication(IApplication application, final List<String> argList) throws Exception {
    String[] args = argList.size() == 0 ? null : (String[]) argList.toArray(new String[argList.size()]);
    final Map<String, Object> launchArgs = new HashMap<>(1);
    if (args != null) {
        launchArgs.put(IApplicationContext.APPLICATION_ARGS, args);
    }
    IApplicationContext context = new IApplicationContext() {

        @Override
        public void setResult(Object result, IApplication application) {
            throw new UnsupportedOperationException();
        }

        @Override
        public String getBrandingProperty(String key) {
            return null;
        }

        @Override
        public String getBrandingName() {
            return null;
        }

        @Override
        public String getBrandingId() {
            return null;
        }

        @Override
        public String getBrandingDescription() {
            return null;
        }

        @Override
        public Bundle getBrandingBundle() {
            return null;
        }

        @Override
        public String getBrandingApplication() {
            return null;
        }

        @SuppressWarnings("rawtypes")
        @Override
        public Map getArguments() {
            return launchArgs;
        }

        @Override
        public void applicationRunning() {
        // anything to do?
        }
    };
    return application.start(context);
}
Also used : IApplication(org.eclipse.equinox.app.IApplication) HashMap(java.util.HashMap) IApplicationContext(org.eclipse.equinox.app.IApplicationContext)

Example 5 with IApplication

use of org.eclipse.equinox.app.IApplication in project rt.equinox.framework by eclipse.

the class ExitValueApp method run.

public synchronized void run() {
    if (active) {
        try {
            // only run for 5 seconds at most
            wait(5000);
        } catch (InterruptedException e) {
        // do nothing
        }
    }
    stopped = true;
    if (useAsync) {
        IApplication app = this;
        Object result = returnNull ? null : exitValue;
        if (setWrongApp) {
            result = "failed";
            app = new IApplication() {

                public void stop() {
                // nothing
                }

                public Object start(IApplicationContext context) throws Exception {
                    return null;
                }
            };
        }
        try {
            appContext.setResult(result, app);
        // failed
        } catch (IllegalArgumentException e) {
            // passed
            appContext.setResult(returnNull ? null : exitValue, this);
        }
    }
    notifyAll();
}
Also used : IApplication(org.eclipse.equinox.app.IApplication) IApplicationContext(org.eclipse.equinox.app.IApplicationContext)

Aggregations

IApplication (org.eclipse.equinox.app.IApplication)10 IConfigurationElement (org.eclipse.core.runtime.IConfigurationElement)3 IExtension (org.eclipse.core.runtime.IExtension)3 IApplicationContext (org.eclipse.equinox.app.IApplicationContext)3 TestableObject (org.eclipse.ui.testing.TestableObject)3 HashMap (java.util.HashMap)1 CoreException (org.eclipse.core.runtime.CoreException)1 IPlatformRunnable (org.eclipse.core.runtime.IPlatformRunnable)1 EObject (org.eclipse.emf.ecore.EObject)1 RedDeerException (org.eclipse.reddeer.common.exception.RedDeerException)1 ApplicationException (org.osgi.service.application.ApplicationException)1