Exemplo n.º 1
0
  /** Method to process the build queue, can be called by more than one thread */
  public void processBuildQueue() throws TablesawException {
    BuildAction ba;
    Rule rule;
    String target;

    synchronized (m_threadList) {
      m_threadList.add(Thread.currentThread());
    }

    try {
      doloop:
      do {
        synchronized (this) {
          try {
            ba = (BuildAction) m_buildQueue.removeLast();
          } catch (NoSuchElementException nsee) {
            break doloop;
            // ba = new BuildAction(m_fileManager, null);
          }

          if (m_printDebug) Debug.print("Processing: " + ba);

          if (m_makeException != null) break doloop;

          ba.waitForDependencies();

          if (m_makeException != null) break doloop;
        }

        rule = ba.getTargetRule();
        MakeAction action = rule.getMakeAction();

        // target = ba.getTarget();
        if (action != null) {
          action.doMakeAction(rule);

          rule.verify();
        }

        Debug.print("COMPLETE - " + ba);
        ba.complete(); // Complete the BuildAction
      } while (m_makeException == null);
    } catch (Exception e) {
      TablesawException cpe;

      if (e instanceof TablesawException) cpe = (TablesawException) e;
      else cpe = new TablesawException(e);

      synchronized (this) {
        m_makeException = cpe;

        for (Thread t : m_threadList) t.interrupt();
      }

      throw cpe;
    }

    // This causes worker threads to die off and the exception to
    // pass to the main thread
    if (m_makeException != null) throw m_makeException;
  }