Example usage for org.apache.commons.lang SystemUtils IS_OS_WINDOWS

List of usage examples for org.apache.commons.lang SystemUtils IS_OS_WINDOWS

Introduction

In this page you can find the example usage for org.apache.commons.lang SystemUtils IS_OS_WINDOWS.

Prototype

boolean IS_OS_WINDOWS

To view the source code for org.apache.commons.lang SystemUtils IS_OS_WINDOWS.

Click Source Link

Document

Is true if this is Windows.

The field will return false if OS_NAME is null.

Usage

From source file:com.jaspersoft.studio.server.wizard.find.FindResourcePage.java

private void search() {
    if (SystemUtils.IS_OS_WINDOWS)
        new Thread(new Runnable() {
            public void run() {
                try {
                    WSClientHelper.findResources(new NullProgressMonitor(), finderUI);
                } catch (Exception e) {
                    e.printStackTrace();
                }/*w ww  .ja va 2  s. c  om*/
            }
        }).start();
    else
        try {
            getContainer().run(true, true, new IRunnableWithProgress() {

                @Override
                public void run(IProgressMonitor monitor)
                        throws InvocationTargetException, InterruptedException {
                    monitor.beginTask(Messages.FindResourcePage_19, IProgressMonitor.UNKNOWN);
                    try {
                        WSClientHelper.findResources(monitor, finderUI);
                    } catch (Exception e) {
                        e.printStackTrace();
                    } finally {
                        monitor.done();
                    }
                }
            });
        } catch (InvocationTargetException e1) {
            e1.printStackTrace();
        } catch (InterruptedException e1) {
            e1.printStackTrace();
        }
}

From source file:com.opengamma.examples.simulated.tool.ExampleDatabasePopulator.java

private static String unpackJar(URL resource) {
    String file = resource.getPath();
    if (file.contains(".jar!/")) {
        s_logger.info("Unpacking zip file located within a jar file: {}", resource);
        String jarFileName = StringUtils.substringBefore(file, "!/");
        if (jarFileName.startsWith("file:/")) {
            jarFileName = jarFileName.substring(5);
            if (SystemUtils.IS_OS_WINDOWS) {
                jarFileName = StringUtils.stripStart(jarFileName, "/");
            }//from w  w  w. ja  va  2  s . c  om
        } else if (jarFileName.startsWith("file:/")) {
            jarFileName = jarFileName.substring(6);
        }
        jarFileName = StringUtils.replace(jarFileName, "%20", " ");
        String innerFileName = StringUtils.substringAfter(file, "!/");
        innerFileName = StringUtils.replace(innerFileName, "%20", " ");
        s_logger.info("Unpacking zip file found jar file: {}", jarFileName);
        s_logger.info("Unpacking zip file found zip file: {}", innerFileName);
        try {
            JarFile jar = new JarFile(jarFileName);
            JarEntry jarEntry = jar.getJarEntry(innerFileName);
            try (InputStream in = jar.getInputStream(jarEntry)) {
                File tempFile = File.createTempFile("simulated-examples-database-populator-", ".zip");
                tempFile.deleteOnExit();
                try (OutputStream out = new FileOutputStream(tempFile)) {
                    IOUtils.copy(in, out);
                }
                file = tempFile.getCanonicalPath();
            }
        } catch (IOException ex) {
            throw new OpenGammaRuntimeException("Unable to open file within jar file: " + resource, ex);
        }
        s_logger.debug("Unpacking zip file extracted to: {}", file);
    }
    return file;
}

From source file:io.fabric8.kubernetes.client.ConfigTest.java

@Test
public void honorClientAuthenticatorCommands() throws Exception {
    if (SystemUtils.IS_OS_WINDOWS) {
        System.setProperty(Config.KUBERNETES_KUBECONFIG_FILE, TEST_KUBECONFIG_EXEC_WIN_FILE);
    } else {/*from ww w  .j ava  2 s. co  m*/
        Files.setPosixFilePermissions(Paths.get(TEST_TOKEN_GENERATOR_FILE),
                PosixFilePermissions.fromString("rwxrwxr-x"));
        System.setProperty(Config.KUBERNETES_KUBECONFIG_FILE, TEST_KUBECONFIG_EXEC_FILE);
    }

    Config config = Config.autoConfigure(null);
    assertNotNull(config);
    assertEquals("HELLO WORLD", config.getOauthToken());
}

From source file:de.uni_hildesheim.sse.easy_producer.instantiator.model.buildlangModel.BuildlangExecution.java

/**
 * Processes the {@link LoadProperties}.
 * //from   w w  w .  j  av a2s.  com
 * @param script the script to process the properties for
 * @param base the base path to make relative paths absolute
 * @throws VilLanguageException in case that something goes wrong
 */
