Class LocalJdkScanner

java.lang.Object
com.dua3.gradle.jdkprovider.local.LocalJdkScanner

public final class LocalJdkScanner extends Object
Scans the local machine for JDK installations.
  • Constructor Details

    • LocalJdkScanner

      public LocalJdkScanner()
      Constructs a new instance of LocalJdkScanner. This class is responsible for scanning the local system to discover installed JDKs, leveraging common locations such as the system's JAVA_HOME environment variable or paths specified in configuration properties (e.g., Gradle's installation paths). When instantiated, the scanner is ready to perform discovery operations.
    • LocalJdkScanner

      public LocalJdkScanner(Map<String,String> environment, Path cacheDir)
      Constructs a new instance of LocalJdkScanner with a custom environment and cache directory.
      Parameters:
      environment - the environment variables to use for scanning
      cacheDir - the cache directory to scan for JDKs
  • Method Details

    • detectJdkHome

      public static Path detectJdkHome(Path jdkRoot)
      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
      1. The presence of a 'bin/java' executable directly under the extracted root.
      2. A single subdirectory under the extracted root containing a 'bin/java' executable.
      3. macOS-style JDK bundles, where 'Contents/Home/bin/java' exists within a subdirectory.
      4. 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

      public List<JdkInstallation> getInstalledJdks()
      Try to find JDK homes from typical locations: JAVA_HOME and Gradle's installation paths property.
      Returns:
      JDK homes
    • readJdkSpec

      public static Optional<JdkInstallation> readJdkSpec(Path jdkDir)
      Attempts to read the JDK spec by reading the release file.
      Parameters:
      jdkDir - JDK home
      Returns:
      JDK spec
    • getCompatibleInstalledJdks

      public List<JdkInstallation> getCompatibleInstalledJdks(JdkQuery jdkQuery)
      Filters the list of installed JDKs to identify those that are compatible based on the provided JdkSpec instance.
      Parameters:
      jdkQuery - The JdkSpec to match against.
      Returns:
      A list of JdkInstallation instances that meet the compatibility requirements.