sprout 1.0.32.pre → 1.0.35.pre

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of sprout might be problematic. Click here for more details.

Files changed (208) hide show
  1. data/Gemfile +2 -1
  2. data/Gemfile.lock +4 -2
  3. data/README.textile +12 -13
  4. data/VERSION +1 -0
  5. data/doc/Dir.html +288 -0
  6. data/doc/Rake/Task.html +184 -0
  7. data/doc/Sprout.html +144 -0
  8. data/doc/Sprout/ArchiveUnpacker.html +1246 -0
  9. data/doc/Sprout/Base.html +126 -0
  10. data/doc/Sprout/Base/ClassMethods.html +434 -0
  11. data/doc/Sprout/Concern.html +353 -0
  12. data/doc/Sprout/Daemon.html +166 -0
  13. data/doc/Sprout/Daemon/ClassMethods.html +244 -0
  14. data/doc/Sprout/Daemon/InstanceMethods.html +601 -0
  15. data/doc/Sprout/Errors.html +101 -0
  16. data/doc/Sprout/Errors/ArchiveUnpackerError.html +125 -0
  17. data/doc/Sprout/Errors/DestinationExistsError.html +133 -0
  18. data/doc/Sprout/Errors/DuplicateMemberError.html +132 -0
  19. data/doc/Sprout/Errors/ExecutableError.html +125 -0
  20. data/doc/Sprout/Errors/ExecutableRegistrationError.html +132 -0
  21. data/doc/Sprout/Errors/ExecutionError.html +121 -0
  22. data/doc/Sprout/Errors/GeneratorError.html +125 -0
  23. data/doc/Sprout/Errors/InvalidArgumentError.html +132 -0
  24. data/doc/Sprout/Errors/LoadError.html +121 -0
  25. data/doc/Sprout/Errors/MissingArgumentError.html +132 -0
  26. data/doc/Sprout/Errors/MissingExecutableError.html +132 -0
  27. data/doc/Sprout/Errors/MissingGeneratorError.html +132 -0
  28. data/doc/Sprout/Errors/MissingTemplateError.html +132 -0
  29. data/doc/Sprout/Errors/ProcessRunnerError.html +121 -0
  30. data/doc/Sprout/Errors/RemoteFileLoaderError.html +110 -0
  31. data/doc/Sprout/Errors/SproutError.html +114 -0
  32. data/doc/Sprout/Errors/UnknownArchiveType.html +122 -0
  33. data/doc/Sprout/Errors/UsageError.html +121 -0
  34. data/doc/Sprout/Errors/ValidationError.html +121 -0
  35. data/doc/Sprout/Errors/VersionRequirementNotMetError.html +121 -0
  36. data/doc/Sprout/Executable.html +173 -0
  37. data/doc/Sprout/Executable/Boolean.html +483 -0
  38. data/doc/Sprout/Executable/ClassMethods.html +417 -0
  39. data/doc/Sprout/Executable/CollectionParam.html +483 -0
  40. data/doc/Sprout/Executable/FileParam.html +484 -0
  41. data/doc/Sprout/Executable/Files.html +292 -0
  42. data/doc/Sprout/Executable/InstanceMethods.html +2006 -0
  43. data/doc/Sprout/Executable/Number.html +141 -0
  44. data/doc/Sprout/Executable/Param.html +2818 -0
  45. data/doc/Sprout/Executable/ParameterFactory.html +232 -0
  46. data/doc/Sprout/Executable/Path.html +223 -0
  47. data/doc/Sprout/Executable/Paths.html +253 -0
  48. data/doc/Sprout/Executable/StringParam.html +213 -0
  49. data/doc/Sprout/Executable/Strings.html +167 -0
  50. data/doc/Sprout/Executable/Url.html +160 -0
  51. data/doc/Sprout/Executable/Urls.html +170 -0
  52. data/doc/Sprout/FileTarget.html +1109 -0
  53. data/doc/Sprout/Generator.html +689 -0
  54. data/doc/Sprout/Generator/Base.html +1626 -0
  55. data/doc/Sprout/Generator/Command.html +690 -0
  56. data/doc/Sprout/Generator/DirectoryManifest.html +476 -0
  57. data/doc/Sprout/Generator/FileManifest.html +572 -0
  58. data/doc/Sprout/Generator/Manifest.html +377 -0
  59. data/doc/Sprout/Generator/TemplateManifest.html +196 -0
  60. data/doc/Sprout/GeneratorGenerator.html +1018 -0
  61. data/doc/Sprout/Library.html +1141 -0
  62. data/doc/Sprout/LibraryGenerator.html +309 -0
  63. data/doc/Sprout/Log.html +496 -0
  64. data/doc/Sprout/MXMLC.html +6373 -0
  65. data/doc/Sprout/Platform.html +714 -0
  66. data/doc/Sprout/ProcessRunner.html +1352 -0
  67. data/doc/Sprout/ProgressBar.html +376 -0
  68. data/doc/Sprout/ProgressBarImpl.html +2119 -0
  69. data/doc/Sprout/ProgressBarManager.html +434 -0
  70. data/doc/Sprout/ProgressBarOutputStream.html +416 -0
  71. data/doc/Sprout/RDocParser.html +211 -0
  72. data/doc/Sprout/RemoteFileLoader.html +172 -0
  73. data/doc/Sprout/RemoteFileTarget.html +679 -0
  74. data/doc/Sprout/ReversedProgressBar.html +194 -0
  75. data/doc/Sprout/RubyFeature.html +155 -0
  76. data/doc/Sprout/RubyFeature/ClassMethods.html +1065 -0
  77. data/doc/Sprout/RubyGenerator.html +764 -0
  78. data/doc/Sprout/Specification.html +767 -0
  79. data/doc/Sprout/System.html +191 -0
  80. data/doc/Sprout/System/BaseSystem.html +1455 -0
  81. data/doc/Sprout/System/JavaSystem.html +122 -0
  82. data/doc/Sprout/System/OSXSystem.html +335 -0
  83. data/doc/Sprout/System/ThreadMock.html +193 -0
  84. data/doc/Sprout/System/UnixSystem.html +584 -0
  85. data/doc/Sprout/System/VistaSystem.html +251 -0
  86. data/doc/Sprout/System/WinNixSystem.html +325 -0
  87. data/doc/Sprout/System/WinSystem.html +571 -0
  88. data/doc/Sprout/ToolGenerator.html +931 -0
  89. data/doc/Sprout/VERSION.html +128 -0
  90. data/doc/SproutTestCase.html +1412 -0
  91. data/doc/String.html +286 -0
  92. data/doc/_index.html +1035 -0
  93. data/doc/class_list.html +36 -0
  94. data/doc/css/common.css +1 -0
  95. data/doc/css/full_list.css +53 -0
  96. data/doc/css/style.css +310 -0
  97. data/doc/file.README.html +96 -0
  98. data/doc/file.archive_unpacker.html +288 -0
  99. data/doc/file.base.html +208 -0
  100. data/doc/file.base_system.html +278 -0
  101. data/doc/file.boolean.html +135 -0
  102. data/doc/file.collection_param.html +139 -0
  103. data/doc/file.command.html +126 -0
  104. data/doc/file.concern.html +136 -0
  105. data/doc/file.daemon.html +309 -0
  106. data/doc/file.dir.html +76 -0
  107. data/doc/file.directory_manifest.html +122 -0
  108. data/doc/file.errors.html +147 -0
  109. data/doc/file.executable.html +638 -0
  110. data/doc/file.file_manifest.html +109 -0
  111. data/doc/file.file_param.html +120 -0
  112. data/doc/file.file_target.html +140 -0
  113. data/doc/file.files.html +85 -0
  114. data/doc/file.generator.html +296 -0
  115. data/doc/file.generator_class.html +72 -0
  116. data/doc/file.generator_generator.html +137 -0
  117. data/doc/file.generator_test.html +92 -0
  118. data/doc/file.generator_test_helper.html +67 -0
  119. data/doc/file.java_system.html +62 -0
  120. data/doc/file.library.html +291 -0
  121. data/doc/file.library_generator.html +74 -0
  122. data/doc/file.log.html +100 -0
  123. data/doc/file.manifest.html +67 -0
  124. data/doc/file.mxmlc.html +740 -0
  125. data/doc/file.number.html +67 -0
  126. data/doc/file.osx_system.html +79 -0
  127. data/doc/file.param.html +491 -0
  128. data/doc/file.parameter_factory.html +119 -0
  129. data/doc/file.path.html +81 -0
  130. data/doc/file.paths.html +80 -0
  131. data/doc/file.platform.html +124 -0
  132. data/doc/file.process_runner.html +224 -0
  133. data/doc/file.progress_bar.html +390 -0
  134. data/doc/file.rdoc_parser.html +145 -0
  135. data/doc/file.remote_file_loader.html +117 -0
  136. data/doc/file.remote_file_target.html +176 -0
  137. data/doc/file.ruby_base.html +64 -0
  138. data/doc/file.ruby_feature.html +244 -0
  139. data/doc/file.ruby_generator.html +118 -0
  140. data/doc/file.ruby_input.html +62 -0
  141. data/doc/file.ruby_test_case.html +78 -0
  142. data/doc/file.ruby_test_helper.html +61 -0
  143. data/doc/file.specification.html +248 -0
  144. data/doc/file.sprout.html +64 -0
  145. data/doc/file.sprout_test_case.html +280 -0
  146. data/doc/file.string.html +72 -0
  147. data/doc/file.string_param.html +76 -0
  148. data/doc/file.strings.html +71 -0
  149. data/doc/file.system.html +86 -0
  150. data/doc/file.template_manifest.html +67 -0
  151. data/doc/file.tool.html +92 -0
  152. data/doc/file.tool_generator.html +90 -0
  153. data/doc/file.unix_system.html +128 -0
  154. data/doc/file.url.html +71 -0
  155. data/doc/file.urls.html +70 -0
  156. data/doc/file.version.html +71 -0
  157. data/doc/file.vista_system.html +69 -0
  158. data/doc/file.win_nix_system.html +88 -0
  159. data/doc/file.win_system.html +129 -0
  160. data/doc/file_list.html +230 -0
  161. data/doc/frames.html +13 -0
  162. data/doc/index.html +96 -0
  163. data/doc/js/app.js +202 -0
  164. data/doc/js/full_list.js +149 -0
  165. data/doc/js/jquery.js +154 -0
  166. data/doc/method_list.html +3355 -0
  167. data/doc/top-level-namespace.html +192 -0
  168. data/lib/sprout/archive_unpacker.rb +203 -137
  169. data/lib/sprout/base.rb +38 -11
  170. data/lib/sprout/concern.rb +51 -0
  171. data/lib/sprout/daemon.rb +256 -0
  172. data/lib/sprout/executable.rb +40 -11
  173. data/lib/sprout/executable/boolean.rb +47 -1
  174. data/lib/sprout/executable/collection_param.rb +33 -1
  175. data/lib/sprout/executable/file_param.rb +16 -3
  176. data/lib/sprout/executable/files.rb +5 -0
  177. data/lib/sprout/executable/number.rb +5 -1
  178. data/lib/sprout/executable/param.rb +232 -16
  179. data/lib/sprout/executable/parameter_factory.rb +39 -1
  180. data/lib/sprout/executable/path.rb +7 -1
  181. data/lib/sprout/executable/paths.rb +6 -1
  182. data/lib/sprout/executable/string_param.rb +8 -1
  183. data/lib/sprout/executable/strings.rb +7 -1
  184. data/lib/sprout/executable/url.rb +8 -1
  185. data/lib/sprout/executable/urls.rb +7 -1
  186. data/lib/sprout/file_target.rb +11 -11
  187. data/lib/sprout/generator.rb +244 -0
  188. data/lib/sprout/generator/base.rb +0 -94
  189. data/lib/sprout/generators/generator/generator_generator.rb +35 -1
  190. data/lib/sprout/generators/generator/templates/generator_class.rb +3 -3
  191. data/lib/sprout/library.rb +75 -0
  192. data/lib/sprout/log.rb +11 -12
  193. data/lib/sprout/process_runner.rb +29 -9
  194. data/lib/sprout/remote_file_target.rb +20 -9
  195. data/lib/sprout/system/base_system.rb +11 -3
  196. data/lib/sprout/test/sprout_test_case.rb +1 -0
  197. data/lib/sprout/version.rb +7 -11
  198. data/rakefile.rb +7 -12
  199. data/script/add_param_handler.rb +43 -0
  200. data/sprout.gemspec +2 -3
  201. data/test/fixtures/executable/fdb.rb +764 -0
  202. data/test/fixtures/executable/flex3sdk_gem/fdb +60 -0
  203. data/test/fixtures/executable/mxmlc.rb +9 -11
  204. data/test/unit/daemon_test.rb +61 -0
  205. data/test/unit/process_runner_test.rb +21 -0
  206. data/test/unit/remote_file_target_test.rb +45 -11
  207. data/test/unit/sprout_test_helper.rb +1 -1
  208. metadata +210 -29
