buildr4osgi 0.9.0 → 0.9.2

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.
Files changed (43) hide show
  1. data/buildr4osgi.gemspec +2 -2
  2. data/lib/buildr4osgi/compile/compiler.rb +23 -5
  3. data/lib/buildr4osgi/compile.rb +1 -1
  4. data/lib/buildr4osgi/eclipse/feature.rb +206 -65
  5. data/lib/buildr4osgi/osgi/bundle.rb +5 -7
  6. data/lib/buildr4osgi/osgi/bundle_package.rb +2 -2
  7. data/lib/buildr4osgi/osgi/container.rb +5 -0
  8. data/lib/buildr4osgi/osgi/dependencies.rb +91 -0
  9. data/lib/buildr4osgi/osgi/library_extension.rb +6 -4
  10. data/lib/buildr4osgi/osgi/packaging.rb +78 -6
  11. data/lib/buildr4osgi/osgi/packaging_sources.rb +86 -0
  12. data/lib/buildr4osgi/osgi/project_extension.rb +9 -115
  13. data/lib/buildr4osgi/osgi/registry.rb +71 -1
  14. data/lib/buildr4osgi/osgi/resolving_strategies.rb +4 -2
  15. data/lib/buildr4osgi/osgi.rb +2 -0
  16. data/lib/buildr4osgi.rb +0 -1
  17. data/rakelib/release.rake +3 -0
  18. data/rakelib/rspec.rake +3 -3
  19. data/rakelib/stage.rake +7 -0
  20. data/spec/compile/compiler_spec.rb +40 -8
  21. data/spec/eclipse/feature_spec.rb +103 -6
  22. data/spec/osgi/bundle_spec.rb +2 -2
  23. data/spec/osgi/dependencies_spec.rb +91 -0
  24. data/spec/osgi/library_extension_spec.rb +17 -0
  25. data/spec/osgi/packaging_sources_spec.rb +71 -0
  26. data/spec/osgi/packaging_spec.rb +11 -1
  27. data/spec/osgi/project_extension_spec.rb +31 -21
  28. data/spec/osgi/registry_spec.rb +31 -0
  29. data/spec/osgi/resolving_strategies_spec.rb +116 -0
  30. data/spec/spec_helpers.rb +2 -2
  31. data/spec/tmp/remote/log4j/log4j/1.2.15/log4j-1.2.15.jar +0 -0
  32. data/spec/tmp/remote/log4j/log4j/1.2.15/log4j-1.2.15.pom +478 -0
  33. metadata +10 -13
  34. data/lib/buildr4osgi/nature/eclipse.rb +0 -80
  35. data/lib/buildr4osgi/nature/java.rb +0 -32
  36. data/lib/buildr4osgi/nature/nature.rb +0 -156
  37. data/lib/buildr4osgi/nature/osgi.rb +0 -32
  38. data/lib/buildr4osgi/nature/scala.rb +0 -32
  39. data/spec/nature/eclipse_spec.rb +0 -46
  40. data/spec/nature/java_spec.rb +0 -45
  41. data/spec/nature/osgi_spec.rb +0 -63
  42. data/spec/nature/scala_spec.rb +0 -45
  43. data/spec/nature_spec.rb +0 -144
@@ -143,7 +143,7 @@ FEATURE
143
143
  foo.package(:feature).feature_xml = "feature.xml"
144
144
 
145
145
  foo.package(:feature).invoke
146
- feature_file = File.join(foo.base_dir, "target", "foo-1.0.0-feature.jar")
146
+ feature_file = File.join(foo.base_dir, "target", "foo-1.0.0.zip")
147
147
  Zip::ZipFile.open(feature_file) do |zip|
148
148
  zip.find_entry("eclipse/features/foo_1.0.0/feature.xml").should_not be_nil
149
149
  zip.read("eclipse/features/foo_1.0.0/feature.xml").should == featurexml
@@ -164,7 +164,7 @@ PROPS
164
164
  foo.package(:feature).feature_xml = "feature.xml"
165
165
  foo.package(:feature).feature_properties = "feature.properties"
166
166
  foo.package(:feature).invoke
