ronin-gen 0.2.0 → 1.0.0.pre1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (87) hide show
  1. data/.document +4 -0
  2. data/.rspec +1 -0
  3. data/.yardopts +1 -0
  4. data/ChangeLog.md +41 -0
  5. data/Gemfile +27 -0
  6. data/{README.txt → README.md} +30 -21
  7. data/Rakefile +24 -20
  8. data/bin/ronin-gen +27 -8
  9. data/data/ronin/gen/library/.document +5 -0
  10. data/data/ronin/gen/library/.gitignore +10 -0
  11. data/data/ronin/gen/library/.rspec +1 -0
  12. data/data/ronin/gen/library/.yardopts.erb +1 -0
  13. data/data/ronin/gen/library/COPYING.txt +339 -0
  14. data/data/ronin/gen/library/ChangeLog.md.erb +4 -0
  15. data/data/ronin/gen/library/Gemfile.erb +23 -0
  16. data/data/ronin/gen/library/README.md.erb +46 -0
  17. data/data/ronin/gen/library/Rakefile +30 -0
  18. data/data/ronin/gen/library/bin/ronin-command.erb +25 -0
  19. data/data/ronin/gen/library/bin/ronin-name.erb +27 -0
  20. data/data/ronin/gen/library/gemspec.yml.erb +20 -0
  21. data/data/ronin/gen/library/lib/ronin/_license.erb +19 -0
  22. data/data/ronin/gen/library/lib/ronin/gen/generators/generator.rb.erb +22 -0
  23. data/data/ronin/gen/library/lib/ronin/name.rb.erb +3 -0
  24. data/data/ronin/gen/library/lib/ronin/name/version.rb.erb +8 -0
  25. data/data/ronin/gen/library/lib/ronin/ui/command_line/commands/command.rb.erb +22 -0
  26. data/data/ronin/gen/library/library.gemspec.erb +10 -0
  27. data/data/ronin/gen/library/spec/name/name_spec.rb.erb +8 -0
  28. data/data/ronin/gen/library/spec/spec_helper.rb.erb +4 -0
  29. data/data/ronin/gen/repository/.rspec +1 -0
  30. data/data/ronin/gen/repository/Rakefile.erb +32 -0
  31. data/data/ronin/gen/repository/ronin.yml.erb +18 -0
  32. data/{static/ronin/generators/platform → data/ronin/gen/repository}/spec/spec_helper.rb +0 -0
  33. data/gemspec.yml +24 -0
  34. data/lib/ronin/gen.rb +26 -0
  35. data/lib/ronin/{ui/command_line/commands/gen_overlay.rb → gen/config.rb} +6 -8
  36. data/lib/ronin/{generators → gen}/dir_generator.rb +25 -21
  37. data/lib/ronin/{generators.rb → gen/exceptions.rb} +2 -5
  38. data/lib/ronin/{generators/platform/static.rb → gen/exceptions/unknown_generator.rb} +3 -6
  39. data/lib/ronin/gen/file_generator.rb +73 -0
  40. data/lib/ronin/gen/gen.rb +85 -0
  41. data/lib/ronin/gen/generatable.rb +36 -0
  42. data/lib/ronin/gen/generator.rb +312 -0
  43. data/lib/ronin/{ui/command_line/commands/gen_extension.rb → gen/generators.rb} +8 -9
  44. data/lib/ronin/gen/generators/library.rb +196 -0
  45. data/lib/ronin/gen/generators/repository.rb +130 -0
  46. data/lib/ronin/gen/ruby_generator.rb +34 -0
  47. data/lib/ronin/gen/source_code_generator.rb +46 -0
  48. data/lib/ronin/{generators → gen}/version.rb +3 -3
  49. data/lib/ronin/ui/{command_line → cli}/commands/gen.rb +18 -19
  50. data/ronin-gen.gemspec +10 -0
  51. data/spec/gen/classes/basic_generator.rb +16 -0
  52. data/spec/gen/classes/dir_generator.rb +9 -0
  53. data/spec/{generators → gen}/classes/file_generator.rb +2 -2
  54. data/spec/{generators → gen}/classes/templated_generator.rb +3 -3
  55. data/spec/gen/classes/touch_generator.rb +9 -0
  56. data/spec/gen/gen_spec.rb +22 -0
  57. data/spec/gen/generator_spec.rb +68 -0
  58. data/spec/gen/generators/library_spec.rb +132 -0
  59. data/spec/gen/generators/repository_spec.rb +92 -0
  60. data/spec/gen/helpers/data.rb +9 -0
  61. data/spec/{generators/helpers/static → gen/helpers/data}/generators/templated.txt.erb +0 -0
  62. data/spec/spec_helper.rb +3 -5
  63. metadata +190 -114
  64. data.tar.gz.sig +0 -0
  65. data/History.txt +0 -41
  66. data/Manifest.txt +0 -39
  67. data/bin/ronin-gen-extension +0 -12
  68. data/bin/ronin-gen-overlay +0 -12
  69. data/lib/ronin/generators/generator.rb +0 -165
  70. data/lib/ronin/generators/platform/extension.rb +0 -52
  71. data/lib/ronin/generators/platform/overlay.rb +0 -223
  72. data/spec/generated_extension_examples.rb +0 -27
  73. data/spec/generated_overlay_examples.rb +0 -72
  74. data/spec/generators/classes/dir_generator.rb +0 -9
  75. data/spec/generators/classes/touch_generator.rb +0 -9
  76. data/spec/generators/generator_spec.rb +0 -50
  77. data/spec/generators/generators_spec.rb +0 -9
  78. data/spec/generators/helpers/generators.rb +0 -3
  79. data/spec/generators/platform/extension_spec.rb +0 -22
  80. data/spec/generators/platform/overlay_spec.rb +0 -36
  81. data/spec/ui/command_line/commands/gen_extension_spec.rb +0 -22
  82. data/spec/ui/command_line/commands/gen_overlay_spec.rb +0 -38
  83. data/static/ronin/generators/platform/Rakefile.erb +0 -5
  84. data/static/ronin/generators/platform/extension.rb +0 -9
  85. data/tasks/spec.rb +0 -10
  86. data/tasks/yard.rb +0 -13
  87. metadata.gz.sig +0 -0
