Class: MavenCentralPublishTool
- Inherits:
-
Object
- Object
- MavenCentralPublishTool
- Defined in:
- lib/mcrt.rb
Instance Attribute Summary collapse
Class Method Summary collapse
Instance Method Summary collapse
- #close_repository(repository_id, description) ⇒ Object
- #drop_repository(repository_id, description) ⇒ Object
- #get_staging_repositories(profile_name) ⇒ Object
- #release_sole_auto_staging(profile_name) ⇒ Object
Instance Attribute Details
#password ⇒ Object
39 40 41 |
# File 'lib/mcrt.rb', line 39 def password @password || (raise 'Password not yet specified') end |
#user_agent ⇒ Object
45 46 47 |
# File 'lib/mcrt.rb', line 45 def user_agent @user_agent || "Ruby-#{RUBY_VERSION}" end |
#username ⇒ Object
33 34 35 |
# File 'lib/mcrt.rb', line 33 def username @username || (raise 'Username not yet specified') end |
Class Method Details
.buildr_release(project, profile_name, username, password) ⇒ Object
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/mcrt.rb', line 7 def self.buildr_release(project, profile_name, username, password) release_to_url = Buildr.repositories.release_to[:url] release_to_username = Buildr.repositories.release_to[:username] release_to_password = Buildr.repositories.release_to[:password] begin Buildr.repositories.release_to[:url] = 'https://oss.sonatype.org/service/local/staging/deploy/maven2' Buildr.repositories.release_to[:username] = username Buildr.repositories.release_to[:password] = password project.task(':upload').invoke r = MavenCentralPublishTool.new r.username = username r.password = password r.user_agent = "Buildr-#{Buildr::VERSION}" r.release_sole_auto_staging(profile_name) ensure Buildr.repositories.release_to[:url] = release_to_url Buildr.repositories.release_to[:username] = release_to_username Buildr.repositories.release_to[:password] = release_to_password end end |
Instance Method Details
#close_repository(repository_id, description) ⇒ Object
60 61 62 63 |
# File 'lib/mcrt.rb', line 60 def close_repository(repository_id, description) post_request('https://oss.sonatype.org/service/local/staging/bulk/close', JSON.pretty_generate('data' => { 'description' => description, 'stagedRepositoryIds' => [repository_id] })) end |
#drop_repository(repository_id, description) ⇒ Object
65 66 67 68 |
# File 'lib/mcrt.rb', line 65 def drop_repository(repository_id, description) post_request('https://oss.sonatype.org/service/local/staging/bulk/drop', JSON.pretty_generate('data' => { 'description' => description, 'stagedRepositoryIds' => [repository_id] })) end |
#get_staging_repositories(profile_name) ⇒ Object
49 50 51 52 53 54 55 56 57 58 |
# File 'lib/mcrt.rb', line 49 def get_staging_repositories(profile_name) result = get_request('https://oss.sonatype.org/service/local/staging/profile_repositories') result = JSON.parse(result) result['data'].select do |repo| repo['profileName'] == profile_name && repo['userId'] == self.username && repo['userAgent'] == self.user_agent && repo['description'] == 'Implicitly created (auto staging).' end end |
#release_sole_auto_staging(profile_name) ⇒ Object
70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 |
# File 'lib/mcrt.rb', line 70 def release_sole_auto_staging(profile_name) candidates = get_staging_repositories(profile_name) if candidates.empty? raise 'Release process unable to find any staging repositories.' elsif 1 != candidates.size raise 'Release process found multiple staging repositories that could be the release just uploaded. Please visit the website https://oss.sonatype.org/index.html#stagingRepositories and manually complete the release.' else candidate = candidates[0] begin close_repository(candidate['repositoryId'], "Closing repository for #{project.name}") rescue raise 'Failed to close repository. It is likely that the release does not conform to Maven Central release requirements. Please visit the website https://oss.sonatype.org/index.html#stagingRepositories and manually complete the release.' end begin #TODO: Implement the next method promote_repository(candidate['repositoryId'], "Promoting repository for #{project.name}") drop_repository(candidate['repositoryId'], "Dropping repository for #{project.name}") rescue raise 'Failed to promote repository. Please visit the website https://oss.sonatype.org/index.html#stagingRepositories and manually complete the release.' end end end |