private Callable<Integer> startCompilingMavenProject(TmcProjectInfo projectInfo) {
    File projectDir = projectInfo.getProjectDirAsFile();

    String goal = "test-compile";
    final InputOutput inOut = IOProvider.getDefault().getIO(projectInfo.getProjectName(), false);

    final ProcessRunner runner =
        new MavenRunBuilder()
            .setProjectDir(projectDir)
            .addGoal(goal)
            .setIO(inOut)
            .createProcessRunner();

    return new Callable<Integer>() {
      @Override
      public Integer call() throws Exception {
        try {
          ProcessResult result = runner.call();
          int ret = result.statusCode;
          if (ret != 0) {
            inOut.select();
          }
          return ret;
        } catch (Exception ex) {
          inOut.select();
          throw ex;
        }
      }
    };
  }
  private Callable<Integer> startCompilingMakefileProject(TmcProjectInfo projectInfo) {
    /* This solution is pretty much copied from the pre-existing Maven option.
     * I have no idea how well it will work, but this is a start.
     * --kviiri */
    Project project = projectInfo.getProject();
    FileObject makeFile = project.getProjectDirectory().getFileObject("Makefile");
    File workDir = projectInfo.getProjectDirAsFile();

    if (makeFile == null) {
      throw new RuntimeException("Project has no Makefile");
    }
    String[] command = {"make", "test"};

    final InputOutput io = IOProvider.getDefault().getIO(projectInfo.getProjectName(), false);
    final ProcessRunner runner = new ProcessRunner(command, workDir, io);
    return new Callable<Integer>() {
      @Override
      public Integer call() throws Exception {
        try {
          ProcessResult result = runner.call();
          int ret = result.statusCode;
          if (ret != 0) {
            io.select();
          }
          return ret;
        } catch (Exception ex) {
          io.select();
          throw ex;
        }
      }
    };
  }
/** @author normenhansen */
public class ApplicationLogHandler extends Handler {

  InputOutput io = IOProvider.getDefault().getIO("Application", true);
  JmeFormatter formatter = new JmeFormatter();

  public ApplicationLogHandler() {
    io.setErrSeparated(true);
  }

  @Override
  public void publish(LogRecord record) {
    if (record.getLevel().equals(Level.SEVERE)) {
      io.getErr().println(formatter.formatMessage(record));
    } else if (record.getLevel().equals(Level.WARNING)) {
      io.getErr().println(formatter.formatMessage(record));
    } else if (record.getLevel().equals(Level.INFO)) {
      io.getOut().println(formatter.formatMessage(record));
    } else {
      io.getOut().println(formatter.formatMessage(record));
    }
  }

  @Override
  public void flush() {
    //        throw new UnsupportedOperationException("Not supported yet.");
  }

  @Override
  public void close() throws SecurityException {
    io.getOut().close();
    io.getErr().close();
    //        throw new UnsupportedOperationException("Not supported yet.");
  }
}
示例#4
0
 private void actionFindPlugins() throws FileNotFoundException, IOException {
   String keywords = fieldKeywords.getText();
   IOProvider.getDefault().getIO("Output", false).getOut().println("Keywords: " + keywords);
   if (keywords == null || keywords.trim().equals("") || keywords.equals("all")) {
     findAllPlugins();
   } else {
     findPlugins(getKeywords(fieldKeywords.getText()));
   }
 }
 private InputOutput getIoTab() {
   InputOutput inOut = IOProvider.getDefault().getIO("Test output", false);
   try {
     inOut.getOut().reset();
   } catch (IOException e) {
     // Ignore
   }
   if (inOut.isClosed()) {
     inOut.select();
   }
   return inOut;
 }
 @Override
 public double[][] read(int length) throws EEAException {
   //        System.out.println("===" + length);
   //        return new double[][]{
   //            gen(100, 3, 200, 32000),
   //            gen(100, 3, 500, 32000),
   //            gen(100, 3, 800, 32000)};
   InputOutput io = IOProvider.getDefault().getIO("TCP", false);
   ServerSocket ss = null;
   Socket sc = null;
   double v[] = null;
   double x[] = null;
   double y[] = null;
   double z[] = null;
   do {
     try {
       ss = new ServerSocket(port);
       sc = ss.accept();
       BufferedReader br = new BufferedReader(new InputStreamReader(sc.getInputStream()));
       String readLine = br.readLine();
       String split[] = readLine.split(":");
       if (split[0].equals("v")) {
         v = sp(split[1]);
       } else if (split[0].equals("x")) {
         x = sp(split[1]);
       } else if (split[0].equals("y")) {
         y = sp(split[1]);
       } else if (split[0].equals("z")) {
         z = sp(split[1]);
       }
       //            DataPacket packet = new DataPacket(readLine);
       //            return packet.getData();
     } catch (IOException ex) {
       Logger.getLogger(TCPDevice.class.getName()).log(Level.SEVERE, null, ex);
       throw new EEAException(ex);
     } finally {
       try {
         sc.close();
         ss.close();
       } catch (IOException ex) {
         Exceptions.printStackTrace(ex);
       }
     }
   } while (x == null || y == null || z == null);
   String s = "V1:" + v[0] + ", V2:" + v[1] + ", X:" + x[0] + ", Y:" + y[0] + ", Z:" + z[0];
   try {
     IOColorLines.println(io, s, Color.BLACK);
   } catch (IOException ex) {
     Exceptions.printStackTrace(ex);
   }
   return new double[][] {x, y, z};
 }
