buildr 0.16.0 → 0.18.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -2,57 +2,120 @@ module Buildr
2
2
 
3
3
  class JUnitTask < Rake::Task
4
4
 
5
- attr_accessor :base_dir
6
- attr_accessor :target
7
5
  attr_accessor :classpath
8
6
 
9
7
  def initialize(*args)
10
8
  super
11
9
  @classpath = []
10
+ @paths = []
11
+ @include = []
12
+ @exclude = []
12
13
  enhance do |task|
13
- test_cases.each do |test|
14
- Dir.chdir base_dir
15
- java "junit.textui.TestRunner", test, :classpath=>real_classpath, :name=>"tests in #{test}"
14
+ if test_cases.empty?
15
+ puts "#{name}: No tests to run"
16
+ else
17
+ passed, failed = Java.junit(test_cases, :classpath=>classpath)
18
+ fail "#{name}: The following tests failed:\n#{failed.join("\n")}" unless failed.empty?
16
19
  end
17
20
  end
18
21
  end
19
22
 
23
+ def from(*files)
24
+ @paths += files
25
+ self
26
+ end
27
+
28
+ def include(*files)
29
+ @include += files
30
+ self
31
+ end
32
+
33
+ def exclude(*files)
34
+ @exclude += files
35
+ self
36
+ end
37
+
38
+ def with(*files)
39
+ @classpath |= artifacts(files.flatten).uniq
40
+ self
41
+ end
42
+
20
43
  def test_cases()
21
- target = File.expand_path(self.target)
22
- return [] unless File.exist?(target)
23
- prefix = Regexp.new("^" + Regexp.escape(target) + "/")
24
- FileList[File.join(target, "**", "*Test.class")].
25
- map { |path| path.sub(prefix, "").ext("").gsub(File::SEPARATOR, ".") }.sort
44
+ unless @cases
45
+ @include << "*" if @include.empty?
46
+ @cases = @paths.map do |path|
47
+ base = Pathname.new(path)
48
+ FileList[File.join(path, "**", "*Test.class")].
49
+ map { |file| Pathname.new(file).relative_path_from(base).to_s.ext("").gsub(File::SEPARATOR, ".") }.
50
+ select { |name| @include.any? { |pattern| File.fnmatch(pattern, name) } }.
51
+ reject { |name| @exclude.any? { |pattern| File.fnmatch(pattern, name) } }
52
+ end.flatten.sort
53
+ end
54
+ @cases
55
+ end
56
+
57
+ def invoke()
58
+ setup
59
+ begin
60
+ super
61
+ ensure
62
+ teardown
63
+ end
64
+ end
65
+
66
+ def needed?()
67
+ return true unless ENV["TESTS"] =~ /(no|off|false|disable)/i
68
+ end
69
+
70
+ def prerequisites()
71
+ super + classpath + @paths
72
+ end
73
+
74
+ def invoke_prerequisites()
75
+ prerequisites.each { |n| application[n, @scope].invoke }
26
76
  end
27
77
 
28
- def real_classpath()
29
- @real_classpath ||= artifacts(@classpath).map(&:to_s)
78
+ def setup()
79
+ Rake::Task[name.sub(/run$/, "setup")].invoke
80
+ end
81
+
82
+ def teardown()
83
+ Rake::Task[name.sub(/run$/, "teardown")].invoke
30
84
  end
31
85
 
32
86
  end
33
87
 
88
+
34
89
  class Tests
90
+
91
+ def initialize(project)
92
+ @project = project
93
+ end
94
+
35
95
  def prepare(*tasks, &block)
36
- returning(@prepare_task ||= task("prepare")) { |task| task.enhance tasks, &block }
96
+ @project.task("tests:prepare").enhance tasks, &block
37
97
  end
38
98
 
39
99
  def compile(*sources, &block)
