-
Notifications
You must be signed in to change notification settings - Fork 5
/
build.gradle
291 lines (257 loc) · 10.1 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
ext {
airshipProperties = new Properties()
airshipProperties.load(new FileInputStream("$projectDir/airship.properties"))
toolsDir = new File("$projectDir/.tools")
if ( !toolsDir.exists() ) {
toolsDir.mkdirs()
}
rootDir = new File("$projectDir")
nugetExe = new File("$toolsDir/nuget.exe")
if (!nugetExe.exists()) {
new URL('https://dist.nuget.org/win-x86-commandline/latest/nuget.exe').withInputStream{
i -> nugetExe.withOutputStream{ it << i }
}
}
msbuild = "/Library/Frameworks/Mono.framework/Commands/msbuild"
}
// Build nuget pkgs -- can pass in parameters (nuspec files) to specify which
// nupkg files to build
task pkg {
dependsOn 'build'
doLast() {
def nuspecs = []
if (project.hasProperty('nuspec')) {
nuspecs = nuspec.split(',')
} else {
nuspecs = [
"Airship.Android.Core.nuspec",
"Airship.Android.ADM.nuspec",
"Airship.Android.FCM.nuspec",
// "Airship.Android.FeatureFlag.nuspec",
"Airship.Android.MessageCenter.nuspec",
"Airship.Android.Layout.nuspec",
"Airship.Android.Automation.nuspec",
"Airship.Android.LiveUpdate.nuspec",
"Airship.Android.PreferenceCenter.nuspec",
"Airship.iOS.Basement.nuspec",
"Airship.iOS.Core.nuspec",
"Airship.iOS.Automation.nuspec",
"Airship.iOS.MessageCenter.nuspec",
"Airship.iOS.PreferenceCenter.nuspec",
"Airship.iOS.NotificationContentExtension.nuspec",
"Airship.iOS.NotificationServiceExtension.nuspec",
"Airship.iOS.nuspec",
"Airship.NETStandard.nuspec",
]
}
for (nuspec in nuspecs) {
exec {
commandLine "mono", "${nugetExe}", "pack", "$nuspec", "-OutputDirectory", "$buildDir"
}
}
}
}
// Create local nuget feed
task createLocalFeed {
doLast() {
// add doesn't have a "-force" option, so first remove all the nuget packages from the local feed
File localNugetFeed = file("${rootDir}/local-nuget-feed")
localNugetFeed.deleteDir()
// get all the nuget packages from the build directory
def nupkgs = buildDir.listFiles(new FilenameFilter() {
public boolean accept(File dir, String name) {
return name.toLowerCase().endsWith(".nupkg");
}
})
// add the packages to the local nuget feed
nupkgs.each { nupkg ->
// add the package to the local nuget feed
exec {
commandLine "mono", "${nugetExe}", "add", "$nupkg", "-source", "$localNugetFeed"
}
}
// clear the local nuget cache (so new packages with unchanged versions are used)
exec {
commandLine "mono", "${nugetExe}", "locals", "all", "-clear"
}
}
}
createLocalFeed.dependsOn('pkg')
// Sync the nuspec and shared assembly versions with the version declared in the airship.properties file.
task syncRootVersion {
doLast() {
def androidNugetVersion = airshipProperties.androidVersion
if (airshipProperties['androidPackageVersion']) {
androidNugetVersion = "${airshipProperties.androidVersion}.${airshipProperties.androidPackageVersion}"
}
def iosNugetVersion = airshipProperties.iosNugetVersion
if (airshipProperties['iosPackageVersion']) {
iosNugetVersion = "${airshipProperties.iosNugetVersion}.${airshipProperties.iosPackageVersion}"
}
// Handle Android nuspec versions
ant.replaceregexp(
match: "<version>.*</version>",
replace: "<version>$androidNugetVersion</version>"
) {
fileset(dir: "$projectDir", includes: "Airship.Android*.nuspec")
}
// Handle iOS nuspec versions
ant.replaceregexp(
match: "<version>.*</version>",
replace: "<version>$iosNugetVersion</version>"
) {
fileset(dir: "$projectDir", includes: "Airship.iOS*.nuspec")
}
// Handle .NET Standard versions
ant.replaceregexp(
file: "$projectDir/Airship.NETStandard.nuspec",
match: "<version>.*</version>",
replace: "<version>$airshipProperties.crossPlatformVersion</version>",
flags: "g"
)
// handle airship.android.core dependencies
ant.replaceregexp(
match: "<dependency id=\"airship.android(.*)\" version=\".*\"/>",
replace: "<dependency id=\"airship.android\\1\" version=\"$androidNugetVersion\"/>",
flags: "g"
) {
fileset(dir: "$projectDir", includes: "Airship*.nuspec")
}
// handle airship.ios dependencies
ant.replaceregexp(
match: "<dependency id=\"airship.ios(.*)\" version=\".*\"/>",
replace: "<dependency id=\"airship.ios\\1\" version=\"$iosNugetVersion\"/>",
flags: "g"
) {
fileset(dir: "$projectDir", includes: "Airship*.nuspec")
}
// Shared assembly info
ant.replaceregexp(
file: "$projectDir/src/SharedAssemblyInfo.CrossPlatform.cs",
match: "AssemblyVersion (.*)]",
replace: "AssemblyVersion (\"$airshipProperties.crossPlatformVersion\")]"
)
ant.replaceregexp(
file: "$projectDir/src/SharedAssemblyInfo.Android.cs",
match: "AssemblyVersion (.*)]",
replace: "AssemblyVersion (\"$airshipProperties.androidVersion\")]"
)
ant.replaceregexp(
file: "$projectDir/src/SharedAssemblyInfo.iOS.cs",
match: "AssemblyVersion (.*)]",
replace: "AssemblyVersion (\"$airshipProperties.iosNugetVersion\")]"
)
ant.replaceregexp(
file: "$projectDir/src/SharedAssemblyInfo.Common.cs",
match: "UACrossPlatformVersion (.*)]",
replace: "UACrossPlatformVersion (\"$airshipProperties.crossPlatformVersion\")]"
)
}
}
// Sync subproject versions with the version declared in the airship.properties file.
task syncVersion
syncVersion.mustRunAfter('clean')
syncVersion.dependsOn('syncRootVersion')
syncVersion.dependsOn(':src:AirshipBindings.Android.ADM:syncVersion',
':src:AirshipBindings.Android.ADM:syncVersion',
':src:AirshipBindings.Android.Core:syncVersion',
':src:AirshipBindings.Android.FCM:syncVersion',
':src:AirshipBindings.Android.FeatureFlag:syncVersion',
':src:AirshipBindings.Android.MessageCenter:syncVersion',
':src:AirshipBindings.Android.Automation:syncVersion',
':src:AirshipBindings.Android.Layout:syncVersion',
':src:AirshipBindings.Android.LiveUpdate:syncVersion',
':src:AirshipBindings.Android.PreferenceCenter:syncVersion',
':src:AirshipBindings.iOS.common:syncVersion',
)
class PublishTask extends DefaultTask {
@InputDirectory
@Optional
def File nupkgDir = getProject().buildDir
@Input
@Optional
def File nugetExec = getProject().nugetExe
@Input
def String nugetRepoURL
@Input
def String nugetApiKey
@TaskAction
def publish() {
// get all the nuget packages from the build directory
def nupkgs = nupkgDir.listFiles(new FilenameFilter() {
public boolean accept(File dir, String name) {
return name.toLowerCase().endsWith(".nupkg");
}
})
// publish the packages to nuget
nupkgs.each { nupkg ->
// publish the package
getProject().exec {
ignoreExitValue true
commandLine "mono", "${nugetExec}", "push", "$nupkg", "-source", "${nugetRepoURL}", "-apikey", "${nugetApiKey}"
}
}
}
}
task publishToStaging(type:PublishTask) {
nugetRepoURL = "https://int.nugettest.org/api/v2/package"
nugetApiKey = "$System.env.NUGET_STAGING_API_KEY"
}
publishToStaging.dependsOn('pkg')
task publishToProduction(type:PublishTask) {
nugetRepoURL = "https://www.nuget.org/api/v2/package"
nugetApiKey = "$System.env.NUGET_PRODUCTION_API_KEY"
}
publishToProduction.dependsOn('pkg')
//--- GLOBAL TASKS ---//
// Clean all
task clean(type: Delete) {
doLast() {
project.delete(files("$buildDir"))
}
}
clean.dependsOn(':src:AirshipBindings.Android.ADM:clean',
':src:AirshipBindings.Android.ADM:clean',
':src:AirshipBindings.Android.Core:clean',
':src:AirshipBindings.Android.FCM:clean',
':src:AirshipBindings.Android.FeatureFlag:clean',
':src:AirshipBindings.Android.MessageCenter:clean',
':src:AirshipBindings.Android.Automation:clean',
':src:AirshipBindings.Android.Layout:clean',
':src:AirshipBindings.Android.LiveUpdate:clean',
':src:AirshipBindings.Android.PreferenceCenter:clean',
':src:AirshipBindings.iOS.common:clean',
)
task preBuild() {
doFirst() {
mkdir project.buildDir
}
}
// Build the plugin
task build()
build.mustRunAfter('clean')
build.dependsOn('preBuild')
build.dependsOn('syncVersion')
build.dependsOn(':docs:build',
':src:AirshipBindings.Android.ADM:build',
':src:AirshipBindings.Android.Core:build',
':src:AirshipBindings.Android.FCM:build',
':src:AirshipBindings.Android.FeatureFlag:build',
':src:AirshipBindings.Android.MessageCenter:build',
':src:AirshipBindings.Android.Automation:build',
':src:AirshipBindings.Android.Layout:build',
':src:AirshipBindings.Android.LiveUpdate:build',
':src:AirshipBindings.Android.PreferenceCenter:build',
':src:AirshipBindings.NETStandard:build',
':src:AirshipBindings.iOS.Basement:build',
':src:AirshipBindings.iOS.Core:build',
':src:AirshipBindings.iOS.Automation:build',
':src:AirshipBindings.iOS.MessageCenter:build',
':src:AirshipBindings.iOS.PreferenceCenter:build',
':src:AirshipBindings.iOS.NotificationContentExtension:build',
':src:AirshipBindings.iOS.NotificationServiceExtension:build' )
task getVersion() {
doLast {
println airshipProperties.crossPlatformVersion
}
}