Class LocalJdkScanner
java.lang.Object
com.dua3.gradle.jdkprovider.local.LocalJdkScanner
Scans the local machine for JDK installations.
-
Constructor Summary
ConstructorsConstructorDescriptionConstructs a new instance ofLocalJdkScanner.LocalJdkScanner(Map<String, String> environment, Path cacheDir) Constructs a new instance ofLocalJdkScannerwith a custom environment and cache directory. -
Method Summary
Modifier and TypeMethodDescriptionstatic PathdetectJdkHome(Path jdkRoot) Detects the home directory of a JDK installation by analyzing the given extracted root directory.getCompatibleInstalledJdks(JdkQuery jdkQuery) Filters the list of installed JDKs to identify those that are compatible based on the providedJdkSpecinstance.Try to find JDK homes from typical locations: JAVA_HOME and Gradle's installation paths property.static Optional<JdkInstallation> readJdkSpec(Path jdkDir) Attempts to read the JDK spec by reading the release file.
-
Constructor Details
-
LocalJdkScanner
public LocalJdkScanner()Constructs a new instance ofLocalJdkScanner. This class is responsible for scanning the local system to discover installed JDKs, leveraging common locations such as the system'sJAVA_HOMEenvironment variable or paths specified in configuration properties (e.g., Gradle's installation paths). When instantiated, the scanner is ready to perform discovery operations. -
LocalJdkScanner
Constructs a new instance ofLocalJdkScannerwith a custom environment and cache directory.- Parameters:
environment- the environment variables to use for scanningcacheDir- the cache directory to scan for JDKs
-
-
Method Details
-
detectJdkHome
Detects the home directory of a JDK installation by analyzing the given extracted root directory. The method searches for well-known JDK layouts, such as- The presence of a 'bin/java' executable directly under the extracted root.
- A single subdirectory under the extracted root containing a 'bin/java' executable.
- macOS-style JDK bundles, where 'Contents/Home/bin/java' exists within a subdirectory.
- macOS-style JDK bundles directly under the extracted root ('Contents/Home/bin/java').
- Parameters:
jdkRoot- the root path of the extracted directory to analyze for a JDK home.- Returns:
- the path to the JDK home directory if detected; otherwise, null.
-
getInstalledJdks
Try to find JDK homes from typical locations: JAVA_HOME and Gradle's installation paths property.- Returns:
- JDK homes
-
readJdkSpec
Attempts to read the JDK spec by reading the release file.- Parameters:
jdkDir- JDK home- Returns:
- JDK spec
-
getCompatibleInstalledJdks
Filters the list of installed JDKs to identify those that are compatible based on the providedJdkSpecinstance.- Parameters:
jdkQuery- TheJdkSpecto match against.- Returns:
- A list of
JdkInstallationinstances that meet the compatibility requirements.
-