167
- feature_file = File.join(foo.base_dir, "target", "foo-1.0.0-feature.jar")
167
+ feature_file = File.join(foo.base_dir, "target", "foo-1.0.0.zip")
168
168
  Zip::ZipFile.open(feature_file) do |zip|
169
169
  zip.find_entry("eclipse/features/foo_1.0.0/feature.xml").should_not be_nil
170
170
  zip.read("eclipse/features/foo_1.0.0/feature.xml").should == featurexml
@@ -190,7 +190,7 @@ PROPS
190
190
  f.license = "The license is too long to explain"
191
191
  f.licenseURL = "http://example.com/license"
192
192
  foo.package(:feature).invoke
193
- feature_file = File.join(foo.base_dir, "target", "foo-1.0.0-feature.jar")
193
+ feature_file = File.join(foo.base_dir, "target", "foo-1.0.0.zip")
194
194
  Zip::ZipFile.open(feature_file) do |zip|
195
195
  zip.find_entry("eclipse/features/foo_1.0.0/feature.xml").should_not be_nil
196
196
  feature_xml = zip.read("eclipse/features/foo_1.0.0/feature.xml")
@@ -222,7 +222,7 @@ describe Buildr4OSGi::FeatureTask, " when running" do
222
222
 
223
223
  it "should create a jar file with a eclipse/plugins and a eclipse/features structure" do
224
224
  @foo.package(:feature).invoke
225
- feature_file = File.join(@foo.base_dir, "target", "foo-1.0.0-feature.jar")
225
+ feature_file = File.join(@foo.base_dir, "target", "foo-1.0.0.zip")
226
226
  File.exists?(feature_file).should be_true
227
227
  Zip::ZipFile.open(feature_file) do |zip|
228
228
  zip.find_entry("eclipse/features/foo_1.0.0/feature.xml").should_not be_nil
@@ -232,7 +232,7 @@ describe Buildr4OSGi::FeatureTask, " when running" do
232
232
  end
233
233
 
234
234
  it 'should complain if one of the dependencies is not a plugin' do
235
- @foo.package(:feature).plugins << SLF4J
235
+ @foo.package(:feature).plugins << LOG4J
236
236
  lambda { @foo.package(:feature).invoke}.should raise_error(
237
237
  /The dependency .* is not an Eclipse plugin: make sure the headers Bundle-SymbolicName and Bundle-Version are present in the manifest/)
238
238
  end
@@ -259,9 +259,11 @@ end
259
259
  describe Buildr4OSGi::FeatureTask, " package subprojects" do
260
260
 
261
261
  before do
262
+ Buildr::write "bar/src/main/java/Hello.java", "public class Hello {}"
262
263
  @container = define("container") do
263
264
  @bar = define("bar", :version => "1.0.0") do
264
- package(:jar).with :manifest => {"Bundle-SymbolicName" => "bar", "Bundle-Version" => "1.0.0"}
265
+ package(:bundle)
266
+ package(:sources)
265
267
  end
266
268
  end
267
269
  @foo = define("foo", :version => "1.0.0")
@@ -288,6 +290,101 @@ describe Buildr4OSGi::FeatureTask, " package subprojects" do
288
290
  zip.find_entry("eclipse/features/foo_1.0.0/feature.properties").should_not be_nil
289
291
  zip.find_entry("eclipse/plugins/bar_1.0.0.jar").should_not be_nil
290
292
  zip.find_entry("eclipse/plugins/bar_1.0.0.jar").directory?.should be_false
