File: build.gradle

package info (click to toggle)
libnative-platform-java 0.3~rc2-3
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 488 kB
  • ctags: 583
  • sloc: java: 1,652; cpp: 884; sh: 122; makefile: 78
file content (271 lines) | stat: -rwxr-xr-x 8,672 bytes parent folder | download
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
apply plugin: 'groovy'
apply plugin: 'cpp'

allprojects {
    apply plugin: 'java'
    apply plugin: 'idea'
    apply plugin: 'maven'

    repositories {
        mavenCentral()
        maven { url "http://repo.gradle.org/gradle/libs-releases-local" }
    }

    dependencies {
        testCompile 'org.spockframework:spock-core:0.6-groovy-1.8'
    }

    group = 'net.rubygrapefruit'
    version = '0.3-rc-2'

    sourceCompatibility = 1.5
    targetCompatibility = 1.5

    tasks.withType(Upload) {
        repositories {
            mavenDeployer {
                if (project.hasProperty('release')) {
                    repository(url: uri("https://gradle.artifactoryonline.com/gradle/libs-releases-local")) {
                        authentication(userName: artifactoryUserName, password: artifactoryPassword)
                    }
                } else {
                    repository(url: uri("$rootProject.buildDir/repo"))
                }
            }
        }
    }
}

dependencies {
    testCompile 'org.codehaus.groovy:groovy:1.8.7'
}

def nativeHeadersDir = file("$buildDir/nativeHeaders")

task nativeHeaders {
    def outputFile = file("$nativeHeadersDir/native.h")
    inputs.files sourceSets.main.output
    outputs.file outputFile
    doLast {
        outputFile.parentFile.mkdirs()
        exec {
            executable org.gradle.internal.jvm.Jvm.current().getExecutable('javah')
            args '-o', outputFile
            args '-classpath', sourceSets.main.output.classesDir
            args 'net.rubygrapefruit.platform.internal.jni.NativeLibraryFunctions'
            args 'net.rubygrapefruit.platform.internal.jni.PosixFileFunctions'
            args 'net.rubygrapefruit.platform.internal.jni.PosixFileSystemFunctions'
            args 'net.rubygrapefruit.platform.internal.jni.PosixProcessFunctions'
            args 'net.rubygrapefruit.platform.internal.jni.PosixTerminalFunctions'
            args 'net.rubygrapefruit.platform.internal.jni.TerminfoFunctions'
            args 'net.rubygrapefruit.platform.internal.jni.WindowsConsoleFunctions'
            args 'net.rubygrapefruit.platform.internal.jni.WindowsHandleFunctions'
        }
    }
}

cpp {
    sourceSets {
        main {
            source.exclude 'curses.cpp'
        }
        curses {
            source.srcDirs = ['src/main/cpp']
            source.include 'curses.cpp'
            source.include 'generic.cpp'
            source.include 'generic_posix.cpp'
        }
    }
}

def variants = [:]

