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:org.pentaho.di.core.ConstTest.java

@Test
public void testIsWindows() {
    assertEquals(SystemUtils.IS_OS_WINDOWS, Const.isWindows());
}

From source file:org.pentaho.hadoop.shim.api.ShimProperties.java

public ShimProperties() {
    this(new WindowsChecker() {

        @Override//from   w w  w  .ja v a  2  s  .  com
        public boolean isWindows() {
            return SystemUtils.IS_OS_WINDOWS;
        }
    });
}

From source file:org.pentaho.hadoop.shim.common.ShellPrevalidator.java

protected static boolean isWindows() {
    return SystemUtils.IS_OS_WINDOWS;
}

From source file:org.qedeq.kernel.se.common.DefaultModuleAddressTest.java

public void testDefaultModuleAddressFile() throws Exception {
    final File file = new File("unknown/hulouo.xml");
    dflt = new DefaultModuleAddress(file);
    assertEquals("hulouo.xml", dflt.getFileName());
    assertEquals("file://", dflt.getHeader());
    assertEquals("hulouo", dflt.getName());
    assertEquals(/* w  w w  . java  2s  . c  om*/
            (SystemUtils.IS_OS_WINDOWS ? "/" : "")
                    + FilenameUtils.separatorsToUnix(file.getCanonicalFile().getParentFile().getPath()) + "/",
            dflt.getPath());
    assertEquals("file://" + (SystemUtils.IS_OS_WINDOWS ? "/" : "")
            + FilenameUtils.separatorsToUnix(file.getCanonicalPath()), dflt.getUrl());
    assertEquals(true, dflt.isFileAddress());
    assertEquals(false, dflt.isRelativeAddress());
    assertEquals(dflt, dflt.createModuleContext().getModuleLocation());
}

From source file:org.rapidcontext.app.ui.AppUtils.java

/**
 * Opens the specified URL in the user's default browser.
 *
 * @param url            the URL to open
 *
 * @throws Exception if the URL failed to open or if no browser was found
 *//* ww w  .j a va  2  s.  c om*/
public static void openURL(String url) throws Exception {
    if (SystemUtils.IS_OS_MAC_OSX) {
        Runtime.getRuntime().exec("open " + url);
    } else if (SystemUtils.IS_OS_WINDOWS) {
        Runtime.getRuntime().exec("cmd.exe /C start " + url);
    } else if (hasCommand("xdg-open")) {
        Runtime.getRuntime().exec("xdg-open " + url);
    } else if (hasCommand("gnome-open")) {
        Runtime.getRuntime().exec("gnome-open " + url);
    } else if (hasCommand("kde-open")) {
        Runtime.getRuntime().exec("kde-open " + url);
    } else {
        for (int i = 0; i < BROWSERS.length; i++) {
            if (hasCommand(BROWSERS[i])) {
                Runtime.getRuntime().exec(BROWSERS[i] + " " + url);
                return;
            }
        }
        throw new Exception("No browser found.");
    }
}

From source file:org.rapidcontext.app.ui.ControlPanel.java

/**
 * Initializes the panel UI./* ww  w  .ja va2s  .  com*/
 */
