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.test.fixture.core.CoreServerFixture.java

private static BootOptions newBootOptions(final File bootDefaults, final String aproxHome) {
    final Properties properties = System.getProperties();
    properties.setProperty("aprox.home", aproxHome);
    System.setProperties(properties);

    try {//from  w w  w .j  a va2 s  .  c  om
        final BootOptions options = new BootOptions(bootDefaults, aproxHome);
        options.setPort(generatePort());

        return options;
    } catch (IOException | InterpolationException e) {
        throw new IllegalStateException(
                "Cannot start core AProx server with the given configuration: " + e.getMessage(), e);
    }
}

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

@Before
public void setup() throws Exception {
    fixture = newServerFixture();//  w ww .j  a  va  2  s  .c  om

    Properties sysprops = System.getProperties();
    oldIni = sysprops.getProperty(CONFIG_SYSPROP);

    url = fixture.getUrl();
    File configFile = temp.newFile("pnc-config.json");
    ModuleConfigJson moduleConfigJson = new ModuleConfigJson("pnc-config");
    MavenRepoDriverModuleConfig mavenRepoDriverModuleConfig = new MavenRepoDriverModuleConfig(fixture.getUrl());
    mavenRepoDriverModuleConfig.setInternalRepoPatterns(getInternalRepoPatterns());
    PNCModuleGroup pncGroup = new PNCModuleGroup();
    pncGroup.addConfig(mavenRepoDriverModuleConfig);
    moduleConfigJson.addConfig(pncGroup);

    ObjectMapper mapper = new ObjectMapper();
    PncConfigProvider<MavenRepoDriverModuleConfig> pncProvider = new PncConfigProvider<MavenRepoDriverModuleConfig>(
            MavenRepoDriverModuleConfig.class);
    pncProvider.registerProvider(mapper);
    mapper.writeValue(configFile, moduleConfigJson);

    sysprops.setProperty(CONFIG_SYSPROP, configFile.getAbsolutePath());
    System.setProperties(sysprops);

    fixture.start();

    if (!fixture.isStarted()) {
        final BootStatus status = fixture.getBootStatus();
        throw new IllegalStateException("server fixture failed to boot.", status.getError());
    }

    Properties props = new Properties();
    props.setProperty("base.url", url);

    System.out.println("Using base URL: " + url);

    Configuration config = new Configuration();
    driver = new RepositoryManagerDriver(config);
}

From source file:net.sourceforge.pmd.cpd.CPD.java

private static void setSystemProperties(String[] args, CPDConfiguration config) {
    boolean ignoreLiterals = CPDConfiguration.findBooleanSwitch(args, "--ignore-literals");
    boolean ignoreIdentifiers = CPDConfiguration.findBooleanSwitch(args, "--ignore-identifiers");
    boolean ignoreAnnotations = CPDConfiguration.findBooleanSwitch(args, "--ignore-annotations");
    Properties properties = System.getProperties();
    if (ignoreLiterals) {
        properties.setProperty(JavaTokenizer.IGNORE_LITERALS, "true");
    }//  ww  w . j  av  a  2s.  c o  m
    if (ignoreIdentifiers) {
        properties.setProperty(JavaTokenizer.IGNORE_IDENTIFIERS, "true");
    }
    if (ignoreAnnotations) {
        properties.setProperty(JavaTokenizer.IGNORE_ANNOTATIONS, "true");
    }
    System.setProperties(properties);
    config.language().setProperties(properties);
}

From source file:org.evosuite.SystemTestBase.java

@After
public void resetStaticVariables() {
    RuntimeInstrumentation.setAvoidInstrumentingShadedClasses(false);
    RuntimeSettings.applyUIDTransformation = false;
    TestCaseExecutor.getInstance().newObservers();
    TestGenerationContext.getInstance().resetContext();
    ClassReInitializer.resetSingleton();
    System.setProperties(currentProperties);
    Properties.getInstance().resetToDefaults();
    ExceptionCoverageFactory.getGoals().clear();
    TestsArchive.instance.reset();//w w  w. ja  v  a2 s .c  o  m
}

From source file:com.pactera.edg.am.metamanager.extractor.util.AdapterContextLoader.java

/**
 * //  w ww.  jav a 2s.  co m
 * SpringClassPathXMLApplicationContext,????${var}
 * prop??? ??.properties??,??${var}
 * 
 * @param configLocations
 *            application context?
 * @param props
 *            ??application context????key/value
 * @return ApplicationContext Application
 *         Context,?,??,bean,null
 * @exception
 */
