本文整理了Java中java.lang.System.setProperties()
方法的一些代码示例,展示了System.setProperties()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。System.setProperties()
方法的具体详情如下:
包路径:java.lang.System
类名称:System
方法名:setProperties
[英]Sets all system properties. This does not take a copy; the passed-in object is used directly. Passing null causes the VM to reinitialize the properties to how they were when the VM was started.
[中]设置所有系统属性。这不需要拷贝;传入的对象直接使用。传递null将导致VM重新初始化属性,使其与VM启动时的状态一致。
代码示例来源:origin: wildfly/wildfly
public Void run() {
System.setProperties(properties);
return null;
}
}
代码示例来源:origin: apache/geode
private static void removeJavaProperties(final Properties javaProps) {
if (javaProps != null) {
Properties props = System.getProperties();
for (Iterator iter = javaProps.keySet().iterator(); iter.hasNext();) {
props.remove(iter.next());
}
System.setProperties(props);
}
}
代码示例来源:origin: stackoverflow.com
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"); // Off or any other level
System.setProperties(p);
代码示例来源:origin: apache/geode
@Override
public void close() {
// Clear the extra stuff from System properties
Properties properties = System.getProperties();
properties.remove(SECURITY_SYSTEM_PREFIX + SECURITY_PEER_AUTH_INIT);
properties.remove(SECURITY_SYSTEM_PREFIX + SECURITY_PEER_AUTHENTICATOR);
Iterator iter = security.keySet().iterator();
while (iter.hasNext()) {
properties.remove(SECURITY_SYSTEM_PREFIX + iter.next());
}
System.setProperties(properties);
}
代码示例来源:origin: spockframework/spock
@Override
public void intercept(IMethodInvocation invocation) throws Throwable {
Properties original = new Properties();
original.putAll(System.getProperties());
try {
invocation.proceed();
} finally {
System.setProperties(original);
}
}
}
代码示例来源:origin: Netflix/conductor
public static void teardown() {
System.setProperties(null);
}
}
代码示例来源:origin: spotbugs/spotbugs
public static void makeSystemPropertiesWriteOnce() {
Properties properties = System.getProperties();
if (properties instanceof WriteOnceProperties) {
return;
}
System.setProperties(new WriteOnceProperties(properties));
}
代码示例来源:origin: jphp-group/jphp
@Signature
public static void setProperties(Properties properties) {
System.setProperties(properties);
}
代码示例来源:origin: groovy/groovy-core
public void tearDown() {
System.setProperties(savedProperties);
}
代码示例来源:origin: oracle/helidon
@Override
public void beforeTestExecution(ExtensionContext ec) throws Exception {
getStore(ec).put(SYSPROPS_KEY, System.getProperties());
Properties copy = new Properties();
copy.putAll(System.getProperties());
System.setProperties(copy);
}
代码示例来源:origin: springside/springside4
/**
* Properties 本质上是一个HashTable,每次读写都会加锁,所以不支持频繁的System.getProperty(name)来检查系统内容变化 因此扩展了一个ListenableProperties,
* 在其所关心的属性变化时进行通知.
*
* @see ListenableProperties
*/
public static synchronized void registerSystemPropertiesListener(PropertiesListener listener) {
Properties currentProperties = System.getProperties();
// 将System的properties实现替换为ListenableProperties
if (!(currentProperties instanceof ListenableProperties)) {
ListenableProperties newProperties = new ListenableProperties(currentProperties);
System.setProperties(newProperties);
currentProperties = newProperties;
}
((ListenableProperties) currentProperties).register(listener);
}
代码示例来源:origin: apache/ignite
/**
* Constructor.
*
* @param name Name.
* @param val Value.
*/
public SystemProperty(String name, String val) {
this.name = name;
Properties props = System.getProperties();
originalValue = (String)props.put(name, val);
System.setProperties(props);
}
代码示例来源:origin: apache/ignite
/** {@inheritDoc} */
@Override public void close() {
Properties props = System.getProperties();
if (originalValue != null)
props.put(name, originalValue);
else
props.remove(name);
System.setProperties(props);
}
}
代码示例来源:origin: groovy/groovy-core
public void setUp() {
savedProperties = System.getProperties();
System.setProperties(new Properties(savedProperties));
}
代码示例来源:origin: org.apache.commons/commons-lang3
/**
* Tests that a lookup object for system properties can deal with a full
* replacement of the system properties object. This test is related to
* LANG-1055.
*/
@Test
public void testSystemPropertiesLookupReplacedProperties() {
final Properties oldProperties = System.getProperties();
final String osName = "os.name";
final String newOsName = oldProperties.getProperty(osName) + "_changed";
final StrLookup<String> sysLookup = StrLookup.systemPropertiesLookup();
final Properties newProps = new Properties();
newProps.setProperty(osName, newOsName);
System.setProperties(newProps);
try {
assertEquals("Changed properties not detected", newOsName, sysLookup.lookup(osName));
} finally {
System.setProperties(oldProperties);
}
}
代码示例来源:origin: pentaho/pentaho-kettle
@Override protected void after() {
cleanUp();
System.setProperties( originalProperties );
Locale.setDefault( originalLocale );
Locale.setDefault( Locale.Category.FORMAT, originalFormatLocale );
LanguageChoice.getInstance().setDefaultLocale( originalLocale );
TimeZone.setDefault( originalTimezone );
FileUtils.deleteQuietly( tmpKettleHome.toFile() );
}
代码示例来源:origin: gocd/gocd
@After
public void cleanUp() {
System.setProperties(original);
files.cleanUp();
}
代码示例来源:origin: AsyncHttpClient/async-http-client
@Test(enabled = false)
public void testIgnoreProxyPropertiesByDefault() throws IOException, TimeoutException, InterruptedException {
// FIXME not threadsafe!
Properties originalProps = new Properties();
originalProps.putAll(System.getProperties());
System.setProperty(ProxyUtils.PROXY_HOST, "localhost");
System.setProperty(ProxyUtils.PROXY_PORT, String.valueOf(port1));
System.setProperty(ProxyUtils.PROXY_NONPROXYHOSTS, "localhost");
AsyncHttpClientConfigHelper.reloadProperties();
try (AsyncHttpClient client = asyncHttpClient()) {
String target = "http://localhost:1234/";
Future<Response> f = client.prepareGet(target).execute();
try {
f.get(3, TimeUnit.SECONDS);
fail("should not be able to connect");
} catch (ExecutionException e) {
// ok, no proxy used
}
} finally {
System.setProperties(originalProps);
}
}
代码示例来源:origin: AsyncHttpClient/async-http-client
@Test(enabled = false)
public void testWildcardNonProxyHosts() throws IOException, TimeoutException, InterruptedException {
// FIXME not threadsafe!
Properties originalProps = new Properties();
originalProps.putAll(System.getProperties());
System.setProperty(ProxyUtils.PROXY_HOST, "127.0.0.1");
System.setProperty(ProxyUtils.PROXY_PORT, String.valueOf(port1));
System.setProperty(ProxyUtils.PROXY_NONPROXYHOSTS, "127.*");
AsyncHttpClientConfigHelper.reloadProperties();
try (AsyncHttpClient client = asyncHttpClient(config().setUseProxyProperties(true))) {
String nonProxifiedTarget = "http://127.0.0.1:1234/";
Future<Response> f = client.prepareGet(nonProxifiedTarget).execute();
try {
f.get(3, TimeUnit.SECONDS);
fail("should not be able to connect");
} catch (ExecutionException e) {
// ok, no proxy used
}
} finally {
System.setProperties(originalProps);
}
}
代码示例来源:origin: gocd/gocd
@After
public void after() {
System.setProperties(original);
new SystemEnvironment().reset(SystemEnvironment.ENABLE_CONFIG_MERGE_FEATURE);
}
内容来源于网络,如有侵权,请联系作者删除!