buildr-bnd 0.0.1 → 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- data/README.rdoc +28 -22
- data/lib/buildr_bnd.rb +39 -2
- data/spec/buildr/bnd/bundle_package_spec.rb +65 -15
- data/spec/buildr/bnd/to_artifacts_spec.rb +52 -0
- metadata +5 -4
data/README.rdoc
CHANGED
@@ -53,6 +53,33 @@ The extension sets the following bnd parameters;
|
|
53
53
|
* -classpath is set to the compile target directory and any compile time
|
54
54
|
dependencies.
|
55
55
|
|
56
|
+
== Parameters
|
57
|
+
|
58
|
+
=== classpath_element
|
59
|
+
|
60
|
+
The user can also specify additional elements that are added to the classpath
|
61
|
+
using the 'classpath_element' method. If the parameter to this element is a
|
62
|
+
task, artifact, artifact namespace etc. then it will be resolved prior to invoking
|
63
|
+
bnd.
|
64
|
+
|
65
|
+
define 'foo' do
|
66
|
+
...
|
67
|
+
package(:bundle).tap do |bnd|
|
68
|
+
# This dependency will be added to classpath
|
69
|
+
bnd.classpath_element 'someOtherExistingFile.zip'
|
70
|
+
# All of these dependencies will be invoked and added to classpath
|
71
|
+
bnd.classpath_element artifact('com.sun.messaging.mq:imq:jar:4.4')
|
72
|
+
bnd.classpath_element project('bar') # Adds all the packages
|
73
|
+
bnd.classpath_element 'org.apache.ant:ant:jar:1.8.0'
|
74
|
+
bnd.classpath_element file('myLocalFile.jar')
|
75
|
+
...
|
76
|
+
end
|
77
|
+
|
78
|
+
project 'bar' do
|
79
|
+
...
|
80
|
+
end
|
81
|
+
end
|
82
|
+
|
56
83
|
== Examples
|
57
84
|
|
58
85
|
=== Using bnd to wrap an existing jar
|
@@ -69,10 +96,10 @@ example wraps the OpenMQ JMS provider as an OSGi bundle.
|
|
69
96
|
define 'com.sun.messaging.mq.imq' do
|
70
97
|
project.version = '4.4'
|
71
98
|
project.group = 'iris'
|
72
|
-
compile.with 'com.sun.messaging.mq:imq:jar:4.4'
|
73
99
|
package(:bundle).tap do |bnd|
|
74
100
|
bnd['Import-Package'] = "*;resolution:=optional"
|
75
101
|
bnd['Export-Package'] = "com.sun.messaging.*;version=#{version}"
|
102
|
+
bnd.classpath_element 'com.sun.messaging.mq:imq:jar:4.4'
|
76
103
|
end
|
77
104
|
end
|
78
105
|
|
@@ -127,27 +154,6 @@ parameter withy a local value.
|
|
127
154
|
end
|
128
155
|
end
|
129
156
|
|
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
157
|
== Credit
|
152
158
|
|
153
159
|
The plugin was heavily inspired by the bnd tasks originally authored by Rhett Sutphin. It began
|
data/lib/buildr_bnd.rb
CHANGED
@@ -22,7 +22,7 @@ module Buildr
|
|
22
22
|
end
|
23
23
|
|
24
24
|
class BundleTask < Rake::FileTask
|
25
|
-
|
25
|
+
attr_reader :project
|
26
26
|
|
27
27
|
def [](key)
|
28
28
|
@params[key]
|
@@ -32,9 +32,17 @@ module Buildr
|
|
32
32
|
@params[key] = value
|
33
33
|
end
|
34
34
|
|
35
|
+
def classpath_element(dependencies)
|
36
|
+
artifacts = self.class.to_artifacts([dependencies])
|
37
|
+
self.prerequisites << artifacts
|
38
|
+
artifacts.each do |dependency|
|
39
|
+
@classpath << dependency.to_s
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
35
43
|
def to_params
|
36
44
|
params = project.manifest.merge(@params).reject { |k, v| v.nil? }
|
37
|
-
params["-classpath"] ||=
|
45
|
+
params["-classpath"] ||= @classpath.collect(&:to_s).join(", ")
|
38
46
|
params['Bundle-SymbolicName'] ||= [project.group, project.name.gsub(':', '.')].join('.')
|
39
47
|
params['Bundle-Name'] ||= project.comment || project.name
|
40
48
|
params['Bundle-Description'] ||= project.comment
|
@@ -45,8 +53,37 @@ module Buildr
|
|
45
53
|
params
|
46
54
|
end
|
47
55
|
|
56
|
+
def project=(project)
|
57
|
+
@project = project
|
58
|
+
@classpath = [project.compile.target] + project.compile.dependencies
|
59
|
+
end
|
60
|
+
|
48
61
|
protected
|
49
62
|
|
63
|
+
# Convert objects to artifacts, where applicable
|
64
|
+
def self.to_artifacts(files)
|
65
|
+
files.flatten.inject([]) do |set, file|
|
66
|
+
case file
|
67
|
+
when ArtifactNamespace
|
68
|
+
set |= file.artifacts
|
69
|
+
when Symbol, Hash
|
70
|
+
set |= [Buildr.artifact(file)]
|
71
|
+
when /([^:]+:){2,4}/ # A spec as opposed to a file name.
|
72
|
+
set |= [Buildr.artifact(file)]
|
73
|
+
when Project
|
74
|
+
set |= Buildr.artifacts(file.packages)
|
75
|
+
when Rake::Task
|
76
|
+
set |= [file]
|
77
|
+
when Struct
|
78
|
+
set |= Buildr.artifacts(file.values)
|
79
|
+
else
|
80
|
+
# non-artifacts passed as-is; in particular, String paths are
|
81
|
+
# unmodified since Rake FileTasks don't use absolute paths
|
82
|
+
set |= [file]
|
83
|
+
end
|
84
|
+
end
|
85
|
+
end
|
86
|
+
|
50
87
|
def initialize(*args) #:nodoc:
|
51
88
|
super
|
52
89
|
@params = {}
|
@@ -1,5 +1,19 @@
|
|
1
1
|
require File.expand_path('../../../spec_helper', __FILE__)
|
2
2
|
|
3
|
+
def open_zip_file(file = 'target/foo-2.1.3.jar')
|
4
|
+
jar_filename = @foo._(file)
|
5
|
+
File.should be_exist(jar_filename)
|
6
|
+
Zip::ZipFile.open(jar_filename) do |zip|
|
7
|
+
yield zip
|
8
|
+
end
|
9
|
+
end
|
10
|
+
|
11
|
+
def open_main_manifest_section(file = 'target/foo-2.1.3.jar')
|
12
|
+
jar_filename = @foo._(file)
|
13
|
+
File.should be_exist(jar_filename)
|
14
|
+
yield Buildr::Packaging::Java::Manifest.from_zip(jar_filename).main
|
15
|
+
end
|
16
|
+
|
3
17
|
describe "package :bundle" do
|
4
18
|
describe "with a valid bundle" do
|
5
19
|
before do
|
@@ -89,20 +103,6 @@ SRC
|
|
89
103
|
attribs['Magic-Food'].should eql('Cheese')
|
90
104
|
end
|
91
105
|
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
106
|
end
|
107
107
|
|
108
108
|
describe "with an invalid bundle" do
|
@@ -119,9 +119,59 @@ SRC
|
|
119
119
|
lambda { task('package').invoke }.should raise_error
|
120
120
|
end
|
121
121
|
|
122
|
-
it "raise
|
122
|
+
it "raise not produce an invalid jar file" do
|
123
123
|
lambda { task('package').invoke }.should raise_error
|
124
124
|
File.should_not be_exist(@foo._("target/foo-2.1.3.jar"))
|
125
125
|
end
|
126
126
|
end
|
127
|
+
|
128
|
+
describe "using classpath_element to specify dependency" do
|
129
|
+
before do
|
130
|
+
@foo = define "foo" do
|
131
|
+
project.version = "2.1.3"
|
132
|
+
project.group = "mygroup"
|
133
|
+
package(:bundle).tap do |bnd|
|
134
|
+
bnd['Export-Package'] = 'org.apache.tools.zip.*'
|
135
|
+
Buildr::Ant.dependencies.each do |d|
|
136
|
+
bnd.classpath_element d
|
137
|
+
end
|
138
|
+
end
|
139
|
+
end
|
140
|
+
end
|
141
|
+
|
142
|
+
it "should not raise an error during packaging" do
|
143
|
+
lambda { task('package').invoke }.should_not raise_error
|
144
|
+
end
|
145
|
+
|
146
|
+
it "should generate package with files exported from dependency" do
|
147
|
+
task('package').invoke
|
148
|
+
open_main_manifest_section do |attribs|
|
149
|
+
attribs['Export-Package'].should eql('org.apache.tools.zip')
|
150
|
+
end
|
151
|
+
end
|
152
|
+
end
|
153
|
+
|
154
|
+
describe "using compile dependencies to specify dependency" do
|
155
|
+
before do
|
156
|
+
@foo = define "foo" do
|
157
|
+
project.version = "2.1.3"
|
158
|
+
project.group = "mygroup"
|
159
|
+
compile.with Buildr::Ant.dependencies
|
160
|
+
package(:bundle).tap do |bnd|
|
161
|
+
bnd['Export-Package'] = 'org.apache.tools.zip.*'
|
162
|
+
end
|
163
|
+
end
|
164
|
+
end
|
165
|
+
|
166
|
+
it "should not raise an error during packaging" do
|
167
|
+
lambda { task('package').invoke }.should_not raise_error
|
168
|
+
end
|
169
|
+
|
170
|
+
it "should generate package with files exported from dependency" do
|
171
|
+
task('package').invoke
|
172
|
+
open_main_manifest_section do |attribs|
|
173
|
+
attribs['Export-Package'].should eql('org.apache.tools.zip')
|
174
|
+
end
|
175
|
+
end
|
176
|
+
end
|
127
177
|
end
|
@@ -0,0 +1,52 @@
|
|
1
|
+
require File.expand_path('../../../spec_helper', __FILE__)
|
2
|
+
|
3
|
+
DEPENDENCY_NAME = 'group:id:jar:1.0'
|
4
|
+
|
5
|
+
describe "Buildr:Bnd:BundleTask.to_artifacts" do
|
6
|
+
before do
|
7
|
+
@artifact = artifact(DEPENDENCY_NAME) { |t| write t.to_s }
|
8
|
+
@foo = define "foo" do
|
9
|
+
project.version = "1.1"
|
10
|
+
compile.with DEPENDENCY_NAME
|
11
|
+
package :zip
|
12
|
+
end
|
13
|
+
|
14
|
+
@bar = define "bar" do
|
15
|
+
project.version = "1.1"
|
16
|
+
compile.with DEPENDENCY_NAME
|
17
|
+
package :zip
|
18
|
+
package :jar
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
it "flattens nested arrays" do
|
23
|
+
to_artifacts([["foo"]]).should eql(['foo'])
|
24
|
+
end
|
25
|
+
|
26
|
+
it "turns projects into tasks to build projects" do
|
27
|
+
artifacts = to_artifacts([@foo])
|
28
|
+
artifacts.length.should eql(1)
|
29
|
+
artifacts[0].should be_a_kind_of(Rake::Task)
|
30
|
+
artifacts[0].to_s.should match(/foo-1\.1\.zip/)
|
31
|
+
|
32
|
+
artifacts = to_artifacts([@bar])
|
33
|
+
artifacts.length.should eql(2)
|
34
|
+
artifacts.each do |artifact|
|
35
|
+
artifact.should be_a_kind_of(Rake::Task)
|
36
|
+
artifact.to_s.should match(/bar-1\.1\.(zip|jar)/)
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
it "converts hashes into artifacts" do
|
41
|
+
artifacts = to_artifacts([{:group => 'group', :id => 'id', :version => '1.0', :type => 'jar'}])
|
42
|
+
artifacts.length.should eql(1)
|
43
|
+
artifacts[0].should be_a_kind_of(Rake::Task)
|
44
|
+
artifacts[0].to_s.should match(/group\/id\/1.0\/id-1\.0\.jar/)
|
45
|
+
end
|
46
|
+
|
47
|
+
protected
|
48
|
+
|
49
|
+
def to_artifacts(args)
|
50
|
+
Buildr::Bnd::BundleTask.to_artifacts(args)
|
51
|
+
end
|
52
|
+
end
|
metadata
CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
|
|
5
5
|
segments:
|
6
6
|
- 0
|
7
7
|
- 0
|
8
|
-
-
|
9
|
-
version: 0.0.
|
8
|
+
- 2
|
9
|
+
version: 0.0.2
|
10
10
|
platform: ruby
|
11
11
|
authors:
|
12
12
|
- Peter Donald
|
@@ -14,7 +14,7 @@ autorequire:
|
|
14
14
|
bindir: bin
|
15
15
|
cert_chain: []
|
16
16
|
|
17
|
-
date: 2010-04-
|
17
|
+
date: 2010-04-18 00:00:00 +10:00
|
18
18
|
default_executable:
|
19
19
|
dependencies: []
|
20
20
|
|
@@ -37,6 +37,7 @@ files:
|
|
37
37
|
- spec/buildr/bnd/project_extension_spec.rb
|
38
38
|
- spec/buildr/bnd/bundle_package_spec.rb
|
39
39
|
- spec/buildr/bnd/defaults_spec.rb
|
40
|
+
- spec/buildr/bnd/to_artifacts_spec.rb
|
40
41
|
- buildr-bnd.gemspec
|
41
42
|
- LICENSE
|
42
43
|
- README.rdoc
|
@@ -48,7 +49,7 @@ licenses: []
|
|
48
49
|
post_install_message:
|
49
50
|
rdoc_options:
|
50
51
|
- --title
|
51
|
-
- buildr-bnd 0.0.
|
52
|
+
- buildr-bnd 0.0.2
|
52
53
|
- --main
|
53
54
|
- README.rdoc
|
54
55
|
require_paths:
|