Module: Buildr4OSGi::LibraryProjectExtension

Includes:
Extension
Included in:
Buildr4OSGi, Buildr::Project
Defined in:
lib/buildr4osgi/osgi/library_extension.rb

Instance Method Summary collapse

Instance Method Details

#library_project(dependencies, group, name, version, options = {:exclude => ["META-INF/MANIFEST.MF"], :include => [], :manifest => {}}) ⇒ Object

Defines a project as the merge of the dependencies. group: the group of the project to define name: the name of the project to define version: the version of the project to define



104
105
106
107
108
109
110
111
112
113
114
115
116
117
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
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
# File 'lib/buildr4osgi/osgi/library_extension.rb', line 104

def library_project(dependencies, group, name, version, options = {:exclude => ["META-INF/MANIFEST.MF"], :include => [], :manifest => {}})
  options[:manifest] ||= {} 
  options[:include] ||= []
  options[:exclude] ||= []
  deps_as_str = []
  # We create an object and we extend with the module so we can get access to the walk_libs method.
  walker = Object.new 
  walker.extend Buildr4OSGi::BuildLibraries::LibraryProject
  walker.walk_libs(dependencies) {|lib|
    deps_as_str << lib.to_spec
  }
  deps_as_str = deps_as_str.flatten.inspect
  exclusion = options[:exclude].collect {|exclusion| ".exclude(#{exclusion.inspect})"}.join if options[:exclude]
  inclusion = options[:include].collect {|inclusion| ".include(#{inclusion.inspect})"}.join if options[:include]
  exclusion ||= ""
  inclusion ||= ""
  eval %{
    desc "#{name}"
    define "#{name}" do
      project.extend Buildr4OSGi::LibraryProject
      #{"project.version = \"#{version}\"" if version}
      #{"project.group = \"#{group}\"" if group}

      package(:library_project).tap {|jar|
        jar.enhance {|task|
          walk_libs(#{deps_as_str}) {|lib|
            lib.invoke # make sure the artifact is present.
            task.merge(lib)#{exclusion}#{inclusion}
          }
        }
        entries = []
        names = []
        walk_libs(#{deps_as_str}) {|lib|
          names << lib.to_spec 
          lib.invoke # make sure the artifact is present.
          Zip::ZipFile.foreach(lib.to_s) {|entry| 
            if /.*\\.class$/.match(entry.name)
              add_to_entries = true
              [#{options[:exclude].inspect}].flatten.each {|excluded|
                add_to_entries &&= !entry.name.match(excluded)
              }
              [#{options[:include].inspect}].flatten.each {|included|
                add_to_entries &&= included.match(entry.name)
              }
              entries << entry.name.sub(/(.*)\\/.*.class$/, '\\1').gsub(/\\//, '.') if add_to_entries
            end
          }
        }
        lib_manifest = { 
          "Bundle-Version" => "#{version}",
          "Bundle-SymbolicName" => project.name,
          "Bundle-Name" => names.join(", "),
          "Bundle-Vendor" => "Intalio, Inc."
        }
        lib_manifest["Export-Package"] = entries.uniq.sort.join(",") unless entries.empty?
        lib_manifest["Bundle-ManifestVersion"] = "2"
        jar.with :manifest => lib_manifest.merge(#{options[:manifest].inspect})
        
        
      }
      package(:sources).tap do |task|
        task.enhance do
          walk_libs(#{deps_as_str}) {|lib|
            lib_src = Buildr::artifact(lib.to_hash.merge(:classifier => "sources"))
            lib_src.extend Buildr4OSGi::SkipSourceDownload
            lib_src.invoke # make sure the artifact is present.
            
            task.merge(lib_src)#{exclusion}#{inclusion} if File.exist?(lib_src.to_s)
          }
        end
      end
    end
  }
end