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
@@ -0,0 +1,48 @@
|
|
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 File.join(File.dirname(__FILE__), '../spec_helpers')
|
17
|
+
|
18
|
+
describe OSGi::ExecutionEnvironment do
|
19
|
+
|
20
|
+
it 'should create a frozen object' do
|
21
|
+
ee = OSGi::ExecutionEnvironment.new("example", "hello", ["com", "org"])
|
22
|
+
ee.should be_frozen
|
23
|
+
ee.packages.should be_frozen
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
describe OSGi::ExecutionEnvironmentConfiguration do
|
28
|
+
|
29
|
+
before :all do
|
30
|
+
@conf = OSGi::ExecutionEnvironmentConfiguration.new
|
31
|
+
end
|
32
|
+
|
33
|
+
|
34
|
+
it "should add the default execution environments" do
|
35
|
+
@conf.send( :available_ee).values.should include OSGi::NONE, OSGi::CDC10FOUNDATION10, OSGi::CDC10FOUNDATION11, OSGi::J2SE12, OSGi::J2SE13, OSGi::J2SE14, OSGi::J2SE15, OSGi::JAVASE16, OSGi::JAVASE17, OSGi::OSGIMINIMUM10, OSGi::OSGIMINIMUM11, OSGi::OSGIMINIMUM12
|
36
|
+
end
|
37
|
+
|
38
|
+
it "should set JavaSE1.6 as the default execution environment" do
|
39
|
+
@conf.current_execution_environment.should == OSGi::JAVASE16
|
40
|
+
end
|
41
|
+
|
42
|
+
it "should let the user define extra packages to be part of the execution environment" do
|
43
|
+
@conf.extra_packages << "com.sum.nedia"
|
44
|
+
@conf.extra_packages.should include("com.sum.nedia")
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
|
@@ -0,0 +1,84 @@
|
|
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 File.join(File.dirname(__FILE__), '../spec_helpers')
|
17
|
+
|
18
|
+
|
19
|
+
Spec::Runner.configure do |config|
|
20
|
+
config.include SpecHelpers
|
21
|
+
end
|
22
|
+
|
23
|
+
describe OSGi::Registry do
|
24
|
+
|
25
|
+
it 'should be possible to set the containers from the OSGi environment variables' do
|
26
|
+
ENV['OSGi'] = "foo;bar"
|
27
|
+
OSGi.registry.containers.should == ["foo","bar"]
|
28
|
+
end
|
29
|
+
|
30
|
+
it 'should fall back on OSGI if the constant OSGi is not defined, issuing a warning' do
|
31
|
+
ENV['OSGi'] = nil
|
32
|
+
ENV['OSGI'] = "foo;bar"
|
33
|
+
lambda {OSGi.registry.resolved_containers}.should show_warning "The correct constant to define for the OSGi containers is named OSGi"
|
34
|
+
ENV['OSGi'].should == ENV['OSGI']
|
35
|
+
end
|
36
|
+
|
37
|
+
it 'should not complain if OSGI is set and OSGi is also set' do
|
38
|
+
ENV['OSGI'] = nil
|
39
|
+
lambda {OSGi.registry.resolved_containers}.should_not show_warning "The correct constant to define for the OSGi containers is named OSGi"
|
40
|
+
end
|
41
|
+
|
42
|
+
it 'should be possible to modify the containers in the registry before the resolved_containers method is called' do
|
43
|
+
lambda {OSGi.registry.containers << "hello"}.should_not raise_error
|
44
|
+
lambda {OSGi.registry.containers = ["hello"]}.should_not raise_error
|
45
|
+
end
|
46
|
+
|
47
|
+
it 'should throw an exception when modifying the containers in the registry after the resolved_containers method is called' do
|
48
|
+
OSGi.registry.resolved_containers
|
49
|
+
lambda {OSGi.registry.containers << "hello"}.should raise_error(TypeError)
|
50
|
+
lambda {OSGi.registry.containers = ["hello"]}.should raise_error(RuntimeError, /Cannot set containers, containers have been resolved already/)
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
|
55
|
+
describe OSGi do
|
56
|
+
|
57
|
+
it 'should give a handle over the OSGi containers registry' do
|
58
|
+
OSGi.registry.should be_instance_of(::OSGi::Registry)
|
59
|
+
end
|
60
|
+
|
61
|
+
it 'should help determine whether a package is part of the framework given by the execution environment' do
|
62
|
+
OSGi.is_framework_package?("com.mypackage").should be_false
|
63
|
+
OSGi.is_framework_package?(OSGi::JAVASE16.packages.first).should be_true
|
64
|
+
end
|
65
|
+
|
66
|
+
end
|
67
|
+
|
68
|
+
describe OSGi::GroupMatcher do
|
69
|
+
|
70
|
+
it 'should use osgi as the default group for an artifact' do
|
71
|
+
OSGi::GroupMatcher.instance.group("hello").should == "osgi"
|
72
|
+
end
|
73
|
+
|
74
|
+
it 'should use org.eclipse as the default group for Eclipse artifacts' do
|
75
|
+
OSGi::GroupMatcher.instance.group("org.eclipse.core.resources").should == "org.eclipse"
|
76
|
+
end
|
77
|
+
|
78
|
+
it 'should let users specify their own groups' do
|
79
|
+
OSGi::GroupMatcher.instance.group_matchers << Proc.new {|name| "bar" if name.match /foo$/}
|
80
|
+
OSGi::GroupMatcher.instance.group("org.eclipse.core.resources").should == "org.eclipse"
|
81
|
+
OSGi::GroupMatcher.instance.group("hello").should == "osgi"
|
82
|
+
OSGi::GroupMatcher.instance.group("org.eclipse.core.foo").should == "bar"
|
83
|
+
end
|
84
|
+
end
|
@@ -0,0 +1,116 @@
|
|
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 File.join(File.dirname(__FILE__), '../spec_helpers')
|
17
|
+
|
18
|
+
describe OSGi::BundleResolvingStrategies do
|
19
|
+
|
20
|
+
before(:all) do
|
21
|
+
@bundles = [OSGi::Bundle.new("art", "1.0"), OSGi::Bundle.new("art", "2.0"),
|
22
|
+
OSGi::Bundle.new("art", "2.0.1"), OSGi::Bundle.new("art", "3.0")]
|
23
|
+
|
24
|
+
end
|
25
|
+
|
26
|
+
it 'should use latest by default to resolve bundle dependencies' do
|
27
|
+
OSGi.options.bundle_resolving_strategy.should eql(:latest)
|
28
|
+
end
|
29
|
+
|
30
|
+
describe 'latest' do
|
31
|
+
|
32
|
+
it 'should return the bundle with the latest version' do
|
33
|
+
OSGi::BundleResolvingStrategies.latest(@bundles).should == @bundles.last
|
34
|
+
end
|
35
|
+
|
36
|
+
end
|
37
|
+
|
38
|
+
describe 'oldest' do
|
39
|
+
|
40
|
+
it 'should return the bundle with the oldest version' do
|
41
|
+
OSGi::BundleResolvingStrategies.oldest(@bundles).should == @bundles.first
|
42
|
+
end
|
43
|
+
|
44
|
+
end
|
45
|
+
|
46
|
+
describe 'prompt' do
|
47
|
+
|
48
|
+
it 'should prompt the user to choose a bundle' do
|
49
|
+
input = $stdin
|
50
|
+
$stdin = StringIO.new
|
51
|
+
$stdin.should_receive(:gets).and_return("i\n")
|
52
|
+
$stdin.should_receive(:gets).and_return("256\n")
|
53
|
+
$stdin.should_receive(:gets).and_return("2\n")
|
54
|
+
lambda {
|
55
|
+
OSGi::BundleResolvingStrategies.prompt(@bundles).should == @bundles[1]
|
56
|
+
}.should show("Invalid index")
|
57
|
+
$stdin = input
|
58
|
+
end
|
59
|
+
|
60
|
+
end
|
61
|
+
|
62
|
+
end
|
63
|
+
|
64
|
+
describe OSGi::PackageResolvingStrategies do
|
65
|
+
|
66
|
+
before(:all) do
|
67
|
+
@bundles = [OSGi::Bundle.new("art", "1.0"), OSGi::Bundle.new("art", "2.0"),
|
68
|
+
OSGi::Bundle.new("art", "2.0.1"), OSGi::Bundle.new("art", "3.0")]
|
69
|
+
|
70
|
+
end
|
71
|
+
|
72
|
+
it 'should use all by default to resolve package dependencies' do
|
73
|
+
OSGi.options.package_resolving_strategy.should eql(:all)
|
74
|
+
end
|
75
|
+
|
76
|
+
describe 'all' do
|
77
|
+
|
78
|
+
it 'should take all the bundles' do
|
79
|
+
OSGi::PackageResolvingStrategies.all(::OSGi::BundlePackage.new("com.package", "1.0"), @bundles).should == @bundles
|
80
|
+
end
|
81
|
+
|
82
|
+
end
|
83
|
+
|
84
|
+
describe 'prompt' do
|
85
|
+
|
86
|
+
it 'should prompt the user to choose a bundle' do
|
87
|
+
input = $stdin
|
88
|
+
$stdin = StringIO.new
|
89
|
+
$stdin.should_receive(:gets).and_return("2\n")
|
90
|
+
OSGi::PackageResolvingStrategies.prompt(::OSGi::BundlePackage.new("com.package", "1.0"), @bundles).should == [@bundles[1]]
|
91
|
+
$stdin = input
|
92
|
+
end
|
93
|
+
|
94
|
+
it 'should complain if the user enters an invalid index' do
|
95
|
+
input = $stdin
|
96
|
+
$stdin = StringIO.new
|
97
|
+
$stdin.should_receive(:gets).and_return("i\n")
|
98
|
+
$stdin.should_receive(:gets).and_return("256\n")
|
99
|
+
$stdin.should_receive(:gets).and_return("2\n")
|
100
|
+
lambda {
|
101
|
+
OSGi::PackageResolvingStrategies.prompt(::OSGi::BundlePackage.new("com.package", "1.0"), @bundles).should == [@bundles[1]]
|
102
|
+
}.should show("Invalid index")
|
103
|
+
$stdin = input
|
104
|
+
end
|
105
|
+
|
106
|
+
it 'should let the user select all bundles' do
|
107
|
+
input = $stdin
|
108
|
+
$stdin = StringIO.new
|
109
|
+
$stdin.should_receive(:gets).and_return("A\n")
|
110
|
+
OSGi::PackageResolvingStrategies.prompt(::OSGi::BundlePackage.new("com.package", "1.0"), @bundles).should == @bundles
|
111
|
+
$stdin = input
|
112
|
+
end
|
113
|
+
|
114
|
+
end
|
115
|
+
|
116
|
+
end
|
@@ -0,0 +1,133 @@
|
|
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 File.join(File.dirname(__FILE__), '../spec_helpers')
|
17
|
+
|
18
|
+
describe OSGi::Version do
|
19
|
+
it 'should initialize itself from a string' do
|
20
|
+
version = OSGi::Version.new("1.0.0.qualifier")
|
21
|
+
version.major.should eql("1")
|
22
|
+
version.minor.should eql("0")
|
23
|
+
version.tiny.should eql("0")
|
24
|
+
version.qualifier.should eql("qualifier")
|
25
|
+
end
|
26
|
+
|
27
|
+
it 'should accept versions without a qualifier' do
|
28
|
+
version = OSGi::Version.new("1.0.0")
|
29
|
+
version.major.should eql("1")
|
30
|
+
version.minor.should eql("0")
|
31
|
+
version.tiny.should eql("0")
|
32
|
+
version.qualifier.should be_nil
|
33
|
+
end
|
34
|
+
|
35
|
+
it 'should accept versions without a qualifier and a tiny digit' do
|
36
|
+
version = OSGi::Version.new("1.0")
|
37
|
+
version.major.should eql("1")
|
38
|
+
version.minor.should eql("0")
|
39
|
+
version.tiny.should be_nil
|
40
|
+
version.qualifier.should be_nil
|
41
|
+
end
|
42
|
+
|
43
|
+
it 'should accept versions without a qualifier, a minor and a tiny digit' do
|
44
|
+
version = OSGi::Version.new("1")
|
45
|
+
version.major.should eql("1")
|
46
|
+
version.minor.should be_nil
|
47
|
+
version.tiny.should be_nil
|
48
|
+
version.qualifier.should be_nil
|
49
|
+
end
|
50
|
+
|
51
|
+
it 'should raise an exception if no major digit is given' do
|
52
|
+
lambda { OSGi::Version.new(".0.0.qualifier") }.should raise_error(RuntimeError, /Invalid version:/)
|
53
|
+
end
|
54
|
+
|
55
|
+
it 'should raise an exception if no minor digit is given' do
|
56
|
+
lambda { OSGi::Version.new("1..0.qualifier") }.should raise_error(RuntimeError, /Invalid version:/)
|
57
|
+
end
|
58
|
+
|
59
|
+
it 'should raise an exception if no tiny digit is given' do
|
60
|
+
lambda { OSGi::Version.new("1.0..qualifier") }.should raise_error(RuntimeError, /Invalid version:/)
|
61
|
+
end
|
62
|
+
|
63
|
+
it 'should have a string representation' do
|
64
|
+
version = OSGi::Version.new("1.0.0.qualifier")
|
65
|
+
version.to_s.should eql("1.0.0.qualifier")
|
66
|
+
version.major = 2
|
67
|
+
version.to_s.should eql("2.0.0.qualifier")
|
68
|
+
end
|
69
|
+
|
70
|
+
it 'should compare with other versions' do
|
71
|
+
(OSGi::Version.new('1.0.0') < "2.0.0").should be_true
|
72
|
+
(OSGi::Version.new('1.9.9') > "2.0.0").should be_false
|
73
|
+
(OSGi::Version.new('1.54.112') < "2.2.0").should be_true
|
74
|
+
(OSGi::Version.new('1.0.3') > "1.0.2").should be_true
|
75
|
+
(OSGi::Version.new('2.3.4') == "2.3.4").should be_true
|
76
|
+
(OSGi::Version.new('2.3.4') <=> "2.3.4").should eql(0)
|
77
|
+
end
|
78
|
+
|
79
|
+
it 'should compare with nil' do
|
80
|
+
(OSGi::Version.new('1.0.0') <=> nil).should eql(1)
|
81
|
+
end
|
82
|
+
|
83
|
+
it 'should find if two versions are equal' do
|
84
|
+
(OSGi::Version.new('1.0.0.001-March') <=> "1.0.0.001-March").should == 0
|
85
|
+
end
|
86
|
+
|
87
|
+
it "should consider a version with no qualifier equals the same version with a qualifier" do
|
88
|
+
(OSGi::Version.new('2.5.0') == "2.5.0.v200806031605").should be_true
|
89
|
+
(OSGi::Version.new('2.5.0.v200806031605') == "2.5.0").should be_true
|
90
|
+
end
|
91
|
+
end
|
92
|
+
|
93
|
+
describe OSGi::VersionRange do
|
94
|
+
|
95
|
+
it 'should be able to parse version ranges' do
|
96
|
+
OSGi::VersionRange.parse("[1.0.0,2.0.0)").should be_instance_of(OSGi::VersionRange)
|
97
|
+
OSGi::VersionRange.parse("[1.0.0,2.0.0]").should be_instance_of(OSGi::VersionRange)
|
98
|
+
OSGi::VersionRange.parse("(1.0.0,2.0.0)").should be_instance_of(OSGi::VersionRange)
|
99
|
+
OSGi::VersionRange.parse("(1.0.0,2.0.0]").should be_instance_of(OSGi::VersionRange)
|
100
|
+
OSGi::VersionRange.parse("[1.0.02.0.0)").should be_false
|
101
|
+
OSGi::VersionRange.parse("[1.0.0,2.0.0").should be_false
|
102
|
+
OSGi::VersionRange.parse("1.0.0,2.0.0)").should be_false
|
103
|
+
OSGi::VersionRange.parse("[1.0,0,2.0.0)").should be_false
|
104
|
+
end
|
105
|
+
|
106
|
+
it 'should be able to tell if a version is in a range' do
|
107
|
+
range = OSGi::VersionRange.parse("[1.0.0,2.0.0)")
|
108
|
+
range.in_range("1.5.0.20080607").should be_true
|
109
|
+
range.in_range("2.0.0.20080607").should be_false
|
110
|
+
range.in_range("1.0.0.20080607").should be_true
|
111
|
+
range.in_range("0.9.0.20080607").should be_false
|
112
|
+
range = OSGi::VersionRange.parse("(1.0.0,2.0.0]")
|
113
|
+
range.in_range("2.0.0.20080607").should be_true
|
114
|
+
range.in_range("1.0.0.20080607").should be_false
|
115
|
+
end
|
116
|
+
|
117
|
+
it 'should have a String representation' do
|
118
|
+
range = OSGi::VersionRange.parse("[1.0.0,2.0.0)")
|
119
|
+
range.to_s.should eql("[1.0.0,2.0.0)")
|
120
|
+
r2 = OSGi::VersionRange.new
|
121
|
+
r2.min = OSGi::Version.new("1.0.0")
|
122
|
+
r2.max = OSGi::Version.new("2.0.0")
|
123
|
+
r2.min_inclusive = true
|
124
|
+
r2.to_s.should eql("[1.0.0,2.0.0)")
|
125
|
+
end
|
126
|
+
|
127
|
+
it 'should be able to consume a range with a space before or after the two limits' do
|
128
|
+
OSGi::VersionRange.parse("[1.0.0, 2.0.0)").should be_instance_of(OSGi::VersionRange)
|
129
|
+
OSGi::VersionRange.parse("[1.0.0 , 2.0.0)").should be_instance_of(OSGi::VersionRange)
|
130
|
+
OSGi::VersionRange.parse("[1.0.0 ,2.0.0)").should be_instance_of(OSGi::VersionRange)
|
131
|
+
end
|
132
|
+
|
133
|
+
end
|
@@ -0,0 +1,131 @@
|
|
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
|
+
unless defined?(SpecHelpers)
|
17
|
+
|
18
|
+
# For testing we use the gem requirements specified on the buildr4osgi.gemspec
|
19
|
+
spec = Gem::Specification.load(File.expand_path('../osgi.gemspec', File.dirname(__FILE__)))
|
20
|
+
spec.dependencies.each { |dep| gem dep.name, dep.version_requirements.to_s }
|
21
|
+
# Make sure to load from these paths first, we don't want to load any
|
22
|
+
# code from Gem library.
|
23
|
+
$LOAD_PATH.unshift File.expand_path('../lib', File.dirname(__FILE__))
|
24
|
+
require 'osgi'
|
25
|
+
|
26
|
+
[:info, :warn, :error, :puts].each do |severity|
|
27
|
+
::Object.class_eval do
|
28
|
+
define_method severity do |*args|
|
29
|
+
$messages ||= {}
|
30
|
+
$messages[severity] ||= []
|
31
|
+
$messages[severity].push(*args)
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
class MessageWithSeverityMatcher
|
37
|
+
def initialize(severity, message)
|
38
|
+
@severity = severity
|
39
|
+
@expect = message
|
40
|
+
end
|
41
|
+
|
42
|
+
def matches?(target)
|
43
|
+
$messages = {@severity => []}
|
44
|
+
target.call
|
45
|
+
return Regexp === @expect ? $messages[@severity].join('\n') =~ @expect : $messages[@severity].include?(@expect.to_s)
|
46
|
+
end
|
47
|
+
|
48
|
+
def failure_message
|
49
|
+
"Expected #{@severity} #{@expect.inspect}, " +
|
50
|
+
($messages[@severity].empty? ? "no #{@severity} issued" : "found #{$messages[@severity].inspect}")
|
51
|
+
end
|
52
|
+
|
53
|
+
def negative_failure_message
|
54
|
+
"Found unexpected #{$messages[@severity].inspect}"
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
58
|
+
# Test if an info message was shown. You can use a string or regular expression.
|
59
|
+
#
|
60
|
+
# For example:
|
61
|
+
# lambda { info 'ze test' }.should show_info(/ze test/)
|
62
|
+
def show_info(message)
|
63
|
+
MessageWithSeverityMatcher.new :info, message
|
64
|
+
end
|
65
|
+
|
66
|
+
# Test if a warning was shown. You can use a string or regular expression.
|
67
|
+
#
|
68
|
+
# For example:
|
69
|
+
# lambda { warn 'ze test' }.should show_warning(/ze test/)
|
70
|
+
def show_warning(message)
|
71
|
+
MessageWithSeverityMatcher.new :warn, message
|
72
|
+
end
|
73
|
+
|
74
|
+
# Test if an error message was shown. You can use a string or regular expression.
|
75
|
+
#
|
76
|
+
# For example:
|
77
|
+
# lambda { error 'ze test' }.should show_error(/ze test/)
|
78
|
+
def show_error(message)
|
79
|
+
MessageWithSeverityMatcher.new :error, message
|
80
|
+
end
|
81
|
+
|
82
|
+
# Test if any message was shown (puts). You can use a string or regular expression.
|
83
|
+
#
|
84
|
+
# For example:
|
85
|
+
# lambda { puts 'ze test' }.should show(/ze test/)
|
86
|
+
def show(message)
|
87
|
+
MessageWithSeverityMatcher.new :puts, message
|
88
|
+
end
|
89
|
+
|
90
|
+
# Writes contents in file
|
91
|
+
def write(file, contents)
|
92
|
+
FileUtils.mkpath File.dirname(file)
|
93
|
+
File.open(file.to_s, 'wb') { |file| file.write contents.to_s }
|
94
|
+
end
|
95
|
+
|
96
|
+
OSGi_REPOS = File.expand_path File.join(File.dirname(__FILE__), "..", "tmp", "osgi")
|
97
|
+
|
98
|
+
module MockInstanceWriter
|
99
|
+
def registry=(i)
|
100
|
+
@registry=i
|
101
|
+
end
|
102
|
+
end
|
103
|
+
|
104
|
+
module SpecHelpers
|
105
|
+
|
106
|
+
class << self
|
107
|
+
|
108
|
+
def included(config)
|
109
|
+
config.before(:all) {
|
110
|
+
OSGi.extend MockInstanceWriter
|
111
|
+
}
|
112
|
+
|
113
|
+
config.before(:each) {
|
114
|
+
OSGi.registry = OSGi::Registry.new
|
115
|
+
}
|
116
|
+
config.after(:all) {
|
117
|
+
FileUtils.rm_rf OSGi_REPOS
|
118
|
+
}
|
119
|
+
end
|
120
|
+
|
121
|
+
end
|
122
|
+
|
123
|
+
end
|
124
|
+
|
125
|
+
def createRepository(name)
|
126
|
+
repo = File.join(OSGi_REPOS, name)
|
127
|
+
FileUtils.mkpath repo
|
128
|
+
return repo
|
129
|
+
end
|
130
|
+
|
131
|
+
end
|