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+ msbuild. dependsOn nugetRestore
29+ msbuild {
30+ solutionFile = ' callfire-api-client-csharp.sln'
31+ configuration = buildReleaseConfiguration
32+ projectName = ' CallfireApiClient'
33+ generateDoc = true
34+ }
35+
36+ task msbuildDebug (type : com.ullink.Msbuild ) {
37+ solutionFile = ' callfire-api-client-csharp.sln'
38+ configuration = buildDebugConfiguration
39+ projectName = ' CallfireApiClient'
40+ }
41+ msbuildDebug. dependsOn nunit
42+
43+ nunit {
44+ testAssemblies = [ msbuild. projects[' CallfireApiClient.Tests' ]. properties.TargetPath ]
45+ }
46+ nunit. dependsOn msbuild
47+
48+ task updateNuspecFile << {
49+ def specFile = file(' CallfireApiClient.nuspec' )
50+ def spec = new XmlSlurper (). parse(specFile)
51+
52+ project. version = patchVersion(spec. metadata. version. text)
53+ spec. metadata. version = project. version
54+ spec. metadata. releaseNotes = file(' Changelog.txt' ). text
55+ // cleanup previous lib/ and src/ files since they depend on build configuration
56+ spec. files. file. findAll { it. @target == ' lib' || it. @target == ' src' }. each { it. replaceNode {} }
57+
58+ def isWindowsOs = Os . isFamily(Os . FAMILY_WINDOWS )
59+ def monoInstallation = " $System . env . MONO_HOME "
60+ def pdbToMdbConverter
61+ if (isWindowsOs) {
62+ if (monoInstallation != ' null' ) {
63+ pdbToMdbConverter = " $System . env . MONO_HOME " + " \\ bin\\ pdb2mdb.bat"
64+ exec { commandLine = [pdbToMdbConverter, " $assemblyBinDebugDir /${ archivesBaseName} .dll" ] }
65+ }
66+ }
67+
68+ spec. files. appendNode {
69+ file(src : " src/**/*.cs" , target : ' src' ) {}
70+ file(src : " $assemblyBinDebugDir /${ archivesBaseName} .dll" , target : ' lib' ) {}
71+ file(src : " $assemblyBinReleaseDir /${ archivesBaseName} .dll.config" , target : ' lib' ) {}
72+ file(src : " $assemblyBinReleaseDir /${ archivesBaseName} .xml" , target : ' lib' ) {}
73+ if (isWindowsOs) {
74+ file(src : " $assemblyBinDebugDir /${ archivesBaseName} .pdb" , target : ' lib' ) {}
75+ }
76+ file(src : " $assemblyBinDebugDir /${ archivesBaseName} .dll.mdb" , target : ' lib' ) {}
77+ }
78+
79+ def fw = new FileWriter (' CallfireApiClient.nuspec' )
80+ XmlUtil . serialize(spec, fw)
81+ // have to close manually because on windows file remains locked
82+ fw. close()
83+ }
84+ updateNuspecFile. dependsOn msbuildDebug
85+
86+ def patchVersion (version ) {
87+ def regex = ~/ \[ assembly: AssemblyVersion\( "(.*)\.\* "\)\] /
88+ def matcher = regex. matcher(new File (assemblyInfo). text)
89+ while (matcher. find()) {
90+ def updated = matcher. group(1 )
91+ println " Patching Nuspec version to $updated "
92+ return updated
93+ }
94+ version
95+ }
96+
97+ task zipBinaries (type : Zip ) {
98+ destinationDir = file(buildDistDir)
99+ from ' LICENSE'
100+ from ' Changelog'
101+ from (assemblyBinReleaseDir) {
102+ include " ${ archivesBaseName} .*"
103+ }
104+ }
105+ zipBinaries. dependsOn nugetSpec
106+
107+ // nuget package for upload to nuget
108+ nugetSpec {
109+ nuspecFile = file(' CallfireApiClient.nuspec' )
110+ }
111+ nugetSpec. dependsOn updateNuspecFile
112+
113+ nugetPack {
114+ destinationDir = buildDistDir
115+ generateSymbols = true
116+ }
117+ nugetPack. dependsOn zipBinaries
118+
119+ // nuget package upload, requires API key to be set
120+ nugetPush {
121+ apiKey = System . properties[ ' NUGET_API_KEY' ] ?: " key not set"
122+ nupkgFile = nugetPack. packageFile
123+ }
0 commit comments