forked from mockito/mockito
-
Notifications
You must be signed in to change notification settings - Fork 4
/
release.gradle
187 lines (153 loc) · 6.13 KB
/
release.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
175
176
177
178
179
180
181
182
183
184
185
186
187
task printHelp << {
println """
---------------------------
How to build mockito?
---------------------------
# Use ant tasks, 'ant -p' for available tasks, 'ant' to build.
---------------------------
How to release mockito?
---------------------------
# Make sure that the version.properties has the version you want to release.
# Release documentation via 'gradlew releaseDocs'.
# Build and push binaries to googlce code via 'gradlew release'. In case of errors follow the instructions.
# Review the google code project:
## Mark all fixed issues with given release with the correct Milestone-ReleaseX label.
### Usually you can use 'advanced search', all open issues, with status 'Fixed, Verified, Done', then sort by 'Milestone' column up.
Items on the top that not yet have the 'milestone' set are the candidates.
## Update the release notes wiki. Mention the prominent features with links to documentation; mention prominent contributors.
## Update the main page (it might have references to previous release, search the page for links to previous version).
## Merge the defult branch with the new release branch. Make sure the version.properties is correct.
---------------------------
More info.
---------------------------
# At some point we will move fully into gradle. For now the Mockito project tells the 'migration story' and demonstrates how ant and gradle can coexist together.
"""
}
task release
if (gradle.startParameter.taskNames == ['release']) {
gradle.startParameter.taskNames = ['releaseDocs', 'updateLicenseHeaders', 'assertCleanCopy', 'uploadToGoogle']
}
gradle.taskGraph.whenReady {
//validate the existence of project properties
if (it.hasTask(':uploadToGoogle')) {
project.tasks.uploadToGoogle.assertUploadPossible()
}
}
//TODO SF read from the file
def version = '1.9.5-rc1'
task uploadToGoogle(type: UploadToGoogle) {
mockitoZip = file("target/mockito-${version}.zip")
mockitoAllJar = file("target/mockito-all-${version}.jar")
}
task buildMockito(type: Exec) {
commandLine 'ant', 'clean', 'test.release', 'release.maven'
}
class UploadToGoogle extends DefaultTask {
@InputFile File mockitoZip
@InputFile File mockitoAllJar
void assertUploadPossible() {
def googleUser = project.hasProperty('googleUser')
def googlePwd = project.hasProperty('googlePwd')
assert googleUser && googlePwd : """Google upload not possible - googleUser or googlePwd property not provided.
Pass -PgoogleUser=someone -PgooglePwd=secret via command line"""
assert mockitoZip.exists() && mockitoAllJar.exists() : "" +
"Google upload not possible - no binaries to upload. Please run 'gradlew build' first."
}
@TaskAction
void upload() {
project.ant {
//declare ant task
taskdef(name:"gcupload", classname:"net.bluecow.googlecode.ant.GoogleCodeUploadTask") {
classpath {
fileset(dir: 'lib/build', includes: 'ant-googlecode-*.jar')
}
}
//acquire the user/password (usually supplied via command line)
def googleUser = project.getProperty('googleUser')
def googlePwd = project.getProperty('googlePwd')
//upload zip
logger.lifecycle "Uploading $mockitoZip ..."
gcupload username:googleUser, password:googlePwd, projectname:"mockito",
filename:mockitoZip, targetfilename:mockitoZip.name, summary:"All jars, source and javadocs",
labels:"Featured"
logger.lifecycle "Uploading $mockitoAllJar ..."
//upload jar
gcupload username:googleUser, password:googlePwd, projectname:"mockito",
filename:mockitoAllJar, targetfilename:mockitoAllJar.name, summary:"Single jar, includes source",
labels:"Featured"
}
}
}
task assertCleanCopy << {
def output = new ByteArrayOutputStream()
exec {
commandLine "hg", "status"
standardOutput = output
errorOutput = output
}
assert output.toString().empty : """
Please commit outstanding files.
----- 'hg st' output -----
$output----- end of output -----
"""
}
task updateLicenseHeaders {
inputs.files fileTree('test') + fileTree('src')
outputs.files inputs.files
doLast {
def files = inputs.files
files = files.filter { !it.name.endsWith('.html') && !it.name.endsWith('.txt')}
logger.lifecycle("Updating licence headers in source... Found ${files.files.size()} files to check the license.")
def header = """/*
* Copyright (c) 2007 Mockito contributors
* This program is made available under the terms of the MIT License.
*/
"""
files.each { File file ->
def currentHdr = /(?sm).*?\/\*.*?\*\/.*?package org\./
def ignoreHdr = /NON-STANDARD LICENCE HEADER HERE - THAT'S OK/
logger.info("Checking the header of $file")
sleep(10)
def content = file.text
if (content =~ ignoreHdr) {
//this means we're ok with non-standard header
} else if (!(content =~ currentHdr)) {
logger.lifecycle "missing header in: ${file} - prepending..."
file.text = header + content
} else if (!content.find(currentHdr)?.contains(header)) {
logger.lifecycle "different header in: ${file} - replacing..."
content = content.replaceFirst(currentHdr, header + "package org.")
file.text = content
}
}
}
}
task releaseDocs {
doLast {
def docsRepo = file("../docs")
//TODO SF validate if this is a correct repo via hg
def docsDir = file("$docsRepo/$version")
assert docsDir.directory || docsDir.mkdirs() : "Expected to find cloned 'docs' repo at: '$docsRepo'. Problems creating docs output dir."
exec {
commandLine 'ant', 'javadoc'
}
copy {
from 'target/javadoc'
into docsDir
}
exec {
commandLine 'hg', 'add'
workingDir docsDir
}
exec {
commandLine 'hg', 'ci', '-m', 'Released the docs.'
workingDir docsDir
}
//TODO SF assert clean copy
exec {
commandLine 'hg', 'push'
workingDir docsRepo
}
}
}
defaultTasks 'printHelp'