@@ -419,12 +419,12 @@ end
419419def sonatype_api_post ( url , token )
420420 uri = URI ( url )
421421 req = Net ::HTTP ::Post . new ( uri )
422- req [ 'Authorization' ] = "Bearer #{ token } "
422+ req [ 'Authorization' ] = "Basic #{ token } "
423423
424424 res = Net ::HTTP . start ( uri . hostname , uri . port , use_ssl : true ) { |http | http . request ( req ) }
425425 raise "Sonatype API error (#{ res . code } ): #{ res . body } " unless res . is_a? ( Net ::HTTPSuccess )
426426
427- res . body . empty? ? { } : JSON . parse ( res . body )
427+ res . body . to_s . empty? ? { } : JSON . parse ( res . body )
428428end
429429
430430def credential_valid? ( cred )
@@ -1232,14 +1232,16 @@ namespace :java do
12321232 read_m2_user_pass unless ENV [ 'MAVEN_PASSWORD' ] && ENV [ 'MAVEN_USER' ]
12331233 token = Base64 . strict_encode64 ( "#{ ENV . fetch ( 'MAVEN_USER' ) } :#{ ENV . fetch ( 'MAVEN_PASSWORD' ) } " )
12341234
1235+ encoded_id = URI . encode_www_form_component ( deployment_id . strip )
1236+ status = { }
12351237 60 . times do
1236- status = sonatype_api_post ( "https://central.sonatype.com/api/v1/publisher/status?id=#{ deployment_id } " , token )
1238+ status = sonatype_api_post ( "https://central.sonatype.com/api/v1/publisher/status?id=#{ encoded_id } " , token )
12371239 state = status [ 'deploymentState' ]
12381240 puts "Deployment state: #{ state } "
12391241
12401242 case state
12411243 when 'VALIDATED' then break
1242- when 'PUBLISHED' then exit ( 0 )
1244+ when 'PUBLISHED' then return
12431245 when 'FAILED' then raise "Deployment failed: #{ status [ 'errors' ] } "
12441246 end
12451247 sleep ( 5 )
@@ -1248,10 +1250,13 @@ namespace :java do
12481250
12491251 expected = java_release_targets . size
12501252 actual = status [ 'purls' ] &.size || 0
1251- raise "Expected #{ expected } packages but found #{ actual } " if actual != expected
1253+ if actual != expected
1254+ raise "Expected #{ expected } packages but found #{ actual } . " \
1255+ 'Drop the deployment at https://central.sonatype.com/publishing/deployments and redeploy.'
1256+ end
12521257
12531258 puts 'Publishing deployed packages...'
1254- sonatype_api_post ( "https://central.sonatype.com/api/v1/publisher/deployment/#{ deployment_id } " , token )
1259+ sonatype_api_post ( "https://central.sonatype.com/api/v1/publisher/deployment/#{ encoded_id } " , token )
12551260 puts "Published! Deployment ID: #{ deployment_id } "
12561261
12571262 Rake ::Task [ 'java:verify' ] . invoke
0 commit comments