Example usage for java.lang System setProperties

List of usage examples for java.lang System setProperties

Introduction

In this page you can find the example usage for java.lang System setProperties.

Prototype

public static void setProperties(Properties props) 

Source Link

Document

Sets the system properties to the Properties argument.

Usage

From source file:org.commonjava.aprox.boot.BootOptions.java

public void setSystemProperties() {
    final Properties properties = System.getProperties();

    System.out.printf("\n\nUsing AProx configuration: %s\n", config);
    properties.setProperty(BootInterface.CONFIG_PATH_PROP, config);
    properties.setProperty(BootInterface.APROX_HOME_PROP, aproxHome);
    System.setProperties(properties);
}

From source file:org.commonjava.indy.tools.cache.Main.java

private int run(final MigrationOptions options) throws IndyBootException {
    try {//from ww  w  .jav  a2  s.co m
        File inXml = options.getInfinispanXml();
        if (inXml != null) {
            File outXmlDir = new File(System.getProperty("java.io.tmpdir", "/tmp"),
                    "infinispan-config-" + System.currentTimeMillis());
            if (!outXmlDir.isDirectory() && !outXmlDir.mkdirs()) {
                throw new IndyBootException(
                        "Failed to create temporary direcory for infinispan configuration loading");
            }

            File outXml = new File(outXmlDir, "infinispan.xml");
            FileUtils.copyFile(inXml, outXml);

            Properties props = System.getProperties();

            props.setProperty("indy.config.dir", outXmlDir.getAbsolutePath());

            System.setProperties(props);
        }

        producer = new SimpleCacheProducer();

        CacheHandle<Object, Object> cache = producer.getCache(options.getCacheName());
        if (MigrationCommand.dump == options.getMigrationCommand()) {
            AtomicReference<Throwable> error = new AtomicReference<>();
            try (ObjectOutputStream out = new ObjectOutputStream(
                    new GZIPOutputStream(new FileOutputStream(options.getDataFile())))) {
                cache.executeCache((c) -> {
                    try {
                        out.writeLong(c.size());
                    } catch (IOException e) {
                        logger.error("Failed to write data file header.", e);
                        error.set(e);
                    }

                    if (error.get() == null) {
                        c.forEach((k, v) -> {
                            if (error.get() == null) {
                                try {
                                    out.writeObject(k);
                                    out.writeObject(v);
                                } catch (IOException e) {
                                    logger.error("Failed to write entry with key: " + k, e);
                                    error.set(e);
                                }
                            }
                        });
                    }

                    return true;
                });
            } catch (IOException e) {
                error.set(e);
            }

            if (error.get() != null) {
                throw new IndyBootException("Failed to write data to file: " + options.getDataFile(),
                        error.get());
            }
        } else {
            AtomicReference<Throwable> error = new AtomicReference<>();
            try (ObjectInputStream in = new ObjectInputStream(
                    new GZIPInputStream(new FileInputStream(options.getDataFile())))) {
                cache.executeCache((c) -> {
                    try {
                        long records = in.readLong();

                        for (long i = 0; i < records; i++) {
                            try {
                                Object k = in.readObject();
                                Object v = in.readObject();

                                c.putAsync(k, v);
                            } catch (Exception e) {
                                logger.error("Failed to read entry at index: " + i, e);
                                error.set(e);
                            }
                        }
                        logger.info("Load {} complete, size: {}", options.getCacheName(), records);
                    } catch (IOException e) {
                        logger.error("Failed to read data file header.", e);
                        error.set(e);
                    }
                    return true;
                });
            } catch (IOException e) {
                error.set(e);
            }

            if (error.get() != null) {
                throw new IndyBootException("Failed to read data from file: " + options.getDataFile(),
                        error.get());
            }
        }

    } catch (final Throwable e) {
        if (e instanceof IndyBootException)
            throw (IndyBootException) e;

        logger.error("Failed to initialize Booter: " + e.getMessage(), e);
        return ERR_CANT_INIT_BOOTER;
    } finally {
        try {
            producer.stop();
        } catch (final IndyLifecycleException e) {
            logger.error("Failed to stop cache subsystem: " + e.getMessage(), e);
        }
    }

    return 0;
}