@@ -1,7 +1,7 @@
1
1
  #
2
2
  # Ronin Gen - A Ruby library for Ronin that provides various generators.
3
3
  #
4
- # Copyright (c) 2009 Hal Brodigan (postmodern.mod3 at gmail.com)
4
+ # Copyright (c) 2009-2010 Hal Brodigan (postmodern.mod3 at example.com)
5
5
  #
6
6
  # This program is free software; you can redistribute it and/or modify
7
7
  # it under the terms of the GNU General Public License as published by
@@ -18,7 +18,4 @@
18
18
  # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
19
19
  #
20
20
 
21
- require 'ronin/generators/generator'
22
- require 'ronin/generators/dir_generator'
23
- require 'ronin/generators/platform'
24
- require 'ronin/generators/version'
21
+ require 'ronin/gen/exceptions/unknown_generator'
@@ -1,7 +1,7 @@
1
1
  #
2
2
  # Ronin Gen - A Ruby library for Ronin that provides various generators.
3
3
  #
4
- # Copyright (c) 2009 Hal Brodigan (postmodern.mod3 at example.com)
4
+ # Copyright (c) 2009-2010 Hal Brodigan (postmodern.mod3 at example.com)
5
5
  #
6
6
  # This program is free software; you can redistribute it and/or modify
7
7
  # it under the terms of the GNU General Public License as published by
@@ -18,12 +18,9 @@
18
18
  # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
19
19
  #
20
20
 
21
- require 'ronin/static'
22
-
23
21
  module Ronin
24
- module Generators
25
- module Platform
26
- Static.directory File.join(File.dirname(__FILE__),'..','..','..','..','static')
22
+ module Gen
23
+ class UnknownGenerator < StandardError
27
24
  end
