raven 1.0
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.
- data/LICENSE +176 -0
- data/README.rdoc +68 -0
- data/bin/raven +5 -0
- data/lib/raven.rb +78 -0
- data/lib/raven/deps_tasks.rb +153 -0
- data/lib/raven/gem_init.rb +84 -0
- data/lib/raven/index_gem_repository.rb +284 -0
- data/lib/raven/java_tasks.rb +399 -0
- data/lib/raven/repo_builder.rb +266 -0
- metadata +64 -0
@@ -0,0 +1,266 @@
|
|
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
|
+
require 'fileutils'
|
19
|
+
|
20
|
+
module Raven
|
21
|
+
|
22
|
+
DIR_EXCL = ['..', '.']
|
23
|
+
|
24
|
+
# Representation of a repository artifact. Mostly based on Maven with
|
25
|
+
# all the groupId and artifactId crap.
|
26
|
+
class Artifact
|
27
|
+
attr_reader :groupId, :artifactId, :versionId, :path
|
28
|
+
def initialize(groupId, artifactId, versionId, path)
|
29
|
+
@groupId, @artifactId, @versionId, @path = groupId, artifactId, versionId, path
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
# Enumerates on a Maven repository by scraping HTML. Yields on every
|
34
|
+
# artifact found in there.
|
35
|
+
class Maven2Repository
|
36
|
+
EXCLUDE = ["sha1", "md5", "pom"]
|
37
|
+
|
38
|
+
attr_writer :group_filters
|
39
|
+
|
40
|
+
def group_filters
|
41
|
+
@group_filters
|
42
|
+
end
|
43
|
+
|
44
|
+
def initialize(server, url)
|
45
|
+
@server, @url = server, url
|
46
|
+
end
|
47
|
+
|
48
|
+
def each
|
49
|
+
http = Net::HTTP.new(@server, 80)
|
50
|
+
folder_regexp = /<img src="\/icons\/folder.gif" alt="\[DIR\]"> <a href="[^\/]*\/">/
|
51
|
+
file_regexp = /<img src="\/icons\/unknown.gif" alt="\[ \]"> <a href="[^"]*">/
|
52
|
+
read_page(http, @url, folder_regexp) do |url1, groupId|
|
53
|
+
if @group_filters.nil? || @group_filters.include?(groupId)
|
54
|
+
puts "#{groupId}"
|
55
|
+
read_page(http, url1 + groupId + '/', folder_regexp) do |url2, artifactId|
|
56
|
+
puts " #{artifactId}"
|
57
|
+
read_page(http, url2 + artifactId + '/', folder_regexp) do |url3, versionId|
|
58
|
+
puts " #{versionId}"
|
59
|
+
art_path = "#{groupId}/#{artifactId}/#{versionId}/#{artifactId}-#{versionId}.jar"
|
60
|
+
artifact = Raven::Artifact.new(groupId, artifactId, versionId, art_path)
|
61
|
+
yield(artifact, http)
|
62
|
+
|
63
|
+
# Check each file if someday we want to package sources files or javadoc as well...
|
64
|
+
# read_page(http, url3 + versionId + '/', file_regexp, 52, 3) do |url4, filename|
|
65
|
+
# type = filename[(filename.rindex('.') + 1)..filename.length]
|
66
|
+
# end
|
67
|
+
end
|
68
|
+
end
|
69
|
+
end
|
70
|
+
end
|
71
|
+
end
|
72
|
+
|
73
|
+
def read_page(http, url, regexp, start=51, crop=4)
|
74
|
+
response = http.get(url, nil)
|
75
|
+
if response.message == "OK"
|
76
|
+
response.body.scan(regexp) do |line|
|
77
|
+
groupId = line[start..(line.length - crop)]
|
78
|
+
yield(url, groupId)
|
79
|
+
end
|
80
|
+
end
|
81
|
+
end
|
82
|
+
end
|
83
|
+
|
84
|
+
class GemRepoBuilder
|
85
|
+
attr_writer :group_filters
|
86
|
+
|
87
|
+
def initialize(server, url)
|
88
|
+
@server, @url = server, url
|
89
|
+
end
|
90
|
+
|
91
|
+
def build(overwrite = false)
|
92
|
+
repo = Maven2Repository.new(@server, @url)
|
93
|
+
repo.group_filters = @group_filters unless @group_filters.nil?
|
94
|
+
|
95
|
+
Dir.mkdir('gems') unless File.exist?('gems')
|
96
|
+
Dir.mkdir('gems/ext') unless File.exist?('gems/ext')
|
97
|
+
|
98
|
+
Dir.chdir('gems') do
|
99
|
+
repo.each do |artifact, http|
|
100
|
+
gemname = "#{artifact.groupId}-#{artifact.artifactId}-#{artifact.versionId}-java.gem"
|
101
|
+
if !File.exist?(gemname) || overwrite
|
102
|
+
with(artifact, 'ext', http) do
|
103
|
+
# The fileset is computed when gemspec is created, file must be there
|
104
|
+
gemspec = Raven.create_gemspec(artifact)
|
105
|
+
Gem::Builder.new(gemspec).build
|
106
|
+
end
|
107
|
+
end
|
108
|
+
end
|
109
|
+
end
|
110
|
+
|
111
|
+
end
|
112
|
+
|
113
|
+
def with(artifact, subdir, http)
|
114
|
+
response = http.get(@url + artifact.path, nil)
|
115
|
+
file = File.new(subdir + "/#{artifact.artifactId}-#{artifact.versionId}.jar", 'wb')
|
116
|
+
file.write(response.body)
|
117
|
+
file.close
|
118
|
+
yield
|
119
|
+
File.delete(subdir + "/#{artifact.artifactId}-#{artifact.versionId}.jar")
|
120
|
+
end
|
121
|
+
end
|
122
|
+
|
123
|
+
def self.create_gemspec(artifact)
|
124
|
+
spec = Gem::Specification.new do |s|
|
125
|
+
s.platform = Gem::Platform::JAVA
|
126
|
+
s.summary = "Raven wrapped library #{artifact.artifactId} from project #{artifact.groupId}."
|
127
|
+
s.name = "#{artifact.groupId}-#{artifact.artifactId}"
|
128
|
+
s.version = artifact.versionId
|
129
|
+
s.requirements << 'none'
|
130
|
+
s.require_path = 'ext'
|
131
|
+
s.autorequire = 'rake'
|
132
|
+
s.files = Dir.glob("{ext}/**/*")
|
133
|
+
end
|
134
|
+
end
|
135
|
+
|
136
|
+
|
137
|
+
class M2LocalRepository
|
138
|
+
def initialize(dir)
|
139
|
+
@dir = dir
|
140
|
+
end
|
141
|
+
|
142
|
+
def each_old
|
143
|
+
Raven.dir_each(@dir) do |groupId|
|
144
|
+
Raven.dir_each(File.join(@dir, groupId)) do |artifactId|
|
145
|
+
Raven.dir_each(File.join(@dir, groupId, artifactId)) do |versionId|
|
146
|
+
art_path = "#{groupId}/#{artifactId}/#{versionId}/#{artifactId}-#{versionId}.jar"
|
147
|
+
artifact = Raven::Artifact.new(groupId, artifactId, versionId, art_path)
|
148
|
+
yield(artifact)
|
149
|
+
end
|
150
|
+
end
|
151
|
+
end
|
152
|
+
end
|
153
|
+
|
154
|
+
def each
|
155
|
+
queue = ['']
|
156
|
+
while (queue.length > 0)
|
157
|
+
path = queue.pop
|
158
|
+
# Going down each folder until we find a jar
|
159
|
+
Raven.dir_each(File.join(@dir, path)) do |elmt|
|
160
|
+
if (File.file?(File.join(@dir, path, elmt)))
|
161
|
+
if (elmt[-4..-1] == '.jar')
|
162
|
+
# Extracting group, artifact and version from the full path
|
163
|
+
c_path = File.join(path, elmt)
|
164
|
+
groupNArt = c_path[/^.*\/[0-9]/][1..-3].gsub(File::SEPARATOR, '.')
|
165
|
+
groupId = groupNArt[0..(groupNArt.rindex('.') -1)]
|
166
|
+
artifactId = groupNArt[(groupNArt.rindex('.') + 1) .. -1]
|
167
|
+
v1 = c_path[0..c_path.rindex('/') - 1]
|
168
|
+
versionId = v1[v1.rindex('/')+1..-1]
|
169
|
+
art_path = "#{groupId.gsub('.', File::SEPARATOR)}/#{artifactId}/#{versionId}/#{artifactId}-#{versionId}.jar"
|
170
|
+
artifact = Raven::Artifact.new(groupId, artifactId, versionId, art_path)
|
171
|
+
yield artifact
|
172
|
+
break
|
173
|
+
end
|
174
|
+
else
|
175
|
+
queue << File.join(path, elmt)
|
176
|
+
end
|
177
|
+
end
|
178
|
+
end
|
179
|
+
end
|
180
|
+
end
|
181
|
+
|
182
|
+
class M1LocalRepository
|
183
|
+
def initialize(dir)
|
184
|
+
@dir = dir
|
185
|
+
end
|
186
|
+
|
187
|
+
def each
|
188
|
+
Raven.dir_each(@dir) do |groupId|
|
189
|
+
if (File.exist?(File.join(@dir, groupId, 'jars')))
|
190
|
+
Raven.dir_each(File.join(@dir, groupId, 'jars')) do |filename|
|
191
|
+
next if filename[-4, 4] != '.jar'
|
192
|
+
begin
|
193
|
+
versionId = filename[/-[^a-z].*\.jar/][1..-5]
|
194
|
+
artifactId = filename[0..(-versionId.length-6)]
|
195
|
+
art_path = "#{groupId}/jars/#{artifactId}-#{versionId}.jar"
|
196
|
+
artifact = Raven::Artifact.new(groupId, artifactId, versionId, art_path)
|
197
|
+
yield(artifact)
|
198
|
+
rescue NoMethodError
|
199
|
+
# Will happen if one of the regular expressions return nil
|
200
|
+
puts "File #{filename} doesn't seem to be correctly named, ignoring."
|
201
|
+
end
|
202
|
+
end
|
203
|
+
end
|
204
|
+
end
|
205
|
+
end
|
206
|
+
end
|
207
|
+
|
208
|
+
module MavenLocalRepoImport
|
209
|
+
def self.run
|
210
|
+
# Trying to find out where the local repository is
|
211
|
+
maven_home = ENV['MAVEN_HOME'] ? ENV['MAVEN_HOME'] : ''
|
212
|
+
repo_home = self.select_repo([maven_home + '/repository', USER_HOME + '/.maven/repository', USER_HOME + '/.m2/repository'])
|
213
|
+
if repo_home
|
214
|
+
print "Found a Maven repository in #{repo_home}, do you want to use this one? (y/n)"
|
215
|
+
puts '' while (!['y', 'n'].include?(answer = gets.chomp))
|
216
|
+
end
|
217
|
+
repo_home = nil if answer == 'n'
|
218
|
+
unless repo_home
|
219
|
+
puts "Please provide the path to your maven repository to convert."
|
220
|
+
puts "Path doesn't exist! Try again..." while (!File.exist?(repo_home = gets.chomp))
|
221
|
+
end
|
222
|
+
# Detect the repository type (2 first entries are always . and ..)
|
223
|
+
first_subdir = Dir.entries(File.join(repo_home, Dir.entries(repo_home)[2]))[2]
|
224
|
+
repo = (first_subdir == 'jars') ? M1LocalRepository.new(repo_home) : M2LocalRepository.new(repo_home)
|
225
|
+
|
226
|
+
FileUtils.mkdir('ext') unless File.exist?('ext')
|
227
|
+
repo.each do |artifact|
|
228
|
+
if File.exist?(File.join(repo_home, artifact.path))
|
229
|
+
# Building Gem
|
230
|
+
FileUtils.cp(File.join(repo_home, artifact.path), 'ext')
|
231
|
+
gemspec = Raven.create_gemspec(artifact)
|
232
|
+
Gem::Builder.new(gemspec).build
|
233
|
+
# Installing Gem
|
234
|
+
params = [false]
|
235
|
+
params << USER_HOME + "/.raven_gems" if defined?(GEMS_IN_HOME)
|
236
|
+
Gem::Installer.new("#{artifact.groupId}-#{artifact.artifactId}-#{artifact.versionId}-java.gem").install(*params)
|
237
|
+
# Cleaning up for next iteration
|
238
|
+
FileUtils.rm(Dir.glob('ext/*'))
|
239
|
+
FileUtils.rm(Dir.glob('*.gem'))
|
240
|
+
else
|
241
|
+
puts "File #{artifact.path} couldn't be found, ignoring."
|
242
|
+
end
|
243
|
+
end
|
244
|
+
FileUtils.rm_r('ext')
|
245
|
+
end
|
246
|
+
|
247
|
+
def self.select_repo(paths)
|
248
|
+
paths.each { |p| return p if File.exist?(p) }
|
249
|
+
nil
|
250
|
+
end
|
251
|
+
end
|
252
|
+
|
253
|
+
def self.dir_each(path)
|
254
|
+
Dir.foreach(path) do |elmt|
|
255
|
+
next if DIR_EXCL.include?(elmt)
|
256
|
+
yield(elmt)
|
257
|
+
end
|
258
|
+
end
|
259
|
+
|
260
|
+
end
|
261
|
+
|
262
|
+
# builder = Raven::GemRepoBuilder.new('www.ibiblio.org', '/maven2/')
|
263
|
+
# builder.group_filters = ['log4j', 'wsdl4j', 'commons-logging', 'commons-lang']
|
264
|
+
# builder.build()
|
265
|
+
|
266
|
+
|
metadata
ADDED
@@ -0,0 +1,64 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
rubygems_version: 0.9.0
|
3
|
+
specification_version: 1
|
4
|
+
name: raven
|
5
|
+
version: !ruby/object:Gem::Version
|
6
|
+
version: "1.0"
|
7
|
+
date: 2006-09-17 00:00:00 -07:00
|
8
|
+
summary: Java build system based on Rake and Gem.
|
9
|
+
require_paths:
|
10
|
+
- lib
|
11
|
+
email:
|
12
|
+
homepage: http://raven.rubyforge.org
|
13
|
+
rubyforge_project:
|
14
|
+
description:
|
15
|
+
autorequire: raven
|
16
|
+
default_executable:
|
17
|
+
bindir: bin
|
18
|
+
has_rdoc: true
|
19
|
+
required_ruby_version: !ruby/object:Gem::Version::Requirement
|
20
|
+
requirements:
|
21
|
+
- - ">"
|
22
|
+
- !ruby/object:Gem::Version
|
23
|
+
version: 0.0.0
|
24
|
+
version:
|
25
|
+
platform: ruby
|
26
|
+
signing_key:
|
27
|
+
cert_chain:
|
28
|
+
post_install_message:
|
29
|
+
authors:
|
30
|
+
- Matthieu Riou
|
31
|
+
files:
|
32
|
+
- bin/raven
|
33
|
+
- lib/raven
|
34
|
+
- lib/raven.rb
|
35
|
+
- lib/raven/deps_tasks.rb
|
36
|
+
- lib/raven/gem_init.rb
|
37
|
+
- lib/raven/java_tasks.rb
|
38
|
+
- lib/raven/repo_builder.rb
|
39
|
+
- lib/raven/index_gem_repository.rb
|
40
|
+
- README.rdoc
|
41
|
+
- LICENSE
|
42
|
+
test_files: []
|
43
|
+
|
44
|
+
rdoc_options: []
|
45
|
+
|
46
|
+
extra_rdoc_files:
|
47
|
+
- README.rdoc
|
48
|
+
- LICENSE
|
49
|
+
executables:
|
50
|
+
- raven
|
51
|
+
extensions: []
|
52
|
+
|
53
|
+
requirements: []
|
54
|
+
|
55
|
+
dependencies:
|
56
|
+
- !ruby/object:Gem::Dependency
|
57
|
+
name: rake
|
58
|
+
version_requirement:
|
59
|
+
version_requirements: !ruby/object:Gem::Version::Requirement
|
60
|
+
requirements:
|
61
|
+
- - ">="
|
62
|
+
- !ruby/object:Gem::Version
|
63
|
+
version: "0.7"
|
64
|
+
version:
|