Class: Eclipse::Plugin::Info
- Inherits:
-
Object
- Object
- Eclipse::Plugin::Info
- Defined in:
- lib/eclipse/plugin.rb
Defined Under Namespace
Classes: Category, UI_Perspective, UI_PreferencePage, UI_View
Constant Summary collapse
- LINE_SEPARATOR =
method parse copied from buildr.apache.org/lib/buildr/java/packaging.rb Avoids pulling in buildr with a lot of dependencies :call-seq:
parse(str) => manifestParse a string in MANIFEST.MF format and return a new Manifest.
/\r\n|\n|\r[^\n]/- SECTION_SEPARATOR =
:nodoc:
/(#{LINE_SEPARATOR}){2}/
Instance Attribute Summary collapse
-
#feature ⇒ Object
readonly
Returns the value of attribute feature.
-
#iso ⇒ Object
readonly
Returns the value of attribute iso.
-
#jar_or_src ⇒ Object
readonly
Returns the value of attribute jar_or_src.
-
#perspectives ⇒ Object
readonly
Returns the value of attribute perspectives.
-
#preferencePage_categories ⇒ Object
readonly
Returns the value of attribute preferencePage_categories.
-
#preferencePages ⇒ Object
readonly
Returns the value of attribute preferencePages.
-
#symbolicName ⇒ Object
readonly
Returns the value of attribute symbolicName.
-
#view_categories ⇒ Object
readonly
Returns the value of attribute view_categories.
-
#views ⇒ Object
readonly
Returns the value of attribute views.
-
#workspace ⇒ Object
readonly
Returns the value of attribute workspace.
Instance Method Summary collapse
- #addCategory(hash, id, name = nil) ⇒ Object
- #getSymbolicNameFrom(content) ⇒ Object
- #getTranslatedPerspectives ⇒ Object
- #getTranslatedPreferencePages ⇒ Object
- #getTranslatedViews ⇒ Object
- #getTranslationForPlugin(look_for, iso) ⇒ Object
-
#initialize(jar_or_src, iso = 'de') ⇒ Info
constructor
A new instance of Info.
- #parse(str) ⇒ Object
- #readPluginXML(plugin) ⇒ Object
- #show ⇒ Object
Constructor Details
#initialize(jar_or_src, iso = 'de') ⇒ Info
Returns a new instance of Info.
45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 |
# File 'lib/eclipse/plugin.rb', line 45 def initialize(jar_or_src, iso='de') @workspace = File.dirname(jar_or_src).sub(/\/plugins$/, '') @iso = iso @jar_or_src = jar_or_src @feature = nil @views = Hash.new @view_categories = Hash.new @preferencePages = Hash.new @perspectives = Hash.new @preferencePage_categories = Hash.new # we use hashes to be able to find the categories fast if File.directory?(jar_or_src) @jarfile = nil readPluginXML(jar_or_src) mfName = File.join(jar_or_src, 'META-INF', 'MANIFEST.MF') featureName = File.join(jar_or_src, 'feature.xml') if File.exist?(mfName) getSymbolicNameFrom(File.read(mfName)) elsif File.exist?(featureName) @feature = Feature::Info.new(jar_or_src) elsif File.exist?(featureName) @feature = Feature::Info.new(featureName) else # puts "Skipping #{jar_or_src} #{featureName}" end else @jarfile = Zip::File.open(jar_or_src) readPluginXML(File.basename(jar_or_src)) if @jarfile.find_entry('feature.xml') @feature = Feature::Info.new(jar_or_src) elsif @jarfile.find_entry('META-INF/MANIFEST.MF') getSymbolicNameFrom(@jarfile.read('META-INF/MANIFEST.MF')) end end # @nonfree = /medelexis/i.match(File.dirname(File.dirname(plugin))) end |
Instance Attribute Details
#feature ⇒ Object (readonly)
Returns the value of attribute feature.
13 14 15 |
# File 'lib/eclipse/plugin.rb', line 13 def feature @feature end |
#iso ⇒ Object (readonly)
Returns the value of attribute iso.
12 13 14 |
# File 'lib/eclipse/plugin.rb', line 12 def iso @iso end |
#jar_or_src ⇒ Object (readonly)
Returns the value of attribute jar_or_src.
13 14 15 |
# File 'lib/eclipse/plugin.rb', line 13 def jar_or_src @jar_or_src end |
#perspectives ⇒ Object (readonly)
Returns the value of attribute perspectives.
12 13 14 |
# File 'lib/eclipse/plugin.rb', line 12 def perspectives @perspectives end |
#preferencePage_categories ⇒ Object (readonly)
Returns the value of attribute preferencePage_categories.
12 13 14 |
# File 'lib/eclipse/plugin.rb', line 12 def preferencePage_categories @preferencePage_categories end |
#preferencePages ⇒ Object (readonly)
Returns the value of attribute preferencePages.
12 13 14 |
# File 'lib/eclipse/plugin.rb', line 12 def preferencePages @preferencePages end |
#symbolicName ⇒ Object (readonly)
Returns the value of attribute symbolicName.
13 14 15 |
# File 'lib/eclipse/plugin.rb', line 13 def symbolicName @symbolicName end |
#view_categories ⇒ Object (readonly)
Returns the value of attribute view_categories.
12 13 14 |
# File 'lib/eclipse/plugin.rb', line 12 def view_categories @view_categories end |
#views ⇒ Object (readonly)
Returns the value of attribute views.
12 13 14 |
# File 'lib/eclipse/plugin.rb', line 12 def views @views end |
#workspace ⇒ Object (readonly)
Returns the value of attribute workspace.
12 13 14 |
# File 'lib/eclipse/plugin.rb', line 12 def workspace @workspace end |
Instance Method Details
#addCategory(hash, id, name = nil) ⇒ Object
86 87 88 89 90 91 92 |
# File 'lib/eclipse/plugin.rb', line 86 def addCategory(hash, id, name = nil) return if hash[id] and hash[id].translation hash[id] = Category.new(id, name) unless hash[id] translation = getTranslationForPlugin(name, @iso) if name hash[id].translation = translation if name and translation puts "Added category #{id} name #{name} tr '#{translation}'" if $VERBOSE end |
#getSymbolicNameFrom(content) ⇒ Object
176 177 178 179 180 181 |
# File 'lib/eclipse/plugin.rb', line 176 def getSymbolicNameFrom(content) if content mf = parse(content) @symbolicName = mf[0]['Bundle-SymbolicName'].split(';')[0] end end |
#getTranslatedPerspectives ⇒ Object
132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 |
# File 'lib/eclipse/plugin.rb', line 132 def getTranslatedPerspectives all = [] @perspectives.each{ |id, content| category = content.category cat_trans = content.translation text = nil if category text = "#{@perspectives[category].translation}/#{content.translation}" puts "perspectives #{id} category #{category.inspect} text #{cat_trans}" if $VERBOSE else text = content.translation puts "perspectives #{id} categories #{category} text #{text}" if $VERBOSE end all << text } all.sort.reverse.uniq if all and all.size > 0 end |
#getTranslatedPreferencePages ⇒ Object
94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 |
# File 'lib/eclipse/plugin.rb', line 94 def getTranslatedPreferencePages all = [] @preferencePages.each{ |id, content| unless content.category next if @preferencePages.find { |sub_id, x| x.category.eql?(content.id) } end category = content.category cat_trans = content.translation text = nil if @preferencePage_categories[category] text = "#{@preferencePage_categories[category].translation}/#{content.translation}" puts "preferencePages #{id} category #{category.inspect} text #{cat_trans}" if $VERBOSE else text = content.translation puts "preferencePages #{id} text #{text}" if $VERBOSE end all << text } all.sort.reverse.uniq if all and all.size > 0 end |
#getTranslatedViews ⇒ Object
116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 |
# File 'lib/eclipse/plugin.rb', line 116 def getTranslatedViews all = [] @views.each{ |id, content| category = content.category cat_trans = content.translation text = nil if category text = "#{@view_categories[category].translation}/#{content.translation}" else text = "Other/#{content.translation}" end all << text if text } all.sort.reverse.uniq if all and all.size > 0 end |
#getTranslationForPlugin(look_for, iso) ⇒ Object
151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 |
# File 'lib/eclipse/plugin.rb', line 151 def getTranslationForPlugin(look_for, iso) properties = "plugin_#{iso}.properties" puts "Looking for translation of #{look_for} in #{properties}" if $VERBOSE content = nil if @jarfile content = @jarfile.read(properties) if @jarfile.find_entry(properties) else name = File.join(@jar_or_src, "plugin.properties") properties = File.new(name).read if File.exist?(name) end return look_for unless content line_nr = 0 content.split("\n").each { |line| line_nr += 1 id,value = line.split(' = ') if id and id.index(look_for) and value return Helpers::unescape(value.sub("\r","").sub("\n","")) else id,value = line.split('=') return Helpers::unescape(value.sub("\r","").sub("\n","")) if id and id.index(look_for) end } return look_for # default end |
#parse(str) ⇒ Object
28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/eclipse/plugin.rb', line 28 def parse(str) sections = str.split(SECTION_SEPARATOR).reject { |s| s.strip.empty? } sections = sections.map { |section| lines = section.split(LINE_SEPARATOR).inject([]) { |merged, line| if line[/^ /] == ' ' merged.last << line[1..-1] else merged << line end merged } lines.map { |line| line.scan(/(.*?):\s*(.*)/).first }. inject({}) { |map, (key, value)| map.merge(key=>value) } } sections end |
#readPluginXML(plugin) ⇒ Object
183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 |
# File 'lib/eclipse/plugin.rb', line 183 def readPluginXML(plugin) if @jarfile return unless @jarfile.find_entry('plugin.xml') doc = Document.new @jarfile.read('plugin.xml') else plugin_xml = File.join(plugin, 'plugin.xml') return unless File.exist?(plugin_xml) doc = Document.new File.new(plugin_xml).read end # Get all perspectives root = doc.root res = [] root.elements.collect { |x| res << x if /org.eclipse.ui.perspectives/.match(x.attributes['point']) } res[0].elements.each{ |x| id = x.attributes['name'].sub(/^%/,'') @perspectives[id] = UI_Perspective.new(id, nil, getTranslationForPlugin(id, @iso)) } if res and res[0] and res[0].elements puts "found #{@perspectives.size} perspectives in #{plugin}" if $VERBOSE # Get all views res = [] root.elements.collect { |x| res << x if /org.eclipse.ui.views/.match(x.attributes['point']) } res[0].elements.each{ |x| name = x.attributes['name'].sub(/^%/,'') if x.attributes['name'] id = x.attributes['id'].sub(/^%/,'') if x.name.eql?('category') addCategory(@view_categories, id, name) elsif x.attributes['name'] category = x.attributes['category'] translation = getTranslationForPlugin(name, @iso) puts "Adding view: id #{id} category #{category.inspect} translation #{translation}" if $VERBOSE unless category @views[id] = UI_View.new(id, nil, translation) else @views[id] = UI_View.new(id, category, translation) end end } if res and res[0] and res[0].elements puts "found #{@views.size} views and #{@view_categories.size} categories" if $VERBOSE # Get all preferencePages res = [] root.elements.collect { |x| res << x if /org.eclipse.ui.preferencePages/.match(x.attributes['point']) } res[0].elements.each{ |x| name = x.attributes['name'].sub(/^%/,'') id = x.attributes['id'].sub(/^%/,'') category = x.attributes['category'] addCategory(@preferencePage_categories, id, name) unless category translation = getTranslationForPlugin(name, @iso) puts "Adding preferences: id #{id} category #{category.inspect} translation #{translation}" if $VERBOSE unless category @preferencePages[id] = UI_PreferencePage.new(id, nil, translation) else @preferencePages[id] = UI_PreferencePage.new(id, category, translation) end } if res and res[0] and res[0].elements puts "#{sprintf("%-40s", File.basename(File.dirname(plugin)))}: now #{@preferencePages.size} preferencePages" if $VERBOSE end |
#show ⇒ Object
82 83 84 |
# File 'lib/eclipse/plugin.rb', line 82 def show puts "Plugin: #{@jar_or_src} with #{@views.size}/#{@view_categories.size} views #{@preferencePages.size}/#{@preferencePage_categories.size} preferencePages #{@perspectives.size} perspectives" end |