Esempio n. 1
0
 private boolean waitForCodeServer() {
   try {
     OtpErlangObject r;
     int i = 30;
     boolean gotIt = false;
     do {
       r = call("erlang", "whereis", "a", "code_server");
       gotIt = !(r instanceof OtpErlangPid);
       if (!gotIt) {
         try {
           Thread.sleep(200);
         } catch (final InterruptedException e) {
         }
       }
       i--;
     } while (gotIt && i > 0);
     if (gotIt) {
       ErlLogger.error("code server did not start in time for %s", getNodeName());
       return false;
     }
     ErlLogger.debug("code server started");
     return true;
   } catch (final Exception e) {
     ErlLogger.error("error starting code server for %s: %s", getNodeName(), e.getMessage());
     return false;
   }
 }
Esempio n. 2
0
    private void findRefs(
        final IErlModule theModule, final ITextSelection aSelection, final boolean hasChanged) {
      final IBackend ideBackend = BackendCore.getBackendManager().getIdeBackend();
      fRefs = null;

      if (fCanceled) {
        return;
      }
      try {
        final int offset = aSelection.getOffset();
        final OpenResult res =
            ErlideOpen.open(
                ideBackend.getRpcSite(),
                theModule,
                offset,
                ModelUtils.getImportsAsList(theModule),
                "",
                ErlModelManager.getErlangModel().getPathVars());
        final ErlangSearchPattern pattern =
            SearchUtil.getSearchPatternFromOpenResultAndLimitTo(
                theModule, offset, res, LimitTo.ALL_OCCURRENCES, false);
        if (fCanceled) {
          return;
        }
        if (pattern != null) {
          final ErlSearchScope scope = new ErlSearchScope();
          scope.addModule(theModule);
          final List<ModuleLineFunctionArityRef> findRefs = Lists.newArrayList();
          // TODO: run in background? for large files, this can take
          // seconds
          final OtpErlangObject refs =
              ErlideSearchServer.findRefs(
                  ideBackend.getRpcSite(), pattern, scope, erlangEditor.getStateDir(), true);
          if (refs != null) {
            SearchUtil.addSearchResult(findRefs, refs);
            fRefs = erlangEditor.markOccurencesHandler.getErlangRefs(theModule, findRefs);
          }
        }
      } catch (final RpcTimeoutException e) {
        if (!ideBackend.isStopped()) {
          ErlLogger.warn(e);
        }
      } catch (final RpcException e) {
        ErlLogger.debug(e);
      } catch (final ErlModelException e) {
        ErlLogger.debug(e);
      } catch (final OtpErlangRangeException e) {
        ErlLogger.debug(e);
      }
      if (fRefs == null) {
        if (!erlangEditor.markOccurencesHandler.fStickyOccurrenceAnnotations) {
          erlangEditor.markOccurencesHandler.removeOccurrenceAnnotations();
        } else if (hasChanged) {
          erlangEditor.markOccurencesHandler.removeOccurrenceAnnotations();
        }
      }
    }
Esempio n. 3
0
 @Override
 public void reconcile(final ErlDirtyRegion r) {
   if (fModule != null) {
     ErlLogger.debug("## reconcile " + fModule.getName());
     fModule.reconcileText(r.getOffset(), r.getLength(), r.getText(), mon);
   }
 }
Esempio n. 4
0
 private void wait_for_epmd(final String host) throws BackendException {
   // If anyone has a better solution for waiting for epmd to be up, please
   // let me know
   int tries = 50;
   boolean ok = false;
   do {
     Socket s;
     try {
       s = new Socket(host, EPMD_PORT);
       s.close();
       ok = true;
     } catch (final IOException e) {
     }
     try {
       Thread.sleep(100);
       // ErlLogger.debug("sleep............");
     } catch (final InterruptedException e1) {
     }
     tries--;
   } while (!ok && tries > 0);
   if (!ok) {
     final String msg =
         "Couldn't contact epmd - erlang backend is probably not working\n"
             + "  Possibly your host's entry in /etc/hosts is wrong ("
             + host
             + ").";
     ErlLogger.error(msg);
     throw new BackendException(msg);
   }
 }
Esempio n. 5
0
 public static void delete(final IRpcSite fBackend, final String moduleName) {
   try {
     fBackend.call("code", "delete", "a", moduleName);
   } catch (final Exception e) {
     ErlLogger.debug(e);
   }
 }
Esempio n. 6
0
 private void tryConnect() throws RpcException {
   synchronized (connectLock) {
     switch (state) {
       case DISCONNECTED:
         reported = false;
         if (connectRetry()) {
           state = State.CONNECTED;
         } else if (connectOnce) {
           state = State.DOWN;
         } else {
           state = State.DISCONNECTED;
         }
         break;
       case CONNECTED:
         break;
       case DOWN:
         try {
           if (process != null) {
             process.terminate();
           }
         } catch (final DebugException e) {
           ErlLogger.info(e);
         }
         // TODO restart it??
         // process =
         if (!stopped) {
           final String msg = reportRuntimeDown(data.getNodeName());
           throw new RpcException(msg);
         }
     }
   }
 }
