Example usage for org.apache.commons.exec OS isFamilyMac

List of usage examples for org.apache.commons.exec OS isFamilyMac

Introduction

In this page you can find the example usage for org.apache.commons.exec OS isFamilyMac.

Prototype

public static boolean isFamilyMac() 

Source Link

Usage

From source file:com.ariatemplates.seleniumjavarobot.Main.java

public static void main(String[] args) throws Exception {
    SeleniumJavaRobot seleniumJavaRobot = new SeleniumJavaRobot();
    String browser;//from  www.ja  v  a2 s  .  com
    seleniumJavaRobot.autoRestart = false;
    if (OS.isFamilyMac()) {
        browser = "safari";
    } else {
        browser = "firefox";
    }
    seleniumJavaRobot.url = "http://localhost:7777/__attester__/slave.html";
    String usageString = String.format(
            "Usage: selenium-java-robot [options]\nOptions:\n  --auto-restart\n  --url <url> [default: %s]\n  --browser <browser> [default: %s, accepted values: %s]\n  -DpropertyName=value",
            seleniumJavaRobot.url, browser, BROWSERS_LIST.toString());
    for (int i = 0, l = args.length; i < l; i++) {
        String curParam = args[i];
        if ("--browser".equalsIgnoreCase(curParam) && i + 1 < l) {
            browser = args[i + 1];
            i++;
        } else if ("--url".equalsIgnoreCase(curParam) && i + 1 < l) {
            seleniumJavaRobot.url = args[i + 1];
            i++;
        } else if ("--auto-restart".equalsIgnoreCase(curParam)) {
            seleniumJavaRobot.autoRestart = true;
        } else if ("--version".equalsIgnoreCase(curParam)) {
            System.out.println(Main.class.getPackage().getImplementationVersion());
            return;
        } else if ("--help".equalsIgnoreCase(curParam)) {
            System.out.println(usageString);
            return;
        } else {
            Matcher matcher = SET_SYSTEM_PROPERTY_REGEXP.matcher(curParam);
            if (matcher.matches()) {
                System.setProperty(matcher.group(1), matcher.group(2));
            } else {
                System.err.println("Unknown command line option: " + curParam);
                System.err.println(usageString);
                return;
            }
        }
    }
    seleniumJavaRobot.robotizedBrowserFactory = LocalRobotizedBrowserFactory
            .createRobotizedWebDriverFactory(browser);
    seleniumJavaRobot.start();
    closeOnStreamEnd(seleniumJavaRobot, System.in);
    closeOnProcessEnd(seleniumJavaRobot);
}

From source file:com.github.cshubhamrao.MediaConverter.Library.OSUtils.java

/**
 * This method returns a member of {@code OperatingSystem} representing the
 * current Operating System.//from   www  . j a  v a 2 s .c o  m
 *
 * @since 1.0.2
 * @return Current Operating System
 */
public static OperatingSystem getCurrentOS() {
    OperatingSystem currentOS = OperatingSystem.UNKNOWN;
    if (OS.isFamilyUnix()) {
        currentOS = OperatingSystem.LINUX;
    }
    if (OS.isFamilyMac()) {
        currentOS = OperatingSystem.MAC;
    }
    if (OS.isFamilyWindows()) {
        currentOS = OperatingSystem.WINDOWS;
    }
    return currentOS;
}

From source file:com.github.genium_framework.appium.support.command.CommandManager.java

/**
 * Constructs a CommandLine object depending on the current running
 * operating system using the number of arguments passed to it.
 *
 * @param command The native OS command to run or an absolute path to an
 * executable to run./*from   w  w  w . j ava2s.  co m*/
 * @param parameters The command parameters.
 * @param arguments String arguments of the command to formulate from.
 * @return CommandLine object that represents the command you want to
 * execute.
 */
