Example usage for java.lang Boolean getBoolean

List of usage examples for java.lang Boolean getBoolean

Introduction

In this page you can find the example usage for java.lang Boolean getBoolean.

Prototype

public static boolean getBoolean(String name) 

Source Link

Document

Returns true if and only if the system property named by the argument exists and is equal to, ignoring case, the string "true" .

Usage

From source file:org.mule.test.infrastructure.process.MuleContextProcessBuilder.java

private TestProcess build() {
    List<String> command = new ArrayList<String>();
    command.add("java");
    command.add("-cp");
    command.add(System.getProperty("java.class.path"));
    if (Boolean.getBoolean("debug")) {
        command.add("-Xdebug");
        int debugPort = getDebugPort();
        command.add("-Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=" + debugPort);
        logger.info(String.format("To connect to process %s for debugging use port %d", instanceId, debugPort));
    }//from   ww w  .  j  ava  2s  .  com
    for (String systemPropertyKey : systemProperties.keySet()) {
        command.add(String.format("-D%s=%s", systemPropertyKey, systemProperties.get(systemPropertyKey)));
    }
    if (muleAppClass == null) {
        command.add("org.mule.test.infrastructure.process.MuleContextProcessApplication");
    } else {
        command.add(muleAppClass);
    }
    ProcessBuilder processBuilder = new ProcessBuilder(command);
    try {
        TestProcess testProcess = new TestProcess(instanceId,
                Integer.valueOf(systemProperties.get(LOG_PORT_PROPERTY)),
                Integer.valueOf(systemProperties.get(COMMAND_PORT_PROPERTY)));
        Process process = processBuilder.start();
        testProcess.setProcess(process);
        return testProcess;
    } catch (IOException e) {
        throw new RuntimeException(e);
    }
}

From source file:org.nuxeo.vision.aws.test.TestAmazonRekognitionProvider.java

protected boolean areCredentialsSet() {
    return Boolean.getBoolean(PROVIDES_AWS_CREDENTIALS);
}

From source file:org.hawkular.wildfly.agent.installer.AgentInstaller.java

