-
Notifications
You must be signed in to change notification settings - Fork 4
/
build.gradle
111 lines (90 loc) · 3.44 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
apply plugin: 'java'
apply plugin: 'eclipse'
sourceCompatibility = 1.7
version = '0.1'
jar {
baseName = 'getdns-java'
version = '0.1'
manifest {
attributes 'Implementation-Title': 'Gradle Quickstart', 'Implementation-Version': version
}
}
repositories {
mavenCentral()
}
dependencies {
testCompile group: 'junit', name: 'junit', version: '4.+'
}
sourceSets {
examples {
java
compileClasspath += main.output
runtimeClasspath += main.output
}
}
task buildJniLib(type:Exec) {
if(!new File(javahome+'/include/jni.h').exists()) {
throw new InvalidUserDataException("Please configure javahome in gradle.properties pointing to JDK_HOME so that gradle can find jni header files under JDK_HOME/include directory.")
}
if(!new File('/usr/local/include/getdns/getdns.h').exists()) {
throw new InvalidUserDataException("Please install getdns 0.1.7 release or above configured with --with-libevent.")
}
if(!new File('/usr/local/include/getdns/getdns_ext_libevent.h').exists()) {
throw new InvalidUserDataException("It looks like getdns is not configured with libevent. Please install getdns 0.1.7 release or above configured with --with-libevent.")
}
workingDir './src/native/jni/'
def libraryExtension = 'so'
def systemJNIPath = 'linux'
if(System.properties['os.name'].toLowerCase().contains('mac')){
libraryExtension = 'dylib'
systemJNIPath = 'darwin'
}
commandLine 'gcc', '-I'+javahome+'/include', '-I'+javahome+'/include/'+systemJNIPath, '-shared','-o',project.libsDir.getPath()+'/libgetdnsconnector.'+libraryExtension,'-fPIC','-I/usr/local/include','-L/usr/local/lib', 'java_util.c', 'GetDNSContext.c', 'GetDNS_common.c', 'getdns_util.c', '-lgetdns','-lldns','-lidn', '-levent','-lgetdns_ext_event'
standardOutput = new ByteArrayOutputStream()
ext.output = {
return standardOutput.toString()
}
}
task installJniLib(type:Copy) {
def libraryExtension = 'so'
def systemJNIPath = 'linux'
if(System.properties['os.name'].toLowerCase().contains('mac')){
libraryExtension = 'dylib'
systemJNIPath = 'darwin'
}
from project.libsDir.getPath()+'/libgetdnsconnector.'+libraryExtension
into '/usr/local/lib'
}
task runExample(type:JavaExec) {
classpath = sourceSets.main.runtimeClasspath + sourceSets.examples.runtimeClasspath
jvmArgs '-Djava.library.path='+project.libsDir.getPath()
environment "LD_LIBRARY_PATH", "/usr/local/lib"
environment "DYLD_LIBRARY_PATH", "/usr/local/lib"
doFirst {
main = System.getProperty("example")
def map = [:]
sourceSets.examples.java.each { File file ->
map[file.name.replace(".java","")] = file.getCanonicalPath().replace(project.projectDir.getCanonicalPath()+"/src/examples/java/","").replace(".java","")
}
if(main == null || map[main] == null){
println "Usage: -Dexample=<exampleName> runExample"
println ("Please provide one of the below exampleName to execute")
map.each{
key, value -> println key;
}
throw new InvalidUserDataException("Invalid or no example name provided")
}
else
main = map[main]
}
}
runExample.dependsOn buildJniLib
buildJniLib.dependsOn assemble
task printBuildInfo << {
print buildJniLib.output()
}
test {
jvmArgs '-Djava.library.path='+System.getProperty("user.dir")+'/build/libs'
environment "LD_LIBRARY_PATH", "/usr/local/lib"
environment "DYLD_LIBRARY_PATH", "/usr/local/lib"
}