gems-status 0.2.5 → 0.2.6
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/gem_simple.rb +33 -2
- data/lib/gems_status_metadata.rb +1 -1
- data/lib/lockfile_gems.rb +28 -2
- data/lib/not_rails_checker.rb +6 -17
- data/lib/ruby_gems_gems_gem_simple.rb +2 -2
- data/test/Gemfile.lock.test +5 -0
- data/test/test-lockfile_gems.rb +32 -4
- data/test/test-not_rails_checker.rb +54 -0
- metadata +4 -3
data/lib/gem_simple.rb
CHANGED
@@ -1,11 +1,42 @@
|
|
1
1
|
class GemSimple
|
2
|
-
attr_reader :name, :version, :md5, :origin, :gems_url
|
3
|
-
def initialize(name, version, md5, origin, gems_url=nil )
|
2
|
+
attr_reader :name, :version, :md5, :origin, :gems_url, :dependencies
|
3
|
+
def initialize(name, version, md5, origin, gems_url=nil, dependencies = nil )
|
4
4
|
@name = name
|
5
5
|
@version = version
|
6
6
|
@md5 = md5
|
7
7
|
@origin = origin
|
8
8
|
@gems_url = gems_url
|
9
|
+
@dependencies = dependencies
|
9
10
|
end
|
11
|
+
|
12
|
+
#TODO: write a test for this
|
13
|
+
def depends?(gem)
|
14
|
+
if !@dependencies
|
15
|
+
Utils::log_error("ERROR: trying to get depends on a gem that has no info on dependencies #{@name} depends #{gem.name}")
|
16
|
+
return false
|
17
|
+
end
|
18
|
+
@dependencies.each do |dep|
|
19
|
+
return true if dep.name == gem.name
|
20
|
+
end
|
21
|
+
return false
|
22
|
+
end
|
23
|
+
|
24
|
+
#TODO: write a test for this
|
25
|
+
def merge_deps(gem)
|
26
|
+
if !@dependencies || !gem.dependencies
|
27
|
+
Utils::log_error("ERROR: trying to merge depends on a gem that has no info on dependencies #{@name} merge #{gem.name}")
|
28
|
+
return false
|
29
|
+
end
|
30
|
+
changes = false
|
31
|
+
gem.dependencies.each do |dep|
|
32
|
+
if !@dependencies.include?(dep)
|
33
|
+
changes = true
|
34
|
+
@dependencies << dep
|
35
|
+
Utils::log_debug("DEBUG: adding #{dep} to dependencies")
|
36
|
+
end
|
37
|
+
end
|
38
|
+
return changes
|
39
|
+
end
|
40
|
+
|
10
41
|
end
|
11
42
|
|
data/lib/gems_status_metadata.rb
CHANGED
data/lib/lockfile_gems.rb
CHANGED
@@ -28,6 +28,25 @@ class LockfileGems < GemsCommand
|
|
28
28
|
return data
|
29
29
|
end
|
30
30
|
|
31
|
+
def update_gem_dependencies(gem)
|
32
|
+
Utils::log_debug("DEBUG: updating dependencies for #{gem.name}")
|
33
|
+
changes = false
|
34
|
+
@result.each do |k, gem2|
|
35
|
+
if gem.depends?(gem2)
|
36
|
+
changes = gem.merge_deps(gem2) || changes
|
37
|
+
end
|
38
|
+
end
|
39
|
+
return changes
|
40
|
+
end
|
41
|
+
|
42
|
+
def update_dependencies
|
43
|
+
changes = false
|
44
|
+
@result.each do |k, gem|
|
45
|
+
changes = update_gem_dependencies(gem) || changes
|
46
|
+
end
|
47
|
+
update_dependencies if changes
|
48
|
+
end
|
49
|
+
|
31
50
|
def execute
|
32
51
|
@filenames.each do |filename|
|
33
52
|
Utils::log_debug "DEBUG: reading #{filename}"
|
@@ -41,10 +60,17 @@ class LockfileGems < GemsCommand
|
|
41
60
|
name = spec.name
|
42
61
|
version = Gem::Version.create(spec.version)
|
43
62
|
if @result[name] && @result[name].version != version
|
44
|
-
Utils::log_error "
|
63
|
+
Utils::log_error "
|
64
|
+
ERROR: Same gem with different versions:
|
65
|
+
#{name} - #{version} - #{filename}\n
|
66
|
+
#{name} - #{@result[name].version} - #{@result[name].origin} "
|
45
67
|
end
|
46
|
-
|
68
|
+
dependencies = spec.dependencies
|
69
|
+
Utils::log_debug "DEBUG: dependencies for #{name} #{dependencies}"
|
70
|
+
@result[name] = RubyGemsGems_GemSimple.new(name, version , '', filename,
|
71
|
+
@gems_url, dependencies)
|
47
72
|
end
|
73
|
+
update_dependencies
|
48
74
|
end
|
49
75
|
end
|
50
76
|
|
data/lib/not_rails_checker.rb
CHANGED
@@ -4,27 +4,16 @@ require 'open-uri'
|
|
4
4
|
require 'gem_checker'
|
5
5
|
|
6
6
|
class NotRailsChecker < GemChecker
|
7
|
+
RAILS_GEMS = ["rails", "railties","activesupport"]
|
7
8
|
def NotRailsChecker.check?(gem)
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
result = Gem::Format.from_io io
|
9
|
+
return false if !gem.dependencies
|
10
|
+
gem.dependencies.each do |dep|
|
11
|
+
if RAILS_GEMS.include?(dep.name)
|
12
|
+
return false
|
13
13
|
end
|
14
|
-
rescue IOError
|
15
|
-
#bug on open-uri:137 on closing strings
|
16
|
-
#it should be
|
17
|
-
#io.close if io && !io.closed?
|
18
|
-
#or is a bug on rubygems???
|
19
|
-
rescue => e
|
20
|
-
Utils::log_error "ERROR: There was a problem opening #{gem_uri} #{e.class} #{e.message}"
|
21
|
-
end
|
22
|
-
return false unless result
|
23
|
-
result.spec.dependencies.each do |gem|
|
24
|
-
return false if gem.name == "rails"
|
25
14
|
end
|
26
15
|
return true
|
27
|
-
|
16
|
+
end
|
28
17
|
|
29
18
|
def NotRailsChecker.description
|
30
19
|
"This gem depends on rails or could not get spec: "
|
@@ -2,8 +2,8 @@ require "gem_simple"
|
|
2
2
|
|
3
3
|
class RubyGemsGems_GemSimple < GemSimple
|
4
4
|
|
5
|
-
def initialize(name, version, md5, origin, gems_url)
|
6
|
-
super(name, version, nil, origin, gems_url)
|
5
|
+
def initialize(name, version, md5, origin, gems_url, dependencies=nil)
|
6
|
+
super(name, version, nil, origin, gems_url, dependencies)
|
7
7
|
end
|
8
8
|
|
9
9
|
def md5
|
data/test/Gemfile.lock.test
CHANGED
data/test/test-lockfile_gems.rb
CHANGED
@@ -1,22 +1,23 @@
|
|
1
1
|
$:.unshift File.join(File.dirname(__FILE__), "..", "lib")
|
2
2
|
require 'test/unit'
|
3
3
|
require 'lockfile_gems'
|
4
|
+
require 'rubygems/dependency'
|
4
5
|
|
5
6
|
class LockfileGemsTest < LockfileGems
|
6
7
|
attr_accessor :result
|
7
8
|
def initialize
|
8
|
-
|
9
|
-
@
|
9
|
+
#TODO: this won't work in other development machines!
|
10
|
+
@filenames = ["/home/jordi/work/suse/gems-status/test/Gemfile.lock.test"]
|
10
11
|
@gems_url = ""
|
11
12
|
@result = {}
|
12
13
|
end
|
13
14
|
end
|
14
15
|
|
15
16
|
class TestLockfileGems < Test::Unit::TestCase
|
16
|
-
def
|
17
|
+
def test_get_rubygems_names
|
17
18
|
lockfilegems = LockfileGemsTest.new
|
18
19
|
lockfilegems.execute
|
19
|
-
assert(lockfilegems.result.length ==
|
20
|
+
assert(lockfilegems.result.length == 4)
|
20
21
|
result = lockfilegems.result["test"].name
|
21
22
|
assert_equal("test",result)
|
22
23
|
result = lockfilegems.result["test"].version
|
@@ -25,6 +26,33 @@ class TestLockfileGems < Test::Unit::TestCase
|
|
25
26
|
assert_equal("test2",result)
|
26
27
|
result = lockfilegems.result["test2"].version
|
27
28
|
assert_equal(Gem::Version.new("1.2.3"), result)
|
29
|
+
result = lockfilegems.result["test3"].name
|
30
|
+
assert_equal("test3",result)
|
31
|
+
result = lockfilegems.result["test3"].version
|
32
|
+
assert_equal(Gem::Version.new("1.2.3"), result)
|
33
|
+
result = lockfilegems.result["test4"].name
|
34
|
+
assert_equal("test4",result)
|
35
|
+
result = lockfilegems.result["test4"].version
|
36
|
+
assert_equal(Gem::Version.new("1.2.3"), result)
|
37
|
+
end
|
38
|
+
|
39
|
+
def test_get_rubygems_dependencies
|
40
|
+
lockfilegems = LockfileGemsTest.new
|
41
|
+
lockfilegems.execute
|
42
|
+
result = lockfilegems.result["test"].dependencies
|
43
|
+
assert(result)
|
44
|
+
result = lockfilegems.result["test"].dependencies.length
|
45
|
+
assert_equal(3, result)
|
46
|
+
result = lockfilegems.result["test"].dependencies
|
47
|
+
assert_equal(
|
48
|
+
Gem::Dependency.new("test2", Gem::Requirement.new(["= 1.2.3"])),
|
49
|
+
result[0])
|
50
|
+
assert_equal(
|
51
|
+
Gem::Dependency.new("test3", Gem::Requirement.new(["= 1.2.3"])),
|
52
|
+
result[1])
|
53
|
+
assert_equal(
|
54
|
+
Gem::Dependency.new("test4", Gem::Requirement.new(["= 1.2.3"])),
|
55
|
+
result[2])
|
28
56
|
end
|
29
57
|
end
|
30
58
|
|
@@ -0,0 +1,54 @@
|
|
1
|
+
$:.unshift File.join(File.dirname(__FILE__), "..", "lib")
|
2
|
+
require 'rubygems'
|
3
|
+
require 'test/unit'
|
4
|
+
require 'gems_command'
|
5
|
+
require 'gem_simple'
|
6
|
+
require 'not_rails_checker'
|
7
|
+
|
8
|
+
class TestNotRailsChecker < Test::Unit::TestCase
|
9
|
+
def test_gem_with_no_deps
|
10
|
+
gem = GemSimple.new("name", Gem::Version.new("1.2.3"), nil, nil, nil, nil)
|
11
|
+
check = NotRailsChecker
|
12
|
+
result = check.check?(gem)
|
13
|
+
assert(!result)
|
14
|
+
end
|
15
|
+
def test_gem_with_no_deps_2
|
16
|
+
gem = GemSimple.new("name", Gem::Version.new("1.2.3"), nil, nil, nil, [])
|
17
|
+
check = NotRailsChecker
|
18
|
+
result = check.check?(gem)
|
19
|
+
assert(result)
|
20
|
+
end
|
21
|
+
def test_gem_with_rail_dep
|
22
|
+
deps = [
|
23
|
+
Gem::Dependency.new("rails", Gem::Requirement.new("> 0.0.0")),
|
24
|
+
Gem::Dependency.new("foo", Gem::Requirement.new("> 0.0.0"))
|
25
|
+
]
|
26
|
+
|
27
|
+
gem = GemSimple.new("name", Gem::Version.new("1.2.3"), nil, nil, nil, deps)
|
28
|
+
check = NotRailsChecker
|
29
|
+
result = check.check?(gem)
|
30
|
+
assert(!result)
|
31
|
+
end
|
32
|
+
def test_gem_with_no_rail_dep
|
33
|
+
deps = [
|
34
|
+
Gem::Dependency.new("norails", Gem::Requirement.new("> 0.0.0")),
|
35
|
+
Gem::Dependency.new("foo", Gem::Requirement.new("> 0.0.0"))
|
36
|
+
]
|
37
|
+
|
38
|
+
gem = GemSimple.new("name", Gem::Version.new("1.2.3"), nil, nil, nil, deps)
|
39
|
+
check = NotRailsChecker
|
40
|
+
result = check.check?(gem)
|
41
|
+
assert(result)
|
42
|
+
end
|
43
|
+
def test_gem_with_railties_dep
|
44
|
+
deps = [
|
45
|
+
Gem::Dependency.new("railties", Gem::Requirement.new("> 0.0.0")),
|
46
|
+
Gem::Dependency.new("foo", Gem::Requirement.new("> 0.0.0"))
|
47
|
+
]
|
48
|
+
|
49
|
+
gem = GemSimple.new("name", Gem::Version.new("1.2.3"), nil, nil, nil, deps)
|
50
|
+
check = NotRailsChecker
|
51
|
+
result = check.check?(gem)
|
52
|
+
assert(!result)
|
53
|
+
end
|
54
|
+
end
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: gems-status
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 27
|
5
5
|
prerelease:
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 2
|
9
|
-
-
|
10
|
-
version: 0.2.
|
9
|
+
- 6
|
10
|
+
version: 0.2.6
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Jordi Massaguer Pla
|
@@ -77,6 +77,7 @@ files:
|
|
77
77
|
- test/test-utils.rb
|
78
78
|
- test/test-ruby_gems_gems.rb
|
79
79
|
- test/test-lockfile_gems.rb
|
80
|
+
- test/test-not_rails_checker.rb
|
80
81
|
- test/test-obs_gems.rb
|
81
82
|
- test/Gemfile.lock
|
82
83
|
- test/Gemfile
|