1
1
import groovy.json.JsonSlurper
2
2
import org.gradle.internal.logging.text.StyledTextOutputFactory
3
3
import static org.gradle.internal.logging.text.StyledTextOutput.Style
4
+ import java.nio.file.Paths
4
5
5
6
apply plugin : ' com.android.library'
6
7
apply plugin : ' kotlin-android'
@@ -25,31 +26,52 @@ buildscript {
25
26
// Set up styled logger
26
27
project. ext. outLogger = services. get(StyledTextOutputFactory ). create(" colouredOutputLogger" )
27
28
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 = { ->
30
32
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" )
35
34
def nsConfig
36
35
37
36
if (nsConfigFile. exists()) {
38
37
nsConfig = new JsonSlurper (). parseText(nsConfigFile. getText(" UTF-8" ))
39
38
}
40
39
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 ) {
42
45
relativePathToApp = nsConfig. appPath
43
46
}
44
47
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 ) {
46
69
relativePathToAppResources = nsConfig. appResourcesPath
70
+ absolutePathToAppResources = Paths . get(USER_PROJECT_ROOT ). resolve(relativePathToAppResources). toAbsolutePath()
47
71
} else {
48
- relativePathToAppResources = " $r elativePathToApp /App_Resources"
72
+ absolutePathToAppResources = " ${ getAppPath() } /App_Resources"
49
73
}
50
74
51
- absolutePathToAppResources = java.nio.file.Paths . get(projectRoot). resolve(relativePathToAppResources). toAbsolutePath()
52
-
53
75
project. ext. appResourcesPath = absolutePathToAppResources
54
76
55
77
return absolutePathToAppResources
0 commit comments