Class JdkResolver

java.lang.Object
com.dua3.gradle.jdkprovider.resolver.JdkResolver

public class JdkResolver extends Object
Resolves a JDK installation that matches the specified requirements. The class checks for compatible local installations or provisions a new JDK using the DiscoAPI when necessary.
  • Constructor Details

    • JdkResolver

      public JdkResolver()
      Constructs a new instance of the JdkResolver.
  • Method Details

    • resolve

      public Optional<JdkInstallation> resolve(JdkQuery jdkQuery, boolean offlineMode)
      Resolves a JDK installation that matches the specified requirements. This method checks for compatible local JDK installations and, if none are found, attempts to provision a JDK using the DiscoAPI, provided offline mode is disabled.
      Parameters:
      jdkQuery - the specification of the JDK version and features required.
      offlineMode - a flag indicating whether the resolution process should avoid network communication and rely only on local installations.
      Returns:
      an Optional containing a JdkInstallation that meets the requirements, or an empty Optional if no suitable JDK could be resolved.
      Throws:
      org.gradle.api.GradleException - if the toolchain cannot be resolved due to offline mode or failure in provisioning a JDK using the DiscoAPI.
    • createLocalJdkScanner

      protected LocalJdkScanner createLocalJdkScanner()
      Creates and returns a new instance of LocalJdkScanner to facilitate scanning and identification of locally installed JDKs.
      Returns:
      a newly instantiated LocalJdkScanner object for discovering local JDK installations.
    • createDiscoApiClient

      protected DiscoApiClient createDiscoApiClient()
      Creates and returns a new instance of the DiscoApiClient.
      Returns:
      a DiscoApiClient instance, used for interacting with the DiscoAPI.
    • createJdkProvisioner

      protected JdkProvisioner createJdkProvisioner()
      Creates and returns an instance of JdkProvisioner, which is responsible for provisioning JDKs based on specified requirements.
      Returns:
      a new instance of JdkProvisioner to handle JDK provisioning.
    • readJdkSpec

      protected Optional<JdkInstallation> readJdkSpec(Path jdkHome)
      Reads the JDK specification from the specified JDK home directory.
      Parameters:
      jdkHome - the filesystem path to the JDK home directory.
      Returns:
      an Optional containing a JdkInstallation if the JDK specification is successfully read, or an empty Optional if the JDK home directory does not contain a valid JDK specification.
    • provisionPackage

      protected Path provisionPackage(DiscoPackage pkg) throws IOException, InterruptedException
      Provisions a package by downloading, verifying, and extracting the specified package archive. This method delegates the operation to a JdkProvisioner instance to handle the actual provisioning logic, including downloading the archive, checking its integrity with the provided SHA-256 checksum, and extracting it to a specified location.
      Parameters:
      pkg - the DiscoPackage containing metadata about the package to be provisioned, including its download URI, checksum, filename, and archive type.
      Returns:
      the Path to the root directory of the provisioned package.
      Throws:
      IOException - if an error occurs during downloading, verifying, or extracting the package.
      InterruptedException - if the thread is interrupted while waiting for an operation to complete.