293
+
294
+ end
295
+ end
296
+
297
+
298
+ end
299
+
300
+
301
+ describe Buildr4OSGi::FeatureTask, "packaged as SDK" do
302
+
303
+ before do
304
+ Buildr::write "bar/src/main/java/Hello.java", "public class Hello {}"
305
+ @container = define("container") do
306
+ project.group = "grp"
307
+ @bar = define("bar", :version => "1.0.0") do
308
+ package(:bundle)
309
+ package(:sources)
310
+ end
311
+ end
312
+ @foo = define("foo", :version => "1.0.0") do
313
+
314
+ f = package(:feature)
315
+ f.plugins.<< project("container:bar"), :unjarred => true
316
+ f.label = "My feature"
317
+ f.provider = "Acme Inc"
318
+ f.description = "The best feature ever"
319
+ f.changesURL = "http://example.com/changes"
320
+ f.license = "The license is too long to explain"
321
+ f.licenseURL = "http://example.com/license"
322
+ f.branding_plugin = "com.musal.ui"
323
+ f.update_sites << {:url => "http://example.com/update", :name => "My update site"}
324
+ f.discovery_sites = [{:url => "http://example.com/update2", :name => "My update site2"},
325
+ {:url => "http://example.com/upup", :name => "My update site in case"}]
326
+ package(:sources)
327
+ end
328
+ end
329
+
330
+ it "should create a jar file with the subproject packaged as a jar inside it" do
331
+ @foo.package(:sources).invoke
332
+ feature_file = @foo.package(:sources).to_s
333
+ File.exists?(feature_file).should be_true
334
+ Zip::ZipFile.open(feature_file) do |zip|
335
+ zip.find_entry("eclipse/features/foo.sources_1.0.0/feature.xml").should_not be_nil
336
+ zip.find_entry("eclipse/features/foo.sources_1.0.0/feature.properties").should_not be_nil
337
+ zip.find_entry("eclipse/plugins/bar.sources_1.0.0.jar").should be_nil
338
+ zip.find_entry("eclipse/plugins/bar.sources_1.0.0").directory?.should be_true
339
+ zip.find_entry("eclipse/plugins/bar.sources_1.0.0/Hello.java").should_not be_nil
340
+
341
+ end
342
+ end
343
+
344
+
345
+ end
346
+
347
+ describe Buildr4OSGi::FeatureTask, "packaged as SDK, detecting the OSGi headers from the original build" do
348
+
349
+ before do
350
+ Buildr::write "bar/src/main/java/Hello.java", "public class Hello {}"
351
+ @container = define("container") do
352
+ project.group = "grp"
353
+ @bar = define("bar", :version => "1.0.0") do
354
+ package(:jar).with :manifest => {"Bundle-SymbolicName" => "myName", "Bundle-Version" => "3.2.1"}
355
+ package(:sources)
356
+ end
357
+ end
358
+ @foo = define("foo", :version => "1.0.0") do
359
+
360
+ f = package(:feature)
361
+ f.plugins.<< project("container:bar"), :unjarred => true
362
+ f.label = "My feature"
363
+ f.provider = "Acme Inc"
364
+ f.description = "The best feature ever"
365
+ f.changesURL = "http://example.com/changes"
366
+ f.license = "The license is too long to explain"
367
+ f.licenseURL = "http://example.com/license"
368
+ f.branding_plugin = "com.musal.ui"
369
+ f.update_sites << {:url => "http://example.com/update", :name => "My update site"}
370
+ f.discovery_sites = [{:url => "http://example.com/update2", :name => "My update site2"},
371
+ {:url => "http://example.com/upup", :name => "My update site in case"}]
372
+ package(:sources)
373
+ end
374
+ end
375
+
376
+ it "should create a jar file with the subproject packaged as a jar inside it" do
377
+ @foo.package(:sources).invoke
378
+ feature_file = @foo.package(:sources).to_s
379
+ File.exists?(feature_file).should be_true
380
+ Zip::ZipFile.open(feature_file) do |zip|
381
+ zip.find_entry("eclipse/features/foo.sources_1.0.0/feature.xml").should_not be_nil
382
+ zip.find_entry("eclipse/features/foo.sources_1.0.0/feature.properties").should_not be_nil
383
+ zip.find_entry("eclipse/plugins/myName.sources_3.2.1.jar").should be_nil
384
+ zip.find_entry("eclipse/plugins/myName.sources_3.2.1").directory?.should be_true
385
+ zip.find_entry("eclipse/plugins/myName.sources_3.2.1/Hello.java").should_not be_nil
386
+ zip.find_entry("eclipse/plugins/myName.sources_3.2.1/META-INF/MANIFEST.MF").should_not be_nil
387
+ zip.read("eclipse/plugins/myName.sources_3.2.1/META-INF/MANIFEST.MF").should match(/Bundle-SymbolicName: myName\.sources/)
291
388
  end
