Example usage for org.apache.commons.lang SystemUtils IS_OS_LINUX

List of usage examples for org.apache.commons.lang SystemUtils IS_OS_LINUX

Introduction

In this page you can find the example usage for org.apache.commons.lang SystemUtils IS_OS_LINUX.

Prototype

boolean IS_OS_LINUX

To view the source code for org.apache.commons.lang SystemUtils IS_OS_LINUX.

Click Source Link

Document

Is true if this is Linux.

The field will return false if OS_NAME is null.

Usage

From source file:org.medici.bia.common.teaching.ImageConversionInvoker.java

public int fire() {
    try {/* ww w.j  av  a  2 s. c o m*/
        Process process = null;

        if (SystemUtils.IS_OS_LINUX) {
            //            logger.info("IMAGE CONVERSION TASK: Linux Operating System detected...");
            //            String[] env = {"PATH=/bin:/usr/bin/"};
            //            String scriptCommand = ApplicationPropertyManager.getApplicationProperty("path.tmpdir") + 
            //                  (ApplicationPropertyManager.getApplicationProperty("path.tmpdir").endsWith("/") ? "upload_images.sh" : "/upload_images.sh");
            //            String cmd = scriptCommand + " " + fileName +  " '" + fileTitle + "' " + imageOrder + " " + storagePath;
            //            logger.info("IMAGE CONVERSION TASK: launching command [" + cmd + "]");
            //            
            //            process = rt.exec(cmd, env);
            logger.info("IMAGE CONVERSION TASK: Linux Operating System detected...");
            String[] env = { "PATH=/bin:/usr/bin/" };
            String[] commandArray = { ApplicationPropertyManager.getApplicationProperty("path.tmpdir") +
                    //(ApplicationPropertyManager.getApplicationProperty("path.tmpdir").endsWith("/") ? "upload_images.sh" : "/upload_images.sh"), fileName, "'" + fileTitle + "'", "" + imageOrder, "" + storagePath} ;
                    (ApplicationPropertyManager.getApplicationProperty("path.tmpdir").endsWith("/")
                            ? ApplicationPropertyManager.getApplicationProperty("upload.script")
                            : "/" + ApplicationPropertyManager.getApplicationProperty("upload.script")),
                    fileName, "'" + fileTitle + "'", "" + imageOrder, "" + storagePath };
            try {
                logger.info("IMAGE CONVERSION TASK: launching command : " + ArrayUtils.toString(commandArray));
                process = Runtime.getRuntime().exec(commandArray, env);
            } catch (Throwable th) {
                logger.error("errore di esecuzione", th);
            }

        } else if (SystemUtils.IS_OS_WINDOWS) {
            // XXX for development environment: we suppose the 'insert_after_upload.bat' file is
            // in the 'path.tmpdir' location
            String realCommand = "\"\"" + ApplicationPropertyManager.getApplicationProperty("path.tmpdir")
                    + "insert_after_upload.bat\"" + " \"" + fileName + "\" \"" + fileTitle + "\" \""
                    + imageOrder + "\" \"" + storagePath + "\"\"";

            logger.info("IMAGE CONVERSION TASK: Windows Operating System detected...");
            String[] command = new String[3];
            command[0] = "cmd.exe";
            command[1] = "/C";
            command[2] = realCommand;

            try {
                logger.info("IMAGE CONVERSION TASK: launching command : " + ArrayUtils.toString(command));

                process = Runtime.getRuntime().exec(command);
            } catch (Throwable th) {
                logger.error("errore di esecuzione", th);
            }
        } else {
            logger.error(
                    "IMAGE CONVERSION TASK: The detected Operating System is not supported...the task is aborted!");
            return NOT_SUPPORTED_OS;
        }

        ImageConversionProcessStreamLogger errorLoggerConsumer = new ImageConversionProcessStreamLogger(
                process.getErrorStream(), logger, ImageConversionProcessStreamLogger.LogLevel.ERROR);
        ImageConversionProcessStreamLogger infoLoggerConsumer = new ImageConversionProcessStreamLogger(
                process.getInputStream(), logger, ImageConversionProcessStreamLogger.LogLevel.INFO);

        errorLoggerConsumer.start();
        infoLoggerConsumer.start();

        return process.waitFor();
    } catch (Exception e) {
        return TASK_ERROR;
    }
}

