11import groovy.json.JsonSlurper
22import org.gradle.internal.logging.text.StyledTextOutputFactory
33import static org.gradle.internal.logging.text.StyledTextOutput.Style
4+ import java.nio.file.Paths
45
56apply plugin : ' com.android.library'
67apply plugin : ' kotlin-android'
@@ -25,31 +26,52 @@ buildscript {
2526 // Set up styled logger
2627 project. ext. outLogger = services. get(StyledTextOutputFactory ). create(" colouredOutputLogger" )
2728
28- // todo: pass appResourcesPath from CLI as a gradle arg
29- project. ext. getAppResourcesPath = { ->
29+ project. ext. USER_PROJECT_ROOT = " $rootDir /../../.."
30+
31+ project. ext. getAppPath = { ->
3032 def relativePathToApp = " app"
31- def relativePathToAppResources
32- def absolutePathToAppResources
33- def projectRoot = " $rootDir /../../.."
34- def nsConfigFile = file(" $projectRoot /nsconfig.json" )
33+ def nsConfigFile = file(" $USER_PROJECT_ROOT /nsconfig.json" )
3534 def nsConfig
3635
3736 if (nsConfigFile. exists()) {
3837 nsConfig = new JsonSlurper (). parseText(nsConfigFile. getText(" UTF-8" ))
3938 }
4039
41- if (nsConfig != null && nsConfig. appPath != null ){
40+ if (project. hasProperty(" appPath" )) {
41+ // when appPath is passed through -PappPath=/path/to/app
42+ // the path could be relative or absolute - either case will work
43+ relativePathToApp = appPath
44+ } else if (nsConfig != null && nsConfig. appPath != null ) {
4245 relativePathToApp = nsConfig. appPath
4346 }
4447
45- if (nsConfig != null && nsConfig. appResourcesPath != null ) {
48+ project. ext. appPath = Paths . get(USER_PROJECT_ROOT ). resolve(relativePathToApp). toAbsolutePath()
49+
50+ return project. ext. appPath
51+ }
52+
53+ project. ext. getAppResourcesPath = { ->
54+ def relativePathToAppResources
55+ def absolutePathToAppResources
56+ def nsConfigFile = file(" $USER_PROJECT_ROOT /nsconfig.json" )
57+ def nsConfig
58+
59+ if (nsConfigFile. exists()) {
60+ nsConfig = new JsonSlurper (). parseText(nsConfigFile. getText(" UTF-8" ))
61+ }
62+
63+ if (project. hasProperty(" appResourcesPath" )) {
64+ // when appResourcesPath is passed through -PappResourcesPath=/path/to/App_Resources
65+ // the path could be relative or absolute - either case will work
66+ relativePathToAppResources = appResourcesPath
67+ absolutePathToAppResources = Paths . get(USER_PROJECT_ROOT ). resolve(relativePathToAppResources). toAbsolutePath()
68+ } else if (nsConfig != null && nsConfig. appResourcesPath != null ) {
4669 relativePathToAppResources = nsConfig. appResourcesPath
70+ absolutePathToAppResources = Paths . get(USER_PROJECT_ROOT ). resolve(relativePathToAppResources). toAbsolutePath()
4771 } else {
48- relativePathToAppResources = " $r elativePathToApp /App_Resources"
72+ absolutePathToAppResources = " ${ getAppPath() } /App_Resources"
4973 }
5074
51- absolutePathToAppResources = java.nio.file.Paths . get(projectRoot). resolve(relativePathToAppResources). toAbsolutePath()
52-
5375 project. ext. appResourcesPath = absolutePathToAppResources
5476
5577 return absolutePathToAppResources
0 commit comments