buildr 1.4.4-x86-mswin32 → 1.4.5-x86-mswin32

Sign up to get free protection for your applications and to get access to all the features.
Files changed (103) hide show
  1. data/CHANGELOG +46 -0
  2. data/Rakefile +0 -1
  3. data/addon/buildr/bnd.rb +147 -0
  4. data/addon/buildr/jaxb_xjc.rb +72 -0
  5. data/addon/buildr/protobuf.rb +14 -1
  6. data/buildr.gemspec +6 -2
  7. data/doc/artifacts.textile +6 -0
  8. data/doc/contributing.textile +3 -0
  9. data/doc/download.textile +60 -0
  10. data/doc/index.textile +9 -15
  11. data/doc/installing.textile +23 -6
  12. data/doc/mailing_lists.textile +4 -0
  13. data/doc/more_stuff.textile +333 -6
  14. data/doc/packaging.textile +187 -1
  15. data/lib/buildr.rb +8 -1
  16. data/lib/buildr/clojure.rb +34 -0
  17. data/lib/buildr/clojure/shell.rb +52 -0
  18. data/lib/buildr/core.rb +3 -0
  19. data/lib/buildr/core/#application.rb# +700 -0
  20. data/lib/buildr/core/application.rb +18 -8
  21. data/lib/buildr/core/build.rb +2 -2
  22. data/lib/buildr/core/cc.rb +57 -63
  23. data/lib/buildr/core/checks.rb +4 -5
  24. data/lib/buildr/core/doc.rb +3 -1
  25. data/lib/buildr/core/generate.rb +2 -0
  26. data/lib/buildr/core/jrebel.rb +42 -0
  27. data/lib/buildr/core/linux.rb +30 -0
  28. data/lib/buildr/core/project.rb +9 -8
  29. data/lib/buildr/core/run.rb +3 -3
  30. data/lib/buildr/core/shell.rb +29 -90
  31. data/lib/buildr/core/test.rb +3 -3
  32. data/lib/buildr/core/transports.rb +5 -5
  33. data/lib/buildr/core/util.rb +2 -2
  34. data/lib/buildr/groovy.rb +1 -0
  35. data/lib/buildr/groovy/compiler.rb +12 -1
  36. data/lib/buildr/groovy/doc.rb +76 -0
  37. data/lib/buildr/groovy/shell.rb +24 -15
  38. data/lib/buildr/ide.rb +1 -1
  39. data/lib/buildr/ide/idea.rb +527 -141
  40. data/lib/buildr/java/bdd.rb +18 -13
  41. data/lib/buildr/java/ecj.rb +1 -3
  42. data/lib/buildr/java/jtestr_result.rb +295 -0
  43. data/lib/buildr/java/jtestr_runner.rb.erb +4 -6
  44. data/lib/buildr/java/packaging.rb +14 -3
  45. data/lib/buildr/java/pom.rb +6 -2
  46. data/lib/buildr/java/test_result.rb +15 -243
  47. data/lib/buildr/java/tests.rb +1 -1
  48. data/lib/buildr/packaging.rb +2 -1
  49. data/lib/buildr/packaging/#package.rb.rej# +19 -0
  50. data/lib/buildr/packaging/archive.rb +13 -3
  51. data/lib/buildr/packaging/artifact.rb +11 -12
  52. data/lib/buildr/packaging/tar.rb +4 -1
  53. data/lib/buildr/packaging/zip.rb +106 -1
  54. data/lib/buildr/resources/completed.png +0 -0
  55. data/lib/buildr/resources/failed.png +0 -0
  56. data/lib/buildr/resources/icons-license.txt +17 -0
  57. data/lib/buildr/run.rb +7 -14
  58. data/lib/buildr/scala/#Untitled-2# +7 -0
  59. data/lib/buildr/scala/bdd.rb +1 -1
  60. data/lib/buildr/scala/compiler.rb +1 -1
  61. data/lib/buildr/scala/doc.rb +20 -2
  62. data/lib/buildr/scala/shell.rb +14 -22
  63. data/lib/buildr/scala/tests.rb +2 -2
  64. data/lib/buildr/shell.rb +113 -108
  65. data/lib/buildr/version.rb +1 -1
  66. data/rakelib/checks.rake +9 -7
  67. data/rakelib/doc.rake +10 -0
  68. data/rakelib/release.rake +9 -0
  69. data/rakelib/rspec.rake +27 -28
  70. data/rakelib/setup.rake +1 -1
  71. data/rakelib/stage.rake +2 -2
  72. data/spec/addon/bnd_spec.rb +330 -0
  73. data/spec/addon/jaxb_xjc_spec.rb +125 -0
  74. data/spec/core/application_spec.rb +1 -1
  75. data/spec/core/build_spec.rb +7 -7
  76. data/spec/core/cc_spec.rb +154 -104
  77. data/spec/core/compile_spec.rb +3 -3
  78. data/spec/core/project_spec.rb +10 -0
  79. data/spec/core/run_spec.rb +1 -0
  80. data/spec/core/shell_spec.rb +146 -0
  81. data/spec/groovy/doc_spec.rb +65 -0
  82. data/spec/ide/eclipse_spec.rb +1 -1
  83. data/spec/ide/idea_spec.rb +1145 -0
  84. data/spec/java/bdd_spec.rb +3 -3
  85. data/spec/java/emma_spec.rb +2 -0
  86. data/spec/java/packaging_spec.rb +40 -11
  87. data/spec/java/test_coverage_helper.rb +1 -1
  88. data/spec/packaging/archive_spec.rb +76 -21
  89. data/spec/packaging/artifact_namespace_spec.rb +1 -1
  90. data/spec/packaging/artifact_spec.rb +14 -7
  91. data/spec/sandbox.rb +11 -4
  92. data/spec/scala/bdd_spec.rb +2 -2
  93. data/spec/scala/compiler_spec.rb +2 -2
  94. data/spec/scala/doc_spec.rb +24 -4
  95. data/spec/scala/scala.rb +2 -2
  96. data/spec/scala/tests_spec.rb +2 -2
  97. data/spec/spec_helpers.rb +9 -8
  98. data/spec/xpath_matchers.rb +121 -0
  99. metadata +246 -166
  100. data/lib/buildr/ide/idea.ipr.template +0 -300
  101. data/lib/buildr/ide/idea7x.ipr.template +0 -290
  102. data/lib/buildr/ide/idea7x.rb +0 -231
  103. data/spec/ide/idea7x_spec.rb +0 -96
@@ -106,9 +106,9 @@ describe Buildr::CompileTask do
106
106
  write "src/main/java/com/example/Hello.java", ""
107
107
  old_compiler = nil
108
108
  new_compiler = nil
