com.liferay.portal.kernel.util.SystemProperties Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of com.liferay.portal.kernel Show documentation
Show all versions of com.liferay.portal.kernel Show documentation
Contains interfaces for the portal services. Interfaces are only loaded by the global class loader and are shared by all plugins.
/**
* Copyright (c) 2000-present Liferay, Inc. All rights reserved.
*
* This library is free software; you can redistribute it and/or modify it under
* the terms of the GNU Lesser General Public License as published by the Free
* Software Foundation; either version 2.1 of the License, or (at your option)
* any later version.
*
* This library is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
* FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
* details.
*/
package com.liferay.portal.kernel.util;
import java.io.IOException;
import java.io.InputStream;
import java.net.URL;
import java.util.ArrayList;
import java.util.Enumeration;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Properties;
import java.util.concurrent.ConcurrentHashMap;
/**
* @author Brian Wing Shun Chan
* @author Mirco Tamburini
* @author Brett Randall
* @author Shuyang Zhou
*/
public class SystemProperties {
public static final String SYSTEM_PROPERTIES_QUIET =
"system.properties.quiet";
public static final String SYSTEM_PROPERTIES_SET = "system.properties.set";
public static final String SYSTEM_PROPERTIES_SET_OVERRIDE =
"system.properties.set.override";
public static final String TMP_DIR = "java.io.tmpdir";
public static void clear(String key) {
System.clearProperty(key);
_properties.remove(key);
}
public static String get(String key) {
String value = _properties.get(key);
if (value == null) {
value = System.getProperty(key);
}
return value;
}
public static Properties getProperties() {
return PropertiesUtil.fromMap(_properties);
}
public static void load(ClassLoader classLoader) {
Properties properties = new Properties();
List urls = null;
if (!GetterUtil.getBoolean(
System.getProperty(SYSTEM_PROPERTIES_QUIET))) {
urls = new ArrayList<>();
}
// system.properties
try {
Enumeration enumeration = classLoader.getResources(
"system.properties");
while (enumeration.hasMoreElements()) {
URL url = enumeration.nextElement();
try (InputStream inputStream = url.openStream()) {
properties.load(inputStream);
}
if (urls != null) {
urls.add(url);
}
}
}
catch (IOException ioe) {
throw new ExceptionInInitializerError(ioe);
}
// system-ext.properties
try {
Enumeration enumeration = classLoader.getResources(
"system-ext.properties");
while (enumeration.hasMoreElements()) {
URL url = enumeration.nextElement();
try (InputStream inputStream = url.openStream()) {
properties.load(inputStream);
}
if (urls != null) {
urls.add(url);
}
}
}
catch (IOException ioe) {
throw new ExceptionInInitializerError(ioe);
}
// Set environment properties
SystemEnv.setProperties(properties);
// Set system properties
if (GetterUtil.getBoolean(
System.getProperty(SYSTEM_PROPERTIES_SET), true)) {
boolean systemPropertiesSetOverride = GetterUtil.getBoolean(
System.getProperty(SYSTEM_PROPERTIES_SET_OVERRIDE), true);
for (Entry
© 2015 - 2025 Weber Informatics LLC | Privacy Policy