@@ -0,0 +1,192 @@
1
+ <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
2
+ "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
3
+ <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
4
+ <head>
5
+ <meta name="Content-Type" content="text/html; charset=utf-8" />
6
+ <title>Top Level Namespace</title>
7
+ <link rel="stylesheet" href="css/style.css" type="text/css" media="screen" charset="utf-8" />
8
+ <link rel="stylesheet" href="css/common.css" type="text/css" media="screen" charset="utf-8" />
9
+
10
+ <script type="text/javascript" charset="utf-8">
11
+ relpath = '';
12
+ if (relpath != '') relpath += '/';
13
+ </script>
14
+ <script type="text/javascript" charset="utf-8" src="js/jquery.js"></script>
15
+ <script type="text/javascript" charset="utf-8" src="js/app.js"></script>
16
+
17
+ </head>
18
+ <body>
19
+ <script type="text/javascript" charset="utf-8">
20
+ if (window.top.frames.main) document.body.className = 'frames';
21
+ </script>
22
+
23
+ <div id="header">
24
+ <div id="menu">
25
+
26
+ <a href="_index.html">Index</a> &raquo;
27
+
28
+
29
+ <span class="title">Top Level Namespace</span>
30
+
31
+
32
+ <div class="noframes"><span class="title">(</span><a href="." target="_top">no frames</a><span class="title">)</span></div>
33
+ </div>
34
+
35
+ <div id="search">
36
+ <a id="class_list_link" href="#">Class List</a>
37
+ <a id="method_list_link" href="#">Method List</a>
38
+ <a id ="file_list_link" href="#">File List</a>
39
+ </div>
40
+
41
+ <div class="clear"></div>
42
+ </div>
43
+
44
+ <iframe id="search_frame"></iframe>
45
+
46
+ <div id="content"><h1>Top Level Namespace
47
+
48
+
49
+
50
+ </h1>
51
+
52
+ <dl class="box">
53
+
54
+
55
+
56
+
57
+
58
+
59
+
60
+
61
+ </dl>
62
+ <div class="clear"></div>
63
+
64
+ <h2>Defined Under Namespace</h2>
65
+ <p class="children">
66
+
67
+
68
+ <strong class="modules">Modules:</strong> <span class='object_link'><a href="Sprout.html" title="Sprout (module)">Sprout</a></span>, <span class='object_link'><a href="SproutTestCase.html" title="SproutTestCase (module)">SproutTestCase</a></span>
69
+
70
+
71
+
72
+ <strong class="classes">Classes:</strong> <span class='object_link'><a href="Dir.html" title="Dir (class)">Dir</a></span>, <span class='object_link'><a href="String.html" title="String (class)">String</a></span>
73
+
74
+
75
+ </p>
76
+
77
+
78
+
79
+
80
+ <h2>
81
+ Instance Method Summary
82
+ <small>(<a href="#" class="summary_toggle">collapse</a>)</small>
83
+ </h2>
84
+
85
+ <ul class="summary">
86
+
87
+ <li class="public ">
88
+ <span class="summary_signature">
89
+
90
+ <a href="#library-instance_method" title="#library (instance method)">- (Object) <strong>library</strong>(pkg_name, name = nil, version = nil) </a>
91
+
92
+
93
+
94
+ </span>
95
+
96
+
97
+
98
+
99
+
100
+
101
+
102
+
103
+ <span class="summary_desc"><div class='inline'>
104
+ <p>From within a Rakefile, you can load libraries by calling this method:.</p>
105
+ </div></span>
106
+
107
+ </li>
108
+
109
+
110
+ </ul>
111
+
112
+
113
+
114
+
115
+ <div id="instance_method_details" class="method_details_list">
116
+ <h2>Instance Method Details</h2>
117
+
118
+
119
+ <div class="method_details first">
120
+ <p class="signature first" id="library-instance_method">
121
+
122
+ - (<tt>Object</tt>) <strong>library</strong>(pkg_name, name = nil, version = nil)
123
+
124
+
125
+
126
+ </p><div class="docstring">
127
+ <div class="discussion">
128
+
129
+ <p>From within a Rakefile, you can load libraries by calling this method:</p>
130
+
131
+ <pre class="code"><span class='id library'>library</span> <span class='symbol'>:asunit4</span></pre>
132
+
133
+ <p>Or, if you would like to specify which registered library to pull from the
134
+ identified package (by name):</p>
135
+
136
+ <pre class="code"><span class='id library'>library</span> <span class='symbol'>:asunit4</span><span class='comma'>,</span> <span class='symbol'>:src</span></pre>
137
+
138
+ <p>Or, if you'd like to specify version requirements:</p>
139
+
140
+ <pre class="code"><span class='id library'>library</span> <span class='symbol'>:asunit4</span><span class='comma'>,</span> <span class='symbol'>:swc</span><span class='comma'>,</span> <span class='tstring'><span class='tstring_beg'>'</span><span class='tstring_content'>&gt;= 4.2.pre</span><span class='tstring_end'>'</span></span></pre>
141
+
142
+ <p>It's important to note that libraries must also be defined in your Gemfile
143
+ like:</p>
144
+
145
+ <pre class="code"><span class='id gem'>gem</span> <span class='tstring'><span class='tstring_beg'>&quot;</span><span class='tstring_content'>asunit4</span><span class='tstring_end'>&quot;</span></span><span class='comma'>,</span> <span class='tstring'><span class='tstring_beg'>&quot;</span><span class='tstring_content'>&gt;= 4.2.pre</span><span class='tstring_end'>&quot;</span></span></pre>
146
+
147
+ <p>Libraries are generally then added to compiler tasks as Rake dependencies
148
+ like:</p>
149
+
150
+ <pre class="code"><span class='id mxmlc'>mxmlc</span> <span class='tstring'><span class='tstring_beg'>'</span><span class='tstring_content'>bin/SomeRunner.swf</span><span class='tstring_end'>'</span></span> <span class='op'>=&gt;</span> <span class='lbracket'>[</span><span class='symbol'>:asunit4</span><span class='rbracket'>]</span> <span class='kw'>do</span> <span class='op'>|</span><span class='id t'>t</span><span class='op'>|</span>
151
+ <span class='id t'>t</span><span class='period'>.</span><span class='id input'>input</span> <span class='op'>=</span> <span class='tstring'><span class='tstring_beg'>'</span><span class='tstring_content'>src/SomeRunner.as</span><span class='tstring_end'>'</span></span>
152
+ <span class='id t'>t</span><span class='period'>.</span><span class='id source_path'>source_path</span> <span class='op'>&lt;&lt;</span> <span class='tstring'><span class='tstring_beg'>'</span><span class='tstring_content'>test</span><span class='tstring_end'>'</span></span>
153
+ <span class='kw'>end</span></pre>
154
+
155
+
156
+ </div>
157
+ </div>
158
+ <div class="tags">
159
+
160
+ </div><table class="source_code">
161
+ <tr>
162
+ <td>
163
+ <pre class="lines">
164
+
165
+
166
+ 251
167
+ 252
168
+ 253</pre>
169
+ </td>
170
+ <td>
171
+ <pre class="code"><span class="info file"># File 'lib/sprout/library.rb', line 251</span>
172
+
173
+ <span class='kw'>def</span> <span class='id library'>library</span> <span class='id pkg_name'>pkg_name</span><span class='comma'>,</span> <span class='id name'>name</span><span class='op'>=</span><span class='kw'>nil</span><span class='comma'>,</span> <span class='id version'>version</span><span class='op'>=</span><span class='kw'>nil</span>
174
+ <span class='const'>Sprout</span><span class='op'>::</span><span class='const'>Library</span><span class='period'>.</span><span class='id define_task'>define_task</span> <span class='id name'>name</span><span class='comma'>,</span> <span class='id pkg_name'>pkg_name</span><span class='comma'>,</span> <span class='id version'>version</span>
175
+ <span class='kw'>end</span></pre>
176
+ </td>
177
+ </tr>
178
+ </table>
179
+ </div>
180
+
181
+ </div>
182
+
183
+ </div>
184
+
185
+ <div id="footer">
186
+ Generated on Wed Dec 22 11:58:37 2010 by
187
+ <a href="http://yardoc.org" title="Yay! A Ruby Documentation Tool" target="_parent">yard</a>
188
+ 0.6.3 (ruby-1.9.2).
189
+ </div>
190
+
191
+ </body>
192
+ </html>
@@ -1,175 +1,241 @@
1
1
  require 'zip/zip'