private void initialize() {
    Rectangle bounds = new Rectangle();
    GridBagConstraints c;
    JLabel label;
    Font font;
    Properties info;
    String str;

    // Set system UI looks
    if (SystemUtils.IS_OS_MAC_OSX || SystemUtils.IS_OS_WINDOWS) {
        try {
            UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
        } catch (Exception ignore) {
            // Ah well... at least we tried.
        }
    }

    // Set title, menu & layout
    setDefaultCloseOperation(EXIT_ON_CLOSE);
    setTitle("RapidContext Server");
    setMenuBar(menuBar);
    initializeMenu();
    getContentPane().setLayout(new GridBagLayout());
    try {
        logotype = ImageIO.read(getClass().getResource("logotype.png"));
        Image img = ImageIO.read(getClass().getResource("logotype-icon-256x256.png"));
        setIconImage(img);
        if (SystemUtils.IS_OS_MAC_OSX) {
            MacApplication.get().setDockIconImage(img);
        }
    } catch (Exception ignore) {
        // Again, we only do our best effort here
    }

    // Add logotype
    c = new GridBagConstraints();
    c.gridheight = 5;
    c.insets = new Insets(6, 15, 10, 10);
    c.anchor = GridBagConstraints.NORTHWEST;
    Image small = logotype.getScaledInstance(128, 128, Image.SCALE_SMOOTH);
    getContentPane().add(new JLabel(new ImageIcon(small)), c);

    // Add link label
    c = new GridBagConstraints();
    c.gridx = 1;
    c.insets = new Insets(10, 10, 2, 10);
    c.anchor = GridBagConstraints.WEST;
    getContentPane().add(new JLabel("Server URL:"), c);
    serverLink.setText("http://localhost:" + server.port + "/");
    serverLink.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent evt) {
            try {
                AppUtils.openURL(serverLink.getText());
            } catch (Exception e) {
                error(e.getMessage());
            }
        }
    });
    c = new GridBagConstraints();
    c.gridx = 2;
    c.weightx = 1.0;
    c.insets = new Insets(10, 0, 2, 10);
    c.anchor = GridBagConstraints.WEST;
    getContentPane().add(serverLink, c);

    // Add login info label
    label = new JLabel("Login as 'admin' on a new server.");
    font = label.getFont();
    font = font.deriveFont(Font.ITALIC, font.getSize() - 2);
    label.setFont(font);
    c = new GridBagConstraints();
    c.gridx = 2;
    c.gridy = 1;
    c.gridwidth = 2;
    c.insets = new Insets(0, 0, 6, 10);
    c.anchor = GridBagConstraints.WEST;
    getContentPane().add(label, c);

    // Add status label
    c = new GridBagConstraints();
    c.gridx = 1;
    c.gridy = 2;
    c.insets = new Insets(0, 10, 6, 10);
    c.anchor = GridBagConstraints.WEST;
    getContentPane().add(new JLabel("Status:"), c);
    c = new GridBagConstraints();
    c.gridx = 2;
    c.gridy = 2;
    c.insets = new Insets(0, 0, 6, 10);
    c.anchor = GridBagConstraints.WEST;
    getContentPane().add(statusLabel, c);

    // Add version label
    c = new GridBagConstraints();
    c.gridx = 1;
    c.gridy = 3;
    c.insets = new Insets(0, 10, 6, 10);
    c.anchor = GridBagConstraints.WEST;
    getContentPane().add(new JLabel("Version:"), c);
    c = new GridBagConstraints();
    c.gridx = 2;
    c.gridy = 3;
    c.insets = new Insets(0, 0, 6, 10);
    c.anchor = GridBagConstraints.WEST;
    info = Main.buildInfo();
    str = info.getProperty("build.version") + " (built " + info.getProperty("build.date") + ")";
    getContentPane().add(new JLabel(str), c);

    // Add buttons
    startButton.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent evt) {
            start();
        }
    });
    c = new GridBagConstraints();
    c.gridx = 1;
    c.gridy = 4;
    c.weighty = 1.0;
    c.insets = new Insets(0, 10, 10, 10);
    c.anchor = GridBagConstraints.SOUTH;
    getContentPane().add(startButton, c);
    stopButton.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent evt) {
            stop();
        }
    });
    c = new GridBagConstraints();
    c.gridx = 2;
    c.gridy = 4;
    c.weighty = 1.0;
    c.insets = new Insets(0, 0, 10, 0);
    c.anchor = GridBagConstraints.SOUTHWEST;
    getContentPane().add(stopButton, c);

    // Set size & position
    pack();
    bounds = this.getBounds();
    bounds.width = 470;
    bounds.x = 100;
    bounds.y = 100;
    setBounds(bounds);
}

From source file:org.shaf.core.util.IOUtilsTest.java

/**
 * Test method for path normalization./*from  w ww  .  j a va 2s .co  m*/
 */
@Test
public void testNormalizePath() {
    try {
        if (SystemUtils.IS_OS_WINDOWS) {
            assertEquals(new Path("C:/user/some/dir"), IOUtils.normalizePath("file:///C:/user/some/dir"));
            assertEquals(new Path("C:/user/some/dir"), IOUtils.normalizePath("C:/user/some/dir"));
        } else {
            assertEquals(new Path("/home/user/some/dir"), IOUtils.normalizePath("file:/home/user/some/dir"));
            assertEquals(new Path("/home/user/some/dir"), IOUtils.normalizePath("/home/user/some/dir"));
        }

        assertEquals(new Path("/home/user/some/dir"),
                IOUtils.normalizePath("http://localhost/home/user/some/dir"));
        assertEquals(new Path("/home/user/some/dir"),
                IOUtils.normalizePath("http://localhost:9000/home/user/some/dir"));
    } catch (IOException exc) {
        fail(exc.getMessage());
    }
}

