forked from us1415/wire-android
-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.gradle
288 lines (246 loc) · 9.51 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
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
import groovy.json.JsonSlurper
import org.ajoberstar.grgit.Grgit
import org.ajoberstar.grgit.Credentials
import groovy.json.JsonOutput
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
repositories {
maven {
url "https://dl.bintray.com/wire-android/third-party"
}
google()
jcenter()
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.2.1'
classpath 'com.mutualmobile.gradle.plugins:dexinfo:0.1.2'
classpath 'com.wire.gradle:gradle-android-scala-plugin:1.6'
classpath 'com.google.gms:google-services:3.1.1'
classpath 'org.ajoberstar.grgit:grgit-core:3.0.0'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:${Versions.KOTLIN}"
classpath "io.gitlab.arturbosch.detekt:detekt-gradle-plugin:${Versions.DETEKT}"
classpath "org.jacoco:org.jacoco.core:${Versions.JACOCO}"
}
}
plugins {
id "com.github.hierynomus.license" version "0.13.1"
id "io.gitlab.arturbosch.detekt" version "1.2.2"
}
license {
header = file('LICENSE_HEADER')
ext.year = Calendar.getInstance().get(Calendar.YEAR)
ext.name = 'Wire Swiss GmbH'
skipExistingHeaders = true
}
allprojects {
repositories {
google()
jcenter()
maven { url "https://dl.bintray.com/wire-android/releases" }
maven { url "https://dl.bintray.com/wire-android/snapshots" }
maven { url "https://dl.bintray.com/wire-android/third-party" }
maven { url 'https://maven.google.com' }
mavenCentral()
}
}
apply from: "./detekt/setup.gradle"
apply from: "./jacoco/coverage.gradle"
// FIXME: License header is disabled because it breaks compilation
//task licenseFormatAndroid(type: nl.javadude.gradle.plugins.license.License) {
// source = fileTree(dir: getRootDir()).include([
// "**/*.java",
// "**/*.scala",
// "**/*.gradle",
// "**/*.xml",
// ]).exclude([
// "**/*build*",
// "**/*target*",
// "**/*gen*",
// "**/*generated*",
// ".idea/**"
// ])
//}
//licenseFormat.dependsOn licenseFormatAndroid
ext {
compileSdkVersion = 28
// When upgrading minimum sdk you might want to search for occurrences of Build.VERSION_CODES.
// There are some classes with possibility of being simplified.
minSdkVersion = 21
targetSdkVersion = 28
buildToolsVersion = '28.0.3'
sourceCompatibilityVersion = JavaVersion.VERSION_1_8
targetCompatibilityVersion = JavaVersion.VERSION_1_8
// configuration and external config
customCheckoutDir = "$rootDir/custom"
buildtimeConfiguration = prepareCustomizationEnvironment()
project.logger.quiet("Build time configuration is: ${JsonOutput.prettyPrint(JsonOutput.toJson(buildtimeConfiguration.configuration))}")
//Update kotlinCore flag as well when adding new kotlin features
kotlinSettings = false
kotlinRegistration = false
kotlinCore = kotlinSettings || kotlinRegistration
}
class BuildtimeConfiguration {
String customResourcesPath
Object configuration
BuildtimeConfiguration(Object configuration, String customResourcesPath) {
this.configuration = configuration
this.customResourcesPath = customResourcesPath
}
def isCustomBuild() {
return customResourcesPath != null
}
}
// Will check out custom repo, if any, and load its configuration, merging it on top of the default configuration
def prepareCustomizationEnvironment() {
def properties = new Properties()
def localProperties = project.rootProject.file("local.properties")
if (localProperties.exists()) {
properties.load(localProperties.newDataInputStream())
}
def jsonReader = new JsonSlurper()
def wireConfigFile = new File("$rootDir/default.json")
def defaultConfig = jsonReader.parseText(wireConfigFile.text)
def customRepository = System.getenv("CUSTOM_REPOSITORY") ?: properties.getProperty("CUSTOM_REPOSITORY") ?: ''
if (customRepository.isEmpty()) {
project.logger.quiet("This is not a custom build (no custom repo)")
return new BuildtimeConfiguration(defaultConfig, null)
}
def customFolder = System.getenv("CUSTOM_FOLDER") ?: properties.getProperty("CUSTOM_FOLDER") ?: ''
if (customFolder.isEmpty()) {
throw new GradleException('Custom repo specified, but not custom folder')
}
def gitHubToken = System.getenv("GITHUB_API_TOKEN") ?: properties.getProperty("GITHUB_API_TOKEN") ?: ''
if (gitHubToken.isEmpty()) {
throw new GradleException('Custom repo specified, but no GitHub API token provided')
}
def customDirPath = customCheckoutDir + '/' + customFolder
def customConfigFile = new File("$customDirPath/custom.json")
// clean up
if (file(customCheckoutDir).exists()) {
delete file(customCheckoutDir)
}
def credentials = new Credentials(gitHubToken, '')
Grgit.clone(dir: customCheckoutDir, uri: customRepository, credentials: credentials)
project.logger.quiet("Using custom repository $customRepository -> folder $customFolder")
def customConfig = jsonReader.parseText(customConfigFile.text)
project.logger.quiet("Loaded custom build configuration for keys: ${customConfig.keySet()}")
customConfig.keySet().forEach { key ->
defaultConfig[key] = customConfig[key]
}
return new BuildtimeConfiguration(defaultConfig, customDirPath)
}
task ci(dependsOn: [
':app:assembleDevDebug',
':app:lintDevDebug',
':app:pmd',
':detektAll'
]) {
doLast {
def lintReportsPattern = /\/?(.*)\/build\/outputs\/lint-results\-(devDebug|debug)\.xml/
def pmdReportsPattern = /\/?(.*)\/build\/reports\/pmd\/pmd\.xml/
def checkstyleReportsPattern = /\/?(.*)\/reports\/checkstyle\/checkstyle\.xml/
def results = new HashMap<String, Map<String, List<Issue>>>()
def totalIssues = 0
def findFilenameClosure = {
if (it.isDirectory()) {
return;
}
def absolutePath = it.getAbsolutePath()
def foundIssues = new ArrayList<Issue>()
def type = ''
if (absolutePath.matches(lintReportsPattern)) {
def issues = new XmlParser().parse(it)
type = 'Lint'
issues.issue.each {
def id = it.'@summary'
it.location.each { foundIssues.add(new LintIssue(id, it)) }
}
} else if (absolutePath.matches(pmdReportsPattern)) {
def issues = new XmlParser().parse(it)
type = 'PMD'
issues.file.each {
def file = new File(it.'@name')
it.violation.each { foundIssues.add(new PmdIssue(file, it)) }
}
} else if (absolutePath.matches(checkstyleReportsPattern)) {
def files = new XmlParser().parse(it)
type = 'Checkstyle'
files.file.findAll { it.children().size() > 0 }.each {
def file = new File(it.'@name')
it.error.each { foundIssues.add(new CheckstyleIssue(file, it)) }
}
}
if (foundIssues.size() > 0) {
if (!results.containsKey(type)) {
results.put(type, new HashMap<String, List<Issue>>())
}
results.get(type).put(it, foundIssues)
totalIssues += foundIssues.size()
}
}
rootProject.rootDir.eachFileRecurse(findFilenameClosure)
if (totalIssues > 0) {
def message = new StringBuilder()
message.append("Found ${totalIssues} issue${totalIssues == 1 ? '' : 's'}\n\n")
for (def entry : results.entrySet()) {
def issues = new StringBuilder()
def count = 0;
for (def file : entry.value.entrySet()) {
issues.append("> ${file.value.size()} in ${file.key}\n")
file.value.each { issues.append("\t${it}\n") }
count += file.value.size()
}
message.append("${entry.key}: ${count} issue${count == 1 ? '' : 's'}\n")
.append(issues.toString())
.append('\n')
}
throw new Exception(message.toString())
} else {
println 'No issues found'
}
}
}
task clean(type: Delete) {
delete rootProject.buildDir
def repo = file(customCheckoutDir)
if (repo.exists()) {
delete repo
}
}
class Issue {
File file
String line
String column
String error
@Override
public String toString() {
return "${file}:${line}:${column}: ${error}";
}
}
class LintIssue extends Issue {
def LintIssue(String error, Node location) {
file = new File(location.'@file')
line = location.'@line'
column = location.'@column'
this.error = error
}
}
class PmdIssue extends Issue {
def PmdIssue(File file, Node violation) {
this.file = file
def beginline = violation.'@beginline'
def endline = violation.'@endline'
line = beginline == endline ? beginline : "${beginline}-${endline}"
column = violation.'@begincolumn'
error = violation.text().replaceAll(/\n/, '')
}
}
class CheckstyleIssue extends Issue {
def CheckstyleIssue(File file, Node node) {
this.file = file
line = node.'@line'
column = node.'@column'
error = node.'@message'
}
}