Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
ScalaのメジャーバージョンごとのArtefactのバージョンを調べるスクリプトです。
#!/usr/bin/env ruby
require 'uri'
require 'open-uri'
require 'json'
require 'pp'
def query(params)
base_url = "http://search.maven.org/solrsearch/select?"
params["start"] = 0
is_finished = false
docs = []
begin
url = base_url + URI.encode_www_form(params)
open( url ) do |res|
result = JSON.parse res.read
if result["response"]["numFound"] == 0 then
return [] # returns empty array
end
result["response"]["docs"].each do |doc|
docs.push doc
end
if docs.length < result["response"]["numFound"] then
params["start"] = docs.length
else
is_finished = true
end
end
end while is_finished == false
return docs
end
groupID = ARGV[0]
artifactID = ARGV[1]
if (ARGV.length < 2)
abort("GroupID and ArtifactID are not specified.")
end
invalid_pkg_name = Regexp.new("[^a-zA-Z0-9._-]")
if (groupID.match(invalid_pkg_name) or artifactID.match(invalid_pkg_name))
abort("Illegal characters are included.")
end
if (artifactID.match(/_2\.\d{2}$/))
abort("Version suffix is attached")
end
a_params = {
:q => %Q{g:"#{groupID}"},
:rows => 100,
:wt => 'json'
}
artifacts = query(a_params).select do |artifact|
artifact["a"].match(/^#{artifactID}_2\.\d{2}$/)
end
vers = {}
artifacts.each do |artifact|
v_params = {
:q => %Q{g:"#{groupID}" AND a:"#{artifact['a']}"},
:core => "gav",
:rows => 100,
:wt => 'json'
}
vers.store(artifact['a'], query(v_params).map { |result| result["v"] } )
end
pp vers
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment