realityforge-buildr 1.5.9

Sign up to get free protection for your applications and to get access to all the features.
Files changed (85) hide show
  1. checksums.yaml +7 -0
  2. data/CHANGELOG.md +5 -0
  3. data/LICENSE +176 -0
  4. data/NOTICE +26 -0
  5. data/README.md +3 -0
  6. data/Rakefile +50 -0
  7. data/addon/buildr/checkstyle-report.xsl +104 -0
  8. data/addon/buildr/checkstyle.rb +254 -0
  9. data/addon/buildr/git_auto_version.rb +36 -0
  10. data/addon/buildr/gpg.rb +90 -0
  11. data/addon/buildr/gwt.rb +413 -0
  12. data/addon/buildr/jacoco.rb +161 -0
  13. data/addon/buildr/pmd.rb +185 -0
  14. data/addon/buildr/single_intermediate_layout.rb +71 -0
  15. data/addon/buildr/spotbugs.rb +265 -0
  16. data/addon/buildr/top_level_generate_dir.rb +37 -0
  17. data/addon/buildr/wsgen.rb +192 -0
  18. data/bin/buildr +20 -0
  19. data/buildr.gemspec +61 -0
  20. data/lib/buildr.rb +86 -0
  21. data/lib/buildr/core/application.rb +705 -0
  22. data/lib/buildr/core/assets.rb +96 -0
  23. data/lib/buildr/core/build.rb +587 -0
  24. data/lib/buildr/core/common.rb +167 -0
  25. data/lib/buildr/core/compile.rb +599 -0
  26. data/lib/buildr/core/console.rb +124 -0
  27. data/lib/buildr/core/doc.rb +275 -0
  28. data/lib/buildr/core/environment.rb +128 -0
  29. data/lib/buildr/core/filter.rb +405 -0
  30. data/lib/buildr/core/help.rb +114 -0
  31. data/lib/buildr/core/progressbar.rb +161 -0
  32. data/lib/buildr/core/project.rb +994 -0
  33. data/lib/buildr/core/test.rb +776 -0
  34. data/lib/buildr/core/transports.rb +456 -0
  35. data/lib/buildr/core/util.rb +77 -0
  36. data/lib/buildr/ide/idea.rb +1664 -0
  37. data/lib/buildr/java/commands.rb +230 -0
  38. data/lib/buildr/java/compiler.rb +85 -0
  39. data/lib/buildr/java/custom_pom.rb +300 -0
  40. data/lib/buildr/java/doc.rb +62 -0
  41. data/lib/buildr/java/packaging.rb +393 -0
  42. data/lib/buildr/java/pom.rb +191 -0
  43. data/lib/buildr/java/test_result.rb +54 -0
  44. data/lib/buildr/java/tests.rb +111 -0
  45. data/lib/buildr/packaging/archive.rb +586 -0
  46. data/lib/buildr/packaging/artifact.rb +1113 -0
  47. data/lib/buildr/packaging/artifact_namespace.rb +1010 -0
  48. data/lib/buildr/packaging/artifact_search.rb +138 -0
  49. data/lib/buildr/packaging/package.rb +237 -0
  50. data/lib/buildr/packaging/version_requirement.rb +189 -0
  51. data/lib/buildr/packaging/zip.rb +189 -0
  52. data/lib/buildr/packaging/ziptask.rb +387 -0
  53. data/lib/buildr/version.rb +18 -0
  54. data/rakelib/release.rake +99 -0
  55. data/spec/addon/checkstyle_spec.rb +58 -0
  56. data/spec/core/application_spec.rb +576 -0
  57. data/spec/core/build_spec.rb +922 -0
  58. data/spec/core/common_spec.rb +670 -0
  59. data/spec/core/compile_spec.rb +656 -0
  60. data/spec/core/console_spec.rb +65 -0
  61. data/spec/core/doc_spec.rb +194 -0
  62. data/spec/core/extension_spec.rb +200 -0
  63. data/spec/core/project_spec.rb +736 -0
  64. data/spec/core/test_spec.rb +1131 -0
  65. data/spec/core/transport_spec.rb +452 -0
  66. data/spec/core/util_spec.rb +154 -0
  67. data/spec/ide/idea_spec.rb +1952 -0
  68. data/spec/java/commands_spec.rb +79 -0
  69. data/spec/java/compiler_spec.rb +274 -0
  70. data/spec/java/custom_pom_spec.rb +165 -0
  71. data/spec/java/doc_spec.rb +55 -0
  72. data/spec/java/packaging_spec.rb +786 -0
  73. data/spec/java/pom_spec.rb +162 -0
  74. data/spec/java/test_coverage_helper.rb +257 -0
  75. data/spec/java/tests_spec.rb +224 -0
  76. data/spec/packaging/archive_spec.rb +686 -0
  77. data/spec/packaging/artifact_namespace_spec.rb +757 -0
  78. data/spec/packaging/artifact_spec.rb +1351 -0
  79. data/spec/packaging/packaging_helper.rb +63 -0
  80. data/spec/packaging/packaging_spec.rb +690 -0
  81. data/spec/sandbox.rb +166 -0
  82. data/spec/spec_helpers.rb +420 -0
  83. data/spec/version_requirement_spec.rb +145 -0
  84. data/spec/xpath_matchers.rb +123 -0
  85. metadata +295 -0