示例#7
0
 private void openLog() {
   if (log == null || log.isClosed()) {
     log = IOProvider.getDefault().getIO(cvsRootDisplay, false);
     try {
       // XXX workaround, otherwise it writes to nowhere
       log.getOut().reset();
     } catch (IOException e) {
       ErrorManager err = ErrorManager.getDefault();
       err.notify(e);
     }
     // log.select();
   }
 }
 private InputOutput getOPWindow() {
   if (iop == null) {
     iop = IOProvider.getDefault().getIO(opTabTitle, false);
     iop.setErrSeparated(true);
     iop.setFocusTaken(false);
     /*iop.select();
     try {
         iop.getOut().reset();
     } catch (IOException ex) {
     }*/
     ioOut = iop.getOut();
     DateFormat dtf = DateFormat.getDateTimeInstance();
     ioOut.print("\n\n" + dtf.format(new Date(System.currentTimeMillis())) + " : ");
   }
   return iop;
 }
 @Override
 protected void init() {
   stopAction.setEnabled(true);
   if (io == null) {
     io =
         IOProvider.getDefault()
             .getIO("Sonar-runner", true, new Action[] {stopAction}, IOContainer.getDefault());
   }
   try {
     io.getOut().reset();
     io.getErr().reset();
   } catch (IOException ex) {
     Exceptions.printStackTrace(ex);
   }
   io.select();
   io.getOut().println("Starting sonar-runner");
 }
 public DataPacket(String line) {
   StringTokenizer st = new StringTokenizer(line);
   //            System.out.println(st.countTokens());
   InputOutput io = IOProvider.getDefault().getIO("TCP", false);
   for (int i = 0; st.hasMoreTokens() && i < 2; i++) {
     try {
       IOColorLines.println(io, _TXT[i] + st.nextToken(), Color.BLACK);
     } catch (IOException ex) {
       Exceptions.printStackTrace(ex);
     }
   }
   //            System.out.println("==========");
   x = token(st);
   y = token(st);
   z = token(st);
   //            System.out.println(Arrays.toString(x));
   //            System.out.println(Arrays.toString(y));
   //            System.out.println(Arrays.toString(z));
 }
