This repository has been archived by the owner on Mar 30, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
/
artifactory-properties.gradle
47 lines (40 loc) · 2.1 KB
/
artifactory-properties.gradle
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
task updateArtifactoryProperties() {
dependsOn artifactoryPublish
doLast {
if (project.isSnapshot || "true" == project.findProperty('qa.build')) {
println 'For a snapshot or qa build, artifactory properties will not be updated.'
} else {
try {
println 'For a release build, an update of artifactory properties will be attempted.'
def latestPropertyKey = "GRADLE_INSPECTOR_LATEST"
def majorVersion = project.version.split("\\.")[0]
def majorVersionPropertyKey = "${latestPropertyKey}_${majorVersion}"
def artifactoryCredentials = "${project.ext.artifactoryDeployerUsername}:${project.ext.artifactoryDeployerPassword}"
def defaultCurlArgs = defaultCurlArgs(artifactoryCredentials)
setArtifactoryProperty(defaultCurlArgs, latestPropertyKey, project.version)
setArtifactoryProperty(defaultCurlArgs, majorVersionPropertyKey, project.version)
} catch (Exception e) {
println "Manual corrections to the properties for ${project.name}-${project.version} may be necessary."
println "Error correcting the artifactory properties: ${e.message}"
}
}
}
}
def setArtifactoryProperty(def defaultCurlArgs, String propertyKey, String propertyValue) {
println "Setting ${propertyKey} to ${propertyValue}."
def curlArgs = defaultCurlArgs + ['--request', 'PATCH', '--data', "{\"props\":{\"${propertyKey}\":\"${propertyValue}\"}}", "${project.ext.artifactoryUrl}/api/metadata/${project.ext.artifactoryRepo}/com/blackducksoftware/integration/integration-gradle-inspector"]
curlResponse(curlArgs)
}
def defaultCurlArgs(String artifactoryCredentials) {
return ['--silent', '--insecure', '--user', artifactoryCredentials, '--header', 'Content-Type: application/json']
}
def curlResponse(def curlArgs) {
new ByteArrayOutputStream().withStream { os ->
exec {
executable = 'curl'
args = curlArgs
standardOutput = os
}
return os.toString()
}
}