109
- define('foo') {
109
+ define('foo') {
110
110
  old_compiler = compile.compiler
111
- compile.using(:scalac)
111
+ compile.using(:scalac)
112
112
  new_compiler = compile.compiler
113
113
  }
114
114
  old_compiler.should == :javac
@@ -416,7 +416,7 @@ describe Buildr::CompileTask, '#invoke' do
416
416
  end
417
417
 
418
418
 
419
- describe 'accessor task', :shared=>true do
419
+ shared_examples_for 'accessor task' do
420
420
  it 'should return a task' do
421
421
  define('foo').send(@task_name).should be_kind_of(Rake::Task)
422
422
  end
@@ -499,6 +499,16 @@ describe Buildr, '#project' do
499
499
  project('foo').should be(foo)
500
500
  end
501
501
 
502
+ it 'should define a project if a block is given' do
503
+ foo = project('foo') {}
504
+ project('foo').should be(foo)
505
+ end
506
+
507
+ it 'should define a project if properties and a block are given' do
508
+ foo = project('foo', :version => '1.2') {}
509
+ project('foo').should be(foo)
510
+ end
511
+
502
512
  it 'should find a project by its full name' do
503
513
  bar, baz = nil
504
514
  define('foo') { bar = define('bar') { baz = define('baz') } }
@@ -67,6 +67,7 @@ describe Project, :run do
67
67
  it 'should depend on project''s compile and test.compile task' do
68
68
  define 'foo'
69
69
  project('foo').run.prerequisites.should include(project('foo').compile)
70
+ project('foo').run.prerequisites.should include(project('foo').test)
70
71
  end
71
72
 
72
73
  it 'should be local task' do
@@ -0,0 +1,146 @@
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.expand_path(File.join(File.dirname(__FILE__), '..', 'spec_helpers'))
17
+
18
+ describe Project, '.shell' do
19
+
20
+ it 'should return the project\'s shell task' do
21
+ define('foo')
22
+ project('foo').shell.name.should eql('foo:shell')
23
+ end
24
+
25
+ it 'should return a ShellTask' do
26
+ define('foo')
27
+ project('foo').shell.should be_kind_of(Shell::ShellTask)
28
+ end
29
+
30
+ it 'should include compile and test.compile dependencies' do
31
+ define('foo') do
32
+ compile.using(:javac).with 'group:compile:jar:1.0'
33
+ test.compile.using(:javac).with 'group:test:jar:1.0'
34
+ end
35
+ project('foo').shell.classpath.should include(artifact('group:compile:jar:1.0'))
36
+ project('foo').shell.classpath.should include(artifact('group:test:jar:1.0'))
37
+ end
38
+
39
+ it 'should respond to using() and return self' do
40
+ define 'foo' do
41
+ shell.using(:foo=>'Fooing').should be(shell)
42
+ end
43
+ end
44
+
45
+ it 'should respond to using() and accept options' do
46
+ define 'foo' do
47
+ shell.using :foo=>'Fooing'
48
+ end
49
+ project('foo').shell.options[:foo].should eql('Fooing')
50
+ end
51
+
52
+ it 'should select provider using shell.using' do
53
+ define 'foo' do
54
+ shell.using :bsh
55
+ end
56
+ project('foo').shell.provider.should be_a(Shell::BeanShell)
57
+ end
58
+
59
+ it 'should select runner based on compile language' do
60
+ write 'src/main/java/Test.java', 'class Test {}'
61
+ define 'foo' do
62
+ # compile language detected as :java
63
+ end
64
+ project('foo').shell.provider.should be_a(Shell::BeanShell)
65
+ end
66
+
67
+ it 'should depend on project''s compile task' do
68
+ define 'foo'
69
+ project('foo').shell.prerequisites.should include(project('foo').compile)
70
+ end
71
+
72
+ it 'should be local task' do
73
+ define 'foo' do
74
+ define('bar') do
75
+ shell.using :bsh
76
+ end
77
+ end
78
+ task = project('foo:bar').shell
79
+ task.should_receive(:invoke_prerequisites)
80
+ task.should_receive(:run)
81
+ in_original_dir(project('foo:bar').base_dir) { task('shell').invoke }
82
+ end
83
+
84
+ it 'should not recurse' do
85
+ define 'foo' do
86
+ shell.using :bsh
87
+ define('bar') { shell.using :bsh }
88
+ end
89
+ project('foo:bar').shell.should_not_receive(:invoke_prerequisites)
90
+ project('foo:bar').shell.should_not_receive(:run)
91
+ project('foo').shell.should_receive(:run)
92
+ project('foo').shell.invoke
93
+ end
94
+
95
+ it 'should call shell provider with task configuration' do
96
+ define 'foo' do
97
+ shell.using :bsh
98
+ end
99
+ shell = project('foo').shell
100
+ shell.provider.should_receive(:launch).with(shell)
101
+ project('foo').shell.invoke
102
+ end
103
+ end
104
+
105
+ shared_examples_for "shell provider" do
106
+
107
+ it 'should have launch method accepting shell task' do
108
+ @instance.method(:launch).should_not be_nil
109
+ @instance.method(:launch).arity.should === 1
110
+ end
111
+
112
+ end
113
+
114
+ Shell.providers.each do |provider|
115
+ describe provider do
116
+ before do
117
+ @provider = provider
118
+ @project = define('foo') {}
119
+ @instance = provider.new(@project)
120
+ @project.shell.using @provider.to_sym
121
+ end
122
+
123
+ it_should_behave_like "shell provider"
124
+
125
+ it 'should call Java::Commands.java with :java_args' do
126
+ @project.shell.using :java_args => ["-Xx"]
127
+ Java::Commands.should_receive(:java).with do |*args|
128
+ args.last.should be_a(Hash)
129
+ args.last.keys.should include(:java_args)
130
+ args.last[:java_args].should include('-Xx')
131
+ end
132
+ project('foo').shell.invoke
133
+ end
134
+
135
+ it 'should call Java::Commands.java with :properties' do
136
+ @project.shell.using :properties => {:foo => "bar"}
137
+ Java::Commands.should_receive(:java).with do |*args|
138
+ args.last.should be_a(Hash)
139
+ args.last.keys.should include(:properties)
140
+ args.last[:properties][:foo].should == "bar"
141
+ end
142
+ project('foo').shell.invoke
143
+ end
144
+ end
145
+ end
146
+
@@ -0,0 +1,65 @@
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
+
19
+ describe "Groovydoc" do
20
+
21
+ it 'should pick :windowtitle from project name by default' do
22
+ define 'foo' do
23
+ doc.using :groovydoc
24
+
25
+ define 'bar' do
26
+ doc.using :groovydoc
27
+ end
28
+ end
29
+
30
+ project('foo').doc.options[:windowtitle].should eql('foo')
31
+ project('foo:bar').doc.options[:windowtitle].should eql('foo:bar')
32
+ end
33
+
34
+ it 'should pick :windowtitle from project description by default, if available' do
35
+ desc 'My App'
36
+ define 'foo' do
37
+ doc.using :groovydoc
38
+ end
39
+ project('foo').doc.options[:windowtitle].should eql('My App')
40
+ end
41
+
42
+ it 'should not override explicit :windowtitle option' do
43
+ define 'foo' do
44
+ doc.using :groovydoc
45
+ doc.using :windowtitle => 'explicit'
46
+ end
47
+ project('foo').doc.options[:windowtitle].should eql('explicit')
48
+ end
49
+
50
+ it 'should identify itself from groovy source directories' do
51
+ write 'src/main/groovy/some/A.java', 'package some; public class A {}'
52
+ write 'src/main/groovy/some/B.groovy', 'package some; public class B {}'
53
+ define('foo') do
54
+ doc.engine.should be_a(Buildr::Doc::Groovydoc)
55
+ end
56
+ end
57
+
58
+ it 'should produce Groovydocs' do
59
+ write 'src/main/groovy/some/A.java', 'package some; public class A {}'
60
+ write 'src/main/groovy/some/B.groovy', 'package some; public class B {}'
61
+ define('foo')
62
+ project('foo').doc.invoke
63
+ file('target/doc/index.html').should exist
64
+ end
65
+ end
@@ -382,7 +382,7 @@ MANIFEST
382
382
  write 'src/test/java/Test.java'
383
383
  end
384
384
 
385
- describe 'source', :shared=>true do
385
+ shared_examples_for 'source' do
386
386
  it 'should ignore CVS and SVN files' do
387
387
  define('foo')
388
388
  classpath_sources('excluding').each do |excluding_attribute|
@@ -0,0 +1,1145 @@
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
+ describe Buildr::IntellijIdea do
21
+
22
+ def invoke_generate_task
23
+ task('idea:generate').invoke
24
+ end
25
+
26
+ def invoke_clean_task
27
+ task('idea:clean').invoke
28
+ end
29
+
30
+ def root_project_filename(project)
31
+ project._("#{project.name}#{Buildr::IntellijIdea::IdeaFile::DEFAULT_SUFFIX}.ipr")
32
+ end
33
+
34
+ def root_project_xml(project)
35
+ xml_document(root_project_filename(project))
36
+ end
37
+
38
+ def root_module_filename(project)
39
+ project._("#{project.name}#{Buildr::IntellijIdea::IdeaFile::DEFAULT_SUFFIX}.iml")
40
+ end
41
+
42
+ def root_module_xml(project)
43
+ xml_document(root_module_filename(project))
44
+ end
45
+
46
+ def subproject_module_filename(project, sub_project_name)
47
+ project._("#{sub_project_name}/#{sub_project_name}#{Buildr::IntellijIdea::IdeaFile::DEFAULT_SUFFIX}.iml")
48
+ end
49
+
50
+ def subproject_module_xml(project, sub_project_name)
51
+ xml_document(subproject_module_filename(project, sub_project_name))
52
+ end
53
+
54
+ def xml_document(filename)
55
+ File.should be_exist(filename)
56
+ REXML::Document.new(File.read(filename))
57
+ end
58
+
59
+ def xpath_to_module
60
+ "/project/component[@name='ProjectModuleManager']/modules/module"
61
+ end
62
+
63
+ describe "idea:clean" do
64
+ before do
65
+ write "foo.ipr"
66
+ write "foo.iml"
67
+ write "other.ipr"
68
+ write "other.iml"
69
+ mkdir_p 'bar'
70
+ write "bar/bar.iml"
71
+ write "bar/other.ipr"
72
+ write "bar/other.iml"
73
+
74
+ @foo = define "foo" do
75
+ define "bar"
76
+ end
77
+ invoke_clean_task
78
+ end
79
+
80
+ it "should remove the ipr file" do
81
+ File.exists?("foo.ipr").should be_false
82
+ end
83
+
84
+ it "should remove the project iml file" do
85
+ File.exists?("foo.iml").should be_false
86
+ end
87
+
88
+ it "should remove the subproject iml file" do
89
+ File.exists?("foo.iml").should be_false
90
+ end
91
+
92
+ it "should not remove other iml and ipr files" do
93
+ File.exists?("other.ipr").should be_true
94
+ File.exists?("other.iml").should be_true
95
+ File.exists?("bar/other.ipr").should be_true
96
+ File.exists?("bar/other.iml").should be_true
97
+ end
98
+ end
99
+
100
+ describe "idea:generate" do
101
+
102
+ def order_entry_xpath
103
+ "/module/component[@name='NewModuleRootManager']/orderEntry"
104
+ end
105
+
106
+ describe "with a single dependency" do
107
+ describe "of type compile" do
108
+ before do
109
+ artifact('group:id:jar:1.0') { |t| write t.to_s }
110
+ @foo = define "foo" do
111
+ compile.with 'group:id:jar:1.0'
112
+ end
113
+ invoke_generate_task
114
+ end
115
+
116
+ it "generates one exported 'module-library' orderEntry in IML" do
117
+ root_module_xml(@foo).should have_nodes("#{order_entry_xpath}[@type='module-library', @exported='']/library/CLASSES/root", 1)
118
+ end
119
+ end
120
+
121
+ describe "with iml.main_dependencies override" do
122
+ before do
123
+ artifact('group:id:jar:1.0') { |t| write t.to_s }
124
+ @foo = define "foo" do
125
+ iml.main_dependencies << 'group:id:jar:1.0'
126
+ end
127
+ invoke_generate_task
128
+ end
129
+
130
+ it "generates one exported 'module-library' orderEntry in IML" do
131
+ root_module_xml(@foo).should have_nodes("#{order_entry_xpath}[@type='module-library', @exported='']/library/CLASSES/root", 1)
132
+ end
133
+ end
134
+
135
+ describe "of type test" do
136
+ before do
137
+ artifact('group:id:jar:1.0') { |t| write t.to_s }
138
+ @foo = define "foo" do
139
+ test.with 'group:id:jar:1.0'
140
+ end
141
+ invoke_generate_task
142
+ end
143
+
144
+ it "generates one non-exported 'module-library' orderEntry in IML" do
145
+ root_module_xml(@foo).should have_nodes("#{order_entry_xpath}[@type='module-library' and @exported]/library/CLASSES/root", 0)
146
+ root_module_xml(@foo).should have_nodes("#{order_entry_xpath}[@type='module-library']/library/CLASSES/root", 1)
147
+ end
148
+ end
149
+
150
+ describe "with iml.test_dependencies override" do
151
+ before do
152
+ artifact('group:id:jar:1.0') { |t| write t.to_s }
153
+ @foo = define "foo" do
154
+ iml.test_dependencies << 'group:id:jar:1.0'
155
+ end
156
+ invoke_generate_task
157
+ end
158
+
159
+ it "generates one non-exported 'module-library' orderEntry in IML" do
160
+ root_module_xml(@foo).should have_nodes("#{order_entry_xpath}[@type='module-library' and @exported]/library/CLASSES/root", 0)
161
+ root_module_xml(@foo).should have_nodes("#{order_entry_xpath}[@type='module-library']/library/CLASSES/root", 1)
162
+ end
163
+ end
164
+
165
+ describe "with sources artifact present" do
166
+ before do
167
+ artifact('group:id:jar:1.0') { |t| write t.to_s }
168
+ artifact('group:id:jar:sources:1.0') { |t| write t.to_s }
169
+ @foo = define "foo" do
170
+ compile.with 'group:id:jar:1.0'
171
+ end
172
+ invoke_generate_task
173
+ end
174
+
175
+ it "generates 'module-library' orderEntry in IML with SOURCES specified" do
176
+ root_module_xml(@foo).should have_nodes("#{order_entry_xpath}[@type='module-library', @exported='']/library/SOURCES/root", 1)
177
+ end
178
+ end
179
+
180
+ describe "with local_repository_env_override set to nil" do
181
+ before do
182
+ artifact('group:id:jar:1.0') { |t| write t.to_s }
183
+ @foo = define "foo" do
184
+ iml.local_repository_env_override = nil
185
+ compile.with 'group:id:jar:1.0'
186
+ end
187
+ invoke_generate_task
188
+ end
189
+
190
+ it "generates orderEntry with absolute path for classes jar" do
191
+ root_module_xml(@foo).should match_xpath("#{order_entry_xpath}/library/CLASSES/root/@url",
192
+ "jar://$MODULE_DIR$/home/.m2/repository/group/id/1.0/id-1.0.jar!/")
193
+ end
194
+ end
195
+ describe "with local_repository_env_override set to MAVEN_REPOSITORY" do
196
+ before do
197
+ artifact('group:id:jar:1.0') { |t| write t.to_s }
198
+ @foo = define "foo" do
199
+ iml.local_repository_env_override = 'MAVEN_REPOSITORY'
200
+ compile.with 'group:id:jar:1.0'
201
+ end
202
+ invoke_generate_task
203
+ end
204
+
205
+ it "generates orderEntry with absolute path for classes jar" do
206
+ root_module_xml(@foo).should match_xpath("#{order_entry_xpath}/library/CLASSES/root/@url",
207
+ "jar://$MAVEN_REPOSITORY$/group/id/1.0/id-1.0.jar!/")
208
+ end
209
+ end
210
+ end
211
+
212
+ describe "with multiple dependencies" do
213
+ before do
214
+ artifact('group:id:jar:1.0') { |t| write t.to_s }
215
+ artifact('group:id2:jar:1.0') { |t| write t.to_s }
216
+ @foo = define "foo" do
217
+ compile.with 'group:id:jar:1.0', 'group:id2:jar:1.0'
218
+ end
219
+ invoke_generate_task
220
+ end
221
+
222
+ it "generates multiple 'module-library' orderEntry in IML" do
223
+ root_module_xml(@foo).should have_nodes("#{order_entry_xpath}[@type='module-library']", 2)
224
+ end
225
+ end
226
+
227
+ describe "with a single non artifact dependency" do
228
+ before do
229
+ @foo = define "foo" do
230
+ filename = _("foo-dep.jar")
231
+ File.open(filename, "wb") { |t| write "Hello" }
232
+ compile.with filename
233
+ end
234
+ invoke_generate_task
235
+ end
236
+
237
+ it "generates one exported 'module-library' orderEntry in IML" do
238
+ root_module_xml(@foo).should match_xpath("#{order_entry_xpath}/library/CLASSES/root/@url",
239
+ "jar://$MODULE_DIR$/foo-dep.jar!/")
240
+ end
241
+ end
242
+
243
+ describe "with extra_modules specified" do
244
+ before do
245
+ @foo = define "foo" do
246
+ ipr.extra_modules << 'other.iml'
247
+ ipr.extra_modules << 'other_other.iml'
248
+ end
249
+ invoke_generate_task
250
+ end
251
+
252
+ it "generate an IPR with extra modules specified" do
253
+ doc = xml_document(@foo._("foo.ipr"))
254
+ doc.should have_nodes("#{xpath_to_module}", 3)
255
+ module_ref = "$PROJECT_DIR$/foo.iml"
256
+ doc.should have_xpath("#{xpath_to_module}[@fileurl='file://#{module_ref}', @filepath='#{module_ref}']")
257
+ module_ref = "$PROJECT_DIR$/other.iml"
258
+ doc.should have_xpath("#{xpath_to_module}[@fileurl='file://#{module_ref}', @filepath='#{module_ref}']")
259
+ module_ref = "$PROJECT_DIR$/other_other.iml"
260
+ doc.should have_xpath("#{xpath_to_module}[@fileurl='file://#{module_ref}', @filepath='#{module_ref}']")
261
+ end
262
+ end
263
+
264
+ describe "with web and webservice facet added to root project" do
265
+ before do
266
+ @foo = define "foo" do
267
+ iml.add_facet("Web", "web") do |facet|
268
+ facet.configuration do |conf|
269
+ conf.descriptors do |desc|
270
+ desc.deploymentDescriptor :name => 'web.xml',
271
+ :url => "file://$MODULE_DIR$/src/main/webapp/WEB-INF/web.xml",
272
+ :optional => "false", :version => "2.4"
273
+ end
274
+ conf.webroots do |webroots|
275
+ webroots.root :url => "file://$MODULE_DIR$/src/main/webapp", :relative => "/"
276
+ end
277
+ end
278
+ end
279
+ iml.add_facet("WebServices Client", "WebServicesClient") do |facet|
280
+ facet.configuration "ws.engine" => "Glassfish / JAX-WS 2.X RI / Metro 1.X / JWSDP 2.0"
281
+ end
282
+ define 'bar'
283
+ end
284
+ invoke_generate_task
285
+ end
286
+
287
+ it "generates an IML for root project with a web and webservice facet" do
288
+ doc = xml_document(@foo._("foo.iml"))
289
+ facet_xpath = "/module/component[@name='FacetManager']/facet"
290
+ doc.should have_nodes(facet_xpath, 2)
291
+ doc.should have_xpath("#{facet_xpath}[@type='web', @name='Web']")
292
+ doc.should have_xpath("#{facet_xpath}[@type='WebServicesClient', @name='WebServices Client']")
293
+ end
294
+ end
295
+
296
+ describe "with iml.group specified" do
297
+ before do
298
+ @foo = define "foo" do
299
+ iml.group = true
300
+ define 'bar' do
301
+ define 'baz' do
302
+
303
+ end
304
+ end
305
+ define 'rab' do
306
+ iml.group = "MyGroup"
307
+ end
308
+ end
309
+ invoke_generate_task
310
+ end
311
+
312
+ it "generate an IPR with correct group references" do
313
+ doc = xml_document(@foo._("foo.ipr"))
314
+ doc.should have_nodes("#{xpath_to_module}", 4)
315
+ module_ref = "$PROJECT_DIR$/foo.iml"
316
+ doc.should have_xpath("#{xpath_to_module}[@fileurl='file://#{module_ref}', @filepath='#{module_ref}']")
317
+ module_ref = "$PROJECT_DIR$/rab/rab.iml"
318
+ doc.should have_xpath("#{xpath_to_module}[@fileurl='file://#{module_ref}', @filepath='#{module_ref}' @group = 'MyGroup']")
319
+ module_ref = "$PROJECT_DIR$/bar/bar.iml"
320
+ doc.should have_xpath("#{xpath_to_module}[@fileurl='file://#{module_ref}', @filepath='#{module_ref}' @group = 'foo']")
321
+ module_ref = "$PROJECT_DIR$/bar/baz/baz.iml"
322
+ doc.should have_xpath("#{xpath_to_module}[@fileurl='file://#{module_ref}', @filepath='#{module_ref}' @group = 'foo/bar']")
323
+ end
324
+ end
325
+
326
+ describe "with a single project definition" do
327
+ describe "and default naming" do
328
+ before do
329
+ @foo = define "foo"
330
+ invoke_generate_task
331
+ end
332
+
333
+ it "generates a single IPR" do
334
+ Dir[@foo._("**/*.ipr")].should have(1).entry
335
+ end
336
+
337
+ it "generate an IPR in the root directory" do
338
+ File.should be_exist(@foo._("foo.ipr"))
339
+ end
340
+
341
+ it "generates a single IML" do
342
+ Dir[@foo._("**/*.iml")].should have(1).entry
343
+ end
344
+
345
+ it "generates an IML in the root directory" do
346
+ File.should be_exist(@foo._("foo.iml"))
347
+ end
348
+
349
+ it "generate an IPR with the reference to correct module file" do
350
+ File.should be_exist(@foo._("foo.ipr"))
351
+ doc = xml_document(@foo._("foo.ipr"))
352
+ module_ref = "$PROJECT_DIR$/foo.iml"
353
+ doc.should have_nodes("#{xpath_to_module}[@fileurl='file://#{module_ref}', @filepath='#{module_ref}']", 1)
354
+ end
355
+ end
356
+
357
+ describe "with no_iml generation disabled" do
358
+ before do
359
+ @foo = define "foo" do
360
+ project.no_iml
361
+ end
362
+ invoke_generate_task
363
+ end
364
+
365
+ it "generates no IML" do
366
+ Dir[@foo._("**/*.iml")].should have(0).entry
367
+ end
368
+
369
+ it "generate an IPR with no references" do
370
+ File.should be_exist(@foo._("foo.ipr"))
371
+ doc = xml_document(@foo._("foo.ipr"))
372
+ doc.should have_nodes("#{xpath_to_module}", 0)
373
+ end
374
+ end
375
+
376
+ describe "with ipr generation disabled" do
377
+ before do
378
+ @foo = define "foo" do
379
+ project.no_ipr
380
+ end
381
+ invoke_generate_task
382
+ end
383
+
384
+ it "generates a single IML" do
385
+ Dir[@foo._("**/*.iml")].should have(1).entry
386
+ end
387
+
388
+ it "generate no IPR" do
389
+ File.should_not be_exist(@foo._("foo.ipr"))
390
+ end
391
+ end
392
+
393
+ describe "and id overrides" do
394
+ before do
395
+ @foo = define "foo" do
396
+ ipr.id = 'fooble'
397
+ iml.id = 'feap'
398
+ define "bar" do
399
+ iml.id = "baz"
400
+ end
401
+ end
402
+ invoke_generate_task
403
+ end
404
+
405
+ it "generate an IPR in the root directory" do
406
+ File.should be_exist(@foo._("fooble.ipr"))
407
+ end
408
+
409
+ it "generates an IML in the root directory" do
410
+ File.should be_exist(@foo._("feap.iml"))
411
+ end
412
+
413
+ it "generates an IML in the subproject directory" do
414
+ File.should be_exist(@foo._("bar/baz.iml"))
415
+ end
416
+
417
+ it "generate an IPR with the reference to correct module file" do
418
+ File.should be_exist(@foo._("fooble.ipr"))
419
+ doc = xml_document(@foo._("fooble.ipr"))
420
+ module_ref = "$PROJECT_DIR$/feap.iml"
421
+ doc.should have_nodes("#{xpath_to_module}[@fileurl='file://#{module_ref}', @filepath='#{module_ref}']", 1)
422
+ end
423
+ end
424
+
425
+ describe "and a suffix defined" do
426
+ before do
427
+ @foo = define "foo" do
428
+ ipr.suffix = '-ipr-suffix'
429
+ iml.suffix = '-iml-suffix'
430
+ end
431
+ invoke_generate_task
432
+ end
433
+
434
+ it "generate an IPR in the root directory" do
435
+ File.should be_exist(@foo._("foo-ipr-suffix.ipr"))
436
+ end
437
+
438
+ it "generates an IML in the root directory" do
439
+ File.should be_exist(@foo._("foo-iml-suffix.iml"))
440
+ end
441
+
442
+ it "generate an IPR with the reference to correct module file" do
443
+ File.should be_exist(@foo._("foo-ipr-suffix.ipr"))
444
+ doc = xml_document(@foo._("foo-ipr-suffix.ipr"))
445
+ doc.should have_nodes("#{xpath_to_module}", 1)
446
+ module_ref = "$PROJECT_DIR$/foo-iml-suffix.iml"
447
+ doc.should have_nodes("#{xpath_to_module}[@fileurl='file://#{module_ref}', @filepath='#{module_ref}']", 1)
448
+ end
449
+ end
450
+ end
451
+
452
+ describe "with a subproject" do
453
+ before do
454
+ @foo = define "foo" do
455
+ define 'bar'
456
+ end
457
+ invoke_generate_task
458
+ end
459
+
460
+ it "creates the subproject directory" do
461
+ File.should be_exist(@foo._("bar"))
462
+ end
463
+
464
+ it "generates an IML in the subproject directory" do
465
+ File.should be_exist(@foo._("bar/bar.iml"))
466
+ end
467
+
468
+ it "generate an IPR with the reference to correct module file" do
469
+ File.should be_exist(@foo._("foo.ipr"))
470
+ doc = xml_document(@foo._("foo.ipr"))
471
+ doc.should have_nodes("#{xpath_to_module}", 2)
472
+ module_ref = "$PROJECT_DIR$/foo.iml"
473
+ doc.should have_nodes("#{xpath_to_module}[@fileurl='file://#{module_ref}', @filepath='#{module_ref}']", 1)
474
+ module_ref = "$PROJECT_DIR$/bar/bar.iml"
475
+ doc.should have_nodes("#{xpath_to_module}[@fileurl='file://#{module_ref}', @filepath='#{module_ref}']", 1)
476
+ end
477
+ end
478
+
479
+ describe "with base_dir specified" do
480
+ before do
481
+ @foo = define "foo" do
482
+ define('bar', :base_dir => 'fe') do
483
+ define('baz', :base_dir => 'fi') do
484
+ define('foe')
485
+ end
486
+ define('fum')
487
+ end
488
+ end
489
+ invoke_generate_task
490
+ end
491
+
492
+ it "generates a subproject IML in the specified directory" do
493
+ File.should be_exist(@foo._("fe/bar.iml"))
494
+ end
495
+
496
+ it "generates a sub-subproject IML in the specified directory" do
497
+ File.should be_exist(@foo._("fi/baz.iml"))
498
+ end
499
+
500
+ it "generates a sub-sub-subproject IML that inherits the specified directory" do
501
+ File.should be_exist(@foo._("fi/foe/foe.iml"))
502
+ end
503
+
504
+ it "generates a sub-subproject IML that inherits the specified directory" do
505
+ File.should be_exist(@foo._("fe/fum/fum.iml"))
506
+ end
507
+
508
+ it "generate an IPR with the references to correct module files" do
509
+ doc = xml_document(@foo._("foo.ipr"))
510
+ doc.should have_nodes("#{xpath_to_module}", 5)
511
+ ["foo.iml", "fe/bar.iml", "fi/baz.iml", "fi/foe/foe.iml", "fe/fum/fum.iml"].each do |module_ref|
512
+ doc.should have_nodes("#{xpath_to_module}[@fileurl='file://$PROJECT_DIR$/#{module_ref}', @filepath='$PROJECT_DIR$/#{module_ref}']", 1)
513
+ end
514
+ end
515
+ end
516
+
517
+ describe "with extensive intermodule dependencies" do
518
+ before do
519
+ mkdir_p 'foo/src/main/resources'
520
+ mkdir_p 'foo/src/main/java/foo'
521
+ touch 'foo/src/main/java/foo/Foo.java' # needed so that buildr will treat as a java project
522
+ artifact('group:id:jar:1.0') { |t| write t.to_s }
523
+ define "root" do
524
+ repositories.remote << 'http://mirrors.ibiblio.org/pub/mirrors/maven2/'
525
+ project.version = "2.5.2"
526
+ define 'foo' do
527
+ resources.from _(:source, :main, :resources)
528
+ compile.with 'group:id:jar:1.0'
529
+ test.using(:junit)
530
+ package(:jar)
531
+ end
532
+
533
+ define 'bar' do
534
+ # internally transitive dependencies on foo, both runtime and test
535
+ compile.with project('root:foo'), project('root:foo').compile.dependencies
536
+ test.using(:junit).with [project('root:foo').test.compile.target,
537
+ project('root:foo').test.resources.target,
538
+ project('root:foo').test.compile.dependencies].compact
539
+ package(:jar)
540
+ end
541
+ end
542
+
543
+ invoke_generate_task
544
+ @bar_iml = xml_document(project('root:bar')._('bar.iml'))
545
+ @bar_lib_urls = @bar_iml.get_elements("//orderEntry[@type='module-library']/library/CLASSES/root").collect do |root|
546
+ root.attribute('url').to_s
547
+ end
548
+ end
549
+
550
+ it "depends on the associated module exactly once" do
551
+ @bar_iml.should have_nodes("//orderEntry[@type='module', @module-name='foo']", 1)
552
+ end
553
+
554
+ it "does not depend on the other project's packaged JAR" do
555
+ @bar_lib_urls.grep(%r{#{project('root:foo').packages.first}}).should == []
556
+ end
557
+
558
+ it "does not depend on the the other project's target/classes directory" do
559
+ @bar_lib_urls.grep(%r{foo/target/classes}).should == []
560
+ end
561
+
562
+ it "depends on the the other project's target/resources directory" do
563
+ @bar_lib_urls.grep(%r{file://\$MODULE_DIR\$/../foo/target/resources}).size.should == 1
564
+ end
565
+ end
566
+
567
+ describe "with a single project definition" do
568
+ before do
569
+ @foo = define "foo"
570
+ end
571
+
572
+ it "informs the user about generating IPR" do
573
+ lambda { invoke_generate_task }.should show_info(/Writing (.+)\/foo\.ipr/)
574
+ end
575
+
576
+ it "informs the user about generating IML" do
577
+ lambda { invoke_generate_task }.should show_info(/Writing (.+)\/foo\.iml/)
578
+ end
579
+ end
580
+ describe "with a subproject" do
581
+ before do
582
+ @foo = define "foo" do
583
+ define 'bar'
584
+ end
585
+ end
586
+
587
+ it "informs the user about generating subporoject IML" do
588
+ lambda { invoke_generate_task }.should show_info(/Writing (.+)\/bar\/bar\.iml/)
589
+ end
590
+ end
591
+
592
+ describe "with compile.options.source = '1.6'" do
593
+
594
+ before do
595
+ @foo = define "foo" do
596
+ compile.options.source = '1.5'
597
+ end
598
+ invoke_generate_task
599
+ end
600
+
601
+ it "generate an ProjectRootManager with 1.5 jdk specified" do
602
+ #raise File.read(@foo._("foo.ipr"))
603
+ xml_document(@foo._("foo.ipr")).
604
+ should have_xpath("/project/component[@name='ProjectRootManager' and @project-jdk-name = '1.5' and @languageLevel = 'JDK_1_5']")
605
+ end
606
+
607
+ it "generates a ProjectDetails component with the projectName option set" do
608
+ xml_document(@foo._("foo.ipr")).
609
+ should have_xpath("/project/component[@name='ProjectDetails']/option[@name = 'projectName' and @value = 'foo']")
610
+ end
611
+ end
612
+
613
+ describe "with compile.options.source = '1.6'" do
614
+ before do
615
+ @foo = define "foo" do
616
+ compile.options.source = '1.6'
617
+ end
618
+ invoke_generate_task
619
+ end
620
+
621
+ it "generate an ProjectRootManager with 1.6 jdk specified" do
622
+ xml_document(@foo._("foo.ipr")).
623
+ should have_xpath("/project/component[@name='ProjectRootManager' and @project-jdk-name = '1.6' and @languageLevel = 'JDK_1_6']")
624
+ end
625
+ end
626
+
627
+ describe "with iml.skip_content! specified" do
628
+ before do
629
+ @foo = define "foo" do
630
+ iml.skip_content!
631
+ end
632
+ invoke_generate_task
633
+ end
634
+
635
+ it "generate an IML with no content section" do
636
+ doc = xml_document(@foo._(root_module_filename(@foo)))
637
+ doc.should_not have_xpath("/module/component[@name='NewModuleRootManager']/content")
638
+ end
639
+ end
640
+
641
+ describe "with iml.skip_content! not specified and standard layout" do
642
+ before do
643
+ @foo = define "foo" do
644
+ end
645
+ invoke_generate_task
646
+ end
647
+
648
+ it "generate an IML with content section" do
649
+ root_module_xml(@foo).should have_xpath("/module/component[@name='NewModuleRootManager']/content")
650
+ end
651
+
652
+ it "generate an exclude in content section for reports" do
653
+ root_module_xml(@foo).should have_xpath("/module/component[@name='NewModuleRootManager']/content/excludeFolder[@url='file://$MODULE_DIR$/reports']")
654
+ end
655
+
656
+ it "generate an exclude in content section for target" do
657
+ root_module_xml(@foo).should have_xpath("/module/component[@name='NewModuleRootManager']/content/excludeFolder[@url='file://$MODULE_DIR$/target']")
658
+ end
659
+ end
660
+
661
+ describe "with subprojects" do
662
+ before do
663
+ @foo = define "foo" do
664
+ define "bar" do
665
+ compile.from _(:source, :main, :bar)
666
+ end
667
+ end
668
+ invoke_generate_task
669
+ @bar_doc = xml_document(project('foo:bar')._('bar.iml'))
670
+ end
671
+
672
+ it "generates the correct source directories" do
673
+ @bar_doc.should have_xpath("//content/sourceFolder[@url='file://$MODULE_DIR$/src/main/bar']")
674
+ end
675
+
676
+ it "generates the correct exclude directories" do
677
+ @bar_doc.should have_xpath("//content/excludeFolder[@url='file://$MODULE_DIR$/target']")
678
+ end
679
+ end
680
+
681
+ describe "with overrides" do
682
+ before do
683
+ @foo = define "foo" do
684
+ compile.from _(:source, :main, :bar)
685
+ iml.main_source_directories << _(:source, :main, :baz)
686
+ iml.test_source_directories << _(:source, :test, :foo)
687
+ end
688
+ invoke_generate_task
689
+ end
690
+
691
+ it "generates the correct main source directories" do
692
+ root_module_xml(@foo).should have_xpath("//content/sourceFolder[@url='file://$MODULE_DIR$/src/main/baz' and @isTestSource='false']")
693
+ end
694
+
695
+ it "generates the correct test source directories" do
696
+ root_module_xml(@foo).should have_xpath("//content/sourceFolder[@url='file://$MODULE_DIR$/src/test/foo' and @isTestSource='true']")
697
+ end
698
+ end
699
+
700
+ describe "with report dir outside content" do
701
+ before do
702
+ layout = Layout::Default.new
703
+ layout[:reports] = "../reports"
704
+
705
+ @foo = define "foo", :layout => layout do
706
+ end
707
+ invoke_generate_task
708
+ end
709
+
710
+ it "generate an exclude in content section for target" do
711
+ root_module_xml(@foo).should have_xpath("/module/component[@name='NewModuleRootManager']/content/excludeFolder[@url='file://$MODULE_DIR$/target']")
712
+ end
713
+
714
+ it "generates an content section without an exclude for report dir" do
715
+ root_module_xml(@foo).should have_nodes("/module/component[@name='NewModuleRootManager']/content/excludeFolder", 1)
716
+ end
717
+ end
718
+
719
+ describe "with target dir outside content" do
720
+ before do
721
+ layout = Layout::Default.new
722
+ layout[:target] = "../target"
723
+ layout[:target, :main] = "../target"
724
+
725
+ @foo = define "foo", :layout => layout do
726
+ end
727
+ invoke_generate_task
728
+ end
729
+
730
+ it "generate an exclude in content section for reports" do
731
+ root_module_xml(@foo).should have_xpath("/module/component[@name='NewModuleRootManager']/content/excludeFolder[@url='file://$MODULE_DIR$/reports']")
732
+ end
733
+
734
+ it "generates an content section without an exclude for target dir" do
735
+ root_module_xml(@foo).should have_nodes("/module/component[@name='NewModuleRootManager']/content/excludeFolder", 1)
736
+ end
737
+ end
738
+
739
+ describe "templates" do
740
+
741
+ def ipr_template
742
+ return <<PROJECT_XML
743
+ <?xml version="1.0" encoding="UTF-8"?>
744
+ <project version="4">
745
+ <component name="SvnBranchConfigurationManager">
746
+ <option name="mySupportsUserInfoFilter" value="false" />
747
+ </component>
748
+ </project>
749
+ PROJECT_XML
750
+ end
751
+
752
+ def ipr_existing
753
+ return <<PROJECT_XML
754
+ <?xml version="1.0" encoding="UTF-8"?>
755
+ <project version="4">
756
+ <component name="AntConfiguration">
757
+ <defaultAnt bundledAnt="true" />
758
+ </component>
759
+ <component name="SvnBranchConfigurationManager">
760
+ <option name="mySupportsUserInfoFilter" value="true" />
761
+ </component>
762
+ <component name="ProjectModuleManager">
763
+ <modules>
764
+ <module fileurl="file://$PROJECT_DIR$/existing.iml" filepath="$PROJECT_DIR$/existing.iml" />
765
+ </modules>
766
+ </component>
767
+ </project>
768
+ PROJECT_XML
769
+ end
770
+
771
+ def ipr_from_template_xpath
772
+ "/project/component[@name='SvnBranchConfigurationManager']/option[@name = 'mySupportsUserInfoFilter' and @value = 'false']"
773
+ end
774
+
775
+ def ipr_from_existing_xpath
776
+ "/project/component[@name='AntConfiguration']"
777
+ end
778
+
779
+ def ipr_from_existing_shadowing_template_xpath
780
+ "/project/component[@name='SvnBranchConfigurationManager']/option[@name = 'mySupportsUserInfoFilter' and @value = 'true']"
781
+ end
782
+
783
+ def ipr_from_existing_shadowing_generated_xpath
784
+ "/project/component[@name='ProjectModuleManager']/modules/module[@fileurl = 'file://$PROJECT_DIR$/existing.iml']"
785
+ end
786
+
787
+ def ipr_from_generated_xpath
788
+ "/project/component[@name='ProjectModuleManager']/modules/module[@fileurl = 'file://$PROJECT_DIR$/foo.iml']"
789
+ end
790
+
791
+ def iml_template
792
+ return <<PROJECT_XML
793
+ <?xml version="1.0" encoding="UTF-8"?>
794
+ <module type="JAVA_MODULE" version="4">
795
+ <component name="FacetManager">
796
+ <facet type="JRUBY" name="JRuby">
797
+ <configuration number="0">
798
+ <JRUBY_FACET_CONFIG_ID NAME="JRUBY_SDK_NAME" VALUE="JRuby SDK 1.4.0RC1" />
799
+ </configuration>
800
+ </facet>
801
+ </component>
802
+ </module>
803
+ PROJECT_XML
804
+ end
805
+
806
+ def iml_existing
807
+ return <<PROJECT_XML
808
+ <?xml version="1.0" encoding="UTF-8"?>
809
+ <module type="JAVA_MODULE" version="4">
810
+ <component name="FunkyPlugin"/>
811
+ <component name="FacetManager">
812
+ <facet type="SCALA" name="Scala"/>
813
+ </component>
814
+ <component name="NewModuleRootManager" inherit-compiler-output="true">
815
+ <exclude-output />
816
+ <content url="file://$MODULE_DIR$"/>
817
+ <orderEntry type="inheritedJdk" />
818
+ <orderEntry type="sourceFolder" forTests="false" />
819
+ <orderEntry type="module" module-name="buildr-bnd" exported="" />
820
+ </component>
821
+ </module>
822
+ PROJECT_XML
823
+ end
824
+
825
+ def iml_from_template_xpath
826
+ "/module/component[@name='FacetManager']/facet[@type = 'JRUBY']"
827
+ end
828
+
829
+ def iml_from_existing_xpath
830
+ "/module/component[@name='FunkyPlugin']"
831
+ end
832
+
833
+ def iml_from_existing_shadowing_template_xpath
834
+ "/module/component[@name='FacetManager']/facet[@type = 'SCALA']"
835
+ end
836
+
837
+ def iml_from_existing_shadowing_generated_xpath
838
+ "/module/component[@name='NewModuleRootManager']/orderEntry[@module-name = 'buildr-bnd']"
839
+ end
840
+
841
+ def iml_from_generated_xpath
842
+ "/module/component[@name='NewModuleRootManager']/orderEntry[@type = 'module-library']"
843
+ end
844
+
845
+ describe "with existing project files" do
846
+ before do
847
+ write "foo.ipr", ipr_existing
848
+ write "foo.iml", iml_existing
849
+ artifact('group:id:jar:1.0') { |t| write t.to_s }
850
+ @foo = define "foo" do
851
+ ipr.template = nil
852
+ iml.template = nil
853
+ compile.with 'group:id:jar:1.0'
854
+ end
855
+ invoke_generate_task
856
+ end
857
+
858
+ it "replaces ProjectModuleManager component in existing ipr file" do
859
+ xml_document(@foo._("foo.ipr")).should have_xpath(ipr_from_generated_xpath)
860
+ xml_document(@foo._("foo.ipr")).should_not have_xpath(ipr_from_existing_shadowing_generated_xpath)
861
+ end
862
+
863
+ it "merges component in existing ipr file" do
864
+ xml_document(@foo._("foo.ipr")).should have_xpath(ipr_from_existing_xpath)
865
+ end
866
+
867
+ def iml_from_generated_xpath
868
+ "/module/component[@name='NewModuleRootManager']/orderEntry[@type = 'module-library']"
869
+ end
870
+
871
+ it "replaces NewModuleRootManager component in existing iml file" do
872
+ xml_document(@foo._("foo.iml")).should have_xpath(iml_from_generated_xpath)
873
+ xml_document(@foo._("foo.iml")).should_not have_xpath(iml_from_existing_shadowing_generated_xpath)
874
+ end
875
+
876
+ it "merges component in existing iml file" do
877
+ xml_document(@foo._("foo.iml")).should have_xpath(iml_from_existing_xpath)
878
+ end
879
+ end
880
+
881
+ describe "with an iml template" do
882
+ before do
883
+ write "module.template.iml", iml_template
884
+ artifact('group:id:jar:1.0') { |t| write t.to_s }
885
+ @foo = define "foo" do
886
+ ipr.template = nil
887
+ iml.template = "module.template.iml"
888
+ compile.with 'group:id:jar:1.0'
889
+ end
890
+ invoke_generate_task
891
+ end
892
+
893
+ it "replaces generated components" do
894
+ xml_document(@foo._("foo.iml")).should have_xpath(iml_from_generated_xpath)
895
+ end
896
+
897
+ it "merges component in iml template" do
898
+ xml_document(@foo._("foo.iml")).should have_xpath(iml_from_template_xpath)
899
+ end
900
+ end
901
+
902
+ describe "with an iml template and existing iml" do
903
+ before do
904
+ write "module.template.iml", iml_template
905
+ write "foo.iml", iml_existing
906
+ artifact('group:id:jar:1.0') { |t| write t.to_s }
907
+ @foo = define "foo" do
908
+ ipr.template = nil
909
+ iml.template = "module.template.iml"
910
+ compile.with 'group:id:jar:1.0'
911
+ end
912
+ invoke_generate_task
913
+ end
914
+
915
+ it "replaces generated components" do
916
+ xml_document(@foo._("foo.iml")).should have_xpath(iml_from_generated_xpath)
917
+ end
918
+
919
+ it "merges component in iml template" do
920
+ xml_document(@foo._("foo.iml")).should have_xpath(iml_from_template_xpath)
921
+ end
922
+
923
+ it "merges components not in iml template and not generated by task" do
924
+ xml_document(@foo._("foo.iml")).should have_xpath(iml_from_existing_xpath)
925
+ xml_document(@foo._("foo.iml")).should_not have_xpath(iml_from_existing_shadowing_template_xpath)
926
+ xml_document(@foo._("foo.iml")).should_not have_xpath(iml_from_existing_shadowing_generated_xpath)
927
+ end
928
+ end
929
+
930
+ describe "with an ipr template" do
931
+ before do
932
+ write "project.template.iml", ipr_template
933
+ artifact('group:id:jar:1.0') { |t| write t.to_s }
934
+ @foo = define "foo" do
935
+ ipr.template = "project.template.iml"
936
+ iml.template = nil
937
+ compile.with 'group:id:jar:1.0'
938
+ end
939
+ invoke_generate_task
940
+ end
941
+
942
+ it "replaces generated component in ipr template" do
943
+ xml_document(@foo._("foo.ipr")).should have_xpath(ipr_from_generated_xpath)
944
+ end
945
+
946
+ it "merges component in ipr template" do
947
+ xml_document(@foo._("foo.ipr")).should have_xpath(ipr_from_template_xpath)
948
+ end
949
+ end
950
+
951
+ describe "with an ipr template and existing ipr" do
952
+ before do
953
+ write "project.template.iml", ipr_template
954
+ write "foo.ipr", ipr_existing
955
+ artifact('group:id:jar:1.0') { |t| write t.to_s }
956
+ @foo = define "foo" do
957
+ ipr.template = "project.template.iml"
958
+ iml.template = nil
959
+ compile.with 'group:id:jar:1.0'
960
+ end
961
+ invoke_generate_task
962
+ end
963
+
964
+ it "replaces generated component in ipr template" do
965
+ xml_document(@foo._("foo.ipr")).should have_xpath(ipr_from_generated_xpath)
966
+ end
967
+
968
+ it "merges component in ipr template" do
969
+ xml_document(@foo._("foo.ipr")).should have_xpath(ipr_from_template_xpath)
970
+ end
971
+
972
+ it "merges components not in ipr template and not generated by task" do
973
+ xml_document(@foo._("foo.ipr")).should have_xpath(ipr_from_existing_xpath)
974
+ xml_document(@foo._("foo.ipr")).should_not have_xpath(ipr_from_existing_shadowing_generated_xpath)
975
+ xml_document(@foo._("foo.ipr")).should_not have_xpath(ipr_from_existing_shadowing_template_xpath)
976
+ end
977
+ end
978
+ end
979
+ end
980
+
981
+ describe "Buildr::IntellijIdea::IdeaModule" do
982
+
983
+ describe "with no settings" do
984
+ before do
985
+ @foo = define "foo"
986
+ end
987
+
988
+ it "has correct default iml.type setting" do
989
+ @foo.iml.type.should == "JAVA_MODULE"
990
+ end
991
+
992
+ it "has correct default iml.local_repository_env_override setting" do
993
+ @foo.iml.local_repository_env_override.should == "MAVEN_REPOSITORY"
994
+ end
995
+ end
996
+
997
+ describe "settings inherited in subprojects" do
998
+ before do
999
+ mkdir_p 'bar'
1000
+ @foo = define "foo" do
1001
+ iml.type = "FOO_MODULE_TYPE"
1002
+ define 'bar'
1003
+ end
1004
+ invoke_generate_task
1005
+ end
1006
+
1007
+ it "generates root IML with specified type" do
1008
+ module_file = root_module_filename(@foo)
1009
+ File.should be_exist(module_file)
1010
+ File.read(module_file).should =~ /FOO_MODULE_TYPE/
1011
+ end
1012
+
1013
+ it "generates subproject IML with inherited type" do
1014
+ module_file = subproject_module_filename(@foo, "bar")
1015
+ File.should be_exist(module_file)
1016
+ File.read(module_file).should =~ /FOO_MODULE_TYPE/
1017
+ end
1018
+
1019
+ end
1020
+
1021
+ describe "with local_repository_env_override = nil" do
1022
+ if Buildr::Util.win_os?
1023
+ describe "base_directory on different drive on windows" do
1024
+ before do
1025
+ @foo = define "foo", :base_dir => "C:/bar" do
1026
+ iml.local_repository_env_override = nil
1027
+ end
1028
+ end
1029
+
1030
+ it "generates relative paths correctly" do
1031
+ @foo.iml.send(:resolve_path, "E:/foo").should eql('E:/foo')
1032
+ end
1033
+ end
1034
+
1035
+ describe "base_directory on same drive on windows" do
1036
+ before do
1037
+ @foo = define "foo", :base_dir => "C:/bar" do
1038
+ iml.local_repository_env_override = nil
1039
+ end
1040
+ end
1041
+
1042
+ it "generates relative paths correctly" do
1043
+ @foo.iml.send(:resolve_path, "C:/foo").should eql('$MODULE_DIR$/../foo')
1044
+ end
1045
+ end
1046
+ end
1047
+ end
1048
+ end
1049
+
1050
+ describe "project extension" do
1051
+ it "provides an 'idea:generate' task" do
1052
+ Rake::Task.tasks.detect { |task| task.to_s == "idea:generate" }.should_not be_nil
1053
+ end
1054
+
1055
+ it "documents the 'idea:generate' task" do
1056
+ Rake::Task.tasks.detect { |task| task.to_s == "idea:generate" }.comment.should_not be_nil
1057
+ end
1058
+
1059
+ it "provides an 'idea:clean' task" do
1060
+ Rake::Task.tasks.detect { |task| task.to_s == "idea:clean" }.should_not be_nil
1061
+ end
1062
+
1063
+ it "documents the 'idea:clean' task" do
1064
+ Rake::Task.tasks.detect { |task| task.to_s == "idea:clean" }.comment.should_not be_nil
1065
+ end
1066
+
1067
+ it "removes the 'idea' task" do
1068
+ Rake::Task.tasks.detect { |task| task.to_s == "idea" }.should be_nil
1069
+ end
1070
+
1071
+ it "removes the 'idea7x' task" do
1072
+ Rake::Task.tasks.detect { |task| task.to_s == "idea7x" }.should be_nil
1073
+ end
1074
+
1075
+ it "removes the 'idea7x:clean' task" do
1076
+ Rake::Task.tasks.detect { |task| task.to_s == "idea7x:clean" }.should be_nil
1077
+ end
1078
+
1079
+ describe "#no_iml" do
1080
+ it "makes #iml? false" do
1081
+ @foo = define "foo" do
1082
+ project.no_iml
1083
+ end
1084
+ @foo.iml?.should be_false
1085
+ end
1086
+ end
1087
+
1088
+ describe "#iml" do
1089
+ before do
1090
+ define "foo" do
1091
+ iml.suffix = "-top"
1092
+
1093
+ define "bar" do
1094
+ iml.suffix = "-mid"
1095
+
1096
+ define "baz" do
1097
+ end
1098
+ end
1099
+ end
1100
+ end
1101
+
1102
+ it "inherits the direct parent's IML settings" do
1103
+ project('foo:bar:baz').iml.suffix.should == "-mid"
1104
+ end
1105
+
1106
+ it "does not modify the parent's IML settings" do
1107
+ project('foo').iml.suffix.should == "-top"
1108
+ end
1109
+
1110
+ it "works even when the parent has no IML" do
1111
+ lambda {
1112
+ define "a" do
1113
+ project.no_iml
1114
+ define "b" do
1115
+ iml.suffix = "-alone"
1116
+ end
1117
+ end
1118
+ }.should_not raise_error
1119
+ end
1120
+
1121
+ it "inherits from the first ancestor which has an IML" do
1122
+ define "a" do
1123
+ iml.suffix = "-a"
1124
+ define "b" do
1125
+ iml.suffix = "-b"
1126
+ define "c" do
1127
+ project.no_iml
1128
+ define "d" do
1129
+ project.no_iml
1130
+ define "e" do
1131
+ project.no_iml
1132
+ define "f" do
1133
+ end
1134
+ end
1135
+ end
1136
+ end
1137
+ end
1138
+ end
1139
+
1140
+ project("a:b:c:d:e:f").iml.suffix.should == "-b"
1141
+ end
1142
+ end
1143
+ end
1144
+
1145
+ end