buildr-bnd 0.0.1

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 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/README.rdoc ADDED
@@ -0,0 +1,154 @@
1
+ = buildr-bnd
2
+
3
+ This is a Buildr extension for packaging OSGi bundles using Bnd (See
4
+ http://www.aqute.biz/Code/Bnd). The extension allows the user to define
5
+ properties/directives to be supplied to the Bnd tool and provides
6
+ reasonable defaults for those that can be derived from the project
7
+ model. Please see the bnd tool for documentation on the available
8
+ properties.
9
+
10
+ The 'bnd' setting is used to provide directives to the bnd tool that
11
+ are not inherited by subprojects while the standard 'manifest' setting is
12
+ used to define properties that inherited by subprojects.
13
+
14
+ A typical project that uses the extension may look something like;
15
+
16
+ define 'myProject' do
17
+ ...
18
+ package(:bundle).tap do |bnd|
19
+ bnd['Import-Package'] = "*;resolution:=optional"
20
+ bnd['Export-Package'] = "*;version=#{version}"
21
+ end
22
+ ...
23
+ end
24
+
25
+ == Installation
26
+
27
+ The extension is packaged as a gem named "buildr-iidea", consult the ruby gems installation
28
+ steps but typically it is either
29
+
30
+ sudo gem install buildr-bnd
31
+
32
+ for MRI ruby or
33
+
34
+ jgem install buildr-bnd
35
+
36
+ for jruby.
37
+
38
+ The user then needs to add the following require into the build file:
39
+
40
+ require 'buildr_bnd'
41
+
42
+ == Defaults
43
+
44
+ The extension sets the following bnd parameters;
45
+
46
+ * Bundle-Version defaults to the project version.
47
+ * Bundle-SymbolicName defaults to the concaternation of the project group
48
+ and project id, replacing ':' characters with '.'.
49
+ * Bundle-Name defaults to the project description if present else the project
50
+ name
51
+ * Bundle-Description defaults to the project description.
52
+ * Import-Package and Export-Package default to *
53
+ * -classpath is set to the compile target directory and any compile time
54
+ dependencies.
55
+
56
+ == Examples
57
+
58
+ === Using bnd to wrap an existing jar
59
+
60
+ Bnd can be used to wrap an existing jar as an OSGi bundle. The following
61
+ example wraps the OpenMQ JMS provider as an OSGi bundle.
62
+
63
+ require 'buildr_bnd'
64
+
65
+ # Add repository for OpenMQ
66
+ repositories.remote << 'http://download.java.net/maven/2'
67
+
68
+ desc 'OSGi bundle for OpenMQ JMS provider client library'
69
+ define 'com.sun.messaging.mq.imq' do
70
+ project.version = '4.4'
71
+ project.group = 'iris'
72
+ compile.with 'com.sun.messaging.mq:imq:jar:4.4'
73
+ package(:bundle).tap do |bnd|
74
+ bnd['Import-Package'] = "*;resolution:=optional"
75
+ bnd['Export-Package'] = "com.sun.messaging.*;version=#{version}"
76
+ end
77
+ end
78
+
79
+ === Create an OSGi bundle with an Activator
80
+
81
+ The following example presents a basic buildfile for building an OSGi bundle with
82
+ an activator.
83
+
84
+ require 'buildr_bnd'
85
+
86
+ # repository for OSGi core bundle
87
+ repositories.remote << 'https://repository.apache.org/content/repositories/releases'
88
+
89
+ desc 'Hello World bundle'
90
+ define 'helloworld' do
91
+ project.version = '1.0'
92
+ project.group = 'org.example'
93
+ compile.with 'org.apache.felix:org.osgi.core:jar:1.4.0'
94
+ package(:bundle).tap do |bnd|
95
+ bnd['Export-Package'] = "org.example.helloworld.api.*;version=#{version}"
96
+ bnd['Bundle-Activator'] = "org.example.helloworld.Activator"
97
+ end
98
+ end
99
+
100
+ === Inheriting parameters for bnd tool
101
+
102
+ The following example shows how you can use 'manifest' to define a bnd parameter that is inherited
103
+ to all child subprojects. The "Bundle-License" defined in the top level project is passed to the bnd
104
+ tool when generating both the 'fe' and 'fi' subprojects but the 'fo' subproject overrides this
105
+ parameter withy a local value.
106
+
107
+ require 'buildr_bnd'
108
+
109
+ define 'myproject' do
110
+ manifest['Bundle-License'] = "http://www.apache.org/licenses/LICENSE-2.0"
111
+ ...
112
+ define 'fe' do
113
+ ...
114
+ package :bundle
115
+ end
116
+
117
+ define 'fi' do
118
+ ...
119
+ package :bundle
120
+ end
121
+
122
+ define 'fo' do
123
+ ...
124
+ package(:bundle).tap do |bnd|
125
+ bnd['Bundle-License'] = "http://www.apache.org/licenses/LICENSE-1.1"
126
+ end
127
+ end
128
+ end
129
+
130
+ == Future Work
131
+
132
+ === Dependencies
133
+
134
+ Currently you need to declare all dependencies required by bnd as a compile dependency via
135
+ "compile.with X" even if they are not compile time dependencies but are just included in the
136
+ bundle otherwise these resources may not be uptodate when the bnd tool is invoked. An option
137
+ for improving this situation is something like the following code;
138
+
139
+ # Will invoke dependencies before packaging
140
+ define 'foo' do
141
+ bnd.dependency artifact('com.sun.messaging.mq:imq:jar:4.4')
142
+ bnd.dependency project('bar')
143
+ ...
144
+ package :bundle
145
+
146
+ project 'bar' do
147
+ ...
148
+ end
149
+ end
150
+
151
+ == Credit
152
+
153
+ The plugin was heavily inspired by the bnd tasks originally authored by Rhett Sutphin. It began
154
+ life as a fork but has been rewritten from scratch to use a different approach.
data/Rakefile ADDED
@@ -0,0 +1,24 @@
1
+ require 'rake'
2
+ require 'rake/rdoctask'
3
+ require 'rake/gempackagetask'
4
+ require 'spec/rake/spectask'
5
+
6
+ gem_spec = Gem::Specification.load(File.expand_path('buildr-bnd.gemspec', File.dirname(__FILE__)))
7
+
8
+ Spec::Rake::SpecTask.new(:spec) do |spec|
9
+ spec.libs << 'lib' << 'spec'
10
+ spec.spec_files = FileList['spec/**/*_spec.rb']
11
+ end
12
+
13
+ task :default => :spec
14
+
15
+ desc "Generate RDoc documentation in rdoc/"
16
+ Rake::RDocTask.new :rdoc do |rdoc|
17
+ rdoc.rdoc_dir = 'rdoc'
18
+ rdoc.title = gem_spec.name
19
+ rdoc.options = gem_spec.rdoc_options.clone
20
+ rdoc.rdoc_files.include('lib/**/*.rb')
21
+ rdoc.rdoc_files.include gem_spec.extra_rdoc_files
22
+ end
23
+
24
+ Rake::GemPackageTask.new(gem_spec).define
@@ -0,0 +1,18 @@
1
+ Gem::Specification.new do |spec|
2
+ spec.name = 'buildr-bnd'
3
+ spec.version = `git describe`.strip.split('-').first
4
+ spec.authors = ['Peter Donald']
5
+ spec.email = ["peter@realityforge.org"]
6
+ spec.homepage = "http://github.com/realityforge/buildr-bnd"
7
+ spec.summary = "Buildr extension for packaging OSGi bundles using bnd"
8
+ spec.description = <<-TEXT
9
+ This is a buildr extension for packaging OSGi bundles using Bnd.
10
+ TEXT
11
+ spec.files = Dir['{lib,spec}/**/*', '*.gemspec'] +
12
+ ['LICENSE', 'README.rdoc', 'Rakefile']
13
+ spec.require_paths = ['lib']
14
+
15
+ spec.has_rdoc = true
16
+ spec.extra_rdoc_files = 'README.rdoc', 'LICENSE'
17
+ spec.rdoc_options = '--title', "#{spec.name} #{spec.version}", '--main', 'README.rdoc'
18
+ end
data/lib/buildr_bnd.rb ADDED
@@ -0,0 +1,104 @@
1
+ module Buildr
2
+ module Bnd
3
+ include Buildr::Extension
4
+
5
+ class << self
6
+
7
+ # The specs for requirements
8
+ def requires
9
+ ["biz.aQute:bnd:jar:0.0.384"]
10
+ end
11
+
12
+ # Repositories containing the requirements
13
+ def remote_repositories
14
+ ["http://www.aQute.biz/repo"]
15
+ end
16
+
17
+ def bnd_main(*args)
18
+ cp = Buildr.artifacts(self.requires).each(&:invoke).map(&:to_s).join(File::PATH_SEPARATOR)
19
+ Java::Commands.java 'aQute.bnd.main.bnd', *(args + [{ :classpath => cp }])
20
+ end
21
+
22
+ end
23
+
24
+ class BundleTask < Rake::FileTask
25
+ attr_accessor :project
26
+
27
+ def [](key)
28
+ @params[key]
29
+ end
30
+
31
+ def []=(key, value)
32
+ @params[key] = value
33
+ end
34
+
35
+ def to_params
36
+ params = project.manifest.merge(@params).reject { |k, v| v.nil? }
37
+ params["-classpath"] ||= ([project.compile.target] + project.compile.dependencies).collect(&:to_s).join(", ")
38
+ params['Bundle-SymbolicName'] ||= [project.group, project.name.gsub(':', '.')].join('.')
39
+ params['Bundle-Name'] ||= project.comment || project.name
40
+ params['Bundle-Description'] ||= project.comment
41
+ params['Bundle-Version'] ||= project.version
42
+ params['Import-Package'] ||= '*'
43
+ params['Export-Package'] ||= '*'
44
+
45
+ params
46
+ end
47
+
48
+ protected
49
+
50
+ def initialize(*args) #:nodoc:
51
+ super
52
+ @params = {}
53
+ enhance do
54
+ filename = self.name
55
+ # Generate BND file with same name as target jar but different extension
56
+ bnd_filename = filename.sub /(\.jar)?$/, '.bnd'
57
+
58
+ params = self.to_params
59
+ params["-output"] = filename
60
+ File.open(bnd_filename, 'w') do |f|
61
+ f.print params.collect { |k, v| "#{k}=#{v}" }.join("\n")
62
+ end
63
+
64
+ Bnd.bnd_main( "build", "-noeclipse", bnd_filename )
65
+ begin
66
+ Bnd.bnd_main( "print", "-verify", filename )
67
+ rescue => e
68
+ rm filename
69
+ raise e
70
+ end
71
+ end
72
+ end
73
+ end
74
+
75
+ def package_as_bundle(filename)
76
+ project.task('bnd:print' => [filename]) do |task|
77
+ Bnd.bnd_main( "print", filename )
78
+ end
79
+
80
+ dirname = File.dirname(filename)
81
+ directory( dirname )
82
+
83
+ # Add Buildr.application.buildfile so it will rebuild if we change settings
84
+ task = BundleTask.define_task(filename => [Buildr.application.buildfile, dirname])
85
+ task.project = self
86
+ # the last task is the task considered the packaging task
87
+ task
88
+ end
89
+
90
+ def package_as_bundle_spec(spec)
91
+ # Change the source distribution to .jar extension
92
+ spec.merge( :type => :jar )
93
+ end
94
+
95
+ first_time do
96
+ desc "Does `bnd print` on the packaged bundle and stdouts the output for inspection"
97
+ Project.local_task("bnd:print")
98
+ end
99
+ end
100
+ end
101
+
102
+ class Buildr::Project
103
+ include Buildr::Bnd
104
+ end
@@ -0,0 +1,127 @@
1
+ require File.expand_path('../../../spec_helper', __FILE__)
2
+
3
+ describe "package :bundle" do
4
+ describe "with a valid bundle" do
5
+ before do
6
+ write "src/main/java/com/biz/Foo.java", <<SRC
7
+ package com.biz;
8
+ public class Foo {}
9
+ SRC
10
+ write "bar/src/main/java/com/biz/bar/Bar.java", <<SRC
11
+ package com.biz.bar;
12
+ public class Bar {}
13
+ SRC
14
+ @foo = define "foo" do
15
+ project.version = "2.1.3"
16
+ project.group = "mygroup"
17
+ manifest["Magic-Food"] = "Chocolate"
18
+ manifest["Magic-Drink"] = "Wine"
19
+ package :bundle
20
+
21
+ define "bar" do
22
+ project.version = "2.2"
23
+ package(:bundle).tap do |bnd|
24
+ bnd["Magic-Food"] = "Cheese"
25
+ end
26
+ end
27
+ end
28
+ task('package').invoke
29
+ end
30
+
31
+ it "produces a .bnd in the correct location for root project" do
32
+ File.should be_exist(@foo._("target/foo-2.1.3.bnd"))
33
+ end
34
+
35
+ it "produces a .jar in the correct location for root project" do
36
+ File.should be_exist(@foo._("target/foo-2.1.3.jar"))
37
+ end
38
+
39
+ it "produces a .jar containing correct .class files for root project" do
40
+ open_zip_file do |zip|
41
+ zip.file.exist?('com/biz/Foo.class').should be_true
42
+ end
43
+ end
44
+
45
+ it "produces a .jar containing expected manifest entries derived from project.bnd for root project" do
46
+ open_main_manifest_section do |attribs|
47
+ attribs['Bundle-Name'].should eql('foo')
48
+ attribs['Bundle-Version'].should eql('2.1.3')
49
+ attribs['Bundle-SymbolicName'].should eql('mygroup.foo')
50
+ attribs['Export-Package'].should eql('com.biz')
51
+ attribs['Import-Package'].should eql('com.biz')
52
+ end
53
+ end
54
+
55
+ it "produces a .jar containing expected manifest entries derived from project.manifest root project" do
56
+ open_main_manifest_section do |attribs|
57
+ attribs['Magic-Drink'].should eql('Wine')
58
+ attribs['Magic-Food'].should eql('Chocolate')
59
+ end
60
+ end
61
+
62
+ it "produces a .bnd in the correct location for subproject project" do
63
+ File.should be_exist(@foo._("bar/target/foo-bar-2.2.bnd"))
64
+ end
65
+
66
+ it "produces a .jar in the correct location for subproject project" do
67
+ File.should be_exist(@foo._("bar/target/foo-bar-2.2.jar"))
68
+ end
69
+
70
+ it "produces a .jar containing correct .class files for subproject project" do
71
+ open_zip_file('bar/target/foo-bar-2.2.jar') do |zip|
72
+ zip.file.exist?('com/biz/bar/Bar.class').should be_true
73
+ end
74
+ end
75
+
76
+ it "produces a .jar containing expected manifest entries derived from project.bnd for subproject project" do
77
+ open_main_manifest_section('bar/target/foo-bar-2.2.jar') do |attribs|
78
+ attribs['Bundle-Name'].should eql('foo:bar')
79
+ attribs['Bundle-Version'].should eql('2.2')
80
+ attribs['Bundle-SymbolicName'].should eql('mygroup.foo.bar')
81
+ attribs['Export-Package'].should eql('com.biz.bar')
82
+ attribs['Import-Package'].should eql('com.biz.bar')
83
+ end
84
+ end
85
+
86
+ it "produces a .jar containing expected manifest entries derived from project.manifest subproject project" do
87
+ open_main_manifest_section('bar/target/foo-bar-2.2.jar') do |attribs|
88
+ attribs['Magic-Drink'].should eql('Wine')
89
+ attribs['Magic-Food'].should eql('Cheese')
90
+ end
91
+ end
92
+
93
+ def open_zip_file(file = 'target/foo-2.1.3.jar')
94
+ jar_filename = @foo._(file)
95
+ File.should be_exist(jar_filename)
96
+ Zip::ZipFile.open(jar_filename) do |zip|
97
+ yield zip
98
+ end
99
+ end
100
+
101
+ def open_main_manifest_section(file = 'target/foo-2.1.3.jar')
102
+ jar_filename = @foo._(file)
103
+ File.should be_exist(jar_filename)
104
+ yield Buildr::Packaging::Java::Manifest.from_zip(jar_filename).main
105
+ end
106
+ end
107
+
108
+ describe "with an invalid bundle" do
109
+ before do
110
+ # bundle invalid as no source
111
+ @foo = define "foo" do
112
+ project.version = "2.1.3"
113
+ project.group = "mygroup"
114
+ package :bundle
115
+ end
116
+ end
117
+
118
+ it "raise an error if unable to build a valid bundle" do
119
+ lambda { task('package').invoke }.should raise_error
120
+ end
121
+
122
+ it "raise notp produce an invalid jar file" do
123
+ lambda { task('package').invoke }.should raise_error
124
+ File.should_not be_exist(@foo._("target/foo-2.1.3.jar"))
125
+ end
126
+ end
127
+ end
@@ -0,0 +1,50 @@
1
+ require File.expand_path('../../../spec_helper', __FILE__)
2
+
3
+ describe "project.bnd defaults" do
4
+
5
+ before do
6
+ @foo = define "foo" do
7
+ project.version = "2.1.3"
8
+ project.group = "mygroup"
9
+ package :bundle
10
+ desc "My Bar Project"
11
+ define "bar" do
12
+ package :bundle
13
+ end
14
+ end
15
+ @bar = @foo.project('bar')
16
+ end
17
+
18
+ it "defaults Bundle-Version to project.version" do
19
+ @foo.packages[0].to_params['Bundle-Version'].should eql('2.1.3')
20
+ @bar.packages[0].to_params['Bundle-Version'].should eql('2.1.3')
21
+ end
22
+
23
+ it "defaults Bundle-SymbolicName to combination of group and name" do
24
+ @foo.packages[0].to_params['Bundle-SymbolicName'].should eql('mygroup.foo')
25
+ @bar.packages[0].to_params['Bundle-SymbolicName'].should eql('mygroup.foo.bar')
26
+ end
27
+
28
+ it "defaults Export-Package to *" do
29
+ @foo.packages[0].to_params['Export-Package'].should eql('*')
30
+ @bar.packages[0].to_params['Export-Package'].should eql('*')
31
+ end
32
+
33
+ it "defaults Import-Package to *" do
34
+ @foo.packages[0].to_params['Import-Package'].should eql('*')
35
+ @bar.packages[0].to_params['Import-Package'].should eql('*')
36
+ end
37
+
38
+ it "defaults Bundle-Name to project.name if comment not present" do
39
+ @foo.packages[0].to_params['Bundle-Name'].should eql('foo')
40
+ end
41
+
42
+ it "defaults Bundle-Name to comment if present" do
43
+ @bar.packages[0].to_params['Bundle-Name'].should eql('My Bar Project')
44
+ end
45
+
46
+ it "defaults Bundle-Description to project.full_comment" do
47
+ @foo.packages[0].to_params['Bundle-Description'].should be_nil
48
+ @bar.packages[0].to_params['Bundle-Description'].should eql('My Bar Project')
49
+ end
50
+ end
@@ -0,0 +1,11 @@
1
+ require File.expand_path('../../../spec_helper', __FILE__)
2
+
3
+ describe "project extension" do
4
+ it "provides an 'bnd:print' task" do
5
+ Rake::Task.tasks.detect{|task| task.to_s == "bnd:print"}.should_not be_nil
6
+ end
7
+
8
+ it "documents the 'bnd:print' task" do
9
+ Rake::Task.tasks.detect{|task| task.to_s == "bnd:print"}.comment.should_not be_nil
10
+ end
11
+ end
data/spec/spec.opts ADDED
@@ -0,0 +1 @@
1
+ --color
@@ -0,0 +1,60 @@
1
+ require 'spec'
2
+
3
+ DEFAULT_BUILDR_DIR=File.expand_path(File.dirname(__FILE__) + '/../../buildr')
4
+ BUILDR_DIR=ENV['BUILDR_DIR'] || DEFAULT_BUILDR_DIR
5
+
6
+ unless File.exist?("#{BUILDR_DIR}/buildr.gemspec")
7
+ raise "Unable to find buildr.gemspec in #{BUILDR_DIR == DEFAULT_BUILDR_DIR ? 'guessed' : 'specified'} $BUILD_DIR (#{BUILDR_DIR})"
8
+ end
9
+
10
+ require 'rubygems'
11
+
12
+ # For testing we use the gem requirements specified on the buildr.gemspec
13
+ Gem::Specification.load(File.expand_path("#{BUILDR_DIR}/buildr.gemspec", File.dirname(__FILE__))).
14
+ dependencies.each { |dep| gem dep.name, dep.requirement.to_s }
15
+
16
+ # hook into buildr's spec_helpers load process
17
+ unless defined?(SpecHelpers)
18
+ module SandboxHook
19
+ def SandboxHook.included(spec_helpers)
20
+ $LOAD_PATH.unshift(File.dirname(__FILE__))
21
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
22
+ require 'buildr_bnd'
23
+ end
24
+ end
25
+
26
+ require "#{BUILDR_DIR}/spec/spec_helpers.rb"
27
+
28
+ # Download deps into real local dir
29
+ Buildr::Bnd.remote_repositories.each {|repository| Buildr::repositories.remote << repository }
30
+ Buildr::Bnd.requires.each { |spec| artifact(spec).invoke }
31
+
32
+ # Adjust specs so that they do not attempt to constantly download helper artifacts
33
+ module BuildrBndSpecHelpers
34
+
35
+ HELPERS_REPOSITORY = "file://#{Buildr::repositories.local}"
36
+ LOCAL_TEST_REPOSITORY = File.expand_path File.join(File.dirname(__FILE__), "..", "tmp", "test_m2_repository")
37
+
38
+ class << self
39
+
40
+ def included(config)
41
+ config.before(:each) do
42
+ repositories.remote << "file://#{HELPERS_REPOSITORY}"
43
+ end
44
+ config.after(:all) do
45
+ FileUtils.rm_rf LOCAL_TEST_REPOSITORY
46
+ end
47
+ end
48
+ end
49
+
50
+ def createRepository(name)
51
+ repo = File.join(LOCAL_TEST_REPOSITORY, name)
52
+ mkpath repo
53
+ return repo
54
+ end
55
+ end
56
+
57
+ Spec::Runner.configure do |config|
58
+ config.include BuildrBndSpecHelpers
59
+ end
60
+ end
metadata ADDED
@@ -0,0 +1,78 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: buildr-bnd
3
+ version: !ruby/object:Gem::Version
4
+ prerelease: false
5
+ segments:
6
+ - 0
7
+ - 0
8
+ - 1
9
+ version: 0.0.1
10
+ platform: ruby
11
+ authors:
12
+ - Peter Donald
13
+ autorequire:
14
+ bindir: bin
15
+ cert_chain: []
16
+
17
+ date: 2010-04-17 00:00:00 +10:00
18
+ default_executable:
19
+ dependencies: []
20
+
21
+ description: |
22
+ This is a buildr extension for packaging OSGi bundles using Bnd.
23
+
24
+ email:
25
+ - peter@realityforge.org
26
+ executables: []
27
+
28
+ extensions: []
29
+
30
+ extra_rdoc_files:
31
+ - README.rdoc
32
+ - LICENSE
33
+ files:
34
+ - lib/buildr_bnd.rb
35
+ - spec/spec_helper.rb
36
+ - spec/spec.opts
37
+ - spec/buildr/bnd/project_extension_spec.rb
38
+ - spec/buildr/bnd/bundle_package_spec.rb
39
+ - spec/buildr/bnd/defaults_spec.rb
40
+ - buildr-bnd.gemspec
41
+ - LICENSE
42
+ - README.rdoc
43
+ - Rakefile
44
+ has_rdoc: true
45
+ homepage: http://github.com/realityforge/buildr-bnd
46
+ licenses: []
47
+
48
+ post_install_message:
49
+ rdoc_options:
50
+ - --title
51
+ - buildr-bnd 0.0.1
52
+ - --main
53
+ - README.rdoc
54
+ require_paths:
55
+ - lib
56
+ required_ruby_version: !ruby/object:Gem::Requirement
57
+ requirements:
58
+ - - ">="
59
+ - !ruby/object:Gem::Version
60
+ segments:
61
+ - 0
62
+ version: "0"
63
+ required_rubygems_version: !ruby/object:Gem::Requirement
64
+ requirements:
65
+ - - ">="
66
+ - !ruby/object:Gem::Version
67
+ segments:
68
+ - 0
69
+ version: "0"
70
+ requirements: []
71
+
72
+ rubyforge_project:
73
+ rubygems_version: 1.3.6
74
+ signing_key:
75
+ specification_version: 3
76
+ summary: Buildr extension for packaging OSGi bundles using bnd
77
+ test_files: []
78
+