raven 1.1.1 → 1.1.2

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.
@@ -30,8 +30,9 @@ module Raven
30
30
  def self.run(args)
31
31
  opts = OptionParser.new
32
32
  opts.banner = "Usage: raven [options] (import | repository * | server | install *)"
33
- repo_url, index_url, all, groupId, allver = '', '', false, nil, false
33
+ repo_url, proxy_url, index_url, all, groupId, allver = '', '', '', false, nil, false
34
34
  opts.on('-m=ARG', '--mavenrepo repo_url', '[repository] Maven repository to build your gem repository from.') { |val| repo_url = val }
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 }
35
36
  opts.on('-i=ARG', '--index index_url', '[install] URL of a directory containing repository indices.') { |val| index_url = val }
36
37
  opts.on('-g=ARG', '--group', '[install] Install artifacts in the provided group.') { |val| groupId = val }
37
38
  opts.on('-a', '--all', '[install] Install all selected artifacts.') { |val| all = true }
@@ -60,7 +61,7 @@ module Raven
60
61
  rel_url = '/maven2/'
61
62
  end
62
63
  puts "Using server #{server} and url #{rel_url}"
63
- builder = Raven::GemRepoBuilder.new(server, rel_url)
64
+ builder = Raven::GemRepoBuilder.new(server, 80, rel_url, Raven::Command.parse_proxy(proxy_url))
64
65
  if (rest.size > 1)
65
66
  rest.shift
66
67
  puts "Packages #{rest}"
@@ -77,11 +78,12 @@ module Raven
77
78
  trap("INT") { s.shutdown }
78
79
  s.start
79
80
  when 'install'
80
- params = ['raven.rubyforge.org', '80', '/indices/']
81
+ params = ['raven.rubyforge.org', 80, '/indices/']
81
82
  if (index_url.length > 0)
82
83
  params = Raven::Command.parse_url(index_url)
83
84
  params[2] = '/' if params[2].empty?
84
85
  end
86
+ params << Raven::Command.parse_proxy(proxy_url)
85
87
  installer = Raven::GemSearchInstaller.new(*params)
86
88
  # Refreshes local gem indices if needed
87
89
  installer.get_indices
@@ -108,7 +110,7 @@ module Raven
108
110
  end
109
111
  end
110
112
  when 'build_index'
111
- RepoIndexBuilder.new('m2_central', 'repo1.maven.org', '/maven2/').build_idx
113
+ RepoIndexBuilder.new('m2_central', 'repo1.maven.org', '/maven2/', Raven::Command.parse_proxy(proxy_url)).build_idx
112
114
  else
113
115
  puts opts.to_s
114
116
  end
@@ -119,5 +121,17 @@ module Raven
119
121
  parsed.shift
120
122
  parsed
121
123
  end
124
+
125
+ def self.parse_proxy(purl)
126
+ if (purl.length > 0)
127
+ match = purl.match('http://(.*):(.*)@([^/]*):([0-9]*)')
128
+ match = match.to_a
129
+ match.shift
130
+ puts "Using proxy #{match[2]} and port #{match[3]}"
131
+ [match[2], match[3], match[0], match[1].length == 0 ? 80 : Integer(match[1])]
132
+ else
133
+ nil
134
+ end
135
+ end
122
136
  end
123
137
  end
@@ -60,340 +60,351 @@ module Raven
60
60
  classfile = 'target/classes/' + java[d.length, (java.length - 5 - d.length)] + '.class'
61
61
  File.exist?(classfile) ? File.stat(java).mtime > File.stat(classfile).mtime : true
62
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 $? == 0
73
- puts "Build failed, see above errors."
74
- exit
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 $? == 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
75
78
  end
76
- else
77
- puts 'All class files are up to date.' if RakeFileUtils.verbose_flag
79
+ end
80
+
81
+ def build_path
82
+ @build_path ||= []
83
+ end
84
+
85
+ def build_path=(p)
86
+ @build_path = [p]
78
87
  end
79
88
  end
80
89
 