示例#11
0
  public FileObject render() throws IOException {
    if (EventQueue.isDispatchThread()) {
      throw new IllegalStateException("Tried to run povray from the " + "event thread");
    }

    // Find the scene file pass to POV-Ray as a java.io.File
    File scene;
    try {
      scene = getFileToRender();
    } catch (IOException ioe) {
      showMsg(ioe.getMessage());
      return null;
    }

    // Get the POV-Ray executable
    File povray = getPovray();
    if (povray == null) {
      // The user cancelled the file chooser w/o selecting
      showMsg(NbBundle.getMessage(Povray.class, "MSG_NoPovrayExe"));
      return null;
    }

    // Get the include dir, if it isn't under povray's home dir
    File includesDir = getStandardIncludeDir(povray);
    if (includesDir == null) {
      // The user cancelled the file chooser w/o selecting
      showMsg(NbBundle.getMessage(Povray.class, "MSG_NoPovrayInc"));
      return null;
    }

    // Find the image output directory for the project
    File imagesDir = getImagesDir();

    // Assemble and format the line switches for the POV-Ray process based
    // on the contents of the Properties object
    String args = getCmdLineArgs(includesDir);
    String outFileName = stripExtension(scene) + ".png";

    // Compute the name of the output image file
    File outFile = new File(imagesDir.getPath() + File.separator + outFileName);

    // Delete the image if it exists, so that any current tab viewing the file is
    // closed and the file will definitely be re-read when it is re-opened
    if (outFile.exists() && !outFile.delete()) {
      showMsg(NbBundle.getMessage(Povray.class, "LBL_CantDelete", outFile.getName()));
      return null;
    }

    // Append the input file and output file arguments to the command line
    String cmdline =
        povray.getPath() + ' ' + args + " +I" + scene.getPath() + " +O" + outFile.getPath();

    System.err.println(cmdline);

    showMsg(NbBundle.getMessage(Povray.class, "MSG_Rendering", scene.getName()));
    final Process process = Runtime.getRuntime().exec(cmdline);

    // Get the standard out of the process
    InputStream out = new BufferedInputStream(process.getInputStream(), 8192);
    // Get the standard in of the process
    InputStream err = new BufferedInputStream(process.getErrorStream(), 8192);

    // Create readers for each
    final Reader outReader = new BufferedReader(new InputStreamReader(out));
    final Reader errReader = new BufferedReader(new InputStreamReader(err));

    // Get an InputOutput to write to the output window
    InputOutput io = IOProvider.getDefault().getIO(scene.getName(), false);

    // Force it to open the output window/activate our tab
    io.select();

    // Print the command line we're calling for debug purposes
    io.getOut().println(cmdline);

    // Create runnables to poll each output stream
    OutHandler processSystemOut = new OutHandler(outReader, io.getOut());
    OutHandler processSystemErr = new OutHandler(errReader, io.getErr());

    // Get two different threads listening on the output & err
    // using the system-wide thread pool
    RequestProcessor.getDefault().post(processSystemOut);
    RequestProcessor.getDefault().post(processSystemErr);

    try {
      // Hang this thread until the process exits
      process.waitFor();
    } catch (InterruptedException ex) {
      Exceptions.printStackTrace(ex);
    }

    // Close the output window's streams (title will become non-bold)
    processSystemOut.close();
    processSystemErr.close();

    if (outFile.exists() && process.exitValue() == 0) {
      // Try to find the new image file
      FileObject outFileObject = FileUtil.toFileObject(outFile);
      showMsg(NbBundle.getMessage(Povray.class, "MSG_Success", outFile.getPath()));
      return outFileObject;
    } else {
      showMsg(NbBundle.getMessage(Povray.class, "MSG_Failure", scene.getPath()));
      return null;
    }
  }
  private void startRunningMakefileProjectTests(
      final TmcProjectInfo projectInfo, final boolean withValgrind) {
    final File testDir = projectInfo.getProjectDirAsFile();
    String[] command;
    if (withValgrind) {
      command =
          new String[] {
            "valgrind",
            "--log-file=valgrind.log",
            "." + File.separatorChar + "test" + File.separatorChar + "test"
          };
    } else {
      // Todo: why does this need testDir.getAbsolutePath()? --kviiri
      command =
          new String[] {
            testDir.getAbsolutePath() + File.separatorChar + "test" + File.separatorChar + "test"
          };
    }
    ProcessRunner runner =
        new ProcessRunner(
            command, testDir, IOProvider.getDefault().getIO(projectInfo.getProjectName(), false));

    BgTask.start(
        "Running tests",
        runner,
        new BgTaskListener<ProcessResult>() {
          @Override
          public void bgTaskReady(ProcessResult result) {
            CTestResultParser parser =
                new CTestResultParser(
                    new File(testDir.getAbsolutePath() + "/tmc_test_results.xml"),
                    withValgrind ? new File(testDir.getAbsolutePath() + "/valgrind.log") : null,
                    null);
            try {
              parser.parseTestOutput();
            } catch (Exception e) {
              dialogDisplayer.displayError(
                  "Failed to read test results:\n" + e.getClass() + " " + e.getMessage());
              return;
            }
            boolean canSubmit = submitAction.enable(projectInfo.getProject());
            List<TestCaseResult> results = parser.getTestCaseResults();
            resultDisplayer.showLocalRunResult(
                results,
                canSubmit,
                new Runnable() {
                  @Override
                  public void run() {
                    submitAction.performAction(projectInfo.getProject());
                  }
                });
          }

          @Override
          public void bgTaskCancelled() {}

          @Override
          public void bgTaskFailed(Throwable ex) {
            if (withValgrind) {
              startRunningMakefileProjectTests(projectInfo, false);
            } else {
              dialogDisplayer.displayError("Failed to run tests:\n" + ex.getMessage());
            }
          }
        });
  }