From source file:org.shaf.core.util.IOUtilsTest.java

/**
 * Test method for path merging./*from  w ww.  j a v a  2  s  .  c o m*/
 */
@Test
public void testMergePath() {

    // The input defined as array of Strings
    if (SystemUtils.IS_OS_WINDOWS) {
        try {
            assertEquals(new Path("C:/user/some/dir"), IOUtils.mergePath("file:///C:/user", "some/dir"));
            assertEquals(new Path("C:/user/some/dir"), IOUtils.mergePath("file:///C:/user", "/some/dir"));
        } catch (Exception exc) {
            fail(exc.getMessage());
        }
    } else {
        try {
            assertEquals(new Path("/home/user/some/dir"), IOUtils.mergePath("file:////home/user", "some/dir"));
            assertEquals(new Path("/home/user/some/dir"), IOUtils.mergePath("file:////home/user", "/some/dir"));
        } catch (Exception exc) {
            fail(exc.getMessage());
        }
    }

    try {
        IOUtils.mergePath(new String[0]);
    } catch (Exception exc) {
        assertTrue(exc instanceof IOException);
        assertEquals("Invalid input.", exc.getMessage());
        assertTrue(exc.getCause() instanceof IllegalArgumentException);
        assertEquals("paths.length=0", exc.getCause().getMessage());
    }

    try {
        IOUtils.mergePath("file:/C:/user", null);
    } catch (Exception exc) {
        assertTrue(exc instanceof IOException);
        assertEquals("Invalid input.", exc.getMessage());
        assertTrue(exc.getCause() instanceof NullPointerException);
        assertEquals("paths[1]", exc.getCause().getMessage());
    }

    // The input defined as array of Paths

    try {
        assertEquals(new Path("/user/some/dir"), IOUtils.mergePath(new Path("/user"), new Path("some/dir")));
        assertEquals(new Path("/user/some/dir"), IOUtils.mergePath(new Path("/user"), new Path("/some/dir")));
    } catch (Exception exc) {
        fail(exc.getMessage());
    }

    try {
        IOUtils.mergePath(new Path[0]);
    } catch (Exception exc) {
        assertTrue(exc instanceof IOException);
        assertEquals("Invalid input.", exc.getMessage());
        assertTrue(exc.getCause() instanceof IllegalArgumentException);
        assertEquals("paths.length=0", exc.getCause().getMessage());
    }

    try {
        IOUtils.mergePath(new Path("file:/C:/user"), null);
    } catch (Exception exc) {
        assertTrue(exc instanceof IOException);
        assertEquals("Invalid input.", exc.getMessage());
        assertTrue(exc.getCause() instanceof NullPointerException);
        assertEquals("paths[1]", exc.getCause().getMessage());
    }
}

From source file:org.sonar.api.resources.DefaultProjectFileSystemTest.java

/**
 * Example of hidden files/directories : .DSStore, .svn, .git
 *///w  w w .  j  a v a 2s .c  om
@Test
public void hiddenFilesAreIgnored() {
    if (!SystemUtils.IS_OS_WINDOWS) {
        // hidden files/directories can not be stored in svn windows
        // On Mac/Linux it's easy, just prefix the filename by '.'
        project = MavenTestUtils.loadProjectFromPom(DefaultProjectFileSystemTest.class, "hidden-files/pom.xml");
        ProjectFileSystem fs = newDefaultProjectFileSystem(project);
        List<File> files = fs.getSourceFiles();
        assertThat(files.size(), is(1));
        assertThat(files.get(0).getName(), is("foo.sql"));
    }
}

From source file:org.sonar.api.utils.command.Command.java

List<String> toStrings() {
    ImmutableList.Builder<String> command = ImmutableList.builder();
    if (newShell) {
        if (SystemUtils.IS_OS_WINDOWS) {
            command.add("cmd", "/C", "call");
        } else {//w  ww . ja  v  a  2  s  .c  o m
            command.add("sh");
        }
    }
    command.add(executable);
    command.addAll(arguments);
    return command.build();
}