Search in sources :

Example 1 with N4IDEXpectRunListener

use of org.eclipse.n4js.xpect.ui.results.N4IDEXpectRunListener in project n4js by eclipse.

the class XpectConfigurationDelegate method execute.

/**
 * Runs provided File in Engine. Returns output of execution.
 */
public void execute(ILaunch launch, XpectRunConfiguration runConfiguration) throws RuntimeException {
    Job job = new Job(launch.getLaunchConfiguration().getName()) {

        @Override
        protected IStatus run(IProgressMonitor monitor) {
            XpectRunner xr;
            try {
                xr = new XpectRunner(N4IDEXpectTestClass.class);
            } catch (InitializationError e) {
                N4IDEXpectUIPlugin.logError("cannot initialize xpect runner", e);
                return Status.CANCEL_STATUS;
            }
            // TODO support multiple selection
            /*
				 * if Project provided, or package files should be discovered there. Also multiple selected files
				 */
            String testFileLocation = runConfiguration.getXtFileToRun();
            IXpectURIProvider uriprov = xr.getUriProvider();
            if (uriprov instanceof N4IDEXpectTestURIProvider) {
                ((N4IDEXpectTestURIProvider) uriprov).addTestFileLocation(testFileLocation);
            }
            Result result = new Result();
            RunNotifier notifier = new RunNotifier();
            RunListener listener = result.createListener();
            N4IDEXpectRunListener n4Listener = new N4IDEXpectRunListener();
            notifier.addFirstListener(listener);
            notifier.addListener(n4Listener);
            try {
                notifier.fireTestRunStarted(xr.getDescription());
                xr.run(notifier);
                notifier.fireTestRunFinished(result);
            } finally {
                notifier.removeListener(n4Listener);
                notifier.removeListener(listener);
            }
            return Status.OK_STATUS;
        }
    };
    job.setUser(true);
    job.schedule();
}
Also used : IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) N4IDEXpectRunListener(org.eclipse.n4js.xpect.ui.results.N4IDEXpectRunListener) N4IDEXpectTestURIProvider(org.eclipse.n4js.xpect.ui.runner.N4IDEXpectTestFilesCollector.N4IDEXpectTestURIProvider) RunNotifier(org.junit.runner.notification.RunNotifier) N4IDEXpectTestClass(org.eclipse.n4js.xpect.ui.runner.N4IDEXpectTestClass) InitializationError(org.junit.runners.model.InitializationError) XpectRunner(org.eclipse.xpect.runner.XpectRunner) Job(org.eclipse.core.runtime.jobs.Job) IXpectURIProvider(org.eclipse.xpect.runner.IXpectURIProvider) Result(org.junit.runner.Result) N4IDEXpectRunListener(org.eclipse.n4js.xpect.ui.results.N4IDEXpectRunListener) RunListener(org.junit.runner.notification.RunListener)

Aggregations

IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)1 Job (org.eclipse.core.runtime.jobs.Job)1 N4IDEXpectRunListener (org.eclipse.n4js.xpect.ui.results.N4IDEXpectRunListener)1 N4IDEXpectTestClass (org.eclipse.n4js.xpect.ui.runner.N4IDEXpectTestClass)1 N4IDEXpectTestURIProvider (org.eclipse.n4js.xpect.ui.runner.N4IDEXpectTestFilesCollector.N4IDEXpectTestURIProvider)1 IXpectURIProvider (org.eclipse.xpect.runner.IXpectURIProvider)1 XpectRunner (org.eclipse.xpect.runner.XpectRunner)1 Result (org.junit.runner.Result)1 RunListener (org.junit.runner.notification.RunListener)1 RunNotifier (org.junit.runner.notification.RunNotifier)1 InitializationError (org.junit.runners.model.InitializationError)1