aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorNikunj Arora <nikunj.arora@qt.io>2025-10-16 14:23:09 +0300
committerNikunj Arora <nikunj.arora@qt.io>2025-12-04 14:38:30 +0200
commitff996fb783c03990007c6980d9c9d1010324f3ae (patch)
tree24e72f3028cf6002f4314e6e932854c5df3b0f55
parent4f526c59421a0aa4f138e77724e86819aa4aef33 (diff)
Add support for reading properties from other locationsHEADdev
Add support for the plugin to read Qt properties from locations other than build.gradle and gradle.properties. It now reads them in the following order of preference: * gradle project propertis (command line, gradle.properties, env) * local.properties * build.gradle Task-number: QTTA-453 Task-number: QTTA-452 Task-number: QTTA-446 Change-Id: I1a965c9c3f6863f244058e42f763b747e7d6daef Reviewed-by: Assam Boudjelthia <assam.boudjelthia@qt.io>
-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) {