1+ import org.gradle.internal.os.OperatingSystem
2+ import org.apache.tools.ant.taskdefs.condition.Os
3+ import groovy.xml.XmlUtil
4+
5+ plugins {
6+ id ' com.ullink.msbuild' version ' 2.14'
7+ id ' com.ullink.nuget' version ' 2.12'
8+ id ' com.ullink.nunit' version ' 1.4'
9+ id ' com.ullink.opencover' version ' 1.2'
10+ id ' net.researchgate.release' version ' 2.3.4'
11+ }
12+
13+ archivesBaseName = ' callfire-api-client'
14+ ext[' buildReleaseConfiguration' ] = " Release"
15+ ext[' buildDebugConfiguration' ] = " Debug"
16+ ext[' assemblyBinReleaseDir' ] = " src/CallfireApiClient/bin/$buildReleaseConfiguration "
17+ ext[' assemblyBinDebugDir' ] = " src/CallfireApiClient/bin/$buildDebugConfiguration "
18+ ext[' buildDistDir' ] = " $buildDir /dist"
19+ ext[' assemblyInfo' ] = " src/CallfireApiClient/Properties/AssemblyInfo.cs"
20+
21+ defaultTasks(' nugetPack' )
22+
23+ nuget {
24+ // oh boy, version 3.3.0 seems to freeze during restore on linux ... rollbacking.... again
25+ version = ' 2.8.6'
26+ }
27+
28+ task msbuildRelease (type : com.ullink.Msbuild ) {
29+ solutionFile = ' callfire-api-client-csharp.sln'
30+ configuration = buildReleaseConfiguration
31+ projectName = ' CallfireApiClient'
32+ generateDoc = true
33+ }
34+ msbuildRelease. dependsOn nugetRestore
35+
36+ task msbuildDebug (type : com.ullink.Msbuild ) {
37+ msbuild {
38+ solutionFile = ' callfire-api-client-csharp.sln'
39+ configuration = buildDebugConfiguration
40+ projectName = ' CallfireApiClient'
41+ }
42+ }
43+ msbuildDebug. dependsOn nunit
44+
45+ nunit {
46+ testAssemblies = [ msbuild. projects[' CallfireApiClient.Tests' ]. properties.TargetPath ]
47+ }
48+ nunit. dependsOn msbuildRelease
49+
50+ task updateNuspecFile << {
51+ def specFile = file(' CallfireApiClient.nuspec' )
52+ def spec = new XmlSlurper (). parse(specFile)
53+
54+ project. version = patchVersion(spec. metadata. version. text)
55+ spec. metadata. version = project. version
56+ spec. metadata. releaseNotes = file(' Changelog' ). text
57+ // cleanup previous lib/ and src/ files since they depend on build configuration
58+ spec. files. file. findAll { it. @target == ' lib' || it. @target == ' src' }. each { it. replaceNode {} }
59+
60+ def isWindowsOs = Os . isFamily(Os . FAMILY_WINDOWS )
61+ def monoInstallation = " $System . env . MONO_HOME "
62+ def pdbToMdbConverter
63+ if (isWindowsOs) {
64+ if (monoInstallation != ' null' ) {
65+ pdbToMdbConverter = " $System . env . MONO_HOME " + " \\ bin\\ pdb2mdb.bat"
66+ exec { commandLine = [pdbToMdbConverter, " $assemblyBinDebugDir /${ archivesBaseName} .dll" ] }
67+ }
68+ }
69+
70+ spec. files. appendNode {
71+ file(src : " src/**/*.cs" , target : ' src' ) {}
72+ file(src : " $assemblyBinDebugDir /${ archivesBaseName} .dll" , target : ' lib' ) {}
73+ file(src : " $assemblyBinReleaseDir /${ archivesBaseName} .dll.config" , target : ' lib' ) {}
74+ file(src : " $assemblyBinReleaseDir /${ archivesBaseName} .xml" , target : ' lib' ) {}
75+ if (isWindowsOs) {
76+ file(src : " $assemblyBinDebugDir /${ archivesBaseName} .pdb" , target : ' lib' ) {}
77+ }
78+ file(src : " $assemblyBinDebugDir /${ archivesBaseName} .dll.mdb" , target : ' lib' ) {}
79+ }
80+
81+ def fw = new FileWriter (' CallfireApiClient.nuspec' )
82+ XmlUtil . serialize(spec, fw)
83+ // have to close manually because on windows file remains locked
84+ fw. close()
85+ }
86+ updateNuspecFile. dependsOn msbuildDebug
87+
88+ def patchVersion (version ) {
89+ def regex = ~/ \[ assembly: AssemblyVersion\( "(.*)\.\* "\)\] /
90+ def matcher = regex. matcher(new File (assemblyInfo). text)
91+ while (matcher. find()) {
92+ def updated = matcher. group(1 )
93+ println " Patching Nuspec version to $updated "
94+ return updated
95+ }
96+ version
97+ }
98+
99+ task zipBinaries (type : Zip ) {
100+ destinationDir = file(buildDistDir)
101+ from ' LICENSE'
102+ from ' Changelog'
103+ from (assemblyBinReleaseDir) {
104+ include " ${ archivesBaseName} .*"
105+ }
106+ }
107+ zipBinaries. dependsOn nugetSpec
108+
109+ // nuget package for upload to nuget
110+ nugetSpec {
111+ nuspecFile = file(' CallfireApiClient.nuspec' )
112+ }
113+ nugetSpec. dependsOn updateNuspecFile
114+
115+ nugetPack {
116+ destinationDir = buildDistDir
117+ generateSymbols = true
118+ }
119+ nugetPack. dependsOn zipBinaries
120+
121+ // nuget package upload, requires API key to be set
122+ nugetPush {
123+ apiKey = System . properties[ ' NUGET_API_KEY' ] ?: " key not set"
124+ nupkgFile = nugetPack. packageFile
125+ }
0 commit comments