Skip to content

Commit

Permalink
Add 'User-Agent' #97
Browse files Browse the repository at this point in the history
  • Loading branch information
eyalbe4 committed Nov 26, 2015
1 parent 0eb097c commit 25afb76
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 3 deletions.
7 changes: 7 additions & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,13 @@ publishing {
}
}

task createReleasePropertiesFile(type:Exec) {

This comment has been minimized.

Copy link
@vgaidarji

vgaidarji Jan 21, 2018

This task actual creates noise, as it creates a properties file which is not added to git and is not git-ignored.
Also, gradle.properties file in project root is git-ignored, but currentVersion property from that file is used in createReleasePropertiesFile.
@eyalbe4 Could you please provide more context why it's done this way?

String fileName = 'bintray.plugin.release.properties'
println 'Creating $fileName'
String fileContent = "version=$currentVersion"
(new File("$rootDir/src/main/resources/$fileName")).write(fileContent)
}

artifactory {
contextUrl = 'https://oss.jfrog.org'
resolve {
Expand Down
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
@@ -1 +1 @@
currentVersion=1.4
currentVersion=1.5
29 changes: 27 additions & 2 deletions src/main/groovy/com/jfrog/bintray/gradle/BintrayUploadTask.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ import org.gradle.api.tasks.Input
import org.gradle.api.tasks.Optional
import org.gradle.api.tasks.TaskAction
import org.gradle.api.tasks.Upload

import java.util.concurrent.ConcurrentHashMap

import static groovyx.net.http.ContentType.BINARY
Expand Down Expand Up @@ -150,6 +149,7 @@ class BintrayUploadTask extends DefaultTask {
Artifact[] fileUploads

boolean subtaskSkipPublish
Properties releaseProps

{
group = GROUP
Expand Down Expand Up @@ -202,6 +202,7 @@ class BintrayUploadTask extends DefaultTask {

def setAttributes = { attributesPath, attributes, entity, entityName ->
http.request(POST, JSON) {
addHeaders(headers)
uri.path = attributesPath
def builder = new JsonBuilder()
builder.content = attributes.collect {
Expand All @@ -227,6 +228,7 @@ class BintrayUploadTask extends DefaultTask {
}
def create
http.request(HEAD) {
addHeaders(headers)
uri.path = "/packages/$packagePath"
response.success = { resp ->
logger.debug("Package '$packageName' exists.")
Expand All @@ -242,6 +244,7 @@ class BintrayUploadTask extends DefaultTask {
return
}
http.request(POST, JSON) {
addHeaders(headers)
uri.path = "/packages/$repoPath"
body = [name : packageName, desc: packageDesc, licenses: packageLicenses, labels: packageLabels,
website_url : packageWebsiteUrl, issue_tracker_url: packageIssueTrackerUrl, vcs_url: packageVcsUrl,
Expand Down Expand Up @@ -269,6 +272,7 @@ class BintrayUploadTask extends DefaultTask {
}
def create
http.request(HEAD) {
addHeaders(headers)
uri.path = "/packages/$packagePath/versions/$versionName"
response.success = { resp ->
logger.debug("Version '$packagePath/$versionName' exists.")
Expand All @@ -284,6 +288,7 @@ class BintrayUploadTask extends DefaultTask {
return
}
http.request(POST, JSON) {
addHeaders(headers)
uri.path = "/packages/$packagePath/versions"
versionReleased = Utils.toIsoDateFormat(versionReleased)
body = [name: versionName, desc: versionDesc, released: versionReleased, vcs_tag: versionVcsTag]
Expand All @@ -310,6 +315,7 @@ class BintrayUploadTask extends DefaultTask {
return
}
http.request(POST, JSON) {
addHeaders(headers)
uri.path = "/gpg/$pkgPath/versions/$versionName"
if (version.gpgPassphrase) {
body = [passphrase: gpgPassphrase]
Expand Down Expand Up @@ -340,8 +346,12 @@ class BintrayUploadTask extends DefaultTask {
return
}
http.request(PUT) {
uri.path = uploadUri
addHeaders(headers)
// Set the requestContentType to BINARY, so that HTTPBuilder can encode the uploaded file:
requestContentType = BINARY
// Set the Content-Type to '*/*' to enable Bintray to set it on its own:
headers["Content-Type"] = '*/*'
uri.path = uploadUri
body = is
response.success = { resp ->
logger.info("Uploaded to '$apiUrl$uri.path'.")
Expand All @@ -362,6 +372,7 @@ class BintrayUploadTask extends DefaultTask {
return
}
http.request(POST, JSON) {
addHeaders(headers)
uri.path = publishUri
response.success = { resp ->
logger.info("Published '$pkgPath/$versionName'.")
Expand All @@ -380,6 +391,7 @@ class BintrayUploadTask extends DefaultTask {
return
}
http.request(POST, JSON) {
addHeaders(headers)
uri.path = "/maven_central_sync/$pkgPath/versions/$versionName"
body = [username: ossUser, password: ossPassword]
if (ossCloseRepo != null) {
Expand Down Expand Up @@ -429,6 +441,19 @@ class BintrayUploadTask extends DefaultTask {
}
}

String getPluginVersion() {
if (!releaseProps) {
Properties tempProps = new Properties()
tempProps.load(getClass().classLoader.getResource("bintray.plugin.release.properties").openStream())
releaseProps = tempProps
}
releaseProps.get('version')
}

void addHeaders(Map<?,?> headers) {
headers.put("User-Agent","gradle-bintray-plugin/$pluginVersion")
}

Package checkPackageAlreadyCreated() {
Package pkg = new Package(packageName)
Package p = BintrayUploadTask.packagesCreated.putIfAbsent(packageName, pkg)
Expand Down

0 comments on commit 25afb76

Please sign in to comment.