class Mvnizer::Command::SearchArtefact

Constants

MAVEN_REPO_SEARCH_URL

Attributes

out[W]

Public Instance Methods

out() click to toggle source
# File lib/mvnizer/commands/search_artefact.rb, line 10
def out
  @out ||= STDOUT
end
run(options) click to toggle source
# 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