polisher 0.10.2 → 0.11.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/bin/binary_gem_resolver.rb +2 -2
- data/bin/bundler2yum.rb +51 -0
- data/bin/check_ruby_spec.rb +32 -0
- data/bin/gem_dependency_checker.rb +13 -242
- data/bin/gem_mapper.rb +27 -0
- data/bin/gems2update.rb +27 -0
- data/bin/git_gem_diff.rb +48 -0
- data/bin/git_gem_updater.rb +3 -3
- data/bin/missing_deps.rb +29 -0
- data/bin/polisher-config.rb +17 -0
- data/bin/ruby_rpm_spec_updater.rb +23 -2
- data/lib/polisher.rb +5 -12
- data/lib/polisher/adaptors/checker_loader.rb +78 -0
- data/lib/polisher/{upstream.rb → adaptors/upstream.rb} +1 -0
- data/lib/polisher/adaptors/version_checker.rb +57 -0
- data/lib/polisher/adaptors/version_checker/bodhi.rb +29 -0
- data/lib/polisher/adaptors/version_checker/errata.rb +29 -0
- data/lib/polisher/adaptors/version_checker/fedora.rb +29 -0
- data/lib/polisher/adaptors/version_checker/gem.rb +27 -0
- data/lib/polisher/adaptors/version_checker/git.rb +29 -0
- data/lib/polisher/adaptors/version_checker/koji.rb +29 -0
- data/lib/polisher/adaptors/version_checker/yum.rb +29 -0
- data/lib/polisher/cli/all.rb +22 -0
- data/lib/polisher/cli/bin/gem_dependency_checker.rb +85 -0
- data/lib/polisher/cli/bin/gem_mapper.rb +37 -0
- data/lib/polisher/cli/bin/gems2update.rb +86 -0
- data/lib/polisher/cli/bin/missing_deps.rb +35 -0
- data/lib/polisher/cli/conf.rb +18 -0
- data/lib/polisher/cli/default.rb +25 -0
- data/lib/polisher/cli/format.rb +130 -0
- data/lib/polisher/cli/sources.rb +106 -0
- data/lib/polisher/cli/specifier.rb +30 -0
- data/lib/polisher/cli/status.rb +50 -0
- data/lib/polisher/cli/targets.rb +88 -0
- data/lib/polisher/gem.rb +41 -338
- data/lib/polisher/gem/attributes.rb +20 -0
- data/lib/polisher/gem/dependencies.rb +63 -0
- data/lib/polisher/gem/diff.rb +39 -0
- data/lib/polisher/gem/files.rb +111 -0
- data/lib/polisher/gem/parser.rb +85 -0
- data/lib/polisher/gem/retriever.rb +137 -0
- data/lib/polisher/{gem_state.rb → gem/state.rb} +6 -6
- data/lib/polisher/gem/versions.rb +131 -0
- data/lib/polisher/gemfile.rb +20 -89
- data/lib/polisher/gemfile/attributes.rb +19 -0
- data/lib/polisher/gemfile/deps.rb +43 -0
- data/lib/polisher/gemfile/parser.rb +45 -0
- data/lib/polisher/git/pkg.rb +33 -238
- data/lib/polisher/git/pkg/attributes.rb +60 -0
- data/lib/polisher/git/pkg/builder.rb +47 -0
- data/lib/polisher/git/pkg/repo.rb +82 -0
- data/lib/polisher/git/pkg/updater.rb +53 -0
- data/lib/polisher/git/pkg/versions.rb +40 -0
- data/lib/polisher/git/project.rb +1 -1
- data/lib/polisher/git/repo.rb +79 -76
- data/lib/polisher/{vendor.rb → mixins/vendored_deps.rb} +4 -7
- data/lib/polisher/mixins/versioned_dependencies.rb +86 -0
- data/lib/polisher/record.rb +2 -0
- data/lib/polisher/rpm.rb +23 -0
- data/lib/polisher/rpm/patch.rb +10 -8
- data/lib/polisher/rpm/requirement.rb +33 -189
- data/lib/polisher/rpm/requirement/attributes.rb +43 -0
- data/lib/polisher/rpm/requirement/comparison.rb +97 -0
- data/lib/polisher/rpm/requirement/gem_reference.rb +46 -0
- data/lib/polisher/rpm/requirement/parser.rb +41 -0
- data/lib/polisher/rpm/spec.rb +97 -436
- data/lib/polisher/rpm/spec/check.rb +14 -0
- data/lib/polisher/rpm/spec/comparison.rb +64 -0
- data/lib/polisher/rpm/spec/files.rb +15 -0
- data/lib/polisher/rpm/spec/gem_files.rb +65 -0
- data/lib/polisher/rpm/spec/gem_reference.rb +59 -0
- data/lib/polisher/rpm/spec/gem_requirements.rb +73 -0
- data/lib/polisher/rpm/spec/parser.rb +106 -0
- data/lib/polisher/rpm/spec/requirements.rb +31 -0
- data/lib/polisher/rpm/spec/subpackages.rb +23 -0
- data/lib/polisher/rpm/spec/updater.rb +268 -0
- data/lib/polisher/specifier.rb +13 -0
- data/lib/polisher/targets.rb +36 -0
- data/lib/polisher/{apt.rb → targets/apt.rb} +1 -1
- data/lib/polisher/targets/bodhi.rb +43 -0
- data/lib/polisher/{bugzilla.rb → targets/bugzilla.rb} +1 -1
- data/lib/polisher/targets/errata.rb +55 -0
- data/lib/polisher/targets/errata/build.rb +24 -0
- data/lib/polisher/targets/fedora.rb +47 -0
- data/lib/polisher/targets/koji.rb +39 -0
- data/lib/polisher/targets/koji/builder.rb +38 -0
- data/lib/polisher/targets/koji/diff.rb +39 -0
- data/lib/polisher/targets/koji/rpc.rb +43 -0
- data/lib/polisher/targets/koji/versions.rb +67 -0
- data/lib/polisher/targets/rhn.rb +12 -0
- data/lib/polisher/targets/yum.rb +36 -0
- data/lib/polisher/{component.rb → util/component.rb} +3 -3
- data/lib/polisher/util/conf_helpers.rb +77 -0
- data/lib/polisher/util/config.rb +45 -0
- data/lib/polisher/util/core_ext.rb +59 -0
- data/lib/polisher/{error.rb → util/error.rb} +0 -0
- data/lib/polisher/{gem_cache.rb → util/gem_cache.rb} +1 -1
- data/lib/polisher/{git_cache.rb → util/git_cache.rb} +0 -0
- data/lib/polisher/{logger.rb → util/logger.rb} +2 -0
- data/lib/polisher/{tag_mapper.rb → util/tag_mapper.rb} +1 -1
- data/lib/polisher/version.rb +1 -1
- data/spec/{upstream_spec.rb → adaptors/upstream_spec.rb} +1 -1
- data/spec/{version_checker_spec.rb → adaptors/version_checker_spec.rb} +1 -6
- data/spec/data/activesupport-4.1.4.gem +0 -0
- data/spec/data/rubygem-activesupport-with-doc.spec +247 -0
- data/spec/data/rubygem-activesupport-without-requires.spec +232 -0
- data/spec/data/rubygem-activesupport.spec +0 -122
- data/spec/fixtures/gem_json.rb +49 -0
- data/spec/fixtures/gem_spec.rb +13 -0
- data/spec/fixtures/gemfile.rb +10 -0
- data/spec/fixtures/local_gem.rb +62 -0
- data/spec/fixtures/rpm_spec.rb +91 -0
- data/spec/gem/attributes_spec.rb +17 -0
- data/spec/gem/diff_spec.rb +80 -0
- data/spec/gem/files_spec.rb +171 -0
- data/spec/gem/parser_spec.rb +44 -0
- data/spec/gem/retriever_spec.rb +124 -0
- data/spec/gem/state_spec.rb +79 -0
- data/spec/gem/versions_spec.rb +148 -0
- data/spec/gem_spec.rb +5 -347
- data/spec/gemfile/deps_spec.rb +20 -0
- data/spec/gemfile/parser_spec.rb +26 -0
- data/spec/gemfile_spec.rb +0 -34
- data/spec/git/pkg/attributes_spec.rb +128 -0
- data/spec/git/pkg/builder_spec.rb +63 -0
- data/spec/git/pkg/repo_spec.rb +146 -0
- data/spec/git/pkg/updater_spec.rb +86 -0
- data/spec/git/pkg/versions_spec.rb +42 -0
- data/spec/git/pkg_spec.rb +21 -0
- data/spec/git/project_spec.rb +21 -0
- data/spec/git/repo_spec.rb +160 -0
- data/spec/{vendor_spec.rb → mixins/vendored_deps_spec.rb} +2 -4
- data/spec/mixins/versioned_dependencies_spec.rb +48 -0
- data/spec/rpm/patch_spec.rb +48 -0
- data/spec/rpm/requirement/attributes_spec.rb +34 -0
- data/spec/rpm/requirement/comparison_spec.rb +286 -0
- data/spec/rpm/requirement/gem_spec.rb +49 -0
- data/spec/rpm/requirement/parser_spec.rb +31 -0
- data/spec/rpm/requirement_spec.rb +8 -334
- data/spec/rpm/spec/check_spec.rb +25 -0
- data/spec/rpm/spec/comparison_spec.rb +55 -0
- data/spec/rpm/spec/files_spec.rb +17 -0
- data/spec/rpm/spec/gem_files_spec.rb +112 -0
- data/spec/rpm/spec/gem_reference_spec.rb +99 -0
- data/spec/rpm/spec/gem_requirement_spec.rb +38 -0
- data/spec/rpm/spec/parser_spec.rb +64 -0
- data/spec/rpm/spec/requirements_spec.rb +10 -0
- data/spec/rpm/spec/subpackages_spec.rb +38 -0
- data/spec/rpm/spec/updater_spec.rb +486 -0
- data/spec/rpm/spec_spec.rb +27 -174
- data/spec/spec_helper.rb +7 -107
- data/spec/support/coveralls.rb +10 -0
- data/spec/support/fixtures.rb +8 -0
- data/spec/support/paths.rb +20 -0
- data/spec/support/rspec.rb +20 -0
- data/spec/support/vcr.rb +11 -0
- data/spec/{bodhi_spec.rb → targets/bodhi_spec.rb} +3 -1
- data/spec/{errata_spec.rb → targets/errata_spec.rb} +2 -2
- data/spec/{fedora_spec.rb → targets/fedora_spec.rb} +3 -3
- data/spec/targets/koji/builder_spec.rb +48 -0
- data/spec/targets/koji/diff_spec.rb +36 -0
- data/spec/targets/koji/rpc_spec.rb +28 -0
- data/spec/{koji_spec.rb → targets/koji/versions_spec.rb} +1 -59
- data/spec/targets/koji_spec.rb +11 -0
- data/spec/{yum_spec.rb → targets/yum_spec.rb} +1 -1
- data/spec/{component_spec.rb → util/component_spec.rb} +1 -1
- data/spec/{core_spec.rb → util/core_ext_spec.rb} +2 -3
- metadata +278 -88
- data/lib/polisher/bodhi.rb +0 -23
- data/lib/polisher/config.rb +0 -32
- data/lib/polisher/core.rb +0 -101
- data/lib/polisher/errata.rb +0 -75
- data/lib/polisher/fedora.rb +0 -46
- data/lib/polisher/git.rb +0 -8
- data/lib/polisher/koji.rb +0 -159
- data/lib/polisher/rhn.rb +0 -15
- data/lib/polisher/version_checker.rb +0 -177
- data/lib/polisher/yum.rb +0 -37
- data/spec/git_spec.rb +0 -445
@@ -0,0 +1,106 @@
|
|
1
|
+
#!/usr/bin/ruby
|
2
|
+
# Polisher CLI Gem Sources Options
|
3
|
+
#
|
4
|
+
# Licensed under the MIT license
|
5
|
+
# Copyright (C) 2015 Red Hat, Inc.
|
6
|
+
###########################################################
|
7
|
+
|
8
|
+
require 'polisher/gem'
|
9
|
+
require 'polisher/gemfile'
|
10
|
+
|
11
|
+
module Polisher
|
12
|
+
module CLI
|
13
|
+
def sources_conf
|
14
|
+
{ :gemfile => './Gemfile',
|
15
|
+
:gemspec => nil,
|
16
|
+
:gemname => nil,
|
17
|
+
:gemversion => nil,
|
18
|
+
:groups => [],
|
19
|
+
:devel_deps => false }
|
20
|
+
end
|
21
|
+
|
22
|
+
def sources_options(option_parser)
|
23
|
+
option_parser.on('--gemfile file', 'Location of the gemfile to parse') do |g|
|
24
|
+
conf[:gemfile] = g
|
25
|
+
end
|
26
|
+
|
27
|
+
option_parser.on('--group gemfile_groups', 'Gemfile groups (may be specified multiple times)') do |g|
|
28
|
+
conf[:groups] << g
|
29
|
+
end
|
30
|
+
|
31
|
+
option_parser.on('--gemspec file', 'Location of the gemspec to parse') do |g|
|
32
|
+
conf[:gemspec] = g
|
33
|
+
end
|
34
|
+
|
35
|
+
option_parser.on('--gem name', 'Name of the rubygem to check') do |g|
|
36
|
+
conf[:gemname] = g
|
37
|
+
end
|
38
|
+
|
39
|
+
option_parser.on('-v', '--version [version]', 'Version of gem to check') do |v|
|
40
|
+
conf[:gemversion] = v
|
41
|
+
end
|
42
|
+
|
43
|
+
option_parser.on('--[no-]devel', 'Include development dependencies') do |d|
|
44
|
+
conf[:devel_deps] = d
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
def validate_sources
|
49
|
+
if conf[:gemfile].nil? &&
|
50
|
+
conf[:gemspec].nil? &&
|
51
|
+
conf[:gemname].nil?
|
52
|
+
|
53
|
+
if File.exists?('./Gemfile')
|
54
|
+
conf[:gemfile] = './Gemfile'
|
55
|
+
else
|
56
|
+
puts "Valid Gemfile, GemSpec, or Gem must be specified".bold.red
|
57
|
+
exit 1
|
58
|
+
end
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
62
|
+
def conf_gem?
|
63
|
+
conf[:gemname] || conf[:gemspec]
|
64
|
+
end
|
65
|
+
|
66
|
+
def conf_gemfile?
|
67
|
+
!conf[:gemfile].nil?
|
68
|
+
end
|
69
|
+
|
70
|
+
def conf_source
|
71
|
+
if conf[:gemname]
|
72
|
+
name = conf[:gemname]
|
73
|
+
if conf[:gemversion]
|
74
|
+
version = conf[:gemversion]
|
75
|
+
Polisher::Gem.from_rubygems(name, version)
|
76
|
+
|
77
|
+
elsif !RELATIVE_SPECIFIERS.include?(conf[:matching])
|
78
|
+
target = conf[:matching]
|
79
|
+
begin
|
80
|
+
Polisher::Gem.latest_in_target(name, target)
|
81
|
+
rescue
|
82
|
+
Polisher::Gem.retrieve(name)
|
83
|
+
end
|
84
|
+
|
85
|
+
else
|
86
|
+
Polisher::Gem.retrieve(name)
|
87
|
+
end
|
88
|
+
|
89
|
+
elsif conf[:gemspec]
|
90
|
+
Polisher::Gem.from_gemspec(conf[:gemspec])
|
91
|
+
|
92
|
+
elsif conf[:gemfile]
|
93
|
+
gemfile = nil
|
94
|
+
|
95
|
+
begin
|
96
|
+
gemfile = Polisher::Gemfile.parse(conf[:gemfile], :groups => conf[:groups])
|
97
|
+
rescue => e
|
98
|
+
puts "Runtime err #{e}".red
|
99
|
+
exit 1
|
100
|
+
end
|
101
|
+
|
102
|
+
gemfile
|
103
|
+
end
|
104
|
+
end
|
105
|
+
end # module CLI
|
106
|
+
end # module Polisher
|
@@ -0,0 +1,30 @@
|
|
1
|
+
#!/usr/bin/ruby
|
2
|
+
# Polisher CLI Gem Specifier Options
|
3
|
+
#
|
4
|
+
# Licensed under the MIT license
|
5
|
+
# Copyright (C) 2015 Red Hat, Inc.
|
6
|
+
###########################################################
|
7
|
+
|
8
|
+
require 'polisher/specifier'
|
9
|
+
|
10
|
+
module Polisher
|
11
|
+
module CLI
|
12
|
+
def specifier_conf
|
13
|
+
{ :matching => LATEST_SPECIFIER }
|
14
|
+
end
|
15
|
+
|
16
|
+
def specifier_opts(option_parser)
|
17
|
+
option_parser.on('--latest', 'Check latest matching version of gem') do
|
18
|
+
conf[:matching] = LATEST_SPECIFIER
|
19
|
+
end
|
20
|
+
|
21
|
+
option_parser.on('--earliest', 'Check earliest matching version of gem') do
|
22
|
+
conf[:matching] = EARLIEST_SPECIFIER
|
23
|
+
end
|
24
|
+
|
25
|
+
option_parser.on('--target [tgt]', 'Check version of gem in target') do |t|
|
26
|
+
conf[:matching] = t
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end # module CLI
|
30
|
+
end # module Polisher
|
@@ -0,0 +1,50 @@
|
|
1
|
+
#!/usr/bin/ruby
|
2
|
+
# Polisher CLI Status Utils
|
3
|
+
#
|
4
|
+
# Licensed under the MIT license
|
5
|
+
# Copyright (C) 2015 Red Hat, Inc.
|
6
|
+
###########################################################
|
7
|
+
|
8
|
+
module Polisher
|
9
|
+
module CLI
|
10
|
+
def clear
|
11
|
+
puts `clear`
|
12
|
+
end
|
13
|
+
|
14
|
+
def num_elipses
|
15
|
+
conf[:num_elipses] ||= 5
|
16
|
+
end
|
17
|
+
|
18
|
+
def elipses_delay
|
19
|
+
conf[:elipses_delay] ||= 1
|
20
|
+
end
|
21
|
+
|
22
|
+
def waiting_msg(msg)
|
23
|
+
conf[:wait_msg] = msg
|
24
|
+
end
|
25
|
+
|
26
|
+
def waiting(args={})
|
27
|
+
waiting_msg(args[:msg]) if args.key?(:msg)
|
28
|
+
color = args[:color] || :black
|
29
|
+
|
30
|
+
@term_waiting = false
|
31
|
+
@waiting_thread = Thread.new(conf) { |conf|
|
32
|
+
until @term_waiting
|
33
|
+
clear
|
34
|
+
print conf[:wait_msg].send(color) if conf.key?(:wait_msg)
|
35
|
+
0.upto(num_elipses) {
|
36
|
+
print '.'.send(color)
|
37
|
+
sleep elipses_delay
|
38
|
+
}
|
39
|
+
puts
|
40
|
+
end
|
41
|
+
}
|
42
|
+
end
|
43
|
+
|
44
|
+
def end_waiting
|
45
|
+
return unless @waiting_thread
|
46
|
+
@term_waiting = true
|
47
|
+
@waiting_thread.join
|
48
|
+
end
|
49
|
+
end # module CLI
|
50
|
+
end # module Polisher
|
@@ -0,0 +1,88 @@
|
|
1
|
+
#!/usr/bin/ruby
|
2
|
+
# Polisher CLI Target Options
|
3
|
+
#
|
4
|
+
# Licensed under the MIT license
|
5
|
+
# Copyright (C) 2015 Red Hat, Inc.
|
6
|
+
###########################################################
|
7
|
+
|
8
|
+
module Polisher
|
9
|
+
module CLI
|
10
|
+
def targets_conf
|
11
|
+
{ :check_fedora => false,
|
12
|
+
:check_git => false,
|
13
|
+
:check_koji => false,
|
14
|
+
:check_rhn => false,
|
15
|
+
:check_yum => false,
|
16
|
+
:check_bugzilla => false,
|
17
|
+
:check_errata => false,
|
18
|
+
:check_bodhi => false,
|
19
|
+
:prefix => nil }
|
20
|
+
end
|
21
|
+
|
22
|
+
def targets_options(option_parser)
|
23
|
+
option_parser.on('-p', '--prefix prefix', 'Prefix to append to gem name') do |p|
|
24
|
+
conf[:prefix] = p
|
25
|
+
end
|
26
|
+
|
27
|
+
option_parser.on('-f', '--[no-]fedora', 'Check fedora for packages') do |f|
|
28
|
+
conf[:check_fedora] = f
|
29
|
+
end
|
30
|
+
|
31
|
+
option_parser.on('-g', '--git [url]', 'Check git for packages') do |g|
|
32
|
+
conf[:check_git] = g || "git://pkgs.fedoraproject.org/"
|
33
|
+
end
|
34
|
+
|
35
|
+
option_parser.on('-k', '--koji [url]', 'Check koji for packages') do |k|
|
36
|
+
conf[:check_koji] = k || true
|
37
|
+
end
|
38
|
+
|
39
|
+
option_parser.on('-t', '--koji-tag tag', 'Koji tag to query') do |t|
|
40
|
+
conf[:koji_tag] = t
|
41
|
+
end
|
42
|
+
|
43
|
+
option_parser.on('-b', '--bodhi [url]', 'Check Bodhi for packages') do |r|
|
44
|
+
conf[:check_bodhi] = r || 'https://admin.fedoraproject.org/updates/'
|
45
|
+
end
|
46
|
+
|
47
|
+
option_parser.on('--rhn [url]', 'Check RHN for packages') do |r|
|
48
|
+
conf[:check_rhn] = r || 'TODO'
|
49
|
+
end
|
50
|
+
|
51
|
+
option_parser.on('-y', '--yum', 'Check yum for packages') do |y|
|
52
|
+
conf[:check_yum] = y
|
53
|
+
end
|
54
|
+
|
55
|
+
option_parser.on('-b', '--bugzilla', 'Check bugzilla for bugs filed against package') do |b|
|
56
|
+
conf[:check_bugzilla] = b
|
57
|
+
end
|
58
|
+
|
59
|
+
option_parser.on('-e', '--errata [url]', 'Check packages filed in errata') do |e|
|
60
|
+
conf[:check_errata] = e || nil
|
61
|
+
end
|
62
|
+
end
|
63
|
+
|
64
|
+
def set_targets(conf)
|
65
|
+
targets = []
|
66
|
+
require 'polisher/adaptors/version_checker'
|
67
|
+
targets << :gem if conf[:check_gem]
|
68
|
+
targets << :koji if conf[:check_koji]
|
69
|
+
targets << :fedora if conf[:check_fedora]
|
70
|
+
targets << :git if conf[:check_git]
|
71
|
+
targets << :yum if conf[:check_yum]
|
72
|
+
targets << :bodhi if conf[:check_bodhi]
|
73
|
+
targets = Polisher::VersionChecker.targets if targets.empty?
|
74
|
+
Polisher::VersionChecker.check targets
|
75
|
+
end
|
76
|
+
|
77
|
+
def configure_targets(conf)
|
78
|
+
if conf[:check_koji]
|
79
|
+
require 'polisher/targets/koji'
|
80
|
+
Polisher::Koji.koji_url conf[:check_koji] if conf[:check_koji].is_a?(String)
|
81
|
+
Polisher::Koji.koji_tag conf[:koji_tag] if conf[:koji_tag]
|
82
|
+
Polisher::Koji.package_prefix conf[:prefix] if conf[:prefix]
|
83
|
+
end
|
84
|
+
|
85
|
+
# TODO other target config
|
86
|
+
end
|
87
|
+
end # module CLI
|
88
|
+
end # module Polisher
|
data/lib/polisher/gem.rb
CHANGED
@@ -3,345 +3,48 @@
|
|
3
3
|
# Licensed under the MIT license
|
4
4
|
# Copyright (C) 2013-2014 Red Hat, Inc.
|
5
5
|
|
6
|
-
require 'polisher/
|
7
|
-
require 'polisher/
|
8
|
-
require 'polisher/component'
|
9
|
-
require 'polisher/gem_cache'
|
10
|
-
require 'polisher/version_checker'
|
11
|
-
require 'polisher/gem_state'
|
6
|
+
require 'polisher/util/conf_helpers'
|
7
|
+
require 'polisher/mixins/vendored_deps'
|
12
8
|
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
include ConfHelpers
|
19
|
-
include HasState
|
20
|
-
include HasVendoredDeps
|
21
|
-
|
22
|
-
conf_attr :diff_cmd, '/usr/bin/diff'
|
23
|
-
|
24
|
-
# Common files shipped in gems that we should ignore
|
25
|
-
IGNORE_FILES = ['.gemtest', '.gitignore', '.travis.yml',
|
26
|
-
/.*.gemspec/, /Gemfile.*/, 'Rakefile',
|
27
|
-
/rspec.*/, '.yardopts', '.rvmrc']
|
28
|
-
|
29
|
-
# Common files shipped in gems that we should mark as doc
|
30
|
-
DOC_FILES = [/\/?CHANGELOG.*/, /\/?CONTRIBUTING.*/, /\/?README.*/, /\/?.*LICENSE/]
|
31
|
-
|
32
|
-
attr_accessor :spec
|
33
|
-
attr_accessor :name
|
34
|
-
attr_accessor :version
|
35
|
-
attr_accessor :deps
|
36
|
-
attr_accessor :dev_deps
|
37
|
-
|
38
|
-
attr_accessor :path
|
39
|
-
|
40
|
-
def file_name
|
41
|
-
"#{name}-#{version}.gem"
|
42
|
-
end
|
43
|
-
|
44
|
-
def initialize(args = {})
|
45
|
-
@spec = args[:spec]
|
46
|
-
@name = args[:name]
|
47
|
-
@version = args[:version]
|
48
|
-
@path = args[:path]
|
49
|
-
@deps = args[:deps] || []
|
50
|
-
@dev_deps = args[:dev_deps] || []
|
51
|
-
end
|
52
|
-
|
53
|
-
# Return bool indicating if the specified file is on the IGNORE_FILES list
|
54
|
-
def self.ignorable_file?(file)
|
55
|
-
IGNORE_FILES.any? do |ignore|
|
56
|
-
ignore.is_a?(Regexp) ? ignore.match(file) : ignore == file
|
57
|
-
end
|
58
|
-
end
|
59
|
-
|
60
|
-
# Return bool indicating if the specified file is on the DOC_FILES list
|
61
|
-
def self.doc_file?(file)
|
62
|
-
DOC_FILES.any? do |doc|
|
63
|
-
doc.is_a?(Regexp) ? doc.match(file) : doc == file
|
64
|
-
end
|
65
|
-
end
|
66
|
-
|
67
|
-
# Retrieve list of the versions of the specified gem installed locally
|
68
|
-
#
|
69
|
-
# @param [String] name name of the gem to lookup
|
70
|
-
# @param [Callable] bl optional block to invoke with versions retrieved
|
71
|
-
# @return [Array<String>] list of versions of gem installed locally
|
72
|
-
def self.local_versions_for(name, &bl)
|
73
|
-
silence_warnings do
|
74
|
-
@local_db ||= ::Gem::Specification.all
|
75
|
-
end
|
76
|
-
versions = @local_db.select { |s| s.name == name }.collect { |s| s.version }
|
77
|
-
bl.call(:local_gem, name, versions) unless(bl.nil?)
|
78
|
-
versions
|
79
|
-
end
|
80
|
-
|
81
|
-
# Return new instance of Gem from JSON Specification
|
82
|
-
def self.from_json(json)
|
83
|
-
specj = JSON.parse(json)
|
84
|
-
metadata = {}
|
85
|
-
metadata[:spec] = specj
|
86
|
-
metadata[:name] = specj['name']
|
87
|
-
metadata[:version] = specj['version']
|
88
|
-
|
89
|
-
metadata[:deps] =
|
90
|
-
specj['dependencies']['runtime'].collect do |d|
|
91
|
-
::Gem::Dependency.new d['name'], *d['requirements'].split(',')
|
92
|
-
end
|
93
|
-
|
94
|
-
metadata[:dev_deps] =
|
95
|
-
specj['dependencies']['development'].collect do |d|
|
96
|
-
::Gem::Dependency.new d['name'], d['requirements'].split(',')
|
97
|
-
end
|
98
|
-
|
99
|
-
new metadata
|
100
|
-
end
|
101
|
-
|
102
|
-
# Retrieve all versions of gem available on rubygems
|
103
|
-
def self.remote_versions_for(name)
|
104
|
-
client.url = "https://rubygems.org/api/v1/versions/#{name}.json"
|
105
|
-
client.follow_location = true
|
106
|
-
client.http_get
|
107
|
-
json = JSON.parse(client.body_str)
|
108
|
-
json.collect { |version| version['number'] }
|
109
|
-
end
|
110
|
-
|
111
|
-
# Retieve latest version of gem available on rubygems
|
112
|
-
def self.latest_version_of(name)
|
113
|
-
remote_versions_for(name).first
|
114
|
-
end
|
115
|
-
|
116
|
-
# Return new instance of Gem from Gemspec
|
117
|
-
def self.from_gemspec(gemspec)
|
118
|
-
gemspec =
|
119
|
-
::Gem::Specification.load(gemspec) if !gemspec.is_a?(::Gem::Specification) &&
|
120
|
-
File.exist?(gemspec)
|
121
|
-
|
122
|
-
metadata = {}
|
123
|
-
metadata[:spec] = gemspec
|
124
|
-
metadata[:name] = gemspec.name
|
125
|
-
metadata[:version] = gemspec.version.to_s
|
126
|
-
|
127
|
-
metadata[:deps] =
|
128
|
-
gemspec.dependencies.select { |dep|
|
129
|
-
dep.type == :runtime
|
130
|
-
}.collect { |dep| dep }
|
131
|
-
|
132
|
-
metadata[:dev_deps] =
|
133
|
-
gemspec.dependencies.select { |dep|
|
134
|
-
dep.type == :development
|
135
|
-
}.collect { |dep| dep }
|
136
|
-
|
137
|
-
new metadata
|
138
|
-
end
|
139
|
-
|
140
|
-
# Return new instance of Gem from rubygem
|
141
|
-
def self.from_gem(gem_path)
|
142
|
-
gem = parse :gemspec => ::Gem::Package.new(gem_path).spec
|
143
|
-
gem.path = gem_path
|
144
|
-
gem
|
145
|
-
end
|
146
|
-
|
147
|
-
# Parse the specified gemspec & return new Gem instance from metadata
|
148
|
-
#
|
149
|
-
# @param [String,Hash] args contents of actual gemspec of option hash
|
150
|
-
# specifying location of gemspec to parse
|
151
|
-
# @option args [String] :gemspec path to gemspec to load / parse
|
152
|
-
# @return [Polisher::Gem] gem instantiated from gemspec metadata
|
153
|
-
def self.parse(args={})
|
154
|
-
if args.is_a?(String)
|
155
|
-
return from_json args
|
156
|
-
|
157
|
-
elsif args.key?(:gemspec)
|
158
|
-
return from_gemspec args[:gemspec]
|
159
|
-
|
160
|
-
elsif args.key?(:gem)
|
161
|
-
return from_gem args[:gem]
|
162
|
-
|
163
|
-
end
|
9
|
+
require 'polisher/gem/attributes'
|
10
|
+
require 'polisher/gem/dependencies'
|
11
|
+
require 'polisher/gem/files'
|
12
|
+
require 'polisher/gem/state'
|
13
|
+
require 'polisher/gem/versions'
|
164
14
|
|
165
|
-
|
166
|
-
|
15
|
+
require 'polisher/gem/parser'
|
16
|
+
require 'polisher/gem/retriever'
|
17
|
+
require 'polisher/gem/diff'
|
167
18
|
|
168
|
-
|
169
|
-
|
170
|
-
|
171
|
-
|
172
|
-
|
173
|
-
|
174
|
-
|
175
|
-
|
176
|
-
|
177
|
-
|
178
|
-
|
179
|
-
|
180
|
-
|
181
|
-
|
182
|
-
|
183
|
-
|
184
|
-
|
185
|
-
|
186
|
-
|
187
|
-
|
188
|
-
|
189
|
-
|
190
|
-
|
191
|
-
|
192
|
-
|
193
|
-
|
194
|
-
|
195
|
-
|
196
|
-
|
197
|
-
|
198
|
-
|
199
|
-
end
|
200
|
-
|
201
|
-
# Returns path to downloaded gem
|
202
|
-
#
|
203
|
-
# @return [String] path to downloaded gem
|
204
|
-
def self.downloaded_gem_path(name, version)
|
205
|
-
# ensure gem is downloaded
|
206
|
-
download_gem name, version
|
207
|
-
GemCache.path_for(name, version)
|
208
|
-
end
|
209
|
-
|
210
|
-
# Return path to downloaded gem
|
211
|
-
def downloaded_gem_path
|
212
|
-
self.class.downloaded_gem_path @name, @version
|
213
|
-
end
|
214
|
-
|
215
|
-
# Returns path to gem, either specified one of downloaded one
|
216
|
-
def gem_path
|
217
|
-
@path || downloaded_gem_path
|
218
|
-
end
|
219
|
-
|
220
|
-
# Unpack files & return unpacked directory
|
221
|
-
#
|
222
|
-
# If block is specified, it will be invoked
|
223
|
-
# with directory after which directory will be removed
|
224
|
-
def unpack(&bl)
|
225
|
-
dir = nil
|
226
|
-
pkg = ::Gem::Installer.new gem_path, :unpack => true
|
227
|
-
|
228
|
-
if bl
|
229
|
-
Dir.mktmpdir do |tmpdir|
|
230
|
-
pkg.unpack tmpdir
|
231
|
-
bl.call tmpdir
|
232
|
-
end
|
233
|
-
else
|
234
|
-
dir = Dir.mktmpdir
|
235
|
-
pkg.unpack dir
|
236
|
-
end
|
237
|
-
|
238
|
-
dir
|
239
|
-
end
|
240
|
-
|
241
|
-
# Iterate over each file in gem invoking block with path
|
242
|
-
def each_file(&bl)
|
243
|
-
unpack do |dir|
|
244
|
-
Pathname(dir).detect do |path|
|
245
|
-
next if path.to_s == dir.to_s
|
246
|
-
pathstr = path.to_s.gsub("#{dir}/", '')
|
247
|
-
bl.call pathstr unless pathstr.blank?
|
248
|
-
end
|
249
|
-
end
|
250
|
-
end
|
251
|
-
|
252
|
-
# Retrieve the list of paths to files in the gem
|
253
|
-
#
|
254
|
-
# @return [Array<String>] list of files in the gem
|
255
|
-
def file_paths
|
256
|
-
@file_paths ||= begin
|
257
|
-
files = []
|
258
|
-
each_file do |path|
|
259
|
-
files << path
|
260
|
-
end
|
261
|
-
files
|
262
|
-
end
|
263
|
-
end
|
264
|
-
|
265
|
-
# Retrieve gem metadata and contents from rubygems.org
|
266
|
-
#
|
267
|
-
# @param [String] name string name of gem to retrieve
|
268
|
-
# @return [Polisher::Gem] representation of gem
|
269
|
-
def self.retrieve(name)
|
270
|
-
gem_json_path = "https://rubygems.org/api/v1/gems/#{name}.json"
|
271
|
-
spec = Curl::Easy.http_get(gem_json_path).body_str
|
272
|
-
gem = parse spec
|
273
|
-
gem
|
274
|
-
end
|
275
|
-
|
276
|
-
# Retreive versions of gem available in all configured targets (optionally recursively)
|
277
|
-
#
|
278
|
-
# @param [Hash] args hash of options to configure retrieval
|
279
|
-
# @option args [Boolean] :recursive indicates if versions of dependencies
|
280
|
-
# should also be retrieved
|
281
|
-
# @option args [Boolean] :dev_deps indicates if versions of development
|
282
|
-
# dependencies should also be retrieved
|
283
|
-
# @retrieve versions of all gem dependencies available in configured targets
|
284
|
-
def dependency_versions(args = {}, &bl)
|
285
|
-
versions = args[:versions] || {}
|
286
|
-
check_deps = args[:dev] ? dev_deps : deps
|
287
|
-
|
288
|
-
check_deps.each do |dep|
|
289
|
-
unless versions.key?(dep.name)
|
290
|
-
begin
|
291
|
-
gem = Polisher::Gem.retrieve(dep.name)
|
292
|
-
versions.merge! gem.versions(args, &bl)
|
293
|
-
rescue
|
294
|
-
unknown = Polisher::VersionChecker.unknown_version(:all, dep.name, &bl)
|
295
|
-
versions.merge! dep.name => unknown
|
296
|
-
end
|
297
|
-
end
|
298
|
-
|
299
|
-
args[:versions] = versions
|
300
|
-
end
|
301
|
-
|
302
|
-
versions
|
303
|
-
end
|
304
|
-
|
305
|
-
# (and dependencies if specified)
|
306
|
-
def versions(args = {}, &bl)
|
307
|
-
local_args = Hash[args]
|
308
|
-
recursive = local_args[:recursive]
|
309
|
-
dev_deps = local_args[:dev_deps]
|
310
|
-
versions = local_args[:versions] || {}
|
311
|
-
|
312
|
-
gem_versions = Polisher::VersionChecker.versions_for(name, &bl)
|
313
|
-
versions.merge! name => gem_versions
|
314
|
-
local_args[:versions] = versions
|
315
|
-
|
316
|
-
if recursive
|
317
|
-
dependency_versions local_args
|
318
|
-
dependency_versions local_args.merge(:dev => true) if dev_deps
|
319
|
-
end
|
320
|
-
|
321
|
-
versions
|
322
|
-
end
|
323
|
-
|
324
|
-
|
325
|
-
# Return diff of content in this gem against other
|
326
|
-
def diff(other)
|
327
|
-
require_cmd! diff_cmd
|
328
|
-
out = nil
|
329
|
-
|
330
|
-
begin
|
331
|
-
this_dir = unpack
|
332
|
-
other_dir = other.is_a?(Polisher::Gem) ? other.unpack :
|
333
|
-
(other.is_a?(Polisher::Git::Repo) ? other.path : other)
|
334
|
-
result = AwesomeSpawn.run("#{diff_cmd} -r #{this_dir} #{other_dir}")
|
335
|
-
out = result.output.gsub("#{this_dir}", 'a').gsub("#{other_dir}", 'b')
|
336
|
-
rescue
|
337
|
-
ensure
|
338
|
-
FileUtils.rm_rf this_dir unless this_dir.nil?
|
339
|
-
FileUtils.rm_rf other_dir unless other_dir.nil? ||
|
340
|
-
!other.is_a?(Polisher::Gem)
|
341
|
-
end
|
342
|
-
|
343
|
-
out
|
344
|
-
end
|
345
|
-
end # class Gem
|
346
|
-
end # Component.verify("Gem")
|
19
|
+
module Polisher
|
20
|
+
class Gem
|
21
|
+
include ConfHelpers
|
22
|
+
include HasVendoredDeps
|
23
|
+
|
24
|
+
include GemAttributes
|
25
|
+
include GemDependencies
|
26
|
+
include GemFiles
|
27
|
+
include GemState
|
28
|
+
include GemVersions
|
29
|
+
|
30
|
+
include GemParser
|
31
|
+
include GemRetriever
|
32
|
+
include GemDiff
|
33
|
+
|
34
|
+
conf_attr :diff_cmd, '/usr/bin/diff'
|
35
|
+
|
36
|
+
def initialize(args = {})
|
37
|
+
@spec = args[:spec]
|
38
|
+
@name = args[:name]
|
39
|
+
@version = args[:version]
|
40
|
+
@path = args[:path]
|
41
|
+
@deps = args[:deps] || []
|
42
|
+
@dev_deps = args[:dev_deps] || []
|
43
|
+
end
|
44
|
+
|
45
|
+
# Returns path to gem, either specified one of downloaded one
|
46
|
+
def gem_path
|
47
|
+
@path || downloaded_gem_path
|
48
|
+
end
|
49
|
+
end # class Gem
|
347
50
|
end # module Polisher
|