albacore 1.0.0 → 2.0.0.rc.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (258) hide show
  1. data/.gitignore +6 -21
  2. data/.travis.yml +31 -12
  3. data/Gemfile +14 -6
  4. data/Guardfile +1 -3
  5. data/README.md +200 -47
  6. data/Rakefile +9 -19
  7. data/albacore.gemspec +33 -23
  8. data/lib/albacore.rb +3 -47
  9. data/lib/albacore/albacore_module.rb +57 -0
  10. data/lib/albacore/application.rb +43 -0
  11. data/lib/albacore/cmd_config.rb +66 -0
  12. data/lib/albacore/config_dsl.rb +55 -0
  13. data/lib/albacore/cross_platform_cmd.rb +291 -0
  14. data/lib/albacore/dsl.rb +90 -0
  15. data/lib/albacore/errors/command_failed_error.rb +11 -0
  16. data/lib/albacore/errors/command_not_found_error.rb +13 -0
  17. data/lib/albacore/errors/unfilled_property_error.rb +14 -0
  18. data/lib/albacore/ext/README.md +12 -0
  19. data/lib/albacore/ext/teamcity.rb +64 -0
  20. data/lib/albacore/facts.rb +25 -0
  21. data/lib/albacore/logging.rb +32 -0
  22. data/lib/albacore/nuget_model.rb +387 -0
  23. data/lib/albacore/paths.rb +34 -0
  24. data/lib/albacore/project.rb +141 -0
  25. data/lib/albacore/semver.rb +5 -0
  26. data/lib/albacore/task_types/asmver.rb +72 -0
  27. data/lib/albacore/task_types/asmver/cpp.rb +20 -0
  28. data/lib/albacore/task_types/asmver/cs.rb +17 -0
  29. data/lib/albacore/task_types/asmver/engine.rb +126 -0
  30. data/lib/albacore/task_types/asmver/file_generator.rb +45 -0
  31. data/lib/albacore/task_types/asmver/fs.rb +37 -0
  32. data/lib/albacore/task_types/asmver/vb.rb +27 -0
  33. data/lib/albacore/task_types/build.rb +192 -0
  34. data/lib/albacore/task_types/nugets_authentication.rb +9 -0
  35. data/lib/albacore/task_types/nugets_pack.rb +378 -0
  36. data/lib/albacore/task_types/nugets_restore.rb +138 -0
  37. data/lib/albacore/task_types/test_runner.rb +39 -0
  38. data/lib/albacore/tasks/README.md +16 -0
  39. data/lib/albacore/tasks/albasemver.rb +49 -0
  40. data/lib/albacore/tasks/projectlint.rb +81 -0
  41. data/lib/albacore/tasks/versionizer.rb +65 -0
  42. data/lib/albacore/tools/fluent_migrator.rb +177 -0
  43. data/lib/albacore/tools/restore_hint_paths.rb +112 -0
  44. data/lib/albacore/version.rb +3 -3
  45. data/spec/Rakefile +5 -0
  46. data/spec/albacore_spec.rb +12 -0
  47. data/spec/asmver_spec.rb +151 -0
  48. data/spec/asmver_task_spec.rb +32 -0
  49. data/spec/build_spec.rb +60 -0
  50. data/spec/config_dsl_spec.rb +83 -0
  51. data/spec/cross_platform_cmd_spec.rb +65 -0
  52. data/spec/dsl_spec.rb +39 -0
  53. data/spec/ext_teamcity_spec.rb +71 -0
  54. data/spec/facts_spec.rb +7 -0
  55. data/spec/nuget_model_spec.rb +401 -0
  56. data/spec/nugets_pack_spec.rb +231 -0
  57. data/spec/nugets_restore_spec.rb +55 -0
  58. data/spec/project_spec.rb +26 -0
  59. data/spec/projectlint/added_but_not_on_filesystem/aproject.csproj +29 -0
  60. data/spec/projectlint/correct/File.cs +1 -0
  61. data/spec/projectlint/correct/Image.txt +1 -0
  62. data/spec/projectlint/correct/MyHeavy.heavy +1 -0
  63. data/spec/projectlint/correct/Schema.xsd +1 -0
  64. data/spec/projectlint/correct/SubFolder/AnotherFile.cs +1 -0
  65. data/spec/projectlint/correct/aproject.csproj +29 -0
  66. data/spec/projectlint/on_filesystem_but_not_added/File.cs +1 -0
  67. data/spec/projectlint/on_filesystem_but_not_added/Image.txt +1 -0
  68. data/spec/projectlint/on_filesystem_but_not_added/aproject.csproj +11 -0
  69. data/spec/projectlint_spec.rb +77 -0
  70. data/spec/smoke_spec.rb +55 -0
  71. data/spec/spec_helper.rb +19 -20
  72. data/spec/support/Nuget/NuGet.exe +0 -0
  73. data/spec/support/echo/FSharp.Core.dll +0 -0
  74. data/spec/support/echo/FSharp.Core.xml +10517 -0
  75. data/spec/support/echo/echo.XML +12 -0
  76. data/spec/support/echo/echo.exe +0 -0
  77. data/spec/support/echo/echo.exe.config +17 -0
  78. data/spec/support/echo/echo.pdb +0 -0
  79. data/spec/support/returnstatus/FSharp.Core.dll +0 -0
  80. data/spec/support/returnstatus/FSharp.Core.xml +10517 -0
  81. data/spec/support/returnstatus/returnstatus.XML +12 -0
  82. data/spec/support/returnstatus/returnstatus.exe +0 -0
  83. data/spec/support/returnstatus/returnstatus.exe.config +17 -0
  84. data/spec/support/returnstatus/returnstatus.pdb +0 -0
  85. data/spec/support/sh_interceptor.rb +83 -0
  86. data/spec/testdata/.gitignore +5 -0
  87. data/spec/testdata/DebugProject/.gitignore +1 -0
  88. data/spec/testdata/DebugProject/Degbu.fsproj +57 -0
  89. data/spec/testdata/DebugProject/Degbu.sln +20 -0
  90. data/spec/testdata/DebugProject/Gemfile +1 -0
  91. data/spec/testdata/DebugProject/Library1.fs +4 -0
  92. data/spec/testdata/DebugProject/Rakefile +22 -0
  93. data/spec/testdata/EmptyProject/EmptyProject.csproj +39 -0
  94. data/spec/{assemblyinfo → testdata/EmptyProject/Properties}/AssemblyInfo.cs +5 -5
  95. data/spec/testdata/Gemfile +1 -0
  96. data/spec/testdata/NuGet.exe +0 -0
  97. data/spec/testdata/Project/Library1.fs +4 -0
  98. data/spec/testdata/Project/Project.fsproj +52 -0
  99. data/spec/testdata/Project/Project.sln +20 -0
  100. data/spec/testdata/Project/packages.config +6 -0
  101. data/spec/testdata/Rakefile +22 -0
  102. data/spec/testdata/TestingDependencies/Sample.Commands/Library.fs +6 -0
  103. data/spec/testdata/TestingDependencies/Sample.Commands/Sample.Commands.fsproj +78 -0
  104. data/spec/testdata/TestingDependencies/Sample.Commands/Script.fsx +8 -0
  105. data/spec/testdata/TestingDependencies/Sample.Commands/packages.config +6 -0
  106. data/spec/testdata/TestingDependencies/Sample.Core/Library.fs +3 -0
  107. data/spec/testdata/TestingDependencies/Sample.Core/Sample.Core.fsproj +59 -0
  108. data/spec/testdata/TestingDependencies/Sample.Core/Script.fsx +8 -0
  109. data/spec/testdata/TestingDependencies/Sample.Core/packages.config +4 -0
  110. data/spec/testdata/TestingDependencies/Sample.sln +26 -0
  111. data/spec/testdata/TestingDependencies/vendor/FSharp.Core.dll +0 -0
  112. data/spec/testdata/TestingDependencies/vendor/FSharp.Core.optdata +0 -0
  113. data/spec/testdata/TestingDependencies/vendor/FSharp.Core.sigdata +0 -0
  114. data/spec/testdata/TestingDependencies/vendor/FSharp.Core.xml +8748 -0
  115. data/spec/testdata/example.nuspec +14 -0
  116. data/spec/testdata/example.symbols.nuspec +21 -0
  117. data/spec/tools/fluent_migrator_spec.rb +80 -0
  118. metadata +303 -212
  119. data/.bundle/config +0 -2
  120. data/.rspec +0 -2
  121. data/CONTRIBUTING.md +0 -87
  122. data/LICENSE +0 -21
  123. data/lib/albacore/albacoretask.rb +0 -50
  124. data/lib/albacore/aspnetcompiler.rb +0 -80
  125. data/lib/albacore/assemblyinfo.rb +0 -163
  126. data/lib/albacore/assemblyinfolanguages/assemblyinfoengine.rb +0 -54
  127. data/lib/albacore/assemblyinfolanguages/cppcliengine.rb +0 -18
  128. data/lib/albacore/assemblyinfolanguages/csharpengine.rb +0 -15
  129. data/lib/albacore/assemblyinfolanguages/fsharpengine.rb +0 -23
  130. data/lib/albacore/assemblyinfolanguages/vbnetengine.rb +0 -15
  131. data/lib/albacore/config/aspnetcompilerconfig.rb +0 -30
  132. data/lib/albacore/config/assemblyinfoconfig.rb +0 -18
  133. data/lib/albacore/config/config.rb +0 -22
  134. data/lib/albacore/config/cscconfig.rb +0 -28
  135. data/lib/albacore/config/docuconfig.rb +0 -19
  136. data/lib/albacore/config/execconfig.rb +0 -19
  137. data/lib/albacore/config/fluentmigratorconfig.rb +0 -19
  138. data/lib/albacore/config/ilmergeconfig.rb +0 -19
  139. data/lib/albacore/config/msbuildconfig.rb +0 -29
  140. data/lib/albacore/config/mspecconfig.rb +0 -19
  141. data/lib/albacore/config/mstestconfig.rb +0 -19
  142. data/lib/albacore/config/nantconfig.rb +0 -18
  143. data/lib/albacore/config/nchurnconfig.rb +0 -19
  144. data/lib/albacore/config/ncoverconsoleconfig.rb +0 -19
  145. data/lib/albacore/config/ncoverreportconfig.rb +0 -18
  146. data/lib/albacore/config/ndependconfig.rb +0 -19
  147. data/lib/albacore/config/netversion.rb +0 -28
  148. data/lib/albacore/config/nugetinstallconfig.rb +0 -18
  149. data/lib/albacore/config/nugetpackconfig.rb +0 -18
  150. data/lib/albacore/config/nugetpushconfig.rb +0 -18
  151. data/lib/albacore/config/nugetupdateconfig.rb +0 -18
  152. data/lib/albacore/config/nunitconfig.rb +0 -19
  153. data/lib/albacore/config/nuspecconfig.rb +0 -18
  154. data/lib/albacore/config/plinkconfig.rb +0 -18
  155. data/lib/albacore/config/specflowconfig.rb +0 -18
  156. data/lib/albacore/config/sqlcmdconfig.rb +0 -18
  157. data/lib/albacore/config/unzipconfig.rb +0 -19
  158. data/lib/albacore/config/xbuildconfig.rb +0 -18
  159. data/lib/albacore/config/xunitconfig.rb +0 -18
  160. data/lib/albacore/config/zipdirectoryconfig.rb +0 -18
  161. data/lib/albacore/csc.rb +0 -77
  162. data/lib/albacore/docu.rb +0 -38
  163. data/lib/albacore/exec.rb +0 -20
  164. data/lib/albacore/fluentmigrator.rb +0 -69
  165. data/lib/albacore/ilmerge.rb +0 -38
  166. data/lib/albacore/msbuild.rb +0 -55
  167. data/lib/albacore/mspec.rb +0 -39
  168. data/lib/albacore/mstest.rb +0 -47
  169. data/lib/albacore/nant.rb +0 -41
  170. data/lib/albacore/nchurn.rb +0 -49
  171. data/lib/albacore/ncoverconsole.rb +0 -56
  172. data/lib/albacore/ncoverreport.rb +0 -40
  173. data/lib/albacore/ncoverreports.rb +0 -16
  174. data/lib/albacore/ncoverreports/assemblyfilter.rb +0 -10
  175. data/lib/albacore/ncoverreports/branchcoverage.rb +0 -10
  176. data/lib/albacore/ncoverreports/classfilter.rb +0 -9
  177. data/lib/albacore/ncoverreports/codecoveragebase.rb +0 -27
  178. data/lib/albacore/ncoverreports/cyclomaticcomplexity.rb +0 -23
  179. data/lib/albacore/ncoverreports/documentfilter.rb +0 -9
  180. data/lib/albacore/ncoverreports/fullcoveragereport.rb +0 -9
  181. data/lib/albacore/ncoverreports/methodcoverage.rb +0 -10
  182. data/lib/albacore/ncoverreports/methodfilter.rb +0 -9
  183. data/lib/albacore/ncoverreports/namespacefilter.rb +0 -9
  184. data/lib/albacore/ncoverreports/reportbase.rb +0 -23
  185. data/lib/albacore/ncoverreports/reportfilterbase.rb +0 -29
  186. data/lib/albacore/ncoverreports/summaryreport.rb +0 -9
  187. data/lib/albacore/ncoverreports/symbolcoverage.rb +0 -9
  188. data/lib/albacore/ndepend.rb +0 -33
  189. data/lib/albacore/nugetinstall.rb +0 -62
  190. data/lib/albacore/nugetpack.rb +0 -50
  191. data/lib/albacore/nugetpush.rb +0 -40
  192. data/lib/albacore/nugetupdate.rb +0 -50
  193. data/lib/albacore/nunit.rb +0 -46
  194. data/lib/albacore/nuspec.rb +0 -180
  195. data/lib/albacore/output.rb +0 -105
  196. data/lib/albacore/plink.rb +0 -50
  197. data/lib/albacore/specflow.rb +0 -30
  198. data/lib/albacore/sqlcmd.rb +0 -67
  199. data/lib/albacore/support/attrmethods.rb +0 -33
  200. data/lib/albacore/support/createtask.rb +0 -50
  201. data/lib/albacore/support/failure.rb +0 -15
  202. data/lib/albacore/support/logging.rb +0 -38
  203. data/lib/albacore/support/openstruct.rb +0 -13
  204. data/lib/albacore/support/platform.rb +0 -25
  205. data/lib/albacore/support/runcommand.rb +0 -45
  206. data/lib/albacore/support/updateattributes.rb +0 -13
  207. data/lib/albacore/support/yamlconfig.rb +0 -18
  208. data/lib/albacore/unzip.rb +0 -42
  209. data/lib/albacore/xbuild.rb +0 -41
  210. data/lib/albacore/xunit.rb +0 -44
  211. data/lib/albacore/zipdirectory.rb +0 -106
  212. data/spec/albacoremodel_spec.rb +0 -52
  213. data/spec/aspnetcompiler_spec.rb +0 -84
  214. data/spec/assemblyinfo_spec.rb +0 -209
  215. data/spec/attrmethods_spec.rb +0 -135
  216. data/spec/config_spec.rb +0 -32
  217. data/spec/createtask_spec.rb +0 -234
  218. data/spec/csc_spec.rb +0 -86
  219. data/spec/docu_spec.rb +0 -31
  220. data/spec/exec_spec.rb +0 -25
  221. data/spec/fluentmigrator_spec.rb +0 -88
  222. data/spec/ilmerge_spec.rb +0 -35
  223. data/spec/msbuild_spec.rb +0 -55
  224. data/spec/mspec_spec.rb +0 -30
  225. data/spec/mstest_spec.rb +0 -35
  226. data/spec/nant_spec.rb +0 -40
  227. data/spec/nchurn_spec.rb +0 -80
  228. data/spec/ncoverconsole_spec.rb +0 -80
  229. data/spec/ncoverreport_spec.rb +0 -139
  230. data/spec/ndepend_spec.rb +0 -26
  231. data/spec/netversion_spec.rb +0 -51
  232. data/spec/nugetinstall_spec.rb +0 -59
  233. data/spec/nugetpack_spec.rb +0 -49
  234. data/spec/nugetpush_spec.rb +0 -39
  235. data/spec/nugetupdate_spec.rb +0 -49
  236. data/spec/nunit_spec.rb +0 -35
  237. data/spec/nuspec/nuspec.xsd +0 -84
  238. data/spec/nuspec_spec.rb +0 -74
  239. data/spec/output/bar/bar.txt +0 -0
  240. data/spec/output/baz.txt +0 -0
  241. data/spec/output/erb.txt +0 -1
  242. data/spec/output/foo/foo/foo.txt +0 -0
  243. data/spec/output_spec.rb +0 -85
  244. data/spec/patch/system_patch.rb +0 -12
  245. data/spec/platform_spec.rb +0 -15
  246. data/spec/plink_spec.rb +0 -56
  247. data/spec/runcommand_spec.rb +0 -92
  248. data/spec/specflow_spec.rb +0 -30
  249. data/spec/sqlcmd_spec.rb +0 -66
  250. data/spec/unzip_spec.rb +0 -56
  251. data/spec/xbuild_spec.rb +0 -40
  252. data/spec/xunit_spec.rb +0 -30
  253. data/spec/yaml/test.yml +0 -3
  254. data/spec/yamlconfig_spec.rb +0 -53
  255. data/spec/zip/baz.txt +0 -0
  256. data/spec/zip/foo/bar/bar.txt +0 -0
  257. data/spec/zip/foo/foo.txt +0 -0
  258. data/spec/zip_spec.rb +0 -97
@@ -0,0 +1,90 @@
1
+ require 'albacore/cross_platform_cmd'
2
+
3
+ module Albacore
4
+ module DSL
5
+ # this means that you can use all things available in the cross platform
6
+ # cmd from within albacore
7
+ include Albacore::CrossPlatformCmd
8
+
9
+ private
10
+
11
+ # a rake task type for outputting assembly versions
12
+ def asmver *args, &block
13
+ require 'albacore/task_types/asmver'
14
+ Albacore.define_task *args do
15
+ c = Albacore::Asmver::Config.new
16
+ yield c
17
+ Albacore::Asmver::Task.new(c.opts).execute
18
+ end
19
+ end
20
+
21
+ # a task for building sln or proj files - or just invoking something
22
+ # with MsBuild
23
+ def build *args, &block
24
+ require 'albacore/task_types/build'
25
+ Albacore.define_task *args do
26
+ c = Albacore::Build::Config.new
27
+ yield c
28
+
29
+ fail "unable to find MsBuild or XBuild" unless c.exe
30
+ command = Albacore::Build::Cmd.new(c.work_dir, c.exe, c.parameters)
31
+ Albacore::Build::Task.new(command).execute
32
+ end
33
+ end
34
+
35
+ # restore the nugets to the solution
36
+ def nugets_restore *args, &block
37
+ require 'albacore/task_types/nugets_restore'
38
+ Albacore.define_task *args do
39
+ c = Albacore::NugetsRestore::Config.new
40
+ yield c
41
+
42
+ c.ensure_authentication!
43
+
44
+ c.packages.each do |p|
45
+ command = Albacore::NugetsRestore::Cmd.new(c.work_dir, c.exe, c.opts_for_pkgcfg(p))
46
+ Albacore::NugetsRestore::Task.new(command).execute
47
+ end
48
+ end
49
+ end
50
+
51
+ # pack nugets
52
+ def nugets_pack *args, &block
53
+ require 'albacore/task_types/nugets_pack'
54
+ Albacore.define_task *args do
55
+ c = Albacore::NugetsPack::Config.new
56
+ yield c
57
+ Albacore::NugetsPack::ProjectTask.new(c.opts).execute
58
+ end
59
+ end
60
+
61
+ # basically a command with some parameters; allows you to execute your
62
+ # tests with albacore
63
+ def test_runner *args, &block
64
+ require 'albacore/task_types/test_runner'
65
+ Albacore.define_task *args do
66
+ c = Albacore::TestRunner::Config.new
67
+ yield c
68
+
69
+ c.files.each { |dll|
70
+ command = Albacore::TestRunner::Cmd.new c.work_dir, c.exe, c.parameters, dll
71
+ Albacore::TestRunner::Task.new(command).execute
72
+ }
73
+ end
74
+ end
75
+
76
+ # Restore hint paths to registered nugets
77
+ def restore_hint_paths *args, &block
78
+ require 'albacore/tools/restore_hint_paths'
79
+ Albacore.define_task *args do
80
+ c = Albacore::RestoreHintPaths::Config.new
81
+ yield c
82
+
83
+ t = Albacore::RestoreHintPaths::Task.new c
84
+ t.execute
85
+ end
86
+ end
87
+ end
88
+ end
89
+
90
+ self.extend Albacore::DSL
@@ -0,0 +1,11 @@
1
+ module Albacore
2
+ class CommandFailedError < StandardError
3
+
4
+ attr_reader :executable
5
+
6
+ def initialize message, executable
7
+ super(message)
8
+ @executable = executable
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,13 @@
1
+ # -*- encoding: utf-8 -*-
2
+
3
+ module Albacore
4
+ class CommandNotFoundError < StandardError
5
+
6
+ attr_reader :executable
7
+
8
+ def initialize message, executable
9
+ super(message)
10
+ @executable = executable
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,14 @@
1
+ # -*- encoding: utf-8 -*-
2
+
3
+ module Albacore
4
+ class UnfilledPropertyError < StandardError
5
+ attr_accessor :property
6
+ def initialize property, message
7
+ super(message)
8
+ @property = property
9
+ end
10
+ def message
11
+ %Q{The property "#{property}"; #{message}}
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,12 @@
1
+ # Folder: ext
2
+
3
+ The `ext` folder contains Albacore extensions. Write code in this folder
4
+ according to the following conventions:
5
+
6
+ * doing `require 'albacore/ext/extension_name'` should add the extensions
7
+ of `extension_name` to the current albacore application. This means
8
+ that there should be no further requirement to call into albacore
9
+ after such a `require` call has been done.
10
+ * prefer to do extensions via `Albacore.subscribe` over extending
11
+ at the call-site, monkey-patching, or including the extended in
12
+ other class/module/object instances.
@@ -0,0 +1,64 @@
1
+ require 'albacore'
2
+
3
+ module Albacore
4
+ module Ext
5
+ # The teamcity module writes appropriate build-script "interaction messages"
6
+ # (see http://confluence.jetbrains.com/display/TCD7/Build+Script+Interaction+with+TeamCity#BuildScriptInteractionwithTeamCity-artPublishing)
7
+ # to STDOUT.
8
+ module TeamCity
9
+ # Escaped the progress message
10
+ # (see http://confluence.jetbrains.com/display/TCD7/Build+Script+Interaction+with+TeamCity#BuildScriptInteractionwithTeamCity-ServiceMessages)
11
+ # The Unicode symbol escape is not implemented
12
+ # Character Should be escaped as
13
+ # ' (apostrophe) |'
14
+ # \n (line feed) |n
15
+ # \r (carriage return) |r
16
+ # \uNNNN (unicode symbol with code 0xNNNN) |0xNNNN
17
+ # | (vertical bar) ||
18
+ # [ (opening bracket) |[
19
+ # ] (closing bracket) |]
20
+ def self.escape message
21
+ message.gsub(/([\[|\]|\|'])/, '|\1').gsub(/\n/, '|n').gsub(/\r/, '|r')
22
+ end
23
+ def self.configure
24
+ Albacore.subscribe :artifact do |artifact|
25
+ ::Albacore.puts "##teamcity[publishArtifacts '#{artifact.location}']"
26
+ end
27
+ Albacore.subscribe :build_version do |version|
28
+ # tell teamcity our decision
29
+ ::Albacore.puts "##teamcity[buildNumber '#{version.build_version}']"
30
+ end
31
+ Albacore.subscribe :progress do |p|
32
+ # tell teamcity of our progress
33
+ ::Albacore.puts "##teamcity[progressMessage '#{escape p.message}']"
34
+ end
35
+ Albacore.subscribe :start_progress do |p|
36
+ # tell teamcity of our progress
37
+ start_progress p.message
38
+ end
39
+ Albacore.subscribe :finish_progress do |p|
40
+ # tell teamcity of our progress
41
+ finish_progress p.message
42
+ end
43
+ end
44
+ private
45
+ PROGRESS_QUEUE = []
46
+ # Starts a new progress block
47
+ def self.start_progress(name)
48
+ PROGRESS_QUEUE.push name
49
+ ::Albacore.puts "##teamcity[progressStart '#{escape name}']"
50
+ end
51
+ # Finishes the progress block and all child progress blocks
52
+ def self.finish_progress(name = '')
53
+ loop do
54
+ p = PROGRESS_QUEUE.pop
55
+ ::Albacore.puts "##teamcity[progressFinish '#{escape p}']" unless p.nil?
56
+ break unless !p.nil? || name == p || name == ''
57
+ end
58
+ end
59
+ end
60
+ end
61
+ end
62
+
63
+ # subscribe the handlers directly when loading this file
64
+ Albacore::Ext::TeamCity.configure
@@ -0,0 +1,25 @@
1
+ # -*- encoding: utf-8 -*-
2
+
3
+ module Albacore
4
+ module Facts
5
+
6
+ def self.processor_count
7
+ case RbConfig::CONFIG['host_os']
8
+ when /darwin9/
9
+ `hwprefs cpu_count`.to_i
10
+ when /darwin/
11
+ ((`which hwprefs` != '') ? `hwprefs thread_count` : `sysctl -n hw.ncpu`).to_i
12
+ when /linux/
13
+ `cat /proc/cpuinfo | grep processor | wc -l`.to_i
14
+ when /freebsd/
15
+ `sysctl -n hw.ncpu`.to_i
16
+ when /mswin|mingw/
17
+ require 'win32ole'
18
+ # http://msdn.microsoft.com/en-us/library/windows/desktop/aa394373%28v=vs.85%29.aspx
19
+ wmi = WIN32OLE.connect("winmgmts://")
20
+ cpu = wmi.ExecQuery("select NumberOfLogicalProcessors from Win32_Processor")
21
+ cpu.to_enum.first.NumberOfLogicalProcessors
22
+ end
23
+ end
24
+ end
25
+ end
@@ -0,0 +1,32 @@
1
+ # -*- encoding: utf-8 -*-
2
+ require 'logger'
3
+ require 'albacore/application'
4
+
5
+ module Albacore
6
+ module Logging
7
+ def trace *str, &block
8
+ ::Albacore.application.logger.debug *str, &block
9
+ end
10
+ def debug *str, &block
11
+ ::Albacore.application.logger.debug *str, &block
12
+ end
13
+ def info *str, &block
14
+ ::Albacore.application.logger.info *str, &block
15
+ end
16
+ def warn *str, &block
17
+ ::Albacore.application.logger.warn *str, &block
18
+ end
19
+ def error *str, &block
20
+ ::Albacore.application.logger.error *str, &block
21
+ end
22
+ def fatal *str, &block
23
+ ::Albacore.application.logger.fatal *str, &block
24
+ end
25
+ def puts *str
26
+ ::Albacore.application.puts *str
27
+ end
28
+ def err str
29
+ ::Albacore.application.err str
30
+ end
31
+ end
32
+ end
@@ -0,0 +1,387 @@
1
+ require 'map'
2
+ require 'albacore/logging'
3
+ require 'albacore/project'
4
+ require 'albacore/paths'
5
+
6
+ module Albacore
7
+ module NugetModel
8
+ class IdVersion
9
+ attr_reader :id, :version
10
+ def initialize id, version
11
+ @id, @version = id, version
12
+ end
13
+ def to_s
14
+ "#{id}@#{version}"
15
+ end
16
+ end
17
+
18
+ class FileItem
19
+ attr_reader :src, :target, :exclude
20
+ def initialize src, target, excl
21
+ src, target = Albacore::Paths.normalise_slashes(src),
22
+ Albacore::Paths.normalise_slashes(target)
23
+ @src, @target, @exclude = src, target, excl
24
+ end
25
+ def to_s
26
+ "NugetModel::FileItem(src: #{@src}, target: #{@target}, exclude: #{@exclude}"
27
+ end
28
+ end
29
+
30
+ # the nuget xml metadata element writer
31
+ class Metadata
32
+ include Logging
33
+
34
+ def self.nuspec_field *syms
35
+ syms.each do |sym|
36
+ self.class_eval(
37
+ %{def #{sym}
38
+ @#{sym}
39
+ end})
40
+ self.class_eval(
41
+ %{def #{sym}= val
42
+ @#{sym} = val
43
+ @set_fields.add? :#{sym}
44
+ end})
45
+ end
46
+ end
47
+
48
+ # gets or sets the id of this package
49
+ nuspec_field :id
50
+
51
+ # gets or sets the version of this package
52
+ nuspec_field :version
53
+
54
+ # gets or sets the authors of this package
55
+ nuspec_field :authors
56
+
57
+ # gets or sets the description of this package
58
+ nuspec_field :description
59
+
60
+ # gets or sets the language that this package has been built with
61
+ nuspec_field :language
62
+
63
+ # gets or sets the project url for this package
64
+ nuspec_field :project_url
65
+
66
+ # gets or sets the license url for this package
67
+ nuspec_field :license_url
68
+
69
+ # gets or sets the release notes for this build.
70
+ nuspec_field :release_notes
71
+
72
+ # gets or sets the owners of this package
73
+ nuspec_field :owners
74
+
75
+ # gets or sets whether this package requires a license acceptance from the user
76
+ # hint: don't.
77
+ nuspec_field :require_license_acceptance
78
+
79
+ # gets or sets the copyright for this package
80
+ nuspec_field :copyright
81
+
82
+ # get or sets the tags for this package
83
+ nuspec_field :tags
84
+
85
+ # get the dependent nuget packages for this package
86
+ nuspec_field :dependencies
87
+
88
+ # gets the framework assemblies for this package
89
+ nuspec_field :framework_assemblies
90
+
91
+ # gets the field symbols that have been set
92
+ attr_reader :set_fields
93
+
94
+ # initialise a new package data object
95
+ def initialize dependencies = nil, framework_assemblies = nil
96
+ @set_fields = Set.new
97
+ @dependencies = dependencies || Hash.new
98
+ @framework_assemblies = framework_assemblies || Hash.new
99
+
100
+ debug "creating new metadata with dependencies: #{dependencies} [nuget model: metadata]" unless dependencies.nil?
101
+ debug "creating new metadata (same as prev) with fw asms: #{framework_assemblies} [nuget model: metadata]" unless framework_assemblies.nil?
102
+ end
103
+
104
+ # add a dependency to the package; id and version
105
+ def add_dependency id, version
106
+ @dependencies[id] = IdVersion.new id, version
107
+ end
108
+
109
+ # add a framework dependency for the package
110
+ def add_framework_dependency id, version
111
+ @framework_assemblies[id] = IdVersion.new id, version
112
+ end
113
+
114
+ def to_xml_builder
115
+ # alt: new(encoding: 'utf-8')
116
+ Nokogiri::XML::Builder.new do |x|
117
+ x.metadata {
118
+ @set_fields.each do |f|
119
+ x.send(Metadata.pascal_case(f), send(f))
120
+ end
121
+ x.dependencies {
122
+ @dependencies.each { |k, d|
123
+ x.dependency id: d.id, version: d.version
124
+ }
125
+ }
126
+ }
127
+ end
128
+ end
129
+
130
+ # transform the data structure to the corresponding xml
131
+ def to_xml
132
+ to_xml_builder.to_xml
133
+ end
134
+
135
+ def merge_with other
136
+ raise ArgumentError, 'other is nil' if other.nil?
137
+ raise ArgumentError, 'other is wrong type' unless other.is_a? Metadata
138
+
139
+ trace { "#{self} merging with #{other} [nuget model: metadata]" }
140
+
141
+ deps = @dependencies.clone.merge(other.dependencies)
142
+ fw_asms = @framework_assemblies.clone.merge(other.framework_assemblies)
143
+
144
+ m_next = Metadata.new deps, fw_asms
145
+
146
+ # set all my fields to the new instance
147
+ @set_fields.each do |field|
148
+ debug "setting field '#{field}' to be '#{send(field)}' [nuget model: metadata]"
149
+ m_next.send(:"#{field}=", send(field))
150
+ end
151
+
152
+ # set all other's fields to the new instance, overriding mine
153
+ other.set_fields.each do |field|
154
+ debug "setting field '#{field}' to be '#{send(field)}' [nuget model: metadata]"
155
+ m_next.send(:"#{field}=", other.send(field))
156
+ end
157
+
158
+ m_next
159
+ end
160
+
161
+ def to_s
162
+ "NugetModel::Metadata(#{ @set_fields.map { |f| "#{f}=#{send(f)}" }.join(', ') })"
163
+ end
164
+
165
+ self.extend Logging
166
+
167
+ def self.from_xml node
168
+ m = Metadata.new
169
+ node.children.reject { |n| n.text? }.each do |n|
170
+ if n.name == 'dependencies'
171
+ n.children.reject { |n| n.text? }.each do |dep|
172
+ m.add_dependency dep['id'], dep['version']
173
+ end
174
+ elsif n.name == 'frameworkDepdendencies'
175
+ n.children.reject { |n| n.text? }.each do |dep|
176
+ m.add_framework_depdendency dep['id'], dep['version']
177
+ end
178
+ else
179
+ # just set the property
180
+ m.send(:"#{underscore n.name}=", n.inner_text)
181
+ end
182
+ end
183
+ m
184
+ end
185
+
186
+ def self.pascal_case str
187
+ str = str.to_s unless str.respond_to? :split
188
+ str = str.split('_').inject([]){ |buffer,e| buffer.push(buffer.empty? ? e : e.capitalize) }.join
189
+ :"#{str}"
190
+ end
191
+
192
+ def self.underscore str
193
+ str.gsub(/::/, '/').
194
+ gsub(/([A-Z]+)([A-Z][a-z])/,'\1_\2').
195
+ gsub(/([a-z\d])([A-Z])/,'\1_\2').
196
+ tr("-", "_").
197
+ downcase
198
+ end
199
+ end
200
+
201
+ # the nuget package element writer
202
+ class Package
203
+ include Logging
204
+
205
+ # the metadata corresponds to the metadata element of the nuspec
206
+ attr_accessor :metadata
207
+
208
+ # the files is something enumerable that corresponds to the file
209
+ # elements inside '//package/files'.
210
+ attr_accessor :files
211
+
212
+ # creates a new nuspec package instance
213
+ def initialize metadata = nil, files = nil
214
+ @metadata = metadata || Metadata.new
215
+ @files = files || []
216
+ end
217
+
218
+ # add a file to the instance
219
+ def add_file src, target, exclude = nil
220
+ @files << FileItem.new(src, target, exclude)
221
+ self
222
+ end
223
+
224
+ # remove the file denoted by src
225
+ def remove_file src
226
+ src = src.src if src.respond_to? :src # if passed an OpenStruct e.g.
227
+ trace { "remove_file: removing file '#{src}' [nuget model: package]" }
228
+ @files = @files.reject { |f| f.src == src }
229
+ end
230
+
231
+ # do something with the metadata.
232
+ # returns the #self Package instance
233
+ def with_metadata &block
234
+ yield @metadata if block_given?
235
+ self
236
+ end
237
+
238
+ # gets the current package as a xml builder
239
+ def to_xml_builder
240
+ md = Nokogiri::XML(@metadata.to_xml).at_css('metadata').to_xml
241
+ Nokogiri::XML::Builder.new(encoding: 'utf-8') do |x|
242
+ x.package(xmlns: 'http://schemas.microsoft.com/packaging/2010/07/nuspec.xsd') {
243
+ x << md
244
+ #x.__send__ :insert, md.at_css("metadata")
245
+ # x << md.at_css("metadata").to_xml(indent: 4)
246
+ x.files {
247
+ @files.each do |f|
248
+ if f.exclude
249
+ x.file src: f.src, target: f.target, exclude: f.exclude
250
+ else
251
+ x.file src: f.src, target: f.target
252
+ end
253
+ end
254
+ }
255
+ }
256
+ end
257
+ end
258
+
259
+ # gets the current package as a xml node
260
+ def to_xml
261
+ to_xml_builder.to_xml
262
+ end
263
+
264
+ # creates a new Package/Metadata by overriding data in this instance with
265
+ # data from passed instance
266
+ def merge_with other
267
+ m_next = @metadata.merge_with other.metadata
268
+ files_other = {}
269
+ other.files.each { |f| files_other[f.src] = f }
270
+ f_next = @files.collect { |f| files_other.fetch f.src, f }
271
+ Package.new m_next, f_next
272
+ end
273
+
274
+ def to_s
275
+ "NugetModel::Package(files: #{@files.map(&:to_s)}, metadata: #{ @metadata.to_s })"
276
+ end
277
+
278
+ # gimme some logging lööve
279
+ self.extend Logging
280
+
281
+ # read the nuget specification from a nuspec file
282
+ def self.from_xml xml
283
+ ns = { ng: 'http://schemas.microsoft.com/packaging/2010/07/nuspec.xsd' }
284
+ parser = Nokogiri::XML(xml)
285
+ meta = Metadata.from_xml(parser.xpath('.//ng:metadata', ns))
286
+ files = parser.
287
+ xpath('.//ng:files', ns).
288
+ children.
289
+ reject { |n| n.text? or n['src'].nil? }.
290
+ collect { |n| FileItem.new n['src'], n['target'], n['exclude'] }
291
+ Package.new meta, files
292
+ end
293
+
294
+ # read the nuget specification from a xxproj file (e.g. csproj, fsproj)
295
+ def self.from_xxproj_file file, *opts
296
+ proj = Albacore::Project.new file
297
+ from_xxproj proj, *opts
298
+ end
299
+
300
+ # Read the nuget specification from a xxproj instance (e.g. csproj, fsproj)
301
+ # Options:
302
+ # - symbols
303
+ # - dotnet_version
304
+ # - known_projects
305
+ # - configuration
306
+ # - project_dependencies
307
+ # - nuget_dependencies
308
+ def self.from_xxproj proj, *opts
309
+ opts = Map.options(opts || {}).
310
+ apply({
311
+ symbols: false,
312
+ dotnet_version: 'net40',
313
+ known_projects: Set.new,
314
+ configuration: 'Debug',
315
+ project_dependencies: true,
316
+ verify_files: false,
317
+ nuget_dependencies: true })
318
+
319
+ trace { "#from_xxproj opts: #{opts} [nuget model: package]" }
320
+
321
+ version = opts.get :version
322
+ package = Package.new
323
+ package.metadata.id = proj.name if proj.name
324
+ package.metadata.version = version if version
325
+ package.metadata.authors = proj.authors if proj.authors
326
+
327
+ if opts.get :nuget_dependencies
328
+ # add declared packages as dependencies
329
+ proj.declared_packages.each do |p|
330
+ package.metadata.add_dependency p.id, p.version
331
+ end
332
+ end
333
+
334
+ if opts.get :project_dependencies
335
+ # add declared projects as dependencies
336
+ proj.
337
+ declared_projects.
338
+ keep_if { |p| opts.get(:known_projects).include? p.name }.
339
+ each do |p|
340
+ debug "adding project dependency: #{proj.name} => #{p.name} at #{version} [nuget model: package]"
341
+ package.metadata.add_dependency p.name, version
342
+ end
343
+ end
344
+
345
+ output = proj.output_path(opts.get(:configuration))
346
+ target_lib = %W[lib #{opts.get(:dotnet_version)}].join(Albacore::Paths.separator)
347
+
348
+ if opts.get :symbols
349
+ compile_files = proj.included_files.keep_if { |f| f.item_name == "compile" }
350
+
351
+ debug "add compiled files: #{compile_files} [nuget model: package]"
352
+ compile_files.each do |f|
353
+ target = %W[src #{Albacore::Paths.normalise_slashes(f.include)}].join(Albacore::Paths.separator)
354
+ package.add_file f.include, target
355
+ end
356
+
357
+ debug "add dll and pdb files [nuget model: package]"
358
+ package.add_file(Albacore::Paths.normalise_slashes(output + proj.asmname + '.pdb'), target_lib)
359
+ package.add_file(Albacore::Paths.normalise_slashes(output + proj.asmname + '.dll'), target_lib)
360
+ else
361
+ # add *.{dll,xml,config}
362
+ %w[dll xml config].each do |ext|
363
+ file = %W{#{output} #{proj.asmname}.#{ext}}.
364
+ map { |f| f.gsub /\\$/, '' }.
365
+ map { |f| Albacore::Paths.normalise_slashes f }.
366
+ join(Albacore::Paths.separator)
367
+ debug "adding binary file #{file} [nuget model: package]"
368
+ package.add_file file, target_lib
369
+ end
370
+ end
371
+
372
+ if opts.get :verify_files
373
+ package.files.each do |file|
374
+ file_path = File.expand_path file.src, proj.proj_path_base
375
+ unless File.exists? file_path
376
+ package.remove_file file.src
377
+ info "while building nuspec for proj: #{proj.name}, file: #{file.src} => #{file.target} not found, removing from nuspec [nuget model: package]"
378
+ trace { "files: #{package.files.map { |f| f.src }.inspect} [nuget model: package]" }
379
+ end
380
+ end
381
+ end
382
+
383
+ package
384
+ end
385
+ end
386
+ end
387
+ end