Java 类org.apache.commons.exec.OS 实例源码

项目:marathonv5    文件:JavaProfileTest.java   
public void executeWSCommand() throws Throwable {
    if (OS.isFamilyWindows()) {
        throw new SkipException("Test not valid for Windows");
    }
    JavaProfile profile = new JavaProfile(LaunchMode.JAVA_WEBSTART).addWSArgument("-verbose").addVMArgument("-Dx.y.z=hello");
    final CommandLine commandLine = profile.getCommandLine();
    AssertJUnit.assertNotNull(commandLine);
    AssertJUnit.assertTrue(commandLine.toString().contains("-javaagent:"));
    AssertJUnit.assertTrue(commandLine.toString().contains("-verbose"));
    AssertJUnit.assertTrue(commandLine.toString().contains("-Dx.y.z=hello"));
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    commandLine.copyOutputTo(baos);
    commandLine.executeAsync();
    new Wait("Waiting till the command is complete") {
        @Override public boolean until() {
            return !commandLine.isRunning();
        }
    };
    BufferedReader reader = new BufferedReader(new StringReader(new String(baos.toByteArray())));
    String line = reader.readLine();
    while (line != null && !line.contains("Web Start")) {
        line = reader.readLine();
    }
    AssertJUnit.assertTrue(line.contains("Web Start"));
}
项目:giiwa    文件:Shell.java   
/**
 * test is Linux
 * 
 * @return true if linux
 */
public static boolean isLinux() {
    if (_linux == -1) {
        try {
            if (OS.isFamilyUnix()) {
                String uname = Shell.run("uname -a");
                log.debug("uname -a=" + uname);
                _linux = uname.indexOf("Linux") > -1 ? 1 : 0;
            } else {
                _linux = 0;
            }
        } catch (Exception e) {
            log.error(e.getMessage(), e);
        }
    }
    return _linux == 1;
}
项目:Camel    文件:ExecScriptTest.java   
private File getExecScriptFileOrNull(String scriptNameBase) {
    String resource = null;
    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;
}
项目:exec-maven-plugin    文件:ExecMojo.java   
static String findExecutable( final String executable, final List<String> paths )
{
    File f = null;
    search: for ( final String path : paths )
    {
        f = new File( path, executable );
        if ( !OS.isFamilyWindows() && f.isFile() )
            break;
        else
            for ( final String extension : getExecutableExtensions() )
            {
                f = new File( path, executable + extension );
                if ( f.isFile() )
                    break search;
            }
    }

    if ( f == null || !f.exists() )
        return null;

    return f.getAbsolutePath();
}
项目:Appium-Support    文件:AppiumServer.java   
/**
 * Search the operating system for an Appium server installation directory.
 *
 * @return A File representation to the Appium server installation
 * directory.
 */
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(APPIUM_SERVER_MAC_DEFAULT_DIRECTORY);
    }

    // server directrory was not found.
    throw new ServerDirectoryNotFoundException();
}
项目:event-store-maven-plugin    文件:EventStoreStopMojo.java   
private void init() throws MojoExecutionException {

        // Supply variables that are OS dependent
        if (OS.isFamilyWindows()) {
            if (command == null) {
                command = "taskkill";
            }
        } 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");
            }
        }

    }
