ore-core 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- 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/settings.rb
ADDED
@@ -0,0 +1,274 @@
|
|
1
|
+
require 'ore/exceptions/invalid_metadata'
|
2
|
+
require 'ore/versions/version'
|
3
|
+
require 'ore/dependency'
|
4
|
+
|
5
|
+
module Ore
|
6
|
+
#
|
7
|
+
# A mixin for {Project} which provides methods for normalizing and
|
8
|
+
# setting project attributes.
|
9
|
+
#
|
10
|
+
module Settings
|
11
|
+
protected
|
12
|
+
|
13
|
+
#
|
14
|
+
# Sets the version of the project.
|
15
|
+
#
|
16
|
+
# @param [Hash<Integer>, String] version
|
17
|
+
# The version from the metadata file.
|
18
|
+
#
|
19
|
+
# @raise [InvalidVersion]
|
20
|
+
# The version must either be a `String` or a `Hash`.
|
21
|
+
#
|
22
|
+
def set_version!(version)
|
23
|
+
case version
|
24
|
+
when Hash
|
25
|
+
major = version['major']
|
26
|
+
minor = version['minor']
|
27
|
+
patch = version['patch']
|
28
|
+
build = version['build']
|
29
|
+
|
30
|
+
@version = Versions::Version.new(major,minor,patch,build)
|
31
|
+
when String
|
32
|
+
@version = Versions::Version.parse(version.to_s)
|
33
|
+
else
|
34
|
+
raise(InvalidMetadata,"version must be a Hash or a String")
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
#
|
39
|
+
# Sets the license(s) of the project.
|
40
|
+
#
|
41
|
+
# @param [Array, String] license
|
42
|
+
# The license(s) of the project.
|
43
|
+
#
|
44
|
+
def set_license!(license)
|
45
|
+
if license.kind_of?(Array)
|
46
|
+
@licenses += license
|
47
|
+
else
|
48
|
+
@licenses << license
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
#
|
53
|
+
# Sets the authors of the project.
|
54
|
+
#
|
55
|
+
# @param [Array<String>, String] authors
|
56
|
+
# The authors listed in the metadata file.
|
57
|
+
#
|
58
|
+
def set_authors!(authors)
|
59
|
+
if authors.kind_of?(Array)
|
60
|
+
@authors += authors
|
61
|
+
else
|
62
|
+
@authors << authors
|
63
|
+
end
|
64
|
+
end
|
65
|
+
|
66
|
+
#
|
67
|
+
# Sets the release date of the project.
|
68
|
+
#
|
69
|
+
# @param [String] date
|
70
|
+
# The release date from the metadata file.
|
71
|
+
#
|
72
|
+
def set_date!(date)
|
73
|
+
@date = Date.parse(date)
|
74
|
+
end
|
75
|
+
|
76
|
+
#
|
77
|
+
# Sets the require-paths of the project.
|
78
|
+
#
|
79
|
+
# @param [Array<String>, String] paths
|
80
|
+
# The require-paths or the glob-pattern listed in the metadata file.
|
81
|
+
#
|
82
|
+
def set_require_paths!(paths)
|
83
|
+
if paths.kind_of?(Array)
|
84
|
+
paths.each { |path| add_require_path(path) }
|
85
|
+
else
|
86
|
+
glob(paths) { |path| add_require_path(path) }
|
87
|
+
end
|
88
|
+
end
|
89
|
+
|
90
|
+
#
|
91
|
+
# Sets the executables of the project.
|
92
|
+
#
|
93
|
+
# @param [Array<String>, String]
|
94
|
+
# The executable names or the glob-pattern listed in the metadata
|
95
|
+
# file.
|
96
|
+
#
|
97
|
+
def set_executables!(paths)
|
98
|
+
if paths.kind_of?(Array)
|
99
|
+
paths.each { |path| add_executable(path) }
|
100
|
+
else
|
101
|
+
glob(paths) { |path| add_executable(path) }
|
102
|
+
end
|
103
|
+
end
|
104
|
+
|
105
|
+
#
|
106
|
+
# Sets the default executable of the project.
|
107
|
+
#
|
108
|
+
# @param [String] name
|
109
|
+
# The default executable name listed in the metadata file.
|
110
|
+
#
|
111
|
+
def set_default_executable!(name)
|
112
|
+
if @executables.include?(name)
|
113
|
+
@default_executable = name
|
114
|
+
else
|
115
|
+
warn "#{name} is not in the executables list"
|
116
|
+
end
|
117
|
+
end
|
118
|
+
|
119
|
+
#
|
120
|
+
# Sets the extra documentation files of the project.
|
121
|
+
#
|
122
|
+
# @param [Array<String>, String] paths
|
123
|
+
# The file paths or the glob-pattern listed in the metadata file.
|
124
|
+
#
|
125
|
+
def set_extra_doc_files!(paths)
|
126
|
+
if paths.kind_of?(Array)
|
127
|
+
paths.each { |path| add_extra_doc_file(path) }
|
128
|
+
else
|
129
|
+
glob(paths) { |path| add_extra_doc_file(path) }
|
130
|
+
end
|
131
|
+
end
|
132
|
+
|
133
|
+
#
|
134
|
+
# Sets the files of the project.
|
135
|
+
#
|
136
|
+
# @param [Array<String>, String] paths
|
137
|
+
# The files or the glob-pattern listed in the metadata file.
|
138
|
+
#
|
139
|
+
def set_files!(paths)
|
140
|
+
if paths.kind_of?(Array)
|
141
|
+
paths.each { |path| add_file(path) }
|
142
|
+
else
|
143
|
+
glob(paths) { |path| add_file(path) }
|
144
|
+
end
|
145
|
+
end
|
146
|
+
|
147
|
+
#
|
148
|
+
# Sets the test-files of the project.
|
149
|
+
#
|
150
|
+
# @param [Array<String>, String] paths
|
151
|
+
# The test-files of the glob-pattern listed in the metadata file.
|
152
|
+
#
|
153
|
+
def set_test_files!(paths)
|
154
|
+
if paths.kind_of?(Array)
|
155
|
+
paths.each { |path| add_test_file(path) }
|
156
|
+
else
|
157
|
+
glob(paths) { |path| add_test_file(path) }
|
158
|
+
end
|
159
|
+
end
|
160
|
+
|
161
|
+
#
|
162
|
+
# Sets the post-installation message.
|
163
|
+
#
|
164
|
+
# @param [String] message
|
165
|
+
# The post-install message.
|
166
|
+
#
|
167
|
+
# @since 0.1.0
|
168
|
+
#
|
169
|
+
def set_post_install_message!(message)
|
170
|
+
@post_install_message = message
|
171
|
+
end
|
172
|
+
|
173
|
+
#
|
174
|
+
# Sets the external requirements of the project.
|
175
|
+
#
|
176
|
+
# @param [Array, String] requirements
|
177
|
+
# The external requirements.
|
178
|
+
#
|
179
|
+
# @since 0.2.0
|
180
|
+
#
|
181
|
+
def set_requirements!(requirements)
|
182
|
+
if requirements.kind_of?(Array)
|
183
|
+
@requirements += requirements
|
184
|
+
else
|
185
|
+
@requirements << requirements
|
186
|
+
end
|
187
|
+
end
|
188
|
+
|
189
|
+
#
|
190
|
+
# Sets the Ruby version required by the project.
|
191
|
+
#
|
192
|
+
# @param [String] version
|
193
|
+
# The version requirement.
|
194
|
+
#
|
195
|
+
def set_required_ruby_version!(version)
|
196
|
+
@required_ruby_version = version.to_s
|
197
|
+
end
|
198
|
+
|
199
|
+
#
|
200
|
+
# Sets the RubyGems version required by the project.
|
201
|
+
#
|
202
|
+
# @param [String] version
|
203
|
+
# The version requirement.
|
204
|
+
#
|
205
|
+
def set_required_rubygems_version!(version)
|
206
|
+
@required_rubygems_version = version.to_s
|
207
|
+
end
|
208
|
+
|
209
|
+
#
|
210
|
+
# Sets the dependencies of the project.
|
211
|
+
#
|
212
|
+
# @param [Hash{String => String}] dependencies
|
213
|
+
# The dependencey names and versions listed in the metadata file.
|
214
|
+
#
|
215
|
+
# @raise [InvalidMetadata]
|
216
|
+
# The dependencies must be a `Hash`.
|
217
|
+
#
|
218
|
+
def set_dependencies!(dependencies)
|
219
|
+
unless dependencies.kind_of?(Hash)
|
220
|
+
raise(InvalidMetadata,"dependencies must be a Hash")
|
221
|
+
end
|
222
|
+
|
223
|
+
dependencies.each do |name,versions|
|
224
|
+
versions = versions.to_s
|
225
|
+
|
226
|
+
@dependencies << Dependency.parse_versions(name,versions)
|
227
|
+
end
|
228
|
+
end
|
229
|
+
|
230
|
+
#
|
231
|
+
# Sets the runtime-dependencies of the project.
|
232
|
+
#
|
233
|
+
# @param [Hash{String => String}] dependencies
|
234
|
+
# The runtime-dependencey names and versions listed in the metadata
|
235
|
+
# file.
|
236
|
+
#
|
237
|
+
# @raise [InvalidMetadata]
|
238
|
+
# The runtime-dependencies must be a `Hash`.
|
239
|
+
#
|
240
|
+
def set_runtime_dependencies!(dependencies)
|
241
|
+
unless dependencies.kind_of?(Hash)
|
242
|
+
raise(InvalidMetadata,"runtime_dependencies must be a Hash")
|
243
|
+
end
|
244
|
+
|
245
|
+
dependencies.each do |name,versions|
|
246
|
+
versions = versions.to_s
|
247
|
+
|
248
|
+
@runtime_dependencies << Dependency.parse_versions(name,versions)
|
249
|
+
end
|
250
|
+
end
|
251
|
+
|
252
|
+
#
|
253
|
+
# Sets the development-dependencies of the project.
|
254
|
+
#
|
255
|
+
# @param [Hash{String => String}] dependencies
|
256
|
+
# The development-dependencey names and versions listed in the
|
257
|
+
# metadata file.
|
258
|
+
#
|
259
|
+
# @raise [InvalidMetadata]
|
260
|
+
# The development-dependencies must be a `Hash`.
|
261
|
+
#
|
262
|
+
def set_development_dependencies!(dependencies)
|
263
|
+
unless dependencies.kind_of?(Hash)
|
264
|
+
raise(InvalidMetadata,"development_dependencies must be a Hash")
|
265
|
+
end
|
266
|
+
|
267
|
+
dependencies.each do |name,versions|
|
268
|
+
versions = versions.to_s
|
269
|
+
|
270
|
+
@development_dependencies << Dependency.parse_versions(name,versions)
|
271
|
+
end
|
272
|
+
end
|
273
|
+
end
|
274
|
+
end
|
@@ -0,0 +1,29 @@
|
|
1
|
+
require 'ore/project'
|
2
|
+
|
3
|
+
module Ore
|
4
|
+
#
|
5
|
+
# Acts as a drop-in replacement for calling `Gem::Specification.new`
|
6
|
+
# in a projects gemspec file.
|
7
|
+
#
|
8
|
+
module Specification
|
9
|
+
#
|
10
|
+
# Creates a new Gem Specification, and automatically populates it
|
11
|
+
# using the metadata file.
|
12
|
+
#
|
13
|
+
# @yield [gemspec]
|
14
|
+
# The given block will be passed the populated Gem Specification
|
15
|
+
# object.
|
16
|
+
#
|
17
|
+
# @yieldparam [Gem::Specification] gemspec
|
18
|
+
# The newly created Gem Specification.
|
19
|
+
#
|
20
|
+
# @return [Gem::Specification]
|
21
|
+
# The Gem Specification.
|
22
|
+
#
|
23
|
+
# @see Project#to_gemspec
|
24
|
+
#
|
25
|
+
def Specification.new(&block)
|
26
|
+
Project.find.to_gemspec(&block)
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
data/lib/ore/versions.rb
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require 'ore/versions/exceptions/invalid_version'
|
@@ -0,0 +1,75 @@
|
|
1
|
+
require 'ore/versions/exceptions/invalid_version'
|
2
|
+
|
3
|
+
require 'rubygems/version'
|
4
|
+
|
5
|
+
module Ore
|
6
|
+
module Versions
|
7
|
+
#
|
8
|
+
# Represents a standard three-number version.
|
9
|
+
#
|
10
|
+
# @see http://semver.org/
|
11
|
+
#
|
12
|
+
class Version < Gem::Version
|
13
|
+
|
14
|
+
# Major version number
|
15
|
+
attr_reader :major
|
16
|
+
|
17
|
+
# Minor version number
|
18
|
+
attr_reader :minor
|
19
|
+
|
20
|
+
# Patch version number
|
21
|
+
attr_reader :patch
|
22
|
+
|
23
|
+
# The build string
|
24
|
+
attr_reader :build
|
25
|
+
|
26
|
+
#
|
27
|
+
# Creates a new version.
|
28
|
+
#
|
29
|
+
# @param [Integer, nil] major
|
30
|
+
# The major version number.
|
31
|
+
#
|
32
|
+
# @param [Integer, nil] minor
|
33
|
+
# The minor version number.
|
34
|
+
#
|
35
|
+
# @param [Integer, nil] patch
|
36
|
+
# The patch version number.
|
37
|
+
#
|
38
|
+
# @param [Integer, nil] build (nil)
|
39
|
+
# The build version number.
|
40
|
+
#
|
41
|
+
def initialize(major,minor,patch,build=nil)
|
42
|
+
@major = (major || 0)
|
43
|
+
@minor = (minor || 0)
|
44
|
+
@patch = (patch || 0)
|
45
|
+
@build = build
|
46
|
+
|
47
|
+
numbers = [@major,@minor,@patch]
|
48
|
+
numbers << @build if @build
|
49
|
+
|
50
|
+
super(numbers.join('.'))
|
51
|
+
end
|
52
|
+
|
53
|
+
#
|
54
|
+
# Parses a version string.
|
55
|
+
#
|
56
|
+
# @param [String] string
|
57
|
+
# The version string.
|
58
|
+
#
|
59
|
+
# @return [Version]
|
60
|
+
# The parsed version.
|
61
|
+
#
|
62
|
+
def self.parse(string)
|
63
|
+
major, minor, patch, build = string.split('.',4)
|
64
|
+
|
65
|
+
return self.new(
|
66
|
+
(major || 0).to_i,
|
67
|
+
(minor || 0).to_i,
|
68
|
+
(patch || 0).to_i,
|
69
|
+
build
|
70
|
+
)
|
71
|
+
end
|
72
|
+
|
73
|
+
end
|
74
|
+
end
|
75
|
+
end
|
@@ -0,0 +1,126 @@
|
|
1
|
+
require 'ore/versions/version'
|
2
|
+
require 'ore/naming'
|
3
|
+
|
4
|
+
module Ore
|
5
|
+
module Versions
|
6
|
+
#
|
7
|
+
# Represents a version loaded from a Ruby `VERSION` constant or
|
8
|
+
# `Version` module.
|
9
|
+
#
|
10
|
+
class VersionConstant < Version
|
11
|
+
|
12
|
+
include Naming
|
13
|
+
|
14
|
+
# Common file-name that the `VERSION` constant or `Version` module
|
15
|
+
# is defined within.
|
16
|
+
@@file_name = 'version.rb'
|
17
|
+
|
18
|
+
#
|
19
|
+
# Finds the `version.rb` file.
|
20
|
+
#
|
21
|
+
# @param [Project] project
|
22
|
+
# The project.
|
23
|
+
#
|
24
|
+
# @return [VersionConstant, nil]
|
25
|
+
# The loaded version constant.
|
26
|
+
#
|
27
|
+
def self.find(project)
|
28
|
+
if project.namespace_dir
|
29
|
+
path = File.join(project.namespace_dir,@@file_name)
|
30
|
+
|
31
|
+
self.load(project.lib_path(path)) if project.lib_file?(path)
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
#
|
36
|
+
# Extracts the `VERSION` constant or the major / minor / patch / build
|
37
|
+
# version numbers from the `Version` module.
|
38
|
+
#
|
39
|
+
# @param [String] path
|
40
|
+
# The path to the `version.rb` file.
|
41
|
+
#
|
42
|
+
# @return [VersionConstant, nil]
|
43
|
+
# The loaded version constant.
|
44
|
+
#
|
45
|
+
def self.load(path)
|
46
|
+
major = nil
|
47
|
+
minor = nil
|
48
|
+
patch = nil
|
49
|
+
build = nil
|
50
|
+
|
51
|
+
File.open(path) do |file|
|
52
|
+
file.each_line do |line|
|
53
|
+
unless line =~ /^\s*#/ # skip commented lines
|
54
|
+
if line =~ /(VERSION|Version)\s*=\s*/
|
55
|
+
version = extract_version(line)
|
56
|
+
|
57
|
+
return self.parse(version) if version
|
58
|
+
elsif line =~ /(MAJOR|Major)\s*=\s*/
|
59
|
+
major ||= extract_number(line)
|
60
|
+
elsif line =~ /(MINOR|Minor)\s*=\s*/
|
61
|
+
minor ||= extract_number(line)
|
62
|
+
elsif line =~ /(PATCH|Patch)\s*=\s*/
|
63
|
+
patch ||= extract_number(line)
|
64
|
+
elsif line =~ /(BUILD|Build)\s*=\s*/
|
65
|
+
build ||= extract_string(line)
|
66
|
+
end
|
67
|
+
|
68
|
+
break if (major && minor && patch && build)
|
69
|
+
end
|
70
|
+
end
|
71
|
+
end
|
72
|
+
|
73
|
+
return self.new(major,minor,patch,build)
|
74
|
+
end
|
75
|
+
|
76
|
+
protected
|
77
|
+
|
78
|
+
#
|
79
|
+
# Extracts the version string from a `VERSION` constant declaration.
|
80
|
+
#
|
81
|
+
# @param [String] line
|
82
|
+
# The line of Ruby code where the `VERSION` constant was defined.
|
83
|
+
#
|
84
|
+
# @return [String, nil]
|
85
|
+
# The extracted version string.
|
86
|
+
#
|
87
|
+
def self.extract_version(line)
|
88
|
+
if (match = line.match(/=\s*['"](\d+\.\d+\.\d+(\.\w+)?)['"]/))
|
89
|
+
match[1]
|
90
|
+
end
|
91
|
+
end
|
92
|
+
|
93
|
+
#
|
94
|
+
# Extracts a number from a `BUILD` constant declaration.
|
95
|
+
#
|
96
|
+
# @param [String] line
|
97
|
+
# The line of Ruby code where the constant was defined.
|
98
|
+
#
|
99
|
+
# @return [String, nil]
|
100
|
+
# The extracted string.
|
101
|
+
#
|
102
|
+
def self.extract_string(line)
|
103
|
+
if (match = line.match(/=\s*['"]?(\w+)['"]?/))
|
104
|
+
match[1]
|
105
|
+
end
|
106
|
+
end
|
107
|
+
|
108
|
+
#
|
109
|
+
# Extracts a version number from a `MAJOR`, `MINOR`, `PATCH` or
|
110
|
+
# `BUILD` constant declaration.
|
111
|
+
#
|
112
|
+
# @param [String] line
|
113
|
+
# The line of Ruby code where the constant was defined.
|
114
|
+
#
|
115
|
+
# @return [Integer, nil]
|
116
|
+
# The extracted version number.
|
117
|
+
#
|
118
|
+
def self.extract_number(line)
|
119
|
+
if (match = line.match(/=\s*['"]?(\d+)['"]?/))
|
120
|
+
match[1].to_i
|
121
|
+
end
|
122
|
+
end
|
123
|
+
|
124
|
+
end
|
125
|
+
end
|
126
|
+
end
|