libraries {
    if (org.gradle.internal.os.OperatingSystem.current().macOsX) {
        all {
            spec {
                includes(files('/System/Library/Frameworks/JavaVM.framework/Versions/Current/Headers/'))
                args("-arch", "x86_64", "-arch", "i386")
            }
        }
        universal {
            sourceSets << cpp.sourceSets.main
            spec {
                baseName = 'native-platform-osx-universal'
                args("-o", outputFile)
            }
        }
        cursesUniversal {
            sourceSets << cpp.sourceSets.curses
            spec {
                baseName = 'native-platform-curses-osx-universal'
                args("-lcurses")
                args("-o", outputFile)
            }
        }
        variants['osx-universal'] = [universal, cursesUniversal]
    } else if (org.gradle.internal.os.OperatingSystem.current().windows) {
        all {
            spec {
                includes(files("${org.gradle.internal.jvm.Jvm.current().javaHome}/include"))
                includes(files("${org.gradle.internal.jvm.Jvm.current().javaHome}/include/win32"))
                args("/DWIN32")
            }
        }

        def out = new ByteArrayOutputStream()
        exec {
            commandLine "cl.exe", "/?"
            errorOutput = out
            standardOutput = new ByteArrayOutputStream()
        }
        def header = out.toString().readLines().head()
        if (header.endsWith("for 80x86") || header.endsWith("for x86")) {
            i386 {
                sourceSets << cpp.sourceSets.main
                spec {
                    baseName = 'native-platform-windows-i386'
                }
            }
            variants['windows-i386'] = [i386]
        } else if (header.endsWith("for x64")) {
            amd64 {
                sourceSets << cpp.sourceSets.main
                spec {
                    baseName = 'native-platform-windows-amd64'
                }
            }
            variants['windows-amd64'] = [amd64]
        } else {
            throw new RuntimeException("Cannot determine compiler's target architecture")
        }

    } else if (org.gradle.internal.os.OperatingSystem.current().linux) {
        all {
            spec {
                includes(files("${org.gradle.internal.jvm.Jvm.current().javaHome}/include"))
                includes(files("${org.gradle.internal.jvm.Jvm.current().javaHome}/include/linux"))
            }
        }
        if (System.getProperty('os.arch') == 'i386' || project.hasProperty('multiarch')) {
            i386 {
                sourceSets << cpp.sourceSets.main
                spec {
                    baseName = 'native-platform-linux-i386'
                    args("-m32")
                }
            }
            cursesI386 {
                sourceSets << cpp.sourceSets.curses
                spec {
                    baseName = 'native-platform-curses-linux-i386'
                    args("-m32", "-lcurses")
                }
            }
            variants['linux-i386'] = [i386, cursesI386]
        }
        if (System.getProperty('os.arch') == 'amd64' || project.hasProperty('multiarch')) {
            amd64 {
                sourceSets << cpp.sourceSets.main
                spec {
                    baseName = 'native-platform-linux-amd64'
                    args("-m64")
                }
            }
            cursesAmd64 {
                sourceSets << cpp.sourceSets.curses
                spec {
                    baseName = 'native-platform-curses-linux-amd64'
                    args("-m64", "-lcurses")
                }
            }
            variants['linux-amd64'] = [amd64, cursesAmd64]
        }
    } else {
        baseName = "native-platform-solaris"
        main {
            sourceSets << cpp.sourceSets.main
            sourceSets << cpp.sourceSets.curses
            spec {
                includes(files("${org.gradle.internal.jvm.Jvm.current().javaHome}/include"))
                includes(files("${org.gradle.internal.jvm.Jvm.current().javaHome}/include/solaris"))
                args("-DSOLARIS", "-lcurses")
            }
        }
        variants['solaris'] = [main]
    }
    all {
        spec {
            includes(files(nativeHeadersDir, 'src/main/headers'))
        }
        def task = tasks["compile${spec.binary.name.capitalize()}"]
        task.dependsOn nativeHeaders
        test.dependsOn spec
    }
}

configurations {
    jni
}

def deployer = uploadJni.repositories.mavenDeployer

variants.each { variant, libs ->
    def variantName = GUtil.toCamelCase(variant)
    def nativeJar = task("nativeJar${variantName}", type: Jar) {
        from libs.collect { tasks["compile${it.name.capitalize()}"] }
        baseName = "native-platform-$variant"
    }
    artifacts {
        jni nativeJar
        runtime nativeJar
    }
    def jniPom = deployer.addFilter(variant) { artifact, file ->
        return file == nativeJar.archivePath
    }
    jniPom.groupId = project.group
    jniPom.artifactId = nativeJar.baseName
    jniPom.version = project.version
    jniPom.scopeMappings.mappings.clear()
}

javadoc {
    exclude '**/internal/**'
}

task sourceZip(type: Zip) {
    from sourceSets.main.allSource
    classifier = 'sources'
    extension = 'jar'
}

task javadocZip(type: Zip) {
    from javadoc
    classifier = 'javadoc'
    extension = 'jar'
}

artifacts {
    archives sourceZip
    archives javadocZip
}

def mainPom = uploadArchives.repositories.mavenDeployer.pom
mainPom.groupId = project.group
mainPom.artifactId = jar.baseName
mainPom.version = project.version
mainPom.scopeMappings.mappings.clear()
mainPom.withXml { provider ->
    def node = provider.asNode()
    def deps = node.appendNode('dependencies')
    ['osx-universal', 'linux-amd64', 'linux-i386', 'windows-amd64', 'windows-i386'].each { platform ->
        def dep = deps.appendNode('dependency')
        dep.appendNode('groupId', project.group)
        dep.appendNode('artifactId', "native-platform-${platform}")
        dep.appendNode('version', project.version)
    }
}

task wrapper(type: Wrapper) {
    gradleVersion = "1.3-20120907220018+0000"
}