shoes 3.0.1 → 4.0.0.pre1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (709) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +44 -3
  3. data/.rspec +3 -0
  4. data/.ruby-gemset +1 -0
  5. data/.ruby-version +1 -0
  6. data/.travis.yml +31 -0
  7. data/CHANGELOG +3 -0
  8. data/Gemfile +3 -0
  9. data/Guardfile +11 -0
  10. data/{COPYING → LICENSE} +1 -0
  11. data/README.md +160 -50
  12. data/Rakefile +188 -101
  13. data/app.yaml +59 -6
  14. data/benchmark/app_clear.rb +21 -0
  15. data/benchmark/clear.rb +69 -0
  16. data/benchmark/memory/text_dispose.rb +9 -0
  17. data/benchmark/para_creator.rb +9 -0
  18. data/benchmark/paras.rb +52 -0
  19. data/benchmark/urls.rb +40 -0
  20. data/bin/ruby-shoes +6 -0
  21. data/bin/shoes +59 -0
  22. data/bin/shoes-guard +8 -0
  23. data/bin/shoes-stub +59 -0
  24. data/bin/shoes.bat +6 -0
  25. data/ext/install/Rakefile +29 -0
  26. data/ext/install/shoes.bat +6 -0
  27. data/lib/ext/highlighter.rb +2 -0
  28. data/lib/ext/highlighter/common.rb +197 -0
  29. data/lib/ext/highlighter/lang/ruby.rb +316 -0
  30. data/lib/ext/highlighter/markup.rb +222 -0
  31. data/lib/rubygems_plugin.rb +19 -0
  32. data/lib/shoes.rb +114 -537
  33. data/lib/shoes/animation.rb +55 -0
  34. data/lib/shoes/app.rb +320 -0
  35. data/lib/shoes/arc.rb +35 -0
  36. data/lib/shoes/background.rb +30 -0
  37. data/lib/shoes/border.rb +33 -0
  38. data/lib/shoes/builtin_methods.rb +73 -0
  39. data/lib/shoes/button.rb +32 -0
  40. data/lib/shoes/check_button.rb +43 -0
  41. data/lib/shoes/cli.rb +96 -0
  42. data/lib/shoes/color.rb +375 -0
  43. data/lib/shoes/common/background_element.rb +9 -0
  44. data/lib/shoes/common/changeable.rb +34 -0
  45. data/lib/shoes/common/clickable.rb +17 -0
  46. data/lib/shoes/common/common_methods.rb +70 -0
  47. data/lib/shoes/common/fill.rb +21 -0
  48. data/lib/shoes/common/registration.rb +33 -0
  49. data/lib/shoes/common/state.rb +18 -0
  50. data/lib/shoes/common/stroke.rb +28 -0
  51. data/lib/shoes/common/style.rb +34 -0
  52. data/lib/shoes/common/style_normalizer.rb +16 -0
  53. data/lib/shoes/configuration.rb +96 -0
  54. data/lib/shoes/dialog.rb +27 -0
  55. data/lib/shoes/dimension.rb +237 -0
  56. data/lib/shoes/dimensions.rb +194 -0
  57. data/lib/shoes/download.rb +117 -0
  58. data/lib/shoes/dsl.rb +478 -0
  59. data/lib/shoes/font.rb +49 -0
  60. data/lib/shoes/gradient.rb +18 -0
  61. data/lib/shoes/help.rb +458 -391
  62. data/lib/shoes/image.rb +27 -19
  63. data/lib/shoes/image_pattern.rb +10 -0
  64. data/lib/shoes/input_box.rb +68 -0
  65. data/lib/shoes/key_event.rb +17 -0
  66. data/lib/shoes/line.rb +38 -0
  67. data/lib/shoes/link.rb +49 -0
  68. data/lib/shoes/link_hover.rb +5 -0
  69. data/lib/shoes/list_box.rb +44 -0
  70. data/lib/shoes/logger.rb +66 -0
  71. data/lib/shoes/logger/ruby.rb +18 -0
  72. data/lib/shoes/manual.rb +6 -0
  73. data/lib/shoes/mock.rb +30 -0
  74. data/lib/shoes/mock/animation.rb +8 -0
  75. data/lib/shoes/mock/app.rb +44 -0
  76. data/lib/shoes/mock/arc.rb +8 -0
  77. data/lib/shoes/mock/background.rb +10 -0
  78. data/lib/shoes/mock/border.rb +7 -0
  79. data/lib/shoes/mock/button.rb +10 -0
  80. data/lib/shoes/mock/check.rb +24 -0
  81. data/lib/shoes/mock/common_methods.rb +11 -0
  82. data/lib/shoes/mock/dialog.rb +13 -0
  83. data/lib/shoes/mock/download.rb +18 -0
  84. data/lib/shoes/mock/font.rb +17 -0
  85. data/lib/shoes/mock/image.rb +12 -0
  86. data/lib/shoes/mock/image_pattern.rb +9 -0
  87. data/lib/shoes/mock/input_box.rb +23 -0
  88. data/lib/shoes/mock/keypress.rb +8 -0
  89. data/lib/shoes/mock/keyrelease.rb +8 -0
  90. data/lib/shoes/mock/line.rb +14 -0
  91. data/lib/shoes/mock/link.rb +11 -0
  92. data/lib/shoes/mock/list_box.rb +16 -0
  93. data/lib/shoes/mock/oval.rb +11 -0
  94. data/lib/shoes/mock/progress.rb +10 -0
  95. data/lib/shoes/mock/radio.rb +26 -0
  96. data/lib/shoes/mock/rect.rb +13 -0
  97. data/lib/shoes/mock/shape.rb +19 -0
  98. data/lib/shoes/mock/slot.rb +14 -0
  99. data/lib/shoes/mock/sound.rb +8 -0
  100. data/lib/shoes/mock/star.rb +13 -0
  101. data/lib/shoes/mock/text_block.rb +29 -0
  102. data/lib/shoes/mock/timer.rb +8 -0
  103. data/lib/shoes/oval.rb +28 -0
  104. data/lib/shoes/point.rb +43 -0
  105. data/lib/shoes/progress.rb +26 -0
  106. data/lib/shoes/radio.rb +15 -0
  107. data/lib/shoes/rect.rb +28 -0
  108. data/lib/shoes/renamed_delegate.rb +15 -0
  109. data/lib/shoes/shape.rb +175 -0
  110. data/lib/shoes/slot.rb +232 -0
  111. data/lib/shoes/slot_contents.rb +56 -0
  112. data/lib/shoes/sound.rb +16 -0
  113. data/lib/shoes/span.rb +16 -0
  114. data/lib/shoes/star.rb +49 -0
  115. data/lib/shoes/swt.rb +114 -0
  116. data/lib/shoes/swt/animation.rb +46 -0
  117. data/lib/shoes/swt/app.rb +300 -0
  118. data/lib/shoes/swt/arc.rb +70 -0
  119. data/lib/shoes/swt/background.rb +31 -0
  120. data/lib/shoes/swt/border.rb +37 -0
  121. data/lib/shoes/swt/button.rb +18 -0
  122. data/lib/shoes/swt/check.rb +14 -0
  123. data/lib/shoes/swt/check_button.rb +19 -0
  124. data/lib/shoes/swt/color.rb +45 -0
  125. data/lib/shoes/swt/common/child.rb +16 -0
  126. data/lib/shoes/swt/common/clear.rb +24 -0
  127. data/lib/shoes/swt/common/clickable.rb +62 -0
  128. data/lib/shoes/swt/common/container.rb +28 -0
  129. data/lib/shoes/swt/common/fill.rb +37 -0
  130. data/lib/shoes/swt/common/painter.rb +83 -0
  131. data/lib/shoes/swt/common/painter_updates_position.rb +12 -0
  132. data/lib/shoes/swt/common/resource.rb +14 -0
  133. data/lib/shoes/swt/common/selection_listener.rb +14 -0
  134. data/lib/shoes/swt/common/stroke.rb +41 -0
  135. data/lib/shoes/swt/common/toggle.rb +13 -0
  136. data/lib/shoes/swt/common/update_position.rb +15 -0
  137. data/lib/shoes/swt/dialog.rb +89 -0
  138. data/lib/shoes/swt/disposed_protection.rb +23 -0
  139. data/lib/shoes/swt/download.rb +24 -0
  140. data/lib/shoes/swt/fitted_text_layout.rb +94 -0
  141. data/lib/shoes/swt/fitted_text_layout_collection.rb +108 -0
  142. data/lib/shoes/swt/font.rb +32 -0
  143. data/lib/shoes/swt/gradient.rb +77 -0
  144. data/lib/shoes/swt/image.rb +130 -0
  145. data/lib/shoes/swt/image_pattern.rb +19 -0
  146. data/lib/shoes/swt/input_box.rb +73 -0
  147. data/lib/shoes/swt/key_listener.rb +145 -0
  148. data/lib/shoes/swt/line.rb +57 -0
  149. data/lib/shoes/swt/link.rb +37 -0
  150. data/lib/shoes/swt/link_segment.rb +108 -0
  151. data/lib/shoes/swt/list_box.rb +49 -0
  152. data/lib/shoes/swt/mouse_move_listener.rb +61 -0
  153. data/lib/shoes/swt/oval.rb +53 -0
  154. data/lib/shoes/swt/progress.rb +35 -0
  155. data/lib/shoes/swt/radio.rb +29 -0
  156. data/lib/shoes/swt/radio_group.rb +54 -0
  157. data/lib/shoes/swt/rect.rb +31 -0
  158. data/lib/shoes/swt/rect_painter.rb +23 -0
  159. data/lib/shoes/swt/redrawing_aspect.rb +122 -0
  160. data/lib/shoes/swt/shape.rb +101 -0
  161. data/lib/shoes/swt/shoes_layout.rb +43 -0
  162. data/lib/shoes/swt/slot.rb +25 -0
  163. data/lib/shoes/swt/sound.rb +119 -0
  164. data/lib/shoes/swt/star.rb +51 -0
  165. data/lib/shoes/swt/swt_button.rb +49 -0
  166. data/lib/shoes/swt/text_block.rb +133 -0
  167. data/lib/shoes/swt/text_block_cursor_painter.rb +112 -0
  168. data/lib/shoes/swt/text_block_fitter.rb +180 -0
  169. data/lib/shoes/swt/text_block_painter.rb +49 -0
  170. data/lib/shoes/swt/text_font_factory.rb +27 -0
  171. data/lib/shoes/swt/text_style_factory.rb +88 -0
  172. data/lib/shoes/swt/timer.rb +19 -0
  173. data/lib/shoes/swt/tooling/leak_hunter.rb +84 -0
  174. data/lib/shoes/text.rb +14 -0
  175. data/lib/shoes/text_block.rb +162 -0
  176. data/lib/shoes/timer.rb +10 -0
  177. data/lib/shoes/url.rb +47 -0
  178. data/lib/shoes/version.rb +1 -1
  179. data/lib/shoes/widget.rb +73 -0
  180. data/lib/support/jl1.0.1.jar +0 -0
  181. data/lib/support/jogg-0.0.7.jar +0 -0
  182. data/lib/support/jorbis-0.0.15.jar +0 -0
  183. data/lib/support/log4j-1.2.16.jar +0 -0
  184. data/lib/support/mp3spi1.9.5.jar +0 -0
  185. data/lib/support/tritonus_share.jar +0 -0
  186. data/lib/support/vorbisspi1.0.3.jar +0 -0
  187. data/samples/README +86 -0
  188. data/samples/class-book-adjusted.rb +45 -0
  189. data/samples/class-book.rb +10 -10
  190. data/samples/cy.png +0 -0
  191. data/samples/expert-definr.rb +6 -6
  192. data/samples/expert-funnies.rb +23 -14
  193. data/samples/expert-game-of-life-adjusted.rb +249 -0
  194. data/samples/expert-game-of-life.rb +243 -0
  195. data/samples/expert-irb-adjusted.rb +110 -0
  196. data/samples/expert-irb.rb +7 -7
  197. data/samples/expert-minesweeper-adjusted.rb +272 -0
  198. data/samples/expert-minesweeper.rb +53 -53
  199. data/samples/expert-othello-adjusted.rb +325 -0
  200. data/samples/expert-othello.rb +38 -39
  201. data/samples/expert-pong.rb +10 -10
  202. data/samples/expert-snake.rb +78 -0
  203. data/samples/expert-tankspank.rb +354 -354
  204. data/samples/good-arc.rb +20 -12
  205. data/samples/good-clock-adjusted.rb +49 -0
  206. data/samples/good-clock.rb +5 -5
  207. data/samples/good-displace.rb +98 -0
  208. data/samples/good-follow.rb +3 -3
  209. data/samples/good-potato-chopping.rb +22 -0
  210. data/samples/good-reminder.rb +51 -51
  211. data/samples/good-vjot.rb +15 -13
  212. data/samples/loogink.png +0 -0
  213. data/samples/nks_poem.rb +22 -0
  214. data/samples/original-manual-adjusted.rb +475 -0
  215. data/samples/original-manual.rb +472 -0
  216. data/samples/potato_chopping/1258_s001.gif +0 -0
  217. data/samples/potato_chopping/1258_s002.gif +0 -0
  218. data/samples/potato_chopping/1258_s003.gif +0 -0
  219. data/samples/potato_chopping/1258_s004.gif +0 -0
  220. data/samples/potato_chopping/1258_s005.gif +0 -0
  221. data/samples/potato_chopping/1258_s006.gif +0 -0
  222. data/samples/potato_chopping/1258_s007.gif +0 -0
  223. data/samples/potato_chopping/1258_s008.gif +0 -0
  224. data/samples/potato_chopping/1258_s009.gif +0 -0
  225. data/samples/potato_chopping/1258_s010.gif +0 -0
  226. data/samples/potato_chopping/1258_s011.gif +0 -0
  227. data/samples/potato_chopping/1258_s012.gif +0 -0
  228. data/samples/potato_chopping/1258_s013.gif +0 -0
  229. data/samples/potato_chopping/1258_s014.gif +0 -0
  230. data/samples/potato_chopping/1258_s015.gif +0 -0
  231. data/samples/potato_chopping/1258_s016.gif +0 -0
  232. data/samples/potato_chopping/1258_s017.gif +0 -0
  233. data/samples/potato_chopping/1258_s018.gif +0 -0
  234. data/samples/potato_chopping/1258_s019.gif +0 -0
  235. data/samples/potato_chopping/1258_s020.gif +0 -0
  236. data/samples/potato_chopping/1258_s021.gif +0 -0
  237. data/samples/potato_chopping/1258_s022.gif +0 -0
  238. data/samples/potato_chopping/1258_s023.gif +0 -0
  239. data/samples/potato_chopping/1258_s024.gif +0 -0
  240. data/samples/potato_chopping/1258_s025.gif +0 -0
  241. data/samples/potato_chopping/1258_s026.gif +0 -0
  242. data/samples/potato_chopping/1258_s027.gif +0 -0
  243. data/samples/potato_chopping/1258_s028.gif +0 -0
  244. data/samples/potato_chopping/1258_s029.gif +0 -0
  245. data/samples/potato_chopping/1258_s030.gif +0 -0
  246. data/samples/potato_chopping/1258_s031.gif +0 -0
  247. data/samples/potato_chopping/1258_s032.gif +0 -0
  248. data/samples/potato_chopping/1258_s033.gif +0 -0
  249. data/samples/potato_chopping/1258_s034.gif +0 -0
  250. data/samples/potato_chopping/1258_s035.gif +0 -0
  251. data/samples/potato_chopping/1258_s036.gif +0 -0
  252. data/samples/potato_chopping/1258_s037.gif +0 -0
  253. data/samples/potato_chopping/1258_s038.gif +0 -0
  254. data/samples/potato_chopping/1258_s039.gif +0 -0
  255. data/samples/potato_chopping/1258_s040.gif +0 -0
  256. data/samples/potato_chopping/1258_s041.gif +0 -0
  257. data/samples/potato_chopping/1258_s042.gif +0 -0
  258. data/samples/potato_chopping/1258_s043.gif +0 -0
  259. data/samples/potato_chopping/1258_s044.gif +0 -0
  260. data/samples/potato_chopping/1258_s045.gif +0 -0
  261. data/samples/potato_chopping/1258_s046.gif +0 -0
  262. data/samples/potato_chopping/1258_s047.gif +0 -0
  263. data/samples/potato_chopping/1258_s048.gif +0 -0
  264. data/samples/potato_chopping/1258_s049.gif +0 -0
  265. data/samples/potato_chopping/1258_s050.gif +0 -0
  266. data/samples/potato_chopping/1258_s051.gif +0 -0
  267. data/samples/potato_chopping/1258_s052.gif +0 -0
  268. data/samples/potato_chopping/1258_s053.gif +0 -0
  269. data/samples/potato_chopping/1258_s054.gif +0 -0
  270. data/samples/potato_chopping/1258_s055.gif +0 -0
  271. data/samples/potato_chopping/1258_s056.gif +0 -0
  272. data/samples/potato_chopping/1258_s057.gif +0 -0
  273. data/samples/potato_chopping/1258_s058.gif +0 -0
  274. data/samples/potato_chopping/1258_s059.gif +0 -0
  275. data/samples/sample1.rb +30 -0
  276. data/samples/sample12.rb +21 -0
  277. data/samples/sample13.rb +13 -0
  278. data/samples/sample14.rb +64 -0
  279. data/samples/sample15.rb +18 -0
  280. data/samples/sample16.rb +10 -0
  281. data/samples/sample17.rb +10 -0
  282. data/samples/sample2.rb +14 -0
  283. data/samples/sample21.rb +5 -0
  284. data/samples/sample23.rb +8 -0
  285. data/samples/sample24.rb +21 -0
  286. data/samples/sample27.rb +18 -0
  287. data/samples/sample3.rb +14 -0
  288. data/samples/sample31.rb +22 -0
  289. data/samples/sample34.rb +27 -0
  290. data/samples/sample35.rb +32 -0
  291. data/samples/sample37.rb +8 -0
  292. data/samples/sample4.rb +7 -0
  293. data/samples/sample42.rb +14 -0
  294. data/samples/sample45.rb +11 -0
  295. data/samples/sample56.rb +10 -0
  296. data/samples/sample6.rb +9 -0
  297. data/samples/sample7.rb +3 -0
  298. data/samples/sample8.rb +7 -0
  299. data/samples/sample9.rb +10 -0
  300. data/samples/simple-accordion.rb +7 -7
  301. data/samples/simple-anim-shapes.rb +3 -3
  302. data/samples/simple-anim-text.rb +2 -2
  303. data/samples/simple-animate.rb +12 -0
  304. data/samples/simple-arc.rb +2 -2
  305. data/samples/simple-bounce.rb +4 -4
  306. data/samples/simple-brightness-transitions.rb +8 -0
  307. data/samples/simple-button-animate.rb +16 -0
  308. data/samples/simple-calc-2.rb +34 -0
  309. data/samples/simple-calc.rb +11 -11
  310. data/samples/simple-color-selector.rb +10 -0
  311. data/samples/simple-color-transitions.rb +11 -0
  312. data/samples/simple-control-sizes.rb +12 -12
  313. data/samples/simple-dialogs-outside.rb +12 -0
  314. data/samples/simple-dialogs.rb +4 -1
  315. data/samples/simple-displace.rb +15 -0
  316. data/samples/simple-downloader.rb +11 -11
  317. data/samples/simple-editor.rb +5 -5
  318. data/samples/simple-face.rb +14 -0
  319. data/samples/simple-flow-wrap.rb +11 -0
  320. data/samples/simple-font.rb +17 -0
  321. data/samples/simple-form.rb +14 -13
  322. data/samples/simple-fullscreen.rb +4 -0
  323. data/samples/simple-guess-game.rb +28 -0
  324. data/samples/simple-keypress.rb +14 -0
  325. data/samples/simple-manual.rb +2 -0
  326. data/samples/simple-mask.rb +4 -4
  327. data/samples/simple-menu.rb +28 -12
  328. data/samples/simple-mouse-follow.rb +8 -0
  329. data/samples/simple-move.rb +13 -0
  330. data/samples/simple-oval.rb +3 -0
  331. data/samples/simple-sample-executor.rb +6 -0
  332. data/samples/simple-shoes-intro.rb +22 -0
  333. data/samples/simple-slide.rb +15 -4
  334. data/samples/simple-sound.rb +30 -0
  335. data/samples/simple-sphere.rb +6 -6
  336. data/samples/simple-stripes.rb +8 -0
  337. data/samples/simple-timer.rb +4 -2
  338. data/samples/simple-video.rb +2 -2
  339. data/samples/sounds/102719__sarge4267__explosion.mp3 +0 -0
  340. data/samples/sounds/145622__andybrannan__train-fog-horn-long-wyomming.aiff +0 -0
  341. data/samples/sounds/46492__phreaksaccount__shields1.ogg +0 -0
  342. data/samples/sounds/61847__simon-rue__boink-v3.wav +0 -0
  343. data/shoes.gemspec +31 -11
  344. data/snapshots/sample1.png +0 -0
  345. data/snapshots/sample10.png +0 -0
  346. data/snapshots/sample11.png +0 -0
  347. data/snapshots/sample12.png +0 -0
  348. data/snapshots/sample13.png +0 -0
  349. data/snapshots/sample14.png +0 -0
  350. data/snapshots/sample15.png +0 -0
  351. data/snapshots/sample16.png +0 -0
  352. data/snapshots/sample17.png +0 -0
  353. data/snapshots/sample18.png +0 -0
  354. data/snapshots/sample19.png +0 -0
  355. data/snapshots/sample2.png +0 -0
  356. data/snapshots/sample20.png +0 -0
  357. data/snapshots/sample21.png +0 -0
  358. data/snapshots/sample22.png +0 -0
  359. data/snapshots/sample23.png +0 -0
  360. data/snapshots/sample24.png +0 -0
  361. data/snapshots/sample27.png +0 -0
  362. data/snapshots/sample28.png +0 -0
  363. data/snapshots/sample29.png +0 -0
  364. data/snapshots/sample3.png +0 -0
  365. data/snapshots/sample30.png +0 -0
  366. data/snapshots/sample31.png +0 -0
  367. data/snapshots/sample34.png +0 -0
  368. data/snapshots/sample35.png +0 -0
  369. data/snapshots/sample36.png +0 -0
  370. data/snapshots/sample37.png +0 -0
  371. data/snapshots/sample4.png +0 -0
  372. data/snapshots/sample42.png +0 -0
  373. data/snapshots/sample44.png +0 -0
  374. data/snapshots/sample45.png +0 -0
  375. data/snapshots/sample46.png +0 -0
  376. data/snapshots/sample5.png +0 -0
  377. data/snapshots/sample6.png +0 -0
  378. data/snapshots/sample7.png +0 -0
  379. data/snapshots/sample8.png +0 -0
  380. data/snapshots/sample9.png +0 -0
  381. data/snapshots/sample99.png +0 -0
  382. data/spec/async_helper.rb +21 -0
  383. data/spec/code_coverage.rb +11 -0
  384. data/spec/shoes/animation_spec.rb +65 -0
  385. data/spec/shoes/app_spec.rb +411 -0
  386. data/spec/shoes/arc_spec.rb +53 -0
  387. data/spec/shoes/background_spec.rb +48 -0
  388. data/spec/shoes/border_spec.rb +43 -0
  389. data/spec/shoes/builtin_methods_spec.rb +84 -0
  390. data/spec/shoes/button_spec.rb +41 -0
  391. data/spec/shoes/check_spec.rb +31 -0
  392. data/spec/shoes/cli_spec.rb +16 -0
  393. data/spec/shoes/color_spec.rb +396 -0
  394. data/spec/shoes/common/style_normalizer_spec.rb +28 -0
  395. data/spec/shoes/common/style_spec.rb +58 -0
  396. data/spec/shoes/configuration_spec.rb +37 -0
  397. data/spec/shoes/constants_spec.rb +38 -0
  398. data/spec/shoes/dialog_spec.rb +163 -0
  399. data/spec/shoes/dimension_spec.rb +381 -0
  400. data/spec/shoes/dimensions_spec.rb +831 -0
  401. data/spec/shoes/download_spec.rb +133 -0
  402. data/spec/shoes/flow_spec.rb +92 -0
  403. data/spec/shoes/font_spec.rb +38 -0
  404. data/spec/shoes/framework_learning_spec.rb +30 -0
  405. data/spec/shoes/helpers/fake_element.rb +11 -0
  406. data/spec/shoes/helpers/sample17_helper.rb +66 -0
  407. data/spec/shoes/image_spec.rb +45 -0
  408. data/spec/shoes/images/shoe.jpg +0 -0
  409. data/spec/shoes/input_box_spec.rb +44 -0
  410. data/spec/shoes/integration_spec.rb +20 -0
  411. data/spec/shoes/keypress_spec.rb +11 -0
  412. data/spec/shoes/keyrelease_spec.rb +12 -0
  413. data/spec/shoes/line_spec.rb +47 -0
  414. data/spec/shoes/link_spec.rb +89 -0
  415. data/spec/shoes/list_box_spec.rb +63 -0
  416. data/spec/shoes/logger/ruby_spec.rb +9 -0
  417. data/spec/shoes/logger_spec.rb +45 -0
  418. data/spec/shoes/oval_spec.rb +20 -0
  419. data/spec/shoes/point_spec.rb +51 -0
  420. data/spec/shoes/progress_spec.rb +40 -0
  421. data/spec/shoes/radio_spec.rb +28 -0
  422. data/spec/shoes/rect_spec.rb +38 -0
  423. data/spec/shoes/renamed_delegate_spec.rb +70 -0
  424. data/spec/shoes/shape_spec.rb +54 -0
  425. data/spec/shoes/shared_examples/button.rb +6 -0
  426. data/spec/shoes/shared_examples/changeable.rb +26 -0
  427. data/spec/shoes/shared_examples/clickable.rb +5 -0
  428. data/spec/shoes/shared_examples/common_methods.rb +42 -0
  429. data/spec/shoes/shared_examples/dimensions.rb +32 -0
  430. data/spec/shoes/shared_examples/dsl.rb +42 -0
  431. data/spec/shoes/shared_examples/dsl/animate.rb +29 -0
  432. data/spec/shoes/shared_examples/dsl/arc.rb +45 -0
  433. data/spec/shoes/shared_examples/dsl/background.rb +26 -0
  434. data/spec/shoes/shared_examples/dsl/border.rb +10 -0
  435. data/spec/shoes/shared_examples/dsl/cap.rb +6 -0
  436. data/spec/shoes/shared_examples/dsl/check.rb +11 -0
  437. data/spec/shoes/shared_examples/dsl/edit_box.rb +8 -0
  438. data/spec/shoes/shared_examples/dsl/edit_line.rb +8 -0
  439. data/spec/shoes/shared_examples/dsl/editable_element.rb +29 -0
  440. data/spec/shoes/shared_examples/dsl/fill.rb +27 -0
  441. data/spec/shoes/shared_examples/dsl/flow.rb +15 -0
  442. data/spec/shoes/shared_examples/dsl/gradient.rb +52 -0
  443. data/spec/shoes/shared_examples/dsl/image.rb +21 -0
  444. data/spec/shoes/shared_examples/dsl/line.rb +9 -0
  445. data/spec/shoes/shared_examples/dsl/nofill.rb +6 -0
  446. data/spec/shoes/shared_examples/dsl/nostroke.rb +6 -0
  447. data/spec/shoes/shared_examples/dsl/oval.rb +60 -0
  448. data/spec/shoes/shared_examples/dsl/pattern.rb +34 -0
  449. data/spec/shoes/shared_examples/dsl/progress.rb +7 -0
  450. data/spec/shoes/shared_examples/dsl/rect.rb +92 -0
  451. data/spec/shoes/shared_examples/dsl/rgb.rb +26 -0
  452. data/spec/shoes/shared_examples/dsl/shape.rb +21 -0
  453. data/spec/shoes/shared_examples/dsl/star.rb +48 -0
  454. data/spec/shoes/shared_examples/dsl/stroke.rb +30 -0
  455. data/spec/shoes/shared_examples/dsl/strokewidth.rb +19 -0
  456. data/spec/shoes/shared_examples/dsl/style.rb +32 -0
  457. data/spec/shoes/shared_examples/dsl/text_elements.rb +81 -0
  458. data/spec/shoes/shared_examples/dsl_app_context.rb +8 -0
  459. data/spec/shoes/shared_examples/hover_leave.rb +11 -0
  460. data/spec/shoes/shared_examples/parent.rb +6 -0
  461. data/spec/shoes/shared_examples/shared_element_method.rb +52 -0
  462. data/spec/shoes/shared_examples/slot.rb +272 -0
  463. data/spec/shoes/shared_examples/state.rb +19 -0
  464. data/spec/shoes/shared_examples/style.rb +24 -0
  465. data/spec/shoes/slot_spec.rb +60 -0
  466. data/spec/shoes/sound_spec.rb +15 -0
  467. data/spec/shoes/span_spec.rb +94 -0
  468. data/spec/shoes/spec_helper.rb +1 -0
  469. data/spec/shoes/stack_spec.rb +53 -0
  470. data/spec/shoes/star_spec.rb +30 -0
  471. data/spec/shoes/text_block_spec.rb +242 -0
  472. data/spec/shoes/url_spec.rb +66 -0
  473. data/spec/shoes/widget_spec.rb +34 -0
  474. data/spec/shoes_spec.rb +44 -0
  475. data/spec/spec_helper.rb +16 -0
  476. data/spec/swt_shoes/animation_spec.rb +86 -0
  477. data/spec/swt_shoes/app_spec.rb +75 -0
  478. data/spec/swt_shoes/arc_spec.rb +101 -0
  479. data/spec/swt_shoes/background_spec.rb +56 -0
  480. data/spec/swt_shoes/border_spec.rb +51 -0
  481. data/spec/swt_shoes/button_spec.rb +101 -0
  482. data/spec/swt_shoes/check_spec.rb +28 -0
  483. data/spec/swt_shoes/color_spec.rb +67 -0
  484. data/spec/swt_shoes/common/painter_spec.rb +29 -0
  485. data/spec/swt_shoes/configuration_spec.rb +12 -0
  486. data/spec/swt_shoes/dialog_spec.rb +106 -0
  487. data/spec/swt_shoes/disposed_protection_spec.rb +49 -0
  488. data/spec/swt_shoes/fitted_text_layout_collection_spec.rb +174 -0
  489. data/spec/swt_shoes/fitted_text_layout_spec.rb +130 -0
  490. data/spec/swt_shoes/flow_spec.rb +26 -0
  491. data/spec/swt_shoes/font_spec.rb +33 -0
  492. data/spec/swt_shoes/gradient_spec.rb +20 -0
  493. data/spec/swt_shoes/image_pattern_spec.rb +19 -0
  494. data/spec/swt_shoes/image_spec.rb +100 -0
  495. data/spec/swt_shoes/input_box_spec.rb +110 -0
  496. data/spec/swt_shoes/integration_spec.rb +18 -0
  497. data/spec/swt_shoes/key_listener_spec.rb +320 -0
  498. data/spec/swt_shoes/line_spec.rb +43 -0
  499. data/spec/swt_shoes/link_segment_spec.rb +103 -0
  500. data/spec/swt_shoes/link_spec.rb +59 -0
  501. data/spec/swt_shoes/list_box_spec.rb +51 -0
  502. data/spec/swt_shoes/minimal.png +0 -0
  503. data/spec/swt_shoes/mouse_move_listener_spec.rb +129 -0
  504. data/spec/swt_shoes/oval_spec.rb +51 -0
  505. data/spec/swt_shoes/progress_spec.rb +44 -0
  506. data/spec/swt_shoes/radio_group_spec.rb +73 -0
  507. data/spec/swt_shoes/radio_spec.rb +56 -0
  508. data/spec/swt_shoes/rect_painter_spec.rb +45 -0
  509. data/spec/swt_shoes/rect_spec.rb +19 -0
  510. data/spec/swt_shoes/shape_spec.rb +81 -0
  511. data/spec/swt_shoes/shared_examples/button.rb +24 -0
  512. data/spec/swt_shoes/shared_examples/clearable.rb +32 -0
  513. data/spec/swt_shoes/shared_examples/clickable.rb +60 -0
  514. data/spec/swt_shoes/shared_examples/movable.rb +36 -0
  515. data/spec/swt_shoes/shared_examples/paintable_spec.rb +7 -0
  516. data/spec/swt_shoes/shared_examples/painter.rb +83 -0
  517. data/spec/swt_shoes/shared_examples/pattern.rb +32 -0
  518. data/spec/swt_shoes/shared_examples/swt_app_context.rb +17 -0
  519. data/spec/swt_shoes/shared_examples/togglable.rb +15 -0
  520. data/spec/swt_shoes/shell_control_listener_spec.rb +23 -0
  521. data/spec/swt_shoes/sound.rb +10 -0
  522. data/spec/swt_shoes/spec_helper.rb +31 -0
  523. data/spec/swt_shoes/star_spec.rb +47 -0
  524. data/spec/swt_shoes/text_block_cursor_painter_spec.rb +202 -0
  525. data/spec/swt_shoes/text_block_fitter_spec.rb +181 -0
  526. data/spec/swt_shoes/text_block_painter_spec.rb +221 -0
  527. data/spec/swt_shoes/text_block_spec.rb +183 -0
  528. data/static/PKGBUILD +47 -0
  529. data/static/downloading.png +0 -0
  530. data/static/manual-en.txt +119 -128
  531. data/static/manual-ja.txt +97 -93
  532. data/static/manual.css +19 -2
  533. data/static/shoes-icon-brown.png +0 -0
  534. data/static/shoes-manual-apps.png +0 -0
  535. metadata +740 -402
  536. data/README.old +0 -117
  537. data/Rakefile.bk +0 -651
  538. data/bin/main.skel +0 -104
  539. data/bugs/issue-012e9468ddc7b0cb7e1503413a8a11c4f8707b67.yaml +0 -21
  540. data/bugs/issue-0711ff8b67baa63586f11d0096fee9dd4436bf58.yaml +0 -23
  541. data/bugs/issue-07f87998d93eb401e22395c11085676389b935c4.yaml +0 -22
  542. data/bugs/issue-0bff2d80008803cbc7efbcdacdc60ef2163664d2.yaml +0 -22
  543. data/bugs/issue-0c66f223d19efbca7b692f3b91961f407ad7abec.yaml +0 -24
  544. data/bugs/issue-183bc3c7a8f575aff2b24e0bf22aa0dfcc8e4fc2.yaml +0 -29
  545. data/bugs/issue-1bad1e60a04cb3adb6a8f3ded128af2e16b56ffe.yaml +0 -18
  546. data/bugs/issue-1f1d43f76bf4de79d7f94adbae6dd506a9d81633.yaml +0 -41
  547. data/bugs/issue-320924117cadb045cc91f2a6fca922b4d81d4bb5.yaml +0 -20
  548. data/bugs/issue-33e5c8355fbf65252ea9e939714651df8bd8cb3b.yaml +0 -25
  549. data/bugs/issue-36f7c8262a72bcd5e28cfa4ed29328b8237ea79b.yaml +0 -20
  550. data/bugs/issue-39bf04ee50c3bef67b89b8e9beb28657805587ce.yaml +0 -18
  551. data/bugs/issue-3e28ba7754f73d02ef416eef989af707a8c00f01.yaml +0 -23
  552. data/bugs/issue-3f638cc03f41f9c3fdf217355321f1563f8fee45.yaml +0 -22
  553. data/bugs/issue-41e48e14f1ef4f6deb69be68165d7dd3ffd99156.yaml +0 -22
  554. data/bugs/issue-4c9408166a2aa5dd333bbb05520deebf4ded08e0.yaml +0 -22
  555. data/bugs/issue-55c687e108ecd5aeb8e0d0aeb4294984f84acd3e.yaml +0 -18
  556. data/bugs/issue-5811d34692cc292717a58ec1df1f8948cf30d826.yaml +0 -28
  557. data/bugs/issue-5a7c1f59a0526f9cea7fb366867cf1e6ed8ef69d.yaml +0 -22
  558. data/bugs/issue-688a2c2566bef6a03efa57a4ae1f7cfa8fc74444.yaml +0 -21
  559. data/bugs/issue-78b16c7988ade2ef96e716fa8cb9a004bd4ced65.yaml +0 -33
  560. data/bugs/issue-804ee49f9800154eddf0650690c7a9bb5626253f.yaml +0 -27
  561. data/bugs/issue-807dd1c610b2e941a5d454e26b2eac27e89a0ab4.yaml +0 -22
  562. data/bugs/issue-822ee33ec11ebd25f90ea86e8438de7891e63aee.yaml +0 -18
  563. data/bugs/issue-82ff7152cebb8a1cb065b864cb4fe22de2328146.yaml +0 -29
  564. data/bugs/issue-856afbdcdd4970ad54b8ce4a6c017fbaab45f49d.yaml +0 -31
  565. data/bugs/issue-8d49e32fb21522651c67490adb4d80076dbb14e1.yaml +0 -24
  566. data/bugs/issue-91583359653a9d530c1e32be72d874d847a306e7.yaml +0 -21
  567. data/bugs/issue-af41a5229613172764e7d3c98431172db337053d.yaml +0 -20
  568. data/bugs/issue-bd9856b3788dd429c998a5af1b2aae8221cb80b7.yaml +0 -28
  569. data/bugs/issue-be22aef5c564fb7b5e9938343136a9cd6a2edb7b.yaml +0 -22
  570. data/bugs/issue-bf8697523c77c326e7e35fc82cf3dd739ae92310.yaml +0 -27
  571. data/bugs/issue-cdd4b4795f34d6ff46e56ece10f8216a4a5456b2.yaml +0 -25
  572. data/bugs/issue-d9bfb5581d745ef9deb3b9b2e08ef74d1cd43082.yaml +0 -20
  573. data/bugs/issue-e0ce2f687cc096f35715d28b0af88589f4ab6cc6.yaml +0 -18
  574. data/bugs/issue-e4b0aca4a10a574b333aeaecaaf221dbc5ed22c6.yaml +0 -38
  575. data/bugs/issue-f263746594b95ba778455730478ee8df60ee639d.yaml +0 -22
  576. data/bugs/project.yaml +0 -72
  577. data/builddeps.sh +0 -102
  578. data/gemlib/shoes.rb +0 -1
  579. data/lib/shoes/cache.rb +0 -54
  580. data/lib/shoes/chipmunk.rb +0 -35
  581. data/lib/shoes/data.rb +0 -39
  582. data/lib/shoes/inspect.rb +0 -128
  583. data/lib/shoes/log.rb +0 -48
  584. data/lib/shoes/minitar.rb +0 -986
  585. data/lib/shoes/override.rb +0 -38
  586. data/lib/shoes/pack.rb +0 -543
  587. data/lib/shoes/search.rb +0 -46
  588. data/lib/shoes/setup.rb +0 -329
  589. data/lib/shoes/shy.rb +0 -131
  590. data/lib/shoes/shybuilder.rb +0 -44
  591. data/make/darwin/deps.vlc +0 -12
  592. data/make/darwin/dylibs.shoes +0 -22
  593. data/make/darwin/dylibs.video +0 -11
  594. data/make/darwin/env.rb +0 -81
  595. data/make/darwin/tasks.rb +0 -105
  596. data/make/linux/env.rb +0 -65
  597. data/make/linux/tasks.rb +0 -61
  598. data/make/make.rb +0 -85
  599. data/make/mingw/dlls +0 -19
  600. data/make/mingw/env.rb +0 -69
  601. data/make/mingw/tasks.rb +0 -70
  602. data/make/rakefile_common.rb +0 -8
  603. data/manual-snapshots/class-book.png +0 -0
  604. data/manual-snapshots/expert-definr.png +0 -0
  605. data/manual-snapshots/expert-funnies.png +0 -0
  606. data/manual-snapshots/expert-irb.png +0 -0
  607. data/manual-snapshots/expert-minesweeper.png +0 -0
  608. data/manual-snapshots/expert-othello.png +0 -0
  609. data/manual-snapshots/expert-pong.png +0 -0
  610. data/manual-snapshots/expert-tankspank.png +0 -0
  611. data/manual-snapshots/good-arc.png +0 -0
  612. data/manual-snapshots/good-clock.png +0 -0
  613. data/manual-snapshots/good-follow.png +0 -0
  614. data/manual-snapshots/good-reminder.png +0 -0
  615. data/manual-snapshots/good-vjot.png +0 -0
  616. data/manual-snapshots/simple-accordion.png +0 -0
  617. data/manual-snapshots/simple-anim-shapes.png +0 -0
  618. data/manual-snapshots/simple-anim-text.png +0 -0
  619. data/manual-snapshots/simple-arc.png +0 -0
  620. data/manual-snapshots/simple-bounce.png +0 -0
  621. data/manual-snapshots/simple-calc.png +0 -0
  622. data/manual-snapshots/simple-chipmunk.png +0 -0
  623. data/manual-snapshots/simple-control-sizes.png +0 -0
  624. data/manual-snapshots/simple-curve.png +0 -0
  625. data/manual-snapshots/simple-dialogs.png +0 -0
  626. data/manual-snapshots/simple-downloader.png +0 -0
  627. data/manual-snapshots/simple-draw.png +0 -0
  628. data/manual-snapshots/simple-editor.png +0 -0
  629. data/manual-snapshots/simple-form.png +0 -0
  630. data/manual-snapshots/simple-mask.png +0 -0
  631. data/manual-snapshots/simple-menu.png +0 -0
  632. data/manual-snapshots/simple-menu1.png +0 -0
  633. data/manual-snapshots/simple-rubygems.png +0 -0
  634. data/manual-snapshots/simple-slide.png +0 -0
  635. data/manual-snapshots/simple-sphere.png +0 -0
  636. data/manual-snapshots/simple-sqlite3.png +0 -0
  637. data/manual-snapshots/simple-timer.png +0 -0
  638. data/manual-snapshots/simple-video.png +0 -0
  639. data/platform/mac/Info.plist +0 -55
  640. data/platform/mac/build-deps.sh +0 -658
  641. data/platform/mac/command-manual.rb +0 -1
  642. data/platform/mac/deps-osx.patch +0 -159
  643. data/platform/mac/dmg_ds_store +0 -0
  644. data/platform/mac/pangorc +0 -2
  645. data/platform/mac/pkg-dmg +0 -1447
  646. data/platform/mac/shoes +0 -31
  647. data/platform/mac/shoes-launch +0 -7
  648. data/platform/mac/stub.m +0 -178
  649. data/platform/mac/version.plist +0 -14
  650. data/platform/msw/base.nsi +0 -644
  651. data/platform/msw/installer-1.bmp +0 -0
  652. data/platform/msw/installer-2.bmp +0 -0
  653. data/platform/msw/shoes.exe.manifest +0 -17
  654. data/platform/msw/shoes.ico +0 -0
  655. data/platform/msw/stub-inject.c +0 -59
  656. data/platform/msw/stub.c +0 -271
  657. data/platform/msw/stub32.h +0 -14
  658. data/platform/msw/stub32.rc +0 -16
  659. data/platform/nix/INSTALL +0 -56
  660. data/platform/nix/Makefile +0 -144
  661. data/platform/nix/shoes.launch +0 -20
  662. data/platform/skel.rb +0 -27
  663. data/rakefile_darwin.rb +0 -7
  664. data/rakefile_linux.rb +0 -3
  665. data/rakefile_mingw.rb +0 -7
  666. data/samples/simple-chipmunk.rb +0 -26
  667. data/samples/simple-menu1.rb +0 -35
  668. data/samples/simple-rubygems.rb +0 -29
  669. data/samples/simple-sqlite3.rb +0 -13
  670. data/shoes/app.c +0 -591
  671. data/shoes/app.h +0 -110
  672. data/shoes/appwin32.h +0 -13
  673. data/shoes/appwin32.rc +0 -28
  674. data/shoes/canvas.c +0 -2202
  675. data/shoes/canvas.h +0 -682
  676. data/shoes/code.h +0 -14
  677. data/shoes/config.h +0 -232
  678. data/shoes/effects.c +0 -243
  679. data/shoes/effects.h +0 -7
  680. data/shoes/http.h +0 -44
  681. data/shoes/http/common.h +0 -86
  682. data/shoes/http/curl.c +0 -259
  683. data/shoes/http/nsurl.m +0 -274
  684. data/shoes/http/windownload.c +0 -114
  685. data/shoes/http/winhttp.c +0 -216
  686. data/shoes/http/winhttp.h +0 -19
  687. data/shoes/image.c +0 -1020
  688. data/shoes/internal.c +0 -46
  689. data/shoes/internal.h +0 -63
  690. data/shoes/native.h +0 -110
  691. data/shoes/native/cocoa.h +0 -105
  692. data/shoes/native/cocoa.m +0 -1557
  693. data/shoes/native/gtk.c +0 -1257
  694. data/shoes/native/windows.c +0 -2392
  695. data/shoes/ruby.c +0 -5221
  696. data/shoes/ruby.h +0 -299
  697. data/shoes/world.c +0 -243
  698. data/shoes/world.h +0 -63
  699. data/static/stubs/blank.exe +0 -0
  700. data/static/stubs/blank.hfz +0 -0
  701. data/static/stubs/blank.run +0 -375
  702. data/static/stubs/cocoa-install +0 -0
  703. data/static/stubs/sh-install +0 -49
  704. data/static/stubs/shoes-stub-inject.exe +0 -0
  705. data/static/stubs/shoes-stub.exe +0 -0
  706. data/test/shoes_test.rb +0 -8
  707. data/test/test_helper.rb +0 -25
  708. data/use-deps +0 -12
  709. data/use-tmp-dep +0 -8
