Class: Mappum::JavaSupport

Inherits:
Object show all
Defined in:
lib/mappum/java_transform.rb

Overview

Utility class providing some usefull methods in java.

Class Method Summary collapse

Class Method Details

.list_maps_on_cp(dir = "map") ⇒ Object

List map files on classpath.



121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
# File 'lib/mappum/java_transform.rb', line 121

def self.list_maps_on_cp(dir="map")
  dir="map" if dir.nil?
  thread = java.lang.Thread.new
  class_loader = thread.context_class_loader
  container_urls = class_loader.find_resources(dir).to_a
  maplist = []
  container_urls.each do |url|
    if url.protocol == "file"
      filelist = Dir.glob(File.join(url.path,"*.rb"))
      #make paths relative again
      maplist += filelist.collect{|f| f[(url.path.size-dir.size)..-1]}
    elsif url.protocol ==  "vfsfile"
      filelist = Dir.glob(File.join(url.path,"*.rb"))
      #make paths relative again
      maplist += filelist.collect{|f| f[(url.path.size-dir.size-1)..-1]}
    elsif url.protocol == "jar"
      #beware nestet url
      path = URI.new(url.path).path
      path = path[0..(path.rindex("!")-1)]
      zip = java.util.zip.ZipFile.new(path)
      names = zip.entries.to_a.collect{|ze| ze.name}
      maplist += names.select{|nm| nm.index("map") == 0 and nm[-3..-1] == ".rb"}
    else
      #ups
      puts "WARN: Unknown protocol #{url.protocol} on the classpath. When looking for #{dir} in #{__FILE__}"
    end
  end
  return maplist
end