Class: Eclipse::Plugin
- Inherits:
-
Object
- Object
- Eclipse::Plugin
- Defined in:
- lib/eclipsehelp.rb
Overview
The plugin class generates the an Eclipse plugin jar. This plugin jar extends the eclipse help toc and can be used as drop-in help for any Eclipse based application.
It is important to note that this generates a plugin compatable with Eclipse >=3.1.
More information on Eclipse can be found at the Eclipse web site.
Instance Attribute Summary collapse
-
#id ⇒ Object
Returns the value of attribute id.
-
#name ⇒ Object
Returns the value of attribute name.
-
#tocs ⇒ Object
Returns the value of attribute tocs.
-
#vendor ⇒ Object
Returns the value of attribute vendor.
-
#version ⇒ Object
Returns the value of attribute version.
Instance Method Summary collapse
-
#initialize(plugin) ⇒ Plugin
constructor
A new instance of Plugin.
-
#make_file_from(old_help) ⇒ Object
Make Eclipse Plugin help from the old help object.
-
#write_manifest(out) ⇒ Object
Writes the plugin manifest with the name, id, version, and vendor of the plugin.
-
#write_pluginxml(out) ⇒ Object
Writes the plugin xml that extends org.eclipse.help.toc.
-
#write_toc_links(out) ⇒ Object
Writes toc_links.xml file.
Constructor Details
#initialize(plugin) ⇒ Plugin
Returns a new instance of Plugin.
18 19 20 21 22 23 24 |
# File 'lib/eclipsehelp.rb', line 18 def initialize(plugin) raise "Eclipse plugin is missing" if plugin.nil? or plugin.length == 0 @plugin = plugin @tocs = [] @vendor = nil parse(plugin) end |
Instance Attribute Details
#id ⇒ Object
Returns the value of attribute id.
16 17 18 |
# File 'lib/eclipsehelp.rb', line 16 def id @id end |
#name ⇒ Object
Returns the value of attribute name.
16 17 18 |
# File 'lib/eclipsehelp.rb', line 16 def name @name end |
#tocs ⇒ Object
Returns the value of attribute tocs.
16 17 18 |
# File 'lib/eclipsehelp.rb', line 16 def tocs @tocs end |
#vendor ⇒ Object
Returns the value of attribute vendor.
16 17 18 |
# File 'lib/eclipsehelp.rb', line 16 def vendor @vendor end |
#version ⇒ Object
Returns the value of attribute version.
16 17 18 |
# File 'lib/eclipsehelp.rb', line 16 def version @version end |
Instance Method Details
#make_file_from(old_help) ⇒ Object
Make Eclipse Plugin help from the old help object. old_help need to implement the methods convert_tocs and copyContentsTo(zipFile). An example of this implementation is JavaHelp::JarConverter
29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 |
# File 'lib/eclipsehelp.rb', line 29 def make_file_from(old_help) @tocs = old_help.convert_tocs = File.(@plugin) parent_path = File.dirname() FileUtils::mkpath(parent_path) unless File.exists?(parent_path) if @version.nil? puts "No plugin version set. Using 1.0.0" @version = '1.0.0' end file_name = File.join(parent_path, "#{@id}_#{@version}.jar") File.delete(file_name) if File.exists?(file_name) f = Zip::ZipFile.new(file_name, Zip::ZipFile::CREATE) begin old_help.copyContentsTo(f) do |entry| lower_name = entry.name.downcase ext = File.extname(lower_name) invalid_exts = ['.mf', '.hs', '.jhm'] entry.file? unless invalid_exts.include?(ext) end f.get_output_stream('META-INF/MANIFEST.MF') {|out| write_manifest(out)} f.get_output_stream('plugin.xml') {|out| write_pluginxml(out)} f.get_output_stream('toc_links.xml') {|out| write_toc_links(out)} @tocs.each do |toc| f.get_output_stream(toc.name) {|out| out.write(toc.xml)} end puts file_name ensure f.close unless f.nil? end end |
#write_manifest(out) ⇒ Object
Writes the plugin manifest with the name, id, version, and vendor of the plugin
64 65 66 67 68 69 70 71 72 73 74 |
# File 'lib/eclipsehelp.rb', line 64 def write_manifest(out) out << "Manifest-Version: 1.0\n" out << "Bundle-ManifestVersion: 2\n" out << "Bundle-Name: #@name\n" out << "Bundle-SymbolicName: #@id; singleton:=true\n" out << "Bundle-Version: #@version\n" out << "Bundle-Localization: plugin\n" unless @vendor.nil? out << "Bundle-Vendor: #@vendor\n" end end |
#write_pluginxml(out) ⇒ Object
Writes the plugin xml that extends org.eclipse.help.toc
77 78 79 80 81 82 83 84 85 86 87 88 89 90 |
# File 'lib/eclipsehelp.rb', line 77 def write_pluginxml(out) raise "I couldn't find any table of contents." unless @tocs.size > 0 out << %Q{<?xml version="1.0" encoding="UTF-8"?>\n} out << %Q{<?eclipse version="3.0"?>\n} out << %Q{<plugin>\n} out << %Q{ <extension point="org.eclipse.help.toc">\n} @tocs.each do |toc| out << %Q{ <toc file="#{toc.name}"/>\n} end out << %Q{ <toc file="toc_links.xml" primary="true"/>\n} out << %Q{ </extension>\n} out << %Q{</plugin>\n} end |
#write_toc_links(out) ⇒ Object
Writes toc_links.xml file.
The purpose of this file is to assemble references to all of the converted table of contents files.
96 97 98 99 100 101 102 103 104 |
# File 'lib/eclipsehelp.rb', line 96 def write_toc_links(out) out << %Q{<?xml version="1.0" encoding="UTF-8"?>\n} out << %Q{<?NLS TYPE="org.eclipse.help.toc"?>\n\n} out << %Q{<toc label="#{@name}">\n} @tocs.each do |toc| out << %Q{ <link toc="#{toc.name}"/>\n} end out << %Q{</toc>\n} end |