Search in sources :

Example 1 with BackendException

use of org.erlide.backend.api.BackendException in project erlide_eclipse by erlang.

the class DialyzerUtils method doDialyze.

public static void doDialyze(final IProgressMonitor monitor, final Set<IErlModule> modules, final Set<IErlProject> projects, final IBackend backend) throws InvocationTargetException, DialyzerErrorException {
    if (backend == null) {
        ErlLogger.warn("Trying to dialyze with null backend");
        return;
    }
    try {
        for (final IErlModule module : modules) {
            DialyzerMarkerUtils.removeDialyzerMarkersFor(module.getResource());
        }
        // TODO handle preferences from multiple projects
        final DialyzerPreferences prefs = DialyzerPreferences.get(null);
        final Collection<String> pltPaths = prefs.getPltPaths();
        // prefs.getFromSource();
        final boolean fromSource = false;
        // prefs.getNoCheckPLT();
        final boolean noCheckPLT = true;
        final List<String> files = Lists.newArrayList();
        final List<IPath> includeDirs = Lists.newArrayList();
        final List<String> names = Lists.newArrayList();
        DialyzerUtils.collectFilesAndIncludeDirs(modules, projects, files, names, includeDirs, fromSource);
        if (names.isEmpty()) {
            return;
        }
        final String fileNames = names.size() + " modules [" + DialyzerUtils.getFileNames(names) + "]";
        monitor.subTask(fileNames);
        ErlLogger.trace("dialyzer", "run %s", fileNames);
        final IOtpRpc b = backend.getOtpRpc();
        final RpcFuture future = ErlideDialyze.dialyze(b, files, pltPaths, includeDirs, fromSource, noCheckPLT);
        while (!future.isDone()) {
            // check cancellation
            if (monitor.isCanceled()) {
                throw new OperationCanceledException();
            }
            // check backend down
            if (!backend.isRunning()) {
                throw new BackendException("Dialyzer: backend " + backend.getName() + " is down");
            }
            OtpErlangObject r = null;
            try {
                r = future.checkedGet(500, TimeUnit.MILLISECONDS);
            } catch (final TimeoutException e) {
            } catch (final RpcTimeoutException e) {
            }
            if (r != null) {
                DialyzerUtils.processResult(b, r);
            }
        }
    } catch (final RpcException e) {
        throw new InvocationTargetException(e);
    } catch (final BackendException e) {
        throw new InvocationTargetException(e);
    }
}
Also used : IPath(org.eclipse.core.runtime.IPath) OperationCanceledException(org.eclipse.core.runtime.OperationCanceledException) InvocationTargetException(java.lang.reflect.InvocationTargetException) IOtpRpc(org.erlide.runtime.rpc.IOtpRpc) BackendException(org.erlide.backend.api.BackendException) OtpErlangObject(com.ericsson.otp.erlang.OtpErlangObject) RpcException(org.erlide.runtime.rpc.RpcException) IErlModule(org.erlide.engine.model.root.IErlModule) RpcFuture(org.erlide.runtime.rpc.RpcFuture) RpcTimeoutException(org.erlide.runtime.rpc.RpcTimeoutException) RpcTimeoutException(org.erlide.runtime.rpc.RpcTimeoutException) TimeoutException(java.util.concurrent.TimeoutException)

Example 2 with BackendException

use of org.erlide.backend.api.BackendException in project erlide_eclipse by erlang.

the class AsyncCaller method run.

@Override
public void run() {
    final T context = prepare();
    try {
        final RpcFuture result = call();
        if (result == null) {
            return;
        }
        final Job job = new UIJob("async call updater") {

            @Override
            public IStatus runInUIThread(final IProgressMonitor monitor) {
                try {
                    if (result.checkedGet(1, TimeUnit.MILLISECONDS) == null) {
                        schedule(interval);
                    }
                } catch (final RpcException e) {
                    ErlLogger.error(e);
                } catch (final TimeoutException e) {
                    ErlLogger.error(e);
                }
                handleResult(context, result);
                if (monitor.isCanceled()) {
                    return Status.CANCEL_STATUS;
                }
                return new Status(IStatus.OK, ErlideUIPlugin.PLUGIN_ID, "done");
            }
        };
        job.schedule(interval);
    } catch (final BackendException e) {
        ErlLogger.error(e);
    }
}
Also used : IStatus(org.eclipse.core.runtime.IStatus) Status(org.eclipse.core.runtime.Status) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) RpcException(org.erlide.runtime.rpc.RpcException) UIJob(org.eclipse.ui.progress.UIJob) RpcFuture(org.erlide.runtime.rpc.RpcFuture) Job(org.eclipse.core.runtime.jobs.Job) UIJob(org.eclipse.ui.progress.UIJob) TimeoutException(java.util.concurrent.TimeoutException) BackendException(org.erlide.backend.api.BackendException)

Example 3 with BackendException

use of org.erlide.backend.api.BackendException in project erlide_eclipse by erlang.

the class InternalBuilder method handleErlangFiles.