28
25
  end
29
26
  end
@@ -0,0 +1,73 @@
1
+ #
2
+ # Ronin Gen - A Ruby library for Ronin that provides various generators.
3
+ #
4
+ # Copyright (c) 2009-2010 Hal Brodigan (postmodern.mod3 at gmail.com)
5
+ #
6
+ # This program is free software; you can redistribute it and/or modify
7
+ # it under the terms of the GNU General Public License as published by
8
+ # the Free Software Foundation; either version 2 of the License, or
9
+ # (at your option) any later version.
10
+ #
11
+ # This program is distributed in the hope that it will be useful,
12
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
13
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14
+ # GNU General Public License for more details.
15
+ #
16
+ # You should have received a copy of the GNU General Public License
17
+ # along with this program; if not, write to the Free Software
18
+ # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
19
+ #
20
+
21
+ require 'ronin/gen/generator'
22
+
23
+ module Ronin
24
+ module Gen
25
+ #
26
+ # A {Generator} class for creating files.
27
+ #
28
+ class FileGenerator < Generator
29
+
30
+ argument :path, :type => :string, :require => true
31
+
32
+ #
33
+ # Generates the file at the given path.
34
+ #
35
+ def self.generate(options={},arguments=[])
36
+ super(options,arguments) do |gen|
37
+ if (self.file_extension && File.extname(gen.path).empty?)
38
+ gen.path += ".#{self.file_extension}"
39
+ end
40
+
41
+ yield gen if block_given?
42
+ end
43
+ end
44
+
45
+ protected
46
+
47
+ #
48
+ # The file extension to append to all paths.
49
+ #
50
+ # @return [String, nil]
51
+ # The file extension.
52
+ #
53
+ # @since 1.0.0
54
+ #
55
+ def self.file_extension
56
+ @file_extension
57
+ end
58
+
59
+ #
60
+ # Sets the file extension to append to all paths.
61
+ #
62
+ # @param [String] ext
63
+ # The file extension.
64
+ #
65
+ # @since 1.0.0
66
+ #
67
+ def self.file_extension!(ext)
68
+ @file_extension = ext.to_s
69
+ end
70
+
71
+ end
72
+ end
73
+ end
@@ -0,0 +1,85 @@
1
+ #
2
+ # Ronin Gen - A Ruby library for Ronin that provides various generators.
3
+ #
4
+ # Copyright (c) 2009-2010 Hal Brodigan (postmodern.mod3 at example.com)
5
+ #
6
+ # This program is free software; you can redistribute it and/or modify
7
+ # it under the terms of the GNU General Public License as published by
8
+ # the Free Software Foundation; either version 2 of the License, or
9
+ # (at your option) any later version.
10
+ #
11
+ # This program is distributed in the hope that it will be useful,
12
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
13
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14
+ # GNU General Public License for more details.
15
+ #
16
+ # You should have received a copy of the GNU General Public License
17
+ # along with this program; if not, write to the Free Software
18
+ # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
19
+ #
20
+
21
+ require 'ronin/gen/exceptions/unknown_generator'
22
+ require 'ronin/gen/generators'
23
+ require 'ronin/installation'
24
+
25
+ module Ronin
26
+ module Gen
27
+ #
28
+ # Loads the generator with the given name.
29
+ #
30
+ # @param [String] name
31
+ # The colon separated name of the generator.
32
+ #
33
+ # @return [Generator, nil]
34
+ # The loaded generator. If `nil` is returned, then the generator
35
+ # could not be found.
36
+ #
37
+ # @raise [UnknownGenerator]
38
+ # The generator could not be found or loaded.
39
+ #
40
+ # @example
41
+ # Gen.generator 'library'
42
+ # # => Ronin::Gen::Generators::Library
43
+ #
44
+ # @example Load a generator within a namespace
45
+ # Gen.generator 'exploits:remote_tcp'
46
+ # # => Ronin::Gen::Generators::Exploits::RemoteTcp
47
+ #
48
+ # @since 1.0.0
49
+ #
50
+ def Gen.generator(name)
51
+ name = name.to_s
52
+ path = name.gsub(/[_-]+/,'_').gsub(/:+/,File::SEPARATOR)
53
+
54
+ unless (generator = Generators.require_const(path))
55
+ raise(UnknownGenerator,"unknown generator #{name.dump}")
56
+ end
57
+
58
+ return generator
59
+ end
60
+
61
+ #
62
+ # The names of all available generators.
63
+ #
64
+ # @return [Hash]
65
+ # The names and paths of all installed generators.
66
+ #
67
+ # @since 0.3.0
68
+ #
69
+ def Gen.generators
70
+ unless defined?(@@ronin_gen_generators)
71
+ directory = File.join('lib',Generators.namespace_root)
72
+
73
+ @@ronin_gen_generators = {}
74
+
75
+ Installation.each_file(directory) do |path|
76
+ name = path.gsub(/\.rb$/,'').split(File::SEPARATOR).join(':')
77
+
78
+ @@ronin_gen_generators[name] = path
79
+ end
80
+ end
81
+
82
+ return @@ronin_gen_generators
83
+ end
84
+ end
85
+ end
@@ -0,0 +1,36 @@
1
+ #
2
+ # Ronin Gen - A Ruby library for Ronin that provides various generators.
3
+ #
4
+ # Copyright (c) 2009-2010 Hal Brodigan (postmodern.mod3 at example.com)
5
+ #
6
+ # This program is free software; you can redistribute it and/or modify
7
+ # it under the terms of the GNU General Public License as published by
8
+ # the Free Software Foundation; either version 2 of the License, or
9
+ # (at your option) any later version.
10
+ #
11
+ # This program is distributed in the hope that it will be useful,
12
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
13
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14
+ # GNU General Public License for more details.
15
+ #
16
+ # You should have received a copy of the GNU General Public License
17
+ # along with this program; if not, write to the Free Software
18
+ # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
19
+ #
20
+
21
+ module Ronin
22
+ module Gen
23
+ module Generatable
24
+ #
25
+ # Default method which will be called upon generation.
26
+ #
27
+ # @param [String] path
28
+ # The path to pass to the generator.
29
+ #
30
+ # @since 1.0.0
31
+ #
32
+ def generate(path)
33
+ end
34
+ end
35
+ end
36
+ end
@@ -0,0 +1,312 @@
1
+ #
2
+ # Ronin Gen - A Ruby library for Ronin that provides various generators.
3
+ #
4
+ # Copyright (c) 2009-2010 Hal Brodigan (postmodern.mod3 at example.com)
5
+ #
6
+ # This program is free software; you can redistribute it and/or modify
7
+ # it under the terms of the GNU General Public License as published by
8
+ # the Free Software Foundation; either version 2 of the License, or
9
+ # (at your option) any later version.
10
+ #
11
+ # This program is distributed in the hope that it will be useful,
12
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
13
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14
+ # GNU General Public License for more details.
15
+ #
16
+ # You should have received a copy of the GNU General Public License
17
+ # along with this program; if not, write to the Free Software
18
+ # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
19
+ #
20
+
21
+ require 'ronin/templates/template'
22
+
23
+ require 'data_paths/finders'
24
+ require 'extlib'
25
+ require 'erb'
26
+ require 'thor'
27
+ require 'thor/group'
28
+ require 'thor/actions'
29
+
30
+ module Ronin
31
+ module Gen
32
+ #
33
+ # The {Generator} class leverages `Thor::Group` and `Thor::Actions`
34
+ # to create a generic generator class. The generator class can
35
+ # define `class_options` that can be used to parse command-line
36
+ # arguments or set directly in Ruby.
37
+ #
38
+ # # Extending
39
+ #
40
+ # To create a new type of generator one can extend {Generator},
41
+ # {FileGenerator} or {DirGenerator} classes. The new generator can
42
+ # define it's own `class_options`, which are made available to other
43
+ # classes that extend our generator. The functionality of the generator
44
+ # is defined via instance methods, which are called sequentially when
45
+ # the generator is invoked.
46
+ #
47
+ # require 'ronin/gen/file_generator'
48
+ #
49
+ # module Ronin
50
+ # module Gen
51
+ # module Generators
52
+ # class MyGenerator < FileGenerator
53
+ #
54
+ # desc 'My generator'
55
+ #
56
+ # # generator options
57
+ # class_option :stuff, :type => :boolean
58
+ # class_option :syntax, :type => :string
59
+ # class_option :includes, :type => :array
60
+ #
61
+ # #
62
+ # # Performs the generation.
63
+ # #
64
+ # def generate
65
+ # erb 'some_template.erb', self.path
66
+ # end
67
+ #
68
+ # end
69
+ # end
70
+ # end
71
+ # end
72
+ #
73
+ # # Invoking
74
+ #
75
+ # To invoke the generator from ruby, one can call the {generate}
76
+ # class method with the options and arguments to run the generator with:
77
+ #
78
+ # MyGenerator.generate(
79
+ # {:stuff => true, :syntax => 'bla', :includes => ['other']}
80
+ # ['path/to/file'],
81
+ # )
82
+ #
83
+ # To make your generator accessible to the `ronin-gen` command, simply
84
+ # place your generator file within the `ronin/gen/generators` directory
85
+ # of any Ronin library. If your generator class is named
86
+ # `MyGenerator`, than it's ruby file must be named `my_generator.rb`.
87
+ #
88
+ # To run the generator using the `ronin-gen` command, simply specify
89
+ # it's underscored name:
90
+ #
91
+ # ronin-gen my_generator path/to/file --stuff --syntax bla --includes other
92
+ #
93
+ class Generator < Thor::Group
94
+
95
+ include Thor::Actions
96
+ include Templates::Template
97
+ include DataPaths::Finders
98
+
99
+ def self.inherited(super_class)
100
+ class_name = super_class.name.sub('Ronin::Gen::Generators::','')
101
+ gen_name = class_name.split('::').join(':').snake_case
102
+
103
+ super_class.namespace(gen_name)
104
+ end
105
+
106
+ #
107
+ # Defines the default source root of the generator as the current
108
+ # working directory.
109
+ #
110
+ # @since 0.2.0
111
+ #
112
+ def self.source_root
113
+ @generator_source_root ||= Dir.pwd
114
+ end
115
+
116
+ #
117
+ # Sets the source root of the generator.
118
+ #
119
+ # @param [String] new_dir
120
+ # The new source root directory.
121
+ #
122
+ # @return [String]
123
+ # The source root directory of the generator.
124
+ #
125
+ # @since 1.0.0
126
+ #
127
+ def self.source_root=(new_dir)
128
+ @genereator_source_root = File.expand_path(new_dir)
129
+ end
130
+
131
+ #
132
+ # Invokes the generator.
133
+ #
134
+ # @param [Hash] options
135
+ # Class options to use with the generator.
136
+ #
137
+ # @param [Array] arguments
138
+ # Additional arguments for the generator.
139
+ #
140
+ # @yield [generator]
141
+ # The given block will be passed the new generator.
142
+ #
143
+ # @yieldparam [Generator] generator
144
+ # The newly created generator object.
145
+ #
146
+ # @return [Generator]
147
+ # The generate object.
148
+ #
149
+ # @example
150
+ # gen.generate
151
+ #
152
+ # @since 0.2.0
153
+ #
154
+ def self.generate(options={},arguments=[],&block)
155
+ generator = self.new(arguments,options,&block)
156
+ generator.invoke_all()
157
+
158
+ return generator
159
+ end
160
+
161
+ desc "default generator task"
162
+
163
+ #
164
+ # Default generator method.
165
+ #
166
+ # @since 0.2.0
167
+ #
168
+ def generate
169
+ end
170
+
171
+ protected
172
+
173
+ #
174
+ # Initializes the generator.
175
+ #
176
+ # @param [Array] arguments
177
+ # Additional arguments for the generator.
178
+ #
179
+ # @param [Hash] options
180
+ # Options to pass to the generator.
181
+ #
182
+ # @param [Hash] config
183
+ # Additional configuration for the generator.
184
+ #
185
+ # @since 1.0.0
186
+ #
187
+ def initialize(arguments=[],options={},config={})
188
+ super(arguments,options,config)
189
+
190
+ setup()
191
+
192
+ yield self if block_given?
193
+ end
194
+
195
+ #
196
+ # Default method to initialize any instance variables before any of
197
+ # the tasks are invoked.
198
+ #
199
+ # @since 1.0.0
200
+ #
201
+ def setup
202
+ end
203
+
204
+ #
205
+ # Touches a file.
206
+ #
207
+ # @param [String] destination
208
+ # The relative path to the file to touch.
209
+ #
210
+ # @example
211
+ # touch 'TODO.txt'
212
+ #
213
+ # @since 0.2.0
214
+ #
215
+ def touch(destination)
216
+ create_file(destination)
217
+ end
218
+
219
+ #
220
+ # Creates an empty directory.
221
+ #
222
+ # @param [String] destination
223
+ # The relative path of the directory to create.
224
+ #
225
+ # @example
226
+ # directory 'sub/dir'
227
+ #
228
+ # @since 0.2.0
229
+ #
230
+ def mkdir(destination)
231
+ empty_directory(destination)
232
+ end
233
+
234
+ #
235
+ # Copies a data file.
236
+ #
237
+ # @param [String] data_file
238
+ # The relative path to the data file.
239
+ #
240
+ # @param [String] destination
241
+ # The destination to copy the data file to.
242
+ #
243
+ # @example
244
+ # copy_file 'ronin/platform/generators/extension.rb',
245
+ # 'myext/extension.rb'
246
+ #
247
+ # @since 0.2.0
248
+ #
249
+ def cp(data_file,destination)
250
+ copy_file(find_data_file(data_file),destination)
251
+ end
252
+
253
+ #
254
+ # Copies the contents of all data directories.
255
+ #
256
+ # @param [String] data_dir
257
+ # The data directories to copy from.
258
+ #
259
+ # @param [String, nil] destination
260
+ # The optional destination directory to copy the files to.
261
+ #
262
+ # @param [Hash] config
263
+ # The optional configuration information.
264
+ #
265
+ # @option config [Boolean] :recursive (false)
266
+ # Recursively copies the contents.
267
+ #
268
+ # @since 1.0.0
269
+ #
270
+ def cp_r(data_dir,destination=nil,config={})
271
+ each_data_dir(data_dir) do |dir|
272
+ directory(dir,destination || data_dir,config)
273
+ end
274
+ end
275
+
276
+ #
277
+ # Renders the ERB template at the specified _template_path_ and
278
+ # saves the result at the given _destination_.
279
+ #
280
+ # @param [String] template_path
281
+ # The relative path to the template.
282
+ #
283
+ # @param [String, nil] destination
284
+ # The destination to write the result of the rendered template to.
285
+ #
286
+ # @return [nil, String]
287
+ # If destination is `nil`, the result of the rendered template
288
+ # will be returned.
289
+ #
290
+ # @example
291
+ # erb 'ronin/platform/generators/Rakefile.erb', 'Rakefile.erb'
292
+ #
293
+ # @example
294
+ # erb '_helpers.erb'
295
+ #
296
+ # @since 0.2.0
297
+ #
298
+ def erb(template_path,destination=nil)
299
+ if destination
300
+ enter_template(template_path) do |path|
301
+ template(path,destination)
302
+ end
303
+ else
304
+ read_template(template_path) do |template|
305
+ ERB.new(template).result(binding).chomp
306
+ end
307
+ end
308
+ end
309
+
310
+ end
311
+ end
312
+ end