public static CommandLine createCommandLine(String command, String[] parameters, String... arguments) {
    CommandLine commanddLine = null;

    // add the command to be executed
    if (OS.isFamilyWindows()) {
        commanddLine = new CommandLine("\"" + command + "\"");
    } else if (OS.isFamilyMac() || OS.isFamilyUnix()) {
        commanddLine = new CommandLine(command.contains(" ") ? "'" + command + "'" : command);
    } else {
        throw new UnsupportedOperationException("Unsupported operating system.");
    }

    // add the command parameters
    if (OS.isFamilyWindows()) {
        for (String parameter : parameters) {
            commanddLine.addArgument("\"" + parameter + "\"", false);
        }
    } else if (OS.isFamilyMac() || OS.isFamilyUnix()) {
        for (String parameter : parameters) {
            commanddLine.addArgument(parameter.contains(" ") ? "'" + parameter + "'" : parameter, false);
        }
    }

    // add the command arguments
    for (String argument : arguments) {
        // you have to pass the false value and disable handling quoting
        // otherwise the OS won't be able to run the shell file on MAc OS
        commanddLine.addArgument(argument, false);
    }

    return commanddLine;
}

From source file:com.github.genium_framework.appium.support.server.AppiumServer.java

/**
 * Search the operating system for an Appium server installation directory.
 *
 * @return A File representation to the Appium server installation
 * directory.// w w  w .  j  ava 2s.com
 */
private File searchForServerDirectory() {
    if (OS.isFamilyWindows()) {
        if (getArch().equals("32")) {
            return doesDirectoryExists(System.getenv("ProgramFiles") + "/Appium");
        } else {
            // must be the x86_64
            return doesDirectoryExists(System.getenv("ProgramFiles") + " (x86)/Appium");
        }
    } else if (OS.isFamilyMac()) {
        return doesDirectoryExists("/Applications/Appium.app/Contents/Resources");
    }

    // server directrory was not found.
    throw new ServerDirectoryNotFoundException();
}

From source file:com.github.genium_framework.appium.support.server.AppiumServer.java

/**
 * Stops an already running Appium server.
 *//*from   w w  w  . j av  a 2 s . c  o m*/
@Override
public void stopServer() {
    String[] stopServerCommand = null;

    try {
        if (OS.isFamilyWindows()) {
            stopServerCommand = new String[] { "cmd", "/c",
                    "echo off & FOR /F \"usebackq tokens=5\" %a in (`netstat -nao ^| findstr /R /C:\""
                            + _serverArguments.get(AppiumCommonArgs.PORT_NUMBER)
                            + " \"`) do (FOR /F \"usebackq\" %b in (`TASKLIST /FI \"PID eq %a\" ^| findstr /I node.exe`) do taskkill /F /PID %a)" };
        } else if (OS.isFamilyMac()) {
            // Using command substitution
            stopServerCommand = new String[] { "/bin/sh", "-c",
                    "PID=\"$(lsof -i -P | pgrep -f node)\";kill -9 $PID" };
        } else if (OS.isFamilyUnix()) {
            // Using command substitution
            stopServerCommand = new String[] { "/bin/env",
                    "PID=\"$(lsof -i -P | pgrep -f node)\";kill -9 $PID" };
        } else {
            throw new UnsupportedOperationException("Not supported yet for this operating system...");
        }

        LOGGER.log(Level.INFO, "Stopping the server with the command: {0}",
                CommandManager.convertCommandStringArrayToString(stopServerCommand));
        String stopServerOutput = CommandManager.executeCommandUsingJavaRuntime(stopServerCommand, true);
        LOGGER.log(Level.INFO, "Server stopping output: {0}", stopServerOutput);
    } catch (UnsupportedOperationException ex) {
        throw ex;
    } catch (Exception ex) {
        LOGGER.log(Level.SEVERE, "An exception was thrown.", ex);
    }
}

From source file:org.docwhat.iated.AppState.java

public String getEditor() {
    String editor;/*from   w w  w .j  ava  2 s. c  o  m*/

    editor = store.get(EDITOR, "");
    if (null == editor || "".equals(editor)) {
        if (OS.isFamilyMac()) {
            editor = "/Applications/TextEdit.app";
        } else if (OS.isFamilyUnix()) {
            editor = "gvim";
        } else if (OS.isFamilyWindows() || OS.isFamilyWin9x()) {
            editor = "notepad.exe";
        } else {
            editor = "";
        }
    }
    return editor;
}

