Exemplo n.º 1
0
  /*
   * (non-Javadoc)
   *
   * @see
   * org.eclipse.swt.events.SelectionListener#widgetSelected(org.eclipse.swt
   * .events.SelectionEvent)
   */
  public void widgetSelected(final SelectionEvent e) {
    ErlLogger.debug("widgetSelected: e.item = " + e.item);
    ErlLogger.debug("widgetSelected: e.widget = " + e.widget);

    if (e.widget == removeFunctionBtn) {
      final TableItem itemsToRemove[] = fTable.getSelection();
      for (final TableItem element : itemsToRemove) {
        fTable.remove(fTable.indexOf(element));
        if (element == fEditingItem) {
          fEditingItem = null;
        }
      }

    } else if (e.widget == editFunctionBtn) {
      if (fEditingItem != null) {
        removeEdit();
      }
      final int selectedIndex = fTable.getSelectionIndex();
      final TableItem selectedItem = fTable.getItem(selectedIndex);
      if (!"".equals(selectedItem.getText(0))) {
        fEditingItem = selectedItem;
        functionNameText.setText(selectedItem.getText(0));
        arityText.setText(selectedItem.getText(1));
        exportButtonBtn.setSelection(selectedItem.getChecked());
        fEditingItem.setText(0, selectedItem.getText(0) + "<<Being Edited>>");
      }
      // } else if (e.widget == addState) {

    }
    dialogChanged();
  }
Exemplo n.º 2
0
  @Override
  protected void clean(final IProgressMonitor monitor) throws CoreException {
    final IProject currentProject = getProject();
    if (currentProject == null || !currentProject.isAccessible()) {
      return;
    }

    if (BuilderHelper.isDebugging()) {
      ErlLogger.debug(
          "Cleaning "
              + currentProject.getName() // $NON-NLS-1$
              + " @ "
              + new Date(System.currentTimeMillis()));
    }

    try {
      initializeBuilder(monitor);
      MarkerUtils.removeProblemsAndTasksFor(currentProject);
      final IErlProject erlProject = CoreScope.getModel().getErlangProject(currentProject);
      final IFolder bf = currentProject.getFolder(erlProject.getOutputLocation());
      if (bf.exists()) {
        final IResource[] beams = bf.members();
        monitor.beginTask("Cleaning Erlang files", beams.length);
        if (beams.length > 0) {
          final float delta = 1.0f / beams.length;
          for (final IResource element : beams) {
            if ("beam".equals(element.getFileExtension())) {
              element.delete(true, monitor);
              notifier.updateProgressDelta(delta);
            }
          }
        }
      }

    } catch (final Exception e) {
      ErlLogger.error(e);
      final String msg =
          NLS.bind(BuilderMessages.build_inconsistentProject, e.getLocalizedMessage());
      MarkerUtils.addProblemMarker(currentProject, null, null, msg, 0, IMarker.SEVERITY_ERROR);
    } finally {
      cleanup();
      if (BuilderHelper.isDebugging()) {
        ErlLogger.debug(
            "Finished cleaning "
                + currentProject.getName() // $NON-NLS-1$
                + " @ "
                + new Date(System.currentTimeMillis()));
      }
    }
  }
Exemplo n.º 3
0
  @Override
  public IBackend createBackend(final BackendData data) {
    ErlLogger.debug("Create backend " + data.getNodeName());
    if (!data.isManaged() && !data.isAutostart()) {
      ErlLogger.info("Not creating backend for %s", data.getNodeName());
      return null;
    }

    final IBackend b;
    final String erlangHostName = HostnameUtils.getErlangHostName(data.isLongName());
    try {
      String nodeName = data.getNodeName();
      final boolean hasHost = nodeName.contains("@");
      nodeName = hasHost ? nodeName : nodeName + "@" + erlangHostName;
      ILaunch launch = data.getLaunch();
      if (launch == null) {
        launch = launchPeer(data);
      }
      final IProcess mainProcess =
          launch.getProcesses().length == 0 ? null : launch.getProcesses()[0];
      final IErlRuntime runtime =
          new ErlRuntime(
              nodeName, data.getCookie(), mainProcess, !data.isTransient(), data.isLongName());
      b =
          data.isInternal()
              ? new InternalBackend(data, runtime)
              : new ExternalBackend(data, runtime);
      b.initialize();
      return b;
    } catch (final BackendException e) {
      e.printStackTrace();
    }
    return null;
  }
