Search in sources :

Example 1 with CommandLauncher

use of org.apache.commons.exec.launcher.CommandLauncher in project opennms by OpenNMS.

the class MeasurementsRestServiceITCase method assumeRrdtoolExists.

protected static void assumeRrdtoolExists(final String libraryName) {
    final String libraryPath = System.getProperty("java.library.path", "");
    if (!libraryPath.contains(":/usr/local/lib")) {
        System.setProperty("java.library.path", libraryPath + ":/usr/local/lib");
    }
    boolean rrdtoolExists = false;
    try {
        final CommandLauncher cl = CommandLauncherFactory.createVMLauncher();
        final Process p = cl.exec(new CommandLine(findRrdtool()), EnvironmentUtils.getProcEnvironment());
        final int returnCode = p.waitFor();
        LOG.debug("Loading library from java.library.path={}", System.getProperty("java.library.path"));
        System.loadLibrary(libraryName);
        rrdtoolExists = returnCode == 0;
    } catch (final Exception e) {
        LOG.warn("Failed to run 'rrdtool' or libjrrd(2)? is missing.", e);
    }
    Assume.assumeTrue(rrdtoolExists);
}
Also used : CommandLine(org.apache.commons.exec.CommandLine) CommandLauncher(org.apache.commons.exec.launcher.CommandLauncher) ExpectedException(org.junit.rules.ExpectedException) WebApplicationException(javax.ws.rs.WebApplicationException)

Aggregations

WebApplicationException (javax.ws.rs.WebApplicationException)1 CommandLine (org.apache.commons.exec.CommandLine)1 CommandLauncher (org.apache.commons.exec.launcher.CommandLauncher)1 ExpectedException (org.junit.rules.ExpectedException)1