81
- def build_path
82
- @build_path ||= []
83
- end
84
- end
85
-
86
- # Builds a jar file from your compiled sources. The jarfile produced
87
- # will have the same name as your jar task.
88
- class JarTask < Rake::Task
89
- def execute
90
- super
91
- latest = Raven.latest_file('target/classes')
92
-
93
- if !File.exist?("target/#{name}") || File.stat("target/#{name}").ctime < latest
94
- `jar -cf target/#{name} -C target/classes .`
95
- else
96
- puts 'Nothing to do, jar is fresh enough.' if RakeFileUtils.verbose_flag
90
+ # Builds a jar file from your compiled sources. The jarfile produced
91
+ # will have the same name as your jar task.
92
+ class JarTask < Rake::Task
93
+ def execute
94
+ super
95
+ 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 .`
99
+ else
100
+ puts 'Nothing to do, jar is fresh enough.' if RakeFileUtils.verbose_flag
101
+ end
97
102
  end
98
103
  end
99
- end
100
-
101
- # Builds a jar file from your sources. Customized by adding directories
102
- # to the <em>source_path</em> just like the JavacTask.
103
- class JarSourceTask < Rake::Task
104
- def execute
105
- super
106
- # Checking if any of our prerequisites is a JavacTask, if
107
- # so we'll just use the build path to construct the jar.
108
- Raven.prereq_filter(prerequisites, :build_path) do |javac_task|
109
- (@source_path ||= []) << javac_task.build_path
104
+
105
+ # Builds a jar file from your sources. Customized by adding directories
106
+ # to the <em>source_path</em> just like the JavacTask.
107
+ class JarSourceTask < Rake::Task
108
+ def execute
109
+ super
110
+ # Checking if any of our prerequisites is a JavacTask, if
111
+ # so we'll just use the build path to construct the jar.
112
+ Raven.prereq_filter(prerequisites, :build_path) do |javac_task|
113
+ (@source_path ||= []) << javac_task.build_path
114
+ end
115
+
116
+ # Initializing source path
117
+ @source_path = ["src/main/java"] unless @source_path
118
+ @source_path.flatten!
119
+
120
+ latest = Time.at(0)
121
+ @source_path.each do |dir|
122
+ dir_latest = Raven.latest_file(dir)
123
+ latest = dir_latest if dir_latest > latest
124
+ end
125
+
126
+ # Manifest inclusion
127
+ mfest_param = @manifest ? "-m #{@manifest}" : ""
128
+
129
+ # Building the jar from all sources
130
+ if !File.exist?("target/#{name}") || File.stat("target/#{name}").ctime < latest
131
+ `jar -cf target/#{name} #{mfest_param} -C #{@source_path.pop} .`
132
+ while (p = @source_path.pop)
133
+ `jar -uf target/#{name} -C #{p} .`
134
+ end
135
+ end
110
136
  end
111
137
 
112
- # Initializing source path
113
- @source_path = ["src/main/java"] unless @source_path
114
- @source_path.flatten!
115
-
116
- latest = Time.at(0)
117
- @source_path.each do |dir|
118
- dir_latest = Raven.latest_file(dir)
119
- latest = dir_latest if dir_latest > latest
138
+ def source_path
139
+ @source_path ||= []
120
140
  end
121
141
 
122
- # Building the jar from all sources
123
- if !File.exist?("target/#{name}") || File.stat("target/#{name}").ctime < latest
124
- `jar -cf target/#{name} -C #{@source_path.pop} .`
125
- while (p = @source_path.pop)
126
- `jar -uf target/#{name} -C #{p} .`
127
- end
142
+ def manifest=(f)
143
+ @manifest = f
128
144
  end
129
145
  end
130
146
 