40
- unless @compile_task
41
- @compile_task = Java::CompileTask.define_task("compile"=>prepare) { |task| resources.invoke }
42
- end
43
- returning(@compile_task) { |task| task.sources |= sources ; task.enhance &block }
100
+ @project.task("tests:compile").from(sources).enhance &block
44
101
  end
45
-
102
+
46
103
  def resources(*tasks, &block)
47
- returning(@resources_task ||= Filter.define_task("resources")) { |task| task.enhance tasks, &block }
104
+ @project.task("tests:resources").enhance tasks, &block
48
105
  end
49
106
 
50
- def junit(*tasks, &block)
51
- unless @junit_task
52
- @junit_task = JUnitTask.define_task("junit"=>compile)
53
- end
54
- returning(@junit_task) { |task| task.enhance tasks, &block }
107
+ def setup(*tasks, &block)
108
+ @project.task("tests:setup").enhance tasks, &block
109
+ end
110
+
111
+ def run(*tasks, &block)
112
+ @project.task("tests:run").enhance tasks, &block
113
+ end
114
+
115
+ def teardown(*tasks, &block)
116
+ @project.task("tests:teardown").enhance tasks, &block
55
117
  end
118
+
56
119
  end
57
120
 
58
121
  class Project
@@ -61,45 +124,52 @@ module Buildr
61
124
  inherited_attr :test_target_dir do File.join(target_dir, "test-classes") end
62
125
 
63
126
  def tests()
64
- @tests ||= Tests.new
127
+ @tests ||= Tests.new(self)
65
128
  end
66
129
 
67
130
  def test(*tasks, &block)
68
- @tests.junit *tasks, &block
131
+ tests.run *tasks, &block
69
132
  end
70
133
  end
71
134
 
72
135
  # Global task compiles all projects.
73
136
  desc "Run all test cases"
74
- LocalDirectoryTask.define_task "test"
137
+ Project.local_task task("test")
75
138
 
76
139
  Project.on_define do |project|
77
- tests = nil
78
- namespace "test" do
79
- tests = project.tests
80
- #tests.compile.enhance([tests.prepare]) { |task| tests.resources.invoke }
81
- tests.compile.classpath += [ "junit:junit:jar:3.8.1", "jmock:jmock:jar:1.1.0" ]
82
- tests.junit
83
- end
84
- tests.compile.enhance [ project.compile ]
140
+ namespace "tests" do
141
+ # Compile task requires prepare and performs resources, if anything compiled.
142
+ #Java::CompileTask.define_task("compile"=>[project.compile, task("prepare")]) { |task| project.tests.resources.invoke }
143
+ Java::CompileTask.define_task("compile"=>[project.compile, task("prepare")]) { |task| project.tests.resources.invoke }
144
+ # Resources task is a filter.
145
+ FilterTask.define_task("resources")
146
+ JUnitTask.define_task("run"=>task("compile"))
147
+ task("setup")
148
+ task("teardown")
149
+ end
150
+ project.tests.compile.with Java::JUNIT_REQUIRES
85
151
  project.recursive_task("test"=>project.test)
86
152
 
