org.openbakery.configuration.ConfigurationFromPlist.groovy Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of xcode-plugin Show documentation
Show all versions of xcode-plugin Show documentation
XCode-Plugin is a plugin to allow custom XCode projects to build as generated by CMake
The newest version!
package org.openbakery.configuration
import org.apache.commons.configuration.plist.XMLPropertyListConfiguration
class ConfigurationFromPlist implements Configuration {
XMLPropertyListConfiguration configuration
ConfigurationFromPlist(String plistPath) {
this(new File(plistPath))
}
ConfigurationFromPlist(File plistFile) {
if (!plistFile.exists()) {
throw new FileNotFoundException(plistFile.path)
}
configuration = new XMLPropertyListConfiguration(plistFile)
}
@Override
Object get(String key) {
def result = configuration.getProperty(escapeKey(key))
if (result instanceof BigInteger) {
return result.intValue() // convert to int because the integer in the plist cannot be a bigInteger
}
return result
}
@Override
String getString(String key) {
def result = get(key)
if (result instanceof String) {
return result
}
if (result instanceof Boolean) {
return result.toString()
}
if (result instanceof Number) {
return result.toString()
}
return null
}
@Override
List getStringArray(Object key) {
def result = configuration.getList(key)
//def result = plistHelper.getValueFromPlist(plistFile, key)
if (result instanceof List) {
return result
}
return []
}
@Override
Set getKeys() {
def result = []
configuration.getKeys().each {
def unescapedKey = it.replace("..", ".")
result << unescapedKey
}
return result as Set
}
String escapeKey(String key) {
return key.replace(".", "..")
}
@Override
boolean containsKey(String key) {
return configuration.containsKey(escapeKey(key))
}
}