コード例 #1
0
ファイル: BuilderHelper.java プロジェクト: sergeyzsg/erlide
  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;
    }
  }
コード例 #2
0
ファイル: ErtsWatcher.java プロジェクト: zhonglihua/erlide
 private String createReport(final int v, final String msg) {
   final String plog = LogUtil.fetchPlatformLog();
   final String elog = LogUtil.fetchErlideLog();
   final String slog = LogUtil.fetchStraceLog(workingDir + "/" + nodeName + ".strace");
   final String delim = "\n==================================\n";
   final String reportFile = LogUtil.getReportFile();
   final File report = new File(reportFile);
   try {
     report.createNewFile();
     final OutputStream out = new FileOutputStream(report);
     final PrintWriter pw = new PrintWriter(out);
     try {
       pw.println(String.format(msg, nodeName, v));
       pw.println(System.getProperty("user.name"));
       pw.println(delim);
       pw.println(plog);
       pw.println(delim);
       pw.println(elog);
       if (slog.length() > 0) {
         pw.println(delim);
         pw.println(elog);
       }
     } finally {
       pw.flush();
       pw.close();
       out.close();
     }
   } catch (final IOException e) {
     ErlLogger.warn(e);
   }
   return reportFile;
 }
コード例 #3
0
ファイル: LogUtil.java プロジェクト: zhonglihua/erlide
 public static String fetchPlatformLog() {
   final List<String> result = new ArrayList<String>();
   final File log = Platform.getLogFileLocation().toFile();
   try {
     final BufferedReader reader =
         new BufferedReader(new InputStreamReader(new FileInputStream(log), "UTF-8"));
     try {
       for (; ; ) {
         String line = reader.readLine();
         if (line == null) {
           break;
         }
         line = line.trim();
         if (line.length() == 0) {
           continue;
         }
         if (line.startsWith("!SESSION ")) {
           result.clear();
         }
         result.add(line);
       }
     } finally {
       reader.close();
     }
   } catch (final Exception e) {
     ErlLogger.warn(e);
   }
   final StringBuffer buf = new StringBuffer();
   for (final String s : result) {
     buf.append(s).append('\n');
   }
   return buf.toString();
 }
コード例 #4
0
ファイル: LogUtil.java プロジェクト: zhonglihua/erlide
 public static String fetchErlideLog() {
   final StringBuffer result = new StringBuffer();
   final File log = new File(ErlLogger.getInstance().getLogLocation());
   try {
     final BufferedReader reader =
         new BufferedReader(new InputStreamReader(new FileInputStream(log), "UTF-8"));
     try {
       for (; ; ) {
         String line = reader.readLine();
         if (line == null) {
           break;
         }
         line = line.trim();
         if (line.length() == 0) {
           continue;
         }
         result.append(line).append('\n');
       }
     } finally {
       reader.close();
     }
   } catch (final Exception e) {
     ErlLogger.warn(e);
   }
   return result.toString();
 }
コード例 #5
0
ファイル: BuilderHelper.java プロジェクト: sergeyzsg/erlide
 public Collection<IPath> getIncludeDirs(
     final IProject project, final Collection<IPath> includeDirs) {
   final IErlProject erlProject = ErlModelManager.getErlangModel().getErlangProject(project);
   if (erlProject == null) {
     return includeDirs;
   }
   final Collection<IPath> projectIncludeDirs = erlProject.getIncludeDirs();
   final IPathVariableManager pvm = ResourcesPlugin.getWorkspace().getPathVariableManager();
   for (IPath inc : projectIncludeDirs) {
     inc = PluginUtils.resolvePVMPath(pvm, inc);
     if (inc.isAbsolute()) {
       includeDirs.add(inc);
     } else {
       final IFolder folder = project.getFolder(inc);
       if (folder != null) {
         final IPath location = folder.getLocation();
         if (location != null) {
           includeDirs.add(location);
         } else {
           ErlLogger.warn("No location for %s", folder);
         }
       }
     }
   }
   return includeDirs;
 }
