Skip to content

feat: settings.gradle plugin #1731

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

Merged
merged 1 commit into from
Oct 21, 2022
Merged
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
71 changes: 71 additions & 0 deletions build-artifacts/project-template-gradle/settings.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,74 @@ include ':app'//, ':runtime', ':runtime-binding-generator'
//project(':runtime-binding-generator').projectDir = new File("${System.env.ANDROID_RUNTIME_HOME}/test-app/runtime-binding-generator")

file("google-services.json").renameTo(file("./app/google-services.json"))

import org.gradle.internal.logging.text.StyledTextOutputFactory

import java.nio.file.Paths

import org.gradle.internal.logging.text.StyledTextOutputFactory
import groovy.json.JsonSlurper
import static org.gradle.internal.logging.text.StyledTextOutput.Style

def USER_PROJECT_ROOT = "$rootDir/../../"
def outLogger = services.get(StyledTextOutputFactory).create("colouredOutputLogger")
def ext = {
appResourcesPath = getProperty("appResourcesPath")
appPath = getProperty("appPath")
}

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

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

if (ext.appPath) {
// when appPath is passed through -PappPath=/path/to/app
// the path could be relative or absolute - either case will work
relativePathToApp = ext.appPath
} else if (nsConfig != null && nsConfig.appPath != null) {
relativePathToApp = nsConfig.appPath
}

return Paths.get(USER_PROJECT_ROOT).resolve(relativePathToApp).toAbsolutePath()
}


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

if (nsConfigFile.exists()) {
nsConfig = new JsonSlurper().parseText(nsConfigFile.getText("UTF-8"))
}
if (ext.appResourcesPath) {
// when appResourcesPath is passed through -PappResourcesPath=/path/to/App_Resources
// the path could be relative or absolute - either case will work
relativePathToAppResources = ext.appResourcesPath
absolutePathToAppResources = Paths.get(USER_PROJECT_ROOT).resolve(relativePathToAppResources).toAbsolutePath()
} else if (nsConfig != null && nsConfig.appResourcesPath != null) {
relativePathToAppResources = nsConfig.appResourcesPath
absolutePathToAppResources = Paths.get(USER_PROJECT_ROOT).resolve(relativePathToAppResources).toAbsolutePath()
} else {
absolutePathToAppResources = "${getAppPath()}/App_Resources"
}
return absolutePathToAppResources
}

def applySettingsGradleConfiguration = { ->
def appResourcesPath = getAppResourcesPath()
def pathToSettingsGradle = "$appResourcesPath/Android/settings.gradle"
def settingsGradle = file(pathToSettingsGradle)
if (settingsGradle.exists()) {
outLogger.withStyle(Style.SuccessHeader).println "\t + applying user-defined configuration from ${settingsGradle}"
apply from: pathToSettingsGradle
}
}

applySettingsGradleConfiguration()