forked from MiniDNS/minidns
-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.gradle
234 lines (204 loc) · 6.33 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
buildscript {
repositories {
maven {
url "https://plugins.gradle.org/m2/"
}
jcenter()
mavenLocal()
mavenCentral()
}
dependencies {
classpath 'com.bmuschko:gradle-nexus-plugin:2.3.1'
classpath "org.kt3k.gradle.plugin:coveralls-gradle-plugin:2.3.1"
}
}
allprojects {
apply plugin: 'java'
apply plugin: 'eclipse'
apply plugin: 'osgi'
apply plugin: 'com.bmuschko.nexus'
apply plugin: 'checkstyle'
apply plugin: 'jacoco'
group = 'de.measite.minidns'
description = "A minimal DNS client library with support for A, AAAA, NS and SRV records"
sourceCompatibility = 1.7
version = 'dev'
ext.isSnapshot = true
ext {
junitVersion = 4.11
minidnsMinAndroidSdk = 9
androidBootClasspath = getAndroidRuntimeJar()
rootConfigDir = new File(rootDir, 'config')
gitCommit = getGitCommit()
builtDate = (new java.text.SimpleDateFormat("yyyy-MM-dd")).format(new Date())
}
if (!ext.isSnapshot && 'git rev-parse --abbrev-ref HEAD'.execute().text.trim() == 'master') {
throw new org.gradle.api.InvalidUserDataException('Untagged version detected! Please tag every release.')
}
if (version != 'dev' && version != 'git tag --points-at HEAD'.execute().text.trim()) {
throw new org.gradle.api.InvalidUserDataException(
'Tag mismatch detected, version is ' + version + ' but should be ' +
'git tag --points-at HEAD'.execute().text.trim())
}
if (ext.isSnapshot) {
version = version + '-SNAPSHOT'
}
repositories {
mavenLocal()
mavenCentral()
}
nexus {
sign = true
}
extraArchive {
tests = true
}
modifyPom {
project {
name 'minidns'
description 'Minimal DNS library for java and android systems'
url 'https://github.com/rtreffer/minidns'
inceptionYear '2014'
scm {
url 'https://github.com/rtreffer/minidns'
connection 'scm:https://github.com/rtreffer/minidns'
developerConnection 'scm:git://github.com/rtreffer/minidns.git'
}
licenses {
license {
name 'The Apache Software License, Version 2.0'
url 'http://www.apache.org/licenses/LICENSE-2.0.txt'
distribution 'repo'
}
}
developers {
developer {
id 'rtreffer'
name 'Rene Treffer'
email '[email protected]'
}
developer {
id 'flow'
name 'Florian Schmaus'
email '[email protected]'
}
}
}
}
tasks.withType(JavaCompile) {
// Some systems may not have set their platform default
// converter to 'utf8', but we use unicode in our source
// files. Therefore ensure that javac uses unicode
options.encoding = "utf8"
options.compilerArgs = [
'-Xlint:all',
// Set '-options' because a non-java7 javac will emit a
// warning if source/traget is set to 1.7 and
// bootclasspath is *not* set.
// TODO implement a sound heuristic to determine a java7
// rt.jar on the build host. And if none is found,
// fallback to using a environment variable,
// e.g. JAVA7_HOME. See SMACK-651.
'-Xlint:-options',
'-Werror',
]
}
checkstyle {
configFile = new File(rootConfigDir, 'checkstyle.xml')
}
jacoco {
toolVersion = "0.7.4.201502262128"
}
jacocoTestReport {
dependsOn test
sourceDirectories = project.files(sourceSets.main.allSource.srcDirs)
classDirectories = project.files(sourceSets.main.output)
reports {
xml.enabled true
}
}
}
configure(subprojects.findAll{!it.name.endsWith('-java7')}) {
task compileAndroid(type: JavaCompile) {
source = compileJava.source
classpath = compileJava.classpath
destinationDir = new File(buildDir, 'android')
options.bootClasspath = androidBootClasspath
}
test { dependsOn compileAndroid }
}
jar {
// Root project should not create empty jar artifact
enabled = false
}
apply plugin: "com.github.kt3k.coveralls"
coveralls {
sourceDirs = files(subprojects.sourceSets.main.allSource.srcDirs).files.absolutePath
}
task jacocoRootReport(type: org.gradle.testing.jacoco.tasks.JacocoReport) {
dependsOn = subprojects.jacocoTestReport
sourceDirectories = files(subprojects.sourceSets.main.allSource.srcDirs)
classDirectories = files(subprojects.sourceSets.main.output)
executionData = files(subprojects.jacocoTestReport.executionData)
reports {
xml.enabled true
xml.destination ="${buildDir}/reports/jacoco/test/jacocoTestReport.xml"
}
// We could remove the following setOnlyIf line, but then
// jacocoRootReport would silently be SKIPPED if something with
// the subprojects is wrong (e.g. a project is missing
// in there).
setOnlyIf { true }
}
task integrationTest {
// Depend on the integration test's 'run' task using a closure, as
// usually the subprojects are evaluated after the parent
// project. The closure defers the lookup, compared to
// dependsOn project(':minidns-integration-test').tasks.run
// which won't work. See also: https://discuss.gradle.org/t/4387/2
dependsOn { project(':minidns-integration-test').tasks.run }
}
task checkFull {
dependsOn = subprojects.tasks.check
dependsOn {
integrationTest
}
}
def getAndroidRuntimeJar() {
def androidHome = getAndroidHome()
def androidJar = new File("$androidHome/platforms/android-$minidnsMinAndroidSdk/android.jar")
if (androidJar.isFile()) {
return androidJar
} else {
throw new Exception("Can't find android.jar for $minidnsMinAndroidSdk API. Please install corresponding SDK platform package")
}
}
def getAndroidHome() {
def androidHomeEnv = System.getenv("ANDROID_HOME")
if (androidHomeEnv == null) {
throw new Exception("ANDROID_HOME environment variable is not set")
}
def androidHome = new File(androidHomeEnv)
if (!androidHome.isDirectory()) throw new Exception("Environment variable ANDROID_HOME is not pointing to a directory")
return androidHome
}
def getGitCommit() {
def dotGit = new File("$projectDir/.git")
if (!dotGit.isDirectory()) return 'non-git build'
def cmd = 'git describe --always --tags --dirty=+'
def proc = cmd.execute()
def gitCommit = proc.text.trim()
assert !gitCommit.isEmpty()
def srCmd = 'git symbolic-ref --short HEAD'
def srProc = srCmd.execute()
srProc.waitForOrKill(10 * 1000)
if (srProc.exitValue() == 0) {
// Only add the information if the git command was
// successful. There may be no symbolic reference for HEAD if
// e.g. in detached mode.
def symbolicReference = srProc.text.trim()
assert !symbolicReference.isEmpty()
gitCommit += "-$symbolicReference"
}
gitCommit
}