sprout 0.7.246 → 1.0.0.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 (211) hide show
  1. data/CHANGELOG.md +10 -0
  2. data/Gemfile +28 -0
  3. data/MIT-LICENSE +3 -2
  4. data/POSTINSTALL.rdoc +28 -0
  5. data/README.textile +152 -0
  6. data/bin/sprout +1 -131
  7. data/bin/sprout-generator +10 -0
  8. data/bin/sprout-library +11 -0
  9. data/bin/sprout-tool +10 -0
  10. data/lib/sprout.rb +4 -500
  11. data/lib/sprout/archive_unpacker.rb +122 -206
  12. data/lib/sprout/base.rb +90 -0
  13. data/lib/sprout/concern.rb +30 -0
  14. data/lib/sprout/dir.rb +23 -0
  15. data/lib/sprout/errors.rb +94 -0
  16. data/lib/sprout/executable.rb +496 -0
  17. data/lib/sprout/executable/boolean.rb +35 -0
  18. data/lib/sprout/executable/collection_param.rb +53 -0
  19. data/lib/sprout/executable/file_param.rb +53 -0
  20. data/lib/sprout/executable/files.rb +26 -0
  21. data/lib/sprout/executable/number.rb +10 -0
  22. data/lib/sprout/executable/param.rb +222 -0
  23. data/lib/sprout/executable/parameter_factory.rb +28 -0
  24. data/lib/sprout/executable/path.rb +21 -0
  25. data/lib/sprout/executable/paths.rb +21 -0
  26. data/lib/sprout/executable/string_param.rb +15 -0
  27. data/lib/sprout/executable/strings.rb +11 -0
  28. data/lib/sprout/executable/url.rb +10 -0
  29. data/lib/sprout/executable/urls.rb +10 -0
  30. data/lib/sprout/file_target.rb +76 -0
  31. data/lib/sprout/generator/base.rb +233 -0
  32. data/lib/sprout/generator/command.rb +67 -0
  33. data/lib/sprout/generator/directory_manifest.rb +49 -0
  34. data/lib/sprout/generator/file_manifest.rb +55 -0
  35. data/lib/sprout/generator/manifest.rb +13 -0
  36. data/lib/sprout/generator/template_manifest.rb +13 -0
  37. data/lib/sprout/generators/generator/generator_generator.rb +48 -0
  38. data/lib/sprout/generators/generator/templates/generator_class.rb +17 -0
  39. data/lib/sprout/generators/generator/templates/generator_executable +9 -0
  40. data/lib/sprout/generators/generator/templates/generator_template +1 -0
  41. data/lib/sprout/generators/generator/templates/generator_test.rb +37 -0
  42. data/lib/sprout/generators/generator/templates/generator_test_helper.rb +16 -0
  43. data/lib/sprout/generators/library/library_generator.rb +20 -0
  44. data/lib/sprout/generators/library/templates/library.gemspec +19 -0
  45. data/lib/sprout/generators/library/templates/library.rb +15 -0
  46. data/lib/sprout/generators/ruby/ruby_generator.rb +59 -0
  47. data/lib/sprout/generators/ruby/templates/ruby_base.rb +10 -0
  48. data/lib/sprout/generators/ruby/templates/ruby_executable +6 -0
  49. data/lib/sprout/generators/ruby/templates/ruby_gemfile +4 -0
  50. data/lib/sprout/generators/ruby/templates/ruby_input.rb +7 -0
  51. data/lib/sprout/generators/tool/templates/Gemfile +4 -0
  52. data/lib/sprout/generators/tool/templates/tool.gemspec +22 -0
  53. data/lib/sprout/generators/tool/templates/tool.rb +38 -0
  54. data/lib/sprout/generators/tool/tool_generator.rb +36 -0
  55. data/lib/sprout/library.rb +111 -0
  56. data/lib/sprout/log.rb +1 -0
  57. data/lib/sprout/platform.rb +71 -0
  58. data/lib/sprout/process_runner.rb +80 -40
  59. data/lib/sprout/progress_bar.rb +341 -0
  60. data/lib/sprout/rdoc_parser.rb +91 -0
  61. data/lib/sprout/remote_file_loader.rb +72 -50
  62. data/lib/sprout/remote_file_target.rb +44 -152
  63. data/lib/sprout/ruby_feature.rb +167 -0
  64. data/lib/sprout/specification.rb +197 -0
  65. data/lib/sprout/string.rb +19 -0
  66. data/lib/sprout/system.rb +35 -0
  67. data/lib/sprout/system/base_system.rb +225 -0
  68. data/lib/sprout/system/java_system.rb +9 -0
  69. data/lib/sprout/system/osx_system.rb +26 -0
  70. data/lib/sprout/system/unix_system.rb +72 -0
  71. data/lib/sprout/system/vista_system.rb +16 -0
  72. data/lib/sprout/system/win_nix_system.rb +41 -0
  73. data/lib/sprout/system/win_system.rb +76 -0
  74. data/lib/sprout/test/sprout_test_case.rb +211 -0
  75. data/lib/sprout/version.rb +9 -4
  76. data/rakefile.rb +85 -144
  77. data/script/console +10 -0
  78. data/script/destroy +14 -0
  79. data/script/generate +14 -0
  80. data/sprout.gemspec +26 -0
  81. data/test/fixtures/archive_unpacker/copyable/some_file.exe +0 -0
  82. data/test/fixtures/archive_unpacker/copyable/some_file.rb +0 -0
  83. data/test/fixtures/archive_unpacker/copyable/some_file.swc +0 -0
  84. data/test/fixtures/archive_unpacker/tgz/some folder.tgz +0 -0
  85. data/test/fixtures/archive_unpacker/tgz/some_file.tgz +0 -0
  86. data/test/fixtures/archive_unpacker/zip/some folder.zip +0 -0
  87. data/test/fixtures/archive_unpacker/zip/some_file.zip +0 -0
  88. data/test/fixtures/examples/app_generator.rb +127 -0
  89. data/test/fixtures/examples/echo_inputs.rb +151 -0
  90. data/test/fixtures/executable/echochamber_gem/bin/echochamber +3 -0
  91. data/test/fixtures/executable/echochamber_gem/echo_chamber.rb +10 -0
  92. data/test/fixtures/executable/flex3sdk_gem/flex3sdk.rb +11 -0
  93. data/test/fixtures/executable/flex3sdk_gem/mxmlc +3 -0
  94. data/test/fixtures/executable/flex3sdk_gem/mxmlc.bat +3 -0
  95. data/test/fixtures/executable/mxmlc.rb +805 -0
  96. data/test/fixtures/executable/params/input.as +0 -0
  97. data/test/fixtures/executable/params/input2.as +0 -0
  98. data/test/fixtures/executable/params/input3.as +0 -0
  99. data/test/fixtures/executable/params/mxmlc +5 -0
  100. data/test/fixtures/executable/path with spaces/input.as b/data/test/fixtures/executable/path with → spaces/input.as +0 -0
  101. data/test/fixtures/executable/path with spaces/input2.as b/data/test/fixtures/executable/path with → spaces/input2.as +0 -0
  102. data/test/fixtures/executable/path with spaces/input3.as b/data/test/fixtures/executable/path with → spaces/input3.as +0 -0
  103. data/test/fixtures/executable/paths/folder1/file1 +0 -0
  104. data/test/fixtures/executable/paths/folder1/file2 +0 -0
  105. data/test/fixtures/executable/paths/folder1/file3 +0 -0
  106. data/test/fixtures/executable/paths/folder2/file4 +0 -0
  107. data/test/fixtures/executable/paths/folder2/file5 +0 -0
  108. data/test/fixtures/executable/paths/folder3/file6 +0 -0
  109. data/test/fixtures/executable/src/Main.as +0 -0
  110. data/test/fixtures/executable/windows_line_endings +47 -0
  111. data/test/fixtures/generators/song_generator.rb +11 -0
  112. data/test/fixtures/generators/song_subclass/least_favorite.rb +10 -0
  113. data/test/fixtures/generators/song_subclass/templates/Song.txt +3 -0
  114. data/test/fixtures/generators/temp_generator.rb +24 -0
  115. data/test/fixtures/generators/templates/Main.as +9 -0
  116. data/test/fixtures/generators/templates/OtherFileTemplate +1 -0
  117. data/test/fixtures/generators/templates/SomeFile +1 -0
  118. data/test/fixtures/generators/templates/SomeSubclassFile +2 -0
  119. data/test/fixtures/generators/templates/Song.txt +3 -0
  120. data/test/fixtures/generators/templates/destroy +0 -0
  121. data/test/fixtures/generators/templates/generate +0 -0
  122. data/test/fixtures/library/archive/Archive.swc +0 -0
  123. data/test/fixtures/library/sources/lib/a/A.as +0 -0
  124. data/test/fixtures/library/sources/lib/b/B.as +0 -0
  125. data/test/fixtures/library/sources/src/Source.as +0 -0
  126. data/test/fixtures/process_runner/chmod_script.sh +3 -0
  127. data/test/fixtures/process_runner/dir with spaces/chmod_script.sh +3 -0
  128. data/test/fixtures/process_runner/failure +5 -0
  129. data/test/fixtures/process_runner/success +4 -0
  130. data/test/fixtures/remote_file_loader/md5/echochamber-test.zip +0 -0
  131. data/test/fixtures/remote_file_loader/md5/file_with_known_md5 +0 -0
  132. data/test/fixtures/remote_file_target/bin/echochamber +3 -0
  133. data/test/fixtures/remote_file_target/bin/echochamber.bat +3 -0
  134. data/test/fixtures/remote_file_target/echochamber-test.zip +0 -0
  135. data/test/fixtures/specification/asunit4.rb +25 -0
  136. data/test/fixtures/specification/ext/AsUnit-4.1.pre.swc +0 -0
  137. data/test/fixtures/specification/flashplayer.rb +30 -0
  138. data/test/fixtures/specification/flex4sdk.rb +72 -0
  139. data/test/fixtures/specification/flexunit4.sproutspec +17 -0
  140. data/test/fixtures/specification/lib/as3reflection/Reflection.as +0 -0
  141. data/test/fixtures/specification/src/AsUnit.as +0 -0
  142. data/test/fixtures/user/mxmlc_crlf +3 -0
  143. data/test/unit/archive_unpacker_test.rb +108 -0
  144. data/test/unit/boolean_param_test.rb +38 -0
  145. data/test/unit/executable_option_parser_test.rb +142 -0
  146. data/test/unit/executable_param_test.rb +76 -0
  147. data/test/unit/executable_test.rb +237 -0
  148. data/test/unit/fake_executable_task.rb +22 -0
  149. data/test/unit/fake_other_executable.rb +20 -0
  150. data/test/unit/fake_process_runner.rb +29 -0
  151. data/test/unit/file_param_test.rb +61 -0
  152. data/test/unit/file_target_test.rb +42 -0
  153. data/test/unit/files_param_test.rb +72 -0
  154. data/test/unit/generator_generator_test.rb +85 -0
  155. data/test/unit/generator_test.rb +333 -0
  156. data/test/unit/library_generator_test.rb +41 -0
  157. data/test/unit/library_test.rb +88 -0
  158. data/test/unit/osx_system_test.rb +20 -0
  159. data/test/unit/path_param_test.rb +43 -0
  160. data/test/unit/paths_param_test.rb +53 -0
  161. data/test/unit/platform_test.rb +76 -0
  162. data/test/unit/process_runner_test.rb +104 -0
  163. data/test/unit/rdoc_parser_test.rb +15 -0
  164. data/test/unit/remote_file_loader_test.rb +34 -0
  165. data/test/unit/remote_file_target_test.rb +105 -0
  166. data/test/unit/ruby_feature_test.rb +108 -0
  167. data/test/unit/ruby_generator_test.rb +70 -0
  168. data/test/unit/specification_test.rb +73 -0
  169. data/test/unit/sprout_test.rb +170 -0
  170. data/test/unit/sprout_test_helper.rb +18 -0
  171. data/test/unit/string_param_test.rb +19 -0
  172. data/test/unit/string_test.rb +20 -0
  173. data/test/unit/strings_param_test.rb +27 -0
  174. data/test/unit/test_helper.rb +1 -0
  175. data/test/unit/tool_generator_test.rb +43 -0
  176. data/test/unit/unix_system_test.rb +52 -0
  177. data/test/unit/user_test.rb +147 -0
  178. data/test/unit/vista_system_test.rb +40 -0
  179. data/test/unit/win_nix_system_test.rb +26 -0
  180. data/test/unit/win_system_test.rb +61 -0
  181. metadata +318 -113
  182. data/doc/Bundle +0 -14
  183. data/doc/Generator +0 -35
  184. data/doc/Library +0 -63
  185. data/doc/Task +0 -21
  186. data/doc/Tool +0 -20
  187. data/lib/platform.rb +0 -113
  188. data/lib/progress_bar.rb +0 -354
  189. data/lib/sprout/builder.rb +0 -51
  190. data/lib/sprout/bundle_resolver.rb +0 -349
  191. data/lib/sprout/commands/generate.rb +0 -9
  192. data/lib/sprout/dynamic_accessors.rb +0 -40
  193. data/lib/sprout/general_tasks.rb +0 -6
  194. data/lib/sprout/generator.rb +0 -7
  195. data/lib/sprout/generator/base_mixins.rb +0 -186
  196. data/lib/sprout/generator/named_base.rb +0 -227
  197. data/lib/sprout/project_model.rb +0 -278
  198. data/lib/sprout/simple_resolver.rb +0 -88
  199. data/lib/sprout/tasks/erb_resolver.rb +0 -118
  200. data/lib/sprout/tasks/gem_wrap_task.rb +0 -214
  201. data/lib/sprout/tasks/git_task.rb +0 -134
  202. data/lib/sprout/tasks/library_task.rb +0 -118
  203. data/lib/sprout/tasks/sftp_task.rb +0 -248
  204. data/lib/sprout/tasks/ssh_task.rb +0 -153
  205. data/lib/sprout/tasks/tool_task.rb +0 -836
  206. data/lib/sprout/tasks/zip_task.rb +0 -158
  207. data/lib/sprout/tool_task_model.rb +0 -19
  208. data/lib/sprout/user.rb +0 -415
  209. data/lib/sprout/version_file.rb +0 -89
  210. data/lib/sprout/zip_util.rb +0 -61
  211. data/samples/gem_wrap/rakefile.rb +0 -17