From source file:org.mule.transport.sftp.AbstractSftpTestCase.java

protected void recursiveDeleteInLocalFilesystem(File parent) throws IOException {
    // If this file is a directory then first delete all its children
    if (parent.isDirectory()) {
        for (File child : parent.listFiles()) {
            recursiveDeleteInLocalFilesystem(child);
        }//from w  ww .  j  a  v a 2 s  . co  m
    }

    // Now delete this file, but first check write permissions on its parent...
    File parentParent = parent.getParentFile();

    if (!parentParent.canWrite()) {
        // setWritable is only available on JDK6 and beyond
        //if (!parentParent.setWritable(true))
        //throw new IOException("Failed to set readonly-folder: " + parentParent + " to writeable");
        // FIXME DZ: since setWritable doesnt exist on jdk5, need to detect os to make dir writable
        if (SystemUtils.IS_OS_WINDOWS) {
            Runtime.getRuntime().exec("attrib -r /D" + parentParent.getAbsolutePath());
        } else if (SystemUtils.IS_OS_UNIX || SystemUtils.IS_OS_LINUX) {
            Runtime.getRuntime().exec("chmod +w " + parentParent.getAbsolutePath());
        } else {
            throw new IOException(
                    "This test is not supported on your detected platform : " + SystemUtils.OS_NAME);
        }
    }

    if (parent.exists()) {
        // FIXME DZ: since setWritable doesnt exist on jdk5, need to detect os to make dir writable
        if (SystemUtils.IS_OS_WINDOWS) {
            Runtime.getRuntime().exec("attrib -r /D" + parent.getAbsolutePath());
        } else if (SystemUtils.IS_OS_UNIX || SystemUtils.IS_OS_LINUX) {
            Runtime.getRuntime().exec("chmod +w " + parent.getAbsolutePath());
        } else {
            throw new IOException(
                    "This test is not supported on your detected platform : " + SystemUtils.OS_NAME);
        }
        if (!parent.delete())
            throw new IOException("Failed to delete folder: " + parent);
    }
}

From source file:org.nuxeo.functionaltests.drivers.ChromeDriverProvider.java

@Override
public RemoteWebDriver init(DesiredCapabilities dc) throws Exception {
    if (System.getProperty(SYSPROP_CHROME_DRIVER_PATH) == null) {
        String chromeDriverDefaultPath = null;
        String chromeDriverExecutableName = CHROME_DRIVER_DEFAULT_EXECUTABLE_NAME;
        if (SystemUtils.IS_OS_LINUX) {
            chromeDriverDefaultPath = CHROME_DRIVER_DEFAULT_PATH_LINUX;
        } else if (SystemUtils.IS_OS_MAC) {
            chromeDriverDefaultPath = CHROME_DRIVER_DEFAULT_PATH_MAC;
        } else if (SystemUtils.IS_OS_WINDOWS_XP) {
            chromeDriverDefaultPath = CHROME_DRIVER_DEFAULT_PATH_WINXP;
            chromeDriverExecutableName = CHROME_DRIVER_WINDOWS_EXECUTABLE_NAME;
        } else if (SystemUtils.IS_OS_WINDOWS_VISTA) {
            chromeDriverDefaultPath = CHROME_DRIVER_DEFAULT_PATH_WINVISTA;
            chromeDriverExecutableName = CHROME_DRIVER_WINDOWS_EXECUTABLE_NAME;
        } else if (SystemUtils.IS_OS_WINDOWS) {
            // Unknown default path on other Windows OS. To be completed.
            chromeDriverDefaultPath = CHROME_DRIVER_DEFAULT_PATH_WINVISTA;
            chromeDriverExecutableName = CHROME_DRIVER_WINDOWS_EXECUTABLE_NAME;
        }//from  w w w. j a v  a  2 s.  c  o m

        if (chromeDriverDefaultPath != null && new File(chromeDriverDefaultPath).exists()) {
            log.warn(String.format("Missing property %s but found %s. Using it...", SYSPROP_CHROME_DRIVER_PATH,
                    chromeDriverDefaultPath));
            System.setProperty(SYSPROP_CHROME_DRIVER_PATH, chromeDriverDefaultPath);
        } else {
            // Can't find chromedriver in default location, check system
            // path
            File chromeDriverExecutable = findExecutableOnPath(chromeDriverExecutableName);
            if ((chromeDriverExecutable != null) && (chromeDriverExecutable.exists())) {
                log.warn(String.format("Missing property %s but found %s. Using it...",
                        SYSPROP_CHROME_DRIVER_PATH, chromeDriverExecutable.getCanonicalPath()));
                System.setProperty(SYSPROP_CHROME_DRIVER_PATH, chromeDriverExecutable.getCanonicalPath());
            } else {
                log.error(String.format(
                        "Could not find the Chrome driver looking at %s or system path."
                                + " Download it from %s and set its path with " + "the System property %s.",
                        chromeDriverDefaultPath, "http://code.google.com/p/chromedriver/downloads/list",
                        SYSPROP_CHROME_DRIVER_PATH));
            }
        }
    }
    ChromeOptions options = new ChromeOptions();
    options.addArguments(Arrays.asList("--ignore-certificate-errors"));
    dc.setCapability(ChromeOptions.CAPABILITY, options);
    driver = new ChromeDriver(dc);
    return driver;
}

