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

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

Introduction

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

Prototype

public static boolean isFamilyWindows() 

Source Link

Usage

From source file:org.fuin.esmp.EventStoreStopMojo.java

private void init() throws MojoExecutionException {

    // Supply variables that are OS dependent
    if (OS.isFamilyWindows()) {
        if (command == null) {
            command = "taskkill";
        }/*www. j a v  a 2 s  .  c o  m*/
    } else if (OS.isFamilyUnix() || OS.isFamilyMac()) {
        if (command == null) {
            command = "kill";
        }
    } else {
        if (command == null) {
            throw new MojoExecutionException("Unknown OS - You must use the 'command' parameter");
        }
    }

}

From source file:org.opennms.web.rest.v1.MeasurementsRestServiceITCase.java

protected static String findRrdtool() {
    try {/* w w w. j  a va  2s. c  o  m*/
        @SuppressWarnings("unchecked")
        final Map<String, String> env = new HashMap<String, String>(EnvironmentUtils.getProcEnvironment());
        if (env.get("PATH") != null) {
            final String pathVar = env.get("PATH");
            if (!OS.isFamilyWindows()) {
                final List<String> paths = new ArrayList<>(Arrays.asList(pathVar.split(":")));
                paths.add("/usr/local/bin");
                paths.add("/usr/local/sbin");
                for (final String path : paths) {
                    final String tryme = path + File.separator + "rrdtool";
                    if (new File(tryme).exists()) {
                        return tryme;
                    }
                }
            }
        }
        return "rrdtool";
    } catch (final Exception e) {
        throw new RuntimeException(e);
    }
}

From source file:org.sourcepit.common.maven.testing.ExternalMavenTest.java

protected CommandLine newCmd(File binDir, String bat, String sh, String... arguments) {
    final CommandLine cmd;
    if (OS.isFamilyWindows() || OS.isFamilyWin9x()) {
        cmd = process.newCommandLine(new File(binDir, bat));
    } else if (OS.isFamilyUnix() || OS.isFamilyMac()) {
        cmd = process.newCommandLine("sh", new File(binDir, sh).getAbsolutePath());
    } else {/*from   ww w . j  a  v a2s. c  o  m*/
        throw new AssertionFailedError("Os family");
    }
    cmd.addArguments(arguments);
    return cmd;
}

From source file:org.stem.ExternalNode.java

private CommandLine newJavaCommandLine() {
    String javaExecPath = null;/*from   w ww  .  j  a  v a  2 s  . c o  m*/

    Toolchain toolchain = getToolchain();

    if (toolchain != null) {
        log.info("Toolchain: " + toolchain);
        javaExecPath = toolchain.findTool("java");

    } else if (OS.isFamilyWindows()) {
        String exec = "java.exe";
        String path = System.getenv("PATH");
        if (path != null) {
            for (String elem : StringUtils.split(path, File.pathSeparator)) {
                File file = new File(elem, exec);
                if (file.exists()) {
                    javaExecPath = file.getAbsolutePath();
                    break;
                }
            }
        }

    }

    if (null == javaExecPath) {
        javaExecPath = "java";
    }

    return new CommandLine(javaExecPath);
}

From source file:pl.net.ptak.InstallShieldBuildMojo.java

/**
 * Verifies that configuration is satisfied to bild the project and builds it.
 * /*from   www .java 2  s .co m*/
 * @throws MojoExecutionException when plugin is misconfigured
 * @throws MojoFailureException when plugin execution result was other than expected
 * @see org.apache.maven.plugin.AbstractMojo#execute()
 */
public void execute() throws MojoExecutionException, MojoFailureException {

    if (!OS.isFamilyWindows()) {
        throw new MojoExecutionException("This plugin is for Windows systems only");
    }

    if (!installshieldOutputDirectory.exists()) {
        installshieldOutputDirectory.mkdirs();
    }

    if (installshieldProjectFile == null || !installshieldProjectFile.exists()) {
        if (failWhenNoInstallshieldFile) {
            getLog().error(String.format("IS Project File available: %b", installshieldProjectFile.exists()));
            throw new MojoFailureException("InstallShield project file not found");
        } else {
            getLog().info("IS Project File not found. IS build skipped");
        }
    } else {

        String canonicalProjectFilePath = resolveCanonicalPath(installshieldProjectFile);

        getLog().info(String.format("About to build file %s", canonicalProjectFilePath));

        String canonicalOutputDirectoryPath = resolveCanonicalPath(installshieldOutputDirectory);

        getLog().info(String.format("Output will be placed in %s", canonicalOutputDirectoryPath));

        CommandLine installshieldCommandLine = new CommandLine(installshieldExecutable);

        addCmdLnArguments(installshieldCommandLine, "-p", canonicalProjectFilePath);
        addCmdLnArguments(installshieldCommandLine, "-b", canonicalOutputDirectoryPath);
        if (usePomVersion && null != version && !version.isEmpty()) {
            addCmdLnArguments(installshieldCommandLine, "-y", version);

        }

        if (null != productConfiguration && !productConfiguration.isEmpty()) {
            addCmdLnArguments(installshieldCommandLine, "-a", productConfiguration);
        }

        if (null != productRelease && !productRelease.isEmpty()) {
            addCmdLnArguments(installshieldCommandLine, "-r", productRelease);
        }

        if (null != properties && !properties.isEmpty()) {
            for (Entry<String, String> entry : properties.entrySet()) {
                addCmdLnArguments(installshieldCommandLine, "-z",
                        String.format("%s=%s", entry.getKey(), entry.getValue()));
            }
        }

        if (null != pathVariables && !pathVariables.isEmpty()) {
            for (Entry<String, String> entry : pathVariables.entrySet()) {
                addCmdLnArguments(installshieldCommandLine, "-l",
                        String.format("%s=%s", entry.getKey(), entry.getValue()));
            }
        }

        Executor exec = new DefaultExecutor();

        getLog().debug(
                String.format("IS Build Command to be executed: %s", installshieldCommandLine.toString()));

        try {
            int exitCode = exec.execute(installshieldCommandLine);
            getLog().debug(String.format("IS build exit code: %d", exitCode));
            if (exitCode != 0) {
                throw new MojoFailureException("Failed to build IS project");
            }
        } catch (IOException e) {
            String errorMessage = "Failed to execute InstallShield build";
            getLog().error(errorMessage);
            getLog().debug("Details to failure: ", e);
            throw new MojoFailureException(errorMessage);
        }
    }

}

