albacore 0.2.5 → 0.2.6

Sign up to get free protection for your applications and to get access to all the features.
Files changed (131) hide show
  1. data/.autotest +4 -4
  2. data/.bundle/config +2 -2
  3. data/.rvmrc +1 -1
  4. data/Gemfile +12 -12
  5. data/README.markdown +92 -68
  6. data/VERSION +1 -1
  7. data/lib/albacore.rb +9 -9
  8. data/lib/albacore/albacoretask.rb +50 -50
  9. data/lib/albacore/aspnetcompiler.rb +58 -58
  10. data/lib/albacore/assemblyinfo.rb +140 -140
  11. data/lib/albacore/assemblyinfolanguages/cppcliengine.rb +17 -0
  12. data/lib/albacore/assemblyinfolanguages/csharpengine.rb +18 -18
  13. data/lib/albacore/assemblyinfolanguages/vbnetengine.rb +18 -18
  14. data/lib/albacore/config/aspnetcompilerconfig.rb +29 -29
  15. data/lib/albacore/config/assemblyinfoconfig.rb +13 -13
  16. data/lib/albacore/config/config.rb +22 -22
  17. data/lib/albacore/config/cscconfig.rb +28 -28
  18. data/lib/albacore/config/docuconfig.rb +23 -23
  19. data/lib/albacore/config/execconfig.rb +15 -15
  20. data/lib/albacore/config/fluentmigratorrunnerconfig.rb +15 -15
  21. data/lib/albacore/config/msbuildconfig.rb +29 -29
  22. data/lib/albacore/config/mspectestrunnerconfig.rb +15 -15
  23. data/lib/albacore/config/mstesttestrunnerconfig.rb +15 -15
  24. data/lib/albacore/config/nantconfig.rb +15 -15
  25. data/lib/albacore/config/nchurnconfig.rb +15 -15
  26. data/lib/albacore/config/ncoverconsoleconfig.rb +15 -15
  27. data/lib/albacore/config/ncoverreportconfig.rb +15 -15
  28. data/lib/albacore/config/ndependconfig.rb +15 -15
  29. data/lib/albacore/config/netversion.rb +21 -21
  30. data/lib/albacore/config/nugetpackconfig.rb +3 -3
  31. data/lib/albacore/config/nugetpublishconfig.rb +19 -0
  32. data/lib/albacore/config/nugetpushconfig.rb +19 -0
  33. data/lib/albacore/config/nunittestrunnerconfig.rb +14 -14
  34. data/lib/albacore/config/specflowreportconfig.rb +24 -24
  35. data/lib/albacore/config/sqlcmdconfig.rb +15 -15
  36. data/lib/albacore/config/unzipconfig.rb +15 -15
  37. data/lib/albacore/config/vssgetconfig.rb +14 -0
  38. data/lib/albacore/config/xbuildconfig.rb +15 -15
  39. data/lib/albacore/config/xunittestrunnerconfig.rb +15 -15
  40. data/lib/albacore/config/zipdirectoryconfig.rb +15 -15
  41. data/lib/albacore/csc.rb +66 -62
  42. data/lib/albacore/docu.rb +41 -41
  43. data/lib/albacore/exec.rb +18 -18
  44. data/lib/albacore/fluentmigratorrunner.rb +51 -46
  45. data/lib/albacore/msbuild.rb +55 -55
  46. data/lib/albacore/mspectestrunner.rb +50 -50
  47. data/lib/albacore/mstesttestrunner.rb +43 -43
  48. data/lib/albacore/nant.rb +38 -38
  49. data/lib/albacore/nchurn.rb +74 -74
  50. data/lib/albacore/ncoverconsole.rb +68 -68
  51. data/lib/albacore/ncoverreport.rb +62 -62
  52. data/lib/albacore/ncoverreports/assemblyfilter.rb +9 -9
  53. data/lib/albacore/ncoverreports/branchcoverage.rb +9 -9
  54. data/lib/albacore/ncoverreports/classfilter.rb +9 -9
  55. data/lib/albacore/ncoverreports/codecoveragebase.rb +25 -25
  56. data/lib/albacore/ncoverreports/cyclomaticcomplexity.rb +23 -23
  57. data/lib/albacore/ncoverreports/documentfilter.rb +9 -9
  58. data/lib/albacore/ncoverreports/fullcoveragereport.rb +13 -13
  59. data/lib/albacore/ncoverreports/methodcoverage.rb +9 -9
  60. data/lib/albacore/ncoverreports/methodfilter.rb +9 -9
  61. data/lib/albacore/ncoverreports/namespacefilter.rb +9 -9
  62. data/lib/albacore/ncoverreports/reportfilterbase.rb +26 -26
  63. data/lib/albacore/ncoverreports/summaryreport.rb +18 -18
  64. data/lib/albacore/ncoverreports/symbolcoverage.rb +9 -9
  65. data/lib/albacore/ndepend.rb +33 -33
  66. data/lib/albacore/nugetpublish.rb +47 -0
  67. data/lib/albacore/nugetpush.rb +46 -0
  68. data/lib/albacore/nunittestrunner.rb +41 -41
  69. data/lib/albacore/nuspec.rb +133 -109
  70. data/lib/albacore/output.rb +99 -99
  71. data/lib/albacore/plink.rb +47 -47
  72. data/lib/albacore/specflowreport.rb +62 -62
  73. data/lib/albacore/sqlcmd.rb +80 -80
  74. data/lib/albacore/support/attrmethods.rb +33 -33
  75. data/lib/albacore/support/createtask.rb +50 -30
  76. data/lib/albacore/support/failure.rb +15 -15
  77. data/lib/albacore/support/logging.rb +38 -38
  78. data/lib/albacore/support/openstruct.rb +13 -13
  79. data/lib/albacore/support/runcommand.rb +45 -45
  80. data/lib/albacore/support/supportlinux.rb +23 -23
  81. data/lib/albacore/support/updateattributes.rb +13 -13
  82. data/lib/albacore/support/yamlconfig.rb +18 -18
  83. data/lib/albacore/unzip.rb +28 -28
  84. data/lib/albacore/vssget.rb +44 -0
  85. data/lib/albacore/xbuild.rb +54 -54
  86. data/lib/albacore/xunittestrunner.rb +52 -52
  87. data/lib/albacore/zipdirectory.rb +105 -105
  88. data/rakefile.rb +297 -297
  89. data/spec/albacoremodel_spec.rb +53 -53
  90. data/spec/assemblyinfo_spec.rb +541 -541
  91. data/spec/attrmethods_spec.rb +136 -136
  92. data/spec/config_spec.rb +34 -34
  93. data/spec/createtask_spec.rb +236 -236
  94. data/spec/csc_spec.rb +253 -253
  95. data/spec/docu_spec.rb +109 -109
  96. data/spec/exec_spec.rb +45 -45
  97. data/spec/fluentmigratorrunner_spec.rb +254 -185
  98. data/spec/msbuild_spec.rb +215 -215
  99. data/spec/mspec_spec.rb +28 -28
  100. data/spec/mstesttestrunner_spec.rb +142 -142
  101. data/spec/nant_spec.rb +110 -110
  102. data/spec/nchurn_spec.rb +75 -75
  103. data/spec/ncoverconsole_spec.rb +353 -353
  104. data/spec/ncoverreport_spec.rb +619 -619
  105. data/spec/ndepend_spec.rb +72 -72
  106. data/spec/nunittestrunner_spec.rb +122 -122
  107. data/spec/nuspec_spec.rb +78 -78
  108. data/spec/patches/docu_patch.rb +12 -12
  109. data/spec/patches/fail_patch.rb +8 -8
  110. data/spec/patches/system_patch.rb +20 -20
  111. data/spec/plink_spec.rb +62 -62
  112. data/spec/runcommand_spec.rb +94 -94
  113. data/spec/spec_helper.rb +17 -17
  114. data/spec/specflowreport_spec.rb +146 -146
  115. data/spec/sqlcmd_spec.rb +334 -334
  116. data/spec/support/assemblyinfotester.rb +51 -51
  117. data/spec/support/ironruby_validator.rb +26 -26
  118. data/spec/support/msbuildtestdata.rb +32 -32
  119. data/spec/support/nanttestdata.rb +33 -33
  120. data/spec/support/ncoverconsoletestdata.rb +19 -19
  121. data/spec/support/ncoverreporttestdata.rb +26 -26
  122. data/spec/support/nokogiri_validator.rb +15 -15
  123. data/spec/support/outputtestdata.rb +12 -12
  124. data/spec/support/ziptestdata.rb +12 -12
  125. data/spec/unzip_spec.rb +15 -15
  126. data/spec/xbuild_spec.rb +15 -15
  127. data/spec/xunit_spec.rb +168 -168
  128. data/spec/yamlconfig_spec.rb +49 -49
  129. data/spec/zip_spec.rb +104 -104
  130. data/watchrtesting.rb +8 -8
  131. metadata +15 -119