2
+ require 'sprout/version'
2
3
  require 'archive/tar/minitar'
3
4
 
4
- module Sprout
5
-
6
- # Given a source, destination and type (or ability to infer it),
7
- # unpack downloaded archives.
8
- class ArchiveUnpacker
9
-
10
- # Figure out what kind of archive you have from the file name,
11
- # and unpack it using the appropriate scheme.
12
- def unpack archive, destination, type=nil, clobber=nil
13
- return unpack_zip(archive, destination, clobber) if is_zip?(archive, type)
14
- return unpack_tgz(archive, destination, clobber) if is_tgz?(archive, type)
15
-
16
- # This is definitely debatable, should we copy the file even if it's
17
- # not an archive that we're about to unpack?
18
- # If so, why would we only do this with some subset of file types?
19
- # Opinions welcome here...
20
- return copy_file(archive, destination, clobber) if is_copyable?(archive)
21
-
22
- raise Sprout::Errors::UnknownArchiveType.new("Unsupported or unknown archive type encountered with: #{archive}")
23
- end
5
+ ##
6
+ # Given a source, destination and archive type (or ability to infer it),
7
+ # unpack the provided archive.
8
+ #
9
+ # unpacker = Sprout::ArchiveUnpacker.new
10
+ # unpacker.unpack "Foo.zip", "unpacked/"
11
+ #
12
+ class Sprout::ArchiveUnpacker
13
+
14
+ ##
15
+ # Unpack the provided +archive+ into the provided +destination+.
16
+ #
17
+ # If a +type+ is not provided, a type will be inferred from the file name suffix.
18
+ #
19
+ # @param archive [File] Path to the archive that will be unpacked (or copied)
20
+ # @param destination [Path] Path to the folder where unpacked files should be placed (or copied).
21
+ # @param type [Symbol] The type of the archive in cases where it can't be inferred
22
+ # from the name. Acceptable values are: :zip, :tgz, :swc, :exe or :rb
23
+ # @param clobber [Boolean] If the destination already contains the expected file(s),
24
+ # the unpacker will not run unless +clobber+ is true.
25
+ # @return [String] path to the unpacked files (usually same as destination).
26
+ # @raise Sprout::Errors::UnknownArchiveType If the archive type cannot be inferred and a valid type is not provided.
27
+ def unpack archive, destination, type=nil, clobber=nil
28
+ return unpack_zip(archive, destination, clobber) if is_zip?(archive, type)
29
+ return unpack_tgz(archive, destination, clobber) if is_tgz?(archive, type)
30
+
31
+ # This is definitely debatable, should we copy the file even if it's
32
+ # not an archive that we're about to unpack?
33
+ # If so, why would we only do this with some subset of file types?
34
+ # Opinions welcome here...
35
+ return copy_file(archive, destination, clobber) if is_copyable?(archive)
36
+
37
+ raise Sprout::Errors::UnknownArchiveType.new("Unsupported or unknown archive type encountered with: #{archive}")
38
+ end
24
39
 
