Search in sources :

Example 1 with RpcException

use of org.erlide.runtime.rpc.RpcException 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 RpcException

use of org.erlide.runtime.rpc.RpcException in project erlide_eclipse by erlang.

the class BuilderHelper method compileErl.

public void compileErl(@NonNull final IProject project, final BuildResource resource, final String outputDir, final IOtpRpc b, final OtpErlangList compilerOptions) {
    final RpcFuture res = startCompileErl(project, resource, outputDir, b, compilerOptions, true);
    if (res == null) {
        ErlLogger.warn("error compiling erl file: " + resource.getResource().getProjectRelativePath());
        return;
    }
    try {
        final OtpErlangObject result = res.checkedGet();
        completeCompile(project, resource.getResource(), result, b, compilerOptions);
    } catch (final RpcException e) {
        ErlLogger.warn(e);
    }
}
Also used : OtpErlangObject(com.ericsson.otp.erlang.OtpErlangObject) RpcException(org.erlide.runtime.rpc.RpcException) RpcFuture(org.erlide.runtime.rpc.RpcFuture)

Example 3 with RpcException

use of org.erlide.runtime.rpc.RpcException in project erlide_eclipse by erlang.

the class CoveragePerformer method setCoverageConfiguration.

/**
 * Set coverage configuration
 */
@Override
public synchronized void setCoverageConfiguration(final IConfiguration conf) throws CoverException {
    config = conf;
    StatsTreeModel.getInstance().setRootLabel(config.getProject().getName());
    final IPath ppath = config.getProject().getWorkspaceProject().getLocation();
    // set include files
    final List<OtpErlangObject> includes = new ArrayList<>(config.getModules().size());
    for (final IPath include : config.getIncludeDirs()) {
        log.info(ppath.append(include));
        includes.add(new OtpErlangList(ppath.append(include).toString()));
    }
    try {
        CoverBackend.getInstance().getBackend().getOtpRpc().call(CoverConstants.COVER_ERL_BACKEND, CoverConstants.FUN_SET_INCLUDES, "x", includes);
    } catch (final RpcException e1) {
        e1.printStackTrace();
        throw new CoverException(e1);
    }
    recompileModules();
}
Also used : IPath(org.eclipse.core.runtime.IPath) OtpErlangList(com.ericsson.otp.erlang.OtpErlangList) OtpErlangObject(com.ericsson.otp.erlang.OtpErlangObject) CoverException(org.erlide.cover.api.CoverException) RpcException(org.erlide.runtime.rpc.RpcException) ArrayList(java.util.ArrayList)

Example 4 with RpcException

use of org.erlide.runtime.rpc.RpcException in project erlide_eclipse by erlang.

the class CoveragePerformer method recompileModules.

// cover compilation of chosen modules
private void recompileModules() throws CoverException {
    final List<OtpErlangObject> paths = new ArrayList<>(config.getModules().size());
    for (final IErlModule module : config.getModules()) {
        if (module == null) {
            final String msg = "No such module at given project. Check your configuration";
            CoverBackend.getInstance().handleError(msg);
            throw new CoverException(msg);
        }
        log.info(module.getFilePath());
        paths.add(new OtpErlangList(module.getFilePath()));
    }
    try {
        CoverBackend.getInstance().getBackend().getOtpRpc().call(CoverConstants.COVER_ERL_BACKEND, CoverConstants.FUN_PREP, "x", paths);
    } catch (final RpcException e) {
        ErlLogger.error(e);
        throw new CoverException(e.getMessage());
    }
}
Also used : OtpErlangList(com.ericsson.otp.erlang.OtpErlangList) OtpErlangObject(com.ericsson.otp.erlang.OtpErlangObject) CoverException(org.erlide.cover.api.CoverException) RpcException(org.erlide.runtime.rpc.RpcException) ArrayList(java.util.ArrayList) IErlModule(org.erlide.engine.model.root.IErlModule)

Example 5 with RpcException

use of org.erlide.runtime.rpc.RpcException in project erlide_eclipse by erlang.

the class CoveragePerformer method startCover.

/**
 * Start cover
 */
@Override
public synchronized void startCover(final Collection<String> nodes) throws CoverException {
    final StatsTreeModel model = StatsTreeModel.getInstance();
    model.clear();
    if (CoverBackend.getInstance().getAnnotationMaker() != null) {
        CoverBackend.getInstance().getAnnotationMaker().clearAllAnnotations();
    }
    for (final ICoverObserver obs : CoverBackend.getInstance().getListeners()) {
        obs.eventOccured(new CoverEvent(CoverStatus.UPDATE));
    }
    boolean different = false;
    for (final String node : nodes) {
        if (!coverNodes.contains(node)) {
            different = true;
            break;
        }
    }
    if (coverNodes.isEmpty() || different) {
        coverNodes = nodes;
        log.info(CoverBackend.getInstance().getBackend().getName());
        coverNodes.add(CoverBackend.getInstance().getBackend().getName());
        // TODO restarting
        final List<OtpErlangObject> names = new ArrayList<>(coverNodes.size());
        for (final String name : coverNodes) {
            names.add(new OtpErlangAtom(name));
        }
        final OtpErlangList nodesList = new OtpErlangList(names.toArray(new OtpErlangObject[0]));
        try {
            CoverBackend.getInstance().getBackend().getOtpRpc().call(CoverConstants.COVER_ERL_BACKEND, CoverConstants.FUN_START, "x", nodesList);
        } catch (final RpcException e) {
            ErlLogger.error(e);
            throw new CoverException(e.getMessage());
        }
    }
}
Also used : OtpErlangList(com.ericsson.otp.erlang.OtpErlangList) OtpErlangObject(com.ericsson.otp.erlang.OtpErlangObject) CoverException(org.erlide.cover.api.CoverException) RpcException(org.erlide.runtime.rpc.RpcException) ArrayList(java.util.ArrayList) OtpErlangAtom(com.ericsson.otp.erlang.OtpErlangAtom) StatsTreeModel(org.erlide.cover.views.model.StatsTreeModel)

Aggregations

RpcException (org.erlide.runtime.rpc.RpcException)37 OtpErlangObject (com.ericsson.otp.erlang.OtpErlangObject)30 OtpErlangTuple (com.ericsson.otp.erlang.OtpErlangTuple)15 OtpErlangList (com.ericsson.otp.erlang.OtpErlangList)12 OtpErlangAtom (com.ericsson.otp.erlang.OtpErlangAtom)8 OtpErlangString (com.ericsson.otp.erlang.OtpErlangString)7 ArrayList (java.util.ArrayList)7 IOtpRpc (org.erlide.runtime.rpc.IOtpRpc)6 RpcFuture (org.erlide.runtime.rpc.RpcFuture)5 OtpErlangPid (com.ericsson.otp.erlang.OtpErlangPid)4 TimeoutException (java.util.concurrent.TimeoutException)4 CoverException (org.erlide.cover.api.CoverException)4 IErlModule (org.erlide.engine.model.root.IErlModule)4 RpcTimeoutException (org.erlide.runtime.rpc.RpcTimeoutException)4 Test (org.junit.Test)4 OtpErlangLong (com.ericsson.otp.erlang.OtpErlangLong)3 OtpErlangRangeException (com.ericsson.otp.erlang.OtpErlangRangeException)3 IPath (org.eclipse.core.runtime.IPath)3 IStatus (org.eclipse.core.runtime.IStatus)3 Status (org.eclipse.core.runtime.Status)3