gemlocker 0.0.1
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.
- data/bin/gemlocker +300 -0
- data/doc/README.TXT +53 -0
- data/lib/gemlocker.rb +298 -0
- metadata +55 -0
data/bin/gemlocker
ADDED
@@ -0,0 +1,300 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
require 'rubygems'
|
3
|
+
require 'fileutils'
|
4
|
+
require 'rubygems/command'
|
5
|
+
require 'rubygems/gem_path_searcher'
|
6
|
+
|
7
|
+
|
8
|
+
class LockCommand < Gem::Command
|
9
|
+
|
10
|
+
def initialize
|
11
|
+
super 'lock', 'Generate a lockdown list of gems',
|
12
|
+
:strict => false
|
13
|
+
|
14
|
+
add_option '-s', '--[no-]strict',
|
15
|
+
'fail if unable to satisfy a dependency' do |strict, options|
|
16
|
+
options[:strict] = strict
|
17
|
+
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
|
22
|
+
def arguments # :nodoc:
|
23
|
+
"GEMNAME name of gem to lock\nVERSION version of gem to lock"
|
24
|
+
end
|
25
|
+
|
26
|
+
def defaults_str # :nodoc:
|
27
|
+
"--no-strict"
|
28
|
+
end
|
29
|
+
|
30
|
+
def usage # :nodoc:
|
31
|
+
"#{program_name} GEMNAME-VERSION [GEMNAME-VERSION ...]"
|
32
|
+
end
|
33
|
+
|
34
|
+
def complain(message)
|
35
|
+
if options[:strict] then
|
36
|
+
raise Gem::Exception, message
|
37
|
+
else
|
38
|
+
say "# #{message}"
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
def execute(out_file_path,x)
|
43
|
+
|
44
|
+
fgl = File.open(File.join(out_file_path, "gem_lockdown.rb"), "w");
|
45
|
+
if !fgl then
|
46
|
+
say " gem_lockdown.rb is not writable";
|
47
|
+
else
|
48
|
+
fgl.puts"require 'rubygems'"
|
49
|
+
end
|
50
|
+
pending = [];
|
51
|
+
locked = {}
|
52
|
+
gemlist_file = File.join(out_file_path,"gemlist.log")
|
53
|
+
if (File.file?(gemlist_file) && File.readable?(gemlist_file)) then
|
54
|
+
f = File.open(gemlist_file,"r");
|
55
|
+
|
56
|
+
while (gemx=f.gets) do
|
57
|
+
|
58
|
+
pending <<gemx.strip
|
59
|
+
end
|
60
|
+
else
|
61
|
+
puts "cant open gemlist file"
|
62
|
+
return
|
63
|
+
end
|
64
|
+
|
65
|
+
puts "-----------------------------------------------------------","direct dependencies ... #{pending.size}","-----------------------------------------------------------";
|
66
|
+
|
67
|
+
until pending.empty? do
|
68
|
+
full_name = pending.shift
|
69
|
+
|
70
|
+
spec = Gem::SourceIndex.load_specification spec_path(full_name)
|
71
|
+
|
72
|
+
if spec.nil? then
|
73
|
+
complain "Could not find gem #{full_name}, try using the full name"
|
74
|
+
next
|
75
|
+
end
|
76
|
+
fgl.puts "gem '#{spec.name}','=#{spec.version}'" unless locked[spec.name]
|
77
|
+
say "gem '#{spec.name}', '= #{spec.version}'" unless locked[spec.name]
|
78
|
+
locked[spec.name] = true
|
79
|
+
|
80
|
+
spec.runtime_dependencies.each do |dep|
|
81
|
+
next if locked[dep.name]
|
82
|
+
candidates = Gem.source_index.search dep
|
83
|
+
|
84
|
+
if candidates.empty? then
|
85
|
+
complain "Unable to satisfy '#{dep}' from currently installed gems"
|
86
|
+
else
|
87
|
+
pending << candidates.last.full_name
|
88
|
+
end
|
89
|
+
end
|
90
|
+
end
|
91
|
+
fgl.close
|
92
|
+
puts "-----------------------------------------------------------","gem Lockdown file: #{File.join(out_file_path, "gem_lockdown.rb")}","-----------------------------------------------------------";
|
93
|
+
|
94
|
+
end
|
95
|
+
|
96
|
+
def spec_path(gem_full_name)
|
97
|
+
gemspecs = Gem.path.map do |path|
|
98
|
+
File.join path, "specifications", "#{gem_full_name}.gemspec"
|
99
|
+
end
|
100
|
+
|
101
|
+
gemspecs.find { |gemspec| File.exist? gemspec }
|
102
|
+
end
|
103
|
+
|
104
|
+
end
|
105
|
+
|
106
|
+
class Whichgem < Gem::Command
|
107
|
+
|
108
|
+
EXT = %w[.rb .rbw .so .dll .bundle] # HACK
|
109
|
+
|
110
|
+
def initialize
|
111
|
+
super 'which', 'Find the location of a library file you can require',
|
112
|
+
:search_gems_first => false, :show_all => false
|
113
|
+
|
114
|
+
add_option '-a', '--[no-]all', 'show all matching files' do |show_all, options|
|
115
|
+
options[:show_all] = show_all
|
116
|
+
end
|
117
|
+
|
118
|
+
add_option '-g', '--[no-]gems-first',
|
119
|
+
'search gems before non-gems' do |gems_first, options|
|
120
|
+
options[:search_gems_first] = gems_first
|
121
|
+
|
122
|
+
end
|
123
|
+
end
|
124
|
+
|
125
|
+
def arguments # :nodoc:
|
126
|
+
"FILE name of file to find"
|
127
|
+
end
|
128
|
+
|
129
|
+
def defaults_str # :nodoc:
|
130
|
+
"--no-gems-first --no-all"
|
131
|
+
end
|
132
|
+
|
133
|
+
def usage # :nodoc:
|
134
|
+
"#{program_name} FILE [FILE ...]"
|
135
|
+
end
|
136
|
+
|
137
|
+
def execute (file_list, file_path)
|
138
|
+
searcher = Gem::GemPathSearcher.new
|
139
|
+
fgl = File.open(File.join(file_path,"gemlist.log"), "a");
|
140
|
+
ferr= File.open(File.join(file_path,"errors.log"),"a");
|
141
|
+
flib= File.open(File.join(file_path,"libfiles.log"), "a");
|
142
|
+
#puts options[:args]
|
143
|
+
|
144
|
+
file_list.each do |arg|
|
145
|
+
dirs = $LOAD_PATH
|
146
|
+
spec = searcher.find arg
|
147
|
+
|
148
|
+
if spec then
|
149
|
+
if options[:search_gems_first] then
|
150
|
+
dirs = gem_paths(spec) + $LOAD_PATH
|
151
|
+
else
|
152
|
+
dirs = $LOAD_PATH + gem_paths(spec)
|
153
|
+
end
|
154
|
+
fgl.puts "#{spec.full_name}"
|
155
|
+
end
|
156
|
+
|
157
|
+
paths = find_paths arg, dirs
|
158
|
+
|
159
|
+
if paths.empty? then
|
160
|
+
ferr.puts "#{arg} : Can't find ruby library file in $LOAD_PATH/Corresponding Gem is not installed"
|
161
|
+
else
|
162
|
+
|
163
|
+
flib.puts paths
|
164
|
+
end
|
165
|
+
end
|
166
|
+
fgl.close;ferr.close;flib.close;
|
167
|
+
end
|
168
|
+
|
169
|
+
def find_paths(package_name, dirs)
|
170
|
+
result = []
|
171
|
+
|
172
|
+
dirs.each do |dir|
|
173
|
+
EXT.each do |ext|
|
174
|
+
full_path = File.join dir, "#{package_name}#{ext}"
|
175
|
+
if File.exist? full_path then
|
176
|
+
result << full_path
|
177
|
+
end
|
178
|
+
end
|
179
|
+
end
|
180
|
+
|
181
|
+
result
|
182
|
+
end
|
183
|
+
|
184
|
+
def gem_paths(spec)
|
185
|
+
spec.require_paths.collect { |d| File.join spec.full_gem_path, d }
|
186
|
+
end
|
187
|
+
|
188
|
+
def usage # :nodoc:
|
189
|
+
"#{program_name} FILE [...]"
|
190
|
+
end
|
191
|
+
|
192
|
+
end
|
193
|
+
|
194
|
+
|
195
|
+
|
196
|
+
class Grepgems
|
197
|
+
def initialize
|
198
|
+
@code_path = ARGV
|
199
|
+
@tmp_files =['gemlist.log','libfiles.log','errors.log']
|
200
|
+
purge_tempfiles;
|
201
|
+
@which_cmd = Whichgem.new;
|
202
|
+
@lock_cmd=LockCommand.new;
|
203
|
+
@out_file_path = Dir.pwd;
|
204
|
+
end
|
205
|
+
def description # :nodoc:
|
206
|
+
puts "
|
207
|
+
gemlocker [DIR1] [DIR2] [DIR3] [DIR......
|
208
|
+
Please supply at least one directory path.
|
209
|
+
|
210
|
+
USES OF GEMLOCKER:
|
211
|
+
-----------------------------------
|
212
|
+
1. To list all dependencies - useful while building a gem/ rake file
|
213
|
+
2. To avoid problems with new versions of gems by loading the required versions of gem; read below for more details.
|
214
|
+
|
215
|
+
|
216
|
+
More details..
|
217
|
+
--------------
|
218
|
+
The gemlocker command will generate a list of +gem+ statements that will lock down
|
219
|
+
the versions for the gem used in the files of the given paths in the command line. It will specify exact
|
220
|
+
versions in the requirements list to ensure that the gems loaded will always
|
221
|
+
be consistent. A full recursive search of all effected gems will be
|
222
|
+
generated.
|
223
|
+
It generates 4 files
|
224
|
+
gemlist.log; errors.log; libfiles.log; and gem_lockdown.rb
|
225
|
+
gemlist.log: contains all lib files used in the files of given path;
|
226
|
+
errors.log : contains all errors - Normally user defined lib files etc..
|
227
|
+
libfiles.log : lists all lib files-paths
|
228
|
+
gem_lockdown.rb : contains all gems and their latest versions.
|
229
|
+
|
230
|
+
It is similar to gem lock command; where gemlock generates lock down list for a given gem;
|
231
|
+
and gemlock generates lock down list for all gems used in a directory (of files.)
|
232
|
+
|
233
|
+
Example:
|
234
|
+
---------
|
235
|
+
gemlocker /home/us/progdir . ..
|
236
|
+
|
237
|
+
will list out all dependencies used in your projects located in /home/us/progdir , current directory, .. and all their subdirectories;
|
238
|
+
in gem_lockdown.rb of command invokation directory by looking at the 'require' statements/lib files in the given paths and their subdirectories
|
239
|
+
|
240
|
+
|
241
|
+
require 'rubygems'
|
242
|
+
gem 'rails', '= 1.0.0'
|
243
|
+
gem 'rake', '= 0.7.0.1'
|
244
|
+
gem 'activesupport', '= 1.2.5'
|
245
|
+
gem 'activerecord', '= 1.13.2'
|
246
|
+
gem 'actionpack', '= 1.11.2'
|
247
|
+
gem 'actionmailer', '= 1.1.5'
|
248
|
+
gem 'actionwebservice', '= 1.0.0'
|
249
|
+
|
250
|
+
Just load gem_lockdown.rb from your application to ensure that the currect
|
251
|
+
versions are loaded. Make sure that lockdown.rb is loaded *before* any
|
252
|
+
other require statements.
|
253
|
+
|
254
|
+
Note : if you are not using latest versions of gems in your files(project), you may have to edit gem_lockdown.rb to load the desired versions.
|
255
|
+
-----
|
256
|
+
Example Scenario: If you are using activerecord-1.0.2 and your system is installed with activerecord-2.2.3 then gem_lockdown.rb will show only 2.2.3;
|
257
|
+
so, you will have to edit the gem_lockdown.rb to modify the version of activerecord to 1.0.2
|
258
|
+
|
259
|
+
"
|
260
|
+
end
|
261
|
+
|
262
|
+
def grep_libfiles
|
263
|
+
libs=[]
|
264
|
+
@code_path.each { |p|
|
265
|
+
rbfiles = File.join(p,"**", "*.*")
|
266
|
+
Dir.glob(rbfiles) {|file| #puts file;
|
267
|
+
f=File.open(file,"r") if File.file?(File.expand_path(file));
|
268
|
+
if f then
|
269
|
+
while(row = f.gets)
|
270
|
+
row.scan(/require\s\'\w+\'/) {|m| s=m.split("'"); libs<<s.last;} # getting single quoted requires
|
271
|
+
row.scan(/require\s\"\w+\"/) {|m| s= m.split('"'); libs <<s.last;} # gettin double quoted requires
|
272
|
+
row.scan(/rrequire\s\'\w+\'/) {|m| s=m.split("'"); libs<<s.last;} # get command line requires
|
273
|
+
row.scan(/gem\s\'\w+\'/) {|m| s=m.split("'"); libs<<s.last;} # get external gem requires.
|
274
|
+
end
|
275
|
+
f.close
|
276
|
+
end
|
277
|
+
|
278
|
+
}
|
279
|
+
}
|
280
|
+
puts "-----------------------","list of requires", "-----------------------",libs.join( ' ');
|
281
|
+
@lock_cmd.execute(@out_file_path,@which_cmd.execute(libs,@out_file_path));
|
282
|
+
end
|
283
|
+
def purge_tempfiles
|
284
|
+
@tmp_files.each {|f| File.delete(f) if File.file?(f) ;}
|
285
|
+
end;
|
286
|
+
|
287
|
+
|
288
|
+
end;
|
289
|
+
|
290
|
+
s = Grepgems.new;
|
291
|
+
if ARGV.size == 0 or ARGV[0]=='--help' then
|
292
|
+
puts ARGV
|
293
|
+
puts " -------Usage -----"
|
294
|
+
s.description;
|
295
|
+
else
|
296
|
+
s.grep_libfiles;
|
297
|
+
end;
|
298
|
+
|
299
|
+
|
300
|
+
|
data/doc/README.TXT
ADDED
@@ -0,0 +1,53 @@
|
|
1
|
+
|
2
|
+
gemlocker [DIR1] [DIR2] [DIR3] [DIR......
|
3
|
+
Please supply at least one directory path.
|
4
|
+
|
5
|
+
USES OF GEMLOCKER:
|
6
|
+
-----------------------------------
|
7
|
+
1. To list all dependencies - useful while building a gem/ rake file
|
8
|
+
2. To avoid problems with new versions of gems by loading the required versions of gem; read below for more details.
|
9
|
+
|
10
|
+
|
11
|
+
The gemlocker command will generate a list of +gem+ statements that will lock down
|
12
|
+
the versions for the gem used in the files of the given paths in the command line. It will specify exact
|
13
|
+
versions in the requirements list to ensure that the gems loaded will always
|
14
|
+
be consistent. A full recursive search of all effected gems will be
|
15
|
+
generated.
|
16
|
+
It generates 4 files
|
17
|
+
gemlist.log; errors.log; libfiles.log; and gem_lockdown.rb
|
18
|
+
gemlist.log: contains all lib files used in the files of given path;
|
19
|
+
errors.log : contains all errors - Normally user defined lib files etc..
|
20
|
+
libfiles.log : lists all lib files-paths
|
21
|
+
gem_lockdown.rb : contains all gems and their latest versions.
|
22
|
+
|
23
|
+
It is similar to gem lock command; where gemlock generates lock down list for a given gem;
|
24
|
+
and gemlock generates lock down list for all gems used in a directory (of files.)
|
25
|
+
|
26
|
+
Example:
|
27
|
+
|
28
|
+
gemlocker /home/us/progdir . ..
|
29
|
+
|
30
|
+
will list out all dependencies used in your projects located in /home/us/progdir , current directory, .. and all their subdirectories;
|
31
|
+
in gem_lockdown.rb of command invokation directory by looking at the "require" statements/lib files in the given paths and their subdirectories
|
32
|
+
|
33
|
+
gem_lockdown.rb will look like below
|
34
|
+
|
35
|
+
require 'rubygems'
|
36
|
+
gem 'rails', '= 1.0.0'
|
37
|
+
gem 'rake', '= 0.7.0.1'
|
38
|
+
gem 'activesupport', '= 1.2.5'
|
39
|
+
gem 'activerecord', '= 1.13.2'
|
40
|
+
gem 'actionpack', '= 1.11.2'
|
41
|
+
gem 'actionmailer', '= 1.1.5'
|
42
|
+
gem 'actionwebservice', '= 1.0.0'
|
43
|
+
|
44
|
+
Just load gem_lockdown.rb from your application to ensure that the currect
|
45
|
+
versions are loaded. Make sure that lockdown.rb is loaded *before* any
|
46
|
+
other require statements.
|
47
|
+
|
48
|
+
Note : if you are not using latest versions of gems in your files(project), you may have to edit gem_lockdown.rb to load the desired versions.
|
49
|
+
-------
|
50
|
+
Example Scenario: If you are using activerecord-1.0.2 and your system is installed with activerecord-2.2.3 then gem_lockdown.rb will show only 2.2.3;
|
51
|
+
so, you will have to edit the gem_lockdown.rb to modify the version of activerecord to 1.0.2
|
52
|
+
|
53
|
+
|
data/lib/gemlocker.rb
ADDED
@@ -0,0 +1,298 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
require 'rubygems'
|
3
|
+
require 'fileutils'
|
4
|
+
require 'rubygems/command'
|
5
|
+
require 'rubygems/gem_path_searcher'
|
6
|
+
|
7
|
+
|
8
|
+
class LockCommand < Gem::Command
|
9
|
+
|
10
|
+
def initialize
|
11
|
+
super 'lock', 'Generate a lockdown list of gems',
|
12
|
+
:strict => false
|
13
|
+
|
14
|
+
add_option '-s', '--[no-]strict',
|
15
|
+
'fail if unable to satisfy a dependency' do |strict, options|
|
16
|
+
options[:strict] = strict
|
17
|
+
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
|
22
|
+
def arguments # :nodoc:
|
23
|
+
"GEMNAME name of gem to lock\nVERSION version of gem to lock"
|
24
|
+
end
|
25
|
+
|
26
|
+
def defaults_str # :nodoc:
|
27
|
+
"--no-strict"
|
28
|
+
end
|
29
|
+
|
30
|
+
def usage # :nodoc:
|
31
|
+
"#{program_name} GEMNAME-VERSION [GEMNAME-VERSION ...]"
|
32
|
+
end
|
33
|
+
|
34
|
+
def complain(message)
|
35
|
+
if options[:strict] then
|
36
|
+
raise Gem::Exception, message
|
37
|
+
else
|
38
|
+
say "# #{message}"
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
def execute(out_file_path,x)
|
43
|
+
|
44
|
+
fgl = File.open(File.join(out_file_path, "gem_lockdown.rb"), "w");
|
45
|
+
if !fgl then
|
46
|
+
say " gem_lockdown.rb is not writable";
|
47
|
+
else
|
48
|
+
fgl.puts"require 'rubygems'"
|
49
|
+
end
|
50
|
+
pending = [];
|
51
|
+
locked = {}
|
52
|
+
gemlist_file = File.join(out_file_path,"gemlist.log")
|
53
|
+
if (File.file?(gemlist_file) && File.readable?(gemlist_file)) then
|
54
|
+
f = File.open(gemlist_file,"r");
|
55
|
+
|
56
|
+
while (gemx=f.gets) do
|
57
|
+
|
58
|
+
pending <<gemx.strip
|
59
|
+
end
|
60
|
+
else
|
61
|
+
puts "cant open gemlist file"
|
62
|
+
return
|
63
|
+
end
|
64
|
+
|
65
|
+
puts "-----------------------------------------------------------","direct dependencies ... #{pending.size}","-----------------------------------------------------------";
|
66
|
+
|
67
|
+
until pending.empty? do
|
68
|
+
full_name = pending.shift
|
69
|
+
|
70
|
+
spec = Gem::SourceIndex.load_specification spec_path(full_name)
|
71
|
+
|
72
|
+
if spec.nil? then
|
73
|
+
complain "Could not find gem #{full_name}, try using the full name"
|
74
|
+
next
|
75
|
+
end
|
76
|
+
fgl.puts "gem '#{spec.name}','=#{spec.version}'" unless locked[spec.name]
|
77
|
+
say "gem '#{spec.name}', '= #{spec.version}'" unless locked[spec.name]
|
78
|
+
locked[spec.name] = true
|
79
|
+
|
80
|
+
spec.runtime_dependencies.each do |dep|
|
81
|
+
next if locked[dep.name]
|
82
|
+
candidates = Gem.source_index.search dep
|
83
|
+
|
84
|
+
if candidates.empty? then
|
85
|
+
complain "Unable to satisfy '#{dep}' from currently installed gems"
|
86
|
+
else
|
87
|
+
pending << candidates.last.full_name
|
88
|
+
end
|
89
|
+
end
|
90
|
+
end
|
91
|
+
fgl.close
|
92
|
+
puts "-----------------------------------------------------------","gem Lockdown file: #{File.join(out_file_path, "gem_lockdown.rb")}","-----------------------------------------------------------";
|
93
|
+
|
94
|
+
end
|
95
|
+
|
96
|
+
def spec_path(gem_full_name)
|
97
|
+
gemspecs = Gem.path.map do |path|
|
98
|
+
File.join path, "specifications", "#{gem_full_name}.gemspec"
|
99
|
+
end
|
100
|
+
|
101
|
+
gemspecs.find { |gemspec| File.exist? gemspec }
|
102
|
+
end
|
103
|
+
|
104
|
+
end
|
105
|
+
|
106
|
+
class Whichgem < Gem::Command
|
107
|
+
|
108
|
+
EXT = %w[.rb .rbw .so .dll .bundle] # HACK
|
109
|
+
|
110
|
+
def initialize
|
111
|
+
super 'which', 'Find the location of a library file you can require',
|
112
|
+
:search_gems_first => false, :show_all => false
|
113
|
+
|
114
|
+
add_option '-a', '--[no-]all', 'show all matching files' do |show_all, options|
|
115
|
+
options[:show_all] = show_all
|
116
|
+
end
|
117
|
+
|
118
|
+
add_option '-g', '--[no-]gems-first',
|
119
|
+
'search gems before non-gems' do |gems_first, options|
|
120
|
+
options[:search_gems_first] = gems_first
|
121
|
+
|
122
|
+
end
|
123
|
+
end
|
124
|
+
|
125
|
+
def arguments # :nodoc:
|
126
|
+
"FILE name of file to find"
|
127
|
+
end
|
128
|
+
|
129
|
+
def defaults_str # :nodoc:
|
130
|
+
"--no-gems-first --no-all"
|
131
|
+
end
|
132
|
+
|
133
|
+
def usage # :nodoc:
|
134
|
+
"#{program_name} FILE [FILE ...]"
|
135
|
+
end
|
136
|
+
|
137
|
+
def execute (file_list, file_path)
|
138
|
+
searcher = Gem::GemPathSearcher.new
|
139
|
+
fgl = File.open(File.join(file_path,"gemlist.log"), "a");
|
140
|
+
ferr= File.open(File.join(file_path,"errors.log"),"a");
|
141
|
+
flib= File.open(File.join(file_path,"libfiles.log"), "a");
|
142
|
+
#puts options[:args]
|
143
|
+
|
144
|
+
file_list.each do |arg|
|
145
|
+
dirs = $LOAD_PATH
|
146
|
+
spec = searcher.find arg
|
147
|
+
|
148
|
+
if spec then
|
149
|
+
if options[:search_gems_first] then
|
150
|
+
dirs = gem_paths(spec) + $LOAD_PATH
|
151
|
+
else
|
152
|
+
dirs = $LOAD_PATH + gem_paths(spec)
|
153
|
+
end
|
154
|
+
fgl.puts "#{spec.full_name}"
|
155
|
+
end
|
156
|
+
|
157
|
+
paths = find_paths arg, dirs
|
158
|
+
|
159
|
+
if paths.empty? then
|
160
|
+
ferr.puts "#{arg} : Can't find ruby library file in $LOAD_PATH/Corresponding Gem is not installed"
|
161
|
+
else
|
162
|
+
|
163
|
+
flib.puts paths
|
164
|
+
end
|
165
|
+
end
|
166
|
+
fgl.close;ferr.close;flib.close;
|
167
|
+
end
|
168
|
+
|
169
|
+
def find_paths(package_name, dirs)
|
170
|
+
result = []
|
171
|
+
|
172
|
+
dirs.each do |dir|
|
173
|
+
EXT.each do |ext|
|
174
|
+
full_path = File.join dir, "#{package_name}#{ext}"
|
175
|
+
if File.exist? full_path then
|
176
|
+
result << full_path
|
177
|
+
end
|
178
|
+
end
|
179
|
+
end
|
180
|
+
|
181
|
+
result
|
182
|
+
end
|
183
|
+
|
184
|
+
def gem_paths(spec)
|
185
|
+
spec.require_paths.collect { |d| File.join spec.full_gem_path, d }
|
186
|
+
end
|
187
|
+
|
188
|
+
def usage # :nodoc:
|
189
|
+
"#{program_name} FILE [...]"
|
190
|
+
end
|
191
|
+
|
192
|
+
end
|
193
|
+
|
194
|
+
|
195
|
+
|
196
|
+
class Grepgems
|
197
|
+
def initialize
|
198
|
+
@code_path = ARGV
|
199
|
+
@tmp_files =['gemlist.log','libfiles.log','errors.log']
|
200
|
+
purge_tempfiles;
|
201
|
+
@which_cmd = Whichgem.new;
|
202
|
+
@lock_cmd=LockCommand.new;
|
203
|
+
@out_file_path = Dir.pwd;
|
204
|
+
end
|
205
|
+
def description # :nodoc:
|
206
|
+
puts "
|
207
|
+
-------Usage -----
|
208
|
+
gemlocker [DIR1] [DIR2] [DIR3] [DIR......
|
209
|
+
Please supply at least one directory path.
|
210
|
+
|
211
|
+
USES OF GEMLOCKER:
|
212
|
+
-----------------
|
213
|
+
1. To avoid problems with new versions of a gem by loading a specific versions of gem;
|
214
|
+
2. To list all dependencies - useful while building a gem/ rake file
|
215
|
+
|
216
|
+
More details..
|
217
|
+
--------------
|
218
|
+
The gemlocker command will generate a list of +gem+ statements that will lock down
|
219
|
+
the versions for the gem used in the files of the given paths in the command line. It will specify exact
|
220
|
+
versions in the requirements list to ensure that the gems loaded will always
|
221
|
+
be consistent. A full recursive search of all effected gems will be
|
222
|
+
generated.
|
223
|
+
It generates 4 files
|
224
|
+
gemlist.log; errors.log; libfiles.log; and gem_lockdown.rb
|
225
|
+
gemlist.log: contains all lib files used in the files of given path;
|
226
|
+
errors.log : contains all errors - Normally user defined lib files etc..
|
227
|
+
libfiles.log : lists all lib files-paths
|
228
|
+
gem_lockdown.rb : contains all gems and their latest versions.
|
229
|
+
|
230
|
+
It is similar to gem lock command; where gemlock generates lock down list for a given gem;
|
231
|
+
and gemlock generates lock down list for all gems used in a directory (of files.)
|
232
|
+
|
233
|
+
Example:
|
234
|
+
|
235
|
+
gemlocker /home/us/progdir . ..
|
236
|
+
|
237
|
+
will list out all dependencies in gem_lockdown.rb in invokation directory by looking at the 'require' statements/lib files used in your projects located in /home/us/progdir , current directory, .. and all their subdirectories;
|
238
|
+
gem_lockdown.rb will look like below
|
239
|
+
|
240
|
+
require 'rubygems'
|
241
|
+
gem 'rails', '= 1.0.0'
|
242
|
+
gem 'rake', '= 0.7.0.1'
|
243
|
+
gem 'activesupport', '= 1.2.5'
|
244
|
+
gem 'activerecord', '= 1.13.2'
|
245
|
+
gem 'actionpack', '= 1.11.2'
|
246
|
+
gem 'actionmailer', '= 1.1.5'
|
247
|
+
gem 'actionwebservice', '= 1.0.0'
|
248
|
+
|
249
|
+
Just load gem_lockdown.rb from your application to ensure that the currect
|
250
|
+
versions are loaded. Make sure that lockdown.rb is loaded *before* any
|
251
|
+
other require statements.
|
252
|
+
|
253
|
+
Note : if you are not using latest versions of gems in your files(project), you may have to edit gem_lockdown.rb to load the desired versions.
|
254
|
+
example scenario: If you are using activerecord-1.0.2 and your system is installed with activerecord-2.2.3 then gem_lockdown.rb will show only 2.2.3;
|
255
|
+
so, you will have to edit the gem_lockdown.rb to modify the version of activerecord to 1.0.2
|
256
|
+
|
257
|
+
"
|
258
|
+
end
|
259
|
+
|
260
|
+
def grep_libfiles
|
261
|
+
libs=[]
|
262
|
+
@code_path.each { |p|
|
263
|
+
rbfiles = File.join(p,"**", "*.*")
|
264
|
+
Dir.glob(rbfiles) {|file| #puts file;
|
265
|
+
f=File.open(file,"r") if File.file?(File.expand_path(file));
|
266
|
+
if f then
|
267
|
+
while(row = f.gets)
|
268
|
+
row.scan(/require\s\'\w+\'/) {|m| s=m.split("'"); libs<<s.last;} # getting single quoted requires
|
269
|
+
row.scan(/require\s\"\w+\"/) {|m| s= m.split('"'); libs <<s.last;} # gettin double quoted requires
|
270
|
+
row.scan(/rrequire\s\'\w+\'/) {|m| s=m.split("'"); libs<<s.last;} # get command line requires
|
271
|
+
row.scan(/gem\s\'\w+\'/) {|m| s=m.split("'"); libs<<s.last;} # get external gem requires.
|
272
|
+
end
|
273
|
+
f.close
|
274
|
+
end
|
275
|
+
|
276
|
+
}
|
277
|
+
}
|
278
|
+
puts "-----------------------","list of requires", "-----------------------",libs.join( ' ');
|
279
|
+
@lock_cmd.execute(@out_file_path,@which_cmd.execute(libs,@out_file_path));
|
280
|
+
end
|
281
|
+
def purge_tempfiles
|
282
|
+
@tmp_files.each {|f| File.delete(f) if File.file?(f) ;}
|
283
|
+
end;
|
284
|
+
|
285
|
+
|
286
|
+
end;
|
287
|
+
|
288
|
+
s = Grepgems.new;
|
289
|
+
if ARGV.size == 0 or ARGV[0]=='--help' then
|
290
|
+
puts ARGV
|
291
|
+
puts " -------Usage -----"
|
292
|
+
s.description;
|
293
|
+
else
|
294
|
+
s.grep_libfiles;
|
295
|
+
end;
|
296
|
+
|
297
|
+
|
298
|
+
|
metadata
ADDED
@@ -0,0 +1,55 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: gemlocker
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Sarat Kumar
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
|
12
|
+
date: 2009-01-13 00:00:00 -08:00
|
13
|
+
default_executable:
|
14
|
+
dependencies: []
|
15
|
+
|
16
|
+
description: To geneate/list of all gems and there versions used in a given directory of ruby files
|
17
|
+
email: skumar@attinteractive.com
|
18
|
+
executables:
|
19
|
+
- gemlocker
|
20
|
+
extensions: []
|
21
|
+
|
22
|
+
extra_rdoc_files:
|
23
|
+
- doc/README.TXT
|
24
|
+
files:
|
25
|
+
- lib/gemlocker.rb
|
26
|
+
- bin/gemlocker
|
27
|
+
- doc/README.TXT
|
28
|
+
has_rdoc: true
|
29
|
+
homepage: Yellowpages.com
|
30
|
+
post_install_message:
|
31
|
+
rdoc_options: []
|
32
|
+
|
33
|
+
require_paths:
|
34
|
+
- lib
|
35
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
36
|
+
requirements:
|
37
|
+
- - ">="
|
38
|
+
- !ruby/object:Gem::Version
|
39
|
+
version: "0"
|
40
|
+
version:
|
41
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
42
|
+
requirements:
|
43
|
+
- - ">="
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
version: "0"
|
46
|
+
version:
|
47
|
+
requirements: []
|
48
|
+
|
49
|
+
rubyforge_project:
|
50
|
+
rubygems_version: 1.3.1
|
51
|
+
signing_key:
|
52
|
+
specification_version: 2
|
53
|
+
summary: To geneate/list of all gems and there versions used in a given directory of ruby files
|
54
|
+
test_files: []
|
55
|
+
|