class Bake::Root

Attributes

depth[RW]
dir[RW]

Public Class Methods

calc_def_roots(dir) click to toggle source
# File lib/common/root.rb, line 78
def self.calc_def_roots(dir)
  return [Root.new(File.dirname(dir), nil)]
end
calc_roots_bake(dir) click to toggle source
# File lib/common/root.rb, line 59
def self.calc_roots_bake(dir)
  def_roots = []
  rootsFile = (File.file?(dir) ? dir : searchRootsFile(dir))
  if (rootsFile)
    File.open(rootsFile).each do |line|
      line = line.split("#")[0].strip.gsub(/[\\]/,'/')
      if line != ""
        root = Root.extract_depth(line)
        root.dir = root.dir[0..-2] if root.dir.end_with?("/")
        if !File.is_absolute?(root.dir)
          root.dir = File.expand_path(File.dirname(rootsFile) + "/" + root.dir)
        end
        def_roots << root
      end
    end
  end
  return def_roots
end
equal(rootArrayA, rootArrayB) click to toggle source
# File lib/common/root.rb, line 40
def self.equal(rootArrayA, rootArrayB)
  return false if rootArrayA.length != rootArrayB.length
  rootArrayA.each_with_index do |a, i|
    b = rootArrayB[i]
    return false if (a.dir != b.dir) || (a.depth != b.depth)
  end
  return true
end
extract_depth(str) click to toggle source
# File lib/common/root.rb, line 30
def self.extract_depth(str)
  regex = /\s*(\S*)\s*,\s*(\d+)\s*\z/
  scan_res = str.scan(regex)
  if scan_res.length > 0
    return Root.new(scan_res[0][0],scan_res[0][1].to_i)
  else
    return Root.new(str, nil)
  end
end
new(directory,search_depth) click to toggle source
# File lib/common/root.rb, line 7
def initialize(directory,search_depth)
  @dir = directory
  @depth = search_depth
end
searchRootsFile(dir) click to toggle source
# File lib/common/root.rb, line 49
def self.searchRootsFile(dir)
  rootsFile = dir+"/roots.bake"
  return rootsFile if File.exist?(rootsFile)

  parent = File.dirname(dir)
  return searchRootsFile(parent) if parent != dir

  return nil
end
search_to_depth(root, baseName, depth) click to toggle source
# File lib/common/root.rb, line 82
def self.search_to_depth(root, baseName, depth)
  return Dir.glob(baseName) if File.is_absolute?(baseName)
  if not File.exist?(root)
    Bake.formatter.printError("Root #{root} does not exist.")
    ExitHelper.exit(1)
  end
  if depth != nil
    array = Array.new(depth+1) {|i| root + '/*'*i + '/' + baseName}
    return Dir.glob(array).sort
  else
    # when using junctions, /**/ does not work, so the glob is splitted into two globs to find at least first level projects
    str1 = "#{root}/#{baseName}"
    str2 = "#{root}/*/**/#{baseName}"
    return (Dir.glob(str1) + Dir.glob(str2)).sort
  end
end
uniq(array) click to toggle source
# File lib/common/root.rb, line 12
def self.uniq(array)
  maxDepth = {}
  newArray = []
  array.each do |r|
    if maxDepth.has_key?r.dir
      d = maxDepth[r.dir]
      if !d.nil? && (r.depth.nil? || d < r.depth) # not covered yet
        newArray << r
        maxDepth[r.dir] = r.depth
      end
    else
      newArray << r
      maxDepth[r.dir] = r.depth
    end
  end
  return newArray
end