Java Code Examples for org.apache.commons.lang3.SystemUtils#IS_OS_WINDOWS

The following examples show how to use org.apache.commons.lang3.SystemUtils#IS_OS_WINDOWS . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: DockerComputerConnectorTest.java    From docker-plugin with MIT License 6 votes vote down vote up
protected void should_connect_agent(DockerTemplate template) throws IOException, ExecutionException, InterruptedException, TimeoutException {

        // FIXME on CI windows nodes don't have Docker4Windows
        Assume.assumeFalse(SystemUtils.IS_OS_WINDOWS);

        String dockerHost = SystemUtils.IS_OS_WINDOWS ? "tcp://localhost:2375" : "unix:///var/run/docker.sock";

        DockerCloud cloud = new DockerCloud(cloudName, new DockerAPI(new DockerServerEndpoint(dockerHost, null)),
                Collections.singletonList(template));

        j.jenkins.clouds.replaceBy(Collections.singleton(cloud));

        final FreeStyleProject project = j.createFreeStyleProject("test-docker-ssh");
        project.setAssignedLabel(Label.get(LABEL));
        project.getBuildersList().add(new Shell("whoami"));
        final QueueTaskFuture<FreeStyleBuild> scheduledBuild = project.scheduleBuild2(0);
        try {
            final FreeStyleBuild build = scheduledBuild.get(60L, TimeUnit.SECONDS);
            Assert.assertTrue(build.getResult() == Result.SUCCESS);
            Assert.assertTrue(build.getLog().contains("jenkins"));
        } finally {
            scheduledBuild.cancel(true);
        }
    }
 
Example 2
Source File: CommandBuilder.java    From gocd with Apache License 2.0 6 votes vote down vote up
@Override
protected CommandLine buildCommandLine() {
    CommandLine command = null;
    if (SystemUtils.IS_OS_WINDOWS) {
        command = CommandLine.createCommandLine("cmd").withWorkingDir(workingDir);
        command.withArg("/c");
        command.withArg(translateToWindowsPath(this.command));
    }
    else {
        command = CommandLine.createCommandLine(this.command).withWorkingDir(workingDir);
    }
    String[] argsArray = CommandLine.translateCommandLine(args);
    for (int i = 0; i < argsArray.length; i++) {
        String arg = argsArray[i];
        command.withArg(arg);
    }
    return command;
}
 
Example 3
Source File: FileSystemsTest.java    From beam with Apache License 2.0 6 votes vote down vote up
@Test
public void testGetLocalFileSystem() throws Exception {
  assertTrue(
      FileSystems.getFileSystemInternal(toLocalResourceId("~/home/").getScheme())
          instanceof LocalFileSystem);
  assertTrue(
      FileSystems.getFileSystemInternal(toLocalResourceId("file://home").getScheme())
          instanceof LocalFileSystem);
  assertTrue(
      FileSystems.getFileSystemInternal(toLocalResourceId("FILE://home").getScheme())
          instanceof LocalFileSystem);
  assertTrue(
      FileSystems.getFileSystemInternal(toLocalResourceId("File://home").getScheme())
          instanceof LocalFileSystem);
  if (SystemUtils.IS_OS_WINDOWS) {
    assertTrue(
        FileSystems.getFileSystemInternal(toLocalResourceId("c:\\home\\").getScheme())
            instanceof LocalFileSystem);
  }
}
 
Example 4
Source File: LocalFileSystemTest.java    From beam with Apache License 2.0 6 votes vote down vote up
@Test
public void testMatchInDirectory() throws Exception {
  List<String> expected = ImmutableList.of(temporaryFolder.newFile("a").toString());
  temporaryFolder.newFile("aa");
  temporaryFolder.newFile("ab");

  String expectedFile = expected.get(0);
  int slashIndex = expectedFile.lastIndexOf('/');
  if (SystemUtils.IS_OS_WINDOWS) {
    slashIndex = expectedFile.lastIndexOf('\\');
  }
  String directory = expectedFile.substring(0, slashIndex);
  String relative = expectedFile.substring(slashIndex + 1);
  System.setProperty("user.dir", directory);
  List<MatchResult> results = localFileSystem.match(ImmutableList.of(relative));
  assertThat(
      toFilenames(results), containsInAnyOrder(expected.toArray(new String[expected.size()])));
}
 