public static void main(String[] args) throws Exception {
    ProcessedCommand<?> options = null;

    ArrayList<File> filesToDelete = new ArrayList<>();

    try {// ww w  .  j ava2  s .  co  m
        options = InstallerConfiguration.buildCommandLineOptions();
        CommandLineParser<?> parser = new CommandLineParserBuilder().processedCommand(options).create();

        StringBuilder argLine = new StringBuilder(InstallerConfiguration.COMMAND_NAME);
        for (String str : args) {
            argLine.append(' ').append(str);
        }

        CommandLine<?> commandLine = parser.parse(argLine.toString());
        InstallerConfiguration installerConfig = new InstallerConfiguration(commandLine);

        // IF we were told the passwords were encrypted THEN
        //   IF we were given the key on the command line THEN
        //      Use the key given on the command line for decoding
        //   ELSE
        //      Use the key the user gives us over stdin for decoding
        //
        //   IF we were given the salt on the command line THEN
        //      Use the salt given on the command line for decoding
        //   ELSE
        //      Use the salt the user gives us over stdin for decoding
        //
        // Decode using the key and salt.
        boolean passwordsEncrypted = commandLine.hasOption(InstallerConfiguration.OPTION_ENCRYPTION_KEY);
        if (passwordsEncrypted) {
            String key = commandLine.getOptionValue(InstallerConfiguration.OPTION_ENCRYPTION_KEY, null);
            String saltAsString = commandLine.getOptionValue(InstallerConfiguration.OPTION_ENCRYPTION_SALT,
                    null);
            if (key == null || key.isEmpty()) {
                key = readPasswordFromStdin("Encryption key:");
            }

            boolean saltSpecified = commandLine.hasOption(InstallerConfiguration.OPTION_ENCRYPTION_SALT);
            if (!saltSpecified) {
                saltAsString = key;
            }

            if (saltAsString == null || saltAsString.isEmpty()) {
                saltAsString = readPasswordFromStdin("Salt:");
            }

            assert saltAsString != null;
            assert key != null;

            byte[] salt = saltAsString.getBytes("UTF-8");
            installerConfig.decodeProperties(key, salt);
        }

        String jbossHome = installerConfig.getTargetLocation();
        if (jbossHome == null) {
            // user did not provide us with a wildfly home - let's see if we are sitting in a wildfly home already
            File jbossHomeFile = new File(".").getCanonicalFile();
            if (!(jbossHomeFile.exists() && jbossHomeFile.isDirectory() && jbossHomeFile.canRead()
                    && new File(jbossHomeFile, "modules").isDirectory())) {
                throw new Exception(InstallerConfiguration.OPTION_TARGET_LOCATION + " must be specified");
            }
            // looks like our current working directory is a WildFly home - use that
            jbossHome = jbossHomeFile.getCanonicalPath();
        }

        if ((installerConfig.getUsername() == null || installerConfig.getPassword() == null)
                && (installerConfig.getSecurityKey() == null || installerConfig.getSecuritySecret() == null)) {
            throw new Exception(
                    "You must provide credentials (username/password or key/secret) in installer configuration");
        }

        String hawkularServerProtocol;
        String hawkularServerHost;
        String hawkularServerPort;

        if (installerConfig.getServerUrl() == null) {
            throw new Exception("You must provide the Hawkular Server URL");
        }

        try {
            URL hawkularServerUrl = new URL(installerConfig.getServerUrl());
            hawkularServerProtocol = hawkularServerUrl.getProtocol();
            hawkularServerHost = hawkularServerUrl.getHost();
            hawkularServerPort = String.valueOf(hawkularServerUrl.getPort());
            if ("-1".equals(hawkularServerPort)) {
                hawkularServerPort = "80";
            }
        } catch (MalformedURLException mue) {
            // its possible the user passed a URL with a WildFly expression like
            // "http://${jboss.bind.address:localhost}:8080". Try to parse something like that.
            Matcher m = Pattern.compile("(https?)://(.*):(\\d+)").matcher(installerConfig.getServerUrl());
            if (!m.matches()) {
                throw mue;
            }
            try {
                hawkularServerProtocol = m.group(1);
                hawkularServerHost = m.group(2);
                hawkularServerPort = m.group(3);
            } catch (Exception e) {
                throw mue;
            }
        }

        String moduleZip = installerConfig.getModuleDistribution();

        URL moduleZipUrl;

        if (moduleZip == null) {
            // --module is not supplied so try to download agent module from server
            File moduleTempFile = downloadModuleZip(getHawkularServerAgentDownloadUrl(installerConfig));
            if (moduleTempFile == null) {
                throw new IOException("Failed to retrieve module dist from server, You can use option ["
                        + InstallerConfiguration.OPTION_MODULE_DISTRIBUTION + "] to supply your own");
            }
            filesToDelete.add(moduleTempFile);
            moduleZipUrl = moduleTempFile.toURI().toURL();
        } else if (moduleZip.startsWith("classpath:")) {
            // This special protocol tells us to read module zip as resource from classpath.
            // This is in case the module zip is bundled directly in the installer.
            String resourceUrl = moduleZip.substring(10);
            if (!resourceUrl.startsWith("/")) {
                resourceUrl = "/" + resourceUrl;
            }
            moduleZipUrl = AgentInstaller.class.getResource(resourceUrl);
            if (moduleZipUrl == null) {
                throw new IOException("Unable to load module.zip from classpath [" + resourceUrl + "]");
            }
        } else if (moduleZip.matches("(http|https|file):.*")) {
            // the module is specified as a URL - we'll download it
            File moduleTempFile = downloadModuleZip(new URL(moduleZip));
            if (moduleTempFile == null) {
                throw new IOException("Failed to retrieve agent module from server, option ["
                        + InstallerConfiguration.OPTION_MODULE_DISTRIBUTION
                        + "] is now required but it was not supplied");
            }
            filesToDelete.add(moduleTempFile);
            moduleZipUrl = moduleTempFile.toURI().toURL();
        } else {
            // the module is specified as a file path
            moduleZipUrl = new File(moduleZip).toURI().toURL();
        }

        // deploy given module into given app server home directory and
        // set it up the way it talks to hawkular server on hawkularServerUrl
        // TODO support domain mode
        File socketBindingSnippetFile = createSocketBindingSnippet(hawkularServerHost, hawkularServerPort);
        filesToDelete.add(socketBindingSnippetFile);
        Builder configurationBldr = DeploymentConfiguration.builder().jbossHome(new File(jbossHome))
                .module(moduleZipUrl).socketBinding(socketBindingSnippetFile.toURI().toURL());

        // let the user override the default subsystem snippet that is found in the module zip
        // can be specified as a URL or a file path
        if (installerConfig.getSubsystemSnippet() != null) {
            try {
                configurationBldr.subsystem(new URL(installerConfig.getSubsystemSnippet()));
            } catch (MalformedURLException mue) {
                File file = new File(installerConfig.getSubsystemSnippet());
                if (file.exists()) {
                    configurationBldr.subsystem(file.getAbsoluteFile().toURI().toURL());
                } else {
                    throw new FileNotFoundException(
                            "Subsystem snippet not found at [" + installerConfig.getSubsystemSnippet() + "]");
                }
            }
        }

        String targetConfig = installerConfig.getTargetConfig();
        if (targetConfig != null) {
            configurationBldr.serverConfig(targetConfig);
        } else {
            targetConfig = DeploymentConfiguration.DEFAULT_SERVER_CONFIG;
            // we'll use this in case of https to resolve server configuration directory
        }

        // If we are to talk to the Hawkular Server over HTTPS, we need to set up some additional things
        if (hawkularServerProtocol.equals("https")) {
            String keystorePath = installerConfig.getKeystorePath();
            String keystorePass = installerConfig.getKeystorePassword();
            String keyPass = installerConfig.getKeyPassword();
            String keyAlias = installerConfig.getKeyAlias();
            if (keystorePath == null || keyAlias == null) {
                throw new Exception(String.format(
                        "When using https protocol, the following keystore "
                                + "command line options are required: %s, %s",
                        InstallerConfiguration.OPTION_KEYSTORE_PATH, InstallerConfiguration.OPTION_KEY_ALIAS));
            }

            // password fields are not required, but if not supplied we'll ask user
            if (keystorePass == null) {
                keystorePass = readPasswordFromStdin("Keystore password:");
                if (keystorePass == null || keystorePass.isEmpty()) {
                    keystorePass = "";
                    log.warn(InstallerConfiguration.OPTION_KEYSTORE_PASSWORD
                            + " was not provided; using empty password");
                }
            }
            if (keyPass == null) {
                keyPass = readPasswordFromStdin("Key password:");
                if (keyPass == null || keyPass.isEmpty()) {
                    keyPass = "";
                    log.warn(InstallerConfiguration.OPTION_KEY_PASSWORD
                            + " was not provided; using empty password");
                }
            }

            // if given keystore path is not already present within server-config directory, copy it
            File keystoreSrcFile = new File(keystorePath);
            if (!(keystoreSrcFile.isFile() && keystoreSrcFile.canRead())) {
                throw new FileNotFoundException("Cannot read " + keystoreSrcFile.getAbsolutePath());
            }
            File targetConfigDir;
            if (new File(targetConfig).isAbsolute()) {
                targetConfigDir = new File(targetConfig).getParentFile();
            } else {
                targetConfigDir = new File(jbossHome, targetConfig).getParentFile();
            }
            Path keystoreDst = Paths.get(targetConfigDir.getAbsolutePath()).resolve(keystoreSrcFile.getName());
            // never overwrite target keystore
            if (!keystoreDst.toFile().exists()) {
                log.info(
                        "Copy [" + keystoreSrcFile.getAbsolutePath() + "] to [" + keystoreDst.toString() + "]");
                Files.copy(Paths.get(keystoreSrcFile.getAbsolutePath()), keystoreDst);
            }

            // setup security-realm and storage-adapter (within hawkular-wildfly-agent subsystem)
            String securityRealm = createSecurityRealm(keystoreSrcFile.getName(), keystorePass, keyPass,
                    keyAlias);
            configurationBldr.addXmlEdit(new XmlEdit("/server/management/security-realms", securityRealm));
            configurationBldr.addXmlEdit(createStorageAdapter(true, installerConfig));
        } else {
            // just going over non-secure HTTP
            configurationBldr.addXmlEdit(createStorageAdapter(false, installerConfig));
        }

        configurationBldr.addXmlEdit(createManagedServers(installerConfig));
        configurationBldr.addXmlEdit(setEnableFlag(installerConfig));
        configurationBldr.modulesHome("modules");

        new ExtensionDeployer().install(configurationBldr.build());

    } catch (CommandLineParserException pe) {
        log.error(pe);
        printHelp(options);
        if (Boolean.getBoolean("org.hawkular.wildfly.agent.installer.throw-exception-on-error")) {
            throw pe;
        }
    } catch (Exception ex) {
        log.error(ex);
        if (Boolean.getBoolean("org.hawkular.wildfly.agent.installer.throw-exception-on-error")) {
            throw ex;
        }
    } finally {
        for (File fileToDelete : filesToDelete) {
            if (!fileToDelete.delete()) {
                log.warn("Failed to delete temporary file: " + fileToDelete);
            }
        }
    }
}

