polisher 0.10.2 → 0.11.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (180) hide show
  1. checksums.yaml +4 -4
  2. data/bin/binary_gem_resolver.rb +2 -2
  3. data/bin/bundler2yum.rb +51 -0
  4. data/bin/check_ruby_spec.rb +32 -0
  5. data/bin/gem_dependency_checker.rb +13 -242
  6. data/bin/gem_mapper.rb +27 -0
  7. data/bin/gems2update.rb +27 -0
  8. data/bin/git_gem_diff.rb +48 -0
  9. data/bin/git_gem_updater.rb +3 -3
  10. data/bin/missing_deps.rb +29 -0
  11. data/bin/polisher-config.rb +17 -0
  12. data/bin/ruby_rpm_spec_updater.rb +23 -2
  13. data/lib/polisher.rb +5 -12
  14. data/lib/polisher/adaptors/checker_loader.rb +78 -0
  15. data/lib/polisher/{upstream.rb → adaptors/upstream.rb} +1 -0
  16. data/lib/polisher/adaptors/version_checker.rb +57 -0
  17. data/lib/polisher/adaptors/version_checker/bodhi.rb +29 -0
  18. data/lib/polisher/adaptors/version_checker/errata.rb +29 -0
  19. data/lib/polisher/adaptors/version_checker/fedora.rb +29 -0
  20. data/lib/polisher/adaptors/version_checker/gem.rb +27 -0
  21. data/lib/polisher/adaptors/version_checker/git.rb +29 -0
  22. data/lib/polisher/adaptors/version_checker/koji.rb +29 -0
  23. data/lib/polisher/adaptors/version_checker/yum.rb +29 -0
  24. data/lib/polisher/cli/all.rb +22 -0
  25. data/lib/polisher/cli/bin/gem_dependency_checker.rb +85 -0
  26. data/lib/polisher/cli/bin/gem_mapper.rb +37 -0
  27. data/lib/polisher/cli/bin/gems2update.rb +86 -0
  28. data/lib/polisher/cli/bin/missing_deps.rb +35 -0
  29. data/lib/polisher/cli/conf.rb +18 -0
  30. data/lib/polisher/cli/default.rb +25 -0
  31. data/lib/polisher/cli/format.rb +130 -0
  32. data/lib/polisher/cli/sources.rb +106 -0
  33. data/lib/polisher/cli/specifier.rb +30 -0
  34. data/lib/polisher/cli/status.rb +50 -0
  35. data/lib/polisher/cli/targets.rb +88 -0
  36. data/lib/polisher/gem.rb +41 -338
  37. data/lib/polisher/gem/attributes.rb +20 -0
  38. data/lib/polisher/gem/dependencies.rb +63 -0
  39. data/lib/polisher/gem/diff.rb +39 -0
  40. data/lib/polisher/gem/files.rb +111 -0
  41. data/lib/polisher/gem/parser.rb +85 -0
  42. data/lib/polisher/gem/retriever.rb +137 -0
  43. data/lib/polisher/{gem_state.rb → gem/state.rb} +6 -6
  44. data/lib/polisher/gem/versions.rb +131 -0
  45. data/lib/polisher/gemfile.rb +20 -89
  46. data/lib/polisher/gemfile/attributes.rb +19 -0
  47. data/lib/polisher/gemfile/deps.rb +43 -0
  48. data/lib/polisher/gemfile/parser.rb +45 -0
  49. data/lib/polisher/git/pkg.rb +33 -238
  50. data/lib/polisher/git/pkg/attributes.rb +60 -0
  51. data/lib/polisher/git/pkg/builder.rb +47 -0
  52. data/lib/polisher/git/pkg/repo.rb +82 -0
  53. data/lib/polisher/git/pkg/updater.rb +53 -0
  54. data/lib/polisher/git/pkg/versions.rb +40 -0
  55. data/lib/polisher/git/project.rb +1 -1
  56. data/lib/polisher/git/repo.rb +79 -76
  57. data/lib/polisher/{vendor.rb → mixins/vendored_deps.rb} +4 -7
  58. data/lib/polisher/mixins/versioned_dependencies.rb +86 -0
  59. data/lib/polisher/record.rb +2 -0
  60. data/lib/polisher/rpm.rb +23 -0
  61. data/lib/polisher/rpm/patch.rb +10 -8
  62. data/lib/polisher/rpm/requirement.rb +33 -189
  63. data/lib/polisher/rpm/requirement/attributes.rb +43 -0
  64. data/lib/polisher/rpm/requirement/comparison.rb +97 -0
  65. data/lib/polisher/rpm/requirement/gem_reference.rb +46 -0
  66. data/lib/polisher/rpm/requirement/parser.rb +41 -0
  67. data/lib/polisher/rpm/spec.rb +97 -436
  68. data/lib/polisher/rpm/spec/check.rb +14 -0
  69. data/lib/polisher/rpm/spec/comparison.rb +64 -0
  70. data/lib/polisher/rpm/spec/files.rb +15 -0
  71. data/lib/polisher/rpm/spec/gem_files.rb +65 -0
  72. data/lib/polisher/rpm/spec/gem_reference.rb +59 -0
  73. data/lib/polisher/rpm/spec/gem_requirements.rb +73 -0
  74. data/lib/polisher/rpm/spec/parser.rb +106 -0
  75. data/lib/polisher/rpm/spec/requirements.rb +31 -0
  76. data/lib/polisher/rpm/spec/subpackages.rb +23 -0
  77. data/lib/polisher/rpm/spec/updater.rb +268 -0
  78. data/lib/polisher/specifier.rb +13 -0
  79. data/lib/polisher/targets.rb +36 -0
  80. data/lib/polisher/{apt.rb → targets/apt.rb} +1 -1
  81. data/lib/polisher/targets/bodhi.rb +43 -0
  82. data/lib/polisher/{bugzilla.rb → targets/bugzilla.rb} +1 -1
  83. data/lib/polisher/targets/errata.rb +55 -0
  84. data/lib/polisher/targets/errata/build.rb +24 -0
  85. data/lib/polisher/targets/fedora.rb +47 -0
  86. data/lib/polisher/targets/koji.rb +39 -0
  87. data/lib/polisher/targets/koji/builder.rb +38 -0
  88. data/lib/polisher/targets/koji/diff.rb +39 -0
  89. data/lib/polisher/targets/koji/rpc.rb +43 -0
  90. data/lib/polisher/targets/koji/versions.rb +67 -0
  91. data/lib/polisher/targets/rhn.rb +12 -0
  92. data/lib/polisher/targets/yum.rb +36 -0
  93. data/lib/polisher/{component.rb → util/component.rb} +3 -3
  94. data/lib/polisher/util/conf_helpers.rb +77 -0
  95. data/lib/polisher/util/config.rb +45 -0
  96. data/lib/polisher/util/core_ext.rb +59 -0
  97. data/lib/polisher/{error.rb → util/error.rb} +0 -0
  98. data/lib/polisher/{gem_cache.rb → util/gem_cache.rb} +1 -1
  99. data/lib/polisher/{git_cache.rb → util/git_cache.rb} +0 -0
  100. data/lib/polisher/{logger.rb → util/logger.rb} +2 -0
  101. data/lib/polisher/{tag_mapper.rb → util/tag_mapper.rb} +1 -1
  102. data/lib/polisher/version.rb +1 -1
  103. data/spec/{upstream_spec.rb → adaptors/upstream_spec.rb} +1 -1
  104. data/spec/{version_checker_spec.rb → adaptors/version_checker_spec.rb} +1 -6
  105. data/spec/data/activesupport-4.1.4.gem +0 -0
  106. data/spec/data/rubygem-activesupport-with-doc.spec +247 -0
  107. data/spec/data/rubygem-activesupport-without-requires.spec +232 -0
  108. data/spec/data/rubygem-activesupport.spec +0 -122
  109. data/spec/fixtures/gem_json.rb +49 -0
  110. data/spec/fixtures/gem_spec.rb +13 -0
  111. data/spec/fixtures/gemfile.rb +10 -0
  112. data/spec/fixtures/local_gem.rb +62 -0
  113. data/spec/fixtures/rpm_spec.rb +91 -0
  114. data/spec/gem/attributes_spec.rb +17 -0
  115. data/spec/gem/diff_spec.rb +80 -0
  116. data/spec/gem/files_spec.rb +171 -0
  117. data/spec/gem/parser_spec.rb +44 -0
  118. data/spec/gem/retriever_spec.rb +124 -0
  119. data/spec/gem/state_spec.rb +79 -0
  120. data/spec/gem/versions_spec.rb +148 -0
  121. data/spec/gem_spec.rb +5 -347
  122. data/spec/gemfile/deps_spec.rb +20 -0
  123. data/spec/gemfile/parser_spec.rb +26 -0
  124. data/spec/gemfile_spec.rb +0 -34
  125. data/spec/git/pkg/attributes_spec.rb +128 -0
  126. data/spec/git/pkg/builder_spec.rb +63 -0
  127. data/spec/git/pkg/repo_spec.rb +146 -0
  128. data/spec/git/pkg/updater_spec.rb +86 -0
  129. data/spec/git/pkg/versions_spec.rb +42 -0
  130. data/spec/git/pkg_spec.rb +21 -0
  131. data/spec/git/project_spec.rb +21 -0
  132. data/spec/git/repo_spec.rb +160 -0
  133. data/spec/{vendor_spec.rb → mixins/vendored_deps_spec.rb} +2 -4
  134. data/spec/mixins/versioned_dependencies_spec.rb +48 -0
  135. data/spec/rpm/patch_spec.rb +48 -0
  136. data/spec/rpm/requirement/attributes_spec.rb +34 -0
  137. data/spec/rpm/requirement/comparison_spec.rb +286 -0
  138. data/spec/rpm/requirement/gem_spec.rb +49 -0
  139. data/spec/rpm/requirement/parser_spec.rb +31 -0
  140. data/spec/rpm/requirement_spec.rb +8 -334
  141. data/spec/rpm/spec/check_spec.rb +25 -0
  142. data/spec/rpm/spec/comparison_spec.rb +55 -0
  143. data/spec/rpm/spec/files_spec.rb +17 -0
  144. data/spec/rpm/spec/gem_files_spec.rb +112 -0
  145. data/spec/rpm/spec/gem_reference_spec.rb +99 -0
  146. data/spec/rpm/spec/gem_requirement_spec.rb +38 -0
  147. data/spec/rpm/spec/parser_spec.rb +64 -0
  148. data/spec/rpm/spec/requirements_spec.rb +10 -0
  149. data/spec/rpm/spec/subpackages_spec.rb +38 -0
  150. data/spec/rpm/spec/updater_spec.rb +486 -0
  151. data/spec/rpm/spec_spec.rb +27 -174
  152. data/spec/spec_helper.rb +7 -107
  153. data/spec/support/coveralls.rb +10 -0
  154. data/spec/support/fixtures.rb +8 -0
  155. data/spec/support/paths.rb +20 -0
  156. data/spec/support/rspec.rb +20 -0
  157. data/spec/support/vcr.rb +11 -0
  158. data/spec/{bodhi_spec.rb → targets/bodhi_spec.rb} +3 -1
  159. data/spec/{errata_spec.rb → targets/errata_spec.rb} +2 -2
  160. data/spec/{fedora_spec.rb → targets/fedora_spec.rb} +3 -3
  161. data/spec/targets/koji/builder_spec.rb +48 -0
  162. data/spec/targets/koji/diff_spec.rb +36 -0
  163. data/spec/targets/koji/rpc_spec.rb +28 -0
  164. data/spec/{koji_spec.rb → targets/koji/versions_spec.rb} +1 -59
  165. data/spec/targets/koji_spec.rb +11 -0
  166. data/spec/{yum_spec.rb → targets/yum_spec.rb} +1 -1
  167. data/spec/{component_spec.rb → util/component_spec.rb} +1 -1
  168. data/spec/{core_spec.rb → util/core_ext_spec.rb} +2 -3
  169. metadata +278 -88
  170. data/lib/polisher/bodhi.rb +0 -23
  171. data/lib/polisher/config.rb +0 -32
  172. data/lib/polisher/core.rb +0 -101
  173. data/lib/polisher/errata.rb +0 -75
  174. data/lib/polisher/fedora.rb +0 -46
  175. data/lib/polisher/git.rb +0 -8
  176. data/lib/polisher/koji.rb +0 -159
  177. data/lib/polisher/rhn.rb +0 -15
  178. data/lib/polisher/version_checker.rb +0 -177
  179. data/lib/polisher/yum.rb +0 -37
  180. data/spec/git_spec.rb +0 -445