Example 5
Source File: LauncherUtils.java    From konduit-serving with Apache License 2.0 6 votes vote down vote up
/**
 * Checks if there is a konduit server running with the given application id.
 * @param applicationId application id of the konduit server.
 * @return true if the server process exists, false otherwise.
 */
public static boolean isProcessExists(String applicationId) {
    List<String> args;

    if(SystemUtils.IS_OS_WINDOWS) {
        args = Arrays.asList("WMIC", "PROCESS", "WHERE", "\"CommandLine like '%serving.id=" + applicationId + "' and name!='wmic.exe'\"", "GET", "CommandLine", "/VALUE");
    } else {
        args = Arrays.asList("sh", "-c", "ps ax | grep \"Dserving.id=" + applicationId + "$\"");
    }

    String output = "";
    try {
        Process process = new ProcessBuilder(args).start();
        output = IOUtils.toString(process.getInputStream(), StandardCharsets.UTF_8);
    } catch (Exception exception) {
        log.error("An error occurred while checking for existing processes:", exception);
        System.exit(1);
    }

    return output.trim()
            .replace(System.lineSeparator(), "")
            .matches("(.*)Dserving.id=" + applicationId);
}
 
Example 6
Source File: EmbeddedUtil.java    From otj-pg-embedded with Apache License 2.0 5 votes vote down vote up
/**
 * Get current operating system string. The string is used in the appropriate
 * postgres binary name.
 *
 * @return Current operating system string.
 */
static String getOS() {
    if (SystemUtils.IS_OS_WINDOWS) {
        return "Windows";
    }
    if (SystemUtils.IS_OS_MAC_OSX) {
        return "Darwin";
    }
    if (SystemUtils.IS_OS_LINUX) {
        return "Linux";
    }
    throw new UnsupportedOperationException("Unknown OS " + SystemUtils.OS_NAME);
}
 
Example 7
Source File: ServiceCenterDeploy.java    From servicecomb-java-chassis with Apache License 2.0 5 votes vote down vote up
public ServiceCenterDeploy() {
  super(new DeployDefinition());

  deployDefinition.setDeployName("serviceCenter");
  deployDefinition.setDisplayName("serviceCenter");
  if (SystemUtils.IS_OS_WINDOWS) {
    deployDefinition.setCmd("service-center.exe");
  } else {
    deployDefinition.setCmd("service-center");
  }
  deployDefinition.setStartCompleteLog("server is ready");
}
 
Example 8
Source File: AnalysisSaikuService.java    From collect-earth with MIT License 5 votes vote down vote up
private String getCommandSuffix() {
	if (SystemUtils.IS_OS_WINDOWS) {
		return COMMAND_SUFFIX_BAT;
	} else {
		return COMMAND_SUFFIX_SH;
	}
}
 
Example 9
Source File: GATKPathUnitTest.java    From gatk with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@Test
public void testStdOut() throws IOException {
    if (SystemUtils.IS_OS_WINDOWS) {
        // stdout is not addressable as a device in the file system namespace on Windows, so skip
        throw new SkipException(("No stdout test on Windows"));
    } else {
        final PathURI pathURI = new GATKPath("/dev/stdout");
        try (final OutputStream os = pathURI.getOutputStream();
             final DataOutputStream dos = new DataOutputStream(os)) {
            dos.write("some stuff".getBytes());
        }
    }
}
 
Example 10
Source File: P4TestRepo.java    From gocd with Apache License 2.0 5 votes vote down vote up
public static P4TestRepo createP4TestRepo(TemporaryFolder temporaryFolder, File clientFolder) throws IOException {
    String repo = "../common/src/test/resources/data/p4repo";
    if (SystemUtils.IS_OS_WINDOWS) {
        repo = "../common/src/test/resources/data/p4repoWindows";
    }
    return new P4TestRepo(RandomPort.find("P4TestRepo"), repo, "cceuser", null, PerforceFixture.DEFAULT_CLIENT_NAME, false, temporaryFolder, clientFolder);
}
 
