assaf-buildr 1.3.3

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 (163) hide show
  1. data/CHANGELOG +887 -0
  2. data/DISCLAIMER +7 -0
  3. data/LICENSE +176 -0
  4. data/NOTICE +26 -0
  5. data/README.rdoc +146 -0
  6. data/Rakefile +62 -0
  7. data/_buildr +38 -0
  8. data/addon/buildr/antlr.rb +65 -0
  9. data/addon/buildr/cobertura.rb +236 -0
  10. data/addon/buildr/emma.rb +238 -0
  11. data/addon/buildr/hibernate.rb +142 -0
  12. data/addon/buildr/javacc.rb +85 -0
  13. data/addon/buildr/jdepend.rb +60 -0
  14. data/addon/buildr/jetty.rb +248 -0
  15. data/addon/buildr/jibx.rb +86 -0
  16. data/addon/buildr/nailgun.rb +817 -0
  17. data/addon/buildr/openjpa.rb +90 -0
  18. data/addon/buildr/org/apache/buildr/BuildrNail$Main.class +0 -0
  19. data/addon/buildr/org/apache/buildr/BuildrNail.class +0 -0
  20. data/addon/buildr/org/apache/buildr/BuildrNail.java +41 -0
  21. data/addon/buildr/org/apache/buildr/JettyWrapper$1.class +0 -0
  22. data/addon/buildr/org/apache/buildr/JettyWrapper$BuildrHandler.class +0 -0
  23. data/addon/buildr/org/apache/buildr/JettyWrapper.class +0 -0
  24. data/addon/buildr/org/apache/buildr/JettyWrapper.java +144 -0
  25. data/addon/buildr/xmlbeans.rb +93 -0
  26. data/bin/buildr +28 -0
  27. data/buildr.buildfile +53 -0
  28. data/buildr.gemspec +58 -0
  29. data/doc/css/default.css +228 -0
  30. data/doc/css/print.css +100 -0
  31. data/doc/css/syntax.css +52 -0
  32. data/doc/images/apache-incubator-logo.png +0 -0
  33. data/doc/images/buildr-hires.png +0 -0
  34. data/doc/images/buildr.png +0 -0
  35. data/doc/images/favicon.png +0 -0
  36. data/doc/images/growl-icon.tiff +0 -0
  37. data/doc/images/note.png +0 -0
  38. data/doc/images/project-structure.png +0 -0
  39. data/doc/images/tip.png +0 -0
  40. data/doc/images/zbuildr.tif +0 -0
  41. data/doc/pages/artifacts.textile +207 -0
  42. data/doc/pages/building.textile +240 -0
  43. data/doc/pages/contributing.textile +208 -0
  44. data/doc/pages/download.textile +62 -0
  45. data/doc/pages/extending.textile +175 -0
  46. data/doc/pages/getting_started.textile +273 -0
  47. data/doc/pages/index.textile +42 -0
  48. data/doc/pages/languages.textile +407 -0
  49. data/doc/pages/mailing_lists.textile +17 -0
  50. data/doc/pages/more_stuff.textile +286 -0
  51. data/doc/pages/packaging.textile +427 -0
  52. data/doc/pages/projects.textile +274 -0
  53. data/doc/pages/recipes.textile +103 -0
  54. data/doc/pages/settings_profiles.textile +274 -0
  55. data/doc/pages/testing.textile +212 -0
  56. data/doc/pages/troubleshooting.textile +103 -0
  57. data/doc/pages/whats_new.textile +323 -0
  58. data/doc/print.haml +51 -0
  59. data/doc/print.toc.yaml +29 -0
  60. data/doc/scripts/buildr-git.rb +412 -0
  61. data/doc/scripts/install-jruby.sh +44 -0
  62. data/doc/scripts/install-linux.sh +64 -0
  63. data/doc/scripts/install-osx.sh +52 -0
  64. data/doc/site.haml +56 -0
  65. data/doc/site.toc.yaml +47 -0
  66. data/etc/KEYS +151 -0
  67. data/etc/git-svn-authors +16 -0
  68. data/lib/buildr.rb +35 -0
  69. data/lib/buildr/core.rb +27 -0
  70. data/lib/buildr/core/application.rb +489 -0
  71. data/lib/buildr/core/application_cli.rb +139 -0
  72. data/lib/buildr/core/build.rb +311 -0
  73. data/lib/buildr/core/checks.rb +382 -0
  74. data/lib/buildr/core/common.rb +154 -0
  75. data/lib/buildr/core/compile.rb +596 -0
  76. data/lib/buildr/core/environment.rb +120 -0
  77. data/lib/buildr/core/filter.rb +362 -0
  78. data/lib/buildr/core/generate.rb +195 -0
  79. data/lib/buildr/core/help.rb +118 -0
  80. data/lib/buildr/core/progressbar.rb +156 -0
  81. data/lib/buildr/core/project.rb +892 -0
  82. data/lib/buildr/core/test.rb +715 -0
  83. data/lib/buildr/core/transports.rb +558 -0
  84. data/lib/buildr/core/util.rb +289 -0
  85. data/lib/buildr/groovy.rb +18 -0
  86. data/lib/buildr/groovy/bdd.rb +105 -0
  87. data/lib/buildr/groovy/compiler.rb +138 -0
  88. data/lib/buildr/ide.rb +19 -0
  89. data/lib/buildr/ide/eclipse.rb +212 -0
  90. data/lib/buildr/ide/idea.ipr.template +300 -0
  91. data/lib/buildr/ide/idea.rb +189 -0
  92. data/lib/buildr/ide/idea7x.ipr.template +290 -0
  93. data/lib/buildr/ide/idea7x.rb +210 -0
  94. data/lib/buildr/java.rb +23 -0
  95. data/lib/buildr/java/ant.rb +92 -0
  96. data/lib/buildr/java/bdd.rb +449 -0
  97. data/lib/buildr/java/commands.rb +211 -0
  98. data/lib/buildr/java/compiler.rb +348 -0
  99. data/lib/buildr/java/deprecated.rb +141 -0
  100. data/lib/buildr/java/jruby.rb +117 -0
  101. data/lib/buildr/java/jtestr_runner.rb.erb +116 -0
  102. data/lib/buildr/java/org/apache/buildr/JavaTestFilter.class +0 -0
  103. data/lib/buildr/java/org/apache/buildr/JavaTestFilter.java +119 -0
  104. data/lib/buildr/java/packaging.rb +713 -0
  105. data/lib/buildr/java/pom.rb +178 -0
  106. data/lib/buildr/java/rjb.rb +155 -0
  107. data/lib/buildr/java/test_result.rb +308 -0
  108. data/lib/buildr/java/tests.rb +324 -0
  109. data/lib/buildr/java/version_requirement.rb +172 -0
  110. data/lib/buildr/packaging.rb +21 -0
  111. data/lib/buildr/packaging/artifact.rb +730 -0
  112. data/lib/buildr/packaging/artifact_namespace.rb +972 -0
  113. data/lib/buildr/packaging/artifact_search.rb +140 -0
  114. data/lib/buildr/packaging/gems.rb +102 -0
  115. data/lib/buildr/packaging/package.rb +233 -0
  116. data/lib/buildr/packaging/tar.rb +104 -0
  117. data/lib/buildr/packaging/zip.rb +722 -0
  118. data/lib/buildr/resources/buildr.icns +0 -0
  119. data/lib/buildr/scala.rb +19 -0
  120. data/lib/buildr/scala/compiler.rb +109 -0
  121. data/lib/buildr/scala/tests.rb +203 -0
  122. data/rakelib/apache.rake +191 -0
  123. data/rakelib/changelog.rake +57 -0
  124. data/rakelib/doc.rake +103 -0
  125. data/rakelib/package.rake +73 -0
  126. data/rakelib/release.rake +65 -0
  127. data/rakelib/rspec.rake +83 -0
  128. data/rakelib/rubyforge.rake +53 -0
  129. data/rakelib/scm.rake +49 -0
  130. data/rakelib/setup.rake +86 -0
  131. data/rakelib/stage.rake +48 -0
  132. data/spec/addon/cobertura_spec.rb +77 -0
  133. data/spec/addon/emma_spec.rb +120 -0
  134. data/spec/addon/test_coverage_spec.rb +255 -0
  135. data/spec/core/application_spec.rb +412 -0
  136. data/spec/core/artifact_namespace_spec.rb +646 -0
  137. data/spec/core/build_spec.rb +415 -0
  138. data/spec/core/checks_spec.rb +537 -0
  139. data/spec/core/common_spec.rb +664 -0
  140. data/spec/core/compile_spec.rb +566 -0
  141. data/spec/core/generate_spec.rb +33 -0
  142. data/spec/core/project_spec.rb +754 -0
  143. data/spec/core/test_spec.rb +1091 -0
  144. data/spec/core/transport_spec.rb +500 -0
  145. data/spec/groovy/bdd_spec.rb +80 -0
  146. data/spec/groovy/compiler_spec.rb +239 -0
  147. data/spec/ide/eclipse_spec.rb +243 -0
  148. data/spec/java/ant.rb +28 -0
  149. data/spec/java/bdd_spec.rb +358 -0
  150. data/spec/java/compiler_spec.rb +446 -0
  151. data/spec/java/java_spec.rb +88 -0
  152. data/spec/java/packaging_spec.rb +1103 -0
  153. data/spec/java/tests_spec.rb +466 -0
  154. data/spec/packaging/archive_spec.rb +503 -0
  155. data/spec/packaging/artifact_spec.rb +754 -0
  156. data/spec/packaging/packaging_helper.rb +63 -0
  157. data/spec/packaging/packaging_spec.rb +589 -0
  158. data/spec/sandbox.rb +137 -0
  159. data/spec/scala/compiler_spec.rb +228 -0
  160. data/spec/scala/tests_spec.rb +215 -0
  161. data/spec/spec_helpers.rb +304 -0
  162. data/spec/version_requirement_spec.rb +123 -0
  163. metadata +369 -0
