Created
July 1, 2017 01:52
-
-
Save magnolia-k/838aa97123281c6916226ec8fb735a92 to your computer and use it in GitHub Desktop.
ScalaのメジャーバージョンごとのArtefactのバージョンを調べるスクリプトです。
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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