Class: Mvnizer::Command::SearchArtefact

Inherits:
Object
  • Object
show all
Includes:
HTTParty
Defined in:
lib/mvnizer/commands/search_artefact.rb

Constant Summary collapse

MAVEN_REPO_SEARCH_URL =
"http://search.maven.org/solrsearch/select?q=:q&rows=:limit&wt=json"

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#outObject



10
11
12
# File 'lib/mvnizer/commands/search_artefact.rb', line 10

def out
  @out ||= STDOUT
end

Instance Method Details

#run(options) ⇒ Object



14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/mvnizer/commands/search_artefact.rb', line 14

def run(options)
  url = MAVEN_REPO_SEARCH_URL.dup
  url[":q"] = options[:name]
  url[":limit"] = "5"

  response = self.class.get(url)
  if response
    if response.code != 200
      out.puts "Error during search: #{response.code}"
      exit(1)
    end

    if response["response"]["numFound"].to_i > 0
      hits = response["response"]["docs"].each do |a|
        out.puts "  #{a['g']}:#{a['a']}:#{a['latestVersion']}:#{a['p']}"
      end
    else
      out.puts "  No result found."
    end
  end

  # TODO:
  # Error handling,
  # Do something for "bundle" packaging (e.g. for log4j)
end