Class: RIM::Processor
- Inherits:
-
Object
show all
- Defined in:
- lib/rim/processor.rb
Constant Summary
collapse
- MaxThreads =
10
- GerritServer =
"ssh://gerrit/"
Class Method Summary
collapse
Instance Method Summary
collapse
Constructor Details
#initialize(workspace_root, logger) ⇒ Processor
Returns a new instance of Processor.
18
19
20
21
22
23
24
25
26
27
28
29
|
# File 'lib/rim/processor.rb', line 18
def initialize(workspace_root, logger)
@ws_root = workspace_root
rim_dir = nil
rim_dir = File.expand_path(ENV['RIM_HOME']) if ENV.has_key?('RIM_HOME')
rim_dir = File.join(File.expand_path(ENV['HOME']), ".rim") if rim_dir.nil? && ENV.has_key?('HOME')
if rim_dir
@rim_path = File.join(rim_dir, Processor.shorten_path(@ws_root))
else
@rim_path = File.join(@ws_root, ".rim")
end
@logger = logger
end
|
Class Method Details
.shorten_path(path) ⇒ Object
142
143
144
145
146
147
148
|
# File 'lib/rim/processor.rb', line 142
def self.shorten_path(path)
if path.length <= 10
path.gsub(':', '#')
else
Digest::SHA1.hexdigest(path || '')[0...10]
end
end
|
Instance Method Details
#clone_or_fetch_repository(remote_url, local_path, clone_log = nil) ⇒ Object
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
|
# File 'lib/rim/processor.rb', line 81
def clone_or_fetch_repository(remote_url, local_path, clone_log = nil)
FileUtils.mkdir_p local_path
RIM::git_session(local_path) do |s|
if !File.exist?(File.join(local_path, ".git"))
@logger.info(clone_log) if clone_log
FileHelper.make_empty_dir(local_path)
s.execute("git clone #{remote_url} .")
s.execute("git config core.ignorecase false")
else
s.execute("git remote set-url origin #{remote_url}") if !s.has_valid_remote_repository?()
s.execute("git fetch")
end
end
local_path
end
|
#commit(session, message) ⇒ Object
97
98
99
100
101
102
103
104
105
106
107
|
# File 'lib/rim/processor.rb', line 97
def commit(session, message)
msg_file = Tempfile.new('message')
begin
msg_file << message
msg_file.close
session.execute("git add --all")
session.execute("git commit -F #{msg_file.path}")
ensure
msg_file.close(true)
end
end
|
#each_module_parallel(task_desc, modules) ⇒ Object
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
|
# File 'lib/rim/processor.rb', line 109
def each_module_parallel(task_desc, modules)
if !modules.empty?
@logger.debug "starting \"#{task_desc}\" for #{modules.size} modules\r"
index_queue = Queue.new
(0...modules.size).each do |i|
index_queue << i
end
result_queue = Queue.new
(1..MaxThreads).each do
Thread.new do
loop do
i = index_queue.empty? ? nil : index_queue.pop(true)
break if i.nil?
result = []
begin
yield(modules[i], i)
rescue RimException => e
result = e.messages
rescue Exception => e
result = [e.to_s]
end
result_queue << result
end
end
end
messages = []
(0...modules.size).each do |i|
messages.concat(result_queue.pop)
end
raise RimException.new(messages) if !messages.empty?
end
end
|
#get_absolute_remote_url(remote_url) ⇒ Object
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
|
# File 'lib/rim/processor.rb', line 57
def get_absolute_remote_url(remote_url)
if remote_url.start_with?("file:")
remote_url = remote_url.gsub(/^file:(\/\/)?/, "")
match = remote_url.match(/^\/(\w)\|/)
if match
remote_url = "#{match[1]}:#{remote_url[match[0].size..-1]}"
elsif !remote_url.start_with?(File::SEPARATOR)
File.expand_path(remote_url, @ws_root)
else
remote_url
end
else
URI.parse(GerritServer).merge(URI.parse(remote_url)).to_s
end
end
|
#get_relative_path(path) ⇒ Object
#local_changes?(ws_dir, dir = ws_dir) ⇒ Boolean
73
74
75
76
77
78
79
|
# File 'lib/rim/processor.rb', line 73
def local_changes?(ws_dir, dir=ws_dir)
stat = nil
RIM::git_session(ws_dir) do |s|
stat = s.status(dir)
end
stat.lines.all?{|l| l.ignored?}
end
|
#module_git_path(remote_path) ⇒ Object
31
32
33
34
35
|
# File 'lib/rim/processor.rb', line 31
def module_git_path(remote_path)
File.join(@rim_path, Processor.shorten_path(remote_path))
end
|
#module_tmp_git_path(remote_path) ⇒ Object
37
38
39
40
41
|
# File 'lib/rim/processor.rb', line 37
def module_tmp_git_path(remote_path)
File.join(@rim_path, ".tmp", Processor.shorten_path(remote_path))
end
|
#remote_path(remote_url) ⇒ Object
43
44
45
46
47
48
49
50
51
|
# File 'lib/rim/processor.rb', line 43
def remote_path(remote_url)
remote_url.
sub(/^\w+:\/\//,'').
sub(/^\w+:/,'\1').
gsub(/\.\.[\\\/]/,'')
end
|