Class: Buildr4OSGi::SiteTask

Inherits:
Buildr::Packaging::Java::JarTask
  • Object
show all
Includes:
SitePackaging
Defined in:
lib/buildr4osgi/eclipse/site.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(*args) ⇒ SiteTask

:nodoc:



114
115
116
# File 'lib/buildr4osgi/eclipse/site.rb', line 114

def initialize(*args) #:nodoc:
  super
end

Instance Attribute Details

#site_xmlObject

Returns the value of attribute site_xml.



112
113
114
# File 'lib/buildr4osgi/eclipse/site.rb', line 112

def site_xml
  @site_xml
end

Instance Method Details

#generateSite(project) ⇒ Object



118
119
120
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
150
151
152
153
154
# File 'lib/buildr4osgi/eclipse/site.rb', line 118

def generateSite(project)
  mkpath File.join(project.base_dir, 'target')
  feature_files = find_feature_files()
  info = {}
  for feature in feature_files
    dir = File.join(project.base_dir, 'target', File.basename(feature.to_s, ".*"))
    
    feature_xml = nil
    feature_info = {}
    info[feature.to_s] = feature_info
    Zip::ZipFile.open(feature.to_s) do |zip|
      
      feature_xml = zip.read(zip.entries.select {|entry| entry.name.to_s.match(".*/feature\.xml")}.first)
      doc = REXML::Document.new(feature_xml)
      feature_info[:id] = REXML::XPath.first(doc, "/feature/@id")
      feature_info[:version] = REXML::XPath.first(doc, "/feature/@version")
    end
    unzip = Buildr::unzip(dir => feature.to_s)
    
    unzip.target.invoke
    include(File.join(dir, "eclipse", "plugins", "*"), :path => "plugins")
    
    Dir.glob(File.join(dir, "eclipse", "features", "*")).each do |feature_dir|
      Buildr::zip(File.join(dir, "features", "#{File.basename(feature_dir)}.jar")).include(File.join(feature_dir, "*")).invoke
      path("features").include File.join(dir, "features", "#{File.basename(feature_dir)}.jar")
    end
  end
  if site_xml
    path("").include site_xml
  else
    File.open(File.join(project.base_dir, 'target', 'site.xml'), 'w') do |f|
      f.write(writeSiteXml(info))
    end
    path("").include File.join(project.base_dir, 'target', 'site.xml')
  end

end