131
- def source_path
132
- @source_path ||= []
147
+ # Produces a WAR from a web application directory. Includes the libraries
148
+ # needed in WEB-INF/lib (as long as the corresponding dependency task is
149
+ # declared as a prerequisite) and the compiled classes (if there are).
150
+ #
151
+ # Can be customized by setting <em>webapp_dir</em> to the directory
152
+ # containing your web application resources (web.xml, jsp, images, ...).
153
+ # The default is src/main/webapp.
154
+ class WarTask < Rake::Task
155
+ DEFAULT_TARGET = 'target/webapp/'
156
+ LIB_SUBDIR = 'WEB-INF/lib/'
157
+ CLASSES_SUBDIR = 'WEB-INF/classes/'
158
+
159
+ def execute
160
+ super
161
+
162
+ # Build target structure
163
+ @webapp_dir = @webapp_dir || 'src/main/webapp'
164
+ Raven.mkdir_recurse(DEFAULT_TARGET)
165
+
166
+ puts "Using web application directory #{@webapp_dir}" if RakeFileUtils.verbose_flag
167
+
168
+ FileUtils.cp_r(@webapp_dir, DEFAULT_TARGET)
169
+
170
+ # Eventually add classes compiled by javac
171
+ if (File.exist?('target/classes'))
172
+ Raven.mkdir_recurse(DEFAULT_TARGET + CLASSES_SUBDIR)
173
+ FileUtils.cp_r('target/classes/.', DEFAULT_TARGET + CLASSES_SUBDIR)
174
+ end
175
+
176
+ # Make lib directory with all dependencies
177
+ Raven.mkdir_recurse(DEFAULT_TARGET + LIB_SUBDIR)
178
+ Raven.mk_libs(DEFAULT_TARGET + LIB_SUBDIR, prerequisites)
179
+
180
+ # Build the war
181
+ `jar -cf target/#{name} -C #{DEFAULT_TARGET} .`
182
+ end
183
+
184
+ def webapp_dir=(param)
185
+ @webapp_dir = param
186
+ end
133
187
  end
134
- end
135
-
136
- # Produces a WAR from a web application directory. Includes the libraries
137
- # needed in WEB-INF/lib (as long as the corresponding dependency task is
138
- # declared as a prerequisite) and the compiled classes (if there are).
139
- #
140
- # Can be customized by setting <em>webapp_dir</em> to the directory
141
- # containing your web application resources (web.xml, jsp, images, ...).
142
- # The default is src/main/webapp.
143
- class WarTask < Rake::Task
144
- DEFAULT_TARGET = 'target/webapp/'
145
- LIB_SUBDIR = 'WEB-INF/lib/'
146
- CLASSES_SUBDIR = 'WEB-INF/classes/'
147
188
 
148
- def execute
149
- super
150
-
151
- # Build target structure
152
- @webapp_dir = @webapp_dir || 'src/main/webapp'
153
- Raven.mkdir_recurse(DEFAULT_TARGET)
154
-
155
- puts "Using web application directory #{@webapp_dir}" if RakeFileUtils.verbose_flag
156
-
157
- FileUtils.cp_r(@webapp_dir, DEFAULT_TARGET)
189
+ # Places all the dependencies in a given directory (useful mostly to
190
+ # build a distribution). The dependencies are selected from the
191
+ # prerequisites (using declared dependency tasks). The default
192
+ # directory is lib. Can be customized by setting <em>target</em>.
193
+ class LibDirTask < Rake::Task
194
+ def execute
195
+ super
196
+ puts "Copying libraries in #{@target}" if RakeFileUtils.verbose_flag
197
+ @target = @target || 'lib'
198
+ Raven.mk_libs(@target, prerequisites)
199
+ end
158
200
 
159
- # Eventually add classes compiled by javac
160
- if (File.exist?('target/classes'))
161
- Raven.mkdir_recurse(DEFAULT_TARGET + CLASSES_SUBDIR)
162
- FileUtils.cp_r('target/classes/.', DEFAULT_TARGET + CLASSES_SUBDIR)
201
+ def target=(param)
202
+ @target = param
163
203
  end
204
+ end
205
+
206
+ # Executes JavaDoc by passing it everything it needs. Stuff like a
207
+ # classpath and sources. The result is generated in target/jdoc. Can
208
+ # be customized exactly in the same way as the javac task.
209
+ class JavaDocTask < Rake::Task
164
210
 
