Class: Autoproj::Ops::Loader
- Inherits:
-
Object
- Object
- Autoproj::Ops::Loader
- Defined in:
- lib/autoproj/ops/loader.rb
Direct Known Subclasses
Instance Attribute Summary collapse
-
#file_stack ⇒ Array<String>
readonly
Information about what is being loaded.
-
#root_dir ⇒ String
readonly
The path w.r.t.
Instance Method Summary collapse
-
#current_file ⇒ Object
Returns the information about the file that is currently being loaded.
-
#current_package_set ⇒ Object
The PackageSet object representing the package set that is currently being loaded.
- #filter_load_exception(error, package_set, path) ⇒ Object
- #import_autobuild_file(package_set, path) ⇒ Object
- #in_package_set(pkg_set, path) ⇒ Object
-
#initialize(root_dir) ⇒ Loader
constructor
A new instance of Loader.
-
#load(pkg_set, *path) ⇒ Object
Load a definition file from a package set.
-
#load_if_present(pkg_set, *path) ⇒ Object
Load a definition file from a package set if the file is present.
Constructor Details
#initialize(root_dir) ⇒ Loader
Returns a new instance of Loader.
11 12 13 14 15 |
# File 'lib/autoproj/ops/loader.rb', line 11 def initialize(root_dir) @root_dir = root_dir @file_stack = Array.new @loaded_autobuild_files = Set.new end |
Instance Attribute Details
#file_stack ⇒ Array<String> (readonly)
Returns information about what is being loaded.
9 10 11 |
# File 'lib/autoproj/ops/loader.rb', line 9 def file_stack @file_stack end |
#root_dir ⇒ String (readonly)
The path w.r.t. which we should resolve relative paths
7 8 9 |
# File 'lib/autoproj/ops/loader.rb', line 7 def root_dir @root_dir end |
Instance Method Details
#current_file ⇒ Object
Returns the information about the file that is currently being loaded
The return value is [package_set, path], where package_set
is the PackageSet instance and path
is the path of the file w.r.t. the autoproj root directory
52 53 54 55 56 57 58 |
# File 'lib/autoproj/ops/loader.rb', line 52 def current_file unless (file = @file_stack.last) raise ArgumentError, "not in a #in_package_set context" end file end |
#current_package_set ⇒ Object
The PackageSet object representing the package set that is currently being loaded
62 63 64 |
# File 'lib/autoproj/ops/loader.rb', line 62 def current_package_set current_file.first end |
#filter_load_exception(error, package_set, path) ⇒ Object
25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/autoproj/ops/loader.rb', line 25 def filter_load_exception(error, package_set, path) raise error if Autoproj.verbose rx_path = Regexp.quote(path) unless (error_line = error.backtrace.find { |l| l =~ /#{rx_path}/ }) raise error end if (line_number = Integer(/#{rx_path}:(\d+)/.match(error_line)[1])) line_number = "#{line_number}:" end if package_set.local? raise ConfigError.new(path), "#{path}:#{line_number} #{error.}", error.backtrace else raise ConfigError.new(path), "#{File.basename(path)}(package_set=#{package_set.name}):"\ "#{line_number} #{error.}", error.backtrace end end |
#import_autobuild_file(package_set, path) ⇒ Object
97 98 99 100 101 102 |
# File 'lib/autoproj/ops/loader.rb', line 97 def import_autobuild_file(package_set, path) return if @loaded_autobuild_files.include?(path) load(package_set, path) @loaded_autobuild_files << path end |
#in_package_set(pkg_set, path) ⇒ Object
17 18 19 20 21 22 23 |
# File 'lib/autoproj/ops/loader.rb', line 17 def in_package_set(pkg_set, path) path = File.(path, root_dir) if path @file_stack.push([pkg_set, path]) yield ensure @file_stack.pop end |
#load(pkg_set, *path) ⇒ Object
Load a definition file from a package set
If any error is detected, the backtrace will be filtered so that it is easier to understand by the user. Moreover, if source
is non-nil, the package set name will be mentionned.
74 75 76 77 78 79 80 81 82 83 84 85 86 87 |
# File 'lib/autoproj/ops/loader.rb', line 74 def load(pkg_set, *path) path = File.join(*path) relative_path = File.(path).gsub(/^#{Regexp.quote(root_dir)}\//, "") in_package_set(pkg_set, relative_path) do Kernel.load path rescue Interrupt raise rescue ConfigError => e raise rescue Exception => e filter_load_exception(e, pkg_set, path) end end |
#load_if_present(pkg_set, *path) ⇒ Object
Load a definition file from a package set if the file is present
(see load)
92 93 94 95 |
# File 'lib/autoproj/ops/loader.rb', line 92 def load_if_present(pkg_set, *path) path = File.join(*path) load(pkg_set, *path) if File.file?(path) end |