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:net.sf.texprinter.utils.UIUtils.java

/**
 * Formats a label as a title. The idea behind this method is to make
 * a JLabel component to look fancy when acting as a title to a window.
 * //from   ww w .  j  ava  2  s .  c o m
 * @param label The label to be formatted as a title.
 */
public static void formatLabelAsTitle(JLabel label) {

    // if it's not Linux
    if (!SystemUtils.IS_OS_LINUX) {

        // simply increase the font size
        label.setFont(label.getFont().deriveFont(14f));

    } else {

        // it's Linux, so add a bold style too.
        label.setFont(label.getFont().deriveFont(Font.BOLD, 14f));

    }

    // paint it as blue
    label.setForeground(new Color(35, 107, 178));
}

From source file:com.ibm.ecm.extension.aspera.AsperaPlugin.java

private void copyResources() throws AsperaPluginException {
    resourcePaths.add(copyResource("", "asperaweb_id_dsa.openssh", ""));
    resourcePaths.add(copyResource(ETC, "aspera-license", ETC));
    resourcePaths.add(copyResource(ETC, "aspera.conf", ETC));
    if (SystemUtils.IS_OS_WINDOWS) {
        copyWindowsResources();/*  w  ww. j  a v  a2  s . com*/
    } else if (SystemUtils.IS_OS_MAC_OSX) {
        resourcePaths.add(makeFileExecutable(copyResource(BIN_OSX, "ascp4", BIN)));
    } else if (SystemUtils.IS_OS_LINUX) {
        resourcePaths.add(makeFileExecutable(copyResource(BIN_LINUX, "ascp4", BIN)));
    } else {
        throw new AsperaPluginException("The operating system is not supported.");
    }
}

From source file:com.kurento.test.selenium.BaseSeleniumTst.java

private void setup(Class<? extends WebDriver> driverClass) {
    if (driverClass.equals(FirefoxDriver.class)) {
        driver = new FirefoxDriver();

    } else if (driverClass.equals(ChromeDriver.class)) {
        String chromedriver = null;
        if (SystemUtils.IS_OS_MAC || SystemUtils.IS_OS_LINUX) {
            chromedriver = "chromedriver";
        } else if (SystemUtils.IS_OS_WINDOWS) {
            chromedriver = "chromedriver.exe";
        }//from w  w w . jav a  2 s.c  om
        System.setProperty("webdriver.chrome.driver",
                new File("target/webdriver/" + chromedriver).getAbsolutePath());
        ChromeOptions options = new ChromeOptions();
        driver = new ChromeDriver(options);
    }
}

From source file:com.yahoo.pulsar.broker.service.BrokerService.java

