esr-rim 1.1.5

Sign up to get free protection for your applications and to get access to all the features.
Files changed (48) hide show
  1. checksums.yaml +7 -0
  2. data/CHANGELOG +40 -0
  3. data/README.md +3 -0
  4. data/Rakefile +56 -0
  5. data/bin/rim +3 -0
  6. data/lib/rim/command/command.rb +37 -0
  7. data/lib/rim/command/status.rb +110 -0
  8. data/lib/rim/command/sync.rb +69 -0
  9. data/lib/rim/command/upload.rb +33 -0
  10. data/lib/rim/command_helper.rb +119 -0
  11. data/lib/rim/dirty_check.rb +111 -0
  12. data/lib/rim/file_helper.rb +58 -0
  13. data/lib/rim/file_logger.rb +21 -0
  14. data/lib/rim/git.rb +339 -0
  15. data/lib/rim/manifest/helper.rb +82 -0
  16. data/lib/rim/manifest/json_reader.rb +40 -0
  17. data/lib/rim/manifest/manifest.json +7 -0
  18. data/lib/rim/manifest/model.rb +33 -0
  19. data/lib/rim/manifest/repo_reader.rb +61 -0
  20. data/lib/rim/module_helper.rb +52 -0
  21. data/lib/rim/module_info.rb +30 -0
  22. data/lib/rim/processor.rb +126 -0
  23. data/lib/rim/rev_status.rb +61 -0
  24. data/lib/rim/rim.rb +93 -0
  25. data/lib/rim/rim_exception.rb +15 -0
  26. data/lib/rim/rim_info.rb +129 -0
  27. data/lib/rim/status_builder.rb +219 -0
  28. data/lib/rim/sync_helper.rb +121 -0
  29. data/lib/rim/sync_module_helper.rb +115 -0
  30. data/lib/rim/upload_helper.rb +67 -0
  31. data/lib/rim/upload_module_helper.rb +152 -0
  32. data/lib/rim/version.rb +10 -0
  33. data/test/dirty_check_test.rb +210 -0
  34. data/test/file_helper_test.rb +132 -0
  35. data/test/git_test.rb +49 -0
  36. data/test/manifest_helper_test.rb +29 -0
  37. data/test/manifest_test_dir/manifest.rim +9 -0
  38. data/test/manifest_test_dir/subdir/only_to_keep_folder_in_git.txt +0 -0
  39. data/test/processor_test.rb +32 -0
  40. data/test/rim_info_test.rb +93 -0
  41. data/test/status_builder_test.rb +488 -0
  42. data/test/sync_helper_test.rb +193 -0
  43. data/test/sync_module_helper_test.rb +96 -0
  44. data/test/test_helper.rb +39 -0
  45. data/test/unit_tests.rb +14 -0
  46. data/test/upload_helper_test.rb +338 -0
  47. data/test/upload_module_helper_test.rb +92 -0
  48. metadata +110 -0
