Exemplo n.º 1
0
  public long computeSize() throws RunnerException {
    String userdir = System.getProperty("user.dir") + File.separator;
    String avrBasePath;
    if (Base.isMacOS()) {
      avrBasePath = new String("tools/avr/bin/");
    } else if (Base.isLinux()) {
      avrBasePath = new String("");
    } else {
      avrBasePath = new String(userdir + "tools/avr/bin/");
    }
    String commandSize[] = new String[] {avrBasePath + "avr-size", " "};

    commandSize[1] = buildPath + File.separator + sketchName + ".hex";

    try {
      exception = null;
      size = -1;
      firstLine = null;
      Process process = Runtime.getRuntime().exec(commandSize);
      new MessageSiphon(process.getInputStream(), this);
      new MessageSiphon(process.getErrorStream(), this);
      boolean running = true;
      while (running) {
        try {
          process.waitFor();
          running = false;
        } catch (InterruptedException intExc) {
        }
      }
    } catch (Exception e) {
      exception = new RunnerException(e.toString());
    }

    if (exception != null) throw exception;

    if (size == -1) throw new RunnerException(firstLine);

    return size;
  }