gem_file_conflict_checker 0.2.1

Sign up to get free protection for your applications and to get access to all the features.
data/.document ADDED
@@ -0,0 +1,5 @@
1
+ README.rdoc
2
+ lib/**/*.rb
3
+ bin/*
4
+ features/**/*.feature
5
+ LICENSE
data/.gitignore ADDED
@@ -0,0 +1,21 @@
1
+ ## MAC OS
2
+ .DS_Store
3
+
4
+ ## TEXTMATE
5
+ *.tmproj
6
+ tmtags
7
+
8
+ ## EMACS
9
+ *~
10
+ \#*
11
+ .\#*
12
+
13
+ ## VIM
14
+ *.swp
15
+
16
+ ## PROJECT::GENERAL
17
+ coverage
18
+ rdoc
19
+ pkg
20
+
21
+ ## PROJECT::SPECIFIC
data/LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2009 rdp
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.rdoc ADDED
@@ -0,0 +1,68 @@
1
+ = gem_conflict_plugin
2
+
3
+ This is a rubygems plugin that warns warn you when you accidentally install gems that have filenames that collide and hence are unstable.
4
+
5
+ Background:
6
+
7
+ Currently with rubygems (1.3.5), if you install two gems that have same-named files, like
8
+
9
+ gem1/lib/a.rb
10
+
11
+ gem2/lib/a.rb
12
+
13
+ Then do a
14
+
15
+ require 'rubygems'
16
+ require 'a'
17
+
18
+ There is no guarantee of *which* a it is going to load.
19
+
20
+ This can cause some really bizarre errors when, for example, in the middle of requiring gem1 gem, that gem does a
21
+
22
+ require 'a'
23
+
24
+ which ends up requiring a *from a totally different, unexpected, other gem*, like gem2.
25
+
26
+ This can lead to unrelated looking errors, like
27
+
28
+ 'undefined method `sexp_type' for class `Sexp' (NameError)'
29
+
30
+ or 'undefined constants Sane::OS'
31
+
32
+ which really aren't helpful to deciphering the root cause (that you have conflicting gems installed).
33
+
34
+ =============== What this gem does
35
+
36
+ This gem creates a rubygems post_install hook that sanity checks your gems, looking for any files that could possibly conflict. If there is a conflict, it outputs a warning message to the screen about it.
37
+
38
+ ex:
39
+
40
+ E:\>gem install require_all
41
+ warning: gem_conflict_plugin: conflicts detected! (they may be expected) your rubygems have one or more gems with conflicting lib/* filenames...
42
+ "require_all" was found redundantly in the libs of these gems: rdp-require_all (lib/require_all.rb), require_all (lib/require_all.rb)
43
+
44
+
45
+ In this example two gems were installed with conflicting (competing) filenames--require_all.rb was found in rdp-require_all and require_all.
46
+
47
+ The post install hook warned me of the problem, and I promptly uninstalled the one I didn't want so that there would be no confusion.
48
+
49
+ ================== Usage/Installation
50
+
51
+ $ gem install gem_file_conflict_checker
52
+ $ gem install gem_file_conflict_checker
53
+ # install it twice so that it will run its post install hooks and warn you of any conflicts. Any gem install after this point will also warn you.
54
+
55
+
56
+ This is especially useful for those of us who are using various versions of gems and forking them and installing our own versions, etc., to sanity check which gems are installed. It is hoped that a future version of rubygems will alleviate this problem, and patches have been proposed [1].
57
+
58
+ Enjoy.
59
+
60
+ -r
61
+
62
+ Feedback welcome:
63
+ http://github.com/rdp/gem_file_conflict_checker
64
+
65
+ refs:
66
+
67
+ [1] http://rubyforge.org/tracker/index.php?func=detail&aid=27318&group_id=126&atid=578
68
+ http://www.ruby-forum.com/topic/190217
data/Rakefile ADDED
@@ -0,0 +1,11 @@
1
+ require 'rubygems'
2
+
3
+ require 'jeweler'
4
+ Jeweler::Tasks.new do |gem|
5
+ gem.name = "gem_file_conflict_checker"
6
+ gem.summary = %Q{A gem plugin to warn you when you accidentally install files with names that collide accidentally}
7
+ gem.email = "rogerpack2005@gmail.com"
8
+ gem.homepage = "http://github.com/rdp/gem_file_conflict_checker"
9
+ gem.authors = ["rdp"]
10
+ end
11
+ Jeweler::GemcutterTasks.new
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 0.2.1
@@ -0,0 +1,56 @@
1
+ class ConflictChecker
2
+
3
+ # check some files
4
+ # expects input like
5
+ # :lib1 => 'lib/file1.rb',
6
+ # :lib2 => 'lib/file2.rb'
7
+ def check names_with_files
8
+ existing_list = {}
9
+ conflict_list = {}
10
+
11
+ for name, files in names_with_files
12
+ for file in files
13
+ orig_file = file.dup
14
+ file = file.split('/')[1..-1].join('/') # strip off lib/
15
+
16
+
17
+ if file =~ /_plugin.rb$/ # ignore lib/rubygems_plugin.rb, which *can* be redundant across gems
18
+ next
19
+ end
20
+
21
+ if file =~ /(.rb|.so)$/
22
+ file = file.split('.')[0..-2].join('.') # strip off .rb .so
23
+ else
24
+ next # skip directories...
25
+ end
26
+
27
+ if existing_list[file]
28
+ # add it to the bad list
29
+ if conflict_list[file]
30
+ conflict_list[file] << [name, orig_file] # add it to the list...
31
+ else
32
+ conflict_list[file] = [existing_list[file], [name, orig_file]]
33
+ end
34
+ end
35
+ existing_list[file] = [name, orig_file]
36
+ end
37
+ end
38
+ conflict_list
39
+ end
40
+
41
+ def self.do_all_gems
42
+ all = {}; Gem.source_index.latest_specs.map{|s| all[s.name] = s.lib_files}
43
+ collisions = ConflictChecker.new.check all
44
+ if collisions.length > 0
45
+ puts "warning: gem_conflict_plugin: conflicts detected! (they may be expected) your rubygems have one or more gems with conflicting lib/* filenames..."
46
+ for filename, gems in collisions
47
+ print " \"#{filename}\" was found redundantly in the libs of these gems: "
48
+ puts gems.map{|gem_name, file_name| "#{gem_name} (#{file_name})"}.join(', ')
49
+ end
50
+ puts
51
+ else
52
+ puts "all clean--your rubygems has no reported conflicting filenames"
53
+ end
54
+ collisions
55
+ end
56
+ end
@@ -0,0 +1,4 @@
1
+ Gem.post_install {
2
+ require 'conflict_checker'
3
+ ConflictChecker.do_all_gems
4
+ }
@@ -0,0 +1,62 @@
1
+ require 'spec/autorun'
2
+ require 'sane'
3
+ require __dir__ + '/../lib/conflict_checker'
4
+ require 'rubygems'
5
+
6
+ describe "conflict plugin" do
7
+
8
+ before do
9
+ @a = ConflictChecker.new
10
+ Gem.clear_paths
11
+ end
12
+
13
+ it "should alert you of potential conflicts" do
14
+ conflict = {:lib1 => ['lib/go.rb'], :lib2 => ['lib/go.rb']}
15
+ @a.check(conflict).should == {"go"=>[[:lib1, "lib/go.rb"], [:lib2, "lib/go.rb"]]}
16
+ end
17
+
18
+ =begin example
19
+ # pp Gem.source_index.latest_specs[0].lib_files
20
+ ["lib/map_reduce",
21
+ "lib/map_reduce.rb",
22
+ "lib/starfish.rb",
23
+ "lib/map_reduce/active_record.rb",
24
+ "lib/map_reduce/array.rb",
25
+ "lib/map_reduce/file.rb"]
26
+ =end
27
+
28
+ it "should also do subdir clashes" do
29
+ conflict = {:lib1 => ['lib/y/go.rb'], :lib2 => ['lib/y/go.rb']}
30
+ @a.check(conflict).should == {"y/go"=>[[:lib1, "lib/y/go.rb"], [:lib2, "lib/y/go.rb"]]}
31
+ end
32
+
33
+ it "should work with non lib directories" do
34
+ pending "request"
35
+ end
36
+
37
+ it "should pass back a hash" do
38
+ ConflictChecker.do_all_gems.should be_a(Hash)
39
+ end
40
+
41
+ it "should detect collisions between .rb and .so" do
42
+ conflict = {:lib1 => ['lib/y/go.so'], :lib2 => ['lib/y/go.rb']}
43
+ @a.check(conflict).should == {"y/go"=>[[:lib1, "lib/y/go.so"], [:lib2, "lib/y/go.rb"]]}
44
+
45
+ end
46
+
47
+ it "should do triple collisions" do
48
+ conflict = {:lib1 => ['lib/go.rb'], :lib2 => ['lib/go.rb'], :lib3 => ['lib/go.rb']}
49
+ @a.check(conflict).should == {"go"=>[[:lib1, "lib/go.rb"], [:lib2, "lib/go.rb"], [:lib3, "lib/go.rb"]]}
50
+ end
51
+
52
+ it "should ignore directory looking entires" do
53
+ conflict = {:lib1 => ['lib/y/go.so'], :lib2 => ['lib/y/go']}
54
+ @a.check(conflict).should == {}
55
+ end
56
+
57
+ it "should ignore plugins which can be redundant" do
58
+ conflict = {:lib1 => ['lib/y/go_plugin.rb'], :lib2 => ['lib/y/go_plugin.rb']}
59
+ @a.check(conflict).should == {}
60
+ end
61
+
62
+ end
metadata ADDED
@@ -0,0 +1,64 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: gem_file_conflict_checker
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.2.1
5
+ platform: ruby
6
+ authors:
7
+ - rdp
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+
12
+ date: 2010-01-02 00:00:00 -07:00
13
+ default_executable:
14
+ dependencies: []
15
+
16
+ description:
17
+ email: rogerpack2005@gmail.com
18
+ executables: []
19
+
20
+ extensions: []
21
+
22
+ extra_rdoc_files:
23
+ - LICENSE
24
+ - README.rdoc
25
+ files:
26
+ - .document
27
+ - .gitignore
28
+ - LICENSE
29
+ - README.rdoc
30
+ - Rakefile
31
+ - VERSION
32
+ - lib/conflict_checker.rb
33
+ - lib/rubygems_plugin.rb
34
+ - spec/spec.gem_conflict_plugin.rb
35
+ has_rdoc: true
36
+ homepage: http://github.com/rdp/gem_file_conflict_checker
37
+ licenses: []
38
+
39
+ post_install_message:
40
+ rdoc_options:
41
+ - --charset=UTF-8
42
+ require_paths:
43
+ - lib
44
+ required_ruby_version: !ruby/object:Gem::Requirement
45
+ requirements:
46
+ - - ">="
47
+ - !ruby/object:Gem::Version
48
+ version: "0"
49
+ version:
50
+ required_rubygems_version: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: "0"
55
+ version:
56
+ requirements: []
57
+
58
+ rubyforge_project:
59
+ rubygems_version: 1.3.5
60
+ signing_key:
61
+ specification_version: 3
62
+ summary: A gem plugin to warn you when you accidentally install files with names that collide accidentally
63
+ test_files:
64
+ - spec/spec.gem_conflict_plugin.rb