-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathrakefile.rb
239 lines (212 loc) · 6.99 KB
/
rakefile.rb
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
# encoding: utf-8
require 'rubygems'
require 'rake/version_task'
Rake::VersionTask.new
require 'albacore'
require 'rake/clean'
require 'date'
OPTIONS_COMPANY = "Acropolium"
OPTIONS_AUTHOR = "Oleksii Glib"
OPTIONS_PROJECT = "Rest4Net"
OPTIONS_URL_PROJECT = "https://github.com/acropolium/Rest4Net"
OPTIONS_URL_LICENSE = "https://github.com/acropolium/Rest4Net/blob/master/license.txt"
OPTIONS_COPYRIGHT = "Copyright (c) "+OPTIONS_AUTHOR+" 2010-"+Date.today.strftime("%Y")
OUTPUT = "build"
SOLUTION_FILE = FileList["src/*.sln"][0]
CLEAN.include(OUTPUT)
CLEAN.include(FileList["src/**/bin"])
CLEAN.include(FileList["src/**/obj"])
Albacore.configure do |config|
config.log_level = :non_verbose
config.msbuild.use :net4
end
def win_dir
ENV['windir'] || ENV['WINDIR'] || 'C:/Windows'
end
def get_net_version(netversion)
case netversion
when :net2, :net20, :net3, :net30
version = 'v2.0.50727'
when :net35
version = 'v3.5'
when :net4, :net40, :net45, :portable45, :portable40
version = 'v4.0.30319'
else
fail_with_message "The .NET Framework #{netversion} is not supported"
end
File.join win_dir, 'Microsoft.NET', 'Framework', version
end
def get_configuration(netversion)
case netversion
when :net20
version = '2.0'
when :net35
version = '3.5'
when :net40
version = '4.0'
when :net45
version = '4.5'
when :portable45
return 'Portable 4.5'
when :portable40
return 'Portable 4.0'
else
fail_with_message "The .NET Framework #{netversion} is not supported"
end
return 'Release ' + version
end
def get_dir(netversion)
case netversion
when :net20
return 'net20'
when :net35
return 'net35'
when :net40
return 'net40'
when :net45
return 'net45'
when :portable45
return 'portable-net45+wp80+win8+wpa81'
when :portable40
return 'portable-net40+sl4+wp7+win8'
else
fail_with_message "The .NET Framework #{netversion} is not supported"
end
end
supportedNetVersions = [ :net20, :net35, :net40, :net45 ]
#supportedNetVersions = [ :net20, :net35, :net40, :net45, :portable45, :portable40 ]
buildTasksNetVersions = supportedNetVersions.map { |ver| "build_#{ver}" }
task :compile => [:clean, :version] + buildTasksNetVersions
task :default => [:clean, :version, :compile, :publish, :package, :nuget_package, :nuget_publish]
supportedNetVersions.zip(buildTasksNetVersions) do |ver, task|
msbuild task do |msb|
msb.properties :configuration => (get_configuration ver)
msb.targets :Clean, :Build
msb.solution = SOLUTION_FILE
msb.verbosity = 'quiet'
end
end
desc "Generates AssemblyInfo files"
task :version do |asm|
FileList["src/**/Properties/AssemblyInfo.*"].each { |assemblyfile|
asm = AssemblyInfo.new()
asm.use(assemblyfile)
asm.version = Version.current
asm.file_version = Version.current
asm.company_name = OPTIONS_COMPANY
asm.product_name = OPTIONS_PROJECT
asm.title = File.basename(File.dirname(File.dirname(assemblyfile)))
asm.copyright = OPTIONS_COPYRIGHT
asm.execute
}
end
desc "Gathers output files and copies them to the output folder"
task :publish => [:compile] do
Dir.mkdir(OUTPUT)
Dir.mkdir("#{OUTPUT}/binaries")
supportedNetVersions.each do |ver|
d = get_dir(ver)
Dir.mkdir("#{OUTPUT}/binaries/#{d}")
FileUtils.cp_r FileList["src/**/#{d}/*.dll", "src/**/#{d}/*.pdb", "src/**/#{d}/*.xml"].exclude(/obj\//).exclude(/.Tests/), "#{OUTPUT}/binaries/#{d}"
end
end
desc "Zips up the built binaries for easy distribution"
zip :package => [:publish] do |zip|
Dir.mkdir("#{OUTPUT}/packages")
zip.directories_to_zip "#{OUTPUT}/binaries"
zip.output_file = "Rest4Net-Latest.zip"
zip.output_path = "#{OUTPUT}/packages"
end
def xmlSetOrCreate(xml, node, key, value)
el = node.elements[key]
if !el
el = node.add_element key
end
el.text = value
end
desc "Generates NuGet packages for each project that contains a nuspec"
task :nuget_package => [:publish] do
Dir.mkdir("#{OUTPUT}/nuget")
nuspecs = FileList["src/*/*.nuspec"].exclude(/packages\//)
root = File.dirname(__FILE__)
FileUtils.cp_r nuspecs, "#{OUTPUT}/nuget"
nuspecs = FileList["#{OUTPUT}/nuget/*.nuspec"]
nuspecs.each do |nuspec|
update_xml nuspec do |xml|
md = xml.root.elements["metadata"]
xmlSetOrCreate(xml, md, "authors", OPTIONS_AUTHOR)
xmlSetOrCreate(xml, md, "copyright", OPTIONS_COPYRIGHT)
xmlSetOrCreate(xml, md, "owners", OPTIONS_AUTHOR)
xmlSetOrCreate(xml, md, "version", Version.current)
xmlSetOrCreate(xml, md, "licenseUrl", OPTIONS_URL_LICENSE)
xmlSetOrCreate(xml, md, "projectUrl", OPTIONS_URL_PROJECT)
xmlSetOrCreate(xml, md, "requireLicenseAcceptance", "false")
md.elements.each("dependencies/dependency") do |e|
if e.attributes["id"] == OPTIONS_PROJECT
e.attributes["version"] = Version.current
end
end
fe = xml.root.elements["files"]
if !fe
fe = REXML::Element.new('files')
xml.root.insert_after('//metadata', fe)
end
ff = fe.add_element 'file'
ff.add_attributes( {"src"=>("src/"+md.elements['id'].text+"/**/*.cs"), "target"=>"src"} )
supportedNetVersions.each do |v|
d = get_dir(v)
ff = fe.add_element 'file'
path = "#{OUTPUT}/binaries/#{d}/"+md.elements['id'].text+".dll"
ff.add_attributes( {"src"=>path, "target"=>"lib/#{d}"} )
path = "#{OUTPUT}/binaries/#{d}/"+md.elements['id'].text+".xml"
if File.file?(path)
ff = fe.add_element 'file'
ff.add_attributes( {"src"=>path, "target"=>"lib/#{d}"} )
end
end
end
end
nuspecs.each do |nuspec|
nuget = NuGetPack.new
nuget.command = "tools/nuget/nuget.exe"
nuget.nuspec = "\"" + root + '/' + nuspec + "\""
nuget.output = "#{OUTPUT}/nuget"
nuget.parameters = "-Symbols", "-BasePath \"#{root}\""
nuget.execute
end
end
desc "Pushes the nuget packages in the nuget folder up to the nuget gallery and symbolsource.org. Also publishes the packages into the feeds."
task :nuget_publish => [:nuget_package] do |task|
if Kernel.is_windows? == true
separator = "\\\\"
else
separator = "/"
end
nupkgs = FileList["#{OUTPUT}/nuget/*.nupkg"]
nupkgs.each do |nupkg|
begin
puts "Pushing #{nupkg}"
nuget_push = NuGetPush.new
nuget_push.command = "tools/nuget/nuget.exe"
nuget_push.package = File.expand_path(nupkg).gsub("/", separator)
nuget_push.create_only = false
nuget_push.execute
rescue
puts "Skipping #{nupkg}"
end
end
end
def Kernel.is_windows?
processor, platform, *rest = RUBY_PLATFORM.split("-")
platform == 'mingw32'
end
def update_xml(xml_path)
xml_file = File.new(xml_path)
xml = REXML::Document.new xml_file
yield xml
xml_file.close
xml_file = File.open(xml_path, "w")
formatter = REXML::Formatters::Pretty.new()
formatter.write(xml, xml_file)
xml_file.close
end