Esempio n. 7
0
 public static void addPathZ(final IRpcSite backend, final String path) {
   try {
     backend.call("code", "add_pathz", "s", path);
   } catch (final Exception e) {
     ErlLogger.debug(e);
   }
 }
Esempio n. 8
0
 @Override
 public void initialReconcile() {
   fModule = fEditor != null ? fEditor.getModule() : null;
   ErlLogger.debug("## initial reconcile " + (fModule != null ? fModule.getName() : ""));
   if (fModule != null) {
     fModule.initialReconcile();
   }
   // notify(new OtpErlangAtom("initialReconcile"));
 }
Esempio n. 9
0
 private boolean connectRetry() {
   int tries = MAX_RETRIES;
   boolean ok = false;
   while (!ok && tries > 0) {
     ErlLogger.debug("# ping..." + getNodeName() + " " + Thread.currentThread().getName());
     ok = localNode.ping(getNodeName(), RETRY_DELAY + (MAX_RETRIES - tries) * RETRY_DELAY % 3);
     tries--;
   }
   return ok;
 }
Esempio n. 10
0
 public static void load(final IRpcSite backend, String name) {
   if (name.endsWith(".beam")) {
     name = name.substring(0, name.length() - 5);
   }
   try {
     backend.call("c", "l", "a", name);
   } catch (final Exception e) {
     ErlLogger.debug(e);
   }
 }
Esempio n. 11
0
 private List<IProject> gatherProjects(final String[] projectNames) {
   final List<IProject> myProjects = Lists.newArrayList();
   for (final String s : projectNames) {
     final IProject project = ResourcesPlugin.getWorkspace().getRoot().getProject(s);
     if (project == null) {
       ErlLogger.error("Launch: project not found: '%s'!", s);
       continue;
     }
     myProjects.add(project);
   }
   return myProjects;
 }
Esempio n. 12
0
 @Override
 public Object[] getChildren(final Object parent) {
   if (parent instanceof IParent) {
     final IParent p = (IParent) parent;
     try {
       return p.getChildren().toArray();
     } catch (final ErlModelException x) {
       if (!x.isDoesNotExist()) {
         ErlLogger.debug("element missing: " + x.getMessage());
       }
     }
   }
   return NO_CHILDREN;
 }
Esempio n. 13
0
 private void fillProcessesList(final TableViewer tableViewer) {
   final IProgressService ps = PlatformUI.getWorkbench().getProgressService();
   try {
     ps.busyCursorWhile(
         new IRunnableWithProgress() {
           @Override
           public void run(final IProgressMonitor pm) {
             final TracedProcess[] processesList = ProcessHelper.getProcsOnTracedNodes();
             TraceBackend.getInstance().setProcesses(processesList);
           }
         });
   } catch (final Exception e) {
     ErlLogger.error(e);
   }
 }
Esempio n. 14
0
 public static void removePath(final IRpcSite backend, String path) {
   try {
     // workaround for bug in code:del_path
     try {
       final OtpErlangObject rr =
           backend.call("filename", "join", "x", new OtpErlangList(new OtpErlangString(path)));
       path = ((OtpErlangString) rr).stringValue();
     } catch (final Exception e) {
       // ignore
     }
     backend.call("code", "del_path", "s", path);
   } catch (final Exception e) {
     ErlLogger.debug(e);
   }
 }
Esempio n. 15
0
 @Override
 public void launch(final ISelection selection, final String mode) {
   ErlLogger.debug("** Launch:: " + selection.toString());
   if (selection.isEmpty()) {
     return;
   }
   if (!(selection instanceof IStructuredSelection)) {
     return;
   }
   final Set<IErlProject> projects = Sets.newHashSet();
   final IStructuredSelection structuredSelection = (IStructuredSelection) selection;
   for (final Object element : structuredSelection.toArray()) {
     if (!(element instanceof IResource)) {
       return;
     }
     final IErlElement erlElement =
         ErlModelManager.getErlangModel().findElement((IResource) element);
     final IErlProject project = ModelUtils.getProject(erlElement);
     if (project != null) {
       projects.add(project);
     }
   }
   if (projects.isEmpty()) {
     return;
   }
   projects.addAll(getDependentProjects(projects));
   final List<IErlProject> projectList = Lists.newArrayList(projects);
   Collections.sort(
       projectList,
       new Comparator<IErlProject>() {
         @Override
         public int compare(final IErlProject o1, final IErlProject o2) {
           return o1.getName().compareTo(o2.getName());
         }
       });
   try {
     doLaunch(mode, projectList);
   } catch (final CoreException e) {
     final IWorkbench workbench = PlatformUI.getWorkbench();
     final Shell shell = workbench.getActiveWorkbenchWindow().getShell();
     MessageDialog.openError(shell, "Error", e.getStatus().getMessage());
   }
 }
