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

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

Introduction

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

Prototype

public static boolean isFamilyUnix() 

Source Link

Usage

From source file:com.smash.revolance.ui.explorer.BaseTests.java

public static String getChromeDriverPath() {
    return new File(new File("").getAbsoluteFile(), "src/test/driver/" + (OS.isFamilyUnix() ? "unix" : "win")
            + "/chromedriver" + (OS.isFamilyUnix() ? "" : ".exe")).getAbsolutePath();
}

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

/**
 * This method returns a member of {@code OperatingSystem} representing the
 * current Operating System./* w w w .j a  v  a 2s  .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.smash.revolance.ui.materials.mock.webdriver.browser.MockedBrowserController.java

@Override
public synchronized void notify(JSonWireEvent event) {
    String name = (String) event.getProp("command.name");
    String path = (String) event.getProp("command.path");
    String elementId = (String) event.getProp("command.elementId");
    String htmlAttribute = (String) event.getProp("command.elementHtmlAttribute");
    String cssAttribute = (String) event.getProp("command.elementCssAttribute");

    System.out.println("Receiving command: " + name + " with path: " + path);

    Map<String, Object> commandPayload = (Map<String, Object>) event.getProp("command.payload");

    // Just the value part in the payload
    Map<String, Object> resultPayload = new HashMap<String, Object>();

    if (isCommand(event, DriverCommand.NEW_SESSION)) {
        browser = new MockedBrowser();

        resultPayload.put("browserName", this.getClass().getSimpleName());
        resultPayload.put("browserPlatform", OS.isFamilyUnix() ? "LINUX" : "WINDOWS");
        resultPayload.put("browserVersion", "0.0.1-SNAPSHOT");
    }/* w  w  w  .ja v  a 2 s.c o m*/
    if (isCommand(event, DriverCommand.SET_WINDOW_SIZE)) {
        browser.setSize((Integer) commandPayload.get("width"), (Integer) commandPayload.get("height"));
    }
    if (isCommand(event, DriverCommand.GET_WINDOW_SIZE)) {
        Dimension dim = browser.getDimension();
        resultPayload.put("width", dim.getWidth());
        resultPayload.put("height", dim.getHeight());
    }
    if (isCommand(event, DriverCommand.SET_WINDOW_POSITION)) {
        browser.setLocation((Integer) commandPayload.get("x"), (Integer) commandPayload.get("y"));
    }
    if (isCommand(event, DriverCommand.GET_WINDOW_POSITION)) {
        Point location = browser.getLocation();
        resultPayload.put("x", location.getX());
        resultPayload.put("y", location.getY());
    }
    if (isCommand(event, DriverCommand.GET_CURRENT_URL)) {
        resultPayload.put("url", browser.getUrl());
    }
    if (isCommand(event, DriverCommand.GET)) {
        try {
            browser.goToUrl((String) commandPayload.get("url"));
        } catch (Exception e) {
            System.err.println(e);
        }
    }
    if (isCommand(event, DriverCommand.EXECUTE_SCRIPT)) {
        resultPayload.put("value", browser.executeJavaScript((String) commandPayload.get("script"),
                (Object[]) commandPayload.get("args")));
    }
    if (isCommand(event, DriverCommand.GET_ALERT_TEXT)) {
        resultPayload.put("alertStatusCode", ErrorCodes.NO_ALERT_PRESENT);
        resultPayload.put("alertMessage", "No alert is present");
    }
    if (isCommand(event, DriverCommand.GET_TITLE)) {
        resultPayload.put("title", browser.getTitle());
    }
    if (isCommand(event, DriverCommand.SCREENSHOT)) {
        resultPayload.put("screenshot", browser.takeScreenshot());
    }
    if (isCommand(event, DriverCommand.FIND_ELEMENTS)) {
        List<String> elements = browser.findElements((String) commandPayload.get("value"));
        resultPayload.put("elementList", buildElementList(elements));
    }
    if (isCommand(event, DriverCommand.GET_ELEMENT_LOCATION)) {
        Point location = browser.getElementLocation(elementId);

        resultPayload.put("elementX", String.valueOf(location.getX()));
        resultPayload.put("elementY", String.valueOf(location.getY()));
    }
    if (isCommand(event, DriverCommand.GET_ELEMENT_SIZE)) {
        Dimension dim = browser.getElementSize(elementId);

        resultPayload.put("elementW", String.valueOf(dim.getWidth()));
        resultPayload.put("elementH", String.valueOf(dim.getHeight()));
    }
    if (isCommand(event, DriverCommand.GET_ELEMENT_TAG_NAME)) {
        resultPayload.put("elementTagName", browser.getElementTag(elementId));
    }
    if (isCommand(event, DriverCommand.GET_ELEMENT_TEXT)) {
        resultPayload.put("elementText", browser.getElementText(elementId));
    }
    if (isCommand(event, DriverCommand.GET_ELEMENT_ATTRIBUTE)) {
        resultPayload.put("elementHtmlAttributeValue",
                browser.getElementHtmlAttribute(elementId, htmlAttribute));
    }
    if (isCommand(event, DriverCommand.IS_ELEMENT_DISPLAYED)) {
        resultPayload.put("isElementDisplayed", browser.isElementDisplayed(elementId));
    }
    if (isCommand(event, DriverCommand.GET_ELEMENT_VALUE_OF_CSS_PROPERTY)) {
        resultPayload.put("elementCssAttributeValue", browser.getElementCssAttribute(elementId, cssAttribute));
    }
    event.setProp("command.value", resultPayload);
    notifyAll();
}

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 ww.  j ava 2 s. 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:GUI.GraphicalInterface.java

