Squashed 'third_party/Phoenix-frc-lib/' content from commit 666d176
Change-Id: Ibaca2fc8ffb1177e786576cc1e4cc9f7a8c98f13
git-subtree-dir: third_party/Phoenix-frc-lib
git-subtree-split: 666d176a08151793044ab74e0005f13d3732ed96
diff --git a/java/java.gradle b/java/java.gradle
new file mode 100644
index 0000000..6ba893f
--- /dev/null
+++ b/java/java.gradle
@@ -0,0 +1,135 @@
+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 {
+ user {
+ java {
+ srcDirs = [userJavaSrc]
+ }
+ }
+ main {
+ java {
+ srcDirs = [javaSrc]
+ }
+ }
+}
+
+dependencies {
+ compile sourceSets.user.output
+ runtime sourceSets.user.output
+ compile wpilibjDep
+ runtime wpilibjDep
+ compile javaNetTablesDep
+ runtime javaNetTablesDep
+ compile fileTree(dir: javaLibraryLoc, include: ['*.jar'])
+ runtime fileTree(dir: javaLibraryLoc, include: ['*.jar'])
+}
+
+jar {
+ description = 'Generates jar'
+ baseName = libraryName
+ duplicatesStrategy = 'exclude'
+
+ dependsOn { classes }
+
+ if (embedJavaLibraries) {
+ def tree = fileTree(dir: javaLibraryLoc, include: ['*.jar'])
+ tree.each {
+ from zipTree(it.path)
+ }
+ }
+
+ if (embedJavaLibraries) {
+ from sourceSets.user.output
+ }
+}
+
+/**
+ * Generates the JNI headers
+ */
+task jniHeaders {
+ description = 'Generates JNI headers'
+ group = 'WPILib'
+ def outputFolder = file(generatedJNIHeaderLoc)
+ inputs.files sourceSets.main.output
+ outputs.file outputFolder
+ doLast {
+ outputFolder.mkdirs()
+ exec {
+ ignoreExitValue = true
+ executable org.gradle.internal.jvm.Jvm.current().getExecutable('javah')
+ args '-d', outputFolder
+ args '-classpath', sourceSets.main.runtimeClasspath.asPath
+ args jniDefinitions
+ }
+ }
+}
+
+ext.getNativeJNISymbols = {
+ def symbolsList = []
+
+ jniHeaders.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
+}
+
+clean {
+ delete generatedJNIHeaderLoc
+}
+
+compileJava {
+ options.compilerArgs << '-Xlint:unchecked' << "-Werror"
+}
+
+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) {
+ cppCompiler.args '-I', file("${rootDir}/java/arm-linux").absolutePath
+ cppCompiler.args '-I', file("${rootDir}/java/arm-linux/linux").absolutePath
+
+ jniHeaders.outputs.files.each { file ->
+ cppCompiler.args '-I', file.getPath()
+ }
+
+ dependsOn jniHeaders
+ }
+ }
+}