nexus_cli 1.0.0 → 1.0.1

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/VERSION CHANGED
@@ -1 +1 @@
1
- 1.0.0
1
+ 1.0.1
data/data/pom.xml.erb ADDED
@@ -0,0 +1,10 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
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
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
4
+ <modelVersion>4.0.0</modelVersion>
5
+ <groupId><%= group_id %></groupId>
6
+ <artifactId><%= artifact_id %></artifactId>
7
+ <version><%= version %></version>
8
+ <packaging><%= extension %></packaging>
9
+ <description>POM was created by Sonatype Nexus</description>
10
+ </project>
@@ -1,8 +1,10 @@
1
+ require 'erb'
1
2
  require 'httpclient'
2
- require 'nokogiri'
3
- require 'yaml'
4
3
  require 'json'
5
4
  require 'jsonpath'
5
+ require 'nokogiri'
6
+ require 'tempfile'
7
+ require 'yaml'
6
8
 
7
9
  module NexusCli
8
10
  # @author Kyle Allan <kallan@riotgames.com>
@@ -24,8 +26,8 @@ module NexusCli
24
26
  # @return [HTTPClient]
25
27
  def nexus
26
28
  client = HTTPClient.new
27
- client.send_timeout = 600
28
- client.receive_timeout = 600
29
+ client.send_timeout = 6000
30
+ client.receive_timeout = 6000
29
31
  # https://github.com/nahi/httpclient/issues/63
30
32
  client.set_auth(nil, configuration['username'], configuration['password'])
31
33
  client.www_auth.basic_auth.challenge(configuration['url'])
@@ -113,9 +115,18 @@ module NexusCli
113
115
  # @return [Boolean] returns true when successful
114
116
  def push_artifact(artifact, file)
115
117
  group_id, artifact_id, version, extension = parse_artifact_string(artifact)
116
- response = nexus.post(nexus_url("service/local/artifact/maven/content"), {:hasPom => false, :g => group_id, :a => artifact_id, :v => version, :e => extension, :p => extension, :r => configuration['repository'], :file => File.open(file)})
118
+ file_name = "#{artifact_id}-#{version}.#{extension}"
119
+ put_string = "content/repositories/#{configuration['repository']}/#{group_id.gsub(".", "/")}/#{artifact_id.gsub(".", "/")}/#{version}/#{file_name}"
120
+ response = nexus.put(nexus_url(put_string), File.open(file))
121
+
117
122
  case response.status
118
123
  when 201
124
+ pom_name = "#{artifact_id}-#{version}.pom"
125
+ put_string = "content/repositories/#{configuration['repository']}/#{group_id.gsub(".", "/")}/#{artifact_id.gsub(".", "/")}/#{version}/#{pom_name}"
126
+ pom_file = generate_fake_pom(pom_name, group_id, artifact_id, version, extension)
127
+ nexus.put(nexus_url(put_string), File.open(pom_file))
128
+ delete_string = "/service/local/metadata/repositories/#{configuration['repository']}/content/#{group_id.gsub(".", "/")}/#{artifact_id.gsub(".", "/")}"
129
+ nexus.delete(nexus_url(delete_string))
119
130
  return true
120
131
  when 400
121
132
  raise BadUploadRequestException
@@ -160,8 +171,13 @@ module NexusCli
160
171
  # Searches for an artifact using the given identifier.
161
172
  #
162
173
  # @param artifact [String] the Maven identifier
174
+ # @example com.artifact:my-artifact
163
175
  #
164
176
  # @return [Array<String>] a formatted Array of results
177
+ # @example
178
+ # 1.0.0 `nexus-cli pull com.artifact:my-artifact:1.0.0:tgz`
179
+ # 2.0.0 `nexus-cli pull com.artifact:my-artifact:2.0.0:tgz`
180
+ # 3.0.0 `nexus-cli pull com.artifact:my-artifact:3.0.0:tgz`
165
181
  def search_for_artifacts(artifact)
166
182
  group_id, artifact_id = artifact.split(":")
167
183
  response = nexus.get(nexus_url("service/local/data_index"), :query => {:g => group_id, :a => artifact_id})
@@ -238,13 +254,16 @@ module NexusCli
238
254
  # @param name [String] the name of the repository to create
239
255
  # @param proxy [Boolean] true if this is a proxy repository
240
256
  # @param url [String] the url for the proxy repository to point to
257
+ # @param id [String] the id of repository
258
+ # @param policy [String] repository policy (RELEASE|SNAPSHOT)
259
+ # @param provider [String] repo provider (maven2 by default)
241
260
  #
242
261
  # @return [Boolean] returns true on success
243
- def create_repository(name, proxy, url)
262
+ def create_repository(name, proxy, url, id, policy, provider)
244
263
  json = if proxy
