Search in sources :

Example 1 with IXpectURIProvider

use of org.eclipse.xpect.runner.IXpectURIProvider 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)

Example 2 with IXpectURIProvider

use of org.eclipse.xpect.runner.IXpectURIProvider in project n4js by eclipse.

the class XpectCompareCommandHandler method displayComparisonView.

/**
 * Display comparison view of test file with expected and actual xpect expectation
 */
private void displayComparisonView(ComparisonFailure cf, Description desc) {
    IXpectURIProvider uriProfider = XpectRunner.INSTANCE.getUriProvider();
    IFile fileTest = null;
    if (uriProfider instanceof N4IDEXpectTestURIProvider) {
        N4IDEXpectTestURIProvider fileCollector = (N4IDEXpectTestURIProvider) uriProfider;
        fileTest = ResourcesPlugin.getWorkspace().getRoot().getFileForLocation(new Path(fileCollector.findRawLocation(desc)));
    }
    if (fileTest != null && fileTest.isAccessible()) {
        N4IDEXpectCompareEditorInput inp = new N4IDEXpectCompareEditorInput(fileTest, cf);
        CompareUI.openCompareEditor(inp);
    } else {
        throw new RuntimeException("paths in descriptions changed!");
    }
}
Also used : Path(org.eclipse.core.runtime.Path) IFile(org.eclipse.core.resources.IFile) N4IDEXpectTestURIProvider(org.eclipse.n4js.xpect.ui.runner.N4IDEXpectTestFilesCollector.N4IDEXpectTestURIProvider) IXpectURIProvider(org.eclipse.xpect.runner.IXpectURIProvider)

Example 3 with IXpectURIProvider

use of org.eclipse.xpect.runner.IXpectURIProvider in project n4js by eclipse.

the class XpectFileContentsUtil method getXpectFileContentAccess.

/**
 * Create instance of {@link XpectFileContentAccess} for given {@link Description}. If xpect file cannot be accessed
 * or resolved from provided description returns empty {@link Optional}
 *
 * @return {@link Optional}<{@link XpectFileContentAccess}>
 */
public static Optional<XpectFileContentAccess> getXpectFileContentAccess(Description description) {
    String contents = "";
    boolean containsFixme = false;
    IXpectURIProvider xpectUriProvider = XpectRunner.INSTANCE.getUriProvider();
    if (xpectUriProvider instanceof N4IDEXpectTestURIProvider) {
        N4IDEXpectTestURIProvider n4XpectUriProvider = (N4IDEXpectTestURIProvider) xpectUriProvider;
        String rawFileLocation = n4XpectUriProvider.findRawLocation(description);
        try {
            contents = new String(Files.readAllBytes(Paths.get(rawFileLocation)));
        } catch (IOException e) {
            N4IDEXpectUIPlugin.logError("cannot read contents of test file", e);
            e.printStackTrace();
            return Optional.empty();
        }
    }
    containsFixme = contents.split("XPECT\\sFIXME").length > 1;
    XpectFileContentAccess xpectFileContetnsAccess = new XpectFileContentAccess(contents, containsFixme);
    return Optional.of(xpectFileContetnsAccess);
}
Also used : N4IDEXpectTestURIProvider(org.eclipse.n4js.xpect.ui.runner.N4IDEXpectTestFilesCollector.N4IDEXpectTestURIProvider) IOException(java.io.IOException) IXpectURIProvider(org.eclipse.xpect.runner.IXpectURIProvider)

Aggregations

N4IDEXpectTestURIProvider (org.eclipse.n4js.xpect.ui.runner.N4IDEXpectTestFilesCollector.N4IDEXpectTestURIProvider)3 IXpectURIProvider (org.eclipse.xpect.runner.IXpectURIProvider)3 IOException (java.io.IOException)1 IFile (org.eclipse.core.resources.IFile)1 IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)1 Path (org.eclipse.core.runtime.Path)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 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