@@ -1,48 +0,0 @@
1
- module Shoes::LogWindow
2
- def setup
3
- stack do
4
- flow do
5
- background black
6
- stack :width => -100 do
7
- tagline "Shoes Console", :stroke => white
8
- end
9
- button "Clear", :margin => 6, :width => 80, :height => 40 do
10
- Shoes.log.clear
11
- end
12
- end
13
- @log, @hash = stack, nil
14
- update
15
- every(0.2) do
16
- update
17
- end
18
- end
19
- end
20
- def update
21
- if @hash != Shoes.log.hash
22
- @hash = Shoes.log.hash
23
- @log.clear do
24
- i = 0
25
- Shoes.log.each do |typ, msg, at, mid, rbf, rbl|
26
- stack do
27
- background "#f1f5e1" if i % 2 == 0
28
- inscription strong(typ.to_s.capitalize, :stroke => "#05C"), " in ",
29
- span(rbf, " line ", rbl, :stroke => "#335"), " | ",
30
- span(at, :stroke => "#777"),
31
- :stroke => "#059", :margin => 4, :margin_bottom => 0
32
- flow do
33
- stack :margin => 6, :width => 20 do
34
- image "#{DIR}/static/icon-#{typ}.png"
35
- end
36
- stack :margin => 4, :width => -20 do
37
- s = msg.to_s.force_encoding "UTF-8"
38
- s << "\n#{msg.backtrace.join("\n")}" if msg.kind_of?(Exception)
39
- para s, :margin => 4, :margin_top => 0
40
- end
41
- end
42
- end
43
- i += 1
44
- end
45
- end
46
- end
47
- end
48
- end
@@ -1,986 +0,0 @@
1
- #!/usr/bin/env ruby
2
- #--
3
- # Archive::Tar::Minitar 0.5.1
4
- # Copyright � 2004 Mauricio Julio Fern�ndez Pradier and Austin Ziegler
5
- #
6
- # This program is based on and incorporates parts of RPA::Package from
7
- # rpa-base (lib/rpa/package.rb and lib/rpa/util.rb) by Mauricio and has been
8
- # adapted to be more generic by Austin.
9
- #
10
- # It is licensed under the GNU General Public Licence or Ruby's licence.
11
- #
12
- # $Id: minitar.rb,v 1.3 2004/09/22 17:47:43 austin Exp $
13
- #++
14
-
15
- module Archive; end
16
- module Archive::Tar; end
17
-
18
- # = Archive::Tar::PosixHeader
19
- # Implements the POSIX tar header as a Ruby class. The structure of
20
- # the POSIX tar header is:
21
- #
22
- # struct tarfile_entry_posix
23
- # { // pack/unpack
24
- # char name[100]; // ASCII (+ Z unless filled) a100/Z100
25
- # char mode[8]; // 0 padded, octal, null a8 /A8
26
- # char uid[8]; // ditto a8 /A8
27
- # char gid[8]; // ditto a8 /A8
28
- # char size[12]; // 0 padded, octal, null a12 /A12
29
- # char mtime[12]; // 0 padded, octal, null a12 /A12
30
- # char checksum[8]; // 0 padded, octal, null, space a8 /A8
31
- # char typeflag[1]; // see below a /a
32
- # char linkname[100]; // ASCII + (Z unless filled) a100/Z100
33
- # char magic[6]; // "ustar\0" a6 /A6
34
- # char version[2]; // "00" a2 /A2
35
- # char uname[32]; // ASCIIZ a32 /Z32
36
- # char gname[32]; // ASCIIZ a32 /Z32
37
- # char devmajor[8]; // 0 padded, octal, null a8 /A8
38
- # char devminor[8]; // 0 padded, octal, null a8 /A8
39
- # char prefix[155]; // ASCII (+ Z unless filled) a155/Z155
40
- # };
41
- #
42
- # The +typeflag+ may be one of the following known values:
43
- #
44
- # <tt>"0"</tt>:: Regular file. NULL should be treated as a synonym, for
45
- # compatibility purposes.
46
- # <tt>"1"</tt>:: Hard link.
47
- # <tt>"2"</tt>:: Symbolic link.
48
- # <tt>"3"</tt>:: Character device node.
49
- # <tt>"4"</tt>:: Block device node.
50
- # <tt>"5"</tt>:: Directory.
51
- # <tt>"6"</tt>:: FIFO node.
52
- # <tt>"7"</tt>:: Reserved.
53
- #
54
- # POSIX indicates that "A POSIX-compliant implementation must treat any
55
- # unrecognized typeflag value as a regular file."
56
- class Archive::Tar::PosixHeader
57
- FIELDS = %w(name mode uid gid size mtime checksum typeflag linkname) +
58
- %w(magic version uname gname devmajor devminor prefix)
59
-
60
- FIELDS.each { |field| attr_reader field.intern }
61
-
62
- HEADER_PACK_FORMAT = "a100a8a8a8a12a12a7aaa100a6a2a32a32a8a8a155"
63
- HEADER_UNPACK_FORMAT = "Z100A8A8A8A12A12A8aZ100A6A2Z32Z32A8A8Z155"
64
-
65
- # Creates a new PosixHeader from a data stream.
66
- def self.new_from_stream(stream)
67
- data = stream.read(512)
68
- fields = data.unpack(HEADER_UNPACK_FORMAT)
69
- name = fields.shift
70
- mode = fields.shift.oct
71
- uid = fields.shift.oct
72
- gid = fields.shift.oct
73
- size = fields.shift.oct
74
- mtime = fields.shift.oct
75
- checksum = fields.shift.oct
76
- typeflag = fields.shift
77
- linkname = fields.shift
78
- magic = fields.shift
79
- version = fields.shift.oct
80
- uname = fields.shift
81
- gname = fields.shift
82
- devmajor = fields.shift.oct
83
- devminor = fields.shift.oct
84
- prefix = fields.shift
85
-
86
- empty = (data == "\0" * 512)
87
-
88
- new(:name => name, :mode => mode, :uid => uid, :gid => gid,
89
- :size => size, :mtime => mtime, :checksum => checksum,
90
- :typeflag => typeflag, :magic => magic, :version => version,
91
- :uname => uname, :gname => gname, :devmajor => devmajor,
92
- :devminor => devminor, :prefix => prefix, :empty => empty)
93
- end
94
-
95
- # Creates a new PosixHeader. A PosixHeader cannot be created unless the
96
- # #name, #size, #prefix, and #mode are provided.
97
- def initialize(vals)
98
- unless vals[:name] && vals[:size] && vals[:prefix] && vals[:mode]
99
- raise ArgumentError
100
- end
101
-
102
- vals[:mtime] ||= 0
103
- vals[:checksum] ||= ""
104
- vals[:typeflag] ||= "0"
105
- vals[:magic] ||= "ustar"
106
- vals[:version] ||= "00"
107
-
108
- FIELDS.each do |field|
109
- instance_variable_set("@#{field}", vals[field.intern])
110
- end
111
- @empty = vals[:empty]
112
- end
113
-
114
- def empty?
115
- @empty
116
- end
117
-
118
- def to_s
119
- update_checksum
120
- header(@checksum)
121
- end
122
-
123
- # Update the checksum field.
124
- def update_checksum
125
- hh = header(" " * 8)
126
- @checksum = oct(calculate_checksum(hh), 6)
127
- end
128
-
129
- private
130
- def oct(num, len)
131
- if num.nil?
132
- "\0" * (len + 1)
133
- else
134
- "%0#{len}o" % num
135
- end
136
- end
137
-
138
- def calculate_checksum(hdr)
139
- hdr.unpack("C*").inject { |aa, bb| aa + bb }
140
- end
141
-
142
- def header(chksum)
143
- arr = [name, oct(mode, 7), oct(uid, 7), oct(gid, 7), oct(size, 11),
144
- oct(mtime, 11), chksum, " ", typeflag, linkname, magic, version,
145
- uname, gname, oct(devmajor, 7), oct(devminor, 7), prefix]
146
- str = arr.pack(HEADER_PACK_FORMAT)
147
- str + "\0" * ((512 - str.size) % 512)
148
- end
149
- end
150
-
151
- require 'fileutils'
152
- require 'find'
153
-
154
- # = Archive::Tar::Minitar 0.5.1
155
- # Archive::Tar::Minitar is a pure-Ruby library and command-line
156
- # utility that provides the ability to deal with POSIX tar(1) archive
157
- # files. The implementation is based heavily on Mauricio Fern�ndez's
158
- # implementation in rpa-base, but has been reorganised to promote
159
- # reuse in other projects.
160
- #
161
- # This tar class performs a subset of all tar (POSIX tape archive)
162
- # operations. We can only deal with typeflags 0, 1, 2, and 5 (see
163
- # Archive::Tar::PosixHeader). All other typeflags will be treated as
164
- # normal files.
165
- #
166
- # NOTE::: support for typeflags 1 and 2 is not yet implemented in this
167
- # version.
168
- #
169
- # This release is version 0.5.1. The library can only handle files and
170
- # directories at this point. A future version will be expanded to
171
- # handle symbolic links and hard links in a portable manner. The
172
- # command line utility, minitar, can only create archives, extract
173
- # from archives, and list archive contents.
174
- #
175
- # == Synopsis
176
- # Using this library is easy. The simplest case is:
177
- #
178
- # require 'zlib'
179
- # require 'archive/tar/minitar'
180
- # include Archive::Tar
181
- #
182
- # # Packs everything that matches Find.find('tests')
183
- # File.open('test.tar', 'wb') { |tar| Minitar.pack('tests', tar) }
184
- # # Unpacks 'test.tar' to 'x', creating 'x' if necessary.
185
- # Minitar.unpack('test.tar', 'x')
186
- #
187
- # A gzipped tar can be written with:
188
- #
189
- # tgz = Zlib::GzipWriter.new(File.open('test.tgz', 'wb'))
190
- # # Warning: tgz will be closed!
191
- # Minitar.pack('tests', tgz)
192
- #
193
- # tgz = Zlib::GzipReader.new(File.open('test.tgz', 'rb'))
194
- # # Warning: tgz will be closed!
195
- # Minitar.unpack(tgz, 'x')
196
- #
197
- # As the case above shows, one need not write to a file. However, it
198
- # will sometimes require that one dive a little deeper into the API,
199
- # as in the case of StringIO objects. Note that I'm not providing a
200
- # block with Minitar::Output, as Minitar::Output#close automatically
201
- # closes both the Output object and the wrapped data stream object.
202
- #
203
- # begin
204
- # sgz = Zlib::GzipWriter.new(StringIO.new(""))
205
- # tar = Output.new(sgz)
206
- # Find.find('tests') do |entry|
207
- # Minitar.pack_file(entry, tar)
208
- # end
209
- # ensure
210
- # # Closes both tar and sgz.
211
- # tar.close
212
- # end
213
- #
214
- # == Copyright
215
- # Copyright 2004 Mauricio Julio Fern�ndez Pradier and Austin Ziegler
216
- #
217
- # This program is based on and incorporates parts of RPA::Package from
218
- # rpa-base (lib/rpa/package.rb and lib/rpa/util.rb) by Mauricio and
219
- # has been adapted to be more generic by Austin.
220
- #
221
- # 'minitar' contains an adaptation of Ruby/ProgressBar by Satoru
222
- # Takabayashi <satoru@namazu.org>, copyright � 2001 - 2004.
223
- #
224
- # This program is free software. It may be redistributed and/or
225
- # modified under the terms of the GPL version 2 (or later) or Ruby's
226
- # licence.
227
- module Archive::Tar::Minitar
228
- VERSION = "0.5.1"
229
-
230
- # The exception raised when a wrapped data stream class is expected to
231
- # respond to #rewind or #pos but does not.
232
- class NonSeekableStream < StandardError; end
233
- # The exception raised when a block is required for proper operation of
234
- # the method.
235
- class BlockRequired < ArgumentError; end
236
- # The exception raised when operations are performed on a stream that has
237
- # previously been closed.
238
- class ClosedStream < StandardError; end
239
- # The exception raised when a filename exceeds 256 bytes in length,
240
- # the maximum supported by the standard Tar format.
241
- class FileNameTooLong < StandardError; end
242
- # The exception raised when a data stream ends before the amount of data
243
- # expected in the archive's PosixHeader.
244
- class UnexpectedEOF < StandardError; end
245
-
246
- # The class that writes a tar format archive to a data stream.
247
- class Writer
248
- # A stream wrapper that can only be written to. Any attempt to read
249
- # from this restricted stream will result in a NameError being thrown.
250
- class RestrictedStream
251
- def initialize(anIO)
252
- @io = anIO
253
- end
254
-
255
- def write(data)
256
- @io.write(data)
257
- end
258
- end
259
-
260
- # A RestrictedStream that also has a size limit.
261
- class BoundedStream < Archive::Tar::Minitar::Writer::RestrictedStream
262
- # The exception raised when the user attempts to write more data to
263
- # a BoundedStream than has been allocated.
264
- class FileOverflow < RuntimeError; end
265
-
266
- # The maximum number of bytes that may be written to this data
267
- # stream.
268
- attr_reader :limit
269
- # The current total number of bytes written to this data stream.
270
- attr_reader :written
271
-
272
- def initialize(io, limit)
273
- @io = io
274
- @limit = limit
275
- @written = 0
276
- end
277
-
278
- def write(data)
279
- raise FileOverflow if (data.size + @written) > @limit
280
- @io.write(data)
281
- @written += data.size
282
- data.size
283
- end
284
- end
285
-
286
- # With no associated block, +Writer::open+ is a synonym for
287
- # +Writer::new+. If the optional code block is given, it will be
288
- # passed the new _writer_ as an argument and the Writer object will
289
- # automatically be closed when the block terminates. In this instance,
290
- # +Writer::open+ returns the value of the block.
291
- def self.open(anIO)
292
- writer = Writer.new(anIO)
293
-
294
- return writer unless block_given?
295
-
296
- begin
297
- res = yield writer
298
- ensure
299
- writer.close
300
- end
301
-
302
- res
303
- end
304
-
305
- # Creates and returns a new Writer object.
306
- def initialize(anIO)
307
- @io = anIO
308
- @closed = false
309
- end
310
-
311
- # Adds a file to the archive as +name+. +opts+ must contain the
312
- # following values:
313
- #
314
- # <tt>:mode</tt>:: The Unix file permissions mode value.
315
- # <tt>:size</tt>:: The size, in bytes.
316
- #
317
- # +opts+ may contain the following values:
318
- #
319
- # <tt>:uid</tt>: The Unix file owner user ID number.
320
- # <tt>:gid</tt>: The Unix file owner group ID number.
321
- # <tt>:mtime</tt>:: The *integer* modification time value.
322
- #
323
- # It will not be possible to add more than <tt>opts[:size]</tt> bytes
324
- # to the file.
325
- def add_file_simple(name, opts = {}) # :yields BoundedStream:
326
- raise Archive::Tar::Minitar::BlockRequired unless block_given?
327
- raise Archive::Tar::ClosedStream if @closed
328
-
329
- name, prefix = split_name(name)
330
-
331
- header = { :name => name, :mode => opts[:mode], :mtime => opts[:mtime],
332
- :size => opts[:size], :gid => opts[:gid], :uid => opts[:uid],
333
- :prefix => prefix }
334
- header = Archive::Tar::PosixHeader.new(header).to_s
335
- @io.write(header)
336
-
337
- os = BoundedStream.new(@io, opts[:size])
338
- yield os
339
- # FIXME: what if an exception is raised in the block?
340
-
341
- min_padding = opts[:size] - os.written
342
- @io.write("\0" * min_padding)
343
- remainder = (512 - (opts[:size] % 512)) % 512
344
- @io.write("\0" * remainder)
345
- end
346
-
347
- # Adds a file to the archive as +name+. +opts+ must contain the
348
- # following value:
349
- #
350
- # <tt>:mode</tt>:: The Unix file permissions mode value.
351
- #
352
- # +opts+ may contain the following values:
353
- #
354
- # <tt>:uid</tt>: The Unix file owner user ID number.
355
- # <tt>:gid</tt>: The Unix file owner group ID number.
356
- # <tt>:mtime</tt>:: The *integer* modification time value.
357
- #
358
- # The file's size will be determined from the amount of data written
359
- # to the stream.
360
- #
361
- # For #add_file to be used, the Archive::Tar::Minitar::Writer must be
362
- # wrapping a stream object that is seekable (e.g., it responds to
363
- # #pos=). Otherwise, #add_file_simple must be used.
364
- #
365
- # +opts+ may be modified during the writing to the stream.
366
- def add_file(name, opts = {}) # :yields RestrictedStream, +opts+:
367
- raise Archive::Tar::Minitar::BlockRequired unless block_given?
368
- raise Archive::Tar::Minitar::ClosedStream if @closed
369
- raise Archive::Tar::Minitar::NonSeekableStream unless @io.respond_to?(:pos=)
370
-
371
- name, prefix = split_name(name)
372
- init_pos = @io.pos
373
- @io.write("\0" * 512) # placeholder for the header
374
-
375
- yield RestrictedStream.new(@io), opts
376
- # FIXME: what if an exception is raised in the block?
377
-
378
- size = @io.pos - (init_pos + 512)
379
- remainder = (512 - (size % 512)) % 512
380
- @io.write("\0" * remainder)
381
-
382
- final_pos = @io.pos
383
- @io.pos = init_pos
384
-
385
- header = { :name => name, :mode => opts[:mode], :mtime => opts[:mtime],
386
- :size => size, :gid => opts[:gid], :uid => opts[:uid],
387
- :prefix => prefix }
388
- header = Archive::Tar::PosixHeader.new(header).to_s
389
- @io.write(header)
390
- @io.pos = final_pos
391
- end
392
-
393
- # Creates a directory in the tar.
394
- def mkdir(name, opts = {})
395
- raise ClosedStream if @closed
396
- name, prefix = split_name(name)
397
- header = { :name => name, :mode => opts[:mode], :typeflag => "5",
398
- :size => 0, :gid => opts[:gid], :uid => opts[:uid],
399
- :mtime => opts[:mtime], :prefix => prefix }
400
- header = Archive::Tar::PosixHeader.new(header).to_s
401
- @io.write(header)
402
- nil
403
- end
404
-
405
- # Passes the #flush method to the wrapped stream, used for buffered
406
- # streams.
407
- def flush
408
- raise ClosedStream if @closed
409
- @io.flush if @io.respond_to?(:flush)
410
- end
411
-
412
- # Closes the Writer.
413
- def close
414
- return if @closed
415
- @io.write("\0" * 1024)
416
- @closed = true
417
- end
418
-
419
- private
420
- def split_name(name)
421
- raise FileNameTooLong if name.size > 256
422
- if name.size <= 100
423
- prefix = ""
424
- else
425
- parts = name.split(/\//)
426
- newname = parts.pop
427
-
428
- nxt = ""
429
-
430
- loop do
431
- nxt = parts.pop
432
- break if newname.size + 1 + nxt.size > 100
433
- newname = "#{nxt}/#{newname}"
434
- end
435
-
436
- prefix = (parts + [nxt]).join("/")
437
-
438
- name = newname
439
-
440
- raise FileNameTooLong if name.size > 100 || prefix.size > 155
441
- end
442
- return name, prefix
443
- end
444
- end
445
-
446
- # The class that reads a tar format archive from a data stream. The data
447
- # stream may be sequential or random access, but certain features only work
448
- # with random access data streams.
449
- class Reader
450
- # This marks the EntryStream closed for reading without closing the
451
- # actual data stream.
452
- module InvalidEntryStream
453
- def read(len = nil); raise ClosedStream; end
454
- def getc; raise ClosedStream; end
455
- def rewind; raise ClosedStream; end
456
- end
457
-
458
- # EntryStreams are pseudo-streams on top of the main data stream.
459
- class EntryStream
460
- Archive::Tar::PosixHeader::FIELDS.each do |field|
461
- attr_reader field.intern
462
- end
463
-
464
- def initialize(header, anIO)
465
- @io = anIO
466
- @name = header.name
467
- @mode = header.mode
468
- @uid = header.uid
469
- @gid = header.gid
470
- @size = header.size
471
- @mtime = header.mtime
472
- @checksum = header.checksum
473
- @typeflag = header.typeflag
474
- @linkname = header.linkname
475
- @magic = header.magic
476
- @version = header.version
477
- @uname = header.uname
478
- @gname = header.gname
479
- @devmajor = header.devmajor
480
- @devminor = header.devminor
481
- @prefix = header.prefix
482
- @read = 0
483
- @orig_pos = @io.pos
484
- end
485
-
486
- # Reads +len+ bytes (or all remaining data) from the entry. Returns
487
- # +nil+ if there is no more data to read.
488
- def read(len = nil)
489
- return nil if @read >= @size
490
- len ||= @size - @read
491
- max_read = [len, @size - @read].min
492
- ret = @io.read(max_read)
493
- @read += ret.size
494
- ret
495
- end
496
-
497
- # Reads one byte from the entry. Returns +nil+ if there is no more data
498
- # to read.
499
- def getc
500
- return nil if @read >= @size
501
- ret = @io.getc
502
- @read += 1 if ret
503
- ret
504
- end
505
-
506
- # Returns +true+ if the entry represents a directory.
507
- def directory?
508
- @typeflag == "5"
509
- end
510
- alias_method :directory, :directory?
511
-
512
- # Returns +true+ if the entry represents a plain file.
513
- def file?
514
- @typeflag == "0"
515
- end
516
- alias_method :file, :file?
517
-
518
- # Returns +true+ if the current read pointer is at the end of the
519
- # EntryStream data.
520
- def eof?
521
- @read >= @size
522
- end
523
-
524
- # Returns the current read pointer in the EntryStream.
525
- def pos
526
- @read
527
- end
528
-
529
- # Sets the current read pointer to the beginning of the EntryStream.
530
- def rewind
531
- raise NonSeekableStream unless @io.respond_to?(:pos=)
532
- @io.pos = @orig_pos
533
- @read = 0
534
- end
535
-
536
- def orig_pos
537
- @orig_pos
538
- end
539
-
540
- def bytes_read
541
- @read
542
- end
543
-
544
- # Returns the full and proper name of the entry.
545
- def full_name
546
- if @prefix != ""
547
- File.join(@prefix, @name)
548
- else
549
- @name
550
- end
551
- end
552
-
553
- # Closes the entry.
554
- def close
555
- invalidate
556
- end
557
-
558
- private
559
- def invalidate
560
- extend InvalidEntryStream
561
- end
562
- end
563
-
564
- # With no associated block, +Reader::open+ is a synonym for
565
- # +Reader::new+. If the optional code block is given, it will be passed
566
- # the new _writer_ as an argument and the Reader object will
567
- # automatically be closed when the block terminates. In this instance,
568
- # +Reader::open+ returns the value of the block.
569
- def self.open(anIO)
570
- reader = Reader.new(anIO)
571
-
572
- return reader unless block_given?
573
-
574
- begin
575
- res = yield reader
576
- ensure
577
- reader.close
578
- end
579
-
580
- res
581
- end
582
-
583
- # Creates and returns a new Reader object.
584
- def initialize(anIO)
585
- @io = anIO
586
- @init_pos = anIO.pos
587
- end
588
-
589
- # Iterates through each entry in the data stream.
590
- def each(&block)
591
- each_entry(&block)
592
- end
593
-
594
- # Resets the read pointer to the beginning of data stream. Do not call
595
- # this during a #each or #each_entry iteration. This only works with
596
- # random access data streams that respond to #rewind and #pos.
597
- def rewind
598
- if @init_pos == 0
599
- raise NonSeekableStream unless @io.respond_to?(:rewind)
600
- @io.rewind
601
- else
602
- raise NonSeekableStream unless @io.respond_to?(:pos=)
603
- @io.pos = @init_pos
604
- end
605
- end
606
-
607
- # Iterates through each entry in the data stream.
608
- def each_entry
609
- loop do
610
- return if @io.eof?
611
-
612
- header = Archive::Tar::PosixHeader.new_from_stream(@io)
613
- return if header.empty?
614
-
615
- entry = EntryStream.new(header, @io)
616
- size = entry.size
617
-
618
- yield entry
619
-
620
- skip = (512 - (size % 512)) % 512
621
-
622
- if @io.respond_to?(:seek)
623
- # avoid reading...
624
- @io.seek(size - entry.bytes_read, IO::SEEK_CUR)
625
- else
626
- pending = size - entry.bytes_read
627
- while pending > 0
628
- bread = @io.read([pending, 4096].min).size
629
- raise UnexpectedEOF if @io.eof?
630
- pending -= bread
631
- end
632
- end
633
- @io.read(skip) # discard trailing zeros
634
- # make sure nobody can use #read, #getc or #rewind anymore
635
- entry.close
636
- end
637
- end
638
-
639
- def close
640
- end
641
- end
642
-
643
- # Wraps a Archive::Tar::Minitar::Reader with convenience methods and
644
- # wrapped stream management; Input only works with random access data
645
- # streams. See Input::new for details.
646
- class Input
647
- include Enumerable
648
-
649
- # With no associated block, +Input::open+ is a synonym for
650
- # +Input::new+. If the optional code block is given, it will be passed
651
- # the new _writer_ as an argument and the Input object will
652
- # automatically be closed when the block terminates. In this instance,
653
- # +Input::open+ returns the value of the block.
654
- def self.open(input)
655
- stream = Input.new(input)
656
- return stream unless block_given?
657
-
658
- begin
659
- res = yield stream
660
- ensure
661
- stream.close
662
- end
663
-
664
- res
665
- end
666
-
667
- # Creates a new Input object. If +input+ is a stream object that responds
668
- # to #read), then it will simply be wrapped. Otherwise, one will be
669
- # created and opened using Kernel#open. When Input#close is called, the
670
- # stream object wrapped will be closed.
671
- def initialize(input)
672
- if input.respond_to?(:read)
673
- @io = input
674
- else
675
- @io = open(input, "rb")
676
- end
677
- @tarreader = Archive::Tar::Minitar::Reader.new(@io)
678
- end
679
-
680
- # Iterates through each entry and rewinds to the beginning of the stream
681
- # when finished.
682
- def each(&block)
683
- @tarreader.each { |entry| yield entry }
684
- ensure
685
- @tarreader.rewind
686
- end
687
-
688
- # Extracts the current +entry+ to +destdir+. If a block is provided, it
689
- # yields an +action+ Symbol, the full name of the file being extracted
690
- # (+name+), and a Hash of statistical information (+stats+).
691
- #
692
- # The +action+ will be one of:
693
- # <tt>:dir</tt>:: The +entry+ is a directory.
694
- # <tt>:file_start</tt>:: The +entry+ is a file; the extract of the
695
- # file is just beginning.
696
- # <tt>:file_progress</tt>:: Yielded every 4096 bytes during the extract
697
- # of the +entry+.
698
- # <tt>:file_done</tt>:: Yielded when the +entry+ is completed.
699
- #
700
- # The +stats+ hash contains the following keys:
701
- # <tt>:current</tt>:: The current total number of bytes read in the
702
- # +entry+.
703
- # <tt>:currinc</tt>:: The current number of bytes read in this read
704
- # cycle.
705
- # <tt>:entry</tt>:: The entry being extracted; this is a
706
- # Reader::EntryStream, with all methods thereof.
707
- def extract_entry(destdir, entry) # :yields action, name, stats:
708
- stats = {
709
- :current => 0,
710
- :currinc => 0,
711
- :entry => entry
712
- }
713
-
714
- if entry.directory?
715
- dest = File.join(destdir, entry.full_name)
716
-
717
- yield :dir, entry.full_name, stats if block_given?
718
-
719
- if Archive::Tar::Minitar.dir?(dest)
720
- begin
721
- FileUtils.chmod(entry.mode, dest)
722
- rescue Exception
723
- nil
724
- end
725
- else
726
- FileUtils.mkdir_p(dest, :mode => entry.mode)
727
- FileUtils.chmod(entry.mode, dest)
728
- end
729
-
730
- fsync_dir(dest)
731
- fsync_dir(File.join(dest, ".."))
732
- return
733
- else # it's a file
734
- destdir = File.join(destdir, File.dirname(entry.full_name))
735
- FileUtils.mkdir_p(destdir, :mode => 0755)
736
-
737
- destfile = File.join(destdir, File.basename(entry.full_name))
738
- FileUtils.chmod(0600, destfile) rescue nil # Errno::ENOENT
739
-
740
- yield :file_start, entry.full_name, stats if block_given?
741
-
742
- File.open(destfile, "wb", entry.mode) do |os|
743
- loop do
744
- data = entry.read(4096)
745
- break unless data
746
-
747
- stats[:currinc] = os.write(data)
748
- stats[:current] += stats[:currinc]
749
-
750
- yield :file_progress, entry.full_name, stats if block_given?
751
- end
752
- os.fsync
753
- end
754
-
755
- FileUtils.chmod(entry.mode, destfile)
756
- fsync_dir(File.dirname(destfile))
757
- fsync_dir(File.join(File.dirname(destfile), ".."))
758
-
759
- yield :file_done, entry.full_name, stats if block_given?
760
- end
761
- end
762
-
763
- # Returns the Reader object for direct access.
764
- def tar
765
- @tarreader
766
- end
767
-
768
- # Closes the Reader object and the wrapped data stream.
769
- def close
770
- @io.close
771
- @tarreader.close
772
- end
773
-
774
- private
775
- def fsync_dir(dirname)
776
- # make sure this hits the disc
777
- dir = open(dirname, 'rb')
778
- dir.fsync
779
- rescue # ignore IOError if it's an unpatched (old) Ruby
780
- nil
781
- ensure
782
- dir.close if dir rescue nil
783
- end
784
- end
785
-
786
- # Wraps a Archive::Tar::Minitar::Writer with convenience methods and
787
- # wrapped stream management; Output only works with random access data
788
- # streams. See Output::new for details.
789
- class Output
790
- # With no associated block, +Output::open+ is a synonym for
791
- # +Output::new+. If the optional code block is given, it will be passed
792
- # the new _writer_ as an argument and the Output object will
793
- # automatically be closed when the block terminates. In this instance,
794
- # +Output::open+ returns the value of the block.
795
- def self.open(output)
796
- stream = Output.new(output)
797
- return stream unless block_given?
798
-
799
- begin
800
- res = yield stream
801
- ensure
802
- stream.close
803
- end
804
-
805
- res
806
- end
807
-
808
- # Creates a new Output object. If +output+ is a stream object that
809
- # responds to #read), then it will simply be wrapped. Otherwise, one will
810
- # be created and opened using Kernel#open. When Output#close is called,
811
- # the stream object wrapped will be closed.
812
- def initialize(output)
813
- if output.respond_to?(:write)
814
- @io = output
815
- else
816
- @io = ::File.open(output, "wb")
817
- end
818
- @tarwriter = Archive::Tar::Minitar::Writer.new(@io)
819
- end
820
-
821
- # Returns the Writer object for direct access.
822
- def tar
823
- @tarwriter
824
- end
825
-
826
- # Closes the Writer object and the wrapped data stream.
827
- def close
828
- @tarwriter.close
829
- @io.close
830
- end
831
- end
832
-
833
- class << self
834
- # Tests if +path+ refers to a directory. Fixes an apparently
835
- # corrupted <tt>stat()</tt> call on Windows.
836
- def dir?(path)
837
- File.directory?((path[-1] == ?/) ? path : "#{path}/")
838
- end
839
-
840
- # A convenience method for wrapping Archive::Tar::Minitar::Input.open
841
- # (mode +r+) and Archive::Tar::Minitar::Output.open (mode +w+). No other
842
- # modes are currently supported.
843
- def open(dest, mode = "r", &block)
844
- case mode
845
- when "r"
846
- Input.open(dest, &block)
847
- when "w"
848
- Output.open(dest, &block)
849
- else
850
- raise "Unknown open mode for Archive::Tar::Minitar.open."
851
- end
852
- end
853
-
854
- # A convenience method to packs the file provided. +entry+ may either be
855
- # a filename (in which case various values for the file (see below) will
856
- # be obtained from <tt>File#stat(entry)</tt> or a Hash with the fields:
857
- #
858
- # <tt>:name</tt>:: The filename to be packed into the tarchive.
859
- # *REQUIRED*.
860
- # <tt>:mode</tt>:: The mode to be applied.
861
- # <tt>:uid</tt>:: The user owner of the file. (Ignored on Windows.)
862
- # <tt>:gid</tt>:: The group owner of the file. (Ignored on Windows.)
863
- # <tt>:mtime</tt>:: The modification Time of the file.
864
- #
865
- # During packing, if a block is provided, #pack_file yields an +action+
866
- # Symol, the full name of the file being packed, and a Hash of
867
- # statistical information, just as with
868
- # Archive::Tar::Minitar::Input#extract_entry.
869
- #
870
- # The +action+ will be one of:
871
- # <tt>:dir</tt>:: The +entry+ is a directory.
872
- # <tt>:file_start</tt>:: The +entry+ is a file; the extract of the
873
- # file is just beginning.
874
- # <tt>:file_progress</tt>:: Yielded every 4096 bytes during the extract
875
- # of the +entry+.
876
- # <tt>:file_done</tt>:: Yielded when the +entry+ is completed.
877
- #
878
- # The +stats+ hash contains the following keys:
879
- # <tt>:current</tt>:: The current total number of bytes read in the
880
- # +entry+.
881
- # <tt>:currinc</tt>:: The current number of bytes read in this read
882
- # cycle.
883
- # <tt>:name</tt>:: The filename to be packed into the tarchive.
884
- # *REQUIRED*.
885
- # <tt>:mode</tt>:: The mode to be applied.
886
- # <tt>:uid</tt>:: The user owner of the file. (+nil+ on Windows.)
887
- # <tt>:gid</tt>:: The group owner of the file. (+nil+ on Windows.)
888
- # <tt>:mtime</tt>:: The modification Time of the file.
889
- def pack_file(entry, outputter) #:yields action, name, stats:
890
- outputter = outputter.tar if outputter.kind_of?(Archive::Tar::Minitar::Output)
891
-
892
- stats = {}
893
-
894
- if entry.kind_of?(Hash)
895
- name = entry[:name]
896
-
897
- entry.each { |kk, vv| stats[kk] = vv unless vv.nil? }
898
- else
899
- name = entry
900
- end
901
-
902
- name = name.sub(%r{\./}, '')
903
- stat = File.stat(name)
904
- stats[:mode] ||= stat.mode
905
- stats[:mtime] ||= stat.mtime
906
- stats[:size] = stat.size
907
- if name == "sh-install" # an ugly shoes-specific hack, to
908
- stats[:mode] = 0755 # get the file to be 0755 on windows
909
- end
910
-
911
- if RUBY_PLATFORM =~ /win32/
912
- stats[:uid] = nil
913
- stats[:gid] = nil
914
- else
915
- stats[:uid] ||= stat.uid
916
- stats[:gid] ||= stat.gid
917
- end
918
-
919
- case
920
- when File.file?(name)
921
- outputter.add_file_simple(name, stats) do |os|
922
- stats[:current] = 0
923
- yield :file_start, name, stats if block_given?
924
- File.open(name, "rb") do |ff|
925
- until ff.eof?
926
- stats[:currinc] = os.write(ff.read(4096))
927
- stats[:current] += stats[:currinc]
928
- yield :file_progress, name, stats if block_given?
929
- end
930
- end
931
- yield :file_done, name, stats if block_given?
932
- end
933
- when dir?(name)
934
- yield :dir, name, stats if block_given?
935
- outputter.mkdir(name, stats)
936
- else
937
- raise "Don't yet know how to pack this type of file."
938
- end
939
- end
940
-
941
- # A convenience method to pack files specified by +src+ into +dest+. If
942
- # +src+ is an Array, then each file detailed therein will be packed into
943
- # the resulting Archive::Tar::Minitar::Output stream; if +recurse_dirs+
944
- # is true, then directories will be recursed.
945
- #
946
- # If +src+ is an Array, it will be treated as the argument to Find.find;
947
- # all files matching will be packed.
948
- def pack(src, dest, recurse_dirs = true, &block)
949
- Output.open(dest) do |outp|
950
- if src.kind_of?(Array)
951
- src.each do |entry|
952
- pack_file(entry, outp, &block)
953
- if dir?(entry) and recurse_dirs
954
- Dir["#{entry}/**/**"].each do |ee|
955
- pack_file(ee, outp, &block)
956
- end
957
- end
958
- end
959
- else
960
- Find.find(src) do |entry|
961
- pack_file(entry, outp, &block)
962
- end
963
- end
964
- end
965
- end
966
-
967
- # A convenience method to unpack files from +src+ into the directory
968
- # specified by +dest+. Only those files named explicitly in +files+
969
- # will be extracted.
970
- def unpack(src, dest, files = [], &block)
971
- Input.open(src) do |inp|
972
- if File.exist?(dest) and (not dir?(dest))
973
- raise "Can't unpack to a non-directory."
974
- elsif not File.exist?(dest)
975
- FileUtils.mkdir_p(dest)
976
- end
977
-
978
- inp.each do |entry|
979
- if files.empty? or files.include?(entry.full_name)
980
- inp.extract_entry(dest, entry, &block)
981
- end
982
- end
983
- end
984
- end
985
- end
986
- end