forked from JeroenMols/GitAsMaven
-
Notifications
You must be signed in to change notification settings - Fork 1
/
publish-bitbucket.gradle
126 lines (91 loc) · 3.18 KB
/
publish-bitbucket.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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
apply plugin: 'maven'
repositories {
maven { url "https://raw.githubusercontent.com/synergian/wagon-git/releases" }
}
configurations {
deployLibrary
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
def library = "ar.com.synergian:wagon-git:0.3.0"
printLine()
println(library)
printLine()
deployLibrary library
}
task androidJavadocs(type: Javadoc) {
failOnError false
source = android.sourceSets.main.java.sourceFiles
}
task androidSourcesJar(type: Jar) {
classifier = 'sources'
from android.sourceSets.main.java.sourceFiles
}
task androidJavadocsJar(type: Jar, dependsOn: androidJavadocs) {
classifier = 'javadoc'
from androidJavadocs.destinationDir
}
artifacts {
archives androidSourcesJar
archives androidJavadocsJar
}
task lookForArtifacts {
doLast {
def artifactName = ARTIFACT_NAME + '-' + ARTIFACT_VERSION + '.aar'
def artifactPath = ARTIFACT_PACKAGE.replace(".", "/") + "/" + ARTIFACT_NAME + "/" + ARTIFACT_VERSION + "/" + artifactName
def repositoryUrl = 'https://api.bitbucket.org/1.0/repositories/' + COMPANY + '/' + REPOSITORY_NAME + '/raw/releases/' + artifactPath
printLine()
println("Checking if artifact already exists: \n" + artifactName)
println("\nURL: \n" + repositoryUrl)
println("\nResponse:")
def artifactExists = urlExists(repositoryUrl)
println(artifactExists ? "Existing artifact found" : "No existing artifact found")
printLine()
if (artifactExists) {
println("Artifact with version " + ARTIFACT_VERSION + " already exist - Not executing uploadArchives")
printLine()
throw new RuntimeException("")
}
return true
}
}
uploadArchives.dependsOn lookForArtifacts
uploadArchives {
repositories.mavenDeployer {
configuration = configurations.deployLibrary
repository(url: 'git:releases://[email protected]:' + COMPANY + '/' + REPOSITORY_NAME + '.git')
uniqueVersion = true
pom.project {
groupId = ARTIFACT_PACKAGE
version = ARTIFACT_VERSION
artifactId = ARTIFACT_NAME
packaging ARTIFACT_PACKAGING
}
}
}
def urlExists(String repositoryUrl) {
try {
def connection = (HttpURLConnection) new URL(repositoryUrl).openConnection()
connection.setRequestProperty("Authorization", "Basic " + getBase64EncodedCredentials())
connection.setConnectTimeout(10000)
connection.setReadTimeout(10000)
connection.setRequestMethod("HEAD")
def responseCode = connection.getResponseCode()
println("ResponseCode: " + responseCode)
return (200 == responseCode)
} catch (IOException ignored) {
return false
}
}
def getBase64EncodedCredentials() {
def s = USERNAME + ":" + PASSWORD;
return s.bytes.encodeBase64().toString()
}
def printLine() {
println("")
println(getLine())
println("")
}
def getLine() {
return "-------------------------------------------------------------------------------------------------------------"
}