From source file:org.openoffice.maven.Environment.java

private static File guessOfficeHome() {
    File home = getenvAsFile(OFFICE_HOME);
    if (home != null) {
        return home;
    }/*  ww w . j a  v  a  2s .c  o m*/
    home = guessOfficeHomeFromPATH();
    if (home != null) {
        return home;
    }
    if (SystemUtils.IS_OS_LINUX) {
        home = tryDirs("/opt/openoffice.org3", "/usr/lib/openoffice");
    } else if (SystemUtils.IS_OS_MAC) {
        home = tryDirs("/Applications/OpenOffice.org.app", "/opt/ooo/OpenOffice.org.app");
    } else if (SystemUtils.IS_OS_WINDOWS) {
        home = tryDirs("C:/programs/OpenOffice.org3", "C:/Programme/OpenOffice.org3",
                "C:/programs/OpenOffice.org 3", "C:/Programme/OpenOffice.org 3",
                "C:/Program Files (x86)/OpenOffice.org 3");
    } else {
        home = tryDirs("/opt/openoffice.org3");
    }
    if (home == null) {
        getLog().debug("office home not found - must be set via configuration '<ooo>...</ooo>'");
    }
    return home;
}

From source file:org.openoffice.maven.Environment.java

private static File guessOoSdkHome() {
    File home = getenvAsFile(OO_SDK_HOME);
    if (home != null) {
        return home;
    }//from   www  .  j ava 2 s  .co  m
    if (SystemUtils.IS_OS_LINUX) {
        home = tryDirs("/opt/openoffice.org/basis3.2/sdk", "/usr/lib/openoffice/basis3.2/sdk");
    } else if (SystemUtils.IS_OS_MAC) {
        home = tryDirs("/Applications/OpenOffice.org3.2_SDK", "/opt/ooo/OpenOffice.org3.2_SDK");
    } else if (SystemUtils.IS_OS_WINDOWS) {
        home = tryDirs(officeHome + "/Basis/sdk", "C:/Programme/OOsdk", "C:/sdk/OpenOffice.org_3.2_SDK/sdk",
                "C:/OO_SDK/sdk");
    } else {
        home = FileFinder.tryDirs(new File(officeHome, "Basis/sdk"),
                new File("/opt/openoffice.org/basis3.2/sdk"));
    }
    if (home == null) {
        getLog().debug("SDK home not found - must be set via configuration '<sdk>...</sdk>'");
    }
    return home;
}

From source file:org.pentaho.di.core.ConstTest.java

@Test
public void testIsLinux() {
    assertEquals(SystemUtils.IS_OS_LINUX, Const.isLinux());
}

From source file:org.zeroturnaround.exec.test.InputRedirectTest.java

