Class JdkProvisioner
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidBlacklists a download URI to avoid redownloading it in the future.static PathRetrieves the base directory used for caching toolchain data for the Java resolver plugin.static PathProvides the directory path where cached JDKs are installed.static PathDetermines the location of the Gradle user home directory.booleanisBlacklisted(URI downloadUri) Checks if a download URI is blacklisted.Provisions a JDK by downloading, verifying, and extracting the archive from a given URI.voidremoveExtractedJdk(Path jdkHome) Removes an extracted JDK directory.
-
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
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
Provides the directory path where cached JDKs are installed.- Returns:
- the path to the directory containing cached JDKs
-
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
Blacklists a download URI to avoid redownloading it in the future.- Parameters:
downloadUri- the URI to blacklist
-
isBlacklisted
Checks if a download URI is blacklisted.- Parameters:
downloadUri- the URI to check- Returns:
trueif the URI is blacklisted,falseotherwise
-
removeExtractedJdk
Removes an extracted JDK directory.- Parameters:
jdkHome- the home directory of the JDK to remove- Throws:
IOException- if an I/O error occurs
-