private void processProperties(Script script, File base) throws VilLanguageException {
    Properties loaded = new Properties();
    for (int p = 0; p < script.getPropertiesCount(); p++) {
        LoadProperties prop = script.getProperties(p);
        String path = prop.getPath();
        try {
            path = StringReplacer.substitute(path, environment, getExpressionParser(), this);
        } catch (ExpressionException e) {
            throw new VilLanguageException(e);
        }
        File file = absolute(path, base);
        loadProperties(file, loaded, null);
        if (SystemUtils.IS_OS_MAC) {
            loadProperties(file, loaded, "macos");
        } else if (SystemUtils.IS_OS_UNIX) {
            loadProperties(file, loaded, "unix");
        } else if (SystemUtils.IS_OS_WINDOWS) {
            loadProperties(file, loaded, "win");
        }
    }
    for (int v = 0; v < script.getVariableDeclarationCount(); v++) {
        VariableDeclaration var = script.getVariableDeclaration(v);
        String value = loaded.getProperty(var.getName(), null);
        if (null != value) {
            if (var.isConstant() && null != var.getExpression()) {
                throw new VilLanguageException("constant '" + var.getName() + "' is already assigned a value",
                        VilLanguageException.ID_IS_CONSTANT);
            }
            Object actValue = evaluateExternalValue(var, value);
            environment.setValue(var, actValue);
            tracer.valueDefined(var, actValue);
        }
    }
}

From source file:io.sloeber.core.managers.InternalPackageManager.java

@SuppressWarnings("nls")
private static void link(File actualFile, File linkName) throws IOException, InterruptedException {
    String[] command = new String[] { "ln", actualFile.getAbsolutePath(), linkName.getAbsolutePath() };
    if (SystemUtils.IS_OS_WINDOWS) {
        command = new String[] { "cmd", "/c", "mklink", "/H", linkName.getAbsolutePath(),
                actualFile.getAbsolutePath() };
    }//w  w w  .j  a  va  2  s . c o  m
    Process process = Runtime.getRuntime().exec(command, null, null);
    process.waitFor();
}

From source file:com.vmware.identity.idm.server.LocalOsIdentityProviderTest.java

private static ISecurityAccountsLibrary getSamLib() {
    if (_lib == null) {
        if (SystemUtils.IS_OS_WINDOWS) {
            _lib = new WinSecurityAccountsLibrary();
        } else if (SystemUtils.IS_OS_LINUX) {
            _lib = new LinuxSecurityAccountsLibrary();
        } else {/*w ww.j a  va 2s . c  o  m*/
            throw new RuntimeException("Only Linux and Windows os's are suported.");
        }
    }

    return _lib;
}

From source file:de.adv_online.aaa.profiltool.ProfilDialog.java

public void actionPerformed(ActionEvent e) {
    if (startButton == e.getSource()) {
        startTransformation();/*from  w  ww .  j  ava 2  s  . co m*/
    } else if (e.getSource() == viewLogButton) {
        try {
            if (Desktop.isDesktopSupported())
                Desktop.getDesktop().open(logfile);
            else if (SystemUtils.IS_OS_WINDOWS)
                Runtime.getRuntime().exec("cmd /c start " + logfile.getPath());
            else
                Runtime.getRuntime().exec("open " + logfile.getPath());
        } catch (IOException e1) {
            e1.printStackTrace();
            System.exit(1);
        }
    } else if (e.getSource() == exitButton) {
        closeDialog();
    }
}

From source file:com.amazonaws.services.kinesis.producer.KinesisProducer.java