Exemplo n.º 4
0
    public boolean handleEvent(final OtpErlangObject msg) {
      notifier.checkCancel();

      ErlLogger.debug(">>> %s", msg);
      if (msg instanceof OtpErlangTuple) {
        try {
          final OtpErlangTuple tuple = (OtpErlangTuple) msg;
          final OtpErlangAtom akey = (OtpErlangAtom) tuple.elementAt(0);
          final String key = akey.atomValue();
          // final OtpErlangObject value = tuple.elementAt(1);

          if ("compile".equals(key)) {
            // value = {ok, Messages, Files} | {error, Messages}
            // TODO create markers for messages
            // TODO refresh Files and mark as derived
          }
          if ("tasks".equals(key)) {
            // value = [Task]
            // TODO create tasks for Tasks
          }
          if ("clash".equals(key)) {
            // value = [Clash]
            // TODO create markers for clashes
          }
        } catch (final Exception e) {
          // ignore?
        }
      }
      return msg.equals(new OtpErlangAtom("stop"));
    }
Exemplo n.º 5
0
 private Set<String> getResourcesToBuild(
     final int kind, @SuppressWarnings("rawtypes") final Map args, final IProject project)
     throws CoreException {
   Set<BuildResource> result = Sets.newHashSet();
   final IProgressMonitor submon = new NullProgressMonitor();
   // new SubProgressMonitor(monitor, 10);
   submon.beginTask("retrieving resources to build", IProgressMonitor.UNKNOWN);
   if (kind == FULL_BUILD) {
     result = helper.getAffectedResources(args, project, submon);
   } else {
     final IResourceDelta delta = getDelta(project);
     final Path path = new Path(".settings/org.erlide.core.prefs");
     if (delta.findMember(path) != null) {
       ErlLogger.info("project configuration changed: doing full rebuild");
       result = helper.getAffectedResources(args, project, submon);
     } else {
       result = helper.getAffectedResources(args, delta, submon);
     }
   }
   if (BuilderHelper.isDebugging()) {
     ErlLogger.debug(
         "Will compile %d resource(s): %s", Integer.valueOf(result.size()), result.toString());
   }
   submon.done();
   final Set<String> paths = new HashSet<String>();
   for (final BuildResource res : result) {
     paths.add(res.getResource().getLocation().toPortableString());
   }
   return paths;
 }
Exemplo n.º 6
0
  public IRpcFuture startCompileErl(
      final IProject project,
      final BuildResource bres,
      final String outputDir0,
      final IBackend backend,
      final OtpErlangList compilerOptions,
      final boolean force) {
    final IPath projectPath = project.getLocation();
    final IResource res = bres.getResource();
    final String s = res.getFileExtension();
    if (!"erl".equals(s)) {
      ErlLogger.warn("trying to compile " + res.getName() + "?!?!");
    }

    MarkerUtils.deleteMarkers(res);

    String outputDir;
    outputDir = getRealOutputDir(bres, outputDir0, projectPath);

    final Collection<IPath> includeDirs = getAllIncludeDirs(project);

    // delete beam file
    final IPath beamPath = getBeamForErl(res);
    final IResource beam = project.findMember(beamPath);

    try {
      final boolean shouldCompile = force || shouldCompile(project, res, beam);

      if (shouldCompile) {
        if (beam != null) {
          try {
            beam.delete(true, null);
          } catch (final Exception e) {
            ErlLogger.warn(e);
          }
        }
        if (isDebugging()) {
          ErlLogger.debug("compiling %s", res.getName());
        }

        createTaskMarkers(project, res);
        return InternalErlideBuilder.compileErl(
            backend, res.getLocation(), outputDir, includeDirs, compilerOptions);

      } else {
        return null;
      }
    } catch (final Exception e) {
      ErlLogger.warn(e);
      return null;
    }
  }