292
389
  end
293
390
 
@@ -48,11 +48,11 @@ MANIFEST
48
48
  end
49
49
 
50
50
  it 'should be transformed as an artifact' do
51
- @bundle.to_s.should eql("osgi:org.eclipse.core.resources:jar:3.5.1.R_20090912")
51
+ @bundle.to_s.should eql("org.eclipse:org.eclipse.core.resources:jar:3.5.1.R_20090912")
52
52
  end
53
53
 
54
54
  it 'should compare with its artifact definition' do
55
- (@bundle <=> "osgi:org.eclipse.core.resources:jar:3.5.1.R_20090912").should == 0
55
+ (@bundle <=> "org.eclipse:org.eclipse.core.resources:jar:3.5.1.R_20090912").should == 0
56
56
  end
57
57
 
58
58
  it 'should recognize itself as a fragment' do
@@ -0,0 +1,91 @@
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::Dependencies do
19
+
20
+ it "should read a dependencies.yml file" do
21
+ write "dependencies.yml", {"foo" => {"dependencies" => ["com:artifact:jar:1.0"], "projects" => ["bar", "foobar"]},
22
+ "bar" => {"dependencies" => [], "projects" => []},
23
+ "foobar" => {"dependencies" => [], "projects" => []}}.to_yaml
24
+ foo = define("foo")
25
+ bar = define("bar")
26
+ foobar = define("foobar")
27
+ deps = OSGi::Dependencies.new(foo)
28
+ deps.read
29
+ deps.dependencies.should == ["com:artifact:jar:1.0"]
30
+ deps.projects.should == [bar, foobar]
31
+ end
32
+
33
+ it "should complain if a project is missing" do
34
+ write "dependencies.yml", {"foo" => {"dependencies" => ["com:artifact:jar:1.0"], "projects" => ["bar", "foobar"]}}.to_yaml
35
+ foo = define("foo")
36
+ bar = define("bar")
37
+
38
+ deps = OSGi::Dependencies.new(foo)
39
+ lambda { deps.read }.should raise_error(RuntimeError, /No such project/)
40
+ end
41
+
42
+ it "should add the project to the dependencies even if the project is not declared in the dependencies file" do
43
+ write "dependencies.yml", {"foo" => {"dependencies" => ["com:artifact:jar:1.0"], "projects" => ["bar", "foobar"]}}.to_yaml
44
+ foo = define("foo")
45
+ bar = define("bar")
46
+ foobar = define("foobar")
47
+ deps = OSGi::Dependencies.new(foo)
48
+ deps.read
49
+ deps.dependencies.should == ["com:artifact:jar:1.0"]
50
+ deps.projects.should == [bar, foobar]
51
+ end
52
+
53
+ it "should find the dependencies of each project even if cycles are present" do
54
+ write "dependencies.yml", {"foo" => {"dependencies" => ["com:artifact:jar:1.0"], "projects" => ["bar", "foobar"]},
55
+ "bar" => {"dependencies" => [], "projects" => ["foo"]},
56
+ "foobar" => {"dependencies" => [], "projects" => ["bar"]}}.to_yaml
57
+ foo = define("foo")
58
+ bar = define("bar")
59
+ foobar = define("foobar")
60
+ deps = OSGi::Dependencies.new(foo)
61
+ deps.read
62
+ deps.dependencies.should == ["com:artifact:jar:1.0"]
63
+ deps.projects.should == [bar, foobar]
64
+ end
65
+
66
+ it "should add the dependencies of the projects it depends on to its own" do
67
+ write "dependencies.yml", {"foo" => {"dependencies" => [], "projects" => ["bar"]},
68
+ "bar" => {"dependencies" => ["com:artifact:jar:1.0"], "projects" => []}}.to_yaml
69
+ foo = define("foo")
70
+ bar = define("bar")
71
+ deps = OSGi::Dependencies.new(foo)
72
+ deps.read
73
+ deps.dependencies.should == ["com:artifact:jar:1.0"]
74
+ deps.projects.should == [bar]
75
+ end
76
+
77
+ it "should write dependencies for several projects" do
78
+ foo = define("foo")
79
+ bar = define("bar")
80
+ deps = OSGi::Dependencies.new(foo)
81
+ deps.write([foo, "bar"]) {|hash, name|
82
+ case
83
+ when name == "foo"
84
+ hash["foo"]["projects"] << "bar"
85
+ when name == "bar"
86
+ hash["bar"]["dependencies"] << "com:art:jar:1.0"
87
+ end
88
+ }
89
+ YAML.load(File.read("dependencies.yml")).should == {"foo"=>{"projects"=>["bar"], "dependencies"=>[]}, "bar"=>{"projects"=>[], "dependencies"=>["com:art:jar:1.0"]}}
90
+ end
91
+ end
@@ -71,6 +71,23 @@ describe Buildr4OSGi::BuildLibraries do
71
71
  }
