public static String jdkDefaultDirectory()

in Utils/azure-toolkit-ide-hdinsight-libs/azuretools-core/src/com/microsoft/azuretools/azurecommons/util/WAEclipseHelperMethods.java [114:163]


    public static String jdkDefaultDirectory(String currentlySelectedDir) {
        File file;

        // Try currently selected JDK path
        String path = currentlySelectedDir;
        if (path != null && !path.isEmpty()) {
            file = new File(path);
            if (file.isDirectory() && file.exists()) {
                return path;
            }
        }

        // Try JAVA_HOME
        path = System.getenv("JAVA_HOME");
        if (path != null && !path.isEmpty()) {
            file = new File(path);
            if (file.exists() && file.isDirectory()) {
                // Verify presence of javac.exe
                File javacFile = new File(file, "bin" + File.separator
                        + "javac.exe");
                if (javacFile.exists()) {
                    return path;
                }
            }
        }

        // Try under %ProgramFiles%\Java
        path = String.format("%s%s%s", System.getenv("ProgramFiles"),
                File.separator, "Java", File.separator);
        file = new File(path);
        if (!file.exists() || !file.isDirectory()) {
            return "";
        }

        // Find the first entry under Java that contains jdk
        File[] jdkDirs = file.listFiles();
        Arrays.sort(jdkDirs);

        TreeSet<File> sortedDirs = new TreeSet<File>(Arrays.asList(jdkDirs));
        for (Iterator<File> iterator = sortedDirs.descendingIterator(); iterator
                .hasNext();) {
            File latestSdkDir = iterator.next();
            if (latestSdkDir.isDirectory()
                    && latestSdkDir.getName().contains("jdk")) {
                return latestSdkDir.getAbsolutePath();
            }
        }

        return "";
    }