From source file:Utility.Description.java

/**
 * Returns description of {@code command} argument as {@code String}.
 * <br> note: returns {@code null} if OS is not Linux or Windows based.
 *
 * @param command command name whose description is fetched
 * @return description of {@code command} passed as argument
 *///from  ww  w.  ja  v  a 2 s.c  o  m
public String getCommandData(String command) {
    String foldername;
    if (OS.isFamilyUnix()) {
        foldername = "linux";
    } else if (OS.isFamilyWindows()) {
        foldername = "windows";
    } else {
        return null;
    }

    String filename = "Resources/description/" + foldername + "/" + command + ".txt";
    ClassLoader CL = this.getClass().getClassLoader();
    InputStream IS = CL.getResourceAsStream(filename);
    BufferedReader br = new BufferedReader(new InputStreamReader(IS));

    String m_description = "";
    try {
        String line = "";
        while (line != null) {
            m_description += line + "\n";
            line = br.readLine();
        }
    } catch (IOException ex) {
        Logger.getLogger(Description.class.getName()).log(Level.SEVERE, null, ex);
    }
    return m_description;
}

From source file:Utility.Platform.java

/**
 * Returns the name of the text editor according to operating system.
 * <br> note: empty string returned if OS name does not start with Linux or
 * Windows.//from  w  w  w  .j  ava2s  . c  o  m
 *
 * @return name of text editor as per OS
 */
public static String getTextEditor() {
    m_textEditor = "";
    if (OS.isFamilyUnix()) {
        m_textEditor = "gedit";
    } else if (OS.isFamilyWindows()) {
        m_textEditor = "notepad.exe";
    }

    return m_textEditor;
}

From source file:Utility.Platform.java

/**
 * Adds commands to list according to operating system and returns the list.
 *
 * @return {@code ArrayList<String>} of commands as per OS
 *///from www .j av  a 2s.c om
public static ArrayList<String> getCommandList() {
    if (OS.isFamilyUnix()) { /* Linux system */

        m_commandList.add("(Select command)");
        m_commandList.add("cat");
        m_commandList.add("chmod");
        m_commandList.add("cp");
        m_commandList.add("ftp");
        m_commandList.add("gcc");
        m_commandList.add("ls");
        m_commandList.add("mkdir");
        m_commandList.add("netstat");
        m_commandList.add("nmap");
        m_commandList.add("ping");
        m_commandList.add("rm");
        m_commandList.add("rsync");
        m_commandList.add("scp");
        m_commandList.add("traceroute");
        m_commandList.add("wc");

    } else if (OS.isFamilyWindows()) { /* Windows system */

        m_commandList.add("(Select command)");
        m_commandList.add("assoc");
        m_commandList.add("copy");
        m_commandList.add("date");
        m_commandList.add("del");
        m_commandList.add("dir");
        m_commandList.add("echo");
        m_commandList.add("erase");
        m_commandList.add("fc");
        m_commandList.add("findstr");
        m_commandList.add("help");
        m_commandList.add("md");
        m_commandList.add("mkdir");
        m_commandList.add("move");
        m_commandList.add("netstat");
        m_commandList.add("ping");
        m_commandList.add("rd");
        m_commandList.add("ren");
        m_commandList.add("tasklist");
        m_commandList.add("time");
        m_commandList.add("type");
        m_commandList.add("ver");
        m_commandList.add("vol");

    }

    return m_commandList;
}

From source file:Utility.Platform.java

/**
 * Returns list of options for a given {@code command}.
 * <br> note: null is returned if OS is neither Linux nor Windows.
 *
 * @param command name of command whose option list ({@code String} array)
 * is returned//from   ww w .j  av a 2  s.  com
 * @return {@code String[]} containing options corresponding to
 * {@code command}
 */
public static String[] getOptionList(String command) {
    String[] optionList;

    if (OS.isFamilyUnix()) {
        optionList = getLinuxOptionList(command);
    } else if (OS.isFamilyWindows()) {
        optionList = getWindowsOptionList(command);
    } else {
        return null;
    }

    return optionList;
}