ore 0.2.3 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (72) hide show
  1. data/.document +0 -1
  2. data/ChangeLog.md +28 -18
  3. data/README.md +8 -6
  4. data/Rakefile +10 -0
  5. data/data/ore/templates/base/[name].gemspec.erb +1 -1
  6. data/data/ore/templates/base/_gemfile.erb +1 -1
  7. data/data/ore/templates/base/gemspec.yml.erb +2 -2
  8. data/data/ore/templates/base/template.yml +1 -1
  9. data/data/ore/templates/ore_tasks/template.yml +1 -1
  10. data/gemspec.yml +4 -2
  11. data/lib/ore/generator.rb +1 -1
  12. data/lib/ore/template/helpers.rb +24 -0
  13. data/ore.gemspec +9 -5
  14. data/spec/generator_spec.rb +9 -1
  15. data/spec/spec_helper.rb +2 -0
  16. metadata +43 -80
  17. data/GemspecYML.md +0 -272
  18. data/lib/ore.rb +0 -3
  19. data/lib/ore/checks.rb +0 -88
  20. data/lib/ore/defaults.rb +0 -141
  21. data/lib/ore/dependency.rb +0 -65
  22. data/lib/ore/document_file.rb +0 -118
  23. data/lib/ore/exceptions.rb +0 -3
  24. data/lib/ore/exceptions/exception.rb +0 -4
  25. data/lib/ore/exceptions/invalid_metadata.rb +0 -6
  26. data/lib/ore/exceptions/project_not_found.rb +0 -6
  27. data/lib/ore/naming.rb +0 -113
  28. data/lib/ore/paths.rb +0 -146
  29. data/lib/ore/project.rb +0 -591
  30. data/lib/ore/settings.rb +0 -262
  31. data/lib/ore/specification.rb +0 -29
  32. data/lib/ore/versions.rb +0 -3
  33. data/lib/ore/versions/exceptions.rb +0 -1
  34. data/lib/ore/versions/exceptions/invalid_version.rb +0 -8
  35. data/lib/ore/versions/version.rb +0 -75
  36. data/lib/ore/versions/version_constant.rb +0 -126
  37. data/lib/ore/versions/version_file.rb +0 -66
  38. data/lib/rubygems_plugin.rb +0 -40
  39. data/spec/dependency_spec.rb +0 -36
  40. data/spec/document_file_spec.rb +0 -29
  41. data/spec/helpers/files.rb +0 -7
  42. data/spec/helpers/files/.document +0 -5
  43. data/spec/helpers/files/VERSION +0 -1
  44. data/spec/helpers/files/VERSION.yml +0 -5
  45. data/spec/helpers/projects.rb +0 -13
  46. data/spec/helpers/projects/dm-is-plugin/Gemfile +0 -3
  47. data/spec/helpers/projects/dm-is-plugin/VERSION +0 -1
  48. data/spec/helpers/projects/dm-is-plugin/dm-is-plugin.gemspec +0 -10
  49. data/spec/helpers/projects/dm-is-plugin/gemspec.yml +0 -7
  50. data/spec/helpers/projects/dm-is-plugin/lib/dm-is-plugin.rb +0 -4
  51. data/spec/helpers/projects/dm-is-plugin/lib/dm-is-plugin/is/plugin.rb +0 -6
  52. data/spec/helpers/projects/explicit/gemspec.yml +0 -10
  53. data/spec/helpers/projects/explicit/lib/explicit/version.rb +0 -15
  54. data/spec/helpers/projects/ffi-binding/gemspec.yml +0 -9
  55. data/spec/helpers/projects/ffi-binding/lib/ffi/binding/version.rb +0 -5
  56. data/spec/helpers/projects/jewelery/VERSION +0 -1
  57. data/spec/helpers/projects/jewelery/bin/jewelery +0 -3
  58. data/spec/helpers/projects/jewelery/gemspec.yml +0 -4
  59. data/spec/helpers/projects/jewelery/jewelery.gemspec +0 -10
  60. data/spec/helpers/projects/jewelery/lib/jewelery.rb +0 -4
  61. data/spec/helpers/projects/jewelery/lib/jewelery/rubies.rb +0 -4
  62. data/spec/helpers/projects/minimal/gemspec.yml +0 -4
  63. data/spec/helpers/projects/minimal/lib/minimal.rb +0 -2
  64. data/spec/naming_spec.rb +0 -56
  65. data/spec/projects/dm_plugin_project_spec.rb +0 -29
  66. data/spec/projects/explicit_project_spec.rb +0 -33
  67. data/spec/projects/ffi_binding_project_spec.rb +0 -25
  68. data/spec/projects/jeweler_project_spec.rb +0 -17
  69. data/spec/projects/minimal_project_spec.rb +0 -17
  70. data/spec/projects/project_examples.rb +0 -34
  71. data/spec/versions/version_file_spec.rb +0 -28
  72. data/spec/versions/version_spec.rb +0 -53
