Exemple #1
0
    private boolean runPolling() {
      try {
        // to make sure that the log file contains up-to-date text,
        // don't do buffering.
        StreamTaskListener listener = new StreamTaskListener(getLogFile());

        try {
          PrintStream logger = listener.getLogger();
          long start = System.currentTimeMillis();
          logger.println("Started on " + DateFormat.getDateTimeInstance().format(new Date()));
          boolean result = job.poll(listener).hasChanges();
          logger.println(
              "Done. Took " + Util.getTimeSpanString(System.currentTimeMillis() - start));
          if (result) logger.println("Changes found");
          else logger.println("No changes");
          return result;
        } catch (Error e) {
          e.printStackTrace(listener.error("Failed to record SCM polling"));
          LOGGER.log(Level.SEVERE, "Failed to record SCM polling", e);
          throw e;
        } catch (RuntimeException e) {
          e.printStackTrace(listener.error("Failed to record SCM polling"));
          LOGGER.log(Level.SEVERE, "Failed to record SCM polling", e);
          throw e;
        } finally {
          listener.close();
        }
      } catch (IOException e) {
        LOGGER.log(Level.SEVERE, "Failed to record SCM polling", e);
        return false;
      }
    }
  /** Called when a POST is made. */
  public void onPost(String triggeredByUser) {
    LOGGER.fine("Received POST by " + triggeredByUser);
    final String pushBy = triggeredByUser;
    if (triggerForUserCommit(triggeredByUser)) {
      LOGGER.fine("Triggering build " + triggeredByUser);
      getDescriptor()
          .queue
          .execute(
              new Runnable() {
                public void run() {
                  try {
                    StreamTaskListener listener = new StreamTaskListener(getLogFile());

                    try {
                      PrintStream logger = listener.getLogger();
                      long start = System.currentTimeMillis();
                      logger.println(
                          "Started on " + DateFormat.getDateTimeInstance().format(new Date()));
                      boolean result = job.poll(listener).hasChanges();
                      logger.println(
                          "Done. Took "
                              + Util.getTimeSpanString(System.currentTimeMillis() - start));
                      if (result) {
                        logger.println("Changes found");
                        job.scheduleBuild(new GitHubPushCause(pushBy));
                      } else {
                        logger.println("No changes");
                      }
                    } finally {
                      listener.close();
                    }
                  } catch (IOException e) {
                    LOGGER.log(Level.SEVERE, "Failed to record SCM polling", e);
                  }
                }
              });
    } else {
      LOGGER.fine("ignoring commit by user " + triggeredByUser);
      try {
        StreamTaskListener listener = new StreamTaskListener(getLogFile());
        try {
          PrintStream logger = listener.getLogger();
          logger.println("ignoring commit by user " + triggeredByUser);
        } finally {
          listener.close();
        }
      } catch (IOException e) {
        LOGGER.log(Level.SEVERE, "Failed to record ignored commit", e);
      }
    }
  }