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

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

Introduction

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

Prototype

boolean IS_OS_LINUX

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

Click Source Link

Document

Is true if this is Linux.

The field will return false if OS_NAME is null.

Usage

From source file:gov.nasa.jpf.symbc.tree.visualizer.DOTVisualizerListener.java

private void outputVisualization(String path) {
    File file = new File(path);
    try {//  ww w.ja  v a 2  s. co  m
        FileOutputStream fo = new FileOutputStream(file);
        graph.printGraph(fo);
        fo.close();
    } catch (FileNotFoundException e) {
        e.printStackTrace();
    } catch (IOException e) {
        e.printStackTrace();
    }

    if (format != OUTPUT_FORMAT.DOT) {
        if ((SystemUtils.IS_OS_LINUX || SystemUtils.IS_OS_MAC_OSX || SystemUtils.IS_OS_MAC)) {
            try {
                convertDotFile(file, format);
                file.delete();
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }
    }
}

From source file:ddf.content.plugin.video.VideoThumbnailPlugin.java

private String getBundledFFmpegBinaryPath() {
    if (SystemUtils.IS_OS_LINUX) {
        return "linux/ffmpeg";
    } else if (SystemUtils.IS_OS_MAC) {
        return "osx/ffmpeg";
    } else if (SystemUtils.IS_OS_SOLARIS) {
        return "solaris/ffmpeg";
    } else if (SystemUtils.IS_OS_WINDOWS) {
        return "windows/ffmpeg.exe";
    } else {/*from   w  w  w. j ava2s . co  m*/
        throw new RuntimeException("OS is not Linux, Mac, Solaris, or Windows."
                + " No FFmpeg binary is available for this OS, so the plugin will not work.");
    }
}

From source file:com.masse.mvn.plugin.BuildJsonFromPropertiesMojo.java

private void buidJsonTargetFile(File inputFile) throws MojoExecutionException {

    String inputFileString = inputFile.getAbsolutePath()
            .substring(inputFile.getAbsolutePath().lastIndexOf(SystemUtils.IS_OS_LINUX ? "/" : "\\") + 1);
    String outputFileString = jsonTargetPath + new String(SystemUtils.IS_OS_LINUX ? "/" : "\\")
            + inputFileString.substring(0, inputFileString.lastIndexOf(".")) + ".json";

    getLog().info("Process file " + inputFileString);

    if (!inputFile.exists()) {
        throw new MojoExecutionException("Properties file " + inputFile + " not found !");
    }//www  .j  ava 2 s.  c  o m

    TreeMap<String, PropertiesToJson> propertiesJson = new TreeMap<String, PropertiesToJson>();
    Properties props = new Properties();

    try {
        FileInputStream inputFileStream = new FileInputStream(inputFile);
        BufferedReader inputFileBufferedReader = new BufferedReader(
                new InputStreamReader(inputFileStream, "UTF-8"));

        File outputTempFile = new File(inputFileString + "-temp");

        FileOutputStream outputTempFileStream = new FileOutputStream(outputTempFile);
        OutputStreamWriter outputTempFileStrWriter = new OutputStreamWriter(outputTempFileStream, "UTF-8");
        BufferedWriter writer = new BufferedWriter(outputTempFileStrWriter);

        String line = "";
        while ((line = inputFileBufferedReader.readLine()) != null) {
            if (!(line.isEmpty() || line.trim().equals("") || line.trim().equals("\n"))) {
                if (line.startsWith("#")) {
                    continue;
                }
                int equalsIndex = line.indexOf("=");
                if (equalsIndex < 0) {
                    continue;
                }
                line = line.replace("\"", "&quot;");
                line = line.replace("\\", "\\\\\\\\");
                line = line.replace("   ", "");
                writer.write(line + "\n");
            }
        }

        writer.close();
        outputTempFileStrWriter.close();
        outputTempFileStream.close();

        inputFileBufferedReader.close();
        inputFileStream.close();

        FileInputStream fis = new FileInputStream(outputTempFile);
        InputStreamReader isr = new InputStreamReader(fis, "UTF-8");
        props.load(isr);
        isr.close();
        fis.close();

        outputTempFile.delete();

        @SuppressWarnings("rawtypes")
        Enumeration e = props.propertyNames();

        while (e.hasMoreElements()) {
            String key = (String) e.nextElement();

            String rootKey = key.split("=")[0];

            propertiesJson.put(rootKey, createMap(propertiesJson, key, props.getProperty(key), 1));

        }
    } catch (FileNotFoundException e) {
        e.printStackTrace();
    } catch (IOException e) {
        e.printStackTrace();
    }

    StringBuffer sb = new StringBuffer();
    sb.append(PrintJsonTree(propertiesJson, 0, false));

    File outputFile = new File(outputFileString);

    try {
        FileOutputStream fos = new FileOutputStream(outputFile);
        OutputStreamWriter osw = new OutputStreamWriter(fos, "UTF-8");
        BufferedWriter bwr = new BufferedWriter(osw);

        //write contents of StringBuffer to a file

        bwr.write(sb.toString());

        //flush the stream
        bwr.flush();

        //close the stream
        bwr.close();
        osw.close();
        fos.close();
    } catch (IOException e) {
        getLog().error(e);
        throw new MojoExecutionException("json file creation error", e);
    }
}

From source file:com.cloud.utils.ScriptTest.java

@Test
public void runSimpleBashScriptNotExisting() {
    Assume.assumeTrue(SystemUtils.IS_OS_LINUX);
    String output = Script.runSimpleBashScript("/not/existing/scripts/" + System.currentTimeMillis());
    Assert.assertNull(output);/* w  w w .j ava 2  s.com*/
}

From source file:com.seyren.core.service.notification.ScriptNotificationService.java

@Override
public boolean canHandle(SubscriptionType subscriptionType) {
    return (subscriptionType == SubscriptionType.SCRIPT && SystemUtils.IS_OS_LINUX);
}

From source file:com.cloud.utils.ScriptTest.java

@Test
public void testRunSimpleBashScriptWithTimeout() {
    Assume.assumeTrue(SystemUtils.IS_OS_LINUX);
    Assert.assertEquals("hello world!", Script.runSimpleBashScript("echo 'hello world!'", 1000));
}

From source file:com.cloud.utils.ScriptTest.java

@Test
public void testFindScript() {
    Assume.assumeTrue(SystemUtils.IS_OS_LINUX);
    String script = Script.findScript("/bin", "pwd");
    Assert.assertNotNull("/bin/pwd shoud be there on linux", script);
}

From source file:com.casewaresa.framework.util.LegacyJasperInputStream.java

public static InputStream convertStringToInputStream(final String template) {
    InputStream is = null;// w w  w  .j  av  a2s  .co  m
    try {

        if (SystemUtils.IS_OS_WINDOWS) {
            log.trace("### Cargando el objeto desde un ambiente WINDOWS");
            is = new ByteArrayInputStream(template.getBytes("UTF-8"));
        } else if (SystemUtils.IS_OS_LINUX) {
            log.trace("### Cargando el objeto desde un ambiente UNIX (LINUX)");
            is = new ByteArrayInputStream(template.getBytes());
        } else if (SystemUtils.IS_OS_MAC) {
            log.trace("### Cargando el objeto desde un ambiente MAC");
            is = new ByteArrayInputStream(template.getBytes("UTF-8"));
        }

    } catch (UnsupportedEncodingException ex) {
        log.debug(ex.getMessage(), ex);
    }
    return is;
}

From source file:com.igormaznitsa.mindmap.model.ModelUtilsTest.java

@Test
public void testMakeFileForPath() throws Exception {
    assertNull(ModelUtils.makeFileForPath(null));
    assertNull(ModelUtils.makeFileForPath(""));

    assertEquals(new File((File) null, "/some/who/files/2012-11-02 13.47.10.jpg").getCanonicalPath(),
            ModelUtils.makeFileForPath("file:///some/who/files/2012-11-02 13.47.10.jpg").getAbsolutePath());
    assertEquals(new File((File) null, "/some/who/files/2012-11-02 13.47.10.jpg").getCanonicalPath(),
            ModelUtils.makeFileForPath("file:///some/who/files/2012-11-02%2013.47.10.jpg").getAbsolutePath());
    assertEquals(new File((File) null, "/some/who/files/main.c++").getCanonicalPath(),
            ModelUtils.makeFileForPath("file:///some/who/files/main.c++").getAbsolutePath());

    assertEquals(new File((File) null, "/some/folder/temp/").getCanonicalPath(),
            ModelUtils.makeFileForPath("file:///some/folder/temp/").getAbsolutePath());

    if (SystemUtils.IS_OS_LINUX) {
        assertEquals(new File((File) null, "/some/folder/temp/ :<>?").getCanonicalPath(),
                ModelUtils.makeFileForPath("file:///some/folder/temp/ :<>?").getAbsolutePath());
        assertEquals(new File((File) null, "/some/folder&ssd/temp/ :<>?test=jks&lls=1").getCanonicalPath(),
                ModelUtils.makeFileForPath("file:///some/folder&ssd/temp/ :<>?test=jks&lls=1")
                        .getAbsolutePath());
    }/*  www  . j  a  v  a 2 s  .c  o m*/
    assertEquals(
            "src/main/java/com/igormaznitsa/nbmindmap/nb/QuickSearchProvider.java".replace('/',
                    File.separatorChar),
            ModelUtils.makeFileForPath("src/main/java/com/igormaznitsa/nbmindmap/nb/QuickSearchProvider.java")
                    .getPath());
}

From source file:interactivespaces.workbench.osgi.InteractiveSpacesWorkbenchActivator.java

/**
 * Start the workbench running./*  w ww  .  ja v  a 2s  .co m*/
 */
public void run() {
    Bundle systemBundle = bundleContext.getBundle(0);
    ClassLoader systemClassLoader = systemBundle.getClass().getClassLoader();

    SimpleInteractiveSpacesEnvironment spaceEnvironment = new SimpleInteractiveSpacesEnvironment();
    spaceEnvironment.setLog(loggingProvider.getLog());
    executorService = new DefaultScheduledExecutorService();
    spaceEnvironment.setExecutorService(executorService);
    SimpleConfiguration configuration = SimpleConfiguration.newConfiguration();
    configuration.setValues(configurationProvider.getInitialConfiguration());

    // TODO(keith): Hide this more deeply in bootstrap.
    String platformOs = SystemUtils.IS_OS_LINUX ? "linux" : "osx";
    configuration.setValue("interactivespaces.platform.os", platformOs);

    spaceEnvironment.setSystemConfiguration(configuration);

    final InteractiveSpacesWorkbench workbench = new InteractiveSpacesWorkbench(spaceEnvironment,
            systemClassLoader);

    final List<String> commandLineArguments = containerCustomizerProvider.getCommandLineArguments();
    if (!commandLineArguments.isEmpty()) {
        new Thread(new Runnable() {
            @Override
            public void run() {
                boolean success = false;
                try {
                    success = workbench.doCommands(commandLineArguments);
                } finally {
                    try {
                        bundleContext.getBundle(0).stop();
                    } catch (BundleException e) {
                        loggingProvider.getLog().error("Error stopping container", e);
                        success = false;
                    }

                    if (!success) {
                        System.exit(-1);
                    }
                }
            }

        }).start();
    } else {
        ui = new WorkbenchUi(workbench);
    }
}