From source file:org.commonjava.aprox.test.fixture.core.CoreServerFixture.java

private static BootOptions editBootOptions(final BootOptions options, final String aproxHome) {
    if (aproxHome != null) {
        final Properties properties = System.getProperties();
        properties.setProperty("aprox.home", aproxHome);
        System.setProperties(properties);
    }/*from   w  w  w . j  a  v a 2 s.c om*/

    options.setPort(generatePort());

    return options;
}

From source file:org.commonjava.indy.boot.BootOptions.java

public void setSystemProperties() {
    final Properties properties = System.getProperties();

    System.out.printf("\n\nUsing Indy configuration: %s\n", config);
    properties.setProperty(BootInterface.CONFIG_PATH_PROP, config);
    properties.setProperty(BootInterface.INDY_HOME_PROP, indyHome);
    properties.setProperty(BootInterface.APROX_CONFIG_PATH_PROP, config);
    properties.setProperty(BootInterface.APROX_HOME_PROP, indyHome);
    System.setProperties(properties);
}

From source file:com.yahoo.ycsb.db.CouchbaseClient.java

@Override
public void init() throws DBException {
    Properties props = getProperties();

    String url = props.getProperty(URL_PROPERTY, "http://127.0.0.1:8091/pools");
    String bucket = props.getProperty(BUCKET_PROPERTY, "default");
    String password = props.getProperty(PASSWORD_PROPERTY, "");

    checkFutures = props.getProperty(CHECKF_PROPERTY, "true").equals("true");
    useJson = props.getProperty(JSON_PROPERTY, "true").equals("true");

    persistTo = parsePersistTo(props.getProperty(PERSIST_PROPERTY, "0"));
    replicateTo = parseReplicateTo(props.getProperty(REPLICATE_PROPERTY, "0"));

    Properties systemProperties = System.getProperties();
    systemProperties.put("net.spy.log.LoggerImpl", "net.spy.memcached.compat.log.SLF4JLogger");
    System.setProperties(systemProperties);

    try {//from www.j a va 2  s .  c o  m
        client = new com.couchbase.client.CouchbaseClient(Arrays.asList(new URI(url)), bucket, password);
    } catch (Exception e) {
        throw new DBException("Could not create CouchbaseClient object.", e);
    }
}

From source file:org.pentaho.di.junit.rules.RestorePDIEnvironment.java

@Override
protected void before() throws Throwable {
    originalProperties = System.getProperties();
    System.setProperties(copyOf(originalProperties));

    originalLocale = Locale.getDefault();
    originalFormatLocale = Locale.getDefault(Locale.Category.FORMAT);
    originalTimezone = TimeZone.getDefault();
    TimeZone.setDefault(TimeZone.getTimeZone("UTC"));
    Locale.setDefault(Locale.US);
    Locale.setDefault(Locale.Category.FORMAT, Locale.US);
    LanguageChoice.getInstance().setDefaultLocale(Locale.US);

    tmpKettleHome = Files.createTempDirectory(Long.toString(System.nanoTime()));
    System.setProperty("file.encoding", "UTF-8");
    System.setProperty("user.timezone", "UTC");
    System.setProperty("KETTLE_HOME", tmpKettleHome.toString());
    System.setProperty(Const.KETTLE_DISABLE_CONSOLE_LOGGING, "Y");
    System.clearProperty(Const.VFS_USER_DIR_IS_ROOT);
    System.clearProperty(Const.KETTLE_LENIENT_STRING_TO_NUMBER_CONVERSION);
    System.clearProperty(Const.KETTLE_COMPATIBILITY_DB_IGNORE_TIMEZONE);
    System.clearProperty(Const.KETTLE_DEFAULT_INTEGER_FORMAT);
    System.clearProperty(Const.KETTLE_DEFAULT_NUMBER_FORMAT);
    System.clearProperty(Const.KETTLE_DEFAULT_BIGNUMBER_FORMAT);
    System.clearProperty(Const.KETTLE_DEFAULT_DATE_FORMAT);
    System.clearProperty(Const.KETTLE_DEFAULT_TIMESTAMP_FORMAT);
    System.clearProperty(Const.KETTLE_EMPTY_STRING_DIFFERS_FROM_NULL);

    defaultInit();//from www  .jav  a2s . c  o  m
}

