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

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

Introduction

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

Prototype

boolean IS_OS_WINDOWS

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

Click Source Link

Document

Is true if this is Windows.

The field will return false if OS_NAME is null.

Usage

From source file:org.lnicholls.galleon.server.Server.java

private static void rollOverLog(Logger root, String appenderName, String appenderRefName, String filename) {
    AsyncAppender asyncAppender = (AsyncAppender) root.getAppender(appenderName);
    if (asyncAppender != null) {
        RollingFileAppender rollingFileAppender = (RollingFileAppender) asyncAppender
                .getAppender(appenderRefName);
        if (rollingFileAppender != null) {
            if (!SystemUtils.IS_OS_WINDOWS) {
                if (rollingFileAppender.getFile() != null) {
                    File file = new File(rollingFileAppender.getFile());
                    if (!file.exists())
                        rollingFileAppender.setFile(System.getProperty("logs") + "/" + filename);
                } else
                    rollingFileAppender.setFile(System.getProperty("logs") + "/" + filename);
            }//from   w  w w. ja va2 s  .co m
            rollingFileAppender.rollOver();
        }
    }
}

From source file:org.lnicholls.galleon.util.FileGatherer.java

public static final File followLink(File file) {
    if (SystemUtils.IS_OS_WINDOWS) {
        if (!file.exists()) {
            if (log.isDebugEnabled())
                log.debug("followLink() does not exist: " + file.getAbsolutePath());
            return null;
        }//  ww w.  j  a va2s .  co m
        try {
            JShellLink windowsShortcut = new JShellLink(file.getParent(),
                    file.getName().substring(0, file.getName().lastIndexOf(".")));
            windowsShortcut.load();
            file = new File(windowsShortcut.getPath());
            return file;
        } catch (Exception ex) {
            Tools.logException(FileGatherer.class, ex, file.getAbsolutePath());
            return null;
        }
    }
    return file;
}

From source file:org.lnicholls.galleon.util.FileGatherer.java

public static final File resolveLink(File file) {
    // Is this a Windows shortcut?
    if (SystemUtils.IS_OS_WINDOWS) {
        if (FileFilters.linkFilter.accept(file)) {
            return resolveLink(followLink(file));
        } else {/* ww  w.  ja v  a 2  s  .c  o m*/
            return file;
        }
    }
    return file;
}

From source file:org.lnicholls.galleon.util.Tools.java

public static Toolkit getDefaultToolkit() {
    // return Toolkit.getDefaultToolkit();
    try {/*from  ww w  .ja va  2 s  . c  o  m*/
        String headless = System.getProperty("java.awt.headless");
        if (headless == null || !headless.equals("true"))
            try {
                if (SystemUtils.IS_OS_WINDOWS)
                    return (Toolkit) Class.forName("sun.awt.windows.WToolkit").newInstance();
                else if (SystemUtils.IS_OS_LINUX)
                    return (Toolkit) Class.forName("sun.awt.motif.MToolkit").newInstance();
                else if (SystemUtils.IS_OS_MAC_OSX)
                    return (Toolkit) Class.forName("apple.awt.CToolkit").newInstance();
            } catch (Throwable ex) {
            }
        return Toolkit.getDefaultToolkit();
    } catch (Throwable ex) {
        try {
            return (Toolkit) Class.forName("com.eteks.awt.PJAToolkit").newInstance();
        } catch (Exception ex2) {

        }
    }
    return null;
}

From source file:org.lsc.webai.utils.ForkProcess.java

public void fork(String className, String[] params, Map<String, String> env) {
    builder = new ProcessBuilder();
    builder.directory(new File(this.getClass().getClassLoader().getResource(".").getPath()));
    List<String> commands = new ArrayList<String>();
    if (SystemUtils.IS_OS_WINDOWS) {
        commands.add("\"" + System.getProperty("java.home") + "\\bin\\java.exe\"");
    } else {//  w  w w  .  java2s .  co  m
        commands.add(System.getProperty("java.home") + "/bin/java");
    }
    commands.add("-classpath");
    // Add the Run Jetty Run classpath
    commands.add(getClasspath());
    for (Entry<String, String> envItem : env.entrySet()) {
        commands.add("-D" + envItem.getKey() + "=" + envItem.getValue());
    }
    if (debug) {
        commands.add("-Xdebug");
        commands.add("-Xrunjdwp:transport=dt_socket,address=" + debugPort + ",server=y,suspend=y");
    }
    commands.add(className);
    Collections.addAll(commands, params);
    if (debug) {
        List<String> interpretor = new ArrayList<String>();
        if (SystemUtils.IS_OS_WINDOWS) {
            interpretor.add(System.getenv("SystemRoot") + "\\system32\\cmd.exe");
            interpretor.add("/U");
            interpretor.add("/K");
            interpretor.add(StringUtils.join(commands, " "));
        } else {
            interpretor.add("/bin/sh");
            interpretor.add("-c");
            interpretor.add(StringUtils.join(commands, " "));
        }
        builder.command(interpretor);
    } else {
        builder.command(commands);
    }
    builder.environment().putAll(env);
    this.run();
    while (process == null) {
        try {
            Thread.sleep(100);
        } catch (InterruptedException e) {
        }
    }
    output = new DataOutputStream(process.getOutputStream());
    input = new BufferedReader(new InputStreamReader(process.getInputStream(), Charset.forName("UTF-8")));
    error = new BufferedReader(new InputStreamReader(process.getErrorStream(), Charset.forName("UTF-8")));
}