项目:event-store-maven-plugin    文件:EventStoreDownloadMojo.java   
private static void applyFileMode(final File file, final FileMode fileMode)
        throws MojoExecutionException {

    if (OS.isFamilyUnix() || OS.isFamilyMac()) {
        final String smode = fileMode.toChmodStringFull();
        final CommandLine cmdLine = new CommandLine("chmod");
        cmdLine.addArgument(smode);
        cmdLine.addArgument(file.getAbsolutePath());
        final Executor executor = new DefaultExecutor();
        try {
            final int result = executor.execute(cmdLine);
            if (result != 0) {
                throw new MojoExecutionException("Error # " + result + " while trying to set mode \""
                        + smode + "\" for file: " + file.getAbsolutePath());
            }
        } catch (final IOException ex) {
            throw new MojoExecutionException("Error while trying to set mode \"" + smode + "\" for file: "
                    + file.getAbsolutePath(), ex);
        }
    } else {
        file.setReadable(fileMode.isUr() || fileMode.isGr() || fileMode.isOr());
        file.setWritable(fileMode.isUw() || fileMode.isGw() || fileMode.isOw());
        file.setExecutable(fileMode.isUx() || fileMode.isGx() || fileMode.isOx());
    }
}
项目:event-store-maven-plugin    文件:EventStorePostStartMojoTest.java   
@Test
public void testExecute() throws MojoExecutionException, IOException {

    // PREPARE
    final EventStorePostStartMojo testee = new EventStorePostStartMojo();
    final File dir = new File("./src/test").getCanonicalFile();
    testee.setEventStoreDir(dir);
    if (OS.isFamilyWindows()) {
        testee.setPostStartCommand(dir + File.separator + "echotest.bat");
    } else {
        testee.setPostStartCommand(dir + File.separator + "echotest.sh");
    }

    // TEST
    testee.execute();

    // VERIFY
    assertThat(testee.getMessages()).contains("Hello world!");

}
项目:marathonv5    文件:LaunchAppletTest.java   
public void checkGivenExecutableIsUsed() throws Throwable {
    JavaProfile profile = new JavaProfile(LaunchMode.JAVA_APPLET);
    File f = findFile();
    profile.setAppletURL(f.getAbsolutePath());
    profile.setStartWindowTitle("Applet Viewer: SwingSet3Init.class");
    String actual = "";
    if (OS.isFamilyWindows()) {
        String path = System.getenv("Path");
        String[] split = path.split(";");
        File file = new File(split[0]);
        File[] listFiles = file.listFiles();
        if (listFiles != null) {
            for (File listFile : listFiles) {
                if (listFile.getName().contains(".exe")) {
                    profile.setJavaCommand(listFile.getAbsolutePath());
                    actual = listFile.getAbsolutePath();
                    break;
                }
            }
        }
    } else {
        actual = "ls";
        profile.setJavaCommand(actual);
    }
    CommandLine commandLine = profile.getCommandLine();
    AssertJUnit.assertTrue(commandLine.toString().contains(actual));
}
项目:giiwa    文件:Shell.java   
/**
 * get the status of the processname.
 *
 * @param processname
 *            the process name
 * @return the status of the process
 * @throws IOException
 *             throw IOException if occur error
 */
public static String getProcessStatus(String processname) throws IOException {
    if (isLinux() || OS.isFamilyMac()) {

        String line = "ps -ef";
        String r = run(line);
        StringBuilder sb = new StringBuilder();
        String[] ss = r.split("\n");
        if (ss != null && ss.length > 0) {
            for (String s : ss) {
                if (s.contains(processname)) {
                    sb.append(s).append("\n");
                }
            }
        }

        return sb.toString();
    } else if (OS.isFamilyWindows()) {

        String cmd = "tasklist /nh /FI \"IMAGENAME eq " + processname + "\"";
        return run(cmd);

    } else {
        throw new IOException("not support");
    }

}
项目:TranskribusSwtGui    文件:ProgramUpdaterDialog.java   
public static String getStartScriptName() throws URISyntaxException {
        String base="Transkribus.";
        if (OS.isFamilyWindows()) {
            String exe = base+"exe";
            String cmd = "cmd /c start "+exe;
//          cmd += "& del "+getCurrentJar().getName(); // this cleans the old version in windows after the new version has started --> should work, as current JVM should exit sooner than new program has started! 
            return cmd;
        } else if (OS.isFamilyMac()) {
            return "./"+base+"command";
        } else {
            return "./"+base+"sh";
        }
    }
