gemrage 0.1.2 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- data/VERSION +1 -1
- data/gemrage.gemspec +1 -1
- data/lib/rubygems/commands/scan_command.rb +84 -13
- metadata +3 -3
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.
|
1
|
+
0.2.0
|
data/gemrage.gemspec
CHANGED
@@ -15,6 +15,8 @@ Bundler.require
|
|
15
15
|
class Gem::Commands::ScanCommand < Gem::Command
|
16
16
|
include Gem::GemcutterUtilities
|
17
17
|
|
18
|
+
GemrageHost = 'http://gemrage.com/'
|
19
|
+
|
18
20
|
def initialize
|
19
21
|
super('scan', description, :dir => '')
|
20
22
|
end
|
@@ -32,17 +34,20 @@ class Gem::Commands::ScanCommand < Gem::Command
|
|
32
34
|
end
|
33
35
|
|
34
36
|
def execute
|
35
|
-
p
|
37
|
+
p system_scan
|
36
38
|
end
|
37
39
|
|
38
40
|
private
|
39
41
|
|
40
42
|
def system_scan
|
41
43
|
if windows? && pik?
|
44
|
+
notify("Scanning with pik")
|
42
45
|
pik_scan
|
43
46
|
elsif !windows? && rvm?
|
47
|
+
notify("Scanning with RVM...this might take a while")
|
44
48
|
rvm_scan
|
45
49
|
else
|
50
|
+
notify("Scanning with basic gem support")
|
46
51
|
basic_scan
|
47
52
|
end
|
48
53
|
end
|
@@ -52,19 +57,72 @@ private
|
|
52
57
|
end
|
53
58
|
|
54
59
|
def rvm_scan
|
60
|
+
h = {}
|
55
61
|
RVM.list_gemsets.map do |config|
|
56
|
-
RVM
|
57
|
-
|
58
|
-
|
62
|
+
notify('Scanning RVM config ', config)
|
63
|
+
begin
|
64
|
+
rd, wr = IO.pipe
|
65
|
+
pid = fork do
|
66
|
+
begin
|
67
|
+
# Clear this because shenanigans ensue
|
68
|
+
ENV['BUNDLE_GEMFILE'] = nil
|
69
|
+
RVM.use(config)
|
70
|
+
wr.write("#{rvm_platform}\n")
|
71
|
+
# Have to do it this way to get stdout instead of just the okay from RVM
|
72
|
+
wr.write(RVM.perform_set_operation(:gem, 'list').stdout)
|
73
|
+
ensure
|
74
|
+
# No, mister superman no here...
|
75
|
+
RVM.reset_current!
|
76
|
+
# Ensure we close these inside the fork
|
77
|
+
rd.close unless rd.closed?
|
78
|
+
wr.close unless wr.closed?
|
79
|
+
end
|
80
|
+
end
|
81
|
+
# Close the write pipe so eof works and we don't hang
|
82
|
+
wr.close unless wr.closed?
|
83
|
+
Process.waitpid(pid)
|
84
|
+
plat = rd.readline.chomp.to_sym
|
85
|
+
h = merge_gem_list(h, parse_gem_list(rd.read, plat))
|
86
|
+
rescue => boom
|
87
|
+
# Don't care right now
|
88
|
+
# Might be an IO problem or whatever, just skip it
|
89
|
+
ensure
|
90
|
+
# Ensure we close these outside the fork
|
91
|
+
rd.close unless rd.closed?
|
92
|
+
wr.close unless wr.closed?
|
93
|
+
end
|
59
94
|
end
|
95
|
+
h
|
96
|
+
rescue => boom
|
97
|
+
notify('There was an error scanning: ', boom.message)
|
98
|
+
notify('On line: ', boom.backtrace.first)
|
99
|
+
notify('Please report this at http://gemrage.com/ so we can fix it!')
|
100
|
+
{}
|
60
101
|
ensure
|
61
102
|
RVM.reset_current!
|
62
103
|
end
|
63
104
|
|
105
|
+
def merge_gem_list(*hashes)
|
106
|
+
h = {}
|
107
|
+
hashes.each do |hash|
|
108
|
+
hash.each do |name, platform_hash|
|
109
|
+
h[name] ||= {}
|
110
|
+
platform_hash.each do |platform, versions|
|
111
|
+
h[name][platform] = [h[name][platform], versions].compact.uniq.join(',')
|
112
|
+
end
|
113
|
+
end
|
114
|
+
end
|
115
|
+
h
|
116
|
+
end
|
117
|
+
|
64
118
|
def basic_scan
|
119
|
+
plat = platform
|
120
|
+
h = {}
|
65
121
|
Gem.source_index.map do |name, spec|
|
66
|
-
spec.name
|
122
|
+
h[spec.name] ||= {}
|
123
|
+
h[spec.name][plat] = [spec.version.to_s, h[spec.name][plat]].compact.uniq.join(',')
|
67
124
|
end
|
125
|
+
h
|
68
126
|
end
|
69
127
|
|
70
128
|
def pik?
|
@@ -79,15 +137,23 @@ private
|
|
79
137
|
Digest::SHA1.hexdigest(Mac.addr)
|
80
138
|
end
|
81
139
|
|
82
|
-
def parse_gem_list(stdout)
|
83
|
-
|
140
|
+
def parse_gem_list(stdout, plat = platform)
|
141
|
+
h = {}
|
142
|
+
stdout.split("\n").each do |line|
|
143
|
+
name, versions = line.match(/^([\w\-_]+) \((.*)\)$/)[1,2] rescue next
|
144
|
+
versions = versions.split(',').map { |version| version.strip.split.first }
|
145
|
+
h[name] ||= {}
|
146
|
+
h[name][plat] = [h[name][plat], versions].compact.uniq.join(',')
|
147
|
+
end
|
148
|
+
h
|
84
149
|
end
|
85
150
|
|
86
151
|
def rvm_platform
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
152
|
+
platform(rvm_const('RUBY_ENGINE'), rvm_const('RUBY_DESCRIPTION'), rvm_const('RUBY_VERSION'))
|
153
|
+
end
|
154
|
+
|
155
|
+
def rvm_const(rc)
|
156
|
+
c = RVM.ruby("print #{rc}").stdout.strip and c = c.empty? ? nil : c
|
91
157
|
end
|
92
158
|
|
93
159
|
def windows?
|
@@ -95,8 +161,8 @@ private
|
|
95
161
|
end
|
96
162
|
|
97
163
|
def platform(engine = (defined?(RUBY_ENGINE) ? RUBY_ENGINE : nil),
|
98
|
-
|
99
|
-
|
164
|
+
description = (defined?(RUBY_DESCRIPTION) ? RUBY_DESCRIPTION : nil),
|
165
|
+
version = (defined?(RUBY_VERSION) ? RUBY_VERSION : nil))
|
100
166
|
if engine && engine == 'jruby'
|
101
167
|
:jruby
|
102
168
|
elsif engine && engine == 'ironruby'
|
@@ -121,4 +187,9 @@ private
|
|
121
187
|
:unknown
|
122
188
|
end
|
123
189
|
end
|
190
|
+
|
191
|
+
def notify(*messages)
|
192
|
+
print(*messages)
|
193
|
+
print("\n")
|
194
|
+
end
|
124
195
|
end
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: gemrage
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 23
|
5
5
|
prerelease: false
|
6
6
|
segments:
|
7
7
|
- 0
|
8
|
-
- 1
|
9
8
|
- 2
|
10
|
-
|
9
|
+
- 0
|
10
|
+
version: 0.2.0
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Daniel Huckstep
|