From source file:org.lsc.webai.utils.ForkProcess.java

private String getClasspath() {
    // Hack to handle Run Jetty Run Eclipse plugin
    String rjrClassPath = System.getProperty("rjrclasspath", null);
    if (rjrClassPath != null) {
        try {//from ww w . j a v a2s .co m
            return new URI(rjrClassPath).getPath();
        } catch (URISyntaxException e) {
        }
    }
    if (System.getProperty("LSC_HOME") != null) {
        StringBuffer cp = new StringBuffer();
        File lscHome = new File(System.getProperty("LSC_HOME"), "jetty" + File.separator + "webapps"
                + File.separator + "lsc-webai" + File.separator + "WEB-INF" + File.separator + "lib");
        if (lscHome.exists() && lscHome.isDirectory()) {
            for (String filename : lscHome.list(new SuffixFileFilter(".jar"))) {
                if (cp.length() > 0) {
                    if (SystemUtils.IS_OS_WINDOWS) {
                        cp.append(";");
                    } else {
                        cp.append(":");
                    }
                }
                cp.append(lscHome.getAbsolutePath() + File.separator + filename);
            }
            return cp.toString();
        }
    }
    return System.getProperty("java.class.path", null);
}

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

public int fire() {
    try {//from www  . ja  va  2  s.  co  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.test.infrastructure.process.MuleProcessController.java

public MuleProcessController(String muleHome, int timeout) {
    controller = SystemUtils.IS_OS_WINDOWS ? new WindowsController(muleHome, timeout)
            : new UnixController(muleHome, timeout);
}

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  www  . j  a va2  s  .  c  om*/
    }

    // 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.n0pe.asadmin.AsAdmin.java

/**
 * Run the given AsAdmin command./*from   w ww  .j a  v  a 2s.com*/
 * 
 * @param cmd AsAdmin command to be run
 * @throws org.n0pe.asadmin.AsAdminException AsAdminException
 */
public void run(final IAsAdminCmd cmd) throws AsAdminException {
    try {
        final File gfBinPath = new File(config.getGlassfishHome() + File.separator + "bin");
        final String[] cmds = buildProcessParams(cmd, config);
        cmds[0] = gfBinPath + File.separator + cmds[0];
        int exitCode;
        final Process proc;
        String[] env = buildEnvironmentStrings(config.getEnvironmentVariables());
        if (SystemUtils.IS_OS_WINDOWS) {
            // Windows
            final String command = "\"\"" + StringUtils.join(cmds, "\" \"") + "\"\"";
            final String[] windowsCommand;
            if (SystemUtils.IS_OS_WINDOWS_95 || SystemUtils.IS_OS_WINDOWS_98 || SystemUtils.IS_OS_WINDOWS_ME) {
                windowsCommand = new String[] { "command.com", "/C", command };
            } else {
                windowsCommand = new String[] { "cmd.exe", "/C", command };
            }
            outPrintln("Will run the following command: " + StringUtils.join(windowsCommand, " "));
            if (env.length > 0) {
                proc = Runtime.getRuntime().exec(windowsCommand, env);
            } else {
                proc = Runtime.getRuntime().exec(windowsCommand);
            }
        } else {
            // Non Windows
            outPrintln("Will run the following command: " + StringUtils.join(cmds, " "));
            proc = Runtime.getRuntime().exec(cmds, env);
        }
        final ProcessStreamGobbler errorGobbler = new ProcessStreamGobbler(cmd, proc.getErrorStream(),
                ProcessStreamGobbler.ERROR);
        final ProcessStreamGobbler outputGobbler = new ProcessStreamGobbler(cmd, proc.getInputStream(),
                ProcessStreamGobbler.OUTPUT);
        errorGobbler.start();
        outputGobbler.start();
        exitCode = proc.waitFor();
        if (exitCode != 0) {
            throw new AsAdminException("asadmin invocation failed and returned : " + String.valueOf(exitCode));
        }
    } catch (final InterruptedException ex) {
        throw new AsAdminException("AsAdmin error occurred: " + ex.getMessage(), ex);
    } catch (final IOException ex) {
        throw new AsAdminException("AsAdmin error occurred: " + ex.getMessage(), ex);
    }
}