Skip to content

Commit 5042306

Browse files
committed
chore: vendor plugin refactoring
1 parent 149936e commit 5042306

File tree

1 file changed

+33
-73
lines changed

1 file changed

+33
-73
lines changed

vendor/gradle-plugin/build.gradle

Lines changed: 33 additions & 73 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,9 @@ buildscript {
7272
logger.warn "\t + failed to load gradle properties from \"$path\". Error is: ${ex.getMessage()}"
7373
}
7474
}
75-
def getAppPath = { ->
75+
76+
77+
project.ext.getAppPath = { ->
7678
def relativePathToApp = "app"
7779
def nsConfigFile = file("$USER_PROJECT_ROOT/nsconfig.json")
7880
def nsConfig
@@ -93,7 +95,7 @@ buildscript {
9395

9496
return project.ext.appPath
9597
}
96-
def getAppResourcesPath = { ->
98+
project.ext.getAppResourcesPath = { ->
9799
def relativePathToAppResources
98100
def absolutePathToAppResources
99101
def nsConfigFile = file("$USER_PROJECT_ROOT/nsconfig.json")
@@ -112,14 +114,25 @@ buildscript {
112114
relativePathToAppResources = nsConfig.appResourcesPath
113115
absolutePathToAppResources = Paths.get(USER_PROJECT_ROOT).resolve(relativePathToAppResources).toAbsolutePath()
114116
} else {
115-
absolutePathToAppResources = "${getAppPath()}/App_Resources"
117+
absolutePathToAppResources = "${project.ext.getAppPath()}/App_Resources"
116118
}
117119

118120
project.ext.appResourcesPath = absolutePathToAppResources
119121

120122
return absolutePathToAppResources
121123
}
122124

125+
project.ext.applyBeforePluginGradleConfiguration = { ->
126+
def appResourcesPath = project.ext.getAppResourcesPath()
127+
def pathToBeforePluginGradle = "$appResourcesPath/Android/before-plugins.gradle"
128+
def beforePluginGradle = file(pathToBeforePluginGradle)
129+
if (beforePluginGradle.exists()) {
130+
outLogger.withStyle(Style.SuccessHeader).println "\t ~ applying user-defined configuration from ${beforePluginGradle}"
131+
apply from: pathToBeforePluginGradle
132+
}
133+
}
134+
135+
123136
def initialize = { ->
124137
// set up our logger
125138
project.ext.outLogger = services.get(StyledTextOutputFactory).create("colouredOutputLogger")
@@ -131,7 +144,7 @@ buildscript {
131144
project.ext.PLUGIN_NAME = "{{pluginName}}"
132145

133146
def userDir = "$USER_PROJECT_ROOT"
134-
rootProject.ext.userDefinedGradleProperties = getUserProperties("${getAppResourcesPath()}/Android")
147+
rootProject.ext.userDefinedGradleProperties = getUserProperties("${project.ext.getAppResourcesPath()}/Android")
135148

136149
loadPropertyFile("$USER_PROJECT_ROOT/${project.ext.PLATFORMS_ANDROID}/gradle.properties")
137150
loadPropertyFile("$USER_PROJECT_ROOT/${project.ext.PLATFORMS_ANDROID}/additional_gradle.properties")
@@ -158,59 +171,9 @@ buildscript {
158171
def appDependencies = new JsonSlurper().parseText(dependenciesJson.text)
159172
def pluginData = appDependencies.find { it.name == project.ext.PLUGIN_NAME }
160173
project.ext.nativescriptDependencies = appDependencies.findAll{pluginData.dependencies.contains(it.name)}.plus([pluginData])
161-
162-
project.ext.getAppResourcesPath = { ->
163-
def relativePathToAppResources
164-
def absolutePathToAppResources
165-
def nsConfigFile = file("$USER_PROJECT_ROOT/nsconfig.json")
166-
def nsConfig
167-
168-
if (nsConfigFile.exists()) {
169-
nsConfig = new JsonSlurper().parseText(nsConfigFile.getText("UTF-8"))
170-
}
171-
172-
if (project.hasProperty("appResourcesPath")) {
173-
// when appResourcesPath is passed through -PappResourcesPath=/path/to/App_Resources
174-
// the path could be relative or absolute - either case will work
175-
relativePathToAppResources = appResourcesPath
176-
absolutePathToAppResources = Paths.get(USER_PROJECT_ROOT).resolve(relativePathToAppResources).toAbsolutePath()
177-
} else if (nsConfig != null && nsConfig.appResourcesPath != null) {
178-
relativePathToAppResources = nsConfig.appResourcesPath
179-
absolutePathToAppResources = Paths.get(USER_PROJECT_ROOT).resolve(relativePathToAppResources).toAbsolutePath()
180-
} else {
181-
absolutePathToAppResources = "${getAppPath()}/App_Resources"
182-
}
183-
184-
project.ext.appResourcesPath = absolutePathToAppResources
185-
186-
return absolutePathToAppResources
187-
}
188-
189-
190-
project.ext.getAppPath = { ->
191-
def relativePathToApp = "app"
192-
def nsConfigFile = file("$USER_PROJECT_ROOT/nsconfig.json")
193-
def nsConfig
194-
195-
if (nsConfigFile.exists()) {
196-
nsConfig = new JsonSlurper().parseText(nsConfigFile.getText("UTF-8"))
197-
}
198-
199-
if (project.hasProperty("appPath")) {
200-
// when appPath is passed through -PappPath=/path/to/app
201-
// the path could be relative or absolute - either case will work
202-
relativePathToApp = appPath
203-
} else if (nsConfig != null && nsConfig.appPath != null) {
204-
relativePathToApp = nsConfig.appPath
205-
}
206-
207-
project.ext.appPath = Paths.get(USER_PROJECT_ROOT).resolve(relativePathToApp).toAbsolutePath()
208-
209-
return project.ext.appPath
210-
}
211174
}
212175
def applyBuildScriptConfigurations = { ->
213-
def absolutePathToAppResources = getAppResourcesPath()
176+
def absolutePathToAppResources = project.ext.getAppResourcesPath()
214177
def pathToBuildScriptGradle = "$absolutePathToAppResources/Android/buildscript.gradle"
215178
def buildScriptGradle = file(pathToBuildScriptGradle)
216179
if (buildScriptGradle.exists()) {
@@ -225,6 +188,12 @@ buildscript {
225188
outLogger.withStyle(Style.SuccessHeader).println "\t + applying user-defined buildscript from dependency ${pluginBuildScriptGradle}"
226189
apply from: pathToPluginBuildScriptGradle, to: buildscript
227190
}
191+
// def pathToPluginProjectBuildScriptGradle = "${getDepPlatformDir(dep)}/project-buildscript.gradle"
192+
// def pluginProjectBuildScriptGradle = file(pathToPluginProjectBuildScriptGradle)
193+
// if (pluginProjectBuildScriptGradle.exists()) {
194+
// outLogger.withStyle(Style.SuccessHeader).println "\t + applying user-defined project-buildscript from dependency ${pluginProjectBuildScriptGradle}"
195+
// apply from: pathToPluginProjectBuildScriptGradle, to: project
196+
// }
228197
}
229198

230199
def pathToPluginBuildScriptGradle = "$rootDir/buildscript.gradle"
@@ -236,6 +205,7 @@ buildscript {
236205
}
237206

238207
initialize()
208+
project.ext.applyBeforePluginGradleConfiguration()
239209
applyBuildScriptConfigurations()
240210

241211
def computeKotlinVersion = { -> project.hasProperty("kotlinVersion") ? kotlinVersion : "${ns_default_kotlin_version}" }
@@ -283,12 +253,6 @@ allprojects {
283253
}
284254
}
285255

286-
def computeCompileSdkVersion = { -> project.hasProperty("compileSdk") ? compileSdk : 31 }
287-
def computeTargetSdkVersion = { -> project.hasProperty("targetSdk") ? targetSdk : 31 as int }
288-
def computeBuildToolsVersion = { ->
289-
project.hasProperty("buildToolsVersion") ? buildToolsVersion : "31.0.0"
290-
}
291-
292256
android {
293257
def applyPluginGradleConfigurations = { ->
294258
nativescriptDependencies.each { dep ->
@@ -299,7 +263,14 @@ android {
299263
}
300264
}
301265
}
302-
applyBeforePluginGradleConfiguration()
266+
267+
def computeCompileSdkVersion = { -> project.hasProperty("compileSdk") ? project.compileSdk : 31 }
268+
def computeTargetSdkVersion = { -> project.hasProperty("targetSdk") ? project.targetSdk : 31 as int }
269+
def computeBuildToolsVersion = { ->
270+
project.hasProperty("buildToolsVersion") ? project.buildToolsVersion : "31.0.0"
271+
}
272+
273+
project.ext.applyBeforePluginGradleConfiguration()
303274
applyPluginGradleConfigurations()
304275

305276
compileSdkVersion computeCompileSdkVersion()
@@ -321,17 +292,6 @@ android {
321292
}
322293
}
323294

324-
325-
def applyBeforePluginGradleConfiguration() {
326-
def appResourcesPath = getAppResourcesPath()
327-
def pathToBeforePluginGradle = "$appResourcesPath/Android/before-plugins.gradle"
328-
def beforePluginGradle = file(pathToBeforePluginGradle)
329-
if (beforePluginGradle.exists()) {
330-
outLogger.withStyle(Style.SuccessHeader).println "\t ~ applying user-defined configuration from ${beforePluginGradle}"
331-
apply from: pathToBeforePluginGradle
332-
}
333-
}
334-
335295
task addDependenciesFromNativeScriptPlugins {
336296
nativescriptDependencies.each { dep ->
337297
def aarFiles = fileTree(dir: getDepPlatformDir(dep), include: ["**/*.aar"])

0 commit comments

Comments
 (0)