blob: 640b2ffc2ec124b085dcd6a73f6913cffb9d6e53 [file] [log] [blame]
apply plugin: 'java'
apply plugin: 'maven-publish'
sourceCompatibility = 1.7
targetCompatibility = 1.7
dependencies {
compile group: 'joda-time', name: 'joda-time', version: '2.7'
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'
testCompile 'org.reflections:reflections:0.9.9-RC1'
}
repositories {
mavenCentral()
}
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()
}
def jiriRoot = VanadiumEnvironment.getVanadiumEnvironment().jiriRoot.getAbsolutePath()
def jiriBin = VanadiumEnvironment.getVanadiumEnvironment().jiriBin.getAbsolutePath()
def vdlPath = [jiriRoot, 'release', 'go', 'src'].join(File.separator)
def vdlBin = [jiriRoot, 'release', 'go', 'bin', 'vdl'].join(File.separator)
sourceSets.main.java.srcDirs += 'generated-src/vdl'
class VanadiumEnvironment {
File jiriRoot;
File jiriBin;
File thirdPartyGoBinDir;
public static getVanadiumEnvironment() {
VanadiumEnvironment result = new VanadiumEnvironment()
if (!System.getenv().containsKey('JIRI_ROOT')) {
throw new InvalidUserDataException("JIRI_ROOT is not set. "
+ "Please follow the Vanadium installation instructions at "
+ "https://github.com/vanadium/docs/blob/master/installation.md")
}
result.jiriRoot = new File(System.getenv()['JIRI_ROOT'])
result.jiriBin = new File(result.jiriRoot, ['devtools', 'bin', 'jiri'].join(File.separator))
if (!result.jiriBin.exists() || !result.jiriBin.isFile() || !result.jiriBin.canExecute()) {
throw new InvalidUserDataException(
result.jiriBin.toString() + " does not exist or is not an executable file. "
+ "Please follow the Vanadium installation instructions at "
+ "https://github.com/vanadium/docs/blob/master/installation.md")
}
result.thirdPartyGoBinDir = new File(result.jiriRoot,
['third_party', 'java', 'go', 'bin'].join(File.separator))
def thirdPartyGoBin = new File(result.thirdPartyGoBinDir, 'go')
if (!thirdPartyGoBin.exists() || !thirdPartyGoBin.isFile() || !thirdPartyGoBin.canExecute()) {
throw new InvalidUserDataException(
thirdPartyGoBin.toString() + " does not exist or is not an executable file. "
+ "You probably didn't install the java profile. Try running\n\n"
+ "jiri profile install java\n\nand then try building again.")
}
return result
}
}
task buildVdlTool(type: Exec) {
commandLine jiriBin, '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 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"
+ "jiri 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 goBuildVanadiumLib(type: Exec, dependsOn: checkVanadiumEnvironment) {
def env = VanadiumEnvironment.getVanadiumEnvironment()
def existingPath = System.getenv('PATH')
if (existingPath == null) {
existingPath = ""
}
environment 'JIRI_PROFILE': 'java'
environment 'PATH': [env.thirdPartyGoBinDir.getAbsolutePath(), existingPath].join(File.pathSeparator)
commandLine env.jiriBin.getAbsolutePath(), 'go', 'install',
'-buildmode=c-shared', '-v', '-tags', 'java', 'v.io/x/jni/main'
}
// Copy the shared library to its ultimate destination.
if (isLinux()) {
task copyVanadiumLib(type: Copy, dependsOn: goBuildVanadiumLib) {
from jiriRoot + '/release/go/pkg/linux_amd64_shared/v.io/x/jni'
into 'build/libs'
include 'main.a'
rename 'main.a', 'libv23.so'
}
} else { // darwin
task copyVanadiumLib(type: Copy, dependsOn: goBuildVanadiumLib) {
from jiriRoot + '/release/go/pkg/darwin_amd64/v.io/x/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)
// We cannot reliably determine whether the native vanadium lib is up-to-date.
// Therefore we always run the tests even if Gradle thinks that there is no
// need.
tasks.'test'.outputs.upToDateWhen({ false })
tasks.'test' << {
io.v.VanadiumTestXmlAggregator.mergeAllTestXmlFiles(new File("${buildDir}/test-results"), new File("${buildDir}/aggregated-test-results.xml"))
}
task buildVanadiumLib(dependsOn: copyVanadiumLib) {}
task sourceJar(type: Jar) {
from sourceSets.main.allJava
}
javadoc {
if (JavaVersion.current().isJava8Compatible()) {
options.addStringOption('Xdoclint:none', '-quiet')
}
}
task javadocJar(type: Jar, dependsOn: javadoc) {
from javadoc.destinationDir
}
task natives(type: Jar, dependsOn: buildVanadiumLib) {
from 'build/libs/libv23.so'
}
publishing {
publications {
mavenJava(MavenPublication) {
groupId 'io.v'
artifactId 'vanadium'
version '0.1-SNAPSHOT'
from components.java
artifact sourceJar {
classifier "sources"
}
artifact javadocJar {
classifier "javadoc"
}
artifact natives {
classifier "natives"
}
}
}
repositories {
maven {
credentials {
username 'admin'
password 'admin123'
}
url "http://srdjan.mtv:8081/nexus/content/repositories/test_repo"
}
}
}