blob: 2ed0b9a31a0887dc2ddfdd44ee9b1e324f67ae4d [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 isArm() {
return getArch().contains("arm")
}
public static getArch() {
return System.properties['os.arch'].toLowerCase()
}
public static getOS() {
return System.properties['os.name'].toLowerCase()
}
def String getOsName() {
if (isLinux()) {
return "linux";
} else if (isDarwin()) {
return "macosx";
} else {
throw new IllegalStateException("Unsupported operating system " + System.properties.'os.name')
}
}
public static newStyleProfiles() {
return new File(System.getenv()['JIRI_ROOT'], '.jiri_v23_profiles').exists()
}
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;
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")
}
return result
}
}
task buildVdlTool(type: Exec) {
commandLine jiriBin, 'go', 'install', 'v.io/x/ref/cmd/vdl'
}
// Delete the previously-generated VDL files, as they might conflict with the new ones.
task deleteVdl(type: Delete, dependsOn: buildVdlTool) {
delete "generated-src/vdl"
}
task generateVdl(type: Exec, dependsOn: deleteVdl) {
environment VDLPATH: vdlPath
commandLine vdlBin, 'generate', '--lang=java', '--java-out-dir=generated-src/vdl', 'all'
}
tasks.'processResources'.dependsOn(generateVdl)
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 v23-profile install java\n\nand then try building again.")
}
if (!isAmd64() && !isArm()) {
throw new InvalidUserDataException("Java Vanadium builds only enabled on amd64 "
+ "and arm 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 existingPath = System.getenv('PATH')
if (existingPath == null) {
existingPath = ""
}
// NOTE(spetrovic): we add the '-installsuffix=shared' flag because the build doesn't work
// without it on linux/arm. (There is some conflict with "regular", i.e., non-shared builds).
if (newStyleProfiles()) {
commandLine jiriBin, 'go', '--profiles=java', 'install', '-buildmode=c-shared', '-v',
'-tags', 'java', '-installsuffix=shared', 'v.io/x/jni/main'
} else {
environment 'JIRI_PROFILE': 'java'
commandLine jiriBin, 'go', 'install', '-buildmode=c-shared', '-v', '-tags', 'java',
'-installsuffix=shared', 'v.io/x/jni/main'
}
}
// Copy the shared library to its ultimate destination.
if (isLinux()) {
def installDir = ''
if (isAmd64()) {
installDir = '/release/go/pkg/linux_amd64_shared_shared/v.io/x/jni'
} else { // arm
installDir = '/release/go/pkg/linux_arm_shared/v.io/x/jni'
}
task copyVanadiumLib(type: Copy, dependsOn: goBuildVanadiumLib) {
from jiriRoot + installDir
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_shared/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) {
if (isLinux()) {
from 'build/libs/libv23.so'
} else if (isDarwin()) {
from 'build/libs/libv23.dylib'
} else {
throw new InvalidUserDataException("unsupported operating system: " + getOS())
}
}
def pomDependencyText = '''
<dependencies>
<dependency>
<groupId>io.v</groupId>
<artifactId>vanadium-without-natives</artifactId>
<version>0.1-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>io.v</groupId>
<artifactId>vanadium-natives-linux</artifactId>
<version>0.1-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>io.v</groupId>
<artifactId>vanadium-natives-macosx</artifactId>
<version>0.1-SNAPSHOT</version>
</dependency>
</dependencies>
'''
def pomDependencies = new XmlParser().parseText(pomDependencyText)
publishing {
publications {
mavenNoNatives(MavenPublication) {
groupId 'io.v'
artifactId 'vanadium-without-natives'
version '0.1-SNAPSHOT'
from components.java
artifact sourceJar {
classifier "sources"
}
artifact javadocJar {
classifier "javadoc"
}
}
mavenJava(MavenPublication) {
groupId 'io.v'
artifactId 'vanadium'
version '0.1-SNAPSHOT'
from components.java
// No archives in this one, it's a meta package only.
artifacts.clear()
pom.withXml {
for (Node node : pomDependencies.children()) {
asNode().dependencies[0].append(node)
}
}
}
mavenNatives(MavenPublication) {
groupId 'io.v'
artifactId 'vanadium-natives-' + getOsName()
version '0.1-SNAPSHOT'
artifact natives
}
}
repositories {
maven {
credentials {
username 'admin'
password 'admin123'
}
url "http://srdjan.mtv:8081/nexus/content/repositories/test_repo"
}
}
}