assaf-buildr 1.3.3
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG +887 -0
- data/DISCLAIMER +7 -0
- data/LICENSE +176 -0
- data/NOTICE +26 -0
- data/README.rdoc +146 -0
- data/Rakefile +62 -0
- data/_buildr +38 -0
- data/addon/buildr/antlr.rb +65 -0
- data/addon/buildr/cobertura.rb +236 -0
- data/addon/buildr/emma.rb +238 -0
- data/addon/buildr/hibernate.rb +142 -0
- data/addon/buildr/javacc.rb +85 -0
- data/addon/buildr/jdepend.rb +60 -0
- data/addon/buildr/jetty.rb +248 -0
- data/addon/buildr/jibx.rb +86 -0
- data/addon/buildr/nailgun.rb +817 -0
- data/addon/buildr/openjpa.rb +90 -0
- data/addon/buildr/org/apache/buildr/BuildrNail$Main.class +0 -0
- data/addon/buildr/org/apache/buildr/BuildrNail.class +0 -0
- data/addon/buildr/org/apache/buildr/BuildrNail.java +41 -0
- data/addon/buildr/org/apache/buildr/JettyWrapper$1.class +0 -0
- data/addon/buildr/org/apache/buildr/JettyWrapper$BuildrHandler.class +0 -0
- data/addon/buildr/org/apache/buildr/JettyWrapper.class +0 -0
- data/addon/buildr/org/apache/buildr/JettyWrapper.java +144 -0
- data/addon/buildr/xmlbeans.rb +93 -0
- data/bin/buildr +28 -0
- data/buildr.buildfile +53 -0
- data/buildr.gemspec +58 -0
- data/doc/css/default.css +228 -0
- data/doc/css/print.css +100 -0
- data/doc/css/syntax.css +52 -0
- data/doc/images/apache-incubator-logo.png +0 -0
- data/doc/images/buildr-hires.png +0 -0
- data/doc/images/buildr.png +0 -0
- data/doc/images/favicon.png +0 -0
- data/doc/images/growl-icon.tiff +0 -0
- data/doc/images/note.png +0 -0
- data/doc/images/project-structure.png +0 -0
- data/doc/images/tip.png +0 -0
- data/doc/images/zbuildr.tif +0 -0
- data/doc/pages/artifacts.textile +207 -0
- data/doc/pages/building.textile +240 -0
- data/doc/pages/contributing.textile +208 -0
- data/doc/pages/download.textile +62 -0
- data/doc/pages/extending.textile +175 -0
- data/doc/pages/getting_started.textile +273 -0
- data/doc/pages/index.textile +42 -0
- data/doc/pages/languages.textile +407 -0
- data/doc/pages/mailing_lists.textile +17 -0
- data/doc/pages/more_stuff.textile +286 -0
- data/doc/pages/packaging.textile +427 -0
- data/doc/pages/projects.textile +274 -0
- data/doc/pages/recipes.textile +103 -0
- data/doc/pages/settings_profiles.textile +274 -0
- data/doc/pages/testing.textile +212 -0
- data/doc/pages/troubleshooting.textile +103 -0
- data/doc/pages/whats_new.textile +323 -0
- data/doc/print.haml +51 -0
- data/doc/print.toc.yaml +29 -0
- data/doc/scripts/buildr-git.rb +412 -0
- data/doc/scripts/install-jruby.sh +44 -0
- data/doc/scripts/install-linux.sh +64 -0
- data/doc/scripts/install-osx.sh +52 -0
- data/doc/site.haml +56 -0
- data/doc/site.toc.yaml +47 -0
- data/etc/KEYS +151 -0
- data/etc/git-svn-authors +16 -0
- data/lib/buildr.rb +35 -0
- data/lib/buildr/core.rb +27 -0
- data/lib/buildr/core/application.rb +489 -0
- data/lib/buildr/core/application_cli.rb +139 -0
- data/lib/buildr/core/build.rb +311 -0
- data/lib/buildr/core/checks.rb +382 -0
- data/lib/buildr/core/common.rb +154 -0
- data/lib/buildr/core/compile.rb +596 -0
- data/lib/buildr/core/environment.rb +120 -0
- data/lib/buildr/core/filter.rb +362 -0
- data/lib/buildr/core/generate.rb +195 -0
- data/lib/buildr/core/help.rb +118 -0
- data/lib/buildr/core/progressbar.rb +156 -0
- data/lib/buildr/core/project.rb +892 -0
- data/lib/buildr/core/test.rb +715 -0
- data/lib/buildr/core/transports.rb +558 -0
- data/lib/buildr/core/util.rb +289 -0
- data/lib/buildr/groovy.rb +18 -0
- data/lib/buildr/groovy/bdd.rb +105 -0
- data/lib/buildr/groovy/compiler.rb +138 -0
- data/lib/buildr/ide.rb +19 -0
- data/lib/buildr/ide/eclipse.rb +212 -0
- data/lib/buildr/ide/idea.ipr.template +300 -0
- data/lib/buildr/ide/idea.rb +189 -0
- data/lib/buildr/ide/idea7x.ipr.template +290 -0
- data/lib/buildr/ide/idea7x.rb +210 -0
- data/lib/buildr/java.rb +23 -0
- data/lib/buildr/java/ant.rb +92 -0
- data/lib/buildr/java/bdd.rb +449 -0
- data/lib/buildr/java/commands.rb +211 -0
- data/lib/buildr/java/compiler.rb +348 -0
- data/lib/buildr/java/deprecated.rb +141 -0
- data/lib/buildr/java/jruby.rb +117 -0
- data/lib/buildr/java/jtestr_runner.rb.erb +116 -0
- data/lib/buildr/java/org/apache/buildr/JavaTestFilter.class +0 -0
- data/lib/buildr/java/org/apache/buildr/JavaTestFilter.java +119 -0
- data/lib/buildr/java/packaging.rb +713 -0
- data/lib/buildr/java/pom.rb +178 -0
- data/lib/buildr/java/rjb.rb +155 -0
- data/lib/buildr/java/test_result.rb +308 -0
- data/lib/buildr/java/tests.rb +324 -0
- data/lib/buildr/java/version_requirement.rb +172 -0
- data/lib/buildr/packaging.rb +21 -0
- data/lib/buildr/packaging/artifact.rb +730 -0
- data/lib/buildr/packaging/artifact_namespace.rb +972 -0
- data/lib/buildr/packaging/artifact_search.rb +140 -0
- data/lib/buildr/packaging/gems.rb +102 -0
- data/lib/buildr/packaging/package.rb +233 -0
- data/lib/buildr/packaging/tar.rb +104 -0
- data/lib/buildr/packaging/zip.rb +722 -0
- data/lib/buildr/resources/buildr.icns +0 -0
- data/lib/buildr/scala.rb +19 -0
- data/lib/buildr/scala/compiler.rb +109 -0
- data/lib/buildr/scala/tests.rb +203 -0
- data/rakelib/apache.rake +191 -0
- data/rakelib/changelog.rake +57 -0
- data/rakelib/doc.rake +103 -0
- data/rakelib/package.rake +73 -0
- data/rakelib/release.rake +65 -0
- data/rakelib/rspec.rake +83 -0
- data/rakelib/rubyforge.rake +53 -0
- data/rakelib/scm.rake +49 -0
- data/rakelib/setup.rake +86 -0
- data/rakelib/stage.rake +48 -0
- data/spec/addon/cobertura_spec.rb +77 -0
- data/spec/addon/emma_spec.rb +120 -0
- data/spec/addon/test_coverage_spec.rb +255 -0
- data/spec/core/application_spec.rb +412 -0
- data/spec/core/artifact_namespace_spec.rb +646 -0
- data/spec/core/build_spec.rb +415 -0
- data/spec/core/checks_spec.rb +537 -0
- data/spec/core/common_spec.rb +664 -0
- data/spec/core/compile_spec.rb +566 -0
- data/spec/core/generate_spec.rb +33 -0
- data/spec/core/project_spec.rb +754 -0
- data/spec/core/test_spec.rb +1091 -0
- data/spec/core/transport_spec.rb +500 -0
- data/spec/groovy/bdd_spec.rb +80 -0
- data/spec/groovy/compiler_spec.rb +239 -0
- data/spec/ide/eclipse_spec.rb +243 -0
- data/spec/java/ant.rb +28 -0
- data/spec/java/bdd_spec.rb +358 -0
- data/spec/java/compiler_spec.rb +446 -0
- data/spec/java/java_spec.rb +88 -0
- data/spec/java/packaging_spec.rb +1103 -0
- data/spec/java/tests_spec.rb +466 -0
- data/spec/packaging/archive_spec.rb +503 -0
- data/spec/packaging/artifact_spec.rb +754 -0
- data/spec/packaging/packaging_helper.rb +63 -0
- data/spec/packaging/packaging_spec.rb +589 -0
- data/spec/sandbox.rb +137 -0
- data/spec/scala/compiler_spec.rb +228 -0
- data/spec/scala/tests_spec.rb +215 -0
- data/spec/spec_helpers.rb +304 -0
- data/spec/version_requirement_spec.rb +123 -0
- metadata +369 -0
@@ -0,0 +1,566 @@
|
|
1
|
+
# Licensed to the Apache Software Foundation (ASF) under one or more
|
2
|
+
# contributor license agreements. See the NOTICE file distributed with this
|
3
|
+
# work for additional information regarding copyright ownership. The ASF
|
4
|
+
# licenses this file to you under the Apache License, Version 2.0 (the
|
5
|
+
# "License"); you may not use this file except in compliance with the License.
|
6
|
+
# You may obtain a copy of the License at
|
7
|
+
#
|
8
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
9
|
+
#
|
10
|
+
# Unless required by applicable law or agreed to in writing, software
|
11
|
+
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
12
|
+
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
13
|
+
# License for the specific language governing permissions and limitations under
|
14
|
+
# the License.
|
15
|
+
|
16
|
+
|
17
|
+
require File.join(File.dirname(__FILE__), '../spec_helpers')
|
18
|
+
|
19
|
+
|
20
|
+
module CompilerHelper
|
21
|
+
def compile_task
|
22
|
+
@compile_task ||= define('foo').compile.using(:javac)
|
23
|
+
end
|
24
|
+
|
25
|
+
def sources
|
26
|
+
@sources ||= ['Test1.java', 'Test2.java'].map { |f| File.join('src/main/java/thepackage', f) }.
|
27
|
+
each { |src| write src, "package thepackage; class #{src.pathmap('%n')} {}" }
|
28
|
+
end
|
29
|
+
|
30
|
+
def jars
|
31
|
+
@jars ||= begin
|
32
|
+
write 'jars/src/main/java/Dependency.java', 'class Dependency { }'
|
33
|
+
define 'jars', :version=>'1.0', :base_dir => 'jars' do
|
34
|
+
package(:jar, :id=>'jar1')
|
35
|
+
package(:jar, :id=>'jar2')
|
36
|
+
end
|
37
|
+
project('jars').packages.map(&:to_s)
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
|
43
|
+
describe Buildr::CompileTask do
|
44
|
+
include CompilerHelper
|
45
|
+
|
46
|
+
it 'should respond to from() and return self' do
|
47
|
+
compile_task.from(sources).should be(compile_task)
|
48
|
+
end
|
49
|
+
|
50
|
+
it 'should respond to from() and add sources' do
|
51
|
+
compile_task.from sources, File.dirname(sources.first)
|
52
|
+
compile_task.sources.should == sources + [File.dirname(sources.first)]
|
53
|
+
end
|
54
|
+
|
55
|
+
it 'should respond to with() and return self' do
|
56
|
+
compile_task.with('test.jar').should be(compile_task)
|
57
|
+
end
|
58
|
+
|
59
|
+
it 'should respond to with() and add dependencies' do
|
60
|
+
jars = (1..3).map { |i| "test#{i}.jar" }
|
61
|
+
compile_task.with *jars
|
62
|
+
compile_task.dependencies.should == artifacts(jars)
|
63
|
+
end
|
64
|
+
|
65
|
+
it 'should respond to into() and return self' do
|
66
|
+
compile_task.into('code').should be(compile_task)
|
67
|
+
end
|
68
|
+
|
69
|
+
it 'should respond to into() and create file task' do
|
70
|
+
compile_task.from(sources).into('code')
|
71
|
+
lambda { file('code').invoke }.should run_task('foo:compile')
|
72
|
+
end
|
73
|
+
|
74
|
+
it 'should respond to using() and return self' do
|
75
|
+
compile_task.using(:source=>'1.4').should eql(compile_task)
|
76
|
+
end
|
77
|
+
|
78
|
+
it 'should respond to using() and set options' do
|
79
|
+
compile_task.using(:source=>'1.4', 'target'=>'1.5')
|
80
|
+
compile_task.options.source.should eql('1.4')
|
81
|
+
compile_task.options.target.should eql('1.5')
|
82
|
+
end
|
83
|
+
|
84
|
+
it 'should attempt to identify compiler' do
|
85
|
+
Compiler.compilers.first.should_receive(:applies_to?).at_least(:once)
|
86
|
+
define('foo')
|
87
|
+
end
|
88
|
+
|
89
|
+
it 'should only support existing compilers' do
|
90
|
+
lambda { define('foo') { compile.using(:unknown) } }.should raise_error(ArgumentError, /unknown compiler/i)
|
91
|
+
end
|
92
|
+
|
93
|
+
it 'should only allow setting the compiler once' do
|
94
|
+
lambda { define('foo') { compile.using(:javac).using(:scalac) } }.should raise_error(RuntimeError, /already selected/i)
|
95
|
+
end
|
96
|
+
end
|
97
|
+
|
98
|
+
|
99
|
+
describe Buildr::CompileTask, '#compiler' do
|
100
|
+
it 'should be nil if no compiler identifier' do
|
101
|
+
define('foo').compile.compiler.should be_nil
|
102
|
+
end
|
103
|
+
|
104
|
+
it 'should return the selected compiler' do
|
105
|
+
define('foo') { compile.using(:javac) }
|
106
|
+
project('foo').compile.compiler.should eql(:javac)
|
107
|
+
end
|
108
|
+
|
109
|
+
it 'should attempt to identify compiler if sources are specified' do
|
110
|
+
define 'foo' do
|
111
|
+
Compiler.compilers.first.should_receive(:applies_to?).at_least(:once)
|
112
|
+
compile.from('sources').compiler
|
113
|
+
end
|
114
|
+
end
|
115
|
+
end
|
116
|
+
|
117
|
+
|
118
|
+
describe Buildr::CompileTask, '#language' do
|
119
|
+
it 'should be nil if no compiler identifier' do
|
120
|
+
define('foo').compile.language.should be_nil
|
121
|
+
end
|
122
|
+
|
123
|
+
it 'should return the appropriate language' do
|
124
|
+
define('foo') { compile.using(:javac) }
|
125
|
+
project('foo').compile.language.should eql(:java)
|
126
|
+
end
|
127
|
+
end
|
128
|
+
|
129
|
+
|
130
|
+
describe Buildr::CompileTask, '#sources' do
|
131
|
+
include CompilerHelper
|
132
|
+
|
133
|
+
it 'should be empty if no sources in default directory' do
|
134
|
+
compile_task.sources.should be_empty
|
135
|
+
end
|
136
|
+
|
137
|
+
it 'should point to default directory if it contains sources' do
|
138
|
+
write 'src/main/java', ''
|
139
|
+
compile_task.sources.first.should point_to_path('src/main/java')
|
140
|
+
end
|
141
|
+
|
142
|
+
it 'should be an array' do
|
143
|
+
compile_task.sources += sources
|
144
|
+
compile_task.sources.should == sources
|
145
|
+
end
|
146
|
+
|
147
|
+
it 'should allow files' do
|
148
|
+
compile_task.from(sources).into('classes').invoke
|
149
|
+
sources.each { |src| file(src.pathmap('classes/thepackage/%n.class')).should exist }
|
150
|
+
end
|
151
|
+
|
152
|
+
it 'should allow directories' do
|
153
|
+
compile_task.from(File.dirname(sources.first)).into('classes').invoke
|
154
|
+
sources.each { |src| file(src.pathmap('classes/thepackage/%n.class')).should exist }
|
155
|
+
end
|
156
|
+
|
157
|
+
it 'should allow tasks' do
|
158
|
+
lambda { compile_task.from(file(sources.first)).into('classes').invoke }.should run_task('foo:compile')
|
159
|
+
end
|
160
|
+
|
161
|
+
it 'should act as prerequisites' do
|
162
|
+
file('src2') { |task| task('prereq').invoke ; mkpath task.name }
|
163
|
+
lambda { compile_task.from('src2').into('classes').invoke }.should run_task('prereq')
|
164
|
+
end
|
165
|
+
end
|
166
|
+
|
167
|
+
|
168
|
+
describe Buildr::CompileTask, '#dependencies' do
|
169
|
+
include CompilerHelper
|
170
|
+
|
171
|
+
it 'should be empty' do
|
172
|
+
compile_task.dependencies.should be_empty
|
173
|
+
end
|
174
|
+
|
175
|
+
it 'should be an array' do
|
176
|
+
compile_task.dependencies += jars
|
177
|
+
compile_task.dependencies.should == jars
|
178
|
+
end
|
179
|
+
|
180
|
+
it 'should allow files' do
|
181
|
+
compile_task.from(sources).with(jars).into('classes').invoke
|
182
|
+
sources.each { |src| file(src.pathmap('classes/thepackage/%n.class')).should exist }
|
183
|
+
end
|
184
|
+
|
185
|
+
it 'should allow tasks' do
|
186
|
+
compile_task.from(sources).with(file(jars.first)).into('classes').invoke
|
187
|
+
end
|
188
|
+
|
189
|
+
it 'should allow artifacts' do
|
190
|
+
artifact('group:id:jar:1.0') { |task| mkpath File.dirname(task.to_s) ; cp jars.first.to_s, task.to_s }.enhance jars
|
191
|
+
compile_task.from(sources).with('group:id:jar:1.0').into('classes').invoke
|
192
|
+
end
|
193
|
+
|
194
|
+
it 'should allow projects' do
|
195
|
+
define('bar', :version=>'1', :group=>'self') { package :jar }
|
196
|
+
compile_task.with project('bar')
|
197
|
+
compile_task.dependencies.should == project('bar').packages
|
198
|
+
end
|
199
|
+
|
200
|
+
it 'should be accessible as classpath' do
|
201
|
+
lambda { compile_task.classpath = jars }.should change(compile_task, :dependencies).to(jars)
|
202
|
+
lambda { compile_task.dependencies = [] }.should change(compile_task, :classpath).to([])
|
203
|
+
end
|
204
|
+
|
205
|
+
end
|
206
|
+
|
207
|
+
|
208
|
+
describe Buildr::CompileTask, '#target' do
|
209
|
+
include CompilerHelper
|
210
|
+
|
211
|
+
it 'should be a file task' do
|
212
|
+
compile_task.from(@sources).into('classes')
|
213
|
+
compile_task.target.should be_kind_of(Rake::FileTask)
|
214
|
+
end
|
215
|
+
|
216
|
+
it 'should accept a task' do
|
217
|
+
task = file('classes')
|
218
|
+
compile_task.into(task).target.should be(task)
|
219
|
+
end
|
220
|
+
|
221
|
+
it 'should create dependency in file task when set' do
|
222
|
+
compile_task.from(sources).into('classes')
|
223
|
+
lambda { file('classes').invoke }.should run_task('foo:compile')
|
224
|
+
end
|
225
|
+
end
|
226
|
+
|
227
|
+
|
228
|
+
describe Buildr::CompileTask, '#options' do
|
229
|
+
include CompilerHelper
|
230
|
+
|
231
|
+
it 'should have getter and setter methods' do
|
232
|
+
compile_task.options.foo = 'bar'
|
233
|
+
compile_task.options.foo.should eql('bar')
|
234
|
+
end
|
235
|
+
|
236
|
+
it 'should have bracket accessors' do
|
237
|
+
compile_task.options[:foo] = 'bar'
|
238
|
+
compile_task.options[:foo].should eql('bar')
|
239
|
+
end
|
240
|
+
|
241
|
+
it 'should map from bracket accessor to get/set accessor' do
|
242
|
+
compile_task.options[:foo] = 'bar'
|
243
|
+
compile_task.options.foo.should eql('bar')
|
244
|
+
end
|
245
|
+
|
246
|
+
it 'should be independent of parent' do
|
247
|
+
define 'foo' do
|
248
|
+
compile.using(:javac, :source=>'1.4')
|
249
|
+
define 'bar' do
|
250
|
+
compile.using(:javac, :source=>'1.5')
|
251
|
+
end
|
252
|
+
end
|
253
|
+
project('foo').compile.options.source.should eql('1.4')
|
254
|
+
project('foo:bar').compile.options.source.should eql('1.5')
|
255
|
+
end
|
256
|
+
end
|
257
|
+
|
258
|
+
|
259
|
+
describe Buildr::CompileTask, '#invoke' do
|
260
|
+
include CompilerHelper
|
261
|
+
|
262
|
+
it 'should compile into target directory' do
|
263
|
+
compile_task.from(sources).into('code').invoke
|
264
|
+
Dir['code/thepackage/*.class'].should_not be_empty
|
265
|
+
end
|
266
|
+
|
267
|
+
it 'should compile only once' do
|
268
|
+
compile_task.from(sources)
|
269
|
+
lambda { compile_task.target.invoke }.should run_task('foo:compile')
|
270
|
+
lambda { compile_task.invoke }.should_not run_task('foo:compile')
|
271
|
+
end
|
272
|
+
|
273
|
+
it 'should compile if there are source files to compile' do
|
274
|
+
lambda { compile_task.from(sources).invoke }.should run_task('foo:compile')
|
275
|
+
end
|
276
|
+
|
277
|
+
it 'should not compile unless there are source files to compile' do
|
278
|
+
lambda { compile_task.invoke }.should_not run_task('foo:compile')
|
279
|
+
end
|
280
|
+
|
281
|
+
it 'should require source file or directory to exist' do
|
282
|
+
lambda { compile_task.from('empty').into('classes').invoke }.should raise_error(RuntimeError, /Don't know how to build/)
|
283
|
+
end
|
284
|
+
|
285
|
+
it 'should run all source files as prerequisites' do
|
286
|
+
file(mkpath('src')).should_receive :invoke_prerequisites
|
287
|
+
compile_task.from('src').invoke
|
288
|
+
end
|
289
|
+
|
290
|
+
it 'should require dependencies to exist' do
|
291
|
+
lambda { compile_task.from(sources).with('no-such.jar').into('classes').invoke }.should \
|
292
|
+
raise_error(RuntimeError, /Don't know how to build/)
|
293
|
+
end
|
294
|
+
|
295
|
+
it 'should run all dependencies as prerequisites' do
|
296
|
+
file(File.expand_path('no-such.jar')) { |task| task('prereq').invoke }
|
297
|
+
lambda { compile_task.from(sources).with('no-such.jar').into('classes').invoke }.should run_tasks(['prereq', 'foo:compile'])
|
298
|
+
end
|
299
|
+
|
300
|
+
it 'should force compilation if no target' do
|
301
|
+
lambda { compile_task.from(sources).invoke }.should run_task('foo:compile')
|
302
|
+
end
|
303
|
+
|
304
|
+
it 'should force compilation if target empty' do
|
305
|
+
time = Time.now
|
306
|
+
mkpath compile_task.target.to_s
|
307
|
+
File.utime(time - 1, time - 1, compile_task.target.to_s)
|
308
|
+
lambda { compile_task.from(sources).invoke }.should run_task('foo:compile')
|
309
|
+
end
|
310
|
+
|
311
|
+
it 'should force compilation if sources newer than compiled' do
|
312
|
+
# Simulate class files that are older than source files.
|
313
|
+
time = Time.now
|
314
|
+
sources.each { |src| File.utime(time + 1, time + 1, src) }
|
315
|
+
sources.map { |src| src.pathmap("#{compile_task.target}/thepackage/%n.class") }.
|
316
|
+
each { |kls| write kls ; File.utime(time, time, kls) }
|
317
|
+
File.utime(time - 1, time - 1, project('foo').compile.target.to_s)
|
318
|
+
lambda { compile_task.from(sources).invoke }.should run_task('foo:compile')
|
319
|
+
end
|
320
|
+
|
321
|
+
it 'should not force compilation if sources older than compiled' do
|
322
|
+
# When everything has the same timestamp, nothing is compiled again.
|
323
|
+
time = Time.now
|
324
|
+
sources.map { |src| src.pathmap("#{compile_task.target}/thepackage/%n.class") }.
|
325
|
+
each { |kls| write kls ; File.utime(time, time, kls) }
|
326
|
+
lambda { compile_task.from(sources).invoke }.should_not run_task('foo:compile')
|
327
|
+
end
|
328
|
+
|
329
|
+
it 'should force compilation if dependencies newer than compiled' do
|
330
|
+
jars; project('jars').task("package").invoke
|
331
|
+
# On my machine the times end up the same, so need to push dependencies in the past.
|
332
|
+
time = Time.now
|
333
|
+
sources.map { |src| src.pathmap("#{compile_task.target}/thepackage/%n.class") }.
|
334
|
+
each { |kls| write kls ; File.utime(time - 1, time - 1, kls) }
|
335
|
+
File.utime(time - 1, time - 1, project('foo').compile.target.to_s)
|
336
|
+
jars.each { |jar| File.utime(time + 1, time + 1, jar) }
|
337
|
+
lambda { compile_task.from(sources).with(jars).invoke }.should run_task('foo:compile')
|
338
|
+
end
|
339
|
+
|
340
|
+
it 'should not force compilation if dependencies older than compiled' do
|
341
|
+
jars; project('jars').task("package").invoke
|
342
|
+
time = Time.now
|
343
|
+
jars.each { |jar| File.utime(time - 1 , time - 1, jar) }
|
344
|
+
sources.map { |src| File.utime(time, time, src); src.pathmap("#{compile_task.target}/thepackage/%n.class") }.
|
345
|
+
each { |kls| write kls ; File.utime(time, time, kls) }
|
346
|
+
lambda { compile_task.from(sources).with(jars).invoke }.should_not run_task('foo:compile')
|
347
|
+
end
|
348
|
+
|
349
|
+
it 'should timestamp target directory if specified' do
|
350
|
+
time = Time.now - 10
|
351
|
+
mkpath compile_task.target.to_s
|
352
|
+
File.utime(time, time, compile_task.target.to_s)
|
353
|
+
compile_task.timestamp.should be_close(time, 1)
|
354
|
+
end
|
355
|
+
|
356
|
+
it 'should touch target if anything compiled' do
|
357
|
+
mkpath compile_task.target.to_s
|
358
|
+
File.utime(Time.now - 10, Time.now - 10, compile_task.target.to_s)
|
359
|
+
compile_task.from(sources).invoke
|
360
|
+
File.stat(compile_task.target.to_s).mtime.should be_close(Time.now, 2)
|
361
|
+
end
|
362
|
+
|
363
|
+
it 'should not touch target if nothing compiled' do
|
364
|
+
mkpath compile_task.target.to_s
|
365
|
+
File.utime(Time.now - 10, Time.now - 10, compile_task.target.to_s)
|
366
|
+
compile_task.invoke
|
367
|
+
File.stat(compile_task.target.to_s).mtime.should be_close(Time.now - 10, 2)
|
368
|
+
end
|
369
|
+
|
370
|
+
it 'should not touch target if failed to compile' do
|
371
|
+
mkpath compile_task.target.to_s
|
372
|
+
File.utime(Time.now - 10, Time.now - 10, compile_task.target.to_s)
|
373
|
+
write 'failed.java', 'not a class'
|
374
|
+
suppress_stdout { compile_task.from('failed.java').invoke rescue nil }
|
375
|
+
File.stat(compile_task.target.to_s).mtime.should be_close(Time.now - 10, 2)
|
376
|
+
end
|
377
|
+
|
378
|
+
it 'should complain if source directories and no compiler selected' do
|
379
|
+
mkpath 'sources'
|
380
|
+
define 'bar' do
|
381
|
+
lambda { compile.from('sources').invoke }.should raise_error(RuntimeError, /no compiler selected/i)
|
382
|
+
end
|
383
|
+
end
|
384
|
+
end
|
385
|
+
|
386
|
+
|
387
|
+
describe 'accessor task', :shared=>true do
|
388
|
+
it 'should return a task' do
|
389
|
+
define('foo').send(@task_name).should be_kind_of(Rake::Task)
|
390
|
+
end
|
391
|
+
|
392
|
+
it 'should always return the same task' do
|
393
|
+
task_name, task = @task_name, nil
|
394
|
+
define('foo') { task = self.send(task_name) }
|
395
|
+
project('foo').send(task_name).should be(task)
|
396
|
+
end
|
397
|
+
|
398
|
+
it 'should be unique for the project' do
|
399
|
+
define('foo') { define 'bar' }
|
400
|
+
project('foo').send(@task_name).should_not eql(project('foo:bar').send(@task_name))
|
401
|
+
end
|
402
|
+
|
403
|
+
it 'should be named after the project' do
|
404
|
+
define('foo') { define 'bar' }
|
405
|
+
project('foo:bar').send(@task_name).name.should eql("foo:bar:#{@task_name}")
|
406
|
+
end
|
407
|
+
end
|
408
|
+
|
409
|
+
|
410
|
+
describe Project, '#compile' do
|
411
|
+
before { @task_name = 'compile' }
|
412
|
+
it_should_behave_like 'accessor task'
|
413
|
+
|
414
|
+
it 'should return a compile task' do
|
415
|
+
define('foo').compile.should be_instance_of(CompileTask)
|
416
|
+
end
|
417
|
+
|
418
|
+
it 'should accept sources and add to source list' do
|
419
|
+
define('foo') { compile('file1', 'file2') }
|
420
|
+
project('foo').compile.sources.should include('file1', 'file2')
|
421
|
+
end
|
422
|
+
|
423
|
+
it 'should accept block and enhance task' do
|
424
|
+
write 'src/main/java/Test.java', 'class Test {}'
|
425
|
+
action = task('action')
|
426
|
+
define('foo') { compile { action.invoke } }
|
427
|
+
lambda { project('foo').compile.invoke }.should run_tasks('foo:compile', action)
|
428
|
+
end
|
429
|
+
|
430
|
+
it 'should execute resources task' do
|
431
|
+
define 'foo'
|
432
|
+
lambda { project('foo').compile.invoke }.should run_task('foo:resources')
|
433
|
+
end
|
434
|
+
|
435
|
+
it 'should be recursive' do
|
436
|
+
write 'bar/src/main/java/Test.java', 'class Test {}'
|
437
|
+
define('foo') { define 'bar' }
|
438
|
+
lambda { project('foo').compile.invoke }.should run_task('foo:bar:compile')
|
439
|
+
end
|
440
|
+
|
441
|
+
it 'should be a local task' do
|
442
|
+
write 'bar/src/main/java/Test.java', 'class Test {}'
|
443
|
+
define('foo') { define 'bar' }
|
444
|
+
lambda do
|
445
|
+
in_original_dir project('foo:bar').base_dir do
|
446
|
+
task('compile').invoke
|
447
|
+
end
|
448
|
+
end.should run_task('foo:bar:compile').but_not('foo:compile')
|
449
|
+
end
|
450
|
+
|
451
|
+
it 'should run from build task' do
|
452
|
+
write 'bar/src/main/java/Test.java', 'class Test {}'
|
453
|
+
define('foo') { define 'bar' }
|
454
|
+
lambda { task('build').invoke }.should run_task('foo:bar:compile')
|
455
|
+
end
|
456
|
+
|
457
|
+
it 'should clean after itself' do
|
458
|
+
mkpath 'code'
|
459
|
+
define('foo') { compile.into('code') }
|
460
|
+
lambda { task('clean').invoke }.should change { File.exist?('code') }.to(false)
|
461
|
+
end
|
462
|
+
end
|
463
|
+
|
464
|
+
|
465
|
+
describe Project, '#resources' do
|
466
|
+
before { @task_name = 'resources' }
|
467
|
+
it_should_behave_like 'accessor task'
|
468
|
+
|
469
|
+
it 'should return a resources task' do
|
470
|
+
define('foo').resources.should be_instance_of(ResourcesTask)
|
471
|
+
end
|
472
|
+
|
473
|
+
it 'should provide a filter' do
|
474
|
+
define('foo').resources.filter.should be_instance_of(Filter)
|
475
|
+
end
|
476
|
+
|
477
|
+
it 'should include src/main/resources as source directory' do
|
478
|
+
write 'src/main/resources/test'
|
479
|
+
define('foo').resources.sources.first.should point_to_path('src/main/resources')
|
480
|
+
end
|
481
|
+
|
482
|
+
it 'should include src/main/resources directory only if it exists' do
|
483
|
+
define('foo').resources.sources.should be_empty
|
484
|
+
end
|
485
|
+
|
486
|
+
it 'should accept prerequisites' do
|
487
|
+
tasks = ['task1', 'task2'].each { |name| task(name) }
|
488
|
+
define('foo') { resources 'task1', 'task2' }
|
489
|
+
lambda { project('foo').resources.invoke }.should run_tasks('task1', 'task2')
|
490
|
+
end
|
491
|
+
|
492
|
+
it 'should respond to from and add additional sources' do
|
493
|
+
write 'src/main/resources/original'
|
494
|
+
write 'extra/spicy'
|
495
|
+
define('foo') { resources.from 'extra' }
|
496
|
+
project('foo').resources.invoke
|
497
|
+
FileList['target/resources/*'].sort.should == ['target/resources/original', 'target/resources/spicy']
|
498
|
+
end
|
499
|
+
|
500
|
+
it 'should pass include pattern to filter' do
|
501
|
+
3.times { |i| write "src/main/resources/test#{i + 1}" }
|
502
|
+
define('foo') { resources.include('test2') }
|
503
|
+
project('foo').resources.invoke
|
504
|
+
FileList['target/resources/*'].should == ['target/resources/test2']
|
505
|
+
end
|
506
|
+
|
507
|
+
it 'should pass exclude pattern to filter' do
|
508
|
+
3.times { |i| write "src/main/resources/test#{i + 1}" }
|
509
|
+
define('foo') { resources.exclude('test2') }
|
510
|
+
project('foo').resources.invoke
|
511
|
+
FileList['target/resources/*'].sort.should == ['target/resources/test1', 'target/resources/test3']
|
512
|
+
end
|
513
|
+
|
514
|
+
it 'should accept block and enhance task' do
|
515
|
+
action = task('action')
|
516
|
+
define('foo') { resources { action.invoke } }
|
517
|
+
lambda { project('foo').resources.invoke }.should run_tasks('foo:resources', action)
|
518
|
+
end
|
519
|
+
|
520
|
+
it 'should set target directory to target/resources' do
|
521
|
+
write 'src/main/resources/foo'
|
522
|
+
define('foo').resources.target.to_s.should point_to_path('target/resources')
|
523
|
+
end
|
524
|
+
|
525
|
+
it 'should use provided target directoy' do
|
526
|
+
define('foo') { resources.filter.into('the_resources') }
|
527
|
+
project('foo').resources.target.to_s.should point_to_path('the_resources')
|
528
|
+
end
|
529
|
+
|
530
|
+
it 'should create file task for target directory' do
|
531
|
+
write 'src/main/resources/foo'
|
532
|
+
define 'foo'
|
533
|
+
project('foo').file('target/resources').invoke
|
534
|
+
file('target/resources/foo').should exist
|
535
|
+
end
|
536
|
+
|
537
|
+
it 'should copy resources to target directory' do
|
538
|
+
write 'src/main/resources/foo', 'Foo'
|
539
|
+
define('foo').compile.invoke
|
540
|
+
file('target/resources/foo').should contain('Foo')
|
541
|
+
end
|
542
|
+
|
543
|
+
it 'should not create target directory unless there are resources' do
|
544
|
+
define('foo').compile.invoke
|
545
|
+
file('target/resources').should_not exist
|
546
|
+
end
|
547
|
+
|
548
|
+
it 'should not be recursive' do
|
549
|
+
define('foo') { define 'bar' }
|
550
|
+
lambda { project('foo').resources.invoke }.should_not run_task('foo:bar:resources')
|
551
|
+
end
|
552
|
+
|
553
|
+
it 'should use current profile for filtering' do
|
554
|
+
write 'profiles.yaml', <<-YAML
|
555
|
+
development:
|
556
|
+
filter:
|
557
|
+
foo: bar
|
558
|
+
test:
|
559
|
+
filter:
|
560
|
+
foo: baz
|
561
|
+
YAML
|
562
|
+
write 'src/main/resources/foo', '${foo}'
|
563
|
+
define('foo').compile.invoke
|
564
|
+
file('target/resources/foo').should contain('bar')
|
565
|
+
end
|
566
|
+
end
|