165
- # Make lib directory with all dependencies
166
- Raven.mkdir_recurse(DEFAULT_TARGET + LIB_SUBDIR)
167
- Raven.mk_libs(DEFAULT_TARGET + LIB_SUBDIR, prerequisites)
211
+ def execute
212
+ super
213
+ classpath = Raven.build_cp(prerequisites)
214
+ classpath << "target/classes"
215
+ @build_path = ["src/main/java"] unless @build_path
216
+
217
+ puts "Executing JavaDoc using source path #{@build_path.join(' ')}" if RakeFileUtils.verbose_flag
218
+
219
+ Dir.mkdir("target") unless File.exist?("target")
220
+ Dir.mkdir("target/jdoc") unless File.exist?("target/jdoc")
221
+
222
+ packages = Set[]
223
+ @build_path.each do |d|
224
+ Dir.glob("#{d}/**/*.java").each do |java|
225
+ packages << java[(d.length + 1)..(java.rindex('/') - 1)].gsub(%r{[\\/]}, '.')
226
+ end
227
+ end
228
+ packages = packages.to_a
229
+
230
+ if (packages.size > 0)
231
+ puts "javadoc -classpath #{classpath.join(CP_SEP)} -sourcepath #{@build_path.join(CP_SEP)} -d target/jdoc #{packages.join(' ')}" if RakeFileUtils.verbose_flag
232
+ `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."
235
+ exit
236
+ end
237
+ end
238
+ end
168
239
 
169
- # Build the war
170
- `jar -cf target/#{name} -C #{DEFAULT_TARGET} .`
240
+ def build_path
241
+ @build_path ||= []
242
+ end
171
243
  end
172
244
 
173
- def webapp_dir=(param)
174
- @webapp_dir = param
175
- end
176
- end
177
-
178
- # Places all the dependencies in a given directory (useful mostly to
179
- # build a distribution). The dependencies are selected from the
180
- # prerequisites (using declared dependency tasks). The default
181
- # directory is lib. Can be customized by setting <em>target</em>.
182
- class LibDirTask < Rake::Task
183
- def execute
184
- super
185
- puts "Copying libraries in #{@target}" if RakeFileUtils.verbose_flag
186
- @target = @target || 'lib'
187
- Raven.mk_libs(@target, prerequisites)
245
+ # Wraps a jar file around a Gem. Useful for distributing it around.
246
+ # The jar is taken from the target directory. You must at least
247
+ # specify <em>version</em> to produce the Gem. The artifact name and
248
+ # group name default to the current directory name and its parent
249
+ # directory name respectively. Convenient if you follow the classic
250
+ # project/module directory structure. Otherwise, just set the
251
+ # <em>artifact</em> and <em>group</em> to any value that suits you.
252
+ class GemWrapTask < Rake::Task
253
+ attr_writer :version, :artifact, :group
254
+
255
+ def execute
256
+ super
257
+ puts "Wrapping jar in a Gem" if RakeFileUtils.verbose_flag
258
+ unless @version
259
+ puts "A version must be provided to produce a Gem!"
260
+ end
261
+ pwd = Dir.pwd
262
+ @artifact = pwd[(pwd.rindex('/') + 1)..pwd.length] unless @artifact
263
+ pwd = pwd[0..pwd.rindex('/') - 1]
264
+ @group = pwd[(pwd.rindex('/') + 1)..pwd.length] unless @group
265
+ Raven.mkdir_recurse('target/gem/ext')
266
+ FileUtils.cp(Dir.glob('target/*.jar'), 'target/gem/ext')
267
+
268
+ Dir.chdir('target/gem') do
269
+ spec = Gem::Specification.new do |s|
270
+ s.platform = Gem::Platform::JAVA
271
+ s.summary = "Raven wrapped library #{@artifact} from project #{@group}."
272
+ s.name = "#{@group}-#{@artifact}"
273
+ s.version = @version
274
+ s.requirements << 'none'
275
+ s.require_path = 'ext'
276
+ s.autorequire = 'rake'
277
+ s.files = Dir.glob("{ext}/**/*")
278
+ end
279
+ Gem::Builder.new(spec).build
280
+ end
281
+ FileUtils.mv("target/gem/#{@group}-#{@artifact}-#{@version}-java.gem", 'target')
282
+ end
188
283
  end
189
284
 
190
- def target=(param)
191
- @target = param
285
+ # Wraps a jar file around a Gem and automatically installs it in your
286
+ # local Gem repository. See the gem wrap task for more info (same rules
287
+ # apply).
288
+ class GemInstallTask < GemWrapTask
289
+ def execute
290
+ super
291
+ params = [false]
292
+ params << RAVEN_HOME if defined?(GEMS_IN_HOME)
293
+ Gem::Installer.new("target/#{@group}-#{@artifact}-#{@version}-java.gem").install(*params)
294
+ end
192
295
  end
