nexus_cli 3.0.0 → 4.0.0.beta1
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.
- data/CHANGELOG.md +4 -0
- data/README.md +4 -4
- data/VERSION +1 -1
- data/data/pom.xml.erb +8 -5
- data/features/nexus_oss.feature +15 -15
- data/features/pro/nexus_custom_metadata.feature +18 -18
- data/lib/nexus_cli/artifact.rb +46 -0
- data/lib/nexus_cli/base_remote.rb +2 -18
- data/lib/nexus_cli/configuration.rb +56 -22
- data/lib/nexus_cli/errors.rb +3 -3
- data/lib/nexus_cli/mixins/artifact_actions.rb +41 -38
- data/lib/nexus_cli/mixins/pro/custom_metadata_actions.rb +23 -22
- data/lib/nexus_cli/n3_metadata.rb +2 -2
- data/lib/nexus_cli/remote_factory.rb +8 -1
- data/lib/nexus_cli/tasks.rb +29 -29
- data/lib/nexus_cli.rb +3 -1
- data/nexus_cli.gemspec +2 -0
- data/spec/fixtures/metadata_search.xml +10 -0
- data/spec/spec_helper.rb +8 -0
- data/spec/unit/nexus_cli/artifact_spec.rb +82 -0
- data/spec/unit/nexus_cli/configuration_spec.rb +116 -15
- data/spec/unit/nexus_cli/mixins/pro/custom_metadata_actions_spec.rb +21 -0
- data/spec/unit/nexus_cli/oss_remote_spec.rb +9 -4
- data/spec/unit/nexus_cli/pro_remote_spec.rb +29 -27
- data/spec/unit/nexus_cli/remote_factory_spec.rb +42 -0
- metadata +49 -10
data/CHANGELOG.md
ADDED
data/README.md
CHANGED
@@ -9,7 +9,7 @@ A CLI wrapper around Sonatype Nexus REST calls.
|
|
9
9
|
|
10
10
|
# Installation
|
11
11
|
|
12
|
-
1. Install the Gem
|
12
|
+
1. Install the Gem - `gem install nexus_cli`
|
13
13
|
2. Create a file in your user's home directory named `.nexus_cli`
|
14
14
|
3. Give the file the following information:
|
15
15
|
|
@@ -22,18 +22,18 @@ password: "password"
|
|
22
22
|
|
23
23
|
# Usage
|
24
24
|
|
25
|
-
There are two calls that can be made. push\_artifact and pull\_artifact. Both calls will push or pull artifacts from Nexus using the Maven-
|
25
|
+
There are two calls that can be made. push\_artifact and pull\_artifact. Both calls will push or pull artifacts from Nexus using the Maven Co-ordinates syntax: `groupId:artifactId:version` or `groupId:artifactId:extension:version` or `groupId:artifactId:extension:classifier:version`
|
26
26
|
|
27
27
|
## Pull Artifact Example
|
28
28
|
|
29
29
|
```
|
30
|
-
nexus-cli pull_artifact com.mycompany.artifacts:myartifact:1.0.0
|
30
|
+
nexus-cli pull_artifact com.mycompany.artifacts:myartifact:tgz:1.0.0
|
31
31
|
```
|
32
32
|
|
33
33
|
## Push Artifact Example
|
34
34
|
|
35
35
|
```
|
36
|
-
nexus-cli push_artifact com.mycompany.artifacts:myartifact:1.0.0
|
36
|
+
nexus-cli push_artifact com.mycompany.artifacts:myartifact:tgz:1.0.0 ~/path/to/file/to/push/myartifact.tgz
|
37
37
|
```
|
38
38
|
|
39
39
|
# License and Author
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
|
1
|
+
4.0.0.beta1
|
data/data/pom.xml.erb
CHANGED
@@ -2,9 +2,12 @@
|
|
2
2
|
<project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd" xmlns="http://maven.apache.org/POM/4.0.0"
|
3
3
|
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
|
4
4
|
<modelVersion>4.0.0</modelVersion>
|
5
|
-
<groupId><%= group_id %></groupId>
|
6
|
-
<artifactId><%= artifact_id %></artifactId>
|
7
|
-
<version><%= version %></version>
|
8
|
-
|
5
|
+
<groupId><%= artifact.group_id %></groupId>
|
6
|
+
<artifactId><%= artifact.artifact_id %></artifactId>
|
7
|
+
<version><%= artifact.version %></version>
|
8
|
+
<% unless artifact.classifier.nil? %>
|
9
|
+
<classifier><%= artifact.classifier %></classifier>
|
10
|
+
<% end %>
|
11
|
+
<packaging><%= artifact.extension %></packaging>
|
9
12
|
<description>POM was created by Sonatype Nexus</description>
|
10
|
-
</project>
|
13
|
+
</project>
|
data/features/nexus_oss.feature
CHANGED
@@ -12,34 +12,34 @@ Feature: Use the Nexus CLI
|
|
12
12
|
|
13
13
|
@push
|
14
14
|
Scenario: Push an Artifact
|
15
|
-
When I push an artifact with the GAV of "com.test:mytest:1.0.0
|
15
|
+
When I push an artifact with the GAV of "com.test:mytest:tgz:1.0.0"
|
16
16
|
Then the output should contain:
|
17
17
|
"""
|
18
|
-
Artifact com.test:mytest:1.0.0
|
18
|
+
Artifact com.test:mytest:tgz:1.0.0 has been successfully pushed to Nexus.
|
19
19
|
"""
|
20
20
|
And the exit status should be 0
|
21
21
|
|
22
22
|
@pull
|
23
23
|
Scenario: Pull an artifact
|
24
|
-
When I call the nexus "pull com.test:mytest:1.0.0
|
24
|
+
When I call the nexus "pull com.test:mytest:tgz:1.0.0" command
|
25
25
|
Then the output should contain:
|
26
26
|
"""
|
27
|
-
Artifact has been
|
27
|
+
Artifact has been retrieved and can be found at path:
|
28
28
|
"""
|
29
29
|
And the exit status should be 0
|
30
30
|
|
31
31
|
Scenario: Pull the LATEST of an artifact
|
32
|
-
When I pull an artifact with the GAV of "com.test:mytest:latest
|
32
|
+
When I pull an artifact with the GAV of "com.test:mytest:tgz:latest" to a temp directory
|
33
33
|
Then I should have a copy of the "mytest-1.0.0.tgz" artifact in a temp directory
|
34
34
|
And the exit status should be 0
|
35
35
|
|
36
36
|
Scenario: Pull an artifact to a specific place
|
37
|
-
When I pull an artifact with the GAV of "com.test:mytest:1.0.0
|
37
|
+
When I pull an artifact with the GAV of "com.test:mytest:tgz:1.0.0" to a temp directory
|
38
38
|
Then I should have a copy of the "mytest-1.0.0.tgz" artifact in a temp directory
|
39
39
|
And the exit status should be 0
|
40
40
|
|
41
41
|
Scenario: Get an artifact's info
|
42
|
-
When I call the nexus "info com.test:mytest:1.0.0
|
42
|
+
When I call the nexus "info com.test:mytest:tgz:1.0.0" command
|
43
43
|
Then the output should contain:
|
44
44
|
"""
|
45
45
|
<groupId>com.test</groupId>
|
@@ -51,23 +51,23 @@ Feature: Use the Nexus CLI
|
|
51
51
|
Then the output should contain:
|
52
52
|
"""
|
53
53
|
Found Versions:
|
54
|
-
1.0.0: `nexus-cli pull com.test:mytest:1.0.0
|
54
|
+
1.0.0: `nexus-cli pull com.test:mytest:tgz:1.0.0`
|
55
55
|
"""
|
56
56
|
And the exit status should be 0
|
57
57
|
|
58
58
|
@transfer
|
59
59
|
Scenario: Transfer an artifact between repositories
|
60
|
-
When I call the nexus "transfer com.test:mytest:1.0.0
|
60
|
+
When I call the nexus "transfer com.test:mytest:tgz:1.0.0 releases thirdparty" command
|
61
61
|
Then the output should contain:
|
62
62
|
"""
|
63
|
-
The artifact com.test:mytest:1.0.0
|
63
|
+
The artifact com.test:mytest:tgz:1.0.0 has been transferred from releases to thirdparty.
|
64
64
|
"""
|
65
65
|
And the exit status should be 0
|
66
66
|
|
67
67
|
@delete
|
68
68
|
Scenario: Attempt to delete an artifact
|
69
|
-
When I delete an artifact with the GAV of "com.test:mytest:1.0.0
|
70
|
-
And I call the nexus "info com.test:mytest:1.0.0
|
69
|
+
When I delete an artifact with the GAV of "com.test:mytest:tgz:1.0.0"
|
70
|
+
And I call the nexus "info com.test:mytest:tgz:1.0.0" command
|
71
71
|
Then the output should contain:
|
72
72
|
"""
|
73
73
|
The artifact you requested information for could not be found. Please ensure it exists inside the Nexus.
|
@@ -76,8 +76,8 @@ Feature: Use the Nexus CLI
|
|
76
76
|
|
77
77
|
@delete
|
78
78
|
Scenario: Attempt to delete another artifact
|
79
|
-
When I delete an artifact with the GAV of "com.test:mytest:1.0.0
|
80
|
-
And I call the nexus "info com.test:mytest:1.0.0
|
79
|
+
When I delete an artifact with the GAV of "com.test:mytest:tgz:1.0.0" from the "thirdparty" repository
|
80
|
+
And I call the nexus "info com.test:mytest:tgz:1.0.0" command overriding "repository:thirdparty"
|
81
81
|
Then the output should contain:
|
82
82
|
"""
|
83
83
|
The artifact you requested information for could not be found. Please ensure it exists inside the Nexus.
|
@@ -249,4 +249,4 @@ Feature: Use the Nexus CLI
|
|
249
249
|
"""
|
250
250
|
\"id\":\"cucumber_group\"
|
251
251
|
"""
|
252
|
-
And the exit status should be 114
|
252
|
+
And the exit status should be 114
|
@@ -3,39 +3,39 @@ Feature: Use the Nexus Pro CLI
|
|
3
3
|
I need commands to get, update, search, and delete Nexus artifact custom metadata
|
4
4
|
|
5
5
|
Scenario: Push an artifact
|
6
|
-
When I push an artifact with the GAV of "com.test:myprotest:1.0.0
|
6
|
+
When I push an artifact with the GAV of "com.test:myprotest:tgz:1.0.0"
|
7
7
|
Then the output should contain:
|
8
8
|
"""
|
9
|
-
Artifact com.test:myprotest:1.0.0
|
9
|
+
Artifact com.test:myprotest:tgz:1.0.0 has been successfully pushed to Nexus.
|
10
10
|
"""
|
11
11
|
And the exit status should be 0
|
12
12
|
|
13
13
|
Scenario: Update an artifact's custom metadata
|
14
|
-
When I call the nexus "update_artifact_custom_info com.test:myprotest:1.0.0
|
14
|
+
When I call the nexus "update_artifact_custom_info com.test:myprotest:tgz:1.0.0 somekey:somevalue" command
|
15
15
|
Then the output should contain:
|
16
16
|
"""
|
17
|
-
Custom metadata for artifact com.test:myprotest:1.0.0
|
17
|
+
Custom metadata for artifact com.test:myprotest:tgz:1.0.0 has been successfully pushed to Nexus.
|
18
18
|
"""
|
19
19
|
And the exit status should be 0
|
20
20
|
|
21
21
|
Scenario: Update an artifact's custom metadata with multiple parameters
|
22
|
-
When I call the nexus "update_artifact_custom_info com.test:myprotest:1.0.0
|
22
|
+
When I call the nexus "update_artifact_custom_info com.test:myprotest:tgz:1.0.0 somekey:somevalue_1! \"someotherkey:some other value\" tempkey:tempvalue" command
|
23
23
|
Then the output should contain:
|
24
24
|
"""
|
25
|
-
Custom metadata for artifact com.test:myprotest:1.0.0
|
25
|
+
Custom metadata for artifact com.test:myprotest:tgz:1.0.0 has been successfully pushed to Nexus.
|
26
26
|
"""
|
27
27
|
And the exit status should be 0
|
28
28
|
|
29
29
|
Scenario: Update an artifact's custom metadata and remove a key
|
30
|
-
When I call the nexus "update_artifact_custom_info com.test:myprotest:1.0.0
|
30
|
+
When I call the nexus "update_artifact_custom_info com.test:myprotest:tgz:1.0.0 tempkey:" command
|
31
31
|
Then the output should contain:
|
32
32
|
"""
|
33
|
-
Custom metadata for artifact com.test:myprotest:1.0.0
|
33
|
+
Custom metadata for artifact com.test:myprotest:tgz:1.0.0 has been successfully pushed to Nexus.
|
34
34
|
"""
|
35
35
|
And the exit status should be 0
|
36
36
|
|
37
37
|
Scenario: Get an artifact's custom metadata
|
38
|
-
When I call the nexus "custom com.test:myprotest:1.0.0
|
38
|
+
When I call the nexus "custom com.test:myprotest:tgz:1.0.0" command
|
39
39
|
Then the output should contain:
|
40
40
|
"""
|
41
41
|
<somekey>somevalue_1!</somekey>
|
@@ -79,8 +79,8 @@ Feature: Use the Nexus Pro CLI
|
|
79
79
|
And the exit status should be 0
|
80
80
|
|
81
81
|
Scenario: Transfer an artifact and ensure its metadata is also copied
|
82
|
-
When I call the nexus "transfer com.test:myprotest:1.0.0
|
83
|
-
And I call the nexus "custom com.test:myprotest:1.0.0
|
82
|
+
When I call the nexus "transfer com.test:myprotest:tgz:1.0.0 releases thirdparty" command
|
83
|
+
And I call the nexus "custom com.test:myprotest:tgz:1.0.0" command overriding "repository:thirdparty"
|
84
84
|
Then the output should contain:
|
85
85
|
"""
|
86
86
|
<somekey>somevalue_1!</somekey>
|
@@ -88,17 +88,17 @@ Feature: Use the Nexus Pro CLI
|
|
88
88
|
And the exit status should be 0
|
89
89
|
|
90
90
|
Scenario: Clear an artifact's custom metadata
|
91
|
-
When I call the nexus "clear_artifact_custom_info com.test:myprotest:1.0.0
|
91
|
+
When I call the nexus "clear_artifact_custom_info com.test:myprotest:tgz:1.0.0" command
|
92
92
|
Then the output should contain:
|
93
93
|
"""
|
94
|
-
Custom metadata for artifact com.test:myprotest:1.0.0
|
94
|
+
Custom metadata for artifact com.test:myprotest:tgz:1.0.0 has been successfully cleared.
|
95
95
|
"""
|
96
96
|
And the exit status should be 0
|
97
97
|
|
98
98
|
@delete
|
99
99
|
Scenario: Attempt to delete an artifact
|
100
|
-
When I delete an artifact with the GAV of "com.test:myprotest:1.0.0
|
101
|
-
And I call the nexus "info com.test:myprotest:1.0.0
|
100
|
+
When I delete an artifact with the GAV of "com.test:myprotest:tgz:1.0.0"
|
101
|
+
And I call the nexus "info com.test:myprotest:tgz:1.0.0" command
|
102
102
|
Then the output should contain:
|
103
103
|
"""
|
104
104
|
The artifact you requested information for could not be found. Please ensure it exists inside the Nexus.
|
@@ -107,10 +107,10 @@ Feature: Use the Nexus Pro CLI
|
|
107
107
|
|
108
108
|
@delete
|
109
109
|
Scenario: Attempt to delete another artifact
|
110
|
-
When I delete an artifact with the GAV of "com.test:myprotest:1.0.0
|
111
|
-
And I call the nexus "info com.test:myprotest:1.0.0
|
110
|
+
When I delete an artifact with the GAV of "com.test:myprotest:tgz:1.0.0" from the "thirdparty" repository
|
111
|
+
And I call the nexus "info com.test:myprotest:tgz:1.0.0" command overriding "repository:thirdparty"
|
112
112
|
Then the output should contain:
|
113
113
|
"""
|
114
114
|
The artifact you requested information for could not be found. Please ensure it exists inside the Nexus.
|
115
115
|
"""
|
116
|
-
And the exit status should be 101
|
116
|
+
And the exit status should be 101
|
@@ -0,0 +1,46 @@
|
|
1
|
+
module NexusCli
|
2
|
+
class Artifact
|
3
|
+
attr_reader :group_id
|
4
|
+
attr_reader :artifact_id
|
5
|
+
attr_reader :extension
|
6
|
+
attr_reader :classifier
|
7
|
+
attr_reader :version
|
8
|
+
attr_reader :file_name
|
9
|
+
|
10
|
+
# Constructs an artifact object from Maven co-ordinates
|
11
|
+
# See http://maven.apache.org/pom.html#Maven_coordinatess
|
12
|
+
# for more information on maven coordinatess
|
13
|
+
#
|
14
|
+
# @param coordinates [String] the Maven identifier
|
15
|
+
#
|
16
|
+
# @return [Array<String>] an Array with four elements
|
17
|
+
def initialize(coordinates)
|
18
|
+
@group_id, @artifact_id, @extension, @classifier, @version = parse_coordinates(coordinates)
|
19
|
+
|
20
|
+
if @classifier.nil?
|
21
|
+
@file_name = "#{@artifact_id}-#{@version}.#{@extension}"
|
22
|
+
else
|
23
|
+
@file_name = "#{@artifact_id}-#{@version}-#{@classifier}.#{@extension}"
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
private
|
28
|
+
|
29
|
+
def parse_coordinates(coordinates)
|
30
|
+
split_coordinates = coordinates.split(":")
|
31
|
+
if(split_coordinates.size < 3 or split_coordinates.size > 5)
|
32
|
+
raise ArtifactMalformedException
|
33
|
+
end
|
34
|
+
|
35
|
+
group_id = split_coordinates[0]
|
36
|
+
artifact_id = split_coordinates[1]
|
37
|
+
extension = split_coordinates.size > 3 ? split_coordinates[2] : "jar"
|
38
|
+
classifier = split_coordinates.size > 4 ? split_coordinates[3] : nil
|
39
|
+
version = split_coordinates[-1]
|
40
|
+
|
41
|
+
version.upcase! if version == "latest"
|
42
|
+
|
43
|
+
return group_id, artifact_id, extension, classifier, version
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
@@ -9,24 +9,8 @@ module NexusCli
|
|
9
9
|
# @param [Hash] overrides
|
10
10
|
# @param [Boolean] ssl_verify
|
11
11
|
def initialize(overrides, ssl_verify=true)
|
12
|
-
@configuration = Configuration
|
12
|
+
@configuration = overrides ? Configuration.from_overrides(overrides) : Configuration.from_file
|
13
13
|
@connection = Connection.new(configuration, ssl_verify)
|
14
14
|
end
|
15
|
-
|
16
|
-
# Parses a given artifact string into its
|
17
|
-
# four, distinct, Maven pieces.
|
18
|
-
#
|
19
|
-
# @param artifact [String] the Maven identifier
|
20
|
-
#
|
21
|
-
# @return [Array<String>] an Array with four elements
|
22
|
-
def parse_artifact_string(artifact)
|
23
|
-
split_artifact = artifact.split(":")
|
24
|
-
if(split_artifact.size < 4)
|
25
|
-
raise ArtifactMalformedException
|
26
|
-
end
|
27
|
-
group_id, artifact_id, version, extension = split_artifact
|
28
|
-
version.upcase! if version.casecmp("latest")
|
29
|
-
return group_id, artifact_id, version, extension
|
30
|
-
end
|
31
15
|
end
|
32
|
-
end
|
16
|
+
end
|
@@ -1,44 +1,78 @@
|
|
1
1
|
require 'extlib'
|
2
|
+
require 'chozo'
|
2
3
|
|
3
4
|
module NexusCli
|
4
|
-
|
5
|
+
class Configuration
|
5
6
|
DEFAULT_FILE = "~/.nexus_cli".freeze
|
6
7
|
|
7
8
|
class << self
|
8
|
-
attr_writer :path
|
9
|
-
|
10
9
|
# The filepath to the nexus cli configuration file
|
11
10
|
#
|
12
11
|
# @return [String]
|
13
|
-
def
|
14
|
-
|
12
|
+
def file_path
|
13
|
+
File.expand_path(ENV['NEXUS_CONFIG'] || File.expand_path(DEFAULT_FILE))
|
15
14
|
end
|
16
15
|
|
16
|
+
# Creates a new instance of the Configuration object based on some overrides
|
17
|
+
#
|
17
18
|
# @param [Hash] overrides
|
18
19
|
#
|
19
|
-
# @return [
|
20
|
-
def
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
end
|
26
|
-
|
27
|
-
unless overrides.nil? || overrides.empty?
|
28
|
-
overrides.each { |key, value| config[key] = value }
|
29
|
-
end
|
20
|
+
# @return [NexusCli::Configuration]
|
21
|
+
def from_overrides(overrides)
|
22
|
+
raise MissingSettingsFileException unless overrides
|
23
|
+
overrides = overrides.with_indifferent_access
|
24
|
+
new(overrides)
|
25
|
+
end
|
30
26
|
|
31
|
-
|
27
|
+
# Creates a new instance of the Configuration object from the config file
|
28
|
+
#
|
29
|
+
#
|
30
|
+
# @return [NexusCli::Configuration]
|
31
|
+
def from_file
|
32
|
+
config = YAML.load_file(file_path)
|
33
|
+
raise MissingSettingsFileException unless config
|
32
34
|
|
33
|
-
config
|
34
|
-
config
|
35
|
+
config = config.with_indifferent_access
|
36
|
+
new(config)
|
35
37
|
end
|
36
38
|
|
37
|
-
|
38
|
-
|
39
|
-
|
39
|
+
# Validates an instance of the Configuration object and raises when there
|
40
|
+
# is an error with it
|
41
|
+
#
|
42
|
+
# @param config [NexusCli::Configuration]
|
43
|
+
#
|
44
|
+
# @raise [NexusCli::InvalidSettingsException]
|
45
|
+
def validate!(config)
|
46
|
+
unless config.valid?
|
47
|
+
raise InvalidSettingsException.new(config.errors)
|
40
48
|
end
|
41
49
|
end
|
42
50
|
end
|
51
|
+
|
52
|
+
include Chozo::VariaModel
|
53
|
+
|
54
|
+
attribute :url,
|
55
|
+
type: String,
|
56
|
+
required: true
|
57
|
+
|
58
|
+
attribute :repository,
|
59
|
+
type: String,
|
60
|
+
required: true,
|
61
|
+
coerce: lambda { |m|
|
62
|
+
m = m.is_a?(String) ? m.gsub(' ', '_').downcase : m
|
63
|
+
}
|
64
|
+
|
65
|
+
attribute :username,
|
66
|
+
type: String,
|
67
|
+
required: true
|
68
|
+
|
69
|
+
attribute :password,
|
70
|
+
type: String,
|
71
|
+
required: true
|
72
|
+
|
73
|
+
def initialize(options)
|
74
|
+
mass_assign(options)
|
75
|
+
self.repository = options[:repository]
|
76
|
+
end
|
43
77
|
end
|
44
78
|
end
|
data/lib/nexus_cli/errors.rb
CHANGED
@@ -24,12 +24,12 @@ module NexusCli
|
|
24
24
|
end
|
25
25
|
|
26
26
|
class InvalidSettingsException < NexusCliError
|
27
|
-
def initialize(
|
28
|
-
@
|
27
|
+
def initialize(errors)
|
28
|
+
@errors = errors
|
29
29
|
end
|
30
30
|
|
31
31
|
def message
|
32
|
-
"
|
32
|
+
"Your configuration has an error: #{@errors}"
|
33
33
|
end
|
34
34
|
status_code(102)
|
35
35
|
end
|
@@ -5,20 +5,22 @@ module NexusCli
|
|
5
5
|
# @author Kyle Allan <kallan@riotgames.com>
|
6
6
|
module ArtifactActions
|
7
7
|
|
8
|
-
# Retrieves a file from the Nexus server using the given [String]
|
9
|
-
#
|
8
|
+
# Retrieves a file from the Nexus server using the given [String]
|
9
|
+
# coordinates. Optionally provide a destination [String].
|
10
10
|
#
|
11
|
-
# @param [String]
|
11
|
+
# @param [String] coordinates
|
12
12
|
# @param [String] destination
|
13
13
|
#
|
14
14
|
# @return [Hash] Some information about the artifact that was pulled.
|
15
|
-
def pull_artifact(
|
16
|
-
|
17
|
-
version = REXML::Document.new(get_artifact_info(
|
15
|
+
def pull_artifact(coordinates, destination=nil)
|
16
|
+
artifact = Artifact.new(coordinates)
|
17
|
+
version = REXML::Document.new(get_artifact_info(coordinates)).elements["//version"].text if artifact.version.casecmp("latest")
|
18
18
|
|
19
|
-
file_name =
|
19
|
+
file_name = artifact.file_name
|
20
20
|
destination = File.join(File.expand_path(destination || "."), file_name)
|
21
|
-
|
21
|
+
query = {:g => artifact.group_id, :a => artifact.artifact_id, :e => artifact.extension, :v => artifact.version, :r => configuration['repository']}
|
22
|
+
query.merge!({:c => artifact.classifier}) unless artifact.classifier.nil?
|
23
|
+
response = nexus.get(nexus_url("service/local/artifact/maven/redirect"), :query => query)
|
22
24
|
case response.status
|
23
25
|
when 301, 307
|
24
26
|
# Follow redirect and stream in chunks.
|
@@ -43,23 +45,22 @@ module NexusCli
|
|
43
45
|
# Pushes the given [file] to the Nexus server
|
44
46
|
# under the given [artifact] identifier.
|
45
47
|
#
|
46
|
-
# @param
|
48
|
+
# @param coordinates [String] the Maven identifier
|
47
49
|
# @param file [type] the path to the file
|
48
50
|
#
|
49
51
|
# @return [Boolean] returns true when successful
|
50
|
-
def push_artifact(
|
51
|
-
|
52
|
-
|
53
|
-
put_string = "content/repositories/#{configuration['repository']}/#{group_id.gsub(".", "/")}/#{artifact_id.gsub(".", "/")}/#{version}/#{file_name}"
|
52
|
+
def push_artifact(coordinates, file)
|
53
|
+
artifact = Artifact.new(coordinates)
|
54
|
+
put_string = "content/repositories/#{configuration['repository']}/#{artifact.group_id.gsub(".", "/")}/#{artifact.artifact_id.gsub(".", "/")}/#{artifact.version}/#{artifact.file_name}"
|
54
55
|
response = nexus.put(nexus_url(put_string), File.open(file))
|
55
56
|
|
56
57
|
case response.status
|
57
58
|
when 201
|
58
|
-
pom_name = "#{artifact_id}-#{version}.pom"
|
59
|
-
put_string = "content/repositories/#{configuration['repository']}/#{group_id.gsub(".", "/")}/#{artifact_id.gsub(".", "/")}/#{version}/#{pom_name}"
|
60
|
-
pom_file = generate_fake_pom(pom_name,
|
59
|
+
pom_name = "#{artifact.artifact_id}-#{artifact.version}.pom"
|
60
|
+
put_string = "content/repositories/#{configuration['repository']}/#{artifact.group_id.gsub(".", "/")}/#{artifact.artifact_id.gsub(".", "/")}/#{artifact.version}/#{pom_name}"
|
61
|
+
pom_file = generate_fake_pom(pom_name, artifact)
|
61
62
|
nexus.put(nexus_url(put_string), File.open(pom_file))
|
62
|
-
delete_string = "/service/local/metadata/repositories/#{configuration['repository']}/content/#{group_id.gsub(".", "/")}/#{artifact_id.gsub(".", "/")}"
|
63
|
+
delete_string = "/service/local/metadata/repositories/#{configuration['repository']}/content/#{artifact.group_id.gsub(".", "/")}/#{artifact.artifact_id.gsub(".", "/")}"
|
63
64
|
nexus.delete(nexus_url(delete_string))
|
64
65
|
return true
|
65
66
|
when 400
|
@@ -75,9 +76,9 @@ module NexusCli
|
|
75
76
|
end
|
76
77
|
end
|
77
78
|
|
78
|
-
def delete_artifact(
|
79
|
-
|
80
|
-
response = nexus.delete(nexus_url("content/repositories/#{configuration['repository']}/#{group_id.gsub(".", "/")}/#{artifact_id.gsub(".", "/")}/#{version}"))
|
79
|
+
def delete_artifact(coordinates)
|
80
|
+
artifact = Artifact.new(coordinates)
|
81
|
+
response = nexus.delete(nexus_url("content/repositories/#{configuration['repository']}/#{artifact.group_id.gsub(".", "/")}/#{artifact.artifact_id.gsub(".", "/")}/#{artifact.version}"))
|
81
82
|
case response.status
|
82
83
|
when 204
|
83
84
|
return true
|
@@ -90,12 +91,14 @@ module NexusCli
|
|
90
91
|
# Retrieves information about the given [artifact] and returns
|
91
92
|
# it in as a [String] of XML.
|
92
93
|
#
|
93
|
-
# @param
|
94
|
+
# @param coordinates [String] the Maven identifier
|
94
95
|
#
|
95
96
|
# @return [String] A string of XML data about the desired artifact
|
96
|
-
def get_artifact_info(
|
97
|
-
|
98
|
-
|
97
|
+
def get_artifact_info(coordinates)
|
98
|
+
artifact = Artifact.new(coordinates)
|
99
|
+
query = {:g => artifact.group_id, :a => artifact.artifact_id, :e => artifact.extension, :v => artifact.version, :r => configuration['repository']}
|
100
|
+
query.merge!({:c => artifact.classifier}) unless artifact.classifier.nil?
|
101
|
+
response = nexus.get(nexus_url("service/local/artifact/maven/resolve"), query)
|
99
102
|
case response.status
|
100
103
|
when 200
|
101
104
|
return response.content
|
@@ -111,16 +114,16 @@ module NexusCli
|
|
111
114
|
|
112
115
|
# Searches for an artifact using the given identifier.
|
113
116
|
#
|
114
|
-
# @param
|
117
|
+
# @param coordinates [String] the Maven identifier
|
115
118
|
# @example com.artifact:my-artifact
|
116
119
|
#
|
117
120
|
# @return [Array<String>] a formatted Array of results
|
118
121
|
# @example
|
119
|
-
# 1.0.0 `nexus-cli pull com.artifact:my-artifact:1.0.0
|
120
|
-
# 2.0.0 `nexus-cli pull com.artifact:my-artifact:2.0.0
|
121
|
-
# 3.0.0 `nexus-cli pull com.artifact:my-artifact:3.0.0
|
122
|
-
def search_for_artifacts(
|
123
|
-
group_id, artifact_id =
|
122
|
+
# 1.0.0 `nexus-cli pull com.artifact:my-artifact:tgz:1.0.0`
|
123
|
+
# 2.0.0 `nexus-cli pull com.artifact:my-artifact:tgz:2.0.0`
|
124
|
+
# 3.0.0 `nexus-cli pull com.artifact:my-artifact:tgz:3.0.0`
|
125
|
+
def search_for_artifacts(coordinates)
|
126
|
+
group_id, artifact_id = coordinates.split(":")
|
124
127
|
response = nexus.get(nexus_url("service/local/data_index"), :query => {:g => group_id, :a => artifact_id})
|
125
128
|
case response.status
|
126
129
|
when 200
|
@@ -131,8 +134,8 @@ module NexusCli
|
|
131
134
|
end
|
132
135
|
end
|
133
136
|
|
134
|
-
def transfer_artifact(
|
135
|
-
do_transfer_artifact(
|
137
|
+
def transfer_artifact(coordinates, from_repository, to_repository)
|
138
|
+
do_transfer_artifact(coordinates, from_repository, to_repository)
|
136
139
|
end
|
137
140
|
|
138
141
|
private
|
@@ -164,21 +167,21 @@ module NexusCli
|
|
164
167
|
# Transfers an artifact from one repository
|
165
168
|
# to another. Sometimes called a `promotion`
|
166
169
|
#
|
167
|
-
# @param
|
170
|
+
# @param coordinates [String] a Maven identifier
|
168
171
|
# @param from_repository [String] the name of the from repository
|
169
172
|
# @param to_repository [String] the name of the to repository
|
170
173
|
#
|
171
174
|
# @return [Boolean] returns true when successful
|
172
|
-
def do_transfer_artifact(
|
175
|
+
def do_transfer_artifact(coordinates, from_repository, to_repository)
|
173
176
|
Dir.mktmpdir do |temp_dir|
|
174
177
|
configuration["repository"] = sanitize_for_id(from_repository)
|
175
|
-
artifact_file = pull_artifact(
|
178
|
+
artifact_file = pull_artifact(coordinates, temp_dir)
|
176
179
|
configuration["repository"] = sanitize_for_id(to_repository)
|
177
|
-
push_artifact(
|
180
|
+
push_artifact(coordinates, artifact_file[:file_path])
|
178
181
|
end
|
179
182
|
end
|
180
183
|
|
181
|
-
def generate_fake_pom(pom_name,
|
184
|
+
def generate_fake_pom(pom_name, artifact)
|
182
185
|
Tempfile.open(pom_name) do |file|
|
183
186
|
template_path = File.join(NexusCli.root, "data", "pom.xml.erb")
|
184
187
|
file.puts ERB.new(File.read(template_path)).result(binding)
|
@@ -186,4 +189,4 @@ module NexusCli
|
|
186
189
|
end
|
187
190
|
end
|
188
191
|
end
|
189
|
-
end
|
192
|
+
end
|