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,18 +1,18 @@
1
- require 'yaml'
2
-
3
- module YAMLConfig
4
- def initialize
5
- super()
6
- end
7
-
8
- def load_config_by_task_name(task_name)
9
- task_config = "#{task_name}.yml"
10
- task_config = File.join(Albacore.configure.yaml_config_folder, task_config) unless Albacore.configure.yaml_config_folder.nil?
11
- configure(task_config) if File.exists?(task_config)
12
- end
13
-
14
- def configure(yml_file)
15
- config = YAML::load(File.open(yml_file))
16
- update_attributes config
17
- end
18
- end
1
+ require 'yaml'
2
+
3
+ module YAMLConfig
4
+ def initialize
5
+ super()
6
+ end
7
+
8
+ def load_config_by_task_name(task_name)
9
+ task_config = "#{task_name}.yml"
10
+ task_config = File.join(Albacore.configure.yaml_config_folder, task_config) unless Albacore.configure.yaml_config_folder.nil?
11
+ configure(task_config) if File.exists?(task_config)
12
+ end
13
+
14
+ def configure(yml_file)
15
+ config = YAML::load(File.open(yml_file))
16
+ update_attributes config
17
+ end
18
+ end
@@ -1,28 +1,28 @@
1
- require 'albacore/albacoretask'
2
- require 'zip/zip'
3
- require 'zip/zipfilesystem'
4
- include Zip
5
-
6
- class Unzip
7
- include Albacore::Task
8
-
9
- attr_accessor :destination, :file
10
-
11
- def initialize
12
- super()
13
- update_attributes Albacore.configuration.unzip.to_hash
14
- end
15
-
16
- def execute()
17
- fail_with_message 'Zip File cannot be empty' if @file.nil?
18
- return if @file.nil?
19
-
20
- Zip::ZipFile.open(@file) do |zip_f|
21
- zip_f.each do |f|
22
- out_path = File.join(@destination, f.name)
23
- FileUtils.mkdir_p(File.dirname(out_path))
24
- zip_f.extract(f, out_path) unless File.exist?(out_path)
25
- end
26
- end
27
- end
28
- end
1
+ require 'albacore/albacoretask'
2
+ require 'zip/zip'
3
+ require 'zip/zipfilesystem'
4
+ include Zip
5
+
6
+ class Unzip
7
+ include Albacore::Task
8
+
9
+ attr_accessor :destination, :file
10
+
11
+ def initialize
12
+ super()
13
+ update_attributes Albacore.configuration.unzip.to_hash
14
+ end
15
+
16
+ def execute()
17
+ fail_with_message 'Zip File cannot be empty' if @file.nil?
18
+ return if @file.nil?
19
+
20
+ Zip::ZipFile.open(@file) do |zip_f|
21
+ zip_f.each do |f|
22
+ out_path = File.join(@destination, f.name)
23
+ FileUtils.mkdir_p(File.dirname(out_path))
24
+ zip_f.extract(f, out_path) unless File.exist?(out_path)
25
+ end
26
+ end
27
+ end
28
+ end
@@ -0,0 +1,44 @@
1
+ require 'albacore/albacoretask'
2
+
3
+ class VssGet
4
+ TaskName = :vssget
5
+ include Albacore::Task
6
+ include Albacore::RunCommand
7
+
8
+ attr_accessor :repository, :project, :path, :username, :password, :recursive, :readonly, :quite
9
+ attr_array :options
10
+
11
+ def initialize(command=nil)
12
+ @options=[]
13
+ @quite = true
14
+ @readonly = true
15
+ @recursive = true
16
+ super()
17
+ update_attributes Albacore.configuration.vss.to_hash
18
+ @command = command unless command.nil?
19
+ end
20
+
21
+ def get_command_parameters
22
+ command_params = []
23
+ command_params << "get"
24
+ command_params << @project || "$/"
25
+ command_params << "-Q" if @quite
26
+ command_params << "-R" if @recursive
27
+ command_params << (@readonly ? "-W-" : "-W")
28
+ command_params << "-Y#{@username},#{@password}" unless @username.nil?
29
+ command_params << "\"-GL#{@path}\"" unless @path.nil?
30
+ command_params << @options.join(" ") unless @options.nil?
31
+ command_params
32
+ end
33
+
34
+ def execute()
35
+ fail_with_message 'Repository should be provided.' if @repository.nil?
36
+
37
+ ENV["SSDIR"] = @repository
38
+
39
+ result = run_command "VssGet", get_command_parameters
40
+
41
+ failure_message = 'Visual SourceSafe Failed. See Build Log For Detail'
42
+ fail_with_message failure_message if !result
43
+ end
44
+ end
@@ -1,54 +1,54 @@
1
- require 'albacore/albacoretask'
2
-
3
- class XBuild
4
- TaskName = [:xbuild, :mono]
5
- include Albacore::Task
6
- include Albacore::RunCommand
7
-
8
- attr_accessor :solution, :verbosity
9
- attr_array :targets
10
- attr_hash :properties
11
-
12
- def initialize
13
- @command = 'xbuild'
14
- super()
15
- update_attributes Albacore.configuration.xbuild.to_hash
16
- end
17
-
18
- def execute
19
- build_solution(@solution)
20
- end
21
-
22
- def build_solution(solution)
23
- check_solution solution
24
-
25
- command_parameters = []
26
- command_parameters << "\"#{solution}\""
27
- command_parameters << "\"/verbosity:#{@verbosity}\"" if @verbosity != nil
28
- command_parameters << build_properties if @properties != nil
29
- command_parameters << "\"/target:#{build_targets}\"" if @targets != nil
30
-
31
- result = run_command "xBuild", command_parameters.join(" ")
32
-
33
- failure_message = 'xBuild Failed. See Build Log For Detail'
34
- fail_with_message failure_message if !result
35
- end
36
-
37
- def check_solution(file)
38
- return if file
39
- msg = 'solution cannot be nil'
40
- fail_with_message msg
41
- end
42
-
43
- def build_targets
44
- @targets.join ";"
45
- end
46
-
47
- def build_properties
48
- option_text = []
49
- @properties.each do |key, value|
50
- option_text << "/p:#{key}\=\"#{value}\""
51
- end
52
- option_text.join(" ")
53
- end
54
- end
1
+ require 'albacore/albacoretask'
2
+
3
+ class XBuild
4
+ TaskName = [:xbuild, :mono]
5
+ include Albacore::Task
6
+ include Albacore::RunCommand
7
+
8
+ attr_accessor :solution, :verbosity
9
+ attr_array :targets
10
+ attr_hash :properties
11
+
12
+ def initialize
13
+ @command = 'xbuild'
14
+ super()
15
+ update_attributes Albacore.configuration.xbuild.to_hash
16
+ end
17
+
18
+ def execute
19
+ build_solution(@solution)
20
+ end
21
+
22
+ def build_solution(solution)
23
+ check_solution solution
24
+
25
+ command_parameters = []
26
+ command_parameters << "\"#{solution}\""
27
+ command_parameters << "\"/verbosity:#{@verbosity}\"" if @verbosity != nil
28
+ command_parameters << build_properties if @properties != nil
29
+ command_parameters << "\"/target:#{build_targets}\"" if @targets != nil
30
+
31
+ result = run_command "xBuild", command_parameters.join(" ")
32
+
33
+ failure_message = 'xBuild Failed. See Build Log For Detail'
34
+ fail_with_message failure_message if !result
35
+ end
36
+
37
+ def check_solution(file)
38
+ return if file
39
+ msg = 'solution cannot be nil'
40
+ fail_with_message msg
41
+ end
42
+
43
+ def build_targets
44
+ @targets.join ";"
45
+ end
46
+
47
+ def build_properties
48
+ option_text = []
49
+ @properties.each do |key, value|
50
+ option_text << "/p:#{key}\=\"#{value}\""
51
+ end
52
+ option_text.join(" ")
53
+ end
54
+ end
@@ -1,52 +1,52 @@
1
- require 'albacore/albacoretask'
2
-
3
- class XUnitTestRunner
4
- TaskName = :xunit
5
- include Albacore::Task
6
- include Albacore::RunCommand
7
-
8
- attr_accessor :html_output
9
- attr_array :options,:assembly,:assemblies
10
-
11
- def initialize(command=nil)
12
- @options=[]
13
- super()
14
- update_attributes Albacore.configuration.xunit.to_hash
15
- @command = command unless command.nil?
16
- end
17
-
18
- def get_command_line
19
- command_params = []
20
- command_params << @command
21
- command_params << get_command_parameters
22
- commandline = command_params.join(" ")
23
- @logger.debug "Build XUnit Test Runner Command Line: " + commandline
24
- commandline
25
- end
26
-
27
- def get_command_parameters
28
- command_params = []
29
- command_params << @options.join(" ") unless @options.nil?
30
- command_params << build_html_output unless @html_output.nil?
31
- command_params
32
- end
33
-
34
- def execute()
35
- @assemblies = [] if @assemblies.nil?
36
- @assemblies << @assembly unless @assembly.nil?
37
- fail_with_message 'At least one assembly is required for assemblies attr' if @assemblies.length==0
38
- failure_message = 'XUnit Failed. See Build Log For Detail'
39
-
40
- @assemblies.each do |assm|
41
- command_params = get_command_parameters.collect{ |p| p % File.basename(assm) }
42
- command_params.insert(0,assm)
43
- result = run_command "XUnit", command_params.join(" ")
44
- fail_with_message failure_message if !result
45
- end
46
- end
47
-
48
- def build_html_output
49
- fail_with_message 'Directory is required for html_output' if !File.directory?(File.expand_path(@html_output))
50
- "/html \"#{File.join(File.expand_path(@html_output),"%s.html")}\""
51
- end
52
- end
1
+ require 'albacore/albacoretask'
2
+
3
+ class XUnitTestRunner
4
+ TaskName = :xunit
5
+ include Albacore::Task
6
+ include Albacore::RunCommand
7
+
8
+ attr_accessor :html_output, :skip_test_fail
9
+ attr_array :options,:assembly,:assemblies
10
+
11
+ def initialize(command=nil)
12
+ @options=[]
13
+ super()
14
+ update_attributes Albacore.configuration.xunit.to_hash
15
+ @command = command unless command.nil?
16
+ end
17
+
18
+ def get_command_line
19
+ command_params = []
20
+ command_params << @command
21
+ command_params << get_command_parameters
22
+ commandline = command_params.join(" ")
23
+ @logger.debug "Build XUnit Test Runner Command Line: " + commandline
24
+ commandline
25
+ end
26
+
27
+ def get_command_parameters
28
+ command_params = []
29
+ command_params << @options.join(" ") unless @options.nil?
30
+ command_params << build_html_output unless @html_output.nil?
31
+ command_params
32
+ end
33
+
34
+ def execute()
35
+ @assemblies = [] if @assemblies.nil?
36
+ @assemblies << @assembly unless @assembly.nil?
37
+ fail_with_message 'At least one assembly is required for assemblies attr' if @assemblies.length==0
38
+ failure_message = 'XUnit Failed. See Build Log For Detail'
39
+
40
+ @assemblies.each do |assm|
41
+ command_params = get_command_parameters.collect{ |p| p % File.basename(assm) }
42
+ command_params.insert(0,assm)
43
+ result = run_command "XUnit", command_params.join(" ")
44
+ fail_with_message failure_message if !result && (!@skip_test_fail || $?.exitstatus > 1)
45
+ end
46
+ end
47
+
48
+ def build_html_output
49
+ fail_with_message 'Directory is required for html_output' if !File.directory?(File.expand_path(@html_output))
50
+ "/html \"#{File.join(File.expand_path(@html_output),"%s.html")}\""
51
+ end
52
+ end
@@ -1,105 +1,105 @@
1
- require 'albacore/albacoretask'
2
- require 'zip/zip'
3
- require 'zip/zipfilesystem'
4
- include Zip
5
-
6
- class ZipDirectory
7
- TaskName = :zip
8
- include Albacore::Task
9
-
10
- attr_accessor :output_path, :output_file
11
- attr_accessor :flatten_zip
12
- attr_array :directories_to_zip, :additional_files, :exclusions
13
-
14
- def initialize
15
- @flatten_zip = true
16
- @exclusions = []
17
- super()
18
- update_attributes Albacore.configuration.zip.to_hash
19
- end
20
-
21
- def execute()
22
- fail_with_message 'Output File cannot be empty' if @output_file.nil?
23
- return if @output_file.nil?
24
-
25
- clean_directories_names
26
- remove zip_name
27
-
28
- ZipFile.open(zip_name, 'w') do |zipfile|
29
- zip_directory(zipfile)
30
- zip_additional(zipfile)
31
- end
32
- end
33
-
34
- def clean_directories_names
35
- return if @directories_to_zip.nil?
36
- @directories_to_zip.each { |d| d.sub!(%r[/$],'')}
37
- end
38
-
39
- def remove(filename)
40
- FileUtils.rm filename, :force=>true
41
- end
42
-
43
- def reject_file(f)
44
- f == zip_name || is_excluded(f)
45
- end
46
-
47
- def is_excluded(f)
48
- expanded_exclusions.any? do |e|
49
- return true if e.respond_to? '~' and f =~ e
50
- e == f
51
- end
52
- end
53
-
54
- def expanded_exclusions
55
- return @expanded_exclusions unless @expanded_exclusions.nil?
56
-
57
- regexp_exclusions, string_exclusions = @exclusions.partition {|x| x.respond_to? '~' }
58
- @expanded_exclusions = [].concat(regexp_exclusions)
59
-
60
- @directories_to_zip.each do |dir|
61
- Dir.chdir(dir) do
62
- string_exclusions.each do |ex|
63
- exclusions = Dir.glob(ex)
64
- exclusions = exclusions.map {|x| File.join(dir, x) } unless exclusions[0] == ex
65
- exclusions << ex if exclusions.empty?
66
- @expanded_exclusions += exclusions
67
- end
68
- end
69
- end
70
-
71
- @expanded_exclusions
72
- end
73
-
74
- def zip_name()
75
- @output_path = set_output_path
76
- File.join(@output_path, @output_file)
77
- end
78
-
79
- def set_output_path()
80
- path = ''
81
- path = @directories_to_zip.first unless @directories_to_zip.nil?
82
- path = @output_path unless @output_path.nil?
83
- return path
84
- end
85
-
86
-
87
- def zip_directory(zipfile)
88
- return if @directories_to_zip.nil?
89
- @directories_to_zip.each do |d|
90
- Dir["#{d}/**/**"].reject{|f| reject_file(f)}.each do |file_path|
91
- file_name = file_path
92
- file_name = file_path.sub(d + '/','') if @flatten_zip
93
- zipfile.add(file_name, file_path)
94
- end
95
- end
96
- end
97
-
98
- def zip_additional(zipfile)
99
- return if @additional_files.nil?
100
- @additional_files.reject{|f| reject_file(f)}.each do |file_path|
101
- file_name = file_path.split('/').last if @flatten_zip
102
- zipfile.add(file_name, file_path)
103
- end
104
- end
105
- end
1
+ require 'albacore/albacoretask'
2
+ require 'zip/zip'
3
+ require 'zip/zipfilesystem'
4
+ include Zip
5
+
6
+ class ZipDirectory
7
+ TaskName = :zip
8
+ include Albacore::Task
9
+
10
+ attr_accessor :output_path, :output_file
11
+ attr_accessor :flatten_zip
12
+ attr_array :directories_to_zip, :additional_files, :exclusions
13
+
14
+ def initialize
15
+ @flatten_zip = true
16
+ @exclusions = []
17
+ super()
18
+ update_attributes Albacore.configuration.zip.to_hash
19
+ end
20
+
21
+ def execute()
22
+ fail_with_message 'Output File cannot be empty' if @output_file.nil?
23
+ return if @output_file.nil?
24
+
25
+ clean_directories_names
26
+ remove zip_name
27
+
28
+ ZipFile.open(zip_name, 'w') do |zipfile|
29
+ zip_directory(zipfile)
30
+ zip_additional(zipfile)
31
+ end
32
+ end
33
+
34
+ def clean_directories_names
35
+ return if @directories_to_zip.nil?
36
+ @directories_to_zip.each { |d| d.sub!(%r[/$],'')}
37
+ end
38
+
39
+ def remove(filename)
40
+ FileUtils.rm filename, :force=>true
41
+ end
42
+
43
+ def reject_file(f)
44
+ f == zip_name || is_excluded(f)
45
+ end
46
+
47
+ def is_excluded(f)
48
+ expanded_exclusions.any? do |e|
49
+ return true if e.respond_to? '~' and f =~ e
50
+ e == f
51
+ end
52
+ end
53
+
54
+ def expanded_exclusions
55
+ return @expanded_exclusions unless @expanded_exclusions.nil?
56
+
57
+ regexp_exclusions, string_exclusions = @exclusions.partition {|x| x.respond_to? '~' }
58
+ @expanded_exclusions = [].concat(regexp_exclusions)
59
+
60
+ @directories_to_zip.each do |dir|
61
+ Dir.chdir(dir) do
62
+ string_exclusions.each do |ex|
63
+ exclusions = Dir.glob(ex)
64
+ exclusions = exclusions.map {|x| File.join(dir, x) } unless exclusions[0] == ex
65
+ exclusions << ex if exclusions.empty?
66
+ @expanded_exclusions += exclusions
67
+ end
68
+ end
69
+ end
70
+
71
+ @expanded_exclusions
72
+ end
73
+
74
+ def zip_name()
75
+ @output_path = set_output_path
76
+ File.join(@output_path, @output_file)
77
+ end
78
+
79
+ def set_output_path()
80
+ path = ''
81
+ path = @directories_to_zip.first unless @directories_to_zip.nil?
82
+ path = @output_path unless @output_path.nil?
83
+ return path
84
+ end
85
+
86
+
87
+ def zip_directory(zipfile)
88
+ return if @directories_to_zip.nil?
89
+ @directories_to_zip.each do |d|
90
+ Dir["#{d}/**/**"].reject{|f| reject_file(f)}.each do |file_path|
91
+ file_name = file_path
92
+ file_name = file_path.sub(d + '/','') if @flatten_zip
93
+ zipfile.add(file_name, file_path)
94
+ end
95
+ end
96
+ end
97
+
98
+ def zip_additional(zipfile)
99
+ return if @additional_files.nil?
100
+ @additional_files.reject{|f| reject_file(f)}.each do |file_path|
101
+ file_name = file_path.split('/').last if @flatten_zip
102
+ zipfile.add(file_name, file_path)
103
+ end
104
+ end
105
+ end