/
cliqz.gradle
171 lines (150 loc) · 4.91 KB
/
cliqz.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
import com.cliqz.minibloomfilter.BloomFilter
import java.util.regex.Matcher
import java.util.regex.Pattern
import groovy.json.JsonSlurper
import org.apache.commons.io.FileUtils
enum DistributionChannel {
CLIQZ(~/(cliqz)|(canary).*/, 0), LUMEN(~/lumen.*/, 6), AMAZON(~/amazon.*/, 2), GHOSTERY(~/ghostery.*/, 3), HUAWEI(~/huawei.*/, 4)
final regexp
final channel
DistributionChannel(regexp, channel) {
this.regexp = regexp
this.channel = channel
}
}
enum BuildType {
DEBUG(2), RELEASE(0)
final value
BuildType(value) {
this.value = value
}
}
buildscript {
repositories {
jcenter()
maven {
url 'https://jitpack.io'
}
}
dependencies {
classpath 'com.github.cliqz-oss:minibloomfilter:1.0'
classpath 'commons-io:commons-io:2.4'
classpath 'com.github.triplet.gradle:play-publisher:1.1.5'
}
}
// Signing configuration for Jenkinsis passed through environment variables
def props = [:].withDefault { '' }
if (System.getenv('CERT_PATH') && System.getenv('CERT_PASS') && System.getenv('PLAY_STORE_CERT')) {
props = [
'Browser.storeFile': System.getenv('CERT_PATH'),
'Browser.storePassword': System.getenv('CERT_PASS'),
'Browser.keyAlias': 'browser',
'Browser.keyPassword': System.getenv('CERT_PASS'),
'Browser.playStoreCert': System.getenv('PLAY_STORE_CERT')
]
} else if (project.hasProperty('Browser.storeFile')) {
props = project.properties.withDefault { "" }
}
// Signing config for local machine appens only if configured in root gradle.properties
if (props['Browser.storeFile']) {
android {
signingConfigs {
release {
storeFile file(props['Browser.storeFile'])
storePassword props['Browser.storePassword']
keyAlias props['Browser.keyAlias']
keyPassword props['Browser.keyPassword']
}
}
buildTypes {
release {
signingConfig signingConfigs.release
}
}
}
}
def extPath = file('../external/extension')
def createBloomFilter(File outputDir) {
def blackList = new File('app/blacklist.txt')
def lineCount = 0
blackList.eachLine { line ->
lineCount++
}
def bloomFilter = BloomFilter.create(lineCount, 0.0001)
blackList.eachLine { line ->
bloomFilter.put(line.substring(1, line.indexOf("\"", 1)));
}
new File(outputDir.absolutePath+"/bloomfilter.data").withObjectOutputStream { stream ->
stream.writeObject(bloomFilter)
}
}
def copyJsEngine(File outputDir) {
final src = new File('./jsengine/')
FileUtils.copyDirectory(src, outputDir);
}
def compileAdHostsList(File outputDir) {
File parent = project.buildscript.sourceFile.parentFile
File adFile = new File(parent, 'ad_servers.txt')
// Pattern p = ~/((([1-2]\d\d)|([1-9]\d)|(\d))\.?){4}\s+([^(localhost)].*)/
Pattern p = ~/^127\.0\.0\.1\s((localhost.*)|(.*))/
new File(outputDir, 'adhosts.txt').withWriter { writer ->
adFile.eachLine { line ->
Matcher matcher = p.matcher(line)
if (matcher.matches()) {
def host = matcher.group(3)
if (host != null) {
writer.println(host)
}
}
}
}
}
def getCliqzExtensionVersion() {
File cliqzJson = new File('node_modules/browser-core/build/config//cliqz.json');
if (cliqzJson.exists() && cliqzJson.isFile()) {
JsonSlurper slurper = new JsonSlurper();
def json = slurper.parse(cliqzJson)
json['EXTENSION_VERSION']
} else {
"0.0.0"
}
}
afterEvaluate { project ->
project.tasks.each { tazk ->
if (tazk.name =~ /merge.*Assets/ && !tazk.name.endsWith('TestAssets')) {
tazk.doLast {
createBloomFilter(tazk.outputDir.get().asFile)
copyJsEngine(tazk.outputDir.get().asFile)
}
}
}
}
// Default configuration for GCM (via Amazon SNS) and debug signing
android {
defaultConfig {
buildConfigField 'String', 'CLIQZ_EXT_VERSION', "\"${getCliqzExtensionVersion()}\""
}
signingConfigs {
debug {
storeFile file('../debug.keystore')
storePassword 'android'
keyAlias 'debug'
keyPassword 'android'
}
}
buildTypes {
debug {
signingConfig signingConfigs.debug
}
}
}
preBuild.doLast {
android.applicationVariants.each { variant ->
final channel = DistributionChannel.find {
variant.name =~ it.regexp
}
final buildType = variant.buildType.debuggable ? BuildType.DEBUG : BuildType.RELEASE
variant.resValue 'string', 'application_id', variant.applicationId
variant.buildConfigField 'String', 'TELEMETRY_CHANNEL', "\"MA${channel.channel}${buildType.value}\""
}
}