From source file:net.sf.keystore_explorer.gui.CreateApplicationGui.java

/**
 * Create and show KeyStore Explorer./*from  w w  w. j a  va2  s.c  o  m*/
 */
@Override
public void run() {
    try {
        if (!checkJreVersion()) {
            System.exit(1);
        }

        initLookAndFeel(applicationSettings);

        // try to remove crypto restrictions
        JcePolicyUtil.removeRestrictions();

        // if crypto strength still limited, start upgrade assistant
        if (JcePolicyUtil.isLocalPolicyCrytoStrengthLimited()) {
            upgradeCryptoStrength();
        }

        final KseFrame kseFrame = new KseFrame();

        // workaround to a bug in initializing JEditorPane that seems to be a 1-in-10000 problem
        if (Thread.currentThread().getContextClassLoader() == null) {
            Thread.currentThread().setContextClassLoader(ClassLoader.getSystemClassLoader());
        }

        if (OperatingSystem.isMacOs()) {
            integrateWithMacOs(kseFrame);
        }

        kseFrame.display();

        // check if stored location of cacerts file still exists
        checkCaCerts(kseFrame);

        // open file list passed via command line params (basically same as if files were dropped on application)
        DroppedFileHandler.openFiles(kseFrame, parameterFiles);

        // start update check in background (disabled if KSE was packaged as rpm)
        if (!Boolean.getBoolean(KseFrame.KSE_UPDATE_CHECK_DISABLED)) {
            checkForUpdates(kseFrame);
        }
    } catch (Throwable t) {
        DError dError = new DError(new JFrame(), t);
        dError.setLocationRelativeTo(null);
        dError.setVisible(true);
        System.exit(1);
    } finally {
        closeSplash();
    }

}

