maven-cli 1.0.0 → 1.1.0

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: a7477c96b8ce0bd10f2e0fecc3cbe6c953da3d68
4
- data.tar.gz: 1e4423fc97b285e9ab7ba75f1b61d56e124f0739
3
+ metadata.gz: e452f3749de2fa98dbd28bb5231db63088af6121
4
+ data.tar.gz: 42acb73cc02aa2990b7c1f0928248b2349e87d73
5
5
  SHA512:
6
- metadata.gz: da11e072a7e428db945c5ca3dc2b11e521a658cfa406e0e9d4ae1baecd074c3e9f090a0bdbf95201385c54dcfb9ebda50c911522a70247cd724ed0888e2324af
7
- data.tar.gz: 73b0587485728a7ad32132a8534197235005af5525840a600d997eb99dd4060195614cf702650482140b37750d004938d7cefa8b7e5d560ef5dc78dcf4d10f33
6
+ metadata.gz: 8906eaa07d210768cea8cad9cd33ac2ee51aa9586e445c3e5c6c77992c310f3b10b2f3483582c2cf239e11946c09c826700c27c0f7d30bde0a3973e6b5d1e6a0
7
+ data.tar.gz: 83c0f810390caf0e33b45a03c1d57b799a5400e4e53de7671f4704a44ba1314a1ff046e2a506772ea01ce18cd3de6d126202809cee491316822b66f50cf03331
data/.gitignore CHANGED
@@ -1,3 +1,4 @@
1
1
  maven-cli-*.gem
2
2
  test-*
3
3
  Gemfile.lock
4
+ coverage
@@ -1,16 +1,19 @@
1
1
  image: sbernard/arch-kitchen-docker
2
2
 
3
3
  rubocop:
4
+ stage: test
4
5
  script:
5
6
  - rubocop
6
7
 
7
8
  lines_length:
9
+ stage: test
8
10
  script:
9
11
  - >
10
12
  curl https://gitlab.com/s4m/checks/raw/master/check_lines_length.sh |
11
13
  bash
12
14
 
13
15
  git_history:
16
+ stage: test
14
17
  script:
15
18
  - >
16
19
  curl https://gitlab.com/s4m/checks/raw/master/check_git_history.sh |
@@ -20,5 +23,22 @@ before_script:
20
23
  - bundle install
21
24
 
22
25
  rspec:
26
+ stage: test
23
27
  script:
24
28
  - rspec
29
+ artifacts:
30
+ paths:
31
+ - coverage/
32
+
33
+ pages:
34
+ stage: deploy
35
+ dependencies:
36
+ - rspec
37
+ script:
38
+ - mv coverage/ public/
39
+ artifacts:
40
+ paths:
41
+ - public
42
+ expire_in: 30 days
43
+ only:
44
+ - develop
data/CHANGELOG CHANGED
@@ -1,6 +1,23 @@
1
1
  Changelog
2
2
  =========
3
3
 
4
+ 1.1.0
5
+ -----
6
+
7
+ Main:
8
+
9
+ - Fix #2: download latest version if not specified
10
+ - Fix #3: 404 error when version contains an hyphen
11
+ - Exit 1 when an error occur, except during tests
12
+ - Fix gem description, add ruby support
13
+
14
+ Tests:
15
+
16
+ - Add code coverage
17
+ - Fix rspec tests (https instead of http)
18
+ - Achieve 100% test coverage!
19
+ - Rewrite stub testcases, shorter and more readable
20
+
4
21
  1.0.0
5
22
  -----
6
23
 
data/README.md CHANGED
@@ -3,6 +3,16 @@ MavenCLI
3
3
 
4
4
  Simple maven cli tool.
5
5
 
