Exemplo n.º 1
0
  private void runJavaProcessInProject(
      TmcProjectInfo projectInfo,
      ClassPath classPath,
      String taskName,
      List<String> args,
      InputOutput inOut,
      BgTaskListener<ProcessResult> listener) {
    FileObject projectDir = projectInfo.getProjectDir();

    JavaPlatform platform =
        JavaPlatform.getDefault(); // Should probably use project's configured platform instead

    FileObject javaExe = platform.findTool("java");
    if (javaExe == null) {
      throw new IllegalArgumentException();
    }

    // TMC server packages this with every exercise for our convenience.
    // True even for Maven exercises, at least until NB's Maven API is published.
    ClassPath testRunnerClassPath = getTestRunnerClassPath(projectInfo);

    if (testRunnerClassPath != null) {
      classPath = ClassPathSupport.createProxyClassPath(classPath, testRunnerClassPath);
    }

    String[] command = new String[3 + args.size()];
    command[0] = FileUtil.toFile(javaExe).getAbsolutePath();
    command[1] = "-cp";
    command[2] = classPath.toString(ClassPath.PathConversionMode.WARN);
    System.arraycopy(args.toArray(new String[args.size()]), 0, command, 3, args.size());

    log.info(StringUtils.join(command, ' '));
    ProcessRunner runner = new ProcessRunner(command, FileUtil.toFile(projectDir), inOut);
    BgTask.start(taskName, runner, listener);
  }
Exemplo n.º 2
0
  public void reparse(Snapshot snapshot, String content) throws ParseException {
    LOG.warning("Thread id " + Thread.currentThread().getId());
    LOG.warning("Parsing document " + (count++));

    this.snapshot = snapshot;

    // mirahParser = new mirah.impl.MirahParser ();
    // mirahParser.parse(snapshot.getText().toString());
    diag = new MirahParseDiagnostics();
    Mirahc compiler = new Mirahc();

    // Project proj = snapshot.getSource().getFileObject().getLookup().lookup(Project.class);
    FileObject src = snapshot.getSource().getFileObject();
    // LOG.warning("Source file is "+src);
    ClassPath compileClassPath = ClassPath.getClassPath(src, ClassPath.COMPILE);
    // LOG.warning("Project directory is "+proj.getProjectDirectory().getName());
    // LOG.warning("Parsing classpath is "+compileClassPath.toString());

    ClassPath buildClassPath = ClassPath.getClassPath(src, ClassPath.EXECUTE);

    // LOG.warning("Execute classapth is "+buildClassPath.toString());

    ClassPath srcClassPath = ClassPath.getClassPath(src, ClassPath.SOURCE);
    // LOG.warning("Src classapth is "+srcClassPath.toString());

    compiler.setDestination(buildClassPath.toString());
    compiler.setDiagnostics(diag);

    List<String> paths = new ArrayList<String>();
    if (!"".equals(srcClassPath.toString())) {
      paths.add(srcClassPath.toString());
    }
    if (!"".equals(buildClassPath.toString())) {
      paths.add(buildClassPath.toString());
    }
    if (!"".equals(compileClassPath.toString())) {
      paths.add(compileClassPath.toString());
    }

    StringBuilder classPath = new StringBuilder();
    for (String path : paths) {
      classPath.append(path);
      classPath.append(File.pathSeparator);
    }

    String cp = ".";
    if (classPath.length() >= 1) {
      cp = classPath.toString().substring(0, classPath.length() - 1);
    }
    compiler.setClasspath(cp);
    DocumentDebugger debugger = new DocumentDebugger();

    compiler.setDebugger(debugger);

    ClassPath bootClassPath = ClassPath.getClassPath(src, ClassPath.BOOT);
    if (!"".equals(bootClassPath.toString())) {
      compiler.setBootClasspath(bootClassPath.toString());
    }
    String srcText = content;

    compiler.addFakeFile(src.getPath(), srcText);

    try {
      compiler.compile(new String[0]);
    } catch (Exception ex) {
      ex.printStackTrace();
    }
    LOG.warning("Finished parsing document");

    synchronized (documentDebuggers) {
      LOG.warning("Inside sync documentDebuggers");
      Document doc = snapshot.getSource().getDocument(true);
      LOG.warning("Resolved types " + debugger.resolvedTypes);
      if (debugger.resolvedTypes.size() > 0) {
        debugger.compiler = compiler;
        LOG.warning("NEW DOCUMENT DEBUGGER ADDED");
        documentDebuggers.put(doc, debugger);
        fireOnParse(doc);
      }
    }
  }