Example 11
Source File: DetectInfoUtility.java    From synopsys-detect with Apache License 2.0 5 votes vote down vote up
public OperatingSystemType findOperatingSystemType() {
    if (SystemUtils.IS_OS_LINUX) {
        return OperatingSystemType.LINUX;
    } else if (SystemUtils.IS_OS_MAC) {
        return OperatingSystemType.MAC;
    } else if (SystemUtils.IS_OS_WINDOWS) {
        return OperatingSystemType.WINDOWS;
    }

    logger.warn("Your operating system is not supported. Linux will be assumed.");
    return OperatingSystemType.LINUX;
}
 
Example 12
Source File: JDA.java    From java-disassembler with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Returns the JDA directory
 *
 * @return the static JDA directory
 */
public static String getJDADirectory() {
    while (!dataDir.exists())
        dataDir.mkdirs();

    if (!dataDir.isHidden() && SystemUtils.IS_OS_WINDOWS)
        hideFileWindows(dataDir);

    return dataDir.getAbsolutePath();
}
 
Example 13
Source File: EditCommands.java    From hdfs-shell with Apache License 2.0 5 votes vote down vote up
public String[] getEditor() {
    if (StringUtils.isEmpty(this.editor)) {
        if (SystemUtils.IS_OS_WINDOWS) {
            return new String[]{"notepad.exe"};
        }
        if (SystemUtils.IS_OS_MAC || SystemUtils.IS_OS_MAC_OSX) {
            return new String[]{"vim"};
        }
        return new String[]{"vim"};
    } else {
        return BashUtils.parseArguments(this.editor);
    }
}
 
Example 14
Source File: ElasticServer.java    From ES-Fastloader with Apache License 2.0 5 votes vote down vote up
private void stopElasticGracefully() throws IOException {
    if (SystemUtils.IS_OS_WINDOWS) {
        stopElasticOnWindows();
    } else {
        elastic.destroy();
    }
}
 
Example 15
Source File: SolrCLI.java    From lucene-solr with Apache License 2.0 5 votes vote down vote up
private void printAuthEnablingInstructions(String username, String password) {
  if (SystemUtils.IS_OS_WINDOWS) {
    CLIO.out("\nAdd the following lines to the solr.in.cmd file so that the solr.cmd script can use subsequently.\n");
    CLIO.out("set SOLR_AUTH_TYPE=basic\n"
        + "set SOLR_AUTHENTICATION_OPTS=\"-Dbasicauth=" + username + ":" + password + "\"\n");
  } else {
    CLIO.out("\nAdd the following lines to the solr.in.sh file so that the ./solr script can use subsequently.\n");
    CLIO.out("SOLR_AUTH_TYPE=\"basic\"\n"
        + "SOLR_AUTHENTICATION_OPTS=\"-Dbasicauth=" + username + ":" + password + "\"\n");
  }
}
 
Example 16
Source File: DifferentFilesSshFetchTest.java    From gitflow-incremental-builder with MIT License 4 votes vote down vote up
private Path writePrivateKey(String fileName, String key) throws IOException {
    Path privateKey = Files.write(sshDir.resolve(fileName), Collections.singleton(key));
    return SystemUtils.IS_OS_WINDOWS
            ? privateKey
            : Files.setPosixFilePermissions(privateKey, new HashSet<>(Arrays.asList(PosixFilePermission.OWNER_READ, PosixFilePermission.OWNER_WRITE)));
}
 
Example 17
Source File: SecurityAnalysisCommandOptions.java    From powsybl-core with Mozilla Public License 2.0 4 votes vote down vote up
private static String getDefaultItoolsCommand() {
    return SystemUtils.IS_OS_WINDOWS ? "itools.bat" : "itools";
}
 