コード例 #6
0
ファイル: BuilderHelper.java プロジェクト: sergeyzsg/erlide
  public void completeCompile(
      final IProject project,
      final IResource source,
      final OtpErlangObject compilationResult,
      final IBackend backend,
      final OtpErlangList compilerOptions) {
    if (compilationResult == null) {
      MarkerUtils.addProblemMarker(
          source, null, null, "Could not compile file", 0, IMarker.SEVERITY_ERROR);
      return;
    }
    final OtpErlangTuple t = (OtpErlangTuple) compilationResult;
    // ErlLogger.debug("** " + t);

    if ("ok".equals(((OtpErlangAtom) t.elementAt(0)).atomValue())) {
      final String beamf = source.getFullPath().removeFileExtension().lastSegment();
      InternalErlideBuilder.loadModule(project, beamf);
      refreshDirs(project, t.elementAt(2));
    } else {
      // ErlLogger.debug(">>>> compile error... %s\n   %s",
      // resource.getName(), t);
    }

    // process compilation messages
    if (t.elementAt(1) instanceof OtpErlangList) {
      final OtpErlangList l = (OtpErlangList) t.elementAt(1);
      MarkerUtils.addErrorMarkers(source, l);
    } else {
      ErlLogger.warn("bad result from builder: %s", t);
    }

    completeCompileForYrl(project, source, backend, compilerOptions);
  }
コード例 #7
0
ファイル: BuilderHelper.java プロジェクト: sergeyzsg/erlide
 public void compileYrl(
     final IProject project,
     final BuildResource resource,
     final IBackend b,
     final OtpErlangList compilerOptions) {
   final IRpcFuture res = startCompileYrl(project, resource.getResource(), b, compilerOptions);
   if (res == null) {
     ErlLogger.warn(
         "error compiling yrl file: " + resource.getResource().getProjectRelativePath());
     return;
   }
   try {
     completeCompile(project, resource.getResource(), res.get(), b, compilerOptions);
   } catch (final RpcException e) {
     ErlLogger.warn(e);
   }
 }
コード例 #8
0
 @Override
 public boolean performOk() {
   try {
     prefs.setAutoActivate(autoActivateButton.getSelection());
     final Integer i = new Integer(delayText.getText());
     prefs.setDelayInMS(i.intValue());
     prefs.setErlangTriggers(erlangTriggersText.getText());
     prefs.seteDocTriggers(eDocTriggersText.getText());
     prefs.store();
   } catch (final BackingStoreException e) {
     ErlLogger.warn(e);
   }
   return super.performOk();
 }
コード例 #9
0
 @Override
 protected void performDefaults() {
   prefs = new CodeAssistPreferences();
   try {
     prefs.load();
     if (autoActivateButton == null) {
       return;
     }
     autoActivateButton.setSelection(prefs.isAutoActivate());
     delayText.setText(Integer.toString(prefs.getDelayInMS()));
     erlangTriggersText.setText(prefs.getErlangTriggers());
     eDocTriggersText.setText(prefs.geteDocTriggers());
   } catch (final BackingStoreException e) {
     ErlLogger.warn(e);
   }
   super.performDefaults();
 }
コード例 #10
0
ファイル: BuilderHelper.java プロジェクト: sergeyzsg/erlide
  public IRpcFuture startCompileYrl(
      final IProject project,
      final IResource resource,
      final IBackend backend,
      final OtpErlangList compilerOptions) {
    // final IPath projectPath = project.getLocation();
    // final OldErlangProjectProperties prefs = new
    // OldErlangProjectProperties(project);

    MarkerUtils.deleteMarkers(resource);
    // try {
    // resource.deleteMarkers(PROBLEM_MARKER, true,
    // IResource.DEPTH_INFINITE);
    // } catch (final CoreException e1) {
    // }

    final IPath erl = getErlForYrl(resource);
    final IResource br = project.findMember(erl);

    // we should check timestamps, but yrl files are rare, so it doesn't
    // matter much

    try {
      if (br != null && br.exists()) {
        try {
          br.delete(true, null);
        } catch (final Exception e) {
          ErlLogger.warn(e);
        }
      }

      final String input = resource.getLocation().toString();
      final String output = resource.getLocation().removeFileExtension().toString();
      return InternalErlideBuilder.compileYrl(backend, input, output);
    } catch (final Exception e) {
      e.printStackTrace();
      return null;
    }
  }