6
+ Build Status & Coverage Report
7
+ ------------------------------
8
+
9
+ [![build status]
10
+ (https://gitlab.com/s4m-gems/maven-cli/badges/develop/build.svg)]
11
+ (https://gitlab.com/s4m-gems/maven-cli/commits/develop)
12
+ [![coverage report]
13
+ (https://gitlab.com/s4m-gems/maven-cli/badges/develop/coverage.svg)]
14
+ (https://s4m-gems.gitlab.io/maven-cli/)
15
+
6
16
  Installation
7
17
  ------------
8
18
 
@@ -22,10 +22,11 @@ module MavenCLI
22
22
  require file
23
23
  end
24
24
 
25
- def start
26
- MavenCLI::CLI.start(ARGV)
25
+ def start(args = ARGV, test = false)
26
+ MavenCLI::CLI.start(args)
27
27
  rescue => e
28
- puts e
28
+ $stderr.puts e
29
+ exit(1) unless test # Do not exit if we are in a test
29
30
  end
30
31
  end
31
32
  end
@@ -25,7 +25,8 @@ module MavenCLI
25
25
  puts "MavenCLI version #{MavenCLI::VERSION}"
26
26
  end
27
27
 
28
- desc 'download GROUP ARTIFACT VERSION [options]', 'Download an artifact'
28
+ desc('download GROUP ARTIFACT VERSION [options]',
29
+ 'Download an artifact from a maven repository.')
29
30
  option(
30
31
  :repository,
31
32
  aliases: ['-r'],
@@ -35,18 +36,18 @@ module MavenCLI
35
36
  option(
36
37
  :classifier,
37
38
  aliases: ['-c'],
38
- desc: 'Classifier of the requested artifact.'
39
+ desc: 'Classifier of the requested artifact'
39
40
  )
40
41
  option(
41
42
  :packaging,
42
43
  aliases: ['-p'],
43
44
  default: 'jar',
44
- desc: 'Packaging of the requested artifact.'
45
+ desc: 'Packaging of the requested artifact'
45
46
  )
46
47
  option(
47
48
  :output_file,
48
49
  aliases: ['-o'],
49
- desc: 'Output file.'
50
+ desc: 'Output file'
50
51
  )
51
52
  option(
52
53
  :quiet,
@@ -62,6 +63,14 @@ module MavenCLI
62
63
  default: false,
63
64
  desc: 'Simulation mode. Do nothing'
64
65
  )
66
+ option(
67
+ :snapshot,
68
+ aliases: ['-n'],
69
+ type: :boolean,
70
+ default: false,
71
+ desc: 'Allow the download of a SNAPSHOT version. Overriden if'\
72
+ 'version contains SNAPSHOT'
73
+ )
65
74
  def download(group, artifact, version)
66
75
  downloader = MavenCLI::Downloader.new(group, artifact, version, options)
67
76
  downloader.download
@@ -23,9 +23,11 @@ module MavenCLI
23
23
  # This is a simple file downloader class.
24
24
  class Downloader
25
25
  def initialize(group, artifact, version, opts)
26
- path = "#{group.tr('.', '/')}/#{artifact}/#{version}"
27
- artifact_name = filename(artifact, version, opts, path)
28
- @target = "#{opts['repository']}/#{path}/#{artifact_name}"
26
+ path = "#{group.tr('.', '/')}/#{artifact}"
27
+ version = latest_version(opts, path) if version.casecmp('latest').zero?
28
+ fullpath = "#{path}/#{version}"
29
+ artifact_name = filename(artifact, version, opts, fullpath)
30
+ @target = "#{opts['repository']}/#{fullpath}/#{artifact_name}"
29
31
  @outfile = opts['output_file'].nil? ? artifact_name : opts['output_file']
30
32
  @quiet = opts['quiet']
31
33
  @simulation = opts['simulation']
@@ -38,27 +40,35 @@ module MavenCLI
38
40
 
39
41
  private
40
42
 
43
+ def latest_version(opts, path)
44
+ xml = http_get("#{opts['repository']}/#{path}/maven-metadata.xml")
45
+ latest = xml_path(xml, 'versioning', 'latest')
46
+ release = xml_path(xml, 'versioning', 'release')
47
+ version = opts['snapshot'] && !latest.nil? ? latest : release
48
+ raise 'No valid version found, try with --snapshot?' if version.nil?
49
+ version
50
+ end
51
+
41
52
  def filename(artifact, version, opts, path)
42
- name = "#{artifact}-#{version.split('-').first}"
43
- if version.include? 'SNAPSHOT'
53
+ name = "#{artifact}-#{version.chomp('-SNAPSHOT')}"
54
+ if version.end_with?('SNAPSHOT')
44
55
  xml = http_get("#{opts['repository']}/#{path}/maven-metadata.xml")
45
- name += "-#{timestamp(xml)}-#{buildnumber(xml)}"
56
+ name += snapshot_tag(xml)
46
57
  end
47
58
  name += "-#{opts['classifier']}" unless opts['classifier'].nil?
48
59
  name += ".#{opts['packaging']}"
49
60
  name
50
61
  end
51
62
 
52
- def timestamp(xml)
53
- versioning_node = XmlSimple.xml_in(xml)['versioning'].first
54
- snapshot_node = versioning_node['snapshot'].first
55
- snapshot_node['timestamp'].first
63
+ def snapshot_tag(xml)
64
+ node = xml_path(xml, 'versioning', 'snapshot')
65
+ "-#{node['timestamp'].first}-#{node['buildNumber'].first}"
56
66
  end
57
67
 
58
- def buildnumber(xml)
59
- versioning_node = XmlSimple.xml_in(xml)['versioning'].first
60
- snapshot_node = versioning_node['snapshot'].first
61
- snapshot_node['buildNumber'].first
68
+ def xml_path(xml, *path)
69
+ path.reduce(XmlSimple.xml_in(xml)) { |acc, elem| acc[elem].first }
70
+ rescue
71
+ nil
62
72
  end
63
73
 
64
74
  def http_get(url)
@@ -16,5 +16,5 @@
16
16
  #
17
17
 
18
18
  module MavenCLI
19
- VERSION = '1.0.0'.freeze
19
+ VERSION = '1.1.0'.freeze
20
20
  end
@@ -26,7 +26,7 @@ Gem::Specification.new do |s|
26
26
  s.license = 'Apache-2.0'
27
27
 
28
28
  s.summary = 'Tool to interact with Maven repositories with CLI'
29
- s.description = IO.read(File.join(File.dirname(__FILE__), 'README.md'))
29
+ s.description = 'Tool to interact with Maven repositories with CLI'
30
30
  s.homepage = 'https://gitlab.com/s4m-gems/maven-cli'
31
31
 
32
32
  s.files = `git ls-files`.lines.map(&:chomp)
@@ -36,11 +36,14 @@ Gem::Specification.new do |s|
36
36
  end
37
37
  s.require_paths = ['lib']
38
38
 
39
+ s.required_ruby_version = '>= 2.0'
40
+
39
41
  s.add_development_dependency 'bundler', '~> 1.12'
40
42
  s.add_development_dependency 'rspec', '~> 3.5'
41
43
  s.add_development_dependency 'rake', '~> 11.2'
42
44
  s.add_development_dependency 'rubocop', '~> 0.43'
43
45
  s.add_development_dependency 'webmock', '~> 2.1'
46
+ s.add_development_dependency 'simplecov', '~> 0.12'
44
47
 
45
48
  s.add_dependency 'thor', '~> 0.19'
46
49
  s.add_dependency 'faraday', '~> 0.9'
@@ -1,7 +1,7 @@
1
1
  <metadata modelVersion="1.1.0">
2
2
  <groupId>com.mygroup</groupId>
3
- <artifactId>test1</artifactId>
4
- <version>0.0.0-SNAPSHOT</version>
3
+ <artifactId>test</artifactId>
4
+ <version>7.0.0-SNAPSHOT</version>
5
5
  <versioning>
6
6
  <snapshot>
7
7
  <timestamp>19831018.151200</timestamp>
@@ -11,24 +11,24 @@
11
11
  <snapshotVersions>
12
12
  <snapshotVersion>
13
13
  <extension>jar</extension>
14
- <value>1.0.0-19831018.151200-1</value>
14
+ <value>7.0.0-19831018.151200-1</value>
15
15
  <updated>19831018151200</updated>
16
16
  </snapshotVersion>
17
17
  <snapshotVersion>
18
18
  <extension>pom</extension>
19
- <value>1.0.0-19831018.151200-1</value>
19
+ <value>7.0.0-19831018.151200-1</value>
20
20
  <updated>19831018151200</updated>
21
21
  </snapshotVersion>
22
22
  <snapshotVersion>
23
23
  <classifier>sources</classifier>
24
24
  <extension>jar</extension>
25
- <value>1.0.0-19831018.151200-1</value>
25
+ <value>7.0.0-19831018.151200-1</value>
26
26
  <updated>19831018151200</updated>
27
27
  </snapshotVersion>
28
28
  <snapshotVersion>
29
29
  <classifier>javadoc</classifier>
30
30
  <extension>jar</extension>
31
- <value>1.0.0-19831018.151200-1</value>
31
+ <value>7.0.0-19831018.151200-1</value>
32
32
  <updated>19831018151200</updated>
33
33
  </snapshotVersion>
34
34
  </snapshotVersions>
@@ -0,0 +1,11 @@
1
+ <metadata modelVersion="1.1.0">
2
+ <groupId>com.mygroup</groupId>
3
+ <artifactId>test2</artifactId>
4
+ <versioning>
5
+ <release>1.0.0</release>
6
+ <versions>
7
+ <version>1.0.0</version>
8
+ </versions>
9
+ <lastUpdated>19831018151200</lastUpdated>
10
+ </versioning>
11
+ </metadata>
@@ -0,0 +1,19 @@
1
+ <metadata modelVersion="1.1.0">
2
+ <groupId>com.mygroup</groupId>
3
+ <artifactId>test</artifactId>
4
+ <versioning>
5
+ <latest>7.0.0-SNAPSHOT</latest>
6
+ <release>7.0.0-rc1</release>
7
+ <versions>
8
+ <version>1.0.0</version>
9
+ <version>2.0.0</version>
10
+ <version>3.0.0</version>
11
+ <version>4.0.0</version>
12
+ <version>5.0.0</version>
13
+ <version>6.0.0</version>
14
+ <version>7.0.0-rc1</version>
15
+ <version>7.0.0-SNAPSHOT</version>
16
+ </versions>
17
+ <lastUpdated>19831018151200</lastUpdated>
18
+ </versioning>
19
+ </metadata>
@@ -0,0 +1,11 @@
1
+ <metadata modelVersion="1.1.0">
2
+ <groupId>com.mygroup</groupId>
3
+ <artifactId>test3</artifactId>
4
+ <versioning>
5
+ <latest>1.0.0-SNAPSHOT</latest>
6
+ <versions>
7
+ <version>1.0.0-SNAPSHOT</version>
8
+ </versions>
9
+ <lastUpdated>19831018151200</lastUpdated>
10
+ </versioning>
11
+ </metadata>
@@ -16,19 +16,6 @@
16
16
 
17
17
  require 'spec_helper'
18
18
 
19
- dir = File.dirname(__FILE__)
20
- nexus = 'https://nexus.mydomain.net/repository/maven-public'
21
-
22
- dl_test = [
23
- 'test-1.0.0.jar',
24
- 'test-2.0.0-19831018.151200-1.jar',
25
- 'test-3.0.0.jar',
26
- 'test-4.0.0.tgz',
27
- 'test-5.0.0_test.jar',
28
- 'test-6.0.0.jar',
29
- 'test-7.0.0.jar'
30
- ].map { |file| File.join(dir, '..', '..', file) }
31
-
32
19
  describe MavenCLI::CLI do
33
20
  context 'version' do
34
21
  it 'prints the version.' do
@@ -36,45 +23,4 @@ describe MavenCLI::CLI do
36
23
  expect { start(self) }.to output(out).to_stdout
37
24
  end
38
25
  end
39
-
40
- context 'download com/mygroup test 1.0.0 -s' do
41
- it 'should simulate a download without option via CLI.' do
42
- out = "#{File.basename(dl_test[0])} has been Downloaded.\n"
43
- expect { start(self) }.to output(out).to_stdout
44
- end
45
- end
46
-
47
- context 'download com/mygroup test 2.0.0-SNAPSHOT -s ' do
48
- it 'should simulate a download a snapshot version via CLI.' do
49
- out = "#{File.basename(dl_test[1])} has been Downloaded.\n"
50
- expect { start(self) }.to output(out).to_stdout
51
- end
52
- end
53
-
54
- context "download com/mygroup test 3.0.0 -r #{nexus} -s" do
55
- it 'should simulate a download with option --repository via CLI.' do
56
- out = "#{File.basename(dl_test[2])} has been Downloaded.\n"
57
- expect { start(self) }.to output(out).to_stdout
58
- end
59
- end
60
-
61
- context 'download com/mygroup test 4.0.0 -p tgz -s' do
62
- it 'should simulate a download with option --packaging via CLI.' do
63
- out = "#{File.basename(dl_test[3])} has been Downloaded.\n"
64
- expect { start(self) }.to output(out).to_stdout
65
- end
66
- end
67
-
68
- context "download com/mygroup test 5.0.0 -o #{dl_test[4]} -s" do
69
- it 'should simulate a download with option --output-file via CLI.' do
70
- out = "#{dl_test[4]} has been Downloaded.\n"
71
- expect { start(self) }.to output(out).to_stdout
72
- end
73
- end
74
-
75
- context 'download com/mygroup test 6.0.0 -q -s' do
76
- it 'should simulate a download with option --quiet via CLI.' do
77
- expect { start(self) }.to output('').to_stdout
78
- end
79
- end
80
26
  end
@@ -16,76 +16,121 @@
16
16
 
17
17
  require 'spec_helper'
18
18
 
19
- dir = File.dirname(__FILE__)
20
19
  nexus = 'https://nexus.mydomain.net/repository/maven-public'
21
20
 
22
- dl_test = [
23
- 'test-1.0.0.jar',
24
- 'test-2.0.0-19831018.151200-1.jar',
25
- 'test-3.0.0.jar',
26
- 'test-4.0.0.tgz',
27
- 'test-5.0.0_test.jar',
28
- 'test-6.0.0.jar',
29
- 'test-7.0.0.jar'
30
- ].map { |file| File.join(dir, '..', '..', file) }
21
+ def dl_test(file)
22
+ dir = File.dirname(__FILE__)
23
+ File.join(dir, '..', '..', file)
24
+ end
31
25
 
32
26
  describe MavenCLI::Downloader do
33
27
  context 'download com/mygroup test 1.0.0' do
34
28
  it 'downloads without option.' do
35
- out = "test-1.0.0.jar has been Downloaded.\n"
29
+ file = 'test-1.0.0.jar'
30
+ out = "#{file} has been Downloaded.\n"
36
31
  expect { start(self) }.to output(out).to_stdout
37
- expect { print File.read(dl_test[0]) }.to output('OK').to_stdout
38
- File.delete(dl_test[0])
32
+ expect { print File.read(dl_test(file)) }.to output('OK').to_stdout
33
+ File.delete(dl_test(file))
39
34
  end
40
35
  end
41
36
 
42
- context 'download com/mygroup test 2.0.0-SNAPSHOT' do
43
- it 'downloads a snapshot version.' do
44
- out = "test-2.0.0-19831018.151200-1.jar has been Downloaded.\n"
37
+ context 'download com/mygroup test 2.0.0 -s' do
38
+ it 'should simulate a download.' do
39
+ out = "test-2.0.0.jar has been Downloaded.\n"
45
40
  expect { start(self) }.to output(out).to_stdout
46
- expect { print File.read(dl_test[1]) }.to output('OK').to_stdout
47
- File.delete(dl_test[1])
48
41
  end
49
42
  end
50
43
 
51
44
  context "download com/mygroup test 3.0.0 -r #{nexus}" do
52
45
  it 'downloads with option --repository.' do
53
- out = "test-3.0.0.jar has been Downloaded.\n"
46
+ file = 'test-3.0.0.jar'
47
+ out = "#{file} has been Downloaded.\n"
54
48
  expect { start(self) }.to output(out).to_stdout
55
- expect { print File.read(dl_test[2]) }.to output('OK').to_stdout
56
- File.delete(dl_test[2])
49
+ expect { print File.read(dl_test(file)) }.to output('OK').to_stdout
50
+ File.delete(dl_test(file))
57
51
  end
58
52
  end
59
53
 
60
54
  context 'download com/mygroup test 4.0.0 -p tgz' do
61
55
  it 'downloads with option --packaging.' do
62
- out = "test-4.0.0.tgz has been Downloaded.\n"
56
+ file = 'test-4.0.0.tgz'
57
+ out = "#{file} has been Downloaded.\n"
63
58
  expect { start(self) }.to output(out).to_stdout
64
- expect { print File.read(dl_test[3]) }.to output('OK').to_stdout
65
- File.delete(dl_test[3])
59
+ expect { print File.read(dl_test(file)) }.to output('OK').to_stdout
60
+ File.delete(dl_test(file))
66
61
  end
67
62
  end
68
63
 
69
- context "download com/mygroup test 5.0.0 -o #{dl_test[4]}" do
64
+ context 'download com/mygroup test 5.0.0 -o test-5.0.0_test.jar' do
70
65
  it 'downloads with option --output-file.' do
71
- out = "#{dl_test[4]} has been Downloaded.\n"
66
+ file = 'test-5.0.0_test.jar'
67
+ out = "#{file} has been Downloaded.\n"
72
68
  expect { start(self) }.to output(out).to_stdout
73
- expect { print File.read(dl_test[4]) }.to output('OK').to_stdout
74
- File.delete(dl_test[4])
69
+ expect { print File.read(dl_test(file)) }.to output('OK').to_stdout
70
+ File.delete(dl_test(file))
75
71
  end
76
72
  end
77
73
 
78
74
  context 'download com/mygroup test 6.0.0 -q' do
79
75
  it 'downloads with option --quiet.' do
76
+ file = 'test-6.0.0.jar'
80
77
  expect { start(self) }.to output('').to_stdout
81
- File.delete(dl_test[5])
78
+ File.delete(dl_test(file))
82
79
  end
83
80
  end
84
81
 
85
82
  context "download com/mygroup test 7.0.0 -r #{nexus}" do
86
83
  it 'fails to download an absent artifact.' do
87
- out = 'Unable to download .* Status: 404'
88
- expect { start(self) }.to raise_error(RuntimeError, /#{out}/)
84
+ out = 'Unable to download '\
85
+ "#{nexus}/com/mygroup/test/7.0.0/test-7.0.0.jar: Status: 404\n"
86
+ expect { start(self) }.to output(out).to_stderr
87
+ end
88
+ end
89
+
90
+ context 'download com/mygroup test 7.0.0-SNAPSHOT' do
91
+ it 'downloads a snapshot version by appending SNAPSHOT to the version.' do
92
+ file = 'test-7.0.0-19831018.151200-1.jar'
93
+ out = "#{file} has been Downloaded.\n"
94
+ expect { start(self) }.to output(out).to_stdout
95
+ expect { print File.read(dl_test(file)) }.to output('OK').to_stdout
96
+ File.delete(dl_test(file))
97
+ end
98
+ end
99
+
100
+ context 'download com/mygroup test latest' do
101
+ it 'downloads latest released (actually rc1) version.' do
102
+ file = 'test-7.0.0-rc1.jar'
103
+ out = "#{file} has been Downloaded.\n"
104
+ expect { start(self) }.to output(out).to_stdout
105
+ expect { print File.read(dl_test(file)) }.to output('OK').to_stdout
106
+ File.delete(dl_test(file))
107
+ end
108
+ end
109
+
110
+ context 'download com/mygroup test latest -n' do
111
+ it 'downloads latest snapshot version.' do
112
+ file = 'test-7.0.0-19831018.151200-1.jar'
113
+ out = "#{file} has been Downloaded.\n"
114
+ expect { start(self) }.to output(out).to_stdout
115
+ expect { print File.read(dl_test(file)) }.to output('OK').to_stdout
116
+ File.delete(dl_test(file))
117
+ end
118
+ end
119
+
120
+ context 'download com/mygroup test2 latest -n' do
121
+ it 'downloads latest released version because no snapshot exists.' do
122
+ file = 'test2-1.0.0.jar'
123
+ out = "#{file} has been Downloaded.\n"
124
+ expect { start(self) }.to output(out).to_stdout
125
+ expect { print File.read(dl_test(file)) }.to output('OK').to_stdout
126
+ File.delete(dl_test(file))
127
+ end
128
+ end
129
+
130
+ context 'download com/mygroup test3 latest' do
131
+ it 'fails to download anything because no release exists.' do
132
+ out = "No valid version found, try with --snapshot?\n"
133
+ expect { start(self) }.to output(out).to_stderr
89
134
  end
90
135
  end
91
136
  end
@@ -16,49 +16,56 @@
16
16
 
17
17
  require 'spec_helper'
18
18
 
19
- dir = File.dirname(__FILE__)
20
19
  meta_file = 'maven-metadata.xml'
21
- xml_content = File.read(File.join(dir, '..', '..', 'files', meta_file))
22
- maven = 'http://repo.maven.apache.org/maven2'
20
+
21
+ def read_xml(name)
22
+ meta_file = 'maven-metadata.xml'
23
+ dir = File.dirname(__FILE__)
24
+ File.read(File.join(dir, '..', '..', 'files', "#{name}_#{meta_file}"))
25
+ end
26
+
27
+ maven = 'https://repo.maven.apache.org/maven2'
23
28
  nexus = 'https://nexus.mydomain.net/repository/maven-public'
24
- artifact = 'test'
29
+
25
30
  tests = {
26
- artifact => [
27
- [200, maven, 'com/mygroup', '1.0.0', 'jar'],
28
- [
29
- 200,
30
- maven,
31
- 'com/mygroup',
32
- '2.0.0-SNAPSHOT',
33
- 'jar',
34
- '19831018.151200',
35
- '1'
36
- ],
37
- [200, nexus, 'com/mygroup', '3.0.0', 'jar'],
38
- [200, maven, 'com/mygroup', '4.0.0', 'tgz'],
39
- [200, maven, 'com/mygroup', '5.0.0', 'jar'],
40
- [200, maven, 'com/mygroup', '6.0.0', 'jar'],
41
- [404, nexus, 'com/mygroup', '7.0.0', 'jar']
31
+ [maven, 'com/mygroup', 'test', 'root'] => [
32
+ [200, '1.0.0', 'jar'],
33
+ [200, '4.0.0', 'tgz'],
34
+ [200, '5.0.0', 'jar'],
35
+ [200, '6.0.0', 'jar'],
36
+ [200, '7.0.0-rc1', 'jar'],
37
+ [200, '7.0.0-SNAPSHOT', 'jar', '-19831018.151200-1']
38
+ ],
39
+ [nexus, 'com/mygroup', 'test', 'root'] => [
40
+ [200, '3.0.0', 'jar'],
41
+ [404, '7.0.0', 'jar']
42
+ ],
43
+ [maven, 'com/mygroup', 'test2', 'rel'] => [
44
+ [200, '1.0.0', 'jar']
45
+ ],
46
+ [maven, 'com/mygroup', 'test3', 'snap'] => [
47
+ [200, '1.0.0-SNAPSHOT', 'jar', '-19831018.151200-1']
42
48
  ]
43
49
  }
44
50
 
45
51
  RSpec.configure do |config|
46
52
  config.before(:each) do
47
- tests[artifact].each do |array|
48
- vernum = array[3].split('-').first
49
- file = "#{artifact}-#{vernum}"
50
- file += "-#{array[5]}" unless array[5].nil?
51
- file += "-#{array[6]}" unless array[6].nil?
52
- file += ".#{array[4]}"
53
- xml = "#{array[1]}/#{array[2]}/#{artifact}/#{array[3]}/#{meta_file}"
54
- test = "#{array[1]}/#{array[2]}/#{artifact}/#{array[3]}/#{file}"
53
+ tests.each do |key, arrays|
54
+ repo, group, artifact, root_xml = key
55
+ stub_request(:get, "#{repo}/#{group}/#{artifact}/#{meta_file}")
56
+ .to_return(status: 200, body: read_xml(root_xml), headers: {})
57
+
58
+ arrays.each do |code, version, type, tag|
59
+ path = "#{repo}/#{group}/#{artifact}/#{version}"
55
60
 
56
- xml_status = array[3].include?('SNAPSHOT') ? array[0] : 404
57
- stub_request(:get, xml)
58
- .to_return(status: xml_status, body: xml_content, headers: {})
61
+ xml_status = version.end_with?('SNAPSHOT') ? code : 404
62
+ stub_request(:get, "#{path}/#{meta_file}")
63
+ .to_return(status: xml_status, body: read_xml('inside'), headers: {})
59
64
 
60
- stub_request(:get, test)
61
- .to_return(status: array[0], body: 'OK', headers: {})
65
+ file = "#{artifact}-#{version.chomp('-SNAPSHOT')}#{tag}.#{type}"
66
+ stub_request(:get, "#{path}/#{file}")
67
+ .to_return(status: code, body: 'OK', headers: {})
68
+ end
62
69
  end
63
70
  end
64
71
  end
@@ -13,6 +13,8 @@
13
13
  # See the License for the specific language governing permissions and
14
14
  # limitations under the License.
15
15
  #
16
+ require 'simplecov'
17
+ SimpleCov.start
16
18
 
17
19
  $LOAD_PATH.unshift File.expand_path('../../lib', __FILE__)
18
20
  require 'mavencli'
@@ -41,5 +43,5 @@ Dir[files].each { |file| require file }
41
43
  def start(caller_object, subcommand = nil)
42
44
  cmd = caller_object.class.description.split(' ')
43
45
  args = [subcommand, *cmd].compact
44
- MavenCLI::CLI.start(args)
46
+ MavenCLI.start(args, true)
45
47
  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.0.0
4
+ version: 1.1.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: 2016-10-11 00:00:00.000000000 Z
12
+ date: 2017-01-12 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: bundler
@@ -81,6 +81,20 @@ dependencies:
81
81
  - - "~>"
82
82
  - !ruby/object:Gem::Version
83
83
  version: '2.1'
84
+ - !ruby/object:Gem::Dependency
85
+ name: simplecov
86
+ requirement: !ruby/object:Gem::Requirement
87
+ requirements:
88
+ - - "~>"
89
+ - !ruby/object:Gem::Version
90
+ version: '0.12'
91
+ type: :development
92
+ prerelease: false
93
+ version_requirements: !ruby/object:Gem::Requirement
94
+ requirements:
95
+ - - "~>"
96
+ - !ruby/object:Gem::Version
97
+ version: '0.12'
84
98
  - !ruby/object:Gem::Dependency
85
99
  name: thor
86
100
  requirement: !ruby/object:Gem::Requirement
@@ -123,71 +137,7 @@ dependencies:
123
137
  - - "~>"
124
138
  - !ruby/object:Gem::Version
125
139
  version: '1.1'
126
- description: |
127
- MavenCLI
128
- ========
129
-
130
- Simple maven cli tool.
131
-
132
- Installation
133
- ------------
134
-
135
- Install as a gem:
136
-
137
- $ gem install maven-cli
138
-
139
- Usage
140
- -----
141
-
142
- You can have an interactive help using:
143
-
144
- $ maven-cli help
145
-
146
- Examples
147
- --------
148
-
149
- To download a jar from maven repository (http://repo.maven.apache.org/maven2)
150
-
151
- $ maven-cli download <group> <artifact> <version>
152
-
153
- For instance: `maven-cli download com.google.guava guava 19.0`
154
-
155
- To download a jar from a non standard repository
156
-
157
- $ maven-cli download <group> <artifact> <version> -r <repository>
158
-
159
- To download a jar from maven repository and save it to file
160
-
161
- $ maven-cli download <group> <artifact> <version> -o <outfile>
162
-
163
- Contributing
164
- ------------
165
-
166
- Please read carefully [CONTRIBUTING.md](CONTRIBUTING.md) before making a merge
167
- request.
168
-
169
- License and Author
170
- ------------------
171
-
172
- - Author:: DPS Team (<dps.team@s4m.io>)
173
- - Author:: Samuel Bernard (<samuel.bernard@s4m.io>)
174
- - Author:: Richard Delaplace (<richard.delaplace@s4m.io>)
175
-
176
- ```text
177
- Copyright (c) 2016 Sam4Mobile
178
-
179
- Licensed under the Apache License, Version 2.0 (the "License");
180
- you may not use this file except in compliance with the License.
181
- You may obtain a copy of the License at
182
-
183
- http://www.apache.org/licenses/LICENSE-2.0
184
-
185
- Unless required by applicable law or agreed to in writing, software
186
- distributed under the License is distributed on an "AS IS" BASIS,
187
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
188
- See the License for the specific language governing permissions and
189
- limitations under the License.
190
- ```
140
+ description: Tool to interact with Maven repositories with CLI
191
141
  email: dps.team@s4m.io
192
142
  executables:
193
143
  - maven-cli
@@ -209,7 +159,10 @@ files:
209
159
  - lib/mavencli/downloader.rb
210
160
  - lib/mavencli/version.rb
211
161
  - maven-cli.gemspec
212
- - spec/files/maven-metadata.xml
162
+ - spec/files/inside_maven-metadata.xml
163
+ - spec/files/rel_maven-metadata.xml
164
+ - spec/files/root_maven-metadata.xml
165
+ - spec/files/snap_maven-metadata.xml
213
166
  - spec/mavencli/cli_spec.rb
214
167
  - spec/mavencli/downloader_spec.rb
215
168
  - spec/mavencli/stubs/servers_stubs.rb
@@ -227,7 +180,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
227
180
  requirements:
228
181
  - - ">="
229
182
  - !ruby/object:Gem::Version
230
- version: '0'
183
+ version: '2.0'
231
184
  required_rubygems_version: !ruby/object:Gem::Requirement
232
185
  requirements:
233
186
  - - ">="
@@ -235,7 +188,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
235
188
  version: '0'
236
189
  requirements: []
237
190
  rubyforge_project:
238
- rubygems_version: 2.5.1
191
+ rubygems_version: 2.6.8
239
192
  signing_key:
240
193
  specification_version: 4
241
194
  summary: Tool to interact with Maven repositories with CLI