Exemplo n.º 7
0
  public void checkForClashes(final IBackend backend, final IProject project) {
    try {
      final OtpErlangList res = InternalErlideBuilder.getCodeClashes(backend);
      for (final OtpErlangObject elem : res) {
        final OtpErlangTuple t = (OtpErlangTuple) elem;
        final String f1 = ((OtpErlangString) t.elementAt(0)).stringValue();
        final String f2 = ((OtpErlangString) t.elementAt(1)).stringValue();

        // add marker only for modules belonging to this project!
        final IResource r1 = project.findMember(f1);
        final IResource r2 = project.findMember(f2);
        if (r1 != null || r2 != null) {
          MarkerUtils.addMarker(
              project,
              null,
              project,
              "Code clash between " + f1 + " and " + f2,
              0,
              IMarker.SEVERITY_WARNING,
              "");
        }
      }

    } catch (final Exception e) {
    }
    try {
      final IErlProject erlProject = ErlModelManager.getErlangModel().getErlangProject(project);
      final Collection<IPath> sd = erlProject.getSourceDirs();
      final String[] dirList = new String[sd.size()];
      int j = 0;
      for (final IPath sp : sd) {
        dirList[j++] = project.getLocation().toPortableString() + "/" + sp;
      }
      final OtpErlangList res = InternalErlideBuilder.getSourceClashes(backend, dirList);
      for (int i = 0; i < res.arity(); i++) {
        final OtpErlangTuple t = (OtpErlangTuple) res.elementAt(i);
        final String f1 = ((OtpErlangString) t.elementAt(0)).stringValue();
        final String f2 = ((OtpErlangString) t.elementAt(1)).stringValue();
        MarkerUtils.addMarker(
            project,
            null,
            project,
            "Duplicated module name in " + f1 + " and " + f2,
            0,
            IMarker.SEVERITY_WARNING,
            "");
      }
    } catch (final Exception e) {
      ErlLogger.debug(e);
    }
  }
Exemplo n.º 8
0
 @Override
 public IBackend createBuildBackend(final RuntimeInfo info) {
   ErlLogger.debug("Create build backend " + info.getVersion().asMajor().toString());
   return createBackend(getBuildBackendData(info));
 }
Exemplo n.º 9
0
 @Override
 public IBackend createIdeBackend() {
   ErlLogger.debug("Create ide backend");
   return createBackend(getIdeBackendData());
 }
Exemplo n.º 10
0
  @Override
  protected IProject[] build(
      final int kind, @SuppressWarnings("rawtypes") final Map args, final IProgressMonitor monitor)
      throws CoreException {
    final IProject project = getProject();
    if (project == null || !project.isAccessible()) {
      return new IProject[0];
    }

    if (BuilderHelper.isDebugging()) {
      ErlLogger.debug(
          "Starting build "
              + helper.buildKind(kind)
              + " of "
              + project.getName()
              + " @ "
              + new Date(System.currentTimeMillis()));
    }
    try {
      MarkerUtils.deleteMarkers(project);
      initializeBuilder(monitor);

      final OtpErlangList compilerOptions = CompilerPreferences.get(project);

      ErlLogger.debug("******** building %s: %s", getProject().getName(), compilerOptions);

      final Set<String> resourcesToBuild = getResourcesToBuild(kind, args, project);
      final int n = resourcesToBuild.size();
      if (n > 0) {
        final IBackend backend = BackendCore.getBackendManager().getBuildBackend(project);
        if (backend == null) {
          final String message =
              "No backend with the required " + "version could be found. Can't build.";
          MarkerUtils.addProblemMarker(project, null, null, message, 0, IMarker.SEVERITY_ERROR);
          throw new BackendException(message);
        }

        notifier.setProgressPerCompilationUnit(1.0f / n);

        final IPath projectPath = project.getLocation();
        final IErlProject erlProject = CoreScope.getModel().getErlangProject(project);
        final String outputDir = projectPath.append(erlProject.getOutputLocation()).toString();
        helper.ensureDirExists(outputDir);

        final Collection<IPath> includeDirs = helper.getAllIncludeDirs(project);

        final RpcEventProcessor processor =
            new RpcEventProcessor(new BuildHandler(), backend.createMbox());
        final OtpErlangPid watcher = processor.getPid();
        final OtpErlangPid builder =
            (OtpErlangPid)
                backend.call(
                    "erlide_builder",
                    "build_resources",
                    "lsslsxp",
                    resourcesToBuild,
                    outputDir,
                    includeDirs,
                    compilerOptions,
                    watcher);
        processor.setStarter(builder);
        processor.run();
      }

    } catch (final Exception e) {
      ErlLogger.error(e);
      final String msg =
          NLS.bind(BuilderMessages.build_inconsistentProject, e.getLocalizedMessage());
      MarkerUtils.addProblemMarker(project, null, null, msg, 0, IMarker.SEVERITY_ERROR);
    } finally {
      cleanup();
      if (BuilderHelper.isDebugging()) {
        ErlLogger.debug(
            "Finished build of "
                + project.getName() // $NON-NLS-1$
                + " @ "
                + new Date(System.currentTimeMillis()));
      }
    }
    return null;
  }