245
- create_proxy_repository_json(name, url)
264
+ create_proxy_repository_json(name, url, id, policy, provider)
246
265
  else
247
- create_hosted_repository_json(name)
266
+ create_hosted_repository_json(name, id, policy, provider)
248
267
  end
249
268
  response = nexus.post(nexus_url("service/local/repositories"), :body => json, :header => DEFAULT_CONTENT_TYPE_HEADER)
250
269
  case response.status
@@ -388,8 +407,8 @@ module NexusCli
388
407
  end
389
408
  end
390
409
 
391
- def create_group_repository(name)
392
- response = nexus.post(nexus_url("service/local/repo_groups"), :body => create_group_repository_json(name), :header => DEFAULT_CONTENT_TYPE_HEADER)
410
+ def create_group_repository(name, id, provider)
411
+ response = nexus.post(nexus_url("service/local/repo_groups"), :body => create_group_repository_json(name, id, provider), :header => DEFAULT_CONTENT_TYPE_HEADER)
393
412
  case response.status
394
413
  when 201
395
414
  return true
@@ -501,12 +520,16 @@ module NexusCli
501
520
  # @return [type] [description]
502
521
  def format_search_results(doc, group_id, artifact_id)
503
522
  versions = doc.xpath("//version").inject([]) {|array,node| array << "#{node.content()}"}
504
- indent_size = versions.max{|a,b| a.length <=> b.length}.size+4
505
- formated_results = ['Found Versions:']
506
- versions.inject(formated_results) do |array,version|
507
- temp_version = version + ":"
508
- array << "#{temp_version.ljust(indent_size)} `nexus-cli pull #{group_id}:#{artifact_id}:#{version}:tgz`"
509
- end
523
+ if versions.length > 0
524
+ indent_size = versions.max{|a,b| a.length <=> b.length}.size+4
525
+ formated_results = ['Found Versions:']
526
+ versions.inject(formated_results) do |array,version|
527
+ temp_version = version + ":"
528
+ array << "#{temp_version.ljust(indent_size)} `nexus-cli pull #{group_id}:#{artifact_id}:#{version}:tgz`"
529
+ end
530
+ else
531
+ formated_results = ['No Versions Found.']
532
+ end
510
533
  end
511
534
 
512
535
 
@@ -526,34 +549,34 @@ module NexusCli
526
549
  return group_id, artifact_id, version, extension
527
550
  end
528
551
 
529
- def create_hosted_repository_json(name)
530
- params = {:provider => "maven2"}
552
+ def create_hosted_repository_json(name, id, policy, provider)
553
+ params = {:provider => provider.nil? ? "maven2": provider}
531
554
  params[:providerRole] = "org.sonatype.nexus.proxy.repository.Repository"
532
555
  params[:exposed] = true
533
556
  params[:browseable] = true
534
557
  params[:indexable] = true
535
558
  params[:repoType] = "hosted"
536
- params[:repoPolicy] = "RELEASE"
559
+ params[:repoPolicy] = policy.nil? ? "RELEASE" : ["RELEASE", "SNAPSHOT"].include?(policy) ? policy : "RELEASE"
537
560
  params[:name] = name
538
- params[:id] = sanitize_for_id(name)
561
+ params[:id] = id.nil? ? sanitize_for_id(name) : sanitize_for_id(id)
539
562
  params[:format] = "maven2"
540
563
  JSON.dump(:data => params)
541
564
  end
542
565
 
543
- def create_proxy_repository_json(name, url)
544
- params = {:provider => "maven2"}
566
+ def create_proxy_repository_json(name, url, id, policy, provider)
567
+ params = {:provider => provider.nil? ? "maven2" : provider}
545
568
  params[:providerRole] = "org.sonatype.nexus.proxy.repository.Repository"
546
569
  params[:exposed] = true
547
570
  params[:browseable] = true
548
571
  params[:indexable] = true
549
572
  params[:repoType] = "proxy"
550
- params[:repoPolicy] = "RELEASE"
573
+ params[:repoPolicy] = policy.nil? ? "RELEASE" : ["RELEASE", "SNAPSHOT"].include?(policy) ? policy : "RELEASE"
551
574
  params[:checksumPolicy] = "WARN"
552
575
  params[:writePolicy] = "READ_ONLY"
553
576
  params[:downloadRemoteIndexes] = true
554
577
  params[:autoBlockActive] = false
555
578
  params[:name] = name
556
- params[:id] = sanitize_for_id(name)
579
+ params[:id] = id.nil? ? sanitize_for_id(name) : sanitize_for_id(id)
557
580
  params[:remoteStorage] = {:remoteStorageUrl => url.nil? ? "http://change-me.com/" : url}
558
581
  JSON.dump(:data => params)
