ore-core 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/.document +4 -0
- data/.rspec +1 -0
- data/.yardopts +1 -0
- data/ChangeLog.md +17 -0
- data/GemspecYML.md +284 -0
- data/LICENSE.txt +21 -0
- data/README.md +68 -0
- data/Rakefile +25 -0
- data/gemspec.yml +18 -0
- data/lib/ore.rb +3 -0
- data/lib/ore/checks.rb +88 -0
- data/lib/ore/defaults.rb +140 -0
- data/lib/ore/dependency.rb +65 -0
- data/lib/ore/document_file.rb +118 -0
- data/lib/ore/exceptions.rb +3 -0
- data/lib/ore/exceptions/exception.rb +4 -0
- data/lib/ore/exceptions/invalid_metadata.rb +6 -0
- data/lib/ore/exceptions/project_not_found.rb +6 -0
- data/lib/ore/naming.rb +113 -0
- data/lib/ore/paths.rb +146 -0
- data/lib/ore/project.rb +599 -0
- data/lib/ore/settings.rb +274 -0
- data/lib/ore/specification.rb +29 -0
- data/lib/ore/versions.rb +3 -0
- data/lib/ore/versions/exceptions.rb +1 -0
- data/lib/ore/versions/exceptions/invalid_version.rb +8 -0
- data/lib/ore/versions/version.rb +75 -0
- data/lib/ore/versions/version_constant.rb +126 -0
- data/lib/ore/versions/version_file.rb +66 -0
- data/lib/rubygems_plugin.rb +40 -0
- data/ore-core.gemspec +6 -0
- data/spec/dependency_spec.rb +36 -0
- data/spec/document_file_spec.rb +29 -0
- data/spec/helpers/files.rb +7 -0
- data/spec/helpers/files/.document +5 -0
- data/spec/helpers/files/VERSION +1 -0
- data/spec/helpers/files/VERSION.yml +5 -0
- data/spec/helpers/projects.rb +13 -0
- data/spec/helpers/projects/dm-is-plugin/Gemfile +3 -0
- data/spec/helpers/projects/dm-is-plugin/VERSION +1 -0
- data/spec/helpers/projects/dm-is-plugin/dm-is-plugin.gemspec +10 -0
- data/spec/helpers/projects/dm-is-plugin/gemspec.yml +9 -0
- data/spec/helpers/projects/dm-is-plugin/lib/dm-is-plugin.rb +4 -0
- data/spec/helpers/projects/dm-is-plugin/lib/dm-is-plugin/is/plugin.rb +6 -0
- data/spec/helpers/projects/explicit/gemspec.yml +19 -0
- data/spec/helpers/projects/explicit/lib/explicit/version.rb +15 -0
- data/spec/helpers/projects/ffi-binding/gemspec.yml +11 -0
- data/spec/helpers/projects/ffi-binding/lib/ffi/binding/version.rb +5 -0
- data/spec/helpers/projects/jewelery/VERSION +1 -0
- data/spec/helpers/projects/jewelery/bin/jewelery +3 -0
- data/spec/helpers/projects/jewelery/gemspec.yml +6 -0
- data/spec/helpers/projects/jewelery/jewelery.gemspec +10 -0
- data/spec/helpers/projects/jewelery/lib/jewelery.rb +4 -0
- data/spec/helpers/projects/jewelery/lib/jewelery/rubies.rb +4 -0
- data/spec/helpers/projects/minimal/gemspec.yml +4 -0
- data/spec/helpers/projects/minimal/lib/minimal.rb +2 -0
- data/spec/naming_spec.rb +56 -0
- data/spec/projects/dm_plugin_project_spec.rb +29 -0
- data/spec/projects/explicit_project_spec.rb +37 -0
- data/spec/projects/ffi_binding_project_spec.rb +25 -0
- data/spec/projects/jeweler_project_spec.rb +17 -0
- data/spec/projects/minimal_project_spec.rb +17 -0
- data/spec/projects/project_examples.rb +40 -0
- data/spec/spec_helper.rb +4 -0
- data/spec/versions/version_file_spec.rb +28 -0
- data/spec/versions/version_spec.rb +53 -0
- metadata +170 -0
data/lib/ore.rb
ADDED
data/lib/ore/checks.rb
ADDED
@@ -0,0 +1,88 @@
|
|
1
|
+
module Ore
|
2
|
+
#
|
3
|
+
# A mixin for {Project} which provides methods for checking files.
|
4
|
+
#
|
5
|
+
module Checks
|
6
|
+
protected
|
7
|
+
|
8
|
+
#
|
9
|
+
# Checks if the path is readable.
|
10
|
+
#
|
11
|
+
# @yield [path]
|
12
|
+
# The block will be passed the path, if it is readable.
|
13
|
+
# Otherwise a warning will be printed.
|
14
|
+
#
|
15
|
+
# @yieldparam [String] path
|
16
|
+
# A readable path.
|
17
|
+
#
|
18
|
+
def check_readable(path)
|
19
|
+
if File.readable?(path)
|
20
|
+
yield path
|
21
|
+
else
|
22
|
+
warn "#{path} is not readable!"
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
#
|
27
|
+
# Checks if the path is a readable directory.
|
28
|
+
#
|
29
|
+
# @yield [path]
|
30
|
+
# The block will be passed the path, if it is a readable directory.
|
31
|
+
# Otherwise a warning will be printed.
|
32
|
+
#
|
33
|
+
# @yieldparam [String] path
|
34
|
+
# The directory path.
|
35
|
+
#
|
36
|
+
def check_directory(path)
|
37
|
+
check_readable(path) do |dir|
|
38
|
+
if File.directory?(dir)
|
39
|
+
yield dir
|
40
|
+
else
|
41
|
+
warn "#{dir} is not a directory!"
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
#
|
47
|
+
# Checks if the path is a readable file.
|
48
|
+
#
|
49
|
+
# @yield [path]
|
50
|
+
# The block will be passed the path, if it is a readable file.
|
51
|
+
# Otherwise a warning will be printed.
|
52
|
+
#
|
53
|
+
# @yieldparam [String] path
|
54
|
+
# A file path.
|
55
|
+
#
|
56
|
+
def check_file(path)
|
57
|
+
if @project_files.include?(path)
|
58
|
+
check_readable(path) do |file|
|
59
|
+
if File.file?(file)
|
60
|
+
yield file
|
61
|
+
else
|
62
|
+
warn "#{file} is not a file!"
|
63
|
+
end
|
64
|
+
end
|
65
|
+
end
|
66
|
+
end
|
67
|
+
|
68
|
+
#
|
69
|
+
# Checks if the path is an executable file.
|
70
|
+
#
|
71
|
+
# @yield [path]
|
72
|
+
# The block will be passed the path, if it is an executable file.
|
73
|
+
# Otherwise a warning will be printed.
|
74
|
+
#
|
75
|
+
# @yieldparam [String] path
|
76
|
+
# An path to an executable file.
|
77
|
+
#
|
78
|
+
def check_executable(path)
|
79
|
+
check_file(path) do |file|
|
80
|
+
if File.executable?(file)
|
81
|
+
yield file
|
82
|
+
else
|
83
|
+
warn "#{file} is not executable!"
|
84
|
+
end
|
85
|
+
end
|
86
|
+
end
|
87
|
+
end
|
88
|
+
end
|
data/lib/ore/defaults.rb
ADDED
@@ -0,0 +1,140 @@
|
|
1
|
+
require 'ore/naming'
|
2
|
+
require 'ore/versions'
|
3
|
+
|
4
|
+
require 'date'
|
5
|
+
|
6
|
+
module Ore
|
7
|
+
#
|
8
|
+
# A mixin for {Project} which provides methods for assigning default
|
9
|
+
# values to project attributes.
|
10
|
+
#
|
11
|
+
module Defaults
|
12
|
+
include Naming
|
13
|
+
|
14
|
+
# The default require-paths
|
15
|
+
@@require_paths = [@@lib_dir, @@ext_dir]
|
16
|
+
|
17
|
+
# The glob to find default executables
|
18
|
+
@@executables = "#{@@bin_dir}/*"
|
19
|
+
|
20
|
+
# The globs to find all testing-files
|
21
|
+
@@test_files = [
|
22
|
+
"#{@@test_dir}/{**/}*_test.rb",
|
23
|
+
"#{@@spec_dir}/{**/}*_spec.rb"
|
24
|
+
]
|
25
|
+
|
26
|
+
# The files to always exclude
|
27
|
+
@@exclude_files = %w[
|
28
|
+
.gitignore
|
29
|
+
]
|
30
|
+
|
31
|
+
protected
|
32
|
+
|
33
|
+
#
|
34
|
+
# Sets the project name using the directory name of the project.
|
35
|
+
#
|
36
|
+
def default_name!
|
37
|
+
@name = @root.basename.to_s
|
38
|
+
end
|
39
|
+
|
40
|
+
#
|
41
|
+
# Finds and sets the version of the project.
|
42
|
+
#
|
43
|
+
def default_version!
|
44
|
+
@version = (
|
45
|
+
Versions::VersionFile.find(self) ||
|
46
|
+
Versions::VersionConstant.find(self)
|
47
|
+
)
|
48
|
+
|
49
|
+
unless @version
|
50
|
+
raise(InvalidMetadata,"no version file or constant in #{@root}")
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
#
|
55
|
+
# Sets the release date of the project.
|
56
|
+
#
|
57
|
+
def default_date!
|
58
|
+
@date = Date.today
|
59
|
+
end
|
60
|
+
|
61
|
+
#
|
62
|
+
# Sets the require-paths of the project.
|
63
|
+
#
|
64
|
+
def default_require_paths!
|
65
|
+
@@require_paths.each do |name|
|
66
|
+
@require_paths << name if @root.join(name).directory?
|
67
|
+
end
|
68
|
+
end
|
69
|
+
|
70
|
+
#
|
71
|
+
# Sets the executables of the project.
|
72
|
+
#
|
73
|
+
def default_executables!
|
74
|
+
glob(@@executables) do |path|
|
75
|
+
check_executable(path) { |exe| @executables << File.basename(exe) }
|
76
|
+
end
|
77
|
+
end
|
78
|
+
|
79
|
+
#
|
80
|
+
# sets the default executable of the project.
|
81
|
+
#
|
82
|
+
def default_executable!
|
83
|
+
@default_executable = if @executables.include?(@name)
|
84
|
+
@name
|
85
|
+
else
|
86
|
+
@executables.first
|
87
|
+
end
|
88
|
+
end
|
89
|
+
|
90
|
+
#
|
91
|
+
# Sets the default documentation of the project.
|
92
|
+
#
|
93
|
+
def default_documentation!
|
94
|
+
if file?('.yardopts')
|
95
|
+
@documentation = :yard
|
96
|
+
else
|
97
|
+
@documentation = :rdoc
|
98
|
+
end
|
99
|
+
end
|
100
|
+
|
101
|
+
#
|
102
|
+
# Sets the extra documentation files of the project.
|
103
|
+
#
|
104
|
+
def default_extra_doc_files!
|
105
|
+
glob('README.*') { |path| add_extra_doc_file(path) }
|
106
|
+
|
107
|
+
if @document
|
108
|
+
@document.each_extra_file { |path| add_extra_doc_file(path) }
|
109
|
+
end
|
110
|
+
end
|
111
|
+
|
112
|
+
#
|
113
|
+
# Sets the files of the project.
|
114
|
+
#
|
115
|
+
def default_files!
|
116
|
+
@project_files.each do |file|
|
117
|
+
@files << file unless @@exclude_files.include?(file)
|
118
|
+
end
|
119
|
+
end
|
120
|
+
|
121
|
+
#
|
122
|
+
# Sets the test-files of the project.
|
123
|
+
#
|
124
|
+
def default_test_files!
|
125
|
+
@@test_files.each do |pattern|
|
126
|
+
glob(pattern) { |path| add_test_file(path) }
|
127
|
+
end
|
128
|
+
end
|
129
|
+
|
130
|
+
#
|
131
|
+
# Defaults the required version of RubyGems to `>= 1.3.6`, if the
|
132
|
+
# project uses Bundler.
|
133
|
+
#
|
134
|
+
def default_required_rubygems_version!
|
135
|
+
if bundler?
|
136
|
+
@required_rubygems_version = '>= 1.3.6'
|
137
|
+
end
|
138
|
+
end
|
139
|
+
end
|
140
|
+
end
|
@@ -0,0 +1,65 @@
|
|
1
|
+
module Ore
|
2
|
+
#
|
3
|
+
# Represents a RubyGem dependency.
|
4
|
+
#
|
5
|
+
class Dependency
|
6
|
+
|
7
|
+
# The name of the dependency
|
8
|
+
attr_reader :name
|
9
|
+
|
10
|
+
# The required versions
|
11
|
+
attr_reader :versions
|
12
|
+
|
13
|
+
#
|
14
|
+
# Creates a new dependency.
|
15
|
+
#
|
16
|
+
# @param [String] name
|
17
|
+
# The name of the dependency.
|
18
|
+
#
|
19
|
+
# @param [Array<String>] versions
|
20
|
+
# The required versions.
|
21
|
+
#
|
22
|
+
def initialize(name,*versions)
|
23
|
+
@name = name
|
24
|
+
@versions = versions
|
25
|
+
end
|
26
|
+
|
27
|
+
#
|
28
|
+
# Parses a version string.
|
29
|
+
#
|
30
|
+
# @param [String] name
|
31
|
+
# The name of the dependency.
|
32
|
+
#
|
33
|
+
# @param [String, nil] versions
|
34
|
+
# The version string.
|
35
|
+
#
|
36
|
+
# @return [Dependency]
|
37
|
+
# The parsed dependency.
|
38
|
+
#
|
39
|
+
def self.parse_versions(name,versions)
|
40
|
+
versions = if versions.kind_of?(String)
|
41
|
+
versions.strip.split(/,\s*/)
|
42
|
+
else
|
43
|
+
[]
|
44
|
+
end
|
45
|
+
|
46
|
+
return new(name,*versions)
|
47
|
+
end
|
48
|
+
|
49
|
+
#
|
50
|
+
# Parses a dependencey string.
|
51
|
+
#
|
52
|
+
# @param [String] dependency
|
53
|
+
# The dependencey string.
|
54
|
+
#
|
55
|
+
# @return [Dependency]
|
56
|
+
# The parsed dependency.
|
57
|
+
#
|
58
|
+
def self.parse(dependency)
|
59
|
+
name, versions = dependency.strip.split(/\s+/,2)
|
60
|
+
|
61
|
+
return parse_versions(name,versions)
|
62
|
+
end
|
63
|
+
|
64
|
+
end
|
65
|
+
end
|
@@ -0,0 +1,118 @@
|
|
1
|
+
require 'set'
|
2
|
+
|
3
|
+
module Ore
|
4
|
+
#
|
5
|
+
# Parses the contents of a `.document`.
|
6
|
+
#
|
7
|
+
class DocumentFile
|
8
|
+
|
9
|
+
# The path to the `.document` file.
|
10
|
+
attr_reader :path
|
11
|
+
|
12
|
+
# The glob-patterns to find all code-files.
|
13
|
+
attr_reader :file_globs
|
14
|
+
|
15
|
+
# The glob-patterns to find all extra-files.
|
16
|
+
attr_reader :extra_file_globs
|
17
|
+
|
18
|
+
#
|
19
|
+
# Creates a new {DocumentFile}.
|
20
|
+
#
|
21
|
+
# @param [String] path
|
22
|
+
# The path of the `.document` file.
|
23
|
+
#
|
24
|
+
def initialize(path)
|
25
|
+
@path = File.expand_path(path)
|
26
|
+
|
27
|
+
@file_globs = Set[]
|
28
|
+
@extra_file_globs = Set[]
|
29
|
+
|
30
|
+
parse!
|
31
|
+
end
|
32
|
+
|
33
|
+
@@file = '.document'
|
34
|
+
|
35
|
+
#
|
36
|
+
# Finds the document file in a project.
|
37
|
+
#
|
38
|
+
# @param [Project] project
|
39
|
+
# The project to search within.
|
40
|
+
#
|
41
|
+
# @return [DocumentFile, nil]
|
42
|
+
# The found document file.
|
43
|
+
#
|
44
|
+
def self.find(project)
|
45
|
+
self.new(project.path(@@file)) if project.file?(@@file)
|
46
|
+
end
|
47
|
+
|
48
|
+
#
|
49
|
+
# All files described in the `.document` file.
|
50
|
+
#
|
51
|
+
# @yield [path]
|
52
|
+
# The given block will be passed every path that matches the file
|
53
|
+
# globs in the `.document` file.
|
54
|
+
#
|
55
|
+
# @yieldparam [String] path
|
56
|
+
# A match that matches the `.document` file patterns.
|
57
|
+
#
|
58
|
+
# @return [Enumerator]
|
59
|
+
# If no block was given, an enumerator object will be returned.
|
60
|
+
#
|
61
|
+
def each_file(&block)
|
62
|
+
return enum_for(:each_file) unless block
|
63
|
+
|
64
|
+
@file_globs.each do |pattern|
|
65
|
+
Dir.glob(pattern,&block)
|
66
|
+
end
|
67
|
+
end
|
68
|
+
|
69
|
+
#
|
70
|
+
# All extra-files described in the `.document` file.
|
71
|
+
#
|
72
|
+
# @yield [path]
|
73
|
+
# The given block will be passed every path that matches the
|
74
|
+
# extra-file globs in the `.document` file.
|
75
|
+
#
|
76
|
+
# @yieldparam [String] path
|
77
|
+
# A match that matches the `.document` extra-file patterns.
|
78
|
+
#
|
79
|
+
# @return [Enumerator]
|
80
|
+
# If no block was given, an enumerator object will be returned.
|
81
|
+
#
|
82
|
+
def each_extra_file(&block)
|
83
|
+
return enum_for(:each_extra_file) unless block
|
84
|
+
|
85
|
+
@extra_file_globs.each do |pattern|
|
86
|
+
Dir.glob(pattern,&block)
|
87
|
+
end
|
88
|
+
end
|
89
|
+
|
90
|
+
protected
|
91
|
+
|
92
|
+
#
|
93
|
+
# Parses the contents of a `.document` file.
|
94
|
+
#
|
95
|
+
def parse!
|
96
|
+
separator = false
|
97
|
+
|
98
|
+
File.open(@path) do |file|
|
99
|
+
file.each_line do |line|
|
100
|
+
line = line.chomp.strip
|
101
|
+
|
102
|
+
next if line.empty?
|
103
|
+
|
104
|
+
unless separator
|
105
|
+
if line == '-'
|
106
|
+
separator = true
|
107
|
+
else
|
108
|
+
@file_globs << line
|
109
|
+
end
|
110
|
+
else
|
111
|
+
@extra_file_globs << line
|
112
|
+
end
|
113
|
+
end
|
114
|
+
end
|
115
|
+
end
|
116
|
+
|
117
|
+
end
|
118
|
+
end
|
data/lib/ore/naming.rb
ADDED
@@ -0,0 +1,113 @@
|
|
1
|
+
module Ore
|
2
|
+
#
|
3
|
+
# Provides methods for guessing the namespaces and directories
|
4
|
+
# of projects. {Naming} uses the naming conventions of project names
|
5
|
+
# defined by the
|
6
|
+
# [Ruby Packaging Standard (RPS)](http://chneukirchen.github.com/rps/).
|
7
|
+
#
|
8
|
+
module Naming
|
9
|
+
# The directory which contains executables for a project
|
10
|
+
@@bin_dir = 'bin'
|
11
|
+
|
12
|
+
# The directory which contains the code for a project
|
13
|
+
@@lib_dir = 'lib'
|
14
|
+
|
15
|
+
# The directory which contains C extension code for a project
|
16
|
+
@@ext_dir = 'ext'
|
17
|
+
|
18
|
+
# The directory which contains data files for a project
|
19
|
+
@@data_dir = 'data'
|
20
|
+
|
21
|
+
# The directory which contains unit-tests for a project
|
22
|
+
@@test_dir = 'test'
|
23
|
+
|
24
|
+
# The directory which contains spec-tests for a project
|
25
|
+
@@spec_dir = 'spec'
|
26
|
+
|
27
|
+
# The directory which contains built packages
|
28
|
+
@@pkg_dir = 'pkg'
|
29
|
+
|
30
|
+
# Words used in project names, but never in directory names
|
31
|
+
@@ignore_namespaces = %w[ruby java]
|
32
|
+
|
33
|
+
# Common project prefixes and namespaces
|
34
|
+
@@common_namespaces = {
|
35
|
+
'ffi' => 'FFI',
|
36
|
+
'dm' => 'DataMapper'
|
37
|
+
}
|
38
|
+
|
39
|
+
#
|
40
|
+
# Splits the project name into individual names.
|
41
|
+
#
|
42
|
+
# @param [String] name
|
43
|
+
# The name to split.
|
44
|
+
#
|
45
|
+
# @return [Array<String>]
|
46
|
+
# The individual names of the project name.
|
47
|
+
#
|
48
|
+
def names_in(name)
|
49
|
+
name.split('-').reject do |word|
|
50
|
+
@@ignore_namespaces.include?(word)
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
#
|
55
|
+
# Guesses the module names from a project name.
|
56
|
+
#
|
57
|
+
# @return [Array<String>]
|
58
|
+
# The module names for a project.
|
59
|
+
#
|
60
|
+
def modules_of(name)
|
61
|
+
names_in(name).map do |words|
|
62
|
+
words.split('_').map { |word|
|
63
|
+
@@common_namespaces[word] || word.capitalize
|
64
|
+
}.join
|
65
|
+
end
|
66
|
+
end
|
67
|
+
|
68
|
+
#
|
69
|
+
# Guesses the full namespace for a project.
|
70
|
+
#
|
71
|
+
# @return [String]
|
72
|
+
# The full module namespace for a project.
|
73
|
+
#
|
74
|
+
def namespace_of(name)
|
75
|
+
modules_of(name).join('::')
|
76
|
+
end
|
77
|
+
|
78
|
+
#
|
79
|
+
# Converts a camel-case name to an underscored file name.
|
80
|
+
#
|
81
|
+
# @param [String] name
|
82
|
+
# The name to underscore.
|
83
|
+
#
|
84
|
+
# @return [String]
|
85
|
+
# The underscored version of the name.
|
86
|
+
#
|
87
|
+
def underscore(name)
|
88
|
+
name.gsub(/[^A-Z_][A-Z][^A-Z_]/) { |cap|
|
89
|
+
cap[0,1] + '_' + cap[1..-1]
|
90
|
+
}.downcase
|
91
|
+
end
|
92
|
+
|
93
|
+
#
|
94
|
+
# Guesses the namespace directories within `lib/` for a project.
|
95
|
+
#
|
96
|
+
# @return [Array<String>]
|
97
|
+
# The namespace directories for the project.
|
98
|
+
#
|
99
|
+
def namespace_dirs_of(name)
|
100
|
+
names_in(name).map { |word| underscore(word) }
|
101
|
+
end
|
102
|
+
|
103
|
+
#
|
104
|
+
# Guesses the namespace directory within `lib/` for a project.
|
105
|
+
#
|
106
|
+
# @return [String]
|
107
|
+
# The namespace directory for the project.
|
108
|
+
#
|
109
|
+
def namespace_path_of(name)
|
110
|
+
File.join(namespace_dirs_of(name))
|
111
|
+
end
|
112
|
+
end
|
113
|
+
end
|