public static ApplicationContext createApplicationContext(String[] configLocations, Properties props) {
    // :spring?system properties??.
    Properties bakProps = null;
    String logMsg = null;
    try {
        if (props != null && props.size() > 0) {
            // system properties
            bakProps = System.getProperties();

            for (Object key : props.keySet()) {
                System.setProperty((String) key, props.getProperty((String) key));
            }

            if (log.isDebugEnabled()) {
                StringBuffer sb = new StringBuffer();
                sb.append("??springxml?${var}prop:\n");
                for (Object key : props.keySet()) {
                    sb.append(key + "=" + System.getProperty((String) key));
                    sb.append("\n");
                }
                log.debug(sb.toString());
            }
        }
        return new ClassPathXmlApplicationContext(configLocations);
    } catch (BeanDefinitionStoreException bse) {
        // 
        logMsg = new StringBuilder("?spring,?")
                .append(Arrays.toString(configLocations)).append(bse.getMessage()).toString();
        log.error(logMsg, bse);
        AdapterExtractorContext.addExtractorLog(ExtractorLogLevel.ERROR, logMsg);
        throw bse;
    } catch (BeanCreationException ce) {
        // BEAN,?RMI??
        logMsg = new StringBuilder("?spring,?BEAN,")
                .append(Arrays.toString(configLocations)).append(ce.getMessage()).toString();
        log.error(logMsg, ce);
        if (logMsg.indexOf("ORA-01017") > -1 || logMsg.indexOf("Invalid password") > -1) {
            // ORACLE????
            AdapterExtractorContext.addExtractorLog(ExtractorLogLevel.ERROR,
                    "??/?,?,???????!");
        } else {
            AdapterExtractorContext.addExtractorLog(ExtractorLogLevel.ERROR, logMsg);
        }
        throw ce;
    } finally {
        // system properties,???,??
        if (bakProps != null) {
            System.setProperties(bakProps);
        }
    }
}

From source file:org.apache.oodt.cas.filemgr.cli.TestFileManagerCli.java

@Override
public void tearDown() throws Exception {
    OptionPropertyRegister.clearRegister();
    System.setProperties(initialProperties);
}

From source file:com.amalto.core.server.Initialization.java

@Override
public void onApplicationEvent(ContextRefreshedEvent event) {
    String version = Version.getSimpleVersionAsString(Initialization.class);
    LOGGER.info("======================================================="); //$NON-NLS-1$
    LOGGER.info("Talend MDM " + version); //$NON-NLS-1$
    LOGGER.info("======================================================="); //$NON-NLS-1$

    //TMDM-2933: ThreadIsolatedSystemProperties allows threads to get different system properties when needed.
    previousSystemProperties = System.getProperties();
    System.setProperties(ThreadIsolatedSystemProperties.getInstance());
    LOGGER.info("Enabled system properties isolation for threads."); //$NON-NLS-1$

    // Initializes server now
    if (serverLifecycle == null) {
        throw new IllegalStateException(
                "Server lifecycle is not set (is server running on a supported platform?)"); //$NON-NLS-1$
    }/*from   w w  w .ja v  a2s . c o m*/
    final Server server = ServerContext.INSTANCE.get(serverLifecycle);
    server.init();
    // Initialize system storage
    LOGGER.info("Starting system storage..."); //$NON-NLS-1$
    final StorageAdmin storageAdmin = server.getStorageAdmin();
    String systemDataSourceName = storageAdmin.getDatasource(StorageAdmin.SYSTEM_STORAGE);
    storageAdmin.create(StorageAdmin.SYSTEM_STORAGE, StorageAdmin.SYSTEM_STORAGE, StorageType.SYSTEM,
            systemDataSourceName);
    Storage systemStorage = storageAdmin.get(StorageAdmin.SYSTEM_STORAGE, StorageType.SYSTEM);
    if (systemStorage == null) {
        LOGGER.error("System storage could not start."); //$NON-NLS-1$
        throw new IllegalStateException("Could not start server (unable to initialize system storage)."); //$NON-NLS-1$
    } else {
        LOGGER.info("System storage started."); //$NON-NLS-1$
    }
    // Migration
    LOGGER.info("Initialization and migration of system database..."); //$NON-NLS-1$
    AssembleConcreteBuilder concreteBuilder = new AssembleConcreteBuilder();
    AssembleDirector director = new AssembleDirector(concreteBuilder);
    director.constructAll();
    final AssembleProc assembleProc = concreteBuilder.getAssembleProc();
    SecurityConfig.invokeSynchronousPrivateInternal(new Runnable() {

        @Override
        public void run() {
            assembleProc.run();
        }
    });

    LOGGER.info("Initialization and migration done."); //$NON-NLS-1$
    // Find configured containers
    MetadataRepository repository = systemStorage.getMetadataRepository();
    String className = StringUtils.substringAfterLast(DataClusterPOJO.class.getName(), "."); //$NON-NLS-1$
    ComplexTypeMetadata containerType = repository.getComplexType(ClassRepository.format(className));
    UserQueryBuilder qb = from(containerType);
    final Set<String> containerNames = new HashSet<String>();
    systemStorage.begin();
    try {
        StorageResults containers = systemStorage.fetch(qb.getSelect());
        for (DataRecord container : containers) {
            String name = String.valueOf(container.get("name")); //$NON-NLS-1$
            if (!DispatchWrapper.isMDMInternal(name)) {
                containerNames.add(name);
            }
        }
        systemStorage.commit();
    } catch (Exception e) {
        systemStorage.rollback();
        throw new RuntimeException("Could not list configured containers", e); //$NON-NLS-1$
    }
    // Log configured containers
    StringBuilder containerNamesLog = new StringBuilder();
    containerNamesLog.append('[').append(' ');
    for (String containerName : containerNames) {
        containerNamesLog.append(containerName).append(' ');
    }
    containerNamesLog.append(']');
    LOGGER.info("Container to initialize (" + containerNames.size() + " found) : " + containerNamesLog); //$NON-NLS-1$ //$NON-NLS-2$

    // Initialize configured containers
    SecurityConfig.invokeSynchronousPrivateInternal(new Runnable() {

        @Override
        public void run() {
            initContainers(server, storageAdmin, containerNames);
        }
    });

    LOGGER.info("Talend MDM " + version + " started."); //$NON-NLS-1$ //$NON-NLS-2$
    if (this.applicationEventPublisher != null) {
        this.applicationEventPublisher.publishEvent(new MDMInitializationCompletedEvent(this));
    }

}

