mguymon-buildr 1.4.5-java

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (220) hide show
  1. data/CHANGELOG +1291 -0
  2. data/LICENSE +176 -0
  3. data/NOTICE +26 -0
  4. data/README.rdoc +134 -0
  5. data/Rakefile +44 -0
  6. data/_buildr +35 -0
  7. data/_jbuildr +35 -0
  8. data/addon/buildr/antlr.rb +65 -0
  9. data/addon/buildr/bnd.rb +147 -0
  10. data/addon/buildr/cobertura.rb +22 -0
  11. data/addon/buildr/drb.rb +281 -0
  12. data/addon/buildr/emma.rb +22 -0
  13. data/addon/buildr/hibernate.rb +149 -0
  14. data/addon/buildr/javacc.rb +85 -0
  15. data/addon/buildr/jaxb_xjc.rb +72 -0
  16. data/addon/buildr/jdepend.rb +60 -0
  17. data/addon/buildr/jetty.rb +248 -0
  18. data/addon/buildr/jibx.rb +86 -0
  19. data/addon/buildr/nailgun.rb +221 -0
  20. data/addon/buildr/openjpa.rb +88 -0
  21. data/addon/buildr/org/apache/buildr/BuildrNail$Main.class +0 -0
  22. data/addon/buildr/org/apache/buildr/BuildrNail.class +0 -0
  23. data/addon/buildr/org/apache/buildr/BuildrNail.java +41 -0
  24. data/addon/buildr/org/apache/buildr/JettyWrapper$1.class +0 -0
  25. data/addon/buildr/org/apache/buildr/JettyWrapper$BuildrHandler.class +0 -0
  26. data/addon/buildr/org/apache/buildr/JettyWrapper.class +0 -0
  27. data/addon/buildr/org/apache/buildr/JettyWrapper.java +144 -0
  28. data/addon/buildr/protobuf.rb +88 -0
  29. data/addon/buildr/xmlbeans.rb +93 -0
  30. data/bin/buildr +19 -0
  31. data/buildr.buildfile +58 -0
  32. data/buildr.gemspec +78 -0
  33. data/doc/_config.yml +1 -0
  34. data/doc/_layouts/default.html +90 -0
  35. data/doc/_layouts/preface.html +22 -0
  36. data/doc/artifacts.textile +217 -0
  37. data/doc/building.textile +276 -0
  38. data/doc/contributing.textile +268 -0
  39. data/doc/css/default.css +236 -0
  40. data/doc/css/print.css +101 -0
  41. data/doc/css/syntax.css +23 -0
  42. data/doc/download.textile +151 -0
  43. data/doc/extending.textile +212 -0
  44. data/doc/images/1442160941-frontcover.jpg +0 -0
  45. data/doc/images/asf-logo.gif +0 -0
  46. data/doc/images/asf-logo.png +0 -0
  47. data/doc/images/buildr-hires.png +0 -0
  48. data/doc/images/buildr.png +0 -0
  49. data/doc/images/favicon.png +0 -0
  50. data/doc/images/growl-icon.tiff +0 -0
  51. data/doc/images/note.png +0 -0
  52. data/doc/images/project-structure.png +0 -0
  53. data/doc/images/tip.png +0 -0
  54. data/doc/images/zbuildr.png +0 -0
  55. data/doc/images/zbuildr.tif +0 -0
  56. data/doc/index.textile +109 -0
  57. data/doc/installing.textile +284 -0
  58. data/doc/languages.textile +599 -0
  59. data/doc/mailing_lists.textile +29 -0
  60. data/doc/more_stuff.textile +845 -0
  61. data/doc/packaging.textile +618 -0
  62. data/doc/preface.textile +54 -0
  63. data/doc/projects.textile +276 -0
  64. data/doc/quick_start.textile +210 -0
  65. data/doc/releasing.textile +117 -0
  66. data/doc/scripts/buildr-git.rb +512 -0
  67. data/doc/scripts/gitflow.rb +296 -0
  68. data/doc/scripts/install-jruby.sh +44 -0
  69. data/doc/scripts/install-linux.sh +73 -0
  70. data/doc/scripts/install-osx.sh +52 -0
  71. data/doc/settings_profiles.textile +287 -0
  72. data/doc/testing.textile +247 -0
  73. data/etc/KEYS +189 -0
  74. data/lib/buildr.rb +44 -0
  75. data/lib/buildr/clojure.rb +34 -0
  76. data/lib/buildr/clojure/shell.rb +52 -0
  77. data/lib/buildr/core.rb +34 -0
  78. data/lib/buildr/core/application.rb +700 -0
  79. data/lib/buildr/core/build.rb +516 -0
  80. data/lib/buildr/core/cc.rb +166 -0
  81. data/lib/buildr/core/checks.rb +253 -0
  82. data/lib/buildr/core/common.rb +151 -0
  83. data/lib/buildr/core/compile.rb +622 -0
  84. data/lib/buildr/core/doc.rb +276 -0
  85. data/lib/buildr/core/environment.rb +129 -0
  86. data/lib/buildr/core/filter.rb +404 -0
  87. data/lib/buildr/core/generate.rb +197 -0
  88. data/lib/buildr/core/help.rb +119 -0
  89. data/lib/buildr/core/jrebel.rb +42 -0
  90. data/lib/buildr/core/linux.rb +30 -0
  91. data/lib/buildr/core/osx.rb +46 -0
  92. data/lib/buildr/core/progressbar.rb +161 -0
  93. data/lib/buildr/core/project.rb +975 -0
  94. data/lib/buildr/core/run.rb +43 -0
  95. data/lib/buildr/core/shell.rb +137 -0
  96. data/lib/buildr/core/test.rb +843 -0
  97. data/lib/buildr/core/transports.rb +575 -0
  98. data/lib/buildr/core/util.rb +537 -0
  99. data/lib/buildr/groovy.rb +20 -0
  100. data/lib/buildr/groovy/bdd.rb +106 -0
  101. data/lib/buildr/groovy/compiler.rb +153 -0
  102. data/lib/buildr/groovy/doc.rb +76 -0
  103. data/lib/buildr/groovy/shell.rb +57 -0
  104. data/lib/buildr/ide.rb +19 -0
  105. data/lib/buildr/ide/eclipse.rb +427 -0
  106. data/lib/buildr/ide/eclipse/java.rb +53 -0
  107. data/lib/buildr/ide/eclipse/plugin.rb +71 -0
  108. data/lib/buildr/ide/eclipse/scala.rb +68 -0
  109. data/lib/buildr/ide/idea.rb +576 -0
  110. data/lib/buildr/java.rb +25 -0
  111. data/lib/buildr/java/ant.rb +94 -0
  112. data/lib/buildr/java/bdd.rb +460 -0
  113. data/lib/buildr/java/cobertura.rb +297 -0
  114. data/lib/buildr/java/commands.rb +223 -0
  115. data/lib/buildr/java/compiler.rb +135 -0
  116. data/lib/buildr/java/deprecated.rb +141 -0
  117. data/lib/buildr/java/doc.rb +86 -0
  118. data/lib/buildr/java/ecj.rb +69 -0
  119. data/lib/buildr/java/emma.rb +244 -0
  120. data/lib/buildr/java/external.rb +73 -0
  121. data/lib/buildr/java/jruby.rb +122 -0
  122. data/lib/buildr/java/jtestr_result.rb +295 -0
  123. data/lib/buildr/java/jtestr_runner.rb.erb +116 -0
  124. data/lib/buildr/java/org/apache/buildr/JavaTestFilter.class +0 -0
  125. data/lib/buildr/java/org/apache/buildr/JavaTestFilter.java +142 -0
  126. data/lib/buildr/java/packaging.rb +734 -0
  127. data/lib/buildr/java/pom.rb +178 -0
  128. data/lib/buildr/java/rjb.rb +154 -0
  129. data/lib/buildr/java/test_result.rb +101 -0
  130. data/lib/buildr/java/tests.rb +362 -0
  131. data/lib/buildr/java/version_requirement.rb +172 -0
  132. data/lib/buildr/packaging.rb +25 -0
  133. data/lib/buildr/packaging/archive.rb +535 -0
  134. data/lib/buildr/packaging/artifact.rb +904 -0
  135. data/lib/buildr/packaging/artifact_namespace.rb +984 -0
  136. data/lib/buildr/packaging/artifact_search.rb +140 -0
  137. data/lib/buildr/packaging/gems.rb +105 -0
  138. data/lib/buildr/packaging/package.rb +249 -0
  139. data/lib/buildr/packaging/repository_array.rb +108 -0
  140. data/lib/buildr/packaging/tar.rb +189 -0
  141. data/lib/buildr/packaging/version_requirement.rb +192 -0
  142. data/lib/buildr/packaging/zip.rb +178 -0
  143. data/lib/buildr/packaging/ziptask.rb +356 -0
  144. data/lib/buildr/resources/buildr.icns +0 -0
  145. data/lib/buildr/resources/completed.png +0 -0
  146. data/lib/buildr/resources/failed.png +0 -0
  147. data/lib/buildr/resources/icons-license.txt +17 -0
  148. data/lib/buildr/run.rb +195 -0
  149. data/lib/buildr/scala.rb +26 -0
  150. data/lib/buildr/scala/bdd.rb +118 -0
  151. data/lib/buildr/scala/compiler.rb +242 -0
  152. data/lib/buildr/scala/doc.rb +142 -0
  153. data/lib/buildr/scala/org/apache/buildr/SpecsSingletonRunner.class +0 -0
  154. data/lib/buildr/scala/org/apache/buildr/SpecsSingletonRunner.java +57 -0
  155. data/lib/buildr/scala/shell.rb +52 -0
  156. data/lib/buildr/scala/tests.rb +171 -0
  157. data/lib/buildr/shell.rb +185 -0
  158. data/lib/buildr/version.rb +18 -0
  159. data/rakelib/all-in-one.rake +113 -0
  160. data/rakelib/checks.rake +57 -0
  161. data/rakelib/doc.rake +137 -0
  162. data/rakelib/metrics.rake +39 -0
  163. data/rakelib/package.rake +73 -0
  164. data/rakelib/release.rake +160 -0
  165. data/rakelib/rspec.rake +91 -0
  166. data/rakelib/setup.rake +66 -0
  167. data/rakelib/stage.rake +220 -0
  168. data/spec/addon/bnd_spec.rb +330 -0
  169. data/spec/addon/drb_spec.rb +328 -0
  170. data/spec/addon/jaxb_xjc_spec.rb +125 -0
  171. data/spec/core/application_spec.rb +631 -0
  172. data/spec/core/build_spec.rb +837 -0
  173. data/spec/core/cc_spec.rb +224 -0
  174. data/spec/core/checks_spec.rb +519 -0
  175. data/spec/core/common_spec.rb +725 -0
  176. data/spec/core/compile_spec.rb +658 -0
  177. data/spec/core/doc_spec.rb +195 -0
  178. data/spec/core/extension_spec.rb +201 -0
  179. data/spec/core/generate_spec.rb +33 -0
  180. data/spec/core/project_spec.rb +772 -0
  181. data/spec/core/run_spec.rb +93 -0
  182. data/spec/core/shell_spec.rb +146 -0
  183. data/spec/core/test_spec.rb +1320 -0
  184. data/spec/core/transport_spec.rb +544 -0
  185. data/spec/core/util_spec.rb +141 -0
  186. data/spec/groovy/bdd_spec.rb +80 -0
  187. data/spec/groovy/compiler_spec.rb +251 -0
  188. data/spec/groovy/doc_spec.rb +65 -0
  189. data/spec/ide/eclipse_spec.rb +739 -0
  190. data/spec/ide/idea_spec.rb +1145 -0
  191. data/spec/java/ant_spec.rb +37 -0
  192. data/spec/java/bdd_spec.rb +374 -0
  193. data/spec/java/cobertura_spec.rb +112 -0
  194. data/spec/java/commands_spec.rb +93 -0
  195. data/spec/java/compiler_spec.rb +252 -0
  196. data/spec/java/doc_spec.rb +56 -0
  197. data/spec/java/ecj_spec.rb +115 -0
  198. data/spec/java/emma_spec.rb +121 -0
  199. data/spec/java/external_spec.rb +56 -0
  200. data/spec/java/java_spec.rb +132 -0
  201. data/spec/java/packaging_spec.rb +1266 -0
  202. data/spec/java/run_spec.rb +78 -0
  203. data/spec/java/test_coverage_helper.rb +257 -0
  204. data/spec/java/tests_spec.rb +497 -0
  205. data/spec/packaging/archive_spec.rb +775 -0
  206. data/spec/packaging/artifact_namespace_spec.rb +743 -0
  207. data/spec/packaging/artifact_spec.rb +1074 -0
  208. data/spec/packaging/packaging_helper.rb +63 -0
  209. data/spec/packaging/packaging_spec.rb +719 -0
  210. data/spec/packaging/repository_array_spec.rb +109 -0
  211. data/spec/sandbox.rb +165 -0
  212. data/spec/scala/bdd_spec.rb +124 -0
  213. data/spec/scala/compiler_spec.rb +289 -0
  214. data/spec/scala/doc_spec.rb +88 -0
  215. data/spec/scala/scala.rb +38 -0
  216. data/spec/scala/tests_spec.rb +283 -0
  217. data/spec/spec_helpers.rb +369 -0
  218. data/spec/version_requirement_spec.rb +143 -0
  219. data/spec/xpath_matchers.rb +121 -0
  220. metadata +600 -0