From source file:com.silverpeas.bootstrap.SilverpeasContextBootStrapper.java

/**
 * Initialise the System.properties according to Silverpeas needs and configuration.
 *
 * @param sce/*w  w  w  .jav a 2s.c  o  m*/
 */
@Override
public void contextInitialized(ServletContextEvent sce) {
    ResourceBundle silverpeasInitialisationSettings = FileUtil.loadBundle(
            "org.silverpeas._silverpeasinitialize.settings._silverpeasinitializeSettings",
            new Locale("fr", ""));

    loadExternalJarLibraries();

    String systemSettingsPath = silverpeasInitialisationSettings.getString("pathInitialize");
    if (!StringUtil.isDefined(systemSettingsPath)) {
        Logger.getLogger("bootstrap").log(Level.SEVERE,
                "Repository Initialize for systemSettings.properties file is not defined in Settings.");
    } else {
        File pathInitialize = new File(systemSettingsPath);
        FileInputStream fis = null;
        try {
            fis = new FileInputStream(new File(pathInitialize, "systemSettings.properties"));
            Properties systemFileProperties = new Properties(System.getProperties());
            systemFileProperties.load(fis);

            // Fix - empty proxy port and proxy host not supported by Spring Social
            if (!StringUtil.isDefined(systemFileProperties.getProperty("http.proxyPort"))) {
                systemFileProperties.remove("http.proxyPort");
            }
            if (!StringUtil.isDefined(systemFileProperties.getProperty("http.proxyHost"))) {
                systemFileProperties.remove("http.proxyHost");
            }

            System.setProperties(systemFileProperties);
            if (isTrustoreConfigured()) {
                registerSSLSocketFactory();
            }
        } catch (FileNotFoundException e) {
            Logger.getLogger("bootstrap").log(Level.SEVERE,
                    "File systemSettings.properties in directory {0} not found.", pathInitialize);
        } catch (IOException e) {
            Logger.getLogger("bootstrap").log(Level.SEVERE, "Unable to read systemSettings.properties.");
        } catch (GeneralSecurityException e) {
            Logger.getLogger("bootstrap").log(Level.SEVERE, "Unable to configure the trustore.");
        } finally {
            IOUtils.closeQuietly(fis);
        }

    }
    URLManager.setSilverpeasVersion(sce.getServletContext().getInitParameter("SILVERPEAS_VERSION"));
    springContextListener.contextInitialized(sce);
}

From source file:org.holistic.ws_proxy.WSProxyHelper.java

private void set_timeout(int iValue) {
    if (iValue > 0) {
        java.util.Properties m_objProperties = System.getProperties();
        m_objProperties.put("sun.net.client.defaultConnectTimeout", "" + iValue * 1000);
        m_objProperties.put("sun.net.client.defaultReadTimeout", "" + iValue * 1000);
        System.setProperties(m_objProperties);
    }//from   w w w .  ja v  a  2s.  c o  m
}

From source file:org.jboss.pnc.indyrepositorymanager.AbstractRepositoryManagerDriverTest.java

@After
public void teardown() throws Exception {
    Properties sysprops = System.getProperties();
    if (oldIni == null) {
        sysprops.remove(CONFIG_SYSPROP);
    } else {/*from   w  ww  .  ja v  a 2 s .com*/
        sysprops.setProperty(CONFIG_SYSPROP, oldIni);
    }
    System.setProperties(sysprops);

    if (fixture != null) {
        fixture.stop();
    }
}

From source file:org.apache.activemq.store.jdbc.JmsTransactionCommitFailureTest.java

@After
public void tearDown() throws Exception {
    try {/*from   w w  w  .  ja va2s  .com*/
        stopBroker();
        stopDataSource();
    } finally {
        System.setProperties(originalSystemProps);
    }
}