Created
November 8, 2017 05:33
-
-
Save simonz/b4a29bbb4e5f91ca4a8896c0041e83ae to your computer and use it in GitHub Desktop.
This file contains 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
require 'mechanize' | |
@agent = Mechanize.new | |
=begin | |
TODO | |
- better matching library | |
- read variables | |
=end | |
@props = {} | |
def prepare | |
dir = File.expand_path(File.dirname(__FILE__)) | |
File.readlines(File.join(dir, '..', 'gradle.properties')).select do |l| | |
l.start_with?('#') == false | |
end.map do |l| | |
key, value = l.split('=').map(&:strip) | |
@props[key] = value | |
end | |
end | |
def run(app) | |
dir = File.expand_path(File.dirname(__FILE__)) | |
File.readlines(File.join(dir, '..', app, 'build.gradle')).each do |l| | |
if l =~ /classpath/ || l =~ /^\s*(debug|minfied|test|androidTest)?(compile|implementation|annotationProcessor|compileOnly)\b/i | |
lib = parse(l) | |
check(lib) unless lib.nil? | |
end | |
end | |
end | |
def parse(line) | |
m = line.match(/('|")(.*):(.*):(.*)\1/) | |
if m | |
{ group: m[2], artifact: m[3], version: variable(m[4]) } | |
else | |
m = line.match(/group:\s*('|")([^'"]+)\1,\s+name:\s*('|")([^'"]+)\3,\s+version:\s*(.*)/) | |
if m | |
{ group: m[2], artifact: m[4], version: variable(m[5]) } | |
else | |
nil | |
end | |
end | |
end | |
def variable(v) | |
v = v.gsub(/'|"|\$|{|}/, '') | |
if @props.has_key?(v) | |
@props[v] | |
else | |
v | |
end | |
end | |
def check(lib) | |
repos = [ | |
'https://maven.google.com', | |
'http://repo1.maven.org/maven2', | |
'http://jcenter.bintray.com', | |
'https://jitpack.io', | |
'https://maven.fabric.io/public', | |
'http://devrepo.kakao.com:8088/nexus/content/repositories/kakaodev-releases' | |
] | |
found = repos.find do |repo| | |
begin | |
url = get_metadata(lib, repo) | |
page = @agent.get(url) | |
page.search('metadata') | |
true | |
rescue Exception => e | |
false | |
end | |
end | |
if found | |
url = get_metadata(lib, found) | |
page = @agent.get(url) | |
last = page.search('metadata > versioning > versions > version').select {|n| n.text =~ /^[\d.]+$/ }.last.text | |
versions = page.search('metadata > versioning > versions > version') | |
if lib[:version] == last | |
# puts "UP-TO-DATE: #{lib}" | |
else | |
puts "New version: #{last} - #{lib}, (#{url})" | |
end | |
else | |
puts "Cannot find: #{lib}" | |
end | |
end | |
def get_metadata(lib, repo) | |
path = "#{lib[:group]}/#{lib[:artifact]}".gsub(/\./, '/') | |
url = "#{repo}/#{path}/maven-metadata.xml" | |
end | |
prepare | |
run('app') | |
# 기타 사용하는 모듈들 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment