
plugins {
  id "us.kirchmeier.capsule" version '1.0.2'
  id 'com.google.protobuf' version '0.8.0'
}

apply plugin: 'java'
apply plugin: 'eclipse'
apply plugin: 'idea'

// Uncomment both lines below to define an application (must set mainClassName
//apply plugin: 'application'
//mainClassName='your.main.ApplicationClass'

apply plugin: 'maven-publish'

// We may need to use this code from Java.
targetCompatibility = '1.7'
sourceCompatibility = '1.7'


// Is this a snapshot version?
ext { isSnapshot = false } 

ext {
    groupId = 'org.factcenter.meerkat'

    // Credentials for publishing repositories
    publishRepository = "https://cs.idc.ac.il/nexus/content/repositories/${project.isSnapshot ? 'snapshots' : 'releases'}"
    publishUser =  project.hasProperty('publishUser') ? project.property('publishUser') : ""
    publishPassword = project.hasProperty('publishPassword') ? project.property('publishPassword') : ""
}

description = "Common classes for implementing Meerkat's RESTful API"

// Your project version
version = "0.0.1"

version += "${isSnapshot ? '-SNAPSHOT' : ''}"


dependencies {
    // Meerkat common
    compile project(':meerkat-common')

    // Jersey for RESTful API
    compile 'org.glassfish.jersey.containers:jersey-container-servlet:2.22.+'

    testCompile 'junit:junit:4.+'

    runtime 'org.codehaus.groovy:groovy:2.4.+'
}


/*==== You probably don't have to edit below this line =======*/

protobuf {
    // Configure the protoc executable
    protoc {
    // Download from repositories
        artifact = 'com.google.protobuf:protoc:3.+'
    }
}


idea {
    module {
        project.sourceSets.each { sourceSet ->

            def srcDir = "${protobuf.generatedFilesBaseDir}/$sourceSet.name/java"

            // add protobuf generated sources to generated source dir.
            if ("test".equals(sourceSet.name)) {
                testSourceDirs += file(srcDir)
            } else {
                sourceDirs += file(srcDir)
            }
            generatedSourceDirs += file(srcDir)

        }

        // Don't exclude build directory
        excludeDirs -= file(buildDir)
    }
}



/*===================================
 *        Repositories
 *===================================*/

repositories {
        // Use local maven repository
        mavenLocal()

        // Use 'maven central' for other dependencies.
        mavenCentral()
}

task "info" {
    doLast {
        println "Project: ${project.name}"
        println "Description: ${project.description}"
        println "--------------------------"
        println "GroupId: $groupId"
        println "Version: $version (${isSnapshot ? 'snapshot' : 'release'})"
        println ""
    }
}
info.description 'Print some information about project parameters'


/*===================================
 *        Publishing
 *===================================*/

publishing {
    publications {
        mavenJava(MavenPublication) {
            groupId project.groupId
            pom.withXml {
                asNode().appendNode('description', project.description)
            }
            from project.components.java

        }
    }
    repositories {
        maven {
            url publishRepository
            credentials { username 
                password 

                username publishUser
                password publishPassword
            }
        }
    }
}



