Module Raven::GemInstaller
In: lib/raven/deps_tasks.rb

Calls Gem installer to install a Gem (very predictible behaviour). Well, but if the Gem is already there, it won‘t be installed. This guy‘s a smart one.

Methods

Public Class methods

Possibly installs a Gem… or not. If it‘s already present installation will just be skipped. The path to the gem root is always returned though. The provided gem name is first looked up with a query in the repositories to support partial names (i.e only artifactId).

[Source]

     # File lib/raven/deps_tasks.rb, line 117
117:     def self.install_or_not(gemname, version='*')
118:       # TODO Add support for regular expressions for gem name, allows multiple 

119:       # selected gems

120:       hems = resolve(gemname, version)
121:       gem_spec = hems[0]
122:       # TODO Handle Gem dependencies

123:       unless hems[1]
124:         installer = Gem::RemoteInstaller.new
125:         params = [gem_spec.name, gem_spec.version.to_s, false]
126:         params << RAVEN_HOME if defined?(GEMS_IN_HOME)
127:         gem_spec = installer.install(*params)[0]
128:       end
129:       gem_spec.full_gem_path
130:     end

Resolves a Gem partial name (like only the artifactId) to a full name and eventually checks its versions. Returns an array with the found Gem in the first position and a boolean indicating whether the array has been found locally or not in second position.

[Source]

     # File lib/raven/deps_tasks.rb, line 136
136:     def self.resolve(gemname, version)
137:       # Search local occurences first, it's faster. Moreover we'll only

138:       # return local versions, avoiding a constant download of latest versions

139:       # when nothing specific is provided.

140:       gems = Gem::cache.search(/.*#{gemname}$/)
141:       local = select_gem(gemname, version, gems, true)
142:       puts "Using local gem #{local[0].name} (#{local[0].version}) to satisfy dependency #{gemname}" if RakeFileUtils.verbose_flag && local
143:       return local if local
144:       begin
145:         if (Gem::RubyGemsPackageVersion != "0.9.0")
146:           gems = Gem::SourceInfoCache.search(/.*#{gemname}$/)
147:         else
148:           gems = Gem::RemoteInstaller.new().search(/.*#{gemname}$/)
149:         end
150:       rescue Exception => rt
151:         puts rt.to_s
152:         puts rt.backtrace.join("\n")
153:         puts "The gem #{gemname} from your dependencies couldn't be found locally"
154:         puts "and the connection to a Gem repository failed."
155:         exit
156:       end 
157:       remote = select_gem(gemname, version, gems.flatten, false)
158:       puts "Downloading remote gem #{remote[0].name} (#{remote[0].version}) to satisfy dependency #{gemname}" if RakeFileUtils.verbose_flag && remote
159:       return remote if remote
160:       
161:       # Nothing found: Houston, we have a problem

162:       raise(GemNotFoundException, "Couldn't find any Gem from name #{gemname} and version #{version}") unless remote
163:     end

[Validate]