@Test
public void testRedirectInput() throws Exception {
    String binTrue;/*from w ww  .j a  va2 s. c  om*/
    if (SystemUtils.IS_OS_LINUX) {
        binTrue = "/bin/true";
    } else if (SystemUtils.IS_OS_MAC_OSX) {
        binTrue = "/usr/bin/true";
    } else {
        Assume.assumeTrue("Unsupported OS " + SystemUtils.OS_NAME, false);
        return; // Skip this test
    }

    // We need to put something in the buffer
    ByteArrayInputStream bais = new ByteArrayInputStream("foo".getBytes());
    ProcessExecutor exec = new ProcessExecutor().command(binTrue);
    // Test that we don't get IOException: Stream closed
    int exit = exec.redirectInput(bais).readOutput(true).execute().getExitValue();
    log.debug("Exit: {}", exit);
}

From source file:program.RunProgram.java

public static boolean isExecutableFound(workflow_properties prop) {

    if (config.getBoolean("UseAlternative")) {
        //-CASE Alternative
        String executable = prop.getAlternative();
        if (!prop.isSet("AlternativeExecutable") || executable.equals(""))
            return false;
        return (Util.FileExists(executable));
    }/*from   w  w w .  ja  v  a 2s  . com*/
    //--CASE WebServices  or internal application (java code)
    if (prop.getBoolean("WebServices") || prop.getBoolean("InternalArmadilloApplication")) {
        return true;
    } else if (SystemUtils.IS_OS_WINDOWS) {
        //--Windows
        String executable = prop.getExecutable();
        if (!prop.isSet("Executable") || executable.equals(""))
            return false;
        return (Util.FileExists(executable));
    } else if (config.getBoolean("MacOSX") || SystemUtils.IS_OS_MAC_OSX) {
        //--CASE MAC OS X
        String executable = prop.getExecutableMacOSX();
        if (!prop.isSet("ExecutableMacOSX") || executable.equals(""))
            return false;
        return (Util.FileExists(executable));
    } else if (config.getBoolean("Linux") || SystemUtils.IS_OS_LINUX || SystemUtils.IS_OS_UNIX) {
        //--CASE Linux?
        String executable = prop.getExecutableLinux();
        if (!prop.isSet("ExecutableLinux") || executable.equals(""))
            return false;
        return (Util.FileExists(executable));
    }

    return false;
}

From source file:program.RunProgram.java

public String[] updateCommandLine(String[] cli) {
    //--Note: 50 is arbitrary number large enough...
    String[] command = new String[50];
    //--Initialization
    for (int i = 0; i < 50; i++) {
        if (i < cli.length) {
            command[i] = cli[i];/* w w w. j  a  v a  2 s. c om*/
        } else
            command[i] = "";
    }

    //--CASE 1. MacOSX (Warning, 1st because MAC_OSX is Linux (lol)
    if (config.getBoolean("MacOSX") || SystemUtils.IS_OS_MAC_OSX) {
        if (command[0].equalsIgnoreCase("cmd.exe"))
            for (int i = 0; i < command.length - 2; i++)
                command[i] = command[i + 2];

        //--Hack
        if (command[0].equalsIgnoreCase("java")) {
            //--Any extra command?
            //--We locate the good spot
            if (command[2].startsWith("-Xmx") || command[2].startsWith("-classpath")) {
                command[3] = properties.getExecutableMacOSX();
            } else {
                command[2] = properties.getExecutableMacOSX();
            }
        } else {
            command[0] = properties.getExecutableMacOSX();
        }
        // return command;
    } else if (config.getBoolean("Linux") || SystemUtils.IS_OS_LINUX || SystemUtils.IS_OS_UNIX) {
        //--or CASE 2.Linux?
        //--Test if we included the cmd.exe /C
        if (command[0].equalsIgnoreCase("cmd.exe"))
            for (int i = 0; i < command.length - 2; i++)
                command[i] = command[i + 2];
        //--Hack
        //--Hack
        if (command[0].equalsIgnoreCase("java")) {
            command[2] = properties.getExecutableLinux();
        } else {
            command[0] = properties.getExecutableLinux();
        }
    }

    //--Change the - to -- if found...
    //               for (int i=0; i<command.length;i++) {
    //                   if (command[i].startsWith("-")) command[i]="-"+command[i];
    //               }

    //--CASE 3. Use Alternative^
    if (properties.getBoolean("UseAlternative")) {
        command[0] = properties.getAlternative();
    }

    // Finally return the command
    return command;
}

From source file:program.RunProgram.java