193
- end
194
-
195
- # Executes JavaDoc by passing it everything it needs. Stuff like a
196
- # classpath and sources. The result is generated in target/jdoc. Can
197
- # be customized exactly in the same way as the javac task.
198
- class JavaDocTask < Rake::Task
199
296
 
200
- def execute
201
- super
202
- classpath = Raven.build_cp(prerequisites)
203
- classpath << "target/classes"
204
- @build_path = ["src/main/java"] unless @build_path
205
-
206
- puts "Executing JavaDoc using source path #{@build_path.join(' ')}" if RakeFileUtils.verbose_flag
207
-
208
- Dir.mkdir("target") unless File.exist?("target")
209
- Dir.mkdir("target/jdoc") unless File.exist?("target/jdoc")
210
-
211
- packages = Set[]
212
- @build_path.each do |d|
213
- Dir.glob("#{d}/**/*.java").each do |java|
214
- packages << java[(d.length + 1)..(java.rindex('/') - 1)].gsub(%r{[\\/]}, '.')
297
+ private
298
+
299
+ # Builds the classpath by getting the path to the jars bundled
300
+ # in each gem dependency.
301
+ def self.build_cp(prerequisites)
302
+ classpath = []
303
+ Raven.prereq_filter(prerequisites, :gem_deps) do |dep_task|
304
+ dep_task.gem_deps.each do |gempath|
305
+ Dir.foreach(gempath + '/ext') do |file|
306
+ next if file == '.' || file == '..'
307
+ classpath << gempath + '/ext/' + file
308
+ end
215
309
  end
216
310
  end
217
- packages = packages.to_a
218
-
219
- if (packages.size > 0)
220
- puts "javadoc -classpath #{classpath.join(CP_SEP)} -sourcepath #{@build_path.join(CP_SEP)} -d target/jdoc #{packages.join(' ')}" if RakeFileUtils.verbose_flag
221
- `javadoc -classpath #{classpath.join(CP_SEP)} -sourcepath #{@build_path.join(CP_SEP)} -d target/jdoc #{packages.join(' ')}`
222
- unless $? == 0
223
- puts "Build failed, see above errors."
224
- exit
311
+ classpath
312
+ end
313
+
314
+ # Copies the jars corresponding to each Gem dependency to a given
315
+ # directory.
316
+ def self.mk_libs(target, prereq)
317
+ Raven.mkdir_recurse(target)
318
+ Raven.prereq_filter(prereq, :gem_deps) do |dep_task|
319
+ dep_task.gem_deps.each do |gempath|
320
+ Dir.foreach(gempath + '/ext') do |file|
321
+ next if file == '.' || file == '..'
322
+ FileUtils.copy(gempath + '/ext/' + file, target)
323
+ end
225
324
  end
226
325
  end
227
326
  end
228
327
 
229
- def build_path
230
- @build_path ||= []
328
+ # Duck typing selection of prerequisites
329
+ def self.prereq_filter(prerequisites, respond_to)
330
+ prerequisites.each do |prereq|
331
+ prereq_task = Rake::Task[prereq]
332
+ if prereq_task.respond_to?(respond_to)
333
+ yield(prereq_task)
334
+ end
335
+ end
231
336
  end
232
- end
233
-
234
- # Wraps a jar file around a Gem. Useful for distributing it around.
235
- # The jar is taken from the target directory. You must at least
236
- # specify <em>version</em> to produce the Gem. The artifact name and
237
- # group name default to the current directory name and its parent
238
- # directory name respectively. Convenient if you follow the classic
239
- # project/module directory structure. Otherwise, just set the
240
- # <em>artifact</em> and <em>group</em> to any value that suits you.
241
- class GemWrapTask < Rake::Task
242
- attr_writer :version, :artifact, :group
243
337
 
244
- def execute
245
- super
246
- puts "Wrapping jar in a Gem" if RakeFileUtils.verbose_flag
247
- unless @version
248
- puts "A version must be provided to produce a Gem!"
338
+ # Recursively creates a directory
339
+ def self.mkdir_recurse(dir)
340
+ if dir.rindex('/')
341
+ parent = dir[0, dir.rindex('/')]
342
+ mkdir_recurse(parent) unless File.exist?(parent)
249
343
  end
