/*
 * Copyright 2010 the original author or authors.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

import org.gradle.build.GenerateReleasesXml

configurations {
    reports
}

dependencies {
    groovy libraries.groovy

    publishCompile libraries.slf4j_api

    compile libraries.asm
    compile libraries.ant
    compile libraries.commons_collections
    compile libraries.commons_io
    compile libraries.commons_lang
    compile libraries.commons_httpclient
    compile libraries.ivy
    compile libraries.logback_core
    compile libraries.logback_classic
    compile libraries.guava
    compile libraries.jcip
    compile libraries.jul_to_slf4j
    compile "slide:webdavlib:2.0@jar"
    compile module('org.fusesource.jansi:jansi:1.2.1') {
        dependency libraries.jna
    }
    compile libraries.commons_httpclient

    compile project(":cli")
    compile project(":native")

    runtime libraries.log4j_to_slf4j
    runtime libraries.jcl_to_slf4j
    runtime module("com.jcraft:jsch:0.1.42") {
        dependency "com.jcraft:jzlib:1.0.7"
    }

    testRuntime "xerces:xercesImpl:2.9.1"

    testFixturesCompile project(":internalTesting")
    testFixturesRuntime project(':coreImpl')

    integTestCompile project(":internalIntegTesting")

    reports 'css3-pie:css3-pie:1.0beta3'
}

test {
    jvmArgs '-Xms128m', '-Xmx512m', '-XX:MaxPermSize=128m', '-XX:+HeapDumpOnOutOfMemoryError'
}

[compileGroovy, compileTestGroovy]*.groovyOptions*.fork(memoryInitialSize: '128M', memoryMaximumSize: '1G')

task releasesResource(type: GenerateReleasesXml) {
    destFile = new File(generatedResourcesDir, "org/gradle/releases.xml")
}
sourceSets.main.output.dir generatedResourcesDir, buildBy: releasesResource

task reportResources(type: Copy) {
    from configurations.reports
    into "$generatedResourcesDir/org/gradle/reporting"
}
sourceSets.main.output.dir generatedResourcesDir, buildBy: reportResources

task pluginsManifest(type: PluginsManifest)
sourceSets.main.output.dir generatedResourcesDir, buildBy: pluginsManifest

class PluginsManifest extends DefaultTask {
    @OutputFile
    File getPropertiesFile() {
        return new File(project.generatedResourcesDir, "gradle-plugins.properties")
    }

    @Input
    Properties getPluginProperties() {
        def properties = new Properties()
        properties.plugins = project.pluginProjects().collect { it.archivesBaseName }.join(',')
        return properties
    }

    @TaskAction
    def generate() {
        propertiesFile.withOutputStream { pluginProperties.save(it, 'plugin definitions') }
    }
}