Java Is Windows isWindowsCygwin()

Here you can find the source of isWindowsCygwin()

Description

is Windows Cygwin

License

Apache License

Declaration

private static boolean isWindowsCygwin() 

Method Source Code


//package com.java2s;
//License from project: Apache License 

import static java.util.Arrays.asList;

import java.io.File;

public class Main {
    private static boolean isWindowsCygwin() {
        return System.getProperty("os.name").toLowerCase().contains("windows") && (findCygwinHome() != null);
    }/*from  w  w w.j  a  va2 s  .  c  o m*/

    private static String findCygwinHome() {
        if (System.getProperties().containsKey("cygwin.home")) {
            return (System.getProperty("cygwin.home") + "\\bin\\bash.exe").replaceAll("//", "/").replaceAll("\\\\",
                    "\\");
        } else if (System.getenv("CYGWIN_HOME") != null && System.getenv("CYGWIN_HOME").trim().length() > 0) {
            return (System.getenv("CYGWIN_HOME") + "\\bin\\bash.exe").replaceAll("//", "/").replaceAll("\\\\",
                    "\\");
        } else {
            for (String candiate : asList("C:\\cygwin_x64\\bin\\", "C:\\cygwin_x86\\bin\\", "C:\\cygwin\\bin\\")) {
                if (new File(candiate).isDirectory()) {
                    return candiate;
                }
            }
            throw new UnsupportedOperationException("on windows and no cygwin found");
        }
    }
}

Related

  1. isWindows()
  2. isWindows()
  3. isWindows()
  4. isWindows64JREAvailable()
  5. isWindowsAdministrator()
  6. isWindowsFileSep()
  7. isWindowsFileSystem()
  8. isWindowsInstall()
  9. isWinFileSystem()