@@ -0,0 +1,10 @@
1
+ module RIM
2
+
3
+ module Version
4
+
5
+ Version = "1.1.5"
6
+
7
+ end
8
+
9
+ end
10
+
@@ -0,0 +1,210 @@
1
+ $:.unshift File.join(File.dirname(__FILE__),"..","lib")
2
+ $:.unshift File.join(File.dirname(__FILE__))
3
+
4
+ require 'minitest/autorun'
5
+ require 'fileutils'
6
+ require 'test_helper'
7
+ require 'rim/rim_info'
8
+ require 'rim/dirty_check'
9
+
10
+ class DirtyCheckTest < MiniTest::Test
11
+
12
+ include FileUtils
13
+ include TestHelper
14
+
15
+ def test_check_empty
16
+ d = empty_test_dir("dirty_check")
17
+ assert RIM::DirtyCheck.dirty?(d)
18
+ end
19
+
20
+ def test_mark_clean_empty
21
+ d = empty_test_dir("dirty_check")
22
+ assert_raises RIM::DirtyCheck::MissingInfoException do
23
+ RIM::DirtyCheck.mark_clean(d)
24
+ end
25
+ end
26
+
27
+ def test_mark_clean
28
+ d = empty_test_dir("dirty_check")
29
+ create_rim_info(d, {
30
+ :remote_url => "ssh://gerrit",
31
+ :revision_sha1 => "4711"
32
+ })
33
+ write_file("#{d}/somefile", "some content")
34
+ RIM::DirtyCheck.mark_clean(d)
35
+ assert !RIM::DirtyCheck.dirty?(d)
36
+ # some whitebox testing
37
+ ri = RIM::RimInfo.from_dir(d)
38
+ assert ri.checksum
39
+ end
40
+
41
+ def test_dirty_add_file
42
+ d = empty_test_dir("dirty_check")
43
+ setup_clean_test_module(d)
44
+ write_file("#{d}/otherfile", "bla")
45
+ assert RIM::DirtyCheck.dirty?(d)
46
+ end
47
+
48
+ def test_dirty_add_file_ignored
49
+ d = empty_test_dir("dirty_check")
50
+ setup_clean_test_module(d)
51
+ write_file("#{d}/ign_file2", "bla")
52
+ assert !RIM::DirtyCheck.dirty?(d)
53
+ end
54
+
55
+ def test_dirty_change_file
56
+ d = empty_test_dir("dirty_check")
57
+ setup_clean_test_module(d)
58
+ File.open("#{d}/file1", "a") do |f|
59
+ f.write("another line\n")
60
+ end
61
+ assert RIM::DirtyCheck.dirty?(d)
62
+ end
63
+
64
+ def test_dirty_change_file_ignored
65
+ d = empty_test_dir("dirty_check")
66
+ setup_clean_test_module(d)
67
+ File.open("#{d}/ign_file1", "a") do |f|
68
+ f.write("another line\n")
69
+ end
70
+ assert !RIM::DirtyCheck.dirty?(d)
71
+ end
72
+
73
+ def test_dirty_move_file
74
+ d = empty_test_dir("dirty_check")
75
+ setup_clean_test_module(d)
76
+ mv "#{d}/file1", "#{d}/file2"
77
+ assert RIM::DirtyCheck.dirty?(d)
78
+ end
79
+
80
+ def test_dirty_move_file_ignored
81
+ d = empty_test_dir("dirty_check")
82
+ setup_clean_test_module(d)
83
+ mv "#{d}/ign_file1", "#{d}/ign_file2"
84
+ assert !RIM::DirtyCheck.dirty?(d)
85
+ end
86
+
87
+ def test_dirty_delete_file
88
+ d = empty_test_dir("dirty_check")
89
+ setup_clean_test_module(d)
90
+ rm "#{d}/file1"
91
+ assert RIM::DirtyCheck.dirty?(d)
92
+ end
93
+
94
+ def test_dirty_delete_file_ignored
95
+ d = empty_test_dir("dirty_check")
96
+ setup_clean_test_module(d)
97
+ rm "#{d}/ign_file1"
98
+ assert !RIM::DirtyCheck.dirty?(d)
99
+ end
100
+
101
+ def test_dirty_move_file_and_repair
102
+ d = empty_test_dir("dirty_check")
103
+ setup_clean_test_module(d)
104
+ mv "#{d}/file1", "#{d}/file2"
105
+ assert RIM::DirtyCheck.dirty?(d)
106
+ mv "#{d}/file2", "#{d}/file1"
107
+ assert !RIM::DirtyCheck.dirty?(d)
108
+ end
109
+
110
+ def test_dirty_corrupt_rim_info
111
+ d = empty_test_dir("dirty_check")
112
+ setup_clean_test_module(d)
113
+ File.open("#{d}/.riminfo", "a") do |f|
114
+ f.write("some text")
115
+ end
116
+ assert RIM::DirtyCheck.dirty?(d)
117
+ end
118
+
119
+ def test_dirty_change_info
120
+ d = empty_test_dir("dirty_check")
121
+ setup_clean_test_module(d)
122
+ ri = RIM::RimInfo.from_dir(d)
123
+ ri.revision_sha1 = "999"
124
+ ri.to_dir(d)
125
+ assert RIM::DirtyCheck.dirty?(d)
126
+ end
127
+
128
+ def test_dirty_change_info_and_repair
129
+ d = empty_test_dir("dirty_check")
130
+ setup_clean_test_module(d)
131
+ ri = RIM::RimInfo.from_dir(d)
132
+ ri.revision_sha1 = "999"
133
+ ri.to_dir(d)
134
+ assert RIM::DirtyCheck.dirty?(d)
135
+ ri.revision_sha1 = "4711"
136
+ ri.to_dir(d)
137
+ assert !RIM::DirtyCheck.dirty?(d)
138
+ end
139
+
140
+ def test_ignore_glob
141
+ d = empty_test_dir("dirty_check")
142
+ setup_clean_test_module(d)
143
+ write_file("#{d}/file.ign", "bla")
144
+ assert !RIM::DirtyCheck.dirty?(d)
145
+ write_file("#{d}/dir1/file.ign", "bla")
146
+ assert RIM::DirtyCheck.dirty?(d)
147
+ end
148
+
149
+ def test_ignore_doubleglob
150
+ d = empty_test_dir("dirty_check")
151
+ setup_clean_test_module(d)
152
+ write_file("#{d}/file.ign2", "bla")
153
+ assert !RIM::DirtyCheck.dirty?(d)
154
+ write_file("#{d}/dir1/file.ign2", "bla")
155
+ assert !RIM::DirtyCheck.dirty?(d)
156
+ end
157
+
158
+ def test_line_ending_change
159
+ d = empty_test_dir("dirty_check")
160
+ setup_clean_test_module(d)
161
+ fn = "#{d}/file1"
162
+ lines = ["a", "b", "c"]
163
+ File.open(fn, "wb") do |f|
164
+ lines.each do |l|
165
+ f.write("#{l}\n")
166
+ end
167
+ end
168
+ RIM::DirtyCheck.mark_clean(d)
169
+ File.open(fn, "wb") do |f|
170
+ lines.each do |l|
171
+ f.write("#{l}\r\n")
172
+ end
173
+ end
174
+ assert !RIM::DirtyCheck.dirty?(d)
175
+ File.open(fn, "wb") do |f|
176
+ lines.each do |l|
177
+ f.write("#{l}\n")
178
+ end
179
+ end
180
+ assert !RIM::DirtyCheck.dirty?(d)
181
+ end
182
+
183
+ def test_empty_dir
184
+ d = empty_test_dir("dirty_check")
185
+ setup_clean_test_module(d)
186
+ mkdir "#{d}/emptydir"
187
+ assert !RIM::DirtyCheck.dirty?(d)
188
+ end
189
+
190
+ def teardown
191
+ # clean up test dirs created during last test
192
+ remove_test_dirs
193
+ end
194
+
195
+ private
196
+
197
+ def setup_clean_test_module(dir)
198
+ create_rim_info(dir, {
199
+ :remote_url => "ssh://gerrit",
200
+ :ignores => "ign_file1,ign_file2,*.ign,**/*.ign2",
201
+ :revision_sha1 => "4711"
202
+ })
203
+ write_file("#{dir}/file1", "some content")
204
+ write_file("#{dir}/ign_file1", "ignored stuff")
205
+ write_file("#{dir}/dir1/file2", "more content")
206
+ RIM::DirtyCheck.mark_clean(dir)
207
+ assert !RIM::DirtyCheck.dirty?(dir)
208
+ end
209
+
210
+ end
@@ -0,0 +1,132 @@
1
+ $:.unshift File.join(File.dirname(__FILE__),"..","lib")
2
+ $:.unshift File.join(File.dirname(__FILE__))
3
+
4
+ require 'minitest/autorun'
5
+ require 'rim/file_helper'
6
+ require 'fileutils'
7
+ require 'test_helper'
8
+
9
+ class FileHelperTest < Minitest::Test
10
+ include FileUtils
11
+ include TestHelper
12
+
13
+ def setup
14
+ @test_dir = empty_test_dir("file_helper_test")
15
+ end
16
+
17
+ def teardown
18
+ remove_test_dirs
19
+ end
20
+
21
+ def test_find_matching_relative_files
22
+ create_test_file(".", "aaa")
23
+ create_test_file(".", "abc")
24
+ create_test_file(".", "bbb")
25
+ create_test_file("f1", "aaa")
26
+ create_test_file("f1", "ccc")
27
+ create_test_file("f2", "ccc")
28
+ create_test_file("f2", "ddd")
29
+ files = RIM::FileHelper.find_matching_files(@test_dir, false)
30
+ assert files[0] == "aaa"
31
+ assert files[1] == "abc"
32
+ assert files[2] == "bbb"
33
+ assert files[3] == "f1"
34
+ assert files[4] == "f1/aaa"
35
+ assert files[5] == "f1/ccc"
36
+ assert files[6] == "f2"
37
+ assert files[7] == "f2/ccc"
38
+ assert files[8] == "f2/ddd"
39
+ end
40
+
41
+ def test_find_matching_absolute_files
42
+ create_test_file(".", "aaa")
43
+ create_test_file(".", "abc")
44
+ create_test_file(".", "bbb")
45
+ create_test_file("f1", "aaa")
46
+ create_test_file("f1", "ccc")
47
+ create_test_file("f2", "ccc")
48
+ create_test_file("f2", "ddd")
49
+ files = RIM::FileHelper.find_matching_files(@test_dir, true)
50
+ assert files[0] == File.join(@test_dir, "aaa")
51
+ assert files[1] == File.join(@test_dir, "abc")
52
+ assert files[2] == File.join(@test_dir, "bbb")
53
+ assert files[3] == File.join(@test_dir, "f1")
54
+ assert files[4] == File.join(@test_dir, "f1/aaa")
55
+ assert files[5] == File.join(@test_dir, "f1/ccc")
56
+ assert files[6] == File.join(@test_dir, "f2")
57
+ assert files[7] == File.join(@test_dir, "f2/ccc")
58
+ assert files[8] == File.join(@test_dir, "f2/ddd")
59
+ end
60
+
61
+ def test_find_matching_relative_files_with_patterns
62
+ create_test_file(".", "aaa")
63
+ create_test_file(".", "abc")
64
+ create_test_file(".", "bbb")
65
+ create_test_file("f1", "aaa")
66
+ create_test_file("f1", "ccc")
67
+ create_test_file("f2", "ccc")
68
+ create_test_file("f2", "ddd")
69
+ files = RIM::FileHelper.find_matching_files(@test_dir, false, ["**/a*", "f2/ccc"])
70
+ assert files[0] == "aaa"
71
+ assert files[1] == "abc"
72
+ assert files[2] == "f1/aaa"
73
+ assert files[3] == "f2/ccc"
74
+ end
75
+
76
+ def test_find_matching_absolute_files_with_patterns
77
+ create_test_file(".", "aaa")
78
+ create_test_file(".", "abc")
79
+ create_test_file(".", "bbb")
80
+ create_test_file("f1", "aaa")
81
+ create_test_file("f1", "ccc")
82
+ create_test_file("f2", "ccc")
83
+ create_test_file("f2", "ddd")
84
+ files = RIM::FileHelper.find_matching_files(@test_dir, true, ["**/a*", "f2/ccc"])
85
+ assert files[0] == File.join(@test_dir, "aaa")
86
+ assert files[1] == File.join(@test_dir, "abc")
87
+ assert files[2] == File.join(@test_dir, "f1/aaa")
88
+ assert files[3] == File.join(@test_dir, "f2/ccc")
89
+ end
90
+
91
+ def test_remove_empty_dirs
92
+ create_test_file(".", "a")
93
+ create_test_file("f1", "ab")
94
+ create_test_file("f1/f1")
95
+ create_test_file("f1/f1/f1")
96
+ create_test_file("f1/f1/f2")
97
+ RIM::FileHelper.remove_empty_dirs(@test_dir)
98
+ files = RIM::FileHelper.find_matching_files(@test_dir, false)
99
+ assert files[0] = "a"
100
+ assert files[1] = "f1"
101
+ assert files[2] = "f1/ab"
102
+ assert !files[3]
103
+ end
104
+
105
+ def test_remove_empty_dirs_with_avoid
106
+ create_test_file(".", "a")
107
+ create_test_file("f1", "ab")
108
+ create_test_file("f1/f1")
109
+ create_test_file("f1/f1/f1")
110
+ create_test_file("f1/f1/f2")
111
+ RIM::FileHelper.remove_empty_dirs(@test_dir, File.join(@test_dir, "f1/f1"))
112
+ files = RIM::FileHelper.find_matching_files(@test_dir, false)
113
+ assert files[0] = "a"
114
+ assert files[1] = "f1"
115
+ assert files[2] = "f1/ab"
116
+ assert files[2] = "f1/f1"
117
+ assert !files[4]
118
+ end
119
+
120
+ private
121
+
122
+ def create_test_file(dir, name = nil)
123
+ abs_dir = File.join(@test_dir, dir)
124
+ FileUtils.mkdir_p(abs_dir)
125
+ if name
126
+ File.open(File.join(abs_dir, name), "w") do |f|
127
+ f.write("Content of #{name}\n")
128
+ end
129
+ end
130
+ end
131
+
132
+ end
@@ -0,0 +1,49 @@
1
+ $:.unshift File.join(File.dirname(__FILE__),"..","lib")
2
+ $:.unshift File.join(File.dirname(__FILE__))
3
+
4
+ require 'minitest/autorun'
5
+ require 'fileutils'
6
+ require 'test_helper'
7
+ require 'rim/git'
8
+
9
+ class GitTest < MiniTest::Test
10
+
11
+ include FileUtils
12
+ include TestHelper
13
+
14
+ def setup
15
+ logger = Logger.new($stdout)
16
+ logger.level = Logger::ERROR unless ARGV.include? "debug"
17
+ RIM::GitSession.logger = logger
18
+ end
19
+
20
+ def test_export_rev_long_cmdline
21
+ d = empty_test_dir("git_test")
22
+
23
+ long_name100 = "a" * 100
24
+ num_files = 100
25
+
26
+ RIM.git_session(d) do |s|
27
+ s.execute "git init"
28
+ (1..num_files).each do |i|
29
+ write_file "#{d}/#{i}/#{long_name100}", i.to_s
30
+ end
31
+ s.execute "git add ."
32
+ s.execute "git commit -m \"test files\""
33
+
34
+ mkdir "#{d}/out"
35
+ s.export_rev("master", "#{d}/out", (1..num_files).collect{|i| "#{i}/#{long_name100}"})
36
+
37
+ (1..num_files).each do |i|
38
+ assert File.read("#{d}/out/#{i}/#{long_name100}") == i.to_s
39
+ end
40
+ end
41
+ end
42
+
43
+ def teardown
44
+ # clean up test dirs created during last test
45
+ remove_test_dirs
46
+ end
47
+
48
+ end
49
+
@@ -0,0 +1,29 @@
1
+ $:.unshift File.join(File.dirname(__FILE__),"..","lib")
2
+
3
+ require "minitest/autorun"
4
+ require "rim/manifest/helper"
5
+ require "fileutils"
6
+
7
+ class ManifestHelperTest < Minitest::Test
8
+ include FileUtils
9
+ include RIM::Manifest::Helpers
10
+
11
+ def setup
12
+ end
13
+
14
+ def test_find_local_config
15
+
16
+ cd File.dirname(__FILE__)+"/manifest_test_dir" do
17
+ m = default_manifest
18
+ assert m != nil
19
+ end
20
+ end
21
+
22
+ def test_find_config_from_subdir
23
+
24
+ cd File.dirname(__FILE__)+"/manifest_test_dir/subdir" do
25
+ m = default_manifest
26
+ assert m != nil
27
+ end
28
+ end
29
+ end
@@ -0,0 +1,9 @@
1
+ {
2
+ "url" : "ssh://gerrit",
3
+ "dependencies" : [
4
+ {
5
+ "unit":"nvStorage", "version": "1.1", "destination": "./bsw/nvStorage",
6
+ "unit":"eepromManager", "version": "2.3", "destination": "./bsw/eeprom"
7
+ }
8
+ ]
9
+ }
@@ -0,0 +1,32 @@
1
+ $:.unshift File.join(File.dirname(__FILE__),"..","lib")
2
+ $:.unshift File.join(File.dirname(__FILE__))
3
+
4
+ require 'minitest/autorun'
5
+ require 'rim/processor'
6
+ require 'test_helper'
7
+ require 'fileutils'
8
+
9
+ class ProcessorTest < Minitest::Test
10
+ include FileUtils
11
+ include TestHelper
12
+
13
+ def setup
14
+ test_dir = empty_test_dir("command_helper_test")
15
+ end
16
+
17
+ def teardown
18
+ remove_test_dirs
19
+ end
20
+
21
+ def test_get_absolute_remote_url
22
+ cut = RIM::Processor.new(".", nil)
23
+ assert File.expand_path(".") == cut.get_absolute_remote_url("file://.")
24
+ assert File.expand_path("abcd", ".") == cut.get_absolute_remote_url("file://abcd")
25
+ assert File.expand_path("abc", ".") == cut.get_absolute_remote_url("file://./abc")
26
+ assert "C:/abcdef" == cut.get_absolute_remote_url("file:///C|/abcdef")
27
+ assert "/abcdef/defghi" == cut.get_absolute_remote_url("file:///abcdef/defghi")
28
+ assert "ssh://gerrit/abcde" == cut.get_absolute_remote_url("abcde")
29
+ assert "ssh://gerrit2/abcde" == cut.get_absolute_remote_url("ssh://gerrit2/abcde")
30
+ end
31
+
32
+ end