osgi 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/LICENSE +176 -0
- data/NOTICE +6 -0
- data/README.rdoc +50 -0
- data/Rakefile +45 -0
- data/lib/osgi.rb +24 -0
- data/lib/osgi/bundle.rb +201 -0
- data/lib/osgi/bundle_package.rb +104 -0
- data/lib/osgi/container.rb +145 -0
- data/lib/osgi/execution_environment.rb +199 -0
- data/lib/osgi/registry.rb +137 -0
- data/lib/osgi/resolving_strategies.rb +107 -0
- data/lib/osgi/version.rb +131 -0
- data/osgi.gemspec +36 -0
- data/spec/osgi/bundle_package_spec.rb +44 -0
- data/spec/osgi/bundle_spec.rb +94 -0
- data/spec/osgi/container_spec.rb +89 -0
- data/spec/osgi/execution_environment_spec.rb +48 -0
- data/spec/osgi/registry_spec.rb +84 -0
- data/spec/osgi/resolving_strategies_spec.rb +116 -0
- data/spec/osgi/version_spec.rb +133 -0
- data/spec/spec_helpers.rb +131 -0
- metadata +94 -0
data/LICENSE
ADDED
@@ -0,0 +1,176 @@
|
|
1
|
+
Apache License
|
2
|
+
Version 2.0, January 2004
|
3
|
+
http://www.apache.org/licenses/
|
4
|
+
|
5
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
6
|
+
|
7
|
+
1. Definitions.
|
8
|
+
|
9
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
10
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
11
|
+
|
12
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
13
|
+
the copyright owner that is granting the License.
|
14
|
+
|
15
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
16
|
+
other entities that control, are controlled by, or are under common
|
17
|
+
control with that entity. For the purposes of this definition,
|
18
|
+
"control" means (i) the power, direct or indirect, to cause the
|
19
|
+
direction or management of such entity, whether by contract or
|
20
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
21
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
22
|
+
|
23
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
24
|
+
exercising permissions granted by this License.
|
25
|
+
|
26
|
+
"Source" form shall mean the preferred form for making modifications,
|
27
|
+
including but not limited to software source code, documentation
|
28
|
+
source, and configuration files.
|
29
|
+
|
30
|
+
"Object" form shall mean any form resulting from mechanical
|
31
|
+
transformation or translation of a Source form, including but
|
32
|
+
not limited to compiled object code, generated documentation,
|
33
|
+
and conversions to other media types.
|
34
|
+
|
35
|
+
"Work" shall mean the work of authorship, whether in Source or
|
36
|
+
Object form, made available under the License, as indicated by a
|
37
|
+
copyright notice that is included in or attached to the work
|
38
|
+
(an example is provided in the Appendix below).
|
39
|
+
|
40
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
41
|
+
form, that is based on (or derived from) the Work and for which the
|
42
|
+
editorial revisions, annotations, elaborations, or other modifications
|
43
|
+
represent, as a whole, an original work of authorship. For the purposes
|
44
|
+
of this License, Derivative Works shall not include works that remain
|
45
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
46
|
+
the Work and Derivative Works thereof.
|
47
|
+
|
48
|
+
"Contribution" shall mean any work of authorship, including
|
49
|
+
the original version of the Work and any modifications or additions
|
50
|
+
to that Work or Derivative Works thereof, that is intentionally
|
51
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
52
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
53
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
54
|
+
means any form of electronic, verbal, or written communication sent
|
55
|
+
to the Licensor or its representatives, including but not limited to
|
56
|
+
communication on electronic mailing lists, source code control systems,
|
57
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
58
|
+
Licensor for the purpose of discussing and improving the Work, but
|
59
|
+
excluding communication that is conspicuously marked or otherwise
|
60
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
61
|
+
|
62
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
63
|
+
on behalf of whom a Contribution has been received by Licensor and
|
64
|
+
subsequently incorporated within the Work.
|
65
|
+
|
66
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
67
|
+
this License, each Contributor hereby grants to You a perpetual,
|
68
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
69
|
+
copyright license to reproduce, prepare Derivative Works of,
|
70
|
+
publicly display, publicly perform, sublicense, and distribute the
|
71
|
+
Work and such Derivative Works in Source or Object form.
|
72
|
+
|
73
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
74
|
+
this License, each Contributor hereby grants to You a perpetual,
|
75
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
76
|
+
(except as stated in this section) patent license to make, have made,
|
77
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
78
|
+
where such license applies only to those patent claims licensable
|
79
|
+
by such Contributor that are necessarily infringed by their
|
80
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
81
|
+
with the Work to which such Contribution(s) was submitted. If You
|
82
|
+
institute patent litigation against any entity (including a
|
83
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
84
|
+
or a Contribution incorporated within the Work constitutes direct
|
85
|
+
or contributory patent infringement, then any patent licenses
|
86
|
+
granted to You under this License for that Work shall terminate
|
87
|
+
as of the date such litigation is filed.
|
88
|
+
|
89
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
90
|
+
Work or Derivative Works thereof in any medium, with or without
|
91
|
+
modifications, and in Source or Object form, provided that You
|
92
|
+
meet the following conditions:
|
93
|
+
|
94
|
+
(a) You must give any other recipients of the Work or
|
95
|
+
Derivative Works a copy of this License; and
|
96
|
+
|
97
|
+
(b) You must cause any modified files to carry prominent notices
|
98
|
+
stating that You changed the files; and
|
99
|
+
|
100
|
+
(c) You must retain, in the Source form of any Derivative Works
|
101
|
+
that You distribute, all copyright, patent, trademark, and
|
102
|
+
attribution notices from the Source form of the Work,
|
103
|
+
excluding those notices that do not pertain to any part of
|
104
|
+
the Derivative Works; and
|
105
|
+
|
106
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
107
|
+
distribution, then any Derivative Works that You distribute must
|
108
|
+
include a readable copy of the attribution notices contained
|
109
|
+
within such NOTICE file, excluding those notices that do not
|
110
|
+
pertain to any part of the Derivative Works, in at least one
|
111
|
+
of the following places: within a NOTICE text file distributed
|
112
|
+
as part of the Derivative Works; within the Source form or
|
113
|
+
documentation, if provided along with the Derivative Works; or,
|
114
|
+
within a display generated by the Derivative Works, if and
|
115
|
+
wherever such third-party notices normally appear. The contents
|
116
|
+
of the NOTICE file are for informational purposes only and
|
117
|
+
do not modify the License. You may add Your own attribution
|
118
|
+
notices within Derivative Works that You distribute, alongside
|
119
|
+
or as an addendum to the NOTICE text from the Work, provided
|
120
|
+
that such additional attribution notices cannot be construed
|
121
|
+
as modifying the License.
|
122
|
+
|
123
|
+
You may add Your own copyright statement to Your modifications and
|
124
|
+
may provide additional or different license terms and conditions
|
125
|
+
for use, reproduction, or distribution of Your modifications, or
|
126
|
+
for any such Derivative Works as a whole, provided Your use,
|
127
|
+
reproduction, and distribution of the Work otherwise complies with
|
128
|
+
the conditions stated in this License.
|
129
|
+
|
130
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
131
|
+
any Contribution intentionally submitted for inclusion in the Work
|
132
|
+
by You to the Licensor shall be under the terms and conditions of
|
133
|
+
this License, without any additional terms or conditions.
|
134
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
135
|
+
the terms of any separate license agreement you may have executed
|
136
|
+
with Licensor regarding such Contributions.
|
137
|
+
|
138
|
+
6. Trademarks. This License does not grant permission to use the trade
|
139
|
+
names, trademarks, service marks, or product names of the Licensor,
|
140
|
+
except as required for reasonable and customary use in describing the
|
141
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
142
|
+
|
143
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
144
|
+
agreed to in writing, Licensor provides the Work (and each
|
145
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
146
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
147
|
+
implied, including, without limitation, any warranties or conditions
|
148
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
149
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
150
|
+
appropriateness of using or redistributing the Work and assume any
|
151
|
+
risks associated with Your exercise of permissions under this License.
|
152
|
+
|
153
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
154
|
+
whether in tort (including negligence), contract, or otherwise,
|
155
|
+
unless required by applicable law (such as deliberate and grossly
|
156
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
157
|
+
liable to You for damages, including any direct, indirect, special,
|
158
|
+
incidental, or consequential damages of any character arising as a
|
159
|
+
result of this License or out of the use or inability to use the
|
160
|
+
Work (including but not limited to damages for loss of goodwill,
|
161
|
+
work stoppage, computer failure or malfunction, or any and all
|
162
|
+
other commercial damages or losses), even if such Contributor
|
163
|
+
has been advised of the possibility of such damages.
|
164
|
+
|
165
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
166
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
167
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
168
|
+
or other liability obligations and/or rights consistent with this
|
169
|
+
License. However, in accepting such obligations, You may act only
|
170
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
171
|
+
of any other Contributor, and only if You agree to indemnify,
|
172
|
+
defend, and hold each Contributor harmless for any liability
|
173
|
+
incurred by, or claims asserted against, such Contributor by reason
|
174
|
+
of your accepting any such warranty or additional liability.
|
175
|
+
|
176
|
+
END OF TERMS AND CONDITIONS
|
data/NOTICE
ADDED
data/README.rdoc
ADDED
@@ -0,0 +1,50 @@
|
|
1
|
+
= Buildr4osgi
|
2
|
+
|
3
|
+
A plugin for adding OSGi support to Buildr.
|
4
|
+
|
5
|
+
See the official Buildr site: http://buildr.apache.org
|
6
|
+
|
7
|
+
You just had this OSGi bundle started, and everything runs in your development environment.
|
8
|
+
You hit one of those issues:
|
9
|
+
* You can't run a reproducible build.
|
10
|
+
* Bundles are hard to package.
|
11
|
+
* And it looks like you are going to have to find a way to resolve all your plugin dependencies (none of them are in a Maven repository!)
|
12
|
+
|
13
|
+
Enter OSGi!
|
14
|
+
|
15
|
+
Your bundle uses one of the mechanisms defined by OSGi to define dependencies:
|
16
|
+
* Require-Bundle: you require some bundles, optionally with a version range or a version.
|
17
|
+
* Import-Package: you import a package exported by other bundles.
|
18
|
+
* Fragment-Host: your bundle has fragments, they will be added to the bundle classpath on activation.
|
19
|
+
|
20
|
+
Each of those instructions have their own use. There's just no way you are going to resolve all your dependencies manually though.
|
21
|
+
|
22
|
+
== Install Buildr4osgi
|
23
|
+
|
24
|
+
* See the github instructions on how to setup to install their gems: http://gems.github.com
|
25
|
+
* For the impatient:
|
26
|
+
* gem sources -a http://gems.github.com
|
27
|
+
* sudo gem install intalio-buildr4osgi
|
28
|
+
|
29
|
+
== Documentation
|
30
|
+
|
31
|
+
See http://oss.intalio.com/buildr4osgi
|
32
|
+
|
33
|
+
http://intalio.github.com/buildr4osgi is the cutting edge documentation if you work against the trunk.
|
34
|
+
|
35
|
+
== License
|
36
|
+
|
37
|
+
Licensed to the Apache Software Foundation (ASF) under one or more
|
38
|
+
contributor license agreements. See the NOTICE file distributed with this
|
39
|
+
work for additional information regarding copyright ownership. The ASF
|
40
|
+
licenses this file to you under the Apache License, Version 2.0 (the
|
41
|
+
"License"); you may not use this file except in compliance with the License.
|
42
|
+
You may obtain a copy of the License at
|
43
|
+
|
44
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
45
|
+
|
46
|
+
Unless required by applicable law or agreed to in writing, software
|
47
|
+
distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
48
|
+
WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
49
|
+
License for the specific language governing permissions and limitations under
|
50
|
+
the License.
|
data/Rakefile
ADDED
@@ -0,0 +1,45 @@
|
|
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
|
+
|
17
|
+
# We need JAVA_HOME for most things (setup, spec, etc).
|
18
|
+
unless ENV['JAVA_HOME']
|
19
|
+
if RUBY_PLATFORM[/java/]
|
20
|
+
ENV['JAVA_HOME'] = java.lang.System.getProperty('java.home')
|
21
|
+
elsif RUBY_PLATFORM[/darwin/]
|
22
|
+
ENV['JAVA_HOME'] = '/System/Library/Frameworks/JavaVM.framework/Home'
|
23
|
+
else
|
24
|
+
fail "Please set JAVA_HOME first (set JAVA_HOME=... or env JAVA_HOME=... rake ...)"
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
|
29
|
+
# Load the Gem specification for the current platform (Ruby or JRuby).
|
30
|
+
def spec(platform = RUBY_PLATFORM[/java/] || 'ruby')
|
31
|
+
@specs ||= ['ruby', 'java', 'x86-mswin32'].inject({}) { |hash, spec_platform|
|
32
|
+
$platform = spec_platform
|
33
|
+
hash.update(spec_platform=>Gem::Specification.load('buildr4osgi.gemspec'))
|
34
|
+
}
|
35
|
+
@specs[platform]
|
36
|
+
end
|
37
|
+
|
38
|
+
# Tell us if we need sudo for various commands.
|
39
|
+
def sudo_needed?
|
40
|
+
Config::CONFIG['host_os'] !~ /windows|cygwin|bccwin|cygwin|djgpp|mingw|mswin|wince/i && !ENV['GEM_HOME']
|
41
|
+
end
|
42
|
+
|
43
|
+
|
44
|
+
desc 'Clean up all temporary directories used for running tests, creating documentation, packaging, etc.'
|
45
|
+
task :clobber
|
data/lib/osgi.rb
ADDED
@@ -0,0 +1,24 @@
|
|
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 'osgi/bundle'
|
17
|
+
require 'osgi/bundle_package'
|
18
|
+
require 'osgi/container'
|
19
|
+
require 'osgi/execution_environment'
|
20
|
+
require 'osgi/registry'
|
21
|
+
require 'osgi/resolving_strategies'
|
22
|
+
require 'osgi/version'
|
23
|
+
|
24
|
+
module OSGi ; extend self ; end
|
data/lib/osgi/bundle.rb
ADDED
@@ -0,0 +1,201 @@
|
|
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 bundle is an OSGi artifact represented by a jar file or a folder.
|
19
|
+
# It contains a manifest file with specific OSGi headers.
|
20
|
+
#
|
21
|
+
class Bundle
|
22
|
+
|
23
|
+
#Keys used in the MANIFEST.MF file
|
24
|
+
B_NAME = "Bundle-SymbolicName"
|
25
|
+
B_REQUIRE = "Require-Bundle"
|
26
|
+
B_IMPORT_PKG = "Import-Package"
|
27
|
+
B_EXPORT_PKG = "Export-Package"
|
28
|
+
B_FRAGMENT_HOST = "Fragment-Host"
|
29
|
+
B_VERSION = "Bundle-Version"
|
30
|
+
B_DEP_VERSION = "bundle-version"
|
31
|
+
B_RESOLUTION = "resolution"
|
32
|
+
B_LAZY_START = "Bundle-ActivationPolicy"
|
33
|
+
B_OLD_LAZY_START = "Eclipse-LazyStart"
|
34
|
+
|
35
|
+
# Creates itself by loading from the manifest file passed to it as a hash
|
36
|
+
# Finds the name and version, and populates a list of dependencies.
|
37
|
+
def self.fromManifest(manifest, jarFile)
|
38
|
+
if manifest.first[B_NAME].nil?
|
39
|
+
warn "Could not find the name of the bundle represented by #{jarFile}"
|
40
|
+
return nil
|
41
|
+
end
|
42
|
+
|
43
|
+
#see http://aspsp.blogspot.com/2008/01/wheressystembundlejarfilecont.html for the system.bundle trick.
|
44
|
+
#key.strip: sometimes there is a space between the comma and the name of the bundle.
|
45
|
+
#Add the required bundles:
|
46
|
+
bundles = []
|
47
|
+
manifest.first[B_REQUIRE].each_pair {|key, value| bundles << Bundle.new(key.strip, value[B_DEP_VERSION], {:optional => value[B_RESOLUTION] == "optional"}) unless "system.bundle" == key} unless manifest.first[B_REQUIRE].nil?
|
48
|
+
exports = []
|
49
|
+
manifest.first[B_EXPORT_PKG].each_pair {|key, value| exports << BundlePackage.new(key.strip, value["version"])} unless manifest.first[B_EXPORT_PKG].nil?
|
50
|
+
|
51
|
+
#Parse the version
|
52
|
+
version = manifest.first[B_VERSION].nil? ? nil : manifest.first[B_VERSION].keys.first
|
53
|
+
|
54
|
+
#Read the imports
|
55
|
+
imports = []
|
56
|
+
manifest.first[B_IMPORT_PKG].each_pair {|key, value| imports << BundlePackage.new(key.strip, value["version"], :is_export => false, :optional => value[B_RESOLUTION] == "optional")} unless manifest.first[B_IMPORT_PKG].nil?
|
57
|
+
|
58
|
+
#Read the imported packages
|
59
|
+
|
60
|
+
bundle = Bundle.new(manifest.first[B_NAME].keys.first, version, {:file => jarFile, :bundles => bundles, :imports => imports, :exported_packages => exports})
|
61
|
+
if !manifest.first[B_LAZY_START].nil?
|
62
|
+
# We look for the value of BundleActivationPolicy: lazy or nothing usually.
|
63
|
+
# lazy may be spelled Lazy too apparently, so we downcase the string in case.
|
64
|
+
bundle.lazy_start = "lazy" == manifest.first[B_LAZY_START].keys.first.strip.downcase
|
65
|
+
else
|
66
|
+
bundle.lazy_start = "true" == manifest.first[B_OLD_LAZY_START].keys.first.strip unless manifest.first[B_OLD_LAZY_START].nil?
|
67
|
+
end
|
68
|
+
if (bundle.lazy_start)
|
69
|
+
bundle.start_level = 4
|
70
|
+
else
|
71
|
+
bundle.start_level = 1
|
72
|
+
end
|
73
|
+
|
74
|
+
bundle.fragment = Bundle.new(manifest.first[B_FRAGMENT_HOST].keys.first.strip,
|
75
|
+
manifest.first[B_FRAGMENT_HOST].values.first[B_DEP_VERSION]) unless (manifest.first[B_FRAGMENT_HOST].nil?)
|
76
|
+
return bundle
|
77
|
+
end
|
78
|
+
|
79
|
+
|
80
|
+
|
81
|
+
# Attributes of a bundle, derived from its manifest
|
82
|
+
# The name is always the symbolic name
|
83
|
+
# The version is either the exact version of the bundle or the range in which the bundle would be accepted.
|
84
|
+
# The file is the location of the bundle on the disk
|
85
|
+
# The optional tag is present on bundles resolved as dependencies, marked as optional.
|
86
|
+
# The start level is deduced from the bundles.info file. Default is 1.
|
87
|
+
# The lazy start is found in the bundles.info file
|
88
|
+
# group is the artifact group used for Maven. By default it is set to OSGI_GROUP_ID.
|
89
|
+
# fragment is a Bundle object that represents the fragment host of this bundle (which means this bundle is a fragment if this field is not null).
|
90
|
+
# exported_packages is an array of strings representing the packages exported by the bundle.
|
91
|
+
# imports is an array of BundlePackage objects representing the packages imported by the bundle.
|
92
|
+
attr_accessor :name, :version, :bundles, :file, :optional, :start_level, :lazy_start, :group, :fragment, :exported_packages, :imports
|
93
|
+
|
94
|
+
alias :id :name
|
95
|
+
|
96
|
+
def initialize(name, version, args = {:file => nil, :bundles=>[], :imports => [], :optional => false}) #:nodoc:
|
97
|
+
@name = name
|
98
|
+
@version = VersionRange.parse(version) || (version.nil? ? nil : Version.new(version))
|
99
|
+
@bundles = args[:bundles] || []
|
100
|
+
@imports = args[:imports] || []
|
101
|
+
@exported_packages = args[:exported_packages] || []
|
102
|
+
@file = args[:file]
|
103
|
+
@optional = args[:optional]
|
104
|
+
@start_level = 4
|
105
|
+
@type = "jar" #it's always a jar, even if it is a directory: we will jar it for Maven.
|
106
|
+
@group = GroupMatcher.instance.group(name)
|
107
|
+
end
|
108
|
+
|
109
|
+
|
110
|
+
#
|
111
|
+
# Resolves the matching artifacts.
|
112
|
+
#
|
113
|
+
def resolve_matching_artifacts
|
114
|
+
|
115
|
+
return OSGi.registry.resolved_containers.collect {|i|
|
116
|
+
i.find(:name => name, :version => version)
|
117
|
+
}.flatten.compact.collect{|b| b.dup }
|
118
|
+
end
|
119
|
+
|
120
|
+
# Returns true if the bundle is an OSGi fragment.
|
121
|
+
#
|
122
|
+
def fragment?
|
123
|
+
!fragment.nil?
|
124
|
+
end
|
125
|
+
|
126
|
+
def to_s #:nodoc:
|
127
|
+
"#{name}:#{id}"
|
128
|
+
end
|
129
|
+
|
130
|
+
def to_yaml(opts = {}) #:nodoc:
|
131
|
+
to_s.to_yaml(opts)
|
132
|
+
end
|
133
|
+
|
134
|
+
def <=>(other) #:nodoc:
|
135
|
+
if other.is_a?(Bundle)
|
136
|
+
return to_s <=> other.to_s
|
137
|
+
else
|
138
|
+
return to_s <=> other
|
139
|
+
end
|
140
|
+
end
|
141
|
+
|
142
|
+
# Resolve a bundle from itself, by finding the appropriate bundle in the OSGi containers.
|
143
|
+
# Returns self or the project it represents if a project is found to be self.
|
144
|
+
#
|
145
|
+
def resolve(bundles = resolve_matching_artifacts)
|
146
|
+
bundle = case bundles.size
|
147
|
+
when 0 then nil
|
148
|
+
when 1 then bundles.first
|
149
|
+
else
|
150
|
+
BundleResolvingStrategies.send(OSGi.options.bundle_resolving_strategy, bundles)
|
151
|
+
end
|
152
|
+
if bundle.nil?
|
153
|
+
warn "Could not resolve bundle for #{self.to_s}"
|
154
|
+
return nil
|
155
|
+
end
|
156
|
+
|
157
|
+
osgi = self.dup
|
158
|
+
osgi.name = bundle.name
|
159
|
+
osgi.version = bundle.version
|
160
|
+
osgi.bundles = bundle.bundles
|
161
|
+
osgi.file = bundle.file
|
162
|
+
osgi.optional = bundle.optional
|
163
|
+
osgi.start_level = bundle.start_level
|
164
|
+
osgi.group = bundle.group
|
165
|
+
|
166
|
+
osgi
|
167
|
+
end
|
168
|
+
|
169
|
+
# Finds the fragments associated with this bundle.
|
170
|
+
#
|
171
|
+
def fragments
|
172
|
+
OSGi.registry.resolved_containers.collect {|i|
|
173
|
+
i.find_fragments(:host => name).select{|f|
|
174
|
+
if f.fragment.version.is_a? VersionRange
|
175
|
+
f.fragment.version.in_range(version)
|
176
|
+
elsif f.fragment.version.nil?
|
177
|
+
true
|
178
|
+
else
|
179
|
+
f.fragment.version == version
|
180
|
+
end
|
181
|
+
}
|
182
|
+
}.flatten.compact.collect{|b| b.dup }
|
183
|
+
end
|
184
|
+
|
185
|
+
# Compares with another bundle and returns true if the name and version match.
|
186
|
+
def ==(other) #:nodoc:
|
187
|
+
return false unless other.is_a?(Bundle)
|
188
|
+
name == other.name && version == other.version
|
189
|
+
end
|
190
|
+
|
191
|
+
alias :eql? ==
|
192
|
+
|
193
|
+
# Important for maps.
|
194
|
+
# We absolutely want to avoid having to resolve several times the same bundle
|
195
|
+
#
|
196
|
+
def hash
|
197
|
+
return to_s.hash
|
198
|
+
end
|
199
|
+
|
200
|
+
end
|
201
|
+
end
|