项目:Camel    文件:ExecScriptTest.java   
private String getClasspathArg() {
    String classpath = System.getProperty("java.class.path");
    if (OS.isFamilyWindows()) {
        // On windows the ";" character is replaced by a space by the
        // command interpreter. Thus the classpath is split with the
        // ;-token. Therefore the classpath should be quoted with double
        // quotes
        classpath = "\"\"" + classpath + "\"\"";
    } else {
        // quote only once
        classpath = "\"" + classpath + "\"";
    }
    return classpath;

}
项目:exec-maven-plugin    文件:ExecMojo.java   
protected File createEnvWrapperFile( File envScript )
    throws IOException
{
    PrintWriter writer = null;
    File tmpFile = null;
    try
    {

        if ( OS.isFamilyWindows() )
        {
            tmpFile = File.createTempFile( "env", ".bat" );
            writer = new PrintWriter( tmpFile );
            writer.append( "@echo off" ).println();
            writer.append( "call \"" ).append( envScript.getCanonicalPath() ).append( "\"" ).println();
            writer.append( "echo " + EnvStreamConsumer.START_PARSING_INDICATOR ).println();
            writer.append( "set" ).println();
            writer.flush();
        }
        else
        {
            tmpFile = File.createTempFile( "env", ".sh" );
            // tmpFile.setExecutable( true );//java 6 only
            writer = new PrintWriter( tmpFile );
            writer.append( "#! /bin/sh" ).println();
            writer.append( ". " ).append( envScript.getCanonicalPath() ).println(); // works on all unix??
            writer.append( "echo " + EnvStreamConsumer.START_PARSING_INDICATOR ).println();
            writer.append( "env" ).println();
            writer.flush();
        }
    }
    finally
    {
        IOUtil.close( writer );
    }

    return tmpFile;

}
项目:exec-maven-plugin    文件:ExecMojoTest.java   
public void testGetExecutablePathPreferExecutableExtensionsOnWindows()
        throws IOException
{
    // this test is for Windows
    if (!OS.isFamilyWindows()) {
        return;
    }
    final ExecMojo realMojo = new ExecMojo();

    final String tmp = System.getProperty("java.io.tmpdir");
    final File workdir = new File(tmp, "testGetExecutablePathPreferExecutableExtensionsOnWindows");
    workdir.mkdirs();

    final Map<String, String> enviro = new HashMap<String, String>();

    final File f = new File(workdir, "mycmd");
    final File fCmd = new File(workdir, "mycmd.cmd");
    f.createNewFile();
    fCmd.createNewFile();
    assertTrue( "file exists...", f.exists() );
    assertTrue( "file exists...", fCmd.exists() );

    realMojo.setExecutable( "mycmd" );

    final CommandLine cmd = realMojo.getExecutablePath( enviro, workdir );
    // cmdline argumets are: [/c, %path-to-temp%\mycmd.cmd], so check second argument
    assertTrue( "File should have cmd extension",
            cmd.getArguments()[1].endsWith( "mycmd.cmd" ) );

    f.delete();
    fCmd.delete();
    assertFalse( "file deleted...", f.exists() );
    assertFalse( "file deleted...", fCmd.exists() );

}
项目:exec-maven-plugin    文件:ExecMojoTest.java   
private String getCommandLineAsString( CommandLine commandline )
{
    // for the sake of the test comparisons, cut out the eventual
    // cmd /c *.bat conversion
    String result = commandline.getExecutable();
    boolean isCmd = false;
    if ( OS.isFamilyWindows() && result.equals( "cmd" ) )
    {
        result = "";
        isCmd = true;
    }
    String[] arguments = commandline.getArguments();
    for ( int i = 0; i < arguments.length; i++ )
    {
        String arg = arguments[i];
        if ( isCmd && i == 0 && "/c".equals( arg ) )
        {
            continue;
        }
        if ( isCmd && i == 1 && arg.endsWith( ".bat" ) )
        {
            arg = arg.substring( 0, arg.length() - ".bat".length() );
        }
        result += ( result.length() == 0 ? "" : " " ) + arg;
    }
    return result;
}
项目:XWBEx    文件:CommandLauncherFactory.java   
/**
 * Factory method to create an appropriate launcher.
 *
 * @return the command launcher
 */
public static CommandLauncher createVMLauncher() {
    // Try using a JDK 1.3 launcher
    CommandLauncher launcher;

    if (OS.isFamilyOpenVms()) {
        launcher = new VmsCommandLauncher();
    } else {
        launcher = new Java13CommandLauncher();
    }

    return launcher;
}
项目:XWBEx    文件:DefaultProcessingEnvironment.java   
/**
 * Creates a map that obeys the casing rules of the current platform for key
 * lookup. E.g. on a Windows platform, the map keys will be
 * case-insensitive.
 * 
 * @return The map for storage of environment variables, never
 *         <code>null</code>.
 */
private Map createEnvironmentMap() {
    if (OS.isFamilyWindows()) {
        return new TreeMap(new Comparator() {
            public int compare(Object arg0, Object arg1) {
                String key0 = (String) arg0;
                String key1 = (String) arg1;
                return key0.compareToIgnoreCase(key1);
            }
        });
    } else {
        return new HashMap();
    }
}
项目:Appium-Support    文件:AppiumServer.java   
/**
 * Constructs an Appium server instance. Searches automatically for an
 * installed Appium server on your machine using the default installation
 * location according to your operating system.
 *
 * The searched directories are: <br><ul><li>Windows OS: "C:/Program
 * Files/Appium" &amp; "C:/Program Files (x86)/Appium"</li> <li>Mac OS:
 * "/Applications/Appium.app/Contents/Resources" </li></ul>zz
 *
 * @param serverArguments The server arguments to be used when working with
 * the server.
 */
