Search in sources :

Example 16 with IBackend

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

the class ConsoleTerminateAction method run.

@Override
public void run() {
    try {
        final IBackend backend = fConsole.getBackend();
        final ILaunch launch = backend.getData().getLaunch();
        if (launch != null) {
            terminate(launch);
            final Collection<IProject> projects = Lists.newArrayList(backend.getData().getProjects());
            final IBackendManager backendManager = BackendCore.getBackendManager();
            for (final IProject project : projects) {
                backendManager.removeExecutionBackend(project, backend);
            }
            setEnabled(false);
            fConsole.stop();
        }
        if (!backend.equals(BackendCore.getBackendManager().getIdeBackend())) {
            backend.dispose();
        }
    } catch (final DebugException e) {
        ErlLogger.error(e);
    }
}
Also used : IBackendManager(org.erlide.backend.api.IBackendManager) IBackend(org.erlide.backend.api.IBackend) ILaunch(org.eclipse.debug.core.ILaunch) DebugException(org.eclipse.debug.core.DebugException) IProject(org.eclipse.core.resources.IProject)

Example 17 with IBackend

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

the class BackendLabelProvider method getText.

@Override
public String getText(final Object element) {
    final IBackend b = (IBackend) element;
    final BackendData data = b.getData();
    final RuntimeInfo info = data.getRuntimeInfo();
    final String s = info != null ? info.getName() : "<none>";
    return s + ": " + data.getNodeName();
}
Also used : BackendData(org.erlide.backend.api.BackendData) RuntimeInfo(org.erlide.runtime.runtimeinfo.RuntimeInfo) IBackend(org.erlide.backend.api.IBackend)

Example 18 with IBackend

use of org.erlide.backend.api.IBackend 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)

Example 19 with IBackend

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

the class BackendFactory method createBuildBackend.

@Override
public synchronized IBackend createBuildBackend(final RuntimeInfo info) {
    ErlLogger.debug("Create build backend " + info.getVersion().asMajor().toString());
    final IBackend backend = createBackend(getBuildBackendData(info));
    return backend;
}
Also used : IBackend(org.erlide.backend.api.IBackend)

Example 20 with IBackend

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

the class BackendManager method getByProject.

@Override
public IOtpRpc getByProject(final String projectName) {
    final IProject project = ResourcesPlugin.getWorkspace().getRoot().getProject(projectName);
    final IErlProject erlProject = ErlangEngine.getInstance().getModel().getErlangProject(project);
    if (erlProject == null) {
        return null;
    }
    final IBackend backend = getBuildBackend(erlProject);
    if (backend == null) {
        ErlLogger.warn("Could not find backend for project %s", project);
        return null;
    }
    return backend.getOtpRpc();
}
Also used : IErlProject(org.erlide.engine.model.root.IErlProject) IBackend(org.erlide.backend.api.IBackend) IProject(org.eclipse.core.resources.IProject)

Aggregations

IBackend (org.erlide.backend.api.IBackend)25 IBackendManager (org.erlide.backend.api.IBackendManager)6 CoreException (org.eclipse.core.runtime.CoreException)4 IErlProject (org.erlide.engine.model.root.IErlProject)4 RuntimeInfo (org.erlide.runtime.runtimeinfo.RuntimeInfo)4 BackendData (org.erlide.backend.api.BackendData)3 ErlModelException (org.erlide.engine.model.ErlModelException)3 IErlModel (org.erlide.engine.model.root.IErlModel)3 HashSet (java.util.HashSet)2 IProject (org.eclipse.core.resources.IProject)2 IResource (org.eclipse.core.resources.IResource)2 OperationCanceledException (org.eclipse.core.runtime.OperationCanceledException)2 ILaunch (org.eclipse.debug.core.ILaunch)2 BackendException (org.erlide.backend.api.BackendException)2 RpcException (org.erlide.runtime.rpc.RpcException)2 OtpErlangBinary (com.ericsson.otp.erlang.OtpErlangBinary)1 OtpErlangList (com.ericsson.otp.erlang.OtpErlangList)1 OtpErlangObject (com.ericsson.otp.erlang.OtpErlangObject)1 InvocationTargetException (java.lang.reflect.InvocationTargetException)1 ArrayList (java.util.ArrayList)1