72
72
  end
73
73
 
74
+ it 'should not add the Export-Package header if no packages contain .class files' do
75
+ pending "Create a zip full of files but no .class files"
76
+ library_project(SLF4J, "group", "foo", "1.0.0")
77
+ foo = project("foo")
78
+ lambda {foo.package(:library_project).invoke}.should_not raise_error
79
+ jar = File.join(foo.base_dir, "target", "foo-1.0.0.jar")
80
+ File.exists?(jar).should be_true
81
+ Zip::ZipFile.open(jar) {|zip|
82
+ manifest = zip.find_entry("META-INF/MANIFEST.MF")
83
+ manifest.should_not be_nil
84
+ contents = Manifest.read(zip.read(manifest))
85
+ contents.first["Export-Package"].should_not be_nil
86
+ contents.first["Export-Package"].keys.should include("org.slf4j.helpers")
87
+ contents.first["Export-Package"].keys.should_not include("org")
88
+ }
89
+ end
90
+
74
91
  it 'should produce a zip of the sources' do
75
92
  library_project(SLF4J, "group", "foo", "1.0.0")
76
93
  foo = project("foo")
@@ -0,0 +1,71 @@
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
+ Spec::Runner.configure do |config|
19
+ config.include Buildr4OSGi::SpecHelpers
20
+ end
21
+
22
+ describe OSGi::BundleTask do
23
+
24
+ def define_project
25
+ Buildr::write "plugin.xml", <<-PLUGIN_XML
26
+ <?xml version="1.0" encoding="UTF-8"?>
27
+ <?eclipse version="3.2"?>
28
+ <plugin>
29
+ <extension point="org.eclipse.core.runtime.preferences">
30
+ <initializer class="org.intalio.preferenceInitializer"></initializer>
31
+ </extension>
32
+ <extension id="helloproblemmarker" name="%marker" point="org.eclipse.core.resources.markers">
33
+ <super type="org.eclipse.core.resources.problemmarker"/>
34
+ <persistent value="true"/>
35
+ </extension>
36
+ </plugin>
37
+ PLUGIN_XML
38
+ Buildr::write "plugin.properties", <<-PLUGIN_PROPERTIES
39
+ marker=Hello marker
40
+ PLUGIN_PROPERTIES
41
+ Buildr::write "src/main/java/Main.java", "public class Main { public static void main(String[] args) {}}"
42
+ @plugin = define("plugin", :version => "1.0.0.001") do
43
+ package(:sources)
44
+ package(:plugin)
45
+ end
46
+ @path = @plugin.package(:sources).to_s
47
+
48
+ end
49
+
50
+ it "should package the sources as a normal Java -sources.jar" do
51
+ define_project
52
+ @plugin.package(:sources).invoke
53
+ File.exists?(@path).should be_true
54
+ @path.to_s.should include(".jar")
55
+ Zip::ZipFile.open(@path) do |zip|
56
+ zip.find_entry("Main.java").should_not be_nil
57
+ end
58
+ end
59
+
60
+ it "should package a manifest for OSGi" do
61
+ define_project
62
+ @plugin.package(:sources).invoke
63
+ File.exists?(@path).should be_true
64
+ sourcesManifest = ::Buildr::Packaging::Java::Manifest.new(nil)
65
+ Zip::ZipFile.open(@path) do |zip|
66
+ zip.find_entry("Main.java").should_not be_nil
67
+ end
68
+ end
69
+
70
+
71
+ end
@@ -41,7 +41,6 @@ PLUGIN_PROPERTIES
41
41
  Buildr::write "src/main/java/Main.java", "public class Main { public static void main(String[] args) {}}"