private void extractBinaries() {
    synchronized (EXTRACT_BIN_MUTEX) {
        final List<File> watchFiles = new ArrayList<>(2);
        String os = SystemUtils.OS_NAME;
        if (SystemUtils.IS_OS_WINDOWS) {
            os = "windows";
        } else if (SystemUtils.IS_OS_LINUX) {
            os = "linux";
        } else if (SystemUtils.IS_OS_MAC_OSX) {
            os = "osx";
        } else {/*from   www .j a  v  a 2  s  .c  o  m*/
            throw new RuntimeException("Your operation system is not supported (" + os
                    + "), the KPL only supports Linux, OSX and Windows");
        }

        String root = "amazon-kinesis-producer-native-binaries";
        String tmpDir = config.getTempDirectory();
        if (tmpDir.trim().length() == 0) {
            tmpDir = System.getProperty("java.io.tmpdir");
        }
        tmpDir = Paths.get(tmpDir, root).toString();
        pathToTmpDir = tmpDir;

        String binPath = config.getNativeExecutable();
        if (binPath != null && !binPath.trim().isEmpty()) {
            pathToExecutable = binPath.trim();
            log.warn("Using non-default native binary at " + pathToExecutable);
            pathToLibDir = "";
        } else {
            log.info("Extracting binaries to " + tmpDir);
            try {
                File tmpDirFile = new File(tmpDir);
                if (!tmpDirFile.exists() && !tmpDirFile.mkdirs()) {
                    throw new IOException("Could not create tmp dir " + tmpDir);
                }

                String extension = os.equals("windows") ? ".exe" : "";
                String executableName = "kinesis_producer" + extension;
                byte[] bin = IOUtils.toByteArray(this.getClass().getClassLoader()
                        .getResourceAsStream(root + "/" + os + "/" + executableName));
                MessageDigest md = MessageDigest.getInstance("SHA1");
                String mdHex = DatatypeConverter.printHexBinary(md.digest(bin)).toLowerCase();

                pathToExecutable = Paths.get(pathToTmpDir, "kinesis_producer_" + mdHex + extension).toString();
                File extracted = new File(pathToExecutable);
                watchFiles.add(extracted);
                if (extracted.exists()) {
                    try (FileInputStream fis = new FileInputStream(extracted);
                            FileLock lock = fis.getChannel().lock(0, Long.MAX_VALUE, true)) {
                        boolean contentEqual = false;
                        if (extracted.length() == bin.length) {
                            byte[] existingBin = IOUtils.toByteArray(new FileInputStream(extracted));
                            contentEqual = Arrays.equals(bin, existingBin);
                        }
                        if (!contentEqual) {
                            throw new SecurityException("The contents of the binary "
                                    + extracted.getAbsolutePath() + " is not what it's expected to be.");
                        }
                    }
                } else {
                    try (FileOutputStream fos = new FileOutputStream(extracted);
                            FileLock lock = fos.getChannel().lock()) {
                        IOUtils.write(bin, fos);
                    }
                    extracted.setExecutable(true);
                }

                String certFileName = "b204d74a.0";
                File certFile = new File(pathToTmpDir, certFileName);
                if (!certFile.exists()) {
                    try (FileOutputStream fos = new FileOutputStream(certFile);
                            FileLock lock = fos.getChannel().lock()) {
                        byte[] certs = IOUtils.toByteArray(this.getClass().getClassLoader()
                                .getResourceAsStream("cacerts/" + certFileName));
                        IOUtils.write(certs, fos);
                    }
                }

                watchFiles.add(certFile);
                pathToLibDir = pathToTmpDir;
                FileAgeManager.instance().registerFiles(watchFiles);
            } catch (Exception e) {
                throw new RuntimeException("Could not copy native binaries to temp directory " + tmpDir, e);
            }

        }
    }
}

From source file:com.topsec.tsm.sim.sysconfig.web.SystemConfigController.java

@RequestMapping("getCfgResponse")
@ResponseBody//from   w w w.j  av  a 2 s  .  co  m
public Object getConfigResponse(SID sid, @RequestParam("cfgKey") String cfgKey,
        @RequestParam("nodeType") String nodeType) {
    Result result = new Result();
    //1.??
    List<Node> nodes = nodeMgrFacade.getNodesByType(nodeType, false, false, false, false);
    if (nodes.isEmpty())
        return new Result(false, "");
    //ID
    String defaultNodeId = nodes.get(0).getNodeId();
    //2.?ID?KEY???
    Response response = eventResponseService.getResponsesByNodeIdAndCofingKey(defaultNodeId, cfgKey);

    Map<String, Object> configMap = new HashMap<String, Object>();
    configMap.put("responseId", response.getId());
    try {
        Config config = RespCfgHelper.getConfig(response);
        for (Block block : config.getCfgBlocks()) {
            Map<String, Object> blockMap = new HashMap<String, Object>();
            if (!config.getGroupList().isEmpty()) {
                //group?
                if (block.isGroupSelect()) {
                    putBlockItemsToMap(sid, block, blockMap);
                }
            } else {
                putBlockItemsToMap(sid, block, blockMap);
            }
            if (!blockMap.isEmpty()) {
                String blockKey = block.getKey();
                configMap.put(blockKey, blockMap);
            }
        }
        configMap.put("isSoft", CommonUtils.isSoftwarePlatform());//true?
        configMap.put("isWindows", SystemUtils.IS_OS_WINDOWS);
    } catch (I18NException e) {
        e.printStackTrace();
    }
    result.setResult(configMap);
    return result;
}

From source file:de.xirp.plugin.PluginManager.java

/**
 * Checks if the operating system we are running on is windows.
 * /*from  w ww. j av  a2  s .  c o  m*/
 * @return <code>true</code> if this is windows
 */
private static boolean osWindows() {
    return SystemUtils.IS_OS_WINDOWS;
}