Class DiscoApiClient

java.lang.Object
com.dua3.gradle.jdkprovider.disco.DiscoApiClient

public final class DiscoApiClient extends Object
DiscoAPI client to discover Disco packages.
  • Constructor Details

    • DiscoApiClient

      public DiscoApiClient()
      Constructs a new instance of DiscoApiClient with the default base URL. The default base URL points to the Disco API's package query endpoint. This constructor is designed for quick initialization using the preset configuration.
    • DiscoApiClient

      public DiscoApiClient(String baseUrl)
      Constructs a new instance of DiscoApiClient with the specified base URL. The base URL is used as the root for building query URLs for the Disco API.

      This constructor is used in unit tests.

      Parameters:
      baseUrl - the base URL to use for API queries, must not be null
      Throws:
      NullPointerException - if the provided base URL is null
  • Method Details

    • getPackagesQueryUrl

      public URI getPackagesQueryUrl(JdkQuery query)
      Builds and returns the DiscoAPI packages query URL for the provided JDK query.
      Parameters:
      query - JDK selection query
      Returns:
      fully qualified packages query URI
    • findPackage

      public Optional<DiscoPackage> findPackage(JdkQuery jdkQuery)
      Finds a suitable DiscoPackage based on the provided JdkQuery.

      This method queries the Disco API using parameters derived from the given JdkQuery to retrieve matching JDK package details. If a package compatible with the specified operating system and other criteria is found, it is returned as an Optional. If no matching package is found or an error occurs during the API query, an empty Optional is returned.

      Parameters:
      jdkQuery - the JdkQuery instance containing parameters used to query the Disco API. This includes fields like operating system, architecture, version preferences, and vendor specifications.
      Returns:
      an Optional containing the selected DiscoPackage if a matching package is found; otherwise, an empty Optional.
    • findPackages

      public List<DiscoPackage> findPackages(JdkQuery jdkQuery)
      Finds all suitable DiscoPackages based on the provided JdkQuery, sorted from most preferred to least preferred.
      Parameters:
      jdkQuery - the JdkQuery instance containing parameters used to query the Disco API.
      Returns:
      a list of matching packages in preference order, or an empty list on query failure.