private void handleErlangFiles(final IErlProject erlProject, @NonNull final IProject project, final BuildKind kind, final IResourceDelta resourceDelta, final BuildNotifier notifier) throws CoreException, BackendException {
    final OtpErlangList compilerOptions = CompilerOptions.get(project);
    final Set<BuildResource> resourcesToBuild = getResourcesToBuild(kind, project, resourceDelta, notifier);
    final int n = resourcesToBuild.size();
    if (n == 0) {
        return;
    }
    if (erlProject == null) {
        return;
    }
    // if (BuilderHelper.isDebugging()) {
    ErlLogger.debug("Will compile %d resource(s)", n);
    // }
    final IBackend backend = BackendCore.getBackendManager().getBuildBackend(erlProject);
    if (backend == null) {
        final String message = "No backend with the required " + "version could be found. Can't build.";
        MarkerUtils.createProblemMarker(project, null, message, 0, IMarker.SEVERITY_ERROR);
        throw new BackendException(message);
    }
    final IErlModel model = ErlangEngine.getInstance().getModel();
    backend.addProjectPath(model.findProject(project));
    notifier.setProgressPerCompilationUnit(1.0f / n);
    final Map<RpcFuture, IResource> results = new HashMap<>();
    for (final BuildResource bres : resourcesToBuild) {
        notifier.checkCancel();
        final IResource resource = bres.getResource();
        MarkerUtils.deleteMarkers(resource);
        notifier.aboutToCompile(resource);
        if ("erl".equals(resource.getFileExtension())) {
            final String outputDir = erlProject.getProperties().getOutputDir().toString();
            final RpcFuture f = helper.startCompileErl(project, bres, outputDir, backend.getOtpRpc(), compilerOptions, kind == BuildKind.FULL);
            if (f != null) {
                results.put(f, resource);
            }
        } else if ("yrl".equals(resource.getFileExtension())) {
            final RpcFuture f = helper.startCompileYrl(project, resource, backend.getOtpRpc(), compilerOptions);
            if (f != null) {
                results.put(f, resource);
            }
        } else {
            ErlLogger.warn("Don't know how to compile: %s", resource.getName());
        }
    }
    final List<Entry<RpcFuture, IResource>> done = Lists.newArrayList();
    final List<Entry<RpcFuture, IResource>> waiting = Lists.newArrayList(results.entrySet());
    // TODO should use some kind of notification!
    while (!waiting.isEmpty()) {
        for (final Entry<RpcFuture, IResource> result : waiting) {
            notifier.checkCancel();
            OtpErlangObject r;
            try {
                r = result.getKey().get(100, TimeUnit.MILLISECONDS);
            } catch (final Exception e) {
                r = null;
            }
            if (r != null) {
                final IResource resource = result.getValue();
                helper.completeCompile(project, resource, r, backend.getOtpRpc(), compilerOptions);
                notifier.compiled(resource);
                done.add(result);
            }
        }
        waiting.removeAll(done);
        done.clear();
    }
    helper.refreshOutputDir(project);
    try {
        helper.checkForClashes(backend.getOtpRpc(), project);
    } catch (final Exception e) {
    }
    backend.removeProjectPath(model.findProject(project));
}
Also used : IErlModel(org.erlide.engine.model.root.IErlModel) OtpErlangList(com.ericsson.otp.erlang.OtpErlangList) HashMap(java.util.HashMap) CoreException(org.eclipse.core.runtime.CoreException) ErlModelException(org.erlide.engine.model.ErlModelException) OperationCanceledException(org.eclipse.core.runtime.OperationCanceledException) BackendException(org.erlide.backend.api.BackendException) BackendException(org.erlide.backend.api.BackendException) Entry(java.util.Map.Entry) OtpErlangObject(com.ericsson.otp.erlang.OtpErlangObject) IBackend(org.erlide.backend.api.IBackend) RpcFuture(org.erlide.runtime.rpc.RpcFuture) IResource(org.eclipse.core.resources.IResource)

Aggregations

BackendException (org.erlide.backend.api.BackendException)3 RpcFuture (org.erlide.runtime.rpc.RpcFuture)3 OtpErlangObject (com.ericsson.otp.erlang.OtpErlangObject)2 TimeoutException (java.util.concurrent.TimeoutException)2 OperationCanceledException (org.eclipse.core.runtime.OperationCanceledException)2 RpcException (org.erlide.runtime.rpc.RpcException)2 OtpErlangList (com.ericsson.otp.erlang.OtpErlangList)1 InvocationTargetException (java.lang.reflect.InvocationTargetException)1 HashMap (java.util.HashMap)1 Entry (java.util.Map.Entry)1 IResource (org.eclipse.core.resources.IResource)1 CoreException (org.eclipse.core.runtime.CoreException)1 IPath (org.eclipse.core.runtime.IPath)1 IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)1 IStatus (org.eclipse.core.runtime.IStatus)1 Status (org.eclipse.core.runtime.Status)1 Job (org.eclipse.core.runtime.jobs.Job)1 UIJob (org.eclipse.ui.progress.UIJob)1 IBackend (org.erlide.backend.api.IBackend)1 ErlModelException (org.erlide.engine.model.ErlModelException)1