ApkConfigurationHelperpublic class ApkConfigurationHelper extends Object Helper class to read and write Apk Configuration into a {@link ProjectProperties} file. |
Fields Summary |
---|
static final String | CONFIG_PREFIXPrefix for property names for config definition. This prevents having config named
after other valid properties such as "target". |
Methods Summary |
---|
public static java.util.Map | getConfigs(ProjectProperties properties)Reads the Apk Configurations from a {@link ProjectProperties} file and returns them as a map.
If there are no defined configurations, the returned map will be empty.
HashMap<String, String> configMap = new HashMap<String, String>();
// get the list of configs.
String configList = properties.getProperty(ProjectProperties.PROPERTY_APK_CONFIGS);
if (configList != null) {
// this is a comma separated list
String[] configs = configList.split(","); //$NON-NLS-1$
// read the value of each config and store it in a map
for (String config : configs) {
config = config.trim();
String configValue = properties.getProperty(CONFIG_PREFIX + config);
if (configValue != null) {
configMap.put(config, configValue);
}
}
}
return configMap;
| public static boolean | setConfigs(ProjectProperties properties, java.util.Map configMap)Writes the Apk Configurations from a given map into a {@link ProjectProperties}.
// load the current configs, in order to remove the value properties for each of them
// in case a config was removed.
// get the list of configs.
String configList = properties.getProperty(ProjectProperties.PROPERTY_APK_CONFIGS);
boolean hasRemovedConfig = false;
if (configList != null) {
// this is a comma separated list
String[] configs = configList.split(","); //$NON-NLS-1$
for (String config : configs) {
config = config.trim();
if (configMap.containsKey(config) == false) {
hasRemovedConfig = true;
properties.removeProperty(CONFIG_PREFIX + config);
}
}
}
// now add the properties.
Set<Entry<String, String>> entrySet = configMap.entrySet();
StringBuilder sb = new StringBuilder();
for (Entry<String, String> entry : entrySet) {
if (sb.length() > 0) {
sb.append(",");
}
sb.append(entry.getKey());
properties.setProperty(CONFIG_PREFIX + entry.getKey(), entry.getValue());
}
properties.setProperty(ProjectProperties.PROPERTY_APK_CONFIGS, sb.toString());
return hasRemovedConfig;
|
|