in ideaSupport/src/main/scala/org/jetbrains/sbtidea/tasks/PublishPlugin.scala [26:64]
def apply(
token: String,
xmlId: String,
channel: Option[String],
pluginFile: File,
log: PluginLogger
): Unit = {
val fileLength = pluginFile.length
log.info(s"Uploading ${pluginFile.getName}($fileLength bytes) to $MarketplaceUrl...")
Using.resource(Files.newInputStream(pluginFile.toPath)) { pluginStream =>
val multipartEntity = MultipartEntityBuilder.create()
.addPart("file", new ProgressTrackingInputStreamBody(
pluginStream,
ContentType.create("application/zip"),
pluginFile.getName,
trackFunc = uploadCallback(fileLength)(_)
))
.addTextBody("xmlId", xmlId)
.addTextBody("channel", channel.getOrElse(""))
.build()
val httpPost = new HttpPost(MarketplacePluginUploadUrl)
httpPost.addHeader("Authorization", s"Bearer $token")
httpPost.setEntity(multipartEntity)
val httpClient: CloseableHttpClient = HttpClients.createDefault
httpClient.execute(httpPost, (response: ClassicHttpResponse) => {
val entity: HttpEntity = response.getEntity
val responseString: String = EntityUtils.toString(entity, "UTF-8")
val httpCode = response.getCode
if (StatusClass.from(httpCode) == StatusClass.SUCCESSFUL) {
log.info(s"Successfully uploaded ${pluginFile.getName} to $MarketplaceUrl")
} else {
throw new IllegalStateException(s"Failed to upload plugin: ($httpCode) : $responseString")
}
})
}
}