blob: 02aed5fc91004f3d4784026377db1fd1c8a09439 [file] [log] [blame]
apply plugin: 'java'
repositories {
mavenCentral()
maven {
url "http://srdjan.mtv:8081/nexus/content/repositories/test_repo/"
}
}
dependencies {
compile 'io.v:vanadium:0.1-SNAPSHOT'
compile group: 'com.google.guava', name: 'guava', version: '18.0'
testCompile group: 'junit', name: 'junit', version: '4.12'
testCompile group: 'com.google.truth', name: 'truth', version: '0.25'
}
clean {
delete 'generated-src'
}
public static isDarwin() {
return getOS().contains("os x")
}
public static isLinux() {
return getOS().contains("linux")
}
public static isAmd64() {
return getArch().contains("x86_64") || getArch().contains("amd64")
}
public static getArch() {
return System.properties['os.arch'].toLowerCase()
}
public static getOS() {
return System.properties['os.name'].toLowerCase()
}
class VanadiumEnvironment {
File v23Root;
File v23Bin;
public static getVanadiumEnvironment() {
VanadiumEnvironment result = new VanadiumEnvironment()
if (!System.getenv().containsKey('V23_ROOT')) {
throw new InvalidUserDataException("V23_ROOT is not set. "
+ "Please follow the Vanadium installation instructions at "
+ "https://v.io/installation/index.html")
}
result.v23Root = new File(System.getenv()['V23_ROOT'])
result.v23Bin = new File(result.v23Root, ['devtools', 'bin', 'v23'].join(File.separator))
if (!result.v23Bin.exists() || !result.v23Bin.isFile() || !result.v23Bin.canExecute()) {
throw new InvalidUserDataException(
result.v23Bin.toString() + " does not exist or is not an executable file. "
+ "Please follow the Vanadium installation instructions at "
+ "https://v.io/installation/index.html")
}
return result
}
}
def v23Root = VanadiumEnvironment.getVanadiumEnvironment().v23Root.getAbsolutePath()
def v23Bin = VanadiumEnvironment.getVanadiumEnvironment().v23Bin.getAbsolutePath()
def vdlBin = [v23Root, 'release', 'go', 'bin', 'vdl'].join(File.separator)
def vdlPath = [ [v23Root, 'roadmap', 'go', 'src'].join(File.separator),
[v23Root, 'release', 'go', 'src'].join(File.separator) ].join(":")
sourceSets.main.java.srcDirs += 'generated-src/vdl'
task checkVanadiumEnvironment {
VanadiumEnvironment.getVanadiumEnvironment()
if (System.getenv('JAVA_HOME') == null) {
throw new InvalidUserDataException("The JAVA_HOME environment variable is not set. "
+ "Please set it to the root of a JDK installation directory. If JDK isn't "
+ "installed, you probably didn't install the java profile: try running\n\n"
+ "v23 profile install java\n\nand then try building again.")
}
if (!isAmd64()) {
throw new InvalidUserDataException("Java Vanadium builds only enabled on amd64 "
+ "architectures, not: " + getArch())
}
if (!isLinux() && !isDarwin()) {
throw new InvalidUserDataException("Java Vanadium builds only enabled on "
+ "linux/darwin systems, not: " + getOS())
}
}
task buildVdlTool(type: Exec) {
commandLine v23Bin, 'go', 'install', 'v.io/x/ref/cmd/vdl'
}
task generateVdl(type: Exec, dependsOn: buildVdlTool) {
environment VDLPATH: vdlPath
commandLine vdlBin, 'generate', '--lang=java', '--java-out-dir=generated-src/vdl', 'all'
}
tasks.'compileJava'.dependsOn(generateVdl)
task goBuildVanadiumLib(type: Exec, dependsOn: checkVanadiumEnvironment) {
def env = VanadiumEnvironment.getVanadiumEnvironment()
def existingPath = System.getenv('PATH')
if (existingPath == null) {
existingPath = ""
}
environment 'V23_PROFILE': 'java'
commandLine env.v23Bin.getAbsolutePath(), 'go', 'install',
'-buildmode=c-shared', '-v', '-tags', 'java', 'v.io/syncbase/jni/main'
}
// Copy the shared library to its ultimate destination.
if (isLinux()) {
task copyVanadiumLib(type: Copy, dependsOn: goBuildVanadiumLib) {
from v23Root + '/roadmap/go/pkg/linux_amd64_shared/v.io/syncbase/jni'
into 'build/libs'
include 'main.a'
rename 'main.a', 'libv23.so'
}
} else { // darwin
task copyVanadiumLib(type: Copy, dependsOn: goBuildVanadiumLib) {
from v23Root + '/roadmap/go/pkg/darwin_amd64/v.io/syncbase/jni'
into 'build/libs'
include 'main.a'
rename 'main.a', 'libv23.dylib'
}
}
// Add shared library dependency to our tests.
tasks.withType(Test) {
if (isDarwin()) {
// TODO(sjr): remove these when
// https://github.com/vanadium/issues/issues/567 is resolved.
jvmArgs '-XX:+UnlockDiagnosticVMOptions'
jvmArgs '-XX:-LogEvents'
}
systemProperty "java.library.path", "build/libs"
}
tasks.'processTestResources'.dependsOn(copyVanadiumLib)