org.openbakery.util.VariableResolver.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.util
import org.gradle.api.Project
import org.slf4j.Logger
import org.slf4j.LoggerFactory
class VariableResolver {
private static Logger logger = LoggerFactory.getLogger(VariableResolver.class)
private Project project
VariableResolver(Project project) {
this.project = project
}
/**
* Replaces the variables ${...}
*
* @param text
* @return
*/
String resolveCurlyBrackets(String text) {
String result = text
binding().each() { key, value ->
if (value != null) {
result = result.replaceAll('\\$\\{' + key + '\\}', value)
}
}
return result
}
/**
* Replaces the variables in the given string with the actual value. e.g. ${PRODUCT_NAME} od $(PRODUCT_NAME) get replaced by the real product name
*
* @param text
* @return
*/
String resolve(String text) {
if (text == null) {
return null
}
String result = text
binding().each() { key, value ->
if (value != null) {
result = result.replaceAll('\\$\\(' + key + '\\)', value)
}
}
return resolveCurlyBrackets(result)
}
def binding() {
return [
"PRODUCT_NAME": project.xcodebuild.productName,
"SRC_ROOT" : project.projectDir.absolutePath,
"TARGET_NAME" : project.xcodebuild.target
];
}
}