250
- pwd = Dir.pwd
251
- @artifact = pwd[(pwd.rindex('/') + 1)..pwd.length] unless @artifact
252
- pwd = pwd[0..pwd.rindex('/') - 1]
253
- @group = pwd[(pwd.rindex('/') + 1)..pwd.length] unless @group
254
- Raven.mkdir_recurse('target/gem/ext')
255
- FileUtils.cp(Dir.glob('target/*.jar'), 'target/gem/ext')
256
-
257
- Dir.chdir('target/gem') do
258
- spec = Gem::Specification.new do |s|
259
- s.platform = Gem::Platform::JAVA
260
- s.summary = "Raven wrapped library #{@artifact} from project #{@group}."
261
- s.name = "#{@group}-#{@artifact}"
262
- s.version = @version
263
- s.requirements << 'none'
264
- s.require_path = 'ext'
265
- s.autorequire = 'rake'
266
- s.files = Dir.glob("{ext}/**/*")
344
+ Dir.mkdir(dir) unless File.exist?(dir)
345
+ end
346
+
347
+ # Receursively browse a directory yielding on each file found.
348
+ def self.browse_files(root)
349
+ queue = [root]
350
+ while !queue.empty?
351
+ filename = queue.pop
352
+ if File.file?(filename)
353
+ yield(filename)
354
+ else
355
+ Dir.new(filename).each do |child|
356
+ unless ['..', '.', '.svn', '.cvs'].include?(child)
357
+ queue.push(filename + "/" + child)
358
+ end
359
+ end
267
360
  end
268
- Gem::Builder.new(spec).build
269
361
  end
270
- FileUtils.mv("target/gem/#{@group}-#{@artifact}-#{@version}-java.gem", 'target')
271
- end
272
- end
273
-
274
- # Wraps a jar file around a Gem and automatically installs it in your
275
- # local Gem repository. See the gem wrap task for more info (same rules
276
- # apply).
277
- class GemInstallTask < GemWrapTask
278
- def execute
279
- super
280
- params = [false]
281
- params << RAVEN_HOME if defined?(GEMS_IN_HOME)
282
- Gem::Installer.new("target/#{@group}-#{@artifact}-#{@version}-java.gem").install(*params)
283
362
  end
363
+
364
+ # Returns the latest file timestamp in a directory structure
365
+ def self.latest_file(dir)
366
+ latest = Time.at(0)
367
+ Raven.browse_files(dir) do |f|
368
+ change = File.stat(f).ctime
369
+ latest = change if change > latest
370
+ end
371
+ latest
372
+ end
373
+
284
374
  end
285
375
 
286
- private
287
376
 
288
- # Builds the classpath by getting the path to the jars bundled
289
- # in each gem dependency.
290
- def self.build_cp(prerequisites)
291
- classpath = []
292
- Raven.prereq_filter(prerequisites, :gem_deps) do |dep_task|
293
- dep_task.gem_deps.each do |gempath|
294
- Dir.foreach(gempath + '/ext') do |file|
295
- next if file == '.' || file == '..'
296
- classpath << gempath + '/ext/' + file
297
- end
298
- end
299
- end
300
- classpath
377
+ # Shortcut to the Javac task creation. Makes it handy.
378
+ def javac(args, &block)
379
+ Raven::JavacTask.define_task(args, &block)
301
380
  end
302
381
 
303
- # Copies the jars corresponding to each Gem dependency to a given
304
- # directory.
305
- def self.mk_libs(target, prereq)
306
- Raven.mkdir_recurse(target)
307
- Raven.prereq_filter(prereq, :gem_deps) do |dep_task|
308
- dep_task.gem_deps.each do |gempath|
309
- Dir.foreach(gempath + '/ext') do |file|
310
- next if file == '.' || file == '..'
311
- FileUtils.copy(gempath + '/ext/' + file, target)
312
- end
313
- end
314
- end
382
+ # Shortcut to jar. Only 3 letters, isn't that beautiful?
383
+ def jar(args, &block)
384
+ Raven::JarTask.define_task(args, &block)
315
385
  end
316
386
 
317
- # Duck typing selection of prerequisites
318
- def self.prereq_filter(prerequisites, respond_to)
319
- prerequisites.each do |prereq|
320
- prereq_task = Rake::Task[prereq]
321
- if prereq_task.respond_to?(respond_to)
322
- yield(prereq_task)
323
- end
324
- end
387
+ # I think you've got it now.
388
+ def jar_source(args, &block)
389
+ Raven::JarSourceTask.define_task(args, &block)
325
390
  end