From source file:nl.ellipsis.webdav.server.WebDAVServlet.java

private boolean getBooleanInitParameter(String key, boolean defaultValue) {
    String value = getInitParameter(key);
    return value == null ? defaultValue : ("1".equals(value) || Boolean.getBoolean(value));
}

From source file:com.dominion.salud.pedicom.configuration.PEDICOMJpaConfigurationCentral.java

@Bean(name = "CentralEM")
@Autowired//  w w w.j  av  a  2s . c  om
public EntityManagerFactory entityManagerFactory() throws Exception {
    HibernateJpaVendorAdapter adapter = new HibernateJpaVendorAdapter();
    adapter.setGenerateDdl(
            Boolean.getBoolean(StringUtils.trim(environment.getRequiredProperty("hibernate.generate_ddl"))));
    adapter.setShowSql(
            Boolean.getBoolean(StringUtils.trim(environment.getRequiredProperty("hibernate.show_sql"))));
    adapter.setDatabasePlatform(StringUtils.trim(environment.getRequiredProperty("hibernate.dialect.central")));
    LocalContainerEntityManagerFactoryBean factory = new LocalContainerEntityManagerFactoryBean();
    factory.setDataSource(crearData());
    factory.setJpaVendorAdapter(adapter);
    factory.setPackagesToScan("com.dominion.salud.pedicom.negocio.entitiesCentral");
    factory.setPersistenceUnitName("CentralEM");
    factory.afterPropertiesSet();
    factory.setLoadTimeWeaver(new InstrumentationLoadTimeWeaver());
    return factory.getObject();
}