/**
 * Constructor to initialize GUI components and data members to default
 * value.//from   ww w.j  av a2  s. c  om
 */
public GraphicalInterface() {
    initComponents();

    Platform.init();
    /* Set variables to null */
    m_command = m_history = m_completeCommand = "";
    m_internalPrefix = m_isManualExecution = false;
    m_defaultDescription = "Welcome to Grafcom!\n"
            + "Select a command from the list to view its description. \n"
            + "Descriptions help you learn how commands work, what arguments they require\n"
            + "and what values they return.\n" + "================";
    m_defaultTerminal = ">> Welcome to Grafcom!\n"
            + ">> This is the terminal text area which displays the output \n"
            + "of all the commands you run along with error messages.\n"
            + ">> Select command from drop-down list or enter manually, \n"
            + "click Execute and see the output!\n" + "====================\n";
    terminalJTextArea.setText(m_defaultTerminal);
    descriptionJTextArea.setText(m_defaultDescription);

    m_runtime = Runtime.getRuntime();
    m_description = new Description();
    bg = new ButtonGroup();
    bg.add(listJRadioButton);
    bg.add(manualJRadioButton);

    setFont();
    /* set icon in title bar */
    ImageIcon icon = new ImageIcon("Resources/icon/utilities-terminal.png");
    this.setIconImage(icon.getImage());

    /* Set default execution path and update GUI */
    m_workingDir = new File(System.getProperty("user.dir"));
    workdirJFileChooser.setCurrentDirectory(m_workingDir);
    terminalJTextArea.append("\n" + m_workingDir.getPath() + "> ");

    /* if windows then disable root access */
    rootJCheckBox.setEnabled(OS.isFamilyUnix());

    commandJTextField.setEnabled(false);
    executeManualJButton.setEnabled(false);

    /* set command list */
    commandJComboBox.setModel(new javax.swing.DefaultComboBoxModel(Platform.getCommandList().toArray()));
}

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

/**
 * Stops an already running Appium server.
 *//*from w w w .  j  a  v  a 2 s.  com*/
@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:GUI.GraphicalInterface.java