87
- #project.recursive_task("compile")
88
- #task("build").enhance [ project.compile ]
89
- #task("clean") { rm_rf project.path_to(:target_dir), :verbose=>false }
90
-
91
- project.after_block do |project|
92
- tests.compile.sources << project.path_to(:test_src_dir) if File.exist?(project.path_to(:test_src_dir))
93
- tests.compile.target ||= project.path_to(:test_target_dir)
94
- tests.compile.classpath << project.compile.target
95
- tests.resources.include project.path_to(:test_resources_dir, "*") if File.exists?(project.path_to(:test_resources_dir))
96
- tests.resources.target ||= tests.compile.target
97
- tests.junit.target = tests.compile.target
98
- tests.junit.classpath += tests.compile.classpath
99
- tests.junit.classpath += [ tests.compile.target, project.compile.target ]
100
- tests.junit.base_dir = project.base_dir
101
- file(tests.compile.target).enhance [ tests.compile ]
102
- file(tests.resources.target).enhance [ tests.resources ]
153
+ project.enhance do |project|
154
+ project.tests.compile.from project.path_to(:test_src_dir) if File.exist?(project.path_to(:test_src_dir))
155
+ project.tests.compile.into project.path_to(:test_target_dir) unless project.tests.compile.target
156
+ project.tests.resources.include project.path_to(:test_resources_dir, "*") if File.exists?(project.path_to(:test_resources_dir))
157
+ project.tests.resources.into project.tests.compile.target unless project.tests.resources.target
158
+
159
+ project.tests.compile.classpath += project.compile.classpath
160
+ project.tests.compile.classpath << project.compile.target
161
+ project.tests.run.from project.tests.compile.target
162
+ project.tests.run.classpath += project.tests.compile.classpath
163
+ project.tests.run.classpath << project.tests.compile.target
103
164
  end
165
+
166
+ end
167
+
168
+ rule /^test:.*$/ do |task|
169
+ test = task.name.scan(/test:(.*)/)[0][0]
170
+ Project.projects.select { |project| project.base_dir == Rake.application.original_dir }.
171
+ map { |project| project.task("tests:run") }.
172
+ each { |task| task.include("*#{test}").invoke }
104
173
  end
174
+
105
175
  end
@@ -9,8 +9,6 @@ module Buildr
9
9
  options[:verbose] ||= Rake.application.options.trace || false
10
10
  fu_check_options options, :verbose, :noop, :javasource, :jar, :classes, :output
11
11
 
12
- # Classpath for XMLBeans.
13
- cp = REQUIRES.map { |id| artifact(id) }.each(&:invoke).map(&:to_s).join(File::PATH_SEPARATOR)
14
12
  # Options for SchemaCompiler.
15
13
  cmd_args = [ options[:verbose] ? "-verbose" : "-quiet" ]
16
14
  cmd_args << "-javasource" << options[:javasource].collect.join(File::PATH_SEPARATOR) if options[:javasource]
@@ -21,10 +19,10 @@ module Buildr
21
19
  cmd_args << { :verbose=>options[:verbose] }
22
20
 
23
21
  unless options[:noop]
24
- verbose { puts "Running XMLBeans schema compiler" }
22
+ puts "Running XMLBeans schema compiler" if verbose
25
23
  mkpath options[:classes], :verbose=>false rescue nil if options[:classes]
26
24
  mkpath options[:output], :verbose=>false rescue nil if options[:output]