Example 18
Source File: JvmUtil.java    From recheck with GNU Affero General Public License v3.0 4 votes vote down vote up
public static String getJvm() {
	final String javaExecutable = SystemUtils.IS_OS_WINDOWS ? "javaw.exe" : "java";
	return System.getProperty( "java.home" ) + separator + "bin" + separator + javaExecutable + " ";
}
 
Example 19
Source File: MiniAccumuloClusterFactory.java    From geowave with Apache License 2.0 4 votes vote down vote up
public static MiniAccumuloClusterImpl newAccumuloCluster(
    final MiniAccumuloConfigImpl config,
    final Class context,
    final URL... additionalClasspathUrls) throws IOException {

  final String jarPath =
      ClasspathUtils.setupPathingJarClassPath(config.getDir(), context, additionalClasspathUrls);

  if (jarPath == null) {
    // Jar was not successfully created
    return null;
  }

  config.setClasspathItems(jarPath);

  final MiniAccumuloClusterImpl retVal = new GeoWaveMiniAccumuloClusterImpl(config);
  if (SystemUtils.IS_OS_WINDOWS && isYarn()) {
    // this must happen after instantiating Mini
    // Accumulo Cluster because it ensures the accumulo
    // directory is empty or it will fail, but must
    // happen before the cluster is started because yarn
    // expects winutils.exe to exist within a bin
    // directory in the mini accumulo cluster directory
    // (mini accumulo cluster will always set this
    // directory as hadoop_home)
    LOGGER.info("Running YARN on windows requires a local installation of Hadoop");
    LOGGER.info("'HADOOP_HOME' must be set and 'PATH' must contain %HADOOP_HOME%/bin");

    final Map<String, String> env = System.getenv();
    // HP Fortify "Path Manipulation" false positive
    // What Fortify considers "user input" comes only
    // from users with OS-level access anyway
    String hadoopHome = System.getProperty("hadoop.home.dir");
    if (hadoopHome == null) {
      hadoopHome = env.get("HADOOP_HOME");
    }
    boolean success = false;
    if (hadoopHome != null) {
      // HP Fortify "Path Traversal" false positive
      // What Fortify considers "user input" comes only
      // from users with OS-level access anyway
      final File hadoopDir = new File(hadoopHome);
      if (hadoopDir.exists()) {
        final File binDir = new File(config.getDir(), "bin");
        if (binDir.mkdir()) {
          FileUtils.copyFile(
              new File(hadoopDir + File.separator + "bin", HADOOP_WINDOWS_UTIL),
              new File(binDir, HADOOP_WINDOWS_UTIL));
          success = true;
        }
      }
    }
    if (!success) {
      LOGGER.error(
          "'HADOOP_HOME' environment variable is not set or <HADOOP_HOME>/bin/winutils.exe does not exist");

      // return mini accumulo cluster anyways
      return retVal;
    }
  }
  return retVal;
}
 
Example 20
Source File: CondisOS.java    From skUtilities with GNU General Public License v3.0 4 votes vote down vote up
@Override
public boolean check(Event e) {
  Boolean chk = false;
  switch (ty) {
    case (0):
      chk = SystemUtils.IS_OS_WINDOWS;
      break;
    case (1):
      chk = SystemUtils.IS_OS_MAC;
      break;
    case (2):
      chk = SystemUtils.IS_OS_LINUX;
      break;
    case (3):
      chk = SystemUtils.IS_OS_UNIX;
      break;
    case (4):
      chk = SystemUtils.IS_OS_SOLARIS;
      break;
    case (5):
      chk = SystemUtils.IS_OS_SUN_OS;
      break;
    case (6):
      chk = SystemUtils.IS_OS_HP_UX;
      break;
    case (7):
      chk = SystemUtils.IS_OS_AIX;
      break;
    case (8):
      chk = SystemUtils.IS_OS_IRIX;
      break;
    case (9):
      chk = SystemUtils.IS_OS_FREE_BSD;
      break;
    case (10):
      chk = SystemUtils.IS_OS_OPEN_BSD;
      break;
    case (11):
      chk = SystemUtils.IS_OS_NET_BSD;
      break;
  }
  return (isNegated() ? !chk : chk);
}