25
- # Unpack zip archives on any platform.
26
- #
27
- # In case you're wondering... Ruby sucks...
28
- # This code corrupts the FlashPlayer executable
29
- # on OSX but if the file is manually unpacked,
30
- # it works fine.
31
- #
32
- def unpack_zip archive, destination, clobber=nil
33
- validate archive, destination
34
-
35
- if is_darwin?
36
- unpack_zip_on_darwin archive, destination, clobber
37
- else
38
- Zip::ZipFile.open archive do |zipfile|
39
- zipfile.each do |entry|
40
- next if entry.name =~ /__MACOSX/ or entry.name =~ /\.DS_Store/
40
+ ##
41
+ # Unpack zip archives on any platform using whatever strategy is most
42
+ # efficient and reliable.
43
+ #
44
+ # @param archive [File] Path to the archive that will be unpacked.
45
+ # @param destination [Path] Path to the folder where unpacked files should be placed.
46
+ # @param clobber [Boolean] If the destination already contains the expected file(s),
47
+ # the unpacker will not run unless +clobber+ is true.
48
+ # @return [File] the file or directory that was created.
49
+ def unpack_zip archive, destination, clobber=nil
50
+ validate archive, destination
51
+
52
+ ##
53
+ # As it turns out, the Rubyzip library corrupts
54
+ # binary files (like the Flash Player) on OSX and is also
55
+ # horribly slow for large archives (like the ~120MB Flex SDK)
56
+ # on all platforms.
57
+ if is_darwin?
58
+ unpack_zip_on_darwin archive, destination, clobber
59
+ else
60
+ Zip::ZipFile.open archive do |zipfile|
61
+ zipfile.each do |entry|
62
+ next if entry.name =~ /__MACOSX/ or entry.name =~ /\.DS_Store/
41
63
  unpack_zip_entry entry, destination, clobber