private void executeJButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_executeJButtonActionPerformed
    /* Clear terminal area if needed */
    if (clearJCheckBox.isSelected() == true) {
        terminalJTextArea.setText(m_defaultTerminal);
    }/*w  w w  .j a v  a2 s  .com*/

    if (OS.isFamilyUnix() && m_command.equals("traceroute")) {
        /* set Absolute path to traceroute in Linux */
        m_command = "/usr/sbin/traceroute";
    }

    m_internalPrefix = OS.isFamilyWindows();
    String prefix = (m_internalPrefix) ? "cmd.exe /c " : "";

    String option = optionJComboBox.getSelectedItem().toString();
    option = option.startsWith("(") ? "" : " " + option;

    String optionarg = optionJTextField.getText();
    optionarg = optionarg.trim().isEmpty() ? "" : " " + optionarg.trim();

    String cmdarg = argumentJTextField.getText();
    cmdarg = cmdarg.trim().isEmpty() ? "" : " " + cmdarg.trim();

    m_completeCommand = m_command + option + optionarg + cmdarg;
    cmdLine = CommandLine.parse(prefix + m_completeCommand);

    /* Update status bar */
    statusJLabel.setText("Running command... " + m_completeCommand);
    statusJProgressBar.setIndeterminate(true);

    terminalJTextArea.append(m_completeCommand + "\n");
    setScrollBar(jScrollPane1, 100);

    m_isManualExecution = false;
    t = new Thread(new newProcess(), "Process-Thread");
    t.start();

    /* Add command to history */
    if (!historyJCheckBox.isSelected()) {
        m_history += m_completeCommand + "\n";
    }

    /* Clear states */
    if (clearargJCheckBox.isSelected()) {
        argumentJTextField.setText("");
        optionJTextField.setText("");
    }
    passwordJTextField.setText("");
    passwordJTextField.setEnabled(false);
    rootJCheckBox.setSelected(false);
}

From source file:org.apache.camel.component.exec.ExecJava8IssueTest.java

@Test
public void test() throws Exception {

    if (!OS.isFamilyUnix()) {
        System.err.println("The test 'CamelExecTest' does not support the following OS : "
                + System.getProperty("os.name"));
        return;//from   w  w w .  j a  v  a 2  s.co m
    }

    String tempFilePath = tempDir.getAbsolutePath() + "/" + tempFileName;

    final File script = File.createTempFile("script", ".sh", tempDir);

    writeScript(script);

    final String exec = "bash?args=" + script.getAbsolutePath() + " " + tempFilePath + "&outFile="
            + tempFilePath;

    DefaultCamelContext context = new DefaultCamelContext();
    context.addRoutes(new RouteBuilder() {
        @Override
        public void configure() throws Exception {
            from("direct:source").to("file:" + tempDir.getAbsolutePath() + "?fileName=" + tempFileName)
                    .to("exec:" + exec).process(new Processor() {
                        @Override
                        public void process(Exchange exchange) throws Exception {
                            String output = exchange.getIn().getBody(String.class);
                            assertEquals("hello world\n", output);
                        }
                    });

        }
    });

    context.start();

    ProducerTemplate pt = context.createProducerTemplate();
    String payload = "hello";

    pt.sendBody("direct:source", payload);
}

From source file:org.apache.camel.component.exec.ExecScriptTest.java

private File getExecScriptFileOrNull(String scriptNameBase) {
    String resource = null;//from w  w  w  .j a  v  a2 s. c o  m
    if (OS.isFamilyWindows()) {
        resource = scriptNameBase + ".bat";
    } else if (OS.isFamilyUnix()) {
        resource = scriptNameBase + ".sh";
    }
    File resourceFile = getClasspathResourceFileOrNull(resource);
    // TODO use canExecute here (available since java 1.6)
    if (resourceFile != null && !resourceFile.canRead()) {
        logger.warn("The resource  " + resourceFile.getAbsolutePath() + " is not readable!");
        // it is not readable, do not try to execute it
        return null;
    }
    return resourceFile;
}

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

public String getEditor() {
    String editor;/*  w ww . ja v a 2s.com*/

    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;
}