<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head><meta http-equiv="content-type" content="text/html; charset=utf-8" /><style type="text/css"><!--
#msg dl { border: 1px #006 solid; background: #369; padding: 6px; color: #fff; }
#msg dt { float: left; width: 6em; font-weight: bold; }
#msg dt:after { content:':';}
#msg dl, #msg dt, #msg ul, #msg li, #header, #footer { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; }
#msg dl a { font-weight: bold}
#msg dl a:link { color:#fc3; }
#msg dl a:active { color:#ff0; }
#msg dl a:visited { color:#cc6; }
h3 { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; font-weight: bold; }
#msg pre { overflow: auto; background: #ffc; border: 1px #fc0 solid; padding: 6px; }
#msg ul, pre { overflow: auto; }
#header, #footer { color: #fff; background: #636; border: 1px #300 solid; padding: 6px; }
#patch { width: 100%; }
#patch h4 {font-family: verdana,arial,helvetica,sans-serif;font-size:10pt;padding:8px;background:#369;color:#fff;margin:0;}
#patch .propset h4, #patch .binary h4 {margin:0;}
#patch pre {padding:0;line-height:1.2em;margin:0;}
#patch .diff {width:100%;background:#eee;padding: 0 0 10px 0;overflow:auto;}
#patch .propset .diff, #patch .binary .diff {padding:10px 0;}
#patch span {display:block;padding:0 10px;}
#patch .modfile, #patch .addfile, #patch .delfile, #patch .propset, #patch .binary, #patch .copfile {border:1px solid #ccc;margin:10px 0;}
#patch ins {background:#dfd;text-decoration:none;display:block;padding:0 10px;}
#patch del {background:#fdd;text-decoration:none;display:block;padding:0 10px;}
#patch .lines, .info {color:#888;background:#fff;}
--></style>
<title>[187] trunk/lib/raven: Renaming maven_crap.rb for a more suitable (well, say descriptive) name.</title>
</head>
<body>
<div id="msg">
<dl>
<dt>Revision</dt> <dd>187</dd>
<dt>Author</dt> <dd>mriou</dd>
<dt>Date</dt> <dd>2007-04-04 21:34:57 -0400 (Wed, 04 Apr 2007)</dd>
</dl>
<h3>Log Message</h3>
<pre>Renaming maven_crap.rb for a more suitable (well, say descriptive) name.</pre>
<h3>Added Paths</h3>
<ul>
<li><a href="#trunklibravenmaven_reporb">trunk/lib/raven/maven_repo.rb</a></li>
</ul>
<h3>Removed Paths</h3>
<ul>
<li><a href="#trunklibravenmaven_craprb">trunk/lib/raven/maven_crap.rb</a></li>
</ul>
</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunklibravenmaven_craprb"></a>
<div class="delfile"><h4>Deleted: trunk/lib/raven/maven_crap.rb (186 => 187)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/lib/raven/maven_crap.rb        2007-04-05 01:33:58 UTC (rev 186)
+++ trunk/lib/raven/maven_crap.rb        2007-04-05 01:34:57 UTC (rev 187)
</span><span class="lines">@@ -1,410 +0,0 @@
</span><del>-#!/usr/bin/env ruby
-
-# Copyright 2006 Matthieu Riou
-#
-# Licensed under the Apache License, Version 2.0 (the "License");
-# you may not use this file except in compliance with the License.
-# You may obtain a copy of the License at
-#
-# http://www.apache.org/licenses/LICENSE-2.0
-#
-# Unless required by applicable law or agreed to in writing, software
-# distributed under the License is distributed on an "AS IS" BASIS,
-# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-# See the License for the specific language governing permissions and
-# limitations under the License.
-
-require 'net/http'
-require 'fileutils'
-
-module Raven
-
- MAVEN_HOME = ENV['MAVEN_HOME'] ? ENV['MAVEN_HOME'] : Raven.maven_repo_home
- DIR_EXCL = ['..', '.']
-
- # Representation of a repository artifact. Mostly based on Maven with
- # all the groupId and artifactId crap.
-
- class Artifact
-
- attr_reader :group, :name, :version, :path
-
- attr_accessor :server
-
- def initialize(group, name, version, path)
- @group, @name, @version, @path = group, name, version, path
- end
-
- def to_yaml_properties
- %w{ @group @name @version @path }
- end
-
- def ==(art) eql?(art); end
- def ===(art) eql?(art); end
- def eql?(art)
- false if art.class != Artifact
- art.group == @group && art.name == @name && art.version == @version
- end
-
- def hash
- @group.hash ^ (@name.hash << 1) ^ (@version.hash << 2)
- end
-
- def to_s
- "#{name} v#{version} (project #{group})"
- end
- end
-
- # Enumerates on a Maven repository by scraping HTML. Yields on every
- # artifact found in there.
- class Maven2Repository
- EXCLUDE = ["sha1", "md5", "pom"]
-
- attr_writer :group_filters
-
- def group_filters
- @group_filters
- end
-
- def initialize(server, port, url, proxy_info)
- @server, @url, @port, @proxy_info = server, url, port, proxy_info
- end
-
- def each_old
- if @proxy_info
- http = Net::HTTP::Proxy(*@proxy_info).new(@server, @port)
- else
- http = Net::HTTP.new(@server, @port)
- end
- folder_regexp = /<img src="\/icons\/folder.gif" alt="\[DIR\]"> <a href="[^\/]*\/">/
- file_regexp = /<img src="\/icons\/unknown.gif" alt="\[ \]"> <a href="[^"]*">/
- read_page(http, @url, folder_regexp) do |url1, group|
- if @group_filters.nil? || @group_filters.include?(group)
- puts "#{group}"
- read_page(http, url1 + group + '/', folder_regexp) do |url2, name|
- puts " #{name}"
- read_page(http, url2 + name + '/', folder_regexp) do |url3, version|
- puts " #{version}"
- art_path = "#{group}/#{name}/#{version}/#{name}-#{version}.jar"
- artifact = Raven::Artifact.new(group, name, version, art_path)
- yield(artifact, http)
-
- # Check each file if someday we want to package sources files or javadoc as well...
- # read_page(http, url3 + version + '/', file_regexp, 52, 3) do |url4, filename|
- # type = filename[(filename.rindex('.') + 1)..filename.length]
- # end
- end
- end
- end
- end
- end
-
- def each
- if @proxy_info
- http = Net::HTTP::Proxy(*@proxy_info).new(@server, @port)
- else
- http = Net::HTTP.new(@server, @port)
- end
-
- folder_regexp = /<img src="\/icons\/folder.gif" alt="\[DIR\]"> <a href="[^\/]*\/">/
- file_regexp = /<img src="\/icons\/unknown.gif" alt="\[ \]"> <a href="[^"]*">/
-
- urls = @group_filters || ['/']
- while !urls.empty?
- url = urls.shift
- response = http.get(@url + url, nil)
- if (folder_regexp =~ response.body)
- response.body.scan(folder_regexp) { |line| urls << "#{url}#{line[51..(line.length - 4)]}/" }
- else
- url_arr = url.split('/')
- puts "arl art #{url_arr}"
- version = url_arr.pop
- name = url_arr.pop
- #url_arr.shift removing first empty element
- group = url_arr.join('.')
- if (file_regexp =~ response.body)
- art_path = "#{group.gsub('.', '/')}/#{name}/#{version}/#{name}-#{version}.jar"
- artifact = Raven::Artifact.new(group, name, version, art_path)
- puts "Found artifact #{artifact} in group #{group}"
- yield(artifact, http)
- end
- end
- end
- end
-
- def read_page(http, url, regexp, start=51, crop=4)
- response = http.get(url, nil)
- if response.is_a? Net::HTTPSuccess
- response.body.scan(regexp) do |line|
- group = line[start..(line.length - crop)]
- yield(url, group)
- end
- else
- STDERR.puts "Error connecting to repository: #{response.message}"
- if response.is_a?(Net::HTTPRedirection) && response["location"]
- puts "Location: #{response['location']}"
- else
- puts "------ RESPONSE CODE -----------------------------"
- puts "Response code: #{response.code}"
- puts "------ HEADERS -----------------------------------"
- response.each_header do |key, value|
- puts "#{key}: #{value}"
- end
- puts "------ CONTENT -----------------------------------"
- puts response.body
- puts '-' * 50
- end
- end
- end
- end
-
- class LocalRepository
-
- attr :dir, true
-
- def initialize(path)
- @dir = path
- end
-
- def self.match_files(dir, pattern)
-
- queue = ['']
-
- while (queue.length > 0)
-
- path = queue.pop
-
- Raven.dir_each(File.join(dir, path)) do |entry|
- if (File.file?(fullpath = File.join(dir, path, entry)))
- yield fullpath if File.fnmatch(pattern, entry)
- else
- queue << File.join(path, entry)
- end
- end
- end
- end
-
- end
-
-
- class M2LocalRepository < LocalRepository
-
- # Directory is considered a Maven 2 repository if at least one
- # '*.pom' file is present in a subdirectory.
-
- def self.valid(path)
- self.match_files(path, '*.pom') { |match| return true }
- end
-
- # Iterate over 'poms' in the repository, constructing and
- # returning an Artifact for each.
-
- def each
- M2LocalRepository.match_files(@dir, "*.pom") do |pom_path|
- jar_path = pom_path.sub("\.pom$", ".jar");
-
- begin
- pom = MavenPom.new(java.io.FileInputStream.new(pom_path))
- artifact = Raven::Artifact.new(pom.groupId, pom.artifactId, pom.version, jar_path)
- yield artifact
- rescue Exception=> e
- Raven.log_error("Failed to construct POM: #{e}")
- end
- end
- end
-
- end
-
- class M1LocalRepository < LocalRepository
-
- # Directory is considered a Maven 1 repository if at least one
- # 'jars' directory is present in a subdirectory.
-
- def self.valid(path)
- Raven.with_directory(path) { return !Dir['*/jars'].empty? }
- end
-
- def each
- Raven.dir_each(@dir) do |group|
- if (File.exist?(File.join(@dir, group, 'jars')))
- Raven.dir_each(File.join(@dir, group, 'jars')) do |filename|
- next if filename[-4, 4] != '.jar'
- begin
- version = filename[/-[^a-z].*\.jar/][1..-5]
- name = filename[0..(-version.length-6)]
- art_path = "#{group}/jars/#{name}-#{version}.jar"
- artifact = Raven::Artifact.new(group, name, version, art_path)
- yield(artifact)
- rescue NoMethodError
- # Will happen if one of the regular expressions return nil
- puts "File #{filename} doesn't seem to be correctly named, ignoring."
- end
- end
- end
- end
- end
-
- end
-
- module MavenLocalRepoImport
-
- def self.run
-
- Raven.log_debug("Trying to find out where the local repository is")
-
- repo = self.select_repo([MAVEN_HOME + '/repository',
- USER_HOME + '/.maven/repository',
- USER_HOME + '/.m2/repository'])
- if repo
- print "Found a Maven repository in #{repo.dir}, do you want to use this one? (y/n)"
- puts '' while (!['y', 'n'].include?(answer = gets.chomp))
- end
-
- repo = self.select_interactively if answer == 'n'
-
- FileUtils.mkdir('ext') unless File.exist?('ext')
- repo.each do |artifact|
- if File.exist?(artifact.path)
- # Building Gem
- FileUtils.cp(artifact.path, 'ext')
- gemspec = Raven.create_gemspec(artifact)
- Gem::Builder.new(gemspec).build
- # Installing Gem
- params = [false]
- params << RAVEN_HOME if defined?(GEMS_IN_HOME)
- Gem::Installer.new("#{artifact.group}-#{artifact.name}-#{artifact.version}-java.gem").install(*params)
- # Cleaning up for next iteration
- FileUtils.rm(Dir.glob('ext/*'))
- FileUtils.rm(Dir.glob('*.gem'))
- else
- puts "File #{artifact.path} couldn't be found, ignoring."
- end
- end
- FileUtils.rm_r('ext')
- end
-
- def self.select_repo(paths)
- paths.each do |p|
- return self.repository_new(p) if self.repository_type(p)
- end
- nil
- end
-
- def self.repository_type(path)
- return if !File.exist?(path)
- if M1LocalRepository.valid(path)
- STDOUT << "Repo at #{path} is M1"
- return :maven1
- elsif M2LocalRepository.valid(path)
- STDOUT << "Repo at #{path} is M2"
- return :maven2
- end
- end
-
- def self.repository_new(path)
- case self.repository_type(path)
- when :maven1
- M1LocalRepository.new(path)
- when :maven2
- M2LocalRepository.new(path)
- else
- raise "Unable to determine Maven repository type."
- end
- end
-
- def self.select_interactively()
- puts "Please provide the path to your maven repository to convert."
- puts "Path doesn't exist! Try again..." while (!self.repository_type(path = gets.chomp))
- self.repository_new(path)
- end
-
- end
-
- # Structured version class used to try to make some sense
- # out of Maven version numbers. A difficult task indeed.
-
- class Version
- include Comparable
- attr_reader :timestamp, :ver_struct, :version
-
- def initialize(version)
- @version = version
- elmts = @version.split(/\.|-/)
- @timestamp = elmts[0].length > 3 ? true : false
- @ver_struct = elmts.collect do |elmt|
- val = ''
- begin
- val = Integer(elmt)
- rescue ArgumentError
- val = elmt
- end
- val
- end
- end
-
- def <=>(ver)
- false if !(Version === ver)
- return -1 if @timestamp && !ver.timestamp
- return 1 if !@timestamp && ver.timestamp
- # Adding 0 to the end of the shortest one to get the same
- # size, JRuby considers size first (even if size doesn't
- # always matter)
- @me, you = @ver_struct.dup, ver.ver_struct.dup
- if (@me.size != you.size)
- shorty = @me.size > you.size ? you : @me
- biggy = @me.size > you.size ? @me : you
- (shorty.size..biggy.size-1).each { |m| shorty[m] = 0 }
- end
- # Setting string elements to 0 (mostly weaker) if they need
- # to be compared to an int otherwise <=> could produce nil
- (0..@me.size).each do |m|
- if (m < you.size && @me[m].class != you[m].class)
- @me[m] = 0 if String === @me[m]
- you[m] = 0 if String === you[m]
- end
- end
- @me <=> you
- end
-
- def to_s
- puts "v#{@version}, ts #{timestamp}, #{ @ver_struct.collect{ |v| v.class }.join('/') }"
- end
- end
-
- def self.dir_each(path)
- Dir.foreach(path) do |elmt|
- next if DIR_EXCL.include?(elmt)
- yield(elmt)
- end
- end
-
- def self.create_gemspec(artifact, dependencies=[])
- spec = Gem::Specification.new do |s|
- s.platform = Gem::Platform::JAVA
- s.summary = "Raven wrapped library #{artifact.name} from project #{artifact.group}."
- s.name = "#{artifact.group}-#{artifact.name}"
- s.version = artifact.version
- s.requirements << 'none'
- s.require_path = 'ext'
- s.autorequire = 'rake'
- s.files = Dir.glob("{ext}/**/*")
- dependencies.each { |dep| s.add_dependency("#{dep.group}-#{dep.name}", "=#{dep.version}") }
- end
- end
-
- def self.with_directory(directory)
- saved = Dir.getwd()
- Dir.chdir(directory)
- yield
- ensure
- Dir.chdir(saved)
- end
-
- class GemTooManyInstallError < RuntimeError
- attr_reader :artifacts
- def initialize(arts)
- @artifacts = arts
- end
- end
-
-end
</del></span></pre></div>
<a id="trunklibravenmaven_reporbfromrev186trunklibravenmaven_craprb"></a>
<div class="copfile"><h4>Copied: trunk/lib/raven/maven_repo.rb (from rev 186, trunk/lib/raven/maven_crap.rb) (0 => 187)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/lib/raven/maven_repo.rb         (rev 0)
+++ trunk/lib/raven/maven_repo.rb        2007-04-05 01:34:57 UTC (rev 187)
</span><span class="lines">@@ -0,0 +1,410 @@
</span><ins>+#!/usr/bin/env ruby
+
+# Copyright 2006 Matthieu Riou
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+require 'net/http'
+require 'fileutils'
+
+module Raven
+
+ MAVEN_HOME = ENV['MAVEN_HOME'] ? ENV['MAVEN_HOME'] : Raven.maven_repo_home
+ DIR_EXCL = ['..', '.']
+
+ # Representation of a repository artifact. Mostly based on Maven with
+ # all the groupId and artifactId crap.
+
+ class Artifact
+
+ attr_reader :group, :name, :version, :path
+
+ attr_accessor :server
+
+ def initialize(group, name, version, path)
+ @group, @name, @version, @path = group, name, version, path
+ end
+
+ def to_yaml_properties
+ %w{ @group @name @version @path }
+ end
+
+ def ==(art) eql?(art); end
+ def ===(art) eql?(art); end
+ def eql?(art)
+ false if art.class != Artifact
+ art.group == @group && art.name == @name && art.version == @version
+ end
+
+ def hash
+ @group.hash ^ (@name.hash << 1) ^ (@version.hash << 2)
+ end
+
+ def to_s
+ "#{name} v#{version} (project #{group})"
+ end
+ end
+
+ # Enumerates on a Maven repository by scraping HTML. Yields on every
+ # artifact found in there.
+ class Maven2Repository
+ EXCLUDE = ["sha1", "md5", "pom"]
+
+ attr_writer :group_filters
+
+ def group_filters
+ @group_filters
+ end
+
+ def initialize(server, port, url, proxy_info)
+ @server, @url, @port, @proxy_info = server, url, port, proxy_info
+ end
+
+ def each_old
+ if @proxy_info
+ http = Net::HTTP::Proxy(*@proxy_info).new(@server, @port)
+ else
+ http = Net::HTTP.new(@server, @port)
+ end
+ folder_regexp = /<img src="\/icons\/folder.gif" alt="\[DIR\]"> <a href="[^\/]*\/">/
+ file_regexp = /<img src="\/icons\/unknown.gif" alt="\[ \]"> <a href="[^"]*">/
+ read_page(http, @url, folder_regexp) do |url1, group|
+ if @group_filters.nil? || @group_filters.include?(group)
+ puts "#{group}"
+ read_page(http, url1 + group + '/', folder_regexp) do |url2, name|
+ puts " #{name}"
+ read_page(http, url2 + name + '/', folder_regexp) do |url3, version|
+ puts " #{version}"
+ art_path = "#{group}/#{name}/#{version}/#{name}-#{version}.jar"
+ artifact = Raven::Artifact.new(group, name, version, art_path)
+ yield(artifact, http)
+
+ # Check each file if someday we want to package sources files or javadoc as well...
+ # read_page(http, url3 + version + '/', file_regexp, 52, 3) do |url4, filename|
+ # type = filename[(filename.rindex('.') + 1)..filename.length]
+ # end
+ end
+ end
+ end
+ end
+ end
+
+ def each
+ if @proxy_info
+ http = Net::HTTP::Proxy(*@proxy_info).new(@server, @port)
+ else
+ http = Net::HTTP.new(@server, @port)
+ end
+
+ folder_regexp = /<img src="\/icons\/folder.gif" alt="\[DIR\]"> <a href="[^\/]*\/">/
+ file_regexp = /<img src="\/icons\/unknown.gif" alt="\[ \]"> <a href="[^"]*">/
+
+ urls = @group_filters || ['/']
+ while !urls.empty?
+ url = urls.shift
+ response = http.get(@url + url, nil)
+ if (folder_regexp =~ response.body)
+ response.body.scan(folder_regexp) { |line| urls << "#{url}#{line[51..(line.length - 4)]}/" }
+ else
+ url_arr = url.split('/')
+ puts "arl art #{url_arr}"
+ version = url_arr.pop
+ name = url_arr.pop
+ #url_arr.shift removing first empty element
+ group = url_arr.join('.')
+ if (file_regexp =~ response.body)
+ art_path = "#{group.gsub('.', '/')}/#{name}/#{version}/#{name}-#{version}.jar"
+ artifact = Raven::Artifact.new(group, name, version, art_path)
+ puts "Found artifact #{artifact} in group #{group}"
+ yield(artifact, http)
+ end
+ end
+ end
+ end
+
+ def read_page(http, url, regexp, start=51, crop=4)
+ response = http.get(url, nil)
+ if response.is_a? Net::HTTPSuccess
+ response.body.scan(regexp) do |line|
+ group = line[start..(line.length - crop)]
+ yield(url, group)
+ end
+ else
+ STDERR.puts "Error connecting to repository: #{response.message}"
+ if response.is_a?(Net::HTTPRedirection) && response["location"]
+ puts "Location: #{response['location']}"
+ else
+ puts "------ RESPONSE CODE -----------------------------"
+ puts "Response code: #{response.code}"
+ puts "------ HEADERS -----------------------------------"
+ response.each_header do |key, value|
+ puts "#{key}: #{value}"
+ end
+ puts "------ CONTENT -----------------------------------"
+ puts response.body
+ puts '-' * 50
+ end
+ end
+ end
+ end
+
+ class LocalRepository
+
+ attr :dir, true
+
+ def initialize(path)
+ @dir = path
+ end
+
+ def self.match_files(dir, pattern)
+
+ queue = ['']
+
+ while (queue.length > 0)
+
+ path = queue.pop
+
+ Raven.dir_each(File.join(dir, path)) do |entry|
+ if (File.file?(fullpath = File.join(dir, path, entry)))
+ yield fullpath if File.fnmatch(pattern, entry)
+ else
+ queue << File.join(path, entry)
+ end
+ end
+ end
+ end
+
+ end
+
+
+ class M2LocalRepository < LocalRepository
+
+ # Directory is considered a Maven 2 repository if at least one
+ # '*.pom' file is present in a subdirectory.
+
+ def self.valid(path)
+ self.match_files(path, '*.pom') { |match| return true }
+ end
+
+ # Iterate over 'poms' in the repository, constructing and
+ # returning an Artifact for each.
+
+ def each
+ M2LocalRepository.match_files(@dir, "*.pom") do |pom_path|
+ jar_path = pom_path.sub("\.pom$", ".jar");
+
+ begin
+ pom = MavenPom.new(java.io.FileInputStream.new(pom_path))
+ artifact = Raven::Artifact.new(pom.groupId, pom.artifactId, pom.version, jar_path)
+ yield artifact
+ rescue Exception=> e
+ Raven.log_error("Failed to construct POM: #{e}")
+ end
+ end
+ end
+
+ end
+
+ class M1LocalRepository < LocalRepository
+
+ # Directory is considered a Maven 1 repository if at least one
+ # 'jars' directory is present in a subdirectory.
+
+ def self.valid(path)
+ Raven.with_directory(path) { return !Dir['*/jars'].empty? }
+ end
+
+ def each
+ Raven.dir_each(@dir) do |group|
+ if (File.exist?(File.join(@dir, group, 'jars')))
+ Raven.dir_each(File.join(@dir, group, 'jars')) do |filename|
+ next if filename[-4, 4] != '.jar'
+ begin
+ version = filename[/-[^a-z].*\.jar/][1..-5]
+ name = filename[0..(-version.length-6)]
+ art_path = "#{group}/jars/#{name}-#{version}.jar"
+ artifact = Raven::Artifact.new(group, name, version, art_path)
+ yield(artifact)
+ rescue NoMethodError
+ # Will happen if one of the regular expressions return nil
+ puts "File #{filename} doesn't seem to be correctly named, ignoring."
+ end
+ end
+ end
+ end
+ end
+
+ end
+
+ module MavenLocalRepoImport
+
+ def self.run
+
+ Raven.log_debug("Trying to find out where the local repository is")
+
+ repo = self.select_repo([MAVEN_HOME + '/repository',
+ USER_HOME + '/.maven/repository',
+ USER_HOME + '/.m2/repository'])
+ if repo
+ print "Found a Maven repository in #{repo.dir}, do you want to use this one? (y/n)"
+ puts '' while (!['y', 'n'].include?(answer = gets.chomp))
+ end
+
+ repo = self.select_interactively if answer == 'n'
+
+ FileUtils.mkdir('ext') unless File.exist?('ext')
+ repo.each do |artifact|
+ if File.exist?(artifact.path)
+ # Building Gem
+ FileUtils.cp(artifact.path, 'ext')
+ gemspec = Raven.create_gemspec(artifact)
+ Gem::Builder.new(gemspec).build
+ # Installing Gem
+ params = [false]
+ params << RAVEN_HOME if defined?(GEMS_IN_HOME)
+ Gem::Installer.new("#{artifact.group}-#{artifact.name}-#{artifact.version}-java.gem").install(*params)
+ # Cleaning up for next iteration
+ FileUtils.rm(Dir.glob('ext/*'))
+ FileUtils.rm(Dir.glob('*.gem'))
+ else
+ puts "File #{artifact.path} couldn't be found, ignoring."
+ end
+ end
+ FileUtils.rm_r('ext')
+ end
+
+ def self.select_repo(paths)
+ paths.each do |p|
+ return self.repository_new(p) if self.repository_type(p)
+ end
+ nil
+ end
+
+ def self.repository_type(path)
+ return if !File.exist?(path)
+ if M1LocalRepository.valid(path)
+ STDOUT << "Repo at #{path} is M1"
+ return :maven1
+ elsif M2LocalRepository.valid(path)
+ STDOUT << "Repo at #{path} is M2"
+ return :maven2
+ end
+ end
+
+ def self.repository_new(path)
+ case self.repository_type(path)
+ when :maven1
+ M1LocalRepository.new(path)
+ when :maven2
+ M2LocalRepository.new(path)
+ else
+ raise "Unable to determine Maven repository type."
+ end
+ end
+
+ def self.select_interactively()
+ puts "Please provide the path to your maven repository to convert."
+ puts "Path doesn't exist! Try again..." while (!self.repository_type(path = gets.chomp))
+ self.repository_new(path)
+ end
+
+ end
+
+ # Structured version class used to try to make some sense
+ # out of Maven version numbers. A difficult task indeed.
+
+ class Version
+ include Comparable
+ attr_reader :timestamp, :ver_struct, :version
+
+ def initialize(version)
+ @version = version
+ elmts = @version.split(/\.|-/)
+ @timestamp = elmts[0].length > 3 ? true : false
+ @ver_struct = elmts.collect do |elmt|
+ val = ''
+ begin
+ val = Integer(elmt)
+ rescue ArgumentError
+ val = elmt
+ end
+ val
+ end
+ end
+
+ def <=>(ver)
+ false if !(Version === ver)
+ return -1 if @timestamp && !ver.timestamp
+ return 1 if !@timestamp && ver.timestamp
+ # Adding 0 to the end of the shortest one to get the same
+ # size, JRuby considers size first (even if size doesn't
+ # always matter)
+ @me, you = @ver_struct.dup, ver.ver_struct.dup
+ if (@me.size != you.size)
+ shorty = @me.size > you.size ? you : @me
+ biggy = @me.size > you.size ? @me : you
+ (shorty.size..biggy.size-1).each { |m| shorty[m] = 0 }
+ end
+ # Setting string elements to 0 (mostly weaker) if they need
+ # to be compared to an int otherwise <=> could produce nil
+ (0..@me.size).each do |m|
+ if (m < you.size && @me[m].class != you[m].class)
+ @me[m] = 0 if String === @me[m]
+ you[m] = 0 if String === you[m]
+ end
+ end
+ @me <=> you
+ end
+
+ def to_s
+ puts "v#{@version}, ts #{timestamp}, #{ @ver_struct.collect{ |v| v.class }.join('/') }"
+ end
+ end
+
+ def self.dir_each(path)
+ Dir.foreach(path) do |elmt|
+ next if DIR_EXCL.include?(elmt)
+ yield(elmt)
+ end
+ end
+
+ def self.create_gemspec(artifact, dependencies=[])
+ spec = Gem::Specification.new do |s|
+ s.platform = Gem::Platform::JAVA
+ s.summary = "Raven wrapped library #{artifact.name} from project #{artifact.group}."
+ s.name = "#{artifact.group}-#{artifact.name}"
+ s.version = artifact.version
+ s.requirements << 'none'
+ s.require_path = 'ext'
+ s.autorequire = 'rake'
+ s.files = Dir.glob("{ext}/**/*")
+ dependencies.each { |dep| s.add_dependency("#{dep.group}-#{dep.name}", "=#{dep.version}") }
+ end
+ end
+
+ def self.with_directory(directory)
+ saved = Dir.getwd()
+ Dir.chdir(directory)
+ yield
+ ensure
+ Dir.chdir(saved)
+ end
+
+ class GemTooManyInstallError < RuntimeError
+ attr_reader :artifacts
+ def initialize(arts)
+ @artifacts = arts
+ end
+ end
+
+end
</ins></span></pre>
</div>
</div>
</body>
</html>