42
42
  @plugin = define("plugin", :version => "1.0.0.001")
43
43
  @path = @plugin.package(:plugin).to_s
44
-
45
44
  end
46
45
 
47
46
  it "should package a project as a normal Java project" do
@@ -63,6 +62,16 @@ PLUGIN_PROPERTIES
63
62
  end
64
63
  end
65
64
 
65
+ it "should package a project as a plugin with its internal properties files" do
66
+ define_project
67
+ Buildr::write "src/main/java/somefolder/hello.properties", "# Empty properties file"
68
+ @plugin.package(:plugin).invoke
69
+ File.exists?(@path).should be_true
70
+ Zip::ZipFile.open(@path) do |zip|
71
+ zip.find_entry("somefolder/hello.properties").should_not be_nil
72
+ end
73
+ end
74
+
66
75
  it "should work with subprojects" do
67
76
  Buildr::write "bar/plugin.xml", <<-PLUGIN_XML
68
77
  <?xml version="1.0" encoding="UTF-8"?>
@@ -85,6 +94,7 @@ PLUGIN_PROPERTIES
85
94
  define("bar", :version => "2.0")
86
95
  end
87
96
  project("plugin:bar").package(:plugin).invoke
97
+ File.basename(project("plugin:bar").package(:plugin).to_s).should == "bar-2.0.jar"
88
98
  Zip::ZipFile.open(project("plugin:bar").package(:plugin).to_s) do |zip|
89
99
  zip.find_entry("plugin.xml").should_not be_nil
90
100
  zip.find_entry("plugin.properties").should_not be_nil
@@ -25,16 +25,26 @@ describe OSGi::ProjectExtension do
25
25
  define('foo').dependencies.should be_instance_of(Array)
26
26
  end
27
27
 
28
- it 'should add a new osgi method to projects' do
29
- define('foo').osgi.should be_instance_of(OSGi::ProjectExtension::OSGi)
30
- end
31
-
32
- it 'should give a handle over the OSGi containers registry' do
33
- define('foo').osgi.registry.should be_instance_of(OSGi::Registry)
28
+ it 'should fail when the user uses a dependency that is not present locally or remotely' do
29
+ write "dependencies.yml", {"foo" => {"dependencies" => ["group:artifact:jar:99.99.1"], "projects" => []},
30
+ "bar" => {"dependencies" => [], "projects" => ["foobar"]}}.to_yaml
31
+ foo = define('foo') {
32
+ compile.with dependencies
33
+ }
34
+ # bar = define("bar") {
35
+ # compile.with dependencies
36
+ # }
37
+ lambda {foo.compile.invoke}.should raise_error(RuntimeError, /Failed to download group:artifact:jar:99.99.1/)
38
+ pending "Unsupported scenario as of now."
39
+ lambda {bar.compile.invoke}.should raise_error(RuntimeError, /No such project/)
34
40
  end
35
41
 
36
- it 'should give options to resolve bundle dependencies' do
37
- pending
42
+ it 'should fail when the user uses a project that is not present locally or remotely' do
43
+ # see the spec dependencies_spec.rb at line 33 for an equivalent test.
44
+ write "dependencies.yml", {"bar" => {"dependencies" => [], "projects" => ["foobar"]}}.to_yaml
45
+ bar = define("bar") {
46
+ lambda {compile.with dependencies}.should raise_error(RuntimeError, /No such project/)
47
+ }
38
48
  end
39
49
 
40
50
  end
@@ -580,7 +590,7 @@ MANIFEST
580
590
  foo.osgi.registry.containers = @eclipse_instances.dup
581
591
  foo.dependencies
582
592
  foo.task('osgi:install:dependencies').invoke
