Module: Buildr4OSGi::BuildLibraries::LibraryProject

Defined in:
lib/buildr4osgi/osgi/library_extension.rb

Overview

A small extension contributed to projects that are library projects so we can walk the libraries we pass to them.

Instance Method Summary collapse

Instance Method Details

#package_as_library_project(file_name) ⇒ Object



46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
# File 'lib/buildr4osgi/osgi/library_extension.rb', line 46

def package_as_library_project(file_name)
  ::OSGi::BundleTask.define_task(file_name).tap do |plugin|

    manifest_location = File.join(project.base_dir, "META-INF", "MANIFEST.MF")
    manifest = project.manifest
    if File.exists?(manifest_location)
      read_m = ::Buildr::Packaging::Java::Manifest.parse(File.read(manifest_location)).main
      manifest = project.manifest.merge(read_m)
    end
    manifest["Bundle-Version"] = project.version # the version of the bundle packaged is ALWAYS the version of the project.
    manifest["Bundle-SymbolicName"] ||= project.id.split(":").last # if it was resetted to nil, we force the id to be added back.

    plugin.with :manifest=> manifest, :meta_inf=>meta_inf
    plugin.with [compile.target, resources.target].compact
  end

end

#package_as_library_project_spec(spec) ⇒ Object

:nodoc:



64
65
66
# File 'lib/buildr4osgi/osgi/library_extension.rb', line 64

def package_as_library_project_spec(spec) #:nodoc:
  spec.merge(:type=>:jar)
end

#walk_libs(lib, &block) ⇒ Object

Walks the libraries passed in parameter, passing each library to the block.



30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/buildr4osgi/osgi/library_extension.rb', line 30

def walk_libs(lib, &block)
  if (lib.is_a?(Struct) || lib.is_a?(Array))
    lib.each {|structdep|
      walk_libs(structdep, &block)
    }
    return
  end
  lib_artifact = case 
  when lib.is_a?(Artifact)  then lib
  when lib.is_a?(String) then Buildr::artifact(lib)
  else
    raise "Don't know how to interpret lib #{lib}"
  end
  block.call(lib_artifact)
end