@@ -1,118 +0,0 @@
1
- =begin
2
- Copyright (c) 2007 Pattern Park
3
-
4
- Permission is hereby granted, free of charge, to any person obtaining
5
- a copy of this software and associated documentation files (the
6
- "Software"), to deal in the Software without restriction, including
7
- without limitation the rights to use, copy, modify, merge, publish,
8
- distribute, sublicense, and/or sell copies of the Software, and to
9
- permit persons to whom the Software is furnished to do so, subject to
10
- the following conditions:
11
-
12
- The above copyright notice and this permission notice shall be
13
- included in all copies or substantial portions of the Software.
14
-
15
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
16
- EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
17
- MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
18
- NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
19
- LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
20
- OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
21
- WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
22
- =end
23
-
24
- module Sprout
25
- class LibraryError < StandardError #:nodoc:
26
- end
27
-
28
- # :include: ../../../doc/Library
29
- class LibraryTask < Rake::Task
30
-
31
- # The RubyGems gem version string for this library (e.g., +version = '0.0.1'+)
32
- attr_accessor :version
33
-
34
- attr_writer :gem_name # :nodoc:
35
- attr_writer :project_lib # :nodoc:
36
-
37
- def self.define_task(args, &block) # :nodoc:
38
- t = super
39
- yield t if block_given?
40
- t.define
41
- end
42
-
43
- # The full gem name like 'sprout-asunit3-library'
44
- def gem_name
45
- @gem_name ||= "sprout-#{clean_name}-library"
46
- end
47
-
48
- # Ensure that namespaced rake tasks only use
49
- # the final part for name-based features
50
- def clean_name
51
- return name.split(':').pop
52
- end
53
-
54
- # The path to the library source or swc that will be copied into your project.
55
- # This can actually be any full or relative path on your system, but should almost
56
- # always be left alone for automatic resolution.
57
- def library_path
58
- @library_path ||= nil
59
- end
60
-
61
- # Override the the project folder where the library will be installed.
62
- #
63
- # By default, libraries are installed into Sprout::ProjectModel +lib_dir+.
64
- def project_lib
65
- if(library_path.index('.swc'))
66
- @project_lib ||= ProjectModel.instance.swc_dir
67
- else
68
- @project_lib ||= ProjectModel.instance.lib_dir
69
- end
70
- end
71
-
72
- # Unlike other rake tasks, Library tasks are actually
73
- # resolved at 'define' time. This allows the tool tasks
74
- # to build their own dependencies (like file deps)
75
- # (I'm sure there's a better way to do this, if you know how to fix this,
76
- # and would like to contribute to sprouts, this might be a good spot for it)
77
- def define
78
- @file_target = sprout(gem_name, version)
79
- @library_path = File.join(@file_target.installed_path, @file_target.archive_path)
80
- define_file_task(library_path, project_path)
81
- end
82
-
83
- def execute(*args) # :nodoc:
84
- super
85
- end
86
-
87
- # The path within the project where this library is installed
88
- def project_path
89
- if(File.directory?(@library_path))
90
- # library is source dir
91
- File.join(project_lib, clean_name)
92
- else
93
- # library is a binary (like swc, jar, etc)
94
- File.join(project_lib, File.basename(@file_target.archive_path))
95
- end
96
- end
97
-
98
- private
99
-
100
- def define_file_task(source, destination)
101
- file destination do |t|
102
- lib_path = library_path
103
- #FileUtils.makedirs(destination)
104
- if(File.directory?(lib_path))
105
- lib_path = "#{lib_path}/."
106
- end
107
- FileUtils.cp_r(lib_path, destination)
108
- end
109
- prerequisites << destination
110
- end
111
-
112
- end
113
- end
114
-
115
- # Helper method for definining and accessing LibraryTask instances in a rakefile
116
- def library(args, &block)
117
- Sprout::LibraryTask.define_task(args, &block)
118
- end
@@ -1,248 +0,0 @@
1
- =begin
2
- Copyright (c) 2007 Pattern Park
3
-
4
- Permission is hereby granted, free of charge, to any person obtaining
5
- a copy of this software and associated documentation files (the
6
- "Software"), to deal in the Software without restriction, including
7
- without limitation the rights to use, copy, modify, merge, publish,
8
- distribute, sublicense, and/or sell copies of the Software, and to
9
- permit persons to whom the Software is furnished to do so, subject to
10
- the following conditions:
11
-
12
- The above copyright notice and this permission notice shall be
13
- included in all copies or substantial portions of the Software.
14
-
15
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
16
- EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
17
- MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
18
- NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
19
- LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
20
- OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
21
- WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
22
-
23
- This class has been commented out because the termios feature
24
- that allows users to more securely enter passwords does not
25
- work in a DOS shell.
26
-
27
- It would be greatly appreciate if someone refactored this to either:
28
- a) Get the same functionality in a cross-platform manner
29
- b) Only require and use termios on systems that allow it
30
- =end
31
-
32
- #gem 'net-ssh', '1.1.4'
33
- #gem 'net-sftp', '1.1.1'
34
-
35
- require 'net/ssh'
36
- require 'net/sftp'
37
-
38
- #require 'termios'
39
-
40
- module Sprout
41
- class SFTPError < StandardError #:nodoc:
42
- end
43
-
44
- # The SFTPTask provides a simple rake task interface to the SFTP client RubyGem.
45
- # This task can allow you to easily push build artifacts to a remote server
46
- # with a single shell command.
47
- class SFTPTask < Rake::Task
48
-
49
- # Collection of files that should be transmitted to the remote server
50
- attr_accessor :files
51
- # Host name of the server to connect to with no protocol prefix, like: sub.yourhost.com
52
- attr_accessor :host
53
- # Username to send to the remote host. You will be prompted for this value if it is left null.
54
- #
55
- # NOTE: You should never check a file into version control with this field filled in, it is
56
- # provided here as a convenience for getting set up.
57
- attr_accessor :username
58
- # The mode for transmitted files. Defaults to 0644
59
- attr_accessor :file_mode
60
- # the mode for created directories. Defaults to 0755
61
- attr_accessor :dir_mode
62
- # The local path to mask from transmitted files. This is key feature for automated file transmission.
63
- # For example, if you are sending a file:
64
- # bin/assets/img/SomeImage.jpg
65
- # into a directory on your server like:
66
- # /var/www/someproject/
67
- # You don't necessarily want the 'bin' folder copied over, so you set the local_path to 'bin' like:
68
- # t.local_path = 'bin'
69
- # and your server will have the file uploaded to:
70
- # /var/www/someproject/assets/img/SomeImage.jpg
71
- attr_accessor :local_path
72
- # The Remote base path where files should be transmitted, can be absolute or relative.
73
- attr_accessor :remote_path
74
- # Password to send to the remote host. You will be prompted for this value if it is left null.
75
- #
76
- # NOTE: You should never check a file into version control with this field filled in, it is
77
- # provided here as a convenience for getting set up.
78
- attr_accessor :password
79
-
80
- def initialize(task_name, app)
81
- super(task_name, app)
82
- @name = name
83
- @files = []
84
- @dir_mode = 0755
85
- @file_mode = 0644
86
- @host = nil
87
- end
88
-
89
- def self.define_task(args, &block) # :nodoc:
90
- t = super
91
- yield t if block_given?
92
- end
93
-
94
- def execute(*args) # :nodoc:
95
- if(@files.size == 0)
96
- if(@local_path)
97
- expr = @local_path + '/**/**/*'
98
- @files = FileList[expr]
99
- else
100
- raise SFTPError.new('SFTP requires either a local_path or files to be transmitted')
101
- end
102
- else
103
- if(!@local_path)
104
- @local_path = ''
105
- end
106
- end
107
-
108
- if(@host.nil?)
109
- raise SFTPError.new('SFTP requires non-nil host parameter')
110
- end
111
-
112
- if(@username.nil?)
113
- print "Username: "
114
- @username = $stdin.gets.chomp!
115
- raise SFTPError.new('SFTP requires username parameter') unless @username
116
- end
117
-
118
- if(@password.nil?)
119
- print "Password: "
120
- @password = $stdin.gets.chomp!
121
- # @password = Password.get
122
- raise SFTPError.new('SFTP requires password parameter') unless @password
123
- end
124
-
125
- if(get_confirmation)
126
- puts ">> Connecting to Remote Server: #{@username}@#{@host}:#{@remote_path}"
127
-
128
- Net::SFTP.start(@host, @username, :password => @password, :keys => []) do |sftp|
129
- begin
130
- dir = sftp.opendir(@remote_path)
131
- rescue Net::SFTP::Operations::StatusException
132
- puts "[ERROR] [#{@remote_path}] does not exist on the server"
133
- return
134
- end
135
- for file in @files
136
- next if File.stat(file).directory?
137
- remote_file = remote_file_name(file)
138
- put_file(file, remote_file, sftp)
139
- end
140
- end
141
- else
142
- puts "[WARNING] Publish aborted by user request"
143
- end
144
- end
145
-
146
- def put_file(local_file, remote_file, sftp) # :nodoc:
147
- begin
148
- create_remote_dir(remote_file, sftp)
149
-
150
- if(file_changed(local_file, remote_file, sftp))
151
- puts ">> Pushing #{local_file} to: #{remote_file}"
152
- sftp.put_file(local_file, remote_file)
153
- end
154
- rescue Net::SFTP::Operations::StatusException => e
155
- raise unless e.code == 2
156
- sftp.put_file(local_file, remote_file)
157
- sftp.setstat(remote_file, :permissions => @file_mode)
158
- end
159
- end
160
-
161
- def create_remote_dir(path, sftp) # :nodoc:
162
- begin
163
- sftp.stat(File.dirname(path))
164
- rescue Net::SFTP::Operations::StatusException => e
165
- raise unless e.code == 2
166
- dir = File.dirname(path.sub(@remote_path, ''))
167
- parts = dir.split(File::SEPARATOR)
168
- part = File.join(@remote_path, parts.shift)
169
- while(part)
170
- begin
171
- sftp.stat(part)
172
- rescue Net::SFTP::Operations::StatusException => ne
173
- raise unless ne.code == 2
174
- sftp.mkdir(part, :permissions => @dir_mode)
175
- end
176
- if(parts.size > 0)
177
- part = File.join(part, parts.shift)
178
- else
179
- part = nil
180
- end
181
- end
182
- end
183
- end
184
-
185
- def file_changed(local_file, remote_file, sftp) # :nodoc:
186
- local_stat = File.stat(local_file)
187
- remote_stat = sftp.stat(remote_file)
188
- time_difference = (local_stat.mtime > Time.at(remote_stat.mtime))
189
- size_difference = (local_stat.size != remote_stat.size)
190
- return (time_difference || size_difference)
191
- end
192
-
193
- def remote_file_name(file) # :nodoc:
194
- return @remote_path + file.sub(@local_path, '')
195
- end
196
-
197
- def get_confirmation # :nodoc:
198
- puts "-----------------------------------------"
199
- puts "Are you sure you want to publish #{@files.size} files to:"
200
- puts "#{@username}@#{@host}:#{@remote_path}? [Yn]"
201
- response = $stdin.gets.chomp!
202
- return (response.downcase == 'y' || response == "")
203
- end
204
-
205
- end
206
-
207
- =begin
208
- # The following implementation does not work at all on DOS machines,
209
- # is there a cross-platform way to solve the secure password prompt problem?
210
- # Password handling snippet found at: http://www.caliban.org/ruby/ruby-password.shtml
211
- class Password
212
-
213
- def Password.get(message="Password: ")
214
- begin
215
- if $stdin.tty?
216
- Password.echo false
217
- print message if message
218
- end
219
-
220
- return $stdin.gets.chomp
221
- ensure
222
- if $stdin.tty?
223
- Password.echo true
224
- print "\n"
225
- end
226
- end
227
- end
228
-
229
- def Password.echo(on=true, masked=false)
230
- term = Termios::getattr( $stdin )
231
-
232
- if on
233
- term.c_lflag |= ( Termios::ECHO | Termios::ICANON )
234
- else # off
235
- term.c_lflag &= ~Termios::ECHO
236
- term.c_lflag &= ~Termios::ICANON if masked
237
- end
238
-
239
- Termios::setattr( $stdin, Termios::TCSANOW, term )
240
- end
241
- end
242
- =end
243
- end
244
-
245
-
246
- def sftp(args, &block)
247
- Sprout::SFTPTask.define_task(args, &block)
248
- end
@@ -1,153 +0,0 @@
1
- =begin
2
- Copyright (c) 2007 Pattern Park
3
-
4
- Permission is hereby granted, free of charge, to any person obtaining
5
- a copy of this software and associated documentation files (the
6
- "Software"), to deal in the Software without restriction, including
7
- without limitation the rights to use, copy, modify, merge, publish,
8
- distribute, sublicense, and/or sell copies of the Software, and to
9
- permit persons to whom the Software is furnished to do so, subject to
10
- the following conditions:
11
-
12
- The above copyright notice and this permission notice shall be
13
- included in all copies or substantial portions of the Software.
14
-
15
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
16
- EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
17
- MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
18
- NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
19
- LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
20
- OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
21
- WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
22
-
23
- This class has been commented out because the termios feature
24
- that allows users to more securely enter passwords does not
25
- work in a DOS shell.
26
-
27
- It would be greatly appreciate if someone refactored this to either:
28
- a) Get the same functionality in a cross-platform manner
29
- b) Only require and use termios on systems that allow it
30
- =end
31
-
32
- #gem 'net-ssh', '1.1.4'
33
- #gem 'net-sftp', '1.1.1'
34
-
35
- require 'net/ssh'
36
- require 'net/sftp'
37
- #require 'termios'
38
-
39
- module Sprout
40
- class SSHError < StandardError #:nodoc:
41
- end
42
-
43
- # The SSHTask allows you to execute arbitrary commands on a remote host.
44
- #
45
- # ssh :update_gem_index do |t|
46
- # t.host = 'dev.projectsprouts.com'
47
- # t.username = 'someUser'
48
- # t.commands << 'cd /var/www/projectsprouts/current/gems'
49
- # t.commands << 'gem generate_index -d .'
50
- # end
51
- #
52
- class SSHTask < Rake::Task
53
-
54
- # Host name of the server to connect to with no protocol prefix, like: sub.yourhost.com
55
- attr_accessor :host
56
- # Array of commands that will be executed on the remote machine
57
- attr_accessor :commands
58
- # Username to send to the remote host. You will be prompted for this value if it is left null.
59
- attr_accessor :username
60
- # Password to send to the remote host. You will be prompted for this value if it is left null.
61
- #
62
- # NOTE: You should never check a file into version control with this field filled in, it is
63
- # provided here as a convenience for getting set up.
64
- attr_accessor :password
65
-
66
- def initialize(task_name, app)
67
- super(task_name, app)
68
- @name = name
69
- @host = nil
70
- @queue = []
71
- @commands = []
72
- end
73
-
74
- def self.define_task(args, &block) # :nodoc:
75
- t = super
76
- yield t if block_given?
77
- end
78
-
79
- def execute(*args) # :nodoc:
80
- if(@host.nil?)
81
- throw SSHError.new('SSH requires a valid host parameter')
82
- end
83
-
84
- if(@username.nil?)
85
- print "Username: "
86
- @username = $stdin.gets.chomp!
87
- raise SFTPError.new('SFTP requires username parameter') unless @username
88
- end
89
-
90
- if(@password.nil?)
91
- print "Password: "
92
- @password = $stdin.gets.chomp!
93
- # @password = Password.get
94
- raise SFTPError.new('SFTP requires password parameter') unless @password
95
- end
96
-
97
- puts ">> Connecting to Remote Server: #{@username}@#{@host}:#{@remote_path}"
98
- Net::SSH.start(@host, @username, @password) do |session|
99
- session.open_channel do |channel|
100
- commands.each do |command|
101
- puts ">> #{command}"
102
- channel.exec command
103
- end
104
- channel.close
105
- end
106
- session.loop
107
- end
108
- end
109
-
110
- end
111
-
112
- =begin
113
- # The following implementation does not work at all on DOS machines,
114
- # is there a cross-platform way to solve the secure password prompt problem?
115
- # Password handling snippet found at: http://www.caliban.org/ruby/ruby-password.shtml
116
- class Password
117
-
118
- def Password.get(message="Password: ")
119
- begin
120
- if $stdin.tty?
121
- Password.echo false
122
- print message if message
123
- end
124
-
125
- return $stdin.gets.chomp
126
- ensure
127
- if $stdin.tty?
128
- Password.echo true
129
- print "\n"
130
- end
131
- end
132
- end
133
-
134
- def Password.echo(on=true, masked=false)
135
- term = Termios::getattr( $stdin )
136
-
137
- if on
138
- term.c_lflag |= ( Termios::ECHO | Termios::ICANON )
139
- else # off
140
- term.c_lflag &= ~Termios::ECHO
141
- term.c_lflag &= ~Termios::ICANON if masked
142
- end
143
-
144
- Termios::setattr( $stdin, Termios::TCSANOW, term )
145
- end
146
- end
147
- =end
148
- end
149
-
150
-
151
- def ssh(args, &block)
152
- Sprout::SSHTask.define_task(args, &block)
153
- end