From source file:io.stallion.dataAccess.db.DB.java

/**
 * Load the database based on the configuration defined in the stallion.toml settings.
 * @return//from   w  w  w.  j ava2 s  .com
 */
public static DB load() {
    if (emptyInstance(Settings.instance().getDatabase()) || empty(Settings.instance().getDatabase().getUrl())) {
        return null;
    }
    Properties p = new Properties(System.getProperties());
    p.put("com.mchange.v2.log.MLog", "com.mchange.v2.log.FallbackMLog");
    p.put("com.mchange.v2.log.FallbackMLog.DEFAULT_CUTOFF_LEVEL", "OFF"); // or any other
    System.setProperties(p);

    DbConfig config = Settings.instance().getDatabase();
    DB db;
    if (empty(config.getDbAccessorClass())
            || "io.stallion.dataAccess.db.DB".equals(config.getDbAccessorClass())) {
        db = new DB();
    } else {
        Class cls = StallionClassLoader.loadClass(config.getDbAccessorClass());
        if (cls == null) {
            throw new ConfigException(
                    "The dbAccessorClass you chose in the database settings could not be found: "
                            + config.getDbAccessorClass());
        }
        try {
            db = (DB) cls.newInstance();
        } catch (InstantiationException e) {
            throw new RuntimeException(e);
        } catch (IllegalAccessException e) {
            throw new RuntimeException(e);
        }
    }

    db.initialize(config);

    _instance = db;
    return _instance;
}

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

@Before
public void setup() throws Exception {
    fixture = newServerFixture();/*  ww  w.  j a v a 2 s.  c om*/

    Properties sysprops = System.getProperties();
    oldIni = sysprops.getProperty(CONFIG_SYSPROP);

    url = fixture.getUrl();
    File configFile = temp.newFile("pnc-config.json");
    ModuleConfigJson moduleConfigJson = new ModuleConfigJson("pnc-config");
    IndyRepoDriverModuleConfig mavenRepoDriverModuleConfig = new IndyRepoDriverModuleConfig(fixture.getUrl());
    mavenRepoDriverModuleConfig.setInternalRepoPatterns(getInternalRepoPatterns());
    SystemConfig systemConfig = new SystemConfig("", "", "JAAS", "4", "4", "4", "", "5", null, "14", "", "10");
    PNCModuleGroup pncGroup = new PNCModuleGroup();
    pncGroup.addConfig(mavenRepoDriverModuleConfig);
    pncGroup.addConfig(systemConfig);
    moduleConfigJson.addConfig(pncGroup);

    ObjectMapper mapper = new ObjectMapper();
    PncConfigProvider<IndyRepoDriverModuleConfig> pncProvider = new PncConfigProvider<>(
            IndyRepoDriverModuleConfig.class);
    pncProvider.registerProvider(mapper);
    mapper.writeValue(configFile, moduleConfigJson);

    sysprops.setProperty(CONFIG_SYSPROP, configFile.getAbsolutePath());
    System.setProperties(sysprops);

    fixture.start();

    if (!fixture.isStarted()) {
        final BootStatus status = fixture.getBootStatus();
        throw new IllegalStateException("server fixture failed to boot.", status.getError());
    }

    Properties props = new Properties();
    props.setProperty("base.url", url);

    System.out.println("Using base URL: " + url);

    Configuration config = new Configuration();
    driver = new RepositoryManagerDriver(config);
}

From source file:sorcer.launcher.SorcerLauncher.java

protected void configure() {
    //TODO RKR check grant
    System.setProperties(properties);
}