All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.openbakery.configuration.ConfigurationFromPlist.groovy Maven / Gradle / Ivy

Go to download

XCode-Plugin is a plugin to allow custom XCode projects to build as generated by CMake

There is a newer version: 0.0.201
Show 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))
	}
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy