pangolin 0.3.0
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 +13 -0
- data/README.rdoc +72 -0
- data/Rakefile +40 -0
- data/VERSION +1 -0
- data/examples/compile/Rakefile +16 -0
- data/examples/compile/src/com/example/HelloWorld.java +10 -0
- data/examples/package/Rakefile +24 -0
- data/examples/package/src/com/example/HelloWorld.java +10 -0
- data/examples/test/Rakefile +21 -0
- data/examples/test/src/com/example/HelloWorld.java +10 -0
- data/examples/test/test/com/example/TestHelloWorld.java +31 -0
- data/java_tools.gemspec +74 -0
- data/lib/pangolin.rb +143 -0
- data/lib/pangolin/jar.rb +179 -0
- data/lib/pangolin/javac.rb +128 -0
- data/lib/pangolin/junit.rb +120 -0
- data/lib/pangolin/output/formatting.rb +65 -0
- data/spec/jar_cmd_spec.rb +121 -0
- data/spec/jar_spec.rb +259 -0
- data/spec/javac_cmd_spec.rb +101 -0
- data/spec/javac_spec.rb +203 -0
- data/spec/junit_cmd_spec.rb +24 -0
- data/spec/junit_spec.rb +24 -0
- data/spec/spec.opts +3 -0
- data/spec/spec_helper.rb +1 -0
- data/tasks/gem.rake +21 -0
- data/tasks/rdoc.rake +10 -0
- data/tasks/spec.rake +9 -0
- metadata +89 -0
@@ -0,0 +1,121 @@
|
|
1
|
+
describe "jar command" do
|
2
|
+
|
3
|
+
it "should pass the first argument to the constructor of Jar" do
|
4
|
+
output = 'archive.jar'
|
5
|
+
|
6
|
+
instance = create_non_exec_jar(output)
|
7
|
+
|
8
|
+
Jar.should_receive(:new).with(output, nil, nil).and_return(instance)
|
9
|
+
|
10
|
+
jar output
|
11
|
+
end
|
12
|
+
|
13
|
+
it "should pass the first and second arguments to the constructor of Jar" do
|
14
|
+
output = 'archive.jar'
|
15
|
+
files = ['one/two.class', 'three/four.txt']
|
16
|
+
|
17
|
+
Jar.should_receive(:new).with(output, files, nil).and_return do
|
18
|
+
instance = mock('JarInstance')
|
19
|
+
instance.should_receive(:execute).and_return(true)
|
20
|
+
instance
|
21
|
+
end
|
22
|
+
|
23
|
+
jar output, files
|
24
|
+
end
|
25
|
+
|
26
|
+
it "should yield a Jar object if a block is given" do
|
27
|
+
instance = create_non_exec_jar('archive.jar')
|
28
|
+
|
29
|
+
Jar.should_receive(:new).and_return(instance)
|
30
|
+
|
31
|
+
jar('archive.jar') do |conf|
|
32
|
+
conf.should be_instance_of(Jar)
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
it "should set properties on the yielded Jar instance" do
|
37
|
+
base_dir = 'build'
|
38
|
+
compression = 3
|
39
|
+
|
40
|
+
instance = create_non_exec_jar('archive.jar')
|
41
|
+
|
42
|
+
Jar.should_receive(:new).and_return do
|
43
|
+
instance.should_receive(:base_dir=).with(base_dir)
|
44
|
+
instance.should_receive(:compression=).with(compression)
|
45
|
+
instance
|
46
|
+
end
|
47
|
+
|
48
|
+
jar('archive.jar') do |conf|
|
49
|
+
conf.base_dir = base_dir
|
50
|
+
conf.compression = compression
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
it "should call #execute after yielding" do
|
55
|
+
Jar.should_receive(:new).and_return do
|
56
|
+
instance = mock('JarInstance')
|
57
|
+
instance.should_receive(:execute).and_return(true)
|
58
|
+
instance
|
59
|
+
end
|
60
|
+
|
61
|
+
jar('archive.jar') { }
|
62
|
+
end
|
63
|
+
|
64
|
+
it "should call #execute in non-yield mode" do
|
65
|
+
instance = create_non_exec_jar('archive.jar')
|
66
|
+
|
67
|
+
Jar.should_receive(:new).and_return(instance)
|
68
|
+
|
69
|
+
jar 'archive.jar', :compression => 4
|
70
|
+
end
|
71
|
+
|
72
|
+
it "should fail if #execute returns false" do
|
73
|
+
instance = mock('Jar')
|
74
|
+
instance.should_receive(:execute).and_return(false)
|
75
|
+
|
76
|
+
Jar.should_receive(:new).and_return(instance)
|
77
|
+
|
78
|
+
lambda { jar 'archive.jar' }.should raise_error
|
79
|
+
end
|
80
|
+
|
81
|
+
it "should set the properties specified in the options parameter" do
|
82
|
+
base_dir = 'build'
|
83
|
+
compression = 4
|
84
|
+
|
85
|
+
Jar.should_receive(:new).and_return do
|
86
|
+
instance = mock('JarInstance')
|
87
|
+
instance.should_receive(:base_dir=).with(base_dir)
|
88
|
+
instance.should_receive(:compression=).with(compression)
|
89
|
+
instance.should_receive(:verbose=).with(false)
|
90
|
+
instance.should_receive(:execute).and_return(true)
|
91
|
+
instance
|
92
|
+
end
|
93
|
+
|
94
|
+
jar 'archive.jar', ['build/two/three.class'], :base_dir => base_dir, :compression => compression, :verbose => false
|
95
|
+
end
|
96
|
+
|
97
|
+
it "should raise an exception for an invalid option" do
|
98
|
+
lambda {
|
99
|
+
jar 'archive.jar', ['Main.class'], :bogus => 'option'
|
100
|
+
}.should raise_error(ArgumentError)
|
101
|
+
end
|
102
|
+
|
103
|
+
it "should pass the base_dir option straight to the constructor" do
|
104
|
+
output = 'output.jar'
|
105
|
+
files = [__FILE__]
|
106
|
+
base_dir = File.dirname(__FILE__)
|
107
|
+
|
108
|
+
instance = create_non_exec_jar(output, files)
|
109
|
+
|
110
|
+
Jar.should_receive(:new).with(output, files, base_dir).and_return(instance)
|
111
|
+
|
112
|
+
jar output, files, :base_dir => base_dir
|
113
|
+
end
|
114
|
+
|
115
|
+
def create_non_exec_jar( output, files = nil )
|
116
|
+
instance = Jar.new(output, files)
|
117
|
+
instance.should_receive(:execute).and_return(true) # stop the real #execute from being called
|
118
|
+
instance
|
119
|
+
end
|
120
|
+
|
121
|
+
end
|
data/spec/jar_spec.rb
ADDED
@@ -0,0 +1,259 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
|
2
|
+
|
3
|
+
|
4
|
+
describe Jar do
|
5
|
+
|
6
|
+
before(:each) do
|
7
|
+
@output = 'archive.jar'
|
8
|
+
@jar = Jar.new(@output)
|
9
|
+
end
|
10
|
+
|
11
|
+
describe " defaults" do
|
12
|
+
|
13
|
+
it "should set the output file specified in the constructor" do
|
14
|
+
@jar.output.should == @output
|
15
|
+
end
|
16
|
+
|
17
|
+
it "should have a default compression rate between 0 and 9" do
|
18
|
+
(@jar.compression >= 0).should be_true
|
19
|
+
(@jar.compression <= 9).should be_true
|
20
|
+
end
|
21
|
+
|
22
|
+
it "should have a default manifest" do
|
23
|
+
@jar.manifest_string.should_not be_nil
|
24
|
+
end
|
25
|
+
|
26
|
+
it "should have no entries" do
|
27
|
+
@jar.entries.should be_empty
|
28
|
+
end
|
29
|
+
|
30
|
+
end
|
31
|
+
|
32
|
+
describe "#initialize" do
|
33
|
+
|
34
|
+
it "should take a path to the output file as parameters" do
|
35
|
+
output = 'path/to/output.jar'
|
36
|
+
|
37
|
+
jar = Jar.new(output)
|
38
|
+
|
39
|
+
jar.output.should == output
|
40
|
+
end
|
41
|
+
|
42
|
+
it "should take a path to the output and a list of files as parameters" do
|
43
|
+
output = 'output.jar'
|
44
|
+
files = [__FILE__]
|
45
|
+
|
46
|
+
jar = Jar.new(output, files)
|
47
|
+
|
48
|
+
jar.output.should == output
|
49
|
+
jar.entries.should == [__FILE__]
|
50
|
+
end
|
51
|
+
|
52
|
+
end
|
53
|
+
|
54
|
+
describe "#archive_path" do
|
55
|
+
|
56
|
+
it "should remove the base dir path from the archive path" do
|
57
|
+
@jar.find_archive_path('build/com/example/HelloWorld.class', 'build').should == 'com/example/HelloWorld.class'
|
58
|
+
end
|
59
|
+
|
60
|
+
it "should not remove anything from a file not in the base dir path" do
|
61
|
+
@jar.find_archive_path('some/other/path', 'build').should == 'some/other/path'
|
62
|
+
end
|
63
|
+
|
64
|
+
it "should not remove anything from a file path if the base dir path is nil" do
|
65
|
+
@jar.find_archive_path('some/other/path', nil).should == 'some/other/path'
|
66
|
+
end
|
67
|
+
|
68
|
+
end
|
69
|
+
|
70
|
+
describe " manifest" do
|
71
|
+
|
72
|
+
it "should include the Built-By key" do
|
73
|
+
@jar.manifest_string.include?('Built-By').should be_true
|
74
|
+
end
|
75
|
+
|
76
|
+
it "should include added attributes" do
|
77
|
+
@jar.manifest = {'abc' => '123'}
|
78
|
+
|
79
|
+
@jar.manifest_string.include?('abc: 123').should be_true
|
80
|
+
end
|
81
|
+
|
82
|
+
it "should write the attributes on the right format" do
|
83
|
+
@jar.manifest = {'one' => '1', 'two' => '2', 'three' => '3'}
|
84
|
+
|
85
|
+
@jar.manifest_string.include?("one: 1\n").should be_true
|
86
|
+
@jar.manifest_string.include?("two: 2\n").should be_true
|
87
|
+
@jar.manifest_string.include?("three: 3\n").should be_true
|
88
|
+
end
|
89
|
+
|
90
|
+
it "should not begin with whitespace" do
|
91
|
+
@jar.manifest_string[0..1].should_not match(/\s/)
|
92
|
+
end
|
93
|
+
|
94
|
+
it "should reject an empty attribute name" do
|
95
|
+
lambda {
|
96
|
+
@jar.manifest = {'' => '432'}
|
97
|
+
}.should raise_error(ArgumentError)
|
98
|
+
end
|
99
|
+
|
100
|
+
it "should reject nil as attribute name" do
|
101
|
+
lambda {
|
102
|
+
@jar.manifest = {nil => 'Hello world'}
|
103
|
+
}.should raise_error(ArgumentError)
|
104
|
+
end
|
105
|
+
|
106
|
+
it "should reject an attribute name containing a space" do
|
107
|
+
lambda {
|
108
|
+
@jar.manifest = {'Hello World' => 'foo'}
|
109
|
+
}.should raise_error(ArgumentError)
|
110
|
+
end
|
111
|
+
|
112
|
+
it "should reject an attribute name containing a colon" do
|
113
|
+
lambda {
|
114
|
+
@jar.manifest = {'Hello:World' => 'foo'}
|
115
|
+
}.should raise_error(ArgumentError)
|
116
|
+
end
|
117
|
+
|
118
|
+
it "should accept a variety of legal attribute names" do
|
119
|
+
lambda {
|
120
|
+
@jar.manifest = {
|
121
|
+
'Manifest-Version' => 'foo',
|
122
|
+
'Created-By' => 'foo',
|
123
|
+
'Signature-Version' => 'foo',
|
124
|
+
'Class-Path' => 'foo'
|
125
|
+
}
|
126
|
+
}.should_not raise_error
|
127
|
+
end
|
128
|
+
|
129
|
+
it "should ignore case when setting attributes" do
|
130
|
+
@jar.manifest = {'Hello' => 'World', 'hello' => 'Theo'}
|
131
|
+
|
132
|
+
@jar.manifest_string.include?('Hello: World').should be_false
|
133
|
+
@jar.manifest_string.include?('hello: Theo').should be_true
|
134
|
+
end
|
135
|
+
|
136
|
+
end
|
137
|
+
|
138
|
+
describe "#main_class=" do
|
139
|
+
|
140
|
+
it "should set the Main-Class attribute" do
|
141
|
+
@jar.main_class = 'com.example.Main'
|
142
|
+
|
143
|
+
@jar.manifest_string.include?('Main-Class: com.example.Main').should be_true
|
144
|
+
end
|
145
|
+
|
146
|
+
end
|
147
|
+
|
148
|
+
describe "#add_file" do
|
149
|
+
|
150
|
+
it "should add an entry" do
|
151
|
+
path = __FILE__
|
152
|
+
|
153
|
+
@jar.add_file(path)
|
154
|
+
|
155
|
+
@jar.entries.include?(path).should be_true
|
156
|
+
end
|
157
|
+
|
158
|
+
it "should add an entry at the specified archive path" do
|
159
|
+
path = __FILE__
|
160
|
+
archive_path = 'some/other/path.rb'
|
161
|
+
|
162
|
+
@jar.add_file(path, archive_path)
|
163
|
+
|
164
|
+
@jar.entries.include?(path).should be_false
|
165
|
+
@jar.entries.include?(archive_path).should be_true
|
166
|
+
end
|
167
|
+
|
168
|
+
it "should raise an exception if the file doesn't exist" do
|
169
|
+
lambda {
|
170
|
+
@jar.add_file('some/bogus/path')
|
171
|
+
}.should raise_error(ArgumentError)
|
172
|
+
end
|
173
|
+
|
174
|
+
it "should raise an exception if the argument is a directory" do
|
175
|
+
lambda {
|
176
|
+
@jar.add_file(File.dirname(__FILE__))
|
177
|
+
}.should raise_error(ArgumentError)
|
178
|
+
end
|
179
|
+
|
180
|
+
end
|
181
|
+
|
182
|
+
describe "#add_blob" do
|
183
|
+
|
184
|
+
it "should add an entry" do
|
185
|
+
archive_path = 'some/path/to/a/file.txt'
|
186
|
+
|
187
|
+
@jar.add_blob('one two three', archive_path)
|
188
|
+
|
189
|
+
@jar.entries.include?(archive_path).should be_true
|
190
|
+
end
|
191
|
+
|
192
|
+
end
|
193
|
+
|
194
|
+
describe "#add_files" do
|
195
|
+
|
196
|
+
it "should add all files" do
|
197
|
+
files = Dir.glob(File.dirname(__FILE__) + '/*.rb')
|
198
|
+
|
199
|
+
@jar.add_files(files)
|
200
|
+
|
201
|
+
files.each do |file|
|
202
|
+
@jar.entries.include?(file).should be_true
|
203
|
+
end
|
204
|
+
end
|
205
|
+
|
206
|
+
it "should remove the base dir from all file paths" do
|
207
|
+
files = Dir.glob(File.dirname(__FILE__) + '/*.rb').map { |f| File.expand_path(f) }
|
208
|
+
base_dir = File.expand_path(File.dirname(__FILE__ + '/..'))
|
209
|
+
|
210
|
+
@jar.add_files(files, base_dir)
|
211
|
+
|
212
|
+
files.each do |file|
|
213
|
+
@jar.entries.include?(file.gsub(base_dir + '/', '')).should be_true
|
214
|
+
end
|
215
|
+
end
|
216
|
+
|
217
|
+
it "should raise an exception if any of the files is a directory" do
|
218
|
+
files = [__FILE__, File.dirname(__FILE__)]
|
219
|
+
|
220
|
+
lambda {
|
221
|
+
@jar.add_files(files)
|
222
|
+
}.should raise_error(ArgumentError)
|
223
|
+
end
|
224
|
+
|
225
|
+
it "should raise an exception if any file doesn't exist" do
|
226
|
+
files = [__FILE__, 'some/bogus/path.txt']
|
227
|
+
|
228
|
+
lambda {
|
229
|
+
@jar.add_files(files)
|
230
|
+
}.should raise_error(ArgumentError)
|
231
|
+
end
|
232
|
+
|
233
|
+
end
|
234
|
+
|
235
|
+
describe "#remove_entry" do
|
236
|
+
|
237
|
+
it "should remove an added file" do
|
238
|
+
@jar.add_file(__FILE__)
|
239
|
+
@jar.remove_entry(__FILE__)
|
240
|
+
|
241
|
+
@jar.entries.include?(__FILE__).should be_false
|
242
|
+
end
|
243
|
+
|
244
|
+
it "should remove an added blob" do
|
245
|
+
@jar.add_blob('foobar', 'foo/bar')
|
246
|
+
@jar.remove_entry('foo/bar')
|
247
|
+
|
248
|
+
@jar.entries.include?('foo/bar').should be_false
|
249
|
+
end
|
250
|
+
|
251
|
+
it "should not do anything when removing an entry that does not exist" do
|
252
|
+
lambda {
|
253
|
+
@jar.remove_entry('non/existent/entry')
|
254
|
+
}.should_not change(@jar, :entries)
|
255
|
+
end
|
256
|
+
|
257
|
+
end
|
258
|
+
|
259
|
+
end
|
@@ -0,0 +1,101 @@
|
|
1
|
+
describe "javac command" do
|
2
|
+
|
3
|
+
it "should pass the first argument to the constructor of Javac" do
|
4
|
+
files = ['one/two.java', 'three/four.java']
|
5
|
+
|
6
|
+
instance = Javac.new(*files)
|
7
|
+
instance.should_receive(:execute).and_return(true) # stop the real execute from being called
|
8
|
+
|
9
|
+
Javac.should_receive(:new).with(*files).and_return(instance)
|
10
|
+
|
11
|
+
javac files
|
12
|
+
end
|
13
|
+
|
14
|
+
it "should yield a Javac object if a block is given" do
|
15
|
+
# prepare a stub that prevents the real #execute being called
|
16
|
+
instance = Javac.new
|
17
|
+
instance.should_receive(:execute).and_return(true)
|
18
|
+
|
19
|
+
Javac.should_receive(:new).and_return(instance)
|
20
|
+
|
21
|
+
javac('Main.java') do |conf|
|
22
|
+
conf.should be_instance_of(Javac)
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
it "should set properties on the yielded Javac instance" do
|
27
|
+
destination = 'build'
|
28
|
+
source_path = ['xyz', 'abc']
|
29
|
+
|
30
|
+
instance = Javac.new('Main.java')
|
31
|
+
|
32
|
+
Javac.should_receive(:new).and_return do
|
33
|
+
instance.should_receive(:destination=).with(destination)
|
34
|
+
instance.should_receive(:source_path=).with(source_path)
|
35
|
+
instance.should_receive(:execute).and_return(true) # stop the real execute from being called
|
36
|
+
instance
|
37
|
+
end
|
38
|
+
|
39
|
+
javac('Main.java') do |conf|
|
40
|
+
conf.destination = destination
|
41
|
+
conf.source_path = source_path
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
it "should call #execute after yielding" do
|
46
|
+
Javac.should_receive(:new).and_return do
|
47
|
+
instance = mock('JavacInstance')
|
48
|
+
instance.should_receive(:execute).and_return(true)
|
49
|
+
instance
|
50
|
+
end
|
51
|
+
|
52
|
+
javac('Main.java') { }
|
53
|
+
end
|
54
|
+
|
55
|
+
it "should call #execute in non-yield mode" do
|
56
|
+
files = ['one/two.java', 'three/four.java']
|
57
|
+
|
58
|
+
instance = Javac.new(*files)
|
59
|
+
|
60
|
+
Javac.should_receive(:new).with(*files).and_return do
|
61
|
+
instance.should_receive(:execute).and_return(true)
|
62
|
+
instance
|
63
|
+
end
|
64
|
+
|
65
|
+
javac files, :destination => 'build'
|
66
|
+
end
|
67
|
+
|
68
|
+
it "should fail if #execute returns false" do
|
69
|
+
instance = mock('Javac')
|
70
|
+
instance.should_receive(:execute).and_return(false)
|
71
|
+
|
72
|
+
Javac.should_receive(:new).and_return(instance)
|
73
|
+
|
74
|
+
lambda { javac ['Hello', 'World'] }.should raise_error
|
75
|
+
end
|
76
|
+
|
77
|
+
it "should set the properties specified in the options parameter" do
|
78
|
+
files = ['one/two.java', 'three/four.java']
|
79
|
+
destination = 'build'
|
80
|
+
source_path = ['src', 'common/src']
|
81
|
+
|
82
|
+
instance = mock('JavacInstance')
|
83
|
+
|
84
|
+
Javac.should_receive(:new).with(*files).and_return do
|
85
|
+
instance.should_receive(:destination=).with(destination)
|
86
|
+
instance.should_receive(:source_path=).with(source_path)
|
87
|
+
instance.should_receive(:warnings=).with(false)
|
88
|
+
instance.should_receive(:execute).and_return(true) # stop the real execute from being called
|
89
|
+
instance
|
90
|
+
end
|
91
|
+
|
92
|
+
javac files, :destination => destination, :source_path => source_path, :warnings => false
|
93
|
+
end
|
94
|
+
|
95
|
+
it "should raise an exception for an invalid option" do
|
96
|
+
lambda {
|
97
|
+
javac ['Main.java'], :bogus => 'option'
|
98
|
+
}.should raise_error(ArgumentError)
|
99
|
+
end
|
100
|
+
|
101
|
+
end
|