public BrokerService(PulsarService pulsar) throws Exception {
    this.pulsar = pulsar;
    this.managedLedgerFactory = pulsar.getManagedLedgerFactory();
    this.port = new URI(pulsar.getBrokerServiceUrl()).getPort();
    this.tlsPort = new URI(pulsar.getBrokerServiceUrlTls()).getPort();
    this.topics = new ConcurrentOpenHashMap<>();
    this.replicationClients = new ConcurrentOpenHashMap<>();
    this.keepAliveIntervalSeconds = pulsar.getConfiguration().getKeepAliveIntervalSeconds();

    this.multiLayerTopicsMap = new ConcurrentOpenHashMap<>();
    this.pulsarStats = new PulsarStats(pulsar);
    this.offlineTopicStatCache = new ConcurrentOpenHashMap<>();

    final DefaultThreadFactory acceptorThreadFactory = new DefaultThreadFactory("pulsar-acceptor");
    final DefaultThreadFactory workersThreadFactory = new DefaultThreadFactory("pulsar-io");
    final int numThreads = Runtime.getRuntime().availableProcessors() * 2;
    log.info("Using {} threads for broker service IO", numThreads);

    EventLoopGroup acceptorEventLoop, workersEventLoop;
    if (SystemUtils.IS_OS_LINUX) {
        try {//w w  w . j av a  2  s.c  om
            acceptorEventLoop = new EpollEventLoopGroup(1, acceptorThreadFactory);
            workersEventLoop = new EpollEventLoopGroup(numThreads, workersThreadFactory);
        } catch (UnsatisfiedLinkError e) {
            acceptorEventLoop = new NioEventLoopGroup(1, acceptorThreadFactory);
            workersEventLoop = new NioEventLoopGroup(numThreads, workersThreadFactory);
        }
    } else {
        acceptorEventLoop = new NioEventLoopGroup(1, acceptorThreadFactory);
        workersEventLoop = new NioEventLoopGroup(numThreads, workersThreadFactory);
    }

    this.acceptorGroup = acceptorEventLoop;
    this.workerGroup = workersEventLoop;
    this.statsUpdater = Executors
            .newSingleThreadScheduledExecutor(new DefaultThreadFactory("pulsar-stats-updater"));
    if (pulsar.getConfiguration().isAuthorizationEnabled()) {
        this.authorizationManager = new AuthorizationManager(pulsar.getConfiguration(),
                pulsar.getConfigurationCache());
    }

    if (pulsar.getConfigurationCache() != null) {
        pulsar.getConfigurationCache().policiesCache().registerListener(this);
    }

    this.inactivityMonitor = Executors
            .newSingleThreadScheduledExecutor(new DefaultThreadFactory("pulsar-inactivity-monitor"));
    this.messageExpiryMonitor = Executors
            .newSingleThreadScheduledExecutor(new DefaultThreadFactory("pulsar-msg-expiry-monitor"));
    this.backlogQuotaManager = new BacklogQuotaManager(pulsar);
    this.backlogQuotaChecker = Executors
            .newSingleThreadScheduledExecutor(new DefaultThreadFactory("pulsar-backlog-quota-checker"));
    this.authenticationService = new AuthenticationService(pulsar.getConfiguration());

    PersistentReplicator.setReplicatorQueueSize(pulsar.getConfiguration().getReplicationProducerQueueSize());
}

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

/**
* Update rsa_api.properties, sdconf.rec, sdopts.rec on local sso server conf directory
* @param tenantInfo/*from   w w  w  .j  a  v a2  s.com*/
* @param rsaConfig
* @throws Exception
*/
public void updateRSAConfigFiles(TenantInformation tenantInfo, RSAAgentConfig rsaConfig) throws Exception {

    Validate.notNull(tenantInfo, "tenantInfo");

    String tenantName = tenantInfo.getTenant().getName();
    Validate.notEmpty(tenantName, "tenantName");

    // read from template from class resource
    ClassLoader classLoader = getClass().getClassLoader();
    InputStream templateStrm = classLoader.getResourceAsStream(RSA_API_PROPERTIES_TEMPLATE);
    Validate.notNull(templateStrm, "rsa_api.properties resource not found");

    // create tenant config directory if it does not exist
    File tenantConfigDir = ensureTenantConfigDirExist(tenantName);

    // create config file
    File tenantConfigFile = new File(tenantConfigDir, RSA_API_PROPERTIES_NAME);

    BufferedReader br = new BufferedReader(new InputStreamReader(templateStrm));

    String lines = "";
    String siteID = _clusterID;
    RSAAMInstanceInfo instInfo = rsaConfig.get_instMap().get(siteID);

    if (instInfo == null) {
        // site info are not defined.
        return;
    }
    String line;
    try {
        line = br.readLine();
        String ls = System.getProperty("line.separator");
        while (line != null) {
            String[] attrVal = line.split("=");

            if (attrVal == null || attrVal.length < 1) {
                continue;
            }

            String attr = attrVal[0].replace("#", "");
            String newLine;
            switch (attr) {
            // keys that are configurable
            case RSA_AGENT_NAME:
                newLine = RSA_AGENT_NAME + "=" + instInfo.get_agentName() + ls;
                lines += newLine;
                break;

            case SDCONF_LOC: {
                byte[] sdConfBytes = instInfo.get_sdconfRec();
                Validate.notNull(sdConfBytes);

                // delete existing file.
                File sdConfFile = new File(tenantConfigDir, SD_CONF_NAME);
                sdConfFile.delete();

                // write the file
                String sdConfFilePath = sdConfFile.getAbsolutePath();
                FileOutputStream fos;
                try {
                    fos = new FileOutputStream(sdConfFilePath);
                } catch (IOException e) {
                    logger.error("Can not create or open sdconf.rec: " + sdConfFilePath, e);
                    throw e;
                }
                try {
                    fos.write(sdConfBytes);
                } catch (IOException e) {
                    logger.error("Can not write to sdconf.rec: " + sdConfFilePath, e);
                    throw e;
                } finally {
                    fos.close();
                }
                // update the api properties
                newLine = SDCONF_LOC + "=" + sdConfFilePath + ls;
                lines += StringEscapeUtils.escapeJava(newLine);

                break;
            }
            case SDOPTS_LOC: {
                byte[] sdOptsBytes = instInfo.get_sdoptsRec();
                if (sdOptsBytes == null) {
                    newLine = "#" + SDOPTS_LOC + "=" + ls;
                    lines += newLine;
                    break;
                }

                // delete existing file.
                File sdOptsFile = new File(tenantConfigDir, SD_OPTS_NAME);
                sdOptsFile.delete();

                // write the file
                String sdOptsFilePath = sdOptsFile.getAbsolutePath();
                FileOutputStream fos;
                try {
                    fos = new FileOutputStream(sdOptsFilePath);
                } catch (IOException e) {
                    logger.error("Can not create or open sdopts.rec: " + sdOptsFilePath, e);
                    throw e;
                }
                try {
                    fos.write(sdOptsBytes);
                } catch (IOException e) {
                    logger.error("Can not write to sdopts.rec: " + sdOptsFilePath, e);
                    throw e;
                } finally {
                    fos.close();
                }
                // update the api properties
                newLine = SDOPTS_LOC + "=" + sdOptsFilePath;
                lines += StringEscapeUtils.escapeJava(newLine);

                break;
            }

            case RSA_LOG_LEVEL:
                newLine = RSA_LOG_LEVEL + "=" + rsaConfig.get_logLevel() + ls;
                lines += newLine;
                break;

            case RSA_LOG_FILE_SIZE:
                newLine = RSA_LOG_FILE_SIZE + "=" + rsaConfig.get_logFileSize() + "MB" + ls;
                lines += newLine;
                break;

            case RSA_LOG_FILE_COUNT:
                newLine = RSA_LOG_FILE_COUNT + "=" + rsaConfig.get_maxLogFileCount() + ls;
                lines += newLine;
                break;

            case RSA_CONNECTION_TIMEOUT:
                newLine = RSA_CONNECTION_TIMEOUT + "=" + rsaConfig.get_connectionTimeOut() + ls;
                lines += newLine;
                break;

            case RSA_READ_TIMEOUT:
                newLine = RSA_READ_TIMEOUT + "=" + rsaConfig.get_readTimeOut() + ls;
                lines += newLine;
                break;

            case RSA_ENC_ALGLIST:
                Set<String> encSet = rsaConfig.get_rsaEncAlgList();
                Validate.notNull(encSet);
                String[] encArray = encSet.toArray(new String[encSet.size()]);

                newLine = RSA_ENC_ALGLIST + "=";
                if (encArray.length > 0) {
                    newLine += encArray[0];
                }
                for (int i = 1; i < encArray.length; i++) {
                    newLine += ("," + encArray[i]);
                }
                newLine += ls;
                lines += newLine;
                break;

            // keys that not configurable
            case RSA_AGENT_PLATFORM:
                newLine = RSA_AGENT_PLATFORM + "=";
                if (SystemUtils.IS_OS_LINUX) {
                    newLine = RSA_AGENT_PLATFORM + "=linux" + ls;
                } else {
                    newLine = RSA_AGENT_PLATFORM + "=windows" + ls;
                }
                lines += newLine;
                break;

            case RSA_CONFIG_DATA_LOC:
                newLine = RSA_CONFIG_DATA_LOC + "=" + tenantConfigDir.getAbsolutePath() + ls;
                lines += StringEscapeUtils.escapeJava(newLine);
                break;

            case SDNDSCRT_LOC:
                File sdndscrtLoc = new File(tenantConfigDir, "secureid");
                newLine = RSA_CONFIG_DATA_LOC + "=" + sdndscrtLoc.getAbsolutePath() + ls;
                lines += StringEscapeUtils.escapeJava(newLine);
                break;

            case RSA_LOG_FILE:
                String ssoConfigDir = IdmUtils.getIdentityServicesLogDir();
                File rsaLogFile = new File(ssoConfigDir, RSA_SECUREID_LOG_NAME);
                newLine = RSA_LOG_FILE + "=" + rsaLogFile.getAbsolutePath() + ls;
                lines += StringEscapeUtils.escapeJava(newLine);
                break;

            default:
                lines += (line + ls);

            }
            line = br.readLine();
        }
    } catch (IOException e) {
        logger.error("Fail to read from rsa_api.properties resource stream", e);
        throw new IDMException("Unable to generate rsa_api property file", e);
    }
    FileWriter fw;
    try {
        fw = new FileWriter(tenantConfigFile);
    } catch (IOException e) {
        logger.error("Fail to create rsa_api.properties file", e);
        throw new IDMException("Unable to generate rsa_api property file", e);
    }

    BufferedWriter out = new BufferedWriter(fw);
    try {
        tenantInfo.get_rsaConfigFilesLock().writeLock().lock();
        out.write(lines.toString());
    } catch (IOException e) {
        logger.error("Fail to write to rsa_api.properties file", e);
        throw new IDMException("Unable to generate rsa_api property file", e);
    } finally {
        try {
            out.close();
        } catch (IOException e) {
            tenantInfo.get_rsaConfigFilesLock().writeLock().unlock();
            logger.error("Fail to close to rsa_api.properties file BufferWriter", e);
            throw new IDMException("Unable to generate rsa_api property file", e);
        }
        tenantInfo.get_rsaConfigFilesLock().writeLock().unlock();
    }
}

From source file:com.igormaznitsa.sciareto.ui.UiUtils.java

private static void showURLExternal(@Nonnull final URL url) {
    if (Desktop.isDesktopSupported()) {
        final Desktop desktop = Desktop.getDesktop();
        if (desktop.isSupported(Desktop.Action.BROWSE)) {
            try {
                desktop.browse(url.toURI());
            } catch (Exception x) {
                LOGGER.error("Can't browse URL in Desktop", x);
            }//from w ww .j av a  2  s. c  o m
        } else if (SystemUtils.IS_OS_LINUX) {
            final Runtime runtime = Runtime.getRuntime();
            try {
                runtime.exec("xdg-open " + url);
            } catch (IOException e) {
                LOGGER.error("Can't browse URL under Linux", e);
            }
        } else if (SystemUtils.IS_OS_MAC) {
            final Runtime runtime = Runtime.getRuntime();
            try {
                runtime.exec("open " + url);
            } catch (IOException e) {
                LOGGER.error("Can't browse URL on MAC", e);
            }
        }
    }

}

From source file:com.vmware.identity.idm.server.config.IdmServerConfig.java

private IdmServerConfig() {
    if (SystemUtils.IS_OS_LINUX) {
        CONFIG_DIRECTORY_ROOT_KEY = "Services\\vmdir";
    } else {//  w  ww.ja v a  2 s. co  m
        CONFIG_DIRECTORY_ROOT_KEY = "System\\CurrentControlset\\Services\\VMwareDirectoryService";
    }
    CONFIG_DIRECTORY_PARAMETERS_KEY = CONFIG_DIRECTORY_ROOT_KEY + "\\Parameters";

    IRegistryAdapter regAdapter = RegistryAdapterFactory.getInstance().getRegistryAdapter();

    IRegistryKey rootKey = regAdapter.openRootKey((int) RegKeyAccess.KEY_READ);

    try {
        _configStoreType = getConfigStoreType(regAdapter, rootKey);

        getServiceProviderUsername();
        getServiceProviderConnParams(regAdapter, rootKey);
        loadConfigStoreProperties();
        loadSystemDomainProperties(regAdapter, rootKey);
        loadTenancyConfig(regAdapter, rootKey);
        loadIdmAuthStatsConfig(regAdapter, rootKey);

        ArrayList<Attribute> attributesList = new ArrayList<Attribute>();
        Attribute attr = new Attribute(ATTRIBUTE_GROUPS);
        attr.setFriendlyName(ATTRIBUTE_GROUPS_FRIENDLY_NAME);
        attr.setNameFormat(ATTRNAME_FORMAT_URI);

        attributesList.add(attr);

        attr = new Attribute(ATTRIBUTE_FIRST_NAME);
        attr.setFriendlyName(ATTRIBUTE_FIRST_NAME_FRIENDLY_NAME);
        attr.setNameFormat(ATTRNAME_FORMAT_URI);

        attributesList.add(attr);

        attr = new Attribute(ATTRIBUTE_LAST_NAME);
        attr.setFriendlyName(ATTRIBUTE_LAST_NAME_FRIENDLY_NAME);
        attr.setNameFormat(ATTRNAME_FORMAT_URI);

        attributesList.add(attr);

        attr = new Attribute(ATTRIBUTE_SUBJECT_TYPE);
        attr.setFriendlyName(ATTRIBUTE_SUBJECT_TYPE_FRIENDLY_NAME);
        attr.setNameFormat(ATTRNAME_FORMAT_URI);

        attributesList.add(attr);

        attr = new Attribute(ATTRIBUTE_USER_PRINCIPAL_NAME);
        attr.setFriendlyName(ATTRIBUTE_USER_PRINCIPAL_NAME_FRIENDLY_NAME);
        attr.setNameFormat(ATTRNAME_FORMAT_URI);

        attributesList.add(attr);

        attr = new Attribute(ATTRIBUTE_EMAIL);
        attr.setFriendlyName(ATTRIBUTE_EMAIL_FRIENDLY_NAME);
        attr.setNameFormat(ATTRNAME_FORMAT_URI);

        attributesList.add(attr);

        this._defaultAttributes = Collections.unmodifiableList(attributesList);
    } finally {
        rootKey.close();
    }
}