@@ -0,0 +1,88 @@
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
+ unless RUBY_PLATFORM =~ /java/
19
+ describe ENV, 'JAVA_HOME on OS X' do
20
+ before do
21
+ @old_home, ENV['JAVA_HOME'] = ENV['JAVA_HOME'], nil
22
+ @old_env_java = ENV_JAVA
23
+ Config::CONFIG.should_receive(:[]).with('host_os').and_return('darwin0.9')
24
+ end
25
+
26
+ it 'should point to default JVM' do
27
+ load File.expand_path('../lib/buildr/java/rjb.rb')
28
+ ENV['JAVA_HOME'].should == '/System/Library/Frameworks/JavaVM.framework/Home'
29
+ end
30
+
31
+ it 'should use value of environment variable if specified' do
32
+ ENV['JAVA_HOME'] = '/System/Library/Frameworks/JavaVM.specified'
33
+ load File.expand_path('../lib/buildr/java/rjb.rb')
34
+ ENV['JAVA_HOME'].should == '/System/Library/Frameworks/JavaVM.specified'
35
+ end
36
+
37
+ after do
38
+ ENV['JAVA_HOME'] = @old_home
39
+ ENV_JAVA.replace @old_env_java
40
+ end
41
+ end
42
+ end
43
+
44
+
45
+ describe Java, '#tools_jar' do
46
+ before do
47
+ @old_home = ENV['JAVA_HOME']
48
+ end
49
+
50
+ describe 'when JAVA_HOME points to a JDK' do
51
+ before do
52
+ Java.instance_eval { @tools_jar = nil }
53
+ write 'jdk/lib/tools.jar'
54
+ ENV['JAVA_HOME'] = File.expand_path('jdk')
55
+ end
56
+
57
+ it 'should return the path to tools.jar' do
58
+ Java.tools_jar.should point_to_path('jdk/lib/tools.jar')
59
+ end
60
+ end
61
+
62
+ describe 'when JAVA_HOME points to a JRE inside a JDK' do
63
+ before do
64
+ Java.instance_eval { @tools_jar = nil }
65
+ write 'jdk/lib/tools.jar'
66
+ ENV['JAVA_HOME'] = File.expand_path('jdk/jre')
67
+ end
68
+
69
+ it 'should return the path to tools.jar' do
70
+ Java.tools_jar.should point_to_path('jdk/lib/tools.jar')
71
+ end
72
+ end
73
+
74
+ describe 'when there is no tools.jar' do
75
+ before do
76
+ Java.instance_eval { @tools_jar = nil }
77
+ ENV['JAVA_HOME'] = File.expand_path('jdk')
78
+ end
79
+
80
+ it 'should return nil' do
81
+ Java.tools_jar.should be_nil
82
+ end
83
+ end
84
+
85
+ after do
86
+ ENV['JAVA_HOME'] = @old_home
87
+ end
88
+ end
@@ -0,0 +1,1103 @@
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
+
17
+ require File.join(File.dirname(__FILE__), '../spec_helpers')
18
+ require File.join(File.dirname(__FILE__), '../packaging/packaging_helper')
19
+
20
+
21
+ describe Project, '#manifest' do
22
+ it 'should include user name' do
23
+ ENV['USER'] = 'MysteriousJoe'
24
+ define('foo').manifest['Build-By'].should eql('MysteriousJoe')
25
+ end
26
+
27
+ it 'should include JDK version' do
28
+ define('foo').manifest['Build-Jdk'].should =~ /^1\.\d+\.\w+$/
29
+ end
30
+
31
+ it 'should include project comment' do
32
+ desc 'My Project'
33
+ define('foo').manifest['Implementation-Title'].should eql('My Project')
34
+ end
35
+
36
+ it 'should include project name if no comment' do
37
+ define('foo').manifest['Implementation-Title'].should eql('foo')
38
+ end
39
+
40
+ it 'should include project version' do
41
+ define('foo', :version=>'2.1').manifest['Implementation-Version'].should eql('2.1')
42
+ end
43
+
44
+ it 'should not include project version unless specified' do
45
+ define('foo').manifest['Implementation-Version'].should be_nil
46
+ end
47
+
48
+ it 'should inherit from parent project' do
49
+ define('foo', :version=>'2.1') { define 'bar' }
50
+ project('foo:bar').manifest['Implementation-Version'].should eql('2.1')
51
+ end
52
+
53
+ end
54
+
55
+
56
+ shared_examples_for 'package with manifest' do
57
+ before do
58
+ @long_line = 'No line may be longer than 72 bytes (not characters), in its UTF8-encoded form. If a value would make the initial line longer than this, it should be continued on extra lines (each starting with a single SPACE).'
59
+ end
60
+
61
+ def package_with_manifest(manifest = nil)
62
+ packaging = @packaging
63
+ @project = define('foo', :version=>'1.2') do
64
+ package packaging
65
+ package(packaging).with(:manifest=>manifest) unless manifest.nil?
66
+ end
67
+ end
68
+
69
+ def inspect_manifest(package = nil)
70
+ package ||= project('foo').package(@packaging)
71
+ package.invoke
72
+ yield Buildr::Packaging::Java::Manifest.from_zip(package)
73
+ end
74
+
75
+ it 'should include default header when no options specified' do
76
+ ENV['USER'] = 'MysteriousJoe'
77
+ package_with_manifest # Nothing for default.
78
+ inspect_manifest do |manifest|
79
+ manifest.sections.size.should be(1)
80
+ manifest.main.should == {
81
+ 'Manifest-Version' =>'1.0',
82
+ 'Created-By' =>'Buildr',
83
+ 'Implementation-Title' =>@project.name,
84
+ 'Implementation-Version' =>'1.2',
85
+ 'Build-Jdk' =>ENV_JAVA['java.version'],
86
+ 'Build-By' =>'MysteriousJoe'
87
+ }
88
+ end
89
+ end
90
+
91
+ it 'should not exist when manifest=false' do
92
+ package_with_manifest false
93
+ @project.package(@packaging).invoke
94
+ Zip::ZipFile.open(@project.package(@packaging).to_s) do |zip|
95
+ zip.file.exist?('META-INF/MANIFEST.MF').should be_false
96
+ end
97
+ end
98
+
99
+ it 'should map manifest from hash' do
100
+ package_with_manifest 'Foo'=>1, :bar=>'Bar'
101
+ inspect_manifest do |manifest|
102
+ manifest.sections.size.should be(1)
103
+ manifest.main['Manifest-Version'].should eql('1.0')
104
+ manifest.main['Created-By'].should eql('Buildr')
105
+ manifest.main['Foo'].should eql('1')
106
+ manifest.main['bar'].should eql('Bar')
107
+ end
108
+ end
109
+
110
+ it 'should end hash manifest with EOL' do
111
+ package_with_manifest 'Foo'=>1, :bar=>'Bar'
112
+ package = project('foo').package(@packaging)
113
+ package.invoke
114
+ Zip::ZipFile.open(package.to_s) { |zip| zip.file.read('META-INF/MANIFEST.MF').should =~ /#{Buildr::Packaging::Java::Manifest::LINE_SEPARATOR}$/ }
115
+ end
116
+
117
+ it 'should break hash manifest lines longer than 72 characters using continuations' do
118
+ package_with_manifest 'foo'=>@long_line
119
+ package = project('foo').package(@packaging)
120
+ inspect_manifest do |manifest|
121
+ manifest.main['foo'].should == @long_line
122
+ end
123
+ end
124
+
125
+ it 'should map manifest from array' do
126
+ package_with_manifest [ { :foo=>'first' }, { :bar=>'second' } ]
127
+ inspect_manifest do |manifest|
128
+ manifest.sections.size.should be(2)
129
+ manifest.main['Manifest-Version'].should eql('1.0')
130
+ manifest.main['foo'].should eql('first')
131
+ manifest.sections.last['bar'].should eql('second')
132
+ end
133
+ end
134
+
135
+ it 'should end array manifest with EOL' do
136
+ package_with_manifest [ { :foo=>'first' }, { :bar=>'second' } ]
137
+ package = project('foo').package(@packaging)
138
+ package.invoke
139
+ Zip::ZipFile.open(package.to_s) { |zip| zip.file.read('META-INF/MANIFEST.MF')[-1].should == ?\n }
140
+ end
141
+
142
+ it 'should break array manifest lines longer than 72 characters using continuations' do
143
+ package_with_manifest ['foo'=>@long_line]
144
+ package = project('foo').package(@packaging)
145
+ inspect_manifest do |manifest|
146
+ manifest.main['foo'].should == @long_line
147
+ end
148
+ end
149
+
150
+ it 'should put Name: at beginning of section' do
151
+ package_with_manifest [ {}, { 'Name'=>'first', :Foo=>'first', :bar=>'second' } ]
152
+ package = project('foo').package(@packaging)
153
+ package.invoke
154
+ inspect_manifest do |manifest|
155
+ manifest.sections[1]["Name"].should == "first"
156
+ end
157
+ end
158
+
159
+ it 'should create manifest from proc' do
160
+ package_with_manifest lambda { 'Meta: data' }
161
+ inspect_manifest do |manifest|
162
+ manifest.sections.size.should be(1)
163
+ manifest.main['Manifest-Version'].should eql('1.0')
164
+ manifest.main['Meta'].should eql('data')
165
+ end
166
+ end
167
+
168
+ it 'should create manifest from file' do
169
+ write 'MANIFEST.MF', 'Meta: data'
170
+ package_with_manifest 'MANIFEST.MF'
171
+ inspect_manifest do |manifest|
172
+ manifest.sections.size.should be(1)
173
+ manifest.main['Manifest-Version'].should eql('1.0')
174
+ manifest.main['Meta'].should eql('data')
175
+ end
176
+ end
177
+
178
+ it 'should create manifest from task' do
179
+ file 'MANIFEST.MF' do |task|
180
+ write task.to_s, 'Meta: data'
181
+ end
182
+ package_with_manifest 'MANIFEST.MF'
183
+ inspect_manifest do |manifest|
184
+ manifest.sections.size.should be(1)
185
+ manifest.main['Manifest-Version'].should eql('1.0')
186
+ manifest.main['Meta'].should eql('data')
187
+ end
188
+ end
189
+
190
+ it 'should respond to with() and accept manifest' do
191
+ write 'DISCLAIMER'
192
+ mkpath 'target/classes'
193
+ packaging = @packaging
194
+ define('foo', :version=>'1.0') { package(packaging).with :manifest=>{'Foo'=>'data'} }
195
+ inspect_manifest { |manifest| manifest.main['Foo'].should eql('data') }
196
+ end
197
+
198
+ it 'should include META-INF directory' do
199
+ packaging = @packaging
200
+ package = define('foo', :version=>'1.0') { package(packaging) }.packages.first
201
+ package.invoke
202
+ Zip::ZipFile.open(package.to_s) do |zip|
203
+ zip.entries.map(&:to_s).should include('META-INF/')
204
+ end
205
+ end
206
+
207
+ it 'should inherit manifest from parent project' do
208
+ packaging = @packaging
209
+ package = nil
210
+ define('foo', :version => '1.0') do
211
+ manifest['Foo'] = '1'
212
+ package(packaging)
213
+ define('bar', :version => '1.0') do
214
+ manifest['bar'] = 'Bar'
215
+ package(:jar)
216
+ package = packages.first
217
+ end
218
+ end
219
+ inspect_manifest(package) do |manifest|
220
+ manifest.sections.size.should be(1)
221
+ manifest.main['Manifest-Version'].should eql('1.0')
222
+ manifest.main['Created-By'].should eql('Buildr')
223
+ manifest.main['Foo'].should eql('1')
224
+ manifest.main['bar'].should eql('Bar')
225
+ end
226
+ end
227
+
228
+ it 'should not modify manifest of parent project' do
229
+ packaging = @packaging
230
+ define('foo', :version => '1.0') do
231
+ manifest['Foo'] = '1'
232
+ package(packaging)
233
+ define('bar', :version => '1.0') do
234
+ manifest['bar'] = 'Bar'
235
+ package(:jar)
236
+ end
237
+ define('baz', :version => '1.0') do
238
+ manifest['baz'] = 'Baz'
239
+ package(:jar)
240
+ end
241
+ end
242
+ inspect_manifest(project('foo').packages.first) do |manifest|
243
+ manifest.sections.size.should be(1)
244
+ manifest.main['Manifest-Version'].should eql('1.0')
245
+ manifest.main['Created-By'].should eql('Buildr')
246
+ manifest.main['Foo'].should eql('1')
247
+ manifest.main['bar'].should be_nil
248
+ manifest.main['baz'].should be_nil
249
+ end
250
+ inspect_manifest(project('foo:bar').packages.first) do |manifest|
251
+ manifest.sections.size.should be(1)
252
+ manifest.main['Manifest-Version'].should eql('1.0')
253
+ manifest.main['Created-By'].should eql('Buildr')
254
+ manifest.main['Foo'].should eql('1')
255
+ manifest.main['bar'].should eql('Bar')
256
+ manifest.main['baz'].should be_nil
257
+ end
258
+ inspect_manifest(project('foo:baz').packages.first) do |manifest|
259
+ manifest.sections.size.should be(1)
260
+ manifest.main['Manifest-Version'].should eql('1.0')
261
+ manifest.main['Created-By'].should eql('Buildr')
262
+ manifest.main['Foo'].should eql('1')
263
+ manifest.main['baz'].should eql('Baz')
264
+ manifest.main['bar'].should be_nil
265
+ end
266
+ end
267
+ end
268
+
269
+
270
+ describe Project, '#meta_inf' do
271
+ it 'should by an array' do
272
+ define('foo').meta_inf.should be_kind_of(Array)
273
+ end
274
+
275
+ it 'should include LICENSE file if found' do
276
+ write 'LICENSE'
277
+ define('foo').meta_inf.first.should point_to_path('LICENSE')
278
+ end
279
+
280
+ it 'should be empty unless LICENSE exists' do
281
+ define('foo').meta_inf.should be_empty
282
+ end
283
+
284
+ it 'should inherit from parent project' do
285
+ write 'LICENSE'
286
+ define('foo') { define 'bar' }
287
+ project('foo:bar').meta_inf.first.should point_to_path('LICENSE')
288
+ end
289
+
290
+ it 'should expect LICENSE file parent project' do
291
+ write 'bar/LICENSE'
292
+ define('foo') { define 'bar' }
293
+ project('foo:bar').meta_inf.should be_empty
294
+ end
295
+ end
296
+
297
+
298
+ describe 'package with meta_inf', :shared=>true do
299
+
300
+ def package_with_meta_inf(meta_inf = nil)
301
+ packaging = @packaging
302
+ @project = Buildr.define('foo', :version=>'1.2') do
303
+ package packaging
304
+ package(packaging).with(:meta_inf=>meta_inf) if meta_inf
305
+ end
306
+ end
307
+
308
+ def inspect_meta_inf
309
+ package = project('foo').package(@packaging)
310
+ package.invoke
311
+ assumed = Array(@meta_inf_ignore)
312
+ Zip::ZipFile.open(package.to_s) do |zip|
313
+ entries = zip.entries.map(&:to_s).select { |f| File.dirname(f) == 'META-INF' }.map { |f| File.basename(f) }
314
+ assumed.each { |f| entries.should include(f) }
315
+ yield entries - assumed if block_given?
316
+ end
317
+ end
318
+
319
+ it 'should default to LICENSE file' do
320
+ write 'LICENSE'
321
+ package_with_meta_inf
322
+ inspect_meta_inf { |files| files.should eql(['LICENSE']) }
323
+ end
324
+
325
+ it 'should be empty if no LICENSE file' do
326
+ package_with_meta_inf
327
+ inspect_meta_inf { |files| files.should be_empty }
328
+ end
329
+
330
+ it 'should include file specified by :meta_inf option' do
331
+ write 'README'
332
+ package_with_meta_inf 'README'
333
+ inspect_meta_inf { |files| files.should eql(['README']) }
334
+ end
335
+
336
+ it 'should include files specified by :meta_inf option' do
337
+ files = ['README', 'DISCLAIMER'].each { |file| write file }
338
+ package_with_meta_inf files
339
+ inspect_meta_inf { |files| files.should eql(files) }
340
+ end
341
+
342
+ it 'should include file task specified by :meta_inf option' do
343
+ file('README') { |task| write task.to_s }
344
+ package_with_meta_inf file('README')
345
+ inspect_meta_inf { |files| files.should eql(['README']) }
346
+ end
347
+
348
+ it 'should include file tasks specified by :meta_inf option' do
349
+ files = ['README', 'DISCLAIMER'].each { |file| file(file) { |task| write task.to_s } }
350
+ package_with_meta_inf files.map { |f| file(f) }
351
+ inspect_meta_inf { |files| files.should eql(files) }
352
+ end
353
+
354
+ it 'should complain if cannot find file' do
355
+ package_with_meta_inf 'README'
356
+ lambda { inspect_meta_inf }.should raise_error(RuntimeError, /README/)
357
+ end
358
+
359
+ it 'should complain if cannot build task' do
360
+ file('README') { fail 'Failed' }
361
+ package_with_meta_inf 'README'
362
+ lambda { inspect_meta_inf }.should raise_error(RuntimeError, /Failed/)
363
+ end
364
+
365
+ it 'should respond to with() and accept manifest and meta_inf' do
366
+ write 'DISCLAIMER'
367
+ mkpath 'target/classes'
368
+ packaging = @packaging
369
+ define('foo', :version=>'1.0') { package(packaging).with :meta_inf=>'DISCLAIMER' }
370
+ inspect_meta_inf { |files| files.should eql(['DISCLAIMER']) }
371
+ end
372
+ end
373
+
374
+
375
+ describe Packaging, 'jar' do
376
+ it_should_behave_like 'packaging'
377
+ before { @packaging = :jar }
378
+ it_should_behave_like 'package with manifest'
379
+ it_should_behave_like 'package with meta_inf'
380
+ before { @meta_inf_ignore = 'MANIFEST.MF' }
381
+
382
+ it 'should use files from compile directory if nothing included' do
383
+ write 'src/main/java/Test.java', 'class Test {}'
384
+ define('foo', :version=>'1.0') { package(:jar) }
385
+ project('foo').package(:jar).invoke
386
+ Zip::ZipFile.open(project('foo').package(:jar).to_s) do |jar|
387
+ jar.entries.map(&:to_s).sort.should include('META-INF/MANIFEST.MF', 'Test.class')
388
+ end
389
+ end
390
+
391
+ it 'should use files from resources directory if nothing included' do
392
+ write 'src/main/resources/test/important.properties'
393
+ define('foo', :version=>'1.0') { package(:jar) }
394
+ project('foo').package(:jar).invoke
395
+ Zip::ZipFile.open(project('foo').package(:jar).to_s) do |jar|
396
+ jar.entries.map(&:to_s).sort.should include('test/important.properties')
397
+ end
398
+ end
399
+
400
+ it 'should include class directories' do
401
+ write 'src/main/java/code/Test.java', 'package code ; class Test {}'
402
+ define('foo', :version=>'1.0') { package(:jar) }
403
+ project('foo').package(:jar).invoke
404
+ Zip::ZipFile.open(project('foo').package(:jar).to_s) do |jar|
405
+ jar.entries.map(&:to_s).sort.should include('code/')
406
+ end
407
+ end
408
+
409
+ it 'should include resource files starting with dot' do
410
+ write 'src/main/resources/test/.config'
411
+ define('foo', :version=>'1.0') { package(:jar) }
412
+ project('foo').package(:jar).invoke
413
+ Zip::ZipFile.open(project('foo').package(:jar).to_s) do |jar|
414
+ jar.entries.map(&:to_s).sort.should include('test/.config')
415
+ end
416
+ end
417
+
418
+ it 'should include empty resource directories' do
419
+ mkpath 'src/main/resources/empty'
420
+ define('foo', :version=>'1.0') { package(:jar) }
421
+ project('foo').package(:jar).invoke
422
+ Zip::ZipFile.open(project('foo').package(:jar).to_s) do |jar|
423
+ jar.entries.map(&:to_s).sort.should include('empty/')
424
+ end
425
+ end
426
+ end
427
+
428
+
429
+ describe Packaging, 'war' do
430
+ it_should_behave_like 'packaging'
431
+ before { @packaging = :war }
432
+ it_should_behave_like 'package with manifest'
433
+ it_should_behave_like 'package with meta_inf'
434
+ before { @meta_inf_ignore = 'MANIFEST.MF' }
435
+
436
+ def make_jars
437
+ artifact('group:id:jar:1.0') { |t| write t.to_s }
438
+ artifact('group:id:jar:2.0') { |t| write t.to_s }
439
+ end
440
+
441
+ def inspect_war
442
+ project('foo').package(:war).invoke
443
+ Zip::ZipFile.open(project('foo').package(:war).to_s) do |war|
444
+ yield war.entries.map(&:to_s).sort
445
+ end
446
+ end
447
+
448
+ it 'should use files from webapp directory if nothing included' do
449
+ write 'src/main/webapp/test.html'
450
+ define('foo', :version=>'1.0') { package(:war) }
451
+ inspect_war { |files| files.should include('test.html') }
452
+ end
453
+
454
+ it 'should accept files from :classes option' do
455
+ write 'src/main/java/Test.java', 'class Test {}'
456
+ write 'classes/test'
457
+ define('foo', :version=>'1.0') { package(:war).with(:classes=>'classes') }
458
+ inspect_war { |files| files.should include('WEB-INF/classes/test') }
459
+ end
460
+
461
+ it 'should use files from compile directory if nothing included' do
462
+ write 'src/main/java/Test.java', 'class Test {}'
463
+ define('foo', :version=>'1.0') { package(:war) }
464
+ inspect_war { |files| files.should include('WEB-INF/classes/Test.class') }
465
+ end
466
+
467
+ it 'should ignore compile directory if no source files to compile' do
468
+ define('foo', :version=>'1.0') { package(:war) }
469
+ inspect_war { |files| files.should_not include('target/classes') }
470
+ end
471
+
472
+ it 'should include only specified classes directories' do
473
+ write 'src/main/java'
474
+ define('foo', :version=>'1.0') { package(:war).with :classes=>_('additional') }
475
+ project('foo').package(:war).classes.should_not include(project('foo').file('target/classes'))
476
+ project('foo').package(:war).classes.should include(project('foo').file('additional'))
477
+ end
478
+
479
+ it 'should use files from resources directory if nothing included' do
480
+ write 'src/main/resources/test/important.properties'
481
+ define('foo', :version=>'1.0') { package(:war) }
482
+ inspect_war { |files| files.should include('WEB-INF/classes/test/important.properties') }
483
+ end
484
+
485
+ it 'should include empty resource directories' do
486
+ mkpath 'src/main/resources/empty'
487
+ define('foo', :version=>'1.0') { package(:war) }
488
+ inspect_war { |files| files.should include('WEB-INF/classes/empty/') }
489
+ end
490
+
491
+ it 'should accept file from :libs option' do
492
+ make_jars
493
+ define('foo', :version=>'1.0') { package(:war).with(:libs=>'group:id:jar:1.0') }
494
+ inspect_war { |files| files.should include('META-INF/MANIFEST.MF', 'WEB-INF/lib/id-1.0.jar') }
495
+ end
496
+
497
+ it 'should accept file from :libs option' do
498
+ make_jars
499
+ define('foo', :version=>'1.0') { package(:war).with(:libs=>['group:id:jar:1.0', 'group:id:jar:2.0']) }
500
+ inspect_war { |files| files.should include('META-INF/MANIFEST.MF', 'WEB-INF/lib/id-1.0.jar', 'WEB-INF/lib/id-2.0.jar') }
501
+ end
502
+
503
+ it 'should use artifacts from compile classpath if no libs specified' do
504
+ make_jars
505
+ define('foo', :version=>'1.0') { compile.with 'group:id:jar:1.0', 'group:id:jar:2.0' ; package(:war) }
506
+ inspect_war { |files| files.should include('META-INF/MANIFEST.MF', 'WEB-INF/lib/id-1.0.jar', 'WEB-INF/lib/id-2.0.jar') }
507
+ end
508
+
509
+ it 'should include only specified libraries' do
510
+ define 'foo', :version=>'1.0' do
511
+ compile.with 'group:id:jar:1.0'
512
+ package(:war).with :libs=>'additional:id:jar:1.0'
513
+ end
514
+ project('foo').package(:war).libs.should_not include(artifact('group:id:jar:1.0'))
515
+ project('foo').package(:war).libs.should include(artifact('additional:id:jar:1.0'))
516
+ end
517
+
518
+ end
519
+
520
+
521
+ describe Packaging, 'aar' do
522
+ it_should_behave_like 'packaging'
523
+ before { @packaging = :aar }
524
+ it_should_behave_like 'package with manifest'
525
+ it_should_behave_like 'package with meta_inf'
526
+ before do
527
+ write 'src/main/axis2/services.xml'
528
+ @meta_inf_ignore = ['MANIFEST.MF', 'services.xml']
529
+ end
530
+
531
+ def make_jars
532
+ artifact('group:id:jar:1.0') { |t| write t.to_s }
533
+ artifact('group:id:jar:2.0') { |t| write t.to_s }
534
+ end
535
+
536
+ def inspect_aar
537
+ project('foo').package(:aar).invoke
538
+ Zip::ZipFile.open(project('foo').package(:aar).to_s) do |aar|
539
+ yield aar.entries.map(&:to_s).sort
540
+ end
541
+ end
542
+
543
+ it 'should automatically include services.xml and any *.wsdl files under src/main/axis2' do
544
+ write 'src/main/axis2/my-service.wsdl'
545
+ define('foo', :version=>'1.0') { package(:aar) }
546
+ inspect_aar { |files| files.should include('META-INF/MANIFEST.MF', 'META-INF/services.xml', 'META-INF/my-service.wsdl') }
547
+ end
548
+
549
+ it 'should accept files from :include option' do
550
+ write 'test'
551
+ define('foo', :version=>'1.0') { package(:aar).include 'test' }
552
+ inspect_aar { |files| files.should include('META-INF/MANIFEST.MF', 'test') }
553
+ end
554
+
555
+ it 'should use files from compile directory if nothing included' do
556
+ write 'src/main/java/Test.java', 'class Test {}'
557
+ define('foo', :version=>'1.0') { package(:aar) }
558
+ inspect_aar { |files| files.should include('Test.class') }
559
+ end
560
+
561
+ it 'should use files from resources directory if nothing included' do
562
+ write 'src/main/resources/test/important.properties'
563
+ define('foo', :version=>'1.0') { package(:aar) }
564
+ inspect_aar { |files| files.should include('test/important.properties') }
565
+ end
566
+
567
+ it 'should include empty resource directories' do
568
+ mkpath 'src/main/resources/empty'
569
+ define('foo', :version=>'1.0') { package(:aar) }
570
+ inspect_aar { |files| files.should include('empty/') }
571
+ end
572
+
573
+ it 'should accept file from :libs option' do
574
+ make_jars
575
+ define('foo', :version=>'1.0') { package(:aar).with :libs=>'group:id:jar:1.0' }
576
+ inspect_aar { |files| files.should include('META-INF/MANIFEST.MF', 'lib/id-1.0.jar') }
577
+ end
578
+
579
+ it 'should accept file from :libs option' do
580
+ make_jars
581
+ define('foo', :version=>'1.0') { package(:aar).with :libs=>['group:id:jar:1.0', 'group:id:jar:2.0'] }
582
+ inspect_aar { |files| files.should include('META-INF/MANIFEST.MF', 'lib/id-1.0.jar', 'lib/id-2.0.jar') }
583
+ end
584
+
585
+ it 'should NOT use artifacts from compile classpath if no libs specified' do
586
+ make_jars
587
+ define('foo', :version=>'1.0') { compile.with 'group:id:jar:1.0', 'group:id:jar:2.0' ; package(:aar) }
588
+ inspect_aar { |files| files.should include('META-INF/MANIFEST.MF') }
589
+ end
590
+
591
+ it 'should return all libraries from libs attribute' do
592
+ define 'foo', :version=>'1.0' do
593
+ compile.with 'group:id:jar:1.0'
594
+ package(:aar).with :libs=>'additional:id:jar:1.0'
595
+ end
596
+ project('foo').package(:aar).libs.should_not include(artifact('group:id:jar:1.0'))
597
+ project('foo').package(:aar).libs.should include(artifact('additional:id:jar:1.0'))
598
+ end
599
+
600
+ end
601
+
602
+
603
+ describe Packaging, 'ear' do
604
+ it_should_behave_like 'packaging'
605
+ before { @packaging = :ear }
606
+ it_should_behave_like 'package with manifest'
607
+ it_should_behave_like 'package with meta_inf'
608
+ before { @meta_inf_ignore = ['MANIFEST.MF', 'application.xml'] }
609
+
610
+ def inspect_ear
611
+ project('foo').package(:ear).invoke
612
+ Zip::ZipFile.open(project('foo').package(:ear).to_s) do |ear|
613
+ yield ear.entries.map(&:to_s).sort
614
+ end
615
+ end
616
+
617
+ def inspect_application_xml
618
+ project('foo').package(:ear).invoke
619
+ Zip::ZipFile.open(project('foo').package(:ear).to_s) do |ear|
620
+ yield REXML::Document.new(ear.read('META-INF/application.xml')).root
621
+ end
622
+ end
623
+
624
+ def inspect_classpath(package)
625
+ project('foo').package(:ear).invoke
626
+ Zip::ZipFile.open(project('foo').package(:ear).to_s) do |ear|
627
+ File.open('tmp.zip', 'wb') do |tmp|
628
+ tmp.write ear.file.read(package)
629
+ end
630
+ manifest = Buildr::Packaging::Java::Manifest.from_zip('tmp.zip')
631
+ yield manifest.main['Class-Path'].to_s.split(' ')
632
+ end
633
+ end
634
+
635
+ it 'should set display name from project id' do
636
+ define 'foo', :version=>'1.0' do
637
+ package(:ear).display_name.should eql('foo')
638
+ define 'bar' do
639
+ package(:ear).display_name.should eql('foo-bar')
640
+ end
641
+ end
642
+ end
643
+
644
+ it 'should set display name in application.xml' do
645
+ define 'foo', :version=>'1.0' do
646
+ package(:ear)
647
+ end
648
+ inspect_application_xml { |xml| xml.get_text('/application/display-name').should == 'foo' }
649
+ end
650
+
651
+ it 'should accept different display name' do
652
+ define 'foo', :version=>'1.0' do
653
+ package(:ear).display_name = 'bar'
654
+ end
655
+ inspect_application_xml { |xml| xml.get_text('/application/display-name').should == 'bar' }
656
+ end
657
+
658
+ it 'should map WARs to /war directory' do
659
+ define 'foo', :version=>'1.0' do
660
+ package(:ear) << package(:war)
661
+ end
662
+ inspect_ear { |files| files.should include('war/foo-1.0.war') }
663
+ end
664
+
665
+ it 'should map EJBs to /ejb directory' do
666
+ define 'foo', :version=>'1.0' do
667
+ package(:ear).add :ejb=>package(:jar)
668
+ end
669
+ inspect_ear { |files| files.should include('ejb/foo-1.0.jar') }
670
+ end
671
+
672
+ it 'should not modify original artifact for its components' do
673
+ define 'one', :version => '1.0' do
674
+ write 'src/main/resources/one.txt', '1'
675
+ package(:jar)
676
+ end
677
+
678
+ define 'two', :version => '1.0' do
679
+ write 'src/main/resources/two.txt', '2'
680
+ package(:jar)
681
+ end
682
+
683
+ define 'foo', :version => '1.0' do
684
+ package(:ear).add project(:one).package(:jar)
685
+ package(:ear).add :ejb => project(:two).package(:jar)
686
+ end
687
+
688
+ inspect_ear { |files| files.should include('lib/one-1.0.jar', 'ejb/two-1.0.jar') }
689
+
690
+ Buildr::Packaging::Java::Manifest.from_zip(project('one').package(:jar)).main['Class-Path'].should be_nil
691
+ Buildr::Packaging::Java::Manifest.from_zip(project('two').package(:jar)).main['Class-Path'].should be_nil
692
+
693
+ inspect_classpath 'ejb/two-1.0.jar' do |classpath|
694
+ classpath.should include('../lib/one-1.0.jar')
695
+ end
696
+ end
697
+
698
+ it 'should map JARs to /lib directory' do
699
+ define 'foo', :version=>'1.0' do
700
+ package(:ear) << package(:jar)
701
+ end
702
+ inspect_ear { |files| files.should include('lib/foo-1.0.jar') }
703
+ end
704
+
705
+ it 'should accept component type with :type option' do
706
+ define 'foo', :version=>'1.0' do
707
+ package(:ear).add package(:jar), :type=>:ejb
708
+ end
709
+ inspect_ear { |files| files.should include('ejb/foo-1.0.jar') }
710
+ end
711
+
712
+ it 'should accept component and its type as type=>artiract' do
713
+ define 'foo', :version=>'1.0' do
714
+ package(:ear).add :ejb=>package(:jar)
715
+ end
716
+ inspect_ear { |files| files.should include('ejb/foo-1.0.jar') }
717
+ end
718
+
719
+ it 'should map typed JARs to /jar directory' do
720
+ define 'foo', :version=>'1.0' do
721
+ package(:ear).add :jar=>package(:jar)
722
+ end
723
+ inspect_ear { |files| files.should include('jar/foo-1.0.jar') }
724
+ end
725
+
726
+ it 'should add multiple components at a time using the type=>component style' do
727
+ define 'bar', :version => '1.5' do
728
+ package(:war) # must be added as a webapp
729
+ package(:jar) # must be added as a shared lib
730
+ package(:zip) # this one should be excluded
731
+ end
732
+ define 'baz', :version => '1.5' do
733
+ package(:jar, :id => 'one')
734
+ package(:jar, :id => 'two')
735
+ end
736
+ define 'foo', :version => '1.0' do
737
+ package(:ear).add :lib => project('baz'),
738
+ :war => project('bar').package(:war),
739
+ :ejb => project('bar').package(:jar)
740
+ end
741
+ inspect_ear do |files|
742
+ files.should include(*%w{ lib/one-1.5.jar lib/two-1.5.jar war/bar-1.5.war ejb/bar-1.5.jar })
743
+ files.should_not satisfy { files.any? { |f| f =~ /\.zip$/ } }
744
+ end
745
+ end
746
+
747
+ it 'should add all EAR supported packages when given a project argument' do
748
+ define 'bar', :version => '1.5' do
749
+ package(:war) # must be added as a webapp
750
+ package(:jar) # must be added as a shared lib
751
+ package(:zip) # this one should be excluded
752
+ end
753
+ define 'baz', :version => '1.5' do
754
+ package(:war)
755
+ package(:jar)
756
+ end
757
+ define 'foo', :version => '1.0' do
758
+ package(:ear).add projects(:bar, :baz)
759
+ end
760
+ inspect_ear do |files|
761
+ files.should include('war/bar-1.5.war', 'lib/bar-1.5.jar', 'lib/baz-1.5.jar', 'war/baz-1.5.war')
762
+ files.should_not satisfy { files.any? { |f| f =~ /\.zip$/ } }
763
+ end
764
+ end
765
+
766
+ it 'should complain about unknown component type' do
767
+ define 'foo', :version=>'1.0' do
768
+ lambda { package(:ear).add package(:zip) }.should raise_error(RuntimeError, /ear component/i)
769
+ end
770
+ end
771
+
772
+ it 'should allow unknown component types with explicit type' do
773
+ define 'foo', :version=>'1.0' do
774
+ package(:ear).add :lib=>package(:zip)
775
+ end
776
+ inspect_ear { |files| files.should include('lib/foo-1.0.zip') }
777
+ end
778
+
779
+ it 'should accept alternative directory name' do
780
+ define 'foo', :version=>'1.0' do
781
+ package(:ear).add package(:jar), :path=>'trash'
782
+ end
783
+ inspect_ear { |files| files.should include('trash/foo-1.0.jar') }
784
+ end
785
+
786
+ it 'should accept customization of directory map' do
787
+ define 'foo', :version=>'1.0' do
788
+ package(:ear).dirs[:jar] = 'jarred'
789
+ package(:ear).add :jar=>package(:jar)
790
+ end
791
+ inspect_ear { |files| files.should include('jarred/foo-1.0.jar') }
792
+ end
793
+
794
+ it 'should accept customization of directory map with nil paths in application.xml' do
795
+ define 'foo', :version=>'1.0' do
796
+ package(:ear).dirs[:war] = nil
797
+ package(:ear).add :war=>package(:war)
798
+ package(:ear).add package(:jar)
799
+ end
800
+ inspect_ear { |files| files.should include('foo-1.0.war') }
801
+ inspect_application_xml do |xml|
802
+ xml.get_text("/application/module[@id='foo']/web/web-uri").to_s.should eql('foo-1.0.war')
803
+ end
804
+ end
805
+
806
+ it 'should accept customization of directory map with nil paths in the classpath' do
807
+ define 'foo', :version=>'1.0' do
808
+ package(:ear).dirs[:lib] = nil
809
+ package(:ear).add :war=>package(:war)
810
+ package(:ear) << package(:jar)
811
+ end
812
+ inspect_classpath 'war/foo-1.0.war' do |classpath|
813
+ classpath.should include('../foo-1.0.jar')
814
+ end
815
+ end
816
+
817
+ it 'should list WAR components in application.xml' do
818
+ define 'foo', :version=>'1.0' do
819
+ package(:ear) << package(:war) << package(:war, :id=>'bar')
820
+ end
821
+ inspect_application_xml do |xml|
822
+ xml.get_elements("/application/module[@id='foo'][web]").should_not be_empty
823
+ xml.get_elements("/application/module[@id='bar'][web]").should_not be_empty
824
+ end
825
+ end
826
+
827
+ it 'should specify web-uri for WAR components in application.xml' do
828
+ define 'foo', :version=>'1.0' do
829
+ package(:ear) << package(:war)
830
+ package(:ear).add package(:war, :id=>'bar'), :path=>'ws'
831
+ end
832
+ inspect_application_xml do |xml|
833
+ xml.get_text("/application/module[@id='foo']/web/web-uri").to_s.should eql('war/foo-1.0.war')
834
+ xml.get_text("/application/module[@id='bar']/web/web-uri").to_s.should eql('ws/bar-1.0.war')
835
+ end
836
+ end
837
+
838
+ it 'should specify context-root for WAR components in application.xml' do
839
+ define 'foo', :version=>'1.0' do
840
+ package(:ear) << package(:war)
841
+ package(:ear).add package(:war, :id=>'bar')
842
+ end
843
+ inspect_application_xml do |xml|
844
+ xml.get_text("/application/module[@id='foo']/web/context-root").to_s.should eql('/foo')
845
+ xml.get_text("/application/module[@id='bar']/web/context-root").to_s.should eql('/bar')
846
+ end
847
+ end
848
+
849
+ it 'should accept context-root for WAR components in application.xml' do
850
+ define 'foo', :version=>'1.0' do
851
+ package(:ear).add package(:war), :context_root=>'rooted'
852
+ end
853
+ inspect_application_xml do |xml|
854
+ xml.get_text("/application/module[@id='foo']/web/context-root").to_s.should eql('/rooted')
855
+ end
856
+ end
857
+
858
+ it 'should allow disabling the context root' do
859
+ define 'foo', :version=>'1.0' do
860
+ package(:ear).add package(:war), :context_root=>false
861
+ end
862
+ inspect_application_xml do |xml|
863
+ xml.get_elements("/application/module[@id='foo']/web/context-root").should be_empty
864
+ end
865
+ end
866
+
867
+ it 'should list EJB components in application.xml' do
868
+ define 'foo', :version=>'1.0' do
869
+ package(:ear).add :ejb=>package(:jar)
870
+ package(:ear).add :ejb=>package(:jar, :id=>'bar')
871
+ end
872
+ inspect_application_xml do |xml|
873
+ xml.get_text("/application/module[@id='foo']/ejb").to_s.should eql('ejb/foo-1.0.jar')
874
+ xml.get_text("/application/module[@id='bar']/ejb").to_s.should eql('ejb/bar-1.0.jar')
875
+ end
876
+ end
877
+
878
+ it 'should list JAR components in application.xml' do
879
+ define 'foo', :version=>'1.0' do
880
+ package(:ear) << { :jar=>package(:jar) } << { :jar=>package(:jar, :id=>'bar') }
881
+ end
882
+ inspect_application_xml do |xml|
883
+ jars = xml.get_elements('/application/jar').map(&:texts).map(&:to_s)
884
+ jars.should include('jar/foo-1.0.jar', 'jar/bar-1.0.jar')
885
+ end
886
+ end
887
+
888
+ it 'should update WAR component classpath to include libraries' do
889
+ define 'foo', :version=>'1.0' do
890
+ package(:ear) << package(:jar, :id=>'lib1') << package(:jar, :id=>'lib2')
891
+ package(:ear).add package(:war)
892
+ end
893
+ inspect_classpath 'war/foo-1.0.war' do |classpath|
894
+ classpath.should include('../lib/lib1-1.0.jar', '../lib/lib2-1.0.jar')
895
+ end
896
+ end
897
+
898
+ it 'should update WAR component classpath but skip internal libraries' do
899
+ define 'foo', :version=>'1.0' do
900
+ package(:ear) << package(:jar, :id=>'lib1') << package(:jar, :id=>'lib2')
901
+ package(:war).with(:libs=>package(:jar, :id=>'lib1'))
902
+ package(:ear).add package(:war)
903
+ end
904
+ inspect_classpath 'war/foo-1.0.war' do |classpath|
905
+ classpath.should_not include('../lib/lib1-1.0.jar')
906
+ classpath.should include('../lib/lib2-1.0.jar')
907
+ end
908
+ end
909
+
910
+ it 'should update EJB component classpath to include libraries' do
911
+ define 'foo', :version=>'1.0' do
912
+ package(:ear) << package(:jar, :id=>'lib1') << package(:jar, :id=>'lib2')
913
+ package(:ear).add :ejb=>package(:jar)
914
+ end
915
+ inspect_classpath 'ejb/foo-1.0.jar' do |classpath|
916
+ classpath.should include('../lib/lib1-1.0.jar', '../lib/lib2-1.0.jar')
917
+ end
918
+ end
919
+
920
+ it 'should update JAR component classpath to include libraries' do
921
+ define 'foo', :version=>'1.0' do
922
+ package(:ear) << package(:jar, :id=>'lib1') << package(:jar, :id=>'lib2')
923
+ package(:ear).add :jar=>package(:jar)
924
+ end
925
+ inspect_classpath 'jar/foo-1.0.jar' do |classpath|
926
+ classpath.should include('../lib/lib1-1.0.jar', '../lib/lib2-1.0.jar')
927
+ end
928
+ end
929
+
930
+ it 'should deal with very long classpaths' do
931
+ define 'foo', :version=>'1.0' do
932
+ 20.times { |i| package(:ear) << package(:jar, :id=>"lib#{i}") }
933
+ package(:ear).add :jar=>package(:jar)
934
+ end
935
+ inspect_classpath 'jar/foo-1.0.jar' do |classpath|
936
+ classpath.should include('../lib/lib1-1.0.jar', '../lib/lib2-1.0.jar')
937
+ end
938
+ end
939
+
940
+
941
+ it 'should generate relative classpaths for top level EJB' do
942
+ define 'foo', :version => '1.0' do
943
+ package(:ear).add package(:jar, :id => 'one'), :path => '.'
944
+ package(:ear).add package(:jar, :id => 'two'), :path => 'dos'
945
+ package(:ear).add package(:jar, :id => 'three'), :path => 'tres'
946
+ package(:ear).add :ejb => package(:jar, :id => 'ejb1'), :path => '.'
947
+ end
948
+ inspect_classpath 'ejb1-1.0.jar' do |classpath|
949
+ classpath.should include(*%w{ one-1.0.jar dos/two-1.0.jar tres/three-1.0.jar })
950
+ end
951
+ end
952
+
953
+ it 'should generate relative classpaths for second level EJB' do
954
+ define 'foo', :version => '1.0' do
955
+ package(:ear).add package(:jar, :id => 'one'), :path => '.'
956
+ package(:ear).add package(:jar, :id => 'two'), :path => 'dos'
957
+ package(:ear).add package(:jar, :id => 'three'), :path => 'tres'
958
+ package(:ear).add :ejb => package(:jar, :id => 'ejb2'), :path => 'dos'
959
+ end
960
+ inspect_classpath 'dos/ejb2-1.0.jar' do |classpath|
961
+ classpath.should include(*%w{ ../one-1.0.jar two-1.0.jar ../tres/three-1.0.jar })
962
+ end
963
+ end
964
+
965
+ it 'should generate relative classpaths for nested EJB' do
966
+ define 'foo', :version => '1.0' do
967
+ package(:ear).add package(:jar, :id => 'one'), :path => '.'
968
+ package(:ear).add package(:jar, :id => 'two'), :path => 'dos'
969
+ package(:ear).add package(:jar, :id => 'three'), :path => 'dos/tres'
970
+ package(:ear).add package(:jar, :id => 'four'), :path => 'dos/cuatro'
971
+ package(:ear).add :ejb => package(:jar, :id => 'ejb4'), :path => 'dos/cuatro'
972
+ end
973
+ inspect_classpath 'dos/cuatro/ejb4-1.0.jar' do |classpath|
974
+ classpath.should include(*%w{ ../../one-1.0.jar ../two-1.0.jar ../tres/three-1.0.jar four-1.0.jar })
975
+ end
976
+ end
977
+
978
+ end
979
+
980
+
981
+ describe Packaging, 'sources' do
982
+ it_should_behave_like 'packaging'
983
+ before { @packaging, @package_type = :sources, :zip }
984
+
985
+ it 'should create package of type :zip and classifier \'sources\'' do
986
+ define 'foo', :version=>'1.0' do
987
+ package(:sources).type.should eql(:zip)
988
+ package(:sources).classifier.should eql('sources')
989
+ package(:sources).name.should match(/foo-1.0-sources.zip$/)
990
+ end
991
+ end
992
+
993
+ it 'should contain source files' do
994
+ write 'src/main/java/Source.java'
995
+ define('foo', :version=>'1.0') { package(:sources) }
996
+ project('foo').task('package').invoke
997
+ project('foo').packages.first.should contain('Source.java')
998
+ end
999
+
1000
+ it 'should be a ZipTask' do
1001
+ define 'foo', :version=>'1.0' do
1002
+ package(:javadoc).should be_kind_of(ZipTask)
1003
+ end
1004
+ end
1005
+ end
1006
+
1007
+
1008
+ describe Packaging, 'javadoc' do
1009
+ it_should_behave_like 'packaging'
1010
+ before { @packaging, @package_type = :javadoc, :zip }
1011
+
1012
+ it 'should create package of type :zip and classifier \'javadoc\'' do
1013
+ define 'foo', :version=>'1.0' do
1014
+ package(:javadoc).type.should eql(:zip)
1015
+ package(:javadoc).classifier.should eql('javadoc')
1016
+ package(:javadoc).name.pathmap('%f').should eql('foo-1.0-javadoc.zip')
1017
+ end
1018
+ end
1019
+
1020
+ it 'should contain Javadocs' do
1021
+ write 'src/main/java/Source.java', 'public class Source {}'
1022
+ define('foo', :version=>'1.0') { package(:javadoc) }
1023
+ project('foo').task('package').invoke
1024
+ project('foo').packages.first.should contain('Source.html', 'index.html')
1025
+ end
1026
+
1027
+ it 'should use project description in window title' do
1028
+ write 'src/main/java/Source.java', 'public class Source {}'
1029
+ desc 'My Project'
1030
+ define('foo', :version=>'1.0') { package(:javadoc) }
1031
+ project('foo').task('package').invoke
1032
+ project('foo').packages.first.entry('index.html').should contain('My Project')
1033
+ end
1034
+
1035
+ it 'should be a ZipTask' do
1036
+ define 'foo', :version=>'1.0' do
1037
+ package(:javadoc).should be_kind_of(ZipTask)
1038
+ end
1039
+ end
1040
+ end
1041
+
1042
+
1043
+ shared_examples_for 'package_with_' do
1044
+
1045
+ def prepare(options = {})
1046
+ packager = "package_with_#{@packaging}"
1047
+ write 'src/main/java/Source.java'
1048
+ write 'baz/src/main/java/Source.java'
1049
+ define 'foo', :version=>'1.0' do
1050
+ send packager, options
1051
+ define 'bar' ; define 'baz'
1052
+ end
1053
+ end
1054
+
1055
+ def applied_to
1056
+ projects.select { |project| project.packages.first }.map(&:name)
1057
+ end
1058
+
1059
+ it 'should create package of type zip with classifier' do
1060
+ prepare
1061
+ project('foo').packages.first.to_s.should =~ /foo-1.0-#{@packaging}.zip/
1062
+ end
1063
+
1064
+ it 'should create package for projects that have source files' do
1065
+ prepare
1066
+ applied_to.should include('foo', 'foo:baz')
1067
+ end
1068
+
1069
+ it 'should not create package for projects that have no source files' do
1070
+ prepare
1071
+ applied_to.should_not include('foo:bar')
1072
+ end
1073
+
1074
+ it 'should limit to projects specified by :only' do
1075
+ prepare :only=>'baz'
1076
+ applied_to.should eql(['foo:baz'])
1077
+ end
1078
+
1079
+ it 'should limit to projects specified by :only array' do
1080
+ prepare :only=>['baz']
1081
+ applied_to.should eql(['foo:baz'])
1082
+ end
1083
+
1084
+ it 'should ignore project specified by :except' do
1085
+ prepare :except=>'baz'
1086
+ applied_to.should eql(['foo'])
1087
+ end
1088
+
1089
+ it 'should ignore projects specified by :except array' do
1090
+ prepare :except=>['baz']
1091
+ applied_to.should eql(['foo'])
1092
+ end
1093
+ end
1094
+
1095
+ describe 'package_with_sources' do
1096
+ it_should_behave_like 'package_with_'
1097
+ before { @packaging = :sources }
1098
+ end
1099
+
1100
+ describe 'package_with_javadoc' do
1101
+ it_should_behave_like 'package_with_'
1102
+ before { @packaging = :javadoc }
1103
+ end