559
582
  end
@@ -571,10 +594,10 @@ module NexusCli
571
594
  JSON.dump(:data => params)
572
595
  end
573
596
 
574
- def create_group_repository_json(name)
575
- params = {:id => sanitize_for_id(name)}
597
+ def create_group_repository_json(name, id, provider)
598
+ params = {:id => id.nil? ? sanitize_for_id(name) : sanitize_for_id(id)}
576
599
  params[:name] = name
577
- params[:provider] = "maven2"
600
+ params[:provider] = provider.nil? ? "maven2" : provider
578
601
  params[:exposed] = true
579
602
  JSON.dump(:data => params)
580
603
  end
@@ -600,5 +623,13 @@ module NexusCli
600
623
  params[:name] = group_repository_json["data"]["name"]
601
624
  JSON.dump(:data => params)
602
625
  end
626
+
627
+ def generate_fake_pom(pom_name, group_id, artifact_id, version, extension)
628
+ Tempfile.open(pom_name) do |file|
629
+ template_path = File.join(NexusCli.root, "data", "pom.xml.erb")
630
+ file.puts ERB.new(File.read(template_path)).result(binding)
631
+ file
632
+ end
633
+ end
603
634
  end
604
635
  end
@@ -48,7 +48,7 @@ module NexusCli
48
48
  say nexus_remote.get_artifact_info(artifact), :green
49
49
  end
50
50
 
51
- desc "search_for_artifacts", "Prints out some information about some junk."
51
+ desc "search_for_artifacts", "Searches for all the versions of a particular artifact and prints it to the screen."
52
52
  def search_for_artifacts(artifact)
53
53
  nexus_remote.search_for_artifacts(artifact).each{|output| say output, :green}
54
54
  end
@@ -121,15 +121,24 @@ module NexusCli
121
121
  say "Your Nexus global settings have been reset to their default values", :blue
122
122
  end
123
123
 
124
+ method_option :id,
125
+ :type => :string,
126
+ :desc => "The id of the repository to use."
127
+ method_option :policy,
128
+ :type => :string,
129
+ :desc => "Repo policy [RELEASE|SNAPSHOT], RELEASE by default"
130
+ method_option :provider,
131
+ :type => :string,
132
+ :desc => "Repo provider (maven2 by default)"
124
133
  method_option :proxy,
125
134
  :type => :boolean,
126
135
  :desc => "True if the new repository should be a proxy repository"
127
- method_option :url,
136
+ method_option :url,
128
137
  :type => :string,
129
138
  :desc => "The url of the actual repository for the proxy repository to use."
130
139
  desc "create_repository name", "Creates a new Repository with the provided name."
131
140
  def create_repository(name)
132
- if nexus_remote.create_repository(name, options[:proxy], options[:url])
141
+ if nexus_remote.create_repository(name, options[:proxy], options[:url], options[:id], options[:policy], options[:provider])
133
142
  say "A new Repository named #{name} has been created.", :blue
134
143
  end
135
144
  end
@@ -379,8 +388,14 @@ module NexusCli
379
388
  end
380
389
 
381
390
  desc "create_group_repository name", "Creates a new repository group with the given name."
391
+ method_option :id,
392
+ :type => :string,
393
+ :desc => "The id of the group repository to use (calculated from name by default)."
394
+ method_option :provider,
395
+ :type => :string,
396
+ :desc => "Group repo provider (maven2 by default)."
382
397
  def create_group_repository(name)
383
- if nexus_remote.create_group_repository(name)
398
+ if nexus_remote.create_group_repository(name, options[:id], options[:provider])
384
399
  say "A new group repository named #{name} has been created.", :blue
385
400
  end
386
401
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: nexus_cli
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0
4
+ version: 1.0.1
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-10-30 00:00:00.000000000 Z
12
+ date: 2012-11-08 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: thor
@@ -218,6 +218,7 @@ files:
218
218
  - Rakefile
219
219
  - VERSION
220
220
  - bin/nexus-cli
221
+ - data/pom.xml.erb
221
222
  - features/nexus_oss.feature
222
223
  - features/step_definitions/cli_steps.rb
223
224
  - features/support/env.rb
@@ -253,7 +254,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
253
254
  version: '0'
254
255
  segments:
255
256
  - 0
256
- hash: -2249648047035309885
257
+ hash: -3948743484323042691
257
258
  required_rubygems_version: !ruby/object:Gem::Requirement
258
259
  none: false
259
260
  requirements:
@@ -262,7 +263,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
262
263
  version: '0'
263
264
  segments:
264
265
  - 0
265
- hash: -2249648047035309885
266
+ hash: -3948743484323042691
266
267
  requirements: []
267
268
  rubyforge_project:
268
269
  rubygems_version: 1.8.21