Module Raven::Command
In: lib/raven.rb

Methods

parse_proxy   parse_url   run  

Included Modules

WEBrick

Public Class methods

[Source]

     # File lib/raven.rb, line 130
130:     def self.parse_proxy(purl)
131:       if (purl.length > 0)
132:         match = purl.match('http://(.*):(.*)@([^/]*):([0-9]*)')
133:         match = match.to_a
134:         match.shift
135:         puts "Using proxy #{match[2]} and port #{match[3]}"
136:         [match[2], match[3].length == 0 ? 80 : Integer(match[3]), match[0], match[1]]
137:       else 
138:         nil
139:       end
140:     end

[Source]

     # File lib/raven.rb, line 124
124:     def self.parse_url(url)
125:       parsed = /http:\/\/([^\/:]*):?([^\/]*)(\/?.*)/.match(url).to_a
126:       parsed.shift
127:       parsed
128:     end

[Source]

     # File lib/raven.rb, line 30
 30:     def self.run(args)
 31:       opts = OptionParser.new
 32:       opts.banner = "Usage: raven [options] (import | repository * | server | install *)"
 33:       repo_url, proxy_url, index_url, all, groupId, allver = '', '', '', false, nil, false
 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 }
 36:       opts.on('-i=ARG', '--index index_url', '[install] URL of a directory containing repository indices.') { |val| index_url = val }
 37:       opts.on('-p=ARG', '--project group_id', '[install] Install artifacts in the provided project.') { |val| groupId = val }
 38:       opts.on('-a', '--all', '[install] Install all selected artifacts.') { |val| all = true }
 39:       opts.on('-v', '--allversions', '[install] Select all versions, not only the latest.') { |val| allver = true }
 40:       
 41:       begin
 42:         rest = opts.parse(*args)
 43:       rescue ArgumentError
 44:         puts 'Wrong option.'
 45:       end
 46:       
 47:       ARGV.pop while ARGV.length > 0
 48:       
 49:       case rest[0]
 50:       when 'import'
 51:         Raven::MavenLocalRepoImport.run() 
 52:       when 'repository'
 53:         if (repo_url.length > 0)
 54:           puts 'repodef'
 55:           match = repo_url.match('http://([^/]*)(/.*)')
 56:           server = match[1]
 57:           rel_url = match[2]
 58:           rel_url = rel_url + '/' if rel_url[-1..-1] != '/'
 59:         else
 60:           # Use the default maven2 repository.
 61:           # Info on maven2 mirrors can be found here:
 62:           #   http://maven.apache.org/guides/mini/guide-mirror-settings.html
 63:           server = 'repo1.maven.org'
 64:           rel_url = '/maven2/'
 65:         end
 66:         puts "Connecting to Maven2 repository at http://#{server}#{rel_url}."
 67:         builder = Raven::GemRepoBuilder.new(server, 80, rel_url, Raven::Command.parse_proxy(proxy_url))
 68:         if (rest.size > 1)
 69:           rest.shift
 70:           puts "Packages: #{rest.join(' ')}"
 71:           builder.group_filters = rest
 72:         end
 73:         builder.build
 74:         main_index(ARGV)
 75:       when 'server'
 76:         require 'webrick'
 77:         include WEBrick
 78:         s = HTTPServer.new(
 79:              :Port         => 2233,
 80:              :DocumentRoot => Dir.pwd )
 81:         trap("INT") { s.shutdown }
 82:         s.start
 83:       when 'install'
 84:         params = ['raven.rubyforge.org', 80, '/indices/']
 85:         if (index_url.length > 0)
 86:           params = Raven::Command.parse_url(index_url)
 87:           params[2] = '/' if params[2].empty?
 88:         end
 89:         params << Raven::Command.parse_proxy(proxy_url)
 90:         installer = Raven::GemSearchInstaller.new(*params)
 91:         # Refreshes local gem indices if needed
 92:         installer.get_indices
 93:         
 94:         rest.shift
 95:         rest << '' if (rest.empty? && groupId)
 96:         rest.each do |artifact| 
 97:           av = artifact.match(/([^:]*):?(.*)/).to_a
 98:           # Trock to see if we've been passed a version number or an artifact
 99:           begin
100:             aint = Integer(av[1][0..0])
101:             if aint != 0
102:               av[2] = av[1]
103:               av[1] = ''
104:             end
105:           rescue
106:           end
107:           begin
108:             installer.install(av[1].length > 0 ? av[1] : nil, 
109:                 groupId, av[2].length > 0 ? av[2] : nil, all, allver)
110:           rescue GemTooManyInstallError => toomany
111:             puts "Couldn't install a gem from name #{av[1]||groupId}, more than one potential"
112:             puts "gem was found for this name. If this is intentional and you want to"
113:             puts "install all these gems please run again with the --all option."
114:             toomany.artifacts.each { |a| puts "   #{a.to_s}"}
115:           end
116:         end
117:       when 'build_index'
118:         RepoIndexBuilder.new('m2_central', 'repo1.maven.org', '/maven2/', Raven::Command.parse_proxy(proxy_url)).build_idx
119:       else
120:         puts opts.to_s
121:       end
122:     end

[Validate]