data/lib/ore/project.rb DELETED
@@ -1,591 +0,0 @@
1
- require 'ore/exceptions/project_not_found'
2
- require 'ore/exceptions/invalid_metadata'
3
- require 'ore/naming'
4
- require 'ore/paths'
5
- require 'ore/checks'
6
- require 'ore/defaults'
7
- require 'ore/settings'
8
- require 'ore/document_file'
9
-
10
- require 'pathname'
11
- require 'yaml'
12
- require 'find'
13
- require 'fileutils'
14
-
15
- module Ore
16
- #
17
- # Combinds the metadata from the `gemspec.yml` file and the inferred
18
- # information from the project directory.
19
- #
20
- class Project
21
-
22
- include Naming
23
- include Paths
24
- include Checks
25
- include Defaults
26
- include Settings
27
-
28
- # The project metadata file
29
- @@metadata_file = 'gemspec.yml'
30
-
31
- # The root directory of the project
32
- attr_reader :root
33
-
34
- # The SCM which the project is currently under
35
- attr_reader :scm
36
-
37
- # The files of the project
38
- attr_reader :project_files
39
-
40
- # The fully-qualified namespace of the project
41
- attr_reader :namespace
42
-
43
- # The infered namespace modules of the project
44
- attr_reader :namespace_modules
45
-
46
- # The directory contain the project code.
47
- attr_reader :namespace_dir
48
-
49
- # The name of the project
50
- attr_reader :name
51
-
52
- # The version of the project
53
- attr_reader :version
54
-
55
- # The project summary
56
- attr_reader :summary
57
-
58
- # The project description
59
- attr_reader :description
60
-
61
- # The licenses of the project
62
- attr_reader :licenses
63
-
64
- # The authors of the project
65
- attr_reader :authors
66
-
67
- # The homepage for the project
68
- attr_reader :homepage
69
-
70
- # The email contact for the project
71
- attr_reader :email
72
-
73
- # The build date for any project gems
74
- attr_reader :date
75
-
76
- # The parsed `.document` file
77
- attr_reader :document
78
-
79
- # The directories to search within the project when requiring files
80
- attr_reader :require_paths
81
-
82
- # The names of the executable scripts
83
- attr_reader :executables
84
-
85
- # The default executable
86
- attr_reader :default_executable
87
-
88
- # The documentation of the project
89
- attr_reader :documentation
90
-
91
- # Any extra files to include in the project documentation
92
- attr_reader :extra_doc_files
93
-
94
- # The files of the project
95
- attr_reader :files
96
-
97
- # The test files for the project
98
- attr_reader :test_files
99
-
100
- # Any external requirements needed by the project
101
- attr_reader :requirements
102
-
103
- # The version of Ruby required by the project
104
- attr_reader :required_ruby_version
105
-
106
- # The version of RubyGems required by the project
107
- attr_reader :required_rubygems_version
108
-
109
- # The dependencies of the project
110
- attr_reader :dependencies
111
-
112
- # The runtime-dependencies of the project
113
- attr_reader :runtime_dependencies
114
-
115
- # The development-dependencies of the project
116
- attr_reader :development_dependencies
117
-
118
- #
119
- # Creates a new {Project}.
120
- #
121
- # @param [String] root
122
- # The root directory of the project.
123
- #
124
- def initialize(root)
125
- @root = Pathname.new(root).expand_path
126
-
127
- unless @root.directory?
128
- raise(ProjectNotFound,"#{@root} is not a directory")
129
- end
130
-
131
- infer_scm!
132
- infer_project_files!
133
-
134
- metadata_file = @root.join(@@metadata_file)
135
-
136
- unless metadata_file.file?
137
- raise(ProjectNotFound,"#{@root} does not contain #{@@metadata_file}")
138
- end
139
-
140
- metadata = YAML.load_file(metadata_file)
141
-
142
- unless metadata.kind_of?(Hash)
143
- raise(InvalidMetadata,"#{metadata_file} did not contain valid metadata")
144
- end
145
-
146
- if metadata['name']
147
- @name = metadata['name'].to_s
148
- else
149
- default_name!
150
- end
151
-
152
- # infer the namespace from the project name
153
- infer_namespace!
154
-
155
- if metadata['version']
156
- set_version! metadata['version']
157
- else
158
- default_version!
159
- end
160
-
161
- @summary = (metadata['summary'] || metadata['description'])
162
- @description = (metadata['description'] || metadata['summary'])
163
-
164
- @licenses = []
165
-
166
- if metadata['license']
167
- set_license!(metadata['license'])
168
- end
169
-
170
- @authors = []
171
-
172
- if metadata['authors']
173
- set_authors! metadata['authors']
174
- end
175
-
176
- @homepage = metadata['homepage']
177
- @email = metadata['email']
178
-
179
- if metadata['date']
180
- set_date! metadata['date']
181
- else
182
- default_date!
183
- end
184
-
185
- @document = DocumentFile.find(self)
186
-
187
- @require_paths = []
188
-
189
- if metadata['require_paths']
190
- set_require_paths! metadata['require_paths']
191
- else
192
- default_require_paths!
193
- end
194
-
195
- @executables = []
196
-
197
- if metadata['executables']
198
- set_executables! metadata['executables']
199
- else
200
- default_executables!
201
- end
202
-
203
- @default_executable = nil
204
-
205
- if metadata['default_executable']
206
- set_default_executable! metadata['default_executable']
207
- else
208
- default_executable!
209
- end
210
-
211
- if metadata['has_yard']
212
- @documentation = :yard
213
- elsif metadata.has_key?('has_rdoc')
214
- @documentation = if metadata['has_rdoc']
215
- :rdoc
216
- end
217
- else
218
- default_documentation!
219
- end
220
-
221
- @extra_doc_files = []
222
-
223
- if metadata['extra_doc_files']
224
- set_extra_doc_files! metadata['extra_doc_files']
225
- else
226
- default_extra_doc_files!
227
- end
228
-
229
- @files = []
230
-
231
- if metadata['files']
232
- set_files! metadata['files']
233
- else
234
- default_files!
235
- end
236
-
237
- @test_files = []
238
-
239
- if metadata['test_files']
240
- set_test_files! metadata['test_files']
241
- else
242
- default_test_files!
243
- end
244
-
245
- @requirements = []
246
-
247
- if metadata['requirements']
248
- set_requirements! metadata['requirements']
249
- end
250
-
251
- if metadata['required_ruby_version']
252
- set_required_ruby_version! metadata['required_ruby_version']
253
- end
254
-
255
- if metadata['required_rubygems_version']
256
- set_required_rubygems_version! metadata['required_rubygems_version']
257
- else
258
- default_required_rubygems_version!
259
- end
260
-
261
- @dependencies = []
262
-
263
- if metadata['dependencies']
264
- set_dependencies! metadata['dependencies']
265
- end
266
-
267
- @runtime_dependencies = []
268
-
269
- if metadata['runtime_dependencies']
270
- set_runtime_dependencies! metadata['runtime_dependencies']
271
- end
272
-
273
- @development_dependencies = []
274
-
275
- if metadata['development_dependencies']
276
- set_development_dependencies! metadata['development_dependencies']
277
- end
278
- end
279
-
280
- #
281
- # Finds the project metadata file and creates a new {Project} object.
282
- #
283
- # @param [String] dir (Dir.pwd)
284
- # The directory to start searching upward from.
285
- #
286
- # @return [Project]
287
- # The found project.
288
- #
289
- # @raise [ProjectNotFound]
290
- # No project metadata file could be found.
291
- #
292
- def self.find(dir=Dir.pwd)
293
- Pathname.new(dir).ascend do |root|
294
- return self.new(root) if root.join(@@metadata_file).file?
295
- end
296
-
297
- raise(ProjectNotFound,"could not find #{@@metadata_file}")
298
- end
299
-
300
- #
301
- # Executes code within the project.
302
- #
303
- # @param [String] sub_dir
304
- # An optional sub-directory within the project to execute from.
305
- #
306
- # @yield []
307
- # The given block will be called once the current working-directory
308
- # has been switched. Once the block finishes executing, the current
309
- # working-directory will be switched back.
310
- #
311
- # @see http://ruby-doc.org/core/classes/Dir.html#M002314
312
- #
313
- def within(sub_dir=nil,&block)
314
- dir = if sub_dir
315
- @root.join(sub_dir)
316
- else
317
- @root
318
- end
319
-
320
- Dir.chdir(dir,&block)
321
- end
322
-
323
- #
324
- # The primary license of the project.
325
- #
326
- # @return [String, nil]
327
- # The primary license for the project.
328
- #
329
- def license
330
- @licenses.first
331
- end
332
-
333
- #
334
- # Determines whether the project uses Bundler.
335
- #
336
- # @return [Boolean]
337
- # Specifies whether the project uses Bundler.
338
- #
339
- def bundler?
340
- file?('Gemfile')
341
- end
342
-
343
- #
344
- # Determines whether the project has been bundled using Bundler.
345
- #
346
- # @return [Boolean]
347
- # Specifies whether the project has been bundled.
348
- #
349
- def bundled?
350
- file?('Gemfile.lock')
351
- end
352
-
353
- #
354
- # Determines if the project contains RDoc documentation.
355
- #
356
- # @return [Boolean]
357
- # Specifies whether the project has RDoc documentation.
358
- #
359
- def has_rdoc
360
- @documentation == :rdoc
361
- end
362
-
363
- #
364
- # Determines if the project contains YARD documentation.
365
- #
366
- # @return [Boolean]
367
- # Specifies whether the project has YARD documentation.
368
- #
369
- def has_yard
370
- @documentation == :yard
371
- end
372
-
373
- #
374
- # Populates a Gem Specification using the metadata of the project.
375
- #
376
- # @yield [gemspec]
377
- # The given block will be passed the populated Gem Specification
378
- # object.
379
- #
380
- # @yieldparam [Gem::Specification] gemspec
381
- # The newly created Gem Specification.
382
- #
383
- # @return [Gem::Specification]
384
- # The Gem Specification.
385
- #
386
- # @see http://rubygems.rubyforge.org/rdoc/Gem/Specification.html
387
- #
388
- def to_gemspec
389
- Gem::Specification.new do |gemspec|
390
- gemspec.name = @name.to_s
391
- gemspec.version = @version.to_s
392
- gemspec.summary = @summary.to_s
393
- gemspec.description = @description.to_s
394
- gemspec.licenses = @licenses
395
- gemspec.authors = @authors
396
- gemspec.homepage = @homepage
397
- gemspec.email = @email
398
- gemspec.date = @date
399
-
400
- @require_paths.each do |path|
401
- unless gemspec.require_paths.include?(path)
402
- gemspec.require_paths << path
403
- end
404
- end
405
-
406
- gemspec.executables = @executables
407
- gemspec.default_executable = @default_executable
408
-
409
- gemspec.has_rdoc = if has_yard
410
- 'yard'
411
- elsif has_rdoc
412
- true
413
- end
414
-
415
- gemspec.extra_rdoc_files = @extra_doc_files
416
- gemspec.files = @files
417
- gemspec.test_files = @test_files
418
-
419
- gemspec.requirements = @requirements
420
-
421
- if gemspec.respond_to?(:required_ruby_version=)
422
- gemspec.required_ruby_version = @required_ruby_version
423
- end
424
-
425
- if gemspec.respond_to?(:required_rubygems_version=)
426
- gemspec.required_rubygems_version = @required_rubygems_version
427
- end
428
-
429
- @dependencies.each do |dep|
430
- gemspec.add_dependency(dep.name,*dep.versions)
431
- end
432
-
433
- if gemspec.respond_to?(:add_runtime_dependency)
434
- @runtime_dependencies.each do |dep|
435
- gemspec.add_runtime_dependency(dep.name,*dep.versions)
436
- end
437
- else
438
- @runtime_dependencies.each do |dep|
439
- gemspec.add_dependency(dep.name,*dep.versions)
440
- end
441
- end
442
-
443
- if gemspec.respond_to?(:add_development_dependency)
444
- @development_dependencies.each do |dep|
445
- gemspec.add_development_dependency(dep.name,*dep.versions)
446
- end
447
- else
448
- @development_dependencies.each do |dep|
449
- gemspec.add_dependency(dep.name,*dep.versions)
450
- end
451
- end
452
-
453
- # legacy information
454
- if gemspec.respond_to?(:rubyforge_project=)
455
- gemspec.rubyforge_project = gemspec.name
456
- end
457
-
458
- yield gemspec if block_given?
459
- end
460
- end
461
-
462
- #
463
- # Builds a gem for the project.
464
- #
465
- # @return [Pathname]
466
- # The path to the built gem file within the `pkg/` directory.
467
- #
468
- def build!
469
- pkg_dir = @root.join(@@pkg_dir)
470
- FileUtils.mkdir_p(pkg_dir)
471
-
472
- gem_file = Gem::Builder.new(self.to_gemspec).build
473
- pkg_path = @root.join(pkg_file)
474
-
475
- FileUtils.mv(gem_file,pkg_path)
476
- return pkg_path
477
- end
478
-
479
- protected
480
-
481
- #
482
- # Prints multiple warning messages.
483
- #
484
- # @param [Array] messages
485
- # The messages to print.
486
- #
487
- def warn(*messages)
488
- messages.each { |mesg| STDERR.puts("WARNING: #{mesg}") }
489
- end
490
-
491
- #
492
- # Infers the Source Code Management used by the project.
493
- #
494
- def infer_scm!
495
- if @root.join('.git').directory?
496
- @scm = :git
497
- else
498
- @scm = nil
499
- end
500
- end
501
-
502
- #
503
- # Infers the project files.
504
- #
505
- def infer_project_files!
506
- @project_files = Set[]
507
-
508
- filter_path = lambda { |path|
509
- check_readable(path) { |file| @project_files << file }
510
- }
511
-
512
- within do
513
- case @scm
514
- when :git
515
- `git ls-files -z`.split("\0").each(&filter_path)
516
- else
517
- within { Dir.glob('{**/}*',&filter_path) }
518
- end
519
- end
520
- end
521
-
522
- #
523
- # Infers the namespace of the project based on the project name.
524
- #
525
- def infer_namespace!
526
- @namespace_modules = modules_of(@name)
527
- @namespace = namespace_of(@name)
528
-
529
- dir = namespace_path_of(@name)
530
-
531
- @namespace_dir = if lib_directory?(dir)
532
- dir
533
- elsif lib_directory?(@name)
534
- @name
535
- end
536
- end
537
-
538
- #
539
- # Adds a require-path to the project.
540
- #
541
- # @param [String] path
542
- # A directory path relative to the project.
543
- #
544
- def add_require_path(path)
545
- check_directory(path) { |dir| @require_paths << dir }
546
- end
547
-
548
- #
549
- # Adds an executable to the project.
550
- #
551
- # @param [String] name
552
- # The name of the executable.
553
- #
554
- def add_executable(name)
555
- path = File.join(@@bin_dir,name)
556
-
557
- check_executable(path) { |exe| @executables << exe }
558
- end
559
-
560
- #
561
- # Adds an extra documentation file to the project.
562
- #
563
- # @param [String] path
564
- # The path to the file, relative to the project.
565
- #
566
- def add_extra_doc_file(path)
567
- check_file(path) { |file| @extra_doc_files << file }
568
- end
569
-
570
- #
571
- # Adds a file to the project.
572
- #
573
- # @param [String] path
574
- # The path to the file, relative to the project.
575
- #
576
- def add_file(path)
577
- check_file(path) { |file| @files << file }
578
- end
579
-
580
- #
581
- # Adds a testing-file to the project.
582
- #
583
- # @param [String] path
584
- # The path to the testing-file, relative to the project.
585
- #
586
- def add_test_file(path)
587
- check_file(path) { |file| @test_files << file }
588
- end
589
-
590
- end
591
- end