private String getJDepsExecutable()

in src/main/java/org/apache/maven/plugins/jdeps/AbstractJDepsMojo.java [358:414]


    private String getJDepsExecutable() throws IOException {
        Toolchain tc = getToolchain();

        String jdepsExecutable = null;
        if (tc != null) {
            jdepsExecutable = tc.findTool("jdeps");
        }

        String jdepsCommand = "jdeps" + (SystemUtils.IS_OS_WINDOWS ? ".exe" : "");

        File jdepsExe;

        if (StringUtils.isNotEmpty(jdepsExecutable)) {
            jdepsExe = new File(jdepsExecutable);

            if (jdepsExe.isDirectory()) {
                jdepsExe = new File(jdepsExe, jdepsCommand);
            }

            if (SystemUtils.IS_OS_WINDOWS && jdepsExe.getName().indexOf('.') < 0) {
                jdepsExe = new File(jdepsExe.getPath() + ".exe");
            }

            if (!jdepsExe.isFile()) {
                throw new IOException("The jdeps executable '" + jdepsExe + "' doesn't exist or is not a file.");
            }
            return jdepsExe.getAbsolutePath();
        }

        jdepsExe = new File(SystemUtils.getJavaHome() + File.separator + ".." + File.separator + "sh", jdepsCommand);

        // ----------------------------------------------------------------------
        // Try to find jdepsExe from JAVA_HOME environment variable
        // ----------------------------------------------------------------------
        if (!jdepsExe.exists() || !jdepsExe.isFile()) {
            Properties env = CommandLineUtils.getSystemEnvVars();
            String javaHome = env.getProperty("JAVA_HOME");
            if (StringUtils.isEmpty(javaHome)) {
                throw new IOException("The environment variable JAVA_HOME is not correctly set.");
            }
            if ((!new File(javaHome).getCanonicalFile().exists())
                    || (new File(javaHome).getCanonicalFile().isFile())) {
                throw new IOException("The environment variable JAVA_HOME=" + javaHome
                        + " doesn't exist or is not a valid directory.");
            }

            jdepsExe = new File(javaHome + File.separator + "bin", jdepsCommand);
        }

        if (!jdepsExe.getCanonicalFile().exists()
                || !jdepsExe.getCanonicalFile().isFile()) {
            throw new IOException("The jdeps executable '" + jdepsExe
                    + "' doesn't exist or is not a file. Verify the JAVA_HOME environment variable.");
        }

        return jdepsExe.getAbsolutePath();
    }