skillnad 1.2.2
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.
- checksums.yaml +7 -0
- data/LICENSE +20 -0
- data/README.md +172 -0
- data/Rakefile +17 -0
- data/lib/rubygems/commands/compare_command.rb +105 -0
- data/lib/rubygems/comparator/base.rb +45 -0
- data/lib/rubygems/comparator/dependency_comparator.rb +110 -0
- data/lib/rubygems/comparator/dir_utils.rb +51 -0
- data/lib/rubygems/comparator/file_list_comparator.rb +212 -0
- data/lib/rubygems/comparator/gemfile_comparator.rb +149 -0
- data/lib/rubygems/comparator/monitor.rb +140 -0
- data/lib/rubygems/comparator/report/entry.rb +40 -0
- data/lib/rubygems/comparator/report.rb +131 -0
- data/lib/rubygems/comparator/spec_comparator.rb +66 -0
- data/lib/rubygems/comparator/utils.rb +134 -0
- data/lib/rubygems/comparator/version.rb +5 -0
- data/lib/rubygems/comparator.rb +308 -0
- data/lib/rubygems_plugin.rb +4 -0
- data/test/gemfiles/lorem-0.0.1/Gemfile +4 -0
- data/test/gemfiles/lorem-0.0.1/LICENSE.txt +22 -0
- data/test/gemfiles/lorem-0.0.1/README.md +29 -0
- data/test/gemfiles/lorem-0.0.1/Rakefile +2 -0
- data/test/gemfiles/lorem-0.0.1/lib/lorem/version.rb +3 -0
- data/test/gemfiles/lorem-0.0.1/lib/lorem.rb +7 -0
- data/test/gemfiles/lorem-0.0.1/lorem.gemspec +24 -0
- data/test/gemfiles/lorem-0.0.1.gem +0 -0
- data/test/gemfiles/lorem-0.0.2/CHANGELOG.md +6 -0
- data/test/gemfiles/lorem-0.0.2/Gemfile +4 -0
- data/test/gemfiles/lorem-0.0.2/LICENSE.txt +3 -0
- data/test/gemfiles/lorem-0.0.2/README.md +29 -0
- data/test/gemfiles/lorem-0.0.2/Rakefile +2 -0
- data/test/gemfiles/lorem-0.0.2/lib/lorem/version.rb +3 -0
- data/test/gemfiles/lorem-0.0.2/lib/lorem.rb +11 -0
- data/test/gemfiles/lorem-0.0.2/lorem.gemspec +24 -0
- data/test/gemfiles/lorem-0.0.2.gem +0 -0
- data/test/gemfiles/lorem-0.0.3/CHANGELOG.md +14 -0
- data/test/gemfiles/lorem-0.0.3/Gemfile +7 -0
- data/test/gemfiles/lorem-0.0.3/LICENSE.txt +3 -0
- data/test/gemfiles/lorem-0.0.3/README.md +29 -0
- data/test/gemfiles/lorem-0.0.3/Rakefile +2 -0
- data/test/gemfiles/lorem-0.0.3/bin/lorem +3 -0
- data/test/gemfiles/lorem-0.0.3/lib/lorem/utils.rb +7 -0
- data/test/gemfiles/lorem-0.0.3/lib/lorem/version.rb +3 -0
- data/test/gemfiles/lorem-0.0.3/lib/lorem.rb +11 -0
- data/test/gemfiles/lorem-0.0.3/lorem.gemspec +25 -0
- data/test/gemfiles/lorem-0.0.3.gem +0 -0
- data/test/gemfiles/lorem-0.0.4/CHANGELOG.md +21 -0
- data/test/gemfiles/lorem-0.0.4/Gemfile +6 -0
- data/test/gemfiles/lorem-0.0.4/LICENSE.txt +3 -0
- data/test/gemfiles/lorem-0.0.4/README.md +29 -0
- data/test/gemfiles/lorem-0.0.4/Rakefile +2 -0
- data/test/gemfiles/lorem-0.0.4/bin/lorem +3 -0
- data/test/gemfiles/lorem-0.0.4/lib/lorem/utils.rb +7 -0
- data/test/gemfiles/lorem-0.0.4/lib/lorem/version.rb +3 -0
- data/test/gemfiles/lorem-0.0.4/lib/lorem.rb +11 -0
- data/test/gemfiles/lorem-0.0.4/lorem.gemspec +25 -0
- data/test/gemfiles/lorem-0.0.4.gem +0 -0
- data/test/rubygems/comparator/test_dependency_comparator.rb +32 -0
- data/test/rubygems/comparator/test_dir_utils.rb +47 -0
- data/test/rubygems/comparator/test_file_list_comparator.rb +29 -0
- data/test/rubygems/comparator/test_gemfile_comparator.rb +16 -0
- data/test/rubygems/comparator/test_monitor.rb +183 -0
- data/test/rubygems/comparator/test_report.rb +25 -0
- data/test/rubygems/comparator/test_spec_comparator.rb +150 -0
- data/test/rubygems/comparator/test_utils.rb +35 -0
- data/test/rubygems/test_gem_commands_compare_command.rb +41 -0
- data/test/test_helper.rb +53 -0
- metadata +165 -0
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require 'rubygems/comparator/base'
|
|
4
|
+
|
|
5
|
+
class Gem::Comparator
|
|
6
|
+
|
|
7
|
+
##
|
|
8
|
+
# Gem::Comparator::SpecComparator can
|
|
9
|
+
# compare values from the gem verions specs
|
|
10
|
+
|
|
11
|
+
class SpecComparator < Gem::Comparator::Base
|
|
12
|
+
|
|
13
|
+
##
|
|
14
|
+
# Compare common fields in spec
|
|
15
|
+
|
|
16
|
+
def compare(specs, report, options = {})
|
|
17
|
+
info 'Checking spec parameters...'
|
|
18
|
+
p = options[:param]
|
|
19
|
+
b = options[:brief]
|
|
20
|
+
|
|
21
|
+
filter_params(SPEC_PARAMS, p, b).each do |param|
|
|
22
|
+
values = values_from_specs(param, specs)
|
|
23
|
+
|
|
24
|
+
if same_values?(values) && options[:log_all]
|
|
25
|
+
v = value(values[0])
|
|
26
|
+
report[param].section do
|
|
27
|
+
set_header "#{self.same} #{param}:"
|
|
28
|
+
puts v
|
|
29
|
+
end
|
|
30
|
+
elsif !same_values?(values)
|
|
31
|
+
report[param].set_header "#{different} #{param}:"
|
|
32
|
+
values.each_with_index do |value, index|
|
|
33
|
+
report[param] << \
|
|
34
|
+
"#{Rainbow(specs[index].version).cyan}: #{value}"
|
|
35
|
+
end
|
|
36
|
+
end
|
|
37
|
+
end
|
|
38
|
+
report
|
|
39
|
+
end
|
|
40
|
+
|
|
41
|
+
private
|
|
42
|
+
|
|
43
|
+
def value(value)
|
|
44
|
+
case value
|
|
45
|
+
when Gem::Requirement
|
|
46
|
+
unless value.requirements.empty?
|
|
47
|
+
r = value.requirements[0]
|
|
48
|
+
"#{r[0]} #{r[1].version} "
|
|
49
|
+
else
|
|
50
|
+
'[]'
|
|
51
|
+
end
|
|
52
|
+
when Gem::Platform
|
|
53
|
+
value.to_s
|
|
54
|
+
when String
|
|
55
|
+
return value unless value.empty?
|
|
56
|
+
''
|
|
57
|
+
else
|
|
58
|
+
value.inspect
|
|
59
|
+
end
|
|
60
|
+
end
|
|
61
|
+
|
|
62
|
+
def same_values?(values)
|
|
63
|
+
values.count(values[0]) == values.size
|
|
64
|
+
end
|
|
65
|
+
end
|
|
66
|
+
end
|
|
@@ -0,0 +1,134 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require 'rainbow'
|
|
4
|
+
require 'rubygems'
|
|
5
|
+
require 'rubygems/user_interaction'
|
|
6
|
+
|
|
7
|
+
class Gem::Comparator
|
|
8
|
+
module Utils
|
|
9
|
+
include Gem::UserInteraction
|
|
10
|
+
|
|
11
|
+
SPACE = ' '
|
|
12
|
+
DEFAULT_INDENT = SPACE*7
|
|
13
|
+
OPERATORS = ['=', '!=', '>', '<', '>=', '<=', '~>']
|
|
14
|
+
VERSION_REGEX = /\A(\d+\.){0,}\d+(\.[a-zA-Z]+\.{0,1}\d{0,1}){0,1}\z/
|
|
15
|
+
SPEC_PARAMS = %w[ author
|
|
16
|
+
authors
|
|
17
|
+
bindir
|
|
18
|
+
cert_chain
|
|
19
|
+
date
|
|
20
|
+
description
|
|
21
|
+
email
|
|
22
|
+
executables
|
|
23
|
+
extensions
|
|
24
|
+
homepage
|
|
25
|
+
license
|
|
26
|
+
licenses
|
|
27
|
+
metadata
|
|
28
|
+
name
|
|
29
|
+
platform
|
|
30
|
+
post_install_message
|
|
31
|
+
rdoc_options
|
|
32
|
+
require_paths
|
|
33
|
+
required_ruby_version
|
|
34
|
+
required_rubygems_version
|
|
35
|
+
requirements
|
|
36
|
+
rubygems_version
|
|
37
|
+
signing_key
|
|
38
|
+
summary
|
|
39
|
+
version ]
|
|
40
|
+
SPEC_FILES_PARAMS = %w[ files
|
|
41
|
+
test_files
|
|
42
|
+
extra_rdoc_files ]
|
|
43
|
+
DEPENDENCY_PARAMS = %w[ runtime_dependency
|
|
44
|
+
development_dependency ]
|
|
45
|
+
GEMFILE_PARAMS = %w[ gemfiles ]
|
|
46
|
+
|
|
47
|
+
# Duplicates or obvious changes
|
|
48
|
+
FILTER_WHEN_BRIEF = %w[ author
|
|
49
|
+
date
|
|
50
|
+
license
|
|
51
|
+
platform
|
|
52
|
+
rubygems_version
|
|
53
|
+
version ]
|
|
54
|
+
|
|
55
|
+
# Not present in marshal file containing the specs
|
|
56
|
+
NOT_IN_MARSHAL = %w[ cert_chain
|
|
57
|
+
executables
|
|
58
|
+
extensions
|
|
59
|
+
extra_rdoc_files
|
|
60
|
+
files
|
|
61
|
+
license
|
|
62
|
+
licenses
|
|
63
|
+
metadata
|
|
64
|
+
post_install_message
|
|
65
|
+
rdoc_options
|
|
66
|
+
requirements
|
|
67
|
+
signing_key
|
|
68
|
+
test_files ]
|
|
69
|
+
|
|
70
|
+
private
|
|
71
|
+
|
|
72
|
+
def param_exists?(param)
|
|
73
|
+
(SPEC_PARAMS.include? param) ||
|
|
74
|
+
(SPEC_FILES_PARAMS.include? param) ||
|
|
75
|
+
(DEPENDENCY_PARAMS.include? param) ||
|
|
76
|
+
(GEMFILE_PARAMS.include? param)
|
|
77
|
+
end
|
|
78
|
+
|
|
79
|
+
def param_available_in_marshal?(param)
|
|
80
|
+
param_exists?(param) && !NOT_IN_MARSHAL.include?(param)
|
|
81
|
+
end
|
|
82
|
+
|
|
83
|
+
def filter_params(params, param, brief_mode = false)
|
|
84
|
+
if param
|
|
85
|
+
if params.include? param
|
|
86
|
+
return [param]
|
|
87
|
+
else
|
|
88
|
+
return []
|
|
89
|
+
end
|
|
90
|
+
end
|
|
91
|
+
if brief_mode
|
|
92
|
+
filter_for_brief_mode(params)
|
|
93
|
+
else
|
|
94
|
+
params
|
|
95
|
+
end
|
|
96
|
+
end
|
|
97
|
+
|
|
98
|
+
def filter_for_brief_mode(params)
|
|
99
|
+
params.delete_if{ |p| FILTER_WHEN_BRIEF.include?(p) }
|
|
100
|
+
end
|
|
101
|
+
|
|
102
|
+
def values_from_specs(param, specs)
|
|
103
|
+
values = []
|
|
104
|
+
specs.each do |s|
|
|
105
|
+
val = value_from_spec(param, s)
|
|
106
|
+
values << val if val
|
|
107
|
+
end
|
|
108
|
+
values
|
|
109
|
+
end
|
|
110
|
+
|
|
111
|
+
def value_from_spec(param, spec)
|
|
112
|
+
if spec.respond_to? :"#{param}"
|
|
113
|
+
spec.send(:"#{param}")
|
|
114
|
+
else
|
|
115
|
+
warn "#{spec.full_name} does not respond to " +
|
|
116
|
+
"#{param}, skipping check"
|
|
117
|
+
nil
|
|
118
|
+
end
|
|
119
|
+
end
|
|
120
|
+
|
|
121
|
+
def info(msg)
|
|
122
|
+
say msg if Gem.configuration.really_verbose
|
|
123
|
+
end
|
|
124
|
+
|
|
125
|
+
def warn(msg)
|
|
126
|
+
say Rainbow("WARNING: #{msg}").red
|
|
127
|
+
end
|
|
128
|
+
|
|
129
|
+
def error(msg)
|
|
130
|
+
say Rainbow("ERROR: #{msg}").red
|
|
131
|
+
exit 1
|
|
132
|
+
end
|
|
133
|
+
end
|
|
134
|
+
end
|
|
@@ -0,0 +1,308 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require 'tmpdir'
|
|
4
|
+
require 'rbconfig'
|
|
5
|
+
require 'rainbow'
|
|
6
|
+
require 'uri'
|
|
7
|
+
require 'json'
|
|
8
|
+
require 'rubygems/package'
|
|
9
|
+
require 'rubygems/dependency'
|
|
10
|
+
require 'rubygems/spec_fetcher'
|
|
11
|
+
require 'rubygems/remote_fetcher'
|
|
12
|
+
require 'rubygems/comparator/version'
|
|
13
|
+
require 'rubygems/comparator/utils'
|
|
14
|
+
require 'rubygems/comparator/report'
|
|
15
|
+
require 'rubygems/comparator/spec_comparator'
|
|
16
|
+
require 'rubygems/comparator/file_list_comparator'
|
|
17
|
+
require 'rubygems/comparator/dependency_comparator'
|
|
18
|
+
require 'rubygems/comparator/gemfile_comparator'
|
|
19
|
+
|
|
20
|
+
##
|
|
21
|
+
# Gem::Comparator compares different version of the given
|
|
22
|
+
# gem. It can compare spec values as well as file lists or
|
|
23
|
+
# Gemfiles
|
|
24
|
+
|
|
25
|
+
class Gem::Comparator
|
|
26
|
+
include Gem::Comparator::Utils
|
|
27
|
+
attr_accessor :options, :report
|
|
28
|
+
|
|
29
|
+
##
|
|
30
|
+
# Set the working dir and process options
|
|
31
|
+
#
|
|
32
|
+
# Creates temporal directory if the gem files shouldn't be kept
|
|
33
|
+
|
|
34
|
+
def initialize(options)
|
|
35
|
+
info "skillnad in #{VERSION}"
|
|
36
|
+
|
|
37
|
+
unless options[:keep_all]
|
|
38
|
+
options[:output] = Dir.mktmpdir
|
|
39
|
+
end
|
|
40
|
+
|
|
41
|
+
if options[:param] && !param_exists?(options[:param])
|
|
42
|
+
error 'Invalid parameter.'
|
|
43
|
+
end
|
|
44
|
+
|
|
45
|
+
if options[:no_color]
|
|
46
|
+
Rainbow.enabled = false
|
|
47
|
+
end
|
|
48
|
+
|
|
49
|
+
# Let's override platforms with the latest one if
|
|
50
|
+
# a platform has been specified via --platform
|
|
51
|
+
if options[:added_platform]
|
|
52
|
+
Gem.platforms = [Gem.platforms.last]
|
|
53
|
+
options[:platform] = Gem.platforms.last.to_s
|
|
54
|
+
info "Overriding platform to: #{options[:platform]}"
|
|
55
|
+
end
|
|
56
|
+
|
|
57
|
+
@options = options
|
|
58
|
+
|
|
59
|
+
# Results from the comparison
|
|
60
|
+
@report = Gem::Comparator::Report.new
|
|
61
|
+
end
|
|
62
|
+
|
|
63
|
+
##
|
|
64
|
+
# Compare versions
|
|
65
|
+
#
|
|
66
|
+
# Compares file lists, requirements, other meta data
|
|
67
|
+
|
|
68
|
+
def compare_versions(gem_name, versions)
|
|
69
|
+
# Expand versions (<=, >=, ~>) and sort them
|
|
70
|
+
compared_versions = expand_versions(gem_name, versions)
|
|
71
|
+
|
|
72
|
+
if versions.include?('_') && (compared_versions.size == 1)
|
|
73
|
+
error 'Latest upstream version matches the version given. Nothing to compare.'
|
|
74
|
+
elsif versions.include?('_') && (compared_versions.size == (versions.size - 1))
|
|
75
|
+
warn 'Latest upstream version matches one of the versions given.'
|
|
76
|
+
elsif compared_versions.size == 1
|
|
77
|
+
error 'Only one version specified. Specify at lease two versions.'
|
|
78
|
+
end
|
|
79
|
+
|
|
80
|
+
# This should match the final versions that has been compared
|
|
81
|
+
@compared_versions = compared_versions
|
|
82
|
+
|
|
83
|
+
compared_versions.each do |version|
|
|
84
|
+
download_gems? ?
|
|
85
|
+
get_package(gem_name, version) :
|
|
86
|
+
get_specification(gem_name, version)
|
|
87
|
+
end
|
|
88
|
+
|
|
89
|
+
@report.set_header "Compared versions: #{@compared_versions}"
|
|
90
|
+
|
|
91
|
+
comparators = [SpecComparator,
|
|
92
|
+
FileListComparator,
|
|
93
|
+
DependencyComparator,
|
|
94
|
+
GemfileComparator]
|
|
95
|
+
|
|
96
|
+
# Use different gem sources if specified
|
|
97
|
+
with_sources @options[:sources] do
|
|
98
|
+
comparators.each do |c|
|
|
99
|
+
comparator = c.new
|
|
100
|
+
cmp = (comparator.compares == :packages) ? gem_packages.values : gem_specs.values
|
|
101
|
+
@report = comparator.compare(cmp, @report, @options)
|
|
102
|
+
end
|
|
103
|
+
end
|
|
104
|
+
|
|
105
|
+
# Clean up
|
|
106
|
+
FileUtils.rm_rf options[:output] unless options[:keep_all]
|
|
107
|
+
end
|
|
108
|
+
|
|
109
|
+
def print_results
|
|
110
|
+
info 'Printing results...'
|
|
111
|
+
@report.print
|
|
112
|
+
end
|
|
113
|
+
|
|
114
|
+
private
|
|
115
|
+
|
|
116
|
+
def with_sources(sources, &block)
|
|
117
|
+
if sources
|
|
118
|
+
override_sources sources do
|
|
119
|
+
yield
|
|
120
|
+
end
|
|
121
|
+
else
|
|
122
|
+
yield
|
|
123
|
+
end
|
|
124
|
+
end
|
|
125
|
+
|
|
126
|
+
def override_sources(new_sources, &block)
|
|
127
|
+
original_sources = Gem.sources.clone
|
|
128
|
+
old_sources = Gem.sources.to_a
|
|
129
|
+
old_sources.each do |source_uri|
|
|
130
|
+
Gem.sources.delete source_uri
|
|
131
|
+
end
|
|
132
|
+
new_sources.each do |source_uri|
|
|
133
|
+
source = Gem::Source.new source_uri
|
|
134
|
+
source.load_specs :released
|
|
135
|
+
Gem.sources << source
|
|
136
|
+
end
|
|
137
|
+
Gem.configuration.write
|
|
138
|
+
yield
|
|
139
|
+
rescue URI::Error, ArgumentError
|
|
140
|
+
error 'Given URI is not valid.'
|
|
141
|
+
rescue Gem::RemoteFetcher::FetchError => e
|
|
142
|
+
error "Fetching the gem from the given URI failed with the " +
|
|
143
|
+
"following error:\n #{e.message}"
|
|
144
|
+
ensure
|
|
145
|
+
original_sources.each do |source_uri|
|
|
146
|
+
source = Gem::Source.new source_uri
|
|
147
|
+
source.load_specs :released
|
|
148
|
+
Gem.sources << source
|
|
149
|
+
end
|
|
150
|
+
Gem.configuration.write
|
|
151
|
+
end
|
|
152
|
+
|
|
153
|
+
##
|
|
154
|
+
# If there is an unexpanded version in +versions+ such
|
|
155
|
+
# as '>= 4.0.0' or '~>1.0.0', find all existing
|
|
156
|
+
# +gem_name+ versions that match the criteria
|
|
157
|
+
#
|
|
158
|
+
# Return list of expanded versions
|
|
159
|
+
|
|
160
|
+
def expand_versions(gem_name, versions)
|
|
161
|
+
info "Expanding versions #{versions}..."
|
|
162
|
+
expanded = []
|
|
163
|
+
versions.each do |version|
|
|
164
|
+
version = latest_gem_version(gem_name) if version == '_'
|
|
165
|
+
if version =~ VERSION_REGEX
|
|
166
|
+
expanded << version
|
|
167
|
+
next
|
|
168
|
+
end
|
|
169
|
+
op, v = (version.scan(/(>=|<=|~>|!=|>|<|=)\s*(.*)/)).flatten
|
|
170
|
+
# Supported operator and version?
|
|
171
|
+
if OPERATORS.include?(op) && v =~ VERSION_REGEX
|
|
172
|
+
dep = Gem::Dependency.new gem_name, version
|
|
173
|
+
specs_and_sources, _errors = Gem::SpecFetcher.fetcher.spec_for_dependency dep
|
|
174
|
+
specs_and_sources.each do |s|
|
|
175
|
+
expanded << s[0].version
|
|
176
|
+
end
|
|
177
|
+
else
|
|
178
|
+
warn "Unsupported version specification: #{version}, skipping."
|
|
179
|
+
end
|
|
180
|
+
end
|
|
181
|
+
|
|
182
|
+
versions = expanded.uniq.map do |v|
|
|
183
|
+
Gem::Version.new v
|
|
184
|
+
end.sort.map(&:to_s)
|
|
185
|
+
|
|
186
|
+
error 'No versions found.' if versions.size == 0
|
|
187
|
+
|
|
188
|
+
info "Expanded versions: #{versions}"
|
|
189
|
+
versions
|
|
190
|
+
end
|
|
191
|
+
|
|
192
|
+
def remote_gem_versions(gem_name)
|
|
193
|
+
body_str = URI.open("https://rubygems.org/api/v1/versions/#{gem_name}.json").read
|
|
194
|
+
json = JSON.parse(body_str)
|
|
195
|
+
gems = json.collect { |version| version['number'] }
|
|
196
|
+
info "Upstream versions: #{gems}"
|
|
197
|
+
gems
|
|
198
|
+
# "This rubygem could not be found."
|
|
199
|
+
rescue JSON::ParserError
|
|
200
|
+
error "Gem #{gem_name} does not exist."
|
|
201
|
+
exit 1
|
|
202
|
+
end
|
|
203
|
+
|
|
204
|
+
def latest_gem_version(gem_name)
|
|
205
|
+
remote_gem_versions(gem_name).map{ |v| Gem::Version.new v }.max.to_s
|
|
206
|
+
end
|
|
207
|
+
|
|
208
|
+
def gem_file_name(gem_name, version)
|
|
209
|
+
if @options[:platform]
|
|
210
|
+
"#{gem_name}-#{version}-#{@options[:platform]}.gem"
|
|
211
|
+
else
|
|
212
|
+
"#{gem_name}-#{version}.gem"
|
|
213
|
+
end
|
|
214
|
+
end
|
|
215
|
+
|
|
216
|
+
def get_package(gem_name, version)
|
|
217
|
+
gem_file = gem_file_name(gem_name, version)
|
|
218
|
+
return gem_packages["#{gem_file}"] if gem_packages["#{gem_file}"]
|
|
219
|
+
|
|
220
|
+
find_downloaded_gem(gem_file)
|
|
221
|
+
return gem_packages["#{gem_file}"] if gem_packages["#{gem_file}"]
|
|
222
|
+
|
|
223
|
+
download_package(gem_name, version)
|
|
224
|
+
end
|
|
225
|
+
|
|
226
|
+
def download_package(gem_name, version)
|
|
227
|
+
spec, source = get_specification(gem_name, version)
|
|
228
|
+
|
|
229
|
+
gem_file_path = Dir.chdir @options[:output] do
|
|
230
|
+
source.download spec
|
|
231
|
+
end
|
|
232
|
+
|
|
233
|
+
package = Gem::Package.new(gem_file_path)
|
|
234
|
+
use_package(package)
|
|
235
|
+
info "#{gem_file_path} downloaded."
|
|
236
|
+
|
|
237
|
+
package
|
|
238
|
+
end
|
|
239
|
+
|
|
240
|
+
def get_specification(gem_name, version)
|
|
241
|
+
gem_file = gem_file_name(gem_name, version)
|
|
242
|
+
return gem_specs["#{gem_file}"] if gem_specs["#{gem_file}"]
|
|
243
|
+
|
|
244
|
+
find_downloaded_gem(gem_file)
|
|
245
|
+
return gem_specs["#{gem_file}"] if gem_specs["#{gem_file}"]
|
|
246
|
+
|
|
247
|
+
download_specification(gem_name, version)
|
|
248
|
+
end
|
|
249
|
+
|
|
250
|
+
def download_specification(gem_name, version)
|
|
251
|
+
dep = Gem::Dependency.new gem_name, version
|
|
252
|
+
specs_and_sources, _errors = Gem::SpecFetcher.fetcher.spec_for_dependency dep
|
|
253
|
+
spec, source = specs_and_sources.max_by { |s,| s.version }
|
|
254
|
+
error "Gem #{gem_name} in #{version} doesn't exist." if spec.nil?
|
|
255
|
+
|
|
256
|
+
fix_comparing_version(version, spec.version.to_s)
|
|
257
|
+
gem_file = gem_file_name(gem_name, spec.version.to_s)
|
|
258
|
+
|
|
259
|
+
gem_specs["#{gem_file}"] = spec
|
|
260
|
+
|
|
261
|
+
[spec, source]
|
|
262
|
+
end
|
|
263
|
+
|
|
264
|
+
##
|
|
265
|
+
# Ensure the right version is referenced
|
|
266
|
+
|
|
267
|
+
def fix_comparing_version(version, spec_version)
|
|
268
|
+
if spec_version != version
|
|
269
|
+
@compared_versions.each do |v|
|
|
270
|
+
if v == version
|
|
271
|
+
@compared_versions[@compared_versions.index(version)] = spec_version
|
|
272
|
+
return
|
|
273
|
+
end
|
|
274
|
+
end
|
|
275
|
+
end
|
|
276
|
+
end
|
|
277
|
+
|
|
278
|
+
def find_downloaded_gem(gem_file)
|
|
279
|
+
if File.exist? File.join(@options[:output], gem_file)
|
|
280
|
+
info "#{gem_file} exists, using already downloaded file."
|
|
281
|
+
package = Gem::Package.new File.join(@options[:output], gem_file)
|
|
282
|
+
use_package(package)
|
|
283
|
+
[package, package.spec]
|
|
284
|
+
else
|
|
285
|
+
[nil, nil]
|
|
286
|
+
end
|
|
287
|
+
end
|
|
288
|
+
|
|
289
|
+
def use_package(package)
|
|
290
|
+
gem_file = gem_file_name(package.spec.name, package.spec.version)
|
|
291
|
+
gem_packages["#{gem_file}"] = package
|
|
292
|
+
gem_specs["#{gem_file}"] = package.spec
|
|
293
|
+
end
|
|
294
|
+
|
|
295
|
+
def download_gems?
|
|
296
|
+
return true if @options[:keep_all]
|
|
297
|
+
@options[:param] ? !param_available_in_marshal?(@options[:param]) : true
|
|
298
|
+
end
|
|
299
|
+
|
|
300
|
+
def gem_packages
|
|
301
|
+
@gem_packages ||= {}
|
|
302
|
+
end
|
|
303
|
+
|
|
304
|
+
def gem_specs
|
|
305
|
+
@gem_specs ||= {}
|
|
306
|
+
end
|
|
307
|
+
|
|
308
|
+
end
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
Copyright (c) 2014 Josef Stribny
|
|
2
|
+
|
|
3
|
+
MIT License
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
|
6
|
+
a copy of this software and associated documentation files (the
|
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
|
11
|
+
the following conditions:
|
|
12
|
+
|
|
13
|
+
The above copyright notice and this permission notice shall be
|
|
14
|
+
included in all copies or substantial portions of the Software.
|
|
15
|
+
|
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
# Lorem
|
|
2
|
+
|
|
3
|
+
TODO: Write a gem description
|
|
4
|
+
|
|
5
|
+
## Installation
|
|
6
|
+
|
|
7
|
+
Add this line to your application's Gemfile:
|
|
8
|
+
|
|
9
|
+
gem 'lorem'
|
|
10
|
+
|
|
11
|
+
And then execute:
|
|
12
|
+
|
|
13
|
+
$ bundle
|
|
14
|
+
|
|
15
|
+
Or install it yourself as:
|
|
16
|
+
|
|
17
|
+
$ gem install lorem
|
|
18
|
+
|
|
19
|
+
## Usage
|
|
20
|
+
|
|
21
|
+
TODO: Write usage instructions here
|
|
22
|
+
|
|
23
|
+
## Contributing
|
|
24
|
+
|
|
25
|
+
1. Fork it ( https://github.com/[my-github-username]/lorem/fork )
|
|
26
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
|
27
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
|
28
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
|
29
|
+
5. Create a new Pull Request
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
# coding: utf-8
|
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
|
4
|
+
require 'lorem/version'
|
|
5
|
+
|
|
6
|
+
Gem::Specification.new do |spec|
|
|
7
|
+
spec.name = "lorem"
|
|
8
|
+
spec.version = Lorem::VERSION
|
|
9
|
+
spec.authors = ["Josef Stribny"]
|
|
10
|
+
spec.email = ["jstribny@redhat.com"]
|
|
11
|
+
spec.summary = "lorem is a gem for testing skillnad"
|
|
12
|
+
spec.description = "lorem changes a lot so we can test skillnad a lot"
|
|
13
|
+
spec.homepage = ""
|
|
14
|
+
spec.license = "MIT"
|
|
15
|
+
|
|
16
|
+
spec.files = ["lorem.gemspec", "Gemfile", "Rakefile", "LICENSE.txt", "README.md"] +
|
|
17
|
+
Dir.glob("lib/**/*")
|
|
18
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
|
19
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
|
20
|
+
spec.require_paths = ["lib"]
|
|
21
|
+
|
|
22
|
+
spec.add_development_dependency "bundler", "~> 1.6"
|
|
23
|
+
spec.add_development_dependency "rake"
|
|
24
|
+
end
|
|
Binary file
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
# Lorem
|
|
2
|
+
|
|
3
|
+
TODO: Write a gem description
|
|
4
|
+
|
|
5
|
+
## Installation
|
|
6
|
+
|
|
7
|
+
Add this line to your application's Gemfile:
|
|
8
|
+
|
|
9
|
+
gem 'lorem'
|
|
10
|
+
|
|
11
|
+
And then execute:
|
|
12
|
+
|
|
13
|
+
$ bundle
|
|
14
|
+
|
|
15
|
+
Or install it yourself as:
|
|
16
|
+
|
|
17
|
+
$ gem install lorem
|
|
18
|
+
|
|
19
|
+
## Usage
|
|
20
|
+
|
|
21
|
+
TODO: Write usage instructions here
|
|
22
|
+
|
|
23
|
+
## Contributing
|
|
24
|
+
|
|
25
|
+
1. Fork it ( https://github.com/[my-github-username]/lorem/fork )
|
|
26
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
|
27
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
|
28
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
|
29
|
+
5. Create a new Pull Request
|