mvn-get 0.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: bf08376d58d584a6ef6551ffa2da90f334666615
4
+ data.tar.gz: f09af3012fc3dd9226f44a1e549d0279ce9c323e
5
+ SHA512:
6
+ metadata.gz: dc06f40b4f80de28326829bf5b0096059b67ef974010f42f316b804b7eff81da23b3a551400fc32d797b847fdf8a6d2c05370d165a95142193c7c540cbe7efea
7
+ data.tar.gz: 40f4fc1e067f3964fbe2d2f4bd614b643b681783f244f182c9211a382bcc898bc8983b4b63d1a4a62c2039d7831ef0315b2c754d698d83316da221c2adad0225
@@ -0,0 +1,22 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
18
+ *.bundle
19
+ *.so
20
+ *.o
21
+ *.a
22
+ mkmf.log
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in mvn-get.gemspec
4
+ gemspec
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2015 HondaDai
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,19 @@
1
+ # mvn-get
2
+
3
+ mvn-get is a java toolkit for quickly checking and setting up library dependencies.
4
+
5
+ ## Installation
6
+
7
+ $ gem install mvn-get
8
+
9
+ ## Usage
10
+
11
+ TODO: Write usage instructions here
12
+
13
+ ## Contributing
14
+
15
+ 1. Fork it ( https://github.com/HondaDai/mvn-get/fork )
16
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
17
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
18
+ 4. Push to the branch (`git push origin my-new-feature`)
19
+ 5. Create a new Pull Request
@@ -0,0 +1,2 @@
1
+ require "bundler/gem_tasks"
2
+
@@ -0,0 +1,6 @@
1
+ #!/usr/bin/env ruby
2
+ # -*- mode: ruby -*-
3
+
4
+ require File.join(File.expand_path(File.dirname(__FILE__)), "../lib/mvn-get/cli.rb")
5
+
6
+ CommandLine.start
@@ -0,0 +1,3 @@
1
+
2
+
3
+ require File.join(File.expand_path(File.dirname(__FILE__)), "./mvn-get/mvn-get.rb")
@@ -0,0 +1,66 @@
1
+
2
+
3
+ require File.join(File.expand_path(File.dirname(__FILE__)), "./mvn-get.rb")
4
+
5
+ require 'thor'
6
+
7
+ def select_one_library(lib_name, show_notice)
8
+ search_result = MavenCentral.search(lib_name)
9
+ if search_result["candidates"].map{|x| x.gsub(/(.*):(.*):(.*)/, '\1:\1') }.uniq.size == 1 and search_result["suggestions"].size == 0
10
+ return MavenCentralRepo.new(search_result["candidates"][0])
11
+ elsif show_notice
12
+ if search_result["candidates"].size > 0
13
+ puts "Please specify a library, for example: "
14
+ search_result["candidates"].each {|x| puts "\t#{x}"}
15
+ else
16
+ puts "No available library call #{lib_name}"
17
+ end
18
+
19
+ if search_result["suggestions"].size > 0
20
+ print "\nOr... " if search_result["candidates"].size > 0
21
+ puts "Did you mean:"
22
+ search_result["suggestions"].each {|x| puts "\t#{x}"}
23
+ end
24
+ end
25
+ nil
26
+ end
27
+
28
+ def check_dependencies(lib_name)
29
+ repo = select_one_library(lib_name, true)
30
+ if repo != nil
31
+ puts "Select library '#{repo.id}'"
32
+ puts "Check dependencies..."
33
+ deps = repo.recursive_dependencies
34
+ if deps.empty?
35
+ puts "Doesn't have any dependencies"
36
+ else
37
+ puts "#{deps.size} Dependencies:"
38
+ deps.each{|x| puts "\t#{x.id}"}
39
+ end
40
+ end
41
+ repo
42
+ end
43
+
44
+
45
+ class CommandLine < Thor
46
+
47
+ desc "deps LIBRARY_NAME", "check dependencies of LIBRARY_NAME"
48
+ def deps(lib_name)
49
+ repo = check_dependencies(lib_name)
50
+ end
51
+
52
+ desc "install LIBRARY_NAME", "install all dependencies of LIBRARY_NAME"
53
+ def install(lib_name)
54
+ repo = check_dependencies(ARGV[1])
55
+ if repo != nil
56
+ puts "Start downloading..."
57
+ deps = [repo, repo.recursive_dependencies].flatten
58
+ deps.zip(1..deps.size).each{|x, i|
59
+ puts "\t[#{i}/#{deps.size}] #{x.id}"
60
+ x.download
61
+ }
62
+ end
63
+ end
64
+ end
65
+
66
+ # CommandLine.start(ARGV)
@@ -0,0 +1,206 @@
1
+
2
+
3
+ require 'active_support/core_ext/hash'
4
+ require 'rest-client'
5
+ require 'json'
6
+
7
+
8
+ MAVEN_CENTRAL_HOST = "http://search.maven.org"
9
+ MAVEN_CENTRAL_REMOTE_CONTENT = "#{MAVEN_CENTRAL_HOST}/remotecontent"
10
+ MAVEN_CENTRAL_SEARCH = "#{MAVEN_CENTRAL_HOST}/solrsearch/select"
11
+
12
+ module MavenCentral
13
+ module_function
14
+
15
+ def version
16
+ "0.0.2"
17
+ end
18
+
19
+ def extract_url_from_dict(d, filetype="pom")
20
+ "#{MAVEN_CENTRAL_REMOTE_CONTENT}?filepath=#{d["groupId"].gsub(".", "/")}/#{d["artifactId"]}/#{d["version"]}/#{d["artifactId"]}-#{d["version"]}.#{filetype}"
21
+ end
22
+
23
+ def extract_url_from_id(id, filetype="pom")
24
+ MavenCentral.extract_url_from_dict(id2dict(id), filetype)
25
+ end
26
+
27
+ def id2dict(id)
28
+ if (res = id.scan(/(.*):(.*)/)[0]) != nil
29
+ if (res1 = id.scan(/(.*):(.*):(.*)/)[0]) != nil
30
+ res = res1
31
+ end
32
+ else
33
+ return nil
34
+ end
35
+
36
+ d = {}
37
+ d["groupId"], d["artifactId"], d["version"] = res
38
+ d
39
+ end
40
+
41
+ def dict2id(d)
42
+ "#{d["groupId"]}:#{d["artifactId"]}:#{d["version"]}"
43
+ end
44
+
45
+ def search(keyword)
46
+ d = MavenCentral.id2dict(keyword)
47
+ url = if d != nil
48
+ "#{MAVEN_CENTRAL_SEARCH}?q=g:%22#{d["groupId"]}%22%20AND%20a:%22#{d["artifactId"]}%22%20AND%20v:%22#{d["version"]}%22&wt=json"
49
+ else
50
+ "#{MAVEN_CENTRAL_SEARCH}?q=#{keyword}&wt=json"
51
+ end
52
+
53
+ # puts url
54
+
55
+ result = {}
56
+ body = JSON.parse(MavenCentral.request(url))
57
+ result["candidates"] = body["response"]["docs"].map{|x| x["id"] }
58
+ result["suggestions"] = if body["spellcheck"] and body["spellcheck"]["suggestions"] and body["spellcheck"]["suggestions"][1] then body["spellcheck"]["suggestions"][1]["suggestion"] else [] end
59
+ result
60
+ end
61
+
62
+ def fetch_lastest_version(groupId, artifactId)
63
+ id2dict(search("#{groupId}:#{artifactId}")["candidates"].sort.last)["version"]
64
+ end
65
+
66
+ def request(url)
67
+ RestClient.get(url)
68
+ end
69
+
70
+ end
71
+
72
+ class MavenCentralRepo
73
+
74
+ attr_reader :id, :pom, :groupId, :artifactId, :version
75
+
76
+ def version
77
+ MavenCentral.version
78
+ end
79
+
80
+ def initialize(id)
81
+
82
+ @id = id
83
+ d = MavenCentral.id2dict(@id)
84
+ raise "not a correct id.\n please use 'groupId:artifactId' or 'groupId:artifactId:version'" if d.nil?
85
+
86
+ # use lastest version by default
87
+ if d["version"] == nil || d["version"].strip == ""
88
+ d["version"] = MavenCentral.fetch_lastest_version(d["groupId"], d["artifactId"])
89
+ @id = MavenCentral.dict2id(d)
90
+ end
91
+
92
+ @groupId, @artifactId, @version = d["groupId"], d["artifactId"], d["version"]
93
+
94
+ pom_url = MavenCentral.extract_url_from_dict(d)
95
+ # puts pom_url
96
+
97
+ body = MavenCentral.request(pom_url)
98
+ @pom = Hash.from_xml( body )
99
+ end
100
+
101
+ # def dependencies_url
102
+ # dependencies.map{|x| MavenCentral.extract_url_from_id(x, "pom") }
103
+ # end
104
+
105
+ def dependencies(ignore_test_lib = true)
106
+ return [] if @pom["project"]["dependencies"].nil? or
107
+ (@pom["project"]["dependencies"].class == String and @pom["project"]["dependencies"].strip == "")
108
+ [@pom["project"]["dependencies"]["dependency"]].flatten.map{|x|
109
+ next if ignore_test_lib and x["scope"] and x["scope"].strip == "test"
110
+ # puts "dep #{@id}\n#{x}"
111
+ if x["version"] =~ /\s*[$]{\s*project[.]version\s*}\s*/
112
+ x["version"] = @version
113
+ end
114
+ "#{x["groupId"]}:#{x["artifactId"]}:#{x["version"]}"
115
+ }.compact.sort!
116
+ end
117
+
118
+ def jar_url
119
+ MavenCentral.extract_url_from_id(@id, "jar")
120
+ end
121
+
122
+ def recursive_dependencies(ignore_test_lib = true, only_select_lastest_version = true)
123
+ return [] if dependencies(ignore_test_lib) == []
124
+ return @_recursive_dependencies[ignore_test_lib][only_select_lastest_version] if @_recursive_dependencies and @_recursive_dependencies[ignore_test_lib] and @_recursive_dependencies[ignore_test_lib][only_select_lastest_version]
125
+
126
+
127
+ res = []
128
+ deps = dependencies(ignore_test_lib)
129
+ while not deps.empty?
130
+ d = deps.shift
131
+ # puts "deps #{d}"
132
+ if not res.map{|x| x.id }.include?(d)
133
+ r = MavenCentralRepo.new(d)
134
+ if not res.include?(r)
135
+ if only_select_lastest_version == false or
136
+ (only_select_lastest_version == true and
137
+ ( not res.any?{|x| r.groupId == x.groupId and r.artifactId == x.artifactId } or
138
+ res.any?{|x| r.groupId == x.groupId and r.artifactId == x.artifactId and r.version < x.version }) # lexicographic order
139
+ )
140
+ deps += r.dependencies
141
+ res << r
142
+ end
143
+ end
144
+ end
145
+ end
146
+
147
+ # if only_select_lastest_version
148
+ # res = res.group_by{|x| "#{x.groupId}:#{x.artifactId}" }.map{|k, v| v.reduce{|s, x| if s.version > x.version then s else x end } }.flatten
149
+ # end
150
+
151
+ res.sort!
152
+ @_recursive_dependencies ||= {}
153
+ @_recursive_dependencies[ignore_test_lib] ||= {}
154
+ @_recursive_dependencies[ignore_test_lib][only_select_lastest_version] = res
155
+ return res
156
+ # dependencies.map{|x|
157
+ # repo = MavenCentralRepo.new(x)
158
+ # puts "--- #{@id} ---"
159
+ # puts repo.dependencies
160
+ # [repo, repo.recursive_dependencies]
161
+ # }.flatten
162
+ end
163
+
164
+ def inspect
165
+ @id
166
+ end
167
+
168
+ def ==(other)
169
+ other.class == MavenCentralRepo and id == other.id
170
+ end
171
+
172
+ def <=>(other)
173
+ id <=> other.id
174
+ end
175
+
176
+ def download(path = ".")
177
+ url = jar_url
178
+ open(File.join(path, url.split("/").last), "w") { |f|
179
+ f.write MavenCentral.request(url)
180
+ }
181
+ end
182
+
183
+ end
184
+
185
+ # id = "org.mockito:mockito-core:2.0.7-beta"
186
+
187
+ # id = "com.mashape.unirest:unirest-java:1.4.5"
188
+ # r = MavenCentralRepo.new(id)
189
+ # r.recursive_dependencies.each {|x| x.download }
190
+ # puts r.dependencies
191
+
192
+ # puts MavenCentral.search("org.technbolts:junit:1.0.1")
193
+
194
+
195
+
196
+ # puts r.recursive_dependencies
197
+ # puts r.dependencies_url
198
+ # puts r.dependencies
199
+
200
+
201
+
202
+ # require 'irb'
203
+ # IRB.start
204
+
205
+
206
+
@@ -0,0 +1,28 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'mvn-get/mvn-get.rb'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "mvn-get"
8
+ spec.version = MavenCentral.version
9
+ spec.authors = ["HondaDai"]
10
+ spec.email = ["hondadai.tw@gmail.com"]
11
+ spec.summary = %q{mvn-get is a java toolkit for quickly checking and setting up library dependencies.}
12
+ spec.description = spec.summary
13
+ spec.homepage = "https://github.com/HondaDai/mvn-get"
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files -z`.split("\x0")
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_dependency "rest-client", '~> 1.6', '>= 1.6.7'
22
+ spec.add_dependency "json", "~> 1.7", '>= 1.7'
23
+ spec.add_dependency "activesupport", '~> 4.2', '>= 4.2.1'
24
+ spec.add_dependency "thor", '~> 0.19.1'
25
+
26
+ spec.add_development_dependency "bundler", "~> 1.6"
27
+ spec.add_development_dependency "rake"
28
+ end
metadata ADDED
@@ -0,0 +1,158 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: mvn-get
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.2
5
+ platform: ruby
6
+ authors:
7
+ - HondaDai
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2015-05-03 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: rest-client
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.6'
20
+ - - ">="
21
+ - !ruby/object:Gem::Version
22
+ version: 1.6.7
23
+ type: :runtime
24
+ prerelease: false
25
+ version_requirements: !ruby/object:Gem::Requirement
26
+ requirements:
27
+ - - "~>"
28
+ - !ruby/object:Gem::Version
29
+ version: '1.6'
30
+ - - ">="
31
+ - !ruby/object:Gem::Version
32
+ version: 1.6.7
33
+ - !ruby/object:Gem::Dependency
34
+ name: json
35
+ requirement: !ruby/object:Gem::Requirement
36
+ requirements:
37
+ - - "~>"
38
+ - !ruby/object:Gem::Version
39
+ version: '1.7'
40
+ - - ">="
41
+ - !ruby/object:Gem::Version
42
+ version: '1.7'
43
+ type: :runtime
44
+ prerelease: false
45
+ version_requirements: !ruby/object:Gem::Requirement
46
+ requirements:
47
+ - - "~>"
48
+ - !ruby/object:Gem::Version
49
+ version: '1.7'
50
+ - - ">="
51
+ - !ruby/object:Gem::Version
52
+ version: '1.7'
53
+ - !ruby/object:Gem::Dependency
54
+ name: activesupport
55
+ requirement: !ruby/object:Gem::Requirement
56
+ requirements:
57
+ - - "~>"
58
+ - !ruby/object:Gem::Version
59
+ version: '4.2'
60
+ - - ">="
61
+ - !ruby/object:Gem::Version
62
+ version: 4.2.1
63
+ type: :runtime
64
+ prerelease: false
65
+ version_requirements: !ruby/object:Gem::Requirement
66
+ requirements:
67
+ - - "~>"
68
+ - !ruby/object:Gem::Version
69
+ version: '4.2'
70
+ - - ">="
71
+ - !ruby/object:Gem::Version
72
+ version: 4.2.1
73
+ - !ruby/object:Gem::Dependency
74
+ name: thor
75
+ requirement: !ruby/object:Gem::Requirement
76
+ requirements:
77
+ - - "~>"
78
+ - !ruby/object:Gem::Version
79
+ version: 0.19.1
80
+ type: :runtime
81
+ prerelease: false
82
+ version_requirements: !ruby/object:Gem::Requirement
83
+ requirements:
84
+ - - "~>"
85
+ - !ruby/object:Gem::Version
86
+ version: 0.19.1
87
+ - !ruby/object:Gem::Dependency
88
+ name: bundler
89
+ requirement: !ruby/object:Gem::Requirement
90
+ requirements:
91
+ - - "~>"
92
+ - !ruby/object:Gem::Version
93
+ version: '1.6'
94
+ type: :development
95
+ prerelease: false
96
+ version_requirements: !ruby/object:Gem::Requirement
97
+ requirements:
98
+ - - "~>"
99
+ - !ruby/object:Gem::Version
100
+ version: '1.6'
101
+ - !ruby/object:Gem::Dependency
102
+ name: rake
103
+ requirement: !ruby/object:Gem::Requirement
104
+ requirements:
105
+ - - ">="
106
+ - !ruby/object:Gem::Version
107
+ version: '0'
108
+ type: :development
109
+ prerelease: false
110
+ version_requirements: !ruby/object:Gem::Requirement
111
+ requirements:
112
+ - - ">="
113
+ - !ruby/object:Gem::Version
114
+ version: '0'
115
+ description: mvn-get is a java toolkit for quickly checking and setting up library
116
+ dependencies.
117
+ email:
118
+ - hondadai.tw@gmail.com
119
+ executables:
120
+ - mvn-get
121
+ extensions: []
122
+ extra_rdoc_files: []
123
+ files:
124
+ - ".gitignore"
125
+ - Gemfile
126
+ - LICENSE.txt
127
+ - README.md
128
+ - Rakefile
129
+ - bin/mvn-get
130
+ - lib/mvn-get.rb
131
+ - lib/mvn-get/cli.rb
132
+ - lib/mvn-get/mvn-get.rb
133
+ - mvn-get.gemspec
134
+ homepage: https://github.com/HondaDai/mvn-get
135
+ licenses:
136
+ - MIT
137
+ metadata: {}
138
+ post_install_message:
139
+ rdoc_options: []
140
+ require_paths:
141
+ - lib
142
+ required_ruby_version: !ruby/object:Gem::Requirement
143
+ requirements:
144
+ - - ">="
145
+ - !ruby/object:Gem::Version
146
+ version: '0'
147
+ required_rubygems_version: !ruby/object:Gem::Requirement
148
+ requirements:
149
+ - - ">="
150
+ - !ruby/object:Gem::Version
151
+ version: '0'
152
+ requirements: []
153
+ rubyforge_project:
154
+ rubygems_version: 2.2.2
155
+ signing_key:
156
+ specification_version: 4
157
+ summary: mvn-get is a java toolkit for quickly checking and setting up library dependencies.
158
+ test_files: []