@@ -1,99 +1,99 @@
1
- require 'albacore/albacoretask'
2
- require 'erb'
3
- require 'ostruct'
4
- require 'fileutils'
5
-
6
- class OutputBuilder
7
- include FileUtils
8
-
9
- def initialize(dir_to, dir_from)
10
- @dir_to = dir_to
11
- @dir_from = dir_from
12
- end
13
-
14
- def dir(dir)
15
- cp_r "#{@dir_from}/#{dir}", @dir_to
16
- end
17
-
18
- def file(f)
19
- file(f,f)
20
- end
21
-
22
- def file(f, ft)
23
- #todo find more elegant way to create base dir if missing for file.
24
- initialize_to_path(ft)
25
- cp "#{@dir_from}/#{f}", "#{@dir_to}/#{ft}"
26
- end
27
-
28
- def erb(f, ft, locals)
29
- initialize_to_path(ft)
30
- erb = ERB.new(File.read("#{@dir_from}/#{f}"))
31
- File.open("#{@dir_to}/#{ft}", 'w') {|f| f.write erb.result(ErbBinding.new(locals).get_binding)}
32
- end
33
-
34
- def self.output_to(dir_to, dir_from)
35
- rmtree dir_to
36
- mkdir dir_to
37
- yield OutputBuilder.new(dir_to, dir_from)
38
- end
39
-
40
- private
41
- def initialize_to_path(ft)
42
- topath = File.dirname("#{@dir_to}/#{ft}")
43
- mkdir_p topath unless File.exist? topath
44
- topath
45
- end
46
- end
47
-
48
- class ErbBinding < OpenStruct
49
- def get_binding
50
- return binding()
51
- end
52
- end
53
-
54
-
55
- class Output
56
- include Albacore::Task
57
-
58
- def initialize
59
- super()
60
-
61
- @files = []
62
- @erbs = []
63
- @directories = []
64
- end
65
-
66
- def execute()
67
- fail_with_message 'No base dir' if @from_dir.nil?
68
- fail_with_message 'No output dir' if @to_dir.nil?
69
-
70
- OutputBuilder.output_to(@to_dir, @from_dir) do |o|
71
- @directories.each { |f| o.dir f }
72
- @files.each { |f| o.file *f }
73
- @erbs.each { |f| o.erb *f }
74
- end
75
- end
76
-
77
- def file(f, opts={})
78
- f_to = opts[:as] || f
79
- @files << [f,f_to]
80
- end
81
-
82
- def erb(f, opts={})
83
- f_to = opts[:as] || f
84
- @erbs << [f,f_to,opts[:locals]||{}]
85
- end
86
-
87
- def dir(d)
88
- @directories << d
89
- end
90
-
91
- def from(from_dir)
92
- @from_dir = from_dir
93
- end
94
-
95
- def to(to_dir)
96
- @to_dir = to_dir
97
- end
98
-
99
- end
1
+ require 'albacore/albacoretask'
2
+ require 'erb'
3
+ require 'ostruct'
4
+ require 'fileutils'
5
+
6
+ class OutputBuilder
7
+ include FileUtils
8
+
9
+ def initialize(dir_to, dir_from)
10
+ @dir_to = dir_to
11
+ @dir_from = dir_from
12
+ end
13
+
14
+ def dir(dir)
15
+ cp_r "#{@dir_from}/#{dir}", @dir_to
16
+ end
17
+
18
+ def file(f)
19
+ file(f,f)
20
+ end
21
+
22
+ def file(f, ft)
23
+ #todo find more elegant way to create base dir if missing for file.
24
+ initialize_to_path(ft)
25
+ cp "#{@dir_from}/#{f}", "#{@dir_to}/#{ft}"
26
+ end
27
+
28
+ def erb(f, ft, locals)
29
+ initialize_to_path(ft)
30
+ erb = ERB.new(File.read("#{@dir_from}/#{f}"))
31
+ File.open("#{@dir_to}/#{ft}", 'w') {|f| f.write erb.result(ErbBinding.new(locals).get_binding)}
32
+ end
33
+
34
+ def self.output_to(dir_to, dir_from)
35
+ rmtree dir_to
36
+ mkdir dir_to
37
+ yield OutputBuilder.new(dir_to, dir_from)
38
+ end
39
+
40
+ private
41
+ def initialize_to_path(ft)
42
+ topath = File.dirname("#{@dir_to}/#{ft}")
43
+ mkdir_p topath unless File.exist? topath
44
+ topath
45
+ end
46
+ end
47
+
48
+ class ErbBinding < OpenStruct
49
+ def get_binding
50
+ return binding()
51
+ end
52
+ end
53
+
54
+
55
+ class Output
56
+ include Albacore::Task
57
+
58
+ def initialize
59
+ super()
60
+
61
+ @files = []
62
+ @erbs = []
63
+ @directories = []
64
+ end
65
+
66
+ def execute()
67
+ fail_with_message 'No base dir' if @from_dir.nil?
68
+ fail_with_message 'No output dir' if @to_dir.nil?
69
+
70
+ OutputBuilder.output_to(@to_dir, @from_dir) do |o|
71
+ @directories.each { |f| o.dir f }
72
+ @files.each { |f| o.file *f }
73
+ @erbs.each { |f| o.erb *f }
74
+ end
75
+ end
76
+
77
+ def file(f, opts={})
78
+ f_to = opts[:as] || f
79
+ @files << [f,f_to]
80
+ end
81
+
82
+ def erb(f, opts={})
83
+ f_to = opts[:as] || f
84
+ @erbs << [f,f_to,opts[:locals]||{}]
85
+ end
86
+
87
+ def dir(d)
88
+ @directories << d
89
+ end
90
+
91
+ def from(from_dir)
92
+ @from_dir = from_dir
93
+ end
94
+
95
+ def to(to_dir)
96
+ @to_dir = to_dir
97
+ end
98
+
99
+ end
@@ -1,47 +1,47 @@
1
- require 'albacore/albacoretask'
2
-
3
- class PLink
4
- include Albacore::Task
5
- include Albacore::RunCommand
6
-
7
- attr_accessor :host, :port, :user, :key, :verbose
8
- attr_array :commands
9
-
10
- def initialize()
11
- @require_valid_command = false
12
- @port = 22
13
- @verbose = false
14
- @commands = []
15
- super()
16
- end
17
-
18
- def run()
19
- return unless check_command
20
-
21
- parameters = create_parameters
22
- result = run_command "Plink", parameters.join(" ")
23
- failure_message = 'Command Failed. See Build Log For Detail'
24
- fail_with_message failure_message if !result
25
- end
26
-
27
- def create_parameters
28
- parameters = []
29
- parameters << "#{@user}@#{@host} -P #{@port} "
30
- parameters << build_parameter("i", @key) unless @key.nil?
31
- parameters << "-batch"
32
- parameters << "-v" if @verbose
33
- parameters << @commands
34
- @logger.debug "PLink Parameters" + parameters.join(" ")
35
- return parameters
36
- end
37
-
38
- def build_parameter(param_name, param_value)
39
- "-#{param_name} #{param_value}"
40
- end
41
-
42
- def check_command
43
- return true if @command
44
- fail_with_message 'Plink.path_to_command cannot be nil.'
45
- return false
46
- end
47
- end
1
+ require 'albacore/albacoretask'
2
+
3
+ class PLink
4
+ include Albacore::Task
5
+ include Albacore::RunCommand
6
+
7
+ attr_accessor :host, :port, :user, :key, :verbose
8
+ attr_array :commands
9
+
10
+ def initialize()
11
+ @require_valid_command = false
12
+ @port = 22
13
+ @verbose = false
14
+ @commands = []
15
+ super()
16
+ end
17
+
18
+ def run()
19
+ return unless check_command
20
+
21
+ parameters = create_parameters
22
+ result = run_command "Plink", parameters.join(" ")
23
+ failure_message = 'Command Failed. See Build Log For Detail'
24
+ fail_with_message failure_message if !result
25
+ end
26
+
27
+ def create_parameters
28
+ parameters = []
29
+ parameters << "#{@user}@#{@host} -P #{@port} "
30
+ parameters << build_parameter("i", @key) unless @key.nil?
31
+ parameters << "-batch"
32
+ parameters << "-v" if @verbose
33
+ parameters << @commands
34
+ @logger.debug "PLink Parameters" + parameters.join(" ")
35
+ return parameters
36
+ end
37
+
38
+ def build_parameter(param_name, param_value)
39
+ "-#{param_name} #{param_value}"
40
+ end
41
+
42
+ def check_command
43
+ return true if @command
44
+ fail_with_message 'Plink.path_to_command cannot be nil.'
45
+ return false
46
+ end
47
+ end
@@ -1,62 +1,62 @@
1
- require 'albacore/albacoretask'
2
- require 'albacore/config/specflowreportconfig'
3
-
4
- class SpecFlowReport
5
- include Albacore::Task
6
- include Albacore::RunCommand
7
- include Configuration::SpecFlowReport
8
-
9
- attr_array :projects, :options, :report
10
-
11
- def initialize(command=nil, report=nil)
12
- @options=[]
13
- @projects =[]
14
- super()
15
- update_attributes specflowreport.to_hash
16
- @command = command unless command.nil?
17
- @report = report unless command.nil?
18
- end
19
-
20
- def get_command_line
21
- command_params = []
22
- command_params << @command
23
- command_params << get_command_parameters
24
- commandline = command_params.join(" ")
25
- @logger.debug "Build SpecFlow Command Line: " + commandline
26
- commandline
27
- end
28
-
29
- def get_projects
30
- if @projects.empty? then
31
- failure_message = "SpecFlow Expects at list one project file"
32
- @logger.debug failure_message
33
- fail_with_message failure_message
34
- else
35
- @projects.map{|asm| "\"#{asm}\""}.join(' ')
36
- end
37
- end
38
-
39
- def get_options
40
- if @options.empty? then
41
- "/xmlTestResult:TestResult.xml /out:specs.html"
42
- else
43
- @options.join(" ")
44
- end
45
- end
46
-
47
- def get_command_parameters
48
- command_params = []
49
- command_params << @report
50
- command_params << get_projects
51
- command_params << get_options
52
- command_params
53
- end
54
-
55
- def execute()
56
- command_params = get_command_parameters
57
- result = run_command "specflow.exe", command_params.join(" ")
58
-
59
- failure_message = 'SpecFlow Failed. See Build Log For Detail. ' + command_params.join(" ")
60
- fail_with_message failure_message if !result
61
- end
62
- end
1
+ require 'albacore/albacoretask'
2
+ require 'albacore/config/specflowreportconfig'
3
+
4
+ class SpecFlowReport
5
+ include Albacore::Task
6
+ include Albacore::RunCommand
7
+ include Configuration::SpecFlowReport
8
+
9
+ attr_array :projects, :options, :report
10
+
11
+ def initialize(command=nil, report=nil)
12
+ @options=[]
13
+ @projects =[]
14
+ super()
15
+ update_attributes specflowreport.to_hash
16
+ @command = command unless command.nil?
17
+ @report = report unless command.nil?
18
+ end
19
+
20
+ def get_command_line
21
+ command_params = []
22
+ command_params << @command
23
+ command_params << get_command_parameters
24
+ commandline = command_params.join(" ")
25
+ @logger.debug "Build SpecFlow Command Line: " + commandline
26
+ commandline
27
+ end
28
+
29
+ def get_projects
30
+ if @projects.empty? then
31
+ failure_message = "SpecFlow Expects at list one project file"
32
+ @logger.debug failure_message
33
+ fail_with_message failure_message
34
+ else
35
+ @projects.map{|asm| "\"#{asm}\""}.join(' ')
36
+ end
37
+ end
38
+
39
+ def get_options
40
+ if @options.empty? then
41
+ "/xmlTestResult:TestResult.xml /out:specs.html"
42
+ else
43
+ @options.join(" ")
44
+ end
45
+ end
46
+
47
+ def get_command_parameters
48
+ command_params = []
49
+ command_params << @report
50
+ command_params << get_projects
51
+ command_params << get_options
52
+ command_params
53
+ end
54
+
55
+ def execute()
56
+ command_params = get_command_parameters
57
+ result = run_command "specflow.exe", command_params.join(" ")
58
+
59
+ failure_message = 'SpecFlow Failed. See Build Log For Detail. ' + command_params.join(" ")
60
+ fail_with_message failure_message if !result
61
+ end
62
+ end
@@ -1,80 +1,80 @@
1
- require 'albacore/albacoretask'
2
-
3
- class SQLCmd
4
- include Albacore::Task
5
- include Albacore::RunCommand
6
-
7
- attr_accessor :server, :database, :username, :password, :trusted_connection, :batch_abort, :severity
8
- attr_array :scripts
9
- attr_hash :variables
10
-
11
- def initialize
12
- @require_valid_command = false
13
- @scripts=[]
14
- @variables={}
15
- @trusted_connection = true
16
- @batch_abort = true
17
- @severity = nil
18
- super()
19
- update_attributes Albacore.configuration.sqlcmd.to_hash
20
- end
21
-
22
- def execute
23
- return unless check_command
24
-
25
- cmd_params=[]
26
- serverParam = @server.nil? ? build_parameter("S", ".") : build_parameter("S", @server)
27
- cmd_params << serverParam
28
- cmd_params << build_parameter("d", @database) unless @database.nil?
29
- cmd_params << get_authentication_params
30
- cmd_params << build_variable_list if @variables.length > 0
31
- cmd_params << get_batch_abort_param
32
- cmd_params << build_script_list if @scripts.length > 0
33
- cmd_params << build_parameter("V", @severity) unless @severity.nil?
34
-
35
- result = run_command "SQLCmd", cmd_params.join(" ")
36
-
37
- failure_msg = 'SQLCmd Failed. See Build Log For Detail.'
38
- fail_with_message failure_msg if !result
39
- end
40
-
41
- def get_batch_abort_param
42
- "-b" if (@scripts.length > 1 && @batch_abort)
43
- end
44
-
45
- def get_authentication_params
46
- integratedParam = "-E" if @trusted_connection
47
- if ((!(@username.nil?)) and (!(@password.nil?)))
48
- integratedParam = build_parameter("U", @username) + " " + build_parameter("P", @password)
49
- end
50
- integratedParam
51
- end
52
-
53
- def check_command
54
- sql2008cmdPath = File.join(ENV['SystemDrive'],'program files','microsoft sql server','100','tools','binn', 'sqlcmd.exe')
55
- sql2005cmdPath = File.join(ENV['SystemDrive'],'program files','microsoft sql server','90','tools','binn', 'sqlcmd.exe')
56
- sql2008cmdPathx86 = File.join(ENV['SystemDrive'],'program files (x86)','microsoft sql server','100','tools','binn', 'sqlcmd.exe')
57
- sql2005cmdPathx86 = File.join(ENV['SystemDrive'],'program files (x86)','microsoft sql server','90','tools','binn', 'sqlcmd.exe')
58
- @command = [sql2008cmdPath, sql2005cmdPath, sql2008cmdPathx86, sql2005cmdPathx86].select { |p| File.exist?(p) }.first
59
- return true if @command != nil
60
- fail_with_message 'SQLCmd.command cannot be nil.'
61
- return false
62
- end
63
-
64
- def build_script_list
65
- @scripts.map{|s| "-i \"#{s.strip}\""}.join(" ")
66
- end
67
-
68
- def build_parameter(param_name, param_value)
69
- "-#{param_name} \"#{param_value}\""
70
- end
71
-
72
- def build_variable_list
73
- vars = []
74
- @variables.each do |k,v|
75
- vars << "-v #{k}=#{v}"
76
- end
77
- vars.join(" ")
78
- end
79
-
80
- end
1
+ require 'albacore/albacoretask'
2
+
3
+ class SQLCmd
4
+ include Albacore::Task
5
+ include Albacore::RunCommand
6
+
7
+ attr_accessor :server, :database, :username, :password, :trusted_connection, :batch_abort, :severity
8
+ attr_array :scripts
9
+ attr_hash :variables
10
+
11
+ def initialize
12
+ @require_valid_command = false
13
+ @scripts=[]
14
+ @variables={}
15
+ @trusted_connection = true
16
+ @batch_abort = true
17
+ @severity = nil
18
+ super()
19
+ update_attributes Albacore.configuration.sqlcmd.to_hash
20
+ end
21
+
22
+ def execute
23
+ return unless check_command
24
+
25
+ cmd_params=[]
26
+ serverParam = @server.nil? ? build_parameter("S", ".") : build_parameter("S", @server)
27
+ cmd_params << serverParam
28
+ cmd_params << build_parameter("d", @database) unless @database.nil?
29
+ cmd_params << get_authentication_params
30
+ cmd_params << build_variable_list if @variables.length > 0
31
+ cmd_params << get_batch_abort_param
32
+ cmd_params << build_script_list if @scripts.length > 0
33
+ cmd_params << build_parameter("V", @severity) unless @severity.nil?
34
+
35
+ result = run_command "SQLCmd", cmd_params.join(" ")
36
+
37
+ failure_msg = 'SQLCmd Failed. See Build Log For Detail.'
38
+ fail_with_message failure_msg if !result
39
+ end
40
+
41
+ def get_batch_abort_param
42
+ "-b" if (@scripts.length > 1 && @batch_abort)
43
+ end
44
+
45
+ def get_authentication_params
46
+ integratedParam = "-E" if @trusted_connection
47
+ if ((!(@username.nil?)) and (!(@password.nil?)))
48
+ integratedParam = build_parameter("U", @username) + " " + build_parameter("P", @password)
49
+ end
50
+ integratedParam
51
+ end
52
+
53
+ def check_command
54
+ sql2008cmdPath = File.join(ENV['SystemDrive'],'program files','microsoft sql server','100','tools','binn', 'sqlcmd.exe')
55
+ sql2005cmdPath = File.join(ENV['SystemDrive'],'program files','microsoft sql server','90','tools','binn', 'sqlcmd.exe')
56
+ sql2008cmdPathx86 = File.join(ENV['SystemDrive'],'program files (x86)','microsoft sql server','100','tools','binn', 'sqlcmd.exe')
57
+ sql2005cmdPathx86 = File.join(ENV['SystemDrive'],'program files (x86)','microsoft sql server','90','tools','binn', 'sqlcmd.exe')
58
+ @command = [sql2008cmdPath, sql2005cmdPath, sql2008cmdPathx86, sql2005cmdPathx86].select { |p| File.exist?(p) }.first
59
+ return true if @command != nil
60
+ fail_with_message 'SQLCmd.command cannot be nil.'
61
+ return false
62
+ end
63
+
64
+ def build_script_list
65
+ @scripts.map{|s| "-i \"#{s.strip}\""}.join(" ")
66
+ end
67
+
68
+ def build_parameter(param_name, param_value)
69
+ "-#{param_name} \"#{param_value}\""
70
+ end
71
+
72
+ def build_variable_list
73
+ vars = []
74
+ @variables.each do |k,v|
75
+ vars << "-v #{k}=#{v}"
76
+ end
77
+ vars.join(" ")
78
+ end
79
+
80
+ end