42
- end
43
64
  end
44
65
  end
45
66
  end
67
+ end
46
68
 
47
- def is_darwin?
48
- Sprout.current_system.is_a?(Sprout::System::OSXSystem)
49
- end
69
+ ##
70
+ # Return true if we're on a Darwin native system (OSX).
71
+ # @return [Boolean]
72
+ def is_darwin?
73
+ Sprout.current_system.is_a?(Sprout::System::OSXSystem)
74
+ end
50
75
 
51
- def unpack_zip_on_darwin archive, destination, clobber
52
- # Unzipping on OS X
53
- FileUtils.makedirs destination
54
- zip_dir = File.expand_path File.dirname(archive)
55
- zip_name = File.basename archive
56
- output = File.expand_path destination
57
- # puts ">> zip_dir: #{zip_dir} zip_name: #{zip_name} output: #{output}"
58
- %x(cd #{zip_dir};unzip #{zip_name} -d #{output})
59
- end
76
+ ##
77
+ # Optimization for zip files on OSX. Uses the native
78
+ # 'unzip' utility which is much faster (and more reliable)
79
+ # than Ruby for large archives (like the Flex SDK) and
80
+ # binaries that Ruby corrupts (like the Flash Player).
81
+ #
82
+ # @return [File] the file or directory that was created.
83
+ def unpack_zip_on_darwin archive, destination, clobber
84
+ # Unzipping on OS X
85
+ FileUtils.makedirs destination
86
+ zip_dir = File.expand_path File.dirname(archive)
87
+ zip_name = File.basename archive
88
+ output = File.expand_path destination
89
+ # puts ">> zip_dir: #{zip_dir} zip_name: #{zip_name} output: #{output}"
90
+ %x(cd #{zip_dir};unzip #{zip_name} -d #{output})
91
+ end
60
92
 
61
- # Unpack tar.gz or .tgz files on any platform.
62
- def unpack_tgz archive, destination, clobber=nil
63
- validate archive, destination
93
+ ##
94
+ # Unpack tar.gz or .tgz files on any platform.
95
+ #
96
+ # @return [File] the file or directory that was created.
97
+ def unpack_tgz archive, destination, clobber=nil
98
+ validate archive, destination
64
99
 
65
- tar = Zlib::GzipReader.new(File.open(archive, 'rb'))
66
- if(!should_unpack_tgz?(destination, clobber))
67
- raise Sprout::Errors::DestinationExistsError.new "Unable to unpack #{archive} into #{destination} without explicit :clobber argument"
68
- end
100
+ tar = Zlib::GzipReader.new(File.open(archive, 'rb'))
101
+ if(!should_unpack_tgz?(destination, clobber))
102
+ raise Sprout::Errors::DestinationExistsError.new "Unable to unpack #{archive} into #{destination} without explicit :clobber argument"
103
+ end
69
104
 
70
- Archive::Tar::Minitar.unpack(tar, destination)
105
+ Archive::Tar::Minitar.unpack(tar, destination)
71
106
 
72
- # Recurse and unpack gzipped children (Adobe did this double
73
- # gzip with the Linux FlashPlayer for some weird reason)
74
- ["#{destination}/**/*.tgz", "#{destination}/**/*.tar.gz"].each do |pattern|
75
- Dir.glob(pattern).each do |child|
76
- if(child != archive && dir != File.dirname(child))
77
- unpack_tgz(child, File.dirname(child))
78
- end
107
+ # Recurse and unpack gzipped children (Adobe did this double
108
+ # gzip with the Linux FlashPlayer for some weird reason)
109
+ ["#{destination}/**/*.tgz", "#{destination}/**/*.tar.gz"].each do |pattern|
110
+ Dir.glob(pattern).each do |child|
111
+ if(child != archive && dir != File.dirname(child))
112
+ unpack_tgz(child, File.dirname(child))
79
113
  end
80
114
  end
81
115
  end
116
+ end
82
117
 
83
- # Rather than unpacking, safely copy the file from one location
84
- # to another.
85
- def copy_file file, destination, clobber=nil
86
- validate file, destination
87
- target = File.expand_path( File.join(destination, File.basename(file)) )
88
- if(File.exists?(target) && clobber != :clobber)
89
- raise Sprout::Errors::DestinationExistsError.new "Unable to copy #{file} to #{target} because target already exists and we were not asked to :clobber it"
90
- end
91
- FileUtils.mkdir_p destination
92
- FileUtils.cp_r file, destination
93
-
94
- destination
95
- end
118
+ ##
119
+ # Rather than unpacking, safely copy the file from one location
120
+ # to another.
121
+ # This method is generally used when .exe files are downloaded
122
+ # directly.
123
+ #
124
+ # @return [File] the file or directory that was created.
125
+ def copy_file file, destination, clobber=nil
126
+ validate file, destination
127
+ target = File.expand_path( File.join(destination, File.basename(file)) )
128
+ if(File.exists?(target) && clobber != :clobber)
129
+ raise Sprout::Errors::DestinationExistsError.new "Unable to copy #{file} to #{target} because target already exists and we were not asked to :clobber it"
130
+ end
131
+ FileUtils.mkdir_p destination
132
+ FileUtils.cp_r file, destination
133
+
134
+ destination
135
+ end
96
136
 
97
- # Return true if the provided file name looks like a zip file.
98
- def is_zip? archive, type=nil
99
- type == :zip || !archive.match(/\.zip$/).nil?
100
- end
137
+ ##
138
+ # Returns true if the provided file name looks like a zip file or the +type+ argument is +:zip+.
139
+ # @return [Boolean]
140
+ def is_zip? archive, type=nil
141
+ type == :zip || !archive.match(/\.zip$/).nil?
142
+ end
101
143
 
102
- # Return true if the provided file name looks like a tar.gz file.
103
- def is_tgz? archive, type=nil
104
- type == :tgz || !archive.match(/\.tgz$/).nil? || !archive.match(/\.tar.gz$/).nil?
105
- end
144
+ ##
145
+ # Return true if the provided file name looks like a tar.gz file or the +type+ argument is +:tgz+.
146
+ # @return [Boolean]
147
+ def is_tgz? archive, type=nil
148
+ type == :tgz || !archive.match(/\.tgz$/).nil? || !archive.match(/\.tar.gz$/).nil?
149
+ end
106
150
 
107
- def is_exe? archive, type=nil
108
- type == :exe || !archive.match(/\.exe$/).nil?
109
- end
110
-
111
- def is_swc? archive, type=nil
112
- type == :swc || !archive.match(/\.swc$/).nil?
113
- end
151
+ ##
152
+ # Return true if the downloaded archive is a .exe file or the +type+ argument is +:exe+.
153
+ # @return [Boolean]
154
+ def is_exe? archive, type=nil
155
+ type == :exe || !archive.match(/\.exe$/).nil?
156
+ end
114
157
 
115
- def is_rb? archive, type=nil
116
- type == :rb || !archive.match(/\.rb$/).nil?
117
- end
158
+ ##
159
+ # Return true if the downloaded archive is a .swc file or the +type+ argument is +:swc+.
160
+ # @return [Boolean]
161
+ def is_swc? archive, type=nil
162
+ type == :swc || !archive.match(/\.swc$/).nil?
163
+ end
118
164
 
119
- private
165
+ ##
166
+ # Return true if the downloaded archive is a .rb file or the +type+ argument is +:rb+.
167
+ # @return [Boolean]
168
+ def is_rb? archive, type=nil
169
+ type == :rb || !archive.match(/\.rb$/).nil?
170
+ end
120
171
 
121
- def is_copyable? archive
122
- (is_exe?(archive) || is_swc?(archive) || is_rb?(archive))
123
- end
172
+ private
124
173
 
125
- def should_unpack_tgz? dir, clobber=nil
126
- return !directory_has_children?(dir) || clobber == :clobber
174
+ ##
175
+ # Return true if the provided archive should be copied as-is, rather
176
+ # than being unpacked first.
177
+ # @return [Boolean]
178
+ def is_copyable? archive
179
+ (is_exe?(archive) || is_swc?(archive) || is_rb?(archive))
180
+ end
127
181
 
128
- end
182
+ ##
183
+ # Return true if the tgz should be unpacked.
184
+ # @return [Boolean]
185
+ def should_unpack_tgz? dir, clobber=nil
186
+ return !directory_has_children?(dir) || clobber == :clobber
129
187
 
130
- def directory_has_children? dir
131
- (Dir.entries(dir) - ['.', '..']).size > 0
132
- end
188
+ end
133
189
 
134
- def validate archive, destination
135
- validate_archive archive
136
- validate_destination destination
137
- end
190
+ ##
191
+ # Return true if the provided directory has one or more chidren.
192
+ # @return [Boolean]
193
+ def directory_has_children? dir
194
+ (Dir.entries(dir) - ['.', '..']).size > 0
195
+ end
138
196
 
139
- def validate_archive archive
140
- message = "Archive could not be found at: #{archive}"
141
- raise Sprout::Errors::ArchiveUnpackerError.new(message) if archive.nil? || !File.exists?(archive)
142
- end
197
+ ##
198
+ # @return [Boolean] true if the +archive+ and +destination+ exist.
199
+ # @raise Sprout::Errors::ArchiveUnpackerError if the +archive+ or +destination+ don't exist.
200
+ def validate archive, destination
201
+ archive_message = "Archive could not be found at: #{archive}"
202
+ raise Sprout::Errors::ArchiveUnpackerError.new(archive_message) unless valid_path?(archive)
203
+ destination_message = "Destination could not be found at: #{destination}"
204
+ raise Sprout::Errors::ArchiveUnpackerError.new(destination_message) unless valid_path?(destination)
205
+ true
206
+ end
143
207
 
144
- def validate_destination path
145
- message = "Archive destination could not be found at: #{path}"
146
- raise Sprout::Errors::ArchiveUnpackerError.new(message) if path.nil? || !File.exists?(path)
147
- end
208
+ ##
209
+ # @return [Boolean] true if the provided +path+ is not nil and exists on disk.
210
+ def valid_path? path
211
+ !path.nil? && File.exists?(path)
212
+ end
148
213
 
149
- def unpack_zip_entry entry, destination, clobber
150
- # Ensure hidden mac files don't get written to disk:
151
- path = File.join destination, entry.name
152
-
153
- if entry.directory?
154
- # If an archive has empty directories:
155
- FileUtils.mkdir_p path
156
- elsif entry.file?
157
- # On Windows, we don't get the entry for
158
- # each parent directory:
159
- FileUtils.mkdir_p File.dirname(path)
160
- begin
214
+ ##
215
+ # Unpack an entry from a zip archive. This is an _inconvenience_ method
216
+ # thanks to the way Ruby zip handles zip archives.
217
+ def unpack_zip_entry entry, destination, clobber
218
+ # Ensure hidden mac files don't get written to disk:
219
+ path = File.join destination, entry.name
220
+
221
+ if entry.directory?
222
+ # If an archive has empty directories:
223
+ FileUtils.mkdir_p path
224
+ elsif entry.file?
225
+ # On Windows, we don't get the entry for
226
+ # each parent directory:
227
+ FileUtils.mkdir_p File.dirname(path)
228
+ begin
229
+ entry.extract path
230
+ rescue Zip::ZipDestinationFileExistsError => zip_dest_error
231
+ if(clobber == :clobber)
232
+ FileUtils.rm_rf path
161
233
  entry.extract path
162
- rescue Zip::ZipDestinationFileExistsError => zip_dest_error
163
- if(clobber == :clobber)
164
- FileUtils.rm_rf path
165
- entry.extract path
166
- else
167
- raise Sprout::Errors::DestinationExistsError.new zip_dest_error.message
168
- end
234
+ else
235
+ raise Sprout::Errors::DestinationExistsError.new zip_dest_error.message
169
236
  end
170
237
  end
171
238
  end
172
-
173
239
  end
174
240
  end
175
241