@@ -0,0 +1,195 @@
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
+
20
+ describe Project, '#doc' do
21
+ def sources
22
+ @sources ||= (1..3).map { |i| "Test#{i}" }.
23
+ each { |name| write "src/main/java/foo/#{name}.java", "package foo; public class #{name}{}" }.
24
+ map { |name| "src/main/java/foo/#{name}.java" }
25
+ end
26
+
27
+ it 'should return the project\'s Javadoc task' do
28
+ define('foo') { compile.using(:javac) }
29
+ project('foo').doc.name.should eql('foo:doc')
30
+ end
31
+
32
+ it 'should return a DocTask' do
33
+ define('foo') { compile.using(:javac) }
34
+ project('foo').doc.should be_kind_of(Doc::DocTask)
35
+ end
36
+
37
+ it 'should set target directory to target/doc' do
38
+ define 'foo' do
39
+ compile.using(:javac)
40
+ doc.target.to_s.should point_to_path('target/doc')
41
+ end
42
+ end
43
+
44
+ it 'should create file task for target directory' do
45
+ define 'foo' do
46
+ compile.using(:javac)
47
+ doc.should_receive(:invoke_prerequisites)
48
+ end
49
+ project('foo').file('target/doc').invoke
50
+ end
51
+
52
+ it 'should respond to into() and return self' do
53
+ define 'foo' do
54
+ compile.using(:javac)
55
+ doc.into('docs').should be(doc)
56
+ end
57
+ end
58
+
59
+ it 'should respond to into() and change target directory' do
60
+ define 'foo' do
61
+ compile.using(:javac)
62
+ doc.into('docs')
63
+ doc.should_receive(:invoke_prerequisites)
64
+ end
65
+ file('docs').invoke
66
+ end
67
+
68
+ it 'should respond to from() and return self' do
69
+ task = nil
70
+ define('foo') do
71
+ compile.using(:javac)
72
+ task = doc.from('srcs')
73
+ end
74
+ task.should be(project('foo').doc)
75
+ end
76
+
77
+ it 'should respond to from() and add sources' do
78
+ define 'foo' do
79
+ compile.using(:javac)
80
+ doc.from('srcs').should be(doc)
81
+ end
82
+ end
83
+
84
+ it 'should respond to from() and add file task' do
85
+ define 'foo' do
86
+ compile.using(:javac)
87
+ doc.from('srcs').should be(doc)
88
+ end
89
+ project('foo').doc.source_files.first.should point_to_path('srcs')
90
+ end
91
+
92
+ it 'should respond to from() and add project\'s sources and dependencies' do
93
+ write 'bar/src/main/java/Test.java'
94
+ define 'foo' do
95
+ compile.using(:javac)
96
+ define('bar') { compile.using(:javac).with 'group:id:jar:1.0' }
97
+ doc.from project('foo:bar')
98
+ end
99
+ project('foo').doc.source_files.first.should point_to_path('bar/src/main/java/Test.java')
100
+ project('foo').doc.classpath.map(&:to_spec).should include('group:id:jar:1.0')
101
+ end
102
+
103
+ it 'should generate docs from project' do
104
+ sources
105
+ define('foo') { compile.using(:javac) }
106
+ project('foo').doc.source_files.sort.should == sources.sort.map { |f| File.expand_path(f) }
107
+ end
108
+
109
+ it 'should include compile dependencies' do
110
+ define('foo') { compile.using(:javac).with 'group:id:jar:1.0' }
111
+ project('foo').doc.classpath.map(&:to_spec).should include('group:id:jar:1.0')
112
+ end
113
+
114
+ it 'should respond to include() and return self' do
115
+ define 'foo' do
116
+ compile.using(:javac)
117
+ doc.include('srcs').should be(doc)
118
+ end
119
+ end
120
+
121
+ it 'should respond to include() and add files' do
122
+ included = sources.first
123
+ define 'foo' do
124
+ compile.using(:javac)
125
+ doc.include included
126
+ end
127
+ project('foo').doc.source_files.should include(included)
128
+ end
129
+
130
+ it 'should respond to exclude() and return self' do
131
+ define 'foo' do
132
+ compile.using(:javac)
133
+ doc.exclude('srcs').should be(doc)
134
+ end
135
+ end
136
+
137
+ it 'should respond to exclude() and ignore files' do
138
+ excluded = sources.first
139
+ define 'foo' do
140
+ compile.using(:javac)
141
+ doc.exclude excluded
142
+ end
143
+ sources
144
+ project('foo').doc.source_files.sort.should == sources[1..-1].map { |f| File.expand_path(f) }
145
+ end
146
+
147
+ it 'should respond to using() and return self' do
148
+ define 'foo' do
149
+ compile.using(:javac)
150
+ doc.using(:foo=>'Fooing').should be(doc)
151
+ end
152
+ end
153
+
154
+ it 'should respond to using() and accept options' do
155
+ define 'foo' do
156
+ compile.using(:javac)
157
+ doc.using :foo=>'Fooing'
158
+ end
159
+ project('foo').doc.options[:foo].should eql('Fooing')
160
+ end
161
+
162
+ it 'should produce documentation' do
163
+ sources
164
+ define('foo') { compile.using(:javac) }
165
+ project('foo').doc.invoke
166
+ (1..3).map { |i| "target/doc/foo/Test#{i}.html" }.each { |f| file(f).should exist }
167
+ end
168
+
169
+ it 'should fail on error' do
170
+ write 'Test.java', 'class Test {}'
171
+ define 'foo' do
172
+ compile.using(:javac)
173
+ doc.include 'Test.java'
174
+ end
175
+ lambda { project('foo').doc.invoke }.should raise_error(RuntimeError, /Failed to generate Javadocs/)
176
+ end
177
+
178
+ it 'should be local task' do
179
+ define 'foo' do
180
+ define('bar') { compile.using(:javac) }
181
+ end
182
+ project('foo:bar').doc.should_receive(:invoke_prerequisites)
183
+ in_original_dir(project('foo:bar').base_dir) { task('doc').invoke }
184
+ end
185
+
186
+ it 'should not recurse' do
187
+ define 'foo' do
188
+ compile.using(:javac)
189
+ define('bar') { compile.using(:javac) }
190
+ end
191
+ project('foo:bar').doc.should_not_receive(:invoke_prerequisites)
192
+ project('foo').doc.invoke
193
+ end
194
+ end
195
+
@@ -0,0 +1,201 @@
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
+
20
+ describe Extension do
21
+
22
+ before do
23
+ @saved_modules = Project.class_eval { @extension_modules }.dup
24
+ @saved_callbacks = Project.class_eval { @global_callbacks }.dup
25
+ end
26
+
27
+ after do
28
+ modules = @saved_modules
29
+ callbacks = @saved_callbacks
30
+ Project.class_eval do
31
+ @global_callbacks = callbacks
32
+ @extension_modules = modules
33
+ end
34
+ end
35
+
36
+ it 'should call Extension.first_time during include' do
37
+ TestExtension.should_receive(:first_time_called).once
38
+ class Buildr::Project
39
+ include TestExtension
40
+ end
41
+ end
42
+
43
+ it 'should call before_define and after_define in order when project is defined' do
44
+ begin
45
+ TestExtension.callback do |extension|
46
+ extension.should_receive(:before_define_called).once.ordered
47
+ extension.should_receive(:after_define_called).once.ordered
48
+ end
49
+ class Buildr::Project
50
+ include TestExtension
51
+ end
52
+ define('foo')
53
+ ensure
54
+ TestExtension.callback { |ignore| }
55
+ end
56
+ end
57
+
58
+ it 'should call before_define and after_define for each project defined' do
59
+ begin
60
+ extensions = 0
61
+ TestExtension.callback do |extension|
62
+ extensions += 1
63
+ extension.should_receive(:before_define_called).once.ordered
64
+ extension.should_receive(:after_define_called).once.ordered
65
+ end
66
+ class Buildr::Project
67
+ include TestExtension
68
+ end
69
+ define('foo')
70
+ define('bar')
71
+ extensions.should equal(2)
72
+ ensure
73
+ TestExtension.callback { |ignore| }
74
+ end
75
+ end
76
+
77
+ it 'should call before_define callbacks in dependency order' do
78
+ class Buildr::Project
79
+ include ExtensionOneTwo
80
+ include ExtensionThreeFour
81
+ end
82
+ define('foo')
83
+ project('foo').before_order.should == [ :one, :two, :three, :four ]
84
+ project('foo').after_order.should == [ :four, :three, :two, :one ]
85
+ end
86
+
87
+ it 'should call before_define callbacks when extending project' do
88
+ define('foo') do
89
+ extend ExtensionOneTwo
90
+ extend ExtensionThreeFour
91
+ end
92
+ project('foo').before_order.should == [ :two, :one, :four, :three ]
93
+ project('foo').after_order.should == [ :four, :three, :two, :one ]
94
+ end
95
+
96
+ it 'should raise error when including if callback dependencies cannot be satisfied' do
97
+ class Buildr::Project
98
+ include ExtensionOneTwo # missing ExtensionThreeFour
99
+ end
100
+ lambda { define('foo') }.should raise_error
101
+ end
102
+
103
+ it 'should raise error when extending if callback dependencies cannot be satisfied' do
104
+ lambda {
105
+ define('foo') do |project|
106
+ extend ExtensionOneTwo # missing ExtensionThreeFour
107
+ end
108
+ }.should raise_error
109
+ end
110
+
111
+ it 'should ignore dependencies when extending project' do
112
+ define('bar') do |project|
113
+ extend ExtensionThreeFour # missing ExtensionOneTwo
114
+ end
115
+ project('bar').before_order.should == [:four, :three]
116
+ project('bar').after_order.should == [:four, :three]
117
+ end
118
+ end
119
+
120
+ module TestExtension
121
+ include Extension
122
+
123
+ def initialize(*args)
124
+ super
125
+ # callback is used to obtain extension instance created by buildr
126
+ @@callback.call(self) if @@callback
127
+ end
128
+
129
+ def self.callback(&block)
130
+ @@callback = block
131
+ end
132
+
133
+ first_time do
134
+ self.first_time_called()
135
+ end
136
+
137
+ before_define do |project|
138
+ project.before_define_called()
139
+ end
140
+
141
+ after_define do |project|
142
+ project.after_define_called()
143
+ end
144
+
145
+ def self.first_time_called()
146
+ end
147
+
148
+ end
149
+
150
+ module BeforeAfter
151
+ def before_order
152
+ @before_order ||= []
153
+ end
154
+
155
+ def after_order
156
+ @after_order ||= []
157
+ end
158
+ end
159
+
160
+ module ExtensionOneTwo
161
+ include Extension, BeforeAfter
162
+
163
+ before_define(:two => :one) do |project|
164
+ project.before_order << :two
165
+ end
166
+
167
+ before_define(:one) do |project|
168
+ project.before_order << :one
169
+ end
170
+
171
+ after_define(:one => :two) do |project|
172
+ project.after_order << :one
173
+ end
174
+
175
+ after_define(:two => :three) do |project|
176
+ project.after_order << :two
177
+ end
178
+ end
179
+
180
+ module ExtensionThreeFour
181
+ include Extension, BeforeAfter
182
+
183
+ before_define(:three => :two)
184
+
185
+ before_define(:four => :three) do |project|
186
+ project.before_order << :four
187
+ end
188
+
189
+ before_define(:three) do |project|
190
+ project.before_order << :three
191
+ end
192
+
193
+ after_define(:three => :four) do |project|
194
+ project.after_order << :three
195
+ end
196
+
197
+ after_define(:four) do |project|
198
+ project.after_order << :four
199
+ end
200
+ end
201
+
@@ -0,0 +1,33 @@
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
+
20
+ describe Buildr::Generate do
21
+
22
+ describe 'Generated buildfile' do
23
+ it 'should be a legal buildfile' do
24
+ File.open('buildfile', 'w') { |file| file.write Generate.from_directory(Dir.pwd).join("\n") }
25
+ lambda { Buildr.application.run }.should_not raise_error
26
+ end
27
+
28
+ it 'should not contain NEXT_VERSION because it was removed in buildr 1.3.3' do
29
+ buildfile = Generate.from_directory(Dir.pwd)
30
+ buildfile.each { |line| line.should_not include('NEXT_VERSION')}
31
+ end
32
+ end
33
+ end
@@ -0,0 +1,772 @@
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
+
20
+ describe Project do
21
+ it 'should be findable' do
22
+ foo = define('foo')
23
+ project('foo').should be(foo)
24
+ end
25
+
26
+ it 'should not exist unless defined' do
27
+ lambda { project('foo') }.should raise_error(RuntimeError, /No such project/)
28
+ end
29
+
30
+ it 'should fail to be defined if its name is already used for a task' do
31
+ lambda { define('test') }.should raise_error(RuntimeError, /Invalid project name/i)
32
+ define 'valid' do
33
+ lambda { define('build') }.should raise_error(RuntimeError, /Invalid project name/i)
34
+ end
35
+ end
36
+
37
+ it 'should exist once defined' do
38
+ define 'foo'
39
+ lambda { project('foo') }.should_not raise_error
40
+ end
41
+
42
+ it 'should always return same project for same name' do
43
+ foo, bar = define('foo'), define('bar')
44
+ foo.should_not be(bar)
45
+ foo.should be(project('foo'))
46
+ bar.should be(project('bar'))
47
+ end
48
+
49
+ it 'should show up in projects list if defined' do
50
+ define('foo')
51
+ projects.map(&:name).should include('foo')
52
+ end
53
+
54
+ it 'should not show up in projects list unless defined' do
55
+ projects.map(&:name).should_not include('foo')
56
+ end
57
+
58
+ it 'should be findable from within a project' do
59
+ define('foo')
60
+ project('foo').project('foo').should be(project('foo'))
61
+ end
62
+
63
+ it 'should cease to exist when project list cleared' do
64
+ define 'foo'
65
+ projects.map(&:name).should include('foo')
66
+ Project.clear
67
+ projects.map(&:name).should be_empty
68
+ end
69
+
70
+ it 'should be defined only once' do
71
+ lambda { define 'foo' }.should_not raise_error
72
+ lambda { define 'foo' }.should raise_error
73
+ end
74
+
75
+ it 'should be definable in any order' do
76
+ Buildr.define('baz') { define('bar') { project('foo:bar') } }
77
+ Buildr.define('foo') { define('bar') }
78
+ lambda { project('foo') }.should_not raise_error
79
+ end
80
+
81
+ it 'should detect circular dependency' do
82
+ Buildr.define('baz') { define('bar') { project('foo:bar') } }
83
+ Buildr.define('foo') { define('bar') { project('baz:bar') } }
84
+ lambda { project('foo') }.should raise_error(RuntimeError, /Circular dependency/)
85
+ end
86
+ end
87
+
88
+ describe Project, ' property' do
89
+ it 'should be set if passed as argument' do
90
+ define 'foo', 'version'=>'1.1'
91
+ project('foo').version.should eql('1.1')
92
+ end
93
+
94
+ it 'should be set if assigned in body' do
95
+ define('foo') { self.version = '1.2' }
96
+ project('foo').version.should eql('1.2')
97
+ end
98
+
99
+ it 'should take precedence when assigned in body' do
100
+ define('foo', 'version'=>'1.1') { self.version = '1.2' }
101
+ project('foo').version.should eql('1.2')
102
+ end
103
+
104
+ it 'should inherit from parent (for some properties)' do
105
+ define('foo', 'version'=>'1.2', :group=>'foobar') { define 'bar' }
106
+ project('foo:bar').version.should eql('1.2')
107
+ project('foo:bar').group.should eql('foobar')
108
+ end
109
+
110
+ it 'should have different value if set in sub-project' do
111
+ define 'foo', 'version'=>'1.2', :group=>'foobar' do
112
+ define 'bar', :version=>'1.3' do
113
+ self.group = 'barbaz'
114
+ end
115
+ end
116
+ project('foo:bar').version.should eql('1.3')
117
+ project('foo:bar').group.should eql('barbaz')
118
+ end
119
+ end
120
+
121
+
122
+ describe Project, ' block' do
123
+ it 'should execute once' do
124
+ define('foo') { self.name.should eql('foo') }
125
+ end
126
+
127
+ it 'should execute in describe of project' do
128
+ define('foo') { self.version = '1.3' }
129
+ project('foo').version.should eql('1.3')
130
+ end
131
+
132
+ it 'should execute by passing project' do
133
+ define('foo') { |project| project.version = '1.3' }
134
+ project('foo').version.should eql('1.3')
135
+ end
136
+
137
+ it 'should execute in namespace of project' do
138
+ define('foo') { define('bar') { Buildr.application.current_scope.should eql(['foo', 'bar']) } }
139
+ end
140
+ end
141
+
142
+
143
+ describe Project, '#base_dir' do
144
+ it 'should be pwd if not specified' do
145
+ define('foo').base_dir.should eql(Dir.pwd)
146
+ end
147
+
148
+ it 'should come from property, if specified' do
149
+ foo = define('foo', :base_dir=>'tmp')
150
+ foo.base_dir.should point_to_path('tmp')
151
+ end
152
+
153
+ it 'should be expanded path' do
154
+ foo = define('foo', :base_dir=>'tmp')
155
+ foo.base_dir.should eql(File.expand_path('tmp'))
156
+ end
157
+
158
+ it 'should be relative to parent project' do
159
+ define('foo') { define('bar') { define 'baz' } }
160
+ project('foo:bar:baz').base_dir.should point_to_path('bar/baz')
161
+ end
162
+
163
+ it 'should be settable only if not read' do
164
+ lambda { define('foo', :base_dir=>'tmp') }.should_not raise_error
165
+ lambda { define('bar', :base_dir=>'tmp') { self.base_dir = 'bar' } }.should raise_error(Exception, /Cannot set/)
166
+ end
167
+ end
168
+
169
+
170
+ describe Layout do
171
+ before :each do
172
+ @layout = Layout.new
173
+ end
174
+
175
+ it 'should expand empty to itself' do
176
+ @layout.expand.should eql('')
177
+ @layout.expand('').should eql('')
178
+ end
179
+
180
+ it 'should expand array of symbols' do
181
+ @layout.expand(:foo, :bar).should eql('foo/bar')
182
+ end
183
+
184
+ it 'should expand array of names' do
185
+ @layout.expand('foo', 'bar').should eql('foo/bar')
186
+ end
187
+
188
+ it 'should map symbol to path' do
189
+ @layout[:foo] = 'baz'
190
+ @layout.expand(:foo, :bar).should eql('baz/bar')
191
+ end
192
+
193
+ it 'should map symbols to path' do
194
+ @layout[:foo, :bar] = 'none'
195
+ @layout.expand(:foo, :bar).should eql('none')
196
+ end
197
+
198
+ it 'should map strings to path' do
199
+ @layout[:foo, "bar"] = 'none'
200
+ @layout.expand(:foo, :bar).should eql('none')
201
+ @layout.expand(:foo, 'bar').should eql('none')
202
+ end
203
+
204
+ it 'should ignore nil elements' do
205
+ @layout[:foo, :bar] = 'none'
206
+ @layout.expand(:foo, nil, :bar).should eql('none')
207
+ @layout.expand(nil, :foo).should eql('foo')
208
+ end
209
+
210
+ it 'should return nil if path not mapped' do
211
+ @layout[:foo].should be_nil
212
+ end
213
+
214
+ it 'should return path from symbol' do
215
+ @layout[:foo] = 'path'
216
+ @layout[:foo].should eql('path')
217
+ end
218
+
219
+ it 'should return path from symbol' do
220
+ @layout[:foo, :bar] = 'path'
221
+ @layout[:foo, :bar].should eql('path')
222
+ end
223
+
224
+ it 'should do eager mapping' do
225
+ @layout[:one] = 'none'
226
+ @layout[:one, :two] = '1..2'
227
+ @layout.expand(:one, :two, :three).should eql('1..2/three')
228
+ end
229
+
230
+ end
231
+
232
+
233
+ describe Project, '#layout' do
234
+ before :each do
235
+ @layout = Layout.new
236
+ end
237
+
238
+ it 'should exist by default' do
239
+ define('foo').layout.should respond_to(:expand)
240
+ end
241
+
242
+ it 'should be clone of default layout' do
243
+ define 'foo' do
244
+ layout.should_not be(Layout.default)
245
+ layout.expand(:test, :main).should eql(Layout.default.expand(:test, :main))
246
+ end
247
+ end
248
+
249
+ it 'should come from property, if specified' do
250
+ foo = define('foo', :layout=>@layout)
251
+ foo.layout.should eql(@layout)
252
+ end
253
+
254
+ it 'should inherit from parent project' do
255
+ define 'foo', :layout=>@layout do
256
+ layout[:foo] = 'foo'
257
+ define 'bar'
258
+ end
259
+ project('foo:bar').layout[:foo].should eql('foo')
260
+ end
261
+
262
+ it 'should clone when inheriting from parent project' do
263
+ define 'foo', :layout=>@layout do
264
+ layout[:foo] = 'foo'
265
+ define 'bar' do
266
+ layout[:foo] = 'bar'
267
+ end
268
+ end
269
+ project('foo').layout[:foo].should eql('foo')
270
+ project('foo:bar').layout[:foo].should eql('bar')
271
+ end
272
+
273
+ it 'should be settable only if not read' do
274
+ lambda { define('foo', :layout=>@layout) }.should_not raise_error
275
+ lambda { define('bar', :layout=>@layout) { self.layout = @layout.clone } }.should raise_error(Exception, /Cannot set/)
276
+ end
277
+
278
+ end
279
+
280
+
281
+ describe Project, '#path_to' do
282
+ it 'should return absolute paths as is' do
283
+ define('foo').path_to('/tmp').should eql(File.expand_path('/tmp'))
284
+ end
285
+
286
+ it 'should resolve empty path to project\'s base directory' do
287
+ define('foo').path_to.should eql(project('foo').base_dir)
288
+ end
289
+
290
+ it 'should resolve relative paths' do
291
+ define('foo').path_to('tmp').should eql(File.expand_path('tmp'))
292
+ end
293
+
294
+ it 'should accept multiple arguments' do
295
+ define('foo').path_to('foo', 'bar').should eql(File.expand_path('foo/bar'))
296
+ end
297
+
298
+ it 'should handle relative paths' do
299
+ define('foo').path_to('..', 'bar').should eql(File.expand_path('../bar'))
300
+ end
301
+
302
+ it 'should resolve symbols using layout' do
303
+ define('foo').layout[:foo] = 'bar'
304
+ project('foo').path_to(:foo).should eql(File.expand_path('bar'))
305
+ project('foo').path_to(:foo, 'tmp').should eql(File.expand_path('bar/tmp'))
306
+ end
307
+
308
+ it 'should resolve path for sub-project' do
309
+ define('foo') { define 'bar' }
310
+ project('foo:bar').path_to('foo').should eql(File.expand_path('foo', project('foo:bar').base_dir))
311
+ end
312
+
313
+ it 'should be idempotent for relative paths' do
314
+ define 'foo'
315
+ path = project('foo').path_to('bar')
316
+ project('foo').path_to(path).should eql(path)
317
+ end
318
+ end
319
+
320
+
321
+ describe Project, '#on_define' do
322
+ it 'should be called when project is defined' do
323
+ names = []
324
+ Project.on_define { |project| names << project.name }
325
+ define 'foo' ; define 'bar'
326
+ names.should eql(['foo', 'bar'])
327
+ end
328
+
329
+ it 'should be called with project object' do
330
+ Project.on_define { |project| project.name.should eql('foo') }
331
+ define('foo')
332
+ end
333
+
334
+ it 'should be called with project object and set properties' do
335
+ Project.on_define { |project| project.version.should eql('2.0') }
336
+ define('foo', :version=>'2.0')
337
+ end
338
+
339
+ it 'should execute in namespace of project' do
340
+ scopes = []
341
+ Project.on_define { |project| scopes << Buildr.application.current_scope }
342
+ define('foo') { define 'bar' }
343
+ scopes.should eql([['foo'], ['foo', 'bar']])
344
+ end
345
+
346
+ it 'should be called before project block' do
347
+ order = []
348
+ Project.on_define { |project| order << 'on_define' }
349
+ define('foo') { order << 'define' }
350
+ order.should eql(['on_define', 'define'])
351
+ end
352
+
353
+ it 'should accept enhancement and call it after project block' do
354
+ order = []
355
+ Project.on_define { |project| project.enhance { order << 'enhance' } }
356
+ define('foo') { order << 'define' }
357
+ order.should eql(['define', 'enhance'])
358
+ end
359
+
360
+ it 'should accept enhancement and call it with project' do
361
+ Project.on_define { |project| project.enhance { |project| project.name.should eql('foo') } }
362
+ define('foo')
363
+ end
364
+
365
+ it 'should execute enhancement in namespace of project' do
366
+ scopes = []
367
+ Project.on_define { |project| project.enhance { scopes << Buildr.application.current_scope } }
368
+ define('foo') { define 'bar' }
369
+ scopes.should eql([['foo'], ['foo', 'bar']])
370
+ end
371
+
372
+ it 'should be removed in version 1.5 since it was deprecated in version 1.3' do
373
+ Buildr::VERSION.should < '1.5'
374
+ end
375
+ end
376
+
377
+
378
+ describe Rake::Task, ' recursive' do
379
+ before do
380
+ @order = []
381
+ Project.on_define do |project| # TODO on_define is deprecated
382
+ project.recursive_task('doda') { @order << project.name }
383
+ end
384
+ define('foo') { define('bar') { define('baz') } }
385
+ end
386
+
387
+ it 'should invoke same task in child project' do
388
+ task('foo:doda').invoke
389
+ @order.should include('foo:bar:baz')
390
+ @order.should include('foo:bar')
391
+ @order.should include('foo')
392
+ end
393
+
394
+ it 'should invoke in depth-first order' do
395
+ task('foo:doda').invoke
396
+ @order.should eql([ 'foo:bar:baz', 'foo:bar', 'foo' ])
397
+ end
398
+
399
+ it 'should not invoke task in parent project' do
400
+ task('foo:bar:baz:doda').invoke
401
+ @order.should eql([ 'foo:bar:baz' ])
402
+ end
403
+ end
404
+
405
+
406
+ describe 'Sub-project' do
407
+ it 'should point at parent project' do
408
+ define('foo') { define 'bar' }
409
+ project('foo:bar').parent.should be(project('foo'))
410
+ end
411
+
412
+ it 'should be defined only within parent project' do
413
+ lambda { define('foo:bar') }.should raise_error
414
+ end
415
+
416
+ it 'should have unique name' do
417
+ lambda do
418
+ define 'foo' do
419
+ define 'bar'
420
+ define 'bar'
421
+ end
422
+ end.should raise_error
423
+ end
424
+
425
+ it 'should be findable from root' do
426
+ define('foo') { define 'bar' }
427
+ projects.map(&:name).should include('foo:bar')
428
+ end
429
+
430
+ it 'should be findable from parent project' do
431
+ define('foo') { define 'bar' }
432
+ project('foo').projects.map(&:name).should include('foo:bar')
433
+ end
434
+
435
+ it 'should be findable during project definition' do
436
+ define 'foo' do
437
+ bar = define 'bar' do
438
+ baz = define 'baz'
439
+ project('baz').should eql(baz)
440
+ end
441
+ # Note: evaluating bar:baz first unearthed a bug that doesn't happen
442
+ # if we evaluate bar, then bar:baz.
443
+ project('bar:baz').should be(bar.project('baz'))
444
+ project('bar').should be(bar)
445
+ end
446
+ end
447
+
448
+ it 'should be findable only if exists' do
449
+ define('foo') { define 'bar' }
450
+ lambda { project('foo').project('baz') }.should raise_error(RuntimeError, /No such project/)
451
+ end
452
+
453
+ it 'should always execute its definition ' do
454
+ ordered = []
455
+ define 'foo' do
456
+ ordered << self.name
457
+ define('bar') { ordered << self.name }
458
+ define('baz') { ordered << self.name }
459
+ end
460
+ ordered.should eql(['foo', 'foo:bar', 'foo:baz'])
461
+ end
462
+
463
+ it 'should execute in order of dependency' do
464
+ ordered = []
465
+ define 'foo' do
466
+ ordered << self.name
467
+ define('bar') { project('foo:baz') ; ordered << self.name }
468
+ define('baz') { ordered << self.name }
469
+ end
470
+ ordered.should eql(['foo', 'foo:baz', 'foo:bar'])
471
+ end
472
+
473
+ it 'should warn of circular dependency' do
474
+ lambda do
475
+ define 'foo' do
476
+ define('bar') { project('foo:baz') }
477
+ define('baz') { project('foo:bar') }
478
+ end
479
+ end.should raise_error(RuntimeError, /Circular dependency/)
480
+ end
481
+ end
482
+
483
+
484
+ describe 'Top-level project' do
485
+ it 'should have no parent' do
486
+ define('foo')
487
+ project('foo').parent.should be_nil
488
+ end
489
+ end
490
+
491
+
492
+ describe Buildr, '#project' do
493
+ it 'should raise error if no such project' do
494
+ lambda { project('foo') }.should raise_error(RuntimeError, /No such project/)
495
+ end
496
+
497
+ it 'should return a project if exists' do
498
+ foo = define('foo')
499
+ project('foo').should be(foo)
500
+ end
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
+
512
+ it 'should find a project by its full name' do
513
+ bar, baz = nil
514
+ define('foo') { bar = define('bar') { baz = define('baz') } }
515
+ project('foo:bar').should be(bar)
516
+ project('foo:bar:baz').should be(baz)
517
+ end
518
+
519
+ it 'should find a project from any context' do
520
+ bar, baz = nil
521
+ define('foo') { bar = define('bar') { baz = define('baz') } }
522
+ project('foo:bar').project('foo:bar:baz').should be(baz)
523
+ project('foo:bar:baz').project('foo:bar').should be(bar)
524
+ end
525
+
526
+ it 'should find a project from its parent or sibling project' do
527
+ define 'foo' do
528
+ define 'bar'
529
+ define 'baz'
530
+ end
531
+ project('foo').project('bar').should be(project('foo:bar'))
532
+ project('foo').project('baz').should be(project('foo:baz'))
533
+ project('foo:bar').project('baz').should be(project('foo:baz'))
534
+ end
535
+
536
+ it 'should fine a project from its parent by proximity' do
537
+ define 'foo' do
538
+ define('bar') { define 'baz' }
539
+ define 'baz'
540
+ end
541
+ project('foo').project('baz').should be(project('foo:baz'))
542
+ project('foo:bar').project('baz').should be(project('foo:bar:baz'))
543
+ end
544
+
545
+ it 'should invoke project before returning it' do
546
+ define('foo').should_receive(:invoke).once
547
+ project('foo')
548
+ end
549
+
550
+ it 'should fail if called without a project name' do
551
+ lambda { project }.should raise_error(ArgumentError)
552
+ end
553
+
554
+ it 'should return self if called on a project without a name' do
555
+ define('foo') { project.should be(self) }
556
+ end
557
+
558
+ it 'should evaluate parent project before returning' do
559
+ # Note: gets around our define that also invokes the project.
560
+ Buildr.define('foo') { define('bar'); define('baz') }
561
+ project('foo:bar').should eql(projects[1])
562
+ end
563
+ end
564
+
565
+
566
+ describe Buildr, '#projects' do
567
+ it 'should only return defined projects' do
568
+ projects.should eql([])
569
+ define 'foo'
570
+ projects.should eql([project('foo')])
571
+ end
572
+
573
+ it 'should return all defined projects' do
574
+ define 'foo'
575
+ define('bar') { define 'baz' }
576
+ projects.should include(project('foo'))
577
+ projects.should include(project('bar'))
578
+ projects.should include(project('bar:baz'))
579
+ end
580
+
581
+ it 'should return only named projects' do
582
+ define 'foo' ; define 'bar' ; define 'baz'
583
+ projects('foo', 'bar').should include(project('foo'))
584
+ projects('foo', 'bar').should include(project('bar'))
585
+ projects('foo', 'bar').should_not include(project('baz'))
586
+ end
587
+
588
+ it 'should complain if named project does not exist' do
589
+ define 'foo'
590
+ projects('foo').should include(project('foo'))
591
+ lambda { projects('bar') }.should raise_error(RuntimeError, /No such project/)
592
+ end
593
+
594
+ it 'should find a project from its parent or sibling project' do
595
+ define 'foo' do
596
+ define 'bar'
597
+ define 'baz'
598
+ end
599
+ project('foo').projects('bar').should eql(projects('foo:bar'))
600
+ project('foo').projects('baz').should eql(projects('foo:baz'))
601
+ project('foo:bar').projects('baz').should eql(projects('foo:baz'))
602
+ end
603
+
604
+ it 'should fine a project from its parent by proximity' do
605
+ define 'foo' do
606
+ define('bar') { define 'baz' }
607
+ define 'baz'
608
+ end
609
+ project('foo').projects('baz').should eql(projects('foo:baz'))
610
+ project('foo:bar').projects('baz').should eql(projects('foo:bar:baz'))
611
+ end
612
+
613
+ it 'should evaluate all projects before returning' do
614
+ # Note: gets around our define that also invokes the project.
615
+ Buildr.define('foo') { define('bar'); define('baz') }
616
+ projects.should eql(projects('foo', 'foo:bar', 'foo:baz'))
617
+ end
618
+ end
619
+
620
+
621
+ describe Rake::Task, ' local directory' do
622
+ before do
623
+ @task = Project.local_task(task(('doda')))
624
+ Project.on_define { |project| task('doda') { |task| @task.from project.name } }
625
+ end
626
+
627
+ it 'should execute project in local directory' do
628
+ define 'foo'
629
+ @task.should_receive(:from).with('foo')
630
+ @task.invoke
631
+ end
632
+
633
+ it 'should execute sub-project in local directory' do
634
+ @task.should_receive(:from).with('foo:bar')
635
+ define('foo') { define 'bar' }
636
+ in_original_dir(project('foo:bar').base_dir) { @task.invoke }
637
+ end
638
+
639
+ it 'should do nothing if no project in local directory' do
640
+ @task.should_not_receive(:from)
641
+ define('foo') { define 'bar' }
642
+ in_original_dir('../not_foo') { @task.invoke }
643
+ end
644
+
645
+ it 'should find closest project that matches current directory' do
646
+ mkpath 'bar/src/main'
647
+ define('foo') { define 'bar' }
648
+ @task.should_receive(:from).with('foo:bar')
649
+ in_original_dir('bar/src/main') { @task.invoke }
650
+ end
651
+ end
652
+
653
+
654
+ describe Project, '#task' do
655
+ it 'should create a regular task' do
656
+ define('foo') { task('bar') }
657
+ Buildr.application.lookup('foo:bar').should_not be_nil
658
+ end
659
+
660
+ it 'should return a task defined in the project' do
661
+ define('foo') { task('bar') }
662
+ project('foo').task('bar').should be_instance_of(Rake::Task)
663
+ end
664
+
665
+ it 'should not create task outside project definition' do
666
+ define 'foo'
667
+ lambda { project('foo').task('bar') }.should raise_error(RuntimeError, /no task foo:bar/)
668
+ end
669
+
670
+ it 'should include project name as prefix' do
671
+ define('foo') { task('bar') }
672
+ project('foo').task('bar').name.should eql('foo:bar')
673
+ end
674
+
675
+ it 'should ignore namespace if starting with color' do
676
+ define 'foo' do
677
+ task(':bar').name.should == 'bar'
678
+ end
679
+ Rake::Task.task_defined?('bar').should be_true
680
+ end
681
+
682
+ it 'should accept single dependency' do
683
+ define('foo') { task('bar'=>'baz') }
684
+ project('foo').task('bar').prerequisites.should include('baz')
685
+ end
686
+
687
+ it 'should accept multiple dependencies' do
688
+ define('foo') { task('bar'=>['baz1', 'baz2']) }
689
+ project('foo').task('bar').prerequisites.should include('baz1')
690
+ project('foo').task('bar').prerequisites.should include('baz2')
691
+ end
692
+
693
+ it 'should execute task exactly once' do
694
+ define('foo') do
695
+ task 'baz'
696
+ task 'bar'=>'baz'
697
+ end
698
+ lambda { project('foo').task('bar').invoke }.should run_tasks(['foo:baz', 'foo:bar'])
699
+ end
700
+
701
+ it 'should create a file task' do
702
+ define('foo') { file('bar') }
703
+ Buildr.application.lookup(File.expand_path('bar')).should_not be_nil
704
+ end
705
+
706
+ it 'should create file task with absolute path' do
707
+ define('foo') { file('/tmp') }
708
+ Buildr.application.lookup(File.expand_path('/tmp')).should_not be_nil
709
+ end
710
+
711
+ it 'should create file task relative to project base directory' do
712
+ define('foo', :base_dir=>'tmp') { file('bar') }
713
+ Buildr.application.lookup(File.expand_path('tmp/bar')).should_not be_nil
714
+ end
715
+
716
+ it 'should accept single dependency' do
717
+ define('foo') { file('bar'=>'baz') }
718
+ project('foo').file('bar').prerequisites.should include('baz')
719
+ end
720
+
721
+ it 'should accept multiple dependencies' do
722
+ define('foo') { file('bar'=>['baz1', 'baz2']) }
723
+ project('foo').file('bar').prerequisites.should include('baz1')
724
+ project('foo').file('bar').prerequisites.should include('baz2')
725
+ end
726
+
727
+ it 'should accept hash arguments' do
728
+ define('foo') do
729
+ task 'bar'=>'bar_dep'
730
+ file 'baz'=>'baz_dep'
731
+ end
732
+ project('foo').task('bar').prerequisites.should include('bar_dep')
733
+ project('foo').file('baz').prerequisites.should include('baz_dep')
734
+ end
735
+
736
+ it 'should return a file task defined in the project' do
737
+ define('foo') { file('bar') }
738
+ project('foo').file('bar').should be_instance_of(Rake::FileTask)
739
+ end
740
+
741
+ it 'should create file task relative to project definition' do
742
+ define('foo') { define 'bar' }
743
+ project('foo:bar').file('baz').name.should point_to_path('bar/baz')
744
+ end
745
+
746
+ it 'should execute task exactly once' do
747
+ define('foo') do
748
+ task 'baz'
749
+ file 'bar'=>'baz'
750
+ end
751
+ lambda { project('foo').file('bar').invoke }.should run_tasks(['foo:baz', project('foo').path_to('bar')])
752
+ end
753
+ end
754
+
755
+
756
+ =begin
757
+ describe Buildr::Generate do
758
+ it 'should be able to create buildfile from directory structure' do
759
+ write 'src/main/java/Foo.java', ''
760
+ write 'one/two/src/main/java/Foo.java', ''
761
+ write 'one/three/src/main/java/Foo.java', ''
762
+ write 'four/src/main/java/Foo.java', ''
763
+ script = Buildr::Generate.from_directory(Dir.pwd)
764
+ instance_eval(script.join("\n"), "generated buildfile")
765
+ # projects should have been defined
766
+ root = Dir.pwd.pathmap('%n')
767
+ names = [root, "#{root}:one:two", "#{root}:one:three", "#{root}:four"]
768
+ # the top level project has the directory name.
769
+ names.each { |name| lambda { project(name) }.should_not raise_error }
770
+ end
771
+ end
772
+ =end