@@ -0,0 +1,29 @@
1
+ # Polisher VersionChecker Yum Mixin
2
+ #
3
+ # Licensed under the MIT license
4
+ # Copyright (C) 2013-2014 Red Hat, Inc.
5
+
6
+ module Polisher
7
+ module YumVersionChecker
8
+ def self.default?
9
+ @default ||= true
10
+ end
11
+
12
+ def self.included(base)
13
+ base.extend(ClassMethods)
14
+ end
15
+
16
+ module ClassMethods
17
+ def yum_versions(name, &bl)
18
+ require 'polisher/targets/yum'
19
+ logger.debug "versions_for<yum>(#{name})..."
20
+ yum_versions = [Yum.version_for(name, &bl)]
21
+ logger.debug yum_versions
22
+ yum_versions
23
+ rescue
24
+ logger.debug 'unknown'
25
+ unknown_version(:yum, name, &bl)
26
+ end
27
+ end # module ClassMethods
28
+ end # module YumVersionChecker
29
+ end # module Polisher
@@ -0,0 +1,22 @@
1
+ #!/usr/bin/ruby
2
+ # Polisher CLI
3
+ #
4
+ # Licensed under the MIT license
5
+ # Copyright (C) 2015 Red Hat, Inc.
6
+ ###########################################################
7
+
8
+ require 'polisher/cli/default'
9
+ require 'polisher/cli/sources'
10
+ require 'polisher/cli/targets'
11
+ require 'polisher/cli/specifier'
12
+ require 'polisher/cli/format'
13
+ require 'polisher/cli/conf'
14
+ require 'polisher/cli/status'
15
+
16
+ module Polisher
17
+ module CLI
18
+ #def self.included(base)
19
+ # base.extend(ClassMethods)
20
+ #end
21
+ end # module CLI
22
+ end # module Polisher
@@ -0,0 +1,85 @@
1
+ # Polisher gem_dependency_checker cli util
2
+ #
3
+ # Licensed under the MIT license
4
+ # Copyright (C) 2015 Red Hat, Inc.
5
+ ###########################################################
6
+
7
+ require 'optparse'
8
+
9
+ module Polisher
10
+ module CLI
11
+ def gem_dependency_checker_conf
12
+ conf.merge!({:format => nil}).merge!(default_conf)
13
+ .merge!(targets_conf)
14
+ .merge!(sources_conf)
15
+ end
16
+
17
+ def gem_dependency_checker_options(option_parser)
18
+ option_parser.on("--format val", 'Format which to render output') do |f|
19
+ conf[:format] = f
20
+ end
21
+ end
22
+
23
+ def gem_dependency_checker_option_parser
24
+ OptionParser.new do |opts|
25
+ default_options opts
26
+ sources_options opts
27
+ targets_options opts
28
+ gem_dependency_checker_options opts
29
+ end
30
+ end
31
+
32
+ def header
33
+ if @format == 'xml'
34
+ '<dependencies>'
35
+ elsif @format == 'json'
36
+ '{'
37
+ end
38
+ end
39
+
40
+ def footer
41
+ if @format == 'xml'
42
+ "</dependencies>"
43
+ elsif @format == 'json'
44
+ "}"
45
+ end
46
+ end
47
+
48
+ def print_header
49
+ print header
50
+ end
51
+
52
+ def print_footer
53
+ print footer
54
+ end
55
+
56
+ def print_dep(dep, tgt, versions)
57
+ print pretty_tgt(dep, tgt, versions)
58
+ end
59
+
60
+ def print_gem_deps(gem)
61
+ gem.versions(:recursive => true,
62
+ :dev_deps => conf[:devel_deps]) do |tgt, dep, versions|
63
+ print_dep(dep, tgt, versions)
64
+ end
65
+ end
66
+
67
+ def print_gemfile_deps(gemfile)
68
+ gemfile.dependency_versions :recursive => true,
69
+ :dev_deps => conf[:devel_deps] do |tgt, dep, versions|
70
+ print_dep(dep, tgt, versions)
71
+ end
72
+ end
73
+
74
+ def print_deps(conf)
75
+ if conf_gem?
76
+ print_gem_deps(conf_source)
77
+
78
+ elsif conf_gemfile?
79
+ print_gemfile_deps(conf_source)
80
+ end
81
+
82
+ puts last_dep # XXX
83
+ end
84
+ end # module CLI
85
+ end # module Polisher
@@ -0,0 +1,37 @@
1
+ # Polisher gem_mapper cli util
2
+ #
3
+ # Licensed under the MIT license
4
+ # Copyright (C) 2015 Red Hat, Inc.
5
+ ###########################################################
6
+
7
+ require 'optparse'
8
+
9
+ def gem_mapper_conf
10
+ conf.merge!(default_conf)
11
+ .merge!(specifier_conf)
12
+ .merge!(sources_conf)
13
+ end
14
+
15
+ def gem_mapper_parser
16
+ OptionParser.new do |opts|
17
+ default_options(opts)
18
+ sources_options(opts)
19
+ specifier_opts(opts)
20
+ end
21
+ end
22
+
23
+ def print_dep(gem, dep, resolved_dep)
24
+ print pretty_dep(gem, dep, resolved_dep)
25
+ end
26
+
27
+ def print_deps(source)
28
+ source.dependency_tree(:recursive => true,
29
+ :dev_deps => conf[:devel_deps],
30
+ :matching => conf[:matching]) do |gem, dep, resolved_dep|
31
+ print_dep(gem, dep, resolved_dep)
32
+ end
33
+ end
34
+
35
+ def print_tree(conf)
36
+ print_deps(conf_source) if conf_gem? || conf_gemfile?
37
+ end
@@ -0,0 +1,86 @@
1
+ # Polisher gem2update cli util
2
+ #
3
+ # Licensed under the MIT license
4
+ # Copyright (C) 2015 Red Hat, Inc.
5
+ ###########################################################
6
+
7
+ require 'optparse'
8
+
9
+ def gems2update_conf
10
+ conf.merge!(default_conf)
11
+ .merge!(targets_conf)
12
+ .merge!(sources_conf)
13
+ end
14
+
15
+ def gems2update_parser
16
+ OptionParser.new do |opts|
17
+ default_options opts
18
+ targets_options opts
19
+ sources_options opts
20
+ end
21
+ end
22
+
23
+ def check_missing(deps, alts)
24
+ deps.each { |name, gdeps|
25
+ versions = Polisher::Gem.remote_versions_for(name)
26
+ matching = versions.select { |v| gdeps.all? { |dep| dep.match?(name, v)} }
27
+ latest = alts[name].max
28
+
29
+ print "#{name}(#{latest}) #{gdeps.collect { |dep| dep.requirement.to_s }}: ".blue.bold
30
+
31
+ if matching.empty?
32
+ puts "No matching upstream versions".red.bold
33
+
34
+ else
35
+ updatable = latest.nil? ? matching : matching.select { |m| m > latest }
36
+
37
+ if updatable.empty?
38
+ puts "No matching upstream version > #{latest} (downstream)".red.bold
39
+
40
+ else
41
+ puts "Update to #{updatable.max}".green.bold
42
+
43
+ end
44
+ end
45
+ }
46
+ end
47
+
48
+ def check_gems2update(source)
49
+ deps = {}
50
+ alts = {}
51
+
52
+ msg = 'processing dependencies'
53
+ waiting :msg => msg,
54
+ :color => :red
55
+
56
+ source.dependency_tree(:recursive => true,
57
+ :dev_deps => conf[:devel_deps]) do |source, dep, resolved_dep|
58
+ waiting_msg "#{msg} #{source.name}(#{dep.name})"
59
+
60
+ # XXX : need to nullify dep.type for this lookup
61
+ dep.instance_variable_set(:@type, :runtime)
62
+ name = dep.name
63
+ other_version_missing = deps.key?(name)
64
+ has_dep = other_version_missing && deps[name].any? { |gdep| gdep == dep }
65
+
66
+ unless has_dep
67
+ versions = Polisher::VersionChecker.matching_versions(dep)
68
+ missing_downstream = versions.empty?
69
+ end
70
+
71
+ if missing_downstream || other_version_missing
72
+ deps[name] ||= []
73
+ deps[name] << dep unless has_dep
74
+
75
+ alts[name] = Polisher::VersionChecker.versions_for(name).values.flatten unless alts.key?(name)
76
+ end
77
+
78
+ end
79
+
80
+ end_waiting
81
+ check_missing(deps, alts)
82
+ end
83
+
84
+ def check_gems(conf)
85
+ check_gems2update(conf_source) if conf_gem? || conf_gemfile?
86
+ end
@@ -0,0 +1,35 @@
1
+ # Polisher missing_deps cli util
2
+ #
3
+ # Licensed under the MIT license
4
+ # Copyright (C) 2015 Red Hat, Inc.
5
+ ###########################################################
6
+
7
+ require 'optparse'
8
+
9
+ def missing_deps_conf
10
+ conf.merge!(default_conf)
11
+ .merge!(targets_conf)
12
+ .merge!(sources_conf)
13
+ end
14
+
15
+ def missing_deps_parser
16
+ OptionParser.new do |opts|
17
+ default_options opts
18
+ targets_options opts
19
+ sources_options opts
20
+ end
21
+ end
22
+
23
+ def check_missing_deps(source)
24
+ source.dependency_tree(:recursive => true,
25
+ :dev_deps => conf[:devel_deps]) do |source, dep, resolved_dep|
26
+ versions = Polisher::VersionChecker.matching_versions(dep)
27
+ alt = Polisher::VersionChecker.versions_for(dep.name)
28
+ source_str = source.is_a?(Polisher::Gemfile) ? "Gemfile" : "#{source.name} #{source.version}"
29
+ puts "#{source_str} missing dep #{dep.name} #{dep.requirement} - alt versions: #{alt}" if versions.empty?
30
+ end
31
+ end
32
+
33
+ def check_deps(conf)
34
+ check_missing_deps(conf_source) if conf_gem? || conf_gemfile?
35
+ end
@@ -0,0 +1,18 @@
1
+ #!/usr/bin/ruby
2
+ # Polisher CLI
3
+ #
4
+ # Licensed under the MIT license
5
+ # Copyright (C) 2015 Red Hat, Inc.
6
+ ###########################################################
7
+
8
+ module Polisher
9
+ module CLI
10
+ def self.conf
11
+ @conf ||= {}
12
+ end
13
+
14
+ def conf
15
+ CLI.conf
16
+ end
17
+ end # mdoule CLI
18
+ end
@@ -0,0 +1,25 @@
1
+ #!/usr/bin/ruby
2
+ # Polisher CLI Default 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 default_conf
11
+ { :log_level => :info }
12
+ end
13
+
14
+ def default_options(option_parser)
15
+ option_parser.on('-h', '--help', 'Display this help screen') do
16
+ puts option_parser
17
+ exit
18
+ end
19
+
20
+ option_parser.on('-l', '--log-level [level]', 'Set the log level') do |level|
21
+ conf[:log_level] = level.intern
22
+ end
23
+ end
24
+ end # module CLI
25
+ end # module Polisher
@@ -0,0 +1,130 @@
1
+ # Polisher CLI Target Options
2
+ #
3
+ # Licensed under the MIT license
4
+ # Copyright (C) 2015 Red Hat, Inc.
5
+ ###########################################################
6
+
7
+ require 'colored'
8
+
9
+ module Polisher
10
+ module CLI
11
+ def set_format(conf)
12
+ @format = conf[:format]
13
+ end
14
+
15
+ def format_title(title)
16
+ if @format.nil?
17
+ title.to_s.blue.bold + ' '
18
+ elsif @format == 'xml'
19
+ "<#{title}>"
20
+ elsif @format == 'json'
21
+ "'#{title}':{"
22
+ end
23
+ end
24
+
25
+ def format_end(closer)
26
+ if @format.nil?
27
+ "\n"
28
+ elsif @format == 'xml'
29
+ "\n</#{closer}>"
30
+ elsif @format == 'json'
31
+ "\n}"
32
+ end
33
+ end
34
+
35
+ def format_missing_dep(dep)
36
+ if @format.nil?
37
+ "\n #{dep.to_s.red.bold}"
38
+ elsif @format == 'xml'
39
+ "<#{dep.name}>#{dep.requirement}</#{dep.name}>"
40
+ elsif @format == 'json'
41
+ "'#{dep.name}':'#{dep.requirement}'"
42
+ end
43
+ end
44
+
45
+ def format_dep(dep, resolved_dep)
46
+ if @format.nil?
47
+ "\n #{dep.to_s.green.bold} (#{resolved_dep.version})"
48
+ elsif @format == 'xml'
49
+ "<#{dep.name}>#{dep.requirement}/#{resolved_dep.version}</#{dep.name}>"
50
+ elsif @format == 'json'
51
+ "'#{dep.name}':'#{dep.requirement}/#{resolved_dep.version}'"
52
+ end
53
+ end
54
+
55
+ def pretty_dep(gem, dep, resolved_dep)
56
+ pretty = ''
57
+
58
+ # XXX little bit hacky but works for now
59
+ @last_gem ||= nil
60
+ if @last_gem != gem
61
+ pretty += format_end(@last_dep.name) unless @last_gem.nil?
62
+ pretty += format_title(gem.is_a?(Gemfile) ? "Gemfile" : "#{gem.name} #{gem.version}")
63
+ @last_gem = gem
64
+ end
65
+
66
+ pretty += resolved_dep.nil? ? format_missing_dep(dep) : format_dep(dep, resolved_dep)
67
+ @last_dep = dep
68
+ pretty
69
+ end
70
+
71
+ def format_tgt(tgt)
72
+ if @format.nil?
73
+ " #{tgt.to_s.red.bold}"
74
+ elsif @format == 'xml'
75
+ "<#{tgt}/>"
76
+ elsif @format == 'json'
77
+ "'#{tgt}':null,"
78
+ end
79
+ end
80
+
81
+ def format_unknown_tgt(tgt)
82
+ if @format.nil?
83
+ "#{tgt.to_s.red.bold}: " + "unknown".yellow
84
+ else
85
+ format_tgt("#{tgt} (unknown)")
86
+ end
87
+ end
88
+
89
+ def format_tgt_with_versions(tgt, versions)
90
+ if @format.nil?
91
+ " #{tgt.to_s.green.bold}: #{versions.join(', ').yellow}"
92
+ elsif @format == 'xml'
93
+ "<#{tgt}>#{versions.join(', ')}</#{tgt}>"
94
+ elsif @format == 'json'
95
+ "'#{tgt}':['#{versions.join('\', \'')}'],"
96
+ end
97
+ end
98
+
99
+ def pretty_tgt(dep, tgt, versions)
100
+ pretty = ''
101
+
102
+ @last_dep ||= nil
103
+ if @last_dep != dep
104
+ pretty += format_end(@last_dep) unless @last_dep.nil?
105
+ pretty += format_title(dep)
106
+ @last_dep = dep
107
+ end
108
+
109
+ if versions.blank? || (versions.size == 1 && versions.first.blank?)
110
+ pretty += format_tgt(tgt)
111
+
112
+ elsif versions.size == 1 && versions.first == :unknown
113
+ pretty += format_unknown_tgt(tgt)
114
+
115
+ else
116
+ pretty += format_tgt_with_versions(tgt, versions)
117
+ end
118
+
119
+ pretty
120
+ end
121
+
122
+ def last_dep # XXX
123
+ format_end(@last_dep) unless @last_dep.nil?
124
+ end
125
+
126
+ def last_gem # XXX
127
+ format_end(@last_gem) unless @last_gem.nil?
128
+ end
129
+ end # module CLI
130
+ end # module Polisher