aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/main/groovy/org/qtproject/qt/gradleplugin/QtGradlePlugin.groovy52
1 files changed, 50 insertions, 2 deletions
diff --git a/src/main/groovy/org/qtproject/qt/gradleplugin/QtGradlePlugin.groovy b/src/main/groovy/org/qtproject/qt/gradleplugin/QtGradlePlugin.groovy
index 0bdf0a5..d048aad 100644
--- a/src/main/groovy/org/qtproject/qt/gradleplugin/QtGradlePlugin.groovy
+++ b/src/main/groovy/org/qtproject/qt/gradleplugin/QtGradlePlugin.groovy
@@ -74,10 +74,58 @@ class QtGradlePlugin implements Plugin<Project> {
}
}
+ /*
+ Order of preference for finding properties:
+ 1. project properties (enforced by gradle)
+ a. command line arguments
+ b. gradle.properties
+ c. environment variables
+ 2. local.properties
+ 3. build.gradle
+ */
static def findProperty(String property, Project project) {
- def propertyValue = project.findProperty(property)
+ return findProjectProperty(property, project)
+ ?: findLocalProperty(property, project)
+ }
+
+ static def findProjectProperty(String property, Project project) {
+ // camelCaseProperty (for command line arguments and env vars)
+ // Example: qtExtraCMakeArguments
+ def camelCaseSplits = property.split("\\.")
+ if (camelCaseSplits.length > 0) {
+ def camelCaseProp = camelCaseSplits[0]
+ for (def i = 1; i < camelCaseSplits.length; i++) {
+ def str = camelCaseSplits[i]
+ camelCaseProp += str.substring(0, 1).toUpperCase() + str.substring(1)
+ }
+ def camelCaseVal = project.findProperty(camelCaseProp)
+ if (camelCaseVal)
+ return camelCaseVal.toString()
+ }
+
+ // Normal property with dot (for gradle.properties file)
+ // Example: qt.extraCMakeArguments
+ def normalVal = project.findProperty(property)
+ if (normalVal)
+ return normalVal.toString()
+
+ return null
+ }
+
+ static def findLocalProperty(String property, Project project) {
+ Properties localProperties = new Properties()
+ def localValue = null
+
+ try {
+ localProperties.load(project.rootProject.file("local.properties").newDataInputStream())
+ localValue = localProperties.getProperty(property)
+ } catch (FileNotFoundException e) {
+ System.err.println(e.getMessage())
+ } catch (IOException e) {
+ System.err.println(e.getMessage())
+ }
- return propertyValue ? propertyValue.toString() : ""
+ return localValue ? localValue.toString() : null
}
static File getBuildDirectory(project, qtProjectName) {