forked from thucydides-webtests/thucydides
-
Notifications
You must be signed in to change notification settings - Fork 1
/
build.gradle
176 lines (142 loc) · 5.32 KB
/
build.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
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
project.ext {
currentBranch = getCurrentBranch()
releaseBranch = "release-${versionNumber}"
workDirectory = createWorkDirectory()
project = 'thucydides'
artifacts = ['thucydides-report-resources','thucydides-core', 'thucydides-junit','maven-thucydides-plugin','thucydides-easyb-plugin', 'thucydides-extensions','thucydides-browsermob-plugin']
mavenRepo = "~/.m2/repository"
}
task createBranch {
executeOnShell "git checkout -b ${project.ext.releaseBranch}"
}
task setNewVersion {
dependsOn createBranch
executeOnShell "mvn versions:set -DnewVersion=${versionNumber}"
}
task buildArtifacts {
dependsOn setNewVersion
executeOnShell "mvn clean install -DskipTests"
executeOnShell "mvn compile test-compile javadoc:jar source:jar"
}
task deployArtifacts {
dependsOn buildArtifacts
def parentPomFile = findParentArtifact()
def jarFiles = findChildArtifacts()
def javadocFiles = findJavadocArtifacts()
def sourceJarFiles = findSourceArtifacts()
deployFile(parentPomFile, parentPomFile)
jarFiles.each { jarFile ->
def artifactName = new File(jarFile).name.replace(".jar","")
def pomFile = jarFile.replace(".jar",".pom")
def sourceFile = sourceJarFiles.find { it.contains(artifactName)}
def javadocFile = javadocFiles.find { it.contains(artifactName)}
deployFiles(pomFile, jarFile, sourceFile, javadocFile)
}
}
task deployCurrentBuildArtifacts {
def parentPomFile = findParentArtifact()
def jarFiles = findChildArtifacts()
def javadocFiles = findJavadocArtifacts()
def sourceJarFiles = findSourceArtifacts()
deployFile(parentPomFile, parentPomFile)
jarFiles.each { jarFile ->
def artifactName = new File(jarFile).name.replace(".jar","")
def pomFile = jarFile.replace(".jar",".pom")
def sourceFile = sourceJarFiles.find { it.contains(artifactName)}
def javadocFile = javadocFiles.find { it.contains(artifactName)}
deployFiles(pomFile, jarFile, sourceFile, javadocFile)
}
}
task pushNewBranch {
executeOnShell "git commit -a -m '[Release version ${versionNumber}]'"
executeOnShell "git push origin ${project.ext.releaseBranch}"
}
task checkoutOriginalBranch {
executeOnShell "git checkout ${project.ext.currentBranch}"
}
task release {
dependsOn deployArtifacts, pushNewBranch, checkoutOriginalBranch
println "RELEASING THUCYDIDES VERSION ${versionNumber}"
}
def deployFile(pomFilePath, artifactFilePath) {
deployFiles(pomFilePath, artifactFilePath, null, null)
}
def deployFiles(pomFilePath, artifactFilePath, sourceFile, javadocFile) {
println "Deploying $artifactFilePath"
def tempDirectory = project.ext.workDirectory
def toSonatypeStagingRepo = "-Durl=https://oss.sonatype.org/service/local/staging/deploy/maven2/ -DrepositoryId=sonatype-nexus-staging"
def pomFile = new File(pomFilePath)
def artifactFile = new File(artifactFilePath)
def tempPom = new File(tempDirectory, pomFile.getName())
def tempArtifact = new File(tempDirectory, artifactFile.getName())
executeOnShell "cp ${pomFilePath.trim()} ${tempDirectory.path}"
executeOnShell "cp ${artifactFilePath.trim()} ${tempDirectory.path}"
deployCmd = "mvn gpg:sign-and-deploy-file $toSonatypeStagingRepo -DpomFile=${tempPom.path} -Dfile=${tempArtifact.path}"
if (sourceFile) {
deployCmd += " -Dsources=$sourceFile"
}
if (javadocFile) {
deployCmd += " -Djavadoc=$javadocFile"
}
executeOnShell deployCmd
}
def getCurrentBranch() {
def branches = executeOnShell('git branch',true)
def branch = branches.readLines().find { it.startsWith('*') }
branch.stripIndent(2)
}
def findParentArtifact() {
def parentPom = executeOnShell "find ~/.m2/repository -name '*.pom' | grep ${project.ext.project}-${versionNumber}.pom"
parentPom.trim()
}
def findChildArtifacts() {
findJarsWithQualifier(versionNumber, "~/.m2/repository")
}
def findJavadocArtifacts() {
findJarsWithQualifier("javadoc")
}
def findSourceArtifacts() {
findJarsWithQualifier("sources")
}
def findJarsWithQualifier(qualifier) {
findJarsWithQualifier(qualifier,".")
}
def findJarsWithQualifier(qualifier, directory) {
def artifactPaths = []
project.ext.artifacts.each {
def jarFile = executeOnShell "find ${directory} -name '*.jar' | grep ${it} | grep ${qualifier}.jar"
if (jarFile) {
artifactPaths.add jarFile.trim()
}
}
return artifactPaths
}
def executeOnShell(String command) {
return executeOnShell(command, false)
}
def createWorkDirectory() {
File dir = File.createTempFile( 'artifacts', '.dir' )
dir.delete()
dir.mkdir()
return dir
}
private def executeOnShell(String command, boolean failOnError) {
println "EXECUTING $command"
def output = new StringBuffer();
def process = new ProcessBuilder(addShellPrefix(command))
.redirectErrorStream(true)
.start()
process.inputStream.eachLine {println it; output.append(it).append("\n")}
process.waitFor();
if (failOnError && process.exitValue() != 0) {
throw new GradleException("$command failed to execute")
}
return output.toString()
}
private def addShellPrefix(String command) {
commandArray = new String[3]
commandArray[0] = "sh"
commandArray[1] = "-c"
commandArray[2] = command
return commandArray
}