/**
 * This is the the actual run of the program
 * 1-Execute in the thread the commandline
 * 2-Catch both stderr and stdout/*from  ww  w.  j  a v a 2 s .c o m*/
 * 3-Put the program ExitValue in properties->ExitValue
 * 4-Put  both stderr and stdout in the output vector and in the "output"properties
 * @throws Exception
 */
public boolean do_run() throws Exception {

    setStatus(status_running, "\tRunning program...");
    setStatus(status_running, "<-Program Output->");
    //--Run the thread and catch stdout and stderr
    if (Docker.isProgramUseDocker(properties) && Docker.isDockerHere()) {
        Docker.executeBashFile(properties);
        setStatus(status_running, properties.get("DockerSTD"));
        String s = properties.get("DockerSTD");
        s = s.toLowerCase();
        Pattern p = Pattern.compile(".*exit is -(\\d+)-.*");
        Matcher m = p.matcher(s);
        //Util.dm(m.toString());
        int i = -1;
        if (m.find()) {
            i = Integer.parseInt(m.group(1));
        }
        Util.dm("Docker exit value is >" + Integer.toString(i) + "<");
        properties.put("ExitValue", i);
    } else {
        ProcessBuilder pb = new ProcessBuilder(commandline);
        if (properties.isSet("RunningDirectory")) {
            pb.directory(new File(properties.get("RunningDirectory")));
        }

        r = Runtime.getRuntime();
        //--Test August 2011 - For Mac OS X
        if ((config.getBoolean("MacOSX") || SystemUtils.IS_OS_MAC_OSX)) {
            if (properties.isSet("RuntimeMacOSX")) {
                String execution_type = properties.get("RuntimeMacOSX");
                //--Default
                if (execution_type.startsWith("default")) {
                    //? Not suppose to exists...
                    p = pb.start();
                }
                //--Runtime (r.exec)
                if (execution_type.startsWith("runtime")) {
                    //--IF MAC_OSX, group option if UseRuntimeMacOSX
                    String cmdm = Util.toString(commandline);
                    cmdm = Util.replaceMultiSpacesByOne(cmdm);
                    cmdm = Util.removeTrailingSpace(cmdm);
                    /*
                    for (int i=0; i<commandline.length;i++) {
                    if (!commandline[i].equals(""))
                        cmdm+=commandline[i]+" ";
                    }
                    commandline=new String[1];
                    commandline[0]=cmdm;
                    */
                    p = r.exec(cmdm);
                }
                //--Bash...
                if (execution_type.startsWith("bash (.sh)")) {
                    //--Create a new bash file
                    Util u = new Util("RunProgram.sh");
                    u.println("#!/bin/sh");
                    u.println("echo \"Executing by bash command: " + properties.getName() + "\"");
                    u.println(Util.toString(commandline));
                    //--Return the application error code
                    u.println("exit $?");
                    u.close();
                    p = r.exec("sh RunProgram.sh");
                }
            } //--End RuntimeMacOSX
              //--Run time
            else {
                //--Create a new bash file
                Util u = new Util("RunProgram.sh");
                u.println("#!/bin/sh");
                u.println("echo \"Executing by bash command: " + properties.getName() + "\"");
                u.println(Util.toString(commandline));
                //--Return the application error code
                u.println("exit $?");
                u.close();
                p = r.exec("sh RunProgram.sh");
            }
        } else if ((config.getBoolean("Linux") || SystemUtils.IS_OS_LINUX)) {
            //                Util u = new Util("RunProgram"+Util.returnTimeCode()+".sh");
            //                u.println("#!/bin/sh");
            //                u.println("echo \"Executing by bash command: "+properties.getName()+"\"");
            //                u.println(Util.toString(commandline));
            //                //--Return the application error code
            //                u.println("exit $?");
            //                u.close();
            //                p=r.exec("sh "+u.log_filename);
            //                Util.deleteFile(u.log_filename);
            String cli = Util.toString(commandline).replace("\\s+", " ");
            p = r.exec(cli); // JG 2015
        } else {
            p = pb.start();
        }

        //pb.redirectErrorStream(true)
        InputStreamThread stderr = new InputStreamThread(p.getErrorStream());
        InputStreamThread stdout = new InputStreamThread(p.getInputStream());

        int exitvalue = p.waitFor();

        //--Wait for the exitValue
        properties.put("ExitValue", exitvalue);
    }
    return true;
}