public AppiumServer(ServerArguments serverArguments) {
    this._serverArguments = serverArguments;

    // search for installed Appium server
    _absoluteServerDirectory = searchForServerDirectory();

    // make sure to get the node executable file path along with the appium.js path too.
    _nodeExecutableFilePath = new File(OS.isFamilyWindows()
            ? _absoluteServerDirectory + NODE_RELATIVE_PATH_WINDOWS
            : _absoluteServerDirectory + NODE_RELATIVE_PATH_MAC_OS);
    _appiumJavaScriptFilePath = new File(_absoluteServerDirectory
            + APPIUM_FILE_RELATIVE_PATH);
}
项目:Appium-Support    文件:AppiumServer.java   
/**
 * Constructs an Appium server instance. You specify the custom directory to
 * your Appium server.
 *
 * @param absoluteServerDirectory The custom directory to your Appium
 * server. The directory that contains the "node_modules" directory &amp;
 * the NodeJS executable.
 * @param serverArguments The server arguments to be used when working with
 * the server.
 */
public AppiumServer(File absoluteServerDirectory, ServerArguments serverArguments) {
    this._absoluteServerDirectory = absoluteServerDirectory;
    this._serverArguments = serverArguments;

    // make sure to get the node executable file path along with the appium.js path too.
    _nodeExecutableFilePath = new File(OS.isFamilyWindows()
            ? _absoluteServerDirectory + NODE_RELATIVE_PATH_WINDOWS
            : _absoluteServerDirectory + NODE_RELATIVE_PATH_MAC_OS);
    _appiumJavaScriptFilePath = new File(_absoluteServerDirectory
            + APPIUM_FILE_RELATIVE_PATH);
}
项目:compose-executor    文件:ProcessUtils.java   
public static  boolean isProcessRunning(int pid) {
    String line;
    if (OS.isFamilyWindows()) {
        line = "cmd /c \"tasklist /FI \"PID eq " + pid + "\" | findstr " + pid + "\"";
    }
    else {
        line = "ps -p " + pid;
    }
    int exitValue = ProcessUtils.executeCommand(line, null);
    return exitValue == 0;
}
项目:event-store-maven-plugin    文件:EventStoreStopMojo.java   
private CommandLine createCommandLine() throws MojoExecutionException {
    final CommandLine cmdLine = new CommandLine(command);
    if (OS.isFamilyWindows()) {
        cmdLine.addArgument("/PID");
        cmdLine.addArgument(readPid());
        cmdLine.addArgument("/F");
    } else if (OS.isFamilyUnix() || OS.isFamilyMac()) {
        cmdLine.addArgument("-SIGKILL");
        cmdLine.addArgument(readPid());
    } else {
        throw new MojoExecutionException(
                "Unknown OS - Cannot kill the process");
    }
    return cmdLine;
}
项目:event-store-maven-plugin    文件:EventStoreStartMojo.java   
private void init() throws MojoExecutionException {

        // Supply variables that are OS dependent
        if (OS.isFamilyWindows()) {
            if (command == null) {
                // For some strange reasons this does not work without the
                // path...
                command = getEventStoreDir() + File.separator
                        + "EventStore.ClusterNode.exe";
            }
        } else if (OS.isFamilyUnix()) {
            if (command == null) {
                command = "./run-node.sh";
            }
        } else if (OS.isFamilyMac()) {
            if (command == null) {
                command = "./run-node.sh";
            }
        } else {
            if (command == null) {
                throw new MojoExecutionException(
                        "Unknown OS - You must use the 'command' parameter");
            }
        }

        // Use in-memory mode if nothing else is set
        if (arguments == null) {
            arguments = new String[1];
            arguments[0] = "--mem-db=TRUE";
        }

    }