From source file:org.docwhat.iated.AppState.java

public String editFile(File file) {
    String editor = getEditor();/*from w  w w. ja va2 s.  c  om*/
    CommandLine cmd;

    if (OS.isFamilyMac() && editor.matches(".*\\.app")) {
        cmd = new CommandLine("/usr/bin/open");
        cmd.addArgument("-a").addArgument(editor).addArgument(file.toString());
    } else {
        cmd = new CommandLine(editor);
        cmd.addArgument(file.toString());
    }

    Executor executor = new DefaultExecutor();
    try {
        executor.execute(cmd);
    } catch (ExecuteException ex) {
        //TODO Do something meaningful with the exception.
        throw new RuntimeException(ex);
    } catch (IOException ex) {
        //TODO Do something meaningful with the exception.
        throw new RuntimeException(ex);
    }
    return "bogus-token";
}

From source file:org.docwhat.iated.ui.PreferencesDialog.java

public String getDefaultAppDirectory() {
    if (OS.isFamilyMac()) {
        return "/Applications";
    } else if (OS.isFamilyWindows() || OS.isFamilyWin9x()) {
        //TODO There is probably a better directory.
        return "C:\\";
    } else if (OS.isFamilyUnix()) {
        return "/usr/bin";
    } else {/*from  w  w  w .ja va 2  s  . com*/
        return ".";
    }
}

From source file:org.docwhat.iated.ui.PreferencesDialog.java

private void browseButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_browseButtonActionPerformed
    JFileChooser chooser = new JFileChooser();
    chooser.setDialogTitle("Please select your editor");

    chooser.setCurrentDirectory(new File(getDefaultAppDirectory()));

    chooser.setFileFilter(new FileFilter() {
        public boolean accept(File f) {
            if (OS.isFamilyMac() && f.isDirectory() && f.getName().toLowerCase().endsWith(".app")) {
                return (true);
            }/*w  ww . j av a  2s . co  m*/
            return f.canExecute();
        }

        public String getDescription() {
            return "Applications";
        }
    });

    int result = chooser.showOpenDialog(this);

    if (result == JFileChooser.APPROVE_OPTION) {
        editorField.setText(chooser.getSelectedFile().getPath());
    }
}

From source file:org.eclipse.tycho.extras.docbundle.JavadocRunner.java

protected String getExecutable() {
    log.debug("Find javadoc executable");

    if (this.options.getExecutable() != null) {
        // prefer the specific one
        log.debug("Using specified javadoc: " + options.getExecutable());
        return this.options.getExecutable();
    }/*from   w w w .j av  a2 s  .c om*/

    log.debug("Toolchain manager: " + toolchainManager);

    if (this.toolchainManager != null) {
        // try the toolchain
        final Toolchain tc = this.toolchainManager.getToolchainFromBuildContext("jdk", this.session);
        log.debug("Toolchain: " + tc);

        if (tc != null) {
            final String exe = tc.findTool("javadoc");
            log.debug("Toolchain Tool: " + exe);
            if (exe != null) {
                return exe;
            }
        }
    }

    String javaHome = System.getProperty("java.home");
    String javadocFromJavaHome;

    // derive path to javac from java.home similar to org.codehaus.plexus.compiler.javac.JavacCompiler.getJavacExecutable() in plexus-compiler-javac
    if (OS.isFamilyMac()) {
        javadocFromJavaHome = javaHome + File.separator + "bin" + File.separator + "javadoc";
    } else {
        javadocFromJavaHome = javaHome + File.separator + ".." + File.separator + "bin" + File.separator
                + "javadoc";
    }

    if (OS.isFamilyWindows()) {
        javadocFromJavaHome += ".exe";
    }

    log.debug("Testing javadoc from java.home = " + javadocFromJavaHome);

    if (new File(javadocFromJavaHome).canExecute()) {
        return javadocFromJavaHome;
    }

    log.debug("Using path fallback");

    // fall back
    return "javadoc";
}