Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add gradle.properties support #1464

Merged
merged 1 commit into from
Aug 29, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -286,6 +286,14 @@ task copyFilesToProjectTemeplate {
from "$TEST_APP_PATH/build.gradle"
into "$DIST_FRAMEWORK_PATH"
}
copy {
from "$TEST_APP_PATH/paths.gradle"
into "$DIST_FRAMEWORK_PATH"
}
copy {
from "$TEST_APP_PATH/user_properties_reader.gradle"
into "$DIST_FRAMEWORK_PATH"
}
copy {
from "$TEST_APP_PATH/gradle"
into "$DIST_FRAMEWORK_PATH/gradle"
Expand Down
9 changes: 5 additions & 4 deletions test-app/app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,9 @@ import java.security.MessageDigest

apply plugin: "com.android.application"

def useKotlin = project.hasProperty("useKotlin") && project.ext.useKotlin=="true"
if (useKotlin) {
def enableKotlin = (project.hasProperty("useKotlin") && project.useKotlin == "true")

if (enableKotlin) {
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-android-extensions'
}
Expand Down Expand Up @@ -228,7 +229,7 @@ def setAppIdentifier = { ->

android {

if (useKotlin) {
if (enableKotlin) {
kotlinOptions {
jvmTarget = '1.8'
}
Expand Down Expand Up @@ -380,7 +381,7 @@ dependencies {
}

def kotlinVersion = computeKotlinVersion()
if (useKotlin) {
if (enableKotlin) {
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk8:$kotlinVersion"
}

Expand Down
25 changes: 21 additions & 4 deletions test-app/build.gradle
Original file line number Diff line number Diff line change
@@ -1,19 +1,26 @@
// Top-level build file where you can add configuration options common to all sub-projects/modules.

buildscript {
def useKotlin = project.hasProperty("useKotlin") && project.ext.useKotlin == "true"

def initialize = { ->
def userDir = "${rootProject.projectDir}/../.."
apply from: "$rootDir/user_properties_reader.gradle"
apply from: "$rootDir/paths.gradle"
rootProject.ext.userDefinedGradleProperties = getUserProperties("${getAppResourcesPath(userDir)}/Android")
}
initialize()

def computeKotlinVersion = { -> project.hasProperty("kotlinVersion") ? kotlinVersion : "1.3.41"
}
def kotlinVersion = computeKotlinVersion()

repositories {
google()
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.5.0'
if (useKotlin) {
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlinVersion"
}
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlinVersion"
}
}

Expand All @@ -22,6 +29,16 @@ allprojects {
google()
jcenter()
}
beforeEvaluate { project ->
if (rootProject.hasProperty("userDefinedGradleProperties")) {
rootProject.ext.userDefinedGradleProperties.each { entry ->
def propertyName = entry.getKey()
def propertyValue = entry.getValue()
project.ext.set(propertyName, propertyValue)
}
}

}
}

task clean(type: Delete) {
Expand Down
37 changes: 37 additions & 0 deletions test-app/paths.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import groovy.json.JsonSlurper

ext.getAppPath = { userDir ->
def relativePathToApp = "app"
def nsConfigFile = file("$userDir/nsconfig.json")
def nsConfig

if (nsConfigFile.exists()) {
nsConfig = new JsonSlurper().parseText(nsConfigFile.getText("UTF-8"))
}

if (nsConfig != null && nsConfig.appPath != null) {
relativePathToApp = nsConfig.appPath
}

return java.nio.file.Paths.get(userDir).resolve(relativePathToApp).toAbsolutePath()
}

ext.getAppResourcesPath = { userDir ->
def relativePathToAppResources
def absolutePathToAppResources
def nsConfigFile = file("$userDir/nsconfig.json")
def nsConfig

if (nsConfigFile.exists()) {
nsConfig = new JsonSlurper().parseText(nsConfigFile.getText("UTF-8"))
}

if (nsConfig != null && nsConfig.appResourcesPath != null) {
relativePathToAppResources = nsConfig.appResourcesPath
absolutePathToAppResources = java.nio.file.Paths.get(userDir).resolve(relativePathToAppResources).toAbsolutePath()
} else {
absolutePathToAppResources = "${getAppPath(userDir)}/App_Resources"
}

return absolutePathToAppResources
}
22 changes: 22 additions & 0 deletions test-app/user_properties_reader.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
def GRADLE_PROPERTIES_FILENAME = "gradle.properties"

def getFile = { dir, filename ->
File file = new File("$dir$File.separator$filename")
file?.exists() ? file : null
}

def getPropertyFile = { dir ->
return getFile(dir, GRADLE_PROPERTIES_FILENAME)
}

ext.getUserProperties = { dir ->
def file = getPropertyFile(dir)
if (!file) {
return null
}

Properties properties = new Properties()
properties.load(file.newInputStream())

return properties
}