<!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 &quot;License&quot;);
-#  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 &quot;AS IS&quot; 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 &amp;&amp; art.name == @name &amp;&amp; art.version == @version
-    end
-    
-    def hash
-      @group.hash ^ (@name.hash &lt;&lt; 1) ^ (@version.hash &lt;&lt; 2)
-    end
-    
-    def to_s
-      &quot;#{name} v#{version} (project #{group})&quot;
-    end
-  end
-  
-  # Enumerates on a Maven repository by scraping HTML. Yields on every
-  # artifact found in there.
-  class Maven2Repository
-    EXCLUDE = [&quot;sha1&quot;, &quot;md5&quot;, &quot;pom&quot;]
-    
-    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 = /&lt;img src=&quot;\/icons\/folder.gif&quot; alt=&quot;\[DIR\]&quot;&gt; &lt;a href=&quot;[^\/]*\/&quot;&gt;/
-      file_regexp = /&lt;img src=&quot;\/icons\/unknown.gif&quot; alt=&quot;\[   \]&quot;&gt; &lt;a href=&quot;[^&quot;]*&quot;&gt;/
-      read_page(http, @url, folder_regexp) do |url1, group|
-        if @group_filters.nil? || @group_filters.include?(group)
-          puts &quot;#{group}&quot;
-          read_page(http, url1 + group + '/', folder_regexp) do |url2, name|
-            puts &quot;  #{name}&quot;
-            read_page(http, url2 + name + '/', folder_regexp) do |url3, version|
-              puts &quot;    #{version}&quot;
-              art_path = &quot;#{group}/#{name}/#{version}/#{name}-#{version}.jar&quot;
-              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 = /&lt;img src=&quot;\/icons\/folder.gif&quot; alt=&quot;\[DIR\]&quot;&gt; &lt;a href=&quot;[^\/]*\/&quot;&gt;/
-      file_regexp = /&lt;img src=&quot;\/icons\/unknown.gif&quot; alt=&quot;\[   \]&quot;&gt; &lt;a href=&quot;[^&quot;]*&quot;&gt;/
-
-      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 &lt;&lt; &quot;#{url}#{line[51..(line.length - 4)]}/&quot; }
-        else
-          url_arr = url.split('/')
-          puts &quot;arl art #{url_arr}&quot;
-          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 = &quot;#{group.gsub('.', '/')}/#{name}/#{version}/#{name}-#{version}.jar&quot;
-            artifact = Raven::Artifact.new(group, name, version, art_path)
-            puts &quot;Found artifact #{artifact} in group #{group}&quot;
-            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 &quot;Error connecting to repository: #{response.message}&quot;
-        if response.is_a?(Net::HTTPRedirection) &amp;&amp; response[&quot;location&quot;]
-          puts &quot;Location: #{response['location']}&quot;
-        else
-          puts &quot;------ RESPONSE CODE -----------------------------&quot;
-          puts &quot;Response code: #{response.code}&quot;
-          puts &quot;------ HEADERS -----------------------------------&quot;
-          response.each_header do |key, value|
-            puts &quot;#{key}: #{value}&quot;
-          end
-          puts &quot;------ CONTENT -----------------------------------&quot;
-          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 &gt; 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 &lt;&lt; File.join(path, entry)
-          end
-        end
-      end
-    end
-
-  end
-
-  
-  class M2LocalRepository &lt; 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, &quot;*.pom&quot;) do |pom_path|
-        jar_path = pom_path.sub(&quot;\.pom$&quot;, &quot;.jar&quot;);
-
-        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=&gt; e
-          Raven.log_error(&quot;Failed to construct POM: #{e}&quot;)
-        end
-      end
-    end
-
-  end
-  
-  class M1LocalRepository &lt; 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 = &quot;#{group}/jars/#{name}-#{version}.jar&quot;
-              artifact = Raven::Artifact.new(group, name, version, art_path)
-              yield(artifact)
-            rescue NoMethodError
-              # Will happen if one of the regular expressions return nil
-              puts &quot;File #{filename} doesn't seem to be correctly named, ignoring.&quot;
-            end
-          end
-        end
-      end
-    end
-
-  end
-  
-  module MavenLocalRepoImport
-
-    def self.run
-      
-      Raven.log_debug(&quot;Trying to find out where the local repository is&quot;)
-
-      repo = self.select_repo([MAVEN_HOME + '/repository',
-                               USER_HOME + '/.maven/repository',
-                               USER_HOME + '/.m2/repository'])
-      if repo
-        print &quot;Found a Maven repository in #{repo.dir}, do you want to use this one? (y/n)&quot;
-        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 &lt;&lt; RAVEN_HOME if defined?(GEMS_IN_HOME)
-          Gem::Installer.new(&quot;#{artifact.group}-#{artifact.name}-#{artifact.version}-java.gem&quot;).install(*params)
-          # Cleaning up for next iteration
-          FileUtils.rm(Dir.glob('ext/*'))
-          FileUtils.rm(Dir.glob('*.gem'))
-        else
-          puts &quot;File #{artifact.path} couldn't be found, ignoring.&quot;
-        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 &lt;&lt; &quot;Repo at #{path} is M1&quot;
-        return :maven1
-      elsif M2LocalRepository.valid(path)
-        STDOUT &lt;&lt; &quot;Repo at #{path} is M2&quot;
-        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 &quot;Unable to determine Maven repository type.&quot;
-      end
-    end
-
-    def self.select_interactively()
-      puts &quot;Please provide the path to your maven repository to convert.&quot;
-      puts &quot;Path doesn't exist! Try again...&quot; 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 &gt; 3 ? true : false
-      @ver_struct = elmts.collect do |elmt|
-        val = ''
-        begin
-          val = Integer(elmt)
-        rescue ArgumentError
-          val = elmt
-        end
-        val
-      end
-    end
-    
-    def &lt;=&gt;(ver)
-      false if !(Version === ver)
-      return -1 if @timestamp &amp;&amp; !ver.timestamp
-      return 1 if !@timestamp &amp;&amp; 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 &gt; you.size ? you : @me
-        biggy = @me.size &gt; 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 &lt;=&gt; could produce nil
-      (0..@me.size).each do |m|
-        if (m &lt; you.size &amp;&amp; @me[m].class != you[m].class)
-          @me[m] = 0 if String === @me[m]
-          you[m] = 0 if String === you[m]
-        end
-      end
-      @me &lt;=&gt; you
-    end
-    
-    def to_s
-      puts &quot;v#{@version}, ts #{timestamp}, #{ @ver_struct.collect{ |v| v.class }.join('/') }&quot;
-    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 = &quot;Raven wrapped library #{artifact.name} from project #{artifact.group}.&quot;
-      s.name = &quot;#{artifact.group}-#{artifact.name}&quot;
-      s.version = artifact.version
-      s.requirements &lt;&lt; 'none'
-      s.require_path = 'ext'
-      s.autorequire = 'rake'
-      s.files = Dir.glob(&quot;{ext}/**/*&quot;)
-      dependencies.each { |dep| s.add_dependency(&quot;#{dep.group}-#{dep.name}&quot;, &quot;=#{dep.version}&quot;) }
-    end
-  end
-  
-  def self.with_directory(directory)
-    saved = Dir.getwd()
-    Dir.chdir(directory)
-    yield
-  ensure
-    Dir.chdir(saved)
-  end
-
-  class GemTooManyInstallError &lt; 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 &quot;License&quot;);
+#  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 &quot;AS IS&quot; 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 &amp;&amp; art.name == @name &amp;&amp; art.version == @version
+    end
+    
+    def hash
+      @group.hash ^ (@name.hash &lt;&lt; 1) ^ (@version.hash &lt;&lt; 2)
+    end
+    
+    def to_s
+      &quot;#{name} v#{version} (project #{group})&quot;
+    end
+  end
+  
+  # Enumerates on a Maven repository by scraping HTML. Yields on every
+  # artifact found in there.
+  class Maven2Repository
+    EXCLUDE = [&quot;sha1&quot;, &quot;md5&quot;, &quot;pom&quot;]
+    
+    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 = /&lt;img src=&quot;\/icons\/folder.gif&quot; alt=&quot;\[DIR\]&quot;&gt; &lt;a href=&quot;[^\/]*\/&quot;&gt;/
+      file_regexp = /&lt;img src=&quot;\/icons\/unknown.gif&quot; alt=&quot;\[   \]&quot;&gt; &lt;a href=&quot;[^&quot;]*&quot;&gt;/
+      read_page(http, @url, folder_regexp) do |url1, group|
+        if @group_filters.nil? || @group_filters.include?(group)
+          puts &quot;#{group}&quot;
+          read_page(http, url1 + group + '/', folder_regexp) do |url2, name|
+            puts &quot;  #{name}&quot;
+            read_page(http, url2 + name + '/', folder_regexp) do |url3, version|
+              puts &quot;    #{version}&quot;
+              art_path = &quot;#{group}/#{name}/#{version}/#{name}-#{version}.jar&quot;
+              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 = /&lt;img src=&quot;\/icons\/folder.gif&quot; alt=&quot;\[DIR\]&quot;&gt; &lt;a href=&quot;[^\/]*\/&quot;&gt;/
+      file_regexp = /&lt;img src=&quot;\/icons\/unknown.gif&quot; alt=&quot;\[   \]&quot;&gt; &lt;a href=&quot;[^&quot;]*&quot;&gt;/
+
+      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 &lt;&lt; &quot;#{url}#{line[51..(line.length - 4)]}/&quot; }
+        else
+          url_arr = url.split('/')
+          puts &quot;arl art #{url_arr}&quot;
+          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 = &quot;#{group.gsub('.', '/')}/#{name}/#{version}/#{name}-#{version}.jar&quot;
+            artifact = Raven::Artifact.new(group, name, version, art_path)
+            puts &quot;Found artifact #{artifact} in group #{group}&quot;
+            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 &quot;Error connecting to repository: #{response.message}&quot;
+        if response.is_a?(Net::HTTPRedirection) &amp;&amp; response[&quot;location&quot;]
+          puts &quot;Location: #{response['location']}&quot;
+        else
+          puts &quot;------ RESPONSE CODE -----------------------------&quot;
+          puts &quot;Response code: #{response.code}&quot;
+          puts &quot;------ HEADERS -----------------------------------&quot;
+          response.each_header do |key, value|
+            puts &quot;#{key}: #{value}&quot;
+          end
+          puts &quot;------ CONTENT -----------------------------------&quot;
+          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 &gt; 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 &lt;&lt; File.join(path, entry)
+          end
+        end
+      end
+    end
+
+  end
+
+  
+  class M2LocalRepository &lt; 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, &quot;*.pom&quot;) do |pom_path|
+        jar_path = pom_path.sub(&quot;\.pom$&quot;, &quot;.jar&quot;);
+
+        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=&gt; e
+          Raven.log_error(&quot;Failed to construct POM: #{e}&quot;)
+        end
+      end
+    end
+
+  end
+  
+  class M1LocalRepository &lt; 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 = &quot;#{group}/jars/#{name}-#{version}.jar&quot;
+              artifact = Raven::Artifact.new(group, name, version, art_path)
+              yield(artifact)
+            rescue NoMethodError
+              # Will happen if one of the regular expressions return nil
+              puts &quot;File #{filename} doesn't seem to be correctly named, ignoring.&quot;
+            end
+          end
+        end
+      end
+    end
+
+  end
+  
+  module MavenLocalRepoImport
+
+    def self.run
+      
+      Raven.log_debug(&quot;Trying to find out where the local repository is&quot;)
+
+      repo = self.select_repo([MAVEN_HOME + '/repository',
+                               USER_HOME + '/.maven/repository',
+                               USER_HOME + '/.m2/repository'])
+      if repo
+        print &quot;Found a Maven repository in #{repo.dir}, do you want to use this one? (y/n)&quot;
+        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 &lt;&lt; RAVEN_HOME if defined?(GEMS_IN_HOME)
+          Gem::Installer.new(&quot;#{artifact.group}-#{artifact.name}-#{artifact.version}-java.gem&quot;).install(*params)
+          # Cleaning up for next iteration
+          FileUtils.rm(Dir.glob('ext/*'))
+          FileUtils.rm(Dir.glob('*.gem'))
+        else
+          puts &quot;File #{artifact.path} couldn't be found, ignoring.&quot;
+        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 &lt;&lt; &quot;Repo at #{path} is M1&quot;
+        return :maven1
+      elsif M2LocalRepository.valid(path)
+        STDOUT &lt;&lt; &quot;Repo at #{path} is M2&quot;
+        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 &quot;Unable to determine Maven repository type.&quot;
+      end
+    end
+
+    def self.select_interactively()
+      puts &quot;Please provide the path to your maven repository to convert.&quot;
+      puts &quot;Path doesn't exist! Try again...&quot; 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 &gt; 3 ? true : false
+      @ver_struct = elmts.collect do |elmt|
+        val = ''
+        begin
+          val = Integer(elmt)
+        rescue ArgumentError
+          val = elmt
+        end
+        val
+      end
+    end
+    
+    def &lt;=&gt;(ver)
+      false if !(Version === ver)
+      return -1 if @timestamp &amp;&amp; !ver.timestamp
+      return 1 if !@timestamp &amp;&amp; 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 &gt; you.size ? you : @me
+        biggy = @me.size &gt; 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 &lt;=&gt; could produce nil
+      (0..@me.size).each do |m|
+        if (m &lt; you.size &amp;&amp; @me[m].class != you[m].class)
+          @me[m] = 0 if String === @me[m]
+          you[m] = 0 if String === you[m]
+        end
+      end
+      @me &lt;=&gt; you
+    end
+    
+    def to_s
+      puts &quot;v#{@version}, ts #{timestamp}, #{ @ver_struct.collect{ |v| v.class }.join('/') }&quot;
+    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 = &quot;Raven wrapped library #{artifact.name} from project #{artifact.group}.&quot;
+      s.name = &quot;#{artifact.group}-#{artifact.name}&quot;
+      s.version = artifact.version
+      s.requirements &lt;&lt; 'none'
+      s.require_path = 'ext'
+      s.autorequire = 'rake'
+      s.files = Dir.glob(&quot;{ext}/**/*&quot;)
+      dependencies.each { |dep| s.add_dependency(&quot;#{dep.group}-#{dep.name}&quot;, &quot;=#{dep.version}&quot;) }
+    end
+  end
+  
+  def self.with_directory(directory)
+    saved = Dir.getwd()
+    Dir.chdir(directory)
+    yield
+  ensure
+    Dir.chdir(saved)
+  end
+
+  class GemTooManyInstallError &lt; RuntimeError
+    attr_reader :artifacts    
+    def initialize(arts)
+      @artifacts = arts
+    end
+  end
+    
+end
</ins></span></pre>
</div>
</div>

</body>
</html>