예제 #1
0
  private void buildFile(
      BuildContext context, List<IBuildParticipant> participants, IProgressMonitor monitor)
      throws CoreException {
    if (CollectionsUtil.isEmpty(participants)) {
      return;
    }

    SubMonitor sub = SubMonitor.convert(monitor, 2 * participants.size());
    for (IBuildParticipant participant : participants) {
      long startTime = System.nanoTime();
      participant.buildFile(context, sub.newChild(1));
      if (traceParticipantsEnabled) {
        double endTime = ((double) System.nanoTime() - startTime) / 1000000;
        IdeLog.logTrace(
            BuildPathCorePlugin.getDefault(),
            MessageFormat.format(
                "Executed build participant ''{0}'' on ''{1}'' in {2} ms.",
                participant.getName(), context.getURI(), endTime),
            IDebugScopes.BUILDER_PARTICIPANTS); // $NON-NLS-1$
      }

      // stop building if it has been canceled
      if (sub.isCanceled()) {
        break;
      }
    }
    updateMarkers(context, sub.newChild(participants.size()));
    sub.done();
  }
  /**
   * Sends a ping.
   *
   * @param event
   * @param user
   * @return The ping response code.
   */
  protected int sendPing(AnalyticsEvent event, IAnalyticsUser user) {
    HttpURLConnection connection = null;
    DataOutputStream output = null;

    try {
      URL url = new URL(getAnalyticsURL());
      connection = (HttpURLConnection) url.openConnection();
      if (user != null) {
        connection.setRequestProperty(
            "Cookie", user.getCookie() + "; uid=" + user.getGUID()); // $NON-NLS-1$ //$NON-NLS-2$
      }
      connection.setRequestProperty("User-Agent", AnalyticsEvent.getUserAgent()); // $NON-NLS-1$
      connection.setDoOutput(true);
      connection.setReadTimeout(getTimeout());
      connection.setConnectTimeout(getTimeout());

      connection.setRequestMethod("POST"); // $NON-NLS-1$
      // writes POST
      output = new DataOutputStream(connection.getOutputStream());
      String data = event.getEventString();
      output.writeBytes(data);
      output.flush();

      if (IdeLog.isTraceEnabled(UsagePlugin.getDefault(), IDebugScopes.USAGE)) {
        IdeLog.logTrace(
            UsagePlugin.getDefault(),
            MessageFormat.format("Sending usage: {0}, {1}", url, data)); // $NON-NLS-1$
      }

      int code = connection.getResponseCode();
      if (code == HttpURLConnection.HTTP_UNAUTHORIZED || code == HttpURLConnection.HTTP_FORBIDDEN) {
        UsagePlugin.logError(
            MessageFormat.format(
                Messages.StudioAnalytics_connection_unauthorized, Integer.toString(code)));
      } else if (code < 200 || code > 205) {
        UsagePlugin.logError(
            MessageFormat.format(
                Messages.StudioAnalytics_connection_failed, Integer.toString(code)));
      }

      return code;
    } catch (Exception e) {
      UsagePlugin.logError(e);
      return HttpURLConnection.HTTP_UNAVAILABLE;
    } finally {
      if (output != null) {
        try {
          output.close();
        } catch (IOException ignore) {
        }
      }
      if (connection != null) {
        connection.disconnect();
      }
    }
  }