27
- sh(Java.path_to_bin("java"), "-Xmx256m", "-cp", cp,
25
+ sh(Java.path_to_bin("java"), "-Xmx256m", "-cp", requires.join(File::PATH_SEPARATOR),
28
26
  "org.apache.xmlbeans.impl.tool.SchemaCompiler", *cmd_args) { |ok, res|
29
27
  fail "Failed to compile schemas, see errors above" unless ok }
30
28
  # Touch paths to let other tasks know there's an update.
@@ -32,6 +30,10 @@ module Buildr
32
30
  touch options[:output], :verbose=>false if options[:output]
33
31
  end
34
32
  end
33
+
34
+ def self.requires()
35
+ @requires ||= artifacts(REQUIRES).each { |artifact| artifact.invoke }.map(&:to_s)
36
+ end
35
37
 
36
38
  class CompileTask < Rake::FileTask
37
39
 
@@ -1,9 +1,9 @@
1
1
  module Buildr
2
2
 
3
- class Filter < Rake::Task
3
+ class FilterTask < Rake::Task
4
4
 
5
5
  # The target directory.
6
- attr_accessor :target
6
+ attr_reader :target
7
7
  # Filter to use.
8
8
  attr_accessor :filter
9
9
 
@@ -46,7 +46,11 @@ module Buildr
46
46
  end
47
47
 
48
48
  def into(dir)
49
- self.target = dir
49
+ dir = File.expand_path(dir)
50
+ unless @target == dir
51
+ @target = dir
52
+ file(dir).enhance [self]
53
+ end
50
54
  self
51
55
  end
52
56
 
@@ -55,6 +59,13 @@ module Buildr
55
59
  self
56
60
  end
57
61
 
62
+ def needed?
63
+ return false if target.nil? || copy_map.empty?
64
+ return true unless File.exist?(target)
65
+ return true if copy_map.any? { |dest, src| !File.exist?(dest) || File.mtime(src) > File.mtime(dest) }
66
+ false
67
+ end
68
+
58
69
  protected
59
70
 
60
71
  # Return a copy map of all the files that need copying: the key is
@@ -89,7 +100,7 @@ module Buildr
89
100
 
90
101
  def filter(*files)
91
102
  task = nil
92
- namespace { task = Filter.define_task("filter").include *files }
103
+ namespace { task = FilterTask.define_task("filter").include *files }
93
104
  task
94
105
  end
95
106
 
@@ -19,18 +19,19 @@ module Buildr
19
19
  else
20
20
  options = {}
21
21
  end
22
+ files = files.flatten
22
23
 
23
24
  if options[:path]
24
25
  path(options[:path]).include *files +[ options.reject { |k,v| k == :path } ]
25
26
  elsif options[:as]
26
27
  raise "You can only use the :as option in combination with the :path option" unless options.keys.size == 1
27
28
  raise "You can only use one file with the :as option" unless files.size == 1
28
- include_as(files.first, options[:as])
29
+ include_as(files.first.to_s, options[:as])
29
30
  elsif options[:merge]
30
31
  raise "You can only use the :merge option in combination with the :path option" unless options.keys.size == 1
31
32
  files.each { |file| merge file }
32
33
  elsif options.keys.empty?
33
- (@files ||= FileList[]).include *files
34
+ (@files ||= FileList[]).include files.map(&:to_s)
34
35
  else
35
36
  raise "Unrecognized option #{options.keys.join(", ")}"
36
37
  end
@@ -55,7 +56,7 @@ module Buildr
55
56
  path(options[:path]).merge *files +[ options.reject { |k,v| k == :path } ]
56
57
  elsif options.keys.empty?
57
58
  files.collect do |file|
58
- @expand_sources << proc { artifacts(file).map(&:to_s) }
59
+ @expand_sources << proc { file.to_s }
59
60
  expander = ZipExpander.new(file)
60
61
  @add_files << proc { |zip| expander.expand(zip, @path) }
61
62
  expander
@@ -69,7 +70,7 @@ module Buildr
69
70
 
70
71
  def setup_path(path = nil)
71
72
  @path = "#{path}/" if path
72
- expand_src = proc { artifacts(*@files || []).map(&:to_s) }
73
+ expand_src = proc { (@files || []).map(&:to_s).uniq }
73
74
  @expand_sources = [ expand_src ]
74
75
  @add_files = [] << proc do |zip|
75
76
  expand_src.call.each do |file|
@@ -87,9 +88,9 @@ module Buildr
87
88
  end
88
89
 
89
90
  def include_as(source, as)
90
- @expand_sources << proc { artifacts(source).map(&:to_s) }
91
+ @expand_sources << proc { source }
91
92
  @add_files << proc do |zip|
92
- file = artifacts(source).first.to_s
93
+ file = source.to_s
93
94
  if File.directory?(file)
94
95
  in_directory(file) do |file, rel_path|
95
96
  puts "Adding #{@path}#{as}/#{rel_path}" if Rake.application.options.trace
@@ -158,7 +159,7 @@ module Buildr
158
159
  class ZipExpander
159
160
 
160
161
  def initialize(zip_file)
161
- @zip_file = zip_file
162
+ @zip_file = zip_file.to_s
162
163
  end
163
164
 
164
165
  def include(*files)
@@ -176,7 +177,7 @@ module Buildr
176
177
  def expand(zip, path)
177
178
  @includes ||= ["*"]
178
179
  @excludes ||= []
179
- Zip::ZipFile.open(artifacts(@zip_file).map(&:to_s).first) do |source|
180
+ Zip::ZipFile.open(@zip_file) do |source|
180
181
  source.entries.reject { |entry| entry.directory? }.each do |entry|
181
182
  if @includes.any? { |pattern| File.fnmatch(pattern, entry.name) } &&
182
183
  !@excludes.any? { |pattern| File.fnmatch(pattern, entry.name) }
@@ -232,7 +233,7 @@ module Buildr
232
233
  most_recent = @paths.collect { |name, path| path.expand_sources }.flatten.
233
234
  each { |src| File.directory?(src) ? FileList[File.join(src, "**", "*")] | [src] : src }.flatten.
234
235
  select { |file| File.exist?(file) }.collect { |file| File.stat(file).mtime }.max
235
- File.stat(name).mtime < (most_recent || Rake::EARLY)
236
+ File.stat(name).mtime < (most_recent || Rake::EARLY) || super
236
237
  end
237
238
 
238
239
  protected
@@ -241,33 +242,6 @@ module Buildr
241
242
  @paths.each { |name, obj| obj.add_file zip }
242
243
  end
243
244
 
244
- def zip_map()
245
- unless @zip_map
246
- args = @paths.collect do |path, files|
247
- if path
248
- dest_for = proc { |f| File.join(path, f) }
249
- else
250
- dest_for = proc { |f| f }
251
- end
252
- artifacts(*files).map(&:to_s).collect do |file|
253
- if File.directory?(file)
254
- # Include all files inside the directory, with path starting
255
- # from the directory itself.
256
- prefix = File.dirname(file) + File::SEPARATOR
257
- Dir[File.join(file, "**", "*")].sort.
258
- reject { |file| File.directory?(file) || files.exclude?(file) }.
259
- collect { |file| [ dest_for[file.sub(prefix, "")], file ] }
260
- else
261
- # Include just that one file, sans its diectory path.
262
- [ dest_for[File.basename(file)], file ]
263
- end
264
- end
265
- end.flatten
266
- @zip_map = Hash[ *args ]
267
- end
268
- @zip_map
269
- end
270
-
271
245
  end
272
246
 
273
247
  # The ZipTask creates a new ZIP file. You can include any number of files and
metadata CHANGED
@@ -3,8 +3,8 @@ rubygems_version: 0.9.2
3
3
  specification_version: 1
4
4
  name: buildr
5
5
  version: !ruby/object:Gem::Version
6
- version: 0.16.0
7
- date: 2007-03-07 00:00:00 -08:00
6
+ version: 0.18.0
7
+ date: 2007-03-30 00:00:00 -07:00
8
8
  summary: A build system that doesn't suck
9
9
  require_paths:
10
10
  - lib
@@ -42,12 +42,19 @@ files:
42
42
  - lib/core/artifact.rb
43
43
  - lib/core/project.rb
44
44
  - lib/java/test.rb
45
+ - lib/java/eclipse.rb
46
+ - lib/java/jetty.rb
45
47
  - lib/java/xmlbeans.rb
46
48
  - lib/java/java.rb
47
49
  - lib/java/javacc.rb
48
50
  - lib/java/packaging.rb
49
51
  - lib/java/openjpa.rb
50
52
  - lib/java/compile.rb
53
+ - lib/java/jetty
54
+ - lib/java/jetty/JettyWrapper.java
55
+ - lib/java/jetty/JettyWrapper$1.class
56
+ - lib/java/jetty/JettyWrapper$BuildrHandler.class
57
+ - lib/java/jetty/JettyWrapper.class
51
58
  - CHANGELOG
52
59
  - README
53
60
  - LICENSE