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
Instance Attribute Summary collapse
-
#iso ⇒ Object
readonly
Returns the value of attribute iso.
-
#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.
-
#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
- #getTranslatedPerspectives ⇒ Object
- #getTranslatedPreferencePages ⇒ Object
- #getTranslatedViews ⇒ Object
- #getTranslationForPlugin(look_for, iso) ⇒ Object
-
#initialize(jar_or_src, iso = 'de') ⇒ Info
constructor
A new instance of Info.
- #readPluginXML(plugin) ⇒ Object
- #show ⇒ Object
Constructor Details
#initialize(jar_or_src, iso = 'de') ⇒ Info
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 |
# File 'lib/eclipse/plugin.rb', line 54 def initialize(jar_or_src, iso='de') @workspace = File.dirname(jar_or_src).sub(/\/plugins$/, '') @iso = iso @jar_or_src = jar_or_src @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) else # @jarname = jar_or_src @jarfile = Zip::ZipFile.open(jar_or_src) readPluginXML(File.basename(jar_or_src)) end if false # rescue => e # HACK: we need this to handle org.apache.commons.lang under Windows-7 puts "Skipped plugin #{File.expand_path(jar_or_src)}" # puts "error was #{e.inspect}" puts caller end end |
Instance Attribute Details
#iso ⇒ Object (readonly)
Returns the value of attribute iso.
47 48 49 |
# File 'lib/eclipse/plugin.rb', line 47 def iso @iso end |
#perspectives ⇒ Object (readonly)
Returns the value of attribute perspectives.
47 48 49 |
# File 'lib/eclipse/plugin.rb', line 47 def perspectives @perspectives end |
#preferencePage_categories ⇒ Object (readonly)
Returns the value of attribute preferencePage_categories.
47 48 49 |
# File 'lib/eclipse/plugin.rb', line 47 def preferencePage_categories @preferencePage_categories end |
#preferencePages ⇒ Object (readonly)
Returns the value of attribute preferencePages.
47 48 49 |
# File 'lib/eclipse/plugin.rb', line 47 def preferencePages @preferencePages end |
#view_categories ⇒ Object (readonly)
Returns the value of attribute view_categories.
47 48 49 |
# File 'lib/eclipse/plugin.rb', line 47 def view_categories @view_categories end |
#views ⇒ Object (readonly)
Returns the value of attribute views.
47 48 49 |
# File 'lib/eclipse/plugin.rb', line 47 def views @views end |
#workspace ⇒ Object (readonly)
Returns the value of attribute workspace.
47 48 49 |
# File 'lib/eclipse/plugin.rb', line 47 def workspace @workspace end |
Instance Method Details
#addCategory(hash, id, name = nil) ⇒ Object
84 85 86 87 88 89 90 |
# File 'lib/eclipse/plugin.rb', line 84 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 "#{File.basename(@jarname)}: Added category #{id} name #{name} tr '#{translation}'" if $VERBOSE end |
#getTranslatedPerspectives ⇒ Object
130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 |
# File 'lib/eclipse/plugin.rb', line 130 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
92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 |
# File 'lib/eclipse/plugin.rb', line 92 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
114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 |
# File 'lib/eclipse/plugin.rb', line 114 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
149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 |
# File 'lib/eclipse/plugin.rb', line 149 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 properties = File.new(File.join(@jar_or_src, "plugin.properties")).read 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 |
#readPluginXML(plugin) ⇒ Object
173 174 175 176 177 178 179 180 181 182 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 |
# File 'lib/eclipse/plugin.rb', line 173 def readPluginXML(plugin) if @jarfile return unless @jarfile.find_entry('plugin.xml') doc = Document.new @jarfile.read('plugin.xml') else doc = Document.new File.new(File.join(plugin, '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 "#{File.basename(@jarname, '.jar')}: 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
80 81 82 |
# File 'lib/eclipse/plugin.rb', line 80 def show puts "Plugin: #{@jar_or_src} with #{@views.size}/#{@view_categories.size} views #{@preferencePages.size}/#{@preferencePage_categories.size} preferencePages #{@perspectives.size} perspectives" end |