-
-
Notifications
You must be signed in to change notification settings - Fork 135
/
build.gradle
302 lines (236 loc) · 8.59 KB
/
build.gradle
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
/*
* Usage:
* gradlew - Builds the NativeScript Android App Package using an application project template.
gradlew -PgitCommitVersion - sets the commit version of the build
gradlew -PpreReleaseVersion - sets the pre-release version of the build (as per semver spec "-alpha" value results in 1.0.0-alpha)
*/
defaultTasks 'createPackage'
import groovy.json.JsonSlurper //used to parse package.json
import groovy.json.JsonBuilder
import groovy.json.JsonOutput
def isWinOs = System.properties['os.name'].toLowerCase().contains('windows')
def localMetadataGen = "../android-metadata-generator/dist/tns-android-metadata-generator-0.0.1.tgz"
def distDir = "$projectDir/dist"
def pVersion = "no package version was provided by build.gradle build"
def arVersion = "no commit sha was provided by build.gradle build"
task checkEnvironmentVariables {
if ("$System.env.JAVA_HOME" == "" || "$System.env.JAVA_HOME" == "null") {
throw new GradleException("Set JAVA_HOME to point to the correct Jdk location\n");
}
if ("$System.env.ANDROID_HOME" == "" || "$System.env.ANDROID_HOME" == "null") {
throw new GradleException("Set ANDROID_HOME to point to the correct Android SDK location\n");
}
if ("$System.env.GIT_COMMIT" == "null" && !project.hasProperty("gitCommitVersion")) {
logger.warn("Warning: The GIT_COMMIT is not set. This NativeScript Android Runtime will not be tagged with the git commit it is build from\n");
}
if(project.hasProperty("metadataGen") && !file("../android-metadata-generator/dist/tns-android-metadata-generator-0.0.1.tgz").exists()) {
throw new GradleException("android-metadata-generator build output not found and no metadataGen option specified. Build android-metadata-generator first.\n");
}
}
task cleanDistDir (type: Delete) {
delete distDir
}
task createDistDir << {
def distF = new File(distDir)
distF.mkdirs()
}
task copyProjectTemplate (type: Copy) {
from "$rootDir/build-artifacts/project-template-gradle"
into "$rootDir/dist/framework"
}
task copyPackageJson (type: Copy) {
from "$rootDir/package.json"
into "$rootDir/dist"
}
task getPackageVersion << {
String content = new File("$rootDir/package.json").getText("UTF-8")
def jsonSlurper = new JsonSlurper()
def packageJsonMap = jsonSlurper.parseText(content)
pVersion = packageJsonMap.version
println "Using runtime version from package.json '${pVersion}'"
if (project.hasProperty("packageVersion")) {
pVersion += "-" + packageVersion
println "Using packageVersion property '${pVersion}'"
}
if (project.hasProperty("preReleaseVersion")) {
pVersion += "-" + preReleaseVersion
println "Adding preReleaseVersion property '${pVersion}' to package version"
}
println "The package version is '${pVersion}'"
}
task getCommitVersion << {
if (project.hasProperty("gitCommitVersion")) {
println "Using commit version property " + gitCommitVersion
arVersion = gitCommitVersion
}
else if ("$System.env.GIT_COMMIT" != "null") {
println "Using commit version environment variable " + $System.env.GIT_COMMIT
String content = "$System.env.GIT_COMMIT"
arVersion = content.trim()
}
}
task generateBindingGenerator (type: Exec) {
doFirst {
workingDir "$rootDir/binding-generator"
if(isWinOs) {
commandLine "cmd", "/c", "gradlew", "jar"
}
else {
commandLine "./gradlew", "jar"
}
}
}
task generateRuntime {
doFirst {
tasks.generateOptimizedRuntimeAar.execute();
tasks.generateRuntimeAar.execute();
}
}
task generateOptimizedRuntimeAar(type: Exec) {
doFirst {
workingDir "$rootDir/runtime"
if(isWinOs) {
commandLine "cmd", "/c", "gradlew", "assembleRelease", "-PpackageVersion=${pVersion}", "-PgitCommitVersion=${arVersion}", "-PembedBindingGenerator=true", "-Poptimized"
}
else {
commandLine "./gradlew", "assembleRelease", "-PpackageVersion=${pVersion}", "-PgitCommitVersion=${arVersion}", "-PembedBindingGenerator=true", "-Poptimized"
}
}
}
task generateRuntimeAar(type: Exec) {
doFirst {
workingDir "$rootDir/runtime"
if(isWinOs) {
commandLine "cmd", "/c", "gradlew", "assembleRelease", "-PpackageVersion=${pVersion}", "-PgitCommitVersion=${arVersion}", "-PembedBindingGenerator=true"
}
else {
commandLine "./gradlew", "assembleRelease", "-PpackageVersion=${pVersion}", "-PgitCommitVersion=${arVersion}", "-PembedBindingGenerator=true"
}
}
}
task copyGeneratedRuntime << {
copy {
from "$rootDir/runtime/build/outputs/aar/runtime-regular-release.aar"
into "$rootDir/dist/framework/libs/runtime-libs/"
rename "runtime-regular-release.aar", "nativescript-regular.aar"
}
copy {
from "$rootDir/runtime/build/outputs/aar/runtime-optimized-release.aar"
into "$rootDir/dist/framework/libs/runtime-libs/"
rename "runtime-optimized-release.aar", "nativescript-optimized.aar"
}
}
task generateMetadataGeneratorJar (type: Exec) {
doFirst {
workingDir "$rootDir/android-metadata-generator"
if(isWinOs) {
commandLine "cmd", "/c", "gradlew", "jarmg"
}
else {
commandLine "./gradlew", "jarmg"
}
}
}
task copyGeneratedMetadataGeneratorJar << {
copy {
from "$rootDir/android-metadata-generator/dist"
into "$rootDir/dist/framework/build-tools"
rename "android-metadata-generator.jar", "metadata-generator.jar"
}
}
task generateStaticBindingGeneratorJar (type: Exec) {
doFirst {
workingDir "$rootDir/android-static-binding-generator/project/staticbindinggenerator"
if(isWinOs) {
commandLine "cmd", "/c", "gradlew", "assemble"
}
else {
commandLine "./gradlew", "assemble"
}
}
}
task copyGeneratedStaticBindingGeneratorJar << {
copy {
from "$rootDir/android-static-binding-generator/project/staticbindinggenerator/build/libs"
into "$rootDir/dist/framework/build-tools/android-static-binding-generator"
}
}
task copyStaticBindingGeneratorProject << {
copy {
from "$rootDir/android-static-binding-generator/project"
exclude "staticbindinggenerator", "**/package.json", "*.txt", "**/logs", "**/out", "**/input_parced_typescript"
into "$rootDir/dist/framework/build-tools/android-static-binding-generator"
}
}
task createNpmPackage (type: Exec) {
doFirst {
workingDir "$rootDir/dist"
if(isWinOs) {
commandLine "cmd", "/c", "npm", "pack"
}
else {
commandLine "npm", "pack"
}
}
}
task setPackageVersionInPackageJsonFile << {
def inputFile = new File("$rootDir/dist/package.json")
def json = new JsonSlurper().parseText(inputFile.text)
json.version = pVersion
def jb = new JsonBuilder(json);
inputFile.text = JsonOutput.prettyPrint(jb.toString())
}
task copyReadme (type: Copy) {
from "README.md"
into "$rootDir/dist"
}
//clean and set up dirs
createDistDir.dependsOn(cleanDistDir)
//copy framework structure
copyProjectTemplate.dependsOn(createDistDir)
copyPackageJson.dependsOn(copyProjectTemplate)
copyStaticBindingGeneratorProject.dependsOn(copyProjectTemplate)
//generate static binding generator and copy into project template
generateStaticBindingGeneratorJar.dependsOn(copyStaticBindingGeneratorProject)
copyGeneratedStaticBindingGeneratorJar.dependsOn(generateStaticBindingGeneratorJar)
//get version from package json
getPackageVersion.dependsOn(copyProjectTemplate)
getCommitVersion.dependsOn(getPackageVersion)
//generate runtime and copy into framework structure
generateBindingGenerator.dependsOn(getCommitVersion)
generateRuntime.dependsOn(generateBindingGenerator)
setPackageVersionInPackageJsonFile.dependsOn(generateRuntime)
//generateRuntime.dependsOn(build)
tasks.whenTaskAdded { task ->
if (task.getName() == "build")
{
generateRuntime
}
}
copyGeneratedRuntime.dependsOn(generateRuntime)
//generate metadata generator and copy into framework structure
generateMetadataGeneratorJar.dependsOn(copyGeneratedRuntime)
copyGeneratedMetadataGeneratorJar.dependsOn(generateMetadataGeneratorJar)
copyReadme.dependsOn(copyGeneratedMetadataGeneratorJar)
//pack runtime
createNpmPackage.dependsOn(copyReadme, setPackageVersionInPackageJsonFile)
task createPackage {
description "Builds the NativeScript Android App Package using an application project template."
dependsOn cleanDistDir,
createDistDir,
copyProjectTemplate,
copyPackageJson,
copyStaticBindingGeneratorProject,
generateStaticBindingGeneratorJar,
copyGeneratedStaticBindingGeneratorJar,
getPackageVersion,
getCommitVersion,
generateRuntime,
setPackageVersionInPackageJsonFile,
copyGeneratedRuntime,
generateMetadataGeneratorJar,
copyGeneratedMetadataGeneratorJar,
copyReadme,
createNpmPackage
println "Creating NativeScript Android Package"
}