-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.gradle
262 lines (216 loc) · 8.47 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
import groovy.xml.*
import org.apache.tools.ant.taskdefs.optional.ReplaceRegExp
plugins {
id 'org.barfuin.gradle.taskinfo' version '2.1.0'
}
ext {
airshipProperties = new Properties()
airshipProperties.load(new FileInputStream("$projectDir/airship.properties"))
androidVersion = airshipProperties.androidVersion
androidRevision = airshipProperties.androidRevision
androidNugetVersion = nugetVersion(androidVersion, androidRevision)
iosVersion = airshipProperties.iosVersion
iosRevision = airshipProperties.iosRevision
iosNugetVersion = nugetVersion(iosVersion, iosRevision)
crossPlatformVersion = airshipProperties.crossPlatformVersion
crossPlatformRevision = airshipProperties.crossPlatformRevision
crossPlatformNugetVersion = nugetVersion(crossPlatformVersion, crossPlatformRevision)
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"
}
tasks.register('pack') {
dependsOn('build')
// Pack all Android bindings generated via Binderator
dependsOn(':binderator:pack')
// Pack all iOS bindings
dependsOn(':src:AirshipBindings.iOS.common:pack')
// Pack .net common libraries
dependsOn(':src:Airship.Net:pack')
dependsOn(':src:Airship.Net.MessageCenter:pack')
}
tasks.register('buildSample') {
dependsOn(':MauiSample:buildSample')
}
// Create local nuget feed
tasks.register('createLocalFeed') {
mustRunAfter('pack')
doLast() {
// add doesn't have a "--force" option and "--skip-duplicates" doesn't work with pushes to local feeds,
// so first remove all the nuget packages from the local feed
File localNugetFeed = file("${rootDir}/local-nuget-feed")
localNugetFeed.deleteDir()
localNugetFeed.mkdirs()
// get all the nuget packages from the build directory
def nupkgs = buildDir.listFiles(new FilenameFilter() {
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 "dotnet", "nuget", "push", "$nupkg", "-s", "$localNugetFeed"
}
}
// clear the local nuget cache (so new packages with unchanged versions are used)
exec {
commandLine "dotnet", "nuget", "locals", "all", "--clear"
}
}
}
// Sync the nuspec and shared assembly versions with the version declared in the airship.properties file.
tasks.register('syncRootVersion') {
dependsOn('syncDirectoryBuildProps')
doFirst() {
// Shared assembly info
ant.replaceregexp(
file: "$projectDir/src/SharedAssemblyInfo.CrossPlatform.cs",
match: "AssemblyVersion (.*)]",
replace: "AssemblyVersion (\"$crossPlatformNugetVersion\")]"
)
ant.replaceregexp(
file: "$projectDir/src/SharedAssemblyInfo.Common.cs",
match: "UACrossPlatformVersion (.*)]",
replace: "UACrossPlatformVersion (\"$crossPlatformNugetVersion\")]"
)
ant.replaceregexp(
file: "$projectDir/src/SharedAssemblyInfo.iOS.cs",
match: "AssemblyVersion (.*)]",
replace: "AssemblyVersion (\"$crossPlatformNugetVersion\")]"
)
}
}
// Sync subproject versions with the version declared in the airship.properties file.
tasks.register('syncVersion') {
mustRunAfter('clean')
dependsOn('syncRootVersion',
':binderator:syncVersion',
':src:AirshipBindings.iOS.common:syncVersion'
)
}
// Sync Directory.Build.props with the version declared in the airship.properties file.
tasks.register('syncDirectoryBuildProps') {
def outputFile = file("Directory.Build.props")
inputs.property("androidVersion", androidVersion)
inputs.property("androidRevision", androidRevision)
inputs.property("iosVersion", iosVersion)
inputs.property("iosRevision", iosRevision)
inputs.property("crossPlatformVersion", crossPlatformVersion)
inputs.property("crossPlatformRevision", crossPlatformRevision)
outputs.file(outputFile)
doLast {
outputFile.withWriter { writer ->
def xml = new MarkupBuilder(new IndentPrinter(writer, " ", true))
xml.doubleQuotes = true
xml.mkp.yieldUnescaped("<!-- THIS FILE IS AUTO-GENERATED. DO NOT MODIFY. -->\n")
xml.mkp.yieldUnescaped("<!-- The `syncRootVersion` gradle task updates this file based on the contents of `airship.properties`. -->\n\n")
xml.Project() {
mkp.yieldUnescaped("\n <!-- Versions -->")
PropertyGroup {
mkp.yieldUnescaped("\n <!-- Airship native SDK versions -->")
AirshipAndroidVersion(androidVersion)
AirshipAndroidNugetVersion(androidNugetVersion)
mkp.yieldUnescaped("\n")
AirshipIosVersion(iosVersion)
AirshipIosNugetVersion(iosNugetVersion)
mkp.yieldUnescaped("\n\n <!-- Airship.Net version -->")
AirshipCrossPlatformVersion(crossPlatformVersion)
AirshipCrossPlatformNugetVersion(crossPlatformNugetVersion)
}
mkp.yieldUnescaped("\n\n <!-- Nuget packaging metadata -->")
PropertyGroup {
Owners('urbanairship')
Company('Airship, Inc.')
AssemblyCompany('Airship, Inc.')
PackageTags('airship, urbanairship')
Copyright('©Airship. All rights reserved.')
PackageProjectUrl('https://github.com/urbanairship/airship-dotnet/')
PackageLicenseExpression('Apache-2.0')
PackageRequireLicenseAcceptance('false')
AllowedOutputExtensionsInPackageBuildOutputFolder('$(AllowedOutputExtensionsInPackageBuildOutputFolder);.pdb')
}
}
}
}
}
tasks.register('packageDocs') {
dependsOn('build', 'docs:package')
}
tasks.register('publishToStaging', PublishTask) {
dependsOn('pack')
nugetRepoURL = "https://int.nugettest.org/api/v2/package"
nugetApiKey = "$System.env.NUGET_STAGING_API_KEY"
}
tasks.register('publishToProduction', PublishTask) {
dependsOn('pack')
nugetRepoURL = "https://www.nuget.org/api/v2/package"
nugetApiKey = "$System.env.NUGET_PRODUCTION_API_KEY"
}
//--- GLOBAL TASKS ---//
// Clean all
tasks.register('clean', Delete) {
delete fileTree(buildDir).matching { include "*" }
}
// Build the plugin
tasks.register('build') {
mustRunAfter('clean')
dependsOn('syncVersion',
':binderator:build',
':src:AirshipBindings.iOS.common:build',
':src:Airship.Net:build',
':src:Airship.Net.MessageCenter:build')
doFirst() {
mkdir project.buildDir
}
}
tasks.register('getVersion') {
doLast {
println crossPlatformNugetVersion
}
}
//--- CUSTOM TASKS ---//
class PublishTask extends DefaultTask {
@InputDirectory
@Optional
File nupkgDir = getProject().buildDir
@InputFile
@Optional
File nugetExec = getProject().nugetExe
@Input
String nugetRepoURL
@Input
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 {
commandLine "dotnet", "nuget", "push", "$nupkg", "--source", "${nugetRepoURL}", "--api-key", "${nugetApiKey}", "--skip-duplicate"
}
}
}
}
//--- HELPERS ---//
static def nugetVersion(version, revision) {
return (revision != null && revision != "0")
? "${version}.${revision}"
: "${version}"
}