private String buildNotFoundMessage(PluginRequest pluginRequest, Result result) {
    if (result.notFoundList.isEmpty()) {
      // this shouldn't happen, resolvers should call notFound()
      return String.format("Plugin %s was not found", pluginRequest.getDisplayName());
    } else {
      StringBuilder sb =
          new StringBuilder("Plugin ")
              .append(pluginRequest.getDisplayName())
              .append(" was not found in any of the following sources:\n");

      for (NotFound notFound : result.notFoundList) {
        sb.append('\n').append("- ").append(notFound.source);
        if (notFound.detail != null) {
          sb.append(" (").append(notFound.detail).append(")");
        }
      }

      return sb.toString();
    }
  }
  private Result resolveToFoundResult(PluginRequest request) {
    Result result = new Result(request);
    try {
      pluginResolver.resolve(request, result);
    } catch (Exception e) {
      throw new LocationAwareException(
          new GradleException(
              String.format("Error resolving plugin %s.", request.getDisplayName()), e),
          request.getScriptSource(),
          request.getLineNumber());
    }

    if (!result.isFound()) {
      String message = buildNotFoundMessage(request, result);
      Exception exception = new UnknownPluginException(message);
      throw new LocationAwareException(
          exception, request.getScriptSource(), request.getLineNumber());
    }

    return result;
  }