项目:MediaConverter    文件:OSUtils.java   
/**
 * This method returns a member of {@code OperatingSystem} representing the
 * current Operating System.
 *
 * @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;
}
项目:selenium-java-robot    文件:LocalRobotizedBrowserFactory.java   
@Override
public RemoteWebDriver createWebDriver() {
    SafariDriver safari = new SafariDriver();
    if (OS.isFamilyMac()) {
        try {
            // put the browser in the foreground:
            String cmdline = "open -a safari";
            SeleniumJavaRobot.log("Executing: " + cmdline);
            Runtime.getRuntime().exec(cmdline);
        } catch (Exception e) {
        }
    }
    return safari;
}
项目:marathonv5    文件:LaunchCommandLineTest.java   
private File findFile() {
    if (OS.isFamilyWindows()) {
        return new File(new File(ClassPathHelper.getClassPath(SwingSet3.class)).getParentFile(), "swingset3.bat");
    }
    return new File(new File(ClassPathHelper.getClassPath(SwingSet3.class)).getParentFile(), "swingset3.sh");
}
项目:marathonv5    文件:LaunchCommandLineTest.java   
private File findFile() {
    if (OS.isFamilyWindows()) {
        return new File(new File(ClassPathHelper.getClassPath(SwingSet3.class)).getParentFile(), "swingset3.bat");
    }
    return new File(new File(ClassPathHelper.getClassPath(SwingSet3.class)).getParentFile(), "swingset3.sh");
}
项目:giiwa    文件:Shell.java   
public static boolean isMac() {
    if (_mac == -1) {
        _mac = OS.isFamilyMac() ? 1 : 0;
    }
    return _mac == 1;
}
项目:TranskribusSwtGui    文件:CanvasKeys.java   
/**
 * On MAC, returns true if command key is down, elsewise if ctrl key is down
 */
public static boolean isCtrlOrCommandKeyDown(int mask) {
    return OS.isFamilyMac() ? isCommandKeyDown(mask) : CanvasKeys.isCtrlKeyDown(mask);  
}
项目:Camel    文件: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;
    }

    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);
}
项目:exec-maven-plugin    文件:ExecMojoTest.java   
public void testGetExecutablePath()
    throws IOException
{

    ExecMojo realMojo = new ExecMojo();

    File workdir = new File( System.getProperty( "user.dir" ) );
    Map<String, String> enviro = new HashMap<String, String>();

    String myJavaPath = "target" + File.separator + "javax";
    File f = new File( myJavaPath );
    assertTrue( "file created...", f.createNewFile() );
    assertTrue( "file exists...", f.exists() );

    realMojo.setExecutable( myJavaPath );

    CommandLine cmd = realMojo.getExecutablePath( enviro, workdir );
    assertTrue( "File exists so path is absolute",
                cmd.getExecutable().startsWith( System.getProperty( "user.dir" ) ) );

    f.delete();
    assertFalse( "file deleted...", f.exists() );
    cmd = realMojo.getExecutablePath( enviro, workdir );
    assertEquals( "File doesn't exist. Let the system find it (in that PATH?)", myJavaPath, cmd.getExecutable() );

    if ( OS.isFamilyWindows() ) // Exec Maven Plugin only supports Batch detection and PATH search on Windows
    {
        myJavaPath = "target" + File.separator + "javax.bat";
        f = new File( myJavaPath );
        assertTrue( "file created...", f.createNewFile() );
        assertTrue( "file exists...", f.exists() );

        final String comSpec = System.getenv( "ComSpec" );

        realMojo.setExecutable( "javax.bat" );
        cmd = realMojo.getExecutablePath( enviro, workdir );
        assertTrue( "is bat file on windows, execute using ComSpec.", cmd.getExecutable().equals( comSpec ) );

        enviro.put( "PATH", workdir.getAbsolutePath() + File.separator + "target" );
        cmd = realMojo.getExecutablePath( enviro, workdir );
        assertTrue( "is bat file on windows' PATH, execute using ComSpec.", cmd.getExecutable().equals( comSpec ) );
        f.delete();
        assertFalse( "file deleted...", f.exists() );
    }
}
项目:cassandra-maven-plugin    文件:AbstractCassandraMojo.java   
/**
 * Create a {@link CommandLine} to launch Java.
 *
 * @return a {@link CommandLine} to launch Java.
 */
