maven-cli 1.1.0 → 1.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG +7 -0
- data/README.md +9 -1
- data/lib/mavencli/cli.rb +15 -4
- data/lib/mavencli/downloader.rb +51 -14
- data/lib/mavencli/version.rb +1 -1
- data/maven-cli.gemspec +2 -1
- data/spec/mavencli/downloader_spec.rb +12 -1
- data/spec/mavencli/stubs/servers_stubs.rb +20 -5
- data/spec/spec_helper.rb +1 -0
- metadata +22 -8
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 6172a1b1fb0b6d19502f41b8e252a8ce170a49d3
|
4
|
+
data.tar.gz: e976eb921e176f3afb7901a08736dd109a9e36bf
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2fe59ac8dd31265e5f184197b43d8cec347bd4b62509571c26e30ee50c93178574e7b948f262ac4f75bda2c7bea01e1099ceb1f30930aef70e049c1b960f7870
|
7
|
+
data.tar.gz: 4d4353357d5fd374dfdcfdf2235b164b37708a01b86697a7bf133fa7753c54753c71b22b7f193dc6530825706524ecf3c2786330866dbc897576c5dc129bd372
|
data/CHANGELOG
CHANGED
data/README.md
CHANGED
@@ -23,7 +23,7 @@ Install as a gem:
|
|
23
23
|
Usage
|
24
24
|
-----
|
25
25
|
|
26
|
-
|
26
|
+
An interactive help is available with:
|
27
27
|
|
28
28
|
$ maven-cli help
|
29
29
|
|
@@ -36,6 +36,10 @@ To download a jar from maven repository (http://repo.maven.apache.org/maven2)
|
|
36
36
|
|
37
37
|
For instance: `maven-cli download com.google.guava guava 19.0`
|
38
38
|
|
39
|
+
To download the latest version of a jar, use `latest` as version:
|
40
|
+
|
41
|
+
$ maven-cli download <group> <artifact> latest
|
42
|
+
|
39
43
|
To download a jar from a non standard repository
|
40
44
|
|
41
45
|
$ maven-cli download <group> <artifact> <version> -r <repository>
|
@@ -44,6 +48,10 @@ To download a jar from maven repository and save it to file
|
|
44
48
|
|
45
49
|
$ maven-cli download <group> <artifact> <version> -o <outfile>
|
46
50
|
|
51
|
+
More options with
|
52
|
+
|
53
|
+
$ maven-cli help download
|
54
|
+
|
47
55
|
Contributing
|
48
56
|
------------
|
49
57
|
|
data/lib/mavencli/cli.rb
CHANGED
@@ -26,7 +26,9 @@ module MavenCLI
|
|
26
26
|
end
|
27
27
|
|
28
28
|
desc('download GROUP ARTIFACT VERSION [options]',
|
29
|
-
'Download an artifact from a maven repository.'
|
29
|
+
'Download an artifact from a maven repository. VERSION can be set '\
|
30
|
+
'to "latest" to fetch the latest release or snapshot (if --snapshot)'\
|
31
|
+
' available.')
|
30
32
|
option(
|
31
33
|
:repository,
|
32
34
|
aliases: ['-r'],
|
@@ -63,16 +65,25 @@ module MavenCLI
|
|
63
65
|
default: false,
|
64
66
|
desc: 'Simulation mode. Do nothing'
|
65
67
|
)
|
68
|
+
option(
|
69
|
+
:progress,
|
70
|
+
aliases: ['-d'],
|
71
|
+
type: :boolean,
|
72
|
+
default: true,
|
73
|
+
desc: 'Display a progressbar.'
|
74
|
+
)
|
66
75
|
option(
|
67
76
|
:snapshot,
|
68
77
|
aliases: ['-n'],
|
69
78
|
type: :boolean,
|
70
79
|
default: false,
|
71
|
-
desc: 'Allow the download of a SNAPSHOT version.
|
72
|
-
'
|
80
|
+
desc: 'Allow the download of a SNAPSHOT version. Automatically set if '\
|
81
|
+
'VERSION is a SNAPSHOT version'
|
73
82
|
)
|
74
83
|
def download(group, artifact, version)
|
75
|
-
|
84
|
+
opts = options.dup
|
85
|
+
opts['progress'] &&= !opts['quiet']
|
86
|
+
downloader = MavenCLI::Downloader.new(group, artifact, version, opts)
|
76
87
|
downloader.download
|
77
88
|
end
|
78
89
|
end
|
data/lib/mavencli/downloader.rb
CHANGED
@@ -15,9 +15,12 @@
|
|
15
15
|
# limitations under the License.
|
16
16
|
#
|
17
17
|
|
18
|
-
require '
|
18
|
+
require 'stringio'
|
19
|
+
require 'net/http'
|
19
20
|
require 'uri'
|
20
21
|
require 'xmlsimple'
|
22
|
+
require 'ruby-progressbar'
|
23
|
+
require 'devnull'
|
21
24
|
|
22
25
|
module MavenCLI
|
23
26
|
# This is a simple file downloader class.
|
@@ -29,19 +32,18 @@ module MavenCLI
|
|
29
32
|
artifact_name = filename(artifact, version, opts, fullpath)
|
30
33
|
@target = "#{opts['repository']}/#{fullpath}/#{artifact_name}"
|
31
34
|
@outfile = opts['output_file'].nil? ? artifact_name : opts['output_file']
|
32
|
-
@
|
33
|
-
@simulation = opts['simulation']
|
35
|
+
@opts = opts
|
34
36
|
end
|
35
37
|
|
36
38
|
def download
|
37
|
-
|
38
|
-
puts "#{@outfile} has been Downloaded." unless @quiet
|
39
|
+
get_write(@target, @outfile) unless @opts['simulation']
|
40
|
+
puts "#{@outfile} has been Downloaded." unless @opts['quiet']
|
39
41
|
end
|
40
42
|
|
41
43
|
private
|
42
44
|
|
43
45
|
def latest_version(opts, path)
|
44
|
-
xml =
|
46
|
+
xml = get_write("#{opts['repository']}/#{path}/maven-metadata.xml")
|
45
47
|
latest = xml_path(xml, 'versioning', 'latest')
|
46
48
|
release = xml_path(xml, 'versioning', 'release')
|
47
49
|
version = opts['snapshot'] && !latest.nil? ? latest : release
|
@@ -52,7 +54,7 @@ module MavenCLI
|
|
52
54
|
def filename(artifact, version, opts, path)
|
53
55
|
name = "#{artifact}-#{version.chomp('-SNAPSHOT')}"
|
54
56
|
if version.end_with?('SNAPSHOT')
|
55
|
-
xml =
|
57
|
+
xml = get_write("#{opts['repository']}/#{path}/maven-metadata.xml")
|
56
58
|
name += snapshot_tag(xml)
|
57
59
|
end
|
58
60
|
name += "-#{opts['classifier']}" unless opts['classifier'].nil?
|
@@ -71,14 +73,49 @@ module MavenCLI
|
|
71
73
|
nil
|
72
74
|
end
|
73
75
|
|
74
|
-
def
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
76
|
+
def get_write(target, outfile = '')
|
77
|
+
ssl = target.start_with?('https://')
|
78
|
+
io = (outfile.empty? ? StringIO : File).new(outfile.dup, 'w')
|
79
|
+
response = get_write_response(URI(target), ssl, io, outfile)
|
80
|
+
io.close
|
81
|
+
case response
|
82
|
+
when Net::HTTPSuccess then io.is_a?(StringIO) ? io.string : 'ok'
|
83
|
+
when Net::HTTPRedirection then get_write(response['location'], outfile)
|
84
|
+
else raise "Unable to download #{target}: Status: #{response.code}"
|
80
85
|
end
|
81
|
-
|
86
|
+
end
|
87
|
+
|
88
|
+
def get_write_response(uri, ssl, io, outfile)
|
89
|
+
Net::HTTP.start(uri.host, uri.port, use_ssl: ssl) do |http|
|
90
|
+
request = Net::HTTP::Get.new(uri)
|
91
|
+
http.request(request) do |response|
|
92
|
+
if response.is_a?(Net::HTTPSuccess)
|
93
|
+
write_response(io, outfile, response)
|
94
|
+
end
|
95
|
+
end
|
96
|
+
end
|
97
|
+
end
|
98
|
+
|
99
|
+
def write_response(io, outfile, response)
|
100
|
+
progressbar = create_progressbar(response, outfile)
|
101
|
+
response.read_body do |chunk|
|
102
|
+
io.write(chunk)
|
103
|
+
progressbar.progress += chunk.length / 1024
|
104
|
+
end
|
105
|
+
progressbar.finish
|
106
|
+
end
|
107
|
+
|
108
|
+
def create_progressbar(response, out)
|
109
|
+
size = response['content-length'].to_i / 1024
|
110
|
+
options = {
|
111
|
+
title: out.length > 19 ? "#{out[0..14]}…#{out[-4..-1]}" : out,
|
112
|
+
total: size.zero? ? nil : size,
|
113
|
+
output: out.empty? || !@opts['progress'] ? DevNull.new : $stdout,
|
114
|
+
format: "%t %b\u{15E7}%i %RkB/s %p%% %E",
|
115
|
+
progress_mark: ' ',
|
116
|
+
remainder_mark: "\u{FF65}"
|
117
|
+
}
|
118
|
+
ProgressBar.create(options)
|
82
119
|
end
|
83
120
|
end
|
84
121
|
end
|
data/lib/mavencli/version.rb
CHANGED
data/maven-cli.gemspec
CHANGED
@@ -46,6 +46,7 @@ Gem::Specification.new do |s|
|
|
46
46
|
s.add_development_dependency 'simplecov', '~> 0.12'
|
47
47
|
|
48
48
|
s.add_dependency 'thor', '~> 0.19'
|
49
|
-
s.add_dependency 'faraday', '~> 0.9'
|
50
49
|
s.add_dependency 'xml-simple', '~> 1.1'
|
50
|
+
s.add_dependency 'ruby-progressbar', '~> 1.8.0'
|
51
|
+
s.add_dependency 'devnull', '~> 0.1.2'
|
51
52
|
end
|
@@ -17,13 +17,14 @@
|
|
17
17
|
require 'spec_helper'
|
18
18
|
|
19
19
|
nexus = 'https://nexus.mydomain.net/repository/maven-public'
|
20
|
+
redirect = 'https://toredirect.org/maven'
|
20
21
|
|
21
22
|
def dl_test(file)
|
22
23
|
dir = File.dirname(__FILE__)
|
23
24
|
File.join(dir, '..', '..', file)
|
24
25
|
end
|
25
26
|
|
26
|
-
describe MavenCLI::Downloader do
|
27
|
+
describe MavenCLI::Downloader do # rubocop:disable Metrics/BlockLength
|
27
28
|
context 'download com/mygroup test 1.0.0' do
|
28
29
|
it 'downloads without option.' do
|
29
30
|
file = 'test-1.0.0.jar'
|
@@ -133,4 +134,14 @@ describe MavenCLI::Downloader do
|
|
133
134
|
expect { start(self) }.to output(out).to_stderr
|
134
135
|
end
|
135
136
|
end
|
137
|
+
|
138
|
+
context "download com/mygroup test latest -n -r #{redirect}" do
|
139
|
+
it 'downloads on a repository that will redirect.' do
|
140
|
+
file = 'test-7.0.0-19831018.151200-1.jar'
|
141
|
+
out = "#{file} has been Downloaded.\n"
|
142
|
+
expect { start(self) }.to output(out).to_stdout
|
143
|
+
expect { print File.read(dl_test(file)) }.to output('OK').to_stdout
|
144
|
+
File.delete(dl_test(file))
|
145
|
+
end
|
146
|
+
end
|
136
147
|
end
|
@@ -26,6 +26,7 @@ end
|
|
26
26
|
|
27
27
|
maven = 'https://repo.maven.apache.org/maven2'
|
28
28
|
nexus = 'https://nexus.mydomain.net/repository/maven-public'
|
29
|
+
redirect = 'https://toredirect.org/maven'
|
29
30
|
|
30
31
|
tests = {
|
31
32
|
[maven, 'com/mygroup', 'test', 'root'] => [
|
@@ -52,18 +53,32 @@ RSpec.configure do |config|
|
|
52
53
|
config.before(:each) do
|
53
54
|
tests.each do |key, arrays|
|
54
55
|
repo, group, artifact, root_xml = key
|
55
|
-
|
56
|
+
|
57
|
+
# artifact metafile
|
58
|
+
meta_path = "#{group}/#{artifact}/#{meta_file}"
|
59
|
+
stub_request(:get, "#{redirect}/#{meta_path}")
|
60
|
+
.to_return(status: 307, headers: { location: "#{repo}/#{meta_path}" })
|
61
|
+
stub_request(:get, "#{repo}/#{meta_path}")
|
56
62
|
.to_return(status: 200, body: read_xml(root_xml), headers: {})
|
57
63
|
|
58
64
|
arrays.each do |code, version, type, tag|
|
59
|
-
path = "#{
|
65
|
+
path = "#{group}/#{artifact}/#{version}"
|
66
|
+
|
67
|
+
# version metafile
|
68
|
+
meta = "#{group}/#{artifact}/#{version}/#{meta_file}"
|
69
|
+
stub_request(:get, "#{redirect}/#{path}/#{meta_file}")
|
70
|
+
.to_return(status: 302, headers: { location: "#{repo}/#{meta}" })
|
60
71
|
|
61
72
|
xml_status = version.end_with?('SNAPSHOT') ? code : 404
|
62
|
-
stub_request(:get, "#{
|
73
|
+
stub_request(:get, "#{repo}/#{meta}")
|
63
74
|
.to_return(status: xml_status, body: read_xml('inside'), headers: {})
|
64
75
|
|
65
|
-
file
|
66
|
-
|
76
|
+
# file download
|
77
|
+
file_version = "#{version.chomp('-SNAPSHOT')}#{tag}"
|
78
|
+
file = "#{path}/#{artifact}-#{file_version}.#{type}"
|
79
|
+
stub_request(:get, "#{redirect}/#{file}")
|
80
|
+
.to_return(status: 301, headers: { location: "#{repo}/#{file}" })
|
81
|
+
stub_request(:get, "#{repo}/#{file}")
|
67
82
|
.to_return(status: code, body: 'OK', headers: {})
|
68
83
|
end
|
69
84
|
end
|
data/spec/spec_helper.rb
CHANGED
@@ -42,6 +42,7 @@ Dir[files].each { |file| require file }
|
|
42
42
|
# To test the cli
|
43
43
|
def start(caller_object, subcommand = nil)
|
44
44
|
cmd = caller_object.class.description.split(' ')
|
45
|
+
cmd << '-d' << 'false' if cmd.first == 'download' && !cmd.include?('-q')
|
45
46
|
args = [subcommand, *cmd].compact
|
46
47
|
MavenCLI.start(args, true)
|
47
48
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: maven-cli
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Samuel Bernard
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2017-01-
|
12
|
+
date: 2017-01-16 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: bundler
|
@@ -110,33 +110,47 @@ dependencies:
|
|
110
110
|
- !ruby/object:Gem::Version
|
111
111
|
version: '0.19'
|
112
112
|
- !ruby/object:Gem::Dependency
|
113
|
-
name:
|
113
|
+
name: xml-simple
|
114
114
|
requirement: !ruby/object:Gem::Requirement
|
115
115
|
requirements:
|
116
116
|
- - "~>"
|
117
117
|
- !ruby/object:Gem::Version
|
118
|
-
version: '
|
118
|
+
version: '1.1'
|
119
119
|
type: :runtime
|
120
120
|
prerelease: false
|
121
121
|
version_requirements: !ruby/object:Gem::Requirement
|
122
122
|
requirements:
|
123
123
|
- - "~>"
|
124
124
|
- !ruby/object:Gem::Version
|
125
|
-
version: '
|
125
|
+
version: '1.1'
|
126
126
|
- !ruby/object:Gem::Dependency
|
127
|
-
name:
|
127
|
+
name: ruby-progressbar
|
128
128
|
requirement: !ruby/object:Gem::Requirement
|
129
129
|
requirements:
|
130
130
|
- - "~>"
|
131
131
|
- !ruby/object:Gem::Version
|
132
|
-
version:
|
132
|
+
version: 1.8.0
|
133
133
|
type: :runtime
|
134
134
|
prerelease: false
|
135
135
|
version_requirements: !ruby/object:Gem::Requirement
|
136
136
|
requirements:
|
137
137
|
- - "~>"
|
138
138
|
- !ruby/object:Gem::Version
|
139
|
-
version:
|
139
|
+
version: 1.8.0
|
140
|
+
- !ruby/object:Gem::Dependency
|
141
|
+
name: devnull
|
142
|
+
requirement: !ruby/object:Gem::Requirement
|
143
|
+
requirements:
|
144
|
+
- - "~>"
|
145
|
+
- !ruby/object:Gem::Version
|
146
|
+
version: 0.1.2
|
147
|
+
type: :runtime
|
148
|
+
prerelease: false
|
149
|
+
version_requirements: !ruby/object:Gem::Requirement
|
150
|
+
requirements:
|
151
|
+
- - "~>"
|
152
|
+
- !ruby/object:Gem::Version
|
153
|
+
version: 0.1.2
|
140
154
|
description: Tool to interact with Maven repositories with CLI
|
141
155
|
email: dps.team@s4m.io
|
142
156
|
executables:
|