From source file:com.asakusafw.testdriver.inprocess.InProcessJobExecutorTest.java

/**
 * Test method for executing non-emulated command.
 *//*from  ww w . j  av a  2s . c om*/
@Test
public void executeCommand_delegate() {
    Assume.assumeTrue("not unix-like", SystemUtils.IS_OS_MAC_OSX || SystemUtils.IS_OS_LINUX);

    File touch = new File("/usr/bin/touch");
    Assume.assumeTrue("no 'touch' command", touch.isFile() && touch.canExecute());

    AtomicBoolean call = new AtomicBoolean();
    MockCommandEmulator.callback(args -> call.set(true));
    File target = new File(framework.getWork("working"), "target");
    Assume.assumeFalse(target.exists());

    // exec: touch .../target
    TestExecutionPlan.Command command = command("generic", touch.getPath(), target.getAbsolutePath());
    JobExecutor executor = new InProcessJobExecutor(context);
    try {
        executor.execute(command, Collections.emptyMap());
    } catch (IOException e) {
        throw new AssertionError(e);
    }
    assertThat(target.exists(), is(true));
    assertThat(call.get(), is(false));
}

From source file:cn.schina.dbfw.service.SystemLicenseSrever.java

/**
 * //from www.  j  a v a2 s  . co m
 * <b>?</b><br/>
 * 
 * @author <b>LCL</b><br/>
 * @date 2016-8-3
 * 
 * @return
 */
public static int ifNsfocus() {
    int returnValure = 0;
    try {
        if (SystemUtils.IS_OS_LINUX) {
            String[] cmd = { "/bin/sh", "-c", " cat /etc/producttype " };
            String value = runCmd(cmd).trim();
            if (value.contains("Nsfocus")) {
                returnValure = 1;
            }
        }
    } catch (Exception e) {
        e.printStackTrace();
    }
    return returnValure;
}

From source file:interactivespaces.liveactivity.runtime.standalone.StandaloneActivityRunner.java

/**
 * Add dynamic configuration parameters to this configuration.
 *
 * @param configuration//from  w w w. jav  a2 s. c  o m
 *          the configuration to dynamically update
 */
private void addDynamicConfiguration(Configuration configuration) {
    String platformOs = SystemUtils.IS_OS_LINUX ? "linux" : "osx";
    configuration.setValue("interactivespaces.platform.os", platformOs);

    try {
        String hostname = InetAddress.getLocalHost().getHostName();
        configuration.setValue(InteractiveSpacesEnvironment.CONFIGURATION_HOSTNAME, hostname);
        configuration.setValue(InteractiveSpacesEnvironment.CONFIGURATION_HOSTID, hostname);
        String hostAddress = InetAddress.getByName(hostname).getHostAddress();
        configuration.setValue(InteractiveSpacesEnvironment.CONFIGURATION_HOST_ADDRESS, hostAddress);
    } catch (UnknownHostException e) {
        throw new InteractiveSpacesException("Could not determine hostname", e);
    }
}