@@ -0,0 +1,1952 @@
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.expand_path(File.join(File.dirname(__FILE__), '..', 'spec_helpers'))
18
+ require File.expand_path(File.join(File.dirname(__FILE__), '..', 'xpath_matchers'))
19
+
20
+ def ensure_facet_xpath(doc, type, name)
21
+ facet_xpath = "/module/component[@name='FacetManager']/facet"
22
+ doc.should have_xpath(facet_xpath)
23
+ web_facet_xpath = "#{facet_xpath}[@type='#{type}' && @name='#{name}']"
24
+ doc.should have_xpath(web_facet_xpath)
25
+ web_facet_xpath
26
+ end
27
+
28
+ describe Buildr::IntellijIdea do
29
+
30
+ def invoke_generate_task
31
+ task('idea').invoke
32
+ end
33
+
34
+ def invoke_clean_task
35
+ task('idea:clean').invoke
36
+ end
37
+
38
+ def root_project_filename(project)
39
+ project._("#{project.name}#{Buildr::IntellijIdea::IdeaFile::DEFAULT_SUFFIX}.ipr")
40
+ end
41
+
42
+ def root_project_xml(project)
43
+ xml_document(root_project_filename(project))
44
+ end
45
+
46
+ def root_module_filename(project)
47
+ project._("#{project.name}#{Buildr::IntellijIdea::IdeaFile::DEFAULT_SUFFIX}.iml")
48
+ end
49
+
50
+ def root_module_xml(project)
51
+ xml_document(root_module_filename(project))
52
+ end
53
+
54
+ def subproject_module_filename(project, sub_project_name)
55
+ project._("#{sub_project_name}/#{sub_project_name}#{Buildr::IntellijIdea::IdeaFile::DEFAULT_SUFFIX}.iml")
56
+ end
57
+
58
+ def subproject_module_xml(project, sub_project_name)
59
+ xml_document(subproject_module_filename(project, sub_project_name))
60
+ end
61
+
62
+ def xml_document(filename)
63
+ File.should be_exist(filename)
64
+ REXML::Document.new(File.read(filename))
65
+ end
66
+
67
+ def xpath_to_module
68
+ "/project/component[@name='ProjectModuleManager']/modules/module"
69
+ end
70
+
71
+ describe "idea:clean" do
72
+ before do
73
+ write "foo.ipr"
74
+ write "foo.iml"
75
+ write "other.ipr"
76
+ write "other.iml"
77
+ mkdir_p 'bar'
78
+ write "bar/bar.iml"
79
+ write "bar/other.ipr"
80
+ write "bar/other.iml"
81
+
82
+ @foo = define "foo" do
83
+ define "bar"
84
+ end
85
+ invoke_clean_task
86
+ end
87
+
88
+ it "should remove the ipr file" do
89
+ File.exists?("foo.ipr").should be_false
90
+ end
91
+
92
+ it "should remove the project iml file" do
93
+ File.exists?("foo.iml").should be_false
94
+ end
95
+
96
+ it "should remove the subproject iml file" do
97
+ File.exists?("foo.iml").should be_false
98
+ end
99
+
100
+ it "should not remove other iml and ipr files" do
101
+ File.exists?("other.ipr").should be_true
102
+ File.exists?("other.iml").should be_true
103
+ File.exists?("bar/other.ipr").should be_true
104
+ File.exists?("bar/other.iml").should be_true
105
+ end
106
+ end
107
+
108
+ describe "idea task" do
109
+
110
+ def order_entry_xpath
111
+ "/module/component[@name='NewModuleRootManager']/orderEntry"
112
+ end
113
+
114
+ describe "with a single dependency" do
115
+ describe "of type compile" do
116
+ before do
117
+ artifact('group:id:jar:1.0') { |t| write t.to_s }
118
+ @foo = define "foo" do
119
+ compile.with 'group:id:jar:1.0'
120
+ end
121
+ invoke_generate_task
122
+ end
123
+
124
+ it "generates one exported 'module-library' orderEntry in IML" do
125
+ root_module_xml(@foo).should have_nodes("#{order_entry_xpath}[@type='module-library' && @exported='']/library/CLASSES/root", 1)
126
+ end
127
+ end
128
+
129
+ describe "with iml.main_dependencies override" do
130
+ before do
131
+ artifact('group:id:jar:1.0') { |t| write t.to_s }
132
+ @foo = define "foo" do
133
+ iml.main_dependencies << 'group:id:jar:1.0'
134
+ end
135
+ invoke_generate_task
136
+ end
137
+
138
+ it "generates one exported 'module-library' orderEntry in IML" do
139
+ root_module_xml(@foo).should have_nodes("#{order_entry_xpath}[@type='module-library' && @scope='TEST']/library/CLASSES/root", 1)
140
+ end
141
+ end
142
+
143
+ describe "of type test" do
144
+ before do
145
+ artifact('group:id:jar:1.0') { |t| write t.to_s }
146
+ @foo = define "foo" do
147
+ test.with 'group:id:jar:1.0'
148
+ end
149
+ invoke_generate_task
150
+ end
151
+
152
+ it "generates one non-exported test scope 'module-library' orderEntry in IML" do
153
+ root_module_xml(@foo).should have_nodes("#{order_entry_xpath}[@type='module-library' && @scope='TEST']/library/CLASSES/root", 1)
154
+ end
155
+ end
156
+
157
+ describe "with iml.test_dependencies override" do
158
+ before do
159
+ artifact('group:id:jar:1.0') { |t| write t.to_s }
160
+ @foo = define "foo" do
161
+ iml.test_dependencies << 'group:id:jar:1.0'
162
+ end
163
+ invoke_generate_task
164
+ end
165
+
166
+ it "generates one non-exported 'module-library' orderEntry in IML" do
167
+ root_module_xml(@foo).should have_nodes("#{order_entry_xpath}[@type='module-library' && @scope='TEST']/library/CLASSES/root", 1)
168
+ end
169
+ end
170
+
171
+ describe "with sources artifact present" do
172
+ before do
173
+ artifact('group:id:jar:1.0') { |t| write t.to_s }
174
+ artifact('group:id:jar:sources:1.0') { |t| write t.to_s }
175
+ @foo = define "foo" do
176
+ compile.with 'group:id:jar:1.0'
177
+ end
178
+ invoke_generate_task
179
+ end
180
+
181
+ it "generates 'module-library' orderEntry in IML with SOURCES specified" do
182
+ root_module_xml(@foo).should have_nodes("#{order_entry_xpath}[@type='module-library' && @exported='']/library/SOURCES/root", 1)
183
+ end
184
+ end
185
+
186
+ describe "with local_repository_env_override set to nil" do
187
+ before do
188
+ Buildr.repositories.instance_eval do
189
+ @local = @remote = @release_to = nil
190
+ end
191
+ artifact('group:id:jar:1.0') { |t| write t.to_s }
192
+ @foo = define "foo" do
193
+ iml.local_repository_env_override = nil
194
+ compile.with 'group:id:jar:1.0'
195
+ end
196
+ invoke_generate_task
197
+ end
198
+
199
+ it "generates orderEntry with absolute path for classes jar" do
200
+ root_module_xml(@foo).should match_xpath("#{order_entry_xpath}/library/CLASSES/root/@url",
201
+ "jar://$MODULE_DIR$/home/.m2/repository/group/id/1.0/id-1.0.jar!/")
202
+ end
203
+ end
204
+ describe "with local_repository_env_override set to MAVEN_REPOSITORY" do
205
+ before do
206
+ artifact('group:id:jar:1.0') { |t| write t.to_s }
207
+ @foo = define "foo" do
208
+ iml.local_repository_env_override = 'MAVEN_REPOSITORY'
209
+ compile.with 'group:id:jar:1.0'
210
+ end
211
+ invoke_generate_task
212
+ end
213
+
214
+ it "generates orderEntry with absolute path for classes jar" do
215
+ root_module_xml(@foo).should match_xpath("#{order_entry_xpath}/library/CLASSES/root/@url",
216
+ "jar://$MAVEN_REPOSITORY$/group/id/1.0/id-1.0.jar!/")
217
+ end
218
+ end
219
+ end
220
+
221
+ describe "with multiple dependencies" do
222
+ before do
223
+ artifact('group:id:jar:1.0') { |t| write t.to_s }
224
+ artifact('group:id2:jar:1.0') { |t| write t.to_s }
225
+ @foo = define "foo" do
226
+ compile.with 'group:id:jar:1.0', 'group:id2:jar:1.0'
227
+ end
228
+ invoke_generate_task
229
+ end
230
+
231
+ it "generates multiple 'module-library' orderEntry in IML" do
232
+ root_module_xml(@foo).should have_nodes("#{order_entry_xpath}[@type='module-library']", 2)
233
+ end
234
+ end
235
+
236
+ describe "with a single non artifact dependency" do
237
+ before do
238
+ @foo = define "foo" do
239
+ filename = _("foo-dep.jar")
240
+ File.open(filename, "wb") { |t| write "Hello" }
241
+ compile.with filename
242
+ end
243
+ invoke_generate_task
244
+ end
245
+
246
+ it "generates one exported 'module-library' orderEntry in IML" do
247
+ root_module_xml(@foo).should match_xpath("#{order_entry_xpath}/library/CLASSES/root/@url",
248
+ "jar://$MODULE_DIR$/foo-dep.jar!/")
249
+ end
250
+ end
251
+
252
+ describe "with extra_modules specified" do
253
+ before do
254
+ @foo = define "foo" do
255
+ ipr.extra_modules << 'other.iml'
256
+ ipr.extra_modules << 'other_other.iml'
257
+ end
258
+ invoke_generate_task
259
+ end
260
+
261
+ it "generate an IPR with extra modules specified" do
262
+ doc = xml_document(@foo._("foo.ipr"))
263
+ doc.should have_nodes("#{xpath_to_module}", 3)
264
+ module_ref = "$PROJECT_DIR$/foo.iml"
265
+ doc.should have_xpath("#{xpath_to_module}[@fileurl='file://#{module_ref}' && @filepath='#{module_ref}']")
266
+ module_ref = "$PROJECT_DIR$/other.iml"
267
+ doc.should have_xpath("#{xpath_to_module}[@fileurl='file://#{module_ref}' && @filepath='#{module_ref}']")
268
+ module_ref = "$PROJECT_DIR$/other_other.iml"
269
+ doc.should have_xpath("#{xpath_to_module}[@fileurl='file://#{module_ref}' && @filepath='#{module_ref}']")
270
+ end
271
+ end
272
+
273
+ describe "with web and webservice facet added to root project" do
274
+ before do
275
+ @foo = define "foo" do
276
+ iml.add_facet("Web", "web") do |facet|
277
+ facet.configuration do |conf|
278
+ conf.descriptors do |desc|
279
+ desc.deploymentDescriptor :name => 'web.xml',
280
+ :url => "file://$MODULE_DIR$/src/main/webapp/WEB-INF/web.xml",
281
+ :optional => "false", :version => "2.4"
282
+ end
283
+ conf.webroots do |webroots|
284
+ webroots.root :url => "file://$MODULE_DIR$/src/main/webapp", :relative => "/"
285
+ end
286
+ end
287
+ end
288
+ iml.add_facet("WebServices Client", "WebServicesClient") do |facet|
289
+ facet.configuration "ws.engine" => "Glassfish / JAX-WS 2.X RI / Metro 1.X / JWSDP 2.0"
290
+ end
291
+ define 'bar'
292
+ end
293
+ invoke_generate_task
294
+ end
295
+
296
+ it "generates an IML for root project with a web and webservice facet" do
297
+ doc = xml_document(@foo._("foo.iml"))
298
+ ensure_facet_xpath(doc, 'web', 'Web')
299
+ ensure_facet_xpath(doc, 'WebServicesClient', 'WebServices Client')
300
+ end
301
+ end
302
+
303
+ describe "using add_gwt_facet" do
304
+ before do
305
+ @foo = define "foo" do
306
+ iml.add_gwt_facet("com.biz.MyModule" => true, "com.biz.MyOtherModule" => false)
307
+ end
308
+ invoke_generate_task
309
+ end
310
+
311
+ it "generates a gwt facet with default settings" do
312
+ doc = xml_document(@foo._("foo.iml"))
313
+ facet_xpath = ensure_facet_xpath(doc, 'gwt', 'GWT')
314
+ setting_xpath = "#{facet_xpath}/configuration/setting"
315
+ doc.should have_xpath("#{setting_xpath}[@name='gwtSdkUrl', value='file://$GWT_TOOLS$']")
316
+ doc.should have_xpath("#{setting_xpath}[@name='gwtScriptOutputStyle', value='PRETTY']")
317
+ doc.should have_xpath("#{setting_xpath}[@name='compilerParameters', value='-draftCompile -localWorkers 2 -strict']")
318
+ doc.should have_xpath("#{setting_xpath}[@name='compilerParameters', value='-draftCompile -localWorkers 2 -strict']")
319
+ doc.should have_xpath("#{setting_xpath}[@name='compilerMaxHeapSize', value='512']")
320
+ doc.should have_xpath("#{setting_xpath}[@name='webFacet', value='Web']")
321
+ end
322
+
323
+ it "generates a gwt facet with specified modules" do
324
+ doc = xml_document(@foo._("foo.iml"))
325
+ facet_xpath = ensure_facet_xpath(doc, 'gwt', 'GWT')
326
+ prefix = "#{facet_xpath}/configuration/packaging/module"
327
+ doc.should have_xpath("#{prefix}[@name='com.biz.MyModule' && @enabled='true']")
328
+ doc.should have_xpath("#{prefix}[@name='com.biz.MyOtherModule' && @enabled='false']")
329
+ end
330
+ end
331
+
332
+ describe "using add_gwt_facet that detects gwt sdk" do
333
+ before do
334
+ artifact('com.google.gwt:gwt-dev:jar:2.5.1-not-a-release') { |task| write task.name }
335
+ @foo = define "foo" do
336
+ compile.with 'com.google.gwt:gwt-dev:jar:2.5.1-not-a-release'
337
+ iml.add_gwt_facet("com.biz.MyModule" => true)
338
+ end
339
+ invoke_generate_task
340
+ end
341
+
342
+ it "generates a gwt facet with detected gwt sdk settings" do
343
+ doc = xml_document(@foo._("foo.iml"))
344
+ facet_xpath = ensure_facet_xpath(doc, 'gwt', 'GWT')
345
+ setting_xpath = "#{facet_xpath}/configuration/setting"
346
+ doc.should have_xpath("#{setting_xpath}[@name='gwtSdkType', value='maven']")
347
+ doc.should have_xpath("#{setting_xpath}[@name='gwtSdkUrl', value='$MAVEN_REPOSITORY$/com/google/gwt/gwt-dev/2.5.1-not-a-release']")
348
+ end
349
+ end
350
+
351
+ describe "using add_gwt_facet that specifies gwt sdk" do
352
+ before do
353
+ artifact('com.example:library:jar:2.0') { |task| write task.name }
354
+ @foo = define "foo" do
355
+ iml.add_gwt_facet({"com.biz.MyModule" => true},:gwt_dev_artifact => 'com.example:library:jar:2.0')
356
+ end
357
+ invoke_generate_task
358
+ end
359
+
360
+ it "generates a gwt facet with detected gwt sdk settings" do
361
+ doc = xml_document(@foo._("foo.iml"))
362
+ facet_xpath = ensure_facet_xpath(doc, 'gwt', 'GWT')
363
+ setting_xpath = "#{facet_xpath}/configuration/setting"
364
+ doc.should have_xpath("#{setting_xpath}[@name='gwtSdkType', value='maven']")
365
+ doc.should have_xpath("#{setting_xpath}[@name='gwtSdkUrl', value='$MAVEN_REPOSITORY$/com/google/gwt/gwt-dev/2.5.1']")
366
+ end
367
+ end
368
+
369
+ describe "using add_gwt_facet that specifies settings" do
370
+ before do
371
+ @foo = define "foo" do
372
+ iml.add_gwt_facet({"com.biz.MyModule" => true, "com.biz.MyOtherModule" => false},
373
+ :settings => {:gwtScriptOutputStyle => 'OTHER', :compilerMaxHeapSize => 1024, :zang => 'zang'})
374
+ end
375
+ invoke_generate_task
376
+ end
377
+
378
+ it "generates a gwt facet with specified settings" do
379
+ doc = xml_document(@foo._("foo.iml"))
380
+ facet_xpath = ensure_facet_xpath(doc, 'gwt', 'GWT')
381
+ setting_xpath = "#{facet_xpath}/configuration/setting"
382
+ doc.should have_xpath("#{setting_xpath}[@name='zang', value='zang']")
383
+ doc.should have_xpath("#{setting_xpath}[@name='gwtScriptOutputStyle', value='OTHER']")
384
+ doc.should have_xpath("#{setting_xpath}[@name='compilerMaxHeapSize', value='1024']")
385
+ end
386
+ end
387
+
388
+ describe "using add_web_facet with jsf and idea version 12" do
389
+ before do
390
+ write "src/main/webapp/WEB-INF/web.xml"
391
+ write "src/main/webapp/WEB-INF/faces-config.xml"
392
+
393
+ @foo = define "foo" do
394
+ ipr.version = "12"
395
+ iml.add_web_facet
396
+ end
397
+ invoke_generate_task
398
+ end
399
+
400
+ it "generates a web facet with jsf facet auto-detected" do
401
+ doc = xml_document(@foo._("foo.iml"))
402
+ web_facet_xpath = ensure_facet_xpath(doc, 'web', 'Web')
403
+ doc.should have_xpath("#{web_facet_xpath}/facet[@type='jsf' && @name='JSF']")
404
+ end
405
+ end
406
+
407
+ describe "using add_web_facet should default to no jsf" do
408
+ before do
409
+ write "src/main/webapp/WEB-INF/web.xml"
410
+
411
+ @foo = define "foo" do
412
+ iml.add_web_facet
413
+ end
414
+ invoke_generate_task
415
+ end
416
+
417
+ it "does not generate a web facet with jsf facet" do
418
+ doc = xml_document(@foo._("foo.iml"))
419
+ web_facet_xpath = ensure_facet_xpath(doc, 'web', 'Web')
420
+ doc.should_not have_xpath("#{web_facet_xpath}/facet[@type='jsf' && @name='JSF']")
421
+ end
422
+ end
423
+
424
+ describe "using add_web_facet with jsf and idea version 13" do
425
+ before do
426
+ write "src/main/webapp/WEB-INF/web.xml"
427
+ write "src/main/webapp/WEB-INF/faces-config.xml"
428
+
429
+ @foo = define "foo" do
430
+ ipr.version = "13"
431
+ iml.add_web_facet
432
+ end
433
+ invoke_generate_task
434
+ end
435
+
436
+ it "does not generate a web facet with jsf facet" do
437
+ doc = xml_document(@foo._("foo.iml"))
438
+ web_facet_xpath = ensure_facet_xpath(doc, 'web', 'Web')
439
+ doc.should_not have_xpath("#{web_facet_xpath}/facet[@type='jsf' && @name='JSF']")
440
+ end
441
+ end
442
+
443
+ describe "using add_web_facet with jsf and idea version 13 and jsf 'enabled'" do
444
+ before do
445
+ write "src/main/webapp/WEB-INF/web.xml"
446
+ write "src/main/webapp/WEB-INF/faces-config.xml"
447
+
448
+ @foo = define "foo" do
449
+ ipr.version = "13"
450
+ iml.add_web_facet(:enable_jsf => true)
451
+ end
452
+ invoke_generate_task
453
+ end
454
+
455
+ it "does not generate a web facet with jsf facet" do
456
+ doc = xml_document(@foo._("foo.iml"))
457
+ web_facet_xpath = ensure_facet_xpath(doc, 'web', 'Web')
458
+ doc.should_not have_xpath("#{web_facet_xpath}/facet[@type='jsf' && @name='JSF']")
459
+ end
460
+ end
461
+
462
+ describe "using add_web_facet" do
463
+ before do
464
+ write "src/main/webapp/WEB-INF/web.xml"
465
+ write "src/main/webapp/WEB-INF/glassfish-web.xml"
466
+ write "src/main/webapp/WEB-INF/context.xml"
467
+
468
+ @foo = define "foo" do
469
+ iml.add_web_facet
470
+ end
471
+ invoke_generate_task
472
+ end
473
+
474
+ it "generates a web facet with appropriate deployment descriptors" do
475
+ doc = xml_document(@foo._("foo.iml"))
476
+ web_facet_xpath = ensure_facet_xpath(doc, 'web', 'Web')
477
+ deployment_descriptor_xpath = "#{web_facet_xpath}/configuration/descriptors/deploymentDescriptor"
478
+ doc.should have_xpath("#{deployment_descriptor_xpath}[@name='web.xml', url='file://$MODULE_DIR$/src/main/webapp/WEB-INF/web.xml']")
479
+ doc.should have_xpath("#{deployment_descriptor_xpath}[@name='glassfish-web.xml', url='file://$MODULE_DIR$/src/main/webapp/WEB-INF/glassfish-web.xml']")
480
+ end
481
+
482
+ it "generates a web facet with derived webroots" do
483
+ doc = xml_document(@foo._("foo.iml"))
484
+ web_facet_xpath = ensure_facet_xpath(doc, 'web', 'Web')
485
+ doc.should have_xpath("#{web_facet_xpath}/configuration/webroots/root[@url='file://$MODULE_DIR$/src/main/webapp' && @relative='/']")
486
+ end
487
+ end
488
+
489
+ describe "using add_web_facet with specified parameters" do
490
+ before do
491
+ @foo = define "foo" do
492
+ iml.add_web_facet(:deployment_descriptors => ["src/main/webapp2/WEB-INF/web.xml"],
493
+ :webroots => {"src/main/webapp2" => "/", "src/main/css" => "/css"})
494
+ end
495
+ invoke_generate_task
496
+ end
497
+
498
+ it "generates a web facet with appropriate deployment descriptors" do
499
+ doc = xml_document(@foo._("foo.iml"))
500
+ web_facet_xpath = ensure_facet_xpath(doc, 'web', 'Web')
501
+ deployment_descriptor_xpath = "#{web_facet_xpath}/configuration/descriptors/deploymentDescriptor"
502
+ doc.should have_xpath("#{deployment_descriptor_xpath}[@name='web.xml', url='file://$MODULE_DIR$/src/main/webapp2/WEB-INF/web.xml']")
503
+ end
504
+
505
+ it "generates a web facet with specified webroots" do
506
+ doc = xml_document(@foo._("foo.iml"))
507
+ web_facet_xpath = ensure_facet_xpath(doc, 'web', 'Web')
508
+ doc.should have_xpath("#{web_facet_xpath}/configuration/webroots/root[@url='file://$MODULE_DIR$/src/main/webapp2' && @relative='/']")
509
+ doc.should have_xpath("#{web_facet_xpath}/configuration/webroots/root[@url='file://$MODULE_DIR$/src/main/css' && @relative='/css']")
510
+ end
511
+ end
512
+
513
+ describe "using add_jpa_facet" do
514
+ before do
515
+ write "src/main/resources/META-INF/persistence.xml", "org.hibernate.ejb.HibernatePersistence"
516
+ write "src/main/resources/META-INF/orm.xml"
517
+
518
+ @foo = define "foo" do
519
+ iml.add_jpa_facet
520
+ end
521
+ invoke_generate_task
522
+ end
523
+
524
+ it "generates a jpa facet with appropriate deployment descriptors" do
525
+ doc = xml_document(@foo._("foo.iml"))
526
+ facet_xpath = ensure_facet_xpath(doc, 'jpa', 'JPA')
527
+ deployment_descriptor_xpath = "#{facet_xpath}/configuration/deploymentDescriptor"
528
+ doc.should have_xpath("#{deployment_descriptor_xpath}[@name='persistence.xml', url='file://$MODULE_DIR$/src/main/resources/META-INF/persistence.xml']")
529
+ doc.should have_xpath("#{deployment_descriptor_xpath}[@name='orm.xml', url='file://$MODULE_DIR$/src/main/resources/META-INF/orm.xml']")
530
+ end
531
+
532
+ it "generates a jpa facet with default settings" do
533
+ doc = xml_document(@foo._("foo.iml"))
534
+ facet_xpath = ensure_facet_xpath(doc, 'jpa', 'JPA')
535
+ doc.should have_xpath("#{facet_xpath}/configuration/setting[@name='validation-enabled' && @value='true']")
536
+ doc.should have_xpath("#{facet_xpath}/configuration/setting[@name='provider-name' && @value='Hibernate']")
537
+ end
538
+ end
539
+
540
+ describe "using add_jpa_facet specifying parameters" do
541
+ before do
542
+ write "src/main/resources2/META-INF/persistence.xml"
543
+ write "src/main/resources2/META-INF/orm.xml"
544
+
545
+ @foo = define "foo" do
546
+ iml.add_jpa_facet(:provider_enabled => 'Hibernate',
547
+ :deployment_descriptors => %w[src/main/resources2/META-INF/persistence.xml src/main/resources2/META-INF/orm.xml])
548
+ end
549
+ invoke_generate_task
550
+ end
551
+
552
+ it "generates a jpa facet with appropriate deployment descriptors" do
553
+ doc = xml_document(@foo._("foo.iml"))
554
+ facet_xpath = ensure_facet_xpath(doc, 'jpa', 'JPA')
555
+ deployment_descriptor_xpath = "#{facet_xpath}/configuration/deploymentDescriptor"
556
+ doc.should have_xpath("#{deployment_descriptor_xpath}[@name='persistence.xml', url='file://$MODULE_DIR$/src/main/resources2/META-INF/persistence.xml']")
557
+ doc.should have_xpath("#{deployment_descriptor_xpath}[@name='orm.xml', url='file://$MODULE_DIR$/src/main/resources2/META-INF/orm.xml']")
558
+ end
559
+
560
+ it "generates a jpa facet with default settings" do
561
+ doc = xml_document(@foo._("foo.iml"))
562
+ facet_xpath = ensure_facet_xpath(doc, 'jpa', 'JPA')
563
+ doc.should have_xpath("#{facet_xpath}/configuration/setting[@name='validation-enabled' && @value='true']")
564
+ doc.should have_xpath("#{facet_xpath}/configuration/setting[@name='provider-name' && @value='Hibernate']")
565
+ end
566
+ end
567
+
568
+ describe "using add_jpa_facet derived from main_source_directories" do
569
+ before do
570
+ write "src/main/resources2/META-INF/persistence.xml"
571
+ write "src/main/resources2/META-INF/orm.xml"
572
+
573
+ @foo = define "foo" do
574
+ iml.main_source_directories << "src/main/resources2"
575
+ iml.add_jpa_facet
576
+
577
+ end
578
+ invoke_generate_task
579
+ end
580
+
581
+ it "generates a jpa facet with appropriate deployment descriptors" do
582
+ doc = xml_document(@foo._("foo.iml"))
583
+ facet_xpath = ensure_facet_xpath(doc, 'jpa', 'JPA')
584
+ deployment_descriptor_xpath = "#{facet_xpath}/configuration/deploymentDescriptor"
585
+ doc.should have_xpath("#{deployment_descriptor_xpath}[@name='persistence.xml', url='file://$MODULE_DIR$/src/main/resources2/META-INF/persistence.xml']")
586
+ doc.should have_xpath("#{deployment_descriptor_xpath}[@name='orm.xml', url='file://$MODULE_DIR$/src/main/resources2/META-INF/orm.xml']")
587
+ end
588
+ end
589
+
590
+ describe "using add_jpa_facet with hibernate configured in persistence.xml" do
591
+ before do
592
+ write "src/main/resources/META-INF/persistence.xml", "org.hibernate.ejb.HibernatePersistence"
593
+ write "src/main/resources/META-INF/orm.xml"
594
+
595
+ @foo = define "foo" do
596
+ iml.add_jpa_facet
597
+ end
598
+ invoke_generate_task
599
+ end
600
+
601
+ it "generates a jpa facet with default settings" do
602
+ doc = xml_document(@foo._("foo.iml"))
603
+ facet_xpath = ensure_facet_xpath(doc, 'jpa', 'JPA')
604
+ doc.should have_xpath("#{facet_xpath}/configuration/setting[@name='validation-enabled' && @value='true']")
605
+ doc.should have_xpath("#{facet_xpath}/configuration/setting[@name='provider-name' && @value='Hibernate']")
606
+ end
607
+ end
608
+
609
+ describe "using add_jpa_facet with eclipselink configured in persistence.xml" do
610
+ before do
611
+ write "src/main/resources/META-INF/persistence.xml", "org.eclipse.persistence.jpa.PersistenceProvider"
612
+ write "src/main/resources/META-INF/orm.xml"
613
+
614
+ @foo = define "foo" do
615
+ iml.add_jpa_facet
616
+ end
617
+ invoke_generate_task
618
+ end
619
+
620
+ it "generates a jpa facet with default settings" do
621
+ doc = xml_document(@foo._("foo.iml"))
622
+ facet_xpath = ensure_facet_xpath(doc, 'jpa', 'JPA')
623
+ doc.should have_xpath("#{facet_xpath}/configuration/setting[@name='validation-enabled' && @value='true']")
624
+ doc.should have_xpath("#{facet_xpath}/configuration/setting[@name='provider-name' && @value='EclipseLink']")
625
+ end
626
+ end
627
+
628
+ describe "using add_ejb_facet" do
629
+ before do
630
+ write "src/main/java/com/bin/foo.java"
631
+ write "src/main/resources/WEB-INF/ejb-jar.xml"
632
+
633
+ @foo = define "foo" do
634
+ iml.add_ejb_facet
635
+ end
636
+ invoke_generate_task
637
+ end
638
+
639
+ it "generates an ejb facet with appropriate deployment descriptors" do
640
+ doc = xml_document(@foo._("foo.iml"))
641
+ ejb_facet_xpath = ensure_facet_xpath(doc, 'ejb', 'EJB')
642
+ deployment_descriptor_xpath = "#{ejb_facet_xpath}/configuration/descriptors/deploymentDescriptor"
643
+ doc.should have_xpath("#{deployment_descriptor_xpath}[@name='ejb-jar.xml', url='file://$MODULE_DIR$/src/main/resources/WEB-INF/ejb-jar.xml']")
644
+ end
645
+
646
+ it "generates an ejb facet with derived ejbRoots" do
647
+ doc = xml_document(@foo._("foo.iml"))
648
+ ejb_facet_xpath = ensure_facet_xpath(doc, 'ejb', 'EJB')
649
+ doc.should have_xpath("#{ejb_facet_xpath}/configuration/ejbRoots/root[@url='file://$MODULE_DIR$/src/main/java']")
650
+ doc.should have_xpath("#{ejb_facet_xpath}/configuration/ejbRoots/root[@url='file://$MODULE_DIR$/src/main/resources']")
651
+ end
652
+ end
653
+
654
+ describe "using add_ejb_facet specifying parameters" do
655
+ before do
656
+ @foo = define "foo" do
657
+ iml.add_ejb_facet(:ejb_roots => %w[generated/main/java generated/main/resources],
658
+ :deployment_descriptors => ["generated/main/resources/WEB-INF/ejb-jar.xml"])
659
+ end
660
+ invoke_generate_task
661
+ end
662
+
663
+ it "generates an ejb facet with appropriate deployment descriptors" do
664
+ doc = xml_document(@foo._("foo.iml"))
665
+ ejb_facet_xpath = ensure_facet_xpath(doc, 'ejb', 'EJB')
666
+ deployment_descriptor_xpath = "#{ejb_facet_xpath}/configuration/descriptors/deploymentDescriptor"
667
+ doc.should have_xpath("#{deployment_descriptor_xpath}[@name='ejb-jar.xml', url='file://$MODULE_DIR$/generated/main/resources/WEB-INF/ejb-jar.xml']")
668
+ end
669
+
670
+ it "generates an ejb facet with derived ejbRoots" do
671
+ doc = xml_document(@foo._("foo.iml"))
672
+ ejb_facet_xpath = ensure_facet_xpath(doc, 'ejb', 'EJB')
673
+ doc.should have_xpath("#{ejb_facet_xpath}/configuration/ejbRoots/root[@url='file://$MODULE_DIR$/generated/main/java']")
674
+ doc.should have_xpath("#{ejb_facet_xpath}/configuration/ejbRoots/root[@url='file://$MODULE_DIR$/generated/main/resources']")
675
+ end
676
+ end
677
+
678
+ describe "using add_ejb_facet derived from main_source_directories" do
679
+ before do
680
+ write "src/main/resources2/WEB-INF/ejb-jar.xml"
681
+ @foo = define "foo" do
682
+ iml.main_source_directories << "src/main/resources2"
683
+ iml.add_ejb_facet
684
+ end
685
+ invoke_generate_task
686
+ end
687
+
688
+ it "generates an ejb facet with appropriate deployment descriptors" do
689
+ doc = xml_document(@foo._("foo.iml"))
690
+ ejb_facet_xpath = ensure_facet_xpath(doc, 'ejb', 'EJB')
691
+ deployment_descriptor_xpath = "#{ejb_facet_xpath}/configuration/descriptors/deploymentDescriptor"
692
+ doc.should have_xpath("#{deployment_descriptor_xpath}[@name='ejb-jar.xml', url='file://$MODULE_DIR$/src/main/resources2/WEB-INF/ejb-jar.xml']")
693
+ end
694
+ end
695
+
696
+ describe "with add_data_source" do
697
+ before do
698
+ artifact("org.postgresql:postgresql:jar:9.not-a-version") { |task| write task.name }
699
+ @foo = define "foo" do
700
+ ipr.add_data_source("Postgres",
701
+ :driver => 'org.postgresql.Driver',
702
+ :url => "jdbc:postgresql://127.0.0.1:5432/MyDb",
703
+ :username => "MyDBUser",
704
+ :password => "secreto",
705
+ :dialect => "PostgreSQL",
706
+ :classpath => ["org.postgresql:postgresql:jar:9.not-a-version"])
707
+ end
708
+ invoke_generate_task
709
+ end
710
+
711
+ it "generates a data source manager with specified data source" do
712
+ doc = xml_document(@foo._("foo.ipr"))
713
+ prefix_xpath = "/project/component[@name='DataSourceManagerImpl' && @format='xml' && @hash='3208837817']/data-source"
714
+ doc.should have_nodes(prefix_xpath, 1)
715
+ ds_path = "#{prefix_xpath}[@source='LOCAL' && @name='Postgres']"
716
+ doc.should have_xpath(ds_path)
717
+ doc.should have_xpath("#{ds_path}/synchronize/text() = 'true'")
718
+ doc.should have_xpath("#{ds_path}/jdbc-driver/text() = 'org.postgresql.Driver'")
719
+ doc.should have_xpath("#{ds_path}/jdbc-url/text() = 'jdbc:postgresql://127.0.0.1:5432/MyDb'")
720
+ doc.should have_xpath("#{ds_path}/user-name/text() = 'MyDBUser'")
721
+ doc.should have_xpath("#{ds_path}/user-password/text() = 'dfd9dfcfdfc9dfd8dfcfdfdedfc5'")
722
+ doc.should have_xpath("#{ds_path}/default-dialect/text() = 'PostgreSQL'")
723
+ doc.should have_xpath("#{ds_path}/libraries/library/url/text() = '$MAVEN_REPOSITORY$/org/postgresql/postgresql/9.not-a-version/postgresql-9.not-a-version.jar'")
724
+ end
725
+ end
726
+
727
+ describe "with add_postgres_data_source" do
728
+ before do
729
+ ENV["USER"] = "Bob"
730
+ artifact("org.postgresql:postgresql:jar:9.2-1003-jdbc4") { |task| write task.name }
731
+ @foo = define "foo" do
732
+ ipr.add_postgres_data_source("Postgres", :database => 'MyDb')
733
+ end
734
+ invoke_generate_task
735
+ end
736
+
737
+ it "generates a data source manager with specified data source" do
738
+ doc = xml_document(@foo._("foo.ipr"))
739
+ prefix_xpath = "/project/component[@name='DataSourceManagerImpl' && @format='xml' && @hash='3208837817']/data-source"
740
+ doc.should have_nodes(prefix_xpath, 1)
741
+ ds_path = "#{prefix_xpath}[@source='LOCAL' && @name='Postgres']"
742
+ doc.should have_xpath(ds_path)
743
+ doc.should have_xpath("#{ds_path}/synchronize/text() = 'true'")
744
+ doc.should have_xpath("#{ds_path}/jdbc-driver/text() = 'org.postgresql.Driver'")
745
+ doc.should have_xpath("#{ds_path}/jdbc-url/text() = 'jdbc:postgresql://127.0.0.1:5432/MyDb'")
746
+ doc.should have_xpath("#{ds_path}/user-name/text() = 'Bob'")
747
+ doc.should have_xpath("#{ds_path}/default-dialect/text() = 'PostgreSQL'")
748
+ doc.should have_xpath("#{ds_path}/libraries/library/url/text() = '$MAVEN_REPOSITORY$/org/postgresql/postgresql/9.2-1003-jdbc4/postgresql-9.2-1003-jdbc4.jar'")
749
+ end
750
+ end
751
+
752
+ describe "with add_sql_server_data_source" do
753
+ before do
754
+ ENV["USER"] = "Bob"
755
+ artifact('net.sourceforge.jtds:jtds:jar:1.2.7') { |task| write task.name }
756
+ @foo = define "foo" do
757
+ ipr.add_sql_server_data_source("SqlServer", :database => 'MyDb')
758
+ end
759
+ invoke_generate_task
760
+ end
761
+
762
+ it "generates a data source manager with specified data source" do
763
+ doc = xml_document(@foo._("foo.ipr"))
764
+ prefix_xpath = "/project/component[@name='DataSourceManagerImpl' && @format='xml' && @hash='3208837817']/data-source"
765
+ doc.should have_nodes(prefix_xpath, 1)
766
+ ds_path = "#{prefix_xpath}[@source='LOCAL' && @name='SqlServer']"
767
+ doc.should have_xpath(ds_path)
768
+
769
+ doc.should have_xpath("#{ds_path}/synchronize/text() = 'true'")
770
+ doc.should have_xpath("#{ds_path}/jdbc-driver/text() = 'net.sourceforge.jtds.jdbc.Driver'")
771
+ doc.should have_xpath("#{ds_path}/jdbc-url/text() = 'jdbc:jtds:sqlserver://127.0.0.1:1433/MyDb'")
772
+ doc.should have_xpath("#{ds_path}/user-name/text() = 'Bob'")
773
+ doc.should have_xpath("#{ds_path}/default-dialect/text() = 'TSQL'")
774
+ doc.should have_xpath("#{ds_path}/libraries/library/url/text() = '$MAVEN_REPOSITORY$/net/sourceforge/jtds/1.2.7/jtds-1.2.7.jar'")
775
+ end
776
+ end
777
+
778
+ describe "with artifacts added to root project" do
779
+ before do
780
+ @foo = define "foo" do
781
+ ipr.add_artifact("MyFancy.jar", "jar") do |xml|
782
+ xml.tag!('output-path', project._(:artifacts, "MyFancy.jar"))
783
+ xml.element :id => "module-output", :name => "foo"
784
+ end
785
+ ipr.add_artifact("MyOtherFancy.jar", "jar") do |xml|
786
+ xml.tag!('output-path', project._(:artifacts, "MyOtherFancy.jar"))
787
+ xml.element :id => "module-output", :name => "foo"
788
+ end
789
+ end
790
+ invoke_generate_task
791
+ end
792
+
793
+ it "generates an IPR with multiple jar artifacts" do
794
+ doc = xml_document(@foo._("foo.ipr"))
795
+ facet_xpath = "/project/component[@name='ArtifactManager']/artifact"
796
+ doc.should have_nodes(facet_xpath, 2)
797
+ doc.should have_xpath("#{facet_xpath}[@type='jar' && @name='MyFancy.jar']")
798
+ doc.should have_xpath("#{facet_xpath}[@type='jar' && @name='MyOtherFancy.jar']")
799
+ end
800
+ end
801
+
802
+ describe "that uses add_jar_artifact with no overrides" do
803
+ before do
804
+ write 'foo/bar/src/main/java/foo/Foo.java' # needed so that buildr will treat as a java project
805
+ artifact('net.sourceforge.jtds:jtds:jar:1.2.7.XX') { |task| write task.name }
806
+
807
+ @foo = define "foo" do
808
+ project.version = '1.0'
809
+ define "bar" do
810
+ compile.with 'net.sourceforge.jtds:jtds:jar:1.2.7.XX'
811
+ package :war
812
+ end
813
+ ipr.add_jar_artifact(project("bar"))
814
+ end
815
+ invoke_generate_task
816
+ end
817
+
818
+ it "generates an IPR with a jar artifact" do
819
+ doc = xml_document(@foo._("foo.ipr"))
820
+ base_xpath = "/project/component[@name='ArtifactManager']/artifact"
821
+ facet_xpath = "#{base_xpath}[@type='jar' && @name='bar.jar' && @build-on-make='false']"
822
+ doc.should have_xpath(facet_xpath)
823
+
824
+ doc.should have_xpath("#{facet_xpath}/output-path/text() = $PROJECT_DIR$/artifacts/bar")
825
+ doc.should have_xpath("#{facet_xpath}/root[@id='archive' && @name='bar.jar']/element[@id='module-output' && @name='bar']")
826
+ end
827
+ end
828
+
829
+ describe "that uses add_jar_artifact with overrides" do
830
+ before do
831
+ write 'foo/bar/src/main/java/foo/Foo.java' # needed so that buildr will treat as a java project
832
+ artifact('net.sourceforge.jtds:jtds:jar:1.2.7.XX') { |task| write task.name }
833
+
834
+ @foo = define "foo" do
835
+ project.version = '1.0'
836
+ define "bar" do
837
+ compile.with 'net.sourceforge.jtds:jtds:jar:1.2.7.XX'
838
+ package :war
839
+ end
840
+ ipr.add_jar_artifact(project,
841
+ :name => 'bar',
842
+ :output_dir => _('bink'),
843
+ :build_on_make => true,
844
+ :ejb_module_names => ['x'],
845
+ :jpa_module_names => ['p'],
846
+ :dependencies => [project('bar')])
847
+ end
848
+ invoke_generate_task
849
+ end
850
+
851
+ it "generates an IPR with a jar artifact" do
852
+ doc = xml_document(@foo._("foo.ipr"))
853
+ base_xpath = "/project/component[@name='ArtifactManager']/artifact"
854
+ facet_xpath = "#{base_xpath}[@type='jar' && @name='bar.jar' && @build-on-make='true']"
855
+ doc.should have_xpath(facet_xpath)
856
+
857
+ doc.should have_xpath("#{facet_xpath}/output-path/text() = $PROJECT_DIR$/bink")
858
+ doc.should have_xpath("#{facet_xpath}/root[@id='archive' && @name='bar.jar']/element[@id='module-output' && @name='bar']")
859
+ doc.should have_xpath("#{facet_xpath}/root[@id='archive' && @name='bar.jar']/element[@id='jpa-descriptors' && @facet='p/jpa/JPA']")
860
+ doc.should have_xpath("#{facet_xpath}/root[@id='archive' && @name='bar.jar']/element[@id='javaee-facet-resources' && @facet='x/ejb/EJB']")
861
+ end
862
+ end
863
+
864
+ describe "that uses add_exploded_ejb_artifact with overrides" do
865
+ before do
866
+ write 'foo/bar/src/main/java/foo/Foo.java' # needed so that buildr will treat as a java project
867
+ artifact('net.sourceforge.jtds:jtds:jar:1.2.7.XX') { |task| write task.name }
868
+
869
+ @foo = define "foo" do
870
+ project.version = '1.0'
871
+ define "bar" do
872
+ compile.with 'net.sourceforge.jtds:jtds:jar:1.2.7.XX'
873
+ package :jar
874
+ end
875
+ ipr.add_exploded_ejb_artifact(project("bar"),
876
+ :ejb_module_names => ['x'],
877
+ :jpa_module_names => ['p'])
878
+ end
879
+ invoke_generate_task
880
+ end
881
+
882
+ it "generates an IPR with an ejb artifact" do
883
+ doc = xml_document(@foo._("foo.ipr"))
884
+ base_xpath = "/project/component[@name='ArtifactManager']/artifact"
885
+ facet_xpath = "#{base_xpath}[@type='exploded-ejb' && @name='bar' && @build-on-make='false']"
886
+ doc.should have_xpath(facet_xpath)
887
+ doc.should have_xpath("#{facet_xpath}/output-path/text() = $PROJECT_DIR$/artifacts/bar")
888
+ doc.should have_xpath("#{facet_xpath}/root[@id='root']/element[@id='module-output' && @name='bar']")
889
+ doc.should have_xpath("#{facet_xpath}/root[@id='root']/element[@id='jpa-descriptors' && @facet='p/jpa/JPA']")
890
+ doc.should have_xpath("#{facet_xpath}/root[@id='root']/element[@id='javaee-facet-resources' && @facet='x/ejb/EJB']")
891
+ end
892
+ end
893
+
894
+ describe "that uses add_exploded_ejb_artifact with no overrides" do
895
+ before do
896
+ write 'foo/bar/src/main/java/foo/Foo.java' # needed so that buildr will treat as a java project
897
+ artifact('net.sourceforge.jtds:jtds:jar:1.2.7.XX') { |task| write task.name }
898
+
899
+ @foo = define "foo" do
900
+ project.version = '1.0'
901
+ define "bar" do
902
+ compile.with 'net.sourceforge.jtds:jtds:jar:1.2.7.XX'
903
+ package :war
904
+ end
905
+ ipr.add_exploded_ejb_artifact(project("bar"))
906
+ end
907
+ invoke_generate_task
908
+ end
909
+
910
+ it "generates an IPR with an ejb artifact" do
911
+ doc = xml_document(@foo._("foo.ipr"))
912
+ base_xpath = "/project/component[@name='ArtifactManager']/artifact"
913
+ facet_xpath = "#{base_xpath}[@type='exploded-ejb' && @name='bar' && @build-on-make='false']"
914
+ doc.should have_xpath(facet_xpath)
915
+
916
+ doc.should have_xpath("#{facet_xpath}/output-path/text() = $PROJECT_DIR$/artifacts/bar")
917
+ doc.should have_xpath("#{facet_xpath}/root[@id='root']/element[@id='module-output' && @name='bar']")
918
+ end
919
+ end
920
+
921
+
922
+ describe "that uses add_exploded_war_artifact with no overrides" do
923
+ before do
924
+ write 'foo/bar/src/main/java/foo/Foo.java' # needed so that buildr will treat as a java project
925
+ artifact('net.sourceforge.jtds:jtds:jar:1.2.7.XX') { |task| write task.name }
926
+
927
+ @foo = define "foo" do
928
+ project.version = '1.0'
929
+ define "bar" do
930
+ compile.with 'net.sourceforge.jtds:jtds:jar:1.2.7.XX'
931
+ package :war
932
+ end
933
+ ipr.add_exploded_war_artifact(project("bar"))
934
+ end
935
+ invoke_generate_task
936
+ end
937
+
938
+ it "generates an IPR with a war artifact" do
939
+ doc = xml_document(@foo._("foo.ipr"))
940
+ base_xpath = "/project/component[@name='ArtifactManager']/artifact"
941
+ facet_xpath = "#{base_xpath}[@type='exploded-war' && @name='bar' && @build-on-make='false']"
942
+ doc.should have_xpath(facet_xpath)
943
+
944
+ doc.should have_xpath("#{facet_xpath}/output-path/text() = $PROJECT_DIR$/artifacts/bar")
945
+ doc.should have_xpath("#{facet_xpath}/root[@id='root']/element[@id='directory' && @name='WEB-INF']/element[@id='directory' && @name='classes']/element[@id='module-output' && @name='bar']")
946
+ doc.should have_xpath("#{facet_xpath}/root[@id='root']/element[@id='directory' && @name='WEB-INF']/element[@id='directory' && @name='lib']/element[@id='file-copy' && @path='$MAVEN_REPOSITORY$/net/sourceforge/jtds/jtds/1.2.7.XX/jtds-1.2.7.XX.jar']")
947
+ doc.should have_xpath("#{facet_xpath}/root[@id='root']/element[@id='javaee-facet-resources' && @facet='bar/web/Web']")
948
+ end
949
+ end
950
+
951
+ describe "that uses add_exploded_war_artifact with overrides" do
952
+ before do
953
+ write 'foo/bar/src/main/java/foo/Foo.java' # needed so that buildr will treat as a java project
954
+ artifact('net.sourceforge.jtds:jtds:jar:1.2.7.XX') { |task| write task.name }
955
+
956
+ @foo = define "foo" do
957
+ project.version = '1.0'
958
+ define "bar" do
959
+ compile.with 'net.sourceforge.jtds:jtds:jar:1.2.7.XX'
960
+ package :war
961
+ end
962
+ ipr.add_exploded_war_artifact(project,
963
+ :name => 'gar',
964
+ :war_module_names => %w[x y],
965
+ :gwt_module_names => %w[p q],
966
+ :artifacts => %w[baz biz],
967
+ :dependencies => ['net.sourceforge.jtds:jtds:jar:1.2.7.XX', project('bar')])
968
+ end
969
+ invoke_generate_task
970
+ end
971
+
972
+ it "generates an IPR with a war artifact" do
973
+ doc = xml_document(@foo._("foo.ipr"))
974
+ base_xpath = "/project/component[@name='ArtifactManager']/artifact"
975
+ facet_xpath = "#{base_xpath}[@type='exploded-war' @name='MyFancy.jar' && @build-on-make='false']"
976
+ doc.should have_xpath(facet_xpath)
977
+
978
+ doc.should have_xpath("#{facet_xpath}/output-path/text() = $PROJECT_DIR$/artifacts/gar")
979
+ doc.should have_xpath("#{facet_xpath}/root[@id='root']/element[@id='directory' && @name='WEB-INF']/element[@id='directory' && @name='classes']/element[@id='module-output' && @name='bar']")
980
+ doc.should have_xpath("#{facet_xpath}/root[@id='root']/element[@id='directory' && @name='WEB-INF']/element[@id='directory' && @name='lib']/element[@id='file-copy' && @path='$MAVEN_REPOSITORY$/net/sourceforge/jtds/jtds/1.2.7.XX/jtds-1.2.7.XX.jar']")
981
+ doc.should have_xpath("#{facet_xpath}/root[@id='root']/element[@id='javaee-facet-resources' && @facet='x/web/Web']")
982
+ doc.should have_xpath("#{facet_xpath}/root[@id='root']/element[@id='javaee-facet-resources' && @facet='y/web/Web']")
983
+ doc.should have_xpath("#{facet_xpath}/root[@id='root']/element[@id='gwt-compiler-output' && @facet='p/gwt/GWT']")
984
+ doc.should have_xpath("#{facet_xpath}/root[@id='root']/element[@id='gwt-compiler-output' && @facet='q/gwt/GWT']")
985
+ doc.should have_xpath("#{facet_xpath}/root[@id='root']/element[@id='directory' && @name='WEB-INF']/element[@id='directory' && @name='lib']/element[@id='artifact' && @artifact-name='baz.jar']")
986
+ doc.should have_xpath("#{facet_xpath}/root[@id='root']/element[@id='directory' && @name='WEB-INF']/element[@id='directory' && @name='lib']/element[@id='artifact' && @artifact-name='biz.jar']")
987
+ end
988
+ end
989
+
990
+ describe "with configurations added to root project" do
991
+ before do
992
+ @foo = define "foo" do
993
+ ipr.add_configuration("Run Contacts.html", "GWT.ConfigurationType", "GWT Configuration") do |xml|
994
+ xml.module(:name => project.iml.id)
995
+ xml.option(:name => "RUN_PAGE", :value => "Contacts.html")
996
+ xml.option(:name => "compilerParameters", :value => "-draftCompile -localWorkers 2")
997
+ xml.option(:name => "compilerMaxHeapSize", :value => "512")
998
+
999
+ xml.RunnerSettings(:RunnerId => "Run")
1000
+ xml.ConfigurationWrapper(:RunnerId => "Run")
1001
+ xml.tag! :method
1002
+ end
1003
+ ipr.add_configuration("Run Planner.html", "GWT.ConfigurationType", "GWT Configuration") do |xml|
1004
+ xml.module(:name => project.iml.id)
1005
+ xml.option(:name => "RUN_PAGE", :value => "Planner.html")
1006
+ xml.option(:name => "compilerParameters", :value => "-draftCompile -localWorkers 2")
1007
+ xml.option(:name => "compilerMaxHeapSize", :value => "512")
1008
+
1009
+ xml.RunnerSettings(:RunnerId => "Run")
1010
+ xml.ConfigurationWrapper(:RunnerId => "Run")
1011
+ xml.tag! :method
1012
+ end
1013
+ end
1014
+ invoke_generate_task
1015
+ end
1016
+
1017
+ it "generates an IPR with multiple configurations" do
1018
+ doc = xml_document(@foo._("foo.ipr"))
1019
+ facet_xpath = "/project/component[@name='ProjectRunConfigurationManager']/configuration"
1020
+ doc.should have_nodes(facet_xpath, 2)
1021
+ doc.should have_xpath("#{facet_xpath}[@type='GWT.ConfigurationType' && @name='Run Contacts.html']")
1022
+ doc.should have_xpath("#{facet_xpath}[@type='GWT.ConfigurationType' && @name='Run Planner.html']")
1023
+ end
1024
+ end
1025
+
1026
+ describe "with default configuration added to root project" do
1027
+ before do
1028
+ @foo = define "foo" do
1029
+ ipr.add_default_configuration("GWT.ConfigurationType", "GWT Configuration") do |xml|
1030
+ xml.module(:name => project.iml.id)
1031
+ xml.option(:name => "RUN_PAGE", :value => "Planner.html")
1032
+ xml.option(:name => "compilerParameters", :value => "-draftCompile -localWorkers 2")
1033
+ xml.option(:name => "compilerMaxHeapSize", :value => "512")
1034
+
1035
+ xml.RunnerSettings(:RunnerId => "Run")
1036
+ xml.ConfigurationWrapper(:RunnerId => "Run")
1037
+ xml.tag! :method
1038
+ end
1039
+ end
1040
+ invoke_generate_task
1041
+ end
1042
+
1043
+ it "generates an IPR with default configuration" do
1044
+ doc = xml_document(@foo._("foo.ipr"))
1045
+ facet_xpath = "/project/component[@name='ProjectRunConfigurationManager']/configuration"
1046
+ doc.should have_nodes(facet_xpath, 1)
1047
+ doc.should have_xpath("#{facet_xpath}[@type='GWT.ConfigurationType' && @factoryName='GWT Configuration' && @default='true']")
1048
+ end
1049
+ end
1050
+
1051
+ describe "with add_default_testng_configuration using defaults" do
1052
+ before do
1053
+ @foo = define "foo" do
1054
+ ipr.add_default_testng_configuration
1055
+ end
1056
+ invoke_generate_task
1057
+ end
1058
+
1059
+ it "generates an IPR with default configuration" do
1060
+ doc = xml_document(@foo._("foo.ipr"))
1061
+ configurations_xpath = "/project/component[@name='ProjectRunConfigurationManager']/configuration"
1062
+ doc.should have_nodes(configurations_xpath, 1)
1063
+ configuration_xpath = "#{configurations_xpath}[@type='TestNG' && @factoryName='TestNG' && @default='true']"
1064
+ doc.should have_xpath(configuration_xpath)
1065
+ doc.should have_xpath("#{configuration_xpath}/option[@name='VM_PARAMETERS' && @value='-ea']")
1066
+ doc.should have_xpath("#{configuration_xpath}/option[@name='WORKING_DIRECTORY' && @value='$PROJECT_DIR$']")
1067
+ end
1068
+ end
1069
+
1070
+ describe "with add_default_testng_configuration specifying values" do
1071
+ before do
1072
+ @foo = define "foo" do
1073
+ ipr.add_default_testng_configuration(:dir => 'C:/blah', :jvm_args => '-ea -Dtest.db.url=xxxx')
1074
+ end
1075
+ invoke_generate_task
1076
+ end
1077
+
1078
+ it "generates an IPR with default configuration" do
1079
+ doc = xml_document(@foo._("foo.ipr"))
1080
+ configurations_xpath = "/project/component[@name='ProjectRunConfigurationManager']/configuration"
1081
+ doc.should have_nodes(configurations_xpath, 1)
1082
+ configuration_xpath = "#{configurations_xpath}[@type='TestNG' && @factoryName='TestNG' && @default='true']"
1083
+ doc.should have_xpath(configuration_xpath)
1084
+ doc.should have_xpath("#{configuration_xpath}/option[@name='VM_PARAMETERS' && @value='-ea -Dtest.db.url=xxxx']")
1085
+ doc.should have_xpath("#{configuration_xpath}/option[@name='WORKING_DIRECTORY' && @value='C:/blah']")
1086
+ end
1087
+ end
1088
+
1089
+ describe "with iml.group specified" do
1090
+ before do
1091
+ @foo = define "foo" do
1092
+ iml.group = true
1093
+ define 'bar' do
1094
+ define 'baz' do
1095
+
1096
+ end
1097
+ end
1098
+ define 'rab' do
1099
+ iml.group = "MyGroup"
1100
+ end
1101
+ end
1102
+ invoke_generate_task
1103
+ end
1104
+
1105
+ it "generate an IPR with correct group references" do
1106
+ doc = xml_document(@foo._("foo.ipr"))
1107
+ doc.should have_nodes("#{xpath_to_module}", 4)
1108
+ module_ref = "$PROJECT_DIR$/foo.iml"
1109
+ doc.should have_xpath("#{xpath_to_module}[@fileurl='file://#{module_ref}' && @filepath='#{module_ref}']")
1110
+ module_ref = "$PROJECT_DIR$/rab/rab.iml"
1111
+ doc.should have_xpath("#{xpath_to_module}[@fileurl='file://#{module_ref}' && @filepath='#{module_ref}' @group = 'MyGroup']")
1112
+ module_ref = "$PROJECT_DIR$/bar/bar.iml"
1113
+ doc.should have_xpath("#{xpath_to_module}[@fileurl='file://#{module_ref}' && @filepath='#{module_ref}' @group = 'foo']")
1114
+ module_ref = "$PROJECT_DIR$/bar/baz/baz.iml"
1115
+ doc.should have_xpath("#{xpath_to_module}[@fileurl='file://#{module_ref}' && @filepath='#{module_ref}' @group = 'foo/bar']")
1116
+ end
1117
+ end
1118
+
1119
+ describe "with a single project definition" do
1120
+ describe "and default naming" do
1121
+ before do
1122
+ @foo = define "foo"
1123
+ invoke_generate_task
1124
+ end
1125
+
1126
+ it "generates a single IPR" do
1127
+ Dir[@foo._("**/*.ipr")].should have(1).entry
1128
+ end
1129
+
1130
+ it "generate an IPR in the root directory" do
1131
+ File.should be_exist(@foo._("foo.ipr"))
1132
+ end
1133
+
1134
+ it "generates a single IML" do
1135
+ Dir[@foo._("**/*.iml")].should have(1).entry
1136
+ end
1137
+
1138
+ it "generates an IML in the root directory" do
1139
+ File.should be_exist(@foo._("foo.iml"))
1140
+ end
1141
+
1142
+ it "generate an IPR with the reference to correct module file" do
1143
+ File.should be_exist(@foo._("foo.ipr"))
1144
+ doc = xml_document(@foo._("foo.ipr"))
1145
+ module_ref = "$PROJECT_DIR$/foo.iml"
1146
+ doc.should have_nodes("#{xpath_to_module}[@fileurl='file://#{module_ref}' && @filepath='#{module_ref}']", 1)
1147
+ end
1148
+ end
1149
+
1150
+ describe "with no_iml generation disabled" do
1151
+ before do
1152
+ @foo = define "foo" do
1153
+ project.no_iml
1154
+ end
1155
+ invoke_generate_task
1156
+ end
1157
+
1158
+ it "generates no IML" do
1159
+ Dir[@foo._("**/*.iml")].should have(0).entry
1160
+ end
1161
+
1162
+ it "generate an IPR with no references" do
1163
+ File.should be_exist(@foo._("foo.ipr"))
1164
+ doc = xml_document(@foo._("foo.ipr"))
1165
+ doc.should have_nodes("#{xpath_to_module}", 0)
1166
+ end
1167
+ end
1168
+
1169
+ describe "with ipr generation disabled" do
1170
+ before do
1171
+ @foo = define "foo" do
1172
+ project.no_ipr
1173
+ end
1174
+ invoke_generate_task
1175
+ end
1176
+
1177
+ it "generates a single IML" do
1178
+ Dir[@foo._("**/*.iml")].should have(1).entry
1179
+ end
1180
+
1181
+ it "generate no IPR" do
1182
+ File.should_not be_exist(@foo._("foo.ipr"))
1183
+ end
1184
+ end
1185
+
1186
+ describe "and id overrides" do
1187
+ before do
1188
+ @foo = define "foo" do
1189
+ ipr.id = 'fooble'
1190
+ iml.id = 'feap'
1191
+ define "bar" do
1192
+ iml.id = "baz"
1193
+ end
1194
+ end
1195
+ invoke_generate_task
1196
+ end
1197
+
1198
+ it "generate an IPR in the root directory" do
1199
+ File.should be_exist(@foo._("fooble.ipr"))
1200
+ end
1201
+
1202
+ it "generates an IML in the root directory" do
1203
+ File.should be_exist(@foo._("feap.iml"))
1204
+ end
1205
+
1206
+ it "generates an IML in the subproject directory" do
1207
+ File.should be_exist(@foo._("bar/baz.iml"))
1208
+ end
1209
+
1210
+ it "generate an IPR with the reference to correct module file" do
1211
+ File.should be_exist(@foo._("fooble.ipr"))
1212
+ doc = xml_document(@foo._("fooble.ipr"))
1213
+ module_ref = "$PROJECT_DIR$/feap.iml"
1214
+ doc.should have_nodes("#{xpath_to_module}[@fileurl='file://#{module_ref}' && @filepath='#{module_ref}']", 1)
1215
+ end
1216
+ end
1217
+
1218
+ describe "and a suffix defined" do
1219
+ before do
1220
+ @foo = define "foo" do
1221
+ ipr.suffix = '-ipr-suffix'
1222
+ iml.suffix = '-iml-suffix'
1223
+ end
1224
+ invoke_generate_task
1225
+ end
1226
+
1227
+ it "generate an IPR in the root directory" do
1228
+ File.should be_exist(@foo._("foo-ipr-suffix.ipr"))
1229
+ end
1230
+
1231
+ it "generates an IML in the root directory" do
1232
+ File.should be_exist(@foo._("foo-iml-suffix.iml"))
1233
+ end
1234
+
1235
+ it "generate an IPR with the reference to correct module file" do
1236
+ File.should be_exist(@foo._("foo-ipr-suffix.ipr"))
1237
+ doc = xml_document(@foo._("foo-ipr-suffix.ipr"))
1238
+ doc.should have_nodes("#{xpath_to_module}", 1)
1239
+ module_ref = "$PROJECT_DIR$/foo-iml-suffix.iml"
1240
+ doc.should have_nodes("#{xpath_to_module}[@fileurl='file://#{module_ref}' && @filepath='#{module_ref}']", 1)
1241
+ end
1242
+ end
1243
+
1244
+ describe "and a prefix defined" do
1245
+ before do
1246
+ @foo = define "foo" do
1247
+ ipr.prefix = 'ipr-prefix-'
1248
+ iml.prefix = 'iml-prefix-'
1249
+ end
1250
+ invoke_generate_task
1251
+ end
1252
+
1253
+ it "generate an IPR in the root directory" do
1254
+ File.should be_exist(@foo._("ipr-prefix-foo.ipr"))
1255
+ end
1256
+
1257
+ it "generates an IML in the root directory" do
1258
+ File.should be_exist(@foo._("iml-prefix-foo.iml"))
1259
+ end
1260
+
1261
+ it "generate an IPR with the reference to correct module file" do
1262
+ File.should be_exist(@foo._("ipr-prefix-foo.ipr"))
1263
+ doc = xml_document(@foo._("ipr-prefix-foo.ipr"))
1264
+ doc.should have_nodes("#{xpath_to_module}", 1)
1265
+ module_ref = "$PROJECT_DIR$/iml-prefix-foo.iml"
1266
+ doc.should have_nodes("#{xpath_to_module}[@fileurl='file://#{module_ref}' && @filepath='#{module_ref}']", 1)
1267
+ end
1268
+ end
1269
+
1270
+ describe "and a suffix and a prefix defined" do
1271
+ before do
1272
+ @foo = define "foo" do
1273
+ ipr.suffix = '-ipr-suffix'
1274
+ iml.suffix = '-iml-suffix'
1275
+ ipr.prefix = 'ipr-prefix-'
1276
+ iml.prefix = 'iml-prefix-'
1277
+ end
1278
+ invoke_generate_task
1279
+ end
1280
+
1281
+ it "generate an IPR in the root directory" do
1282
+ File.should be_exist(@foo._("ipr-prefix-foo-ipr-suffix.ipr"))
1283
+ end
1284
+
1285
+ it "generates an IML in the root directory" do
1286
+ File.should be_exist(@foo._("iml-prefix-foo-iml-suffix.iml"))
1287
+ end
1288
+
1289
+ it "generate an IPR with the reference to correct module file" do
1290
+ File.should be_exist(@foo._("ipr-prefix-foo-ipr-suffix.ipr"))
1291
+ doc = xml_document(@foo._("ipr-prefix-foo-ipr-suffix.ipr"))
1292
+ doc.should have_nodes("#{xpath_to_module}", 1)
1293
+ module_ref = "$PROJECT_DIR$/iml-prefix-foo-iml-suffix.iml"
1294
+ doc.should have_nodes("#{xpath_to_module}[@fileurl='file://#{module_ref}' && @filepath='#{module_ref}']", 1)
1295
+ end
1296
+ end
1297
+ end
1298
+
1299
+ describe "with a subproject" do
1300
+ before do
1301
+ @foo = define "foo" do
1302
+ define 'bar'
1303
+ end
1304
+ invoke_generate_task
1305
+ end
1306
+
1307
+ it "creates the subproject directory" do
1308
+ File.should be_exist(@foo._("bar"))
1309
+ end
1310
+
1311
+ it "generates an IML in the subproject directory" do
1312
+ File.should be_exist(@foo._("bar/bar.iml"))
1313
+ end
1314
+
1315
+ it "generate an IPR with the reference to correct module file" do
1316
+ File.should be_exist(@foo._("foo.ipr"))
1317
+ doc = xml_document(@foo._("foo.ipr"))
1318
+ doc.should have_nodes("#{xpath_to_module}", 2)
1319
+ module_ref = "$PROJECT_DIR$/foo.iml"
1320
+ doc.should have_nodes("#{xpath_to_module}[@fileurl='file://#{module_ref}' && @filepath='#{module_ref}']", 1)
1321
+ module_ref = "$PROJECT_DIR$/bar/bar.iml"
1322
+ doc.should have_nodes("#{xpath_to_module}[@fileurl='file://#{module_ref}' && @filepath='#{module_ref}']", 1)
1323
+ end
1324
+ end
1325
+
1326
+ describe "with base_dir specified" do
1327
+ before do
1328
+ @foo = define "foo" do
1329
+ define('bar', :base_dir => 'fe') do
1330
+ define('baz', :base_dir => 'fi') do
1331
+ define('foe')
1332
+ end
1333
+ define('fum')
1334
+ end
1335
+ end
1336
+ invoke_generate_task
1337
+ end
1338
+
1339
+ it "generates a subproject IML in the specified directory" do
1340
+ File.should be_exist(@foo._("fe/bar.iml"))
1341
+ end
1342
+
1343
+ it "generates a sub-subproject IML in the specified directory" do
1344
+ File.should be_exist(@foo._("fi/baz.iml"))
1345
+ end
1346
+
1347
+ it "generates a sub-sub-subproject IML that inherits the specified directory" do
1348
+ File.should be_exist(@foo._("fi/foe/foe.iml"))
1349
+ end
1350
+
1351
+ it "generates a sub-subproject IML that inherits the specified directory" do
1352
+ File.should be_exist(@foo._("fe/fum/fum.iml"))
1353
+ end
1354
+
1355
+ it "generate an IPR with the references to correct module files" do
1356
+ doc = xml_document(@foo._("foo.ipr"))
1357
+ doc.should have_nodes("#{xpath_to_module}", 5)
1358
+ %w[foo.iml fe/bar.iml fi/baz.iml fi/foe/foe.iml fe/fum/fum.iml].each do |module_ref|
1359
+ doc.should have_nodes("#{xpath_to_module}[@fileurl='file://$PROJECT_DIR$/#{module_ref}' && @filepath='$PROJECT_DIR$/#{module_ref}']", 1)
1360
+ end
1361
+ end
1362
+ end
1363
+
1364
+ describe "with extensive intermodule dependencies" do
1365
+ before do
1366
+ mkdir_p 'foo/src/main/resources'
1367
+ mkdir_p 'foo/src/main/java/foo'
1368
+ touch 'foo/src/main/java/foo/Foo.java' # needed so that buildr will treat as a java project
1369
+ artifact('group:id:jar:1.0') { |t| write t.to_s }
1370
+ define "root" do
1371
+ repositories.remote << 'https://repo1.maven.org/maven2'
1372
+ project.version = "2.5.2"
1373
+ define 'foo' do
1374
+ resources.from _(:source, :main, :resources)
1375
+ compile.with 'group:id:jar:1.0'
1376
+ test.using(:testng)
1377
+ package(:jar)
1378
+ end
1379
+
1380
+ define 'bar' do
1381
+ # internally transitive dependencies on foo, both runtime and test
1382
+ compile.with project('root:foo'), project('root:foo').compile.dependencies
1383
+ test.using(:testng).with [project('root:foo').test.compile.target,
1384
+ project('root:foo').test.resources.target,
1385
+ project('root:foo').test.compile.dependencies].compact
1386
+ package(:jar)
1387
+ end
1388
+ end
1389
+
1390
+ invoke_generate_task
1391
+ @bar_iml = xml_document(project('root:bar')._('bar.iml'))
1392
+ @bar_lib_urls = @bar_iml.get_elements("//orderEntry[@type='module-library']/library/CLASSES/root").collect do |root|
1393
+ root.attribute('url').to_s
1394
+ end
1395
+ end
1396
+
1397
+ it "depends on the associated module exactly once" do
1398
+ @bar_iml.should have_nodes("//orderEntry[@type='module' && @module-name='foo' && @exported=""]", 1)
1399
+ end
1400
+
1401
+ it "does not depend on the other project's packaged JAR" do
1402
+ @bar_lib_urls.grep(%r{#{project('root:foo').packages.first}}).should == []
1403
+ end
1404
+
1405
+ it "does not depend on the the other project's target/classes directory" do
1406
+ @bar_lib_urls.grep(%r{foo/target/classes}).should == []
1407
+ end
1408
+
1409
+ it "does not depend on the the other project's target/resources directory" do
1410
+ @bar_lib_urls.grep(%r{file://\$MODULE_DIR\$/../foo/target/resources}).size.should == 0
1411
+ end
1412
+ end
1413
+
1414
+ describe "with a single project definition" do
1415
+ before do
1416
+ @foo = define "foo"
1417
+ end
1418
+
1419
+ it "informs the user about generating IPR" do
1420
+ lambda { invoke_generate_task }.should show_info(/Writing (.+)\/foo\.ipr/)
1421
+ end
1422
+
1423
+ it "informs the user about generating IML" do
1424
+ lambda { invoke_generate_task }.should show_info(/Writing (.+)\/foo\.iml/)
1425
+ end
1426
+ end
1427
+ describe "with a subproject" do
1428
+ before do
1429
+ @foo = define "foo" do
1430
+ define 'bar'
1431
+ end
1432
+ end
1433
+
1434
+ it "informs the user about generating subporoject IML" do
1435
+ lambda { invoke_generate_task }.should show_info(/Writing (.+)\/bar\/bar\.iml/)
1436
+ end
1437
+ end
1438
+
1439
+ describe "with compile.options.source = '1.6'" do
1440
+
1441
+ before do
1442
+ @foo = define "foo" do
1443
+ compile.options.source = '1.5'
1444
+ end
1445
+ invoke_generate_task
1446
+ end
1447
+
1448
+ it "generate an ProjectRootManager with 1.5 jdk specified" do
1449
+ #raise File.read(@foo._("foo.ipr"))
1450
+ xml_document(@foo._("foo.ipr")).
1451
+ should have_xpath("/project/component[@name='ProjectRootManager' && @project-jdk-name = '1.5' && @languageLevel = 'JDK_1_5']")
1452
+ end
1453
+
1454
+ it "generates a ProjectDetails component with the projectName option set" do
1455
+ xml_document(@foo._("foo.ipr")).
1456
+ should have_xpath("/project/component[@name='ProjectDetails']/option[@name = 'projectName' && @value = 'foo']")
1457
+ end
1458
+ end
1459
+
1460
+ describe "with compile.options.source = '1.6'" do
1461
+ before do
1462
+ @foo = define "foo" do
1463
+ compile.options.source = '1.6'
1464
+ end
1465
+ invoke_generate_task
1466
+ end
1467
+
1468
+ it "generate an ProjectRootManager with 1.6 jdk specified" do
1469
+ xml_document(@foo._("foo.ipr")).
1470
+ should have_xpath("/project/component[@name='ProjectRootManager' && @project-jdk-name = '1.6' && @languageLevel = 'JDK_1_6']")
1471
+ end
1472
+ end
1473
+
1474
+ describe "with iml.skip_content! specified" do
1475
+ before do
1476
+ @foo = define "foo" do
1477
+ iml.skip_content!
1478
+ end
1479
+ invoke_generate_task
1480
+ end
1481
+
1482
+ it "generate an IML with no content section" do
1483
+ doc = xml_document(@foo._(root_module_filename(@foo)))
1484
+ doc.should_not have_xpath("/module/component[@name='NewModuleRootManager']/content")
1485
+ end
1486
+ end
1487
+
1488
+ describe "with iml.skip_content! not specified and standard layout" do
1489
+ before do
1490
+ @foo = define "foo" do
1491
+ end
1492
+ invoke_generate_task
1493
+ end
1494
+
1495
+ it "generate an IML with content section" do
1496
+ root_module_xml(@foo).should have_xpath("/module/component[@name='NewModuleRootManager']/content")
1497
+ end
1498
+
1499
+ it "generate an exclude in content section for reports" do
1500
+ root_module_xml(@foo).should have_xpath("/module/component[@name='NewModuleRootManager']/content/excludeFolder[@url='file://$MODULE_DIR$/reports']")
1501
+ end
1502
+
1503
+ it "generate an exclude in content section for target" do
1504
+ root_module_xml(@foo).should have_xpath("/module/component[@name='NewModuleRootManager']/content/excludeFolder[@url='file://$MODULE_DIR$/target']")
1505
+ end
1506
+ end
1507
+
1508
+ describe "with subprojects" do
1509
+ before do
1510
+ @foo = define "foo" do
1511
+ define "bar" do
1512
+ compile.from _(:source, :main, :bar)
1513
+ end
1514
+ end
1515
+ invoke_generate_task
1516
+ @bar_doc = xml_document(project('foo:bar')._('bar.iml'))
1517
+ end
1518
+
1519
+ it "generates the correct source directories" do
1520
+ @bar_doc.should have_xpath("//content/sourceFolder[@url='file://$MODULE_DIR$/src/main/bar']")
1521
+ end
1522
+
1523
+ it "generates the correct exclude directories" do
1524
+ @bar_doc.should have_xpath("//content/excludeFolder[@url='file://$MODULE_DIR$/target']")
1525
+ end
1526
+ end
1527
+
1528
+ describe "with overrides" do
1529
+ before do
1530
+ @foo = define "foo" do
1531
+ compile.from _(:source, :main, :bar)
1532
+ iml.main_source_directories << _(:source, :main, :baz)
1533
+ iml.test_source_directories << _(:source, :test, :foo)
1534
+ end
1535
+ invoke_generate_task
1536
+ end
1537
+
1538
+ it "generates the correct main source directories" do
1539
+ root_module_xml(@foo).should have_xpath("//content/sourceFolder[@url='file://$MODULE_DIR$/src/main/baz' && @isTestSource='false']")
1540
+ end
1541
+
1542
+ it "generates the correct test source directories" do
1543
+ root_module_xml(@foo).should have_xpath("//content/sourceFolder[@url='file://$MODULE_DIR$/src/test/foo' && @isTestSource='true']")
1544
+ end
1545
+ end
1546
+
1547
+ describe "with report dir outside content" do
1548
+ before do
1549
+ layout = Layout::Default.new
1550
+ layout[:reports] = "../reports"
1551
+
1552
+ @foo = define "foo", :layout => layout do
1553
+ end
1554
+ invoke_generate_task
1555
+ end
1556
+
1557
+ it "generate an exclude in content section for target" do
1558
+ root_module_xml(@foo).should have_xpath("/module/component[@name='NewModuleRootManager']/content/excludeFolder[@url='file://$MODULE_DIR$/target']")
1559
+ end
1560
+
1561
+ it "generates an content section without an exclude for report dir" do
1562
+ root_module_xml(@foo).should have_nodes("/module/component[@name='NewModuleRootManager']/content/excludeFolder", 1)
1563
+ end
1564
+ end
1565
+
1566
+ describe "with target dir outside content" do
1567
+ before do
1568
+ layout = Layout::Default.new
1569
+ layout[:target] = "../target"
1570
+ layout[:target, :main] = "../target"
1571
+
1572
+ @foo = define "foo", :layout => layout do
1573
+ end
1574
+ invoke_generate_task
1575
+ end
1576
+
1577
+ it "generate an exclude in content section for reports" do
1578
+ root_module_xml(@foo).should have_xpath("/module/component[@name='NewModuleRootManager']/content/excludeFolder[@url='file://$MODULE_DIR$/reports']")
1579
+ end
1580
+
1581
+ it "generates an content section without an exclude for target dir" do
1582
+ root_module_xml(@foo).should have_nodes("/module/component[@name='NewModuleRootManager']/content/excludeFolder", 1)
1583
+ end
1584
+ end
1585
+
1586
+ describe "templates" do
1587
+
1588
+ def ipr_template
1589
+ return <<PROJECT_XML
1590
+ <?xml version="1.0" encoding="UTF-8"?>
1591
+ <project version="4">
1592
+ <component name="SvnBranchConfigurationManager">
1593
+ <option name="mySupportsUserInfoFilter" value="false" />
1594
+ </component>
1595
+ </project>
1596
+ PROJECT_XML
1597
+ end
1598
+
1599
+ def ipr_existing
1600
+ return <<PROJECT_XML
1601
+ <?xml version="1.0" encoding="UTF-8"?>
1602
+ <project version="4">
1603
+ <component name="AntConfiguration">
1604
+ <defaultAnt bundledAnt="true" />
1605
+ </component>
1606
+ <component name="SvnBranchConfigurationManager">
1607
+ <option name="mySupportsUserInfoFilter" value="true" />
1608
+ </component>
1609
+ <component name="ProjectModuleManager">
1610
+ <modules>
1611
+ <module fileurl="file://$PROJECT_DIR$/existing.iml" filepath="$PROJECT_DIR$/existing.iml" />
1612
+ </modules>
1613
+ </component>
1614
+ </project>
1615
+ PROJECT_XML
1616
+ end
1617
+
1618
+ def ipr_from_template_xpath
1619
+ "/project/component[@name='SvnBranchConfigurationManager']/option[@name = 'mySupportsUserInfoFilter' && @value = 'false']"
1620
+ end
1621
+
1622
+ def ipr_from_existing_xpath
1623
+ "/project/component[@name='AntConfiguration']"
1624
+ end
1625
+
1626
+ def ipr_from_existing_shadowing_template_xpath
1627
+ "/project/component[@name='SvnBranchConfigurationManager']/option[@name = 'mySupportsUserInfoFilter' && @value = 'true']"
1628
+ end
1629
+
1630
+ def ipr_from_existing_shadowing_generated_xpath
1631
+ "/project/component[@name='ProjectModuleManager']/modules/module[@fileurl = 'file://$PROJECT_DIR$/existing.iml']"
1632
+ end
1633
+
1634
+ def ipr_from_generated_xpath
1635
+ "/project/component[@name='ProjectModuleManager']/modules/module[@fileurl = 'file://$PROJECT_DIR$/foo.iml']"
1636
+ end
1637
+
1638
+ def iml_template
1639
+ return <<PROJECT_XML
1640
+ <?xml version="1.0" encoding="UTF-8"?>
1641
+ <module type="JAVA_MODULE" version="4">
1642
+ <component name="FacetManager">
1643
+ <facet type="JRUBY" name="JRuby">
1644
+ <configuration number="0">
1645
+ <JRUBY_FACET_CONFIG_ID NAME="JRUBY_SDK_NAME" VALUE="JRuby SDK 1.4.0RC1" />
1646
+ </configuration>
1647
+ </facet>
1648
+ </component>
1649
+ </module>
1650
+ PROJECT_XML
1651
+ end
1652
+
1653
+ def iml_existing
1654
+ return <<PROJECT_XML
1655
+ <?xml version="1.0" encoding="UTF-8"?>
1656
+ <module type="JAVA_MODULE" version="4">
1657
+ <component name="FunkyPlugin"/>
1658
+ <component name="FacetManager">
1659
+ <facet type="SCALA" name="Scala"/>
1660
+ </component>
1661
+ <component name="NewModuleRootManager" inherit-compiler-output="true">
1662
+ <exclude-output />
1663
+ <content url="file://$MODULE_DIR$"/>
1664
+ <orderEntry type="inheritedJdk" />
1665
+ <orderEntry type="sourceFolder" forTests="false" />
1666
+ <orderEntry type="module" module-name="buildr-bnd" exported="" />
1667
+ </component>
1668
+ </module>
1669
+ PROJECT_XML
1670
+ end
1671
+
1672
+ def iml_from_template_xpath
1673
+ "/module/component[@name='FacetManager']/facet[@type = 'JRUBY']"
1674
+ end
1675
+
1676
+ def iml_from_existing_xpath
1677
+ "/module/component[@name='FunkyPlugin']"
1678
+ end
1679
+
1680
+ def iml_from_existing_shadowing_template_xpath
1681
+ "/module/component[@name='FacetManager']/facet[@type = 'SCALA']"
1682
+ end
1683
+
1684
+ def iml_from_existing_shadowing_generated_xpath
1685
+ "/module/component[@name='NewModuleRootManager']/orderEntry[@module-name = 'buildr-bnd']"
1686
+ end
1687
+
1688
+ def iml_from_generated_xpath
1689
+ "/module/component[@name='NewModuleRootManager']/orderEntry[@type = 'module-library']"
1690
+ end
1691
+
1692
+ describe "with existing project files" do
1693
+ before do
1694
+ write "foo.ipr", ipr_existing
1695
+ write "foo.iml", iml_existing
1696
+ artifact('group:id:jar:1.0') { |t| write t.to_s }
1697
+ @foo = define "foo" do
1698
+ ipr.template = nil
1699
+ iml.template = nil
1700
+ compile.with 'group:id:jar:1.0'
1701
+ end
1702
+ invoke_generate_task
1703
+ end
1704
+
1705
+ it "replaces ProjectModuleManager component in existing ipr file" do
1706
+ xml_document(@foo._("foo.ipr")).should have_xpath(ipr_from_generated_xpath)
1707
+ xml_document(@foo._("foo.ipr")).should_not have_xpath(ipr_from_existing_shadowing_generated_xpath)
1708
+ end
1709
+
1710
+ it "merges component in existing ipr file" do
1711
+ xml_document(@foo._("foo.ipr")).should have_xpath(ipr_from_existing_xpath)
1712
+ end
1713
+
1714
+ def iml_from_generated_xpath
1715
+ "/module/component[@name='NewModuleRootManager']/orderEntry[@type = 'module-library']"
1716
+ end
1717
+
1718
+ it "replaces NewModuleRootManager component in existing iml file" do
1719
+ xml_document(@foo._("foo.iml")).should have_xpath(iml_from_generated_xpath)
1720
+ xml_document(@foo._("foo.iml")).should_not have_xpath(iml_from_existing_shadowing_generated_xpath)
1721
+ end
1722
+
1723
+ it "merges component in existing iml file" do
1724
+ xml_document(@foo._("foo.iml")).should have_xpath(iml_from_existing_xpath)
1725
+ end
1726
+ end
1727
+
1728
+ describe "with an iml template" do
1729
+ before do
1730
+ write "module.template.iml", iml_template
1731
+ artifact('group:id:jar:1.0') { |t| write t.to_s }
1732
+ @foo = define "foo" do
1733
+ ipr.template = nil
1734
+ iml.template = "module.template.iml"
1735
+ compile.with 'group:id:jar:1.0'
1736
+ end
1737
+ invoke_generate_task
1738
+ end
1739
+
1740
+ it "replaces generated components" do
1741
+ xml_document(@foo._("foo.iml")).should have_xpath(iml_from_generated_xpath)
1742
+ end
1743
+
1744
+ it "merges component in iml template" do
1745
+ xml_document(@foo._("foo.iml")).should have_xpath(iml_from_template_xpath)
1746
+ end
1747
+ end
1748
+
1749
+ describe "with an iml template and existing iml" do
1750
+ before do
1751
+ write "module.template.iml", iml_template
1752
+ write "foo.iml", iml_existing
1753
+ artifact('group:id:jar:1.0') { |t| write t.to_s }
1754
+ @foo = define "foo" do
1755
+ ipr.template = nil
1756
+ iml.template = "module.template.iml"
1757
+ compile.with 'group:id:jar:1.0'
1758
+ end
1759
+ invoke_generate_task
1760
+ end
1761
+
1762
+ it "replaces generated components" do
1763
+ xml_document(@foo._("foo.iml")).should have_xpath(iml_from_generated_xpath)
1764
+ end
1765
+
1766
+ it "merges component in iml template" do
1767
+ xml_document(@foo._("foo.iml")).should have_xpath(iml_from_template_xpath)
1768
+ end
1769
+
1770
+ it "merges components not in iml template and not generated by task" do
1771
+ xml_document(@foo._("foo.iml")).should have_xpath(iml_from_existing_xpath)
1772
+ xml_document(@foo._("foo.iml")).should_not have_xpath(iml_from_existing_shadowing_template_xpath)
1773
+ xml_document(@foo._("foo.iml")).should_not have_xpath(iml_from_existing_shadowing_generated_xpath)
1774
+ end
1775
+ end
1776
+
1777
+ describe "with an ipr template" do
1778
+ before do
1779
+ write "project.template.iml", ipr_template
1780
+ artifact('group:id:jar:1.0') { |t| write t.to_s }
1781
+ @foo = define "foo" do
1782
+ ipr.template = "project.template.iml"
1783
+ iml.template = nil
1784
+ compile.with 'group:id:jar:1.0'
1785
+ end
1786
+ invoke_generate_task
1787
+ end
1788
+
1789
+ it "replaces generated component in ipr template" do
1790
+ xml_document(@foo._("foo.ipr")).should have_xpath(ipr_from_generated_xpath)
1791
+ end
1792
+
1793
+ it "merges component in ipr template" do
1794
+ xml_document(@foo._("foo.ipr")).should have_xpath(ipr_from_template_xpath)
1795
+ end
1796
+ end
1797
+
1798
+ describe "with an ipr template and existing ipr" do
1799
+ before do
1800
+ write "project.template.iml", ipr_template
1801
+ write "foo.ipr", ipr_existing
1802
+ artifact('group:id:jar:1.0') { |t| write t.to_s }
1803
+ @foo = define "foo" do
1804
+ ipr.template = "project.template.iml"
1805
+ iml.template = nil
1806
+ compile.with 'group:id:jar:1.0'
1807
+ end
1808
+ invoke_generate_task
1809
+ end
1810
+
1811
+ it "replaces generated component in ipr template" do
1812
+ xml_document(@foo._("foo.ipr")).should have_xpath(ipr_from_generated_xpath)
1813
+ end
1814
+
1815
+ it "merges component in ipr template" do
1816
+ xml_document(@foo._("foo.ipr")).should have_xpath(ipr_from_template_xpath)
1817
+ end
1818
+
1819
+ it "merges components not in ipr template and not generated by task" do
1820
+ xml_document(@foo._("foo.ipr")).should have_xpath(ipr_from_existing_xpath)
1821
+ xml_document(@foo._("foo.ipr")).should_not have_xpath(ipr_from_existing_shadowing_generated_xpath)
1822
+ xml_document(@foo._("foo.ipr")).should have_xpath(ipr_from_existing_shadowing_template_xpath)
1823
+ end
1824
+ end
1825
+ end
1826
+ end
1827
+
1828
+ describe "Buildr::IntellijIdea::IdeaModule" do
1829
+
1830
+ describe "with no settings" do
1831
+ before do
1832
+ @foo = define "foo"
1833
+ end
1834
+
1835
+ it "has correct default iml.type setting" do
1836
+ @foo.iml.type.should == "JAVA_MODULE"
1837
+ end
1838
+
1839
+ it "has correct default iml.local_repository_env_override setting" do
1840
+ @foo.iml.local_repository_env_override.should == "MAVEN_REPOSITORY"
1841
+ end
1842
+ end
1843
+
1844
+ describe "settings inherited in subprojects" do
1845
+ before do
1846
+ mkdir_p 'bar'
1847
+ @foo = define "foo" do
1848
+ iml.type = "FOO_MODULE_TYPE"
1849
+ define 'bar'
1850
+ end
1851
+ invoke_generate_task
1852
+ end
1853
+
1854
+ it "generates root IML with specified type" do
1855
+ module_file = root_module_filename(@foo)
1856
+ File.should be_exist(module_file)
1857
+ File.read(module_file).should =~ /FOO_MODULE_TYPE/
1858
+ end
1859
+
1860
+ it "generates subproject IML with inherited type" do
1861
+ module_file = subproject_module_filename(@foo, "bar")
1862
+ File.should be_exist(module_file)
1863
+ File.read(module_file).should =~ /FOO_MODULE_TYPE/
1864
+ end
1865
+
1866
+ end
1867
+ end
1868
+
1869
+ describe "project extension" do
1870
+ it "provides an 'idea' task" do
1871
+ Rake::Task.tasks.detect { |task| task.to_s == "idea" }.should_not be_nil
1872
+ end
1873
+
1874
+ it "documents the 'idea' task" do
1875
+ Rake::Task.tasks.detect { |task| task.to_s == "idea" }.comment.should_not be_nil
1876
+ end
1877
+
1878
+ it "provides an 'idea:clean' task" do
1879
+ Rake::Task.tasks.detect { |task| task.to_s == "idea:clean" }.should_not be_nil
1880
+ end
1881
+
1882
+ it "documents the 'idea:clean' task" do
1883
+ Rake::Task.tasks.detect { |task| task.to_s == "idea:clean" }.comment.should_not be_nil
1884
+ end
1885
+
1886
+ describe "#no_iml" do
1887
+ it "makes #iml? false" do
1888
+ @foo = define "foo" do
1889
+ project.no_iml
1890
+ end
1891
+ @foo.iml?.should be_false
1892
+ end
1893
+ end
1894
+
1895
+ describe "#iml" do
1896
+ before do
1897
+ define "foo" do
1898
+ iml.suffix = "-top"
1899
+
1900
+ define "bar" do
1901
+ iml.suffix = "-mid"
1902
+
1903
+ define "baz" do
1904
+ end
1905
+ end
1906
+ end
1907
+ end
1908
+
1909
+ it "inherits the direct parent's IML settings" do
1910
+ project('foo:bar:baz').iml.suffix.should == "-mid"
1911
+ end
1912
+
1913
+ it "does not modify the parent's IML settings" do
1914
+ project('foo').iml.suffix.should == "-top"
1915
+ end
1916
+
1917
+ it "works even when the parent has no IML" do
1918
+ lambda {
1919
+ define "a" do
1920
+ project.no_iml
1921
+ define "b" do
1922
+ iml.suffix = "-alone"
1923
+ end
1924
+ end
1925
+ }.should_not raise_error
1926
+ end
1927
+
1928
+ it "inherits from the first ancestor which has an IML" do
1929
+ define "a" do
1930
+ iml.suffix = "-a"
1931
+ define "b" do
1932
+ iml.suffix = "-b"
1933
+ define "c" do
1934
+ project.no_iml
1935
+ define "d" do
1936
+ project.no_iml
1937
+ define "e" do
1938
+ project.no_iml
1939
+ define "f" do
1940
+ end
1941
+ end
1942
+ end
1943
+ end
1944
+ end
1945
+ end
1946
+
1947
+ project("a:b:c:d:e:f").iml.suffix.should == "-b"
1948
+ end
1949
+ end
1950
+ end
1951
+
1952
+ end