Class JdkProvisioner

java.lang.Object
com.dua3.gradle.jdkprovider.provision.JdkProvisioner

public class JdkProvisioner extends Object
Downloads, verifies, and extracts JDK archives into a managed cache and returns the JDK home path.
  • Constructor Details

    • JdkProvisioner

      public JdkProvisioner()
      Default constructor for the JdkProvisioner class.
  • Method Details

    • provision

      public Path provision(URI downloadUri, String expectedSha256, String preferredFilename, String archiveType) throws IOException, InterruptedException
      Provisions a JDK by downloading, verifying, and extracting the archive from a given URI.

      This method handles the caching of previously downloaded or extracted JDKs, verifies the integrity of the downloaded files, and extracts the JDK to a specified location. It ensures atomic extraction and creates a completion marker upon successful operation. If an existing extracted JDK is detected and valid, it will be reused instead of redownloading or re-extracting.

      Parameters:
      downloadUri - The URI from which the JDK archive will be downloaded.
      expectedSha256 - The expected SHA-256 checksum of the archive for verification.
      preferredFilename - The preferred filename to use for the downloaded archive, or null to auto-determine.
      archiveType - The type of the archive (e.g., "zip," "tar.gz") to help determine handling.
      Returns:
      The path to the root directory of the provisioned JDK.
      Throws:
      IOException - If an I/O error occurs during downloading, verifying, extracting, or any other operation.
      InterruptedException - If the thread is interrupted while waiting for an operation to complete.
    • getCacheDir

      public static Path getCacheDir()
      Retrieves the base directory used for caching toolchain data for the Java resolver plugin.

      This method constructs the cache location by resolving the "caches/javaresolverplugin-toolchains" path relative to the Gradle user home directory. The Gradle user home directory is determined using the getGradleUserHome() method, which looks at system and environment variables to determine its location.

      Returns:
      The path to the base directory used for caching toolchain data.
    • getCachedJdksDir

      public static Path getCachedJdksDir()
      Provides the directory path where cached JDKs are installed.
      Returns:
      the path to the directory containing cached JDKs
    • getGradleUserHome

      public static Path getGradleUserHome()
      Determines the location of the Gradle user home directory.

      This method checks system and environment variables to locate the Gradle user home directory: 1. If the system property "gradle.user.home" is set and non-blank, its value is used. 2. If the environment variable "GRADLE_USER_HOME" is set and non-blank, its value is used. 3. If neither is set nor non-blank, the default location is resolved to a ".gradle" directory within the user's home directory as specified by the "user.home" system property.

      Returns:
      The path to the Gradle user home directory.
    • blacklist

      public void blacklist(URI downloadUri)
      Blacklists a download URI to avoid redownloading it in the future.
      Parameters:
      downloadUri - the URI to blacklist
    • isBlacklisted

      public boolean isBlacklisted(URI downloadUri)
      Checks if a download URI is blacklisted.
      Parameters:
      downloadUri - the URI to check
      Returns:
      true if the URI is blacklisted, false otherwise
    • removeExtractedJdk

      public void removeExtractedJdk(Path jdkHome) throws IOException
      Removes an extracted JDK directory.
      Parameters:
      jdkHome - the home directory of the JDK to remove
      Throws:
      IOException - if an I/O error occurs