From source file:org.apache.geode.distributed.AbstractLauncher.java

public AbstractLauncher() {
    try {/*w  ww.j a va 2 s  .  co m*/
        if (Boolean.getBoolean(SIGNAL_HANDLER_REGISTRATION_SYSTEM_PROPERTY)) {
            forName(SUN_SIGNAL_API_CLASS_NAME, new SunAPINotFoundException(
                    "WARNING!!! Not running a Sun JVM.  Could not find the sun.misc.Signal class; Signal handling disabled."));
            RegisterSignalHandlerSupport.registerSignalHandlers();
        }
    } catch (SunAPINotFoundException handled) {
        info(handled.getMessage());
    }
}

From source file:com.netflix.config.ConfigurationManager.java

private static AbstractConfiguration createDefaultConfigInstance() {
    ConcurrentCompositeConfiguration config = new ConcurrentCompositeConfiguration();
    if (!Boolean.getBoolean(DynamicPropertyFactory.DISABLE_DEFAULT_SYS_CONFIG)) {
        try {//from  w w  w . j  av a  2  s  . c o m
            DynamicURLConfiguration defaultURLConfig = new DynamicURLConfiguration();
            config.addConfiguration(defaultURLConfig, DynamicPropertyFactory.URL_CONFIG_NAME);
        } catch (Throwable e) {
            logger.warn("Failed to create default dynamic configuration", e);
        }
        SystemConfiguration sysConfig = new SystemConfiguration();
        config.addConfiguration(sysConfig, DynamicPropertyFactory.SYS_CONFIG_NAME);
        int index = config.getIndexOfConfiguration(sysConfig);
        config.setContainerConfigurationIndex(index);
    }
    return config;
}

From source file:org.pentaho.platform.repository.solution.filebased.FileBasedSolutionRepository.java

@Override
public void init() {
    if (!repositoryInit) {
        super.init();

        String flag = PentahoSystem.getSystemSetting("filebased-solution-cache", "false"); //$NON-NLS-1$ //$NON-NLS-2$
        try {/*  w w  w .jav a  2  s  . co  m*/
            useActionSequenceCaching = Boolean.getBoolean(flag);
        } catch (Exception e) {
            useActionSequenceCaching = false;
        }
        repositoryInit = true;
    }
}

From source file:io.adeptj.runtime.core.Launcher.java

private static void shutdownJvm(Throwable th) {
    if (Boolean.getBoolean(SYS_PROP_ENABLE_SYSTEM_EXIT)) {
        Logger logger = LoggerFactory.getLogger(Launcher.class);
        // Check if OSGi Framework was already started, try to stop the framework gracefully.
        Optional.ofNullable(BundleContextHolder.getInstance().getBundleContext()).ifPresent(context -> {
            logger.warn("Server startup failed but OSGi Framework already started, stopping it gracefully!!");
            FrameworkManager.getInstance().stopFramework();
        });/*w  w w  .j ava 2  s  .com*/
        logger.error("Shutting down JVM!!", th);
        // Let the LOGBACK cleans up it's state.
        LogbackManager.INSTANCE.getLoggerContext().stop();
        System.exit(-1);
    }
}