buildr4osgi 0.9.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/LICENSE +176 -0
- data/NOTICE +6 -0
- data/README.rdoc +50 -0
- data/Rakefile +45 -0
- data/buildr4osgi.gemspec +40 -0
- data/lib/buildr4osgi/compile/compiler.rb +54 -0
- data/lib/buildr4osgi/compile/ecj-3.4.1.jar +0 -0
- data/lib/buildr4osgi/compile.rb +16 -0
- data/lib/buildr4osgi/eclipse/feature.rb +271 -0
- data/lib/buildr4osgi/eclipse/plugin.rb +22 -0
- data/lib/buildr4osgi/eclipse.rb +17 -0
- data/lib/buildr4osgi/nature/eclipse.rb +80 -0
- data/lib/buildr4osgi/nature/java.rb +32 -0
- data/lib/buildr4osgi/nature/nature.rb +156 -0
- data/lib/buildr4osgi/nature/osgi.rb +32 -0
- data/lib/buildr4osgi/nature/scala.rb +32 -0
- data/lib/buildr4osgi/nature.rb +23 -0
- data/lib/buildr4osgi/osgi/bundle.rb +275 -0
- data/lib/buildr4osgi/osgi/bundle_package.rb +80 -0
- data/lib/buildr4osgi/osgi/container.rb +140 -0
- data/lib/buildr4osgi/osgi/library_extension.rb +174 -0
- data/lib/buildr4osgi/osgi/packaging.rb +129 -0
- data/lib/buildr4osgi/osgi/project_extension.rb +324 -0
- data/lib/buildr4osgi/osgi/registry.rb +61 -0
- data/lib/buildr4osgi/osgi/resolving_strategies.rb +104 -0
- data/lib/buildr4osgi/osgi/version.rb +131 -0
- data/lib/buildr4osgi/osgi.rb +24 -0
- data/lib/buildr4osgi.rb +37 -0
- data/rakelib/checks.rake +57 -0
- data/rakelib/doc.rake +92 -0
- data/rakelib/jekylltask.rb +120 -0
- data/rakelib/package.rake +73 -0
- data/rakelib/release.rake +149 -0
- data/rakelib/rspec.rake +73 -0
- data/rakelib/setup.rake +54 -0
- data/rakelib/stage.rake +206 -0
- data/spec/compile/compiler_spec.rb +30 -0
- data/spec/eclipse/feature_spec.rb +295 -0
- data/spec/nature/eclipse_spec.rb +46 -0
- data/spec/nature/java_spec.rb +45 -0
- data/spec/nature/osgi_spec.rb +63 -0
- data/spec/nature/scala_spec.rb +45 -0
- data/spec/nature_spec.rb +144 -0
- data/spec/osgi/bundle_package_spec.rb +32 -0
- data/spec/osgi/bundle_spec.rb +202 -0
- data/spec/osgi/container_spec.rb +93 -0
- data/spec/osgi/library_extension_spec.rb +142 -0
- data/spec/osgi/packaging_spec.rb +340 -0
- data/spec/osgi/plugins/org.eclipse.core.runtime.compatibility.registry_3.2.200.v20090429-1800/META-INF/ECLIPSEF.RSA +0 -0
- data/spec/osgi/plugins/org.eclipse.core.runtime.compatibility.registry_3.2.200.v20090429-1800/META-INF/ECLIPSEF.SF +20 -0
- data/spec/osgi/plugins/org.eclipse.core.runtime.compatibility.registry_3.2.200.v20090429-1800/META-INF/MANIFEST.MF +28 -0
- data/spec/osgi/plugins/org.eclipse.core.runtime.compatibility.registry_3.2.200.v20090429-1800/META-INF/eclipse.inf +3 -0
- data/spec/osgi/plugins/org.eclipse.core.runtime.compatibility.registry_3.2.200.v20090429-1800/about.html +28 -0
- data/spec/osgi/plugins/org.eclipse.core.runtime.compatibility.registry_3.2.200.v20090429-1800/fragment.properties +12 -0
- data/spec/osgi/plugins/org.eclipse.core.runtime.compatibility.registry_3.2.200.v20090429-1800/runtime_registry_compatibility.jar +0 -0
- data/spec/osgi/project_extension_spec.rb +662 -0
- data/spec/osgi/registry_spec.rb +50 -0
- data/spec/osgi/version_spec.rb +127 -0
- data/spec/spec_helpers.rb +85 -0
- data/spec/tmp/remote/eclipse/org.eclipse.debug.ui/3.4.1.v20080811_r341/org.eclipse.debug.ui-3.4.1.v20080811_r341.jar +0 -0
- data/spec/tmp/remote/eclipse/org.eclipse.debug.ui/3.4.1.v20080811_r341/org.eclipse.debug.ui-3.4.1.v20080811_r341.pom +82 -0
- data/spec/tmp/remote/org/slf4j/jcl104-over-slf4j/1.5.8/jcl104-over-slf4j-1.5.8-sources.jar +0 -0
- data/spec/tmp/remote/org/slf4j/jcl104-over-slf4j/1.5.8/jcl104-over-slf4j-1.5.8.jar +0 -0
- data/spec/tmp/remote/org/slf4j/jcl104-over-slf4j/1.5.8/jcl104-over-slf4j-1.5.8.pom +30 -0
- data/spec/tmp/remote/org/slf4j/slf4j-api/1.5.8/slf4j-api-1.5.8-sources.jar +0 -0
- data/spec/tmp/remote/org/slf4j/slf4j-api/1.5.8/slf4j-api-1.5.8.jar +0 -0
- data/spec/tmp/remote/org/slf4j/slf4j-api/1.5.8/slf4j-api-1.5.8.pom +101 -0
- data/spec/tmp/remote/org/slf4j/slf4j-log4j12/1.5.8/slf4j-log4j12-1.5.8-sources.jar +0 -0
- data/spec/tmp/remote/org/slf4j/slf4j-log4j12/1.5.8/slf4j-log4j12-1.5.8.jar +0 -0
- data/spec/tmp/remote/org/slf4j/slf4j-log4j12/1.5.8/slf4j-log4j12-1.5.8.pom +56 -0
- metadata +142 -0
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
# Licensed to the Apache Software Foundation (ASF) under one or more
|
|
2
|
+
# contributor license agreements. See the NOTICE file distributed with this
|
|
3
|
+
# work for additional information regarding copyright ownership. The ASF
|
|
4
|
+
# licenses this file to you under the Apache License, Version 2.0 (the
|
|
5
|
+
# "License"); you may not use this file except in compliance with the License.
|
|
6
|
+
# You may obtain a copy of the License at
|
|
7
|
+
#
|
|
8
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
|
9
|
+
#
|
|
10
|
+
# Unless required by applicable law or agreed to in writing, software
|
|
11
|
+
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
|
12
|
+
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
|
13
|
+
# License for the specific language governing permissions and limitations under
|
|
14
|
+
# the License.
|
|
15
|
+
|
|
16
|
+
module OSGi #:nodoc:
|
|
17
|
+
|
|
18
|
+
# A class to represent an OSGi bundle package.
|
|
19
|
+
# Created from the Import-Package or Provide-Package (Export-Package) header.
|
|
20
|
+
#
|
|
21
|
+
class BundlePackage
|
|
22
|
+
attr_accessor :name, :version, :bundles, :imports, :is_export
|
|
23
|
+
|
|
24
|
+
def initialize(name, version, args = {}) #:nodoc:
|
|
25
|
+
@name= name
|
|
26
|
+
@is_export = args[:is_export]
|
|
27
|
+
@version = (is_export ? version.gsub(/\"/, '') : VersionRange.parse(version, true)) if version
|
|
28
|
+
@bundles = args[:bundles] || []
|
|
29
|
+
@imports = args[:imports] || []
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
#
|
|
33
|
+
# Resolves the matching artifacts associated with the project.
|
|
34
|
+
#
|
|
35
|
+
def resolve_matching_artifacts(project)
|
|
36
|
+
# Collect the bundle projects
|
|
37
|
+
# and extend them with the BundleProjectMatcher module
|
|
38
|
+
b_projects = OSGi::BundleProjects::bundle_projects.select {|p|
|
|
39
|
+
unless p == project
|
|
40
|
+
p.extend OSGi::BundleProjectMatcher
|
|
41
|
+
p.matches(:exports_package => name, :version => version)
|
|
42
|
+
end
|
|
43
|
+
}
|
|
44
|
+
return b_projects unless b_projects.empty?
|
|
45
|
+
|
|
46
|
+
resolved = project.osgi.registry.resolved_containers.collect {|i| i.find(:exports_package => name, :version => version)}
|
|
47
|
+
resolved.flatten.compact.collect{|b| b.dup}
|
|
48
|
+
end
|
|
49
|
+
|
|
50
|
+
# Resolves the bundles that export this package.
|
|
51
|
+
#
|
|
52
|
+
def resolve(project, bundles = resolve_matching_artifacts(project))
|
|
53
|
+
bundles = case bundles.size
|
|
54
|
+
when 0 then []
|
|
55
|
+
when 1 then bundles
|
|
56
|
+
else
|
|
57
|
+
bundles = OSGi::PackageResolvingStrategies.send(project.osgi.options.package_resolving_strategy, name, bundles)
|
|
58
|
+
end
|
|
59
|
+
warn "No bundles found exporting the package #{name}; version=#{version}" if (bundles.empty?)
|
|
60
|
+
bundles
|
|
61
|
+
|
|
62
|
+
end
|
|
63
|
+
|
|
64
|
+
def to_s #:nodoc:
|
|
65
|
+
"Package #{name}; version #{version}"
|
|
66
|
+
end
|
|
67
|
+
|
|
68
|
+
# We just test the name and version as we want to be able to see if an unresolved package and a resolved one represent the same
|
|
69
|
+
# bundle package.
|
|
70
|
+
def ==(other)
|
|
71
|
+
return false unless other.is_a? BundlePackage
|
|
72
|
+
eql = name == other.name
|
|
73
|
+
eql |= version.nil? ? other.version.nil? : version == other.version
|
|
74
|
+
eql
|
|
75
|
+
end
|
|
76
|
+
|
|
77
|
+
alias :eql? :==
|
|
78
|
+
end
|
|
79
|
+
|
|
80
|
+
end
|
|
@@ -0,0 +1,140 @@
|
|
|
1
|
+
# Licensed to the Apache Software Foundation (ASF) under one or more
|
|
2
|
+
# contributor license agreements. See the NOTICE file distributed with this
|
|
3
|
+
# work for additional information regarding copyright ownership. The ASF
|
|
4
|
+
# licenses this file to you under the Apache License, Version 2.0 (the
|
|
5
|
+
# "License"); you may not use this file except in compliance with the License.
|
|
6
|
+
# You may obtain a copy of the License at
|
|
7
|
+
#
|
|
8
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
|
9
|
+
#
|
|
10
|
+
# Unless required by applicable law or agreed to in writing, software
|
|
11
|
+
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
|
12
|
+
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
|
13
|
+
# License for the specific language governing permissions and limitations under
|
|
14
|
+
# the License.
|
|
15
|
+
|
|
16
|
+
require "manifest"
|
|
17
|
+
|
|
18
|
+
module OSGi #:nodoc:
|
|
19
|
+
|
|
20
|
+
# This class represents an OSGi container.
|
|
21
|
+
# It contains the bundles, fragments, and the location of the OSGi container.
|
|
22
|
+
# A typical OSGi container is an Eclipse instance.
|
|
23
|
+
#
|
|
24
|
+
class Container
|
|
25
|
+
|
|
26
|
+
# bundles: the bundles of the eclipse instance loaded on startup
|
|
27
|
+
# location: the location of the Eclipse instance
|
|
28
|
+
attr_reader :bundles, :fragments, :location
|
|
29
|
+
|
|
30
|
+
# Default constructor for a Container
|
|
31
|
+
#
|
|
32
|
+
# location: the location of the Eclipse instance
|
|
33
|
+
# plugin_locations, default value is ["dropins", "plugins"]
|
|
34
|
+
# create_bundle_info, default value is true
|
|
35
|
+
def initialize(location, plugin_locations = ["dropins", "plugins"])
|
|
36
|
+
@location = location
|
|
37
|
+
@bundles = []
|
|
38
|
+
@fragments = []
|
|
39
|
+
plugin_locations.each do |p_loc|
|
|
40
|
+
p_loc_complete = File.join(@location, p_loc)
|
|
41
|
+
warn "Folder #{p_loc_complete} not found!" if !File.exists? p_loc_complete
|
|
42
|
+
parse(p_loc_complete) if File.exists? p_loc_complete
|
|
43
|
+
end
|
|
44
|
+
end
|
|
45
|
+
|
|
46
|
+
# Parses the directory and grabs the plugins, adding the created bundle objects to @bundles.
|
|
47
|
+
def parse(dir)
|
|
48
|
+
Dir.open(dir) do |plugins|
|
|
49
|
+
plugins.entries.each do |plugin|
|
|
50
|
+
absolute_plugin_path = "#{plugins.path}#{File::SEPARATOR}#{plugin}"
|
|
51
|
+
if (/.*\.jar$/.match(plugin))
|
|
52
|
+
zipfile = Zip::ZipFile.open(absolute_plugin_path)
|
|
53
|
+
entry = zipfile.find_entry("META-INF/MANIFEST.MF")
|
|
54
|
+
if (entry != nil)
|
|
55
|
+
manifest = Manifest.read(zipfile.read("META-INF/MANIFEST.MF"))
|
|
56
|
+
bundle = Bundle.fromManifest(manifest, absolute_plugin_path)
|
|
57
|
+
if bundle.nil?
|
|
58
|
+
elsif bundle.fragment?
|
|
59
|
+
@fragments << bundle
|
|
60
|
+
else
|
|
61
|
+
@bundles << bundle
|
|
62
|
+
end
|
|
63
|
+
end
|
|
64
|
+
zipfile.close
|
|
65
|
+
else
|
|
66
|
+
# take care of the folder
|
|
67
|
+
if (File.directory?(absolute_plugin_path) && !(plugin == "." || plugin == ".."))
|
|
68
|
+
if (!File.exists? ["#{absolute_plugin_path}", "META-INF", "MANIFEST.MF"].join(File::SEPARATOR))
|
|
69
|
+
#recursive approach: we have a folder wih no MANIFEST.MF, we should look into it.
|
|
70
|
+
parse(absolute_plugin_path)
|
|
71
|
+
else
|
|
72
|
+
next if File.exists? "#{absolute_plugin_path}/feature.xml" # avoid parsing features.
|
|
73
|
+
begin
|
|
74
|
+
manifest = Manifest.read((file = File.open("#{absolute_plugin_path}/META-INF/MANIFEST.MF")).read)
|
|
75
|
+
rescue
|
|
76
|
+
file.close
|
|
77
|
+
end
|
|
78
|
+
bundle = Bundle.fromManifest(manifest, absolute_plugin_path)
|
|
79
|
+
if bundle.nil?
|
|
80
|
+
elsif bundle.fragment?
|
|
81
|
+
@fragments << bundle
|
|
82
|
+
else
|
|
83
|
+
@bundles << bundle
|
|
84
|
+
end
|
|
85
|
+
end
|
|
86
|
+
end
|
|
87
|
+
end
|
|
88
|
+
end
|
|
89
|
+
end
|
|
90
|
+
@bundles = @bundles.compact
|
|
91
|
+
@fragments = @fragments.compact
|
|
92
|
+
end
|
|
93
|
+
|
|
94
|
+
# Return the list of bundles and fragments that match the criteria passed as arguments
|
|
95
|
+
# Possible criterias:
|
|
96
|
+
# name: the name of the bundle
|
|
97
|
+
# version: the version of the bundle
|
|
98
|
+
# exports_package: a package exported by the bundle
|
|
99
|
+
def find(criteria = {})
|
|
100
|
+
selected = bundles + fragments
|
|
101
|
+
|
|
102
|
+
if (criteria[:name])
|
|
103
|
+
selected = selected.select {|b| b.name == criteria[:name]}
|
|
104
|
+
end
|
|
105
|
+
if (criteria[:exports_package])
|
|
106
|
+
selected = selected.select {|b|
|
|
107
|
+
!(b.exported_packages.select {|package|
|
|
108
|
+
package.name == criteria[:exports_package] &&
|
|
109
|
+
(criteria[:version].nil? || criteria[:version].in_range(package.version))
|
|
110
|
+
}.empty?)
|
|
111
|
+
}
|
|
112
|
+
else
|
|
113
|
+
if (criteria[:version])
|
|
114
|
+
if criteria[:version].is_a?(VersionRange)
|
|
115
|
+
selected = selected.select {|b| criteria[:version].in_range(b.version)}
|
|
116
|
+
else
|
|
117
|
+
selected = selected.select {|b| b.version == criteria[:version]}
|
|
118
|
+
end
|
|
119
|
+
end
|
|
120
|
+
end
|
|
121
|
+
selected
|
|
122
|
+
end
|
|
123
|
+
|
|
124
|
+
# Return the list of fragments that match the criteria passed as arguments
|
|
125
|
+
# Possible criterias:
|
|
126
|
+
# host: the name of the host bundle
|
|
127
|
+
# version: the version of the bundle
|
|
128
|
+
#
|
|
129
|
+
def find_fragments(criteria = {:host => "", :version => ""})
|
|
130
|
+
selected = fragments
|
|
131
|
+
if (criteria[:host])
|
|
132
|
+
selected = selected.select {|b| b.fragment.name == criteria[:host]}
|
|
133
|
+
end
|
|
134
|
+
if (criteria[:version])
|
|
135
|
+
selected = selected.select {|b| b.fragment.version == criteria[:version]}
|
|
136
|
+
end
|
|
137
|
+
selected
|
|
138
|
+
end
|
|
139
|
+
end
|
|
140
|
+
end
|
|
@@ -0,0 +1,174 @@
|
|
|
1
|
+
# Licensed to the Apache Software Foundation (ASF) under one or more
|
|
2
|
+
# contributor license agreements. See the NOTICE file distributed with this
|
|
3
|
+
# work for additional information regarding copyright ownership. The ASF
|
|
4
|
+
# licenses this file to you under the Apache License, Version 2.0 (the
|
|
5
|
+
# "License"); you may not use this file except in compliance with the License.
|
|
6
|
+
# You may obtain a copy of the License at
|
|
7
|
+
#
|
|
8
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
|
9
|
+
#
|
|
10
|
+
# Unless required by applicable law or agreed to in writing, software
|
|
11
|
+
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
|
12
|
+
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
|
13
|
+
# License for the specific language governing permissions and limitations under
|
|
14
|
+
# the License.
|
|
15
|
+
|
|
16
|
+
module Buildr4OSGi #:nodoc:
|
|
17
|
+
|
|
18
|
+
# A module dedicated to building jars into OSGi bundles to serve as libraries.
|
|
19
|
+
#
|
|
20
|
+
module BuildLibraries
|
|
21
|
+
|
|
22
|
+
# A small extension contributed to projects that are library projects
|
|
23
|
+
# so we can walk the libraries we pass to them.
|
|
24
|
+
#
|
|
25
|
+
module LibraryProject
|
|
26
|
+
|
|
27
|
+
#
|
|
28
|
+
# Walks the libraries passed in parameter, passing each library to the block.
|
|
29
|
+
#
|
|
30
|
+
def walk_libs(lib, &block)
|
|
31
|
+
if (lib.is_a?(Struct) || lib.is_a?(Array))
|
|
32
|
+
lib.each {|structdep|
|
|
33
|
+
walk_libs(structdep, &block)
|
|
34
|
+
}
|
|
35
|
+
return
|
|
36
|
+
end
|
|
37
|
+
lib_artifact = case
|
|
38
|
+
when lib.is_a?(Artifact) then lib
|
|
39
|
+
when lib.is_a?(String) then Buildr::artifact(lib)
|
|
40
|
+
else
|
|
41
|
+
raise "Don't know how to interpret lib #{lib}"
|
|
42
|
+
end
|
|
43
|
+
block.call(lib_artifact)
|
|
44
|
+
end
|
|
45
|
+
|
|
46
|
+
def package_as_library_project(file_name)
|
|
47
|
+
::OSGi::BundleTask.define_task(file_name).tap do |plugin|
|
|
48
|
+
|
|
49
|
+
manifest_location = File.join(project.base_dir, "META-INF", "MANIFEST.MF")
|
|
50
|
+
manifest = project.manifest
|
|
51
|
+
if File.exists?(manifest_location)
|
|
52
|
+
read_m = ::Buildr::Packaging::Java::Manifest.parse(File.read(manifest_location)).main
|
|
53
|
+
manifest = project.manifest.merge(read_m)
|
|
54
|
+
end
|
|
55
|
+
manifest["Bundle-Version"] = project.version # the version of the bundle packaged is ALWAYS the version of the project.
|
|
56
|
+
manifest["Bundle-SymbolicName"] ||= project.id # if it was resetted to nil, we force the id to be added back.
|
|
57
|
+
|
|
58
|
+
plugin.with :manifest=> manifest, :meta_inf=>meta_inf
|
|
59
|
+
plugin.with [compile.target, resources.target].compact
|
|
60
|
+
end
|
|
61
|
+
|
|
62
|
+
end
|
|
63
|
+
|
|
64
|
+
def package_as_library_project_spec(spec) #:nodoc:
|
|
65
|
+
spec.merge(:type=>:jar)
|
|
66
|
+
end
|
|
67
|
+
end
|
|
68
|
+
|
|
69
|
+
# Monkey-patching the artifact so that it warns instead of failing
|
|
70
|
+
# when it cannot download the source
|
|
71
|
+
module SkipSourceDownload
|
|
72
|
+
def fail_download(remote_uris)
|
|
73
|
+
warn "Failed to download the sources #{to_spec}, tried the following repositories:\n#{remote_uris.join("\n")}"
|
|
74
|
+
end
|
|
75
|
+
end
|
|
76
|
+
|
|
77
|
+
#
|
|
78
|
+
# Returns the main section of the manifest of the bundle.
|
|
79
|
+
#
|
|
80
|
+
def manifest(lib)
|
|
81
|
+
artifact = Buildr.artifact(lib)
|
|
82
|
+
artifact.invoke # download it if needed.
|
|
83
|
+
|
|
84
|
+
m = nil
|
|
85
|
+
Zip::ZipFile.open(artifact.to_s) do |zip|
|
|
86
|
+
raise "No manifest contained in #{lib}" if zip.find_entry("META-INF/MANIFEST.MF").nil?
|
|
87
|
+
m = zip.read("META-INF/MANIFEST.MF")
|
|
88
|
+
end
|
|
89
|
+
manifest = ::Buildr::Packaging::Java::Manifest.new(m)
|
|
90
|
+
manifest.main
|
|
91
|
+
end
|
|
92
|
+
end
|
|
93
|
+
|
|
94
|
+
module LibraryProjectExtension
|
|
95
|
+
include Extension
|
|
96
|
+
|
|
97
|
+
#
|
|
98
|
+
#
|
|
99
|
+
# Defines a project as the merge of the dependencies.
|
|
100
|
+
# group: the group of the project to define
|
|
101
|
+
# name: the name of the project to define
|
|
102
|
+
# version: the version of the project to define
|
|
103
|
+
#
|
|
104
|
+
def library_project(dependencies, group, name, version, options = {:exclude => ["META-INF/MANIFEST.MF"], :include => [], :manifest => {}})
|
|
105
|
+
options[:manifest] ||= {}
|
|
106
|
+
deps_as_str = []
|
|
107
|
+
# We create an object and we extend with the module so we can get access to the walk_libs method.
|
|
108
|
+
walker = Object.new
|
|
109
|
+
walker.extend Buildr4OSGi::BuildLibraries::LibraryProject
|
|
110
|
+
walker.walk_libs(dependencies) {|lib|
|
|
111
|
+
deps_as_str << lib.to_spec
|
|
112
|
+
}
|
|
113
|
+
deps_as_str = deps_as_str.flatten.inspect
|
|
114
|
+
exclusion = options[:exclude].collect {|exclusion| ".exclude(#{exclusion.inspect})"}.join if options[:exclude]
|
|
115
|
+
inclusion = options[:include].collect {|inclusion| ".include(#{inclusion.inspect})"}.join if options[:include]
|
|
116
|
+
exclusion ||= ""
|
|
117
|
+
inclusion ||= ""
|
|
118
|
+
eval %{
|
|
119
|
+
desc "#{name}"
|
|
120
|
+
define "#{name}" do
|
|
121
|
+
project.extend Buildr4OSGi::LibraryProject
|
|
122
|
+
#{"project.version = \"#{version}\"" if version}
|
|
123
|
+
#{"project.group = \"#{group}\"" if group}
|
|
124
|
+
|
|
125
|
+
package(:library_project).tap {|jar|
|
|
126
|
+
jar.enhance {|task|
|
|
127
|
+
walk_libs(#{deps_as_str}) {|lib|
|
|
128
|
+
lib.invoke # make sure the artifact is present.
|
|
129
|
+
task.merge(lib)#{exclusion}#{inclusion}
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
entries = []
|
|
133
|
+
names = []
|
|
134
|
+
walk_libs(#{deps_as_str}) {|lib|
|
|
135
|
+
names << lib.to_spec
|
|
136
|
+
lib.invoke # make sure the artifact is present.
|
|
137
|
+
Zip::ZipFile.foreach(lib.to_s) {|entry| entries << entry.name.sub(/(.*)\\/.*.class$/, '\\1').gsub(/\\//, '.') if /.*\\.class$/.match(entry.name)}
|
|
138
|
+
}
|
|
139
|
+
jar.with :manifest => {
|
|
140
|
+
"Export-Package" => entries.uniq.sort.join(","),
|
|
141
|
+
"Bundle-Version" => "#{version}",
|
|
142
|
+
"Bundle-SymbolicName" => project.name,
|
|
143
|
+
"Bundle-Name" => names.join(", "),
|
|
144
|
+
"Bundle-Vendor" => "Intalio, Inc."
|
|
145
|
+
}.merge(#{options[:manifest].inspect})
|
|
146
|
+
|
|
147
|
+
|
|
148
|
+
}
|
|
149
|
+
package(:sources).tap do |task|
|
|
150
|
+
task.enhance do
|
|
151
|
+
walk_libs(#{deps_as_str}) {|lib|
|
|
152
|
+
lib_src = Buildr::artifact(lib.to_hash.merge(:classifier => "sources"))
|
|
153
|
+
lib_src.extend Buildr4OSGi::SkipSourceDownload
|
|
154
|
+
lib_src.invoke # make sure the artifact is present.
|
|
155
|
+
|
|
156
|
+
task.merge(lib_src)#{exclusion}#{inclusion} if File.exist?(lib_src.to_s)
|
|
157
|
+
}
|
|
158
|
+
end
|
|
159
|
+
end
|
|
160
|
+
end
|
|
161
|
+
}
|
|
162
|
+
end
|
|
163
|
+
end
|
|
164
|
+
end
|
|
165
|
+
|
|
166
|
+
module Buildr4OSGi
|
|
167
|
+
include Buildr4OSGi::BuildLibraries
|
|
168
|
+
include Buildr4OSGi::LibraryProjectExtension
|
|
169
|
+
end
|
|
170
|
+
|
|
171
|
+
class Buildr::Project
|
|
172
|
+
include Buildr4OSGi::LibraryProjectExtension
|
|
173
|
+
end
|
|
174
|
+
|
|
@@ -0,0 +1,129 @@
|
|
|
1
|
+
# Licensed to the Apache Software Foundation (ASF) under one or more
|
|
2
|
+
# contributor license agreements. See the NOTICE file distributed with this
|
|
3
|
+
# work for additional information regarding copyright ownership. The ASF
|
|
4
|
+
# licenses this file to you under the Apache License, Version 2.0 (the
|
|
5
|
+
# "License"); you may not use this file except in compliance with the License.
|
|
6
|
+
# You may obtain a copy of the License at
|
|
7
|
+
#
|
|
8
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
|
9
|
+
#
|
|
10
|
+
# Unless required by applicable law or agreed to in writing, software
|
|
11
|
+
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
|
12
|
+
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
|
13
|
+
# License for the specific language governing permissions and limitations under
|
|
14
|
+
# the License.
|
|
15
|
+
|
|
16
|
+
module OSGi
|
|
17
|
+
|
|
18
|
+
#:nodoc:
|
|
19
|
+
# This module is used to identify the packaging task
|
|
20
|
+
# that represent a bundle packaging.
|
|
21
|
+
#
|
|
22
|
+
# Tasks representing bundle packaging should include this module
|
|
23
|
+
# to be used by the buildr system properly.
|
|
24
|
+
#
|
|
25
|
+
module BundlePackaging
|
|
26
|
+
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
#
|
|
31
|
+
# The task to package a project
|
|
32
|
+
# as a OSGi bundle.
|
|
33
|
+
#
|
|
34
|
+
class BundleTask < ::Buildr::Packaging::Java::JarTask
|
|
35
|
+
include BundlePackaging
|
|
36
|
+
# Artifacts to include under /lib.
|
|
37
|
+
attr_accessor :libs
|
|
38
|
+
|
|
39
|
+
def initialize(*args) #:nodoc:
|
|
40
|
+
super
|
|
41
|
+
@libs = []
|
|
42
|
+
prepare do
|
|
43
|
+
unless @libs.nil? || @libs.empty?
|
|
44
|
+
artifacts = Buildr.artifacts(@libs)
|
|
45
|
+
path('lib').include artifacts
|
|
46
|
+
manifest["Bundle-Classpath"] = [".", artifacts.collect {|a| "lib/#{File.basename(a.to_s)}"}].flatten.join(",")
|
|
47
|
+
|
|
48
|
+
end
|
|
49
|
+
end
|
|
50
|
+
end
|
|
51
|
+
|
|
52
|
+
end
|
|
53
|
+
|
|
54
|
+
module ActAsOSGiBundle
|
|
55
|
+
include Extension
|
|
56
|
+
|
|
57
|
+
protected
|
|
58
|
+
|
|
59
|
+
# returns true if the project defines at least one bundle packaging.
|
|
60
|
+
# We keep this method protected and we will call it using send.
|
|
61
|
+
def is_packaging_osgi_bundle()
|
|
62
|
+
packages.each {|package| return true if package.is_a?(::OSGi::BundlePackaging)}
|
|
63
|
+
return false
|
|
64
|
+
end
|
|
65
|
+
|
|
66
|
+
def package_as_bundle(file_name)
|
|
67
|
+
task = BundleTask.define_task(file_name).tap do |plugin|
|
|
68
|
+
# Custom resource task to grab everything located at the root of the project
|
|
69
|
+
# while leaving the user also specify a resources directory, in case we are in face
|
|
70
|
+
# of a complex project.
|
|
71
|
+
# This is a bit hacky and not fully respecting the project layout, so we might find some alternative later
|
|
72
|
+
# to do the job by extending the layout object, and maybe making this resource task available as a subclass
|
|
73
|
+
# of ResourcesTask.
|
|
74
|
+
p_r = ResourcesTask.define_task
|
|
75
|
+
p_r.send :associate_with, project, :main
|
|
76
|
+
p_r.from("#{project.base_dir}").exclude("**/.*").exclude("**/*.jar").exclude("**/*.java")
|
|
77
|
+
p_r.exclude("src/**").exclude("*src").exclude("*src/**").exclude("build.properties")
|
|
78
|
+
p_r.exclude("bin").exclude("bin/**")
|
|
79
|
+
p_r.exclude("target/**").exclude("target")
|
|
80
|
+
|
|
81
|
+
manifest_location = File.join(project.base_dir, "META-INF", "MANIFEST.MF")
|
|
82
|
+
manifest = project.manifest
|
|
83
|
+
if File.exists?(manifest_location)
|
|
84
|
+
read_m = ::Buildr::Packaging::Java::Manifest.parse(File.read(manifest_location)).main
|
|
85
|
+
manifest = project.manifest.merge(read_m)
|
|
86
|
+
end
|
|
87
|
+
manifest["Bundle-Version"] = project.version # the version of the bundle packaged is ALWAYS the version of the project.
|
|
88
|
+
manifest["Bundle-SymbolicName"] ||= project.id # if it was resetted to nil, we force the id to be added back.
|
|
89
|
+
|
|
90
|
+
plugin.with :manifest=> manifest, :meta_inf=>meta_inf
|
|
91
|
+
plugin.with [compile.target, resources.target, p_r.target].compact
|
|
92
|
+
end
|
|
93
|
+
end
|
|
94
|
+
|
|
95
|
+
def package_as_bundle_spec(spec) #:nodoc:
|
|
96
|
+
spec.merge(:type=>:jar)
|
|
97
|
+
end
|
|
98
|
+
|
|
99
|
+
before_define do |project|
|
|
100
|
+
project.manifest["Bundle-SymbolicName"] = project.id
|
|
101
|
+
project.manifest["Bundle-Name"] = project.comment || project.name
|
|
102
|
+
project.manifest["Bundle-Version"] = project.version
|
|
103
|
+
end
|
|
104
|
+
end
|
|
105
|
+
|
|
106
|
+
module BundleProjects #:nodoc
|
|
107
|
+
|
|
108
|
+
# Returns the projects
|
|
109
|
+
# that define an OSGi bundle packaging.
|
|
110
|
+
#
|
|
111
|
+
def bundle_projects
|
|
112
|
+
|
|
113
|
+
Buildr.projects.flatten.select {|project|
|
|
114
|
+
project.send :is_packaging_osgi_bundle
|
|
115
|
+
}
|
|
116
|
+
end
|
|
117
|
+
|
|
118
|
+
module_function :bundle_projects
|
|
119
|
+
end
|
|
120
|
+
|
|
121
|
+
end
|
|
122
|
+
|
|
123
|
+
class Buildr::Project
|
|
124
|
+
include OSGi::ActAsOSGiBundle
|
|
125
|
+
end
|
|
126
|
+
|
|
127
|
+
module Buildr4OSGi
|
|
128
|
+
include OSGi::BundleProjects
|
|
129
|
+
end
|