Ejemplo n.º 1
0
  /**
   * Fetch the raw body of an ApexLog with the specified log ID.
   *
   * @param forceProject
   * @param logId
   * @return Raw log. Null if something is wrong.
   */
  public String getApexLogBody(ForceProject forceProject, String logId) {
    String rawLog = null;

    try {
      initializeConnection(forceProject);

      PromiseableJob<String> job =
          new ApexLogCommand(
              new HTTPAdapter<>(
                  String.class,
                  new ApexLogTransport(toolingRESTConnection, logId),
                  HTTPMethod.GET));
      job.schedule();

      try {
        job.join();
        rawLog = job.getAnswer();
      } catch (InterruptedException e) {
        logger.error("Failed to get Apex Log", e);
      }
    } catch (ForceConnectionException | ForceRemoteException e) {
      logger.error("Failed to connect to Tooling API", e);
    }

    return rawLog;
  }
Ejemplo n.º 2
0
  /**
   * Enqueue a tests array to Tooling's runTestsAsynchronous.
   *
   * @param testsInJson
   * @return The test run ID if valid. Null otherwise.
   */
  public String enqueueTests(String testsInJson) {
    String response = null;

    if (Utils.isEmpty(forceProject)) {
      return response;
    }

    try {
      initializeConnection(forceProject);

      PromiseableJob<String> job =
          new RunTestsCommand(
              new HTTPAdapter<>(
                  String.class, new RunTestsTransport(toolingRESTConnection), HTTPMethod.POST),
              testsInJson);
      job.schedule();

      try {
        job.join();
        response = job.getAnswer();
      } catch (InterruptedException e) {
        logger.error("Failed to enqueue test run", e);
      }

    } catch (ForceConnectionException | ForceRemoteException e) {
      logger.error("Failed to connect to Tooling API", e);
    }

    return response;
  }
  public synchronized Completions getCompletionsFetchIfNecessary(ForceProject project) {
    if (completions == NOT_INITIALIZED && !FETCHING_IN_PROGRESS) {
      try {
        initializeConnectionIfNecessary(project);
        PromiseableJob<Completions> job =
            new SystemCompletionsCommand(
                new HTTPAdapter<>(
                    Completions.class,
                    new SystemCompletionTransport(toolingRESTConnection),
                    HTTPMethod.GET)) {
              {
                onSuccess =
                    new Function<Completions, IStatus>() {
                      @Override
                      public IStatus apply(Completions c) {
                        if (c != null) {
                          completions = c;
                        }
                        FETCHING_IN_PROGRESS = false;
                        return Status.OK_STATUS;
                      }
                    };

                onFailure =
                    new Function<Throwable, IStatus>() {
                      @Override
                      public IStatus apply(Throwable t) {
                        completions = NOT_INITIALIZED;
                        FETCHING_IN_PROGRESS = false;
                        return new Status(
                            Status.ERROR,
                            ForceIdeCorePlugin.PLUGIN_ID,
                            Messages.PromiseableJob_GenericError,
                            t);
                      }
                    };
              }
            };

        FETCHING_IN_PROGRESS = true;
        job.schedule();
      } catch (InsufficientPermissionsException | ForceConnectionException e) {
        logger.error("Failed to fetch system completions", e);
        completions = NOT_INITIALIZED;
        FETCHING_IN_PROGRESS = false;
      }
    }
    return completions;
  }