583
- File.exist?(artifact("osgi:org.eclipse.debug.ui:jar:3.4.1.v20080811_r341").to_s).should be_true
593
+ File.exist?(artifact("org.eclipse:org.eclipse.debug.ui:jar:3.4.1.v20080811_r341").to_s).should be_true
584
594
 
585
595
  end
586
596
 
@@ -599,13 +609,13 @@ MANIFEST
599
609
 
600
610
  foo.task('osgi:resolve:dependencies').invoke
601
611
  foo.task('osgi:install:dependencies').invoke
602
- File.exist?(artifact("osgi:org.eclipse.core.resources:jar:3.5.1.R_20090512").to_s).should be_true
603
- Zip::ZipFile.open(artifact("osgi:org.eclipse.core.resources:jar:3.5.1.R_20090512").to_s) {|zip|
612
+ File.exist?(artifact("org.eclipse:org.eclipse.core.resources:jar:3.5.1.R_20090512").to_s).should be_true
613
+ Zip::ZipFile.open(artifact("org.eclipse:org.eclipse.core.resources:jar:3.5.1.R_20090512").to_s) {|zip|
604
614
  zip.entries.empty?.should_not be_true
605
615
  }
606
- File.exist?(artifact("osgi:org.eclipse.core.runtime.compatibility.registry:jar:3.2.200.v20090429-1800").to_s).should be_true
616
+ File.exist?(artifact("org.eclipse:org.eclipse.core.runtime.compatibility.registry:jar:3.2.200.v20090429-1800").to_s).should be_true
607
617
 
608
- Zip::ZipFile.open(artifact("osgi:org.eclipse.core.runtime.compatibility.registry:jar:3.2.200.v20090429-1800").to_s) {|zip|
618
+ Zip::ZipFile.open(artifact("org.eclipse:org.eclipse.core.runtime.compatibility.registry:jar:3.2.200.v20090429-1800").to_s) {|zip|
609
619
 
610
620
  zip.entries.empty?.should_not be_true
611
621
  }
@@ -627,17 +637,17 @@ MANIFEST
627
637
 
628
638
  foo.task('osgi:resolve:dependencies').invoke
629
639
  URI.should_receive(:upload).once.
630
- with(URI.parse('sftp://example.com/base/osgi/org.eclipse.debug.ui/3.4.1.v20080811_r341/org.eclipse.debug.ui-3.4.1.v20080811_r341.jar'),
631
- artifact("osgi:org.eclipse.debug.ui:jar:3.4.1.v20080811_r341").to_s, anything)
640
+ with(URI.parse('sftp://example.com/base/org/eclipse/org.eclipse.debug.ui/3.4.1.v20080811_r341/org.eclipse.debug.ui-3.4.1.v20080811_r341.jar'),
641
+ artifact("org.eclipse:org.eclipse.debug.ui:jar:3.4.1.v20080811_r341").to_s, anything)
632
642
  URI.should_receive(:upload).once.
633
- with(URI.parse('sftp://example.com/base/osgi/org.eclipse.debug.ui/3.4.1.v20080811_r341/org.eclipse.debug.ui-3.4.1.v20080811_r341.pom'),
634
- artifact("osgi:org.eclipse.debug.ui:jar:3.4.1.v20080811_r341").pom.to_s, anything)
643
+ with(URI.parse('sftp://example.com/base/org/eclipse/org.eclipse.debug.ui/3.4.1.v20080811_r341/org.eclipse.debug.ui-3.4.1.v20080811_r341.pom'),
644
+ artifact("org.eclipse:org.eclipse.debug.ui:jar:3.4.1.v20080811_r341").pom.to_s, anything)
635
645
  URI.should_receive(:upload).once.
636
- with(URI.parse('sftp://example.com/base/osgi/org.eclipse.core.resources/3.5.1.R_20090512/org.eclipse.core.resources-3.5.1.R_20090512.pom'),
637
- artifact("osgi:org.eclipse.core.resources:jar:3.5.1.R_20090512").pom.to_s, anything)
646
+ with(URI.parse('sftp://example.com/base/org/eclipse/org.eclipse.core.resources/3.5.1.R_20090512/org.eclipse.core.resources-3.5.1.R_20090512.pom'),
647
+ artifact("org.eclipse:org.eclipse.core.resources:jar:3.5.1.R_20090512").pom.to_s, anything)
638
648
  URI.should_receive(:upload).once.
639
- with(URI.parse('sftp://example.com/base/osgi/org.eclipse.core.resources/3.5.1.R_20090512/org.eclipse.core.resources-3.5.1.R_20090512.jar'),
640
- artifact("osgi:org.eclipse.core.resources:jar:3.5.1.R_20090512").to_s, anything)
649
+ with(URI.parse('sftp://example.com/base/org/eclipse/org.eclipse.core.resources/3.5.1.R_20090512/org.eclipse.core.resources-3.5.1.R_20090512.jar'),
650
+ artifact("org.eclipse:org.eclipse.core.resources:jar:3.5.1.R_20090512").to_s, anything)
641
651
 
642
652
  foo.task('osgi:upload:dependencies').invoke
643
653
 
@@ -47,4 +47,35 @@ describe OSGi::Registry do
47
47
  lambda {foo.osgi.registry.containers << "hello"}.should raise_error(TypeError)
48
48
  lambda {foo.osgi.registry.containers = ["hello"]}.should raise_error(RuntimeError, /Cannot set containers, containers have been resolved already/)
49
49
  end
50
+ end
51
+
52
+
53
+ describe OSGi::OSGi do
54
+
55
+ it 'should add a new osgi method to projects' do
56
+ define('foo').osgi.should be_instance_of(::OSGi::OSGi)
57
+ end
58
+
59
+ it 'should give a handle over the OSGi containers registry' do
60
+ define('foo').osgi.registry.should be_instance_of(::OSGi::Registry)
61
+ end
62
+
63
+ end
64
+
65
+ describe OSGi::GroupMatcher do
66
+
67
+ it 'should use osgi as the default group for an artifact' do
68
+ OSGi::GroupMatcher.instance.group("hello").should == "osgi"
69
+ end
70
+
71
+ it 'should use org.eclipse as the default group for Eclipse artifacts' do
72
+ OSGi::GroupMatcher.instance.group("org.eclipse.core.resources").should == "org.eclipse"
73
+ end
74
+
75
+ it 'should let users specify their own groups' do
76
+ OSGi::GroupMatcher.instance.group_matchers << Proc.new {|name| "bar" if name.match /foo$/}
77
+ OSGi::GroupMatcher.instance.group("org.eclipse.core.resources").should == "org.eclipse"
78
+ OSGi::GroupMatcher.instance.group("hello").should == "osgi"
79
+ OSGi::GroupMatcher.instance.group("org.eclipse.core.foo").should == "bar"
80
+ end
50
81
  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
+ define('foo').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
+ define('foo').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
data/spec/spec_helpers.rb CHANGED
@@ -35,17 +35,17 @@ unless defined?(SpecHelpers)
35
35
  HELPERS_REPOSITORY = File.expand_path(File.join(File.dirname(__FILE__), "tmp", "remote"))
36
36
  Buildr::repositories.local = HELPERS_REPOSITORY
37
37
  slf4j = Buildr::group(%w{ slf4j-api slf4j-log4j12 jcl104-over-slf4j }, :under=>"org.slf4j", :version=>"1.5.8")
38
+ LOG4J = "log4j:log4j:jar:1.2.15"
38
39
  SLF4J = slf4j
39
40
  DEBUG_UI = "eclipse:org.eclipse.debug.ui:jar:3.4.1.v20080811_r341"
40
41
  Buildr::repositories.remote << "http://www.intalio.org/public/maven2"
41
42
  artifact(DEBUG_UI).invoke # download it once!
43
+ artifact(LOG4J).invoke
42
44
  for lib in SLF4J do
43
45
  artifact(lib).invoke
44
46
  artifact(artifact(lib).to_hash.merge(:classifier => "sources")).invoke
45
47
  end
46
48
  Buildr::repositories.local = fake_local
47
- # Keep a default registry.
48
- DEFAULT = Buildr::Nature::Registry.all unless defined?(DEFAULT)
49
49
 
50
50
  module Buildr4OSGi::SpecHelpers
51
51