Class JdkResolver
java.lang.Object
com.dua3.gradle.jdkprovider.resolver.JdkResolver
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 Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected DiscoApiClientCreates and returns a new instance of theDiscoApiClient.protected JdkProvisionerCreates and returns an instance ofJdkProvisioner, which is responsible for provisioning JDKs based on specified requirements.protected LocalJdkScannerCreates and returns a new instance ofLocalJdkScannerto facilitate scanning and identification of locally installed JDKs.protected PathProvisions a package by downloading, verifying, and extracting the specified package archive.protected Optional<JdkInstallation> readJdkSpec(Path jdkHome) Reads the JDK specification from the specified JDK home directory.Resolves a JDK installation that matches the specified requirements.
-
Constructor Details
-
JdkResolver
public JdkResolver()Constructs a new instance of the JdkResolver.
-
-
Method Details
-
resolve
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
Optionalcontaining aJdkInstallationthat meets the requirements, or an emptyOptionalif 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
Creates and returns a new instance ofLocalJdkScannerto facilitate scanning and identification of locally installed JDKs.- Returns:
- a newly instantiated
LocalJdkScannerobject for discovering local JDK installations.
-
createDiscoApiClient
Creates and returns a new instance of theDiscoApiClient.- Returns:
- a
DiscoApiClientinstance, used for interacting with the DiscoAPI.
-
createJdkProvisioner
Creates and returns an instance ofJdkProvisioner, which is responsible for provisioning JDKs based on specified requirements.- Returns:
- a new instance of
JdkProvisionerto handle JDK provisioning.
-
readJdkSpec
Reads the JDK specification from the specified JDK home directory.- Parameters:
jdkHome- the filesystem path to the JDK home directory.- Returns:
- an
Optionalcontaining aJdkInstallationif the JDK specification is successfully read, or an emptyOptionalif the JDK home directory does not contain a valid JDK specification.
-
provisionPackage
Provisions a package by downloading, verifying, and extracting the specified package archive. This method delegates the operation to aJdkProvisionerinstance 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- theDiscoPackagecontaining metadata about the package to be provisioned, including its download URI, checksum, filename, and archive type.- Returns:
- the
Pathto 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.
-