Files
allwpilib/java/java.gradle

181 lines
5.6 KiB
Groovy
Raw Normal View History

2016-08-14 12:38:13 -07:00
import org.gradle.internal.os.OperatingSystem
apply plugin: 'java'
apply plugin: 'net.ltgt.errorprone'
repositories {
mavenCentral()
}
configurations.errorprone {
resolutionStrategy.force 'com.google.errorprone:error_prone_core:2.0.9'
}
def generatedJNIHeaderLoc = "${buildDir}/include"
sourceSets {
main {
java {
srcDirs = ["${rootDir}/java/src"]
}
}
}
dependencies {
compile 'org.opencv:opencv-java:3.1.0'
runtime 'org.opencv:opencv-java:3.1.0'
}
2016-08-14 12:38:13 -07:00
jar {
description = 'Generates cscore jar, with the JNI shared libraries embedded'
baseName = 'cscore'
2016-08-14 12:38:13 -07:00
classifier = "$buildPlatform"
duplicatesStrategy = 'exclude'
dependsOn { classes }
model {
binaries {
withType(SharedLibraryBinarySpec) { binary ->
// Only include the native file if not cross compiling to the roboRIO
if (!project.isArm || project.hasProperty('compilerPrefix'))
from(file(binary.sharedLibraryFile)) {
into getPlatformPath(binary)
}
2016-08-14 12:38:13 -07:00
}
}
}
}
project.tasks.whenTaskAdded { task ->
if (isArm) {
if (task.name == 'cscoreSharedLibrary') jar.dependsOn task
2016-08-14 12:38:13 -07:00
} else {
if (task.name == 'cscoreX64SharedLibrary' || task.name == 'cscoreX86SharedLibrary')
2016-08-14 12:38:13 -07:00
jar.dependsOn task
}
}
task cscoreJavaSource(type: Jar, dependsOn: classes) {
description = 'Generates the source jar for cscore java'
2016-08-14 12:38:13 -07:00
group = 'WPILib'
baseName = 'cscore'
2016-08-14 12:38:13 -07:00
classifier = "sources"
duplicatesStrategy = 'exclude'
from sourceSets.main.allJava
}
task cscoreJavadoc(type: Jar, dependsOn: javadoc) {
description = 'Generates the javadoc jar for cscore java'
2016-08-14 12:38:13 -07:00
group = 'WPILib'
baseName = 'cscore'
2016-08-14 12:38:13 -07:00
classifier = "javadoc"
duplicatesStrategy = 'exclude'
from javadoc.destinationDir
}
build.dependsOn cscoreJavaSource
build.dependsOn cscoreJavadoc
2016-08-14 12:38:13 -07:00
/**
* Generates the JNI headers
*/
task jniHeadersCscore {
description = 'Generates JNI headers from edu.wpi.cscore.*'
2016-08-14 12:38:13 -07:00
group = 'WPILib'
def outputFolder = file(generatedJNIHeaderLoc)
inputs.files sourceSets.main.output
outputs.file outputFolder
doLast {
outputFolder.mkdirs()
exec {
executable org.gradle.internal.jvm.Jvm.current().getExecutable('javah')
args '-d', outputFolder
args '-classpath', sourceSets.main.runtimeClasspath.asPath
args 'edu.wpi.cscore.CameraServerJNI'
2016-08-14 12:38:13 -07:00
}
}
}
ext.getNativeJNISymbols = {
def symbolsList = []
jniHeadersCscore.outputs.files.each {
FileTree tree = fileTree(dir: it)
tree.each { File file ->
file.eachLine { line ->
if (line.trim()) {
if (line.startsWith("JNIEXPORT ") && line.contains('JNICALL')) {
def (p1, p2) = line.split('JNICALL').collect { it.trim() }
// p2 is our JNI call
symbolsList << p2
}
}
}
}
}
return symbolsList
}
2016-08-14 12:38:13 -07:00
clean {
delete generatedJNIHeaderLoc
}
compileJava {
options.compilerArgs << '-Xlint:unchecked'
}
javadoc {
options.addStringOption('Xdoclint:none', '-quiet')
}
// This creates a lambda that the main build.gradle can access, which sets up the JNI includes for the
// target build platform. This lambda is exposed as a property in the main build.gradle.
ext.setupJniIncludes = { binaries ->
def platformSpecificIncludeFlag = { loc, cppCompiler ->
if (OperatingSystem.current().isWindows()) {
cppCompiler.args "/I$loc"
} else {
cppCompiler.args '-I', loc
}
}
binaries.all {
tasks.withType(CppCompile) {
if (buildPlatform == 'arm') {
cppCompiler.args '-I', file("${rootDir}/java/arm-linux").absolutePath
cppCompiler.args '-I', file("${rootDir}/java/arm-linux/linux").absolutePath
} else {
def jdkLocation = org.gradle.internal.jvm.Jvm.current().javaHome
platformSpecificIncludeFlag("${jdkLocation}/include", cppCompiler)
if (targetPlatform.operatingSystem.macOsX) {
platformSpecificIncludeFlag("${jdkLocation}/include/darwin", cppCompiler)
} else if (targetPlatform.operatingSystem.linux) {
platformSpecificIncludeFlag("${jdkLocation}/include/linux", cppCompiler)
} else if (targetPlatform.operatingSystem.windows) {
platformSpecificIncludeFlag("${jdkLocation}/include/win32", cppCompiler)
} else if (targetPlatform.operatingSystem.freeBSD) {
platformSpecificIncludeFlag("${jdkLocation}/include/freebsd", cppCompiler)
} else if (file("$jdkLocation/include/darwin").exists()) {
// TODO: As of Gradle 2.8, targetPlatform.operatingSystem.macOsX returns false
// on El Capitan. We therefore manually test for the darwin folder and include it
// if it exists
platformSpecificIncludeFlag("${jdkLocation}/include/darwin", cppCompiler)
}
}
jniHeadersCscore.outputs.files.each { file ->
2016-08-14 12:38:13 -07:00
if (buildPlatform == 'arm') {
cppCompiler.args '-I', file.getPath()
} else {
platformSpecificIncludeFlag(file.getPath(), cppCompiler)
}
}
dependsOn jniHeadersCscore
2016-08-14 12:38:13 -07:00
}
}
}