326
391
 
327
- # Recursively creates a directory
328
- def self.mkdir_recurse(dir)
329
- if dir.rindex('/')
330
- parent = dir[0, dir.rindex('/')]
331
- mkdir_recurse(parent) unless File.exist?(parent)
332
- end
333
- Dir.mkdir(dir) unless File.exist?(dir)
392
+ def lib_dir(args, &block)
393
+ Raven::LibDirTask.define_task(args, &block)
334
394
  end
335
395
 
336
- # Receursively browse a directory yielding on each file found.
337
- def self.browse_files(root)
338
- queue = [root]
339
- while !queue.empty?
340
- filename = queue.pop
341
- if File.file?(filename)
342
- yield(filename)
343
- else
344
- Dir.new(filename).each do |child|
345
- unless ['..', '.', '.svn', '.cvs'].include?(child)
346
- queue.push(filename + "/" + child)
347
- end
348
- end
349
- end
350
- end
396
+ def war(args, &block)
397
+ Raven::WarTask.define_task(args, &block)
351
398
  end
352
399
 
353
- # Returns the latest file timestamp in a directory structure
354
- def self.latest_file(dir)
355
- latest = Time.at(0)
356
- Raven.browse_files(dir) do |f|
357
- change = File.stat(f).ctime
358
- latest = change if change > latest
359
- end
360
- latest
400
+ def javadoc(args, &block)
401
+ Raven::JavaDocTask.define_task(args, &block)
361
402
  end
362
403
 
363
- end
364
-
365
-
366
- # Shortcut to the Javac task creation. Makes it handy.
367
- def javac(args, &block)
368
- Raven::JavacTask.define_task(args, &block)
369
- end
370
-
371
- # Shortcut to jar. Only 3 letters, isn't that beautiful?
372
- def jar(args, &block)
373
- Raven::JarTask.define_task(args, &block)
374
- end
375
-
376
- # I think you've got it now.
377
- def jar_source(args, &block)
378
- Raven::JarSourceTask.define_task(args, &block)
379
- end
380
-
381
- def lib_dir(args, &block)
382
- Raven::LibDirTask.define_task(args, &block)
383
- end
384
-
385
- def war(args, &block)
386
- Raven::WarTask.define_task(args, &block)
387
- end
388
-
389
- def javadoc(args, &block)
390
- Raven::JavaDocTask.define_task(args, &block)
391
- end
392
-
393
- def gem_wrap(args, &block)
394
- Raven::GemWrapTask.define_task(args, &block)
395
- end
396
-
397
- def gem_wrap_inst(args, &block)
398
- Raven::GemInstallTask.define_task(args, &block)
399
- end
404
+ def gem_wrap(args, &block)
405
+ Raven::GemWrapTask.define_task(args, &block)
406
+ end
407
+
408
+ def gem_wrap_inst(args, &block)
409
+ Raven::GemInstallTask.define_task(args, &block)
410
+ end
@@ -61,12 +61,16 @@ module Raven
61
61
  @group_filters
62
62
  end
63
63
 
64
- def initialize(server, url, port="80")
65
- @server, @url, @port = server, url, port
64
+ def initialize(server, port, url, proxy_info)
65
+ @server, @url, @port, @proxy_info = server, url, port, proxy_info
66
66
  end
67
67
 
68
68
  def each
69
- http = Net::HTTP.new(@server, @port)
69
+ if @proxy_info
70
+ http = Net::HTTP::Proxy(*@proxy_info).new(@server, @port)
71
+ else
72
+ http = Net::HTTP.new(@server, @port)
73
+ end
70
74
  folder_regexp = /<img src="\/icons\/folder.gif" alt="\[DIR\]"> <a href="[^\/]*\/">/
71
75
  file_regexp = /<img src="\/icons\/unknown.gif" alt="\[ \]"> <a href="[^"]*">/
72
76
  read_page(http, @url, folder_regexp) do |url1, groupId|
@@ -104,12 +108,12 @@ module Raven
104
108
  class GemRepoBuilder
105
109
  attr_writer :group_filters
