Class: RIM::CommandHelper
Constant Summary
Constants inherited
from Processor
Processor::GerritServer, Processor::MaxThreads
Instance Method Summary
collapse
Methods included from Manifest
#parse_manifest, #read_manifest
Methods inherited from Processor
#clone_or_fetch_repository, #commit, #each_module_parallel, #get_absolute_remote_url, #get_relative_path, #local_changes?, #module_git_path, #module_tmp_git_path, #remote_path
Constructor Details
#initialize(workspace_root, logger, module_infos = nil) ⇒ CommandHelper
Returns a new instance of CommandHelper.
15
16
17
18
19
20
21
22
23
24
|
# File 'lib/rim/command_helper.rb', line 15
def initialize(workspace_root, logger, module_infos = nil)
super(workspace_root, logger)
@paths = []
@logger = logger
if module_infos
module_infos.each do |m|
add_module_info(m)
end
end
end
|
Instance Method Details
#add_unique_module_info(module_info) ⇒ Object
97
98
99
100
101
102
103
104
|
# File 'lib/rim/command_helper.rb', line 97
def add_unique_module_info(module_info)
if !@paths.include?(module_info.local_path)
@paths.push(module_info.local_path)
add_module_info(module_info)
else
raise RimException.new("Module '#{module_info.local_path}' specified more than once.")
end
end
|
#all_module_paths_from_path(path) ⇒ Object
93
94
95
|
# File 'lib/rim/command_helper.rb', line 93
def all_module_paths_from_path(path)
Dir.glob(File.join(path, "**/.riminfo")).map { |f| Pathname.new(File.expand_path(File.dirname(f))).relative_path_from(Pathname.pwd).to_s }
end
|
#check_arguments ⇒ Object
31
32
33
|
# File 'lib/rim/command_helper.rb', line 31
def check_arguments
raise RimException.new("Unexpected command line arguments.") if !ARGV.empty?
end
|
#check_ready ⇒ Object
check whether workspace is not touched
27
28
29
|
# File 'lib/rim/command_helper.rb', line 27
def check_ready
raise RimException.new("The workspace git contains uncommitted changes.") if !local_changes?(@ws_root)
end
|
#create_module_info(remote_url, local_path, target_revision, ignores) ⇒ Object
35
36
37
|
# File 'lib/rim/command_helper.rb', line 35
def create_module_info(remote_url, local_path, target_revision, ignores)
ModuleInfo.new(remote_url, get_relative_path(local_path), target_revision, ignores, remote_url ? get_remote_branch_format(remote_url) : nil)
end
|
#find_file_dir_in_workspace(start_dir, file) ⇒ Object
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
|
# File 'lib/rim/command_helper.rb', line 111
def find_file_dir_in_workspace(start_dir, file)
path = File.expand_path(start_dir)
while path != @ws_root
if File.exist?(File.join(path, file))
return path
else
parent = File.dirname(path)
if parent != path
path = parent
else
break
end
end
end
nil
end
|
106
107
108
109
|
# File 'lib/rim/command_helper.rb', line 106
def get_remote_branch_format(remote_url)
get_absolute_remote_url(remote_url).start_with?(GerritServer) ? "refs/for/%s" : nil
end
|
#module_from_path(path, opts = {}) ⇒ Object
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
|
# File 'lib/rim/command_helper.rb', line 59
def module_from_path(path, opts = {})
module_path = find_file_dir_in_workspace(path || ".", RimInfo::InfoFileName)
if module_path
rim_info = RimInfo.from_dir(module_path)
module_info = create_module_info(opts.has_key?(:remote_url) ? opts[:remote_url] : rim_info.remote_url, \
module_path, opts.has_key?(:target_revision) ? opts[:target_revision] : rim_info.target_revision, \
opts.has_key?(:ignores) ? opts[:ignores] : rim_info.ignores)
if module_info.valid?
add_unique_module_info(module_info)
module_path
else
raise RimException.new("Invalid .riminfo file found in directory '#{module_path}'.")
end
else
raise RimException.new(path ? "No module info found in '#{path}'." : "No module info found.")
end
end
|
#module_paths(paths, exclude_paths = nil) ⇒ Object
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
|
# File 'lib/rim/command_helper.rb', line 77
def module_paths(paths, exclude_paths = nil)
module_paths = []
(paths.empty? ? ['.'] : paths).each do |p|
module_paths.concat(all_module_paths_from_path(p))
end
paths.clear
if exclude_paths
exclude_paths.each do |e|
all_module_paths_from_path(e).each do |p|
module_paths.delete(p)
end
end
end
module_paths.sort
end
|
#modules_from_manifest(path) ⇒ Object
39
40
41
42
43
44
45
|
# File 'lib/rim/command_helper.rb', line 39
def modules_from_manifest(path)
manifest = read_manifest(path)
manifest.modules.each do |mod|
add_unique_module_info(create_module_info(mod.remote_path, mod.local_path, mod.target_revision, mod.ignores))
end
true
end
|
#modules_from_paths(paths, opts = {}) ⇒ Object
47
48
49
50
51
52
53
54
55
56
57
|
# File 'lib/rim/command_helper.rb', line 47
def modules_from_paths(paths, opts = {})
if paths.empty?
module_from_path(nil, opts)
elsif paths.length == 1 || !opts.has_key?(:remote_url)
while !paths.empty?
module_from_path(paths.shift, opts)
end
else
raise RimException.new("Multiple modules cannot be used with URL option.")
end
end
|