protected CommandLine newJavaCommandLine()
{
    String exec = null;
    Toolchain tc = getToolchain();

    // if the file doesn't exist & toolchain is null, java is probably in the PATH...
    // we should probably also test for isFile and canExecute, but the second one is only
    // available in SDK 6.
    if ( tc != null )
    {
        getLog().info( "Toolchain in cassandra-maven-plugin: " + tc );
        exec = tc.findTool( "java" );
    }
    else
    {
        if ( OS.isFamilyWindows() )
        {
            String ex = "java.exe";
            // now try to figure the path from PATH, PATHEXT env vars
            // if bat file, wrap in cmd /c
            String path = System.getenv( "PATH" );
            if ( path != null )
            {
                for ( String elem : StringUtils.split( path, File.pathSeparator ) )
                {
                    File f = new File( new File( elem ), ex );
                    if ( f.exists() )
                    {
                        exec = ex;
                        break;
                    }
                }
            }
        }
    }

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

    return new CommandLine( exec );
}
项目:event-store-maven-plugin    文件:AbstractEventStoreMojo.java   
private void initUsingLatest() throws MojoExecutionException {

        try {
            final URL versionURL = new URL(versionUrl);
            final File jsonVersionFile = new File(canonicalFile(targetDir),
                    "event-store-versions.json");
            final Downloads downloads = new Downloads(versionURL,
                    jsonVersionFile);
            downloads.parse();

            final String os;
            if (OS.isFamilyWindows()) {
                os = "win";
            } else if (OS.isFamilyMac()) {
                os = "osx-10.10";
            } else if (OS.isFamilyUnix()) {
                os = "ubuntu-14.04";
            } else {
                throw new MojoExecutionException(
                        "Unknown OS - You must use the 'archive-name' parameter");
            }

            final DownloadOS downloadOS = downloads.findOS(os);
            if (downloadOS == null) {
                throw new MojoExecutionException("Couldn't find OS '" + os
                        + "' in '" + downloads.getJsonDownloadsFile() + "'");
            }
            final DownloadVersion version = downloadOS.getLatestVersion();
            if (version == null) {
                throw new MojoExecutionException(
                        "No latest version found for OS '" + os + "'");
            }

            downloadUrl = version.getUrl();

        } catch (final IOException ex) {
            throw new MojoExecutionException(
                    "Error parsing the event store version file", ex);
        }

    }
项目:event-store-maven-plugin    文件:AbstractEventStoreMojo.java   
private void initUsingVersion() throws MojoExecutionException {

        // Make sure base URL always ends with a slash
        if (!baseUrl.endsWith("/")) {
            baseUrl = baseUrl + "/";
        }

        // Supply variables that are OS dependent
        if (OS.isFamilyWindows()) {
            if (archiveName == null) {
                archiveName = "EventStore-OSS-Win";
            }
            if (archiveExtension == null) {
                archiveExtension = "zip";
            }
        } else if (OS.isFamilyMac()) {
            if (archiveName == null) {
                archiveName = "EventStore-OSS-Mac";
            }
            if (archiveExtension == null) {
                archiveExtension = "tar.gz";
            }
        } else if (OS.isFamilyUnix()) {
            if (archiveName == null) {
                if (isUbuntuVersion()) {
                    archiveName = "EventStore-OSS-Ubuntu-14.04";
                } else {
                    archiveName = "EventStore-OSS-Linux";
                }
            }
            if (archiveExtension == null) {
                archiveExtension = "tar.gz";
            }
        } else {
            if (archiveName == null) {
                throw new MojoExecutionException(
                        "Unknown OS - You must use the 'archive-name' parameter");
            }
            if (archiveExtension == null) {
                throw new MojoExecutionException(
                        "Unknown OS - You must use the 'archive-ext' parameter");
            }
        }

        downloadUrl = baseUrl + archiveName + "-v" + archiveVersion + "."
                + archiveExtension;

    }
项目:ABRAID-MP    文件:OSCheckerImpl.java   
/**
 * Determines if the current OS is in the Windows family.
 * @return True if on Windows, otherwise false.
 */
@Override
public boolean isWindows() {
    return OS.isFamilyWindows();
}
项目:ABRAID-MP    文件:OSCheckerTest.java   
@Test
public void isWindowsReturnsCorrectResult() throws Exception {
    assertThat((new OSCheckerImpl().isWindows())).isEqualTo(OS.isFamilyWindows());
}
项目:selenium-java-robot    文件:Main.java   
public static void main(String[] args) throws Exception {
    SeleniumJavaRobot seleniumJavaRobot = new SeleniumJavaRobot();
    String browser;
    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);
}