106
110
 
107
- def initialize(server, port, url)
108
- @server, @url = server, url
111
+ def initialize(server, port, url, proxy_info)
112
+ @server, @port, @url, @proxy_info = server, port, url, proxy_info
109
113
  end
110
114
 
111
115
  def build(overwrite = false)
112
- repo = Maven2Repository.new(@server, @url)
116
+ repo = Maven2Repository.new(@server, @port, @url, @proxy_info)
113
117
  repo.group_filters = @group_filters unless @group_filters.nil?
114
118
 
115
119
  Dir.mkdir('gems') unless File.exist?('gems')
@@ -19,8 +19,8 @@ require 'net/http'
19
19
  module Raven
20
20
 
21
21
  class RepoIndexBuilder
22
- def initialize(name, server, base_url, port='80')
23
- @name, @server, @base_url, @port = name, server, base_url, port
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
24
  end
25
25
 
26
26
  def build_idx
@@ -28,7 +28,7 @@ module Raven
28
28
  require 'zlib'
29
29
  Zlib::GzipWriter.open("#{@name}.mvnidx.gz") do |f|
30
30
  f << @server + "#" + @port + "#" + @base_url + "\n"
31
- Raven::Maven2Repository.new(@server, @base_url, @port).each do |artifact, http|
31
+ Raven::Maven2Repository.new(@server, @base_url, @port, @proxy_info).each do |artifact, http|
32
32
  f << YAML.dump(artifact)
33
33
  end
34
34
  end
@@ -36,15 +36,19 @@ module Raven
36
36
  end
37
37
 
38
38
  class GemSearchInstaller
39
- def initialize(server, port, base_url)
40
- @server, @base_url, @port = server, base_url, port
39
+ def initialize(server, port, base_url, proxy_info)
40
+ @server, @base_url, @port, @proxy_info = server, base_url, port, proxy_info
41
41
  end
42
42
 
43
43
  def list_indices
44
44
  indices = []
45
- http = Net::HTTP.new(@server, @port)
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
46
50
  response = http.get(@base_url, nil)
47
- expr = /HREF="([^"]*idx.gz)"/
51
+ expr = /href="([^"]*idx.gz)"|HREF="([^"]*idx.gz)"/
48
52
  if response.message.strip == "OK"
49
53
  response.body.each_line do |line|
50
54
  if expr =~ line
@@ -59,7 +63,11 @@ module Raven
59
63
 
60
64
  def get_indices
61
65
  require 'stringio'
62
- http = Net::HTTP.new(@server, @port)
66
+ if @proxy_info
67
+ http = Net::HTTP::Proxy(*@proxy_info).new(@server, @port)
68
+ else
69
+ http = Net::HTTP.new(@server, @port)
70
+ end
63
71
 
64
72
  list_indices.each do |file|
65
73
  http_fn, fs_fn = @base_url + file, RAVEN_HOME + file[0..-4]
@@ -153,7 +161,11 @@ module Raven
153
161
  FileUtils.mkdir('ext')
154
162
  puts "Installing Gems:"
155
163
  artifacts.each do |artifact|
156
- http = Net::HTTP.new(artifact.server[0], artifact.server[1])
164
+ if @proxy_info
165
+ http = Net::HTTP::Proxy(*@proxy_info).new(artifact.server[0], artifact.server[1])
166
+ else
167
+ http = Net::HTTP.new(artifact.server[0], artifact.server[1])
168
+ end
157
169
  puts " - #{artifact.to_s}"
158
170
  gemname = Raven.install_remote_gem(artifact, http, artifact.server[2], true)
159
171
  params = [false]
@@ -0,0 +1,247 @@
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
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.1
7
- date: 2006-11-11 00:00:00 -08:00
6
+ version: 1.1.2
7
+ date: 2006-11-23 00:00:00 -08:00
8
8
  summary: Java build system based on Rake and Gem.
9
9
  require_paths:
10
10
  - lib
@@ -33,6 +33,7 @@ files:
33
33
  - bin/raven
34
34
  - lib/raven
35
35
  - lib/raven.rb
36
+ - lib/raven/search_install.rb~
36
37
  - lib/raven/deps_tasks.rb
37
38
  - lib/raven/gem_init.rb
38
39
  - lib/raven/java_tasks.rb