Esempio n. 16
0
 @Override
 public Object execute(final ExecutionEvent event) throws ExecutionException {
   // final Command command = event.getCommand();
   // final boolean oldValue = HandlerUtil.toggleCommandState(command);
   final String filterId = event.getParameter("org.erlide.ui.filterId");
   final IEclipsePreferences prefsNode = ErlangOutlinePage.getPrefsNode();
   final boolean oldValue = prefsNode.getBoolean(filterId, false);
   final boolean value = !oldValue;
   final Object activePart = HandlerUtil.getVariable(event, "activePart");
   if (activePart instanceof ContentOutline) {
     OutlineFilterUtils.addFilter(filterId, value, activePart);
   }
   prefsNode.putBoolean(filterId, value);
   try {
     prefsNode.flush();
   } catch (final BackingStoreException e) {
     ErlLogger.error(e);
   }
   return null;
 }
Esempio n. 17
0
 @Override
 public void launch(final IEditorPart editor, final String mode) {
   ErlLogger.debug("** Launch :: " + editor.getTitle());
   if (editor instanceof ErlangEditor) {
     final ErlangEditor erlangEditor = (ErlangEditor) editor;
     final IErlModule module = erlangEditor.getModule();
     if (module != null) {
       final IErlProject project = ModelUtils.getProject(module);
       if (project != null) {
         try {
           doLaunch(mode, Lists.newArrayList(project));
         } catch (final CoreException e) {
           final IWorkbench workbench = PlatformUI.getWorkbench();
           final Shell shell = workbench.getActiveWorkbenchWindow().getShell();
           MessageDialog.openError(shell, "Error", e.getStatus().getMessage());
         }
       }
     }
   }
 }
Esempio n. 18
0
 public void startLocalNode() {
   boolean nodeCreated = false;
   synchronized (localNodeLock) {
     int i = 0;
     do {
       try {
         i++;
         localNode = ErlRuntime.createOtpNode(data.getCookie(), data.hasLongName());
         localNode.registerStatusHandler(statusWatcher);
         nodeCreated = true;
       } catch (final IOException e) {
         ErlLogger.error("ErlRuntime could not be created (%s), retrying %d", e.getMessage(), i);
         try {
           localNodeLock.wait(300);
         } catch (final InterruptedException e1) {
         }
       }
     } while (!nodeCreated && i < 10);
   }
 }
Esempio n. 19
0
 /** Method called when stopping tracing. */
 private void doStopTracing() {
   task =
       new RunnableWithProgress("Loading trace results...") {
         @Override
         public void doAction() {
           TraceBackend.getInstance().stop();
         }
       };
   try {
     final Shell shell = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell();
     new ProgressMonitorDialog(shell).run(true, false, task);
     startStopAction.setImageDescriptor(
         DebugUITools.getImageDescriptor(IDebugUIConstants.IMG_ACT_RUN));
     startStopAction.setToolTipText(START_LABEL);
     startStopAction.setEnabled(true);
     TracingStatusHandler.handleStatus(status);
   } catch (final Exception e) {
     ErlLogger.error(e);
   } finally {
     task = null;
   }
 }
Esempio n. 20
0
 public static String loadPreviewContentFromFile(final Class<?> clazz, final String filename) {
   String line;
   final String separator = System.getProperty("line.separator"); // $NON-NLS-1$
   final StringBuilder buffer = new StringBuilder(512);
   BufferedReader reader = null;
   try {
     reader = new BufferedReader(new InputStreamReader(clazz.getResourceAsStream(filename)));
     while ((line = reader.readLine()) != null) {
       buffer.append(line);
       buffer.append(separator);
     }
   } catch (final IOException io) {
     ErlLogger.error(io);
   } finally {
     if (reader != null) {
       try {
         reader.close();
       } catch (final IOException e) {
       }
     }
   }
   return buffer.toString();
 }
Esempio n. 21
0
  @Override
  public void connect() {
    final String label = getNodeName();
    ErlLogger.debug(label + ": waiting connection to peer...");
    try {
      wait_for_epmd();
      eventBox = createMbox("rex");

      if (waitForCodeServer()) {
        ErlLogger.debug("connected!");
      } else {
        ErlLogger.error(COULD_NOT_CONNECT_TO_BACKEND);
      }

    } catch (final BackendException e) {
      ErlLogger.error(e);
      ErlLogger.error(COULD_NOT_CONNECT_TO_BACKEND);
    } catch (final Exception e) {
      ErlLogger.error(e);
      ErlLogger.error(COULD_NOT_CONNECT_TO_BACKEND);
    }
  }
Esempio n. 22
0
 @Override
 public void reconcile(final IRegion partition) {
   ErlLogger.error("reconcile called");
 }
Esempio n. 23
0
 private static void debugPrintCookie(final String cookie) {
   final int len = cookie.length();
   final String trimmed = len > 7 ? cookie.substring(0, 7) : cookie;
   ErlLogger.debug("using cookie '%s...'%d (info: '%s')", trimmed, len, cookie);
 }
Esempio n. 24
0
 @Override
 public void reconcile(final DirtyRegion dirtyRegion, final IRegion subRegion) {
   ErlLogger.error("reconcile called");
 }