/*
 * Copyright 2012, Google Inc.
 * All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions are
 * met:
 *
 *     * Redistributions of source code must retain the above copyright
 * notice, this list of conditions and the following disclaimer.
 *     * Redistributions in binary form must reproduce the above
 * copyright notice, this list of conditions and the following disclaimer
 * in the documentation and/or other materials provided with the
 * distribution.
 *     * Neither the name of Google Inc. nor the names of its
 * contributors may be used to endorse or promote products derived from
 * this software without specific prior written permission.
 *
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 */

apply plugin: 'idea'

subprojects {
    apply plugin: 'java'
    apply plugin: 'idea'

    ext.baseVersion = '1.4.1'
    ext.jarVersion = baseVersion

    // For non-release builds, we want to append the commit and
    // dirty status to the version
    gradle.taskGraph.whenReady {
        if (!it.hasTask(release)) {
            def versionSuffix
            try {
                def git = org.eclipse.jgit.api.Git.open(file('.'))
                def head = git.getRepository().getRef("HEAD")
                versionSuffix = head.getObjectId().abbreviate(8).name()

                if (!git.status().call().clean) {
                    versionSuffix += '-dirty'
                }
            } catch (Exception) {
                // In case we can't get the commit for some reason,
                // just use -dev
                versionSuffix = 'dev'
            }

            version = baseVersion + '-' + versionSuffix

            // use <version>-dev for the jar name, rather than the
            // full commit+dirty string
            jarVersion = baseVersion + '-dev'
        } else {
            version = baseVersion
        }

        jar {
            version = jarVersion
        }
    }

    repositories {
        mavenCentral()
    }

    // Note: please don't use this. This is strictly for the official releases
    // that are posted on the googlecode download page.
    task release {
    }
}


buildscript {
    repositories {
        mavenCentral()
    }
    dependencies {
        classpath 'org.eclipse.jgit:org.eclipse.jgit:2.0.0.201206130900-r'
    }
}