def invoke(recipe)
filenames = [recipe]
filenames << File.join(project, "recipes", recipe) if project
filenames << File.join(project, "recipes", recipe + ".rb") if project
for filename in filenames
log.debug(PNOTE+" invoking "+filename)
if File.exists?(filename)
data = File.read(filename)
begin
return instance_eval(data, filename, 1)
rescue Exception => e
if @friendly_exceptions
stack = caller
preresult = []
for line in e.backtrace
break if line == stack.first
preresult << line
end
preresult.last.match(/^([^:]+):(\d+):in `invoke'/)
recipe = $1
result = []
for line in preresult
next if line =~ %r{lib/automateit/.+manager\.rb:\d+:in `.+'$}
result << line
break if line =~ /^#{recipe}/
end
if e.is_a?(SyntaxError)
line_number = e.message.match(/^[^:]+:(\d+):/)[1].to_i
else
result.last.match(/^([^:]+):(\d+):in `invoke'/)
line_number = $2.to_i
end
msg = "Problem with recipe '#{recipe}' at line #{line_number}\n"
begin
lines = File.read(recipe).split(/\n/)
min = line_number - 7
min = 0 if min < 0
max = line_number + 1
max = lines.size if max > lines.size
width = max.to_s.size
for i in min..max
n = i+1
marker = n == line_number ? "*" : ""
msg << "\n%2s %#{width}i %s" % [marker, n, lines[i]]
end
msg << "\n"
rescue Exception => e
end
msg << "\n(#{e.exception.class}) #{e.message}"
for line in result
msg << "\n "+line
end
msg.gsub!(/#{@project}\/?/, '') if @project
raise AutomateIt::Error.new(msg, e)
else
raise e
end
end
end
end
raise Errno::ENOENT.new(recipe)
end