Skip to content

Instantly share code, notes, and snippets.

@gangmax
Created March 14, 2013 09:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gangmax/5159938 to your computer and use it in GitHub Desktop.
Save gangmax/5159938 to your computer and use it in GitHub Desktop.
A Ruby code snippet whose function is to search the missing required OSGi bundles of a given one, recursively.
require 'zip/zip'
def load_manifest(properties_content)
properties = {}
last_key = ""
last_value = ""
properties_content.each_line do |line|
line.strip!
if (line[0] != ?# and line[0] != ?=)
i = line.index(': ')
if (i)
last_key = line[0..i - 1].strip
last_value = line[i + 1..-1].strip
properties[last_key] = last_value
else
properties[last_key] = properties[last_key] + line
end
end
end
properties
end
def load_required_bundles(file_content)
bundles = []
bundle_string = load_manifest(file_content)['Require-Bundle']
if(!bundle_string)
return nil
end
# puts "bundle_string: " + bundle_string
raw_required_bundles = bundle_string.split(",")
# puts "raw_required_bundles: #{raw_required_bundles}"
raw_required_bundles.each do |line|
i = line.index(';')
if (i)
value = line[0..i - 1].strip
if(!value.match(/^\d.+/))
bundles.push(value)
end
else
value = line
if(!value.match(/^\d.+/))
bundles.push(value)
end
end
end
bundles
end
def load_required_bundles_from_jarfile(jarfile)
# puts "jarfile=#{jarfile}"
file_content = Zip::ZipFile.new(jarfile).read("META-INF/MANIFEST.MF")
# puts "file_content is: #{file_content}"
bundles = load_required_bundles(file_content)
# puts "bundles = #{bundles}"
bundles
end
def found_not_existing_bundles(bundle_file, target_dir = "/home/user/coderoot/rtc/icap/com.ibm.ws.icap.dt.fat/osgi_lib", base_eclipse_dir = "/home/user/java/eclipse_javaee_3.7.1", bundles_not_existing)
required_bundles = load_required_bundles_from_jarfile(bundle_file)
if(!required_bundles || required_bundles.size<=0)
return
end
# puts required_bundles
current_level_bundles_not_existing = []
required_bundles.each do |bundle|
search_result = Dir.glob("#{target_dir}/**/#{bundle}_*.jar")
# puts search_result
if(search_result.size==0)
# puts "missing_bundle: #{bundle}"
bundles_not_existing.push(bundle)
current_level_bundles_not_existing.push(bundle)
end
end
if (current_level_bundles_not_existing.size>0)
current_level_bundles_not_existing.each do |missing_bundle|
search_result = Dir.glob("#{base_eclipse_dir}/**/#{missing_bundle}_*.jar")
if(search_result.size>0)
found_not_existing_bundles(search_result[0], target_dir, base_eclipse_dir, bundles_not_existing)
else
puts "search_result is null for '#{base_eclipse_dir}/**/#{missing_bundle}_*.jar'!!!!!!!!!!!!!!"
end
end
end
end
bundles_not_existing = []
base_eclipse_dir = "/home/user/java/eclipse_javaee_3.7.1"
found_not_existing_bundles('/home/user/java/eclipse_javaee_3.7.1/plugins/org.eclipse.ant.ui_3.5.100.v20110510.jar', "/home/user/coderoot/rtc/icap/com.ibm.ws.icap.dt.fat/osgi_lib", base_eclipse_dir, bundles_not_existing)
puts "bundles_not_existing======#{bundles_not_existing.uniq}"
bundles_not_existing.uniq.each do |bundle|
search_result = Dir.glob("#{base_eclipse_dir}/**/#{bundle}_*.jar")
if(search_result.size>0)
puts "#{search_result[0]}"
# system("cp #{search_result[0]} /home/user/temp/osgi")
else
puts "#{bundle} is not found!"
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment