raven 1.1.2 → 1.2

Sign up to get free protection for your applications and to get access to all the features.
@@ -34,7 +34,7 @@ module Raven
34
34
  opts.on('-m=ARG', '--mavenrepo repo_url', '[repository] Maven repository to build your gem repository from.') { |val| repo_url = val }
35
35
  opts.on('-p=ARG', '--proxy proxy_url', '[repository|install] Proxy url (http://<p_user>:<p_pwd>@<p_host>:<p_port>) for access outside corporate firewalls.') { |val| proxy_url = val }
36
36
  opts.on('-i=ARG', '--index index_url', '[install] URL of a directory containing repository indices.') { |val| index_url = val }
37
- opts.on('-g=ARG', '--group', '[install] Install artifacts in the provided group.') { |val| groupId = val }
37
+ opts.on('-p=ARG', '--project group_id', '[install] Install artifacts in the provided project.') { |val| groupId = val }
38
38
  opts.on('-a', '--all', '[install] Install all selected artifacts.') { |val| all = true }
39
39
  opts.on('-v', '--allversions', '[install] Select all versions, not only the latest.') { |val| allver = true }
40
40
 
@@ -94,9 +94,11 @@ module Raven
94
94
  av = artifact.match(/([^:]*):?(.*)/).to_a
95
95
  # Trock to see if we've been passed a version number or an artifact
96
96
  begin
97
- Integer(av[1][0..0])
98
- av[2] = av[1]
99
- av[1] = ''
97
+ aint = Integer(av[1][0..0])
98
+ if aint != 0
99
+ av[2] = av[1]
100
+ av[1] = ''
101
+ end
100
102
  rescue
101
103
  end
102
104
  begin
@@ -128,7 +130,7 @@ module Raven
128
130
  match = match.to_a
129
131
  match.shift
130
132
  puts "Using proxy #{match[2]} and port #{match[3]}"
131
- [match[2], match[3], match[0], match[1].length == 0 ? 80 : Integer(match[1])]
133
+ [match[2], match[3].length == 0 ? 80 : Integer(match[3]), match[0], match[1]]
132
134
  else
133
135
  nil
134
136
  end
@@ -122,7 +122,13 @@ module Raven
122
122
  local = select_gem(gemname, version, gems, true)
123
123
  puts "Using local gem #{local[0].name} (#{local[0].version}) to satisfy dependency #{gemname}" if RakeFileUtils.verbose_flag && local
124
124
  return local if local
125
- gems = Gem::RemoteInstaller.new().search(/.*#{gemname}$/)
125
+ begin
126
+ gems = Gem::RemoteInstaller.new().search(/.*#{gemname}$/)
127
+ rescue Exception => rt
128
+ puts "The gem #{gemname} from your dependencies couldn't be found locally"
129
+ puts "and the connection to a Gem repository failed."
130
+ exit
131
+ end
126
132
  remote = select_gem(gemname, version, gems.flatten, false)
127
133
  puts "Downloading remote gem #{remote[0].name} (#{remote[0].version}) to satisfy dependency #{gemname}" if RakeFileUtils.verbose_flag && remote
128
134
  return remote if remote
@@ -45,8 +45,8 @@ module Raven
45
45
 
46
46
  def execute
47
47
  super
48
- classpath = Raven.build_cp(prerequisites)
49
- classpath << "target/classes"
48
+ @classpath = Raven.build_cp(prerequisites)
49
+ @classpath << "target/classes"
50
50
  @build_path = ["src/main/java"] unless @build_path
51
51
 
52
52
  puts "Building path #{@build_path.join(' ')}" if RakeFileUtils.verbose_flag
@@ -67,9 +67,9 @@ module Raven
67
67
  source_pkg = Set.new
68
68
  source_files.each { |src| source_pkg << File.join(File.dirname(src), '*.java') }
69
69
  # Executing javac
70
- puts "javac -classpath \"#{classpath.join(CP_SEP)}\" -sourcepath \"#{@build_path.join(CP_SEP)}\" -d target/classes #{source_pkg.to_a.join(' ')}" if RakeFileUtils.verbose_flag
71
- `javac -classpath "#{classpath.join(CP_SEP)}" -sourcepath "#{@build_path.join(CP_SEP)}" -d target/classes #{source_pkg.to_a.join(' ')}`
72
- unless $? == 0
70
+ puts "javac -classpath \"#{@classpath.join(CP_SEP)}\" -sourcepath \"#{@build_path.join(CP_SEP)}\" -d target/classes #{source_pkg.to_a.join(' ')}" if RakeFileUtils.verbose_flag
71
+ `javac -classpath "#{@classpath.join(CP_SEP)}" -sourcepath "#{@build_path.join(CP_SEP)}" -d target/classes #{source_pkg.to_a.join(' ')}`
72
+ unless $?.exitstatus == 0
73
73
  puts "Build failed, see above errors."
74
74
  exit
75
75
  end
@@ -86,20 +86,58 @@ module Raven
86
86
  @build_path = [p]
87
87
  end
88
88
  end
89
+
90
+ class JUnitTask < JavacTask
91
+ def execute
92
+ @build_path = ["src/test/java"] unless @build_path
93
+ super
94
+ unless @test_classes
95
+ tests = @build_path.collect { |d| Dir.glob("#{d}/**/Test*.java").collect { |sd| sd[d.size+1..-1] } }
96
+ @test_classes = tests.flatten.collect { |d| d.gsub('/', '.')[0..-6] }
97
+ end
98
+ failures = false
99
+ @test_classes.flatten.each do |tc|
100
+ puts "Running test #{tc}"
101
+ result = `java -classpath "#{@classpath.join(CP_SEP)}" junit.textui.TestRunner #{tc}`
102
+ puts result
103
+ failures = true if /FAILURES/ =~ result || /ERRORS/ =~ result
104
+ end
105
+ if failures
106
+ puts "There were failures!"
107
+ exit(1)
108
+ end
109
+ end
110
+
111
+ def test_classes
112
+ @test_classes ||= []
113
+ end
114
+
115
+ def test_classes=(c)
116
+ @test_classes = [c]
117
+ end
118
+ end
89
119
 
90
120
  # Builds a jar file from your compiled sources. The jarfile produced
91
121
  # will have the same name as your jar task.
92
122
  class JarTask < Rake::Task
93
123
  def execute
94
- super
124
+ super
95
125
  latest = Raven.latest_file('target/classes')
96
-
97
- if !File.exist?("target/#{name}") || File.stat("target/#{name}").ctime < latest
98
- `jar -cf target/#{name} -C target/classes .`
126
+
127
+ # Manifest inclusion
128
+ mfest_param = @manifest ? "-m #{@manifest}" : ""
129
+
130
+ if !File.exist?("target/#{name}") || File.stat("target/#{name}").mtime < latest
131
+ `jar -cf target/#{name} #{mfest_param} -C target/classes .`
132
+ puts "Built jar file #{name}." if RakeFileUtils.verbose_flag
99
133
  else
100
134
  puts 'Nothing to do, jar is fresh enough.' if RakeFileUtils.verbose_flag
101
135
  end
102
136
  end
137
+
138
+ def manifest=(f)
139
+ @manifest = f
140
+ end
103
141
  end
104
142
 
105
143
  # Builds a jar file from your sources. Customized by adding directories
@@ -127,7 +165,7 @@ module Raven
127
165
  mfest_param = @manifest ? "-m #{@manifest}" : ""
128
166
 
129
167
  # Building the jar from all sources
130
- if !File.exist?("target/#{name}") || File.stat("target/#{name}").ctime < latest
168
+ if !File.exist?("target/#{name}") || File.stat("target/#{name}").mtime < latest
131
169
  `jar -cf target/#{name} #{mfest_param} -C #{@source_path.pop} .`
132
170
  while (p = @source_path.pop)
133
171
  `jar -uf target/#{name} -C #{p} .`
@@ -230,16 +268,20 @@ module Raven
230
268
  if (packages.size > 0)
231
269
  puts "javadoc -classpath #{classpath.join(CP_SEP)} -sourcepath #{@build_path.join(CP_SEP)} -d target/jdoc #{packages.join(' ')}" if RakeFileUtils.verbose_flag
232
270
  `javadoc -classpath #{classpath.join(CP_SEP)} -sourcepath #{@build_path.join(CP_SEP)} -d target/jdoc #{packages.join(' ')}`
233
- unless $? == 0
234
- puts "Build failed, see above errors."
271
+ unless $?.exitstatus == 0
272
+ puts "Javadoc failed, see above errors."
235
273
  exit
236
274
  end
237
275
  end
238
276
  end
239
-
277
+
240
278
  def build_path
241
279
  @build_path ||= []
242
280
  end
281
+
282
+ def build_path=(p)
283
+ @build_path = [p]
284
+ end
243
285
  end
244
286
 
245
287
  # Wraps a jar file around a Gem. Useful for distributing it around.
@@ -365,7 +407,7 @@ module Raven
365
407
  def self.latest_file(dir)
366
408
  latest = Time.at(0)
367
409
  Raven.browse_files(dir) do |f|
368
- change = File.stat(f).ctime
410
+ change = File.stat(f).mtime
369
411
  latest = change if change > latest
370
412
  end
371
413
  latest
@@ -388,6 +430,10 @@ module Raven
388
430
  def jar_source(args, &block)
389
431
  Raven::JarSourceTask.define_task(args, &block)
390
432
  end
433
+
434
+ def junit(args, &block)
435
+ Raven::JUnitTask.define_task(args, &block)
436
+ end
391
437
 
392
438
  def lib_dir(args, &block)
393
439
  Raven::LibDirTask.define_task(args, &block)
@@ -0,0 +1,459 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ # Copyright 2006 Matthieu Riou
4
+ #
5
+ # Licensed under the Apache License, Version 2.0 (the "License");
6
+ # you may not use this file except in compliance with the License.
7
+ # You may obtain a copy of the License at
8
+ #
9
+ # http://www.apache.org/licenses/LICENSE-2.0
10
+ #
11
+ # Unless required by applicable law or agreed to in writing, software
12
+ # distributed under the License is distributed on an "AS IS" BASIS,
13
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
+ # See the License for the specific language governing permissions and
15
+ # limitations under the License.
16
+
17
+ require 'rake'
18
+ require 'fileutils'
19
+ require 'set'
20
+
21
+ # Monkey patching FileUtils to support filtering in copy.
22
+ module FileUtils
23
+ class Entry_
24
+ alias original copy
25
+ def copy(dest)
26
+ unless path['.svn'] || path['.cvs']
27
+ original(dest)
28
+ end
29
+ end
30
+ end
31
+ end
32
+
33
+ module Raven
34
+ CP_SEP = PLATFORM['mswin'] ? ';' : ':'
35
+
36
+ # Executes Javac by passing it everything it needs. Stuff like a
37
+ # classpath and sources. The classpath is built by checking the
38
+ # prerequisites of the javac task. When a prerequisite is a dependency
39
+ # declaration (dependency task), it takes each declared Gems and
40
+ # adds the jar files found in them to the classpath.
41
+ #
42
+ # Can be customized by adding directories to the <em>build_path</em>
43
+ # using the << operator (if none defined, default is src/main/java).
44
+ class JavacTask < Rake::Task
45
+
46
+ def execute
47
+ super
48
+ @classpath = Raven.build_cp(prerequisites)
49
+ @classpath << "target/classes"
50
+ @build_path = ["src/main/java"] unless @build_path
51
+
52
+ puts "Building path #{@build_path.join(' ')}" if RakeFileUtils.verbose_flag
53
+
54
+ Dir.mkdir("target") unless File.exist?("target")
55
+ Dir.mkdir("target/classes") unless File.exist?("target/classes")
56
+ # Getting the source files to compile. Filtrating sources already
57
+ # compiled having a fresh enough class
58
+ source_files = @build_path.collect do |d|
59
+ Dir.glob("#{d}/**/*.java").select do |java|
60
+ classfile = 'target/classes/' + java[d.length, (java.length - 5 - d.length)] + '.class'
61
+ File.exist?(classfile) ? File.stat(java).mtime > File.stat(classfile).mtime : true
62
+ end
63
+ end.flatten
64
+
65
+ if (source_files.size > 0)
66
+ # Getting only package names, it shortens the command line
67
+ source_pkg = Set.new
68
+ source_files.each { |src| source_pkg << File.join(File.dirname(src), '*.java') }
69
+ # Executing javac
70
+ puts "javac -classpath \"#{@classpath.join(CP_SEP)}\" -sourcepath \"#{@build_path.join(CP_SEP)}\" -d target/classes #{source_pkg.to_a.join(' ')}" if RakeFileUtils.verbose_flag
71
+ `javac -classpath "#{@classpath.join(CP_SEP)}" -sourcepath "#{@build_path.join(CP_SEP)}" -d target/classes #{source_pkg.to_a.join(' ')}`
72
+ unless $?.exitstatus == 0
73
+ puts "Build failed, see above errors."
74
+ exit
75
+ end
76
+ else
77
+ puts 'All class files are up to date.' if RakeFileUtils.verbose_flag
78
+ end
79
+ end
80
+
81
+ def build_path
82
+ @build_path ||= []
83
+ end
84
+
85
+ def build_path=(p)
86
+ @build_path = [p]
87
+ end
88
+ end
89
+
90
+ class JUnitTask < JavacTask
91
+ def execute
92
+ @build_path = ["src/test/java"] unless @build_path
93
+ super
94
+ unless @test_classes
95
+ puts "IN"
96
+ tests = @build_path.collect { |d| Dir.glob("#{d}/**/Test*.java").collect { |sd| sd[d.size+1..-1] } }
97
+ puts tests
98
+ @test_classes = tests.flatten.collect { |d| d.gsub('/', '.')[0..-6] }
99
+ puts @test_classes
100
+ end
101
+ failures = false
102
+ @test_classes.flatten.each do |tc|
103
+ puts "Running test #{tc}"
104
+ result = `java -classpath "#{@classpath.join(CP_SEP)}" junit.textui.TestRunner #{tc}`
105
+ puts result
106
+ failures = true if /FAILURES/ =~ result || /ERRORS/ =~ result
107
+ end
108
+ if failures
109
+ puts "There were failures!"
110
+ exit(1)
111
+ end
112
+ end
113
+
114
+ def test_classes
115
+ @test_classes ||= []
116
+ end
117
+
118
+ def test_classes=(c)
119
+ @test_classes = [c]
120
+ end
121
+ end
122
+
123
+ # Builds a jar file from your compiled sources. The jarfile produced
124
+ # will have the same name as your jar task.
125
+ class JarTask < Rake::Task
126
+ def execute
127
+ super
128
+ latest = Raven.latest_file('target/classes')
129
+
130
+ # Manifest inclusion
131
+ mfest_param = @manifest ? "-m #{@manifest}" : ""
132
+
133
+ if !File.exist?("target/#{name}") || File.stat("target/#{name}").mtime < latest
134
+ `jar -cf target/#{name} #{mfest_param} -C target/classes .`
135
+ puts "Built jar file #{name}." if RakeFileUtils.verbose_flag
136
+ else
137
+ puts 'Nothing to do, jar is fresh enough.' if RakeFileUtils.verbose_flag
138
+ end
139
+ end
140
+
141
+ def manifest=(f)
142
+ @manifest = f
143
+ end
144
+ end
145
+
146
+ # Builds a jar file from your sources. Customized by adding directories
147
+ # to the <em>source_path</em> just like the JavacTask.
148
+ class JarSourceTask < Rake::Task
149
+ def execute
150
+ super
151
+ # Checking if any of our prerequisites is a JavacTask, if
152
+ # so we'll just use the build path to construct the jar.
153
+ Raven.prereq_filter(prerequisites, :build_path) do |javac_task|
154
+ (@source_path ||= []) << javac_task.build_path
155
+ end
156
+
157
+ # Initializing source path
158
+ @source_path = ["src/main/java"] unless @source_path
159
+ @source_path.flatten!
160
+
161
+ latest = Time.at(0)
162
+ @source_path.each do |dir|
163
+ dir_latest = Raven.latest_file(dir)
164
+ latest = dir_latest if dir_latest > latest
165
+ end
166
+
167
+ # Manifest inclusion
168
+ mfest_param = @manifest ? "-m #{@manifest}" : ""
169
+
170
+ # Building the jar from all sources
171
+ if !File.exist?("target/#{name}") || File.stat("target/#{name}").mtime < latest
172
+ `jar -cf target/#{name} #{mfest_param} -C #{@source_path.pop} .`
173
+ while (p = @source_path.pop)
174
+ `jar -uf target/#{name} -C #{p} .`
175
+ end
176
+ end
177
+ end
178
+
179
+ def source_path
180
+ @source_path ||= []
181
+ end
182
+
183
+ def manifest=(f)
184
+ @manifest = f
185
+ end
186
+ end
187
+
188
+ # Produces a WAR from a web application directory. Includes the libraries
189
+ # needed in WEB-INF/lib (as long as the corresponding dependency task is
190
+ # declared as a prerequisite) and the compiled classes (if there are).
191
+ #
192
+ # Can be customized by setting <em>webapp_dir</em> to the directory
193
+ # containing your web application resources (web.xml, jsp, images, ...).
194
+ # The default is src/main/webapp.
195
+ class WarTask < Rake::Task
196
+ DEFAULT_TARGET = 'target/webapp/'
197
+ LIB_SUBDIR = 'WEB-INF/lib/'
198
+ CLASSES_SUBDIR = 'WEB-INF/classes/'
199
+
200
+ def execute
201
+ super
202
+
203
+ # Build target structure
204
+ @webapp_dir = @webapp_dir || 'src/main/webapp'
205
+ Raven.mkdir_recurse(DEFAULT_TARGET)
206
+
207
+ puts "Using web application directory #{@webapp_dir}" if RakeFileUtils.verbose_flag
208
+
209
+ FileUtils.cp_r(@webapp_dir, DEFAULT_TARGET)
210
+
211
+ # Eventually add classes compiled by javac
212
+ if (File.exist?('target/classes'))
213
+ Raven.mkdir_recurse(DEFAULT_TARGET + CLASSES_SUBDIR)
214
+ FileUtils.cp_r('target/classes/.', DEFAULT_TARGET + CLASSES_SUBDIR)
215
+ end
216
+
217
+ # Make lib directory with all dependencies
218
+ Raven.mkdir_recurse(DEFAULT_TARGET + LIB_SUBDIR)
219
+ Raven.mk_libs(DEFAULT_TARGET + LIB_SUBDIR, prerequisites)
220
+
221
+ # Build the war
222
+ `jar -cf target/#{name} -C #{DEFAULT_TARGET} .`
223
+ end
224
+
225
+ def webapp_dir=(param)
226
+ @webapp_dir = param
227
+ end
228
+ end
229
+
230
+ # Places all the dependencies in a given directory (useful mostly to
231
+ # build a distribution). The dependencies are selected from the
232
+ # prerequisites (using declared dependency tasks). The default
233
+ # directory is lib. Can be customized by setting <em>target</em>.
234
+ class LibDirTask < Rake::Task
235
+ def execute
236
+ super
237
+ puts "Copying libraries in #{@target}" if RakeFileUtils.verbose_flag
238
+ @target = @target || 'lib'
239
+ Raven.mk_libs(@target, prerequisites)
240
+ end
241
+
242
+ def target=(param)
243
+ @target = param
244
+ end
245
+ end
246
+
247
+ # Executes JavaDoc by passing it everything it needs. Stuff like a
248
+ # classpath and sources. The result is generated in target/jdoc. Can
249
+ # be customized exactly in the same way as the javac task.
250
+ class JavaDocTask < Rake::Task
251
+
252
+ def execute
253
+ super
254
+ classpath = Raven.build_cp(prerequisites)
255
+ classpath << "target/classes"
256
+ @build_path = ["src/main/java"] unless @build_path
257
+
258
+ puts "Executing JavaDoc using source path #{@build_path.join(' ')}" if RakeFileUtils.verbose_flag
259
+
260
+ Dir.mkdir("target") unless File.exist?("target")
261
+ Dir.mkdir("target/jdoc") unless File.exist?("target/jdoc")
262
+
263
+ packages = Set[]
264
+ @build_path.each do |d|
265
+ Dir.glob("#{d}/**/*.java").each do |java|
266
+ packages << java[(d.length + 1)..(java.rindex('/') - 1)].gsub(%r{[\\/]}, '.')
267
+ end
268
+ end
269
+ packages = packages.to_a
270
+
271
+ if (packages.size > 0)
272
+ puts "javadoc -classpath #{classpath.join(CP_SEP)} -sourcepath #{@build_path.join(CP_SEP)} -d target/jdoc #{packages.join(' ')}" if RakeFileUtils.verbose_flag
273
+ `javadoc -classpath #{classpath.join(CP_SEP)} -sourcepath #{@build_path.join(CP_SEP)} -d target/jdoc #{packages.join(' ')}`
274
+ unless $?.exitstatus == 0
275
+ puts "Javadoc failed, see above errors."
276
+ exit
277
+ end
278
+ end
279
+ end
280
+
281
+ def build_path
282
+ @build_path ||= []
283
+ end
284
+
285
+ def build_path=(p)
286
+ @build_path = [p]
287
+ end
288
+ end
289
+
290
+ # Wraps a jar file around a Gem. Useful for distributing it around.
291
+ # The jar is taken from the target directory. You must at least
292
+ # specify <em>version</em> to produce the Gem. The artifact name and
293
+ # group name default to the current directory name and its parent
294
+ # directory name respectively. Convenient if you follow the classic
295
+ # project/module directory structure. Otherwise, just set the
296
+ # <em>artifact</em> and <em>group</em> to any value that suits you.
297
+ class GemWrapTask < Rake::Task
298
+ attr_writer :version, :artifact, :group
299
+
300
+ def execute
301
+ super
302
+ puts "Wrapping jar in a Gem" if RakeFileUtils.verbose_flag
303
+ unless @version
304
+ puts "A version must be provided to produce a Gem!"
305
+ end
306
+ pwd = Dir.pwd
307
+ @artifact = pwd[(pwd.rindex('/') + 1)..pwd.length] unless @artifact
308
+ pwd = pwd[0..pwd.rindex('/') - 1]
309
+ @group = pwd[(pwd.rindex('/') + 1)..pwd.length] unless @group
310
+ Raven.mkdir_recurse('target/gem/ext')
311
+ FileUtils.cp(Dir.glob('target/*.jar'), 'target/gem/ext')
312
+
313
+ Dir.chdir('target/gem') do
314
+ spec = Gem::Specification.new do |s|
315
+ s.platform = Gem::Platform::JAVA
316
+ s.summary = "Raven wrapped library #{@artifact} from project #{@group}."
317
+ s.name = "#{@group}-#{@artifact}"
318
+ s.version = @version
319
+ s.requirements << 'none'
320
+ s.require_path = 'ext'
321
+ s.autorequire = 'rake'
322
+ s.files = Dir.glob("{ext}/**/*")
323
+ end
324
+ Gem::Builder.new(spec).build
325
+ end
326
+ FileUtils.mv("target/gem/#{@group}-#{@artifact}-#{@version}-java.gem", 'target')
327
+ end
328
+ end
329
+
330
+ # Wraps a jar file around a Gem and automatically installs it in your
331
+ # local Gem repository. See the gem wrap task for more info (same rules
332
+ # apply).
333
+ class GemInstallTask < GemWrapTask
334
+ def execute
335
+ super
336
+ params = [false]
337
+ params << RAVEN_HOME if defined?(GEMS_IN_HOME)
338
+ Gem::Installer.new("target/#{@group}-#{@artifact}-#{@version}-java.gem").install(*params)
339
+ end
340
+ end
341
+
342
+ private
343
+
344
+ # Builds the classpath by getting the path to the jars bundled
345
+ # in each gem dependency.
346
+ def self.build_cp(prerequisites)
347
+ classpath = []
348
+ Raven.prereq_filter(prerequisites, :gem_deps) do |dep_task|
349
+ dep_task.gem_deps.each do |gempath|
350
+ Dir.foreach(gempath + '/ext') do |file|
351
+ next if file == '.' || file == '..'
352
+ classpath << gempath + '/ext/' + file
353
+ end
354
+ end
355
+ end
356
+ classpath
357
+ end
358
+
359
+ # Copies the jars corresponding to each Gem dependency to a given
360
+ # directory.
361
+ def self.mk_libs(target, prereq)
362
+ Raven.mkdir_recurse(target)
363
+ Raven.prereq_filter(prereq, :gem_deps) do |dep_task|
364
+ dep_task.gem_deps.each do |gempath|
365
+ Dir.foreach(gempath + '/ext') do |file|
366
+ next if file == '.' || file == '..'
367
+ FileUtils.copy(gempath + '/ext/' + file, target)
368
+ end
369
+ end
370
+ end
371
+ end
372
+
373
+ # Duck typing selection of prerequisites
374
+ def self.prereq_filter(prerequisites, respond_to)
375
+ prerequisites.each do |prereq|
376
+ prereq_task = Rake::Task[prereq]
377
+ if prereq_task.respond_to?(respond_to)
378
+ yield(prereq_task)
379
+ end
380
+ end
381
+ end
382
+
383
+ # Recursively creates a directory
384
+ def self.mkdir_recurse(dir)
385
+ if dir.rindex('/')
386
+ parent = dir[0, dir.rindex('/')]
387
+ mkdir_recurse(parent) unless File.exist?(parent)
388
+ end
389
+ Dir.mkdir(dir) unless File.exist?(dir)
390
+ end
391
+
392
+ # Receursively browse a directory yielding on each file found.
393
+ def self.browse_files(root)
394
+ queue = [root]
395
+ while !queue.empty?
396
+ filename = queue.pop
397
+ if File.file?(filename)
398
+ yield(filename)
399
+ else
400
+ Dir.new(filename).each do |child|
401
+ unless ['..', '.', '.svn', '.cvs'].include?(child)
402
+ queue.push(filename + "/" + child)
403
+ end
404
+ end
405
+ end
406
+ end
407
+ end
408
+
409
+ # Returns the latest file timestamp in a directory structure
410
+ def self.latest_file(dir)
411
+ latest = Time.at(0)
412
+ Raven.browse_files(dir) do |f|
413
+ change = File.stat(f).mtime
414
+ latest = change if change > latest
415
+ end
416
+ latest
417
+ end
418
+
419
+ end
420
+
421
+
422
+ # Shortcut to the Javac task creation. Makes it handy.
423
+ def javac(args, &block)
424
+ Raven::JavacTask.define_task(args, &block)
425
+ end
426
+
427
+ # Shortcut to jar. Only 3 letters, isn't that beautiful?
428
+ def jar(args, &block)
429
+ Raven::JarTask.define_task(args, &block)
430
+ end
431
+
432
+ # I think you've got it now.
433
+ def jar_source(args, &block)
434
+ Raven::JarSourceTask.define_task(args, &block)
435
+ end
436
+
437
+ def junit(args, &block)
438
+ Raven::JUnitTask.define_task(args, &block)
439
+ end
440
+
441
+ def lib_dir(args, &block)
442
+ Raven::LibDirTask.define_task(args, &block)
443
+ end
444
+
445
+ def war(args, &block)
446
+ Raven::WarTask.define_task(args, &block)
447
+ end
448
+
449
+ def javadoc(args, &block)
450
+ Raven::JavaDocTask.define_task(args, &block)
451
+ end
452
+
453
+ def gem_wrap(args, &block)
454
+ Raven::GemWrapTask.define_task(args, &block)
455
+ end
456
+
457
+ def gem_wrap_inst(args, &block)
458
+ Raven::GemInstallTask.define_task(args, &block)
459
+ end
@@ -46,7 +46,7 @@ module Raven
46
46
  end
47
47
 
48
48
  def to_s
49
- "#{artifactId} v#{versionId} (module #{groupId})"
49
+ "#{artifactId} v#{versionId} (project #{groupId})"
50
50
  end
51
51
  end
52
52
 
@@ -107,11 +107,13 @@ module Raven
107
107
  # Getting server name and gz file size header
108
108
  server_addr = idx_file.gets.chomp.split("#")
109
109
  aid_line = /artifactId: (.*#{artifactId}.*)/
110
+ aidx_line = /artifactId: (#{artifactId})$/
110
111
  gid_line = /groupId: (.*#{groupId}.*)/
111
112
  vid_line = /versionId: "?(#{versionId})"?/
112
113
 
113
114
  # a, a+v, a+g, g, v+g, a+v+g
114
115
  found = []
116
+ exact_match = false
115
117
  while (lines = read_lines(idx_file, 5))
116
118
  ma, mg, mv = false, false, false
117
119
  ma = lines[2].strip =~ aid_line if artifactId
@@ -123,9 +125,18 @@ module Raven
123
125
  (ma && mg && mv) ||
124
126
  (mg && mv && artifactId.nil?) ||
125
127
  (mg && artifactId.nil? && versionId.nil?))
126
- artifact = YAML.load(lines.join("\n"))
127
- artifact.server = server_addr
128
- found << artifact
128
+ artifact = YAML.load(lines.join("\n"))
129
+ artifact.server = server_addr
130
+ # We have an exact match, the rules change, only other exact matches
131
+ # get selected
132
+ if lines[2].strip =~ aidx_line
133
+ unless exact_match
134
+ exact_match = true
135
+ found = []
136
+ end
137
+ found << artifact
138
+ end
139
+ found << artifact unless exact_match
129
140
  end
130
141
  end
131
142
  found
@@ -143,7 +154,6 @@ module Raven
143
154
 
144
155
  if (versionId.nil? && !all_versions)
145
156
  artifacts = filtrate_latest(artifacts)
146
- puts artifacts
147
157
  end
148
158
 
149
159
  # Selected several artifacts but supposed to have only one
@@ -151,20 +161,20 @@ module Raven
151
161
  puts "Gem indices couldn't be found properly (either you provided a wrong URL or the main site is down)."
152
162
  return
153
163
  end
154
- raise GemTooManyInstallError.new(artifacts), "Too many artifacts" if (!all && artifacts.size > 1)
164
+ raise GemTooManyInstallError.new(artifacts) if (!all && artifacts.size > 1)
155
165
 
156
166
  if (artifacts.empty?)
157
167
  puts "Nothing found."
158
168
  else
159
169
  # TODO install from the servers returned by search
160
170
  # Proceeding with installation
161
- FileUtils.mkdir('ext')
171
+ FileUtils.mkdir('ext') unless File.exist?('ext')
162
172
  puts "Installing Gems:"
163
173
  artifacts.each do |artifact|
164
174
  if @proxy_info
165
175
  http = Net::HTTP::Proxy(*@proxy_info).new(artifact.server[0], artifact.server[1])
166
176
  else
167
- http = Net::HTTP.new(artifact.server[0], artifact.server[1])
177
+ http = Net::HTTP.new(artifact.server[0], Integer(artifact.server[1]))
168
178
  end
169
179
  puts " - #{artifact.to_s}"
170
180
  gemname = Raven.install_remote_gem(artifact, http, artifact.server[2], true)
@@ -225,15 +235,23 @@ module Raven
225
235
  false if !(Version === ver)
226
236
  return -1 if @timestamp && !ver.timestamp
227
237
  return 1 if !@timestamp && ver.timestamp
238
+ # Adding 0 to the end of the shortest one to get the same
239
+ # size, JRuby considers size first (even if size doesn't
240
+ # always matter)
241
+ @me, you = @ver_struct.dup, ver.ver_struct.dup
242
+ if (@me.size != you.size)
243
+ shorty = @me.size > you.size ? you : @me
244
+ biggy = @me.size > you.size ? @me : you
245
+ (shorty.size..biggy.size-1).each { |m| shorty[m] = 0 }
246
+ end
228
247
  # Setting string elements to 0 (mostly weaker) if they need
229
248
  # to be compared to an int otherwise <=> could produce nil
230
- @me, you = @ver_struct.dup, ver.ver_struct.dup
231
249
  (0..@me.size).each do |m|
232
250
  if (m < you.size && @me[m].class != you[m].class)
233
251
  @me[m] = 0 if String === @me[m]
234
252
  you[m] = 0 if String === you[m]
235
253
  end
236
- end
254
+ end
237
255
  @me <=> you
238
256
  end
239
257
 
metadata CHANGED
@@ -3,8 +3,8 @@ rubygems_version: 0.9.0
3
3
  specification_version: 1
4
4
  name: raven
5
5
  version: !ruby/object:Gem::Version
6
- version: 1.1.2
7
- date: 2006-11-23 00:00:00 -08:00
6
+ version: "1.2"
7
+ date: 2006-12-18 00:00:00 -08:00
8
8
  summary: Java build system based on Rake and Gem.
9
9
  require_paths:
10
10
  - lib
@@ -33,7 +33,7 @@ files:
33
33
  - bin/raven
34
34
  - lib/raven
35
35
  - lib/raven.rb
36
- - lib/raven/search_install.rb~
36
+ - lib/raven/java_tasks.rb~
37
37
  - lib/raven/deps_tasks.rb
38
38
  - lib/raven/gem_init.rb
39
39
  - lib/raven/java_tasks.rb
@@ -1,247 +0,0 @@
1
- #!/usr/bin/env ruby
2
-
3
- # Copyright 2006 Matthieu Riou
4
- #
5
- # Licensed under the Apache License, Version 2.0 (the "License");
6
- # you may not use this file except in compliance with the License.
7
- # You may obtain a copy of the License at
8
- #
9
- # http://www.apache.org/licenses/LICENSE-2.0
10
- #
11
- # Unless required by applicable law or agreed to in writing, software
12
- # distributed under the License is distributed on an "AS IS" BASIS,
13
- # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
- # See the License for the specific language governing permissions and
15
- # limitations under the License.
16
-
17
- require 'net/http'
18
-
19
- module Raven
20
-
21
- class RepoIndexBuilder
22
- def initialize(name, server, base_url, port, proxy_info)
23
- @name, @server, @base_url, @port, @proxy_info = name, server, base_url, port, proxy_info
24
- end
25
-
26
- def build_idx
27
- require 'yaml'
28
- require 'zlib'
29
- Zlib::GzipWriter.open("#{@name}.mvnidx.gz") do |f|
30
- f << @server + "#" + @port + "#" + @base_url + "\n"
31
- Raven::Maven2Repository.new(@server, @base_url, @port, @proxy_info).each do |artifact, http|
32
- f << YAML.dump(artifact)
33
- end
34
- end
35
- end
36
- end
37
-
38
- class GemSearchInstaller
39
- def initialize(server, port, base_url, proxy_info)
40
- @server, @base_url, @port, @proxy_info = server, base_url, port, proxy_info
41
- end
42
-
43
- def list_indices
44
- indices = []
45
- if @proxy_info
46
- http = Net::HTTP::Proxy(*@proxy_info).new(@server, @port)
47
- else
48
- http = Net::HTTP.new(@server, @port)
49
- end
50
- response = http.get(@base_url, nil)
51
- puts "RESPONSE #{response}"
52
- puts "BODY #{response.body}"
53
- expr = /href="([^"]*idx.gz)"|HREF="([^"]*idx.gz)"/
54
- if response.message.strip == "OK"
55
- response.body.each_line do |line|
56
- if expr =~ line
57
- indices << expr.match(line)[1]
58
- end
59
- end
60
- else
61
- puts "Got a bad response from server http://#{@server}:#{@port}/#{@base_url}, couldn't update local index"
62
- end
63
- indices
64
- end
65
-
66
- def get_indices
67
- require 'stringio'
68
- if @proxy_info
69
- http = Net::HTTP::Proxy(*@proxy_info).new(@server, @port)
70
- else
71
- http = Net::HTTP.new(@server, @port)
72
- end
73
-
74
- list_indices.each do |file|
75
- http_fn, fs_fn = @base_url + file, RAVEN_HOME + file[0..-4]
76
-
77
- # Checking file size to see if it changed
78
- header = http.head(http_fn)
79
- zipsize = header["content-length"]
80
- oldsize = File.exist?(fs_fn) ? File.new(fs_fn).readline.chomp : '0'
81
-
82
- unless (zipsize.to_i == oldsize.to_i)
83
- puts "Refreshing index file #{file[0..-4]}"
84
- response = StringIO.new(http.get(@base_url + file, nil).body)
85
- zlib = Zlib::GzipReader.new(response)
86
- file = File.new(RAVEN_HOME + file[0..-4], 'wb')
87
- file << zipsize + "\n"
88
- file.write(zlib.read)
89
- file.close
90
- zlib.close
91
- end
92
- end
93
- end
94
-
95
- def search(artifactId, groupId=nil, versionId=nil)
96
- idx_files = Dir[RAVEN_HOME + '*.mvnidx']
97
- found = []
98
- idx_files.each do |idx_file|
99
- puts "Searching in #{idx_file}..."
100
- f = File.new(idx_file)
101
- found.concat(search_index(f, artifactId, groupId, versionId))
102
- end
103
- found
104
- end
105
-
106
- def search_index(idx_file, artifactId, groupId, versionId)
107
- # Removing gz file size header
108
- idx_file.gets
109
- # Getting server name and gz file size header
110
- server_addr = idx_file.gets.chomp.split("#")
111
- aid_line = /artifactId: (.*#{artifactId}.*)/
112
- gid_line = /groupId: (.*#{groupId}.*)/
113
- vid_line = /versionId: "?(#{versionId})"?/
114
-
115
- # a, a+v, a+g, g, v+g, a+v+g
116
- found = []
117
- while (lines = read_lines(idx_file, 5))
118
- ma, mg, mv = false, false, false
119
- ma = lines[2].strip =~ aid_line if artifactId
120
- mg = lines[1].strip =~ gid_line if groupId
121
- mv = lines[3].strip =~ vid_line if versionId
122
- if ((ma && groupId.nil? && versionId.nil?) ||
123
- (ma && mg && versionId.nil?) ||
124
- (ma && mv && groupId.nil?) ||
125
- (ma && mg && mv) ||
126
- (mg && mv && artifactId.nil?) ||
127
- (mg && artifactId.nil? && versionId.nil?))
128
- artifact = YAML.load(lines.join("\n"))
129
- artifact.server = server_addr
130
- found << artifact
131
- end
132
- end
133
- found
134
- end
135
-
136
- def read_lines(file, size)
137
- lines = []
138
- 0.upto(size-1) { |m| lines[m] = file.gets }
139
- return nil if lines[size-1].nil?
140
- lines
141
- end
142
-
143
- def install(artifactId, groupId, versionId, all=false, all_versions=false)
144
- artifacts = search(artifactId, groupId, versionId).uniq
145
-
146
- if (versionId.nil? && !all_versions)
147
- artifacts = filtrate_latest(artifacts)
148
- puts artifacts
149
- end
150
-
151
- # Selected several artifacts but supposed to have only one
152
- if (artifacts.nil?)
153
- puts "Gem indices couldn't be found properly (either you provided a wrong URL or the main site is down)."
154
- return
155
- end
156
- raise GemTooManyInstallError.new(artifacts), "Too many artifacts" if (!all && artifacts.size > 1)
157
-
158
- if (artifacts.empty?)
159
- puts "Nothing found."
160
- else
161
- # TODO install from the servers returned by search
162
- # Proceeding with installation
163
- FileUtils.mkdir('ext')
164
- puts "Installing Gems:"
165
- artifacts.each do |artifact|
166
- if @proxy_info
167
- http = Net::HTTP::Proxy(*@proxy_info).new(artifact.server[0], artifact.server[1])
168
- else
169
- http = Net::HTTP.new(artifact.server[0], artifact.server[1])
170
- end
171
- puts " - #{artifact.to_s}"
172
- gemname = Raven.install_remote_gem(artifact, http, artifact.server[2], true)
173
- params = [false]
174
- params << RAVEN_HOME if defined?(GEMS_IN_HOME)
175
- Gem::Installer.new(gemname).install(*params)
176
- FileUtils.rm(gemname)
177
- end
178
- FileUtils.rm_rf('ext')
179
- end
180
- end
181
-
182
- def filtrate_latest(artifacts)
183
- # Create a hash with all versions of each artifact
184
- arth = {}
185
- artifacts.each do |art|
186
- key = "#{art.groupId}%#{art.artifactId}"
187
- arth[key] ||= []
188
- arth[key] << Version.new(art.versionId)
189
- end
190
-
191
- arth.keys.collect do |key|
192
- last_ver = arth[key].sort[-1].version
193
- find_artifact(artifacts, *(key.split('%') << last_ver))
194
- end
195
- end
196
-
197
- def find_artifact(artifacts, groupId, artifactId, versionId)
198
- artifacts.select do |art|
199
- art if art.artifactId == artifactId &&
200
- art.groupId == groupId && art.versionId == versionId
201
- end[0]
202
- end
203
- end
204
-
205
- # Structured version class used to try to make some sense
206
- # out of Maven version numbers. A difficult task indeed.
207
- class Version
208
- include Comparable
209
- attr_reader :timestamp, :ver_struct, :version
210
-
211
- def initialize(version)
212
- @version = version
213
- elmts = @version.split(/\.|-/)
214
- @timestamp = elmts[0].length > 3 ? true : false
215
- @ver_struct = elmts.collect do |elmt|
216
- val = ''
217
- begin
218
- val = Integer(elmt)
219
- rescue ArgumentError
220
- val = elmt
221
- end
222
- val
223
- end
224
- end
225
-
226
- def <=>(ver)
227
- false if !(Version === ver)
228
- return -1 if @timestamp && !ver.timestamp
229
- return 1 if !@timestamp && ver.timestamp
230
- # Setting string elements to 0 (mostly weaker) if they need
231
- # to be compared to an int otherwise <=> could produce nil
232
- @me, you = @ver_struct.dup, ver.ver_struct.dup
233
- (0..@me.size).each do |m|
234
- if (m < you.size && @me[m].class != you[m].class)
235
- @me[m] = 0 if String === @me[m]
236
- you[m] = 0 if String === you[m]
237
- end
238
- end
239
- @me <=> you
240
- end
241
-
242
- def to_s
243
- puts "v#{@version}, ts #{timestamp}, #{ @ver_struct.collect{ |v| v.class }.join('/') }"
244
- end
245
- end
246
-
247
- end