コード例 #11
0
 boolean addAllErlangModules(final IErlElement elem) {
   if (elem instanceof IErlModule) {
     children.add(new DebugTreeItem(elem, this));
     return true;
   } else if (elem instanceof ErlOtpExternalReferenceEntryList) {
     return false;
   } else if (elem instanceof ErlExternalReferenceEntryList) {
     return false;
   } else if (elem instanceof ErlExternalReferenceEntry) {
     return false;
   } else if (elem instanceof IParent) {
     try {
       if (elem instanceof IErlFolder) {
         final IErlFolder f = (IErlFolder) elem;
         if (!f.isSourcePathParent()) {
           return false;
         }
       }
       if (elem instanceof IOpenable) {
         final IOpenable o = (IOpenable) elem;
         o.open(null);
       }
       final DebugTreeItem dti = new DebugTreeItem(elem, this);
       final IParent p = (IParent) elem;
       boolean addedAny = false;
       for (final IErlElement i : p.getChildren()) {
         addedAny |= dti.addAllErlangModules(i);
       }
       if (addedAny) {
         children.add(dti);
       }
       return true;
     } catch (final ErlModelException e) {
       ErlLogger.warn(e);
     }
   }
   return false;
 }
コード例 #12
0
ファイル: BuilderHelper.java プロジェクト: sergeyzsg/erlide
 private void completeCompileForYrl(
     final IProject project,
     final IResource source,
     final IBackend backend,
     final OtpErlangList compilerOptions) {
   final IPath erl = getErlForYrl(source);
   if (erl != null) {
     try {
       source.getParent().refreshLocal(IResource.DEPTH_ONE, null);
       final IResource br = project.findMember(erl);
       if (br != null) {
         br.setDerived(true, null);
         final BuildResource bbr = new BuildResource(br);
         // br.touch() doesn't work...
         final IErlProject erlProject = ErlModelManager.getErlangModel().getErlangProject(project);
         compileErl(
             project, bbr, erlProject.getOutputLocation().toString(), backend, compilerOptions);
       }
     } catch (final CoreException e) {
       ErlLogger.warn(e);
     }
   }
 }
コード例 #13
0
 @SuppressWarnings("unchecked")
 public OtpErlangList export() {
   final List<OtpErlangObject> result = new ArrayList<OtpErlangObject>();
   for (final CompilerOption option : CompilerOption.ALL_OPTIONS) {
     final Object optionValue = options.get(option);
     if (optionValue != null) {
       if (option instanceof BooleanOption) {
         final OtpErlangObject val =
             ((BooleanOption) option).toTerm(((Boolean) optionValue).booleanValue());
         if (val != null) {
           result.add(val);
         }
       } else if (option instanceof PathsOption) {
         final Iterable<String> value = (Iterable<String>) optionValue;
         final OtpErlangObject val = ((PathsOption) option).toTerm(value);
         result.add(val);
       } else if (option instanceof ModuleOption) {
         final String value = (String) optionValue;
         final OtpErlangObject val = ((ModuleOption) option).toTerm(value);
         result.add(val);
       } else {
         try {
           final OtpErlangList val =
               ((DefineOption) option).toTerm((List<Tuple<String, String>>) optionValue);
           if (val != null) {
             result.addAll(Lists.newArrayList(val.elements()));
           }
         } catch (final TermParserException e) {
           ErlLogger.warn(e);
         }
       }
     }
   }
   final OtpErlangList list = OtpErlang.mkList(result);
   return list;
 }